Skip to content

refactor(cli): project core native commands with open_binary target options - #10736

Merged
morluto merged 3 commits into
mainfrom
refactor/cli-contract-native-open
Nov 15, 2026
Merged

morluto merged 3 commits into
mainfrom
refactor/cli-contract-native-open

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Next slice of plan W1, stacked on #10722 (base refactor/cli-contract-artifact-target-open; retarget as the lower PRs merge). Refs #10583.

Eleven core native commands are now derived from their tool contracts, on a native session target opened with open_binary's format, architecture, entry point, provider and snapshot fields. This extends the sessionTarget.open mechanism from #10722 with a runDirectAnalysis runner.

Problem and expected behavior

annotate-native-function, search-bytes, inspect-native-load-image, read-bytes, address-to-file-offset, trace-native-values, inspect-native-data-type, inspect-native-instruction, resolve-native-call-targets, trace-native-ui-action and inspect-native-dispatch-metadata were hand-written:

  • Each re-declared its contract fields as options and rebuilt the contract input by hand.
  • search-bytes and inspect-native-data-type kept CLI copies of the byte-pattern and selector-choice checks that runDirectAnalysis already runs (admitOneShotOperation) before any target access.
  • inspect-native-dispatch-metadata did not expose the contract's objc_class_import_addresses and objc_class_import_addresses_complete fields.
  • trace-native-values held its own copy of the "source Evidence missing" refusal.

Expected behavior: the same arguments, options, defaults and help, with the contract as the single owner of the input.

Change and scope

  • contractCliDescription.ts:
    • An opening field projection may set callerPath: the value is admitted by the opening contract in its resolved form and passed on as the caller spelled it, like the target itself. Registration refuses callerPath on a non-string field.
    • A union of text forms (such as the provider selector, auto or a provider ID) renders as one argv token.
  • options.ts: nativeTarget(description, snapshot?) declares a native executable opened with open_binary's format (narrowed to dos-com, raw-binary, gamecube-dol as before), architecture, entry_point, provider_id and, where the command loads one, snapshot_path. Flag names (--target-format, --architecture, --entry-point, --provider, --snapshot) and help text are unchanged and shared with the hand-written flags through one help table.
  • contractCommand.ts: runDirectOnTarget maps the admitted opening through openBinaryTargetSelection and runs the operation with runDirectAnalysis. With evidenceDelivery it publishes complete Evidence or a summary; requireSourceEvidence keeps trace-native-values' refusal when the session returns no source Evidence.
  • coreNativeCommands.ts: the eleven commands are registered from their contracts; the Hopper document field is declared omitted where the contract has it.
  • Not included (next W1 slices):
    • procedure-references and inspect-native-api, and the core binary commands, take a selector either positionally or as an option (resolveCliAnalysisSelector). The projection has no such form yet.
    • decompile-directory, utility and managed families.

Contribution scope: not applicable. Target selection and authority are unchanged.

  • Startup stays lazy: commands read their contracts from their own groups (contractNamed(OFFICIAL_TOOL_CONTRACTS, …), ENHANCED_TOOL_CONTRACTS, NATIVE_TOOL_CONTRACTS, ELECTRON_TOOL_CONTRACTS, OPEN_BINARY_TOOL_CONTRACT) instead of toolContract from toolContracts.ts, which loaded the complete catalog at CLI startup (tests/boundary/cli/cliStartupImports.test.ts). The lint rule added in refactor(cli): project inspect-artifact and extract-artifact with open_binary target options #10722 keeps it out.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the tool contracts own the inputs; the service's contract parse (admitOneShotOperation) owns cross-field and grammar admission. Removed: the CLI's hand-built inputs, its byte-pattern and data-type selector admission copies, and the per-command opening option mapping (replaced by openBinaryTargetSelection).
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract:
    • MCP: unchanged.
    • CLI help for the eleven commands is unchanged except option order within three commands, and two new inspect-native-dispatch-metadata options: --objc-class-import-address (repeatable) and --objc-class-import-addresses-complete.
    • inspect-native-data-type --type "" / --address "" is now refused by argv validation (VALIDATION_ERROR) like other contract-derived empty selectors, instead of invalid_request. Still before the target is opened.
    • Byte-pattern refusals of search-bytes are unchanged for callers (invalid_request with the field path, before target access); they now come from the service's admission.
    • An unpaired --target-format raw-binary / gamecube-dol with --architecture / --entry-point is now refused by open_binary's input schema before the target is opened: invalid_request with details.issues[].path naming the CLI key. The message is the same. Before, the target resolver refused it with details.reason.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged.
  • Target selection, authority, upstream behavior, and cleanup details: the commands without Evidence delivery now also run under the command's cancellation signal. Otherwise unchanged.
  • Generated metadata, package, or installation impact: none.

Expected effects (unchanged from the existing commands; left for the human owner to check):

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

(annotate-native-function edits annotations in the ephemeral analysis database, as before.)

Evidence and regression coverage

  • Tests added or updated:
    • cliContractCommandParity.test.ts: the eleven commands join the parity checks (every contract field exposed or omitted, argv maps to an admitted contract input, renamed fields named by CLI key). For every native-target command: opening values stay out of the contract input, admitOpening returns them in contract spelling with the snapshot as typed, the raw-binary pairing rule refuses naming entry-point, and --target-format refuses esp-flash-image. Registration refuses callerPath on a non-path field.
    • searchBytesAdmission.test.ts: the mocked-runner rejection cases are removed; they asserted the CLI-local admission copy. searchBytesAdmissionCli.test.ts (real CLI) covers the same refusals before target access and gains the all-zero-mask case.
    • analysisSelectorCli.test.ts: empty --type / --address now expect VALIDATION_ERROR.
  • Base reproduction or other evidence: help output of the 13 commands in coreNativeCommands.ts was rendered with incur from the parent tree and this branch and diffed: only the reorders and the two new options above differ.
  • Remaining proof gaps: no real Ghidra/Hopper run of the migrated commands in this PR.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:focused -- tests/boundary/cli/cliContractCommandParity.test.ts: 407 passed.
  • npm run test:focused -- 12 native CLI boundary files (nativeMachoArm64_32Cli, cliInputSchemaRequired, nativeLoadImageSummaryCli, searchBytesAdmission, nativeDispatchInputBudget, traceNativeValuesEvidenceCli, emptyLocalTargetAdmission, traceNativeValuesCompletenessCli, analysisSelectorCli, nativeDispatchRecordBudget, cliDecimalArguments, nativeDispatchPropertyAttributes): failures in searchBytesAdmission and analysisSelectorCli before the test updates above; passing after.
  • npm run test:focused -- searchBytesAdmission, analysisSelectorCli, acceptance/searchBytesAdmissionCli, acceptance/localPathAdmissionCli, acceptance/nativeDispatchSnapshot, acceptance/nativeDispatchFallbackFailure, process-global/cliSelectedEnvironment, filesystem/productCatalog: 57 passed.
  • npm run check:fast: passed.
  • npm run knip: no findings.
  • npx oxfmt --check src/cli tests/boundary/cli tests/acceptance/searchBytesAdmissionCli.test.ts: clean.
  • After rebasing onto main with the startup-import fix: npm run check:fast passed (pre-push) at this branch; at the top of the stack npm run test:focused -- tests/boundary/cli/cliStartupImports.test.ts tests/boundary/cli/cliContractCommandParity.test.ts tests/boundary/cli/nativePlistCli.test.ts tests/boundary/cli/nativePlistSelectionFailureCli.test.ts tests/boundary/cli/contractCommandInputFields.test.ts tests/boundary/cli/nativeMachoEvidenceDeliveryCli.test.ts: 660 passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Only the error code for an empty data-type selector changes (still refused before the target opens).
  • 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.

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-15T13:05:13.945001Z
We couldn’t complete this review. Comment @codex review to try again.
a8bd2c7 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 the reviewed dependent stack; no blocking defect remains.

Summary

Moves native and core binary commands onto contract-derived CLI registration and a shared runDirectOnTarget runner.

  • CLI selectors and target-opening options now share one contract path.
  • Native analysis commands now take their inputs from their tool contracts.
  • Core binary commands now use contracts to build their CLI inputs.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[CLI arguments and options] --> B[Contract-derived schemas]
  B --> C[Check selector agreement and delivery]
  C --> D[Admit selected opening fields]
  D --> E[runDirectOnTarget]
  E --> F[admitOneShotOperation]
  F --> G[Open target and run analysis]
  G --> H[Finish cleanup]
  H --> I{Evidence delivery selected?}
  I -->|No| J[Return result]
  I -->|Yes| K[Publish complete Evidence or summary]
Loading

Reviews (3) · Last reviewed commit: "refactor(cli): project procedure-referen..." · Reviewed by Greptile

Comment thread src/cli/options.ts Resolved
@morluto
morluto force-pushed the refactor/cli-contract-artifact-target-open branch from 5310117 to 589c9f3 Compare November 15, 2026 05:58
@morluto
morluto force-pushed the refactor/cli-contract-native-open branch from 2394666 to 0b50b74 Compare November 15, 2026 05:58
@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-open branch 2 times, most recently from b8f774f to 8b730fc 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-open branch from 8b730fc to 314a029 Compare November 15, 2026 10:08
@morluto
morluto force-pushed the refactor/cli-contract-artifact-target-open branch from 4255498 to d6b961c Compare November 15, 2026 11:18
@morluto
morluto force-pushed the refactor/cli-contract-native-open branch from 314a029 to 74f1dec 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.

1 similar comment
@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 force-pushed the refactor/cli-contract-native-open branch from 74f1dec to e05806c 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.

Base automatically changed from refactor/cli-contract-artifact-target-open to refactor/cli-contract-native-call-document November 15, 2026 11:51
@morluto
morluto force-pushed the refactor/cli-contract-native-call-document branch from 6047cc5 to d270416 Compare November 15, 2026 12:19
@morluto
morluto force-pushed the refactor/cli-contract-native-open branch from e05806c to 59190c5 Compare November 15, 2026 12:19
@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.

1 similar comment
@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 changed the base branch from refactor/cli-contract-native-call-document to main November 15, 2026 12:36
…ptions

A session target's opening fields may now be caller paths, admitted
resolved and passed on as the caller spelled them, and a union of text
forms such as the provider selector renders as one argv token.

nativeTarget declares a native executable opened with open_binary's
format, architecture, entry point and provider fields, plus the snapshot
where a command loads one. runDirectOnTarget runs an operation on that
target through runDirectAnalysis, with Evidence delivery when declared.

Eleven core native commands are now derived from their contracts. Their
inputs are admitted by the service's contract parse, which replaces the
CLI's copies of the byte-pattern and data-type selector checks.
inspect-native-dispatch-metadata now exposes the contract's Objective-C
class import address fields.
…th named selector options (#10738)

* refactor(cli): project procedure-references and inspect-native-api with named selector options

A contract projection may let the caller give a positional selector with
a named option instead, for values that begin with a dash. The positional
becomes optional; equal values agree (native addresses by identity), and
different values, or neither for a required field, are refused before the
target is opened. selectCliAnalysisSelector owns that rule and returns a
Result; resolveCliAnalysisSelector remains for the hand-written core
binary commands.

procedure-references and inspect-native-api are now derived from their
contracts on the native session target, which completes the core native
family.

* fix(cli): refuse empty named and positional selectors before opening the target

* refactor(cli): project inspect, xrefs, trace, function and instructions from their contracts (#10747)

The five core binary commands are derived from their contracts on the
native session target with the snapshot option, using named selector
options for the procedure, address and query.

A selector projection may require a selector the contract lets the MCP
caller omit: xrefs' address defaults to Hopper's cursor, which a one-shot
CLI command does not have. A selector names one object, so neither
spelling may be empty, as before, even where the contract's text admits
it.

open_binary's pairing rules now refuse an unpaired --target-format,
--architecture or --entry-point for inspect before the target is opened,
naming the CLI key.

* fix(cli): read core binary contracts from their contract groups so startup stays lazy
@morluto
morluto force-pushed the refactor/cli-contract-native-open branch from 59190c5 to a8bd2c7 Compare November 15, 2026 13:05
@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 4eafd9d into main Nov 15, 2026
6 checks passed
@morluto
morluto deleted the refactor/cli-contract-native-open branch November 15, 2026 13:32
@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