@neuralnomads/codenomad-dev 0.20.0-dev-20260917-aa51cbb9 → 0.20.0-dev-20260918-a311de98

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 (223) hide show
  1. package/dist/api-types.js.map +1 -1
  2. package/dist/events/bus.js +2 -0
  3. package/dist/events/bus.js.map +1 -1
  4. package/dist/filesystem/__tests__/browser.test.js +10 -10
  5. package/dist/filesystem/__tests__/browser.test.js.map +1 -1
  6. package/dist/filesystem/__tests__/responsiveness.test.js +79 -0
  7. package/dist/filesystem/__tests__/responsiveness.test.js.map +1 -0
  8. package/dist/filesystem/__tests__/search-cache.test.js +48 -9
  9. package/dist/filesystem/__tests__/search-cache.test.js.map +1 -1
  10. package/dist/filesystem/__tests__/search.test.js +8 -8
  11. package/dist/filesystem/__tests__/search.test.js.map +1 -1
  12. package/dist/filesystem/__tests__/write-order.test.js +64 -0
  13. package/dist/filesystem/__tests__/write-order.test.js.map +1 -0
  14. package/dist/filesystem/browser.js +44 -46
  15. package/dist/filesystem/browser.js.map +1 -1
  16. package/dist/filesystem/file-access.js +19 -0
  17. package/dist/filesystem/file-access.js.map +1 -0
  18. package/dist/filesystem/search-cache.js +35 -9
  19. package/dist/filesystem/search-cache.js.map +1 -1
  20. package/dist/filesystem/search.js +9 -8
  21. package/dist/filesystem/search.js.map +1 -1
  22. package/dist/index.js +28 -18
  23. package/dist/index.js.map +1 -1
  24. package/dist/opencode/automation/desktop-plugin.js +69 -0
  25. package/dist/opencode/automation/desktop-plugin.js.map +1 -0
  26. package/dist/opencode/automation/desktop-plugin.test.js +155 -0
  27. package/dist/opencode/automation/desktop-plugin.test.js.map +1 -0
  28. package/dist/opencode/automation-plugin.js +90 -24
  29. package/dist/opencode/automation-plugin.js.map +1 -1
  30. package/dist/opencode/automation-plugin.test.js +14 -1
  31. package/dist/opencode/automation-plugin.test.js.map +1 -1
  32. package/dist/opencode/compatibility/contract-fixture.js +13 -1
  33. package/dist/opencode/compatibility/contract-fixture.js.map +1 -1
  34. package/dist/opencode/compatibility/location.js +13 -0
  35. package/dist/opencode/compatibility/location.js.map +1 -1
  36. package/dist/opencode/compatibility/location.test.js +44 -0
  37. package/dist/opencode/compatibility/location.test.js.map +1 -1
  38. package/dist/opencode/compatibility/runtime.js.map +1 -1
  39. package/dist/opencode/compatibility/transport.js +3 -0
  40. package/dist/opencode/compatibility/transport.js.map +1 -1
  41. package/dist/opencode/compatibility/transport.test.js +40 -0
  42. package/dist/opencode/compatibility/transport.test.js.map +1 -1
  43. package/dist/opencode/desktop-plugin-installation.js +103 -0
  44. package/dist/opencode/desktop-plugin-installation.js.map +1 -0
  45. package/dist/opencode/desktop-plugin-lifecycle.js +117 -0
  46. package/dist/opencode/desktop-plugin-lifecycle.js.map +1 -0
  47. package/dist/opencode/desktop-plugin-lifecycle.test.js +180 -0
  48. package/dist/opencode/desktop-plugin-lifecycle.test.js.map +1 -0
  49. package/dist/opencode/desktop-plugin-paths.js +30 -0
  50. package/dist/opencode/desktop-plugin-paths.js.map +1 -0
  51. package/dist/opencode/desktop-plugin-paths.test.js +46 -0
  52. package/dist/opencode/desktop-plugin-paths.test.js.map +1 -0
  53. package/dist/opencode/desktop-plugin-presence.js +42 -0
  54. package/dist/opencode/desktop-plugin-presence.js.map +1 -0
  55. package/dist/opencode/pruning-installation.js +3 -63
  56. package/dist/opencode/pruning-installation.js.map +1 -1
  57. package/dist/opencode/pruning-lifecycle.js +3 -64
  58. package/dist/opencode/pruning-lifecycle.js.map +1 -1
  59. package/dist/opencode/session-pruning/presence.js +1 -41
  60. package/dist/opencode/session-pruning/presence.js.map +1 -1
  61. package/dist/permissions/opencode-yolo-metadata.js +3 -1
  62. package/dist/permissions/opencode-yolo-metadata.js.map +1 -1
  63. package/dist/permissions/opencode-yolo-metadata.test.js +2 -2
  64. package/dist/permissions/opencode-yolo-metadata.test.js.map +1 -1
  65. package/dist/plugins/automation/plugin.mjs +504 -0
  66. package/dist/plugins/session-pruning/plugin.mjs +1 -1
  67. package/dist/server/routes/automation-plugin.js +31 -4
  68. package/dist/server/routes/automation-plugin.js.map +1 -1
  69. package/dist/server/routes/automation-plugin.test.js +46 -0
  70. package/dist/server/routes/automation-plugin.test.js.map +1 -1
  71. package/dist/server/routes/filesystem.js +3 -3
  72. package/dist/server/routes/filesystem.js.map +1 -1
  73. package/dist/server/routes/workspaces.js +13 -7
  74. package/dist/server/routes/workspaces.js.map +1 -1
  75. package/dist/server/routes/workspaces.test.js +31 -0
  76. package/dist/server/routes/workspaces.test.js.map +1 -1
  77. package/dist/server/routes/worktrees.js +232 -41
  78. package/dist/server/routes/worktrees.js.map +1 -1
  79. package/dist/server/routes/worktrees.test.js +113 -40
  80. package/dist/server/routes/worktrees.test.js.map +1 -1
  81. package/dist/workspaces/__tests__/git-worktrees.test.js +2 -2
  82. package/dist/workspaces/__tests__/git-worktrees.test.js.map +1 -1
  83. package/dist/workspaces/__tests__/native-worktree-fixture.js +22 -0
  84. package/dist/workspaces/__tests__/native-worktree-fixture.js.map +1 -0
  85. package/dist/workspaces/git-status.test.js +24 -1
  86. package/dist/workspaces/git-status.test.js.map +1 -1
  87. package/dist/workspaces/git-worktrees.js +37 -204
  88. package/dist/workspaces/git-worktrees.js.map +1 -1
  89. package/dist/workspaces/host-opencode-service.test.js +58 -1
  90. package/dist/workspaces/host-opencode-service.test.js.map +1 -1
  91. package/dist/workspaces/instance-events.js +5 -0
  92. package/dist/workspaces/instance-events.js.map +1 -1
  93. package/dist/workspaces/instance-events.test.js +36 -1
  94. package/dist/workspaces/instance-events.test.js.map +1 -1
  95. package/dist/workspaces/manager.js +124 -14
  96. package/dist/workspaces/manager.js.map +1 -1
  97. package/dist/workspaces/manager.test.js +25 -0
  98. package/dist/workspaces/manager.test.js.map +1 -1
  99. package/dist/workspaces/native-service-start.js +13 -0
  100. package/dist/workspaces/native-service-start.js.map +1 -0
  101. package/dist/workspaces/native-service-start.test.js +65 -0
  102. package/dist/workspaces/native-service-start.test.js.map +1 -0
  103. package/dist/workspaces/native-worktrees.js +140 -0
  104. package/dist/workspaces/native-worktrees.js.map +1 -0
  105. package/dist/workspaces/opencode-cli-service.js +10 -2
  106. package/dist/workspaces/opencode-cli-service.js.map +1 -1
  107. package/dist/workspaces/opencode-service.js +24 -2
  108. package/dist/workspaces/opencode-service.js.map +1 -1
  109. package/dist/workspaces/opencode-service.test.js +62 -0
  110. package/dist/workspaces/opencode-service.test.js.map +1 -1
  111. package/dist/workspaces/project-session-families.js +376 -0
  112. package/dist/workspaces/project-session-families.js.map +1 -0
  113. package/dist/workspaces/project-session-families.test.js +341 -0
  114. package/dist/workspaces/project-session-families.test.js.map +1 -0
  115. package/dist/workspaces/worktree-directory.js +36 -18
  116. package/dist/workspaces/worktree-directory.js.map +1 -1
  117. package/dist/workspaces/worktree-directory.test.js +123 -5
  118. package/dist/workspaces/worktree-directory.test.js.map +1 -1
  119. package/dist/workspaces/worktree-inventory.js +79 -0
  120. package/dist/workspaces/worktree-inventory.js.map +1 -0
  121. package/dist/workspaces/worktree-inventory.test.js +156 -0
  122. package/dist/workspaces/worktree-inventory.test.js.map +1 -0
  123. package/dist/workspaces/worktree-map.js +2 -5
  124. package/dist/workspaces/worktree-map.js.map +1 -1
  125. package/dist/workspaces/wsl-opencode-service.test.js +16 -2
  126. package/dist/workspaces/wsl-opencode-service.test.js.map +1 -1
  127. package/package.json +4 -3
  128. package/public/assets/App-I9uNKt0K.js +54 -0
  129. package/public/assets/App-I9uNKt0K.js.map +1 -0
  130. package/public/assets/{FilesTab-DY3Vr-3r.js → FilesTab-_xb_Aq0c.js} +3 -3
  131. package/public/assets/{FilesTab-DY3Vr-3r.js.map → FilesTab-_xb_Aq0c.js.map} +1 -1
  132. package/public/assets/{GitChangesTab-BD6CJngE.js → GitChangesTab-Cz0RckYn.js} +3 -3
  133. package/public/assets/{GitChangesTab-BD6CJngE.js.map → GitChangesTab-Cz0RckYn.js.map} +1 -1
  134. package/public/assets/{SplitFilePanel-BdY6d_6m.js → SplitFilePanel-DVkVS5C0.js} +2 -2
  135. package/public/assets/{SplitFilePanel-BdY6d_6m.js.map → SplitFilePanel-DVkVS5C0.js.map} +1 -1
  136. package/public/assets/{StatusTab-C-_2yaPa.js → StatusTab-DU1H4ngp.js} +2 -2
  137. package/public/assets/{StatusTab-C-_2yaPa.js.map → StatusTab-DU1H4ngp.js.map} +1 -1
  138. package/public/assets/{align-justify-DI8VTZ4G.js → align-justify-Czy9hp3K.js} +2 -2
  139. package/public/assets/{align-justify-DI8VTZ4G.js.map → align-justify-Czy9hp3K.js.map} +1 -1
  140. package/public/assets/{bundle-full-D_M65Eb_.js → bundle-full-CMakdq_6.js} +2 -2
  141. package/public/assets/{bundle-full-D_M65Eb_.js.map → bundle-full-CMakdq_6.js.map} +1 -1
  142. package/public/assets/{client-state-CWCzCOz6.js → client-state-DGbupmmR.js} +2 -2
  143. package/public/assets/{client-state-CWCzCOz6.js.map → client-state-DGbupmmR.js.map} +1 -1
  144. package/public/assets/{diff-viewer-CGPsYEr3.js → diff-viewer-CSOlh3i1.js} +2 -2
  145. package/public/assets/{diff-viewer-CGPsYEr3.js.map → diff-viewer-CSOlh3i1.js.map} +1 -1
  146. package/public/assets/index-B0BLbbT3.js +2 -0
  147. package/public/assets/{index-BxRFHpJd.js.map → index-B0BLbbT3.js.map} +1 -1
  148. package/public/assets/index-B52s_Dh2.js +2 -0
  149. package/public/assets/index-B52s_Dh2.js.map +1 -0
  150. package/public/assets/index-B8W9is7z.js +2 -0
  151. package/public/assets/index-B8W9is7z.js.map +1 -0
  152. package/public/assets/index-Bn8a8ymh.js +2 -0
  153. package/public/assets/index-Bn8a8ymh.js.map +1 -0
  154. package/public/assets/index-CWaDoBhJ.js +2 -0
  155. package/public/assets/index-CWaDoBhJ.js.map +1 -0
  156. package/public/assets/{index-MeFffHqb.css → index-CXEtEGDL.css} +1 -1
  157. package/public/assets/index-CbuT2QEY.js +2 -0
  158. package/public/assets/index-CbuT2QEY.js.map +1 -0
  159. package/public/assets/{index-Ddjkirek.js → index-Cq5Hfa6i.js} +2 -2
  160. package/public/assets/{index-Ddjkirek.js.map → index-Cq5Hfa6i.js.map} +1 -1
  161. package/public/assets/index-D03eJbIp.js +2 -0
  162. package/public/assets/index-D03eJbIp.js.map +1 -0
  163. package/public/assets/index-DDK0Fk7j.js +2 -0
  164. package/public/assets/index-DDK0Fk7j.js.map +1 -0
  165. package/public/assets/index-DftCJdT3.js +2 -0
  166. package/public/assets/index-DftCJdT3.js.map +1 -0
  167. package/public/assets/index-_N9V2vB3.js +3 -0
  168. package/public/assets/index-_N9V2vB3.js.map +1 -0
  169. package/public/assets/index-zo6cKyNQ.js +2 -0
  170. package/public/assets/index-zo6cKyNQ.js.map +1 -0
  171. package/public/assets/{loading-Gqh6NPUr.js → loading-B2-6L7aO.js} +2 -2
  172. package/public/assets/{loading-Gqh6NPUr.js.map → loading-B2-6L7aO.js.map} +1 -1
  173. package/public/assets/main-pZWMgVoG.js +42 -0
  174. package/public/assets/main-pZWMgVoG.js.map +1 -0
  175. package/public/assets/{markdown-BWnjyvnX.js → markdown-CH9bocix.js} +4 -4
  176. package/public/assets/{markdown-BWnjyvnX.js.map → markdown-CH9bocix.js.map} +1 -1
  177. package/public/assets/monaco-viewer-Bv1s0h2m.js +27 -0
  178. package/public/assets/monaco-viewer-Bv1s0h2m.js.map +1 -0
  179. package/public/assets/{startup-state-settings-card-C4E2Itop.js → startup-state-settings-card-mmovljyz.js} +2 -2
  180. package/public/assets/{startup-state-settings-card-C4E2Itop.js.map → startup-state-settings-card-mmovljyz.js.map} +1 -1
  181. package/public/assets/{terminal-square-C3wutdV0.js → terminal-square-U8R46SS0.js} +2 -2
  182. package/public/assets/{terminal-square-C3wutdV0.js.map → terminal-square-U8R46SS0.js.map} +1 -1
  183. package/public/assets/tool-call-AnfwOPww.js +60 -0
  184. package/public/assets/tool-call-AnfwOPww.js.map +1 -0
  185. package/public/assets/unified-picker-DtvQUEiv.js +2 -0
  186. package/public/assets/unified-picker-DtvQUEiv.js.map +1 -0
  187. package/public/assets/{wrap-text-CkBxzt04.js → wrap-text-Bh1AU9Re.js} +2 -2
  188. package/public/assets/{wrap-text-CkBxzt04.js.map → wrap-text-Bh1AU9Re.js.map} +1 -1
  189. package/public/index.html +4 -4
  190. package/public/loading.html +4 -4
  191. package/public/sw.js +1 -1
  192. package/public/sw.js.map +1 -1
  193. package/public/assets/App-BROhwPo9.js +0 -54
  194. package/public/assets/App-BROhwPo9.js.map +0 -1
  195. package/public/assets/index-B8-lAqjr.js +0 -2
  196. package/public/assets/index-B8-lAqjr.js.map +0 -1
  197. package/public/assets/index-BeUewQym.js +0 -2
  198. package/public/assets/index-BeUewQym.js.map +0 -1
  199. package/public/assets/index-BxRFHpJd.js +0 -2
  200. package/public/assets/index-Bzv1kU-S.js +0 -2
  201. package/public/assets/index-Bzv1kU-S.js.map +0 -1
  202. package/public/assets/index-C9tI4CRG.js +0 -2
  203. package/public/assets/index-C9tI4CRG.js.map +0 -1
  204. package/public/assets/index-CGYHFZ6F.js +0 -2
  205. package/public/assets/index-CGYHFZ6F.js.map +0 -1
  206. package/public/assets/index-CMEAjBFp.js +0 -2
  207. package/public/assets/index-CMEAjBFp.js.map +0 -1
  208. package/public/assets/index-Cazypvyc.js +0 -2
  209. package/public/assets/index-Cazypvyc.js.map +0 -1
  210. package/public/assets/index-CwqzofWP.js +0 -2
  211. package/public/assets/index-CwqzofWP.js.map +0 -1
  212. package/public/assets/index-Da9yOa6q.js +0 -2
  213. package/public/assets/index-Da9yOa6q.js.map +0 -1
  214. package/public/assets/index-HHgvEOAH.js +0 -3
  215. package/public/assets/index-HHgvEOAH.js.map +0 -1
  216. package/public/assets/main-Cbx7KdTr.js +0 -38
  217. package/public/assets/main-Cbx7KdTr.js.map +0 -1
  218. package/public/assets/monaco-viewer-BEJIiZWL.js +0 -27
  219. package/public/assets/monaco-viewer-BEJIiZWL.js.map +0 -1
  220. package/public/assets/tool-call-DNsAQ_m4.js +0 -60
  221. package/public/assets/tool-call-DNsAQ_m4.js.map +0 -1
  222. package/public/assets/unified-picker-tB7y17Qz.js +0 -2
  223. package/public/assets/unified-picker-tB7y17Qz.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"transport.test.js","sourceRoot":"","sources":["../../../src/opencode/compatibility/transport.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEhD,IAAI,CAAC,wFAAwF,EAAE,KAAK,IAAI,EAAE;IACxG,MAAM,IAAI,GAA2D,EAAE,CAAA;IACvE,MAAM,IAAI,GAAG,EAAE,EAAE,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,CAAA;IACrI,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QAC7C,IAAI,GAAG,GAAG,EAAE,CAAA;QACZ,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,GAAG;YAAE,GAAG,IAAI,IAAI,CAAA;QACzC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,SAAS,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QACtG,IAAI,CAAC,IAAI,CAAC,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E,CAAC,CAAA;IACzJ,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,mCAAmC,CAAC,EAAE,iBAAiB,CAAC,CAAA;AACzF,CAAC,CAAC,CAAA","sourcesContent":["import assert from \"node:assert/strict\"\nimport { createServer } from \"node:http\"\nimport { once } from \"node:events\"\nimport { test } from \"node:test\"\nimport { OpenCode } from \"@opencode/client\"\nimport type { Endpoint } from \"@opencode/client/service\"\nimport { rememberRuntime } from \"./runtime\"\nimport { createRuntimeFetch } from \"./transport\"\n\ntest(\"the pinned client uses the earlier wire contract and retains admission/list timestamps\", async () => {\n const seen: Array<{ method: string; path: string; body: unknown }> = []\n const item = { id: \"inbox-fixture\", sessionID: \"s\", type: \"user\", payload: { text: \"fixture\" }, delivery: \"queue\", timeCreated: 123 }\n const server = createServer(async (req, res) => {\n let raw = \"\"\n for await (const data of req) raw += data\n assert.equal(req.headers.authorization, `Basic ${Buffer.from(\"opencode:fixture\").toString(\"base64\")}`)\n seen.push({ method: req.method!, path: req.url!, body: raw ? JSON.parse(raw) : undefined })\n res.setHeader(\"content-type\", \"application/json\")\n if (req.url === \"/api/session/s/prompt\") return res.end(JSON.stringify({ data: item }))\n if (req.url === \"/api/session/s/inbox\") return res.end(JSON.stringify({ data: [item] }))\n if (req.url === \"/api/session/s/fork\") return res.end(JSON.stringify({ data: { id: \"fork\" } }))\n if (req.url?.startsWith(\"/api/session/s/interrupt\")) return res.end(\"{}\")\n res.writeHead(204).end()\n })\n server.listen(0, \"127.0.0.1\")\n await once(server, \"listening\")\n const endpoint: Endpoint = { url: `http://127.0.0.1:${(server.address() as { port: number }).port}`, auth: { type: \"basic\", username: \"opencode\", password: \"fixture\" } }\n rememberRuntime(endpoint, { version: \"2.0.3\", pid: 1, discovery: \"health\" })\n const client = OpenCode.make({ baseUrl: endpoint.url, fetch: createRuntimeFetch(endpoint) })\n try {\n assert.equal((await client.session.prompt({ sessionID: \"s\", text: \"fixture\" })).time.created, 123)\n assert.equal((await client.session.inbox.list({ sessionID: \"s\" }))[0].time.created, 123)\n await client.permission.reply({ sessionID: \"s\", requestID: \"p\", decision: \"once\" })\n await client.session.command({ sessionID: \"s\", name: \"test\", text: \"args\", delivery: \"queue\" })\n await client.session.fork({ sessionID: \"s\", before: \"m\" })\n await client.session.interrupt({ sessionID: \"s\", resume: true })\n await client.session.inbox.update({ sessionID: \"s\", inboxID: \"i\", delivery: \"steer\" })\n await client.session.form.cancel({ sessionID: \"s\", formID: \"f\" })\n await client.session.instructions.entry.remove({ sessionID: \"s\", key: \"voice\" })\n assert.deepEqual(seen.slice(2), [\n { method: \"POST\", path: \"/api/session/s/permission/p/reply\", body: { reply: \"once\" } },\n { method: \"POST\", path: \"/api/session/s/command\", body: { command: \"test\", text: \"args\", delivery: \"queue\" } },\n { method: \"POST\", path: \"/api/session/s/fork\", body: { boundary: { type: \"before\", messageID: \"m\" } } },\n { method: \"POST\", path: \"/api/session/s/interrupt?continue=true\", body: undefined },\n { method: \"POST\", path: \"/api/session/s/inbox/i/steer\", body: undefined },\n { method: \"POST\", path: \"/api/session/s/form/f/cancel\", body: undefined },\n { method: \"DELETE\", path: \"/api/session/s/instructions/entries/voice\", body: undefined },\n ])\n } finally { server.closeAllConnections(); await new Promise<void>(resolve => server.close(() => resolve())) }\n})\n\ntest(\"errors never retry a mutation, unsupported fields are rejected, and abort/auth are preserved\", async () => {\n const endpoint: Endpoint = { url: \"http://127.0.0.1:4321\" }\n rememberRuntime(endpoint, { version: \"2.0.3\", pid: 2, discovery: \"health\" })\n let calls = 0\n for (const status of [400, 401, 404, 500]) {\n const client = OpenCode.make({ baseUrl: endpoint.url, fetch: createRuntimeFetch(endpoint, async () => { calls++; return new Response(null, { status }) }) })\n await assert.rejects(client.session.update({ sessionID: \"s\", title: \"title\" }))\n }\n assert.equal(calls, 4)\n const client = OpenCode.make({ baseUrl: endpoint.url, fetch: createRuntimeFetch(endpoint, async () => { calls++; return new Response(null, { status: 204 }) }) })\n await assert.rejects(client.session.update({ sessionID: \"s\", title: \"title\", permissions: [] }), (error: Error) => {\n assert.match(String((error as Error & { cause?: unknown }).cause), /title-only/)\n return true\n })\n assert.equal(calls, 4)\n const controller = new AbortController()\n controller.abort()\n const transport = createRuntimeFetch(endpoint, async (_url, init) => {\n assert.equal(init?.redirect, \"error\")\n init?.signal?.throwIfAborted()\n throw new Error(\"unexpected live request\")\n })\n await assert.rejects(transport(new Request(`${endpoint.url}/api/session/s/wait`, { method: \"POST\", signal: controller.signal })), { name: \"AbortError\" })\n await assert.rejects(transport(\"http://127.0.0.1:4322/api/session\"), /origin mismatch/)\n})\n"]}
1
+ {"version":3,"file":"transport.test.js","sourceRoot":"","sources":["../../../src/opencode/compatibility/transport.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,IAAI,CAAC,+FAA+F,EAAE,KAAK,IAAI,EAAE;IAC/G,KAAK,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI;QACxC,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC;QAClC,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC;QAClC,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC;QAC9B,CAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,CAAC;KAC/B,EAAE,CAAC;QACX,MAAM,QAAQ,GAAa,EAAE,GAAG,EAAE,uBAAuB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Content":["import assert from \"node:assert/strict\"\nimport { createServer } from \"node:http\"\nimport { once } from \"node:events\"\nimport { test } from \"node:test\"\nimport { OpenCode } from \"@opencode/client\"\nimport type { Endpoint } from \"@opencode/client/service\"\nimport { rememberRuntime } from \"./runtime\"\nimport { createRuntimeFetch } from \"./transport\"\nimport { modernContractFixture } from \"./contract-fixture\"\n\ntest(\"the pinned status client follows the discovered route across legacy, modern and info runtimes\", async () => {\n for (const [version, discovery, route] of [\n [\"2.0.0\", \"health\", \"/api/health\"],\n [\"2.0.4\", \"status\", \"/api/status\"],\n [\"2.0.7\", \"info\", \"/api/info\"],\n [\"future-release\", \"info\", \"/api/info\"],\n ] as const) {\n const endpoint: Endpoint = { url: \"http://127.0.0.1:4321\", auth: { type: \"basic\", username: \"opencode\", password: \"fixture\" } }\n rememberRuntime(endpoint, { version, pid: 123, discovery })\n const seen: string[] = []\n const fetch = createRuntimeFetch(endpoint, async (input, init) => {\n const path = new URL(String(input)).pathname\n seen.push(path)\n assert.equal(init?.redirect, \"error\")\n assert.equal(new Headers(init?.headers).get(\"authorization\"), `Basic ${Buffer.from(\"opencode:fixture\").toString(\"base64\")}`)\n if (path === \"/openapi.json\") return Response.json(modernContractFixture)\n assert.equal(path, route)\n return Response.json(discovery === \"health\" ? { healthy: true, version, pid: 123 } : { version, pid: 123, urls: [endpoint.url] })\n })\n const client = OpenCode.make({ baseUrl: endpoint.url, fetch })\n assert.deepEqual(await client.server.status(), { version, pid: 123, urls: [endpoint.url] })\n assert.deepEqual(seen, discovery === \"info\" ? [\"/openapi.json\", route] : [route])\n }\n})\n\ntest(\"info translation is GET-only and does not probe alternate routes on failure\", async () => {\n const endpoint: Endpoint = { url: \"http://127.0.0.1:4321\" }\n rememberRuntime(endpoint, { version: \"2.0.7\", pid: 123, discovery: \"info\" })\n const seen: string[] = []\n const fetch = createRuntimeFetch(endpoint, async (input, init) => {\n const path = new URL(String(input)).pathname\n seen.push(`${init?.method ?? \"GET\"} ${path}`)\n return path === \"/openapi.json\" ? Response.json(modernContractFixture) : new Response(null, { status: 404 })\n })\n const client = OpenCode.make({ baseUrl: endpoint.url, fetch })\n await assert.rejects(client.server.status())\n await fetch(`${endpoint.url}/api/status`, { method: \"POST\" })\n assert.deepEqual(seen, [\"GET /openapi.json\", \"GET /api/info\", \"POST /api/status\"])\n})\n\ntest(\"the pinned client uses the earlier wire contract and retains admission/list timestamps\", async () => {\n const seen: Array<{ method: string; path: string; body: unknown }> = []\n const item = { id: \"inbox-fixture\", sessionID: \"s\", type: \"user\", payload: { text: \"fixture\" }, delivery: \"queue\", timeCreated: 123 }\n const server = createServer(async (req, res) => {\n let raw = \"\"\n for await (const data of req) raw += data\n assert.equal(req.headers.authorization, `Basic ${Buffer.from(\"opencode:fixture\").toString(\"base64\")}`)\n seen.push({ method: req.method!, path: req.url!, body: raw ? JSON.parse(raw) : undefined })\n res.setHeader(\"content-type\", \"application/json\")\n if (req.url === \"/api/session/s/prompt\") return res.end(JSON.stringify({ data: item }))\n if (req.url === \"/api/session/s/inbox\") return res.end(JSON.stringify({ data: [item] }))\n if (req.url === \"/api/session/s/fork\") return res.end(JSON.stringify({ data: { id: \"fork\" } }))\n if (req.url?.startsWith(\"/api/session/s/interrupt\")) return res.end(\"{}\")\n res.writeHead(204).end()\n })\n server.listen(0, \"127.0.0.1\")\n await once(server, \"listening\")\n const endpoint: Endpoint = { url: `http://127.0.0.1:${(server.address() as { port: number }).port}`, auth: { type: \"basic\", username: \"opencode\", password: \"fixture\" } }\n rememberRuntime(endpoint, { version: \"2.0.3\", pid: 1, discovery: \"health\" })\n const client = OpenCode.make({ baseUrl: endpoint.url, fetch: createRuntimeFetch(endpoint) })\n try {\n assert.equal((await client.session.prompt({ sessionID: \"s\", text: \"fixture\" })).time.created, 123)\n assert.equal((await client.session.inbox.list({ sessionID: \"s\" }))[0].time.created, 123)\n await client.permission.reply({ sessionID: \"s\", requestID: \"p\", decision: \"once\" })\n await client.session.command({ sessionID: \"s\", name: \"test\", text: \"args\", delivery: \"queue\" })\n await client.session.fork({ sessionID: \"s\", before: \"m\" })\n await client.session.interrupt({ sessionID: \"s\", resume: true })\n await client.session.inbox.update({ sessionID: \"s\", inboxID: \"i\", delivery: \"steer\" })\n await client.session.form.cancel({ sessionID: \"s\", formID: \"f\" })\n await client.session.instructions.entry.remove({ sessionID: \"s\", key: \"voice\" })\n assert.deepEqual(seen.slice(2), [\n { method: \"POST\", path: \"/api/session/s/permission/p/reply\", body: { reply: \"once\" } },\n { method: \"POST\", path: \"/api/session/s/command\", body: { command: \"test\", text: \"args\", delivery: \"queue\" } },\n { method: \"POST\", path: \"/api/session/s/fork\", body: { boundary: { type: \"before\", messageID: \"m\" } } },\n { method: \"POST\", path: \"/api/session/s/interrupt?continue=true\", body: undefined },\n { method: \"POST\", path: \"/api/session/s/inbox/i/steer\", body: undefined },\n { method: \"POST\", path: \"/api/session/s/form/f/cancel\", body: undefined },\n { method: \"DELETE\", path: \"/api/session/s/instructions/entries/voice\", body: undefined },\n ])\n } finally { server.closeAllConnections(); await new Promise<void>(resolve => server.close(() => resolve())) }\n})\n\ntest(\"errors never retry a mutation, unsupported fields are rejected, and abort/auth are preserved\", async () => {\n const endpoint: Endpoint = { url: \"http://127.0.0.1:4321\" }\n rememberRuntime(endpoint, { version: \"2.0.3\", pid: 2, discovery: \"health\" })\n let calls = 0\n for (const status of [400, 401, 404, 500]) {\n const client = OpenCode.make({ baseUrl: endpoint.url, fetch: createRuntimeFetch(endpoint, async () => { calls++; return new Response(null, { status }) }) })\n await assert.rejects(client.session.update({ sessionID: \"s\", title: \"title\" }))\n }\n assert.equal(calls, 4)\n const client = OpenCode.make({ baseUrl: endpoint.url, fetch: createRuntimeFetch(endpoint, async () => { calls++; return new Response(null, { status: 204 }) }) })\n await assert.rejects(client.session.update({ sessionID: \"s\", title: \"title\", permissions: [] }), (error: Error) => {\n assert.match(String((error as Error & { cause?: unknown }).cause), /title-only/)\n return true\n })\n assert.equal(calls, 4)\n const controller = new AbortController()\n controller.abort()\n const transport = createRuntimeFetch(endpoint, async (_url, init) => {\n assert.equal(init?.redirect, \"error\")\n init?.signal?.throwIfAborted()\n throw new Error(\"unexpected live request\")\n })\n await assert.rejects(transport(new Request(`${endpoint.url}/api/session/s/wait`, { method: \"POST\", signal: controller.signal })), { name: \"AbortError\" })\n await assert.rejects(transport(\"http://127.0.0.1:4322/api/session\"), /origin mismatch/)\n})\n"]}
@@ -0,0 +1,103 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { mkdir, readFile, rename, rm, writeFile, utimes } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
+ import { PRESENCE_INTERVAL_MS } from "./desktop-plugin-presence";
6
+ import { isLegacyAutomationPlugin } from "./automation-plugin";
7
+ // Retain the explicitly recorded managed storage on upgrade: another backend
8
+ // may still be heartbeating there. Only parse our exact generated entry shape.
9
+ function managedStorage(feature, existing, marker, paths) {
10
+ if (!existing?.startsWith(marker))
11
+ return undefined;
12
+ const match = /^import \{ desktopPlugin \} from ("(?:[^"\\]|\\.)*")\nexport default desktopPlugin\(("(?:[^"\\]|\\.)*")\)\n$/.exec(existing.slice(marker.length));
13
+ if (!match)
14
+ throw new Error("Invalid managed CodeNomad plugin entry");
15
+ const url = new URL(JSON.parse(match[1]));
16
+ const nativeLeases = JSON.parse(match[2]);
17
+ const nativePaths = paths.nativeData ? path.posix : path;
18
+ const nativeDirectory = nativePaths.dirname(nativeLeases);
19
+ const plugin = paths.nativeData ? decodeURIComponent(url.pathname) : fileURLToPath(url);
20
+ if (url.protocol !== "file:" || url.search || url.hash || (paths.nativeData && url.hostname)
21
+ || !nativePaths.isAbsolute(nativeDirectory) || nativePaths.basename(nativeDirectory) !== feature
22
+ || nativePaths.basename(nativeLeases) !== "presence" || nativePaths.dirname(plugin) !== nativeDirectory
23
+ || !/^[a-f\d]{64}\.mjs$/.test(nativePaths.basename(plugin))) {
24
+ throw new Error("Invalid managed CodeNomad plugin storage");
25
+ }
26
+ if (!paths.nativeData)
27
+ return { directory: nativeDirectory, nativeDirectory };
28
+ const uncRoot = /^(\\\\wsl(?:\.localhost|\$)\\[^\\]+)/i.exec(paths.config)?.[1];
29
+ if (!uncRoot || nativeDirectory.includes("\\"))
30
+ throw new Error("Invalid managed WSL plugin storage");
31
+ return { directory: `${uncRoot}${nativeDirectory.replaceAll("/", "\\")}`, nativeDirectory };
32
+ }
33
+ export async function installDesktopPluginPresence(feature, bundle, paths, assertCurrent = () => { }) {
34
+ assertCurrent();
35
+ const marker = `// Managed by CodeNomad: ${feature.replaceAll("-", " ")} lifecycle v1\n`;
36
+ const hash = createHash("sha256").update(bundle).digest("hex");
37
+ const entry = path.join(paths.config, "plugins", `codenomad-${feature}.ts`);
38
+ const existing = await readFile(entry, "utf8").catch((error) => {
39
+ if (error.code !== "ENOENT")
40
+ throw error;
41
+ return undefined;
42
+ });
43
+ assertCurrent();
44
+ if (existing !== undefined && !existing.startsWith(marker)
45
+ && !(feature === "automation" && isLegacyAutomationPlugin(existing))) {
46
+ throw new Error(`Existing plugin entry is not managed by CodeNomad: ${entry}`);
47
+ }
48
+ const storage = managedStorage(feature, existing, marker, paths);
49
+ const directory = storage?.directory ?? path.join(paths.data, feature);
50
+ const nativeDirectory = storage?.nativeDirectory ?? (paths.nativeData ? path.posix.join(paths.nativeData, feature) : directory);
51
+ const leases = path.join(directory, "presence");
52
+ const nativeLeases = paths.nativeData ? path.posix.join(nativeDirectory, "presence") : leases;
53
+ const plugin = path.join(directory, `${hash}.mjs`);
54
+ const nativeUrl = new URL("file:///");
55
+ nativeUrl.pathname = `${nativeDirectory}/${hash}.mjs`;
56
+ const pluginUrl = paths.nativeData ? nativeUrl.href : pathToFileURL(plugin).href;
57
+ const source = `${marker}import { desktopPlugin } from ${JSON.stringify(pluginUrl)}\nexport default desktopPlugin(${JSON.stringify(nativeLeases)})\n`;
58
+ await mkdir(leases, { recursive: true });
59
+ assertCurrent();
60
+ await mkdir(path.dirname(entry), { recursive: true });
61
+ assertCurrent();
62
+ // Immutable, content-addressed payloads keep running instances independent of upgrades.
63
+ await writeFile(plugin, bundle, { flag: "wx" }).catch((error) => {
64
+ if (error.code !== "EEXIST")
65
+ throw error;
66
+ });
67
+ assertCurrent();
68
+ const lease = path.join(leases, `${randomUUID()}.lease`);
69
+ try {
70
+ await writeFile(lease, "");
71
+ assertCurrent();
72
+ if (existing !== source) {
73
+ const temporary = `${entry}.${randomUUID()}.tmp`;
74
+ try {
75
+ await writeFile(temporary, source);
76
+ assertCurrent();
77
+ await rename(temporary, entry);
78
+ }
79
+ finally {
80
+ await rm(temporary, { force: true });
81
+ }
82
+ }
83
+ assertCurrent();
84
+ }
85
+ catch (error) {
86
+ await rm(lease, { force: true });
87
+ throw error;
88
+ }
89
+ let pending = Promise.resolve();
90
+ const timer = setInterval(() => {
91
+ pending = pending.then(async () => {
92
+ const now = new Date();
93
+ await utimes(lease, now, now);
94
+ }).catch(() => { });
95
+ }, PRESENCE_INTERVAL_MS);
96
+ timer.unref();
97
+ return async () => {
98
+ clearInterval(timer);
99
+ await pending;
100
+ await rm(lease, { force: true });
101
+ };
102
+ }
103
+ //# sourceMappingURL=desktop-plugin-installation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"desktop-plugin-installation.js","sourceRoot":"","sources":["../../src/opencode/desktop-plugin-installation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACjF,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAU9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,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;YAAC,CAAC;QACpD,CAAC;QACD,aAAa,EAAE,CAAA;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QAChC,MAAM,KAAK,CAAA;IACb,CAAC;IACD,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;IAC/B,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC7B,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;YAChC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;YACtB,MAAM,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;QAC/B,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;IACpB,CAAC,EAAE,oBAAoB,CAAC,CAAA;IACxB,KAAK,CAAC,KAAK,EAAE,CAAA;IACb,OAAO,KAAK,IAAI,EAAE;QAChB,aAAa,CAAC,KAAK,CAAC,CAAA;QACpB,MAAM,OAAO,CAAA;QACb,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAClC,CAAC,CAAA;AACH,CAAC","sourcesContent":["import { createHash, randomUUID } from \"node:crypto\"\nimport { mkdir, readFile, rename, rm, writeFile, utimes } from \"node:fs/promises\"\nimport path from \"node:path\"\nimport { fileURLToPath, pathToFileURL } from \"node:url\"\nimport { PRESENCE_INTERVAL_MS } from \"./desktop-plugin-presence\"\nimport { isLegacyAutomationPlugin } from \"./automation-plugin\"\n\nexport interface DesktopPluginPaths {\n config: string\n data: string\n // WSL uses Linux paths in the entry, UNC paths only for host filesystem I/O.\n nativeData?: string\n}\nexport type DesktopPluginFeature = \"session-pruning\" | \"automation\"\n\n// Retain the explicitly recorded managed storage on upgrade: another backend\n// may still be heartbeating there. Only parse our exact generated entry shape.\nfunction managedStorage(feature: DesktopPluginFeature, existing: string | undefined, marker: string, paths: DesktopPluginPaths) {\n if (!existing?.startsWith(marker)) return undefined\n const match = /^import \\{ desktopPlugin \\} from (\"(?:[^\"\\\\]|\\\\.)*\")\\nexport default desktopPlugin\\((\"(?:[^\"\\\\]|\\\\.)*\")\\)\\n$/.exec(existing.slice(marker.length))\n if (!match) throw new Error(\"Invalid managed CodeNomad plugin entry\")\n const url = new URL(JSON.parse(match[1]) as string)\n const nativeLeases: string = JSON.parse(match[2])\n const nativePaths = paths.nativeData ? path.posix : path\n const nativeDirectory = nativePaths.dirname(nativeLeases)\n const plugin = paths.nativeData ? decodeURIComponent(url.pathname) : fileURLToPath(url)\n if (url.protocol !== \"file:\" || url.search || url.hash || (paths.nativeData && url.hostname)\n || !nativePaths.isAbsolute(nativeDirectory) || nativePaths.basename(nativeDirectory) !== feature\n || nativePaths.basename(nativeLeases) !== \"presence\" || nativePaths.dirname(plugin) !== nativeDirectory\n || !/^[a-f\\d]{64}\\.mjs$/.test(nativePaths.basename(plugin))) {\n throw new Error(\"Invalid managed CodeNomad plugin storage\")\n }\n if (!paths.nativeData) return { directory: nativeDirectory, nativeDirectory }\n const uncRoot = /^(\\\\\\\\wsl(?:\\.localhost|\\$)\\\\[^\\\\]+)/i.exec(paths.config)?.[1]\n if (!uncRoot || nativeDirectory.includes(\"\\\\\")) throw new Error(\"Invalid managed WSL plugin storage\")\n return { directory: `${uncRoot}${nativeDirectory.replaceAll(\"/\", \"\\\\\")}`, nativeDirectory }\n}\n\nexport async function installDesktopPluginPresence(\n feature: DesktopPluginFeature,\n bundle: Uint8Array,\n paths: DesktopPluginPaths,\n assertCurrent: () => void = () => {},\n) {\n assertCurrent()\n const marker = `// Managed by CodeNomad: ${feature.replaceAll(\"-\", \" \")} lifecycle v1\\n`\n const hash = createHash(\"sha256\").update(bundle).digest(\"hex\")\n const entry = path.join(paths.config, \"plugins\", `codenomad-${feature}.ts`)\n const existing = await readFile(entry, \"utf8\").catch((error: NodeJS.ErrnoException) => {\n if (error.code !== \"ENOENT\") throw error\n return undefined\n })\n assertCurrent()\n if (existing !== undefined && !existing.startsWith(marker)\n && !(feature === \"automation\" && isLegacyAutomationPlugin(existing))) {\n throw new Error(`Existing plugin entry is not managed by CodeNomad: ${entry}`)\n }\n const storage = managedStorage(feature, existing, marker, paths)\n const directory = storage?.directory ?? path.join(paths.data, feature)\n const nativeDirectory = storage?.nativeDirectory ?? (paths.nativeData ? path.posix.join(paths.nativeData, feature) : directory)\n const leases = path.join(directory, \"presence\")\n const nativeLeases = paths.nativeData ? path.posix.join(nativeDirectory, \"presence\") : leases\n const plugin = path.join(directory, `${hash}.mjs`)\n const nativeUrl = new URL(\"file:///\")\n nativeUrl.pathname = `${nativeDirectory}/${hash}.mjs`\n const pluginUrl = paths.nativeData ? nativeUrl.href : pathToFileURL(plugin).href\n const source = `${marker}import { desktopPlugin } from ${JSON.stringify(pluginUrl)}\\nexport default desktopPlugin(${JSON.stringify(nativeLeases)})\\n`\n await mkdir(leases, { recursive: true })\n assertCurrent()\n await mkdir(path.dirname(entry), { recursive: true })\n assertCurrent()\n // Immutable, content-addressed payloads keep running instances independent of upgrades.\n await writeFile(plugin, bundle, { flag: \"wx\" }).catch((error: NodeJS.ErrnoException) => {\n if (error.code !== \"EEXIST\") throw error\n })\n assertCurrent()\n const lease = path.join(leases, `${randomUUID()}.lease`)\n try {\n await writeFile(lease, \"\")\n assertCurrent()\n if (existing !== source) {\n const temporary = `${entry}.${randomUUID()}.tmp`\n try {\n await writeFile(temporary, source)\n assertCurrent()\n await rename(temporary, entry)\n } finally { await rm(temporary, { force: true }) }\n }\n assertCurrent()\n } catch (error) {\n await rm(lease, { force: true })\n throw error\n }\n let pending = Promise.resolve()\n const timer = setInterval(() => {\n pending = pending.then(async () => {\n const now = new Date()\n await utimes(lease, now, now)\n }).catch(() => {})\n }, PRESENCE_INTERVAL_MS)\n timer.unref()\n return async () => {\n clearInterval(timer)\n await pending\n await rm(lease, { force: true })\n }\n}\n"]}
@@ -0,0 +1,117 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { installDesktopPluginPresence } from "./desktop-plugin-installation";
3
+ // One backend lease per namespace. Temporary claims keep overlapping connection
4
+ // attempts independent; only successful preparation retains the backend lease.
5
+ export class DesktopPluginLifecycle {
6
+ constructor(feature, readBundle = () => readFile(new URL(`../plugins/${feature}/plugin.mjs`, import.meta.url))
7
+ .catch((error) => {
8
+ if (error.code !== "ENOENT")
9
+ throw error;
10
+ return readFile(new URL(`../../dist/plugins/${feature}/plugin.mjs`, import.meta.url));
11
+ })) {
12
+ this.feature = feature;
13
+ this.readBundle = readBundle;
14
+ this.installations = new Map();
15
+ this.stopped = false;
16
+ }
17
+ async start(paths) {
18
+ const prepared = await this.prepare(paths, () => { });
19
+ try {
20
+ prepared.commit();
21
+ }
22
+ finally {
23
+ await prepared.release();
24
+ }
25
+ }
26
+ async prepare(paths, assertCurrent) {
27
+ const check = () => {
28
+ if (this.stopped)
29
+ throw new Error("Desktop plugin lifecycle has stopped");
30
+ assertCurrent();
31
+ };
32
+ check();
33
+ const key = paths.config;
34
+ const claim = Symbol();
35
+ let entry = this.installations.get(key);
36
+ if (!entry) {
37
+ const claims = new Map();
38
+ const current = () => {
39
+ if (this.stopped)
40
+ throw new Error("Desktop plugin lifecycle has stopped");
41
+ for (const validate of claims.values()) {
42
+ try {
43
+ validate();
44
+ return;
45
+ }
46
+ catch { /* Another attempt may still own this installation. */ }
47
+ }
48
+ throw new Error("Desktop plugin preparation is no longer current");
49
+ };
50
+ entry = {
51
+ claims, committed: false,
52
+ pending: Promise.resolve().then(async () => {
53
+ current();
54
+ const bundle = await this.readBundle();
55
+ current();
56
+ return installDesktopPluginPresence(this.feature, bundle, paths, current);
57
+ }),
58
+ };
59
+ this.installations.set(key, entry);
60
+ const installation = entry;
61
+ void entry.pending.catch(() => {
62
+ if (this.installations.get(key) === installation)
63
+ this.installations.delete(key);
64
+ });
65
+ }
66
+ const installation = entry;
67
+ installation.claims.set(claim, check);
68
+ const release = async () => {
69
+ installation.claims.delete(claim);
70
+ if (installation.committed || installation.claims.size)
71
+ return;
72
+ if (this.installations.get(key) === installation)
73
+ this.installations.delete(key);
74
+ await this.close(installation);
75
+ };
76
+ try {
77
+ await installation.pending;
78
+ check();
79
+ return {
80
+ commit: () => { check(); installation.committed = true; },
81
+ release,
82
+ };
83
+ }
84
+ catch (error) {
85
+ await release();
86
+ throw error;
87
+ }
88
+ }
89
+ close(installation) {
90
+ return installation.closing ??= installation.pending.then(dispose => dispose(), () => { });
91
+ }
92
+ async stop() {
93
+ this.stopped = true;
94
+ const pending = [...this.installations.values()].map(installation => this.close(installation));
95
+ this.installations.clear();
96
+ await Promise.all(pending);
97
+ }
98
+ }
99
+ // Commit both feature claims together. A failed/stale attempt relinquishes only
100
+ // its new claims, never another attempt's committed lease or another backend's.
101
+ export async function prepareDesktopPluginPresence(paths, assertCurrent, lifecycles) {
102
+ const prepared = [];
103
+ try {
104
+ assertCurrent();
105
+ prepared.push(await lifecycles.pruning.prepare(paths, assertCurrent));
106
+ assertCurrent();
107
+ if (lifecycles.automation)
108
+ prepared.push(await lifecycles.automation.prepare(paths, assertCurrent));
109
+ assertCurrent();
110
+ for (const entry of prepared)
111
+ entry.commit();
112
+ }
113
+ finally {
114
+ await Promise.all(prepared.map(entry => entry.release()));
115
+ }
116
+ }
117
+ //# sourceMappingURL=desktop-plugin-lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"desktop-plugin-lifecycle.js","sourceRoot":"","sources":["../../src/opencode/desktop-plugin-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,4BAA4B,EAAsD,MAAM,+BAA+B,CAAA;AAUhI,gFAAgF;AAChF,+EAA+E;AAC/E,MAAM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CAAC,aAAa,CAAC,KAAK,EAAE,CAAA;QAC1B,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAC5B,CAAC;CACF;AAED,gFAAgF;AAChF,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,KAAyB,EACzB,aAAyB,EACzB,UAAoF;IAEpF,MAAM,QAAQ,GAAqB,EAAE,CAAA;IACrC,IAAI,CAAC;QACH,aAAa,EAAE,CAAA;QACf,QAAQ,CAAC,IAAI,CAAC,MAAM,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAA;QACrE,aAAa,EAAE,CAAA;QACf,IAAI,UAAU,CAAC,UAAU;YAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAA;QACnG,aAAa,EAAE,CAAA;QACf,KAAK,MAAM,KAAK,IAAI,QAAQ;YAAE,KAAK,CAAC,MAAM,EAAE,CAAA;IAC9C,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;IAC3D,CAAC;AACH,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\"\nimport { installDesktopPluginPresence, type DesktopPluginFeature, type DesktopPluginPaths } from \"./desktop-plugin-installation\"\n\ntype PreparedPlugin = { commit(): void; release(): Promise<void> }\ntype Installation = {\n claims: Map<symbol, () => void>\n committed: boolean\n pending: Promise<() => Promise<void>>\n closing?: Promise<void>\n}\n\n// One backend lease per namespace. Temporary claims keep overlapping connection\n// attempts independent; only successful preparation retains the backend lease.\nexport class DesktopPluginLifecycle {\n private readonly installations = new Map<string, Installation>()\n private stopped = false\n\n constructor(\n private readonly feature: DesktopPluginFeature,\n private readonly readBundle = () => readFile(new URL(`../plugins/${feature}/plugin.mjs`, import.meta.url))\n .catch((error: NodeJS.ErrnoException) => {\n if (error.code !== \"ENOENT\") throw error\n return readFile(new URL(`../../dist/plugins/${feature}/plugin.mjs`, import.meta.url))\n }),\n ) {}\n\n async start(paths: DesktopPluginPaths): Promise<void> {\n const prepared = await this.prepare(paths, () => {})\n try { prepared.commit() }\n finally { await prepared.release() }\n }\n\n async prepare(paths: DesktopPluginPaths, assertCurrent: () => void): Promise<PreparedPlugin> {\n const check = () => {\n if (this.stopped) throw new Error(\"Desktop plugin lifecycle has stopped\")\n assertCurrent()\n }\n check()\n const key = paths.config\n const claim = Symbol()\n let entry = this.installations.get(key)\n if (!entry) {\n const claims = new Map<symbol, () => void>()\n const current = (): void => {\n if (this.stopped) throw new Error(\"Desktop plugin lifecycle has stopped\")\n for (const validate of claims.values()) {\n try { validate(); return } catch { /* Another attempt may still own this installation. */ }\n }\n throw new Error(\"Desktop plugin preparation is no longer current\")\n }\n entry = {\n claims, committed: false,\n pending: Promise.resolve().then(async () => {\n current()\n const bundle = await this.readBundle()\n current()\n return installDesktopPluginPresence(this.feature, bundle, paths, current)\n }),\n }\n this.installations.set(key, entry)\n const installation = entry\n void entry.pending.catch(() => {\n if (this.installations.get(key) === installation) this.installations.delete(key)\n })\n }\n const installation = entry\n installation.claims.set(claim, check)\n const release = async () => {\n installation.claims.delete(claim)\n if (installation.committed || installation.claims.size) return\n if (this.installations.get(key) === installation) this.installations.delete(key)\n await this.close(installation)\n }\n try {\n await installation.pending\n check()\n return {\n commit: () => { check(); installation.committed = true },\n release,\n }\n } catch (error) {\n await release()\n throw error\n }\n }\n\n private close(installation: Installation): Promise<void> {\n return installation.closing ??= installation.pending.then(dispose => dispose(), () => {})\n }\n\n async stop(): Promise<void> {\n this.stopped = true\n const pending = [...this.installations.values()].map(installation => this.close(installation))\n this.installations.clear()\n await Promise.all(pending)\n }\n}\n\n// Commit both feature claims together. A failed/stale attempt relinquishes only\n// its new claims, never another attempt's committed lease or another backend's.\nexport async function prepareDesktopPluginPresence(\n paths: DesktopPluginPaths,\n assertCurrent: () => void,\n lifecycles: { pruning: DesktopPluginLifecycle; automation?: DesktopPluginLifecycle },\n): Promise<void> {\n const prepared: PreparedPlugin[] = []\n try {\n assertCurrent()\n prepared.push(await lifecycles.pruning.prepare(paths, assertCurrent))\n assertCurrent()\n if (lifecycles.automation) prepared.push(await lifecycles.automation.prepare(paths, assertCurrent))\n assertCurrent()\n for (const entry of prepared) entry.commit()\n } finally {\n await Promise.all(prepared.map(entry => entry.release()))\n }\n}\n"]}
@@ -0,0 +1,180 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { existsSync, readdirSync } from "node:fs";
4
+ import { mkdtemp, readdir, readFile, rm } from "node:fs/promises";
5
+ import os from "node:os";
6
+ import path from "node:path";
7
+ import { OpenCodeSharedService } from "../workspaces/opencode-service";
8
+ import { DesktopPluginLifecycle, prepareDesktopPluginPresence } from "./desktop-plugin-lifecycle";
9
+ import { installDesktopPluginPresence } from "./desktop-plugin-installation";
10
+ import { resolveDesktopPluginPaths } from "./desktop-plugin-paths";
11
+ const bundle = Buffer.from("export const desktopPlugin = () => ({ id: 'isolated-fixture' })");
12
+ const pathsFor = (root) => ({ config: root, data: path.join(root, ".codenomad") });
13
+ const leasesFor = (root, feature) => path.join(root, ".codenomad", feature, "presence");
14
+ const entryFor = (root, feature) => path.join(root, "plugins", `codenomad-${feature}.ts`);
15
+ function gate() {
16
+ let release;
17
+ const pending = new Promise(resolve => { release = resolve; });
18
+ return { pending, release };
19
+ }
20
+ test("connection A cannot install after root discovery is superseded by connection B", async (t) => {
21
+ const root = await mkdtemp(path.join(os.tmpdir(), "codenomad-plugin-stale-roots-"));
22
+ const a = path.join(root, "daemon-a"), b = path.join(root, "daemon-b");
23
+ const paused = gate(), resume = gate();
24
+ let reads = 0, automationReads = 0;
25
+ const pruning = new DesktopPluginLifecycle("session-pruning", async () => {
26
+ if (++reads === 1) {
27
+ paused.release();
28
+ await resume.pending;
29
+ }
30
+ return bundle;
31
+ });
32
+ const automation = new DesktopPluginLifecycle("automation", async () => { automationReads++; return bundle; });
33
+ const firstEndpoint = { url: "http://127.0.0.1:4321", auth: { type: "basic", username: "fixture", password: "fixture" } };
34
+ let active = firstEndpoint;
35
+ const makeClient = options => ({
36
+ config: { get: async () => [{ type: "directory", path: options.baseUrl === firstEndpoint.url ? a : b }] },
37
+ });
38
+ const service = new OpenCodeSharedService({ headers: () => ({ authorization: "Basic fixture" }), makeClient });
39
+ t.after(async () => {
40
+ resume.release();
41
+ await Promise.all([pruning.stop(), automation.stop(), service.shutdown()]);
42
+ await rm(root, { recursive: true, force: true });
43
+ });
44
+ const first = service.client({
45
+ kind: "lifecycle", identity: "isolated-roots",
46
+ lifecycle: { discover: async () => active, ensure: async () => active },
47
+ prepareDesktopPlugins: async (connection) => {
48
+ const paths = await resolveDesktopPluginPaths(connection, { kind: "host", platform: process.platform, binary: "fixture" });
49
+ await prepareDesktopPluginPresence(paths, connection.assertCurrent, { pruning, automation });
50
+ return true;
51
+ },
52
+ });
53
+ const rejected = assert.rejects(first, /no longer current|connection changed/);
54
+ await paused.pending;
55
+ active = { ...firstEndpoint, url: "http://127.0.0.1:4322" };
56
+ service.invalidate();
57
+ await service.acquire();
58
+ resume.release();
59
+ await rejected;
60
+ assert.equal(automationReads, 1, "Only valid connection B may start the second installer");
61
+ for (const feature of ["session-pruning", "automation"]) {
62
+ await assert.rejects(readFile(entryFor(a, feature)), { code: "ENOENT" });
63
+ await assert.rejects(readdir(leasesFor(a, feature)), { code: "ENOENT" });
64
+ assert.equal((await readdir(leasesFor(b, feature))).length, 1);
65
+ }
66
+ });
67
+ test("stale preparation releases its first lease but preserves another backend's lease", async (t) => {
68
+ const root = await mkdtemp(path.join(os.tmpdir(), "codenomad-plugin-stale-claim-"));
69
+ const paths = pathsFor(root);
70
+ const other = await installDesktopPluginPresence("session-pruning", bundle, paths);
71
+ const paused = gate(), resume = gate();
72
+ let current = true;
73
+ const pruning = new DesktopPluginLifecycle("session-pruning", async () => bundle);
74
+ const automation = new DesktopPluginLifecycle("automation", async () => {
75
+ paused.release();
76
+ await resume.pending;
77
+ return bundle;
78
+ });
79
+ t.after(async () => {
80
+ resume.release();
81
+ await Promise.all([pruning.stop(), automation.stop()]);
82
+ await other();
83
+ await rm(root, { recursive: true, force: true });
84
+ });
85
+ const preparation = prepareDesktopPluginPresence(paths, () => { if (!current)
86
+ throw new Error("stale connection"); }, { pruning, automation });
87
+ const rejected = assert.rejects(preparation, /no longer current|stale connection/);
88
+ await paused.pending;
89
+ assert.equal((await readdir(leasesFor(root, "session-pruning"))).length, 2);
90
+ current = false;
91
+ resume.release();
92
+ await rejected;
93
+ assert.equal((await readdir(leasesFor(root, "session-pruning"))).length, 1);
94
+ await assert.rejects(readFile(entryFor(root, "automation")), { code: "ENOENT" });
95
+ });
96
+ test("a valid overlapping claim for the same namespace survives the stale attempt", async (t) => {
97
+ const root = await mkdtemp(path.join(os.tmpdir(), "codenomad-plugin-concurrent-claim-"));
98
+ const paused = gate(), resume = gate();
99
+ const pruning = new DesktopPluginLifecycle("session-pruning", async () => {
100
+ paused.release();
101
+ await resume.pending;
102
+ return bundle;
103
+ });
104
+ const automation = new DesktopPluginLifecycle("automation", async () => bundle);
105
+ t.after(async () => {
106
+ resume.release();
107
+ await Promise.all([pruning.stop(), automation.stop()]);
108
+ await rm(root, { recursive: true, force: true });
109
+ });
110
+ let currentA = true;
111
+ const first = prepareDesktopPluginPresence(pathsFor(root), () => { if (!currentA)
112
+ throw new Error("stale A"); }, { pruning, automation });
113
+ const rejected = assert.rejects(first, /stale A/);
114
+ await paused.pending;
115
+ const second = prepareDesktopPluginPresence(pathsFor(root), () => { }, { pruning, automation });
116
+ currentA = false;
117
+ resume.release();
118
+ await Promise.all([rejected, second]);
119
+ for (const feature of ["session-pruning", "automation"]) {
120
+ assert.equal((await readdir(leasesFor(root, feature))).length, 1);
121
+ }
122
+ });
123
+ test("a stale attempt cannot release a previously committed lease of this backend", async (t) => {
124
+ const root = await mkdtemp(path.join(os.tmpdir(), "codenomad-plugin-committed-claim-"));
125
+ const paused = gate(), resume = gate();
126
+ const pruning = new DesktopPluginLifecycle("session-pruning", async () => bundle);
127
+ const automation = new DesktopPluginLifecycle("automation", async () => {
128
+ paused.release();
129
+ await resume.pending;
130
+ return bundle;
131
+ });
132
+ t.after(async () => {
133
+ resume.release();
134
+ await Promise.all([pruning.stop(), automation.stop()]);
135
+ await rm(root, { recursive: true, force: true });
136
+ });
137
+ await pruning.start(pathsFor(root));
138
+ const originalLeases = await readdir(leasesFor(root, "session-pruning"));
139
+ let current = true;
140
+ const pending = prepareDesktopPluginPresence(pathsFor(root), () => { if (!current)
141
+ throw new Error("stale"); }, { pruning, automation });
142
+ const rejected = assert.rejects(pending, /no longer current|stale/);
143
+ await paused.pending;
144
+ current = false;
145
+ resume.release();
146
+ await rejected;
147
+ assert.deepEqual(await readdir(leasesFor(root, "session-pruning")), originalLeases);
148
+ await assert.rejects(readFile(entryFor(root, "automation")), { code: "ENOENT" });
149
+ });
150
+ test("stopping during pending installation cannot publish or resurrect a lease", async (t) => {
151
+ const root = await mkdtemp(path.join(os.tmpdir(), "codenomad-plugin-stop-pending-"));
152
+ const paused = gate(), resume = gate();
153
+ const lifecycle = new DesktopPluginLifecycle("automation", async () => {
154
+ paused.release();
155
+ await resume.pending;
156
+ return bundle;
157
+ });
158
+ t.after(async () => { resume.release(); await lifecycle.stop(); await rm(root, { recursive: true, force: true }); });
159
+ const starting = lifecycle.start(pathsFor(root));
160
+ const rejected = assert.rejects(starting, /has stopped/);
161
+ await paused.pending;
162
+ const stopping = lifecycle.stop();
163
+ resume.release();
164
+ await Promise.all([stopping, rejected]);
165
+ await assert.rejects(readFile(entryFor(root, "automation")), { code: "ENOENT" });
166
+ await assert.rejects(readdir(leasesFor(root, "automation")), { code: "ENOENT" });
167
+ await assert.rejects(lifecycle.start(pathsFor(root)), /has stopped/);
168
+ });
169
+ test("installer invalidation after lease creation removes that lease before publication", async (t) => {
170
+ const root = await mkdtemp(path.join(os.tmpdir(), "codenomad-plugin-install-fence-"));
171
+ t.after(() => rm(root, { recursive: true, force: true }));
172
+ const leases = leasesFor(root, "automation");
173
+ await assert.rejects(installDesktopPluginPresence("automation", bundle, pathsFor(root), () => {
174
+ if (existsSync(leases) && readdirSync(leases).length)
175
+ throw new Error("connection superseded");
176
+ }), /connection superseded/);
177
+ assert.deepEqual(await readdir(leases), []);
178
+ await assert.rejects(readFile(entryFor(root, "automation")), { code: "ENOENT" });
179
+ });
180
+ //# sourceMappingURL=desktop-plugin-lifecycle.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"desktop-plugin-lifecycle.test.js","sourceRoot":"","sources":["../../src/opencode/desktop-plugin-lifecycle.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B,OAAO,EAAE,qBAAqB,EAA0C,MAAM,gCAAgC,CAAA;AAC9G,OAAO,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAA;AACjG,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAA;AAC5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAA;AAElE,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,iEAAiE,CAAC,CAAA;AAC7F,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,I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,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,iCAAiC,CAAC,CAAC,CAAA;IACrF,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACzD,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;IAC5C,MAAM,MAAM,CAAC,OAAO,CAAC,4BAA4B,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE;QAC3F,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;IAChG,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAA;IAC5B,MAAM,CAAC,SAAS,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;IAC3C,MAAM,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;AAClF,CAAC,CAAC,CAAA","sourcesContent":["import assert from \"node:assert/strict\"\nimport { test } from \"node:test\"\nimport { existsSync, readdirSync } from \"node:fs\"\nimport { mkdtemp, readdir, readFile, rm } from \"node:fs/promises\"\nimport os from \"node:os\"\nimport path from \"node:path\"\nimport type { OpenCodeClient } from \"@opencode/client\"\nimport type { Endpoint } from \"@opencode/client/service\"\nimport { OpenCodeSharedService, type OpenCodeSharedServiceDependencies } from \"../workspaces/opencode-service\"\nimport { DesktopPluginLifecycle, prepareDesktopPluginPresence } from \"./desktop-plugin-lifecycle\"\nimport { installDesktopPluginPresence } from \"./desktop-plugin-installation\"\nimport { resolveDesktopPluginPaths } from \"./desktop-plugin-paths\"\n\nconst bundle = Buffer.from(\"export const desktopPlugin = () => ({ id: 'isolated-fixture' })\")\nconst pathsFor = (root: string) => ({ config: root, data: path.join(root, \".codenomad\") })\nconst leasesFor = (root: string, feature: string) => path.join(root, \".codenomad\", feature, \"presence\")\nconst entryFor = (root: string, feature: string) => path.join(root, \"plugins\", `codenomad-${feature}.ts`)\nfunction gate() {\n let release!: () => void\n const pending = new Promise<void>(resolve => { release = resolve })\n return { pending, release }\n}\n\ntest(\"connection A cannot install after root discovery is superseded by connection B\", async (t) => {\n const root = await mkdtemp(path.join(os.tmpdir(), \"codenomad-plugin-stale-roots-\"))\n const a = path.join(root, \"daemon-a\"), b = path.join(root, \"daemon-b\")\n const paused = gate(), resume = gate()\n let reads = 0, automationReads = 0\n const pruning = new DesktopPluginLifecycle(\"session-pruning\", async () => {\n if (++reads === 1) { paused.release(); await resume.pending }\n return bundle\n })\n const automation = new DesktopPluginLifecycle(\"automation\", async () => { automationReads++; return bundle })\n const firstEndpoint: Endpoint = { url: \"http://127.0.0.1:4321\", auth: { type: \"basic\", username: \"fixture\", password: \"fixture\" } }\n let active = firstEndpoint\n const makeClient: OpenCodeSharedServiceDependencies[\"makeClient\"] = options => ({\n config: { get: async () => [{ type: \"directory\", path: options.baseUrl === firstEndpoint.url ? a : b }] },\n }) as unknown as OpenCodeClient\n const service = new OpenCodeSharedService({ headers: () => ({ authorization: \"Basic fixture\" }), makeClient })\n t.after(async () => {\n resume.release()\n await Promise.all([pruning.stop(), automation.stop(), service.shutdown()])\n await rm(root, { recursive: true, force: true })\n })\n const first = service.client({\n kind: \"lifecycle\", identity: \"isolated-roots\",\n lifecycle: { discover: async () => active, ensure: async () => active },\n prepareDesktopPlugins: async connection => {\n const paths = await resolveDesktopPluginPaths(connection, { kind: \"host\", platform: process.platform, binary: \"fixture\" })\n await prepareDesktopPluginPresence(paths, connection.assertCurrent, { pruning, automation })\n return true\n },\n })\n const rejected = assert.rejects(first, /no longer current|connection changed/)\n await paused.pending\n active = { ...firstEndpoint, url: \"http://127.0.0.1:4322\" }\n service.invalidate()\n await service.acquire()\n resume.release()\n await rejected\n assert.equal(automationReads, 1, \"Only valid connection B may start the second installer\")\n for (const feature of [\"session-pruning\", \"automation\"]) {\n await assert.rejects(readFile(entryFor(a, feature)), { code: \"ENOENT\" })\n await assert.rejects(readdir(leasesFor(a, feature)), { code: \"ENOENT\" })\n assert.equal((await readdir(leasesFor(b, feature))).length, 1)\n }\n})\n\ntest(\"stale preparation releases its first lease but preserves another backend's lease\", async (t) => {\n const root = await mkdtemp(path.join(os.tmpdir(), \"codenomad-plugin-stale-claim-\"))\n const paths = pathsFor(root)\n const other = await installDesktopPluginPresence(\"session-pruning\", bundle, paths)\n const paused = gate(), resume = gate()\n let current = true\n const pruning = new DesktopPluginLifecycle(\"session-pruning\", async () => bundle)\n const automation = new DesktopPluginLifecycle(\"automation\", async () => {\n paused.release(); await resume.pending; return bundle\n })\n t.after(async () => {\n resume.release()\n await Promise.all([pruning.stop(), automation.stop()])\n await other()\n await rm(root, { recursive: true, force: true })\n })\n const preparation = prepareDesktopPluginPresence(paths, () => { if (!current) throw new Error(\"stale connection\") }, { pruning, automation })\n const rejected = assert.rejects(preparation, /no longer current|stale connection/)\n await paused.pending\n assert.equal((await readdir(leasesFor(root, \"session-pruning\"))).length, 2)\n current = false\n resume.release()\n await rejected\n assert.equal((await readdir(leasesFor(root, \"session-pruning\"))).length, 1)\n await assert.rejects(readFile(entryFor(root, \"automation\")), { code: \"ENOENT\" })\n})\n\ntest(\"a valid overlapping claim for the same namespace survives the stale attempt\", async (t) => {\n const root = await mkdtemp(path.join(os.tmpdir(), \"codenomad-plugin-concurrent-claim-\"))\n const paused = gate(), resume = gate()\n const pruning = new DesktopPluginLifecycle(\"session-pruning\", async () => {\n paused.release(); await resume.pending; return bundle\n })\n const automation = new DesktopPluginLifecycle(\"automation\", async () => bundle)\n t.after(async () => {\n resume.release()\n await Promise.all([pruning.stop(), automation.stop()])\n await rm(root, { recursive: true, force: true })\n })\n let currentA = true\n const first = prepareDesktopPluginPresence(pathsFor(root), () => { if (!currentA) throw new Error(\"stale A\") }, { pruning, automation })\n const rejected = assert.rejects(first, /stale A/)\n await paused.pending\n const second = prepareDesktopPluginPresence(pathsFor(root), () => {}, { pruning, automation })\n currentA = false\n resume.release()\n await Promise.all([rejected, second])\n for (const feature of [\"session-pruning\", \"automation\"]) {\n assert.equal((await readdir(leasesFor(root, feature))).length, 1)\n }\n})\n\ntest(\"a stale attempt cannot release a previously committed lease of this backend\", async (t) => {\n const root = await mkdtemp(path.join(os.tmpdir(), \"codenomad-plugin-committed-claim-\"))\n const paused = gate(), resume = gate()\n const pruning = new DesktopPluginLifecycle(\"session-pruning\", async () => bundle)\n const automation = new DesktopPluginLifecycle(\"automation\", async () => {\n paused.release(); await resume.pending; return bundle\n })\n t.after(async () => {\n resume.release()\n await Promise.all([pruning.stop(), automation.stop()])\n await rm(root, { recursive: true, force: true })\n })\n await pruning.start(pathsFor(root))\n const originalLeases = await readdir(leasesFor(root, \"session-pruning\"))\n let current = true\n const pending = prepareDesktopPluginPresence(pathsFor(root), () => { if (!current) throw new Error(\"stale\") }, { pruning, automation })\n const rejected = assert.rejects(pending, /no longer current|stale/)\n await paused.pending\n current = false\n resume.release()\n await rejected\n assert.deepEqual(await readdir(leasesFor(root, \"session-pruning\")), originalLeases)\n await assert.rejects(readFile(entryFor(root, \"automation\")), { code: \"ENOENT\" })\n})\n\ntest(\"stopping during pending installation cannot publish or resurrect a lease\", async (t) => {\n const root = await mkdtemp(path.join(os.tmpdir(), \"codenomad-plugin-stop-pending-\"))\n const paused = gate(), resume = gate()\n const lifecycle = new DesktopPluginLifecycle(\"automation\", async () => {\n paused.release(); await resume.pending; return bundle\n })\n t.after(async () => { resume.release(); await lifecycle.stop(); await rm(root, { recursive: true, force: true }) })\n const starting = lifecycle.start(pathsFor(root))\n const rejected = assert.rejects(starting, /has stopped/)\n await paused.pending\n const stopping = lifecycle.stop()\n resume.release()\n await Promise.all([stopping, rejected])\n await assert.rejects(readFile(entryFor(root, \"automation\")), { code: \"ENOENT\" })\n await assert.rejects(readdir(leasesFor(root, \"automation\")), { code: \"ENOENT\" })\n await assert.rejects(lifecycle.start(pathsFor(root)), /has stopped/)\n})\n\ntest(\"installer invalidation after lease creation removes that lease before publication\", async (t) => {\n const root = await mkdtemp(path.join(os.tmpdir(), \"codenomad-plugin-install-fence-\"))\n t.after(() => rm(root, { recursive: true, force: true }))\n const leases = leasesFor(root, \"automation\")\n await assert.rejects(installDesktopPluginPresence(\"automation\", bundle, pathsFor(root), () => {\n if (existsSync(leases) && readdirSync(leases).length) throw new Error(\"connection superseded\")\n }), /connection superseded/)\n assert.deepEqual(await readdir(leases), [])\n await assert.rejects(readFile(entryFor(root, \"automation\")), { code: \"ENOENT\" })\n})\n"]}
@@ -0,0 +1,30 @@
1
+ import path from "node:path";
2
+ // Native config.get returns discovery sources in precedence order. The first
3
+ // directory is the global discovery root, including OPENCODE_CONFIG_DIR when
4
+ // set in the *running daemon*. CLI debug paths describes the caller instead.
5
+ export async function resolveDesktopPluginPaths(connection, launch, deadlineAt = Date.now() + 15_000) {
6
+ const entries = await connection.client.config.get(undefined, {
7
+ signal: AbortSignal.timeout(Math.max(1, deadlineAt - Date.now())),
8
+ });
9
+ connection.assertCurrent();
10
+ const directory = Array.isArray(entries)
11
+ ? entries.find(entry => entry?.type === "directory")?.path
12
+ : undefined;
13
+ const paths = launch.kind === "wsl" || launch.platform !== "win32" ? path.posix : path.win32;
14
+ if (typeof directory !== "string" || !paths.isAbsolute(directory) || directory.includes("\0")) {
15
+ throw new Error("Connected OpenCode daemon did not report an absolute global plugin discovery directory");
16
+ }
17
+ const config = paths.normalize(directory);
18
+ // The API does not expose the daemon's data root. Keep CodeNomad-owned
19
+ // immutable payloads and leases under its reported config root, outside the
20
+ // auto-discovered plugins directory, without deriving another environment.
21
+ const data = paths.join(config, ".codenomad");
22
+ if (launch.kind !== "wsl")
23
+ return { config, data };
24
+ if (config.includes("\\") || config.startsWith("//")) {
25
+ throw new Error("Connected WSL daemon reported a path that cannot be accessed through its distro");
26
+ }
27
+ const unc = (directory) => `\\\\wsl.localhost\\${launch.distro}${directory.replaceAll("/", "\\")}`;
28
+ return { config: unc(config), data: unc(data), nativeData: data };
29
+ }
30
+ //# sourceMappingURL=desktop-plugin-paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"desktop-plugin-paths.js","sourceRoot":"","sources":["../../src/opencode/desktop-plugin-paths.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAK5B,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,UAA+D,EAC/D,MAAyB,EACzB,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM;IAEhC,MAAM,OAAO,GAAY,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE;QACrE,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;KAClE,CAAC,CAAA;IACF,UAAU,CAAC,aAAa,EAAE,CAAA;IAC1B,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QACtC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,WAAW,CAAC,EAAE,IAAI;QAC1D,CAAC,CAAC,SAAS,CAAA;IACb,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,KAAK,KAAK,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAA;IAC5F,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9F,MAAM,IAAI,KAAK,CAAC,wFAAwF,CAAC,CAAA;IAC3G,CAAC;IACD,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;IACzC,uEAAuE;IACvE,4EAA4E;IAC5E,2EAA2E;IAC3E,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IAC7C,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK;QAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;IAClD,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,iFAAiF,CAAC,CAAA;IACpG,CAAC;IACD,MAAM,GAAG,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC,sBAAsB,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAA;IAC1G,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAA;AACnE,CAAC","sourcesContent":["import path from \"node:path\"\nimport type { ServiceConnection } from \"../workspaces/opencode-service\"\nimport type { ServiceLaunchSpec } from \"../workspaces/spawn\"\nimport type { DesktopPluginPaths } from \"./desktop-plugin-installation\"\n\n// Native config.get returns discovery sources in precedence order. The first\n// directory is the global discovery root, including OPENCODE_CONFIG_DIR when\n// set in the *running daemon*. CLI debug paths describes the caller instead.\nexport async function resolveDesktopPluginPaths(\n connection: Pick<ServiceConnection, \"client\" | \"assertCurrent\">,\n launch: ServiceLaunchSpec,\n deadlineAt = Date.now() + 15_000,\n): Promise<DesktopPluginPaths> {\n const entries: unknown = await connection.client.config.get(undefined, {\n signal: AbortSignal.timeout(Math.max(1, deadlineAt - Date.now())),\n })\n connection.assertCurrent()\n const directory = Array.isArray(entries)\n ? entries.find(entry => entry?.type === \"directory\")?.path\n : undefined\n const paths = launch.kind === \"wsl\" || launch.platform !== \"win32\" ? path.posix : path.win32\n if (typeof directory !== \"string\" || !paths.isAbsolute(directory) || directory.includes(\"\\0\")) {\n throw new Error(\"Connected OpenCode daemon did not report an absolute global plugin discovery directory\")\n }\n const config = paths.normalize(directory)\n // The API does not expose the daemon's data root. Keep CodeNomad-owned\n // immutable payloads and leases under its reported config root, outside the\n // auto-discovered plugins directory, without deriving another environment.\n const data = paths.join(config, \".codenomad\")\n if (launch.kind !== \"wsl\") return { config, data }\n if (config.includes(\"\\\\\") || config.startsWith(\"//\")) {\n throw new Error(\"Connected WSL daemon reported a path that cannot be accessed through its distro\")\n }\n const unc = (directory: string) => `\\\\\\\\wsl.localhost\\\\${launch.distro}${directory.replaceAll(\"/\", \"\\\\\")}`\n return { config: unc(config), data: unc(data), nativeData: data }\n}\n"]}