Skip to content

fix(cli): admit native data type selectors before opening a target - #7360

Merged
morluto merged 11 commits into
morluto:mainfrom
viniciusdsandrade:fix/7276-native-data-type-selector-admission
Nov 9, 2026
Merged

morluto merged 11 commits into
morluto:mainfrom
viniciusdsandrade:fix/7276-native-data-type-selector-admission

Conversation

@viniciusdsandrade

@viniciusdsandrade viniciusdsandrade commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #7276. rea inspect-native-data-type forwarded its optional --type and --address selectors straight to runDirectAnalysis, which prepares the target before the provider validates the operation input. A request with no selector, both selectors, or an empty selector therefore reported target_unavailable for a missing or unsupported target, and for a valid target it opened the target before rejecting the request. The command now admits the canonical selector choice before opening the target, and its help names that choice like the other CLI commands with selector alternatives. It also declares its positional target with localPathStringSchema, which #7956 applied to its sibling local-file commands but not to this one, so an empty target is rejected at validation instead of resolving to the working directory.

Current main (db0b9ac20) is merged into the branch.

Problem and expected behavior

Smallest trigger: rea inspect-native-data-type does-not-exist --format json, or the same command with --type /MyStruct --address 0x1000, --type "", or --address "".

Base behavior: code: "target_unavailable". #7276 reproduces the six malformed cases through the production CLI builder and dispatcher. By source, runAnalysis in src/application/DirectAnalysis.ts calls prepareSnapshot before session.execute, and the selector rule is enforced after that, for Ghidra by its input schema in src/ghidra/GhidraFunctionValues.ts.

Violated invariant: nativeDataTypeInputSchema in src/domain/native/nativeDataType.ts requires exactly one nonempty type or address. The CLI translations section of docs/tool-design.md requires the help to state a required choice that the CLI schema cannot express, and admission of that choice before target access.

Expected: an input error before target access, whether or not the target exists or is supported.

Change and scope

  • src/cli/analysisSelector.ts: export dataTypeSelectorGuidance alongside the existing shared CLI selector guidance constants so the inspect-native-data-type help text and its discovery test share one owner.
  • src/cli/coreNativeCommands.ts: parse the selectors with nativeDataTypeInputSchema before calling runDirectAnalysis, and return failures through analysisInputErrorFromIssues (retaining { cause: selected.error }) and projectAnalysisError, the admission shape that search-bytes, inspect-gpu-code-objects, and inspect-model-artifact already use. Valid requests pass the same input object to runDirectAnalysis as before.
  • Same file: the command description and both option descriptions append dataTypeSelectorGuidance, following the instrument-with-frida script source guidance.
  • Same file: the positional path uses localPathStringSchema, the shared nonempty, NUL-free schema that fix(cli): reject empty native and managed targets before resolution #7956 adopted for the other local-file commands in this group. docs/cli.md already states that local inspection commands reject empty paths before resolution.
  • Not included: no change to the domain or Ghidra schemas, to MCP, or to runDirectAnalysis ordering for other commands. Pre-existing selector test constants for unrelated commands in cliInputSchemaRequired.test.ts are left untouched to keep this PR scoped to [Bug] inspect-native-data-type reports target_unavailable for an invalid selector #7276.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the selector rule stays owned by nativeDataTypeInputSchema, and the CLI selector guidance text is owned by dataTypeSelectorGuidance in src/cli/analysisSelector.ts; the CLI adapter applies the schema at admission, before runDirectAnalysis.
  • Contribution scope fit and linked maintainer decision: not applicable; CLI admission fix within an existing command.
  • CLI and MCP/tool-catalog contract: CLI only. An invalid selector returns invalid_request for operation inspect_native_data_type before target access, and the command help, schema, and full manifest name the exactly-one choice. Valid requests and MCP are unchanged.
  • Provider, bridge, target-format, or platform compatibility: none; an invalid selector no longer reaches a provider.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): an invalid selector no longer opens, analyzes, or releases a target.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: no generated file is committed; the advertised change is the command and option description text.

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.

Evidence and regression coverage

  • Tests added or updated:

    • tests/boundary/cli/analysisSelectorCli.test.ts: runs the compiled CLI against does-not-exist with no selector, both selectors, --type "", and --address "", and expects invalid_request for operation inspect_native_data_type with the root issue message read from the owning nativeDataTypeInputSchema alongside independent checks on parameter names (type, address), paths, reasons, and minimum: 1 bounds. A single --type or --address still reaches the target and reports target_unavailable. On the base revision the four invalid cases report target_unavailable, so the test fails there.
    • tests/boundary/cli/cliInputSchemaRequired.test.ts: adds inspect-native-data-type to the required selector discovery table, comparing the advertised schema, help, and full manifest against the owning dataTypeSelectorGuidance alongside independent checks for "exactly one", absence of "at least one", preserved --type and --address option names, optional schema fields, and Ajv validation of representable and rejected shapes. On the base revision the descriptions lack the guidance, so the entry fails there.
    • tests/boundary/cli/emptyLocalTargetAdmission.test.ts: adds inspect-native-data-type --type /MyStruct to the empty-target table, which expects VALIDATION_ERROR on path with too_small before runDirectAnalysis is called, rejects NUL bytes, and admits an explicit .. On main the command still accepts the empty target, so the row fails there.
  • Base reproduction or other evidence: the [Bug] inspect-native-data-type reports target_unavailable for an invalid selector #7276 reproduction, and the source path above (coreNativeCommands.ts, DirectAnalysis.ts runAnalysis, GhidraFunctionValues.ts).

  • User-visible CLI/MCP output (if applicable): the details asserted by the new test, which the compiled CLI produced in the earlier local run:

    {"operation":"inspect_native_data_type","issues":[{"path":[],"reason":"invalid_value","message":"Supply exactly one of type or address"}]}

    An empty selector reports {"path":["type"],"reason":"out_of_range","minimum":1} (or address).

  • Remaining proof gaps: no real provider run; none is needed for the rejected cases because they no longer reach a provider, and valid requests take the unchanged path. The latest commits (810c94da1, a735387be, 220c14a25) were verified by source reading and run through CI rather than re-executed locally.

Covered boundary regressions: missing, empty, and unknown values (omitted, empty, and conflicting selectors against a single valid selector) and public success and error delivery (the compiled CLI path and its named invalid_request contract). Lifecycle regressions: not applicable; no resource ownership or finalization changes, and invalid requests no longer acquire a target.

Validation performed

On the earlier branch revision merged with main at d48e472fa (Node 24.22.1, macOS arm64):

  • npm run test:focused -- tests/boundary/cli/analysisSelectorCli.test.ts tests/boundary/cli/cliInputSchemaRequired.test.ts tests/boundary/cli/emptyLocalTargetAdmission.test.ts: 3 files, 73 tests passed, including the compiled-CLI selector cases and the new empty-target row.
  • npm run check:fast: typecheck and lint passed.
  • Not run locally after merging main at db0b9ac20 and binding the selector guidance tests to their owning contracts (a735387be, 220c14a25); those updates were verified by source reading and rely on CI execution. Full check:pr and real provider workflows were not run locally.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. A request that was already invalid now fails before target access with the canonical input error.
  • Real Hopper/Ghidra, browser, or OS coverage: platform-independent; no provider runs for the rejected cases.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new process, file, or network access; invalid requests now avoid target access.

Author readiness

Human owner: @viniciusdsandrade

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

@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Low impact] The PR appears safe to merge; no actionable issue remains in the reviewed changes.

Summary

inspect-native-data-type now checks its selector choice before opening a target. Its help and discovery tests share dataTypeSelectorGuidance.

  • Native data type inspection checks its selector before opening a target.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["CLI request"] --> B["Check local path"]
  B -->|Invalid| C["Return path error"]
  B -->|Valid| D["Check exactly one nonempty selector"]
  D -->|Invalid| E["Return input error without target access"]
  D -->|Valid| F["Open target and run analysis"]
Loading

Reviews (5) · Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." · Reviewed by Greptile

inspect-native-data-type still declared its positional target as a plain
string after morluto#7956 moved its sibling local-file commands to
localPathStringSchema, so an empty target passed validation and resolved
to the working directory. Use the shared schema and cover the command in
the empty-target admission table.
@viniciusdsandrade
viniciusdsandrade marked this pull request as ready for review November 6, 2026 22:13
@chatgpt-codex-connector

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-06T22:13:41.014721Z
We couldn’t complete this review. Comment @codex review to try again.
9a09d6a Draft marked ready
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: I ran the PR's 3 changed test files on Node 22.23.4, 24.22.1 and 26.12.1, and 79 tests passed each time. With the 2 changed source files swapped back to the merge base, 3 tests failed on every Node version. I did not run the command on a real binary.

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
Head 220c14a pass: 3 files, 79 tests pass: 3 files, 79 tests pass: 3 files, 79 tests
Red run (2 source files from db0b9ac) fail: 3 files, 3 tests failed, 76 passed fail: 3 files, 3 tests failed, 76 passed fail: 3 files, 3 tests failed, 76 passed

The red run puts src/cli/analysisSelector.ts and src/cli/coreNativeCommands.ts back to db0b9ac. That commit is where the PR branch split from main.

In the Node 24.22.1 log, one test fails in each file:

  • admits exactly one nonempty native data type selector before opening a target
  • inspect-native-data-type names every permitted selector alternative in schema, help, and the full LLM manifest
  • rejects an empty or NUL inspect-native-data-type target before resolution and admits explicit .

So the new checks fail without the fix and pass with it.

CI on 220c14a: all 19 check runs that ran passed, including CI required, Source tests and Portable tests. Conventional PR title and Validate author declaration each have one cancelled run. 25 lanes were skipped, and so was the CodeQL production workflow. PR readiness passed on a later run, and its commit status is success. GitHub says the PR is mergeable, and its merge state is clean.

The head is 25 commits behind main b81da90.

Not run

  • rea inspect-native-data-type against a real binary.
  • A merge with current main, b81da90.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 220c14a / db0b9ac (merge base with main)
  • Red run: 220c14a with the 2 changed source files from db0b9ac
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1, exit 0, for both trees
Commands
npm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- tests/boundary/cli/analysisSelectorCli.test.ts tests/boundary/cli/cliInputSchemaRequired.test.ts tests/boundary/cli/emptyLocalTargetAdmission.test.ts

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

…a-type-selector-admission

# Conflicts:
#	src/cli/coreNativeCommands.ts
@greptile-apps

greptile-apps Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@morluto
morluto merged commit dcf481c into morluto:main Nov 9, 2026
45 checks passed
@morluto morluto added area: cli CLI adapter and one-shot commands bug Something isn't working labels Nov 23, 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 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] inspect-native-data-type reports target_unavailable for an invalid selector

3 participants