@cortexkit/opencode-antigravity-auth 1.1.0 → 2.0.1

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 (379) hide show
  1. package/README.md +225 -569
  2. package/dist/cli.js +4017 -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 +20742 -14586
  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/account-command-oauth.d.ts +34 -0
  38. package/dist/src/plugin/account-command-oauth.d.ts.map +1 -0
  39. package/dist/src/plugin/account-command-oauth.js +156 -0
  40. package/dist/src/plugin/account-command-oauth.js.map +1 -0
  41. package/dist/src/plugin/accounts.d.ts +7 -256
  42. package/dist/src/plugin/accounts.d.ts.map +1 -1
  43. package/dist/src/plugin/accounts.js +31 -1367
  44. package/dist/src/plugin/accounts.js.map +1 -1
  45. package/dist/src/plugin/agy-request-metadata.d.ts +1 -1
  46. package/dist/src/plugin/agy-request-metadata.js +1 -1
  47. package/dist/src/plugin/agy-transport.d.ts +1 -1
  48. package/dist/src/plugin/agy-transport.js +1 -1
  49. package/dist/src/plugin/auth-doctor.d.ts +6 -6
  50. package/dist/src/plugin/auth-doctor.d.ts.map +1 -1
  51. package/dist/src/plugin/auth-doctor.js +74 -66
  52. package/dist/src/plugin/auth-doctor.js.map +1 -1
  53. package/dist/src/plugin/auth-drift.d.ts +4 -4
  54. package/dist/src/plugin/auth-drift.d.ts.map +1 -1
  55. package/dist/src/plugin/auth-drift.js +15 -15
  56. package/dist/src/plugin/auth-drift.js.map +1 -1
  57. package/dist/src/plugin/auth-loader.d.ts +50 -0
  58. package/dist/src/plugin/auth-loader.d.ts.map +1 -0
  59. package/dist/src/plugin/auth-loader.js +225 -0
  60. package/dist/src/plugin/auth-loader.js.map +1 -0
  61. package/dist/src/plugin/auth.d.ts +1 -1
  62. package/dist/src/plugin/auth.js +1 -1
  63. package/dist/src/plugin/background-quota-refresh.d.ts +146 -0
  64. package/dist/src/plugin/background-quota-refresh.d.ts.map +1 -0
  65. package/dist/src/plugin/background-quota-refresh.js +347 -0
  66. package/dist/src/plugin/background-quota-refresh.js.map +1 -0
  67. package/dist/src/plugin/cache/index.d.ts +1 -1
  68. package/dist/src/plugin/cache/index.d.ts.map +1 -1
  69. package/dist/src/plugin/cache/index.js +1 -1
  70. package/dist/src/plugin/cache/index.js.map +1 -1
  71. package/dist/src/plugin/cache/signature-cache.d.ts +1 -1
  72. package/dist/src/plugin/cache/signature-cache.d.ts.map +1 -1
  73. package/dist/src/plugin/cache/signature-cache.js +23 -24
  74. package/dist/src/plugin/cache/signature-cache.js.map +1 -1
  75. package/dist/src/plugin/cache.d.ts +6 -5
  76. package/dist/src/plugin/cache.d.ts.map +1 -1
  77. package/dist/src/plugin/cache.js +21 -7
  78. package/dist/src/plugin/cache.js.map +1 -1
  79. package/dist/src/plugin/catalog.d.ts +23 -0
  80. package/dist/src/plugin/catalog.d.ts.map +1 -0
  81. package/dist/src/plugin/catalog.js +60 -0
  82. package/dist/src/plugin/catalog.js.map +1 -0
  83. package/dist/src/plugin/cli.d.ts +7 -7
  84. package/dist/src/plugin/cli.d.ts.map +1 -1
  85. package/dist/src/plugin/cli.js +62 -55
  86. package/dist/src/plugin/cli.js.map +1 -1
  87. package/dist/src/plugin/command-data.d.ts +329 -0
  88. package/dist/src/plugin/command-data.d.ts.map +1 -0
  89. package/dist/src/plugin/command-data.js +517 -0
  90. package/dist/src/plugin/command-data.js.map +1 -0
  91. package/dist/src/plugin/commands.d.ts +154 -0
  92. package/dist/src/plugin/commands.d.ts.map +1 -0
  93. package/dist/src/plugin/commands.js +746 -0
  94. package/dist/src/plugin/commands.js.map +1 -0
  95. package/dist/src/plugin/config/index.d.ts +2 -2
  96. package/dist/src/plugin/config/index.d.ts.map +1 -1
  97. package/dist/src/plugin/config/index.js +2 -2
  98. package/dist/src/plugin/config/index.js.map +1 -1
  99. package/dist/src/plugin/config/loader.d.ts +1 -1
  100. package/dist/src/plugin/config/loader.d.ts.map +1 -1
  101. package/dist/src/plugin/config/loader.js +18 -16
  102. package/dist/src/plugin/config/loader.js.map +1 -1
  103. package/dist/src/plugin/config/models.d.ts +2 -2
  104. package/dist/src/plugin/config/models.d.ts.map +1 -1
  105. package/dist/src/plugin/config/models.js +1 -1
  106. package/dist/src/plugin/config/models.js.map +1 -1
  107. package/dist/src/plugin/config/operator-settings-schema.d.ts +29 -0
  108. package/dist/src/plugin/config/operator-settings-schema.d.ts.map +1 -0
  109. package/dist/src/plugin/config/operator-settings-schema.js +28 -0
  110. package/dist/src/plugin/config/operator-settings-schema.js.map +1 -0
  111. package/dist/src/plugin/config/schema.d.ts +23 -2
  112. package/dist/src/plugin/config/schema.d.ts.map +1 -1
  113. package/dist/src/plugin/config/schema.js +109 -25
  114. package/dist/src/plugin/config/schema.js.map +1 -1
  115. package/dist/src/plugin/config/updater.d.ts.map +1 -1
  116. package/dist/src/plugin/config/updater.js +15 -15
  117. package/dist/src/plugin/config/updater.js.map +1 -1
  118. package/dist/src/plugin/config/writer.d.ts +34 -0
  119. package/dist/src/plugin/config/writer.d.ts.map +1 -0
  120. package/dist/src/plugin/config/writer.js +81 -0
  121. package/dist/src/plugin/config/writer.js.map +1 -0
  122. package/dist/src/plugin/core/streaming/index.d.ts +1 -1
  123. package/dist/src/plugin/core/streaming/index.d.ts.map +1 -1
  124. package/dist/src/plugin/core/streaming/index.js +1 -1
  125. package/dist/src/plugin/core/streaming/index.js.map +1 -1
  126. package/dist/src/plugin/core/streaming/transformer.d.ts.map +1 -1
  127. package/dist/src/plugin/core/streaming/transformer.js +85 -44
  128. package/dist/src/plugin/core/streaming/transformer.js.map +1 -1
  129. package/dist/src/plugin/core/streaming/types.d.ts.map +1 -1
  130. package/dist/src/plugin/debug.d.ts +10 -3
  131. package/dist/src/plugin/debug.d.ts.map +1 -1
  132. package/dist/src/plugin/debug.js +110 -47
  133. package/dist/src/plugin/debug.js.map +1 -1
  134. package/dist/src/plugin/dependencies.d.ts +129 -0
  135. package/dist/src/plugin/dependencies.d.ts.map +1 -0
  136. package/dist/src/plugin/dependencies.js +107 -0
  137. package/dist/src/plugin/dependencies.js.map +1 -0
  138. package/dist/src/plugin/errors.d.ts +27 -0
  139. package/dist/src/plugin/errors.d.ts.map +1 -1
  140. package/dist/src/plugin/errors.js +29 -3
  141. package/dist/src/plugin/errors.js.map +1 -1
  142. package/dist/src/plugin/event-handler.d.ts +53 -0
  143. package/dist/src/plugin/event-handler.d.ts.map +1 -0
  144. package/dist/src/plugin/event-handler.js +101 -0
  145. package/dist/src/plugin/event-handler.js.map +1 -0
  146. package/dist/src/plugin/fetch/retry-state.d.ts +61 -0
  147. package/dist/src/plugin/fetch/retry-state.d.ts.map +1 -0
  148. package/dist/src/plugin/fetch/retry-state.js +248 -0
  149. package/dist/src/plugin/fetch/retry-state.js.map +1 -0
  150. package/dist/src/plugin/fetch/warmup.d.ts +30 -0
  151. package/dist/src/plugin/fetch/warmup.d.ts.map +1 -0
  152. package/dist/src/plugin/fetch/warmup.js +76 -0
  153. package/dist/src/plugin/fetch/warmup.js.map +1 -0
  154. package/dist/src/plugin/fetch-interceptor.d.ts +59 -0
  155. package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -0
  156. package/dist/src/plugin/fetch-interceptor.js +1399 -0
  157. package/dist/src/plugin/fetch-interceptor.js.map +1 -0
  158. package/dist/src/plugin/fetch-routing.d.ts +26 -0
  159. package/dist/src/plugin/fetch-routing.d.ts.map +1 -0
  160. package/dist/src/plugin/fetch-routing.js +99 -0
  161. package/dist/src/plugin/fetch-routing.js.map +1 -0
  162. package/dist/src/plugin/fingerprint.d.ts +1 -1
  163. package/dist/src/plugin/fingerprint.js +1 -1
  164. package/dist/src/plugin/gemini-dump.d.ts +5 -5
  165. package/dist/src/plugin/gemini-dump.d.ts.map +1 -1
  166. package/dist/src/plugin/gemini-dump.js +109 -55
  167. package/dist/src/plugin/gemini-dump.js.map +1 -1
  168. package/dist/src/plugin/google-search-tool.d.ts +9 -0
  169. package/dist/src/plugin/google-search-tool.d.ts.map +1 -0
  170. package/dist/src/plugin/google-search-tool.js +56 -0
  171. package/dist/src/plugin/google-search-tool.js.map +1 -0
  172. package/dist/src/plugin/image-saver.d.ts.map +1 -1
  173. package/dist/src/plugin/image-saver.js +16 -16
  174. package/dist/src/plugin/image-saver.js.map +1 -1
  175. package/dist/src/plugin/index.d.ts +30 -0
  176. package/dist/src/plugin/index.d.ts.map +1 -0
  177. package/dist/src/plugin/index.js +411 -0
  178. package/dist/src/plugin/index.js.map +1 -0
  179. package/dist/src/plugin/killswitch.d.ts +94 -0
  180. package/dist/src/plugin/killswitch.d.ts.map +1 -0
  181. package/dist/src/plugin/killswitch.js +197 -0
  182. package/dist/src/plugin/killswitch.js.map +1 -0
  183. package/dist/src/plugin/lifecycle.d.ts +40 -0
  184. package/dist/src/plugin/lifecycle.d.ts.map +1 -0
  185. package/dist/src/plugin/lifecycle.js +73 -0
  186. package/dist/src/plugin/lifecycle.js.map +1 -0
  187. package/dist/src/plugin/logger.d.ts +10 -1
  188. package/dist/src/plugin/logger.d.ts.map +1 -1
  189. package/dist/src/plugin/logger.js +38 -12
  190. package/dist/src/plugin/logger.js.map +1 -1
  191. package/dist/src/plugin/logging-utils.d.ts +35 -1
  192. package/dist/src/plugin/logging-utils.d.ts.map +1 -1
  193. package/dist/src/plugin/logging-utils.js +98 -15
  194. package/dist/src/plugin/logging-utils.js.map +1 -1
  195. package/dist/src/plugin/model-registry.d.ts +1 -1
  196. package/dist/src/plugin/model-registry.js +1 -1
  197. package/dist/src/plugin/oauth-login.d.ts +22 -0
  198. package/dist/src/plugin/oauth-login.d.ts.map +1 -0
  199. package/dist/src/plugin/oauth-login.js +37 -0
  200. package/dist/src/plugin/oauth-login.js.map +1 -0
  201. package/dist/src/plugin/oauth-methods.d.ts +42 -0
  202. package/dist/src/plugin/oauth-methods.d.ts.map +1 -0
  203. package/dist/src/plugin/oauth-methods.js +1276 -0
  204. package/dist/src/plugin/oauth-methods.js.map +1 -0
  205. package/dist/src/plugin/operator-settings.d.ts +40 -0
  206. package/dist/src/plugin/operator-settings.d.ts.map +1 -0
  207. package/dist/src/plugin/operator-settings.js +148 -0
  208. package/dist/src/plugin/operator-settings.js.map +1 -0
  209. package/dist/src/plugin/persist-account-pool.d.ts +37 -0
  210. package/dist/src/plugin/persist-account-pool.d.ts.map +1 -0
  211. package/dist/src/plugin/persist-account-pool.js +142 -0
  212. package/dist/src/plugin/persist-account-pool.js.map +1 -0
  213. package/dist/src/plugin/project.d.ts +1 -1
  214. package/dist/src/plugin/project.js +1 -1
  215. package/dist/src/plugin/prompt-context.d.ts.map +1 -1
  216. package/dist/src/plugin/prompt-context.js +11 -11
  217. package/dist/src/plugin/prompt-context.js.map +1 -1
  218. package/dist/src/plugin/quota.d.ts +138 -41
  219. package/dist/src/plugin/quota.d.ts.map +1 -1
  220. package/dist/src/plugin/quota.js +417 -285
  221. package/dist/src/plugin/quota.js.map +1 -1
  222. package/dist/src/plugin/recovery/constants.d.ts.map +1 -1
  223. package/dist/src/plugin/recovery/constants.js +24 -15
  224. package/dist/src/plugin/recovery/constants.js.map +1 -1
  225. package/dist/src/plugin/recovery/index.d.ts +3 -3
  226. package/dist/src/plugin/recovery/index.d.ts.map +1 -1
  227. package/dist/src/plugin/recovery/index.js +3 -3
  228. package/dist/src/plugin/recovery/index.js.map +1 -1
  229. package/dist/src/plugin/recovery/storage.d.ts +1 -1
  230. package/dist/src/plugin/recovery/storage.d.ts.map +1 -1
  231. package/dist/src/plugin/recovery/storage.js +31 -39
  232. package/dist/src/plugin/recovery/storage.js.map +1 -1
  233. package/dist/src/plugin/recovery/types.d.ts +12 -12
  234. package/dist/src/plugin/recovery/types.d.ts.map +1 -1
  235. package/dist/src/plugin/recovery.d.ts +3 -3
  236. package/dist/src/plugin/recovery.d.ts.map +1 -1
  237. package/dist/src/plugin/recovery.js +62 -58
  238. package/dist/src/plugin/recovery.js.map +1 -1
  239. package/dist/src/plugin/refresh-queue.d.ts +5 -2
  240. package/dist/src/plugin/refresh-queue.d.ts.map +1 -1
  241. package/dist/src/plugin/refresh-queue.js +37 -15
  242. package/dist/src/plugin/refresh-queue.js.map +1 -1
  243. package/dist/src/plugin/request-helpers.d.ts +1 -1
  244. package/dist/src/plugin/request-helpers.d.ts.map +1 -1
  245. package/dist/src/plugin/request-helpers.js +451 -352
  246. package/dist/src/plugin/request-helpers.js.map +1 -1
  247. package/dist/src/plugin/request.d.ts +7 -7
  248. package/dist/src/plugin/request.d.ts.map +1 -1
  249. package/dist/src/plugin/request.js +622 -384
  250. package/dist/src/plugin/request.js.map +1 -1
  251. package/dist/src/plugin/rotation.d.ts +1 -168
  252. package/dist/src/plugin/rotation.d.ts.map +1 -1
  253. package/dist/src/plugin/rotation.js +1 -327
  254. package/dist/src/plugin/rotation.js.map +1 -1
  255. package/dist/src/plugin/search.d.ts.map +1 -1
  256. package/dist/src/plugin/search.js +39 -35
  257. package/dist/src/plugin/search.js.map +1 -1
  258. package/dist/src/plugin/server.d.ts +1 -1
  259. package/dist/src/plugin/server.d.ts.map +1 -1
  260. package/dist/src/plugin/server.js +42 -37
  261. package/dist/src/plugin/server.js.map +1 -1
  262. package/dist/src/plugin/session-context.d.ts +2 -1
  263. package/dist/src/plugin/session-context.d.ts.map +1 -1
  264. package/dist/src/plugin/session-context.js +11 -7
  265. package/dist/src/plugin/session-context.js.map +1 -1
  266. package/dist/src/plugin/storage.d.ts +59 -120
  267. package/dist/src/plugin/storage.d.ts.map +1 -1
  268. package/dist/src/plugin/storage.js +140 -485
  269. package/dist/src/plugin/storage.js.map +1 -1
  270. package/dist/src/plugin/stores/signature-store.d.ts.map +1 -1
  271. package/dist/src/plugin/stores/signature-store.js.map +1 -1
  272. package/dist/src/plugin/thinking-recovery.d.ts.map +1 -1
  273. package/dist/src/plugin/thinking-recovery.js +35 -33
  274. package/dist/src/plugin/thinking-recovery.js.map +1 -1
  275. package/dist/src/plugin/token.d.ts +2 -2
  276. package/dist/src/plugin/token.d.ts.map +1 -1
  277. package/dist/src/plugin/token.js +30 -21
  278. package/dist/src/plugin/token.js.map +1 -1
  279. package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +1 -1
  280. package/dist/src/plugin/transform/cross-model-sanitizer.js +1 -1
  281. package/dist/src/plugin/transform/index.d.ts +1 -1
  282. package/dist/src/plugin/transform/index.js +1 -1
  283. package/dist/src/plugin/transform/model-resolver.d.ts +1 -1
  284. package/dist/src/plugin/transform/model-resolver.js +1 -1
  285. package/dist/src/plugin/transform/types.d.ts +1 -1
  286. package/dist/src/plugin/transform/types.js +1 -1
  287. package/dist/src/plugin/types.d.ts +25 -69
  288. package/dist/src/plugin/types.d.ts.map +1 -1
  289. package/dist/src/plugin/ui/ansi.d.ts.map +1 -1
  290. package/dist/src/plugin/ui/ansi.js.map +1 -1
  291. package/dist/src/plugin/ui/auth-menu.d.ts +1 -1
  292. package/dist/src/plugin/ui/auth-menu.d.ts.map +1 -1
  293. package/dist/src/plugin/ui/auth-menu.js +84 -35
  294. package/dist/src/plugin/ui/auth-menu.js.map +1 -1
  295. package/dist/src/plugin/ui/confirm.d.ts.map +1 -1
  296. package/dist/src/plugin/ui/confirm.js.map +1 -1
  297. package/dist/src/plugin/ui/model-status.d.ts +3 -3
  298. package/dist/src/plugin/ui/model-status.d.ts.map +1 -1
  299. package/dist/src/plugin/ui/model-status.js +3 -3
  300. package/dist/src/plugin/ui/model-status.js.map +1 -1
  301. package/dist/src/plugin/ui/quota-status.d.ts +4 -4
  302. package/dist/src/plugin/ui/quota-status.d.ts.map +1 -1
  303. package/dist/src/plugin/ui/quota-status.js +49 -49
  304. package/dist/src/plugin/ui/quota-status.js.map +1 -1
  305. package/dist/src/plugin/ui/select.d.ts.map +1 -1
  306. package/dist/src/plugin/ui/select.js +22 -12
  307. package/dist/src/plugin/ui/select.js.map +1 -1
  308. package/dist/src/plugin/version.d.ts +1 -1
  309. package/dist/src/plugin/version.js +1 -1
  310. package/dist/src/rpc/notifications.d.ts +6 -0
  311. package/dist/src/rpc/notifications.d.ts.map +1 -0
  312. package/dist/src/rpc/notifications.js +46 -0
  313. package/dist/src/rpc/notifications.js.map +1 -0
  314. package/dist/src/rpc/port-file.d.ts +13 -0
  315. package/dist/src/rpc/port-file.d.ts.map +1 -0
  316. package/dist/src/rpc/port-file.js +109 -0
  317. package/dist/src/rpc/port-file.js.map +1 -0
  318. package/dist/src/rpc/protocol.d.ts +22 -0
  319. package/dist/src/rpc/protocol.d.ts.map +1 -0
  320. package/dist/src/rpc/protocol.js +1 -0
  321. package/dist/src/rpc/protocol.js.map +1 -0
  322. package/dist/src/rpc/rpc-client.d.ts +10 -0
  323. package/dist/src/rpc/rpc-client.d.ts.map +1 -0
  324. package/dist/src/rpc/rpc-client.js +58 -0
  325. package/dist/src/rpc/rpc-client.js.map +1 -0
  326. package/dist/src/rpc/rpc-dir.d.ts +4 -0
  327. package/dist/src/rpc/rpc-dir.d.ts.map +1 -0
  328. package/dist/src/rpc/rpc-dir.js +19 -0
  329. package/dist/src/rpc/rpc-dir.js.map +1 -0
  330. package/dist/src/rpc/rpc-server.d.ts +13 -0
  331. package/dist/src/rpc/rpc-server.d.ts.map +1 -0
  332. package/dist/src/rpc/rpc-server.js +231 -0
  333. package/dist/src/rpc/rpc-server.js.map +1 -0
  334. package/dist/src/sidebar-state.d.ts +357 -0
  335. package/dist/src/sidebar-state.d.ts.map +1 -0
  336. package/dist/src/sidebar-state.js +680 -0
  337. package/dist/src/sidebar-state.js.map +1 -0
  338. package/dist/src/tui/command-dialogs.d.ts +61 -0
  339. package/dist/src/tui/command-dialogs.d.ts.map +1 -0
  340. package/dist/src/tui/command-dialogs.js +595 -0
  341. package/dist/src/tui/command-dialogs.js.map +1 -0
  342. package/dist/src/tui/file-logger.d.ts +41 -0
  343. package/dist/src/tui/file-logger.d.ts.map +1 -0
  344. package/dist/src/tui/file-logger.js +114 -0
  345. package/dist/src/tui/file-logger.js.map +1 -0
  346. package/dist/src/tui-preferences.d.ts +40 -0
  347. package/dist/src/tui-preferences.d.ts.map +1 -0
  348. package/dist/src/tui-preferences.js +328 -0
  349. package/dist/src/tui-preferences.js.map +1 -0
  350. package/dist/src/tui.d.ts +68 -0
  351. package/dist/src/tui.d.ts.map +1 -0
  352. package/dist/src/tui.js +697 -0
  353. package/dist/src/tui.js.map +1 -0
  354. package/package.json +46 -22
  355. package/src/plugin/command-data.ts +931 -0
  356. package/src/rpc/port-file.ts +143 -0
  357. package/src/rpc/protocol.ts +31 -0
  358. package/src/rpc/rpc-client.ts +102 -0
  359. package/src/rpc/rpc-dir.ts +24 -0
  360. package/src/sidebar-state.ts +991 -0
  361. package/src/tui/command-dialogs.tsx +832 -0
  362. package/src/tui/entry.mjs +74 -0
  363. package/src/tui/file-logger.ts +145 -0
  364. package/src/tui-compiled/plugin/command-data.ts +931 -0
  365. package/src/tui-compiled/rpc/port-file.ts +143 -0
  366. package/src/tui-compiled/rpc/protocol.ts +31 -0
  367. package/src/tui-compiled/rpc/rpc-client.ts +102 -0
  368. package/src/tui-compiled/rpc/rpc-dir.ts +24 -0
  369. package/src/tui-compiled/sidebar-state.ts +991 -0
  370. package/src/tui-compiled/tui/command-dialogs.tsx +779 -0
  371. package/src/tui-compiled/tui/file-logger.ts +145 -0
  372. package/src/tui-compiled/tui-preferences.ts +416 -0
  373. package/src/tui-compiled/tui.tsx +1193 -0
  374. package/src/tui-preferences.ts +416 -0
  375. package/src/tui.tsx +1171 -0
  376. package/dist/src/plugin.d.ts +0 -48
  377. package/dist/src/plugin.d.ts.map +0 -1
  378. package/dist/src/plugin.js +0 -3311
  379. package/dist/src/plugin.js.map +0 -1
@@ -0,0 +1,746 @@
1
+ /**
2
+ * Slash-command wiring for the antigravity plugin.
3
+ *
4
+ * Three places must agree on the set of modal commands — keeping
5
+ * them in lockstep is a hard invariant:
6
+ *
7
+ * 1. `MODAL_COMMANDS` — the canonical list of `CommandModalName`s.
8
+ * 2. `registerAntigravityCommands` (in `./catalog.ts`) — what we
9
+ * register in the host `config.command.*` map so OpenCode
10
+ * recognises them.
11
+ * 3. `buildDialogPayload` (here) — the per-command dialog payload
12
+ * builder the TUI renders when a notification arrives.
13
+ *
14
+ * If any one drifts, a future slash command will be discoverable in
15
+ * the host palette but invisible to the dialog flow (or vice versa).
16
+ * The bidirectional three-wiring test pins this invariant.
17
+ *
18
+ * `/gemini-dump` remains a backward-compatibility alias: the host
19
+ * already registers the command under that name in `OpenCode` and
20
+ * long-running sessions may still call it. The modal name
21
+ * `antigravity-dump` is the canonical name; both stay registered.
22
+ */
23
+ import { isTuiConnected as defaultIsTuiConnected } from '../rpc/notifications';
24
+ import { buildSidebarMachineStateFromAccounts, setSidebarMachineState, } from '../sidebar-state';
25
+ import { executeGeminiDumpCommand, GEMINI_DUMP_COMMAND_NAME, parseGeminiDumpCommandAction, setGeminiDumpEnabled, } from './gemini-dump';
26
+ import { createLogger } from './logger';
27
+ import { createOperatorSettingsController, } from './operator-settings';
28
+ import { resolvePromptContext } from './prompt-context';
29
+ import { AccountStorageUnreadableError } from './storage';
30
+ const log = createLogger('commands');
31
+ export const ANTIGRAVITY_QUOTA_COMMAND_NAME = 'antigravity-quota';
32
+ export const ANTIGRAVITY_ACCOUNT_COMMAND_NAME = 'antigravity-account';
33
+ export const ANTIGRAVITY_ROUTING_COMMAND_NAME = 'antigravity-routing';
34
+ export const ANTIGRAVITY_KILLSWITCH_COMMAND_NAME = 'antigravity-killswitch';
35
+ export const ANTIGRAVITY_DUMP_COMMAND_NAME = 'antigravity-dump';
36
+ export const ANTIGRAVITY_LOGGING_COMMAND_NAME = 'antigravity-logging';
37
+ export const MODAL_COMMANDS = [
38
+ ANTIGRAVITY_QUOTA_COMMAND_NAME,
39
+ ANTIGRAVITY_ACCOUNT_COMMAND_NAME,
40
+ ANTIGRAVITY_ROUTING_COMMAND_NAME,
41
+ ANTIGRAVITY_KILLSWITCH_COMMAND_NAME,
42
+ ANTIGRAVITY_DUMP_COMMAND_NAME,
43
+ ANTIGRAVITY_LOGGING_COMMAND_NAME,
44
+ ];
45
+ const HANDLED_COMMAND_SENTINEL = 'ANTIGRAVITY_COMMAND_HANDLED';
46
+ async function sendIgnoredMessage(client, sessionID, text) {
47
+ const session = client.session;
48
+ const promptContext = await resolvePromptContext(client, sessionID);
49
+ const request = {
50
+ path: { id: sessionID },
51
+ body: {
52
+ noReply: true,
53
+ parts: [{ type: 'text', text, ignored: true }],
54
+ ...(promptContext?.agent ? { agent: promptContext.agent } : {}),
55
+ ...(promptContext?.model ? { model: promptContext.model } : {}),
56
+ ...(promptContext?.variant ? { variant: promptContext.variant } : {}),
57
+ },
58
+ };
59
+ if (typeof session?.promptAsync === 'function') {
60
+ await session.promptAsync(request);
61
+ return;
62
+ }
63
+ if (typeof session?.prompt === 'function') {
64
+ await Promise.resolve(session.prompt(request));
65
+ return;
66
+ }
67
+ throw new Error('OpenCode session prompt API is unavailable for ignored replies.');
68
+ }
69
+ function throwHandledCommandSentinel() {
70
+ throw new Error(HANDLED_COMMAND_SENTINEL);
71
+ }
72
+ /**
73
+ * Build the dialog payload the TUI renders for `command`.
74
+ *
75
+ * Each branch produces a self-contained payload the OpenTUI dialog tree
76
+ * can mount without further RPC chatter. The knobs object is the
77
+ * payload-specific metadata (current toggle state, available actions,
78
+ * default values) — knobs are intentionally stringly-typed to keep the
79
+ * dialog code free of per-command schema definitions.
80
+ */
81
+ export async function buildDialogPayload(command, argumentsText, context) {
82
+ switch (command) {
83
+ case 'antigravity-quota': {
84
+ const action = argumentsText.trim().toLowerCase();
85
+ const accounts = context.commandData
86
+ ? await context.commandData.listAccounts()
87
+ : [];
88
+ // Render the cached snapshot immediately. Opening the dialog is a
89
+ // VIEW — it must respect the quota manager's per-account backoff so
90
+ // a rate-limited account isn't hammered every time the dialog opens.
91
+ // Explicit user-triggered refreshes (inside the dialog) keep force:true.
92
+ if (context.commandData) {
93
+ void context.commandData.refreshQuotaRespectingBackoff().catch(() => { });
94
+ }
95
+ return {
96
+ command,
97
+ text: 'Antigravity quota',
98
+ knobs: {
99
+ mode: action === 'refresh' ? 'refresh' : 'status',
100
+ accounts,
101
+ },
102
+ };
103
+ }
104
+ case 'antigravity-account': {
105
+ const action = argumentsText.trim().toLowerCase();
106
+ const accounts = context.commandData
107
+ ? await context.commandData.listAccounts()
108
+ : [];
109
+ return {
110
+ command,
111
+ text: 'Antigravity accounts',
112
+ knobs: {
113
+ action: action === 'add' ||
114
+ action === 'refresh' ||
115
+ action === 'remove' ||
116
+ action === 'list'
117
+ ? action
118
+ : 'list',
119
+ accounts,
120
+ },
121
+ };
122
+ }
123
+ case 'antigravity-routing': {
124
+ const settings = context.settings.get();
125
+ const parsed = parseToggleArguments(argumentsText);
126
+ // State-first: the opening payload reports the CURRENT persisted
127
+ // values (no `!` inversion). Argument overrides still flow through
128
+ // so the slash-command-direct path can pre-stage a value, but the
129
+ // fallback when no argument is provided is the actual current
130
+ // state, not its negation. The apply handler returns the complete
131
+ // post-mutation state in `knobs` so the dialog re-renders from
132
+ // the same shape it was opened with.
133
+ return {
134
+ command,
135
+ text: 'Antigravity routing',
136
+ knobs: {
137
+ cli_first: parsed.cli_first ?? settings.routing.cli_first,
138
+ quota_style_fallback: parsed.quota_style_fallback ??
139
+ settings.routing.quota_style_fallback,
140
+ timeoutMs: 2_000,
141
+ },
142
+ };
143
+ }
144
+ case 'antigravity-killswitch': {
145
+ const settings = context.settings.get();
146
+ const parsed = parseKillswitchArguments(argumentsText);
147
+ // State-first: opening reports the current killswitch shape
148
+ // (`enabled`, `minimum_remaining_percent`, plus the full
149
+ // per-account override map if any keys exist). Argument overrides
150
+ // are honored so the slash-command-direct path stays explicit.
151
+ return {
152
+ command,
153
+ text: 'Antigravity killswitch',
154
+ knobs: {
155
+ enabled: parsed.enabled ?? settings.killswitch.enabled,
156
+ minimum_remaining_percent: parsed.minimum_remaining_percent ??
157
+ settings.killswitch.minimum_remaining_percent,
158
+ accounts: settings.killswitch.accounts ?? {},
159
+ timeoutMs: 2_000,
160
+ },
161
+ };
162
+ }
163
+ case 'antigravity-dump': {
164
+ const action = parseGeminiDumpCommandAction(argumentsText);
165
+ return {
166
+ command,
167
+ text: 'Antigravity wire dump',
168
+ knobs: {
169
+ mode: action.type === 'usage' ? 'status' : action.type,
170
+ },
171
+ };
172
+ }
173
+ case 'antigravity-logging': {
174
+ const level = parseLoggingLevel(argumentsText);
175
+ return {
176
+ command,
177
+ text: 'Antigravity logging',
178
+ knobs: { log_level: level },
179
+ };
180
+ }
181
+ default: {
182
+ const exhaustiveCheck = command;
183
+ throw new Error(`Unknown command ${exhaustiveCheck}`);
184
+ }
185
+ }
186
+ }
187
+ function parseToggleArguments(input) {
188
+ const result = {};
189
+ for (const part of input.split(/\s+/).filter(Boolean)) {
190
+ const eq = part.indexOf('=');
191
+ if (eq < 0)
192
+ continue;
193
+ const key = part.slice(0, eq).trim().toLowerCase();
194
+ const value = part
195
+ .slice(eq + 1)
196
+ .trim()
197
+ .toLowerCase();
198
+ if (key === 'cli_first' || key === 'cli-first') {
199
+ result.cli_first = value === 'true' || value === '1' || value === 'on';
200
+ }
201
+ else if (key === 'quota_style_fallback' ||
202
+ key === 'quota-style-fallback') {
203
+ result.quota_style_fallback =
204
+ value === 'true' || value === '1' || value === 'on';
205
+ }
206
+ }
207
+ return result;
208
+ }
209
+ function parseKillswitchArguments(input) {
210
+ const result = {};
211
+ for (const part of input.split(/\s+/).filter(Boolean)) {
212
+ const eq = part.indexOf('=');
213
+ if (eq < 0)
214
+ continue;
215
+ const key = part.slice(0, eq).trim().toLowerCase();
216
+ const value = part
217
+ .slice(eq + 1)
218
+ .trim()
219
+ .toLowerCase();
220
+ if (key === 'enabled') {
221
+ result.enabled = value === 'true' || value === '1' || value === 'on';
222
+ }
223
+ else if (key === 'minimum_remaining_percent' ||
224
+ key === 'minimum-remaining-percent') {
225
+ const n = Number.parseFloat(value);
226
+ if (!Number.isNaN(n) && n >= 0 && n <= 100) {
227
+ result.minimum_remaining_percent = n;
228
+ }
229
+ }
230
+ }
231
+ return result;
232
+ }
233
+ function parseLoggingLevel(input) {
234
+ const trimmed = input.trim().toLowerCase();
235
+ if (trimmed === 'error' ||
236
+ trimmed === 'warn' ||
237
+ trimmed === 'info' ||
238
+ trimmed === 'debug' ||
239
+ trimmed === 'trace') {
240
+ return trimmed;
241
+ }
242
+ return 'info';
243
+ }
244
+ /**
245
+ * Parse the slash-command apply argument for `/antigravity-account`.
246
+ *
247
+ * Recognized forms:
248
+ * `<empty>` → `{ kind: 'refresh' }` (keeps the original
249
+ * "manage → refresh" placeholder semantics)
250
+ * `add` → `{ kind: 'add' }`
251
+ * `refresh` → `{ kind: 'refresh' }`
252
+ * `current <n>` → `{ kind: 'current', index: n }`
253
+ * `toggle <n>` → `{ kind: 'toggle', index: n }`
254
+ * `remove <n>` → `{ kind: 'remove', index: n }`
255
+ *
256
+ * `n` is the transient `acct-<index>` position the dialog renders.
257
+ * Negative or non-integer values are rejected; out-of-range indices
258
+ * are accepted here and rejected by the data service so the dialog
259
+ * can surface the error text.
260
+ */
261
+ function parseAccountAction(input) {
262
+ const trimmed = input.trim();
263
+ if (!trimmed)
264
+ return { kind: 'refresh' };
265
+ const parts = trimmed.split(/\s+/).filter(Boolean);
266
+ const head = parts[0]?.toLowerCase();
267
+ if (head === 'add')
268
+ return { kind: 'add' };
269
+ if (head === 'add-oauth-start' && parts.length === 1) {
270
+ return { kind: 'add-oauth-start' };
271
+ }
272
+ if (head === 'add-oauth-finish') {
273
+ const code = parts[1];
274
+ if (!code)
275
+ return undefined;
276
+ const labelAt = parts.indexOf('--label');
277
+ const label = labelAt === -1
278
+ ? undefined
279
+ : parts
280
+ .slice(labelAt + 1)
281
+ .join(' ')
282
+ .trim();
283
+ return { kind: 'add-oauth-finish', code, label: label || undefined };
284
+ }
285
+ if (head === 'refresh')
286
+ return { kind: 'refresh' };
287
+ if (head === 'current' || head === 'toggle' || head === 'remove') {
288
+ const raw = parts[1];
289
+ if (raw === undefined)
290
+ return undefined;
291
+ const index = Number.parseInt(raw, 10);
292
+ if (!Number.isInteger(index) || index < 0)
293
+ return undefined;
294
+ return { kind: head, index };
295
+ }
296
+ return undefined;
297
+ }
298
+ /**
299
+ * Apply the result of a TUI dialog back to the plugin runtime.
300
+ *
301
+ * Most commands mutate persistent operator settings (routing toggles,
302
+ * killswitch thresholds, log level). Account add/refresh kicks off the
303
+ * OAuth flow which can take up to two minutes on a fresh login — that
304
+ * path opts into a 120s RPC timeout. Status / toggle paths keep the
305
+ * default 2s timeout.
306
+ *
307
+ * The TUI's imperative dispatcher (`tui/command-dialogs.openCommandDialog`)
308
+ * forwards the apply `options.timeoutMs` knob into the RPC apply call
309
+ * so a long-running path (account add / refresh) can opt in without the
310
+ * dialog layer having to special-case it.
311
+ */
312
+ export async function applyCommand(request, context) {
313
+ const result = await applyCommandInner(request, context);
314
+ // Push a sidebar refresh after every mutation so the TUI's next poll
315
+ // sees a fresh `checkedAt`. The refresher is optional; tests and
316
+ // read-only contexts leave it undefined and skip the write entirely.
317
+ if (context.onApplied) {
318
+ const accounts = result.knobs.accounts;
319
+ await Promise.resolve(context.onApplied(Array.isArray(accounts) ? accounts : undefined)).catch(() => {
320
+ // Sidebar refresh must never break the command's apply response.
321
+ });
322
+ }
323
+ return result;
324
+ }
325
+ async function runAccountMutation(context, call) {
326
+ if (!context.commandData) {
327
+ return {
328
+ kind: 'error',
329
+ text: 'Command data service is not wired; account mutations are disabled.',
330
+ };
331
+ }
332
+ try {
333
+ const rows = await call();
334
+ if (rows == null)
335
+ return { kind: 'not-found' };
336
+ return { kind: 'rows', rows };
337
+ }
338
+ catch (error) {
339
+ if (error instanceof AccountStorageUnreadableError) {
340
+ log.warn('account mutation: locked storage is unreadable', {
341
+ error: error.message,
342
+ });
343
+ return {
344
+ kind: 'error',
345
+ text: `Account storage is unreadable: ${error.details.reason}. The mutation was not applied.`,
346
+ };
347
+ }
348
+ const message = error instanceof Error ? error.message : String(error);
349
+ log.warn('account mutation failed', { error: message });
350
+ return {
351
+ kind: 'error',
352
+ text: `Account mutation failed: ${message}`,
353
+ };
354
+ }
355
+ }
356
+ function notFoundResult(verb, index) {
357
+ return {
358
+ text: `Cannot ${verb}: account ${index} not found`,
359
+ knobs: { action: verb, timeoutMs: 2_000 },
360
+ };
361
+ }
362
+ function errorResult(verb, text) {
363
+ return {
364
+ text,
365
+ knobs: { action: verb, timeoutMs: 2_000, error: true },
366
+ };
367
+ }
368
+ async function applyCommandInner(request, context) {
369
+ switch (request.command) {
370
+ case 'antigravity-quota': {
371
+ // `refresh` is the only quota apply path; opening is cache-only
372
+ // via `listAccounts`. The data service forces the refresh and
373
+ // returns the freshly persisted rows so the dialog can re-render
374
+ // in place without a second RPC round-trip.
375
+ const accounts = context.commandData
376
+ ? await context.commandData.refreshQuota()
377
+ : [];
378
+ return {
379
+ text: 'Quota refreshed',
380
+ knobs: { accounts, timeoutMs: 2_000 },
381
+ };
382
+ }
383
+ case 'antigravity-account': {
384
+ const args = request.arguments.trim();
385
+ const parsed = parseAccountAction(args);
386
+ if (!parsed) {
387
+ return {
388
+ text: `Unknown account action: ${args}`,
389
+ knobs: { action: 'unknown', timeoutMs: 2_000 },
390
+ };
391
+ }
392
+ if (parsed.kind === 'add-oauth-start') {
393
+ if (!context.accountOAuth) {
394
+ return {
395
+ text: 'OAuth account add is unavailable.',
396
+ knobs: { timeoutMs: 120_000, error: true },
397
+ };
398
+ }
399
+ const result = await context.accountOAuth.start(context.sessionID);
400
+ return {
401
+ text: `Open this URL in your browser:\n${result.url}`,
402
+ knobs: {
403
+ oauthUrl: result.url,
404
+ accounts: result.accounts,
405
+ timeoutMs: 120_000,
406
+ },
407
+ };
408
+ }
409
+ if (parsed.kind === 'add-oauth-finish') {
410
+ if (!context.accountOAuth) {
411
+ return {
412
+ text: 'OAuth account add is unavailable.',
413
+ knobs: { timeoutMs: 120_000, error: true },
414
+ };
415
+ }
416
+ const result = parsed.label
417
+ ? await context.accountOAuth.finish(context.sessionID, parsed.code, parsed.label)
418
+ : await context.accountOAuth.finish(context.sessionID, parsed.code);
419
+ return {
420
+ text: result.text,
421
+ knobs: { accounts: result.accounts, timeoutMs: 120_000 },
422
+ };
423
+ }
424
+ // The data service drives the locked-storage mutator for the
425
+ // three CRUD mutations. The locked-storage write is awaited FIRST so a
426
+ // failed disk write never leaves the runtime ahead of disk. When
427
+ // that await throws — AccountStorageUnreadableError, lock
428
+ // contention, I/O — we catch here and surface the message as the
429
+ // apply's `text`. The dialog toasts that text and stays mounted
430
+ // (the `clear()` is gated on `apply returning rows`).
431
+ if (parsed.kind === 'current') {
432
+ const result = await runAccountMutation(context, () => context.commandData?.setCurrentAccount(parsed.index));
433
+ if (result.kind === 'not-found') {
434
+ return notFoundResult('set current', parsed.index);
435
+ }
436
+ if (result.kind === 'error') {
437
+ return errorResult('current', result.text);
438
+ }
439
+ return {
440
+ text: 'Current account updated',
441
+ knobs: {
442
+ accounts: result.rows,
443
+ action: 'current',
444
+ timeoutMs: 2_000,
445
+ },
446
+ };
447
+ }
448
+ if (parsed.kind === 'toggle') {
449
+ const result = await runAccountMutation(context, () => context.commandData?.toggleAccountEnabled(parsed.index));
450
+ if (result.kind === 'not-found') {
451
+ return notFoundResult('toggle', parsed.index);
452
+ }
453
+ if (result.kind === 'error') {
454
+ return errorResult('toggle', result.text);
455
+ }
456
+ return {
457
+ text: 'Account enabled state updated',
458
+ knobs: {
459
+ accounts: result.rows,
460
+ action: 'toggle',
461
+ timeoutMs: 2_000,
462
+ },
463
+ };
464
+ }
465
+ if (parsed.kind === 'remove') {
466
+ const result = await runAccountMutation(context, () => context.commandData?.removeAccount(parsed.index));
467
+ if (result.kind === 'not-found') {
468
+ return notFoundResult('remove', parsed.index);
469
+ }
470
+ if (result.kind === 'error') {
471
+ return errorResult('remove', result.text);
472
+ }
473
+ return {
474
+ text: 'Account removed',
475
+ knobs: {
476
+ accounts: result.rows,
477
+ action: 'remove',
478
+ timeoutMs: 2_000,
479
+ },
480
+ };
481
+ }
482
+ // `add` (and `refresh`) — backwards-compatible no-op response
483
+ // that keeps the 120s RPC timeout for the future OAuth path.
484
+ return {
485
+ text: `Account ${parsed.kind} requested`,
486
+ knobs: { action: parsed.kind, timeoutMs: 120_000 },
487
+ };
488
+ }
489
+ case 'antigravity-routing': {
490
+ const parsed = parseToggleArguments(request.arguments);
491
+ try {
492
+ await context.settings.update((draft) => {
493
+ if (parsed.cli_first !== undefined) {
494
+ draft.routing.cli_first = parsed.cli_first;
495
+ }
496
+ if (parsed.quota_style_fallback !== undefined) {
497
+ draft.routing.quota_style_fallback = parsed.quota_style_fallback;
498
+ }
499
+ });
500
+ }
501
+ catch (error) {
502
+ // Lock contention / unreadable config — surface the writer's
503
+ // message so the dialog can toast the real cause and stay
504
+ // mounted (T8/T10 pattern). The runtime view is left untouched
505
+ // because the writer either landed or threw.
506
+ const message = error instanceof Error ? error.message : String(error);
507
+ log.warn('routing update failed', { error: message });
508
+ return {
509
+ text: `Routing update failed: ${message}`,
510
+ knobs: { timeoutMs: 2_000, error: true },
511
+ };
512
+ }
513
+ // Complete persisted state — the dialog re-renders from the same
514
+ // shape `buildDialogPayload` produced on open.
515
+ const after = context.settings.get();
516
+ return {
517
+ text: 'Routing updated',
518
+ knobs: {
519
+ cli_first: after.routing.cli_first,
520
+ quota_style_fallback: after.routing.quota_style_fallback,
521
+ timeoutMs: 2_000,
522
+ },
523
+ };
524
+ }
525
+ case 'antigravity-killswitch': {
526
+ const parsed = parseKillswitchArguments(request.arguments);
527
+ try {
528
+ await context.settings.update((draft) => {
529
+ if (parsed.enabled !== undefined) {
530
+ draft.killswitch.enabled = parsed.enabled;
531
+ }
532
+ if (parsed.minimum_remaining_percent !== undefined) {
533
+ draft.killswitch.minimum_remaining_percent =
534
+ parsed.minimum_remaining_percent;
535
+ }
536
+ });
537
+ }
538
+ catch (error) {
539
+ const message = error instanceof Error ? error.message : String(error);
540
+ log.warn('killswitch update failed', { error: message });
541
+ return {
542
+ text: `Killswitch update failed: ${message}`,
543
+ knobs: { timeoutMs: 2_000, error: true },
544
+ };
545
+ }
546
+ // Complete persisted state — the dialog re-renders the full
547
+ // killswitch shape (enabled, threshold, per-account overrides).
548
+ const after = context.settings.get();
549
+ return {
550
+ text: 'Killswitch updated',
551
+ knobs: {
552
+ enabled: after.killswitch.enabled,
553
+ minimum_remaining_percent: after.killswitch.minimum_remaining_percent,
554
+ accounts: after.killswitch.accounts ?? {},
555
+ timeoutMs: 2_000,
556
+ },
557
+ };
558
+ }
559
+ case 'antigravity-dump': {
560
+ const action = parseGeminiDumpCommandAction(request.arguments);
561
+ if (action.type === 'enable')
562
+ setGeminiDumpEnabled(true);
563
+ else if (action.type === 'disable')
564
+ setGeminiDumpEnabled(false);
565
+ return {
566
+ text: executeGeminiDumpCommand({
567
+ argumentsText: request.arguments,
568
+ }),
569
+ knobs: { timeoutMs: 2_000 },
570
+ };
571
+ }
572
+ case 'antigravity-logging': {
573
+ const level = parseLoggingLevel(request.arguments);
574
+ await context.settings.update((draft) => {
575
+ draft.log_level = level;
576
+ });
577
+ return {
578
+ text: `Logging level set to ${level}`,
579
+ knobs: { log_level: level, timeoutMs: 2_000 },
580
+ };
581
+ }
582
+ default: {
583
+ const exhaustiveCheck = request.command;
584
+ throw new Error(`Unknown command ${exhaustiveCheck}`);
585
+ }
586
+ }
587
+ }
588
+ /**
589
+ * Build a sidebar refresher bound to the supplied account-snapshot provider.
590
+ * The plugin entry passes `lifecycle.getAccountManager()`'s snapshot getter so
591
+ * every `/antigravity-*` apply that mutates persistent state also bumps the
592
+ * sidebar's `checkedAt`. The refresher is best-effort: a lock-contention
593
+ * error or missing manager is swallowed by the caller.
594
+ */
595
+ export function createSidebarRefresher(getAccounts) {
596
+ return async (dialogAccounts) => {
597
+ // Live cooldown lookup keyed by numeric index — a best-effort
598
+ // fallback for rows projected before coolingDownUntil was
599
+ // added to CommandAccountRow. Rows now carry their own
600
+ // cooldown from projection time; the live map only fills in
601
+ // when the row value is absent.
602
+ const liveByIndex = new Map();
603
+ try {
604
+ const live = getAccounts();
605
+ if (live) {
606
+ for (const entry of live)
607
+ liveByIndex.set(entry.index, entry.coolingDownUntil);
608
+ }
609
+ }
610
+ catch {
611
+ // The live provider is best-effort; fall through with an empty
612
+ // map if the manager is gone.
613
+ }
614
+ const accounts = dialogAccounts
615
+ ? dialogAccounts.map((entry) => {
616
+ // Prefer the row's own cooldown — it was projected from the
617
+ // live view at the last projection and is stable regardless
618
+ // of concurrent reloads. Fall back to the live-by-index map
619
+ // only for legacy rows that lack the field entirely (?? can't
620
+ // distinguish absent from present-but-undefined).
621
+ const liveCooldown = 'coolingDownUntil' in entry
622
+ ? entry.coolingDownUntil
623
+ : liveByIndex.get(entry.index);
624
+ return {
625
+ index: entry.index,
626
+ label: entry.label,
627
+ enabled: entry.enabled,
628
+ current: entry.current,
629
+ coolingDownUntil: liveCooldown,
630
+ healthScore: entry.healthScore,
631
+ tier: entry.tier,
632
+ // Rebuild cachedQuota carrying the windows array so the sidebar
633
+ // doesn't collapse from per-window rows to a single aggregate bar
634
+ // after every apply. Mirrors the QuotaGroupSummary shape expected
635
+ // by projectQuotaPoolForSidebar inside buildSidebarMachineStateFromAccounts.
636
+ cachedQuota: Object.fromEntries(entry.quota.flatMap((group) => {
637
+ if (group.remainingPercent == null)
638
+ return [];
639
+ return [
640
+ [
641
+ group.key,
642
+ {
643
+ remainingFraction: group.remainingPercent / 100,
644
+ ...(group.resetAt === undefined
645
+ ? {}
646
+ : { resetTime: new Date(group.resetAt).toISOString() }),
647
+ ...(group.windows && group.windows.length > 0
648
+ ? {
649
+ windows: group.windows.map((w) => ({
650
+ window: w.window,
651
+ remainingFraction: w.remainingPercent / 100,
652
+ resetTime: typeof w.resetAt === 'number' &&
653
+ Number.isFinite(w.resetAt)
654
+ ? new Date(w.resetAt).toISOString()
655
+ : '',
656
+ })),
657
+ }
658
+ : {}),
659
+ },
660
+ ],
661
+ ];
662
+ })),
663
+ };
664
+ })
665
+ : getAccounts();
666
+ if (!accounts || accounts.length === 0)
667
+ return;
668
+ try {
669
+ // Pass the already-projected accounts directly so every field the
670
+ // intermediate map built (healthScore, cachedQuota with windows, ...)
671
+ // reaches the redactor unchanged. A second .map here would silently
672
+ // drop any field not explicitly forwarded -- that is the class of
673
+ // defect this cast prevents.
674
+ await setSidebarMachineState(buildSidebarMachineStateFromAccounts(accounts));
675
+ }
676
+ catch {
677
+ // Sidebar refresh is best-effort; the next command or quota refresh
678
+ // will publish the current account snapshot.
679
+ }
680
+ };
681
+ }
682
+ /**
683
+ * Hook the host's `command.execute.before` to the modal commands.
684
+ *
685
+ * When a slash command is invoked, we push a notification onto the
686
+ * RPC queue and abort the normal prompt with the same handled
687
+ * sentinel the legacy `/gemini-dump` flow already uses.
688
+ *
689
+ * The `sendIgnoredMessage` fallback only fires when no TUI is
690
+ * listening — the only path that actually consumes the queued
691
+ * message. With a live TUI, push alone is enough; double-sending
692
+ * would otherwise render the command text as a visible chat message
693
+ * alongside the dialog the TUI renders.
694
+ */
695
+ export function createCommandExecuteBefore(client, settings, pushNotification, commandData, connectionState = {
696
+ isTuiConnected: defaultIsTuiConnected,
697
+ }) {
698
+ const context = {
699
+ client,
700
+ sessionID: '',
701
+ settings,
702
+ commandData,
703
+ };
704
+ return async (input) => {
705
+ const command = input.command;
706
+ if (command === GEMINI_DUMP_COMMAND_NAME) {
707
+ const action = parseGeminiDumpCommandAction(input.arguments);
708
+ if (action.type === 'enable' || action.type === 'disable') {
709
+ setGeminiDumpEnabled(action.type === 'enable');
710
+ }
711
+ if (!connectionState.isTuiConnected(input.sessionID)) {
712
+ await sendIgnoredMessage(client, input.sessionID, executeGeminiDumpCommand({ argumentsText: input.arguments }));
713
+ }
714
+ throwHandledCommandSentinel();
715
+ }
716
+ if (command !== ANTIGRAVITY_QUOTA_COMMAND_NAME &&
717
+ command !== ANTIGRAVITY_ACCOUNT_COMMAND_NAME &&
718
+ command !== ANTIGRAVITY_ROUTING_COMMAND_NAME &&
719
+ command !== ANTIGRAVITY_KILLSWITCH_COMMAND_NAME &&
720
+ command !== ANTIGRAVITY_DUMP_COMMAND_NAME &&
721
+ command !== ANTIGRAVITY_LOGGING_COMMAND_NAME) {
722
+ return;
723
+ }
724
+ const payload = await buildDialogPayload(command, input.arguments, {
725
+ ...context,
726
+ sessionID: input.sessionID,
727
+ });
728
+ pushNotification(payload, input.sessionID);
729
+ if (!connectionState.isTuiConnected(input.sessionID)) {
730
+ await sendIgnoredMessage(client, input.sessionID, payload.text);
731
+ }
732
+ throwHandledCommandSentinel();
733
+ };
734
+ }
735
+ /**
736
+ * Backward-compat wrapper that constructs a no-settings `command.execute.before`
737
+ * for tests that don't care about the operator settings controller. Production
738
+ * code wires the real controller via `createAntigravityPlugin`.
739
+ */
740
+ export function createCommandExecuteBeforeForClient(client, commandData) {
741
+ return createCommandExecuteBefore(client, createOperatorSettingsController({
742
+ projectConfigPath: '/dev/null',
743
+ userConfigPath: '/dev/null',
744
+ }), () => undefined, commandData);
745
+ }
746
+ //# sourceMappingURL=commands.js.map