Skip to content

fix: report unknown command before flag-support validation - #1038

Merged
thymikee merged 2 commits into
mainfrom
claude/issue-1036-unknown-command-order
Jul 3, 2026
Merged

fix: report unknown command before flag-support validation#1038
thymikee merged 2 commits into
mainfrom
claude/issue-1036-unknown-command-order

Conversation

@thymikee

@thymikee thymikee commented Jul 3, 2026

Copy link
Copy Markdown
Member

Summary

Fixes unknown-command detection to run before flag-support validation in the CLI parser. This resolves the bug where agent-device tap e3 --session foo reported "Flags --session are not supported for command tap" instead of the more helpful "Unknown command: tap".

Before/After

Before:

$ agent-device tap e3 --session foo
Error (INVALID_ARGS): Flags --session is not supported for command tap.

After:

$ agent-device tap e3 --session foo
Error (INVALID_ARGS): Unknown command: tap. Did you mean press or click?

Changes

  1. Reordered validation in finalizeParsedArgs (src/cli/parser/args.ts) to check if the command is known before validating flag support
  2. Added a small alias-suggestion map for helpful hints (e.g., tappress or click)
  3. Special handling for --help flag to allow graceful error messages from cli.ts
  4. Added tests to verify the fix works correctly

Closes #1036

When an unknown command is provided with flags, the parser was
validating flag support before checking if the command exists,
resulting in misleading "Flags are not supported for command X"
errors instead of "Unknown command: X".

This fix reorders the validation to check for unknown commands
first, reporting more helpful error messages. Additionally, when
the unknown command is 'tap', the error now includes a hint
suggesting 'press or click' as alternatives.

Closes #1036
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
JS raw 1.5 MB 1.5 MB +288 B
JS gzip 482.6 kB 482.7 kB +99 B
npm tarball 584.4 kB 584.5 kB +100 B
npm unpacked 2.1 MB 2.1 MB +288 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 27.1 ms 26.6 ms -0.5 ms
CLI --help 47.5 ms 47.6 ms +0.1 ms

Top changed chunks:

Chunk Raw diff Gzip diff
dist/src/cli.js +288 B +99 B

@thymikee thymikee left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Review: LGTM with two non-blocking notes. Verified locally (cli-help + parser suites pass) and confirmed the reorder does what #1036 asked: unknown command now wins over flag validation, with the tap → press/click suggestion.

  1. This adds a second source of command-knowledge. The early check derives "known" from the catalog (listCliCommandNames + INTERNAL_COMMANDS + hardcoded help), while the authoritative check remains the cli.ts:408 fall-through after all runners decline. I verified today's special-cased commands (auth/connection/mcp/proxy/web) are all in LOCAL_CLI_COMMANDS, so nothing regresses — but a future command wired only into cli.ts would now be rejected at parse time. Worth a one-line comment on isCommandKnown pointing at the cli.ts fall-through as the thing it must stay in sync with (or, later, extracting one shared helper).

  2. includes(command as any) ×2 — prefer widening the array instead of narrowing the value: (listCliCommandNames() as readonly string[]).includes(command).

Known accepted gap: tap --help still takes the old path (deliberate flags.help skip) and reports without the alias suggestion — fine, but worth stating in the PR body so it reads as a decision rather than an omission.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Jul 3, 2026
Review follow-ups: widen the command lists to readonly string[] instead
of narrowing the value, and document that isCommandKnown must stay in
sync with the cli.ts dispatch fall-through.
@thymikee

thymikee commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

Applied the review nits directly on the branch (6df7d4e): dropped both as any casts (widened the lists to readonly string[]) and added the sync-requirement comment on isCommandKnown pointing at the cli.ts dispatch fall-through. Tests/format/typecheck green.

@thymikee
thymikee merged commit 0453826 into main Jul 3, 2026
21 checks passed
@thymikee
thymikee deleted the claude/issue-1036-unknown-command-order branch July 3, 2026 08:15
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-03 08:15 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unknown command reports flag-support errors instead of 'unknown command'

1 participant