@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,22 @@
1
+ export type CommandModalName = 'antigravity-quota' | 'antigravity-account' | 'antigravity-routing' | 'antigravity-killswitch' | 'antigravity-dump' | 'antigravity-logging';
2
+ export interface OpenDialogPayload {
3
+ command: CommandModalName;
4
+ text: string;
5
+ knobs: Record<string, unknown>;
6
+ }
7
+ export interface RpcNotification {
8
+ id: number;
9
+ type: 'open-dialog';
10
+ payload: OpenDialogPayload;
11
+ sessionId?: string;
12
+ }
13
+ export interface ApplyRequest {
14
+ command: CommandModalName;
15
+ arguments: string;
16
+ sessionId?: string;
17
+ }
18
+ export interface ApplyResult {
19
+ text: string;
20
+ knobs: Record<string, unknown>;
21
+ }
22
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/rpc/protocol.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB,mBAAmB,GACnB,qBAAqB,GACrB,qBAAqB,GACrB,wBAAwB,GACxB,kBAAkB,GAClB,qBAAqB,CAAA;AAEzB,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,gBAAgB,CAAA;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,aAAa,CAAA;IACnB,OAAO,EAAE,iBAAiB,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,gBAAgB,CAAA;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/rpc/protocol.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import type { ApplyRequest, ApplyResult, RpcNotification } from './protocol';
2
+ export interface RpcRequestOptions {
3
+ timeoutMs?: number;
4
+ }
5
+ export interface RpcClient {
6
+ apply(request: ApplyRequest, options?: RpcRequestOptions): Promise<ApplyResult>;
7
+ pendingNotifications(lastReceivedId: number, sessionId?: string, options?: RpcRequestOptions): Promise<RpcNotification[]>;
8
+ }
9
+ export declare function createRpcClient(dir: string, expectedPid?: number): RpcClient;
10
+ //# sourceMappingURL=rpc-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../../../src/rpc/rpc-client.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAO5E,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,CACH,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,WAAW,CAAC,CAAA;IACvB,oBAAoB,CAClB,cAAc,EAAE,MAAM,EACtB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,eAAe,EAAE,CAAC,CAAA;CAC9B;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CA0B5E"}
@@ -0,0 +1,58 @@
1
+ // Subpath import (not the barrel): this module ships into the TUI's
2
+ // compiled tree, which must not pull the credential-bearing barrel into
3
+ // the host's render path.
4
+ import { fetchWithActiveTimeout } from '@cortexkit/antigravity-auth-core/fetch-timeout';
5
+ import { discoverPortFile } from './port-file';
6
+ const DEFAULT_TIMEOUT_MS = 2_000;
7
+ const APPLY_FALLBACK = { text: 'apply failed', knobs: {} };
8
+ const PENDING_FALLBACK = [];
9
+ export function createRpcClient(dir, expectedPid) {
10
+ return {
11
+ async apply(request, options) {
12
+ const result = await post(dir, expectedPid, '/rpc/apply', request, options);
13
+ return result ?? APPLY_FALLBACK;
14
+ },
15
+ async pendingNotifications(lastReceivedId, sessionId, options) {
16
+ const result = await post(dir, expectedPid, '/rpc/pending-notifications', {
17
+ lastReceivedId,
18
+ ...(sessionId === undefined ? {} : { sessionId }),
19
+ }, options);
20
+ return result?.messages ?? PENDING_FALLBACK;
21
+ },
22
+ };
23
+ }
24
+ async function post(dir, expectedPid, path, body, options) {
25
+ // Internal nullable — every RPC call site (apply, pending) must absorb a
26
+ // missing/unreachable server gracefully. The TUI render path never
27
+ // crashes because the server is dead; the user sees a fallback text and
28
+ // a fresh poll retries the next tick.
29
+ const entry = await discoverPortFileSafe(dir, expectedPid);
30
+ if (!entry)
31
+ return null;
32
+ const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33
+ try {
34
+ const response = await fetchWithActiveTimeout(`http://127.0.0.1:${entry.port}${path}`, {
35
+ method: 'POST',
36
+ headers: {
37
+ authorization: `Bearer ${entry.token}`,
38
+ 'content-type': 'application/json',
39
+ },
40
+ body: JSON.stringify(body),
41
+ }, { timeoutMs });
42
+ if (!response.ok)
43
+ return null;
44
+ return (await response.json());
45
+ }
46
+ catch {
47
+ return null;
48
+ }
49
+ }
50
+ async function discoverPortFileSafe(dir, expectedPid) {
51
+ try {
52
+ return await discoverPortFile(dir, expectedPid);
53
+ }
54
+ catch {
55
+ return null;
56
+ }
57
+ }
58
+ //# sourceMappingURL=rpc-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../../src/rpc/rpc-client.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,wEAAwE;AACxE,0BAA0B;AAC1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAA;AAEvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAG9C,MAAM,kBAAkB,GAAG,KAAK,CAAA;AAEhC,MAAM,cAAc,GAAgB,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;AACvE,MAAM,gBAAgB,GAAsB,EAAE,CAAA;AAkB9C,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,WAAoB;IAC/D,OAAO;QACL,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO;YAC1B,MAAM,MAAM,GAAG,MAAM,IAAI,CACvB,GAAG,EACH,WAAW,EACX,YAAY,EACZ,OAAO,EACP,OAAO,CACR,CAAA;YACD,OAAO,MAAM,IAAI,cAAc,CAAA;QACjC,CAAC;QACD,KAAK,CAAC,oBAAoB,CAAC,cAAc,EAAE,SAAS,EAAE,OAAO;YAC3D,MAAM,MAAM,GAAG,MAAM,IAAI,CACvB,GAAG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AAW,CAAC,CAAA;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { tmpdir } from 'node:os';
2
+ export declare function getRpcDir(projectDirectory: string): string;
3
+ export { tmpdir };
4
+ //# sourceMappingURL=rpc-dir.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-dir.d.ts","sourceRoot":"","sources":["../../../src/rpc/rpc-dir.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,MAAM,EAAE,MAAM,SAAS,CAAA;AAMzC,wBAAgB,SAAS,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAc1D;AAED,OAAO,EAAE,MAAM,EAAE,CAAA"}
@@ -0,0 +1,19 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { homedir, tmpdir } from 'node:os';
3
+ import { isAbsolute, join, resolve } from 'node:path';
4
+ const RPC_DIR_ENV = 'ANTIGRAVITY_AUTH_RPC_DIR';
5
+ // Both processes must resolve the SAME dir from the SAME project directory.
6
+ export function getRpcDir(projectDirectory) {
7
+ const override = process.env[RPC_DIR_ENV]?.trim();
8
+ if (override) {
9
+ return isAbsolute(override) ? override : resolve(projectDirectory, override);
10
+ }
11
+ const projectHash = createHash('sha256')
12
+ .update(resolve(projectDirectory))
13
+ .digest('hex')
14
+ .slice(0, 16);
15
+ const stateHome = process.env.XDG_STATE_HOME ?? join(homedir(), '.local', 'state');
16
+ return join(stateHome, 'cortexkit', 'antigravity-auth', 'rpc', projectHash);
17
+ }
18
+ export { tmpdir };
19
+ //# sourceMappingURL=rpc-dir.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-dir.js","sourceRoot":"","sources":["../../../src/rpc/rpc-dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAErD,MAAM,WAAW,GAAG,0BAA0B,CAAA;AAE9C,4EAA4E;AAC5E,MAAM,UAAU,SAAS,CAAC,gBAAwB;IAChD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,CAAA;IACjD,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAA;IAC9E,CAAC;IAED,MAAM,WAAW,GAAG,UAAU,CAAC,QAAQ,CAAC;SACrC,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;SACjC,MAAM,CAAC,KAAK,CAAC;SACb,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IACf,MAAM,SAAS,GACb,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAA;IAElE,OAAO,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,kBAAkB,EAAE,KAAK,EAAE,WAAW,CAAC,CAAA;AAC7E,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,CAAA"}
@@ -0,0 +1,13 @@
1
+ import type { ApplyRequest, ApplyResult, RpcNotification } from './protocol';
2
+ export interface StartRpcServerOptions {
3
+ dir: string;
4
+ apply(request: ApplyRequest): Promise<ApplyResult> | ApplyResult;
5
+ drain(lastReceivedId: number, sessionId?: string): Promise<RpcNotification[]> | RpcNotification[];
6
+ }
7
+ export interface RpcServerHandle {
8
+ port: number;
9
+ token: string;
10
+ stop(): Promise<void>;
11
+ }
12
+ export declare function startRpcServer(options: StartRpcServerOptions): Promise<RpcServerHandle>;
13
+ //# sourceMappingURL=rpc-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-server.d.ts","sourceRoot":"","sources":["../../../src/rpc/rpc-server.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EAEX,eAAe,EAChB,MAAM,YAAY,CAAA;AAmBnB,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,CAAA;IAChE,KAAK,CACH,cAAc,EAAE,MAAM,EACtB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,EAAE,CAAC,GAAG,eAAe,EAAE,CAAA;CAClD;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAWD,wBAAsB,cAAc,CAClC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC,CAoE1B"}
@@ -0,0 +1,231 @@
1
+ import { randomBytes, timingSafeEqual } from 'node:crypto';
2
+ import { unlink } from 'node:fs/promises';
3
+ import { createServer, } from 'node:http';
4
+ import { join } from 'node:path';
5
+ import { writePortFile } from './port-file';
6
+ const LOOPBACK_HOST = '127.0.0.1';
7
+ const REQUEST_TIMEOUT_MS = 2_000;
8
+ const APPLY_TIMEOUT_MS = 120_000;
9
+ const MAX_BODY_BYTES = 1024 * 1024;
10
+ const APPLY_PATH = '/rpc/apply';
11
+ const NOTIFICATIONS_PATH = '/rpc/pending-notifications';
12
+ const HEALTH_PATH = '/health';
13
+ const COMMANDS = new Set([
14
+ 'antigravity-quota',
15
+ 'antigravity-account',
16
+ 'antigravity-routing',
17
+ 'antigravity-killswitch',
18
+ 'antigravity-dump',
19
+ 'antigravity-logging',
20
+ ]);
21
+ class HttpError extends Error {
22
+ status;
23
+ constructor(status, message) {
24
+ super(message);
25
+ this.status = status;
26
+ }
27
+ }
28
+ export async function startRpcServer(options) {
29
+ const token = randomBytes(32).toString('hex');
30
+ const server = createServer((request, response) => {
31
+ void handleRequest(request, response, token, options).catch((error) => {
32
+ if (response.headersSent || response.writableEnded)
33
+ return;
34
+ if (error instanceof HttpError) {
35
+ sendJson(response, error.status, { error: error.message });
36
+ return;
37
+ }
38
+ sendJson(response, 500, { error: 'Internal RPC error' });
39
+ });
40
+ });
41
+ server.headersTimeout = REQUEST_TIMEOUT_MS;
42
+ server.requestTimeout = REQUEST_TIMEOUT_MS;
43
+ await new Promise((resolve, reject) => {
44
+ const onError = (error) => {
45
+ server.off('listening', onListening);
46
+ reject(error);
47
+ };
48
+ const onListening = () => {
49
+ server.off('error', onError);
50
+ resolve();
51
+ };
52
+ server.once('error', onError);
53
+ server.once('listening', onListening);
54
+ server.listen(0, LOOPBACK_HOST);
55
+ });
56
+ // unref so the open TCP listener does not keep the host process alive
57
+ // once the rest of the event loop has nothing else to do.
58
+ server.unref();
59
+ const address = server.address();
60
+ if (!address) {
61
+ await closeServer(server);
62
+ throw new Error('RPC server started without a TCP address');
63
+ }
64
+ try {
65
+ await writePortFile(options.dir, {
66
+ pid: process.pid,
67
+ port: address.port,
68
+ token,
69
+ });
70
+ }
71
+ catch (error) {
72
+ await closeServer(server);
73
+ throw error;
74
+ }
75
+ let stopping = null;
76
+ return {
77
+ port: address.port,
78
+ token,
79
+ stop() {
80
+ if (!stopping) {
81
+ stopping = (async () => {
82
+ await closeServer(server);
83
+ try {
84
+ await unlink(join(options.dir, `port-${process.pid}.json`));
85
+ }
86
+ catch (error) {
87
+ if (!isNodeError(error, 'ENOENT'))
88
+ throw error;
89
+ }
90
+ })();
91
+ }
92
+ return stopping;
93
+ },
94
+ };
95
+ }
96
+ async function handleRequest(request, response, token, options) {
97
+ const path = request.url
98
+ ? new URL(request.url, 'http://localhost').pathname
99
+ : '';
100
+ if (request.method === 'GET' && path === HEALTH_PATH) {
101
+ sendJson(response, 200, { ok: true });
102
+ return;
103
+ }
104
+ if (request.method !== 'POST' ||
105
+ (path !== APPLY_PATH && path !== NOTIFICATIONS_PATH)) {
106
+ sendJson(response, 404, { error: 'Not found' });
107
+ return;
108
+ }
109
+ if (!isAuthorized(request.headers.authorization, token)) {
110
+ sendJson(response, 401, { error: 'Unauthorized' });
111
+ return;
112
+ }
113
+ const body = await readJsonBody(request);
114
+ if (path === APPLY_PATH) {
115
+ const applyRequest = parseApplyRequest(body);
116
+ const result = await withTimeout(Promise.resolve(options.apply(applyRequest)), APPLY_TIMEOUT_MS);
117
+ sendJson(response, 200, result);
118
+ return;
119
+ }
120
+ const pendingRequest = parsePendingRequest(body);
121
+ const notifications = await options.drain(pendingRequest.lastReceivedId, pendingRequest.sessionId);
122
+ sendJson(response, 200, { messages: notifications });
123
+ }
124
+ function isAuthorized(header, token) {
125
+ const prefix = 'Bearer ';
126
+ const provided = header?.startsWith(prefix) ? header.slice(prefix.length) : '';
127
+ const expectedBytes = Buffer.from(token);
128
+ const providedBytes = Buffer.from(provided);
129
+ const padded = Buffer.alloc(expectedBytes.length);
130
+ providedBytes.copy(padded, 0, 0, expectedBytes.length);
131
+ const sameLength = providedBytes.length === expectedBytes.length;
132
+ return timingSafeEqual(padded, expectedBytes) && sameLength;
133
+ }
134
+ async function readJsonBody(request) {
135
+ const declaredLength = Number(request.headers['content-length'] ?? 0);
136
+ if (Number.isFinite(declaredLength) && declaredLength > MAX_BODY_BYTES) {
137
+ request.resume();
138
+ throw new HttpError(413, 'Request body too large');
139
+ }
140
+ const chunks = [];
141
+ let bytes = 0;
142
+ await new Promise((resolve, reject) => {
143
+ request.on('data', (chunk) => {
144
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
145
+ bytes += buffer.length;
146
+ if (bytes > MAX_BODY_BYTES) {
147
+ request.removeAllListeners('data');
148
+ request.on('data', () => { });
149
+ request.resume();
150
+ reject(new HttpError(413, 'Request body too large'));
151
+ return;
152
+ }
153
+ chunks.push(buffer);
154
+ });
155
+ request.once('end', resolve);
156
+ request.once('error', reject);
157
+ request.once('aborted', () => reject(new HttpError(400, 'Request aborted')));
158
+ });
159
+ try {
160
+ return JSON.parse(Buffer.concat(chunks).toString('utf8'));
161
+ }
162
+ catch {
163
+ throw new HttpError(400, 'Invalid JSON');
164
+ }
165
+ }
166
+ function parseApplyRequest(value) {
167
+ if (!isRecord(value) ||
168
+ typeof value.command !== 'string' ||
169
+ !COMMANDS.has(value.command) ||
170
+ typeof value.arguments !== 'string' ||
171
+ (value.sessionId !== undefined && typeof value.sessionId !== 'string')) {
172
+ throw new HttpError(400, 'Invalid apply request');
173
+ }
174
+ return value;
175
+ }
176
+ function parsePendingRequest(value) {
177
+ if (!isRecord(value) ||
178
+ !Number.isSafeInteger(value.lastReceivedId) ||
179
+ value.lastReceivedId < 0 ||
180
+ (value.sessionId !== undefined && typeof value.sessionId !== 'string')) {
181
+ throw new HttpError(400, 'Invalid pending-notifications request');
182
+ }
183
+ return {
184
+ lastReceivedId: value.lastReceivedId,
185
+ ...(value.sessionId === undefined
186
+ ? {}
187
+ : { sessionId: value.sessionId }),
188
+ };
189
+ }
190
+ function isRecord(value) {
191
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
192
+ }
193
+ function sendJson(response, status, value) {
194
+ response.writeHead(status, {
195
+ 'content-type': 'application/json; charset=utf-8',
196
+ 'x-content-type-options': 'nosniff',
197
+ });
198
+ response.end(JSON.stringify(value));
199
+ }
200
+ async function withTimeout(promise, timeoutMs) {
201
+ let timeout;
202
+ const deadline = new Promise((_, reject) => {
203
+ timeout = setTimeout(() => reject(new HttpError(504, 'RPC handler timed out')), timeoutMs);
204
+ timeout.unref?.();
205
+ });
206
+ try {
207
+ return await Promise.race([promise, deadline]);
208
+ }
209
+ finally {
210
+ if (timeout)
211
+ clearTimeout(timeout);
212
+ }
213
+ }
214
+ function closeServer(server) {
215
+ return new Promise((resolve, reject) => {
216
+ server.close((error) => {
217
+ if (error && !isNodeError(error, 'ERR_SERVER_NOT_RUNNING')) {
218
+ reject(error);
219
+ return;
220
+ }
221
+ resolve();
222
+ });
223
+ server.closeAllConnections?.();
224
+ });
225
+ }
226
+ function isNodeError(error, code) {
227
+ return (error instanceof Error &&
228
+ 'code' in error &&
229
+ error.code === code);
230
+ }
231
+ //# sourceMappingURL=rpc-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-server.js","sourceRoot":"","sources":["../../../src/rpc/rpc-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EACL,YAAY,GAGb,MAAM,WAAW,CAAA;AAElB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAQ3C,MAAM,aAAa,GAAG,WAAW,CAAA;AACjC,MAAM,kBAAkB,GAAG,KAAK,CAAA;AAChC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AAChC,MAAM,cAAc,GAAG,IAAI,GAAG,IAAI,CAAA;AAClC,MAAM,UAAU,GAAG,YAAY,CAAA;AAC/B,MAAM,kBAAkB,GAAG,4BAA4B,CAAA;AACvD,MAAM,WAAW,GAAG,SAAS,CAAA;AAE7B,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAmB;IACzC,mBAAmB;IACnB,qBAAqB;IACrB,qBAAqB;IACrB,wBAAwB;IACxB,kBAAkB;IAClB,qBAAqB;CACtB,CAAC,CAAA;AAiBF,MAAM,SAAU,SAAQ,KAAK;IAEhB;IADX,YACW,MAAc,EACvB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAA;QAHL,WAAM,GAAN,MAAM,CAAQ;IAIzB,CAAC;CACF;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAA8B;IAE9B,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,CA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AA;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,KAAc,EAAE,IAAY;IAC/C,OAAO,CACL,KAAK,YAAY,KAAK;QACtB,MAAM,IAAI,KAAK;QACd,KAA+B,CAAC,IAAI,KAAK,IAAI,CAC/C,CAAA;AACH,CAAC"}
@@ -0,0 +1,240 @@
1
+ /**
2
+ * Sidebar state contract for the OpenTUI sidebar.
3
+ *
4
+ * This module is the read-only seam between the long-running plugin and the
5
+ * Solid/OpenTUI sidebar tree. It deliberately does NOT import account storage,
6
+ * the account manager, OAuth code, or any other privileged host-side module:
7
+ * the TUI is rendered inside the host's terminal and a single stray import
8
+ * could leak credentials or pull a heavy manager into the render path.
9
+ *
10
+ * The plugin writes a redacted snapshot to the file resolved by
11
+ * `getSidebarStateFile()` and the TUI polls it. The contract version is `1`:
12
+ * any future field that the TUI cannot understand must be ignored, and any
13
+ * broken/missing file must collapse to `DEFAULT_SIDEBAR_STATE`.
14
+ *
15
+ * ## Writer surface
16
+ *
17
+ * The plugin-side writers live here too so the read and write halves of the
18
+ * contract evolve together. They are imported by the plugin (auth-loader,
19
+ * quota, fetch-interceptor, event-handler, commands) but never invoked from
20
+ * the TUI's compiled tree — that tree only calls the readers, so the
21
+ * heavyweight core imports below never run inside the host's render path.
22
+ *
23
+ * Every disk mutation follows the same recipe:
24
+ *
25
+ * 1. Serialize through `sidebarWriteChain` so concurrent in-process calls
26
+ * never interleave merges against the same file.
27
+ * 2. Acquire Task 7's `acquireFencedFileLock` with bounded retry+jitter
28
+ * (≤2s). A live cross-process holder that does not release in time
29
+ * surfaces as `SidebarStateLockContentionError`.
30
+ * 3. Re-read and normalize the on-disk state while holding the lock.
31
+ * 4. Merge the new machine or routing payload against the re-read state.
32
+ * 5. `assertOwned()` + `writeJsonAtomic` with mode 0o600, then release.
33
+ *
34
+ * The merge step is deterministic: machine fields adopt only when the new
35
+ * `checkedAt` is ≥ the on-disk one, `routingAuthoritative` is sticky-true,
36
+ * and `activeRouting` is merged independently and pruned to the freshest
37
+ * 100 entries within 24h.
38
+ */
39
+ export declare const SIDEBAR_STATE_VERSION: 1;
40
+ export type SidebarQuotaKey = 'claude' | 'gemini-pro' | 'gemini-flash' | 'gpt-oss';
41
+ export interface SidebarQuotaEntry {
42
+ remainingPercent: number;
43
+ resetAt?: number;
44
+ }
45
+ export interface SidebarAccountState {
46
+ id: string;
47
+ label: string;
48
+ enabled: boolean;
49
+ health: number;
50
+ current: boolean;
51
+ cooldownUntil?: number;
52
+ quota: Partial<Record<SidebarQuotaKey, SidebarQuotaEntry>>;
53
+ }
54
+ export interface SidebarRoutingEntry {
55
+ accountId: string;
56
+ modelFamily: 'claude' | 'gemini';
57
+ headerStyle: 'antigravity' | 'gemini-cli';
58
+ strategy?: 'sticky' | 'round-robin' | 'hybrid';
59
+ updatedAt: number;
60
+ }
61
+ export interface SidebarStateV1 {
62
+ version: typeof SIDEBAR_STATE_VERSION;
63
+ checkedAt: number;
64
+ accounts: SidebarAccountState[];
65
+ activeRouting: Record<string, SidebarRoutingEntry>;
66
+ routingAuthoritative: boolean;
67
+ quotaBackoffUntil?: number;
68
+ lastError?: string;
69
+ }
70
+ /**
71
+ * The subset of `SidebarStateV1` that a non-routing writer may set. The
72
+ * fetch interceptor writes `activeRouting` directly via its own entry point
73
+ * because routing is session-scoped, not machine-scoped.
74
+ */
75
+ export interface SidebarMachineState {
76
+ checkedAt: number;
77
+ accounts: SidebarAccountState[];
78
+ quotaBackoffUntil?: number;
79
+ lastError?: string;
80
+ /**
81
+ * Optional: opt in to mark the snapshot as authoritative. When `true`,
82
+ * the merge keeps the existing `routingAuthoritative: true` even if a
83
+ * later non-authoritative machine write lands. Sticky-true semantics.
84
+ */
85
+ routingAuthoritative?: boolean;
86
+ }
87
+ export declare const DEFAULT_SIDEBAR_STATE: SidebarStateV1;
88
+ export declare const SIDEBAR_STATE_ENV = "ANTIGRAVITY_AUTH_SIDEBAR_STATE_FILE";
89
+ /**
90
+ * Thrown by every writer when the cross-process lock cannot be acquired
91
+ * within `SIDEBAR_LOCK_TIMEOUT_MS`. The caller decides whether to surface
92
+ * a toast, drop the write, or retry the next tick.
93
+ */
94
+ export declare class SidebarStateLockContentionError extends Error {
95
+ readonly details: {
96
+ stateFile: string;
97
+ timeoutMs: number;
98
+ };
99
+ constructor(stateFile: string, timeoutMs: number);
100
+ }
101
+ /**
102
+ * Steps exposed to the merge hooks. Race tests pause writers here; production
103
+ * callers leave the hooks unset (a no-op fast path).
104
+ *
105
+ * - `await-lock` — before invoking `acquireFencedFileLock`.
106
+ * - `acquired-lock` — after the lock is granted and before the read.
107
+ * - `read-state` — after the on-disk state is normalized.
108
+ * - `merged-state` — after the merge but before `writeJsonAtomic`.
109
+ * - `wrote-state` — after the rename but before `lock.release()`.
110
+ */
111
+ export type SidebarMergeStep = 'await-lock' | 'acquired-lock' | 'read-state' | 'merged-state' | 'wrote-state';
112
+ export interface SidebarMergeHooks {
113
+ onStep?: (step: SidebarMergeStep) => Promise<void> | void;
114
+ }
115
+ /**
116
+ * Install (or clear with `null`) the deterministic race hooks. Tests use
117
+ * these to inject interleavings; production callers leave them unset. The
118
+ * module-level state means a test must reset hooks in its own `afterEach`
119
+ * to avoid bleeding into the next test.
120
+ */
121
+ export declare function setSidebarMergeHooks(hooks: SidebarMergeHooks | null): void;
122
+ /**
123
+ * Resolve the on-disk path the plugin writes to and the TUI reads from.
124
+ *
125
+ * - `ANTIGRAVITY_AUTH_SIDEBAR_STATE_FILE` wins when set (tests, packaged
126
+ * installers, and any user override).
127
+ * - Otherwise fall back to the XDG state directory, mirroring the path
128
+ * conventions used elsewhere in the project.
129
+ */
130
+ export declare function getSidebarStateFile(): string;
131
+ /**
132
+ * Read and normalize the sidebar state file. Returns the default state when
133
+ * the file is missing, unreadable, malformed, or schema-incompatible — the TUI
134
+ * must never throw out of `readSidebarState()`, the panel just shows
135
+ * "Awaiting Antigravity state" and the next poll retries.
136
+ *
137
+ * The read is sync on purpose: the TUI polls on a 2-second timer and the file
138
+ * is tiny (a handful of accounts); an async read here would just add race
139
+ * surface area against Solid's reactive render cycle.
140
+ */
141
+ export declare function readSidebarState(path?: string): SidebarStateV1;
142
+ /**
143
+ * Ensure the parent directory for the sidebar state file exists. Convenience
144
+ * helper used by writers (tests, plugins) — the TUI itself does not write.
145
+ */
146
+ export declare function ensureSidebarStateDir(path?: string): void;
147
+ /**
148
+ * Drop active-routing entries older than 24h and cap the map at the freshest
149
+ * 100. Pure helper exposed for unit testing; the writers call it on every
150
+ * merge so the on-disk map never grows without bound.
151
+ */
152
+ export declare function pruneActiveRouting(map: Record<string, SidebarRoutingEntry>, now: number): Record<string, SidebarRoutingEntry>;
153
+ /**
154
+ * Structural input for `redactAccountForSidebar`. Decoupled from the core
155
+ * `ManagedAccount` type so this module never forces a type-level import
156
+ * shape on callers (and so the TUI's compiled tree does not see the core
157
+ * ManagedAccount shape beyond what's actually used).
158
+ *
159
+ * Deliberately excludes `email`: the sidebar/redaction boundary is a PII
160
+ * firewall. Adding `email` here would re-introduce the leak this boundary
161
+ * exists to prevent. Legacy profile labels are accepted but never serialized.
162
+ */
163
+ export interface SidebarAccountRedactionInput {
164
+ /** Position in the harness-visible account array. */
165
+ index: number;
166
+ /** Legacy profile label; deliberately ignored by the redactor. */
167
+ label?: string;
168
+ enabled?: boolean;
169
+ current?: boolean;
170
+ coolingDownUntil?: number;
171
+ /** Health score in `[0, 100]`. Defaults to 100 when missing. */
172
+ healthScore?: number;
173
+ cachedQuota?: {
174
+ claude?: {
175
+ remainingFraction?: number;
176
+ resetTime?: string;
177
+ };
178
+ 'gemini-pro'?: {
179
+ remainingFraction?: number;
180
+ resetTime?: string;
181
+ };
182
+ 'gemini-flash'?: {
183
+ remainingFraction?: number;
184
+ resetTime?: string;
185
+ };
186
+ 'gpt-oss'?: {
187
+ remainingFraction?: number;
188
+ resetTime?: string;
189
+ };
190
+ };
191
+ }
192
+ /**
193
+ * Convert a live account snapshot into the redacted shape the TUI renders.
194
+ * The redacted `SidebarAccountState` carries no email, refresh token, access
195
+ * token, project ID, fingerprint, OAuth profile name, or other personal or
196
+ * credential-shaped fields. Display labels are generated ordinal account names.
197
+ */
198
+ export declare function redactAccountForSidebar(source: SidebarAccountRedactionInput): SidebarAccountState;
199
+ /**
200
+ * Build a `SidebarMachineState` from a list of live account snapshots.
201
+ * Convenience for the auth-loader / quota writer call sites that already
202
+ * hold an array of accounts and want to push a single snapshot.
203
+ */
204
+ export declare function buildSidebarMachineStateFromAccounts(accounts: SidebarAccountRedactionInput[], options?: {
205
+ checkedAt?: number;
206
+ quotaBackoffUntil?: number;
207
+ lastError?: string;
208
+ routingAuthoritative?: boolean;
209
+ }): SidebarMachineState;
210
+ interface SidebarStateWriteOptions {
211
+ stateFile?: string;
212
+ }
213
+ /**
214
+ * Wait for any in-flight sidebar state write to drain. The plugin lifecycle
215
+ * calls this during `dispose()` so the file logger and RPC server are torn
216
+ * down only after every queued write has either landed or thrown.
217
+ */
218
+ export declare function drainSidebarWrites(): Promise<void>;
219
+ /**
220
+ * Upsert a single session's active routing entry. The fetch interceptor calls
221
+ * this with `authoritative: true` after every final route selection; the
222
+ * `accountId`/`modelFamily`/`headerStyle` fields are already redacted by the
223
+ * caller (the writer never sees token or project fields).
224
+ */
225
+ export declare function upsertSidebarActiveRouting(sessionId: string, entry: SidebarRoutingEntry, options?: SidebarStateWriteOptions & {
226
+ authoritative?: boolean;
227
+ }): Promise<void>;
228
+ /**
229
+ * Remove one session's active routing entry. The event handler calls this
230
+ * when a session is deleted so the sidebar does not retain dead routes.
231
+ */
232
+ export declare function removeSidebarActiveRouting(sessionId: string, options?: SidebarStateWriteOptions): Promise<void>;
233
+ /**
234
+ * Write a new machine-state snapshot. The fetch interceptor and quota
235
+ * manager call this after each refresh; auth-loader calls it after the
236
+ * account pool is materialized.
237
+ */
238
+ export declare function setSidebarMachineState(next: SidebarMachineState, options?: SidebarStateWriteOptions): Promise<void>;
239
+ export {};
240
+ //# sourceMappingURL=sidebar-state.d.ts.map