Skip to content

fix(cli): reject empty and non-decimal text for integer positional arguments - #4182

Closed
arjunprabhulal wants to merge 1 commit into
morluto:mainfrom
arjunprabhulal:fix/cli-strict-integer-args
Closed

arjunprabhulal wants to merge 1 commit into
morluto:mainfrom
arjunprabhulal:fix/cli-strict-integer-args

Conversation

@arjunprabhulal

Copy link
Copy Markdown
Contributor

Summary

Integer CLI arguments accept text that is not a number. rea cutter-command <session> "$GEN" pdi with GEN unset sends expected_generation: 0, and a fresh Cutter bridge is at generation 0, so the stale-document guard passes without the caller ever supplying a generation. rea trace-web-module-imports <manifest> "" likewise traces script 0 and exits 0. Hex, binary, exponent, signed and fractional spellings (0x1, 0b1, 1e0, +1, 1.0) are also accepted.

Problem and expected behavior

These arguments were declared as z.coerce.number().int().nonnegative() (or .min(0) / .min(1)). z.coerce.number() calls Number(value), and Number("") and Number(" ") are 0, which passes both checks. Incur passes an empty token through as a positional, so the empty value reaches the schema. Expected: anything other than a plain decimal integer is a VALIDATION_ERROR naming the argument, as it already is for other malformed positionals. MCP is unaffected because its schemas use strict z.number().

Change and scope

src/cli/options.ts adds cliIntegerArgument(min): a string that must match ^(?:0|[1-9][0-9]*)$, piped into z.coerce.number<string>().int().safe().min(min). A pipe keeps the schema exportable, which a transform would not. It replaces the coerced schemas at every CLI integer site: cutter-command expectedGeneration, trace-web-module-imports scriptIndex, the web source-location scriptIndex, line (min 1) and column, and the web network capture --record ordinals. Valid decimal values parse to the same numbers as before. Not included: MCP schemas, which already reject strings.

Contract and boundary impact

  • Semantic owner and earliest changed stage: CLI argument parsing (src/cli/*Commands.ts, src/cli/options.ts).

  • Contribution scope fit and linked maintainer decision: ordinary fix within existing boundaries; not applicable.

  • CLI and MCP/tool-catalog contract: CLI rejects inputs it previously coerced to numbers; accepted values are unchanged. MCP 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): cutter-command no longer runs against session generation 0 when the generation argument is empty.

  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none committed; CI regenerates catalogs.

  • Documentation or usability only; no target interaction.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/cli/cliIntegerArguments.test.ts runs cutter-command and trace-web-module-imports with "", " ", 0x1, 0b1, 1e0, +1 and 1.0, and expects exit 1 with a VALIDATION_ERROR on expectedGeneration / scriptIndex.
  • Base reproduction or other evidence: on main all 14 cases exit 0 (executed).
  • User-visible CLI/MCP output (if applicable): {"code":"VALIDATION_ERROR","fieldErrors":[{"path":"expectedGeneration","message":"Expected a decimal integer",...}]}.
  • Remaining proof gaps: --record is covered by the shared schema but has no dedicated case.

Validation performed

  • npm run test:prepare && npx vitest run --project cli-boundary — 88 files, 498 passed, 2 skipped
  • npx vitest run --project mcp-boundary — 138 files, 776 passed, 5 skipped
  • npx vitest run tests/acceptance/webModuleCli.test.ts — 1 passed
  • npx tsc --noEmit -p . — no errors
  • npx prettier --check and npx oxlint on the changed files — clean apart from the existing max-params warning at options.ts:69

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

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 ✅ Completed 2026-10-15T17:17:55.338541Z 281d040 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 Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable defects were found.

Summary

The PR adds cliIntegerArgument and shares it across Cutter generations, web script indexes, source coordinates, and capture record selections.

  • CLI integer arguments accept only plain decimal digits.

arjunprabhulal acknowledged that malformed --record values have no dedicated regression case. Whether this PR has been superseded could not be checked because GitHub access required authentication. Tests were inspected, not run.

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

morluto added a commit that referenced this pull request Oct 15, 2026
Validate decimal tokens at the CLI owner before safe-number parsing. Apply the same rule to positional indexes/generations and repeated record selectors, retaining leading-zero decimals and canonical MCP inputs.

Refs #4182

Co-authored-by: Arjun Prabhulal <[email protected]>
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Integrated on main in 8d82579. CLI integer arguments now validate decimal token syntax before safe-number coercion, across generations, script positions and repeated record selectors. Leading-zero decimal inputs remain supported; MCP number contracts and hex entry points retain their existing semantics.

Public CLI negatives cover empty/whitespace, alternate numeric syntax, unsafe integers and an invalid later repeated selector. The Cutter bridge control confirms 000 selects generation 0. Relevant positive CLI/MCP workflows and main CI passed: https://github.com/morluto/rea/actions/runs/38792163880. Closing as addressed.

@morluto morluto closed this Oct 15, 2026
@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.

2 participants