migrate-to-spec
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseConvert an existing hand-written CLAUDE.md (or AGENTS.md) into a typed file. This is the incremental adoption path — you keep your existing instruction file as the starting point and get type safety going forward.
CLAUDE.md.spec.tsDon't need full TypeScript? A typed spec is the deepest commitment level. If the user only wants verified rules without a build step, point them at markdown mode first: inlinecomments (Level 0) or a<!-- vigiles:enforce ... -->YAML frontmatter block withvigiles:for editor autocomplete (Level 1). Both are verified byvigiles generate-schemawith the same engine as a spec. Seevigiles lint. Migrate to a spec only when they want compiler-grade guarantees.docs/markdown-mode.md
将现有的手写CLAUDE.md(或AGENTS.md)转换为带类型的文件。这是一条渐进式采用路径——你可以保留现有的指令文件作为起点,同时在后续获得类型安全性。
CLAUDE.md.spec.ts不需要完整的TypeScript? 带类型的规范是最高级别的承诺。如果用户只想要无需构建步骤的已验证规则,先引导他们使用markdown模式:内嵌的注释(0级),或是带有<!-- vigiles:enforce ... -->的YAML前置块,配合vigiles:实现编辑器自动补全(1级)。这两种方式都能通过vigiles generate-schema进行验证,使用的引擎与规范文件相同。详见vigiles lint。只有当用户需要编译器级别的保障时,再迁移到规范文件。docs/markdown-mode.md
Instructions
操作步骤
Step 1: Read the Existing File
步骤1:读取现有文件
Read the target instruction file (default: in the repo root). If the user specified a path, use that.
CLAUDE.mdAlso check if vigiles is installed: look for in devDependencies. If not, suggest:
vigilespackage.jsonbash
npm install -D vigiles读取目标指令文件(默认:仓库根目录下的)。如果用户指定了路径,则使用该路径。
CLAUDE.md同时检查是否已安装vigiles:查看的devDependencies中是否有。如果没有,建议执行:
package.jsonvigilesbash
npm install -D vigilesStep 2: Parse the Structure
步骤2:解析结构
Identify these sections in the markdown:
- Commands — lines like or
`npm run build` — description- `command` — description - Key files — lines like listing important files
`src/foo.ts` — description - Rules — headings with
###or**Enforced by:**annotations**Guidance only** - Prose sections — everything else (positioning, architecture, principles, etc.)
For each rule, classify it:
- Has linter/rule`
**Enforced by:** \enforce("linter/rule", "why")`→ - Has code-review`
**Enforced by:** \guidance("...")`or similar non-linter → - Has →
**Guidance only**guidance("...") - Has no annotation → mark as TODO for the user to classify
识别markdown中的以下部分:
- 命令 —— 类似或
`npm run build` —— 描述的行- `command` —— 描述 - 关键文件 —— 类似的行,列出重要文件
`src/foo.ts` —— 描述 - 规则 —— 带有或
**Enforced by:**注释的**Guidance only**标题### - 散文式章节 —— 其他所有内容(定位、架构、原则等)
对每条规则进行分类:
- 带有linter/rule`
**Enforced by:** \enforce("linter/rule", "why")`→ - 带有code-review`
**Enforced by:** \guidance("...")`或类似非linter的注释 → - 带有→
**Guidance only**guidance("...") - 无注释 → 标记为TODO,供用户后续分类
Step 3: Generate the Spec File
步骤3:生成规范文件
Create (or the appropriate name based on the source file) with this structure:
CLAUDE.md.spec.tstypescript
import {
claude,
enforce,
guidance,
check,
every,
file,
cmd,
ref,
instructions,
} from "vigiles/spec";
export default claude({
sections: {
// Prose sections here
},
keyFiles: {
// Key files here
},
commands: {
// Commands here
},
rules: {
// Rules here
},
});Important guidelines:
- Use refs in sections where file paths appear in backticks — this enables stale reference detection
file() - Use refs for any
cmd()commands mentioned in sectionsnpm run - Convert code-review`
**Enforced by:** \guidance()` — code review is not a mechanical enforcementrules to - For rules with no annotation, add a comment
// TODO: classify as enforce() or guidance() - Keep rule IDs as kebab-case versions of the heading text
- Preserve the text as the second argument to
**Why:**orenforce()guidance() - If sections reference other files or skills, use for cross-references
ref()
创建(或根据源文件命名的对应文件),结构如下:
CLAUDE.md.spec.tstypescript
import {
claude,
enforce,
guidance,
check,
every,
file,
cmd,
ref,
instructions,
} from "vigiles/spec";
export default claude({
sections: {
// 散文式章节放在这里
},
keyFiles: {
// 关键文件放在这里
},
commands: {
// 命令放在这里
},
rules: {
// 规则放在这里
},
});重要指南:
- 在包含反引号包裹的文件路径的章节中,使用引用——这能启用过时引用检测
file() - 对章节中提到的任何命令,使用
npm run引用cmd() - 将带有code-review`
**Enforced by:** \guidance()`——代码审查不属于机械性强制执行的规则转换为 - 对无注释的规则,添加注释
// TODO: classify as enforce() or guidance() - 将规则ID保留为标题文本的kebab-case格式
- 保留文本作为
**Why:**或enforce()的第二个参数guidance() - 如果章节引用了其他文件或技能,使用进行交叉引用
ref()
Step 4: Verify the Spec Compiles
步骤4:验证规范文件可编译
Run:
bash
npm run build
npx vigiles compile CLAUDE.md.spec.tsCompare the compiled output against the original file. Key differences are expected (formatting, section ordering), but all rules, commands, key files, and prose content should be preserved.
运行:
bash
npm run build
npx vigiles compile CLAUDE.md.spec.ts将编译输出与原始文件进行对比。格式、章节顺序等方面的差异是正常的,但所有规则、命令、关键文件和散文内容都应被保留。
Step 5: Present the Result
步骤5:呈现结果
Show the user:
- The generated spec file
- How many rules were converted (enforce vs guidance vs TODO)
- How many file/cmd refs were added for stale reference detection
- The command to compile:
npx vigiles compile - The command to verify:
npx vigiles check
Ask if they want you to write the file. If yes, also suggest adding to or updating CI to run and .
.gitignorevigiles compilevigiles check向用户展示:
- 生成的规范文件
- 已转换的规则数量(enforce、guidance、TODO分别有多少)
- 为过时引用检测添加的file/cmd引用数量
- 编译命令:
npx vigiles compile - 验证命令:
npx vigiles check
询问用户是否需要写入该文件。如果需要,还建议添加到或更新CI以运行和。
.gitignorevigiles compilevigiles checkStep 6: Optional — Set Up CI
步骤6:可选——设置CI
If the user wants CI integration, suggest adding to their GitHub Actions workflow:
yaml
- name: Compile specs
run: npx vigiles compile
- name: Verify integrity
run: npx vigiles checkOr using the vigiles GitHub Action:
yaml
- uses: zernie/vigiles@main
with:
command: check如果用户需要CI集成,建议添加到GitHub Actions工作流中:
yaml
- name: Compile specs
run: npx vigiles compile
- name: Verify integrity
run: npx vigiles check或使用vigiles GitHub Action:
yaml
- uses: zernie/vigiles@main
with:
command: check