@cortexkit/opencode-antigravity-auth 3.1.9 → 3.1.11

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 (173) hide show
  1. package/README.md +4 -0
  2. package/dist/cli.js +502 -160
  3. package/dist/cli.js.map +3 -3
  4. package/dist/cli.meta.json +52 -42
  5. package/dist/index.js +1306 -656
  6. package/dist/index.js.map +4 -4
  7. package/dist/index.meta.json +102 -74
  8. package/dist/server.js +1437 -767
  9. package/dist/server.js.map +4 -4
  10. package/dist/server.meta.json +1 -1
  11. package/dist/src/cli.d.ts +3 -1
  12. package/dist/src/cli.d.ts.map +1 -1
  13. package/dist/src/cli.js +19 -6
  14. package/dist/src/cli.js.map +1 -1
  15. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
  16. package/dist/src/common-auth-embedded/claustrum/consumer.js +32 -0
  17. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +54 -5
  18. package/dist/src/common-auth-embedded/claustrum/custody.js +176 -22
  19. package/dist/src/common-auth-embedded/claustrum/host.js +8 -0
  20. package/dist/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  21. package/dist/src/common-auth-embedded/claustrum/hub.js +10 -0
  22. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  23. package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +6 -1
  24. package/dist/src/common-auth-embedded/routing-accessor/index.js +5 -3
  25. package/dist/src/common-auth-embedded/setup/process-fence.js +20 -3
  26. package/dist/src/common-auth-embedded/source-output.json +41 -41
  27. package/dist/src/ga/rpc/protocol.d.ts +11 -5
  28. package/dist/src/ga/rpc/protocol.d.ts.map +1 -1
  29. package/dist/src/ga/rpc/protocol.js +11 -3
  30. package/dist/src/ga/rpc/protocol.js.map +1 -1
  31. package/dist/src/ga/server/index.d.ts.map +1 -1
  32. package/dist/src/ga/server/index.js +30 -14
  33. package/dist/src/ga/server/index.js.map +1 -1
  34. package/dist/src/ga/tui/host-ga.d.ts +2 -1
  35. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  36. package/dist/src/ga/tui/host-ga.js +9 -4
  37. package/dist/src/ga/tui/host-ga.js.map +1 -1
  38. package/dist/src/plugin/__fixtures__/release-model-ids.d.ts.map +1 -1
  39. package/dist/src/plugin/__fixtures__/release-model-ids.js +1 -0
  40. package/dist/src/plugin/__fixtures__/release-model-ids.js.map +1 -1
  41. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  42. package/dist/src/plugin/account-access.d.ts +1 -0
  43. package/dist/src/plugin/account-access.d.ts.map +1 -1
  44. package/dist/src/plugin/account-access.js +28 -0
  45. package/dist/src/plugin/account-access.js.map +1 -1
  46. package/dist/src/plugin/auth-loader.d.ts.map +1 -1
  47. package/dist/src/plugin/auth-loader.js +21 -12
  48. package/dist/src/plugin/auth-loader.js.map +1 -1
  49. package/dist/src/plugin/background-quota-refresh.d.ts +11 -24
  50. package/dist/src/plugin/background-quota-refresh.d.ts.map +1 -1
  51. package/dist/src/plugin/background-quota-refresh.js +54 -60
  52. package/dist/src/plugin/background-quota-refresh.js.map +1 -1
  53. package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  54. package/dist/src/plugin/background-vault-quota-refresh.js +6 -3
  55. package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
  56. package/dist/src/plugin/cache/signature-cache.d.ts +3 -0
  57. package/dist/src/plugin/cache/signature-cache.d.ts.map +1 -1
  58. package/dist/src/plugin/cache/signature-cache.js +73 -46
  59. package/dist/src/plugin/cache/signature-cache.js.map +1 -1
  60. package/dist/src/plugin/cache.d.ts.map +1 -1
  61. package/dist/src/plugin/cache.js +17 -7
  62. package/dist/src/plugin/cache.js.map +1 -1
  63. package/dist/src/plugin/config/models.d.ts +1 -1
  64. package/dist/src/plugin/config/models.d.ts.map +1 -1
  65. package/dist/src/plugin/config/models.js +10 -5
  66. package/dist/src/plugin/config/models.js.map +1 -1
  67. package/dist/src/plugin/core/streaming/displayed-thinking.d.ts +23 -0
  68. package/dist/src/plugin/core/streaming/displayed-thinking.d.ts.map +1 -0
  69. package/dist/src/plugin/core/streaming/displayed-thinking.js +58 -0
  70. package/dist/src/plugin/core/streaming/displayed-thinking.js.map +1 -0
  71. package/dist/src/plugin/fetch/warmup.d.ts +9 -2
  72. package/dist/src/plugin/fetch/warmup.d.ts.map +1 -1
  73. package/dist/src/plugin/fetch/warmup.js +22 -14
  74. package/dist/src/plugin/fetch/warmup.js.map +1 -1
  75. package/dist/src/plugin/quota.d.ts +10 -2
  76. package/dist/src/plugin/quota.d.ts.map +1 -1
  77. package/dist/src/plugin/quota.js +38 -10
  78. package/dist/src/plugin/quota.js.map +1 -1
  79. package/dist/src/plugin/request-helpers.d.ts.map +1 -1
  80. package/dist/src/plugin/request-helpers.js +51 -19
  81. package/dist/src/plugin/request-helpers.js.map +1 -1
  82. package/dist/src/plugin/request.d.ts +12 -1
  83. package/dist/src/plugin/request.d.ts.map +1 -1
  84. package/dist/src/plugin/request.js +34 -49
  85. package/dist/src/plugin/request.js.map +1 -1
  86. package/dist/src/plugin/shared/request-services.d.ts +4 -1
  87. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  88. package/dist/src/plugin/shared/request-services.js +142 -24
  89. package/dist/src/plugin/shared/request-services.js.map +1 -1
  90. package/dist/src/plugin/shared/runtime.d.ts +3 -4
  91. package/dist/src/plugin/shared/runtime.d.ts.map +1 -1
  92. package/dist/src/plugin/shared/runtime.js +2 -2
  93. package/dist/src/plugin/shared/runtime.js.map +1 -1
  94. package/dist/src/plugin/shared/vault-request-credentials.d.ts +13 -7
  95. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  96. package/dist/src/plugin/shared/vault-request-credentials.js +24 -18
  97. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  98. package/dist/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
  99. package/dist/src/setup.d.ts +3 -0
  100. package/dist/src/setup.d.ts.map +1 -1
  101. package/dist/src/setup.js +18 -6
  102. package/dist/src/setup.js.map +1 -1
  103. package/dist/src/sidebar-state.d.ts +20 -7
  104. package/dist/src/sidebar-state.d.ts.map +1 -1
  105. package/dist/src/sidebar-state.js +57 -8
  106. package/dist/src/sidebar-state.js.map +1 -1
  107. package/dist/src/tui.d.ts.map +1 -1
  108. package/dist/src/tui.js +43 -23
  109. package/dist/src/tui.js.map +1 -1
  110. package/dist/tui-build-map.json +9 -9
  111. package/dist/tui-ga-build-map.json +5 -5
  112. package/dist/types/src/cli.d.ts +3 -1
  113. package/dist/types/src/cli.d.ts.map +1 -1
  114. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
  115. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +54 -5
  116. package/dist/types/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  117. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  118. package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +6 -1
  119. package/dist/types/src/ga/rpc/protocol.d.ts +11 -5
  120. package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -1
  121. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  122. package/dist/types/src/plugin/account-access.d.ts +1 -0
  123. package/dist/types/src/plugin/account-access.d.ts.map +1 -1
  124. package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
  125. package/dist/types/src/plugin/background-quota-refresh.d.ts +11 -24
  126. package/dist/types/src/plugin/background-quota-refresh.d.ts.map +1 -1
  127. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  128. package/dist/types/src/plugin/cache/signature-cache.d.ts +3 -0
  129. package/dist/types/src/plugin/cache/signature-cache.d.ts.map +1 -1
  130. package/dist/types/src/plugin/cache.d.ts.map +1 -1
  131. package/dist/types/src/plugin/config/models.d.ts +1 -1
  132. package/dist/types/src/plugin/config/models.d.ts.map +1 -1
  133. package/dist/types/src/plugin/core/streaming/displayed-thinking.d.ts +23 -0
  134. package/dist/types/src/plugin/core/streaming/displayed-thinking.d.ts.map +1 -0
  135. package/dist/types/src/plugin/fetch/warmup.d.ts +9 -2
  136. package/dist/types/src/plugin/fetch/warmup.d.ts.map +1 -1
  137. package/dist/types/src/plugin/quota.d.ts +10 -2
  138. package/dist/types/src/plugin/quota.d.ts.map +1 -1
  139. package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
  140. package/dist/types/src/plugin/request.d.ts +12 -1
  141. package/dist/types/src/plugin/request.d.ts.map +1 -1
  142. package/dist/types/src/plugin/shared/request-services.d.ts +4 -1
  143. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  144. package/dist/types/src/plugin/shared/runtime.d.ts +3 -4
  145. package/dist/types/src/plugin/shared/runtime.d.ts.map +1 -1
  146. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +13 -7
  147. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  148. package/dist/types/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
  149. package/dist/types/src/setup.d.ts +3 -0
  150. package/dist/types/src/setup.d.ts.map +1 -1
  151. package/dist/types/src/sidebar-state.d.ts +20 -7
  152. package/dist/types/src/sidebar-state.d.ts.map +1 -1
  153. package/package.json +3 -3
  154. package/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
  155. package/src/common-auth-embedded/claustrum/consumer.js +32 -0
  156. package/src/common-auth-embedded/claustrum/custody.d.ts +54 -5
  157. package/src/common-auth-embedded/claustrum/custody.js +176 -22
  158. package/src/common-auth-embedded/claustrum/host.js +8 -0
  159. package/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  160. package/src/common-auth-embedded/claustrum/hub.js +10 -0
  161. package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  162. package/src/common-auth-embedded/routing-accessor/index.d.ts +6 -1
  163. package/src/common-auth-embedded/routing-accessor/index.js +5 -3
  164. package/src/common-auth-embedded/setup/process-fence.js +20 -3
  165. package/src/common-auth-embedded/source-output.json +41 -41
  166. package/src/sidebar-state.ts +77 -8
  167. package/src/tui-compiled/sidebar-state.js +40 -1
  168. package/src/tui-compiled/tui.js +49 -24
  169. package/src/tui-ga-compiled/host-ga.js +11 -5
  170. package/src/tui-ga-raw/host-ga.tsx +17 -6
  171. package/src/tui-raw/sidebar-state.js +40 -1
  172. package/src/tui-raw/tui.tsx +40 -24
  173. package/src/tui.tsx +40 -24
package/dist/cli.js CHANGED
@@ -383,6 +383,11 @@ function mergeQuotaState(stored, observation) {
383
383
  if (stored === void 0)
384
384
  return incoming;
385
385
  const prior = encodeQuotaState(decodeQuotaState(stored));
386
+ const previousAt = prior.cachedQuotaUpdatedAt;
387
+ const observedAt = incoming.cachedQuotaUpdatedAt;
388
+ if (typeof previousAt === "number" && typeof observedAt === "number" && observedAt < previousAt) {
389
+ throw new StaleQuotaObservationError();
390
+ }
386
391
  return encodeQuotaState(decodeQuotaState({ ...prior, ...incoming }));
387
392
  }
388
393
  function decodeRoutingSettings(raw) {
@@ -418,7 +423,7 @@ function createProviderStateCodec(policy) {
418
423
  }
419
424
  };
420
425
  }
421
- var AccountCodecError, MAX_JSON_DEPTH, IDENTIFIER, jsonValue, string, nonEmptyString, finiteNumber, count, credentialEpoch, boolean, rowId, required, optional, EXTENSIONS, CREDENTIAL_REFUSAL, CREDENTIAL_KEYS, POOL_FIELD_REFUSAL, QUOTA_FIELD_REFUSAL, LEGACY_FIELD_REFUSAL, METADATA_FIELD_REFUSAL, clientMetadataCodec, fingerprintCodec, fingerprintVersionCodec, dailyRequestCountsCodec, metadataShape, quotaShape, metadataForbidden, quotaForbidden, metadataCodec, providerStateCodec, quotaCodec, rowRefCodec, routingCodec, QUOTA_CODEC;
426
+ var AccountCodecError, MAX_JSON_DEPTH, IDENTIFIER, jsonValue, string, nonEmptyString, finiteNumber, count, credentialEpoch, boolean, rowId, required, optional, EXTENSIONS, CREDENTIAL_REFUSAL, CREDENTIAL_KEYS, POOL_FIELD_REFUSAL, QUOTA_FIELD_REFUSAL, LEGACY_FIELD_REFUSAL, METADATA_FIELD_REFUSAL, clientMetadataCodec, fingerprintCodec, fingerprintVersionCodec, dailyRequestCountsCodec, metadataShape, quotaShape, metadataForbidden, quotaForbidden, metadataCodec, providerStateCodec, quotaCodec, rowRefCodec, routingCodec, StaleQuotaObservationError, QUOTA_CODEC;
422
427
  var init_account_repository_codecs = __esm({
423
428
  "../core/dist/account-repository-codecs.js"() {
424
429
  "use strict";
@@ -588,6 +593,11 @@ var init_account_repository_codecs = __esm({
588
593
  gemini: optional(nullable(rowRefCodec))
589
594
  })))
590
595
  }, { forbidden: CREDENTIAL_KEYS });
596
+ StaleQuotaObservationError = class extends Error {
597
+ constructor() {
598
+ super("A newer quota observation is already stored");
599
+ }
600
+ };
591
601
  QUOTA_CODEC = {
592
602
  validate: isValidQuotaState,
593
603
  merge: mergeQuotaState
@@ -4047,6 +4057,8 @@ function getResolverAliasMap() {
4047
4057
  }
4048
4058
  function getQuotaGroupForModel(modelId, hasArgonPool = false) {
4049
4059
  const normalized = modelId.toLowerCase();
4060
+ if (isGeminiNeonModel(normalized))
4061
+ return "gemini";
4050
4062
  if (isGeminiHydrogenModel(normalized))
4051
4063
  return "gemini";
4052
4064
  if (isGeminiCarbonModel(normalized))
@@ -4069,6 +4081,9 @@ function isGeminiCarbonModel(model) {
4069
4081
  function isGeminiHydrogenModel(model) {
4070
4082
  return /^(?:antigravity-)?gemini-4-hydrogen(?:-(?:low|medium|high|xhigh))?$/.test(model.toLowerCase());
4071
4083
  }
4084
+ function isGeminiNeonModel(model) {
4085
+ return /^(?:antigravity-)?gemini-4-neon(?:-(?:low|medium|high|xhigh))?$/i.test(model);
4086
+ }
4072
4087
  var DEFAULT_MODALITIES, MODEL_RELEASE_DATE, DEFAULT_COST, DEFAULT_OPTIONS, ALL_MODEL_DEFINITIONS, RESOLVER_ALIASES, QUOTA_GROUP_BY_MODEL_ID, ANTIGRAVITY_OPENCODE_MODEL_IDS, OPENCODE_MODEL_DEFINITIONS;
4073
4088
  var init_model_registry = __esm({
4074
4089
  "../core/dist/model-registry.js"() {
@@ -4081,6 +4096,18 @@ var init_model_registry = __esm({
4081
4096
  DEFAULT_COST = { input: 0, output: 0 };
4082
4097
  DEFAULT_OPTIONS = {};
4083
4098
  ALL_MODEL_DEFINITIONS = {
4099
+ "antigravity-gemini-4-neon": defineModel("antigravity-gemini-4-neon", {
4100
+ name: "Gemini 4 Neon (Antigravity)",
4101
+ reasoning: true,
4102
+ limit: { context: 1048576, output: 262144 },
4103
+ modalities: DEFAULT_MODALITIES,
4104
+ variants: {
4105
+ low: { thinkingLevel: "low" },
4106
+ medium: { thinkingLevel: "medium" },
4107
+ high: { thinkingLevel: "high" },
4108
+ xhigh: { thinkingLevel: "xhigh" }
4109
+ }
4110
+ }),
4084
4111
  "antigravity-gemini-4-hydrogen": defineModel("antigravity-gemini-4-hydrogen", {
4085
4112
  name: "Gemini 4 Hydrogen (Antigravity)",
4086
4113
  reasoning: true,
@@ -4228,6 +4255,7 @@ var init_model_registry = __esm({
4228
4255
  "antigravity-gemini-4-argon",
4229
4256
  "antigravity-gemini-4-carbon",
4230
4257
  "antigravity-gemini-4-hydrogen",
4258
+ "antigravity-gemini-4-neon",
4231
4259
  "antigravity-gemini-3.8-flash",
4232
4260
  "antigravity-gemini-3.1-flash-image",
4233
4261
  "antigravity-claude-sonnet-5-5",
@@ -5681,11 +5709,21 @@ var init_account_repository = __esm({
5681
5709
  rowId: ref.id
5682
5710
  });
5683
5711
  }
5684
- await this.store.recordQuota(ref.id, credentialFenceOf(ref), encoded);
5685
- await this.updateMetadata(ref, (metadata) => metadata ? {
5686
- kind: "set",
5687
- metadata: applyRateLimitReadingUpdate(metadata, rateLimitReadingUpdateOf(observation), this.now())
5688
- } : { kind: "keep" });
5712
+ try {
5713
+ await this.store.recordQuota(ref.id, credentialFenceOf(ref), encoded);
5714
+ } catch (error) {
5715
+ if (error instanceof StaleQuotaObservationError || error instanceof this.storeFailure && error.cause instanceof StaleQuotaObservationError)
5716
+ return;
5717
+ throw error;
5718
+ }
5719
+ await this.updateMetadata(ref, (metadata, row) => {
5720
+ if (!metadata || observation.cachedQuotaUpdatedAt == null || row.quota.status !== "present" || row.quota.quota.cachedQuotaUpdatedAt !== observation.cachedQuotaUpdatedAt)
5721
+ return { kind: "keep" };
5722
+ return {
5723
+ kind: "set",
5724
+ metadata: applyRateLimitReadingUpdate(metadata, rateLimitReadingUpdateOf(observation), this.now())
5725
+ };
5726
+ });
5689
5727
  });
5690
5728
  }
5691
5729
  // ---- selection and roster ---------------------------------------------
@@ -6629,7 +6667,7 @@ function writeConsoleLog(level, ...args) {
6629
6667
  }
6630
6668
  function createLogger(module) {
6631
6669
  const service = `antigravity.${module}`;
6632
- const log9 = (level, message, extra) => {
6670
+ const log10 = (level, message, extra) => {
6633
6671
  if (_sink) {
6634
6672
  try {
6635
6673
  _sink({ service, level, message, extra });
@@ -6643,10 +6681,10 @@ function createLogger(module) {
6643
6681
  }
6644
6682
  };
6645
6683
  return {
6646
- debug: (message, extra) => log9("debug", message, extra),
6647
- info: (message, extra) => log9("info", message, extra),
6648
- warn: (message, extra) => log9("warn", message, extra),
6649
- error: (message, extra) => log9("error", message, extra)
6684
+ debug: (message, extra) => log10("debug", message, extra),
6685
+ info: (message, extra) => log10("info", message, extra),
6686
+ warn: (message, extra) => log10("warn", message, extra),
6687
+ error: (message, extra) => log10("error", message, extra)
6650
6688
  };
6651
6689
  }
6652
6690
  var ENV_CONSOLE_LOG, _sink;
@@ -7438,15 +7476,24 @@ function buildResponseStream(socket, leftover, head, signal, idleTimeoutMs, onDe
7438
7476
  source.write(leftover);
7439
7477
  }
7440
7478
  socket.pipe(source);
7479
+ const stages = [source];
7480
+ let framing;
7441
7481
  let responseBody = source;
7442
7482
  if (head.chunked) {
7443
- responseBody = responseBody.pipe(new ChunkedDecodeStream());
7483
+ framing = new ChunkedDecodeStream();
7444
7484
  } else if (typeof head.contentLength === "number") {
7445
- responseBody = responseBody.pipe(new ContentLengthStream(head.contentLength));
7485
+ framing = new ContentLengthStream(head.contentLength);
7486
+ }
7487
+ if (framing) {
7488
+ responseBody = responseBody.pipe(framing);
7489
+ stages.push(framing);
7446
7490
  }
7447
7491
  if (head.gzip) {
7448
7492
  responseBody = responseBody.pipe(createGunzip());
7493
+ stages.push(responseBody);
7449
7494
  }
7495
+ let settled = false;
7496
+ let socketEnded = false;
7450
7497
  let idleTimer;
7451
7498
  const clearIdle = () => {
7452
7499
  if (idleTimer) {
@@ -7460,31 +7507,55 @@ function buildResponseStream(socket, leftover, head, signal, idleTimeoutMs, onDe
7460
7507
  clearIdle();
7461
7508
  idleTimer = setTimeout(() => {
7462
7509
  onDebug?.(`agy transport idle timeout after ${idleTimeoutMs}ms with no body data`);
7463
- socket.destroy(new Error(`Antigravity response stalled: no data for ${idleTimeoutMs}ms`));
7510
+ settle(new Error("Antigravity response stalled: no body data within the limit"));
7464
7511
  }, idleTimeoutMs);
7465
7512
  };
7466
- socket.on("data", armIdle);
7467
- armIdle();
7468
- const abort = () => socket.destroy(new DOMException("The operation was aborted", "AbortError"));
7469
- const cleanup2 = () => {
7513
+ const abort = () => settle(new DOMException("The operation was aborted", "AbortError"));
7514
+ const onSocketEnd = () => {
7515
+ socketEnded = true;
7516
+ };
7517
+ const onSocketClose = () => {
7518
+ if (!socketEnded && !framing?.complete) {
7519
+ settle(new Error("Antigravity response connection closed before the body ended"));
7520
+ }
7521
+ };
7522
+ const fail2 = (error) => settle(error instanceof Error ? error : new Error(String(error)));
7523
+ function settle(error) {
7524
+ if (settled)
7525
+ return;
7526
+ settled = true;
7470
7527
  clearIdle();
7471
7528
  socket.off("data", armIdle);
7529
+ socket.off("end", onSocketEnd);
7530
+ socket.off("close", onSocketClose);
7472
7531
  signal?.removeEventListener("abort", abort);
7473
- };
7532
+ socket.unpipe(source);
7533
+ socket.destroy();
7534
+ for (const stage of stages) {
7535
+ if (stage !== responseBody && !stage.destroyed)
7536
+ stage.destroy();
7537
+ }
7538
+ if (!responseBody.destroyed) {
7539
+ if (error)
7540
+ responseBody.destroy(error);
7541
+ else if (!responseBody.readableEnded)
7542
+ responseBody.destroy();
7543
+ }
7544
+ }
7545
+ socket.on("error", fail2);
7546
+ socket.on("data", armIdle);
7547
+ socket.once("end", onSocketEnd);
7548
+ socket.once("close", onSocketClose);
7549
+ for (const stage of stages)
7550
+ stage.on("error", fail2);
7551
+ responseBody.once("end", () => settle());
7552
+ responseBody.once("close", () => settle());
7553
+ armIdle();
7474
7554
  if (signal?.aborted) {
7475
7555
  abort();
7476
7556
  } else {
7477
7557
  signal?.addEventListener("abort", abort, { once: true });
7478
7558
  }
7479
- responseBody.once("end", () => {
7480
- cleanup2();
7481
- socket.destroy();
7482
- });
7483
- responseBody.once("error", () => {
7484
- cleanup2();
7485
- socket.destroy();
7486
- });
7487
- responseBody.once("close", cleanup2);
7488
7559
  return Readable.toWeb(responseBody);
7489
7560
  }
7490
7561
  async function fetchWithAgyCliTransport(url, init = {}, options = {}) {
@@ -7542,6 +7613,11 @@ var init_agy_transport = __esm({
7542
7613
  constructor(contentLength) {
7543
7614
  super();
7544
7615
  this.remaining = contentLength;
7616
+ if (this.remaining <= 0)
7617
+ this.push(null);
7618
+ }
7619
+ get complete() {
7620
+ return this.remaining <= 0;
7545
7621
  }
7546
7622
  _transform(chunk, _encoding, callback) {
7547
7623
  if (this.remaining <= 0) {
@@ -7560,10 +7636,21 @@ var init_agy_transport = __esm({
7560
7636
  }
7561
7637
  callback();
7562
7638
  }
7639
+ _flush(callback) {
7640
+ callback(this.remaining > 0 ? new Error("Antigravity response ended before its declared length") : null);
7641
+ }
7563
7642
  };
7564
7643
  ChunkedDecodeStream = class extends Transform {
7565
7644
  buffer = Buffer2.alloc(0);
7645
+ finished = false;
7646
+ get complete() {
7647
+ return this.finished;
7648
+ }
7566
7649
  _transform(chunk, _encoding, callback) {
7650
+ if (this.finished) {
7651
+ callback();
7652
+ return;
7653
+ }
7567
7654
  this.buffer = Buffer2.concat([this.buffer, chunk]);
7568
7655
  try {
7569
7656
  this.flushAvailableChunks();
@@ -7574,8 +7661,9 @@ var init_agy_transport = __esm({
7574
7661
  }
7575
7662
  _flush(callback) {
7576
7663
  try {
7577
- this.flushAvailableChunks();
7578
- callback();
7664
+ if (!this.finished)
7665
+ this.flushAvailableChunks();
7666
+ callback(this.finished ? null : new Error("Antigravity response ended before its final chunk"));
7579
7667
  } catch (error) {
7580
7668
  callback(error instanceof Error ? error : new Error(String(error)));
7581
7669
  }
@@ -7591,16 +7679,19 @@ var init_agy_transport = __esm({
7591
7679
  if (!Number.isFinite(size)) {
7592
7680
  throw new Error(`Invalid chunk size: ${sizeLine}`);
7593
7681
  }
7594
- const chunkStart = lineEnd + 2;
7595
- const chunkEnd = chunkStart + size;
7596
- const nextOffset = chunkEnd + 2;
7597
- if (this.buffer.length < nextOffset)
7598
- return;
7599
7682
  if (size === 0) {
7683
+ if (this.buffer.indexOf("\r\n\r\n", lineEnd) === -1)
7684
+ return;
7685
+ this.finished = true;
7600
7686
  this.buffer = Buffer2.alloc(0);
7601
7687
  this.push(null);
7602
7688
  return;
7603
7689
  }
7690
+ const chunkStart = lineEnd + 2;
7691
+ const chunkEnd = chunkStart + size;
7692
+ const nextOffset = chunkEnd + 2;
7693
+ if (this.buffer.length < nextOffset)
7694
+ return;
7604
7695
  this.push(this.buffer.subarray(chunkStart, chunkEnd));
7605
7696
  this.buffer = this.buffer.subarray(nextOffset);
7606
7697
  }
@@ -16115,6 +16206,8 @@ async function request(operation) {
16115
16206
  function wrapHostClient(client) {
16116
16207
  const watchScoped = client.watchScoped?.bind(client);
16117
16208
  const reportUsageScoped = client.reportUsageScoped?.bind(client);
16209
+ const reportCondition = client.reportCondition?.bind(client);
16210
+ const clearCondition = client.clearCondition?.bind(client);
16118
16211
  return {
16119
16212
  listScoped: (...args) => request(() => client.listScoped(...args)),
16120
16213
  getScoped: (...args) => request(() => client.getScoped(...args)),
@@ -16135,6 +16228,12 @@ function wrapHostClient(client) {
16135
16228
  ...reportUsageScoped && {
16136
16229
  reportUsageScoped: (...args) => request(() => reportUsageScoped(...args))
16137
16230
  },
16231
+ ...reportCondition && {
16232
+ reportCondition: (...args) => request(() => reportCondition(...args))
16233
+ },
16234
+ ...clearCondition && {
16235
+ clearCondition: (...args) => request(() => clearCondition(...args))
16236
+ },
16138
16237
  ...client.insula && {
16139
16238
  insula: wrapInsula(client.insula)
16140
16239
  }
@@ -18813,22 +18912,22 @@ function credentialTypeOf(row, family) {
18813
18912
  return notMine;
18814
18913
  if ("classify" in family) {
18815
18914
  const metadata = rowFactsOf(row);
18816
- let type;
18915
+ let type2;
18817
18916
  switch (metadata.authMethod) {
18818
18917
  case "apikey":
18819
- type = "api_key";
18918
+ type2 = "api_key";
18820
18919
  break;
18821
18920
  case "chatgpt":
18822
18921
  case "antigravity":
18823
18922
  case "oauth":
18824
- type = "oauth";
18923
+ type2 = "oauth";
18825
18924
  break;
18826
18925
  default:
18827
18926
  return { kind: "refused", code: "unknown-auth-method" };
18828
18927
  }
18829
18928
  const facts = {
18830
18929
  credentialId: row.id,
18831
- credentialType: type,
18930
+ credentialType: type2,
18832
18931
  categories: row.categories,
18833
18932
  refreshAdapter: row.refreshAdapter,
18834
18933
  ...metadata
@@ -18840,24 +18939,59 @@ function credentialTypeOf(row, family) {
18840
18939
  if (result.kind === "not-mine")
18841
18940
  return notMine;
18842
18941
  if (result.kind === "mine" && typeof result.member === "string")
18843
- return { kind: "mine", type, member: result.member };
18942
+ return { kind: "mine", type: type2, member: result.member };
18844
18943
  if (result.kind === "refused" && typeof result.code === "string" && /^[a-z][a-z0-9-]{0,31}$/.test(result.code) && !result.code.includes("\n") && family.refusalCodes.includes(result.code))
18845
18944
  return { kind: "refused", code: result.code };
18846
18945
  } catch {
18847
18946
  }
18848
18947
  return { kind: "refused", code: "unclassified" };
18849
18948
  }
18850
- if (row.credentialType !== "oauth" && row.credentialType !== "api_key")
18949
+ const type = row.credentialType;
18950
+ if (type === "oauth") {
18951
+ if (row.refreshAdapter !== family.refreshAdapter)
18952
+ return notMine;
18953
+ } else if (type === "api_key") {
18954
+ if (!family.apiKeys || row.refreshAdapter !== void 0)
18955
+ return notMine;
18956
+ } else {
18851
18957
  return notMine;
18852
- if (row.credentialType === "oauth")
18853
- return row.refreshAdapter === family.refreshAdapter ? { kind: "mine", type: "oauth" } : notMine;
18854
- if (row.credentialType === "api_key" && family.apiKeys)
18855
- return row.refreshAdapter === void 0 ? { kind: "mine", type: "api_key" } : notMine;
18856
- return notMine;
18958
+ }
18959
+ const { authMethod } = rowFactsOf(row, { includeProviderIds: false });
18960
+ if (authMethod !== void 0) {
18961
+ const matchesType = type === "oauth" ? authMethod === "chatgpt" || authMethod === "antigravity" || authMethod === "oauth" : authMethod === "apikey";
18962
+ if (!matchesType)
18963
+ return { kind: "refused", code: "unknown-auth-method" };
18964
+ }
18965
+ return { kind: "mine", type };
18857
18966
  }
18858
- function rowFactsOf(row) {
18967
+ function rowFactsOf(row, { includeProviderIds = true } = {}) {
18859
18968
  const metadata = row;
18860
- return { providerIds: metadata.providerIds, authMethod: metadata.authMethod };
18969
+ return {
18970
+ providerIds: includeProviderIds ? metadata.providerIds : void 0,
18971
+ authMethod: metadata.authMethod
18972
+ };
18973
+ }
18974
+ function isVaultConditionReason(reason) {
18975
+ return reason === "provider_verification_required" || reason === "provider_ineligible";
18976
+ }
18977
+ function vaultConditionOf(row) {
18978
+ const condition = row.condition;
18979
+ if (!condition)
18980
+ return void 0;
18981
+ const { reason, sinceMs } = condition;
18982
+ if (isVaultConditionReason(reason) && Number.isSafeInteger(sinceMs) && sinceMs > 0)
18983
+ return Object.freeze({ reason, sinceMs });
18984
+ return void 0;
18985
+ }
18986
+ function httpsActionUrl(actionUrl) {
18987
+ if (typeof actionUrl !== "string")
18988
+ return void 0;
18989
+ try {
18990
+ if (new URL(actionUrl).protocol === "https:")
18991
+ return actionUrl;
18992
+ } catch {
18993
+ }
18994
+ return void 0;
18861
18995
  }
18862
18996
  function grantReachOf(listed) {
18863
18997
  const { grants, grantTuples } = listed;
@@ -18897,6 +19031,10 @@ var init_custody = __esm({
18897
19031
  #logger;
18898
19032
  #provenance = /* @__PURE__ */ new WeakMap();
18899
19033
  #reports = /* @__PURE__ */ new WeakMap();
19034
+ #conditionReports = /* @__PURE__ */ new Map();
19035
+ #conditionClears = /* @__PURE__ */ new Map();
19036
+ #conditionsUnsupported = false;
19037
+ #pendingConditionCalls = 0;
18900
19038
  #kept = /* @__PURE__ */ new Map();
18901
19039
  #keptAttempts = /* @__PURE__ */ new WeakMap();
18902
19040
  #usage;
@@ -18915,8 +19053,9 @@ var init_custody = __esm({
18915
19053
  #closed = false;
18916
19054
  /** The view of the last successful `discover()`, for `watchRoster`. */
18917
19055
  #discoveredView;
19056
+ #discoveredConditions = /* @__PURE__ */ new Map();
18918
19057
  #watches = /* @__PURE__ */ new Set();
18919
- #tokenReads = /* @__PURE__ */ new Set();
19058
+ #shutdownWork = /* @__PURE__ */ new Set();
18920
19059
  #warnShutdown;
18921
19060
  #onDrainTimeout;
18922
19061
  #disposing;
@@ -18975,6 +19114,7 @@ var init_custody = __esm({
18975
19114
  if (hasVaultHost() && !isVaultHostClient(next))
18976
19115
  throw new ClaustrumUnreachableError();
18977
19116
  this.#client = next;
19117
+ this.#conditionsUnsupported = false;
18978
19118
  for (const watch of this.#watches)
18979
19119
  watch.restart();
18980
19120
  }
@@ -19043,12 +19183,12 @@ var init_custody = __esm({
19043
19183
  phase: "token read begin"
19044
19184
  });
19045
19185
  const pending = this.#readToken();
19046
- this.#tokenReads.add(pending);
19186
+ this.#shutdownWork.add(pending);
19047
19187
  let value;
19048
19188
  try {
19049
19189
  value = await pending;
19050
19190
  } finally {
19051
- this.#tokenReads.delete(pending);
19191
+ this.#shutdownWork.delete(pending);
19052
19192
  if (phaseDiagnostics.hasSubscribers)
19053
19193
  phaseDiagnostics.publish({
19054
19194
  logger: this.#logger,
@@ -19101,6 +19241,11 @@ var init_custody = __esm({
19101
19241
  async discover(signal) {
19102
19242
  const inventory = await this.#list(signal);
19103
19243
  this.#discoveredView = inventory.view;
19244
+ this.#discoveredConditions.clear();
19245
+ for (const { credentialId, condition } of inventory.credentials) {
19246
+ if (condition)
19247
+ this.#discoveredConditions.set(credentialId, condition);
19248
+ }
19104
19249
  return inventory;
19105
19250
  }
19106
19251
  async #list(signal) {
@@ -19174,6 +19319,7 @@ var init_custody = __esm({
19174
19319
  });
19175
19320
  continue;
19176
19321
  }
19322
+ const condition = vaultConditionOf(row);
19177
19323
  credentials.push(Object.freeze({
19178
19324
  credentialId: row.id,
19179
19325
  credentialType: type,
@@ -19183,20 +19329,22 @@ var init_custody = __esm({
19183
19329
  },
19184
19330
  state: row.state,
19185
19331
  ...row.email !== void 0 && { email: row.email },
19186
- ...row.orgName !== void 0 && { orgName: row.orgName }
19332
+ ...row.orgName !== void 0 && { orgName: row.orgName },
19333
+ ...condition && { condition }
19187
19334
  }));
19188
19335
  }
19189
19336
  for (const record3 of skipped)
19190
19337
  this.#logger.warn("skipped malformed vault record", record3);
19191
19338
  const grantReach = grantReachOf(inventory);
19339
+ const classifying = "classify" in this.#family;
19192
19340
  return {
19193
19341
  view: inventory.view,
19194
19342
  credentials: Object.freeze(credentials),
19195
19343
  skipped: Object.freeze(skipped),
19196
- ..."classify" in this.#family && {
19197
- refused: Object.freeze(refused2),
19198
- notMine
19344
+ ...(classifying || refused2.length > 0) && {
19345
+ refused: Object.freeze(refused2)
19199
19346
  },
19347
+ ...classifying && { notMine },
19200
19348
  ...grantReach && { grantReach }
19201
19349
  };
19202
19350
  }
@@ -19527,6 +19675,90 @@ var init_custody = __esm({
19527
19675
  throw error;
19528
19676
  }
19529
19677
  }
19678
+ /**
19679
+ * Report a provider login condition as bookkeeping after handing back the
19680
+ * reply, never on the request path. Pass the receipt actually sent with it.
19681
+ */
19682
+ reportCondition(attempt, input) {
19683
+ const provenance = this.#provenance.get(attempt);
19684
+ if (!provenance)
19685
+ return Promise.reject(new ClaustrumConsumerError("no-receipt", "Claustrum condition report requires an original dispatch receipt"));
19686
+ const { reason, providerStatus } = input ?? {};
19687
+ if (this.#closed || this.#keptAttempts.has(attempt) || providerStatus !== 403 || !isVaultConditionReason(reason))
19688
+ return Promise.resolve("skipped");
19689
+ const { credentialId, recordVersion } = attempt;
19690
+ const actionUrl = reason === "provider_verification_required" ? httpsActionUrl(input.actionUrl) : void 0;
19691
+ return this.#conditionOnce(this.#conditionReports, JSON.stringify([credentialId, recordVersion, reason]), { credentialId, recordVersion, reason }, (client) => client.reportCondition?.({
19692
+ credentialId,
19693
+ recordVersion,
19694
+ reason,
19695
+ providerStatus,
19696
+ ...actionUrl !== void 0 && { actionUrl },
19697
+ enrollmentToken: provenance.token
19698
+ }));
19699
+ }
19700
+ /**
19701
+ * Clear a listed condition as bookkeeping after handing back a successful
19702
+ * reply, never on the request path. Pass the receipt actually sent with it.
19703
+ */
19704
+ clearCondition(attempt) {
19705
+ const provenance = this.#provenance.get(attempt);
19706
+ if (!provenance)
19707
+ return Promise.reject(new ClaustrumConsumerError("no-receipt", "Claustrum condition clear requires an original dispatch receipt"));
19708
+ if (this.#closed || this.#keptAttempts.has(attempt))
19709
+ return Promise.resolve("skipped");
19710
+ const { credentialId, recordVersion } = attempt;
19711
+ const condition = this.#discoveredConditions.get(credentialId);
19712
+ if (!condition)
19713
+ return Promise.resolve("skipped");
19714
+ return this.#conditionOnce(this.#conditionClears, JSON.stringify([credentialId, condition.sinceMs]), { credentialId, recordVersion, reason: condition.reason }, (client) => client.clearCondition?.({
19715
+ credentialId,
19716
+ recordVersion,
19717
+ enrollmentToken: provenance.token
19718
+ }));
19719
+ }
19720
+ #conditionOnce(outcomes, key, details, send) {
19721
+ const previous = outcomes.get(key);
19722
+ if (previous)
19723
+ return previous;
19724
+ if (this.#conditionsUnsupported)
19725
+ return Promise.resolve("unsupported");
19726
+ const pending = Promise.resolve().then(async () => {
19727
+ const client = this.#client;
19728
+ if (this.#conditionsUnsupported)
19729
+ return "unsupported";
19730
+ try {
19731
+ const sent = send(client);
19732
+ if (!sent)
19733
+ return "unsupported";
19734
+ if (await sent === false)
19735
+ this.#debugCondition("scoped login condition not cleared", details);
19736
+ return "reported";
19737
+ } catch (error) {
19738
+ if (error instanceof ClaustrumCredentialError5 && error.code === "unknown_method") {
19739
+ if (client === this.#client)
19740
+ this.#conditionsUnsupported = true;
19741
+ return "unsupported";
19742
+ }
19743
+ this.#debugCondition("scoped login condition update failed", details);
19744
+ return "failed";
19745
+ }
19746
+ });
19747
+ outcomes.set(key, pending);
19748
+ this.#pendingConditionCalls++;
19749
+ this.#shutdownWork.add(pending);
19750
+ void pending.then(() => {
19751
+ this.#pendingConditionCalls--;
19752
+ this.#shutdownWork.delete(pending);
19753
+ });
19754
+ return pending;
19755
+ }
19756
+ #debugCondition(message, details) {
19757
+ try {
19758
+ this.#logger.debug(message, details);
19759
+ } catch {
19760
+ }
19761
+ }
19530
19762
  /**
19531
19763
  * Watch this consumer's visible vault accounts instead of listing them on a
19532
19764
  * short timer. Opens one `watchScoped` on this custody's client and calls
@@ -19642,15 +19874,17 @@ var init_custody = __esm({
19642
19874
  this.#watches.clear();
19643
19875
  this.#kept.clear();
19644
19876
  const usage = this.#usage.close();
19877
+ const keepClientOpen = usage !== void 0 || this.#pendingConditionCalls > 0;
19645
19878
  if (usage) {
19646
- this.#tokenReads.add(usage);
19647
- void usage.then(() => this.#tokenReads.delete(usage));
19648
- } else
19879
+ this.#shutdownWork.add(usage);
19880
+ void usage.then(() => this.#shutdownWork.delete(usage));
19881
+ }
19882
+ if (!keepClientOpen)
19649
19883
  this.#client.close();
19650
- this.#disposing = drainShutdown(this.#tokenReads, (count3) => (this.#onDrainTimeout ?? this.#warnShutdown)(count3)).finally(() => {
19884
+ this.#disposing = drainShutdown(this.#shutdownWork, (count3) => (this.#onDrainTimeout ?? this.#warnShutdown)(count3)).finally(() => {
19651
19885
  this.#usage.drop();
19652
19886
  this.#usageServed.clear();
19653
- if (usage)
19887
+ if (keepClientOpen)
19654
19888
  this.#client.close();
19655
19889
  });
19656
19890
  }
@@ -21245,6 +21479,36 @@ var init_consumer = __esm({
21245
21479
  throw new ClaustrumConsumerError("no-receipt", "Claustrum dispatch receipt has no active owner");
21246
21480
  await this.#custody.reportFailure(attempt, status, source);
21247
21481
  }
21482
+ /** The custody (or hub lease) that issued `attempt`, or a `no-receipt` refusal. */
21483
+ #issuingCustody(attempt) {
21484
+ const custody = this.#hub ? this.#issuedBy.get(attempt)?.custody : this.#custody;
21485
+ if (!custody)
21486
+ throw new ClaustrumConsumerError("no-receipt", "Claustrum dispatch receipt has no active owner");
21487
+ return custody;
21488
+ }
21489
+ /**
21490
+ * Report a provider login condition through the custody that issued the
21491
+ * receipt; see `ClaustrumScopedCustody.reportCondition`. Bookkeeping: call it
21492
+ * after handing back the reply, never on the request path. It resolves
21493
+ * `skipped` after shutdown and rejects only with `no-receipt` for a receipt
21494
+ * no live custody of this consumer issued.
21495
+ */
21496
+ async reportCondition(attempt, input) {
21497
+ if (this.#shutdown.signal.aborted)
21498
+ return "skipped";
21499
+ return this.#issuingCustody(attempt).reportCondition(attempt, input);
21500
+ }
21501
+ /**
21502
+ * Clear a listed login condition through the custody that issued the
21503
+ * receipt; see `ClaustrumScopedCustody.clearCondition`. Safe to call after
21504
+ * every successful reply: it sends nothing unless the login is marked.
21505
+ * Same `skipped` and `no-receipt` rules as `reportCondition`.
21506
+ */
21507
+ async clearCondition(attempt) {
21508
+ if (this.#shutdown.signal.aborted)
21509
+ return "skipped";
21510
+ return this.#issuingCustody(attempt).clearCondition(attempt);
21511
+ }
21248
21512
  /**
21249
21513
  * Send on a vault route. `dispatch` builds and sends the request with the
21250
21514
  * receipt's token and may be called twice, so it must be able to rebuild
@@ -21851,6 +22115,16 @@ var init_hub = __esm({
21851
22115
  check();
21852
22116
  return custody.reportFailure(attempt, status, source);
21853
22117
  },
22118
+ reportCondition: async (attempt, input) => {
22119
+ if (state.released || generation.ended)
22120
+ return "skipped";
22121
+ return custody.reportCondition(attempt, input);
22122
+ },
22123
+ clearCondition: async (attempt) => {
22124
+ if (state.released || generation.ended)
22125
+ return "skipped";
22126
+ return custody.clearCondition(attempt);
22127
+ },
21854
22128
  reportUsage: (input) => {
21855
22129
  if (!state.released && !generation.ended)
21856
22130
  custody.reportUsage(input);
@@ -23236,7 +23510,7 @@ function invalidateProjectContextCache(refresh) {
23236
23510
  projectContextResultCache.delete(cacheKey);
23237
23511
  provisionFailedKeys.delete(cacheKey);
23238
23512
  }
23239
- async function loadManagedProject(accessToken, _projectId) {
23513
+ async function loadManagedProject(accessToken, _projectId, admit2) {
23240
23514
  const requestBody = buildBootstrapRequestBody();
23241
23515
  const loadHeaders = buildAntigravityHarnessBootstrapHeaders(accessToken);
23242
23516
  const loadEndpoints = Array.from(/* @__PURE__ */ new Set([
@@ -23244,6 +23518,8 @@ async function loadManagedProject(accessToken, _projectId) {
23244
23518
  ...ANTIGRAVITY_ENDPOINT_FALLBACKS
23245
23519
  ]));
23246
23520
  for (const baseEndpoint of loadEndpoints) {
23521
+ if (admit2)
23522
+ await admit2();
23247
23523
  try {
23248
23524
  const response = await fetchWithAgyCliTransport(`${baseEndpoint}/v1internal:loadCodeAssist`, {
23249
23525
  method: "POST",
@@ -23263,7 +23539,7 @@ async function loadManagedProject(accessToken, _projectId) {
23263
23539
  }
23264
23540
  return null;
23265
23541
  }
23266
- async function onboardManagedProject(accessToken, tierId, projectId, attempts2 = 10, delayMs = 5e3) {
23542
+ async function onboardManagedProject(accessToken, tierId, projectId, attempts2 = 10, delayMs = 5e3, admit2) {
23267
23543
  const requestBody = { tierId };
23268
23544
  const onboardEndpoints = Array.from(/* @__PURE__ */ new Set([
23269
23545
  ANTIGRAVITY_ENDPOINT_PROD,
@@ -23272,6 +23548,8 @@ async function onboardManagedProject(accessToken, tierId, projectId, attempts2 =
23272
23548
  ]));
23273
23549
  for (const baseEndpoint of onboardEndpoints) {
23274
23550
  for (let attempt = 0; attempt < attempts2; attempt += 1) {
23551
+ if (admit2)
23552
+ await admit2();
23275
23553
  try {
23276
23554
  const response = await fetchWithAgyCliTransport(`${baseEndpoint}/v1internal:onboardUser`, {
23277
23555
  method: "POST",
@@ -23306,7 +23584,7 @@ async function onboardManagedProject(accessToken, tierId, projectId, attempts2 =
23306
23584
  }
23307
23585
  return void 0;
23308
23586
  }
23309
- async function ensureProjectContext(auth) {
23587
+ async function ensureProjectContext(auth, admit2) {
23310
23588
  const accessToken = auth.access;
23311
23589
  if (!accessToken) {
23312
23590
  return { auth, effectiveProjectId: "" };
@@ -23350,7 +23628,7 @@ async function ensureProjectContext(auth) {
23350
23628
  capturedTier
23351
23629
  };
23352
23630
  };
23353
- const loadPayload = await loadManagedProject(accessToken, parts.projectId ?? fallbackProjectId);
23631
+ const loadPayload = await loadManagedProject(accessToken, parts.projectId ?? fallbackProjectId, admit2);
23354
23632
  const capturedTierId = loadPayload?.currentTier?.id;
23355
23633
  const paidTierId = typeof loadPayload?.paidTier === "string" ? loadPayload.paidTier : loadPayload?.paidTier?.id;
23356
23634
  const tierFromPayload = capturedTierId ? {
@@ -23367,7 +23645,7 @@ async function ensureProjectContext(auth) {
23367
23645
  tierId,
23368
23646
  projectId: parts.projectId
23369
23647
  });
23370
- const provisionedProjectId = await onboardManagedProject(accessToken, tierId, parts.projectId);
23648
+ const provisionedProjectId = await onboardManagedProject(accessToken, tierId, parts.projectId, void 0, void 0, admit2);
23371
23649
  if (provisionedProjectId) {
23372
23650
  log3.debug("Successfully provisioned managed project", {
23373
23651
  provisionedProjectId
@@ -25476,7 +25754,7 @@ async function prepareVaultFolder(options) {
25476
25754
  const kept = refusals.get(key);
25477
25755
  if (kept)
25478
25756
  return override ? { ...override, refusal: kept } : refused(accountFile, kept);
25479
- const log9 = options.log ?? createLogger4("runtime-layout");
25757
+ const log10 = options.log ?? createLogger4("runtime-layout");
25480
25758
  const version = options.version ?? await pluginPackageVersion().catch(() => "unknown");
25481
25759
  try {
25482
25760
  if (override) {
@@ -25485,11 +25763,11 @@ async function prepareVaultFolder(options) {
25485
25763
  await prepareRuntimeLayout({
25486
25764
  version,
25487
25765
  accountFile,
25488
- log: log9,
25766
+ log: log10,
25489
25767
  ...options.layoutLockWaitMs === void 0 ? {} : { layoutLockWaitMs: options.layoutLockWaitMs }
25490
25768
  });
25491
25769
  if (options.accountStore !== false)
25492
- await prepareAccountStore({ version, log: log9 });
25770
+ await prepareAccountStore({ version, log: log10 });
25493
25771
  } catch (error) {
25494
25772
  const refusal3 = error instanceof RuntimeLayoutRefusal ? error : new RuntimeLayoutRefusal(
25495
25773
  override?.vaultDir ?? runtimeLayoutLocation().stateHomeDir,
@@ -25497,7 +25775,7 @@ async function prepareVaultFolder(options) {
25497
25775
  );
25498
25776
  if (!refusals.has(key)) {
25499
25777
  refusals.set(key, refusal3);
25500
- log9.warn(refusal3.message, {
25778
+ log10.warn(refusal3.message, {
25501
25779
  stateDir: refusal3.stateDir,
25502
25780
  errorClass: refusal3.errorClass
25503
25781
  });
@@ -25618,10 +25896,10 @@ function errorFile(error) {
25618
25896
  ...typeof stage === "string" && stage ? { stage } : {}
25619
25897
  };
25620
25898
  }
25621
- function logCleanupFailure(location, log9, step, error) {
25899
+ function logCleanupFailure(location, log10, step, error) {
25622
25900
  logOnce(
25623
25901
  `${location.key}\0cleanup`,
25624
- () => log9.warn(
25902
+ () => log10.warn(
25625
25903
  "antigravity-auth could not finish removing its old vault files from OpenCode's config folder; it tries again at the next start",
25626
25904
  {
25627
25905
  configDir: location.configDir,
@@ -25650,13 +25928,13 @@ function prepareRuntimeLayout(options) {
25650
25928
  return run;
25651
25929
  }
25652
25930
  async function decide(location, options) {
25653
- const log9 = options.log ?? createLogger4("runtime-layout");
25931
+ const log10 = options.log ?? createLogger4("runtime-layout");
25654
25932
  const stateDir = location.stateHomeDir;
25655
25933
  const markerPath = join14(stateDir, RUNTIME_LAYOUT_MARKER_FILE);
25656
25934
  const files = layoutFiles(location, options.accountFile);
25657
25935
  const fence = options.fence ?? defaultFence(options.version);
25658
25936
  const stateHome = async () => {
25659
- await settleVault(location, options, "state-home", log9);
25937
+ await settleVault(location, options, "state-home", log10);
25660
25938
  return "state-home";
25661
25939
  };
25662
25940
  let marker = await readMarker(markerPath, stateDir, files.vault.old);
@@ -25667,7 +25945,7 @@ async function decide(location, options) {
25667
25945
  join14(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE)
25668
25946
  ).catch(() => true);
25669
25947
  if (!manifestLeft) {
25670
- await settleVault(location, options, "state-home", log9);
25948
+ await settleVault(location, options, "state-home", log10);
25671
25949
  return stateHome();
25672
25950
  }
25673
25951
  }
@@ -25679,7 +25957,7 @@ async function decide(location, options) {
25679
25957
  RUNTIME_LAYOUT_LOCK_NAME,
25680
25958
  markerPath,
25681
25959
  options.layoutLockWaitMs ?? LAYOUT_LOCK_WAIT_MS,
25682
- log9
25960
+ log10
25683
25961
  );
25684
25962
  } catch (error) {
25685
25963
  marker = await readMarker(markerPath, stateDir, files.vault.old);
@@ -25699,7 +25977,7 @@ async function decide(location, options) {
25699
25977
  const legacy = async () => {
25700
25978
  try {
25701
25979
  await lock.assertOwned();
25702
- await settleVault(location, options, "legacy", log9);
25980
+ await settleVault(location, options, "legacy", log10);
25703
25981
  } catch (error) {
25704
25982
  throw new RuntimeLayoutRefusal(stateDir, errorClass(error));
25705
25983
  }
@@ -25713,20 +25991,20 @@ async function decide(location, options) {
25713
25991
  if (!marker.oldFilesRemoved && !aliased)
25714
25992
  await finishOldFiles(location, files, markerPath, marker, lock, {
25715
25993
  fence,
25716
- log: log9,
25994
+ log: log10,
25717
25995
  steps: options.steps,
25718
25996
  oldSignatureCache: options.oldSignatureCacheFile ?? legacySignatureCacheFile()
25719
25997
  });
25720
25998
  else if (marker.oldFilesRemoved) {
25721
25999
  await refuseReappearedFiles(location, files);
25722
- await removeLeftoverManifest(location, lock, options.steps, log9);
26000
+ await removeLeftoverManifest(location, lock, options.steps, log10);
25723
26001
  }
25724
26002
  return await stateHome();
25725
26003
  }
25726
26004
  if (aliased) {
25727
26005
  logOnce(
25728
26006
  `${location.key}\0aliased`,
25729
- () => log9.warn(
26007
+ () => log10.warn(
25730
26008
  "antigravity-auth keeps its vault files in OpenCode's config folder: its state folder is that same folder",
25731
26009
  { configDir: location.configDir, stateDir }
25732
26010
  )
@@ -25735,14 +26013,14 @@ async function decide(location, options) {
25735
26013
  }
25736
26014
  const gate = await fence();
25737
26015
  if (!gate.open) {
25738
- logDeferral(location, gate.blockers, log9);
26016
+ logDeferral(location, gate.blockers, log10);
25739
26017
  return await legacy();
25740
26018
  }
25741
26019
  let markerStarted = false;
25742
26020
  try {
25743
26021
  const outcome = await moveFiles(location, files, markerPath, lock, {
25744
26022
  fence,
25745
- log: log9,
26023
+ log: log10,
25746
26024
  steps: options.steps,
25747
26025
  destinationPrivate: options.destinationPrivate ?? defaultDestinationPrivate,
25748
26026
  oldSignatureCache: options.oldSignatureCacheFile ?? legacySignatureCacheFile(),
@@ -25751,13 +26029,13 @@ async function decide(location, options) {
25751
26029
  }
25752
26030
  });
25753
26031
  if (outcome.kind === "deferred") {
25754
- logDeferral(location, outcome.blockers, log9);
26032
+ logDeferral(location, outcome.blockers, log10);
25755
26033
  return await legacy();
25756
26034
  }
25757
26035
  if (outcome.kind === "refused") {
25758
26036
  logOnce(
25759
26037
  `${location.key}\0refused`,
25760
- () => log9.warn(
26038
+ () => log10.warn(
25761
26039
  outcome.reason === "destination-not-private" ? "antigravity-auth keeps its vault files in OpenCode's config folder: the vault folder in its state folder already exists and is not private to your user. It was left unchanged; remove it if it holds nothing you need, then restart OpenCode." : "antigravity-auth keeps its vault files in OpenCode's config folder: it will not move them",
25762
26040
  { reason: outcome.reason, paths: outcome.paths, stateDir }
25763
26041
  )
@@ -25765,7 +26043,7 @@ async function decide(location, options) {
25765
26043
  return await legacy();
25766
26044
  }
25767
26045
  if (outcome.moved)
25768
- log9.info(
26046
+ log10.info(
25769
26047
  "antigravity-auth moved its vault files out of OpenCode's config folder",
25770
26048
  { from: files.vault.old, to: files.vault.next }
25771
26049
  );
@@ -25776,7 +26054,7 @@ async function decide(location, options) {
25776
26054
  return await stateHome();
25777
26055
  logOnce(
25778
26056
  `${location.key}\0failed`,
25779
- () => log9.warn(
26057
+ () => log10.warn(
25780
26058
  "antigravity-auth's vault files stay in OpenCode's config folder: moving them failed; the move is tried again at the next start",
25781
26059
  {
25782
26060
  configDir: location.configDir,
@@ -25825,7 +26103,7 @@ async function prepareAccountStore(options) {
25825
26103
  if (!await localAccountStoreAuthorized()) return void 0;
25826
26104
  const decided = decidedAccountStoreAnchor(location);
25827
26105
  if (decided) return decided;
25828
- const log9 = options.log ?? createLogger4("runtime-layout");
26106
+ const log10 = options.log ?? createLogger4("runtime-layout");
25829
26107
  const runKey = `${location.stateHomeDir}\0${location.key}`;
25830
26108
  let run = processState.storeRuns.get(runKey);
25831
26109
  if (!run) {
@@ -25836,12 +26114,12 @@ async function prepareAccountStore(options) {
25836
26114
  RUNTIME_LAYOUT_LOCK_NAME,
25837
26115
  join14(location.stateHomeDir, RUNTIME_LAYOUT_MARKER_FILE),
25838
26116
  options.layoutLockWaitMs ?? LAYOUT_LOCK_WAIT_MS,
25839
- log9
26117
+ log10
25840
26118
  );
25841
26119
  try {
25842
26120
  await lock.assertOwned();
25843
26121
  if (!await localAccountStoreAuthorized()) return void 0;
25844
- return await settleAccountStore(location, options, log9);
26122
+ return await settleAccountStore(location, options, log10);
25845
26123
  } finally {
25846
26124
  await lock.release();
25847
26125
  }
@@ -25852,20 +26130,20 @@ async function prepareAccountStore(options) {
25852
26130
  }
25853
26131
  return run;
25854
26132
  }
25855
- async function settleAccountStore(location, options, log9) {
26133
+ async function settleAccountStore(location, options, log10) {
25856
26134
  const decided = decidedAccountStoreAnchor(location);
25857
26135
  if (decided) return decided;
25858
- const anchor = await decideAccountStore(location, options, log9);
26136
+ const anchor = await decideAccountStore(location, options, log10);
25859
26137
  setAccountStoreAnchor(location, anchor);
25860
26138
  return anchor;
25861
26139
  }
25862
- async function decideAccountStore(location, options, log9) {
25863
- const keepConfig = () => recordAnchor(location, options, "config", log9);
26140
+ async function decideAccountStore(location, options, log10) {
26141
+ const keepConfig = () => recordAnchor(location, options, "config", log10);
25864
26142
  if (processHasOlderGeneration()) {
25865
26143
  logOnce(
25866
26144
  "older-generation-account-store",
25867
26145
  () => showLog(
25868
- log9,
26146
+ log10,
25869
26147
  "antigravity-auth keeps the account store in OpenCode's config folder until OpenCode restarts, because an older version of the plugin ran in this process.",
25870
26148
  { accountStore: "config" }
25871
26149
  )
@@ -25879,7 +26157,7 @@ async function decideAccountStore(location, options, log9) {
25879
26157
  if (!sameSpelling(forward.legacyPath, stateAnchor)) {
25880
26158
  logOnce(
25881
26159
  `${location.key}\0store-forward-elsewhere`,
25882
- () => log9.warn(
26160
+ () => log10.warn(
25883
26161
  "the account store moved to another folder than this process resolved; check XDG_STATE_HOME",
25884
26162
  { movedTo: forward.legacyPath, expected: stateAnchor }
25885
26163
  )
@@ -25890,9 +26168,9 @@ async function decideAccountStore(location, options, log9) {
25890
26168
  options,
25891
26169
  configAnchor,
25892
26170
  stateAnchor,
25893
- log9
26171
+ log10
25894
26172
  );
25895
- return recordAnchor(location, options, "state-home", log9);
26173
+ return recordAnchor(location, options, "state-home", log10);
25896
26174
  }
25897
26175
  if (decidedRuntimeLayout(location) === "legacy") return keepConfig();
25898
26176
  const configStore = await presentAccountStore(configAnchor);
@@ -25904,9 +26182,9 @@ async function decideAccountStore(location, options, log9) {
25904
26182
  `antigravity-auth cannot start: two account stores exist, one at ${configAnchor} and one at ${stateAnchor}, and neither is marked as moved. Keep the one you want and move the other one aside, then restart OpenCode.`
25905
26183
  );
25906
26184
  }
25907
- if (stateStore) return recordAnchor(location, options, "state-home", log9);
26185
+ if (stateStore) return recordAnchor(location, options, "state-home", log10);
25908
26186
  if (configStore) {
25909
- if (!await storeMovePathResolves(stateAnchor, location, log9))
26187
+ if (!await storeMovePathResolves(stateAnchor, location, log10))
25910
26188
  return keepConfig();
25911
26189
  return moveStore(
25912
26190
  location,
@@ -25914,21 +26192,21 @@ async function decideAccountStore(location, options, log9) {
25914
26192
  configAnchor,
25915
26193
  stateAnchor,
25916
26194
  false,
25917
- log9,
26195
+ log10,
25918
26196
  false
25919
26197
  );
25920
26198
  }
25921
- if (await storeArtefacts(stateAnchor) > 0 && !await abandonUnpublishedStore(location, stateAnchor, log9))
26199
+ if (await storeArtefacts(stateAnchor) > 0 && !await abandonUnpublishedStore(location, stateAnchor, log10))
25922
26200
  return keepConfig();
25923
- if (!await storeMovePathResolves(stateAnchor, location, log9))
26201
+ if (!await storeMovePathResolves(stateAnchor, location, log10))
25924
26202
  return keepConfig();
25925
- return initializeStore(location, options, stateAnchor, log9);
26203
+ return initializeStore(location, options, stateAnchor, log10);
25926
26204
  }
25927
- function showLog(log9, message, meta) {
25928
- if (log9.log) log9.log(message, meta);
25929
- else log9.info(message, meta);
26205
+ function showLog(log10, message, meta) {
26206
+ if (log10.log) log10.log(message, meta);
26207
+ else log10.info(message, meta);
25930
26208
  }
25931
- async function recordAnchor(location, options, anchor, log9) {
26209
+ async function recordAnchor(location, options, anchor, log10) {
25932
26210
  try {
25933
26211
  await recordProcessAnchor({
25934
26212
  key: location.key,
@@ -25940,32 +26218,32 @@ async function recordAnchor(location, options, anchor, log9) {
25940
26218
  }
25941
26219
  if (anchor === "state-home")
25942
26220
  showLog(
25943
- log9,
26221
+ log10,
25944
26222
  "antigravity-auth keeps its account store in its state folder",
25945
26223
  { accountStore: anchor }
25946
26224
  );
25947
26225
  return anchor;
25948
26226
  }
25949
- async function storeMovePathResolves(stateAnchor, location, log9) {
26227
+ async function storeMovePathResolves(stateAnchor, location, log10) {
25950
26228
  if (folderResolvesToItself(
25951
26229
  join14(location.stateHomeDir, "antigravity-accounts.json")
25952
26230
  ))
25953
26231
  return true;
25954
26232
  logOnce(
25955
26233
  `${location.key}\0store-linked-path`,
25956
- () => log9.warn(ACCOUNT_STORE_LINKED_PATH_MESSAGE, {
26234
+ () => log10.warn(ACCOUNT_STORE_LINKED_PATH_MESSAGE, {
25957
26235
  accountStore: stateAnchor,
25958
26236
  stateFolder: location.stateHomeDir
25959
26237
  })
25960
26238
  );
25961
26239
  return false;
25962
26240
  }
25963
- async function storeFenceOpen(location, options, log9) {
26241
+ async function storeFenceOpen(location, options, log10) {
25964
26242
  const gate = await (options.storeFence ?? defaultStoreFence(options.version))();
25965
26243
  if (gate.open) return true;
25966
26244
  logOnce(
25967
26245
  `${location.key}\0store-version-fence`,
25968
- () => log9.info(ACCOUNT_STORE_DEFERRED_MESSAGE, {
26246
+ () => log10.info(ACCOUNT_STORE_DEFERRED_MESSAGE, {
25969
26247
  configDir: location.configDir,
25970
26248
  blockers: gate.blockers
25971
26249
  })
@@ -25992,7 +26270,7 @@ async function storeArtefacts(anchor) {
25992
26270
  (name) => name === store || name.startsWith(`${pool}.store.`) || name.startsWith(pool) && name.endsWith(".tmp")
25993
26271
  ).length;
25994
26272
  }
25995
- async function abandonUnpublishedStore(location, stateAnchor, log9) {
26273
+ async function abandonUnpublishedStore(location, stateAnchor, log10) {
25996
26274
  const store = await loadCommonAuthStoreModules();
25997
26275
  const binding = await readAccountStoreBinding(stateAnchor, store, Date.now);
25998
26276
  if (binding.status === "bound") return false;
@@ -26003,7 +26281,7 @@ async function abandonUnpublishedStore(location, stateAnchor, log9) {
26003
26281
  });
26004
26282
  await unlink11(accountStorePointerPath(stateAnchor)).catch(() => {
26005
26283
  });
26006
- log9.info(
26284
+ log10.info(
26007
26285
  "antigravity-auth set an unfinished account store aside before starting its move again",
26008
26286
  { configDir: location.configDir, archived }
26009
26287
  );
@@ -26025,9 +26303,9 @@ async function runStoreMove(input) {
26025
26303
  return { status: "pending", reason: outcome.reason };
26026
26304
  return { status: "cancelled" };
26027
26305
  }
26028
- async function moveStore(location, options, source, target, back, log9, forwarded) {
26029
- const keepConfig = () => recordAnchor(location, options, "config", log9);
26030
- if (!await storeFenceOpen(location, options, log9)) return keepConfig();
26306
+ async function moveStore(location, options, source, target, back, log10, forwarded) {
26307
+ const keepConfig = () => recordAnchor(location, options, "config", log10);
26308
+ if (!await storeFenceOpen(location, options, log10)) return keepConfig();
26031
26309
  try {
26032
26310
  const result = await (options.relocate ?? runStoreMove)({
26033
26311
  source,
@@ -26037,7 +26315,7 @@ async function moveStore(location, options, source, target, back, log9, forwarde
26037
26315
  if (result.status !== "completed") {
26038
26316
  logOnce(
26039
26317
  `${location.key}\0store-move-unfinished`,
26040
- () => log9.info(ACCOUNT_STORE_DEFERRED_MESSAGE, {
26318
+ () => log10.info(ACCOUNT_STORE_DEFERRED_MESSAGE, {
26041
26319
  configDir: location.configDir,
26042
26320
  reason: result.status === "pending" ? result.reason : result.status
26043
26321
  })
@@ -26045,14 +26323,14 @@ async function moveStore(location, options, source, target, back, log9, forwarde
26045
26323
  return forwarded ? "state-home" : keepConfig();
26046
26324
  }
26047
26325
  showLog(
26048
- log9,
26326
+ log10,
26049
26327
  "antigravity-auth moved the account store out of OpenCode's config folder",
26050
26328
  { from: source, to: target, generation: result.id }
26051
26329
  );
26052
26330
  } catch (error) {
26053
26331
  logOnce(
26054
26332
  `${location.key}\0store-move-failed`,
26055
- () => log9.warn(
26333
+ () => log10.warn(
26056
26334
  "antigravity-auth's account store stays in OpenCode's config folder: moving it failed; the move is tried again at the next start",
26057
26335
  {
26058
26336
  configDir: location.configDir,
@@ -26063,9 +26341,9 @@ async function moveStore(location, options, source, target, back, log9, forwarde
26063
26341
  );
26064
26342
  return forwarded ? "state-home" : keepConfig();
26065
26343
  }
26066
- return recordAnchor(location, options, "state-home", log9);
26344
+ return recordAnchor(location, options, "state-home", log10);
26067
26345
  }
26068
- async function resumeForwardedStore(location, options, configAnchor, stateAnchor, log9) {
26346
+ async function resumeForwardedStore(location, options, configAnchor, stateAnchor, log10) {
26069
26347
  const store = await loadCommonAuthStoreModules();
26070
26348
  const binding = await readAccountStoreBinding(stateAnchor, store, Date.now);
26071
26349
  if (binding.status === "bound") return;
@@ -26076,13 +26354,13 @@ async function resumeForwardedStore(location, options, configAnchor, stateAnchor
26076
26354
  configAnchor,
26077
26355
  stateAnchor,
26078
26356
  false,
26079
- log9,
26357
+ log10,
26080
26358
  true
26081
26359
  );
26082
26360
  } catch (error) {
26083
26361
  logOnce(
26084
26362
  `${location.key}\0store-resume-failed`,
26085
- () => log9.warn(
26363
+ () => log10.warn(
26086
26364
  "antigravity-auth's account store is still moving; it could not be finished at this start",
26087
26365
  {
26088
26366
  configDir: location.configDir,
@@ -26093,9 +26371,9 @@ async function resumeForwardedStore(location, options, configAnchor, stateAnchor
26093
26371
  );
26094
26372
  }
26095
26373
  }
26096
- async function initializeStore(location, options, stateAnchor, log9) {
26097
- const keepConfig = () => recordAnchor(location, options, "config", log9);
26098
- if (!await storeFenceOpen(location, options, log9)) return keepConfig();
26374
+ async function initializeStore(location, options, stateAnchor, log10) {
26375
+ const keepConfig = () => recordAnchor(location, options, "config", log10);
26376
+ if (!await storeFenceOpen(location, options, log10)) return keepConfig();
26099
26377
  try {
26100
26378
  const store = await loadCommonAuthStoreModules();
26101
26379
  const created = await initializeFreshAccountStore(store, {
@@ -26108,7 +26386,7 @@ async function initializeStore(location, options, stateAnchor, log9) {
26108
26386
  } catch (error) {
26109
26387
  logOnce(
26110
26388
  `${location.key}\0store-init-failed`,
26111
- () => log9.warn(
26389
+ () => log10.warn(
26112
26390
  "antigravity-auth's account store stays in OpenCode's config folder: creating it in its state folder failed; it is tried again at the next start",
26113
26391
  {
26114
26392
  configDir: location.configDir,
@@ -26120,13 +26398,13 @@ async function initializeStore(location, options, stateAnchor, log9) {
26120
26398
  return keepConfig();
26121
26399
  }
26122
26400
  showLog(
26123
- log9,
26401
+ log10,
26124
26402
  "antigravity-auth created its account store in its state folder",
26125
26403
  {
26126
26404
  accountStore: stateAnchor
26127
26405
  }
26128
26406
  );
26129
- return recordAnchor(location, options, "state-home", log9);
26407
+ return recordAnchor(location, options, "state-home", log10);
26130
26408
  }
26131
26409
  async function writeStateHomeStoreForward(id, stateAnchor, configAnchor = legacyAccountFile(runtimeLayoutLocation().configDir)) {
26132
26410
  const forward = {
@@ -26141,10 +26419,10 @@ async function writeStateHomeStoreForward(id, stateAnchor, configAnchor = legacy
26141
26419
  durability: "file-only-on-windows"
26142
26420
  });
26143
26421
  }
26144
- function logDeferral(location, blockers, log9) {
26422
+ function logDeferral(location, blockers, log10) {
26145
26423
  logOnce(
26146
26424
  `${location.key}\0deferred`,
26147
- () => log9.info(RUNTIME_LAYOUT_DEFERRED_MESSAGE, {
26425
+ () => log10.info(RUNTIME_LAYOUT_DEFERRED_MESSAGE, {
26148
26426
  configDir: location.configDir,
26149
26427
  blockers
26150
26428
  })
@@ -26302,13 +26580,13 @@ async function finishOldFiles(location, files, markerPath, marker, layoutLock, i
26302
26580
  if (done) await removeOldVaultFolder(files, layoutLock, input.steps);
26303
26581
  }
26304
26582
  }
26305
- async function removeLeftoverManifest(location, layoutLock, steps, log9) {
26583
+ async function removeLeftoverManifest(location, layoutLock, steps, log10) {
26306
26584
  try {
26307
26585
  await removeManifestOwned(location.stateHomeDir, layoutLock, steps);
26308
26586
  } catch (error) {
26309
26587
  logOnce(
26310
26588
  `${location.key}\0manifest`,
26311
- () => log9.warn(
26589
+ () => log10.warn(
26312
26590
  `antigravity-auth could not remove ${RUNTIME_LAYOUT_MANIFEST_FILE} from its state folder; it tries again at the next start`,
26313
26591
  { stateDir: location.stateHomeDir, errorClass: errorClass(error) }
26314
26592
  )
@@ -26328,7 +26606,7 @@ async function removeOldVaultFolder(files, layoutLock, steps) {
26328
26606
  } catch {
26329
26607
  }
26330
26608
  }
26331
- async function removeOldSignatureCache(location, path2, layoutLock, steps, log9) {
26609
+ async function removeOldSignatureCache(location, path2, layoutLock, steps, log10) {
26332
26610
  try {
26333
26611
  if (!await exists2(path2)) return;
26334
26612
  await beforeRemove(path2, layoutLock, steps);
@@ -26337,7 +26615,7 @@ async function removeOldSignatureCache(location, path2, layoutLock, steps, log9)
26337
26615
  if (error?.code === "ENOENT") return;
26338
26616
  logOnce(
26339
26617
  `${location.key}\0signature-cache`,
26340
- () => log9.warn(
26618
+ () => log10.warn(
26341
26619
  "antigravity-auth could not remove its old signature cache from OpenCode's config folder; it is no longer used and can be deleted",
26342
26620
  { path: path2, errorClass: errorClass(error) }
26343
26621
  )
@@ -26348,7 +26626,7 @@ async function beforeRemove(path2, layoutLock, steps) {
26348
26626
  await steps?.beforeRemove?.(path2);
26349
26627
  await layoutLock.assertOwned();
26350
26628
  }
26351
- async function takeDataLocks(files, log9) {
26629
+ async function takeDataLocks(files, log10) {
26352
26630
  const locks = [];
26353
26631
  try {
26354
26632
  if (await exists2(files.vault.old))
@@ -26358,7 +26636,7 @@ async function takeDataLocks(files, log9) {
26358
26636
  lock.name,
26359
26637
  join14(files.vault.old, lock.file),
26360
26638
  lock.waitMs,
26361
- log9
26639
+ log10
26362
26640
  )
26363
26641
  );
26364
26642
  return locks;
@@ -26709,7 +26987,7 @@ async function ensureOwnerOnlyDir(path2) {
26709
26987
  await mkdir12(path2, { recursive: true, mode: 448 });
26710
26988
  await chmod4(path2, 448);
26711
26989
  }
26712
- async function takeLock(name, path2, waitMs, log9) {
26990
+ async function takeLock(name, path2, waitMs, log10) {
26713
26991
  const fs3 = await loadCommonAuthFs();
26714
26992
  const started = performance.now();
26715
26993
  let announced = false;
@@ -26734,7 +27012,7 @@ async function takeLock(name, path2, waitMs, log9) {
26734
27012
  );
26735
27013
  if (!announced && waited >= LOCK_WAIT_NOTICE_MS) {
26736
27014
  announced = true;
26737
- log9.info(
27015
+ log10.info(
26738
27016
  `antigravity-auth is waiting up to ${Math.round(waitMs / 1e3)} s for the ${name} lock at ${path2}.${lockHolderText(name)}`,
26739
27017
  { lock: name, path: path2 }
26740
27018
  );
@@ -27951,19 +28229,19 @@ function getLegacyLogger() {
27951
28229
  }
27952
28230
  function createLogger4(module) {
27953
28231
  let channel3;
27954
- const log9 = (level, message, extra) => {
28232
+ const log10 = (level, message, extra) => {
27955
28233
  channel3 ??= getLegacyLogger().createLogger(module);
27956
28234
  channel3[level](message, extra);
27957
28235
  };
27958
28236
  return {
27959
- debug: (message, extra) => log9("debug", message, extra),
27960
- info: (message, extra) => log9("info", message, extra),
28237
+ debug: (message, extra) => log10("debug", message, extra),
28238
+ info: (message, extra) => log10("info", message, extra),
27961
28239
  hostInfo: (message, extra) => {
27962
28240
  channel3 ??= getLegacyLogger().createLogger(module);
27963
28241
  channel3.hostInfo?.(message, extra);
27964
28242
  },
27965
- warn: (message, extra) => log9("warn", message, extra),
27966
- error: (message, extra) => log9("error", message, extra)
28243
+ warn: (message, extra) => log10("warn", message, extra),
28244
+ error: (message, extra) => log10("error", message, extra)
27967
28245
  };
27968
28246
  }
27969
28247
  var ENV_CONSOLE_LOG2, LOG_LEVEL_FROM_OPERATOR, legacyClient, legacyLogger;
@@ -28333,10 +28611,29 @@ async function checkAccountsQuotaStandalone(accounts, options) {
28333
28611
  }
28334
28612
  }));
28335
28613
  }
28336
- return checkAccountsQuotaWith(
28614
+ const refused2 = new AbortController();
28615
+ const admit2 = options.assertAdmission;
28616
+ const assertAdmission = admit2 && (async () => {
28617
+ refused2.signal.throwIfAborted();
28618
+ try {
28619
+ await admit2();
28620
+ } catch (error) {
28621
+ refused2.abort(error);
28622
+ throw error;
28623
+ }
28624
+ refused2.signal.throwIfAborted();
28625
+ });
28626
+ const results = await checkAccountsQuotaWith(
28337
28627
  accounts,
28338
- makeFetchAccountQuota(void 0, ANTIGRAVITY_PROVIDER_ID)
28628
+ makeFetchAccountQuota(
28629
+ void 0,
28630
+ ANTIGRAVITY_PROVIDER_ID,
28631
+ void 0,
28632
+ assertAdmission
28633
+ )
28339
28634
  );
28635
+ refused2.signal.throwIfAborted();
28636
+ return results;
28340
28637
  }
28341
28638
  async function fetchLegacyModelsFallback(options) {
28342
28639
  try {
@@ -28415,7 +28712,7 @@ function untilQuotaAborted(pending, signal) {
28415
28712
  );
28416
28713
  });
28417
28714
  }
28418
- function makeFetchAccountQuota(client, providerId, fetchVia) {
28715
+ function makeFetchAccountQuota(client, providerId, fetchVia, assertAdmission) {
28419
28716
  return async (account, signal, purpose = "required") => {
28420
28717
  const index = 0;
28421
28718
  const disabled = account.enabled === false;
@@ -28497,6 +28794,8 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
28497
28794
  }
28498
28795
  try {
28499
28796
  if (accessTokenExpired(auth)) {
28797
+ if (assertAdmission) await assertAdmission();
28798
+ signal.throwIfAborted();
28500
28799
  const refreshed = await refreshAccessToken(
28501
28800
  auth,
28502
28801
  client,
@@ -28510,7 +28809,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
28510
28809
  }
28511
28810
  auth = refreshed;
28512
28811
  }
28513
- const projectContext = await ensureProjectContext(auth);
28812
+ const projectContext = await ensureProjectContext(auth, assertAdmission);
28514
28813
  auth = projectContext.auth;
28515
28814
  const updatedAccount = applyAccountUpdates(
28516
28815
  account,
@@ -28525,11 +28824,20 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
28525
28824
  let fellBackToLegacy = false;
28526
28825
  const authParts = parseRefreshParts(auth.refresh);
28527
28826
  const managedProjectId = authParts.managedProjectId ?? account.managedProjectId;
28827
+ const guarded = assertAdmission ? async (url, init, extra) => {
28828
+ await assertAdmission();
28829
+ signal.throwIfAborted();
28830
+ return fetchWithActiveTimeout(
28831
+ url,
28832
+ { ...init, signal },
28833
+ { timeoutMs: extra.timeoutMs }
28834
+ );
28835
+ } : fetchVia;
28528
28836
  const payloads = await fetchQuotaPayloads({
28529
28837
  accessToken: auth.access ?? "",
28530
28838
  managedProjectId,
28531
28839
  projectId: projectContext.effectiveProjectId,
28532
- fetchVia,
28840
+ fetchVia: guarded,
28533
28841
  logger: log8
28534
28842
  });
28535
28843
  quotaResult = payloads.quota;
@@ -31540,9 +31848,11 @@ import { setTimeout as delay2 } from "node:timers/promises";
31540
31848
  import { writeEnrollmentTokenFile as writeEnrollmentTokenFile3 } from "@cortexkit/claustrum-client";
31541
31849
 
31542
31850
  // src/common-auth-embedded/setup/process-fence.js
31851
+ init_logger3();
31543
31852
  import { statSync as statSync6 } from "node:fs";
31544
31853
  import { win32 as win323 } from "node:path";
31545
31854
  var WINDOWS_CIM_TIMEOUT_MS = 45e3;
31855
+ var log9 = createLogger3("setup-process-fence");
31546
31856
  var WINDOWS_ARM_POWERSHELL_TIMEOUT_MS = 9e4;
31547
31857
  function isFile(file) {
31548
31858
  try {
@@ -31702,14 +32012,23 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
31702
32012
  options.onStep?.({ ...inspection });
31703
32013
  }
31704
32014
  };
31705
- const inspectCim = (args) => {
32015
+ const inspectCim = async (args) => {
31706
32016
  const pwsh = win323.resolve(windowsEnv(env3, "ProgramFiles") ?? "C:\\Program Files", "PowerShell", "7", "pwsh.exe");
31707
32017
  const program = (options.isFile ?? isFile)(pwsh) ? "pwsh" : "powershell";
31708
32018
  const arm64 = (windowsEnv(env3, "PROCESSOR_ARCHITEW6432") ?? windowsEnv(env3, "PROCESSOR_ARCHITECTURE"))?.toUpperCase() === "ARM64";
31709
32019
  const slow = program === "powershell" && arm64;
31710
32020
  if (slow)
31711
32021
  options.onProgress?.("Checking that OpenCode and Pi are not running. Without PowerShell 7 this can take up to a minute on Windows ARM; installing PowerShell 7 makes it fast.");
31712
- return inspect("CIM", program === "pwsh" ? pwsh : win323.resolve(system32, "WindowsPowerShell", "v1.0", "powershell.exe"), args, slow ? WINDOWS_ARM_POWERSHELL_TIMEOUT_MS : WINDOWS_CIM_TIMEOUT_MS, program);
32022
+ const file = program === "pwsh" ? pwsh : win323.resolve(system32, "WindowsPowerShell", "v1.0", "powershell.exe");
32023
+ const timeoutMs = slow ? WINDOWS_ARM_POWERSHELL_TIMEOUT_MS : WINDOWS_CIM_TIMEOUT_MS;
32024
+ const started = performance.now();
32025
+ const result = await inspect("CIM", file, args, timeoutMs, program);
32026
+ const remaining = Math.floor(timeoutMs - (performance.now() - started));
32027
+ if ((result.exitCode === 3221225477 || result.exitCode === -1073741819) && !result.timedOut && !result.signal && !result.spawnError && remaining > 0) {
32028
+ log9.warn("Windows process query crashed with an access violation; retrying once");
32029
+ return inspect("CIM", file, args, remaining, program);
32030
+ }
32031
+ return result;
31713
32032
  };
31714
32033
  try {
31715
32034
  if (windows && options.hostImagesOnly) {
@@ -32660,19 +32979,31 @@ async function readNativeAuth(path2) {
32660
32979
  throw error;
32661
32980
  }
32662
32981
  }
32982
+ async function readOpenCodeAuthority(legacyPath) {
32983
+ try {
32984
+ const claustrum = await loadCommonAuthClaustrum();
32985
+ if (claustrum.hasVaultHost()) return "host";
32986
+ return await vaultAuthority2(
32987
+ claustrum.hostEnrollmentPaths({
32988
+ stateDir: openCodeVaultDir(
32989
+ legacyPath ?? resolve23(accountFileForVault())
32990
+ ),
32991
+ host: "opencode"
32992
+ }),
32993
+ OPENCODE_VAULT_ENROLLMENT_NAME,
32994
+ claustrum
32995
+ );
32996
+ } catch {
32997
+ return "unreadable";
32998
+ }
32999
+ }
32663
33000
  async function assertLocalOpenCodeLogin(legacyPath, generation) {
32664
- const claustrum = await loadCommonAuthClaustrum();
32665
- if (await claustrum.vaultAuthority(
32666
- claustrum.hostEnrollmentPaths({
32667
- stateDir: openCodeVaultDir(legacyPath),
32668
- host: "opencode"
32669
- }),
32670
- OPENCODE_VAULT_ENROLLMENT_NAME
32671
- ) !== "local")
33001
+ if (await readOpenCodeAuthority(legacyPath) !== "local")
32672
33002
  throw new Error(
32673
33003
  "Vault enrollment excludes local sign-in. Resolve vault access before choosing local setup."
32674
33004
  );
32675
33005
  if (generation === "2") return;
33006
+ const claustrum = await loadCommonAuthClaustrum();
32676
33007
  claustrum.assertHostSlotMatchesMode({
32677
33008
  mode: "local",
32678
33009
  auth: (await readNativeAuth(nativeOpenCodeAuthPath()))[OPENCODE_VAULT_PROVIDER],
@@ -33288,6 +33619,16 @@ async function runCli(argv, deps) {
33288
33619
  return 0;
33289
33620
  }
33290
33621
  try {
33622
+ const assertLocalAccounts = async () => {
33623
+ const authority = await (deps.readAuthority ?? readOpenCodeAuthority)();
33624
+ if (authority === "local") return;
33625
+ const source2 = authority === "vault" ? "Accounts are served by the vault, not this computer's local sign-ins." : authority === "host" ? "Accounts are served by Thalamus, not this computer's local sign-ins." : "Account authority could not be read, so this computer's local sign-ins were not used.";
33626
+ throw new Error(
33627
+ `${source2} Use the /antigravity menu in OpenCode to see them and their quota.`
33628
+ );
33629
+ };
33630
+ if (parsed.value.command === "list" || parsed.value.command === "quota")
33631
+ await assertLocalAccounts();
33291
33632
  if (parsed.value.command !== "setup") {
33292
33633
  if (parsed.value.command === "login") await deps.prepareVaultFolder?.();
33293
33634
  await deps.processHeartbeat?.();
@@ -33392,7 +33733,8 @@ async function runCli(argv, deps) {
33392
33733
  return 0;
33393
33734
  }
33394
33735
  const results = await deps.getQuota(storage?.accounts ?? [], {
33395
- refresh: parsed.value.refresh
33736
+ refresh: parsed.value.refresh,
33737
+ ...parsed.value.refresh ? { assertAdmission: assertLocalAccounts } : {}
33396
33738
  });
33397
33739
  deps.stdout.write(
33398
33740
  parsed.value.json ? `${JSON.stringify(quotaSummary(results))}