Systematic debugger

From findscripter/everything-skills · View interactive version

Systematic debugger is an AI agent skill from the GitHub repository findscripter/everything-skills. 当排查 bug、性能问题、崩溃或线上异常时使用;用科学方法分阶段定位并产出最小复现、根因结论与可验证修复;不适用于已知根因的直接改码或新功能开发;触发词:调试、debug、根因分析、root cause、复现、性能排查、内存泄漏、二分定位、git bisect

How to use this skill

Skill file

何时使用

适用:

不该用(负边界):

步骤

采用科学方法循环:观察 → 假设 → 实验 → 分析 → 重复,直到锁定根因。

  1. 复现(Reproduce):先确认能否稳定复现(总是/偶尔/随机?需要什么前置条件?他人能否复现?)。收敛为最小复现,剥离无关代码,记录精确步骤与环境。
  2. 收集信息(Gather):完整堆栈、错误码、日志;OS/运行时/依赖版本、环境变量;近期变更(git 历史、发布时间线、配置改动);影响范围(全量还是特定用户/浏览器/环境)。
  3. 形成假设(Hypothesize):问“改了什么 / 哪里不同(可用差分表对比 working vs broken)/ 哪一层可能失败(输入校验、业务逻辑、数据层、外部服务)”。
  4. 测试验证(Test & Verify):二分法(注释一半代码逐步收窄)、加日志(追踪变量与执行流)、隔离组件(mock 依赖单测)、对比 working/broken 的配置与数据。
  5. 修根因而非症状:定位后修复根本原因,并验证修复确实有效;移除临时调试日志。

指令

核心原则与硬约束(务必遵守):

二分定位回归(git bisect):

git bisect start
git bisect bad                # 当前提交有问题
git bisect good v1.0.0        # v1.0.0 是好的
# 测试 checkout 出的中间提交后:
git bisect good   # 正常
git bisect bad    # 仍有问题
git bisect reset  # 结束

卡住时的快速排查清单:

示例

按语言的断点与性能分析:

Python(pdb / breakpoint / cProfile):

def calculate_total(items):
    breakpoint()  # Python 3.7+,等价 pdb.set_trace()
    return sum(i.price * i.quantity for i in items)

# 异常事后调试
try:
    risky_operation()
except Exception:
    import pdb; pdb.post_mortem()

# 性能剖析,找最慢的 10 个
import cProfile, pstats
cProfile.run('slow_function()', 'profile_stats')
pstats.Stats('profile_stats').sort_stats('cumulative').print_stats(10)

JS/TS(DevTools 与 console):

debugger;                 // 条件断点:if (cond) debugger;
console.table(rows);      // 表格化
console.time('op'); /* ... */ console.timeEnd('op');
console.trace();          // 堆栈

Go(delve / pprof / panic 恢复):

// dlv debug main.go
defer func() {
    if r := recover(); r != nil { fmt.Println("Panic:", r); debug.PrintStack() }
}()
import _ "net/http/pprof" // 访问 /debug/pprof/

差分调试对比表(定位“哪里不同”):

| 维度 | Working | Broken |

| --- | --- | --- |

| 环境 | Development | Production |

| 版本 | 18.16.0 | 18.15.0 |

| 数据量 | 空库 | 100 万条 |

| 时间 | 白天 | 凌晨后 |

假设:可能与时区处理有关,重点查时间逻辑。

注意事项

互见


本条采编自 wshobson/agents(MIT)。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.