@cortexkit/opencode-antigravity-auth 3.0.34 → 3.0.36

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 (107) hide show
  1. package/dist/cli.js +413 -182
  2. package/dist/cli.js.map +4 -4
  3. package/dist/cli.meta.json +196 -69
  4. package/dist/index.js +506 -245
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +217 -90
  7. package/dist/server.js +1185 -860
  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/accounts.js +9 -3
  11. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +5 -1
  12. package/dist/src/common-auth-embedded/claustrum/consumer.js +14 -5
  13. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +11 -8
  14. package/dist/src/common-auth-embedded/claustrum/custody.js +26 -15
  15. package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +2 -0
  16. package/dist/src/common-auth-embedded/claustrum/enrollment.js +7 -0
  17. package/dist/src/common-auth-embedded/claustrum/host.d.ts +8 -0
  18. package/dist/src/common-auth-embedded/claustrum/host.js +113 -0
  19. package/dist/src/common-auth-embedded/claustrum/hub.d.ts +5 -1
  20. package/dist/src/common-auth-embedded/claustrum/hub.js +5 -2
  21. package/dist/src/common-auth-embedded/claustrum/index.d.ts +2 -1
  22. package/dist/src/common-auth-embedded/claustrum/index.js +2 -1
  23. package/dist/src/common-auth-embedded/opencode2/install.js +42 -9
  24. package/dist/src/common-auth-embedded/opencode2/types.d.ts +3 -1
  25. package/dist/src/common-auth-embedded/setup/command.js +8 -4
  26. package/dist/src/common-auth-embedded/setup/enroll.js +3 -0
  27. package/dist/src/common-auth-embedded/source-output.json +68 -52
  28. package/dist/src/ga/rpc/protocol.d.ts +1 -0
  29. package/dist/src/ga/rpc/protocol.d.ts.map +1 -1
  30. package/dist/src/ga/rpc/protocol.js +4 -1
  31. package/dist/src/ga/rpc/protocol.js.map +1 -1
  32. package/dist/src/ga/server/auth.d.ts.map +1 -1
  33. package/dist/src/ga/server/auth.js +27 -4
  34. package/dist/src/ga/server/auth.js.map +1 -1
  35. package/dist/src/ga/server/index.d.ts.map +1 -1
  36. package/dist/src/ga/server/index.js +5 -1
  37. package/dist/src/ga/server/index.js.map +1 -1
  38. package/dist/src/ga/tui/host-ga.d.ts +22 -58
  39. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  40. package/dist/src/ga/tui/host-ga.js +161 -248
  41. package/dist/src/ga/tui/host-ga.js.map +1 -1
  42. package/dist/src/plugin/__fixtures__/verified-store.d.ts +1 -1
  43. package/dist/src/plugin/__fixtures__/verified-store.js +4 -4
  44. package/dist/src/plugin/auth-loader.js +1 -1
  45. package/dist/src/plugin/auth-loader.js.map +1 -1
  46. package/dist/src/plugin/background-vault-quota-refresh.js +1 -1
  47. package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
  48. package/dist/src/plugin/ga-location-services.d.ts +1 -0
  49. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  50. package/dist/src/plugin/ga-location-services.js +87 -51
  51. package/dist/src/plugin/ga-location-services.js.map +1 -1
  52. package/dist/src/plugin/index.d.ts.map +1 -1
  53. package/dist/src/plugin/index.js +2 -2
  54. package/dist/src/plugin/index.js.map +1 -1
  55. package/dist/src/plugin/shared/source-sidebar.js +1 -1
  56. package/dist/src/plugin/shared/source-sidebar.js.map +1 -1
  57. package/dist/src/plugin/vault-activation.d.ts.map +1 -1
  58. package/dist/src/plugin/vault-activation.js +10 -2
  59. package/dist/src/plugin/vault-activation.js.map +1 -1
  60. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  61. package/dist/src/plugin/vault-custody.js +25 -3
  62. package/dist/src/plugin/vault-custody.js.map +1 -1
  63. package/dist/src/runtime-layout.js +3 -3
  64. package/dist/src/runtime-layout.js.map +1 -1
  65. package/dist/src/setup.d.ts.map +1 -1
  66. package/dist/src/setup.js +8 -5
  67. package/dist/src/setup.js.map +1 -1
  68. package/dist/tui-build-map.json +1 -1
  69. package/dist/tui-ga-build-map.json +5 -5
  70. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +5 -1
  71. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +11 -8
  72. package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +2 -0
  73. package/dist/types/src/common-auth-embedded/claustrum/host.d.ts +8 -0
  74. package/dist/types/src/common-auth-embedded/claustrum/hub.d.ts +5 -1
  75. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +2 -1
  76. package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +3 -1
  77. package/dist/types/src/ga/rpc/protocol.d.ts +1 -0
  78. package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -1
  79. package/dist/types/src/ga/server/auth.d.ts.map +1 -1
  80. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  81. package/dist/types/src/plugin/ga-location-services.d.ts +1 -0
  82. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  83. package/dist/types/src/plugin/index.d.ts.map +1 -1
  84. package/dist/types/src/plugin/vault-activation.d.ts.map +1 -1
  85. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  86. package/dist/types/src/setup.d.ts.map +1 -1
  87. package/package.json +2 -2
  88. package/src/common-auth-embedded/auth-menu/accounts.js +9 -3
  89. package/src/common-auth-embedded/claustrum/consumer.d.ts +5 -1
  90. package/src/common-auth-embedded/claustrum/consumer.js +14 -5
  91. package/src/common-auth-embedded/claustrum/custody.d.ts +11 -8
  92. package/src/common-auth-embedded/claustrum/custody.js +26 -15
  93. package/src/common-auth-embedded/claustrum/enrollment.d.ts +2 -0
  94. package/src/common-auth-embedded/claustrum/enrollment.js +7 -0
  95. package/src/common-auth-embedded/claustrum/host.d.ts +8 -0
  96. package/src/common-auth-embedded/claustrum/host.js +113 -0
  97. package/src/common-auth-embedded/claustrum/hub.d.ts +5 -1
  98. package/src/common-auth-embedded/claustrum/hub.js +5 -2
  99. package/src/common-auth-embedded/claustrum/index.d.ts +2 -1
  100. package/src/common-auth-embedded/claustrum/index.js +2 -1
  101. package/src/common-auth-embedded/opencode2/install.js +42 -9
  102. package/src/common-auth-embedded/opencode2/types.d.ts +3 -1
  103. package/src/common-auth-embedded/setup/command.js +8 -4
  104. package/src/common-auth-embedded/setup/enroll.js +3 -0
  105. package/src/common-auth-embedded/source-output.json +68 -52
  106. package/src/tui-ga-compiled/host-ga.js +133 -241
  107. package/src/tui-ga-raw/host-ga.tsx +222 -315
package/dist/server.js CHANGED
@@ -16352,7 +16352,7 @@ var init_pull = __esm({
16352
16352
  const locks = new LockStack(ctx.lockDefaults, ctx.lockEnv);
16353
16353
  const progress = { writes: 0 };
16354
16354
  try {
16355
- const request = await withTransaction(ctx, locks, progress, { operation: "pull", rowId: id }, async (tx) => {
16355
+ const request2 = await withTransaction(ctx, locks, progress, { operation: "pull", rowId: id }, async (tx) => {
16356
16356
  if (tx.reservation(id) !== void 0)
16357
16357
  return void 0;
16358
16358
  await tx.completeTorn();
@@ -16377,14 +16377,14 @@ var init_pull = __esm({
16377
16377
  };
16378
16378
  }, { completeTorn: false });
16379
16379
  await locks.releaseAll();
16380
- if (!request) {
16380
+ if (!request2) {
16381
16381
  this.firedAtLoad.delete(id);
16382
16382
  return;
16383
16383
  }
16384
16384
  await ctx.hold?.("pull-before-request", id);
16385
16385
  let observation;
16386
16386
  try {
16387
- observation = await this.hook?.(request);
16387
+ observation = await this.hook?.(request2);
16388
16388
  } catch (cause) {
16389
16389
  throw new PoolOperationError({
16390
16390
  operation: "pull",
@@ -16398,8 +16398,8 @@ var init_pull = __esm({
16398
16398
  }
16399
16399
  const publish = rt.publishQuota ?? ((rowId2, attribution, value) => recordQuota(rt, rowId2, attribution, value));
16400
16400
  await publish(id, {
16401
- credentialEpoch: request.credentialEpoch,
16402
- ...request.identity !== void 0 ? { identity: request.identity } : {}
16401
+ credentialEpoch: request2.credentialEpoch,
16402
+ ...request2.identity !== void 0 ? { identity: request2.identity } : {}
16403
16403
  }, observation);
16404
16404
  } catch (error) {
16405
16405
  this.firedAtLoad.delete(id);
@@ -19039,12 +19039,12 @@ function coerceValues(knobs, raw) {
19039
19039
  }
19040
19040
  return { values };
19041
19041
  }
19042
- function findAction(sections, request) {
19043
- const section = sections.find((entry) => entry.id === request.sectionId);
19042
+ function findAction(sections, request2) {
19043
+ const section = sections.find((entry) => entry.id === request2.sectionId);
19044
19044
  if (!section)
19045
19045
  return void 0;
19046
- const actions = request.itemId === void 0 ? section.content.actions : section.content.items?.find((item) => item.id === request.itemId)?.actions;
19047
- return actions?.find((action) => action.id === request.actionId);
19046
+ const actions = request2.itemId === void 0 ? section.content.actions : section.content.items?.find((item) => item.id === request2.itemId)?.actions;
19047
+ return actions?.find((action) => action.id === request2.actionId);
19048
19048
  }
19049
19049
  function createCommandMenu(options) {
19050
19050
  const logger3 = options.logger ?? createLogger2("commands");
@@ -19124,10 +19124,10 @@ function createCommandMenu(options) {
19124
19124
  const own = ownInvocation(invocation, redact3);
19125
19125
  return dialogPayload(options.command, options.title, await sections(own), seam);
19126
19126
  },
19127
- async apply(request, invocation) {
19127
+ async apply(request2, invocation) {
19128
19128
  const own = ownInvocation(invocation, redact3);
19129
19129
  const finish = async (outcome2) => applyResult(options.command, options.title, await sections(own), outcome2, seam);
19130
- const action = request.command === options.command ? findAction(await sections(own), request) : void 0;
19130
+ const action = request2.command === options.command ? findAction(await sections(own), request2) : void 0;
19131
19131
  if (!action)
19132
19132
  return finish({
19133
19133
  ok: false,
@@ -19135,14 +19135,14 @@ function createCommandMenu(options) {
19135
19135
  text: "That action is no longer available."
19136
19136
  });
19137
19137
  const confirmation = confirmationOf(action);
19138
- if (confirmation && request.confirmed !== true)
19138
+ if (confirmation && request2.confirmed !== true)
19139
19139
  return finish({
19140
19140
  ok: false,
19141
19141
  code: "needs-confirmation",
19142
19142
  text: confirmation.message,
19143
19143
  needsConfirmation: true
19144
19144
  });
19145
- const coerced = coerceValues(action.knobs ?? [], request.values);
19145
+ const coerced = coerceValues(action.knobs ?? [], request2.values);
19146
19146
  if ("problem" in coerced)
19147
19147
  return finish({
19148
19148
  ok: false,
@@ -19153,7 +19153,7 @@ function createCommandMenu(options) {
19153
19153
  try {
19154
19154
  const result = await action.run({
19155
19155
  values: coerced.values,
19156
- ...request.itemId !== void 0 ? { itemId: request.itemId } : {},
19156
+ ...request2.itemId !== void 0 ? { itemId: request2.itemId } : {},
19157
19157
  invocation: own
19158
19158
  });
19159
19159
  outcome = typeof result === "string" ? { ok: true, text: result } : {
@@ -19165,8 +19165,8 @@ function createCommandMenu(options) {
19165
19165
  const failure2 = projectFailure(error);
19166
19166
  logger3.warn("command menu action failed", {
19167
19167
  command: options.command,
19168
- section: request.sectionId,
19169
- action: request.actionId,
19168
+ section: request2.sectionId,
19169
+ action: request2.actionId,
19170
19170
  code: failure2.code,
19171
19171
  error: redact3(error instanceof Error ? error.message : String(error))
19172
19172
  });
@@ -19452,6 +19452,219 @@ var init_commands = __esm({
19452
19452
  }
19453
19453
  });
19454
19454
 
19455
+ // ../core/dist/common-auth-embedded/claustrum/errors.js
19456
+ var ClaustrumConsumerError;
19457
+ var init_errors2 = __esm({
19458
+ "../core/dist/common-auth-embedded/claustrum/errors.js"() {
19459
+ "use strict";
19460
+ ClaustrumConsumerError = class extends Error {
19461
+ kind;
19462
+ constructor(kind, message) {
19463
+ super(message);
19464
+ this.name = "ClaustrumConsumerError";
19465
+ this.kind = kind;
19466
+ }
19467
+ };
19468
+ }
19469
+ });
19470
+
19471
+ // ../core/dist/common-auth-embedded/claustrum/availability.js
19472
+ import { ClaustrumCredentialError } from "@cortexkit/claustrum-client";
19473
+ import { SocketClosedError, SocketTimeoutError, SubcCallError } from "@cortexkit/subc-client";
19474
+ function classifyVaultFailure(error) {
19475
+ if (error instanceof ClaustrumUnreachableError || error instanceof SocketClosedError || error instanceof SocketTimeoutError)
19476
+ return "unreachable";
19477
+ const code2 = error instanceof ClaustrumCredentialError || error instanceof SubcCallError ? error.code : error instanceof Error && "code" in error ? error.code : void 0;
19478
+ if (typeof code2 !== "string" || !Object.hasOwn(VAULT_FAILURE_CLASSES, code2))
19479
+ return "answered";
19480
+ return VAULT_FAILURE_CLASSES[code2];
19481
+ }
19482
+ var VAULT_FAILURE_CLASSES, ClaustrumUnreachableError;
19483
+ var init_availability = __esm({
19484
+ "../core/dist/common-auth-embedded/claustrum/availability.js"() {
19485
+ "use strict";
19486
+ init_errors2();
19487
+ VAULT_FAILURE_CLASSES = Object.freeze({
19488
+ ECONNREFUSED: "unreachable",
19489
+ ENOENT: "unreachable",
19490
+ ECONNRESET: "unreachable",
19491
+ EPIPE: "unreachable",
19492
+ ETIMEDOUT: "unreachable",
19493
+ transport_error: "unreachable",
19494
+ unavailable: "unreachable",
19495
+ timeout: "unreachable",
19496
+ route_closed: "unreachable",
19497
+ daemon_draining: "unreachable",
19498
+ connection_closed: "unreachable",
19499
+ connection_dropped: "unreachable",
19500
+ request_deadline: "unreachable",
19501
+ deadline_exceeded_no_drop_observed: "unreachable",
19502
+ module_reloading: "unreachable",
19503
+ module_warming: "unreachable",
19504
+ target_unavailable: "unreachable",
19505
+ module_timeout: "unreachable",
19506
+ invalid_response: "answered",
19507
+ invalid_record_version: "answered",
19508
+ invalid_expiry: "answered",
19509
+ invalid_status: "answered",
19510
+ invalid_params: "answered",
19511
+ ttl_unsatisfiable: "answered",
19512
+ not_found: "answered",
19513
+ enrollment_revoked: "answered",
19514
+ enrollment_invalid: "answered",
19515
+ grant_denied: "answered",
19516
+ credential_unavailable: "answered",
19517
+ needs_reauth: "answered",
19518
+ declined: "answered",
19519
+ disabled: "answered",
19520
+ identity_changed: "answered",
19521
+ closed: "answered",
19522
+ client_closed: "answered",
19523
+ pending_exists: "answered",
19524
+ pending_queue_full: "answered",
19525
+ already_consumed: "answered",
19526
+ superseded: "answered",
19527
+ stale_generation: "answered",
19528
+ missing_identity: "answered",
19529
+ invalid_control_body: "answered",
19530
+ unknown_module: "answered",
19531
+ module_removed: "answered",
19532
+ capability_denied: "answered",
19533
+ unknown_channel: "unreachable",
19534
+ stale_route_epoch: "unreachable",
19535
+ capability_forbidden: "answered",
19536
+ capability_unprovided: "answered",
19537
+ capability_ambiguous: "answered",
19538
+ invalid_capability_identifier: "answered",
19539
+ binary_body_required: "answered",
19540
+ binary_call_requires_call_binary: "answered",
19541
+ corr_exhausted: "answered",
19542
+ late_route_cleanup_failed: "answered",
19543
+ reverse_request_capability_not_declared: "answered",
19544
+ stale_route_handle: "answered",
19545
+ reverse_request_unhandled: "answered",
19546
+ handler_error: "answered",
19547
+ health_error: "answered",
19548
+ duplicate_module_id: "answered",
19549
+ route_rejected: "answered",
19550
+ lock_busy: "answered",
19551
+ owner_invalid: "answered",
19552
+ renewal_failed: "answered",
19553
+ unsupported_platform: "answered",
19554
+ EACCES: "answered",
19555
+ EPERM: "answered",
19556
+ ERR_PRIVATE_FILES_SECURITY: "answered"
19557
+ });
19558
+ ClaustrumUnreachableError = class extends ClaustrumConsumerError {
19559
+ constructor() {
19560
+ super("unavailable", "Claustrum scoped operation unavailable");
19561
+ this.name = "ClaustrumUnreachableError";
19562
+ }
19563
+ };
19564
+ }
19565
+ });
19566
+
19567
+ // ../core/dist/common-auth-embedded/claustrum/host.js
19568
+ import { ClaustrumCredentialError as ClaustrumCredentialError2 } from "@cortexkit/claustrum-client";
19569
+ function isVaultHostClient(client) {
19570
+ return hostClients.has(client);
19571
+ }
19572
+ function hasVaultHost() {
19573
+ return process.env.CORTEXKIT_VAULT_HOST === "thalamus";
19574
+ }
19575
+ function hostError(error) {
19576
+ if (typeof error !== "object" || error === null)
19577
+ return error;
19578
+ const value = error;
19579
+ if (typeof value.code === "string" && (value.class === "transient" || value.class === "permanent" || value.class === "auth_required" || value.class === "context_overflow") && (value.action === "gone" || value.action === "reauth" || value.action === "retry" || value.action === "reduce_and_retry"))
19580
+ return new ClaustrumCredentialError2(value.code, value.class, value.action);
19581
+ if (value.name === "ClaustrumUnreachableError" || typeof value.code === "string" && classifyVaultFailure(Object.assign(new Error(), { code: value.code })) === "unreachable")
19582
+ return new ClaustrumUnreachableError();
19583
+ return error;
19584
+ }
19585
+ function call(operation) {
19586
+ try {
19587
+ return operation();
19588
+ } catch (error) {
19589
+ throw hostError(error);
19590
+ }
19591
+ }
19592
+ async function request(operation) {
19593
+ try {
19594
+ return await operation();
19595
+ } catch (error) {
19596
+ throw hostError(error);
19597
+ }
19598
+ }
19599
+ function wrapHostClient(client) {
19600
+ const watchScoped = client.watchScoped?.bind(client);
19601
+ const reportUsageScoped = client.reportUsageScoped?.bind(client);
19602
+ return {
19603
+ listScoped: (...args) => request(() => client.listScoped(...args)),
19604
+ getScoped: (...args) => request(() => client.getScoped(...args)),
19605
+ reportAuthFailureScoped: (...args) => request(() => client.reportAuthFailureScoped(...args)),
19606
+ close: () => call(() => client.close()),
19607
+ ...watchScoped && {
19608
+ watchScoped: (...args) => {
19609
+ const watch = call(() => watchScoped(...args));
19610
+ return {
19611
+ stop: () => call(() => watch.stop()),
19612
+ closed: request(async () => {
19613
+ const end = await watch.closed;
19614
+ return end.kind === "refused" || end.kind === "transport_lost" ? { ...end, error: hostError(end.error) } : end;
19615
+ })
19616
+ };
19617
+ }
19618
+ },
19619
+ ...reportUsageScoped && {
19620
+ reportUsageScoped: (...args) => request(() => reportUsageScoped(...args))
19621
+ },
19622
+ ...client.insula && {
19623
+ insula: wrapInsula(client.insula)
19624
+ }
19625
+ };
19626
+ }
19627
+ function wrapInsula(transport) {
19628
+ const watchUsage = transport.watchUsage?.bind(transport);
19629
+ return {
19630
+ connectionFile: transport.connectionFile,
19631
+ getUsage: () => request(() => transport.getUsage()),
19632
+ ...watchUsage && {
19633
+ watchUsage: (...args) => {
19634
+ const watch = call(() => watchUsage(...args));
19635
+ return {
19636
+ stop: () => call(() => watch.stop()),
19637
+ closed: request(() => watch.closed)
19638
+ };
19639
+ }
19640
+ }
19641
+ };
19642
+ }
19643
+ function connectVaultHost(pluginId) {
19644
+ if (!hasVaultHost() || !pluginId)
19645
+ throw new ClaustrumUnreachableError();
19646
+ try {
19647
+ const accessor = globalThis[/* @__PURE__ */ Symbol.for("cortexkit.vault")];
19648
+ if (typeof accessor !== "function")
19649
+ throw new ClaustrumUnreachableError();
19650
+ const client = wrapHostClient(accessor(pluginId));
19651
+ hostClients.add(client);
19652
+ return client;
19653
+ } catch {
19654
+ throw new ClaustrumUnreachableError();
19655
+ }
19656
+ }
19657
+ var VAULT_HOST_STATUS, VAULT_HOST_CONNECT_REFUSAL, hostClients;
19658
+ var init_host = __esm({
19659
+ "../core/dist/common-auth-embedded/claustrum/host.js"() {
19660
+ "use strict";
19661
+ init_availability();
19662
+ VAULT_HOST_STATUS = "Served by Thalamus";
19663
+ VAULT_HOST_CONNECT_REFUSAL = "This host gets its vault accounts from Thalamus, so it can't connect to the vault itself.";
19664
+ hostClients = /* @__PURE__ */ new WeakSet();
19665
+ }
19666
+ });
19667
+
19455
19668
  // ../core/dist/common-auth-embedded/auth-menu/doctor.js
19456
19669
  async function runDoctorChecks(checks) {
19457
19670
  const findings = [];
@@ -20222,7 +20435,7 @@ function deleteAllAction(options) {
20222
20435
  };
20223
20436
  }
20224
20437
  async function accountMenuActions(options) {
20225
- return actionsFor(options, await options.custody?.() === true);
20438
+ return actionsFor(options, hasVaultHost() || await options.custody?.() === true);
20226
20439
  }
20227
20440
  function actionsFor(options, custody) {
20228
20441
  const doctor = options.doctor?.length ? [doctorAction({ checks: options.doctor })] : [];
@@ -20247,7 +20460,8 @@ function actionsFor(options, custody) {
20247
20460
  ];
20248
20461
  }
20249
20462
  async function runAccountMenu(options) {
20250
- const custody = await options.custody?.() === true;
20463
+ const hosted = hasVaultHost();
20464
+ const custody = hosted || await options.custody?.() === true;
20251
20465
  const actions = actionsFor(options, custody);
20252
20466
  const [read, status] = await Promise.all([
20253
20467
  readRows(options.store),
@@ -20256,7 +20470,11 @@ async function runAccountMenu(options) {
20256
20470
  return runMenu({
20257
20471
  title: options.title,
20258
20472
  subtitle: custody ? "Accounts come from the vault; select an action" : "Select an account action",
20259
- status: [...status, ...accountLines(read)],
20473
+ status: [
20474
+ ...status,
20475
+ ...hosted ? [VAULT_HOST_STATUS] : [],
20476
+ ...accountLines(read)
20477
+ ],
20260
20478
  actions,
20261
20479
  ...options.terminal ? { terminal: options.terminal } : {}
20262
20480
  });
@@ -20265,6 +20483,7 @@ var MENU_DISABLE_REASON, STATUS_ACCOUNT_LINES;
20265
20483
  var init_accounts = __esm({
20266
20484
  "../core/dist/common-auth-embedded/auth-menu/accounts.js"() {
20267
20485
  "use strict";
20486
+ init_host();
20268
20487
  init_quota();
20269
20488
  init_store();
20270
20489
  init_doctor();
@@ -20356,118 +20575,6 @@ var init_auth_menu = __esm({
20356
20575
  }
20357
20576
  });
20358
20577
 
20359
- // ../core/dist/common-auth-embedded/claustrum/errors.js
20360
- var ClaustrumConsumerError;
20361
- var init_errors2 = __esm({
20362
- "../core/dist/common-auth-embedded/claustrum/errors.js"() {
20363
- "use strict";
20364
- ClaustrumConsumerError = class extends Error {
20365
- kind;
20366
- constructor(kind, message) {
20367
- super(message);
20368
- this.name = "ClaustrumConsumerError";
20369
- this.kind = kind;
20370
- }
20371
- };
20372
- }
20373
- });
20374
-
20375
- // ../core/dist/common-auth-embedded/claustrum/availability.js
20376
- import { ClaustrumCredentialError } from "@cortexkit/claustrum-client";
20377
- import { SocketClosedError, SocketTimeoutError, SubcCallError } from "@cortexkit/subc-client";
20378
- function classifyVaultFailure(error) {
20379
- if (error instanceof ClaustrumUnreachableError || error instanceof SocketClosedError || error instanceof SocketTimeoutError)
20380
- return "unreachable";
20381
- const code2 = error instanceof ClaustrumCredentialError || error instanceof SubcCallError ? error.code : error instanceof Error && "code" in error ? error.code : void 0;
20382
- if (typeof code2 !== "string" || !Object.hasOwn(VAULT_FAILURE_CLASSES, code2))
20383
- return "answered";
20384
- return VAULT_FAILURE_CLASSES[code2];
20385
- }
20386
- var VAULT_FAILURE_CLASSES, ClaustrumUnreachableError;
20387
- var init_availability = __esm({
20388
- "../core/dist/common-auth-embedded/claustrum/availability.js"() {
20389
- "use strict";
20390
- init_errors2();
20391
- VAULT_FAILURE_CLASSES = Object.freeze({
20392
- ECONNREFUSED: "unreachable",
20393
- ENOENT: "unreachable",
20394
- ECONNRESET: "unreachable",
20395
- EPIPE: "unreachable",
20396
- ETIMEDOUT: "unreachable",
20397
- transport_error: "unreachable",
20398
- unavailable: "unreachable",
20399
- timeout: "unreachable",
20400
- route_closed: "unreachable",
20401
- daemon_draining: "unreachable",
20402
- connection_closed: "unreachable",
20403
- connection_dropped: "unreachable",
20404
- request_deadline: "unreachable",
20405
- deadline_exceeded_no_drop_observed: "unreachable",
20406
- module_reloading: "unreachable",
20407
- module_warming: "unreachable",
20408
- target_unavailable: "unreachable",
20409
- module_timeout: "unreachable",
20410
- invalid_response: "answered",
20411
- invalid_record_version: "answered",
20412
- invalid_expiry: "answered",
20413
- invalid_status: "answered",
20414
- invalid_params: "answered",
20415
- ttl_unsatisfiable: "answered",
20416
- not_found: "answered",
20417
- enrollment_revoked: "answered",
20418
- enrollment_invalid: "answered",
20419
- grant_denied: "answered",
20420
- credential_unavailable: "answered",
20421
- needs_reauth: "answered",
20422
- declined: "answered",
20423
- disabled: "answered",
20424
- identity_changed: "answered",
20425
- closed: "answered",
20426
- client_closed: "answered",
20427
- pending_exists: "answered",
20428
- pending_queue_full: "answered",
20429
- already_consumed: "answered",
20430
- superseded: "answered",
20431
- stale_generation: "answered",
20432
- missing_identity: "answered",
20433
- invalid_control_body: "answered",
20434
- unknown_module: "answered",
20435
- module_removed: "answered",
20436
- capability_denied: "answered",
20437
- unknown_channel: "unreachable",
20438
- stale_route_epoch: "unreachable",
20439
- capability_forbidden: "answered",
20440
- capability_unprovided: "answered",
20441
- capability_ambiguous: "answered",
20442
- invalid_capability_identifier: "answered",
20443
- binary_body_required: "answered",
20444
- binary_call_requires_call_binary: "answered",
20445
- corr_exhausted: "answered",
20446
- late_route_cleanup_failed: "answered",
20447
- reverse_request_capability_not_declared: "answered",
20448
- stale_route_handle: "answered",
20449
- reverse_request_unhandled: "answered",
20450
- handler_error: "answered",
20451
- health_error: "answered",
20452
- duplicate_module_id: "answered",
20453
- route_rejected: "answered",
20454
- lock_busy: "answered",
20455
- owner_invalid: "answered",
20456
- renewal_failed: "answered",
20457
- unsupported_platform: "answered",
20458
- EACCES: "answered",
20459
- EPERM: "answered",
20460
- ERR_PRIVATE_FILES_SECURITY: "answered"
20461
- });
20462
- ClaustrumUnreachableError = class extends ClaustrumConsumerError {
20463
- constructor() {
20464
- super("unavailable", "Claustrum scoped operation unavailable");
20465
- this.name = "ClaustrumUnreachableError";
20466
- }
20467
- };
20468
- }
20469
- });
20470
-
20471
20578
  // ../core/dist/common-auth-embedded/claustrum/watch.js
20472
20579
  var SAFETY_POLL_MS, WATCH_RETRY_MS, RESUBSCRIBE_BACKOFF_MS, ChangeNoticeReader, CoalescedRead, ScopedRosterWatch;
20473
20580
  var init_watch = __esm({
@@ -20692,7 +20799,7 @@ function insulaUsageTransport(options) {
20692
20799
  timer = setTimeout(() => reject(new Error("insula usage timeout")), 3e3);
20693
20800
  timer.unref?.();
20694
20801
  });
20695
- const request = (async () => {
20802
+ const request2 = (async () => {
20696
20803
  client = options.connector ? await options.connector({
20697
20804
  connectionFile: options.connectionFile,
20698
20805
  handshakeTimeoutMs: Math.min(options.handshakeTimeoutMs ?? 3e3, 3e3)
@@ -20708,7 +20815,7 @@ function insulaUsageTransport(options) {
20708
20815
  return await client.request(route, { method: "usage.get", params: {} });
20709
20816
  })();
20710
20817
  try {
20711
- return await Promise.race([request, timeout]);
20818
+ return await Promise.race([request2, timeout]);
20712
20819
  } finally {
20713
20820
  expired = true;
20714
20821
  clearTimeout(timer);
@@ -21121,9 +21228,9 @@ import { createHash as createHash6, randomBytes as randomBytes4, randomUUID as r
21121
21228
  import { constants as fsConstants } from "node:fs";
21122
21229
  import { chmod as chmod2, mkdir as mkdir8, open as open6, readFile as readFile6, realpath as realpath3, rename as rename7, stat as stat5, unlink as unlink6 } from "node:fs/promises";
21123
21230
  import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join7, resolve as resolve7 } from "node:path";
21124
- import { ClaustrumCredentialError as ClaustrumCredentialError2, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
21231
+ import { ClaustrumCredentialError as ClaustrumCredentialError3, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
21125
21232
  function classifyEnrollmentError(error) {
21126
- if (!(error instanceof ClaustrumCredentialError2))
21233
+ if (!(error instanceof ClaustrumCredentialError3))
21127
21234
  return void 0;
21128
21235
  if (TERMINAL_ENROLLMENT_CODES.has(error.code))
21129
21236
  return { code: error.code, disposition: "terminal" };
@@ -21476,6 +21583,11 @@ async function enrollmentAuthority(paths, proposedName) {
21476
21583
  }
21477
21584
  return "local";
21478
21585
  }
21586
+ async function vaultAuthority(paths, proposedName) {
21587
+ if (hasVaultHost())
21588
+ return "host";
21589
+ return enrollmentAuthority(paths, proposedName);
21590
+ }
21479
21591
  async function readClaustrumEnrollmentToken(tokenPath) {
21480
21592
  const value = await readBoundedJson(tokenPath);
21481
21593
  if (value === void 0)
@@ -21589,6 +21701,7 @@ var init_enrollment = __esm({
21589
21701
  init_fs();
21590
21702
  init_private_files();
21591
21703
  init_errors2();
21704
+ init_host();
21592
21705
  ENROLLMENT_SCHEMA = 1;
21593
21706
  ENROLLMENT_FILE_MAX_BYTES = 16 * 1024;
21594
21707
  ENROLLMENT_LOCK_TTL_MS = 3e4;
@@ -21904,7 +22017,7 @@ var init_shutdown = __esm({
21904
22017
  });
21905
22018
 
21906
22019
  // ../core/dist/common-auth-embedded/claustrum/usage.js
21907
- import { ClaustrumCredentialError as ClaustrumCredentialError3 } from "@cortexkit/claustrum-client";
22020
+ import { ClaustrumCredentialError as ClaustrumCredentialError4 } from "@cortexkit/claustrum-client";
21908
22021
  function plain(value) {
21909
22022
  return value !== null && typeof value === "object" && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
21910
22023
  }
@@ -22010,7 +22123,7 @@ var init_usage = __esm({
22010
22123
  #log(error) {
22011
22124
  let code2 = "transport_error";
22012
22125
  try {
22013
- if (error instanceof ClaustrumCredentialError3)
22126
+ if (error instanceof ClaustrumCredentialError4)
22014
22127
  code2 = /^[a-z][a-z0-9_]{0,63}$/.test(error.code) ? error.code : code2;
22015
22128
  if (this.#errors.has(code2))
22016
22129
  return;
@@ -22040,7 +22153,7 @@ var init_usage = __esm({
22040
22153
 
22041
22154
  // ../core/dist/common-auth-embedded/claustrum/custody.js
22042
22155
  import { channel } from "node:diagnostics_channel";
22043
- import { ClaustrumCredentialError as ClaustrumCredentialError4 } from "@cortexkit/claustrum-client";
22156
+ import { ClaustrumCredentialError as ClaustrumCredentialError5 } from "@cortexkit/claustrum-client";
22044
22157
  function isScopedCredentialRotation(served, current) {
22045
22158
  return current !== void 0 && !current.fromKeptReceipt && !served.fromKeptReceipt && current.credentialId === served.credentialId && current.accountIdentity === served.accountIdentity && current.recordVersion !== served.recordVersion;
22046
22159
  }
@@ -22167,6 +22280,7 @@ var init_custody = __esm({
22167
22280
  init_availability();
22168
22281
  init_enrollment();
22169
22282
  init_errors2();
22283
+ init_host();
22170
22284
  init_host_slot();
22171
22285
  init_shutdown();
22172
22286
  init_usage();
@@ -22206,15 +22320,21 @@ var init_custody = __esm({
22206
22320
  #onDrainTimeout;
22207
22321
  #disposing;
22208
22322
  constructor(options) {
22323
+ if (hasVaultHost() && options.client && !isVaultHostClient(options.client))
22324
+ throw new ClaustrumUnreachableError();
22209
22325
  const tokenPath = options.tokenPath;
22210
22326
  if (options.readToken) {
22211
22327
  this.#readToken = options.readToken;
22212
22328
  } else if (tokenPath) {
22213
22329
  this.#readToken = () => readClaustrumEnrollmentToken(tokenPath);
22330
+ } else if (hasVaultHost()) {
22331
+ this.#readToken = async () => {
22332
+ throw new ClaustrumConsumerError("not-enrolled", "Claustrum enrollment token path is required");
22333
+ };
22214
22334
  } else {
22215
22335
  throw new ClaustrumConsumerError("not-enrolled", "Claustrum enrollment token path is required");
22216
22336
  }
22217
- this.#client = options.client;
22337
+ this.#client = options.client ?? connectVaultHost(options.pluginId);
22218
22338
  this.#family = options.family;
22219
22339
  this.#parseIdentity = options.parseIdentity;
22220
22340
  this.#requireAssertion = options.requireAssertion ?? false;
@@ -22226,7 +22346,7 @@ var init_custody = __esm({
22226
22346
  this.#usage = new ScopedUsageReporter({
22227
22347
  client: this.#client,
22228
22348
  owns: (id) => this.#usageServed.has(id),
22229
- token: async () => checkedEnrollmentToken(await this.#readToken()),
22349
+ token: async () => hasVaultHost() ? "" : checkedEnrollmentToken(await this.#readToken()),
22230
22350
  logger: this.#logger,
22231
22351
  setTimeout: this.#setTimeout,
22232
22352
  clearTimeout: this.#clearTimeout
@@ -22237,7 +22357,7 @@ var init_custody = __esm({
22237
22357
  if (this.#closed || this.#outage)
22238
22358
  return;
22239
22359
  this.#outage = true;
22240
- this.#outageError = error instanceof ClaustrumCredentialError4 ? error : new ClaustrumUnreachableError();
22360
+ this.#outageError = error instanceof ClaustrumCredentialError5 ? error : new ClaustrumUnreachableError();
22241
22361
  this.#logger.warn("serving kept vault receipt", { reason: "unreachable" });
22242
22362
  this.#scheduleProbe();
22243
22363
  }
@@ -22287,6 +22407,8 @@ var init_custody = __esm({
22287
22407
  }
22288
22408
  async #token(signal) {
22289
22409
  this.#check(signal);
22410
+ if (hasVaultHost())
22411
+ return "";
22290
22412
  if (phaseDiagnostics.hasSubscribers)
22291
22413
  phaseDiagnostics.publish({
22292
22414
  logger: this.#logger,
@@ -22330,7 +22452,7 @@ var init_custody = __esm({
22330
22452
  this.transportLost(error);
22331
22453
  else
22332
22454
  this.reachable();
22333
- if (error instanceof ClaustrumCredentialError4)
22455
+ if (error instanceof ClaustrumCredentialError5)
22334
22456
  throw error;
22335
22457
  if (classifyVaultFailure(error) === "unreachable")
22336
22458
  throw new ClaustrumUnreachableError();
@@ -22549,7 +22671,7 @@ var init_custody = __esm({
22549
22671
  if (kept.since === null)
22550
22672
  kept.since = this.#now();
22551
22673
  const attempt = Object.freeze(Object.defineProperty({ ...kept.attempt, fromKeptReceipt: true }, "accessToken", { value: kept.attempt.accessToken, enumerable: false }));
22552
- this.#provenance.set(attempt, token);
22674
+ this.#provenance.set(attempt, this.#provenance.get(kept.attempt) ?? { token, client: this.#client });
22553
22675
  this.#keptAttempts.set(attempt, routeId);
22554
22676
  return attempt;
22555
22677
  }
@@ -22610,22 +22732,22 @@ var init_custody = __esm({
22610
22732
  recordVersion: served.recordVersion,
22611
22733
  expiresAtMs
22612
22734
  }, "accessToken", { value: accessToken, enumerable: false }));
22613
- this.#provenance.set(attempt, token);
22735
+ this.#provenance.set(attempt, { token, client: this.#client });
22614
22736
  return attempt;
22615
22737
  }
22616
22738
  /**
22617
22739
  * Report that a send this consumer actually made was rejected. Only a 401
22618
22740
  * is reported (the vault refuses 429, 402 and 5xx reports), addressed by
22619
22741
  * credential id with the exact record version that send was served, and
22620
- * signed with the enrollment token that authorized it. A receipt this
22621
- * custody did not issue is refused rather than reported.
22742
+ * sent through the client and enrollment token that authorized it. A receipt
22743
+ * this custody did not issue is refused rather than reported.
22622
22744
  */
22623
22745
  async reportFailure(attempt, status, reporterSource) {
22624
22746
  if (status !== 401)
22625
22747
  return;
22626
22748
  this.#check();
22627
- const token = this.#provenance.get(attempt);
22628
- if (!token)
22749
+ const provenance = this.#provenance.get(attempt);
22750
+ if (!provenance)
22629
22751
  throw new ClaustrumConsumerError("no-receipt", "Claustrum failure report requires an original dispatch receipt");
22630
22752
  const keptRoute = this.#keptAttempts.get(attempt);
22631
22753
  if (keptRoute !== void 0) {
@@ -22642,9 +22764,9 @@ var init_custody = __esm({
22642
22764
  const pending = this.#reports.get(attempt);
22643
22765
  if (pending)
22644
22766
  return pending;
22645
- const report = this.#call(() => this.#client.reportAuthFailureScoped({
22767
+ const report = this.#call(() => provenance.client.reportAuthFailureScoped({
22646
22768
  credentialId: attempt.credentialId,
22647
- enrollmentToken: token,
22769
+ enrollmentToken: provenance.token,
22648
22770
  providerStatus: 401,
22649
22771
  recordVersion: attempt.recordVersion,
22650
22772
  reporterSource
@@ -23664,6 +23786,7 @@ var init_consumer = __esm({
23664
23786
  init_custody();
23665
23787
  init_enrollment();
23666
23788
  init_errors2();
23789
+ init_host();
23667
23790
  init_insula();
23668
23791
  init_quota_writer2();
23669
23792
  init_roster();
@@ -23726,6 +23849,8 @@ var init_consumer = __esm({
23726
23849
  return pending;
23727
23850
  }
23728
23851
  async #active() {
23852
+ if (hasVaultHost())
23853
+ return true;
23729
23854
  return await this.#options.isCustodyActive?.() ?? true;
23730
23855
  }
23731
23856
  #wait(pending, signal) {
@@ -23776,7 +23901,7 @@ var init_consumer = __esm({
23776
23901
  #boundedConnect(attempt) {
23777
23902
  const setTimer = this.#options.setTimeoutImpl ?? setTimeout;
23778
23903
  const clearTimer = this.#options.clearTimeoutImpl ?? clearTimeout;
23779
- const pending = this.#options.connect().then((client) => {
23904
+ const pending = (!hasVaultHost() && this.#options.connect ? this.#options.connect() : Promise.resolve().then(() => connectVaultHost(this.#options.pluginId))).then((client) => {
23780
23905
  if (this.#shutdown.signal.aborted || attempt.timedOut) {
23781
23906
  client.close();
23782
23907
  if (!attempt.timedOut)
@@ -24029,7 +24154,8 @@ var init_consumer = __esm({
24029
24154
  if (!this.#options.insula || this.#shutdown.signal.aborted || !await this.#active())
24030
24155
  return;
24031
24156
  try {
24032
- await readClaustrumEnrollmentToken(this.#options.tokenPath);
24157
+ if (!hasVaultHost())
24158
+ await readClaustrumEnrollmentToken(this.#options.tokenPath);
24033
24159
  await this.#getCustody();
24034
24160
  await this.#insula?.source.refresh((this.#options.now ?? Date.now)());
24035
24161
  } catch {
@@ -24045,7 +24171,8 @@ var init_consumer = __esm({
24045
24171
  if (!this.#options.insula || this.#shutdown.signal.aborted || !await this.#active())
24046
24172
  return void 0;
24047
24173
  try {
24048
- await readClaustrumEnrollmentToken(this.#options.tokenPath);
24174
+ if (!hasVaultHost())
24175
+ await readClaustrumEnrollmentToken(this.#options.tokenPath);
24049
24176
  return this.#normalizeInsulaQuota(receipt2.assertedAccountIdentity);
24050
24177
  } catch {
24051
24178
  return void 0;
@@ -24060,7 +24187,8 @@ var init_consumer = __esm({
24060
24187
  if (!this.#options.insula || this.#shutdown.signal.aborted || !await this.#active())
24061
24188
  return void 0;
24062
24189
  try {
24063
- await readClaustrumEnrollmentToken(this.#options.tokenPath);
24190
+ if (!hasVaultHost())
24191
+ await readClaustrumEnrollmentToken(this.#options.tokenPath);
24064
24192
  const roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
24065
24193
  const row = roster?.rows.find((entry) => entry.routeId === routeId);
24066
24194
  return this.#normalizeInsulaQuota(row?.accountIdentity);
@@ -24074,7 +24202,8 @@ var init_consumer = __esm({
24074
24202
  if (!options || this.#shutdown.signal.aborted || !await this.#active())
24075
24203
  return { miss: "unreachable" };
24076
24204
  try {
24077
- await readClaustrumEnrollmentToken(this.#options.tokenPath);
24205
+ if (!hasVaultHost())
24206
+ await readClaustrumEnrollmentToken(this.#options.tokenPath);
24078
24207
  const roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
24079
24208
  const account = roster?.rows.find((row) => row.routeId === routeId)?.accountIdentity;
24080
24209
  if (!account || !this.#insula)
@@ -24578,6 +24707,7 @@ var init_hub = __esm({
24578
24707
  init_custody();
24579
24708
  init_enrollment();
24580
24709
  init_errors2();
24710
+ init_host();
24581
24711
  init_roster();
24582
24712
  init_shutdown();
24583
24713
  init_watch();
@@ -24807,7 +24937,7 @@ var init_hub = __esm({
24807
24937
  const entry = { generation, timedOut: false };
24808
24938
  const connectTimeoutMs = this.#options.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
24809
24939
  let timer;
24810
- const connect3 = this.#options.connect().then((client) => {
24940
+ const connect3 = (!hasVaultHost() && this.#options.connect ? this.#options.connect() : Promise.resolve().then(() => connectVaultHost(this.#options.pluginId))).then((client) => {
24811
24941
  if (entry.timedOut) {
24812
24942
  client.close();
24813
24943
  throw unreachableConnect2();
@@ -24982,7 +25112,7 @@ var init_hub = __esm({
24982
25112
  * runs the inactive transition; nothing else does.
24983
25113
  */
24984
25114
  async #readAuthority() {
24985
- const active2 = await this.#options.isCustodyActive?.() ?? true;
25115
+ const active2 = hasVaultHost() || (await this.#options.isCustodyActive?.() ?? true);
24986
25116
  if (this.#shutdown.signal.aborted)
24987
25117
  return false;
24988
25118
  const was = this.#active;
@@ -25489,7 +25619,7 @@ __export(claustrum_exports, {
25489
25619
  ChangeNoticeReader: () => ChangeNoticeReader,
25490
25620
  ClaustrumConsumer: () => ClaustrumConsumer,
25491
25621
  ClaustrumConsumerError: () => ClaustrumConsumerError,
25492
- ClaustrumCredentialError: () => ClaustrumCredentialError5,
25622
+ ClaustrumCredentialError: () => ClaustrumCredentialError6,
25493
25623
  ClaustrumDiscoveryHub: () => ClaustrumDiscoveryHub,
25494
25624
  ClaustrumEnrollmentManager: () => ClaustrumEnrollmentManager,
25495
25625
  ClaustrumScopedCustody: () => ClaustrumScopedCustody,
@@ -25505,6 +25635,8 @@ __export(claustrum_exports, {
25505
25635
  ScopedRosterWatch: () => ScopedRosterWatch,
25506
25636
  TERMINAL_ENROLLMENT_CODES: () => TERMINAL_ENROLLMENT_CODES,
25507
25637
  VAULT_FAILURE_CLASSES: () => VAULT_FAILURE_CLASSES,
25638
+ VAULT_HOST_CONNECT_REFUSAL: () => VAULT_HOST_CONNECT_REFUSAL,
25639
+ VAULT_HOST_STATUS: () => VAULT_HOST_STATUS,
25508
25640
  WATCH_RETRY_MS: () => WATCH_RETRY_MS,
25509
25641
  acceptAccount: () => acceptAccount,
25510
25642
  acceptVaultRoute: () => acceptVaultRoute,
@@ -25516,6 +25648,7 @@ __export(claustrum_exports, {
25516
25648
  classifyVaultFailure: () => classifyVaultFailure,
25517
25649
  connectClaustrumEnrollmentClient: () => connectClaustrumEnrollmentClient,
25518
25650
  connectClaustrumScopedClient: () => connectClaustrumScopedClient,
25651
+ connectVaultHost: () => connectVaultHost,
25519
25652
  custodyPlaceholder: () => custodyPlaceholder,
25520
25653
  custodyPlaceholderKey: () => custodyPlaceholderKey,
25521
25654
  decideScopedRetryAfter401: () => decideScopedRetryAfter401,
@@ -25542,11 +25675,12 @@ __export(claustrum_exports, {
25542
25675
  reorderVaultRoster: () => reorderVaultRoster,
25543
25676
  resetClaustrumEnrollmentState: () => resetClaustrumEnrollmentState,
25544
25677
  resolveVaultPrimary: () => resolveVaultPrimary,
25678
+ vaultAuthority: () => vaultAuthority,
25545
25679
  vaultRosterSeed: () => vaultRosterSeed,
25546
25680
  vaultRoutingRows: () => vaultRoutingRows
25547
25681
  });
25548
25682
  import { ClaustrumClient } from "@cortexkit/claustrum-client";
25549
- import { ClaustrumCredentialError as ClaustrumCredentialError5 } from "@cortexkit/claustrum-client";
25683
+ import { ClaustrumCredentialError as ClaustrumCredentialError6 } from "@cortexkit/claustrum-client";
25550
25684
  async function connectClaustrumScopedClient(options) {
25551
25685
  const { connectTimeoutMs, ...client } = options;
25552
25686
  const limit = connectTimeoutMs ?? SCOPED_CONNECT_TIMEOUT_MS;
@@ -25583,6 +25717,7 @@ var init_claustrum = __esm({
25583
25717
  init_custody();
25584
25718
  init_enrollment();
25585
25719
  init_errors2();
25720
+ init_host();
25586
25721
  init_host_slot();
25587
25722
  init_hub();
25588
25723
  init_insula();
@@ -29008,6 +29143,7 @@ function admissionFromReceipt(ref, receipt2) {
29008
29143
  function createAntigravityVaultAccountSource(options) {
29009
29144
  const { claustrum } = options;
29010
29145
  const consumer = new claustrum.ClaustrumConsumer({
29146
+ pluginId: "antigravity-auth",
29011
29147
  rosterPath: options.rosterPath,
29012
29148
  tokenPath: options.tokenPath,
29013
29149
  family: { ...ANTIGRAVITY_VAULT_FAMILY },
@@ -29245,9 +29381,9 @@ var init_vault_account_source = __esm({
29245
29381
  });
29246
29382
 
29247
29383
  // ../core/dist/vault-enrollment-authority.js
29248
- async function enrollmentAuthority2(paths, proposedName, reader) {
29384
+ async function vaultAuthority2(paths, proposedName, reader) {
29249
29385
  try {
29250
- return await (reader ?? await loadCommonAuthClaustrum()).enrollmentAuthority(paths, proposedName);
29386
+ return await (reader ?? await loadCommonAuthClaustrum()).vaultAuthority(paths, proposedName);
29251
29387
  } catch {
29252
29388
  return "unreadable";
29253
29389
  }
@@ -29790,7 +29926,7 @@ var init_redact2 = __esm({
29790
29926
  });
29791
29927
 
29792
29928
  // src/common-auth-embedded/logger/engine.js
29793
- import { appendFileSync as appendFileSync2, chmodSync as chmodSync2, existsSync as existsSync2, renameSync as renameSync2, statSync as statSync3 } from "node:fs";
29929
+ import { appendFileSync as appendFileSync2, chmodSync as chmodSync2, existsSync as existsSync3, renameSync as renameSync2, statSync as statSync3 } from "node:fs";
29794
29930
  import { open as open8 } from "node:fs/promises";
29795
29931
  import { dirname as dirname14, resolve as resolve13 } from "node:path";
29796
29932
  function chmodPrivate2(path5) {
@@ -29801,10 +29937,10 @@ function chmodPrivate2(path5) {
29801
29937
  }
29802
29938
  function rotateIfNeeded2(f) {
29803
29939
  try {
29804
- if (!(existsSync2(f) && statSync3(f).size >= MAX_BYTES2))
29940
+ if (!(existsSync3(f) && statSync3(f).size >= MAX_BYTES2))
29805
29941
  return;
29806
29942
  for (let i = ROTATE_KEEP2 - 1; i >= 1; i--) {
29807
- if (existsSync2(`${f}.${i}`)) {
29943
+ if (existsSync3(`${f}.${i}`)) {
29808
29944
  const rotated2 = `${f}.${i + 1}`;
29809
29945
  renameSync2(`${f}.${i}`, rotated2);
29810
29946
  chmodPrivate2(rotated2);
@@ -29974,7 +30110,7 @@ function createEngine2(options) {
29974
30110
  }
29975
30111
  try {
29976
30112
  rotateIfNeeded2(file);
29977
- if (existsSync2(file))
30113
+ if (existsSync3(file))
29978
30114
  chmodPrivate2(file);
29979
30115
  appendFileSync2(file, text2, { encoding: "utf8", mode: 384 });
29980
30116
  } catch {
@@ -30737,6 +30873,12 @@ function createOpenCodeVaultCustody(options) {
30737
30873
  const readEnrollment = async () => {
30738
30874
  if (layoutRefusal !== void 0) return unsettled;
30739
30875
  const claustrum = await loadClaustrum();
30876
+ if (process.env.CORTEXKIT_VAULT_HOST === "thalamus")
30877
+ return {
30878
+ state: "unavailable",
30879
+ code: "host",
30880
+ proposedName: OPENCODE_VAULT_ENROLLMENT_NAME
30881
+ };
30740
30882
  const status = await claustrum.readClaustrumEnrollmentStatus(
30741
30883
  await enrollmentPaths(),
30742
30884
  OPENCODE_VAULT_ENROLLMENT_NAME
@@ -30759,6 +30901,8 @@ function createOpenCodeVaultCustody(options) {
30759
30901
  const readEnrollmentSnapshot = async () => {
30760
30902
  if (layoutRefusal !== void 0)
30761
30903
  return { authority: "unreadable", status: unsettled };
30904
+ if (process.env.CORTEXKIT_VAULT_HOST === "thalamus")
30905
+ return { authority: "host", status: await readEnrollment() };
30762
30906
  const enrollment = await enrollmentPaths();
30763
30907
  const identity3 = await enrollmentFilesIdentity(enrollment);
30764
30908
  if (identity3) {
@@ -30769,7 +30913,7 @@ function createOpenCodeVaultCustody(options) {
30769
30913
  return enrollmentReading.promise;
30770
30914
  }
30771
30915
  const promise = (async () => {
30772
- const authority = await enrollmentAuthority2(
30916
+ const authority = await vaultAuthority2(
30773
30917
  enrollment,
30774
30918
  OPENCODE_VAULT_ENROLLMENT_NAME,
30775
30919
  await loadClaustrum()
@@ -30841,6 +30985,7 @@ function createOpenCodeVaultCustody(options) {
30841
30985
  observedAuthority = authority;
30842
30986
  options.onAuthorityChanged?.(authority);
30843
30987
  }
30988
+ if (authority === "host") return true;
30844
30989
  if (authority !== "vault") return false;
30845
30990
  return status.state === "approved";
30846
30991
  },
@@ -30976,7 +31121,7 @@ function createOpenCodeVaultCustody(options) {
30976
31121
  return { ok: false, reason: VAULT_ACCOUNT_REMEDY };
30977
31122
  return {
30978
31123
  ok: true,
30979
- record: authority === "vault" ? CUSTODY_MODE : LOCAL_MODE
31124
+ record: authority === "vault" || authority === "host" ? CUSTODY_MODE : LOCAL_MODE
30980
31125
  };
30981
31126
  },
30982
31127
  async custodySource() {
@@ -31002,10 +31147,16 @@ function createOpenCodeVaultCustody(options) {
31002
31147
  };
31003
31148
  },
31004
31149
  async requestAccess() {
31150
+ const claustrum = await loadClaustrum();
31151
+ if (process.env.CORTEXKIT_VAULT_HOST === "thalamus")
31152
+ throw new OpenCodeVaultCustodyError(
31153
+ claustrum.VAULT_HOST_CONNECT_REFUSAL
31154
+ );
31005
31155
  return connectStep(true);
31006
31156
  },
31007
31157
  async useVault() {
31008
31158
  refuseUnsettled();
31159
+ if (process.env.CORTEXKIT_VAULT_HOST === "thalamus") return;
31009
31160
  const enrollment = await readEnrollment();
31010
31161
  if (enrollment.state !== "approved")
31011
31162
  throw new OpenCodeVaultCustodyError(
@@ -31017,6 +31168,10 @@ function createOpenCodeVaultCustody(options) {
31017
31168
  async useLocal() {
31018
31169
  refuseUnsettled();
31019
31170
  const claustrum = await loadClaustrum();
31171
+ if (process.env.CORTEXKIT_VAULT_HOST === "thalamus")
31172
+ throw new OpenCodeVaultCustodyError(
31173
+ claustrum.VAULT_HOST_CONNECT_REFUSAL
31174
+ );
31020
31175
  const disconnected = await claustrum.disconnectClaustrumEnrollment(
31021
31176
  await enrollmentPaths(),
31022
31177
  OPENCODE_VAULT_ENROLLMENT_NAME
@@ -31047,6 +31202,9 @@ function createOpenCodeVaultCustody(options) {
31047
31202
  build: async () => {
31048
31203
  if (layoutRefusal !== void 0)
31049
31204
  return { lines: [`Vault: ${layoutRefusal}`], actions: [] };
31205
+ const claustrum = await loadClaustrum();
31206
+ if (process.env.CORTEXKIT_VAULT_HOST === "thalamus")
31207
+ return { lines: [claustrum.VAULT_HOST_STATUS], actions: [] };
31050
31208
  const status = await custody.status();
31051
31209
  const lines = statusLines(status);
31052
31210
  if (status.enrollment.state === "approved")
@@ -32079,7 +32237,7 @@ async function localAccountStoreAuthorized() {
32079
32237
  if (folder?.refusal) return false;
32080
32238
  const claustrum = await loadCommonAuthClaustrum();
32081
32239
  const vaultDir = folder ? folder.vaultDir : decidedRuntimeLayout(location) === "state-home" ? stateHomeVaultDir(location) : legacyVaultDir(accountFileForVault(location.configDir));
32082
- return await enrollmentAuthority2(
32240
+ return await vaultAuthority2(
32083
32241
  claustrum.hostEnrollmentPaths({
32084
32242
  stateDir: vaultDir,
32085
32243
  host: OPENCODE_VAULT_HOST
@@ -33113,10 +33271,10 @@ var init_runtime_layout = __esm({
33113
33271
  import {
33114
33272
  appendFileSync as appendFileSync3,
33115
33273
  copyFileSync,
33116
- existsSync as existsSync3,
33274
+ existsSync as existsSync4,
33117
33275
  promises as fs,
33118
33276
  mkdirSync,
33119
- readFileSync,
33277
+ readFileSync as readFileSync2,
33120
33278
  renameSync as renameSync3,
33121
33279
  unlinkSync,
33122
33280
  writeFileSync
@@ -33191,7 +33349,7 @@ function migrateLegacyWindowsConfig() {
33191
33349
  getLegacyWindowsConfigDir(),
33192
33350
  "antigravity-accounts.json"
33193
33351
  );
33194
- if (!existsSync3(legacyPath) || existsSync3(newPath)) {
33352
+ if (!existsSync4(legacyPath) || existsSync4(newPath)) {
33195
33353
  return false;
33196
33354
  }
33197
33355
  try {
@@ -33225,15 +33383,15 @@ function resolveWindowsAccountAnchor(newPath, legacyPath) {
33225
33383
  const standard = resolve16(newPath);
33226
33384
  const legacy = resolve16(legacyPath);
33227
33385
  if (standard.toLowerCase() === legacy.toLowerCase()) return newPath;
33228
- const standardPointer = existsSync3(accountStorePointerPath(standard));
33229
- const legacyPointer = existsSync3(accountStorePointerPath(legacy));
33386
+ const standardPointer = existsSync4(accountStorePointerPath(standard));
33387
+ const legacyPointer = existsSync4(accountStorePointerPath(legacy));
33230
33388
  if (standardPointer && legacyPointer) {
33231
33389
  throw new Error(
33232
33390
  `Two migrated account stores exist: one is published at ${newPath} and another at ${legacyPath}. Keep one store and remove the other, then restart OpenCode.`
33233
33391
  );
33234
33392
  }
33235
33393
  if (legacyPointer && !standardPointer) return legacyPath;
33236
- if (!existsSync3(standard) && existsSync3(legacy)) return legacyPath;
33394
+ if (!existsSync4(standard) && existsSync4(legacy)) return legacyPath;
33237
33395
  return newPath;
33238
33396
  }
33239
33397
  function getStoragePathWithMigration() {
@@ -33245,7 +33403,7 @@ function getStoragePathWithMigration() {
33245
33403
  "antigravity-accounts.json"
33246
33404
  );
33247
33405
  const anchored = resolveWindowsAccountAnchor(newPath, legacyPath);
33248
- if (resolve16(anchored).toLowerCase() !== resolve16(newPath).toLowerCase() && !existsSync3(accountStorePointerPath(resolve16(anchored)))) {
33406
+ if (resolve16(anchored).toLowerCase() !== resolve16(newPath).toLowerCase() && !existsSync4(accountStorePointerPath(resolve16(anchored)))) {
33249
33407
  log6.info("Using legacy Windows config path (migration failed)", {
33250
33408
  legacyPath,
33251
33409
  newPath
@@ -33266,8 +33424,8 @@ function accountFileForVault(configDir = getConfigDir()) {
33266
33424
  return configured;
33267
33425
  const configuredVault = join15(configDir, "antigravity-auth-vault");
33268
33426
  const legacyVault = join15(legacyDir, "antigravity-auth-vault");
33269
- const configuredPresent = existsSync3(configuredVault);
33270
- const legacyPresent = existsSync3(legacyVault);
33427
+ const configuredPresent = existsSync4(configuredVault);
33428
+ const legacyPresent = existsSync4(legacyVault);
33271
33429
  if (configuredPresent && legacyPresent)
33272
33430
  throw new Error(
33273
33431
  `Two vault folders exist: ${configuredVault} and ${legacyVault}. Keep one vault enrollment before restarting OpenCode.`
@@ -33458,7 +33616,7 @@ var init_storage = __esm({
33458
33616
 
33459
33617
  // src/runtime-paths.ts
33460
33618
  import { createHash as createHash12 } from "node:crypto";
33461
- import { existsSync as existsSync4, promises as fs2, readFileSync as readFileSync2, realpathSync as realpathSync2 } from "node:fs";
33619
+ import { existsSync as existsSync5, promises as fs2, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
33462
33620
  import { homedir as homedir5 } from "node:os";
33463
33621
  import { dirname as dirname17, join as join16, resolve as resolve17 } from "node:path";
33464
33622
  function configDirIdentity(path5) {
@@ -33506,7 +33664,7 @@ function decidedAccountStoreAnchor(location) {
33506
33664
  return shared2.storeAnchors.get(`${location.stateHomeDir}\0${location.key}`);
33507
33665
  }
33508
33666
  function currentRuntimeLayout(location = runtimeLayoutLocation()) {
33509
- return decidedRuntimeLayout(location) ?? (existsSync4(join16(location.stateHomeDir, RUNTIME_LAYOUT_MARKER_FILE)) ? "state-home" : "legacy");
33667
+ return decidedRuntimeLayout(location) ?? (existsSync5(join16(location.stateHomeDir, RUNTIME_LAYOUT_MARKER_FILE)) ? "state-home" : "legacy");
33510
33668
  }
33511
33669
  function legacyWindowsConfigDir() {
33512
33670
  return join16(
@@ -33560,7 +33718,7 @@ function realPathOrSelf(path5) {
33560
33718
  function folderResolvesToItself(path5) {
33561
33719
  let current = dirname17(path5);
33562
33720
  for (; ; ) {
33563
- if (!existsSync4(current)) {
33721
+ if (!existsSync5(current)) {
33564
33722
  const parent = dirname17(current);
33565
33723
  if (parent === current) return true;
33566
33724
  current = parent;
@@ -33573,7 +33731,7 @@ function folderResolvesToItself(path5) {
33573
33731
  function readForwardedAccountStore(anchor) {
33574
33732
  let text2;
33575
33733
  try {
33576
- text2 = readFileSync2(accountStorePointerPath2(anchor), "utf8");
33734
+ text2 = readFileSync3(accountStorePointerPath2(anchor), "utf8");
33577
33735
  } catch {
33578
33736
  return void 0;
33579
33737
  }
@@ -34615,15 +34773,488 @@ async function registerOpenCode2AuthMethods(ctx, options) {
34615
34773
 
34616
34774
  // src/plugin/ga-location-services.ts
34617
34775
  init_dist();
34618
- init_vault_folder();
34619
34776
  import { randomBytes as randomBytes5 } from "node:crypto";
34620
34777
 
34621
- // src/plugin/account-access.ts
34778
+ // src/ga/server/pool-login.ts
34622
34779
  init_dist();
34623
34780
 
34781
+ // src/auth-method-labels.ts
34782
+ var OPENCODE2_POOL_AUTH_LABEL = "Google (antigravity-auth pool, browser)";
34783
+ var OPENCODE2_VAULT_AUTH_LABEL = "Use approved Antigravity vault";
34784
+ var OPENCODE2_POOL_RECONNECT_LABEL = "Use existing local Antigravity pool";
34785
+
34786
+ // src/plugin/server.ts
34787
+ import { existsSync as existsSync2, readFileSync } from "node:fs";
34788
+ import { createServer } from "node:http";
34789
+
34624
34790
  // src/constants.ts
34625
34791
  init_dist();
34626
34792
 
34793
+ // src/plugin/server.ts
34794
+ var redirectUri = new URL(ANTIGRAVITY_REDIRECT_URI);
34795
+ var callbackPath = redirectUri.pathname || "/";
34796
+ function isOrbStackDockerHost() {
34797
+ if (!existsSync2("/.dockerenv")) {
34798
+ return false;
34799
+ }
34800
+ try {
34801
+ if (existsSync2("/proc/version")) {
34802
+ const version = readFileSync("/proc/version", "utf8").toLowerCase();
34803
+ if (version.includes("orbstack")) {
34804
+ return true;
34805
+ }
34806
+ }
34807
+ const hostname = process.env.HOSTNAME || "";
34808
+ if (hostname.startsWith("orbstack-") || hostname.endsWith(".orb") || hostname === "orbstack") {
34809
+ return true;
34810
+ }
34811
+ if (existsSync2("/etc/resolv.conf")) {
34812
+ const resolv = readFileSync("/etc/resolv.conf", "utf8");
34813
+ if (resolv.includes("orb.local") || resolv.includes("orbstack")) {
34814
+ return true;
34815
+ }
34816
+ }
34817
+ if (process.platform === "linux" && existsSync2("/.dockerenv")) {
34818
+ if (existsSync2("/run/host-services")) {
34819
+ return true;
34820
+ }
34821
+ }
34822
+ } catch {
34823
+ }
34824
+ return false;
34825
+ }
34826
+ function isWSL() {
34827
+ if (process.platform !== "linux") return false;
34828
+ try {
34829
+ const release2 = readFileSync("/proc/version", "utf8").toLowerCase();
34830
+ return release2.includes("microsoft") || release2.includes("wsl");
34831
+ } catch {
34832
+ return false;
34833
+ }
34834
+ }
34835
+ function isRemoteEnvironment() {
34836
+ if (process.env.SSH_CLIENT || process.env.SSH_TTY || process.env.SSH_CONNECTION) {
34837
+ return true;
34838
+ }
34839
+ if (process.env.REMOTE_CONTAINERS || process.env.CODESPACES) {
34840
+ return true;
34841
+ }
34842
+ return false;
34843
+ }
34844
+ function getBindAddress() {
34845
+ const envBind = process.env.OPENCODE_ANTIGRAVITY_OAUTH_BIND;
34846
+ if (envBind) {
34847
+ return envBind;
34848
+ }
34849
+ if (isOrbStackDockerHost()) {
34850
+ return "127.0.0.1";
34851
+ }
34852
+ if (isWSL() || isRemoteEnvironment()) {
34853
+ return "0.0.0.0";
34854
+ }
34855
+ return "127.0.0.1";
34856
+ }
34857
+ async function startOAuthListener({
34858
+ timeoutMs = 5 * 60 * 1e3
34859
+ } = {}) {
34860
+ const port = redirectUri.port ? Number.parseInt(redirectUri.port, 10) : redirectUri.protocol === "https:" ? 443 : 80;
34861
+ const origin = `${redirectUri.protocol}//${redirectUri.host}`;
34862
+ let settled = false;
34863
+ let resolveCallback;
34864
+ let rejectCallback;
34865
+ let timeoutHandle;
34866
+ const callbackPromise = new Promise((resolve28, reject) => {
34867
+ resolveCallback = (url) => {
34868
+ if (settled) return;
34869
+ settled = true;
34870
+ if (timeoutHandle) clearTimeout(timeoutHandle);
34871
+ resolve28(url);
34872
+ };
34873
+ rejectCallback = (error) => {
34874
+ if (settled) return;
34875
+ settled = true;
34876
+ if (timeoutHandle) clearTimeout(timeoutHandle);
34877
+ reject(error);
34878
+ };
34879
+ });
34880
+ const successResponse = `<!DOCTYPE html>
34881
+ <html lang="en">
34882
+ <head>
34883
+ <meta charset="utf-8" />
34884
+ <meta name="viewport" content="width=device-width, initial-scale=1">
34885
+ <title>Authentication Successful</title>
34886
+ <style>
34887
+ :root {
34888
+ --bg: #FAFAFA;
34889
+ --card-bg: #FFFFFF;
34890
+ --text-primary: #1F2937;
34891
+ --text-secondary: #6B7280;
34892
+ --accent: #2563EB;
34893
+ --success: #10B981;
34894
+ --border: #E5E7EB;
34895
+ }
34896
+ @media (prefers-color-scheme: dark) {
34897
+ :root {
34898
+ --bg: #111827;
34899
+ --card-bg: #1F2937;
34900
+ --text-primary: #F9FAFB;
34901
+ --text-secondary: #9CA3AF;
34902
+ --accent: #3B82F6;
34903
+ --success: #34D399;
34904
+ --border: #374151;
34905
+ }
34906
+ }
34907
+ body {
34908
+ margin: 0;
34909
+ min-height: 100vh;
34910
+ display: flex;
34911
+ align-items: center;
34912
+ justify-content: center;
34913
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
34914
+ background: var(--bg);
34915
+ color: var(--text-primary);
34916
+ padding: 1rem;
34917
+ }
34918
+ .card {
34919
+ background: var(--card-bg);
34920
+ border-radius: 16px;
34921
+ padding: 3rem 2rem;
34922
+ width: 100%;
34923
+ max-width: 400px;
34924
+ text-align: center;
34925
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
34926
+ border: 1px solid var(--border);
34927
+ }
34928
+ .icon-wrapper {
34929
+ width: 64px;
34930
+ height: 64px;
34931
+ background: rgba(16, 185, 129, 0.1);
34932
+ border-radius: 50%;
34933
+ display: flex;
34934
+ align-items: center;
34935
+ justify-content: center;
34936
+ margin: 0 auto 1.5rem;
34937
+ }
34938
+ .icon {
34939
+ width: 32px;
34940
+ height: 32px;
34941
+ color: var(--success);
34942
+ }
34943
+ h1 {
34944
+ font-size: 1.5rem;
34945
+ font-weight: 600;
34946
+ margin: 0 0 0.5rem;
34947
+ letter-spacing: -0.025em;
34948
+ }
34949
+ p {
34950
+ color: var(--text-secondary);
34951
+ font-size: 0.95rem;
34952
+ line-height: 1.5;
34953
+ margin: 0 0 2rem;
34954
+ }
34955
+ .btn {
34956
+ display: inline-flex;
34957
+ align-items: center;
34958
+ justify-content: center;
34959
+ background: var(--text-primary);
34960
+ color: var(--card-bg);
34961
+ font-weight: 500;
34962
+ padding: 0.75rem 1.5rem;
34963
+ border-radius: 8px;
34964
+ text-decoration: none;
34965
+ transition: opacity 0.2s;
34966
+ font-size: 0.95rem;
34967
+ border: none;
34968
+ cursor: pointer;
34969
+ width: 100%;
34970
+ box-sizing: border-box;
34971
+ }
34972
+ .btn:hover {
34973
+ opacity: 0.9;
34974
+ }
34975
+ .sub-text {
34976
+ margin-top: 1rem;
34977
+ font-size: 0.8rem;
34978
+ color: var(--text-secondary);
34979
+ }
34980
+ </style>
34981
+ </head>
34982
+ <body>
34983
+ <div class="card">
34984
+ <div class="icon-wrapper">
34985
+ <svg class="icon" fill="none" viewBox="0 0 24 24" stroke="currentColor">
34986
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M5 13l4 4L19 7" />
34987
+ </svg>
34988
+ </div>
34989
+ <h1>All set!</h1>
34990
+ <p>You've successfully authenticated with Antigravity. You can now return to Opencode.</p>
34991
+ <button class="btn" onclick="closeWindow()">Close this tab</button>
34992
+ <div class="sub-text">Usage Tip: Most browsers block auto-closing. If the button doesn't work, please close the tab manually.</div>
34993
+ </div>
34994
+ <script>
34995
+ function closeWindow() {
34996
+ window.close();
34997
+ // Fallback if window.close() is blocked
34998
+ document.querySelector('.btn').textContent = "Tab cannot be closed automatically";
34999
+ document.querySelector('.btn').style.opacity = "0.5";
35000
+ document.querySelector('.btn').style.cursor = "default";
35001
+ }
35002
+ </script>
35003
+ </body>
35004
+ </html>`;
35005
+ try {
35006
+ timeoutHandle = setTimeout(() => {
35007
+ rejectCallback(new Error("Timed out waiting for OAuth callback"));
35008
+ }, timeoutMs);
35009
+ timeoutHandle.unref?.();
35010
+ const server = createServer((request2, response) => {
35011
+ if (!request2.url) {
35012
+ response.writeHead(400, { "Content-Type": "text/plain" });
35013
+ response.end("Invalid request");
35014
+ return;
35015
+ }
35016
+ const url = new URL(request2.url, origin);
35017
+ if (url.pathname !== callbackPath) {
35018
+ response.writeHead(404, { "Content-Type": "text/plain" });
35019
+ response.end("Not found");
35020
+ return;
35021
+ }
35022
+ response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
35023
+ response.end(successResponse);
35024
+ resolveCallback(url);
35025
+ setImmediate(() => {
35026
+ server.close();
35027
+ });
35028
+ });
35029
+ const bindAddress = getBindAddress();
35030
+ await new Promise((resolve28, reject) => {
35031
+ const handleError = (error) => {
35032
+ server.off("error", handleError);
35033
+ if (error.code === "EADDRINUSE") {
35034
+ reject(
35035
+ new Error(
35036
+ `Port ${port} is already in use. Another process is occupying this port. Please terminate the process or try again later.`
35037
+ )
35038
+ );
35039
+ return;
35040
+ }
35041
+ reject(error);
35042
+ };
35043
+ server.once("error", handleError);
35044
+ server.listen(port, bindAddress, () => {
35045
+ server.off("error", handleError);
35046
+ resolve28();
35047
+ });
35048
+ });
35049
+ server.on("error", (error) => {
35050
+ rejectCallback(error instanceof Error ? error : new Error(String(error)));
35051
+ });
35052
+ return {
35053
+ waitForCallback: () => callbackPromise,
35054
+ close: () => new Promise((resolve28, reject) => {
35055
+ server.close((error) => {
35056
+ if (error && error.code !== "ERR_SERVER_NOT_RUNNING") {
35057
+ reject(error);
35058
+ return;
35059
+ }
35060
+ if (!settled) {
35061
+ rejectCallback(new Error("OAuth listener closed before callback"));
35062
+ }
35063
+ resolve28();
35064
+ });
35065
+ })
35066
+ };
35067
+ } catch (error) {
35068
+ if (timeoutHandle) clearTimeout(timeoutHandle);
35069
+ throw error;
35070
+ }
35071
+ }
35072
+
35073
+ // src/ga/server/pool-login.ts
35074
+ var GA_POOL_METHOD_ID = "antigravity-auth-pool-browser";
35075
+ var GA_POOL_RECONNECT_METHOD_ID = "antigravity-auth-pool-reconnect";
35076
+ var LOGIN_FAILED = "The Antigravity pool login could not be completed.";
35077
+ function abortable(pending, signal) {
35078
+ return new Promise((resolve28, reject) => {
35079
+ const abort = () => reject(signal.reason);
35080
+ if (signal.aborted) abort();
35081
+ else signal.addEventListener("abort", abort, { once: true });
35082
+ void pending.then(resolve28, reject).finally(() => {
35083
+ signal.removeEventListener("abort", abort);
35084
+ });
35085
+ });
35086
+ }
35087
+ function createGaPoolLogin(input2) {
35088
+ const shutdown = new AbortController();
35089
+ const listeners = /* @__PURE__ */ new Set();
35090
+ const pending = /* @__PURE__ */ new Set();
35091
+ const track = (work) => {
35092
+ pending.add(work);
35093
+ void work.then(
35094
+ () => pending.delete(work),
35095
+ () => pending.delete(work)
35096
+ );
35097
+ return work;
35098
+ };
35099
+ const admit2 = async () => {
35100
+ try {
35101
+ shutdown.signal.throwIfAborted();
35102
+ if (!input2.local) throw new Error(LOGIN_FAILED);
35103
+ await input2.local.assertAdmission();
35104
+ shutdown.signal.throwIfAborted();
35105
+ } catch {
35106
+ throw new Error(LOGIN_FAILED);
35107
+ }
35108
+ };
35109
+ const close = async (listener) => {
35110
+ try {
35111
+ await listener.close();
35112
+ } finally {
35113
+ listeners.delete(listener);
35114
+ }
35115
+ };
35116
+ const method = {
35117
+ method: {
35118
+ id: GA_POOL_METHOD_ID,
35119
+ type: "oauth",
35120
+ label: OPENCODE2_POOL_AUTH_LABEL
35121
+ },
35122
+ authorize: () => track(
35123
+ (async () => {
35124
+ await admit2();
35125
+ const authorization = await (async () => {
35126
+ try {
35127
+ return await abortable(
35128
+ (input2.oauth?.authorize ?? authorizeAntigravity)(),
35129
+ shutdown.signal
35130
+ );
35131
+ } catch {
35132
+ throw new Error(LOGIN_FAILED);
35133
+ }
35134
+ })();
35135
+ await admit2();
35136
+ const state = new URL(authorization.url).searchParams.get("state");
35137
+ if (!state) throw new Error(LOGIN_FAILED);
35138
+ let listener;
35139
+ let code2;
35140
+ const waitForCode = input2.oauth?.waitForCode;
35141
+ if (waitForCode) {
35142
+ code2 = Promise.resolve().then(() => waitForCode(state));
35143
+ } else {
35144
+ listener = await startOAuthListener();
35145
+ listeners.add(listener);
35146
+ code2 = listener.waitForCallback().then((url) => {
35147
+ if (url.searchParams.get("state") !== state)
35148
+ throw new Error(LOGIN_FAILED);
35149
+ const value = url.searchParams.get("code");
35150
+ if (!value) throw new Error(LOGIN_FAILED);
35151
+ return value;
35152
+ });
35153
+ }
35154
+ void code2.catch(() => {
35155
+ });
35156
+ try {
35157
+ await admit2();
35158
+ } catch (error) {
35159
+ if (listener) await close(listener);
35160
+ throw error;
35161
+ }
35162
+ const ownedListener = listener;
35163
+ const callback = track(
35164
+ (async () => {
35165
+ try {
35166
+ await admit2();
35167
+ const value = await abortable(code2, shutdown.signal);
35168
+ await admit2();
35169
+ const result = await abortable(
35170
+ (input2.oauth?.exchange ?? exchangeAntigravity)(value, state, {
35171
+ signal: shutdown.signal,
35172
+ admit: admit2
35173
+ }),
35174
+ shutdown.signal
35175
+ );
35176
+ await admit2();
35177
+ if (result.type !== "success") throw new Error(LOGIN_FAILED);
35178
+ return result;
35179
+ } catch {
35180
+ throw new Error(LOGIN_FAILED);
35181
+ } finally {
35182
+ if (ownedListener) await close(ownedListener);
35183
+ }
35184
+ })()
35185
+ );
35186
+ void callback.catch(() => {
35187
+ });
35188
+ return {
35189
+ mode: "auto",
35190
+ url: authorization.url,
35191
+ instructions: "Complete Google sign-in in your browser.",
35192
+ callback
35193
+ };
35194
+ })()
35195
+ )
35196
+ };
35197
+ return {
35198
+ method,
35199
+ connectExisting: () => track(
35200
+ (async () => {
35201
+ let stage = "initial-admission";
35202
+ try {
35203
+ await admit2();
35204
+ if (!input2.local?.assertExistingPool) throw new Error(LOGIN_FAILED);
35205
+ stage = "existing-pool-admission";
35206
+ await abortable(
35207
+ track(input2.local.assertExistingPool(admit2)),
35208
+ shutdown.signal
35209
+ );
35210
+ stage = "final-admission";
35211
+ await admit2();
35212
+ stage = "placeholder";
35213
+ return placeholderCredential({
35214
+ integrationID: ANTIGRAVITY_PROVIDER_ID,
35215
+ methodID: GA_POOL_RECONNECT_METHOD_ID,
35216
+ now: Date.now()
35217
+ });
35218
+ } catch (error) {
35219
+ const busy = error instanceof AccountStoreBusyError;
35220
+ try {
35221
+ console.warn(
35222
+ `[antigravity.pool-login] stage=${stage} reason=${busy ? "store-busy" : "store-refusal"}`
35223
+ );
35224
+ } catch {
35225
+ }
35226
+ if (busy) throw new AccountStoreBusyError();
35227
+ throw new Error(LOGIN_FAILED);
35228
+ }
35229
+ })()
35230
+ ),
35231
+ onLogin: (result) => track(
35232
+ (async () => {
35233
+ try {
35234
+ await admit2();
35235
+ await input2.local.persist(result, admit2);
35236
+ await admit2();
35237
+ } catch (error) {
35238
+ if (error instanceof AccountStoreBusyError)
35239
+ throw new AccountStoreBusyError();
35240
+ throw new Error(LOGIN_FAILED);
35241
+ }
35242
+ })()
35243
+ ),
35244
+ async dispose() {
35245
+ shutdown.abort(new Error(LOGIN_FAILED));
35246
+ await Promise.allSettled([...listeners].map(close));
35247
+ while (pending.size) await Promise.allSettled([...pending]);
35248
+ }
35249
+ };
35250
+ }
35251
+
35252
+ // src/plugin/ga-location-services.ts
35253
+ init_vault_folder();
35254
+
35255
+ // src/plugin/account-access.ts
35256
+ init_dist();
35257
+
34627
35258
  // src/plugin/account-blocks.ts
34628
35259
  function present3(value) {
34629
35260
  return value === null ? void 0 : value;
@@ -35060,22 +35691,22 @@ function extractAccountAccessErrorDetails(bodyText) {
35060
35691
  }
35061
35692
  function buildAccountAccessProbeRequest(projectId) {
35062
35693
  const wireModel = "gemini-3.8-flash-low";
35063
- const request = {
35694
+ const request2 = {
35064
35695
  contents: [{ role: "user", parts: [{ text: "ping" }] }],
35065
35696
  generationConfig: { maxOutputTokens: 1, temperature: 0 }
35066
35697
  };
35067
35698
  const requestMetadata = buildAgyAgentRequestMetadata(
35068
35699
  createAgyRequestSessionContext(""),
35069
- request,
35700
+ request2,
35070
35701
  wireModel
35071
35702
  );
35072
- request.labels = requestMetadata.labels;
35073
- request.sessionId = requestMetadata.sessionId;
35074
- orderAgyRequestPayloadInPlace(request);
35703
+ request2.labels = requestMetadata.labels;
35704
+ request2.sessionId = requestMetadata.sessionId;
35705
+ orderAgyRequestPayloadInPlace(request2);
35075
35706
  return {
35076
35707
  project: projectId,
35077
35708
  requestId: requestMetadata.requestId,
35078
- request,
35709
+ request: request2,
35079
35710
  model: wireModel,
35080
35711
  userAgent: "antigravity",
35081
35712
  requestType: "agent"
@@ -35693,13 +36324,13 @@ init_dist();
35693
36324
 
35694
36325
  // src/plugin/operator-settings.ts
35695
36326
  import { createHash as createHash13 } from "node:crypto";
35696
- import { existsSync as existsSync7, readFileSync as readFileSync5 } from "node:fs";
36327
+ import { existsSync as existsSync8, readFileSync as readFileSync6 } from "node:fs";
35697
36328
  import { z as z4 } from "zod";
35698
36329
 
35699
36330
  // src/plugin/config/loader.ts
35700
36331
  init_runtime_paths();
35701
36332
  init_logger4();
35702
- import { existsSync as existsSync5, readFileSync as readFileSync3, realpathSync as realpathSync3 } from "node:fs";
36333
+ import { existsSync as existsSync6, readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
35703
36334
  import { homedir as homedir6 } from "node:os";
35704
36335
  import { basename as basename5, dirname as dirname18, join as join18, resolve as resolve18 } from "node:path";
35705
36336
 
@@ -36207,10 +36838,10 @@ function getProjectConfigPath(directory) {
36207
36838
  }
36208
36839
  function loadConfigFile(path5, log17) {
36209
36840
  try {
36210
- if (!existsSync5(path5)) {
36841
+ if (!existsSync6(path5)) {
36211
36842
  return null;
36212
36843
  }
36213
- const content = readFileSync3(path5, "utf-8");
36844
+ const content = readFileSync4(path5, "utf-8");
36214
36845
  const rawConfig = JSON.parse(content);
36215
36846
  const result = AntigravityConfigSchema.partial().safeParse(rawConfig);
36216
36847
  if (!result.success) {
@@ -36315,11 +36946,11 @@ function emptyOperatorSettings() {
36315
36946
  }
36316
36947
 
36317
36948
  // src/plugin/config/writer.ts
36318
- import { existsSync as existsSync6, readFileSync as readFileSync4 } from "node:fs";
36949
+ import { existsSync as existsSync7, readFileSync as readFileSync5 } from "node:fs";
36319
36950
  init_dist();
36320
36951
  import { z as z3 } from "zod";
36321
36952
  async function writeOperatorConfig(options) {
36322
- const target = existsSync6(options.projectConfigPath) ? options.projectConfigPath : options.userConfigPath;
36953
+ const target = existsSync7(options.projectConfigPath) ? options.projectConfigPath : options.userConfigPath;
36323
36954
  await writeOperatorConfigAt(target, options.operator);
36324
36955
  }
36325
36956
  async function writeOperatorConfigAt(target, settings) {
@@ -36345,9 +36976,9 @@ async function writeOperatorConfigAt(target, settings) {
36345
36976
  }
36346
36977
  }
36347
36978
  function readExistingConfig(target) {
36348
- if (!existsSync6(target)) return {};
36979
+ if (!existsSync7(target)) return {};
36349
36980
  try {
36350
- const raw = readFileSync4(target, "utf-8");
36981
+ const raw = readFileSync5(target, "utf-8");
36351
36982
  const parsed = JSON.parse(raw);
36352
36983
  if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
36353
36984
  return parsed;
@@ -36486,7 +37117,7 @@ function acquireLocationOperatorSettings(options) {
36486
37117
  sourcePath: () => projectBound() ? project3.path : user.path,
36487
37118
  async update(mutator) {
36488
37119
  if (disposed) throw new Error("OperatorSettingsController is disposed");
36489
- const target = existsSync7(project3.path) ? project3 : user;
37120
+ const target = existsSync8(project3.path) ? project3 : user;
36490
37121
  const seed = target === project3 ? () => user.read() ?? emptyOperatorSettings() : emptyOperatorSettings;
36491
37122
  const run = target.update(seed, mutator);
36492
37123
  pending = run.catch(() => {
@@ -36507,7 +37138,7 @@ function cloneSettings(settings) {
36507
37138
  }
36508
37139
  function readOperatorFile(path5) {
36509
37140
  try {
36510
- const raw = readFileSync5(path5, "utf-8");
37141
+ const raw = readFileSync6(path5, "utf-8");
36511
37142
  const parsed = JSON.parse(raw);
36512
37143
  if (parsed === null || typeof parsed !== "object" || !("operator" in parsed)) {
36513
37144
  return null;
@@ -36659,7 +37290,7 @@ import { resolve as resolve19 } from "node:path";
36659
37290
  // src/sidebar-state.ts
36660
37291
  init_atomic_write();
36661
37292
  init_file_lock();
36662
- import { chmodSync as chmodSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync6 } from "node:fs";
37293
+ import { chmodSync as chmodSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync7 } from "node:fs";
36663
37294
  import { homedir as homedir7 } from "node:os";
36664
37295
  import { dirname as dirname19, join as join19 } from "node:path";
36665
37296
 
@@ -36726,7 +37357,7 @@ function getSidebarStateFile() {
36726
37357
  function readSidebarState(path5 = getSidebarStateFile()) {
36727
37358
  let raw;
36728
37359
  try {
36729
- raw = readFileSync6(path5, "utf-8");
37360
+ raw = readFileSync7(path5, "utf-8");
36730
37361
  } catch {
36731
37362
  return { ...DEFAULT_SIDEBAR_STATE };
36732
37363
  }
@@ -36740,7 +37371,7 @@ function readSidebarState(path5 = getSidebarStateFile()) {
36740
37371
  }
36741
37372
  function readSidebarStateVersion(path5) {
36742
37373
  try {
36743
- const parsed = JSON.parse(readFileSync6(path5, "utf-8"));
37374
+ const parsed = JSON.parse(readFileSync7(path5, "utf-8"));
36744
37375
  if (!isObject(parsed)) return;
36745
37376
  const version = parsed.version;
36746
37377
  return typeof version === "number" ? version : void 0;
@@ -37208,7 +37839,7 @@ function createOpenCodeQuotaManager(client, providerId = ANTIGRAVITY_PROVIDER_ID
37208
37839
  providerId,
37209
37840
  options.fetchVia
37210
37841
  );
37211
- const fetchAccountQuota = async (account, request, purpose = "required") => {
37842
+ const fetchAccountQuota = async (account, request2, purpose = "required") => {
37212
37843
  const target = account;
37213
37844
  const ref = target.rowRef;
37214
37845
  if (options.mayRun && !await options.mayRun())
@@ -37217,9 +37848,9 @@ function createOpenCodeQuotaManager(client, providerId = ANTIGRAVITY_PROVIDER_ID
37217
37848
  if (!options.fetchStoreAccountQuota)
37218
37849
  throw new Error("Store quota authorization is unavailable");
37219
37850
  const captured = { ...target, rowRef: ref };
37220
- return purpose === "advisory" ? options.fetchStoreAccountQuota(captured, request, purpose) : options.fetchStoreAccountQuota(captured, request);
37851
+ return purpose === "advisory" ? options.fetchStoreAccountQuota(captured, request2, purpose) : options.fetchStoreAccountQuota(captured, request2);
37221
37852
  }
37222
- return purpose === "advisory" ? fetchPoolFileQuota(account, request, purpose) : fetchPoolFileQuota(account, request);
37853
+ return purpose === "advisory" ? fetchPoolFileQuota(account, request2, purpose) : fetchPoolFileQuota(account, request2);
37223
37854
  };
37224
37855
  const manager = createQuotaManager({
37225
37856
  fetchAccountQuota,
@@ -38371,7 +39002,7 @@ var BackgroundVaultQuotaRefresh = class {
38371
39002
  async assertActive(controller) {
38372
39003
  controller.signal.throwIfAborted();
38373
39004
  if (this.disposed) controller.abort();
38374
- else if (await this.options.readAuthority() !== "vault")
39005
+ else if (!["host", "vault"].includes(await this.options.readAuthority()))
38375
39006
  controller.abort({ kind: "not-active" });
38376
39007
  controller.signal.throwIfAborted();
38377
39008
  }
@@ -38848,9 +39479,9 @@ import { createHash as createHash14 } from "node:crypto";
38848
39479
  // src/plugin/cache/signature-cache.ts
38849
39480
  init_runtime_paths();
38850
39481
  import {
38851
- existsSync as existsSync8,
39482
+ existsSync as existsSync9,
38852
39483
  mkdirSync as mkdirSync4,
38853
- readFileSync as readFileSync7,
39484
+ readFileSync as readFileSync8,
38854
39485
  renameSync as renameSync4,
38855
39486
  unlinkSync as unlinkSync3,
38856
39487
  writeFileSync as writeFileSync2
@@ -39066,10 +39697,10 @@ var SignatureCache = class {
39066
39697
  */
39067
39698
  loadFromDisk() {
39068
39699
  try {
39069
- if (!existsSync8(this.cacheFilePath)) {
39700
+ if (!existsSync9(this.cacheFilePath)) {
39070
39701
  return;
39071
39702
  }
39072
- const content = readFileSync7(this.cacheFilePath, "utf-8");
39703
+ const content = readFileSync8(this.cacheFilePath, "utf-8");
39073
39704
  const data = JSON.parse(content);
39074
39705
  if (data.version !== "1.0") {
39075
39706
  return;
@@ -39100,14 +39731,14 @@ var SignatureCache = class {
39100
39731
  saveToDisk() {
39101
39732
  try {
39102
39733
  const dir = dirname20(this.cacheFilePath);
39103
- if (!existsSync8(dir)) {
39734
+ if (!existsSync9(dir)) {
39104
39735
  mkdirSync4(dir, { recursive: true });
39105
39736
  }
39106
39737
  const now = this.now();
39107
39738
  let existingEntries = {};
39108
- if (existsSync8(this.cacheFilePath)) {
39739
+ if (existsSync9(this.cacheFilePath)) {
39109
39740
  try {
39110
- const content = readFileSync7(this.cacheFilePath, "utf-8");
39741
+ const content = readFileSync8(this.cacheFilePath, "utf-8");
39111
39742
  const data = JSON.parse(content);
39112
39743
  existingEntries = data.entries || {};
39113
39744
  } catch {
@@ -39148,7 +39779,7 @@ var SignatureCache = class {
39148
39779
  try {
39149
39780
  renameSync4(tmpPath, this.cacheFilePath);
39150
39781
  } catch {
39151
- writeFileSync2(this.cacheFilePath, readFileSync7(tmpPath));
39782
+ writeFileSync2(this.cacheFilePath, readFileSync8(tmpPath));
39152
39783
  try {
39153
39784
  unlinkSync3(tmpPath);
39154
39785
  } catch {
@@ -39495,12 +40126,12 @@ function clearSignatureCache(sessionId) {
39495
40126
  }
39496
40127
 
39497
40128
  // src/plugin/image-saver.ts
39498
- import { chmodSync as chmodSync4, existsSync as existsSync9, mkdirSync as mkdirSync5, writeFileSync as writeFileSync3 } from "node:fs";
40129
+ import { chmodSync as chmodSync4, existsSync as existsSync10, mkdirSync as mkdirSync5, writeFileSync as writeFileSync3 } from "node:fs";
39499
40130
  import { homedir as homedir8 } from "node:os";
39500
40131
  import { join as join21 } from "node:path";
39501
40132
  function getImageOutputDir(outputDir) {
39502
40133
  const resolved = outputDir ?? join21(homedir8(), ".opencode", "generated-images");
39503
- if (!existsSync9(resolved)) {
40134
+ if (!existsSync10(resolved)) {
39504
40135
  mkdirSync5(resolved, { recursive: true, mode: 448 });
39505
40136
  }
39506
40137
  chmodSync4(resolved, 448);
@@ -40080,9 +40711,9 @@ function collectToolNames(value) {
40080
40711
  function bodyStructureSummary(bodyText) {
40081
40712
  const parsed = parseBody(bodyText);
40082
40713
  if (!parsed) return { parseable: false };
40083
- const request = parsed.request && typeof parsed.request === "object" ? parsed.request : void 0;
40084
- const contents = Array.isArray(request?.contents) ? request.contents : [];
40085
- const toolNames = collectToolNames(request ?? parsed);
40714
+ const request2 = parsed.request && typeof parsed.request === "object" ? parsed.request : void 0;
40715
+ const contents = Array.isArray(request2?.contents) ? request2.contents : [];
40716
+ const toolNames = collectToolNames(request2 ?? parsed);
40086
40717
  return {
40087
40718
  parseable: true,
40088
40719
  model: typeof parsed.model === "string" ? parsed.model : void 0,
@@ -40204,10 +40835,10 @@ init_logger4();
40204
40835
 
40205
40836
  // src/plugin/recovery/storage.ts
40206
40837
  import {
40207
- existsSync as existsSync10,
40838
+ existsSync as existsSync11,
40208
40839
  mkdirSync as mkdirSync7,
40209
40840
  readdirSync as readdirSync2,
40210
- readFileSync as readFileSync8,
40841
+ readFileSync as readFileSync9,
40211
40842
  unlinkSync as unlinkSync4,
40212
40843
  writeFileSync as writeFileSync5
40213
40844
  } from "node:fs";
@@ -40234,15 +40865,15 @@ var THINKING_TYPES = /* @__PURE__ */ new Set([
40234
40865
 
40235
40866
  // src/plugin/recovery/storage.ts
40236
40867
  function getMessageDir(sessionID) {
40237
- if (!existsSync10(MESSAGE_STORAGE)) return "";
40868
+ if (!existsSync11(MESSAGE_STORAGE)) return "";
40238
40869
  const directPath = join24(MESSAGE_STORAGE, sessionID);
40239
- if (existsSync10(directPath)) {
40870
+ if (existsSync11(directPath)) {
40240
40871
  return directPath;
40241
40872
  }
40242
40873
  try {
40243
40874
  for (const dir of readdirSync2(MESSAGE_STORAGE)) {
40244
40875
  const sessionPath = join24(MESSAGE_STORAGE, dir, sessionID);
40245
- if (existsSync10(sessionPath)) {
40876
+ if (existsSync11(sessionPath)) {
40246
40877
  return sessionPath;
40247
40878
  }
40248
40879
  }
@@ -40252,13 +40883,13 @@ function getMessageDir(sessionID) {
40252
40883
  }
40253
40884
  function readMessages(sessionID) {
40254
40885
  const messageDir = getMessageDir(sessionID);
40255
- if (!messageDir || !existsSync10(messageDir)) return [];
40886
+ if (!messageDir || !existsSync11(messageDir)) return [];
40256
40887
  const messages = [];
40257
40888
  try {
40258
40889
  for (const file of readdirSync2(messageDir)) {
40259
40890
  if (!file.endsWith(".json")) continue;
40260
40891
  try {
40261
- const content = readFileSync8(join24(messageDir, file), "utf-8");
40892
+ const content = readFileSync9(join24(messageDir, file), "utf-8");
40262
40893
  messages.push(JSON.parse(content));
40263
40894
  } catch {
40264
40895
  }
@@ -40275,13 +40906,13 @@ function readMessages(sessionID) {
40275
40906
  }
40276
40907
  function readParts(messageID) {
40277
40908
  const partDir = join24(PART_STORAGE, messageID);
40278
- if (!existsSync10(partDir)) return [];
40909
+ if (!existsSync11(partDir)) return [];
40279
40910
  const parts = [];
40280
40911
  try {
40281
40912
  for (const file of readdirSync2(partDir)) {
40282
40913
  if (!file.endsWith(".json")) continue;
40283
40914
  try {
40284
- const content = readFileSync8(join24(partDir, file), "utf-8");
40915
+ const content = readFileSync9(join24(partDir, file), "utf-8");
40285
40916
  parts.push(JSON.parse(content));
40286
40917
  } catch {
40287
40918
  }
@@ -40325,7 +40956,7 @@ function findMessagesWithOrphanThinking(sessionID) {
40325
40956
  function prependThinkingPart(sessionID, messageID) {
40326
40957
  const partDir = join24(PART_STORAGE, messageID);
40327
40958
  try {
40328
- if (!existsSync10(partDir)) {
40959
+ if (!existsSync11(partDir)) {
40329
40960
  mkdirSync7(partDir, { recursive: true });
40330
40961
  }
40331
40962
  const partId = "prt_0000000000_thinking";
@@ -40348,14 +40979,14 @@ function prependThinkingPart(sessionID, messageID) {
40348
40979
  }
40349
40980
  function stripThinkingParts(messageID) {
40350
40981
  const partDir = join24(PART_STORAGE, messageID);
40351
- if (!existsSync10(partDir)) return false;
40982
+ if (!existsSync11(partDir)) return false;
40352
40983
  let anyRemoved = false;
40353
40984
  try {
40354
40985
  for (const file of readdirSync2(partDir)) {
40355
40986
  if (!file.endsWith(".json")) continue;
40356
40987
  try {
40357
40988
  const filePath = join24(partDir, file);
40358
- const content = readFileSync8(filePath, "utf-8");
40989
+ const content = readFileSync9(filePath, "utf-8");
40359
40990
  const part = JSON.parse(content);
40360
40991
  if (THINKING_TYPES.has(part.type)) {
40361
40992
  unlinkSync4(filePath);
@@ -42016,15 +42647,15 @@ function assignToolIdsToContents(contents) {
42016
42647
  }
42017
42648
  const newParts = content.parts.map((part) => {
42018
42649
  if (part && typeof part === "object" && part.functionCall) {
42019
- const call = { ...part.functionCall };
42020
- if (!call.id) {
42021
- call.id = `tool-call-${++toolCallCounter}`;
42650
+ const call2 = { ...part.functionCall };
42651
+ if (!call2.id) {
42652
+ call2.id = `tool-call-${++toolCallCounter}`;
42022
42653
  }
42023
- const nameKey = typeof call.name === "string" ? call.name : `tool-${toolCallCounter}`;
42654
+ const nameKey = typeof call2.name === "string" ? call2.name : `tool-${toolCallCounter}`;
42024
42655
  const queue2 = pendingCallIdsByName.get(nameKey) || [];
42025
- queue2.push(call.id);
42656
+ queue2.push(call2.id);
42026
42657
  pendingCallIdsByName.set(nameKey, queue2);
42027
- return { ...part, functionCall: call };
42658
+ return { ...part, functionCall: call2 };
42028
42659
  }
42029
42660
  return part;
42030
42661
  });
@@ -43090,14 +43721,14 @@ function normalizeNativeFunctionResponseRoles(payload) {
43090
43721
  if (!Array.isArray(parts)) continue;
43091
43722
  let signedTurn = false;
43092
43723
  for (const part of parts) {
43093
- const call = part?.functionCall;
43094
- if (!call) continue;
43724
+ const call2 = part?.functionCall;
43725
+ if (!call2) continue;
43095
43726
  const signature = part.thoughtSignature;
43096
43727
  if (typeof signature === "string") {
43097
43728
  signedTurn = signature.length >= MIN_SIGNATURE_LENGTH && signature !== SKIP_THOUGHT_SIGNATURE;
43098
43729
  }
43099
43730
  if (signedTurn) {
43100
- signedCalls.add(String(call.id ?? call.name));
43731
+ signedCalls.add(String(call2.id ?? call2.name));
43101
43732
  }
43102
43733
  }
43103
43734
  }
@@ -43994,15 +44625,15 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
43994
44625
  }
43995
44626
  const newParts = content.parts.map((part) => {
43996
44627
  if (part && typeof part === "object" && part.functionCall) {
43997
- const call = { ...part.functionCall };
43998
- if (!call.id) {
43999
- call.id = `tool-call-${++toolCallCounter}`;
44628
+ const call2 = { ...part.functionCall };
44629
+ if (!call2.id) {
44630
+ call2.id = `tool-call-${++toolCallCounter}`;
44000
44631
  }
44001
- const nameKey = typeof call.name === "string" ? call.name : `tool-${toolCallCounter}`;
44632
+ const nameKey = typeof call2.name === "string" ? call2.name : `tool-${toolCallCounter}`;
44002
44633
  const queue2 = pendingCallIdsByName.get(nameKey) || [];
44003
- queue2.push(call.id);
44634
+ queue2.push(call2.id);
44004
44635
  pendingCallIdsByName.set(nameKey, queue2);
44005
- return { ...part, functionCall: call };
44636
+ return { ...part, functionCall: call2 };
44006
44637
  }
44007
44638
  return part;
44008
44639
  });
@@ -44602,288 +45233,6 @@ function transformAntigravityResponse(...args) {
44602
45233
  return transformAntigravityResponseIn(openCode1WireLocation, ...args);
44603
45234
  }
44604
45235
 
44605
- // src/plugin/server.ts
44606
- import { existsSync as existsSync11, readFileSync as readFileSync9 } from "node:fs";
44607
- import { createServer } from "node:http";
44608
- var redirectUri = new URL(ANTIGRAVITY_REDIRECT_URI);
44609
- var callbackPath = redirectUri.pathname || "/";
44610
- function isOrbStackDockerHost() {
44611
- if (!existsSync11("/.dockerenv")) {
44612
- return false;
44613
- }
44614
- try {
44615
- if (existsSync11("/proc/version")) {
44616
- const version = readFileSync9("/proc/version", "utf8").toLowerCase();
44617
- if (version.includes("orbstack")) {
44618
- return true;
44619
- }
44620
- }
44621
- const hostname = process.env.HOSTNAME || "";
44622
- if (hostname.startsWith("orbstack-") || hostname.endsWith(".orb") || hostname === "orbstack") {
44623
- return true;
44624
- }
44625
- if (existsSync11("/etc/resolv.conf")) {
44626
- const resolv = readFileSync9("/etc/resolv.conf", "utf8");
44627
- if (resolv.includes("orb.local") || resolv.includes("orbstack")) {
44628
- return true;
44629
- }
44630
- }
44631
- if (process.platform === "linux" && existsSync11("/.dockerenv")) {
44632
- if (existsSync11("/run/host-services")) {
44633
- return true;
44634
- }
44635
- }
44636
- } catch {
44637
- }
44638
- return false;
44639
- }
44640
- function isWSL() {
44641
- if (process.platform !== "linux") return false;
44642
- try {
44643
- const release2 = readFileSync9("/proc/version", "utf8").toLowerCase();
44644
- return release2.includes("microsoft") || release2.includes("wsl");
44645
- } catch {
44646
- return false;
44647
- }
44648
- }
44649
- function isRemoteEnvironment() {
44650
- if (process.env.SSH_CLIENT || process.env.SSH_TTY || process.env.SSH_CONNECTION) {
44651
- return true;
44652
- }
44653
- if (process.env.REMOTE_CONTAINERS || process.env.CODESPACES) {
44654
- return true;
44655
- }
44656
- return false;
44657
- }
44658
- function getBindAddress() {
44659
- const envBind = process.env.OPENCODE_ANTIGRAVITY_OAUTH_BIND;
44660
- if (envBind) {
44661
- return envBind;
44662
- }
44663
- if (isOrbStackDockerHost()) {
44664
- return "127.0.0.1";
44665
- }
44666
- if (isWSL() || isRemoteEnvironment()) {
44667
- return "0.0.0.0";
44668
- }
44669
- return "127.0.0.1";
44670
- }
44671
- async function startOAuthListener({
44672
- timeoutMs = 5 * 60 * 1e3
44673
- } = {}) {
44674
- const port = redirectUri.port ? Number.parseInt(redirectUri.port, 10) : redirectUri.protocol === "https:" ? 443 : 80;
44675
- const origin = `${redirectUri.protocol}//${redirectUri.host}`;
44676
- let settled = false;
44677
- let resolveCallback;
44678
- let rejectCallback;
44679
- let timeoutHandle;
44680
- const callbackPromise = new Promise((resolve28, reject) => {
44681
- resolveCallback = (url) => {
44682
- if (settled) return;
44683
- settled = true;
44684
- if (timeoutHandle) clearTimeout(timeoutHandle);
44685
- resolve28(url);
44686
- };
44687
- rejectCallback = (error) => {
44688
- if (settled) return;
44689
- settled = true;
44690
- if (timeoutHandle) clearTimeout(timeoutHandle);
44691
- reject(error);
44692
- };
44693
- });
44694
- const successResponse = `<!DOCTYPE html>
44695
- <html lang="en">
44696
- <head>
44697
- <meta charset="utf-8" />
44698
- <meta name="viewport" content="width=device-width, initial-scale=1">
44699
- <title>Authentication Successful</title>
44700
- <style>
44701
- :root {
44702
- --bg: #FAFAFA;
44703
- --card-bg: #FFFFFF;
44704
- --text-primary: #1F2937;
44705
- --text-secondary: #6B7280;
44706
- --accent: #2563EB;
44707
- --success: #10B981;
44708
- --border: #E5E7EB;
44709
- }
44710
- @media (prefers-color-scheme: dark) {
44711
- :root {
44712
- --bg: #111827;
44713
- --card-bg: #1F2937;
44714
- --text-primary: #F9FAFB;
44715
- --text-secondary: #9CA3AF;
44716
- --accent: #3B82F6;
44717
- --success: #34D399;
44718
- --border: #374151;
44719
- }
44720
- }
44721
- body {
44722
- margin: 0;
44723
- min-height: 100vh;
44724
- display: flex;
44725
- align-items: center;
44726
- justify-content: center;
44727
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
44728
- background: var(--bg);
44729
- color: var(--text-primary);
44730
- padding: 1rem;
44731
- }
44732
- .card {
44733
- background: var(--card-bg);
44734
- border-radius: 16px;
44735
- padding: 3rem 2rem;
44736
- width: 100%;
44737
- max-width: 400px;
44738
- text-align: center;
44739
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
44740
- border: 1px solid var(--border);
44741
- }
44742
- .icon-wrapper {
44743
- width: 64px;
44744
- height: 64px;
44745
- background: rgba(16, 185, 129, 0.1);
44746
- border-radius: 50%;
44747
- display: flex;
44748
- align-items: center;
44749
- justify-content: center;
44750
- margin: 0 auto 1.5rem;
44751
- }
44752
- .icon {
44753
- width: 32px;
44754
- height: 32px;
44755
- color: var(--success);
44756
- }
44757
- h1 {
44758
- font-size: 1.5rem;
44759
- font-weight: 600;
44760
- margin: 0 0 0.5rem;
44761
- letter-spacing: -0.025em;
44762
- }
44763
- p {
44764
- color: var(--text-secondary);
44765
- font-size: 0.95rem;
44766
- line-height: 1.5;
44767
- margin: 0 0 2rem;
44768
- }
44769
- .btn {
44770
- display: inline-flex;
44771
- align-items: center;
44772
- justify-content: center;
44773
- background: var(--text-primary);
44774
- color: var(--card-bg);
44775
- font-weight: 500;
44776
- padding: 0.75rem 1.5rem;
44777
- border-radius: 8px;
44778
- text-decoration: none;
44779
- transition: opacity 0.2s;
44780
- font-size: 0.95rem;
44781
- border: none;
44782
- cursor: pointer;
44783
- width: 100%;
44784
- box-sizing: border-box;
44785
- }
44786
- .btn:hover {
44787
- opacity: 0.9;
44788
- }
44789
- .sub-text {
44790
- margin-top: 1rem;
44791
- font-size: 0.8rem;
44792
- color: var(--text-secondary);
44793
- }
44794
- </style>
44795
- </head>
44796
- <body>
44797
- <div class="card">
44798
- <div class="icon-wrapper">
44799
- <svg class="icon" fill="none" viewBox="0 0 24 24" stroke="currentColor">
44800
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M5 13l4 4L19 7" />
44801
- </svg>
44802
- </div>
44803
- <h1>All set!</h1>
44804
- <p>You've successfully authenticated with Antigravity. You can now return to Opencode.</p>
44805
- <button class="btn" onclick="closeWindow()">Close this tab</button>
44806
- <div class="sub-text">Usage Tip: Most browsers block auto-closing. If the button doesn't work, please close the tab manually.</div>
44807
- </div>
44808
- <script>
44809
- function closeWindow() {
44810
- window.close();
44811
- // Fallback if window.close() is blocked
44812
- document.querySelector('.btn').textContent = "Tab cannot be closed automatically";
44813
- document.querySelector('.btn').style.opacity = "0.5";
44814
- document.querySelector('.btn').style.cursor = "default";
44815
- }
44816
- </script>
44817
- </body>
44818
- </html>`;
44819
- try {
44820
- timeoutHandle = setTimeout(() => {
44821
- rejectCallback(new Error("Timed out waiting for OAuth callback"));
44822
- }, timeoutMs);
44823
- timeoutHandle.unref?.();
44824
- const server = createServer((request, response) => {
44825
- if (!request.url) {
44826
- response.writeHead(400, { "Content-Type": "text/plain" });
44827
- response.end("Invalid request");
44828
- return;
44829
- }
44830
- const url = new URL(request.url, origin);
44831
- if (url.pathname !== callbackPath) {
44832
- response.writeHead(404, { "Content-Type": "text/plain" });
44833
- response.end("Not found");
44834
- return;
44835
- }
44836
- response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
44837
- response.end(successResponse);
44838
- resolveCallback(url);
44839
- setImmediate(() => {
44840
- server.close();
44841
- });
44842
- });
44843
- const bindAddress = getBindAddress();
44844
- await new Promise((resolve28, reject) => {
44845
- const handleError = (error) => {
44846
- server.off("error", handleError);
44847
- if (error.code === "EADDRINUSE") {
44848
- reject(
44849
- new Error(
44850
- `Port ${port} is already in use. Another process is occupying this port. Please terminate the process or try again later.`
44851
- )
44852
- );
44853
- return;
44854
- }
44855
- reject(error);
44856
- };
44857
- server.once("error", handleError);
44858
- server.listen(port, bindAddress, () => {
44859
- server.off("error", handleError);
44860
- resolve28();
44861
- });
44862
- });
44863
- server.on("error", (error) => {
44864
- rejectCallback(error instanceof Error ? error : new Error(String(error)));
44865
- });
44866
- return {
44867
- waitForCallback: () => callbackPromise,
44868
- close: () => new Promise((resolve28, reject) => {
44869
- server.close((error) => {
44870
- if (error && error.code !== "ERR_SERVER_NOT_RUNNING") {
44871
- reject(error);
44872
- return;
44873
- }
44874
- if (!settled) {
44875
- rejectCallback(new Error("OAuth listener closed before callback"));
44876
- }
44877
- resolve28();
44878
- });
44879
- })
44880
- };
44881
- } catch (error) {
44882
- if (timeoutHandle) clearTimeout(timeoutHandle);
44883
- throw error;
44884
- }
44885
- }
44886
-
44887
45236
  // src/plugin/session-context.ts
44888
45237
  import { resolve as resolve20 } from "node:path";
44889
45238
  import { pathToFileURL } from "node:url";
@@ -44904,10 +45253,10 @@ var AgySessionRegistry = class {
44904
45253
  }
44905
45254
  getOrCreate(identity3) {
44906
45255
  const key = identity3.sessionId ?? FALLBACK_SESSION_KEY;
44907
- const request = this.requestSessions.getOrCreate(key);
45256
+ const request2 = this.requestSessions.getOrCreate(key);
44908
45257
  this.recordParent(key, identity3.parentSessionId);
44909
45258
  this.pruneParentRelationships();
44910
- return request;
45259
+ return request2;
44911
45260
  }
44912
45261
  beginRequest(identity3) {
44913
45262
  const key = identity3.sessionId ?? FALLBACK_SESSION_KEY;
@@ -45182,15 +45531,15 @@ async function askRouting(input2) {
45182
45531
  timer = setTimeout(() => resolve28(void 0), deadlineMs);
45183
45532
  timer.unref();
45184
45533
  });
45185
- const request = {
45534
+ const request2 = {
45186
45535
  provider: input2.provider,
45187
45536
  modelId: input2.modelId
45188
45537
  };
45189
45538
  const cap = input2.holdWaitMaxS;
45190
45539
  if (typeof cap === "number" && Number.isFinite(cap)) {
45191
- request.hold_wait_max_s = Math.max(0, Math.floor(cap));
45540
+ request2.hold_wait_max_s = Math.max(0, Math.floor(cap));
45192
45541
  }
45193
- const pending = accountFor.call(handle, request, { deadlineMs });
45542
+ const pending = accountFor.call(handle, request2, { deadlineMs });
45194
45543
  if (!isObject2(pending) || typeof pending.then !== "function")
45195
45544
  return void 0;
45196
45545
  const answer = await Promise.race([pending, expired]);
@@ -45999,15 +46348,15 @@ function isPrimaryVaultRequest(kind, headers) {
45999
46348
  // src/plugin/shared/request-services.ts
46000
46349
  var FIRST_RETRY_DELAY_MS = 1e3;
46001
46350
  var MODEL_UNAVAILABLE_TTL_MS = 60 * 60 * 1e3;
46002
- function prepareAgyWireRequest(wire, request) {
46351
+ function prepareAgyWireRequest(wire, request2) {
46003
46352
  return wire.prepare(
46004
- request.input,
46005
- request.init,
46006
- request.accessToken,
46007
- request.projectId,
46008
- request.endpoint,
46009
- request.forceThinkingRecovery ?? false,
46010
- request.options
46353
+ request2.input,
46354
+ request2.init,
46355
+ request2.accessToken,
46356
+ request2.projectId,
46357
+ request2.endpoint,
46358
+ request2.forceThinkingRecovery ?? false,
46359
+ request2.options
46011
46360
  );
46012
46361
  }
46013
46362
  var TITLE_FALLBACK_MODEL = "gemini-3.8-flash-low";
@@ -49246,6 +49595,7 @@ function createGaLocationMenu(input2) {
49246
49595
  }),
49247
49596
  ...input2.refreshQuota ? { refreshQuota: input2.refreshQuota } : {},
49248
49597
  ...input2.reauthorize ? { reauthorize: input2.reauthorize } : {},
49598
+ ...input2.login ? { login: input2.login } : {},
49249
49599
  ...input2.vault ? { extras: [input2.vault] } : {}
49250
49600
  });
49251
49601
  }
@@ -49262,10 +49612,10 @@ function scopeInvocation(scope, notify) {
49262
49612
  }
49263
49613
  function createGaMenuCommandService(input2) {
49264
49614
  return {
49265
- async apply({ request, scope, signal }) {
49615
+ async apply({ request: request2, scope, signal }) {
49266
49616
  if (signal.aborted) throw abortError(signal);
49267
49617
  const result = await input2.menu.apply(
49268
- request,
49618
+ request2,
49269
49619
  scopeInvocation(scope, input2.notify)
49270
49620
  );
49271
49621
  if (input2.afterApply) {
@@ -50208,55 +50558,62 @@ function createGaLocationServicesFactory(bindings) {
50208
50558
  });
50209
50559
  throw error;
50210
50560
  }
50211
- return {
50212
- runtime,
50213
- localLogin: {
50214
- assertAdmission: assertLocal,
50215
- async assertExistingPool(admit2) {
50216
- await assertLocal();
50217
- await admit2();
50218
- const repository = await getRepository();
50219
- await admit2();
50220
- const opened = await repositoryPromise;
50221
- await admit2();
50222
- if (!opened)
50223
- throw new Error("The local repository was not constructed");
50224
- await assertServingAdmission(opened, bindings.now);
50225
- await admit2();
50226
- const read = await repository.read();
50227
- await admit2();
50228
- if (read.status !== "ready" || !read.rows.some(
50229
- (row) => row.enabled && row.usable && row.credential !== void 0 && !row.torn && !row.unbound && row.invalid === void 0 && row.metadata.status === "present" && accessBlockOf2(row).kind === "none"
50230
- ))
50231
- throw new Error(
50232
- "The existing local Antigravity pool is unavailable"
50233
- );
50234
- await assertServingAdmission(opened, bindings.now);
50235
- await admit2();
50236
- await assertLocal();
50237
- await admit2();
50238
- },
50239
- async persist(result, admit2) {
50240
- await assertLocal();
50241
- await admit2();
50242
- const repository = await getRepository({ admit: admit2 });
50243
- await admit2();
50244
- const opened = await repositoryPromise;
50245
- await admit2();
50246
- if (!opened)
50247
- throw new Error("The local repository was not constructed");
50248
- await assertServingAdmission(opened, bindings.now);
50249
- await admit2();
50250
- const committed = await commitLogins(repository, [result]);
50251
- await admit2();
50252
- if (committed.length !== 1 || committed[0]?.status !== "committed")
50253
- throw new Error(
50254
- "The Antigravity pool login could not be completed."
50255
- );
50256
- await localPipeline?.refreshAccounts();
50257
- await admit2();
50561
+ const localLogin = {
50562
+ assertAdmission: assertLocal,
50563
+ async assertExistingPool(admit2) {
50564
+ await assertLocal();
50565
+ await admit2();
50566
+ const repository = await getRepository();
50567
+ await admit2();
50568
+ const opened = await repositoryPromise;
50569
+ await admit2();
50570
+ if (!opened) throw new Error("The local repository was not constructed");
50571
+ await assertServingAdmission(opened, bindings.now);
50572
+ await admit2();
50573
+ const read = await repository.read();
50574
+ await admit2();
50575
+ if (read.status !== "ready" || !read.rows.some(
50576
+ (row) => row.enabled && row.usable && row.credential !== void 0 && !row.torn && !row.unbound && row.invalid === void 0 && row.metadata.status === "present" && accessBlockOf2(row).kind === "none"
50577
+ ))
50578
+ throw new Error("The existing local Antigravity pool is unavailable");
50579
+ await assertServingAdmission(opened, bindings.now);
50580
+ await admit2();
50581
+ await assertLocal();
50582
+ await admit2();
50583
+ },
50584
+ async persist(result, admit2) {
50585
+ await assertLocal();
50586
+ await admit2();
50587
+ const repository = await getRepository({ admit: admit2 });
50588
+ await admit2();
50589
+ const opened = await repositoryPromise;
50590
+ await admit2();
50591
+ if (!opened) throw new Error("The local repository was not constructed");
50592
+ await assertServingAdmission(opened, bindings.now);
50593
+ await admit2();
50594
+ const committed = await commitLogins(repository, [result]);
50595
+ await admit2();
50596
+ if (committed.length !== 1 || committed[0]?.status !== "committed")
50597
+ throw new Error("The Antigravity pool login could not be completed.");
50598
+ await localPipeline?.refreshAccounts();
50599
+ await admit2();
50600
+ }
50601
+ };
50602
+ const menuLogin = createGaPoolLogin({
50603
+ local: {
50604
+ ...localLogin,
50605
+ async assertAdmission() {
50606
+ if (process.env.CORTEXKIT_VAULT_HOST === "thalamus")
50607
+ throw new Error("Vault authority excludes local sign-in.");
50608
+ await localLogin.assertAdmission();
50258
50609
  }
50259
50610
  },
50611
+ oauth: overrides.oauth
50612
+ });
50613
+ const loginCompletions = /* @__PURE__ */ new Set();
50614
+ return {
50615
+ runtime,
50616
+ localLogin,
50260
50617
  async start(input2) {
50261
50618
  if (closing) throw new Error("The location services are disposed");
50262
50619
  if (started) throw new Error("The location services already started");
@@ -50373,6 +50730,33 @@ function createGaLocationServicesFactory(bindings) {
50373
50730
  repository,
50374
50731
  runtime: location,
50375
50732
  reauthorize: pendingReauthorization,
50733
+ login: {
50734
+ async run(invocation) {
50735
+ const authorization = await menuLogin.method.authorize({});
50736
+ if (authorization.mode !== "auto")
50737
+ throw new Error(
50738
+ "Antigravity sign-in needs a local browser callback."
50739
+ );
50740
+ const completion = authorization.callback.then((result) => menuLogin.onLogin(result)).then(
50741
+ () => {
50742
+ invocation.notify("Account added.", "info");
50743
+ },
50744
+ () => {
50745
+ invocation.notify(
50746
+ "Antigravity sign-in did not complete.",
50747
+ "error"
50748
+ );
50749
+ }
50750
+ ).catch(() => {
50751
+ });
50752
+ loginCompletions.add(completion);
50753
+ void completion.finally(
50754
+ () => loginCompletions.delete(completion)
50755
+ );
50756
+ return `Open ${authorization.url} in your browser and sign in.
50757
+ The account is added when the browser returns here; there is nothing to paste.`;
50758
+ }
50759
+ },
50376
50760
  ...custody ? { vault: custody.menuSection() } : {},
50377
50761
  ...checkQuota ? {
50378
50762
  refreshQuota: async (refs) => {
@@ -50497,25 +50881,25 @@ function createGaLocationServicesFactory(bindings) {
50497
50881
  return (await choose("execute")).execute(job, context);
50498
50882
  }),
50499
50883
  commands: {
50500
- apply: (request) => run(async () => {
50501
- if (request.signal.aborted) throw request.signal.reason;
50502
- return (await choose("view")).commands.apply(request);
50884
+ apply: (request2) => run(async () => {
50885
+ if (request2.signal.aborted) throw request2.signal.reason;
50886
+ return (await choose("view")).commands.apply(request2);
50503
50887
  }),
50504
- open: (request) => run(async () => {
50505
- if (request.signal.aborted) throw request.signal.reason;
50506
- return (await choose("view")).commands.open(request);
50888
+ open: (request2) => run(async () => {
50889
+ if (request2.signal.aborted) throw request2.signal.reason;
50890
+ return (await choose("view")).commands.open(request2);
50507
50891
  })
50508
50892
  },
50509
50893
  state: {
50510
- read(request) {
50894
+ read(request2) {
50511
50895
  return run(() => {
50512
50896
  const pending = reads.then(async () => {
50513
50897
  if (closing)
50514
50898
  throw new Error("The location services are disposed");
50515
- if (request.signal.aborted) throw request.signal.reason;
50899
+ if (request2.signal.aborted) throw request2.signal.reason;
50516
50900
  for (let attempt = 0; attempt < 2; attempt++) {
50517
50901
  const before = await authority();
50518
- const answer = await (await choose("view", before)).state.read(request);
50902
+ const answer = await (await choose("view", before)).state.read(request2);
50519
50903
  if (before === await authority()) return answer;
50520
50904
  }
50521
50905
  throw new Error(
@@ -50540,6 +50924,7 @@ function createGaLocationServicesFactory(bindings) {
50540
50924
  ]);
50541
50925
  try {
50542
50926
  const resources = Promise.allSettled([
50927
+ menuLogin.dispose().then(() => Promise.allSettled([...loginCompletions])),
50543
50928
  reauthorize?.dispose(),
50544
50929
  localPipeline?.dispose(),
50545
50930
  vaultServices?.dispose()
@@ -51776,11 +52161,13 @@ function validateStateOutput(value, issues) {
51776
52161
  "status",
51777
52162
  "settings"
51778
52163
  ],
51779
- ["reset", "route"]
52164
+ ["reset", "route", "vaultHostStatus"]
51780
52165
  )) {
51781
52166
  return;
51782
52167
  }
51783
52168
  checkNullableKeysPresent(value, ["reset", "route"], path5, issues);
52169
+ if (present4(value, "vaultHostStatus") && value.vaultHostStatus !== "Served by Thalamus")
52170
+ issues.add(["vaultHostStatus"], "expected the hosted vault status");
51784
52171
  checkVersion(value, path5, issues);
51785
52172
  if (present4(value, "generation")) {
51786
52173
  checkGeneration(value.generation, ["generation"], issues);
@@ -52013,198 +52400,9 @@ var ANTIGRAVITY_RPC_DEFINITION = {
52013
52400
 
52014
52401
  // src/ga/server/auth.ts
52015
52402
  init_dist();
52016
-
52017
- // src/auth-method-labels.ts
52018
- var OPENCODE2_POOL_AUTH_LABEL = "Google (antigravity-auth pool, browser)";
52019
- var OPENCODE2_VAULT_AUTH_LABEL = "Use approved Antigravity vault";
52020
- var OPENCODE2_POOL_RECONNECT_LABEL = "Use existing local Antigravity pool";
52021
-
52022
- // src/ga/server/auth.ts
52023
52403
  init_storage();
52024
52404
  init_vault_custody();
52025
52405
  init_vault_folder();
52026
-
52027
- // src/ga/server/pool-login.ts
52028
- init_dist();
52029
- var GA_POOL_METHOD_ID = "antigravity-auth-pool-browser";
52030
- var GA_POOL_RECONNECT_METHOD_ID = "antigravity-auth-pool-reconnect";
52031
- var LOGIN_FAILED = "The Antigravity pool login could not be completed.";
52032
- function abortable(pending, signal) {
52033
- return new Promise((resolve28, reject) => {
52034
- const abort = () => reject(signal.reason);
52035
- if (signal.aborted) abort();
52036
- else signal.addEventListener("abort", abort, { once: true });
52037
- void pending.then(resolve28, reject).finally(() => {
52038
- signal.removeEventListener("abort", abort);
52039
- });
52040
- });
52041
- }
52042
- function createGaPoolLogin(input2) {
52043
- const shutdown = new AbortController();
52044
- const listeners = /* @__PURE__ */ new Set();
52045
- const pending = /* @__PURE__ */ new Set();
52046
- const track = (work) => {
52047
- pending.add(work);
52048
- void work.then(
52049
- () => pending.delete(work),
52050
- () => pending.delete(work)
52051
- );
52052
- return work;
52053
- };
52054
- const admit2 = async () => {
52055
- try {
52056
- shutdown.signal.throwIfAborted();
52057
- if (!input2.local) throw new Error(LOGIN_FAILED);
52058
- await input2.local.assertAdmission();
52059
- shutdown.signal.throwIfAborted();
52060
- } catch {
52061
- throw new Error(LOGIN_FAILED);
52062
- }
52063
- };
52064
- const close = async (listener) => {
52065
- try {
52066
- await listener.close();
52067
- } finally {
52068
- listeners.delete(listener);
52069
- }
52070
- };
52071
- const method = {
52072
- method: {
52073
- id: GA_POOL_METHOD_ID,
52074
- type: "oauth",
52075
- label: OPENCODE2_POOL_AUTH_LABEL
52076
- },
52077
- authorize: () => track(
52078
- (async () => {
52079
- await admit2();
52080
- const authorization = await (async () => {
52081
- try {
52082
- return await abortable(
52083
- (input2.oauth?.authorize ?? authorizeAntigravity)(),
52084
- shutdown.signal
52085
- );
52086
- } catch {
52087
- throw new Error(LOGIN_FAILED);
52088
- }
52089
- })();
52090
- await admit2();
52091
- const state = new URL(authorization.url).searchParams.get("state");
52092
- if (!state) throw new Error(LOGIN_FAILED);
52093
- let listener;
52094
- let code2;
52095
- const waitForCode = input2.oauth?.waitForCode;
52096
- if (waitForCode) {
52097
- code2 = Promise.resolve().then(() => waitForCode(state));
52098
- } else {
52099
- listener = await startOAuthListener();
52100
- listeners.add(listener);
52101
- code2 = listener.waitForCallback().then((url) => {
52102
- if (url.searchParams.get("state") !== state)
52103
- throw new Error(LOGIN_FAILED);
52104
- const value = url.searchParams.get("code");
52105
- if (!value) throw new Error(LOGIN_FAILED);
52106
- return value;
52107
- });
52108
- }
52109
- void code2.catch(() => {
52110
- });
52111
- try {
52112
- await admit2();
52113
- } catch (error) {
52114
- if (listener) await close(listener);
52115
- throw error;
52116
- }
52117
- const ownedListener = listener;
52118
- const callback = track(
52119
- (async () => {
52120
- try {
52121
- await admit2();
52122
- const value = await abortable(code2, shutdown.signal);
52123
- await admit2();
52124
- const result = await abortable(
52125
- (input2.oauth?.exchange ?? exchangeAntigravity)(value, state, {
52126
- signal: shutdown.signal,
52127
- admit: admit2
52128
- }),
52129
- shutdown.signal
52130
- );
52131
- await admit2();
52132
- if (result.type !== "success") throw new Error(LOGIN_FAILED);
52133
- return result;
52134
- } catch {
52135
- throw new Error(LOGIN_FAILED);
52136
- } finally {
52137
- if (ownedListener) await close(ownedListener);
52138
- }
52139
- })()
52140
- );
52141
- void callback.catch(() => {
52142
- });
52143
- return {
52144
- mode: "auto",
52145
- url: authorization.url,
52146
- instructions: "Complete Google sign-in in your browser.",
52147
- callback
52148
- };
52149
- })()
52150
- )
52151
- };
52152
- return {
52153
- method,
52154
- connectExisting: () => track(
52155
- (async () => {
52156
- let stage = "initial-admission";
52157
- try {
52158
- await admit2();
52159
- if (!input2.local?.assertExistingPool) throw new Error(LOGIN_FAILED);
52160
- stage = "existing-pool-admission";
52161
- await abortable(
52162
- track(input2.local.assertExistingPool(admit2)),
52163
- shutdown.signal
52164
- );
52165
- stage = "final-admission";
52166
- await admit2();
52167
- stage = "placeholder";
52168
- return placeholderCredential({
52169
- integrationID: ANTIGRAVITY_PROVIDER_ID,
52170
- methodID: GA_POOL_RECONNECT_METHOD_ID,
52171
- now: Date.now()
52172
- });
52173
- } catch (error) {
52174
- const busy = error instanceof AccountStoreBusyError;
52175
- try {
52176
- console.warn(
52177
- `[antigravity.pool-login] stage=${stage} reason=${busy ? "store-busy" : "store-refusal"}`
52178
- );
52179
- } catch {
52180
- }
52181
- if (busy) throw new AccountStoreBusyError();
52182
- throw new Error(LOGIN_FAILED);
52183
- }
52184
- })()
52185
- ),
52186
- onLogin: (result) => track(
52187
- (async () => {
52188
- try {
52189
- await admit2();
52190
- await input2.local.persist(result, admit2);
52191
- await admit2();
52192
- } catch (error) {
52193
- if (error instanceof AccountStoreBusyError)
52194
- throw new AccountStoreBusyError();
52195
- throw new Error(LOGIN_FAILED);
52196
- }
52197
- })()
52198
- ),
52199
- async dispose() {
52200
- shutdown.abort(new Error(LOGIN_FAILED));
52201
- await Promise.allSettled([...listeners].map(close));
52202
- while (pending.size) await Promise.allSettled([...pending]);
52203
- }
52204
- };
52205
- }
52206
-
52207
- // src/ga/server/auth.ts
52208
52406
  var GA_VAULT_METHOD_ID = "antigravity-vault";
52209
52407
  async function readAuthority() {
52210
52408
  const folder = currentVaultFolder(getStoragePath());
@@ -52214,10 +52412,23 @@ async function readAuthority() {
52214
52412
  stateDir: folder.vaultDir,
52215
52413
  host: OPENCODE_VAULT_HOST
52216
52414
  });
52217
- return enrollmentAuthority2(paths, OPENCODE_VAULT_ENROLLMENT_NAME, claustrum);
52415
+ return vaultAuthority2(paths, OPENCODE_VAULT_ENROLLMENT_NAME, claustrum);
52218
52416
  }
52219
52417
  async function registerGaAuthMethods(context, authority = readAuthority, input2 = {}) {
52220
- const pool = createGaPoolLogin(input2);
52418
+ const local = input2.local;
52419
+ const pool = createGaPoolLogin({
52420
+ ...input2,
52421
+ ...local ? {
52422
+ local: {
52423
+ ...local,
52424
+ assertAdmission: async () => {
52425
+ if (process.env.CORTEXKIT_VAULT_HOST === "thalamus")
52426
+ throw new Error("Vault authority excludes local sign-in.");
52427
+ await local.assertAdmission();
52428
+ }
52429
+ }
52430
+ } : {}
52431
+ });
52221
52432
  const registrations = [];
52222
52433
  try {
52223
52434
  registrations.push(
@@ -52232,11 +52443,20 @@ async function registerGaAuthMethods(context, authority = readAuthority, input2
52232
52443
  label: OPENCODE2_VAULT_AUTH_LABEL
52233
52444
  },
52234
52445
  async activate() {
52235
- if (await authority() !== "vault") {
52446
+ const current = await authority();
52447
+ if (!["host", "vault"].includes(current)) {
52236
52448
  throw new Error(
52237
52449
  "Approve Antigravity vault access before activating this connection"
52238
52450
  );
52239
52451
  }
52452
+ if (current === "host") {
52453
+ const client = (await loadCommonAuthClaustrum()).connectVaultHost(
52454
+ "antigravity-auth"
52455
+ );
52456
+ await Promise.resolve(client.close()).catch(() => void 0);
52457
+ if (await authority() !== "host")
52458
+ throw new Error("Vault authority changed during activation.");
52459
+ }
52240
52460
  }
52241
52461
  },
52242
52462
  label: "Antigravity"
@@ -52344,10 +52564,10 @@ var BRIDGE_HOST = "127.0.0.1";
52344
52564
  var JOB_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
52345
52565
  var JOB_PATH_PATTERN = /^\/agy\/([^/]+)$/;
52346
52566
  var GA_UNCLAIMED_JOB_TTL_MS = 6e4;
52347
- function isGaGoogleContentRequest(request) {
52348
- if (request.method !== "POST") return false;
52567
+ function isGaGoogleContentRequest(request2) {
52568
+ if (request2.method !== "POST") return false;
52349
52569
  try {
52350
- return GA_GOOGLE_CONTENT_PATH.test(new URL(request.url).pathname);
52570
+ return GA_GOOGLE_CONTENT_PATH.test(new URL(request2.url).pathname);
52351
52571
  } catch {
52352
52572
  return false;
52353
52573
  }
@@ -52463,8 +52683,8 @@ async function startGaLoopbackBridge(options) {
52463
52683
  } catch {
52464
52684
  }
52465
52685
  };
52466
- const server = createServer2((request, response) => {
52467
- const pending = handle(request, response).catch((error) => {
52686
+ const server = createServer2((request2, response) => {
52687
+ const pending = handle(request2, response).catch((error) => {
52468
52688
  report(`bridge request failed: ${errorMessage(error)}`);
52469
52689
  if (!response.headersSent) {
52470
52690
  writeResponseHead(response, 500, "application/json");
@@ -52480,15 +52700,15 @@ async function startGaLoopbackBridge(options) {
52480
52700
  sockets.add(socket);
52481
52701
  socket.once("close", () => sockets.delete(socket));
52482
52702
  });
52483
- const handle = async (request, response) => {
52703
+ const handle = async (request2, response) => {
52484
52704
  const match = JOB_PATH_PATTERN.exec(
52485
- new URL(request.url ?? "/", "http://bridge").pathname
52705
+ new URL(request2.url ?? "/", "http://bridge").pathname
52486
52706
  );
52487
52707
  const candidate = match?.[1];
52488
52708
  const id = candidate !== void 0 && isGaJobId(candidate) ? candidate : null;
52489
52709
  const entry = id ? queued.get(id) : void 0;
52490
- request.resume();
52491
- if (request.method !== "POST" || !id || !entry || closing) {
52710
+ request2.resume();
52711
+ if (request2.method !== "POST" || !id || !entry || closing) {
52492
52712
  writeResponseHead(response, 404, "application/json");
52493
52713
  response.end(JSON.stringify({ error: { message: "unknown job" } }));
52494
52714
  return;
@@ -52587,10 +52807,10 @@ async function startGaLoopbackBridge(options) {
52587
52807
  signal: original.signal
52588
52808
  });
52589
52809
  },
52590
- adaptResponse(request, response) {
52810
+ adaptResponse(request2, response) {
52591
52811
  let url;
52592
52812
  try {
52593
- url = new URL(request.url);
52813
+ url = new URL(request2.url);
52594
52814
  } catch {
52595
52815
  return null;
52596
52816
  }
@@ -52947,23 +53167,23 @@ function createGaRpcActivation(options) {
52947
53167
  const parsed = AntigravityStateInputSchema.parse(input2);
52948
53168
  if (!parsed.ok) throw new GaRpcInputError(parsed.issues);
52949
53169
  if (disposed) return disposedOutput();
52950
- const request = parsed.value;
53170
+ const request2 = parsed.value;
52951
53171
  const read = await track(
52952
53172
  signal,
52953
- (readSignal) => options.state.read({ scope: request.scope, signal: readSignal })
53173
+ (readSignal) => options.state.read({ scope: request2.scope, signal: readSignal })
52954
53174
  );
52955
53175
  if (disposed) return disposedOutput();
52956
53176
  if (!Number.isSafeInteger(read.readSeq) || read.readSeq <= lastReadSeq) {
52957
53177
  throw new GaRpcContractError("State source returned a stale readSeq");
52958
53178
  }
52959
53179
  lastReadSeq = read.readSeq;
52960
- const queue2 = queueFor(request.scope);
53180
+ const queue2 = queueFor(request2.scope);
52961
53181
  queue2.lastPullAt = now();
52962
53182
  let reset = null;
52963
- if (request.generation === null) reset = "initial";
52964
- else if (request.generation !== generation) reset = "generation-changed";
52965
- else if (request.cursor > queue2.lastIssued) reset = "cursor-ahead";
52966
- const acknowledged = reset === null ? request.cursor : 0;
53183
+ if (request2.generation === null) reset = "initial";
53184
+ else if (request2.generation !== generation) reset = "generation-changed";
53185
+ else if (request2.cursor > queue2.lastIssued) reset = "cursor-ahead";
53186
+ const acknowledged = reset === null ? request2.cursor : 0;
52967
53187
  queue2.notifications = queue2.notifications.filter(
52968
53188
  (notification) => notification.cursor > acknowledged
52969
53189
  );
@@ -52973,11 +53193,13 @@ function createGaRpcActivation(options) {
52973
53193
  );
52974
53194
  const last = delivered.at(-1);
52975
53195
  const cursor = last ? last.cursor : Math.max(acknowledged, queue2.evictedThrough);
53196
+ const claustrum = await loadCommonAuthClaustrum();
52976
53197
  const output2 = {
53198
+ ...process.env.CORTEXKIT_VAULT_HOST === "thalamus" ? { vaultHostStatus: claustrum.VAULT_HOST_STATUS } : {},
52977
53199
  version: ANTIGRAVITY_RPC_VERSION,
52978
53200
  kind: "snapshot",
52979
53201
  generation,
52980
- scope: request.scope,
53202
+ scope: request2.scope,
52981
53203
  reset,
52982
53204
  cursor,
52983
53205
  dropped: Math.max(0, queue2.evictedThrough - acknowledged),
@@ -52985,7 +53207,7 @@ function createGaRpcActivation(options) {
52985
53207
  notifications: delivered,
52986
53208
  readSeq: read.readSeq,
52987
53209
  ...accountsDto(read.accounts),
52988
- route: request.scope.kind === "session" ? routeDto(read.route) : null,
53210
+ route: request2.scope.kind === "session" ? routeDto(read.route) : null,
52989
53211
  status: read.status,
52990
53212
  settings: read.settings
52991
53213
  };
@@ -52999,8 +53221,8 @@ function createGaRpcActivation(options) {
52999
53221
  const parsed = AntigravityApplyInputSchema.parse(input2);
53000
53222
  if (!parsed.ok) throw new GaRpcInputError(parsed.issues);
53001
53223
  if (disposed) return disposedOutput();
53002
- const request = parsed.value;
53003
- if (request.generation !== generation) {
53224
+ const request2 = parsed.value;
53225
+ if (request2.generation !== generation) {
53004
53226
  return {
53005
53227
  version: ANTIGRAVITY_RPC_VERSION,
53006
53228
  kind: "stale-generation",
@@ -53008,8 +53230,8 @@ function createGaRpcActivation(options) {
53008
53230
  };
53009
53231
  }
53010
53232
  const menuRequest = options.parseApplyRequest({
53011
- ...request.request,
53012
- ...request.scope.kind === "session" ? { sessionId: request.scope.sessionID } : {}
53233
+ ...request2.request,
53234
+ ...request2.scope.kind === "session" ? { sessionId: request2.scope.sessionID } : {}
53013
53235
  });
53014
53236
  if (!menuRequest) {
53015
53237
  throw new GaRpcInputError([
@@ -53020,7 +53242,7 @@ function createGaRpcActivation(options) {
53020
53242
  signal,
53021
53243
  (applySignal) => options.commands.apply({
53022
53244
  request: menuRequest,
53023
- scope: request.scope,
53245
+ scope: request2.scope,
53024
53246
  signal: applySignal
53025
53247
  })
53026
53248
  );
@@ -53035,7 +53257,7 @@ function createGaRpcActivation(options) {
53035
53257
  version: ANTIGRAVITY_RPC_VERSION,
53036
53258
  kind: "applied",
53037
53259
  generation,
53038
- scope: request.scope,
53260
+ scope: request2.scope,
53039
53261
  result
53040
53262
  };
53041
53263
  if (!AntigravityApplyOutputSchema.parse(output2).ok) {
@@ -53213,9 +53435,9 @@ function stderrLogSink(record3) {
53213
53435
  } catch {
53214
53436
  }
53215
53437
  }
53216
- function headerValue(request, names) {
53438
+ function headerValue(request2, names) {
53217
53439
  for (const name of names) {
53218
- const value = request.headers.get(name);
53440
+ const value = request2.headers.get(name);
53219
53441
  if (value) return value;
53220
53442
  }
53221
53443
  return null;
@@ -53273,7 +53495,7 @@ async function setupGaActivation(context, factory, overrides = {}) {
53273
53495
  read: (input2) => requireServing().state.read(input2)
53274
53496
  },
53275
53497
  commands: {
53276
- apply: (request) => requireServing().commands.apply(request)
53498
+ apply: (request2) => requireServing().commands.apply(request2)
53277
53499
  },
53278
53500
  parseApplyRequest: commandsModule.parseApplyRequest,
53279
53501
  onChanged: (event) => {
@@ -53327,8 +53549,8 @@ async function setupGaActivation(context, factory, overrides = {}) {
53327
53549
  "producer"
53328
53550
  );
53329
53551
  const handlers = {
53330
- state: (input2, call) => activation.handlers.state(input2, call.signal),
53331
- apply: (input2, call) => activation.handlers.apply(input2, call.signal)
53552
+ state: (input2, call2) => activation.handlers.state(input2, call2.signal),
53553
+ apply: (input2, call2) => activation.handlers.apply(input2, call2.signal)
53332
53554
  };
53333
53555
  rpcRegistration = await context.rpc.register(
53334
53556
  ANTIGRAVITY_RPC_DEFINITION,
@@ -53442,11 +53664,11 @@ function callbackParams(callbackUrl, expected) {
53442
53664
  if (expected && state !== expected) throw new Error("OAuth state mismatch");
53443
53665
  return { code: code2, state };
53444
53666
  }
53445
- async function performOAuthLogin(request, deps) {
53667
+ async function performOAuthLogin(request2, deps) {
53446
53668
  const listener = await deps.startListener();
53447
53669
  try {
53448
- const authorization = await deps.authorize(request.projectId ?? "");
53449
- if (!request.noBrowser && !request.isHeadless) {
53670
+ const authorization = await deps.authorize(request2.projectId ?? "");
53671
+ if (!request2.noBrowser && !request2.isHeadless) {
53450
53672
  await deps.openBrowser(authorization.url);
53451
53673
  }
53452
53674
  const params = callbackParams(
@@ -53456,7 +53678,7 @@ async function performOAuthLogin(request, deps) {
53456
53678
  const result = await deps.exchange(params.code, params.state);
53457
53679
  if (result.type === "failed") throw new Error(result.error);
53458
53680
  await deps.upsert(result);
53459
- request.accounts.push(result);
53681
+ request2.accounts.push(result);
53460
53682
  return result;
53461
53683
  } finally {
53462
53684
  await listener.close().catch(() => {
@@ -53716,7 +53938,7 @@ import { createHash as createHash19, randomBytes as randomBytes6, randomUUID as
53716
53938
  import { constants as fsConstants2 } from "node:fs";
53717
53939
  import { chmod as chmod6, mkdir as mkdir15, open as open10, readFile as readFile14, realpath as realpath4, rename as rename12, stat as stat14, unlink as unlink11 } from "node:fs/promises";
53718
53940
  import { basename as basename6, dirname as dirname22, extname as extname2, isAbsolute as isAbsolute4, join as join26, resolve as resolve22 } from "node:path";
53719
- import { ClaustrumCredentialError as ClaustrumCredentialError6, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
53941
+ import { ClaustrumCredentialError as ClaustrumCredentialError9, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
53720
53942
 
53721
53943
  // src/common-auth-embedded/fs/file-read-cache.js
53722
53944
  import { lstat as lstat7, stat as stat12 } from "node:fs/promises";
@@ -54643,6 +54865,90 @@ var ClaustrumConsumerError2 = class extends Error {
54643
54865
  }
54644
54866
  };
54645
54867
 
54868
+ // src/common-auth-embedded/claustrum/host.js
54869
+ import { ClaustrumCredentialError as ClaustrumCredentialError8 } from "@cortexkit/claustrum-client";
54870
+
54871
+ // src/common-auth-embedded/claustrum/availability.js
54872
+ import { ClaustrumCredentialError as ClaustrumCredentialError7 } from "@cortexkit/claustrum-client";
54873
+ import { SocketClosedError as SocketClosedError2, SocketTimeoutError as SocketTimeoutError2, SubcCallError as SubcCallError2 } from "@cortexkit/subc-client";
54874
+ var VAULT_FAILURE_CLASSES2 = Object.freeze({
54875
+ ECONNREFUSED: "unreachable",
54876
+ ENOENT: "unreachable",
54877
+ ECONNRESET: "unreachable",
54878
+ EPIPE: "unreachable",
54879
+ ETIMEDOUT: "unreachable",
54880
+ transport_error: "unreachable",
54881
+ unavailable: "unreachable",
54882
+ timeout: "unreachable",
54883
+ route_closed: "unreachable",
54884
+ daemon_draining: "unreachable",
54885
+ connection_closed: "unreachable",
54886
+ connection_dropped: "unreachable",
54887
+ request_deadline: "unreachable",
54888
+ deadline_exceeded_no_drop_observed: "unreachable",
54889
+ module_reloading: "unreachable",
54890
+ module_warming: "unreachable",
54891
+ target_unavailable: "unreachable",
54892
+ module_timeout: "unreachable",
54893
+ invalid_response: "answered",
54894
+ invalid_record_version: "answered",
54895
+ invalid_expiry: "answered",
54896
+ invalid_status: "answered",
54897
+ invalid_params: "answered",
54898
+ ttl_unsatisfiable: "answered",
54899
+ not_found: "answered",
54900
+ enrollment_revoked: "answered",
54901
+ enrollment_invalid: "answered",
54902
+ grant_denied: "answered",
54903
+ credential_unavailable: "answered",
54904
+ needs_reauth: "answered",
54905
+ declined: "answered",
54906
+ disabled: "answered",
54907
+ identity_changed: "answered",
54908
+ closed: "answered",
54909
+ client_closed: "answered",
54910
+ pending_exists: "answered",
54911
+ pending_queue_full: "answered",
54912
+ already_consumed: "answered",
54913
+ superseded: "answered",
54914
+ stale_generation: "answered",
54915
+ missing_identity: "answered",
54916
+ invalid_control_body: "answered",
54917
+ unknown_module: "answered",
54918
+ module_removed: "answered",
54919
+ capability_denied: "answered",
54920
+ unknown_channel: "unreachable",
54921
+ stale_route_epoch: "unreachable",
54922
+ capability_forbidden: "answered",
54923
+ capability_unprovided: "answered",
54924
+ capability_ambiguous: "answered",
54925
+ invalid_capability_identifier: "answered",
54926
+ binary_body_required: "answered",
54927
+ binary_call_requires_call_binary: "answered",
54928
+ corr_exhausted: "answered",
54929
+ late_route_cleanup_failed: "answered",
54930
+ reverse_request_capability_not_declared: "answered",
54931
+ stale_route_handle: "answered",
54932
+ reverse_request_unhandled: "answered",
54933
+ handler_error: "answered",
54934
+ health_error: "answered",
54935
+ duplicate_module_id: "answered",
54936
+ route_rejected: "answered",
54937
+ lock_busy: "answered",
54938
+ owner_invalid: "answered",
54939
+ renewal_failed: "answered",
54940
+ unsupported_platform: "answered",
54941
+ EACCES: "answered",
54942
+ EPERM: "answered",
54943
+ ERR_PRIVATE_FILES_SECURITY: "answered"
54944
+ });
54945
+
54946
+ // src/common-auth-embedded/claustrum/host.js
54947
+ var VAULT_HOST_CONNECT_REFUSAL2 = "This host gets its vault accounts from Thalamus, so it can't connect to the vault itself.";
54948
+ function hasVaultHost2() {
54949
+ return process.env.CORTEXKIT_VAULT_HOST === "thalamus";
54950
+ }
54951
+
54646
54952
  // src/common-auth-embedded/claustrum/enrollment.js
54647
54953
  var ENROLLMENT_SCHEMA2 = 1;
54648
54954
  var ENROLLMENT_FILE_MAX_BYTES2 = 16 * 1024;
@@ -54666,7 +54972,7 @@ var RETRYABLE_ENROLLMENT_CODES2 = /* @__PURE__ */ new Set([
54666
54972
  "pending_queue_full"
54667
54973
  ]);
54668
54974
  function classifyEnrollmentError2(error) {
54669
- if (!(error instanceof ClaustrumCredentialError6))
54975
+ if (!(error instanceof ClaustrumCredentialError9))
54670
54976
  return void 0;
54671
54977
  if (TERMINAL_ENROLLMENT_CODES2.has(error.code))
54672
54978
  return { code: error.code, disposition: "terminal" };
@@ -54990,7 +55296,7 @@ async function readEnrollmentStatus2(paths, proposedName) {
54990
55296
  }
54991
55297
  return { status: statusFromState2(state), usesProposedName: false };
54992
55298
  }
54993
- async function enrollmentAuthority3(paths, proposedName) {
55299
+ async function enrollmentAuthority2(paths, proposedName) {
54994
55300
  let status;
54995
55301
  try {
54996
55302
  status = await readClaustrumEnrollmentStatus2(paths, proposedName);
@@ -55015,6 +55321,11 @@ async function enrollmentAuthority3(paths, proposedName) {
55015
55321
  }
55016
55322
  return "local";
55017
55323
  }
55324
+ async function vaultAuthority3(paths, proposedName) {
55325
+ if (hasVaultHost2())
55326
+ return "host";
55327
+ return enrollmentAuthority2(paths, proposedName);
55328
+ }
55018
55329
  function statusFromState2(state) {
55019
55330
  if (state.phase === "pending") {
55020
55331
  return {
@@ -55983,6 +56294,8 @@ function approveCommand(requestId, name) {
55983
56294
  return `ck auth enroll approve --request-id ${requestId} --name ${name}`;
55984
56295
  }
55985
56296
  async function connectSetupHost(plugin2, host, io, terminal, fence) {
56297
+ if (hasVaultHost2())
56298
+ throw new Error(VAULT_HOST_CONNECT_REFUSAL2);
55986
56299
  const { name, paths: input2 } = plugin2.vault.hosts[host];
55987
56300
  const paths = hostEnrollmentPaths2(input2);
55988
56301
  await fence();
@@ -56466,8 +56779,8 @@ async function enrollmentReport(plugin2, hosts, recorded) {
56466
56779
  let outcome = recorded.get(host) ?? "not-enrolled";
56467
56780
  if (outcome === "unknown") {
56468
56781
  const { name, paths } = plugin2.vault.hosts[host];
56469
- const authority = await enrollmentAuthority3(hostEnrollmentPaths2(paths), name).catch(() => "unreadable");
56470
- if (authority === "vault")
56782
+ const authority = await vaultAuthority3(hostEnrollmentPaths2(paths), name).catch(() => "unreadable");
56783
+ if (authority === "vault" || authority === "host")
56471
56784
  outcome = "enrolled";
56472
56785
  else if (authority === "local")
56473
56786
  outcome = "not-enrolled";
@@ -56478,6 +56791,8 @@ async function enrollmentReport(plugin2, hosts, recorded) {
56478
56791
  }
56479
56792
  async function runSetup(plugin2, argv = [], io = {}) {
56480
56793
  const options = parseSetupFlags(argv);
56794
+ if (hasVaultHost2())
56795
+ throw new Error(VAULT_HOST_CONNECT_REFUSAL2);
56481
56796
  validatePlugin(plugin2);
56482
56797
  const terminal = io.terminal ?? processTerminal2();
56483
56798
  const detection = await detectHosts(plugin2, io);
@@ -56676,7 +56991,7 @@ function createV1VaultActivationMethod(input2) {
56676
56991
  instructions: "Vault access is approved. Activate it without signing in to Google.",
56677
56992
  callback: async () => {
56678
56993
  try {
56679
- if (await input2.readAuthority() !== "vault")
56994
+ if (!["host", "vault"].includes(await input2.readAuthority()))
56680
56995
  return { type: "failed" };
56681
56996
  try {
56682
56997
  const value = JSON.parse(
@@ -56692,8 +57007,14 @@ function createV1VaultActivationMethod(input2) {
56692
57007
  return { type: "failed" };
56693
57008
  }
56694
57009
  const claustrum = await loadCommonAuthClaustrum();
56695
- if (await input2.readAuthority() !== "vault")
56696
- return { type: "failed" };
57010
+ const current = await input2.readAuthority();
57011
+ if (!["host", "vault"].includes(current)) return { type: "failed" };
57012
+ if (current === "host") {
57013
+ const client = claustrum.connectVaultHost("antigravity-auth");
57014
+ await Promise.resolve(client.close()).catch(() => void 0);
57015
+ if (await input2.readAuthority() !== "host")
57016
+ return { type: "failed" };
57017
+ }
56697
57018
  return {
56698
57019
  ...claustrum.custodyPlaceholder(input2.providerId),
56699
57020
  type: "success"
@@ -56750,7 +57071,7 @@ async function readNativeAuth(path5) {
56750
57071
  }
56751
57072
  async function assertLocalOpenCodeLogin(legacyPath, generation) {
56752
57073
  const claustrum = await loadCommonAuthClaustrum();
56753
- if (await claustrum.enrollmentAuthority(
57074
+ if (await claustrum.vaultAuthority(
56754
57075
  claustrum.hostEnrollmentPaths({
56755
57076
  stateDir: openCodeVaultDir(legacyPath),
56756
57077
  host: "opencode"
@@ -56783,7 +57104,7 @@ async function writeNativeSlot(host, slot, context, expectedAuthority = "local")
56783
57104
  await assertSetupHostsStopped();
56784
57105
  const claustrum = await loadCommonAuthClaustrum();
56785
57106
  const stateDir = host === "opencode" ? openCodeVaultDir(resolve23(accountFileForVault())) : getPiAntigravityVaultDir();
56786
- if (await claustrum.enrollmentAuthority(
57107
+ if (await claustrum.vaultAuthority(
56787
57108
  claustrum.hostEnrollmentPaths({ stateDir, host }),
56788
57109
  `antigravity-auth-${host}`
56789
57110
  ) !== expectedAuthority)
@@ -56830,7 +57151,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
56830
57151
  paths: { stateDir: piDir, host: "pi" }
56831
57152
  }
56832
57153
  };
56833
- const authority = (host) => claustrum.enrollmentAuthority(
57154
+ const authority = (host) => claustrum.vaultAuthority(
56834
57155
  claustrum.hostEnrollmentPaths(hosts[host].paths),
56835
57156
  hosts[host].name
56836
57157
  );
@@ -56996,7 +57317,7 @@ Setup has not completed the OpenCode 2 native Google connection.
56996
57317
  );
56997
57318
  return;
56998
57319
  }
56999
- if (await authority(host) !== "vault")
57320
+ if (!["host", "vault"].includes(await authority(host)))
57000
57321
  throw new Error("Vault access must be approved before activation.");
57001
57322
  if (host === "opencode") {
57002
57323
  if (context.opencodeGeneration === "2") {
@@ -57029,7 +57350,7 @@ Setup has not completed the OpenCode 2 native Google connection.
57029
57350
  },
57030
57351
  migrate: async (host, context) => {
57031
57352
  if (context.mode === "local") await assertLocal(host, context);
57032
- else if (await authority(host) !== "vault")
57353
+ else if (!["host", "vault"].includes(await authority(host)))
57033
57354
  throw new Error("Vault access must remain approved during setup.");
57034
57355
  if (host === "opencode") {
57035
57356
  const current = await authority(host);
@@ -57095,6 +57416,9 @@ Setup has not completed the OpenCode 2 native Google connection.
57095
57416
  };
57096
57417
  }
57097
57418
  async function runPluginSetup(argv, deps, migrateOpenCode, io = {}) {
57419
+ const claustrum = await loadCommonAuthClaustrum();
57420
+ if (process.env.CORTEXKIT_VAULT_HOST === "thalamus")
57421
+ throw new Error(claustrum.VAULT_HOST_CONNECT_REFUSAL);
57098
57422
  const plugin2 = await createSetupPlugin(
57099
57423
  deps,
57100
57424
  migrateOpenCode,
@@ -57533,7 +57857,7 @@ function createDefaultCliDependencies() {
57533
57857
  isHeadless: () => Boolean(
57534
57858
  process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY || process.env.OPENCODE_HEADLESS
57535
57859
  ),
57536
- performLogin: async (request, openBrowser, host, context) => {
57860
+ performLogin: async (request2, openBrowser, host, context) => {
57537
57861
  if (host === "pi" && !context)
57538
57862
  throw new Error(
57539
57863
  "Pi setup requires its detected native agent directory."
@@ -57548,7 +57872,7 @@ function createDefaultCliDependencies() {
57548
57872
  context?.opencodeGeneration
57549
57873
  );
57550
57874
  try {
57551
- return await performOAuthLogin(request, {
57875
+ return await performOAuthLogin(request2, {
57552
57876
  authorize: authorizeAntigravity,
57553
57877
  exchange: exchangeAntigravity,
57554
57878
  startListener: startOAuthListener,
@@ -57566,7 +57890,7 @@ function createDefaultCliDependencies() {
57566
57890
  await persistCliStoreLogin(
57567
57891
  repository,
57568
57892
  result,
57569
- request.startFresh && request.accounts.length === 0
57893
+ request2.startFresh && request2.accounts.length === 0
57570
57894
  );
57571
57895
  }
57572
57896
  });
@@ -58726,11 +59050,11 @@ async function startRpcServer2(options) {
58726
59050
  throw new TypeError("startRpcServer needs this plugin's package version");
58727
59051
  }
58728
59052
  const parseApply = (value) => {
58729
- const request = options.parseApplyRequest(value);
58730
- if (request === void 0) {
59053
+ const request2 = options.parseApplyRequest(value);
59054
+ if (request2 === void 0) {
58731
59055
  throw new RpcRequestError(400, "Invalid apply request");
58732
59056
  }
58733
- return request;
59057
+ return request2;
58734
59058
  };
58735
59059
  const server = await startRpcServer({
58736
59060
  dir: options.dir,
@@ -58742,7 +59066,7 @@ async function startRpcServer2(options) {
58742
59066
  applyDeadlineMs: 12e4,
58743
59067
  timeoutMs: 0,
58744
59068
  parsePending,
58745
- apply: (async (request) => options.apply(parseApply(request))),
59069
+ apply: (async (request2) => options.apply(parseApply(request2))),
58746
59070
  // Use only the asynchronous overload, including for synchronous producers.
58747
59071
  drainAsync: (async (cursor, session) => Promise.resolve(
58748
59072
  options.drain(cursor, session)
@@ -61892,7 +62216,7 @@ function createAuthLoader({
61892
62216
  const authority = await readAuthority2?.() ?? "local";
61893
62217
  assertOpen();
61894
62218
  if (authority === "unreadable") throw new Error(unavailableMessage);
61895
- if (authority === "vault") {
62219
+ if (authority === "vault" || authority === "host") {
61896
62220
  currentRequestSource = "vault";
61897
62221
  if (!createVaultFetch) throw new Error(unavailableMessage);
61898
62222
  vaultFetchRuntime ??= createVaultFetch().catch((error) => {
@@ -62057,7 +62381,7 @@ var HANDLED_COMMAND_SENTINEL = "ANTIGRAVITY_COMMAND_HANDLED";
62057
62381
  async function sendIgnoredMessage(client, sessionID, text2) {
62058
62382
  const session = client.session;
62059
62383
  const promptContext = await resolvePromptContext(client, sessionID);
62060
- const request = {
62384
+ const request2 = {
62061
62385
  path: { id: sessionID },
62062
62386
  body: {
62063
62387
  noReply: true,
@@ -62068,11 +62392,11 @@ async function sendIgnoredMessage(client, sessionID, text2) {
62068
62392
  }
62069
62393
  };
62070
62394
  if (typeof session?.promptAsync === "function") {
62071
- await session.promptAsync(request);
62395
+ await session.promptAsync(request2);
62072
62396
  return;
62073
62397
  }
62074
62398
  if (typeof session?.prompt === "function") {
62075
- await Promise.resolve(session.prompt(request));
62399
+ await Promise.resolve(session.prompt(request2));
62076
62400
  return;
62077
62401
  }
62078
62402
  throw new Error(
@@ -63163,7 +63487,7 @@ function createSourceSidebarPublisher(options) {
63163
63487
  const authority = await options.readAuthority();
63164
63488
  let projection;
63165
63489
  if (authority === "local") projection = await options.local();
63166
- else if (authority === "vault") {
63490
+ else if (authority === "vault" || authority === "host") {
63167
63491
  try {
63168
63492
  projection = await options.vault();
63169
63493
  } catch {
@@ -63275,7 +63599,8 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
63275
63599
  // which decides whether its served credential needs replacement.
63276
63600
  reporterSource: "direct",
63277
63601
  onAuthorityChanged: (authority) => {
63278
- if (authority !== "vault") vaultQuotaPoller?.abortTick();
63602
+ if (authority !== "vault" && authority !== "host")
63603
+ vaultQuotaPoller?.abortTick();
63279
63604
  scheduleSidebarPublication();
63280
63605
  },
63281
63606
  onRosterChanged: () => scheduleSidebarPublication()
@@ -63308,11 +63633,11 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
63308
63633
  // the caller injected a mock transport.
63309
63634
  fetchVia: dependencies.agyTransport,
63310
63635
  mayRun: mayRunLocalAccounts,
63311
- fetchStoreAccountQuota: async (account, request) => {
63636
+ fetchStoreAccountQuota: async (account, request2) => {
63312
63637
  const service = await currentStoreQuota();
63313
63638
  if (!service)
63314
63639
  throw new Error("The current store quota service is unavailable");
63315
- return service.fetchAccountQuota(account, request);
63640
+ return service.fetchAccountQuota(account, request2);
63316
63641
  },
63317
63642
  // Bind to the live AccountManager so every refresh (manual or
63318
63643
  // background) pushes the freshly-updated quota percentages into the
@@ -63749,7 +64074,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
63749
64074
  const { source, pool } = await currentVaultPool();
63750
64075
  return createVaultFetchInterceptor({
63751
64076
  assertAdmission: async () => {
63752
- if (await readAuthority2() !== "vault")
64077
+ if (!["host", "vault"].includes(await readAuthority2()))
63753
64078
  throw new Error(unavailableMessage);
63754
64079
  },
63755
64080
  client,
@@ -63863,11 +64188,11 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
63863
64188
  dir: getRpcDir(directory),
63864
64189
  parseApplyRequest: commandsModule.parseApplyRequest,
63865
64190
  version: await pluginPackageVersion(),
63866
- apply: async (request) => {
64191
+ apply: async (request2) => {
63867
64192
  const current = await currentMenu();
63868
64193
  if (current.kind === "unavailable") throw new Error(current.message);
63869
- const invocation = menuInvocation(pushNotification, request.sessionId);
63870
- const result = await current.menu.apply(request, invocation);
64194
+ const invocation = menuInvocation(pushNotification, request2.sessionId);
64195
+ const result = await current.menu.apply(request2, invocation);
63871
64196
  try {
63872
64197
  if (await readAuthority2() === "local")
63873
64198
  await lifecycle.getAccountManager()?.refreshFromRepository();
@@ -63881,7 +64206,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
63881
64206
  kind: "warning"
63882
64207
  }
63883
64208
  },
63884
- request.sessionId
64209
+ request2.sessionId
63885
64210
  );
63886
64211
  }
63887
64212
  const refreshed = await currentMenu();