@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
@@ -0,0 +1,391 @@
1
+ /** @jsxImportSource @opentui/solid */
2
+
3
+ /**
4
+ * Quota layout shared by the OpenCode 1 sidebar (`tui.tsx`) and the OpenCode 2
5
+ * sidebar (`ga/tui/host-ga.tsx`): one account block with its header line, the
6
+ * reading age once per account, plain-word group headers and one width-fitted
7
+ * row per quota window.
8
+ *
9
+ * Each renderer supplies its own data source and colors. This module imports
10
+ * only the pure quota presentation helpers, so it stays inside both TUI
11
+ * import graphs: no sidebar file, preferences file, RPC, account store,
12
+ * OAuth, token or host SDK module, and nothing that writes to the terminal.
13
+ */
14
+
15
+ import type { RGBA } from "@opentui/core"
16
+ import { For, type JSX, Show } from "solid-js"
17
+ import {
18
+ NO_QUOTA_READING,
19
+ type QuotaReading,
20
+ type QuotaWindowText,
21
+ quotaReadingAge,
22
+ quotaWindowText,
23
+ } from "./98cc0c186c46c42d-quota-presentation.js"
24
+
25
+ export type QuotaTone = 'ok' | 'warn' | 'err' | 'muted' | 'accent' | 'text'
26
+
27
+ /** A text color; `undefined` leaves the host's default color in place. */
28
+ export type QuotaColor = string | RGBA | undefined
29
+
30
+ /**
31
+ * How a renderer colors the quota layout. OpenCode 1 maps these onto its live
32
+ * host theme; a renderer without a theme returns `undefined` everywhere.
33
+ */
34
+ export interface QuotaPalette {
35
+ readonly text: () => QuotaColor
36
+ readonly muted: () => QuotaColor
37
+ readonly tone: (tone: QuotaTone) => QuotaColor
38
+ }
39
+
40
+ /** The bar and threshold settings the layout reads. */
41
+ export interface QuotaAppearance {
42
+ readonly barWidth: number
43
+ readonly barFilledChar: string
44
+ readonly barEmptyChar: string
45
+ readonly warnThreshold: number
46
+ readonly errorThreshold: number
47
+ }
48
+
49
+ /**
50
+ * The OpenCode 1 preference defaults for the quota bar, for a renderer that
51
+ * has no preferences file. A test keeps it equal to `DEFAULT_PREFS.appearance`.
52
+ */
53
+ export const DEFAULT_QUOTA_APPEARANCE: QuotaAppearance = {
54
+ barWidth: 10,
55
+ barFilledChar: '█',
56
+ barEmptyChar: '░',
57
+ warnThreshold: 50,
58
+ errorThreshold: 80,
59
+ }
60
+
61
+ export type QuotaGroupKey = 'gemini' | 'non-gemini'
62
+
63
+ export interface QuotaLayoutWindow {
64
+ readonly window: 'weekly' | '5h'
65
+ readonly remainingPercent: number
66
+ readonly resetAt?: number
67
+ readonly checkedAt?: number
68
+ }
69
+
70
+ export interface QuotaLayoutEntry {
71
+ readonly remainingPercent: number
72
+ readonly resetAt?: number
73
+ readonly checkedAt?: number
74
+ readonly windows?: readonly QuotaLayoutWindow[]
75
+ }
76
+
77
+ /** The account fields the quota layout reads, and nothing else. */
78
+ export interface QuotaLayoutAccount {
79
+ readonly label: string
80
+ readonly quota: {
81
+ readonly gemini?: QuotaLayoutEntry
82
+ readonly 'non-gemini'?: QuotaLayoutEntry
83
+ }
84
+ }
85
+
86
+ // Group headers name each quota pool in plain words.
87
+ export const GROUP_NAMES: Record<QuotaGroupKey, string> = {
88
+ gemini: 'Gemini',
89
+ 'non-gemini': 'Other models',
90
+ }
91
+
92
+ export const QUOTA_ORDER: readonly QuotaGroupKey[] = ['gemini', 'non-gemini']
93
+
94
+ // Shown instead of a stored figure once the window has reset since it was
95
+ // read: the stored figure describes the window before the reset.
96
+ export const RESET_SINCE_READING = 'reset since last check'
97
+
98
+ // Content width used until the first layout pass reports the real one. It
99
+ // fits the narrowest OpenCode sidebar.
100
+ export const ASSUMED_CONTENT_WIDTH = 28
101
+
102
+ // A window row is `<name> <bar> <figure> <reset>`. The bar shrinks to this
103
+ // before the reset column is dropped; below it the bar is dropped too.
104
+ const MIN_BAR_WIDTH = 4
105
+ // The widest figure the formatter writes: `100% left`.
106
+ const FIGURE_WIDTH = 9
107
+ // A window name (`5h`, `7d`) and the space after it.
108
+ const NAME_WIDTH = 3
109
+
110
+ export function quotaTone(
111
+ usedPct: number,
112
+ appearance: QuotaAppearance,
113
+ ): QuotaTone {
114
+ if (usedPct < appearance.warnThreshold) return 'ok'
115
+ if (usedPct < appearance.errorThreshold) return 'warn'
116
+ return 'err'
117
+ }
118
+
119
+ interface BarSegment {
120
+ text: string
121
+ tone: QuotaTone
122
+ }
123
+
124
+ function quotaBarSegments(
125
+ remainingPct: number,
126
+ width: number,
127
+ appearance: QuotaAppearance,
128
+ ): BarSegment[] {
129
+ const usedCells = Math.max(
130
+ 0,
131
+ Math.min(Math.round((remainingPct / 100) * width), width),
132
+ )
133
+ const tone = quotaTone(100 - remainingPct, appearance)
134
+ return [
135
+ { text: appearance.barFilledChar.repeat(usedCells), tone },
136
+ { text: appearance.barEmptyChar.repeat(width - usedCells), tone },
137
+ ].filter((segment) => segment.text.length > 0)
138
+ }
139
+
140
+ // --- Width-fitted quota rows ------------------------------------------------
141
+ //
142
+ // The host sidebars are about 20 to 48 columns wide. Every quota line is
143
+ // sized from the measured content width so that it fits on one line: text is
144
+ // never left to the renderer's wrapping, which breaks a row mid-word or down
145
+ // to one character per line once the right-hand column runs out of room.
146
+
147
+ export interface AccountWindow {
148
+ key: QuotaGroupKey
149
+ reading: QuotaReading
150
+ text: QuotaWindowText
151
+ }
152
+
153
+ // One entry per stored window, in group order. A pool stored before
154
+ // per-window readings existed contributes one window without a name.
155
+ export function accountWindows(
156
+ account: QuotaLayoutAccount,
157
+ now: number,
158
+ ): AccountWindow[] {
159
+ const result: AccountWindow[] = []
160
+ for (const key of QUOTA_ORDER) {
161
+ const entry = account.quota[key]
162
+ if (!entry) continue
163
+ const readings: QuotaReading[] =
164
+ entry.windows && entry.windows.length > 0
165
+ ? entry.windows.map((window) => ({
166
+ window: window.window,
167
+ remainingPercent: window.remainingPercent,
168
+ resetAt: window.resetAt,
169
+ checkedAt: window.checkedAt,
170
+ }))
171
+ : [
172
+ {
173
+ remainingPercent: entry.remainingPercent,
174
+ resetAt: entry.resetAt,
175
+ checkedAt: entry.checkedAt,
176
+ },
177
+ ]
178
+ for (const reading of readings)
179
+ result.push({ key, reading, text: quotaWindowText(reading, now) })
180
+ }
181
+ return result
182
+ }
183
+
184
+ // A window shows its figure only while no reset has happened since it was
185
+ // read and it has a read time at all.
186
+ export function showsFigure(window: AccountWindow): boolean {
187
+ return window.text.remaining != null && !window.text.resetSinceReading
188
+ }
189
+
190
+ interface WindowRowLayout {
191
+ bar: number
192
+ reset: boolean
193
+ }
194
+
195
+ // Column widths for one `<name> <bar> <figure> <reset>` row within `width`
196
+ // cells. The bar shrinks first, down to MIN_BAR_WIDTH; then the reset column
197
+ // is dropped; when even that leaves less than MIN_BAR_WIDTH cells for the
198
+ // bar, the bar is left out and the row is just the name and figure.
199
+ function windowRowLayout(
200
+ width: number,
201
+ named: boolean,
202
+ resetWidth: number,
203
+ maxBar: number,
204
+ ): WindowRowLayout {
205
+ const room = width - (named ? NAME_WIDTH : 0) - FIGURE_WIDTH
206
+ if (resetWidth > 0) {
207
+ const bar = Math.min(maxBar, room - resetWidth - 2)
208
+ if (bar >= MIN_BAR_WIDTH) return { bar, reset: true }
209
+ }
210
+ const bar = Math.min(maxBar, room - 1)
211
+ return { bar: bar >= MIN_BAR_WIDTH ? bar : 0, reset: false }
212
+ }
213
+
214
+ // Shorten a label to `max` cells, marking the cut with an ellipsis.
215
+ export function fitLabel(label: string, max: number): string {
216
+ if (label.length <= max) return label
217
+ if (max <= 0) return ''
218
+ if (max === 1) return '…'
219
+ return `${label.slice(0, max - 1)}…`
220
+ }
221
+
222
+ // One quota window on one line. The bar fills with remaining quota; the
223
+ // figure and reset come from the shared formatter. A window that reset since
224
+ // its reading shows that fact, dim, in place of the stale figure.
225
+ function WindowRow(props: {
226
+ palette: QuotaPalette
227
+ appearance: QuotaAppearance
228
+ window: AccountWindow
229
+ layout: WindowRowLayout
230
+ }): JSX.Element {
231
+ const text = () => props.window.text
232
+ const tone = () => quotaTone(100 - (text().remaining ?? 0), props.appearance)
233
+ return (
234
+ <box width='100%' flexDirection='row'>
235
+ <Show when={text().name !== ''}>
236
+ <text
237
+ width={NAME_WIDTH}
238
+ flexShrink={0}
239
+ wrapMode='none'
240
+ fg={props.palette.muted()}
241
+ >
242
+ {text().name}
243
+ </text>
244
+ </Show>
245
+ <Show
246
+ when={showsFigure(props.window)}
247
+ fallback={
248
+ <text flexShrink={1} wrapMode='none' fg={props.palette.muted()}>
249
+ {text().resetSinceReading ? RESET_SINCE_READING : text().figure}
250
+ </text>
251
+ }
252
+ >
253
+ <Show when={props.layout.bar > 0}>
254
+ <box width={props.layout.bar + 1} flexShrink={0} flexDirection='row'>
255
+ <For
256
+ each={quotaBarSegments(
257
+ text().remaining ?? 0,
258
+ props.layout.bar,
259
+ props.appearance,
260
+ )}
261
+ >
262
+ {(segment) => (
263
+ <text wrapMode='none' fg={props.palette.tone(segment.tone)}>
264
+ {segment.text}
265
+ </text>
266
+ )}
267
+ </For>
268
+ </box>
269
+ </Show>
270
+ <text flexShrink={0} wrapMode='none' fg={props.palette.tone(tone())}>
271
+ {text().figure}
272
+ </text>
273
+ <box flexGrow={1} />
274
+ <Show when={props.layout.reset && text().reset !== ''}>
275
+ <text flexShrink={0} wrapMode='none' fg={props.palette.muted()}>
276
+ {text().reset}
277
+ </text>
278
+ </Show>
279
+ </Show>
280
+ </box>
281
+ )
282
+ }
283
+
284
+ /**
285
+ * One account's quota block. The header line is the account label, the
286
+ * reading age when the oldest reading is stale, and the caller's status word
287
+ * right-aligned; the age moves to its own dim line when the three do not
288
+ * fit. Below it each quota group present gets a plain-word header and one
289
+ * row per window, or a single dim line when there is no reading at all.
290
+ * `children` render after the quota rows (the OpenCode 2 health line).
291
+ */
292
+ export function QuotaAccountBlock(props: {
293
+ palette: QuotaPalette
294
+ appearance: QuotaAppearance
295
+ account: QuotaLayoutAccount
296
+ status: string
297
+ statusTone: QuotaTone
298
+ now: () => number
299
+ width: () => number
300
+ marginTop?: number
301
+ children?: JSX.Element
302
+ }): JSX.Element {
303
+ const windows = () => accountWindows(props.account, props.now())
304
+ const age = () =>
305
+ quotaReadingAge(
306
+ windows().map((window) => window.reading),
307
+ props.now(),
308
+ )
309
+ const ageInline = () =>
310
+ age() !== '' &&
311
+ props.account.label.length + 3 + age().length + 1 + props.status.length <=
312
+ props.width()
313
+ const label = () =>
314
+ fitLabel(props.account.label, props.width() - 1 - props.status.length)
315
+ // One reset column width per account, so bars line up across its rows.
316
+ const resetWidth = () =>
317
+ Math.max(
318
+ 0,
319
+ ...windows()
320
+ .filter(showsFigure)
321
+ .map((window) => window.text.reset.length),
322
+ )
323
+ const layoutFor = (window: AccountWindow) =>
324
+ windowRowLayout(
325
+ props.width(),
326
+ window.text.name !== '',
327
+ resetWidth(),
328
+ props.appearance.barWidth,
329
+ )
330
+ const groups = () =>
331
+ QUOTA_ORDER.map((key) => ({
332
+ key,
333
+ windows: windows().filter((window) => window.key === key),
334
+ })).filter((group) => group.windows.length > 0)
335
+ return (
336
+ <box width='100%' flexDirection='column' marginTop={props.marginTop ?? 0}>
337
+ <box width='100%' flexDirection='row'>
338
+ <text flexShrink={0} wrapMode='none' fg={props.palette.text()}>
339
+ <b>{label()}</b>
340
+ </text>
341
+ <Show when={ageInline()}>
342
+ <text flexShrink={0} wrapMode='none' fg={props.palette.muted()}>
343
+ {` · ${age()}`}
344
+ </text>
345
+ </Show>
346
+ <box flexGrow={1} />
347
+ <text
348
+ flexShrink={0}
349
+ wrapMode='none'
350
+ fg={props.palette.tone(props.statusTone)}
351
+ >
352
+ <b>{props.status}</b>
353
+ </text>
354
+ </box>
355
+ <Show when={age() !== '' && !ageInline()}>
356
+ <text wrapMode='none' fg={props.palette.muted()}>
357
+ {age()}
358
+ </text>
359
+ </Show>
360
+ <Show
361
+ when={groups().length > 0}
362
+ fallback={
363
+ <text wrapMode='none' fg={props.palette.muted()}>
364
+ {NO_QUOTA_READING}
365
+ </text>
366
+ }
367
+ >
368
+ <For each={groups()}>
369
+ {(group) => (
370
+ <>
371
+ <text wrapMode='none' fg={props.palette.muted()}>
372
+ {GROUP_NAMES[group.key]}
373
+ </text>
374
+ <For each={group.windows}>
375
+ {(window) => (
376
+ <WindowRow
377
+ palette={props.palette}
378
+ appearance={props.appearance}
379
+ window={window}
380
+ layout={layoutFor(window)}
381
+ />
382
+ )}
383
+ </For>
384
+ </>
385
+ )}
386
+ </For>
387
+ </Show>
388
+ {props.children}
389
+ </box>
390
+ )
391
+ }
@@ -11,7 +11,7 @@
11
11
  // no entry gets an absence record. A pair outside the coverage is never
12
12
  // touched, so a header-shaped partial observation (which covers only what it
13
13
  // carries) cannot erase a family limit or the budget.
14
- import { ALL_SCOPE, entryTime, isQuotaMap, limitKey, } from "./77138df80c7ae006-map.js";
14
+ import { ALL_SCOPE, decodeQuotaMap, entryTime, isQuotaCounters, limitKey, } from "./77138df80c7ae006-map.js";
15
15
  /** Thrown by `mergeQuotaObservation` when either argument is malformed. */
16
16
  export class QuotaCodecError extends TypeError {
17
17
  constructor(message) {
@@ -83,7 +83,8 @@ export function isQuotaObservation(value) {
83
83
  }
84
84
  if (!coverage.every(isObservedPair))
85
85
  return false;
86
- return value.budget === undefined || isObservedBudget(value.budget);
86
+ return ((value.budget === undefined || isObservedBudget(value.budget)) &&
87
+ (value.counters === undefined || isQuotaCounters(value.counters)));
87
88
  }
88
89
  function compareEntries(left, right) {
89
90
  if (left.scope !== right.scope)
@@ -99,6 +100,16 @@ function mergeBudget(stored, observed, checkedAt) {
99
100
  return stored;
100
101
  return { ...observed, checkedAt };
101
102
  }
103
+ function mergeCounters(stored, observed) {
104
+ const counters = new Map(Object.entries(stored ?? {}));
105
+ for (const [name, counter] of Object.entries(observed ?? {})) {
106
+ const existing = counters.get(name);
107
+ if (existing === undefined || counter.checkedAt >= existing.checkedAt) {
108
+ counters.set(name, counter);
109
+ }
110
+ }
111
+ return counters.size === 0 ? undefined : Object.fromEntries(counters);
112
+ }
102
113
  /**
103
114
  * Applies `observation` to `stored` (undefined for a row with no map yet) and
104
115
  * returns the new map. Pure: neither argument is modified. Throws
@@ -106,13 +117,16 @@ function mergeBudget(stored, observed, checkedAt) {
106
117
  * write rather than persisting a map it could not read back.
107
118
  */
108
119
  export function mergeQuotaObservation(stored, observation) {
109
- if (stored !== undefined && !isQuotaMap(stored)) {
120
+ // Decode the stored map the way reads do, so a malformed counter that reads
121
+ // already hide is dropped here too instead of refusing every later write.
122
+ const decoded = stored === undefined ? undefined : decodeQuotaMap(stored);
123
+ if (stored !== undefined && decoded === undefined) {
110
124
  throw new QuotaCodecError('stored quota map is malformed');
111
125
  }
112
126
  if (!isQuotaObservation(observation)) {
113
127
  throw new QuotaCodecError('quota observation is malformed');
114
128
  }
115
- const base = stored ?? { limits: [] };
129
+ const base = decoded ?? { limits: [] };
116
130
  const at = observation.checkedAt;
117
131
  const entries = new Map();
118
132
  for (const entry of base.limits) {
@@ -152,11 +166,13 @@ export function mergeQuotaObservation(stored, observation) {
152
166
  : { scope, label: pair.label, kind: 'retired', retiredAt: at });
153
167
  }
154
168
  // Keys this module does not recognise are carried over untouched.
155
- const { limits: _limits, budget: _budget, ...unknownKeys } = base;
169
+ const { limits: _limits, budget: _budget, counters: _counters, ...unknownKeys } = base;
156
170
  const budget = mergeBudget(base.budget, observation.budget, at);
171
+ const counters = mergeCounters(base.counters, observation.counters);
157
172
  return {
158
173
  ...unknownKeys,
159
174
  limits: [...entries.values()].sort(compareEntries),
160
175
  ...(budget === undefined ? {} : { budget }),
176
+ ...(counters === undefined ? {} : { counters }),
161
177
  };
162
178
  }
@@ -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
  });