Skip to content

feat(parse): add subcommand value precedence - #1105

Merged
jdx merged 1 commit into
agent/args-conflict-subcommandsfrom
agent/subcommand-precedence
Aug 20, 2026
Merged

jdx merged 1 commit into
agent/args-conflict-subcommandsfrom
agent/subcommand-precedence

Conversation

@jdx

@jdx jdx commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • add subcommand_precedence_over_arg across KDL, typed Rust, usage-lib, clap conversion, and generated/runtime Go
  • let a known child interrupt a variadic value owner only when explicitly enabled
  • document the policy and remove its obsolete fidelity warning

Verification

  • cargo test --all --all-features
  • cargo clippy --all --all-features -- -D warnings
  • go test ./... (from go/)

AI-generated pull request.


Note

Medium Risk
Changes argv routing in Rust and Go parsers, but behavior is opt-in per command and covered by new tests; main risk is subtle interaction with variadic flags, positionals, and args_conflicts_with_subcommands.

Overview
Adds clap-aligned subcommand_precedence_over_arg end-to-end. When a command sets it, a recognized subcommand token can stop an in-progress variadic value owner instead of being swallowed as another value; default stays off, so existing CLIs are unchanged unless they opt in.

Parsing changes land in usage-argv and usage-lib (plus generated Go): an early subcommand check while variadic collection is active, with args_conflicts_with_subcommands still blocking parent args + child selection. Metadata flows through Command / spec KDL, #[command(subcommand_precedence_over_arg)], conformance tables, and clap bridge/spec emission; clap_usage no longer reports this as a fidelity loss.

Docs, migration notes, and tests (including typed Precedence + KDL variadic-flag case) cover the new policy; allow_missing_positional remains the open parsing-policy gap in PLAN.md.

Reviewed by Cursor Bugbot for commit e4c0c41. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 682b09a1-3cb8-49ef-b07f-8fce75854afd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread argv/src/lib.rs
Comment thread lib/src/parse.rs
@jdx
jdx force-pushed the agent/subcommand-precedence branch from 8f506a7 to dd0f5ac Compare August 20, 2026 05:01
@jdx
jdx force-pushed the agent/subcommand-precedence branch from dd0f5ac to cad6a2a Compare August 20, 2026 05:14
@jdx
jdx force-pushed the agent/subcommand-precedence branch from cad6a2a to c85f61e Compare August 20, 2026 05:37

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c85f61e. Configure here.

Comment thread argv/src/lib.rs
@jdx
jdx force-pushed the agent/subcommand-precedence branch from c85f61e to f98a59c Compare August 20, 2026 05:50
@jdx
jdx force-pushed the agent/subcommand-precedence branch from f98a59c to 259e957 Compare August 20, 2026 05:52
@jdx
jdx force-pushed the agent/subcommand-precedence branch from 259e957 to f3c8270 Compare August 20, 2026 05:54
@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Instruction counts

Nothing was compared, and so nothing was gated. No series appears on both sides: either the base has no measurements recorded, or the two were measured on different runner classes, which are deliberately not comparable — counts shift between machine types by more than a real regression does.

New, nothing to compare against: markdown on bamboo-v2-ubuntu24.04-x64-30vcpu-24gb-rust1.97.1, startup on bamboo-v2-ubuntu24.04-x64-30vcpu-24gb-rust1.97.1

Only instruction counts gate. Wall clock is shown for context — on identical hardware it moves 4-20% run to run.

Measured by tak — instruction-counted CLI benchmarks, stored in this repository's git notes.

Shadow comparison

Parsing mise use -g node@20 against a shadow of mise's committed spec.
Reported, not gated: the shadow grows as the derive learns to express more, so
what to watch is the ratio rather than either column.

framework instructions, cold parse vs usage
usage 4328
argh 6292 1.5x
clap 5895248 1362x
bpaf 21917796 5064x
                                              min       p01       p10    median
usage-rs: argv -> struct                      185       187       192       196  ns
argh: argv -> struct                          287       292       298       314  ns
clap: build tree + parse -> struct         483924    488693    494912    509226  ns
bpaf: build parser + parse -> struct      1622604   1622604   1630854   1668090  ns

usage: argv -> struct                             217 ns      0.22 µs
clap: build tree + parse -> struct             486885 ns    486.88 µs
clap: parse -> struct, tree reused              23039 ns     23.04 µs
clap: build tree only                          304969 ns    304.97 µs

e4c0c41518be vs 7e0931de618f · measured on the runner, not pushed to the history.

@jdx
jdx force-pushed the agent/subcommand-precedence branch from f3c8270 to 936ef16 Compare August 20, 2026 07:05
@jdx
jdx force-pushed the agent/subcommand-precedence branch from 936ef16 to f89dcf4 Compare August 20, 2026 07:17
@jdx
jdx force-pushed the agent/subcommand-precedence branch from f89dcf4 to e4c0c41 Compare August 20, 2026 07:53
@jdx
jdx merged commit 9757f9b into main Aug 20, 2026
10 checks passed
@jdx
jdx deleted the agent/subcommand-precedence branch August 20, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant