Skip to content

fix: bound --token-limit and --token-offset windows - #319

Merged
jxom merged 1 commit into
mainfrom
fix/token-window-bounds
Nov 24, 2026
Merged

jxom merged 1 commit into
mainfrom
fix/token-window-bounds

Conversation

@jxom

@jxom jxom commented Nov 24, 2026

Copy link
Copy Markdown
Member

Fixes #273
Fixes #247

Supersedes #296, thanks @debojyoti10CC, and supersedes #254, thanks @HereForTheTechNFT.

Both PRs touch the same token window code, so this combines them and ports them to Rust, Python, and Zig.

  • --token-limit and --token-offset reject negative values with the same error as a non-numeric value (Invalid value for --token-limit: "-3"), so the command doesn't run and the exit code is 1. 0 and -0 stay valid.
  • An offset past the end of the output clamps the footer start to the total: showing tokens 100000–13 of 13 is now 13–13 of 13. The slice and meta.nextOffset are unchanged.
  • Ports: same checks in Rust, Python, and Zig. Their token slicers no longer handle negative positions (mirrored from tokenx), since nothing can pass one now.
  • Differential cases: past-end offsets (plain, TTY, with a limit, and --full-output), -1, -0.5, and -0. Existing negative cases now expect the error.
  • The e2e.test.ts snapshot that captured the reversed 6–3 of 3 footer now shows 3–3 of 3.

Reject negative --token-limit and --token-offset values before the command
runs, and clamp the start of the truncation footer so an offset past the end
reads `13–13 of 13` instead of a reversed range. Ports the fix to Rust,
Python, and Zig, drops their now-unreachable negative token slicing, and adds
differential cases.

Fixes #273
Fixes #247

Co-authored-by: Debojyoti De Majumder <[email protected]>
Co-authored-by: forthetech.eth <[email protected]>
Amp-Thread-ID: https://ampcode.com/threads/T-01a20b38-b5a6-738c-870c-833aef311fdc
Co-authored-by: jxom <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T02:00:15.243133Z 63e14f5 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.

@pkg-pr-new

pkg-pr-new Bot commented Nov 24, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/incur@319

commit: 63e14f5

@jxom
jxom merged commit 6958e59 into main Nov 24, 2026
9 of 10 checks passed
@jxom
jxom deleted the fix/token-window-bounds branch November 24, 2026 02:11
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.

fix(cli): past-end token offsets print reversed output ranges fix(cli): negative token limits and offsets produce invalid output windows

2 participants