<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vasyl</title>
    <description>The latest articles on DEV Community by Vasyl (@vasyl_92cb4a6e255af8cb754).</description>
    <link>https://dev.to/vasyl_92cb4a6e255af8cb754</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3835947%2F363420f9-c497-4f62-9b19-92c8935dc0d3.jpg</url>
      <title>DEV Community: Vasyl</title>
      <link>https://dev.to/vasyl_92cb4a6e255af8cb754</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vasyl_92cb4a6e255af8cb754"/>
    <language>en</language>
    <item>
      <title>How I built an AI that patches code without rewriting files</title>
      <dc:creator>Vasyl</dc:creator>
      <pubDate>Fri, 20 Mar 2026 18:30:24 +0000</pubDate>
      <link>https://dev.to/vasyl_92cb4a6e255af8cb754/how-i-built-an-ai-that-patches-code-without-rewriting-files-3p3p</link>
      <guid>https://dev.to/vasyl_92cb4a6e255af8cb754/how-i-built-an-ai-that-patches-code-without-rewriting-files-3p3p</guid>
      <description>&lt;p&gt;Every time I asked an AI to fix a bug, it rewrote my entire file.&lt;/p&gt;

&lt;p&gt;I'd ask: "fix the empty list check on line 47."&lt;br&gt;
The AI would return: 300 lines of "improved" code.&lt;br&gt;
Half my carefully tuned logic — gone.&lt;/p&gt;

&lt;p&gt;This happened to me one too many times. So I built something different.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Problem with AI Code Tools
&lt;/h2&gt;

&lt;p&gt;Most AI coding assistants work like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You send the whole file&lt;/li&gt;
&lt;li&gt;AI rewrites the whole file&lt;/li&gt;
&lt;li&gt;You diff 300 lines to find the 2 that changed&lt;/li&gt;
&lt;li&gt;Something else broke that wasn't broken before&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Copilot, Cursor, and friends are great — but they all have this problem when you're working on existing code you care about.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Solution: Surgical SEARCH/REPLACE Patches
&lt;/h2&gt;

&lt;p&gt;I built &lt;strong&gt;AI Code Sherlock&lt;/strong&gt; around one core idea:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The AI should only touch the exact block that needs changing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Every response from the AI looks like this:&lt;br&gt;
[SEARCH_BLOCK]&lt;br&gt;
result = data[0]["value"]&lt;br&gt;
[REPLACE_BLOCK]&lt;br&gt;
if not data:&lt;br&gt;
return None&lt;br&gt;
result = data[0]["value"]&lt;br&gt;
[END_PATCH]&lt;/p&gt;

&lt;p&gt;The engine finds this exact string in your file, validates it appears exactly once, creates a backup, and replaces only that block. Nothing else is touched.&lt;/p&gt;

&lt;p&gt;If the search block isn't found — or matches more than once — the patch is rejected. No silent corruption.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Auto-Improve Pipeline
&lt;/h2&gt;

&lt;p&gt;This is where it gets interesting.&lt;/p&gt;

&lt;p&gt;You configure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Goal&lt;/strong&gt;: "achieve f1 &amp;gt; 0.85 on validation set"
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Script&lt;/strong&gt;: train_model.py&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strategy&lt;/strong&gt;: Safe Ratchet&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Max iterations&lt;/strong&gt;: 20&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then press Run and walk away.&lt;/p&gt;

&lt;p&gt;The pipeline:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Runs your script&lt;/li&gt;
&lt;li&gt;Reads stdout/stderr&lt;/li&gt;
&lt;li&gt;Extracts metrics&lt;/li&gt;
&lt;li&gt;Builds a prompt with context + history&lt;/li&gt;
&lt;li&gt;Gets a patch from the AI&lt;/li&gt;
&lt;li&gt;Validates syntax&lt;/li&gt;
&lt;li&gt;Applies the patch&lt;/li&gt;
&lt;li&gt;Re-runs the script&lt;/li&gt;
&lt;li&gt;Checks if metrics improved (Safe Ratchet mode)&lt;/li&gt;
&lt;li&gt;Repeats until goal is reached or iterations exhausted&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Real terminal output looks like this:&lt;br&gt;
[PIPELINE] Iteration 3/10  strategy=SAFE_RATCHET  goal="f1 &amp;gt; 0.85"&lt;br&gt;
[RUN]    python train_model.py → exit 0 (14.3s)&lt;br&gt;
precision=0.71  recall=0.68  f1=0.69&lt;br&gt;
[AI]     Analysing metrics... building patch...&lt;br&gt;
[APPLY]  ✓ Patch applied · syntax OK · backup created&lt;br&gt;
[RUN]    python train_model.py → exit 0 (13.8s)&lt;br&gt;
f1=0.73  ↑+0.04&lt;br&gt;
[RATCHET] metrics improved — continuing to iteration 4...&lt;/p&gt;
&lt;h2&gt;
  
  
  8 AI Strategies
&lt;/h2&gt;

&lt;p&gt;Different problems need different approaches:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Strategy&lt;/th&gt;
&lt;th&gt;When to use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🛡️ Conservative&lt;/td&gt;
&lt;td&gt;Only fix explicit errors&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;⚖️ Balanced&lt;/td&gt;
&lt;td&gt;Fix + moderate improvements (default)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🔥 Aggressive&lt;/td&gt;
&lt;td&gt;Maximum changes, refactor logic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🔒 Safe Ratchet&lt;/td&gt;
&lt;td&gt;Apply only if metrics improve&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🧭 Explorer&lt;/td&gt;
&lt;td&gt;Different approach every iteration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🔬 Hypothesis&lt;/td&gt;
&lt;td&gt;Form hypothesis → test → validate&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🎭 Ensemble&lt;/td&gt;
&lt;td&gt;Generate 3 variants, pick best&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📈 Exploit&lt;/td&gt;
&lt;td&gt;Double down on what worked&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Works 100% Offline with Ollama
&lt;/h2&gt;

&lt;p&gt;No API key required. Just run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ollama serve
ollama pull deepseek-coder-v2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And point AI Code Sherlock at localhost. Your code never leaves your machine.&lt;/p&gt;

&lt;p&gt;It also supports OpenAI, Gemini, Groq, Mistral — any OpenAI-compatible endpoint.&lt;/p&gt;

&lt;h2&gt;
  
  
  Consensus Engine
&lt;/h2&gt;

&lt;p&gt;Query multiple models at once and let them vote:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Vote mode&lt;/strong&gt;: patches agreed on by ≥N models win&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Best-of-N&lt;/strong&gt;: pick response with most valid patches
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Merge&lt;/strong&gt;: combine unique patches from all models&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Judge&lt;/strong&gt;: one model evaluates all responses and picks the best&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Error Map
&lt;/h2&gt;

&lt;p&gt;Every error gets stored with its confirmed solution. When the same error appears again, the AI sees: "this exact problem was fixed before — here's what worked."&lt;/p&gt;

&lt;p&gt;Avoid-patterns prevent the AI from repeating approaches that already failed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Technical Details
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Built with Python 3.11 + PyQt6&lt;/li&gt;
&lt;li&gt;Async subprocess runner with real-time stdout/stderr streaming&lt;/li&gt;
&lt;li&gt;AST-based context compression (120k tokens → 4k without losing signal)&lt;/li&gt;
&lt;li&gt;Unicode sanitizer strips zero-width spaces, BOM, smart quotes from AI responses&lt;/li&gt;
&lt;li&gt;Atomic settings save (corruption-proof)&lt;/li&gt;
&lt;li&gt;Version control: every patch backed up, full diff viewer, one-click restore&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try It
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;GitHub&lt;/strong&gt;: &lt;a href="https://github.com/signupss/ai-code-sherlock" rel="noopener noreferrer"&gt;https://github.com/signupss/ai-code-sherlock&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Website&lt;/strong&gt;: &lt;a href="https://codesherlock.dev" rel="noopener noreferrer"&gt;https://codesherlock.dev&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/signupss/ai-code-sherlock.git
&lt;span class="nb"&gt;cd &lt;/span&gt;ai-code-sherlock
pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
python main.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Free and open source under MIT License.&lt;/p&gt;




&lt;p&gt;Would love to hear what you think — especially if you've tried to build something similar or have ideas for the pipeline. What would make this useful for your workflow?&lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>ollama</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
