Skip to content

fix(cli): reject non-decimal token window options - #9038

Closed
Goldloli wants to merge 1 commit into
morluto:mainfrom
Goldloli:fix/cli-token-window-decimal-text
Closed

Goldloli wants to merge 1 commit into
morluto:mainfrom
Goldloli:fix/cli-token-window-decimal-text

Conversation

@Goldloli

@Goldloli Goldloli commented Nov 5, 2026 •

Copy link
Copy Markdown

Summary

The builtin --token-limit and --token-offset options validated their value with Number() coercion, so non-decimal spellings were silently reinterpreted instead of refused. They now admit decimal token text only, matching the numeric command options admitted through cliIntegerArgument (#8919).

No linked issue. This completes the same admission rule for the builtin output options that #8386 and #8920 apply to command options. #5544 changes the same options for window bounds; the spelling admission here supersedes its explicit hexadecimal allowance, so its decimal-spelling branch would no longer be reachable for hex input.

Problem and expected behavior

Smallest trigger on current main (560674e):

$ rea inspect-byte-entropy --token-limit 0x10 <file>
[truncated: showing tokens 0–16 of 513]     # 0x10 read as 16

1e3, " 5 ", and 5.0 are accepted the same way; Number() rewrites the token instead of reporting the spelling. Violated invariant: these options take decimal nonnegative safe integers, and an invalid value must fail with INVALID_OUTPUT_VALUE on its own field before dispatch. After this change all four spellings fail with INVALID_OUTPUT_VALUE naming the flag.

Change and scope

  • cliOutputValueRejection in src/cliOutput.ts now requires /^[0-9]+$/u plus a safe-integer value, so hexadecimal, exponent, padded, fractional, signed, and non-ASCII digit spellings are refused on the field.
  • docs/cli.md states the decimal-digits spelling for token windows.
  • No command options, MCP inputs, or token-window slicing behavior change; the assignment at the parse site is unchanged because an accepted value is already a safe decimal integer.

Follow the contribution scope. Ordinary fix within existing boundaries; maintainer scope decision not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: CLI builtin output-argument admission in cliOutput.ts, before command dispatch. Consumers: validateCliOutputArguments diagnostics; no other callers read these spellings.
  • Contribution scope fit and linked maintainer decision: ordinary CLI fix; not applicable.
  • CLI and MCP/tool-catalog contract: CLI builtin options only; --token-limit/--token-offset have no MCP counterpart, so tool schemas and catalog are unchanged.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none; token windows shape output only.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata: none; no generated catalogs or skills touch these options.

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/cliOutput.test.ts rejects 0x10, 0b101, 1e3, " 5 ", 5.0, +5, and ٥ for both flags and accepts 007, keeping the existing cases.
  • Base reproduction or other evidence: shown above from unmodified main (560674e).
  • User-visible CLI/MCP output (if applicable): after the change, --token-limit 0x10 returns {"ok":false,"error":{"code":"INVALID_OUTPUT_VALUE","message":"Invalid value for --token-limit: \"0x10\". Expected a nonnegative safe integer written in decimal digits."}} before any command runs; --token-limit 5 and --token-limit 9007199254740991 keep working.
  • Remaining proof gaps: none known for this admission rule.

Boundary regressions covered: malformed-input admission for the builtin argument boundary (wrong-spelling values must fail on their own field). Lifecycle regressions: not applicable; no resources or targets involved.

Validation performed

  • npm run test:focused -- tests/boundary/cli/cliOutput.test.ts — 64/64 passed (includes the new cases).
  • npm run test:focused -- tests/boundary/cli/cliTokenWindowOutput.test.ts tests/boundary/cli/dispatcher.test.ts tests/boundary/cli/versionReportCli.test.ts tests/boundary/cli/markdownArgumentErrors.test.ts tests/boundary/cli/explicitSensitiveArgumentsCli.test.ts tests/boundary/cli/textUnicodeOutput.test.ts tests/boundary/cli/completions.test.ts — 7 files, 76/76 passed.
  • npm run check:fast — passed (typecheck + lint).
  • npm run docs:check — 9/9 passed.
  • Compiled CLI spot check on macOS arm64, Node 24.22.1: --token-limit 0x10|1e3|" 5 "|5.0 all fail with INVALID_OUTPUT_VALUE; 5, 0, 9007199254740991 still produce output.

Compatibility, safety, and release

  • Breaking changes or migration steps: none intended; previously accepted non-decimal spellings were undocumented reinterpretations, and the documented decimal behavior is unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; argument admission only, verified through the compiled CLI.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new inputs reach any provider, process, or network boundary.

Author readiness

Human owner: @Goldloli

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

The builtin --token-limit and --token-offset values passed through
Number() coercion, so spellings such as 0x10, 1e3, " 5 ", and 5.0
were silently reinterpreted as integers instead of being refused.
Admit decimal token text only, as the numeric command options already
do through cliIntegerArgument.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-05T17:55:31.157822Z
We couldn’t complete this review. Comment @codex review to try again.
d7905f3 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.

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

@greptile-apps

greptile-apps Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the stricter check preserves valid decimal token-window values.

Summary

The PR rejects non-decimal spellings for --token-limit and --token-offset before command dispatch.

  • Token limits and offsets reject non-decimal spellings.

Reviews (1) · Last reviewed commit: "fix(cli): reject non-decimal token windo..." · Reviewed by Greptile

@morluto morluto closed this Nov 7, 2026
@morluto morluto added area: cli CLI adapter and one-shot commands bug Something isn't working labels 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 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants