fix(ui): normalize line endings in session file diff stats#3082
Open
CnsMaple wants to merge 1 commit into
Open
fix(ui): normalize line endings in session file diff stats#3082CnsMaple wants to merge 1 commit into
CnsMaple wants to merge 1 commit into
Conversation
The sidebar's modified-files diff stats are computed by diffing the first and last versions of a file stored in history. When a file was first written with one set of line endings (e.g. CRLF, preserved by the edit tool from a Windows editor) and later overwritten with different line endings (e.g. LF, typical for LLM-generated content written by the write tool), every line in the file was reported as changed. A 1000-line file gained 1 line would show "+1001 -1000" instead of "+1 -0". Normalize both sides to LF before calling diff.GenerateDiff so the stats reflect the real textual delta. A regression test covers the CRLF-vs-LF mismatch and the identical-content case. 💘 Generated with Crush Assisted-by: Crush:MiniMax-M3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
The sidebar's "Modified Files" list computes additions/deletions by diffing the first and last versions of a file stored in history (
internal/ui/model/session.go:139). The two versions can carry different line endings:edittool preserve the original line endings (CRLF on Windows).writetool store whatever the LLM emitted, which is almost always LF.When the diff runs, every line is reported as changed because the trailing
\ris missing/present. A 1000-line file gaining 1 line shows+1001 -1000instead of+1 -0.Fix
Normalize both sides to LF with
fsext.ToUnixLineEndingsbefore callingdiff.GenerateDiff. This is the same helper theedit/multiedittools already use internally for diff computation.Test plan
go test ./internal/ui/model/ -run TestLoadSessionFilesNormalizesLineEndingspassesgo test ./internal/ui/model/ -run TestFileListstill passesgo build ./...💘 Generated with Crush