Skip to content

refactor(cli): project reconstruction and source-to-bundle documents from their contracts - #10697

Merged
morluto merged 6 commits into
mainfrom
refactor/cli-contract-reconstruction-documents
Nov 15, 2026
Merged

morluto merged 6 commits into
mainfrom
refactor/cli-contract-reconstruction-documents

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Next slice of plan W1, stacked on #10668 (base refactor/cli-contract-json-document; retarget as the lower PRs merge). Refs #10583.

Three more JSON-document commands are derived from their MCP contracts: build-reconstruction-obligation-ledger, evaluate-reconstruction-coverage and compare-source-to-bundle. Two fixes to the shared document projection come with them:

  • A document field the projection omits is now refused with its reason.
  • Caller-path fields are advertised in --schema as the CLI admits them.

Problem and expected behavior

  • Ledger and coverage used a private registerJsonCommand. It parsed with z.unknown() and advertised a separate documentSchema. That request envelope replaced the Evidence bundle (ledger) or the whole coverage document with {}, so the CLI's --schema showed less than the contract and accepted documents the command then refused.
  • compare-source-to-bundle parsed with its own compareSourceToBundleCliInputSchema, a copy of the contract with a relative-path file reference and without view. The service took the schema as a parameter to support both.
  • registerContractDocumentCommand (refactor(cli): project JSON-document workflow commands from their contracts #10668) records omit reasons but did not enforce them. An omitted field passed through to an owner that might accept it. For trace-application-feature the owner refused it with a generic strict-key error. For compare-source-to-bundle on the contract schema, the owner would silently ignore view.
  • Each callerPaths field in a document is resolved against the working directory before admission. But --schema advertised the contract's absolute-path pattern (^/), so a relative path the command accepts looked invalid. This already affected inspect-analysis-view (source.path), compare-artifacts (left/right.path) and capture-electron-scenario (executable_path, application_path, application_root).

Change and scope

  • applicationCommands.ts: ledger and coverage use registerContractDocumentCommand with their contracts. registerJsonCommand and its documentSchema override are deleted. Each service still parses its own envelope and reads the bundle itself. --schema now advertises the contract input, as MCP does.
  • compare-source-to-bundle:
    • Projected from compare_source_to_bundle, with callerPaths: [["reference","path"]] and view omitted with a reason.
    • compareSourceToBundleCliInputSchema is deleted. executeSourceToBundleComparison always parses with the contract schema; MCP no longer passes it.
    • The caller's spelling still reaches Evidence: the handler passes the as-typed reference.path as requestedReferencePath, so reference_source.requested_path stays the relative spelling.
  • contractCommand.ts: omittedDocumentFieldError refuses an omitted top-level field with <field> is not accepted by this command: <reason>.
  • contractCliDescription.ts: admitDocumentCallerPath rewrites each caller-path leaf of the advertised document to cliJsonCallerPathSchema, through unions and wrappers. Clones keep their parent's registry metadata.
  • cliJsonInput.ts: owns the CLI's URL rule (fix(cli): file URLs become invented local paths in Electron requests #2577) once. URL_REFERENCE_SOURCE feeds both the resolver and cliJsonCallerPathSchema. That schema is a local path that is not a file:/scheme:// URL, spelled case-insensitively, so --schema advertises exactly what the CLI resolves. A file literally named file:ref.json is selected as ./file:ref.json, as for the other document commands.
  • The error operation for these three commands is now the contract operation (compare_source_to_bundle), not the command name, matching the other projected commands.
  • Not included, left for later W1 slices:
    • compare-static-and-observed-endpoints and capture-browser-scenario. They take contract fields (detail, view) as CLI flags next to the document, which the document projection cannot express yet.
    • validate-browser-scenario and observe-native-calls.
  • Contribution scope: not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage:
    • The contract-document projection owns the advertised document and omissions.
    • The source-to-bundle service owns admission with one schema.
    • Removed: registerJsonCommand, documentSchema and compareSourceToBundleCliInputSchema.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract:
    • MCP: unchanged.
    • CLI --schema:
      • Ledger and coverage now show the full contract input, including the Evidence bundle and coverage document, instead of {}.
      • Caller-path fields of the five document commands above accept any nonempty local path.
      • compare-source-to-bundle is otherwise unchanged.
    • CLI refusals: an omitted view is refused with its reason. Input-error details.operation uses the contract operation for the three migrated commands.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged. reference_source.requested_path still keeps the caller's spelling (covered by applicationWorkflowCli.test.ts).
  • Target selection, authority, upstream behavior, and cleanup details: unchanged.
  • Generated metadata, package, or installation impact: none.

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

  • Tests added or updated:
    • jsonInputSchema.test.ts:
      • Ledger and coverage now expect their contract inputs.
      • The representative-document test accepts a structurally complete coverage document. It rejects an arbitrary coverage and a malformed embedded bundle.
      • Caller-path fields are expected with the CLI's local-path admission, through a JSON-level oracle (admitRelativePath).
    • jsonInputStatus.test.ts:
      • New cases check that compare-source-to-bundle and trace-application-feature refuse an omitted view with its reason.
      • A new case checks that file:ref.json is refused at ["reference","path"].
      • Operation names are updated.
    • jsonInputSchema.test.ts also checks that the advertised caller path accepts ref.json, ./file:ref.json and C:\ref.json, and rejects file:, FILE: and https:// spellings.
    • cliContractCommandParity.test.ts: lists the two new document commands.
  • Base reproduction:
    • The omission tests fail without the contractCommand.ts change (2 failed).
    • The caller-path schema test failed before admitDocumentCallerPath. It showed allOf: [{pattern:"^[^\\x00]*$"},{pattern:"^\\/"}] for inspect-analysis-view, compare-artifacts, capture-electron-scenario and compare-source-to-bundle.
  • User-visible CLI output (node scripts/rea.mjs compare-source-to-bundle '{"reference":{"kind":"file","path":"ref.json"},"application":{},"view":{"kind":"summary"}}' --json):
    {"code":"invalid_request","category":"invalid_input",...,"details":{"operation":"compare_source_to_bundle","issues":[{"path":["view"],"reason":"invalid_value","message":"view is not accepted by this command: A one-shot command retains no session Evidence for a selected view; save the complete comparison and query it with inspect-analysis-view"}]}}
    
  • Remaining proof gaps: none known for these commands. No real-provider workflow is involved.

Validation performed

  • npm run typecheck: passed.
  • npm run lint: 0 errors.
  • npm run verify:module-boundaries: passed.
  • npm run test:focused -- tests/boundary/cli/jsonInputSchema.test.ts tests/boundary/cli/jsonInputStatus.test.ts tests/boundary/cli/cliContractCommandParity.test.ts tests/boundary/cli/analysisViewCli.test.ts tests/boundary/cli/artifactComparisonSources.test.ts tests/boundary/cli/electronCli.test.ts: passed (357 tests in the last combined run).
  • npm run test:focused -- tests/boundary/filesystem/sourceToBundlePaths.test.ts tests/boundary/mcp/sourceToBundleViewsMcp.test.ts tests/acceptance/applications/applicationWorkflowCli.test.ts: passed. These ran together with the schema, status and parity tests (429 passed). The one status failure in that run was the expected operation-name change, fixed and rerun.
  • npm run test:focused -- tests/process-global/sourceToBundleReferenceGuards.test.ts tests/boundary/cli/reconstructionCoverageCli.test.ts tests/boundary/cli/reconstructionObligationLedgerCli.test.ts tests/boundary/cli/inlineEvidenceBundleKind.test.ts: 38 passed.
  • After the URL-rule commit: npm run test:focused -- tests/boundary/cli/jsonInputSchema.test.ts src/cliJsonPaths.test.ts and npm run test:focused -- tests/boundary/cli/jsonInputStatus.test.ts tests/boundary/cli/cliContractCommandParity.test.ts: all passed.
  • Pushed with --no-verify; typecheck and lint were run manually as above.
  • After refactor(cli): project JSON-document workflow commands from their contracts #10668 merged: rebased onto main (dropping refactor(cli): project JSON-document workflow commands from their contracts #10668's commits). The merge gate (briefs/local-gate.sh) failed check:fast on the provider-failure-classifier lint for omittedDocumentFieldError(…, document: unknown); it now takes an object and the caller narrows (the shape later stack PRs already use). npm run test:focused -- tests/boundary/cli/jsonInputSchema.test.ts failed because main now requires evidence_format: 1 in Evidence bundles; the coverage fixture now carries it, and 43 tests in jsonInputSchema/jsonInputStatus pass. briefs/local-gate.sh 10697 refactor/cli-contract-reconstruction-documents: passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none intended.
    • compare-source-to-bundle already refused view (strict schema); it now names the reason.
    • Input-error details.operation for the three commands changes from the command name to the operation name, as for the other projected commands.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new inputs or 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 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T11:26:38.130277Z
We couldn’t complete this review. Comment @codex review to try again.
ea14e78 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 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge, with one non-blocking mismatch in the advertised path schema.

Fix All in CodexFindings

  1. P2 Blank paths pass schema checks ▶
Fix with agent prompt
### Issue 1
src/cliJsonInput.ts:276-279
`cliJsonCallerPathSchema` accepts whitespace-only paths such as `" "` and `"\t"`. But `resolveJsonPath` leaves them unchanged, and the contract rejects them because they are not absolute paths. A document can therefore pass the new `--schema` check and still fail at `reference.path`; the other projected caller paths have the same mismatch.

Reject whitespace-only strings in the advertised schema without trimming valid filenames.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Moves reconstruction ledger, coverage, and source-to-bundle commands onto their named contracts.

  • Reconstruction commands now advertise their full contract inputs.
  • Source-to-bundle comparisons now follow the shared CLI contract.
  • CLI schemas now show local paths the commands resolve.
  • CLI documents refuse fields their command does not accept.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["CLI JSON document"] --> B["Decode document"]
  B --> C{"Omitted field supplied?"}
  C -- Yes --> D["Return field-specific refusal"]
  C -- No --> E["Resolve declared caller paths"]
  E --> F["Existing workflow owner"]
  G["Named contract"] --> H["Project document schema"]
  H --> I["CLI --schema"]
  G --> F
  F --> J["Authenticate inputs and return result"]
Loading

Reviews (3) · Last reviewed commit: "test(cli): give the coverage document fi..." · Reviewed by Greptile

Comment thread src/cli/sourceToBundleCommand.ts Resolved
@morluto
morluto force-pushed the refactor/cli-contract-reconstruction-documents branch from c61fa6d to afb76d7 Compare November 15, 2026 01:45
@morluto
morluto force-pushed the refactor/cli-contract-json-document branch 2 times, most recently from 1fd7db5 to dcc1991 Compare November 15, 2026 05:58
@morluto
morluto force-pushed the refactor/cli-contract-reconstruction-documents branch from afb76d7 to 63990e9 Compare November 15, 2026 05:58
@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-reconstruction-documents branch 2 times, most recently from fb146a1 to cdb44f0 Compare November 15, 2026 09:37
@morluto
morluto force-pushed the refactor/cli-contract-json-document branch from 46f4815 to 85df160 Compare November 15, 2026 09:37
@morluto
morluto force-pushed the refactor/cli-contract-reconstruction-documents branch from cdb44f0 to dfd85dd Compare November 15, 2026 10:08
@morluto
morluto force-pushed the refactor/cli-contract-json-document branch from 85df160 to 2dd9aec Compare November 15, 2026 10:08
@morluto
morluto changed the base branch from refactor/cli-contract-json-document to main November 15, 2026 10:25
@morluto
morluto force-pushed the refactor/cli-contract-reconstruction-documents branch from dfd85dd to 4fe7fd8 Compare November 15, 2026 11:18
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Comment thread src/cliJsonInput.ts
Comment on lines +276 to +279
export const cliJsonCallerPathSchema = localPathStringSchema.regex(
new RegExp(`^(?!${URL_REFERENCE_SOURCE})`, "u"),
"must be a local path, not a URL",
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Blank paths pass schema checks

cliJsonCallerPathSchema accepts whitespace-only paths such as " " and "\t". But resolveJsonPath leaves them unchanged, and the contract rejects them because they are not absolute paths. A document can therefore pass the new --schema check and still fail at reference.path; the other projected caller paths have the same mismatch.

Reject whitespace-only strings in the advertised schema without trimming valid filenames.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cliJsonInput.ts
Line: 276-279

Comment:
**Blank paths pass schema checks**

`cliJsonCallerPathSchema` accepts whitespace-only paths such as `" "` and `"\t"`. But `resolveJsonPath` leaves them unchanged, and the contract rejects them because they are not absolute paths. A document can therefore pass the new `--schema` check and still fail at `reference.path`; the other projected caller paths have the same mismatch.

Reject whitespace-only strings in the advertised schema without trimming valid filenames.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex

@morluto
morluto merged commit 9be6a96 into main Nov 15, 2026
7 of 9 checks passed
@morluto
morluto deleted the refactor/cli-contract-reconstruction-documents branch November 15, 2026 11:40
@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