@wwkit/harness 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/extract.md +2 -14
- package/agents/lint.md +368 -0
- package/agents/pyit.md +361 -0
- package/agents/pyut.md +347 -0
- package/agents/query.md +2 -14
- package/agents/revise.md +2 -14
- package/agents/work.md +631 -0
- package/commands/fix.md +77 -0
- package/commands/git-sync.md +218 -0
- package/commands/net-port.md +364 -0
- package/commands/pyit.md +6 -0
- package/commands/pyut.md +6 -0
- package/commands/resume.md +104 -0
- package/package.json +4 -2
- package/plugins/work-bootstrap.js +77 -0
- package/scripts/work-review-package +50 -0
- package/scripts/work-task-brief +27 -0
- package/scripts/work-workspace +31 -0
- package/skills/better-skill/SKILL.md +124 -0
- package/skills/blame-skill/SKILL.md +201 -0
- package/skills/lint-ai-fix/SKILL.md +141 -0
- package/skills/lint-config-setup/SKILL.md +106 -0
- package/skills/lint-config-setup/references/languages/js.md +110 -0
- package/skills/lint-config-setup/references/languages/py.md +89 -0
- package/skills/lint-env-ensure/SKILL.md +92 -0
- package/skills/lint-env-ensure/references/config.md +65 -0
- package/skills/lint-language-detect/SKILL.md +79 -0
- package/skills/lint-language-detect/references/detect-language.js +65 -0
- package/skills/lint-rules-analyze/SKILL.md +129 -0
- package/skills/lint-suitability-check/SKILL.md +84 -0
- package/skills/lint-tool-fix/SKILL.md +94 -0
- package/skills/new-skill/SKILL.md +227 -0
- package/skills/new-skill/references/template.md +53 -0
- package/skills/new-skill/references/workflow-patterns.md +104 -0
- package/skills/pytest-case-create/SKILL.md +327 -0
- package/skills/pytest-case-create/references/test-standards.md +244 -0
- package/skills/pytest-case-fix/SKILL.md +274 -0
- package/skills/pytest-coverage-analyze/SKILL.md +226 -0
- package/skills/pytest-coverage-analyze/references/scoring-rules.md +57 -0
- package/skills/pytest-env-ensure/SKILL.md +198 -0
- package/skills/pytest-env-ensure/references/config.md +145 -0
- package/skills/pytest-execute/SKILL.md +155 -0
- package/skills/pytest-sample/SKILL.md +164 -0
- package/skills/pytest-sample/references/src/pytest-sample/Calculator.py +67 -0
- package/skills/pytest-sample/references/src/pytest-sample/ConfigManager.py +68 -0
- package/skills/pytest-sample/references/src/pytest-sample/FileProcessor.py +53 -0
- package/skills/pytest-sample/references/src/pytest-sample/OrderService.py +82 -0
- package/skills/pytest-sample/references/src/pytest-sample/TokenGenerator.py +50 -0
- package/skills/pytest-sample/references/src/pytest-sample/UserService.py +45 -0
- package/skills/pytest-sample/references/src/pytest-sample/__init__.py +0 -0
- package/skills/pytest-suitability-check/SKILL.md +224 -0
- package/skills/read-docs/SKILL.md +134 -0
- package/skills/read-docs/references/opencode/agents/cases.md +206 -0
- package/skills/read-docs/references/opencode/agents/design-pattern.md +47 -0
- package/skills/read-docs/references/opencode/agents/detail.md +191 -0
- package/skills/read-docs/references/opencode/agents/examples.md +100 -0
- package/skills/read-docs/references/opencode/agents/index.md +309 -0
- package/skills/read-docs/references/opencode/agents/parallel-dispatch.md +149 -0
- package/skills/read-docs/references/opencode/agents/subagent-internals.md +217 -0
- package/skills/read-docs/references/opencode/agents/workflow.md +161 -0
- package/skills/read-docs/references/opencode/cli/commands/acp.md +32 -0
- package/skills/read-docs/references/opencode/cli/commands/agent.md +16 -0
- package/skills/read-docs/references/opencode/cli/commands/attach.md +20 -0
- package/skills/read-docs/references/opencode/cli/commands/mcp.md +37 -0
- package/skills/read-docs/references/opencode/cli/commands/others.md +49 -0
- package/skills/read-docs/references/opencode/cli/commands/plugin.md +13 -0
- package/skills/read-docs/references/opencode/cli/commands/provider.md +44 -0
- package/skills/read-docs/references/opencode/cli/commands/run.md +81 -0
- package/skills/read-docs/references/opencode/cli/commands/serve.md +84 -0
- package/skills/read-docs/references/opencode/cli/commands/session.md +38 -0
- package/skills/read-docs/references/opencode/cli/commands/web.md +15 -0
- package/skills/read-docs/references/opencode/cli/env.md +39 -0
- package/skills/read-docs/references/opencode/cli/index.md +19 -0
- package/skills/read-docs/references/opencode/cli/tui.md +35 -0
- package/skills/read-docs/references/opencode/commands/examples.md +42 -0
- package/skills/read-docs/references/opencode/commands/index.md +185 -0
- package/skills/read-docs/references/opencode/config/provider.md +152 -0
- package/skills/read-docs/references/opencode/formatter/index.md +71 -0
- package/skills/read-docs/references/opencode/guide/config.md +419 -0
- package/skills/read-docs/references/opencode/guide/formatters.md +70 -0
- package/skills/read-docs/references/opencode/guide/index.md +37 -0
- package/skills/read-docs/references/opencode/guide/providers.md +31 -0
- package/skills/read-docs/references/opencode/guide/rules.md +63 -0
- package/skills/read-docs/references/opencode/plugins/examples.md +75 -0
- package/skills/read-docs/references/opencode/plugins/index.md +188 -0
- package/skills/read-docs/references/opencode/reference/index.md +119 -0
- package/skills/read-docs/references/opencode/rule/index.md +78 -0
- package/skills/read-docs/references/opencode/skills/detail.md +113 -0
- package/skills/read-docs/references/opencode/skills/examples.md +141 -0
- package/skills/read-docs/references/opencode/skills/index.md +126 -0
- package/skills/read-docs/references/opencode/skills/workflow.md +146 -0
- package/skills/read-docs/references/opencode/tests/agent.md +10 -0
- package/skills/read-docs/references/opencode/tests/config.md +60 -0
- package/skills/read-docs/references/opencode/tests/file.md +12 -0
- package/skills/read-docs/references/opencode/tests/serve.md +18 -0
- package/skills/read-docs/references/opencode/tests/session.md +31 -0
- package/skills/read-docs/references/opencode/tests/web.md +17 -0
- package/skills/read-docs/references/opencode/tools/arguments.md +305 -0
- package/skills/read-docs/references/opencode/tools/context.md +18 -0
- package/skills/read-docs/references/opencode/tools/custom.md +111 -0
- package/skills/read-docs/references/opencode/tools/detail.md +104 -0
- package/skills/read-docs/references/opencode/tools/examples.md +71 -0
- package/skills/read-docs/references/opencode/tools/index.md +56 -0
- package/skills/read-docs/references/opencode/tools/lsp.md +26 -0
- package/skills/read-docs/references/opencode/tools/mcp.md +132 -0
- package/skills/read-docs/references/opencode/train/README.md +135 -0
- package/skills/read-docs/references/opencode/train/agent-basic.md +772 -0
- package/skills/read-docs/references/opencode/train/command-basic.md +668 -0
- package/skills/read-docs/references/opencode/train/config-basic.md +509 -0
- package/skills/read-docs/references/opencode/train/index.md +164 -0
- package/skills/read-docs/references/opencode/train/practice.md +873 -0
- package/skills/read-docs/references/opencode/train/skill-basic.md +608 -0
- package/skills/read-docs/references/opencode/tui/commands/config.md +32 -0
- package/skills/read-docs/references/opencode/tui/commands/editor.md +47 -0
- package/skills/read-docs/references/opencode/tui/commands/index.md +125 -0
- package/skills/read-docs/references/opencode/tui/commands/init.md +5 -0
- package/skills/read-docs/references/opencode/tui/index.md +26 -0
- package/skills/read-docs/references/superpowers/bootstrap.md +107 -0
- package/skills/read-docs/references/superpowers/comparison.md +77 -0
- package/skills/read-docs/references/superpowers/context.md +71 -0
- package/skills/read-docs/references/superpowers/index.md +58 -0
- package/skills/read-docs/references/superpowers/parallel.md +49 -0
- package/skills/read-docs/references/superpowers/sdd.md +183 -0
- package/skills/read-docs/references/superpowers/skills.md +68 -0
- package/skills/read-docs/references/superpowers/workflow.md +83 -0
|
@@ -0,0 +1,668 @@
|
|
|
1
|
+
# 命令使用培训
|
|
2
|
+
|
|
3
|
+
学习创建和使用 OpenCode 自定义命令,提高工作效率。
|
|
4
|
+
|
|
5
|
+
## 理论介绍
|
|
6
|
+
|
|
7
|
+
### 什么是命令(Command)?
|
|
8
|
+
|
|
9
|
+
自定义命令让你在 TUI 中执行预设的提示词:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
/my-command
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**核心特点**:
|
|
16
|
+
- **快捷执行**:一键触发预设任务
|
|
17
|
+
- **参数化**:支持传递参数
|
|
18
|
+
- **模板化**:复用常见工作流
|
|
19
|
+
- **Agent 指定**:指定执行命令的 Agent
|
|
20
|
+
|
|
21
|
+
### 命令文件位置
|
|
22
|
+
|
|
23
|
+
创建 Markdown 文件:
|
|
24
|
+
- **全局**:`~/.config/opencode/commands/`
|
|
25
|
+
- **项目级**:`.opencode/commands/`
|
|
26
|
+
|
|
27
|
+
文件名即为命令名,如 `test.md` 创建 `/test` 命令。
|
|
28
|
+
|
|
29
|
+
### 命令结构
|
|
30
|
+
|
|
31
|
+
```markdown
|
|
32
|
+
---
|
|
33
|
+
description: 命令描述
|
|
34
|
+
agent: build
|
|
35
|
+
model: anthropic/claude-sonnet-4-5
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
命令模板内容...
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Frontmatter 字段**:
|
|
42
|
+
- `description`:命令描述(可选)
|
|
43
|
+
- `agent`:执行命令的 Agent(可选)
|
|
44
|
+
- `model`:覆盖模型(可选)
|
|
45
|
+
- `subtask`:强制触发子代理(可选)
|
|
46
|
+
|
|
47
|
+
## 命令模板功能
|
|
48
|
+
|
|
49
|
+
### 1. 参数传递
|
|
50
|
+
|
|
51
|
+
#### 使用 `$ARGUMENTS`
|
|
52
|
+
|
|
53
|
+
传递所有参数:
|
|
54
|
+
|
|
55
|
+
```markdown
|
|
56
|
+
---
|
|
57
|
+
description: 创建新组件
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
创建名为 $ARGUMENTS 的 React 组件,包含 TypeScript 支持。
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**使用**:
|
|
64
|
+
```
|
|
65
|
+
/component Button
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### 使用位置参数
|
|
69
|
+
|
|
70
|
+
传递特定位置参数:
|
|
71
|
+
|
|
72
|
+
```markdown
|
|
73
|
+
---
|
|
74
|
+
description: 创建文件
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
在目录 $2 创建文件 $1,内容为:
|
|
78
|
+
$3
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**使用**:
|
|
82
|
+
```
|
|
83
|
+
/create-file config.json src "{ \"key\": \"value\" }"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 2. Shell 输出注入
|
|
87
|
+
|
|
88
|
+
使用 `` !`command` `` 注入 bash 命令输出:
|
|
89
|
+
|
|
90
|
+
```markdown
|
|
91
|
+
---
|
|
92
|
+
description: 分析测试覆盖率
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
以下是当前测试结果:
|
|
96
|
+
!`npm test`
|
|
97
|
+
|
|
98
|
+
基于这些结果,建议改进覆盖率的方法。
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**执行流程**:
|
|
102
|
+
1. 运行 `npm test`
|
|
103
|
+
2. 将输出注入提示词
|
|
104
|
+
3. Agent 分析结果
|
|
105
|
+
|
|
106
|
+
### 3. 文件引用
|
|
107
|
+
|
|
108
|
+
使用 `@` 引用文件:
|
|
109
|
+
|
|
110
|
+
```markdown
|
|
111
|
+
---
|
|
112
|
+
description: 审查组件
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
审查组件 @src/components/Button.tsx。
|
|
116
|
+
检查性能问题并建议改进。
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**执行流程**:
|
|
120
|
+
1. 读取 `src/components/Button.tsx`
|
|
121
|
+
2. 将内容注入提示词
|
|
122
|
+
3. Agent 审查文件
|
|
123
|
+
|
|
124
|
+
### 4. 组合使用
|
|
125
|
+
|
|
126
|
+
组合多种功能:
|
|
127
|
+
|
|
128
|
+
```markdown
|
|
129
|
+
---
|
|
130
|
+
description: 完整审查流程
|
|
131
|
+
agent: reviewer
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
审查变更:
|
|
135
|
+
|
|
136
|
+
## Git 变更
|
|
137
|
+
!`git diff origin/main...HEAD`
|
|
138
|
+
|
|
139
|
+
## 相关文件
|
|
140
|
+
@$ARGUMENTS
|
|
141
|
+
|
|
142
|
+
请审查这些变更,检查代码质量和安全性。
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**使用**:
|
|
146
|
+
```
|
|
147
|
+
/review src/components/Button.tsx
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## 实例展示
|
|
151
|
+
|
|
152
|
+
### 案例 1:测试命令
|
|
153
|
+
|
|
154
|
+
创建 `.opencode/commands/test.md`:
|
|
155
|
+
|
|
156
|
+
```markdown
|
|
157
|
+
---
|
|
158
|
+
description: 运行测试套件并分析失败
|
|
159
|
+
agent: build
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
运行完整测试套件并显示覆盖率报告:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
npm test -- --coverage
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
分析失败的测试:
|
|
169
|
+
1. 识别失败原因
|
|
170
|
+
2. 定位问题代码
|
|
171
|
+
3. 提供修复建议
|
|
172
|
+
|
|
173
|
+
输出结构化报告。
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**使用**:
|
|
177
|
+
```
|
|
178
|
+
/test
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### 案例 2:组件创建命令
|
|
182
|
+
|
|
183
|
+
创建 `.opencode/commands/component.md`:
|
|
184
|
+
|
|
185
|
+
```markdown
|
|
186
|
+
---
|
|
187
|
+
description: 创建 React 组件
|
|
188
|
+
agent: build
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
创建名为 $ARGUMENTS 的 React 组件,要求:
|
|
192
|
+
|
|
193
|
+
## 组件结构
|
|
194
|
+
|
|
195
|
+
1. **文件位置**:`src/components/$ARGUMENTS.tsx`
|
|
196
|
+
2. **TypeScript 支持**:完整类型定义
|
|
197
|
+
3. **Props 定义**:明确的接口定义
|
|
198
|
+
4. **样式方案**:使用 CSS Modules 或 Tailwind
|
|
199
|
+
|
|
200
|
+
## 组件模板
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
interface $ARGUMENTSProps {
|
|
204
|
+
// Props 定义
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function $ARGUMENTS({ }: $ARGUMENTSProps) {
|
|
208
|
+
return (
|
|
209
|
+
// 组件实现
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## 附加文件
|
|
215
|
+
|
|
216
|
+
- 创建测试文件:`src/components/$ARGUMENTS.test.tsx`
|
|
217
|
+
- 创建样式文件:`src/components/$ARGUMENTS.css`
|
|
218
|
+
|
|
219
|
+
创建完成后,确保组件可导入和使用。
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**使用**:
|
|
223
|
+
```
|
|
224
|
+
/component Button
|
|
225
|
+
/component UserCard
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### 案例 3:代码审查命令
|
|
229
|
+
|
|
230
|
+
创建 `.opencode/commands/review.md`:
|
|
231
|
+
|
|
232
|
+
```markdown
|
|
233
|
+
---
|
|
234
|
+
description: 审查代码变更
|
|
235
|
+
agent: reviewer
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
审查以下代码变更:
|
|
239
|
+
|
|
240
|
+
## Git 差异
|
|
241
|
+
!`git diff HEAD`
|
|
242
|
+
|
|
243
|
+
## 相关文件
|
|
244
|
+
@$ARGUMENTS
|
|
245
|
+
|
|
246
|
+
## 审查要求
|
|
247
|
+
|
|
248
|
+
1. **代码质量**:
|
|
249
|
+
- 命名规范
|
|
250
|
+
- 格式规范
|
|
251
|
+
- 注释规范
|
|
252
|
+
|
|
253
|
+
2. **安全性**:
|
|
254
|
+
- 输入验证
|
|
255
|
+
- 权限检查
|
|
256
|
+
- 数据泄露
|
|
257
|
+
|
|
258
|
+
3. **性能**:
|
|
259
|
+
- 算法效率
|
|
260
|
+
- 资源管理
|
|
261
|
+
|
|
262
|
+
输出审查报告,指出具体问题和修复建议。
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**使用**:
|
|
266
|
+
```
|
|
267
|
+
/review src/utils/helper.ts
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### 案例 4:文档生成命令
|
|
271
|
+
|
|
272
|
+
创建 `.opencode/commands/docs.md`:
|
|
273
|
+
|
|
274
|
+
```markdown
|
|
275
|
+
---
|
|
276
|
+
description: 生成 API 文档
|
|
277
|
+
agent: docs-writer
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
为以下文件生成 API 文档:
|
|
281
|
+
|
|
282
|
+
@$ARGUMENTS
|
|
283
|
+
|
|
284
|
+
## 文档要求
|
|
285
|
+
|
|
286
|
+
1. **概述**:一句话说明功能
|
|
287
|
+
2. **参数说明**:
|
|
288
|
+
- 参数名
|
|
289
|
+
- 类型
|
|
290
|
+
- 默认值
|
|
291
|
+
- 说明
|
|
292
|
+
|
|
293
|
+
3. **返回值**:
|
|
294
|
+
- 类型
|
|
295
|
+
- 说明
|
|
296
|
+
|
|
297
|
+
4. **示例代码**:
|
|
298
|
+
- 基础用法
|
|
299
|
+
- 高级用法
|
|
300
|
+
|
|
301
|
+
5. **注意事项**:
|
|
302
|
+
|
|
303
|
+
使用 Markdown 格式,代码块指定语言。
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
**使用**:
|
|
307
|
+
```
|
|
308
|
+
/docs src/api/user.ts
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### 案例 5:Git 提交命令
|
|
312
|
+
|
|
313
|
+
创建 `.opencode/commands/commit.md`:
|
|
314
|
+
|
|
315
|
+
```markdown
|
|
316
|
+
---
|
|
317
|
+
description: 创建 Git 提交
|
|
318
|
+
agent: build
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
创建 Git 提交,提交信息为:$ARGUMENTS
|
|
322
|
+
|
|
323
|
+
## 提交前检查
|
|
324
|
+
|
|
325
|
+
1. 查看变更:
|
|
326
|
+
!`git status`
|
|
327
|
+
!`git diff`
|
|
328
|
+
|
|
329
|
+
2. 运行测试:
|
|
330
|
+
!`npm test`
|
|
331
|
+
|
|
332
|
+
3. 运行 lint:
|
|
333
|
+
!`npm run lint`
|
|
334
|
+
|
|
335
|
+
## 提交要求
|
|
336
|
+
|
|
337
|
+
- 提交信息格式:`type: description`
|
|
338
|
+
- type 可选:feat, fix, docs, style, refactor, test, chore
|
|
339
|
+
- 描述简洁明了
|
|
340
|
+
|
|
341
|
+
如果测试或 lint 失败,先修复问题再提交。
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
**使用**:
|
|
345
|
+
```
|
|
346
|
+
/commit feat: 添加用户认证功能
|
|
347
|
+
/commit fix: 修复登录验证 Bug
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### 案例 6:依赖更新命令
|
|
351
|
+
|
|
352
|
+
创建 `.opencode/commands/update-deps.md`:
|
|
353
|
+
|
|
354
|
+
```markdown
|
|
355
|
+
---
|
|
356
|
+
description: 更新项目依赖
|
|
357
|
+
agent: build
|
|
358
|
+
---
|
|
359
|
+
|
|
360
|
+
更新项目依赖:
|
|
361
|
+
|
|
362
|
+
## 当前依赖状态
|
|
363
|
+
!`npm outdated`
|
|
364
|
+
|
|
365
|
+
## 更新步骤
|
|
366
|
+
|
|
367
|
+
1. **检查更新**:
|
|
368
|
+
```bash
|
|
369
|
+
npm outdated
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
2. **更新依赖**:
|
|
373
|
+
```bash
|
|
374
|
+
npm update
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
3. **测试验证**:
|
|
378
|
+
```bash
|
|
379
|
+
npm test
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
4. **提交变更**:
|
|
383
|
+
```bash
|
|
384
|
+
git add package.json package-lock.json
|
|
385
|
+
git commit -m "chore: 更新依赖"
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
## 注意事项
|
|
389
|
+
|
|
390
|
+
- 主要版本更新需谨慎
|
|
391
|
+
- 更新后必须运行测试
|
|
392
|
+
- 检查是否有 breaking changes
|
|
393
|
+
|
|
394
|
+
如果测试失败,回滚变更并分析问题。
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
**使用**:
|
|
398
|
+
```
|
|
399
|
+
/update-deps
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### 案例 7:项目初始化命令
|
|
403
|
+
|
|
404
|
+
创建 `.opencode/commands/init-project.md`:
|
|
405
|
+
|
|
406
|
+
```markdown
|
|
407
|
+
---
|
|
408
|
+
description: 初始化新项目
|
|
409
|
+
agent: build
|
|
410
|
+
---
|
|
411
|
+
|
|
412
|
+
初始化名为 $ARGUMENTS 的项目:
|
|
413
|
+
|
|
414
|
+
## 项目结构
|
|
415
|
+
|
|
416
|
+
```
|
|
417
|
+
$ARGUMENTS/
|
|
418
|
+
├── src/
|
|
419
|
+
│ ├── components/
|
|
420
|
+
│ ├── utils/
|
|
421
|
+
│ └── index.ts
|
|
422
|
+
├── tests/
|
|
423
|
+
├── package.json
|
|
424
|
+
├── tsconfig.json
|
|
425
|
+
├── README.md
|
|
426
|
+
└── .gitignore
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## 创建步骤
|
|
430
|
+
|
|
431
|
+
1. 创建目录结构
|
|
432
|
+
2. 生成 package.json:
|
|
433
|
+
```json
|
|
434
|
+
{
|
|
435
|
+
"name": "$ARGUMENTS",
|
|
436
|
+
"version": "1.0.0",
|
|
437
|
+
"scripts": {
|
|
438
|
+
"build": "tsc",
|
|
439
|
+
"test": "jest"
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
3. 生成 tsconfig.json
|
|
445
|
+
4. 生成 README.md
|
|
446
|
+
5. 初始化 Git 仓库
|
|
447
|
+
|
|
448
|
+
## 初始化 Git
|
|
449
|
+
|
|
450
|
+
```bash
|
|
451
|
+
git init
|
|
452
|
+
git add .
|
|
453
|
+
git commit -m "init: 初始化项目"
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
创建完成后,项目可以立即开始开发。
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
**使用**:
|
|
460
|
+
```
|
|
461
|
+
/init-project my-app
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
### 案例 8:性能分析命令
|
|
465
|
+
|
|
466
|
+
创建 `.opencode/commands/perf.md`:
|
|
467
|
+
|
|
468
|
+
```markdown
|
|
469
|
+
---
|
|
470
|
+
description: 性能分析
|
|
471
|
+
agent: analyzer
|
|
472
|
+
---
|
|
473
|
+
|
|
474
|
+
分析性能问题:
|
|
475
|
+
|
|
476
|
+
## 当前状态
|
|
477
|
+
!`npm run build -- --profile`
|
|
478
|
+
|
|
479
|
+
## 分析要求
|
|
480
|
+
|
|
481
|
+
1. **构建性能**:
|
|
482
|
+
- 构建时间
|
|
483
|
+
- Bundle 大小
|
|
484
|
+
- 模块依赖
|
|
485
|
+
|
|
486
|
+
2. **运行性能**:
|
|
487
|
+
- 启动时间
|
|
488
|
+
- 内存使用
|
|
489
|
+
- CPU 占用
|
|
490
|
+
|
|
491
|
+
3. **优化建议**:
|
|
492
|
+
- 代码分割
|
|
493
|
+
- 懒加载
|
|
494
|
+
- Tree shaking
|
|
495
|
+
|
|
496
|
+
输出性能报告和优化建议。
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
**使用**:
|
|
500
|
+
```
|
|
501
|
+
/perf
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
## JSON 配置方式
|
|
505
|
+
|
|
506
|
+
在 `opencode.json` 中配置:
|
|
507
|
+
|
|
508
|
+
```jsonc
|
|
509
|
+
{
|
|
510
|
+
"$schema": "https://opencode.ai/config.json",
|
|
511
|
+
|
|
512
|
+
"command": {
|
|
513
|
+
"test": {
|
|
514
|
+
"template": "运行完整测试套件并分析失败原因",
|
|
515
|
+
"description": "运行测试",
|
|
516
|
+
"agent": "build",
|
|
517
|
+
"model": "anthropic/claude-haiku-4-5"
|
|
518
|
+
},
|
|
519
|
+
|
|
520
|
+
"component": {
|
|
521
|
+
"template": "创建名为 $ARGUMENTS 的 React组件",
|
|
522
|
+
"description": "创建组件",
|
|
523
|
+
"subtask": true
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
## 动手练习
|
|
530
|
+
|
|
531
|
+
### 练习 1:创建简单命令
|
|
532
|
+
|
|
533
|
+
**任务**:创建一个 lint 命令
|
|
534
|
+
|
|
535
|
+
**提示**:
|
|
536
|
+
```markdown
|
|
537
|
+
---
|
|
538
|
+
description: 运行代码规范检查
|
|
539
|
+
---
|
|
540
|
+
|
|
541
|
+
运行 ESLint 检查:
|
|
542
|
+
|
|
543
|
+
```bash
|
|
544
|
+
npm run lint
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
分析问题并提供修复建议。
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
### 练习 2:创建参数化命令
|
|
551
|
+
|
|
552
|
+
**任务**:创建一个文件创建命令
|
|
553
|
+
|
|
554
|
+
**提示**:
|
|
555
|
+
```markdown
|
|
556
|
+
---
|
|
557
|
+
description: 创建文件
|
|
558
|
+
---
|
|
559
|
+
|
|
560
|
+
在目录 $2 创建文件 $1,内容为:
|
|
561
|
+
$3
|
|
562
|
+
|
|
563
|
+
创建完成后验证文件内容。
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
### 练习 3:创建 Shell 集成命令
|
|
567
|
+
|
|
568
|
+
**任务**:创建一个 Git 状态命令
|
|
569
|
+
|
|
570
|
+
**提示**:
|
|
571
|
+
```markdown
|
|
572
|
+
---
|
|
573
|
+
description: 查看 Git 状态
|
|
574
|
+
---
|
|
575
|
+
|
|
576
|
+
当前 Git 状态:
|
|
577
|
+
!`git status`
|
|
578
|
+
|
|
579
|
+
分析变更并提供下一步建议。
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
### 练习 4:创建组合命令
|
|
583
|
+
|
|
584
|
+
**任务**:创建一个完整的开发流程命令
|
|
585
|
+
|
|
586
|
+
**提示**:
|
|
587
|
+
```markdown
|
|
588
|
+
---
|
|
589
|
+
description: 完整开发流程
|
|
590
|
+
agent: build
|
|
591
|
+
---
|
|
592
|
+
|
|
593
|
+
执行完整开发流程:
|
|
594
|
+
|
|
595
|
+
## 1. 查看变更
|
|
596
|
+
!`git status`
|
|
597
|
+
|
|
598
|
+
## 2. 运行 lint
|
|
599
|
+
!`npm run lint`
|
|
600
|
+
|
|
601
|
+
## 3. 运行测试
|
|
602
|
+
!`npm test`
|
|
603
|
+
|
|
604
|
+
## 4. 构建项目
|
|
605
|
+
!`npm run build`
|
|
606
|
+
|
|
607
|
+
分析所有步骤的结果,如果失败提供修复建议。
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
## 常见问题
|
|
611
|
+
|
|
612
|
+
### Q1: 命令和技能有什么区别?
|
|
613
|
+
|
|
614
|
+
| 特性 | 命令 | 技能 |
|
|
615
|
+
|------|------|------|
|
|
616
|
+
| 触发方式 | `/command-name` | Agent 按需加载 |
|
|
617
|
+
| 主要用途 | 快捷执行预设任务 | 可复用工作流 |
|
|
618
|
+
| 参数支持 | `$ARGUMENTS` | 无参数机制 |
|
|
619
|
+
| Agent 指定 | Frontmatter | 继承 Agent |
|
|
620
|
+
|
|
621
|
+
### Q2: 如何调试命令?
|
|
622
|
+
|
|
623
|
+
1. 使用 `/help` 查看命令列表
|
|
624
|
+
2. 执行命令查看输出
|
|
625
|
+
3. 检查 Shell 输出是否正确
|
|
626
|
+
4. 验证 Agent 是否正确执行
|
|
627
|
+
|
|
628
|
+
### Q3: 命令可以调用其他命令吗?
|
|
629
|
+
|
|
630
|
+
不可以,但可以通过 Agent 间接协作:
|
|
631
|
+
```
|
|
632
|
+
命令 → Agent → 技能 → 工作流
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
### Q4: 如何创建交互式命令?
|
|
636
|
+
|
|
637
|
+
使用 Agent 的 `question` 工具:
|
|
638
|
+
```markdown
|
|
639
|
+
---
|
|
640
|
+
description: 交互式组件创建
|
|
641
|
+
agent: build
|
|
642
|
+
---
|
|
643
|
+
|
|
644
|
+
创建组件,询问用户:
|
|
645
|
+
1. 组件名称
|
|
646
|
+
2. 组件类型
|
|
647
|
+
3. 样式方案
|
|
648
|
+
|
|
649
|
+
根据用户选择创建组件。
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
## 内置命令
|
|
653
|
+
|
|
654
|
+
OpenCode 包含以下内置命令:
|
|
655
|
+
|
|
656
|
+
| 命令 | 说明 |
|
|
657
|
+
|------|------|
|
|
658
|
+
| `/init` | 初始化项目配置 |
|
|
659
|
+
| `/undo` | 撤销操作 |
|
|
660
|
+
| `/redo` | 重做操作 |
|
|
661
|
+
| `/share` | 分享对话 |
|
|
662
|
+
| `/help` | 显示帮助 |
|
|
663
|
+
|
|
664
|
+
## 下一步
|
|
665
|
+
|
|
666
|
+
- 🎯 [实战案例](/train/practice) - 综合应用所学知识
|
|
667
|
+
- 📖 [命令示例](/commands/examples) - 更多命令示例
|
|
668
|
+
- 🤖 [Agent 配置](/train/agent-basic) - 深入理解 Agent
|