代码前规格

yannikzz2026-10-27查看 1786复制 1562

在实现之前保持一份书面规范来约束它。文档先改,代码随后跟进;实现暴露出的漏洞以规则形式写回,而非悄悄打补丁;被推翻的结论移入附录而非删除。当一个项目已有代码本应遵守的规范、且变更请求正在到来时使用。

Download (.md)

📘如何使用这个技能

  1. 1
    复制技能内容·点击上方「Copy SKILL.md」复制全部内容,或 Download 下载到本地
  2. 2
    打开你的 AI 客户端·支持 Claude Code、Trae、Cursor、ChatGPT、DeepSeek、Kimi 等任意 AI 助手
  3. 3
    粘贴为系统提示/知识文件·Claude Code:放入 .claude/skills/ 目录;普通对话:作为首条消息发送并说「请严格按这份技能文档执行」
  4. 4
    直接提出你的需求·AI 会按技能定义的工作流、格式和约束来处理,无需再解释背景

💡 提示:技能生效后,每次对话只需一句需求,AI 会按 SKILL.md 的流程执行。

SKILL.md2616 chars
---
name: spec-before-code
description: Keep a written specification ahead of the implementation it governs. Documents change first and code follows; holes the implementation exposes are written back as rules rather than patched silently; overturned conclusions move to an appendix instead of being deleted. Use when a project has a spec that code is supposed to obey, and change requests are arriving.
---

# Spec before code

The spec is a constraint on future work, not a description of existing work. The moment code leads and the document follows, it has quietly become the latter.

## Handling a change request

Once the user sees something running, change requests arrive. For each one:

1. **First judge whether it belongs in the spec at all.** Recording "right-align it" or "add a button" verbatim is nearly worthless; the value is in the **rule it forces**. Ask: what constraint is behind this request, and would it still hold under different surface choices?
2. **Name the existing clause it collides with.** New requests frequently contradict prohibitions you wrote yourself — surface that, then change the prohibition or the request. **Never let both stand.**
3. **Documents change first, code follows.** Always.
4. **When overturning an old conclusion, don't delete it.** Move it to the *Overturned* appendix with the reasoning, or to a decision record. Which of the two, and why the appendix is allowed to exist at all, is `decision-record`'s call — not restated here, because the reason moved there and a second copy of it would drift.
5. **Report precisely what changed**: which sections, which new prohibitions, what followed in the code.

## Building the thing exposes the spec's holes

This is the part people skip. Implementing a spec surfaces questions the spec never answered — a case that was never decided, a combination nobody walked through. That exposure is **the point**, not an interruption.

When it happens: **write the rule into the document first, then write the code.** Never quietly add a rule to the code that the document doesn't state. A rule that lives only in code is a rule the next agent will overwrite without knowing it existed.

(Detecting drift *after* the fact is a different job with a different owner. This skill is only about staying ahead of it while you work.)

## When you were wrong earlier

If you discover mid-implementation that something you said earlier was inaccurate — you promised a property the design can't actually deliver, say — **say so and correct it**. Do not leave the wrong conclusion standing in the document because correcting it is awkward.
来源:skillsdirectory

评论0

登录后参与评论

还没有评论,来抢沙发吧