fix(core): reuse shared patch diff - #41186
Merged
Merged
Conversation
This was referenced Aug 8, 2026
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.
What
Consolidate Patch file-diff construction on the shared
fileDiffhelper used by edit/write. This corrects the observable deletion count for a one-line file ending in a newline from2to1.Before / After
Before: deleting a file containing
remove\ngenerated a patch with one removed line but returneddeletions: 2because Patch countedbefore.split("\n").length. Patch also duplicated patch construction and line-counting logic already owned byfileDiff.After: Patch delegates patch construction and additions/deletions counting to
fileDiff, so bothremove\nandremovereportdeletions: 1. Move results still expose the destination resource infile, while generated patch headers still identify the source path.How
packages/core/src/tool/plugin/patch.tscallsfileDiffwith the source absolute path and Patch status, then preserves Patch-specific destination-resource projection andtrimDiffprocessing.packages/core/test/tool-patch.test.tscovers one-line deletions with and without a trailing newline and pins move patch headers to the source path.Scope
fileDiffhelper.Testing
cd packages/core && bun run test test/tool-patch.test.ts(37 passed)cd packages/core && bun typecheckbun run lint packages/core/src/tool/plugin/patch.ts packages/core/test/tool-patch.test.tsbunx prettier --check packages/core/src/tool/plugin/patch.ts packages/core/test/tool-patch.test.tsbunx ast-grep scan -c script/ast-grep/sgconfig.yml packages/core/src/tool/plugin/patch.tsbun turbo typecheck --concurrency=3(33 tasks passed)Also attempted the repository-wide
bun run lint:effect-patterns; it remains blocked by six pre-existing diagnostics in unrelated files (filesystem/watcher.ts,session.ts,aisdk.ts,models-dev.ts,tool/read-filesystem.ts, andtool/runtime.ts).