@cortexkit/opencode-antigravity-auth 3.0.5 → 3.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (422) hide show
  1. package/README.md +38 -352
  2. package/dist/cli.js +13757 -12857
  3. package/dist/cli.js.map +4 -4
  4. package/dist/cli.meta.json +1362 -1056
  5. package/dist/index.js +16038 -16162
  6. package/dist/index.js.map +4 -4
  7. package/dist/index.meta.json +1447 -1375
  8. package/dist/server.js +11254 -10921
  9. package/dist/server.js.map +4 -4
  10. package/dist/server.meta.json +1 -1
  11. package/dist/src/auth-method-labels.d.ts +3 -0
  12. package/dist/src/auth-method-labels.d.ts.map +1 -0
  13. package/dist/src/auth-method-labels.js +5 -0
  14. package/dist/src/auth-method-labels.js.map +1 -0
  15. package/dist/src/cli.d.ts +3 -1
  16. package/dist/src/cli.d.ts.map +1 -1
  17. package/dist/src/cli.js +98 -12
  18. package/dist/src/cli.js.map +1 -1
  19. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +44 -4
  20. package/dist/src/common-auth-embedded/claustrum/consumer.js +134 -2
  21. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +33 -1
  22. package/dist/src/common-auth-embedded/claustrum/custody.js +17 -0
  23. package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +6 -1
  24. package/dist/src/common-auth-embedded/claustrum/enrollment.js +6 -1
  25. package/dist/src/common-auth-embedded/claustrum/index.d.ts +3 -2
  26. package/dist/src/common-auth-embedded/claustrum/index.js +5 -3
  27. package/dist/src/common-auth-embedded/claustrum/insula.d.ts +69 -0
  28. package/dist/src/common-auth-embedded/claustrum/insula.js +152 -0
  29. package/dist/src/common-auth-embedded/claustrum/roster.d.ts +13 -0
  30. package/dist/src/common-auth-embedded/claustrum/roster.js +33 -3
  31. package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
  32. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +26 -12
  33. package/dist/src/common-auth-embedded/pi-slot/lock.js +7 -3
  34. package/dist/src/common-auth-embedded/quota/codec.d.ts +2 -0
  35. package/dist/src/common-auth-embedded/quota/codec.js +2 -1
  36. package/dist/src/common-auth-embedded/quota/format.d.ts +40 -3
  37. package/dist/src/common-auth-embedded/quota/format.js +196 -43
  38. package/dist/src/common-auth-embedded/quota/index.d.ts +4 -4
  39. package/dist/src/common-auth-embedded/quota/index.js +2 -2
  40. package/dist/src/common-auth-embedded/quota/map.d.ts +11 -0
  41. package/dist/src/common-auth-embedded/quota/map.js +36 -1
  42. package/dist/src/common-auth-embedded/quota/merge.d.ts +3 -1
  43. package/dist/src/common-auth-embedded/quota/merge.js +21 -5
  44. package/dist/src/common-auth-embedded/quota/projection.d.ts +2 -1
  45. package/dist/src/common-auth-embedded/quota/projection.js +3 -1
  46. package/dist/src/common-auth-embedded/setup/command-error.d.ts +32 -0
  47. package/dist/src/common-auth-embedded/setup/command-error.js +79 -0
  48. package/dist/src/common-auth-embedded/setup/command-runner.js +143 -0
  49. package/dist/src/common-auth-embedded/setup/command.d.ts +3 -0
  50. package/dist/src/common-auth-embedded/setup/command.js +271 -0
  51. package/dist/src/common-auth-embedded/setup/config-write.js +60 -0
  52. package/dist/src/common-auth-embedded/setup/detect.d.ts +6 -0
  53. package/dist/src/common-auth-embedded/setup/detect.js +224 -0
  54. package/dist/src/common-auth-embedded/setup/enroll.js +82 -0
  55. package/dist/src/common-auth-embedded/setup/index.d.ts +6 -0
  56. package/dist/src/common-auth-embedded/setup/index.js +5 -0
  57. package/dist/src/common-auth-embedded/setup/paths.js +33 -0
  58. package/dist/src/common-auth-embedded/setup/process-fence.d.ts +43 -0
  59. package/dist/src/common-auth-embedded/setup/process-fence.js +270 -0
  60. package/dist/src/common-auth-embedded/setup/prompts.js +26 -0
  61. package/dist/src/common-auth-embedded/setup/register.d.ts +11 -0
  62. package/dist/src/common-auth-embedded/setup/register.js +136 -0
  63. package/dist/src/common-auth-embedded/setup/types.d.ts +150 -0
  64. package/dist/src/common-auth-embedded/source-output.json +265 -101
  65. package/dist/src/common-auth-embedded/store/pool.d.ts +1 -1
  66. package/dist/src/common-auth-embedded/store/pool.js +0 -1
  67. package/dist/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
  68. package/dist/src/common-auth-embedded/store/refresh-lock.js +0 -1
  69. package/dist/src/common-auth-embedded/store/schema.d.ts +2 -0
  70. package/dist/src/common-auth-embedded/store/schema.js +3 -2
  71. package/dist/src/ga/rpc/protocol.d.ts +4 -7
  72. package/dist/src/ga/rpc/protocol.d.ts.map +1 -1
  73. package/dist/src/ga/rpc/protocol.js +5 -13
  74. package/dist/src/ga/rpc/protocol.js.map +1 -1
  75. package/dist/src/ga/server/auth.d.ts +8 -3
  76. package/dist/src/ga/server/auth.d.ts.map +1 -1
  77. package/dist/src/ga/server/auth.js +25 -9
  78. package/dist/src/ga/server/auth.js.map +1 -1
  79. package/dist/src/ga/server/index.d.ts +39 -12
  80. package/dist/src/ga/server/index.d.ts.map +1 -1
  81. package/dist/src/ga/server/index.js +218 -55
  82. package/dist/src/ga/server/index.js.map +1 -1
  83. package/dist/src/ga/server/pool-login.d.ts +22 -0
  84. package/dist/src/ga/server/pool-login.d.ts.map +1 -0
  85. package/dist/src/ga/server/pool-login.js +150 -0
  86. package/dist/src/ga/server/pool-login.js.map +1 -0
  87. package/dist/src/ga/tui/host-ga.d.ts +2 -5
  88. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  89. package/dist/src/ga/tui/host-ga.js +54 -52
  90. package/dist/src/ga/tui/host-ga.js.map +1 -1
  91. package/dist/src/plugin/accounts.d.ts +1 -1
  92. package/dist/src/plugin/accounts.d.ts.map +1 -1
  93. package/dist/src/plugin/accounts.js +1 -0
  94. package/dist/src/plugin/accounts.js.map +1 -1
  95. package/dist/src/plugin/background-vault-quota-refresh.d.ts +2 -0
  96. package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  97. package/dist/src/plugin/background-vault-quota-refresh.js +125 -10
  98. package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
  99. package/dist/src/plugin/command-apply.d.ts +2 -2
  100. package/dist/src/plugin/command-apply.d.ts.map +1 -1
  101. package/dist/src/plugin/command-apply.js +3 -10
  102. package/dist/src/plugin/command-apply.js.map +1 -1
  103. package/dist/src/plugin/commands.d.ts +1 -0
  104. package/dist/src/plugin/commands.d.ts.map +1 -1
  105. package/dist/src/plugin/commands.js +2 -2
  106. package/dist/src/plugin/commands.js.map +1 -1
  107. package/dist/src/plugin/config/operator-settings-schema.d.ts +0 -4
  108. package/dist/src/plugin/config/operator-settings-schema.d.ts.map +1 -1
  109. package/dist/src/plugin/config/operator-settings-schema.js +0 -5
  110. package/dist/src/plugin/config/operator-settings-schema.js.map +1 -1
  111. package/dist/src/plugin/config/schema.d.ts +0 -7
  112. package/dist/src/plugin/config/schema.d.ts.map +1 -1
  113. package/dist/src/plugin/config/schema.js +2 -44
  114. package/dist/src/plugin/config/schema.js.map +1 -1
  115. package/dist/src/plugin/config/writer.d.ts +1 -1
  116. package/dist/src/plugin/config/writer.js +1 -1
  117. package/dist/src/plugin/fetch/retry-state.d.ts +19 -3
  118. package/dist/src/plugin/fetch/retry-state.d.ts.map +1 -1
  119. package/dist/src/plugin/fetch/retry-state.js +0 -6
  120. package/dist/src/plugin/fetch/retry-state.js.map +1 -1
  121. package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
  122. package/dist/src/plugin/fetch-interceptor.js +0 -3
  123. package/dist/src/plugin/fetch-interceptor.js.map +1 -1
  124. package/dist/src/plugin/fetch-routing.d.ts +0 -16
  125. package/dist/src/plugin/fetch-routing.d.ts.map +1 -1
  126. package/dist/src/plugin/fetch-routing.js +0 -49
  127. package/dist/src/plugin/fetch-routing.js.map +1 -1
  128. package/dist/src/plugin/ga-location-services.d.ts +14 -9
  129. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  130. package/dist/src/plugin/ga-location-services.js +124 -43
  131. package/dist/src/plugin/ga-location-services.js.map +1 -1
  132. package/dist/src/plugin/gemini-dump.d.ts.map +1 -1
  133. package/dist/src/plugin/gemini-dump.js +2 -5
  134. package/dist/src/plugin/gemini-dump.js.map +1 -1
  135. package/dist/src/plugin/google-origin.d.ts +7 -0
  136. package/dist/src/plugin/google-origin.d.ts.map +1 -0
  137. package/dist/src/plugin/google-origin.js +14 -0
  138. package/dist/src/plugin/google-origin.js.map +1 -0
  139. package/dist/src/plugin/index.d.ts.map +1 -1
  140. package/dist/src/plugin/index.js +18 -7
  141. package/dist/src/plugin/index.js.map +1 -1
  142. package/dist/src/plugin/logging-utils.d.ts.map +1 -1
  143. package/dist/src/plugin/logging-utils.js +2 -5
  144. package/dist/src/plugin/logging-utils.js.map +1 -1
  145. package/dist/src/plugin/oauth-methods.d.ts.map +1 -1
  146. package/dist/src/plugin/oauth-methods.js +0 -33
  147. package/dist/src/plugin/oauth-methods.js.map +1 -1
  148. package/dist/src/plugin/operator-settings.d.ts +1 -1
  149. package/dist/src/plugin/operator-settings.d.ts.map +1 -1
  150. package/dist/src/plugin/operator-settings.js +1 -8
  151. package/dist/src/plugin/operator-settings.js.map +1 -1
  152. package/dist/src/plugin/quota.d.ts +11 -7
  153. package/dist/src/plugin/quota.d.ts.map +1 -1
  154. package/dist/src/plugin/quota.js +128 -102
  155. package/dist/src/plugin/quota.js.map +1 -1
  156. package/dist/src/plugin/request.d.ts +6 -5
  157. package/dist/src/plugin/request.d.ts.map +1 -1
  158. package/dist/src/plugin/request.js +95 -180
  159. package/dist/src/plugin/request.js.map +1 -1
  160. package/dist/src/plugin/server.d.ts.map +1 -1
  161. package/dist/src/plugin/server.js +60 -53
  162. package/dist/src/plugin/server.js.map +1 -1
  163. package/dist/src/plugin/shared/advisory-repository.d.ts +20 -0
  164. package/dist/src/plugin/shared/advisory-repository.d.ts.map +1 -0
  165. package/dist/src/plugin/shared/advisory-repository.js +91 -0
  166. package/dist/src/plugin/shared/advisory-repository.js.map +1 -0
  167. package/dist/src/plugin/shared/request-services.d.ts +27 -26
  168. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  169. package/dist/src/plugin/shared/request-services.js +244 -245
  170. package/dist/src/plugin/shared/request-services.js.map +1 -1
  171. package/dist/src/plugin/shared/runtime.js +4 -2
  172. package/dist/src/plugin/shared/runtime.js.map +1 -1
  173. package/dist/src/plugin/shared/vault-request-credentials.d.ts +16 -4
  174. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  175. package/dist/src/plugin/shared/vault-request-credentials.js +44 -7
  176. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  177. package/dist/src/plugin/storage.d.ts +2 -2
  178. package/dist/src/plugin/storage.d.ts.map +1 -1
  179. package/dist/src/plugin/storage.js.map +1 -1
  180. package/dist/src/plugin/vault-custody.d.ts +14 -1
  181. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  182. package/dist/src/plugin/vault-custody.js +203 -44
  183. package/dist/src/plugin/vault-custody.js.map +1 -1
  184. package/dist/src/plugin/vault-quota-outcome.d.ts +19 -0
  185. package/dist/src/plugin/vault-quota-outcome.d.ts.map +1 -0
  186. package/dist/src/plugin/vault-quota-outcome.js +47 -0
  187. package/dist/src/plugin/vault-quota-outcome.js.map +1 -0
  188. package/dist/src/quota-presentation.d.ts +29 -1
  189. package/dist/src/quota-presentation.d.ts.map +1 -1
  190. package/dist/src/quota-presentation.js +52 -17
  191. package/dist/src/quota-presentation.js.map +1 -1
  192. package/dist/src/setup.d.ts +15 -0
  193. package/dist/src/setup.d.ts.map +1 -0
  194. package/dist/src/setup.js +320 -0
  195. package/dist/src/setup.js.map +1 -0
  196. package/dist/src/sidebar-projection.d.ts +5 -1
  197. package/dist/src/sidebar-projection.d.ts.map +1 -1
  198. package/dist/src/sidebar-projection.js +6 -2
  199. package/dist/src/sidebar-projection.js.map +1 -1
  200. package/dist/src/sidebar-state.d.ts +1 -1
  201. package/dist/src/sidebar-state.d.ts.map +1 -1
  202. package/dist/src/sidebar-state.js +19 -1
  203. package/dist/src/sidebar-state.js.map +1 -1
  204. package/dist/src/tui/quota-layout.d.ts +94 -0
  205. package/dist/src/tui/quota-layout.d.ts.map +1 -0
  206. package/dist/src/tui/quota-layout.js +139 -0
  207. package/dist/src/tui/quota-layout.js.map +1 -0
  208. package/dist/src/tui/route-layout.d.ts +8 -0
  209. package/dist/src/tui/route-layout.d.ts.map +1 -0
  210. package/dist/src/tui/route-layout.js +36 -0
  211. package/dist/src/tui/route-layout.js.map +1 -0
  212. package/dist/src/tui.d.ts.map +1 -1
  213. package/dist/src/tui.js +120 -127
  214. package/dist/src/tui.js.map +1 -1
  215. package/dist/tui-build-map.json +66 -37
  216. package/dist/tui-ga-build-map.json +66 -37
  217. package/dist/types/src/auth-method-labels.d.ts +3 -0
  218. package/dist/types/src/auth-method-labels.d.ts.map +1 -0
  219. package/dist/types/src/cli.d.ts +3 -1
  220. package/dist/types/src/cli.d.ts.map +1 -1
  221. package/dist/types/src/common-auth-embedded/auth-menu/terminal.d.ts +43 -0
  222. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +142 -0
  223. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +207 -0
  224. package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +164 -0
  225. package/dist/types/src/common-auth-embedded/claustrum/errors.d.ts +16 -0
  226. package/dist/types/src/common-auth-embedded/claustrum/host-slot.d.ts +39 -0
  227. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +19 -0
  228. package/dist/types/src/common-auth-embedded/claustrum/insula.d.ts +69 -0
  229. package/dist/types/src/common-auth-embedded/claustrum/interlock.d.ts +27 -0
  230. package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +221 -0
  231. package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
  232. package/dist/types/src/common-auth-embedded/opencode2/errors.d.ts +25 -0
  233. package/dist/types/src/common-auth-embedded/opencode2/index.d.ts +8 -0
  234. package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +55 -0
  235. package/dist/types/src/common-auth-embedded/opencode2/integration.d.ts +112 -0
  236. package/dist/types/src/common-auth-embedded/opencode2/sse.d.ts +12 -0
  237. package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +413 -0
  238. package/dist/types/src/common-auth-embedded/quota/codec.d.ts +2 -0
  239. package/dist/types/src/common-auth-embedded/quota/format.d.ts +40 -3
  240. package/dist/types/src/common-auth-embedded/quota/index.d.ts +4 -4
  241. package/dist/types/src/common-auth-embedded/quota/map.d.ts +11 -0
  242. package/dist/types/src/common-auth-embedded/quota/merge.d.ts +3 -1
  243. package/dist/types/src/common-auth-embedded/quota/projection.d.ts +2 -1
  244. package/dist/types/src/common-auth-embedded/routing/admission.d.ts +93 -0
  245. package/dist/types/src/common-auth-embedded/routing/index.d.ts +8 -0
  246. package/dist/types/src/common-auth-embedded/routing/ordered.d.ts +47 -0
  247. package/dist/types/src/common-auth-embedded/routing/pins.d.ts +22 -0
  248. package/dist/types/src/common-auth-embedded/routing/sticky.d.ts +158 -0
  249. package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +32 -0
  250. package/dist/types/src/common-auth-embedded/setup/command.d.ts +3 -0
  251. package/dist/types/src/common-auth-embedded/setup/detect.d.ts +6 -0
  252. package/dist/types/src/common-auth-embedded/setup/index.d.ts +6 -0
  253. package/dist/types/src/common-auth-embedded/setup/process-fence.d.ts +43 -0
  254. package/dist/types/src/common-auth-embedded/setup/register.d.ts +11 -0
  255. package/dist/types/src/common-auth-embedded/setup/types.d.ts +150 -0
  256. package/dist/types/src/common-auth-embedded/store/pool.d.ts +1 -1
  257. package/dist/types/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
  258. package/dist/types/src/common-auth-embedded/store/schema.d.ts +2 -0
  259. package/dist/types/src/ga/rpc/protocol.d.ts +4 -7
  260. package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -1
  261. package/dist/types/src/ga/server/auth.d.ts +8 -3
  262. package/dist/types/src/ga/server/auth.d.ts.map +1 -1
  263. package/dist/types/src/ga/server/index.d.ts +39 -12
  264. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  265. package/dist/types/src/ga/server/pool-login.d.ts +22 -0
  266. package/dist/types/src/ga/server/pool-login.d.ts.map +1 -0
  267. package/dist/types/src/plugin/accounts.d.ts +1 -1
  268. package/dist/types/src/plugin/accounts.d.ts.map +1 -1
  269. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts +2 -0
  270. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  271. package/dist/types/src/plugin/command-apply.d.ts +2 -2
  272. package/dist/types/src/plugin/command-apply.d.ts.map +1 -1
  273. package/dist/types/src/plugin/commands.d.ts +1 -0
  274. package/dist/types/src/plugin/commands.d.ts.map +1 -1
  275. package/dist/types/src/plugin/config/operator-settings-schema.d.ts +0 -4
  276. package/dist/types/src/plugin/config/operator-settings-schema.d.ts.map +1 -1
  277. package/dist/types/src/plugin/config/schema.d.ts +0 -7
  278. package/dist/types/src/plugin/config/schema.d.ts.map +1 -1
  279. package/dist/types/src/plugin/config/writer.d.ts +1 -1
  280. package/dist/types/src/plugin/fetch/retry-state.d.ts +19 -3
  281. package/dist/types/src/plugin/fetch/retry-state.d.ts.map +1 -1
  282. package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
  283. package/dist/types/src/plugin/fetch-routing.d.ts +0 -16
  284. package/dist/types/src/plugin/fetch-routing.d.ts.map +1 -1
  285. package/dist/types/src/plugin/ga-location-services.d.ts +14 -9
  286. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  287. package/dist/types/src/plugin/gemini-dump.d.ts.map +1 -1
  288. package/dist/types/src/plugin/google-origin.d.ts +7 -0
  289. package/dist/types/src/plugin/google-origin.d.ts.map +1 -0
  290. package/dist/types/src/plugin/index.d.ts.map +1 -1
  291. package/dist/types/src/plugin/logging-utils.d.ts.map +1 -1
  292. package/dist/types/src/plugin/oauth-methods.d.ts.map +1 -1
  293. package/dist/types/src/plugin/operator-settings.d.ts +1 -1
  294. package/dist/types/src/plugin/operator-settings.d.ts.map +1 -1
  295. package/dist/types/src/plugin/quota.d.ts +11 -7
  296. package/dist/types/src/plugin/quota.d.ts.map +1 -1
  297. package/dist/types/src/plugin/request.d.ts +6 -5
  298. package/dist/types/src/plugin/request.d.ts.map +1 -1
  299. package/dist/types/src/plugin/server.d.ts.map +1 -1
  300. package/dist/types/src/plugin/shared/advisory-repository.d.ts +20 -0
  301. package/dist/types/src/plugin/shared/advisory-repository.d.ts.map +1 -0
  302. package/dist/types/src/plugin/shared/request-services.d.ts +27 -26
  303. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  304. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +16 -4
  305. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  306. package/dist/types/src/plugin/storage.d.ts +2 -2
  307. package/dist/types/src/plugin/storage.d.ts.map +1 -1
  308. package/dist/types/src/plugin/vault-custody.d.ts +14 -1
  309. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  310. package/dist/types/src/plugin/vault-quota-outcome.d.ts +19 -0
  311. package/dist/types/src/plugin/vault-quota-outcome.d.ts.map +1 -0
  312. package/dist/types/src/setup.d.ts +15 -0
  313. package/dist/types/src/setup.d.ts.map +1 -0
  314. package/dist/types/src/sidebar-state.d.ts +1 -1
  315. package/dist/types/src/sidebar-state.d.ts.map +1 -1
  316. package/package.json +5 -4
  317. package/src/common-auth-embedded/claustrum/consumer.d.ts +44 -4
  318. package/src/common-auth-embedded/claustrum/consumer.js +134 -2
  319. package/src/common-auth-embedded/claustrum/custody.d.ts +33 -1
  320. package/src/common-auth-embedded/claustrum/custody.js +17 -0
  321. package/src/common-auth-embedded/claustrum/enrollment.d.ts +6 -1
  322. package/src/common-auth-embedded/claustrum/enrollment.js +6 -1
  323. package/src/common-auth-embedded/claustrum/index.d.ts +3 -2
  324. package/src/common-auth-embedded/claustrum/index.js +5 -3
  325. package/src/common-auth-embedded/claustrum/insula.d.ts +69 -0
  326. package/src/common-auth-embedded/claustrum/insula.js +152 -0
  327. package/src/common-auth-embedded/claustrum/roster.d.ts +13 -0
  328. package/src/common-auth-embedded/claustrum/roster.js +33 -3
  329. package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
  330. package/src/common-auth-embedded/fs/refresh-file-lock.js +26 -12
  331. package/src/common-auth-embedded/pi-slot/lock.js +7 -3
  332. package/src/common-auth-embedded/quota/codec.d.ts +2 -0
  333. package/src/common-auth-embedded/quota/codec.js +2 -1
  334. package/src/common-auth-embedded/quota/format.d.ts +40 -3
  335. package/src/common-auth-embedded/quota/format.js +196 -43
  336. package/src/common-auth-embedded/quota/index.d.ts +4 -4
  337. package/src/common-auth-embedded/quota/index.js +2 -2
  338. package/src/common-auth-embedded/quota/map.d.ts +11 -0
  339. package/src/common-auth-embedded/quota/map.js +36 -1
  340. package/src/common-auth-embedded/quota/merge.d.ts +3 -1
  341. package/src/common-auth-embedded/quota/merge.js +21 -5
  342. package/src/common-auth-embedded/quota/projection.d.ts +2 -1
  343. package/src/common-auth-embedded/quota/projection.js +3 -1
  344. package/src/common-auth-embedded/setup/command-error.d.ts +32 -0
  345. package/src/common-auth-embedded/setup/command-error.js +79 -0
  346. package/src/common-auth-embedded/setup/command-runner.js +143 -0
  347. package/src/common-auth-embedded/setup/command.d.ts +3 -0
  348. package/src/common-auth-embedded/setup/command.js +271 -0
  349. package/src/common-auth-embedded/setup/config-write.js +60 -0
  350. package/src/common-auth-embedded/setup/detect.d.ts +6 -0
  351. package/src/common-auth-embedded/setup/detect.js +224 -0
  352. package/src/common-auth-embedded/setup/enroll.js +82 -0
  353. package/src/common-auth-embedded/setup/index.d.ts +6 -0
  354. package/src/common-auth-embedded/setup/index.js +5 -0
  355. package/src/common-auth-embedded/setup/paths.js +33 -0
  356. package/src/common-auth-embedded/setup/process-fence.d.ts +43 -0
  357. package/src/common-auth-embedded/setup/process-fence.js +270 -0
  358. package/src/common-auth-embedded/setup/prompts.js +26 -0
  359. package/src/common-auth-embedded/setup/register.d.ts +11 -0
  360. package/src/common-auth-embedded/setup/register.js +136 -0
  361. package/src/common-auth-embedded/setup/types.d.ts +150 -0
  362. package/src/common-auth-embedded/source-output.json +265 -101
  363. package/src/common-auth-embedded/store/pool.d.ts +1 -1
  364. package/src/common-auth-embedded/store/pool.js +0 -1
  365. package/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
  366. package/src/common-auth-embedded/store/refresh-lock.js +0 -1
  367. package/src/common-auth-embedded/store/schema.d.ts +2 -0
  368. package/src/common-auth-embedded/store/schema.js +3 -2
  369. package/src/sidebar-state.ts +19 -2
  370. package/src/tui-compiled/common-auth-embedded/quota/codec.js +2 -1
  371. package/src/tui-compiled/common-auth-embedded/quota/format.js +196 -43
  372. package/src/tui-compiled/common-auth-embedded/quota/index.js +2 -2
  373. package/src/tui-compiled/common-auth-embedded/quota/map.js +36 -1
  374. package/src/tui-compiled/common-auth-embedded/quota/merge.js +21 -5
  375. package/src/tui-compiled/common-auth-embedded/quota/projection.js +3 -1
  376. package/src/tui-compiled/quota-presentation.js +42 -9
  377. package/src/tui-compiled/sidebar-state.js +15 -1
  378. package/src/tui-compiled/tui/quota-layout.js +378 -0
  379. package/src/tui-compiled/tui/route-layout.js +30 -0
  380. package/src/tui-compiled/tui.js +271 -371
  381. package/src/tui-ga-compiled/host-ga.js +93 -90
  382. package/src/tui-ga-compiled/shared/1ff34afa7c42d196-projection.js +3 -1
  383. package/src/tui-ga-compiled/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
  384. package/src/tui-ga-compiled/shared/77138df80c7ae006-map.js +36 -1
  385. package/src/tui-ga-compiled/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
  386. package/src/tui-ga-compiled/shared/98cc0c186c46c42d-quota-presentation.js +42 -9
  387. package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +196 -43
  388. package/src/tui-ga-compiled/shared/bf17cbee28e58197-index.js +2 -2
  389. package/src/tui-ga-compiled/shared/ca21dc417b36dc5d-codec.js +2 -1
  390. package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +378 -0
  391. package/src/tui-ga-compiled/shared/ecc214300932dfb6-merge.js +21 -5
  392. package/src/tui-ga-raw/host-ga.tsx +102 -92
  393. package/src/tui-ga-raw/shared/1ff34afa7c42d196-projection.js +3 -1
  394. package/src/tui-ga-raw/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
  395. package/src/tui-ga-raw/shared/77138df80c7ae006-map.js +36 -1
  396. package/src/tui-ga-raw/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
  397. package/src/tui-ga-raw/shared/98cc0c186c46c42d-quota-presentation.js +42 -9
  398. package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +196 -43
  399. package/src/tui-ga-raw/shared/bf17cbee28e58197-index.js +2 -2
  400. package/src/tui-ga-raw/shared/ca21dc417b36dc5d-codec.js +2 -1
  401. package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +391 -0
  402. package/src/tui-ga-raw/shared/ecc214300932dfb6-merge.js +21 -5
  403. package/src/tui-raw/common-auth-embedded/quota/codec.js +2 -1
  404. package/src/tui-raw/common-auth-embedded/quota/format.js +196 -43
  405. package/src/tui-raw/common-auth-embedded/quota/index.js +2 -2
  406. package/src/tui-raw/common-auth-embedded/quota/map.js +36 -1
  407. package/src/tui-raw/common-auth-embedded/quota/merge.js +21 -5
  408. package/src/tui-raw/common-auth-embedded/quota/projection.js +3 -1
  409. package/src/tui-raw/quota-presentation.js +42 -9
  410. package/src/tui-raw/sidebar-state.js +15 -1
  411. package/src/tui-raw/tui/quota-layout.tsx +391 -0
  412. package/src/tui-raw/tui/route-layout.js +30 -0
  413. package/src/tui-raw/tui.tsx +218 -272
  414. package/src/tui.tsx +218 -272
  415. package/dist/src/tui/vault-setup.d.ts +0 -98
  416. package/dist/src/tui/vault-setup.d.ts.map +0 -1
  417. package/dist/src/tui/vault-setup.js +0 -198
  418. package/dist/src/tui/vault-setup.js.map +0 -1
  419. package/dist/types/src/plugin/transform/model-resolver.d.ts +0 -2
  420. package/dist/types/src/plugin/transform/model-resolver.d.ts.map +0 -1
  421. package/dist/types/src/quota-presentation.d.ts +0 -18
  422. package/dist/types/src/quota-presentation.d.ts.map +0 -1
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Shared Antigravity request engine: account selection, retries, endpoint
3
- * and quota fallback, warmups and response handling for one plugin location.
3
+ * fallback, warmups and response handling for one plugin location.
4
4
  *
5
5
  * OpenCode 1's `createFetchInterceptor` and the GA location services both
6
6
  * call `createRequestExecutor`, so there is exactly one retry loop. Every
@@ -16,12 +16,12 @@
16
16
  * `RequestWire`, which `createRequestWire` binds to one location's signature
17
17
  * cache, debug log and logger; the raw sender is called unchanged.
18
18
  */
19
- import { accessTokenExpired, calculateBackoffMs, computeSoftQuotaCacheTtlMs, getPublicModelDefinitions, getResolverAliasMap, isClaudeThinkingModel, isImageGenerationModel, isRetiredAgyModel, parseRateLimitReason, preserveResponseMetadata, RETIRED_AGY_MODEL_MESSAGE, redactCredentialError, redactCredentialResponse, redactCredentialText, resolveQuotaGroup, VAULT_ACCOUNT_REMEDY, } from '@cortexkit/antigravity-auth-core';
20
- import { ANTIGRAVITY_ENDPOINT_FALLBACKS, } from '../../constants';
19
+ import { accessTokenExpired, calculateBackoffMs, computeSoftQuotaCacheTtlMs, getPublicModelDefinitions, getQuotaKey, getResolverAliasMap, isClaudeThinkingModel, isImageGenerationModel, isRetiredAgyModel, PRE_RESPONSE_DEADLINE_MS, PreResponseDeadline, PreResponseTimeoutError, parseRateLimitReason, parseRefreshParts, preResponseTimeoutResponse, preserveResponseMetadata, RETIRED_AGY_MODEL_MESSAGE, redactCredentialError, redactCredentialResponse, redactCredentialText, resolveQuotaGroup, VAULT_ACCOUNT_REMEDY, } from '@cortexkit/antigravity-auth-core';
20
+ import { ANTIGRAVITY_ENDPOINT_FALLBACKS } from '../../constants';
21
21
  import { AntigravityKillswitchError } from '../errors';
22
22
  import { createRetryState, } from '../fetch/retry-state';
23
23
  import { createWarmupState } from '../fetch/warmup';
24
- import { extractModelFromUrl, getModelFamilyFromUrl, isCapacityRetryBudgetExhausted, MAX_TOTAL_CAPACITY_RETRIES, resolveHeaderRoutingDecision, resolveQuotaFallbackHeaderStyle, toUrlString, toWarmupStreamUrl, } from '../fetch-routing';
24
+ import { extractModelFromUrl, getModelFamilyFromUrl, isCapacityRetryBudgetExhausted, MAX_TOTAL_CAPACITY_RETRIES, toUrlString, toWarmupStreamUrl, } from '../fetch-routing';
25
25
  import { noteGeminiDumpResponse } from '../gemini-dump';
26
26
  import { evaluateKillswitchForAccount, throwIfAllKilled } from '../killswitch';
27
27
  import { createNativeGoogleErrorResponse, createSyntheticTextResponse, isEmptyResponseBody, } from '../request-helpers';
@@ -39,7 +39,7 @@ const FIRST_RETRY_DELAY_MS = 1000;
39
39
  * `RequestWire.prepare`'s.
40
40
  */
41
41
  export function prepareAgyWireRequest(wire, request) {
42
- return wire.prepare(request.input, request.init, request.accessToken, request.projectId, request.endpoint, request.headerStyle, request.forceThinkingRecovery ?? false, request.options);
42
+ return wire.prepare(request.input, request.init, request.accessToken, request.projectId, request.endpoint, request.forceThinkingRecovery ?? false, request.options);
43
43
  }
44
44
  /**
45
45
  * The model a title request is sent to when the host selected one this
@@ -61,6 +61,22 @@ export function routeTitleModel(url) {
61
61
  return url;
62
62
  return url.replace(`/models/${model}`, `/models/${TITLE_FALLBACK_MODEL}`);
63
63
  }
64
+ /**
65
+ * Return the retired-model error using only the model registry: callers need
66
+ * neither an initialized account store nor an available vault to reject it.
67
+ */
68
+ export function retiredModelResponse(url) {
69
+ const model = extractModelFromUrl(url);
70
+ if (!model || !isRetiredAgyModel(model))
71
+ return undefined;
72
+ return new Response(JSON.stringify({
73
+ error: {
74
+ code: 412,
75
+ status: 'FAILED_PRECONDITION',
76
+ message: RETIRED_AGY_MODEL_MESSAGE,
77
+ },
78
+ }), { status: 412, headers: { 'Content-Type': 'application/json' } });
79
+ }
64
80
  /**
65
81
  * The AGY metadata key for a request: the host session for primary (and
66
82
  * kind-less) requests, a separate per-kind key for every other kind.
@@ -174,7 +190,7 @@ function sleep(ms, signal) {
174
190
  * dropped.
175
191
  */
176
192
  export function createLocalQuotaRefresh(accountManager, quotaManager, log) {
177
- return async function refreshQuotaAfterSuccess(account, intervalMinutes) {
193
+ return async function refreshQuotaAfterSuccess(account, intervalMinutes, signal) {
178
194
  if (intervalMinutes <= 0)
179
195
  return;
180
196
  const accountIndex = accountManager.getAccounts().indexOf(account);
@@ -197,7 +213,11 @@ export function createLocalQuotaRefresh(accountManager, quotaManager, log) {
197
213
  const expectedRefreshToken = singleAccount.refreshToken;
198
214
  const result = await quotaManager.refreshAccount(singleAccount, {
199
215
  index: accountIndex,
216
+ purpose: 'advisory',
217
+ ...(signal ? { signal } : {}),
200
218
  });
219
+ if (signal?.aborted)
220
+ return;
201
221
  if (result.status === 'ok' && result.quota?.groups) {
202
222
  // Re-resolve the selected row itself. If it was removed meanwhile,
203
223
  // drop the reading rather than writing onto whichever row shifted
@@ -219,11 +239,13 @@ export function createLocalQuotaRefresh(accountManager, quotaManager, log) {
219
239
  * warmup bookkeeping, so disposing it releases every counter.
220
240
  */
221
241
  export function createRequestExecutor(deps) {
222
- const { config, accounts: accountManager, credentials, sessions: agySessionRegistry, operatorSettings, transport: defaultTransport, fetchImpl: upstreamFetch, wire, debug, dump, logger: log, trackers, classifyAccessError, notify, onRouting, } = deps;
242
+ const { config, accounts: accountManager, credentials, sessions: agySessionRegistry, operatorSettings, transport: defaultTransport, wire, debug, dump, logger: log, trackers, classifyAccessError, notify, onRouting, } = deps;
223
243
  const retryState = createRetryState();
224
244
  const warmupState = createWarmupState();
225
245
  const shutdown = new AbortController();
226
246
  const inFlight = new Set();
247
+ const advisoryWork = new Set();
248
+ let advisoryClosing = false;
227
249
  const bufferedOverflow = new WeakMap();
228
250
  let retired = false;
229
251
  let drainPromise;
@@ -248,12 +270,11 @@ export function createRequestExecutor(deps) {
248
270
  log.debug('routing-report-failed', { sessionId, error: String(error) });
249
271
  }
250
272
  };
251
- async function execute(input, init, options = {}, selectedCredentials = new Set()) {
273
+ async function execute(input, init, options, selectedCredentials, selectedProjectIds, deadline, waitPolicy) {
252
274
  const assertAdmission = async () => {
253
- init?.signal?.throwIfAborted();
254
- await deps.assertAdmission?.();
255
- init?.signal?.throwIfAborted();
275
+ await deadline.wait(() => deps.assertAdmission?.());
256
276
  };
277
+ const logResponseBody = (...args) => deadline.wait(() => debug.logResponseBody(...args));
257
278
  await assertAdmission();
258
279
  // Normalize Request/URL inputs to (urlString, init) so the string-based
259
280
  // transform pipeline sees the real method/headers/body. Without this,
@@ -269,7 +290,7 @@ export function createRequestExecutor(deps) {
269
290
  });
270
291
  }
271
292
  const bodyBuffer = req.body
272
- ? await req.clone().arrayBuffer()
293
+ ? await deadline.wait(() => req.clone().arrayBuffer())
273
294
  : undefined;
274
295
  init = {
275
296
  method: init?.method ?? req.method,
@@ -295,23 +316,46 @@ export function createRequestExecutor(deps) {
295
316
  });
296
317
  }
297
318
  }
319
+ let selectedVariant = options.variant;
298
320
  if (kind === 'title') {
299
- input = routeTitleModel(input);
321
+ const routed = routeTitleModel(input);
322
+ // A variant belongs to its catalog model, not the replacement title model.
323
+ if (routed !== input)
324
+ selectedVariant = undefined;
325
+ input = routed;
300
326
  }
327
+ const retired = retiredModelResponse(input);
328
+ if (retired)
329
+ return retired;
301
330
  const selectedModel = extractModelFromUrl(input);
302
- if (selectedModel && isRetiredAgyModel(selectedModel)) {
303
- return new Response(JSON.stringify({
304
- error: {
305
- code: 412,
306
- status: 'FAILED_PRECONDITION',
307
- message: RETIRED_AGY_MODEL_MESSAGE,
308
- },
309
- }), { status: 412, headers: { 'Content-Type': 'application/json' } });
331
+ let variant;
332
+ if (selectedVariant !== undefined) {
333
+ const definitions = getPublicModelDefinitions();
334
+ const variants = selectedModel && Object.hasOwn(definitions, selectedModel)
335
+ ? definitions[selectedModel]?.variants
336
+ : undefined;
337
+ const registered = variants && Object.hasOwn(variants, selectedVariant)
338
+ ? variants[selectedVariant]
339
+ : undefined;
340
+ if (!registered || registered.disabled === true) {
341
+ return new Response(JSON.stringify({
342
+ error: {
343
+ code: 412,
344
+ status: 'FAILED_PRECONDITION',
345
+ message: 'This Antigravity thinking level is unavailable. Choose another thinking level.',
346
+ },
347
+ }), { status: 412, headers: { 'Content-Type': 'application/json' } });
348
+ }
349
+ variant = {
350
+ thinkingLevel: registered.thinkingLevel,
351
+ thinkingBudget: registered.thinkingConfig?.thinkingBudget,
352
+ };
310
353
  }
311
354
  // A host that sends each request through its own raw sender (the GA
312
355
  // loopback bridge) supplies it per request; every send of this request,
313
356
  // warmups included, then goes through it with the same AbortSignal.
314
- const transport = options.transport ?? defaultTransport;
357
+ const sender = options.transport ?? defaultTransport;
358
+ const transport = (url, sendInit, sendOptions) => deadline.open(() => sender(url, sendInit, { ...sendOptions, signal: deadline.signal }));
315
359
  const requestSessionIdentity = options.session ?? extractOpenCodeSessionIdentity(init?.headers);
316
360
  // AGY conversation/trajectory/step metadata is kept per session and
317
361
  // request kind: a title or compaction request never advances the
@@ -332,7 +376,7 @@ export function createRequestExecutor(deps) {
332
376
  const urlString = typeof input === 'string' ? input : toUrlString(input);
333
377
  const modelFromUrl = extractModelFromUrl(urlString) ?? 'unknown';
334
378
  return createNoAccountResponse(credentials.domain === 'vault'
335
- ? VAULT_ACCOUNT_REMEDY
379
+ ? (credentials.emptyRosterRefusal?.() ?? VAULT_ACCOUNT_REMEDY)
336
380
  : 'No Antigravity accounts configured. Run `opencode auth login`.', modelFromUrl);
337
381
  }
338
382
  const urlString = toUrlString(input);
@@ -342,7 +386,7 @@ export function createRequestExecutor(deps) {
342
386
  const pushDebug = (line) => {
343
387
  if (!debug.isDebugEnabled())
344
388
  return;
345
- debugLines.push(redactCredentialText(line, [...selectedCredentials]));
389
+ debugLines.push(redactCredentialText(line, [...selectedCredentials], [...selectedProjectIds]));
346
390
  };
347
391
  pushDebug(`request=${urlString}`);
348
392
  if (requestSessionIdentity.sessionId) {
@@ -359,6 +403,7 @@ export function createRequestExecutor(deps) {
359
403
  let lastError = null;
360
404
  const abortSignal = init?.signal ?? undefined;
361
405
  const checkAborted = () => {
406
+ deadline.check();
362
407
  if (abortSignal?.aborted) {
363
408
  throw abortSignal.reason instanceof Error
364
409
  ? abortSignal.reason
@@ -367,16 +412,6 @@ export function createRequestExecutor(deps) {
367
412
  };
368
413
  const quietMode = config.quiet_mode;
369
414
  const toastScope = config.toast_scope;
370
- // Apply operator-controlled routing overrides live. The slash
371
- // commands mutate these values through `applyCommand`; reading
372
- // them per-request means a runtime flip takes effect on the next
373
- // dispatched call without restarting the plugin.
374
- const operatorRouting = operatorSettings?.get().routing;
375
- const effectiveConfig = {
376
- ...config,
377
- cli_first: operatorRouting?.cli_first ?? config.cli_first,
378
- quota_style_fallback: operatorRouting?.quota_style_fallback ?? config.quota_style_fallback,
379
- };
380
415
  const showToast = async (message, variant) => {
381
416
  log.debug('toast', {
382
417
  message,
@@ -402,28 +437,24 @@ export function createRequestExecutor(deps) {
402
437
  }
403
438
  }
404
439
  try {
405
- await notify?.(message, variant);
440
+ await deadline.wait(() => notify?.(message, variant));
406
441
  }
407
442
  catch {
443
+ checkAborted();
408
444
  // TUI may not be available
409
445
  }
410
446
  };
411
- const hasOtherAccountWithAntigravity = (currentAccount) => {
412
- if (family !== 'gemini')
413
- return false;
414
- return accountManager.hasOtherAccountWithAntigravityAvailable(currentAccount.index, family, model);
415
- };
416
447
  let accountSwitchCount = 0;
417
448
  const maxAccountSwitches = config.max_account_switches ?? 2;
418
449
  let previousAccountIndex = -1;
419
450
  let needsCacheWarmup = false;
420
451
  let localRecaptureUsed = false;
452
+ const maxWaitMs = (config.max_rate_limit_wait_seconds ?? 300) * 1000;
453
+ let allAccountsBlockedAt;
421
454
  while (true) {
422
455
  await assertAdmission();
423
456
  checkAborted();
424
457
  const accountCount = accountManager.getAccountCount();
425
- const routingDecision = resolveHeaderRoutingDecision(urlString, family, effectiveConfig);
426
- const { preferredHeaderStyle, explicitQuota, allowQuotaFallback } = routingDecision;
427
458
  if (accountCount === 0) {
428
459
  // Mirror the no-account short-circuit inside the retry loop so callers
429
460
  // that race with account removal still get a proper 401 instead of a
@@ -441,12 +472,6 @@ export function createRequestExecutor(deps) {
441
472
  .getAccounts()
442
473
  .filter((entry) => {
443
474
  const decision = evaluateKillswitchForAccount(entry, family, {
444
- routing: effectiveConfig.cli_first !== undefined
445
- ? {
446
- cli_first: effectiveConfig.cli_first,
447
- quota_style_fallback: !!effectiveConfig.quota_style_fallback,
448
- }
449
- : { cli_first: false, quota_style_fallback: false },
450
475
  killswitch: operatorKillswitch,
451
476
  log_level: 'info',
452
477
  }, { now: Date.now(), model });
@@ -463,7 +488,6 @@ export function createRequestExecutor(deps) {
463
488
  model: model ?? 'unknown',
464
489
  accounts: accountManager.getAccounts(),
465
490
  settings: {
466
- routing: { cli_first: false, quota_style_fallback: false },
467
491
  killswitch: operatorKillswitch ?? {
468
492
  enabled: false,
469
493
  minimum_remaining_percent: 0,
@@ -490,8 +514,7 @@ export function createRequestExecutor(deps) {
490
514
  }
491
515
  }
492
516
  // The eligibility mask above is computed once for this selection
493
- // pass and applies to both the initial selection and the header-style
494
- // fallback below. Selection does not re-evaluate quota, so a killed
517
+ // pass and applies to the account selection below. Selection does not re-evaluate quota, so a killed
495
518
  // current account falls through to the next eligible account.
496
519
  const killedIndexes = eligibleIndexes === null
497
520
  ? undefined
@@ -499,7 +522,7 @@ export function createRequestExecutor(deps) {
499
522
  .getAccounts()
500
523
  .map((entry) => entry.index)
501
524
  .filter((index) => !eligibleIndexes.has(index)));
502
- let account = accountManager.getCurrentOrNextForFamily(family, model, config.account_selection_strategy, preferredHeaderStyle, config.pid_offset_enabled, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, accountSessionIdentity, killedIndexes);
525
+ let account = accountManager.getCurrentOrNextForFamily(family, model, config.account_selection_strategy, config.pid_offset_enabled, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, accountSessionIdentity, killedIndexes);
503
526
  // The selected account must be inside the eligibility mask.
504
527
  if (account &&
505
528
  eligibleIndexes !== null &&
@@ -507,27 +530,29 @@ export function createRequestExecutor(deps) {
507
530
  pushDebug(`killswitch-excluded idx=${account.index} (precomputed eligible set)`);
508
531
  account = null;
509
532
  }
510
- if (!account && allowQuotaFallback) {
511
- const alternateHeaderStyle = preferredHeaderStyle === 'antigravity' ? 'gemini-cli' : 'antigravity';
512
- account = accountManager.getCurrentOrNextForFamily(family, model, config.account_selection_strategy, alternateHeaderStyle, config.pid_offset_enabled, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, accountSessionIdentity, killedIndexes);
513
- if (account) {
514
- pushDebug(`selected-by-fallback idx=${account.index} preferred=${preferredHeaderStyle} alternate=${alternateHeaderStyle}`);
515
- }
516
- // The header-style fallback may not select an account outside the
517
- // eligibility mask.
518
- if (account &&
519
- eligibleIndexes !== null &&
520
- !eligibleIndexes.has(account.index)) {
521
- pushDebug(`killswitch-excluded idx=${account.index} after fallback (precomputed eligible set)`);
522
- account = null;
523
- }
524
- }
525
533
  if (!account) {
534
+ // Rate-limit and soft-quota waits belong to the same blocked period.
535
+ // Selection of an eligible account below starts a fresh budget.
536
+ allAccountsBlockedAt ??= Date.now();
537
+ const blockedSince = allAccountsBlockedAt;
538
+ const remainingWaitMs = () => maxWaitMs > 0
539
+ ? Math.max(0, maxWaitMs - (Date.now() - blockedSince))
540
+ : Number.POSITIVE_INFINITY;
541
+ // At an equal deadline, retain the classified blocked-pool refusal.
542
+ // This priority never changes either clock or replenishes the request.
543
+ const quotaWins = remainingWaitMs() <= deadline.remainingMs();
526
544
  if (accountManager.areAllAccountsOverSoftQuota(family, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, model)) {
527
545
  const threshold = config.soft_quota_threshold_percent;
528
546
  const softQuotaWaitMs = accountManager.getMinWaitTimeForSoftQuota(family, threshold, softQuotaCacheTtlMs, model);
529
- const maxWaitMs = (config.max_rate_limit_wait_seconds ?? 300) * 1000;
547
+ waitPolicy.refusal = quotaWins
548
+ ? () => createNativeGoogleErrorResponse({
549
+ status: 412,
550
+ reason: 'soft_quota',
551
+ resetAfterMs: softQuotaWaitMs,
552
+ })
553
+ : undefined;
530
554
  if (softQuotaWaitMs === null ||
555
+ remainingWaitMs() <= 0 ||
531
556
  (maxWaitMs > 0 && softQuotaWaitMs > maxWaitMs)) {
532
557
  const waitTimeFormatted = softQuotaWaitMs
533
558
  ? formatWaitTime(softQuotaWaitMs)
@@ -544,12 +569,18 @@ export function createRequestExecutor(deps) {
544
569
  await showToast(`All ${accountCount} account(s) over ${threshold}% quota. Waiting ${formatWaitTime(softQuotaWaitMs)}...`, 'warning');
545
570
  retryState.markSoftQuotaToastShown();
546
571
  }
547
- await sleep(softQuotaWaitMs, abortSignal);
572
+ await sleep(Math.min(softQuotaWaitMs, remainingWaitMs()), abortSignal);
548
573
  continue;
549
574
  }
550
- const strictWait = !allowQuotaFallback;
551
- const minWaitMs = accountManager.getMinWaitTimeForFamily(family, model, preferredHeaderStyle, strictWait);
575
+ const minWaitMs = accountManager.getMinWaitTimeForFamily(family, model);
552
576
  const waitMs = minWaitMs || 60_000;
577
+ waitPolicy.refusal = quotaWins
578
+ ? () => createNativeGoogleErrorResponse({
579
+ status: 412,
580
+ reason: 'pool_unavailable',
581
+ resetAfterMs: minWaitMs > 0 ? minWaitMs : undefined,
582
+ })
583
+ : undefined;
553
584
  pushDebug(`all-rate-limited family=${family} accounts=${accountCount} waitMs=${waitMs}`);
554
585
  if (debug.isDebugEnabled()) {
555
586
  debug.logAccountContext('All accounts rate-limited', {
@@ -559,8 +590,7 @@ export function createRequestExecutor(deps) {
559
590
  });
560
591
  debug.logRateLimitSnapshot(family, accountManager.getAccountsSnapshot());
561
592
  }
562
- const maxWaitMs = (config.max_rate_limit_wait_seconds ?? 300) * 1000;
563
- if (maxWaitMs > 0 && waitMs > maxWaitMs) {
593
+ if (remainingWaitMs() <= 0 || (maxWaitMs > 0 && waitMs > maxWaitMs)) {
564
594
  const waitTimeFormatted = formatWaitTime(waitMs);
565
595
  await showToast(`Rate limited for ${waitTimeFormatted}. Try again later or add another account.`, 'error');
566
596
  return createNativeGoogleErrorResponse({
@@ -576,10 +606,12 @@ export function createRequestExecutor(deps) {
576
606
  await showToast(`All ${accountCount} account(s) rate-limited for ${family}. Waiting ${waitSecValue}s...`, 'warning');
577
607
  retryState.markRateLimitToastShown();
578
608
  }
579
- await sleep(waitMs, abortSignal);
609
+ await sleep(Math.min(waitMs, remainingWaitMs()), abortSignal);
580
610
  continue;
581
611
  }
582
- // Account is available - reset the toast flag
612
+ // An eligible account ends the contiguous all-accounts-blocked period.
613
+ allAccountsBlockedAt = undefined;
614
+ waitPolicy.refusal = undefined;
583
615
  retryState.resetAllAccountsBlockedToasts();
584
616
  pushDebug(`selected idx=${account.index} email=${account.email ?? ''} family=${family} accounts=${accountCount} strategy=${config.account_selection_strategy}`);
585
617
  if (previousAccountIndex >= 0 && previousAccountIndex !== account.index) {
@@ -620,11 +652,21 @@ export function createRequestExecutor(deps) {
620
652
  // Project resolution can use this bearer before the main model send.
621
653
  if (auth.access)
622
654
  selectedCredentials.add(auth.access);
623
- const context = await credentials
624
- .ensureProject(auth)
655
+ const packedProject = parseRefreshParts(auth.refresh);
656
+ for (const projectId of [
657
+ packedProject.projectId,
658
+ packedProject.managedProjectId,
659
+ ]) {
660
+ if (projectId)
661
+ selectedProjectIds.add(projectId);
662
+ }
663
+ const context = await deadline
664
+ .wait(() => credentials.ensureProject(auth))
625
665
  .catch((error) => {
626
- throw redactCredentialError(error, [...selectedCredentials]);
666
+ throw redactCredentialError(error, [...selectedCredentials], [...selectedProjectIds]);
627
667
  });
668
+ if (context.effectiveProjectId)
669
+ selectedProjectIds.add(context.effectiveProjectId);
628
670
  await assertAdmission();
629
671
  // A project cache may carry an older bearer. Only the token fixed
630
672
  // before this await belongs to the newly prepared request.
@@ -636,9 +678,10 @@ export function createRequestExecutor(deps) {
636
678
  if (persistProject && projectAuth.refresh !== auth.refresh) {
637
679
  credentials.updateFromAuth(account, projectAuth);
638
680
  try {
639
- await credentials.saveToDisk();
681
+ await deadline.wait(() => credentials.saveToDisk());
640
682
  }
641
683
  catch (error) {
684
+ checkAborted();
642
685
  log.error('Failed to persist project context', {
643
686
  error: String(error),
644
687
  });
@@ -666,7 +709,7 @@ export function createRequestExecutor(deps) {
666
709
  if (accessTokenExpired(authRecord)) {
667
710
  try {
668
711
  await assertAdmission();
669
- const refreshed = await credentials.refresh(account);
712
+ const refreshed = await deadline.wait(() => credentials.refresh(account));
670
713
  if (!refreshed) {
671
714
  const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
672
715
  trackers.health.recordFailure(account.index);
@@ -683,7 +726,7 @@ export function createRequestExecutor(deps) {
683
726
  }
684
727
  if (shouldCooldown) {
685
728
  accountManager.markAccountCoolingDown(account, cooldownMs, 'auth-failure');
686
- accountManager.markRateLimited(account, cooldownMs, family, 'antigravity', model);
729
+ accountManager.markRateLimited(account, cooldownMs, family, model);
687
730
  pushDebug(`token-refresh-failed: cooldown ${cooldownMs}ms after ${failures} failures`);
688
731
  }
689
732
  continue;
@@ -693,23 +736,26 @@ export function createRequestExecutor(deps) {
693
736
  authRecord = refreshed;
694
737
  grantCheck = captureFor(authRecord);
695
738
  try {
696
- await credentials.saveToDisk();
739
+ await deadline.wait(() => credentials.saveToDisk());
697
740
  }
698
741
  catch (error) {
742
+ checkAborted();
699
743
  log.error('Failed to persist refreshed auth', {
700
744
  error: String(error),
701
745
  });
702
746
  }
703
747
  }
704
748
  catch (error) {
749
+ checkAborted();
705
750
  if (credentials.isInvalidGrant(error)) {
706
751
  const removed = credentials.removeAccount(account);
707
752
  if (removed) {
708
753
  log.warn('Removed revoked account from pool - reauthenticate via `opencode auth login`');
709
754
  try {
710
- await credentials.saveToDiskReplace();
755
+ await deadline.wait(() => credentials.saveToDiskReplace());
711
756
  }
712
757
  catch (persistError) {
758
+ checkAborted();
713
759
  log.error('Failed to persist revoked account removal', {
714
760
  error: String(persistError),
715
761
  });
@@ -717,9 +763,10 @@ export function createRequestExecutor(deps) {
717
763
  }
718
764
  if (accountManager.getAccountCount() === 0) {
719
765
  try {
720
- await credentials.clearStoredAuth();
766
+ await deadline.wait(() => credentials.clearStoredAuth());
721
767
  }
722
768
  catch (storeError) {
769
+ checkAborted();
723
770
  log.error('Failed to clear stored Antigravity OAuth credentials', {
724
771
  error: String(storeError),
725
772
  });
@@ -736,7 +783,7 @@ export function createRequestExecutor(deps) {
736
783
  error instanceof Error ? error : new Error(String(error));
737
784
  if (shouldCooldown) {
738
785
  accountManager.markAccountCoolingDown(account, cooldownMs, 'auth-failure');
739
- accountManager.markRateLimited(account, cooldownMs, family, 'antigravity', model);
786
+ accountManager.markRateLimited(account, cooldownMs, family, model);
740
787
  pushDebug(`token-refresh-error: cooldown ${cooldownMs}ms after ${failures} failures`);
741
788
  }
742
789
  continue;
@@ -760,12 +807,13 @@ export function createRequestExecutor(deps) {
760
807
  retryState.resetAccountFailureState(account.index);
761
808
  }
762
809
  catch (error) {
810
+ checkAborted();
763
811
  const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
764
812
  trackers.health.recordFailure(account.index);
765
813
  lastError = error instanceof Error ? error : new Error(String(error));
766
814
  if (shouldCooldown) {
767
815
  accountManager.markAccountCoolingDown(account, cooldownMs, 'project-error');
768
- accountManager.markRateLimited(account, cooldownMs, family, 'antigravity', model);
816
+ accountManager.markRateLimited(account, cooldownMs, family, model);
769
817
  pushDebug(`project-context-error: cooldown ${cooldownMs}ms after ${failures} failures`);
770
818
  }
771
819
  continue;
@@ -781,10 +829,10 @@ export function createRequestExecutor(deps) {
781
829
  const credentialForAuxiliarySend = async (sendInit, preparedProjectId) => {
782
830
  await assertAdmission();
783
831
  if (credentials.domain === 'vault') {
784
- const admission = await credentials.admit({
832
+ const admission = await deadline.wait(() => credentials.admit({
785
833
  account: selected,
786
834
  signal: abortSignal,
787
- });
835
+ }));
788
836
  selectedCredentials.add(admission.accessToken);
789
837
  if (admission.projectId !== preparedProjectId) {
790
838
  throw new Error('The vault served another project for this send; skipping it');
@@ -796,7 +844,7 @@ export function createRequestExecutor(deps) {
796
844
  if (!localGrant) {
797
845
  throw new Error('Local credentials were not resolved for the selected account');
798
846
  }
799
- await localGrant.captured.check();
847
+ await deadline.wait(() => localGrant.captured.check());
800
848
  await assertAdmission();
801
849
  return { init: sendInit };
802
850
  };
@@ -833,20 +881,21 @@ export function createRequestExecutor(deps) {
833
881
  try {
834
882
  pushDebug('thinking-warmup: start');
835
883
  const warmupSend = await credentialForAuxiliarySend(warmupInit, projectId);
836
- const warmupResponse = prepared.headerStyle === 'antigravity'
837
- ? await transport(warmupUrl, warmupSend.init, {
838
- signal: abortSignal,
839
- onDebug: pushDebug,
840
- })
841
- : await upstreamFetch(warmupUrl, warmupSend.init);
884
+ const warmupResponse = await transport(warmupUrl, warmupSend.init, {
885
+ signal: abortSignal,
886
+ onDebug: pushDebug,
887
+ });
842
888
  reportVault401(warmupSend.admission, warmupResponse.status);
843
- const transformed = await wire.transformResponse(warmupResponse, true, warmupDebugContext, prepared.requestedModel, projectId, warmupUrl, prepared.effectiveModel, prepared.sessionId);
844
- await transformed.text();
889
+ const transformed = await deadline.wait(() => wire.transformResponse(warmupResponse, true, warmupDebugContext, prepared.requestedModel, projectId, warmupUrl, prepared.effectiveModel, prepared.sessionId));
890
+ await deadline.wait(() => transformed.text());
845
891
  warmupState.markSuccess(prepared.sessionId);
846
892
  pushDebug('thinking-warmup: done');
847
893
  }
848
894
  catch (error) {
849
895
  warmupState.clearWarmupAttempt(prepared.sessionId);
896
+ if (error instanceof PreResponseTimeoutError)
897
+ throw error;
898
+ checkAborted();
850
899
  if (isLocalGrantError(error))
851
900
  throw error;
852
901
  pushDebug(`thinking-warmup: failed ${error instanceof Error ? error.message : String(error)}`);
@@ -864,23 +913,21 @@ export function createRequestExecutor(deps) {
864
913
  try {
865
914
  pushDebug('cache-warmup-probe: start');
866
915
  const probeSend = await credentialForAuxiliarySend({ ...prepared.init, method: 'POST', body: bodyStr }, prepared.projectId ?? '');
867
- const probeResponse = prepared.headerStyle === 'antigravity'
868
- ? await transport(toUrlString(prepared.request), probeSend.init, {
869
- signal: abortSignal,
870
- onDebug: pushDebug,
871
- })
872
- : await upstreamFetch(toUrlString(prepared.request), probeSend.init);
916
+ const probeResponse = await transport(toUrlString(prepared.request), probeSend.init, {
917
+ signal: abortSignal,
918
+ onDebug: pushDebug,
919
+ });
873
920
  reportVault401(probeSend.admission, probeResponse.status);
874
921
  if (probeResponse.body) {
875
922
  const reader = probeResponse.body.getReader();
876
- await reader.read();
877
- await reader.cancel();
923
+ await deadline.wait(() => reader.read());
924
+ await deadline.wait(() => reader.cancel());
878
925
  }
879
926
  const status = probeResponse.status;
880
927
  if (status >= 400) {
881
928
  let errorSnippet = '';
882
929
  try {
883
- const errText = await probeResponse.text().catch(() => '');
930
+ const errText = await deadline.wait(() => probeResponse.text().catch(() => ''));
884
931
  errorSnippet = errText.slice(0, 200);
885
932
  }
886
933
  catch {
@@ -893,6 +940,9 @@ export function createRequestExecutor(deps) {
893
940
  }
894
941
  }
895
942
  catch (error) {
943
+ if (error instanceof PreResponseTimeoutError)
944
+ throw error;
945
+ checkAborted();
896
946
  if (isLocalGrantError(error)) {
897
947
  needsCacheWarmup = true;
898
948
  throw error;
@@ -902,57 +952,11 @@ export function createRequestExecutor(deps) {
902
952
  };
903
953
  let apiRequestCount = 0;
904
954
  let shouldSwitchAccount = false;
905
- let headerStyle = preferredHeaderStyle;
906
- pushDebug(`headerStyle=${headerStyle} explicit=${explicitQuota}`);
907
955
  if (account.fingerprint) {
908
956
  pushDebug(`fingerprint: deviceId=${account.fingerprint.deviceId.slice(0, 8)}...`);
909
957
  }
910
- if (accountManager.isRateLimitedForHeaderStyle(account, family, headerStyle, model)) {
911
- if (allowQuotaFallback &&
912
- family === 'gemini' &&
913
- headerStyle === 'antigravity') {
914
- if (accountManager.hasOtherAccountWithAntigravityAvailable(account.index, family, model)) {
915
- pushDebug(`antigravity rate-limited on account ${account.index}, but available on other accounts. Switching.`);
916
- shouldSwitchAccount = true;
917
- }
918
- else {
919
- const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model);
920
- const fallbackStyle = resolveQuotaFallbackHeaderStyle({
921
- family,
922
- headerStyle,
923
- alternateStyle,
924
- });
925
- if (fallbackStyle) {
926
- await showToast(`Antigravity quota exhausted on all accounts. Using Gemini CLI quota.`, 'warning');
927
- headerStyle = fallbackStyle;
928
- pushDebug(`all-accounts antigravity exhausted, quota fallback: ${headerStyle}`);
929
- }
930
- else {
931
- shouldSwitchAccount = true;
932
- }
933
- }
934
- }
935
- else if (allowQuotaFallback && family === 'gemini') {
936
- const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model);
937
- const fallbackStyle = resolveQuotaFallbackHeaderStyle({
938
- family,
939
- headerStyle,
940
- alternateStyle,
941
- });
942
- if (fallbackStyle) {
943
- const quotaName = headerStyle === 'gemini-cli' ? 'Gemini CLI' : 'Antigravity';
944
- const altQuotaName = fallbackStyle === 'gemini-cli' ? 'Gemini CLI' : 'Antigravity';
945
- await showToast(`${quotaName} quota exhausted, using ${altQuotaName} quota`, 'warning');
946
- headerStyle = fallbackStyle;
947
- pushDebug(`quota fallback: ${headerStyle}`);
948
- }
949
- else {
950
- shouldSwitchAccount = true;
951
- }
952
- }
953
- else {
954
- shouldSwitchAccount = true;
955
- }
958
+ if (accountManager.isRateLimited(account, family, model)) {
959
+ shouldSwitchAccount = true;
956
960
  }
957
961
  let totalCapacityRetries = 0;
958
962
  while (!shouldSwitchAccount) {
@@ -969,11 +973,6 @@ export function createRequestExecutor(deps) {
969
973
  lastEndpointIndex = i;
970
974
  }
971
975
  const currentEndpoint = ANTIGRAVITY_ENDPOINT_FALLBACKS[i];
972
- if (headerStyle === 'gemini-cli' &&
973
- currentEndpoint !== 'https://cloudcode-pa.googleapis.com') {
974
- pushDebug(`Skipping sandbox endpoint ${currentEndpoint} for gemini-cli headerStyle`);
975
- continue;
976
- }
977
976
  let tokenConsumed = false;
978
977
  let physicalAttemptStarted = false;
979
978
  try {
@@ -989,10 +988,10 @@ export function createRequestExecutor(deps) {
989
988
  // retry it was taken for, then is gone.
990
989
  sendAdmission =
991
990
  rotatedAdmission ??
992
- (await credentials.admit({
991
+ (await deadline.wait(() => credentials.admit({
993
992
  account,
994
993
  signal: abortSignal,
995
- }));
994
+ })));
996
995
  rotatedAdmission = undefined;
997
996
  sendAccessToken = sendAdmission.accessToken;
998
997
  sendProjectId = sendAdmission.projectId;
@@ -1004,6 +1003,8 @@ export function createRequestExecutor(deps) {
1004
1003
  else {
1005
1004
  throw new Error('Local credentials were not resolved for the selected account');
1006
1005
  }
1006
+ if (sendProjectId)
1007
+ selectedProjectIds.add(sendProjectId);
1007
1008
  selectedCredentials.add(sendAccessToken);
1008
1009
  const prepared = prepareAgyWireRequest(wire, {
1009
1010
  input,
@@ -1011,7 +1012,6 @@ export function createRequestExecutor(deps) {
1011
1012
  accessToken: sendAccessToken,
1012
1013
  projectId: sendProjectId,
1013
1014
  endpoint: currentEndpoint,
1014
- headerStyle,
1015
1015
  forceThinkingRecovery,
1016
1016
  options: {
1017
1017
  claudeToolHardening: config.claude_tool_hardening,
@@ -1019,6 +1019,7 @@ export function createRequestExecutor(deps) {
1019
1019
  fingerprint: account.fingerprint,
1020
1020
  agySession: agyRequestSession,
1021
1021
  agyRequestTimestamp: agyRequestScope.timestamp,
1022
+ variant,
1022
1023
  },
1023
1024
  });
1024
1025
  const originalUrl = toUrlString(input);
@@ -1057,7 +1058,6 @@ export function createRequestExecutor(deps) {
1057
1058
  sessionId: prepared.sessionId,
1058
1059
  toolDebugMissing: prepared.toolDebugMissing,
1059
1060
  toolDebugSummary: prepared.toolDebugSummary,
1060
- toolDebugPayload: prepared.toolDebugPayload,
1061
1061
  dumpContext,
1062
1062
  });
1063
1063
  await runThinkingWarmup(prepared, sendProjectId);
@@ -1076,14 +1076,14 @@ export function createRequestExecutor(deps) {
1076
1076
  if (!localGrant) {
1077
1077
  throw new Error('Local credentials were not resolved for the selected account');
1078
1078
  }
1079
- await localGrant.captured.check();
1079
+ await deadline.wait(() => localGrant.captured.check());
1080
1080
  await assertAdmission();
1081
1081
  }
1082
1082
  pushDebug(`dispatching request via ${prepared.headerStyle} transport`);
1083
1083
  physicalAttemptStarted = true;
1084
- const response = prepared.headerStyle === 'antigravity'
1085
- ? await transport(toUrlString(prepared.request), prepared.init, { signal: abortSignal, onDebug: pushDebug })
1086
- : await upstreamFetch(prepared.request, prepared.init);
1084
+ const response = await transport(toUrlString(prepared.request), prepared.init, { signal: abortSignal, onDebug: pushDebug });
1085
+ if (response.ok)
1086
+ deadline.acceptHeaders();
1087
1087
  apiRequestCount++;
1088
1088
  accountManager.recordRequest(account.index, family);
1089
1089
  const requestCounts = accountManager.getDailyRequestCounts(account.index);
@@ -1100,18 +1100,19 @@ export function createRequestExecutor(deps) {
1100
1100
  // version of the same credential and account may retry this
1101
1101
  // endpoint, once; otherwise the 401 stands.
1102
1102
  try {
1103
- await sendAdmission.report401(response.status);
1103
+ await deadline.wait(() => sendAdmission.report401(response.status));
1104
1104
  }
1105
1105
  catch (error) {
1106
+ checkAborted();
1106
1107
  log.debug('send-admission-401-report-failed', {
1107
1108
  error: String(error),
1108
1109
  });
1109
1110
  }
1110
1111
  if (!vault401Retried) {
1111
- const next = await credentials.admit({
1112
+ const next = await deadline.wait(() => credentials.admit({
1112
1113
  account,
1113
1114
  signal: abortSignal,
1114
- });
1115
+ }));
1115
1116
  if (next.credentialId === sendAdmission.credentialId &&
1116
1117
  next.accountIdentity === sendAdmission.accountIdentity &&
1117
1118
  next.recordVersion > sendAdmission.recordVersion) {
@@ -1150,7 +1151,7 @@ export function createRequestExecutor(deps) {
1150
1151
  const headerRetryMs = retryAfterMsFromResponse(response, defaultRetryMs);
1151
1152
  const bodyInfo = await (async () => {
1152
1153
  try {
1153
- const text = await response.clone().text();
1154
+ const text = await deadline.wait(() => response.clone().text());
1154
1155
  try {
1155
1156
  return JSON.parse(text);
1156
1157
  }
@@ -1159,6 +1160,7 @@ export function createRequestExecutor(deps) {
1159
1160
  }
1160
1161
  }
1161
1162
  catch {
1163
+ checkAborted();
1162
1164
  return null;
1163
1165
  }
1164
1166
  })();
@@ -1199,7 +1201,7 @@ export function createRequestExecutor(deps) {
1199
1201
  continue;
1200
1202
  }
1201
1203
  }
1202
- const quotaKey = retryState.headerStyleToQuotaKey(headerStyle, family);
1204
+ const quotaKey = getQuotaKey(family, model);
1203
1205
  const backoff = retryState.getRateLimitBackoff(account.index, quotaKey, serverRetryMs);
1204
1206
  const smartBackoffMs = calculateBackoffMs(rateLimitReason, account.consecutiveFailures ?? 0, serverRetryMs);
1205
1207
  const effectiveDelayMs = Math.max(backoff.delayMs, smartBackoffMs);
@@ -1211,7 +1213,7 @@ export function createRequestExecutor(deps) {
1211
1213
  if (reasonInfo.reason)
1212
1214
  pushDebug(`429 reason=${reasonInfo.reason}`);
1213
1215
  debug.logRateLimitEvent(account.index, account.email, family, response.status, effectiveDelayMs, reasonInfo);
1214
- await debug.logResponseBody(debugContext, response, 429);
1216
+ await logResponseBody(debugContext, response, 429);
1215
1217
  trackers.health.recordRateLimit(account.index);
1216
1218
  const _accountLabel = account.email || `Account ${account.index + 1}`;
1217
1219
  if (backoff.attempt === 1 &&
@@ -1223,7 +1225,7 @@ export function createRequestExecutor(deps) {
1223
1225
  if (effectiveDelayMs <= maxCacheFirstWaitMs) {
1224
1226
  pushDebug(`cache_first: waiting ${effectiveDelayMs}ms for same account to recover`);
1225
1227
  await showToast(`⏳ Waiting ${Math.ceil(effectiveDelayMs / 1000)}s for same account (prompt cache preserved)...`, 'info');
1226
- accountManager.markRateLimitedWithReason(account, family, headerStyle, model, rateLimitReason, serverRetryMs);
1228
+ accountManager.markRateLimitedWithReason(account, family, model, rateLimitReason, serverRetryMs);
1227
1229
  await sleep(effectiveDelayMs, abortSignal);
1228
1230
  i -= 1;
1229
1231
  continue;
@@ -1231,59 +1233,16 @@ export function createRequestExecutor(deps) {
1231
1233
  pushDebug(`cache_first: wait ${effectiveDelayMs}ms exceeds max ${maxCacheFirstWaitMs}ms, switching account`);
1232
1234
  }
1233
1235
  if (config.switch_on_first_rate_limit && accountCount > 1) {
1234
- accountManager.markRateLimitedWithReason(account, family, headerStyle, model, rateLimitReason, serverRetryMs, config.failure_ttl_seconds * 1000);
1236
+ accountManager.markRateLimitedWithReason(account, family, model, rateLimitReason, serverRetryMs, config.failure_ttl_seconds * 1000);
1235
1237
  shouldSwitchAccount = true;
1236
1238
  break;
1237
1239
  }
1238
1240
  i -= 1;
1239
1241
  continue;
1240
1242
  }
1241
- accountManager.markRateLimitedWithReason(account, family, headerStyle, model, rateLimitReason, serverRetryMs, config.failure_ttl_seconds * 1000);
1243
+ accountManager.markRateLimitedWithReason(account, family, model, rateLimitReason, serverRetryMs, config.failure_ttl_seconds * 1000);
1242
1244
  accountManager.requestSaveToDisk();
1243
1245
  const switchAccountDelayMs = config.switch_account_delay_ms ?? 500;
1244
- if (family === 'gemini') {
1245
- if (headerStyle === 'antigravity') {
1246
- if (hasOtherAccountWithAntigravity(account)) {
1247
- pushDebug(`antigravity exhausted on account ${account.index}, but available on others. Switching account.`);
1248
- await showToast(`Rate limited again. Switching account in ${formatWaitTime(switchAccountDelayMs)}...`, 'warning');
1249
- await sleep(switchAccountDelayMs, abortSignal);
1250
- shouldSwitchAccount = true;
1251
- break;
1252
- }
1253
- if (allowQuotaFallback) {
1254
- const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model);
1255
- const fallbackStyle = resolveQuotaFallbackHeaderStyle({
1256
- family,
1257
- headerStyle,
1258
- alternateStyle,
1259
- });
1260
- if (fallbackStyle) {
1261
- const safeModelName = model || 'this model';
1262
- await showToast(`Antigravity quota exhausted for ${safeModelName}. Switching to Gemini CLI quota...`, 'warning');
1263
- headerStyle = fallbackStyle;
1264
- pushDebug(`quota fallback: ${headerStyle}`);
1265
- continue;
1266
- }
1267
- }
1268
- }
1269
- else if (headerStyle === 'gemini-cli') {
1270
- if (allowQuotaFallback) {
1271
- const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model);
1272
- const fallbackStyle = resolveQuotaFallbackHeaderStyle({
1273
- family,
1274
- headerStyle,
1275
- alternateStyle,
1276
- });
1277
- if (fallbackStyle) {
1278
- const safeModelName = model || 'this model';
1279
- await showToast(`Gemini CLI quota exhausted for ${safeModelName}. Switching to Antigravity quota...`, 'warning');
1280
- headerStyle = fallbackStyle;
1281
- pushDebug(`quota fallback: ${headerStyle}`);
1282
- continue;
1283
- }
1284
- }
1285
- }
1286
- }
1287
1246
  if (accountCount > 1) {
1288
1247
  const quotaMsg = reasonInfo.quotaResetTime
1289
1248
  ? ` (quota resets ${reasonInfo.quotaResetTime})`
@@ -1303,14 +1262,14 @@ export function createRequestExecutor(deps) {
1303
1262
  shouldSwitchAccount = true;
1304
1263
  break;
1305
1264
  }
1306
- const quotaKey = retryState.headerStyleToQuotaKey(headerStyle, family);
1265
+ const quotaKey = getQuotaKey(family, model);
1307
1266
  retryState.resetRateLimitState(account.index, quotaKey);
1308
1267
  retryState.resetAccountFailureState(account.index);
1309
1268
  if (response.status === 403) {
1310
- const errorBodyText = await response
1269
+ const errorBodyText = await deadline.wait(() => response
1311
1270
  .clone()
1312
1271
  .text()
1313
- .catch(() => '');
1272
+ .catch(() => ''));
1314
1273
  const extracted = classifyAccessError(errorBodyText);
1315
1274
  if (extracted.accountIneligible) {
1316
1275
  const ineligibleReason = extracted.message ??
@@ -1333,7 +1292,7 @@ export function createRequestExecutor(deps) {
1333
1292
  const cooldownMs = 10 * 60 * 1000;
1334
1293
  accountManager.markAccountVerificationRequired(account.index, verificationReason, extracted.verifyUrl);
1335
1294
  accountManager.markAccountCoolingDown(account, cooldownMs, 'validation-required');
1336
- accountManager.markRateLimited(account, cooldownMs, family, headerStyle, model);
1295
+ accountManager.markRateLimited(account, cooldownMs, family, model);
1337
1296
  const label = account.email || `Account ${account.index + 1}`;
1338
1297
  if (accountManager.shouldShowAccountToast(account.index, 60000)) {
1339
1298
  await showToast(`⚠ ${label} needs verification. Run 'opencode auth login' and use Verify accounts.`, 'warning');
@@ -1351,24 +1310,35 @@ export function createRequestExecutor(deps) {
1351
1310
  response.status >= 500;
1352
1311
  if (shouldRetryEndpoint &&
1353
1312
  i < ANTIGRAVITY_ENDPOINT_FALLBACKS.length - 1) {
1354
- await debug.logResponseBody(debugContext, response, response.status);
1313
+ await logResponseBody(debugContext, response, response.status);
1355
1314
  lastFailure = createFailureContext(response);
1356
1315
  continue;
1357
1316
  }
1358
1317
  if (response.ok) {
1359
1318
  account.consecutiveFailures = 0;
1360
1319
  trackers.health.recordSuccess(account.index);
1361
- accountManager.markAccountUsed(account.index);
1320
+ if (!advisoryClosing)
1321
+ accountManager.markAccountUsed(account.index);
1362
1322
  if (credentials.domain === 'local' &&
1323
+ !advisoryClosing &&
1363
1324
  credentials.refreshQuotaAfterSuccess) {
1364
- void credentials
1365
- .refreshQuotaAfterSuccess(account, config.quota_refresh_interval_minutes)
1366
- .catch(() => { });
1325
+ const quotaCancellation = createRequestCancellation(init?.signal
1326
+ ? [init.signal, shutdown.signal]
1327
+ : [shutdown.signal]);
1328
+ const work = credentials
1329
+ .refreshQuotaAfterSuccess(account, config.quota_refresh_interval_minutes, quotaCancellation.signal)
1330
+ .catch(() => {
1331
+ log.debug('post-response-advisory-work-failed');
1332
+ })
1333
+ .finally(() => quotaCancellation.release());
1334
+ advisoryWork.add(work);
1335
+ void work.then(() => advisoryWork.delete(work), () => advisoryWork.delete(work));
1367
1336
  }
1368
1337
  const proactiveThreshold = config.proactive_rotation_threshold_percent ?? 20;
1369
- if (proactiveThreshold > 0 &&
1338
+ if (!advisoryClosing &&
1339
+ proactiveThreshold > 0 &&
1370
1340
  accountManager.shouldProactivelyRotate(family, model, proactiveThreshold, softQuotaCacheTtlMs, accountSessionIdentity)) {
1371
- const rotated = accountManager.proactivelyRotateForFamily(family, model, headerStyle, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, accountSessionIdentity);
1341
+ const rotated = accountManager.proactivelyRotateForFamily(family, model, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, accountSessionIdentity);
1372
1342
  if (rotated) {
1373
1343
  const remaining = account.cachedQuota?.[resolveQuotaGroup(family, model)]
1374
1344
  ?.remainingFraction;
@@ -1383,13 +1353,13 @@ export function createRequestExecutor(deps) {
1383
1353
  note: response.ok ? 'Success' : `Error ${response.status}`,
1384
1354
  });
1385
1355
  if (response.ok && !prepared.streaming) {
1386
- await debug.logResponseBody(debugContext, response, response.status);
1356
+ await logResponseBody(debugContext, response, response.status);
1387
1357
  }
1388
1358
  if (!response.ok) {
1389
- await debug.logResponseBody(debugContext, response, response.status);
1359
+ await logResponseBody(debugContext, response, response.status);
1390
1360
  if (response.status === 400) {
1391
1361
  const cloned = response.clone();
1392
- const bodyText = await cloned.text();
1362
+ const bodyText = await deadline.wait(() => cloned.text());
1393
1363
  if (bodyText.includes('Prompt is too long') ||
1394
1364
  bodyText.includes('prompt_too_long')) {
1395
1365
  await showToast('Context too long - use /compact to reduce size', 'warning');
@@ -1404,12 +1374,13 @@ export function createRequestExecutor(deps) {
1404
1374
  const maxAttempts = config.empty_response_max_attempts ?? 4;
1405
1375
  const retryDelayMs = config.empty_response_retry_delay_ms ?? 2000;
1406
1376
  const clonedForCheck = response.clone();
1407
- const bodyText = await clonedForCheck.text();
1377
+ const bodyText = await deadline.wait(() => clonedForCheck.text());
1408
1378
  if (isEmptyResponseBody(bodyText)) {
1409
1379
  const emptyAttemptKey = `${prepared.sessionId ?? 'none'}:${prepared.effectiveModel ?? 'unknown'}`;
1410
1380
  const currentAttempts = retryState.recordEmptyResponseAttempt(emptyAttemptKey);
1411
1381
  pushDebug(`empty-response: attempt ${currentAttempts}/${maxAttempts}`);
1412
1382
  if (currentAttempts < maxAttempts) {
1383
+ deadline.resume();
1413
1384
  await showToast(`Empty response received. Retrying (${currentAttempts}/${maxAttempts})...`, 'warning');
1414
1385
  await sleep(retryDelayMs, abortSignal);
1415
1386
  continue;
@@ -1423,7 +1394,7 @@ export function createRequestExecutor(deps) {
1423
1394
  const _emptyAttemptKeyClean = `${prepared.sessionId ?? 'none'}:${prepared.effectiveModel ?? 'unknown'}`;
1424
1395
  retryState.clearEmptyResponseAttempts();
1425
1396
  }
1426
- const transformedResponse = await wire.transformResponse(response, prepared.streaming, debugContext, prepared.requestedModel, prepared.projectId, prepared.endpoint, prepared.effectiveModel, prepared.sessionId, prepared.toolDebugMissing, prepared.toolDebugSummary, prepared.toolDebugPayload, debugLines, dumpContext);
1397
+ const transformedResponse = await deadline.wait(() => wire.transformResponse(response, prepared.streaming, debugContext, prepared.requestedModel, prepared.projectId, prepared.endpoint, prepared.effectiveModel, prepared.sessionId, prepared.toolDebugMissing, prepared.toolDebugSummary, debugLines, dumpContext));
1427
1398
  const contextError = transformedResponse.headers.get('x-antigravity-context-error');
1428
1399
  if (contextError) {
1429
1400
  if (contextError === 'prompt_too_long') {
@@ -1464,6 +1435,9 @@ export function createRequestExecutor(deps) {
1464
1435
  return transformedResponse;
1465
1436
  }
1466
1437
  catch (error) {
1438
+ if (error instanceof PreResponseTimeoutError)
1439
+ throw error;
1440
+ checkAborted();
1467
1441
  if (tokenConsumed &&
1468
1442
  (!isLocalGrantError(error) || !physicalAttemptStarted)) {
1469
1443
  trackers.token.refund(account.index);
@@ -1479,7 +1453,8 @@ export function createRequestExecutor(deps) {
1479
1453
  !localRecaptureUsed) {
1480
1454
  localRecaptureUsed = true;
1481
1455
  try {
1482
- await localGrant.captured.resolveCurrent();
1456
+ const originalGrant = localGrant.captured;
1457
+ await deadline.wait(() => originalGrant.resolveCurrent());
1483
1458
  const auth = credentials.toAuthDetails(account);
1484
1459
  if (!auth.access || accessTokenExpired(auth))
1485
1460
  return createNativeGoogleErrorResponse({
@@ -1506,6 +1481,7 @@ export function createRequestExecutor(deps) {
1506
1481
  if (error instanceof Error &&
1507
1482
  error.message === 'THINKING_RECOVERY_NEEDED') {
1508
1483
  if (!forceThinkingRecovery) {
1484
+ deadline.resume();
1509
1485
  pushDebug('thinking-recovery: API error detected, retrying with forced recovery');
1510
1486
  forceThinkingRecovery = true;
1511
1487
  i = -1;
@@ -1537,7 +1513,7 @@ export function createRequestExecutor(deps) {
1537
1513
  error instanceof Error ? error : new Error(String(error));
1538
1514
  if (shouldCooldown) {
1539
1515
  accountManager.markAccountCoolingDown(account, cooldownMs, 'network-error');
1540
- accountManager.markRateLimited(account, cooldownMs, family, headerStyle, model);
1516
+ accountManager.markRateLimited(account, cooldownMs, family, model);
1541
1517
  pushDebug(`endpoint-error: cooldown ${cooldownMs}ms after ${failures} failures`);
1542
1518
  }
1543
1519
  shouldSwitchAccount = true;
@@ -1550,20 +1526,20 @@ export function createRequestExecutor(deps) {
1550
1526
  if (accountSwitchCount > maxAccountSwitches) {
1551
1527
  pushDebug(`account-switch-cap: exceeded max_account_switches=${maxAccountSwitches}, giving up`);
1552
1528
  if (lastFailure) {
1553
- return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, lastFailure.toolDebugPayload, debugLines, lastFailure.dumpContext);
1529
+ return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, debugLines, lastFailure.dumpContext);
1554
1530
  }
1555
1531
  throw terminalFetchError(lastError, `Exceeded max account switches (${maxAccountSwitches}). All accounts rate-limited.`);
1556
1532
  }
1557
1533
  if (accountCount <= 1) {
1558
1534
  if (lastFailure) {
1559
- return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, lastFailure.toolDebugPayload, debugLines, lastFailure.dumpContext);
1535
+ return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, debugLines, lastFailure.dumpContext);
1560
1536
  }
1561
1537
  throw terminalFetchError(lastError, 'All Antigravity endpoints failed');
1562
1538
  }
1563
1539
  continue;
1564
1540
  }
1565
1541
  if (lastFailure) {
1566
- return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, lastFailure.toolDebugPayload, debugLines, lastFailure.dumpContext);
1542
+ return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, debugLines, lastFailure.dumpContext);
1567
1543
  }
1568
1544
  throw terminalFetchError(lastError, 'All Antigravity accounts failed');
1569
1545
  }
@@ -1571,10 +1547,13 @@ export function createRequestExecutor(deps) {
1571
1547
  // Waits for every admitted request and retained body, then releases the
1572
1548
  // bookkeeping they use. Runs once, whether `retire` or `dispose` asks first.
1573
1549
  function drain() {
1550
+ advisoryClosing = true;
1574
1551
  drainPromise ??= (async () => {
1575
1552
  // A refresh that already exchanged tokens must finish its owned store write.
1576
1553
  while (inFlight.size > 0)
1577
1554
  await Promise.allSettled([...inFlight]);
1555
+ while (advisoryWork.size > 0)
1556
+ await Promise.allSettled([...advisoryWork]);
1578
1557
  retryState.dispose();
1579
1558
  warmupState.dispose();
1580
1559
  })();
@@ -1602,26 +1581,46 @@ export function createRequestExecutor(deps) {
1602
1581
  const cancellation = createRequestCancellation(requestedSignal
1603
1582
  ? [requestedSignal, shutdown.signal]
1604
1583
  : [shutdown.signal]);
1584
+ const deadline = new PreResponseDeadline(cancellation.signal, deps.preResponseClock);
1585
+ log.debug('pre-response-start', { limitMs: PRE_RESPONSE_DEADLINE_MS });
1586
+ const waitPolicy = {};
1605
1587
  const selectedCredentials = new Set();
1606
- const pending = execute(input, { ...init, signal: cancellation.signal }, requestOptions, selectedCredentials)
1588
+ const selectedProjectIds = new Set();
1589
+ const pending = deadline
1590
+ .wait(() => execute(input, { ...init, signal: deadline.signal }, requestOptions ?? {}, selectedCredentials, selectedProjectIds, deadline, waitPolicy))
1591
+ .catch((error) => {
1592
+ cancellation.signal.throwIfAborted();
1593
+ if (error instanceof PreResponseTimeoutError) {
1594
+ log.debug('pre-response-timeout', { reason: error.reason });
1595
+ return waitPolicy.refusal?.() ?? preResponseTimeoutResponse();
1596
+ }
1597
+ throw error;
1598
+ })
1607
1599
  .then(async (response) => {
1600
+ // Retain caller cancellation over the accepted response body;
1601
+ // only the pre-response timer ends at accepted headers.
1602
+ deadline.acceptTerminalResponse();
1608
1603
  // Overflow classification read a clone to EOF. Reuse that text
1609
1604
  // for redaction; safe diagnostics retain the original unread response.
1610
1605
  if (bufferedOverflow.has(response)) {
1606
+ deadline.dispose();
1611
1607
  cancellation.release();
1612
- return redactCredentialResponse(response, [...selectedCredentials], bufferedOverflow.get(response));
1608
+ return redactCredentialResponse(response, [...selectedCredentials], bufferedOverflow.get(response), [...selectedProjectIds]);
1613
1609
  }
1614
1610
  const retained = await retainResponseLifetime(response, cancellation);
1615
1611
  inFlight.add(retained.settled);
1616
1612
  void retained.settled.then(() => inFlight.delete(retained.settled));
1617
- return redactCredentialResponse(preserveResponseMetadata(retained.response, response), [...selectedCredentials]);
1613
+ void retained.settled.then(() => deadline.dispose());
1614
+ return redactCredentialResponse(preserveResponseMetadata(retained.response, response), [...selectedCredentials], undefined, [...selectedProjectIds]);
1618
1615
  }, (error) => {
1616
+ deadline.dispose();
1619
1617
  cancellation.release();
1620
- throw redactCredentialError(error, [...selectedCredentials]);
1618
+ throw redactCredentialError(error, [...selectedCredentials], [...selectedProjectIds]);
1621
1619
  })
1622
1620
  .catch((error) => {
1621
+ deadline.dispose();
1623
1622
  cancellation.release();
1624
- throw redactCredentialError(error, [...selectedCredentials]);
1623
+ throw redactCredentialError(error, [...selectedCredentials], [...selectedProjectIds]);
1625
1624
  });
1626
1625
  inFlight.add(pending);
1627
1626
  void pending.then(() => inFlight.delete(pending), () => inFlight.delete(pending));