Files
summercms/.planning/phases/19.7-generic-mcp-module/19.7-07-PLAN.md

45 KiB

phase, plan, type, wave, depends_on, gap_closure, files_modified, autonomous, requirements, estimate, must_haves
phase plan type wave depends_on gap_closure files_modified autonomous requirements estimate must_haves
19.7-generic-mcp-module 07 execute 2
19.7-06
true
modules/bouncer/mint.go
modules/bouncer/refresh.go
modules/bouncer/jwt.go
modules/bouncer/auth_time_smoke_test.go
modules/bouncer/README.md
docs/services/authentication.md
modules/pact/capabilities.go
modules/pact/mcp.go
modules/pact/README.md
modules/cabana/token_scopes.go
docs/plugins/registration.md
docs/backend/users-and-permissions.md
.planning/notes/2026-10-23-frontend-token-scopes.md
modules/pier/store.go
modules/pier/events.go
modules/pier/session.go
modules/pier/stateless.go
modules/pier/pier.go
modules/pier/host.go
modules/pier/README.md
modules/surf/pier_on.go
modules/towel/context.go
modules/towel/README.md
modules/cabana/account_tokens.go
modules/cabana/subject_events.go
modules/cabana/token_resolver.go
modules/cabana/account_contributions.go
modules/cabana/actions.go
modules/cabana/admin_openapi.go
modules/cabana/README.md
modules/phrasebook/backend/lang/en/lang.yaml
modules/phrasebook/backend/lang/pl/lang.yaml
docs/services/mcp.md
admin/openapi/admin.json
admin/src/api/schema.d.ts
admin/src/app/hotkeys.ts
admin/src/components/account/AccountContributions.vue
admin/tests/fixtures/lang.json
modules/boardwalk/dist
true
SC-4
D-04
D-05
D-17
D-19
D-26
D-27
D-34
E-2
tokens raw_tokens tasks confidence
130000 130000 5 low
truths artifacts key_links
A frontend or backend token minted at sign-in carries an auth_time claim; POST /refresh (any audience) copies it unchanged into the rotated token, and a token that had none is refreshed without one; plugins read it through bouncer.VerifyAuthTime, which applies the same signature, audience and expiry checks as VerifyClaims (C-CR-02 framework part, D-05)
A plugin declares member (frontend) personal-token scopes through pact.HasFrontendTokenScopes, a separate capability that cabana's admin token catalog never reads; pact.ValidTokenScopeName is the one name rule both catalogs use, and cabana's g15_ catalog behaves exactly as before (E-2 framework seam, decision P-30)
Revoking one admin personal token ends only the MCP sessions opened with that token; an event naming a client ends only that client's OAuth sessions; an event naming neither ends every session of the subject as before (B-WR-04, D-26, D-27)
A failed g15_ token attempt at /mcp is logged with the client address, and a resolver plugin can read the address from the context (B-IN-04)
An account contribution action can only hand the admin an http(s) or same-origin relative URL; the server drops anything else and the SPA refuses to render or open it (B-WR-03)
One contributing plugin's Status or Applies error no longer removes the other My account sections: the failing section is sent with error true, and a failed GET shows a toast (B-WR-06)
A typed character or Esc inside a plugin field type's shadow DOM never triggers a plain-key shortcut, and Ctrl/Cmd+S or Ctrl/Cmd+Enter commits a pending taglist draft before saving (B-WR-01, B-WR-02)
The published admin API contract says a prompted record action accepts payload, and admin.json, schema.d.ts and the committed admin dist match their sources (B-WR-05)
path provides contains
modules/bouncer/mint.go auth_time stamped at sign-in ClaimAuthTime
path provides contains
modules/bouncer/jwt.go the plugin-facing accessor func VerifyAuthTime(
path provides contains
modules/pact/capabilities.go the member token scope capability and the shared name rule type HasFrontendTokenScopes interface
path provides contains
.planning/notes/2026-10-23-frontend-token-scopes.md the recorded E-2 design decision HasFrontendTokenScopes
path provides contains
modules/towel/context.go client address on the context func ClientIP(
path provides contains
modules/cabana/account_contributions.go URL scheme rule and per-section isolation Error
from to via pattern
modules/bouncer/refresh.go modules/bouncer/mint.go refreshAudience passes the presented token's auth_time to the internal mint auth_time
from to via pattern
modules/cabana/account_tokens.go modules/pier/events.go the revoked event carries TokenID and pier closes only matching sessions TokenID
from to via pattern
modules/pier/pier.go modules/cabana/token_resolver.go bearer puts towel.WithClientIP on the resolve context; ResolveBackendToken logs it ClientIP
Close lane B of the phase code review (B-WR-01..B-WR-06 and the cheap B-IN items) and add the two framework pieces the plugins need in plan 08: - the `auth_time` claim that makes the account link's fresh-sign-in proof real (C-CR-02, framework part); - the plugin-declared member token scope seam escalated by sm-servers-app (E-2, `19.7-GAP-INPUTS.md`).

Serialization (planner decision, forced by file overlap):

  • The user confirmed waves 06 = 1, 07 = 1, 08 = 2 and 09 = 3. This plan instead depends on 19.7-06, which makes the waves 1, 2, 3 and 4.
  • The overlap: both plans edit modules/pier/{session,stateless,store,pier}.go, modules/pact/mcp.go and modules/pact/README.md. The token-specific revoke event in Task 3 also builds on 06's session and stateless matching code.
  • Disjoint file sets would have meant moving B-WR-04 out of this plan, against the confirmed split.
  • The plan count (four) and the execution order 06 → 07 → 08 → 09 are unchanged. The orchestrator reports the change to the user.

Planner decisions recorded here (P-29..P-33):

  • P-29 (auth_time, C-CR-02): the claim is auth_time (OIDC Core's name, NumericDate seconds), exported as bouncer.ClaimAuthTime.

    • MintAudience (and so Mint) stamps it equal to iat, because every direct mint is a sign-in: password login, auto-activated registration, activation by code, social login, the cabana admin login and its re-mint after a password change.
    • refreshAudience copies the presented token's value unchanged. A token without one is refreshed without one; it is never stamped "now".
    • Plugins read it with bouncer.VerifyAuthTime(tokenString, secret, audience string) (sub string, authTime time.Time, ok bool, err error), which runs exactly the checks VerifyClaims runs for AudienceUser and VerifyClaimsAudience runs for other audiences. ok is false when the claim is absent.
    • Settled by the review's suggested fix, so there is no decision checkpoint. Reversibility costly: once sessions carry the claim and plugins read it, renaming needs both names for a refresh window.
  • P-30 (E-2 seam, the open design point in GAP-INPUTS): a separate capability, not a reuse of pact.HasTokenScopes and not an audience field.

    • Shape: pact.FrontendTokenScope{Name, Label, Description} and pact.HasFrontendTokenScopes{ FrontendTokenScopes() []FrontendTokenScope }. This mirrors the existing Permission/FrontendPermission pair.
    • Reasons:
      1. The escalation asks for no change to the backend g15_ catalog. Reusing the interface would show every member scope in the admin's token catalog, and every admin scope in the member list.
      2. pact.TokenScope carries Permissions (cabana permission patterns) and Methods (an HTTP method filter). Neither applies to a member token, whose route middleware user.scope:<name> decides. cabana's boot validation requires both fields, so a member scope could not even be declared through it.
      3. An audience field would leave two fields meaningless for one audience, and cabana would have to skip entries silently.
    • pact.ValidTokenScopeName(name string) bool carries cabana's existing pattern, so both catalogs validate names identically. cabana switches to it with no behaviour change.
    • The framework never reads HasFrontendTokenScopes. The user plugin compiles it in plan 08, as it does HasFrontendPermissions.
    • Written down as .planning/notes/2026-10-23-frontend-token-scopes.md. Reversibility costly: a published framework API.
  • P-31 (token-specific revocation, B-WR-04 and the framework half of C-IN-02): pact.MCPSubjectChanged gains TokenID uint and ClientID string, and pier.Event carries both as omitempty JSON. For MCPSubjectRevoked:

    • a non-zero TokenID ends only the sessions whose subject under Guard has that TokenID and no ClientID (personal-token sessions);
    • a non-empty ClientID ends only the sessions whose subject has that ClientID;
    • neither ends every session of the subject (today's behaviour);
    • other kinds ignore the fields.

    cabana fires the admin token revoke with the token row id.

  • P-32 (client address, B-IN-04 and the seam for C-IN-04):

    • towel.WithClientIP and towel.ClientIP carry the client address on a context.
    • pier's bearer sets it before resolving, from the host's optional ClientIP(*http.Request) string (surf's adapter uses surf.ClientIP with http.trusted_proxies), falling back to the host part of RemoteAddr.
    • cabana.ResolveBackendToken logs it.
  • P-33 (My account seam, B-WR-03 and B-WR-06):

    • An action result URL is kept only when it is https/http absolute or same-origin relative (starts with one /, not //); anything else is dropped with an error log.
    • A section whose Status fails is sent with Status empty and Error: true (json:"error,omitempty", additive). An action whose Applies fails is omitted with a log. The list never answers 500 for one plugin's failure.

Purpose: lane B is fixed before v0.5.0, and plan 08 has bouncer.VerifyAuthTime, pact.HasFrontendTokenScopes, the token-specific events and towel.ClientIP to build on. Output: framework commits in bouncer, pact, pier, surf, towel and cabana; the admin SPA fixes with a rebuilt committed dist; the regenerated OpenAPI; docs; one decision note; one tracer smoke test.

<execution_context> @/.claude/msd-core/workflows/execute-plan.md @/.claude/msd-core/templates/summary.md </execution_context>

@.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.md @.planning/phases/19.7-generic-mcp-module/19.7-GAP-INPUTS.md @.planning/phases/19.7-generic-mcp-module/19.7-REVIEW.md @.planning/phases/19.7-generic-mcp-module/19.7-CONTEXT.md @.planning/phases/19.7-generic-mcp-module/19.7-01-SUMMARY.md @.planning/phases/19.7-generic-mcp-module/19.7-06-SUMMARY.md @CLAUDE.md

<project_rules>

  • Unit tests are plan 09's job. This plan carries one tracer smoke, TestAuthTimeSmoke, and keeps every existing test green. A test that pinned the old wrong behaviour (for example the per-admin session kill on token revoke) is changed in the fix commit and named in the SUMMARY.

  • Documentation rule: every exported API change updates the module README and the affected docs/ page in the same commit; summer docs:build --check must stay green.

  • Admin rule (CLAUDE.md): swag annotations change → scripts/check-admin-openapi.sh regenerates admin/openapi/admin.json and admin/src/api/schema.d.ts in the same commit; admin/ changes → npm --prefix admin run build, commit modules/boardwalk/dist, and scripts/check-admin-dist.sh passes. Run npm --prefix admin ci first if admin/node_modules is missing.

  • Response shapes stay as they are (core value): the only payload change is the additive error key on a My account section. Existing /account* and /auth/me payloads stay byte-identical (the gate checks modules/cabana/account.go against 51d088a; this plan must not touch that file).

  • Several sessions work in this repo, cabana especially: run git status --short modules/cabana modules/pier modules/pact admin modules/boardwalk/dist before every task and leave foreign edits alone. Stage by explicit path, one logical change per commit, no co-author tags; the decision note and the SUMMARY are planning docs in their own commits.

  • No new dependency (go.mod, go.sum, admin/package-lock.json unchanged).

  • Every commit is self-contained. At each commit:

    • the framework builds, go vet ./... is clean and the -short tests pass;
    • generated files (admin.json, schema.d.ts) match their annotations;
    • the committed admin dist matches the SPA source.

    No commit relies on a later task's commit.

  • Release rule: no tag, push or deploy in this plan. </project_rules>

Task 1: Tracer: auth_time is minted at sign-in, survives refresh unchanged and is readable through bouncer.VerifyAuthTime A JWT claim that plugins read (the account-link proof in plan 08); renaming it later needs both names accepted for a whole refresh window. modules/bouncer/mint.go, modules/bouncer/refresh.go, modules/bouncer/jwt.go, modules/bouncer/auth_time_smoke_test.go, modules/bouncer/README.md, docs/services/authentication.md - 19.7-REVIEW.md, section C-CR-02 (the failure scenario and the suggested fix) - modules/bouncer/mint.go (`registeredClaims`, `MintAudience`), refresh.go (`refreshAudience`, which calls `MintAudience` after its checks; `RefreshAudienceFor`), jwt.go (`VerifyClaims`, `VerifyClaimsAudience`, `verifyClaims`, `frontendAudienceOK`, `claimTime`) - modules/bouncer/mint_test.go and refresh_test.go (what the existing tests pin about the claim set) - modules/cabana/auth.go lines 200-270 and account.go around line 411 (the backend mints and refresh) - ../sm-demo-app/plugins/golem15/user/controllers/backend_link_controller.go (the consumer in plan 08: it re-reads the session token with `bouncer.VerifyClaims` today) - modules/bouncer/README.md (API reference table) and docs/services/authentication.md (token lifecycle section) Implement P-29 for C-CR-02.
In mint.go:
- Add the exported constant `ClaimAuthTime = "auth_time"`.
- Add `AuthTime *jwt.NumericDate \`json:"auth_time,omitempty"\`` to `registeredClaims`.
- Move the body of `MintAudience` into an unexported `mintAudience(secret, sub, issuerURL string, ttl time.Duration, audience string, authTime time.Time)`. It sets `AuthTime` when `authTime` is non-zero.
- `MintAudience` keeps its signature and calls `mintAudience` with `now`, so `auth_time` equals `iat` on every sign-in mint.

In refresh.go `refreshAudience`:
- Read the presented token's `auth_time` with `claimTime(claims, ClaimAuthTime)`.
- Mint the rotated token through `mintAudience` with that value. When the claim is absent, pass the zero time, so the rotated token carries none.
- Every exported refresh function keeps its signature.

In jwt.go, add `func VerifyAuthTime(tokenString, secret, audience string) (sub string, authTime time.Time, ok bool, err error)`:
- it runs exactly the verification `VerifyClaims` runs for `AudienceUser` (which accepts a frontend token without `aud`) and `VerifyClaimsAudience` runs for any other audience: signature, audience, `exp`, required claims;
- it returns the subject and the `auth_time` claim;
- `ok` is false when the claim is missing or not a number.

Update existing tests that compare the exact claim set of a minted token in the same commit.

New file `modules/bouncer/auth_time_smoke_test.go` holds `TestAuthTimeSmoke`:
1. `Mint` a token, then `VerifyAuthTime` returns `ok` and a time equal to `iat` (seconds).
2. Sleep past one second (or mint with a past clock through `mintAudience` from an in-package test), call `Refresh`, and `VerifyAuthTime` on the new token returns the original auth_time while its `iat` is later.
3. A token minted by the test with `registeredClaims` and no `AuthTime` refreshes into a token where `ok == false`.
4. A token with the wrong audience, a bad signature or past `exp` answers an error.

Docs in the same commit:
- modules/bouncer/README.md: API rows for `ClaimAuthTime` and `VerifyAuthTime`, and a Features line saying refresh keeps the sign-in time.
- docs/services/authentication.md: a short "Sign-in time (auth_time)" subsection explaining that a "fresh sign-in" check compares `auth_time`, never `iat`, because refresh renews `iat`.
go vet ./modules/bouncer/... ./modules/cabana/... && go test -count=1 -short ./modules/bouncer/... ./modules/cabana/... && go test -count=1 -short -run '^TestAuthTimeSmoke$' -v ./modules/bouncer/ 2>&1 | grep -q -- '^--- PASS: TestAuthTimeSmoke' && bash scripts/check-phase19.7.sh --docs non-zero exit, "FAIL" in the output, the PASS line missing, or the docs stage printing FAIL or "refuse:" - `grep -c 'ClaimAuthTime = "auth_time"' modules/bouncer/mint.go` prints 1 and `grep -c "func mintAudience(" modules/bouncer/mint.go` prints 1 - `grep -v '^\s*//' modules/bouncer/refresh.go | grep -c "mintAudience("` prints at least 1 and `grep -v '^\s*//' modules/bouncer/refresh.go | grep -c "ClaimAuthTime"` prints at least 1 - `grep -c "func VerifyAuthTime(tokenString, secret, audience string) (sub string, authTime time.Time, ok bool, err error)" modules/bouncer/jwt.go` prints 1 - `grep -c "VerifyAuthTime\|ClaimAuthTime" modules/bouncer/README.md` prints at least 2 and `grep -c "auth_time" docs/services/authentication.md` prints at least 1 - `grep -c "func TestAuthTimeSmoke(" modules/bouncer/auth_time_smoke_test.go` prints 1 Every sign-in mint carries auth_time, refresh never renews it, a legacy token stays without it, and plugins have one documented accessor; the smoke proves mint → refresh → read end to end. Task 2: The E-2 framework seam: pact.HasFrontendTokenScopes, the shared scope-name rule, and the recorded decision A published pact capability (decision P-30); plugins and the user plugin compile against it, so a later reshape needs a deprecation cycle. modules/pact/capabilities.go, modules/cabana/token_scopes.go, modules/pact/README.md, docs/plugins/registration.md, docs/backend/users-and-permissions.md, .planning/notes/2026-10-23-frontend-token-scopes.md - .planning/phases/19.7-generic-mcp-module/19.7-GAP-INPUTS.md, section "E-2" (the ask, "Not asked for", acceptance and the open design point) - modules/pact/capabilities.go (`TokenScope`, `HasTokenScopes`; the doc at line ~367 on prompted record actions is Task 4's); modules/pact/mcp.go (`FrontendPermission`, `HasFrontendPermissions`, the style to mirror) - modules/cabana/token_scopes.go (`tokenScopeNameRE`, `validatePluginTokenScope`) - modules/pact/README.md (Features list and type table rows for TokenScope and FrontendPermission); docs/plugins/registration.md (capability table, lines ~80-95); docs/backend/users-and-permissions.md (the `pact.HasTokenScopes` section around line 92) - .planning/notes/ (an existing decision note's shape, for example 2026-10-22-mcp-go-sdk.md) Implement P-30.
In modules/pact/capabilities.go, next to `TokenScope`/`HasTokenScopes`:
- `type FrontendTokenScope struct { Name, Label, Description string }`. Doc: one scope of the user plugin's member personal API tokens (`usr_`). Label and Description are phrase keys (containing "::") or literal text. The name is what a route's `user.scope:<name>` middleware checks.
- `type HasFrontendTokenScopes interface { FrontendTokenScopes() []FrontendTokenScope }`. Doc: the frontend counterpart of `HasTokenScopes`. The framework's admin token catalog never reads it; the plugin that owns member tokens compiles it.
- `func ValidTokenScopeName(name string) bool`, with the pattern `^[a-z][a-z0-9_-]*(:[a-z][a-z0-9_-]*)?$` compiled once in pact. Doc: the one name rule for both catalogs.

In modules/cabana/token_scopes.go, replace the body of the name check with `pact.ValidTokenScopeName`. Remove the local regexp only if nothing else uses it. Every error message stays word for word.

Docs in the same commit:
- modules/pact/README.md: a Features line and two type rows plus the function row.
- docs/plugins/registration.md: a capability table row.
- docs/backend/users-and-permissions.md: one paragraph after the `pact.HasTokenScopes` section saying member token scopes are declared with `pact.HasFrontendTokenScopes`, appear only in the member token list, and never in the admin catalog.

Write `.planning/notes/2026-10-23-frontend-token-scopes.md` (title "Decision: member token scopes use a separate pact capability") with these sections:
- Context: the E-2 escalation, with what was asked and what was not;
- Options: reuse `HasTokenScopes`, an audience field, a separate interface;
- Decision and reasons: the three reasons in P-30;
- Consequences: the user plugin compiles and validates the scopes and fails boot on bad ones; the cabana catalog is unchanged; `pact.ValidTokenScopeName` is shared;
- Related: GAP-INPUTS E-2, plan 08 Task 3.

Commit the note separately as a planning doc.
go vet ./modules/pact/... ./modules/cabana/... && go test -count=1 -short ./modules/pact/... ./modules/cabana/... && go test -count=1 -short -run '^(TestPactStaysSDKFree|TestPhase197ContractsOnSamplePlugin)$' -v ./modules/pact/ 2>&1 | grep -c -- '^--- PASS: Test' | grep -qx 2 && bash scripts/check-phase19.7.sh --docs && bash scripts/check-phase19.7.sh --marker non-zero exit, "FAIL" in the output, fewer than 2 PASS lines, or a gate stage printing FAIL or "refuse:" - `grep -c "type FrontendTokenScope struct\|type HasFrontendTokenScopes interface\|func ValidTokenScopeName(" modules/pact/capabilities.go` prints 3 - `grep -v '^\s*//' modules/cabana/token_scopes.go | grep -c "pact.ValidTokenScopeName("` prints at least 1 - `grep -rn "HasFrontendTokenScopes" modules/cabana --include=*.go | grep -v _test | wc -l` prints 0 (cabana never reads the member capability) - `grep -c "HasFrontendTokenScopes" modules/pact/README.md docs/plugins/registration.md docs/backend/users-and-permissions.md` prints at least 1 per file - `test -f .planning/notes/2026-10-23-frontend-token-scopes.md && grep -c "HasTokenScopes\|audience" .planning/notes/2026-10-23-frontend-token-scopes.md` prints at least 2 The framework offers the member token scope capability and one shared name rule, cabana's admin catalog is untouched in behaviour, and the E-2 design decision is recorded as a note. Task 3: Token- and client-specific revocation events, and the client address on pier's resolve path New fields on the published pact.MCPSubjectChanged event and on pier.Event's wire JSON between instances (additive and omitempty, so mixed-version instances ignore them). modules/pact/mcp.go, modules/pier/store.go, modules/pier/events.go, modules/pier/session.go, modules/pier/stateless.go, modules/pier/pier.go, modules/pier/host.go, modules/surf/pier_on.go, modules/towel/context.go, modules/cabana/account_tokens.go, modules/cabana/subject_events.go, modules/cabana/token_resolver.go, modules/pact/README.md, modules/pier/README.md, modules/towel/README.md, modules/cabana/README.md, docs/services/mcp.md - 19.7-REVIEW.md, sections B-WR-04, B-IN-04 and C-IN-02 - modules/pact/mcp.go: `MCPSubjectChanged`, `MCPSubject` (ClientID, TokenID) - modules/pier/events.go (`listenEvents`, `handleEvent`), store.go (`Event`), session.go (`matching`, and the matching method 06 left), stateless.go (`matching`, `evict`), identity.go (`Identity.has`, `subjectFor`; which subjects carry ClientID and TokenID for OAuth, personal frontend and admin `g15_` tokens) - modules/pier/pier.go `bearer` (where `identities.resolve` is called); host.go (`Host`); modules/surf/pier_on.go (`pierHost`, `mountPier`); modules/surf/clientip.go (`ClientIP`, `TrustedProxies`) - modules/towel/context.go (`withValue`, `stringValue`, `WithActor`/`Actor` as the model) - modules/cabana/account_tokens.go around line 155-170 (the revoke handler) and subject_events.go (`fireSubjectChanged`); token_resolver.go (`ResolveBackendToken`, its `logTokenAuthAt` calls) and token_guard.go (`logTokenAuthAt`) **P-31.** - In pact/mcp.go, add `TokenID uint` and `ClientID string` to `MCPSubjectChanged`. Rewrite its doc to state the narrowing rule for `MCPSubjectRevoked`; other kinds ignore both fields. - In pier/store.go, add `TokenID uint \`json:"token_id,omitempty"\`` and `ClientID string \`json:"client_id,omitempty"\`` to `Event`. - `listenEvents` copies both. - In `handleEvent`'s revoked/deleted branch, select sessions with a predicate: - with `TokenID != 0`: sessions whose subject under `ev.Guard` has that `TokenID` and an empty `ClientID`; - with `ClientID != ""`: sessions whose subject under `ev.Guard` has that `ClientID`; - otherwise: today's `has(guard, userID)`. - Deleted events always use the whole subject. - Add the predicate form to `sessionRouter.matching` and to `statelessPath.matching`/`evict`, keeping the existing signatures as wrappers. - In cabana/subject_events.go, add an unexported `fireTokenRevoked(ctx, app, adminID, tokenID uint)` that fires `&pact.MCPSubjectChanged{Guard: "backend", UserID: adminID, Kind: pact.MCPSubjectRevoked, TokenID: tokenID}` like `fireSubjectChanged`. - In account_tokens.go, the revoke handler calls it with `row.ID` instead of the per-admin event. Fix the misleading comment above the call so it says which sessions end.
**P-32.**
- In towel/context.go, add `WithClientIP(ctx context.Context, ip string) context.Context` and `ClientIP(ctx context.Context) (string, bool)` on an unexported key, following `WithActor`/`Actor`.
- In pier, declare an unexported interface in host.go, `clientIPHost interface{ ClientIP(*http.Request) string }`. Document it as optional for hosts.
- In surf/pier_on.go, `pierHost` gains a `trusted []netip.Prefix` field, filled in `mountPier` from `TrustedProxies(app.Config)`, and a `ClientIP` method calling `ClientIP(req, h.trusted)`.
- In pier.go `bearer`, before `p.identities.resolve`, wrap the context with `towel.WithClientIP`. Use the host's answer when it implements the interface; otherwise use the host part of `r.RemoteAddr` (`net.SplitHostPort`, or the raw value on error).
- In cabana/token_resolver.go, pass `towel.ClientIP(ctx)` as the `remote` of every `logTokenAuthAt` call in `ResolveBackendToken`.

Docs in the same commit:
- pact README: the `MCPSubjectChanged` row.
- pier README: the fan-out section's narrowing rule.
- towel README: the API rows.
- cabana README: the token revoke event and resolver logging.
- docs/services/mcp.md: the fan-out paragraph.
go vet ./... && go vet -tags summercms_mcp ./modules/surf/... ./modules/pier/... && go test -count=1 -short ./modules/pier/... ./modules/pact/... ./modules/towel/... ./modules/cabana/... && go test -count=1 -short -tags summercms_mcp ./modules/pier/... ./modules/surf/... && go test -count=1 -short -run '^(TestFanOut|TestPierFanOutSmoke|TestFireSubjectChangedReachesPointerListener)$' -v ./modules/pier/ ./modules/cabana/ 2>&1 | grep -c -- '^--- PASS: Test' | grep -qx 3 && bash scripts/check-phase19.7.sh --docs && bash scripts/check-phase19.7.sh --marker non-zero exit, "FAIL" in the output, fewer than 3 PASS lines, or a gate stage printing FAIL or "refuse:" - `grep -A6 "type MCPSubjectChanged struct" modules/pact/mcp.go | grep -c "TokenID\|ClientID"` prints 2 - `grep -c 'json:"token_id,omitempty"\|json:"client_id,omitempty"' modules/pier/store.go` prints 2 - `grep -v '^\s*//' modules/pier/events.go | grep -c "TokenID\|ClientID"` prints at least 2 - `grep -v '^\s*//' modules/cabana/account_tokens.go | grep -c "fireTokenRevoked("` prints 1 - `grep -c "func WithClientIP(\|func ClientIP(" modules/towel/context.go` prints 2 and `grep -v '^\s*//' modules/cabana/token_resolver.go | grep -c "towel.ClientIP("` prints at least 1 - `grep -v '^\s*//' modules/pier/pier.go | grep -c "towel.WithClientIP("` prints 1 and `grep -c "func (h pierHost) ClientIP(" modules/surf/pier_on.go` prints 1 Revoking one admin token ends only what that token opened; the event shape can also target one OAuth client (used by the plugins in plan 08); failed g15_ attempts at /mcp carry the client address and resolvers can read it. Task 4: cabana admin API: account action URL rule, per-section isolation, localized texts, the prompted record action contract, regenerated OpenAPI modules/cabana/account_contributions.go, modules/cabana/actions.go, modules/cabana/admin_openapi.go, modules/pact/capabilities.go, modules/cabana/README.md, modules/phrasebook/backend/lang/en/lang.yaml, modules/phrasebook/backend/lang/pl/lang.yaml, admin/tests/fixtures/lang.json, admin/openapi/admin.json, admin/src/api/schema.d.ts - 19.7-REVIEW.md, sections B-WR-03 (server part), B-WR-05, B-WR-06 (server part), B-IN-02, B-IN-03, B-IN-05 - modules/cabana/account_contributions.go (`accountContributionsList`, `AccountContributionView`, the action handler around line 200 that writes `AccountActionResultView{URL: result.URL}`); modules/cabana/crud.go `localizeDetail` - modules/cabana/actions.go lines 240-280 (`promptRequiredKey` and the three prompt refusals) - modules/cabana/admin_openapi.go lines 790-830 (`AdminRecordAction` description, the body param text, `AdminActionRequest.Payload`) and the My account contributions annotations (the view type's doc) - modules/pact/capabilities.go around line 367 (the prompted record action doc that promises a validation error on the input) - modules/phrasebook/backend/lang/en/lang.yaml `form:` and `myaccount:` sections, the pl twin, admin/tests/fixtures/lang.json - scripts/check-admin-openapi.sh (how to regenerate vs `--check`) **B-WR-03, server (P-33).** Before `WriteData` in the action handler, keep `result.URL` only when one of these holds: - `url.Parse` succeeds with scheme `https` or `http` and a host; - or it is a same-origin relative reference (starts with exactly one `/`, not `//`, and has no scheme).
Otherwise set it to "" and log `cabana: account contribution action answered a non-http URL` with section and action, never the URL itself.

**B-WR-06, server (P-33).**
- Add `Error bool \`json:"error,omitempty"\`` to `AccountContributionView`, documented as "the section's status could not be loaded".
- When `Status` errors, log as today, leave `Status` empty, set `Error`, and continue.
- When an action's `Applies` errors, log and skip that action.
- The handler never answers 500 for a plugin's error. A database or registry failure outside the plugin hooks still does.

**B-IN-03.** Translate a section's status with `localizeDetail(ctx, tr, status)` instead of `translateKey`.

**B-IN-02.** In actions.go, replace the hard-coded English refusal for a non-string payload with the phrase key `backend::lang.form.action_prompt_invalid` (en "The answer must be text." / pl "Odpowiedź musi być tekstem."), added to both lang files and to admin/tests/fixtures/lang.json.

**B-IN-05.** Rewrite the sentence in pact/capabilities.go that promises a validation error on the input. It should say what happens: the admin refuses the value with a 422 whose message is shown as a toast, and the prompt dialog closes. The dialog-stays-open UX is deferred (recorded by plan 09 in deferred-items).

**B-WR-05, in admin_openapi.go.** Replace the stale sentence in the `AdminRecordAction` description with: the body is `{}` for an action without a prompt; an action whose record response carries `prompt` takes `{"payload": "<text>"}`, trimmed, non-empty and at most `prompt.max_length` runes, with a 422 on `payload` otherwise. Make these match:
- the body param text: "Empty object, or {"payload": text} for a prompted action";
- the `AdminActionRequest.Payload` comment: toolbar routes refuse it; record routes accept a JSON string only for a prompted action.

Document the new `error` key wherever the contribution view type is annotated.

Run `scripts/check-admin-openapi.sh` to regenerate admin/openapi/admin.json and admin/src/api/schema.d.ts, then `scripts/check-admin-openapi.sh --check`. The cabana README's My account section gains the URL rule and the `error` flag. Commit the code, the generated files and the docs together.
go vet ./modules/cabana/... ./modules/pact/... && go test -count=1 -short ./modules/cabana/... ./modules/pact/... && go test -count=1 -short -run '^(TestAccountContributions|TestAccountContributionsSmoke|TestRecordActionPrompt|TestRecordActionPromptSmoke)$' -v ./modules/cabana/ 2>&1 | grep -c -- '^--- PASS: Test' | grep -qx 4 && bash scripts/check-admin-openapi.sh --check && bash scripts/check-phase19.7.sh --docs non-zero exit, "FAIL" in the output, fewer than 4 PASS lines, an OpenAPI drift report, or the docs stage printing FAIL or "refuse:" - `grep -c 'json:"error,omitempty"' modules/cabana/account_contributions.go` prints 1 and `grep -c "non-http URL" modules/cabana/account_contributions.go` prints 1 - `grep -v '^\s*//' modules/cabana/account_contributions.go | grep -c "localizeDetail("` prints at least 1 - `grep -c "action_prompt_invalid" modules/cabana/actions.go modules/phrasebook/backend/lang/en/lang.yaml modules/phrasebook/backend/lang/pl/lang.yaml admin/tests/fixtures/lang.json` prints at least 1 per file - `grep -c "payload are all refused" modules/cabana/admin_openapi.go admin/openapi/admin.json` prints 0 for both files and `grep -c "prompt.max_length" admin/openapi/admin.json` prints at least 1 - `bash scripts/check-admin-openapi.sh --check` exits 0 - `git diff --quiet 51d088a -- modules/cabana/account.go` (My account's own handlers untouched) The admin API only hands out safe URLs, one broken contributing plugin cannot blank My account, the remaining English text is localized, the prompted-action contract is published correctly and the generated API files match. Task 5: Admin SPA: shadow-DOM-aware plain keys, commit-before-save shortcuts, safe account links, the section error state and My account texts; rebuilt dist admin/src/app/hotkeys.ts, admin/src/components/account/AccountContributions.vue, modules/phrasebook/backend/lang/en/lang.yaml, modules/phrasebook/backend/lang/pl/lang.yaml, admin/tests/fixtures/lang.json, modules/boardwalk/dist - 19.7-REVIEW.md, sections B-WR-01, B-WR-02, B-WR-03 (SPA part), B-WR-06 (SPA part), B-IN-01, B-IN-06 - admin/src/app/hotkeys.ts (`isEditableTarget` at ~100-105, `onModifierKey` at ~187-206 with `target.click()`, `onPlainKey` at ~208-236) - admin/src/components/form/fields/TaglistField.vue (`addDraft` on blur and Enter, lines ~73 and ~167) - admin/src/components/account/AccountContributions.vue (`load`, the confirm texts at ~52 and ~78, `links` and `window.open` at ~43-46 and ~103-111) - admin/tests/app/hotkeys.test.ts and admin/tests/account/AccountContributions.test.ts (existing expectations to keep green) - modules/phrasebook/backend/lang/en/lang.yaml `myaccount:` and `form:` sections - scripts/check-admin-dist.sh **B-WR-01.** - In hotkeys.ts, add `originOf(event)`: the first entry of `event.composedPath()` when available, else `event.target`. - `onPlainKey` tests `isEditableTarget(originOf(event))`. - `isEditableTarget` also treats any element whose tag name contains `-` (a custom element) and that sits inside a `form` or `[role=form]` as editable. That covers closed shadow roots, where `composedPath()` stops at the host.
**B-WR-02.** In `onModifierKey`, before `target.click()`:
- when `document.activeElement` is an element other than the target and has `blur`, call `blur()`, so TaglistField's `addDraft` and native `change` run as a pointer click would trigger them;
- restore focus to the element after the click only when it is still in the document and the view did not navigate (keep it simple: refocus when `isConnected`).

**B-WR-03, SPA.** In AccountContributions.vue, add `safeUrl(u: string): string`, returning the value only for `/^https?:\/\//i` or a single-slash relative path, else ''. Use it for both the rendered `href` and `window.open`. An unsafe URL is never bound and never opened. B-IN-06 stays as is: the visible link remains the fallback for a blocked popup, with no code change.

**B-WR-06, SPA.**
- On a non-2xx GET of the contributions, show a toast with `backend::lang.form.error_generic` and keep the previous sections.
- A section with `error: true` renders a muted line `backend::lang.myaccount.section_error` (en "This section could not be loaded." / pl "Nie udało się wczytać tej sekcji.").

**B-IN-01.** Use the new keys `backend::lang.myaccount.action_confirm` (en "Run “:action”?" / pl "Wykonać „:action”?") and `backend::lang.myaccount.action_stale` (en "This action no longer applies. The page has been refreshed." / pl "Ta akcja nie ma już zastosowania. Strona została odświeżona.") in place of the record-oriented form texts.

Add every new key to the en and pl lang files and to admin/tests/fixtures/lang.json. Adjust existing vitest expectations that asserted the record-oriented texts in the same commit (plan 09 adds the new tests).

Run `npm --prefix admin run typecheck`, `npm --prefix admin run test`, `npm --prefix admin run build`, then `scripts/check-admin-dist.sh`. Commit the SPA source, the lang changes and the rebuilt `modules/boardwalk/dist` in one commit, so `check-admin-dist.sh` passes at that commit (self-contained rule).
npm --prefix admin run typecheck && npm --prefix admin run test 2>&1 | grep -E 'Test Files +[0-9]+ passed' | grep -qv failed && bash scripts/check-admin-dist.sh && bash scripts/check-phase19.7.sh --admin non-zero exit, a failed or skipped vitest file, a dist drift report from check-admin-dist.sh, or the admin stage printing FAIL, "refuse:" or "missing-named" - `grep -c "composedPath" admin/src/app/hotkeys.ts` prints at least 1 and `grep -v '^\s*//' admin/src/app/hotkeys.ts | grep -c "\.blur()"` prints at least 1 - `grep -c "safeUrl" admin/src/components/account/AccountContributions.vue` prints at least 3 (definition, href binding, window.open) - `grep -c "myaccount.action_confirm\|myaccount.action_stale\|myaccount.section_error" admin/src/components/account/AccountContributions.vue` prints at least 3 - `grep -c "section_error\|action_confirm\|action_stale" modules/phrasebook/backend/lang/pl/lang.yaml` prints at least 3 and the same keys are in admin/tests/fixtures/lang.json - `bash scripts/check-admin-dist.sh` exits 0 at the task's commit (source and dist in the same commit) Typing inside plugin field types is safe from plain shortcuts, keyboard saves include pending drafts, My account never renders or opens a script URL, a broken section shows an error instead of vanishing, the texts fit My account, and the embedded SPA matches its source.

<artifacts_this_phase_produces>

Artifacts this plan produces

Framework code (summercms.go, local commits on master):

  • bouncer: ClaimAuthTime, VerifyAuthTime, the auth_time mint and refresh carry-over.
  • pact:
    • FrontendTokenScope, HasFrontendTokenScopes, ValidTokenScopeName;
    • MCPSubjectChanged.TokenID and ClientID;
    • the corrected prompted-action doc.
  • pier: event narrowing, Event.TokenID/ClientID, the client address on the resolve context, and the optional host capability.
  • surf: pierHost.ClientIP.
  • towel: WithClientIP and ClientIP.
  • cabana:
    • the token-specific revoke event;
    • the resolver's remote address;
    • the account action URL rule, the section error flag and status localization;
    • the localized payload refusal;
    • the corrected record action annotations.

Admin SPA:

  • hotkeys.ts (composedPath, blur before click);
  • AccountContributions.vue (safeUrl, the error state, the My account texts);
  • the rebuilt modules/boardwalk/dist;
  • the regenerated admin/openapi/admin.json and admin/src/api/schema.d.ts.

Docs:

  • READMEs: bouncer, pact, pier, towel, cabana;
  • docs/services/authentication.md, docs/services/mcp.md, docs/plugins/registration.md, docs/backend/users-and-permissions.md.

Decision note: .planning/notes/2026-10-23-frontend-token-scopes.md (E-2, P-30).

Test: modules/bouncer/auth_time_smoke_test.go (TestAuthTimeSmoke). </artifacts_this_phase_produces>

<threat_model>

Trust Boundaries

Boundary Description
browser session to the token refresh endpoints any holder of a token inside its refresh window can rotate it without a password
plugins to the admin token catalog and the member token catalog plugins declare scope names that end up on stored tokens
plugin account actions to the admin SPA a plugin answers a URL the admin's browser renders and opens
admin and plugins to pier's fan-out revocation events decide which live MCP sessions end
MCP clients to the token resolvers failed attempts must be traceable to an address

STRIDE Threat Register

Threat ID Category Component Severity Disposition Mitigation Plan
T-19.7-51 Spoofing the fresh-sign-in proof (D-05) high mitigate auth_time stamped only at sign-in, copied unchanged by refresh, absent stays absent; VerifyAuthTime checks signature, audience and expiry; plan 08 makes the link confirm compare auth_time; TestAuthTimeSmoke here, TestAuthTime and TestBackendLinkAuthTime in plan 09
T-19.7-52 Elevation of privilege member scopes crossing into the admin token catalog, or the reverse medium mitigate separate capability that cabana never reads (acceptance grep); one shared name rule pact.ValidTokenScopeName
T-19.7-53 Tampering a javascript:/data: URL from an account action rendered into href or window.open medium mitigate server keeps only http(s) and same-origin relative URLs; SPA safeUrl on both sinks
T-19.7-54 Denial of service revoking one token ends every MCP session of the admin, including OAuth sessions of the linked user low mitigate token-specific revoked event; client-specific variant for plan 08
T-19.7-55 Repudiation failed g15_ attempts at /mcp logged without a client address low mitigate towel client address on the resolve context, logged by ResolveBackendToken
T-19.7-56 Information disclosure one plugin's error silently hides other plugins' My account sections (including the Unlink action) low mitigate per-section isolation with the error flag and a toast on a failed GET
T-19.7-SC Tampering package installs low mitigate no package added; npm --prefix admin ci installs the committed lock only; go.mod, go.sum and admin/package-lock.json unchanged
</threat_model>
- `go vet ./... && go test -count=1 -short ./...` and `go test -count=1 ./modules/cabana/...` on a Docker host (the cabana Postgres suites, through `sudo -u golem` if the socket is denied) - `bash scripts/check-phase19.7.sh --go`, `--admin`, `--docs` and `--marker` print PASS - `cd examples/hello && go test ./...` stays green - `git diff --quiet 51d088a -- modules/cabana/account.go`

<success_criteria>

  • B-WR-01..B-WR-06 fixed; B-IN-01, B-IN-02, B-IN-03 and B-IN-04 fixed; B-IN-05's contract text corrected (the UX deferral is recorded by plan 09); B-IN-06 needs no change
  • bouncer.VerifyAuthTime, pact.HasFrontendTokenScopes, pact.ValidTokenScopeName, pact.MCPSubjectChanged.TokenID/ClientID and towel.ClientIP exist with docs, ready for plan 08
  • The E-2 design decision is recorded (P-30 and the note)
  • No exported identifier removed; every response shape unchanged except the additive error key </success_criteria>
Create `.planning/phases/19.7-generic-mcp-module/19.7-07-SUMMARY.md` when done, with every commit sha mapped to its finding ids. Commit the SUMMARY separately as a planning doc.

Release rule: this plan does not tag, push or deploy. Every repository works against the local framework (go.work, or replace ../summercms.go), and every plugin's go.mod require line stays at its current version. The plans may commit locally in every repository. The releases happen only after phase verification, in this order: framework v0.5.0, then the plugin tags that require it, then the application bumps.