alchemylab-opencode 1.0.6 → 1.0.8

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 (413) hide show
  1. package/dist/arktype-aI7TBD0R-HX4BR3RX.js +21 -0
  2. package/dist/arktype-aI7TBD0R-HX4BR3RX.js.map +7 -0
  3. package/dist/{chunk-UWZSRZHA.js → chunk-23UYOGZG.js} +817 -315
  4. package/dist/chunk-23UYOGZG.js.map +7 -0
  5. package/dist/chunk-3AF5MXLF.js +49 -0
  6. package/dist/chunk-3AF5MXLF.js.map +7 -0
  7. package/dist/chunk-FMP3YLWX.js +30 -0
  8. package/dist/chunk-FMP3YLWX.js.map +7 -0
  9. package/dist/{chunk-ANDTK76Q.js → chunk-GSE2T5UY.js} +3 -3
  10. package/dist/{chunk-CYXMV3J3.js → chunk-LU5XVQUD.js} +4 -4
  11. package/dist/chunk-O5VWOPCL.js +106 -0
  12. package/dist/chunk-O5VWOPCL.js.map +7 -0
  13. package/dist/chunk-PWFRMDDF.js +12 -0
  14. package/dist/{chunk-DSPC5QIG.js → chunk-SM6WZDN6.js} +9 -9
  15. package/dist/{chunk-MCWTARFP.js → chunk-TASPMBUL.js} +4 -4
  16. package/dist/chunk-VL3RSEZ2.js +160 -0
  17. package/dist/chunk-VL3RSEZ2.js.map +7 -0
  18. package/dist/default-u_dwuiYb-WOFHQQ3K.js +22 -0
  19. package/dist/effect-QlVUlMFu-UERLUUQW.js +29 -0
  20. package/dist/effect-QlVUlMFu-UERLUUQW.js.map +7 -0
  21. package/dist/{mcp-VAU4RMWH.js → mcp-XFGN3FWW.js} +2 -2
  22. package/dist/{registry-PYMN6L3G.js → registry-W4MBVBYD.js} +3 -3
  23. package/dist/{run-YFVCQJQM.js → run-73HUV4H3.js} +9 -6
  24. package/dist/{run-YFVCQJQM.js.map → run-73HUV4H3.js.map} +1 -1
  25. package/dist/run.js +1 -1
  26. package/dist/serve.js +1 -1
  27. package/dist/{server-K3UGWASP.js → server-2CPOG3LS.js} +9 -6
  28. package/dist/{session-HJFWTM7C.js → session-M6HOZ56B.js} +3 -3
  29. package/dist/session-M6HOZ56B.js.map +7 -0
  30. package/dist/{share-next-55VCIMUH.js → share-next-QRBVSD37.js} +4 -4
  31. package/dist/share-next-QRBVSD37.js.map +7 -0
  32. package/dist/sury-CWZTCd75-XC3NCMTP.js +29 -0
  33. package/dist/sury-CWZTCd75-XC3NCMTP.js.map +7 -0
  34. package/dist/typebox-Dei93FPO-QOBKW4L7.js +21 -0
  35. package/dist/typebox-Dei93FPO-QOBKW4L7.js.map +7 -0
  36. package/dist/valibot--1zFm7rT-LHHLSLYY.js +29 -0
  37. package/dist/valibot--1zFm7rT-LHHLSLYY.js.map +7 -0
  38. package/dist/valibot-D_HTw1Gn-UR62BIDY.js +60 -0
  39. package/dist/valibot-D_HTw1Gn-UR62BIDY.js.map +7 -0
  40. package/dist/{worktree-6GGDLADY.js → worktree-3GUHT2P7.js} +5 -5
  41. package/dist/zod-Bwrt9trS-J2GOMA2R.js +43 -0
  42. package/dist/zod-Bwrt9trS-J2GOMA2R.js.map +7 -0
  43. package/dist/zod-DSgpEGAE-VTXQW6SB.js +56 -0
  44. package/dist/zod-DSgpEGAE-VTXQW6SB.js.map +7 -0
  45. package/package.json +2 -15
  46. package/build.mjs +0 -182
  47. package/dist/chunk-UWZSRZHA.js.map +0 -7
  48. package/packages/opencode/package.json +0 -138
  49. package/packages/opencode/src/account/account.sql.ts +0 -39
  50. package/packages/opencode/src/account/index.ts +0 -463
  51. package/packages/opencode/src/account/repo.ts +0 -163
  52. package/packages/opencode/src/account/schema.ts +0 -91
  53. package/packages/opencode/src/acp/README.md +0 -174
  54. package/packages/opencode/src/acp/agent.ts +0 -1847
  55. package/packages/opencode/src/acp/session.ts +0 -116
  56. package/packages/opencode/src/acp/types.ts +0 -24
  57. package/packages/opencode/src/agent/agent.ts +0 -420
  58. package/packages/opencode/src/agent/generate.txt +0 -75
  59. package/packages/opencode/src/agent/prompt/compaction.txt +0 -15
  60. package/packages/opencode/src/agent/prompt/explore.txt +0 -18
  61. package/packages/opencode/src/agent/prompt/summary.txt +0 -11
  62. package/packages/opencode/src/agent/prompt/title.txt +0 -44
  63. package/packages/opencode/src/auth/index.ts +0 -110
  64. package/packages/opencode/src/bus/bus-event.ts +0 -40
  65. package/packages/opencode/src/bus/global.ts +0 -10
  66. package/packages/opencode/src/bus/index.ts +0 -185
  67. package/packages/opencode/src/cli/bootstrap.ts +0 -17
  68. package/packages/opencode/src/cli/cmd/cmd.ts +0 -7
  69. package/packages/opencode/src/cli/cmd/run.ts +0 -689
  70. package/packages/opencode/src/cli/cmd/serve.ts +0 -24
  71. package/packages/opencode/src/cli/cmd/tui/event.ts +0 -49
  72. package/packages/opencode/src/cli/effect/prompt.ts +0 -25
  73. package/packages/opencode/src/cli/error.ts +0 -46
  74. package/packages/opencode/src/cli/heap.ts +0 -59
  75. package/packages/opencode/src/cli/logo.ts +0 -6
  76. package/packages/opencode/src/cli/network.ts +0 -60
  77. package/packages/opencode/src/cli/ui.ts +0 -133
  78. package/packages/opencode/src/cli/upgrade.ts +0 -31
  79. package/packages/opencode/src/command/index.ts +0 -195
  80. package/packages/opencode/src/command/template/initialize.txt +0 -66
  81. package/packages/opencode/src/command/template/review.txt +0 -101
  82. package/packages/opencode/src/config/config.ts +0 -1599
  83. package/packages/opencode/src/config/console-state.ts +0 -15
  84. package/packages/opencode/src/config/markdown.ts +0 -99
  85. package/packages/opencode/src/config/paths.ts +0 -167
  86. package/packages/opencode/src/config/tui-migrate.ts +0 -155
  87. package/packages/opencode/src/config/tui-schema.ts +0 -37
  88. package/packages/opencode/src/config/tui.ts +0 -179
  89. package/packages/opencode/src/control-plane/adaptors/index.ts +0 -20
  90. package/packages/opencode/src/control-plane/adaptors/worktree.ts +0 -42
  91. package/packages/opencode/src/control-plane/schema.ts +0 -17
  92. package/packages/opencode/src/control-plane/sse.ts +0 -66
  93. package/packages/opencode/src/control-plane/types.ts +0 -32
  94. package/packages/opencode/src/control-plane/workspace.sql.ts +0 -17
  95. package/packages/opencode/src/control-plane/workspace.ts +0 -168
  96. package/packages/opencode/src/effect/cross-spawn-spawner.ts +0 -502
  97. package/packages/opencode/src/effect/instance-ref.ts +0 -6
  98. package/packages/opencode/src/effect/instance-registry.ts +0 -12
  99. package/packages/opencode/src/effect/instance-state.ts +0 -82
  100. package/packages/opencode/src/effect/run-service.ts +0 -33
  101. package/packages/opencode/src/effect/runner.ts +0 -216
  102. package/packages/opencode/src/env/index.ts +0 -28
  103. package/packages/opencode/src/file/ignore.ts +0 -82
  104. package/packages/opencode/src/file/index.ts +0 -686
  105. package/packages/opencode/src/file/protected.ts +0 -59
  106. package/packages/opencode/src/file/ripgrep.ts +0 -376
  107. package/packages/opencode/src/file/time.ts +0 -133
  108. package/packages/opencode/src/file/watcher.ts +0 -173
  109. package/packages/opencode/src/filesystem/index.ts +0 -236
  110. package/packages/opencode/src/flag/flag.ts +0 -156
  111. package/packages/opencode/src/format/formatter.ts +0 -413
  112. package/packages/opencode/src/format/index.ts +0 -203
  113. package/packages/opencode/src/git/index.ts +0 -303
  114. package/packages/opencode/src/global/index.ts +0 -56
  115. package/packages/opencode/src/id/id.ts +0 -85
  116. package/packages/opencode/src/ide/index.ts +0 -74
  117. package/packages/opencode/src/installation/index.ts +0 -355
  118. package/packages/opencode/src/installation/meta.ts +0 -7
  119. package/packages/opencode/src/lsp/client.ts +0 -252
  120. package/packages/opencode/src/lsp/index.ts +0 -558
  121. package/packages/opencode/src/lsp/language.ts +0 -120
  122. package/packages/opencode/src/lsp/launch.ts +0 -21
  123. package/packages/opencode/src/lsp/server.ts +0 -1968
  124. package/packages/opencode/src/mcp/auth.ts +0 -173
  125. package/packages/opencode/src/mcp/index.ts +0 -931
  126. package/packages/opencode/src/mcp/oauth-callback.ts +0 -216
  127. package/packages/opencode/src/mcp/oauth-provider.ts +0 -185
  128. package/packages/opencode/src/node-loader.mjs +0 -104
  129. package/packages/opencode/src/node-preload.mjs +0 -39
  130. package/packages/opencode/src/node.ts +0 -1
  131. package/packages/opencode/src/npm/index.ts +0 -188
  132. package/packages/opencode/src/patch/index.ts +0 -680
  133. package/packages/opencode/src/permission/arity.ts +0 -163
  134. package/packages/opencode/src/permission/evaluate.ts +0 -15
  135. package/packages/opencode/src/permission/index.ts +0 -325
  136. package/packages/opencode/src/permission/schema.ts +0 -17
  137. package/packages/opencode/src/plugin/cloudflare.ts +0 -67
  138. package/packages/opencode/src/plugin/codex.ts +0 -608
  139. package/packages/opencode/src/plugin/github-copilot/copilot.ts +0 -361
  140. package/packages/opencode/src/plugin/github-copilot/models.ts +0 -144
  141. package/packages/opencode/src/plugin/index.ts +0 -299
  142. package/packages/opencode/src/plugin/install.ts +0 -439
  143. package/packages/opencode/src/plugin/loader.ts +0 -174
  144. package/packages/opencode/src/plugin/meta.ts +0 -188
  145. package/packages/opencode/src/plugin/shared.ts +0 -323
  146. package/packages/opencode/src/project/bootstrap.ts +0 -31
  147. package/packages/opencode/src/project/instance.ts +0 -175
  148. package/packages/opencode/src/project/project.sql.ts +0 -16
  149. package/packages/opencode/src/project/project.ts +0 -519
  150. package/packages/opencode/src/project/schema.ts +0 -16
  151. package/packages/opencode/src/project/state.ts +0 -70
  152. package/packages/opencode/src/project/vcs.ts +0 -240
  153. package/packages/opencode/src/provider/auth.ts +0 -253
  154. package/packages/opencode/src/provider/error.ts +0 -197
  155. package/packages/opencode/src/provider/models.ts +0 -162
  156. package/packages/opencode/src/provider/provider.ts +0 -1709
  157. package/packages/opencode/src/provider/schema.ts +0 -38
  158. package/packages/opencode/src/provider/sdk/copilot/README.md +0 -5
  159. package/packages/opencode/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +0 -170
  160. package/packages/opencode/src/provider/sdk/copilot/chat/get-response-metadata.ts +0 -15
  161. package/packages/opencode/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +0 -19
  162. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +0 -64
  163. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +0 -815
  164. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +0 -28
  165. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +0 -44
  166. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +0 -83
  167. package/packages/opencode/src/provider/sdk/copilot/copilot-provider.ts +0 -100
  168. package/packages/opencode/src/provider/sdk/copilot/index.ts +0 -2
  169. package/packages/opencode/src/provider/sdk/copilot/openai-compatible-error.ts +0 -27
  170. package/packages/opencode/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +0 -335
  171. package/packages/opencode/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +0 -22
  172. package/packages/opencode/src/provider/sdk/copilot/responses/openai-config.ts +0 -18
  173. package/packages/opencode/src/provider/sdk/copilot/responses/openai-error.ts +0 -22
  174. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +0 -214
  175. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +0 -1769
  176. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +0 -173
  177. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-settings.ts +0 -1
  178. package/packages/opencode/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +0 -87
  179. package/packages/opencode/src/provider/sdk/copilot/responses/tool/file-search.ts +0 -127
  180. package/packages/opencode/src/provider/sdk/copilot/responses/tool/image-generation.ts +0 -114
  181. package/packages/opencode/src/provider/sdk/copilot/responses/tool/local-shell.ts +0 -64
  182. package/packages/opencode/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +0 -103
  183. package/packages/opencode/src/provider/sdk/copilot/responses/tool/web-search.ts +0 -102
  184. package/packages/opencode/src/provider/transform.ts +0 -1050
  185. package/packages/opencode/src/pty/index.ts +0 -397
  186. package/packages/opencode/src/pty/pty.node.ts +0 -27
  187. package/packages/opencode/src/pty/pty.ts +0 -25
  188. package/packages/opencode/src/pty/schema.ts +0 -17
  189. package/packages/opencode/src/question/index.ts +0 -224
  190. package/packages/opencode/src/question/schema.ts +0 -17
  191. package/packages/opencode/src/run.ts +0 -28
  192. package/packages/opencode/src/serve.ts +0 -45
  193. package/packages/opencode/src/server/error.ts +0 -36
  194. package/packages/opencode/src/server/event.ts +0 -7
  195. package/packages/opencode/src/server/instance.ts +0 -324
  196. package/packages/opencode/src/server/mdns.ts +0 -60
  197. package/packages/opencode/src/server/middleware.ts +0 -33
  198. package/packages/opencode/src/server/projectors.ts +0 -28
  199. package/packages/opencode/src/server/proxy.ts +0 -131
  200. package/packages/opencode/src/server/router.ts +0 -105
  201. package/packages/opencode/src/server/routes/config.ts +0 -92
  202. package/packages/opencode/src/server/routes/event.ts +0 -83
  203. package/packages/opencode/src/server/routes/experimental.ts +0 -374
  204. package/packages/opencode/src/server/routes/file.ts +0 -197
  205. package/packages/opencode/src/server/routes/global.ts +0 -312
  206. package/packages/opencode/src/server/routes/mcp.ts +0 -225
  207. package/packages/opencode/src/server/routes/permission.ts +0 -69
  208. package/packages/opencode/src/server/routes/project.ts +0 -118
  209. package/packages/opencode/src/server/routes/provider.ts +0 -171
  210. package/packages/opencode/src/server/routes/pty.ts +0 -210
  211. package/packages/opencode/src/server/routes/question.ts +0 -99
  212. package/packages/opencode/src/server/routes/session.ts +0 -1030
  213. package/packages/opencode/src/server/routes/tui.ts +0 -379
  214. package/packages/opencode/src/server/routes/workspace.ts +0 -94
  215. package/packages/opencode/src/server/server.ts +0 -353
  216. package/packages/opencode/src/session/compaction.ts +0 -428
  217. package/packages/opencode/src/session/index.ts +0 -887
  218. package/packages/opencode/src/session/instruction.ts +0 -258
  219. package/packages/opencode/src/session/llm.ts +0 -354
  220. package/packages/opencode/src/session/message-v2.ts +0 -1031
  221. package/packages/opencode/src/session/message.ts +0 -191
  222. package/packages/opencode/src/session/overflow.ts +0 -22
  223. package/packages/opencode/src/session/processor.ts +0 -523
  224. package/packages/opencode/src/session/projectors.ts +0 -135
  225. package/packages/opencode/src/session/prompt/anthropic.txt +0 -105
  226. package/packages/opencode/src/session/prompt/beast.txt +0 -147
  227. package/packages/opencode/src/session/prompt/build-switch.txt +0 -5
  228. package/packages/opencode/src/session/prompt/codex.txt +0 -79
  229. package/packages/opencode/src/session/prompt/copilot-gpt-5.txt +0 -143
  230. package/packages/opencode/src/session/prompt/default.txt +0 -105
  231. package/packages/opencode/src/session/prompt/gemini.txt +0 -155
  232. package/packages/opencode/src/session/prompt/gpt.txt +0 -107
  233. package/packages/opencode/src/session/prompt/kimi.txt +0 -95
  234. package/packages/opencode/src/session/prompt/max-steps.txt +0 -16
  235. package/packages/opencode/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  236. package/packages/opencode/src/session/prompt/plan.txt +0 -26
  237. package/packages/opencode/src/session/prompt/trinity.txt +0 -97
  238. package/packages/opencode/src/session/prompt.ts +0 -1911
  239. package/packages/opencode/src/session/retry.ts +0 -106
  240. package/packages/opencode/src/session/revert.ts +0 -176
  241. package/packages/opencode/src/session/schema.ts +0 -38
  242. package/packages/opencode/src/session/session.sql.ts +0 -103
  243. package/packages/opencode/src/session/status.ts +0 -102
  244. package/packages/opencode/src/session/summary.ts +0 -177
  245. package/packages/opencode/src/session/system.ts +0 -76
  246. package/packages/opencode/src/session/todo.ts +0 -95
  247. package/packages/opencode/src/share/share-next.ts +0 -369
  248. package/packages/opencode/src/share/share.sql.ts +0 -13
  249. package/packages/opencode/src/shell/shell.ts +0 -110
  250. package/packages/opencode/src/skill/discovery.ts +0 -116
  251. package/packages/opencode/src/skill/index.ts +0 -277
  252. package/packages/opencode/src/snapshot/index.ts +0 -726
  253. package/packages/opencode/src/sql.d.ts +0 -4
  254. package/packages/opencode/src/storage/db.node.ts +0 -8
  255. package/packages/opencode/src/storage/db.ts +0 -177
  256. package/packages/opencode/src/storage/json-migration.ts +0 -425
  257. package/packages/opencode/src/storage/schema.sql.ts +0 -10
  258. package/packages/opencode/src/storage/schema.ts +0 -5
  259. package/packages/opencode/src/storage/storage.ts +0 -353
  260. package/packages/opencode/src/sync/README.md +0 -179
  261. package/packages/opencode/src/sync/event.sql.ts +0 -16
  262. package/packages/opencode/src/sync/index.ts +0 -263
  263. package/packages/opencode/src/sync/schema.ts +0 -14
  264. package/packages/opencode/src/tool/apply_patch.ts +0 -281
  265. package/packages/opencode/src/tool/apply_patch.txt +0 -33
  266. package/packages/opencode/src/tool/bash.ts +0 -496
  267. package/packages/opencode/src/tool/bash.txt +0 -117
  268. package/packages/opencode/src/tool/batch.ts +0 -183
  269. package/packages/opencode/src/tool/batch.txt +0 -24
  270. package/packages/opencode/src/tool/codesearch.ts +0 -132
  271. package/packages/opencode/src/tool/codesearch.txt +0 -12
  272. package/packages/opencode/src/tool/edit.ts +0 -667
  273. package/packages/opencode/src/tool/edit.txt +0 -10
  274. package/packages/opencode/src/tool/external-directory.ts +0 -46
  275. package/packages/opencode/src/tool/glob.ts +0 -78
  276. package/packages/opencode/src/tool/glob.txt +0 -6
  277. package/packages/opencode/src/tool/grep.ts +0 -156
  278. package/packages/opencode/src/tool/grep.txt +0 -8
  279. package/packages/opencode/src/tool/invalid.ts +0 -17
  280. package/packages/opencode/src/tool/ls.ts +0 -121
  281. package/packages/opencode/src/tool/ls.txt +0 -1
  282. package/packages/opencode/src/tool/lsp.ts +0 -97
  283. package/packages/opencode/src/tool/lsp.txt +0 -19
  284. package/packages/opencode/src/tool/multiedit.ts +0 -46
  285. package/packages/opencode/src/tool/multiedit.txt +0 -41
  286. package/packages/opencode/src/tool/plan-enter.txt +0 -14
  287. package/packages/opencode/src/tool/plan-exit.txt +0 -13
  288. package/packages/opencode/src/tool/plan.ts +0 -131
  289. package/packages/opencode/src/tool/question.ts +0 -46
  290. package/packages/opencode/src/tool/question.txt +0 -10
  291. package/packages/opencode/src/tool/read.ts +0 -332
  292. package/packages/opencode/src/tool/read.txt +0 -14
  293. package/packages/opencode/src/tool/registry.ts +0 -265
  294. package/packages/opencode/src/tool/schema.ts +0 -17
  295. package/packages/opencode/src/tool/skill.ts +0 -105
  296. package/packages/opencode/src/tool/task.ts +0 -166
  297. package/packages/opencode/src/tool/task.txt +0 -60
  298. package/packages/opencode/src/tool/todo.ts +0 -48
  299. package/packages/opencode/src/tool/todowrite.txt +0 -167
  300. package/packages/opencode/src/tool/tool.ts +0 -112
  301. package/packages/opencode/src/tool/truncate.ts +0 -144
  302. package/packages/opencode/src/tool/truncation-dir.ts +0 -4
  303. package/packages/opencode/src/tool/webfetch.ts +0 -206
  304. package/packages/opencode/src/tool/webfetch.txt +0 -13
  305. package/packages/opencode/src/tool/websearch.ts +0 -150
  306. package/packages/opencode/src/tool/websearch.txt +0 -14
  307. package/packages/opencode/src/tool/write.ts +0 -84
  308. package/packages/opencode/src/tool/write.txt +0 -8
  309. package/packages/opencode/src/util/abort.ts +0 -35
  310. package/packages/opencode/src/util/archive.ts +0 -17
  311. package/packages/opencode/src/util/color.ts +0 -19
  312. package/packages/opencode/src/util/context.ts +0 -25
  313. package/packages/opencode/src/util/data-url.ts +0 -9
  314. package/packages/opencode/src/util/defer.ts +0 -12
  315. package/packages/opencode/src/util/effect-http-client.ts +0 -11
  316. package/packages/opencode/src/util/effect-zod.ts +0 -98
  317. package/packages/opencode/src/util/error.ts +0 -77
  318. package/packages/opencode/src/util/filesystem.ts +0 -245
  319. package/packages/opencode/src/util/flock.ts +0 -333
  320. package/packages/opencode/src/util/fn.ts +0 -21
  321. package/packages/opencode/src/util/format.ts +0 -20
  322. package/packages/opencode/src/util/glob.ts +0 -34
  323. package/packages/opencode/src/util/hash.ts +0 -7
  324. package/packages/opencode/src/util/iife.ts +0 -3
  325. package/packages/opencode/src/util/keybind.ts +0 -103
  326. package/packages/opencode/src/util/lazy.ts +0 -23
  327. package/packages/opencode/src/util/locale.ts +0 -81
  328. package/packages/opencode/src/util/lock.ts +0 -98
  329. package/packages/opencode/src/util/log.ts +0 -182
  330. package/packages/opencode/src/util/network.ts +0 -9
  331. package/packages/opencode/src/util/process.ts +0 -176
  332. package/packages/opencode/src/util/queue.ts +0 -32
  333. package/packages/opencode/src/util/record.ts +0 -3
  334. package/packages/opencode/src/util/rpc.ts +0 -66
  335. package/packages/opencode/src/util/schema.ts +0 -53
  336. package/packages/opencode/src/util/scrap.ts +0 -10
  337. package/packages/opencode/src/util/signal.ts +0 -12
  338. package/packages/opencode/src/util/timeout.ts +0 -14
  339. package/packages/opencode/src/util/token.ts +0 -7
  340. package/packages/opencode/src/util/update-schema.ts +0 -13
  341. package/packages/opencode/src/util/which.ts +0 -14
  342. package/packages/opencode/src/util/wildcard.ts +0 -59
  343. package/packages/opencode/src/worktree/index.ts +0 -612
  344. package/packages/plugin/package.json +0 -38
  345. package/packages/plugin/src/example.ts +0 -18
  346. package/packages/plugin/src/index.ts +0 -282
  347. package/packages/plugin/src/shell.ts +0 -136
  348. package/packages/plugin/src/tool.ts +0 -38
  349. package/packages/plugin/src/tui.ts +0 -508
  350. package/packages/script/package.json +0 -16
  351. package/packages/script/src/index.ts +0 -77
  352. package/packages/sdk/package.json +0 -33
  353. package/packages/sdk/src/client.ts +0 -55
  354. package/packages/sdk/src/gen/client/client.gen.ts +0 -212
  355. package/packages/sdk/src/gen/client/index.ts +0 -25
  356. package/packages/sdk/src/gen/client/types.gen.ts +0 -222
  357. package/packages/sdk/src/gen/client/utils.gen.ts +0 -287
  358. package/packages/sdk/src/gen/client.gen.ts +0 -22
  359. package/packages/sdk/src/gen/core/auth.gen.ts +0 -41
  360. package/packages/sdk/src/gen/core/bodySerializer.gen.ts +0 -74
  361. package/packages/sdk/src/gen/core/params.gen.ts +0 -144
  362. package/packages/sdk/src/gen/core/pathSerializer.gen.ts +0 -167
  363. package/packages/sdk/src/gen/core/queryKeySerializer.gen.ts +0 -111
  364. package/packages/sdk/src/gen/core/serverSentEvents.gen.ts +0 -210
  365. package/packages/sdk/src/gen/core/types.gen.ts +0 -91
  366. package/packages/sdk/src/gen/core/utils.gen.ts +0 -109
  367. package/packages/sdk/src/gen/sdk.gen.ts +0 -1197
  368. package/packages/sdk/src/gen/types.gen.ts +0 -3904
  369. package/packages/sdk/src/index.ts +0 -21
  370. package/packages/sdk/src/process.ts +0 -31
  371. package/packages/sdk/src/server.ts +0 -134
  372. package/packages/sdk/src/v2/client.ts +0 -81
  373. package/packages/sdk/src/v2/gen/client/client.gen.ts +0 -285
  374. package/packages/sdk/src/v2/gen/client/index.ts +0 -25
  375. package/packages/sdk/src/v2/gen/client/types.gen.ts +0 -202
  376. package/packages/sdk/src/v2/gen/client/utils.gen.ts +0 -289
  377. package/packages/sdk/src/v2/gen/client.gen.ts +0 -18
  378. package/packages/sdk/src/v2/gen/core/auth.gen.ts +0 -41
  379. package/packages/sdk/src/v2/gen/core/bodySerializer.gen.ts +0 -82
  380. package/packages/sdk/src/v2/gen/core/params.gen.ts +0 -169
  381. package/packages/sdk/src/v2/gen/core/pathSerializer.gen.ts +0 -167
  382. package/packages/sdk/src/v2/gen/core/queryKeySerializer.gen.ts +0 -111
  383. package/packages/sdk/src/v2/gen/core/serverSentEvents.gen.ts +0 -239
  384. package/packages/sdk/src/v2/gen/core/types.gen.ts +0 -86
  385. package/packages/sdk/src/v2/gen/core/utils.gen.ts +0 -137
  386. package/packages/sdk/src/v2/gen/sdk.gen.ts +0 -4223
  387. package/packages/sdk/src/v2/gen/types.gen.ts +0 -5265
  388. package/packages/sdk/src/v2/index.ts +0 -21
  389. package/packages/sdk/src/v2/server.ts +0 -134
  390. package/packages/util/package.json +0 -20
  391. package/packages/util/src/array.ts +0 -10
  392. package/packages/util/src/binary.ts +0 -41
  393. package/packages/util/src/encode.ts +0 -51
  394. package/packages/util/src/error.ts +0 -54
  395. package/packages/util/src/fn.ts +0 -11
  396. package/packages/util/src/identifier.ts +0 -48
  397. package/packages/util/src/iife.ts +0 -3
  398. package/packages/util/src/lazy.ts +0 -11
  399. package/packages/util/src/module.ts +0 -10
  400. package/packages/util/src/path.ts +0 -37
  401. package/packages/util/src/retry.ts +0 -41
  402. package/packages/util/src/slug.ts +0 -74
  403. package/postinstall.cjs +0 -55
  404. /package/dist/{chunk-ANDTK76Q.js.map → chunk-GSE2T5UY.js.map} +0 -0
  405. /package/dist/{chunk-CYXMV3J3.js.map → chunk-LU5XVQUD.js.map} +0 -0
  406. /package/dist/{mcp-VAU4RMWH.js.map → chunk-PWFRMDDF.js.map} +0 -0
  407. /package/dist/{chunk-DSPC5QIG.js.map → chunk-SM6WZDN6.js.map} +0 -0
  408. /package/dist/{chunk-MCWTARFP.js.map → chunk-TASPMBUL.js.map} +0 -0
  409. /package/dist/{registry-PYMN6L3G.js.map → default-u_dwuiYb-WOFHQQ3K.js.map} +0 -0
  410. /package/dist/{server-K3UGWASP.js.map → mcp-XFGN3FWW.js.map} +0 -0
  411. /package/dist/{session-HJFWTM7C.js.map → registry-W4MBVBYD.js.map} +0 -0
  412. /package/dist/{share-next-55VCIMUH.js.map → server-2CPOG3LS.js.map} +0 -0
  413. /package/dist/{worktree-6GGDLADY.js.map → worktree-3GUHT2P7.js.map} +0 -0
@@ -1,1599 +0,0 @@
1
- import { Log } from "../util/log"
2
- import path from "path"
3
- import { pathToFileURL } from "url"
4
- import os from "os"
5
- import { Process } from "../util/process"
6
- import z from "zod"
7
- import { ModelsDev } from "../provider/models"
8
- import { mergeDeep, pipe, unique } from "remeda"
9
- import { Global } from "../global"
10
- import fsNode from "fs/promises"
11
- import { NamedError } from "@opencode-ai/util/error"
12
- import { Flag } from "../flag/flag"
13
- import { Auth } from "../auth"
14
- import { Env } from "../env"
15
- import {
16
- type ParseError as JsoncParseError,
17
- applyEdits,
18
- modify,
19
- parse as parseJsonc,
20
- printParseErrorCode,
21
- } from "jsonc-parser"
22
- import { Instance, type InstanceContext } from "../project/instance"
23
- import { LSPServer } from "../lsp/server"
24
- import { Installation } from "@/installation"
25
- import { ConfigMarkdown } from "./markdown"
26
- import { constants, existsSync } from "fs"
27
- import { Bus } from "@/bus"
28
- import { GlobalBus } from "@/bus/global"
29
- import { Event } from "../server/event"
30
- import { Glob } from "../util/glob"
31
- import { iife } from "@/util/iife"
32
- import { Account } from "@/account"
33
- import { isRecord } from "@/util/record"
34
- import { ConfigPaths } from "./paths"
35
- import { Filesystem } from "@/util/filesystem"
36
- import type { ConsoleState } from "./console-state"
37
- import { AppFileSystem } from "@/filesystem"
38
- import { InstanceState } from "@/effect/instance-state"
39
- import { makeRuntime } from "@/effect/run-service"
40
- import { Duration, Effect, Layer, Option, ServiceMap } from "effect"
41
- import { Flock } from "@/util/flock"
42
- import { isPathPluginSpec, parsePluginSpecifier, resolvePathPluginTarget } from "@/plugin/shared"
43
- import { Npm } from "@/npm"
44
-
45
- export namespace Config {
46
- const ModelId = z.string().meta({ $ref: "https://models.dev/model-schema.json#/$defs/Model" })
47
- const PluginOptions = z.record(z.string(), z.unknown())
48
- export const PluginSpec = z.union([z.string(), z.tuple([z.string(), PluginOptions])])
49
-
50
- export type PluginOptions = z.infer<typeof PluginOptions>
51
- export type PluginSpec = z.infer<typeof PluginSpec>
52
- export type PluginScope = "global" | "local"
53
- export type PluginOrigin = {
54
- spec: PluginSpec
55
- source: string
56
- scope: PluginScope
57
- }
58
-
59
- const log = Log.create({ service: "config" })
60
-
61
- // Managed settings directory for enterprise deployments (highest priority, admin-controlled)
62
- // These settings override all user and project settings
63
- function systemManagedConfigDir(): string {
64
- switch (process.platform) {
65
- case "darwin":
66
- return "/Library/Application Support/opencode"
67
- case "win32":
68
- return path.join(process.env.ProgramData || "C:\\ProgramData", "opencode")
69
- default:
70
- return "/etc/opencode"
71
- }
72
- }
73
-
74
- export function managedConfigDir() {
75
- return process.env.OPENCODE_TEST_MANAGED_CONFIG_DIR || systemManagedConfigDir()
76
- }
77
-
78
- const managedDir = managedConfigDir()
79
-
80
- const MANAGED_PLIST_DOMAIN = "ai.opencode.managed"
81
-
82
- // Keys injected by macOS/MDM into the managed plist that are not OpenCode config
83
- const PLIST_META = new Set([
84
- "PayloadDisplayName",
85
- "PayloadIdentifier",
86
- "PayloadType",
87
- "PayloadUUID",
88
- "PayloadVersion",
89
- "_manualProfile",
90
- ])
91
-
92
- /**
93
- * Parse raw JSON (from plutil conversion of a managed plist) into OpenCode config.
94
- * Strips MDM metadata keys before parsing through the config schema.
95
- * Pure function — no OS interaction, safe to unit test directly.
96
- */
97
- export function parseManagedPlist(json: string, source: string): Info {
98
- const raw = JSON.parse(json)
99
- for (const key of Object.keys(raw)) {
100
- if (PLIST_META.has(key)) delete raw[key]
101
- }
102
- return parseConfig(JSON.stringify(raw), source)
103
- }
104
-
105
- /**
106
- * Read macOS managed preferences deployed via .mobileconfig / MDM (Jamf, Kandji, etc).
107
- * MDM-installed profiles write to /Library/Managed Preferences/ which is only writable by root.
108
- * User-scoped plists are checked first, then machine-scoped.
109
- */
110
- async function readManagedPreferences(): Promise<Info> {
111
- if (process.platform !== "darwin") return {}
112
-
113
- const domain = MANAGED_PLIST_DOMAIN
114
- const user = os.userInfo().username
115
- const paths = [
116
- path.join("/Library/Managed Preferences", user, `${domain}.plist`),
117
- path.join("/Library/Managed Preferences", `${domain}.plist`),
118
- ]
119
-
120
- for (const plist of paths) {
121
- if (!existsSync(plist)) continue
122
- log.info("reading macOS managed preferences", { path: plist })
123
- const result = await Process.run(["plutil", "-convert", "json", "-o", "-", plist], { nothrow: true })
124
- if (result.code !== 0) {
125
- log.warn("failed to convert managed preferences plist", { path: plist })
126
- continue
127
- }
128
- return parseManagedPlist(result.stdout.toString(), `mobileconfig:${plist}`)
129
- }
130
- return {}
131
- }
132
-
133
- // Custom merge function that concatenates array fields instead of replacing them
134
- function mergeConfigConcatArrays(target: Info, source: Info): Info {
135
- const merged = mergeDeep(target, source)
136
- if (target.instructions && source.instructions) {
137
- merged.instructions = Array.from(new Set([...target.instructions, ...source.instructions]))
138
- }
139
- return merged
140
- }
141
-
142
- export type InstallInput = {
143
- signal?: AbortSignal
144
- waitTick?: (input: { dir: string; attempt: number; delay: number; waited: number }) => void | Promise<void>
145
- }
146
-
147
- export async function installDependencies(dir: string, input?: InstallInput) {
148
- if (!(await isWritable(dir))) return
149
- await using _ = await Flock.acquire(`config-install:${Filesystem.resolve(dir)}`, {
150
- signal: input?.signal,
151
- onWait: (tick) =>
152
- input?.waitTick?.({
153
- dir,
154
- attempt: tick.attempt,
155
- delay: tick.delay,
156
- waited: tick.waited,
157
- }),
158
- })
159
- input?.signal?.throwIfAborted()
160
-
161
- const pkg = path.join(dir, "package.json")
162
- const target = Installation.isLocal() ? "*" : Installation.VERSION
163
- const json = await Filesystem.readJson<{ dependencies?: Record<string, string> }>(pkg).catch(() => ({
164
- dependencies: {},
165
- }))
166
- json.dependencies = {
167
- ...json.dependencies,
168
- "@opencode-ai/plugin": target,
169
- }
170
- await Filesystem.writeJson(pkg, json)
171
-
172
- const gitignore = path.join(dir, ".gitignore")
173
- const ignore = await Filesystem.exists(gitignore)
174
- if (!ignore) {
175
- await Filesystem.write(
176
- gitignore,
177
- ["node_modules", "package.json", "package-lock.json", "bun.lock", ".gitignore"].join("\n"),
178
- )
179
- }
180
- await Npm.install(dir)
181
- }
182
-
183
- async function isWritable(dir: string) {
184
- try {
185
- await fsNode.access(dir, constants.W_OK)
186
- return true
187
- } catch {
188
- return false
189
- }
190
- }
191
-
192
- function rel(item: string, patterns: string[]) {
193
- const normalizedItem = item.replaceAll("\\", "/")
194
- for (const pattern of patterns) {
195
- const index = normalizedItem.indexOf(pattern)
196
- if (index === -1) continue
197
- return normalizedItem.slice(index + pattern.length)
198
- }
199
- }
200
-
201
- function trim(file: string) {
202
- const ext = path.extname(file)
203
- return ext.length ? file.slice(0, -ext.length) : file
204
- }
205
-
206
- async function loadCommand(dir: string) {
207
- const result: Record<string, Command> = {}
208
- for (const item of await Glob.scan("{command,commands}/**/*.md", {
209
- cwd: dir,
210
- absolute: true,
211
- dot: true,
212
- symlink: true,
213
- })) {
214
- const md = await ConfigMarkdown.parse(item).catch(async (err) => {
215
- const message = ConfigMarkdown.FrontmatterError.isInstance(err)
216
- ? err.data.message
217
- : `Failed to parse command ${item}`
218
- const { Session } = await import("@/session")
219
- Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() })
220
- log.error("failed to load command", { command: item, err })
221
- return undefined
222
- })
223
- if (!md) continue
224
-
225
- const patterns = ["/.opencode/command/", "/.opencode/commands/", "/command/", "/commands/"]
226
- const file = rel(item, patterns) ?? path.basename(item)
227
- const name = trim(file)
228
-
229
- const config = {
230
- name,
231
- ...md.data,
232
- template: md.content.trim(),
233
- }
234
- const parsed = Command.safeParse(config)
235
- if (parsed.success) {
236
- result[config.name] = parsed.data
237
- continue
238
- }
239
- throw new InvalidError({ path: item, issues: parsed.error.issues }, { cause: parsed.error })
240
- }
241
- return result
242
- }
243
-
244
- async function loadAgent(dir: string) {
245
- const result: Record<string, Agent> = {}
246
-
247
- for (const item of await Glob.scan("{agent,agents}/**/*.md", {
248
- cwd: dir,
249
- absolute: true,
250
- dot: true,
251
- symlink: true,
252
- })) {
253
- const md = await ConfigMarkdown.parse(item).catch(async (err) => {
254
- const message = ConfigMarkdown.FrontmatterError.isInstance(err)
255
- ? err.data.message
256
- : `Failed to parse agent ${item}`
257
- const { Session } = await import("@/session")
258
- Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() })
259
- log.error("failed to load agent", { agent: item, err })
260
- return undefined
261
- })
262
- if (!md) continue
263
-
264
- const patterns = ["/.opencode/agent/", "/.opencode/agents/", "/agent/", "/agents/"]
265
- const file = rel(item, patterns) ?? path.basename(item)
266
- const agentName = trim(file)
267
-
268
- const config = {
269
- name: agentName,
270
- ...md.data,
271
- prompt: md.content.trim(),
272
- }
273
- const parsed = Agent.safeParse(config)
274
- if (parsed.success) {
275
- result[config.name] = parsed.data
276
- continue
277
- }
278
- throw new InvalidError({ path: item, issues: parsed.error.issues }, { cause: parsed.error })
279
- }
280
- return result
281
- }
282
-
283
- async function loadMode(dir: string) {
284
- const result: Record<string, Agent> = {}
285
- for (const item of await Glob.scan("{mode,modes}/*.md", {
286
- cwd: dir,
287
- absolute: true,
288
- dot: true,
289
- symlink: true,
290
- })) {
291
- const md = await ConfigMarkdown.parse(item).catch(async (err) => {
292
- const message = ConfigMarkdown.FrontmatterError.isInstance(err)
293
- ? err.data.message
294
- : `Failed to parse mode ${item}`
295
- const { Session } = await import("@/session")
296
- Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() })
297
- log.error("failed to load mode", { mode: item, err })
298
- return undefined
299
- })
300
- if (!md) continue
301
-
302
- const config = {
303
- name: path.basename(item, ".md"),
304
- ...md.data,
305
- prompt: md.content.trim(),
306
- }
307
- const parsed = Agent.safeParse(config)
308
- if (parsed.success) {
309
- result[config.name] = {
310
- ...parsed.data,
311
- mode: "primary" as const,
312
- }
313
- continue
314
- }
315
- }
316
- return result
317
- }
318
-
319
- async function loadPlugin(dir: string) {
320
- const plugins: PluginSpec[] = []
321
-
322
- for (const item of await Glob.scan("{plugin,plugins}/*.{ts,js}", {
323
- cwd: dir,
324
- absolute: true,
325
- dot: true,
326
- symlink: true,
327
- })) {
328
- plugins.push(pathToFileURL(item).href)
329
- }
330
- return plugins
331
- }
332
-
333
- export function pluginSpecifier(plugin: PluginSpec): string {
334
- return Array.isArray(plugin) ? plugin[0] : plugin
335
- }
336
-
337
- export function pluginOptions(plugin: PluginSpec): PluginOptions | undefined {
338
- return Array.isArray(plugin) ? plugin[1] : undefined
339
- }
340
-
341
- export async function resolvePluginSpec(plugin: PluginSpec, configFilepath: string): Promise<PluginSpec> {
342
- const spec = pluginSpecifier(plugin)
343
- if (!isPathPluginSpec(spec)) return plugin
344
-
345
- const base = path.dirname(configFilepath)
346
- const file = (() => {
347
- if (spec.startsWith("file://")) return spec
348
- if (path.isAbsolute(spec) || /^[A-Za-z]:[\\/]/.test(spec)) return pathToFileURL(spec).href
349
- return pathToFileURL(path.resolve(base, spec)).href
350
- })()
351
-
352
- const resolved = await resolvePathPluginTarget(file).catch(() => file)
353
-
354
- if (Array.isArray(plugin)) return [resolved, plugin[1]]
355
- return resolved
356
- }
357
-
358
- export function deduplicatePluginOrigins(plugins: PluginOrigin[]): PluginOrigin[] {
359
- const seen = new Set<string>()
360
- const list: PluginOrigin[] = []
361
-
362
- for (const plugin of plugins.toReversed()) {
363
- const spec = pluginSpecifier(plugin.spec)
364
- const name = spec.startsWith("file://") ? spec : parsePluginSpecifier(spec).pkg
365
- if (seen.has(name)) continue
366
- seen.add(name)
367
- list.push(plugin)
368
- }
369
-
370
- return list.toReversed()
371
- }
372
-
373
- export const McpLocal = z
374
- .object({
375
- type: z.literal("local").describe("Type of MCP server connection"),
376
- command: z.string().array().describe("Command and arguments to run the MCP server"),
377
- environment: z
378
- .record(z.string(), z.string())
379
- .optional()
380
- .describe("Environment variables to set when running the MCP server"),
381
- enabled: z.boolean().optional().describe("Enable or disable the MCP server on startup"),
382
- timeout: z
383
- .number()
384
- .int()
385
- .positive()
386
- .optional()
387
- .describe("Timeout in ms for MCP server requests. Defaults to 5000 (5 seconds) if not specified."),
388
- })
389
- .strict()
390
- .meta({
391
- ref: "McpLocalConfig",
392
- })
393
-
394
- export const McpOAuth = z
395
- .object({
396
- clientId: z
397
- .string()
398
- .optional()
399
- .describe("OAuth client ID. If not provided, dynamic client registration (RFC 7591) will be attempted."),
400
- clientSecret: z.string().optional().describe("OAuth client secret (if required by the authorization server)"),
401
- scope: z.string().optional().describe("OAuth scopes to request during authorization"),
402
- })
403
- .strict()
404
- .meta({
405
- ref: "McpOAuthConfig",
406
- })
407
- export type McpOAuth = z.infer<typeof McpOAuth>
408
-
409
- export const McpRemote = z
410
- .object({
411
- type: z.literal("remote").describe("Type of MCP server connection"),
412
- url: z.string().describe("URL of the remote MCP server"),
413
- enabled: z.boolean().optional().describe("Enable or disable the MCP server on startup"),
414
- headers: z.record(z.string(), z.string()).optional().describe("Headers to send with the request"),
415
- oauth: z
416
- .union([McpOAuth, z.literal(false)])
417
- .optional()
418
- .describe(
419
- "OAuth authentication configuration for the MCP server. Set to false to disable OAuth auto-detection.",
420
- ),
421
- timeout: z
422
- .number()
423
- .int()
424
- .positive()
425
- .optional()
426
- .describe("Timeout in ms for MCP server requests. Defaults to 5000 (5 seconds) if not specified."),
427
- })
428
- .strict()
429
- .meta({
430
- ref: "McpRemoteConfig",
431
- })
432
-
433
- export const Mcp = z.discriminatedUnion("type", [McpLocal, McpRemote])
434
- export type Mcp = z.infer<typeof Mcp>
435
-
436
- export const PermissionAction = z.enum(["ask", "allow", "deny"]).meta({
437
- ref: "PermissionActionConfig",
438
- })
439
- export type PermissionAction = z.infer<typeof PermissionAction>
440
-
441
- export const PermissionObject = z.record(z.string(), PermissionAction).meta({
442
- ref: "PermissionObjectConfig",
443
- })
444
- export type PermissionObject = z.infer<typeof PermissionObject>
445
-
446
- export const PermissionRule = z.union([PermissionAction, PermissionObject]).meta({
447
- ref: "PermissionRuleConfig",
448
- })
449
- export type PermissionRule = z.infer<typeof PermissionRule>
450
-
451
- // Capture original key order before zod reorders, then rebuild in original order
452
- const permissionPreprocess = (val: unknown) => {
453
- if (typeof val === "object" && val !== null && !Array.isArray(val)) {
454
- return { __originalKeys: Object.keys(val), ...val }
455
- }
456
- return val
457
- }
458
-
459
- const permissionTransform = (x: unknown): Record<string, PermissionRule> => {
460
- if (typeof x === "string") return { "*": x as PermissionAction }
461
- const obj = x as { __originalKeys?: string[] } & Record<string, unknown>
462
- const { __originalKeys, ...rest } = obj
463
- if (!__originalKeys) return rest as Record<string, PermissionRule>
464
- const result: Record<string, PermissionRule> = {}
465
- for (const key of __originalKeys) {
466
- if (key in rest) result[key] = rest[key] as PermissionRule
467
- }
468
- return result
469
- }
470
-
471
- export const Permission = z
472
- .preprocess(
473
- permissionPreprocess,
474
- z
475
- .object({
476
- __originalKeys: z.string().array().optional(),
477
- read: PermissionRule.optional(),
478
- edit: PermissionRule.optional(),
479
- glob: PermissionRule.optional(),
480
- grep: PermissionRule.optional(),
481
- list: PermissionRule.optional(),
482
- bash: PermissionRule.optional(),
483
- task: PermissionRule.optional(),
484
- external_directory: PermissionRule.optional(),
485
- todowrite: PermissionAction.optional(),
486
- question: PermissionAction.optional(),
487
- webfetch: PermissionAction.optional(),
488
- websearch: PermissionAction.optional(),
489
- codesearch: PermissionAction.optional(),
490
- lsp: PermissionRule.optional(),
491
- doom_loop: PermissionAction.optional(),
492
- skill: PermissionRule.optional(),
493
- })
494
- .catchall(PermissionRule)
495
- .or(PermissionAction),
496
- )
497
- .transform(permissionTransform)
498
- .meta({
499
- ref: "PermissionConfig",
500
- })
501
- export type Permission = z.infer<typeof Permission>
502
-
503
- export const Command = z.object({
504
- template: z.string(),
505
- description: z.string().optional(),
506
- agent: z.string().optional(),
507
- model: ModelId.optional(),
508
- subtask: z.boolean().optional(),
509
- })
510
- export type Command = z.infer<typeof Command>
511
-
512
- export const Skills = z.object({
513
- paths: z.array(z.string()).optional().describe("Additional paths to skill folders"),
514
- urls: z
515
- .array(z.string())
516
- .optional()
517
- .describe("URLs to fetch skills from (e.g., https://example.com/.well-known/skills/)"),
518
- })
519
- export type Skills = z.infer<typeof Skills>
520
-
521
- export const Agent = z
522
- .object({
523
- model: ModelId.optional(),
524
- variant: z
525
- .string()
526
- .optional()
527
- .describe("Default model variant for this agent (applies only when using the agent's configured model)."),
528
- temperature: z.number().optional(),
529
- top_p: z.number().optional(),
530
- prompt: z.string().optional(),
531
- tools: z.record(z.string(), z.boolean()).optional().describe("@deprecated Use 'permission' field instead"),
532
- disable: z.boolean().optional(),
533
- description: z.string().optional().describe("Description of when to use the agent"),
534
- mode: z.enum(["subagent", "primary", "all"]).optional(),
535
- hidden: z
536
- .boolean()
537
- .optional()
538
- .describe("Hide this subagent from the @ autocomplete menu (default: false, only applies to mode: subagent)"),
539
- options: z.record(z.string(), z.any()).optional(),
540
- color: z
541
- .union([
542
- z.string().regex(/^#[0-9a-fA-F]{6}$/, "Invalid hex color format"),
543
- z.enum(["primary", "secondary", "accent", "success", "warning", "error", "info"]),
544
- ])
545
- .optional()
546
- .describe("Hex color code (e.g., #FF5733) or theme color (e.g., primary)"),
547
- steps: z
548
- .number()
549
- .int()
550
- .positive()
551
- .optional()
552
- .describe("Maximum number of agentic iterations before forcing text-only response"),
553
- maxSteps: z.number().int().positive().optional().describe("@deprecated Use 'steps' field instead."),
554
- permission: Permission.optional(),
555
- })
556
- .catchall(z.any())
557
- .transform((agent, ctx) => {
558
- const knownKeys = new Set([
559
- "name",
560
- "model",
561
- "variant",
562
- "prompt",
563
- "description",
564
- "temperature",
565
- "top_p",
566
- "mode",
567
- "hidden",
568
- "color",
569
- "steps",
570
- "maxSteps",
571
- "options",
572
- "permission",
573
- "disable",
574
- "tools",
575
- ])
576
-
577
- // Extract unknown properties into options
578
- const options: Record<string, unknown> = { ...agent.options }
579
- for (const [key, value] of Object.entries(agent)) {
580
- if (!knownKeys.has(key)) options[key] = value
581
- }
582
-
583
- // Convert legacy tools config to permissions
584
- const permission: Permission = {}
585
- for (const [tool, enabled] of Object.entries(agent.tools ?? {})) {
586
- const action = enabled ? "allow" : "deny"
587
- // write, edit, patch, multiedit all map to edit permission
588
- if (tool === "write" || tool === "edit" || tool === "patch" || tool === "multiedit") {
589
- permission.edit = action
590
- } else {
591
- permission[tool] = action
592
- }
593
- }
594
- Object.assign(permission, agent.permission)
595
-
596
- // Convert legacy maxSteps to steps
597
- const steps = agent.steps ?? agent.maxSteps
598
-
599
- return { ...agent, options, permission, steps } as typeof agent & {
600
- options?: Record<string, unknown>
601
- permission?: Permission
602
- steps?: number
603
- }
604
- })
605
- .meta({
606
- ref: "AgentConfig",
607
- })
608
- export type Agent = z.infer<typeof Agent>
609
-
610
- export const Keybinds = z
611
- .object({
612
- leader: z.string().optional().default("ctrl+x").describe("Leader key for keybind combinations"),
613
- app_exit: z.string().optional().default("ctrl+c,ctrl+d,<leader>q").describe("Exit the application"),
614
- editor_open: z.string().optional().default("<leader>e").describe("Open external editor"),
615
- theme_list: z.string().optional().default("<leader>t").describe("List available themes"),
616
- sidebar_toggle: z.string().optional().default("<leader>b").describe("Toggle sidebar"),
617
- scrollbar_toggle: z.string().optional().default("none").describe("Toggle session scrollbar"),
618
- username_toggle: z.string().optional().default("none").describe("Toggle username visibility"),
619
- status_view: z.string().optional().default("<leader>s").describe("View status"),
620
- session_export: z.string().optional().default("<leader>x").describe("Export session to editor"),
621
- session_new: z.string().optional().default("<leader>n").describe("Create a new session"),
622
- session_list: z.string().optional().default("<leader>l").describe("List all sessions"),
623
- session_timeline: z.string().optional().default("<leader>g").describe("Show session timeline"),
624
- session_fork: z.string().optional().default("none").describe("Fork session from message"),
625
- session_rename: z.string().optional().default("ctrl+r").describe("Rename session"),
626
- session_delete: z.string().optional().default("ctrl+d").describe("Delete session"),
627
- stash_delete: z.string().optional().default("ctrl+d").describe("Delete stash entry"),
628
- model_provider_list: z.string().optional().default("ctrl+a").describe("Open provider list from model dialog"),
629
- model_favorite_toggle: z.string().optional().default("ctrl+f").describe("Toggle model favorite status"),
630
- session_share: z.string().optional().default("none").describe("Share current session"),
631
- session_unshare: z.string().optional().default("none").describe("Unshare current session"),
632
- session_interrupt: z.string().optional().default("escape").describe("Interrupt current session"),
633
- session_compact: z.string().optional().default("<leader>c").describe("Compact the session"),
634
- messages_page_up: z.string().optional().default("pageup,ctrl+alt+b").describe("Scroll messages up by one page"),
635
- messages_page_down: z
636
- .string()
637
- .optional()
638
- .default("pagedown,ctrl+alt+f")
639
- .describe("Scroll messages down by one page"),
640
- messages_line_up: z.string().optional().default("ctrl+alt+y").describe("Scroll messages up by one line"),
641
- messages_line_down: z.string().optional().default("ctrl+alt+e").describe("Scroll messages down by one line"),
642
- messages_half_page_up: z.string().optional().default("ctrl+alt+u").describe("Scroll messages up by half page"),
643
- messages_half_page_down: z
644
- .string()
645
- .optional()
646
- .default("ctrl+alt+d")
647
- .describe("Scroll messages down by half page"),
648
- messages_first: z.string().optional().default("ctrl+g,home").describe("Navigate to first message"),
649
- messages_last: z.string().optional().default("ctrl+alt+g,end").describe("Navigate to last message"),
650
- messages_next: z.string().optional().default("none").describe("Navigate to next message"),
651
- messages_previous: z.string().optional().default("none").describe("Navigate to previous message"),
652
- messages_last_user: z.string().optional().default("none").describe("Navigate to last user message"),
653
- messages_copy: z.string().optional().default("<leader>y").describe("Copy message"),
654
- messages_undo: z.string().optional().default("<leader>u").describe("Undo message"),
655
- messages_redo: z.string().optional().default("<leader>r").describe("Redo message"),
656
- messages_toggle_conceal: z
657
- .string()
658
- .optional()
659
- .default("<leader>h")
660
- .describe("Toggle code block concealment in messages"),
661
- tool_details: z.string().optional().default("none").describe("Toggle tool details visibility"),
662
- model_list: z.string().optional().default("<leader>m").describe("List available models"),
663
- model_cycle_recent: z.string().optional().default("f2").describe("Next recently used model"),
664
- model_cycle_recent_reverse: z.string().optional().default("shift+f2").describe("Previous recently used model"),
665
- model_cycle_favorite: z.string().optional().default("none").describe("Next favorite model"),
666
- model_cycle_favorite_reverse: z.string().optional().default("none").describe("Previous favorite model"),
667
- command_list: z.string().optional().default("ctrl+p").describe("List available commands"),
668
- agent_list: z.string().optional().default("<leader>a").describe("List agents"),
669
- agent_cycle: z.string().optional().default("tab").describe("Next agent"),
670
- agent_cycle_reverse: z.string().optional().default("shift+tab").describe("Previous agent"),
671
- variant_cycle: z.string().optional().default("ctrl+t").describe("Cycle model variants"),
672
- input_clear: z.string().optional().default("ctrl+c").describe("Clear input field"),
673
- input_paste: z.string().optional().default("ctrl+v").describe("Paste from clipboard"),
674
- input_submit: z.string().optional().default("return").describe("Submit input"),
675
- input_newline: z
676
- .string()
677
- .optional()
678
- .default("shift+return,ctrl+return,alt+return,ctrl+j")
679
- .describe("Insert newline in input"),
680
- input_move_left: z.string().optional().default("left,ctrl+b").describe("Move cursor left in input"),
681
- input_move_right: z.string().optional().default("right,ctrl+f").describe("Move cursor right in input"),
682
- input_move_up: z.string().optional().default("up").describe("Move cursor up in input"),
683
- input_move_down: z.string().optional().default("down").describe("Move cursor down in input"),
684
- input_select_left: z.string().optional().default("shift+left").describe("Select left in input"),
685
- input_select_right: z.string().optional().default("shift+right").describe("Select right in input"),
686
- input_select_up: z.string().optional().default("shift+up").describe("Select up in input"),
687
- input_select_down: z.string().optional().default("shift+down").describe("Select down in input"),
688
- input_line_home: z.string().optional().default("ctrl+a").describe("Move to start of line in input"),
689
- input_line_end: z.string().optional().default("ctrl+e").describe("Move to end of line in input"),
690
- input_select_line_home: z
691
- .string()
692
- .optional()
693
- .default("ctrl+shift+a")
694
- .describe("Select to start of line in input"),
695
- input_select_line_end: z.string().optional().default("ctrl+shift+e").describe("Select to end of line in input"),
696
- input_visual_line_home: z.string().optional().default("alt+a").describe("Move to start of visual line in input"),
697
- input_visual_line_end: z.string().optional().default("alt+e").describe("Move to end of visual line in input"),
698
- input_select_visual_line_home: z
699
- .string()
700
- .optional()
701
- .default("alt+shift+a")
702
- .describe("Select to start of visual line in input"),
703
- input_select_visual_line_end: z
704
- .string()
705
- .optional()
706
- .default("alt+shift+e")
707
- .describe("Select to end of visual line in input"),
708
- input_buffer_home: z.string().optional().default("home").describe("Move to start of buffer in input"),
709
- input_buffer_end: z.string().optional().default("end").describe("Move to end of buffer in input"),
710
- input_select_buffer_home: z
711
- .string()
712
- .optional()
713
- .default("shift+home")
714
- .describe("Select to start of buffer in input"),
715
- input_select_buffer_end: z.string().optional().default("shift+end").describe("Select to end of buffer in input"),
716
- input_delete_line: z.string().optional().default("ctrl+shift+d").describe("Delete line in input"),
717
- input_delete_to_line_end: z.string().optional().default("ctrl+k").describe("Delete to end of line in input"),
718
- input_delete_to_line_start: z.string().optional().default("ctrl+u").describe("Delete to start of line in input"),
719
- input_backspace: z.string().optional().default("backspace,shift+backspace").describe("Backspace in input"),
720
- input_delete: z.string().optional().default("ctrl+d,delete,shift+delete").describe("Delete character in input"),
721
- input_undo: z.string().optional().default("ctrl+-,super+z").describe("Undo in input"),
722
- input_redo: z.string().optional().default("ctrl+.,super+shift+z").describe("Redo in input"),
723
- input_word_forward: z
724
- .string()
725
- .optional()
726
- .default("alt+f,alt+right,ctrl+right")
727
- .describe("Move word forward in input"),
728
- input_word_backward: z
729
- .string()
730
- .optional()
731
- .default("alt+b,alt+left,ctrl+left")
732
- .describe("Move word backward in input"),
733
- input_select_word_forward: z
734
- .string()
735
- .optional()
736
- .default("alt+shift+f,alt+shift+right")
737
- .describe("Select word forward in input"),
738
- input_select_word_backward: z
739
- .string()
740
- .optional()
741
- .default("alt+shift+b,alt+shift+left")
742
- .describe("Select word backward in input"),
743
- input_delete_word_forward: z
744
- .string()
745
- .optional()
746
- .default("alt+d,alt+delete,ctrl+delete")
747
- .describe("Delete word forward in input"),
748
- input_delete_word_backward: z
749
- .string()
750
- .optional()
751
- .default("ctrl+w,ctrl+backspace,alt+backspace")
752
- .describe("Delete word backward in input"),
753
- history_previous: z.string().optional().default("up").describe("Previous history item"),
754
- history_next: z.string().optional().default("down").describe("Next history item"),
755
- session_child_first: z.string().optional().default("<leader>down").describe("Go to first child session"),
756
- session_child_cycle: z.string().optional().default("right").describe("Go to next child session"),
757
- session_child_cycle_reverse: z.string().optional().default("left").describe("Go to previous child session"),
758
- session_parent: z.string().optional().default("up").describe("Go to parent session"),
759
- terminal_suspend: z.string().optional().default("ctrl+z").describe("Suspend terminal"),
760
- terminal_title_toggle: z.string().optional().default("none").describe("Toggle terminal title"),
761
- tips_toggle: z.string().optional().default("<leader>h").describe("Toggle tips on home screen"),
762
- plugin_manager: z.string().optional().default("none").describe("Open plugin manager dialog"),
763
- display_thinking: z.string().optional().default("none").describe("Toggle thinking blocks visibility"),
764
- })
765
- .strict()
766
- .meta({
767
- ref: "KeybindsConfig",
768
- })
769
-
770
- export const Server = z
771
- .object({
772
- port: z.number().int().positive().optional().describe("Port to listen on"),
773
- hostname: z.string().optional().describe("Hostname to listen on"),
774
- mdns: z.boolean().optional().describe("Enable mDNS service discovery"),
775
- mdnsDomain: z.string().optional().describe("Custom domain name for mDNS service (default: opencode.local)"),
776
- cors: z.array(z.string()).optional().describe("Additional domains to allow for CORS"),
777
- })
778
- .strict()
779
- .meta({
780
- ref: "ServerConfig",
781
- })
782
-
783
- export const Layout = z.enum(["auto", "stretch"]).meta({
784
- ref: "LayoutConfig",
785
- })
786
- export type Layout = z.infer<typeof Layout>
787
-
788
- export const Provider = ModelsDev.Provider.partial()
789
- .extend({
790
- whitelist: z.array(z.string()).optional(),
791
- blacklist: z.array(z.string()).optional(),
792
- models: z
793
- .record(
794
- z.string(),
795
- ModelsDev.Model.partial().extend({
796
- variants: z
797
- .record(
798
- z.string(),
799
- z
800
- .object({
801
- disabled: z.boolean().optional().describe("Disable this variant for the model"),
802
- })
803
- .catchall(z.any()),
804
- )
805
- .optional()
806
- .describe("Variant-specific configuration"),
807
- }),
808
- )
809
- .optional(),
810
- options: z
811
- .object({
812
- apiKey: z.string().optional(),
813
- baseURL: z.string().optional(),
814
- enterpriseUrl: z.string().optional().describe("GitHub Enterprise URL for copilot authentication"),
815
- setCacheKey: z.boolean().optional().describe("Enable promptCacheKey for this provider (default false)"),
816
- timeout: z
817
- .union([
818
- z
819
- .number()
820
- .int()
821
- .positive()
822
- .describe(
823
- "Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.",
824
- ),
825
- z.literal(false).describe("Disable timeout for this provider entirely."),
826
- ])
827
- .optional()
828
- .describe(
829
- "Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.",
830
- ),
831
- chunkTimeout: z
832
- .number()
833
- .int()
834
- .positive()
835
- .optional()
836
- .describe(
837
- "Timeout in milliseconds between streamed SSE chunks for this provider. If no chunk arrives within this window, the request is aborted.",
838
- ),
839
- })
840
- .catchall(z.any())
841
- .optional(),
842
- })
843
- .strict()
844
- .meta({
845
- ref: "ProviderConfig",
846
- })
847
- export type Provider = z.infer<typeof Provider>
848
-
849
- export const Info = z
850
- .object({
851
- $schema: z.string().optional().describe("JSON schema reference for configuration validation"),
852
- logLevel: Log.Level.optional().describe("Log level"),
853
- server: Server.optional().describe("Server configuration for opencode serve and web commands"),
854
- command: z
855
- .record(z.string(), Command)
856
- .optional()
857
- .describe("Command configuration, see https://opencode.ai/docs/commands"),
858
- skills: Skills.optional().describe("Additional skill folder paths"),
859
- watcher: z
860
- .object({
861
- ignore: z.array(z.string()).optional(),
862
- })
863
- .optional(),
864
- snapshot: z
865
- .boolean()
866
- .optional()
867
- .describe(
868
- "Enable or disable snapshot tracking. When false, filesystem snapshots are not recorded and undoing or reverting will not undo/redo file changes. Defaults to true.",
869
- ),
870
- plugin: PluginSpec.array().optional(),
871
- share: z
872
- .enum(["manual", "auto", "disabled"])
873
- .optional()
874
- .describe(
875
- "Control sharing behavior:'manual' allows manual sharing via commands, 'auto' enables automatic sharing, 'disabled' disables all sharing",
876
- ),
877
- autoshare: z
878
- .boolean()
879
- .optional()
880
- .describe("@deprecated Use 'share' field instead. Share newly created sessions automatically"),
881
- autoupdate: z
882
- .union([z.boolean(), z.literal("notify")])
883
- .optional()
884
- .describe(
885
- "Automatically update to the latest version. Set to true to auto-update, false to disable, or 'notify' to show update notifications",
886
- ),
887
- disabled_providers: z.array(z.string()).optional().describe("Disable providers that are loaded automatically"),
888
- enabled_providers: z
889
- .array(z.string())
890
- .optional()
891
- .describe("When set, ONLY these providers will be enabled. All other providers will be ignored"),
892
- model: ModelId.describe("Model to use in the format of provider/model, eg anthropic/claude-2").optional(),
893
- small_model: ModelId.describe(
894
- "Small model to use for tasks like title generation in the format of provider/model",
895
- ).optional(),
896
- default_agent: z
897
- .string()
898
- .optional()
899
- .describe(
900
- "Default agent to use when none is specified. Must be a primary agent. Falls back to 'build' if not set or if the specified agent is invalid.",
901
- ),
902
- username: z
903
- .string()
904
- .optional()
905
- .describe("Custom username to display in conversations instead of system username"),
906
- mode: z
907
- .object({
908
- build: Agent.optional(),
909
- plan: Agent.optional(),
910
- })
911
- .catchall(Agent)
912
- .optional()
913
- .describe("@deprecated Use `agent` field instead."),
914
- agent: z
915
- .object({
916
- // primary
917
- plan: Agent.optional(),
918
- build: Agent.optional(),
919
- // subagent
920
- general: Agent.optional(),
921
- explore: Agent.optional(),
922
- // specialized
923
- title: Agent.optional(),
924
- summary: Agent.optional(),
925
- compaction: Agent.optional(),
926
- })
927
- .catchall(Agent)
928
- .optional()
929
- .describe("Agent configuration, see https://opencode.ai/docs/agents"),
930
- provider: z
931
- .record(z.string(), Provider)
932
- .optional()
933
- .describe("Custom provider configurations and model overrides"),
934
- mcp: z
935
- .record(
936
- z.string(),
937
- z.union([
938
- Mcp,
939
- z
940
- .object({
941
- enabled: z.boolean(),
942
- })
943
- .strict(),
944
- ]),
945
- )
946
- .optional()
947
- .describe("MCP (Model Context Protocol) server configurations"),
948
- formatter: z
949
- .union([
950
- z.literal(false),
951
- z.record(
952
- z.string(),
953
- z.object({
954
- disabled: z.boolean().optional(),
955
- command: z.array(z.string()).optional(),
956
- environment: z.record(z.string(), z.string()).optional(),
957
- extensions: z.array(z.string()).optional(),
958
- }),
959
- ),
960
- ])
961
- .optional(),
962
- lsp: z
963
- .union([
964
- z.literal(false),
965
- z.record(
966
- z.string(),
967
- z.union([
968
- z.object({
969
- disabled: z.literal(true),
970
- }),
971
- z.object({
972
- command: z.array(z.string()),
973
- extensions: z.array(z.string()).optional(),
974
- disabled: z.boolean().optional(),
975
- env: z.record(z.string(), z.string()).optional(),
976
- initialization: z.record(z.string(), z.any()).optional(),
977
- }),
978
- ]),
979
- ),
980
- ])
981
- .optional()
982
- .refine(
983
- (data) => {
984
- if (!data) return true
985
- if (typeof data === "boolean") return true
986
- const serverIds = new Set(Object.values(LSPServer).map((s) => s.id))
987
-
988
- return Object.entries(data).every(([id, config]) => {
989
- if (config.disabled) return true
990
- if (serverIds.has(id)) return true
991
- return Boolean(config.extensions)
992
- })
993
- },
994
- {
995
- error: "For custom LSP servers, 'extensions' array is required.",
996
- },
997
- ),
998
- instructions: z.array(z.string()).optional().describe("Additional instruction files or patterns to include"),
999
- layout: Layout.optional().describe("@deprecated Always uses stretch layout."),
1000
- permission: Permission.optional(),
1001
- tools: z.record(z.string(), z.boolean()).optional(),
1002
- enterprise: z
1003
- .object({
1004
- url: z.string().optional().describe("Enterprise URL"),
1005
- })
1006
- .optional(),
1007
- compaction: z
1008
- .object({
1009
- auto: z.boolean().optional().describe("Enable automatic compaction when context is full (default: true)"),
1010
- prune: z.boolean().optional().describe("Enable pruning of old tool outputs (default: true)"),
1011
- reserved: z
1012
- .number()
1013
- .int()
1014
- .min(0)
1015
- .optional()
1016
- .describe("Token buffer for compaction. Leaves enough window to avoid overflow during compaction."),
1017
- })
1018
- .optional(),
1019
- experimental: z
1020
- .object({
1021
- disable_paste_summary: z.boolean().optional(),
1022
- batch_tool: z.boolean().optional().describe("Enable the batch tool"),
1023
- openTelemetry: z
1024
- .boolean()
1025
- .optional()
1026
- .describe("Enable OpenTelemetry spans for AI SDK calls (using the 'experimental_telemetry' flag)"),
1027
- primary_tools: z
1028
- .array(z.string())
1029
- .optional()
1030
- .describe("Tools that should only be available to primary agents."),
1031
- continue_loop_on_deny: z.boolean().optional().describe("Continue the agent loop when a tool call is denied"),
1032
- mcp_timeout: z
1033
- .number()
1034
- .int()
1035
- .positive()
1036
- .optional()
1037
- .describe("Timeout in milliseconds for model context protocol (MCP) requests"),
1038
- })
1039
- .optional(),
1040
- })
1041
- .strict()
1042
- .meta({
1043
- ref: "Config",
1044
- })
1045
-
1046
- export type Info = z.output<typeof Info> & {
1047
- plugin_origins?: PluginOrigin[]
1048
- }
1049
-
1050
- type State = {
1051
- config: Info
1052
- directories: string[]
1053
- deps: Promise<void>[]
1054
- consoleState: ConsoleState
1055
- }
1056
-
1057
- export interface Interface {
1058
- readonly get: () => Effect.Effect<Info>
1059
- readonly getGlobal: () => Effect.Effect<Info>
1060
- readonly getConsoleState: () => Effect.Effect<ConsoleState>
1061
- readonly update: (config: Info) => Effect.Effect<void>
1062
- readonly updateGlobal: (config: Info) => Effect.Effect<Info>
1063
- readonly invalidate: (wait?: boolean) => Effect.Effect<void>
1064
- readonly directories: () => Effect.Effect<string[]>
1065
- readonly waitForDependencies: () => Effect.Effect<void>
1066
- }
1067
-
1068
- export class Service extends ServiceMap.Service<Service, Interface>()("@opencode/Config") {}
1069
-
1070
- function globalConfigFile() {
1071
- const candidates = ["opencode.jsonc", "opencode.json", "config.json"].map((file) =>
1072
- path.join(Global.Path.config, file),
1073
- )
1074
- for (const file of candidates) {
1075
- if (existsSync(file)) return file
1076
- }
1077
- return candidates[0]
1078
- }
1079
-
1080
- function patchJsonc(input: string, patch: unknown, path: string[] = []): string {
1081
- if (!isRecord(patch)) {
1082
- const edits = modify(input, path, patch, {
1083
- formattingOptions: {
1084
- insertSpaces: true,
1085
- tabSize: 2,
1086
- },
1087
- })
1088
- return applyEdits(input, edits)
1089
- }
1090
-
1091
- return Object.entries(patch).reduce((result, [key, value]) => {
1092
- if (value === undefined) return result
1093
- return patchJsonc(result, value, [...path, key])
1094
- }, input)
1095
- }
1096
-
1097
- function writable(info: Info) {
1098
- const { plugin_origins, ...next } = info
1099
- return next
1100
- }
1101
-
1102
- function parseConfig(text: string, filepath: string): Info {
1103
- const errors: JsoncParseError[] = []
1104
- const data = parseJsonc(text, errors, { allowTrailingComma: true })
1105
- if (errors.length) {
1106
- const lines = text.split("\n")
1107
- const errorDetails = errors
1108
- .map((e) => {
1109
- const beforeOffset = text.substring(0, e.offset).split("\n")
1110
- const line = beforeOffset.length
1111
- const column = beforeOffset[beforeOffset.length - 1].length + 1
1112
- const problemLine = lines[line - 1]
1113
-
1114
- const error = `${printParseErrorCode(e.error)} at line ${line}, column ${column}`
1115
- if (!problemLine) return error
1116
-
1117
- return `${error}\n Line ${line}: ${problemLine}\n${"".padStart(column + 9)}^`
1118
- })
1119
- .join("\n")
1120
-
1121
- throw new JsonError({
1122
- path: filepath,
1123
- message: `\n--- JSONC Input ---\n${text}\n--- Errors ---\n${errorDetails}\n--- End ---`,
1124
- })
1125
- }
1126
-
1127
- const parsed = Info.safeParse(data)
1128
- if (parsed.success) return parsed.data
1129
-
1130
- throw new InvalidError({
1131
- path: filepath,
1132
- issues: parsed.error.issues,
1133
- })
1134
- }
1135
-
1136
- export const { JsonError, InvalidError } = ConfigPaths
1137
-
1138
- export const ConfigDirectoryTypoError = NamedError.create(
1139
- "ConfigDirectoryTypoError",
1140
- z.object({
1141
- path: z.string(),
1142
- dir: z.string(),
1143
- suggestion: z.string(),
1144
- }),
1145
- )
1146
-
1147
- export const layer: Layer.Layer<Service, never, AppFileSystem.Service | Auth.Service | Account.Service> =
1148
- Layer.effect(
1149
- Service,
1150
- Effect.gen(function* () {
1151
- const fs = yield* AppFileSystem.Service
1152
- const authSvc = yield* Auth.Service
1153
- const accountSvc = yield* Account.Service
1154
-
1155
- const readConfigFile = Effect.fnUntraced(function* (filepath: string) {
1156
- return yield* fs.readFileString(filepath).pipe(
1157
- Effect.catchIf(
1158
- (e) => e.reason._tag === "NotFound",
1159
- () => Effect.succeed(undefined),
1160
- ),
1161
- Effect.orDie,
1162
- )
1163
- })
1164
-
1165
- const loadConfig = Effect.fnUntraced(function* (
1166
- text: string,
1167
- options: { path: string } | { dir: string; source: string },
1168
- ) {
1169
- const original = text
1170
- const source = "path" in options ? options.path : options.source
1171
- const isFile = "path" in options
1172
- const data = yield* Effect.promise(() =>
1173
- ConfigPaths.parseText(
1174
- text,
1175
- "path" in options ? options.path : { source: options.source, dir: options.dir },
1176
- ),
1177
- )
1178
-
1179
- const normalized = (() => {
1180
- if (!data || typeof data !== "object" || Array.isArray(data)) return data
1181
- const copy = { ...(data as Record<string, unknown>) }
1182
- const hadLegacy = "theme" in copy || "keybinds" in copy || "tui" in copy
1183
- if (!hadLegacy) return copy
1184
- delete copy.theme
1185
- delete copy.keybinds
1186
- delete copy.tui
1187
- log.warn("tui keys in opencode config are deprecated; move them to tui.json", { path: source })
1188
- return copy
1189
- })()
1190
-
1191
- const parsed = Info.safeParse(normalized)
1192
- if (parsed.success) {
1193
- if (!parsed.data.$schema && isFile) {
1194
- parsed.data.$schema = "https://opencode.ai/config.json"
1195
- const updated = original.replace(/^\s*\{/, '{\n "$schema": "https://opencode.ai/config.json",')
1196
- yield* fs.writeFileString(options.path, updated).pipe(Effect.catch(() => Effect.void))
1197
- }
1198
- const data = parsed.data
1199
- if (data.plugin && isFile) {
1200
- const list = data.plugin
1201
- for (let i = 0; i < list.length; i++) {
1202
- list[i] = yield* Effect.promise(() => resolvePluginSpec(list[i], options.path))
1203
- }
1204
- }
1205
- return data
1206
- }
1207
-
1208
- throw new InvalidError({
1209
- path: source,
1210
- issues: parsed.error.issues,
1211
- })
1212
- })
1213
-
1214
- const loadFile = Effect.fnUntraced(function* (filepath: string) {
1215
- log.info("loading", { path: filepath })
1216
- const text = yield* readConfigFile(filepath)
1217
- if (!text) return {} as Info
1218
- return yield* loadConfig(text, { path: filepath })
1219
- })
1220
-
1221
- const loadGlobal = Effect.fnUntraced(function* () {
1222
- let result: Info = pipe(
1223
- {},
1224
- mergeDeep(yield* loadFile(path.join(Global.Path.config, "config.json"))),
1225
- mergeDeep(yield* loadFile(path.join(Global.Path.config, "opencode.json"))),
1226
- mergeDeep(yield* loadFile(path.join(Global.Path.config, "opencode.jsonc"))),
1227
- )
1228
-
1229
- const legacy = path.join(Global.Path.config, "config")
1230
- if (existsSync(legacy)) {
1231
- yield* Effect.promise(() =>
1232
- import(pathToFileURL(legacy).href, { with: { type: "toml" } })
1233
- .then(async (mod) => {
1234
- const { provider, model, ...rest } = mod.default
1235
- if (provider && model) result.model = `${provider}/${model}`
1236
- result["$schema"] = "https://opencode.ai/config.json"
1237
- result = mergeDeep(result, rest)
1238
- await fsNode.writeFile(path.join(Global.Path.config, "config.json"), JSON.stringify(result, null, 2))
1239
- await fsNode.unlink(legacy)
1240
- })
1241
- .catch(() => {}),
1242
- )
1243
- }
1244
-
1245
- return result
1246
- })
1247
-
1248
- const [cachedGlobal, invalidateGlobal] = yield* Effect.cachedInvalidateWithTTL(
1249
- loadGlobal().pipe(
1250
- Effect.tapError((error) =>
1251
- Effect.sync(() => log.error("failed to load global config, using defaults", { error: String(error) })),
1252
- ),
1253
- Effect.orElseSucceed((): Info => ({})),
1254
- ),
1255
- Duration.infinity,
1256
- )
1257
-
1258
- const getGlobal = Effect.fn("Config.getGlobal")(function* () {
1259
- return yield* cachedGlobal
1260
- })
1261
-
1262
- const loadInstanceState = Effect.fnUntraced(function* (ctx: InstanceContext) {
1263
- const auth = yield* authSvc.all().pipe(Effect.orDie)
1264
-
1265
- let result: Info = {}
1266
- const consoleManagedProviders = new Set<string>()
1267
- let activeOrgName: string | undefined
1268
-
1269
- const scope = (source: string): PluginScope => {
1270
- if (source.startsWith("http://") || source.startsWith("https://")) return "global"
1271
- if (source === "OPENCODE_CONFIG_CONTENT") return "local"
1272
- if (Instance.containsPath(source)) return "local"
1273
- return "global"
1274
- }
1275
-
1276
- const track = (source: string, list: PluginSpec[] | undefined, kind?: PluginScope) => {
1277
- if (!list?.length) return
1278
- const hit = kind ?? scope(source)
1279
- const plugins = deduplicatePluginOrigins([
1280
- ...(result.plugin_origins ?? []),
1281
- ...list.map((spec) => ({ spec, source, scope: hit })),
1282
- ])
1283
- result.plugin = plugins.map((item) => item.spec)
1284
- result.plugin_origins = plugins
1285
- }
1286
-
1287
- const merge = (source: string, next: Info, kind?: PluginScope) => {
1288
- result = mergeConfigConcatArrays(result, next)
1289
- track(source, next.plugin, kind)
1290
- }
1291
-
1292
- for (const [key, value] of Object.entries(auth)) {
1293
- if (value.type === "wellknown") {
1294
- const url = key.replace(/\/+$/, "")
1295
- process.env[value.key] = value.token
1296
- log.debug("fetching remote config", { url: `${url}/.well-known/opencode` })
1297
- const response = yield* Effect.promise(() => fetch(`${url}/.well-known/opencode`))
1298
- if (!response.ok) {
1299
- throw new Error(`failed to fetch remote config from ${url}: ${response.status}`)
1300
- }
1301
- const wellknown = (yield* Effect.promise(() => response.json())) as any
1302
- const remoteConfig = wellknown.config ?? {}
1303
- if (!remoteConfig.$schema) remoteConfig.$schema = "https://opencode.ai/config.json"
1304
- const source = `${url}/.well-known/opencode`
1305
- const next = yield* loadConfig(JSON.stringify(remoteConfig), {
1306
- dir: path.dirname(source),
1307
- source,
1308
- })
1309
- merge(source, next, "global")
1310
- log.debug("loaded remote config from well-known", { url })
1311
- }
1312
- }
1313
-
1314
- const global = yield* getGlobal()
1315
- merge(Global.Path.config, global, "global")
1316
-
1317
- if (Flag.OPENCODE_CONFIG) {
1318
- merge(Flag.OPENCODE_CONFIG, yield* loadFile(Flag.OPENCODE_CONFIG))
1319
- log.debug("loaded custom config", { path: Flag.OPENCODE_CONFIG })
1320
- }
1321
-
1322
- if (!Flag.OPENCODE_DISABLE_PROJECT_CONFIG) {
1323
- for (const file of yield* Effect.promise(() =>
1324
- ConfigPaths.projectFiles("opencode", ctx.directory, ctx.worktree),
1325
- )) {
1326
- merge(file, yield* loadFile(file), "local")
1327
- }
1328
- }
1329
-
1330
- result.agent = result.agent || {}
1331
- result.mode = result.mode || {}
1332
- result.plugin = result.plugin || []
1333
-
1334
- const directories = yield* Effect.promise(() => ConfigPaths.directories(ctx.directory, ctx.worktree))
1335
-
1336
- if (Flag.OPENCODE_CONFIG_DIR) {
1337
- log.debug("loading config from OPENCODE_CONFIG_DIR", { path: Flag.OPENCODE_CONFIG_DIR })
1338
- }
1339
-
1340
- const deps: Promise<void>[] = []
1341
-
1342
- for (const dir of unique(directories)) {
1343
- if (dir.endsWith(".opencode") || dir === Flag.OPENCODE_CONFIG_DIR) {
1344
- for (const file of ["opencode.json", "opencode.jsonc"]) {
1345
- const source = path.join(dir, file)
1346
- log.debug(`loading config from ${source}`)
1347
- merge(source, yield* loadFile(source))
1348
- result.agent ??= {}
1349
- result.mode ??= {}
1350
- result.plugin ??= []
1351
- }
1352
- }
1353
-
1354
- const dep = iife(async () => {
1355
- await installDependencies(dir)
1356
- })
1357
- void dep.catch((err) => {
1358
- log.warn("background dependency install failed", { dir, error: err })
1359
- })
1360
- deps.push(dep)
1361
-
1362
- result.command = mergeDeep(result.command ?? {}, yield* Effect.promise(() => loadCommand(dir)))
1363
- result.agent = mergeDeep(result.agent, yield* Effect.promise(() => loadAgent(dir)))
1364
- result.agent = mergeDeep(result.agent, yield* Effect.promise(() => loadMode(dir)))
1365
- const list = yield* Effect.promise(() => loadPlugin(dir))
1366
- track(dir, list)
1367
- }
1368
-
1369
- if (process.env.OPENCODE_CONFIG_CONTENT) {
1370
- const source = "OPENCODE_CONFIG_CONTENT"
1371
- const next = yield* loadConfig(process.env.OPENCODE_CONFIG_CONTENT, {
1372
- dir: ctx.directory,
1373
- source,
1374
- })
1375
- merge(source, next, "local")
1376
- log.debug("loaded custom config from OPENCODE_CONFIG_CONTENT")
1377
- }
1378
-
1379
- const activeOrg = Option.getOrUndefined(
1380
- yield* accountSvc.activeOrg().pipe(Effect.catch(() => Effect.succeed(Option.none()))),
1381
- )
1382
- if (activeOrg) {
1383
- yield* Effect.gen(function* () {
1384
- const [configOpt, tokenOpt] = yield* Effect.all(
1385
- [accountSvc.config(activeOrg.account.id, activeOrg.org.id), accountSvc.token(activeOrg.account.id)],
1386
- { concurrency: 2 },
1387
- )
1388
- if (Option.isSome(tokenOpt)) {
1389
- process.env["OPENCODE_CONSOLE_TOKEN"] = tokenOpt.value
1390
- Env.set("OPENCODE_CONSOLE_TOKEN", tokenOpt.value)
1391
- }
1392
-
1393
- activeOrgName = activeOrg.org.name
1394
-
1395
- if (Option.isSome(configOpt)) {
1396
- const source = `${activeOrg.account.url}/api/config`
1397
- const next = yield* loadConfig(JSON.stringify(configOpt.value), {
1398
- dir: path.dirname(source),
1399
- source,
1400
- })
1401
- for (const providerID of Object.keys(next.provider ?? {})) {
1402
- consoleManagedProviders.add(providerID)
1403
- }
1404
- merge(source, next, "global")
1405
- }
1406
- }).pipe(
1407
- Effect.catch((err) => {
1408
- log.debug("failed to fetch remote account config", {
1409
- error: err instanceof Error ? err.message : String(err),
1410
- })
1411
- return Effect.void
1412
- }),
1413
- )
1414
- }
1415
-
1416
- if (existsSync(managedDir)) {
1417
- for (const file of ["opencode.json", "opencode.jsonc"]) {
1418
- const source = path.join(managedDir, file)
1419
- merge(source, yield* loadFile(source), "global")
1420
- }
1421
- }
1422
-
1423
- // macOS managed preferences (.mobileconfig deployed via MDM) override everything
1424
- result = mergeConfigConcatArrays(result, yield* Effect.promise(() => readManagedPreferences()))
1425
-
1426
- for (const [name, mode] of Object.entries(result.mode ?? {})) {
1427
- result.agent = mergeDeep(result.agent ?? {}, {
1428
- [name]: {
1429
- ...mode,
1430
- mode: "primary" as const,
1431
- },
1432
- })
1433
- }
1434
-
1435
- if (Flag.OPENCODE_PERMISSION) {
1436
- result.permission = mergeDeep(result.permission ?? {}, JSON.parse(Flag.OPENCODE_PERMISSION))
1437
- }
1438
-
1439
- if (result.tools) {
1440
- const perms: Record<string, Config.PermissionAction> = {}
1441
- for (const [tool, enabled] of Object.entries(result.tools)) {
1442
- const action: Config.PermissionAction = enabled ? "allow" : "deny"
1443
- if (tool === "write" || tool === "edit" || tool === "patch" || tool === "multiedit") {
1444
- perms.edit = action
1445
- continue
1446
- }
1447
- perms[tool] = action
1448
- }
1449
- result.permission = mergeDeep(perms, result.permission ?? {})
1450
- }
1451
-
1452
- if (!result.username) result.username = os.userInfo().username
1453
-
1454
- if (result.autoshare === true && !result.share) {
1455
- result.share = "auto"
1456
- }
1457
-
1458
- if (Flag.OPENCODE_DISABLE_AUTOCOMPACT) {
1459
- result.compaction = { ...result.compaction, auto: false }
1460
- }
1461
- if (Flag.OPENCODE_DISABLE_PRUNE) {
1462
- result.compaction = { ...result.compaction, prune: false }
1463
- }
1464
-
1465
- return {
1466
- config: result,
1467
- directories,
1468
- deps,
1469
- consoleState: {
1470
- consoleManagedProviders: Array.from(consoleManagedProviders),
1471
- activeOrgName,
1472
- switchableOrgCount: 0,
1473
- },
1474
- }
1475
- })
1476
-
1477
- const state = yield* InstanceState.make<State>(
1478
- Effect.fn("Config.state")(function* (ctx) {
1479
- return yield* loadInstanceState(ctx)
1480
- }),
1481
- )
1482
-
1483
- const get = Effect.fn("Config.get")(function* () {
1484
- return yield* InstanceState.use(state, (s) => s.config)
1485
- })
1486
-
1487
- const directories = Effect.fn("Config.directories")(function* () {
1488
- return yield* InstanceState.use(state, (s) => s.directories)
1489
- })
1490
-
1491
- const getConsoleState = Effect.fn("Config.getConsoleState")(function* () {
1492
- return yield* InstanceState.use(state, (s) => s.consoleState)
1493
- })
1494
-
1495
- const waitForDependencies = Effect.fn("Config.waitForDependencies")(function* () {
1496
- yield* InstanceState.useEffect(state, (s) => Effect.promise(() => Promise.all(s.deps).then(() => undefined)))
1497
- })
1498
-
1499
- const update = Effect.fn("Config.update")(function* (config: Info) {
1500
- const dir = yield* InstanceState.directory
1501
- const file = path.join(dir, "config.json")
1502
- const existing = yield* loadFile(file)
1503
- yield* fs
1504
- .writeFileString(file, JSON.stringify(mergeDeep(writable(existing), writable(config)), null, 2))
1505
- .pipe(Effect.orDie)
1506
- yield* Effect.promise(() => Instance.dispose())
1507
- })
1508
-
1509
- const invalidate = Effect.fn("Config.invalidate")(function* (wait?: boolean) {
1510
- yield* invalidateGlobal
1511
- const task = Instance.disposeAll()
1512
- .catch(() => undefined)
1513
- .finally(() =>
1514
- GlobalBus.emit("event", {
1515
- directory: "global",
1516
- payload: {
1517
- type: Event.Disposed.type,
1518
- properties: {},
1519
- },
1520
- }),
1521
- )
1522
- if (wait) yield* Effect.promise(() => task)
1523
- else void task
1524
- })
1525
-
1526
- const updateGlobal = Effect.fn("Config.updateGlobal")(function* (config: Info) {
1527
- const file = globalConfigFile()
1528
- const before = (yield* readConfigFile(file)) ?? "{}"
1529
- const input = writable(config)
1530
-
1531
- let next: Info
1532
- if (!file.endsWith(".jsonc")) {
1533
- const existing = parseConfig(before, file)
1534
- const merged = mergeDeep(writable(existing), input)
1535
- yield* fs.writeFileString(file, JSON.stringify(merged, null, 2)).pipe(Effect.orDie)
1536
- next = merged
1537
- } else {
1538
- const updated = patchJsonc(before, input)
1539
- next = parseConfig(updated, file)
1540
- yield* fs.writeFileString(file, updated).pipe(Effect.orDie)
1541
- }
1542
-
1543
- yield* invalidate()
1544
- return next
1545
- })
1546
-
1547
- return Service.of({
1548
- get,
1549
- getGlobal,
1550
- getConsoleState,
1551
- update,
1552
- updateGlobal,
1553
- invalidate,
1554
- directories,
1555
- waitForDependencies,
1556
- })
1557
- }),
1558
- )
1559
-
1560
- export const defaultLayer = layer.pipe(
1561
- Layer.provide(AppFileSystem.defaultLayer),
1562
- Layer.provide(Auth.defaultLayer),
1563
- Layer.provide(Account.defaultLayer),
1564
- )
1565
-
1566
- const { runPromise } = makeRuntime(Service, defaultLayer)
1567
-
1568
- export async function get() {
1569
- return runPromise((svc) => svc.get())
1570
- }
1571
-
1572
- export async function getGlobal() {
1573
- return runPromise((svc) => svc.getGlobal())
1574
- }
1575
-
1576
- export async function getConsoleState() {
1577
- return runPromise((svc) => svc.getConsoleState())
1578
- }
1579
-
1580
- export async function update(config: Info) {
1581
- return runPromise((svc) => svc.update(config))
1582
- }
1583
-
1584
- export async function updateGlobal(config: Info) {
1585
- return runPromise((svc) => svc.updateGlobal(config))
1586
- }
1587
-
1588
- export async function invalidate(wait = false) {
1589
- return runPromise((svc) => svc.invalidate(wait))
1590
- }
1591
-
1592
- export async function directories() {
1593
- return runPromise((svc) => svc.directories())
1594
- }
1595
-
1596
- export async function waitForDependencies() {
1597
- return runPromise((svc) => svc.waitForDependencies())
1598
- }
1599
- }