Skip to content

fix: reject invalid numeric CLI options - #13

Merged
royalpinto007 merged 2 commits into
AgentPostmortem:mainfrom
mikemikimike:codex/issue-8-numeric-cli-validation
Sep 6, 2026
Merged

fix: reject invalid numeric CLI options#13
royalpinto007 merged 2 commits into
AgentPostmortem:mainfrom
mikemikimike:codex/issue-8-numeric-cli-validation

Conversation

@mikemikimike

Copy link
Copy Markdown
Contributor

Summary

Validate numeric CLI options before scanning a repository so invalid thresholds cannot produce misleading reports or silently disable a CI gate.

Background

Number() converted values such as abc to NaN, while negative values were accepted. That allowed --max-tokens abc, --price -3, and --top -1 to exit successfully with nonsensical behavior.

Changes

  • Reject non-finite and negative values for --price and --max-tokens.
  • Require --top to be a non-negative integer.
  • Require --fail-on-waste to be a finite percentage from 0 through 100.
  • Match long options exactly, while retaining both separated and --option=value forms.
  • Add CLI regression coverage and bump the package version to 0.1.3.

Implementation

Validation runs before repository scanning and ignore-file writes, so invalid input exits with status 2 without filesystem side effects. Existing defaults and valid scan/report behavior are unchanged.

Compatibility / Known limitations

The project remains zero-dependency and supports its existing Node.js >=18 engine range. The local environment used Node 22; the repository workflow runs the same tests on Node 20.

Tests

  • npm test — 9 passed, 0 failed.
  • node bin/ctxtrim.js test/fixtures/sample-repo --format json — smoke output generated successfully.
  • node --check src/cli.js
  • node --check bin/ctxtrim.js
  • git diff --check

Issue

Closes #8

@royalpinto007
royalpinto007 merged commit f85b36d into AgentPostmortem:main Sep 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--price/--max-tokens/--top/--fail-on-waste accept NaN and negatives

2 participants