Skip to content

fix(cli): report unknown-flag errors + cover nested subcommands (HF#2033) [P2]#2072

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/flag-error-telemetry-nested
Jul 8, 2026
Merged

fix(cli): report unknown-flag errors + cover nested subcommands (HF#2033) [P2]#2072
miguel-heygen merged 2 commits into
mainfrom
fix/flag-error-telemetry-nested

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

Addresses the two OPEN items from Rames' HF#2033 review (the load-bearing hardening behind the flag-hygiene arc, e.g. #2067).

1. Unknown-flag errors weren't reported to telemetry

assertKnownFlags ran before the try/catch in the command wrapper, so an unknown-flag throw bypassed reportCommandFailure — no signal on how often users hit bad flags. Moved the assertion inside the try so it's reported like any other failure.

2. Nested command groups weren't covered

cli.ts wraps only the top-level command loaders. citty dispatches hyperframes cloud render --badflag to the render leaf, whose run was never wrapped — so nested groups (cloud/*, auth/*, figma/*, lambda/*, capture/*, skills) silently ignored unknown flags and reported nothing. trackCommandFailures now recurses through cmd.subCommands (normalizing citty's Resolvable entries to loaders) and wraps every leaf. Object identity is preserved for bare no-run/no-subcommand defs.

Verified E2E

  • auth status --badflagError: Unknown flag: --badflag (previously silently ignored)
  • auth --help still dispatches correctly (no regression)
  • top-level lint --badflag still rejected

Tests

+2: an unknown-flag rejection is routed through onFailure; a nested subcommand's failure reaches onFailure. 15 tracker+reject tests pass.

…033)

Two flag-hygiene gaps behind the assertKnownFlags arc:

1. Telemetry loss: assertKnownFlags ran BEFORE the try/catch in the command
   wrapper, so an unknown-flag throw skipped reportCommandFailure entirely —
   zero signal on how often users hit bad flags. Moved the assertion inside
   the try so it reports like any other failure.

2. Nested-subcommand scope: cli.ts wraps only the top-level command loaders,
   so command groups' leaves (cloud/*, auth/*, figma/*, lambda/*, capture/*,
   skills) were never wrapped — citty dispatches to the leaf, whose run had no
   assertion and no failure reporting. So `hyperframes cloud render --badflag`
   silently ignored the flag. trackCommandFailures now recurses through
   cmd.subCommands (normalizing citty's Resolvable entries to loaders) and
   wraps every leaf. Identity is preserved for bare no-run/no-subcommand defs.

Verified: `auth status --badflag` now errors "Unknown flag: --badflag"
(previously silent); `auth --help` still dispatches; top-level `lint
--badflag` still rejected. Tests: unknown-flag rejection is reported, and a
nested subcommand's failure reaches onFailure.
CI Typecheck (tsc, unlike the local tsup build) flagged the nested-subcommand
test: indexing `subCommands["render"]` yields `T | undefined` under
noUncheckedIndexedAccess, so invoking it tripped TS2722/TS18048. Guard the
loader before calling it.
@miguel-heygen miguel-heygen merged commit 38b27c4 into main Jul 8, 2026
47 checks passed
@miguel-heygen miguel-heygen deleted the fix/flag-error-telemetry-nested branch July 8, 2026 20:24
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