Skip to content

Return the changed region from edit/write/delete/apply_patch - #575

Merged
TheGreatAxios merged 3 commits into
mainfrom
cl-6962-edit-and-write-tools-should-return-the-changed-region-so-no
Aug 23, 2026
Merged

Return the changed region from edit/write/delete/apply_patch#575
TheGreatAxios merged 3 commits into
mainfrom
cl-6962-edit-and-write-tools-should-return-the-changed-region-so-no

Conversation

@TheGreatAxios

@TheGreatAxios TheGreatAxios commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Closes CL-6962.

Summary

  • edit_file, write_file, and delete_file now append a bounded unified diff of the changed region to their tool result, instead of returning only a success status.
  • apply_patch gets this for free: each op forwards through write_file/delete_file (posixTools.run), so the same diff is embedded per operation.
  • The diff comes from verify-plugin.ts's existing before/after content for edit_file (reused, no extra read). write_file did not previously read the file before writing, so this does add one genuine extra read per write_file call — needed to source the "before" side of its diff. That tradeoff is documented inline in verify-plugin.ts.
  • Payload is bounded: a small LCS-based diff for normal edits, a truncated diff (with a note, reserved within the char cap so the result never exceeds it) for large rewrites, and a bounded summary (skipping the O(n*m) LCS) for files over 2,000 lines.
  • delete_file skips reading file content above 256KB and reports a byte-count summary instead of a diff, so deleting a large file does not buffer it into memory just to produce a preview.
  • Unified-diff hunk headers follow convention for a zero-length side (e.g. a pure insertion is -0,0, not -1,0).
  • docs/PRODUCT.md's write-verification line now describes what the model/operator actually get.

Test plan

  • bunx tsc --noEmit
  • bun test src/plugins/change-diff.test.ts — small edit diff, whole-file rewrite truncation (cap enforced exactly), boundary truncation at several small caps, large-file summary, deletion, unchanged-content no-op, correct hunk headers
  • bun test src/plugins/verify-plugin.test.ts — edit_file and write_file results carry the diff, including new-file creation
  • bun test src/plugins/delete-file-plugin.test.ts — delete result carries removed content
  • bun test src/agent/apply-patch-diff.test.ts — Add/Update/Delete ops each surface their diff (Update is stubbed around a known read_file defect filed as CL-6966; not proof that path works in production, noted in the test)
  • bun test src/plugins src/agent src/subagent — full local sweep, 1158 pass

Surfaces the diff verify-plugin already computes when checking a write
landed, instead of discarding it. Bounded to a char cap so a whole-file
rewrite can't blow the result size.
@linear-code

linear-code Bot commented Aug 23, 2026

Copy link
Copy Markdown

CL-6962

- truncate() now reserves the truncation note's length within maxChars
  instead of appending after slicing, so the result never exceeds the cap.
- delete_file skips reading file content into memory above 256KB and
  reports a byte-count summary instead, so deleting a large file no
  longer buffers it just to produce a diff.
- toHunks()/formatHunk() now follow unified-diff convention for a
  zero-length side (start is one less than the adjacent line, not the
  line itself).
- Loosened delete-file-plugin.test.ts assertions to check the parts that
  matter instead of the exact (previously wrong) hunk header text.
- Documented that write_file gains a real extra pre-write read to source
  the diff's "before" content, while edit_file's read is reused.
- Noted in apply-patch-diff.test.ts that the Update File case stubs
  around a known read_file defect (CL-6966) and is not proof that path
  works in production.
@TheGreatAxios
TheGreatAxios merged commit 1675c8c into main Aug 23, 2026
5 checks passed
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