Repository navigation
feat(cli): reject unknown flags on every command, from a declared surface - #494
Merged
Merged
Conversation
|
✅ Docker image built successfully
|
…face Two command modules validated their flags and 43 did not (#488). The class is not theoretical: `kit check --category security` ran the FULL check for six majors because nothing rejected the flag, and `kit upgrade --self.` — one trailing period — fell through to the lock-file branch, rewrote every `installedAt`, installed nothing and printed the success line. Sweeping 43 handlers would fix today and rot tomorrow, so the shape is the one read-only-surface.ts already uses for the write surface: a declared table (src/flag-surface.ts, 71 verbs) and one refusal at dispatch. The table is GENERATED from the source — scripts/derive-command-flags.mjs unions every `--flag` literal in a command's own module (security.ts reads --only / --skip / --exclude through a local commaList() helper, which a reader-only scan missed), the literals its DIRECT imports hand to an argv reader (depth 1 is where the --attest regression lived: a hand-built CHECK_FLAGS from check.ts's own literals rejected `kit check --attest` and --no-auto-install, both documented and both read in cli-checks-shared.ts), and every flag docs/COMMANDS.md documents for that verb. flag-surface.test.ts fails when the table drifts, so a new flag cannot land unlisted. GLOBAL_FLAGS are unioned in by the guard rather than listed per verb — that omission is what made `kit check --read-only` exit 1 without running. Everything after `--` passes through untouched. The sets err toward accepting: over-accepting leaves a working invocation working, under-accepting breaks one. The guard catches what does NOTHING. The sweep surfaced two real defects, both measured: - `kit add --list` is documented in kit's own help twice and read nowhere, so argv[3] took the flag as the SERVICE NAME: the documented invocation printed "Provisioning --list..." then "Unknown service: --list". It now lists and exits 0; bare `kit add` still exits 1, since a forgotten argument is not a completed provision. - `kit setup --activate-mise` never existed. mise-path.ts claimed that flag appends the mise-shims PATH line; no code reads it and ensureMiseActivation has no production caller at all. The claim is corrected rather than the feature quietly invented — writing to a shell profile needs its own consent design. Both were silent before the floor and would have become rejections of kit's own advice after it, so a test pins that kit never prints an invocation its own floor rejects. That test found the first one. self-audit's flag-validation row now measures verbs against the declared surface instead of grepping src/commands/*.ts for the string `unknownFlags(` — that measured the shape of the fix, missed verbs inside multi-handler modules, and could never see `fix` or `plugin`, which do not live under src/commands at all. Closes #488 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
sandstream
force-pushed
the
feat/488-flag-floor
branch
from
August 20, 2026 08:20
acceae3 to
a903821
Compare
|
✅ Docker image built successfully
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #488.
What
Every command verb now rejects flags it does not accept — 71/71, from 2/45.
The shape is the one
read-only-surface.tsalready established for the write surface: a declared table plus one refusal at dispatch. Sweeping 43 handlers would have fixed today and rotted tomorrow; the defect #488 names is that nothing enumerated which flags a command accepts, so "did we cover everything?" had no answer.The table is generated, not hand-written
#488warned that an allowlist from the wrong source is its own outage —CHECK_FLAGSwas built fromcommands/check.ts's own literals and rejectedkit check --attestand--no-auto-install, both documented, both read one import away incli-checks-shared.ts.So
src/flag-surface.tsis emitted byscripts/derive-command-flags.mjs, which unions, per verb:--flagliteral in the command's own module — needed becausecommands/security.tsreads--only/--skip/--excludethrough a localcommaList(name)helper, which a reader-only scan missed;hasFlag/flagValue/flagInt/includes/indexOf/===/startsWith) — depth 1, which is exactly where the--attestregression lived;docs/COMMANDS.mddocuments for that verb;COMPAT_FLAGSentry:agent-config --install-gate, whichcommands/agent.tsstates "is still accepted for backward compatibility" and which nothing reads — so no scan could find it, and a scan-only floor would have started rejecting an invocation kit's own generated banner still prints.GLOBAL_FLAGSare unioned in by the guard rather than listed per verb, so a global can never be missing from one — the omission that madekit check --read-onlyexit 1 without running. Everything after--passes through untouched, sokit run -- pnpm test --watchis unaffected.The sets err toward accepting: a flag kit only passes to a subprocess can appear. Over-accepting leaves a working invocation working; under-accepting breaks one. The guard's job is to catch what does nothing.
Two defects the sweep surfaced (both measured, both fixed)
1.
kit add --listprovisioned a service named--list. kit documented it in two places — the help table (kit add --list # List all available adapters) and the command's own one-line help — and read it nowhere, soargv[3]took the flag as the service name. On cleanmain:--listnow lists and exits 0. Barekit addstill exits 1: a forgotten argument is not a completed provision.2.
kit setup --activate-misenever existed.mise-path.tssaid that flag appends the mise-shims PATH line. No code reads it, andensureMiseActivation— the appender — has no production caller at all (it is in self-audit's unwired-code advisory).kit doctorreports the gap and prints the line. The claim is corrected rather than the feature quietly invented: writing to a user's shell profile needs its own consent design. Flagged as a follow-up, not smuggled in here.Both were silent before the floor. After it they would have become rejections of kit's own documented advice — worse than the silence — so a test now pins that kit never prints an invocation its own floor rejects. That test is what found #1.
The self-audit row now measures the property, not the fix's shape
flagValidationCoveragegreppedsrc/commands/*.tsfor the stringunknownFlags(. That measured whether a file contained a guard: a module with several handlers could hold one and leave its other verbs open, and two verbs (fix,plugin) do not live undersrc/commandsat all, so no grep there could ever see them. Coverage is now "every verb inCOMMAND_REGISTRYhas an entry in the declared surface", and a verb without one is reported as unvalidated rather than counted as covered. A missing table reports every verb as missing — fail-open there would have called a repo with no flag surface fully validated.self-auditadvisories: 143 → 100.Tests
src/flag-surface.test.ts— 17 tests:flagsForCommandreturnsnull(skip + report) rather than[](reject everything) for an unknown verb--category,--attest/--no-auto-install,--only/--skip/--exclude)rejectUnknownFlags: names every unknown flag, prints the accepted set once (deduped — callers union withGLOBAL_FLAGS, which overlap), leaves--pass-through alone, writes to stderr so a--jsonstdout stays parseablekit upgrade --self.is caught;kit secrets --drry-runis caught (the side-effectful module 43 command modules still accept unknown flags silently — sweep the flag-validation advisory to zero #488 put first);kit audit --limit 1still runskit <verb> --flagin a string literal undersrc/**or in the CI workflows is accepted by the floorRewrote the three
flagValidationCoveragefixtures for the verb-based oracle, plus a new one for hyphenated verbs (gha-audit) and one asserting a missing table fails closed.Verification
npm test: 4299 tests, 0 fail, 0 skipped (macOS, non-root). The suite is the real safety net here — a floor that rejects a valid flag shows up as a failing command test, and none did.kit self-audit: 16 rules, 0 fail, 0 warnkit check --category security: 24/25, the one finding being the pre-existing historical-secret warn on git history.github/workflows/*.yml,src/hooks.tsor the agent-config generators is rejectedNot in scope
kit check verify-attestationaccepting only its own flags).commands/check.tskeeps its finer per-form guards; the floor is the union, i.e. the floor, not a replacement.ensureMiseActivation(needs a consent design for shell-profile writes).🤖 Generated with Claude Code