mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
When `context` is set, the grep tool reads the file again to print the lines around each match. It turned CRLF into LF and also turned every lone CR into LF before splitting the text into lines. ripgrep, which supplies the match line numbers, counts lines only at LF. A lone CR therefore added an extra line on pi's side, so every later line was off by one. For example, in a file containing `before\rprogress\nneedle\nafter`, a search for `needle` with `context: 1` showed `progress` as the line-2 match and left out `after`. The fix keeps the CRLF normalization and splits only on LF, so pi numbers lines the same way ripgrep does. Displayed lines already have `\r` removed, so the line before the match now shows as `beforeprogress`. **Testing** - Added a test in `packages/coding-agent/test/tools.test.ts` for a file with a lone CR searched with `context: 1`. It fails without the fix and passes with it. - `test/tools.test.ts`: all 87 tests pass. - `npm run check` passes. - Reproduction from the issue. Before the fix: ``` f.txt-1- before f.txt:2: progress f.txt-3- needle ``` After the fix: ``` f.txt-1- beforeprogress f.txt:2: needle f.txt-3- after ``` Fixes #11398 Requested by @badlogic Co-authored-by: triagent <triagent@localhost> |
||
|---|---|---|
| .. | ||
| agent | ||
| ai | ||
| chord | ||
| codemode | ||
| coding-agent | ||
| durable | ||
| env | ||
| evals | ||
| mcp | ||
| telemetry | ||
| tui | ||