Skip to content

fix(agents): edit tool rewrites line endings on lines it did not touch - #116011

Merged
vincentkoc merged 6 commits into
openclaw:mainfrom
yetval:fix/edit-preserve-line-endings
Jul 29, 2026
Merged

vincentkoc merged 6 commits into
openclaw:mainfrom
yetval:fix/edit-preserve-line-endings

Conversation

@yetval

@yetval yetval commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users whose agent edits a file through the edit tool would find lines the edit never targeted silently rewritten on disk, with the tool reporting success and showing a clean one-line diff.

Two real cases:

  • A text file that contains a bare carriage return as data rather than as a line break, for example a captured terminal log where \r separates progress updates, or a record stream that uses \r as its separator. Editing one word in that file deletes carriage returns, and what was one logical line becomes several.
  • A working tree with mixed line endings, common when a Windows checkout, a generated file, or a pasted snippet lands in an otherwise LF repo. Editing one line converts every other line in the file to whichever ending happened to come first.

Nothing about this is visible to the model or in the TUI. The diff and the unified patch returned to the model are computed on the LF-normalized text, so the rewritten lines render as unchanged context, and the tool result reads Successfully replaced 1 block(s). The next git diff shows a whole-file change that the agent did not intend and cannot explain.

This is on the default path. The edit branch sits inside includeBaseCodingTools in src/agents/agent-tools.ts, includeCoreTools defaults to on, and no config gates it. It reaches both the host and sandbox operation sets, since the line-ending handling runs inside execute upstream of ops.writeFile.

Why This Change Was Made

src/agents/sessions/tools/edit.ts picked one line ending for the whole file from the very first newline, normalized the entire file to LF for matching, then re-applied that single ending to every \n on write.

before:

const originalEnding = detectLineEnding(content);
const normalizedContent = normalizeToLF(content);
...
const finalContent = bom + restoreLineEndings(newContent, originalEnding);

normalizeToLF is text.replace(/\r\n/g, "\n").replace(/\r/g, "\n"), so it destroys every CR in the file including the ones that are data. restoreLineEndings then stamps one terminator onto every line. The round trip alone, with zero edits applied, is already lossy for any file that is not uniformly CRLF.

after:

const finalContent = bom + restoreOriginalLineEndings(content, newContent);

restoreOriginalLineEndings splits the original on any terminator, keeps each line's own terminator bytes, and walks a line diff between the normalized original and the edited result. Lines the edits did not touch are emitted from the original verbatim. Newly written lines take the terminator of the original line they replaced, falling back to the terminator of the nearest preceding original line for a pure insertion. Matching still happens in LF space, so a model that sends LF oldText against a CRLF file still matches exactly as before.

A bare carriage return is both a line boundary and a data byte, so the reconstruction tracks \r as a terminator in its own right alongside \n and \r\n. That distinction matters when the edit lands on the CR-terminated line itself: the split treats the \r as the boundary, and a reconstruction that can only emit \n or \r\n writes PREFIX\nprogress\n for an edit to prefix\rprogress\n, deleting a byte the edit never targeted. Because the model-facing diff is computed on normalized text, that byte loss is invisible in review. The pairing is per line rather than per hunk, so a one-line-to-many expansion inside a CR-separated file keeps the separator on each new line.

This completes a fix the repo already made on the sibling path. Issue #89994 reported that a fuzzy edit rewrote unrelated lines across the whole file, and the resolution was applyReplacementsPreservingUnchangedLines in edit-diff.ts, which rewrites only the lines a replacement covers. The same invariant, untouched lines keep their bytes, was never applied to the line-ending path, so the identical class of damage survived on every edit rather than only fuzzy ones. The new helper lives next to that one and follows its shape.

The other file-mutating tool, apply_patch, is unaffected. Its normalize and restore round trip is gated on hasOnlyCrlfLineEndings (src/agents/apply-patch-update.ts), so it never touches a mixed-ending or lone-CR file. edit was the remaining surface without that protection.

User Impact

An agent edit now changes the lines it says it changed and nothing else. Terminal captures, fixtures, record streams, and generated files keep their carriage returns, including on the line the edit rewrote. Mixed-ending working trees stop collapsing to a single ending on the first edit. Diffs stay scoped to the real change, so review noise and spurious whole-file churn go away. Uniform LF and uniform CRLF files behave exactly as before.

Evidence

Live runs of the real production factory createHostWorkspaceEditTool (src/agents/agent-tools.read.ts), the same call src/agents/agent-tools.ts makes when it assembles the coding tools for an agent. Real on-disk files in a temp workspace, real guarded host filesystem operations, real matcher and writer, nothing stubbed. Identical starting files and identical edits in both runs. Base is pristine main at bfc99c97c57a70d030a068cf1b435903c5f9fb19, head is 349e1542e36cb375a4210c98f97d1dccff58fa4f.

BEFORE, pristine main bfc99c97c5:

--- bare CR terminates the edited line (progress log, replace the prefix)
on disk before: "prefix\rprogress\n"
tool result:    Successfully replaced 1 block(s) in run.txt.
tool diff:      "-1 prefix\n+1 PREFIX\n 2 progress"
on disk after:  "PREFIX\nprogress\n"  bytes 16 -> 16  CR 1 -> 0

--- terminal capture with CR progress separators, edit the last line
on disk before: "start\n10%\r50%\r100%\ndone\n"
tool result:    Successfully replaced 1 block(s) in run.txt.
tool diff:      " 1 start\n 2 10%\n 3 50%\n 4 100%\n-5 done\n+5 finished"
on disk after:  "start\n10%\n50%\n100%\nfinished\n"  bytes 24 -> 28  CR 2 -> 0

--- CR-separated record rewritten in the middle
on disk before: "id=1\rid=2\rid=3\nfooter\n"
tool result:    Successfully replaced 1 block(s) in run.txt.
tool diff:      " 1 id=1\n-2 id=2\n+2 id=two\n 3 id=3\n 4 footer"
on disk after:  "id=1\nid=two\nid=3\nfooter\n"  bytes 22 -> 24  CR 2 -> 0

--- mixed tree, first line LF and the rest CRLF, edit the first line
on disk before: "alpha\nbeta\r\ngamma\r\n"
tool result:    Successfully replaced 1 block(s) in run.txt.
tool diff:      "-1 alpha\n+1 ALPHA\n 2 beta\n 3 gamma"
on disk after:  "ALPHA\nbeta\ngamma\n"  bytes 19 -> 17  CR 2 -> 0

--- mixed tree, first line CRLF and the rest LF, edit the last line
on disk before: "alpha\r\nbeta\ngamma\n"
tool result:    Successfully replaced 1 block(s) in run.txt.
tool diff:      " 1 alpha\n 2 beta\n-3 gamma\n+3 GAMMA"
on disk after:  "alpha\r\nbeta\r\nGAMMA\r\n"  bytes 18 -> 20  CR 1 -> 3

--- uniform CRLF file, edit the middle line
on disk before: "alpha\r\nbeta\r\ngamma\r\n"
tool result:    Successfully replaced 1 block(s) in run.txt.
tool diff:      " 1 alpha\n-2 beta\n+2 BETA\n 3 gamma"
on disk after:  "alpha\r\nBETA\r\ngamma\r\n"  bytes 20 -> 20  CR 3 -> 3

AFTER, this branch at 349e1542e3, identical inputs:

--- bare CR terminates the edited line (progress log, replace the prefix)
on disk before: "prefix\rprogress\n"
tool result:    Successfully replaced 1 block(s) in run.txt.
tool diff:      "-1 prefix\n+1 PREFIX\n 2 progress"
on disk after:  "PREFIX\rprogress\n"  bytes 16 -> 16  CR 1 -> 1

--- terminal capture with CR progress separators, edit the last line
on disk before: "start\n10%\r50%\r100%\ndone\n"
tool result:    Successfully replaced 1 block(s) in run.txt.
tool diff:      " 1 start\n 2 10%\n 3 50%\n 4 100%\n-5 done\n+5 finished"
on disk after:  "start\n10%\r50%\r100%\nfinished\n"  bytes 24 -> 28  CR 2 -> 2

--- CR-separated record rewritten in the middle
on disk before: "id=1\rid=2\rid=3\nfooter\n"
tool result:    Successfully replaced 1 block(s) in run.txt.
tool diff:      " 1 id=1\n-2 id=2\n+2 id=two\n 3 id=3\n 4 footer"
on disk after:  "id=1\rid=two\rid=3\nfooter\n"  bytes 22 -> 24  CR 2 -> 2

--- mixed tree, first line LF and the rest CRLF, edit the first line
on disk before: "alpha\nbeta\r\ngamma\r\n"
tool result:    Successfully replaced 1 block(s) in run.txt.
tool diff:      "-1 alpha\n+1 ALPHA\n 2 beta\n 3 gamma"
on disk after:  "ALPHA\nbeta\r\ngamma\r\n"  bytes 19 -> 19  CR 2 -> 2

--- mixed tree, first line CRLF and the rest LF, edit the last line
on disk before: "alpha\r\nbeta\ngamma\n"
tool result:    Successfully replaced 1 block(s) in run.txt.
tool diff:      " 1 alpha\n 2 beta\n-3 gamma\n+3 GAMMA"
on disk after:  "alpha\r\nbeta\nGAMMA\n"  bytes 18 -> 18  CR 1 -> 1

--- uniform CRLF file, edit the middle line
on disk before: "alpha\r\nbeta\r\ngamma\r\n"
tool result:    Successfully replaced 1 block(s) in run.txt.
tool diff:      " 1 alpha\n-2 beta\n+2 BETA\n 3 gamma"
on disk after:  "alpha\r\nBETA\r\ngamma\r\n"  bytes 20 -> 20  CR 3 -> 3

The tool result string and the diff returned to the model are byte-identical between the two runs in every scenario. Only the file on disk differs, which is exactly why this is invisible today. On this branch the five damaged scenarios preserve their original terminators and byte counts, and the sixth, uniform CRLF, is unchanged from current behavior.

Checks

  • node scripts/run-vitest.mjs src/agents/sessions/tools/edit.test.ts src/agents/sessions/tools/edit-diff.test.ts src/agents/apply-patch.test.ts passes, 3 shards.
  • Eleven table-driven cases plus one focused case were added to edit.test.ts, covering a lone CR as data, a lone CR terminating the edited line, a CR-separated record rewritten in the middle, a CR-terminated line expanded into several lines, a lone CR at end of file on the edited line, LF-first mixed, CRLF-first mixed, two edits with untouched mixed lines between them, multi-line insertion into a CRLF file, uniform CRLF, and uniform LF. Reverting only edit.ts and edit-diff.ts to main fails nine of them with assertions such as expected 'PREFIX\nprogress\n' to be 'PREFIX\rprogress\n' and expected 'start\n10%\n50%\n100%\nfinished\n' to be 'start\n10%\r50%\r100%\nfinished\n', and leaves the two uniform-file cases passing, so the LF and CRLF paths are provably unchanged.
  • node scripts/run-oxlint.mjs and oxfmt --check clean on all three changed files.
  • node scripts/run-tsgo.mjs -p tsconfig.core.json clean.
  • node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json reports 197 errors, all under ui/** and all present identically on the unmodified base. None are in the changed files. Local dependency-resolution artifact, not introduced here.

Not covered: no run on a real Windows host, and no full pnpm build, since no dynamic imports, packaging, or published surfaces changed.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Jul 29, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Jul 29, 2026
@clawsweeper

clawsweeper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 5:25 PM ET / 21:25 UTC.

ClawSweeper review

What this changes

The PR changes the agent edit tool so it retains each original LF, CRLF, or bare-CR line terminator when writing an edited workspace file.

Merge readiness

⚠️ Needs maintainer review before merge - 3 items remain

Keep this PR open for maintainer review: its detailed real-workspace evidence supports a default-path data-integrity fix, but the current three-way merge and final head could not be independently inspected in the read-only checkout.

Priority: P1
Reviewed head: f990d1f698d9e2e750081b6d0f26b3041495bec3

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The behavioral proof is strong, while final patch confidence remains limited until the current merged head is independently inspected and exercised.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body supplies before/after production-factory runs against real workspace files and records the improved on-disk byte results; contributors should keep any future logs redacted.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body supplies before/after production-factory runs against real workspace files and records the improved on-disk byte results; contributors should keep any future logs redacted.
Evidence reviewed 4 items Real behavior proof in PR body: The PR body records before/after runs through the production host-workspace edit-tool factory with real files, showing bare-CR and mixed-ending bytes are preserved after the proposed fix.
Current branch scope: The supplied current-head file list limits the change to the edit tool, its replacement helper, and focused tests; it does not include workflows, dependencies, publishing metadata, or credential handling.
Review continuity: The latest prior ClawSweeper cycle found no remaining line-level defect and requested a final evaluation of the actual current three-way merge after the branch moved forward.
Findings None None.
Security None None.

How this fits together

The agent coding tool accepts model-provided text replacements, finds them against normalized text, then writes the reconstructed file through host or sandbox filesystem operations. Its returned diff informs the model what changed, so preserving untouched bytes keeps on-disk changes aligned with that model-visible result.

flowchart LR
  A[Agent edit request] --> B[Edit matcher]
  B --> C[Normalized matching view]
  C --> D[Replacement reconstruction]
  D --> E[Workspace file write]
  D --> F[Model-visible diff]
  E --> G[Edited source file]
  F --> H[Next agent decision]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is behind main; before merge, maintainers should refresh the three-way result and confirm focused edit-tool coverage still exercises the exact merged head.
  • Resolve merge risk (P1) - The reconstruction algorithm changes default file-write behavior for mixed and bare-CR inputs, so its upgrade safety depends on the focused regression cases continuing to pass on the rebased head.
  • Complete next step (P2) - The PR has credible real behavior proof but needs a maintainer to verify the rebased three-way merge and focused proof on its final head.
Agent review details

Security

None.

PR surface

Source +168, Tests +154. Total +322 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 293 125 +168
Tests 2 161 7 +154
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 454 132 +322

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/agents/sessions/tools/edit-diff.ts, serialized state: src/agents/sessions/tools/edit-replacements.ts, serialized state: src/agents/sessions/tools/edit.ts, unknown-data-model-change: src/agents/sessions/tools/edit-diff.ts, unknown-data-model-change: src/agents/sessions/tools/edit-replacements.ts, unknown-data-model-change: src/agents/sessions/tools/edit.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Refresh merge proof (recommended)
    Rebase or otherwise inspect the actual three-way merge, then rerun the focused edit-tool regression coverage against that head before merging.
  2. Pause for a narrower rewrite
    Pause this PR if the rebased reconstruction logic cannot retain unchanged bytes without altering established LF and CRLF edit semantics.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Refresh the branch against current main and provide focused edit-tool proof for the exact merged head.

Technical review

Best possible solution:

Land a rebased version only after the merged result proves that untouched bytes remain unchanged while LF and uniform-CRLF edits retain their existing behavior.

Do we have a high-confidence way to reproduce the issue?

Unclear for an independent current-head run: the PR supplies a concrete real-workspace reproduction and before/after output, but this review could not execute or inspect the checked-out head directly.

Is this the best way to solve the issue?

Unclear pending current-head inspection: preserving terminators from the original file is a focused solution to the reported corruption, but the rebased three-way result must still confirm it preserves existing edit semantics.

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: model internal, reasoning high; reviewed against d98e984ec2ae.

Labels

Label justifications:

  • P1: The default agent edit path can silently rewrite bytes outside the requested replacement, creating misleading diffs for active coding workflows.
  • merge-risk: 🚨 compatibility: Changing line-ending reconstruction can alter existing file-write results for mixed, CRLF, and bare-CR workspace content.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body supplies before/after production-factory runs against real workspace files and records the improved on-disk byte results; contributors should keep any future logs redacted.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies before/after production-factory runs against real workspace files and records the improved on-disk byte results; contributors should keep any future logs redacted.

Evidence

What I checked:

  • Real behavior proof in PR body: The PR body records before/after runs through the production host-workspace edit-tool factory with real files, showing bare-CR and mixed-ending bytes are preserved after the proposed fix. (src/agents/sessions/tools/edit.ts:457, 349e1542e36c)
  • Current branch scope: The supplied current-head file list limits the change to the edit tool, its replacement helper, and focused tests; it does not include workflows, dependencies, publishing metadata, or credential handling. (src/agents/sessions/tools/edit-replacements.ts:1, f990d1f698d9)
  • Review continuity: The latest prior ClawSweeper cycle found no remaining line-level defect and requested a final evaluation of the actual current three-way merge after the branch moved forward. (35e9a2444394)
  • Related prior repair: The PR body and related issue context identify the closed fuzzy-edit repair as adjacent work: both protect untouched file content, while this PR addresses the separate line-terminator reconstruction path. (src/agents/sessions/tools/edit-diff.ts:74, f990d1f698d9)

Likely related people:

  • vincentkoc: Authored the five follow-up commits that refined CR fallback, replacement boundaries, provenance, extraction, and production-path tests on this edit-tool change. (role: recent area contributor; confidence: medium; commits: e405df5a7cff, 883e079bf52c, 5fd57fd81283; files: src/agents/sessions/tools/edit.ts, src/agents/sessions/tools/edit-diff.ts, src/agents/sessions/tools/edit-replacements.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Refresh the branch against current main and attach focused edit-tool proof for the exact resulting head.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-07-29T17:34:03.929Z sha 4eed18946b0630e5056c028569bca12ada8d8a95 :: needs changes before merge. :: [P1] Preserve bare carriage returns beside edited text
  • reviewed 2026-07-29T19:10:16.461Z sha 349e154 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-29T19:28:52.074Z sha 349e154 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-29T21:00:04.042Z sha 5fd57fd :: needs maintainer review before merge. :: none
  • reviewed 2026-07-29T21:12:29.742Z sha 35e9a24 :: needs maintainer review before merge. :: none

The edit tool detected one line ending from the file's first newline,
normalized the whole file to LF for matching, then re-applied that single
ending to every line on write. A one-line edit therefore rewrote the
terminator of every untouched line, and deleted lone carriage returns
that were data rather than line breaks. The diff and unified patch
returned to the model are computed on the normalized text, so the damage
never surfaces in the tool result or the TUI preview.

Rebuild the written text from the original terminators instead. A bare
carriage return is tracked as its own terminator, so lines the edits did
not touch keep their exact bytes and a rewritten line is written back
with the terminator bytes it had. Newly written lines take the
terminator of the original line they replaced. Matching still runs in LF
space, so LF oldText against a CRLF file matches as before.
@yetval
yetval force-pushed the fix/edit-preserve-line-endings branch from 4eed189 to 349e154 Compare July 29, 2026 19:02
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Jul 29, 2026
@yetval
yetval marked this pull request as ready for review July 29, 2026 19:24
@vincentkoc vincentkoc self-assigned this Jul 29, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 29, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer merge note: the contributor branch is intentionally not rebased because the repository-native scripts/pr flow preserves hosted PR ancestry and assigns current-main drift to merge-verify. Current origin/main changes no PR-touched paths. Exact head f990d1f698d9e2e750081b6d0f26b3041495bec3 passed hosted CI plus sanitized AWS focused proof (109 edit/edit-diff/apply-patch tests and lint/format/dead-code gates). Proceeding through pinned squash auto-merge.

@vincentkoc
vincentkoc merged commit 51241c4 into openclaw:main Jul 29, 2026
120 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
openclaw#116011)

* fix(agents): edit tool rewrites line endings on lines it did not touch

The edit tool detected one line ending from the file's first newline,
normalized the whole file to LF for matching, then re-applied that single
ending to every line on write. A one-line edit therefore rewrote the
terminator of every untouched line, and deleted lone carriage returns
that were data rather than line breaks. The diff and unified patch
returned to the model are computed on the normalized text, so the damage
never surfaces in the tool result or the TUI preview.

Rebuild the written text from the original terminators instead. A bare
carriage return is tracked as its own terminator, so lines the edits did
not touch keep their exact bytes and a rewritten line is written back
with the terminator bytes it had. Newly written lines take the
terminator of the original line they replaced. Matching still runs in LF
space, so LF oldText against a CRLF file matches as before.

* fix(agents): preserve CR fallback for leading edit insertions

* fix(agents): align replacement line-ending boundaries

* fix(agents): preserve edit line-ending provenance

* refactor(agents): isolate edit replacement reconstruction

* test(agents): cover edits through production line endings

---------

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants