| name | debug-probe |
| description | Hypothesis-driven runtime debugging with precise instrumentation. Use when debugging bugs, anomalies, or unexpected behavior where static code analysis is insufficient. 6-phase loop: hypothesize โ instrument โ reproduce โ converge โ fix โ clean up. Triggers on: debug, diagnose, broken, bug, not working, unexpected behavior, investigate, root cause, probe. |
Debug Probe
Quick Start
When you hit a bug that reading code can't resolve:
- Hypothesize โ Read source, generate 2-4 falsifiable hypotheses
- Instrument โ Insert minimal logging (2-4 points per hypothesis), tag
[DIAG_<topic>]
- Collect โ Build โ user reproduces โ user exports logs
- Converge โ Match logs to hypotheses โ confirm root cause
- Fix โ Minimal fix โ verify with user
- Clean up โ Remove ALL instrumentation, confirm build passes
Never skip to fixing. Always clean up after.
The 6 Phases
Phase 1: Hypothesize
Read relevant source code. Generate 2-4 testable hypotheses:
[H1] Root cause may be X โ if true, log would show Y
[H2] Root cause may be Z โ if true, log would show W
Share hypotheses with user before touching code.
Phase 2: Instrument
Rules:
- Only instrument to test hypotheses โ no fishing expeditions
- Tag format:
[DIAG_<topic>] (short topic like auth, render, state)
- 2-4 instrumentation points per hypothesis
- Mark ALL temporary code:
// DIAG: remove after debug (adapt comment syntax to language)
- Set up a diagnostic buffer (pick from TEMPLATES.md)
Use diagLog('H1', 'key=val', ...) โ outputs to both console and an in-memory buffer so users can export all logs at once after reproducing the bug.
Phase 3: Collect
- Build & deploy
- User reproduces the bug
- User exports logs (dump function, console output, log file, etc.)
- Group logs by hypothesis tag (
[DIAG][H1], [DIAG][H2])
- If expected paths aren't hit โ is instrumentation on the right branch? โ adjust and rebuild
Phase 4: Converge
| Situation | Action |
|---|
| Logs confirm a hypothesis | Confirmed root cause โ Phase 5 |
| All hypotheses refuted | New hypotheses from log clues โ Phase 2 |
| Insufficient data | More precise instrumentation โ Phase 2 |
Max 2-3 iterations before escalating.
Phase 5: Fix & Verify
- Minimal fix targeting confirmed root cause
- Build โ user verifies fix works
- Fix fails โ keep key instrumentation, return to Phase 1
- Fix works โ Phase 6
Phase 6: Clean Up
Mandatory. Search for DIAG: remove after debug and:
- Remove all temporary instrumentation code
- Remove all diagnostic imports
- Remove diagnostic buffer file if no longer referenced
- Build to confirm compilation passes
- Tell user: instrumentation removed, only fix remains
Anti-Patterns
- โ Skip hypotheses, jump straight to "fixing"
- โ Instrument 10+ points โ precision beats coverage
- โ Dump entire objects โ signal drowns in noise
- โ Forget Phase 6 cleanup โ instrumentation rots
- โ Claim "done" without user verification
- โ Use raw
console.log / print โ use the diag buffer pattern