| index 7ff9f2b0f..ecb670b87 100644 |
| --- a/docs/superpowers/specs/2026-11-09-cli-registry-design.md |
| +++ b/docs/superpowers/specs/2026-11-09-cli-registry-design.md |
| @@ -1,7 +1,13 @@ |
| # The CLI command registry (slice 4, project 1 of 3) |
| |
| -Status: rev 2, 2026-11-09, for review. Rev 2 applies the builder check |
| -(fresh Sonnet reading spec and code; points marked **(builder N)**). Slice 4 is the Carloku MCP |
| +Status: rev 3, 2026-11-09, for review (Astra round 2 of 3). Rev 2 |
| +applied the builder check (fresh Sonnet reading spec and code; points |
| +marked **(builder N)**). Astra round 1 (`CODEX-FINDINGS-cli-registry.md`, |
| +NOT READY: two P1s in the CLI enumeration family, three P2s) hit stopping |
| +rule 2, since R3 of the earlier design had a P1 in the same family. Paul |
| +chose option A, refuse up front (the rule in A0), and ruled on production |
| +changes (C5). Rev 3 applies that and every round-1 finding, marked |
| +**(R1-N)**. Slice 4 is the Carloku MCP |
| connector for Claude, approved by Paul 2026-11-09 in three projects: (1) |
| this registry, (2) the connector (OAuth sign-in, read tools generated from |
| the registry, deploy-from-files), (3) change tools and the confirmation |
| @@ -50,8 +56,8 @@ them and commands whose deciding word follows flags (`steering --app a |
| a row, every row's CLI member is a real path, flag qualifiers name real |
| flags, and the MCP column is filled from the registry. |
| 5. A compatibility proof: a golden corpus recorded from the binary before |
| - the change and replayed after it, plus a lint that keeps word dispatch |
| - inside the registry. |
| + the change and replayed after it, plus the rule that no leaf dispatches |
| + on a word (A0), with a tripwire test that catches its common breaches. |
| |
| ## Goals |
| |
| @@ -104,6 +110,22 @@ them and commands whose deciding word follows flags (`steering --app a |
| |
| ### A. The tree and the walk |
| |
| +0. **The rule: no leaf dispatches on a word (Paul, 2026-11-09, option A; |
| + R1-1, R1-2).** A word that selects code is a node, everywhere, raw |
| + parsers included. A leaf may compare an argument only against the |
| + declared enum values of one of its positionals (a value, A4) or |
| + against flag spellings it parses itself (`raw`, B6); never against a |
| + word that picks a different behaviour. Every word-first descendant of |
| + a hand parser therefore becomes a node (B6 lists them), and only flag |
| + and value parsing stays raw. What holds the rule: the walk for every |
| + word it dispatches; `Validate` and the projection for the tree; and, |
| + for code inside handlers, the AGENTS.md rule (step 1 adds it: "a word |
| + that selects code is a `clireg` node; a leaf compares arguments only to |
| + its declared enum values or flag spellings") with branch and census |
| + review. The lint (E3) is a tripwire that catches the common forms |
| + early. It is not a proof of completeness, and this spec no longer |
| + claims one. |
| + |
| 1. **Node.** `clireg.Node` has `Name`, `Aliases`, `Summary` (one line), |
| `Children []*Node`, `Default` (below), `DefaultOn`, `Fallback`, `Run`, |
| `Args` (section B), `Meta` (section C), `Transparent`, `When` and |
| @@ -311,7 +333,15 @@ them and commands whose deciding word follows flags (`steering --app a |
| flag set: `IsBoolFlag`, and `flag.Getter`'s value type for string, int, |
| duration and so on; a custom `flag.Value` without `Getter` is a string. |
| Aliases (`-a`) come from `cliflag.Aliases` and are not separate |
| - schema entries. |
| + schema entries. **Repeatable flags (R1-5):** a value type that |
| + accumulates (`multiFlag` in `logs.go:48`, used by `logs --field`) |
| + implements `clireg.Repeatable` (`Repeatable() bool`); the projection |
| + shows it as a list of its element type, and a generated call passes one |
| + occurrence per element, none when the list is empty. A test sets such |
| + a flag twice through the leaf's own flag set and checks both values |
| + survive, so the interface cannot be claimed by a value that overwrites. |
| + A custom value that is neither a `Getter` nor `Repeatable` is a single |
| + string. |
| 5. **What the annotations do not promise.** The handler still enforces |
| required and enum rules itself, with today's messages and exit codes. |
| An annotation that is wrong makes a generated tool call fail with the |
| @@ -319,17 +349,47 @@ them and commands whose deciding word follows flags (`steering --app a |
| The one annotation with a safety role, `Secret`, is checked from the |
| other side (C4). The enum annotations on payload switches are checked |
| against the code by the lint (E3). |
| -6. **Raw leaves** (`system demos`, `system box|group role`, `system |
| - floor-allows-prev`, `system named-units`, `system guard-exec`, |
| - `system host-env` (pre-scan), `instance-control`, `instance-exec`, |
| - `instance-exit`, `instance-stop`, `agent`, `edge`, `adopt` (startup |
| - work before `fs.Parse`, `agent.go:5643-5671`, **builder 12**), `ops |
| - host resolve`, `run` (`--` split), `store scan enforce`, and any other |
| - leaf the args step finds doing work before its parse, since parsing |
| - first would reorder its output): their parsing stays in the |
| - handler, unchanged, including today's bugs (`store scan enforce -a on`, |
| - audit B (1)). They carry positional and flag annotations as text only |
| - and can never become tools (C3). All but `run` and `store scan |
| +6. **Raw leaves: flags and values only (A0, R1-1).** A `raw` leaf parses |
| + its own flags and values, unchanged, including today's bugs (`store |
| + scan enforce -a on`, audit B (1)). It never chooses between |
| + subcommands: every word a hand parser used to dispatch on is a node, |
| + and the raw leaf is what runs at the end of that path. The hand |
| + parsers and the nodes their words become (audit B lines cited): |
| + - `system demos` (`system_demos.go:19`): children `status`, |
| + `serving`, `takedown`, `takedown-status`, and `reports` (a branch: |
| + child `resolve`, and an unnamed default on `absent`/`flag`/`word` |
| + for the list). Each leaf runs today's manual flag loop and its |
| + after-loop checks, unchanged; `serving`'s `on|off` is an enum |
| + positional. Today every error, an unknown verb included, prints |
| + `systemDemosInvalid` and exits 2, and `help`/`-h`/`--help` as the |
| + only argument prints to stdout and exits 0: `demos`'s fallback does |
| + exactly that, and so does each leaf for its own errors, so the order |
| + in which a bad verb and a bad flag are noticed cannot show |
| + (every case prints the same text and code). The corpus has cases for |
| + a bad verb with a bad flag, both orders. |
| + - `system box`: children `role` (raw leaf: `roleArgs`, `<box> <role>` |
| + then optional `--console V`) and `publish-record` (std leaf); |
| + `system group`: child `role`. Fallback: `systemUsage`, exit 2. |
| + - `system guard-exec`: children `apply`, `recover`, `edge`, and |
| + `console` (raw leaf: `<bin>` then a tail passed on unparsed). |
| + Fallback: `log.Fatal(hostfloor.ErrFloor)`. The spellings it re-execs |
| + (`system apply [--recover]`, `agent`) stay valid; the corpus pins |
| + them. |
| + - `system group-maintenance`: children `permit`, `revoke`, `status`, |
| + `apply`, `rollback`, `prepare`; fallback prints help to stderr, exit |
| + 2, and `help` alone to stdout, exit 0 (`group_maintenance_verbs.go`). |
| + - `system host-env`: children `write`, `seed` (raw: the `--group` |
| + pre-scan stays in each leaf); `system named-units`: child `install` |
| + (raw: exactly one `<file>`); `system files`: child `seed`. |
| + - `ops host`: child `resolve` (raw leaf, `hostclaim_cli.go:52`). |
| + Raw leaves with no words to lift: `system floor-allows-prev`, |
| + `instance-control`, `instance-exec` and `instance-exit` (the role is |
| + an enum positional), `instance-stop`, `agent`, `edge`, `adopt` |
| + (startup work before `fs.Parse`, `agent.go:5643-5671`, **builder |
| + 12**), `run` (`--` split), `store scan enforce` (`on|off` is an enum |
| + positional), and any other leaf the args step finds doing work before |
| + its parse. Raw leaves carry positional and flag annotations as text |
| + only and can never become tools (C3). All but `run` and `store scan |
| enforce` are box-local, operator or internal. **Call B6.** |
| |
| ### C. Metadata for the connector |
| @@ -349,25 +409,35 @@ them and commands whose deciding word follows flags (`steering --app a |
| fill these from the connection's picked accounts and refuse any other. |
| 3. **`Tool`:** `eligible`, or `never` with a reason. `eligible` requires |
| `Audience: customer`, `Locality: api`, a strategy other than `raw`, no |
| - positional whose meaning depends on other input (B3), and no required |
| - `Secret` flag; `Validate` refuses anything else. Optional `Secret` |
| + positional whose meaning depends on other input (B3), no required |
| + `Secret` flag, and no `Sensitive` mark (C4); `Validate` refuses |
| + anything else. Optional `Secret` |
| flags are dropped from the generated schema. The tool name is the ID |
| with spaces as underscores (`apps_set`, `apps_build-probe`), within |
| MCP's 64-character name limit (checked). |
| -4. **Secrets.** `secrets set` and every leaf that takes a secret value |
| - (gate password on stdin, service or fleet tokens printed once, |
| - `secrets genkey`) are `Tool: never`, reason "secrets go through the |
| - Environments page" or "prints a credential once". A test lists every |
| - leaf whose flag set registers a flag whose name contains `password`, |
| - `secret`, `token` or `key` and requires each to be annotated `Secret` |
| - or explicitly `NotSecret` with a reason. This is a backstop, not the |
| - enumeration. |
| -5. **Effect classification rule** (a Paul question below asks only about |
| - production deploys): `read` changes nothing; `risky` is irreversible or |
| - loses data (delete, purge, restore over, revoke), changes who can reach |
| - or administer something (roles, tokens, gate, protection off, domains |
| - detach), moves money (billing, packs) or touches a whole account; |
| - `change` is every other write. A flag or enum value can raise a leaf |
| +4. **Secrets, at the leaf (R1-4).** `Meta.Sensitive` marks a leaf that |
| + reads a secret by any route (`flag`, `positional`, `stdin`, `prompt`) |
| + or prints a credential (`prints`), each with a one-line reason. Either |
| + makes `Tool: eligible` invalid (C3), whatever its flags say. A |
| + regression test names the leaves that must carry it and must be |
| + `never`, at least: `secrets set`, `secrets genkey`, `gate set` |
| + (password on stdin, `gate_cli.go:119`), `services create` and |
| + `services rotate` (print a token, `services.go:284`), `fleets |
| + create`, `fleets add-box` and `fleets rotate-token` (box tokens print |
| + once), `email credentials create`, `release-keygen`, `proof keygen`, |
| + `relay keygen`; the args step for each area adds any others it finds. |
| + As a supplementary check, a test lists every leaf whose flag set |
| + registers a flag whose name contains `password`, `secret`, `token` or |
| + `key` and requires `Secret` on that flag or an explicit `NotSecret` |
| + with a reason. |
| +5. **Effect classification rule.** `read` changes nothing; `risky` is |
| + irreversible or loses data (delete, purge, restore over, revoke), |
| + changes who can reach or administer something (roles, tokens, gate, |
| + protection off, domains detach), moves money (billing, packs) or |
| + touches a whole account; `change` is every other write. **Paul, |
| + 2026-11-09:** deploying, promoting, rolling back and restarting an |
| + app's production are `change` (Claude acts and reports); deletions |
| + stay `risky`. A flag or enum value can raise a leaf |
| (`RiskyWhen: {"--yes": ..., "off": ...}`); nothing lowers one. |
| |
| ### D. The parity guard, from the registry |
| @@ -412,11 +482,22 @@ them and commands whose deciding word follows flags (`steering --app a |
| and `--` forms its strategy accepts. Nodes marked `Golden: skip` with a |
| reason (daemons such as `edge`, `agent`, `relay serve`; anything that |
| would touch a box or the terminal) are listed in the file as skipped. |
| - Each case runs with `HOME` and the working directory in an empty |
| - directory under `$TMPDIR`, `CARLOS_*` unset, `HTTP(S)_PROXY` pointed at |
| - a closed local port so any network attempt fails at once and the same |
| - way, and a 5-second limit; a case that exceeds it is recorded as |
| - skipped with that reason rather than flaking. It records stdout, stderr |
| + Also, for every alias, the same cases spelled with the alias; for |
| + every transparent word, the cases with it (`system router ...`, |
| + `system router` alone, `system router router`); and for every node |
| + with `When`, its cases with the condition true and false (`ops host` |
| + with `CARLOS_HOST_CLAIM` set and unset) **(R1-3)**. |
| + **Environment (R1-3).** Each case starts from an empty environment and |
| + gets exactly: `PATH` (the test's own), `HOME` and the working |
| + directory (an empty directory under `$TMPDIR`), `TMPDIR`, `LANG=C`, |
| + `HTTP_PROXY`/`HTTPS_PROXY` pointed at a closed local port (any |
| + network attempt fails at once and the same way), and the case's own |
| + variables (a `When` case's switch). Nothing inherited reaches the |
| + binary, so `rootaws`'s scrub alert (`environment.go:59`) and any |
| + `CARLOS_*` or `AWS_*` setting cannot change stderr. A case has a |
| + 10-second limit, and running past it **fails** the test. The only |
| + skips are nodes marked `Golden: skip` with a reason, listed in the |
| + file and reviewed with the branch. It records stdout, stderr |
| and exit code, with `log`'s date-time prefix (`^\d{4}/\d\d/\d\d |
| \d\d:\d\d:\d\d `) and the temporary paths normalised, on record and |
| on replay alike. |
| @@ -430,36 +511,49 @@ them and commands whose deciding word follows flags (`steering --app a |
| recorded from its own merge base. A step that changes behaviour on |
| purpose re-records and lists each changed line in its PR; project 1 |
| itself changes none. |
| -3. **The word-dispatch lint.** `TestWordsDispatchOnlyInRegistry` parses |
| - the root binary's non-test Go files and fails on a `switch` or |
| - if-chain comparing `X[n]` or `fs.Arg(n)` (any `[]string` index or |
| - `Arg` call) against two or more string literals, unless the statement |
| - carries one of: |
| - - `// clireg:enum <node ID> <positional>`, and its literals equal that |
| - positional's declared `Enum` (help words excluded); |
| - - `// clireg:pending <node ID>`, allowed only until that node's args |
| - step **(builder 1, 8)**: in step 1 every payload switch the audit |
| - lists (about 37 in package main, `runSteering`'s at |
| - `instances_cli.go:957` among them) and every whole-function |
| - dispatcher (A5) carries it; each args step turns its area's markers |
| - into `clireg:enum` or removes the switch, and step 7 makes the lint |
| - refuse `pending`. |
| - Fallbacks may compare against help words only. A switch on a variable |
| - the registry passed in (`switch verb` in `runSystemAntivirus`, set by |
| - the child's closure) is not flagged: that word was dispatched by the |
| - walk. This keeps new sub-verbs out of handlers and ties every payload |
| - enum to the code that reads it. It is a ban with an exact allowance, |
| - not an enumeration (Paul's 2026-11-09 ruling stands: the list of |
| - commands comes from the registry). |
| +3. **The word-dispatch tripwire (A0; R1-2).** `TestWordsDispatchTripwire` |
| + parses the root binary's non-test Go files and flags a comparison of an |
| + *argument-derived string* against a string literal, in a `switch` |
| + (any number of cases), an `if`/`else if` chain (one comparison is |
| + enough), or a map or slice lookup keyed by it (`slices.Contains`, a |
| + `map[string]...` index). Argument-derived means: an element of a |
| + `[]string` parameter or of `fs.Args()`/`fs.Arg(n)`/`inv.Pos`, or a |
| + local assigned from one, followed through plain assignments within the |
| + function. It does not follow values through calls or struct fields; |
| + that is where it stops being a proof, and A0 says so. A flagged |
| + statement passes only with one marker on the line above: |
| + - `// clireg:enum <node ID> <positional>`: its literals equal that |
| + positional's declared `Enum`; |
| + - `// clireg:flags`: in a `raw` leaf only, and every literal starts |
| + with `-` (manual flag spellings such as `system_demos.go:50`); |
| + - `// clireg:help`: in a fallback only, literals within `help`, `-h`, |
| + `--help`; |
| + - `// clireg:pending <node ID> <lit>,<lit>,...` **(builder 1, 8)**: |
| + the literals are pinned, so the statement fails when a case is added |
| + or changed; allowed only until that node's args step. In step 1 every |
| + payload switch the audit lists (about 37 in package main, |
| + `runSteering`'s at `instances_cli.go:957` among them) and every |
| + whole-function dispatcher (A5) carries it; each args step turns its |
| + area's markers into `clireg:enum` or removes the switch, and step 7 |
| + refuses `pending`. |
| + A switch on a word the walk passed in through a child's closure |
| + (`switch verb` in `runSystemAntivirus`) is not argument-derived and is |
| + not flagged: that word was dispatched by the walk. Fixtures, one each: |
| + a single-literal `if args[0] == "x"`, a local copied from `args[0]`, |
| + a `slices.Contains(words, args[0])`, a `map[string]func` lookup, a |
| + `pending` marker whose switch gained a case, and a `clireg:flags` |
| + marker on a literal without `-`. |
| |
| ### F. Migration |
| |
| -The guard is complete when the words are in the registry, so the words go |
| +The guard covers every path the walk dispatches once the words are in the |
| +registry (with A0 holding the words inside handlers), so the words go |
| in one branch and the arguments follow by area. **Call F0:** no legacy |
| adapter, no opaque nodes; this removes R3-2 and R3-3 rather than patching |
| them. |
| |
| -- **Step 1, words (one branch, one census card).** `internal/clireg` |
| +- **Step 1, words (one branch, one census card).** The AGENTS.md rule |
| + (A0), `internal/clireg` |
| (walk, `Validate`, `Invocation`, strategies, `OnError`), every |
| dispatcher's `switch` turned into nodes (about 50 dispatchers and their |
| nested ones, audit A and B), `Run` on each leaf as |
| @@ -467,7 +561,8 @@ them. |
| args, wrapped in the parent's error mapping where one exists), the |
| early phase (A9), `commandRoot()` in `commands.go`, `NoUpdateHint` |
| (A7), the corpus recorded from the merge base and replayed (E1-E2), the |
| - lint with `pending` markers (E3), `parity/cli.tsv` and the new coverage |
| + tripwire with `pending` markers (E3), the raw parsers' words lifted |
| + into nodes (B6), `parity/cli.tsv` and the new coverage |
| guard (D2, D5), the docsite move (G), and the parity rows the full |
| coverage newly demands. Built as one task per area so each commit is |
| reviewable; merged once so the guard never has a half state. Only |
| @@ -486,7 +581,7 @@ them. |
| markers, and replays the corpus. Customer areas go first because |
| project 2 needs them. |
| - **Step 7:** `RawArgs` is allowed only on `raw`-strategy leaves (B6); |
| - `Validate` refuses it elsewhere, and the lint refuses `pending`. |
| + `Validate` refuses it elsewhere, and the tripwire refuses `pending`. |
| |
| ### G. Docsite |
| |
| @@ -512,8 +607,13 @@ non-vacuity test becomes one on the file (at least 20 commands; `ship`, |
| - **A9:** shim words enumerated from cgroup's own map. |
| - **B1:** registration moves into the node (`Args.New`) rather than being redeclared |
| in a schema DSL, so help output and parsing cannot change. |
| -- **B2, B6:** hand loops and hand parsers stay as they are (`raw`) unless |
| - proven identical. |
| +- **B2, B6:** hand loops and hand parsers keep their flag and value |
| + parsing (`raw`) unless proven identical; their words become nodes (A0). |
| +- **E3:** the tripwire follows locals by plain assignment only; values |
| + passed through calls or struct fields are left to the AGENTS.md rule and |
| + review (A0). |
| +- **C4:** `Sensitive` is a leaf-level mark covering stdin, prompts and |
| + printed credentials, with a named regression list. |
| - **C3:** tool eligibility is decided in the registry, refused for raw, |
| local, secret-taking and ambiguous-positional leaves. |
| - **D1:** one generated projection file is the bridge to `internal/parity` |
| @@ -531,14 +631,16 @@ non-vacuity test becomes one on the file (at least 20 commands; `ship`, |
| `GoldenArgs` and a closed proxy for the corpus (E1); `pending` lint |
| markers until each args step (E3); `help` stays a customer row (A6). |
| |
| -## For Paul |
| +## Paul's rulings (2026-11-09) |
| |
| -1. **Is a deploy to an app's production channel `change` or `risky`?** |
| - With `change` (recommended), Claude deploys and reports, as the |
| - connector is meant for; rollback exists. With `risky`, every |
| - production deploy asks in chat and needs approval in Carloku by |
| - default, and the per-connection setting can loosen it. The same answer |
| - applies to `promote`, `rollback` and `restart` of production. |
| +1. **Option A after round 1 (stopping rule 2):** refuse up front. No leaf |
| + dispatches on a word; every word-first descendant of a raw parser is a |
| + node; raw parsing only for flags and values; the lint is a tripwire, |
| + not a completeness proof; the AGENTS.md rule and branch and census |
| + review hold dispatch inside handlers (A0, B6, E3). |
| +2. **Production changes are `change`:** deploy, promote, rollback and |
| + restart of an app's production act and report; deletions stay `risky` |
| + (C5). |
| |
| ## Earlier findings, where they went |
| |
| @@ -555,3 +657,16 @@ non-vacuity test becomes one on the file (at least 20 commands; `ship`, |
| - **R3-4 (mode qualifiers):** already in slice 3; D3 adds checking where |
| a qualifier names a flag or enum value. |
| - **R3-5 (console scanners):** slice 3, unaffected. |
| +- **R1-1 (raw leaves dispatch words; P1):** A0 and B6: every word of a |
| + hand parser is a node; raw parsing for flags and values only. |
| +- **R1-2 (lint misses forms, flags manual flag parsers; P1):** A0 (the |
| + lint is a tripwire, the rule is held by AGENTS.md and review) and E3 |
| + (single comparisons, locals, map and slice lookups flagged; |
| + `clireg:flags` for manual flag spellings; `pending` pinned to its |
| + literals; fixtures). |
| +- **R1-3 (corpus):** E1: alias, transparent and `When` cases; empty |
| + environment plus an explicit list; timeouts fail; reviewed skips only. |
| +- **R1-4 (secrets):** C3 and C4: leaf-level `Sensitive`, named |
| + regression list. |
| +- **R1-5 (repeatable flags):** B4: `clireg.Repeatable`, checked by |
| + setting twice. |