alchemylab-opencode 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (413) hide show
  1. package/dist/arktype-aI7TBD0R-HX4BR3RX.js +21 -0
  2. package/dist/arktype-aI7TBD0R-HX4BR3RX.js.map +7 -0
  3. package/dist/{chunk-UWZSRZHA.js → chunk-23UYOGZG.js} +817 -315
  4. package/dist/chunk-23UYOGZG.js.map +7 -0
  5. package/dist/chunk-3AF5MXLF.js +49 -0
  6. package/dist/chunk-3AF5MXLF.js.map +7 -0
  7. package/dist/chunk-FMP3YLWX.js +30 -0
  8. package/dist/chunk-FMP3YLWX.js.map +7 -0
  9. package/dist/{chunk-ANDTK76Q.js → chunk-GSE2T5UY.js} +3 -3
  10. package/dist/{chunk-CYXMV3J3.js → chunk-LU5XVQUD.js} +4 -4
  11. package/dist/chunk-O5VWOPCL.js +106 -0
  12. package/dist/chunk-O5VWOPCL.js.map +7 -0
  13. package/dist/chunk-PWFRMDDF.js +12 -0
  14. package/dist/{chunk-DSPC5QIG.js → chunk-SM6WZDN6.js} +9 -9
  15. package/dist/{chunk-MCWTARFP.js → chunk-TASPMBUL.js} +4 -4
  16. package/dist/chunk-VL3RSEZ2.js +160 -0
  17. package/dist/chunk-VL3RSEZ2.js.map +7 -0
  18. package/dist/default-u_dwuiYb-WOFHQQ3K.js +22 -0
  19. package/dist/effect-QlVUlMFu-UERLUUQW.js +29 -0
  20. package/dist/effect-QlVUlMFu-UERLUUQW.js.map +7 -0
  21. package/dist/{mcp-VAU4RMWH.js → mcp-XFGN3FWW.js} +2 -2
  22. package/dist/{registry-PYMN6L3G.js → registry-W4MBVBYD.js} +3 -3
  23. package/dist/{run-YFVCQJQM.js → run-73HUV4H3.js} +9 -6
  24. package/dist/{run-YFVCQJQM.js.map → run-73HUV4H3.js.map} +1 -1
  25. package/dist/run.js +1 -1
  26. package/dist/serve.js +1 -1
  27. package/dist/{server-K3UGWASP.js → server-2CPOG3LS.js} +9 -6
  28. package/dist/{session-HJFWTM7C.js → session-M6HOZ56B.js} +3 -3
  29. package/dist/session-M6HOZ56B.js.map +7 -0
  30. package/dist/{share-next-55VCIMUH.js → share-next-QRBVSD37.js} +4 -4
  31. package/dist/share-next-QRBVSD37.js.map +7 -0
  32. package/dist/sury-CWZTCd75-XC3NCMTP.js +29 -0
  33. package/dist/sury-CWZTCd75-XC3NCMTP.js.map +7 -0
  34. package/dist/typebox-Dei93FPO-QOBKW4L7.js +21 -0
  35. package/dist/typebox-Dei93FPO-QOBKW4L7.js.map +7 -0
  36. package/dist/valibot--1zFm7rT-LHHLSLYY.js +29 -0
  37. package/dist/valibot--1zFm7rT-LHHLSLYY.js.map +7 -0
  38. package/dist/valibot-D_HTw1Gn-UR62BIDY.js +60 -0
  39. package/dist/valibot-D_HTw1Gn-UR62BIDY.js.map +7 -0
  40. package/dist/{worktree-6GGDLADY.js → worktree-3GUHT2P7.js} +5 -5
  41. package/dist/zod-Bwrt9trS-J2GOMA2R.js +43 -0
  42. package/dist/zod-Bwrt9trS-J2GOMA2R.js.map +7 -0
  43. package/dist/zod-DSgpEGAE-VTXQW6SB.js +56 -0
  44. package/dist/zod-DSgpEGAE-VTXQW6SB.js.map +7 -0
  45. package/package.json +2 -15
  46. package/build.mjs +0 -182
  47. package/dist/chunk-UWZSRZHA.js.map +0 -7
  48. package/packages/opencode/package.json +0 -138
  49. package/packages/opencode/src/account/account.sql.ts +0 -39
  50. package/packages/opencode/src/account/index.ts +0 -463
  51. package/packages/opencode/src/account/repo.ts +0 -163
  52. package/packages/opencode/src/account/schema.ts +0 -91
  53. package/packages/opencode/src/acp/README.md +0 -174
  54. package/packages/opencode/src/acp/agent.ts +0 -1847
  55. package/packages/opencode/src/acp/session.ts +0 -116
  56. package/packages/opencode/src/acp/types.ts +0 -24
  57. package/packages/opencode/src/agent/agent.ts +0 -420
  58. package/packages/opencode/src/agent/generate.txt +0 -75
  59. package/packages/opencode/src/agent/prompt/compaction.txt +0 -15
  60. package/packages/opencode/src/agent/prompt/explore.txt +0 -18
  61. package/packages/opencode/src/agent/prompt/summary.txt +0 -11
  62. package/packages/opencode/src/agent/prompt/title.txt +0 -44
  63. package/packages/opencode/src/auth/index.ts +0 -110
  64. package/packages/opencode/src/bus/bus-event.ts +0 -40
  65. package/packages/opencode/src/bus/global.ts +0 -10
  66. package/packages/opencode/src/bus/index.ts +0 -185
  67. package/packages/opencode/src/cli/bootstrap.ts +0 -17
  68. package/packages/opencode/src/cli/cmd/cmd.ts +0 -7
  69. package/packages/opencode/src/cli/cmd/run.ts +0 -689
  70. package/packages/opencode/src/cli/cmd/serve.ts +0 -24
  71. package/packages/opencode/src/cli/cmd/tui/event.ts +0 -49
  72. package/packages/opencode/src/cli/effect/prompt.ts +0 -25
  73. package/packages/opencode/src/cli/error.ts +0 -46
  74. package/packages/opencode/src/cli/heap.ts +0 -59
  75. package/packages/opencode/src/cli/logo.ts +0 -6
  76. package/packages/opencode/src/cli/network.ts +0 -60
  77. package/packages/opencode/src/cli/ui.ts +0 -133
  78. package/packages/opencode/src/cli/upgrade.ts +0 -31
  79. package/packages/opencode/src/command/index.ts +0 -195
  80. package/packages/opencode/src/command/template/initialize.txt +0 -66
  81. package/packages/opencode/src/command/template/review.txt +0 -101
  82. package/packages/opencode/src/config/config.ts +0 -1599
  83. package/packages/opencode/src/config/console-state.ts +0 -15
  84. package/packages/opencode/src/config/markdown.ts +0 -99
  85. package/packages/opencode/src/config/paths.ts +0 -167
  86. package/packages/opencode/src/config/tui-migrate.ts +0 -155
  87. package/packages/opencode/src/config/tui-schema.ts +0 -37
  88. package/packages/opencode/src/config/tui.ts +0 -179
  89. package/packages/opencode/src/control-plane/adaptors/index.ts +0 -20
  90. package/packages/opencode/src/control-plane/adaptors/worktree.ts +0 -42
  91. package/packages/opencode/src/control-plane/schema.ts +0 -17
  92. package/packages/opencode/src/control-plane/sse.ts +0 -66
  93. package/packages/opencode/src/control-plane/types.ts +0 -32
  94. package/packages/opencode/src/control-plane/workspace.sql.ts +0 -17
  95. package/packages/opencode/src/control-plane/workspace.ts +0 -168
  96. package/packages/opencode/src/effect/cross-spawn-spawner.ts +0 -502
  97. package/packages/opencode/src/effect/instance-ref.ts +0 -6
  98. package/packages/opencode/src/effect/instance-registry.ts +0 -12
  99. package/packages/opencode/src/effect/instance-state.ts +0 -82
  100. package/packages/opencode/src/effect/run-service.ts +0 -33
  101. package/packages/opencode/src/effect/runner.ts +0 -216
  102. package/packages/opencode/src/env/index.ts +0 -28
  103. package/packages/opencode/src/file/ignore.ts +0 -82
  104. package/packages/opencode/src/file/index.ts +0 -686
  105. package/packages/opencode/src/file/protected.ts +0 -59
  106. package/packages/opencode/src/file/ripgrep.ts +0 -376
  107. package/packages/opencode/src/file/time.ts +0 -133
  108. package/packages/opencode/src/file/watcher.ts +0 -173
  109. package/packages/opencode/src/filesystem/index.ts +0 -236
  110. package/packages/opencode/src/flag/flag.ts +0 -156
  111. package/packages/opencode/src/format/formatter.ts +0 -413
  112. package/packages/opencode/src/format/index.ts +0 -203
  113. package/packages/opencode/src/git/index.ts +0 -303
  114. package/packages/opencode/src/global/index.ts +0 -56
  115. package/packages/opencode/src/id/id.ts +0 -85
  116. package/packages/opencode/src/ide/index.ts +0 -74
  117. package/packages/opencode/src/installation/index.ts +0 -355
  118. package/packages/opencode/src/installation/meta.ts +0 -7
  119. package/packages/opencode/src/lsp/client.ts +0 -252
  120. package/packages/opencode/src/lsp/index.ts +0 -558
  121. package/packages/opencode/src/lsp/language.ts +0 -120
  122. package/packages/opencode/src/lsp/launch.ts +0 -21
  123. package/packages/opencode/src/lsp/server.ts +0 -1968
  124. package/packages/opencode/src/mcp/auth.ts +0 -173
  125. package/packages/opencode/src/mcp/index.ts +0 -931
  126. package/packages/opencode/src/mcp/oauth-callback.ts +0 -216
  127. package/packages/opencode/src/mcp/oauth-provider.ts +0 -185
  128. package/packages/opencode/src/node-loader.mjs +0 -104
  129. package/packages/opencode/src/node-preload.mjs +0 -39
  130. package/packages/opencode/src/node.ts +0 -1
  131. package/packages/opencode/src/npm/index.ts +0 -188
  132. package/packages/opencode/src/patch/index.ts +0 -680
  133. package/packages/opencode/src/permission/arity.ts +0 -163
  134. package/packages/opencode/src/permission/evaluate.ts +0 -15
  135. package/packages/opencode/src/permission/index.ts +0 -325
  136. package/packages/opencode/src/permission/schema.ts +0 -17
  137. package/packages/opencode/src/plugin/cloudflare.ts +0 -67
  138. package/packages/opencode/src/plugin/codex.ts +0 -608
  139. package/packages/opencode/src/plugin/github-copilot/copilot.ts +0 -361
  140. package/packages/opencode/src/plugin/github-copilot/models.ts +0 -144
  141. package/packages/opencode/src/plugin/index.ts +0 -299
  142. package/packages/opencode/src/plugin/install.ts +0 -439
  143. package/packages/opencode/src/plugin/loader.ts +0 -174
  144. package/packages/opencode/src/plugin/meta.ts +0 -188
  145. package/packages/opencode/src/plugin/shared.ts +0 -323
  146. package/packages/opencode/src/project/bootstrap.ts +0 -31
  147. package/packages/opencode/src/project/instance.ts +0 -175
  148. package/packages/opencode/src/project/project.sql.ts +0 -16
  149. package/packages/opencode/src/project/project.ts +0 -519
  150. package/packages/opencode/src/project/schema.ts +0 -16
  151. package/packages/opencode/src/project/state.ts +0 -70
  152. package/packages/opencode/src/project/vcs.ts +0 -240
  153. package/packages/opencode/src/provider/auth.ts +0 -253
  154. package/packages/opencode/src/provider/error.ts +0 -197
  155. package/packages/opencode/src/provider/models.ts +0 -162
  156. package/packages/opencode/src/provider/provider.ts +0 -1709
  157. package/packages/opencode/src/provider/schema.ts +0 -38
  158. package/packages/opencode/src/provider/sdk/copilot/README.md +0 -5
  159. package/packages/opencode/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +0 -170
  160. package/packages/opencode/src/provider/sdk/copilot/chat/get-response-metadata.ts +0 -15
  161. package/packages/opencode/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +0 -19
  162. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +0 -64
  163. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +0 -815
  164. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +0 -28
  165. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +0 -44
  166. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +0 -83
  167. package/packages/opencode/src/provider/sdk/copilot/copilot-provider.ts +0 -100
  168. package/packages/opencode/src/provider/sdk/copilot/index.ts +0 -2
  169. package/packages/opencode/src/provider/sdk/copilot/openai-compatible-error.ts +0 -27
  170. package/packages/opencode/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +0 -335
  171. package/packages/opencode/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +0 -22
  172. package/packages/opencode/src/provider/sdk/copilot/responses/openai-config.ts +0 -18
  173. package/packages/opencode/src/provider/sdk/copilot/responses/openai-error.ts +0 -22
  174. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +0 -214
  175. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +0 -1769
  176. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +0 -173
  177. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-settings.ts +0 -1
  178. package/packages/opencode/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +0 -87
  179. package/packages/opencode/src/provider/sdk/copilot/responses/tool/file-search.ts +0 -127
  180. package/packages/opencode/src/provider/sdk/copilot/responses/tool/image-generation.ts +0 -114
  181. package/packages/opencode/src/provider/sdk/copilot/responses/tool/local-shell.ts +0 -64
  182. package/packages/opencode/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +0 -103
  183. package/packages/opencode/src/provider/sdk/copilot/responses/tool/web-search.ts +0 -102
  184. package/packages/opencode/src/provider/transform.ts +0 -1050
  185. package/packages/opencode/src/pty/index.ts +0 -397
  186. package/packages/opencode/src/pty/pty.node.ts +0 -27
  187. package/packages/opencode/src/pty/pty.ts +0 -25
  188. package/packages/opencode/src/pty/schema.ts +0 -17
  189. package/packages/opencode/src/question/index.ts +0 -224
  190. package/packages/opencode/src/question/schema.ts +0 -17
  191. package/packages/opencode/src/run.ts +0 -28
  192. package/packages/opencode/src/serve.ts +0 -45
  193. package/packages/opencode/src/server/error.ts +0 -36
  194. package/packages/opencode/src/server/event.ts +0 -7
  195. package/packages/opencode/src/server/instance.ts +0 -324
  196. package/packages/opencode/src/server/mdns.ts +0 -60
  197. package/packages/opencode/src/server/middleware.ts +0 -33
  198. package/packages/opencode/src/server/projectors.ts +0 -28
  199. package/packages/opencode/src/server/proxy.ts +0 -131
  200. package/packages/opencode/src/server/router.ts +0 -105
  201. package/packages/opencode/src/server/routes/config.ts +0 -92
  202. package/packages/opencode/src/server/routes/event.ts +0 -83
  203. package/packages/opencode/src/server/routes/experimental.ts +0 -374
  204. package/packages/opencode/src/server/routes/file.ts +0 -197
  205. package/packages/opencode/src/server/routes/global.ts +0 -312
  206. package/packages/opencode/src/server/routes/mcp.ts +0 -225
  207. package/packages/opencode/src/server/routes/permission.ts +0 -69
  208. package/packages/opencode/src/server/routes/project.ts +0 -118
  209. package/packages/opencode/src/server/routes/provider.ts +0 -171
  210. package/packages/opencode/src/server/routes/pty.ts +0 -210
  211. package/packages/opencode/src/server/routes/question.ts +0 -99
  212. package/packages/opencode/src/server/routes/session.ts +0 -1030
  213. package/packages/opencode/src/server/routes/tui.ts +0 -379
  214. package/packages/opencode/src/server/routes/workspace.ts +0 -94
  215. package/packages/opencode/src/server/server.ts +0 -353
  216. package/packages/opencode/src/session/compaction.ts +0 -428
  217. package/packages/opencode/src/session/index.ts +0 -887
  218. package/packages/opencode/src/session/instruction.ts +0 -258
  219. package/packages/opencode/src/session/llm.ts +0 -354
  220. package/packages/opencode/src/session/message-v2.ts +0 -1031
  221. package/packages/opencode/src/session/message.ts +0 -191
  222. package/packages/opencode/src/session/overflow.ts +0 -22
  223. package/packages/opencode/src/session/processor.ts +0 -523
  224. package/packages/opencode/src/session/projectors.ts +0 -135
  225. package/packages/opencode/src/session/prompt/anthropic.txt +0 -105
  226. package/packages/opencode/src/session/prompt/beast.txt +0 -147
  227. package/packages/opencode/src/session/prompt/build-switch.txt +0 -5
  228. package/packages/opencode/src/session/prompt/codex.txt +0 -79
  229. package/packages/opencode/src/session/prompt/copilot-gpt-5.txt +0 -143
  230. package/packages/opencode/src/session/prompt/default.txt +0 -105
  231. package/packages/opencode/src/session/prompt/gemini.txt +0 -155
  232. package/packages/opencode/src/session/prompt/gpt.txt +0 -107
  233. package/packages/opencode/src/session/prompt/kimi.txt +0 -95
  234. package/packages/opencode/src/session/prompt/max-steps.txt +0 -16
  235. package/packages/opencode/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  236. package/packages/opencode/src/session/prompt/plan.txt +0 -26
  237. package/packages/opencode/src/session/prompt/trinity.txt +0 -97
  238. package/packages/opencode/src/session/prompt.ts +0 -1911
  239. package/packages/opencode/src/session/retry.ts +0 -106
  240. package/packages/opencode/src/session/revert.ts +0 -176
  241. package/packages/opencode/src/session/schema.ts +0 -38
  242. package/packages/opencode/src/session/session.sql.ts +0 -103
  243. package/packages/opencode/src/session/status.ts +0 -102
  244. package/packages/opencode/src/session/summary.ts +0 -177
  245. package/packages/opencode/src/session/system.ts +0 -76
  246. package/packages/opencode/src/session/todo.ts +0 -95
  247. package/packages/opencode/src/share/share-next.ts +0 -369
  248. package/packages/opencode/src/share/share.sql.ts +0 -13
  249. package/packages/opencode/src/shell/shell.ts +0 -110
  250. package/packages/opencode/src/skill/discovery.ts +0 -116
  251. package/packages/opencode/src/skill/index.ts +0 -277
  252. package/packages/opencode/src/snapshot/index.ts +0 -726
  253. package/packages/opencode/src/sql.d.ts +0 -4
  254. package/packages/opencode/src/storage/db.node.ts +0 -8
  255. package/packages/opencode/src/storage/db.ts +0 -177
  256. package/packages/opencode/src/storage/json-migration.ts +0 -425
  257. package/packages/opencode/src/storage/schema.sql.ts +0 -10
  258. package/packages/opencode/src/storage/schema.ts +0 -5
  259. package/packages/opencode/src/storage/storage.ts +0 -353
  260. package/packages/opencode/src/sync/README.md +0 -179
  261. package/packages/opencode/src/sync/event.sql.ts +0 -16
  262. package/packages/opencode/src/sync/index.ts +0 -263
  263. package/packages/opencode/src/sync/schema.ts +0 -14
  264. package/packages/opencode/src/tool/apply_patch.ts +0 -281
  265. package/packages/opencode/src/tool/apply_patch.txt +0 -33
  266. package/packages/opencode/src/tool/bash.ts +0 -496
  267. package/packages/opencode/src/tool/bash.txt +0 -117
  268. package/packages/opencode/src/tool/batch.ts +0 -183
  269. package/packages/opencode/src/tool/batch.txt +0 -24
  270. package/packages/opencode/src/tool/codesearch.ts +0 -132
  271. package/packages/opencode/src/tool/codesearch.txt +0 -12
  272. package/packages/opencode/src/tool/edit.ts +0 -667
  273. package/packages/opencode/src/tool/edit.txt +0 -10
  274. package/packages/opencode/src/tool/external-directory.ts +0 -46
  275. package/packages/opencode/src/tool/glob.ts +0 -78
  276. package/packages/opencode/src/tool/glob.txt +0 -6
  277. package/packages/opencode/src/tool/grep.ts +0 -156
  278. package/packages/opencode/src/tool/grep.txt +0 -8
  279. package/packages/opencode/src/tool/invalid.ts +0 -17
  280. package/packages/opencode/src/tool/ls.ts +0 -121
  281. package/packages/opencode/src/tool/ls.txt +0 -1
  282. package/packages/opencode/src/tool/lsp.ts +0 -97
  283. package/packages/opencode/src/tool/lsp.txt +0 -19
  284. package/packages/opencode/src/tool/multiedit.ts +0 -46
  285. package/packages/opencode/src/tool/multiedit.txt +0 -41
  286. package/packages/opencode/src/tool/plan-enter.txt +0 -14
  287. package/packages/opencode/src/tool/plan-exit.txt +0 -13
  288. package/packages/opencode/src/tool/plan.ts +0 -131
  289. package/packages/opencode/src/tool/question.ts +0 -46
  290. package/packages/opencode/src/tool/question.txt +0 -10
  291. package/packages/opencode/src/tool/read.ts +0 -332
  292. package/packages/opencode/src/tool/read.txt +0 -14
  293. package/packages/opencode/src/tool/registry.ts +0 -265
  294. package/packages/opencode/src/tool/schema.ts +0 -17
  295. package/packages/opencode/src/tool/skill.ts +0 -105
  296. package/packages/opencode/src/tool/task.ts +0 -166
  297. package/packages/opencode/src/tool/task.txt +0 -60
  298. package/packages/opencode/src/tool/todo.ts +0 -48
  299. package/packages/opencode/src/tool/todowrite.txt +0 -167
  300. package/packages/opencode/src/tool/tool.ts +0 -112
  301. package/packages/opencode/src/tool/truncate.ts +0 -144
  302. package/packages/opencode/src/tool/truncation-dir.ts +0 -4
  303. package/packages/opencode/src/tool/webfetch.ts +0 -206
  304. package/packages/opencode/src/tool/webfetch.txt +0 -13
  305. package/packages/opencode/src/tool/websearch.ts +0 -150
  306. package/packages/opencode/src/tool/websearch.txt +0 -14
  307. package/packages/opencode/src/tool/write.ts +0 -84
  308. package/packages/opencode/src/tool/write.txt +0 -8
  309. package/packages/opencode/src/util/abort.ts +0 -35
  310. package/packages/opencode/src/util/archive.ts +0 -17
  311. package/packages/opencode/src/util/color.ts +0 -19
  312. package/packages/opencode/src/util/context.ts +0 -25
  313. package/packages/opencode/src/util/data-url.ts +0 -9
  314. package/packages/opencode/src/util/defer.ts +0 -12
  315. package/packages/opencode/src/util/effect-http-client.ts +0 -11
  316. package/packages/opencode/src/util/effect-zod.ts +0 -98
  317. package/packages/opencode/src/util/error.ts +0 -77
  318. package/packages/opencode/src/util/filesystem.ts +0 -245
  319. package/packages/opencode/src/util/flock.ts +0 -333
  320. package/packages/opencode/src/util/fn.ts +0 -21
  321. package/packages/opencode/src/util/format.ts +0 -20
  322. package/packages/opencode/src/util/glob.ts +0 -34
  323. package/packages/opencode/src/util/hash.ts +0 -7
  324. package/packages/opencode/src/util/iife.ts +0 -3
  325. package/packages/opencode/src/util/keybind.ts +0 -103
  326. package/packages/opencode/src/util/lazy.ts +0 -23
  327. package/packages/opencode/src/util/locale.ts +0 -81
  328. package/packages/opencode/src/util/lock.ts +0 -98
  329. package/packages/opencode/src/util/log.ts +0 -182
  330. package/packages/opencode/src/util/network.ts +0 -9
  331. package/packages/opencode/src/util/process.ts +0 -176
  332. package/packages/opencode/src/util/queue.ts +0 -32
  333. package/packages/opencode/src/util/record.ts +0 -3
  334. package/packages/opencode/src/util/rpc.ts +0 -66
  335. package/packages/opencode/src/util/schema.ts +0 -53
  336. package/packages/opencode/src/util/scrap.ts +0 -10
  337. package/packages/opencode/src/util/signal.ts +0 -12
  338. package/packages/opencode/src/util/timeout.ts +0 -14
  339. package/packages/opencode/src/util/token.ts +0 -7
  340. package/packages/opencode/src/util/update-schema.ts +0 -13
  341. package/packages/opencode/src/util/which.ts +0 -14
  342. package/packages/opencode/src/util/wildcard.ts +0 -59
  343. package/packages/opencode/src/worktree/index.ts +0 -612
  344. package/packages/plugin/package.json +0 -38
  345. package/packages/plugin/src/example.ts +0 -18
  346. package/packages/plugin/src/index.ts +0 -282
  347. package/packages/plugin/src/shell.ts +0 -136
  348. package/packages/plugin/src/tool.ts +0 -38
  349. package/packages/plugin/src/tui.ts +0 -508
  350. package/packages/script/package.json +0 -16
  351. package/packages/script/src/index.ts +0 -77
  352. package/packages/sdk/package.json +0 -33
  353. package/packages/sdk/src/client.ts +0 -55
  354. package/packages/sdk/src/gen/client/client.gen.ts +0 -212
  355. package/packages/sdk/src/gen/client/index.ts +0 -25
  356. package/packages/sdk/src/gen/client/types.gen.ts +0 -222
  357. package/packages/sdk/src/gen/client/utils.gen.ts +0 -287
  358. package/packages/sdk/src/gen/client.gen.ts +0 -22
  359. package/packages/sdk/src/gen/core/auth.gen.ts +0 -41
  360. package/packages/sdk/src/gen/core/bodySerializer.gen.ts +0 -74
  361. package/packages/sdk/src/gen/core/params.gen.ts +0 -144
  362. package/packages/sdk/src/gen/core/pathSerializer.gen.ts +0 -167
  363. package/packages/sdk/src/gen/core/queryKeySerializer.gen.ts +0 -111
  364. package/packages/sdk/src/gen/core/serverSentEvents.gen.ts +0 -210
  365. package/packages/sdk/src/gen/core/types.gen.ts +0 -91
  366. package/packages/sdk/src/gen/core/utils.gen.ts +0 -109
  367. package/packages/sdk/src/gen/sdk.gen.ts +0 -1197
  368. package/packages/sdk/src/gen/types.gen.ts +0 -3904
  369. package/packages/sdk/src/index.ts +0 -21
  370. package/packages/sdk/src/process.ts +0 -31
  371. package/packages/sdk/src/server.ts +0 -134
  372. package/packages/sdk/src/v2/client.ts +0 -81
  373. package/packages/sdk/src/v2/gen/client/client.gen.ts +0 -285
  374. package/packages/sdk/src/v2/gen/client/index.ts +0 -25
  375. package/packages/sdk/src/v2/gen/client/types.gen.ts +0 -202
  376. package/packages/sdk/src/v2/gen/client/utils.gen.ts +0 -289
  377. package/packages/sdk/src/v2/gen/client.gen.ts +0 -18
  378. package/packages/sdk/src/v2/gen/core/auth.gen.ts +0 -41
  379. package/packages/sdk/src/v2/gen/core/bodySerializer.gen.ts +0 -82
  380. package/packages/sdk/src/v2/gen/core/params.gen.ts +0 -169
  381. package/packages/sdk/src/v2/gen/core/pathSerializer.gen.ts +0 -167
  382. package/packages/sdk/src/v2/gen/core/queryKeySerializer.gen.ts +0 -111
  383. package/packages/sdk/src/v2/gen/core/serverSentEvents.gen.ts +0 -239
  384. package/packages/sdk/src/v2/gen/core/types.gen.ts +0 -86
  385. package/packages/sdk/src/v2/gen/core/utils.gen.ts +0 -137
  386. package/packages/sdk/src/v2/gen/sdk.gen.ts +0 -4223
  387. package/packages/sdk/src/v2/gen/types.gen.ts +0 -5265
  388. package/packages/sdk/src/v2/index.ts +0 -21
  389. package/packages/sdk/src/v2/server.ts +0 -134
  390. package/packages/util/package.json +0 -20
  391. package/packages/util/src/array.ts +0 -10
  392. package/packages/util/src/binary.ts +0 -41
  393. package/packages/util/src/encode.ts +0 -51
  394. package/packages/util/src/error.ts +0 -54
  395. package/packages/util/src/fn.ts +0 -11
  396. package/packages/util/src/identifier.ts +0 -48
  397. package/packages/util/src/iife.ts +0 -3
  398. package/packages/util/src/lazy.ts +0 -11
  399. package/packages/util/src/module.ts +0 -10
  400. package/packages/util/src/path.ts +0 -37
  401. package/packages/util/src/retry.ts +0 -41
  402. package/packages/util/src/slug.ts +0 -74
  403. package/postinstall.cjs +0 -55
  404. /package/dist/{chunk-ANDTK76Q.js.map → chunk-GSE2T5UY.js.map} +0 -0
  405. /package/dist/{chunk-CYXMV3J3.js.map → chunk-LU5XVQUD.js.map} +0 -0
  406. /package/dist/{mcp-VAU4RMWH.js.map → chunk-PWFRMDDF.js.map} +0 -0
  407. /package/dist/{chunk-DSPC5QIG.js.map → chunk-SM6WZDN6.js.map} +0 -0
  408. /package/dist/{chunk-MCWTARFP.js.map → chunk-TASPMBUL.js.map} +0 -0
  409. /package/dist/{registry-PYMN6L3G.js.map → default-u_dwuiYb-WOFHQQ3K.js.map} +0 -0
  410. /package/dist/{server-K3UGWASP.js.map → mcp-XFGN3FWW.js.map} +0 -0
  411. /package/dist/{session-HJFWTM7C.js.map → registry-W4MBVBYD.js.map} +0 -0
  412. /package/dist/{share-next-55VCIMUH.js.map → server-2CPOG3LS.js.map} +0 -0
  413. /package/dist/{worktree-6GGDLADY.js.map → worktree-3GUHT2P7.js.map} +0 -0
@@ -1,175 +0,0 @@
1
- import { GlobalBus } from "@/bus/global"
2
- import { disposeInstance } from "@/effect/instance-registry"
3
- import { Filesystem } from "@/util/filesystem"
4
- import { iife } from "@/util/iife"
5
- import { Log } from "@/util/log"
6
- import { Context } from "../util/context"
7
- import { Project } from "./project"
8
- import { State } from "./state"
9
-
10
- export interface InstanceContext {
11
- directory: string
12
- worktree: string
13
- project: Project.Info
14
- }
15
-
16
- const context = Context.create<InstanceContext>("instance")
17
- const cache = new Map<string, Promise<InstanceContext>>()
18
-
19
- const disposal = {
20
- all: undefined as Promise<void> | undefined,
21
- }
22
-
23
- function emit(directory: string) {
24
- GlobalBus.emit("event", {
25
- directory,
26
- payload: {
27
- type: "server.instance.disposed",
28
- properties: {
29
- directory,
30
- },
31
- },
32
- })
33
- }
34
-
35
- function boot(input: { directory: string; init?: () => Promise<any>; project?: Project.Info; worktree?: string }) {
36
- return iife(async () => {
37
- const ctx =
38
- input.project && input.worktree
39
- ? {
40
- directory: input.directory,
41
- worktree: input.worktree,
42
- project: input.project,
43
- }
44
- : await Project.fromDirectory(input.directory).then(({ project, sandbox }) => ({
45
- directory: input.directory,
46
- worktree: sandbox,
47
- project,
48
- }))
49
- await context.provide(ctx, async () => {
50
- await input.init?.()
51
- })
52
- return ctx
53
- })
54
- }
55
-
56
- function track(directory: string, next: Promise<InstanceContext>) {
57
- const task = next.catch((error) => {
58
- if (cache.get(directory) === task) cache.delete(directory)
59
- throw error
60
- })
61
- cache.set(directory, task)
62
- return task
63
- }
64
-
65
- export const Instance = {
66
- async provide<R>(input: { directory: string; init?: () => Promise<any>; fn: () => R }): Promise<R> {
67
- const directory = Filesystem.resolve(input.directory)
68
- let existing = cache.get(directory)
69
- if (!existing) {
70
- Log.Default.info("creating instance", { directory })
71
- existing = track(
72
- directory,
73
- boot({
74
- directory,
75
- init: input.init,
76
- }),
77
- )
78
- }
79
- const ctx = await existing
80
- return context.provide(ctx, async () => {
81
- return input.fn()
82
- })
83
- },
84
- get current() {
85
- return context.use()
86
- },
87
- get directory() {
88
- return context.use().directory
89
- },
90
- get worktree() {
91
- return context.use().worktree
92
- },
93
- get project() {
94
- return context.use().project
95
- },
96
- /**
97
- * Check if a path is within the project boundary.
98
- * Returns true if path is inside Instance.directory OR Instance.worktree.
99
- * Paths within the worktree but outside the working directory should not trigger external_directory permission.
100
- */
101
- containsPath(filepath: string) {
102
- if (Filesystem.contains(Instance.directory, filepath)) return true
103
- // Non-git projects set worktree to "/" which would match ANY absolute path.
104
- // Skip worktree check in this case to preserve external_directory permissions.
105
- if (Instance.worktree === "/") return false
106
- return Filesystem.contains(Instance.worktree, filepath)
107
- },
108
- /**
109
- * Captures the current instance ALS context and returns a wrapper that
110
- * restores it when called. Use this for callbacks that fire outside the
111
- * instance async context (native addons, event emitters, timers, etc.).
112
- */
113
- bind<F extends (...args: any[]) => any>(fn: F): F {
114
- const ctx = context.use()
115
- return ((...args: any[]) => context.provide(ctx, () => fn(...args))) as F
116
- },
117
- /**
118
- * Run a synchronous function within the given instance context ALS.
119
- * Use this to bridge from Effect (where InstanceRef carries context)
120
- * back to sync code that reads Instance.directory from ALS.
121
- */
122
- restore<R>(ctx: InstanceContext, fn: () => R): R {
123
- return context.provide(ctx, fn)
124
- },
125
- state<S>(init: () => S, dispose?: (state: Awaited<S>) => Promise<void>): () => S {
126
- return State.create(() => Instance.directory, init, dispose)
127
- },
128
- async reload(input: { directory: string; init?: () => Promise<any>; project?: Project.Info; worktree?: string }) {
129
- const directory = Filesystem.resolve(input.directory)
130
- Log.Default.info("reloading instance", { directory })
131
- await Promise.all([State.dispose(directory), disposeInstance(directory)])
132
- cache.delete(directory)
133
- const next = track(directory, boot({ ...input, directory }))
134
- emit(directory)
135
- return await next
136
- },
137
- async dispose() {
138
- const directory = Instance.directory
139
- Log.Default.info("disposing instance", { directory })
140
- await Promise.all([State.dispose(directory), disposeInstance(directory)])
141
- cache.delete(directory)
142
- emit(directory)
143
- },
144
- async disposeAll() {
145
- if (disposal.all) return disposal.all
146
-
147
- disposal.all = iife(async () => {
148
- Log.Default.info("disposing all instances")
149
- const entries = [...cache.entries()]
150
- for (const [key, value] of entries) {
151
- if (cache.get(key) !== value) continue
152
-
153
- const ctx = await value.catch((error) => {
154
- Log.Default.warn("instance dispose failed", { key, error })
155
- return undefined
156
- })
157
-
158
- if (!ctx) {
159
- if (cache.get(key) === value) cache.delete(key)
160
- continue
161
- }
162
-
163
- if (cache.get(key) !== value) continue
164
-
165
- await context.provide(ctx, async () => {
166
- await Instance.dispose()
167
- })
168
- }
169
- }).finally(() => {
170
- disposal.all = undefined
171
- })
172
-
173
- return disposal.all
174
- },
175
- }
@@ -1,16 +0,0 @@
1
- import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core"
2
- import { Timestamps } from "../storage/schema.sql"
3
- import type { ProjectID } from "./schema"
4
-
5
- export const ProjectTable = sqliteTable("project", {
6
- id: text().$type<ProjectID>().primaryKey(),
7
- worktree: text().notNull(),
8
- vcs: text(),
9
- name: text(),
10
- icon_url: text(),
11
- icon_color: text(),
12
- ...Timestamps,
13
- time_initialized: integer(),
14
- sandboxes: text({ mode: "json" }).notNull().$type<string[]>(),
15
- commands: text({ mode: "json" }).$type<{ start?: string }>(),
16
- })
@@ -1,519 +0,0 @@
1
- import z from "zod"
2
- import { and, Database, eq } from "../storage/db"
3
- import { ProjectTable } from "./project.sql"
4
- import { SessionTable } from "../session/session.sql"
5
- import { Log } from "../util/log"
6
- import { Flag } from "@/flag/flag"
7
- import { BusEvent } from "@/bus/bus-event"
8
- import { GlobalBus } from "@/bus/global"
9
- import { which } from "../util/which"
10
- import { ProjectID } from "./schema"
11
- import { Effect, Layer, Path, Scope, ServiceMap, Stream } from "effect"
12
- import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
13
- import { NodeFileSystem, NodePath } from "@effect/platform-node"
14
- import { makeRuntime } from "@/effect/run-service"
15
- import { AppFileSystem } from "@/filesystem"
16
- import * as CrossSpawnSpawner from "@/effect/cross-spawn-spawner"
17
-
18
- export namespace Project {
19
- const log = Log.create({ service: "project" })
20
-
21
- export const Info = z
22
- .object({
23
- id: ProjectID.zod,
24
- worktree: z.string(),
25
- vcs: z.literal("git").optional(),
26
- name: z.string().optional(),
27
- icon: z
28
- .object({
29
- url: z.string().optional(),
30
- override: z.string().optional(),
31
- color: z.string().optional(),
32
- })
33
- .optional(),
34
- commands: z
35
- .object({
36
- start: z.string().optional().describe("Startup script to run when creating a new workspace (worktree)"),
37
- })
38
- .optional(),
39
- time: z.object({
40
- created: z.number(),
41
- updated: z.number(),
42
- initialized: z.number().optional(),
43
- }),
44
- sandboxes: z.array(z.string()),
45
- })
46
- .meta({
47
- ref: "Project",
48
- })
49
- export type Info = z.infer<typeof Info>
50
-
51
- export const Event = {
52
- Updated: BusEvent.define("project.updated", Info),
53
- }
54
-
55
- type Row = typeof ProjectTable.$inferSelect
56
-
57
- export function fromRow(row: Row): Info {
58
- const icon =
59
- row.icon_url || row.icon_color
60
- ? { url: row.icon_url ?? undefined, color: row.icon_color ?? undefined }
61
- : undefined
62
- return {
63
- id: row.id,
64
- worktree: row.worktree,
65
- vcs: row.vcs ? Info.shape.vcs.parse(row.vcs) : undefined,
66
- name: row.name ?? undefined,
67
- icon,
68
- time: {
69
- created: row.time_created,
70
- updated: row.time_updated,
71
- initialized: row.time_initialized ?? undefined,
72
- },
73
- sandboxes: row.sandboxes,
74
- commands: row.commands ?? undefined,
75
- }
76
- }
77
-
78
- export const UpdateInput = z.object({
79
- projectID: ProjectID.zod,
80
- name: z.string().optional(),
81
- icon: Info.shape.icon.optional(),
82
- commands: Info.shape.commands.optional(),
83
- })
84
- export type UpdateInput = z.infer<typeof UpdateInput>
85
-
86
- // ---------------------------------------------------------------------------
87
- // Effect service
88
- // ---------------------------------------------------------------------------
89
-
90
- export interface Interface {
91
- readonly fromDirectory: (directory: string) => Effect.Effect<{ project: Info; sandbox: string }>
92
- readonly discover: (input: Info) => Effect.Effect<void>
93
- readonly list: () => Effect.Effect<Info[]>
94
- readonly get: (id: ProjectID) => Effect.Effect<Info | undefined>
95
- readonly update: (input: UpdateInput) => Effect.Effect<Info>
96
- readonly initGit: (input: { directory: string; project: Info }) => Effect.Effect<Info>
97
- readonly setInitialized: (id: ProjectID) => Effect.Effect<void>
98
- readonly sandboxes: (id: ProjectID) => Effect.Effect<string[]>
99
- readonly addSandbox: (id: ProjectID, directory: string) => Effect.Effect<void>
100
- readonly removeSandbox: (id: ProjectID, directory: string) => Effect.Effect<void>
101
- }
102
-
103
- export class Service extends ServiceMap.Service<Service, Interface>()("@opencode/Project") {}
104
-
105
- type GitResult = { code: number; text: string; stderr: string }
106
-
107
- export const layer: Layer.Layer<
108
- Service,
109
- never,
110
- AppFileSystem.Service | Path.Path | ChildProcessSpawner.ChildProcessSpawner
111
- > = Layer.effect(
112
- Service,
113
- Effect.gen(function* () {
114
- const fs = yield* AppFileSystem.Service
115
- const pathSvc = yield* Path.Path
116
- const spawner = yield* ChildProcessSpawner.ChildProcessSpawner
117
-
118
- const git = Effect.fnUntraced(
119
- function* (args: string[], opts?: { cwd?: string }) {
120
- const handle = yield* spawner.spawn(
121
- ChildProcess.make("git", args, { cwd: opts?.cwd, extendEnv: true, stdin: "ignore" }),
122
- )
123
- const [text, stderr] = yield* Effect.all(
124
- [Stream.mkString(Stream.decodeText(handle.stdout)), Stream.mkString(Stream.decodeText(handle.stderr))],
125
- { concurrency: 2 },
126
- )
127
- const code = yield* handle.exitCode
128
- return { code, text, stderr } satisfies GitResult
129
- },
130
- Effect.scoped,
131
- Effect.catch(() => Effect.succeed({ code: 1, text: "", stderr: "" } satisfies GitResult)),
132
- )
133
-
134
- const db = <T>(fn: (d: Parameters<typeof Database.use>[0] extends (trx: infer D) => any ? D : never) => T) =>
135
- Effect.sync(() => Database.use(fn))
136
-
137
- const emitUpdated = (data: Info) =>
138
- Effect.sync(() =>
139
- GlobalBus.emit("event", {
140
- payload: { type: Event.Updated.type, properties: data },
141
- }),
142
- )
143
-
144
- const fakeVcs = Info.shape.vcs.parse(Flag.OPENCODE_FAKE_VCS)
145
-
146
- const resolveGitPath = (cwd: string, name: string) => {
147
- if (!name) return cwd
148
- name = name.replace(/[\r\n]+$/, "")
149
- if (!name) return cwd
150
- name = AppFileSystem.windowsPath(name)
151
- if (pathSvc.isAbsolute(name)) return pathSvc.normalize(name)
152
- return pathSvc.resolve(cwd, name)
153
- }
154
-
155
- const scope = yield* Scope.Scope
156
-
157
- const readCachedProjectId = Effect.fnUntraced(function* (dir: string) {
158
- return yield* fs.readFileString(pathSvc.join(dir, "opencode")).pipe(
159
- Effect.map((x) => x.trim()),
160
- Effect.map(ProjectID.make),
161
- Effect.catch(() => Effect.succeed(undefined)),
162
- )
163
- })
164
-
165
- const fromDirectory = Effect.fn("Project.fromDirectory")(function* (directory: string) {
166
- log.info("fromDirectory", { directory })
167
-
168
- // Phase 1: discover git info
169
- type DiscoveryResult = { id: ProjectID; worktree: string; sandbox: string; vcs: Info["vcs"] }
170
-
171
- const data: DiscoveryResult = yield* Effect.gen(function* () {
172
- const dotgitMatches = yield* fs.up({ targets: [".git"], start: directory }).pipe(Effect.orDie)
173
- const dotgit = dotgitMatches[0]
174
-
175
- if (!dotgit) {
176
- return {
177
- id: ProjectID.global,
178
- worktree: "/",
179
- sandbox: "/",
180
- vcs: fakeVcs,
181
- }
182
- }
183
-
184
- let sandbox = pathSvc.dirname(dotgit)
185
- const gitBinary = yield* Effect.sync(() => which("git"))
186
- let id = yield* readCachedProjectId(dotgit)
187
-
188
- if (!gitBinary) {
189
- return {
190
- id: id ?? ProjectID.global,
191
- worktree: sandbox,
192
- sandbox,
193
- vcs: fakeVcs,
194
- }
195
- }
196
-
197
- const commonDir = yield* git(["rev-parse", "--git-common-dir"], { cwd: sandbox })
198
- if (commonDir.code !== 0) {
199
- return {
200
- id: id ?? ProjectID.global,
201
- worktree: sandbox,
202
- sandbox,
203
- vcs: fakeVcs,
204
- }
205
- }
206
- const worktree = (() => {
207
- const common = resolveGitPath(sandbox, commonDir.text.trim())
208
- return common === sandbox ? sandbox : pathSvc.dirname(common)
209
- })()
210
-
211
- if (id == null) {
212
- id = yield* readCachedProjectId(pathSvc.join(worktree, ".git"))
213
- }
214
-
215
- if (!id) {
216
- const revList = yield* git(["rev-list", "--max-parents=0", "HEAD"], { cwd: sandbox })
217
- const roots = revList.text
218
- .split("\n")
219
- .filter(Boolean)
220
- .map((x) => x.trim())
221
- .toSorted()
222
-
223
- id = roots[0] ? ProjectID.make(roots[0]) : undefined
224
- if (id) {
225
- yield* fs.writeFileString(pathSvc.join(worktree, ".git", "opencode"), id).pipe(Effect.ignore)
226
- }
227
- }
228
-
229
- if (!id) {
230
- return { id: ProjectID.global, worktree: sandbox, sandbox, vcs: "git" as const }
231
- }
232
-
233
- const topLevel = yield* git(["rev-parse", "--show-toplevel"], { cwd: sandbox })
234
- if (topLevel.code !== 0) {
235
- return {
236
- id,
237
- worktree: sandbox,
238
- sandbox,
239
- vcs: fakeVcs,
240
- }
241
- }
242
- sandbox = resolveGitPath(sandbox, topLevel.text.trim())
243
-
244
- return { id, sandbox, worktree, vcs: "git" as const }
245
- })
246
-
247
- // Phase 2: upsert
248
- const row = yield* db((d) => d.select().from(ProjectTable).where(eq(ProjectTable.id, data.id)).get())
249
- const existing = row
250
- ? fromRow(row)
251
- : {
252
- id: data.id,
253
- worktree: data.worktree,
254
- vcs: data.vcs,
255
- sandboxes: [] as string[],
256
- time: { created: Date.now(), updated: Date.now() },
257
- }
258
-
259
- if (Flag.OPENCODE_EXPERIMENTAL_ICON_DISCOVERY)
260
- yield* discover(existing).pipe(Effect.ignore, Effect.forkIn(scope))
261
-
262
- const result: Info = {
263
- ...existing,
264
- worktree: data.worktree,
265
- vcs: data.vcs,
266
- time: { ...existing.time, updated: Date.now() },
267
- }
268
- if (data.sandbox !== result.worktree && !result.sandboxes.includes(data.sandbox))
269
- result.sandboxes.push(data.sandbox)
270
- result.sandboxes = yield* Effect.forEach(
271
- result.sandboxes,
272
- (s) =>
273
- fs.exists(s).pipe(
274
- Effect.orDie,
275
- Effect.map((exists) => (exists ? s : undefined)),
276
- ),
277
- { concurrency: "unbounded" },
278
- ).pipe(Effect.map((arr) => arr.filter((x): x is string => x !== undefined)))
279
-
280
- yield* db((d) =>
281
- d
282
- .insert(ProjectTable)
283
- .values({
284
- id: result.id,
285
- worktree: result.worktree,
286
- vcs: result.vcs ?? null,
287
- name: result.name,
288
- icon_url: result.icon?.url,
289
- icon_color: result.icon?.color,
290
- time_created: result.time.created,
291
- time_updated: result.time.updated,
292
- time_initialized: result.time.initialized,
293
- sandboxes: result.sandboxes,
294
- commands: result.commands,
295
- })
296
- .onConflictDoUpdate({
297
- target: ProjectTable.id,
298
- set: {
299
- worktree: result.worktree,
300
- vcs: result.vcs ?? null,
301
- name: result.name,
302
- icon_url: result.icon?.url,
303
- icon_color: result.icon?.color,
304
- time_updated: result.time.updated,
305
- time_initialized: result.time.initialized,
306
- sandboxes: result.sandboxes,
307
- commands: result.commands,
308
- },
309
- })
310
- .run(),
311
- )
312
-
313
- if (data.id !== ProjectID.global) {
314
- yield* db((d) =>
315
- d
316
- .update(SessionTable)
317
- .set({ project_id: data.id })
318
- .where(and(eq(SessionTable.project_id, ProjectID.global), eq(SessionTable.directory, data.worktree)))
319
- .run(),
320
- )
321
- }
322
-
323
- yield* emitUpdated(result)
324
- return { project: result, sandbox: data.sandbox }
325
- })
326
-
327
- const discover = Effect.fn("Project.discover")(function* (input: Info) {
328
- if (input.vcs !== "git") return
329
- if (input.icon?.override) return
330
- if (input.icon?.url) return
331
-
332
- const matches = yield* fs
333
- .glob("**/favicon.{ico,png,svg,jpg,jpeg,webp}", {
334
- cwd: input.worktree,
335
- absolute: true,
336
- include: "file",
337
- })
338
- .pipe(Effect.orDie)
339
- const shortest = matches.sort((a, b) => a.length - b.length)[0]
340
- if (!shortest) return
341
-
342
- const buffer = yield* fs.readFile(shortest).pipe(Effect.orDie)
343
- const base64 = Buffer.from(buffer).toString("base64")
344
- const mime = AppFileSystem.mimeType(shortest)
345
- const url = `data:${mime};base64,${base64}`
346
- yield* update({ projectID: input.id, icon: { url } })
347
- })
348
-
349
- const list = Effect.fn("Project.list")(function* () {
350
- return yield* db((d) => d.select().from(ProjectTable).all().map(fromRow))
351
- })
352
-
353
- const get = Effect.fn("Project.get")(function* (id: ProjectID) {
354
- const row = yield* db((d) => d.select().from(ProjectTable).where(eq(ProjectTable.id, id)).get())
355
- return row ? fromRow(row) : undefined
356
- })
357
-
358
- const update = Effect.fn("Project.update")(function* (input: UpdateInput) {
359
- const result = yield* db((d) =>
360
- d
361
- .update(ProjectTable)
362
- .set({
363
- name: input.name,
364
- icon_url: input.icon?.url,
365
- icon_color: input.icon?.color,
366
- commands: input.commands,
367
- time_updated: Date.now(),
368
- })
369
- .where(eq(ProjectTable.id, input.projectID))
370
- .returning()
371
- .get(),
372
- )
373
- if (!result) throw new Error(`Project not found: ${input.projectID}`)
374
- const data = fromRow(result)
375
- yield* emitUpdated(data)
376
- return data
377
- })
378
-
379
- const initGit = Effect.fn("Project.initGit")(function* (input: { directory: string; project: Info }) {
380
- if (input.project.vcs === "git") return input.project
381
- if (!(yield* Effect.sync(() => which("git")))) throw new Error("Git is not installed")
382
- const result = yield* git(["init", "--quiet"], { cwd: input.directory })
383
- if (result.code !== 0) {
384
- throw new Error(result.stderr.trim() || result.text.trim() || "Failed to initialize git repository")
385
- }
386
- const { project } = yield* fromDirectory(input.directory)
387
- return project
388
- })
389
-
390
- const setInitialized = Effect.fn("Project.setInitialized")(function* (id: ProjectID) {
391
- yield* db((d) =>
392
- d.update(ProjectTable).set({ time_initialized: Date.now() }).where(eq(ProjectTable.id, id)).run(),
393
- )
394
- })
395
-
396
- const sandboxes = Effect.fn("Project.sandboxes")(function* (id: ProjectID) {
397
- const row = yield* db((d) => d.select().from(ProjectTable).where(eq(ProjectTable.id, id)).get())
398
- if (!row) return []
399
- const data = fromRow(row)
400
- return yield* Effect.forEach(
401
- data.sandboxes,
402
- (dir) =>
403
- fs.isDir(dir).pipe(
404
- Effect.orDie,
405
- Effect.map((ok) => (ok ? dir : undefined)),
406
- ),
407
- { concurrency: "unbounded" },
408
- ).pipe(Effect.map((arr) => arr.filter((x): x is string => x !== undefined)))
409
- })
410
-
411
- const addSandbox = Effect.fn("Project.addSandbox")(function* (id: ProjectID, directory: string) {
412
- const row = yield* db((d) => d.select().from(ProjectTable).where(eq(ProjectTable.id, id)).get())
413
- if (!row) throw new Error(`Project not found: ${id}`)
414
- const sboxes = [...row.sandboxes]
415
- if (!sboxes.includes(directory)) sboxes.push(directory)
416
- const result = yield* db((d) =>
417
- d
418
- .update(ProjectTable)
419
- .set({ sandboxes: sboxes, time_updated: Date.now() })
420
- .where(eq(ProjectTable.id, id))
421
- .returning()
422
- .get(),
423
- )
424
- if (!result) throw new Error(`Project not found: ${id}`)
425
- yield* emitUpdated(fromRow(result))
426
- })
427
-
428
- const removeSandbox = Effect.fn("Project.removeSandbox")(function* (id: ProjectID, directory: string) {
429
- const row = yield* db((d) => d.select().from(ProjectTable).where(eq(ProjectTable.id, id)).get())
430
- if (!row) throw new Error(`Project not found: ${id}`)
431
- const sboxes = row.sandboxes.filter((s) => s !== directory)
432
- const result = yield* db((d) =>
433
- d
434
- .update(ProjectTable)
435
- .set({ sandboxes: sboxes, time_updated: Date.now() })
436
- .where(eq(ProjectTable.id, id))
437
- .returning()
438
- .get(),
439
- )
440
- if (!result) throw new Error(`Project not found: ${id}`)
441
- yield* emitUpdated(fromRow(result))
442
- })
443
-
444
- return Service.of({
445
- fromDirectory,
446
- discover,
447
- list,
448
- get,
449
- update,
450
- initGit,
451
- setInitialized,
452
- sandboxes,
453
- addSandbox,
454
- removeSandbox,
455
- })
456
- }),
457
- )
458
-
459
- export const defaultLayer = layer.pipe(
460
- Layer.provide(CrossSpawnSpawner.defaultLayer),
461
- Layer.provide(AppFileSystem.defaultLayer),
462
- Layer.provide(NodePath.layer),
463
- )
464
- const { runPromise } = makeRuntime(Service, defaultLayer)
465
-
466
- // ---------------------------------------------------------------------------
467
- // Promise-based API (delegates to Effect service via runPromise)
468
- // ---------------------------------------------------------------------------
469
-
470
- export function fromDirectory(directory: string) {
471
- return runPromise((svc) => svc.fromDirectory(directory))
472
- }
473
-
474
- export function discover(input: Info) {
475
- return runPromise((svc) => svc.discover(input))
476
- }
477
-
478
- export function list() {
479
- return Database.use((db) =>
480
- db
481
- .select()
482
- .from(ProjectTable)
483
- .all()
484
- .map((row) => fromRow(row)),
485
- )
486
- }
487
-
488
- export function get(id: ProjectID): Info | undefined {
489
- const row = Database.use((db) => db.select().from(ProjectTable).where(eq(ProjectTable.id, id)).get())
490
- if (!row) return undefined
491
- return fromRow(row)
492
- }
493
-
494
- export function setInitialized(id: ProjectID) {
495
- Database.use((db) =>
496
- db.update(ProjectTable).set({ time_initialized: Date.now() }).where(eq(ProjectTable.id, id)).run(),
497
- )
498
- }
499
-
500
- export function initGit(input: { directory: string; project: Info }) {
501
- return runPromise((svc) => svc.initGit(input))
502
- }
503
-
504
- export function update(input: UpdateInput) {
505
- return runPromise((svc) => svc.update(input))
506
- }
507
-
508
- export function sandboxes(id: ProjectID) {
509
- return runPromise((svc) => svc.sandboxes(id))
510
- }
511
-
512
- export function addSandbox(id: ProjectID, directory: string) {
513
- return runPromise((svc) => svc.addSandbox(id, directory))
514
- }
515
-
516
- export function removeSandbox(id: ProjectID, directory: string) {
517
- return runPromise((svc) => svc.removeSandbox(id, directory))
518
- }
519
- }