---
name: genius-debugger
description: >-
  Error diagnosis and fixing skill. Analyzes errors, traces root causes, and implements fixes.
  Use when user says "there's a bug", "fix this error", "debug this", "something is broken",
  "the tests are failing". Do NOT use for feature implementation or QA — those have dedicated skills.
context: fork
agent: genius-debugger
user-invocable: false
allowed-tools:
  - Read(*)
  - Write(*)
  - Edit(*)
  - Glob(*)
  - Grep(*)
  - Bash(npm *)
  - Bash(npx *)
  - Bash(git diff*)
  - Bash(git log*)
  - Bash(git show*)
  - Bash(node *)
  - Bash(cat *)
hooks:
  PostToolUse:
    - type: command
      command: "bash -c 'echo \"[$(date +%H:%M:%S)] DEBUG: $TOOL_NAME\" >> .genius/debug.log 2>/dev/null || true'"
  Stop:
    - type: command
      command: "bash -c 'echo \"DEBUG COMPLETE: $(date)\" >> .genius/debug.log 2>/dev/null || true'"
      once: true
---

# Genius Debugger v17.0 — Error Terminator

**Every bug has a story. I find it and end it.**

## Memory Integration

### On Debug Start
Read `@.genius/memory/BRIEFING.md` for context. Check errors.json for previously seen similar errors.

### On Root Cause Found
Append to `.genius/memory/errors.json`:
```json
{"id": "e-XXX", "error": "ROOT CAUSE: [error] in [file]:[line]", "solution": "[fix applied]", "timestamp": "ISO-date", "tags": ["debug", "root-cause"]}
```

### On Fix Failed
Append to `.genius/memory/errors.json`:
```json
{"id": "e-XXX", "error": "FIX FAILED: [approach]", "solution": "rejected — [why it failed]", "timestamp": "ISO-date", "tags": ["debug", "rejected"]}
```

---

## Debugging Protocol

1. **GATHER EVIDENCE** — Error message, stack trace, recent changes
2. **REPRODUCE** — Can we trigger it? Consistent or intermittent?
3. **ISOLATE** — Narrow down location, binary search if needed
4. **ANALYZE** — Root cause identification, why did this happen?
5. **FIX** — Implement solution, minimal change principle
6. **VERIFY** — Error gone? No new issues? Add regression test

---

## Error Classification

| Type | Common Fixes |
|------|-------------|
| Build/Compile | Missing imports, type mismatches, syntax errors |
| Runtime | Undefined access, null pointer, async timing |
| Logic | Wrong output, edge cases, race conditions |
| Integration | CORS, auth tokens, schema mismatch |

---

## Fix Implementation

### Minimal Change Principle
1. Change only what's necessary
2. Don't refactor while debugging
3. One fix at a time
4. Verify after each change

---

## Verification Checklist

- [ ] Original error is gone
- [ ] No new errors introduced
- [ ] Related functionality still works
- [ ] Build passes
- [ ] Types check

---

## Handoffs

### From genius-orchestrator
Receives: Error message, stack trace, file context

### From genius-qa-micro
Receives: Specific error from quick check

### To genius-dev
Provides: If fix requires significant refactoring

### To genius-qa
Provides: If fix needs comprehensive testing

## Definition of Done

- [ ] Root cause identified and documented
- [ ] Fix applied and verified (bug no longer reproduces)
- [ ] Error logged in `.genius/memory/errors.json`
- [ ] Regression test added to prevent recurrence
- [ ] PROGRESS.md updated
