Skip to content

fix(cli): honor global flags before the command word, and reject a typo'd upgrade flag - #487

Merged
sandstream merged 1 commit into
mainfrom
fix/global-flags-dispatch
Aug 20, 2026
Merged

sandstream merged 1 commit into
mainfrom
fix/global-flags-dispatch

Conversation

@sandstream

@sandstream sandstream commented Aug 19, 2026 •

Copy link
Copy Markdown
Owner

Found by running kit upgrade --self. — with a trailing period. It reported a successful upgrade and upgraded nothing.

Three defects, one class: argv handling that fails silently or fails wrongly. All measured against the published 6.6.5, not inferred.

1. A typo'd flag silently became a different operation

kit upgrade --self. missed hasFlag's exact match, fell through to the lock-file path, and rewrote every installedAt in .kit/cli-lock.json to "now" while installing nothing — under the normal success output. The user had no signal that the self-upgrade never ran.

cmdUpgrade now rejects unknown flags with the unknownFlags helper this repo already ships. self-audit/flag-validation has been advising exactly this for 44 command modules; this fixes the one where it bit. The remaining 43 are a separate sweep (#488) — the --attest history shows an allowlist built from the wrong source is its own outage, so they need per-command verification, not a mechanical pass.

2. kit check rejected two documented global flags

Invocation 6.6.5 after
kit check --read-only exit 1, unknown flag for kit check runs
kit check --non-interactive exit 1, unknown flag for kit check runs
kit check --env=prod exit 1, unknown flag for kit check runs
kit check --not-a-real-flag exit 1 exit 1 (unchanged)

All three are global — --read-only/--non-interactive are in the "Global flags" table of docs/COMMANDS.md, --env= is read by config.ts:resolveActiveEnvironment off raw argv for every command. CHECK_FLAGS was built from the check path's own literals only: the same false red as the --attest regression its own comment documents. A gate that refuses to run is the mirror image of a false green.

3. kit --read-only <cmd> never dispatched

The form documented in README.md:299 and docs/THREAT_MODEL.md:98 activated read-only mode and then answered Unknown command: --read-only (exit 1) — for every command, since the flag was args[0].

cli.ts now splits leading global flags off the positional stream and re-appends them behind it. That ordering matters: command modules read subcommands off raw indices, so a flag in front of the command word shifts all of them. Verified end to end that kit --read-only check verify-attestation reaches the subcommand.

Oracle

GLOBAL_FLAGS is asserted against docs/COMMANDS.md's own table, not a second copy of the list — a test that restated the flags would have passed happily while the flag was rejected in production. The docs scan has a guard asserting it matched something, per the five historical measurement bugs in this repo that were regexes matching nothing.

--env=<name> is added to that table, and the table now states that globals may be written on either side of the command word.

Verification

  • full suite 4274/4274 (was 4274 before, +14 new)
  • npm run lint clean, format:check clean
  • kit check --category security: 24/25, one pre-existing accepted secrets-scan warn — unchanged
  • the built CLI driven directly against all three broken invocations, plus kit upgrade (happy path) and kit check --not-a-real-flag (rejection must survive the widened allowlist)

🤖 Generated with Claude Code

…po'd upgrade flag

Three defects in one class — argv handling that fails silently or fails wrongly.
All three were measured against the published 6.6.5, not inferred.

1. `kit upgrade --self.` (trailing period) missed hasFlag's exact match, fell
   through to the lock-file path, rewrote every `installedAt` in
   .kit/cli-lock.json to "now" while installing nothing, and printed the normal
   success line. A typo silently became a different operation. `cmdUpgrade` now
   rejects unknown flags via the `unknownFlags` helper the repo already ships —
   self-audit/flag-validation has been advising exactly this for 44 command
   modules.

2. `kit check --read-only` and `kit check --non-interactive` exited 1 with
   "unknown flag for kit check" and never ran the check. Both are in the
   "Global flags" table of docs/COMMANDS.md; CHECK_FLAGS was built from the
   check path's own literals only — the same false red as the `--attest`
   regression its own comment documents. GLOBAL_FLAGS is now part of every
   check allowlist, and check-flags.test.ts pins the superset relation.

3. `kit --read-only check` — the form README.md:299 and docs/THREAT_MODEL.md:98
   both document — activated read-only mode and then answered "Unknown command:
   --read-only" (exit 1), because the flag WAS args[0]. cli.ts now splits
   leading global flags off the positional stream and re-appends them behind it,
   so raw-index subcommand reads (`process.argv[3] === "verify-attestation"`)
   see the same shape as the flagless form. Verified end to end:
   `kit --read-only check verify-attestation` reaches the subcommand.

The oracle for GLOBAL_FLAGS is docs/COMMANDS.md's own table, not a second copy
of the list — a test that restated the flags would have passed happily while
the flag was rejected in production. `--env=<name>` is added to that table:
config.ts has always honored it globally off raw argv.

Full suite 4274/4274, lint clean, `kit check --category security` unchanged
(one pre-existing accepted secrets-scan warn).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@sandstream
sandstream merged commit e54507f into main Aug 20, 2026
19 checks passed
@sandstream
sandstream deleted the fix/global-flags-dispatch branch August 20, 2026 06:39
sandstream added a commit that referenced this pull request Aug 20, 2026
Promotes the #487 arc decision to the curated shared tier: hasFlag matches
exact tokens, so a near-miss flag is invisible and the command silently
takes another branch (`kit upgrade --self.` rewrote lock-file timestamps
instead of self-upgrading). The entry records the rule plus the two
corollaries — command allowlists include GLOBAL_FLAGS, and leading globals
are stripped before positional dispatch.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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