Skip to content

fix(tools): match and keep CRLF line endings in diff_edit - #1995

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

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

Conversation

@Edzard9

@Edzard9 Edzard9 commented Nov 7, 2026 •

Copy link
Copy Markdown

Description

diff_edit matched SEARCH blocks literally against the raw file content, so a multi-line block sent with LF line breaks never matched a file with CRLF line endings, and was refused with Search block 1 was not found in file.

Parsed blocks are now fitted to the file's line endings with fitEditToLineEndings from source/utils/line-endings.ts - the same helper string_replace uses since #1961 - before validation, application, and the VS Code diff preview. When most of a file's lines end in CRLF, the search and replacement text are converted to CRLF; LF files are unchanged, and a block that only matches an LF region of a mixed file is applied as sent.

I commented on #1993 first that I would like to take it. This is the third and last file editor from #1964 with the CRLF problem, after string_replace (#1961) and write_file (#1992).

Closes #1993

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Added two tests to diff-edit.spec.tsx: a multi-line LF SEARCH block against a CRLF file (the result keeps CRLF endings everywhere), and a mixed-ending file where the LF search only matches the LF region and is applied as sent. Ran locally: diff-edit.spec.tsx (33 tests), line-endings.spec.ts and string-replace.spec.tsx (67 tests) all pass, and pnpm test:types is clean. The full pnpm test:all suite was left to CI.

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Not applicable: this only changes how the local diff_edit tool matches text in files, independent of provider.

Checklist

  • If this was for an open issue, I was assigned to it
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

On the two unchecked boxes: I am not formally assigned to #1993 (I left a comment on the issue stating I would work on it), and this change adds no new behavior that needs logging.

diff_edit matched SEARCH blocks literally against the raw file, so a
multi-line block with LF breaks never matched a CRLF file and its
replacement wrote LF lines back into it. Parsed blocks are now fitted
with fitEditToLineEndings before validation, application and the VS
Code preview, the same way string_replace does it. A block that only
matches an LF region of a mixed file is still applied as sent.
@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: needs work — 1 blocking, 1 nit

@Edzard9 — there is a blocking item below.

The change fits diff_edit's SEARCH/REPLACE blocks to the file's dominant line endings with the existing fitEditToLineEndings helper before validation, application and the VS Code diff preview, and adds two regression tests plus a changeset. The implementation itself is correct and consistent with the string_replace fix (#1961), with no behaviour regression for LF files and no scope creep. It is not ready to merge because open PR #1994 already solves the same problem in the same file from a different branch with the identical head branch name.

Possible duplicate of #1994 — worth checking before going further.

🔴 blocking · duplicate · source/tools/file-ops/diff-edit.tsx:192

This is a duplicate of open PR #1994 ("fix(diff-edit): match SEARCH blocks on CRLF files", author Chavaaa). The evidence is strong rather than circumstantial:

Per the base rubric a duplicate of another open PR is blocking, and per the project rubric this is exactly where duplicates cluster in Nanocoder's queue. The fix is to coordinate with the other contributor: if #1994 is the one that will land, close this one; if this one is preferred (it does reuse the shared fitEditToLineEndings helper rather than reimplementing it, and covers the validator and the VS Code preview), ask the other author to close theirs. Please also link the chosen PR to #1993 so the issue closes.

⚪ nit · completeness · .changeset/diff-edit-crlf.md:5

The changeset ends with Closes #1993. but the PR body has no closing keyword, so GitHub will not auto-close #1993 when this merges — the changelog prose is not a closing reference. This matches the house style of .changeset/string-replace-crlf.md (Closes #1930.), so the maintainers may handle it at release time, but adding Closes #1993 to the PR title or body would make the reference actually close the issue.


🔴 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 github-actions Bot added the agent:needs-work nc-review found blocking findings label Nov 7, 2026
@Edzard9

Edzard9 commented Nov 7, 2026

Copy link
Copy Markdown
Author

Hi, thanks for the review. Noting the timeline here for the maintainers: I claimed issue #1993 in a comment on the issue itself before opening this PR, and followed the approach the issue points to - reusing fitEditToLineEndings from #1961 rather than reimplementing the matching, applied in the executor, the validator, and the VS Code diff preview, with regression tests for both the CRLF and mixed-ending cases. I see #1994 by @chavaAA tackles the same issue and was opened just before this one. Happy to defer to whichever the maintainers prefer - if #1994 is the one you'd rather land, I'll close this PR with no hard feelings. If this one is preferred, I can keep it updated. Either way #1993 should end up closed by one of them; I've added the closing keyword to this PR's description as the review suggested.

@Edzard9

Edzard9 commented Nov 10, 2026

Copy link
Copy Markdown
Author

Understood, thanks for clarifying. Closing this PR. I'll comment and wait for assignment before opening a PR next time. Good luck @Mahdi-Hasan!

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

Labels

agent:needs-work nc-review found blocking findings area:tools Tool implementations and tool-calling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] diff_edit fails to match SEARCH blocks on CRLF files

1 participant