Skip to content

refactor(cli): project JSON-document workflow commands from their contracts - #10668

Merged
morluto merged 2 commits into
mainfrom
refactor/cli-contract-json-document
Nov 15, 2026
Merged

morluto merged 2 commits into
mainfrom
refactor/cli-contract-json-document

Conversation

@morluto

@morluto morluto commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Summary

This is the eleventh slice of plan W1. It is stacked on #10656 (base refactor/cli-contract-session-target); retarget it as the lower PRs merge. Refs #10583.

This PR adds a JSON-document projection for contracts whose whole input is one JSON document. It moves 16 hand-written JSON-input commands onto that projection:

  • compare-wasm-interfaces
  • match-native-functions
  • compare-artifacts
  • inspect-analysis-view
  • the managed workflows: import-managed-reconstruction, verify-managed-native-boundaries and project-managed-application-graph
  • the application workflows: trace-application-feature, trace-javascript-semantics, compare-application-versions, compare-javascript-export-shapes and project-{android,apple,harmony}-application-graph
  • reconcile-javascript-runtime
  • capture-electron-scenario

Problem and expected behavior

Each JSON-input command hand-wrote the same pieces:

  • the positional argument and its contentSchema (or omitted it);
  • inline, file or stdin decoding;
  • caller-path resolution inside the document;
  • the operation name used for decoding failures.

These copies had drifted:

  • compare-wasm-interfaces and match-native-functions advertised a bare string in --schema, with no contentSchema. This is the [Bug] CLI --schema on JSON-input commands emits only the outer inputJson string wrapper #9195 class.
  • Eleven commands named the CLI command (project-managed-application-graph) when JSON decoding failed, but the contract operation (project_managed_application_graph) when the decoded input was refused.
  • Each command picked its contentSchema source by hand: the frame schema, the request schema or nothing.

Expected: one projection owns the argument, its advertised content, decoding and caller-path resolution. Every failure from one command names the same contract operation.

Change and scope

contractCliDescription.ts:

  • CliDocumentProjection and describeContractDocumentCommand.
  • The advertised content is the contract input's Evidence frame. getEvidenceInputContract(...).frameSchema leaves inline Evidence carriers to their owner, as before.
  • An optional omit declares fields the one-shot command does not admit. trace-application-feature uses it for the MCP-only view.
  • callerPaths lists property paths inside the document.
  • cliOptions declares CLI-only options such as --evidence-bundle.
  • Registration refuses omitting a required field, omitting from a union input, and an option keyed inputJson.
  • contractNamed accepts any named contract list.
  • Two misplaced doc comments from refactor(cli): project Apple bundle commands onto a declared session target #10656 are corrected (flatten and CliSessionTarget).

contractCommand.ts: registerContractDocumentCommand renders the projection as an Incur inputJson argument with contentMediaType/contentSchema. Under the shared command cancellation, it then does the following:

  • decodes with parseCliJsonInput, using the contract name as the operation;
  • resolves the declared caller paths;
  • passes the handler the resolved document and the document as decoded (spelled).

The decoded document is still admitted by each command's owning service (its frame or request parser), as before.

Commands:

  • managedProjectGraphCommand.ts is deleted. The three managed workflows are one table in managedCommands.ts.
  • registerEvidenceJsonCommand in applicationCommands.ts now delegates to the projection and binds each command to its contract by name. The hand-built document schema constants are removed.
  • Error labels after decoding are unchanged (Application workflow failed, Electron analysis failed, and the unlabeled managed results).

Parity guard (cliContractCommandParity.test.ts):

  • The guard lists the 16 document commands.
  • Each takes exactly one inputJson argument, whose contentSchema is its described content.
  • Every contract field reaches the document unless it is omitted with a reason.
  • Options are exactly the declared CLI-only options.
  • Each caller path names a string property in the contract input.
  • The registration refusals above are covered.

Not included (next slices):

  • The remaining JSON-input commands. compare-source-to-bundle, compare-static-and-observed-endpoints, capture-browser-scenario and validate-browser-scenario use CLI-specific document schemas or delivery options. build-reconstruction-obligation-ledger and evaluate-reconstruction-coverage advertise a schema that differs from their contract frame. inspect-evidence-bundle has no contract. observe-native-calls is a session target plus a document.
  • Recording caller path spellings from inside documents in Evidence (W1 item 7).

Contribution scope: not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the CLI argv projection. Per-command decoding and argument construction are removed for these 16 commands.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract:
    • MCP: unchanged.
    • --schema: identical for 14 commands. For compare-wasm-interfaces and match-native-functions, the positional is now inputJson, as on the other JSON commands. It now advertises contentMediaType: application/json and its contract's contentSchema.
    • Help: identical except those two commands' positional name (<input> became <inputJson>). Positional names do not appear in argv, so invocations are unchanged.
    • Intended behavior change: a JSON decoding failure now names the contract operation, matching the same command's later input refusals. This applies to inline JSON that is not JSON, and to a missing or unreadable file. It affects the 11 commands that previously named the CLI command: inspect-analysis-view, the 7 application workflows and the 3 managed workflows. The fields affected are details.operation, recovery.operation and the remediation text.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged.
  • Target selection, authority, upstream behavior, and cleanup details: the same services, resource scopes and finishAnalysisCommand cleanup run in the same order.
  • Generated metadata, package, or installation impact: none (npm run docs:check passes).

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

(No effect changes.)

Evidence and regression coverage

User-visible CLI output was captured through createCli().serve before and after the change. The capture covered --schema --format json and --help for all 16 commands, plus 107 argv runs:

  • missing argument, {bad, {}, [], a missing relative file, and an unknown field, for each command;
  • relative evidence-file paths in compare-artifacts and inspect-analysis-view;
  • a relative --evidence-bundle;
  • retained references without a bundle;
  • trace-application-feature with the omitted view;
  • match-native-functions summary without --evidence_output, and with a relative --source_bundle;
  • capture-electron-scenario with relative executable and application paths.

Results:

  • 79 of 107 runs are byte-identical, including every caller-path resolution and every post-decoding refusal.
  • The other 28 differ only as described above:
    • 26 are decoding failures naming the contract operation.
    • 2 are the missing-argument message naming inputJson instead of input.
  • --schema and help are identical except for compare-wasm-interfaces and match-native-functions.

Tests updated for the intended operation name:

  • jsonInputStatus.test.ts (10 commands plus the file and overlong cases)
  • analysisViewCli.test.ts
  • cliJsonInput.test.ts (permission denial)

Remaining proof gaps: none known for this slice.

Validation performed

  • npm run check:fast: passed.
  • npm run knip: no findings.
  • npm run docs:check: passed.
  • npm run test:focused -- tests/boundary/cli/cliContractCommandParity.test.ts: 275 passed.
  • npm run test:focused -- with 21 JSON-input, caller-path, electron, analysis-view, managed, WASM-comparison, native-matching, application-workflow, session-parity and finalization-cancellation test files:
    • First run: 3 files failed on the operation-name expectations above (14 tests).
    • After updating those expectations, the 3 files passed (106 tests).
    • The other 18 files passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none for argv. Scripts that match the CLI command name in details.operation of a JSON decoding failure would now see the contract operation.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no change in authority or side effects.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T10:10:44.137564Z 2dd9aec New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge; no blocking issue remains.

Summary

Moves 16 JSON-document commands onto one contract-based description and registration path.

  • JSON-document commands now take their input shape from a named contract.
  • Application and evidence-view commands use contract-shaped JSON documents.
  • Managed and Electron workflows use contract-shaped JSON documents.
  • WASM and native-matching commands advertise their JSON input shapes.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Named contract and CLI choices] --> B[Document description]
  B --> C[Advertised argument schema]
  B --> D[Shared command registration]
  D --> E[Decode inline JSON, file, or stdin]
  E --> F[Resolve declared caller paths]
  F --> G[Owning service checks input]
  G --> H[Run workflow and await cleanup]
  H --> I[Return result or error]
Loading

Reviews (2) · Last reviewed commit: "test(cli): include WASM interface and na..." · Reviewed by Greptile

@morluto
morluto force-pushed the refactor/cli-contract-session-target branch from bca9646 to 7092a1f Compare November 14, 2026 20:33
@morluto
morluto force-pushed the refactor/cli-contract-json-document branch from e0d0dfd to 4f61b76 Compare November 14, 2026 20:33
@morluto
morluto force-pushed the refactor/cli-contract-session-target branch from 7092a1f to e21b171 Compare November 15, 2026 01:45
@morluto
morluto force-pushed the refactor/cli-contract-json-document branch from e267296 to 1fd7db5 Compare November 15, 2026 01:45
@morluto
morluto force-pushed the refactor/cli-contract-session-target branch from e21b171 to d85f894 Compare November 15, 2026 05:58
@morluto
morluto force-pushed the refactor/cli-contract-json-document branch from 1fd7db5 to dcc1991 Compare November 15, 2026 05:58
@morluto
morluto force-pushed the refactor/cli-contract-session-target branch from d85f894 to af4cad5 Compare November 15, 2026 07:34
@morluto
morluto force-pushed the refactor/cli-contract-json-document branch from dcc1991 to 46f4815 Compare November 15, 2026 07:34
@morluto
morluto force-pushed the refactor/cli-contract-session-target branch from af4cad5 to edbf64e Compare November 15, 2026 09:34
@morluto
morluto force-pushed the refactor/cli-contract-json-document branch from 46f4815 to 85df160 Compare November 15, 2026 09:37
Base automatically changed from refactor/cli-contract-session-target to refactor/cli-contract-path-lists-flattened November 15, 2026 09:39
@morluto
morluto changed the base branch from refactor/cli-contract-path-lists-flattened to main November 15, 2026 09:45
@morluto
morluto force-pushed the refactor/cli-contract-json-document branch from 85df160 to 2dd9aec Compare November 15, 2026 10:08
@morluto
morluto merged commit fc6a960 into main Nov 15, 2026
6 checks passed
@morluto
morluto deleted the refactor/cli-contract-json-document branch November 15, 2026 10:25
@morluto morluto added the area: cli CLI adapter and one-shot commands label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant