Skip to content

refactor(cli): project Apple bundle commands onto a declared session target - #10656

Merged
morluto merged 1 commit into
refactor/cli-contract-path-lists-flattenedfrom
refactor/cli-contract-session-target
Nov 15, 2026
Merged

morluto merged 1 commit into
refactor/cli-contract-path-lists-flattenedfrom
refactor/cli-contract-session-target

Conversation

@morluto

@morluto morluto commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Summary

Tenth slice of plan W1, stacked on #10648 (base refactor/cli-contract-path-lists-flattened; retarget as the lower PRs merge). Refs #10583.

This PR designs a declared session-target projection and pilots it on the Apple bundle resource family: inspect-keyed-archive, trace-dylib-resolution, inspect-asset-catalog and decode-interface-builder.

Problem and expected behavior

About 45 CLI commands (source count of runProviderAnalysis and runDirectAnalysis registrations) run tools whose MCP contract takes the target from the session. These include the artifact, utility, core binary and core native families, plus managed commands. The CLI's positional path is therefore not a contract field. Every such command hand-writes all its options and its input mapping, so it cannot use the contract command description. Some of those options validate less than the contract; trace-dylib-resolution --root accepted any string.

Expected: the command is described from the contract, with the target declared as CLI-only. The CLI opens the target the same way the hand-written command did, then runs the operation with the rest of the contract input.

Design: declared session target

  • Projection: sessionTarget: { description } declares that the operation runs on a target an MCP session would hold open.
  • Argv: the target is the first positional, path. It is a nonempty, NUL-free local path, admitted like other caller paths, and is never a contract field. A contract field also keyed path must be renamed, or registration fails (keyed archive renames its relative path to archive, as before).
  • Description: sessionTarget carries the positional key and schema. parameters, toContractInput and callerInputs never see it, so the contract input is exactly the session operation's input.
  • Run: the handler context carries the target as spelled. runOnSessionTarget(runProviderAnalysis, logger) passes it to runProviderAnalysis, the path every hand-written artifact, utility and managed command uses, with the contract name, the contract input and the command's cancellation signal.
  • Input issues: the description derives inputBinding (contract field → CLI key for renamed fields). The runner gives it to projectCliAnalysisResult, so analysis-time input issues name the CLI key. This generalizes the keyed archive's hand-written { path: "archive" } binding.
  • Planned extension for the core families: coreBinaryCommands and coreNativeCommands open the target with runDirectAnalysis plus open options (provider, format hint, architecture, entry point, snapshot) that MCP takes from open_binary. The next slice declares those as sessionTarget.open, projected from the opening contract's own fields, and adds a runDirectAnalysis runner. Operation fields still come from the operation contract.

Change and scope

  • contractCliDescription.ts: sessionTarget and inputBinding. The target key takes part in the CLI-key collision check.
  • contractCommand.ts:
    • The target is registered as the first Incur positional.
    • The context carries sessionTarget and inputBinding.
    • New runOnSessionTarget.
  • artifactCommands.ts: the four hand-written commands, their register functions and the keyed-archive binding are replaced by registerAppleBundleCommands. decode-interface-builder omits detail with a reason, because the hand-written command never exposed it.
  • Parity guard:
    • Covers the four commands.
    • The target is the first positional, is admitted as a local path, and never reaches the contract input or caller inputs.
    • inputBinding names every renamed field.
    • A target beside a contract field keyed path is refused.
  • Not included (next slices):
    • inspect-artifact and extract-artifact: ESP flash target selection and the extraction destination.
    • The utility, core binary and core native families, which need the open extension above.
    • The managed commands.
  • Contribution scope: not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the CLI argv projection. Per-command option mapping is removed for the pilot.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract:
    • MCP: unchanged.
    • --schema: semantically identical for keyed archive, asset catalog and interface builder. trace-dylib-resolution --root now advertises its contract's root syntax and minItems.
    • Help: identical up to order.
    • Behavior changes, both intended (the CLI now admits what the contract admits):
      • trace-dylib-resolution --root ../outside is refused at argv parsing (VALIDATION_ERROR, root.0, the contract's own message) instead of by the analysis.
      • Analysis-time root issues name root instead of roots.
    • The four commands now run under the shared command cancellation, like every contract command; they previously passed no signal.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged.
  • Target selection, authority, upstream behavior, and cleanup details: the target is opened by the same runProviderAnalysis call.
  • 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

  • Tests added or updated:
    • Parity guard: 41 projected commands plus the session-target checks above.
    • dylibResolutionCli: the escaping root now expects the argv refusal, and analysis-time root issues expect root.
  • User-visible CLI output: captured --schema --format json, --help and 21 argv runs before and after through createCli().serve.
    • The runs include completed analyses on this host: trace-dylib-resolution /bin/ls --architecture arm64, inspect-asset-catalog, decode-interface-builder and inspect-keyed-archive on /System/Applications/Calculator.app.
    • They also cover missing targets, out-of-range and non-decimal limits, an invalid architecture, an escaping archive path, and repeated roots.
    • Results: 20 of 21 runs byte-identical, including the completed analyses and their Evidence. The other run is trace-dylib-resolution /bin/ls --root ../../x, changed as described above.
    • --schema: equal except trace-dylib-resolution's root.
  • Remaining proof gaps: the open extension for core commands is designed here but not implemented.

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: 254 passed.
  • npm run test:focused -- 18 keyed-archive, dylib, asset-catalog, interface-builder, bundle-resource and CLI-admission test files: dylibResolutionCli failed on the two expectations above. After updating it, that file passed (20 passed, 1 skipped); the other 17 files passed.

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:35:37.820652Z edbf64e 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 actionable issues were found.

Summary

Moves four Apple commands to shared contract-based registration.

  • Apple bundle commands now keep the target separate from their contract options.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[CLI arguments] --> B[Shared command registration]
  B --> C[Target path as typed]
  B --> D[Contract options and defaults]
  C --> E[Open target and run operation]
  D --> E
  E --> F[Await cleanup]
  F --> G[Evidence or error]
  G --> H[Rename input issue fields for CLI]
Loading

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

@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-session-target branch from 73dec66 to bca9646 Compare November 14, 2026 20:10
@morluto
morluto force-pushed the refactor/cli-contract-path-lists-flattened branch from 886a42d to 15423d9 Compare November 14, 2026 20:33
@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-session-target branch from 7092a1f to e21b171 Compare November 15, 2026 01:45
@morluto
morluto force-pushed the refactor/cli-contract-path-lists-flattened branch 2 times, most recently from 96f5467 to 70dd410 Compare November 15, 2026 05:58
@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-path-lists-flattened branch from 70dd410 to 6d01705 Compare November 15, 2026 07:34
@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-path-lists-flattened branch from 6d01705 to cc1f1b2 Compare November 15, 2026 08:48
…target

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 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-path-lists-flattened branch from cc1f1b2 to 1fbcfd3 Compare November 15, 2026 09:34
@morluto
morluto merged commit cb25d10 into refactor/cli-contract-path-lists-flattened Nov 15, 2026
@morluto
morluto deleted the refactor/cli-contract-session-target branch November 15, 2026 09:39
morluto added a commit that referenced this pull request Nov 15, 2026
…ir contracts (#10648)

* refactor(cli): project WASM inspection and firmware commands from their 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.

* refactor(cli): project Apple bundle commands onto a declared session 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 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