-
Notifications
You must be signed in to change notification settings - Fork 8.6k
feat(opencode): switch tool truncation to token-based limits #9648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
Updated the PR title to conventional format and added |
d11838e to
6dd40a4
Compare
6dd40a4 to
ea7d600
Compare
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
Summary
Testing
bun test test/tool/truncation.test.tsbun test test/tool/bash.test.tsReferences