Repository navigation
fix(core): show line counts when tool output is truncated - #51200
Merged
Merged
Conversation
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
N/A
Type of change
What does this PR do?
When shell output or another tool's result is cut, the note now says which lines are shown and how many there are in total.
[full output saved to <file>][showing lines 6432-8431 of 8431; full output saved to <file>]... 6431 lines truncated; full content saved to <file> ...[showing lines 1-2000 of 8431; full output saved to <file>]The line numbers match
read'soffset, so the agent knows exactly where the missing part starts in the saved file. The shell note used to give no size at all. The other note gave a line count or a byte count depending on which limit was hit; it now always gives lines.Cost. Shell output is only read back from its last 50 KB, so the total can't come from the capture. Instead, newlines are counted as each chunk is written to the output file, so building the note never rescans the file. Counting took about 17 ms per 100 MB of output in a quick benchmark. The other tools' results are already in memory, so their count is free.
Edge cases:
[showing 0 lines of 1; full output saved to <file>].read,grepandglobare unchanged.readalready says where to continue, andgrep/globstop searching at the limit, so their totals aren't known.How did you verify your code works?
seq 1 8431giveslines 6432-8431 of 8431, and the first line shown is6432.lines 494-1000 of 1000, and the partial first line is line 494.lines 1-1 of 1.ToolOutput.truncateon 8,431 short lines (lines 1-2000 of 8431, last line shown isline 2000) and on a single 60 KB line (0 lines of 1).test/tool-output.test.tsfor the new note, and renamed the byte-limit test to match.bun run checkpasses. Inpackages/core,test/tool-output.test.ts,test/tool-shell.test.ts,test/session-shell.test.tsandtest/shell.test.tsgive 104 pass, 6 fail. The same 6 bash-approval tests fail locally onv2without this change.Screenshots / recordings
N/A
Checklist