fix(coding-agent): preserve line endings when apply_patch updates a file - #2639
Conversation
|
Lead in-session review at 1814736: PASS. Same model as pi-apply-patch #48. |
|
Real-CLI QA (senpi-qa Channel 3 pattern, zero tokens). The real
|
1814736 to
f89ea49
Compare
The built-in apply_patch split files on LF and joined them back with LF, so a one-line patch rewrote every line of a CRLF or mixed-ending file. Files are now parsed into lines that keep their own ending; a chunk is replaced around its context lines, which stay untouched, and inserted lines take the file's first ending (Codex's PreserveLineEndings model). Fixes #2638
713c9dd to
b6762bf
Compare
…rve-line-endings # Conflicts: # packages/coding-agent/CHANGELOG.md # packages/coding-agent/src/core/extensions/builtin/gpt-apply-patch/changes.md # packages/coding-agent/src/core/extensions/builtin/gpt-apply-patch/parser.ts
Fixes #2638. The standalone package's same fix is code-yeongyu/pi-apply-patch#48; senpi's builtin is a hand-maintained port (
MANUAL_PACKAGES), so it gets its own fix.What
line-endings.ts(new):SourceTextkeeps each line's own ending (\r\n,\n, lone\r).replacementsAroundContextsplits a matched chunk around its context lines, so those stay exactly as in the file. Inserted lines take the file's first ending, and every line still ends with one.replaceChunksuses it, and the parsers record each chunk'scontextLineIndices.text_file.rs,compute_replacements). In Codex it is behind an under-development flag, off by default, and its conformance scenarios run with it on. oh-my-pi restores the detected ending after edits.Tests (
test/suite/gpt-apply-patch-line-endings.test.ts)TEST AUTHORING GATE:
applyPatchDetailedand the tool'sexecute.mainVerification
test/suite/gpt-apply-patch*plustest/permission: 25 files, 565/565.tsc --noEmitclean, biome clean, changelog gate PASS.Summary by cubic
Fixes
apply_patchrewriting every line of CRLF and mixed-ending files as LF on update, so a one-line patch no longer becomes a whole-file diff in git and in the preview (#2638).Files are now parsed into lines that keep their own ending; only touched lines are replaced, context lines stay exactly as they were, and inserted lines take the file's first ending. A context line matched only after trimming is also left untouched. LF files produce identical bytes.
Pins
pi-apply-patchto 0.1.4, which carries this fix and the indented-header fix from #2637 upstream; the grammar declaration it added is already native here.Tests
Written for commit 8ac5ce9. Summary will update on new commits.