Skip to content

fix(cli): a lone word that is a nested subcommand is a mistyped command, not a task - #100

Merged
zeekay merged 1 commit into
mainfrom
job/nested-word
Nov 27, 2026
Merged

zeekay merged 1 commit into
mainfrom
job/nested-word

Conversation

@jamessburnss1313-dev

@jamessburnss1313-dev jamessburnss1313-dev commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What a customer would see

hanzo balance and hanzo quota, typed by two people on 25 Nov 2026, each opened a coding-agent session. The real commands are hanzo billing balance and hanzo sandbox quota. After this change:

no command `balance`: did you mean `hanzo billing balance`? As a coding task: `hanzo dev "balance"`

Cause

misspelled() in src/main.rs (called from run) compared a lone word only with the top-level command names, by similarity (0.85). A word that is exactly a subcommand deeper in the tree is neither top-level nor similar to one, so it fell through to the coding session.

Fix

A lone word that is exactly the name or alias of ONE visible command deeper in the tree is answered with that path (nested() collects them; a hidden command hides its subtree). If a near top-level command also fits, it is named second in the same sentence:

no command `undeploy`: did you mean `hanzo ai deployments owner undeploy` or `hanzo deploy`? As a coding task: `hanzo dev "undeploy"`

A word that names two or more deeper commands is ambiguous and changes nothing: the near top-level match if there is one, otherwise a task, as on main. The tree passed in is the merged one (augment), so the generated groups (billing, sandbox) are in it. A quoted multi-word task, a backend name, a word with flags after it, and a word found nowhere are unchanged. On main a near top-level match won outright, which gave the opposite action for undeploy (hanzo deploy) and models for mode; that is why the exact path now comes first.

Tests (written first)

Red, as run (against the first version of this branch, where a near top-level match won and several deep matches were listed):

  • tests::a_lone_word_that_is_one_nested_command_names_its_path FAILED (undeploy answered only "did you mean hanzo deploy")
  • tests::only_a_unique_nested_match_is_named FAILED (two deep matches, go, still gave an answer)

Against main these two were not run. By reading: on main the first fails at balance (no message at all) and the second at solo.

Green, after: the whole hanzo bin suite 459 passed (includes the existing a_lone_near_miss_names_the_command_and_a_task_still_runs: stauts still suggests status, a quoted task and whoami and claude unchanged); tests/cli.rs 25 passed; cargo clippy --locked --all-targets -- -D warnings clean.

What the new tests cover: on the real tree, balance and quota (one path each on current main), undeploy (exact path first, hanzo deploy second), create (many matches: still a task) and an unknown word (still a task). In a small tree: a unique name that also has a near top-level match (exact first, near second), an alias, a hidden command that is skipped, two matches and no near match (a task), and a near-only word.

Measured risk

Each word typed alone, on main and with this change (a throwaway test, not committed):

word main this change
test, review, analyze, document, merge, update, check, install, explain, refactor, debug task task
fix task refused: hanzo patrol unit fix
commit task refused: hanzo ai records commit
generate task refused: hanzo content generate
diff task refused: hanzo graph diff
build, deploy, status, help, plan existing command existing command
run retired, names hanzo dev same (the retired check runs first)
lint refused: hanzo link refused: hanzo link
format refused: hanzo form refused: hanzo o11y query_range format or hanzo form
undeploy refused: hanzo deploy refused: hanzo ai deployments owner undeploy or hanzo deploy
mode refused: hanzo models refused: hanzo billing mode or hanzo models

Risk

Of the words measured, four one-word tasks are newly refused: fix, commit, generate, diff. The table is a sample, not the whole list: any ordinary word that is exactly one deeper command's name is refused the same way. A read of the generated commands also finds docs (team docs), clone (o11y dashboards clone), schedule (marketing campaigns schedule), apply (affiliate apply) and email (notify send email). The way out is in the message: hanzo dev "fix" runs it as a coding task; it is the same one retype the existing near-miss rule already costs for lint. Whether that trade is right is the maintainers' call. Two words that were already refused (format, mode) and undeploy now name the exact command as well. Every other word measured behaves as on main.

Not tested

  • The installed binary on a real terminal.
  • cargo fmt --check already reports diffs on main in other places; the lines this PR touches are clean.

How to revert

git revert the commit; it is one commit.

Built by one agent; an independent review follows. Nothing merged; production is Zach's call.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T02:44:43.033357Z
We couldn’t complete this review. Comment @codex review to try again.
637132a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

zeekay commented Nov 27, 2026

Copy link
Copy Markdown
Member

Thanks for the command-tree regression tests. Holding merge: no CI run or combined status was returned for current head 5931c27, and the automated review receipt is for the older 637132a commit. Please attach current-head CI for the workspace and shipped binary invocation; verify hanzo balance, hanzo quota, explicit hanzo dev and ambiguous one-word tasks, then re-request review.

@zeekay

zeekay commented Nov 27, 2026

Copy link
Copy Markdown
Member

Rebased onto modularized main (8028ad70) at aee5e348:

  • Verified a_lone_word_that_is_one_nested_command_names_its_path (balance, quota, undeploy, mode exact-first + near-second, dev balance, ambiguous create), only_a_unique_nested_match_is_named (15/15 main_tests), and shipped binary shipped_binary_intercepts_unique_nested_subcommand_typo (27/27 tests/cli.rs).
  • cargo clippy --locked --all-targets -- -D warnings: 0 warnings.

@zeekay
zeekay merged commit e268bcd into main Nov 27, 2026
@zeekay
zeekay deleted the job/nested-word branch November 27, 2026 03:52
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.

2 participants