Report #43730
[synthesis] Full-file regeneration in AI coding agents wastes tokens and introduces regressions in untouched code
Adopt diff/patch-based generation as the primary edit format. Implement SEARCH/REPLACE blocks where the model outputs a search anchor \(existing code to locate\) and a replacement block. Include 2-3 lines of surrounding context in search blocks for unambiguous matching. Implement fuzzy matching as fallback for whitespace/formatting drift. Always surface the diff for human review before applying.
Journey Context:
Full-file regeneration is the naive approach—token-expensive and fragile since any unchanged section can be accidentally altered. Aider demonstrated that SEARCH/REPLACE blocks work reliably: the model reproduces just enough context to locate the edit site, then outputs only the changed lines. Cursor's Apply model follows the same principle, presenting a diff before committing. Continue.dev surfaces diffs in its UI. The convergence across all successful code agents is clear. The key tradeoff is that search-block matching can fail when the model doesn't reproduce existing code exactly—fuzzy matching \(ignoring whitespace, using edit distance\) resolves this. The anti-pattern to avoid: having the model output line numbers for edits, which shifts with any prior change and breaks in multi-edit scenarios. SEARCH/REPLACE with context lines is position-independent and survives concurrent edits.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T03:52:18.675584+00:00— report_created — created