@cortexkit/opencode-antigravity-auth 3.0.5 → 3.0.7

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 (422) hide show
  1. package/README.md +38 -352
  2. package/dist/cli.js +13757 -12857
  3. package/dist/cli.js.map +4 -4
  4. package/dist/cli.meta.json +1362 -1056
  5. package/dist/index.js +16038 -16162
  6. package/dist/index.js.map +4 -4
  7. package/dist/index.meta.json +1447 -1375
  8. package/dist/server.js +11254 -10921
  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 +44 -4
  20. package/dist/src/common-auth-embedded/claustrum/consumer.js +134 -2
  21. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +33 -1
  22. package/dist/src/common-auth-embedded/claustrum/custody.js +17 -0
  23. package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +6 -1
  24. package/dist/src/common-auth-embedded/claustrum/enrollment.js +6 -1
  25. package/dist/src/common-auth-embedded/claustrum/index.d.ts +3 -2
  26. package/dist/src/common-auth-embedded/claustrum/index.js +5 -3
  27. package/dist/src/common-auth-embedded/claustrum/insula.d.ts +69 -0
  28. package/dist/src/common-auth-embedded/claustrum/insula.js +152 -0
  29. package/dist/src/common-auth-embedded/claustrum/roster.d.ts +13 -0
  30. package/dist/src/common-auth-embedded/claustrum/roster.js +33 -3
  31. package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
  32. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +26 -12
  33. package/dist/src/common-auth-embedded/pi-slot/lock.js +7 -3
  34. package/dist/src/common-auth-embedded/quota/codec.d.ts +2 -0
  35. package/dist/src/common-auth-embedded/quota/codec.js +2 -1
  36. package/dist/src/common-auth-embedded/quota/format.d.ts +40 -3
  37. package/dist/src/common-auth-embedded/quota/format.js +196 -43
  38. package/dist/src/common-auth-embedded/quota/index.d.ts +4 -4
  39. package/dist/src/common-auth-embedded/quota/index.js +2 -2
  40. package/dist/src/common-auth-embedded/quota/map.d.ts +11 -0
  41. package/dist/src/common-auth-embedded/quota/map.js +36 -1
  42. package/dist/src/common-auth-embedded/quota/merge.d.ts +3 -1
  43. package/dist/src/common-auth-embedded/quota/merge.js +21 -5
  44. package/dist/src/common-auth-embedded/quota/projection.d.ts +2 -1
  45. package/dist/src/common-auth-embedded/quota/projection.js +3 -1
  46. package/dist/src/common-auth-embedded/setup/command-error.d.ts +32 -0
  47. package/dist/src/common-auth-embedded/setup/command-error.js +79 -0
  48. package/dist/src/common-auth-embedded/setup/command-runner.js +143 -0
  49. package/dist/src/common-auth-embedded/setup/command.d.ts +3 -0
  50. package/dist/src/common-auth-embedded/setup/command.js +271 -0
  51. package/dist/src/common-auth-embedded/setup/config-write.js +60 -0
  52. package/dist/src/common-auth-embedded/setup/detect.d.ts +6 -0
  53. package/dist/src/common-auth-embedded/setup/detect.js +224 -0
  54. package/dist/src/common-auth-embedded/setup/enroll.js +82 -0
  55. package/dist/src/common-auth-embedded/setup/index.d.ts +6 -0
  56. package/dist/src/common-auth-embedded/setup/index.js +5 -0
  57. package/dist/src/common-auth-embedded/setup/paths.js +33 -0
  58. package/dist/src/common-auth-embedded/setup/process-fence.d.ts +43 -0
  59. package/dist/src/common-auth-embedded/setup/process-fence.js +270 -0
  60. package/dist/src/common-auth-embedded/setup/prompts.js +26 -0
  61. package/dist/src/common-auth-embedded/setup/register.d.ts +11 -0
  62. package/dist/src/common-auth-embedded/setup/register.js +136 -0
  63. package/dist/src/common-auth-embedded/setup/types.d.ts +150 -0
  64. package/dist/src/common-auth-embedded/source-output.json +265 -101
  65. package/dist/src/common-auth-embedded/store/pool.d.ts +1 -1
  66. package/dist/src/common-auth-embedded/store/pool.js +0 -1
  67. package/dist/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
  68. package/dist/src/common-auth-embedded/store/refresh-lock.js +0 -1
  69. package/dist/src/common-auth-embedded/store/schema.d.ts +2 -0
  70. package/dist/src/common-auth-embedded/store/schema.js +3 -2
  71. package/dist/src/ga/rpc/protocol.d.ts +4 -7
  72. package/dist/src/ga/rpc/protocol.d.ts.map +1 -1
  73. package/dist/src/ga/rpc/protocol.js +5 -13
  74. package/dist/src/ga/rpc/protocol.js.map +1 -1
  75. package/dist/src/ga/server/auth.d.ts +8 -3
  76. package/dist/src/ga/server/auth.d.ts.map +1 -1
  77. package/dist/src/ga/server/auth.js +25 -9
  78. package/dist/src/ga/server/auth.js.map +1 -1
  79. package/dist/src/ga/server/index.d.ts +39 -12
  80. package/dist/src/ga/server/index.d.ts.map +1 -1
  81. package/dist/src/ga/server/index.js +218 -55
  82. package/dist/src/ga/server/index.js.map +1 -1
  83. package/dist/src/ga/server/pool-login.d.ts +22 -0
  84. package/dist/src/ga/server/pool-login.d.ts.map +1 -0
  85. package/dist/src/ga/server/pool-login.js +150 -0
  86. package/dist/src/ga/server/pool-login.js.map +1 -0
  87. package/dist/src/ga/tui/host-ga.d.ts +2 -5
  88. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  89. package/dist/src/ga/tui/host-ga.js +54 -52
  90. package/dist/src/ga/tui/host-ga.js.map +1 -1
  91. package/dist/src/plugin/accounts.d.ts +1 -1
  92. package/dist/src/plugin/accounts.d.ts.map +1 -1
  93. package/dist/src/plugin/accounts.js +1 -0
  94. package/dist/src/plugin/accounts.js.map +1 -1
  95. package/dist/src/plugin/background-vault-quota-refresh.d.ts +2 -0
  96. package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  97. package/dist/src/plugin/background-vault-quota-refresh.js +125 -10
  98. package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
  99. package/dist/src/plugin/command-apply.d.ts +2 -2
  100. package/dist/src/plugin/command-apply.d.ts.map +1 -1
  101. package/dist/src/plugin/command-apply.js +3 -10
  102. package/dist/src/plugin/command-apply.js.map +1 -1
  103. package/dist/src/plugin/commands.d.ts +1 -0
  104. package/dist/src/plugin/commands.d.ts.map +1 -1
  105. package/dist/src/plugin/commands.js +2 -2
  106. package/dist/src/plugin/commands.js.map +1 -1
  107. package/dist/src/plugin/config/operator-settings-schema.d.ts +0 -4
  108. package/dist/src/plugin/config/operator-settings-schema.d.ts.map +1 -1
  109. package/dist/src/plugin/config/operator-settings-schema.js +0 -5
  110. package/dist/src/plugin/config/operator-settings-schema.js.map +1 -1
  111. package/dist/src/plugin/config/schema.d.ts +0 -7
  112. package/dist/src/plugin/config/schema.d.ts.map +1 -1
  113. package/dist/src/plugin/config/schema.js +2 -44
  114. package/dist/src/plugin/config/schema.js.map +1 -1
  115. package/dist/src/plugin/config/writer.d.ts +1 -1
  116. package/dist/src/plugin/config/writer.js +1 -1
  117. package/dist/src/plugin/fetch/retry-state.d.ts +19 -3
  118. package/dist/src/plugin/fetch/retry-state.d.ts.map +1 -1
  119. package/dist/src/plugin/fetch/retry-state.js +0 -6
  120. package/dist/src/plugin/fetch/retry-state.js.map +1 -1
  121. package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
  122. package/dist/src/plugin/fetch-interceptor.js +0 -3
  123. package/dist/src/plugin/fetch-interceptor.js.map +1 -1
  124. package/dist/src/plugin/fetch-routing.d.ts +0 -16
  125. package/dist/src/plugin/fetch-routing.d.ts.map +1 -1
  126. package/dist/src/plugin/fetch-routing.js +0 -49
  127. package/dist/src/plugin/fetch-routing.js.map +1 -1
  128. package/dist/src/plugin/ga-location-services.d.ts +14 -9
  129. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  130. package/dist/src/plugin/ga-location-services.js +124 -43
  131. package/dist/src/plugin/ga-location-services.js.map +1 -1
  132. package/dist/src/plugin/gemini-dump.d.ts.map +1 -1
  133. package/dist/src/plugin/gemini-dump.js +2 -5
  134. package/dist/src/plugin/gemini-dump.js.map +1 -1
  135. package/dist/src/plugin/google-origin.d.ts +7 -0
  136. package/dist/src/plugin/google-origin.d.ts.map +1 -0
  137. package/dist/src/plugin/google-origin.js +14 -0
  138. package/dist/src/plugin/google-origin.js.map +1 -0
  139. package/dist/src/plugin/index.d.ts.map +1 -1
  140. package/dist/src/plugin/index.js +18 -7
  141. package/dist/src/plugin/index.js.map +1 -1
  142. package/dist/src/plugin/logging-utils.d.ts.map +1 -1
  143. package/dist/src/plugin/logging-utils.js +2 -5
  144. package/dist/src/plugin/logging-utils.js.map +1 -1
  145. package/dist/src/plugin/oauth-methods.d.ts.map +1 -1
  146. package/dist/src/plugin/oauth-methods.js +0 -33
  147. package/dist/src/plugin/oauth-methods.js.map +1 -1
  148. package/dist/src/plugin/operator-settings.d.ts +1 -1
  149. package/dist/src/plugin/operator-settings.d.ts.map +1 -1
  150. package/dist/src/plugin/operator-settings.js +1 -8
  151. package/dist/src/plugin/operator-settings.js.map +1 -1
  152. package/dist/src/plugin/quota.d.ts +11 -7
  153. package/dist/src/plugin/quota.d.ts.map +1 -1
  154. package/dist/src/plugin/quota.js +128 -102
  155. package/dist/src/plugin/quota.js.map +1 -1
  156. package/dist/src/plugin/request.d.ts +6 -5
  157. package/dist/src/plugin/request.d.ts.map +1 -1
  158. package/dist/src/plugin/request.js +95 -180
  159. package/dist/src/plugin/request.js.map +1 -1
  160. package/dist/src/plugin/server.d.ts.map +1 -1
  161. package/dist/src/plugin/server.js +60 -53
  162. package/dist/src/plugin/server.js.map +1 -1
  163. package/dist/src/plugin/shared/advisory-repository.d.ts +20 -0
  164. package/dist/src/plugin/shared/advisory-repository.d.ts.map +1 -0
  165. package/dist/src/plugin/shared/advisory-repository.js +91 -0
  166. package/dist/src/plugin/shared/advisory-repository.js.map +1 -0
  167. package/dist/src/plugin/shared/request-services.d.ts +27 -26
  168. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  169. package/dist/src/plugin/shared/request-services.js +244 -245
  170. package/dist/src/plugin/shared/request-services.js.map +1 -1
  171. package/dist/src/plugin/shared/runtime.js +4 -2
  172. package/dist/src/plugin/shared/runtime.js.map +1 -1
  173. package/dist/src/plugin/shared/vault-request-credentials.d.ts +16 -4
  174. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  175. package/dist/src/plugin/shared/vault-request-credentials.js +44 -7
  176. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  177. package/dist/src/plugin/storage.d.ts +2 -2
  178. package/dist/src/plugin/storage.d.ts.map +1 -1
  179. package/dist/src/plugin/storage.js.map +1 -1
  180. package/dist/src/plugin/vault-custody.d.ts +14 -1
  181. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  182. package/dist/src/plugin/vault-custody.js +203 -44
  183. package/dist/src/plugin/vault-custody.js.map +1 -1
  184. package/dist/src/plugin/vault-quota-outcome.d.ts +19 -0
  185. package/dist/src/plugin/vault-quota-outcome.d.ts.map +1 -0
  186. package/dist/src/plugin/vault-quota-outcome.js +47 -0
  187. package/dist/src/plugin/vault-quota-outcome.js.map +1 -0
  188. package/dist/src/quota-presentation.d.ts +29 -1
  189. package/dist/src/quota-presentation.d.ts.map +1 -1
  190. package/dist/src/quota-presentation.js +52 -17
  191. package/dist/src/quota-presentation.js.map +1 -1
  192. package/dist/src/setup.d.ts +15 -0
  193. package/dist/src/setup.d.ts.map +1 -0
  194. package/dist/src/setup.js +320 -0
  195. package/dist/src/setup.js.map +1 -0
  196. package/dist/src/sidebar-projection.d.ts +5 -1
  197. package/dist/src/sidebar-projection.d.ts.map +1 -1
  198. package/dist/src/sidebar-projection.js +6 -2
  199. package/dist/src/sidebar-projection.js.map +1 -1
  200. package/dist/src/sidebar-state.d.ts +1 -1
  201. package/dist/src/sidebar-state.d.ts.map +1 -1
  202. package/dist/src/sidebar-state.js +19 -1
  203. package/dist/src/sidebar-state.js.map +1 -1
  204. package/dist/src/tui/quota-layout.d.ts +94 -0
  205. package/dist/src/tui/quota-layout.d.ts.map +1 -0
  206. package/dist/src/tui/quota-layout.js +139 -0
  207. package/dist/src/tui/quota-layout.js.map +1 -0
  208. package/dist/src/tui/route-layout.d.ts +8 -0
  209. package/dist/src/tui/route-layout.d.ts.map +1 -0
  210. package/dist/src/tui/route-layout.js +36 -0
  211. package/dist/src/tui/route-layout.js.map +1 -0
  212. package/dist/src/tui.d.ts.map +1 -1
  213. package/dist/src/tui.js +120 -127
  214. package/dist/src/tui.js.map +1 -1
  215. package/dist/tui-build-map.json +66 -37
  216. package/dist/tui-ga-build-map.json +66 -37
  217. package/dist/types/src/auth-method-labels.d.ts +3 -0
  218. package/dist/types/src/auth-method-labels.d.ts.map +1 -0
  219. package/dist/types/src/cli.d.ts +3 -1
  220. package/dist/types/src/cli.d.ts.map +1 -1
  221. package/dist/types/src/common-auth-embedded/auth-menu/terminal.d.ts +43 -0
  222. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +142 -0
  223. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +207 -0
  224. package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +164 -0
  225. package/dist/types/src/common-auth-embedded/claustrum/errors.d.ts +16 -0
  226. package/dist/types/src/common-auth-embedded/claustrum/host-slot.d.ts +39 -0
  227. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +19 -0
  228. package/dist/types/src/common-auth-embedded/claustrum/insula.d.ts +69 -0
  229. package/dist/types/src/common-auth-embedded/claustrum/interlock.d.ts +27 -0
  230. package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +221 -0
  231. package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
  232. package/dist/types/src/common-auth-embedded/opencode2/errors.d.ts +25 -0
  233. package/dist/types/src/common-auth-embedded/opencode2/index.d.ts +8 -0
  234. package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +55 -0
  235. package/dist/types/src/common-auth-embedded/opencode2/integration.d.ts +112 -0
  236. package/dist/types/src/common-auth-embedded/opencode2/sse.d.ts +12 -0
  237. package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +413 -0
  238. package/dist/types/src/common-auth-embedded/quota/codec.d.ts +2 -0
  239. package/dist/types/src/common-auth-embedded/quota/format.d.ts +40 -3
  240. package/dist/types/src/common-auth-embedded/quota/index.d.ts +4 -4
  241. package/dist/types/src/common-auth-embedded/quota/map.d.ts +11 -0
  242. package/dist/types/src/common-auth-embedded/quota/merge.d.ts +3 -1
  243. package/dist/types/src/common-auth-embedded/quota/projection.d.ts +2 -1
  244. package/dist/types/src/common-auth-embedded/routing/admission.d.ts +93 -0
  245. package/dist/types/src/common-auth-embedded/routing/index.d.ts +8 -0
  246. package/dist/types/src/common-auth-embedded/routing/ordered.d.ts +47 -0
  247. package/dist/types/src/common-auth-embedded/routing/pins.d.ts +22 -0
  248. package/dist/types/src/common-auth-embedded/routing/sticky.d.ts +158 -0
  249. package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +32 -0
  250. package/dist/types/src/common-auth-embedded/setup/command.d.ts +3 -0
  251. package/dist/types/src/common-auth-embedded/setup/detect.d.ts +6 -0
  252. package/dist/types/src/common-auth-embedded/setup/index.d.ts +6 -0
  253. package/dist/types/src/common-auth-embedded/setup/process-fence.d.ts +43 -0
  254. package/dist/types/src/common-auth-embedded/setup/register.d.ts +11 -0
  255. package/dist/types/src/common-auth-embedded/setup/types.d.ts +150 -0
  256. package/dist/types/src/common-auth-embedded/store/pool.d.ts +1 -1
  257. package/dist/types/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
  258. package/dist/types/src/common-auth-embedded/store/schema.d.ts +2 -0
  259. package/dist/types/src/ga/rpc/protocol.d.ts +4 -7
  260. package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -1
  261. package/dist/types/src/ga/server/auth.d.ts +8 -3
  262. package/dist/types/src/ga/server/auth.d.ts.map +1 -1
  263. package/dist/types/src/ga/server/index.d.ts +39 -12
  264. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  265. package/dist/types/src/ga/server/pool-login.d.ts +22 -0
  266. package/dist/types/src/ga/server/pool-login.d.ts.map +1 -0
  267. package/dist/types/src/plugin/accounts.d.ts +1 -1
  268. package/dist/types/src/plugin/accounts.d.ts.map +1 -1
  269. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts +2 -0
  270. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  271. package/dist/types/src/plugin/command-apply.d.ts +2 -2
  272. package/dist/types/src/plugin/command-apply.d.ts.map +1 -1
  273. package/dist/types/src/plugin/commands.d.ts +1 -0
  274. package/dist/types/src/plugin/commands.d.ts.map +1 -1
  275. package/dist/types/src/plugin/config/operator-settings-schema.d.ts +0 -4
  276. package/dist/types/src/plugin/config/operator-settings-schema.d.ts.map +1 -1
  277. package/dist/types/src/plugin/config/schema.d.ts +0 -7
  278. package/dist/types/src/plugin/config/schema.d.ts.map +1 -1
  279. package/dist/types/src/plugin/config/writer.d.ts +1 -1
  280. package/dist/types/src/plugin/fetch/retry-state.d.ts +19 -3
  281. package/dist/types/src/plugin/fetch/retry-state.d.ts.map +1 -1
  282. package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
  283. package/dist/types/src/plugin/fetch-routing.d.ts +0 -16
  284. package/dist/types/src/plugin/fetch-routing.d.ts.map +1 -1
  285. package/dist/types/src/plugin/ga-location-services.d.ts +14 -9
  286. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  287. package/dist/types/src/plugin/gemini-dump.d.ts.map +1 -1
  288. package/dist/types/src/plugin/google-origin.d.ts +7 -0
  289. package/dist/types/src/plugin/google-origin.d.ts.map +1 -0
  290. package/dist/types/src/plugin/index.d.ts.map +1 -1
  291. package/dist/types/src/plugin/logging-utils.d.ts.map +1 -1
  292. package/dist/types/src/plugin/oauth-methods.d.ts.map +1 -1
  293. package/dist/types/src/plugin/operator-settings.d.ts +1 -1
  294. package/dist/types/src/plugin/operator-settings.d.ts.map +1 -1
  295. package/dist/types/src/plugin/quota.d.ts +11 -7
  296. package/dist/types/src/plugin/quota.d.ts.map +1 -1
  297. package/dist/types/src/plugin/request.d.ts +6 -5
  298. package/dist/types/src/plugin/request.d.ts.map +1 -1
  299. package/dist/types/src/plugin/server.d.ts.map +1 -1
  300. package/dist/types/src/plugin/shared/advisory-repository.d.ts +20 -0
  301. package/dist/types/src/plugin/shared/advisory-repository.d.ts.map +1 -0
  302. package/dist/types/src/plugin/shared/request-services.d.ts +27 -26
  303. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  304. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +16 -4
  305. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  306. package/dist/types/src/plugin/storage.d.ts +2 -2
  307. package/dist/types/src/plugin/storage.d.ts.map +1 -1
  308. package/dist/types/src/plugin/vault-custody.d.ts +14 -1
  309. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  310. package/dist/types/src/plugin/vault-quota-outcome.d.ts +19 -0
  311. package/dist/types/src/plugin/vault-quota-outcome.d.ts.map +1 -0
  312. package/dist/types/src/setup.d.ts +15 -0
  313. package/dist/types/src/setup.d.ts.map +1 -0
  314. package/dist/types/src/sidebar-state.d.ts +1 -1
  315. package/dist/types/src/sidebar-state.d.ts.map +1 -1
  316. package/package.json +5 -4
  317. package/src/common-auth-embedded/claustrum/consumer.d.ts +44 -4
  318. package/src/common-auth-embedded/claustrum/consumer.js +134 -2
  319. package/src/common-auth-embedded/claustrum/custody.d.ts +33 -1
  320. package/src/common-auth-embedded/claustrum/custody.js +17 -0
  321. package/src/common-auth-embedded/claustrum/enrollment.d.ts +6 -1
  322. package/src/common-auth-embedded/claustrum/enrollment.js +6 -1
  323. package/src/common-auth-embedded/claustrum/index.d.ts +3 -2
  324. package/src/common-auth-embedded/claustrum/index.js +5 -3
  325. package/src/common-auth-embedded/claustrum/insula.d.ts +69 -0
  326. package/src/common-auth-embedded/claustrum/insula.js +152 -0
  327. package/src/common-auth-embedded/claustrum/roster.d.ts +13 -0
  328. package/src/common-auth-embedded/claustrum/roster.js +33 -3
  329. package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
  330. package/src/common-auth-embedded/fs/refresh-file-lock.js +26 -12
  331. package/src/common-auth-embedded/pi-slot/lock.js +7 -3
  332. package/src/common-auth-embedded/quota/codec.d.ts +2 -0
  333. package/src/common-auth-embedded/quota/codec.js +2 -1
  334. package/src/common-auth-embedded/quota/format.d.ts +40 -3
  335. package/src/common-auth-embedded/quota/format.js +196 -43
  336. package/src/common-auth-embedded/quota/index.d.ts +4 -4
  337. package/src/common-auth-embedded/quota/index.js +2 -2
  338. package/src/common-auth-embedded/quota/map.d.ts +11 -0
  339. package/src/common-auth-embedded/quota/map.js +36 -1
  340. package/src/common-auth-embedded/quota/merge.d.ts +3 -1
  341. package/src/common-auth-embedded/quota/merge.js +21 -5
  342. package/src/common-auth-embedded/quota/projection.d.ts +2 -1
  343. package/src/common-auth-embedded/quota/projection.js +3 -1
  344. package/src/common-auth-embedded/setup/command-error.d.ts +32 -0
  345. package/src/common-auth-embedded/setup/command-error.js +79 -0
  346. package/src/common-auth-embedded/setup/command-runner.js +143 -0
  347. package/src/common-auth-embedded/setup/command.d.ts +3 -0
  348. package/src/common-auth-embedded/setup/command.js +271 -0
  349. package/src/common-auth-embedded/setup/config-write.js +60 -0
  350. package/src/common-auth-embedded/setup/detect.d.ts +6 -0
  351. package/src/common-auth-embedded/setup/detect.js +224 -0
  352. package/src/common-auth-embedded/setup/enroll.js +82 -0
  353. package/src/common-auth-embedded/setup/index.d.ts +6 -0
  354. package/src/common-auth-embedded/setup/index.js +5 -0
  355. package/src/common-auth-embedded/setup/paths.js +33 -0
  356. package/src/common-auth-embedded/setup/process-fence.d.ts +43 -0
  357. package/src/common-auth-embedded/setup/process-fence.js +270 -0
  358. package/src/common-auth-embedded/setup/prompts.js +26 -0
  359. package/src/common-auth-embedded/setup/register.d.ts +11 -0
  360. package/src/common-auth-embedded/setup/register.js +136 -0
  361. package/src/common-auth-embedded/setup/types.d.ts +150 -0
  362. package/src/common-auth-embedded/source-output.json +265 -101
  363. package/src/common-auth-embedded/store/pool.d.ts +1 -1
  364. package/src/common-auth-embedded/store/pool.js +0 -1
  365. package/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
  366. package/src/common-auth-embedded/store/refresh-lock.js +0 -1
  367. package/src/common-auth-embedded/store/schema.d.ts +2 -0
  368. package/src/common-auth-embedded/store/schema.js +3 -2
  369. package/src/sidebar-state.ts +19 -2
  370. package/src/tui-compiled/common-auth-embedded/quota/codec.js +2 -1
  371. package/src/tui-compiled/common-auth-embedded/quota/format.js +196 -43
  372. package/src/tui-compiled/common-auth-embedded/quota/index.js +2 -2
  373. package/src/tui-compiled/common-auth-embedded/quota/map.js +36 -1
  374. package/src/tui-compiled/common-auth-embedded/quota/merge.js +21 -5
  375. package/src/tui-compiled/common-auth-embedded/quota/projection.js +3 -1
  376. package/src/tui-compiled/quota-presentation.js +42 -9
  377. package/src/tui-compiled/sidebar-state.js +15 -1
  378. package/src/tui-compiled/tui/quota-layout.js +378 -0
  379. package/src/tui-compiled/tui/route-layout.js +30 -0
  380. package/src/tui-compiled/tui.js +271 -371
  381. package/src/tui-ga-compiled/host-ga.js +93 -90
  382. package/src/tui-ga-compiled/shared/1ff34afa7c42d196-projection.js +3 -1
  383. package/src/tui-ga-compiled/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
  384. package/src/tui-ga-compiled/shared/77138df80c7ae006-map.js +36 -1
  385. package/src/tui-ga-compiled/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
  386. package/src/tui-ga-compiled/shared/98cc0c186c46c42d-quota-presentation.js +42 -9
  387. package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +196 -43
  388. package/src/tui-ga-compiled/shared/bf17cbee28e58197-index.js +2 -2
  389. package/src/tui-ga-compiled/shared/ca21dc417b36dc5d-codec.js +2 -1
  390. package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +378 -0
  391. package/src/tui-ga-compiled/shared/ecc214300932dfb6-merge.js +21 -5
  392. package/src/tui-ga-raw/host-ga.tsx +102 -92
  393. package/src/tui-ga-raw/shared/1ff34afa7c42d196-projection.js +3 -1
  394. package/src/tui-ga-raw/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
  395. package/src/tui-ga-raw/shared/77138df80c7ae006-map.js +36 -1
  396. package/src/tui-ga-raw/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
  397. package/src/tui-ga-raw/shared/98cc0c186c46c42d-quota-presentation.js +42 -9
  398. package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +196 -43
  399. package/src/tui-ga-raw/shared/bf17cbee28e58197-index.js +2 -2
  400. package/src/tui-ga-raw/shared/ca21dc417b36dc5d-codec.js +2 -1
  401. package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +391 -0
  402. package/src/tui-ga-raw/shared/ecc214300932dfb6-merge.js +21 -5
  403. package/src/tui-raw/common-auth-embedded/quota/codec.js +2 -1
  404. package/src/tui-raw/common-auth-embedded/quota/format.js +196 -43
  405. package/src/tui-raw/common-auth-embedded/quota/index.js +2 -2
  406. package/src/tui-raw/common-auth-embedded/quota/map.js +36 -1
  407. package/src/tui-raw/common-auth-embedded/quota/merge.js +21 -5
  408. package/src/tui-raw/common-auth-embedded/quota/projection.js +3 -1
  409. package/src/tui-raw/quota-presentation.js +42 -9
  410. package/src/tui-raw/sidebar-state.js +15 -1
  411. package/src/tui-raw/tui/quota-layout.tsx +391 -0
  412. package/src/tui-raw/tui/route-layout.js +30 -0
  413. package/src/tui-raw/tui.tsx +218 -272
  414. package/src/tui.tsx +218 -272
  415. package/dist/src/tui/vault-setup.d.ts +0 -98
  416. package/dist/src/tui/vault-setup.d.ts.map +0 -1
  417. package/dist/src/tui/vault-setup.js +0 -198
  418. package/dist/src/tui/vault-setup.js.map +0 -1
  419. package/dist/types/src/plugin/transform/model-resolver.d.ts +0 -2
  420. package/dist/types/src/plugin/transform/model-resolver.d.ts.map +0 -1
  421. package/dist/types/src/quota-presentation.d.ts +0 -18
  422. package/dist/types/src/quota-presentation.d.ts.map +0 -1
@@ -83,6 +83,21 @@ function credentialTypeOf(row, family) {
83
83
  return row.refreshAdapter === undefined ? 'api_key' : undefined;
84
84
  return undefined;
85
85
  }
86
+ /**
87
+ * The grants named in the vault's list reply, or undefined when it names none.
88
+ * Both fields must be present: a reply carrying only one of them is treated as
89
+ * unknown rather than completed with a guess. claustrum-client already refuses
90
+ * a malformed value, so nothing here validates it again.
91
+ */
92
+ function grantReachOf(listed) {
93
+ const { grants, grantTuples } = listed;
94
+ if (grants === undefined || grantTuples === undefined)
95
+ return undefined;
96
+ return Object.freeze({
97
+ grants,
98
+ tuples: Object.freeze(grantTuples.map(({ selectorKind, selector, operation }) => Object.freeze({ selectorKind, selector, operation }))),
99
+ });
100
+ }
86
101
  /**
87
102
  * Reads this consumer's vault credentials (list, fetch, 401 report), with the
88
103
  * enrollment token as authorization. Used by every host of a plugin. There is
@@ -217,10 +232,12 @@ export class ClaustrumScopedCustody {
217
232
  }
218
233
  for (const record of skipped)
219
234
  this.#logger.warn('skipped malformed vault record', record);
235
+ const grantReach = grantReachOf(inventory);
220
236
  return {
221
237
  view: inventory.view,
222
238
  credentials: Object.freeze(credentials),
223
239
  skipped: Object.freeze(skipped),
240
+ ...(grantReach && { grantReach }),
224
241
  };
225
242
  }
226
243
  /**
@@ -103,7 +103,12 @@ export interface EnrollmentAncestorOptions {
103
103
  */
104
104
  export declare function refuseWritableAncestor(parent: string, options?: EnrollmentAncestorOptions): Promise<void>;
105
105
  export declare function readClaustrumEnrollmentStatus(paths: ClaustrumEnrollmentPaths, proposedName: string): Promise<ClaustrumEnrollmentStatus>;
106
- /** Resolve the host's account mode from its enrollment files without writing. */
106
+ /**
107
+ * Resolve the host's account mode from its enrollment files. It never changes
108
+ * their contents or the host's mode. On Windows, reading them may create a
109
+ * missing private state folder and tighten an enrollment file's permissions to
110
+ * owner-only, as every private-file read there does.
111
+ */
107
112
  export declare function enrollmentAuthority(paths: ClaustrumEnrollmentPaths, proposedName: string): Promise<'vault' | 'local' | 'unreadable'>;
108
113
  /**
109
114
  * Read fresh bearer material for one scoped operation; never publish it.
@@ -419,7 +419,12 @@ export async function readClaustrumEnrollmentStatus(paths, proposedName) {
419
419
  }
420
420
  return statusFromState(state);
421
421
  }
422
- /** Resolve the host's account mode from its enrollment files without writing. */
422
+ /**
423
+ * Resolve the host's account mode from its enrollment files. It never changes
424
+ * their contents or the host's mode. On Windows, reading them may create a
425
+ * missing private state folder and tighten an enrollment file's permissions to
426
+ * owner-only, as every private-file read there does.
427
+ */
423
428
  export async function enrollmentAuthority(paths, proposedName) {
424
429
  let status;
425
430
  try {
@@ -2,12 +2,13 @@ import { type ClaustrumClientOptions } from '@cortexkit/claustrum-client';
2
2
  import type { ClaustrumScopedClient } from './custody.js';
3
3
  export { ClaustrumCredentialError, type ClaustrumReporterSource, type EnrollmentTokenFile, } from '@cortexkit/claustrum-client';
4
4
  export { ClaustrumConsumer, type ClaustrumConsumerOptions, type SendOptions, } from './consumer.js';
5
- export { type AccountIdentitySource, type ClaustrumFamily, type ClaustrumScopedAttempt, type ClaustrumScopedClient, ClaustrumScopedCustody, type ClaustrumScopedIdentity, decideScopedRetryAfter401, type IdentityParser, isScopedCredentialRotation, type ScopedRetryReason, SERVING_MARGIN_MS, type SkippedVaultReason, type SkippedVaultRecord, type VaultCredential, type VaultCredentialType, type VaultInventory, } from './custody.js';
5
+ export { type AccountIdentitySource, type ClaustrumFamily, type ClaustrumScopedAttempt, type ClaustrumScopedClient, ClaustrumScopedCustody, type ClaustrumScopedIdentity, decideScopedRetryAfter401, type IdentityParser, isScopedCredentialRotation, type ScopedRetryReason, SERVING_MARGIN_MS, type SkippedVaultReason, type SkippedVaultRecord, type VaultCredential, type VaultCredentialType, type VaultGrantReach, type VaultGrantTuple, type VaultInventory, } from './custody.js';
6
6
  export { type ClaustrumEnrollmentClient, type ClaustrumEnrollmentConnection, type ClaustrumEnrollmentDisconnectResult, ClaustrumEnrollmentManager, type ClaustrumEnrollmentPaths, type ClaustrumEnrollmentResetResult, type ClaustrumEnrollmentStatus, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, type EnrollmentDisposition, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, } from './enrollment.js';
7
7
  export { ClaustrumConsumerError, type ClaustrumConsumerFailureKind, type ClaustrumLogger, } from './errors.js';
8
8
  export { assertHostSlotMatchesMode, assertNotCustodyPlaceholder, CUSTODY_PLACEHOLDER_PREFIX, classifyHostSlot, custodyPlaceholder, custodyPlaceholderKey, type HostSlotContent, isCustodyPlaceholder, isCustodyPlaceholderValue, } from './host-slot.js';
9
+ export type { InsulaQuotaContext, InsulaQuotaOptions, InsulaUsageEntry, InsulaUsageTransport, InsulaUsageWindow, } from './insula.js';
9
10
  export { acceptAccount, type DeclinedAccount, declineAccount, isDeclined, } from './interlock.js';
10
- export { type AccountMapper, acceptVaultRoute, DEFAULT_ROUTE_PREFIX, declineVaultRoute, type MutateVaultRosterOptions, mutateVaultRoster, type ProjectionOptions, projectVaultRoster, type QuotaReceipt, readVaultRoster, recordVaultQuota, refreshVaultRoster, resolveVaultPrimary, type VaultPrimary, type VaultPrimaryBinding, type VaultPrimaryUnavailableReason, type VaultRosterFile, type VaultRosterLockContext, type VaultRosterRow, vaultRoutingRows, } from './roster.js';
11
+ export { type AccountMapper, acceptVaultRoute, DEFAULT_ROUTE_PREFIX, declineVaultRoute, type MutateVaultRosterOptions, mutateVaultRoster, type ProjectionOptions, projectVaultRoster, type QuotaReceipt, readVaultRoster, recordVaultAccountQuota, recordVaultQuota, refreshVaultRoster, resolveVaultPrimary, type VaultPrimary, type VaultPrimaryBinding, type VaultPrimaryUnavailableReason, type VaultRosterFile, type VaultRosterLockContext, type VaultRosterRow, vaultRoutingRows, } from './roster.js';
11
12
  /**
12
13
  * Connect the client that lists and fetches this consumer's vault credentials
13
14
  * on the request path. `connectionFile` is required: this library
@@ -4,6 +4,7 @@
4
4
  // declined-account interlock and the host-slot guard. Needs the optional
5
5
  // peer `@cortexkit/claustrum-client`.
6
6
  import { ClaustrumClient, } from '@cortexkit/claustrum-client';
7
+ import { insulaUsageTransport } from './insula.js';
7
8
  export { ClaustrumCredentialError, } from '@cortexkit/claustrum-client';
8
9
  export { ClaustrumConsumer, } from './consumer.js';
9
10
  export { ClaustrumScopedCustody, decideScopedRetryAfter401, isScopedCredentialRotation, SERVING_MARGIN_MS, } from './custody.js';
@@ -11,12 +12,13 @@ export { ClaustrumEnrollmentManager, classifyEnrollmentError, connectClaustrumEn
11
12
  export { ClaustrumConsumerError, } from './errors.js';
12
13
  export { assertHostSlotMatchesMode, assertNotCustodyPlaceholder, CUSTODY_PLACEHOLDER_PREFIX, classifyHostSlot, custodyPlaceholder, custodyPlaceholderKey, isCustodyPlaceholder, isCustodyPlaceholderValue, } from './host-slot.js';
13
14
  export { acceptAccount, declineAccount, isDeclined, } from './interlock.js';
14
- export { acceptVaultRoute, DEFAULT_ROUTE_PREFIX, declineVaultRoute, mutateVaultRoster, projectVaultRoster, readVaultRoster, recordVaultQuota, refreshVaultRoster, resolveVaultPrimary, vaultRoutingRows, } from './roster.js';
15
+ export { acceptVaultRoute, DEFAULT_ROUTE_PREFIX, declineVaultRoute, mutateVaultRoster, projectVaultRoster, readVaultRoster, recordVaultAccountQuota, recordVaultQuota, refreshVaultRoster, resolveVaultPrimary, vaultRoutingRows, } from './roster.js';
15
16
  /**
16
17
  * Connect the client that lists and fetches this consumer's vault credentials
17
18
  * on the request path. `connectionFile` is required: this library
18
19
  * reads no environment, so the plugin resolves the vault's connection file.
19
20
  */
20
- export function connectClaustrumScopedClient(options) {
21
- return ClaustrumClient.connect(options);
21
+ export async function connectClaustrumScopedClient(options) {
22
+ const client = await ClaustrumClient.connect(options);
23
+ return Object.assign(client, { insula: insulaUsageTransport(options) });
22
24
  }
@@ -0,0 +1,69 @@
1
+ import type { ClaustrumClientOptions } from '@cortexkit/claustrum-client';
2
+ /** Insula's window fields are open: plugins choose which limits they understand. */
3
+ export interface InsulaUsageWindow {
4
+ usedPercent: number;
5
+ rawUsedPercent?: number;
6
+ resetsAt?: string;
7
+ windowMinutes?: number;
8
+ windowKind?: string;
9
+ [field: string]: unknown;
10
+ }
11
+ export interface InsulaUsageEntry {
12
+ provider: string;
13
+ account?: string;
14
+ fetchedAt?: string;
15
+ source?: string;
16
+ stale?: unknown;
17
+ errorClass?: unknown;
18
+ usage?: {
19
+ primary?: InsulaUsageWindow;
20
+ secondary?: InsulaUsageWindow;
21
+ tertiary?: InsulaUsageWindow;
22
+ extraRateWindows?: Array<{
23
+ id?: string;
24
+ title?: string;
25
+ window?: InsulaUsageWindow;
26
+ }>;
27
+ [field: string]: unknown;
28
+ };
29
+ [field: string]: unknown;
30
+ }
31
+ export interface InsulaQuotaContext {
32
+ /** Milliseconds since the epoch, parsed from the producer's fetchedAt. */
33
+ fetchedAt: number;
34
+ source?: string;
35
+ }
36
+ export interface InsulaQuotaOptions<Q> {
37
+ provider: 'codex' | 'claude' | 'antigravity';
38
+ /**
39
+ * Set every converted window's reading time to context.fetchedAt, not poll
40
+ * time. Return undefined for entries the plugin cannot use. Antigravity can
41
+ * receive its own sidebar reading back from insula: accept it only from the
42
+ * vault or when fetchedAt is newer than the plugin's last reading.
43
+ */
44
+ normalize: (entry: InsulaUsageEntry, context: InsulaQuotaContext) => Q | undefined;
45
+ }
46
+ /** Optional transport for custom scoped clients; getUsage must not retry refusals. */
47
+ export interface InsulaUsageTransport {
48
+ connectionFile: string;
49
+ getUsage(): Promise<unknown>;
50
+ }
51
+ /** Constructing this transport opens no connection; getUsage opens one per call. */
52
+ export declare function insulaUsageTransport(options: ClaustrumClientOptions & {
53
+ connectionFile: string;
54
+ }): InsulaUsageTransport;
55
+ export declare class InsulaQuotaSource {
56
+ #private;
57
+ private readonly transport;
58
+ private readonly key;
59
+ constructor(transport: InsulaUsageTransport, key: string);
60
+ refresh(now: number): Promise<void>;
61
+ current(provider: string, accountId: string, now: number): {
62
+ entry: InsulaUsageEntry;
63
+ context: InsulaQuotaContext;
64
+ } | undefined;
65
+ }
66
+ export declare function acquireInsulaQuotaSource(transport: InsulaUsageTransport, tokenPath: string): {
67
+ source: InsulaQuotaSource;
68
+ release(): void;
69
+ };
@@ -0,0 +1,152 @@
1
+ import { resolve } from 'node:path';
2
+ import { storeIdentity } from '@cortexkit/claustrum-client';
3
+ // A static import: claustrum-client already loads subc-client whenever
4
+ // /claustrum is imported, so loading it lazily saves nothing, and a dynamic
5
+ // import makes bundlers emit a separate chunk that a running host loses when
6
+ // its dist folder is rebuilt underneath it.
7
+ import { SubcClient } from '@cortexkit/subc-client';
8
+ /** Constructing this transport opens no connection; getUsage opens one per call. */
9
+ export function insulaUsageTransport(options) {
10
+ const identity = options.identity ??
11
+ storeIdentity(options.projectRoot ?? process.cwd(), options.storagePath ?? process.cwd());
12
+ return {
13
+ connectionFile: options.connectionFile,
14
+ async getUsage() {
15
+ let client;
16
+ let expired = false;
17
+ let timer;
18
+ const timeout = new Promise((_resolve, reject) => {
19
+ timer = setTimeout(() => reject(new Error('insula usage timeout')), 3_000);
20
+ timer.unref?.();
21
+ });
22
+ const request = (async () => {
23
+ client = options.connector
24
+ ? await options.connector({
25
+ connectionFile: options.connectionFile,
26
+ handshakeTimeoutMs: Math.min(options.handshakeTimeoutMs ?? 3_000, 3_000),
27
+ })
28
+ : await SubcClient.connect({
29
+ connectionFile: options.connectionFile,
30
+ handshakeTimeoutMs: Math.min(options.handshakeTimeoutMs ?? 3_000, 3_000),
31
+ });
32
+ // A slow connector may resolve after the whole-call deadline. It still
33
+ // owns a socket, which must not survive or open a route after fallback.
34
+ if (expired) {
35
+ client.close();
36
+ throw new Error('insula usage timeout');
37
+ }
38
+ // Managed call() retries warming routes. A single routeOpen/request
39
+ // instead lets the plugin fall back as soon as the daemon refuses.
40
+ const route = await client.routeOpen({ kind: 'management_surface', module_id: 'insula' }, identity);
41
+ return await client.request(route, { method: 'usage.get', params: {} });
42
+ })();
43
+ try {
44
+ return await Promise.race([request, timeout]);
45
+ }
46
+ finally {
47
+ expired = true;
48
+ clearTimeout(timer);
49
+ client?.close();
50
+ }
51
+ },
52
+ };
53
+ }
54
+ const MINUTE = 60_000;
55
+ const MAX_AGE = 4 * MINUTE;
56
+ const sources = new Map();
57
+ // Keep only the minute budget after the last owner closes, so project churn
58
+ // cannot reset the bound. Expired budgets are pruned on the next tick.
59
+ const attempts = new Map();
60
+ function record(value) {
61
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
62
+ }
63
+ export class InsulaQuotaSource {
64
+ transport;
65
+ key;
66
+ #entries = [];
67
+ #pending;
68
+ constructor(transport, key) {
69
+ this.transport = transport;
70
+ this.key = key;
71
+ }
72
+ refresh(now) {
73
+ if (this.#pending)
74
+ return this.#pending;
75
+ for (const [key, time] of attempts) {
76
+ if (now - time >= MINUTE)
77
+ attempts.delete(key);
78
+ }
79
+ const lastAttempt = attempts.get(this.key);
80
+ if (lastAttempt !== undefined && now - lastAttempt < MINUTE)
81
+ return Promise.resolve();
82
+ // Reserve the minute before I/O, so concurrent projects cannot each poll.
83
+ attempts.set(this.key, now);
84
+ this.#pending = (async () => {
85
+ try {
86
+ const reply = await this.transport.getUsage();
87
+ if (!record(reply) ||
88
+ !Array.isArray(reply.result) ||
89
+ reply.error !== undefined)
90
+ throw new Error('unavailable insula usage');
91
+ // Each response is a snapshot, not a delta. Missing accounts fall back;
92
+ // neither pending nor the entry count asserts provider completeness.
93
+ this.#entries = reply.result.filter((entry) => record(entry) && typeof entry.provider === 'string');
94
+ }
95
+ catch {
96
+ // Refusal is absence, even if the previous reading was still young.
97
+ this.#entries = [];
98
+ }
99
+ })().finally(() => {
100
+ this.#pending = undefined;
101
+ });
102
+ return this.#pending;
103
+ }
104
+ current(provider, accountId, now) {
105
+ for (const entry of this.#entries) {
106
+ if (entry.provider !== provider ||
107
+ typeof entry.account !== 'string' ||
108
+ entry.account.trim() !== accountId)
109
+ continue;
110
+ if (entry.stale !== undefined ||
111
+ entry.errorClass !== undefined ||
112
+ !record(entry.usage))
113
+ continue;
114
+ const fetchedAt = typeof entry.fetchedAt === 'string'
115
+ ? Date.parse(entry.fetchedAt)
116
+ : Number.NaN;
117
+ if (!Number.isFinite(fetchedAt) || now - fetchedAt >= MAX_AGE)
118
+ continue;
119
+ return {
120
+ entry,
121
+ context: {
122
+ fetchedAt,
123
+ ...(typeof entry.source === 'string' && { source: entry.source }),
124
+ },
125
+ };
126
+ }
127
+ return undefined;
128
+ }
129
+ }
130
+ export function acquireInsulaQuotaSource(transport, tokenPath) {
131
+ const key = JSON.stringify([
132
+ resolve(transport.connectionFile),
133
+ resolve(tokenPath),
134
+ ]);
135
+ let shared = sources.get(key);
136
+ if (!shared) {
137
+ shared = { source: new InsulaQuotaSource(transport, key), refs: 0 };
138
+ sources.set(key, shared);
139
+ }
140
+ shared.refs++;
141
+ let released = false;
142
+ return {
143
+ source: shared.source,
144
+ release() {
145
+ if (released)
146
+ return;
147
+ released = true;
148
+ if (--shared.refs === 0)
149
+ sources.delete(key);
150
+ },
151
+ };
152
+ }
@@ -133,6 +133,19 @@ export declare function recordVaultQuota(path: string, input: QuotaReceipt & {
133
133
  routeId: string;
134
134
  observation: QuotaObservation;
135
135
  }): Promise<boolean>;
136
+ /**
137
+ * Merge a quota observation that belongs to an account rather than to a
138
+ * served credential, such as a background reading from insula. The write
139
+ * lands only while the row is still bound to that exact known account, so a
140
+ * reading taken before a replacement never reaches the successor. Unlike
141
+ * `recordVaultQuota` it never binds an account: a row without a known account
142
+ * is refused. Returns whether the observation was kept.
143
+ */
144
+ export declare function recordVaultAccountQuota(path: string, input: {
145
+ routeId: string;
146
+ accountIdentity: string;
147
+ observation: QuotaObservation;
148
+ }): Promise<boolean>;
136
149
  /**
137
150
  * Discover and commit the roster. The lease covers the list call and the
138
151
  * commit, not just the write: an opaque view cannot tell a delayed old reply
@@ -1,7 +1,7 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { acquireRefreshFileLock, withLock, writeJsonAtomic, } from '../fs/index.js';
3
3
  import { readPrivateText, windowsPrivateFiles } from '../fs/private-files.js';
4
- import { isQuotaMap, mergeQuotaObservation, } from '../quota/index.js';
4
+ import { decodeQuotaMap, mergeQuotaObservation, } from '../quota/index.js';
5
5
  import { ClaustrumConsumerError } from './errors.js';
6
6
  import { acceptAccount, declineAccount, isDeclined, } from './interlock.js';
7
7
  export const DEFAULT_ROUTE_PREFIX = 'vault:';
@@ -210,6 +210,7 @@ function optionalString(value) {
210
210
  return value === undefined || typeof value === 'string';
211
211
  }
212
212
  function decodeRow(value) {
213
+ const quota = isRecord(value) ? decodeQuotaMap(value.quota) : undefined;
213
214
  if (!isRecord(value) ||
214
215
  typeof value.routeId !== 'string' ||
215
216
  typeof value.credentialId !== 'string' ||
@@ -224,11 +225,14 @@ function decodeRow(value) {
224
225
  (value.aliases !== undefined &&
225
226
  (!Array.isArray(value.aliases) ||
226
227
  !value.aliases.every((alias) => typeof alias === 'string'))) ||
227
- (value.quota !== undefined && !isQuotaMap(value.quota)) ||
228
+ (value.quota !== undefined && quota === undefined) ||
228
229
  (value.stale !== undefined && value.stale !== true) ||
229
230
  (value.unclaimed !== undefined && value.unclaimed !== true))
230
231
  return undefined;
231
- return value;
232
+ return {
233
+ ...value,
234
+ ...(quota === undefined ? {} : { quota }),
235
+ };
232
236
  }
233
237
  const SKIPPED_REASONS = new Set([
234
238
  'empty credential id',
@@ -435,6 +439,32 @@ export function recordVaultQuota(path, input) {
435
439
  };
436
440
  });
437
441
  }
442
+ /**
443
+ * Merge a quota observation that belongs to an account rather than to a
444
+ * served credential, such as a background reading from insula. The write
445
+ * lands only while the row is still bound to that exact known account, so a
446
+ * reading taken before a replacement never reaches the successor. Unlike
447
+ * `recordVaultQuota` it never binds an account: a row without a known account
448
+ * is refused. Returns whether the observation was kept.
449
+ */
450
+ export function recordVaultAccountQuota(path, input) {
451
+ return mutateVaultRoster(path, (current) => {
452
+ const row = current?.rows.find((entry) => entry.routeId === input.routeId);
453
+ if (!current ||
454
+ !row ||
455
+ row.accountIdentity === undefined ||
456
+ row.accountIdentity !== input.accountIdentity)
457
+ return { result: false };
458
+ const quota = mergeQuotaObservation(row.quota, input.observation);
459
+ return {
460
+ next: {
461
+ ...current,
462
+ rows: current.rows.map((entry) => entry === row ? { ...entry, quota } : entry),
463
+ },
464
+ result: true,
465
+ };
466
+ });
467
+ }
438
468
  /**
439
469
  * Discover and commit the roster. The lease covers the list call and the
440
470
  * commit, not just the write: an opaque view cannot tell a delayed old reply
@@ -13,7 +13,7 @@ export interface RefreshFileLock {
13
13
  whenLost(): Promise<LockLoss>;
14
14
  hasLost(): boolean;
15
15
  }
16
- export declare function acquireRefreshFileLock(options: {
16
+ type RefreshFileLockOptions = {
17
17
  name: string;
18
18
  ttlMs: number;
19
19
  /**
@@ -22,7 +22,6 @@ export declare function acquireRefreshFileLock(options: {
22
22
  * be one host's path.
23
23
  */
24
24
  path: string;
25
- now?: () => number;
26
25
  renew?: boolean;
27
26
  renewIntervalMs?: number;
28
27
  /** Notifies a live-owner refusal without awaiting; observer failures are ignored. */
@@ -30,4 +29,11 @@ export declare function acquireRefreshFileLock(options: {
30
29
  /** Synchronous, never awaited; throws and returned promise/thenable rejections are isolated. */
31
30
  onRenewalTimer?: (event: 'scheduled' | 'cancelled') => void;
32
31
  onStep?: (step: 'stale-marker-stat' | 'stale-marker-claimed' | 'stale-lock-observed' | 'lock-read-ready' | 'lock-missing' | 'stale-lock-confirmed' | 'stale-lock-removed' | 'stale-lock-recreated' | 'eviction-marker-acquired' | 'renewal-owner-confirmed' | 'renewal-marker-unavailable' | 'renewal-write-fenced' | 'renewal-write-ready' | 'renewal-write-finished' | 'relinquish-read' | 'renewal-finished' | 'release-owner-confirmed') => void | Promise<void>;
32
+ };
33
+ /** Filesystem leases share wall time across all callers and processes. */
34
+ export declare function acquireRefreshFileLock(options: RefreshFileLockOptions): Promise<RefreshFileLock | null>;
35
+ /** @internal Clock seam for lease tests; not exported by the package's fs entry point. */
36
+ export declare function acquireRefreshFileLockWithClock(options: RefreshFileLockOptions & {
37
+ now?: () => number;
33
38
  }): Promise<RefreshFileLock | null>;
39
+ export {};
@@ -1,8 +1,25 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { mkdir, open, readFile, rename, rm, stat, writeFile, } from 'node:fs/promises';
2
+ import { mkdir, open, readFile, rename, rm, stat } from 'node:fs/promises';
3
3
  import { dirname, join } from 'node:path';
4
4
  import { createPrivateBytes, createPrivateDirectoryExclusive, ensurePrivateDirectory, PrivateFileError, privateOperation, readPrivateText, verifyPrivate, windowsPrivateFiles, writePrivateAtomic, } from './private-files.js';
5
5
  import { LockOwnershipError, lockPathFor } from './with-lock.js';
6
+ /**
7
+ * Create a new owner-only file and write `text` into it, failing with EEXIST if
8
+ * the file already exists. Writing through the handle rather than path-based
9
+ * `writeFile(path, …, { flag: 'wx' })` matters: Bun's path form also truncates
10
+ * the file it has just created, and on some Linux filesystems (XFS under load)
11
+ * that redundant ftruncate stalls for hundreds of milliseconds, inside every
12
+ * lock acquisition.
13
+ */
14
+ async function createExclusiveText(path, text) {
15
+ const handle = await open(path, 'wx', 0o600);
16
+ try {
17
+ await handle.writeFile(text, 'utf8');
18
+ }
19
+ finally {
20
+ await handle.close();
21
+ }
22
+ }
6
23
  const setRefreshLockRenewalTimeout = globalThis.setTimeout.bind(globalThis);
7
24
  const clearRefreshLockRenewalTimeout = globalThis.clearTimeout.bind(globalThis);
8
25
  // A concurrent contender renaming the freshly-created eviction-marker directory
@@ -14,7 +31,12 @@ export function isLostMarkerRaceError(error) {
14
31
  return (code === 'ENOENT' ||
15
32
  (!windowsPrivateFiles && (code === 'EINVAL' || code === 'ENOTDIR')));
16
33
  }
17
- export async function acquireRefreshFileLock(options) {
34
+ /** Filesystem leases share wall time across all callers and processes. */
35
+ export function acquireRefreshFileLock(options) {
36
+ return acquireRefreshFileLockWithClock({ ...options, now: Date.now });
37
+ }
38
+ /** @internal Clock seam for lease tests; not exported by the package's fs entry point. */
39
+ export async function acquireRefreshFileLockWithClock(options) {
18
40
  const lockPath = lockPathFor(options.path, options.name);
19
41
  const legacyOwnerPath = join(lockPath, 'owner.json');
20
42
  const ownerId = randomUUID();
@@ -152,11 +174,7 @@ export async function acquireRefreshFileLock(options) {
152
174
  if (windowsPrivateFiles)
153
175
  await createPrivateBytes(lockPath, bytes);
154
176
  else
155
- await writeFile(lockPath, bytes, {
156
- encoding: 'utf8',
157
- mode: 0o600,
158
- flag: 'wx',
159
- });
177
+ await createExclusiveText(lockPath, bytes);
160
178
  }
161
179
  async function leaseContention(error) {
162
180
  const code = error.code;
@@ -304,11 +322,7 @@ export async function acquireRefreshFileLock(options) {
304
322
  if (windowsPrivateFiles)
305
323
  await createPrivateBytes(evictOwnerPath, bytes);
306
324
  else
307
- await writeFile(evictOwnerPath, bytes, {
308
- encoding: 'utf8',
309
- mode: 0o600,
310
- flag: 'wx',
311
- });
325
+ await createExclusiveText(evictOwnerPath, bytes);
312
326
  }
313
327
  catch (error) {
314
328
  // A competing contender can rename our just-created marker directory
@@ -1,4 +1,4 @@
1
- import { rmdirSync, statSync } from 'node:fs';
1
+ import { rmdirSync, statSync, utimesSync } from 'node:fs';
2
2
  import { mkdir, rmdir, stat, utimes } from 'node:fs/promises';
3
3
  // Protocol source: proper-lockfile 4.1.2 lib/lockfile.js and lib/mtime-precision.js;
4
4
  // line-level citations and the Pi lock options are recorded in docs/sources.md.
@@ -135,7 +135,9 @@ export async function acquirePiLock(authPath, onCompromised, onRenew) {
135
135
  return;
136
136
  let observed;
137
137
  try {
138
- observed = await stat(path);
138
+ // Durable writes can occupy every async filesystem worker in fsync.
139
+ // Renew on the calling thread so their queue cannot consume the lease.
140
+ observed = statSync(path);
139
141
  }
140
142
  catch (error) {
141
143
  retry(error);
@@ -151,12 +153,14 @@ export async function acquirePiLock(authPath, onCompromised, onRenew) {
151
153
  }
152
154
  const next = new Date(precision === 's' ? Math.ceil(Date.now() / 1_000) * 1_000 : Date.now());
153
155
  try {
154
- await utimes(path, next, next);
156
+ utimesSync(path, next, next);
155
157
  }
156
158
  catch (error) {
157
159
  retry(error);
158
160
  return;
159
161
  }
162
+ // A metadata syscall can itself stall; never confirm an expired lease.
163
+ assertFresh();
160
164
  if (released)
161
165
  return;
162
166
  mtime = next.getTime();
@@ -1,5 +1,7 @@
1
1
  export interface QuotaCodec {
2
2
  readonly validate: (value: unknown) => boolean;
3
+ /** Normalize persisted data before validation; older codecs may omit this. */
4
+ readonly decode?: (value: unknown) => unknown;
3
5
  readonly merge: (stored: unknown, observation: unknown) => unknown;
4
6
  }
5
7
  /**
@@ -1,4 +1,4 @@
1
- import { isQuotaMap } from './map.js';
1
+ import { decodeQuotaMap, isQuotaMap } from './map.js';
2
2
  import { mergeQuotaObservation } from './merge.js';
3
3
  /**
4
4
  * The quota codec the account-pool store (the `/store` subpath) takes when it
@@ -8,5 +8,6 @@ import { mergeQuotaObservation } from './merge.js';
8
8
  */
9
9
  export const quotaCodec = Object.freeze({
10
10
  validate: isQuotaMap,
11
+ decode: decodeQuotaMap,
11
12
  merge: mergeQuotaObservation,
12
13
  });
@@ -11,8 +11,11 @@ export declare const NO_LIMITS_REPORTED = "no limits reported";
11
11
  /**
12
12
  * `compact` fits a footer or a sidebar row: each window's figure, the credit
13
13
  * budget and the stale marker, without reset times. `full` adds each reset.
14
+ * `narrow` fits one line per account in a narrow sidebar: `5h 92% · 7d 66%
15
+ * · Fa 98% left`, the account-wide windows plus at most one model-scoped
16
+ * window or the budget (as `cr`), and no stale marker (see `isQuotaStale`).
14
17
  */
15
- export type QuotaTextForm = 'compact' | 'full';
18
+ export type QuotaTextForm = 'compact' | 'full' | 'narrow';
16
19
  export interface QuotaTextOptions {
17
20
  /** The current time in ms, for reset countdowns and the stale marker. */
18
21
  now: number;
@@ -21,6 +24,26 @@ export interface QuotaTextOptions {
21
24
  /** Defaults to `QUOTA_STALE_AFTER_MS`. */
22
25
  staleAfterMs?: number;
23
26
  }
27
+ export interface QuotaWindowPart {
28
+ kind: 'window' | 'budget';
29
+ /** The display name of a quota window, or `credits` for the budget. */
30
+ name: string;
31
+ /** The shared figure wording, including `credits` for budget figures. */
32
+ figure: string;
33
+ /** The unrounded remaining percentage, clamped to 0–100, when known. */
34
+ remainingPercent?: number;
35
+ /** A bare relative reset span such as `4d`, only when the reset is future. */
36
+ resetIn?: string;
37
+ checkedAt: number;
38
+ /** Whether the reset followed this reading and has arrived by `now`. */
39
+ resetSinceReading: boolean;
40
+ }
41
+ export interface QuotaParts {
42
+ /** Reported windows in display order, followed by the budget when present. */
43
+ windows: QuotaWindowPart[];
44
+ /** The shared checked-age wording, present only when the reading is stale. */
45
+ age?: string;
46
+ }
24
47
  /**
25
48
  * The name a window is shown under. A general window (scope `all`) is named
26
49
  * by its stored length; a model-scoped window keeps the label the plugin
@@ -29,17 +52,31 @@ export interface QuotaTextOptions {
29
52
  * were recorded) falls back to its label.
30
53
  */
31
54
  export declare function quotaWindowName(limit: Pick<ProjectedLimit, 'scope' | 'label' | 'windowMinutes'>): string;
55
+ /**
56
+ * Structured quota wording for layouts that need one row per window. The
57
+ * windows use the same filtering and order as `quotaTextParts`; future resets
58
+ * and the optional age keep the shared formatter's wording.
59
+ */
60
+ export declare function quotaWindowParts(quota: ProjectedQuota | undefined, options: QuotaTextOptions): QuotaParts;
61
+ /**
62
+ * Whether the reading is stale: true exactly when the compact and full forms
63
+ * would end with `checked … ago`. The narrow form leaves that age out to stay
64
+ * short, so a caller drawing a narrow line uses this to dim it instead.
65
+ */
66
+ export declare function isQuotaStale(quota: ProjectedQuota | undefined, options: QuotaTextOptions): boolean;
32
67
  /**
33
68
  * The pieces of a quota text, in order: one per reported window
34
69
  * (`5h 58% left, resets 2h`), then the credit budget when there is one, then
35
70
  * `checked 3h ago` when the oldest piece shown is stale. Empty when nothing
36
71
  * was reported; `formatQuota` turns that into a sentence. A caller printing
37
- * one line per window (the terminal auth menu) uses these directly.
72
+ * one line per window (the terminal auth menu) uses these directly. In the
73
+ * narrow form the pieces are the narrow line's (`5h 92%`, `7d 66% left`).
38
74
  */
39
75
  export declare function quotaTextParts(quota: ProjectedQuota | undefined, options: QuotaTextOptions): string[];
40
76
  /**
41
77
  * A row's quota as one line: `5h 58% left · 7d 90% left` in the compact
42
- * form, with `, resets 2h` after each window in the full form. With nothing
78
+ * form, with `, resets 2h` after each window in the full form, and
79
+ * `5h 58% · 7d 90% left` in the narrow form. With nothing
43
80
  * reported it is `NO_QUOTA_READING`, or `NO_LIMITS_REPORTED` when the
44
81
  * provider answered without a limit for any window.
45
82
  */