Repository navigation
refactor(cli): derive contract-backed command options from the tool contract - #10571
Conversation
…ontract Each contract-backed CLI command restated its contract's input fields as hand-written incur options and mapped them back to snake_case input with conditional spreads. Nothing checked that the two schemas agreed. Add registerContractCommand: a per-command projection names only what the CLI spells differently (positionals, caller-relative path fields, option renames, CLI help wording, omitted optional fields with a reason). Option schemas, decimal argv tokens and the contract's cross-field rules are derived from the contract input schema, and parsed options map back to the contract input mechanically. Migrate inspect-sqlite-database and the thirteen flat binary-diagnostics inspectors. Their --schema output is unchanged apart from property order, and help lists options in contract order. Delete the SQLite superRefine that mirrored the contract and the per-command spreads. Add a parity test: every projected command exposes each contract field or declares its omission, and each field admits exactly what the contract admits for empty, NUL, relative-path, bound and numeric-spelling probes.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c27b1c552
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
[Medium impact] The PR appears safe to merge; no blocking issue remains in the reviewed changes. SummaryDerives options for SQLite and 13 binary inspectors from their tool contracts.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Tool contract"] --> C["describeContractCommand"]
B["CLI spelling choices"] --> C
C --> D["registerContractCommand"]
D --> E["Incur parses arguments and options"]
E --> F["Map fields and resolve caller paths"]
F --> G["Service validates and inspects"]
G --> H["Finish cleanup and return Evidence"]
Reviews (4) · Last reviewed commit: "refactor(cli): describe contract command..." · Reviewed by Greptile |
Address review findings on the contract projection: - Bind inspect-sqlite-database to its contract by name instead of catalog position. - Accept only field forms argv can carry (string, number, boolean, enum, and arrays of strings or enums) instead of rejecting a short list, so arrays of objects, tuples and other forms fail at registration. - Refuse root input keywords other than the projected object constraints and presentation annotations, so a contract rule such as `not` cannot disappear from --schema.
…amework Split the contract projection into a framework-neutral description and a thin Incur adapter, so a later REA-owned CLI layer (#10583) can render the same description. - contractCliDescription.ts derives each positional and option from the contract and projection: key and short flag, help, argv admission schema, boolean-flag/repeatable/decimal/caller-path facts, object constraints renamed to CLI keys, the optional argv-time cross-field check, and the mapping back to contract input. - contractCommand.ts only renders that description as Incur args and options and runs the handler. Cross-field rules now refuse at argv parsing only when a projection asks (inspect-sqlite-database does, keeping its behavior); otherwise the service's contract parse refuses them as before. Exact-optional fields are projected as optional because argv cannot carry an explicit undefined and Incur's help reads flag and choice types only through optional. The parity guard reads the descriptions, and also checks that boolean fields parse as bare flags and that no projected field stays exact-optional.
|
The Greptile summary's Issue 1 ("Dependent callers lose required exports") no longer applies. The dependent PR was updated with this refactor:
@greptileai please re-review. |
Summary
Contract-backed CLI commands restate each tool contract's input fields as hand-written incur options, then map them back to snake_case input with conditional spreads. Nothing checks that the CLI and the contract admit the same values, which has produced the "CLI schema drift" issue family (S01/S02: NUL bytes, missing bounds, renamed fields, decimal tokens).
This PR adds one owner for that projection,
registerContractCommand, migrates a pilot set of commands onto it, and adds a parity guard. It is the first slice of plan W1 ("one definition per operation"). Refs #9348 (decimal-token bounds class; not closed here). Refs #10583: the description is framework-neutral, so a REA-owned CLI layer could render it in place of Incur.Problem and expected behavior
src/cli/sqliteCommands.tsre-declared six options, asuperRefine"mirroring" the contract's table-selection rules, adependentRequired/if/thenblock, and six conditional spreads.src/cli/binaryDiagnosticsCommands.tsrepeated a ~40-line command body per inspector with a hand-written camelCase-to-snake_case map.absoluteCallerPath), and a test enforces that.Change and scope
src/cli/contractCliDescription.ts(framework-neutral; imports zod, not Incur):CliContractProjection: command name, description,positionals,callerPaths, per-fieldname(rename),alias(short flag) anddescription(CLI help wording),omit(optional fields the one-shot command does not expose, each with a reason), andcrossFieldRules: "argv".describeContractCommand(contract, projection)returns aContractCliDescription:cliDecimalShape/cliDecimalField; caller-path fields admitlocalPathStringSchema.dependentRequired/if/then/elsemetadata, renamed to CLI keys.crossFieldRules: "argv";inspect-sqlite-databasedoes, matching its previous hand-written refinement. Otherwise the service's contract parse refuses the combination, as for hand-written commands.toContractInput(values), which drops omissions and resolves caller paths withabsoluteCallerPath, andcallerInputs(values).optional. Argv cannot carry an explicit undefined, and Incur's help reads flag and choice types only throughoptional.src/cli/contractCommand.tsis a thin Incur adapter.registerContractCommand(cli, logger, contract, projection, run)renders the description as Incurargs/options/aliasand runs the handler inside the existingwithCommandCancellationandlogCliCommandwrappers.inspectWithService(service, providerId)is the sharedfinishCliEvidenceCommand+projectCliAnalysisResultbody the inspectors used.inspect-sqlite-database, plus 13 flat binary-diagnostics inspectors (inspect-elf-notes,-native-initializers,-elf-unwind-ranges,-apple-ips,-kernel-module,-kernel-build-config,-pe-load-config,-binary-hardening,-byte-entropy,-pe-certificates,-pe-imports,-windows-shortcut,-pe-resources). Deleted their hand-written option schemas, spreads and the mirrored SQLitesuperRefine.inspect-devicetree,inspect-native-exports,inspect-binary-layoutandinspect-recorded-crashstay hand-written for now: they use evidence delivery options, producer-limit JSON, or a renamed boolean.CLI_COMMANDS, the MCP registration loop,TOOL_EFFECT_AUDITkeys andCapabilityInventorychecks.Contract and boundary impact
describeContractCommand;registerContractCommandonly renders it for Incur. The tool contract stays the single definition. Superseded per-command option declarations and mappings for the 14 commands are removed.--schemaoutput for all 14 commands is semantically identical before and after (compared with object keys andrequiredsorted).inspect-sqlite-databaselists the same option lines in contract order, so--worker-timeout-msmoves from first to last.pathspelling throughfinishCliEvidenceCommand.Expected effects:
(No effect changes: the migrated commands read the same files as before.)
Evidence and regression coverage
tests/boundary/cli/cliContractCommandParity.test.tsruns over every contract command description registered in the complete CLI. It checks that:omit;0x10,1e3,010,+1,-1,1.5, and enum members;not.inspect-sqlite-databasebinds its contract by name (contractNamed), not by catalog position. The argv-form check is now an explicit allowlist. Unknown root input keywords are refused.z.string()made the "admits exactly what its contract admits" case fail for every migrated command. Reverting restored the pass.rea <cmd> --schema --format jsonandrea <cmd> --helpfor all CLI commands from the base build, and again after the change for the 14 migrated commands.--schemawas semantically equal for all 14.--architecturehelp wording oninspect-native-initializers) is preserved with adescriptionoverride.inspect-sqlite-databasehelp option order.Validation performed
npm run typecheck: passed.npm run check:fast: passed.npm run knip: no findings.npm run verify:architecture-guards: passed.npm run lint:typed: exit 0 (existing warning counts only).npm run docs:check: passed.npx oxfmt --checkon changed files: passed.npm run test:focused --the new parity test plus 41 existing files: 41 passed, 1 skipped; 446 tests passed, 2 skipped.After the framework-neutral split and review fixes (latest commits):
npm run check:fast: exit 0.npm run knip: no findings.npm run test:focused --the parity guard plus 12 files (overnight batch-1 schemas, decimal/integer arguments, lazy registration, startup imports, empty diagnostic target, help default annotations, and the sqlite, apple-ips, local-path admission, format-specific caller path and byte-entropy acceptance tests): 12 passed, 1 skipped; 245 tests passed, 2 skipped.--schema/--helpcapture re-compared for all 14 commands, with the same result as above.Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.