Home

mweinbach / agent-coworker

publicmweinbach/agent-coworker
Overview Code History Branches Pull requestsIssuesInsights
main
HomeOverview Code PRsIssues

fix(tools): read/edit EOL contract — multi-line edits work on CRLF checkouts

2 months ago

e724434
Authored
Max Weinbach7/7/2026, 11:52:52 AM
The audit's single CRITICAL finding. read strips \r via readline, so any
multi-line oldString the model copies carries bare \n and could never match
a CRLF file's raw bytes: every multi-line edit failed with 'oldString not
found' on Windows checkouts (core.autocrlf=true) while the identical call
succeeded on macOS/Linux. And when a single-line-anchored edit DID succeed,
Bun.write spliced LF lines into the CRLF file.

edit now matches on LF-normalized haystack+needle and re-emits the file's
dominant EOL via platform/text.replaceRespectingEol — CRLF files stay CRLF
byte-exact. read gains BOM handling (UTF-8 BOM no longer leaks into line 1)
and UTF-16 decoding (the PowerShell-redirection artifact) with a size guard;
its LF-normalized view is now the documented canonical contract. UTF-8
streaming path unchanged for large files.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Parentd38940a

3 files changed
  • src/tools/edit.ts+27−10
  • src/tools/read.ts+59−7
  • test/tools/tools.eol-contract.test.ts+172−0