@cortexkit/opencode-antigravity-auth 3.0.5 → 3.0.6

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 (370) hide show
  1. package/README.md +38 -352
  2. package/dist/cli.js +9199 -8799
  3. package/dist/cli.js.map +4 -4
  4. package/dist/cli.meta.json +1286 -1064
  5. package/dist/index.js +13641 -14559
  6. package/dist/index.js.map +4 -4
  7. package/dist/index.meta.json +1333 -1342
  8. package/dist/server.js +10618 -11080
  9. package/dist/server.js.map +4 -4
  10. package/dist/server.meta.json +1 -1
  11. package/dist/src/auth-method-labels.d.ts +3 -0
  12. package/dist/src/auth-method-labels.d.ts.map +1 -0
  13. package/dist/src/auth-method-labels.js +5 -0
  14. package/dist/src/auth-method-labels.js.map +1 -0
  15. package/dist/src/cli.d.ts +3 -1
  16. package/dist/src/cli.d.ts.map +1 -1
  17. package/dist/src/cli.js +98 -12
  18. package/dist/src/cli.js.map +1 -1
  19. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +33 -3
  20. package/dist/src/common-auth-embedded/claustrum/consumer.js +96 -1
  21. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +4 -1
  22. package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +6 -1
  23. package/dist/src/common-auth-embedded/claustrum/enrollment.js +6 -1
  24. package/dist/src/common-auth-embedded/claustrum/index.d.ts +2 -1
  25. package/dist/src/common-auth-embedded/claustrum/index.js +5 -3
  26. package/dist/src/common-auth-embedded/claustrum/insula.d.ts +69 -0
  27. package/dist/src/common-auth-embedded/claustrum/insula.js +152 -0
  28. package/dist/src/common-auth-embedded/claustrum/roster.d.ts +13 -0
  29. package/dist/src/common-auth-embedded/claustrum/roster.js +33 -3
  30. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +20 -11
  31. package/dist/src/common-auth-embedded/quota/codec.d.ts +2 -0
  32. package/dist/src/common-auth-embedded/quota/codec.js +2 -1
  33. package/dist/src/common-auth-embedded/quota/format.d.ts +26 -0
  34. package/dist/src/common-auth-embedded/quota/format.js +78 -42
  35. package/dist/src/common-auth-embedded/quota/index.d.ts +4 -4
  36. package/dist/src/common-auth-embedded/quota/index.js +2 -2
  37. package/dist/src/common-auth-embedded/quota/map.d.ts +11 -0
  38. package/dist/src/common-auth-embedded/quota/map.js +36 -1
  39. package/dist/src/common-auth-embedded/quota/merge.d.ts +3 -1
  40. package/dist/src/common-auth-embedded/quota/merge.js +21 -5
  41. package/dist/src/common-auth-embedded/quota/projection.d.ts +2 -1
  42. package/dist/src/common-auth-embedded/quota/projection.js +3 -1
  43. package/dist/src/common-auth-embedded/setup/command-runner.js +49 -0
  44. package/dist/src/common-auth-embedded/setup/command.d.ts +3 -0
  45. package/dist/src/common-auth-embedded/setup/command.js +215 -0
  46. package/dist/src/common-auth-embedded/setup/config-write.js +60 -0
  47. package/dist/src/common-auth-embedded/setup/detect.d.ts +6 -0
  48. package/dist/src/common-auth-embedded/setup/detect.js +224 -0
  49. package/dist/src/common-auth-embedded/setup/enroll.js +70 -0
  50. package/dist/src/common-auth-embedded/setup/index.d.ts +5 -0
  51. package/dist/src/common-auth-embedded/setup/index.js +4 -0
  52. package/dist/src/common-auth-embedded/setup/paths.js +33 -0
  53. package/dist/src/common-auth-embedded/setup/process-fence.d.ts +43 -0
  54. package/dist/src/common-auth-embedded/setup/process-fence.js +270 -0
  55. package/dist/src/common-auth-embedded/setup/prompts.js +26 -0
  56. package/dist/src/common-auth-embedded/setup/register.d.ts +11 -0
  57. package/dist/src/common-auth-embedded/setup/register.js +130 -0
  58. package/dist/src/common-auth-embedded/setup/types.d.ts +136 -0
  59. package/dist/src/common-auth-embedded/source-output.json +228 -80
  60. package/dist/src/common-auth-embedded/store/schema.d.ts +2 -0
  61. package/dist/src/common-auth-embedded/store/schema.js +3 -2
  62. package/dist/src/ga/rpc/protocol.d.ts +4 -7
  63. package/dist/src/ga/rpc/protocol.d.ts.map +1 -1
  64. package/dist/src/ga/rpc/protocol.js +5 -13
  65. package/dist/src/ga/rpc/protocol.js.map +1 -1
  66. package/dist/src/ga/server/auth.d.ts +8 -3
  67. package/dist/src/ga/server/auth.d.ts.map +1 -1
  68. package/dist/src/ga/server/auth.js +25 -9
  69. package/dist/src/ga/server/auth.js.map +1 -1
  70. package/dist/src/ga/server/index.d.ts +39 -12
  71. package/dist/src/ga/server/index.d.ts.map +1 -1
  72. package/dist/src/ga/server/index.js +214 -53
  73. package/dist/src/ga/server/index.js.map +1 -1
  74. package/dist/src/ga/server/pool-login.d.ts +22 -0
  75. package/dist/src/ga/server/pool-login.d.ts.map +1 -0
  76. package/dist/src/ga/server/pool-login.js +150 -0
  77. package/dist/src/ga/server/pool-login.js.map +1 -0
  78. package/dist/src/ga/tui/host-ga.d.ts +2 -5
  79. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  80. package/dist/src/ga/tui/host-ga.js +17 -49
  81. package/dist/src/ga/tui/host-ga.js.map +1 -1
  82. package/dist/src/plugin/accounts.d.ts +1 -1
  83. package/dist/src/plugin/accounts.d.ts.map +1 -1
  84. package/dist/src/plugin/accounts.js +1 -0
  85. package/dist/src/plugin/accounts.js.map +1 -1
  86. package/dist/src/plugin/background-vault-quota-refresh.d.ts +2 -0
  87. package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  88. package/dist/src/plugin/background-vault-quota-refresh.js +125 -10
  89. package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
  90. package/dist/src/plugin/command-apply.d.ts +2 -2
  91. package/dist/src/plugin/command-apply.d.ts.map +1 -1
  92. package/dist/src/plugin/command-apply.js +3 -10
  93. package/dist/src/plugin/command-apply.js.map +1 -1
  94. package/dist/src/plugin/commands.d.ts +1 -0
  95. package/dist/src/plugin/commands.d.ts.map +1 -1
  96. package/dist/src/plugin/commands.js +2 -2
  97. package/dist/src/plugin/commands.js.map +1 -1
  98. package/dist/src/plugin/config/operator-settings-schema.d.ts +0 -4
  99. package/dist/src/plugin/config/operator-settings-schema.d.ts.map +1 -1
  100. package/dist/src/plugin/config/operator-settings-schema.js +0 -5
  101. package/dist/src/plugin/config/operator-settings-schema.js.map +1 -1
  102. package/dist/src/plugin/config/schema.d.ts +0 -7
  103. package/dist/src/plugin/config/schema.d.ts.map +1 -1
  104. package/dist/src/plugin/config/schema.js +0 -43
  105. package/dist/src/plugin/config/schema.js.map +1 -1
  106. package/dist/src/plugin/config/writer.d.ts +1 -1
  107. package/dist/src/plugin/config/writer.js +1 -1
  108. package/dist/src/plugin/fetch/retry-state.d.ts +19 -3
  109. package/dist/src/plugin/fetch/retry-state.d.ts.map +1 -1
  110. package/dist/src/plugin/fetch/retry-state.js +0 -6
  111. package/dist/src/plugin/fetch/retry-state.js.map +1 -1
  112. package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
  113. package/dist/src/plugin/fetch-interceptor.js +0 -3
  114. package/dist/src/plugin/fetch-interceptor.js.map +1 -1
  115. package/dist/src/plugin/fetch-routing.d.ts +0 -16
  116. package/dist/src/plugin/fetch-routing.d.ts.map +1 -1
  117. package/dist/src/plugin/fetch-routing.js +0 -49
  118. package/dist/src/plugin/fetch-routing.js.map +1 -1
  119. package/dist/src/plugin/ga-location-services.d.ts +14 -9
  120. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  121. package/dist/src/plugin/ga-location-services.js +120 -40
  122. package/dist/src/plugin/ga-location-services.js.map +1 -1
  123. package/dist/src/plugin/google-origin.d.ts +7 -0
  124. package/dist/src/plugin/google-origin.d.ts.map +1 -0
  125. package/dist/src/plugin/google-origin.js +14 -0
  126. package/dist/src/plugin/google-origin.js.map +1 -0
  127. package/dist/src/plugin/index.d.ts.map +1 -1
  128. package/dist/src/plugin/index.js +15 -4
  129. package/dist/src/plugin/index.js.map +1 -1
  130. package/dist/src/plugin/oauth-methods.d.ts.map +1 -1
  131. package/dist/src/plugin/oauth-methods.js +0 -33
  132. package/dist/src/plugin/oauth-methods.js.map +1 -1
  133. package/dist/src/plugin/operator-settings.d.ts +1 -1
  134. package/dist/src/plugin/operator-settings.d.ts.map +1 -1
  135. package/dist/src/plugin/operator-settings.js +1 -8
  136. package/dist/src/plugin/operator-settings.js.map +1 -1
  137. package/dist/src/plugin/quota.d.ts +11 -7
  138. package/dist/src/plugin/quota.d.ts.map +1 -1
  139. package/dist/src/plugin/quota.js +128 -102
  140. package/dist/src/plugin/quota.js.map +1 -1
  141. package/dist/src/plugin/request.d.ts +5 -3
  142. package/dist/src/plugin/request.d.ts.map +1 -1
  143. package/dist/src/plugin/request.js +87 -168
  144. package/dist/src/plugin/request.js.map +1 -1
  145. package/dist/src/plugin/server.d.ts.map +1 -1
  146. package/dist/src/plugin/server.js +60 -53
  147. package/dist/src/plugin/server.js.map +1 -1
  148. package/dist/src/plugin/shared/advisory-repository.d.ts +20 -0
  149. package/dist/src/plugin/shared/advisory-repository.d.ts.map +1 -0
  150. package/dist/src/plugin/shared/advisory-repository.js +91 -0
  151. package/dist/src/plugin/shared/advisory-repository.js.map +1 -0
  152. package/dist/src/plugin/shared/request-services.d.ts +19 -25
  153. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  154. package/dist/src/plugin/shared/request-services.js +105 -188
  155. package/dist/src/plugin/shared/request-services.js.map +1 -1
  156. package/dist/src/plugin/shared/runtime.js +4 -2
  157. package/dist/src/plugin/shared/runtime.js.map +1 -1
  158. package/dist/src/plugin/shared/vault-request-credentials.d.ts +4 -1
  159. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  160. package/dist/src/plugin/shared/vault-request-credentials.js +41 -7
  161. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  162. package/dist/src/plugin/storage.d.ts +2 -2
  163. package/dist/src/plugin/storage.d.ts.map +1 -1
  164. package/dist/src/plugin/storage.js.map +1 -1
  165. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  166. package/dist/src/plugin/vault-custody.js +147 -35
  167. package/dist/src/plugin/vault-custody.js.map +1 -1
  168. package/dist/src/plugin/vault-quota-outcome.d.ts +19 -0
  169. package/dist/src/plugin/vault-quota-outcome.d.ts.map +1 -0
  170. package/dist/src/plugin/vault-quota-outcome.js +47 -0
  171. package/dist/src/plugin/vault-quota-outcome.js.map +1 -0
  172. package/dist/src/quota-presentation.d.ts +29 -1
  173. package/dist/src/quota-presentation.d.ts.map +1 -1
  174. package/dist/src/quota-presentation.js +52 -17
  175. package/dist/src/quota-presentation.js.map +1 -1
  176. package/dist/src/setup.d.ts +15 -0
  177. package/dist/src/setup.d.ts.map +1 -0
  178. package/dist/src/setup.js +320 -0
  179. package/dist/src/setup.js.map +1 -0
  180. package/dist/src/sidebar-projection.d.ts +1 -1
  181. package/dist/src/sidebar-projection.d.ts.map +1 -1
  182. package/dist/src/sidebar-state.d.ts +1 -1
  183. package/dist/src/sidebar-state.d.ts.map +1 -1
  184. package/dist/src/sidebar-state.js +19 -1
  185. package/dist/src/sidebar-state.js.map +1 -1
  186. package/dist/src/tui.d.ts.map +1 -1
  187. package/dist/src/tui.js +205 -110
  188. package/dist/src/tui.js.map +1 -1
  189. package/dist/tui-build-map.json +37 -37
  190. package/dist/tui-ga-build-map.json +33 -33
  191. package/dist/types/src/auth-method-labels.d.ts +3 -0
  192. package/dist/types/src/auth-method-labels.d.ts.map +1 -0
  193. package/dist/types/src/cli.d.ts +3 -1
  194. package/dist/types/src/cli.d.ts.map +1 -1
  195. package/dist/types/src/common-auth-embedded/auth-menu/terminal.d.ts +43 -0
  196. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +132 -0
  197. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +178 -0
  198. package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +164 -0
  199. package/dist/types/src/common-auth-embedded/claustrum/errors.d.ts +16 -0
  200. package/dist/types/src/common-auth-embedded/claustrum/host-slot.d.ts +39 -0
  201. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +19 -0
  202. package/dist/types/src/common-auth-embedded/claustrum/insula.d.ts +69 -0
  203. package/dist/types/src/common-auth-embedded/claustrum/interlock.d.ts +27 -0
  204. package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +221 -0
  205. package/dist/types/src/common-auth-embedded/opencode2/errors.d.ts +25 -0
  206. package/dist/types/src/common-auth-embedded/opencode2/index.d.ts +8 -0
  207. package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +55 -0
  208. package/dist/types/src/common-auth-embedded/opencode2/integration.d.ts +112 -0
  209. package/dist/types/src/common-auth-embedded/opencode2/sse.d.ts +12 -0
  210. package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +413 -0
  211. package/dist/types/src/common-auth-embedded/quota/codec.d.ts +2 -0
  212. package/dist/types/src/common-auth-embedded/quota/format.d.ts +26 -0
  213. package/dist/types/src/common-auth-embedded/quota/index.d.ts +4 -4
  214. package/dist/types/src/common-auth-embedded/quota/map.d.ts +11 -0
  215. package/dist/types/src/common-auth-embedded/quota/merge.d.ts +3 -1
  216. package/dist/types/src/common-auth-embedded/quota/projection.d.ts +2 -1
  217. package/dist/types/src/common-auth-embedded/routing/admission.d.ts +93 -0
  218. package/dist/types/src/common-auth-embedded/routing/index.d.ts +8 -0
  219. package/dist/types/src/common-auth-embedded/routing/ordered.d.ts +47 -0
  220. package/dist/types/src/common-auth-embedded/routing/pins.d.ts +22 -0
  221. package/dist/types/src/common-auth-embedded/routing/sticky.d.ts +158 -0
  222. package/dist/types/src/common-auth-embedded/setup/command.d.ts +3 -0
  223. package/dist/types/src/common-auth-embedded/setup/detect.d.ts +6 -0
  224. package/dist/types/src/common-auth-embedded/setup/index.d.ts +5 -0
  225. package/dist/types/src/common-auth-embedded/setup/process-fence.d.ts +43 -0
  226. package/dist/types/src/common-auth-embedded/setup/register.d.ts +11 -0
  227. package/dist/types/src/common-auth-embedded/setup/types.d.ts +136 -0
  228. package/dist/types/src/common-auth-embedded/store/schema.d.ts +2 -0
  229. package/dist/types/src/ga/rpc/protocol.d.ts +4 -7
  230. package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -1
  231. package/dist/types/src/ga/server/auth.d.ts +8 -3
  232. package/dist/types/src/ga/server/auth.d.ts.map +1 -1
  233. package/dist/types/src/ga/server/index.d.ts +39 -12
  234. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  235. package/dist/types/src/ga/server/pool-login.d.ts +22 -0
  236. package/dist/types/src/ga/server/pool-login.d.ts.map +1 -0
  237. package/dist/types/src/plugin/accounts.d.ts +1 -1
  238. package/dist/types/src/plugin/accounts.d.ts.map +1 -1
  239. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts +2 -0
  240. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  241. package/dist/types/src/plugin/command-apply.d.ts +2 -2
  242. package/dist/types/src/plugin/command-apply.d.ts.map +1 -1
  243. package/dist/types/src/plugin/commands.d.ts +1 -0
  244. package/dist/types/src/plugin/commands.d.ts.map +1 -1
  245. package/dist/types/src/plugin/config/operator-settings-schema.d.ts +0 -4
  246. package/dist/types/src/plugin/config/operator-settings-schema.d.ts.map +1 -1
  247. package/dist/types/src/plugin/config/schema.d.ts +0 -7
  248. package/dist/types/src/plugin/config/schema.d.ts.map +1 -1
  249. package/dist/types/src/plugin/config/writer.d.ts +1 -1
  250. package/dist/types/src/plugin/fetch/retry-state.d.ts +19 -3
  251. package/dist/types/src/plugin/fetch/retry-state.d.ts.map +1 -1
  252. package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
  253. package/dist/types/src/plugin/fetch-routing.d.ts +0 -16
  254. package/dist/types/src/plugin/fetch-routing.d.ts.map +1 -1
  255. package/dist/types/src/plugin/ga-location-services.d.ts +14 -9
  256. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  257. package/dist/types/src/plugin/google-origin.d.ts +7 -0
  258. package/dist/types/src/plugin/google-origin.d.ts.map +1 -0
  259. package/dist/types/src/plugin/index.d.ts.map +1 -1
  260. package/dist/types/src/plugin/oauth-methods.d.ts.map +1 -1
  261. package/dist/types/src/plugin/operator-settings.d.ts +1 -1
  262. package/dist/types/src/plugin/operator-settings.d.ts.map +1 -1
  263. package/dist/types/src/plugin/quota.d.ts +11 -7
  264. package/dist/types/src/plugin/quota.d.ts.map +1 -1
  265. package/dist/types/src/plugin/request.d.ts +5 -3
  266. package/dist/types/src/plugin/request.d.ts.map +1 -1
  267. package/dist/types/src/plugin/server.d.ts.map +1 -1
  268. package/dist/types/src/plugin/shared/advisory-repository.d.ts +20 -0
  269. package/dist/types/src/plugin/shared/advisory-repository.d.ts.map +1 -0
  270. package/dist/types/src/plugin/shared/request-services.d.ts +19 -25
  271. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  272. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +4 -1
  273. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  274. package/dist/types/src/plugin/storage.d.ts +2 -2
  275. package/dist/types/src/plugin/storage.d.ts.map +1 -1
  276. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  277. package/dist/types/src/plugin/vault-quota-outcome.d.ts +19 -0
  278. package/dist/types/src/plugin/vault-quota-outcome.d.ts.map +1 -0
  279. package/dist/types/src/setup.d.ts +15 -0
  280. package/dist/types/src/setup.d.ts.map +1 -0
  281. package/dist/types/src/sidebar-state.d.ts +1 -1
  282. package/dist/types/src/sidebar-state.d.ts.map +1 -1
  283. package/package.json +5 -4
  284. package/src/common-auth-embedded/claustrum/consumer.d.ts +33 -3
  285. package/src/common-auth-embedded/claustrum/consumer.js +96 -1
  286. package/src/common-auth-embedded/claustrum/custody.d.ts +4 -1
  287. package/src/common-auth-embedded/claustrum/enrollment.d.ts +6 -1
  288. package/src/common-auth-embedded/claustrum/enrollment.js +6 -1
  289. package/src/common-auth-embedded/claustrum/index.d.ts +2 -1
  290. package/src/common-auth-embedded/claustrum/index.js +5 -3
  291. package/src/common-auth-embedded/claustrum/insula.d.ts +69 -0
  292. package/src/common-auth-embedded/claustrum/insula.js +152 -0
  293. package/src/common-auth-embedded/claustrum/roster.d.ts +13 -0
  294. package/src/common-auth-embedded/claustrum/roster.js +33 -3
  295. package/src/common-auth-embedded/fs/refresh-file-lock.js +20 -11
  296. package/src/common-auth-embedded/quota/codec.d.ts +2 -0
  297. package/src/common-auth-embedded/quota/codec.js +2 -1
  298. package/src/common-auth-embedded/quota/format.d.ts +26 -0
  299. package/src/common-auth-embedded/quota/format.js +78 -42
  300. package/src/common-auth-embedded/quota/index.d.ts +4 -4
  301. package/src/common-auth-embedded/quota/index.js +2 -2
  302. package/src/common-auth-embedded/quota/map.d.ts +11 -0
  303. package/src/common-auth-embedded/quota/map.js +36 -1
  304. package/src/common-auth-embedded/quota/merge.d.ts +3 -1
  305. package/src/common-auth-embedded/quota/merge.js +21 -5
  306. package/src/common-auth-embedded/quota/projection.d.ts +2 -1
  307. package/src/common-auth-embedded/quota/projection.js +3 -1
  308. package/src/common-auth-embedded/setup/command-runner.js +49 -0
  309. package/src/common-auth-embedded/setup/command.d.ts +3 -0
  310. package/src/common-auth-embedded/setup/command.js +215 -0
  311. package/src/common-auth-embedded/setup/config-write.js +60 -0
  312. package/src/common-auth-embedded/setup/detect.d.ts +6 -0
  313. package/src/common-auth-embedded/setup/detect.js +224 -0
  314. package/src/common-auth-embedded/setup/enroll.js +70 -0
  315. package/src/common-auth-embedded/setup/index.d.ts +5 -0
  316. package/src/common-auth-embedded/setup/index.js +4 -0
  317. package/src/common-auth-embedded/setup/paths.js +33 -0
  318. package/src/common-auth-embedded/setup/process-fence.d.ts +43 -0
  319. package/src/common-auth-embedded/setup/process-fence.js +270 -0
  320. package/src/common-auth-embedded/setup/prompts.js +26 -0
  321. package/src/common-auth-embedded/setup/register.d.ts +11 -0
  322. package/src/common-auth-embedded/setup/register.js +130 -0
  323. package/src/common-auth-embedded/setup/types.d.ts +136 -0
  324. package/src/common-auth-embedded/source-output.json +228 -80
  325. package/src/common-auth-embedded/store/schema.d.ts +2 -0
  326. package/src/common-auth-embedded/store/schema.js +3 -2
  327. package/src/sidebar-state.ts +19 -2
  328. package/src/tui-compiled/common-auth-embedded/quota/codec.js +2 -1
  329. package/src/tui-compiled/common-auth-embedded/quota/format.js +78 -42
  330. package/src/tui-compiled/common-auth-embedded/quota/index.js +2 -2
  331. package/src/tui-compiled/common-auth-embedded/quota/map.js +36 -1
  332. package/src/tui-compiled/common-auth-embedded/quota/merge.js +21 -5
  333. package/src/tui-compiled/common-auth-embedded/quota/projection.js +3 -1
  334. package/src/tui-compiled/quota-presentation.js +42 -9
  335. package/src/tui-compiled/sidebar-state.js +15 -1
  336. package/src/tui-compiled/tui.js +516 -334
  337. package/src/tui-ga-compiled/host-ga.js +11 -38
  338. package/src/tui-ga-compiled/shared/1ff34afa7c42d196-projection.js +3 -1
  339. package/src/tui-ga-compiled/shared/77138df80c7ae006-map.js +36 -1
  340. package/src/tui-ga-compiled/shared/98cc0c186c46c42d-quota-presentation.js +42 -9
  341. package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +78 -42
  342. package/src/tui-ga-compiled/shared/bf17cbee28e58197-index.js +2 -2
  343. package/src/tui-ga-compiled/shared/ca21dc417b36dc5d-codec.js +2 -1
  344. package/src/tui-ga-compiled/shared/ecc214300932dfb6-merge.js +21 -5
  345. package/src/tui-ga-raw/host-ga.tsx +31 -62
  346. package/src/tui-ga-raw/shared/1ff34afa7c42d196-projection.js +3 -1
  347. package/src/tui-ga-raw/shared/77138df80c7ae006-map.js +36 -1
  348. package/src/tui-ga-raw/shared/98cc0c186c46c42d-quota-presentation.js +42 -9
  349. package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +78 -42
  350. package/src/tui-ga-raw/shared/bf17cbee28e58197-index.js +2 -2
  351. package/src/tui-ga-raw/shared/ca21dc417b36dc5d-codec.js +2 -1
  352. package/src/tui-ga-raw/shared/ecc214300932dfb6-merge.js +21 -5
  353. package/src/tui-raw/common-auth-embedded/quota/codec.js +2 -1
  354. package/src/tui-raw/common-auth-embedded/quota/format.js +78 -42
  355. package/src/tui-raw/common-auth-embedded/quota/index.js +2 -2
  356. package/src/tui-raw/common-auth-embedded/quota/map.js +36 -1
  357. package/src/tui-raw/common-auth-embedded/quota/merge.js +21 -5
  358. package/src/tui-raw/common-auth-embedded/quota/projection.js +3 -1
  359. package/src/tui-raw/quota-presentation.js +42 -9
  360. package/src/tui-raw/sidebar-state.js +15 -1
  361. package/src/tui-raw/tui.tsx +423 -218
  362. package/src/tui.tsx +423 -218
  363. package/dist/src/tui/vault-setup.d.ts +0 -98
  364. package/dist/src/tui/vault-setup.d.ts.map +0 -1
  365. package/dist/src/tui/vault-setup.js +0 -198
  366. package/dist/src/tui/vault-setup.js.map +0 -1
  367. package/dist/types/src/plugin/transform/model-resolver.d.ts +0 -2
  368. package/dist/types/src/plugin/transform/model-resolver.d.ts.map +0 -1
  369. package/dist/types/src/quota-presentation.d.ts +0 -18
  370. package/dist/types/src/quota-presentation.d.ts.map +0 -1
@@ -0,0 +1,215 @@
1
+ import { select } from '../auth-menu/select.js';
2
+ import { isInteractive, printLine, processTerminal, } from '../auth-menu/terminal.js';
3
+ import { hostEnrollmentPaths } from '../claustrum/enrollment.js';
4
+ import { defaultCommandRunner } from './command-runner.js';
5
+ import { detectHosts } from './detect.js';
6
+ import { connectSetupHost } from './enroll.js';
7
+ import { setupPaths } from './paths.js';
8
+ import { assertHostsStopped, createProcessFence, ProcessFenceViolationError, ProcessInspectionError, } from './process-fence.js';
9
+ import { selectSetupHosts } from './prompts.js';
10
+ import { planOpenCodeRegistration, registerOpenCode, registerPi, } from './register.js';
11
+ export const AMBIGUOUS_OPENCODE_MESSAGE = 'Multiple OpenCode generations found. Choose --opencode=1|2|both before running noninteractive setup.';
12
+ function flags(argv) {
13
+ const result = {
14
+ yes: false,
15
+ dryRun: false,
16
+ claustrum: false,
17
+ noClaustrum: false,
18
+ login: false,
19
+ opencode: undefined,
20
+ };
21
+ for (const arg of argv) {
22
+ if (arg === '--yes')
23
+ result.yes = true;
24
+ else if (arg === '--dry-run')
25
+ result.dryRun = true;
26
+ else if (arg === '--claustrum')
27
+ result.claustrum = true;
28
+ else if (arg === '--no-claustrum')
29
+ result.noClaustrum = true;
30
+ else if (arg === '--login')
31
+ result.login = true;
32
+ else if (/^--opencode=(1|2|both)$/.test(arg))
33
+ result.opencode = arg.slice('--opencode='.length);
34
+ else
35
+ throw new Error(`Unknown setup argument: ${arg}`);
36
+ }
37
+ if (result.claustrum && result.noClaustrum)
38
+ throw new Error('--claustrum and --no-claustrum cannot be used together.');
39
+ if (result.login && result.claustrum)
40
+ throw new Error('--login and --claustrum cannot be used together.');
41
+ return result;
42
+ }
43
+ function validatePlugin(plugin) {
44
+ for (const pkg of Object.values(plugin.packages)) {
45
+ if (!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(pkg))
46
+ throw new Error('Setup requires npm package names.');
47
+ }
48
+ if (!/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?(?:\+[a-zA-Z0-9.-]+)?$/.test(plugin.version))
49
+ throw new Error('Setup requires a concrete package version.');
50
+ for (const host of Object.values(plugin.vault.hosts)) {
51
+ if (!/^[a-z0-9][a-z0-9-]*$/.test(host.name))
52
+ throw new Error('Setup requires lowercase vault names containing only letters, digits and dashes.');
53
+ }
54
+ }
55
+ export async function runSetup(plugin, argv = [], io = {}) {
56
+ const options = flags(argv);
57
+ validatePlugin(plugin);
58
+ const terminal = io.terminal ?? processTerminal();
59
+ const detection = await detectHosts(plugin, io);
60
+ printLine(terminal, `${plugin.displayName} setup`);
61
+ for (const [label, host] of [
62
+ ['OpenCode', detection.opencode],
63
+ ['Pi', detection.pi],
64
+ ]) {
65
+ printLine(terminal, `${label}: ${host.installed ? `found (version ${host.version ?? 'unknown'})` : 'not found'} — ${host.directory}`);
66
+ }
67
+ printLine(terminal, `Claustrum: ${detection.claustrum.available ? 'available' : 'not available'}`);
68
+ // Pi is registered by running its CLI, so a leftover Pi folder without the
69
+ // CLI cannot be set up. Leave it out instead of failing the whole run, so it
70
+ // never blocks setting up OpenCode.
71
+ const piWithoutCli = detection.pi.installed && !detection.pi.executable;
72
+ if (piWithoutCli)
73
+ printLine(terminal, 'Pi: skipped, because its folder exists but pi is not on PATH. Install the Pi CLI and rerun setup to add it.');
74
+ const found = ['opencode', 'pi'].filter((host) => detection[host].installed && !(host === 'pi' && piWithoutCli));
75
+ // A dry run changes nothing, so without a terminal it plans the --yes path
76
+ // instead of refusing; scripts and CI can preview setup with --dry-run alone.
77
+ const assumeYes = options.yes || (options.dryRun && !isInteractive(terminal));
78
+ if (!assumeYes && !isInteractive(terminal))
79
+ throw new Error('Setup requires a TTY or --yes.');
80
+ const hosts = assumeYes
81
+ ? found
82
+ : ((await selectSetupHosts(terminal, found)) ?? []);
83
+ let generation = options.opencode ??
84
+ (detection.opencode.generation === 'ambiguous'
85
+ ? '1'
86
+ : detection.opencode.generation);
87
+ if (hosts.includes('opencode') &&
88
+ !options.opencode &&
89
+ detection.opencode.generation === 'ambiguous') {
90
+ if (assumeYes || !isInteractive(terminal))
91
+ throw new Error(AMBIGUOUS_OPENCODE_MESSAGE);
92
+ const choice = await select(terminal, [
93
+ { value: '1', label: 'OpenCode 1' },
94
+ { value: '2', label: 'OpenCode 2' },
95
+ { value: 'both', label: 'Both (one compatible registration)' },
96
+ ], { message: 'Which OpenCode generation should be registered?' });
97
+ if (choice === null)
98
+ return { hosts: [], dryRun: options.dryRun, mode: 'local', detection };
99
+ generation = choice;
100
+ }
101
+ if (!hosts.length) {
102
+ printLine(terminal, 'No hosts selected. Install OpenCode or Pi and rerun setup.');
103
+ return { hosts, dryRun: options.dryRun, mode: 'local', detection };
104
+ }
105
+ const { env, platform } = setupPaths(io);
106
+ const fence = io.fence ??
107
+ createProcessFence(io.runner ?? defaultCommandRunner, { platform });
108
+ const stopped = async () => {
109
+ try {
110
+ await assertHostsStopped(fence, env);
111
+ }
112
+ catch (error) {
113
+ if (error instanceof ProcessInspectionError)
114
+ printLine(terminal, error.refusalText);
115
+ throw error;
116
+ }
117
+ };
118
+ printLine(terminal, 'Checking that OpenCode and Pi are not running…');
119
+ if (options.dryRun) {
120
+ try {
121
+ const preview = fence.previewRunningHosts
122
+ ? await fence.previewRunningHosts(env)
123
+ : { hosts: await fence.listRunningHosts(env), uncheckedRuntimes: 0 };
124
+ const active = preview.hosts;
125
+ if (preview.uncheckedRuntimes > 0)
126
+ printLine(terminal, 'Node or Bun programs are running; a real run checks whether any of them is OpenCode or Pi.');
127
+ const names = new Set(new ProcessFenceViolationError(active).activeHosts.map((host) => host.command.toLowerCase() === 'pi' ? 'Pi' : 'OpenCode'));
128
+ for (const name of names)
129
+ printLine(terminal, `${name} is running; setup will ask you to quit it.`);
130
+ }
131
+ catch (error) {
132
+ printLine(terminal, 'Process inspection failed; real setup will require successful inspection and stopped OpenCode/Pi hosts.');
133
+ if (error instanceof ProcessInspectionError)
134
+ printLine(terminal, error.refusalText);
135
+ }
136
+ }
137
+ else
138
+ await stopped();
139
+ if (options.claustrum && !detection.claustrum.available)
140
+ throw new Error('Claustrum is not available. Start ck or use --no-claustrum for local sign-in.');
141
+ let useVault = Boolean(options.claustrum);
142
+ if (!useVault &&
143
+ !options.login &&
144
+ !options.noClaustrum &&
145
+ !assumeYes &&
146
+ detection.claustrum.available &&
147
+ isInteractive(terminal)) {
148
+ // Not `confirm`: it reads Escape and Ctrl-C as "No", and "No" here means
149
+ // a local sign-in. Cancelling must stop setup before anything changes.
150
+ const choice = await select(terminal, [
151
+ { label: 'No', value: false },
152
+ { label: 'Yes', value: true },
153
+ ], { message: 'Connect these hosts to the Claustrum vault?' });
154
+ if (choice === null) {
155
+ printLine(terminal, 'Setup cancelled. Nothing was changed.');
156
+ return { hosts: [], dryRun: options.dryRun, mode: 'local', detection };
157
+ }
158
+ useVault = choice === true;
159
+ }
160
+ const mode = useVault ? 'claustrum' : 'local';
161
+ // Validate every config before login or enrollment can change credential state.
162
+ const writes = hosts.includes('opencode')
163
+ ? planOpenCodeRegistration(plugin, generation, io)
164
+ : [];
165
+ if (options.dryRun) {
166
+ printLine(terminal, 'Dry run: no registrations, enrollment, sign-in or migration will be performed.');
167
+ for (const host of hosts) {
168
+ if (plugin.beforeSignIn)
169
+ printLine(terminal, `Would run beforeSignIn(${host}, ${mode}).`);
170
+ if (useVault) {
171
+ const paths = hostEnrollmentPaths(plugin.vault.hosts[host].paths);
172
+ printLine(terminal, `Would Connect ${host}: write ${paths.statePath} and ${paths.tokenPath}; wait for ck auth enroll approve.`);
173
+ }
174
+ else
175
+ printLine(terminal, `Would sign in locally for ${host}.`);
176
+ if (plugin.beforeRegister)
177
+ printLine(terminal, `Would run beforeRegister(${host}, ${mode}).`);
178
+ }
179
+ for (const write of writes)
180
+ printLine(terminal, `${write.changed ? 'Would write' : 'Unchanged'} ${write.path}:\n${write.content}`);
181
+ if (hosts.includes('pi'))
182
+ printLine(terminal, `Would run ${detection.pi.executable} install npm:${plugin.packages.pi}@${plugin.version}`);
183
+ for (const host of hosts)
184
+ printLine(terminal, `Would migrate ${host} using the plugin callback (provider-specific writes).`);
185
+ }
186
+ else {
187
+ const context = {
188
+ opencodeGeneration: generation,
189
+ mode,
190
+ hosts: Object.freeze([...hosts]),
191
+ piAgentDir: detection.pi.directory,
192
+ };
193
+ for (const host of hosts) {
194
+ await stopped();
195
+ await plugin.beforeSignIn?.(host, context);
196
+ await stopped();
197
+ if (useVault)
198
+ await connectSetupHost(plugin, host, io, terminal, stopped);
199
+ else
200
+ await plugin.signInLocal(host, context);
201
+ await stopped();
202
+ await plugin.beforeRegister?.(host, mode, context);
203
+ await stopped();
204
+ if (host === 'opencode')
205
+ await registerOpenCode(writes, stopped);
206
+ else
207
+ await registerPi(plugin, detection.pi.executable, io);
208
+ await stopped();
209
+ await plugin.migrate(host, context);
210
+ }
211
+ }
212
+ printLine(terminal, `${options.dryRun ? 'Planned' : 'Configured'} ${plugin.displayName} for ${hosts.join(', ')} (${mode}).`);
213
+ printLine(terminal, `Next: ${hosts.includes('opencode') ? 'start OpenCode' : 'start Pi'} and run ${plugin.slashCommand}.`);
214
+ return { hosts, dryRun: options.dryRun, mode, detection };
215
+ }
@@ -0,0 +1,60 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { mkdir, open, rename, stat, unlink } from 'node:fs/promises';
3
+ import { basename, dirname, join } from 'node:path';
4
+ import { setTimeout as delay } from 'node:timers/promises';
5
+ /** Ordinary host config inherits Windows ACLs and preserves an existing POSIX mode. */
6
+ export async function writeHostConfigAtomic(file, content, options = {}) {
7
+ const windows = (options.platform ?? process.platform) === 'win32';
8
+ const parent = dirname(file);
9
+ await mkdir(parent, { recursive: true });
10
+ let mode;
11
+ if (!windows) {
12
+ try {
13
+ mode = (await stat(file)).mode & 0o7777;
14
+ }
15
+ catch (error) {
16
+ if (error.code !== 'ENOENT')
17
+ throw error;
18
+ }
19
+ }
20
+ const stage = join(parent, `.${basename(file)}.${(options.stageName ?? randomUUID)()}.tmp`);
21
+ let created = false;
22
+ try {
23
+ const handle = await open(stage, 'wx', mode ?? 0o666);
24
+ created = true;
25
+ try {
26
+ await handle.writeFile(content, 'utf8');
27
+ // An existing mode is deliberate; restore bits masked by the current umask.
28
+ if (mode !== undefined)
29
+ await handle.chmod(mode);
30
+ }
31
+ finally {
32
+ await handle.close();
33
+ }
34
+ const now = options.now ?? (() => performance.now());
35
+ const started = now();
36
+ for (let attempt = 0;; attempt++) {
37
+ await options.beforeRename?.();
38
+ try {
39
+ await (options.rename ?? rename)(stage, file);
40
+ created = false;
41
+ return;
42
+ }
43
+ catch (error) {
44
+ const code = error.code;
45
+ const remaining = 2000 - (now() - started);
46
+ if (!windows ||
47
+ !['EPERM', 'EBUSY', 'EACCES'].includes(code ?? '') ||
48
+ remaining <= 0 ||
49
+ attempt >= 40)
50
+ throw new Error(`Unable to replace host config ${file}. Close editors or other programs using the file, then rerun setup.`);
51
+ await (options.wait ?? delay)(Math.min(remaining, 25 * 2 ** Math.min(attempt, 2)));
52
+ }
53
+ }
54
+ }
55
+ finally {
56
+ // Never remove a colliding stage that this call did not create.
57
+ if (created)
58
+ await unlink(stage).catch(() => { });
59
+ }
60
+ }
@@ -0,0 +1,6 @@
1
+ import type { SetupDetection, SetupFileSystem, SetupIO, SetupPlugin } from './types.js';
2
+ export declare const defaultSetupFileSystem: SetupFileSystem;
3
+ export declare function findExecutableOnPath(name: string, io?: SetupIO): string | null;
4
+ export declare function openCodeDesktopMarkers(io?: SetupIO): string[];
5
+ export declare function detectOpenCodeGeneration(io?: SetupIO): '1' | '2' | 'ambiguous';
6
+ export declare function detectHosts(plugin: SetupPlugin, io?: SetupIO): Promise<SetupDetection>;
@@ -0,0 +1,224 @@
1
+ import { accessSync, constants, existsSync, readFileSync, realpathSync, statSync, } from 'node:fs';
2
+ import { mkdtemp, rm } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { parse } from 'jsonc-parser';
6
+ import { connectClaustrumEnrollmentClient } from '../claustrum/enrollment.js';
7
+ import { defaultCommandRunner, runResolvedCommand } from './command-runner.js';
8
+ import { setupPaths } from './paths.js';
9
+ function stat(path, kind) {
10
+ try {
11
+ return statSync(path)[kind]();
12
+ }
13
+ catch {
14
+ return false;
15
+ }
16
+ }
17
+ export const defaultSetupFileSystem = {
18
+ exists: existsSync,
19
+ isFile: (path) => stat(path, 'isFile'),
20
+ isDirectory: (path) => stat(path, 'isDirectory'),
21
+ isExecutable(path) {
22
+ try {
23
+ accessSync(path, constants.X_OK);
24
+ return stat(path, 'isFile');
25
+ }
26
+ catch {
27
+ return false;
28
+ }
29
+ },
30
+ readText: (path) => readFileSync(path, 'utf8'),
31
+ realpath: realpathSync,
32
+ };
33
+ export function findExecutableOnPath(name, io = {}) {
34
+ const { env, platform, path, cwd } = setupPaths(io);
35
+ const fs = io.fs ?? defaultSetupFileSystem;
36
+ const value = Object.entries(env).find(([key]) => platform === 'win32' ? key.toUpperCase() === 'PATH' : key === 'PATH')?.[1] ?? '';
37
+ // npm also writes an extensionless POSIX shim on Windows; prefer a runnable launcher.
38
+ const suffixes = platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
39
+ for (const entry of value.split(platform === 'win32' ? ';' : ':')) {
40
+ const dir = entry.trim().replace(/^"|"$/g, '');
41
+ if (!dir)
42
+ continue;
43
+ for (const suffix of suffixes) {
44
+ const candidate = path.resolve(cwd, dir, name + suffix);
45
+ if (platform === 'win32' ? fs.isFile(candidate) : fs.isExecutable(candidate))
46
+ return candidate;
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+ export function openCodeDesktopMarkers(io = {}) {
52
+ const { platform, home, env, path } = setupPaths(io);
53
+ if (platform === 'darwin')
54
+ return [
55
+ '/Applications/OpenCode.app',
56
+ '/Applications/OpenCode Beta.app',
57
+ path.join(home, 'Applications', 'OpenCode.app'),
58
+ path.join(home, 'Applications', 'OpenCode Beta.app'),
59
+ ];
60
+ if (platform === 'win32') {
61
+ const local = env.LOCALAPPDATA || path.join(home, 'AppData', 'Local');
62
+ return [
63
+ path.join(local, 'Programs', 'opencode'),
64
+ path.join(local, 'opencode'),
65
+ ];
66
+ }
67
+ return [
68
+ '/opt/OpenCode',
69
+ '/usr/lib/opencode',
70
+ path.join(home, '.local', 'share', 'applications', 'opencode.desktop'),
71
+ ];
72
+ }
73
+ function launcherTarget(file, io) {
74
+ const fs = io.fs ?? defaultSetupFileSystem;
75
+ const { path } = setupPaths(io);
76
+ try {
77
+ const source = fs.readText(file);
78
+ if (source.length > 64 * 1024)
79
+ return file;
80
+ const operands = [...source.matchAll(/"%~?dp0%?\\([^"%\r\n]+)"/g)];
81
+ if (!operands.length)
82
+ operands.push(...source.matchAll(/"\$basedir\/([^"$\r\n]+)"/g));
83
+ const relative = operands.at(-1)?.[1];
84
+ if (relative) {
85
+ const target = path.join(path.dirname(file), ...relative.split(/[/\\]+/));
86
+ if (fs.isFile(target))
87
+ return fs.realpath(target);
88
+ }
89
+ return fs.realpath(file);
90
+ }
91
+ catch {
92
+ return file;
93
+ }
94
+ }
95
+ function diskGeneration(file, io) {
96
+ const fs = io.fs ?? defaultSetupFileSystem;
97
+ const { path } = setupPaths(io);
98
+ let dir = path.dirname(launcherTarget(file, io));
99
+ for (;;) {
100
+ try {
101
+ const metadata = JSON.parse(fs.readText(path.join(dir, 'package.json')));
102
+ if (['@opencode/cli', '@opencode-ai/cli'].includes(metadata.name))
103
+ return '2';
104
+ if (metadata.name === 'opencode-ai')
105
+ return /^(?:[2-9]\d*|1\d+)\.|^0\.0\.0-(?:beta|dev)-/.test(metadata.version ?? '')
106
+ ? '2'
107
+ : '1';
108
+ }
109
+ catch {
110
+ /* No owning package at this level. */
111
+ }
112
+ const parent = path.dirname(dir);
113
+ if (parent === dir)
114
+ return null;
115
+ dir = parent;
116
+ }
117
+ }
118
+ export function detectOpenCodeGeneration(io = {}) {
119
+ const first = findExecutableOnPath('opencode', io);
120
+ const second = findExecutableOnPath('opencode2', io);
121
+ const shared = first && second && launcherTarget(first, io) === launcherTarget(second, io);
122
+ const fs = io.fs ?? defaultSetupFileSystem;
123
+ const { path, opencode } = setupPaths(io);
124
+ let inferred = '1';
125
+ for (const suffix of ['jsonc', 'json']) {
126
+ const file = path.join(opencode, `opencode.${suffix}`);
127
+ if (!fs.exists(file))
128
+ continue;
129
+ try {
130
+ if (Object.hasOwn(parse(fs.readText(file)) ?? {}, 'plugins'))
131
+ inferred = '2';
132
+ }
133
+ catch {
134
+ /* OpenCode registration rejects malformed config before writing it. */
135
+ }
136
+ break;
137
+ }
138
+ const generation = first
139
+ ? (diskGeneration(first, io) ?? (shared ? '2' : inferred))
140
+ : null;
141
+ if (second && generation === '1' && !shared)
142
+ return 'ambiguous';
143
+ return second || shared ? '2' : (generation ?? inferred);
144
+ }
145
+ export async function detectHosts(plugin, io = {}) {
146
+ const fs = io.fs ?? defaultSetupFileSystem;
147
+ const { env, platform, opencode: configDir, pi: agentDir } = setupPaths(io);
148
+ const runner = io.runner ?? defaultCommandRunner;
149
+ const opencode = findExecutableOnPath('opencode', io) ??
150
+ findExecutableOnPath('opencode2', io);
151
+ const pi = findExecutableOnPath('pi', io);
152
+ const ck = findExecutableOnPath('ck', io);
153
+ const version = async (file) => {
154
+ if (!file)
155
+ return null;
156
+ let root;
157
+ try {
158
+ root = await mkdtemp(join(tmpdir(), 'common-auth-setup-version-'));
159
+ // A diagnostic host launch must not create state in the user's profile, even on a dry run.
160
+ const probeEnv = {
161
+ ...env,
162
+ HOME: root,
163
+ USERPROFILE: root,
164
+ XDG_CONFIG_HOME: root,
165
+ XDG_DATA_HOME: root,
166
+ XDG_STATE_HOME: root,
167
+ XDG_CACHE_HOME: root,
168
+ OPENCODE_CONFIG_DIR: root,
169
+ OPENCODE_CONFIG: undefined,
170
+ OPENCODE_CONFIG_CONTENT: undefined,
171
+ OPENCODE_AUTH_CONTENT: undefined,
172
+ PI_CODING_AGENT_DIR: root,
173
+ };
174
+ const result = await runResolvedCommand(runner, platform, file, ['--version'], probeEnv, 2000);
175
+ return result.exitCode === 0
176
+ ? (/\b\d+\.\d+\.\d+(?:-[\w.-]+)?/.exec(result.stdout)?.[0] ?? null)
177
+ : null;
178
+ }
179
+ catch {
180
+ return null;
181
+ }
182
+ finally {
183
+ if (root)
184
+ await rm(root, { recursive: true, force: true }).catch(() => { });
185
+ }
186
+ };
187
+ let available = false;
188
+ if (ck && fs.exists(plugin.vault.connectionFile)) {
189
+ try {
190
+ const connect = io.connect ?? connectClaustrumEnrollmentClient;
191
+ const client = await connect({
192
+ connectionFile: plugin.vault.connectionFile,
193
+ handshakeTimeoutMs: 2000,
194
+ });
195
+ client.close();
196
+ available = true;
197
+ }
198
+ catch {
199
+ available = false;
200
+ }
201
+ }
202
+ const [openCodeVersion, piVersion] = await Promise.all([
203
+ version(opencode),
204
+ version(pi),
205
+ ]);
206
+ return {
207
+ opencode: {
208
+ installed: fs.isDirectory(configDir) ||
209
+ openCodeDesktopMarkers(io).some((marker) => fs.exists(marker)) ||
210
+ opencode !== null,
211
+ executable: opencode,
212
+ version: openCodeVersion,
213
+ directory: configDir,
214
+ generation: detectOpenCodeGeneration(io),
215
+ },
216
+ pi: {
217
+ installed: pi !== null || fs.isDirectory(agentDir),
218
+ executable: pi,
219
+ version: piVersion,
220
+ directory: agentDir,
221
+ },
222
+ claustrum: { available, executable: ck },
223
+ };
224
+ }
@@ -0,0 +1,70 @@
1
+ import { setTimeout as delay } from 'node:timers/promises';
2
+ import { writeEnrollmentTokenFile } from '@cortexkit/claustrum-client';
3
+ import { printLine } from '../auth-menu/terminal.js';
4
+ import { ClaustrumEnrollmentManager, connectClaustrumEnrollmentClient, hostEnrollmentPaths, } from '../claustrum/enrollment.js';
5
+ import { ProcessFenceViolationError, ProcessInspectionError, } from './process-fence.js';
6
+ /** Enroll an independently revocable host; plugin callbacks choose its credential store and account permissions. */
7
+ export async function connectSetupHost(plugin, host, io, terminal, fence) {
8
+ const { name, paths: input } = plugin.vault.hosts[host];
9
+ const paths = hostEnrollmentPaths(input);
10
+ await fence();
11
+ const client = await (io.connect ?? connectClaustrumEnrollmentClient)({
12
+ connectionFile: plugin.vault.connectionFile,
13
+ handshakeTimeoutMs: 2000,
14
+ }).catch(() => {
15
+ throw new Error('Claustrum connection failed; start ck and rerun setup.');
16
+ });
17
+ try {
18
+ const manager = new ClaustrumEnrollmentManager({
19
+ proposedName: name,
20
+ paths,
21
+ client: {
22
+ enrollPropose: async (input) => {
23
+ await fence();
24
+ return client.enrollPropose(input);
25
+ },
26
+ enrollPoll: async (input) => {
27
+ await fence();
28
+ return client.enrollPoll(input);
29
+ },
30
+ },
31
+ writeTokenFile: async (path, file) => {
32
+ await fence();
33
+ await writeEnrollmentTokenFile(path, file);
34
+ },
35
+ });
36
+ let printedRequest;
37
+ for (let tick = 0; tick < 300; tick++) {
38
+ await fence();
39
+ const status = await manager.reconcile();
40
+ if (status.state === 'approved') {
41
+ printLine(terminal, `Connected ${host} to Claustrum.`);
42
+ return;
43
+ }
44
+ if (status.state !== 'pending' && status.state !== 'busy')
45
+ throw new Error('Claustrum enrollment refused; inspect its status with ck before rerunning setup.');
46
+ if (status.state === 'pending' &&
47
+ status.requestId &&
48
+ status.requestId !== printedRequest) {
49
+ if (!/^[a-zA-Z0-9_-]+$/.test(status.requestId))
50
+ throw new Error('Invalid enrollment request id.');
51
+ printedRequest = status.requestId;
52
+ printLine(terminal, 'Waiting for approval. In another terminal, run:');
53
+ printLine(terminal, ` ck auth enroll approve --request-id ${status.requestId} --name ${name}`);
54
+ printLine(terminal, `Enrollment files: ${paths.statePath}, ${paths.tokenPath}`);
55
+ }
56
+ await (io.wait ?? delay)(1000);
57
+ }
58
+ throw new Error('Claustrum approval is still pending; approve with ck and rerun setup.');
59
+ }
60
+ catch (error) {
61
+ if (error instanceof ProcessFenceViolationError ||
62
+ error instanceof ProcessInspectionError)
63
+ throw error;
64
+ // Enrollment exceptions can carry request secrets or bearer tokens; never display them.
65
+ throw new Error('Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.');
66
+ }
67
+ finally {
68
+ client.close();
69
+ }
70
+ }
@@ -0,0 +1,5 @@
1
+ export { AMBIGUOUS_OPENCODE_MESSAGE, runSetup } from './command.js';
2
+ export { detectHosts, detectOpenCodeGeneration, findExecutableOnPath, openCodeDesktopMarkers, } from './detect.js';
3
+ export { assertHostsStopped, createProcessFence, listSetupProcesses, ProcessFenceViolationError, ProcessInspectionError, type ProcessInspectionStep, } from './process-fence.js';
4
+ export { type PlannedWrite, planOpenCodeRegistration, registerOpenCode, registerPi, updatePluginConfig, } from './register.js';
5
+ export type { CommandResult, CommandRunner, HostDetection, OpenCodeGeneration, ProcessFence, SetupCallbackContext, SetupDetection, SetupEnvironment, SetupFileSystem, SetupHost, SetupIO, SetupPlugin, SetupResult, } from './types.js';
@@ -0,0 +1,4 @@
1
+ export { AMBIGUOUS_OPENCODE_MESSAGE, runSetup } from './command.js';
2
+ export { detectHosts, detectOpenCodeGeneration, findExecutableOnPath, openCodeDesktopMarkers, } from './detect.js';
3
+ export { assertHostsStopped, createProcessFence, listSetupProcesses, ProcessFenceViolationError, ProcessInspectionError, } from './process-fence.js';
4
+ export { planOpenCodeRegistration, registerOpenCode, registerPi, updatePluginConfig, } from './register.js';
@@ -0,0 +1,33 @@
1
+ import { homedir } from 'node:os';
2
+ import { posix, win32 } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ export function setupPaths(io = {}) {
5
+ const env = io.env ?? process.env;
6
+ const platform = io.platform ?? process.platform;
7
+ const path = platform === 'win32' ? win32 : posix;
8
+ const home = io.home ?? (platform === 'win32' ? env.USERPROFILE : env.HOME) ?? homedir();
9
+ const cwd = io.cwd ?? process.cwd();
10
+ const absolute = (value) => path.resolve(cwd, value);
11
+ const config = env.OPENCODE_CONFIG_DIR?.trim();
12
+ const xdg = env.XDG_CONFIG_HOME?.trim();
13
+ let agent = env.PI_CODING_AGENT_DIR?.trim() || path.join(home, '.pi', 'agent');
14
+ if (agent === '~')
15
+ agent = home;
16
+ else if (/^~[/\\]/.test(agent))
17
+ agent = path.join(home, agent.slice(2));
18
+ if (agent.startsWith('file://'))
19
+ agent = fileURLToPath(agent);
20
+ return {
21
+ env,
22
+ platform,
23
+ path,
24
+ home,
25
+ cwd,
26
+ opencode: config
27
+ ? absolute(config)
28
+ : xdg
29
+ ? path.join(absolute(xdg), 'opencode')
30
+ : path.join(home, '.config', 'opencode'),
31
+ pi: absolute(agent),
32
+ };
33
+ }
@@ -0,0 +1,43 @@
1
+ import type { CommandRunner, ProcessFence, SetupEnvironment } from './types.js';
2
+ export interface ProcessInspectionStep {
3
+ step: 'tasklist' | 'CIM' | 'ps';
4
+ exitCode: number | null;
5
+ signal: NodeJS.Signals | null;
6
+ timedOut: boolean;
7
+ durationMs: number;
8
+ }
9
+ export declare class ProcessInspectionError extends Error implements ProcessInspectionStep {
10
+ readonly code = "process-inspection-failed";
11
+ readonly step: ProcessInspectionStep['step'];
12
+ readonly exitCode: number | null;
13
+ readonly signal: NodeJS.Signals | null;
14
+ readonly timedOut: boolean;
15
+ readonly durationMs: number;
16
+ constructor(details: ProcessInspectionStep);
17
+ get refusalText(): string;
18
+ }
19
+ export declare class ProcessFenceViolationError extends Error {
20
+ readonly activeHosts: Array<{
21
+ pid: number;
22
+ command: string;
23
+ }>;
24
+ constructor(activeHosts: Array<{
25
+ pid: number;
26
+ command: string;
27
+ }>);
28
+ }
29
+ /** List processes before filtering hosts; Windows PID 0 is a valid idle-process row. */
30
+ export declare function listSetupProcesses(runner?: CommandRunner, options?: {
31
+ platform?: string;
32
+ env?: SetupEnvironment;
33
+ onStep?: (details: ProcessInspectionStep) => void;
34
+ /** False skips the Windows PowerShell query for Node and Bun command lines. */
35
+ inspectRuntimes?: boolean;
36
+ }): Promise<Array<{
37
+ pid: number;
38
+ command: string;
39
+ }>>;
40
+ export declare function createProcessFence(runner?: CommandRunner, options?: {
41
+ platform?: string;
42
+ }): ProcessFence;
43
+ export declare function assertHostsStopped(fence: ProcessFence, env?: SetupEnvironment): Promise<void>;