humanerd-drew/opencode-drewgent/python-large-file-patch-drewgent

Claude Code and agent skill by humanerd-drew/opencode-drewgent

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

How to patch large Python files in the {{AGENT_NAME}} codebase. Covers the dual-file layout (runtime ~/.{{AGENT_NAME_LOWER}}/agent/ vs source ~/.{{AGENT_NAME_LOWER}}/source/{{AGENT_NAME_LOWER}}-agent/), diagnose-fallback when direct patch fails, and the copy-sync protocol to keep both copies aligned.

Install

npx vskill@latest install humanerd-drew/opencode-drewgent/python-large-file-patch-drewgent

SKILL.md

The same SKILL.md was published earlier as humanerd-drew/opencode-drewgent/python-large-file-patch-drewgent.

Skill: Patching Large Python Files in {{AGENT_NAME}}

When to Use

When you need to edit a specific function or code block inside a large Python file (500+ lines) in the {{AGENT_NAME}} codebase (signal_processor.py, run_agent.py, gateway/run.py, etc.), and direct patch fails due to text pattern mismatch.

The Problem

patch relies on exact string matching. Large files with complex docstrings (especially with newlines and special characters) often don't match what you expect from reading partial snippets. You get "old_string not found" even when the function exists.

CRITICAL: Dual-File Layout (Runtime vs Source)

{{AGENT_NAME}} has two copies of the agent code:

CopyPathPurpose
Runtime~/.{{AGENT_NAME_LOWER}}/agent/What Python actually imports at runtime
Source~/.{{AGENT_NAME_LOWER}}/source/{{AGENT_NAME_LOWER}}-agent/agent/Git-tracked development copy

When you patched a file in the source/ copy but nothing changed, it's because Python loaded from ~/.{{AGENT_NAME_LOWER}}/agent/ instead. The two copies can and do diverge.

Patching Protocol
  1. Identify which copy is live before editing:

``python python3 -c "import module_name; print(module_name.__file__)" ``

  1. Patch the runtime copy first (~/.{{AGENT_NAME_LOWER}}/agent/...) — that's where the effect is immediate.
  1. Sync the source copy after the fix to keep them aligned:

``bash cp ~/.{{AGENT_NAME_LOWER}}/agent/patched_file.py ~/.{{AGENT_NAME_LOWER}}/source/{{AGENT_NAME_LOWER}}-agent/agent/patched_file.py ``

  1. Verify with an import and test call before declaring done.

Solution: Python Patch Script with Diagnostic Output

When patch fails, use execute_code to:

  1. First read the file and locate the exact text with in operator
  2. Print diagnostics so you know exactly what to match
  3. Apply with content.replace(old, new, 1) — the 1 limit prevents accidental multi-match
  4. Write back and verify
python
with open('/path/to/file.py') as f:
content = f.read()
old1 = ''' def _on_dangerous_op(self, event: BrainEvent) -> None:
"""Handle dangerous.op'''
if old1 not in content:
import re
match = re.search(r'def _on_dangerous_op.*?(?=\n def )', content, re.DOTALL)
if match:
print("FOUND at char", match.start())
print("Actual text:", repr(match.group()[:200]))
else:
print("ERROR: pattern not found")
else:
content = content.replace(old1, new1, 1)
print("Patch OK")
with open('/path/to/file.py', 'w') as f:
f.write(content)

Key Rules

  1. Always use `1` in `replace(old, new, 1)` — prevents replacing the same pattern multiple times accidentally
  2. Search before patching — use in operator to confirm exact text exists before replacing
  3. Use `re.DOTALL` for multi-line matches — docstrings and indented blocks span lines
  4. Print `repr()` of found text — reveals hidden characters (\n, \r, trailing spaces) that break exact matching
  5. Match from unique anchor to unique anchor — not just the function header alone; include enough context to be unique
  6. Patch both copies — runtime first, then sync source. Patching only the source has no effect.

{{AGENT_NAME}} File Paths (both copies)

Runtime (active) — ~/.{{AGENT_NAME_LOWER}}/:

  • agent/auxiliary_client.py (~2127 lines)
  • agent/title_generator.py
  • agent/signal_processor.py
  • gateway/run.py (~8700 lines)
  • run_agent.py
  • {{AGENT_NAME_LOWER}}_cli/auth.py

Source (git-versioned) — ~/.{{AGENT_NAME_LOWER}}/source/{{AGENT_NAME_LOWER}}-agent/:

  • agent/auxiliary_client.py
  • agent/signal_processor.py
  • agent/prompt_builder.py
  • run_agent.py
  • gateway/run.py

Anti-Patterns

  • Don't use cat or head to read files before patching — use read_file with offset/limit
  • Don't patch only the source copy and expect the runtime to change — patch both
  • Don't try to match just """docstring""" alone — docstrings often have newlines and vary in wording
  • Don't use replace_all=True unless you intentionally want to replace every occurrence

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/humanerd-drew/opencode-drewgent/python-large-file-patch-drewgent/badge)](https://verified-skill.com/skills/humanerd-drew/opencode-drewgent/python-large-file-patch-drewgent)

Something wrong with this skill or its page? Tell us.