Skip to content

refactor(cli): project WASM inspection and firmware commands from their contracts - #10648

Merged
morluto merged 2 commits into
mainfrom
refactor/cli-contract-path-lists-flattened
Nov 15, 2026
Merged

morluto merged 2 commits into
mainfrom
refactor/cli-contract-path-lists-flattened

Conversation

@morluto

@morluto morluto commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Ninth slice of plan W1, stacked on #10635 (base refactor/cli-contract-option-effects, which now includes #10643; retarget as the lower PRs merge). Refs #10583.

The contract command description gains two features, and three commands are derived from their contracts with them:

  • Lists of caller paths: inspect-wasm-artifact --glue_paths/--candidate_paths.
  • Optional object fields flattened into one option per member: extract-firmware --offset/--length for range.

inspect-firmware-regions is migrated too. extract-firmware now records the caller's output_directory spelling in Evidence, as every other caller-path field does (see below).

Problem and expected behavior

  • WASM re-declared seven fields, mapped each with a conditional spread, resolved both path lists by hand, and assembled caller_input_paths itself.
  • Firmware re-declared every extraction limit, built range from two options, and passed only path as a caller spelling. output_directory is also caller-selected, but its spelling was dropped.

This is the sibling of #10606 (--join-path). The derived commands must keep their flags, help, --schema, refusals (including the missing-companion range refusal from firmwareIncompleteRange) and service input.

Change and scope

  • contractCliDescription.ts:
    • callerPaths also takes array fields. Each element is admitted as a nonempty, NUL-free local path and resolved. callerInputs returns CallerInputPaths, so lists keep their spelled order.
    • flatten: an optional object field taken as one option per member. Every member must be projected. Any member given supplies the whole object, absent members included, so the contract still names the missing companion.
  • contractCommand.ts: callerTargetPath(context) returns the spelled target path. The two binary-diagnostics handlers that read callerInputs.path use it now that caller inputs may be lists.
  • inspect-wasm-artifact: path, glue_paths and candidate_paths are caller paths. detail is omitted with a reason, as before; the contract has a detail field the hand-written command never exposed.
  • Firmware: both commands share one FirmwareAnalysisService through inspectWithService. extract-firmware takes path and output_directory as caller-path positionals and flattens range.
  • Parity guard:
    • Covers the three commands.
    • Caller-path lists are admitted exactly as the resolved contract field admits them.
    • Flattened members are compared with their member schema, and the whole object is supplied when any member is given.
    • Partial or non-object flattening is refused at registration.
  • cliInputSchemaRequired: the derived option admits an explicit undefined, as every projected command does, because argv cannot carry one. The assertion now checks what argv can do: an omitted --command-timeout-ms is absent from the parsed options, so the contract default applies.
  • Not included: compare-wasm-interfaces. It is a JSON-input command (inline JSON or a file, plus --evidence-bundle). It belongs with the other 17 JSON-input commands, which need one shared JSON-input projection; that projection would also add the contract's contentSchema to its --schema ([Bug] CLI --schema on JSON-input commands emits only the outer inputJson string wrapper #9195).
  • Contribution scope: not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the CLI argv projection. Per-command spreads, list resolution and caller-path assembly are removed.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract:
    • MCP: unchanged.
    • CLI --schema: semantically identical for all three commands.
    • Help: only line order changes.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: extract-firmware Evidence gains caller_input_paths.output_directory, keyed by contract field. WASM and inspect-firmware-regions Evidence are unchanged.
  • 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: the parity guard covers 37 projected commands, plus the list and flattening checks above.
  • User-visible CLI output: captured --schema --format json, --help and 23 argv runs before and after through createCli().serve.
    • The runs cover empty and NUL list elements, repeated relative list paths, non-decimal and out-of-range limits, missing positionals, each lone range member, a zero length, a non-decimal offset, an over-limit depth, empty paths, and runs on a small fixture.
    • --schema: semantically equal for all three commands.
    • Help: order-only differences.
    • All 23 argv outputs and exit statuses: byte-identical.
  • Service input and Evidence: WABT, binwalk and unblob are unavailable on this macOS host. A script replaced the WASM service and FirmwareAnalysisService.execute with recorders returning Evidence, then ran six argv lines.
    • Service inputs: identical values; only key order differs.
    • WASM caller_input_paths: identical ({"glue_paths":["rel/a.js","/abs/b.js"],"candidate_paths":["./c.wasm"]}).
    • extract-firmware: now adds caller_input_paths: {"output_directory": "rel/out"}.
  • Base reproduction: not rerun for this slice. The registration check names the three commands, which the hand-written commands do not register through the description.
  • Remaining proof gaps: no real WABT or firmware-engine run on this host. The output_directory recording is shown only through the recording script and the guard's callerInputs check.

Validation performed

  • npm run check:fast: passed.
  • npm run knip: no findings.
  • npm run test:focused -- tests/boundary/cli/cliContractCommandParity.test.ts: 225 passed.
  • npm run test:focused -- wasmAcquiredInputsCli, wasmCleanupCli, cliInputSchemaRequired, artifactInputLimits, cliDecimalArguments, firmwareIncompleteRange, nonBinaryComposition, localPathAdmissionCli, binaryDiagnosticsCliCleanup, commandFinalizationCancellation: cliInputSchemaRequired failed on the explicit-undefined assertion described above. After that change it passed (25 tests); the other nine files passed (72 passed, 2 skipped across the run).

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • 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-15T09:41:21.540718Z cb25d10 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 reviewed changes appear safe to merge, with no blocking issue found.

Summary

Moves WASM inspection, firmware commands, and four Apple commands onto shared contract-based CLI descriptions.

  • WASM inspection resolves selected paths through its contract.
  • Firmware extraction takes range flags and records its output folder.
  • Apple resource commands use a separate target path and contract inputs.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[CLI arguments] --> B[Contract-based command description]
  B --> C[Resolve caller paths and assemble input]
  C --> D{Command kind}
  D -->|WASM or firmware| E[Shared inspection service]
  D -->|Apple command| F[Open session target and run operation]
  E --> G[Finish cleanup]
  F --> G
  G --> H[Return Evidence or named input errors]
Loading

Reviews (2) · Last reviewed commit: "refactor(cli): project Apple bundle comm..." · Reviewed by Greptile

Base automatically changed from refactor/cli-contract-runtime-json-null-limits to refactor/cli-contract-option-effects November 14, 2026 20:02
@morluto
morluto force-pushed the refactor/cli-contract-path-lists-flattened branch from 5ae577b to 886a42d Compare November 14, 2026 20:10
@morluto
morluto force-pushed the refactor/cli-contract-option-effects branch from d9f8120 to 18d160e Compare November 14, 2026 20:33
@morluto
morluto force-pushed the refactor/cli-contract-path-lists-flattened branch 2 times, most recently from 15423d9 to 96f5467 Compare November 15, 2026 01:45
@morluto
morluto force-pushed the refactor/cli-contract-option-effects branch 2 times, most recently from eaeac7a to 4b81d9a Compare November 15, 2026 05:58
@morluto
morluto force-pushed the refactor/cli-contract-path-lists-flattened branch from 96f5467 to 70dd410 Compare November 15, 2026 05:58
@morluto
morluto force-pushed the refactor/cli-contract-option-effects branch from 4b81d9a to 90bd307 Compare November 15, 2026 07:34
@morluto
morluto force-pushed the refactor/cli-contract-path-lists-flattened branch from 70dd410 to 6d01705 Compare November 15, 2026 07:34
Base automatically changed from refactor/cli-contract-option-effects to fix/cli-apple-ips-join-path-spelling November 15, 2026 08:39
@morluto
morluto force-pushed the refactor/cli-contract-path-lists-flattened branch from 6d01705 to cc1f1b2 Compare November 15, 2026 08:48
@morluto
morluto changed the base branch from fix/cli-apple-ips-join-path-spelling to main November 15, 2026 09:04
…ir contracts

The contract command description gains lists of caller paths and optional object fields flattened into one option per member. inspect-wasm-artifact, inspect-firmware-regions and extract-firmware are derived from their contracts. extract-firmware now records the caller's output_directory spelling in Evidence, like every other caller-path field.
@morluto
morluto force-pushed the refactor/cli-contract-path-lists-flattened branch from cc1f1b2 to 1fbcfd3 Compare November 15, 2026 09:34
…target (#10656)

Session-scoped operations take their target from the MCP session, so the CLI's target positional is not a contract field. The contract command description declares a session target: the CLI takes it as the first positional, opens it through runProviderAnalysis as the hand-written commands did, and passes the rest of the contract input. Input issues reported after argv parsing name renamed fields by their CLI key. inspect-keyed-archive, trace-dylib-resolution, inspect-asset-catalog and decode-interface-builder are the pilot; trace-dylib-resolution --root now admits only the roots its contract admits.
@morluto
morluto merged commit a761efd into main Nov 15, 2026
7 checks passed
@morluto
morluto deleted the refactor/cli-contract-path-lists-flattened branch November 15, 2026 09:45
@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