aft icon indicating copy to clipboard operation
aft copied to clipboard

`edit` and `edit_symbol` write LF lines into CRLF files

Open null-axiom opened this issue 1 week ago • 1 comments

edit_match and edit_symbol insert the replacement text exactly as sent. Models send LF, so a CRLF file comes out with mixed line endings. apply_patch already converts its hunks to the file's ending, so the tools disagree.

Repro (v0.68.0 binary, one-shot NDJSON):

printf 'a\r\nb\r\nc\r\n' > c.txt
{"id":"1","command":"edit_match","file":"<abs>/c.txt","match":"b","replacement":"B\nB2"}

Result: a\r\nB\nB2\r\nc\r\n (610d0a42 0a42320d 0a630d0a). Expected a\r\nB\r\nB2\r\nc\r\n.

edit_symbol with operation: "replace" on a CRLF TypeScript file does the same: the replaced function's lines are LF, the rest of the file stays CRLF.

Cause (v0.68.1): the replacement is pushed raw, with no conversion to the file's line ending — crates/aft/src/commands/edit_match.rs:1802 (output.push_str(replacement)) and crates/aft/src/edit.rs replace_byte_range. The OpenCode plugin doesn't convert either.

Suggested fix: convert the replacement's line endings to the file's (the same rule apply_patch uses) before splicing it in, for edit_match, edit_symbol and batch edits.

null-axiom avatar Nov 26 '26 19:11 null-axiom

Thanks, @null-axiom. Confirmed: edit (match and line-range edits, including batches) and symbol edits insert the replacement text with LF line endings, even when the rest of the file uses CRLF. apply_patch already keeps a file's line endings, so the fix gives the other edit paths the same rule: new or replaced lines use the file's existing line ending, and untouched lines are left exactly as they are. It's planned for the next release.

aft-alfonso[bot] avatar Nov 26 '26 22:11 aft-alfonso[bot]