跳到正文
Skillpedia
通用编程12k · #11523

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/trycompai/crm/blob/release/.agents/skills/pit-of-success/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“当有人传入 null 时,这个设置器会出错。你能修改代码,让普通的调用总是能正常工作吗?”

每周 5 个新技能,1 分钟读完。

工作原理

AI 会找出公共入口的每个调用方,检查显而易见的调用是否会导致错误行为,然后把规则移入共享代码。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Pit of Success

Make misuse hard and the obvious call correct.

Steps

  1. 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.
  2. 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.
  3. 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.
  4. Delete bypasses and duplicate meanings. Replace local wrappers, parallel helper names, and comments that explain the trap with one shared implementation at the seam.
  5. 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能