grep tool: parse ripgrep output correctly on Windows drive paths - #27
Closed
Saidheerajgollu wants to merge 1 commit into
Closed
grep tool: parse ripgrep output correctly on Windows drive paths#27Saidheerajgollu wants to merge 1 commit into
Saidheerajgollu wants to merge 1 commit into
Conversation
The grep tool parsed each rg match line with split(":", 2). rg is
invoked with an absolute search base, so on Windows every line comes
back as C:\ws\src\a.py:12:text - the split yields file="C",
line="\ws\src\a.py" (not a digit, coerced to 0), and the real line
number ends up glued to the front of the text. Every grep result on
Windows is garbage: unusable file names, line 0, wrong text.
Match lines are now parsed with a regex whose path group tolerates an
optional drive prefix; the line group requires digits, so stray output
lines are skipped instead of misparsed. POSIX output and matches whose
text contains colons parse exactly as before.
Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Author
|
Closing this one — #20 landed a few minutes earlier and takes an equivalent approach (anchor the parse on the numeric |
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.
The bug
The
greptool invokes ripgrep with an absolute search base (cmd.append(str(base))incoworker/tools/search.py), so rg echoes absolute paths in itspath:line:textoutput._parse_rgthen splits each line withline.split(":", 2)— which on Windows breaks on the drive letter:Every match the agent sees on Windows has a one-letter filename, line 0, and the real line number glued to the front of the text — the tool is effectively unusable there, and the model can't cite or re-read anything it "found". POSIX is unaffected, which is why the existing tests (and everyday macOS use) never caught it.
The fix
Match lines are parsed with a regex whose path group tolerates an optional
[A-Za-z]:drive prefix and whose line group requires digits:POSIX paths and match text containing colons (URLs, timestamps) parse exactly as before; non-match lines are now skipped instead of misparsed, since the line group must be numeric.
Tests
Two new tests in
tests/test_code_tools.pyexercise_parse_rgdirectly (it's a pure function, so the Windows shape is testable from any OS): a POSIX line with colons in the match text, and a Windows drive-letter line asserting the file isn't truncated toCand the line number survives.tests/test_code_tools.py: 16 passed.Made with Cursor