
How I built an AI that patches code without rewriting files
Every time I asked an AI to fix a bug, it rewrote my entire file. I'd ask: "fix the empty list check on line 47." The AI would return: 300 lines of "improved" code. Half my carefully tuned logic — gone. This happened to me one too many times. So I built something different. The Problem with AI Code Tools Most AI coding assistants work like this: You send the whole file AI rewrites the whole file You diff 300 lines to find the 2 that changed Something else broke that wasn't broken before Copilot, Cursor, and friends are great — but they all have this problem when you're working on existing code you care about. The Solution: Surgical SEARCH/REPLACE Patches I built AI Code Sherlock around one core idea: The AI should only touch the exact block that needs changing. Every response from the AI looks like this: [SEARCH_BLOCK] result = data[0]["value"] [REPLACE_BLOCK] if not data: return None result = data[0]["value"] [END_PATCH] The engine finds this exact string in your file, validates it ap
Continue reading on Dev.to Python
Opens in a new tab

