Skip to content

Bound the output of grep_files - #41

Merged
shellygr merged 2 commits into
masterfrom
shelly/cap-grep-output
Nov 4, 2026
Merged

shellygr merged 2 commits into
masterfrom
shelly/cap-grep-output

Conversation

@shellygr

@shellygr shellygr commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

grep_files had no limit on its output. With matching_lines=True, it returned every matching line of every matching file, and the next prompt contained the whole result. On a project with three vendored copies of OpenZeppelin and four of forge-std (1,274 .sol files, 8.5 MB), one broad pattern added about 1.25M tokens. The next model call then failed with prompt is too long: 1304836 tokens > 1000000 maximum. For example, a grep for function over that tree returns 3.2 MB.

Changes:

  • _grep_impl stops adding entries before the output reaches GREP_MAX_OUTPUT_CHARS (100,000 characters). Its last line then tells how many entries it left out, and it tells the agent to use a more specific search_string or match_in. This applies to both output modes.
  • A matching line longer than GREP_MAX_LINE_CHARS (500) is cut and gets a marker. A minified or generated file can hold megabytes on one line.
  • The tool description tells the agent about both limits.
  • The _grep_impl docstring now lists its real arguments.

Both tool families (vfs_tools and fs_tools_layered) share _grep_impl, so both get the limits.

Tests: uv run pytest tests/ gives 272 passed, and uv run pyright . gives 0 errors. Without the vfs.py change, the 4 new tests that check the limits fail.

After this merges, AutoProver needs a graphcore pin bump to pick it up.

🤖 Generated with Claude Code

shellygr and others added 2 commits November 3, 2026 19:32
One grep_files call returned every matching line of every matching file,
and the next prompt contains the whole result. On a project with several
vendored copies of a dependency, a broad pattern returned more than 1M
tokens. The next model call then failed with "prompt is too long".

grep_files now stops before 100,000 characters. Its last line then tells
how many entries it left out and how to narrow the search. The tool also
cuts any matching line that is longer than 500 characters. The tool
description tells the agent about both limits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shellygr
shellygr marked this pull request as ready for review November 4, 2026 17:54
@shellygr
shellygr requested a review from jtoman November 4, 2026 17:54
@shellygr
shellygr merged commit c03be3a into master Nov 4, 2026
2 checks passed
@shellygr
shellygr deleted the shelly/cap-grep-output branch November 4, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants