Skip to content

refactor(cli): project inspect-artifact and extract-artifact with open_binary target options - #10722

Merged
morluto merged 3 commits into
refactor/cli-contract-native-call-documentfrom
refactor/cli-contract-artifact-target-open
Nov 15, 2026
Merged

morluto merged 3 commits into
refactor/cli-contract-native-call-documentfrom
refactor/cli-contract-artifact-target-open

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

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

A declared session target can now take fields of the contract an MCP client opens the target with (open_binary) as options. inspect-artifact and extract-artifact are derived from their contracts with open_binary's format and ESP flash fields. This is the sessionTarget.open extension designed in #10656.

Problem and expected behavior

inspect-artifact and extract-artifact were hand-written:

  • They re-declared every contract field as an option, including a private copy of the --artifact-limits JSON parser (producerLimitsOption).
  • --target-format, --flash-offset and --partition-table-offset were hand-written options. A private mapping (espFlashTargetSelection) duplicated the one the MCP open_binary handler held.
  • An unpaired --flash-offset was refused only after the target was opened, by the target resolver.
  • extract-artifact ran without the command's cancellation signal.

Expected behavior: the same arguments, options, defaults and help. The opening options are admitted by open_binary's own input schema before the target is opened.

Change and scope

  • contractCliDescription.ts:
    • CliSessionTarget.open names the opening contract and the fields taken as options. Each field keeps its own schema. A field projection may give values to narrow an enum; registration checks that the contract admits each value.
    • A shared describeSessionTarget now builds the target for both flag and document commands.
    • admitOpening admits the selected fields with the opening contract, with the target as its path. Issues name CLI keys.
    • Opening option keys take part in the CLI-key collision check.
  • contractCommand.ts:
    • Both adapters render the opening options and admit them before the handler runs. The context carries opening.
    • runOnSessionTarget passes the opening selection to runProviderAnalysis and, for evidenceDelivery, publishes complete Evidence or a summary.
  • sessionLifecycleInputs.ts: new openBinaryTargetSelection, the one mapping from open_binary fields to the target selection. registerSessionTools.ts (MCP open_binary) uses it instead of its inline copy.
  • artifactCommands.ts:
    • The two commands are registered from inspect_artifact and extract_artifact.
    • --target-format admits only esp-flash-image, as before.
    • extract-artifact still fills an omitted output_root with createArtifactExtractionDestination.
  • sessionToolContracts.ts: open_binary is exported as OPEN_BINARY_TOOL_CONTRACT and listed first in SESSION_TOOL_CONTRACTS, as before. artifactCommands.ts reads it there. Reading it through toolContract from toolContracts.ts loaded the complete tool catalog when the CLI registered its commands, which tests/boundary/cli/cliStartupImports.test.ts refuses.
  • .oxlintrc.json: src/cli*.ts and src/cli/** may not import contracts/toolContracts.js except as a type. Stacked PRs get no CI run (CI runs only for PRs into main or release/*), and the startup test needs a build, so the regression was not caught before. The lint rule runs in the pre-push check:fast.
  • producerLimitsOption.ts: the unused producerLimitsOption is removed (jsonText replaces it); the help constant stays.
  • Not included:
    • output_root stays absolute-only on the CLI, as before. Admitting caller-relative paths waits for test(cli): report CLI fields that admit values their contract refuses #10575 (W1 item 5).
    • Recording the target's spelling in inspect-artifact Evidence (W1 step 7).
    • The core binary, core native, utility and managed families, which need a runDirectAnalysis runner with provider, architecture, entry point and snapshot options.
  • Contribution scope: not applicable. Target selection and authority are unchanged.

Contract and boundary impact

  • Semantic owner and earliest changed stage:
    • The CLI argv projection now owns opening options.
    • openBinaryTargetSelection owns the field-to-selection mapping for MCP and CLI.
    • Removed: the CLI and MCP copies of that mapping, two hand-written commands and the CLI limits parser.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract:
    • MCP: unchanged.
    • CLI help for extract-artifact lists the same options, descriptions and defaults; --output-root now shows the contract's description.
    • Refusals: an unpaired --flash-offset or --partition-table-offset is now refused as invalid_request with issue path flashOffset / partitionTableOffset, before the target is opened. The message is the same espFlashSelectionError text.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged.
  • Target selection, authority, upstream behavior, and cleanup details:
    • extract-artifact now runs under withCommandCancellation, and the analysis receives the command's signal.
    • Otherwise unchanged.

Expected effects (unchanged from the existing commands; left for the human owner to check: reads the artifact, and extract-artifact writes files to its destination):

  • 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.

(extract-artifact writes the selected files to its destination, as before.)

Evidence and regression coverage

  • Tests added or updated (cliContractCommandParity.test.ts):
    • Rendered options include the opening options.
    • For every command with opening options:
      • Opening values stay out of the contract input.
      • admitOpening returns them in contract spelling.
      • An unpaired flash offset is refused naming flashOffset.
      • --target-format admits only esp-flash-image.
    • A projection that names a missing, required or path opening field, or narrows to a value the contract refuses, throws.
  • Unchanged and passing:
    • espFlashImageCli.test.ts: unpaired refusal message, automatic guess, caller-selected offset.
    • espFlashImageMcp.test.ts, rawBinaryMcp.test.ts, gamecubeDolSessionMcp.test.ts, artifactMcp.test.ts: the MCP open_binary mapping.
    • Artifact CLI tests for limits, integrity policy, extraction coverage, current-directory targets and caller selection.
  • Manual smoke run against the built CLI, on a two-file zip in a temporary directory:
    • extract-artifact t.zip --output-root <abs>: extracted a.txt.
    • extract-artifact t.zip --flash-offset 0x1000: invalid_request at flashOffset.
    • inspect-artifact t.zip --detail summary: invalid_request, summary needs --evidence_output.
  • Remaining proof gaps: cancellation of extract-artifact during extraction is not exercised by a new test.

Validation performed

  • npm run test:focused -- tests/boundary/cli/cliContractCommandParity.test.ts tests/acceptance/espFlashImageCli.test.ts: 306 passed.
  • npm run test:focused -- 17 artifact and ESP files (espFlashImageMcp, artifactReaderLimitsCli, artifactArmSlicesCli, emptyLocalTargetAdmission, emptyArtifactBundleTargetCli, javascriptIntegrityPolicyCli, artifactZipCurrentDirectory, artifactCallerSelection, cliOutput, analysisViewCli, artifactZipIntegrity, espImageCli, godotPck, nodeSeaCli, unityFsCli, artifactZstandardWindow, artifactExtractionCoverage): 233 passed, 2 skipped.
  • npm run test:focused -- tests/boundary/mcp/rawBinaryMcp.test.ts tests/boundary/mcp/gamecubeDolSessionMcp.test.ts tests/boundary/mcp/artifactMcp.test.ts: 26 passed, 2 skipped.
  • npm run check:fast: passed.
  • After the startup-import fix: npm run test:focused -- tests/boundary/cli/cliStartupImports.test.ts: 6 passed; with the old artifactCommands.ts it fails ("does not load command-specific code to register the command catalog"). npx oxlint reports the old import as no-restricted-imports and admits a type-only import. npm run check:fast: passed.
  • npm run knip: no findings, after removing producerLimitsOption.
  • npm run docs:check: passed.
  • node scripts/rea.mjs extract-artifact --help and the smoke runs above: as described.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Only the timing and issue path of the unpaired-flash refusal change.
  • Real Hopper/Ghidra, browser, or OS coverage: macOS only, via the tests above.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no change in authority or side effects. Extraction keeps its destination checks.

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:39.039637Z
We couldn’t complete this review. Comment @codex review to try again.
4ea8804 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] This PR appears safe to merge; no actionable issue was found.

Summary

Moves inspect-artifact and extract-artifact onto shared contract-based registration.

  • Artifact CLI commands take their inputs from contracts and their opening options from open_binary.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["CLI artifact options"] --> B["Check opening contract"]
  B --> C["Shared selection mapping"]
  D["MCP open_binary input"] --> C
  C -->|CLI| E["runProviderAnalysis"]
  C -->|MCP| F["session.open"]
  E --> G["Inspect or extract"]
  G --> H["Deliver Evidence"]
Loading

Reviews (1) · Last reviewed commit: "refactor(cli): project inspect-artifact ..." · Reviewed by Greptile

@morluto
morluto force-pushed the refactor/cli-contract-artifact-target-open branch from ee0ea16 to 6129b8e Compare November 15, 2026 01:14
@morluto
morluto force-pushed the refactor/cli-contract-document-delivery branch from ce4fa7c to abd18b3 Compare November 15, 2026 01:45
@morluto
morluto force-pushed the refactor/cli-contract-artifact-target-open branch from 6129b8e to 5310117 Compare November 15, 2026 01:45
@morluto
morluto force-pushed the refactor/cli-contract-document-delivery branch from abd18b3 to 05ed54d Compare November 15, 2026 05:58
@morluto
morluto force-pushed the refactor/cli-contract-artifact-target-open branch from 5310117 to 589c9f3 Compare November 15, 2026 05:58
Base automatically changed from refactor/cli-contract-document-delivery to refactor/cli-contract-native-call-document November 15, 2026 07:11
@morluto
morluto force-pushed the refactor/cli-contract-native-call-document branch from e6f1711 to 0e105c7 Compare November 15, 2026 07:34
@morluto
morluto force-pushed the refactor/cli-contract-artifact-target-open branch from 589c9f3 to f766b78 Compare November 15, 2026 07:35
@morluto
morluto force-pushed the refactor/cli-contract-native-call-document branch from 0e105c7 to bd32c3d Compare November 15, 2026 09:37
@morluto
morluto force-pushed the refactor/cli-contract-artifact-target-open branch 2 times, most recently from 519cfcf to 4255498 Compare November 15, 2026 10:08
@morluto
morluto force-pushed the refactor/cli-contract-native-call-document branch 2 times, most recently from 00fc8a2 to eefe85d Compare November 15, 2026 11:18
@morluto
morluto force-pushed the refactor/cli-contract-artifact-target-open branch from 4255498 to d6b961c 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.

…n_binary target options

A declared session target can now take fields of the contract an MCP
client opens the target with as options. They are admitted by that
contract, with the target as its path, before the target is opened, and
the projection can narrow an enum to the values the command supports.

inspect-artifact and extract-artifact are derived from their contracts
with open_binary's format and ESP flash fields. MCP open_binary and the
CLI share one mapping from those fields to the target selection.
extract-artifact now runs under the command's cancellation signal.
@morluto
morluto force-pushed the refactor/cli-contract-native-call-document branch from eefe85d to 58a3b8b Compare November 15, 2026 11:26
@morluto
morluto force-pushed the refactor/cli-contract-artifact-target-open branch from d6b961c to 4ea8804 Compare November 15, 2026 11:26
@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.

@morluto
morluto merged commit 6047cc5 into refactor/cli-contract-native-call-document Nov 15, 2026
@morluto
morluto deleted the refactor/cli-contract-artifact-target-open branch November 15, 2026 11:51
morluto added a commit that referenced this pull request Nov 15, 2026
… its contract document (#10700)

* refactor(cli): project observe-native-calls onto a session target and its contract document

* refactor(cli): project endpoint comparison and browser scenario documents with delivery options (#10711)

* refactor(cli): carry document command delivery as options and project endpoint and browser scenario commands

A JSON-document projection can now take the contract's detail and view
fields as --detail, --evidence_output and --view beside the document.
The document refuses those fields with the option to use, and the
delivery is admitted by the contract's own view schema before the
document is read.

compare-static-and-observed-endpoints, capture-browser-scenario and
validate-browser-scenario now register from their contracts; validation
projects the capture contract without detail.

* fix(cli): admit the endpoint comparison document before reading its Evidence bundle

The document command context carries the document's transport frame, so
a handler that reads an Evidence bundle first can refuse a malformed
document beforehand, as the hand-written command did.

* refactor(cli): pass only object documents to the document field refusal

* refactor(cli): project inspect-artifact and extract-artifact with open_binary target options (#10722)

* refactor(cli): project inspect-artifact and extract-artifact with open_binary target options

A declared session target can now take fields of the contract an MCP
client opens the target with as options. They are admitted by that
contract, with the target as its path, before the target is opened, and
the projection can narrow an enum to the values the command supports.

inspect-artifact and extract-artifact are derived from their contracts
with open_binary's format and ESP flash fields. MCP open_binary and the
CLI share one mapping from those fields to the target selection.
extract-artifact now runs under the command's cancellation signal.

* fix(cli): read open_binary from its session contract so startup stays lazy

* build(lint): refuse value imports of the complete tool catalog in CLI startup modules
@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