borgmcp 1.1.14 → 2.0.1

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 (459) hide show
  1. package/CONTRIBUTING.md +15 -0
  2. package/LICENSE +201 -33
  3. package/NOTICE +2 -0
  4. package/README.md +86 -37
  5. package/SECURITY.md +7 -0
  6. package/dist/agent-runtime.d.ts.map +1 -0
  7. package/dist/agent-runtime.js +63 -1
  8. package/dist/agent-runtime.js.map +1 -0
  9. package/dist/assimilate-cmd.d.ts +96 -17
  10. package/dist/assimilate-cmd.d.ts.map +1 -0
  11. package/dist/assimilate-cmd.js +1396 -48
  12. package/dist/assimilate-cmd.js.map +1 -0
  13. package/dist/assimilate-deps.d.ts.map +1 -0
  14. package/dist/assimilate-deps.js +384 -3
  15. package/dist/assimilate-deps.js.map +1 -0
  16. package/dist/assimilate-guard.d.ts +5 -7
  17. package/dist/assimilate-guard.d.ts.map +1 -0
  18. package/dist/assimilate-guard.js +60 -2
  19. package/dist/assimilate-guard.js.map +1 -0
  20. package/dist/assimilate-welcome.d.ts +1 -1
  21. package/dist/assimilate-welcome.d.ts.map +1 -0
  22. package/dist/assimilate-welcome.js +32 -2
  23. package/dist/assimilate-welcome.js.map +1 -0
  24. package/dist/auth-env.d.ts +7 -50
  25. package/dist/auth-env.d.ts.map +1 -0
  26. package/dist/auth-env.js +22 -1
  27. package/dist/auth-env.js.map +1 -0
  28. package/dist/backends/launch-all-pastelist.d.ts.map +1 -0
  29. package/dist/backends/launch-all-pastelist.js +11 -4
  30. package/dist/backends/launch-all-pastelist.js.map +1 -0
  31. package/dist/backends/launch-all-tmux.d.ts.map +1 -0
  32. package/dist/backends/launch-all-tmux.js +49 -1
  33. package/dist/backends/launch-all-tmux.js.map +1 -0
  34. package/dist/backends/launch-all-windows.d.ts.map +1 -0
  35. package/dist/backends/launch-all-windows.js +86 -12
  36. package/dist/backends/launch-all-windows.js.map +1 -0
  37. package/dist/bare-launch-menu.d.ts.map +1 -0
  38. package/dist/bare-launch-menu.js +83 -6
  39. package/dist/bare-launch-menu.js.map +1 -0
  40. package/dist/claude-launch-args.d.ts.map +1 -0
  41. package/dist/claude-launch-args.js +34 -1
  42. package/dist/claude-launch-args.js.map +1 -0
  43. package/dist/claude.d.ts.map +1 -0
  44. package/dist/claude.js +486 -14
  45. package/dist/claude.js.map +1 -0
  46. package/dist/cleanup-cmd.d.ts +5 -5
  47. package/dist/cleanup-cmd.d.ts.map +1 -0
  48. package/dist/cleanup-cmd.js +453 -14
  49. package/dist/cleanup-cmd.js.map +1 -0
  50. package/dist/clear-rewake-core.d.ts.map +1 -0
  51. package/dist/clear-rewake-core.js +23 -2
  52. package/dist/clear-rewake-core.js.map +1 -0
  53. package/dist/clear-rewake.d.ts.map +1 -0
  54. package/dist/clear-rewake.js +19 -1
  55. package/dist/clear-rewake.js.map +1 -0
  56. package/dist/cli-help.d.ts +5 -0
  57. package/dist/cli-help.d.ts.map +1 -0
  58. package/dist/cli-help.js +104 -56
  59. package/dist/cli-help.js.map +1 -0
  60. package/dist/cli-platform.d.ts.map +1 -0
  61. package/dist/cli-platform.js +106 -4
  62. package/dist/cli-platform.js.map +1 -0
  63. package/dist/cli-tool-approval.d.ts +84 -0
  64. package/dist/cli-tool-approval.d.ts.map +1 -0
  65. package/dist/cli-tool-approval.js +583 -0
  66. package/dist/cli-tool-approval.js.map +1 -0
  67. package/dist/codex-app-server.d.ts.map +1 -0
  68. package/dist/codex-app-server.js +228 -4
  69. package/dist/codex-app-server.js.map +1 -0
  70. package/dist/codex-app-wake.d.ts.map +1 -0
  71. package/dist/codex-app-wake.js +432 -2
  72. package/dist/codex-app-wake.js.map +1 -0
  73. package/dist/codex-launch.d.ts.map +1 -0
  74. package/dist/codex-launch.js +102 -2
  75. package/dist/codex-launch.js.map +1 -0
  76. package/dist/codex-remote.d.ts +6 -1
  77. package/dist/codex-remote.d.ts.map +1 -0
  78. package/dist/codex-remote.js +394 -1
  79. package/dist/codex-remote.js.map +1 -0
  80. package/dist/codex-wake-resolve.d.ts.map +1 -0
  81. package/dist/codex-wake-resolve.js +127 -1
  82. package/dist/codex-wake-resolve.js.map +1 -0
  83. package/dist/config-utils.d.ts +2 -2
  84. package/dist/config-utils.d.ts.map +1 -0
  85. package/dist/config-utils.js +766 -3
  86. package/dist/config-utils.js.map +1 -0
  87. package/dist/config.d.ts +98 -61
  88. package/dist/config.d.ts.map +1 -0
  89. package/dist/config.js +426 -1
  90. package/dist/config.js.map +1 -0
  91. package/dist/console-prefix.d.ts.map +1 -0
  92. package/dist/console-prefix.js +96 -1
  93. package/dist/console-prefix.js.map +1 -0
  94. package/dist/cube-name.d.ts.map +1 -0
  95. package/dist/cube-name.js +67 -1
  96. package/dist/cube-name.js.map +1 -0
  97. package/dist/cubes.d.ts +126 -18
  98. package/dist/cubes.d.ts.map +1 -0
  99. package/dist/cubes.js +412 -4
  100. package/dist/cubes.js.map +1 -0
  101. package/dist/debug.d.ts.map +1 -0
  102. package/dist/debug.js +71 -1
  103. package/dist/debug.js.map +1 -0
  104. package/dist/direct-log.d.ts.map +1 -0
  105. package/dist/direct-log.js +11 -1
  106. package/dist/direct-log.js.map +1 -0
  107. package/dist/docs-sections.d.ts +11 -10
  108. package/dist/docs-sections.d.ts.map +1 -0
  109. package/dist/docs-sections.js +113 -3
  110. package/dist/docs-sections.js.map +1 -0
  111. package/dist/drone-lifecycle.d.ts +5 -21
  112. package/dist/drone-lifecycle.d.ts.map +1 -0
  113. package/dist/drone-lifecycle.js +57 -8
  114. package/dist/drone-lifecycle.js.map +1 -0
  115. package/dist/drone-management.d.ts +29 -0
  116. package/dist/drone-management.d.ts.map +1 -0
  117. package/dist/drone-management.js +109 -0
  118. package/dist/drone-management.js.map +1 -0
  119. package/dist/ensure-mcp-config.d.ts.map +1 -0
  120. package/dist/ensure-mcp-config.js +36 -1
  121. package/dist/ensure-mcp-config.js.map +1 -0
  122. package/dist/evict-drone.d.ts +10 -2
  123. package/dist/evict-drone.d.ts.map +1 -0
  124. package/dist/evict-drone.js +60 -1
  125. package/dist/evict-drone.js.map +1 -0
  126. package/dist/gc-orphan-inboxes.d.ts.map +1 -0
  127. package/dist/gc-orphan-inboxes.js +177 -1
  128. package/dist/gc-orphan-inboxes.js.map +1 -0
  129. package/dist/inbox-monitor.d.ts +1 -1
  130. package/dist/inbox-monitor.d.ts.map +1 -0
  131. package/dist/inbox-monitor.js +856 -3
  132. package/dist/inbox-monitor.js.map +1 -0
  133. package/dist/index.d.ts +6 -4
  134. package/dist/index.d.ts.map +1 -0
  135. package/dist/index.js +1034 -37
  136. package/dist/index.js.map +1 -0
  137. package/dist/launch-all-cmd.d.ts.map +1 -0
  138. package/dist/launch-all-cmd.js +377 -37
  139. package/dist/launch-all-cmd.js.map +1 -0
  140. package/dist/launch-all-command.d.ts.map +1 -0
  141. package/dist/launch-all-command.js +24 -1
  142. package/dist/launch-all-command.js.map +1 -0
  143. package/dist/launch-all-deps.d.ts +3 -8
  144. package/dist/launch-all-deps.d.ts.map +1 -0
  145. package/dist/launch-all-deps.js +99 -1
  146. package/dist/launch-all-deps.js.map +1 -0
  147. package/dist/launch-all-discovery.d.ts +1 -0
  148. package/dist/launch-all-discovery.d.ts.map +1 -0
  149. package/dist/launch-all-discovery.js +90 -4
  150. package/dist/launch-all-discovery.js.map +1 -0
  151. package/dist/launch-all-locks.d.ts.map +1 -0
  152. package/dist/launch-all-locks.js +54 -1
  153. package/dist/launch-all-locks.js.map +1 -0
  154. package/dist/launch-gate.d.ts +2 -2
  155. package/dist/launch-gate.d.ts.map +1 -0
  156. package/dist/launch-gate.js +73 -1
  157. package/dist/launch-gate.js.map +1 -0
  158. package/dist/lifecycle-log-guard.d.ts.map +1 -0
  159. package/dist/lifecycle-log-guard.js +93 -2
  160. package/dist/lifecycle-log-guard.js.map +1 -0
  161. package/dist/list-roles-render.d.ts.map +1 -0
  162. package/dist/list-roles-render.js +40 -6
  163. package/dist/list-roles-render.js.map +1 -0
  164. package/dist/local-log-routing.d.ts +19 -0
  165. package/dist/local-log-routing.d.ts.map +1 -0
  166. package/dist/local-log-routing.js +67 -0
  167. package/dist/local-log-routing.js.map +1 -0
  168. package/dist/local-manage-tool-result.d.ts +8 -0
  169. package/dist/local-manage-tool-result.d.ts.map +1 -0
  170. package/dist/local-manage-tool-result.js +10 -0
  171. package/dist/local-manage-tool-result.js.map +1 -0
  172. package/dist/local-server-cursor.d.ts +34 -0
  173. package/dist/local-server-cursor.d.ts.map +1 -0
  174. package/dist/local-server-cursor.js +151 -0
  175. package/dist/local-server-cursor.js.map +1 -0
  176. package/dist/log-audit.d.ts.map +1 -0
  177. package/dist/log-audit.js +194 -3
  178. package/dist/log-audit.js.map +1 -0
  179. package/dist/log-stream.d.ts +31 -18
  180. package/dist/log-stream.d.ts.map +1 -0
  181. package/dist/log-stream.js +1214 -12
  182. package/dist/log-stream.js.map +1 -0
  183. package/dist/model-presets.d.ts.map +1 -0
  184. package/dist/model-presets.js +19 -1
  185. package/dist/model-presets.js.map +1 -0
  186. package/dist/name-validator.d.ts.map +1 -0
  187. package/dist/name-validator.js +22 -1
  188. package/dist/name-validator.js.map +1 -0
  189. package/dist/opencode-drone.d.ts.map +1 -0
  190. package/dist/opencode-drone.js +438 -4
  191. package/dist/opencode-drone.js.map +1 -0
  192. package/dist/opencode-plugin.d.ts +1 -1
  193. package/dist/opencode-plugin.d.ts.map +1 -0
  194. package/dist/opencode-plugin.js +29 -4
  195. package/dist/opencode-plugin.js.map +1 -0
  196. package/dist/parse-assimilate-args.d.ts +1 -1
  197. package/dist/parse-assimilate-args.d.ts.map +1 -0
  198. package/dist/parse-assimilate-args.js +125 -1
  199. package/dist/parse-assimilate-args.js.map +1 -0
  200. package/dist/parse-launch-all-args.d.ts.map +1 -0
  201. package/dist/parse-launch-all-args.js +70 -1
  202. package/dist/parse-launch-all-args.js.map +1 -0
  203. package/dist/postinstall-banner.d.ts.map +1 -0
  204. package/dist/postinstall-banner.js +27 -2
  205. package/dist/postinstall-banner.js.map +1 -0
  206. package/dist/postinstall.d.ts.map +1 -0
  207. package/dist/postinstall.js +32 -5
  208. package/dist/postinstall.js.map +1 -0
  209. package/dist/readiness-probe.d.ts.map +1 -0
  210. package/dist/readiness-probe.js +9 -1
  211. package/dist/readiness-probe.js.map +1 -0
  212. package/dist/regen-format.d.ts.map +1 -0
  213. package/dist/regen-format.js +545 -13
  214. package/dist/regen-format.js.map +1 -0
  215. package/dist/regen.d.ts.map +1 -0
  216. package/dist/regen.js +141 -5
  217. package/dist/regen.js.map +1 -0
  218. package/dist/remote-client.d.ts +65 -175
  219. package/dist/remote-client.d.ts.map +1 -0
  220. package/dist/remote-client.js +942 -1
  221. package/dist/remote-client.js.map +1 -0
  222. package/dist/reset-local-seat-cmd.d.ts +50 -0
  223. package/dist/reset-local-seat-cmd.d.ts.map +1 -0
  224. package/dist/reset-local-seat-cmd.js +169 -0
  225. package/dist/reset-local-seat-cmd.js.map +1 -0
  226. package/dist/role-match.d.ts.map +1 -0
  227. package/dist/role-match.js +23 -1
  228. package/dist/role-match.js.map +1 -0
  229. package/dist/role-resolver.d.ts.map +1 -0
  230. package/dist/role-resolver.js +60 -1
  231. package/dist/role-resolver.js.map +1 -0
  232. package/dist/roster-render.d.ts.map +1 -0
  233. package/dist/roster-render.js +121 -3
  234. package/dist/roster-render.js.map +1 -0
  235. package/dist/seat-probe.d.ts +32 -13
  236. package/dist/seat-probe.d.ts.map +1 -0
  237. package/dist/seat-probe.js +78 -1
  238. package/dist/seat-probe.js.map +1 -0
  239. package/dist/seat-store.d.ts +76 -0
  240. package/dist/seat-store.d.ts.map +1 -0
  241. package/dist/seat-store.js +309 -0
  242. package/dist/seat-store.js.map +1 -0
  243. package/dist/seats.d.ts +303 -0
  244. package/dist/seats.d.ts.map +1 -0
  245. package/dist/seats.js +551 -0
  246. package/dist/seats.js.map +1 -0
  247. package/dist/self-path.d.ts +27 -0
  248. package/dist/self-path.d.ts.map +1 -0
  249. package/dist/self-path.js +43 -0
  250. package/dist/self-path.js.map +1 -0
  251. package/dist/server-endpoint.d.ts +9 -0
  252. package/dist/server-endpoint.d.ts.map +1 -0
  253. package/dist/server-endpoint.js +38 -0
  254. package/dist/server-endpoint.js.map +1 -0
  255. package/dist/server-errors.d.ts +50 -0
  256. package/dist/server-errors.d.ts.map +1 -0
  257. package/dist/server-errors.js +79 -0
  258. package/dist/server-errors.js.map +1 -0
  259. package/dist/server-handshake.d.ts +197 -0
  260. package/dist/server-handshake.d.ts.map +1 -0
  261. package/dist/server-handshake.js +505 -0
  262. package/dist/server-handshake.js.map +1 -0
  263. package/dist/server-response.d.ts +3 -0
  264. package/dist/server-response.d.ts.map +1 -0
  265. package/dist/server-response.js +67 -0
  266. package/dist/server-response.js.map +1 -0
  267. package/dist/server-trust.d.ts +14 -0
  268. package/dist/server-trust.d.ts.map +1 -0
  269. package/dist/server-trust.js +225 -0
  270. package/dist/server-trust.js.map +1 -0
  271. package/dist/setup-confirm.d.ts +3 -3
  272. package/dist/setup-confirm.d.ts.map +1 -0
  273. package/dist/setup-confirm.js +126 -2
  274. package/dist/setup-confirm.js.map +1 -0
  275. package/dist/setup.d.ts +5 -3
  276. package/dist/setup.d.ts.map +1 -0
  277. package/dist/setup.js +169 -46
  278. package/dist/setup.js.map +1 -0
  279. package/dist/shell-escape.d.ts.map +1 -0
  280. package/dist/shell-escape.js +22 -1
  281. package/dist/shell-escape.js.map +1 -0
  282. package/dist/spawn.d.ts +2 -2
  283. package/dist/spawn.d.ts.map +1 -0
  284. package/dist/spawn.js +29 -10
  285. package/dist/spawn.js.map +1 -0
  286. package/dist/startup-services.d.ts +0 -1
  287. package/dist/startup-services.d.ts.map +1 -0
  288. package/dist/startup-services.js +26 -1
  289. package/dist/startup-services.js.map +1 -0
  290. package/dist/stream-owner.d.ts +6 -2
  291. package/dist/stream-owner.d.ts.map +1 -0
  292. package/dist/stream-owner.js +547 -2
  293. package/dist/stream-owner.js.map +1 -0
  294. package/dist/stream-status.d.ts +1 -1
  295. package/dist/stream-status.d.ts.map +1 -0
  296. package/dist/stream-status.js +268 -3
  297. package/dist/stream-status.js.map +1 -0
  298. package/dist/sync-roles-render.d.ts.map +1 -0
  299. package/dist/sync-roles-render.js +118 -3
  300. package/dist/sync-roles-render.js.map +1 -0
  301. package/dist/sync.d.ts +1 -1
  302. package/dist/sync.d.ts.map +1 -0
  303. package/dist/sync.js +286 -22
  304. package/dist/sync.js.map +1 -0
  305. package/dist/terminal-title.d.ts.map +1 -0
  306. package/dist/terminal-title.js +68 -1
  307. package/dist/terminal-title.js.map +1 -0
  308. package/dist/token-store.d.ts +17 -111
  309. package/dist/token-store.d.ts.map +1 -0
  310. package/dist/token-store.js +81 -1
  311. package/dist/token-store.js.map +1 -0
  312. package/dist/tool-manifest.d.ts +4 -8
  313. package/dist/tool-manifest.d.ts.map +1 -0
  314. package/dist/tool-manifest.js +554 -1
  315. package/dist/tool-manifest.js.map +1 -0
  316. package/dist/tool-scope.d.ts +8 -12
  317. package/dist/tool-scope.d.ts.map +1 -0
  318. package/dist/tool-scope.js +97 -1
  319. package/dist/tool-scope.js.map +1 -0
  320. package/dist/types.d.ts +1 -5
  321. package/dist/types.d.ts.map +1 -0
  322. package/dist/types.js +5 -0
  323. package/dist/types.js.map +1 -0
  324. package/dist/unknown-subcommand.d.ts +1 -1
  325. package/dist/unknown-subcommand.d.ts.map +1 -0
  326. package/dist/unknown-subcommand.js +37 -1
  327. package/dist/unknown-subcommand.js.map +1 -0
  328. package/dist/version.d.ts +1 -1
  329. package/dist/version.d.ts.map +1 -0
  330. package/dist/version.js +78 -2
  331. package/dist/version.js.map +1 -0
  332. package/dist/working-repo.d.ts.map +1 -0
  333. package/dist/working-repo.js +81 -1
  334. package/dist/working-repo.js.map +1 -0
  335. package/dist/worktree-lifecycle.d.ts.map +1 -0
  336. package/dist/worktree-lifecycle.js +205 -2
  337. package/dist/worktree-lifecycle.js.map +1 -0
  338. package/docs/EXTRACTION_PROVENANCE.md +40 -0
  339. package/docs/LOCAL_SERVER.md +103 -0
  340. package/docs/RELEASING.md +120 -0
  341. package/package.json +52 -34
  342. package/src/agent-runtime.ts +69 -0
  343. package/src/assimilate-cmd.ts +1864 -0
  344. package/src/assimilate-deps.ts +444 -0
  345. package/src/assimilate-guard.ts +84 -0
  346. package/src/assimilate-welcome.ts +39 -0
  347. package/src/auth-env.ts +21 -0
  348. package/src/backends/launch-all-pastelist.ts +18 -0
  349. package/src/backends/launch-all-tmux.ts +75 -0
  350. package/src/backends/launch-all-windows.ts +110 -0
  351. package/src/bare-launch-menu.ts +148 -0
  352. package/src/claude-launch-args.ts +35 -0
  353. package/src/claude.ts +561 -0
  354. package/src/cleanup-cmd.ts +581 -0
  355. package/src/clear-rewake-core.ts +34 -0
  356. package/src/clear-rewake.ts +18 -0
  357. package/src/cli-help.ts +116 -0
  358. package/src/cli-platform.ts +127 -0
  359. package/src/cli-tool-approval.ts +716 -0
  360. package/src/codex-app-server.ts +238 -0
  361. package/src/codex-app-wake.ts +512 -0
  362. package/src/codex-launch.ts +140 -0
  363. package/src/codex-remote.ts +500 -0
  364. package/src/codex-wake-resolve.ts +155 -0
  365. package/src/config-utils.ts +811 -0
  366. package/src/config.ts +595 -0
  367. package/src/console-prefix.ts +99 -0
  368. package/src/cube-name.ts +69 -0
  369. package/src/cubes.ts +583 -0
  370. package/src/debug.ts +73 -0
  371. package/src/direct-log.ts +9 -0
  372. package/src/docs-sections.ts +129 -0
  373. package/src/drone-lifecycle.ts +62 -0
  374. package/src/drone-management.ts +162 -0
  375. package/src/ensure-mcp-config.ts +54 -0
  376. package/src/evict-drone.ts +82 -0
  377. package/src/gc-orphan-inboxes.ts +229 -0
  378. package/src/inbox-monitor.ts +1005 -0
  379. package/src/index.ts +1201 -0
  380. package/src/launch-all-cmd.ts +450 -0
  381. package/src/launch-all-command.ts +30 -0
  382. package/src/launch-all-deps.ts +188 -0
  383. package/src/launch-all-discovery.ts +118 -0
  384. package/src/launch-all-locks.ts +74 -0
  385. package/src/launch-gate.ts +80 -0
  386. package/src/lifecycle-log-guard.ts +144 -0
  387. package/src/list-roles-render.ts +52 -0
  388. package/src/local-log-routing.ts +106 -0
  389. package/src/local-manage-tool-result.ts +10 -0
  390. package/src/local-server-cursor.ts +188 -0
  391. package/src/log-audit.ts +207 -0
  392. package/src/log-stream.ts +1505 -0
  393. package/src/model-presets.ts +22 -0
  394. package/src/name-validator.ts +23 -0
  395. package/src/opencode-drone.ts +528 -0
  396. package/src/opencode-plugin.ts +38 -0
  397. package/src/parse-assimilate-args.ts +125 -0
  398. package/src/parse-launch-all-args.ts +100 -0
  399. package/src/postinstall-banner.ts +37 -0
  400. package/src/postinstall.ts +36 -0
  401. package/src/readiness-probe.ts +12 -0
  402. package/src/regen-format.ts +651 -0
  403. package/src/regen.ts +150 -0
  404. package/src/remote-client.ts +1379 -0
  405. package/src/reset-local-seat-cmd.ts +227 -0
  406. package/src/role-match.ts +29 -0
  407. package/src/role-resolver.ts +93 -0
  408. package/src/roster-render.ts +196 -0
  409. package/src/seat-probe.ts +115 -0
  410. package/src/seat-store.ts +333 -0
  411. package/src/seats.ts +741 -0
  412. package/src/self-path.ts +51 -0
  413. package/src/server-endpoint.ts +38 -0
  414. package/src/server-errors.ts +93 -0
  415. package/src/server-handshake.ts +783 -0
  416. package/src/server-response.ts +76 -0
  417. package/src/server-trust.ts +245 -0
  418. package/src/setup-confirm.ts +171 -0
  419. package/src/setup.ts +186 -0
  420. package/src/shell-escape.ts +22 -0
  421. package/src/spawn.ts +31 -0
  422. package/src/startup-services.ts +36 -0
  423. package/src/stream-owner.ts +686 -0
  424. package/src/stream-status.ts +337 -0
  425. package/src/sync-roles-render.ts +163 -0
  426. package/src/sync.ts +363 -0
  427. package/src/terminal-title.ts +76 -0
  428. package/src/token-store.ts +102 -0
  429. package/src/tool-manifest.ts +610 -0
  430. package/src/tool-scope.ts +110 -0
  431. package/src/types.ts +5 -0
  432. package/src/unknown-subcommand.ts +35 -0
  433. package/src/version.ts +82 -0
  434. package/src/working-repo.ts +99 -0
  435. package/src/worktree-lifecycle.ts +254 -0
  436. package/dist/auth-recovery.d.ts +0 -33
  437. package/dist/auth-recovery.js +0 -1
  438. package/dist/auth.d.ts +0 -103
  439. package/dist/auth.js +0 -39
  440. package/dist/device-auth.d.ts +0 -75
  441. package/dist/device-auth.js +0 -1
  442. package/dist/drone-address.d.ts +0 -26
  443. package/dist/drone-address.js +0 -1
  444. package/dist/get-started.d.ts +0 -20
  445. package/dist/get-started.js +0 -2
  446. package/dist/health-beat.d.ts +0 -134
  447. package/dist/health-beat.js +0 -1
  448. package/dist/role-section.d.ts +0 -110
  449. package/dist/role-section.js +0 -8
  450. package/dist/setup-action.d.ts +0 -20
  451. package/dist/setup-action.js +0 -1
  452. package/dist/stale-version-check.d.ts +0 -40
  453. package/dist/stale-version-check.js +0 -1
  454. package/dist/subscription-retry.d.ts +0 -40
  455. package/dist/subscription-retry.js +0 -1
  456. package/dist/templates.d.ts +0 -107
  457. package/dist/templates.js +0 -359
  458. package/dist/token-crypto.d.ts +0 -50
  459. package/dist/token-crypto.js +0 -1
package/dist/cubes.js CHANGED
@@ -1,4 +1,412 @@
1
- import{existsSync as I}from"node:fs";import{mkdir as k,readFile as l,writeFile as N,unlink as w,rename as O}from"node:fs/promises";import{homedir as T}from"node:os";import{dirname as g,join as o,resolve as j}from"node:path";import{pruneDeadWakeTargets as A}from"./codex-wake-resolve.js";const c=o(T(),".config","borgmcp"),f=o(c,"cubes.json"),x=o(c,"launch.json"),h=o(c,"codex-wake-targets.json"),S=o(c,"inboxes");function i(t=process.cwd()){let e=j(t);for(;;){if(I(o(e,".git")))return e;const r=g(e);if(r===e)return j(t);e=r}}const a=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function B(t,e){if(!a.test(t))throw new Error(`Invalid cubeId: ${t}`);if(!a.test(e))throw new Error(`Invalid droneId: ${e}`);return o(S,t,`${e}.log`)}function W(t){return t!==null&&typeof t=="object"&&typeof t.projects=="object"&&t.projects!==null&&!Array.isArray(t.projects)}async function s(){let t;try{t=await l(f,"utf8")}catch(r){if(r?.code==="ENOENT")return null;throw r}let e;try{e=JSON.parse(t)}catch{return null}return W(e)?e:null}async function b(t){await p(f,JSON.stringify(t,null,2)+`
2
- `)}let $=0;async function p(t,e,r={}){const n=r.io??{writeFile:N,rename:O,unlink:w},E=r.mode??384;await k(g(t),{recursive:!0});const u=`${t}.${process.pid}.${$++}.tmp`;try{await n.writeFile(u,e,{mode:E}),await n.rename(u,t)}catch(F){try{await n.unlink(u)}catch{}throw F}}function L(t){return t!==null&&typeof t=="object"&&typeof t.projects=="object"&&t.projects!==null&&!Array.isArray(t.projects)}async function y(){let t;try{t=await l(x,"utf8")}catch(e){if(e?.code==="ENOENT")return null;throw e}try{const e=JSON.parse(t);return L(e)?e:null}catch{return null}}async function P(t){await p(x,JSON.stringify(t,null,2)+`
3
- `)}function m(t,e){if(!a.test(t))throw new Error(`Invalid cubeId: ${t}`);if(!a.test(e))throw new Error(`Invalid droneId: ${e}`);return`${t}:${e}`}function D(t){return t!==null&&typeof t=="object"&&typeof t.targets=="object"&&t.targets!==null&&!Array.isArray(t.targets)}async function d(){let t;try{t=await l(h,"utf8")}catch(e){if(e?.code==="ENOENT")return null;throw e}try{const e=JSON.parse(t);return D(e)?e:null}catch{return null}}async function C(t){await p(h,JSON.stringify(t,null,2)+`
4
- `)}async function K(){const t=await s();if(!t)return null;const e=i(),r=t.projects[e];return!r||typeof r.cubeId!="string"||!r.cubeId||typeof r.droneId!="string"||!r.droneId?null:r}async function X(t){const e=await s()??{projects:{}};e.projects[i()]=t,await b(e)}function G(t,e){const r=e.cube?.name??t.name,n=e.drone?.label??t.droneLabel;return r===t.name&&n===t.droneLabel?t:{...t,name:r,droneLabel:n}}async function H(){const t=await s();if(!t)return;const e=i();if(e in t.projects){if(delete t.projects[e],Object.keys(t.projects).length===0){try{await w(f)}catch(r){if(r?.code!=="ENOENT")throw r}return}await b(t)}}async function q(){const t=await y();if(!t)return null;const e=t.projects[i()];return e?.cli==="claude"||e?.cli==="codex"||e?.cli==="opencode"?e.cli:null}async function z(t){const e=await y();if(!e)return null;const r=e.projects[i(t)];return r?.cli==="claude"||r?.cli==="codex"||r?.cli==="opencode"?r.cli:null}async function M(){const t=await s();return t?Object.entries(t.projects).filter(([,e])=>e!==null&&typeof e=="object"&&typeof e.cubeId=="string"&&e.cubeId.length>0&&typeof e.droneId=="string"&&e.droneId.length>0).map(([e,r])=>({projectPath:e,cube:r})):[]}async function Q(t){const e=await y()??{projects:{}};e.projects[i()]={cli:t},await P(e)}async function V(t,e,r){const n=await d()??{targets:{}};n.targets[m(t,e)]={...r,updatedAt:new Date().toISOString()},await C(n)}async function Y(t,e){const r=await d();if(!r)return null;const n=r.targets[m(t,e)];return!n||typeof n.threadId!="string"||typeof n.socketPath!="string"?null:n}async function Z(t){const e=await d();if(!e)return;const{targets:r,changed:n}=A(e.targets,t);n&&await C({...e,targets:r})}export{G as activeCubeWithFreshRegenIdentity,p as atomicWriteFile,H as clearActiveCube,i as findProjectRoot,K as getActiveCube,Y as getCodexWakeTarget,q as getProjectCliPreference,z as getProjectCliPreferenceForPath,B as inboxPathForDrone,Z as pruneDeadCodexWakeTargets,M as readAllProjectIdentities,X as setActiveCube,V as setCodexWakeTarget,Q as setProjectCliPreference};
1
+ /**
2
+ * Per-project active-cube persistence for Borg MCP client
3
+ *
4
+ * Stores the currently-assimilated cube identity + authority metadata PER
5
+ * PROJECT in ~/.config/borgmcp/cubes.json. The "project"
6
+ * is identified by walking up from cwd to find a .git directory; if none is
7
+ * found, cwd itself is used as the project key.
8
+ *
9
+ * Local-server session tokens never enter this file: only an opaque keychain
10
+ * reference is stored and hydrated at read time. An entry without verified
11
+ * local-server trust can no longer be hydrated.
12
+ *
13
+ * apiUrl is captured at assimilate time so subprocess invocations (e.g. the
14
+ * SessionStart hook firing borg-regen) don't need BORG_API_URL in their env
15
+ * to know which worker to talk to.
16
+ */
17
+ import { existsSync } from 'node:fs';
18
+ import { mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
19
+ import { homedir } from 'node:os';
20
+ import { dirname, join, resolve } from 'node:path';
21
+ import { pruneDeadWakeTargets } from './codex-wake-resolve.js';
22
+ import { getActiveSeatCredential, getActiveSeatForWorktree, getSeatForWorktree, hasSeatForWorktree, observeSeat, readAllActiveSeats, refreshSeatMetadata, resetSeatForWorktree, seatRef, } from './seats.js';
23
+ const CUBES_DIR = join(homedir(), '.config', 'borgmcp');
24
+ const LAUNCH_FILE = join(CUBES_DIR, 'launch.json');
25
+ const CODEX_WAKE_TARGETS_FILE = join(CUBES_DIR, 'codex-wake-targets.json');
26
+ const INBOX_DIR = join(CUBES_DIR, 'inboxes');
27
+ /**
28
+ * Walk up from cwd looking for a .git directory. If found, return that
29
+ * directory. If not found by filesystem root, return the original cwd.
30
+ * The returned absolute path is the "project key" used to scope cube state.
31
+ */
32
+ export function findProjectRoot(cwd = process.cwd()) {
33
+ let dir = resolve(cwd);
34
+ while (true) {
35
+ if (existsSync(join(dir, '.git')))
36
+ return dir;
37
+ const parent = dirname(dir);
38
+ if (parent === dir)
39
+ return resolve(cwd); // hit root, fall back to cwd
40
+ dir = parent;
41
+ }
42
+ }
43
+ /**
44
+ * Per-(cube, drone) inbox file path. Each drone gets its own file so that
45
+ * multiple drones in the same cube don't trample each other's writes when
46
+ * they each receive the same long-poll batch. The file lives under a
47
+ * per-cube subdir keyed by cube ID, then by drone ID (a UUID, globally
48
+ * unique).
49
+ *
50
+ * Validates cubeId/droneId as UUIDs before using them in a filesystem
51
+ * path. The values come from cubes.json (populated from server response),
52
+ * so the input is trusted in normal operation — but a regex guard is
53
+ * cheap defense against a corrupted file or future bug that would
54
+ * otherwise let `../` slip through into the inbox path.
55
+ */
56
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
57
+ export function inboxPathForDrone(cubeId, droneId) {
58
+ if (!UUID_RE.test(cubeId))
59
+ throw new Error(`Invalid cubeId: ${cubeId}`);
60
+ if (!UUID_RE.test(droneId))
61
+ throw new Error(`Invalid droneId: ${droneId}`);
62
+ return join(INBOX_DIR, cubeId, `${droneId}.log`);
63
+ }
64
+ // gh#894: crash-safe write. A plain truncate-write (open-for-write then write)
65
+ // leaves a truncated/empty prefs file if the process dies mid-write — losing
66
+ // every stored cube preference. Instead write to a same-directory temp file
67
+ // and rename() it over the target: rename is atomic on POSIX, so a reader
68
+ // always sees either the old complete file or the new complete file, never a
69
+ // partial one. On any failure the original is untouched (we never opened it for
70
+ // write) and the temp is best-effort cleaned. `io` is injectable for tests.
71
+ let atomicTmpCounter = 0;
72
+ export async function atomicWriteFile(filePath, data, opts = {}) {
73
+ const io = opts.io ?? { writeFile, rename, unlink };
74
+ const mode = opts.mode ?? 0o600;
75
+ await mkdir(dirname(filePath), { recursive: true });
76
+ // Same-dir temp so rename() stays on one filesystem (atomicity requirement).
77
+ // pid + counter keeps concurrent same-process writes from colliding.
78
+ const tmp = `${filePath}.${process.pid}.${atomicTmpCounter++}.tmp`;
79
+ try {
80
+ await io.writeFile(tmp, data, { mode });
81
+ await io.rename(tmp, filePath);
82
+ }
83
+ catch (err) {
84
+ try {
85
+ await io.unlink(tmp);
86
+ }
87
+ catch {
88
+ /* best-effort temp cleanup; never mask the original error */
89
+ }
90
+ throw err;
91
+ }
92
+ }
93
+ function isLaunchFile(data) {
94
+ return (data !== null &&
95
+ typeof data === 'object' &&
96
+ typeof data.projects === 'object' &&
97
+ data.projects !== null &&
98
+ !Array.isArray(data.projects));
99
+ }
100
+ async function readLaunchFile() {
101
+ let raw;
102
+ try {
103
+ raw = await readFile(LAUNCH_FILE, 'utf8');
104
+ }
105
+ catch (error) {
106
+ if (error?.code === 'ENOENT')
107
+ return null;
108
+ throw error;
109
+ }
110
+ try {
111
+ const parsed = JSON.parse(raw);
112
+ return isLaunchFile(parsed) ? parsed : null;
113
+ }
114
+ catch {
115
+ return null;
116
+ }
117
+ }
118
+ async function writeLaunchFile(data) {
119
+ // atomicWriteFile handles the mkdir + 0o600 mode, and the temp+rename keeps
120
+ // a concurrent reader from seeing a half-written launch file (gh#894, gh#901).
121
+ await atomicWriteFile(LAUNCH_FILE, JSON.stringify(data, null, 2) + '\n');
122
+ }
123
+ function codexWakeTargetKey(cubeId, droneId) {
124
+ if (!UUID_RE.test(cubeId))
125
+ throw new Error(`Invalid cubeId: ${cubeId}`);
126
+ if (!UUID_RE.test(droneId))
127
+ throw new Error(`Invalid droneId: ${droneId}`);
128
+ return `${cubeId}:${droneId}`;
129
+ }
130
+ function isCodexWakeTargetsFile(data) {
131
+ return (data !== null &&
132
+ typeof data === 'object' &&
133
+ typeof data.targets === 'object' &&
134
+ data.targets !== null &&
135
+ !Array.isArray(data.targets));
136
+ }
137
+ async function readCodexWakeTargetsFile() {
138
+ let raw;
139
+ try {
140
+ raw = await readFile(CODEX_WAKE_TARGETS_FILE, 'utf8');
141
+ }
142
+ catch (error) {
143
+ if (error?.code === 'ENOENT')
144
+ return null;
145
+ throw error;
146
+ }
147
+ try {
148
+ const parsed = JSON.parse(raw);
149
+ return isCodexWakeTargetsFile(parsed) ? parsed : null;
150
+ }
151
+ catch {
152
+ return null;
153
+ }
154
+ }
155
+ async function writeCodexWakeTargetsFile(data) {
156
+ // atomicWriteFile handles the mkdir + 0o600 mode, and the temp+rename keeps
157
+ // a concurrent reader from seeing a half-written file (gh#894, gh#901).
158
+ await atomicWriteFile(CODEX_WAKE_TARGETS_FILE, JSON.stringify(data, null, 2) + '\n');
159
+ }
160
+ /**
161
+ * Get the currently-active cube for the current project, or null if not
162
+ * assimilated in this project. Entries written by older client versions
163
+ * that lack the `cubeId` field are treated as absent — re-assimilate to
164
+ * refresh.
165
+ */
166
+ export async function getActiveCube() {
167
+ const record = await getActiveSeatForWorktree(findProjectRoot());
168
+ if (!record || !record.cubeId || !record.droneId)
169
+ return null;
170
+ return hydrateActiveCube(record);
171
+ }
172
+ /**
173
+ * True iff this worktree has an ACTIVE bound seat in seats.json. In the collapsed
174
+ * single-store model the credential and the worktree binding are one atomic unit,
175
+ * so there is no "binding present but credential lost" partial state to diagnose:
176
+ * an active bound seat always hydrates.
177
+ */
178
+ export async function hasPersistedActiveCube() {
179
+ return hasSeatForWorktree(findProjectRoot());
180
+ }
181
+ /**
182
+ * Compose an ActiveCube from an ACTIVE SeatRecord, hydrating the session bearer via
183
+ * the SOLE raw-bearer reader (getActiveSeatCredential). Returns null if the bearer
184
+ * can no longer be resolved (record concurrently reset/replaced).
185
+ */
186
+ async function hydrateActiveCube(record) {
187
+ const ref = seatRef(record);
188
+ const sessionToken = await getActiveSeatCredential(ref, {
189
+ origin: record.origin,
190
+ trustIdentity: record.trustIdentity,
191
+ cubeId: record.cubeId,
192
+ });
193
+ if (!sessionToken)
194
+ return null;
195
+ return {
196
+ cubeId: record.cubeId,
197
+ droneId: record.droneId,
198
+ name: record.name ?? '',
199
+ droneLabel: record.droneLabel ?? '',
200
+ sessionToken,
201
+ apiUrl: record.origin,
202
+ serverTrustIdentity: record.trustIdentity,
203
+ localSessionCredentialRef: ref,
204
+ ...(record.expiresAt !== undefined ? { localSessionExpiresAt: record.expiresAt } : {}),
205
+ ...(record.roleName !== undefined ? { roleName: record.roleName } : {}),
206
+ ...(record.roleClass !== undefined ? { roleClass: record.roleClass } : {}),
207
+ ...(record.isHumanSeat !== undefined ? { isHumanSeat: record.isHumanSeat } : {}),
208
+ };
209
+ }
210
+ /**
211
+ * Legacy binding-only writer. In the collapsed single-store model an ACTIVE seat is
212
+ * created ONLY by the atomic mint→activate+bind path in seats.ts (driven by the
213
+ * attach FINALIZE); there is no standalone binding write. Retained solely as a
214
+ * fail-closed guard for incomplete session metadata.
215
+ */
216
+ export async function setActiveCube(_active) {
217
+ throw new Error('local Borg server session metadata is incomplete');
218
+ }
219
+ export function activeCubeWithFreshRegenIdentity(active, result) {
220
+ const name = result.cube?.name ?? active.name;
221
+ const droneLabel = result.drone?.label ?? active.droneLabel;
222
+ const roleName = result.role?.name ?? active.roleName;
223
+ const roleClass = result.role?.role_class ?? active.roleClass;
224
+ const isHumanSeat = result.role?.is_human_seat ?? active.isHumanSeat;
225
+ if (name === active.name && droneLabel === active.droneLabel &&
226
+ roleName === active.roleName && roleClass === active.roleClass &&
227
+ isHumanSeat === active.isHumanSeat)
228
+ return active;
229
+ return { ...active, name, droneLabel, roleName, roleClass, isHumanSeat };
230
+ }
231
+ /**
232
+ * Snapshot this worktree's exact FULL local-seat binding (incl drone id) plus a
233
+ * token-safe TYPED observation (active + digest | absent). Read-only. Returns null
234
+ * when this worktree has no ACTIVE bound seat to reset: an honest no-op.
235
+ */
236
+ export async function snapshotLocalSeat() {
237
+ const worktree = findProjectRoot();
238
+ // CR#4: discover an ACTIVE seat OR a bound-PENDING record (a sibling whose
239
+ // activation failed, bound to THIS worktree by the attach bind-pending step).
240
+ // getActiveSeatForWorktree would MISS the bound-pending record (it requires
241
+ // state==='active' + a drone id), so `reset-local-seat` would FALSELY report
242
+ // "nothing to reset" (exit 0) while a resumable, server-digest-bound bearer
243
+ // persists at rest — a FALSE-SUCCESS revocation failure. getSeatForWorktree sees
244
+ // both, and the offline reset's exact re-check + delete cover the bound-pending
245
+ // record too.
246
+ const record = await getSeatForWorktree(worktree);
247
+ if (!record || !record.cubeId)
248
+ return null;
249
+ const ref = seatRef(record);
250
+ const observation = await observeSeat(ref, {
251
+ origin: record.origin,
252
+ trustIdentity: record.trustIdentity,
253
+ cubeId: record.cubeId,
254
+ });
255
+ return {
256
+ apiUrl: record.origin,
257
+ serverTrustIdentity: record.trustIdentity,
258
+ cubeId: record.cubeId,
259
+ ...(record.droneId !== undefined ? { droneId: record.droneId } : {}),
260
+ credentialRef: ref,
261
+ worktree,
262
+ observation,
263
+ };
264
+ }
265
+ /**
266
+ * Read the RAW persisted local-server seat bound to the current worktree — ACTIVE
267
+ * or a bound-PENDING record — WITHOUT hydrating its credential. Used by the resume
268
+ * path to recover the seat identity, its stored `operation`, and its `state`.
269
+ *
270
+ * CR#2: a SIBLING attach whose activation failed leaves a PENDING record BOUND to
271
+ * the preserved worktree (via the attach path's bind-pending step). This surfaces it so the
272
+ * rerun-from-that-worktree re-derives the EXACT sibling ref and re-sends the
273
+ * identical bearer (ghost-free convergence). A crash-in-gap PENDING record that was
274
+ * NEVER bound to a worktree still returns null here (it carries no worktree locator)
275
+ * and is resumed by prepareSeat's idempotent mint-or-reuse; a genuine absence is
276
+ * likewise null and a fresh enroll mints correctly.
277
+ */
278
+ export async function readPersistedLocalSeat() {
279
+ const record = await getSeatForWorktree(findProjectRoot());
280
+ if (!record || !record.cubeId)
281
+ return null;
282
+ return {
283
+ cubeId: record.cubeId,
284
+ ...(record.droneId !== undefined ? { droneId: record.droneId } : {}),
285
+ name: record.name ?? '',
286
+ droneLabel: record.droneLabel ?? '',
287
+ apiUrl: record.origin,
288
+ serverTrustIdentity: record.trustIdentity,
289
+ localSessionCredentialRef: seatRef(record),
290
+ operation: record.operation,
291
+ state: record.state,
292
+ ...(record.expiresAt !== undefined ? { localSessionExpiresAt: record.expiresAt } : {}),
293
+ ...(record.roleName !== undefined ? { roleName: record.roleName } : {}),
294
+ ...(record.roleClass !== undefined ? { roleClass: record.roleClass } : {}),
295
+ ...(record.isHumanSeat !== undefined ? { isHumanSeat: record.isHumanSeat } : {}),
296
+ };
297
+ }
298
+ /**
299
+ * Reset this worktree's seat: delegate to the single-store resetSeatForWorktree,
300
+ * which under ONE flock re-checks the exact FULL binding (ref + drone id, CR #3)
301
+ * plus the token-safe observation and DELETES the whole record — credential AND
302
+ * binding vanish together in one commit. Any drift / missing / same-ref digest
303
+ * replacement is an honest no-op ('changed'); no cross-store 'partial' exists.
304
+ */
305
+ export async function resetLocalSeatBinding(expected) {
306
+ const outcome = await resetSeatForWorktree({
307
+ worktree: expected.worktree,
308
+ ref: expected.credentialRef,
309
+ droneId: expected.droneId,
310
+ observation: expected.observation,
311
+ });
312
+ if (outcome.outcome === 'reset')
313
+ return { outcome: 'reset', credentialRef: outcome.ref };
314
+ if (outcome.outcome === 'no-binding')
315
+ return { outcome: 'no-binding' };
316
+ return { outcome: 'changed' };
317
+ }
318
+ /**
319
+ * Metadata-only refresh (cube name / drone label / role display) of the CURRENT
320
+ * worktree's ACTIVE seat — delegates to seats.ts refreshSeatMetadata, which CANNOT
321
+ * alter the credential, ref, identity, or worktree binding. A no-op when this
322
+ * worktree has no active seat, so a stale regen identity can never resurrect or
323
+ * mutate a seat ref.
324
+ */
325
+ export async function refreshActiveCubeMetadata(active) {
326
+ if (!active.localSessionCredentialRef)
327
+ return false;
328
+ return refreshSeatMetadata(findProjectRoot(), {
329
+ credentialRef: active.localSessionCredentialRef,
330
+ cubeId: active.cubeId,
331
+ droneId: active.droneId,
332
+ }, {
333
+ name: active.name,
334
+ droneLabel: active.droneLabel,
335
+ ...(active.roleName !== undefined ? { roleName: active.roleName } : {}),
336
+ ...(active.roleClass !== undefined ? { roleClass: active.roleClass } : {}),
337
+ ...(active.isHumanSeat !== undefined ? { isHumanSeat: active.isHumanSeat } : {}),
338
+ });
339
+ }
340
+ export async function getProjectCliPreference() {
341
+ const data = await readLaunchFile();
342
+ if (!data)
343
+ return null;
344
+ const entry = data.projects[findProjectRoot()];
345
+ return entry?.cli === 'claude' || entry?.cli === 'codex' || entry?.cli === 'opencode' ? entry.cli : null;
346
+ }
347
+ /**
348
+ * gh#556 Part 2 — like getProjectCliPreference, but keyed on an arbitrary
349
+ * worktree dir (launch-all reads the saved CLI preference for EACH discovered
350
+ * worktree, not just cwd). Returns null if no preference is saved for that path.
351
+ */
352
+ export async function getProjectCliPreferenceForPath(dir) {
353
+ const data = await readLaunchFile();
354
+ if (!data)
355
+ return null;
356
+ const entry = data.projects[findProjectRoot(dir)];
357
+ return entry?.cli === 'claude' || entry?.cli === 'codex' || entry?.cli === 'opencode' ? entry.cli : null;
358
+ }
359
+ /**
360
+ * gh#556 Part 2 — returns all persisted project identities from the seat store.
361
+ * Used by `borg launch-all` to enumerate drones across all known worktrees.
362
+ * Returns an empty array when no ACTIVE bound seats exist.
363
+ */
364
+ export async function readAllProjectIdentities() {
365
+ const seats = await readAllActiveSeats();
366
+ const hydrated = await Promise.all(seats.map(async ({ worktree, record }) => ({
367
+ projectPath: worktree,
368
+ cube: await hydrateActiveCube(record),
369
+ })));
370
+ return hydrated.flatMap(({ projectPath, cube }) => cube === null ? [] : [{ projectPath, cube }]);
371
+ }
372
+ export async function setProjectCliPreference(cli) {
373
+ const existing = (await readLaunchFile()) ?? { projects: {} };
374
+ existing.projects[findProjectRoot()] = { cli };
375
+ await writeLaunchFile(existing);
376
+ }
377
+ export async function setCodexWakeTarget(cubeId, droneId, target) {
378
+ const existing = (await readCodexWakeTargetsFile()) ?? { targets: {} };
379
+ existing.targets[codexWakeTargetKey(cubeId, droneId)] = {
380
+ ...target,
381
+ updatedAt: new Date().toISOString(),
382
+ };
383
+ await writeCodexWakeTargetsFile(existing);
384
+ }
385
+ export async function getCodexWakeTarget(cubeId, droneId) {
386
+ const existing = await readCodexWakeTargetsFile();
387
+ if (!existing)
388
+ return null;
389
+ const target = existing.targets[codexWakeTargetKey(cubeId, droneId)];
390
+ if (!target || typeof target.threadId !== 'string' || typeof target.socketPath !== 'string') {
391
+ return null;
392
+ }
393
+ return target;
394
+ }
395
+ /**
396
+ * gh#855: drop wake-target entries whose app-server socket is positively dead,
397
+ * so the file self-heals (stale dead-socket entries from crashed prior launches
398
+ * don't linger and mislead probeCodexBridgeArmed / health-beat). Pure prune
399
+ * decision lives in codex-wake-resolve.ts (false-deaf-avoidance: keeps alive +
400
+ * indeterminate); this is the thin read → prune → write-only-on-change glue.
401
+ * The liveness check is injected (claude.ts wires checkCodexBridgeHealthy) so
402
+ * cubes.ts stays free of the codex-remote dependency.
403
+ */
404
+ export async function pruneDeadCodexWakeTargets(socketLiveness) {
405
+ const existing = await readCodexWakeTargetsFile();
406
+ if (!existing)
407
+ return;
408
+ const { targets, changed } = pruneDeadWakeTargets(existing.targets, socketLiveness);
409
+ if (changed)
410
+ await writeCodexWakeTargetsFile({ ...existing, targets });
411
+ }
412
+ //# sourceMappingURL=cubes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cubes.js","sourceRoot":"","sources":["../src/cubes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,OAAO,GAIR,MAAM,YAAY,CAAC;AAWpB,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AACxD,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;AACnD,MAAM,uBAAuB,GAAG,IAAI,CAAC,SAAS,EAAE,yBAAyB,CAAC,CAAC;AAC3E,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AA4C7C;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc,OAAO,CAAC,GAAG,EAAE;IACzD,IAAI,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACvB,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAAE,OAAO,GAAG,CAAC;QAC9C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e){n=e}function u(){return n}function f(...e){n&&(e.length>0&&typeof e[0]=="string"?console.error(`[borg:debug] ${e[0]}`,...e.slice(1)):console.error("[borg:debug]",...e))}function s(e){const o=e.includes("--debug");if((o||i(process.env.BORG_DEBUG))&&r(!0),o)for(let t=e.length-1;t>=0;t-=1)e[t]==="--debug"&&e.splice(t,1)}function i(e){if(!e)return!1;const o=e.trim().toLowerCase();return o!==""&&o!=="0"&&o!=="false"&&o!=="no"&&o!=="off"}function l(){n=!1}export{l as _resetDebugForTests,f as debugLog,s as initDebugFromArgv,u as isDebug,r as setDebug};
1
+ /**
2
+ * Opt-in debug logging for the borg CLI (Queen observability ask — surface
3
+ * exactly what failed on errors like the cross-account assimilate 404).
4
+ *
5
+ * Enabled by `--debug` on the command line OR a truthy `BORG_DEBUG` env var,
6
+ * wired at the CLI entry points (top-level `borg` dispatcher + `borg setup`
7
+ * + `borg assimilate`). When on, `authedFetch` (remote-client.ts) emits one
8
+ * line per HTTP request + the server error body on failure.
9
+ *
10
+ * Output goes to STDERR with a `[borg:debug]` prefix so it never contaminates
11
+ * STDOUT (the MCP / tool output stream a drone session proxies).
12
+ *
13
+ * HARD INVARIANT: debug output must NEVER contain token material — no
14
+ * Authorization header, id_token, or refresh_token. Call sites log only
15
+ * method / path / status / server-error-body; the Bearer token is omitted.
16
+ */
17
+ let debugEnabled = false;
18
+ /** Enable or disable debug logging for the lifetime of the process. */
19
+ export function setDebug(on) {
20
+ debugEnabled = on;
21
+ }
22
+ /** Whether debug logging is currently enabled. */
23
+ export function isDebug() {
24
+ return debugEnabled;
25
+ }
26
+ /**
27
+ * Emit a debug line to STDERR with the `[borg:debug]` prefix. No-op when
28
+ * debug is disabled, so call sites need not guard. STDOUT is left clean for
29
+ * MCP / tool output.
30
+ */
31
+ export function debugLog(...args) {
32
+ if (!debugEnabled)
33
+ return;
34
+ if (args.length > 0 && typeof args[0] === 'string') {
35
+ console.error(`[borg:debug] ${args[0]}`, ...args.slice(1));
36
+ }
37
+ else {
38
+ console.error('[borg:debug]', ...args);
39
+ }
40
+ }
41
+ /**
42
+ * Resolve debug state from a process argv array + `BORG_DEBUG` at a CLI entry
43
+ * point. Enables debug when `--debug` is present OR `BORG_DEBUG` is truthy,
44
+ * then STRIPS every `--debug` token from the array IN PLACE so downstream
45
+ * subcommand parsers (which reject unknown flags) never see it. Idempotent —
46
+ * safe to call from more than one entry point in the same process.
47
+ */
48
+ export function initDebugFromArgv(argv) {
49
+ const hasFlag = argv.includes('--debug');
50
+ if (hasFlag || isTruthyEnv(process.env.BORG_DEBUG)) {
51
+ setDebug(true);
52
+ }
53
+ if (hasFlag) {
54
+ for (let i = argv.length - 1; i >= 0; i -= 1) {
55
+ if (argv[i] === '--debug')
56
+ argv.splice(i, 1);
57
+ }
58
+ }
59
+ }
60
+ /** A non-empty env value other than the common falsy spellings is truthy. */
61
+ function isTruthyEnv(value) {
62
+ if (!value)
63
+ return false;
64
+ const v = value.trim().toLowerCase();
65
+ return v !== '' && v !== '0' && v !== 'false' && v !== 'no' && v !== 'off';
66
+ }
67
+ /** Test hook: reset module-level debug state between tests. */
68
+ export function _resetDebugForTests() {
69
+ debugEnabled = false;
70
+ }
71
+ //# sourceMappingURL=debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.js","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,IAAI,YAAY,GAAG,KAAK,CAAC;AAEzB,uEAAuE;AACvE,MAAM,UAAU,QAAQ,CAAC,EAAW;IAClC,YAAY,GAAG,EAAE,CAAC;AACpB,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,OAAO;IACrB,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAG,IAAe;IACzC,IAAI,CAAC,YAAY;QAAE,OAAO;IAC1B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC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 +1 @@
1
+ {"version":3,"file":"direct-log.d.ts","sourceRoot":"","sources":["../src/direct-log.ts"],"names":[],"mappings":"AAAA,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,CAQrE"}
@@ -1 +1,11 @@
1
- function e(t){if(t==null)return[];const i=(Array.isArray(t)?t:[t]).filter(r=>typeof r=="string").map(r=>r.trim()).filter(r=>r.length>0);return[...new Set(i)]}export{e as normalizeDirectLogRecipients};
1
+ export function normalizeDirectLogRecipients(value) {
2
+ if (value == null)
3
+ return [];
4
+ const raw = Array.isArray(value) ? value : [value];
5
+ const recipients = raw
6
+ .filter((item) => typeof item === 'string')
7
+ .map((item) => item.trim())
8
+ .filter((item) => item.length > 0);
9
+ return [...new Set(recipients)];
10
+ }
11
+ //# sourceMappingURL=direct-log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direct-log.js","sourceRoot":"","sources":["../src/direct-log.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,4BAA4B,CAAC,KAAc;IACzD,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,EAAE,CAAC;IAC7B,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,GAAG;SACnB,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC;SAC1D,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACrC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AAClC,CAAC"}
@@ -1,23 +1,24 @@
1
1
  /**
2
- * gh#docs-site phase B — the single source for the in-product docs index.
2
+ * The single source for the in-product docs index.
3
3
  *
4
4
  * `borg_docs` (index.ts) returns these sections so an agent can route a "how
5
- * does borgmcp work / pricing / setup" question to the right page, then WebFetch
6
- * the URL for the content. Pure data + a lazy keyword match — NO server-side
7
- * fetch, NO RAG/embeddings.
5
+ * does borgmcp work / setup / concept / tool" question to the right
6
+ * repository-local document, then WebFetch the URL for the content. Pure data +
7
+ * a lazy keyword match — NO server-side fetch, NO RAG/embeddings.
8
8
  *
9
- * `page` is the landing-page/src/pages/docs/<page>.astro file each section maps
10
- * to; a test pins these against the real files so the index can't drift from
11
- * the phase-A docs pages (the gh#740 lesson).
9
+ * This is a local-only client: every URL points at the public source repository
10
+ * (its README + `docs/`), never a hosted product site.
11
+ *
12
+ * `page` is the repository-local file each section maps to (anti-drift anchor).
12
13
  */
13
- export declare const DOCS_BASE_URL = "https://borgmcp.ai/docs";
14
+ export declare const DOCS_BASE_URL = "https://github.com/Byte-Ventures/borg-mcp-client";
14
15
  export interface DocsSection {
15
16
  /** logical topic key */
16
17
  slug: string;
17
18
  title: string;
18
- /** public page URL the agent should WebFetch */
19
+ /** repository-local document URL the agent should WebFetch */
19
20
  url: string;
20
- /** the docs/<page>.astro file this section maps to (anti-drift anchor) */
21
+ /** the repository file this section maps to (anti-drift anchor) */
21
22
  page: string;
22
23
  summary: string;
23
24
  /** extra match terms for the topic lookup */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs-sections.d.ts","sourceRoot":"","sources":["../src/docs-sections.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,aAAa,qDAAqD,CAAC;AAKhF,MAAM,WAAW,WAAW;IAC1B,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,GAAG,EAAE,MAAM,CAAC;IACZ,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,aAAa,EAAE,WAAW,EAyEtC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE,CAU9D;AAED,8EAA8E;AAC9E,wBAAgB,eAAe,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,CAE/D"}