Skip to content

fix(diff-edit): match SEARCH blocks on CRLF files - #1994

Closed
SatriaBagusNurhadianto wants to merge 1 commit into
Nano-Collective:mainfrom
SatriaBagusNurhadianto:fix/diff-edit-crlf
Closed

SatriaBagusNurhadianto wants to merge 1 commit into
Nano-Collective:mainfrom
SatriaBagusNurhadianto:fix/diff-edit-crlf

Conversation

@SatriaBagusNurhadianto

Copy link
Copy Markdown

What changed:

  • diff_edit now fits SEARCH/REPLACE blocks to the file line endings, so edits match on CRLF files.

Why:

  • Models send LF blocks; on CRLF files multi-line SEARCH blocks never matched.

Tests:

  • Existing diff-edit spec; typecheck not run locally.

Related: #1993

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

No changeset found

This PR does not add a changeset, so it will not appear in the changelog or trigger a release.

If the change is user-facing, add one:

pnpm changeset

Pick a bump (patch / minor / major) and write the changelog entry in our usual voice ("Added X... Thanks to @you. Closes #123."), then commit the generated .changeset/*.md file.

If this PR is docs-only or a chore that needs no release note, you can ignore this — or run pnpm changeset --empty to record that intentionally.

@github-actions github-actions Bot added the area:tools Tool implementations and tool-calling label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

nc-review: comments — 2 important, 1 nit

@SatriaBagusNurhadianto — a few things worth a look, none blocking.

The PR makes diff_edit reuse the existing fitEditToLineEndings helper so SEARCH/REPLACE blocks written by a model as LF match CRLF files, applying the fit consistently in the execute path, the VS Code preview path and the validator. The change itself reads correctly and mirrors the string_replace CRLF fix (#1930) that is already in the tree, including the fitted-blocks argument to formatUpdatedFileContext (which also fixes a latent line-offset drift). It is not ready to merge as-is: the new behaviour has no test at all — the PR description points at the existing diff-edit spec, which contains no CRLF case — and the user-facing fix ships without a changeset.

🟠 important · tests · source/tools/file-ops/diff-edit.spec.tsx

There is no test covering the new behaviour. The PR description lists "Existing diff-edit spec" as the test, but diff-edit.spec.tsx has no CRLF case at all — every fixture it creates is LF-only ('const oldValue = 1;\nconsole.log(oldValue);\n', 'alpha\ngamma\n', …). source/utils/line-endings.spec.ts covers the shared helper, but nothing exercises the wiring in diff_edit, so the new fitBlocksToLineEndings call sites could be reverted, dropped from the validator, or dropped from the formatter and the suite would still be green.

The precedent is right next door: the equivalent string_replace CRLF fix (#1930) shipped with dedicated cases in source/tools/file-ops/string-replace.spec.tsx ("multi-line LF edit matches a CRLF file", "added lines in a CRLF file keep CRLF", "validator: accepts an LF edit for a CRLF file", "formatter: previews an LF edit for a CRLF file"). The project rubric asks for a regression test on a bug fix.

At minimum add: (a) an execute case writing 'one\r\ntwo\r\nthree\r\n' with an LF search/replace pair and asserting the file on disk is 'ONE\r\nTWO\r\nthree\r\n'; (b) a case where the replacement adds a line, asserting CRLF is kept rather than an LF line being written into a CRLF file; (c) a validator case asserting an LF block for a CRLF file returns {valid: true}.

🟠 important · changeset · source/tools/file-ops/diff-edit.tsx

This is a user-facing bug fix to a tool exposed to models, and it ships with no changeset — changed_files contains only source/tools/file-ops/diff-edit.tsx, and there is no new file under .changeset/. The directly analogous fix is .changeset/string-replace-crlf.md, which describes exactly this behaviour for string_replace in the house changelog voice, so the precedent for what this entry should say already exists.

Add a .changeset/*.md with the frontmatter package name "@nanocollective/nanocoder" (a bare nanocoder passes the file-presence check but breaks release-prepare), bump type patch, and body text covering: diff_edit now matches SEARCH blocks against CRLF files, models send LF so multi-line blocks previously never matched, LF files and LF regions of mixed files are unchanged.

⚪ nit · design · source/tools/file-ops/diff-edit.tsx

fitBlocksToLineEndings calls fitEditToLineEndings once per block, and each call re-runs detectLineEnding(fileContent) over the whole file, so the dominant line ending is recomputed N times for N blocks. Negligible in practice, but detecting the ending once in fitBlocksToLineEndings and passing it down would make the intent clearer — and it mirrors how string-replace.tsx fits a single edit once per call site.


🔴 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 /re-review.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @SatriaBagusNurhadianto, thanks for this PR! It looks like a maintainer has left feedback
or review activity and there are still some outstanding items to wrap up.

Whenever you get a chance, could you take a look at the open comments?
If anything is unclear or you'd like a hand, just reply here and we'll help you get it across the line.

@will-lamerton

Copy link
Copy Markdown
Member

Thanks for this, @SatriaBagusNurhadianto. #1993 is assigned to @Mahdi-Hasan and is being fixed in #2007, so I'm closing this as a duplicate. If you'd like to pick up another issue, ask to be assigned first so work isn't duplicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:comments nc-review left non-blocking findings area:tools Tool implementations and tool-calling stale:nudged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants