@wwkit/harness 1.0.31 → 1.0.33

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.
Files changed (173) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +128 -128
  3. package/agents/scrum.md +186 -180
  4. package/agents/sprint.md +121 -118
  5. package/bin/index.js +226 -226
  6. package/commands/fix.md +87 -87
  7. package/commands/git-sync.md +217 -217
  8. package/commands/net-port.md +364 -364
  9. package/commands/pytest.md +10 -10
  10. package/commands/resume.md +104 -104
  11. package/commands/tl.md +11 -11
  12. package/package.json +8 -7
  13. package/plugin.js +19 -19
  14. package/readme/development.md +39 -39
  15. package/readme/publish.md +41 -41
  16. package/readme/testing.md +44 -36
  17. package/scripts/postinstall.js +58 -58
  18. package/skills/better-skill/SKILL.md +124 -124
  19. package/skills/blame-skill/SKILL.md +201 -201
  20. package/skills/extract/SKILL.md +119 -119
  21. package/skills/extract/references/build-xpath.js +30 -30
  22. package/skills/extract/references/clean-html.js +90 -90
  23. package/skills/extract/references/detail.md +54 -54
  24. package/skills/extract/references/detail.schema.json5 +48 -48
  25. package/skills/extract/references/extract-detail.js +71 -71
  26. package/skills/extract/references/extract-regex.js +81 -81
  27. package/skills/extract/references/extract-sample.js +48 -48
  28. package/skills/extract/references/list-rule-gen.md +109 -109
  29. package/skills/extract/references/list.md +134 -134
  30. package/skills/extract/references/list.schema.json5 +33 -33
  31. package/skills/extract/references/navi.md +44 -44
  32. package/skills/extract/references/navi.schema.json5 +23 -23
  33. package/skills/extract/references/text.md +40 -40
  34. package/skills/extract/references/text.schema.json5 +21 -21
  35. package/skills/extract/references/to-text.js +20 -20
  36. package/skills/extract/references/validate-schema.js +39 -39
  37. package/skills/jstest/SKILL.md +561 -561
  38. package/skills/jstest/references/case-create.md +327 -327
  39. package/skills/jstest/references/case-fix.md +273 -273
  40. package/skills/jstest/references/config.md +148 -148
  41. package/skills/jstest/references/coverage-analyze.md +247 -247
  42. package/skills/jstest/references/env-ensure.md +210 -210
  43. package/skills/jstest/references/execute.md +168 -168
  44. package/skills/jstest/references/sample.md +166 -166
  45. package/skills/jstest/references/scoring-rules.md +75 -75
  46. package/skills/jstest/references/src/jstest-sample/Calculator.js +80 -80
  47. package/skills/jstest/references/src/jstest-sample/ConfigManager.js +72 -72
  48. package/skills/jstest/references/src/jstest-sample/FileProcessor.js +57 -57
  49. package/skills/jstest/references/src/jstest-sample/OrderService.js +98 -98
  50. package/skills/jstest/references/src/jstest-sample/TokenGenerator.js +60 -60
  51. package/skills/jstest/references/src/jstest-sample/UserService.js +56 -56
  52. package/skills/jstest/references/src/jstest-sample/index.js +6 -6
  53. package/skills/jstest/references/suitability-check.md +232 -232
  54. package/skills/jstest/references/test-standards.md +288 -288
  55. package/skills/lint/SKILL.md +440 -440
  56. package/skills/lint/references/ai-fix.md +137 -137
  57. package/skills/lint/references/config-setup.md +102 -102
  58. package/skills/lint/references/config.md +65 -65
  59. package/skills/lint/references/detect-language.js +65 -65
  60. package/skills/lint/references/env-ensure.md +88 -88
  61. package/skills/lint/references/language-detect.md +75 -75
  62. package/skills/lint/references/languages/js.md +110 -110
  63. package/skills/lint/references/languages/py.md +89 -89
  64. package/skills/lint/references/rules-analyze.md +125 -125
  65. package/skills/lint/references/suitability-check.md +81 -81
  66. package/skills/lint/references/tool-fix.md +90 -90
  67. package/skills/new-skill/SKILL.md +227 -227
  68. package/skills/new-skill/references/template.md +53 -53
  69. package/skills/new-skill/references/workflow-patterns.md +104 -104
  70. package/skills/pytest/SKILL.md +555 -555
  71. package/skills/pytest/references/case-create.md +324 -324
  72. package/skills/pytest/references/case-fix.md +271 -271
  73. package/skills/pytest/references/config.md +145 -145
  74. package/skills/pytest/references/coverage-analyze.md +223 -223
  75. package/skills/pytest/references/env-ensure.md +195 -195
  76. package/skills/pytest/references/execute.md +152 -152
  77. package/skills/pytest/references/sample.md +159 -159
  78. package/skills/pytest/references/scoring-rules.md +57 -57
  79. package/skills/pytest/references/src/pytest-sample/Calculator.py +67 -67
  80. package/skills/pytest/references/src/pytest-sample/ConfigManager.py +68 -68
  81. package/skills/pytest/references/src/pytest-sample/FileProcessor.py +53 -53
  82. package/skills/pytest/references/src/pytest-sample/OrderService.py +82 -82
  83. package/skills/pytest/references/src/pytest-sample/TokenGenerator.py +50 -50
  84. package/skills/pytest/references/src/pytest-sample/UserService.py +45 -45
  85. package/skills/pytest/references/suitability-check.md +220 -220
  86. package/skills/pytest/references/test-standards.md +244 -244
  87. package/skills/query/SKILL.md +71 -71
  88. package/skills/read-docs/SKILL.md +134 -134
  89. package/skills/read-docs/references/opencode/agents/cases.md +206 -206
  90. package/skills/read-docs/references/opencode/agents/design-pattern.md +47 -47
  91. package/skills/read-docs/references/opencode/agents/detail.md +191 -191
  92. package/skills/read-docs/references/opencode/agents/examples.md +100 -100
  93. package/skills/read-docs/references/opencode/agents/index.md +309 -309
  94. package/skills/read-docs/references/opencode/agents/parallel-dispatch.md +149 -149
  95. package/skills/read-docs/references/opencode/agents/subagent-internals.md +217 -217
  96. package/skills/read-docs/references/opencode/agents/workflow.md +161 -161
  97. package/skills/read-docs/references/opencode/cli/commands/acp.md +31 -31
  98. package/skills/read-docs/references/opencode/cli/commands/agent.md +16 -16
  99. package/skills/read-docs/references/opencode/cli/commands/attach.md +20 -20
  100. package/skills/read-docs/references/opencode/cli/commands/mcp.md +37 -37
  101. package/skills/read-docs/references/opencode/cli/commands/others.md +48 -48
  102. package/skills/read-docs/references/opencode/cli/commands/plugin.md +12 -12
  103. package/skills/read-docs/references/opencode/cli/commands/provider.md +43 -43
  104. package/skills/read-docs/references/opencode/cli/commands/run.md +81 -81
  105. package/skills/read-docs/references/opencode/cli/commands/serve.md +84 -84
  106. package/skills/read-docs/references/opencode/cli/commands/session.md +37 -37
  107. package/skills/read-docs/references/opencode/cli/commands/web.md +14 -14
  108. package/skills/read-docs/references/opencode/cli/env.md +38 -38
  109. package/skills/read-docs/references/opencode/cli/index.md +18 -18
  110. package/skills/read-docs/references/opencode/cli/tui.md +35 -35
  111. package/skills/read-docs/references/opencode/commands/examples.md +42 -42
  112. package/skills/read-docs/references/opencode/commands/index.md +185 -185
  113. package/skills/read-docs/references/opencode/config/provider.md +151 -151
  114. package/skills/read-docs/references/opencode/formatter/index.md +70 -70
  115. package/skills/read-docs/references/opencode/guide/config.md +419 -419
  116. package/skills/read-docs/references/opencode/guide/formatters.md +70 -70
  117. package/skills/read-docs/references/opencode/guide/index.md +37 -37
  118. package/skills/read-docs/references/opencode/guide/providers.md +31 -31
  119. package/skills/read-docs/references/opencode/guide/rules.md +63 -63
  120. package/skills/read-docs/references/opencode/plugins/examples.md +75 -75
  121. package/skills/read-docs/references/opencode/plugins/index.md +188 -188
  122. package/skills/read-docs/references/opencode/reference/index.md +118 -118
  123. package/skills/read-docs/references/opencode/rule/index.md +77 -77
  124. package/skills/read-docs/references/opencode/skills/detail.md +113 -113
  125. package/skills/read-docs/references/opencode/skills/examples.md +141 -141
  126. package/skills/read-docs/references/opencode/skills/index.md +126 -126
  127. package/skills/read-docs/references/opencode/skills/workflow.md +146 -146
  128. package/skills/read-docs/references/opencode/tests/agent.md +9 -9
  129. package/skills/read-docs/references/opencode/tests/config.md +59 -59
  130. package/skills/read-docs/references/opencode/tests/file.md +11 -11
  131. package/skills/read-docs/references/opencode/tests/serve.md +17 -17
  132. package/skills/read-docs/references/opencode/tests/session.md +30 -30
  133. package/skills/read-docs/references/opencode/tests/web.md +16 -16
  134. package/skills/read-docs/references/opencode/tools/arguments.md +305 -305
  135. package/skills/read-docs/references/opencode/tools/context.md +17 -17
  136. package/skills/read-docs/references/opencode/tools/custom.md +110 -110
  137. package/skills/read-docs/references/opencode/tools/detail.md +104 -104
  138. package/skills/read-docs/references/opencode/tools/examples.md +71 -71
  139. package/skills/read-docs/references/opencode/tools/index.md +56 -56
  140. package/skills/read-docs/references/opencode/tools/lsp.md +25 -25
  141. package/skills/read-docs/references/opencode/tools/mcp.md +132 -132
  142. package/skills/read-docs/references/opencode/train/README.md +134 -134
  143. package/skills/read-docs/references/opencode/train/agent-basic.md +771 -771
  144. package/skills/read-docs/references/opencode/train/command-basic.md +667 -667
  145. package/skills/read-docs/references/opencode/train/config-basic.md +508 -508
  146. package/skills/read-docs/references/opencode/train/index.md +163 -163
  147. package/skills/read-docs/references/opencode/train/practice.md +872 -872
  148. package/skills/read-docs/references/opencode/train/skill-basic.md +607 -607
  149. package/skills/read-docs/references/opencode/tui/commands/config.md +31 -31
  150. package/skills/read-docs/references/opencode/tui/commands/editor.md +46 -46
  151. package/skills/read-docs/references/opencode/tui/commands/index.md +124 -124
  152. package/skills/read-docs/references/opencode/tui/commands/init.md +4 -4
  153. package/skills/read-docs/references/opencode/tui/index.md +26 -26
  154. package/skills/read-docs/references/superpowers/bootstrap.md +107 -107
  155. package/skills/read-docs/references/superpowers/comparison.md +77 -77
  156. package/skills/read-docs/references/superpowers/context.md +71 -71
  157. package/skills/read-docs/references/superpowers/index.md +58 -58
  158. package/skills/read-docs/references/superpowers/parallel.md +49 -49
  159. package/skills/read-docs/references/superpowers/sdd.md +183 -183
  160. package/skills/read-docs/references/superpowers/skills.md +68 -68
  161. package/skills/read-docs/references/superpowers/workflow.md +83 -83
  162. package/skills/revise/SKILL.md +121 -121
  163. package/skills/revise/references/article.md +36 -36
  164. package/skills/revise/references/article.schema.json5 +40 -40
  165. package/skills/revise/references/gallery.md +34 -34
  166. package/skills/revise/references/gallery.schema.json5 +40 -40
  167. package/skills/revise/references/question.md +32 -32
  168. package/skills/revise/references/question.schema.json5 +31 -31
  169. package/skills/revise/references/status.md +31 -31
  170. package/skills/revise/references/status.schema.json5 +27 -27
  171. package/skills/revise/references/validate-schema.js +39 -39
  172. package/src/config.js +29 -29
  173. package/src/config.json5 +19 -19
@@ -1,419 +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
- ```
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
+ ```