Uh oh!
There was an error while loading. Please reload this page.
feat(opencode): switch tool truncation to token-based limits - #9648
feat(opencode): switch tool truncation to token-based limits#9648Skyline-23 wants to merge 2 commits into
Conversation
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
The following comment was made by an LLM, it may be inaccurate: Based on my search results, I found some related PRs that deal with output limits and truncation, but none appear to be direct duplicates of PR #9648. Here are the potentially related PRs: Related PRs (not duplicates):
These PRs address related concerns about tool output management, but none appear to be duplicate work on the same token-based truncation feature that PR #9648 implements. |
There was a problem hiding this comment.
Pull request overview
This pull request switches the tool output truncation system from byte-based limits to token-based limits for more accurate context management. The token estimation uses a simple 4 characters per token approximation.
Changes:
- Replaced
MAX_BYTES(50KB) withMAX_TOKENS(10,000) as the default truncation limit - Updated truncation logic to use
Token.estimate()instead ofBuffer.byteLength() - Updated user-facing messages in Read and Bash tools to reference tokens instead of bytes
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/opencode/src/tool/truncation.ts | Core implementation: renamed constants, options, and variables from byte-based to token-based; replaced byte counting with token estimation |
| packages/opencode/src/tool/read.ts | Updated Read tool to use token-based truncation and updated user-facing messages to reference tokens |
| packages/opencode/src/tool/bash.ts | Updated template variable replacement from maxBytes to maxTokens |
| packages/opencode/src/tool/bash.txt | Updated help text to reference token limits instead of byte limits |
| packages/opencode/test/tool/truncation.test.ts | Updated test descriptions and assertions to use token-based expectations; added Token import |
| packages/opencode/test/tool/bash.test.ts | Updated truncation test to generate token-based test data |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Skyline-23
commented
Jan 20, 2026
Updated the PR title to conventional format and added |
d11838e to
6dd40a4Compare6dd40a4 to
ea7d600Comparef1ae801 to
08fa7f7CompareClosing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Summary
Testing
bun test test/tool/truncation.test.tsbun test test/tool/bash.test.tsReferences