fix: limit grep results to prevent context_length_exceeded errors (#2510)
## Summary
- Add a configurable `limit` parameter to the grep tool (default: 100,
max: 500) to prevent context window overflow
- Truncate individual line text to 500 characters to handle very long
lines
- Add clear truncation notice telling the AI to narrow its search when
results are truncated
- Add `total` and `truncated` attributes to XML output for visibility
## Test plan
- [x] Build passes (`npm run build`)
- [x] Lint passes (`npm run lint`)
- [x] All 669 unit tests pass (`npm test`)
- Manual testing: grep with a broad query like "import" should now
return limited results with a truncation notice instead of overflowing
the context window
Fixes #2509
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- devin-review-badge-begin -->
---
<a href="https://app.devin.ai/review/dyad-sh/dyad/pull/2510"
target="_blank">
<picture>
<source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
<img
src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1"
alt="Open with Devin">
</picture>
</a>
<!-- devin-review-badge-end -->
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Limits grep results and line lengths to prevent context window overflows
and context_length_exceeded errors. Addresses Linear #2509 with a
configurable cap, consistent sorting, clearer UI output, and ignoring
include_pattern "*" when it matches all files.
- **Bug Fixes**
- Added limit parameter (default 100, max 250) to cap matches.
- Truncated each matched line to 500 chars.
- Sorted results by path and line number, and ignored include_pattern
"*" with a note to avoid broad searches.
- Added truncation notice and "X of Y matches" in UI.
- Exposed total and truncated flags in XML output for visibility.
<sup>Written for commit ad5979b9352ffc754019e13ead9c6be2e7b24ce9.
Summary will update on new commits.</sup>
<!-- End of auto-generated description by cubic. -->
---------
Co-authored-by:
Will Chen <willchen90@gmail.com>
Co-authored-by:
Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by:
claude[bot] <41898282+claude[bot]@users.noreply.github.com>
正在显示
请
注册
或者
登录
后发表评论