skills/debugging/bug-to-patch-generator/SKILL.md
Automatically synthesizes code patches to fix identified bugs, leveraging the bug location and surrounding context. Use when a bug has been localized and the user wants an automated fix, when generating candidate patches for review, or when the user asks to fix a specific bug.
npx skillsauth add santosomar/general-secure-coding-agent-skills bug-to-patch-generatorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Produce the minimal edit that makes the failing test pass without breaking anything else. The discipline is subtractive: most first-draft patches are too big, and every unnecessary line is a line a reviewer has to verify.
| Precondition | Why you need it | If missing |
| --------------------------- | ------------------------------------------------------- | --------------------------------------- |
| Fault location (file:line) | You need to know where to edit | → bug-localization |
| Failing test | You need a red→green signal | → bug-reproduction-test-generator |
| Green baseline | You need to know what "doesn't break anything" means | Run the full suite once, record result |
If you don't have all three, you are not patching a bug — you are guessing.
Match the fault to a fix family. Different families have different minimal-patch shapes.
| Fault class | Typical symptom | Minimal patch shape |
| ---------------------------- | ---------------------------------------- | --------------------------------------------- |
| Off-by-one | Loop over/under-runs by one | Change < ↔ <=, n ↔ n-1, ++i ↔ i++ |
| Missing null/empty guard | NPE / KeyError / index-out-of-bounds | One early-return or if (x == null) branch |
| Wrong operator | Inverted condition, swapped args | Single-token edit: && ↔ \|\|, swap two args |
| Wrong constant | Magic number is slightly wrong | One literal changes |
| Missing state update | Stale cache, unrotated log, unset flag | One statement added: the missing mutation |
| Wrong API call | Deprecated/misused library call | Replace call; may cascade to import/signature |
| Missing case | Unhandled enum branch / edge input | One branch added to a switch/match/if-chain |
| Resource leak | FD/connection/lock not released | Move into try/with; add finally/defer |
Start with the smallest family that could explain the symptom.
Write the minimal candidate for the classified family. Constraints:
== not is, use ==.Run validation in order of cost. Stop at the first failure.
| Gate | What it checks | On failure |
| ----------------------- | --------------------------------------------------- | ------------------------------------------ |
| Compile / typecheck | Patch is syntactically & type-valid | Revert; your classification is wrong |
| Failing test now passes | Patch actually fixes the bug | Wrong family — go back to Step 1 |
| Green baseline still green | No collateral damage | Shrink the patch; you changed too much |
| → behavior-preservation-checker | Semantic equivalence on unchanged paths | If time allows — catches subtle breakage |
Input:
src/pagination.py:47 in page_slice(items, page, per_page)test_last_page_partial — last page returns [] when it should return 2 itemsdef page_slice(items, page, per_page):
start = page * per_page
end = start + per_page
if end > len(items):
return [] # line 47
return items[start:end]
Classification: Missing case — but look closer. The guard end > len(items) isn't missing a case, it's wrong. The fault class is actually wrong operator: it should only bail when start is past the end, not end.
Minimal patch:
- if end > len(items):
- return []
+ if start >= len(items):
+ return []
One line. items[start:end] already handles end > len(items) correctly via Python's slice semantics.
Validation: test_last_page_partial passes; full suite green. Done.
bug-reproduction-test-generator to stabilize first.try/except to swallow the symptom. That's a bug in a trench coat.## Patch
<unified diff — minimal>
## Classification
<fault family from table>
## Validation
- [ ] compiles
- [ ] failing test → pass
- [ ] baseline suite → green
- [ ] behavior-preservation check (optional)
## Assumptions
<anything the patch relies on that isn't proven by the test>
development
Extracts human-readable pseudocode from a verified formal artifact (Dafny, Lean, TLA+) while preserving the verified properties as annotations, so the proof-carrying logic can be reimplemented in a production language. Use when porting verified code to an unverified target, when documenting what a formal spec actually does, or when handing a verified algorithm to an implementer.
development
Translates natural-language or pseudocode descriptions of concurrent and distributed systems into TLA+ specifications ready for the TLC model checker. Identifies state variables, actions, type invariants, safety properties, and liveness properties from the description. Use when formalizing a protocol, when the user describes a distributed algorithm to verify, when designing a consensus or locking scheme, or when starting formal verification of a concurrent system.
testing
Reduces a TLA+ model so TLC can actually check it — shrinks constants, adds state constraints, abstracts data, or applies symmetry — when the state space is too large to enumerate. Use when TLC runs out of memory, when checking takes hours, or when a spec works at N=2 and you need confidence at larger scale.
development
TLA+-specific instance of model-guided repair — reads a TLC error trace, identifies the enabling condition that should have been false, strengthens the corresponding action, and maps the fix to source code. Use when TLC reports an invariant violation or deadlock and you have the code-to-TLA+ mapping from extraction.