Repository navigation
fix(tools): keep CRLF line endings when write_file overwrites a CRLF file - #1992
Conversation
nc-review: comments — 2 important, 1 nit@Mahdi-Hasan — a few things worth a look, none blocking. The PR adds a 🟠 important · This PR is stacked on the still-open #1961 ("fix(tools): match and keep CRLF line endings in string_replace", same author) and, as the description says, "this diff also shows its commits". The result is that two open PRs carry byte-identical This is a stacking-hygiene problem rather than a rejected idea, so it should not block the 🟠 important ·
#1964 only enumerates ⚪ nit ·
🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with |
|
Thanks for the review. All three addressed:
|
|
#1961 is merged, so I merged main in (5e03e53). The diff is now only the |
…file Models send LF, so rewriting a CRLF file with write_file turned every line into LF. When the existing file is mostly CRLF and the new content has no CRLF of its own, write it with CRLF. New files, LF files and content with its own CRLF are written as sent. The terminal diff, the VS Code diff and the ACP diff use the same content, so the diff shows changed lines instead of every line. Closes Nano-Collective#1964
computeLineDiff split on LF only, so each line of a CRLF file kept its CR, and Ink rendered it as a blank line after every unchanged line.
One CRLF anywhere in the new content turned off the conversion, so a model that echoed back one CRLF line could still flip a CRLF file to mostly LF. Convert all line breaks whenever the existing file is mostly CRLF, as fitEditToLineEndings does for string_replace.
5e03e53 to
2f82ff5
Compare
|
Thanks @Mahdi-Hasan, nice work keeping CRLF files intact and splitting out the |
Description
write_filewrote the model's content as sent. Models send LF, so rewriting a CRLF file turned every line into LF. Fixes #1964 (thewrite_filehalf;string_replaceis #1930).It reuses
source/utils/line-endings.tsfrom #1961 (now merged), as asked on the issue.fitContentToLineEndings(existing, content)insource/utils/line-endings.ts.computeLineDiffnow splits on CRLF too. Each CRLF line kept its CR, which Ink rendered as a blank line after every unchanged line.diff_edithas the same CRLF bug. It is tracked in #1993, to keep this PR to #1964.Preview
Terminal preview when the model rewrites one line of a CRLF file with LF content:
Before (every line shows as changed):
After (only the changed line, and the file stays CRLF on disk):
Type of Change
Changeset
pnpm changeset) describing this change for the changelogTesting
Automated Tests
New features include passing tests in
.spec.ts/tsxfilesAll existing tests pass (
pnpm test:allcompletes successfully)Tests cover both success and error scenarios
5 new tests in
write-file.spec.tsx: the repro from the issue, mixed content on a CRLF file, CRLF content on an LF file, a new file, and the preview and result diffs on a CRLF file. The repro and the diff test fail without the change.1 new test in
acp-tool-call.spec.ts: the ACP diff for an LF rewrite of a CRLF file. Fails without the change.4 new tests in
line-endings.spec.tsfor the helper.1 new test in
inline-diff.spec.ts: CRLF lines lose their CR. Fails without the change.inline-diff+line-endings+write-file+acp-tool-call+string-replacespecs: 188 pass. Types, Biome and knip pass.The one failure,
write_file validator: rejects Windows system directories, also fails without this change on Windows. CI on Linux should settle it.Manual Testing
Checklist