Skip to content

fix(cli): require decimal integer text for numeric options - #8386

Closed
SwintexD wants to merge 3 commits into
morluto:mainfrom
SwintexD:fix/cli-decimal-numeric-options
Closed

SwintexD wants to merge 3 commits into
morluto:mainfrom
SwintexD:fix/cli-decimal-numeric-options

Conversation

@SwintexD

@SwintexD SwintexD commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Several numeric CLI options still bind raw domain schemas or plain
z.number() fields. Incur coerces ZodNumber argv fields with Number()
(the hazard noted in src/cliObservationOptions.ts), so non-decimal
spellings pass validation and silently change meaning: "" becomes 0,
"0x10" becomes 16, and "1e3" becomes 1000.

This PR binds those options through the existing cliIntegerArgument
decimal-text guard, the same approach merged for --overload-index
(#7493) and --outline-depth (#7505) and integrated for integer
positional arguments in 8d82579 (refs #4182).

No issue tracks these options. Two open PRs fix other commands in the same
class: #7877 (byte-entropy windows, #7376) and #8042 (native UI and command
deadlines). They touch different commands; the only shared code is the
helper signature described below.

Problem and expected behavior

Smallest trigger: rea read-bytes <file> 0 --length 0x10 --json on a
64-byte file. On d54a466 the option passes validation (Number("0x10") is
16) and the command goes on to open the artifact (exit 0, target_unavailable
for this non-binary file). Expected, and on this branch: VALIDATION_ERROR
with invalid_format / Expected a decimal integer on length, before any
target access. Options whose minimum is 0 (--offset, --duration-ms)
silently accepted "" as 0.

Affected options:

  • read-bytes --length, search-bytes --limit
  • inspect-asset-catalog --offset/--limit, inspect-keyed-archive --offset/--limit
  • inspect-sqlite-database --row-limit/--worker-timeout-ms
  • inspect-evm-interface --timeout-ms
  • read-adb-logcat --count/--pid
  • instrument-with-frida --duration-ms
  • decompile-all --limit
  • inspect-packet-fields --limit, inspect-signal-decoders --limit
  • analyze-javascript-application --max-semantic-nodes,
    --max-semantic-nodes-per-file, --max-semantic-unknowns,
    --max-semantic-unknowns-per-file, --max-heap-mb, --analysis-timeout-ms
  • discover-webmcp-tools --observation-ms (blank text only; see below)

Change and scope

  • src/cli/options.ts: cliIntegerArgument(min, max = Number.MAX_SAFE_INTEGER)
    gains an optional upper bound. Existing call sites are unchanged, and the
    default adds no new limit because .safe() already bounds the value. The
    signature matches fix(cli): reject non-decimal byte-entropy window options #7877, so call sites from either PR work with either
    helper; whichever lands second resolves a one-line conflict in this helper.
  • Options whose CLI field was a canonical domain field (JavaScript resource
    controls, EVM timeout_ms, SQLite worker_timeout_ms, keyed-archive
    offset/limit) go through cliOptionalDecimalField /
    cliDefaultedDecimalField: decimal text is admitted by cliIntegerArgument
    and then piped into the owner's field, so bounds, defaults and help text
    stay owned by the domain schema. Optionality, defaults and descriptions sit
    on the outer schema, where Incur reads them for parsing and help.
  • The other listed options were CLI-owned and keep their previous
    min/max/default/optional semantics through cliIntegerArgument.
  • Help shows these options as <value> instead of <number>, as it already
    does for existing cliIntegerArgument options. Descriptions and defaults
    are unchanged (help compared on d54a466 and this branch).
  • discover-webmcp-tools --observation-ms uses the shared
    observationDuration(100) guard, like inspect-web-page and
    observe-web-session. That guard refuses blank text but intentionally
    still accepts non-decimal numeric spellings (src/cliObservationOptions.test.ts
    asserts "0x10" → 16), so this option now matches its siblings rather than
    getting a stricter rule.
  • MCP input schemas, domain schemas and generated catalogs are unchanged.

Follow the contribution scope.
Maintainer scope decision: not applicable; ordinary CLI input fix within
existing boundaries.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the CLI option adapters, at argv
    text before Incur's Number() coercion. Application workflows receive the
    same typed numbers for decimal input.
  • Contribution scope fit and linked maintainer decision: ordinary fix; not applicable.
  • CLI and MCP/tool-catalog contract: CLI acceptance narrows to decimal integer
    text for the listed options. MCP schemas are unchanged.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable; rejected input never reaches an operation.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none expected; flags and describe texts are unchanged. docs:check was not run locally.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

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

The change itself only validates argv text. The affected commands keep their
existing effects for accepted input.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/cli/cliDecimalArguments.test.ts
    runs the real CLI in-process (createCli(...).serve). For each option it
    asserts that 0x10, 1e3 and "" return VALIDATION_ERROR naming the
    field, and it checks that decimal values still get past validation. The
    read-adb-logcat positive control sets a missing REA_ADB_PATH, so it
    never starts an installed adb client.

  • Base reproduction: with the source files reverted to d54a466 and the new
    test kept, 7 of 8 tests fail (every rejection test); the decimal control
    passes. On this branch all 8 pass.

  • User-visible CLI/MCP output, read-bytes <file> 0 --length 0x10 on this
    branch (--length 8 still passes validation):

    code: VALIDATION_ERROR
    message: "REA could not read the command arguments. Check the named argument and its expected type, then try again."
    fieldErrors[1]{code,missing,path,expected,received,message}:
      invalid_format,false,length,"","",Expected a decimal integer
    
  • Remaining proof gaps: decompile-all --limit is changed but has no
    regression case. Only Windows was exercised. Node v22.23.3 was used rather
    than the pinned 24.22.1.

For boundary fixes: this covers input-boundary validation at the CLI adapter.
No lifecycle, ownership or cleanup behavior changes.

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

Windows 11 x64, Node v22.23.3, branch based on d54a466.

  • Real CLI from source (createCli(...).serve), read-bytes <file> 0 --length 0x10: on d54a466 passes validation and reaches artifact open; on this branch VALIDATION_ERROR (output under "Evidence and regression coverage").
  • npx vitest run tests/boundary/cli/cliDecimalArguments.test.ts — 8 passed.
  • Same, with the source files reverted to d54a466 — 7 failed, 1 passed.
  • npx vitest run on the new test plus tests/boundary/cli/cliIntegerArguments.test.ts, cliInputSchemaRequired.test.ts, referenceSourceSummary.test.ts, adbCli.test.ts, src/cliObservationOptions.test.ts and the keyed-archive, search-bytes and local-path acceptance tests — 10 files, 160 passed, 16 skipped.
  • npm run typecheck — passed.
  • npx oxfmt --check on the 13 changed files — clean.
  • npx oxlint on the 13 changed files — 5 max-lines-per-function warnings, all pre-existing (the touched functions got shorter).
  • npm run verify:test-discovery — "Discovered all 2930 test files exactly once."
  • npm run check — cannot start on this Windows source checkout: its run-exclusive wrapper requires the native addon that a source checkout lacks (see CONTRIBUTING, "Windows source checkouts"). Its stages were run directly instead:
    • npm run lint — 0 errors, 3169 warnings (same counts as d54a466).
    • npm run format:check, npm run metadata:check, npm run verify:architecture-guards, npm run knip:production, npm run lint:typed (0 errors) — passed.
    • npm run knip — fails with one unused exported type in src/process/DarwinHelperCache.ts, identically on d54a466; not touched here.

After the review fixes in 3ff176a:

  • Schema probes on the new adapters: --max-heap-mb accepts 512, rejects 64/99999 with the domain's too_small/too_big, and rejects 0x400, 1e3, "" and 512 as Expected a decimal integer; keyed-archive offset/limit fall back to the domain defaults 0/20000 when omitted and keep its bounds.
  • --help for inspect-keyed-archive, inspect-evm-interface, inspect-sqlite-database and analyze-javascript-application compared with d54a466: same descriptions and defaults; only the type hint changes to <value>.
  • npm run compile, then the same 10 test files — 160 passed, 16 skipped.
  • npm run typecheck — passed. npm run lint — 0 errors, 3169 warnings (unchanged). npx oxfmt --check and npx oxlint on the 6 changed files — clean. npm run knip — only the pre-existing DarwinHelperCache.ts finding.

Compatibility, safety, and release

  • Breaking changes or migration steps: scripts that passed 0x10, 1e3 or
    blank text to these options were silently reinterpreted; they now get a
    VALIDATION_ERROR naming the field. Decimal values are unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; no provider
    boundary is involved. Windows only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: input validation only.

Author readiness

Human owner: @SwintexD

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

Incur coerces ZodNumber argv fields with Number(), which silently
reinterprets non-decimal spellings: "" becomes 0, "0x10" becomes 16,
and "1e3" becomes 1000. Several numeric options still bound the raw
domain schemas or plain z.number() fields, so those spellings crossed
input validation and changed behavior silently:

- read-bytes --length and search-bytes --limit
- inspect-asset-catalog --offset/--limit
- inspect-keyed-archive --offset/--limit
- inspect-sqlite-database --worker-timeout-ms/--row-limit
- inspect-evm-interface --timeout-ms
- read-adb-logcat --count/--pid
- instrument-with-frida --duration-ms
- decompile-all --limit
- inspect-packet-fields --limit and inspect-signal-decoders --limit
- analyze-javascript-application resource bounds (--max-semantic-nodes,
  --max-semantic-nodes-per-file, --max-semantic-unknowns,
  --max-semantic-unknowns-per-file, --max-heap-mb,
  --analysis-timeout-ms)

Bind these options through cliIntegerArgument (extended with an
optional maximum) so canonical bounds are preserved in the CLI adapter
while the decimal-text guard rejects those spellings at the input
boundary with "Expected a decimal integer". Reuse the shared
observationDuration guard for discover-webmcp-tools --observation-ms
to match its inspect-web-page and observe-web-session siblings, which
refuse blank text.

Canonical MCP contracts and describe texts are unchanged. New boundary
tests refuse "0x10", "1e3", and "" per option and confirm decimal
values still reach the operations.
Give cliIntegerArgument a Number.MAX_SAFE_INTEGER default maximum
instead of branching on an optional one. The default adds no limit
because .safe() already bounds the value, and the signature matches
the helper proposed in morluto#7877 so call sites from either change work
with either helper.

Drop the comment on the JavaScript resource bounds that described the
domain fields as z.int() (ZodNumberFormat). They are z.number().int(),
a ZodNumber that incur coerces with Number(), which is the same reason
as every other option in this change.
@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge; both previous findings are addressed and no new blocking issue was found.

Summary

The PR requires decimal integer text for the listed CLI options while preserving their number checks and defaults.

  • Numeric CLI options accept decimal integer text only.
  • WebMCP discovery rejects blank observation durations.

Review checks were source-only; dependencies were not installed. The superseding-PR check could not finish because GitHub authentication was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["Supplied option text"] --> B["Decimal integer guard"]
  B --> C["Shared number checks"]
  C --> D["Existing command"]
  E["Omitted option"] --> F["Keep absent or use shared default"]
  F --> D
Loading

Reviews (2) · Last reviewed commit: "fix(cli): bind decimal options to canoni..." · Reviewed by Greptile

Comment thread src/cliObservationOptions.ts Resolved
@SwintexD
SwintexD marked this pull request as ready for review October 31, 2026 23:16
The JavaScript resource controls, EVM timeout, SQLite worker timeout and
keyed-archive page options restated their domain bounds, defaults and
help text in the CLI adapter, so later domain changes could leave the
CLI stale. Admit decimal argv text with cliIntegerArgument and pipe it
into the owner's field instead. Optionality, defaults and descriptions
stay on the outer schema, where Incur reads them for parsing and help.

Run the read-adb-logcat positive control with a missing REA_ADB_PATH so
it never starts an installed adb client.
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.

2 participants