innocode 1.0.0 → 1.0.229

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 (433) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +17 -118
  3. package/AGENTS.md +0 -27
  4. package/Dockerfile +0 -18
  5. package/README.md +0 -15
  6. package/bunfig.toml +0 -5
  7. package/parsers-config.ts +0 -253
  8. package/script/build.ts +0 -198
  9. package/script/publish.ts +0 -186
  10. package/script/schema.ts +0 -47
  11. package/script/seed-e2e.ts +0 -50
  12. package/src/acp/README.md +0 -164
  13. package/src/acp/agent.ts +0 -1676
  14. package/src/acp/session.ts +0 -117
  15. package/src/acp/types.ts +0 -23
  16. package/src/agent/agent.ts +0 -338
  17. package/src/agent/generate.txt +0 -75
  18. package/src/agent/prompt/compaction.txt +0 -14
  19. package/src/agent/prompt/explore.txt +0 -18
  20. package/src/agent/prompt/summary.txt +0 -11
  21. package/src/agent/prompt/title.txt +0 -44
  22. package/src/auth/index.ts +0 -70
  23. package/src/bun/index.ts +0 -137
  24. package/src/bun/registry.ts +0 -48
  25. package/src/bus/bus-event.ts +0 -43
  26. package/src/bus/global.ts +0 -10
  27. package/src/bus/index.ts +0 -105
  28. package/src/cli/bootstrap.ts +0 -17
  29. package/src/cli/cmd/acp.ts +0 -70
  30. package/src/cli/cmd/agent.ts +0 -257
  31. package/src/cli/cmd/auth.ts +0 -400
  32. package/src/cli/cmd/cmd.ts +0 -7
  33. package/src/cli/cmd/debug/agent.ts +0 -167
  34. package/src/cli/cmd/debug/config.ts +0 -16
  35. package/src/cli/cmd/debug/file.ts +0 -97
  36. package/src/cli/cmd/debug/index.ts +0 -48
  37. package/src/cli/cmd/debug/lsp.ts +0 -52
  38. package/src/cli/cmd/debug/ripgrep.ts +0 -87
  39. package/src/cli/cmd/debug/scrap.ts +0 -16
  40. package/src/cli/cmd/debug/skill.ts +0 -16
  41. package/src/cli/cmd/debug/snapshot.ts +0 -52
  42. package/src/cli/cmd/export.ts +0 -88
  43. package/src/cli/cmd/generate.ts +0 -38
  44. package/src/cli/cmd/github.ts +0 -1540
  45. package/src/cli/cmd/import.ts +0 -147
  46. package/src/cli/cmd/mcp.ts +0 -765
  47. package/src/cli/cmd/models.ts +0 -77
  48. package/src/cli/cmd/pr.ts +0 -113
  49. package/src/cli/cmd/run.ts +0 -598
  50. package/src/cli/cmd/serve.ts +0 -20
  51. package/src/cli/cmd/session.ts +0 -135
  52. package/src/cli/cmd/stats.ts +0 -426
  53. package/src/cli/cmd/tui/app.tsx +0 -812
  54. package/src/cli/cmd/tui/attach.ts +0 -60
  55. package/src/cli/cmd/tui/component/border.tsx +0 -21
  56. package/src/cli/cmd/tui/component/dialog-agent.tsx +0 -31
  57. package/src/cli/cmd/tui/component/dialog-command.tsx +0 -148
  58. package/src/cli/cmd/tui/component/dialog-mcp.tsx +0 -86
  59. package/src/cli/cmd/tui/component/dialog-model.tsx +0 -165
  60. package/src/cli/cmd/tui/component/dialog-provider.tsx +0 -243
  61. package/src/cli/cmd/tui/component/dialog-session-list.tsx +0 -108
  62. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +0 -31
  63. package/src/cli/cmd/tui/component/dialog-skill.tsx +0 -36
  64. package/src/cli/cmd/tui/component/dialog-stash.tsx +0 -87
  65. package/src/cli/cmd/tui/component/dialog-status.tsx +0 -167
  66. package/src/cli/cmd/tui/component/dialog-tag.tsx +0 -44
  67. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +0 -50
  68. package/src/cli/cmd/tui/component/logo.tsx +0 -85
  69. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +0 -666
  70. package/src/cli/cmd/tui/component/prompt/frecency.tsx +0 -89
  71. package/src/cli/cmd/tui/component/prompt/history.tsx +0 -108
  72. package/src/cli/cmd/tui/component/prompt/index.tsx +0 -1153
  73. package/src/cli/cmd/tui/component/prompt/stash.tsx +0 -101
  74. package/src/cli/cmd/tui/component/spinner.tsx +0 -24
  75. package/src/cli/cmd/tui/component/textarea-keybindings.ts +0 -73
  76. package/src/cli/cmd/tui/component/tips.tsx +0 -153
  77. package/src/cli/cmd/tui/component/todo-item.tsx +0 -32
  78. package/src/cli/cmd/tui/context/args.tsx +0 -15
  79. package/src/cli/cmd/tui/context/directory.ts +0 -13
  80. package/src/cli/cmd/tui/context/exit.tsx +0 -54
  81. package/src/cli/cmd/tui/context/helper.tsx +0 -25
  82. package/src/cli/cmd/tui/context/keybind.tsx +0 -100
  83. package/src/cli/cmd/tui/context/kv.tsx +0 -52
  84. package/src/cli/cmd/tui/context/local.tsx +0 -409
  85. package/src/cli/cmd/tui/context/prompt.tsx +0 -18
  86. package/src/cli/cmd/tui/context/route.tsx +0 -46
  87. package/src/cli/cmd/tui/context/sdk.tsx +0 -101
  88. package/src/cli/cmd/tui/context/sync.tsx +0 -470
  89. package/src/cli/cmd/tui/context/theme/aura.json +0 -69
  90. package/src/cli/cmd/tui/context/theme/ayu.json +0 -80
  91. package/src/cli/cmd/tui/context/theme/carbonfox.json +0 -248
  92. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +0 -233
  93. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +0 -233
  94. package/src/cli/cmd/tui/context/theme/catppuccin.json +0 -112
  95. package/src/cli/cmd/tui/context/theme/cobalt2.json +0 -228
  96. package/src/cli/cmd/tui/context/theme/cursor.json +0 -249
  97. package/src/cli/cmd/tui/context/theme/dracula.json +0 -219
  98. package/src/cli/cmd/tui/context/theme/everforest.json +0 -241
  99. package/src/cli/cmd/tui/context/theme/flexoki.json +0 -237
  100. package/src/cli/cmd/tui/context/theme/github.json +0 -233
  101. package/src/cli/cmd/tui/context/theme/gruvbox.json +0 -242
  102. package/src/cli/cmd/tui/context/theme/innocode.json +0 -245
  103. package/src/cli/cmd/tui/context/theme/kanagawa.json +0 -77
  104. package/src/cli/cmd/tui/context/theme/lucent-orng.json +0 -237
  105. package/src/cli/cmd/tui/context/theme/material.json +0 -235
  106. package/src/cli/cmd/tui/context/theme/matrix.json +0 -77
  107. package/src/cli/cmd/tui/context/theme/mercury.json +0 -252
  108. package/src/cli/cmd/tui/context/theme/monokai.json +0 -221
  109. package/src/cli/cmd/tui/context/theme/nightowl.json +0 -221
  110. package/src/cli/cmd/tui/context/theme/nord.json +0 -223
  111. package/src/cli/cmd/tui/context/theme/one-dark.json +0 -84
  112. package/src/cli/cmd/tui/context/theme/orng.json +0 -249
  113. package/src/cli/cmd/tui/context/theme/osaka-jade.json +0 -93
  114. package/src/cli/cmd/tui/context/theme/palenight.json +0 -222
  115. package/src/cli/cmd/tui/context/theme/rosepine.json +0 -234
  116. package/src/cli/cmd/tui/context/theme/solarized.json +0 -223
  117. package/src/cli/cmd/tui/context/theme/synthwave84.json +0 -226
  118. package/src/cli/cmd/tui/context/theme/tokyonight.json +0 -243
  119. package/src/cli/cmd/tui/context/theme/vercel.json +0 -245
  120. package/src/cli/cmd/tui/context/theme/vesper.json +0 -218
  121. package/src/cli/cmd/tui/context/theme/zenburn.json +0 -223
  122. package/src/cli/cmd/tui/context/theme.tsx +0 -1154
  123. package/src/cli/cmd/tui/event.ts +0 -48
  124. package/src/cli/cmd/tui/routes/home.tsx +0 -145
  125. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +0 -64
  126. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +0 -109
  127. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +0 -26
  128. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +0 -47
  129. package/src/cli/cmd/tui/routes/session/footer.tsx +0 -91
  130. package/src/cli/cmd/tui/routes/session/header.tsx +0 -135
  131. package/src/cli/cmd/tui/routes/session/index.tsx +0 -2139
  132. package/src/cli/cmd/tui/routes/session/permission.tsx +0 -508
  133. package/src/cli/cmd/tui/routes/session/question.tsx +0 -466
  134. package/src/cli/cmd/tui/routes/session/sidebar.tsx +0 -313
  135. package/src/cli/cmd/tui/thread.ts +0 -188
  136. package/src/cli/cmd/tui/ui/dialog-alert.tsx +0 -59
  137. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +0 -85
  138. package/src/cli/cmd/tui/ui/dialog-export-options.tsx +0 -207
  139. package/src/cli/cmd/tui/ui/dialog-help.tsx +0 -40
  140. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +0 -80
  141. package/src/cli/cmd/tui/ui/dialog-select.tsx +0 -401
  142. package/src/cli/cmd/tui/ui/dialog.tsx +0 -167
  143. package/src/cli/cmd/tui/ui/link.tsx +0 -28
  144. package/src/cli/cmd/tui/ui/spinner.ts +0 -368
  145. package/src/cli/cmd/tui/ui/toast.tsx +0 -100
  146. package/src/cli/cmd/tui/util/clipboard.ts +0 -159
  147. package/src/cli/cmd/tui/util/editor.ts +0 -32
  148. package/src/cli/cmd/tui/util/signal.ts +0 -7
  149. package/src/cli/cmd/tui/util/terminal.ts +0 -114
  150. package/src/cli/cmd/tui/util/transcript.ts +0 -98
  151. package/src/cli/cmd/tui/win32.ts +0 -129
  152. package/src/cli/cmd/tui/worker.ts +0 -152
  153. package/src/cli/cmd/uninstall.ts +0 -363
  154. package/src/cli/cmd/upgrade.ts +0 -73
  155. package/src/cli/cmd/web.ts +0 -81
  156. package/src/cli/error.ts +0 -57
  157. package/src/cli/logo.ts +0 -6
  158. package/src/cli/network.ts +0 -60
  159. package/src/cli/ui.ts +0 -113
  160. package/src/cli/upgrade.ts +0 -25
  161. package/src/command/index.ts +0 -150
  162. package/src/command/template/initialize.txt +0 -10
  163. package/src/command/template/review.txt +0 -101
  164. package/src/config/config.ts +0 -1517
  165. package/src/config/markdown.ts +0 -98
  166. package/src/env/index.ts +0 -28
  167. package/src/file/ignore.ts +0 -83
  168. package/src/file/index.ts +0 -583
  169. package/src/file/ripgrep.ts +0 -375
  170. package/src/file/time.ts +0 -69
  171. package/src/file/watcher.ts +0 -127
  172. package/src/flag/flag.ts +0 -148
  173. package/src/format/formatter.ts +0 -366
  174. package/src/format/index.ts +0 -137
  175. package/src/global/index.ts +0 -80
  176. package/src/id/id.ts +0 -83
  177. package/src/ide/index.ts +0 -76
  178. package/src/index.ts +0 -160
  179. package/src/installation/index.ts +0 -268
  180. package/src/lsp/client.ts +0 -252
  181. package/src/lsp/index.ts +0 -485
  182. package/src/lsp/language.ts +0 -119
  183. package/src/lsp/server.ts +0 -2046
  184. package/src/mcp/auth.ts +0 -132
  185. package/src/mcp/index.ts +0 -937
  186. package/src/mcp/oauth-callback.ts +0 -200
  187. package/src/mcp/oauth-provider.ts +0 -154
  188. package/src/patch/index.ts +0 -680
  189. package/src/permission/arity.ts +0 -163
  190. package/src/permission/index.ts +0 -210
  191. package/src/permission/next.ts +0 -280
  192. package/src/plugin/codex.ts +0 -624
  193. package/src/plugin/copilot.ts +0 -327
  194. package/src/plugin/index.ts +0 -138
  195. package/src/project/bootstrap.ts +0 -35
  196. package/src/project/instance.ts +0 -114
  197. package/src/project/project.ts +0 -371
  198. package/src/project/state.ts +0 -70
  199. package/src/project/vcs.ts +0 -76
  200. package/src/provider/auth.ts +0 -147
  201. package/src/provider/error.ts +0 -189
  202. package/src/provider/models.ts +0 -133
  203. package/src/provider/provider.ts +0 -1370
  204. package/src/provider/sdk/copilot/README.md +0 -5
  205. package/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +0 -164
  206. package/src/provider/sdk/copilot/chat/get-response-metadata.ts +0 -15
  207. package/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +0 -17
  208. package/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +0 -64
  209. package/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +0 -780
  210. package/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +0 -28
  211. package/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +0 -44
  212. package/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +0 -87
  213. package/src/provider/sdk/copilot/copilot-provider.ts +0 -100
  214. package/src/provider/sdk/copilot/index.ts +0 -2
  215. package/src/provider/sdk/copilot/openai-compatible-error.ts +0 -27
  216. package/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +0 -303
  217. package/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +0 -22
  218. package/src/provider/sdk/copilot/responses/openai-config.ts +0 -18
  219. package/src/provider/sdk/copilot/responses/openai-error.ts +0 -22
  220. package/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +0 -207
  221. package/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +0 -1732
  222. package/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +0 -177
  223. package/src/provider/sdk/copilot/responses/openai-responses-settings.ts +0 -1
  224. package/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +0 -88
  225. package/src/provider/sdk/copilot/responses/tool/file-search.ts +0 -128
  226. package/src/provider/sdk/copilot/responses/tool/image-generation.ts +0 -115
  227. package/src/provider/sdk/copilot/responses/tool/local-shell.ts +0 -65
  228. package/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +0 -104
  229. package/src/provider/sdk/copilot/responses/tool/web-search.ts +0 -103
  230. package/src/provider/transform.ts +0 -806
  231. package/src/pty/index.ts +0 -286
  232. package/src/question/index.ts +0 -171
  233. package/src/scheduler/index.ts +0 -61
  234. package/src/server/error.ts +0 -36
  235. package/src/server/event.ts +0 -7
  236. package/src/server/mdns.ts +0 -60
  237. package/src/server/routes/config.ts +0 -92
  238. package/src/server/routes/experimental.ts +0 -208
  239. package/src/server/routes/file.ts +0 -197
  240. package/src/server/routes/global.ts +0 -183
  241. package/src/server/routes/mcp.ts +0 -225
  242. package/src/server/routes/permission.ts +0 -68
  243. package/src/server/routes/project.ts +0 -82
  244. package/src/server/routes/provider.ts +0 -179
  245. package/src/server/routes/pty.ts +0 -176
  246. package/src/server/routes/question.ts +0 -98
  247. package/src/server/routes/session.ts +0 -939
  248. package/src/server/routes/tui.ts +0 -379
  249. package/src/server/server.ts +0 -621
  250. package/src/session/compaction.ts +0 -261
  251. package/src/session/index.ts +0 -543
  252. package/src/session/instruction.ts +0 -197
  253. package/src/session/llm.ts +0 -283
  254. package/src/session/message-v2.ts +0 -841
  255. package/src/session/message.ts +0 -189
  256. package/src/session/processor.ts +0 -410
  257. package/src/session/prompt/anthropic-20250930.txt +0 -166
  258. package/src/session/prompt/anthropic.txt +0 -105
  259. package/src/session/prompt/beast.txt +0 -147
  260. package/src/session/prompt/build-switch.txt +0 -5
  261. package/src/session/prompt/codex_header.txt +0 -79
  262. package/src/session/prompt/copilot-gpt-5.txt +0 -143
  263. package/src/session/prompt/gemini.txt +0 -155
  264. package/src/session/prompt/max-steps.txt +0 -16
  265. package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  266. package/src/session/prompt/plan.txt +0 -26
  267. package/src/session/prompt/qwen.txt +0 -109
  268. package/src/session/prompt/trinity.txt +0 -97
  269. package/src/session/prompt.ts +0 -1964
  270. package/src/session/retry.ts +0 -101
  271. package/src/session/revert.ts +0 -121
  272. package/src/session/status.ts +0 -76
  273. package/src/session/summary.ts +0 -203
  274. package/src/session/system.ts +0 -54
  275. package/src/session/todo.ts +0 -37
  276. package/src/share/share-next.ts +0 -200
  277. package/src/share/share.ts +0 -92
  278. package/src/shell/shell.ts +0 -67
  279. package/src/skill/discovery.ts +0 -97
  280. package/src/skill/index.ts +0 -1
  281. package/src/skill/skill.ts +0 -188
  282. package/src/snapshot/index.ts +0 -255
  283. package/src/storage/storage.ts +0 -227
  284. package/src/tool/apply_patch.ts +0 -281
  285. package/src/tool/apply_patch.txt +0 -33
  286. package/src/tool/bash.ts +0 -269
  287. package/src/tool/bash.txt +0 -115
  288. package/src/tool/batch.ts +0 -175
  289. package/src/tool/batch.txt +0 -24
  290. package/src/tool/codesearch.ts +0 -132
  291. package/src/tool/codesearch.txt +0 -12
  292. package/src/tool/edit.ts +0 -655
  293. package/src/tool/edit.txt +0 -10
  294. package/src/tool/external-directory.ts +0 -32
  295. package/src/tool/glob.ts +0 -80
  296. package/src/tool/glob.txt +0 -6
  297. package/src/tool/grep.ts +0 -150
  298. package/src/tool/grep.txt +0 -8
  299. package/src/tool/invalid.ts +0 -17
  300. package/src/tool/ls.ts +0 -121
  301. package/src/tool/ls.txt +0 -1
  302. package/src/tool/lsp.ts +0 -96
  303. package/src/tool/lsp.txt +0 -19
  304. package/src/tool/multiedit.ts +0 -46
  305. package/src/tool/multiedit.txt +0 -41
  306. package/src/tool/plan-enter.txt +0 -14
  307. package/src/tool/plan-exit.txt +0 -13
  308. package/src/tool/plan.ts +0 -130
  309. package/src/tool/question.ts +0 -33
  310. package/src/tool/question.txt +0 -10
  311. package/src/tool/read.ts +0 -261
  312. package/src/tool/read.txt +0 -14
  313. package/src/tool/registry.ts +0 -160
  314. package/src/tool/skill.ts +0 -123
  315. package/src/tool/task.ts +0 -165
  316. package/src/tool/task.txt +0 -60
  317. package/src/tool/todo.ts +0 -53
  318. package/src/tool/todoread.txt +0 -14
  319. package/src/tool/todowrite.txt +0 -167
  320. package/src/tool/tool.ts +0 -89
  321. package/src/tool/truncation.ts +0 -106
  322. package/src/tool/webfetch.ts +0 -186
  323. package/src/tool/webfetch.txt +0 -13
  324. package/src/tool/websearch.ts +0 -150
  325. package/src/tool/websearch.txt +0 -14
  326. package/src/tool/write.ts +0 -85
  327. package/src/tool/write.txt +0 -8
  328. package/src/util/abort.ts +0 -35
  329. package/src/util/archive.ts +0 -16
  330. package/src/util/color.ts +0 -19
  331. package/src/util/context.ts +0 -25
  332. package/src/util/defer.ts +0 -12
  333. package/src/util/eventloop.ts +0 -20
  334. package/src/util/filesystem.ts +0 -93
  335. package/src/util/fn.ts +0 -11
  336. package/src/util/format.ts +0 -20
  337. package/src/util/iife.ts +0 -3
  338. package/src/util/keybind.ts +0 -103
  339. package/src/util/lazy.ts +0 -18
  340. package/src/util/locale.ts +0 -81
  341. package/src/util/lock.ts +0 -98
  342. package/src/util/log.ts +0 -180
  343. package/src/util/proxied.ts +0 -3
  344. package/src/util/queue.ts +0 -32
  345. package/src/util/rpc.ts +0 -66
  346. package/src/util/scrap.ts +0 -10
  347. package/src/util/signal.ts +0 -12
  348. package/src/util/timeout.ts +0 -14
  349. package/src/util/token.ts +0 -7
  350. package/src/util/wildcard.ts +0 -56
  351. package/src/worktree/index.ts +0 -612
  352. package/sst-env.d.ts +0 -9
  353. package/test/acp/agent-interface.test.ts +0 -51
  354. package/test/acp/event-subscription.test.ts +0 -436
  355. package/test/agent/agent.test.ts +0 -675
  356. package/test/bun.test.ts +0 -53
  357. package/test/cli/github-action.test.ts +0 -161
  358. package/test/cli/github-remote.test.ts +0 -80
  359. package/test/cli/import.test.ts +0 -38
  360. package/test/cli/tui/transcript.test.ts +0 -322
  361. package/test/config/agent-color.test.ts +0 -71
  362. package/test/config/config.test.ts +0 -1802
  363. package/test/config/fixtures/empty-frontmatter.md +0 -4
  364. package/test/config/fixtures/frontmatter.md +0 -28
  365. package/test/config/fixtures/markdown-header.md +0 -11
  366. package/test/config/fixtures/no-frontmatter.md +0 -1
  367. package/test/config/fixtures/weird-model-id.md +0 -13
  368. package/test/config/markdown.test.ts +0 -228
  369. package/test/file/ignore.test.ts +0 -10
  370. package/test/file/path-traversal.test.ts +0 -198
  371. package/test/file/ripgrep.test.ts +0 -39
  372. package/test/fixture/fixture.ts +0 -45
  373. package/test/fixture/lsp/fake-lsp-server.js +0 -77
  374. package/test/ide/ide.test.ts +0 -82
  375. package/test/keybind.test.ts +0 -421
  376. package/test/lsp/client.test.ts +0 -95
  377. package/test/mcp/headers.test.ts +0 -153
  378. package/test/mcp/oauth-browser.test.ts +0 -249
  379. package/test/memory/abort-leak.test.ts +0 -136
  380. package/test/patch/patch.test.ts +0 -348
  381. package/test/permission/arity.test.ts +0 -33
  382. package/test/permission/next.test.ts +0 -690
  383. package/test/permission-task.test.ts +0 -319
  384. package/test/plugin/auth-override.test.ts +0 -44
  385. package/test/plugin/codex.test.ts +0 -123
  386. package/test/preload.ts +0 -63
  387. package/test/project/project.test.ts +0 -120
  388. package/test/provider/amazon-bedrock.test.ts +0 -445
  389. package/test/provider/copilot/convert-to-copilot-messages.test.ts +0 -523
  390. package/test/provider/copilot/copilot-chat-model.test.ts +0 -592
  391. package/test/provider/gitlab-duo.test.ts +0 -262
  392. package/test/provider/provider.test.ts +0 -2129
  393. package/test/provider/transform.test.ts +0 -1928
  394. package/test/question/question.test.ts +0 -300
  395. package/test/scheduler.test.ts +0 -73
  396. package/test/server/session-list.test.ts +0 -39
  397. package/test/server/session-select.test.ts +0 -78
  398. package/test/session/compaction.test.ts +0 -423
  399. package/test/session/instruction.test.ts +0 -170
  400. package/test/session/llm.test.ts +0 -667
  401. package/test/session/message-v2.test.ts +0 -924
  402. package/test/session/prompt-missing-file.test.ts +0 -53
  403. package/test/session/prompt-special-chars.test.ts +0 -56
  404. package/test/session/prompt-variant.test.ts +0 -68
  405. package/test/session/retry.test.ts +0 -188
  406. package/test/session/revert-compact.test.ts +0 -285
  407. package/test/session/session.test.ts +0 -71
  408. package/test/session/structured-output-integration.test.ts +0 -233
  409. package/test/session/structured-output.test.ts +0 -385
  410. package/test/skill/discovery.test.ts +0 -60
  411. package/test/skill/skill.test.ts +0 -388
  412. package/test/snapshot/snapshot.test.ts +0 -1040
  413. package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
  414. package/test/tool/apply_patch.test.ts +0 -559
  415. package/test/tool/bash.test.ts +0 -399
  416. package/test/tool/external-directory.test.ts +0 -127
  417. package/test/tool/fixtures/large-image.png +0 -0
  418. package/test/tool/fixtures/models-api.json +0 -38413
  419. package/test/tool/grep.test.ts +0 -110
  420. package/test/tool/question.test.ts +0 -107
  421. package/test/tool/read.test.ts +0 -421
  422. package/test/tool/registry.test.ts +0 -122
  423. package/test/tool/skill.test.ts +0 -112
  424. package/test/tool/truncation.test.ts +0 -159
  425. package/test/util/filesystem.test.ts +0 -39
  426. package/test/util/format.test.ts +0 -59
  427. package/test/util/iife.test.ts +0 -36
  428. package/test/util/lazy.test.ts +0 -50
  429. package/test/util/lock.test.ts +0 -72
  430. package/test/util/timeout.test.ts +0 -21
  431. package/test/util/wildcard.test.ts +0 -75
  432. package/tsconfig.json +0 -16
  433. /package/{script/postinstall.mjs → postinstall.mjs} +0 -0
@@ -1,1802 +0,0 @@
1
- import { test, expect, describe, mock, afterEach } from "bun:test"
2
- import { Config } from "../../src/config/config"
3
- import { Instance } from "../../src/project/instance"
4
- import { Auth } from "../../src/auth"
5
- import { tmpdir } from "../fixture/fixture"
6
- import path from "path"
7
- import fs from "fs/promises"
8
- import { pathToFileURL } from "url"
9
- import { Global } from "../../src/global"
10
-
11
- // Get managed config directory from environment (set in preload.ts)
12
- const managedConfigDir = process.env.OPENCODE_TEST_MANAGED_CONFIG_DIR!
13
-
14
- afterEach(async () => {
15
- await fs.rm(managedConfigDir, { force: true, recursive: true }).catch(() => {})
16
- })
17
-
18
- async function writeManagedSettings(settings: object, filename = "opencode.json") {
19
- await fs.mkdir(managedConfigDir, { recursive: true })
20
- await Bun.write(path.join(managedConfigDir, filename), JSON.stringify(settings))
21
- }
22
-
23
- async function writeConfig(dir: string, config: object, name = "opencode.json") {
24
- await Bun.write(path.join(dir, name), JSON.stringify(config))
25
- }
26
-
27
- test("loads config with defaults when no files exist", async () => {
28
- await using tmp = await tmpdir()
29
- await Instance.provide({
30
- directory: tmp.path,
31
- fn: async () => {
32
- const config = await Config.get()
33
- expect(config.username).toBeDefined()
34
- },
35
- })
36
- })
37
-
38
- test("loads JSON config file", async () => {
39
- await using tmp = await tmpdir({
40
- init: async (dir) => {
41
- await writeConfig(dir, {
42
- $schema: "https://opencode.ai/config.json",
43
- model: "test/model",
44
- username: "testuser",
45
- })
46
- },
47
- })
48
- await Instance.provide({
49
- directory: tmp.path,
50
- fn: async () => {
51
- const config = await Config.get()
52
- expect(config.model).toBe("test/model")
53
- expect(config.username).toBe("testuser")
54
- },
55
- })
56
- })
57
-
58
- test("loads JSONC config file", async () => {
59
- await using tmp = await tmpdir({
60
- init: async (dir) => {
61
- await Bun.write(
62
- path.join(dir, "opencode.jsonc"),
63
- `{
64
- // This is a comment
65
- "$schema": "https://opencode.ai/config.json",
66
- "model": "test/model",
67
- "username": "testuser"
68
- }`,
69
- )
70
- },
71
- })
72
- await Instance.provide({
73
- directory: tmp.path,
74
- fn: async () => {
75
- const config = await Config.get()
76
- expect(config.model).toBe("test/model")
77
- expect(config.username).toBe("testuser")
78
- },
79
- })
80
- })
81
-
82
- test("merges multiple config files with correct precedence", async () => {
83
- await using tmp = await tmpdir({
84
- init: async (dir) => {
85
- await writeConfig(
86
- dir,
87
- {
88
- $schema: "https://opencode.ai/config.json",
89
- model: "base",
90
- username: "base",
91
- },
92
- "opencode.jsonc",
93
- )
94
- await writeConfig(dir, {
95
- $schema: "https://opencode.ai/config.json",
96
- model: "override",
97
- })
98
- },
99
- })
100
- await Instance.provide({
101
- directory: tmp.path,
102
- fn: async () => {
103
- const config = await Config.get()
104
- expect(config.model).toBe("override")
105
- expect(config.username).toBe("base")
106
- },
107
- })
108
- })
109
-
110
- test("handles environment variable substitution", async () => {
111
- const originalEnv = process.env["TEST_VAR"]
112
- process.env["TEST_VAR"] = "test_theme"
113
-
114
- try {
115
- await using tmp = await tmpdir({
116
- init: async (dir) => {
117
- await writeConfig(dir, {
118
- $schema: "https://opencode.ai/config.json",
119
- theme: "{env:TEST_VAR}",
120
- })
121
- },
122
- })
123
- await Instance.provide({
124
- directory: tmp.path,
125
- fn: async () => {
126
- const config = await Config.get()
127
- expect(config.theme).toBe("test_theme")
128
- },
129
- })
130
- } finally {
131
- if (originalEnv !== undefined) {
132
- process.env["TEST_VAR"] = originalEnv
133
- } else {
134
- delete process.env["TEST_VAR"]
135
- }
136
- }
137
- })
138
-
139
- test("preserves env variables when adding $schema to config", async () => {
140
- const originalEnv = process.env["PRESERVE_VAR"]
141
- process.env["PRESERVE_VAR"] = "secret_value"
142
-
143
- try {
144
- await using tmp = await tmpdir({
145
- init: async (dir) => {
146
- // Config without $schema - should trigger auto-add
147
- await Bun.write(
148
- path.join(dir, "opencode.json"),
149
- JSON.stringify({
150
- theme: "{env:PRESERVE_VAR}",
151
- }),
152
- )
153
- },
154
- })
155
- await Instance.provide({
156
- directory: tmp.path,
157
- fn: async () => {
158
- const config = await Config.get()
159
- expect(config.theme).toBe("secret_value")
160
-
161
- // Read the file to verify the env variable was preserved
162
- const content = await Bun.file(path.join(tmp.path, "opencode.json")).text()
163
- expect(content).toContain("{env:PRESERVE_VAR}")
164
- expect(content).not.toContain("secret_value")
165
- expect(content).toContain("$schema")
166
- },
167
- })
168
- } finally {
169
- if (originalEnv !== undefined) {
170
- process.env["PRESERVE_VAR"] = originalEnv
171
- } else {
172
- delete process.env["PRESERVE_VAR"]
173
- }
174
- }
175
- })
176
-
177
- test("handles file inclusion substitution", async () => {
178
- await using tmp = await tmpdir({
179
- init: async (dir) => {
180
- await Bun.write(path.join(dir, "included.txt"), "test_theme")
181
- await writeConfig(dir, {
182
- $schema: "https://opencode.ai/config.json",
183
- theme: "{file:included.txt}",
184
- })
185
- },
186
- })
187
- await Instance.provide({
188
- directory: tmp.path,
189
- fn: async () => {
190
- const config = await Config.get()
191
- expect(config.theme).toBe("test_theme")
192
- },
193
- })
194
- })
195
-
196
- test("handles file inclusion with replacement tokens", async () => {
197
- await using tmp = await tmpdir({
198
- init: async (dir) => {
199
- await Bun.write(path.join(dir, "included.md"), "const out = await Bun.$`echo hi`")
200
- await writeConfig(dir, {
201
- $schema: "https://opencode.ai/config.json",
202
- theme: "{file:included.md}",
203
- })
204
- },
205
- })
206
- await Instance.provide({
207
- directory: tmp.path,
208
- fn: async () => {
209
- const config = await Config.get()
210
- expect(config.theme).toBe("const out = await Bun.$`echo hi`")
211
- },
212
- })
213
- })
214
-
215
- test("validates config schema and throws on invalid fields", async () => {
216
- await using tmp = await tmpdir({
217
- init: async (dir) => {
218
- await writeConfig(dir, {
219
- $schema: "https://opencode.ai/config.json",
220
- invalid_field: "should cause error",
221
- })
222
- },
223
- })
224
- await Instance.provide({
225
- directory: tmp.path,
226
- fn: async () => {
227
- // Strict schema should throw an error for invalid fields
228
- await expect(Config.get()).rejects.toThrow()
229
- },
230
- })
231
- })
232
-
233
- test("throws error for invalid JSON", async () => {
234
- await using tmp = await tmpdir({
235
- init: async (dir) => {
236
- await Bun.write(path.join(dir, "opencode.json"), "{ invalid json }")
237
- },
238
- })
239
- await Instance.provide({
240
- directory: tmp.path,
241
- fn: async () => {
242
- await expect(Config.get()).rejects.toThrow()
243
- },
244
- })
245
- })
246
-
247
- test("handles agent configuration", async () => {
248
- await using tmp = await tmpdir({
249
- init: async (dir) => {
250
- await writeConfig(dir, {
251
- $schema: "https://opencode.ai/config.json",
252
- agent: {
253
- test_agent: {
254
- model: "test/model",
255
- temperature: 0.7,
256
- description: "test agent",
257
- },
258
- },
259
- })
260
- },
261
- })
262
- await Instance.provide({
263
- directory: tmp.path,
264
- fn: async () => {
265
- const config = await Config.get()
266
- expect(config.agent?.["test_agent"]).toEqual(
267
- expect.objectContaining({
268
- model: "test/model",
269
- temperature: 0.7,
270
- description: "test agent",
271
- }),
272
- )
273
- },
274
- })
275
- })
276
-
277
- test("treats agent variant as model-scoped setting (not provider option)", async () => {
278
- await using tmp = await tmpdir({
279
- init: async (dir) => {
280
- await writeConfig(dir, {
281
- $schema: "https://opencode.ai/config.json",
282
- agent: {
283
- test_agent: {
284
- model: "openai/gpt-5.2",
285
- variant: "xhigh",
286
- max_tokens: 123,
287
- },
288
- },
289
- })
290
- },
291
- })
292
-
293
- await Instance.provide({
294
- directory: tmp.path,
295
- fn: async () => {
296
- const config = await Config.get()
297
- const agent = config.agent?.["test_agent"]
298
-
299
- expect(agent?.variant).toBe("xhigh")
300
- expect(agent?.options).toMatchObject({
301
- max_tokens: 123,
302
- })
303
- expect(agent?.options).not.toHaveProperty("variant")
304
- },
305
- })
306
- })
307
-
308
- test("handles command configuration", async () => {
309
- await using tmp = await tmpdir({
310
- init: async (dir) => {
311
- await writeConfig(dir, {
312
- $schema: "https://opencode.ai/config.json",
313
- command: {
314
- test_command: {
315
- template: "test template",
316
- description: "test command",
317
- agent: "test_agent",
318
- },
319
- },
320
- })
321
- },
322
- })
323
- await Instance.provide({
324
- directory: tmp.path,
325
- fn: async () => {
326
- const config = await Config.get()
327
- expect(config.command?.["test_command"]).toEqual({
328
- template: "test template",
329
- description: "test command",
330
- agent: "test_agent",
331
- })
332
- },
333
- })
334
- })
335
-
336
- test("migrates autoshare to share field", async () => {
337
- await using tmp = await tmpdir({
338
- init: async (dir) => {
339
- await Bun.write(
340
- path.join(dir, "opencode.json"),
341
- JSON.stringify({
342
- $schema: "https://opencode.ai/config.json",
343
- autoshare: true,
344
- }),
345
- )
346
- },
347
- })
348
- await Instance.provide({
349
- directory: tmp.path,
350
- fn: async () => {
351
- const config = await Config.get()
352
- expect(config.share).toBe("auto")
353
- expect(config.autoshare).toBe(true)
354
- },
355
- })
356
- })
357
-
358
- test("migrates mode field to agent field", async () => {
359
- await using tmp = await tmpdir({
360
- init: async (dir) => {
361
- await Bun.write(
362
- path.join(dir, "opencode.json"),
363
- JSON.stringify({
364
- $schema: "https://opencode.ai/config.json",
365
- mode: {
366
- test_mode: {
367
- model: "test/model",
368
- temperature: 0.5,
369
- },
370
- },
371
- }),
372
- )
373
- },
374
- })
375
- await Instance.provide({
376
- directory: tmp.path,
377
- fn: async () => {
378
- const config = await Config.get()
379
- expect(config.agent?.["test_mode"]).toEqual({
380
- model: "test/model",
381
- temperature: 0.5,
382
- mode: "primary",
383
- options: {},
384
- permission: {},
385
- })
386
- },
387
- })
388
- })
389
-
390
- test("loads config from .opencode directory", async () => {
391
- await using tmp = await tmpdir({
392
- init: async (dir) => {
393
- const opencodeDir = path.join(dir, ".opencode")
394
- await fs.mkdir(opencodeDir, { recursive: true })
395
- const agentDir = path.join(opencodeDir, "agent")
396
- await fs.mkdir(agentDir, { recursive: true })
397
-
398
- await Bun.write(
399
- path.join(agentDir, "test.md"),
400
- `---
401
- model: test/model
402
- ---
403
- Test agent prompt`,
404
- )
405
- },
406
- })
407
- await Instance.provide({
408
- directory: tmp.path,
409
- fn: async () => {
410
- const config = await Config.get()
411
- expect(config.agent?.["test"]).toEqual(
412
- expect.objectContaining({
413
- name: "test",
414
- model: "test/model",
415
- prompt: "Test agent prompt",
416
- }),
417
- )
418
- },
419
- })
420
- })
421
-
422
- test("loads agents from .opencode/agents (plural)", async () => {
423
- await using tmp = await tmpdir({
424
- init: async (dir) => {
425
- const opencodeDir = path.join(dir, ".opencode")
426
- await fs.mkdir(opencodeDir, { recursive: true })
427
-
428
- const agentsDir = path.join(opencodeDir, "agents")
429
- await fs.mkdir(path.join(agentsDir, "nested"), { recursive: true })
430
-
431
- await Bun.write(
432
- path.join(agentsDir, "helper.md"),
433
- `---
434
- model: test/model
435
- mode: subagent
436
- ---
437
- Helper agent prompt`,
438
- )
439
-
440
- await Bun.write(
441
- path.join(agentsDir, "nested", "child.md"),
442
- `---
443
- model: test/model
444
- mode: subagent
445
- ---
446
- Nested agent prompt`,
447
- )
448
- },
449
- })
450
-
451
- await Instance.provide({
452
- directory: tmp.path,
453
- fn: async () => {
454
- const config = await Config.get()
455
-
456
- expect(config.agent?.["helper"]).toMatchObject({
457
- name: "helper",
458
- model: "test/model",
459
- mode: "subagent",
460
- prompt: "Helper agent prompt",
461
- })
462
-
463
- expect(config.agent?.["nested/child"]).toMatchObject({
464
- name: "nested/child",
465
- model: "test/model",
466
- mode: "subagent",
467
- prompt: "Nested agent prompt",
468
- })
469
- },
470
- })
471
- })
472
-
473
- test("loads commands from .opencode/command (singular)", async () => {
474
- await using tmp = await tmpdir({
475
- init: async (dir) => {
476
- const opencodeDir = path.join(dir, ".opencode")
477
- await fs.mkdir(opencodeDir, { recursive: true })
478
-
479
- const commandDir = path.join(opencodeDir, "command")
480
- await fs.mkdir(path.join(commandDir, "nested"), { recursive: true })
481
-
482
- await Bun.write(
483
- path.join(commandDir, "hello.md"),
484
- `---
485
- description: Test command
486
- ---
487
- Hello from singular command`,
488
- )
489
-
490
- await Bun.write(
491
- path.join(commandDir, "nested", "child.md"),
492
- `---
493
- description: Nested command
494
- ---
495
- Nested command template`,
496
- )
497
- },
498
- })
499
-
500
- await Instance.provide({
501
- directory: tmp.path,
502
- fn: async () => {
503
- const config = await Config.get()
504
-
505
- expect(config.command?.["hello"]).toEqual({
506
- description: "Test command",
507
- template: "Hello from singular command",
508
- })
509
-
510
- expect(config.command?.["nested/child"]).toEqual({
511
- description: "Nested command",
512
- template: "Nested command template",
513
- })
514
- },
515
- })
516
- })
517
-
518
- test("loads commands from .opencode/commands (plural)", async () => {
519
- await using tmp = await tmpdir({
520
- init: async (dir) => {
521
- const opencodeDir = path.join(dir, ".opencode")
522
- await fs.mkdir(opencodeDir, { recursive: true })
523
-
524
- const commandsDir = path.join(opencodeDir, "commands")
525
- await fs.mkdir(path.join(commandsDir, "nested"), { recursive: true })
526
-
527
- await Bun.write(
528
- path.join(commandsDir, "hello.md"),
529
- `---
530
- description: Test command
531
- ---
532
- Hello from plural commands`,
533
- )
534
-
535
- await Bun.write(
536
- path.join(commandsDir, "nested", "child.md"),
537
- `---
538
- description: Nested command
539
- ---
540
- Nested command template`,
541
- )
542
- },
543
- })
544
-
545
- await Instance.provide({
546
- directory: tmp.path,
547
- fn: async () => {
548
- const config = await Config.get()
549
-
550
- expect(config.command?.["hello"]).toEqual({
551
- description: "Test command",
552
- template: "Hello from plural commands",
553
- })
554
-
555
- expect(config.command?.["nested/child"]).toEqual({
556
- description: "Nested command",
557
- template: "Nested command template",
558
- })
559
- },
560
- })
561
- })
562
-
563
- test("updates config and writes to file", async () => {
564
- await using tmp = await tmpdir()
565
- await Instance.provide({
566
- directory: tmp.path,
567
- fn: async () => {
568
- const newConfig = { model: "updated/model" }
569
- await Config.update(newConfig as any)
570
-
571
- const writtenConfig = JSON.parse(await Bun.file(path.join(tmp.path, "config.json")).text())
572
- expect(writtenConfig.model).toBe("updated/model")
573
- },
574
- })
575
- })
576
-
577
- test("gets config directories", async () => {
578
- await using tmp = await tmpdir()
579
- await Instance.provide({
580
- directory: tmp.path,
581
- fn: async () => {
582
- const dirs = await Config.directories()
583
- expect(dirs.length).toBeGreaterThanOrEqual(1)
584
- },
585
- })
586
- })
587
-
588
- test("does not try to install dependencies in read-only OPENCODE_CONFIG_DIR", async () => {
589
- if (process.platform === "win32") return
590
-
591
- await using tmp = await tmpdir<string>({
592
- init: async (dir) => {
593
- const ro = path.join(dir, "readonly")
594
- await fs.mkdir(ro, { recursive: true })
595
- await fs.chmod(ro, 0o555)
596
- return ro
597
- },
598
- dispose: async (dir) => {
599
- const ro = path.join(dir, "readonly")
600
- await fs.chmod(ro, 0o755).catch(() => {})
601
- return ro
602
- },
603
- })
604
-
605
- const prev = process.env.OPENCODE_CONFIG_DIR
606
- process.env.OPENCODE_CONFIG_DIR = tmp.extra
607
-
608
- try {
609
- await Instance.provide({
610
- directory: tmp.path,
611
- fn: async () => {
612
- await Config.get()
613
- },
614
- })
615
- } finally {
616
- if (prev === undefined) delete process.env.OPENCODE_CONFIG_DIR
617
- else process.env.OPENCODE_CONFIG_DIR = prev
618
- }
619
- })
620
-
621
- test("installs dependencies in writable OPENCODE_CONFIG_DIR", async () => {
622
- await using tmp = await tmpdir<string>({
623
- init: async (dir) => {
624
- const cfg = path.join(dir, "configdir")
625
- await fs.mkdir(cfg, { recursive: true })
626
- return cfg
627
- },
628
- })
629
-
630
- const prev = process.env.OPENCODE_CONFIG_DIR
631
- process.env.OPENCODE_CONFIG_DIR = tmp.extra
632
-
633
- try {
634
- await Instance.provide({
635
- directory: tmp.path,
636
- fn: async () => {
637
- await Config.get()
638
- await Config.waitForDependencies()
639
- },
640
- })
641
-
642
- expect(await Bun.file(path.join(tmp.extra, "package.json")).exists()).toBe(true)
643
- expect(await Bun.file(path.join(tmp.extra, ".gitignore")).exists()).toBe(true)
644
- } finally {
645
- if (prev === undefined) delete process.env.OPENCODE_CONFIG_DIR
646
- else process.env.OPENCODE_CONFIG_DIR = prev
647
- }
648
- })
649
-
650
- test("resolves scoped npm plugins in config", async () => {
651
- await using tmp = await tmpdir({
652
- init: async (dir) => {
653
- const pluginDir = path.join(dir, "node_modules", "@scope", "plugin")
654
- await fs.mkdir(pluginDir, { recursive: true })
655
-
656
- await Bun.write(
657
- path.join(dir, "package.json"),
658
- JSON.stringify({ name: "config-fixture", version: "1.0.0", type: "module" }, null, 2),
659
- )
660
-
661
- await Bun.write(
662
- path.join(pluginDir, "package.json"),
663
- JSON.stringify(
664
- {
665
- name: "@scope/plugin",
666
- version: "1.0.0",
667
- type: "module",
668
- main: "./index.js",
669
- },
670
- null,
671
- 2,
672
- ),
673
- )
674
-
675
- await Bun.write(path.join(pluginDir, "index.js"), "export default {}\n")
676
-
677
- await Bun.write(
678
- path.join(dir, "opencode.json"),
679
- JSON.stringify({ $schema: "https://opencode.ai/config.json", plugin: ["@scope/plugin"] }, null, 2),
680
- )
681
- },
682
- })
683
-
684
- await Instance.provide({
685
- directory: tmp.path,
686
- fn: async () => {
687
- const config = await Config.get()
688
- const pluginEntries = config.plugin ?? []
689
-
690
- const baseUrl = pathToFileURL(path.join(tmp.path, "opencode.json")).href
691
- const expected = import.meta.resolve("@scope/plugin", baseUrl)
692
-
693
- expect(pluginEntries.includes(expected)).toBe(true)
694
-
695
- const scopedEntry = pluginEntries.find((entry) => entry === expected)
696
- expect(scopedEntry).toBeDefined()
697
- expect(scopedEntry?.includes("/node_modules/@scope/plugin/")).toBe(true)
698
- },
699
- })
700
- })
701
-
702
- test("merges plugin arrays from global and local configs", async () => {
703
- await using tmp = await tmpdir({
704
- init: async (dir) => {
705
- // Create a nested project structure with local .opencode config
706
- const projectDir = path.join(dir, "project")
707
- const opencodeDir = path.join(projectDir, ".opencode")
708
- await fs.mkdir(opencodeDir, { recursive: true })
709
-
710
- // Global config with plugins
711
- await Bun.write(
712
- path.join(dir, "opencode.json"),
713
- JSON.stringify({
714
- $schema: "https://opencode.ai/config.json",
715
- plugin: ["global-plugin-1", "global-plugin-2"],
716
- }),
717
- )
718
-
719
- // Local .opencode config with different plugins
720
- await Bun.write(
721
- path.join(opencodeDir, "opencode.json"),
722
- JSON.stringify({
723
- $schema: "https://opencode.ai/config.json",
724
- plugin: ["local-plugin-1"],
725
- }),
726
- )
727
- },
728
- })
729
-
730
- await Instance.provide({
731
- directory: path.join(tmp.path, "project"),
732
- fn: async () => {
733
- const config = await Config.get()
734
- const plugins = config.plugin ?? []
735
-
736
- // Should contain both global and local plugins
737
- expect(plugins.some((p) => p.includes("global-plugin-1"))).toBe(true)
738
- expect(plugins.some((p) => p.includes("global-plugin-2"))).toBe(true)
739
- expect(plugins.some((p) => p.includes("local-plugin-1"))).toBe(true)
740
-
741
- // Should have all 3 plugins (not replaced, but merged)
742
- const pluginNames = plugins.filter((p) => p.includes("global-plugin") || p.includes("local-plugin"))
743
- expect(pluginNames.length).toBeGreaterThanOrEqual(3)
744
- },
745
- })
746
- })
747
-
748
- test("does not error when only custom agent is a subagent", async () => {
749
- await using tmp = await tmpdir({
750
- init: async (dir) => {
751
- const opencodeDir = path.join(dir, ".opencode")
752
- await fs.mkdir(opencodeDir, { recursive: true })
753
- const agentDir = path.join(opencodeDir, "agent")
754
- await fs.mkdir(agentDir, { recursive: true })
755
-
756
- await Bun.write(
757
- path.join(agentDir, "helper.md"),
758
- `---
759
- model: test/model
760
- mode: subagent
761
- ---
762
- Helper subagent prompt`,
763
- )
764
- },
765
- })
766
- await Instance.provide({
767
- directory: tmp.path,
768
- fn: async () => {
769
- const config = await Config.get()
770
- expect(config.agent?.["helper"]).toMatchObject({
771
- name: "helper",
772
- model: "test/model",
773
- mode: "subagent",
774
- prompt: "Helper subagent prompt",
775
- })
776
- },
777
- })
778
- })
779
-
780
- test("merges instructions arrays from global and local configs", async () => {
781
- await using tmp = await tmpdir({
782
- init: async (dir) => {
783
- const projectDir = path.join(dir, "project")
784
- const opencodeDir = path.join(projectDir, ".opencode")
785
- await fs.mkdir(opencodeDir, { recursive: true })
786
-
787
- await Bun.write(
788
- path.join(dir, "opencode.json"),
789
- JSON.stringify({
790
- $schema: "https://opencode.ai/config.json",
791
- instructions: ["global-instructions.md", "shared-rules.md"],
792
- }),
793
- )
794
-
795
- await Bun.write(
796
- path.join(opencodeDir, "opencode.json"),
797
- JSON.stringify({
798
- $schema: "https://opencode.ai/config.json",
799
- instructions: ["local-instructions.md"],
800
- }),
801
- )
802
- },
803
- })
804
-
805
- await Instance.provide({
806
- directory: path.join(tmp.path, "project"),
807
- fn: async () => {
808
- const config = await Config.get()
809
- const instructions = config.instructions ?? []
810
-
811
- expect(instructions).toContain("global-instructions.md")
812
- expect(instructions).toContain("shared-rules.md")
813
- expect(instructions).toContain("local-instructions.md")
814
- expect(instructions.length).toBe(3)
815
- },
816
- })
817
- })
818
-
819
- test("deduplicates duplicate instructions from global and local configs", async () => {
820
- await using tmp = await tmpdir({
821
- init: async (dir) => {
822
- const projectDir = path.join(dir, "project")
823
- const opencodeDir = path.join(projectDir, ".opencode")
824
- await fs.mkdir(opencodeDir, { recursive: true })
825
-
826
- await Bun.write(
827
- path.join(dir, "opencode.json"),
828
- JSON.stringify({
829
- $schema: "https://opencode.ai/config.json",
830
- instructions: ["duplicate.md", "global-only.md"],
831
- }),
832
- )
833
-
834
- await Bun.write(
835
- path.join(opencodeDir, "opencode.json"),
836
- JSON.stringify({
837
- $schema: "https://opencode.ai/config.json",
838
- instructions: ["duplicate.md", "local-only.md"],
839
- }),
840
- )
841
- },
842
- })
843
-
844
- await Instance.provide({
845
- directory: path.join(tmp.path, "project"),
846
- fn: async () => {
847
- const config = await Config.get()
848
- const instructions = config.instructions ?? []
849
-
850
- expect(instructions).toContain("global-only.md")
851
- expect(instructions).toContain("local-only.md")
852
- expect(instructions).toContain("duplicate.md")
853
-
854
- const duplicates = instructions.filter((i) => i === "duplicate.md")
855
- expect(duplicates.length).toBe(1)
856
- expect(instructions.length).toBe(3)
857
- },
858
- })
859
- })
860
-
861
- test("deduplicates duplicate plugins from global and local configs", async () => {
862
- await using tmp = await tmpdir({
863
- init: async (dir) => {
864
- // Create a nested project structure with local .opencode config
865
- const projectDir = path.join(dir, "project")
866
- const opencodeDir = path.join(projectDir, ".opencode")
867
- await fs.mkdir(opencodeDir, { recursive: true })
868
-
869
- // Global config with plugins
870
- await Bun.write(
871
- path.join(dir, "opencode.json"),
872
- JSON.stringify({
873
- $schema: "https://opencode.ai/config.json",
874
- plugin: ["duplicate-plugin", "global-plugin-1"],
875
- }),
876
- )
877
-
878
- // Local .opencode config with some overlapping plugins
879
- await Bun.write(
880
- path.join(opencodeDir, "opencode.json"),
881
- JSON.stringify({
882
- $schema: "https://opencode.ai/config.json",
883
- plugin: ["duplicate-plugin", "local-plugin-1"],
884
- }),
885
- )
886
- },
887
- })
888
-
889
- await Instance.provide({
890
- directory: path.join(tmp.path, "project"),
891
- fn: async () => {
892
- const config = await Config.get()
893
- const plugins = config.plugin ?? []
894
-
895
- // Should contain all unique plugins
896
- expect(plugins.some((p) => p.includes("global-plugin-1"))).toBe(true)
897
- expect(plugins.some((p) => p.includes("local-plugin-1"))).toBe(true)
898
- expect(plugins.some((p) => p.includes("duplicate-plugin"))).toBe(true)
899
-
900
- // Should deduplicate the duplicate plugin
901
- const duplicatePlugins = plugins.filter((p) => p.includes("duplicate-plugin"))
902
- expect(duplicatePlugins.length).toBe(1)
903
-
904
- // Should have exactly 3 unique plugins
905
- const pluginNames = plugins.filter(
906
- (p) => p.includes("global-plugin") || p.includes("local-plugin") || p.includes("duplicate-plugin"),
907
- )
908
- expect(pluginNames.length).toBe(3)
909
- },
910
- })
911
- })
912
-
913
- // Legacy tools migration tests
914
-
915
- test("migrates legacy tools config to permissions - allow", async () => {
916
- await using tmp = await tmpdir({
917
- init: async (dir) => {
918
- await Bun.write(
919
- path.join(dir, "opencode.json"),
920
- JSON.stringify({
921
- $schema: "https://opencode.ai/config.json",
922
- agent: {
923
- test: {
924
- tools: {
925
- bash: true,
926
- read: true,
927
- },
928
- },
929
- },
930
- }),
931
- )
932
- },
933
- })
934
- await Instance.provide({
935
- directory: tmp.path,
936
- fn: async () => {
937
- const config = await Config.get()
938
- expect(config.agent?.["test"]?.permission).toEqual({
939
- bash: "allow",
940
- read: "allow",
941
- })
942
- },
943
- })
944
- })
945
-
946
- test("migrates legacy tools config to permissions - deny", async () => {
947
- await using tmp = await tmpdir({
948
- init: async (dir) => {
949
- await Bun.write(
950
- path.join(dir, "opencode.json"),
951
- JSON.stringify({
952
- $schema: "https://opencode.ai/config.json",
953
- agent: {
954
- test: {
955
- tools: {
956
- bash: false,
957
- webfetch: false,
958
- },
959
- },
960
- },
961
- }),
962
- )
963
- },
964
- })
965
- await Instance.provide({
966
- directory: tmp.path,
967
- fn: async () => {
968
- const config = await Config.get()
969
- expect(config.agent?.["test"]?.permission).toEqual({
970
- bash: "deny",
971
- webfetch: "deny",
972
- })
973
- },
974
- })
975
- })
976
-
977
- test("migrates legacy write tool to edit permission", async () => {
978
- await using tmp = await tmpdir({
979
- init: async (dir) => {
980
- await Bun.write(
981
- path.join(dir, "opencode.json"),
982
- JSON.stringify({
983
- $schema: "https://opencode.ai/config.json",
984
- agent: {
985
- test: {
986
- tools: {
987
- write: true,
988
- },
989
- },
990
- },
991
- }),
992
- )
993
- },
994
- })
995
- await Instance.provide({
996
- directory: tmp.path,
997
- fn: async () => {
998
- const config = await Config.get()
999
- expect(config.agent?.["test"]?.permission).toEqual({
1000
- edit: "allow",
1001
- })
1002
- },
1003
- })
1004
- })
1005
-
1006
- // Managed settings tests
1007
- // Note: preload.ts sets OPENCODE_TEST_MANAGED_CONFIG which Global.Path.managedConfig uses
1008
-
1009
- test("managed settings override user settings", async () => {
1010
- await using tmp = await tmpdir({
1011
- init: async (dir) => {
1012
- await writeConfig(dir, {
1013
- $schema: "https://opencode.ai/config.json",
1014
- model: "user/model",
1015
- share: "auto",
1016
- username: "testuser",
1017
- })
1018
- },
1019
- })
1020
-
1021
- await writeManagedSettings({
1022
- $schema: "https://opencode.ai/config.json",
1023
- model: "managed/model",
1024
- share: "disabled",
1025
- })
1026
-
1027
- await Instance.provide({
1028
- directory: tmp.path,
1029
- fn: async () => {
1030
- const config = await Config.get()
1031
- expect(config.model).toBe("managed/model")
1032
- expect(config.share).toBe("disabled")
1033
- expect(config.username).toBe("testuser")
1034
- },
1035
- })
1036
- })
1037
-
1038
- test("managed settings override project settings", async () => {
1039
- await using tmp = await tmpdir({
1040
- init: async (dir) => {
1041
- await writeConfig(dir, {
1042
- $schema: "https://opencode.ai/config.json",
1043
- autoupdate: true,
1044
- disabled_providers: [],
1045
- theme: "dark",
1046
- })
1047
- },
1048
- })
1049
-
1050
- await writeManagedSettings({
1051
- $schema: "https://opencode.ai/config.json",
1052
- autoupdate: false,
1053
- disabled_providers: ["openai"],
1054
- })
1055
-
1056
- await Instance.provide({
1057
- directory: tmp.path,
1058
- fn: async () => {
1059
- const config = await Config.get()
1060
- expect(config.autoupdate).toBe(false)
1061
- expect(config.disabled_providers).toEqual(["openai"])
1062
- expect(config.theme).toBe("dark")
1063
- },
1064
- })
1065
- })
1066
-
1067
- test("missing managed settings file is not an error", async () => {
1068
- await using tmp = await tmpdir({
1069
- init: async (dir) => {
1070
- await writeConfig(dir, {
1071
- $schema: "https://opencode.ai/config.json",
1072
- model: "user/model",
1073
- })
1074
- },
1075
- })
1076
-
1077
- await Instance.provide({
1078
- directory: tmp.path,
1079
- fn: async () => {
1080
- const config = await Config.get()
1081
- expect(config.model).toBe("user/model")
1082
- },
1083
- })
1084
- })
1085
-
1086
- test("migrates legacy edit tool to edit permission", async () => {
1087
- await using tmp = await tmpdir({
1088
- init: async (dir) => {
1089
- await Bun.write(
1090
- path.join(dir, "opencode.json"),
1091
- JSON.stringify({
1092
- $schema: "https://opencode.ai/config.json",
1093
- agent: {
1094
- test: {
1095
- tools: {
1096
- edit: false,
1097
- },
1098
- },
1099
- },
1100
- }),
1101
- )
1102
- },
1103
- })
1104
- await Instance.provide({
1105
- directory: tmp.path,
1106
- fn: async () => {
1107
- const config = await Config.get()
1108
- expect(config.agent?.["test"]?.permission).toEqual({
1109
- edit: "deny",
1110
- })
1111
- },
1112
- })
1113
- })
1114
-
1115
- test("migrates legacy patch tool to edit permission", async () => {
1116
- await using tmp = await tmpdir({
1117
- init: async (dir) => {
1118
- await Bun.write(
1119
- path.join(dir, "opencode.json"),
1120
- JSON.stringify({
1121
- $schema: "https://opencode.ai/config.json",
1122
- agent: {
1123
- test: {
1124
- tools: {
1125
- patch: true,
1126
- },
1127
- },
1128
- },
1129
- }),
1130
- )
1131
- },
1132
- })
1133
- await Instance.provide({
1134
- directory: tmp.path,
1135
- fn: async () => {
1136
- const config = await Config.get()
1137
- expect(config.agent?.["test"]?.permission).toEqual({
1138
- edit: "allow",
1139
- })
1140
- },
1141
- })
1142
- })
1143
-
1144
- test("migrates legacy multiedit tool to edit permission", async () => {
1145
- await using tmp = await tmpdir({
1146
- init: async (dir) => {
1147
- await Bun.write(
1148
- path.join(dir, "opencode.json"),
1149
- JSON.stringify({
1150
- $schema: "https://opencode.ai/config.json",
1151
- agent: {
1152
- test: {
1153
- tools: {
1154
- multiedit: false,
1155
- },
1156
- },
1157
- },
1158
- }),
1159
- )
1160
- },
1161
- })
1162
- await Instance.provide({
1163
- directory: tmp.path,
1164
- fn: async () => {
1165
- const config = await Config.get()
1166
- expect(config.agent?.["test"]?.permission).toEqual({
1167
- edit: "deny",
1168
- })
1169
- },
1170
- })
1171
- })
1172
-
1173
- test("migrates mixed legacy tools config", async () => {
1174
- await using tmp = await tmpdir({
1175
- init: async (dir) => {
1176
- await Bun.write(
1177
- path.join(dir, "opencode.json"),
1178
- JSON.stringify({
1179
- $schema: "https://opencode.ai/config.json",
1180
- agent: {
1181
- test: {
1182
- tools: {
1183
- bash: true,
1184
- write: true,
1185
- read: false,
1186
- webfetch: true,
1187
- },
1188
- },
1189
- },
1190
- }),
1191
- )
1192
- },
1193
- })
1194
- await Instance.provide({
1195
- directory: tmp.path,
1196
- fn: async () => {
1197
- const config = await Config.get()
1198
- expect(config.agent?.["test"]?.permission).toEqual({
1199
- bash: "allow",
1200
- edit: "allow",
1201
- read: "deny",
1202
- webfetch: "allow",
1203
- })
1204
- },
1205
- })
1206
- })
1207
-
1208
- test("merges legacy tools with existing permission config", async () => {
1209
- await using tmp = await tmpdir({
1210
- init: async (dir) => {
1211
- await Bun.write(
1212
- path.join(dir, "opencode.json"),
1213
- JSON.stringify({
1214
- $schema: "https://opencode.ai/config.json",
1215
- agent: {
1216
- test: {
1217
- permission: {
1218
- glob: "allow",
1219
- },
1220
- tools: {
1221
- bash: true,
1222
- },
1223
- },
1224
- },
1225
- }),
1226
- )
1227
- },
1228
- })
1229
- await Instance.provide({
1230
- directory: tmp.path,
1231
- fn: async () => {
1232
- const config = await Config.get()
1233
- expect(config.agent?.["test"]?.permission).toEqual({
1234
- glob: "allow",
1235
- bash: "allow",
1236
- })
1237
- },
1238
- })
1239
- })
1240
-
1241
- test("permission config preserves key order", async () => {
1242
- await using tmp = await tmpdir({
1243
- init: async (dir) => {
1244
- await Bun.write(
1245
- path.join(dir, "opencode.json"),
1246
- JSON.stringify({
1247
- $schema: "https://opencode.ai/config.json",
1248
- permission: {
1249
- "*": "deny",
1250
- edit: "ask",
1251
- write: "ask",
1252
- external_directory: "ask",
1253
- read: "allow",
1254
- todowrite: "allow",
1255
- todoread: "allow",
1256
- "thoughts_*": "allow",
1257
- "reasoning_model_*": "allow",
1258
- "tools_*": "allow",
1259
- "pr_comments_*": "allow",
1260
- },
1261
- }),
1262
- )
1263
- },
1264
- })
1265
- await Instance.provide({
1266
- directory: tmp.path,
1267
- fn: async () => {
1268
- const config = await Config.get()
1269
- expect(Object.keys(config.permission!)).toEqual([
1270
- "*",
1271
- "edit",
1272
- "write",
1273
- "external_directory",
1274
- "read",
1275
- "todowrite",
1276
- "todoread",
1277
- "thoughts_*",
1278
- "reasoning_model_*",
1279
- "tools_*",
1280
- "pr_comments_*",
1281
- ])
1282
- },
1283
- })
1284
- })
1285
-
1286
- // MCP config merging tests
1287
-
1288
- test("project config can override MCP server enabled status", async () => {
1289
- await using tmp = await tmpdir({
1290
- init: async (dir) => {
1291
- // Simulates a base config (like from remote .well-known) with disabled MCP
1292
- await Bun.write(
1293
- path.join(dir, "opencode.jsonc"),
1294
- JSON.stringify({
1295
- $schema: "https://opencode.ai/config.json",
1296
- mcp: {
1297
- jira: {
1298
- type: "remote",
1299
- url: "https://jira.example.com/mcp",
1300
- enabled: false,
1301
- },
1302
- wiki: {
1303
- type: "remote",
1304
- url: "https://wiki.example.com/mcp",
1305
- enabled: false,
1306
- },
1307
- },
1308
- }),
1309
- )
1310
- // Project config enables just jira
1311
- await Bun.write(
1312
- path.join(dir, "opencode.json"),
1313
- JSON.stringify({
1314
- $schema: "https://opencode.ai/config.json",
1315
- mcp: {
1316
- jira: {
1317
- type: "remote",
1318
- url: "https://jira.example.com/mcp",
1319
- enabled: true,
1320
- },
1321
- },
1322
- }),
1323
- )
1324
- },
1325
- })
1326
- await Instance.provide({
1327
- directory: tmp.path,
1328
- fn: async () => {
1329
- const config = await Config.get()
1330
- // jira should be enabled (overridden by project config)
1331
- expect(config.mcp?.jira).toEqual({
1332
- type: "remote",
1333
- url: "https://jira.example.com/mcp",
1334
- enabled: true,
1335
- })
1336
- // wiki should still be disabled (not overridden)
1337
- expect(config.mcp?.wiki).toEqual({
1338
- type: "remote",
1339
- url: "https://wiki.example.com/mcp",
1340
- enabled: false,
1341
- })
1342
- },
1343
- })
1344
- })
1345
-
1346
- test("MCP config deep merges preserving base config properties", async () => {
1347
- await using tmp = await tmpdir({
1348
- init: async (dir) => {
1349
- // Base config with full MCP definition
1350
- await Bun.write(
1351
- path.join(dir, "opencode.jsonc"),
1352
- JSON.stringify({
1353
- $schema: "https://opencode.ai/config.json",
1354
- mcp: {
1355
- myserver: {
1356
- type: "remote",
1357
- url: "https://myserver.example.com/mcp",
1358
- enabled: false,
1359
- headers: {
1360
- "X-Custom-Header": "value",
1361
- },
1362
- },
1363
- },
1364
- }),
1365
- )
1366
- // Override just enables it, should preserve other properties
1367
- await Bun.write(
1368
- path.join(dir, "opencode.json"),
1369
- JSON.stringify({
1370
- $schema: "https://opencode.ai/config.json",
1371
- mcp: {
1372
- myserver: {
1373
- type: "remote",
1374
- url: "https://myserver.example.com/mcp",
1375
- enabled: true,
1376
- },
1377
- },
1378
- }),
1379
- )
1380
- },
1381
- })
1382
- await Instance.provide({
1383
- directory: tmp.path,
1384
- fn: async () => {
1385
- const config = await Config.get()
1386
- expect(config.mcp?.myserver).toEqual({
1387
- type: "remote",
1388
- url: "https://myserver.example.com/mcp",
1389
- enabled: true,
1390
- headers: {
1391
- "X-Custom-Header": "value",
1392
- },
1393
- })
1394
- },
1395
- })
1396
- })
1397
-
1398
- test("local .opencode config can override MCP from project config", async () => {
1399
- await using tmp = await tmpdir({
1400
- init: async (dir) => {
1401
- // Project config with disabled MCP
1402
- await Bun.write(
1403
- path.join(dir, "opencode.json"),
1404
- JSON.stringify({
1405
- $schema: "https://opencode.ai/config.json",
1406
- mcp: {
1407
- docs: {
1408
- type: "remote",
1409
- url: "https://docs.example.com/mcp",
1410
- enabled: false,
1411
- },
1412
- },
1413
- }),
1414
- )
1415
- // Local .opencode directory config enables it
1416
- const opencodeDir = path.join(dir, ".opencode")
1417
- await fs.mkdir(opencodeDir, { recursive: true })
1418
- await Bun.write(
1419
- path.join(opencodeDir, "opencode.json"),
1420
- JSON.stringify({
1421
- $schema: "https://opencode.ai/config.json",
1422
- mcp: {
1423
- docs: {
1424
- type: "remote",
1425
- url: "https://docs.example.com/mcp",
1426
- enabled: true,
1427
- },
1428
- },
1429
- }),
1430
- )
1431
- },
1432
- })
1433
- await Instance.provide({
1434
- directory: tmp.path,
1435
- fn: async () => {
1436
- const config = await Config.get()
1437
- expect(config.mcp?.docs?.enabled).toBe(true)
1438
- },
1439
- })
1440
- })
1441
-
1442
- test("project config overrides remote well-known config", async () => {
1443
- const originalFetch = globalThis.fetch
1444
- let fetchedUrl: string | undefined
1445
- const mockFetch = mock((url: string | URL | Request) => {
1446
- const urlStr = url.toString()
1447
- if (urlStr.includes(".well-known/opencode")) {
1448
- fetchedUrl = urlStr
1449
- return Promise.resolve(
1450
- new Response(
1451
- JSON.stringify({
1452
- config: {
1453
- mcp: {
1454
- jira: {
1455
- type: "remote",
1456
- url: "https://jira.example.com/mcp",
1457
- enabled: false,
1458
- },
1459
- },
1460
- },
1461
- }),
1462
- { status: 200 },
1463
- ),
1464
- )
1465
- }
1466
- return originalFetch(url)
1467
- })
1468
- globalThis.fetch = mockFetch as unknown as typeof fetch
1469
-
1470
- const originalAuthAll = Auth.all
1471
- Auth.all = mock(() =>
1472
- Promise.resolve({
1473
- "https://example.com": {
1474
- type: "wellknown" as const,
1475
- key: "TEST_TOKEN",
1476
- token: "test-token",
1477
- },
1478
- }),
1479
- )
1480
-
1481
- try {
1482
- await using tmp = await tmpdir({
1483
- git: true,
1484
- init: async (dir) => {
1485
- // Project config enables jira (overriding remote default)
1486
- await Bun.write(
1487
- path.join(dir, "opencode.json"),
1488
- JSON.stringify({
1489
- $schema: "https://opencode.ai/config.json",
1490
- mcp: {
1491
- jira: {
1492
- type: "remote",
1493
- url: "https://jira.example.com/mcp",
1494
- enabled: true,
1495
- },
1496
- },
1497
- }),
1498
- )
1499
- },
1500
- })
1501
- await Instance.provide({
1502
- directory: tmp.path,
1503
- fn: async () => {
1504
- const config = await Config.get()
1505
- // Verify fetch was called for wellknown config
1506
- expect(fetchedUrl).toBe("https://example.com/.well-known/opencode")
1507
- // Project config (enabled: true) should override remote (enabled: false)
1508
- expect(config.mcp?.jira?.enabled).toBe(true)
1509
- },
1510
- })
1511
- } finally {
1512
- globalThis.fetch = originalFetch
1513
- Auth.all = originalAuthAll
1514
- }
1515
- })
1516
-
1517
- describe("getPluginName", () => {
1518
- test("extracts name from file:// URL", () => {
1519
- expect(Config.getPluginName("file:///path/to/plugin/foo.js")).toBe("foo")
1520
- expect(Config.getPluginName("file:///path/to/plugin/bar.ts")).toBe("bar")
1521
- expect(Config.getPluginName("file:///some/path/my-plugin.js")).toBe("my-plugin")
1522
- })
1523
-
1524
- test("extracts name from npm package with version", () => {
1525
- expect(Config.getPluginName("oh-my-opencode@2.4.3")).toBe("oh-my-opencode")
1526
- expect(Config.getPluginName("some-plugin@1.0.0")).toBe("some-plugin")
1527
- expect(Config.getPluginName("plugin@latest")).toBe("plugin")
1528
- })
1529
-
1530
- test("extracts name from scoped npm package", () => {
1531
- expect(Config.getPluginName("@scope/pkg@1.0.0")).toBe("@scope/pkg")
1532
- expect(Config.getPluginName("@opencode/plugin@2.0.0")).toBe("@opencode/plugin")
1533
- })
1534
-
1535
- test("returns full string for package without version", () => {
1536
- expect(Config.getPluginName("some-plugin")).toBe("some-plugin")
1537
- expect(Config.getPluginName("@scope/pkg")).toBe("@scope/pkg")
1538
- })
1539
- })
1540
-
1541
- describe("deduplicatePlugins", () => {
1542
- test("removes duplicates keeping higher priority (later entries)", () => {
1543
- const plugins = ["global-plugin@1.0.0", "shared-plugin@1.0.0", "local-plugin@2.0.0", "shared-plugin@2.0.0"]
1544
-
1545
- const result = Config.deduplicatePlugins(plugins)
1546
-
1547
- expect(result).toContain("global-plugin@1.0.0")
1548
- expect(result).toContain("local-plugin@2.0.0")
1549
- expect(result).toContain("shared-plugin@2.0.0")
1550
- expect(result).not.toContain("shared-plugin@1.0.0")
1551
- expect(result.length).toBe(3)
1552
- })
1553
-
1554
- test("prefers local file over npm package with same name", () => {
1555
- const plugins = ["oh-my-opencode@2.4.3", "file:///project/.opencode/plugin/oh-my-opencode.js"]
1556
-
1557
- const result = Config.deduplicatePlugins(plugins)
1558
-
1559
- expect(result.length).toBe(1)
1560
- expect(result[0]).toBe("file:///project/.opencode/plugin/oh-my-opencode.js")
1561
- })
1562
-
1563
- test("preserves order of remaining plugins", () => {
1564
- const plugins = ["a-plugin@1.0.0", "b-plugin@1.0.0", "c-plugin@1.0.0"]
1565
-
1566
- const result = Config.deduplicatePlugins(plugins)
1567
-
1568
- expect(result).toEqual(["a-plugin@1.0.0", "b-plugin@1.0.0", "c-plugin@1.0.0"])
1569
- })
1570
-
1571
- test("local plugin directory overrides global opencode.json plugin", async () => {
1572
- await using tmp = await tmpdir({
1573
- init: async (dir) => {
1574
- const projectDir = path.join(dir, "project")
1575
- const opencodeDir = path.join(projectDir, ".opencode")
1576
- const pluginDir = path.join(opencodeDir, "plugin")
1577
- await fs.mkdir(pluginDir, { recursive: true })
1578
-
1579
- await Bun.write(
1580
- path.join(dir, "opencode.json"),
1581
- JSON.stringify({
1582
- $schema: "https://opencode.ai/config.json",
1583
- plugin: ["my-plugin@1.0.0"],
1584
- }),
1585
- )
1586
-
1587
- await Bun.write(path.join(pluginDir, "my-plugin.js"), "export default {}")
1588
- },
1589
- })
1590
-
1591
- await Instance.provide({
1592
- directory: path.join(tmp.path, "project"),
1593
- fn: async () => {
1594
- const config = await Config.get()
1595
- const plugins = config.plugin ?? []
1596
-
1597
- const myPlugins = plugins.filter((p) => Config.getPluginName(p) === "my-plugin")
1598
- expect(myPlugins.length).toBe(1)
1599
- expect(myPlugins[0].startsWith("file://")).toBe(true)
1600
- },
1601
- })
1602
- })
1603
- })
1604
-
1605
- describe("OPENCODE_DISABLE_PROJECT_CONFIG", () => {
1606
- test("skips project config files when flag is set", async () => {
1607
- const originalEnv = process.env["OPENCODE_DISABLE_PROJECT_CONFIG"]
1608
- process.env["OPENCODE_DISABLE_PROJECT_CONFIG"] = "true"
1609
-
1610
- try {
1611
- await using tmp = await tmpdir({
1612
- init: async (dir) => {
1613
- // Create a project config that would normally be loaded
1614
- await Bun.write(
1615
- path.join(dir, "opencode.json"),
1616
- JSON.stringify({
1617
- $schema: "https://opencode.ai/config.json",
1618
- model: "project/model",
1619
- username: "project-user",
1620
- }),
1621
- )
1622
- },
1623
- })
1624
- await Instance.provide({
1625
- directory: tmp.path,
1626
- fn: async () => {
1627
- const config = await Config.get()
1628
- // Project config should NOT be loaded - model should be default, not "project/model"
1629
- expect(config.model).not.toBe("project/model")
1630
- expect(config.username).not.toBe("project-user")
1631
- },
1632
- })
1633
- } finally {
1634
- if (originalEnv === undefined) {
1635
- delete process.env["OPENCODE_DISABLE_PROJECT_CONFIG"]
1636
- } else {
1637
- process.env["OPENCODE_DISABLE_PROJECT_CONFIG"] = originalEnv
1638
- }
1639
- }
1640
- })
1641
-
1642
- test("skips project .opencode/ directories when flag is set", async () => {
1643
- const originalEnv = process.env["OPENCODE_DISABLE_PROJECT_CONFIG"]
1644
- process.env["OPENCODE_DISABLE_PROJECT_CONFIG"] = "true"
1645
-
1646
- try {
1647
- await using tmp = await tmpdir({
1648
- init: async (dir) => {
1649
- // Create a .opencode directory with a command
1650
- const opencodeDir = path.join(dir, ".opencode", "command")
1651
- await fs.mkdir(opencodeDir, { recursive: true })
1652
- await Bun.write(path.join(opencodeDir, "test-cmd.md"), "# Test Command\nThis is a test command.")
1653
- },
1654
- })
1655
- await Instance.provide({
1656
- directory: tmp.path,
1657
- fn: async () => {
1658
- const directories = await Config.directories()
1659
- // Project .opencode should NOT be in directories list
1660
- const hasProjectOpencode = directories.some((d) => d.startsWith(tmp.path))
1661
- expect(hasProjectOpencode).toBe(false)
1662
- },
1663
- })
1664
- } finally {
1665
- if (originalEnv === undefined) {
1666
- delete process.env["OPENCODE_DISABLE_PROJECT_CONFIG"]
1667
- } else {
1668
- process.env["OPENCODE_DISABLE_PROJECT_CONFIG"] = originalEnv
1669
- }
1670
- }
1671
- })
1672
-
1673
- test("still loads global config when flag is set", async () => {
1674
- const originalEnv = process.env["OPENCODE_DISABLE_PROJECT_CONFIG"]
1675
- process.env["OPENCODE_DISABLE_PROJECT_CONFIG"] = "true"
1676
-
1677
- try {
1678
- await using tmp = await tmpdir()
1679
- await Instance.provide({
1680
- directory: tmp.path,
1681
- fn: async () => {
1682
- // Should still get default config (from global or defaults)
1683
- const config = await Config.get()
1684
- expect(config).toBeDefined()
1685
- expect(config.username).toBeDefined()
1686
- },
1687
- })
1688
- } finally {
1689
- if (originalEnv === undefined) {
1690
- delete process.env["OPENCODE_DISABLE_PROJECT_CONFIG"]
1691
- } else {
1692
- process.env["OPENCODE_DISABLE_PROJECT_CONFIG"] = originalEnv
1693
- }
1694
- }
1695
- })
1696
-
1697
- test("skips relative instructions with warning when flag is set but no config dir", async () => {
1698
- const originalDisable = process.env["OPENCODE_DISABLE_PROJECT_CONFIG"]
1699
- const originalConfigDir = process.env["OPENCODE_CONFIG_DIR"]
1700
-
1701
- try {
1702
- // Ensure no config dir is set
1703
- delete process.env["OPENCODE_CONFIG_DIR"]
1704
- process.env["OPENCODE_DISABLE_PROJECT_CONFIG"] = "true"
1705
-
1706
- await using tmp = await tmpdir({
1707
- init: async (dir) => {
1708
- // Create a config with relative instruction path
1709
- await Bun.write(
1710
- path.join(dir, "opencode.json"),
1711
- JSON.stringify({
1712
- $schema: "https://opencode.ai/config.json",
1713
- instructions: ["./CUSTOM.md"],
1714
- }),
1715
- )
1716
- // Create the instruction file (should be skipped)
1717
- await Bun.write(path.join(dir, "CUSTOM.md"), "# Custom Instructions")
1718
- },
1719
- })
1720
-
1721
- await Instance.provide({
1722
- directory: tmp.path,
1723
- fn: async () => {
1724
- // The relative instruction should be skipped without error
1725
- // We're mainly verifying this doesn't throw and the config loads
1726
- const config = await Config.get()
1727
- expect(config).toBeDefined()
1728
- // The instruction should have been skipped (warning logged)
1729
- // We can't easily test the warning was logged, but we verify
1730
- // the relative path didn't cause an error
1731
- },
1732
- })
1733
- } finally {
1734
- if (originalDisable === undefined) {
1735
- delete process.env["OPENCODE_DISABLE_PROJECT_CONFIG"]
1736
- } else {
1737
- process.env["OPENCODE_DISABLE_PROJECT_CONFIG"] = originalDisable
1738
- }
1739
- if (originalConfigDir === undefined) {
1740
- delete process.env["OPENCODE_CONFIG_DIR"]
1741
- } else {
1742
- process.env["OPENCODE_CONFIG_DIR"] = originalConfigDir
1743
- }
1744
- }
1745
- })
1746
-
1747
- test("OPENCODE_CONFIG_DIR still works when flag is set", async () => {
1748
- const originalDisable = process.env["OPENCODE_DISABLE_PROJECT_CONFIG"]
1749
- const originalConfigDir = process.env["OPENCODE_CONFIG_DIR"]
1750
-
1751
- try {
1752
- await using configDirTmp = await tmpdir({
1753
- init: async (dir) => {
1754
- // Create config in the custom config dir
1755
- await Bun.write(
1756
- path.join(dir, "opencode.json"),
1757
- JSON.stringify({
1758
- $schema: "https://opencode.ai/config.json",
1759
- model: "configdir/model",
1760
- }),
1761
- )
1762
- },
1763
- })
1764
-
1765
- await using projectTmp = await tmpdir({
1766
- init: async (dir) => {
1767
- // Create config in project (should be ignored)
1768
- await Bun.write(
1769
- path.join(dir, "opencode.json"),
1770
- JSON.stringify({
1771
- $schema: "https://opencode.ai/config.json",
1772
- model: "project/model",
1773
- }),
1774
- )
1775
- },
1776
- })
1777
-
1778
- process.env["OPENCODE_DISABLE_PROJECT_CONFIG"] = "true"
1779
- process.env["OPENCODE_CONFIG_DIR"] = configDirTmp.path
1780
-
1781
- await Instance.provide({
1782
- directory: projectTmp.path,
1783
- fn: async () => {
1784
- const config = await Config.get()
1785
- // Should load from OPENCODE_CONFIG_DIR, not project
1786
- expect(config.model).toBe("configdir/model")
1787
- },
1788
- })
1789
- } finally {
1790
- if (originalDisable === undefined) {
1791
- delete process.env["OPENCODE_DISABLE_PROJECT_CONFIG"]
1792
- } else {
1793
- process.env["OPENCODE_DISABLE_PROJECT_CONFIG"] = originalDisable
1794
- }
1795
- if (originalConfigDir === undefined) {
1796
- delete process.env["OPENCODE_CONFIG_DIR"]
1797
- } else {
1798
- process.env["OPENCODE_CONFIG_DIR"] = originalConfigDir
1799
- }
1800
- }
1801
- })
1802
- })