refactor(commands): declare project-config admission and recorder sanitization on the flag declaration
What
A flag's two fail-closed properties — may it be set from a project agent-device.json and does the session recorder copy it into SessionAction.flags — move off their hand-maintained allowlists and onto each FlagDefinition as required projectConfig / recorded fields. Omitting either is now a type error, so the compiler holds the fail-closed property a list held by omission.
Closes #2445 (Wave 2 child of #2409; the "#1665-shaped follow-up" named in #2421).
Changes
FlagDefinitiongains requiredprojectConfig: booleanandrecorded: boolean. All 156 declarations plus the 6ScreenshotSpecificFlagDefinitionentries carry both.recordedis constrained toCommandFlagskeys by the type:FlagDefinitionis a union that pinsrecordedtofalsefor aNonRecordableFlagKey = Exclude<FlagKey, keyof CommandFlags>(json / help / version / replayMaestro / daemonAuthToken). This preserves thesatisfies readonly (keyof CommandFlags)[]guard the old list carried, sorecorded: trueon a CLI-only key does not compile and cannot leak into a recorded action.cli-config.tsandsession-action-recorder.tsderive their sets from the registry and no longer list keys (PROJECT_CONFIG_FLAG_KEYS/SANITIZED_FLAG_KEYSliterals deleted).SCREENSHOT_ACTION_FLAG_KEYSstays (screenshot-options.test.tsstill consumes it).- Derivations (
projectConfigFlagKeys()/recordedFlagKeys()inflag-registry.ts) recompute per call so each consumer freezes its set at its own module load — which is what lets a planted declaration move the surface.recordedFlagKeys()returnsReadonlySet<RecordableFlagKey>via a narrowing predicate, sosanitizeFlagsneeds no cast. - The recorder reaches the derivation through the
cli-schema/command-schema.tsseam: R2commands-floorforbidsdaemon/ -> commands/. - Planted-divergence tests per the #2421 pattern, plus two
@ts-expect-errorcompile-time pins (missing fields; a CLI-only key cannot opt into recording). docs/agents/cli-flags.mdpoints at the declaration fields, not the deleted allowlist.
Acceptance (from the issue)
- Re-doing #1665 edits the declaration, no allowlist: both consumer files now derive; re-adding a flag touches only the declaration.
- Derived sets equal the deleted sets — one-off diff is empty (verified against
HEAD):- PROJECT_CONFIG: derived 85 = original 85; only-derived
[], only-orig[] - RECORDED: derived 39 = original 39; only-derived
[], only-orig[] cli-config-trust.test.ts(19) andsession-action-recorder.test.ts(27) stay green with no edits.
- PROJECT_CONFIG: derived 85 = original 85; only-derived
- A declaration without both fields does not compile: enforced by the required fields +
@ts-expect-errorpins; fullpnpm typecheckgreen.
Size & design tradeoff
The size bot reports roughly +3 kB unpacked (the exact figure drifts run to run — it has shown +3.0 to +3.3 kB; download is slightly negative; startup within noise). The growth is the two required booleans repeated across all 162 declarations in the emitted bundles — inherent to stating the property per declaration rather than in one list.
The smaller alternative is to keep the two sets as standalone allowlists and not touch the declarations: near-zero bundle cost, but it is exactly the "fail-closed by omission, so a new flag edits a second file anyway" shape #2410/#2445 retire, and it cannot express the CommandFlags guard on a per-declaration basis. Retaining required declarations (so omission is a type error, not a silent drop) over another allowlist is the deliberate tradeoff here: +3 kB unpacked, one file per flag instead of two, and the guard moves onto the declaration.
Verification
pnpm build, pnpm typecheck (all packages + examples), pnpm lint, pnpm format:check, pnpm check:layering, check:production-exports, check:mcp-metadata, check:gate-manifest, check:bundle-owner-files, check:package — all green. Targeted suites: src/daemon (2639), packages/contracts + src/commands/capture + src/cli/parser (447), plus cli-schema/commands/cli-grammar and the new test. Rebased onto main (3bbeb61917); no upstream change touched these files.
Notes
docs/adr/0012-interactive-replay.mdstill namesSANITIZED_FLAG_KEYSin a point-in-time record; left unchanged (ADRs are historical and the described behavior —--settle/--verifydropped from recordings — is unchanged).