Consolidate the four grep-output truncation implementations into one - #400
Merged
TheGreatAxios merged 2 commits intoAug 8, 2026
Merged
Conversation
TheGreatAxios
force-pushed
the
cl-5674-four-different-tool-output-truncation-implementations
branch
from
August 8, 2026 19:10
b602705 to
e16c36e
Compare
Grep results passed through both ripgrep-plugin's line cap and rg-output's byte cap on the way in, then result-truncation-plugin's character cap on the way out, each with its own wording. Whenever more than one of those caps actually fired on the same result, the notices concatenated (or one silently clobbered another), so the model would sometimes see two differently-worded "truncated" notices, or a mangled fragment of one. result-truncation-plugin.ts's truncateToolResultContent is now the only place that attaches a truncation notice; it takes an optional threshold so other callers can reuse the same wording at a different cap size. The grep-specific cappers (rg-output's byte-cap breach, ripgrep-plugin's line-count cap) now trim silently and rely on that final pass to report the truncation once. bounded-grep-fallback's own byte-cap loop is removed outright — ripgrep-plugin's boundedContent already re-checks the fallback walker's output against the same byte-cap primitive downstream, making the fallback's own pass redundant. rg-output's timeout notice is untouched, since a run timing out is a different, non-redundant fact from output being oversized.
ripgrepPlugin answers grep and search_files without calling next, so the result-truncation middleware later in the plugin array never observed those results and an oversized grep reached the model uncapped. Apply the shared primitive at ripgrepPlugin's own return paths, and restore the match-count notice, which reports an omission no size-based pass can infer.
TheGreatAxios
force-pushed
the
cl-5674-four-different-tool-output-truncation-implementations
branch
from
August 8, 2026 20:05
e16c36e to
664d799
Compare
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.
Summary
truncateToolResultContentin result-truncation-plugin.ts is now the single primitive that produces a truncation notice (takes an optional threshold for reuse at other cap sizes). The grep-specific caps now trim silently and leave notice duty to that pass, which runs last in the plugin chain. bounded-grep-fallback.ts's own byte-cap loop is deleted outright — ripgrep-plugin.ts'sboundedContentalready re-checks its output downstream.Test plan
tests/unit/ripgrep-plugin.test.ts(scripted rg stream bypassing real rg's--max-count) proved two notices stacked pre-fix, verified single/no notice post-fixbun run typecheckbun run buildbun run test— full suite green except one pre-existing, unrelated failure (lsp-availability.test.ts, an environment/install check on the worktree's node_modules, untouched by this change)grep -e -context 3 -max_results 5000 src) through the actual plugin chain: 80,115-char result, exactly one truncation notice