@cortexkit/opencode-antigravity-auth 3.0.1 → 3.0.2

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 (138) hide show
  1. package/dist/cli.js.map +2 -2
  2. package/dist/cli.meta.json +3 -3
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.js +1136 -928
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +107 -25
  7. package/dist/server.js +267 -37
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -7313
  10. package/dist/src/cli.d.ts +1 -1
  11. package/dist/src/constants.d.ts +1 -1
  12. package/dist/src/ga/rpc/protocol.d.ts +1 -1
  13. package/dist/src/ga/server/index.d.ts +6 -6
  14. package/dist/src/ga/server/index.d.ts.map +1 -1
  15. package/dist/src/ga/server/index.js +29 -1
  16. package/dist/src/ga/server/index.js.map +1 -1
  17. package/dist/src/ga/tui/host-ga.d.ts +2 -2
  18. package/dist/src/hooks/auto-update-checker/checker.d.ts +1 -1
  19. package/dist/src/hooks/auto-update-checker/index.d.ts +4 -4
  20. package/dist/src/plugin/account-access.d.ts +6 -6
  21. package/dist/src/plugin/account-command-oauth.d.ts +2 -2
  22. package/dist/src/plugin/accounts.d.ts +3 -3
  23. package/dist/src/plugin/auth-doctor.d.ts +2 -2
  24. package/dist/src/plugin/auth-drift.d.ts +2 -2
  25. package/dist/src/plugin/auth-loader.d.ts +8 -8
  26. package/dist/src/plugin/auth-loader.d.ts.map +1 -1
  27. package/dist/src/plugin/auth-loader.js +1 -0
  28. package/dist/src/plugin/auth-loader.js.map +1 -1
  29. package/dist/src/plugin/background-quota-refresh.d.ts +3 -3
  30. package/dist/src/plugin/background-vault-quota-refresh.d.ts +43 -0
  31. package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -0
  32. package/dist/src/plugin/background-vault-quota-refresh.js +155 -0
  33. package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -0
  34. package/dist/src/plugin/cache/index.d.ts +1 -1
  35. package/dist/src/plugin/cache/signature-cache.d.ts +2 -2
  36. package/dist/src/plugin/cache.d.ts +6 -6
  37. package/dist/src/plugin/cli.d.ts +6 -6
  38. package/dist/src/plugin/command-apply.d.ts +1 -1
  39. package/dist/src/plugin/command-data.d.ts +6 -4
  40. package/dist/src/plugin/command-data.d.ts.map +1 -1
  41. package/dist/src/plugin/command-data.js +13 -34
  42. package/dist/src/plugin/command-data.js.map +1 -1
  43. package/dist/src/plugin/commands.d.ts +4 -4
  44. package/dist/src/plugin/config/index.d.ts +2 -2
  45. package/dist/src/plugin/config/loader.d.ts +2 -2
  46. package/dist/src/plugin/config/models.d.ts +2 -2
  47. package/dist/src/plugin/config/writer.d.ts +2 -2
  48. package/dist/src/plugin/core/streaming/index.d.ts +2 -2
  49. package/dist/src/plugin/core/streaming/transformer.d.ts +1 -1
  50. package/dist/src/plugin/debug.d.ts +1 -1
  51. package/dist/src/plugin/dependencies.d.ts +3 -3
  52. package/dist/src/plugin/event-handler.d.ts +3 -3
  53. package/dist/src/plugin/fetch-interceptor.d.ts +10 -10
  54. package/dist/src/plugin/fetch-routing.d.ts +3 -3
  55. package/dist/src/plugin/ga-location-services.d.ts +10 -10
  56. package/dist/src/plugin/google-search-tool.d.ts +1 -1
  57. package/dist/src/plugin/index.d.ts +8 -6
  58. package/dist/src/plugin/index.d.ts.map +1 -1
  59. package/dist/src/plugin/index.js +41 -18
  60. package/dist/src/plugin/index.js.map +1 -1
  61. package/dist/src/plugin/killswitch.d.ts +1 -1
  62. package/dist/src/plugin/lifecycle.d.ts +2 -2
  63. package/dist/src/plugin/logger.d.ts +2 -2
  64. package/dist/src/plugin/oauth-login.d.ts +1 -1
  65. package/dist/src/plugin/oauth-methods.d.ts +9 -9
  66. package/dist/src/plugin/operator-settings.d.ts +3 -3
  67. package/dist/src/plugin/persist-account-pool.d.ts +1 -1
  68. package/dist/src/plugin/quota.d.ts +5 -4
  69. package/dist/src/plugin/quota.d.ts.map +1 -1
  70. package/dist/src/plugin/quota.js +1 -0
  71. package/dist/src/plugin/quota.js.map +1 -1
  72. package/dist/src/plugin/recovery/index.d.ts +3 -3
  73. package/dist/src/plugin/recovery/storage.d.ts +1 -1
  74. package/dist/src/plugin/recovery.d.ts +3 -3
  75. package/dist/src/plugin/refresh-queue.d.ts +3 -3
  76. package/dist/src/plugin/request-helpers.d.ts +1 -1
  77. package/dist/src/plugin/request.d.ts +9 -9
  78. package/dist/src/plugin/session-context.d.ts +1 -1
  79. package/dist/src/plugin/shared/request-services.d.ts +9 -9
  80. package/dist/src/plugin/shared/runtime.d.ts +11 -11
  81. package/dist/src/plugin/shared/source-sidebar.d.ts +1 -1
  82. package/dist/src/plugin/shared/vault-menu.d.ts +1 -1
  83. package/dist/src/plugin/shared/vault-request-credentials.d.ts +3 -1
  84. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  85. package/dist/src/plugin/shared/vault-request-credentials.js +1 -1
  86. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  87. package/dist/src/plugin/stores/signature-store.d.ts +1 -1
  88. package/dist/src/plugin/token.d.ts +1 -1
  89. package/dist/src/plugin/ui/auth-menu.d.ts +4 -4
  90. package/dist/src/plugin/ui/model-status.d.ts +3 -3
  91. package/dist/src/plugin/ui/quota-status.d.ts +2 -2
  92. package/dist/src/plugin/vault-activation.d.ts +1 -1
  93. package/dist/src/plugin/vault-quota-refresh.d.ts +7 -0
  94. package/dist/src/plugin/vault-quota-refresh.d.ts.map +1 -0
  95. package/dist/src/plugin/vault-quota-refresh.js +12 -0
  96. package/dist/src/plugin/vault-quota-refresh.js.map +1 -0
  97. package/dist/src/plugin/vault-sidebar-projection.d.ts +27 -0
  98. package/dist/src/plugin/vault-sidebar-projection.d.ts.map +1 -0
  99. package/dist/src/plugin/vault-sidebar-projection.js +34 -0
  100. package/dist/src/plugin/vault-sidebar-projection.js.map +1 -0
  101. package/dist/src/rpc/notifications.d.ts +1 -1
  102. package/dist/src/rpc/rpc-server.d.ts +1 -1
  103. package/dist/src/server.d.ts +3 -3
  104. package/dist/src/sidebar-state.d.ts +20 -13
  105. package/dist/src/sidebar-state.d.ts.map +1 -1
  106. package/dist/src/sidebar-state.js +20 -10
  107. package/dist/src/sidebar-state.js.map +1 -1
  108. package/dist/src/tui/command-dialogs.d.ts +1 -1
  109. package/dist/src/tui/host-v1.d.ts +3 -3
  110. package/dist/src/tui.d.ts +3 -3
  111. package/dist/src/tui.js +1 -1
  112. package/dist/tui-build-map.json +6 -6
  113. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  114. package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
  115. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts +43 -0
  116. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -0
  117. package/dist/types/src/plugin/command-data.d.ts +6 -4
  118. package/dist/types/src/plugin/command-data.d.ts.map +1 -1
  119. package/dist/types/src/plugin/index.d.ts +2 -0
  120. package/dist/types/src/plugin/index.d.ts.map +1 -1
  121. package/dist/types/src/plugin/quota.d.ts +1 -0
  122. package/dist/types/src/plugin/quota.d.ts.map +1 -1
  123. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +2 -0
  124. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  125. package/dist/types/src/plugin/vault-quota-refresh.d.ts +7 -0
  126. package/dist/types/src/plugin/vault-quota-refresh.d.ts.map +1 -0
  127. package/dist/types/src/plugin/vault-sidebar-projection.d.ts +27 -0
  128. package/dist/types/src/plugin/vault-sidebar-projection.d.ts.map +1 -0
  129. package/dist/types/src/sidebar-state.d.ts +20 -13
  130. package/dist/types/src/sidebar-state.d.ts.map +1 -1
  131. package/package.json +2 -2
  132. package/src/plugin/command-data.ts +19 -47
  133. package/src/sidebar-state.ts +34 -15
  134. package/src/tui-compiled/sidebar-state.js +12 -5
  135. package/src/tui-compiled/tui.js +1 -1
  136. package/src/tui-raw/sidebar-state.js +12 -5
  137. package/src/tui-raw/tui.tsx +1 -1
  138. package/src/tui.tsx +1 -1
package/dist/server.js CHANGED
@@ -28984,7 +28984,7 @@ function createStoreAccountLimits(input2) {
28984
28984
  }
28985
28985
 
28986
28986
  // src/sidebar-state.ts
28987
- import { mkdirSync as mkdirSync3, readFileSync as readFileSync5 } from "node:fs";
28987
+ import { chmodSync as chmodSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync5 } from "node:fs";
28988
28988
  import { homedir as homedir4 } from "node:os";
28989
28989
  import { dirname as dirname15, join as join13 } from "node:path";
28990
28990
 
@@ -29008,7 +29008,7 @@ if (xdgConfig) {
29008
29008
  }
29009
29009
 
29010
29010
  // src/sidebar-state.ts
29011
- var SIDEBAR_STATE_VERSION = 1;
29011
+ var SIDEBAR_STATE_VERSION = 2;
29012
29012
  var DEFAULT_SIDEBAR_STATE = {
29013
29013
  version: SIDEBAR_STATE_VERSION,
29014
29014
  checkedAt: 0,
@@ -29069,7 +29069,7 @@ function normalizeSidebarState(input2) {
29069
29069
  }
29070
29070
  const record2 = input2;
29071
29071
  const version = record2.version;
29072
- if (version !== SIDEBAR_STATE_VERSION) {
29072
+ if (version !== 1 && version !== SIDEBAR_STATE_VERSION) {
29073
29073
  return {
29074
29074
  ...DEFAULT_SIDEBAR_STATE,
29075
29075
  lastError: `unsupported-version:${stringifySafe(version)}`
@@ -29124,6 +29124,7 @@ function normalizeAccount(input2) {
29124
29124
  return {
29125
29125
  id,
29126
29126
  label,
29127
+ ...typeof record2.email === "string" ? { email: record2.email } : {},
29127
29128
  enabled,
29128
29129
  health,
29129
29130
  current,
@@ -29145,6 +29146,7 @@ function normalizeQuota(input2) {
29145
29146
  if (!isObject(input2)) return null;
29146
29147
  const record2 = input2;
29147
29148
  const remaining = toFiniteNumber(record2.remainingPercent);
29149
+ const fraction = toFiniteNumber(record2.remainingFraction);
29148
29150
  if (remaining === null) return null;
29149
29151
  const resetAt = toFiniteNumber(record2.resetAt) ?? void 0;
29150
29152
  const checkedAt = toFiniteNumber(record2.checkedAt) ?? void 0;
@@ -29158,10 +29160,12 @@ function normalizeQuota(input2) {
29158
29160
  );
29159
29161
  const ra = toFiniteNumber(w.resetAt);
29160
29162
  const ca = toFiniteNumber(w.checkedAt);
29163
+ const rf = toFiniteNumber(w.remainingFraction);
29161
29164
  if (win !== "weekly" && win !== "5h" || rp === null) return null;
29162
29165
  return {
29163
29166
  window: win,
29164
29167
  remainingPercent: clampNumber(rp, 0, 100),
29168
+ ...rf !== null ? { remainingFraction: clampNumber(rf, 0, 1) } : {},
29165
29169
  resetAt: ra ?? void 0,
29166
29170
  ...ca !== null && ca >= 0 ? { checkedAt: ca } : {}
29167
29171
  };
@@ -29170,6 +29174,7 @@ function normalizeQuota(input2) {
29170
29174
  }
29171
29175
  return {
29172
29176
  remainingPercent: clampNumber(remaining, 0, 100),
29177
+ ...fraction !== null ? { remainingFraction: clampNumber(fraction, 0, 1) } : {},
29173
29178
  resetAt,
29174
29179
  ...checkedAt !== void 0 ? { checkedAt } : {},
29175
29180
  windows
@@ -29221,6 +29226,7 @@ function stringifySafe(value) {
29221
29226
  }
29222
29227
  function ensureSidebarStateDir(path5 = getSidebarStateFile()) {
29223
29228
  mkdirSync3(dirname15(path5), { recursive: true, mode: SIDEBAR_STATE_DIR_MODE });
29229
+ chmodSync3(dirname15(path5), SIDEBAR_STATE_DIR_MODE);
29224
29230
  }
29225
29231
  function pruneActiveRouting(map, now) {
29226
29232
  const cutoff = now - ACTIVE_ROUTING_MAX_AGE_MS;
@@ -29299,6 +29305,7 @@ function projectQuotaPoolForSidebar(source, checkedAt) {
29299
29305
  0,
29300
29306
  100
29301
29307
  ),
29308
+ remainingFraction: clampNumber(w.remainingFraction, 0, 1),
29302
29309
  resetAt: typeof w.resetTime === "string" && w.resetTime.length > 0 ? (() => {
29303
29310
  const parsed = Date.parse(w.resetTime);
29304
29311
  return Number.isFinite(parsed) ? parsed : void 0;
@@ -29306,6 +29313,7 @@ function projectQuotaPoolForSidebar(source, checkedAt) {
29306
29313
  })) : void 0;
29307
29314
  return {
29308
29315
  remainingPercent,
29316
+ remainingFraction: clampNumber(fraction, 0, 1),
29309
29317
  resetAt,
29310
29318
  windows,
29311
29319
  ...readingAt !== void 0 ? { checkedAt: readingAt } : {}
@@ -29342,6 +29350,7 @@ function redactAccountForSidebar(source) {
29342
29350
  return {
29343
29351
  id,
29344
29352
  label,
29353
+ ...typeof source.email === "string" ? { email: source.email } : {},
29345
29354
  enabled,
29346
29355
  health,
29347
29356
  current,
@@ -29664,6 +29673,7 @@ async function pushSidebarQuotaSnapshot(getAccounts, backoffUntil = 0, getActive
29664
29673
  accounts.map((entry) => ({
29665
29674
  index: entry.index,
29666
29675
  label: entry.label,
29676
+ email: entry.email,
29667
29677
  enabled: entry.enabled,
29668
29678
  current: activeByFamily ? isAccountCurrent(entry.index, activeByFamily) : false,
29669
29679
  coolingDownUntil: entry.coolingDownUntil,
@@ -31095,7 +31105,7 @@ function clearSignatureCache(sessionId) {
31095
31105
  }
31096
31106
 
31097
31107
  // src/plugin/image-saver.ts
31098
- import { chmodSync as chmodSync3, existsSync as existsSync9, mkdirSync as mkdirSync5, writeFileSync as writeFileSync3 } from "node:fs";
31108
+ import { chmodSync as chmodSync4, existsSync as existsSync9, mkdirSync as mkdirSync5, writeFileSync as writeFileSync3 } from "node:fs";
31099
31109
  import { homedir as homedir6 } from "node:os";
31100
31110
  import { join as join15 } from "node:path";
31101
31111
  function getImageOutputDir(outputDir) {
@@ -31103,7 +31113,7 @@ function getImageOutputDir(outputDir) {
31103
31113
  if (!existsSync9(resolved)) {
31104
31114
  mkdirSync5(resolved, { recursive: true, mode: 448 });
31105
31115
  }
31106
- chmodSync3(resolved, 448);
31116
+ chmodSync4(resolved, 448);
31107
31117
  return resolved;
31108
31118
  }
31109
31119
  function generateImageFilename(mimeType) {
@@ -31124,7 +31134,7 @@ function saveImageToDisk(base64Data, mimeType, outputDir) {
31124
31134
  const resolvedOutputDir = getImageOutputDir(outputDir);
31125
31135
  const filePath = join15(resolvedOutputDir, generateImageFilename(mimeType));
31126
31136
  writeFileSync3(filePath, Buffer.from(base64Data, "base64"), { mode: 384 });
31127
- chmodSync3(filePath, 384);
31137
+ chmodSync4(filePath, 384);
31128
31138
  return filePath;
31129
31139
  } catch (error) {
31130
31140
  console.error("[image-saver] Failed to save image:", error);
@@ -43858,10 +43868,32 @@ function createGaRpcActivation(options) {
43858
43868
  accountsStatus: { kind: "complete" },
43859
43869
  accounts: accounts.rows.map(({ selector, row }) => ({
43860
43870
  selector,
43861
- ...redactAccountForSidebar(row)
43871
+ ...gaAccountFields(redactAccountForSidebar(row))
43862
43872
  }))
43863
43873
  };
43864
43874
  };
43875
+ const gaAccountFields = (account) => {
43876
+ const { email: _email, quota, ...rest } = account;
43877
+ const entry = (value) => {
43878
+ if (value === void 0) return void 0;
43879
+ const { remainingFraction: _fraction, windows, ...fields } = value;
43880
+ return windows === void 0 ? fields : {
43881
+ ...fields,
43882
+ windows: windows.map(
43883
+ ({ remainingFraction: _windowFraction, ...window }) => window
43884
+ )
43885
+ };
43886
+ };
43887
+ const gemini = entry(quota.gemini);
43888
+ const nonGemini = entry(quota["non-gemini"]);
43889
+ return {
43890
+ ...rest,
43891
+ quota: {
43892
+ ...gemini ? { gemini } : {},
43893
+ ...nonGemini ? { "non-gemini": nonGemini } : {}
43894
+ }
43895
+ };
43896
+ };
43865
43897
  const state = async (input2, signal) => {
43866
43898
  const parsed = AntigravityStateInputSchema.parse(input2);
43867
43899
  if (!parsed.ok) throw new GaRpcInputError(parsed.issues);
@@ -49045,6 +49077,7 @@ function createAuthLoader({
49045
49077
  return {
49046
49078
  index: entry.index,
49047
49079
  label: entry.label,
49080
+ email: entry.email,
49048
49081
  enabled: entry.enabled,
49049
49082
  current: isAccountCurrent(entry.index, activeByFamily),
49050
49083
  coolingDownUntil: entry.coolingDownUntil,
@@ -49298,6 +49331,185 @@ function createAuthLoader({
49298
49331
  return authLoader;
49299
49332
  }
49300
49333
 
49334
+ // src/plugin/vault-quota-refresh.ts
49335
+ async function checkAndPublishVaultQuota(input2, publishSidebar) {
49336
+ const report = await checkVaultQuota(input2);
49337
+ if (report.checked > 0 && !input2.signal.aborted) await publishSidebar();
49338
+ return report;
49339
+ }
49340
+
49341
+ // src/plugin/vault-sidebar-projection.ts
49342
+ function quotaReadingForVaultRoute(route, state) {
49343
+ const stored = state.accounts[route.accountIdentity];
49344
+ return stored?.observed.routeId === route.routeId && stored.observed.credentialId === route.credentialId ? stored.quota : void 0;
49345
+ }
49346
+ function buildVaultSidebarProjection(pool, state, checkedAt = Date.now()) {
49347
+ const projection = buildSidebarMachineStateFromAccounts(
49348
+ pool.selector.rows.map((row) => {
49349
+ const quota = quotaReadingForVaultRoute(row.route, state);
49350
+ return {
49351
+ index: row.index,
49352
+ email: row.route.email,
49353
+ enabled: row.enabled,
49354
+ current: false,
49355
+ coolingDownUntil: row.coolingDownUntil,
49356
+ healthScore: pool.selector.healthTracker.getScore(row.index),
49357
+ cachedQuota: quota ? cachedQuotaOf(quota) : void 0,
49358
+ cachedQuotaUpdatedAt: quota?.cachedQuotaUpdatedAt ?? void 0
49359
+ };
49360
+ }),
49361
+ { checkedAt }
49362
+ );
49363
+ return {
49364
+ ...projection,
49365
+ accounts: projection.accounts.map((account) => ({
49366
+ ...account,
49367
+ id: `vault-${account.id}`
49368
+ }))
49369
+ };
49370
+ }
49371
+
49372
+ // src/plugin/background-vault-quota-refresh.ts
49373
+ var BackgroundVaultQuotaRefresh = class {
49374
+ constructor(options) {
49375
+ this.options = options;
49376
+ this.now = options.now ?? Date.now;
49377
+ this.random = options.random ?? Math.random;
49378
+ this.acquireLock = options.acquireLock ?? acquireFencedFileLock;
49379
+ }
49380
+ options;
49381
+ timer = null;
49382
+ inFlight = null;
49383
+ controller = null;
49384
+ disposed = false;
49385
+ started = false;
49386
+ now;
49387
+ random;
49388
+ acquireLock;
49389
+ start() {
49390
+ if (this.disposed || this.started) return;
49391
+ this.started = true;
49392
+ this.schedule(Math.floor(this.random() * 3e4));
49393
+ }
49394
+ /** Custody notifications cancel admitted work as soon as authority changes. */
49395
+ abortTick() {
49396
+ this.controller?.abort();
49397
+ }
49398
+ async dispose() {
49399
+ this.disposed = true;
49400
+ if (this.timer !== null) clearTimeout(this.timer);
49401
+ this.timer = null;
49402
+ this.abortTick();
49403
+ await this.inFlight;
49404
+ }
49405
+ schedule(delay) {
49406
+ if (this.disposed || !this.started) return;
49407
+ this.timer = setTimeout(() => {
49408
+ this.timer = null;
49409
+ void this.tick();
49410
+ }, delay);
49411
+ this.timer.unref?.();
49412
+ }
49413
+ /** One serialized tick; also used by deterministic composition tests. */
49414
+ tick() {
49415
+ if (this.disposed) return Promise.resolve();
49416
+ if (this.inFlight) return this.inFlight;
49417
+ const controller = new AbortController();
49418
+ this.controller = controller;
49419
+ let extraJitter = 0;
49420
+ this.inFlight = this.runTick(controller).catch(() => {
49421
+ extraJitter = 15e3;
49422
+ }).finally(() => {
49423
+ this.inFlight = null;
49424
+ this.controller = null;
49425
+ this.schedule(
49426
+ this.options.intervalMs + Math.floor(this.random() * this.options.intervalMs * 0.1) + extraJitter
49427
+ );
49428
+ });
49429
+ return this.inFlight;
49430
+ }
49431
+ async assertActive(controller) {
49432
+ if (this.disposed || await this.options.readAuthority() !== "vault")
49433
+ controller.abort();
49434
+ controller.signal.throwIfAborted();
49435
+ }
49436
+ async runTick(controller) {
49437
+ await this.assertActive(controller);
49438
+ ensureSidebarStateDir(this.options.sidebarStateFile);
49439
+ const lock = await this.acquireLock({
49440
+ path: this.options.sidebarStateFile,
49441
+ name: "bg-vault-quota-poll",
49442
+ ttlMs: 6e4,
49443
+ renew: true
49444
+ });
49445
+ if (!lock) return;
49446
+ let released = false;
49447
+ void lock.whenLost().then(() => {
49448
+ if (!released) controller.abort();
49449
+ });
49450
+ try {
49451
+ await this.assertActive(controller);
49452
+ await lock.assertOwned();
49453
+ const { source, pool } = await this.options.currentVaultPool();
49454
+ await this.assertActive(controller);
49455
+ await pool.sync();
49456
+ await this.assertActive(controller);
49457
+ const state = await this.options.readProviderState();
49458
+ await this.assertActive(controller);
49459
+ await lock.assertOwned();
49460
+ const threshold = Math.max(
49461
+ this.options.intervalMs - 6e4,
49462
+ Math.floor(this.options.intervalMs / 2)
49463
+ );
49464
+ const now = this.now();
49465
+ const due = pool.selector.rows.some((row) => {
49466
+ const quota = quotaReadingForVaultRoute(row.route, state);
49467
+ const at = quota?.cachedQuotaUpdatedAt;
49468
+ return quota?.cachedQuota == null || typeof at !== "number" || !Number.isFinite(at) || at < 0 || now - at >= threshold;
49469
+ });
49470
+ if (!due) return;
49471
+ await checkAndPublishVaultQuota(
49472
+ {
49473
+ pool,
49474
+ signal: controller.signal,
49475
+ now: this.now,
49476
+ fetchReading: async (ref, signal) => {
49477
+ await this.assertActive(controller);
49478
+ const reading = await fetchVaultAccountQuota({
49479
+ source,
49480
+ ref,
49481
+ signal,
49482
+ logger: this.options.logger,
49483
+ transport: async (url, init, extra) => {
49484
+ await this.assertActive(controller);
49485
+ await lock.assertOwned();
49486
+ controller.signal.throwIfAborted();
49487
+ return this.options.transport(
49488
+ url,
49489
+ { ...init, signal: extra.signal ?? controller.signal },
49490
+ extra
49491
+ );
49492
+ }
49493
+ });
49494
+ await this.assertActive(controller);
49495
+ await lock.assertOwned();
49496
+ return reading;
49497
+ }
49498
+ },
49499
+ async () => {
49500
+ await this.assertActive(controller);
49501
+ await lock.assertOwned();
49502
+ await this.options.publishSidebar();
49503
+ }
49504
+ );
49505
+ } finally {
49506
+ released = true;
49507
+ await lock.release().catch(() => {
49508
+ });
49509
+ }
49510
+ }
49511
+ };
49512
+
49301
49513
  // src/plugin/prompt-context.ts
49302
49514
  function isRecord15(value) {
49303
49515
  return typeof value === "object" && value !== null;
@@ -50568,6 +50780,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
50568
50780
  await drainSidebarWrites();
50569
50781
  }
50570
50782
  });
50783
+ let vaultQuotaPoller;
50571
50784
  const vaultCustody = createOpenCodeVaultCustody({
50572
50785
  accountFile: resolve11(getStoragePath()),
50573
50786
  readHostSlot: async () => {
@@ -50578,7 +50791,10 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
50578
50791
  // The request executor reports failed bearer authorization to Claustrum,
50579
50792
  // which decides whether its served credential needs replacement.
50580
50793
  reporterSource: "direct",
50581
- onAuthorityChanged: () => scheduleSidebarPublication(),
50794
+ onAuthorityChanged: (authority) => {
50795
+ if (authority !== "vault") vaultQuotaPoller?.abortTick();
50796
+ scheduleSidebarPublication();
50797
+ },
50582
50798
  onRosterChanged: () => scheduleSidebarPublication()
50583
50799
  });
50584
50800
  let vaultPool;
@@ -50625,6 +50841,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
50625
50841
  return manager.getAccounts().map((entry) => ({
50626
50842
  index: entry.index,
50627
50843
  label: entry.label,
50844
+ email: entry.email,
50628
50845
  enabled: entry.enabled,
50629
50846
  current: isAccountCurrent(entry.index, activeByFamily),
50630
50847
  coolingDownUntil: entry.coolingDownUntil,
@@ -50652,6 +50869,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
50652
50869
  return buildSidebarMachineStateFromAccounts(
50653
50870
  manager?.getAccounts().map((entry) => ({
50654
50871
  index: entry.index,
50872
+ email: entry.email,
50655
50873
  enabled: entry.enabled,
50656
50874
  current: active2 ? isAccountCurrent(entry.index, active2) : false,
50657
50875
  coolingDownUntil: entry.coolingDownUntil,
@@ -50669,23 +50887,13 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
50669
50887
  vault: async () => {
50670
50888
  const { pool } = await currentVaultPool();
50671
50889
  await pool.sync();
50672
- const projection = buildSidebarMachineStateFromAccounts(
50673
- pool.selector.rows.map((entry) => ({
50674
- index: entry.index,
50675
- enabled: entry.enabled,
50676
- current: false,
50677
- coolingDownUntil: entry.coolingDownUntil,
50678
- healthScore: pool.selector.healthTracker.getScore(entry.index),
50679
- cachedQuota: entry.cachedQuota,
50680
- cachedQuotaUpdatedAt: entry.cachedQuotaUpdatedAt
50681
- }))
50890
+ const projection = buildVaultSidebarProjection(
50891
+ pool,
50892
+ await vaultCustody.readState(),
50893
+ dependencies.clock.now()
50682
50894
  );
50683
50895
  return {
50684
50896
  ...projection,
50685
- accounts: projection.accounts.map((account) => ({
50686
- ...account,
50687
- id: `vault-${account.id}`
50688
- })),
50689
50897
  ...projection.accounts.length === 0 ? { lastError: VAULT_ACCOUNT_REMEDY } : {}
50690
50898
  };
50691
50899
  },
@@ -50764,6 +50972,21 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
50764
50972
  options._onPollerCreated?.(poller);
50765
50973
  poller.start();
50766
50974
  lifecycle.register({ dispose: () => poller.dispose() }, "producer");
50975
+ vaultQuotaPoller = new BackgroundVaultQuotaRefresh({
50976
+ intervalMs: config.background_quota_refresh_interval_minutes * 6e4,
50977
+ sidebarStateFile: getSidebarStateFile(),
50978
+ readAuthority: readAuthority2,
50979
+ currentVaultPool,
50980
+ readProviderState: () => vaultCustody.readState(),
50981
+ publishSidebar: () => sidebarPublisher.publish(),
50982
+ transport: dependencies.fetchImpl,
50983
+ logger,
50984
+ now: dependencies.clock.now,
50985
+ random: dependencies.clock.random
50986
+ });
50987
+ options._onVaultPollerCreated?.(vaultQuotaPoller);
50988
+ vaultQuotaPoller.start();
50989
+ lifecycle.register(vaultQuotaPoller, "producer");
50767
50990
  }
50768
50991
  const operatorSettings = createOperatorSettingsController({
50769
50992
  projectConfigPath: join29(directory, ".opencode", "antigravity.json"),
@@ -50887,17 +51110,21 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
50887
51110
  vaultSelectors2.set(key, selector);
50888
51111
  return selector;
50889
51112
  },
50890
- (signal) => checkVaultQuota({
50891
- pool,
50892
- signal,
50893
- fetchReading: (ref, check) => fetchVaultAccountQuota({
50894
- source,
50895
- ref,
50896
- signal: check,
50897
- logger,
50898
- transport: dependencies.fetchImpl
50899
- })
50900
- })
51113
+ (signal) => checkAndPublishVaultQuota(
51114
+ {
51115
+ pool,
51116
+ signal,
51117
+ now: dependencies.clock.now,
51118
+ fetchReading: (ref, check) => fetchVaultAccountQuota({
51119
+ source,
51120
+ ref,
51121
+ signal: check,
51122
+ logger,
51123
+ transport: dependencies.fetchImpl
51124
+ })
51125
+ },
51126
+ () => sidebarPublisher.publish()
51127
+ )
50901
51128
  )
50902
51129
  })
50903
51130
  };
@@ -51145,10 +51372,8 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
51145
51372
  apply: async (request) => {
51146
51373
  const current = await currentMenu();
51147
51374
  if (current.kind === "unavailable") throw new Error(current.message);
51148
- const result = await current.menu.apply(
51149
- request,
51150
- menuInvocation(pushNotification, request.sessionId)
51151
- );
51375
+ const invocation = menuInvocation(pushNotification, request.sessionId);
51376
+ const result = await current.menu.apply(request, invocation);
51152
51377
  try {
51153
51378
  if (await readAuthority2() === "local")
51154
51379
  await lifecycle.getAccountManager()?.refreshFromRepository();
@@ -51165,6 +51390,11 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
51165
51390
  request.sessionId
51166
51391
  );
51167
51392
  }
51393
+ const refreshed = await currentMenu();
51394
+ if (refreshed.kind === "menu" && refreshed.menu !== current.menu) {
51395
+ const payload = await refreshed.menu.open(invocation);
51396
+ return { ...result, menu: payload.menu };
51397
+ }
51168
51398
  return result;
51169
51399
  },
51170
51400
  drain: drainNotifications