@cortexkit/opencode-antigravity-auth 3.0.8 → 3.0.9

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 (68) hide show
  1. package/dist/cli.js +96 -15
  2. package/dist/cli.js.map +3 -3
  3. package/dist/cli.meta.json +25 -15
  4. package/dist/index.js +256 -69
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +43 -30
  7. package/dist/server.js +261 -72
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/common-auth-embedded/auth-menu/login.d.ts +6 -10
  11. package/dist/src/common-auth-embedded/auth-menu/login.js +14 -11
  12. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +5 -1
  13. package/dist/src/common-auth-embedded/claustrum/consumer.js +40 -1
  14. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  15. package/dist/src/common-auth-embedded/claustrum/insula.d.ts +23 -0
  16. package/dist/src/common-auth-embedded/claustrum/insula.js +64 -2
  17. package/dist/src/common-auth-embedded/source-output.json +27 -27
  18. package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  19. package/dist/src/plugin/background-vault-quota-refresh.js +8 -1
  20. package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
  21. package/dist/src/plugin/index.d.ts.map +1 -1
  22. package/dist/src/plugin/index.js +1 -0
  23. package/dist/src/plugin/index.js.map +1 -1
  24. package/dist/src/plugin/quota.d.ts +1 -1
  25. package/dist/src/plugin/quota.d.ts.map +1 -1
  26. package/dist/src/plugin/quota.js +17 -5
  27. package/dist/src/plugin/quota.js.map +1 -1
  28. package/dist/src/plugin/shared/vault-request-credentials.d.ts +9 -6
  29. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  30. package/dist/src/plugin/shared/vault-request-credentials.js +9 -4
  31. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  32. package/dist/src/plugin/vault-custody.d.ts +2 -0
  33. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  34. package/dist/src/plugin/vault-custody.js +9 -0
  35. package/dist/src/plugin/vault-custody.js.map +1 -1
  36. package/dist/src/plugin/vault-insula-quota.d.ts +6 -0
  37. package/dist/src/plugin/vault-insula-quota.d.ts.map +1 -0
  38. package/dist/src/plugin/vault-insula-quota.js +50 -0
  39. package/dist/src/plugin/vault-insula-quota.js.map +1 -0
  40. package/dist/src/plugin/vault-quota-outcome.d.ts +1 -1
  41. package/dist/src/plugin/vault-quota-outcome.d.ts.map +1 -1
  42. package/dist/src/plugin/vault-quota-outcome.js.map +1 -1
  43. package/dist/tui-build-map.json +1 -1
  44. package/dist/tui-ga-build-map.json +1 -1
  45. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +5 -1
  46. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  47. package/dist/types/src/common-auth-embedded/claustrum/insula.d.ts +23 -0
  48. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  49. package/dist/types/src/plugin/index.d.ts.map +1 -1
  50. package/dist/types/src/plugin/quota.d.ts +1 -1
  51. package/dist/types/src/plugin/quota.d.ts.map +1 -1
  52. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +9 -6
  53. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  54. package/dist/types/src/plugin/vault-custody.d.ts +2 -0
  55. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  56. package/dist/types/src/plugin/vault-insula-quota.d.ts +6 -0
  57. package/dist/types/src/plugin/vault-insula-quota.d.ts.map +1 -0
  58. package/dist/types/src/plugin/vault-quota-outcome.d.ts +1 -1
  59. package/dist/types/src/plugin/vault-quota-outcome.d.ts.map +1 -1
  60. package/package.json +2 -2
  61. package/src/common-auth-embedded/auth-menu/login.d.ts +6 -10
  62. package/src/common-auth-embedded/auth-menu/login.js +14 -11
  63. package/src/common-auth-embedded/claustrum/consumer.d.ts +5 -1
  64. package/src/common-auth-embedded/claustrum/consumer.js +40 -1
  65. package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  66. package/src/common-auth-embedded/claustrum/insula.d.ts +23 -0
  67. package/src/common-auth-embedded/claustrum/insula.js +64 -2
  68. package/src/common-auth-embedded/source-output.json +27 -27
package/dist/server.js CHANGED
@@ -323,8 +323,8 @@ function displayOrder(left, right) {
323
323
  return left.label < right.label ? -1 : left.label > right.label ? 1 : 0;
324
324
  }
325
325
  function quotaWindowParts(quota, options) {
326
- const { windows, age } = scopedWindowParts(quota, options);
327
- const parts = windows.map(({ part }) => part);
326
+ const { windows: windows2, age } = scopedWindowParts(quota, options);
327
+ const parts = windows2.map(({ part }) => part);
328
328
  return age === void 0 ? { windows: parts } : { windows: parts, age };
329
329
  }
330
330
  function scopedWindowParts(quota, options) {
@@ -332,7 +332,7 @@ function scopedWindowParts(quota, options) {
332
332
  return { windows: [] };
333
333
  const { now } = options;
334
334
  const readings = quota.limits.filter((limit) => limit.kind === "reading" && limit.remainingPercent !== void 0).sort(displayOrder);
335
- const windows = readings.map((limit) => {
335
+ const windows2 = readings.map((limit) => {
336
336
  const remainingPercent = clampPercent(limit.remainingPercent ?? 0);
337
337
  return {
338
338
  scope: limit.scope,
@@ -351,7 +351,7 @@ function scopedWindowParts(quota, options) {
351
351
  if (budget) {
352
352
  const remainingPercent = budget.remainingPercent;
353
353
  const figure = budget.reached ? "credits spent" : remainingPercent !== void 0 ? `credits ${percentLeft(remainingPercent)}` : "credits available";
354
- windows.push({
354
+ windows2.push({
355
355
  scope: ALL_SCOPE,
356
356
  spent: budget.reached,
357
357
  part: {
@@ -364,13 +364,13 @@ function scopedWindowParts(quota, options) {
364
364
  }
365
365
  });
366
366
  }
367
- if (windows.length > 0) {
368
- const age = now - Math.min(...windows.map(({ part }) => part.checkedAt));
367
+ if (windows2.length > 0) {
368
+ const age = now - Math.min(...windows2.map(({ part }) => part.checkedAt));
369
369
  if (age > (options.staleAfterMs ?? QUOTA_STALE_AFTER_MS)) {
370
- return { windows, age: `checked ${shortSpan(age)} ago` };
370
+ return { windows: windows2, age: `checked ${shortSpan(age)} ago` };
371
371
  }
372
372
  }
373
- return { windows };
373
+ return { windows: windows2 };
374
374
  }
375
375
  function isQuotaStale(quota, options) {
376
376
  return scopedWindowParts(quota, options).age !== void 0;
@@ -410,10 +410,10 @@ function groupShortNames(groups) {
410
410
  const short = scopeAbbreviations(labels);
411
411
  return labels.map((label) => short.get(label) ?? label);
412
412
  }
413
- function groupedNarrowPieces(groups, windows) {
413
+ function groupedNarrowPieces(groups, windows2) {
414
414
  if (!groups || groups.length === 0)
415
415
  return void 0;
416
- const reported = windows.filter(({ part }) => part.kind === "window");
416
+ const reported = windows2.filter(({ part }) => part.kind === "window");
417
417
  if (reported.some(({ scope }) => scope === ALL_SCOPE))
418
418
  return void 0;
419
419
  const candidates = groups.flatMap((group, listed) => {
@@ -437,14 +437,14 @@ function groupedNarrowPieces(groups, windows) {
437
437
  });
438
438
  }
439
439
  function narrowTextParts(quota, options) {
440
- const { windows } = scopedWindowParts(quota, options);
441
- const grouped = groupedNarrowPieces(quota?.groups, windows);
440
+ const { windows: windows2 } = scopedWindowParts(quota, options);
441
+ const grouped = groupedNarrowPieces(quota?.groups, windows2);
442
442
  if (grouped)
443
443
  return grouped;
444
- const general = windows.filter(({ part, scope }) => part.kind === "window" && scope === ALL_SCOPE);
445
- const scoped = windows.filter(({ part, scope }) => part.kind === "window" && scope !== ALL_SCOPE);
444
+ const general = windows2.filter(({ part, scope }) => part.kind === "window" && scope === ALL_SCOPE);
445
+ const scoped = windows2.filter(({ part, scope }) => part.kind === "window" && scope !== ALL_SCOPE);
446
446
  const abbreviations = scopeAbbreviations(scoped.map(({ scope }) => scope));
447
- const budget = windows.find(({ part }) => part.kind === "budget");
447
+ const budget = windows2.find(({ part }) => part.kind === "budget");
448
448
  const budgetLeft = budget?.spent ? 0 : budget?.part.remainingPercent;
449
449
  const extras = [
450
450
  ...scoped.map(({ scope, part }) => ({
@@ -459,7 +459,7 @@ function narrowTextParts(quota, options) {
459
459
  pieces.push(`${tightest.label} ${wholePercent(tightest.remaining)}%`);
460
460
  }
461
461
  if (pieces.length === 0)
462
- return windows.map(({ part }) => part.figure);
462
+ return windows2.map(({ part }) => part.figure);
463
463
  return pieces.map((piece, index) => index === pieces.length - 1 ? `${piece} left` : piece);
464
464
  }
465
465
  function quotaTextParts(quota, options) {
@@ -7227,12 +7227,12 @@ var init_doctor = __esm({
7227
7227
  });
7228
7228
 
7229
7229
  // ../core/dist/common-auth-embedded/auth-menu/login.js
7230
- import { execFileSync as defaultExecFileSync, spawn as defaultSpawn } from "node:child_process";
7231
- function openBrowserForMenu(url, platform = process.platform, execFileSync = defaultExecFileSync, spawn2 = defaultSpawn) {
7230
+ import { spawn as defaultSpawn } from "node:child_process";
7231
+ function openBrowserForMenu(url, platform = process.platform, spawn2 = defaultSpawn) {
7232
7232
  try {
7233
7233
  if (platform === "win32") {
7234
7234
  const command = `Start-Process '${url.replaceAll("'", "''")}'`;
7235
- const child = spawn2("powershell.exe", [
7235
+ const child2 = spawn2("powershell.exe", [
7236
7236
  "-NoProfile",
7237
7237
  "-NonInteractive",
7238
7238
  "-WindowStyle",
@@ -7240,17 +7240,18 @@ function openBrowserForMenu(url, platform = process.platform, execFileSync = def
7240
7240
  "-EncodedCommand",
7241
7241
  Buffer.from(command, "utf16le").toString("base64")
7242
7242
  ], { stdio: "ignore", windowsHide: true });
7243
- child.on("error", () => {
7244
- });
7245
- child.unref();
7246
- return child.pid !== void 0;
7247
- } else {
7248
- execFileSync(platform === "darwin" ? "open" : "xdg-open", [url], {
7249
- stdio: "ignore",
7250
- timeout: 3e3
7243
+ child2.on("error", () => {
7251
7244
  });
7245
+ child2.unref();
7246
+ return child2.pid !== void 0;
7252
7247
  }
7253
- return true;
7248
+ const child = spawn2(platform === "darwin" ? "open" : "xdg-open", [url], {
7249
+ stdio: "ignore"
7250
+ });
7251
+ child.on("error", () => {
7252
+ });
7253
+ child.unref();
7254
+ return child.pid !== void 0;
7254
7255
  } catch {
7255
7256
  return false;
7256
7257
  }
@@ -8523,7 +8524,7 @@ function acquireInsulaQuotaSource(transport, tokenPath) {
8523
8524
  }
8524
8525
  };
8525
8526
  }
8526
- var MINUTE, MAX_AGE, sources, attempts, InsulaQuotaSource;
8527
+ var MINUTE, MAX_AGE, COLD_WAIT, sources, attempts, InsulaQuotaSource;
8527
8528
  var init_insula = __esm({
8528
8529
  "../core/dist/common-auth-embedded/claustrum/insula.js"() {
8529
8530
  "use strict";
@@ -8531,12 +8532,16 @@ var init_insula = __esm({
8531
8532
  init_watch();
8532
8533
  MINUTE = 6e4;
8533
8534
  MAX_AGE = 4 * MINUTE;
8535
+ COLD_WAIT = 2 * MINUTE;
8534
8536
  sources = /* @__PURE__ */ new Map();
8535
8537
  attempts = /* @__PURE__ */ new Map();
8536
8538
  InsulaQuotaSource = class {
8537
8539
  transport;
8538
8540
  key;
8539
8541
  #entries = [];
8542
+ #available = false;
8543
+ #completeProviders = /* @__PURE__ */ new Set();
8544
+ #coldSince = /* @__PURE__ */ new Map();
8540
8545
  /** Every usage.get, polled or watch-driven, shares this one slot. */
8541
8546
  #reads = new CoalescedRead(async () => {
8542
8547
  try {
@@ -8544,8 +8549,14 @@ var init_insula = __esm({
8544
8549
  if (!record2(reply) || !Array.isArray(reply.result) || reply.error !== void 0)
8545
8550
  throw new Error("unavailable insula usage");
8546
8551
  this.#entries = reply.result.filter((entry) => record2(entry) && typeof entry.provider === "string");
8552
+ this.#available = this.#entries.length === reply.result.length && (reply.completeProviders === void 0 || Array.isArray(reply.completeProviders) && reply.completeProviders.every((value) => typeof value === "string"));
8553
+ this.#completeProviders = new Set(this.#available && Array.isArray(reply.completeProviders) ? reply.completeProviders : []);
8554
+ for (const provider2 of this.#completeProviders)
8555
+ this.#coldSince.delete(provider2);
8547
8556
  } catch {
8548
8557
  this.#entries = [];
8558
+ this.#available = false;
8559
+ this.#completeProviders.clear();
8549
8560
  }
8550
8561
  }, () => {
8551
8562
  });
@@ -8724,6 +8735,37 @@ var init_insula = __esm({
8724
8735
  }
8725
8736
  return void 0;
8726
8737
  }
8738
+ /** Cache-only background lookup; current() retains its original miss behavior. */
8739
+ lookup(provider2, accountId, now) {
8740
+ if (!this.#available)
8741
+ return { miss: "unreachable" };
8742
+ const entry = this.#entries.find((value) => value.provider === provider2 && typeof value.account === "string" && value.account.trim() === accountId);
8743
+ const errorClass = (entry ?? this.#entries.find((value) => value.provider === provider2 && value.account === void 0 && value.errorClass !== void 0))?.errorClass;
8744
+ if (errorClass === "upstream_failed")
8745
+ return { miss: "upstream-failed" };
8746
+ if (errorClass === "credential_absent" || errorClass === "credential_unusable" || errorClass === "credential_rejected")
8747
+ return { miss: "credential" };
8748
+ if (errorClass !== void 0)
8749
+ return { miss: "unreachable" };
8750
+ if (entry) {
8751
+ const fetchedAt = typeof entry.fetchedAt === "string" ? Date.parse(entry.fetchedAt) : Number.NaN;
8752
+ if (!record2(entry.usage) || !Number.isFinite(fetchedAt))
8753
+ return { miss: "unreachable" };
8754
+ const reading = {
8755
+ entry,
8756
+ context: {
8757
+ fetchedAt,
8758
+ ...typeof entry.source === "string" && { source: entry.source }
8759
+ }
8760
+ };
8761
+ return now >= fetchedAt + MAX_AGE || entry.stale !== void 0 ? { miss: "stale", reading } : { reading };
8762
+ }
8763
+ if (this.#completeProviders.has(provider2))
8764
+ return { miss: "absent" };
8765
+ const since = this.#coldSince.get(provider2) ?? now;
8766
+ this.#coldSince.set(provider2, since);
8767
+ return { miss: now - since >= COLD_WAIT ? "unreachable" : "cold" };
8768
+ }
8727
8769
  };
8728
8770
  }
8729
8771
  });
@@ -10501,6 +10543,7 @@ var init_consumer = __esm({
10501
10543
  #insula;
10502
10544
  #vaultWatch;
10503
10545
  #releaseInsulaWatch;
10546
+ #insulaSkips = /* @__PURE__ */ new Map();
10504
10547
  /** When this instance last completed a discovery, by `now`. */
10505
10548
  #discoveredAt;
10506
10549
  constructor(options) {
@@ -10794,6 +10837,41 @@ var init_consumer = __esm({
10794
10837
  return void 0;
10795
10838
  }
10796
10839
  }
10840
+ /** Cache-only background lookup, preserving the reason a route has no reading. */
10841
+ async lookupInsulaQuotaForRoute(routeId) {
10842
+ const options = this.#options.insula;
10843
+ if (!options || this.#shutdown.signal.aborted || !await this.#active())
10844
+ return { miss: "unreachable" };
10845
+ try {
10846
+ await readClaustrumEnrollmentToken(this.#options.tokenPath);
10847
+ const roster = await readVaultRoster(this.#options.rosterPath);
10848
+ const account = roster?.rows.find((row) => row.routeId === routeId)?.accountIdentity;
10849
+ if (!account || !this.#insula)
10850
+ return { miss: "unreachable" };
10851
+ const result = this.#insula.source.lookup(options.provider, account, (this.#options.now ?? Date.now)());
10852
+ const reading = result.reading && options.normalize(result.reading.entry, result.reading.context);
10853
+ if (result.miss)
10854
+ return { miss: result.miss, ...reading !== void 0 && { reading } };
10855
+ return reading === void 0 ? { miss: "unreachable" } : { reading };
10856
+ } catch {
10857
+ return { miss: "unreachable" };
10858
+ }
10859
+ }
10860
+ /** Skip the fallback poll while insula is cold or its upstream fetch failed. */
10861
+ async pollInsulaQuotaForRoute(routeId, fallback) {
10862
+ const result = await this.lookupInsulaQuotaForRoute(routeId);
10863
+ if (result.miss === "cold" || result.miss === "upstream-failed") {
10864
+ if (this.#insulaSkips.get(routeId) !== result.miss) {
10865
+ this.#insulaSkips.set(routeId, result.miss);
10866
+ this.#logger.warn("skipped insula provider poll", {
10867
+ reason: result.miss
10868
+ });
10869
+ }
10870
+ return void 0;
10871
+ }
10872
+ this.#insulaSkips.delete(routeId);
10873
+ return result.miss ? fallback() : result.reading;
10874
+ }
10797
10875
  #normalizeInsulaQuota(accountIdentity) {
10798
10876
  if (!this.#options.insula || !accountIdentity)
10799
10877
  return void 0;
@@ -21008,6 +21086,7 @@ var ANTIGRAVITY_SCOPES = [
21008
21086
  var ANTIGRAVITY_REDIRECT_URI = "http://localhost:51121/oauth-callback";
21009
21087
  var ANTIGRAVITY_ENDPOINT_DAILY = "https://daily-cloudcode-pa.googleapis.com";
21010
21088
  var ANTIGRAVITY_ENDPOINT_PROD = "https://cloudcode-pa.googleapis.com";
21089
+ var ANTIGRAVITY_QUOTA_ENDPOINT = ANTIGRAVITY_ENDPOINT_DAILY;
21011
21090
  var ANTIGRAVITY_ENDPOINT_FALLBACKS = [
21012
21091
  ANTIGRAVITY_ENDPOINT_DAILY,
21013
21092
  ANTIGRAVITY_ENDPOINT_PROD
@@ -21409,9 +21488,9 @@ function projectAntigravityQuota(quota) {
21409
21488
  const model = MODEL_LABELS[scope];
21410
21489
  if (!model)
21411
21490
  continue;
21412
- const windows = group.windows ?? [];
21413
- if (windows.length) {
21414
- for (const window of windows) {
21491
+ const windows2 = group.windows ?? [];
21492
+ if (windows2.length) {
21493
+ for (const window of windows2) {
21415
21494
  if (!Number.isFinite(window.remainingFraction))
21416
21495
  continue;
21417
21496
  const duration = window.window === "weekly" ? "7d" : "5h";
@@ -22833,13 +22912,13 @@ function aggregateQuota(models) {
22833
22912
  perModel.sort((a, b) => a.modelId.localeCompare(b.modelId));
22834
22913
  return { groups, perModel, modelCount: totalCount };
22835
22914
  }
22836
- function mostConstrainedWindow(windows) {
22837
- if (windows.length === 0)
22915
+ function mostConstrainedWindow(windows2) {
22916
+ if (windows2.length === 0)
22838
22917
  return void 0;
22839
- let best = windows[0];
22840
- for (let i = 1; i < windows.length; i++) {
22841
- if (windows[i].remainingFraction < best.remainingFraction) {
22842
- best = windows[i];
22918
+ let best = windows2[0];
22919
+ for (let i = 1; i < windows2.length; i++) {
22920
+ if (windows2[i].remainingFraction < best.remainingFraction) {
22921
+ best = windows2[i];
22843
22922
  }
22844
22923
  }
22845
22924
  return {
@@ -22876,21 +22955,21 @@ function aggregateQuotaSummary(response) {
22876
22955
  const groups = {};
22877
22956
  let totalCount = 0;
22878
22957
  for (const group of response.groups) {
22879
- const windows = [];
22958
+ const windows2 = [];
22880
22959
  for (const bucket of group.buckets) {
22881
22960
  const pool2 = poolForBucketId(bucket.bucketId);
22882
22961
  if (!pool2)
22883
22962
  continue;
22884
- windows.push({
22963
+ windows2.push({
22885
22964
  window: bucket.window,
22886
22965
  remainingFraction: normalizeRemainingFraction(bucket.remainingFraction),
22887
22966
  resetTime: bucket.resetTime
22888
22967
  });
22889
22968
  }
22890
- if (windows.length === 0)
22969
+ if (windows2.length === 0)
22891
22970
  continue;
22892
- windows.sort((a, b) => windowDurationMs(a.window) - windowDurationMs(b.window));
22893
- const constrained = mostConstrainedWindow(windows);
22971
+ windows2.sort((a, b) => windowDurationMs(a.window) - windowDurationMs(b.window));
22972
+ const constrained = mostConstrainedWindow(windows2);
22894
22973
  const recognizedBucket = group.buckets.find((bucket) => poolForBucketId(bucket.bucketId));
22895
22974
  if (!recognizedBucket)
22896
22975
  continue;
@@ -22902,7 +22981,7 @@ function aggregateQuotaSummary(response) {
22902
22981
  remainingFraction: constrained.remainingFraction,
22903
22982
  resetTime: constrained.resetTime,
22904
22983
  modelCount,
22905
- windows
22984
+ windows: windows2
22906
22985
  };
22907
22986
  totalCount += modelCount;
22908
22987
  }
@@ -24408,7 +24487,8 @@ function createAntigravityVaultAccountSource(options) {
24408
24487
  pollIntervalMs: options.pollIntervalMs
24409
24488
  },
24410
24489
  ...options.now && { now: options.now },
24411
- ...options.logger && { logger: options.logger }
24490
+ ...options.logger && { logger: options.logger },
24491
+ ...options.insula && { insula: options.insula }
24412
24492
  });
24413
24493
  const issued = /* @__PURE__ */ new WeakMap();
24414
24494
  const isDeclined2 = claustrum.isDeclined.bind(claustrum);
@@ -24520,6 +24600,37 @@ function createAntigravityVaultAccountSource(options) {
24520
24600
  recordVersion: admission.recordVersion
24521
24601
  });
24522
24602
  },
24603
+ pollInsulaQuotaForRoute: async (ref, fallback, signal, onSkip) => {
24604
+ await assertServing(signal);
24605
+ assertCurrentRoute(ref);
24606
+ if (!consumer.pollInsulaQuotaForRoute)
24607
+ return fallback();
24608
+ let usedFallback = false;
24609
+ const reading = await untilAborted(consumer.pollInsulaQuotaForRoute(ref.routeId, () => {
24610
+ usedFallback = true;
24611
+ return fallback();
24612
+ }), signal);
24613
+ if (reading === void 0) {
24614
+ const result = consumer.lookupInsulaQuotaForRoute ? await untilAborted(consumer.lookupInsulaQuotaForRoute(ref.routeId), signal) : void 0;
24615
+ if (result?.miss === "cold" || result?.miss === "upstream-failed")
24616
+ onSkip?.(result.miss);
24617
+ return void 0;
24618
+ }
24619
+ if (usedFallback)
24620
+ return reading;
24621
+ if (reading.accountIdentity !== ref.accountIdentity)
24622
+ throw new AntigravityVaultSourceError("identity-contradicted", "The background quota reading belongs to another vault account");
24623
+ const admission = await admit2(ref, signal);
24624
+ return {
24625
+ ...reading,
24626
+ quotaAttribution: {
24627
+ routeId: admission.routeId,
24628
+ credentialId: admission.credentialId,
24629
+ accountIdentity: admission.accountIdentity,
24630
+ recordVersion: admission.recordVersion
24631
+ }
24632
+ };
24633
+ },
24523
24634
  commitState: async (attribution, update, signal) => {
24524
24635
  assertOpen(signal);
24525
24636
  if (!options.state)
@@ -28820,7 +28931,7 @@ function normalizeQuota(input2) {
28820
28931
  const resetAt = toFiniteNumber(record3.resetAt) ?? void 0;
28821
28932
  const checkedAt = toFiniteNumber(record3.checkedAt) ?? void 0;
28822
28933
  const windowsRaw = record3.windows;
28823
- let windows;
28934
+ let windows2;
28824
28935
  if (Array.isArray(windowsRaw)) {
28825
28936
  const parsed = windowsRaw.filter(isObject).map((w) => {
28826
28937
  const win = w.window;
@@ -28839,14 +28950,14 @@ function normalizeQuota(input2) {
28839
28950
  ...ca !== null && ca >= 0 ? { checkedAt: ca } : {}
28840
28951
  };
28841
28952
  }).filter((v) => v !== null);
28842
- if (parsed.length > 0) windows = parsed;
28953
+ if (parsed.length > 0) windows2 = parsed;
28843
28954
  }
28844
28955
  return {
28845
28956
  remainingPercent: clampNumber(remaining, 0, 100),
28846
28957
  ...fraction !== null ? { remainingFraction: clampNumber(fraction, 0, 1) } : {},
28847
28958
  resetAt,
28848
28959
  ...checkedAt !== void 0 ? { checkedAt } : {},
28849
- windows
28960
+ windows: windows2
28850
28961
  };
28851
28962
  }
28852
28963
  function normalizeRouting(input2) {
@@ -28966,7 +29077,7 @@ function projectQuotaPoolForSidebar(source, checkedAt) {
28966
29077
  const parsed = Date.parse(source.resetTime);
28967
29078
  if (Number.isFinite(parsed)) resetAt = parsed;
28968
29079
  }
28969
- const windows = source.windows?.length ? source.windows.map((w) => ({
29080
+ const windows2 = source.windows?.length ? source.windows.map((w) => ({
28970
29081
  window: w.window,
28971
29082
  ...readingAt !== void 0 ? { checkedAt: readingAt } : {},
28972
29083
  remainingPercent: clampNumber(
@@ -28984,7 +29095,7 @@ function projectQuotaPoolForSidebar(source, checkedAt) {
28984
29095
  remainingPercent,
28985
29096
  remainingFraction: clampNumber(fraction, 0, 1),
28986
29097
  resetAt,
28987
- windows,
29098
+ windows: windows2,
28988
29099
  ...readingAt !== void 0 ? { checkedAt: readingAt } : {}
28989
29100
  };
28990
29101
  }
@@ -29375,7 +29486,7 @@ async function fetchLegacyModelsFallback(options) {
29375
29486
  const modelsResponse = await fetchAvailableModels({
29376
29487
  accessToken: options.accessToken,
29377
29488
  projectId: options.projectId,
29378
- endpoints: ANTIGRAVITY_ENDPOINT_FALLBACKS,
29489
+ endpoints: [ANTIGRAVITY_QUOTA_ENDPOINT],
29379
29490
  userAgent: buildAntigravityHarnessUserAgent(),
29380
29491
  timeoutMs: 1e4,
29381
29492
  ...options.fetchVia ? { fetchVia: options.fetchVia } : {}
@@ -29404,7 +29515,7 @@ async function fetchQuotaPayloads(options) {
29404
29515
  accessToken,
29405
29516
  managedProjectId,
29406
29517
  projectId,
29407
- endpoints: ANTIGRAVITY_ENDPOINT_FALLBACKS,
29518
+ endpoints: [ANTIGRAVITY_QUOTA_ENDPOINT],
29408
29519
  userAgent: buildAntigravityHarnessUserAgent(),
29409
29520
  timeoutMs: 1e4,
29410
29521
  ...fetchVia ? { fetchVia } : {}
@@ -29521,7 +29632,7 @@ async function fetchVaultAccountQuota(options) {
29521
29632
  return result;
29522
29633
  };
29523
29634
  const fetchSummary = async () => {
29524
- for (const endpoint of ANTIGRAVITY_ENDPOINT_FALLBACKS) {
29635
+ for (const endpoint of [ANTIGRAVITY_QUOTA_ENDPOINT]) {
29525
29636
  const result = await attempt(
29526
29637
  async (grant, fetchVia) => aggregateQuotaSummary(
29527
29638
  (await fetchQuotaSummary({
@@ -29543,7 +29654,7 @@ async function fetchVaultAccountQuota(options) {
29543
29654
  }
29544
29655
  if (result.refused) break;
29545
29656
  }
29546
- for (const endpoint of ANTIGRAVITY_ENDPOINT_FALLBACKS) {
29657
+ for (const endpoint of [ANTIGRAVITY_QUOTA_ENDPOINT]) {
29547
29658
  for (const withProject of [true, false]) {
29548
29659
  const result = await attempt(
29549
29660
  (grant, fetchVia) => fetchAvailableModels({
@@ -29686,6 +29797,14 @@ function createAuthorizedFetchAccountQuota(options) {
29686
29797
  error: `quota check refused (stale grant: ${staleReason})`
29687
29798
  };
29688
29799
  }
29800
+ if (payloads.quota.error) {
29801
+ return {
29802
+ ...base,
29803
+ status: "error",
29804
+ disabled: false,
29805
+ error: payloads.quota.error
29806
+ };
29807
+ }
29689
29808
  return {
29690
29809
  ...base,
29691
29810
  status: "ok",
@@ -29761,6 +29880,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
29761
29880
  }),
29762
29881
  signal
29763
29882
  );
29883
+ if (payloads.quota.error) throw new Error(payloads.quota.error);
29764
29884
  return {
29765
29885
  index,
29766
29886
  email: account.email,
@@ -29816,6 +29936,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
29816
29936
  logger: log7
29817
29937
  });
29818
29938
  quotaResult = payloads.quota;
29939
+ if (quotaResult.error) throw new Error(quotaResult.error);
29819
29940
  fellBackToLegacy = payloads.fellBackToLegacy;
29820
29941
  for (const [family, groupQuota] of Object.entries(quotaResult.groups)) {
29821
29942
  const remainingPercent = (groupQuota.remainingFraction ?? 0) * 100;
@@ -39544,6 +39665,10 @@ async function checkVaultQuota(input2) {
39544
39665
  input2.onStage?.("fetch");
39545
39666
  const answer = await input2.fetchReading(row.route, input2.signal);
39546
39667
  input2.signal.throwIfAborted();
39668
+ if (answer === void 0) {
39669
+ input2.onOutcome?.("fetch-failed");
39670
+ continue;
39671
+ }
39547
39672
  const attribution = answer.quotaAttribution;
39548
39673
  if (answer.quota.error !== void 0) {
39549
39674
  input2.onOutcome?.("fetch-failed");
@@ -39553,7 +39678,7 @@ async function checkVaultQuota(input2) {
39553
39678
  input2.onOutcome?.("unattributed");
39554
39679
  continue;
39555
39680
  }
39556
- const reading = vaultQuotaState(answer.quota, now());
39681
+ const reading = vaultQuotaState(answer.quota, answer.observedAt ?? now());
39557
39682
  input2.onStage?.("commit");
39558
39683
  input2.signal.throwIfAborted();
39559
39684
  const result = await state.recordQuota(attribution, reading, input2.signal);
@@ -39587,6 +39712,50 @@ async function checkVaultQuota(input2) {
39587
39712
  // src/plugin/vault-custody.ts
39588
39713
  import { chmod as chmod3, mkdir as mkdir11, readFile as readFile9 } from "node:fs/promises";
39589
39714
  import { dirname as dirname18, join as join16 } from "node:path";
39715
+
39716
+ // src/plugin/vault-insula-quota.ts
39717
+ var windows = [
39718
+ ["gemini-5h", "gemini", "5h"],
39719
+ ["gemini-weekly", "gemini", "weekly"],
39720
+ ["3p-5h", "non-gemini", "5h"],
39721
+ ["3p-weekly", "non-gemini", "weekly"]
39722
+ ];
39723
+ var normalizeVaultInsulaQuota = (entry, context) => {
39724
+ if (entry.source !== "vault") return void 0;
39725
+ if (entry.provider !== "antigravity" || !entry.account?.trim() || !Number.isFinite(context.fetchedAt))
39726
+ return void 0;
39727
+ const groups = {};
39728
+ for (const [id, group, window] of windows) {
39729
+ const reading = entry.usage?.extraRateWindows?.find(
39730
+ (extra) => extra.id === id
39731
+ )?.window;
39732
+ if (!reading || !Number.isFinite(reading.usedPercent) || reading.usedPercent < 0 || reading.usedPercent > 100)
39733
+ continue;
39734
+ const normalized = {
39735
+ window,
39736
+ remainingFraction: 1 - reading.usedPercent / 100,
39737
+ resetTime: reading.resetsAt ?? ""
39738
+ };
39739
+ let summary = groups[group];
39740
+ if (summary === void 0) {
39741
+ summary = { modelCount: 0, windows: [] };
39742
+ groups[group] = summary;
39743
+ }
39744
+ summary.windows?.push(normalized);
39745
+ if (summary.remainingFraction === void 0 || normalized.remainingFraction < summary.remainingFraction) {
39746
+ summary.remainingFraction = normalized.remainingFraction;
39747
+ summary.resetTime = normalized.resetTime;
39748
+ }
39749
+ }
39750
+ if (Object.keys(groups).length === 0) return void 0;
39751
+ return {
39752
+ quota: { groups, modelCount: 0 },
39753
+ accountIdentity: entry.account.trim(),
39754
+ observedAt: context.fetchedAt
39755
+ };
39756
+ };
39757
+
39758
+ // src/plugin/vault-custody.ts
39590
39759
  var OPENCODE_VAULT_PROVIDER = "google";
39591
39760
  var OPENCODE_VAULT_HOST = "opencode";
39592
39761
  var OPENCODE_VAULT_ENROLLMENT_NAME = getAntigravityVaultEnrollmentName(OPENCODE_VAULT_HOST);
@@ -39694,6 +39863,12 @@ function createOpenCodeVaultCustody(options) {
39694
39863
  onError: () => options.onRosterChanged?.(),
39695
39864
  reporterSource: options.reporterSource,
39696
39865
  state: { path: paths.stateFile, fs: await loadCommonAuthFs() },
39866
+ ...options.insulaQuota ? {
39867
+ insula: {
39868
+ provider: "antigravity",
39869
+ normalize: normalizeVaultInsulaQuota
39870
+ }
39871
+ } : {},
39697
39872
  ...options.logger ? { logger: options.logger } : {},
39698
39873
  ...options.now ? { now: options.now } : {},
39699
39874
  ...options.pollIntervalMs !== void 0 ? { pollIntervalMs: options.pollIntervalMs } : {}
@@ -43724,10 +43899,10 @@ function createGaRpcActivation(options) {
43724
43899
  const { email: _email, quota, ...rest } = account;
43725
43900
  const entry = (value) => {
43726
43901
  if (value === void 0) return void 0;
43727
- const { remainingFraction: _fraction, windows, ...fields } = value;
43728
- return windows === void 0 ? fields : {
43902
+ const { remainingFraction: _fraction, windows: windows2, ...fields } = value;
43903
+ return windows2 === void 0 ? fields : {
43729
43904
  ...fields,
43730
- windows: windows.map(
43905
+ windows: windows2.map(
43731
43906
  ({ remainingFraction: _windowFraction, ...window }) => window
43732
43907
  )
43733
43908
  };
@@ -46268,9 +46443,9 @@ Please quit all OpenCode, LiteCode, and Pi processes before running setup.`);
46268
46443
  }
46269
46444
  };
46270
46445
  async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
46271
- const windows = (options.platform ?? process.platform) === "win32";
46446
+ const windows2 = (options.platform ?? process.platform) === "win32";
46272
46447
  let inspection = {
46273
- step: windows ? "tasklist" : "ps",
46448
+ step: windows2 ? "tasklist" : "ps",
46274
46449
  exitCode: null,
46275
46450
  signal: null,
46276
46451
  timedOut: false,
@@ -46305,7 +46480,7 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
46305
46480
  }
46306
46481
  };
46307
46482
  try {
46308
- const result = await inspect(windows ? "tasklist" : "ps", windows ? "tasklist.exe" : "ps", windows ? ["/fo", "csv", "/nh"] : ["-eo", "pid,command"]);
46483
+ const result = await inspect(windows2 ? "tasklist" : "ps", windows2 ? "tasklist.exe" : "ps", windows2 ? ["/fo", "csv", "/nh"] : ["-eo", "pid,command"]);
46309
46484
  if (result.exitCode !== 0)
46310
46485
  throw new ProcessInspectionError(inspection);
46311
46486
  const processes = [];
@@ -46315,7 +46490,7 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
46315
46490
  continue;
46316
46491
  let pid;
46317
46492
  let command;
46318
- if (windows) {
46493
+ if (windows2) {
46319
46494
  const match = /^"([^"]+)","(\d+)"(?:,|$)/.exec(trimmed);
46320
46495
  if (!match)
46321
46496
  throw new ProcessInspectionError(inspection);
@@ -46338,7 +46513,7 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
46338
46513
  if (!processes.length)
46339
46514
  throw new ProcessInspectionError(inspection);
46340
46515
  const runtimes = processes.filter((entry) => entry.pid !== process.pid && /^(?:node|bun)\.exe$/i.test(entry.command));
46341
- if (windows && runtimes.length && options.inspectRuntimes !== false) {
46516
+ if (windows2 && runtimes.length && options.inspectRuntimes !== false) {
46342
46517
  const details = await inspect("CIM", "powershell.exe", [
46343
46518
  "-NoProfile",
46344
46519
  "-NonInteractive",
@@ -46381,10 +46556,10 @@ function createProcessFence(runner = defaultCommandRunner, options = {}) {
46381
46556
  env: env3,
46382
46557
  inspectRuntimes: false
46383
46558
  });
46384
- const windows = (options.platform ?? process.platform) === "win32";
46559
+ const windows2 = (options.platform ?? process.platform) === "win32";
46385
46560
  return {
46386
46561
  hosts: processes.filter(isHost),
46387
- uncheckedRuntimes: windows ? processes.filter((entry) => entry.pid !== process.pid && /^(?:node|bun)\.exe$/i.test(entry.command)).length : 0
46562
+ uncheckedRuntimes: windows2 ? processes.filter((entry) => entry.pid !== process.pid && /^(?:node|bun)\.exe$/i.test(entry.command)).length : 0
46388
46563
  };
46389
46564
  }
46390
46565
  };
@@ -46495,11 +46670,11 @@ import { mkdir as mkdir14, open as open11, rename as rename10, stat as stat9, un
46495
46670
  import { basename as basename6, dirname as dirname21, join as join20 } from "node:path";
46496
46671
  import { setTimeout as delay2 } from "node:timers/promises";
46497
46672
  async function writeHostConfigAtomic(file, content, options = {}) {
46498
- const windows = (options.platform ?? process.platform) === "win32";
46673
+ const windows2 = (options.platform ?? process.platform) === "win32";
46499
46674
  const parent = dirname21(file);
46500
46675
  await mkdir14(parent, { recursive: true });
46501
46676
  let mode;
46502
- if (!windows) {
46677
+ if (!windows2) {
46503
46678
  try {
46504
46679
  mode = (await stat9(file)).mode & 4095;
46505
46680
  } catch (error) {
@@ -46530,7 +46705,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
46530
46705
  } catch (error) {
46531
46706
  const code2 = error.code;
46532
46707
  const remaining = 2e3 - (now() - started);
46533
- if (!windows || !["EPERM", "EBUSY", "EACCES"].includes(code2 ?? "") || remaining <= 0 || attempt >= 40)
46708
+ if (!windows2 || !["EPERM", "EBUSY", "EACCES"].includes(code2 ?? "") || remaining <= 0 || attempt >= 40)
46534
46709
  throw new Error(`Unable to replace host config ${file}. Close editors or other programs using the file, then rerun setup.`);
46535
46710
  await (options.wait ?? delay2)(Math.min(remaining, 25 * 2 ** Math.min(attempt, 2)));
46536
46711
  }
@@ -52118,7 +52293,7 @@ var BackgroundVaultQuotaRefresh = class {
52118
52293
  fetchReading: async (ref, signal) => {
52119
52294
  rowFailure = "fetch-failed";
52120
52295
  await this.assertActive(controller);
52121
- const reading = await fetchVaultAccountQuota({
52296
+ const fallback = () => fetchVaultAccountQuota({
52122
52297
  source,
52123
52298
  ref,
52124
52299
  signal,
@@ -52128,7 +52303,10 @@ var BackgroundVaultQuotaRefresh = class {
52128
52303
  if (kind !== "unknown" || outcome.errorKind === void 0)
52129
52304
  outcome.errorKind = kind;
52130
52305
  if (refused)
52131
- rowFailure = vaultQuotaErrorReason(error, "admission-refused");
52306
+ rowFailure = vaultQuotaErrorReason(
52307
+ error,
52308
+ "admission-refused"
52309
+ );
52132
52310
  },
52133
52311
  transport: async (url, init, extra) => {
52134
52312
  await this.assertActive(controller);
@@ -52151,6 +52329,16 @@ var BackgroundVaultQuotaRefresh = class {
52151
52329
  }
52152
52330
  }
52153
52331
  });
52332
+ const reading = source.pollInsulaQuotaForRoute ? await source.pollInsulaQuotaForRoute(
52333
+ ref,
52334
+ fallback,
52335
+ signal,
52336
+ (reason) => {
52337
+ rowFailure = `insula-${reason}`;
52338
+ }
52339
+ ) : await fallback();
52340
+ if (reading === void 0 && rowFailure === "fetch-failed")
52341
+ rowFailure = "insula-skipped";
52154
52342
  await this.assertActive(controller);
52155
52343
  await lock.assertOwned();
52156
52344
  return reading;
@@ -52481,7 +52669,7 @@ function toCommandAccountRow(entry) {
52481
52669
  const parsed = Date.parse(cachedEntry.resetTime);
52482
52670
  if (Number.isFinite(parsed)) resetAt = parsed;
52483
52671
  }
52484
- const windows = cachedEntry.windows?.length ? cachedEntry.windows.map((w) => ({
52672
+ const windows2 = cachedEntry.windows?.length ? cachedEntry.windows.map((w) => ({
52485
52673
  window: w.window,
52486
52674
  remainingPercent: Math.round(w.remainingFraction * 100),
52487
52675
  resetAt: typeof w.resetTime === "string" && w.resetTime.length > 0 ? (() => {
@@ -52494,7 +52682,7 @@ function toCommandAccountRow(entry) {
52494
52682
  label: QUOTA_GROUP_LABELS[key],
52495
52683
  remainingPercent,
52496
52684
  resetAt,
52497
- windows
52685
+ windows: windows2
52498
52686
  });
52499
52687
  }
52500
52688
  const label = `Account ${entry.index + 1}`;
@@ -53406,6 +53594,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
53406
53594
  let vaultQuotaPoller;
53407
53595
  const vaultCustody = createOpenCodeVaultCustody({
53408
53596
  accountFile: resolve17(getStoragePath()),
53597
+ insulaQuota: true,
53409
53598
  readHostSlot: async () => {
53410
53599
  if (!cachedGetAuth)
53411
53600
  throw new Error("OpenCode has not provided its sign-in yet");