Community编程与开发github.com

系统性调试

用于在遇到任何Bug、测试失败或意外行为时,在提出修复方案前,先系统性地定位根本原因。

系统性调试 是什么?

这个技能提供了一个严格、多阶段的调试流程,旨在防止基于症状的、可能造成更多问题的临时修复。其核心理念是“在找到根本原因之前,绝不进行任何修复”。该技能将过程分为四个明确的阶段:根本原因调查(通过检查错误、复现问题、审查近期更改和追踪数据流)、模式分析(对比类似的工作代码)、假设与测试(应用科学方法)以及最终实施(在确保有失败的测试用例后,只实施单点修复)。它特别强调了“红旗”信号和常见的错误合理化现象,例如在时间压力下跳过步骤,或是在三次修复失败后仍然继续尝试——这种行为被视作架构问题的明确信号。该技能旨在为AI编码助手(如Claude Code、Cursor等)提供支持,帮助开发者和AI代理避免在未知领域中进行无意义的“猜测式”调试,将一种被验证有效的、基于证据的工程纪律转化为可执行的规范。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/alfathafp/portofolio-web-design/tree/HEAD/.agents/skills/systematic-debugging

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

系统性调试 是做什么的?

概述

核心原则: 在尝试任何修复之前,永远先找到根本原因。症状修复是失败。

违反本流程的字面意思,就是违反调试的精神。

铁律

未进行根本原因调查前,不得提出任何修复方案

如果你尚未完成第一阶段,就不能提出修复方案。

何时使用

适用于任何技术问题:

  • 测试失败
  • 生产环境中的Bug
  • 意外行为
  • 性能问题
  • 构建失败
  • 集成问题

以下情况尤其需要使用:

  • 时间紧迫(紧急情况容易让人想猜)
  • “就快速修复一下”看起来很明显
  • 你已经尝试过多种修复
  • 之前的修复没起作用
  • 你并未完全理解问题

以下情况不要跳过:

  • 问题看起来很简单(简单的Bug也有其根本原因)
  • 你很赶时间(匆忙保证返工)
  • 经理要求立刻修复(系统化比慌乱地反复试错更快)

四个阶段

在进入下一阶段前,你必须完成当前阶段的全部要求。

第一阶段:根本原因调查

在尝试任何修复之前:

  1. 仔细阅读错误信息
  • 不要跳过错误或警告
  • 它们通常包含精确的解决方案
  • 完整阅读堆栈跟踪信息
  • 记录行号、文件路径、错误代码
  1. 稳定复现问题
  • 你能可靠地触发它吗?
  • 确切的步骤是什么?
  • 它每次都发生吗?
  • 如果不可复现 → 收集更多数据,不要猜测
  1. 检查近期更改
  • 什么变化可能导致此问题?
  • Git diff、最近的提交
  • 新的依赖、配置更改
  • 环境差异
  1. 在多组件系统中收集证据

当系统有多个组件时(如CI → 构建 → 签名、API → 服务 → 数据库):

在提出修复方案前,添加诊断性监控:

对于每个组件边界:
  - 记录进入组件的数据
  - 记录离开组件的数据
  - 验证环境/配置的传播
  - 检查每一层的状态

运行一次以收集证据,找出问题出在哪里
然后分析证据,识别出故障组件
接着调查那个具体的组件

示例 (多层系统):

# 第1层:工作流
echo "=== 工作流中可用的密钥: ==="
echo "IDENTITY: $([ -n "${IDENTITY:-}" ] && echo 已设置 || echo 未设置)"

# 第2层:构建脚本
echo "=== 构建脚本中的环境变量: ==="
printenv IDENTITY >/dev/null 2>&1 && echo "IDENTITY 在环境中" || echo "IDENTITY 不在环境中"

# 第3层:签名脚本
echo "=== 钥匙串状态: ==="
security list-keychains
security find-identity -v

# 第4层:实际签名
codesign --sign "$IDENTITY" --verbose=4 "$APP"

这能揭示: 哪一层失败了(密钥→工作流 ✓、工作流→构建 ✗)

  1. 追踪数据流

当错误发生在调用栈深处时:

请参阅此目录中的 root-cause-tracing.md 以获取完整的逆向追踪技术。

快速版:

  • 错误的值从何而来?
  • 谁带着错误的值调用了这里?
  • 持续向上追踪,直到找到源头
  • 修复源头,而不是症状

第二阶段:模式分析

在修复前找到模式:

  1. 寻找工作示例
  • 在同一个代码库中找到类似的工作代码
  • 什么代码能工作,并且和出问题的代码类似?
  1. 与参考资料对比
  • 如果要实现某个模式,请完整阅读参考实现
  • 不要浏览——阅读每一行
  • 在应用之前,完全理解该模式
  1. 识别差异
  • 工作代码和错误代码之间有什么不同?
  • 列出每一个差异,无论多小
  • 不要认为“那不可能有关系”
  1. 理解依赖关系
  • 这需要哪些其他组件?
  • 需要哪些设置、配置、环境?
  • 它做了哪些假设?

第三阶段:假设与测试

科学方法:

  1. 形成单一假设
  • 明确陈述:“我认为X是根本原因,因为Y”
  • 写下来
  • 要具体,不要含糊
  1. 最小化测试
  • 进行最小的更改来验证假设
  • 一次只改变一个变量
  • 不要同时修复多个问题
  1. 验证后再继续
  • 成功了吗?是 → 进入第四阶段
  • 没成功?形成新的假设
  • 不要堆叠更多的修复
  1. 当你不确定时
  • 说“我不理解X”
  • 不要假装知道
  • 寻求帮助
  • 进一步研究

第四阶段:实施

修复根本原因,而不是症状:

  1. 创建失败的测试用例
  • 最简单的复现方式
  • 如果可能,创建自动化测试
  • 没有测试框架就写一次性测试脚本
  • 在修复前必须有此测试
  • 使用 superpowers:test-driven-development 技能来编写合适的失败测试
  1. 实施单一修复
  • 只整改已确定的根本原因
  • 一次只做一个更改
  • 不要做“既然我在改,就顺便……”的改进
  • 不要捆绑重构
  1. 验证修复
  • 测试现在通过了吗?
  • 其他测试没被破坏吗?
  • 问题真的解决了吗?
  • 在声称成功前,使用 superpowers:verification-before-completion 技能
  1. 如果修复不起作用
  • 停止
  • 数一数:你已经尝试过多少次修复?
  • 如果 < 3 次:回到第一阶段,根据新信息重新分析
  • 如果 ≥ 3 次:停止并质疑架构(如下方第5步)
  • 在没有讨论架构的情况下,不要尝试第4次修复
  1. 如果3次及以上的修复都失败:质疑架构

表明架构问题的模式:

  • 每次修复都会在不同地方揭示新的共享状态/耦合/问题
  • 修复需要“大规模重构”才能实施
  • 每次修复都会在其他地方产生新的症状

停止并质疑基础问题:

  • 这个模式从根本上是否健全?
  • 我们是否“因为惯性而勉强用它”?
  • 我们应该重构架构,还是继续修复症状?

在尝试更多修复前,与你的人类搭档讨论

这不是假设失败——这是架构错误。

红旗信号 - 停止并遵循流程

如果你发现自己在想:

  • “先快速修复,之后再来调查”
  • “就试试改X,看看行不行”
  • “做多个更改,然后跑测试”
  • “跳过测试,我自己手动验证”
  • “可能是X,让我修复它”
  • “我不完全理解,但这样也许可行”
  • “模式说是X,但我会用不同的方式适配”
  • “这里主要的问题有:[列出修复方案,但没有调查]”
  • 在追踪数据流之前就提出解决方案
  • “再试一次修复”(当已经尝试了2次及以上)
  • 每次修复都在不同地方揭示新问题

所有这些都意味着:停止。回到第一阶段。

如果3次及以上修复失败: 质疑架构(见第四阶段第5点)

你的人类搭档发出的“你做错了”的信号

留意这些重定向信号:

  • “那件事没有发生吗?” - 你在没有验证的情况下做了假设
  • “它会不会向我们展示……?” - 你应该已经添加了证据收集
  • “别猜了” - 你在没有理解的情况下提出修复
  • “深入思考这个” - 质疑基础,而不仅仅是症状
  • “我们卡住了?”(感到沮丧) - 你的方法不起作用

当你看到这些信号时: 停止。回到第一阶段。

常见的自我合理化

借口现实
“问题很简单,不需要流程”简单问题也有根本原因。对于简单Bug,流程很快。
“紧急情况,没时间走流程”系统性调试快于猜测式调试的反复试错。
“先试试这个,然后调查”第一次修复定下了基调。从一开始就做对。
“我会在确认修复有效后写测试”未经测试的修复站不住脚。先有测试才能证明它。
“一次做多个修复能省时间”无法隔离哪个修复有效。还会引入新Bug。
“参考太长了,我会自己适配这个模式”部分理解必定导致Bug。请完整阅读。
“我看到问题了,让我修复它”看到症状 ≠ 理解根本原因。
“再试一次修复”(在2次及以上失败后)3次及以上失败 = 架构问题。质疑模式,不要继续修复。

快速参考

阶段关键活动成功标准
1. 根本原因阅读错误、复现、检查更改、收集证据理解什么和为什么
2. 模式寻找工作示例、对比识别差异
3. 假设形成理论、最小化测试确认假设或形成新假设
4. 实施创建测试、修复、验证Bug已解决,测试通过

当流程揭示“没有根本原因”时

如果系统性的调查揭示问题确实是环境、时序或外部依赖导致的:

  1. 你已完成流程
  2. 记录你调查的内容
  3. 实施适当的处理(重试、超时、错误信息)
  4. 添加监控/日志记录,以便将来调查

但是: 95% 的“没有根本原因”的情况,都是调查不完整。

辅助技术

这些技术是系统性调试的一部分,可在本目录中找到:

  • root-cause-tracing.md - 通过调用栈逆向追踪Bug,找到原始触发器
  • defense-in-depth.md - 在找到根本原因后,在多层添加验证
  • condition-based-waiting.md - 用条件轮询替换任意超时

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

alfathafp/portofolio-web-design

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

alfathafp/portofolio-web-design

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

alfathafp/portofolio-web-design

Automates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.

alfathafp/portofolio-web-design

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

alfathafp/portofolio-web-design

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

alfathafp/portofolio-web-design

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

alfathafp/portofolio-web-design

Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

alfathafp/portofolio-web-design

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.

alfathafp/portofolio-web-design

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

alfathafp/portofolio-web-design

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.

alfathafp/portofolio-web-design

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

alfathafp/portofolio-web-design

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

alfathafp/portofolio-web-design

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

alfathafp/portofolio-web-design

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when you want every assumption cross-examined before proceeding, when stress-testing a plan for hidden failure modes, when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production auth, security-sensitive logic, a high-stakes migration, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

alfathafp/portofolio-web-design

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

alfathafp/portofolio-web-design

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

alfathafp/portofolio-web-design

Builds production-quality, accessible, responsive user-facing UIs. Use when building or modifying interfaces and pages, creating components, implementing layouts, meeting WCAG accessibility requirements, managing state, or when the output needs to look and feel production-quality rather than AI-generated.

alfathafp/portofolio-web-design

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.

alfathafp/portofolio-web-design

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

alfathafp/portofolio-web-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

相关技能