Skip to content

fix(diff): drop the phantom trailing row from every edit's diff - #22

Merged
ericleepi314 merged 1 commit into
mainfrom
diff-no-newline
Aug 19, 2026
Merged

fix(diff): drop the phantom trailing row from every edit's diff#22
ericleepi314 merged 1 commit into
mainfrom
diff-no-newline

Conversation

@ericleepi314

Copy link
Copy Markdown
Collaborator

What

An edit rendered a fourth row past the end of a three-line file:

before                              after
⎿  Added 1 line, removed 1 line     ⎿  Added 1 line, removed 1 line
    1  alpha                            1  alpha
    2 -beta                             2 -beta
    2 +BETA-changed                     2 +BETA-changed
    3  gamma                            3  gamma
    4   No newline at end of file

Why

\ No newline at end of file is a patch marker, not a line, and the row renderer has no marker for it — \ parses as an unknown prefix, so it came out as an ordinary context line, numbered one past the file.

It is also not true. The diff is computed over the tool's applied hunk, not the whole file: a fragment that stops mid-file has no trailing newline by construction, and alpha\nbeta\ngamma\n on disk is perfectly fine. So the row asserted something false about the user's file, in the one place a reader looks to see what changed.

Filtered where the hunks are built — the only producer — so replay gets the same shape. Claude Code 2.1.235 renders no such row; the diff is now byte-identical to its output for the same edit.

Also

The gallery's mutation scenarios each own their own file, and leftovers are cleared at bootstrap. Previously write created gallery.txt and the edit scenario then failed on it (cannot overwrite existing … without reading it first) instead of exercising the diff card. edit also now reads before editing, the way the harness requires.

Test

  • npm run typecheck, npm test — 150 files / 1940 passing
  • node scripts/verify-boundary.mjs
  • new case: a hunk-shaped diff (neither side carrying a trailing newline) yields no \-prefixed row
  • live capture via scripts/tool-gallery.py edit

🤖 Generated with Claude Code

An edit rendered a fourth row past the end of a three-line file:

    ⎿  Added 1 line, removed 1 line
        1  alpha
        2 -beta
        2 +BETA-changed
        3  gamma
        4   No newline at end of file

`\ No newline at end of file` is a patch MARKER, not a line, and the row
renderer has no marker for it — `\` parses as an unknown prefix, so it
came out as an ordinary context line, numbered one past the file.

It is also not true. The diff is computed over the tool's applied HUNK,
not the whole file: a fragment that stops mid-file has no trailing newline
by construction, and `alpha\nbeta\ngamma\n` on disk is perfectly fine. So
the row asserted something false about the user's file, in the one place a
reader looks to see what changed.

Filtered where the hunks are built, which is the only producer, so replay
gets the same shape. Upstream renders no such row; the diff is now
byte-identical to what Claude Code 2.1.235 shows for the same edit.

Also tidies the gallery's mutation scenarios: `write` and `edit` each own
their own file and the leftovers are cleared at bootstrap, so `edit`
exercises the diff card instead of failing on yesterday's file, and it
reads before editing the way the harness requires.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ericleepi314
ericleepi314 merged commit 35d55f4 into main Aug 19, 2026
1 check passed
@ericleepi314
ericleepi314 deleted the diff-no-newline branch August 19, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant