codely-openspec-spec-create-from-code
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese🧬 How to create OpenSpec specs from existing code
🧬 如何从现有代码创建 OpenSpec 规范
An OpenSpec change can only or a requirement that already lives in . Behaviour built before the team adopted OpenSpec has no spec, so every change over it lands as and the spec forgets what was there before. This skill writes that missing baseline: main specs for behaviour that already ships.
MODIFYREMOVEopenspec/specs/ADDEDThe baseline is the spec OpenSpec would have archived if the feature had been built with it: intent that was implemented and verified. Every sentence holds against the code, and every requirement is something someone meant. A baseline that flatters the code is worse than none, because the next proposal builds on it.
一次 OpenSpec 变更只能 或 已经位于 中的 requirement。团队采用 OpenSpec 之前构建的行为没有 spec,因此对这些行为的每次变更都会作为 落地,而 spec 会忘记之前已有的内容。该 skill 会写入这份缺失的 baseline:为已经交付的行为创建主 spec。
MODIFYREMOVEopenspec/specs/ADDEDbaseline 是:如果该功能从一开始就使用 OpenSpec 构建,OpenSpec 本应归档的 spec:已经实现并验证的 intent。每句话都能与代码相符,每条 requirement 都代表某个人确实有意实现的内容。一个只会粉饰代码的 baseline 比没有 baseline 更糟糕,因为下一份 proposal 会以它为基础。
📥 Input
📥 输入
The argument is free text. Read it as one of these:
| Input | Example | Scope |
|---|---|---|
| Nothing, or a question about what lacks a spec | | The inventory in |
| A capability | | That capability. |
| A change the user is about to make | | The current behaviour the change will touch. The new behaviour belongs to the change, not to the baseline. |
| A path or a screen | | The business concept that path serves, traced back from it. |
参数是自由文本。按以下类型之一理解:
| 输入 | 示例 | 范围 |
|---|---|---|
| 无,或询问哪些功能缺少 spec | | |
| 一项 capability | | 该 capability。 |
| 用户即将进行的变更 | | 该变更将触及的当前行为。新行为属于变更,而不属于 baseline。 |
| 路径或界面 | | 从该路径反向追踪出的业务概念。 |
🪜 Steps
🪜 步骤
1. Check the preconditions
1. 检查前置条件
- Run . If the CLI is missing, stop and ask the user to install it.
openspec --version - Locate the OpenSpec root: the folder holding
openspec/. When that config points to a store, the specs live in the store.config.yaml - Read the of
context:. It sets the language of the specs; without it, write them in English.config.yaml
Done when the CLI answers and you know the folder the specs go into.
- 执行 。如果 CLI 缺失,停止并请用户安装。
openspec --version - 定位 OpenSpec 根目录,即包含 的
config.yaml文件夹。当该 config 指向一个 store 时,spec 位于该 store 中。openspec/ - 读取 的
config.yaml。它设置 spec 的语言;如果没有它,则用英语编写。context:
完成条件:CLI 已正常响应,并且已确定 spec 的存放目录。
2. Bound the capability
2. 确定 capability 边界
- A capability is one folder under , named in kebab-case after the business concept (
openspec/specs/,checkout), never after a class, a table or a folder.order-management - Run . When an existing spec already covers part of the behaviour, extend that spec.
openspec list --specs - When the areas involved share no business concept, they are several capabilities: propose the split to the user.
- For a change the user is about to make, list the existing behaviour it will touch and confirm that scope with the user.
- Run and look for
openspec listin each active change. When an active change has a delta on the capability, warn the user that extending the main spec can break that change's archive, and ask whether to go on.openspec/changes/<change>/specs/<capability>/
Done when the user has confirmed every capability, and whether each one is new or extended.
- capability 是 下的一个文件夹,以业务概念命名并使用 kebab-case(如
openspec/specs/、checkout),绝不能按 class、table 或 folder 命名。order-management - 执行 。如果现有 spec 已覆盖部分行为,则扩展该 spec。
openspec list --specs - 如果涉及的领域不共享任何业务概念,则它们属于多个 capability:向用户建议拆分。
- 对于用户即将进行的变更,列出该变更将触及的当前行为,并与用户确认范围。
- 执行 ,并在每个 active change 中查找
openspec list。如果 active change 对该 capability 有 delta,应警告用户:扩展主 spec 可能破坏该变更的归档,并询问是否继续。openspec/changes/<change>/specs/<capability>/
完成条件:用户已确认每个 capability,以及每个 capability 是新建还是扩展。
3. Collect the evidence
3. 收集证据
Read and dispatch the subagents it describes. Delegate the exploration: your job is to cross the reports, not to read the codebase.
resources/evidence-guidelines.mdDone when every area of every capability has a report, and every candidate behaviour in it carries its evidence.
读取 ,并按照其中描述分派 subagents。将探索工作委托出去:你的职责是交叉核对报告,而不是亲自阅读代码库。
resources/evidence-guidelines.md完成条件:每个 capability 的每个领域都有报告,且其中每个候选行为都附有证据。
4. Classify
4. 分类
Sort every candidate behaviour into one of the four cases of . Then ask the user about all the ambiguous candidates in a single round, as that file describes. Use the tool to question the user if you have one.
resources/evidence-guidelines.mdDone when every candidate has a case, and every ambiguous one has the user's verdict.
将每个候选行为归入 所述四种情况之一。随后按照该文件的说明,在一轮中向用户询问所有 ambiguous 候选。如果有可用的提问工具,就使用它向用户提问。
resources/evidence-guidelines.md完成条件:每个候选行为都有明确分类,且每个 ambiguous 候选都有用户的判断。
5. Write the specs
5. 编写 spec
Read and write with the intended and verified behaviour only.
resources/spec-format.mdopenspec/specs/<capability>/spec.mdWhen you extend an existing spec, add requirements and scenarios and keep every existing one exactly as it is. An existing requirement that the code contradicts is drift: it goes to the report, and changing it is the job of an OpenSpec change.
Done when every intended and verified candidate is a requirement or a scenario in the spec.
读取 ,并编写 ,只写入符合 intent 且已验证的行为。
resources/spec-format.mdopenspec/specs/<capability>/spec.md扩展现有 spec 时,添加 requirements 和 scenarios,并原样保留所有现有内容。如果现有 requirement 与代码矛盾,则属于 drift:将其记录到报告中;修改它是 OpenSpec change 的职责。
完成条件:每个符合 intent 且已验证的候选行为,都已成为 spec 中的一条 requirement 或 scenario。
6. Validate
6. 验证
Run for every spec you wrote, fix every error and warning, and rerun.
openspec validate <capability> --type spec --strictDone when every spec passes strict validation.
对每个编写的 spec 执行 ,修复所有错误和警告,然后重新运行。
openspec validate <capability> --type spec --strict完成条件:每个 spec 都通过严格验证。
7. Report and close
7. 报告并结束
Answer in the language the user writes in. Report, in this order:
- The specs written or extended, each with its capability id.
- The scope decisions: splits, extensions, what you left out of the scope and why.
- The candidates you left out of the spec, each with its case and its evidence.
- The drift between existing requirements and the code.
Do not paraphrase the specs: the files are the deliverable. Then close with the steps that this run's facts call for, in this order, translated to the user's language:
-
Always, the review:
Review <spec paths>: they come from the code, and from now on agents will treat them as the truth. Once you agree with them, commit them with `/codely-git-conventional-commit`. -
When the input was a change the user is about to make, the way back to it:
With the baseline ready, go on with your change: `/openspec-explore <the change, as the user described it>` -
When you left a bug out of the spec, one ready-to-paste command per bug, with the evidence inline:
⚠️ <n> inconsistencies left out of the spec. To fix one: - `/openspec-explore <the behaviour the intent asks for> fails when <the case that breaks> (<file:line>; <the test that covers it, or "no test covers it">)`
使用用户所用的语言回答。按以下顺序报告:
- 已编写或扩展的 spec,并附上每个 spec 的 capability id。
- 范围决策:拆分、扩展、排除在范围外的内容及其原因。
- 未纳入 spec 的候选行为,以及每个候选行为所属的情况和证据。
- 现有 requirement 与代码之间的 drift。
不要转述 spec:文件才是交付物。然后按照此次运行的事实所要求的顺序收尾:
-
始终执行审阅:
Review <spec paths>: they come from the code, and from now on agents will treat them as the truth. Once you agree with them, commit them with `/codely-git-conventional-commit`. -
当输入是用户即将进行的变更时,返回该变更:
With the baseline ready, go on with your change: `/openspec-explore <the change, as the user described it>` -
当有 bug 未纳入 spec 时,为每个 bug 提供一条可直接粘贴的命令,并在其中附上证据:
⚠️ <n> inconsistencies left out of the spec. To fix one: - `/openspec-explore <the behaviour the intent asks for>` fails when <the case that breaks> (<file:line>; <the test that covers it, or "no test covers it">)
🧱 Boundaries
🧱 边界
- Write only under . Changes,
openspec/specs/and the code stay as they are.config.yaml - Leave the specs uncommitted: committing comes after the user's review.
- 只能写入 。change、
openspec/specs/和代码保持原样。config.yaml - 保持 spec 未提交:提交应在用户审阅后进行。