pi-mono/packages
robopipi[bot] fecc19e4e9
fix(coding-agent): keep grep context lines aligned with ripgrep when a file has a lone CR (#11465)
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>
2026-10-27 09:07:23 +01:00
..
agent fix(ai,chord,durable,coding-agent): parse streamed tool-call arguments incrementally (fixes #9265) 2026-10-24 08:00:07 +00:00
ai feat(ai): add GPT-6.1 Terra 2026-10-26 21:27:08 +01:00
chord feat(durable,chord): publish commits at adoption, address-following watches, synchronous observers 2026-10-26 20:44:34 +00:00
codemode fix: update deps for security advisories 2026-10-22 11:24:50 +02:00
coding-agent fix(coding-agent): keep grep context lines aligned with ripgrep when a file has a lone CR (#11465) 2026-10-27 09:07:23 +01:00
durable feat(durable,chord): publish commits at adoption, address-following watches, synchronous observers 2026-10-26 20:44:34 +00:00
env feat(durable,chord): publish commits at adoption, address-following watches, synchronous observers 2026-10-26 20:44:34 +00:00
evals fix(evals): drop autoevals dependency 2026-10-22 23:32:38 +02:00
mcp fix(ai,chord,durable,coding-agent): parse streamed tool-call arguments incrementally (fixes #9265) 2026-10-24 08:00:07 +00:00
telemetry fix(ai): resolve pi-telemetry from source in workspace tests 2026-10-26 21:05:54 +00:00
tui fix: harden handling of untrusted URLs, terminal text, and streamed data 2026-10-26 20:46:31 +01:00