Agent Skills
› trycompai/crm
› pit-of-success
pit-of-success
GitHub指导通过重构API、Hooks或组件Props消除设计缺陷,使正确用法成为默认路径。核心步骤包括识别公共接口、执行脚坑测试、将不变量移入接口层并删除绕过逻辑,确保调用者无需额外注意即可安全使用。
触发场景
代码审查发现API存在易误用风险
需要重构导致状态不一致的接口
消除开发中的常见陷阱和隐藏依赖
安装
npx skills add trycompai/crm --skill pit-of-success -g -y
SKILL.md
Frontmatter
{
"name": "pit-of-success",
"description": "Review or refactor code so the correct behavior is the default path; use when APIs, setters, hooks, helpers, or component props have footguns where a natural call bypasses required semantics.",
"user-invocable": true
}
Pit of Success
Make misuse hard and the obvious call correct.
Steps
- Find the public seam being used: exported function, hook return value, setter, component prop, route body, schema, or command. Then search every caller of that seam. Done when you know the natural call a future maintainer would write.
- Run the footgun test: “If someone does the obvious thing without knowing the hidden helper or convention, does behavior break?” Examples:
setSelection(null)should mean the product’s normal clear behavior; a schema should reject states the UI never wants; a prop should not require sibling props in the right combo. - Move the invariant into the seam. Prefer, in order:
- make the existing API do the safe thing,
- narrow the type/schema so bad states cannot be represented,
- rename/split the API so the dangerous path is explicit,
- only then add a helper, and only if all natural callers use it.
- Delete bypasses and duplicate meanings. Replace local wrappers, parallel helper names, and comments that explain the trap with one shared implementation at the seam.
- Prove the pit with one check: a focused test or type/schema assertion showing the obvious call now preserves behavior, plus a grep confirming no caller still uses the old footgun.
Rules
- Do not fix only the named callsite. If the seam is wrong, fix the seam.
- Do not rely on “remember to call this helper first” when callers can still call the raw API.
- Do not add comments as a substitute for making misuse impossible or obvious.
- Keep the diff boring: one invariant, one owner, no speculative abstraction.
- If compatibility prevents changing the seam, name the dangerous API accordingly and expose a safe default API beside it.
版本历史
- c26a08d 当前 2026-08-08 08:04


