Debug — Unified Debug Command
Debug platform-specific issues with automatic platform detection.
Detect platform per skill-discovery protocol.
Execution
- Detect platform
- Route to platform-specific agent (read-only investigation tools preferred)
- Analyze error context, gather logs, identify root cause
- Explain root cause and suggest fix (do NOT auto-apply fix — that's
/fix)
Expertise
Systematic Debugging
- Understand: What's the symptom?
- Reproduce: Can you reproduce it?
- Isolate: What's the minimal case?
- Analyze: What's actually happening?
- Hypothesize: What could cause this?
- Verify: Does the fix work?
Log Analysis
- Parse error messages
- Follow stack traces
- Identify log patterns
- Contextual logging
Stack Trace Interpretation
- Read top-down
- Identify root cause frame
- Distinguish cause from symptom
- Async stack traces
Reproduction Strategies
- Minimal reproduction
- Environment matching
- Data setup
- Step reproduction
Root Cause Analysis
See problem-solving for root cause analysis techniques (5 Whys, bisection, inversion).
Fix Validation
- Regression testing
- Edge case testing
- Performance impact
- Side effect analysis
Patterns
Debug Logging
typescript
1console.log('[Feature]', { variable, state });
2console.debug('[Debug]', value);
3console.error('[Error]', error);
Error Boundaries
typescript
1class ErrorBoundary extends Component {
2 componentDidCatch(error, errorInfo) {
3 console.error('Error caught:', error, errorInfo);
4 }
5}
Debug Mode
typescript
1const DEBUG = process.env.DEBUG === 'true';
2if (DEBUG) console.debug('Debug info');
Structured Logging
typescript
1logger.info('User action', {
2 action: 'login',
3 userId: user.id,
4 timestamp: Date.now()
5});
Common Issues
TypeScript
- Type mismatches
- Missing type imports
- Any type issues
- Generic constraints
React
- Stale closures
- Missing dependencies
- Re-render loops
- State timing
Async
- Race conditions
- Promise rejection
- Missing await
- Callback hell
Defense-in-Depth Patterns
Validation Layers
- Input validation (reject invalid early)
- Business logic validation (enforce invariants)
- Output validation (verify results before return)
Error Handling Strategy
- Catch: Only where you can handle meaningfully
- Transform: Convert to domain-specific errors
- Log: Include context (not just message)
- Propagate: Let upstream handle if you can't
Assertion vs Exception
- Assertions: Programmer errors (should never happen)
- Exceptions: Runtime problems (can happen legitimately)
State Diagram Tracing
When debugging state-related bugs (unexpected transitions, stuck states, race conditions):
- Draw the ACTUAL state machine from code — read every
if/switch/state= and extract what ACTUALLY happens
- Draw the EXPECTED state machine from requirements or docs
- Overlay and diff — mismatches reveal the bug:
- Missing transitions (no path from state A to B)
- Unguarded transitions (state changes without preconditions)
- Dead states (reachable but no exit — component gets "stuck")
- Race conditions (two transitions competing for same state)
ACTUAL: [LOADING] ──(timeout)──▸ [LOADING] ← stuck! no error path
EXPECTED: [LOADING] ──(timeout)──▸ [ERROR] ──(retry)──▸ [LOADING]
MISSING: timeout → ERROR transition
Applies to: React useState/useReducer, iOS view lifecycle, Android Compose state, async/Promise chains, WebSocket connections.
See plan/references/state-machine-guide.md for notation and common patterns.
Verification Checklist
- Browser DevTools (breakpoints, profiling)
- Node debugger (--inspect)
- Console logging (structured)
- Source maps (correct line numbers)
- Test suite (regression testing)
Debugging Discipline
IRON LAW: NO FIXES WITHOUT ROOT CAUSE FIRST.
Applying a fix before identifying root cause is not debugging — it is guessing. Guesses compound into technical debt.
See verification-before-completion skill for anti-rationalization table, red flags, and the full verification gate protocol.
Sub-Skill Routing
| Intent | Sub-Skill | When |
|---|
| Fix broken code | fix | /fix, "fix this", error/crash/failing |
| Fix deeply | fix-deep | /fix-deep, complex multi-file bugs |
| Fix CI pipeline | fix-ci | /fix-ci, CI/CD failures, build pipeline |
| Fix UI issues | fix-ui | /fix-ui, visual bugs, layout broken |
knowledge-retrieval — Knowledge storage format and docs/ directory
knowledge-capture — Post-task capture workflow
problem-solving — Root cause analysis techniques
error-recovery — Error handling and recovery patterns
verification-before-completion — Verify fixes before claiming done
auto-improvement — Error metrics auto-captured by session-metrics hook on Stop
References
references/debugging-flow.dot — Authoritative debugging process flowchart
references/condition-based-waiting.md — Patterns for replacing sleep() with condition polling
<issue>$ARGUMENTS</issue>
IMPORTANT: Analyze the skills catalog and activate needed skills for the detected platform.