Skip to content

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

Merged
morluto merged 4 commits into
refactor/cli-contract-native-openfrom
refactor/cli-contract-selector-options
Nov 15, 2026
Merged

morluto merged 4 commits into
refactor/cli-contract-native-openfrom
refactor/cli-contract-selector-options

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

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

A contract projection can now take a positional selector that the caller may instead give with a named option, the form the remaining core binary commands use. procedure-references and inspect-native-api are derived from their contracts with it, which completes the core native family.

Problem and expected behavior

procedure-references and inspect-native-api were hand-written because they take the procedure either positionally or as --procedure (for symbols that begin with a dash). Equal values agree, native addresses by identity (0x1a and 0x1A), and conflicts fail. The contract projection had no such form, so each command re-declared its inputs and called resolveCliAnalysisSelector itself. The same form blocks decompile, xrefs, trace, function, instructions and search.

Expected behavior: same arguments, options and help. Missing or conflicting selectors are refused before the target is opened, with the same issue paths and messages.

Change and scope

  • analysisSelector.ts: selectCliAnalysisSelector owns the agreement rule and returns a Result. resolveCliAnalysisSelector now wraps it (throws) for the core binary commands that are still hand-written.
  • contractCliDescription.ts:
    • selectorOptions names, per positional field, the option key, help and agreement kind (text or native). The positional becomes optional. Registration refuses a selector on a non-positional or non-text field.
    • The option may share the positional's key, so its parsed value travels under a separate valueKey. CLI-key collisions are checked separately for positionals and for options.
    • toContractInput keeps the named spelling when both are given. admit runs selectCliAnalysisSelector before the contract input is admitted.
  • contractCommand.ts: renders selector options and keeps the positional and named values apart.
  • coreNativeCommands.ts: the two commands are registered from procedure_references and inspect_native_api on nativeTarget(..., true) (with --snapshot). procedure-references keeps Evidence delivery. The Hopper document field is omitted.
  • Not included: the core binary commands (next slice), 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: selectCliAnalysisSelector owns positional/named selector agreement. The contract projection owns the two commands' inputs. Removed: the two hand-written commands.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: MCP unchanged. CLI help for both commands is unchanged except option order. Refusals keep the issue path procedure and the same messages.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged.
  • Target selection, authority, upstream behavior, and cleanup details: inspect-native-api now runs 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):
    • Both commands join the parity checks. Option keys include selector options. A selector positional may be omitted when its named option supplies it.
    • New "Positional selectors with a named option" block, for every command with a selector option:
      • The selector is taken positionally, by name (including a leading dash), or both when equal.
      • Different values are refused at the option key with invalid_value.
      • A missing required selector is refused with missing_argument.
      • For native selectors, 0x1a / 0x1A agree and keep the named spelling.
    • Registration refuses a selector option on a non-positional or non-text field.
  • Unchanged and passing: analysisSelectorCli.test.ts (missing, conflicting and dash-leading inspect-native-api selectors through the real CLI), procedureReferencesDelivery.test.ts, cliInputSchemaRequired.test.ts, emptyLocalTargetAdmission.test.ts, src/analysisSelector.test.ts.
  • Base reproduction or other evidence: help for all 13 commands in coreNativeCommands.ts was rendered with incur from refactor(cli): project inspect-artifact and extract-artifact with open_binary target options #10722's tree and this branch and diffed. For these two commands only option order differs; the other differences are the ones refactor(cli): project core native commands with open_binary target options #10736 describes.
  • 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: 429 passed.

  • npm run test:focused -- procedureReferencesDelivery, analysisSelectorCli, cliInputSchemaRequired, emptyLocalTargetAdmission, filesystem/productCatalog, mcp/nativeProcedureReferenceViews, src/analysisSelector.test.ts: 117 passed.

  • npm run check:fast: passed.

  • npx oxfmt --check src/cli tests/boundary/cli: clean.

  • Review follow-up (3f6291e): npm run test:focused -- tests/boundary/cli/analysisSelectorCli.test.ts — 36 passed; the new procedure-references empty-selector case failed before the selector projection refused "". cliContractCommandParity.test.ts + cliInputSchemaRequired.test.ts — 454 passed. npm run check:fast — passed.

  • This branch now also carries refactor(cli): project inspect, xrefs, trace, function and instructions from their contracts #10747 (collapsed into it); see that PR for its validation.

  • 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.
  • 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: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T07:36:55.235354Z bb60c95 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 reviewed changes appear safe to merge; no blocking issue was found.

Summary

The PR adds shared support for positional selectors with named alternatives and moves seven commands onto contract-based registration.

  • Contract commands accept a selector by position or name.
  • Native procedure commands use their tool contracts.
  • Core binary commands use their tool contracts.

This assessment is source-based; tests and real providers were not run. Live supersession status could not be checked because GitHub authentication was unavailable. The supplied stack lists no higher dependent PR.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Parse arguments and options] --> B[Keep selector spellings separate]
  B --> C{Selectors agree and required value exists?}
  C -->|No| D[Return input error]
  C -->|Yes| E[Check delivery and opening options]
  E --> F[Run direct analysis]
  F --> G[Await provider cleanup]
  G --> H[Return Evidence or publish bundle]
Loading

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

Comment thread src/cli/coreNativeCommands.ts Resolved
…th 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.
…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
morluto force-pushed the refactor/cli-contract-native-open branch from 0b50b74 to 6b05a90 Compare November 15, 2026 07:35
@morluto
morluto force-pushed the refactor/cli-contract-selector-options branch from 5dead85 to bb60c95 Compare November 15, 2026 07:35
@morluto
morluto merged commit b8f774f into refactor/cli-contract-native-open Nov 15, 2026
1 check passed
@morluto
morluto deleted the refactor/cli-contract-selector-options branch November 15, 2026 07:55
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