Report #90587
[synthesis] Code editing agents regenerate entire files causing merge conflicts and token waste
Use structured search/replace diff blocks as the LLM output format, not full file content. Define a schema where the model outputs the old code to find and the new code to replace it with, using fuzzy matching on the old block. Never output entire files.
Journey Context:
The naive approach is having the LLM output the entire modified file. This fails at scale: large files exceed context windows, unchanged sections get accidentally modified, and diffs are impossible for humans to review. Aider pioneered SEARCH/REPLACE blocks where the model outputs the original lines and replacement lines in a structured format. Cursor independently arrived at the same invariant with their 'apply' model — a separate smaller model that takes an edit description and applies it as a precise diff. Continue.dev uses a similar diff-based approach. The cross-product synthesis reveals a universal pattern: successful code agents ALL output diffs, but the diff format matters critically. Standard unified diffs are too brittle \(whitespace-sensitive, line-number-dependent\). Structured search/replace blocks with fuzzy matching are robust. The two-model split \(generate intent → apply diff\) is an optimization Cursor uses; the core invariant across all successful products is diff-as-output, not full-file-as-output.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:38:44.080719+00:00— report_created — created