Skip to content

fix(cli): clamp past-end --token-offset in truncation footer - #296

Closed
debojyoti10CC wants to merge 1 commit into
wevm:mainfrom
debojyoti10CC:fix/token-offset-past-end
Closed

debojyoti10CC wants to merge 1 commit into
wevm:mainfrom
debojyoti10CC:fix/token-offset-past-end

Conversation

@debojyoti10CC

Copy link
Copy Markdown
Contributor

What's wrong

If --token-offset is past the end of the output, the truncation footer prints a reversed range, e.g. showing tokens 100000–13 of 13. The slice is correctly empty, but the footer used the raw offset as the start while only clamping the end.

Fix

Clamp the start of the footer range to the total token count, so the past-end case reads the same as the exact-end case (13–13 of 13). The slice itself and nextOffset are unchanged. Added a patch changeset.

Testing

  • New regression test in src/Cli.test.ts (fails on main, passes now).
  • src/Cli.test.ts: 469 of 470 pass. The one failure is the symlinked-entrypoint test, which needs symlink privileges on my Windows machine and is unrelated. oxlint and oxfmt are clean on the touched files.

Before / After

Output of hello --token-offset 100000 on a command returning a 13-token message.

Before (main):

[truncated: showing tokens 100000–13 of 13]

After:

[truncated: showing tokens 13–13 of 13]

Controls unchanged: --token-offset 13 gives 13–13 of 13, --token-offset 0 gives the full message, --token-limit 5 gives 0–5 of 13.

Fixes #273

@debojyoti10CC

Copy link
Copy Markdown
Contributor Author

Bumping this in case it got buried. It is still ready for review, and I am happy to make any changes you would like. Thanks!

jxom commented Nov 24, 2026

Copy link
Copy Markdown
Member

Thanks so much for the fix and the clear before/after, @debojyoti10CC! We've folded it into #319, which combines it with #254 and ports the change to the Rust, Python, and Zig ports with differential cases. You're credited as co-author there. Closing in favor of #319.

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

2 participants