@cortexkit/opencode-antigravity-auth 1.1.0 → 2.0.0

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 (371) hide show
  1. package/README.md +225 -569
  2. package/dist/cli.js +3790 -0
  3. package/dist/cli.js.map +7 -0
  4. package/dist/index.d.ts +1 -3
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +18767 -13829
  7. package/dist/index.js.map +4 -4
  8. package/dist/src/antigravity/oauth.d.ts +1 -1
  9. package/dist/src/antigravity/oauth.js +1 -1
  10. package/dist/src/cli.d.ts +21 -0
  11. package/dist/src/cli.d.ts.map +1 -0
  12. package/dist/src/cli.js +237 -0
  13. package/dist/src/cli.js.map +1 -0
  14. package/dist/src/constants.d.ts +1 -1
  15. package/dist/src/constants.js +1 -1
  16. package/dist/src/hooks/auto-update-checker/cache.d.ts.map +1 -1
  17. package/dist/src/hooks/auto-update-checker/cache.js +13 -13
  18. package/dist/src/hooks/auto-update-checker/cache.js.map +1 -1
  19. package/dist/src/hooks/auto-update-checker/checker.d.ts +1 -1
  20. package/dist/src/hooks/auto-update-checker/checker.d.ts.map +1 -1
  21. package/dist/src/hooks/auto-update-checker/checker.js +75 -51
  22. package/dist/src/hooks/auto-update-checker/checker.js.map +1 -1
  23. package/dist/src/hooks/auto-update-checker/constants.d.ts.map +1 -1
  24. package/dist/src/hooks/auto-update-checker/constants.js +12 -12
  25. package/dist/src/hooks/auto-update-checker/constants.js.map +1 -1
  26. package/dist/src/hooks/auto-update-checker/index.d.ts +6 -6
  27. package/dist/src/hooks/auto-update-checker/index.d.ts.map +1 -1
  28. package/dist/src/hooks/auto-update-checker/index.js +17 -17
  29. package/dist/src/hooks/auto-update-checker/index.js.map +1 -1
  30. package/dist/src/hooks/auto-update-checker/logging.js +2 -2
  31. package/dist/src/hooks/auto-update-checker/logging.js.map +1 -1
  32. package/dist/src/hooks/auto-update-checker/types.d.ts.map +1 -1
  33. package/dist/src/plugin/account-access.d.ts +99 -0
  34. package/dist/src/plugin/account-access.d.ts.map +1 -0
  35. package/dist/src/plugin/account-access.js +480 -0
  36. package/dist/src/plugin/account-access.js.map +1 -0
  37. package/dist/src/plugin/accounts.d.ts +7 -256
  38. package/dist/src/plugin/accounts.d.ts.map +1 -1
  39. package/dist/src/plugin/accounts.js +31 -1367
  40. package/dist/src/plugin/accounts.js.map +1 -1
  41. package/dist/src/plugin/agy-request-metadata.d.ts +1 -1
  42. package/dist/src/plugin/agy-request-metadata.js +1 -1
  43. package/dist/src/plugin/agy-transport.d.ts +1 -1
  44. package/dist/src/plugin/agy-transport.js +1 -1
  45. package/dist/src/plugin/auth-doctor.d.ts +6 -6
  46. package/dist/src/plugin/auth-doctor.d.ts.map +1 -1
  47. package/dist/src/plugin/auth-doctor.js +74 -66
  48. package/dist/src/plugin/auth-doctor.js.map +1 -1
  49. package/dist/src/plugin/auth-drift.d.ts +4 -4
  50. package/dist/src/plugin/auth-drift.d.ts.map +1 -1
  51. package/dist/src/plugin/auth-drift.js +15 -15
  52. package/dist/src/plugin/auth-drift.js.map +1 -1
  53. package/dist/src/plugin/auth-loader.d.ts +35 -0
  54. package/dist/src/plugin/auth-loader.d.ts.map +1 -0
  55. package/dist/src/plugin/auth-loader.js +144 -0
  56. package/dist/src/plugin/auth-loader.js.map +1 -0
  57. package/dist/src/plugin/auth.d.ts +1 -1
  58. package/dist/src/plugin/auth.js +1 -1
  59. package/dist/src/plugin/cache/index.d.ts +1 -1
  60. package/dist/src/plugin/cache/index.d.ts.map +1 -1
  61. package/dist/src/plugin/cache/index.js +1 -1
  62. package/dist/src/plugin/cache/index.js.map +1 -1
  63. package/dist/src/plugin/cache/signature-cache.d.ts +1 -1
  64. package/dist/src/plugin/cache/signature-cache.d.ts.map +1 -1
  65. package/dist/src/plugin/cache/signature-cache.js +23 -24
  66. package/dist/src/plugin/cache/signature-cache.js.map +1 -1
  67. package/dist/src/plugin/cache.d.ts +6 -5
  68. package/dist/src/plugin/cache.d.ts.map +1 -1
  69. package/dist/src/plugin/cache.js +21 -7
  70. package/dist/src/plugin/cache.js.map +1 -1
  71. package/dist/src/plugin/catalog.d.ts +23 -0
  72. package/dist/src/plugin/catalog.d.ts.map +1 -0
  73. package/dist/src/plugin/catalog.js +60 -0
  74. package/dist/src/plugin/catalog.js.map +1 -0
  75. package/dist/src/plugin/cli.d.ts +7 -7
  76. package/dist/src/plugin/cli.d.ts.map +1 -1
  77. package/dist/src/plugin/cli.js +62 -55
  78. package/dist/src/plugin/cli.js.map +1 -1
  79. package/dist/src/plugin/command-data.d.ts +276 -0
  80. package/dist/src/plugin/command-data.d.ts.map +1 -0
  81. package/dist/src/plugin/command-data.js +325 -0
  82. package/dist/src/plugin/command-data.js.map +1 -0
  83. package/dist/src/plugin/commands.d.ts +151 -0
  84. package/dist/src/plugin/commands.d.ts.map +1 -0
  85. package/dist/src/plugin/commands.js +639 -0
  86. package/dist/src/plugin/commands.js.map +1 -0
  87. package/dist/src/plugin/config/index.d.ts +2 -2
  88. package/dist/src/plugin/config/index.d.ts.map +1 -1
  89. package/dist/src/plugin/config/index.js +2 -2
  90. package/dist/src/plugin/config/index.js.map +1 -1
  91. package/dist/src/plugin/config/loader.d.ts +1 -1
  92. package/dist/src/plugin/config/loader.d.ts.map +1 -1
  93. package/dist/src/plugin/config/loader.js +18 -16
  94. package/dist/src/plugin/config/loader.js.map +1 -1
  95. package/dist/src/plugin/config/models.d.ts +2 -2
  96. package/dist/src/plugin/config/models.d.ts.map +1 -1
  97. package/dist/src/plugin/config/models.js +1 -1
  98. package/dist/src/plugin/config/models.js.map +1 -1
  99. package/dist/src/plugin/config/operator-settings-schema.d.ts +29 -0
  100. package/dist/src/plugin/config/operator-settings-schema.d.ts.map +1 -0
  101. package/dist/src/plugin/config/operator-settings-schema.js +28 -0
  102. package/dist/src/plugin/config/operator-settings-schema.js.map +1 -0
  103. package/dist/src/plugin/config/schema.d.ts +21 -2
  104. package/dist/src/plugin/config/schema.d.ts.map +1 -1
  105. package/dist/src/plugin/config/schema.js +85 -25
  106. package/dist/src/plugin/config/schema.js.map +1 -1
  107. package/dist/src/plugin/config/updater.d.ts.map +1 -1
  108. package/dist/src/plugin/config/updater.js +15 -15
  109. package/dist/src/plugin/config/updater.js.map +1 -1
  110. package/dist/src/plugin/config/writer.d.ts +34 -0
  111. package/dist/src/plugin/config/writer.d.ts.map +1 -0
  112. package/dist/src/plugin/config/writer.js +81 -0
  113. package/dist/src/plugin/config/writer.js.map +1 -0
  114. package/dist/src/plugin/core/streaming/index.d.ts +1 -1
  115. package/dist/src/plugin/core/streaming/index.d.ts.map +1 -1
  116. package/dist/src/plugin/core/streaming/index.js +1 -1
  117. package/dist/src/plugin/core/streaming/index.js.map +1 -1
  118. package/dist/src/plugin/core/streaming/transformer.d.ts.map +1 -1
  119. package/dist/src/plugin/core/streaming/transformer.js +85 -44
  120. package/dist/src/plugin/core/streaming/transformer.js.map +1 -1
  121. package/dist/src/plugin/core/streaming/types.d.ts.map +1 -1
  122. package/dist/src/plugin/debug.d.ts +3 -3
  123. package/dist/src/plugin/debug.d.ts.map +1 -1
  124. package/dist/src/plugin/debug.js +85 -47
  125. package/dist/src/plugin/debug.js.map +1 -1
  126. package/dist/src/plugin/dependencies.d.ts +129 -0
  127. package/dist/src/plugin/dependencies.d.ts.map +1 -0
  128. package/dist/src/plugin/dependencies.js +107 -0
  129. package/dist/src/plugin/dependencies.js.map +1 -0
  130. package/dist/src/plugin/errors.d.ts +27 -0
  131. package/dist/src/plugin/errors.d.ts.map +1 -1
  132. package/dist/src/plugin/errors.js +29 -3
  133. package/dist/src/plugin/errors.js.map +1 -1
  134. package/dist/src/plugin/event-handler.d.ts +53 -0
  135. package/dist/src/plugin/event-handler.d.ts.map +1 -0
  136. package/dist/src/plugin/event-handler.js +101 -0
  137. package/dist/src/plugin/event-handler.js.map +1 -0
  138. package/dist/src/plugin/fetch/retry-state.d.ts +61 -0
  139. package/dist/src/plugin/fetch/retry-state.d.ts.map +1 -0
  140. package/dist/src/plugin/fetch/retry-state.js +248 -0
  141. package/dist/src/plugin/fetch/retry-state.js.map +1 -0
  142. package/dist/src/plugin/fetch/warmup.d.ts +30 -0
  143. package/dist/src/plugin/fetch/warmup.d.ts.map +1 -0
  144. package/dist/src/plugin/fetch/warmup.js +76 -0
  145. package/dist/src/plugin/fetch/warmup.js.map +1 -0
  146. package/dist/src/plugin/fetch-interceptor.d.ts +59 -0
  147. package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -0
  148. package/dist/src/plugin/fetch-interceptor.js +1387 -0
  149. package/dist/src/plugin/fetch-interceptor.js.map +1 -0
  150. package/dist/src/plugin/fetch-routing.d.ts +26 -0
  151. package/dist/src/plugin/fetch-routing.d.ts.map +1 -0
  152. package/dist/src/plugin/fetch-routing.js +99 -0
  153. package/dist/src/plugin/fetch-routing.js.map +1 -0
  154. package/dist/src/plugin/fingerprint.d.ts +1 -1
  155. package/dist/src/plugin/fingerprint.js +1 -1
  156. package/dist/src/plugin/gemini-dump.d.ts +5 -5
  157. package/dist/src/plugin/gemini-dump.d.ts.map +1 -1
  158. package/dist/src/plugin/gemini-dump.js +109 -55
  159. package/dist/src/plugin/gemini-dump.js.map +1 -1
  160. package/dist/src/plugin/google-search-tool.d.ts +9 -0
  161. package/dist/src/plugin/google-search-tool.d.ts.map +1 -0
  162. package/dist/src/plugin/google-search-tool.js +56 -0
  163. package/dist/src/plugin/google-search-tool.js.map +1 -0
  164. package/dist/src/plugin/image-saver.d.ts.map +1 -1
  165. package/dist/src/plugin/image-saver.js +16 -16
  166. package/dist/src/plugin/image-saver.js.map +1 -1
  167. package/dist/src/plugin/index.d.ts +23 -0
  168. package/dist/src/plugin/index.d.ts.map +1 -0
  169. package/dist/src/plugin/index.js +308 -0
  170. package/dist/src/plugin/index.js.map +1 -0
  171. package/dist/src/plugin/killswitch.d.ts +94 -0
  172. package/dist/src/plugin/killswitch.d.ts.map +1 -0
  173. package/dist/src/plugin/killswitch.js +194 -0
  174. package/dist/src/plugin/killswitch.js.map +1 -0
  175. package/dist/src/plugin/lifecycle.d.ts +40 -0
  176. package/dist/src/plugin/lifecycle.d.ts.map +1 -0
  177. package/dist/src/plugin/lifecycle.js +73 -0
  178. package/dist/src/plugin/lifecycle.js.map +1 -0
  179. package/dist/src/plugin/logger.d.ts +10 -1
  180. package/dist/src/plugin/logger.d.ts.map +1 -1
  181. package/dist/src/plugin/logger.js +38 -12
  182. package/dist/src/plugin/logger.js.map +1 -1
  183. package/dist/src/plugin/logging-utils.d.ts +35 -1
  184. package/dist/src/plugin/logging-utils.d.ts.map +1 -1
  185. package/dist/src/plugin/logging-utils.js +98 -15
  186. package/dist/src/plugin/logging-utils.js.map +1 -1
  187. package/dist/src/plugin/model-registry.d.ts +1 -1
  188. package/dist/src/plugin/model-registry.js +1 -1
  189. package/dist/src/plugin/oauth-login.d.ts +22 -0
  190. package/dist/src/plugin/oauth-login.d.ts.map +1 -0
  191. package/dist/src/plugin/oauth-login.js +37 -0
  192. package/dist/src/plugin/oauth-login.js.map +1 -0
  193. package/dist/src/plugin/oauth-methods.d.ts +42 -0
  194. package/dist/src/plugin/oauth-methods.d.ts.map +1 -0
  195. package/dist/src/plugin/oauth-methods.js +1284 -0
  196. package/dist/src/plugin/oauth-methods.js.map +1 -0
  197. package/dist/src/plugin/operator-settings.d.ts +40 -0
  198. package/dist/src/plugin/operator-settings.d.ts.map +1 -0
  199. package/dist/src/plugin/operator-settings.js +148 -0
  200. package/dist/src/plugin/operator-settings.js.map +1 -0
  201. package/dist/src/plugin/persist-account-pool.d.ts +37 -0
  202. package/dist/src/plugin/persist-account-pool.d.ts.map +1 -0
  203. package/dist/src/plugin/persist-account-pool.js +142 -0
  204. package/dist/src/plugin/persist-account-pool.js.map +1 -0
  205. package/dist/src/plugin/project.d.ts +1 -1
  206. package/dist/src/plugin/project.js +1 -1
  207. package/dist/src/plugin/prompt-context.d.ts.map +1 -1
  208. package/dist/src/plugin/prompt-context.js +11 -11
  209. package/dist/src/plugin/prompt-context.js.map +1 -1
  210. package/dist/src/plugin/quota.d.ts +97 -41
  211. package/dist/src/plugin/quota.d.ts.map +1 -1
  212. package/dist/src/plugin/quota.js +273 -285
  213. package/dist/src/plugin/quota.js.map +1 -1
  214. package/dist/src/plugin/recovery/constants.d.ts.map +1 -1
  215. package/dist/src/plugin/recovery/constants.js +24 -15
  216. package/dist/src/plugin/recovery/constants.js.map +1 -1
  217. package/dist/src/plugin/recovery/index.d.ts +3 -3
  218. package/dist/src/plugin/recovery/index.d.ts.map +1 -1
  219. package/dist/src/plugin/recovery/index.js +3 -3
  220. package/dist/src/plugin/recovery/index.js.map +1 -1
  221. package/dist/src/plugin/recovery/storage.d.ts +1 -1
  222. package/dist/src/plugin/recovery/storage.d.ts.map +1 -1
  223. package/dist/src/plugin/recovery/storage.js +31 -39
  224. package/dist/src/plugin/recovery/storage.js.map +1 -1
  225. package/dist/src/plugin/recovery/types.d.ts +12 -12
  226. package/dist/src/plugin/recovery/types.d.ts.map +1 -1
  227. package/dist/src/plugin/recovery.d.ts +3 -3
  228. package/dist/src/plugin/recovery.d.ts.map +1 -1
  229. package/dist/src/plugin/recovery.js +62 -58
  230. package/dist/src/plugin/recovery.js.map +1 -1
  231. package/dist/src/plugin/refresh-queue.d.ts +5 -2
  232. package/dist/src/plugin/refresh-queue.d.ts.map +1 -1
  233. package/dist/src/plugin/refresh-queue.js +37 -15
  234. package/dist/src/plugin/refresh-queue.js.map +1 -1
  235. package/dist/src/plugin/request-helpers.d.ts +1 -1
  236. package/dist/src/plugin/request-helpers.d.ts.map +1 -1
  237. package/dist/src/plugin/request-helpers.js +451 -352
  238. package/dist/src/plugin/request-helpers.js.map +1 -1
  239. package/dist/src/plugin/request.d.ts +7 -7
  240. package/dist/src/plugin/request.d.ts.map +1 -1
  241. package/dist/src/plugin/request.js +622 -384
  242. package/dist/src/plugin/request.js.map +1 -1
  243. package/dist/src/plugin/rotation.d.ts +1 -168
  244. package/dist/src/plugin/rotation.d.ts.map +1 -1
  245. package/dist/src/plugin/rotation.js +1 -327
  246. package/dist/src/plugin/rotation.js.map +1 -1
  247. package/dist/src/plugin/search.d.ts.map +1 -1
  248. package/dist/src/plugin/search.js +39 -35
  249. package/dist/src/plugin/search.js.map +1 -1
  250. package/dist/src/plugin/server.d.ts +1 -1
  251. package/dist/src/plugin/server.d.ts.map +1 -1
  252. package/dist/src/plugin/server.js +42 -37
  253. package/dist/src/plugin/server.js.map +1 -1
  254. package/dist/src/plugin/session-context.d.ts +2 -1
  255. package/dist/src/plugin/session-context.d.ts.map +1 -1
  256. package/dist/src/plugin/session-context.js +11 -7
  257. package/dist/src/plugin/session-context.js.map +1 -1
  258. package/dist/src/plugin/storage.d.ts +59 -120
  259. package/dist/src/plugin/storage.d.ts.map +1 -1
  260. package/dist/src/plugin/storage.js +140 -485
  261. package/dist/src/plugin/storage.js.map +1 -1
  262. package/dist/src/plugin/stores/signature-store.d.ts.map +1 -1
  263. package/dist/src/plugin/stores/signature-store.js.map +1 -1
  264. package/dist/src/plugin/thinking-recovery.d.ts.map +1 -1
  265. package/dist/src/plugin/thinking-recovery.js +35 -33
  266. package/dist/src/plugin/thinking-recovery.js.map +1 -1
  267. package/dist/src/plugin/token.d.ts +2 -2
  268. package/dist/src/plugin/token.d.ts.map +1 -1
  269. package/dist/src/plugin/token.js +30 -21
  270. package/dist/src/plugin/token.js.map +1 -1
  271. package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +1 -1
  272. package/dist/src/plugin/transform/cross-model-sanitizer.js +1 -1
  273. package/dist/src/plugin/transform/index.d.ts +1 -1
  274. package/dist/src/plugin/transform/index.js +1 -1
  275. package/dist/src/plugin/transform/model-resolver.d.ts +1 -1
  276. package/dist/src/plugin/transform/model-resolver.js +1 -1
  277. package/dist/src/plugin/transform/types.d.ts +1 -1
  278. package/dist/src/plugin/transform/types.js +1 -1
  279. package/dist/src/plugin/types.d.ts +25 -69
  280. package/dist/src/plugin/types.d.ts.map +1 -1
  281. package/dist/src/plugin/ui/ansi.d.ts.map +1 -1
  282. package/dist/src/plugin/ui/ansi.js.map +1 -1
  283. package/dist/src/plugin/ui/auth-menu.d.ts +1 -1
  284. package/dist/src/plugin/ui/auth-menu.d.ts.map +1 -1
  285. package/dist/src/plugin/ui/auth-menu.js +82 -31
  286. package/dist/src/plugin/ui/auth-menu.js.map +1 -1
  287. package/dist/src/plugin/ui/confirm.d.ts.map +1 -1
  288. package/dist/src/plugin/ui/confirm.js.map +1 -1
  289. package/dist/src/plugin/ui/model-status.d.ts +3 -3
  290. package/dist/src/plugin/ui/model-status.d.ts.map +1 -1
  291. package/dist/src/plugin/ui/model-status.js +3 -3
  292. package/dist/src/plugin/ui/model-status.js.map +1 -1
  293. package/dist/src/plugin/ui/quota-status.d.ts +4 -4
  294. package/dist/src/plugin/ui/quota-status.d.ts.map +1 -1
  295. package/dist/src/plugin/ui/quota-status.js +51 -49
  296. package/dist/src/plugin/ui/quota-status.js.map +1 -1
  297. package/dist/src/plugin/ui/select.d.ts.map +1 -1
  298. package/dist/src/plugin/ui/select.js +22 -12
  299. package/dist/src/plugin/ui/select.js.map +1 -1
  300. package/dist/src/plugin/version.d.ts +1 -1
  301. package/dist/src/plugin/version.js +1 -1
  302. package/dist/src/rpc/notifications.d.ts +6 -0
  303. package/dist/src/rpc/notifications.d.ts.map +1 -0
  304. package/dist/src/rpc/notifications.js +46 -0
  305. package/dist/src/rpc/notifications.js.map +1 -0
  306. package/dist/src/rpc/port-file.d.ts +13 -0
  307. package/dist/src/rpc/port-file.d.ts.map +1 -0
  308. package/dist/src/rpc/port-file.js +109 -0
  309. package/dist/src/rpc/port-file.js.map +1 -0
  310. package/dist/src/rpc/protocol.d.ts +22 -0
  311. package/dist/src/rpc/protocol.d.ts.map +1 -0
  312. package/dist/src/rpc/protocol.js +1 -0
  313. package/dist/src/rpc/protocol.js.map +1 -0
  314. package/dist/src/rpc/rpc-client.d.ts +10 -0
  315. package/dist/src/rpc/rpc-client.d.ts.map +1 -0
  316. package/dist/src/rpc/rpc-client.js +58 -0
  317. package/dist/src/rpc/rpc-client.js.map +1 -0
  318. package/dist/src/rpc/rpc-dir.d.ts +4 -0
  319. package/dist/src/rpc/rpc-dir.d.ts.map +1 -0
  320. package/dist/src/rpc/rpc-dir.js +19 -0
  321. package/dist/src/rpc/rpc-dir.js.map +1 -0
  322. package/dist/src/rpc/rpc-server.d.ts +13 -0
  323. package/dist/src/rpc/rpc-server.d.ts.map +1 -0
  324. package/dist/src/rpc/rpc-server.js +231 -0
  325. package/dist/src/rpc/rpc-server.js.map +1 -0
  326. package/dist/src/sidebar-state.d.ts +240 -0
  327. package/dist/src/sidebar-state.d.ts.map +1 -0
  328. package/dist/src/sidebar-state.js +520 -0
  329. package/dist/src/sidebar-state.js.map +1 -0
  330. package/dist/src/tui/command-dialogs.d.ts +61 -0
  331. package/dist/src/tui/command-dialogs.d.ts.map +1 -0
  332. package/dist/src/tui/command-dialogs.js +497 -0
  333. package/dist/src/tui/command-dialogs.js.map +1 -0
  334. package/dist/src/tui/file-logger.d.ts +41 -0
  335. package/dist/src/tui/file-logger.d.ts.map +1 -0
  336. package/dist/src/tui/file-logger.js +114 -0
  337. package/dist/src/tui/file-logger.js.map +1 -0
  338. package/dist/src/tui-preferences.d.ts +40 -0
  339. package/dist/src/tui-preferences.d.ts.map +1 -0
  340. package/dist/src/tui-preferences.js +328 -0
  341. package/dist/src/tui-preferences.js.map +1 -0
  342. package/dist/src/tui.d.ts +68 -0
  343. package/dist/src/tui.d.ts.map +1 -0
  344. package/dist/src/tui.js +662 -0
  345. package/dist/src/tui.js.map +1 -0
  346. package/package.json +46 -22
  347. package/src/plugin/command-data.ts +651 -0
  348. package/src/rpc/port-file.ts +143 -0
  349. package/src/rpc/protocol.ts +31 -0
  350. package/src/rpc/rpc-client.ts +102 -0
  351. package/src/rpc/rpc-dir.ts +24 -0
  352. package/src/sidebar-state.ts +717 -0
  353. package/src/tui/command-dialogs.tsx +699 -0
  354. package/src/tui/entry.mjs +74 -0
  355. package/src/tui/file-logger.ts +145 -0
  356. package/src/tui-compiled/plugin/command-data.ts +651 -0
  357. package/src/tui-compiled/rpc/port-file.ts +143 -0
  358. package/src/tui-compiled/rpc/protocol.ts +31 -0
  359. package/src/tui-compiled/rpc/rpc-client.ts +102 -0
  360. package/src/tui-compiled/rpc/rpc-dir.ts +24 -0
  361. package/src/tui-compiled/sidebar-state.ts +717 -0
  362. package/src/tui-compiled/tui/command-dialogs.tsx +659 -0
  363. package/src/tui-compiled/tui/file-logger.ts +145 -0
  364. package/src/tui-compiled/tui-preferences.ts +416 -0
  365. package/src/tui-compiled/tui.tsx +1150 -0
  366. package/src/tui-preferences.ts +416 -0
  367. package/src/tui.tsx +1117 -0
  368. package/dist/src/plugin.d.ts +0 -48
  369. package/dist/src/plugin.d.ts.map +0 -1
  370. package/dist/src/plugin.js +0 -3311
  371. package/dist/src/plugin.js.map +0 -1
package/src/tui.tsx ADDED
@@ -0,0 +1,1117 @@
1
+ /** @jsxImportSource @opentui/solid */
2
+
3
+ /**
4
+ * Read-only OpenTUI sidebar for the Antigravity plugin.
5
+ *
6
+ * Mirrors the fleet sibling layout (see `anthropic-auth-live` /
7
+ * `openai-auth-live` `packages/opencode/src/tui.tsx`): a single bordered
8
+ * column with a labelled header badge, a Quota section that lists one
9
+ * `AccountBlock` per visible account, a Routing section that surfaces the
10
+ * most recent session route, and a Health section that only appears when
11
+ * something is wrong. The Antigravity data model is richer than the
12
+ * Claude/Codex one (per-account Claude + Gemini Pro + Gemini Flash quota
13
+ * groups, a health score, and per-session routing decisions), so the
14
+ * fleet components are adapted rather than copied verbatim:
15
+ *
16
+ * - `QuotaRow` reads `remainingPercent + resetAt` from the Antigravity
17
+ * `SidebarQuotaEntry` shape and colors via `quotaTone` (remaining
18
+ * threshold) instead of `usageTone` (used threshold).
19
+ * - `AccountBlock` derives its status word (`active` / `idle` /
20
+ * `cooling` / `off` / `blocked`) from the Antigravity account state and
21
+ * surfaces health as a muted secondary line rather than a top-level
22
+ * bar — fleet parity for "Quota first, health second".
23
+ * - `Routing` resolves to a single `Route` `StatRow` carrying the most
24
+ * recent `activeRouting` entry, since Antigravity does not maintain a
25
+ * per-session sidebar state alongside the slot-rendered tree.
26
+ *
27
+ * Hard rules for this file:
28
+ *
29
+ * - NO direct writes to the host terminal anywhere in the render path.
30
+ * The host terminal is the frame buffer; one stray byte corrupts every
31
+ * subsequent cell. Errors flow through `createTuiFileLogger()`.
32
+ * - NO imports from `./plugin/storage`, `./plugin/accounts`, OAuth code,
33
+ * or anything that touches tokens.
34
+ * - The component uses Solid's `onCleanup` to release the polling timer
35
+ * on unmount so a route change can never leak an interval.
36
+ */
37
+
38
+ import { readFileSync } from 'node:fs'
39
+ import { dirname, join } from 'node:path'
40
+ import { fileURLToPath } from 'node:url'
41
+ import type {
42
+ TuiPlugin,
43
+ TuiPluginApi,
44
+ TuiPluginModule,
45
+ TuiThemeCurrent,
46
+ } from '@opencode-ai/plugin/tui'
47
+ import { createSlot } from '@opentui/solid'
48
+ import {
49
+ createEffect,
50
+ createSignal,
51
+ For,
52
+ type JSX,
53
+ onCleanup,
54
+ onMount,
55
+ Show,
56
+ } from 'solid-js'
57
+ import type { RpcNotification } from './rpc/protocol'
58
+ import { createRpcClient } from './rpc/rpc-client'
59
+ import { getRpcDir } from './rpc/rpc-dir'
60
+ import {
61
+ readSidebarState,
62
+ type SidebarAccountState,
63
+ type SidebarQuotaEntry,
64
+ type SidebarQuotaKey,
65
+ type SidebarStateV1,
66
+ } from './sidebar-state'
67
+ import { openCommandDialog } from './tui/command-dialogs'
68
+ import { createTuiFileLogger, type TuiLogger } from './tui/file-logger'
69
+ import {
70
+ type AntigravityAuthTuiPrefs,
71
+ type AppearancePrefs,
72
+ computeEffectiveOrder,
73
+ DEFAULT_PREFS,
74
+ DEFAULT_SLOT_ORDER,
75
+ PLUGIN_KEY,
76
+ queueTuiPreferenceUpdate,
77
+ readTuiPreferencesFile,
78
+ resolveAntigravityAuthPrefs,
79
+ watchTuiPreferences,
80
+ } from './tui-preferences'
81
+
82
+ const ID = 'cortexkit.antigravity-auth'
83
+
84
+ const POLL_INTERVAL_MS = 2000
85
+ const RPC_POLL_MS = 500
86
+
87
+ const SINGLE_BORDER = { type: 'single' } as any
88
+
89
+ // Read package metadata from either the raw src/ entry or its generated
90
+ // src/tui-compiled/ counterpart. Avoid a JSON import because package.json sits
91
+ // outside the declaration build's rootDir.
92
+ const PLUGIN_VERSION: string = (() => {
93
+ const here = dirname(fileURLToPath(import.meta.url))
94
+ for (const packageFile of [
95
+ join(here, '..', 'package.json'),
96
+ join(here, '..', '..', 'package.json'),
97
+ ]) {
98
+ try {
99
+ const raw = readFileSync(packageFile, 'utf8')
100
+ const version = (JSON.parse(raw) as { version?: string }).version
101
+ if (version) return version
102
+ } catch {
103
+ // Try the path for the other TUI entry layout.
104
+ }
105
+ }
106
+ return ''
107
+ })()
108
+ // Module-scoped state — TEST ISOLATION CONTRACT:
109
+ //
110
+ // `rpcPollStarted`, notification cursor/deduplication state, `rpcInFlight`, and the lazy
111
+ // `sidebarController` below persist across tests via the cached ES
112
+ // module Bun loads once per `--isolate` file. Tests must NOT assert
113
+ // fresh-process behaviour from these variables — by the time the first
114
+ // `startRpcNotificationPolling` runs, all four carry stale values from
115
+ // prior tests in the same file. Test isolation comes from:
116
+ // 1. fresh-importing `tui.tsx` via a cache-busted dynamic `import`
117
+ // so the module re-evaluates with fresh module-scoped bindings, and
118
+ // 2. constructing a fresh `SidebarController` via
119
+ // `createSidebarController(prefs)` and passing it through
120
+ // `SidebarPanel.props.controller` — never through
121
+ // `getSidebarController()`, which lazily seeds the module-scoped
122
+ // singleton.
123
+ let rpcPollStarted = false
124
+ const notificationCursorBySession = new Map<string, number>()
125
+ const dispatchedNotificationIds = new Set<number>()
126
+ let rpcInFlight = false
127
+ const GLOBAL_NOTIFICATION_CURSOR = '__global__'
128
+ const MAX_NOTIFICATION_CURSORS = 256
129
+
130
+ const QUOTA_LABELS: Record<SidebarQuotaKey, string> = {
131
+ claude: 'Cl',
132
+ 'gemini-pro': 'GP',
133
+ 'gemini-flash': 'GF',
134
+ 'gpt-oss': 'GPT',
135
+ }
136
+
137
+ const QUOTA_ORDER: readonly SidebarQuotaKey[] = [
138
+ 'claude',
139
+ 'gemini-pro',
140
+ 'gemini-flash',
141
+ 'gpt-oss',
142
+ ]
143
+
144
+ // --- Theme tokens ----------------------------------------------------------
145
+ //
146
+ // The sidebar pulls its colors from the live host theme (`api.theme.current`
147
+ // — a Solid-friendly getter that re-emits when the user switches theme).
148
+ // Every render path resolves through `toneColor(theme, tone)` with a
149
+ // sibling-style `??` fallback chain, so the sidebar always tracks the
150
+ // active theme and never hardcodes an ANSI literal.
151
+ //
152
+ // `FALLBACK_THEME` is the safety net for tests and any future host that
153
+ // does not implement the theme surface. The fields the sidebar actually
154
+ // uses are populated; the rest of the TuiThemeCurrent fields are left
155
+ // undefined and the `??` chain in `toneColor` falls through cleanly.
156
+
157
+ type Tone = 'ok' | 'warn' | 'err' | 'muted' | 'accent' | 'text'
158
+ type Theme = TuiThemeCurrent
159
+ type ThemeColor = Theme['text']
160
+
161
+ const FALLBACK_THEME = {
162
+ primary: '#3b82f6',
163
+ secondary: '#a855f7',
164
+ accent: '#7c3aed',
165
+ error: '#ef4444',
166
+ warning: '#eab308',
167
+ success: '#22c55e',
168
+ info: '#0ea5e9',
169
+ text: '#e5e7eb',
170
+ textMuted: '#6b7280',
171
+ selectedListItemText: '#ffffff',
172
+ background: '#0b0d12',
173
+ backgroundPanel: '#11131a',
174
+ backgroundElement: '#1a1d27',
175
+ backgroundMenu: '#1a1d27',
176
+ border: '#2a2d3a',
177
+ borderActive: '#7c3aed',
178
+ borderSubtle: '#2a2d3a',
179
+ diffAdded: '#22c55e',
180
+ diffRemoved: '#ef4444',
181
+ diffContext: '#6b7280',
182
+ diffHunkHeader: '#7c3aed',
183
+ diffHighlightAdded: '#166534',
184
+ diffHighlightRemoved: '#7f1d1d',
185
+ diffAddedBg: '#0a1f12',
186
+ diffRemovedBg: '#1f0a0a',
187
+ diffContextBg: '#0b0d12',
188
+ diffLineNumber: '#4b5563',
189
+ diffAddedLineNumberBg: '#0a1f12',
190
+ diffRemovedLineNumberBg: '#1f0a0a',
191
+ markdownText: '#e5e7eb',
192
+ markdownHeading: '#7c3aed',
193
+ markdownLink: '#3b82f6',
194
+ markdownLinkText: '#60a5fa',
195
+ markdownCode: '#22c55e',
196
+ markdownBlockQuote: '#6b7280',
197
+ markdownEmph: '#eab308',
198
+ markdownStrong: '#7c3aed',
199
+ markdownHorizontalRule: '#2a2d3a',
200
+ markdownListItem: '#7c3aed',
201
+ markdownListEnumeration: '#a855f7',
202
+ markdownImage: '#3b82f6',
203
+ markdownImageText: '#60a5fa',
204
+ markdownCodeBlock: '#11131a',
205
+ syntaxComment: '#6b7280',
206
+ syntaxKeyword: '#a855f7',
207
+ syntaxFunction: '#3b82f6',
208
+ syntaxVariable: '#e5e7eb',
209
+ syntaxString: '#22c55e',
210
+ syntaxNumber: '#eab308',
211
+ syntaxType: '#7c3aed',
212
+ syntaxOperator: '#e5e7eb',
213
+ syntaxPunctuation: '#6b7280',
214
+ thinkingOpacity: 0.6,
215
+ } as unknown as Theme
216
+
217
+ // Mirror the fleet siblings' tone chain: every tone falls through to a
218
+ // sibling token, so a sparse custom theme still renders readably.
219
+ function toneColor(theme: Theme, tone: Tone): ThemeColor {
220
+ switch (tone) {
221
+ case 'ok':
222
+ return theme.success ?? theme.accent
223
+ case 'warn':
224
+ return theme.warning ?? theme.accent
225
+ case 'err':
226
+ return theme.error ?? theme.accent
227
+ case 'muted':
228
+ return theme.textMuted ?? theme.text
229
+ case 'accent':
230
+ return theme.accent ?? theme.text
231
+ default:
232
+ return theme.text
233
+ }
234
+ }
235
+
236
+ function quotaTone(usedPct: number, appearance: AppearancePrefs): Tone {
237
+ if (usedPct < appearance.warnThreshold) return 'ok'
238
+ if (usedPct < appearance.errorThreshold) return 'warn'
239
+ return 'err'
240
+ }
241
+
242
+ interface BarSegment {
243
+ text: string
244
+ tone: Tone
245
+ }
246
+
247
+ function quotaBarSegments(
248
+ usedPct: number,
249
+ appearance: AppearancePrefs,
250
+ ): BarSegment[] {
251
+ const width = appearance.barWidth
252
+ const usedCells = Math.max(
253
+ 0,
254
+ Math.min(Math.round((usedPct / 100) * width), width),
255
+ )
256
+ const tone = quotaTone(usedPct, appearance)
257
+ return [
258
+ { text: appearance.barFilledChar.repeat(usedCells), tone },
259
+ { text: appearance.barEmptyChar.repeat(width - usedCells), tone },
260
+ ].filter((segment) => segment.text.length > 0)
261
+ }
262
+
263
+ export interface SidebarPanelProps {
264
+ /** Override the file the TUI polls. Defaults to `getSidebarStateFile()`. */
265
+ stateFile?: string
266
+ /** Override the polling interval. Defaults to 2000ms. */
267
+ pollIntervalMs?: number
268
+ /** Override the logger; tests inject a logger that captures into memory. */
269
+ logger?: TuiLogger
270
+ /** Optional override for the current epoch in milliseconds (tests). */
271
+ now?: () => number
272
+ /** Optional prefs controller — when present, drives collapse/expand and
273
+ * section toggles. Module-scoped controller is created at plugin init. */
274
+ controller?: SidebarController
275
+ /** Optional live-theme accessor. The host's `api.theme.current` is wired
276
+ * through here in production; tests pass a custom accessor to flip theme
277
+ * and assert re-render. Falls back to FALLBACK_THEME when unset. */
278
+ theme?: () => Theme
279
+ /** The slot session determines which route is relevant to this sidebar. */
280
+ sessionId?: string
281
+ }
282
+
283
+ export interface SidebarController {
284
+ prefs: () => AntigravityAuthTuiPrefs
285
+ collapsed: () => boolean
286
+ toggleCollapsed: () => void
287
+ }
288
+
289
+ interface InternalState {
290
+ loaded: SidebarStateV1
291
+ lastReadAt: number
292
+ lastError: string | null
293
+ }
294
+
295
+ const EMPTY_STATE: SidebarStateV1 = {
296
+ version: 1,
297
+ checkedAt: 0,
298
+ accounts: [],
299
+ activeRouting: {},
300
+ routingAuthoritative: false,
301
+ }
302
+
303
+ function resolveLogger(logger: TuiLogger | undefined): TuiLogger {
304
+ if (logger) return logger
305
+ try {
306
+ return createTuiFileLogger()
307
+ } catch {
308
+ // Fall back to a stub that drops everything — the sidebar must still
309
+ // render even if file logging cannot be initialized.
310
+ return noopLogger()
311
+ }
312
+ }
313
+
314
+ function noopLogger(): TuiLogger {
315
+ const drop = () => undefined
316
+ return {
317
+ debug: drop,
318
+ info: drop,
319
+ warn: drop,
320
+ error: drop,
321
+ getLogPath: () => undefined,
322
+ }
323
+ }
324
+
325
+ // Module-scoped controller singleton, initialized at plugin startup. The
326
+ // watcher is intentionally never disposed — collapse/prefs state survives
327
+ // sidebar remounts (route changes) for the lifetime of the TUI process,
328
+ // mirroring the fleet siblings.
329
+ //
330
+ // TEST ISOLATION: this singleton, like `rpcPollStarted` above, persists
331
+ // across tests via the cached ES module. Tests construct a controller
332
+ // via `createSidebarController(prefs)` and pass it through
333
+ // `SidebarPanel.props.controller` — they MUST NOT rely on this lazy
334
+ // singleton for isolation. See the block above for the full contract.
335
+ let sidebarController: SidebarController | null = null
336
+
337
+ // The TUI may unmount and remount sidebar_content when the user switches
338
+ // views. A remount re-runs the component body, so any signal created inside
339
+ // the component would reset to its seed. The controller lives in the plugin
340
+ // closure (process lifetime) and owns the durable prefs/collapse signals
341
+ // plus the single shared watcher subscription, so collapse and live pref
342
+ // reloads survive the remount.
343
+ //
344
+ // Exported so tests can construct a controller with a controlled initial
345
+ // prefs snapshot without touching the module-scoped singleton.
346
+ export function createSidebarController(
347
+ initialPrefs: AntigravityAuthTuiPrefs,
348
+ ): SidebarController {
349
+ const [prefs, setPrefs] = createSignal<AntigravityAuthTuiPrefs>(initialPrefs)
350
+ const seedCollapsed =
351
+ initialPrefs.rememberCollapsed && initialPrefs.collapsed != null
352
+ ? initialPrefs.collapsed
353
+ : initialPrefs.startCollapsed
354
+ const [collapsed, setCollapsed] = createSignal(seedCollapsed)
355
+ let lastPersistedCollapsed: boolean | null = initialPrefs.collapsed
356
+ let lastApplied = JSON.stringify(initialPrefs)
357
+
358
+ // The watcher lives for the plugin/process lifetime — it is intentionally
359
+ // never disposed. Collapse guard mirrors the race-fix in toggleCollapsed:
360
+ // lastPersistedCollapsed is advanced only once our own write lands, so
361
+ // watcher echoes of the previous persisted value are rejected by the
362
+ // `!==` check and cannot revert a user click.
363
+ watchTuiPreferences(() => {
364
+ void (async () => {
365
+ const next = resolveAntigravityAuthPrefs(await readTuiPreferencesFile())
366
+ const serialized = JSON.stringify(next)
367
+ if (serialized === lastApplied) return
368
+ lastApplied = serialized
369
+ setPrefs(next)
370
+ if (
371
+ next.rememberCollapsed &&
372
+ next.collapsed != null &&
373
+ next.collapsed !== lastPersistedCollapsed
374
+ ) {
375
+ lastPersistedCollapsed = next.collapsed
376
+ setCollapsed(next.collapsed)
377
+ }
378
+ })()
379
+ })
380
+
381
+ function toggleCollapsed() {
382
+ const next = !collapsed()
383
+ setCollapsed(next)
384
+ if (prefs().rememberCollapsed) {
385
+ void queueTuiPreferenceUpdate(PLUGIN_KEY, ['collapsed'], next).then(
386
+ () => {
387
+ lastPersistedCollapsed = next
388
+ },
389
+ )
390
+ }
391
+ }
392
+
393
+ return { prefs, collapsed, toggleCollapsed }
394
+ }
395
+
396
+ // Lazy module-scoped accessor used by the plugin entry. Tests should NOT go
397
+ // through this — they construct their own controller via createSidebarController
398
+ // and pass it via SidebarPanelProps.controller.
399
+ function getSidebarController(): SidebarController {
400
+ if (!sidebarController) {
401
+ sidebarController = createSidebarController(DEFAULT_PREFS)
402
+ }
403
+ return sidebarController
404
+ }
405
+
406
+ // --- Shared helpers (fleet shape, antigravity data) ------------------------
407
+
408
+ function clamp(value: number, min: number, max: number): number {
409
+ if (value < min) return min
410
+ if (value > max) return max
411
+ return value
412
+ }
413
+
414
+ // Render a "reset in Nm/Nh/NdNh" string from an epoch-ms reset time.
415
+ // Empty string when no resetAt is cached. The fleet's `formatResetIn`
416
+ // reads ISO strings; Antigravity persists resetAt as a numeric epoch, so
417
+ // the wrapper adapts to that without changing the shape of the output.
418
+ function formatResetIn(resetAt: number | undefined, now: () => number): string {
419
+ if (!resetAt) return ''
420
+ const ms = resetAt - now()
421
+ if (ms <= 0) return 'now'
422
+ const mins = Math.floor(ms / 60_000)
423
+ if (mins < 60) return `${mins}m`
424
+ const hrs = Math.floor(mins / 60)
425
+ if (hrs < 24) {
426
+ const rm = mins % 60
427
+ return rm > 0 ? `${hrs}h${rm}m` : `${hrs}h`
428
+ }
429
+ const days = Math.floor(hrs / 24)
430
+ const rh = hrs % 24
431
+ return rh > 0 ? `${days}d${rh}h` : `${days}d`
432
+ }
433
+
434
+ function formatError(value: unknown): string {
435
+ if (value instanceof Error) return value.message
436
+ try {
437
+ return JSON.stringify(value)
438
+ } catch {
439
+ return String(value)
440
+ }
441
+ }
442
+
443
+ // --- Fleet components (adapted to antigravity data) ------------------------
444
+
445
+ // Section header — fleet pattern: bold title, themed text color, top margin
446
+ // for vertical breathing room between sections.
447
+ function SectionHeader(props: {
448
+ theme: () => Theme
449
+ title: string
450
+ }): JSX.Element {
451
+ return (
452
+ <box width='100%' marginTop={1}>
453
+ <text fg={toneColor(props.theme(), 'text')}>
454
+ <b>{props.title}</b>
455
+ </text>
456
+ </box>
457
+ )
458
+ }
459
+
460
+ // Fleet StatRow: muted label left, value (optionally tone-tinted, bold)
461
+ // right. Mirrors the layout the Claude/Codex sidebars use for routing
462
+ // rows, plan rows, and "resets N" rows.
463
+ function StatRow(props: {
464
+ theme: () => Theme
465
+ label: string
466
+ value: string
467
+ tone?: Tone
468
+ }): JSX.Element {
469
+ return (
470
+ <box width='100%' flexDirection='row' justifyContent='space-between'>
471
+ <text fg={props.theme().textMuted}>{props.label}</text>
472
+ <text fg={toneColor(props.theme(), props.tone ?? 'text')}>
473
+ <b>{props.value}</b>
474
+ </text>
475
+ </box>
476
+ )
477
+ }
478
+
479
+ // Fleet CollapsedRow: muted label left, caller-supplied value right. Used
480
+ // for the collapsed sidebar view; the Antigravity adapter renders one
481
+ // CollapsedRow per visible account (Claude's sibling collapses to a
482
+ // single primary-quota line, but Antigravity's multi-quota model fits a
483
+ // per-account row better when the sidebar is collapsed).
484
+ function CollapsedRow(props: {
485
+ theme: () => Theme
486
+ label: string
487
+ children: JSX.Element
488
+ }): JSX.Element {
489
+ return (
490
+ <box width='100%' flexDirection='row' justifyContent='space-between'>
491
+ <text fg={props.theme().textMuted}>{props.label}</text>
492
+ {props.children}
493
+ </box>
494
+ )
495
+ }
496
+
497
+ // Fleet QuotaRow, adapted to Antigravity's `remainingPercent + resetAt`
498
+ // shape. The left group stacks label + bar + pct in fixed columns so
499
+ // bars line up across rows; the right group carries the reset countdown
500
+ // when the plugin has cached a reset time. Tone is read off the
501
+ // remaining percentage via the antigravity threshold rules — the fleet's
502
+ // `usageTone` would invert the polarity (healthy = high remaining vs
503
+ // healthy = low used), so we keep the antigravity-local `quotaTone`.
504
+ function QuotaRow(props: {
505
+ theme: () => Theme
506
+ appearance: AppearancePrefs
507
+ label: string
508
+ entry: SidebarQuotaEntry | undefined
509
+ now: () => number
510
+ }): JSX.Element {
511
+ const used = () =>
512
+ props.entry ? 100 - clamp(props.entry.remainingPercent, 0, 100) : null
513
+ const reset = () =>
514
+ props.entry ? formatResetIn(props.entry.resetAt, props.now) : ''
515
+ return (
516
+ <Show
517
+ when={used() != null}
518
+ fallback={
519
+ <box width='100%' flexDirection='row' justifyContent='space-between'>
520
+ <text fg={props.theme().textMuted}>{props.label.padEnd(3)}</text>
521
+ <text fg={props.theme().textMuted}>{'\u2014'}</text>
522
+ </box>
523
+ }
524
+ >
525
+ <box width='100%' flexDirection='row' justifyContent='space-between'>
526
+ <box flexDirection='row'>
527
+ <text width={3} flexShrink={0} fg={props.theme().textMuted}>
528
+ {props.label}
529
+ </text>
530
+ <box
531
+ width={props.appearance.barWidth}
532
+ flexShrink={0}
533
+ flexDirection='row'
534
+ >
535
+ <For each={quotaBarSegments(used() ?? 0, props.appearance)}>
536
+ {(segment) => (
537
+ <text fg={toneColor(props.theme(), segment.tone)}>
538
+ {segment.text}
539
+ </text>
540
+ )}
541
+ </For>
542
+ </box>
543
+ <text
544
+ fg={toneColor(
545
+ props.theme(),
546
+ quotaTone(used() ?? 0, props.appearance),
547
+ )}
548
+ >
549
+ {` ${String(Math.round(used() ?? 0)).padStart(3)}%`}
550
+ </text>
551
+ </box>
552
+ <Show when={reset()}>
553
+ <text fg={props.theme().textMuted}>{reset()}</text>
554
+ </Show>
555
+ </box>
556
+ </Show>
557
+ )
558
+ }
559
+
560
+ // Fleet AccountBlock, adapted to Antigravity's per-account data. Header
561
+ // row is account label (left) + status word (right). The body renders one
562
+ // QuotaRow per present quota group in the fleet's stable order, then a
563
+ // muted secondary line with the account's health score and, when
564
+ // relevant, a cooldown countdown. Status word priorities (first match
565
+ // wins):
566
+ // - `off` when the account is disabled
567
+ // - `cooling` when cooldownUntil is still in the future
568
+ // - `active` when current === true
569
+ // - `idle` for the fallback (current === false) case
570
+ function AccountBlock(props: {
571
+ theme: () => Theme
572
+ appearance: AppearancePrefs
573
+ account: SidebarAccountState
574
+ now: () => number
575
+ active?: boolean
576
+ marginTop?: number
577
+ }): JSX.Element {
578
+ const active = () => props.active ?? props.account.current
579
+ const statusWord = (): string => {
580
+ if (!props.account.enabled) return 'off'
581
+ const cd = props.account.cooldownUntil
582
+ if (typeof cd === 'number' && cd > props.now()) return 'cooling'
583
+ return active() ? 'active' : 'idle'
584
+ }
585
+ const statusTone = (): Tone => {
586
+ if (!props.account.enabled) return 'muted'
587
+ const cd = props.account.cooldownUntil
588
+ if (typeof cd === 'number' && cd > props.now()) return 'warn'
589
+ return active() ? 'ok' : 'muted'
590
+ }
591
+ const cooldownMs = (): number => {
592
+ const cd = props.account.cooldownUntil
593
+ if (typeof cd !== 'number') return 0
594
+ return Math.max(0, cd - props.now())
595
+ }
596
+ const healthText = () => {
597
+ const base = `health ${Math.round(clamp(props.account.health, 0, 100))}`
598
+ return cooldownMs() > 0
599
+ ? `${base} · cooling ${formatWait(cooldownMs())}`
600
+ : base
601
+ }
602
+ return (
603
+ <box width='100%' flexDirection='column' marginTop={props.marginTop ?? 0}>
604
+ <box width='100%' flexDirection='row' justifyContent='space-between'>
605
+ <text fg={props.theme().text}>
606
+ <b>{props.account.label}</b>
607
+ </text>
608
+ <text fg={toneColor(props.theme(), statusTone())}>
609
+ <b>{statusWord()}</b>
610
+ </text>
611
+ </box>
612
+ <For each={QUOTA_ORDER}>
613
+ {(key) => (
614
+ <QuotaRow
615
+ theme={props.theme}
616
+ appearance={props.appearance}
617
+ label={QUOTA_LABELS[key]}
618
+ entry={props.account.quota[key]}
619
+ now={props.now}
620
+ />
621
+ )}
622
+ </For>
623
+ <box width='100%' flexDirection='row'>
624
+ <text fg={props.theme().textMuted}>{` ${healthText()}`}</text>
625
+ </box>
626
+ </box>
627
+ )
628
+ }
629
+
630
+ function formatWait(ms: number): string {
631
+ const seconds = Math.ceil(ms / 1000)
632
+ if (seconds < 60) return `${seconds}s`
633
+ const minutes = Math.floor(seconds / 60)
634
+ const remaining = seconds % 60
635
+ return remaining > 0 ? `${minutes}m ${remaining}s` : `${minutes}m`
636
+ }
637
+
638
+ export function resolveQuotaDialogActiveId(
639
+ state: SidebarStateV1,
640
+ sessionId: string | undefined,
641
+ ): string | undefined {
642
+ return (
643
+ (sessionId ? state.activeRouting[sessionId]?.accountId : undefined) ??
644
+ state.accounts.find((account) => account.current)?.id
645
+ )
646
+ }
647
+
648
+ export function QuotaDialogContent(props: {
649
+ api: TuiPluginApi
650
+ controller: SidebarController
651
+ sessionId: string | undefined
652
+ }): JSX.Element {
653
+ const prefs = props.controller.prefs
654
+ const [state, setState] = createSignal<SidebarStateV1>(EMPTY_STATE)
655
+ const refresh = (): void => {
656
+ setState(readSidebarState())
657
+ }
658
+ createEffect(() => {
659
+ const timer = setInterval(refresh, prefs().pollMs)
660
+ onCleanup(() => clearInterval(timer))
661
+ })
662
+ setTimeout(refresh, 0)
663
+
664
+ const theme = (): Theme => props.api.theme.current
665
+ const visibleAccounts = () => {
666
+ if (prefs().sections.fallbackAccounts) return state().accounts
667
+ return state().accounts.filter((account) => account.current)
668
+ }
669
+ const activeId = () => resolveQuotaDialogActiveId(state(), props.sessionId)
670
+
671
+ return (
672
+ <box flexDirection='column' padding={2} width='100%' alignItems='center'>
673
+ <box flexDirection='column' width={58}>
674
+ <box width='100%' justifyContent='center' marginBottom={1}>
675
+ <text fg={theme().text}>
676
+ <b>Antigravity Quota</b>
677
+ </text>
678
+ </box>
679
+ <For each={visibleAccounts()}>
680
+ {(account, index) => (
681
+ <AccountBlock
682
+ theme={theme}
683
+ appearance={prefs().appearance}
684
+ account={account}
685
+ active={activeId() === account.id}
686
+ now={() => Date.now()}
687
+ marginTop={index() === 0 ? 0 : 1}
688
+ />
689
+ )}
690
+ </For>
691
+ </box>
692
+ </box>
693
+ )
694
+ }
695
+
696
+ // --- SidebarPanel ----------------------------------------------------------
697
+
698
+ export function SidebarPanel(props: SidebarPanelProps): JSX.Element {
699
+ const logger = resolveLogger(props.logger)
700
+ const now = props.now ?? (() => Date.now())
701
+ const pollMs = props.pollIntervalMs ?? POLL_INTERVAL_MS
702
+ const controller = props.controller ?? getSidebarController()
703
+ const collapsed = controller.collapsed
704
+ const prefs = controller.prefs
705
+ // Live host theme — falls back to a sensible dark palette when the host
706
+ // does not expose one. Solid tracks `theme()` so a theme switch re-renders
707
+ // every styled span/border without a manual subscription.
708
+ const theme = (): Theme => props.theme?.() ?? FALLBACK_THEME
709
+
710
+ const [state, setState] = createSignal<InternalState>({
711
+ loaded: EMPTY_STATE,
712
+ lastReadAt: 0,
713
+ lastError: null,
714
+ })
715
+
716
+ const refresh = (): void => {
717
+ try {
718
+ const loaded = readSidebarState(props.stateFile)
719
+ setState({
720
+ loaded,
721
+ lastReadAt: now(),
722
+ lastError: null,
723
+ })
724
+ } catch (error) {
725
+ logger.warn('sidebar-poll-failed', { error: formatError(error) })
726
+ setState((prev) => ({
727
+ ...prev,
728
+ lastReadAt: now(),
729
+ lastError: formatError(error),
730
+ }))
731
+ }
732
+ }
733
+
734
+ onMount(() => {
735
+ refresh()
736
+ const interval = setInterval(refresh, pollMs)
737
+ onCleanup(() => clearInterval(interval))
738
+ })
739
+
740
+ const hasData = () => state().loaded.accounts.length > 0
741
+ const backoffActive = () => {
742
+ const until = state().loaded.quotaBackoffUntil
743
+ return typeof until === 'number' && until > now()
744
+ }
745
+ const lastError = () => state().lastError ?? state().loaded.lastError
746
+ const degraded = () => backoffActive() || !!lastError()
747
+ // Honors sections.fallbackAccounts. Both the expanded (AccountBlock list)
748
+ // and the collapsed (CollapsedRow list) paths use the same filter so the
749
+ // user sees the same account set in either mode.
750
+ const visibleAccounts = () => {
751
+ const showFallback = prefs().sections.fallbackAccounts
752
+ if (showFallback) return state().loaded.accounts
753
+ return state().loaded.accounts.filter((account) => account.current)
754
+ }
755
+
756
+ const currentRoute = (): {
757
+ strategy?: 'sticky' | 'round-robin' | 'hybrid'
758
+ family: string
759
+ style: string
760
+ } | null => {
761
+ const routes = state().loaded.activeRouting
762
+ const entry = props.sessionId
763
+ ? routes[props.sessionId]
764
+ : Object.values(routes).sort((a, b) => b.updatedAt - a.updatedAt)[0]
765
+ if (!entry) return null
766
+ return {
767
+ strategy: entry.strategy,
768
+ family: entry.modelFamily,
769
+ style: entry.headerStyle,
770
+ }
771
+ }
772
+
773
+ // Header badge: ▼/▶ {label}. The fleet shows the version string on the
774
+ // right when no degraded state is present; the antigravity adapter keeps
775
+ // that right-alignment and surfaces `degraded` as a "LIMITED" badge
776
+ // instead of the "1/1 ready" count the previous revision rendered.
777
+ const headerLabel = () => {
778
+ const name = prefs().header.label
779
+ return !hasData() ? name : collapsed() ? `\u25b6 ${name}` : `\u25bc ${name}`
780
+ }
781
+
782
+ return (
783
+ <box
784
+ width='100%'
785
+ flexDirection='column'
786
+ border={SINGLE_BORDER}
787
+ borderColor={theme().borderActive}
788
+ paddingTop={1}
789
+ paddingBottom={1}
790
+ paddingLeft={1}
791
+ paddingRight={1}
792
+ >
793
+ {/* biome-ignore lint/a11y/noStaticElementInteractions: opentui renders to a terminal, not the DOM — ARIA roles do not apply */}
794
+ <box
795
+ width='100%'
796
+ flexDirection='row'
797
+ justifyContent='space-between'
798
+ alignItems='center'
799
+ onMouseDown={() => {
800
+ // Mirror the fleet guard: only toggle when there is data to expand
801
+ // into. Without this a click on the empty-awaiting header would just
802
+ // toggle the affordance for nothing.
803
+ if (hasData()) controller.toggleCollapsed()
804
+ }}
805
+ >
806
+ <box paddingLeft={1} paddingRight={1} backgroundColor={theme().accent}>
807
+ <text fg={theme().background}>
808
+ <b>{headerLabel()}</b>
809
+ </text>
810
+ </box>
811
+ <Show
812
+ when={degraded()}
813
+ fallback={
814
+ <Show when={prefs().header.showVersion && PLUGIN_VERSION !== ''}>
815
+ <text fg={theme().textMuted}>{`v${PLUGIN_VERSION}`}</text>
816
+ </Show>
817
+ }
818
+ >
819
+ <box
820
+ paddingLeft={1}
821
+ paddingRight={1}
822
+ backgroundColor={theme().warning}
823
+ >
824
+ <text fg={theme().background}>
825
+ <b>{'LIMITED'}</b>
826
+ </text>
827
+ </box>
828
+ </Show>
829
+ </box>
830
+
831
+ {/* Collapsed: the active account's primary quota and fleet status dot. */}
832
+ <Show when={collapsed() && hasData()}>
833
+ {(() => {
834
+ const account = () =>
835
+ visibleAccounts().find((entry) => entry.current) ??
836
+ visibleAccounts()[0]
837
+ const used = () => {
838
+ const entry = account()?.quota.claude
839
+ return entry ? 100 - clamp(entry.remainingPercent, 0, 100) : null
840
+ }
841
+ const unavailable = () => {
842
+ const selected = account()
843
+ return (
844
+ selected != null &&
845
+ (!selected.enabled ||
846
+ (selected.cooldownUntil != null &&
847
+ selected.cooldownUntil > now()))
848
+ )
849
+ }
850
+ return (
851
+ <Show when={account()}>
852
+ {(selected) => (
853
+ <CollapsedRow theme={theme} label={selected().label}>
854
+ <box flexDirection='row'>
855
+ <text
856
+ fg={toneColor(
857
+ theme(),
858
+ used() == null
859
+ ? 'muted'
860
+ : quotaTone(used() ?? 0, prefs().appearance),
861
+ )}
862
+ >
863
+ <b>
864
+ {used() == null
865
+ ? '—'
866
+ : `Cl: ${Math.round(used() ?? 0)}%`}
867
+ </b>
868
+ </text>
869
+ <text
870
+ fg={toneColor(
871
+ theme(),
872
+ unavailable()
873
+ ? 'err'
874
+ : quotaTone(used() ?? 0, prefs().appearance),
875
+ )}
876
+ >
877
+ {unavailable() ? ' ⊘' : ' ●'}
878
+ </text>
879
+ </box>
880
+ </CollapsedRow>
881
+ )}
882
+ </Show>
883
+ )
884
+ })()}
885
+ </Show>
886
+
887
+ {/* Expanded: full sections. Also render when there's no data so the
888
+ sidebar can never go blank if data clears while collapsed. */}
889
+ <Show when={!collapsed() || !hasData()}>
890
+ <Show
891
+ when={hasData()}
892
+ fallback={
893
+ <box marginTop={1} width='100%'>
894
+ <text fg={theme().textMuted}>{'Waiting for quota\u2026'}</text>
895
+ </box>
896
+ }
897
+ >
898
+ {/* Quota */}
899
+ <Show when={prefs().sections.quota}>
900
+ <SectionHeader theme={theme} title='Quota' />
901
+ <For each={visibleAccounts()}>
902
+ {(account, index) => (
903
+ <AccountBlock
904
+ theme={theme}
905
+ appearance={prefs().appearance}
906
+ account={account}
907
+ now={now}
908
+ marginTop={index() === 0 ? 0 : 1}
909
+ />
910
+ )}
911
+ </For>
912
+ </Show>
913
+
914
+ {/* Routing */}
915
+ <Show when={prefs().sections.routing}>
916
+ <SectionHeader theme={theme} title='Routing' />
917
+ <Show
918
+ when={currentRoute()}
919
+ fallback={
920
+ <StatRow theme={theme} label='Route' value='—' tone='muted' />
921
+ }
922
+ >
923
+ {(route) => (
924
+ <StatRow
925
+ theme={theme}
926
+ label='Route'
927
+ value={`${route().strategy ? `${route().strategy} · ` : ''}${route().family}: ${route().style}`}
928
+ tone='accent'
929
+ />
930
+ )}
931
+ </Show>
932
+ </Show>
933
+
934
+ {/* Health — only when something is wrong AND sections.health is true */}
935
+ <Show when={degraded() && prefs().sections.health}>
936
+ <SectionHeader theme={theme} title='Health' />
937
+ <Show when={backoffActive()}>
938
+ <StatRow
939
+ theme={theme}
940
+ label='Quota API'
941
+ value={`backoff ${formatResetIn(state().loaded.quotaBackoffUntil, now)}`}
942
+ tone='warn'
943
+ />
944
+ </Show>
945
+ <Show when={lastError()}>
946
+ <StatRow
947
+ theme={theme}
948
+ label='Last error'
949
+ value={lastError() ?? ''}
950
+ tone='err'
951
+ />
952
+ </Show>
953
+ </Show>
954
+ </Show>
955
+ </Show>
956
+ </box>
957
+ )
958
+ }
959
+
960
+ /**
961
+ * Solid slot registry binding exposed for hosts that want to mount the
962
+ * sidebar inside their renderer. Hosts that already own a slot registry can
963
+ * use `createSlot` directly; we re-export for convenience and to keep the
964
+ * contract visible at the module entry point.
965
+ */
966
+ export const sidebar_content = createSlot
967
+
968
+ interface RpcNotificationPollOptions {
969
+ pending: (
970
+ lastReceivedId: number,
971
+ sessionId?: string,
972
+ ) => Promise<RpcNotification[]>
973
+ currentSessionId: () => string | undefined
974
+ dispatch: (notification: RpcNotification) => void | Promise<void>
975
+ schedule: (poll: () => Promise<void>, intervalMs: number) => void
976
+ /**
977
+ * File logger used to surface poll errors. Must be a file logger — the
978
+ * host terminal is the frame buffer, so writes to stdout/stderr would
979
+ * corrupt the sidebar render. The plugin production path uses
980
+ * `resolveLogger(undefined)` to fall through to the on-disk file
981
+ * logger.
982
+ */
983
+ logger: TuiLogger
984
+ }
985
+
986
+ export function startRpcNotificationPolling(
987
+ options: RpcNotificationPollOptions,
988
+ ): void {
989
+ if (rpcPollStarted) return
990
+ rpcPollStarted = true
991
+ options.schedule(async () => {
992
+ if (rpcInFlight) return
993
+ rpcInFlight = true
994
+ try {
995
+ const sessionId = options.currentSessionId()
996
+ const cursorKey = sessionId ?? GLOBAL_NOTIFICATION_CURSOR
997
+ let cursor = notificationCursorBySession.get(cursorKey) ?? 0
998
+ const notifications = await options.pending(cursor, sessionId)
999
+ for (const notification of [...notifications].sort(
1000
+ (a, b) => a.id - b.id,
1001
+ )) {
1002
+ if (notification.id <= cursor) continue
1003
+ cursor = Math.max(cursor, notification.id)
1004
+ if (dispatchedNotificationIds.has(notification.id)) continue
1005
+ dispatchedNotificationIds.add(notification.id)
1006
+ if (dispatchedNotificationIds.size > 100) {
1007
+ const oldestId = dispatchedNotificationIds.values().next().value
1008
+ if (oldestId !== undefined) dispatchedNotificationIds.delete(oldestId)
1009
+ }
1010
+ await options.dispatch(notification)
1011
+ }
1012
+ if (!notificationCursorBySession.has(cursorKey)) {
1013
+ while (notificationCursorBySession.size >= MAX_NOTIFICATION_CURSORS) {
1014
+ const oldest = notificationCursorBySession.keys().next().value
1015
+ if (oldest === undefined) break
1016
+ notificationCursorBySession.delete(oldest)
1017
+ }
1018
+ }
1019
+ notificationCursorBySession.set(cursorKey, cursor)
1020
+ } catch (error) {
1021
+ // Surface the swallowed error through the file logger rather than
1022
+ // stdout/stderr (the host terminal is the frame buffer — any byte
1023
+ // written here corrupts every subsequent cell). Without this, a
1024
+ // transient RPC outage is invisible to operators. The catch stays
1025
+ // because one failed poll must never break the next — the scheduler
1026
+ // is a setInterval and a thrown error there would crash the
1027
+ // process.
1028
+ options.logger.warn('rpc-poll-failed', {
1029
+ error: error instanceof Error ? error.message : String(error),
1030
+ })
1031
+ } finally {
1032
+ rpcInFlight = false
1033
+ }
1034
+ }, RPC_POLL_MS)
1035
+ }
1036
+
1037
+ const tui: TuiPlugin = async (api) => {
1038
+ const logger = resolveLogger(undefined)
1039
+ const prefsRoot = await readTuiPreferencesFile()
1040
+ if (!sidebarController) {
1041
+ sidebarController = createSidebarController(
1042
+ resolveAntigravityAuthPrefs(prefsRoot),
1043
+ )
1044
+ }
1045
+ const rpcClient = createRpcClient(
1046
+ getRpcDir(api.state.path.directory ?? ''),
1047
+ process.pid,
1048
+ )
1049
+
1050
+ startRpcNotificationPolling({
1051
+ pending: (lastReceivedId, sessionId) =>
1052
+ rpcClient.pendingNotifications(lastReceivedId, sessionId),
1053
+ currentSessionId: () => {
1054
+ const current = (api.route as { current?: unknown }).current
1055
+ const resolved =
1056
+ typeof current === 'function' ? (current as () => unknown)() : current
1057
+ return (resolved as { params?: { sessionID?: string } } | undefined)
1058
+ ?.params?.sessionID
1059
+ },
1060
+ dispatch: async (notification) => {
1061
+ logger.debug('rpc-notification-received', {
1062
+ command: notification.payload.command,
1063
+ id: notification.id,
1064
+ sessionId: notification.sessionId,
1065
+ })
1066
+ // Call the imperative dispatcher directly — the prior
1067
+ // two-phase `collectDialogFlow` + `renderDialogFlow` is gone.
1068
+ // The dispatcher awaits `apply`, toasts the result, then clears
1069
+ // (or replaces for multi-step flows). The RPC `apply` accepts the
1070
+ // optional `timeoutMs` knob so account add / refresh can opt into
1071
+ // the 120s RPC timeout without the dialog layer having to know
1072
+ // about it.
1073
+ if (notification.payload.command === 'antigravity-quota') {
1074
+ api.ui.dialog.setSize('xlarge')
1075
+ api.ui.dialog.replace(() => (
1076
+ <QuotaDialogContent
1077
+ api={api}
1078
+ controller={getSidebarController()}
1079
+ sessionId={notification.sessionId}
1080
+ />
1081
+ ))
1082
+ return
1083
+ }
1084
+ openCommandDialog(api, notification.payload, (command, args, options) =>
1085
+ rpcClient.apply(
1086
+ { command, arguments: args, sessionId: notification.sessionId },
1087
+ options,
1088
+ ),
1089
+ )
1090
+ },
1091
+ schedule: (poll, intervalMs) => {
1092
+ setInterval(() => void poll(), intervalMs)
1093
+ },
1094
+ logger,
1095
+ })
1096
+
1097
+ // The host supplies the live theme via `api.theme.current` — the slot
1098
+ // callback's closure captures `api` so the accessor always reads the
1099
+ // current theme. A Solid re-render follows whenever the user switches.
1100
+ const liveTheme = (): TuiThemeCurrent => api.theme.current
1101
+
1102
+ api.slots.register({
1103
+ order: computeEffectiveOrder(prefsRoot, PLUGIN_KEY, DEFAULT_SLOT_ORDER),
1104
+ slots: {
1105
+ sidebar_content: (_context, { session_id: sessionId }) => (
1106
+ <SidebarPanel logger={logger} theme={liveTheme} sessionId={sessionId} />
1107
+ ),
1108
+ },
1109
+ })
1110
+ }
1111
+
1112
+ const plugin: TuiPluginModule & { id: string } = {
1113
+ id: ID,
1114
+ tui,
1115
+ }
1116
+
1117
+ export default plugin