pit-of-success
它能做什么
它指导 AI 找出可能被误用的 API 调用、设置器和属性,然后把必要的行为移入共享代码。适用于审查或重构代码的开发者。
适用场景
- ✓当 API、设置器或组件属性存在一个自然调用会掉进去的陷阱时。
- ✓当你重构代码,使安全的路径成为默认路径时。
- ✓当你希望用一个共享实现替换重复的辅助函数或包装器时。
技能链接
https://github.com/trycompai/crm/blob/release/.agents/skills/pit-of-success/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“当有人传入 null 时,这个设置器会出错。你能修改代码,让普通的调用总是能正常工作吗?”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会找出公共入口的每个调用方,检查显而易见的调用是否会导致错误行为,然后把规则移入共享代码。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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.
常见问题
它只修复一个调用位置吗?
不是。如果 API 本身有问题,该技能要求修复共享的接缝,而不是修复某一个调用方。
它偏好哪种修复顺序?
它优先让现有 API 变得安全,然后收紧类型,再拆分 API,最后才添加辅助函数。
它如何证明修复有效?
它使用有针对性的测试或类型检查,证明显而易见的调用现在能正常工作,并通过搜索确认没有残留的旧调用方。
详情
作者的原始描述
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.
repo: trycompai/crm
热度
- GitHub 星标
- 12k
- 排名
- #11523
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
ai-elements
12k帮你的智能体用现成的组件构建 AI 聊天界面,包括对话、消息、工具显示和提示输入框。
ai-sdk
12k帮你的智能体使用 Vercel AI SDK 构建 AI 功能,包括文本生成、流式输出、工具调用和智能体。
better-accessibility
12k帮你的智能体让界面可以通过键盘和屏幕阅读器使用,涵盖焦点、标签、ARIA 和表单。
better-auth-best-practices
12k帮你的智能体按照官方文档步骤,在 TypeScript 应用中设置 Better Auth,实现登录、会话、OAuth 和插件。