search_files can substitute the wrong line when matched text contains :number: #186
Description
What happened?
search_files can return the wrong source text when a matched line itself contains another :<number>: sequence.
For example, if line 1 is:
src/example.ts:42: build failed
the native grep tool correctly returns:
many.log:1: src/example.ts:42: build failed
but the Step-facing search_files result can become:
many.log:1: src/example.ts:42: UNRELATED_LINE_42
The adapter reparses rendered grep output with a greedy path:line:text regex, mistakes the later :42: for the real line number, then reloads line 42 from the file. Timestamp-shaped text such as 12:34: reproduces the same problem; if the false line number is past EOF, the visible result can become (no matches) while the details still report one match.
I reproduced this on clean main @ f113768 with the built-in tool profile and project-native Vitest, without external extensions.
Steps to reproduce
- Create a 42-line file where line 1 is
src/example.ts:42: build failedand line 42 isUNRELATED_LINE_42. - Run
search_filesforbuild failedon that file. - The native grep result contains the correct line-1 text.
- The Step-facing result substitutes the contents of line 42.
Expected behavior
search_files should preserve the native match path, line number, and matched text without reinterpreting delimiter-like text inside the match.
Version
main @ f113768 / @step-harness/coding-agent 0.84.4
Activity
xuxujo97-coder commentedon Sep 28, 2026
Verification (against current
main)packages/coding-agent/src/core/tools/grep.ts:296-310(parseGrepLine, regex^([^\0]+?):(\d+):(.*)$); its own comment already flags:<digits>:-shaped content as the mis-parse class. Your repro (matched text containingsrc/example.ts:42:yielding an unrelated line) is consistent with a mis-parse/reload at this boundary; the exact step-facingsearch_filesstep that reloads the line is for the maintainers to pin down.The NUL-separated form mentioned in that comment would remove the ambiguity at the source.
li-xiu-qi commentedon Oct 20, 2026
Reproduced on clean
mainand fixed it locally. I would like to claim this issue — PR #278 carries the fix.