AgentSkillsCN

Fix Bug

修复 Bug

SKILL.md

/fix-bug — Structured Bug Fix Workflow

Systematic approach to diagnosing and fixing bugs with TDD regression testing.


Steps

Phase 1: Diagnosis

  1. Gather information — ask the user:

    • What is the expected behavior?
    • What is the actual behavior?
    • Steps to reproduce?
    • When did it start? (recent change? always broken?)
    • Any error messages or logs?
  2. Reproduce the bug — write a test that demonstrates the failure:

    • The test MUST fail before the fix
    • The test describes the correct behavior
    • Name it clearly: test_[scenario]_should_[expected_behavior]
  3. Run the test — confirm it FAILS for the RIGHT reason

  4. Root cause analysis — investigate:

    • Read the relevant code
    • Trace the execution path
    • Identify where behavior diverges from expectation
    • Document the root cause (not just the symptom)

Phase 2: Fix

  1. Plan the fix — for non-trivial bugs:

    • Save plan to working/plans/YYYY-MM-DD_fix-description.md
    • Describe the root cause and the fix approach
  2. Implement the fix — minimal change that addresses the root cause

    • Fix the root cause, not the symptom
    • Don't refactor unrelated code in the same change
  3. Run the regression test — confirm it now PASSES

  4. Run full suitemake check — ensure no regressions

Phase 3: Review

  1. Spawn review subagents using the Task tool:
code
Task(subagent_type="senior-code-reviewer",
     prompt="<content of .claude/agents/code-reviewer.md>\n\n
     Review this bug fix:\n{changed_files}\n
     Root cause: {root_cause}\n
     Verify the fix addresses the root cause, not just the symptom.")

Task(subagent_type="senior-code-reviewer",
     prompt="<content of .claude/agents/test-reviewer.md>\n\n
     Review the regression test for this bug fix:\n{test_files}\n
     Verify the test would catch a recurrence of this bug.")
  1. Verifymake check passes after any review fixes

Phase 4: Delivery

  1. Present summary:

    • Root cause explanation
    • What was changed (minimal diff)
    • Regression test added
    • Full suite results
  2. Commit — with conventional commit message:

    code
    fix(scope): short description
    
    Root cause: [explanation]
    Regression test: [test name]
    
    Closes #[issue]
    

Rules

  • ALWAYS write a regression test BEFORE fixing
  • The test must FAIL before the fix and PASS after
  • Minimal change: fix the bug, don't refactor surrounding code
  • Commit the test WITH the fix — they travel together

Options

  • /fix-bug [issue number or description] — start with context
  • /fix-bug — interactive, asks for bug description