|
| 1 | +# Deep Code CLI Agent Skills 指南 |
| 2 | + |
| 3 | +## 概述 |
| 4 | + |
| 5 | +适合写成 skill 的内容通常具备以下特点: |
| 6 | + |
| 7 | +- 会重复使用,例如固定的代码审查流程、发布流程或文档生成流程 |
| 8 | +- 需要较长的说明,不适合每次都粘贴到对话中 |
| 9 | +- 需要配套资源,例如模板、脚本、schema、示例或参考文档 |
| 10 | +- 需要明确触发条件,例如“处理 PDF 表单”或“为本项目生成数据库迁移” |
| 11 | + |
| 12 | +不适合写成 skill 的内容: |
| 13 | + |
| 14 | +- 一次性的任务要求 |
| 15 | +- 当前仓库的短规则,此类内容更适合写入 `AGENTS.md` |
| 16 | +- 需要实时连接外部系统的能力,此类能力更适合通过 MCP 提供工具 |
| 17 | + |
| 18 | +## 扫描位置 |
| 19 | + |
| 20 | +Deep Code CLI 会按以下顺序扫描 skills。相同 `name` 的 skill 只保留优先级最高的一个。 |
| 21 | + |
| 22 | +| 优先级 | Scope | Path | 用途 | |
| 23 | +| ------ | ------- | --------------------- | ---- | |
| 24 | +| 1 | Project | `./.deepcode/skills/` | Deep Code 项目级原生位置 | |
| 25 | +| 2 | Project | `./.agents/skills/` | 项目级跨客户端互操作位置 | |
| 26 | +| 3 | User | `~/.deepcode/skills/` | Deep Code 用户级原生位置 | |
| 27 | +| 4 | User | `~/.agents/skills/` | 用户级跨客户端互操作位置 | |
| 28 | +| 5 | Global | `built-in` | Deep Code 内置 skills | |
| 29 | + |
| 30 | +目录结构示例: |
| 31 | + |
| 32 | +```text |
| 33 | +.deepcode/ |
| 34 | +└── skills/ |
| 35 | + └── code-review/ |
| 36 | + ├── SKILL.md |
| 37 | + ├── checklist.md |
| 38 | + └── scripts/ |
| 39 | + └── collect-diff.sh |
| 40 | +``` |
| 41 | + |
| 42 | +## 最小 Skill |
| 43 | + |
| 44 | +每个 skill 必须放在独立目录中,并包含 `SKILL.md`。 |
| 45 | + |
| 46 | +```markdown |
| 47 | +--- |
| 48 | +name: code-review |
| 49 | +description: Review code changes for correctness, regressions, security risks, and missing tests. Use when the user asks for a review, PR review, diff review, or pre-merge check. |
| 50 | +--- |
| 51 | + |
| 52 | +# Code Review |
| 53 | + |
| 54 | +Use a code review mindset. Prioritize bugs, behavioral regressions, security issues, |
| 55 | +and missing tests over style comments. |
| 56 | + |
| 57 | +## Workflow |
| 58 | + |
| 59 | +1. Inspect the diff and relevant surrounding code. |
| 60 | +2. List findings first, ordered by severity. |
| 61 | +3. Include file and line references for every finding. |
| 62 | +4. If there are no findings, say so and mention residual risks or test gaps. |
| 63 | +``` |
| 64 | + |
| 65 | +## `SKILL.md` Frontmatter |
| 66 | + |
| 67 | +Deep Code CLI reads the YAML frontmatter at the top of `SKILL.md`. |
| 68 | + |
| 69 | +| 字段 | 必填 | Deep Code 行为 | 建议 | |
| 70 | +| ---- | ---- | -------------- | ---- | |
| 71 | +| `name` | 建议必填 | 作为 skill 的唯一名称。缺失时使用目录名,并把 `_` 转成 `-`。 | 使用小写字母、数字和连字符。保持与目录名一致。 | |
| 72 | +| `description` | 建议必填 | 用于自动匹配任务,也显示在 `/skills` 和斜杠菜单中。 | 写清楚 skill 做什么、何时使用、常见触发词。 | |
| 73 | +| `metadata.allow-implicit-invocation` | 可选 | 设置为 `false` 时,不参与自动匹配;仍可手动选择。 | 用于只想手动调用的 skill。 | |
| 74 | + |
| 75 | +示例: |
| 76 | + |
| 77 | +```yaml |
| 78 | +--- |
| 79 | +name: db-migration |
| 80 | +description: Create and review database migrations for this project. Use when the user asks to add columns, change schema, write migrations, or validate rollback behavior. |
| 81 | +metadata: |
| 82 | + allow-implicit-invocation: false |
| 83 | +--- |
| 84 | +``` |
| 85 | + |
| 86 | +> Deep Code CLI 当前只解释上表中的字段。其他 frontmatter 字段可用于跨客户端互操作或文档说明,但不会自动限制 Deep Code 的工具权限。 |
| 87 | +
|
| 88 | +## 写好 `description` |
| 89 | + |
| 90 | +`description` 是最重要的发现信号。Deep Code 会在自动匹配阶段只把 skill 的 `name` 和 `description` 交给模型判断,因此描述越具体,匹配越可靠。 |
| 91 | + |
| 92 | +推荐结构: |
| 93 | + |
| 94 | +```text |
| 95 | +<这个 skill 做什么>. Use when <任务类型、文件类型、领域、用户常见说法或触发词>. |
| 96 | +``` |
| 97 | + |
| 98 | +好的示例: |
| 99 | + |
| 100 | +```yaml |
| 101 | +description: Extract tables from PDF files, fill PDF forms, and merge documents. Use when working with PDFs, forms, invoices, statements, or document extraction. |
| 102 | +``` |
| 103 | +
|
| 104 | +```yaml |
| 105 | +description: Generate Lessweb routes, services, and Pydantic request models. Use when editing Lessweb projects, adding @Get/@Post endpoints, configuring IOC modules, or updating OpenAPI output. |
| 106 | +``` |
| 107 | +
|
| 108 | +避免: |
| 109 | +
|
| 110 | +```yaml |
| 111 | +description: Helps with documents |
| 112 | +description: Useful project skill |
| 113 | +description: Tooling instructions |
| 114 | +``` |
| 115 | +
|
| 116 | +检查清单: |
| 117 | +
|
| 118 | +- 是否说明了具体能力,而不是只写主题名 |
| 119 | +- 是否说明了何时使用,而不是只写结果 |
| 120 | +- 是否包含用户可能输入的关键词 |
| 121 | +- 是否包含相关文件类型、框架名、命令名或领域名 |
| 122 | +- 是否避免覆盖过宽,导致无关任务也触发 |
| 123 | +
|
| 124 | +## Skill 正文结构 |
| 125 | +
|
| 126 | +`SKILL.md` 的正文应面向 agent,而不是面向普通读者。写法要直接、可执行、可验证。 |
| 127 | + |
| 128 | +推荐结构: |
| 129 | + |
| 130 | +```markdown |
| 131 | +# Skill Name |
| 132 | +
|
| 133 | +Briefly state what this skill is for. |
| 134 | +
|
| 135 | +## When to use |
| 136 | +
|
| 137 | +- Use when ... |
| 138 | +- Do not use when ... |
| 139 | +
|
| 140 | +## Workflow |
| 141 | +
|
| 142 | +1. Read ... |
| 143 | +2. Run ... |
| 144 | +3. Edit ... |
| 145 | +4. Verify ... |
| 146 | +
|
| 147 | +## Rules |
| 148 | +
|
| 149 | +- Preserve ... |
| 150 | +- Never ... |
| 151 | +- Ask the user when ... |
| 152 | +
|
| 153 | +## Examples |
| 154 | +
|
| 155 | +... |
| 156 | +``` |
| 157 | + |
| 158 | +写作原则: |
| 159 | + |
| 160 | +- 使用命令式步骤,例如“Read the schema first”或“Run tests after editing” |
| 161 | +- 把必须遵守的约束写成明确规则 |
| 162 | +- 对高风险操作写清楚边界,例如删除文件、迁移数据、发送请求 |
| 163 | +- 对常见分支写出决策规则,例如“如果没有配置文件,先搜索默认路径” |
| 164 | +- 避免把大量参考资料全部塞进 `SKILL.md` |
| 165 | + |
| 166 | +## 附加资源 |
| 167 | + |
| 168 | +一个 skill 可以包含 `SKILL.md` 之外的文件: |
| 169 | + |
| 170 | +```text |
| 171 | +my-skill/ |
| 172 | +├── SKILL.md |
| 173 | +├── references/ |
| 174 | +│ └── api.md |
| 175 | +├── examples/ |
| 176 | +│ └── request.json |
| 177 | +├── scripts/ |
| 178 | +│ └── validate.py |
| 179 | +└── templates/ |
| 180 | + └── report.md |
| 181 | +``` |
| 182 | + |
| 183 | +如果某些内容会让 `SKILL.md` 过长或难以阅读,可以放到附加文件中: |
| 184 | + |
| 185 | +- `references/` 放长文档、规范、API 说明 |
| 186 | +- `examples/` 放输入输出样例 |
| 187 | +- `scripts/` 放可复用脚本 |
| 188 | +- `templates/` 放文档或代码模板 |
| 189 | +- 在 `SKILL.md` 中说明什么时候需要使用这些附加文件 |
| 190 | + |
| 191 | +示例: |
| 192 | + |
| 193 | +```markdown |
| 194 | +## Workflow |
| 195 | +
|
| 196 | +1. Read `references/schema.md` before changing generated types. |
| 197 | +2. Use `templates/migration.sql` when creating a new migration. |
| 198 | +3. Run `python scripts/check_migration.py <file>` before reporting completion. |
| 199 | +``` |
| 200 | + |
| 201 | +## 调用方式 |
| 202 | + |
| 203 | +Deep Code CLI 支持自动和手动两种调用方式。 |
| 204 | + |
| 205 | +### 自动调用 |
| 206 | + |
| 207 | +每次用户输入后,Deep Code 会根据可用 skills 的 `name` 和 `description` 判断哪些 skill 与任务匹配。匹配到的 skill 会被加载到当前会话中。 |
| 208 | + |
| 209 | +自动调用规则: |
| 210 | + |
| 211 | +- 已加载的 skill 不会在同一会话中重复加载 |
| 212 | +- `metadata.allow-implicit-invocation: false` 的 skill 不会自动加载 |
| 213 | +- 自动匹配会结合当前 `AGENTS.md` 指令 |
| 214 | +- 如果没有匹配项,则不加载 skill |
| 215 | + |
| 216 | +### 手动调用 |
| 217 | + |
| 218 | +你可以在输入框中使用 `/` 打开 skills / 命令菜单,选择某个 skill;也可以使用 `/skills` 查看可用 skills。 |
| 219 | + |
| 220 | +常用命令: |
| 221 | + |
| 222 | +| 命令 | 作用 | |
| 223 | +| ---- | ---- | |
| 224 | +| `/` | 打开 skills / 命令菜单 | |
| 225 | +| `/skills` | 列出可用 skills | |
| 226 | +| `/<skill-name>` | 从菜单中选择对应 skill | |
| 227 | + |
| 228 | +## 启用和禁用 |
| 229 | + |
| 230 | +使用 `settings.json` 的 `enabledSkills` 可以按 skill 名称启用或禁用 skill。 |
| 231 | + |
| 232 | +```json |
| 233 | +{ |
| 234 | + "enabledSkills": { |
| 235 | + "code-review": true, |
| 236 | + "db-migration": false |
| 237 | + } |
| 238 | +} |
| 239 | +``` |
| 240 | + |
| 241 | +规则: |
| 242 | + |
| 243 | +- 未配置的 skill 默认启用 |
| 244 | +- 设置为 `false` 会隐藏所有扫描位置中同名的 skill |
| 245 | +- 项目设置会按 skill 覆盖用户设置 |
| 246 | + |
| 247 | +更多配置说明请参考 [configuration.md](configuration.md)。 |
| 248 | + |
| 249 | +## 与 `AGENTS.md`、MCP 的区别 |
| 250 | + |
| 251 | +| 机制 | 适合放什么 | 不适合放什么 | |
| 252 | +| ---- | ---------- | ------------ | |
| 253 | +| `AGENTS.md` | 当前仓库的长期规则、代码风格、测试命令、协作约定 | 可复用的复杂工作流或跨项目工具说明 | |
| 254 | +| Agent Skill | 可复用工作流、领域知识、模板、脚本、参考资料 | 只对当前一次任务生效的临时要求 | |
| 255 | +| MCP | 外部系统能力、实时数据、浏览器、数据库、GitHub 等工具调用 | 纯文本流程说明 | |
| 256 | + |
| 257 | +常见组合: |
| 258 | + |
| 259 | +- 把项目规则写进 `AGENTS.md` |
| 260 | +- 把可复用流程写成 skill |
| 261 | +- 把需要执行外部动作的能力接入 MCP |
| 262 | + |
| 263 | +## 编写示例:项目发布 Skill |
| 264 | + |
| 265 | +```markdown |
| 266 | +--- |
| 267 | +name: release-check |
| 268 | +description: Prepare and verify a project release. Use when the user asks to release, publish, bump version, update changelog, or run pre-release checks. |
| 269 | +--- |
| 270 | + |
| 271 | +# Release Check |
| 272 | + |
| 273 | +Use this skill to prepare a safe release for this repository. |
| 274 | + |
| 275 | +## Workflow |
| 276 | + |
| 277 | +1. Read `package.json` and the existing changelog. |
| 278 | +2. Inspect commits or diffs since the previous release tag. |
| 279 | +3. Update version and changelog only when the user explicitly asks. |
| 280 | +4. Run the project test and build commands. |
| 281 | +5. Report the version, changed files, verification results, and remaining risks. |
| 282 | + |
| 283 | +## Rules |
| 284 | + |
| 285 | +- Do not publish packages unless the user explicitly asks. |
| 286 | +- Do not create or push git tags without explicit approval. |
| 287 | +- Preserve existing changelog style. |
| 288 | +``` |
| 289 | + |
| 290 | +## 故障排查 |
| 291 | + |
| 292 | +### `/skills` 中看不到 skill |
| 293 | + |
| 294 | +检查: |
| 295 | + |
| 296 | +1. 目录是否位于 Deep Code 扫描位置之一 |
| 297 | +2. 文件名是否为 `SKILL.md` |
| 298 | +3. `SKILL.md` 是否在独立 skill 目录中,例如 `.deepcode/skills/my-skill/SKILL.md` |
| 299 | +4. `enabledSkills` 是否把该 skill 设置为 `false` |
| 300 | +5. 是否存在同名 skill 被更高优先级位置覆盖 |
| 301 | + |
| 302 | +### 自动调用不稳定 |
| 303 | + |
| 304 | +检查: |
| 305 | + |
| 306 | +1. `description` 是否包含清晰的使用场景和触发词 |
| 307 | +2. skill 是否过宽,导致模型难以判断边界 |
| 308 | +3. 是否设置了 `metadata.allow-implicit-invocation: false` |
| 309 | +4. 用户请求是否需要更明确地提到该 skill 的领域或文件类型 |
| 310 | + |
| 311 | +### Skill 内容过长 |
| 312 | + |
| 313 | +建议: |
| 314 | + |
| 315 | +1. 保留 `SKILL.md` 中的核心流程和规则 |
| 316 | +2. 把长文档移到 `references/` |
| 317 | +3. 把重复命令移到 `scripts/` |
| 318 | +4. 在 `SKILL.md` 中说明何时读取相关文件 |
| 319 | + |
| 320 | +## 参考 |
| 321 | + |
| 322 | +- [Agent Skills Specification](https://agentskills.io/specification) |
0 commit comments