easc-cli 1.1.28

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 (404) hide show
  1. package/AGENTS.md +27 -0
  2. package/Dockerfile +18 -0
  3. package/README.md +15 -0
  4. package/bin/opencode +108 -0
  5. package/bunfig.toml +7 -0
  6. package/package.json +132 -0
  7. package/parsers-config.ts +253 -0
  8. package/script/build.ts +172 -0
  9. package/script/deploy.ts +64 -0
  10. package/script/postinstall.mjs +125 -0
  11. package/script/publish-registries.ts +187 -0
  12. package/script/publish.ts +70 -0
  13. package/script/schema.ts +47 -0
  14. package/script/seed-e2e.ts +50 -0
  15. package/src/acp/README.md +164 -0
  16. package/src/acp/agent.ts +1285 -0
  17. package/src/acp/session.ts +105 -0
  18. package/src/acp/types.ts +22 -0
  19. package/src/agent/agent.ts +332 -0
  20. package/src/agent/generate.txt +75 -0
  21. package/src/agent/prompt/compaction.txt +12 -0
  22. package/src/agent/prompt/explore.txt +18 -0
  23. package/src/agent/prompt/summary.txt +11 -0
  24. package/src/agent/prompt/title.txt +43 -0
  25. package/src/auth/eliseart.ts +76 -0
  26. package/src/auth/index.ts +73 -0
  27. package/src/bun/index.ts +134 -0
  28. package/src/bus/bus-event.ts +43 -0
  29. package/src/bus/global.ts +10 -0
  30. package/src/bus/index.ts +105 -0
  31. package/src/cli/bootstrap.ts +17 -0
  32. package/src/cli/cmd/account.ts +81 -0
  33. package/src/cli/cmd/acp.ts +69 -0
  34. package/src/cli/cmd/agent.ts +257 -0
  35. package/src/cli/cmd/auth.ts +427 -0
  36. package/src/cli/cmd/cmd.ts +7 -0
  37. package/src/cli/cmd/debug/agent.ts +166 -0
  38. package/src/cli/cmd/debug/config.ts +16 -0
  39. package/src/cli/cmd/debug/file.ts +97 -0
  40. package/src/cli/cmd/debug/index.ts +48 -0
  41. package/src/cli/cmd/debug/lsp.ts +52 -0
  42. package/src/cli/cmd/debug/ripgrep.ts +87 -0
  43. package/src/cli/cmd/debug/scrap.ts +16 -0
  44. package/src/cli/cmd/debug/skill.ts +16 -0
  45. package/src/cli/cmd/debug/snapshot.ts +52 -0
  46. package/src/cli/cmd/export.ts +88 -0
  47. package/src/cli/cmd/generate.ts +38 -0
  48. package/src/cli/cmd/github.ts +1548 -0
  49. package/src/cli/cmd/import.ts +98 -0
  50. package/src/cli/cmd/mcp.ts +827 -0
  51. package/src/cli/cmd/models.ts +77 -0
  52. package/src/cli/cmd/pr.ts +112 -0
  53. package/src/cli/cmd/run.ts +407 -0
  54. package/src/cli/cmd/serve.ts +20 -0
  55. package/src/cli/cmd/session.ts +135 -0
  56. package/src/cli/cmd/stats.ts +402 -0
  57. package/src/cli/cmd/tui/app.tsx +774 -0
  58. package/src/cli/cmd/tui/attach.ts +31 -0
  59. package/src/cli/cmd/tui/component/border.tsx +21 -0
  60. package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  61. package/src/cli/cmd/tui/component/dialog-command.tsx +148 -0
  62. package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  63. package/src/cli/cmd/tui/component/dialog-model.tsx +234 -0
  64. package/src/cli/cmd/tui/component/dialog-provider.tsx +256 -0
  65. package/src/cli/cmd/tui/component/dialog-session-list.tsx +114 -0
  66. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  67. package/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
  68. package/src/cli/cmd/tui/component/dialog-status.tsx +164 -0
  69. package/src/cli/cmd/tui/component/dialog-supabase.tsx +102 -0
  70. package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  71. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  72. package/src/cli/cmd/tui/component/logo.tsx +88 -0
  73. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +653 -0
  74. package/src/cli/cmd/tui/component/prompt/frecency.tsx +89 -0
  75. package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
  76. package/src/cli/cmd/tui/component/prompt/index.tsx +1182 -0
  77. package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
  78. package/src/cli/cmd/tui/component/spinner.tsx +16 -0
  79. package/src/cli/cmd/tui/component/textarea-keybindings.ts +73 -0
  80. package/src/cli/cmd/tui/component/tips.tsx +153 -0
  81. package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
  82. package/src/cli/cmd/tui/context/args.tsx +14 -0
  83. package/src/cli/cmd/tui/context/directory.ts +13 -0
  84. package/src/cli/cmd/tui/context/exit.tsx +23 -0
  85. package/src/cli/cmd/tui/context/helper.tsx +25 -0
  86. package/src/cli/cmd/tui/context/keybind.tsx +101 -0
  87. package/src/cli/cmd/tui/context/kv.tsx +52 -0
  88. package/src/cli/cmd/tui/context/local.tsx +402 -0
  89. package/src/cli/cmd/tui/context/prompt.tsx +18 -0
  90. package/src/cli/cmd/tui/context/route.tsx +46 -0
  91. package/src/cli/cmd/tui/context/sdk.tsx +94 -0
  92. package/src/cli/cmd/tui/context/sync.tsx +445 -0
  93. package/src/cli/cmd/tui/context/theme/aura.json +69 -0
  94. package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  95. package/src/cli/cmd/tui/context/theme/carbonfox.json +248 -0
  96. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
  97. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  98. package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  99. package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  100. package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
  101. package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  102. package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  103. package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  104. package/src/cli/cmd/tui/context/theme/github.json +233 -0
  105. package/src/cli/cmd/tui/context/theme/gruvbox.json +95 -0
  106. package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  107. package/src/cli/cmd/tui/context/theme/lucent-orng.json +237 -0
  108. package/src/cli/cmd/tui/context/theme/material.json +235 -0
  109. package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  110. package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  111. package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  112. package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  113. package/src/cli/cmd/tui/context/theme/nord.json +223 -0
  114. package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  115. package/src/cli/cmd/tui/context/theme/orng.json +249 -0
  116. package/src/cli/cmd/tui/context/theme/osaka-jade.json +93 -0
  117. package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  118. package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  119. package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  120. package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  121. package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  122. package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  123. package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  124. package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  125. package/src/cli/cmd/tui/context/theme.tsx +1152 -0
  126. package/src/cli/cmd/tui/event.ts +48 -0
  127. package/src/cli/cmd/tui/routes/home.tsx +140 -0
  128. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
  129. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
  130. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
  131. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
  132. package/src/cli/cmd/tui/routes/session/dialog-tool.tsx +63 -0
  133. package/src/cli/cmd/tui/routes/session/footer.tsx +129 -0
  134. package/src/cli/cmd/tui/routes/session/header.tsx +136 -0
  135. package/src/cli/cmd/tui/routes/session/index.tsx +2132 -0
  136. package/src/cli/cmd/tui/routes/session/permission.tsx +495 -0
  137. package/src/cli/cmd/tui/routes/session/question.tsx +435 -0
  138. package/src/cli/cmd/tui/routes/session/sidebar.tsx +313 -0
  139. package/src/cli/cmd/tui/thread.ts +165 -0
  140. package/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -0
  141. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
  142. package/src/cli/cmd/tui/ui/dialog-export-options.tsx +204 -0
  143. package/src/cli/cmd/tui/ui/dialog-help.tsx +38 -0
  144. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
  145. package/src/cli/cmd/tui/ui/dialog-select.tsx +376 -0
  146. package/src/cli/cmd/tui/ui/dialog.tsx +167 -0
  147. package/src/cli/cmd/tui/ui/link.tsx +28 -0
  148. package/src/cli/cmd/tui/ui/spinner.ts +368 -0
  149. package/src/cli/cmd/tui/ui/toast.tsx +100 -0
  150. package/src/cli/cmd/tui/util/clipboard.ts +160 -0
  151. package/src/cli/cmd/tui/util/editor.ts +32 -0
  152. package/src/cli/cmd/tui/util/signal.ts +7 -0
  153. package/src/cli/cmd/tui/util/terminal.ts +114 -0
  154. package/src/cli/cmd/tui/util/transcript.ts +98 -0
  155. package/src/cli/cmd/tui/worker.ts +152 -0
  156. package/src/cli/cmd/uninstall.ts +357 -0
  157. package/src/cli/cmd/upgrade.ts +73 -0
  158. package/src/cli/cmd/web.ts +81 -0
  159. package/src/cli/error.ts +57 -0
  160. package/src/cli/network.ts +53 -0
  161. package/src/cli/ui.ts +84 -0
  162. package/src/cli/upgrade.ts +25 -0
  163. package/src/command/index.ts +131 -0
  164. package/src/command/template/initialize.txt +10 -0
  165. package/src/command/template/review.txt +99 -0
  166. package/src/config/config.ts +1361 -0
  167. package/src/config/markdown.ts +93 -0
  168. package/src/env/index.ts +26 -0
  169. package/src/file/ignore.ts +83 -0
  170. package/src/file/index.ts +411 -0
  171. package/src/file/ripgrep.ts +407 -0
  172. package/src/file/time.ts +64 -0
  173. package/src/file/watcher.ts +127 -0
  174. package/src/flag/flag.ts +54 -0
  175. package/src/format/formatter.ts +342 -0
  176. package/src/format/index.ts +137 -0
  177. package/src/global/index.ts +55 -0
  178. package/src/id/id.ts +83 -0
  179. package/src/ide/index.ts +76 -0
  180. package/src/index.ts +162 -0
  181. package/src/installation/index.ts +246 -0
  182. package/src/lsp/client.ts +252 -0
  183. package/src/lsp/index.ts +485 -0
  184. package/src/lsp/language.ts +119 -0
  185. package/src/lsp/server.ts +2046 -0
  186. package/src/mcp/auth.ts +135 -0
  187. package/src/mcp/index.ts +931 -0
  188. package/src/mcp/oauth-callback.ts +200 -0
  189. package/src/mcp/oauth-provider.ts +154 -0
  190. package/src/patch/index.ts +680 -0
  191. package/src/permission/arity.ts +163 -0
  192. package/src/permission/index.ts +210 -0
  193. package/src/permission/next.ts +269 -0
  194. package/src/plugin/codex.ts +493 -0
  195. package/src/plugin/copilot.ts +269 -0
  196. package/src/plugin/index.ts +135 -0
  197. package/src/project/bootstrap.ts +35 -0
  198. package/src/project/instance.ts +91 -0
  199. package/src/project/project.ts +339 -0
  200. package/src/project/state.ts +66 -0
  201. package/src/project/vcs.ts +76 -0
  202. package/src/provider/auth.ts +147 -0
  203. package/src/provider/models-macro.ts +11 -0
  204. package/src/provider/models.ts +112 -0
  205. package/src/provider/provider.ts +1391 -0
  206. package/src/provider/sdk/openai-compatible/src/README.md +5 -0
  207. package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
  208. package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +100 -0
  209. package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
  210. package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
  211. package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
  212. package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
  213. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
  214. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1732 -0
  215. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
  216. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
  217. package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
  218. package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
  219. package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
  220. package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
  221. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
  222. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
  223. package/src/provider/transform.ts +733 -0
  224. package/src/pty/index.ts +232 -0
  225. package/src/question/index.ts +171 -0
  226. package/src/scheduler/index.ts +61 -0
  227. package/src/server/error.ts +36 -0
  228. package/src/server/event.ts +7 -0
  229. package/src/server/mdns.ts +59 -0
  230. package/src/server/routes/config.ts +92 -0
  231. package/src/server/routes/experimental.ts +208 -0
  232. package/src/server/routes/file.ts +197 -0
  233. package/src/server/routes/global.ts +135 -0
  234. package/src/server/routes/mcp.ts +361 -0
  235. package/src/server/routes/permission.ts +68 -0
  236. package/src/server/routes/project.ts +82 -0
  237. package/src/server/routes/provider.ts +165 -0
  238. package/src/server/routes/pty.ts +169 -0
  239. package/src/server/routes/question.ts +98 -0
  240. package/src/server/routes/session.ts +935 -0
  241. package/src/server/routes/tui.ts +379 -0
  242. package/src/server/server.ts +573 -0
  243. package/src/session/compaction.ts +225 -0
  244. package/src/session/index.ts +488 -0
  245. package/src/session/llm.ts +279 -0
  246. package/src/session/message-v2.ts +702 -0
  247. package/src/session/message.ts +189 -0
  248. package/src/session/processor.ts +406 -0
  249. package/src/session/prompt/anthropic-20250930.txt +166 -0
  250. package/src/session/prompt/anthropic.txt +105 -0
  251. package/src/session/prompt/anthropic_spoof.txt +1 -0
  252. package/src/session/prompt/beast.txt +147 -0
  253. package/src/session/prompt/build-switch.txt +5 -0
  254. package/src/session/prompt/codex_header.txt +79 -0
  255. package/src/session/prompt/copilot-gpt-5.txt +143 -0
  256. package/src/session/prompt/gemini.txt +155 -0
  257. package/src/session/prompt/max-steps.txt +16 -0
  258. package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
  259. package/src/session/prompt/plan.txt +26 -0
  260. package/src/session/prompt/qwen.txt +109 -0
  261. package/src/session/prompt.ts +1820 -0
  262. package/src/session/retry.ts +90 -0
  263. package/src/session/revert.ts +108 -0
  264. package/src/session/status.ts +76 -0
  265. package/src/session/summary.ts +150 -0
  266. package/src/session/system.ts +152 -0
  267. package/src/session/todo.ts +37 -0
  268. package/src/share/share-next.ts +200 -0
  269. package/src/share/share.ts +92 -0
  270. package/src/shell/shell.ts +67 -0
  271. package/src/skill/index.ts +1 -0
  272. package/src/skill/skill.ts +136 -0
  273. package/src/snapshot/index.ts +236 -0
  274. package/src/storage/storage.ts +227 -0
  275. package/src/tool/apply_patch.ts +269 -0
  276. package/src/tool/apply_patch.txt +33 -0
  277. package/src/tool/bash.ts +259 -0
  278. package/src/tool/bash.txt +115 -0
  279. package/src/tool/batch.ts +175 -0
  280. package/src/tool/batch.txt +24 -0
  281. package/src/tool/codesearch.ts +132 -0
  282. package/src/tool/codesearch.txt +12 -0
  283. package/src/tool/edit.ts +645 -0
  284. package/src/tool/edit.txt +10 -0
  285. package/src/tool/external-directory.ts +32 -0
  286. package/src/tool/glob.ts +77 -0
  287. package/src/tool/glob.txt +6 -0
  288. package/src/tool/grep.ts +154 -0
  289. package/src/tool/grep.txt +8 -0
  290. package/src/tool/invalid.ts +17 -0
  291. package/src/tool/ls.ts +121 -0
  292. package/src/tool/ls.txt +1 -0
  293. package/src/tool/lsp.ts +96 -0
  294. package/src/tool/lsp.txt +19 -0
  295. package/src/tool/multiedit.ts +46 -0
  296. package/src/tool/multiedit.txt +41 -0
  297. package/src/tool/plan-enter.txt +14 -0
  298. package/src/tool/plan-exit.txt +13 -0
  299. package/src/tool/plan.ts +130 -0
  300. package/src/tool/question.ts +33 -0
  301. package/src/tool/question.txt +10 -0
  302. package/src/tool/read.ts +202 -0
  303. package/src/tool/read.txt +12 -0
  304. package/src/tool/registry.ts +163 -0
  305. package/src/tool/skill.ts +75 -0
  306. package/src/tool/task.ts +188 -0
  307. package/src/tool/task.txt +60 -0
  308. package/src/tool/todo.ts +53 -0
  309. package/src/tool/todoread.txt +14 -0
  310. package/src/tool/todowrite.txt +167 -0
  311. package/src/tool/tool.ts +88 -0
  312. package/src/tool/truncation.ts +106 -0
  313. package/src/tool/webfetch.ts +182 -0
  314. package/src/tool/webfetch.txt +13 -0
  315. package/src/tool/websearch.ts +150 -0
  316. package/src/tool/websearch.txt +14 -0
  317. package/src/tool/write.ts +80 -0
  318. package/src/tool/write.txt +8 -0
  319. package/src/util/archive.ts +16 -0
  320. package/src/util/color.ts +19 -0
  321. package/src/util/context.ts +25 -0
  322. package/src/util/defer.ts +12 -0
  323. package/src/util/eventloop.ts +20 -0
  324. package/src/util/filesystem.ts +93 -0
  325. package/src/util/fn.ts +11 -0
  326. package/src/util/format.ts +20 -0
  327. package/src/util/iife.ts +3 -0
  328. package/src/util/keybind.ts +103 -0
  329. package/src/util/lazy.ts +18 -0
  330. package/src/util/locale.ts +81 -0
  331. package/src/util/lock.ts +98 -0
  332. package/src/util/log.ts +180 -0
  333. package/src/util/queue.ts +32 -0
  334. package/src/util/rpc.ts +66 -0
  335. package/src/util/scrap.ts +10 -0
  336. package/src/util/signal.ts +12 -0
  337. package/src/util/timeout.ts +14 -0
  338. package/src/util/token.ts +7 -0
  339. package/src/util/wildcard.ts +56 -0
  340. package/src/worktree/index.ts +424 -0
  341. package/sst-env.d.ts +9 -0
  342. package/test/acp/event-subscription.test.ts +436 -0
  343. package/test/agent/agent.test.ts +638 -0
  344. package/test/bun.test.ts +53 -0
  345. package/test/cli/github-action.test.ts +129 -0
  346. package/test/cli/github-remote.test.ts +80 -0
  347. package/test/cli/tui/transcript.test.ts +297 -0
  348. package/test/config/agent-color.test.ts +66 -0
  349. package/test/config/config.test.ts +1414 -0
  350. package/test/config/fixtures/empty-frontmatter.md +4 -0
  351. package/test/config/fixtures/frontmatter.md +28 -0
  352. package/test/config/fixtures/no-frontmatter.md +1 -0
  353. package/test/config/markdown.test.ts +192 -0
  354. package/test/file/ignore.test.ts +10 -0
  355. package/test/file/path-traversal.test.ts +198 -0
  356. package/test/fixture/fixture.ts +45 -0
  357. package/test/fixture/lsp/fake-lsp-server.js +77 -0
  358. package/test/ide/ide.test.ts +82 -0
  359. package/test/keybind.test.ts +421 -0
  360. package/test/lsp/client.test.ts +95 -0
  361. package/test/mcp/headers.test.ts +153 -0
  362. package/test/mcp/oauth-browser.test.ts +261 -0
  363. package/test/patch/patch.test.ts +348 -0
  364. package/test/permission/arity.test.ts +33 -0
  365. package/test/permission/next.test.ts +652 -0
  366. package/test/permission-task.test.ts +319 -0
  367. package/test/plugin/codex.test.ts +123 -0
  368. package/test/preload.ts +65 -0
  369. package/test/project/project.test.ts +120 -0
  370. package/test/provider/amazon-bedrock.test.ts +268 -0
  371. package/test/provider/gitlab-duo.test.ts +286 -0
  372. package/test/provider/provider.test.ts +2149 -0
  373. package/test/provider/transform.test.ts +1596 -0
  374. package/test/question/question.test.ts +300 -0
  375. package/test/scheduler.test.ts +73 -0
  376. package/test/server/session-list.test.ts +39 -0
  377. package/test/server/session-select.test.ts +78 -0
  378. package/test/session/compaction.test.ts +293 -0
  379. package/test/session/llm.test.ts +90 -0
  380. package/test/session/message-v2.test.ts +662 -0
  381. package/test/session/retry.test.ts +131 -0
  382. package/test/session/revert-compact.test.ts +285 -0
  383. package/test/session/session.test.ts +71 -0
  384. package/test/skill/skill.test.ts +185 -0
  385. package/test/snapshot/snapshot.test.ts +939 -0
  386. package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
  387. package/test/tool/apply_patch.test.ts +499 -0
  388. package/test/tool/bash.test.ts +320 -0
  389. package/test/tool/external-directory.test.ts +126 -0
  390. package/test/tool/fixtures/large-image.png +0 -0
  391. package/test/tool/fixtures/models-api.json +33453 -0
  392. package/test/tool/grep.test.ts +109 -0
  393. package/test/tool/question.test.ts +105 -0
  394. package/test/tool/read.test.ts +332 -0
  395. package/test/tool/registry.test.ts +76 -0
  396. package/test/tool/truncation.test.ts +159 -0
  397. package/test/util/filesystem.test.ts +39 -0
  398. package/test/util/format.test.ts +59 -0
  399. package/test/util/iife.test.ts +36 -0
  400. package/test/util/lazy.test.ts +50 -0
  401. package/test/util/lock.test.ts +72 -0
  402. package/test/util/timeout.test.ts +21 -0
  403. package/test/util/wildcard.test.ts +75 -0
  404. package/tsconfig.json +16 -0
@@ -0,0 +1,1414 @@
1
+ import { test, expect, describe, mock } 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
+
10
+ test("loads config with defaults when no files exist", async () => {
11
+ await using tmp = await tmpdir()
12
+ await Instance.provide({
13
+ directory: tmp.path,
14
+ fn: async () => {
15
+ const config = await Config.get()
16
+ expect(config.username).toBeDefined()
17
+ },
18
+ })
19
+ })
20
+
21
+ test("loads JSON config file", async () => {
22
+ await using tmp = await tmpdir({
23
+ init: async (dir) => {
24
+ await Bun.write(
25
+ path.join(dir, "opencode.json"),
26
+ JSON.stringify({
27
+ $schema: "https://opencode.ai/config.json",
28
+ model: "test/model",
29
+ username: "testuser",
30
+ }),
31
+ )
32
+ },
33
+ })
34
+ await Instance.provide({
35
+ directory: tmp.path,
36
+ fn: async () => {
37
+ const config = await Config.get()
38
+ expect(config.model).toBe("test/model")
39
+ expect(config.username).toBe("testuser")
40
+ },
41
+ })
42
+ })
43
+
44
+ test("loads JSONC config file", async () => {
45
+ await using tmp = await tmpdir({
46
+ init: async (dir) => {
47
+ await Bun.write(
48
+ path.join(dir, "opencode.jsonc"),
49
+ `{
50
+ // This is a comment
51
+ "$schema": "https://opencode.ai/config.json",
52
+ "model": "test/model",
53
+ "username": "testuser"
54
+ }`,
55
+ )
56
+ },
57
+ })
58
+ await Instance.provide({
59
+ directory: tmp.path,
60
+ fn: async () => {
61
+ const config = await Config.get()
62
+ expect(config.model).toBe("test/model")
63
+ expect(config.username).toBe("testuser")
64
+ },
65
+ })
66
+ })
67
+
68
+ test("merges multiple config files with correct precedence", async () => {
69
+ await using tmp = await tmpdir({
70
+ init: async (dir) => {
71
+ await Bun.write(
72
+ path.join(dir, "opencode.jsonc"),
73
+ JSON.stringify({
74
+ $schema: "https://opencode.ai/config.json",
75
+ model: "base",
76
+ username: "base",
77
+ }),
78
+ )
79
+ await Bun.write(
80
+ path.join(dir, "opencode.json"),
81
+ JSON.stringify({
82
+ $schema: "https://opencode.ai/config.json",
83
+ model: "override",
84
+ }),
85
+ )
86
+ },
87
+ })
88
+ await Instance.provide({
89
+ directory: tmp.path,
90
+ fn: async () => {
91
+ const config = await Config.get()
92
+ expect(config.model).toBe("override")
93
+ expect(config.username).toBe("base")
94
+ },
95
+ })
96
+ })
97
+
98
+ test("handles environment variable substitution", async () => {
99
+ const originalEnv = process.env["TEST_VAR"]
100
+ process.env["TEST_VAR"] = "test_theme"
101
+
102
+ try {
103
+ await using tmp = await tmpdir({
104
+ init: async (dir) => {
105
+ await Bun.write(
106
+ path.join(dir, "opencode.json"),
107
+ JSON.stringify({
108
+ $schema: "https://opencode.ai/config.json",
109
+ theme: "{env:TEST_VAR}",
110
+ }),
111
+ )
112
+ },
113
+ })
114
+ await Instance.provide({
115
+ directory: tmp.path,
116
+ fn: async () => {
117
+ const config = await Config.get()
118
+ expect(config.theme).toBe("test_theme")
119
+ },
120
+ })
121
+ } finally {
122
+ if (originalEnv !== undefined) {
123
+ process.env["TEST_VAR"] = originalEnv
124
+ } else {
125
+ delete process.env["TEST_VAR"]
126
+ }
127
+ }
128
+ })
129
+
130
+ test("preserves env variables when adding $schema to config", async () => {
131
+ const originalEnv = process.env["PRESERVE_VAR"]
132
+ process.env["PRESERVE_VAR"] = "secret_value"
133
+
134
+ try {
135
+ await using tmp = await tmpdir({
136
+ init: async (dir) => {
137
+ // Config without $schema - should trigger auto-add
138
+ await Bun.write(
139
+ path.join(dir, "opencode.json"),
140
+ JSON.stringify({
141
+ theme: "{env:PRESERVE_VAR}",
142
+ }),
143
+ )
144
+ },
145
+ })
146
+ await Instance.provide({
147
+ directory: tmp.path,
148
+ fn: async () => {
149
+ const config = await Config.get()
150
+ expect(config.theme).toBe("secret_value")
151
+
152
+ // Read the file to verify the env variable was preserved
153
+ const content = await Bun.file(path.join(tmp.path, "opencode.json")).text()
154
+ expect(content).toContain("{env:PRESERVE_VAR}")
155
+ expect(content).not.toContain("secret_value")
156
+ expect(content).toContain("$schema")
157
+ },
158
+ })
159
+ } finally {
160
+ if (originalEnv !== undefined) {
161
+ process.env["PRESERVE_VAR"] = originalEnv
162
+ } else {
163
+ delete process.env["PRESERVE_VAR"]
164
+ }
165
+ }
166
+ })
167
+
168
+ test("handles file inclusion substitution", async () => {
169
+ await using tmp = await tmpdir({
170
+ init: async (dir) => {
171
+ await Bun.write(path.join(dir, "included.txt"), "test_theme")
172
+ await Bun.write(
173
+ path.join(dir, "opencode.json"),
174
+ JSON.stringify({
175
+ $schema: "https://opencode.ai/config.json",
176
+ theme: "{file:included.txt}",
177
+ }),
178
+ )
179
+ },
180
+ })
181
+ await Instance.provide({
182
+ directory: tmp.path,
183
+ fn: async () => {
184
+ const config = await Config.get()
185
+ expect(config.theme).toBe("test_theme")
186
+ },
187
+ })
188
+ })
189
+
190
+ test("validates config schema and throws on invalid fields", async () => {
191
+ await using tmp = await tmpdir({
192
+ init: async (dir) => {
193
+ await Bun.write(
194
+ path.join(dir, "opencode.json"),
195
+ JSON.stringify({
196
+ $schema: "https://opencode.ai/config.json",
197
+ invalid_field: "should cause error",
198
+ }),
199
+ )
200
+ },
201
+ })
202
+ await Instance.provide({
203
+ directory: tmp.path,
204
+ fn: async () => {
205
+ // Strict schema should throw an error for invalid fields
206
+ await expect(Config.get()).rejects.toThrow()
207
+ },
208
+ })
209
+ })
210
+
211
+ test("throws error for invalid JSON", async () => {
212
+ await using tmp = await tmpdir({
213
+ init: async (dir) => {
214
+ await Bun.write(path.join(dir, "opencode.json"), "{ invalid json }")
215
+ },
216
+ })
217
+ await Instance.provide({
218
+ directory: tmp.path,
219
+ fn: async () => {
220
+ await expect(Config.get()).rejects.toThrow()
221
+ },
222
+ })
223
+ })
224
+
225
+ test("handles agent configuration", async () => {
226
+ await using tmp = await tmpdir({
227
+ init: async (dir) => {
228
+ await Bun.write(
229
+ path.join(dir, "opencode.json"),
230
+ JSON.stringify({
231
+ $schema: "https://opencode.ai/config.json",
232
+ agent: {
233
+ test_agent: {
234
+ model: "test/model",
235
+ temperature: 0.7,
236
+ description: "test agent",
237
+ },
238
+ },
239
+ }),
240
+ )
241
+ },
242
+ })
243
+ await Instance.provide({
244
+ directory: tmp.path,
245
+ fn: async () => {
246
+ const config = await Config.get()
247
+ expect(config.agent?.["test_agent"]).toEqual(
248
+ expect.objectContaining({
249
+ model: "test/model",
250
+ temperature: 0.7,
251
+ description: "test agent",
252
+ }),
253
+ )
254
+ },
255
+ })
256
+ })
257
+
258
+ test("handles command configuration", async () => {
259
+ await using tmp = await tmpdir({
260
+ init: async (dir) => {
261
+ await Bun.write(
262
+ path.join(dir, "opencode.json"),
263
+ JSON.stringify({
264
+ $schema: "https://opencode.ai/config.json",
265
+ command: {
266
+ test_command: {
267
+ template: "test template",
268
+ description: "test command",
269
+ agent: "test_agent",
270
+ },
271
+ },
272
+ }),
273
+ )
274
+ },
275
+ })
276
+ await Instance.provide({
277
+ directory: tmp.path,
278
+ fn: async () => {
279
+ const config = await Config.get()
280
+ expect(config.command?.["test_command"]).toEqual({
281
+ template: "test template",
282
+ description: "test command",
283
+ agent: "test_agent",
284
+ })
285
+ },
286
+ })
287
+ })
288
+
289
+ test("migrates autoshare to share field", async () => {
290
+ await using tmp = await tmpdir({
291
+ init: async (dir) => {
292
+ await Bun.write(
293
+ path.join(dir, "opencode.json"),
294
+ JSON.stringify({
295
+ $schema: "https://opencode.ai/config.json",
296
+ autoshare: true,
297
+ }),
298
+ )
299
+ },
300
+ })
301
+ await Instance.provide({
302
+ directory: tmp.path,
303
+ fn: async () => {
304
+ const config = await Config.get()
305
+ expect(config.share).toBe("auto")
306
+ expect(config.autoshare).toBe(true)
307
+ },
308
+ })
309
+ })
310
+
311
+ test("migrates mode field to agent field", async () => {
312
+ await using tmp = await tmpdir({
313
+ init: async (dir) => {
314
+ await Bun.write(
315
+ path.join(dir, "opencode.json"),
316
+ JSON.stringify({
317
+ $schema: "https://opencode.ai/config.json",
318
+ mode: {
319
+ test_mode: {
320
+ model: "test/model",
321
+ temperature: 0.5,
322
+ },
323
+ },
324
+ }),
325
+ )
326
+ },
327
+ })
328
+ await Instance.provide({
329
+ directory: tmp.path,
330
+ fn: async () => {
331
+ const config = await Config.get()
332
+ expect(config.agent?.["test_mode"]).toEqual({
333
+ model: "test/model",
334
+ temperature: 0.5,
335
+ mode: "primary",
336
+ options: {},
337
+ permission: {},
338
+ })
339
+ },
340
+ })
341
+ })
342
+
343
+ test("loads config from .opencode directory", async () => {
344
+ await using tmp = await tmpdir({
345
+ init: async (dir) => {
346
+ const opencodeDir = path.join(dir, ".opencode")
347
+ await fs.mkdir(opencodeDir, { recursive: true })
348
+ const agentDir = path.join(opencodeDir, "agent")
349
+ await fs.mkdir(agentDir, { recursive: true })
350
+
351
+ await Bun.write(
352
+ path.join(agentDir, "test.md"),
353
+ `---
354
+ model: test/model
355
+ ---
356
+ Test agent prompt`,
357
+ )
358
+ },
359
+ })
360
+ await Instance.provide({
361
+ directory: tmp.path,
362
+ fn: async () => {
363
+ const config = await Config.get()
364
+ expect(config.agent?.["test"]).toEqual(
365
+ expect.objectContaining({
366
+ name: "test",
367
+ model: "test/model",
368
+ prompt: "Test agent prompt",
369
+ }),
370
+ )
371
+ },
372
+ })
373
+ })
374
+
375
+ test("loads agents from .opencode/agents (plural)", async () => {
376
+ await using tmp = await tmpdir({
377
+ init: async (dir) => {
378
+ const opencodeDir = path.join(dir, ".opencode")
379
+ await fs.mkdir(opencodeDir, { recursive: true })
380
+
381
+ const agentsDir = path.join(opencodeDir, "agents")
382
+ await fs.mkdir(path.join(agentsDir, "nested"), { recursive: true })
383
+
384
+ await Bun.write(
385
+ path.join(agentsDir, "helper.md"),
386
+ `---
387
+ model: test/model
388
+ mode: subagent
389
+ ---
390
+ Helper agent prompt`,
391
+ )
392
+
393
+ await Bun.write(
394
+ path.join(agentsDir, "nested", "child.md"),
395
+ `---
396
+ model: test/model
397
+ mode: subagent
398
+ ---
399
+ Nested agent prompt`,
400
+ )
401
+ },
402
+ })
403
+
404
+ await Instance.provide({
405
+ directory: tmp.path,
406
+ fn: async () => {
407
+ const config = await Config.get()
408
+
409
+ expect(config.agent?.["helper"]).toMatchObject({
410
+ name: "helper",
411
+ model: "test/model",
412
+ mode: "subagent",
413
+ prompt: "Helper agent prompt",
414
+ })
415
+
416
+ expect(config.agent?.["nested/child"]).toMatchObject({
417
+ name: "nested/child",
418
+ model: "test/model",
419
+ mode: "subagent",
420
+ prompt: "Nested agent prompt",
421
+ })
422
+ },
423
+ })
424
+ })
425
+
426
+ test("loads commands from .opencode/command (singular)", async () => {
427
+ await using tmp = await tmpdir({
428
+ init: async (dir) => {
429
+ const opencodeDir = path.join(dir, ".opencode")
430
+ await fs.mkdir(opencodeDir, { recursive: true })
431
+
432
+ const commandDir = path.join(opencodeDir, "command")
433
+ await fs.mkdir(path.join(commandDir, "nested"), { recursive: true })
434
+
435
+ await Bun.write(
436
+ path.join(commandDir, "hello.md"),
437
+ `---
438
+ description: Test command
439
+ ---
440
+ Hello from singular command`,
441
+ )
442
+
443
+ await Bun.write(
444
+ path.join(commandDir, "nested", "child.md"),
445
+ `---
446
+ description: Nested command
447
+ ---
448
+ Nested command template`,
449
+ )
450
+ },
451
+ })
452
+
453
+ await Instance.provide({
454
+ directory: tmp.path,
455
+ fn: async () => {
456
+ const config = await Config.get()
457
+
458
+ expect(config.command?.["hello"]).toEqual({
459
+ description: "Test command",
460
+ template: "Hello from singular command",
461
+ })
462
+
463
+ expect(config.command?.["nested/child"]).toEqual({
464
+ description: "Nested command",
465
+ template: "Nested command template",
466
+ })
467
+ },
468
+ })
469
+ })
470
+
471
+ test("loads commands from .opencode/commands (plural)", async () => {
472
+ await using tmp = await tmpdir({
473
+ init: async (dir) => {
474
+ const opencodeDir = path.join(dir, ".opencode")
475
+ await fs.mkdir(opencodeDir, { recursive: true })
476
+
477
+ const commandsDir = path.join(opencodeDir, "commands")
478
+ await fs.mkdir(path.join(commandsDir, "nested"), { recursive: true })
479
+
480
+ await Bun.write(
481
+ path.join(commandsDir, "hello.md"),
482
+ `---
483
+ description: Test command
484
+ ---
485
+ Hello from plural commands`,
486
+ )
487
+
488
+ await Bun.write(
489
+ path.join(commandsDir, "nested", "child.md"),
490
+ `---
491
+ description: Nested command
492
+ ---
493
+ Nested command template`,
494
+ )
495
+ },
496
+ })
497
+
498
+ await Instance.provide({
499
+ directory: tmp.path,
500
+ fn: async () => {
501
+ const config = await Config.get()
502
+
503
+ expect(config.command?.["hello"]).toEqual({
504
+ description: "Test command",
505
+ template: "Hello from plural commands",
506
+ })
507
+
508
+ expect(config.command?.["nested/child"]).toEqual({
509
+ description: "Nested command",
510
+ template: "Nested command template",
511
+ })
512
+ },
513
+ })
514
+ })
515
+
516
+ test("updates config and writes to file", async () => {
517
+ await using tmp = await tmpdir()
518
+ await Instance.provide({
519
+ directory: tmp.path,
520
+ fn: async () => {
521
+ const newConfig = { model: "updated/model" }
522
+ await Config.update(newConfig as any)
523
+
524
+ const writtenConfig = JSON.parse(await Bun.file(path.join(tmp.path, "config.json")).text())
525
+ expect(writtenConfig.model).toBe("updated/model")
526
+ },
527
+ })
528
+ })
529
+
530
+ test("gets config directories", async () => {
531
+ await using tmp = await tmpdir()
532
+ await Instance.provide({
533
+ directory: tmp.path,
534
+ fn: async () => {
535
+ const dirs = await Config.directories()
536
+ expect(dirs.length).toBeGreaterThanOrEqual(1)
537
+ },
538
+ })
539
+ })
540
+
541
+ test("resolves scoped npm plugins in config", async () => {
542
+ await using tmp = await tmpdir({
543
+ init: async (dir) => {
544
+ const pluginDir = path.join(dir, "node_modules", "@scope", "plugin")
545
+ await fs.mkdir(pluginDir, { recursive: true })
546
+
547
+ await Bun.write(
548
+ path.join(dir, "package.json"),
549
+ JSON.stringify({ name: "config-fixture", version: "1.0.0", type: "module" }, null, 2),
550
+ )
551
+
552
+ await Bun.write(
553
+ path.join(pluginDir, "package.json"),
554
+ JSON.stringify(
555
+ {
556
+ name: "@scope/plugin",
557
+ version: "1.0.0",
558
+ type: "module",
559
+ main: "./index.js",
560
+ },
561
+ null,
562
+ 2,
563
+ ),
564
+ )
565
+
566
+ await Bun.write(path.join(pluginDir, "index.js"), "export default {}\n")
567
+
568
+ await Bun.write(
569
+ path.join(dir, "opencode.json"),
570
+ JSON.stringify({ $schema: "https://opencode.ai/config.json", plugin: ["@scope/plugin"] }, null, 2),
571
+ )
572
+ },
573
+ })
574
+
575
+ await Instance.provide({
576
+ directory: tmp.path,
577
+ fn: async () => {
578
+ const config = await Config.get()
579
+ const pluginEntries = config.plugin ?? []
580
+
581
+ const baseUrl = pathToFileURL(path.join(tmp.path, "opencode.json")).href
582
+ const expected = import.meta.resolve("@scope/plugin", baseUrl)
583
+
584
+ expect(pluginEntries.includes(expected)).toBe(true)
585
+
586
+ const scopedEntry = pluginEntries.find((entry) => entry === expected)
587
+ expect(scopedEntry).toBeDefined()
588
+ expect(scopedEntry?.includes("/node_modules/@scope/plugin/")).toBe(true)
589
+ },
590
+ })
591
+ })
592
+
593
+ test("merges plugin arrays from global and local configs", async () => {
594
+ await using tmp = await tmpdir({
595
+ init: async (dir) => {
596
+ // Create a nested project structure with local .opencode config
597
+ const projectDir = path.join(dir, "project")
598
+ const opencodeDir = path.join(projectDir, ".opencode")
599
+ await fs.mkdir(opencodeDir, { recursive: true })
600
+
601
+ // Global config with plugins
602
+ await Bun.write(
603
+ path.join(dir, "opencode.json"),
604
+ JSON.stringify({
605
+ $schema: "https://opencode.ai/config.json",
606
+ plugin: ["global-plugin-1", "global-plugin-2"],
607
+ }),
608
+ )
609
+
610
+ // Local .opencode config with different plugins
611
+ await Bun.write(
612
+ path.join(opencodeDir, "opencode.json"),
613
+ JSON.stringify({
614
+ $schema: "https://opencode.ai/config.json",
615
+ plugin: ["local-plugin-1"],
616
+ }),
617
+ )
618
+ },
619
+ })
620
+
621
+ await Instance.provide({
622
+ directory: path.join(tmp.path, "project"),
623
+ fn: async () => {
624
+ const config = await Config.get()
625
+ const plugins = config.plugin ?? []
626
+
627
+ // Should contain both global and local plugins
628
+ expect(plugins.some((p) => p.includes("global-plugin-1"))).toBe(true)
629
+ expect(plugins.some((p) => p.includes("global-plugin-2"))).toBe(true)
630
+ expect(plugins.some((p) => p.includes("local-plugin-1"))).toBe(true)
631
+
632
+ // Should have all 3 plugins (not replaced, but merged)
633
+ const pluginNames = plugins.filter((p) => p.includes("global-plugin") || p.includes("local-plugin"))
634
+ expect(pluginNames.length).toBeGreaterThanOrEqual(3)
635
+ },
636
+ })
637
+ })
638
+
639
+ test("does not error when only custom agent is a subagent", async () => {
640
+ await using tmp = await tmpdir({
641
+ init: async (dir) => {
642
+ const opencodeDir = path.join(dir, ".opencode")
643
+ await fs.mkdir(opencodeDir, { recursive: true })
644
+ const agentDir = path.join(opencodeDir, "agent")
645
+ await fs.mkdir(agentDir, { recursive: true })
646
+
647
+ await Bun.write(
648
+ path.join(agentDir, "helper.md"),
649
+ `---
650
+ model: test/model
651
+ mode: subagent
652
+ ---
653
+ Helper subagent prompt`,
654
+ )
655
+ },
656
+ })
657
+ await Instance.provide({
658
+ directory: tmp.path,
659
+ fn: async () => {
660
+ const config = await Config.get()
661
+ expect(config.agent?.["helper"]).toMatchObject({
662
+ name: "helper",
663
+ model: "test/model",
664
+ mode: "subagent",
665
+ prompt: "Helper subagent prompt",
666
+ })
667
+ },
668
+ })
669
+ })
670
+
671
+ test("merges instructions arrays from global and local configs", async () => {
672
+ await using tmp = await tmpdir({
673
+ init: async (dir) => {
674
+ const projectDir = path.join(dir, "project")
675
+ const opencodeDir = path.join(projectDir, ".opencode")
676
+ await fs.mkdir(opencodeDir, { recursive: true })
677
+
678
+ await Bun.write(
679
+ path.join(dir, "opencode.json"),
680
+ JSON.stringify({
681
+ $schema: "https://opencode.ai/config.json",
682
+ instructions: ["global-instructions.md", "shared-rules.md"],
683
+ }),
684
+ )
685
+
686
+ await Bun.write(
687
+ path.join(opencodeDir, "opencode.json"),
688
+ JSON.stringify({
689
+ $schema: "https://opencode.ai/config.json",
690
+ instructions: ["local-instructions.md"],
691
+ }),
692
+ )
693
+ },
694
+ })
695
+
696
+ await Instance.provide({
697
+ directory: path.join(tmp.path, "project"),
698
+ fn: async () => {
699
+ const config = await Config.get()
700
+ const instructions = config.instructions ?? []
701
+
702
+ expect(instructions).toContain("global-instructions.md")
703
+ expect(instructions).toContain("shared-rules.md")
704
+ expect(instructions).toContain("local-instructions.md")
705
+ expect(instructions.length).toBe(3)
706
+ },
707
+ })
708
+ })
709
+
710
+ test("deduplicates duplicate instructions from global and local configs", async () => {
711
+ await using tmp = await tmpdir({
712
+ init: async (dir) => {
713
+ const projectDir = path.join(dir, "project")
714
+ const opencodeDir = path.join(projectDir, ".opencode")
715
+ await fs.mkdir(opencodeDir, { recursive: true })
716
+
717
+ await Bun.write(
718
+ path.join(dir, "opencode.json"),
719
+ JSON.stringify({
720
+ $schema: "https://opencode.ai/config.json",
721
+ instructions: ["duplicate.md", "global-only.md"],
722
+ }),
723
+ )
724
+
725
+ await Bun.write(
726
+ path.join(opencodeDir, "opencode.json"),
727
+ JSON.stringify({
728
+ $schema: "https://opencode.ai/config.json",
729
+ instructions: ["duplicate.md", "local-only.md"],
730
+ }),
731
+ )
732
+ },
733
+ })
734
+
735
+ await Instance.provide({
736
+ directory: path.join(tmp.path, "project"),
737
+ fn: async () => {
738
+ const config = await Config.get()
739
+ const instructions = config.instructions ?? []
740
+
741
+ expect(instructions).toContain("global-only.md")
742
+ expect(instructions).toContain("local-only.md")
743
+ expect(instructions).toContain("duplicate.md")
744
+
745
+ const duplicates = instructions.filter((i) => i === "duplicate.md")
746
+ expect(duplicates.length).toBe(1)
747
+ expect(instructions.length).toBe(3)
748
+ },
749
+ })
750
+ })
751
+
752
+ test("deduplicates duplicate plugins from global and local configs", async () => {
753
+ await using tmp = await tmpdir({
754
+ init: async (dir) => {
755
+ // Create a nested project structure with local .opencode config
756
+ const projectDir = path.join(dir, "project")
757
+ const opencodeDir = path.join(projectDir, ".opencode")
758
+ await fs.mkdir(opencodeDir, { recursive: true })
759
+
760
+ // Global config with plugins
761
+ await Bun.write(
762
+ path.join(dir, "opencode.json"),
763
+ JSON.stringify({
764
+ $schema: "https://opencode.ai/config.json",
765
+ plugin: ["duplicate-plugin", "global-plugin-1"],
766
+ }),
767
+ )
768
+
769
+ // Local .opencode config with some overlapping plugins
770
+ await Bun.write(
771
+ path.join(opencodeDir, "opencode.json"),
772
+ JSON.stringify({
773
+ $schema: "https://opencode.ai/config.json",
774
+ plugin: ["duplicate-plugin", "local-plugin-1"],
775
+ }),
776
+ )
777
+ },
778
+ })
779
+
780
+ await Instance.provide({
781
+ directory: path.join(tmp.path, "project"),
782
+ fn: async () => {
783
+ const config = await Config.get()
784
+ const plugins = config.plugin ?? []
785
+
786
+ // Should contain all unique plugins
787
+ expect(plugins.some((p) => p.includes("global-plugin-1"))).toBe(true)
788
+ expect(plugins.some((p) => p.includes("local-plugin-1"))).toBe(true)
789
+ expect(plugins.some((p) => p.includes("duplicate-plugin"))).toBe(true)
790
+
791
+ // Should deduplicate the duplicate plugin
792
+ const duplicatePlugins = plugins.filter((p) => p.includes("duplicate-plugin"))
793
+ expect(duplicatePlugins.length).toBe(1)
794
+
795
+ // Should have exactly 3 unique plugins
796
+ const pluginNames = plugins.filter(
797
+ (p) => p.includes("global-plugin") || p.includes("local-plugin") || p.includes("duplicate-plugin"),
798
+ )
799
+ expect(pluginNames.length).toBe(3)
800
+ },
801
+ })
802
+ })
803
+
804
+ // Legacy tools migration tests
805
+
806
+ test("migrates legacy tools config to permissions - allow", async () => {
807
+ await using tmp = await tmpdir({
808
+ init: async (dir) => {
809
+ await Bun.write(
810
+ path.join(dir, "opencode.json"),
811
+ JSON.stringify({
812
+ $schema: "https://opencode.ai/config.json",
813
+ agent: {
814
+ test: {
815
+ tools: {
816
+ bash: true,
817
+ read: true,
818
+ },
819
+ },
820
+ },
821
+ }),
822
+ )
823
+ },
824
+ })
825
+ await Instance.provide({
826
+ directory: tmp.path,
827
+ fn: async () => {
828
+ const config = await Config.get()
829
+ expect(config.agent?.["test"]?.permission).toEqual({
830
+ bash: "allow",
831
+ read: "allow",
832
+ })
833
+ },
834
+ })
835
+ })
836
+
837
+ test("migrates legacy tools config to permissions - deny", async () => {
838
+ await using tmp = await tmpdir({
839
+ init: async (dir) => {
840
+ await Bun.write(
841
+ path.join(dir, "opencode.json"),
842
+ JSON.stringify({
843
+ $schema: "https://opencode.ai/config.json",
844
+ agent: {
845
+ test: {
846
+ tools: {
847
+ bash: false,
848
+ webfetch: false,
849
+ },
850
+ },
851
+ },
852
+ }),
853
+ )
854
+ },
855
+ })
856
+ await Instance.provide({
857
+ directory: tmp.path,
858
+ fn: async () => {
859
+ const config = await Config.get()
860
+ expect(config.agent?.["test"]?.permission).toEqual({
861
+ bash: "deny",
862
+ webfetch: "deny",
863
+ })
864
+ },
865
+ })
866
+ })
867
+
868
+ test("migrates legacy write tool to edit permission", async () => {
869
+ await using tmp = await tmpdir({
870
+ init: async (dir) => {
871
+ await Bun.write(
872
+ path.join(dir, "opencode.json"),
873
+ JSON.stringify({
874
+ $schema: "https://opencode.ai/config.json",
875
+ agent: {
876
+ test: {
877
+ tools: {
878
+ write: true,
879
+ },
880
+ },
881
+ },
882
+ }),
883
+ )
884
+ },
885
+ })
886
+ await Instance.provide({
887
+ directory: tmp.path,
888
+ fn: async () => {
889
+ const config = await Config.get()
890
+ expect(config.agent?.["test"]?.permission).toEqual({
891
+ edit: "allow",
892
+ })
893
+ },
894
+ })
895
+ })
896
+
897
+ test("migrates legacy edit tool to edit permission", async () => {
898
+ await using tmp = await tmpdir({
899
+ init: async (dir) => {
900
+ await Bun.write(
901
+ path.join(dir, "opencode.json"),
902
+ JSON.stringify({
903
+ $schema: "https://opencode.ai/config.json",
904
+ agent: {
905
+ test: {
906
+ tools: {
907
+ edit: false,
908
+ },
909
+ },
910
+ },
911
+ }),
912
+ )
913
+ },
914
+ })
915
+ await Instance.provide({
916
+ directory: tmp.path,
917
+ fn: async () => {
918
+ const config = await Config.get()
919
+ expect(config.agent?.["test"]?.permission).toEqual({
920
+ edit: "deny",
921
+ })
922
+ },
923
+ })
924
+ })
925
+
926
+ test("migrates legacy patch tool to edit permission", async () => {
927
+ await using tmp = await tmpdir({
928
+ init: async (dir) => {
929
+ await Bun.write(
930
+ path.join(dir, "opencode.json"),
931
+ JSON.stringify({
932
+ $schema: "https://opencode.ai/config.json",
933
+ agent: {
934
+ test: {
935
+ tools: {
936
+ patch: true,
937
+ },
938
+ },
939
+ },
940
+ }),
941
+ )
942
+ },
943
+ })
944
+ await Instance.provide({
945
+ directory: tmp.path,
946
+ fn: async () => {
947
+ const config = await Config.get()
948
+ expect(config.agent?.["test"]?.permission).toEqual({
949
+ edit: "allow",
950
+ })
951
+ },
952
+ })
953
+ })
954
+
955
+ test("migrates legacy multiedit tool to edit permission", async () => {
956
+ await using tmp = await tmpdir({
957
+ init: async (dir) => {
958
+ await Bun.write(
959
+ path.join(dir, "opencode.json"),
960
+ JSON.stringify({
961
+ $schema: "https://opencode.ai/config.json",
962
+ agent: {
963
+ test: {
964
+ tools: {
965
+ multiedit: false,
966
+ },
967
+ },
968
+ },
969
+ }),
970
+ )
971
+ },
972
+ })
973
+ await Instance.provide({
974
+ directory: tmp.path,
975
+ fn: async () => {
976
+ const config = await Config.get()
977
+ expect(config.agent?.["test"]?.permission).toEqual({
978
+ edit: "deny",
979
+ })
980
+ },
981
+ })
982
+ })
983
+
984
+ test("migrates mixed legacy tools config", async () => {
985
+ await using tmp = await tmpdir({
986
+ init: async (dir) => {
987
+ await Bun.write(
988
+ path.join(dir, "opencode.json"),
989
+ JSON.stringify({
990
+ $schema: "https://opencode.ai/config.json",
991
+ agent: {
992
+ test: {
993
+ tools: {
994
+ bash: true,
995
+ write: true,
996
+ read: false,
997
+ webfetch: true,
998
+ },
999
+ },
1000
+ },
1001
+ }),
1002
+ )
1003
+ },
1004
+ })
1005
+ await Instance.provide({
1006
+ directory: tmp.path,
1007
+ fn: async () => {
1008
+ const config = await Config.get()
1009
+ expect(config.agent?.["test"]?.permission).toEqual({
1010
+ bash: "allow",
1011
+ edit: "allow",
1012
+ read: "deny",
1013
+ webfetch: "allow",
1014
+ })
1015
+ },
1016
+ })
1017
+ })
1018
+
1019
+ test("merges legacy tools with existing permission config", async () => {
1020
+ await using tmp = await tmpdir({
1021
+ init: async (dir) => {
1022
+ await Bun.write(
1023
+ path.join(dir, "opencode.json"),
1024
+ JSON.stringify({
1025
+ $schema: "https://opencode.ai/config.json",
1026
+ agent: {
1027
+ test: {
1028
+ permission: {
1029
+ glob: "allow",
1030
+ },
1031
+ tools: {
1032
+ bash: true,
1033
+ },
1034
+ },
1035
+ },
1036
+ }),
1037
+ )
1038
+ },
1039
+ })
1040
+ await Instance.provide({
1041
+ directory: tmp.path,
1042
+ fn: async () => {
1043
+ const config = await Config.get()
1044
+ expect(config.agent?.["test"]?.permission).toEqual({
1045
+ glob: "allow",
1046
+ bash: "allow",
1047
+ })
1048
+ },
1049
+ })
1050
+ })
1051
+
1052
+ test("permission config preserves key order", async () => {
1053
+ await using tmp = await tmpdir({
1054
+ init: async (dir) => {
1055
+ await Bun.write(
1056
+ path.join(dir, "opencode.json"),
1057
+ JSON.stringify({
1058
+ $schema: "https://opencode.ai/config.json",
1059
+ permission: {
1060
+ "*": "deny",
1061
+ edit: "ask",
1062
+ write: "ask",
1063
+ external_directory: "ask",
1064
+ read: "allow",
1065
+ todowrite: "allow",
1066
+ todoread: "allow",
1067
+ "thoughts_*": "allow",
1068
+ "reasoning_model_*": "allow",
1069
+ "tools_*": "allow",
1070
+ "pr_comments_*": "allow",
1071
+ },
1072
+ }),
1073
+ )
1074
+ },
1075
+ })
1076
+ await Instance.provide({
1077
+ directory: tmp.path,
1078
+ fn: async () => {
1079
+ const config = await Config.get()
1080
+ expect(Object.keys(config.permission!)).toEqual([
1081
+ "*",
1082
+ "edit",
1083
+ "write",
1084
+ "external_directory",
1085
+ "read",
1086
+ "todowrite",
1087
+ "todoread",
1088
+ "thoughts_*",
1089
+ "reasoning_model_*",
1090
+ "tools_*",
1091
+ "pr_comments_*",
1092
+ ])
1093
+ },
1094
+ })
1095
+ })
1096
+
1097
+ // MCP config merging tests
1098
+
1099
+ test("project config can override MCP server enabled status", async () => {
1100
+ await using tmp = await tmpdir({
1101
+ init: async (dir) => {
1102
+ // Simulates a base config (like from remote .well-known) with disabled MCP
1103
+ await Bun.write(
1104
+ path.join(dir, "opencode.jsonc"),
1105
+ JSON.stringify({
1106
+ $schema: "https://opencode.ai/config.json",
1107
+ mcp: {
1108
+ jira: {
1109
+ type: "remote",
1110
+ url: "https://jira.example.com/mcp",
1111
+ enabled: false,
1112
+ },
1113
+ wiki: {
1114
+ type: "remote",
1115
+ url: "https://wiki.example.com/mcp",
1116
+ enabled: false,
1117
+ },
1118
+ },
1119
+ }),
1120
+ )
1121
+ // Project config enables just jira
1122
+ await Bun.write(
1123
+ path.join(dir, "opencode.json"),
1124
+ JSON.stringify({
1125
+ $schema: "https://opencode.ai/config.json",
1126
+ mcp: {
1127
+ jira: {
1128
+ type: "remote",
1129
+ url: "https://jira.example.com/mcp",
1130
+ enabled: true,
1131
+ },
1132
+ },
1133
+ }),
1134
+ )
1135
+ },
1136
+ })
1137
+ await Instance.provide({
1138
+ directory: tmp.path,
1139
+ fn: async () => {
1140
+ const config = await Config.get()
1141
+ // jira should be enabled (overridden by project config)
1142
+ expect(config.mcp?.jira).toEqual({
1143
+ type: "remote",
1144
+ url: "https://jira.example.com/mcp",
1145
+ enabled: true,
1146
+ })
1147
+ // wiki should still be disabled (not overridden)
1148
+ expect(config.mcp?.wiki).toEqual({
1149
+ type: "remote",
1150
+ url: "https://wiki.example.com/mcp",
1151
+ enabled: false,
1152
+ })
1153
+ },
1154
+ })
1155
+ })
1156
+
1157
+ test("MCP config deep merges preserving base config properties", async () => {
1158
+ await using tmp = await tmpdir({
1159
+ init: async (dir) => {
1160
+ // Base config with full MCP definition
1161
+ await Bun.write(
1162
+ path.join(dir, "opencode.jsonc"),
1163
+ JSON.stringify({
1164
+ $schema: "https://opencode.ai/config.json",
1165
+ mcp: {
1166
+ myserver: {
1167
+ type: "remote",
1168
+ url: "https://myserver.example.com/mcp",
1169
+ enabled: false,
1170
+ headers: {
1171
+ "X-Custom-Header": "value",
1172
+ },
1173
+ },
1174
+ },
1175
+ }),
1176
+ )
1177
+ // Override just enables it, should preserve other properties
1178
+ await Bun.write(
1179
+ path.join(dir, "opencode.json"),
1180
+ JSON.stringify({
1181
+ $schema: "https://opencode.ai/config.json",
1182
+ mcp: {
1183
+ myserver: {
1184
+ type: "remote",
1185
+ url: "https://myserver.example.com/mcp",
1186
+ enabled: true,
1187
+ },
1188
+ },
1189
+ }),
1190
+ )
1191
+ },
1192
+ })
1193
+ await Instance.provide({
1194
+ directory: tmp.path,
1195
+ fn: async () => {
1196
+ const config = await Config.get()
1197
+ expect(config.mcp?.myserver).toEqual({
1198
+ type: "remote",
1199
+ url: "https://myserver.example.com/mcp",
1200
+ enabled: true,
1201
+ headers: {
1202
+ "X-Custom-Header": "value",
1203
+ },
1204
+ })
1205
+ },
1206
+ })
1207
+ })
1208
+
1209
+ test("local .opencode config can override MCP from project config", async () => {
1210
+ await using tmp = await tmpdir({
1211
+ init: async (dir) => {
1212
+ // Project config with disabled MCP
1213
+ await Bun.write(
1214
+ path.join(dir, "opencode.json"),
1215
+ JSON.stringify({
1216
+ $schema: "https://opencode.ai/config.json",
1217
+ mcp: {
1218
+ docs: {
1219
+ type: "remote",
1220
+ url: "https://docs.example.com/mcp",
1221
+ enabled: false,
1222
+ },
1223
+ },
1224
+ }),
1225
+ )
1226
+ // Local .opencode directory config enables it
1227
+ const opencodeDir = path.join(dir, ".opencode")
1228
+ await fs.mkdir(opencodeDir, { recursive: true })
1229
+ await Bun.write(
1230
+ path.join(opencodeDir, "opencode.json"),
1231
+ JSON.stringify({
1232
+ $schema: "https://opencode.ai/config.json",
1233
+ mcp: {
1234
+ docs: {
1235
+ type: "remote",
1236
+ url: "https://docs.example.com/mcp",
1237
+ enabled: true,
1238
+ },
1239
+ },
1240
+ }),
1241
+ )
1242
+ },
1243
+ })
1244
+ await Instance.provide({
1245
+ directory: tmp.path,
1246
+ fn: async () => {
1247
+ const config = await Config.get()
1248
+ expect(config.mcp?.docs?.enabled).toBe(true)
1249
+ },
1250
+ })
1251
+ })
1252
+
1253
+ test("project config overrides remote well-known config", async () => {
1254
+ const originalFetch = globalThis.fetch
1255
+ let fetchedUrl: string | undefined
1256
+ const mockFetch = mock((url: string | URL | Request) => {
1257
+ const urlStr = url.toString()
1258
+ if (urlStr.includes(".well-known/opencode")) {
1259
+ fetchedUrl = urlStr
1260
+ return Promise.resolve(
1261
+ new Response(
1262
+ JSON.stringify({
1263
+ config: {
1264
+ mcp: {
1265
+ jira: {
1266
+ type: "remote",
1267
+ url: "https://jira.example.com/mcp",
1268
+ enabled: false,
1269
+ },
1270
+ },
1271
+ },
1272
+ }),
1273
+ { status: 200 },
1274
+ ),
1275
+ )
1276
+ }
1277
+ return originalFetch(url)
1278
+ })
1279
+ globalThis.fetch = mockFetch as unknown as typeof fetch
1280
+
1281
+ const originalAuthAll = Auth.all
1282
+ Auth.all = mock(() =>
1283
+ Promise.resolve({
1284
+ "https://example.com": {
1285
+ type: "wellknown" as const,
1286
+ key: "TEST_TOKEN",
1287
+ token: "test-token",
1288
+ },
1289
+ }),
1290
+ )
1291
+
1292
+ try {
1293
+ await using tmp = await tmpdir({
1294
+ git: true,
1295
+ init: async (dir) => {
1296
+ // Project config enables jira (overriding remote default)
1297
+ await Bun.write(
1298
+ path.join(dir, "opencode.json"),
1299
+ JSON.stringify({
1300
+ $schema: "https://opencode.ai/config.json",
1301
+ mcp: {
1302
+ jira: {
1303
+ type: "remote",
1304
+ url: "https://jira.example.com/mcp",
1305
+ enabled: true,
1306
+ },
1307
+ },
1308
+ }),
1309
+ )
1310
+ },
1311
+ })
1312
+ await Instance.provide({
1313
+ directory: tmp.path,
1314
+ fn: async () => {
1315
+ const config = await Config.get()
1316
+ // Verify fetch was called for wellknown config
1317
+ expect(fetchedUrl).toBe("https://example.com/.well-known/opencode")
1318
+ // Project config (enabled: true) should override remote (enabled: false)
1319
+ expect(config.mcp?.jira?.enabled).toBe(true)
1320
+ },
1321
+ })
1322
+ } finally {
1323
+ globalThis.fetch = originalFetch
1324
+ Auth.all = originalAuthAll
1325
+ }
1326
+ })
1327
+
1328
+ describe("getPluginName", () => {
1329
+ test("extracts name from file:// URL", () => {
1330
+ expect(Config.getPluginName("file:///path/to/plugin/foo.js")).toBe("foo")
1331
+ expect(Config.getPluginName("file:///path/to/plugin/bar.ts")).toBe("bar")
1332
+ expect(Config.getPluginName("file:///some/path/my-plugin.js")).toBe("my-plugin")
1333
+ })
1334
+
1335
+ test("extracts name from npm package with version", () => {
1336
+ expect(Config.getPluginName("oh-my-opencode@2.4.3")).toBe("oh-my-opencode")
1337
+ expect(Config.getPluginName("some-plugin@1.0.0")).toBe("some-plugin")
1338
+ expect(Config.getPluginName("plugin@latest")).toBe("plugin")
1339
+ })
1340
+
1341
+ test("extracts name from scoped npm package", () => {
1342
+ expect(Config.getPluginName("@scope/pkg@1.0.0")).toBe("@scope/pkg")
1343
+ expect(Config.getPluginName("@opencode/plugin@2.0.0")).toBe("@opencode/plugin")
1344
+ })
1345
+
1346
+ test("returns full string for package without version", () => {
1347
+ expect(Config.getPluginName("some-plugin")).toBe("some-plugin")
1348
+ expect(Config.getPluginName("@scope/pkg")).toBe("@scope/pkg")
1349
+ })
1350
+ })
1351
+
1352
+ describe("deduplicatePlugins", () => {
1353
+ test("removes duplicates keeping higher priority (later entries)", () => {
1354
+ const plugins = ["global-plugin@1.0.0", "shared-plugin@1.0.0", "local-plugin@2.0.0", "shared-plugin@2.0.0"]
1355
+
1356
+ const result = Config.deduplicatePlugins(plugins)
1357
+
1358
+ expect(result).toContain("global-plugin@1.0.0")
1359
+ expect(result).toContain("local-plugin@2.0.0")
1360
+ expect(result).toContain("shared-plugin@2.0.0")
1361
+ expect(result).not.toContain("shared-plugin@1.0.0")
1362
+ expect(result.length).toBe(3)
1363
+ })
1364
+
1365
+ test("prefers local file over npm package with same name", () => {
1366
+ const plugins = ["oh-my-opencode@2.4.3", "file:///project/.opencode/plugin/oh-my-opencode.js"]
1367
+
1368
+ const result = Config.deduplicatePlugins(plugins)
1369
+
1370
+ expect(result.length).toBe(1)
1371
+ expect(result[0]).toBe("file:///project/.opencode/plugin/oh-my-opencode.js")
1372
+ })
1373
+
1374
+ test("preserves order of remaining plugins", () => {
1375
+ const plugins = ["a-plugin@1.0.0", "b-plugin@1.0.0", "c-plugin@1.0.0"]
1376
+
1377
+ const result = Config.deduplicatePlugins(plugins)
1378
+
1379
+ expect(result).toEqual(["a-plugin@1.0.0", "b-plugin@1.0.0", "c-plugin@1.0.0"])
1380
+ })
1381
+
1382
+ test("local plugin directory overrides global opencode.json plugin", async () => {
1383
+ await using tmp = await tmpdir({
1384
+ init: async (dir) => {
1385
+ const projectDir = path.join(dir, "project")
1386
+ const opencodeDir = path.join(projectDir, ".opencode")
1387
+ const pluginDir = path.join(opencodeDir, "plugin")
1388
+ await fs.mkdir(pluginDir, { recursive: true })
1389
+
1390
+ await Bun.write(
1391
+ path.join(dir, "opencode.json"),
1392
+ JSON.stringify({
1393
+ $schema: "https://opencode.ai/config.json",
1394
+ plugin: ["my-plugin@1.0.0"],
1395
+ }),
1396
+ )
1397
+
1398
+ await Bun.write(path.join(pluginDir, "my-plugin.js"), "export default {}")
1399
+ },
1400
+ })
1401
+
1402
+ await Instance.provide({
1403
+ directory: path.join(tmp.path, "project"),
1404
+ fn: async () => {
1405
+ const config = await Config.get()
1406
+ const plugins = config.plugin ?? []
1407
+
1408
+ const myPlugins = plugins.filter((p) => Config.getPluginName(p) === "my-plugin")
1409
+ expect(myPlugins.length).toBe(1)
1410
+ expect(myPlugins[0].startsWith("file://")).toBe(true)
1411
+ },
1412
+ })
1413
+ })
1414
+ })