Here is a tragedy that every developer experiences when using AI:
You have a 400-line file that works beautifully. You just need to change one single line to fix a button color. You ask the AI: "Update the button color in this file."
The AI begins generating all 400 lines. Halfway through, it gets lazy and writes: // ... rest of your code remains unchanged .... You copy-paste it, and your entire application crashes!
The Catastrophe of Full-File Rewrites
When an AI regenerates a 400-line file, every single line is subject to probabilistic variance. It might accidentally rename a variable, delete your inline comments, or drop essential error-handling logic.
The Solution: The Surgical Diff Pattern
Do NOT rewrite the entire file.
Output ONLY the specific lines that need to change using a unified diff or search/replace block:
<<<<<<< SEARCH
const buttonColor = "blue";
=======
const buttonColor = "var(--accent-violet)";
>>>>>>> REPLACE
This ensures 99.9% of your codebase remains untouched, audited, and stable!