alchemylab-opencode 1.0.0

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 (379) hide show
  1. package/LICENSE +21 -0
  2. package/NODE_COMPAT.md +184 -0
  3. package/package.json +112 -0
  4. package/packages/opencode/migration/20260127222353_familiar_lady_ursula/migration.sql +90 -0
  5. package/packages/opencode/migration/20260127222353_familiar_lady_ursula/snapshot.json +796 -0
  6. package/packages/opencode/migration/20260211171708_add_project_commands/migration.sql +1 -0
  7. package/packages/opencode/migration/20260211171708_add_project_commands/snapshot.json +806 -0
  8. package/packages/opencode/migration/20260213144116_wakeful_the_professor/migration.sql +11 -0
  9. package/packages/opencode/migration/20260213144116_wakeful_the_professor/snapshot.json +897 -0
  10. package/packages/opencode/migration/20260225215848_workspace/migration.sql +7 -0
  11. package/packages/opencode/migration/20260225215848_workspace/snapshot.json +959 -0
  12. package/packages/opencode/migration/20260227213759_add_session_workspace_id/migration.sql +2 -0
  13. package/packages/opencode/migration/20260227213759_add_session_workspace_id/snapshot.json +983 -0
  14. package/packages/opencode/migration/20260228203230_blue_harpoon/migration.sql +17 -0
  15. package/packages/opencode/migration/20260228203230_blue_harpoon/snapshot.json +1102 -0
  16. package/packages/opencode/migration/20260303231226_add_workspace_fields/migration.sql +5 -0
  17. package/packages/opencode/migration/20260303231226_add_workspace_fields/snapshot.json +1013 -0
  18. package/packages/opencode/migration/20260309230000_move_org_to_state/migration.sql +3 -0
  19. package/packages/opencode/migration/20260309230000_move_org_to_state/snapshot.json +1156 -0
  20. package/packages/opencode/migration/20260312043431_session_message_cursor/migration.sql +4 -0
  21. package/packages/opencode/migration/20260312043431_session_message_cursor/snapshot.json +1168 -0
  22. package/packages/opencode/migration/20260323234822_events/migration.sql +13 -0
  23. package/packages/opencode/migration/20260323234822_events/snapshot.json +1271 -0
  24. package/packages/opencode/package.json +140 -0
  25. package/packages/opencode/src/account/account.sql.ts +39 -0
  26. package/packages/opencode/src/account/index.ts +463 -0
  27. package/packages/opencode/src/account/repo.ts +163 -0
  28. package/packages/opencode/src/account/schema.ts +91 -0
  29. package/packages/opencode/src/acp/README.md +174 -0
  30. package/packages/opencode/src/acp/agent.ts +1847 -0
  31. package/packages/opencode/src/acp/session.ts +116 -0
  32. package/packages/opencode/src/acp/types.ts +24 -0
  33. package/packages/opencode/src/agent/agent.ts +420 -0
  34. package/packages/opencode/src/agent/generate.txt +75 -0
  35. package/packages/opencode/src/agent/prompt/compaction.txt +15 -0
  36. package/packages/opencode/src/agent/prompt/explore.txt +18 -0
  37. package/packages/opencode/src/agent/prompt/summary.txt +11 -0
  38. package/packages/opencode/src/agent/prompt/title.txt +44 -0
  39. package/packages/opencode/src/auth/index.ts +110 -0
  40. package/packages/opencode/src/bus/bus-event.ts +40 -0
  41. package/packages/opencode/src/bus/global.ts +10 -0
  42. package/packages/opencode/src/bus/index.ts +185 -0
  43. package/packages/opencode/src/cli/bootstrap.ts +17 -0
  44. package/packages/opencode/src/cli/cmd/cmd.ts +7 -0
  45. package/packages/opencode/src/cli/cmd/run.ts +689 -0
  46. package/packages/opencode/src/cli/cmd/serve.ts +24 -0
  47. package/packages/opencode/src/cli/cmd/tui/event.ts +49 -0
  48. package/packages/opencode/src/cli/effect/prompt.ts +25 -0
  49. package/packages/opencode/src/cli/error.ts +46 -0
  50. package/packages/opencode/src/cli/heap.ts +59 -0
  51. package/packages/opencode/src/cli/logo.ts +6 -0
  52. package/packages/opencode/src/cli/network.ts +60 -0
  53. package/packages/opencode/src/cli/ui.ts +133 -0
  54. package/packages/opencode/src/cli/upgrade.ts +31 -0
  55. package/packages/opencode/src/command/index.ts +195 -0
  56. package/packages/opencode/src/command/template/initialize.txt +66 -0
  57. package/packages/opencode/src/command/template/review.txt +101 -0
  58. package/packages/opencode/src/config/config.ts +1599 -0
  59. package/packages/opencode/src/config/console-state.ts +15 -0
  60. package/packages/opencode/src/config/markdown.ts +99 -0
  61. package/packages/opencode/src/config/paths.ts +167 -0
  62. package/packages/opencode/src/config/tui-migrate.ts +155 -0
  63. package/packages/opencode/src/config/tui-schema.ts +37 -0
  64. package/packages/opencode/src/config/tui.ts +179 -0
  65. package/packages/opencode/src/control-plane/adaptors/index.ts +20 -0
  66. package/packages/opencode/src/control-plane/adaptors/worktree.ts +42 -0
  67. package/packages/opencode/src/control-plane/schema.ts +17 -0
  68. package/packages/opencode/src/control-plane/sse.ts +66 -0
  69. package/packages/opencode/src/control-plane/types.ts +32 -0
  70. package/packages/opencode/src/control-plane/workspace.sql.ts +17 -0
  71. package/packages/opencode/src/control-plane/workspace.ts +168 -0
  72. package/packages/opencode/src/effect/cross-spawn-spawner.ts +502 -0
  73. package/packages/opencode/src/effect/instance-ref.ts +6 -0
  74. package/packages/opencode/src/effect/instance-registry.ts +12 -0
  75. package/packages/opencode/src/effect/instance-state.ts +82 -0
  76. package/packages/opencode/src/effect/run-service.ts +33 -0
  77. package/packages/opencode/src/effect/runner.ts +216 -0
  78. package/packages/opencode/src/env/index.ts +28 -0
  79. package/packages/opencode/src/file/ignore.ts +82 -0
  80. package/packages/opencode/src/file/index.ts +686 -0
  81. package/packages/opencode/src/file/protected.ts +59 -0
  82. package/packages/opencode/src/file/ripgrep.ts +376 -0
  83. package/packages/opencode/src/file/time.ts +133 -0
  84. package/packages/opencode/src/file/watcher.ts +173 -0
  85. package/packages/opencode/src/filesystem/index.ts +236 -0
  86. package/packages/opencode/src/flag/flag.ts +156 -0
  87. package/packages/opencode/src/format/formatter.ts +413 -0
  88. package/packages/opencode/src/format/index.ts +203 -0
  89. package/packages/opencode/src/git/index.ts +303 -0
  90. package/packages/opencode/src/global/index.ts +56 -0
  91. package/packages/opencode/src/id/id.ts +85 -0
  92. package/packages/opencode/src/ide/index.ts +74 -0
  93. package/packages/opencode/src/installation/index.ts +355 -0
  94. package/packages/opencode/src/installation/meta.ts +7 -0
  95. package/packages/opencode/src/lsp/client.ts +252 -0
  96. package/packages/opencode/src/lsp/index.ts +558 -0
  97. package/packages/opencode/src/lsp/language.ts +120 -0
  98. package/packages/opencode/src/lsp/launch.ts +21 -0
  99. package/packages/opencode/src/lsp/server.ts +1968 -0
  100. package/packages/opencode/src/mcp/auth.ts +173 -0
  101. package/packages/opencode/src/mcp/index.ts +931 -0
  102. package/packages/opencode/src/mcp/oauth-callback.ts +216 -0
  103. package/packages/opencode/src/mcp/oauth-provider.ts +185 -0
  104. package/packages/opencode/src/node-loader.mjs +104 -0
  105. package/packages/opencode/src/node-preload.mjs +39 -0
  106. package/packages/opencode/src/node.ts +1 -0
  107. package/packages/opencode/src/npm/index.ts +188 -0
  108. package/packages/opencode/src/patch/index.ts +680 -0
  109. package/packages/opencode/src/permission/arity.ts +163 -0
  110. package/packages/opencode/src/permission/evaluate.ts +15 -0
  111. package/packages/opencode/src/permission/index.ts +325 -0
  112. package/packages/opencode/src/permission/schema.ts +17 -0
  113. package/packages/opencode/src/plugin/cloudflare.ts +67 -0
  114. package/packages/opencode/src/plugin/codex.ts +608 -0
  115. package/packages/opencode/src/plugin/github-copilot/copilot.ts +361 -0
  116. package/packages/opencode/src/plugin/github-copilot/models.ts +144 -0
  117. package/packages/opencode/src/plugin/index.ts +299 -0
  118. package/packages/opencode/src/plugin/install.ts +439 -0
  119. package/packages/opencode/src/plugin/loader.ts +174 -0
  120. package/packages/opencode/src/plugin/meta.ts +188 -0
  121. package/packages/opencode/src/plugin/shared.ts +323 -0
  122. package/packages/opencode/src/project/bootstrap.ts +31 -0
  123. package/packages/opencode/src/project/instance.ts +175 -0
  124. package/packages/opencode/src/project/project.sql.ts +16 -0
  125. package/packages/opencode/src/project/project.ts +519 -0
  126. package/packages/opencode/src/project/schema.ts +16 -0
  127. package/packages/opencode/src/project/state.ts +70 -0
  128. package/packages/opencode/src/project/vcs.ts +240 -0
  129. package/packages/opencode/src/provider/auth.ts +253 -0
  130. package/packages/opencode/src/provider/error.ts +197 -0
  131. package/packages/opencode/src/provider/models.ts +162 -0
  132. package/packages/opencode/src/provider/provider.ts +1709 -0
  133. package/packages/opencode/src/provider/schema.ts +38 -0
  134. package/packages/opencode/src/provider/sdk/copilot/README.md +5 -0
  135. package/packages/opencode/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +170 -0
  136. package/packages/opencode/src/provider/sdk/copilot/chat/get-response-metadata.ts +15 -0
  137. package/packages/opencode/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +19 -0
  138. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +64 -0
  139. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +815 -0
  140. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +28 -0
  141. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +44 -0
  142. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +83 -0
  143. package/packages/opencode/src/provider/sdk/copilot/copilot-provider.ts +100 -0
  144. package/packages/opencode/src/provider/sdk/copilot/index.ts +2 -0
  145. package/packages/opencode/src/provider/sdk/copilot/openai-compatible-error.ts +27 -0
  146. package/packages/opencode/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +335 -0
  147. package/packages/opencode/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +22 -0
  148. package/packages/opencode/src/provider/sdk/copilot/responses/openai-config.ts +18 -0
  149. package/packages/opencode/src/provider/sdk/copilot/responses/openai-error.ts +22 -0
  150. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +214 -0
  151. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +1769 -0
  152. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +173 -0
  153. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-settings.ts +1 -0
  154. package/packages/opencode/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +87 -0
  155. package/packages/opencode/src/provider/sdk/copilot/responses/tool/file-search.ts +127 -0
  156. package/packages/opencode/src/provider/sdk/copilot/responses/tool/image-generation.ts +114 -0
  157. package/packages/opencode/src/provider/sdk/copilot/responses/tool/local-shell.ts +64 -0
  158. package/packages/opencode/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +103 -0
  159. package/packages/opencode/src/provider/sdk/copilot/responses/tool/web-search.ts +102 -0
  160. package/packages/opencode/src/provider/transform.ts +1050 -0
  161. package/packages/opencode/src/pty/index.ts +397 -0
  162. package/packages/opencode/src/pty/pty.node.ts +27 -0
  163. package/packages/opencode/src/pty/pty.ts +25 -0
  164. package/packages/opencode/src/pty/schema.ts +17 -0
  165. package/packages/opencode/src/question/index.ts +224 -0
  166. package/packages/opencode/src/question/schema.ts +17 -0
  167. package/packages/opencode/src/run.ts +28 -0
  168. package/packages/opencode/src/serve.ts +45 -0
  169. package/packages/opencode/src/server/error.ts +36 -0
  170. package/packages/opencode/src/server/event.ts +7 -0
  171. package/packages/opencode/src/server/instance.ts +324 -0
  172. package/packages/opencode/src/server/mdns.ts +60 -0
  173. package/packages/opencode/src/server/middleware.ts +33 -0
  174. package/packages/opencode/src/server/projectors.ts +28 -0
  175. package/packages/opencode/src/server/proxy.ts +131 -0
  176. package/packages/opencode/src/server/router.ts +105 -0
  177. package/packages/opencode/src/server/routes/config.ts +92 -0
  178. package/packages/opencode/src/server/routes/event.ts +83 -0
  179. package/packages/opencode/src/server/routes/experimental.ts +374 -0
  180. package/packages/opencode/src/server/routes/file.ts +197 -0
  181. package/packages/opencode/src/server/routes/global.ts +312 -0
  182. package/packages/opencode/src/server/routes/mcp.ts +225 -0
  183. package/packages/opencode/src/server/routes/permission.ts +69 -0
  184. package/packages/opencode/src/server/routes/project.ts +118 -0
  185. package/packages/opencode/src/server/routes/provider.ts +171 -0
  186. package/packages/opencode/src/server/routes/pty.ts +210 -0
  187. package/packages/opencode/src/server/routes/question.ts +99 -0
  188. package/packages/opencode/src/server/routes/session.ts +1030 -0
  189. package/packages/opencode/src/server/routes/tui.ts +379 -0
  190. package/packages/opencode/src/server/routes/workspace.ts +94 -0
  191. package/packages/opencode/src/server/server.ts +353 -0
  192. package/packages/opencode/src/session/compaction.ts +428 -0
  193. package/packages/opencode/src/session/index.ts +887 -0
  194. package/packages/opencode/src/session/instruction.ts +258 -0
  195. package/packages/opencode/src/session/llm.ts +354 -0
  196. package/packages/opencode/src/session/message-v2.ts +1031 -0
  197. package/packages/opencode/src/session/message.ts +191 -0
  198. package/packages/opencode/src/session/overflow.ts +22 -0
  199. package/packages/opencode/src/session/processor.ts +523 -0
  200. package/packages/opencode/src/session/projectors.ts +135 -0
  201. package/packages/opencode/src/session/prompt/anthropic.txt +105 -0
  202. package/packages/opencode/src/session/prompt/beast.txt +147 -0
  203. package/packages/opencode/src/session/prompt/build-switch.txt +5 -0
  204. package/packages/opencode/src/session/prompt/codex.txt +79 -0
  205. package/packages/opencode/src/session/prompt/copilot-gpt-5.txt +143 -0
  206. package/packages/opencode/src/session/prompt/default.txt +105 -0
  207. package/packages/opencode/src/session/prompt/gemini.txt +155 -0
  208. package/packages/opencode/src/session/prompt/gpt.txt +107 -0
  209. package/packages/opencode/src/session/prompt/kimi.txt +95 -0
  210. package/packages/opencode/src/session/prompt/max-steps.txt +16 -0
  211. package/packages/opencode/src/session/prompt/plan-reminder-anthropic.txt +67 -0
  212. package/packages/opencode/src/session/prompt/plan.txt +26 -0
  213. package/packages/opencode/src/session/prompt/trinity.txt +97 -0
  214. package/packages/opencode/src/session/prompt.ts +1911 -0
  215. package/packages/opencode/src/session/retry.ts +106 -0
  216. package/packages/opencode/src/session/revert.ts +176 -0
  217. package/packages/opencode/src/session/schema.ts +38 -0
  218. package/packages/opencode/src/session/session.sql.ts +103 -0
  219. package/packages/opencode/src/session/status.ts +102 -0
  220. package/packages/opencode/src/session/summary.ts +177 -0
  221. package/packages/opencode/src/session/system.ts +76 -0
  222. package/packages/opencode/src/session/todo.ts +95 -0
  223. package/packages/opencode/src/share/share-next.ts +369 -0
  224. package/packages/opencode/src/share/share.sql.ts +13 -0
  225. package/packages/opencode/src/shell/shell.ts +110 -0
  226. package/packages/opencode/src/skill/discovery.ts +116 -0
  227. package/packages/opencode/src/skill/index.ts +277 -0
  228. package/packages/opencode/src/snapshot/index.ts +726 -0
  229. package/packages/opencode/src/sql.d.ts +4 -0
  230. package/packages/opencode/src/storage/db.node.ts +8 -0
  231. package/packages/opencode/src/storage/db.ts +177 -0
  232. package/packages/opencode/src/storage/json-migration.ts +425 -0
  233. package/packages/opencode/src/storage/schema.sql.ts +10 -0
  234. package/packages/opencode/src/storage/schema.ts +5 -0
  235. package/packages/opencode/src/storage/storage.ts +353 -0
  236. package/packages/opencode/src/sync/README.md +179 -0
  237. package/packages/opencode/src/sync/event.sql.ts +16 -0
  238. package/packages/opencode/src/sync/index.ts +263 -0
  239. package/packages/opencode/src/sync/schema.ts +14 -0
  240. package/packages/opencode/src/tool/apply_patch.ts +281 -0
  241. package/packages/opencode/src/tool/apply_patch.txt +33 -0
  242. package/packages/opencode/src/tool/bash.ts +496 -0
  243. package/packages/opencode/src/tool/bash.txt +117 -0
  244. package/packages/opencode/src/tool/batch.ts +183 -0
  245. package/packages/opencode/src/tool/batch.txt +24 -0
  246. package/packages/opencode/src/tool/codesearch.ts +132 -0
  247. package/packages/opencode/src/tool/codesearch.txt +12 -0
  248. package/packages/opencode/src/tool/edit.ts +667 -0
  249. package/packages/opencode/src/tool/edit.txt +10 -0
  250. package/packages/opencode/src/tool/external-directory.ts +46 -0
  251. package/packages/opencode/src/tool/glob.ts +78 -0
  252. package/packages/opencode/src/tool/glob.txt +6 -0
  253. package/packages/opencode/src/tool/grep.ts +156 -0
  254. package/packages/opencode/src/tool/grep.txt +8 -0
  255. package/packages/opencode/src/tool/invalid.ts +17 -0
  256. package/packages/opencode/src/tool/ls.ts +121 -0
  257. package/packages/opencode/src/tool/ls.txt +1 -0
  258. package/packages/opencode/src/tool/lsp.ts +97 -0
  259. package/packages/opencode/src/tool/lsp.txt +19 -0
  260. package/packages/opencode/src/tool/multiedit.ts +46 -0
  261. package/packages/opencode/src/tool/multiedit.txt +41 -0
  262. package/packages/opencode/src/tool/plan-enter.txt +14 -0
  263. package/packages/opencode/src/tool/plan-exit.txt +13 -0
  264. package/packages/opencode/src/tool/plan.ts +131 -0
  265. package/packages/opencode/src/tool/question.ts +46 -0
  266. package/packages/opencode/src/tool/question.txt +10 -0
  267. package/packages/opencode/src/tool/read.ts +332 -0
  268. package/packages/opencode/src/tool/read.txt +14 -0
  269. package/packages/opencode/src/tool/registry.ts +265 -0
  270. package/packages/opencode/src/tool/schema.ts +17 -0
  271. package/packages/opencode/src/tool/skill.ts +105 -0
  272. package/packages/opencode/src/tool/task.ts +166 -0
  273. package/packages/opencode/src/tool/task.txt +60 -0
  274. package/packages/opencode/src/tool/todo.ts +48 -0
  275. package/packages/opencode/src/tool/todowrite.txt +167 -0
  276. package/packages/opencode/src/tool/tool.ts +112 -0
  277. package/packages/opencode/src/tool/truncate.ts +144 -0
  278. package/packages/opencode/src/tool/truncation-dir.ts +4 -0
  279. package/packages/opencode/src/tool/webfetch.ts +206 -0
  280. package/packages/opencode/src/tool/webfetch.txt +13 -0
  281. package/packages/opencode/src/tool/websearch.ts +150 -0
  282. package/packages/opencode/src/tool/websearch.txt +14 -0
  283. package/packages/opencode/src/tool/write.ts +84 -0
  284. package/packages/opencode/src/tool/write.txt +8 -0
  285. package/packages/opencode/src/util/abort.ts +35 -0
  286. package/packages/opencode/src/util/archive.ts +17 -0
  287. package/packages/opencode/src/util/color.ts +19 -0
  288. package/packages/opencode/src/util/context.ts +25 -0
  289. package/packages/opencode/src/util/data-url.ts +9 -0
  290. package/packages/opencode/src/util/defer.ts +12 -0
  291. package/packages/opencode/src/util/effect-http-client.ts +11 -0
  292. package/packages/opencode/src/util/effect-zod.ts +98 -0
  293. package/packages/opencode/src/util/error.ts +77 -0
  294. package/packages/opencode/src/util/filesystem.ts +245 -0
  295. package/packages/opencode/src/util/flock.ts +333 -0
  296. package/packages/opencode/src/util/fn.ts +21 -0
  297. package/packages/opencode/src/util/format.ts +20 -0
  298. package/packages/opencode/src/util/glob.ts +34 -0
  299. package/packages/opencode/src/util/hash.ts +7 -0
  300. package/packages/opencode/src/util/iife.ts +3 -0
  301. package/packages/opencode/src/util/keybind.ts +103 -0
  302. package/packages/opencode/src/util/lazy.ts +23 -0
  303. package/packages/opencode/src/util/locale.ts +81 -0
  304. package/packages/opencode/src/util/lock.ts +98 -0
  305. package/packages/opencode/src/util/log.ts +182 -0
  306. package/packages/opencode/src/util/network.ts +9 -0
  307. package/packages/opencode/src/util/process.ts +176 -0
  308. package/packages/opencode/src/util/queue.ts +32 -0
  309. package/packages/opencode/src/util/record.ts +3 -0
  310. package/packages/opencode/src/util/rpc.ts +66 -0
  311. package/packages/opencode/src/util/schema.ts +53 -0
  312. package/packages/opencode/src/util/scrap.ts +10 -0
  313. package/packages/opencode/src/util/signal.ts +12 -0
  314. package/packages/opencode/src/util/timeout.ts +14 -0
  315. package/packages/opencode/src/util/token.ts +7 -0
  316. package/packages/opencode/src/util/update-schema.ts +13 -0
  317. package/packages/opencode/src/util/which.ts +14 -0
  318. package/packages/opencode/src/util/wildcard.ts +59 -0
  319. package/packages/opencode/src/worktree/index.ts +612 -0
  320. package/packages/plugin/package.json +38 -0
  321. package/packages/plugin/src/example.ts +18 -0
  322. package/packages/plugin/src/index.ts +282 -0
  323. package/packages/plugin/src/shell.ts +136 -0
  324. package/packages/plugin/src/tool.ts +38 -0
  325. package/packages/plugin/src/tui.ts +508 -0
  326. package/packages/script/package.json +16 -0
  327. package/packages/script/src/index.ts +77 -0
  328. package/packages/sdk/package.json +33 -0
  329. package/packages/sdk/src/client.ts +55 -0
  330. package/packages/sdk/src/gen/client/client.gen.ts +212 -0
  331. package/packages/sdk/src/gen/client/index.ts +25 -0
  332. package/packages/sdk/src/gen/client/types.gen.ts +222 -0
  333. package/packages/sdk/src/gen/client/utils.gen.ts +287 -0
  334. package/packages/sdk/src/gen/client.gen.ts +22 -0
  335. package/packages/sdk/src/gen/core/auth.gen.ts +41 -0
  336. package/packages/sdk/src/gen/core/bodySerializer.gen.ts +74 -0
  337. package/packages/sdk/src/gen/core/params.gen.ts +144 -0
  338. package/packages/sdk/src/gen/core/pathSerializer.gen.ts +167 -0
  339. package/packages/sdk/src/gen/core/queryKeySerializer.gen.ts +111 -0
  340. package/packages/sdk/src/gen/core/serverSentEvents.gen.ts +210 -0
  341. package/packages/sdk/src/gen/core/types.gen.ts +91 -0
  342. package/packages/sdk/src/gen/core/utils.gen.ts +109 -0
  343. package/packages/sdk/src/gen/sdk.gen.ts +1197 -0
  344. package/packages/sdk/src/gen/types.gen.ts +3904 -0
  345. package/packages/sdk/src/index.ts +21 -0
  346. package/packages/sdk/src/process.ts +31 -0
  347. package/packages/sdk/src/server.ts +134 -0
  348. package/packages/sdk/src/v2/client.ts +81 -0
  349. package/packages/sdk/src/v2/gen/client/client.gen.ts +285 -0
  350. package/packages/sdk/src/v2/gen/client/index.ts +25 -0
  351. package/packages/sdk/src/v2/gen/client/types.gen.ts +202 -0
  352. package/packages/sdk/src/v2/gen/client/utils.gen.ts +289 -0
  353. package/packages/sdk/src/v2/gen/client.gen.ts +18 -0
  354. package/packages/sdk/src/v2/gen/core/auth.gen.ts +41 -0
  355. package/packages/sdk/src/v2/gen/core/bodySerializer.gen.ts +82 -0
  356. package/packages/sdk/src/v2/gen/core/params.gen.ts +169 -0
  357. package/packages/sdk/src/v2/gen/core/pathSerializer.gen.ts +167 -0
  358. package/packages/sdk/src/v2/gen/core/queryKeySerializer.gen.ts +111 -0
  359. package/packages/sdk/src/v2/gen/core/serverSentEvents.gen.ts +239 -0
  360. package/packages/sdk/src/v2/gen/core/types.gen.ts +86 -0
  361. package/packages/sdk/src/v2/gen/core/utils.gen.ts +137 -0
  362. package/packages/sdk/src/v2/gen/sdk.gen.ts +4223 -0
  363. package/packages/sdk/src/v2/gen/types.gen.ts +5265 -0
  364. package/packages/sdk/src/v2/index.ts +21 -0
  365. package/packages/sdk/src/v2/server.ts +134 -0
  366. package/packages/util/package.json +20 -0
  367. package/packages/util/src/array.ts +10 -0
  368. package/packages/util/src/binary.ts +41 -0
  369. package/packages/util/src/encode.ts +51 -0
  370. package/packages/util/src/error.ts +54 -0
  371. package/packages/util/src/fn.ts +11 -0
  372. package/packages/util/src/identifier.ts +48 -0
  373. package/packages/util/src/iife.ts +3 -0
  374. package/packages/util/src/lazy.ts +11 -0
  375. package/packages/util/src/module.ts +10 -0
  376. package/packages/util/src/path.ts +37 -0
  377. package/packages/util/src/retry.ts +41 -0
  378. package/packages/util/src/slug.ts +74 -0
  379. package/postinstall.cjs +55 -0
@@ -0,0 +1,439 @@
1
+ import path from "path"
2
+ import {
3
+ type ParseError as JsoncParseError,
4
+ applyEdits,
5
+ modify,
6
+ parse as parseJsonc,
7
+ printParseErrorCode,
8
+ } from "jsonc-parser"
9
+
10
+ import { ConfigPaths } from "@/config/paths"
11
+ import { Global } from "@/global"
12
+ import { Filesystem } from "@/util/filesystem"
13
+ import { Flock } from "@/util/flock"
14
+ import { isRecord } from "@/util/record"
15
+
16
+ import { parsePluginSpecifier, readPackageThemes, readPluginPackage, resolvePluginTarget } from "./shared"
17
+
18
+ type Mode = "noop" | "add" | "replace"
19
+ type Kind = "server" | "tui"
20
+
21
+ export type Target = {
22
+ kind: Kind
23
+ opts?: Record<string, unknown>
24
+ }
25
+
26
+ export type InstallDeps = {
27
+ resolve: (spec: string) => Promise<string>
28
+ }
29
+
30
+ export type PatchDeps = {
31
+ readText: (file: string) => Promise<string>
32
+ write: (file: string, text: string) => Promise<void>
33
+ exists: (file: string) => Promise<boolean>
34
+ files: (dir: string, name: "opencode" | "tui") => string[]
35
+ }
36
+
37
+ export type PatchInput = {
38
+ spec: string
39
+ targets: Target[]
40
+ force?: boolean
41
+ global?: boolean
42
+ vcs?: string
43
+ worktree: string
44
+ directory: string
45
+ config?: string
46
+ }
47
+
48
+ type Ok<T> = {
49
+ ok: true
50
+ } & T
51
+
52
+ type Err<C extends string, T> = {
53
+ ok: false
54
+ code: C
55
+ } & T
56
+
57
+ export type InstallResult = Ok<{ target: string }> | Err<"install_failed", { error: unknown }>
58
+
59
+ export type ManifestResult =
60
+ | Ok<{ targets: Target[] }>
61
+ | Err<"manifest_read_failed", { file: string; error: unknown }>
62
+ | Err<"manifest_no_targets", { file: string }>
63
+
64
+ export type PatchItem = {
65
+ kind: Kind
66
+ mode: Mode
67
+ file: string
68
+ }
69
+
70
+ type PatchErr =
71
+ | Err<"invalid_json", { kind: Kind; file: string; line: number; col: number; parse: string }>
72
+ | Err<"patch_failed", { kind: Kind; error: unknown }>
73
+
74
+ type PatchOne = Ok<{ item: PatchItem }> | PatchErr
75
+
76
+ export type PatchResult = Ok<{ dir: string; items: PatchItem[] }> | (PatchErr & { dir: string })
77
+
78
+ const defaultInstallDeps: InstallDeps = {
79
+ resolve: (spec) => resolvePluginTarget(spec),
80
+ }
81
+
82
+ const defaultPatchDeps: PatchDeps = {
83
+ readText: (file) => Filesystem.readText(file),
84
+ write: async (file, text) => {
85
+ await Filesystem.write(file, text)
86
+ },
87
+ exists: (file) => Filesystem.exists(file),
88
+ files: (dir, name) => ConfigPaths.fileInDirectory(dir, name),
89
+ }
90
+
91
+ function pluginSpec(item: unknown) {
92
+ if (typeof item === "string") return item
93
+ if (!Array.isArray(item)) return
94
+ if (typeof item[0] !== "string") return
95
+ return item[0]
96
+ }
97
+
98
+ function pluginList(data: unknown) {
99
+ if (!data || typeof data !== "object" || Array.isArray(data)) return
100
+ const item = data as { plugin?: unknown }
101
+ if (!Array.isArray(item.plugin)) return
102
+ return item.plugin
103
+ }
104
+
105
+ function exportValue(value: unknown): string | undefined {
106
+ if (typeof value === "string") {
107
+ const next = value.trim()
108
+ if (next) return next
109
+ return
110
+ }
111
+ if (!isRecord(value)) return
112
+ for (const key of ["import", "default"]) {
113
+ const next = value[key]
114
+ if (typeof next !== "string") continue
115
+ const hit = next.trim()
116
+ if (!hit) continue
117
+ return hit
118
+ }
119
+ }
120
+
121
+ function exportOptions(value: unknown): Record<string, unknown> | undefined {
122
+ if (!isRecord(value)) return
123
+ const config = value.config
124
+ if (!isRecord(config)) return
125
+ return config
126
+ }
127
+
128
+ function exportTarget(pkg: Record<string, unknown>, kind: Kind) {
129
+ const exports = pkg.exports
130
+ if (!isRecord(exports)) return
131
+ const value = exports[`./${kind}`]
132
+ const entry = exportValue(value)
133
+ if (!entry) return
134
+ return {
135
+ opts: exportOptions(value),
136
+ }
137
+ }
138
+
139
+ function hasMainTarget(pkg: Record<string, unknown>) {
140
+ const main = pkg.main
141
+ if (typeof main !== "string") return false
142
+ return Boolean(main.trim())
143
+ }
144
+
145
+ function packageTargets(pkg: { json: Record<string, unknown>; dir: string; pkg: string }) {
146
+ const spec =
147
+ typeof pkg.json.name === "string" && pkg.json.name.trim().length > 0 ? pkg.json.name.trim() : path.basename(pkg.dir)
148
+ const targets: Target[] = []
149
+ const server = exportTarget(pkg.json, "server")
150
+ if (server) {
151
+ targets.push({ kind: "server", opts: server.opts })
152
+ } else if (hasMainTarget(pkg.json)) {
153
+ targets.push({ kind: "server" })
154
+ }
155
+
156
+ const tui = exportTarget(pkg.json, "tui")
157
+ if (tui) {
158
+ targets.push({ kind: "tui", opts: tui.opts })
159
+ }
160
+
161
+ if (!targets.some((item) => item.kind === "tui") && readPackageThemes(spec, pkg).length) {
162
+ targets.push({ kind: "tui" })
163
+ }
164
+
165
+ return targets
166
+ }
167
+
168
+ function patch(text: string, path: Array<string | number>, value: unknown, insert = false) {
169
+ return applyEdits(
170
+ text,
171
+ modify(text, path, value, {
172
+ formattingOptions: {
173
+ tabSize: 2,
174
+ insertSpaces: true,
175
+ },
176
+ isArrayInsertion: insert,
177
+ }),
178
+ )
179
+ }
180
+
181
+ function patchPluginList(
182
+ text: string,
183
+ list: unknown[] | undefined,
184
+ spec: string,
185
+ next: unknown,
186
+ force = false,
187
+ ): { mode: Mode; text: string } {
188
+ const pkg = parsePluginSpecifier(spec).pkg
189
+ const rows = (list ?? []).map((item, i) => ({
190
+ item,
191
+ i,
192
+ spec: pluginSpec(item),
193
+ }))
194
+ const dup = rows.filter((item) => {
195
+ if (!item.spec) return false
196
+ if (item.spec === spec) return true
197
+ if (item.spec.startsWith("file://")) return false
198
+ return parsePluginSpecifier(item.spec).pkg === pkg
199
+ })
200
+
201
+ if (!dup.length) {
202
+ if (!list) {
203
+ return {
204
+ mode: "add",
205
+ text: patch(text, ["plugin"], [next]),
206
+ }
207
+ }
208
+ return {
209
+ mode: "add",
210
+ text: patch(text, ["plugin", list.length], next, true),
211
+ }
212
+ }
213
+
214
+ if (!force) {
215
+ return {
216
+ mode: "noop",
217
+ text,
218
+ }
219
+ }
220
+
221
+ const keep = dup[0]
222
+ if (!keep) {
223
+ return {
224
+ mode: "noop",
225
+ text,
226
+ }
227
+ }
228
+
229
+ if (dup.length === 1 && keep.spec === spec) {
230
+ return {
231
+ mode: "noop",
232
+ text,
233
+ }
234
+ }
235
+
236
+ let out = text
237
+ if (typeof keep.item === "string") {
238
+ out = patch(out, ["plugin", keep.i], next)
239
+ }
240
+ if (Array.isArray(keep.item) && typeof keep.item[0] === "string") {
241
+ out = patch(out, ["plugin", keep.i, 0], spec)
242
+ }
243
+
244
+ const del = dup
245
+ .map((item) => item.i)
246
+ .filter((i) => i !== keep.i)
247
+ .sort((a, b) => b - a)
248
+
249
+ for (const i of del) {
250
+ out = patch(out, ["plugin", i], undefined)
251
+ }
252
+
253
+ return {
254
+ mode: "replace",
255
+ text: out,
256
+ }
257
+ }
258
+
259
+ export async function installPlugin(spec: string, dep: InstallDeps = defaultInstallDeps): Promise<InstallResult> {
260
+ const target = await dep.resolve(spec).then(
261
+ (item) => ({
262
+ ok: true as const,
263
+ item,
264
+ }),
265
+ (error: unknown) => ({
266
+ ok: false as const,
267
+ error,
268
+ }),
269
+ )
270
+ if (!target.ok) {
271
+ return {
272
+ ok: false,
273
+ code: "install_failed",
274
+ error: target.error,
275
+ }
276
+ }
277
+ return {
278
+ ok: true,
279
+ target: target.item,
280
+ }
281
+ }
282
+
283
+ export async function readPluginManifest(target: string): Promise<ManifestResult> {
284
+ const pkg = await readPluginPackage(target).then(
285
+ (item) => ({
286
+ ok: true as const,
287
+ item,
288
+ }),
289
+ (error: unknown) => ({
290
+ ok: false as const,
291
+ error,
292
+ }),
293
+ )
294
+ if (!pkg.ok) {
295
+ return {
296
+ ok: false,
297
+ code: "manifest_read_failed",
298
+ file: target,
299
+ error: pkg.error,
300
+ }
301
+ }
302
+
303
+ const targets = await Promise.resolve()
304
+ .then(() => packageTargets(pkg.item))
305
+ .then(
306
+ (item) => ({ ok: true as const, item }),
307
+ (error: unknown) => ({ ok: false as const, error }),
308
+ )
309
+
310
+ if (!targets.ok) {
311
+ return {
312
+ ok: false,
313
+ code: "manifest_read_failed",
314
+ file: pkg.item.pkg,
315
+ error: targets.error,
316
+ }
317
+ }
318
+
319
+ if (!targets.item.length) {
320
+ return {
321
+ ok: false,
322
+ code: "manifest_no_targets",
323
+ file: pkg.item.pkg,
324
+ }
325
+ }
326
+
327
+ return {
328
+ ok: true,
329
+ targets: targets.item,
330
+ }
331
+ }
332
+
333
+ function patchDir(input: PatchInput) {
334
+ if (input.global) return input.config ?? Global.Path.config
335
+ const git = input.vcs === "git" && input.worktree !== "/"
336
+ const root = git ? input.worktree : input.directory
337
+ return path.join(root, ".opencode")
338
+ }
339
+
340
+ function patchName(kind: Kind): "opencode" | "tui" {
341
+ if (kind === "server") return "opencode"
342
+ return "tui"
343
+ }
344
+
345
+ async function patchOne(dir: string, target: Target, spec: string, force: boolean, dep: PatchDeps): Promise<PatchOne> {
346
+ const name = patchName(target.kind)
347
+ await using _ = await Flock.acquire(`plug-config:${Filesystem.resolve(path.join(dir, name))}`)
348
+
349
+ const files = dep.files(dir, name)
350
+ let cfg = files[0]
351
+ for (const file of files) {
352
+ if (!(await dep.exists(file))) continue
353
+ cfg = file
354
+ break
355
+ }
356
+
357
+ const src = await dep.readText(cfg).catch((err: NodeJS.ErrnoException) => {
358
+ if (err.code === "ENOENT") return "{}"
359
+ return err
360
+ })
361
+ if (src instanceof Error) {
362
+ return {
363
+ ok: false,
364
+ code: "patch_failed",
365
+ kind: target.kind,
366
+ error: src,
367
+ }
368
+ }
369
+ const text = src.trim() ? src : "{}"
370
+
371
+ const errs: JsoncParseError[] = []
372
+ const data = parseJsonc(text, errs, { allowTrailingComma: true })
373
+ if (errs.length) {
374
+ const err = errs[0]
375
+ const lines = text.substring(0, err.offset).split("\n")
376
+ return {
377
+ ok: false,
378
+ code: "invalid_json",
379
+ kind: target.kind,
380
+ file: cfg,
381
+ line: lines.length,
382
+ col: lines[lines.length - 1].length + 1,
383
+ parse: printParseErrorCode(err.error),
384
+ }
385
+ }
386
+
387
+ const list = pluginList(data)
388
+ const item = target.opts ? ([spec, target.opts] as const) : spec
389
+ const out = patchPluginList(text, list, spec, item, force)
390
+ if (out.mode === "noop") {
391
+ return {
392
+ ok: true,
393
+ item: {
394
+ kind: target.kind,
395
+ mode: out.mode,
396
+ file: cfg,
397
+ },
398
+ }
399
+ }
400
+
401
+ const write = await dep.write(cfg, out.text).catch((error: unknown) => error)
402
+ if (write instanceof Error) {
403
+ return {
404
+ ok: false,
405
+ code: "patch_failed",
406
+ kind: target.kind,
407
+ error: write,
408
+ }
409
+ }
410
+
411
+ return {
412
+ ok: true,
413
+ item: {
414
+ kind: target.kind,
415
+ mode: out.mode,
416
+ file: cfg,
417
+ },
418
+ }
419
+ }
420
+
421
+ export async function patchPluginConfig(input: PatchInput, dep: PatchDeps = defaultPatchDeps): Promise<PatchResult> {
422
+ const dir = patchDir(input)
423
+ const items: PatchItem[] = []
424
+ for (const target of input.targets) {
425
+ const hit = await patchOne(dir, target, input.spec, Boolean(input.force), dep)
426
+ if (!hit.ok) {
427
+ return {
428
+ ...hit,
429
+ dir,
430
+ }
431
+ }
432
+ items.push(hit.item)
433
+ }
434
+ return {
435
+ ok: true,
436
+ dir,
437
+ items,
438
+ }
439
+ }
@@ -0,0 +1,174 @@
1
+ import { Config } from "@/config/config"
2
+ import { Installation } from "@/installation"
3
+ import {
4
+ checkPluginCompatibility,
5
+ createPluginEntry,
6
+ isDeprecatedPlugin,
7
+ pluginSource,
8
+ resolvePluginTarget,
9
+ type PluginKind,
10
+ type PluginPackage,
11
+ type PluginSource,
12
+ } from "./shared"
13
+
14
+ export namespace PluginLoader {
15
+ export type Plan = {
16
+ spec: string
17
+ options: Config.PluginOptions | undefined
18
+ deprecated: boolean
19
+ }
20
+ export type Resolved = Plan & {
21
+ source: PluginSource
22
+ target: string
23
+ entry: string
24
+ pkg?: PluginPackage
25
+ }
26
+ export type Missing = Plan & {
27
+ source: PluginSource
28
+ target: string
29
+ pkg?: PluginPackage
30
+ message: string
31
+ }
32
+ export type Loaded = Resolved & {
33
+ mod: Record<string, unknown>
34
+ }
35
+
36
+ type Candidate = { origin: Config.PluginOrigin; plan: Plan }
37
+ type Report = {
38
+ start?: (candidate: Candidate, retry: boolean) => void
39
+ missing?: (candidate: Candidate, retry: boolean, message: string, resolved: Missing) => void
40
+ error?: (
41
+ candidate: Candidate,
42
+ retry: boolean,
43
+ stage: "install" | "entry" | "compatibility" | "load",
44
+ error: unknown,
45
+ resolved?: Resolved,
46
+ ) => void
47
+ }
48
+
49
+ function plan(item: Config.PluginSpec): Plan {
50
+ const spec = Config.pluginSpecifier(item)
51
+ return { spec, options: Config.pluginOptions(item), deprecated: isDeprecatedPlugin(spec) }
52
+ }
53
+
54
+ export async function resolve(
55
+ plan: Plan,
56
+ kind: PluginKind,
57
+ ): Promise<
58
+ | { ok: true; value: Resolved }
59
+ | { ok: false; stage: "missing"; value: Missing }
60
+ | { ok: false; stage: "install" | "entry" | "compatibility"; error: unknown }
61
+ > {
62
+ let target = ""
63
+ try {
64
+ target = await resolvePluginTarget(plan.spec)
65
+ } catch (error) {
66
+ return { ok: false, stage: "install", error }
67
+ }
68
+ if (!target) return { ok: false, stage: "install", error: new Error(`Plugin ${plan.spec} target is empty`) }
69
+
70
+ let base
71
+ try {
72
+ base = await createPluginEntry(plan.spec, target, kind)
73
+ } catch (error) {
74
+ return { ok: false, stage: "entry", error }
75
+ }
76
+ if (!base.entry)
77
+ return {
78
+ ok: false,
79
+ stage: "missing",
80
+ value: {
81
+ ...plan,
82
+ source: base.source,
83
+ target: base.target,
84
+ pkg: base.pkg,
85
+ message: `Plugin ${plan.spec} does not expose a ${kind} entrypoint`,
86
+ },
87
+ }
88
+
89
+ if (base.source === "npm") {
90
+ try {
91
+ await checkPluginCompatibility(base.target, Installation.VERSION, base.pkg)
92
+ } catch (error) {
93
+ return { ok: false, stage: "compatibility", error }
94
+ }
95
+ }
96
+ return { ok: true, value: { ...plan, source: base.source, target: base.target, entry: base.entry, pkg: base.pkg } }
97
+ }
98
+
99
+ export async function load(row: Resolved): Promise<{ ok: true; value: Loaded } | { ok: false; error: unknown }> {
100
+ let mod
101
+ try {
102
+ mod = await import(row.entry)
103
+ } catch (error) {
104
+ return { ok: false, error }
105
+ }
106
+ if (!mod) return { ok: false, error: new Error(`Plugin ${row.spec} module is empty`) }
107
+ return { ok: true, value: { ...row, mod } }
108
+ }
109
+
110
+ async function attempt<R>(
111
+ candidate: Candidate,
112
+ kind: PluginKind,
113
+ retry: boolean,
114
+ finish: ((load: Loaded, origin: Config.PluginOrigin, retry: boolean) => Promise<R | undefined>) | undefined,
115
+ missing: ((value: Missing, origin: Config.PluginOrigin, retry: boolean) => Promise<R | undefined>) | undefined,
116
+ report: Report | undefined,
117
+ ): Promise<R | undefined> {
118
+ const plan = candidate.plan
119
+ if (plan.deprecated) return
120
+ report?.start?.(candidate, retry)
121
+ const resolved = await resolve(plan, kind)
122
+ if (!resolved.ok) {
123
+ if (resolved.stage === "missing") {
124
+ if (missing) {
125
+ const value = await missing(resolved.value, candidate.origin, retry)
126
+ if (value !== undefined) return value
127
+ }
128
+ report?.missing?.(candidate, retry, resolved.value.message, resolved.value)
129
+ return
130
+ }
131
+ report?.error?.(candidate, retry, resolved.stage, resolved.error)
132
+ return
133
+ }
134
+ const loaded = await load(resolved.value)
135
+ if (!loaded.ok) {
136
+ report?.error?.(candidate, retry, "load", loaded.error, resolved.value)
137
+ return
138
+ }
139
+ if (!finish) return loaded.value as R
140
+ return finish(loaded.value, candidate.origin, retry)
141
+ }
142
+
143
+ type Input<R> = {
144
+ items: Config.PluginOrigin[]
145
+ kind: PluginKind
146
+ wait?: () => Promise<void>
147
+ finish?: (load: Loaded, origin: Config.PluginOrigin, retry: boolean) => Promise<R | undefined>
148
+ missing?: (value: Missing, origin: Config.PluginOrigin, retry: boolean) => Promise<R | undefined>
149
+ report?: Report
150
+ }
151
+
152
+ export async function loadExternal<R = Loaded>(input: Input<R>): Promise<R[]> {
153
+ const candidates = input.items.map((origin) => ({ origin, plan: plan(origin.spec) }))
154
+ const list: Array<Promise<R | undefined>> = []
155
+ for (const candidate of candidates) {
156
+ list.push(attempt(candidate, input.kind, false, input.finish, input.missing, input.report))
157
+ }
158
+ const out = await Promise.all(list)
159
+ if (input.wait) {
160
+ let deps: Promise<void> | undefined
161
+ for (let i = 0; i < candidates.length; i++) {
162
+ if (out[i] !== undefined) continue
163
+ const candidate = candidates[i]
164
+ if (!candidate || pluginSource(candidate.plan.spec) !== "file") continue
165
+ deps ??= input.wait()
166
+ await deps
167
+ out[i] = await attempt(candidate, input.kind, true, input.finish, input.missing, input.report)
168
+ }
169
+ }
170
+ const ready: R[] = []
171
+ for (const item of out) if (item !== undefined) ready.push(item)
172
+ return ready
173
+ }
174
+ }