feat: improve Search tool truncation logic for long lines #7819
+363
−51
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
Improves the truncation logic for the Search tool to handle edge cases with extremely long lines (like base64 content) that can cause terminal display issues.
Changes
Problem Solved
The previous truncation logic only considered line count, which caused problems when search results contained very long lines (e.g., base64 strings, minified code). This could lead to:
Solution
The new function handles multiple limits:
It truncates content intelligently, respecting whichever limit is hit first, and provides informative messages about what was truncated.
Testing
Added comprehensive unit tests covering:
Manual testing confirms the integration works correctly with the Search tool.
Summary by cubic
Improves the Search tool’s truncation to handle extremely long lines and big outputs without breaking the terminal. Adds smart, configurable limits with clear messages to keep results readable and safe.