Skip to content

fix(core): reuse shared patch diff - #41186

Merged
kitlangton merged 1 commit into
v2from
share-patch-diff
Aug 8, 2026
Merged

fix(core): reuse shared patch diff#41186
kitlangton merged 1 commit into
v2from
share-patch-diff

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What

Consolidate Patch file-diff construction on the shared fileDiff helper used by edit/write. This corrects the observable deletion count for a one-line file ending in a newline from 2 to 1.

Before / After

Before: deleting a file containing remove\n generated a patch with one removed line but returned deletions: 2 because Patch counted before.split("\n").length. Patch also duplicated patch construction and line-counting logic already owned by fileDiff.

After: Patch delegates patch construction and additions/deletions counting to fileDiff, so both remove\n and remove report deletions: 1. Move results still expose the destination resource in file, while generated patch headers still identify the source path.

How

  • packages/core/src/tool/plugin/patch.ts calls fileDiff with the source absolute path and Patch status, then preserves Patch-specific destination-resource projection and trimDiff processing.
  • packages/core/test/tool-patch.test.ts covers one-line deletions with and without a trailing newline and pins move patch headers to the source path.

Scope

  • No changes to the shared fileDiff helper.
  • No changes to Patch formatting, mutation, permission, or move behavior beyond consolidating diff construction and correcting the derived deletion count.

Testing

  • cd packages/core && bun run test test/tool-patch.test.ts (37 passed)
  • cd packages/core && bun typecheck
  • bun run lint packages/core/src/tool/plugin/patch.ts packages/core/test/tool-patch.test.ts
  • bunx prettier --check packages/core/src/tool/plugin/patch.ts packages/core/test/tool-patch.test.ts
  • bunx ast-grep scan -c script/ast-grep/sgconfig.yml packages/core/src/tool/plugin/patch.ts
  • Push hook: bun 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, and tool/runtime.ts).

@kitlangton
kitlangton merged commit 8c758e4 into v2 Aug 8, 2026
8 of 10 checks passed
@kitlangton
kitlangton deleted the share-patch-diff branch August 8, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant