From 7644786d628c992b630b1d1bc0722dec2596e118 Mon Sep 17 00:00:00 2001 From: Jakub Zych Date: Tue, 24 Nov 2026 18:56:21 +0100 Subject: [PATCH] docs(36): create phase plan --- .planning/ROADMAP.md | 32 + .planning/STATE.md | 20 +- .../36-01-PLAN.md | 311 +++++++++ .../36-02-PLAN.md | 322 +++++++++ .../36-03-PLAN.md | 230 +++++++ .../36-04-PLAN.md | 387 +++++++++++ .../36-PATTERNS.md | 499 ++++++++++++++ .../36-RESEARCH.md | 620 ++++++++++++++++++ .../36-VALIDATION.md | 85 +++ .planning/state.json | 18 +- 10 files changed, 2510 insertions(+), 14 deletions(-) create mode 100644 .planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-01-PLAN.md create mode 100644 .planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-02-PLAN.md create mode 100644 .planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-03-PLAN.md create mode 100644 .planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-04-PLAN.md create mode 100644 .planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-PATTERNS.md create mode 100644 .planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-RESEARCH.md create mode 100644 .planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-VALIDATION.md diff --git a/.planning/ROADMAP.md b/.planning/ROADMAP.md index 03bb5415..5f72b789 100644 --- a/.planning/ROADMAP.md +++ b/.planning/ROADMAP.md @@ -1917,6 +1917,8 @@ Phases execute in numeric order: 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8 → | 32. SEO foundation | 6/6 | In Progress| | | 33. SEO output, audit and content | 16/16 | In Progress| | | 34. Plugin marketplace | 6/6 | In Progress| | +| 35. Mail templates and layouts editor | 9/9 | Complete | 2026-11-14 | +| 36. Granular MCP OAuth & API token scope picker | 0/4 | Planned | - | ## Backlog @@ -1995,3 +1997,33 @@ Plans: **Wave 9** *(gap closure tests, blocked on Wave 8 completion)* - [x] 35-09-PLAN.md — regression and unit tests for CR-01, WR-01 and WR-05, new names required by `scripts/check-phase35.sh` (plus the IN-03 self-test fix), validation map + +### Phase 36: Granular MCP OAuth & API token scope picker + +**Goal:** Scale the administrator MCP OAuth consent screen (`ConnectView.vue`) and personal API token creation dialog (`ApiTokenCreateDialog.vue`) to dozens of plugins and hundreds of granular feature-level scopes, fix the `admin:read` visibility footgun, expose plugin/group metadata on token scopes, and warn at boot when plugins declare backend write MCP tools without a covering `pact.HasTokenScopes` declaration. Decision note: `.planning/notes/2026-11-24-mcp-consent-granular-scope-picker.md`. +**Mode:** mvp +**Depends on:** Phase 32.2 (MCP OAuth with administrator subjects) +**Repos:** `summercms.go` (plus follow-up `HasTokenScopes` additions in `sm-seo-plugin`, `sm-sitemap-plugin` and any other core plugins exposing backend write MCP tools) +**Requirements**: TBD +**Success Criteria** (what must be TRUE): + + 1. `pact.TokenScope` accepts an optional `Group` field (phrase key or literal, validated when containing `::`) and `cabana.AdminAPITokenScope` additively exposes `plugin_id` and resolved `group` (falling back to plugin name / permission tab / `plugin_id`); `ValidTokenScopeName` stays unchanged and existing plugins without `Group` keep working. + 2. Booting an app where a plugin registers backend non-read-only `MCPTool`s not covered by any non-`*` `TokenScope` logs a clear warning identifying the plugin and uncovered tools, without breaking boot. + 3. `ConnectView.vue` keeps its `480px` summary card with 3-tier access selection (**Full `*`** | **Read-only `admin:read`** | **Custom**), defaults to `Read-only (admin:read)` when requested and grantable, shows effective-access chips, and opens a dedicated **Customize scopes** modal with search, `All / Selected / Read-only` filters, collapsible plugin/group accordions, per-group quick actions (`Read` / `All` / `Clear`), and an opt-in `admin:read` toggle that visibly locks all `:read` rows (`via admin:read`). + 4. `ApiTokenCreateDialog.vue` reuses the same shared `ScopePicker` via an in-dialog view swap (`← Back` / `Apply scopes`, no nested modal overlay) with dark-mode-aware tokens. + 5. OpenAPI schema, embedded `boardwalk/dist`, en/pl phrasebook copy, Go unit tests, and Vitest coverage for both `ConnectView` and `ApiTokenCreateDialog` pass green. + +**Plans:** 4 plans + +Plans: +**Wave 1** +- [ ] 36-01-PLAN.md — Go backend scope metadata (`pact.TokenScope.Group`, `cabana.AdminAPITokenScope` `plugin_id`/`group` + D-16 fallback), `cabana.TokenScopeCovers` + `pier.Mount` boot warning, EN/PL phrasebooks, OpenAPI/TS regen, READMEs & docs + +**Wave 2** *(blocked on Wave 1 completion)* +- [ ] 36-02-PLAN.md — Shared 3-tier access selector & `ScopePicker` on `ConnectView.vue` (light-literal modal) and `ApiTokenCreateDialog.vue` (fixed-width in-dialog swap), rebuilt `modules/boardwalk/dist` + +**Wave 3** *(blocked on Wave 2 completion)* +- [ ] 36-03-PLAN.md — Core plugin `pact.HasTokenScopes` rollout in `sm-sitemap-plugin` (`sitemap`/`sitemap:read`) and `sm-seo-plugin` (`seo`/`seo:read`) with EN/PL copy, READMEs, and tests + +**Wave 4** *(blocked on Wave 3 completion)* +- [ ] 36-04-PLAN.md — Comprehensive Go & Vitest unit/component suites (closing all 7 UI-SPEC backstops), full release gates, human release-tag checkpoint, and `sm-grzybyfunkcjonalne-app` local E2E proof diff --git a/.planning/STATE.md b/.planning/STATE.md index 024144eb..6eae7e06 100644 --- a/.planning/STATE.md +++ b/.planning/STATE.md @@ -1,20 +1,20 @@ --- -msd_state_version: "1.0" +gsd_state_version: "1.0" milestone: v1.0 -current_phase: "19.3" -current_phase_name: Framework transport and infrastructure for WavePath -status: planning +current_phase: 36 +current_phase_name: granular-mcp-oauth-api-token-scope-picker +status: executing stopped_at: Phase 36 context gathered -last_updated: "2026-11-24T16:32:14.991Z" +last_updated: "2026-11-24T17:54:17.146Z" last_activity: 2026-11-21 last_activity_desc: Phase 32.2 complete, transitioned to Phase 19.3 -state_head: ab64f649b04a2df5699f489cc479a89633def9ce +state_head: 4c078005c0ef71c191dde752c5082981bb843f64 progress: total_phases: 54 completed_phases: 38 - total_plans: 309 + total_plans: 313 completed_plans: 298 -gsd_state_version: "1.0" +msd_state_version: "1.0" milestone_name: milestone --- @@ -29,9 +29,9 @@ See: .planning/PROJECT.md (updated 2026-11-21) ## Current Position -Phase: 19.3 — Framework transport and infrastructure for WavePath +Phase: 36 (granular-mcp-oauth-api-token-scope-picker) — READY TO EXECUTE Plan: Not started -Status: Ready to plan +Status: Ready to execute Last activity: 2026-11-21 — Phase 32.2 complete, transitioned to Phase 19.3 Progress: [████████░░] 77% diff --git a/.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-01-PLAN.md b/.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-01-PLAN.md new file mode 100644 index 00000000..a558cf4b --- /dev/null +++ b/.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-01-PLAN.md @@ -0,0 +1,311 @@ +--- +phase: 36-granular-mcp-oauth-api-token-scope-picker +plan: 01 +type: execute +wave: 1 +depends_on: [] +files_modified: + - modules/pact/capabilities.go + - modules/cabana/token_scopes.go + - modules/cabana/account_tokens.go + - modules/cabana/mcp_consent.go + - modules/cabana/token_scopes_export.go + - modules/pier/pier.go + - modules/pier/uncovered_scopes_warning.go + - modules/phrasebook/backend/lang/en/lang.yaml + - modules/phrasebook/backend/lang/pl/lang.yaml + - admin/openapi/admin.json + - admin/src/api/schema.d.ts + - modules/pact/README.md + - modules/cabana/README.md + - modules/pier/README.md + - docs/backend/users-and-permissions.md + - docs/services/mcp.md +autonomous: true +requirements: [] +user_setup: [] +must_haves: + truths: + - "`pact.TokenScope` accepts an optional `Group string` field (literal text or `::` phrasebook key) while `pact.ValidTokenScopeName` and its regex remain unchanged and `pact.HasTokenScopes` remains explicit with no auto-generation at boot (D-01, D-05, D-14)." + - "`cabana` carries `Group` on `compiledTokenScope` and `validateTokenScopeMessageKeys` fails boot when a non-empty `Group` contains `::` and names a missing phrase key (D-14)." + - "`cabana.AdminAPITokenScope` emits always-present `plugin_id` and `group` JSON fields (no `omitempty`), setting both to `\"\"` for framework scopes (`*`, `admin:read`) and unknown stored scopes across `/account/tokens/scopes`, `/account/tokens`, and `/mcp/consent/{request}` (D-15)." + - "When `TokenScope.Group` is empty on a plugin scope, `cabana` resolves `AdminAPITokenScope.group` in exact D-16 order: (1) `::lang.plugin.name` if present and translated, (2) unanimous non-empty `Tab` across matched `reg.permissions` (translated when containing `::`), (3) raw `PluginID` (D-16)." + - "`cabana.TokenScopeCovers(app, plugins, method, permissions)` evaluates whether at least one non-`*` `TokenScope` covers both HTTP method and all required permissions (returning `false` for empty `permissions`), and `pier.Mount` emits one structured `Warn` log per plugin for uncovered backend non-`GET`/`HEAD` MCP tools without ever breaking boot (D-18)." + - "English and Polish phrasebooks in `modules/phrasebook/backend/lang/{en,pl}/lang.yaml` define all 44 `api_tokens.*` keys (including CLDR plurals `scope_count`, `scope_write_count`, `scope_plugin_count`) and 2 `mcp_connect.*` keys locked in `36-UI-SPEC.md`." + - "`admin/openapi/admin.json`, `admin/src/api/schema.d.ts`, module READMEs (`pact`, `cabana`, `pier`), and `docs/` pages match the new exported Go API and pass `scripts/check-admin-openapi.sh --check`, `TestDocsTree`, and `summer docs:build --check`." + artifacts: + - path: "modules/pact/capabilities.go" + provides: "Optional `Group string` field on `pact.TokenScope`" + contains: "Group string" + - path: "modules/cabana/token_scopes.go" + provides: "`compiledTokenScope.Group` and `validateTokenScopeMessageKeys` check for `scope.Group`" + contains: "scope.Group" + - path: "modules/cabana/account_tokens.go" + provides: "Additive `PluginID`/`Group` on `AdminAPITokenScope` and `resolveScopeGroup` D-16 fallback" + contains: "json:\"plugin_id\"" + - path: "modules/cabana/token_scopes_export.go" + provides: "`cabana.TokenScopeCovers` helper for `pier` and plugin tests" + exports: ["TokenScopeCovers"] + - path: "modules/pier/uncovered_scopes_warning.go" + provides: "`warnUncoveredBackendWriteTools` boot-time structured `Warn` per plugin" + contains: "warnUncoveredBackendWriteTools" + - path: "admin/openapi/admin.json" + provides: "Regenerated OpenAPI 3.0 spec with required `plugin_id` and `group` on `cabana.AdminAPITokenScope`" + contains: "\"plugin_id\"" + - path: "admin/src/api/schema.d.ts" + provides: "Regenerated TypeScript schema consumed by `admin/src/api/types.ts`" + contains: "plugin_id: string;" + key_links: + - from: "modules/pact/capabilities.go" + to: "modules/cabana/token_scopes.go" + via: "`compileTokenScopes` copies `strings.TrimSpace(scope.Group)` onto `compiledTokenScope.Group` and `validateTokenScopeMessageKeys` validates `::` keys" + pattern: "scope\\.Group" + - from: "modules/cabana/account_tokens.go" + to: "modules/cabana/mcp_consent.go" + via: "Both `/account/tokens/scopes`, `/account/tokens`, and `/mcp/consent/{request}` call `mapCompiledScope(ctx, tr, s.reg, scope)`" + pattern: "mapCompiledScope\\(ctx, tr, s\\.reg, scope\\)" + - from: "modules/pier/pier.go" + to: "modules/cabana/token_scopes_export.go" + via: "`pier.Mount` calls `warnUncoveredBackendWriteTools(app, plugins, cat)` which queries `cabana.TokenScopeCovers`" + pattern: "cabana\\.TokenScopeCovers" + prohibitions: + - "Do NOT alter `pact.ValidTokenScopeName` or `tokenScopeNameRE` (D-01)." + - "Do NOT auto-generate `` `TokenScope`s at boot (D-05)." + - "Do NOT add `omitempty` to `AdminAPITokenScope.PluginID` or `AdminAPITokenScope.Group` (D-15)." + - "Do NOT make `pier.Mount` return an error for uncovered backend write MCP tools (D-18)." + - "Do NOT name any consuming application in framework code, module READMEs, or `docs/` (`CLAUDE.md`)." +--- + + +**As an** administrator granting MCP OAuth or personal API token access on a multi-plugin SummerCMS site, **I want** every advertised token scope to carry its owning plugin and localized group metadata and **I want** the server to warn at boot when any plugin registers backend write MCP tools without covering `TokenScope`s, **so that** the admin SPA can group hundreds of granular scopes cleanly and operators immediately spot plugins missing `pact.HasTokenScopes`. + +**Scope (Plan 36-01, Wave 1):** Framework Go backend changes in `modules/pact`, `modules/cabana`, `modules/pier`, en/pl phrasebook copy in `modules/phrasebook`, OpenAPI/TS schema regeneration (`admin/openapi/admin.json`, `admin/src/api/schema.d.ts`), and module README / `docs/` updates. + +*Scope note:* `spec-less probe fallback skipped: phase has no requirement IDs to probe (visible skip)`. +*Reversibility:* `pact.TokenScope.Group` (D-14) and `cabana.AdminAPITokenScope` `plugin_id`/`group` (D-15) are **costly** exported Go/OpenAPI contracts; additive design ensures zero breakage for existing plugins and clients. + + + +@~/.claude/get-shit-done/workflows/execute-plan.md +@~/.claude/get-shit-done/templates/summary.md + + + +@.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-CONTEXT.md +@.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-UI-SPEC.md +@.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-RESEARCH.md +@.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-PATTERNS.md +@CLAUDE.md + + + +## Trust Boundaries + +| Boundary | Description | +|----------|-------------| +| Plugin declaration (`pact.TokenScope`) → `cabana` boot registry | Untrusted/third-party plugin declarations enter boot compilation and phrasebook validation. | +| `cabana` HTTP endpoints (`/account/tokens/scopes`, `/account/tokens`, `/mcp/consent/{request}`) → Admin SPA | Serialized `AdminAPITokenScope` JSON drives grant decisions in both consent and token-creation UIs. | +| Plugin MCP tool catalog (`pier`) → Operator logs (`diary`) | Boot-time visibility into backend write tools that would otherwise force wildcard `*` grants. | + +## STRIDE Threat Register + +| Threat ID | Category | Component | Disposition | Mitigation Plan | +|-----------|----------|-----------|-------------|-----------------| +| T-36-01 | Tampering / Information Disclosure | `modules/cabana/token_scopes.go`, `admin/openapi/admin.json`, `admin/src/api/schema.d.ts` | mitigate | Validate `TokenScope.Group` phrase keys containing `::` via `validateTokenScopeMessageKeys` at boot; emit always-present `plugin_id`/`group` strings (no `omitempty`) and enforce schema parity with `scripts/check-admin-openapi.sh --check` so the SPA never sees undefined or drifted fields. | +| T-36-02 | Elevation of Privilege / Repudiation | `modules/cabana/token_scopes_export.go`, `modules/pier/uncovered_scopes_warning.go` | mitigate | `cabana.TokenScopeCovers` excludes wildcard `*` and delegates to `scopeCoversAll`, returning `false` when `permissions` is empty (matching runtime `allowsUnderScope`). `pier.Mount` logs one structured `Warn` per plugin listing uncovered backend write tool names so operators do not silently fall back to `*`. | +| T-36-03 | Spoofing / Elevation of Privilege | `modules/cabana/account_tokens.go` (`mapCompiledScope`, `mapStoredScope`) | mitigate | Force `plugin_id: ""` and `group: ""` for framework scopes (`*`, `admin:read`) and unknown stored scopes so they can never masquerade inside a plugin accordion group; iterate `reg.permissionOrder` deterministically when computing unanimous `Tab` fallback. | + + +## Artifacts this phase produces + +- **Modified exported struct field (`modules/pact/capabilities.go`):** `pact.TokenScope.Group string` +- **Modified internal struct field & validator (`modules/cabana/token_scopes.go`):** `compiledTokenScope.Group`, `validateTokenScopeMessageKeys` validating `scope.Group` +- **Modified exported DTO fields & helpers (`modules/cabana/account_tokens.go`, `modules/cabana/mcp_consent.go`):** `cabana.AdminAPITokenScope.PluginID` (`json:"plugin_id"`), `cabana.AdminAPITokenScope.Group` (`json:"group"`), `resolveScopeGroup(ctx, tr, reg, scope)`, updated `mapCompiledScope(ctx, tr, reg, scope)` +- **New exported function (`modules/cabana/token_scopes_export.go`):** `cabana.TokenScopeCovers(app *backpack.App, plugins []party.Plugin, method string, permissions []string) bool` and internal `tokenScopeCatalogFor(app, plugins)` +- **New file & function (`modules/pier/uncovered_scopes_warning.go`, wired in `modules/pier/pier.go`):** `warnUncoveredBackendWriteTools(app *backpack.App, plugins []party.Plugin, cat *catalog)` +- **Phrasebook keys (`modules/phrasebook/backend/lang/{en,pl}/lang.yaml`):** 44 new/updated `backend::lang.api_tokens.*` keys (incl. CLDR plurals `scope_count`, `scope_write_count`, `scope_plugin_count`) and 2 `backend::lang.mcp_connect.*` keys (`subline`, `scope_picker_description`) +- **Regenerated contract artifacts:** `admin/openapi/admin.json`, `admin/src/api/schema.d.ts` +- **Updated docs:** `modules/pact/README.md`, `modules/cabana/README.md`, `modules/pier/README.md`, `docs/backend/users-and-permissions.md`, `docs/services/mcp.md` + + + + + Task 1: Add `pact.TokenScope.Group`, `cabana` D-16 group resolution, and `AdminAPITokenScope` `plugin_id`/`group` end-to-end + modules/pact/capabilities.go, modules/cabana/token_scopes.go, modules/cabana/account_tokens.go, modules/cabana/mcp_consent.go + + - modules/pact/capabilities.go (lines 845-920 — `Permission`, `TokenScope`, `HasTokenScopes`, `ValidTokenScopeName`) + - modules/cabana/token_scopes.go (lines 1-240 — `compiledTokenScope`, `compileTokenScopes`, `validatePluginTokenScope`, `validateTokenScopeMessageKeys`, `scopeMatch`) + - modules/cabana/account_tokens.go (lines 1-45, 165-315 — `AdminAPITokenScope`, `accountTokenScopes`, `mapStoredScope`, `mapCompiledScope`, `resolveScopePhrase`) + - modules/cabana/mcp_consent.go (lines 130-165 — `mcpConsentShow` calling `mapCompiledScope`) + - modules/cabana/registry.go (lines 210-270 — `compilePermissionCatalog`, `reg.permissions`, `reg.permissionOrder`) + - .planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-PATTERNS.md (Patterns 1–3) + + + Implement the end-to-end scope metadata slice across `pact` and `cabana` (**Reversibility: costly** for exported `TokenScope.Group` and `AdminAPITokenScope` JSON fields): + + 1. **`modules/pact/capabilities.go` (D-01, D-05, D-14):** + - Add `Group string` to `pact.TokenScope` right after `Description string` (mirroring `Permission.Tab`). + - Update the doc comment on `TokenScope` to state that `Group` is optional (empty falls back to plugin metadata in `cabana`) and accepts a phrase key containing `"::"` or literal text. + - Keep `HasTokenScopes`, `tokenScopeNameRE`, and `ValidTokenScopeName` completely untouched (D-01, D-05). + + 2. **`modules/cabana/token_scopes.go` (D-14):** + - Add `Group string` to `compiledTokenScope`. + - In `compileTokenScopes`, copy `Group: strings.TrimSpace(scope.Group)` onto each plugin's `compiledTokenScope`. Keep `PluginID: ""` and `Group: ""` on framework scopes (`*`, `admin:read`). + - In `validateTokenScopeMessageKeys`, check `[]string{scope.Label, scope.Description, scope.Group}` so any non-empty `Group` containing `"::"` must exist in `tr.Has(...)`, while empty `Group` and literal strings pass cleanly. + - Confirm `validatePluginTokenScope` does NOT require `Group` to be non-empty. + + 3. **`modules/cabana/account_tokens.go` & `modules/cabana/mcp_consent.go` (D-15, D-16, T-36-03):** + - Add `PluginID string \`json:"plugin_id"\`` and `Group string \`json:"group"\`` (no `omitempty`) to `AdminAPITokenScope`. + - Change `mapCompiledScope` signature to `mapCompiledScope(ctx context.Context, tr *phrasebook.Translator, reg *Registry, scope *compiledTokenScope) AdminAPITokenScope`. + - Populate `PluginID: scope.PluginID` and `Group: resolveScopeGroup(ctx, tr, reg, scope)`. + - Implement `resolveScopeGroup(ctx context.Context, tr *phrasebook.Translator, reg *Registry, scope *compiledTokenScope) string` following exact D-16 precedence: + - If `scope == nil || scope.PluginID == ""` (framework scopes `*` and `admin:read`): return `""`. + - Explicit `scope.Group != ""`: if `strings.Contains(scope.Group, "::")`, return `strings.TrimSpace(resolveScopePhrase(ctx, tr, scope.Group, scope.Group))`; otherwise return `scope.Group`. + - Fallback 1: `key := scope.PluginID + "::lang.plugin.name"`. If `tr != nil && tr.Has(key)`, let `s := strings.TrimSpace(tr.Get(ctx, key, nil))`; if `s != "" && s != key`, return `s`. + - Fallback 2: if `reg != nil && len(reg.permissions) > 0`: iterate deterministically over `reg.permissionOrder` (falling back to iterating `reg.permissions` only if `permissionOrder` is empty). For each registered permission `code` matched by any `pattern` in `scope.Permissions` via `scopeMatch(pattern, code) != matchNone`, inspect `p := reg.permissions[code]`. Trim `p.Tab`; if empty, unanimity fails. If `tab` contains `"::"`, resolve via `strings.TrimSpace(resolveScopePhrase(ctx, tr, tab, tab))`; if empty, unanimity fails. If any matched permission has a different resolved `tab` than the first matched permission, unanimity fails. If at least one permission matched and all matched permissions unanimously shared the same non-empty `tab`, return it. + - Fallback 3: return `scope.PluginID`. + - Update all 3 call sites of `mapCompiledScope`: + - `modules/cabana/account_tokens.go` (`s.accountTokenScopes`, pass `s.reg`) + - `modules/cabana/account_tokens.go` (`mapStoredScope`, pass `reg`; unknown stored scope continues returning zero-value `PluginID: ""` and `Group: ""`) + - `modules/cabana/mcp_consent.go` (`s.mcpConsentShow`, pass `s.reg`) + + + - `modules/pact/capabilities.go` contains `Group` field on `type TokenScope struct` and `tokenScopeNameRE` is unchanged (`git diff modules/pact/capabilities.go` shows no edit to `tokenScopeNameRE` or `ValidTokenScopeName`). + - `modules/cabana/token_scopes.go` checks `scope.Group` inside `validateTokenScopeMessageKeys` and stores `strings.TrimSpace(scope.Group)` on `compiledTokenScope`. + - `modules/cabana/account_tokens.go` defines `PluginID string \`json:"plugin_id"\`` and `Group string \`json:"group"\`` (no `omitempty`) on `AdminAPITokenScope` and implements `resolveScopeGroup` with all 3 D-16 fallback steps. + - All 3 `mapCompiledScope` call sites (`account_tokens.go` x2, `mcp_consent.go` x1) pass `reg` / `s.reg`. + - `go vet ./modules/pact ./modules/cabana && go test -short ./modules/pact ./modules/cabana` passes cleanly. + + + go vet ./modules/pact ./modules/cabana && go test -short ./modules/pact ./modules/cabana + non-zero exit, compile error, or "FAIL" in output + + `pact.TokenScope.Group`, `cabana` boot phrase-key validation, D-16 3-step fallback resolution, and `AdminAPITokenScope` `plugin_id`/`group` compile and pass existing short tests. + + + + Task 2: Export `cabana.TokenScopeCovers` and emit `pier.Mount` boot-time warning for uncovered backend write MCP tools (D-18) + modules/cabana/token_scopes_export.go, modules/pier/pier.go, modules/pier/uncovered_scopes_warning.go + + - modules/cabana/token_scopes_export.go (full file — `TokenScopeNames`, `TokenScopeLabels`, `tokenCatalogForApp`) + - modules/cabana/token_resolver.go (lines 70-120 — `publishedResolverGuard`) + - modules/cabana/token_scopes.go (lines 245-330 — `allowsUnderScope`, `scopeCoversAll`) + - modules/pier/pier.go (lines 90-170 — `Mount` and `compileCatalog` call site) + - modules/pier/catalog.go (lines 45-80 — `tool` struct fields `name`, `pluginID`, `decl.Permissions`, `method`, `guardName`) + - modules/pier/backend_guard.go (lines 1-40 — `BackendGuard`, existing `cabana` import) + - modules/pier/audit.go (lines 1-30 — `LogComponent`, `logger()`) + - .planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-PATTERNS.md (Patterns 4–5) + + + Implement the boot-time coverage check and structured warning (D-18, T-36-02): + + 1. **`modules/cabana/token_scopes_export.go`:** + - Add internal helper `tokenScopeCatalogFor(app *backpack.App, plugins []party.Plugin) *tokenScopeCatalog`: + 1. If `guard := publishedResolverGuard(app); guard != nil && guard.reg != nil && guard.reg.tokenScopes != nil`, return `guard.reg.tokenScopes`. + 2. Else if `len(plugins) > 0`, call `cat, err := compileTokenCatalog(plugins)`; if `err == nil`, return `cat` (if `err != nil`, return `nil` without panicking or failing boot). + 3. Else return `tokenCatalogForApp(app)`. + - Export `func TokenScopeCovers(app *backpack.App, plugins []party.Plugin, method string, permissions []string) bool`: + - Look up `cat := tokenScopeCatalogFor(app, plugins)`. If `cat == nil`, return `false`. + - Normalize `m := strings.ToUpper(strings.TrimSpace(method))`. If `m == ""`, return `false`. + - Iterate `cat.ordered`: + - Skip `scope.Name == scopeAll` (`*` never satisfies non-`*` coverage). + - Skip scopes where `!scope.Methods[m]`. + - If `scope.Full` (i.e. `admin:read` for `GET`/`HEAD`), return `true`. + - Append `scope.Permissions` to `scopes [][]string`. + - Return `scopeCoversAll(&bouncer.ScopeLimit{Scopes: scopes}, permissions)` (note: `scopeCoversAll` returns `false` when `len(permissions) == 0`, matching runtime `allowsUnderScope`, so backend write tools without `Permissions` are flagged as uncovered). + + 2. **`modules/pier/uncovered_scopes_warning.go` (new file) & `modules/pier/pier.go`:** + - Create `modules/pier/uncovered_scopes_warning.go` in `package pier` containing `warnUncoveredBackendWriteTools(app *backpack.App, plugins []party.Plugin, cat *catalog)`: + - Return immediately if `cat == nil || len(cat.tools) == 0`. + - Track uncovered tool names per plugin using `byPlugin := map[string][]string{}` and `pluginOrder := []string{}` (preserving first-seen plugin order). + - For each `t` in `cat.tools`: + - Skip unless `t.guardName == BackendGuard`. + - Skip if `t.method == http.MethodGet || t.method == http.MethodHead`. + - If `cabana.TokenScopeCovers(app, plugins, t.method, t.decl.Permissions)`, continue. + - Record `t.name` under `t.pluginID` (if not yet seen, append `t.pluginID` to `pluginOrder`). + - For each `pluginID` in `pluginOrder`: + - Sort `tools := byPlugin[pluginID]` with `slices.Sort(tools)` for deterministic log output. + - Emit ONE structured warning via `logger().Warn(...)`: + `logger().Warn("pier: plugin registers backend write MCP tools not covered by any non-* TokenScope; implement pact.HasTokenScopes so scoped tokens and MCP OAuth grants can call them", "plugin", pluginID, "tools", tools)` + - In `modules/pier/pier.go` inside `Mount`, call `warnUncoveredBackendWriteTools(app, plugins, cat)` immediately after `compileCatalog` succeeds (before returning or mounting handlers). Never return an error from this check (D-18). + + + - `modules/cabana/token_scopes_export.go` exports `func TokenScopeCovers(app *backpack.App, plugins []party.Plugin, method string, permissions []string) bool`. + - `modules/pier/uncovered_scopes_warning.go` exists and emits `logger().Warn(...)` with `"plugin"` and `"tools"` fields once per plugin with uncovered backend write MCP tools. + - `modules/pier/pier.go` invokes `warnUncoveredBackendWriteTools(app, plugins, cat)` right after `compileCatalog` without adding any error return path. + - `go vet ./modules/cabana ./modules/pier && go test -short ./modules/cabana ./modules/pier` passes cleanly (all existing `pier` tests remain green). + + + go vet ./modules/cabana ./modules/pier && go test -short ./modules/cabana ./modules/pier + non-zero exit, compile error, or "FAIL" in output + + `cabana.TokenScopeCovers` and `pier.Mount`'s structured per-plugin boot warning are wired and pass existing `cabana` and `pier` tests. + + + + Task 3: Add en/pl phrasebook copy, regenerate OpenAPI/TS schema, and update module READMEs & docs + modules/phrasebook/backend/lang/en/lang.yaml, modules/phrasebook/backend/lang/pl/lang.yaml, admin/openapi/admin.json, admin/src/api/schema.d.ts, modules/pact/README.md, modules/cabana/README.md, modules/pier/README.md, docs/backend/users-and-permissions.md, docs/services/mcp.md + + - .planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-UI-SPEC.md (lines 243-319 — verbatim EN/PL Copywriting Contract) + - modules/phrasebook/backend/lang/en/lang.yaml (lines 285-380, 410-422 — `api_tokens:`, `mcp_connect:`, CLDR plural format) + - modules/phrasebook/backend/lang/pl/lang.yaml (lines 305-402, 430-445 — `api_tokens:`, `mcp_connect:`, CLDR plural format) + - modules/pact/README.md (lines 95-130) + - modules/cabana/README.md (lines 80-115, 275-305) + - modules/pier/README.md (lines 125-160) + - docs/backend/users-and-permissions.md (lines 80-125) + - docs/services/mcp.md (lines 105-150) + + + 1. **Phrasebook (`modules/phrasebook/backend/lang/en/lang.yaml` and `pl/lang.yaml`):** + - Add all 44 new keys under `api_tokens:` matching `36-UI-SPEC.md` lines 251–296 verbatim, including the 3 CLDR plural maps: + - `scope_count` (`one`/`other` in EN; `one`/`few`/`many`/`other` in PL) + - `scope_write_count` (`one`/`other` in EN; `one`/`few`/`many`/`other` in PL) + - `scope_plugin_count` (`one`/`other` in EN; `one: ":count wtyczce"`, `few: ":count wtyczkach"`, `many: ":count wtyczkach"`, `other: ":count wtyczki"` in PL — locative form after `"w"`!) + - All remaining keys: `access_level`, `tier_full`, `tier_read_only`, `tier_custom`, `scope_customize`, `scope_more`, `scope_summary_line`, `scope_summary_admin_read_only`, `scope_summary_admin_read_plus`, `scope_summary_empty`, `scope_picker_title`, `scope_picker_description`, `scope_picker_apply`, `scope_picker_discard`, `scope_picker_back`, `scope_picker_selected`, `scope_picker_selected_admin_read`, `scope_picker_none_selected`, `scope_search_label`, `scope_search_placeholder`, `scope_search_clear`, `scope_filter_label`, `scope_filter_all`, `scope_filter_selected`, `scope_filter_read_only`, `scope_filter_reset`, `scope_also_admin_read`, `scope_also_admin_read_hint`, `via_admin_read`, `group_select_read`, `group_select_all`, `group_clear`, `group_select_read_named`, `group_select_all_named`, `group_clear_named`, `scope_empty_search_title`, `scope_empty_search_body`, `scope_empty_selected_title`, `scope_empty_selected_body`, `scope_empty_readonly_title`, `scope_empty_readonly_body`. + - Update `mcp_connect.subline` and add `mcp_connect.scope_picker_description` in both `en/lang.yaml` and `pl/lang.yaml` verbatim per `36-UI-SPEC.md` lines 300–303. + - Preserve all existing keys under `api_tokens:` and `mcp_connect:` so nothing breaks. + + 2. **OpenAPI & TypeScript Schema Regeneration:** + - Run `scripts/check-admin-openapi.sh` (without `--check`) to regenerate `admin/openapi/admin.json` and `admin/src/api/schema.d.ts` with required `plugin_id: string` and `group: string` on `cabana.AdminAPITokenScope`. + - Verify with `scripts/check-admin-openapi.sh --check`. + + 3. **Module READMEs & `docs/` (`CLAUDE.md` Documentation rules):** + - `modules/pact/README.md`: document optional `Group` field on `pact.TokenScope` (phrase key containing `::` or literal text, matching `Permission.Tab`). + - `modules/cabana/README.md`: document `PluginID` (`plugin_id`) and `Group` (`group`) on `cabana.AdminAPITokenScope` (including D-16 fallback resolution order) and add `cabana.TokenScopeCovers` to the API reference. + - `modules/pier/README.md`: document that `pier.Mount` checks backend write MCP tools against non-`*` `TokenScope`s via `cabana.TokenScopeCovers` and logs one structured `Warn` per plugin with uncovered tools without failing boot. + - `docs/backend/users-and-permissions.md`: document optional `TokenScope.Group` (and its `::` phrase-key boot check) and `plugin_id`/`group` fallback resolution. + - `docs/services/mcp.md`: note that backend write MCP tools should be covered by `pact.HasTokenScopes` and that `pier` logs a boot-time warning per plugin when any backend non-`GET`/`HEAD` tool is uncovered. + - Keep every cited Go identifier exact and neutral (never name any consuming application). Run `go test ./cmd/summer -run 'TestCommandsDocumented|TestDocsTree'` and `go run ./cmd/summer docs:build --check`. + + + - `modules/phrasebook/backend/lang/en/lang.yaml` and `pl/lang.yaml` parse cleanly under `go test -short ./modules/phrasebook` and contain all 46 new/updated keys (`access_level`, `via_admin_read`, `scope_plugin_count`, `mcp_connect.scope_picker_description`, etc.). + - `admin/openapi/admin.json` and `admin/src/api/schema.d.ts` both include required `plugin_id` and `group` properties on `cabana.AdminAPITokenScope`, and `scripts/check-admin-openapi.sh --check` exits 0. + - `go test ./cmd/summer -run 'TestCommandsDocumented|TestDocsTree' -count=1` and `go run ./cmd/summer docs:build --check` both exit 0. + - `go vet ./... && go test -short ./modules/pact ./modules/cabana ./modules/pier ./modules/phrasebook` exits 0. + + + go vet ./... && go test -short ./modules/pact ./modules/cabana ./modules/pier ./modules/phrasebook && scripts/check-admin-openapi.sh --check && go test ./cmd/summer -run 'TestCommandsDocumented|TestDocsTree' -count=1 && go run ./cmd/summer docs:build --check + non-zero exit, OpenAPI drift message, docs identifier error, or "FAIL" in output + + EN/PL phrasebook copy, OpenAPI/TS schema, and all module READMEs + `docs/` pages are updated and pass all Go, OpenAPI, and docs gates. + + + + + +Run full Wave 1 smoke & contract verification before advancing to Wave 2: +- `go vet ./... && go test -short ./modules/pact ./modules/cabana ./modules/pier ./modules/phrasebook` +- `scripts/check-admin-openapi.sh --check` +- `go test ./cmd/summer -run 'TestCommandsDocumented|TestDocsTree' -count=1 && go run ./cmd/summer docs:build --check` + + + +- `pact.TokenScope.Group`, `cabana` compilation/validation/D-16 fallback, `AdminAPITokenScope` `plugin_id`/`group`, `cabana.TokenScopeCovers`, and `pier.Mount` boot warning are all implemented and green. +- All 46 EN/PL phrasebook keys match `36-UI-SPEC.md` verbatim. +- `admin/openapi/admin.json` and `admin/src/api/schema.d.ts` are regenerated and pass `--check`. +- All module READMEs and `docs/` pages pass `TestDocsTree` and `docs:build --check`. + + + +After completion, create `.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-01-SUMMARY.md` + diff --git a/.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-02-PLAN.md b/.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-02-PLAN.md new file mode 100644 index 00000000..e5b2f114 --- /dev/null +++ b/.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-02-PLAN.md @@ -0,0 +1,322 @@ +--- +phase: 36-granular-mcp-oauth-api-token-scope-picker +plan: 02 +type: execute +wave: 2 +depends_on: ["36-01"] +files_modified: + - admin/src/styles/main.css + - admin/src/app/scopeCatalog.ts + - admin/src/components/scopes/useScopeSelection.ts + - admin/src/components/scopes/ScopeAccessControl.vue + - admin/src/components/scopes/ScopePicker.vue + - admin/src/views/ConnectView.vue + - admin/src/components/account/ApiTokenCreateDialog.vue + - admin/tests/fixtures/lang.json + - admin/tests/views/ConnectView.test.ts + - admin/tests/smoke/connect.smoke.test.ts + - admin/tests/account/ApiTokenCreateDialog.test.ts + - admin/tests/account/ApiTokensPanel.test.ts + - modules/boardwalk/dist/index.html +autonomous: true +requirements: [] +user_setup: [] +must_haves: + truths: + - "`ConnectView` consent card loading skeleton (`aria-busy=\"true\"`) mirrors client mark + segmented tier bar + summary box with no buttons until loaded." + - "`ApiTokenCreateDialog` scope catalog loading state renders a skeleton segmented tier bar + summary box while `GET /account/tokens/scopes` is in flight and keeps **Create token** disabled." + - "`ConnectView` and `ApiTokenCreateDialog` submit loading states disable fieldsets and buttons with a `LoaderCircle` spinner and prevent opening the Customize picker while busy." + - "`ConnectView` with zero grantable scopes displays the existing `none_grantable` alert in place of `ScopeAccessControl` and offers only **Deny** (D-03)." + - "`ScopeAccessControl` in `Custom` with 0 selected scopes displays actionable `scope_summary_empty` copy + **Customize scopes…** button and keeps **Allow** / **Create token** disabled (D-02)." + - "`ScopePicker` search with 0 matches renders a dashed empty block with `scope_empty_search_title`, `scope_empty_search_body` naming `:query`, and a **Clear search** button." + - "`ScopePicker` `Selected` filter with 0 selected scopes renders a dashed empty block with `scope_empty_selected_*` and a **Show all scopes** button." + - "`ScopePicker` `Read-only` filter with 0 read-only scopes renders a dashed empty block with `scope_empty_readonly_*` and a **Show all scopes** button." + - "`ScopePicker` with an empty draft disables **Apply scopes** and renders `scope_picker_none_selected` in the live footer so the user must pick at least one scope or discard (D-11)." + - "`ConnectView` preserves all Phase 32.2 load/submit/404/401/422/bad-URI error states, and 422 `scopes_required` highlights `ScopeAccessControl` in `border-danger` (D-03)." + - "`ApiTokenCreateDialog` preserves its `scopes_failed` alert and highlights `ScopeAccessControl` invalid + moves focus to it on 422 `errors.scopes`." + - "Small scope catalogs (`<= 3` groups or `<= 12` plugin scopes) expand all accordions automatically on picker open (D-07)." + - "Large scope catalogs (`> 3` groups and `> 12` plugin scopes) expand only groups with active selections on picker open (all collapsed if none selected), and typing a search auto-expands all matching groups without destroying pre-search expand state (D-07)." + - "Custom summary box displays elevated-first chips (`admin:read` if ON, then write scopes, then read-only scopes when `admin:read` is OFF), capped at 6 + clickable `+N more` chip + `\"X scopes across Y plugins\"` subtitle (D-04, D-06)." + - "Missing tiers are omitted from `RadioGroupRoot`; if no plugin scopes exist beyond `*` and `admin:read`, `Custom` tier is hidden (D-03); `ApiTokenCreateDialog` falls back to `Full (*)` when `admin:read` is absent (D-08); `ConnectView` opens in `Custom` when the client requested only a narrow plugin subset (D-03)." + - "Two plugins with identical translated `group` labels render separate flat accordions keyed by `${plugin_id}\\0${group}` (never colliding), sorted alphabetically with `Intl.Collator` and tie-broken by `plugin_id`, preserving declared intra-group scope order (D-01, D-17)." + - "Scope counts, write-scope counts, and plugin counts evaluate full CLDR plural keys (`one`/`few`/`many`/`other` in PL, `one`/`other` in EN) via `tc()`." + - "On mobile viewports (`< 640px`), `ConnectView` Customize scopes modal renders as a `100dvh` full-screen sheet with sticky search/filter header, independently scrollable accordion body, and sticky footer (D-10)." + - "On desktop viewports (`>= 640px`), `ConnectView` Customize modal is capped at `max-w-[640px] max-h-[85dvh]` and `ApiTokenCreateDialog` stays fixed at `max-w-[560px] max-h-[calc(100vh-32px)]` with sticky header/footer and zero double scrollbars (D-10, D-13)." + - "Long plugin group names, scope labels, mono codes, and descriptions use `[overflow-wrap:anywhere]`, and summary chips truncate safely inside `max-w-full` pills with full scope name in `:title`." + - "In ``, `ApiTokenCreateDialog` inherits `.dark` semantic tokens automatically while `ConnectView`'s card and portaled Customize modal apply `.connect-light-surface` (defined in `admin/src/styles/main.css` `@layer components`, pinning both `--c-*` and `--color-*` aliases) so they stay strictly light (D-12)." + - "Opening `ScopePicker` focuses the search input; closing restores focus to **Customize scopes…** (or checked tier radio); pressing Escape in `ApiTokenCreateDialog`'s swapped picker view discards draft (reverting tier if auto-opened empty) and returns to the token form preserving `name` and `expires` without closing the dialog (D-09, D-11, D-13); `mod+s`/`mod+enter` is inactive inside the picker view." + - "`ApiTokensPanel.vue` remains backwards-compatible with additive `plugin_id` and `group` fields on `AdminAPITokenScope` (D-15) and `scripts/check-admin-dist.sh` passes after rebuilding `modules/boardwalk/dist`." + artifacts: + - path: "admin/src/styles/main.css" + provides: "`.connect-light-surface` in `@layer components` pinning both `--c-*` and `--color-*` aliases" + contains: ".connect-light-surface" + - path: "admin/src/app/scopeCatalog.ts" + provides: "Pure catalog partitioning, `(plugin_id, group)` grouping/collation, query matching, smart expand, elevated-first summary builder, submitted-scope serializer, initial state resolver" + exports: ["partitionCatalog", "groupPluginScopes", "matchesScopeQuery", "isEffectivelySelected", "computeDefaultExpanded", "buildSummaryModel", "computeSubmittedScopes", "resolveInitialState"] + - path: "admin/src/components/scopes/useScopeSelection.ts" + provides: "Reactive 3-tier scope state, tier memory, auto-open empty Custom, draft/apply/discard composable" + exports: ["useScopeSelection"] + - path: "admin/src/components/scopes/ScopeAccessControl.vue" + provides: "Shared 3-tier `RadioGroupRoot` + compact effective-access summary box" + contains: "data-access-tiers" + - path: "admin/src/components/scopes/ScopePicker.vue" + provides: "Shared sticky-header / flat-accordion / sticky-footer scope picker with opt-in `admin:read` toggle and `via admin:read` lock" + contains: "data-scope-picker" + - path: "admin/src/views/ConnectView.vue" + provides: "Option D standalone `480px` consent card + responsive `.connect-light-surface` Customize modal" + contains: "data-scope-picker-dialog" + - path: "admin/src/components/account/ApiTokenCreateDialog.vue" + provides: "Option D personal token dialog with `Read-only` default and fixed `max-w-[560px]` in-dialog `ScopePicker` view swap" + contains: "data-action=\"scope-picker-back\"" + key_links: + - from: "admin/src/views/ConnectView.vue" + to: "admin/src/components/scopes/ScopePicker.vue" + via: "Reka `DialogPortal` with `.connect-light-surface` on `DialogOverlay` and `DialogContent`, state managed by `useScopeSelection(scopes, 'connect')`" + pattern: "useScopeSelection" + - from: "admin/src/components/account/ApiTokenCreateDialog.vue" + to: "admin/src/components/scopes/ScopePicker.vue" + via: "In-dialog `v-if=\"step === 1 && pickerOpen\"` view swap inside fixed `max-w-[560px]` `DialogContent`, Escape intercepted to call `onPickerCancel()`" + pattern: "useScopeSelection" + - from: "admin/src/components/scopes/ScopePicker.vue" + to: "admin/src/app/scopeCatalog.ts" + via: "`groupPluginScopes`, `matchesScopeQuery`, `isEffectivelySelected`, `computeDefaultExpanded`, `buildSummaryModel`" + pattern: "groupPluginScopes" + prohibitions: + - "Do NOT add any new npm dependencies or new `:root`/`.dark` CSS custom properties (`36-UI-SPEC.md`)." + - "Do NOT define `.connect-light-surface` in Vue `