Skip to content

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

Merged
morluto merged 1 commit into
refactor/cli-contract-selector-optionsfrom
refactor/cli-contract-core-binary
Nov 15, 2026
Merged

morluto merged 1 commit into
refactor/cli-contract-selector-optionsfrom
refactor/cli-contract-core-binary

Conversation

@morluto

@morluto morluto commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Summary

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

inspect, xrefs, trace, function and instructions are now derived from their contracts (binary_overview, xrefs, trace_feature, analyze_function, read_function_instructions). They use the native session target from #10736 and the named selector options from #10738.

Problem and expected behavior

The five commands were hand-written. Each re-declared its contract fields, the native open flags and the selector option, and built the contract input itself. trace and function held their own copies of the summary-delivery preflight.

Expected behavior: the same arguments, options, defaults and help. Missing, empty and conflicting selectors are still refused before the target is opened.

Change and scope

  • contractCliDescription.ts:
    • A selector option may set required when the command needs a selector the contract lets callers omit. xrefs' contract address is optional because Hopper falls back to its cursor; a one-shot CLI command has no cursor.
    • Neither selector spelling may be empty. This keeps the CLI's existing rule where the contract's text admits "" (xrefs.address, read_function_instructions.procedure).
  • coreBinaryCommands.ts:
    • The five commands are registered from their contracts on nativeTarget(..., true), which includes --snapshot.
    • function and instructions take the procedure positionally ([address]) or as --procedure. xrefs takes [address] or --address. trace takes [query] or --query.
    • trace and function keep Evidence delivery. The CLI --detail default stays complete; analyze_function's MCP default is summary.
    • The Hopper document field is omitted.
  • Not included (need more mechanism):
    • analyze, which routes JavaScript targets to another lane.
    • decompile, which has a third selector, --file-offset.
    • search, where --kind selects between two contracts.
    • decompile-directory, and the utility and managed families.

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

Contract and boundary impact

  • Semantic owner and earliest changed stage: the tool contracts own the inputs, and open_binary owns the pairing rules for the target interpretation. Removed: five hand-written commands and two copies of the delivery preflight.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract:
    • MCP: unchanged.
    • CLI help for the five commands is unchanged except option order.
    • Refusals: an unpaired --target-format raw-binary / gamecube-dol with --architecture or --entry-point is now refused by open_binary's input schema before the target is opened, as invalid_request with details.issues[].path naming the CLI key (architecture). The message text is unchanged. Before, the target resolver refused it with details.reason. refactor(cli): project core native commands with open_binary target options #10736's commands behave the same way.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged.
  • Target selection, authority, upstream behavior, and cleanup details: inspect, xrefs and instructions now 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.

Evidence and regression coverage

  • Tests added or updated:
    • cliContractCommandParity.test.ts:
      • The five commands join the parity checks.
      • The selector checks use the selector's required. For xrefs, that checks the CLI-only requirement.
      • Selector admission expects "" to be refused.
    • rawBinaryCli.test.ts: the GameCube-with-architecture and raw-binary-without-architecture refusals now assert the issue path and message, not details.reason.
  • Unchanged and passing:
    • cliInputSchemaRequired.test.ts: selector discovery in schema, help and the LLM manifest, including that empty values are refused for xrefs and instructions.
    • analysisSelectorCli.test.ts: missing, conflicting and dash-leading selectors through the real CLI.
    • analyzeFunctionDetail, nativeFeatureTraceDelivery, commandEvidenceDelivery, procedureAliasSearchCli, directAnalysisSnapshotReplay, localToolContracts, completions and others listed below.
  • Base reproduction or other evidence:
  • Remaining proof gaps: no real Ghidra/Hopper run 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 tests/boundary/cli/cliInputSchemaRequired.test.ts tests/boundary/cli/rawBinaryCli.test.ts tests/boundary/cli/analysisSelectorCli.test.ts: 536 passed. Before the empty-selector rule and the rawBinaryCli update, 4 failed: 2 in cliInputSchemaRequired and 2 in rawBinaryCli.
  • npm run test:focused -- with 18 files (analyzeFunctionDetail, markdownArgumentErrors, commandEvidenceDelivery, nativeFeatureTraceDelivery, emptyLocalTargetAdmission, overnightBatch1CliSchemas, javascriptIntegrityPolicyCli, cliWorkerCompletion, completions, cliEvidenceCallerPath, cliLogLevelConfiguration, procedureAliasSearchCli, filesystem/directAnalysisSnapshotReplay, acceptance/tools/localToolContracts, procedureReferencesDelivery, acceptance/applications/erlangBeamViews, process-global/pwntoolsCliFinalization, process-global/setupPolicySnapshot): 178 passed, 2 skipped.
  • npm run check:fast: passed.
  • npm run knip: no findings.
  • npx oxfmt --check src/cli tests/boundary/cli: clean.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Only the timing and the error shape (issues instead of reason) of the unpaired target-interpretation 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.

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.

…ns from their contracts

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 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-15T02:09:20.270345Z d0638c8 PR opened
ℹ️ 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 reviewed changes appear safe to merge.

Summary

Moves inspect, xrefs, trace, function, and instructions to shared contract-based registration.

  • Five native CLI commands now take their inputs from tool contracts.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[CLI arguments and options] --> B[Contract-based registration]
  B --> C[Check selector and delivery choices]
  C --> D[Check native opening choices]
  D --> E[Open target and run direct analysis]
  E --> F[Await provider cleanup]
  F --> G{Evidence delivery requested?}
  G -->|No| H[Return analysis result]
  G -->|Yes| I[Return complete Evidence or save bundle and summary]
Loading

Reviews (1) · Last reviewed commit: "refactor(cli): project inspect, xrefs, t..." · Reviewed by Greptile

@morluto
morluto merged commit 3bebed9 into refactor/cli-contract-selector-options Nov 15, 2026
1 check passed
@morluto
morluto deleted the refactor/cli-contract-core-binary branch November 15, 2026 02:17
morluto added a commit that referenced this pull request Nov 15, 2026
…ns 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.
morluto added a commit that referenced this pull request Nov 15, 2026
…ns 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.
morluto added a commit that referenced this pull request Nov 15, 2026
…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 added a commit that referenced this pull request Nov 15, 2026
…ptions (#10736)

* refactor(cli): project core native commands with open_binary target options

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.

* fix(cli): read core native contracts from their contract groups so startup stays lazy

* refactor(cli): project procedure-references and inspect-native-api with 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 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