Repository navigation
fix(cli): accept inherited flags after nested subcommands - #116587
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 12:49 PM ET / 16:49 UTC. ClawSweeper reviewWhat this changesThe PR registers selected model-auth, Skills Workshop, and Skills Curator options on nested leaf commands so they work after the subcommand and leaf values take precedence. Merge readinessKeep open. This maintainer-labeled PR addresses a current CLI parser gap, preserves the documented parent form, and has no blocking correctness or security finding. Priority: P2 Review scores
Verification
How this fits togetherThe Commander-based CLI parses operator arguments before dispatching model authentication or skill-management actions. Agent selection determines the workspace/auth store, while JSON selection determines the response format. flowchart LR
A[Operator CLI arguments] --> B[Commander positional parsing]
B --> C[Model auth and Skills commands]
C --> D[Leaf and parent option resolution]
D --> E[Selected agent workspace]
D --> F[Selected JSON output]
E --> G[Auth or skill operation]
F --> G
Before merge
Agent review detailsSecurityNone. PR surfaceSource +39, Tests +187, Docs +3. Total +229 across 10 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the bounded leaf-registration repair with its parser-level invariants, keeping option inheritance explicit only on leaves where the option has the same semantics. Do we have a high-confidence way to reproduce the issue? Yes. Current main registers the affected option only on parents, while the exact-head installed-package proof demonstrates the repaired trailing-option paths; local execution was not run under the read-only review constraint. Is this the best way to solve the issue? Yes. Explicit leaf registration and source-aware inheritance fit Commander positional parsing without exposing the option on unrelated leaves or adding a competing resolver. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against cd5076770e56. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (12 earlier review cycles; latest 8 shown)
|
|
@clawsweeper re-review clawbro |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Yigtwxx
left a comment
There was a problem hiding this comment.
Reviewed at f1b0b1c. No correctness finding — I went looking for one and it didn't survive. Both comments below are about the convention this PR writes down for everyone else, not about the two families it fixes.
What I checked that came back clean. The sibling-parity question ("if models and skills were broken, what else is?") is genuinely closed. I walked every command family in src/cli/ where a parent declares options and has subcommands: agent/exec, acp/client, gateway/run, the daemon service commands, update, sessions, commitments, tasks, onboard. Each one either already declares the applicable option on the leaf or has no parent option at all — and sessions/commitments/tasks were already calling enablePositionalOptions() on the group, so the convention predates this change. These two families really were the stragglers.
The part of the diff that makes the tests able to fail is the harness change, not the assertions. Adding enablePositionalOptions() in models-cli.test.ts:101,107-112, skills-cli.curator.test.ts:64, skills-cli.workshop.test.ts:96, and skills-cli.commands.test.ts:677 is what aligns the harness with production (build-program.ts:12). Without it the harness builds a plain new Command(), positional parsing is off, and the parent quietly consumes --agent before dispatch — meaning the pre-PR tests would have passed against the broken code. Worth calling out because it's easy to read that as boilerplate.
Of the new cases, "resolves workshop --agent with $label" (skills-cli.workshop.test.ts:134-153) is the one that actually pins new logic: workshop list's action passes the parent command object plus leaf opts (skills-cli.ts:958), so the third case would return "parent-agent" without the :154 flip. The models-side precedence test pins pre-existing cli-utils.ts walk-order rather than anything this PR wrote, which is fine as a regression test — just not evidence for the new resolution.
Two comments inline:
-
AGENTS.md:89states "resolve the leaf value first, then ancestors" without the defaults caveat, and the pattern it implicitly points at (resolveOptionFromCommand) reads rawopts(). Two places in-tree already had to invert precedence for exactly that reason, one of them with the hazard in a comment, and the repo has a source-aware helper built for it. Nothing in this PR is affected — none of the touched leaf options has a default — but--json/--limit/--timeoutleaves in this repo usually do. -
models-cli.test.ts:177-196hardcodes the leaf list where its skills counterpart iteratesworkshop.commands. Complete today; won't catch a futureauthleaf that forgets--agent.
| - OpenAI Codex is folded into `openai`. No new/live `openai-codex` provider/plugin/auth/model routes; treat them as legacy input only. Runtime/setup/auth/catalog use `openai` + `openai/*`; doctor/migrations repair stale `openai-codex/*` profiles/metadata. | ||
| - Config/env surface bar is high; `openclaw.json` and environment variables are already large. Before adding a config option or env var, first prove existing product behavior, provider selection, defaults, or doctor migration cannot solve it. Prefer removing or consolidating config/env options when touching these surfaces. Core supports only the latest config shape; `openclaw doctor --fix` migrates older shipped shapes into the current one. | ||
| - CLI setup flows are public API when external docs, installers, or integrations can copy them. Changes to `openclaw onboard`, `openclaw configure`, their documented flags, non-interactive behavior, or generated config shape are compatibility-sensitive API contract changes; prefer additive flags/aliases, deprecation windows, and backward-preserving migrations over breaking existing snippets. | ||
| - Nested CLI options: when a parent option semantically applies to a leaf subcommand, declare it on both the parent and every applicable leaf so positional parsing accepts the option before or after the subcommand. Resolve the leaf value first, then ancestors. Do not expose inherited options on leaves where the semantics differ. Add real-parser coverage that enumerates every applicable leaf. |
There was a problem hiding this comment.
"Resolve the leaf value first, then ancestors" is correct for every option this PR touches, but as a repo-wide rule it inverts the moment a leaf option has a default — and the rule as written doesn't mention defaults or point at the helper that handles them.
The pattern a reader will copy is the one in the two files this PR changes, resolveOptionFromCommand (src/cli/cli-utils.ts:60-73), which walks leaf→root returning the first opts[key] !== undefined. In Commander a defaulted option is present in opts() whether or not the user typed it, so with a default on the leaf that walk returns the default and an explicitly typed ancestor flag never wins.
Two places in-tree already hit this and had to work around it:
src/cli/program/register.agent-turn.ts — parent --timeout has no default (:73-76), leaf agent exec --timeout defaults to "600" (:149), and the merge at :185 is deliberately ancestor-first:
messageFile: opts.messageFile ?? parentOpts?.messageFile, // leaf-first
model: opts.model ?? parentOpts?.model, // leaf-first
thinking: opts.thinking ?? parentOpts?.thinking, // leaf-first
timeout: parentOpts?.timeout ?? opts.timeout, // ancestor-first — the one with a leaf defaultsrc/cli/gateway-cli/run-options.ts:60-62 says it outright:
if (key === "wsLog") {
// wsLog has a child default ("auto"), so prefer inherited parent CLI value when present.
resolved[key] = inherited ?? resolved[key];And the repo already has the primitive that makes the rule safe in both cases — inheritOptionFromParent (src/cli/command-options.ts:12-36) uses getOptionValueSource(name) and skips values whose source is "default". It's what acp-cli.ts:66, gateway-cli/register.ts:21, update-cli.ts:27,38, and daemon-cli/register-service-commands.ts use.
Since --json, --limit, and --timeout leaf options in this repo commonly carry defaults, the next person following this line is fairly likely to land in the inverted case. Naming the caveat and the helper would cost one clause:
| - Nested CLI options: when a parent option semantically applies to a leaf subcommand, declare it on both the parent and every applicable leaf so positional parsing accepts the option before or after the subcommand. Resolve the leaf value first, then ancestors. Do not expose inherited options on leaves where the semantics differ. Add real-parser coverage that enumerates every applicable leaf. | |
| - Nested CLI options: when a parent option semantically applies to a leaf subcommand, declare it on both the parent and every applicable leaf so positional parsing accepts the option before or after the subcommand. Resolve the leaf value first, then ancestors — but when the leaf option has a default, resolve by option source (`inheritOptionFromParent` in `src/cli/command-options.ts`) so a leaf default never beats an explicitly supplied ancestor value. Do not expose inherited options on leaves where the semantics differ. Add real-parser coverage that enumerates every applicable leaf. |
To be explicit about scope: this is about the rule, not this PR's code. I checked every leaf option the branch declares — models-cli.ts:331,351,364,384,421,442,468,489,513,534,555 and the skills-cli.ts loops at :938-940 and :1291-1296 — and none of them has a default, so the leaf-first resolution here produces exactly the documented behavior.
| it("declares --agent on every agent-aware auth leaf command", () => { | ||
| const models = requireCommand(createProgram(), "models"); | ||
| const auth = requireCommand(models, "auth"); | ||
| const authLeaves = [ |
There was a problem hiding this comment.
This is the one place where the two halves of the PR diverge on the invariant the new AGENTS.md line asks for ("coverage that enumerates every applicable leaf").
The skills counterpart iterates the registered commands, so it stays true as leaves are added — src/cli/skills-cli.commands.test.ts:676-694:
for (const command of workshop.commands) {
expect(command.options.some((option) => option.long === "--agent"), command.name()).toBe(true);
}Here the leaf set is a hardcoded list. I checked it against this head and it is complete today — those eight plus order get|set|clear are exactly auth's current leaves — so this isn't a coverage hole right now. The difference is what happens next: a new models auth <leaf> added without --agent fails the skills-shaped test and passes this one, which makes it a snapshot of today's tree rather than a guard on the rule.
Iterating would match the sibling and drop the maintenance burden:
| const authLeaves = [ | |
| it("declares --agent on every agent-aware auth leaf command", () => { | |
| const models = requireCommand(createProgram(), "models"); | |
| const auth = requireCommand(models, "auth"); | |
| const order = requireCommand(auth, "order"); | |
| for (const command of [...auth.commands, ...order.commands]) { | |
| if (command === order) { | |
| continue; | |
| } | |
| expect(command.options.some((option) => option.long === "--agent"), command.name()).toBe(true); | |
| } | |
| }); |
That skips the order group itself, which is a container rather than an agent-aware leaf (it declares no --agent at models-cli.ts:507) — worth confirming that's the only exclusion you'd want, since you know the intended semantics of each leaf better than the shape of the tree does.
f1b0b1c to
37e2d05
Compare
|
Follow-up review at The new commit is a tightening, not a loosening
Mutation, on So the old allowlist was the only thing that had been letting those four paths through without their own flag, and after this PR gives them one, deleting it raises the bar rather than lowering it. Unmutated the file is The open P3: it is hardening, not a hidden bug — and it is still worth addingFirst, a small correction to the finding's inventory, since it changes how much work is left. The two parser tables are missing different things:
So I table-drove those five ( The interesting part is whether those rows can catch anything the existing
The second row is the case the review named — a leaf that registers the option but does not forward it — and it is structurally invisible to an options-enumeration test. That is the argument for adding the rows even though nothing is broken today. Ready patch, test-only,
|
| path | commits on main since branch base 2db3431f4aa |
|---|---|
src/cli/models-cli.ts |
0 |
src/cli/program/root-command-descriptions.test.ts |
0 |
docs/cli/skills.md |
0 |
src/cli/skills-cli.ts |
1 — 90e39c49e46, a type-only narrowing of runWorkshopDraftAction's input parameter, no command registration touched |
docs/cli/models.md |
2 |
AGENTS.md |
1 |
git merge-tree --write-tree pr-head main exits 0, and the merge is behaviourally clean too, not just textually — on a local merge of current main into e62dbd0, with the five rows above applied:
node scripts/run-vitest.mjs run --configLoader runner \
src/cli/models-cli.test.ts src/cli/skills-cli.commands.test.ts \
src/cli/skills-cli.curator.test.ts src/cli/skills-cli.workshop.test.ts \
src/cli/program/root-command-descriptions.test.ts
Test Files 5 passed (5)
Tests 119 passed (119)
Windows 11, Node 24.15.0. Worth stating explicitly because a clean three-way merge does not by itself prove the fix still lands where the parser reads it — here it does.
On my earlier comment
The hardcoded-leaf-list point from my first review is resolved: declares --agent on every agent-aware auth leaf command now iterates auth.commands plus order.commands instead of listing them, so a future leaf that forgets the option fails without anyone editing the test. The AGENTS.md defaults caveat is still just a documentation nit and not a blocker.
|
Re-measured against today's The branch no longer merges cleanlyA week ago The The // main, after 2463ea0a5e6
.action(async (proposalId: string, opts: { json?: boolean; agent?: string }) => {
const { agentId, workspaceDir } = resolveSkillsWorkspaceForCommand(workshop, opts);while this branch's whole point at that call site is the leaf: .action(
async (proposalId: string, opts: { json?: boolean; agent?: string }, command: Command) => {
const { agentId, workspaceDir } = resolveSkillsWorkspaceForCommand(command, opts);So neither side can be taken wholesale: the fix's On that resolution, Windows 11 / Node 24.15.0:
A correction to my own earlier commentI wrote that The open P3 patch still applies and still earns its placeSame five leaf-form rows as before, applied on the resolved merge:
Exactly one test fails, and the The full patch is in my previous comment; nothing in it needed changing for today's |
e62dbd0 to
00d7a8d
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Maintainer merge review for exact head
|
|
Merged via squash.
|
…16587) * fix(cli): accept auth agent flag after subcommands * openclaw-87a: normalize inherited skills options * test(cli): classify curator leaf JSON flags * test(cli): cover all auth agent leaves
What
Allow nested model-auth and skills commands to accept inherited flags after the leaf command. Both parent and leaf placements work, and a leaf
--agentvalue takes precedence over the parent value.Why
The root CLI enables Commander positional options. Under that parser mode, a flag declared only on a parent command is rejected after a nested leaf. This affected model-auth agent selection, Skill Workshop agent selection, and Skill Curator JSON output.
Changes
Testing
00d7a8df461cf63d10e230af9d12a5b6f8c80171check-openclaw-package-tarball.mjsOpenClaw 2026.8.1 (00d7a8d)proof-agentand stored a syntheticopenai:proofAPI-key profile with trailing--agentmodels auth list --agent proof-agent --jsonreads the selected agent profile without exposing credentialsmodels auth login --provider openai --agent proof-agentreaches the expected non-interactive TTY guard, not an unknown-option errorskills workshop list --agent proof-agent --jsonreturns an empty proposal manifestskills curator status --jsonreturns an empty curator status documentnode scripts/run-vitest.mjs src/cli/models-cli.test.ts src/cli/skills-cli.commands.test.ts src/cli/skills-cli.curator.test.ts src/cli/skills-cli.workshop.test.ts src/cli/program/root-command-descriptions.test.tsnode scripts/check-changed.mjs.agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --stream-engine-outputRemaining Risk
Commander requires repeated leaf declarations under positional parsing. Registration and action-forwarding tests cover every applicable model-auth leaf, every Workshop leaf, and every Curator leaf so future drift fails CI.