clireg: Task 1 review P2s (typed words, identity, audience)
consumed keeps the words as typed; Validate refuses whitespace in words, empty aliases, and internal audience on a transparent word.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/plans/CODEX-FINDINGS-cli-registry-words-T1.md+25 −0internal/clireg/dispatch.go+2 −2internal/clireg/dispatch_test.go+29 −0internal/clireg/validate.go+13 −3internal/clireg/validate_test.go+6 −0
Intent
<task-notification> <task-id>buy2qcblc</task-id> <tool-use-id>toolu_01D6Q3gmbNbw1KF7bNaofHpn</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/27979b8d-cc90-4f50-88f6-87ba41433627/tasks/buy2qcblc.output</output-file> <status>completed</status> <summary>Background command "Wait for Astra T1 review" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 18.2 g CO₂e (2,290,314 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on cli-registry-words, 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/plans/CODEX-FINDINGS-cli-registry-words-T1.md b/docs/superpowers/plans/CODEX-FINDINGS-cli-registry-words-T1.md| new file mode 100644 |
| index 000000000..0d4f9cef7 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/CODEX-FINDINGS-cli-registry-words-T1.md |
| @@ -0,0 +1,25 @@ |
| +Reviewed `fb0bba0d^..fb0bba0d`, round 1 of 3. No P1 findings. |
| + |
| +1. **P2 — `consumed` loses the spelling actually supplied.** |
| + **Evidence:** [dispatch.go:34](internal/clireg/dispatch.go:34) and line 42 append `c.Name` instead of `args[0]`. |
| + **Failure scenario:** With branch `system` aliased as `sys`, `sys unknown` reaches the fallback with `consumed=["system"]`. An aliased transparent word is likewise rewritten. A2 promises the words dropped; only `Invocation.Path` is explicitly canonical. A fallback cannot recover the original spelling. |
| + **Fix:** Append `args[0]` to `consumed` before advancing. Add fallback tests for branch and transparent aliases; existing alias tests only reach leaves. |
| + **Fault family:** Preservation of dispatch input. |
| + |
| +2. **P2 — Validation permits ambiguous command identities.** |
| + **Evidence:** [validate.go:97](internal/clireg/validate.go:97) checks only empty names; line 102 skips empty aliases. [clireg.go:127](internal/clireg/clireg.go:127) joins names without checking uniqueness. |
| + **Failure scenario:** A root leaf named `"apps list"` and a branch `apps` containing leaf `list` both pass validation and produce the same projected ID, despite dispatching different argv shapes. Separately, two siblings with alias `""` pass validation even though both match an empty argument, violating A8’s duplicate-alias rule. |
| + **Fix:** Reject whitespace in command names and aliases, and reject empty aliases. Preserve the unnamed `DefaultLeaf` exception and valid flag-like aliases such as `--help`. Add negative fixtures for both cases. |
| + **Fault family:** Unique command identity and projection coverage. |
| + |
| +3. **P2 — Transparent nodes bypass the internal-audience rule.** |
| + **Evidence:** [validate.go:28](internal/clireg/validate.go:28) returns before the audience check at line 34. |
| + **Failure scenario:** `{Name: "router", Transparent: true, Audience: Internal}` passes validation, although A8 refuses internal audience on a word without the `__` prefix. The existing negative fixture covers only an ordinary leaf. |
| + **Fix:** Apply the audience check before the transparent-node return and add this negative fixture. |
| + **Fault family:** Audience declaration validation. |
| + |
| +The stricter fallback requirement is correct: any case excluded by `DefaultOn` needs a fallback when no child matches. It accommodates the audited dispatchers, including `config destinations`. |
| + |
| +Targeted tests and `go vet` could not start because the read-only sandbox prevented Go build-directory writes; these were infrastructure failures, not test failures. `git diff --check` passed. No files changed. |
| + |
| +READY AFTER FIXES (no P1) |
| \ No newline at end of file |
diff --git a/internal/clireg/dispatch.go b/internal/clireg/dispatch.go| index 850c1ed29..6f77c3399 100644 |
| --- a/internal/clireg/dispatch.go |
| +++ b/internal/clireg/dispatch.go |
| @@ -31,7 +31,7 @@ func Dispatch(root *Node, args []string) []*Node { |
| if c := matchChild(n, args[0], false, nil); c != nil { |
| path = append(path, c) |
| words = append(words, c.Name) |
| - consumed = append(consumed, c.Name) |
| + consumed = append(consumed, args[0]) |
| args = args[1:] |
| n = c |
| dropped = map[*Node]bool{} |
| @@ -39,7 +39,7 @@ func Dispatch(root *Node, args []string) []*Node { |
| } |
| if c := matchChild(n, args[0], true, dropped); c != nil { |
| dropped[c] = true |
| - consumed = append(consumed, c.Name) |
| + consumed = append(consumed, args[0]) |
| args = args[1:] |
| continue |
| } |
diff --git a/internal/clireg/dispatch_test.go b/internal/clireg/dispatch_test.go| index b29650301..c25ce536a 100644 |
| --- a/internal/clireg/dispatch_test.go |
| +++ b/internal/clireg/dispatch_test.go |
| @@ -314,3 +314,32 @@ func TestRunnable(t *testing.T) { |
| t.Fatalf("Runnable IDs:\n got %q\nwant %q", got, want) |
| } |
| } |
| + |
| +// TestDispatchConsumedKeepsTypedSpelling: a fallback sees the words as the |
| +// person typed them, aliases included, not their canonical names. |
| +func TestDispatchConsumedKeepsTypedSpelling(t *testing.T) { |
| + var got []string |
| + root := &Node{Name: "carlos", Fallback: func(_, _ []string) {}, Children: []*Node{{ |
| + Name: "system", |
| + Aliases: []string{"sys"}, |
| + Children: []*Node{ |
| + {Name: "router", Aliases: []string{"rt"}, Transparent: true}, |
| + {Name: "update", Run: func(*Invocation) error { return nil }, Audience: Operator}, |
| + }, |
| + Fallback: func(_, consumed []string) { got = append([]string(nil), consumed...) }, |
| + }}} |
| + for _, c := range []struct { |
| + args []string |
| + want []string |
| + }{ |
| + {[]string{"sys", "zz"}, []string{"sys"}}, |
| + {[]string{"sys", "rt"}, []string{"sys", "rt"}}, |
| + {[]string{"system", "router", "zz"}, []string{"system", "router"}}, |
| + } { |
| + got = nil |
| + Dispatch(root, c.args) |
| + if strings.Join(got, " ") != strings.Join(c.want, " ") { |
| + t.Errorf("%v: consumed %q, want %q", c.args, got, c.want) |
| + } |
| + } |
| +} |
diff --git a/internal/clireg/validate.go b/internal/clireg/validate.go| index fbf3c0af8..d8db47014 100644 |
| --- a/internal/clireg/validate.go |
| +++ b/internal/clireg/validate.go |
| @@ -25,15 +25,15 @@ func (v *validator) fail(id, format string, a ...any) { |
| } |
| func (v *validator) node(n *Node, id string, isRoot bool) { |
| + if !isRoot && n.Audience == Internal && !strings.HasPrefix(n.Name, "__") { |
| + v.fail(id, "audience %q on a word without the __ prefix", Internal) |
| + } |
| if n.Transparent { |
| if len(n.Children) > 0 || n.Run != nil || n.Default != "" || n.DefaultLeaf != nil { |
| v.fail(id, "a transparent node has no children, Run or default") |
| } |
| return |
| } |
| - if !isRoot && n.Audience == Internal && !strings.HasPrefix(n.Name, "__") { |
| - v.fail(id, "audience %q on a word without the __ prefix", Internal) |
| - } |
| switch { |
| case n.isLeaf() && n.isBranch(): |
| v.fail(id, "both a branch and a leaf (Run set with children or a default)") |
| @@ -97,6 +97,16 @@ func (v *validator) branch(n *Node, id string) { |
| if c.Name == "" { |
| v.fail(cid, "a child with no Name") |
| } |
| + for _, w := range append([]string{c.Name}, c.Aliases...) { |
| + if strings.ContainsAny(w, " \t\n") { |
| + v.fail(cid, "word %q contains whitespace; a command word is one argument", w) |
| + } |
| + } |
| + for _, a := range c.Aliases { |
| + if a == "" { |
| + v.fail(cid, "an empty alias") |
| + } |
| + } |
| own := map[string]bool{} |
| for _, w := range append([]string{c.Name}, c.Aliases...) { |
| if w == "" || own[w] { |
diff --git a/internal/clireg/validate_test.go b/internal/clireg/validate_test.go| index 4ab12ace7..a39117d0e 100644 |
| --- a/internal/clireg/validate_test.go |
| +++ b/internal/clireg/validate_test.go |
| @@ -31,6 +31,12 @@ func TestValidate(t *testing.T) { |
| "apps list: "}, |
| {"duplicate alias", under(&Node{Name: "apps", Children: []*Node{leaf("set", "s"), leaf("list", "s")}, Fallback: fb}), |
| "apps list: "}, |
| + {"whitespace in a name", under(&Node{Name: "apps", Children: []*Node{leaf("set"), leaf("apps list")}, Fallback: fb}), |
| + "apps apps list: "}, |
| + {"empty alias", under(&Node{Name: "apps", Children: []*Node{leaf("set", ""), leaf("list")}, Fallback: fb}), |
| + "apps set: "}, |
| + {"internal audience on a transparent word", under(&Node{Name: "system", Children: []*Node{{Name: "router", Transparent: true, Audience: Internal}, leaf("update")}, Fallback: fb}), |
| + "system router: "}, |
| {"duplicate with a transparent sibling", under(&Node{Name: "system", Children: []*Node{{Name: "router", Transparent: true}, leaf("update", "router")}, Fallback: fb}), |
| "system update: "}, |
| {"Default naming no child", under(&Node{Name: "canary", Children: []*Node{leaf("deploy")}, Default: "deplo", DefaultOn: OnWord, Fallback: fb}), |