spec rev 3: parity guard, command registry (Astra round 2)
CLI command registry the CLI dispatches from, console route declaration list with per-configuration equality, qualified shared CLI members, migration steps 0-7 with a gated legacy adapter, census per CLI step, docsite projection on the registry. Round 3 review brief.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+271
−67
docs/superpowers/specs/2026-11-09-parity-guard-design.md+220 −67docs/superpowers/specs/CODEX-REVIEW-BRIEF-parity-guard-R3.md+51 −0
Intent
Attributed to this commit: 20.6 g CO₂e (1,286,452 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-parity-guard, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/specs/2026-11-09-parity-guard-design.md b/docs/superpowers/specs/2026-11-09-parity-guard-design.md| index 830d14de2..ae9e3e6fd 100644 |
| --- a/docs/superpowers/specs/2026-11-09-parity-guard-design.md |
| +++ b/docs/superpowers/specs/2026-11-09-parity-guard-design.md |
| @@ -1,9 +1,12 @@ |
| # CLI and console parity: the stock and its guard (slice 3) |
| -Status: rev 2 for Paul, 2026-11-09. Astra round 1: |
| +Status: rev 3 for Paul, 2026-11-09. Astra round 1: |
| `CODEX-FINDINGS-parity-guard.md` (NOT READY: P1 CLI enumeration, three P2s), |
| -all accepted, marked **(codex N)**. Slice 3 of "agent-first onboarding and |
| -console parity". |
| +all accepted, marked **(codex N)**. Astra round 2: |
| +`CODEX-FINDINGS-parity-guard-R2.md` (NOT READY, stopping rule 2: P1 CLI |
| +enumeration, three P2s), all accepted, marked **(codex R2-N)**. Paul's ruling |
| +after round 2: enumerate from registries the code dispatches from, not from |
| +scanners. Slice 3 of "agent-first onboarding and console parity". |
| ## Why |
| @@ -38,8 +41,9 @@ listed apart. |
| - a row names a CLI command or console route that no longer exists; |
| - a row's status is not one of the allowed values, or a `gap` row has no |
| work package, or a `cli-only`/`console-only` row has no reason. |
| - Both lists are derived from the real code (the CLI's command dispatch and |
| - the console's route registrations), never from a second hand-kept list. |
| + Both lists come from registries production dispatches from (the CLI |
| + command registry and the console route declaration list, below), never |
| + from a scanner or a second hand-kept list **(codex R2-1, R2-3, R2-4)**. |
| The failure message says exactly which row to add or fix. |
| 3. **A readable view:** `docs/parity.md`, generated from the table |
| (`make parity-doc`), grouped by area, with counts per status at the top; |
| @@ -63,7 +67,8 @@ listed apart. |
| ## Non-goals |
| -Closing any gap (each package is its own later design); the MCP connector; |
| +Closing any gap (each package is its own later design); the MCP connector |
| +(slice 4; the CLI registry carries what it will need, nothing is built); |
| judging whether a console page is good (only whether the capability exists); |
| API-door parity (`/api/cli/*` vs CLI is already one-to-one by construction). |
| @@ -76,72 +81,220 @@ API-door parity (`/api/cli/*` vs CLI is already one-to-one by construction). |
| ## Constraints |
| AGENTS.md: amadan discussions not GitHub; touched-package tests locally, CI |
| -full; census if any root-scope code moves (unlikely: a test, a data file, a |
| -make target, docs). Add a short AGENTS.md rule: new CLI commands and console |
| -actions update `parity/parity.tsv` in the same branch. |
| +full. **Census (codex R2, closing note):** the CLI registry changes the root |
| +binary's production dispatch (package main, a new `internal/clireg`, and the |
| +dispatching functions of `internal/cgroup`, `internal/host`, |
| +`internal/ops`, `internal/hostenv`, `internal/edge`, `internal/vet`, |
| +`internal/instanceexec`), so every CLI step below carries a census card |
| +(class: argument routing; no root-read unit changes) and needs the |
| +independent reviewer's approval before its merge. The console half is out of |
| +census scope (`internal/console`). Add a short AGENTS.md rule: a new CLI |
| +command is a registry node and a new console route is a declaration, each |
| +with its `parity/parity.tsv` row in the same branch. |
| -## Calls after the builder check (mine, 2026-11-09) |
| +## Calls (rev 3: registries, Paul's ruling 2026-11-09) |
| + |
| +### A. The CLI command registry **(codex R2-1)** |
| + |
| +1. **One tree the CLI dispatches from.** A new package `internal/clireg` |
| + (no dependencies beyond the standard library) defines `Node`: `Name`, |
| + `Aliases`, `Summary` (one line), `Params` (named positionals, in order), |
| + `Children`, `Default` (the child that runs when the next argument is a |
| + flag or absent, e.g. `config destinations` -> `list`), `Run func(args |
| + []string)`, and the metadata in A4. `main()` becomes: the early phase |
| + (A3), `rootaws.ScrubEnvironment()`, the error writer, then |
| + `clireg.Dispatch(root, os.Args[1:])`, then `maybeUpdateHint` with the |
| + matched top-level word. `Dispatch` walks words: at a node with children |
| + the next argument must be a child name or alias, or a flag/absent with |
| + `Default` set; at a node with `Params` it consumes them; at a node with |
| + `Run` it calls `Run` with what is left. Anything else is the existing |
| + usage error (stderr, exit 2). There is no other way for an argument word |
| + to select code, so the registry is complete by construction. |
| +2. **Refused up front, by `clireg.Validate` (panics at init, unit-tested |
| + with one negative fixture each):** a level that takes both child words |
| + and a positional value; a node with neither `Run` nor children; a |
| + duplicate name or alias among siblings; an alias equal to a sibling name; |
| + a leaf with zero-valued metadata (A4); `Audience: internal` on a word |
| + that does not start with `__` and is not a help alias. The current |
| + ambiguous shapes become declared structure: `version` bare prints the |
| + build and `version target` is a child (`Default` = the bare print); |
| + `channels`/`releases` bare list via `Default`; `apps source pull`'s |
| + valid bare form is a declared `Default`; `instances import |
| + commit/abort` are nested children; `move offline <verb>` is eight |
| + declared children, and `offlineVerbs` becomes the registry's child list |
| + rather than a slice a parser consults (the R2-1 collection case). |
| + Handler maps keyed on argument words are not a registry and cannot |
| + dispatch: a word reaches code only through `Dispatch`. |
| +3. **Plumbing dispatched before main's switch.** `internal/cgroup` exports |
| + its shim words as nodes (`ShimCommands()`, names from its existing |
| + constants); `main()` calls `clireg.DispatchEarly(cgroup.ShimCommands(), |
| + os.Args[1:])` as its first statement, preserving today's order (before |
| + the environment scrub; the `shimHooked` invariant unchanged). |
| + `__demo-snapshot`, `__registry-child` and the `__rootfs-check-*` words |
| + become ordinary `internal` nodes in the main tree, still dispatched |
| + before any other word because they are matched first by name. |
| +4. **Metadata for slice 4 (MCP), required on every runnable node now:** |
| + `Effect` (`read` | `write` | `destructive`), `Auth` (`none` | |
| + `console-login` | `operator` | `box-root`), `Audience` (`customer` | |
| + `operator` | `box-local` | `internal`), `Summary`, `Params`. Zero values |
| + are refused (A2). Flags stay in each handler's `flag.FlagSet` for now; a |
| + reserved `Flags func(*flag.FlagSet)` field, nil in this slice, is where |
| + slice 4 declares them so MCP tool schemas can be generated. A node's |
| + stable ID is its path joined with spaces (`apps set`), the ID the |
| + parity table and later the MCP tool name use. |
| +5. **Migration with an adapter, the guard complete at every step.** A node |
| + may be `Legacy`: its `Run` is an unmigrated dispatcher (`RunApps`) and |
| + its `Children` declare that dispatcher's whole word tree (names, aliases, |
| + nesting, `Default`, `Params`) with no `Run` on the declared descendants. |
| + `Dispatch` walks a legacy node's declared tree exactly as A1 (the gate) |
| + and refuses any undeclared word, then calls the legacy `Run` with the |
| + original arguments. A word the legacy code would act on but the tree |
| + does not declare is therefore unreachable, so the enumeration stays |
| + complete. Two pins keep the adapter honest until it is deleted: |
| + - a level the gate cannot close (word or value at the same position, or |
| + words found after flags) is not allowed under `Legacy`: those commands |
| + are fully migrated in step 0; |
| + - `testdata/clireg-legacy.tsv` lists each remaining legacy node and a |
| + go/ast hash of each of its dispatching functions' bodies. The list may |
| + only shrink, and a branch that changes a pinned function must migrate |
| + that command instead of re-pinning (the test says so). A stale |
| + declaration (declared word the legacy code no longer handles) is |
| + caught by the same test: each declared word under a legacy node must |
| + appear as a string constant in the pinned functions. |
| + Migrated nodes need neither pin: their `Run` is the leaf handler. |
| +6. **Steps (each one reviewable branch, census card each):** |
| + - **Step 0:** `internal/clireg` with `Validate`, `Dispatch`, |
| + `DispatchEarly` and the adapter; main's switch and if-chains replaced by |
| + the root tree (every top-level command a migrated or legacy node); |
| + the cgroup early phase; full migration of every command A5 bars from |
| + `Legacy` (expected: `move`, `version`, `channels`, `releases`, `config`, |
| + plus any the builder's audit finds); the docsite move (A7); the |
| + parity table, both guards and `docs/parity.md` (sections B and C). |
| + - **Steps 1-6**, about eight dispatchers each, by area: (1) apps, |
| + appconfig, env, secrets, features, assets; (2) instances, sidecars, |
| + schedule, run, db, devbox; (3) domains, routes, gate, ratelimit, |
| + protection, analytics, geo, errors, logs; (4) store, email, relay, |
| + services, fleets, accounts, auth, billing; (5) pipeline, skills, |
| + ship/deploy/canary/promote/rollback, economics, steering, ledger, |
| + proof, update; (6) system, ops, console, the host/edge/vet/ |
| + instanceexec packages (each exports its subtree as `[]clireg.Node`; |
| + their dispatchers move like main's). |
| + - **Step 7:** delete the `Legacy` field, its gate path and the pin file. |
| + Each step changes no command's behaviour except refusing words that were |
| + silently ignored (e.g. `carlos version foo`, today the build id); the |
| + builder lists every such tightening in the step's PR. |
| +7. **Docsite projection moves onto the registry (codex R2 closing note).** |
| + `internal/docsite.TopLevelCommands` (the main.go AST scan) is deleted. |
| + `docsite` gains `CommandsMissingHeadings(site, cmds []string)`; the gate |
| + test `TestCLICommandsAreDocumented` moves to package main and calls it |
| + with the projection `root.TopLevel()`: top-level names, excluding |
| + aliases and `internal` nodes, so `-h`/`--help` stay excluded and |
| + headings are still required. Step 0's test asserts the projection |
| + equals today's scanner output (pinned list in testdata) so the move |
| + changes nothing; the scanner's own non-vacuity test becomes a |
| + non-vacuity test on the projection (at least 20, `ship`, `deploy`, |
| + `fleets` present). |
| + |
| +### B. Console route declarations **(codex R2-3, R2-4)** |
| + |
| +1. **One declaration list production registers from.** `internal/console` |
| + gains `routeDecls []routeDecl`: `Method`, `Pattern` (literal, exactly as |
| + registered; methodless keeps an empty method), `Kind` (`plain` | |
| + `cli` | `cli-journaled` | `cli-scoped`, which picks today's helper |
| + wrapper: `registerRoute`, `cliRoute`, `cliRouteJournaled`, |
| + `cliScopedRoute`, with their `allow`, `refused` and `target` as fields), |
| + `Gate` (a named predicate over `Config`, nil = always; e.g. `gateDemo` = |
| + today's `Demo.Enabled || Demo.BoxMode()`), and `Handler func(*Server) |
| + http.HandlerFunc` (method values and closures alike). `s.routes()` is a |
| + loop: for each declaration whose gate holds, call its helper. The |
| + helpers stay the only wrappers, but their pattern now always comes from a |
| + declaration, so the forwarding-helper boundary is the declaration itself |
| + (R2-4): no call-site scan, no literal-pattern rule. |
| +2. **One registrar.** `TestClaimConsoleMuxHasOneRegistrar` is extended: the |
| + only call sites of `registerRoute`, `cliRoute`, `cliRouteJournaled` and |
| + `cliScopedRoute` in non-test code are the declaration loop and the |
| + helpers forwarding to `registerRoute`; anything else fails with its |
| + location. So a registration cannot exist outside the list. |
| +3. **Static/runtime equality across configurations (R2-3).** The test |
| + builds the server under a matrix of configurations (every named gate on |
| + and off at least once; the matrix lives beside the gates and a gate not |
| + flipped by it fails). For each configuration, the runtime register |
| + (`claimEntries`, kind `route`) must EQUAL the declarations whose gate |
| + holds; across the matrix every declaration must be registered at least |
| + once (an unexercised declaration fails); and a non-empty list is |
| + checked first (empty discovery fails on its own). Negative fixtures: a |
| + declaration whose gate is never true; a group function kept but its |
| + loop entry or gate disconnected (R2-3's `registerDemoRoutes` case); a |
| + direct registration outside the loop. |
| +4. **CLI doors.** Declarations of kind `cli*` are the `/api/cli/*` doors: |
| + in the equality check, out of parity coverage (they are the CLI's API, |
| + one-to-one by construction). The exclusion comes from `Kind`, not a |
| + prefix. |
| +5. **Migration:** console is out of census and has one registrar, so it |
| + moves in one mechanical branch inside step 0 (one commit per source |
| + file: `server.go`, `authcli.go`, `apidemo.go`, `teamdoors.go` and the |
| + rest). `registerDemoRoutes` and similar group functions become gated |
| + declarations. |
| + |
| +### C. The table and the guard |
| 1. **Rows are capabilities; coverage is separate from reference** |
| - **(codex 3)**. A row lists zero or more CLI verb paths and zero or more |
| - console routes (route identity = method + pattern exactly as registered; |
| - methodless registrations keep an empty method). Coverage rule: every |
| - enumerated verb path and every enumerated route appears in at least one |
| - row. A route may appear in several rows when one route serves several |
| - capabilities (e.g. `GET /a/{sqid}/apps/{app}/settings/{section}` serves |
| - storage, email and feature flags); a verb path appears in exactly one |
| - row. Duplicate row IDs, and duplicate members within a row, are invalid. |
| -2. **The table classifies, not a prefix list.** Every non-`/api/cli/*` |
| - route the console registers appears in some row; its status says whether |
| - it counts toward customer parity. Statuses add `auth`, `demo`, `asset` |
| - and `internal` (each with a reason). Counts in `docs/parity.md` cover |
| - customer rows only. |
| -3. **Structural rules per status** **(codex 4)**, each with a negative |
| - fixture: every row is non-empty; `both` and `partial` list at least one |
| - member on EACH side, and `partial` has a note saying what is missing; |
| - `gap` lists members on exactly one side and names its work package; |
| - `cli-only` lists only CLI members, `console-only` only routes, both with a |
| + **(codex 3)**. A row lists zero or more CLI members and zero or more |
| + console members. Coverage: every runnable registry node not `internal` |
| + and every non-`cli*` route declaration appears in at least one row. |
| + Duplicate row IDs and duplicate members within a row are invalid. |
| +2. **Shared members with qualifiers (codex R2-2).** A CLI member is a node |
| + ID with an optional flag qualifier: `apps set [--swap,--swap-concurrency]`, |
| + `apps set [--interactive]`, `apps set [--egress-allow,--size]` may be |
| + three rows with three statuses (parity, gap, operator). A node ID in |
| + more than one row must carry a qualifier in every one of them, and the |
| + qualifiers must be pairwise disjoint; an unqualified member owns the |
| + whole node and may appear in one row only. Console routes may be shared |
| + across rows without qualifiers (one GET page serving several settings |
| + sections). In this slice a qualifier's flags are checked for shape and |
| + disjointness only: flags are not in the registry until slice 4 fills |
| + `Flags`, and from then the guard also checks each qualified flag |
| + exists on its node. |
| +3. **The table classifies, not a prefix list** (rev 2 call 2). Statuses: |
| + `both`, `partial`, `gap`, `cli-only`, `console-only`, `operator`, |
| + `box-local`, and for non-customer routes `auth`, `demo`, `asset`, |
| + `internal`. A row whose CLI members have `Audience` operator or |
| + box-local must have that status (the registry's audience and the table |
| + cannot disagree). Counts in `docs/parity.md` cover customer rows only. |
| +4. **Structural rules per status** **(codex 4)**, each with a negative |
| + fixture: every row non-empty; `both`/`partial` list at least one member |
| + on each side, `partial` with a note saying what is missing; `gap` lists |
| + members on exactly one side and names its work package; |
| + `cli-only` only CLI members, `console-only` only routes, both with a |
| reason; `auth`/`demo`/`asset`/`internal`/`operator`/`box-local` have a |
| reason. |
| -4. **Console routes are enumerated statically** **(codex 2)**: the guard |
| - reads every `registerRoute` / `cliRoute`-family call site in |
| - `internal/console` (go/ast) and takes its literal pattern, so a route |
| - behind any configuration gate, current or future, is found whether or |
| - not a test enables it. A call site whose pattern is not a literal (or |
| - whose method cannot be read) fails the guard with its location. The |
| - runtime register (`claimEntries`, all optional groups on) is a |
| - cross-check: every runtime route must be in the static set. `/api/cli/*` |
| - doors are excluded by their registration helper, not by prefix. Empty |
| - discovery fails on its own, before table comparison. |
| -5. **CLI verb paths: one scanner shared with the docs site** **(codex 1)**. |
| - `internal/docsite/cliscan.go` already scans the CLI dispatch for the docs. |
| - The parity guard uses (and extends) that scanner, so docs and parity |
| - cannot disagree. It must recognise every dispatch shape in the tree |
| - today, each with a fixture: the top-level switch; per-command switches |
| - on `args[N]` or on a local verb variable (`config_cli.go`); `if args[N] == |
| - "x"` branches (`main.go` `version target`, `releases retention`, |
| - `releases authorize`); nested conditionals (`instances import |
| - commit/abort`); rejecting conditions that define a valid bare form |
| - (`apps source pull`); constant-valued cases resolved through go/types, |
| - including constants from other packages (`internal/cgroup/shim.go` |
| - `__cgexec`, `__cgprobe`, dispatched before main's switch); aliases |
| - (listed as aliases of one verb path). Any function in the dispatch tree |
| - that compares an argument against a string or constant in a shape the |
| - scanner does not recognise fails the guard with its location, so a new |
| - shape cannot slip through. Flag-level capabilities are noted in rows, |
| - not enumerated. Hidden plumbing verbs (leading `__`, internal helpers) and |
| - help aliases get `internal` rows. If the scanner cannot be made robust, |
| - the fallback is a verb registry the dispatch itself uses (census |
| - approval then, and `cliscan.go` and its test updated with it). |
| -6. **Operator and box-local verbs get exact rows** (no wildcards), several |
| - verbs per row where they form one capability. |
| -7. **Two tests, one table:** the console test checks routes, the root test |
| - checks verb paths and the generated page; both read `parity/parity.tsv`. |
| - `make parity-doc` is a new target; the stale check regenerates and diffs. |
| +5. **Stale references fail:** a CLI member that is not a node ID, a |
| + console member that is not a declaration, a qualifier on a node with |
| + one row. |
| +6. **Two tests, one table:** the console test (package console) checks |
| + routes against `routeDecls`; the root test (package main) checks node |
| + IDs against the registry and the generated page. Both read |
| + `parity/parity.tsv`. `make parity-doc` regenerates; the stale check |
| + regenerates and diffs. Failure messages name the exact row to add or |
| + fix. |
| + |
| +## Round-2 findings, closed |
| + |
| +- **R2-1 (P1, CLI enumeration):** closed by construction: the CLI dispatches |
| + from the registry (A1); collection, map and returned-value dispatch cannot |
| + select code (A2); the transitional adapter gates undeclared words and pins |
| + legacy dispatchers until they migrate (A5). |
| +- **R2-2 (P2, shared CLI references):** qualified shared members (C2). |
| +- **R2-3 (P2, disconnected registrations):** declaration list plus |
| + per-configuration equality and an unexercised-declaration failure (B3). |
| +- **R2-4 (P2, forwarding helpers):** patterns live in declarations; helpers |
| + only wrap; the `cli*` kinds are doors, in equality, out of coverage |
| + (B1, B4). |
| +- **Census and docsite notes:** census card per CLI step (Constraints); |
| + docsite projection moved onto the registry with its tests (A7). |
| ## Left to the builder |
| -The table format and location details, how commands and routes are |
| -enumerated (reflection over the dispatch table, a small exported registry, |
| -or parsing the registration calls, whichever is robust), the docs page |
| -layout, and the exact work-package IDs. |
| +The table format details, the docs page layout, the exact work-package IDs, |
| +the gate names and test matrix, and the exact grouping of steps 1-6 (any |
| +grouping that keeps each branch reviewable and each step's guard complete). |
diff --git a/docs/superpowers/specs/CODEX-REVIEW-BRIEF-parity-guard-R3.md b/docs/superpowers/specs/CODEX-REVIEW-BRIEF-parity-guard-R3.md| new file mode 100644 |
| index 000000000..2dfcc4535 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/CODEX-REVIEW-BRIEF-parity-guard-R3.md |
| @@ -0,0 +1,51 @@ |
| +# Review brief: spec "CLI and console parity: the stock and its guard", round 3 of 3 (the last) |
| + |
| +Repo carlos/platform, branch `design-parity-guard`, commit: the commit that |
| +adds this file. Under review: |
| +`docs/superpowers/specs/2026-11-09-parity-guard-design.md`, seeded from |
| +`docs/superpowers/notes/2026-11-09-parity-inventory.md`. Authorities: main's |
| +code (main.go and the CLI dispatchers; internal/console route registration, |
| +claim_routes.go, server.go registerRoute and the cliRoute family). |
| + |
| +Fixed, do not re-argue: Paul's direction (parity both ways; keep the stock; |
| +gaps closed over time, not now). The builder-check calls are the author's; |
| +challenge them on correctness and robustness. |
| + |
| +Check: |
| +1. Can the guard really enumerate ALL CLI verb paths and ALL console routes (now from the CLI registry and the console declaration list, section A and B) |
| + from code (no second hand list), including config-gated route groups and |
| + commands dispatched into other packages? Name anything it would miss. |
| +2. Would it fail on every kind of drift the spec promises, and not pass |
| + vacuously (e.g. an enumeration that silently returns nothing)? |
| +3. Is the row model (capability rows listing exact members, statuses) sound |
| + and not so noisy that people rubber-stamp rows? |
| +4. Census or other repo gates the build would trip. |
| + |
| +Severity P1/P2/P3; end with exactly one verdict: READY, READY AFTER FIXES, |
| +NOT READY. Do not edit files. No subagents. No full test suites. |
| + |
| +## Round 2 |
| + |
| +Round 1: `CODEX-FINDINGS-parity-guard.md` (P1 CLI enumeration; P2 console |
| +gated routes, exclusive route membership, status structure), all accepted. |
| +First one line per round-1 finding: resolved, partly, or not; then new |
| +findings with their fault family; say whether any family recurs. |
| + |
| +## Round 3 (the last) |
| + |
| +Round 2: `CODEX-FINDINGS-parity-guard-R2.md` (NOT READY, stopping rule 2). |
| +Paul ruled after it: a command registry the CLI dispatches from, and one |
| +console route declaration list production registers from, with |
| +static/runtime equality across configurations; the registry carries what |
| +the slice-4 MCP connector will need; the registry may land with an adapter |
| +so dispatchers move incrementally, if the guard is complete at each step. |
| +Rev 3 marks its changes **(codex R2-N)**. Also check census and the |
| +migration plan (steps 0-7) for reviewability and completeness at each step. |
| + |
| +First one line per round-2 finding (R2-1..R2-4, and the census/docsite |
| +closing note): resolved, partly, or not. Then say for each recurring family |
| +(CLI enumeration, console enumeration, capability granularity) whether it |
| +is now closed. Then new findings with their fault family. |
| + |
| +If NOT READY: say whether the P1s share one cause, and whether refusing the |
| +case up front or cutting scope would remove them (name the cut). |