@wwkit/harness 1.0.8 → 1.0.10
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 +367 -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 +151 -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 +2 -2
- 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 +307 -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
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Formatters
|
|
2
|
+
OpenCode can format files after they are written or edited using language-specific formatters.
|
|
3
|
+
|
|
4
|
+
> Formatters are disabled by default; enable them in your config before OpenCode will run them.
|
|
5
|
+
|
|
6
|
+
## Built-in
|
|
7
|
+
OpenCode comes with several built-in formatters for popular languages and frameworks.
|
|
8
|
+
- `prettier` : .js, .jsx, .ts, .tsx, .html, .css, .md, .json, .yaml
|
|
9
|
+
- `uv` : .py, .pyi
|
|
10
|
+
- `shfmt` : .sh, .bash
|
|
11
|
+
- `pint` : .php
|
|
12
|
+
|
|
13
|
+
## How it works
|
|
14
|
+
When OpenCode writes or edits a file and formatters are enabled, it:
|
|
15
|
+
|
|
16
|
+
1. Checks the file extension against all enabled formatters.
|
|
17
|
+
2. Runs the appropriate formatter command on the file.
|
|
18
|
+
3. Applies the formatting changes.
|
|
19
|
+
|
|
20
|
+
This process happens in the background for enabled formatters.
|
|
21
|
+
|
|
22
|
+
## Configure
|
|
23
|
+
You can enable and customize formatters through the formatter section in your OpenCode config.
|
|
24
|
+
|
|
25
|
+
To enable all built-in formatters, set formatter to true.
|
|
26
|
+
```
|
|
27
|
+
{
|
|
28
|
+
"$schema": "https://opencode.ai/config.json",
|
|
29
|
+
"formatter": true
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Each formatter configuration supports the following:
|
|
34
|
+
- `disabled` : `boolean` Set this to true to disable the formatter
|
|
35
|
+
- `command` : `string[]` The command to run for formatting.
|
|
36
|
+
- Required for custom formatters;
|
|
37
|
+
- optional for built-ins.
|
|
38
|
+
- `environment` : `object` Environment variables to set when running the formatter
|
|
39
|
+
- `extensions` : `string[]` File extensions this formatter should handle
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"$schema": "https://opencode.ai/config.json",
|
|
44
|
+
"formatter": {
|
|
45
|
+
"prettier": {
|
|
46
|
+
"disabled": true
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Custom formatters
|
|
53
|
+
The `$FILE` placeholder in the command will be replaced with the path to the file being formatted.
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"$schema": "https://opencode.ai/config.json",
|
|
57
|
+
"formatter": {
|
|
58
|
+
"prettier": {
|
|
59
|
+
"command": ["npx", "prettier", "--write", "$FILE"],
|
|
60
|
+
"environment": {
|
|
61
|
+
"NODE_ENV": "development"
|
|
62
|
+
},
|
|
63
|
+
"extensions": [".js", ".ts", ".jsx", ".tsx"]
|
|
64
|
+
},
|
|
65
|
+
"custom-markdown-formatter": {
|
|
66
|
+
"command": ["deno", "fmt", "$FILE"],
|
|
67
|
+
"extensions": [".md"]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
# OpenCode 配置
|
|
2
|
+
|
|
3
|
+
OpenCode 使用 JSON 或 JSONC(带注释的 JSON)配置文件进行配置。
|
|
4
|
+
|
|
5
|
+
## 配置格式
|
|
6
|
+
|
|
7
|
+
```jsonc
|
|
8
|
+
{
|
|
9
|
+
"$schema": "https://opencode.ai/config.json",
|
|
10
|
+
"model": "anthropic/claude-sonnet-4-5",
|
|
11
|
+
"autoupdate": true,
|
|
12
|
+
"server": {
|
|
13
|
+
"port": 4096,
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 配置文件位置
|
|
19
|
+
|
|
20
|
+
配置文件按以下优先级加载(后者覆盖前者):
|
|
21
|
+
|
|
22
|
+
| 优先级 | 位置 | 说明 |
|
|
23
|
+
|--------|------|------|
|
|
24
|
+
| 1 | 远程配置(`.well-known/opencode`) | 组织级默认配置 |
|
|
25
|
+
| 2 | 全局配置(`~/.config/opencode/opencode.json`) | 用户偏好 |
|
|
26
|
+
| 3 | 自定义配置(`OPENCODE_CONFIG` 环境变量) | 自定义覆盖 |
|
|
27
|
+
| 4 | 项目配置(`.opencode/opencode.json`) | 项目级设置 |
|
|
28
|
+
|
|
29
|
+
### 自定义配置路径
|
|
30
|
+
|
|
31
|
+
通过 `OPENCODE_CONFIG` 环境变量指定自定义配置文件:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
export OPENCODE_CONFIG=/path/to/my/custom-config.json
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
自定义配置在全局配置和项目配置之间加载。
|
|
38
|
+
|
|
39
|
+
### 自定义配置目录
|
|
40
|
+
|
|
41
|
+
通过 `OPENCODE_CONFIG_DIR` 环境变量指定自定义配置目录:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
export OPENCODE_CONFIG_DIR=/path/to/my/config-directory
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
该目录将按 `.opencode` 目录的标准结构搜索 agents、commands、modes 和 plugins。
|
|
48
|
+
|
|
49
|
+
## 配置项详解
|
|
50
|
+
|
|
51
|
+
### Server
|
|
52
|
+
|
|
53
|
+
配置 `opencode serve` 和 `opencode web` 命令的服务器设置:
|
|
54
|
+
|
|
55
|
+
```jsonc
|
|
56
|
+
{
|
|
57
|
+
"$schema": "https://opencode.ai/config.json",
|
|
58
|
+
"server": {
|
|
59
|
+
"port": 4096,
|
|
60
|
+
"hostname": "0.0.0.0",
|
|
61
|
+
"mdns": true,
|
|
62
|
+
"mdnsDomain": "myproject.local",
|
|
63
|
+
"cors": ["http://localhost:5173"]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Shell
|
|
69
|
+
|
|
70
|
+
配置交互式终端使用的 Shell:
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"$schema": "https://opencode.ai/config.json",
|
|
75
|
+
"shell": "pwsh"
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Tools
|
|
80
|
+
|
|
81
|
+
管理 LLM 可使用的工具:
|
|
82
|
+
|
|
83
|
+
```jsonc
|
|
84
|
+
{
|
|
85
|
+
"$schema": "https://opencode.ai/config.json",
|
|
86
|
+
"tools": {
|
|
87
|
+
"write": false,
|
|
88
|
+
"bash": false
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Models
|
|
94
|
+
|
|
95
|
+
配置使用的 Provider 和模型:
|
|
96
|
+
|
|
97
|
+
```jsonc
|
|
98
|
+
{
|
|
99
|
+
"$schema": "https://opencode.ai/config.json",
|
|
100
|
+
"provider": {},
|
|
101
|
+
"model": "anthropic/claude-sonnet-4-5",
|
|
102
|
+
"small_model": "anthropic/claude-haiku-4-5"
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Provider 选项可包含 `timeout`、`chunkTimeout` 和 `setCacheKey`:
|
|
107
|
+
|
|
108
|
+
```jsonc
|
|
109
|
+
{
|
|
110
|
+
"$schema": "https://opencode.ai/config.json",
|
|
111
|
+
"provider": {
|
|
112
|
+
"anthropic": {
|
|
113
|
+
"options": {
|
|
114
|
+
"timeout": 600000,
|
|
115
|
+
"chunkTimeout": 30000,
|
|
116
|
+
"setCacheKey": true
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Image Attachments
|
|
124
|
+
|
|
125
|
+
OpenCode 在发送图片前会自动标准化,默认超过 2000x2000 像素或 5242880 base64 字节时自动缩放:
|
|
126
|
+
|
|
127
|
+
```jsonc
|
|
128
|
+
{
|
|
129
|
+
"$schema": "https://opencode.ai/config.json",
|
|
130
|
+
"attachment": {
|
|
131
|
+
"image": {
|
|
132
|
+
"auto_resize": true,
|
|
133
|
+
"max_width": 2000,
|
|
134
|
+
"max_height": 2000,
|
|
135
|
+
"max_base64_bytes": 5242880
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Agents
|
|
142
|
+
|
|
143
|
+
配置专门的 Agent 执行特定任务:
|
|
144
|
+
|
|
145
|
+
```jsonc
|
|
146
|
+
{
|
|
147
|
+
"$schema": "https://opencode.ai/config.json",
|
|
148
|
+
"agent": {
|
|
149
|
+
"code-reviewer": {
|
|
150
|
+
"description": "Reviews code for best practices and potential issues",
|
|
151
|
+
"model": "anthropic/claude-sonnet-4-5",
|
|
152
|
+
"prompt": "You are a code reviewer. Focus on security, performance, and maintainability.",
|
|
153
|
+
"tools": {
|
|
154
|
+
"write": false,
|
|
155
|
+
"edit": false,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
也可以使用 Markdown 文件定义 Agent,放置在 `~/.config/opencode/agents/` 或 `.opencode/agents/`。
|
|
163
|
+
|
|
164
|
+
### Default Agent
|
|
165
|
+
|
|
166
|
+
设置默认 Agent:
|
|
167
|
+
|
|
168
|
+
```jsonc
|
|
169
|
+
{
|
|
170
|
+
"$schema": "https://opencode.ai/config.json",
|
|
171
|
+
"default_agent": "plan"
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Sharing
|
|
176
|
+
|
|
177
|
+
配置分享功能:
|
|
178
|
+
|
|
179
|
+
| 值 | 说明 |
|
|
180
|
+
|----|------|
|
|
181
|
+
| `manual` | 手动分享(默认) |
|
|
182
|
+
| `auto` | 自动分享新对话 |
|
|
183
|
+
| `disabled` | 禁用分享 |
|
|
184
|
+
|
|
185
|
+
```json
|
|
186
|
+
{
|
|
187
|
+
"$schema": "https://opencode.ai/config.json",
|
|
188
|
+
"share": "manual"
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Commands
|
|
193
|
+
|
|
194
|
+
配置自定义命令:
|
|
195
|
+
|
|
196
|
+
```jsonc
|
|
197
|
+
{
|
|
198
|
+
"$schema": "https://opencode.ai/config.json",
|
|
199
|
+
"command": {
|
|
200
|
+
"test": {
|
|
201
|
+
"template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes.",
|
|
202
|
+
"description": "Run tests with coverage",
|
|
203
|
+
"agent": "build",
|
|
204
|
+
"model": "anthropic/claude-haiku-4-5",
|
|
205
|
+
},
|
|
206
|
+
"component": {
|
|
207
|
+
"template": "Create a new React component named $ARGUMENTS with TypeScript support.\nInclude proper typing and basic structure.",
|
|
208
|
+
"description": "Create a new component",
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
也可以使用 Markdown 文件定义命令,放置在 `~/.config/opencode/commands/` 或 `.opencode/commands/`。
|
|
215
|
+
|
|
216
|
+
### Snapshot
|
|
217
|
+
|
|
218
|
+
OpenCode 使用快照跟踪 Agent 操作期间的文件变更,支持撤销和恢复。默认启用:
|
|
219
|
+
|
|
220
|
+
```jsonc
|
|
221
|
+
{
|
|
222
|
+
"$schema": "https://opencode.ai/config.json",
|
|
223
|
+
"snapshot": false
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Autoupdate
|
|
228
|
+
|
|
229
|
+
OpenCode 启动时自动下载更新(默认启用):
|
|
230
|
+
|
|
231
|
+
```jsonc
|
|
232
|
+
{
|
|
233
|
+
"$schema": "https://opencode.ai/config.json",
|
|
234
|
+
"autoupdate": false
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Formatters
|
|
239
|
+
|
|
240
|
+
配置代码格式化器,详见 [格式化器](/guide/formatters)。
|
|
241
|
+
|
|
242
|
+
### LSP Servers
|
|
243
|
+
|
|
244
|
+
配置 LSP 服务器:
|
|
245
|
+
|
|
246
|
+
```jsonc
|
|
247
|
+
{
|
|
248
|
+
"$schema": "https://opencode.ai/config.json",
|
|
249
|
+
"lsp": true
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
```jsonc
|
|
254
|
+
{
|
|
255
|
+
"$schema": "https://opencode.ai/config.json",
|
|
256
|
+
"lsp": {
|
|
257
|
+
"typescript": {
|
|
258
|
+
"disabled": true
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Permissions
|
|
265
|
+
|
|
266
|
+
默认允许所有操作,可通过 `permission` 配置审批策略:
|
|
267
|
+
|
|
268
|
+
```jsonc
|
|
269
|
+
{
|
|
270
|
+
"$schema": "https://opencode.ai/config.json",
|
|
271
|
+
"permission": {
|
|
272
|
+
"edit": "ask",
|
|
273
|
+
"bash": "ask"
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Compaction
|
|
279
|
+
|
|
280
|
+
控制上下文压缩行为:
|
|
281
|
+
|
|
282
|
+
```jsonc
|
|
283
|
+
{
|
|
284
|
+
"$schema": "https://opencode.ai/config.json",
|
|
285
|
+
"compaction": {
|
|
286
|
+
"auto": true,
|
|
287
|
+
"prune": true,
|
|
288
|
+
"reserved": 10000
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Watcher
|
|
294
|
+
|
|
295
|
+
配置文件监视器的忽略模式:
|
|
296
|
+
|
|
297
|
+
```json
|
|
298
|
+
{
|
|
299
|
+
"$schema": "https://opencode.ai/config.json",
|
|
300
|
+
"watcher": {
|
|
301
|
+
"ignore": ["node_modules/**", "dist/**", ".git/**"]
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### MCP Servers
|
|
307
|
+
|
|
308
|
+
配置 MCP 服务器,详见 [MCP 服务器](/tools/mcp)。
|
|
309
|
+
|
|
310
|
+
### Plugins
|
|
311
|
+
|
|
312
|
+
配置插件,详见 [插件](/plugins/)。
|
|
313
|
+
|
|
314
|
+
```jsonc
|
|
315
|
+
{
|
|
316
|
+
"$schema": "https://opencode.ai/config.json",
|
|
317
|
+
"plugin": ["opencode-helicone-session", "@my-org/custom-plugin"]
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### Instructions
|
|
322
|
+
|
|
323
|
+
配置模型的指令文件:
|
|
324
|
+
|
|
325
|
+
```json
|
|
326
|
+
{
|
|
327
|
+
"$schema": "https://opencode.ai/config.json",
|
|
328
|
+
"instructions": ["CONTRIBUTING.md", "docs/guidelines.md", ".cursor/rules/*.md"]
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Enabled Providers
|
|
333
|
+
|
|
334
|
+
指定允许使用的 Provider 白名单:
|
|
335
|
+
|
|
336
|
+
```jsonc
|
|
337
|
+
{
|
|
338
|
+
"$schema": "https://opencode.ai/config.json",
|
|
339
|
+
"enabled_providers": ["anthropic", "openai"]
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## 变量替换
|
|
344
|
+
|
|
345
|
+
配置文件支持变量替换。
|
|
346
|
+
|
|
347
|
+
### 环境变量
|
|
348
|
+
|
|
349
|
+
使用 `{env:VARIABLE_NAME}` 引用环境变量:
|
|
350
|
+
|
|
351
|
+
```jsonc
|
|
352
|
+
{
|
|
353
|
+
"$schema": "https://opencode.ai/config.json",
|
|
354
|
+
"model": "{env:OPENCODE_MODEL}",
|
|
355
|
+
"provider": {
|
|
356
|
+
"anthropic": {
|
|
357
|
+
"models": {},
|
|
358
|
+
"options": {
|
|
359
|
+
"apiKey": "{env:ANTHROPIC_API_KEY}"
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### 文件内容
|
|
367
|
+
|
|
368
|
+
使用 `{file:path/to/file}` 引用文件内容(相对于配置文件目录,或以 `/`、`~` 开头的绝对路径):
|
|
369
|
+
|
|
370
|
+
```jsonc
|
|
371
|
+
{
|
|
372
|
+
"$schema": "https://opencode.ai/config.json",
|
|
373
|
+
"instructions": ["./custom-instructions.md"],
|
|
374
|
+
"provider": {
|
|
375
|
+
"openai": {
|
|
376
|
+
"options": {
|
|
377
|
+
"apiKey": "{file:~/.secrets/openai-key}"
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
## TUI 配置
|
|
385
|
+
|
|
386
|
+
使用独立的 `tui.json`(或 `tui.jsonc`)配置 TUI 界面设置:
|
|
387
|
+
|
|
388
|
+
```jsonc
|
|
389
|
+
{
|
|
390
|
+
"$schema": "https://opencode.ai/tui.json",
|
|
391
|
+
"scroll_speed": 3,
|
|
392
|
+
"scroll_acceleration": {
|
|
393
|
+
"enabled": true
|
|
394
|
+
},
|
|
395
|
+
"diff_style": "auto",
|
|
396
|
+
"mouse": true,
|
|
397
|
+
"attention": {
|
|
398
|
+
"enabled": true,
|
|
399
|
+
"notifications": true,
|
|
400
|
+
"sound": true,
|
|
401
|
+
"volume": 0.4
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
通过 `OPENCODE_TUI_CONFIG` 环境变量指定自定义 TUI 配置文件。
|
|
407
|
+
|
|
408
|
+
### Keybinds
|
|
409
|
+
|
|
410
|
+
自定义 TUI 键盘快捷键:
|
|
411
|
+
|
|
412
|
+
```jsonc
|
|
413
|
+
{
|
|
414
|
+
"$schema": "https://opencode.ai/tui.json",
|
|
415
|
+
"keybinds": {
|
|
416
|
+
"command_list": "ctrl+p"
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
```
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# 格式化器
|
|
2
|
+
|
|
3
|
+
OpenCode 可以在文件写入或编辑后使用语言特定的格式化器自动格式化代码。
|
|
4
|
+
|
|
5
|
+
格式化器默认禁用,需在配置中启用。
|
|
6
|
+
|
|
7
|
+
## 内置格式化器
|
|
8
|
+
|
|
9
|
+
| 格式化器 | 支持的文件类型 |
|
|
10
|
+
|----------|---------------|
|
|
11
|
+
| prettier | `.js`, `.jsx`, `.ts`, `.tsx`, `.html`, `.css`, `.md`, `.json`, `.yaml` |
|
|
12
|
+
| uv | `.py`, `.pyi` |
|
|
13
|
+
|
|
14
|
+
启用后,如果项目 `package.json` 中包含 prettier 依赖,OpenCode 将自动使用 prettier 格式化匹配的文件。
|
|
15
|
+
|
|
16
|
+
## 工作原理
|
|
17
|
+
|
|
18
|
+
当 OpenCode 写入或编辑文件且格式化器启用时:
|
|
19
|
+
|
|
20
|
+
1. 检查文件扩展名是否匹配已启用的格式化器
|
|
21
|
+
2. 运行对应的格式化器命令
|
|
22
|
+
3. 应用格式化变更
|
|
23
|
+
4. 此过程在后台自动进行
|
|
24
|
+
|
|
25
|
+
## 启用格式化器
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"$schema": "https://opencode.ai/config.json",
|
|
30
|
+
"formatter": true
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
禁用特定格式化器:
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"$schema": "https://opencode.ai/config.json",
|
|
39
|
+
"formatter": {
|
|
40
|
+
"prettier": {
|
|
41
|
+
"disabled": true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 自定义格式化器
|
|
48
|
+
|
|
49
|
+
可以配置内置格式化器的选项,或添加自定义格式化器:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"$schema": "https://opencode.ai/config.json",
|
|
54
|
+
"formatter": {
|
|
55
|
+
"prettier": {
|
|
56
|
+
"command": ["npx", "prettier", "--write", "$FILE"],
|
|
57
|
+
"environment": {
|
|
58
|
+
"NODE_ENV": "development"
|
|
59
|
+
},
|
|
60
|
+
"extensions": [".js", ".ts", ".jsx", ".tsx"]
|
|
61
|
+
},
|
|
62
|
+
"custom-markdown-formatter": {
|
|
63
|
+
"command": ["deno", "fmt", "$FILE"],
|
|
64
|
+
"extensions": [".md"]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
命令中的 `$FILE` 占位符将被替换为正在格式化的文件路径。
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# OpenCode 指南
|
|
2
|
+
|
|
3
|
+
OpenCode 是一个 AI 驱动的编码助手,支持自定义配置、技能扩展和多种 AI 模型。
|
|
4
|
+
|
|
5
|
+
## 快速开始
|
|
6
|
+
|
|
7
|
+
1. 安装 OpenCode
|
|
8
|
+
2. 运行 `opencode` 启动交互式会话
|
|
9
|
+
3. 使用 `/init` 命令初始化项目配置
|
|
10
|
+
|
|
11
|
+
## 核心概念
|
|
12
|
+
|
|
13
|
+
| 概念 | 说明 | 文档 |
|
|
14
|
+
|------|------|------|
|
|
15
|
+
| 配置 | JSON/JSONC 配置文件管理所有设置 | [配置](/guide/config) |
|
|
16
|
+
| 格式化器 | 自动格式化写入和编辑的代码 | [格式化器](/guide/formatters) |
|
|
17
|
+
| Provider | 配置 AI 模型提供商和 API 密钥 | [Provider](/guide/providers) |
|
|
18
|
+
| 规则 | 通过 AGENTS.md 提供自定义指令 | [规则](/guide/rules) |
|
|
19
|
+
| 技能 | 可复用的行为定义(SKILL.md) | [技能](/skills/) |
|
|
20
|
+
| Agent | 专门的 AI 助手 | [Agent](/agents/) |
|
|
21
|
+
| 命令 | 自定义快捷命令 | [命令](/commands/) |
|
|
22
|
+
| 插件 | 扩展 OpenCode 功能 | [插件](/plugins/) |
|
|
23
|
+
| 工具 | LLM 可调用的操作 | [工具](/tools/) |
|
|
24
|
+
|
|
25
|
+
## 内置 Agent
|
|
26
|
+
|
|
27
|
+
| Agent | 类型 | 说明 |
|
|
28
|
+
|-------|------|------|
|
|
29
|
+
| build | 主 Agent | 默认 Agent,所有工具启用 |
|
|
30
|
+
| plan | 主 Agent | 规划和分析,文件编辑和 bash 需审批 |
|
|
31
|
+
| general | 子 Agent | 通用多步骤任务,完整工具访问 |
|
|
32
|
+
| explore | 子 Agent | 快速只读代码探索 |
|
|
33
|
+
| scout | 子 Agent | 外部文档和依赖研究 |
|
|
34
|
+
|
|
35
|
+
## 资源文件
|
|
36
|
+
|
|
37
|
+
<SrcTree />
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Providers
|
|
2
|
+
|
|
3
|
+
添加 Provider 需要两步:
|
|
4
|
+
|
|
5
|
+
1. 使用 `/connect` 命令添加 Provider 的 API 密钥
|
|
6
|
+
2. 在 OpenCode 配置中配置 Provider
|
|
7
|
+
|
|
8
|
+
## 凭证管理
|
|
9
|
+
|
|
10
|
+
通过 `/connect` 命令添加的 API 密钥存储在 `~/.local/share/opencode/auth.json` 中。
|
|
11
|
+
|
|
12
|
+
## 配置 Provider
|
|
13
|
+
|
|
14
|
+
在 OpenCode 配置的 `provider` 部分自定义 Provider:
|
|
15
|
+
|
|
16
|
+
```jsonc
|
|
17
|
+
{
|
|
18
|
+
"$schema": "https://opencode.ai/config.json",
|
|
19
|
+
"provider": {
|
|
20
|
+
"anthropic": {
|
|
21
|
+
"options": {
|
|
22
|
+
"baseURL": "https://api.anthropic.com/v1"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## OpenCode Zen
|
|
30
|
+
|
|
31
|
+
OpenCode Zen 是 OpenCode 团队提供的经过测试验证的模型列表,可确保与 OpenCode 良好配合。
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# 规则(Rules)
|
|
2
|
+
|
|
3
|
+
通过创建 `AGENTS.md` 文件为 OpenCode 提供自定义指令。
|
|
4
|
+
|
|
5
|
+
## 初始化
|
|
6
|
+
|
|
7
|
+
在 OpenCode 中运行 `/init` 命令创建 `AGENTS.md` 文件:
|
|
8
|
+
|
|
9
|
+
- `/init` 扫描项目中的重要文件,可能提出针对性问题
|
|
10
|
+
- 如果已有 `AGENTS.md`,`/init` 会原地改进而非盲目替换
|
|
11
|
+
|
|
12
|
+
## 示例
|
|
13
|
+
|
|
14
|
+
手动创建 `AGENTS.md`:
|
|
15
|
+
|
|
16
|
+
```md
|
|
17
|
+
# SST v3 Monorepo Project
|
|
18
|
+
|
|
19
|
+
This is an SST v3 monorepo with TypeScript. The project uses bun workspaces for package management.
|
|
20
|
+
|
|
21
|
+
## Project Structure
|
|
22
|
+
|
|
23
|
+
- `packages/` - Contains all workspace packages (functions, core, web, etc.)
|
|
24
|
+
- `infra/` - Infrastructure definitions split by service (storage.ts, api.ts, web.ts)
|
|
25
|
+
- `sst.config.ts` - Main SST configuration with dynamic imports
|
|
26
|
+
|
|
27
|
+
## Code Standards
|
|
28
|
+
|
|
29
|
+
- Use TypeScript with strict mode enabled
|
|
30
|
+
- Shared code goes in `packages/core/` with proper exports configuration
|
|
31
|
+
- Functions go in `packages/functions/`
|
|
32
|
+
- Infrastructure should be split into logical files in `infra/`
|
|
33
|
+
|
|
34
|
+
## Monorepo Conventions
|
|
35
|
+
|
|
36
|
+
- Import shared modules using workspace names: `@my-app/core/example`
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 项目级规则
|
|
40
|
+
|
|
41
|
+
在项目根目录放置 `AGENTS.md`,仅对该项目生效。
|
|
42
|
+
|
|
43
|
+
## 全局规则
|
|
44
|
+
|
|
45
|
+
在 `~/.config/opencode/AGENTS.md` 放置全局规则,对所有 OpenCode 会话生效。
|
|
46
|
+
|
|
47
|
+
## 加载优先级
|
|
48
|
+
|
|
49
|
+
OpenCode 启动时按以下顺序查找规则文件:
|
|
50
|
+
|
|
51
|
+
1. 本地文件:从当前目录向上遍历查找 `AGENTS.md`
|
|
52
|
+
2. 全局文件:`~/.config/opencode/AGENTS.md`
|
|
53
|
+
|
|
54
|
+
## 自定义指令文件
|
|
55
|
+
|
|
56
|
+
在 `opencode.json` 或全局 `~/.config/opencode/opencode.json` 中指定自定义指令文件:
|
|
57
|
+
|
|
58
|
+
```jsonc
|
|
59
|
+
{
|
|
60
|
+
"$schema": "https://opencode.ai/config.json",
|
|
61
|
+
"instructions": ["CONTRIBUTING.md", "docs/guidelines.md", ".cursor/rules/*.md"]
|
|
62
|
+
}
|
|
63
|
+
```
|