@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
@@ -0,0 +1,662 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@opentui/solid/jsx-runtime";
2
+ /** @jsxImportSource @opentui/solid */
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
+ import { readFileSync } from 'node:fs';
38
+ import { dirname, join } from 'node:path';
39
+ import { fileURLToPath } from 'node:url';
40
+ import { createSlot } from '@opentui/solid';
41
+ import { createEffect, createSignal, For, onCleanup, onMount, Show, } from 'solid-js';
42
+ import { createRpcClient } from './rpc/rpc-client';
43
+ import { getRpcDir } from './rpc/rpc-dir';
44
+ import { readSidebarState, } from './sidebar-state';
45
+ import { openCommandDialog } from './tui/command-dialogs';
46
+ import { createTuiFileLogger } from './tui/file-logger';
47
+ import { computeEffectiveOrder, DEFAULT_PREFS, DEFAULT_SLOT_ORDER, PLUGIN_KEY, queueTuiPreferenceUpdate, readTuiPreferencesFile, resolveAntigravityAuthPrefs, watchTuiPreferences, } from './tui-preferences';
48
+ const ID = 'cortexkit.antigravity-auth';
49
+ const POLL_INTERVAL_MS = 2000;
50
+ const RPC_POLL_MS = 500;
51
+ const SINGLE_BORDER = { type: 'single' };
52
+ // Read package metadata from either the raw src/ entry or its generated
53
+ // src/tui-compiled/ counterpart. Avoid a JSON import because package.json sits
54
+ // outside the declaration build's rootDir.
55
+ const PLUGIN_VERSION = (() => {
56
+ const here = dirname(fileURLToPath(import.meta.url));
57
+ for (const packageFile of [
58
+ join(here, '..', 'package.json'),
59
+ join(here, '..', '..', 'package.json'),
60
+ ]) {
61
+ try {
62
+ const raw = readFileSync(packageFile, 'utf8');
63
+ const version = JSON.parse(raw).version;
64
+ if (version)
65
+ return version;
66
+ }
67
+ catch {
68
+ // Try the path for the other TUI entry layout.
69
+ }
70
+ }
71
+ return '';
72
+ })();
73
+ // Module-scoped state — TEST ISOLATION CONTRACT:
74
+ //
75
+ // `rpcPollStarted`, notification cursor/deduplication state, `rpcInFlight`, and the lazy
76
+ // `sidebarController` below persist across tests via the cached ES
77
+ // module Bun loads once per `--isolate` file. Tests must NOT assert
78
+ // fresh-process behaviour from these variables — by the time the first
79
+ // `startRpcNotificationPolling` runs, all four carry stale values from
80
+ // prior tests in the same file. Test isolation comes from:
81
+ // 1. fresh-importing `tui.tsx` via a cache-busted dynamic `import`
82
+ // so the module re-evaluates with fresh module-scoped bindings, and
83
+ // 2. constructing a fresh `SidebarController` via
84
+ // `createSidebarController(prefs)` and passing it through
85
+ // `SidebarPanel.props.controller` — never through
86
+ // `getSidebarController()`, which lazily seeds the module-scoped
87
+ // singleton.
88
+ let rpcPollStarted = false;
89
+ const notificationCursorBySession = new Map();
90
+ const dispatchedNotificationIds = new Set();
91
+ let rpcInFlight = false;
92
+ const GLOBAL_NOTIFICATION_CURSOR = '__global__';
93
+ const MAX_NOTIFICATION_CURSORS = 256;
94
+ const QUOTA_LABELS = {
95
+ claude: 'Cl',
96
+ 'gemini-pro': 'GP',
97
+ 'gemini-flash': 'GF',
98
+ 'gpt-oss': 'GPT',
99
+ };
100
+ const QUOTA_ORDER = [
101
+ 'claude',
102
+ 'gemini-pro',
103
+ 'gemini-flash',
104
+ 'gpt-oss',
105
+ ];
106
+ const FALLBACK_THEME = {
107
+ primary: '#3b82f6',
108
+ secondary: '#a855f7',
109
+ accent: '#7c3aed',
110
+ error: '#ef4444',
111
+ warning: '#eab308',
112
+ success: '#22c55e',
113
+ info: '#0ea5e9',
114
+ text: '#e5e7eb',
115
+ textMuted: '#6b7280',
116
+ selectedListItemText: '#ffffff',
117
+ background: '#0b0d12',
118
+ backgroundPanel: '#11131a',
119
+ backgroundElement: '#1a1d27',
120
+ backgroundMenu: '#1a1d27',
121
+ border: '#2a2d3a',
122
+ borderActive: '#7c3aed',
123
+ borderSubtle: '#2a2d3a',
124
+ diffAdded: '#22c55e',
125
+ diffRemoved: '#ef4444',
126
+ diffContext: '#6b7280',
127
+ diffHunkHeader: '#7c3aed',
128
+ diffHighlightAdded: '#166534',
129
+ diffHighlightRemoved: '#7f1d1d',
130
+ diffAddedBg: '#0a1f12',
131
+ diffRemovedBg: '#1f0a0a',
132
+ diffContextBg: '#0b0d12',
133
+ diffLineNumber: '#4b5563',
134
+ diffAddedLineNumberBg: '#0a1f12',
135
+ diffRemovedLineNumberBg: '#1f0a0a',
136
+ markdownText: '#e5e7eb',
137
+ markdownHeading: '#7c3aed',
138
+ markdownLink: '#3b82f6',
139
+ markdownLinkText: '#60a5fa',
140
+ markdownCode: '#22c55e',
141
+ markdownBlockQuote: '#6b7280',
142
+ markdownEmph: '#eab308',
143
+ markdownStrong: '#7c3aed',
144
+ markdownHorizontalRule: '#2a2d3a',
145
+ markdownListItem: '#7c3aed',
146
+ markdownListEnumeration: '#a855f7',
147
+ markdownImage: '#3b82f6',
148
+ markdownImageText: '#60a5fa',
149
+ markdownCodeBlock: '#11131a',
150
+ syntaxComment: '#6b7280',
151
+ syntaxKeyword: '#a855f7',
152
+ syntaxFunction: '#3b82f6',
153
+ syntaxVariable: '#e5e7eb',
154
+ syntaxString: '#22c55e',
155
+ syntaxNumber: '#eab308',
156
+ syntaxType: '#7c3aed',
157
+ syntaxOperator: '#e5e7eb',
158
+ syntaxPunctuation: '#6b7280',
159
+ thinkingOpacity: 0.6,
160
+ };
161
+ // Mirror the fleet siblings' tone chain: every tone falls through to a
162
+ // sibling token, so a sparse custom theme still renders readably.
163
+ function toneColor(theme, tone) {
164
+ switch (tone) {
165
+ case 'ok':
166
+ return theme.success ?? theme.accent;
167
+ case 'warn':
168
+ return theme.warning ?? theme.accent;
169
+ case 'err':
170
+ return theme.error ?? theme.accent;
171
+ case 'muted':
172
+ return theme.textMuted ?? theme.text;
173
+ case 'accent':
174
+ return theme.accent ?? theme.text;
175
+ default:
176
+ return theme.text;
177
+ }
178
+ }
179
+ function quotaTone(usedPct, appearance) {
180
+ if (usedPct < appearance.warnThreshold)
181
+ return 'ok';
182
+ if (usedPct < appearance.errorThreshold)
183
+ return 'warn';
184
+ return 'err';
185
+ }
186
+ function quotaBarSegments(usedPct, appearance) {
187
+ const width = appearance.barWidth;
188
+ const usedCells = Math.max(0, Math.min(Math.round((usedPct / 100) * width), width));
189
+ const tone = quotaTone(usedPct, appearance);
190
+ return [
191
+ { text: appearance.barFilledChar.repeat(usedCells), tone },
192
+ { text: appearance.barEmptyChar.repeat(width - usedCells), tone },
193
+ ].filter((segment) => segment.text.length > 0);
194
+ }
195
+ const EMPTY_STATE = {
196
+ version: 1,
197
+ checkedAt: 0,
198
+ accounts: [],
199
+ activeRouting: {},
200
+ routingAuthoritative: false,
201
+ };
202
+ function resolveLogger(logger) {
203
+ if (logger)
204
+ return logger;
205
+ try {
206
+ return createTuiFileLogger();
207
+ }
208
+ catch {
209
+ // Fall back to a stub that drops everything — the sidebar must still
210
+ // render even if file logging cannot be initialized.
211
+ return noopLogger();
212
+ }
213
+ }
214
+ function noopLogger() {
215
+ const drop = () => undefined;
216
+ return {
217
+ debug: drop,
218
+ info: drop,
219
+ warn: drop,
220
+ error: drop,
221
+ getLogPath: () => undefined,
222
+ };
223
+ }
224
+ // Module-scoped controller singleton, initialized at plugin startup. The
225
+ // watcher is intentionally never disposed — collapse/prefs state survives
226
+ // sidebar remounts (route changes) for the lifetime of the TUI process,
227
+ // mirroring the fleet siblings.
228
+ //
229
+ // TEST ISOLATION: this singleton, like `rpcPollStarted` above, persists
230
+ // across tests via the cached ES module. Tests construct a controller
231
+ // via `createSidebarController(prefs)` and pass it through
232
+ // `SidebarPanel.props.controller` — they MUST NOT rely on this lazy
233
+ // singleton for isolation. See the block above for the full contract.
234
+ let sidebarController = null;
235
+ // The TUI may unmount and remount sidebar_content when the user switches
236
+ // views. A remount re-runs the component body, so any signal created inside
237
+ // the component would reset to its seed. The controller lives in the plugin
238
+ // closure (process lifetime) and owns the durable prefs/collapse signals
239
+ // plus the single shared watcher subscription, so collapse and live pref
240
+ // reloads survive the remount.
241
+ //
242
+ // Exported so tests can construct a controller with a controlled initial
243
+ // prefs snapshot without touching the module-scoped singleton.
244
+ export function createSidebarController(initialPrefs) {
245
+ const [prefs, setPrefs] = createSignal(initialPrefs);
246
+ const seedCollapsed = initialPrefs.rememberCollapsed && initialPrefs.collapsed != null
247
+ ? initialPrefs.collapsed
248
+ : initialPrefs.startCollapsed;
249
+ const [collapsed, setCollapsed] = createSignal(seedCollapsed);
250
+ let lastPersistedCollapsed = initialPrefs.collapsed;
251
+ let lastApplied = JSON.stringify(initialPrefs);
252
+ // The watcher lives for the plugin/process lifetime — it is intentionally
253
+ // never disposed. Collapse guard mirrors the race-fix in toggleCollapsed:
254
+ // lastPersistedCollapsed is advanced only once our own write lands, so
255
+ // watcher echoes of the previous persisted value are rejected by the
256
+ // `!==` check and cannot revert a user click.
257
+ watchTuiPreferences(() => {
258
+ void (async () => {
259
+ const next = resolveAntigravityAuthPrefs(await readTuiPreferencesFile());
260
+ const serialized = JSON.stringify(next);
261
+ if (serialized === lastApplied)
262
+ return;
263
+ lastApplied = serialized;
264
+ setPrefs(next);
265
+ if (next.rememberCollapsed &&
266
+ next.collapsed != null &&
267
+ next.collapsed !== lastPersistedCollapsed) {
268
+ lastPersistedCollapsed = next.collapsed;
269
+ setCollapsed(next.collapsed);
270
+ }
271
+ })();
272
+ });
273
+ function toggleCollapsed() {
274
+ const next = !collapsed();
275
+ setCollapsed(next);
276
+ if (prefs().rememberCollapsed) {
277
+ void queueTuiPreferenceUpdate(PLUGIN_KEY, ['collapsed'], next).then(() => {
278
+ lastPersistedCollapsed = next;
279
+ });
280
+ }
281
+ }
282
+ return { prefs, collapsed, toggleCollapsed };
283
+ }
284
+ // Lazy module-scoped accessor used by the plugin entry. Tests should NOT go
285
+ // through this — they construct their own controller via createSidebarController
286
+ // and pass it via SidebarPanelProps.controller.
287
+ function getSidebarController() {
288
+ if (!sidebarController) {
289
+ sidebarController = createSidebarController(DEFAULT_PREFS);
290
+ }
291
+ return sidebarController;
292
+ }
293
+ // --- Shared helpers (fleet shape, antigravity data) ------------------------
294
+ function clamp(value, min, max) {
295
+ if (value < min)
296
+ return min;
297
+ if (value > max)
298
+ return max;
299
+ return value;
300
+ }
301
+ // Render a "reset in Nm/Nh/NdNh" string from an epoch-ms reset time.
302
+ // Empty string when no resetAt is cached. The fleet's `formatResetIn`
303
+ // reads ISO strings; Antigravity persists resetAt as a numeric epoch, so
304
+ // the wrapper adapts to that without changing the shape of the output.
305
+ function formatResetIn(resetAt, now) {
306
+ if (!resetAt)
307
+ return '';
308
+ const ms = resetAt - now();
309
+ if (ms <= 0)
310
+ return 'now';
311
+ const mins = Math.floor(ms / 60_000);
312
+ if (mins < 60)
313
+ return `${mins}m`;
314
+ const hrs = Math.floor(mins / 60);
315
+ if (hrs < 24) {
316
+ const rm = mins % 60;
317
+ return rm > 0 ? `${hrs}h${rm}m` : `${hrs}h`;
318
+ }
319
+ const days = Math.floor(hrs / 24);
320
+ const rh = hrs % 24;
321
+ return rh > 0 ? `${days}d${rh}h` : `${days}d`;
322
+ }
323
+ function formatError(value) {
324
+ if (value instanceof Error)
325
+ return value.message;
326
+ try {
327
+ return JSON.stringify(value);
328
+ }
329
+ catch {
330
+ return String(value);
331
+ }
332
+ }
333
+ // --- Fleet components (adapted to antigravity data) ------------------------
334
+ // Section header — fleet pattern: bold title, themed text color, top margin
335
+ // for vertical breathing room between sections.
336
+ function SectionHeader(props) {
337
+ return (_jsx("box", { width: '100%', marginTop: 1, children: _jsx("text", { fg: toneColor(props.theme(), 'text'), children: _jsx("b", { children: props.title }) }) }));
338
+ }
339
+ // Fleet StatRow: muted label left, value (optionally tone-tinted, bold)
340
+ // right. Mirrors the layout the Claude/Codex sidebars use for routing
341
+ // rows, plan rows, and "resets N" rows.
342
+ function StatRow(props) {
343
+ return (_jsxs("box", { width: '100%', flexDirection: 'row', justifyContent: 'space-between', children: [_jsx("text", { fg: props.theme().textMuted, children: props.label }), _jsx("text", { fg: toneColor(props.theme(), props.tone ?? 'text'), children: _jsx("b", { children: props.value }) })] }));
344
+ }
345
+ // Fleet CollapsedRow: muted label left, caller-supplied value right. Used
346
+ // for the collapsed sidebar view; the Antigravity adapter renders one
347
+ // CollapsedRow per visible account (Claude's sibling collapses to a
348
+ // single primary-quota line, but Antigravity's multi-quota model fits a
349
+ // per-account row better when the sidebar is collapsed).
350
+ function CollapsedRow(props) {
351
+ return (_jsxs("box", { width: '100%', flexDirection: 'row', justifyContent: 'space-between', children: [_jsx("text", { fg: props.theme().textMuted, children: props.label }), props.children] }));
352
+ }
353
+ // Fleet QuotaRow, adapted to Antigravity's `remainingPercent + resetAt`
354
+ // shape. The left group stacks label + bar + pct in fixed columns so
355
+ // bars line up across rows; the right group carries the reset countdown
356
+ // when the plugin has cached a reset time. Tone is read off the
357
+ // remaining percentage via the antigravity threshold rules — the fleet's
358
+ // `usageTone` would invert the polarity (healthy = high remaining vs
359
+ // healthy = low used), so we keep the antigravity-local `quotaTone`.
360
+ function QuotaRow(props) {
361
+ const used = () => props.entry ? 100 - clamp(props.entry.remainingPercent, 0, 100) : null;
362
+ const reset = () => props.entry ? formatResetIn(props.entry.resetAt, props.now) : '';
363
+ return (_jsx(Show, { when: used() != null, fallback: _jsxs("box", { width: '100%', flexDirection: 'row', justifyContent: 'space-between', children: [_jsx("text", { fg: props.theme().textMuted, children: props.label.padEnd(3) }), _jsx("text", { fg: props.theme().textMuted, children: '\u2014' })] }), children: _jsxs("box", { width: '100%', flexDirection: 'row', justifyContent: 'space-between', children: [_jsxs("box", { flexDirection: 'row', children: [_jsx("text", { width: 3, flexShrink: 0, fg: props.theme().textMuted, children: props.label }), _jsx("box", { width: props.appearance.barWidth, flexShrink: 0, flexDirection: 'row', children: _jsx(For, { each: quotaBarSegments(used() ?? 0, props.appearance), children: (segment) => (_jsx("text", { fg: toneColor(props.theme(), segment.tone), children: segment.text })) }) }), _jsx("text", { fg: toneColor(props.theme(), quotaTone(used() ?? 0, props.appearance)), children: ` ${String(Math.round(used() ?? 0)).padStart(3)}%` })] }), _jsx(Show, { when: reset(), children: _jsx("text", { fg: props.theme().textMuted, children: reset() }) })] }) }));
364
+ }
365
+ // Fleet AccountBlock, adapted to Antigravity's per-account data. Header
366
+ // row is account label (left) + status word (right). The body renders one
367
+ // QuotaRow per present quota group in the fleet's stable order, then a
368
+ // muted secondary line with the account's health score and, when
369
+ // relevant, a cooldown countdown. Status word priorities (first match
370
+ // wins):
371
+ // - `off` when the account is disabled
372
+ // - `cooling` when cooldownUntil is still in the future
373
+ // - `active` when current === true
374
+ // - `idle` for the fallback (current === false) case
375
+ function AccountBlock(props) {
376
+ const active = () => props.active ?? props.account.current;
377
+ const statusWord = () => {
378
+ if (!props.account.enabled)
379
+ return 'off';
380
+ const cd = props.account.cooldownUntil;
381
+ if (typeof cd === 'number' && cd > props.now())
382
+ return 'cooling';
383
+ return active() ? 'active' : 'idle';
384
+ };
385
+ const statusTone = () => {
386
+ if (!props.account.enabled)
387
+ return 'muted';
388
+ const cd = props.account.cooldownUntil;
389
+ if (typeof cd === 'number' && cd > props.now())
390
+ return 'warn';
391
+ return active() ? 'ok' : 'muted';
392
+ };
393
+ const cooldownMs = () => {
394
+ const cd = props.account.cooldownUntil;
395
+ if (typeof cd !== 'number')
396
+ return 0;
397
+ return Math.max(0, cd - props.now());
398
+ };
399
+ const healthText = () => {
400
+ const base = `health ${Math.round(clamp(props.account.health, 0, 100))}`;
401
+ return cooldownMs() > 0
402
+ ? `${base} · cooling ${formatWait(cooldownMs())}`
403
+ : base;
404
+ };
405
+ return (_jsxs("box", { width: '100%', flexDirection: 'column', marginTop: props.marginTop ?? 0, children: [_jsxs("box", { width: '100%', flexDirection: 'row', justifyContent: 'space-between', children: [_jsx("text", { fg: props.theme().text, children: _jsx("b", { children: props.account.label }) }), _jsx("text", { fg: toneColor(props.theme(), statusTone()), children: _jsx("b", { children: statusWord() }) })] }), _jsx(For, { each: QUOTA_ORDER, children: (key) => (_jsx(QuotaRow, { theme: props.theme, appearance: props.appearance, label: QUOTA_LABELS[key], entry: props.account.quota[key], now: props.now })) }), _jsx("box", { width: '100%', flexDirection: 'row', children: _jsx("text", { fg: props.theme().textMuted, children: ` ${healthText()}` }) })] }));
406
+ }
407
+ function formatWait(ms) {
408
+ const seconds = Math.ceil(ms / 1000);
409
+ if (seconds < 60)
410
+ return `${seconds}s`;
411
+ const minutes = Math.floor(seconds / 60);
412
+ const remaining = seconds % 60;
413
+ return remaining > 0 ? `${minutes}m ${remaining}s` : `${minutes}m`;
414
+ }
415
+ export function resolveQuotaDialogActiveId(state, sessionId) {
416
+ return ((sessionId ? state.activeRouting[sessionId]?.accountId : undefined) ??
417
+ state.accounts.find((account) => account.current)?.id);
418
+ }
419
+ export function QuotaDialogContent(props) {
420
+ const prefs = props.controller.prefs;
421
+ const [state, setState] = createSignal(EMPTY_STATE);
422
+ const refresh = () => {
423
+ setState(readSidebarState());
424
+ };
425
+ createEffect(() => {
426
+ const timer = setInterval(refresh, prefs().pollMs);
427
+ onCleanup(() => clearInterval(timer));
428
+ });
429
+ setTimeout(refresh, 0);
430
+ const theme = () => props.api.theme.current;
431
+ const visibleAccounts = () => {
432
+ if (prefs().sections.fallbackAccounts)
433
+ return state().accounts;
434
+ return state().accounts.filter((account) => account.current);
435
+ };
436
+ const activeId = () => resolveQuotaDialogActiveId(state(), props.sessionId);
437
+ return (_jsx("box", { flexDirection: 'column', padding: 2, width: '100%', alignItems: 'center', children: _jsxs("box", { flexDirection: 'column', width: 58, children: [_jsx("box", { width: '100%', justifyContent: 'center', marginBottom: 1, children: _jsx("text", { fg: theme().text, children: _jsx("b", { children: "Antigravity Quota" }) }) }), _jsx(For, { each: visibleAccounts(), children: (account, index) => (_jsx(AccountBlock, { theme: theme, appearance: prefs().appearance, account: account, active: activeId() === account.id, now: () => Date.now(), marginTop: index() === 0 ? 0 : 1 })) })] }) }));
438
+ }
439
+ // --- SidebarPanel ----------------------------------------------------------
440
+ export function SidebarPanel(props) {
441
+ const logger = resolveLogger(props.logger);
442
+ const now = props.now ?? (() => Date.now());
443
+ const pollMs = props.pollIntervalMs ?? POLL_INTERVAL_MS;
444
+ const controller = props.controller ?? getSidebarController();
445
+ const collapsed = controller.collapsed;
446
+ const prefs = controller.prefs;
447
+ // Live host theme — falls back to a sensible dark palette when the host
448
+ // does not expose one. Solid tracks `theme()` so a theme switch re-renders
449
+ // every styled span/border without a manual subscription.
450
+ const theme = () => props.theme?.() ?? FALLBACK_THEME;
451
+ const [state, setState] = createSignal({
452
+ loaded: EMPTY_STATE,
453
+ lastReadAt: 0,
454
+ lastError: null,
455
+ });
456
+ const refresh = () => {
457
+ try {
458
+ const loaded = readSidebarState(props.stateFile);
459
+ setState({
460
+ loaded,
461
+ lastReadAt: now(),
462
+ lastError: null,
463
+ });
464
+ }
465
+ catch (error) {
466
+ logger.warn('sidebar-poll-failed', { error: formatError(error) });
467
+ setState((prev) => ({
468
+ ...prev,
469
+ lastReadAt: now(),
470
+ lastError: formatError(error),
471
+ }));
472
+ }
473
+ };
474
+ onMount(() => {
475
+ refresh();
476
+ const interval = setInterval(refresh, pollMs);
477
+ onCleanup(() => clearInterval(interval));
478
+ });
479
+ const hasData = () => state().loaded.accounts.length > 0;
480
+ const backoffActive = () => {
481
+ const until = state().loaded.quotaBackoffUntil;
482
+ return typeof until === 'number' && until > now();
483
+ };
484
+ const lastError = () => state().lastError ?? state().loaded.lastError;
485
+ const degraded = () => backoffActive() || !!lastError();
486
+ // Honors sections.fallbackAccounts. Both the expanded (AccountBlock list)
487
+ // and the collapsed (CollapsedRow list) paths use the same filter so the
488
+ // user sees the same account set in either mode.
489
+ const visibleAccounts = () => {
490
+ const showFallback = prefs().sections.fallbackAccounts;
491
+ if (showFallback)
492
+ return state().loaded.accounts;
493
+ return state().loaded.accounts.filter((account) => account.current);
494
+ };
495
+ const currentRoute = () => {
496
+ const routes = state().loaded.activeRouting;
497
+ const entry = props.sessionId
498
+ ? routes[props.sessionId]
499
+ : Object.values(routes).sort((a, b) => b.updatedAt - a.updatedAt)[0];
500
+ if (!entry)
501
+ return null;
502
+ return {
503
+ strategy: entry.strategy,
504
+ family: entry.modelFamily,
505
+ style: entry.headerStyle,
506
+ };
507
+ };
508
+ // Header badge: ▼/▶ {label}. The fleet shows the version string on the
509
+ // right when no degraded state is present; the antigravity adapter keeps
510
+ // that right-alignment and surfaces `degraded` as a "LIMITED" badge
511
+ // instead of the "1/1 ready" count the previous revision rendered.
512
+ const headerLabel = () => {
513
+ const name = prefs().header.label;
514
+ return !hasData() ? name : collapsed() ? `\u25b6 ${name}` : `\u25bc ${name}`;
515
+ };
516
+ return (_jsxs("box", { width: '100%', flexDirection: 'column', border: SINGLE_BORDER, borderColor: theme().borderActive, paddingTop: 1, paddingBottom: 1, paddingLeft: 1, paddingRight: 1, children: [_jsxs("box", { width: '100%', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', onMouseDown: () => {
517
+ // Mirror the fleet guard: only toggle when there is data to expand
518
+ // into. Without this a click on the empty-awaiting header would just
519
+ // toggle the affordance for nothing.
520
+ if (hasData())
521
+ controller.toggleCollapsed();
522
+ }, children: [_jsx("box", { paddingLeft: 1, paddingRight: 1, backgroundColor: theme().accent, children: _jsx("text", { fg: theme().background, children: _jsx("b", { children: headerLabel() }) }) }), _jsx(Show, { when: degraded(), fallback: _jsx(Show, { when: prefs().header.showVersion && PLUGIN_VERSION !== '', children: _jsx("text", { fg: theme().textMuted, children: `v${PLUGIN_VERSION}` }) }), children: _jsx("box", { paddingLeft: 1, paddingRight: 1, backgroundColor: theme().warning, children: _jsx("text", { fg: theme().background, children: _jsx("b", { children: 'LIMITED' }) }) }) })] }), _jsx(Show, { when: collapsed() && hasData(), children: (() => {
523
+ const account = () => visibleAccounts().find((entry) => entry.current) ??
524
+ visibleAccounts()[0];
525
+ const used = () => {
526
+ const entry = account()?.quota.claude;
527
+ return entry ? 100 - clamp(entry.remainingPercent, 0, 100) : null;
528
+ };
529
+ const unavailable = () => {
530
+ const selected = account();
531
+ return (selected != null &&
532
+ (!selected.enabled ||
533
+ (selected.cooldownUntil != null &&
534
+ selected.cooldownUntil > now())));
535
+ };
536
+ return (_jsx(Show, { when: account(), children: (selected) => (_jsx(CollapsedRow, { theme: theme, label: selected().label, children: _jsxs("box", { flexDirection: 'row', children: [_jsx("text", { fg: toneColor(theme(), used() == null
537
+ ? 'muted'
538
+ : quotaTone(used() ?? 0, prefs().appearance)), children: _jsx("b", { children: used() == null
539
+ ? '—'
540
+ : `Cl: ${Math.round(used() ?? 0)}%` }) }), _jsx("text", { fg: toneColor(theme(), unavailable()
541
+ ? 'err'
542
+ : quotaTone(used() ?? 0, prefs().appearance)), children: unavailable() ? ' ⊘' : ' ●' })] }) })) }));
543
+ })() }), _jsx(Show, { when: !collapsed() || !hasData(), children: _jsxs(Show, { when: hasData(), fallback: _jsx("box", { marginTop: 1, width: '100%', children: _jsx("text", { fg: theme().textMuted, children: 'Waiting for quota\u2026' }) }), children: [_jsxs(Show, { when: prefs().sections.quota, children: [_jsx(SectionHeader, { theme: theme, title: 'Quota' }), _jsx(For, { each: visibleAccounts(), children: (account, index) => (_jsx(AccountBlock, { theme: theme, appearance: prefs().appearance, account: account, now: now, marginTop: index() === 0 ? 0 : 1 })) })] }), _jsxs(Show, { when: prefs().sections.routing, children: [_jsx(SectionHeader, { theme: theme, title: 'Routing' }), _jsx(Show, { when: currentRoute(), fallback: _jsx(StatRow, { theme: theme, label: 'Route', value: '\u2014', tone: 'muted' }), children: (route) => (_jsx(StatRow, { theme: theme, label: 'Route', value: `${route().strategy ? `${route().strategy} · ` : ''}${route().family}: ${route().style}`, tone: 'accent' })) })] }), _jsxs(Show, { when: degraded() && prefs().sections.health, children: [_jsx(SectionHeader, { theme: theme, title: 'Health' }), _jsx(Show, { when: backoffActive(), children: _jsx(StatRow, { theme: theme, label: 'Quota API', value: `backoff ${formatResetIn(state().loaded.quotaBackoffUntil, now)}`, tone: 'warn' }) }), _jsx(Show, { when: lastError(), children: _jsx(StatRow, { theme: theme, label: 'Last error', value: lastError() ?? '', tone: 'err' }) })] })] }) })] }));
544
+ }
545
+ /**
546
+ * Solid slot registry binding exposed for hosts that want to mount the
547
+ * sidebar inside their renderer. Hosts that already own a slot registry can
548
+ * use `createSlot` directly; we re-export for convenience and to keep the
549
+ * contract visible at the module entry point.
550
+ */
551
+ export const sidebar_content = createSlot;
552
+ export function startRpcNotificationPolling(options) {
553
+ if (rpcPollStarted)
554
+ return;
555
+ rpcPollStarted = true;
556
+ options.schedule(async () => {
557
+ if (rpcInFlight)
558
+ return;
559
+ rpcInFlight = true;
560
+ try {
561
+ const sessionId = options.currentSessionId();
562
+ const cursorKey = sessionId ?? GLOBAL_NOTIFICATION_CURSOR;
563
+ let cursor = notificationCursorBySession.get(cursorKey) ?? 0;
564
+ const notifications = await options.pending(cursor, sessionId);
565
+ for (const notification of [...notifications].sort((a, b) => a.id - b.id)) {
566
+ if (notification.id <= cursor)
567
+ continue;
568
+ cursor = Math.max(cursor, notification.id);
569
+ if (dispatchedNotificationIds.has(notification.id))
570
+ continue;
571
+ dispatchedNotificationIds.add(notification.id);
572
+ if (dispatchedNotificationIds.size > 100) {
573
+ const oldestId = dispatchedNotificationIds.values().next().value;
574
+ if (oldestId !== undefined)
575
+ dispatchedNotificationIds.delete(oldestId);
576
+ }
577
+ await options.dispatch(notification);
578
+ }
579
+ if (!notificationCursorBySession.has(cursorKey)) {
580
+ while (notificationCursorBySession.size >= MAX_NOTIFICATION_CURSORS) {
581
+ const oldest = notificationCursorBySession.keys().next().value;
582
+ if (oldest === undefined)
583
+ break;
584
+ notificationCursorBySession.delete(oldest);
585
+ }
586
+ }
587
+ notificationCursorBySession.set(cursorKey, cursor);
588
+ }
589
+ catch (error) {
590
+ // Surface the swallowed error through the file logger rather than
591
+ // stdout/stderr (the host terminal is the frame buffer — any byte
592
+ // written here corrupts every subsequent cell). Without this, a
593
+ // transient RPC outage is invisible to operators. The catch stays
594
+ // because one failed poll must never break the next — the scheduler
595
+ // is a setInterval and a thrown error there would crash the
596
+ // process.
597
+ options.logger.warn('rpc-poll-failed', {
598
+ error: error instanceof Error ? error.message : String(error),
599
+ });
600
+ }
601
+ finally {
602
+ rpcInFlight = false;
603
+ }
604
+ }, RPC_POLL_MS);
605
+ }
606
+ const tui = async (api) => {
607
+ const logger = resolveLogger(undefined);
608
+ const prefsRoot = await readTuiPreferencesFile();
609
+ if (!sidebarController) {
610
+ sidebarController = createSidebarController(resolveAntigravityAuthPrefs(prefsRoot));
611
+ }
612
+ const rpcClient = createRpcClient(getRpcDir(api.state.path.directory ?? ''), process.pid);
613
+ startRpcNotificationPolling({
614
+ pending: (lastReceivedId, sessionId) => rpcClient.pendingNotifications(lastReceivedId, sessionId),
615
+ currentSessionId: () => {
616
+ const current = api.route.current;
617
+ const resolved = typeof current === 'function' ? current() : current;
618
+ return resolved
619
+ ?.params?.sessionID;
620
+ },
621
+ dispatch: async (notification) => {
622
+ logger.debug('rpc-notification-received', {
623
+ command: notification.payload.command,
624
+ id: notification.id,
625
+ sessionId: notification.sessionId,
626
+ });
627
+ // Call the imperative dispatcher directly — the prior
628
+ // two-phase `collectDialogFlow` + `renderDialogFlow` is gone.
629
+ // The dispatcher awaits `apply`, toasts the result, then clears
630
+ // (or replaces for multi-step flows). The RPC `apply` accepts the
631
+ // optional `timeoutMs` knob so account add / refresh can opt into
632
+ // the 120s RPC timeout without the dialog layer having to know
633
+ // about it.
634
+ if (notification.payload.command === 'antigravity-quota') {
635
+ api.ui.dialog.setSize('xlarge');
636
+ api.ui.dialog.replace(() => (_jsx(QuotaDialogContent, { api: api, controller: getSidebarController(), sessionId: notification.sessionId })));
637
+ return;
638
+ }
639
+ openCommandDialog(api, notification.payload, (command, args, options) => rpcClient.apply({ command, arguments: args, sessionId: notification.sessionId }, options));
640
+ },
641
+ schedule: (poll, intervalMs) => {
642
+ setInterval(() => void poll(), intervalMs);
643
+ },
644
+ logger,
645
+ });
646
+ // The host supplies the live theme via `api.theme.current` — the slot
647
+ // callback's closure captures `api` so the accessor always reads the
648
+ // current theme. A Solid re-render follows whenever the user switches.
649
+ const liveTheme = () => api.theme.current;
650
+ api.slots.register({
651
+ order: computeEffectiveOrder(prefsRoot, PLUGIN_KEY, DEFAULT_SLOT_ORDER),
652
+ slots: {
653
+ sidebar_content: (_context, { session_id: sessionId }) => (_jsx(SidebarPanel, { logger: logger, theme: liveTheme, sessionId: sessionId })),
654
+ },
655
+ });
656
+ };
657
+ const plugin = {
658
+ id: ID,
659
+ tui,
660
+ };
661
+ export default plugin;
662
+ //# sourceMappingURL=tui.js.map