@cortexkit/opencode-antigravity-auth 3.0.10 → 3.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/cli.js +319 -111
  2. package/dist/cli.js.map +3 -3
  3. package/dist/cli.meta.json +48 -23
  4. package/dist/index.js +457 -211
  5. package/dist/index.js.map +3 -3
  6. package/dist/index.meta.json +55 -30
  7. package/dist/server.js +457 -211
  8. package/dist/server.js.map +3 -3
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +5 -0
  11. package/dist/src/common-auth-embedded/claustrum/enrollment.js +27 -0
  12. package/dist/src/common-auth-embedded/fs/private-files.d.ts +2 -0
  13. package/dist/src/common-auth-embedded/fs/private-files.js +49 -3
  14. package/dist/src/common-auth-embedded/setup/enroll.d.ts +34 -0
  15. package/dist/src/common-auth-embedded/setup/enroll.js +116 -34
  16. package/dist/src/common-auth-embedded/setup/index.d.ts +1 -0
  17. package/dist/src/common-auth-embedded/setup/index.js +1 -0
  18. package/dist/src/common-auth-embedded/setup/process-fence.d.ts +7 -0
  19. package/dist/src/common-auth-embedded/setup/process-fence.js +56 -1
  20. package/dist/src/common-auth-embedded/setup/types.d.ts +5 -0
  21. package/dist/src/common-auth-embedded/source-output.json +45 -37
  22. package/dist/src/plugin/lifecycle.d.ts.map +1 -1
  23. package/dist/src/plugin/lifecycle.js +48 -27
  24. package/dist/src/plugin/lifecycle.js.map +1 -1
  25. package/dist/src/plugin/shared/request-services.js +2 -2
  26. package/dist/src/plugin/shared/request-services.js.map +1 -1
  27. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  28. package/dist/src/plugin/vault-custody.js +13 -3
  29. package/dist/src/plugin/vault-custody.js.map +1 -1
  30. package/dist/tui-build-map.json +5 -5
  31. package/dist/tui-ga-build-map.json +1 -1
  32. package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +5 -0
  33. package/dist/types/src/common-auth-embedded/setup/enroll.d.ts +34 -0
  34. package/dist/types/src/common-auth-embedded/setup/index.d.ts +1 -0
  35. package/dist/types/src/common-auth-embedded/setup/process-fence.d.ts +7 -0
  36. package/dist/types/src/common-auth-embedded/setup/types.d.ts +5 -0
  37. package/dist/types/src/plugin/lifecycle.d.ts.map +1 -1
  38. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  39. package/package.json +2 -2
  40. package/src/common-auth-embedded/claustrum/enrollment.d.ts +5 -0
  41. package/src/common-auth-embedded/claustrum/enrollment.js +27 -0
  42. package/src/common-auth-embedded/fs/private-files.d.ts +2 -0
  43. package/src/common-auth-embedded/fs/private-files.js +49 -3
  44. package/src/common-auth-embedded/setup/enroll.d.ts +34 -0
  45. package/src/common-auth-embedded/setup/enroll.js +116 -34
  46. package/src/common-auth-embedded/setup/index.d.ts +1 -0
  47. package/src/common-auth-embedded/setup/index.js +1 -0
  48. package/src/common-auth-embedded/setup/process-fence.d.ts +7 -0
  49. package/src/common-auth-embedded/setup/process-fence.js +56 -1
  50. package/src/common-auth-embedded/setup/types.d.ts +5 -0
  51. package/src/common-auth-embedded/source-output.json +45 -37
  52. package/src/tui-compiled/common-auth-embedded/fs/private-files.js +49 -3
  53. package/src/tui-raw/common-auth-embedded/fs/private-files.js +49 -3
package/dist/cli.js CHANGED
@@ -765,7 +765,8 @@ var init_identity = __esm({
765
765
  // ../core/dist/common-auth-embedded/fs/private-files.js
766
766
  import { randomUUID as randomUUID5 } from "node:crypto";
767
767
  import { lstat as lstat2, readFile as readFile4, rename as rename3, unlink as unlink5 } from "node:fs/promises";
768
- import { dirname as dirname5, resolve as resolve2 } from "node:path";
768
+ import { tmpdir } from "node:os";
769
+ import { dirname as dirname5, join as join4, resolve as resolve2 } from "node:path";
769
770
  function ioCode(detail) {
770
771
  if (detail?.reason === "io-error") {
771
772
  if (detail.win32Code === 2 || detail.win32Code === 3)
@@ -775,8 +776,31 @@ function ioCode(detail) {
775
776
  }
776
777
  return detail?.code ?? "ERR_PRIVATE_FILE";
777
778
  }
779
+ function privateFilesUnavailable(cause) {
780
+ return Object.assign(new Error("Windows private-files native addon is unavailable", { cause }), {
781
+ code: "ERR_PRIVATE_FILES_UNAVAILABLE",
782
+ reason: PRIVATE_FILES_UNAVAILABLE_REASON
783
+ });
784
+ }
785
+ function isUnavailable(api, error) {
786
+ return error instanceof api.PrivateFilesUnavailableError || error?.code === "ERR_PRIVATE_FILES_UNAVAILABLE";
787
+ }
788
+ async function assertNativeAddonLoads(api) {
789
+ try {
790
+ await api.verifyPrivatePath(join4(tmpdir(), `.common-auth-private-files-probe-${randomUUID5()}`), "file");
791
+ } catch (error) {
792
+ if (isUnavailable(api, error))
793
+ throw privateFilesUnavailable(error);
794
+ }
795
+ }
778
796
  function loadBackend() {
779
- backend ??= import("@cortexkit/private-files");
797
+ backend ??= import("@cortexkit/private-files").then(async (api) => {
798
+ if (windowsPrivateFiles)
799
+ await assertNativeAddonLoads(api);
800
+ return api;
801
+ }, (cause) => {
802
+ throw windowsPrivateFiles ? privateFilesUnavailable(cause) : cause;
803
+ });
780
804
  return backend;
781
805
  }
782
806
  async function privateOperation(path2, stage, operation) {
@@ -1002,12 +1026,13 @@ async function writePrivateAtomic(path2, bytes, options = {}) {
1002
1026
  });
1003
1027
  }
1004
1028
  }
1005
- var windowsPrivateFiles, migrationNotices, backend, PrivateFileError, safeParentOptionsForTest;
1029
+ var windowsPrivateFiles, migrationNotices, backend, PRIVATE_FILES_UNAVAILABLE_REASON, PrivateFileError, safeParentOptionsForTest;
1006
1030
  var init_private_files = __esm({
1007
1031
  "../core/dist/common-auth-embedded/fs/private-files.js"() {
1008
1032
  "use strict";
1009
1033
  windowsPrivateFiles = process.platform === "win32";
1010
1034
  migrationNotices = /* @__PURE__ */ new Set();
1035
+ PRIVATE_FILES_UNAVAILABLE_REASON = "native-addon-unavailable";
1011
1036
  PrivateFileError = class extends Error {
1012
1037
  path;
1013
1038
  stage;
@@ -1022,7 +1047,7 @@ var init_private_files = __esm({
1022
1047
  orphanPath;
1023
1048
  constructor(path2, stage, cause) {
1024
1049
  const detail = cause;
1025
- super(`Private file refused at ${stage}: ${path2} (${detail?.reason ?? detail?.code ?? "io-error"}). Use a safe parent directory. Repair only a named secret file in safe ancestry whose owner the published policy trusts, without changing its owner or any existing directory. Previously exposed credentials may need rotation. Windows requires the private-files native prebuild and an ACL-persisting local filesystem such as NTFS.`, { cause });
1050
+ super(detail?.code === "ERR_PRIVATE_FILES_UNAVAILABLE" ? `Private file refused at ${stage}: ${path2} (${PRIVATE_FILES_UNAVAILABLE_REASON}). The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.` : `Private file refused at ${stage}: ${path2} (${detail?.reason ?? detail?.code ?? "io-error"}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
1026
1051
  this.path = path2;
1027
1052
  this.stage = stage;
1028
1053
  this.name = "PrivateFileError";
@@ -1133,7 +1158,7 @@ var init_atomic_write = __esm({
1133
1158
  // ../core/dist/common-auth-embedded/fs/refresh-file-lock.js
1134
1159
  import { randomUUID as randomUUID7 } from "node:crypto";
1135
1160
  import { mkdir as mkdir7, open as open4, readFile as readFile5, rename as rename5, rm as rm4, stat as stat3 } from "node:fs/promises";
1136
- import { dirname as dirname7, join as join4 } from "node:path";
1161
+ import { dirname as dirname7, join as join5 } from "node:path";
1137
1162
  async function createExclusiveText(path2, text2) {
1138
1163
  const handle = await open4(path2, "wx", 384);
1139
1164
  try {
@@ -1151,7 +1176,7 @@ function acquireRefreshFileLock(options) {
1151
1176
  }
1152
1177
  async function acquireRefreshFileLockWithClock(options) {
1153
1178
  const lockPath = lockPathFor(options.path, options.name);
1154
- const legacyOwnerPath = join4(lockPath, "owner.json");
1179
+ const legacyOwnerPath = join5(lockPath, "owner.json");
1155
1180
  const ownerId = randomUUID7();
1156
1181
  const now = options.now ?? Date.now;
1157
1182
  let renewTimer = null;
@@ -1194,7 +1219,7 @@ async function acquireRefreshFileLockWithClock(options) {
1194
1219
  let terminalIOError;
1195
1220
  let renewalInFlight = null;
1196
1221
  const evictPath = `${lockPath}.evicting`;
1197
- const evictOwnerPath = join4(evictPath, "owner.json");
1222
+ const evictOwnerPath = join5(evictPath, "owner.json");
1198
1223
  const evictOwnerId = randomUUID7();
1199
1224
  const EVICT_TTL = 5e3;
1200
1225
  const MAX_STEAL_ATTEMPTS = 8;
@@ -8863,7 +8888,7 @@ var init_any_signal = __esm({
8863
8888
  import { createHash as createHash5, randomBytes as randomBytes2, randomUUID as randomUUID10 } from "node:crypto";
8864
8889
  import { constants as fsConstants } from "node:fs";
8865
8890
  import { chmod as chmod2, mkdir as mkdir8, open as open6, readFile as readFile6, realpath as realpath3, rename as rename6, stat as stat4, unlink as unlink6 } from "node:fs/promises";
8866
- import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join5, resolve as resolve5 } from "node:path";
8891
+ import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join6, resolve as resolve5 } from "node:path";
8867
8892
  import { ClaustrumCredentialError as ClaustrumCredentialError2, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
8868
8893
  function classifyEnrollmentError(error) {
8869
8894
  if (!(error instanceof ClaustrumCredentialError2))
@@ -8889,7 +8914,7 @@ function getClaustrumEnrollmentPaths(tokenPath) {
8889
8914
  const extension = extname(tokenPath) || ".json";
8890
8915
  const stem = basename3(tokenPath, extname(tokenPath));
8891
8916
  return {
8892
- statePath: join5(dirname9(tokenPath), `${stem}-state${extension}`),
8917
+ statePath: join6(dirname9(tokenPath), `${stem}-state${extension}`),
8893
8918
  tokenPath
8894
8919
  };
8895
8920
  }
@@ -8897,7 +8922,7 @@ function hostEnrollmentPaths(input) {
8897
8922
  const override = input.override?.trim();
8898
8923
  if (override && !isAbsolute2(override) && !input.cwd)
8899
8924
  throw new ClaustrumConsumerError("invalid-state", "A relative Claustrum enrollment override needs a base directory");
8900
- const tokenPath = override ? isAbsolute2(override) ? override : resolve5(input.cwd, override) : join5(input.stateDir, `${input.host}-enrollment.json`);
8925
+ const tokenPath = override ? isAbsolute2(override) ? override : resolve5(input.cwd, override) : join6(input.stateDir, `${input.host}-enrollment.json`);
8901
8926
  return getClaustrumEnrollmentPaths(tokenPath);
8902
8927
  }
8903
8928
  function isRecord6(value) {
@@ -9130,7 +9155,7 @@ async function writeStateAtomic(path2, state, ancestorOptions = {}) {
9130
9155
  }
9131
9156
  if (windowsPrivateFiles)
9132
9157
  return writePrivateAtomic(path2, bytes);
9133
- const temporary = join5(parent, `.${basename3(path2)}.${process.pid}.${randomUUID10()}.tmp`);
9158
+ const temporary = join6(parent, `.${basename3(path2)}.${process.pid}.${randomUUID10()}.tmp`);
9134
9159
  let descriptor;
9135
9160
  let created = false;
9136
9161
  try {
@@ -9307,7 +9332,7 @@ async function disconnectClaustrumEnrollment(paths, proposedName) {
9307
9332
  await lock.release();
9308
9333
  }
9309
9334
  }
9310
- var ENROLLMENT_SCHEMA, ENROLLMENT_FILE_MAX_BYTES, ENROLLMENT_LOCK_TTL_MS, TOKEN_RE, TERMINAL_ENROLLMENT_CODES, RETRYABLE_ENROLLMENT_CODES, ClaustrumEnrollmentManager;
9335
+ var ENROLLMENT_SCHEMA, ENROLLMENT_FILE_MAX_BYTES, ENROLLMENT_LOCK_TTL_MS, TOKEN_RE, UNSUPPORTED_ENROLLMENT_CODE, TERMINAL_ENROLLMENT_CODES, RETRYABLE_ENROLLMENT_CODES, ClaustrumEnrollmentManager;
9311
9336
  var init_enrollment = __esm({
9312
9337
  "../core/dist/common-auth-embedded/claustrum/enrollment.js"() {
9313
9338
  "use strict";
@@ -9318,7 +9343,13 @@ var init_enrollment = __esm({
9318
9343
  ENROLLMENT_FILE_MAX_BYTES = 16 * 1024;
9319
9344
  ENROLLMENT_LOCK_TTL_MS = 3e4;
9320
9345
  TOKEN_RE = /^[0-9a-f]{64}$/;
9346
+ UNSUPPORTED_ENROLLMENT_CODE = "unknown_method";
9321
9347
  TERMINAL_ENROLLMENT_CODES = /* @__PURE__ */ new Set([
9348
+ // The daemon's answer to an operation it does not implement: a vault built
9349
+ // before the enrollment ceremony. It arrives as a transport Error frame with
9350
+ // no class, which claustrum-client before 0.13.0 labels transient/retry, but
9351
+ // asking again can never succeed.
9352
+ UNSUPPORTED_ENROLLMENT_CODE,
9322
9353
  "invalid_params",
9323
9354
  "pending_exists",
9324
9355
  "not_found",
@@ -9452,6 +9483,18 @@ var init_enrollment = __esm({
9452
9483
  retryCode: refusal3.code
9453
9484
  };
9454
9485
  }
9486
+ if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE) {
9487
+ await lock.assertOwned();
9488
+ await unlink6(this.#paths.statePath).catch((cause) => {
9489
+ if (cause.code !== "ENOENT")
9490
+ throw cause;
9491
+ });
9492
+ return {
9493
+ state: "unavailable",
9494
+ proposedName: state.proposedName,
9495
+ code: refusal3.code
9496
+ };
9497
+ }
9455
9498
  return this.#block(state, refusal3.code);
9456
9499
  }
9457
9500
  }
@@ -18449,15 +18492,15 @@ function maskSensitiveIdentifier(value) {
18449
18492
 
18450
18493
  // ../core/dist/pi-paths.js
18451
18494
  import { homedir } from "node:os";
18452
- import { dirname as dirname11, join as join6 } from "node:path";
18495
+ import { dirname as dirname11, join as join7 } from "node:path";
18453
18496
  function getPiConfigDir() {
18454
- return process.env.PI_AGENT_DIR?.trim() || join6(homedir(), ".pi", "agent");
18497
+ return process.env.PI_AGENT_DIR?.trim() || join7(homedir(), ".pi", "agent");
18455
18498
  }
18456
18499
  function getPiAntigravityAuthFile() {
18457
- return process.env.PI_ANTIGRAVITY_AUTH_FILE?.trim() || join6(getPiConfigDir(), "antigravity-accounts.json");
18500
+ return process.env.PI_ANTIGRAVITY_AUTH_FILE?.trim() || join7(getPiConfigDir(), "antigravity-accounts.json");
18458
18501
  }
18459
18502
  function getPiAntigravityVaultDir() {
18460
- return join6(dirname11(getPiAntigravityAuthFile()), "antigravity-auth-vault");
18503
+ return join7(dirname11(getPiAntigravityAuthFile()), "antigravity-auth-vault");
18461
18504
  }
18462
18505
 
18463
18506
  // ../core/dist/project.js
@@ -19041,11 +19084,16 @@ function mostConstrainedWindow(windows) {
19041
19084
  };
19042
19085
  }
19043
19086
  function poolForBucketId(bucketId) {
19044
- if (bucketId.startsWith("gemini-"))
19045
- return "gemini";
19046
- if (bucketId.startsWith("3p-"))
19047
- return "non-gemini";
19048
- return null;
19087
+ switch (bucketId) {
19088
+ case "gemini-5h":
19089
+ case "gemini-weekly":
19090
+ return "gemini";
19091
+ case "3p-5h":
19092
+ case "3p-weekly":
19093
+ return "non-gemini";
19094
+ default:
19095
+ return null;
19096
+ }
19049
19097
  }
19050
19098
  function parseDescriptionModelCount(description) {
19051
19099
  const prefixMatch = description.match(/^[^:]+:\s*/);
@@ -19066,31 +19114,60 @@ function windowDurationMs(window) {
19066
19114
  }
19067
19115
  }
19068
19116
  function aggregateQuotaSummary(response) {
19069
- const groups = {};
19070
- let totalCount = 0;
19117
+ const windowsByPool = {
19118
+ gemini: /* @__PURE__ */ new Map(),
19119
+ "non-gemini": /* @__PURE__ */ new Map()
19120
+ };
19121
+ const modelCounts = {
19122
+ gemini: 0,
19123
+ "non-gemini": 0
19124
+ };
19125
+ const seenBucketIds = /* @__PURE__ */ new Set();
19126
+ const duplicateBucketIds = /* @__PURE__ */ new Set();
19071
19127
  for (const group of response.groups) {
19072
- const windows = [];
19128
+ const contributingPools = /* @__PURE__ */ new Set();
19073
19129
  for (const bucket of group.buckets) {
19074
- const pool2 = poolForBucketId(bucket.bucketId);
19075
- if (!pool2)
19130
+ if (bucket.disabled === true)
19131
+ continue;
19132
+ const pool = poolForBucketId(bucket.bucketId);
19133
+ if (!pool)
19076
19134
  continue;
19077
- windows.push({
19135
+ contributingPools.add(pool);
19136
+ const window = {
19078
19137
  window: bucket.window,
19079
19138
  remainingFraction: normalizeRemainingFraction(bucket.remainingFraction),
19080
19139
  resetTime: bucket.resetTime
19081
- });
19140
+ };
19141
+ const previous = windowsByPool[pool].get(bucket.bucketId);
19142
+ if (seenBucketIds.has(bucket.bucketId)) {
19143
+ duplicateBucketIds.add(bucket.bucketId);
19144
+ } else {
19145
+ seenBucketIds.add(bucket.bucketId);
19146
+ }
19147
+ if (!previous || window.remainingFraction < previous.remainingFraction) {
19148
+ windowsByPool[pool].set(bucket.bucketId, window);
19149
+ }
19082
19150
  }
19151
+ const modelCount = group.description ? parseDescriptionModelCount(group.description) : 0;
19152
+ for (const pool of contributingPools)
19153
+ modelCounts[pool] += modelCount;
19154
+ }
19155
+ if (duplicateBucketIds.size > 0) {
19156
+ log4.debug("duplicate quota summary bucket ids", {
19157
+ bucketIds: [...duplicateBucketIds].sort()
19158
+ });
19159
+ }
19160
+ const groups = {};
19161
+ let totalCount = 0;
19162
+ for (const pool of ["gemini", "non-gemini"]) {
19163
+ const windows = [...windowsByPool[pool].values()];
19083
19164
  if (windows.length === 0)
19084
19165
  continue;
19085
19166
  windows.sort((a, b) => windowDurationMs(a.window) - windowDurationMs(b.window));
19086
19167
  const constrained = mostConstrainedWindow(windows);
19087
- const recognizedBucket = group.buckets.find((bucket) => poolForBucketId(bucket.bucketId));
19088
- if (!recognizedBucket)
19168
+ if (!constrained)
19089
19169
  continue;
19090
- const pool = poolForBucketId(recognizedBucket.bucketId);
19091
- if (!pool || !constrained)
19092
- continue;
19093
- const modelCount = group.description ? parseDescriptionModelCount(group.description) : 0;
19170
+ const modelCount = modelCounts[pool];
19094
19171
  groups[pool] = {
19095
19172
  remainingFraction: constrained.remainingFraction,
19096
19173
  resetTime: constrained.resetTime,
@@ -19326,7 +19403,7 @@ import {
19326
19403
  writeFileSync
19327
19404
  } from "node:fs";
19328
19405
  import { homedir as homedir3 } from "node:os";
19329
- import { dirname as dirname14, join as join8, resolve as resolve11 } from "node:path";
19406
+ import { dirname as dirname14, join as join10, resolve as resolve11 } from "node:path";
19330
19407
 
19331
19408
  // src/common-auth-embedded/logger/engine.js
19332
19409
  import { appendFileSync as appendFileSync2, chmodSync as chmodSync2, existsSync as existsSync2, renameSync as renameSync2, statSync as statSync3 } from "node:fs";
@@ -19336,7 +19413,8 @@ import { dirname as dirname13, resolve as resolve10 } from "node:path";
19336
19413
  // src/common-auth-embedded/fs/private-files.js
19337
19414
  import { randomUUID as randomUUID11 } from "node:crypto";
19338
19415
  import { lstat as lstat4, readFile as readFile7, rename as rename7, unlink as unlink8 } from "node:fs/promises";
19339
- import { dirname as dirname12, resolve as resolve9 } from "node:path";
19416
+ import { tmpdir as tmpdir2 } from "node:os";
19417
+ import { dirname as dirname12, join as join8, resolve as resolve9 } from "node:path";
19340
19418
  var windowsPrivateFiles2 = process.platform === "win32";
19341
19419
  var migrationNotices2 = /* @__PURE__ */ new Set();
19342
19420
  function ioCode2(detail) {
@@ -19349,8 +19427,32 @@ function ioCode2(detail) {
19349
19427
  return detail?.code ?? "ERR_PRIVATE_FILE";
19350
19428
  }
19351
19429
  var backend2;
19430
+ var PRIVATE_FILES_UNAVAILABLE_REASON2 = "native-addon-unavailable";
19431
+ function privateFilesUnavailable2(cause) {
19432
+ return Object.assign(new Error("Windows private-files native addon is unavailable", { cause }), {
19433
+ code: "ERR_PRIVATE_FILES_UNAVAILABLE",
19434
+ reason: PRIVATE_FILES_UNAVAILABLE_REASON2
19435
+ });
19436
+ }
19437
+ function isUnavailable2(api, error) {
19438
+ return error instanceof api.PrivateFilesUnavailableError || error?.code === "ERR_PRIVATE_FILES_UNAVAILABLE";
19439
+ }
19440
+ async function assertNativeAddonLoads2(api) {
19441
+ try {
19442
+ await api.verifyPrivatePath(join8(tmpdir2(), `.common-auth-private-files-probe-${randomUUID11()}`), "file");
19443
+ } catch (error) {
19444
+ if (isUnavailable2(api, error))
19445
+ throw privateFilesUnavailable2(error);
19446
+ }
19447
+ }
19352
19448
  function loadBackend2() {
19353
- backend2 ??= import("@cortexkit/private-files");
19449
+ backend2 ??= import("@cortexkit/private-files").then(async (api) => {
19450
+ if (windowsPrivateFiles2)
19451
+ await assertNativeAddonLoads2(api);
19452
+ return api;
19453
+ }, (cause) => {
19454
+ throw windowsPrivateFiles2 ? privateFilesUnavailable2(cause) : cause;
19455
+ });
19354
19456
  return backend2;
19355
19457
  }
19356
19458
  var PrivateFileError2 = class extends Error {
@@ -19367,7 +19469,7 @@ var PrivateFileError2 = class extends Error {
19367
19469
  orphanPath;
19368
19470
  constructor(path2, stage, cause) {
19369
19471
  const detail = cause;
19370
- super(`Private file refused at ${stage}: ${path2} (${detail?.reason ?? detail?.code ?? "io-error"}). Use a safe parent directory. Repair only a named secret file in safe ancestry whose owner the published policy trusts, without changing its owner or any existing directory. Previously exposed credentials may need rotation. Windows requires the private-files native prebuild and an ACL-persisting local filesystem such as NTFS.`, { cause });
19472
+ super(detail?.code === "ERR_PRIVATE_FILES_UNAVAILABLE" ? `Private file refused at ${stage}: ${path2} (${PRIVATE_FILES_UNAVAILABLE_REASON2}). The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.` : `Private file refused at ${stage}: ${path2} (${detail?.reason ?? detail?.code ?? "io-error"}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
19371
19473
  this.path = path2;
19372
19474
  this.stage = stage;
19373
19475
  this.name = "PrivateFileError";
@@ -19959,7 +20061,7 @@ import {
19959
20061
  unlinkSync
19960
20062
  } from "node:fs";
19961
20063
  import { homedir as homedir2 } from "node:os";
19962
- import { join as join7 } from "node:path";
20064
+ import { join as join9 } from "node:path";
19963
20065
  import { env } from "node:process";
19964
20066
 
19965
20067
  // src/plugin/logging-utils.ts
@@ -20090,16 +20192,16 @@ var liveLogFilePaths = /* @__PURE__ */ new Set();
20090
20192
  function getConfigDir() {
20091
20193
  const platform = process.platform;
20092
20194
  if (platform === "win32") {
20093
- return join7(
20094
- env.APPDATA || join7(homedir2(), "AppData", "Roaming"),
20195
+ return join9(
20196
+ env.APPDATA || join9(homedir2(), "AppData", "Roaming"),
20095
20197
  "opencode"
20096
20198
  );
20097
20199
  }
20098
- const xdgConfig2 = env.XDG_CONFIG_HOME || join7(homedir2(), ".config");
20099
- return join7(xdgConfig2, "opencode");
20200
+ const xdgConfig2 = env.XDG_CONFIG_HOME || join9(homedir2(), ".config");
20201
+ return join9(xdgConfig2, "opencode");
20100
20202
  }
20101
20203
  function getLogsDir(customLogDir) {
20102
- const logsDir = customLogDir || join7(getConfigDir(), "antigravity-logs");
20204
+ const logsDir = customLogDir || join9(getConfigDir(), "antigravity-logs");
20103
20205
  try {
20104
20206
  mkdirSync(logsDir, { recursive: true, mode: 448 });
20105
20207
  } catch {
@@ -20110,9 +20212,9 @@ function createLogFilePath(customLogDir) {
20110
20212
  const logsDir = getLogsDir(customLogDir);
20111
20213
  cleanupOldLogs(logsDir, 25);
20112
20214
  const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
20113
- let candidate = join7(logsDir, `antigravity-debug-${timestamp}.log`);
20215
+ let candidate = join9(logsDir, `antigravity-debug-${timestamp}.log`);
20114
20216
  for (let suffix = 2; liveLogFilePaths.has(candidate); suffix++) {
20115
- candidate = join7(logsDir, `antigravity-debug-${timestamp}-${suffix}.log`);
20217
+ candidate = join9(logsDir, `antigravity-debug-${timestamp}-${suffix}.log`);
20116
20218
  }
20117
20219
  return candidate;
20118
20220
  }
@@ -20120,7 +20222,7 @@ function cleanupOldLogs(logsDir, maxFiles) {
20120
20222
  try {
20121
20223
  const files = readdirSync(logsDir).filter(
20122
20224
  (file) => file.startsWith("antigravity-debug-") && file.endsWith(".log")
20123
- ).map((file) => join7(logsDir, file));
20225
+ ).map((file) => join9(logsDir, file));
20124
20226
  if (files.length <= maxFiles) {
20125
20227
  return;
20126
20228
  }
@@ -20595,7 +20697,7 @@ var GITIGNORE_ENTRIES = [
20595
20697
  "antigravity-logs/"
20596
20698
  ];
20597
20699
  async function ensureGitignore(configDir) {
20598
- const gitignorePath = join8(configDir, ".gitignore");
20700
+ const gitignorePath = join10(configDir, ".gitignore");
20599
20701
  try {
20600
20702
  let content;
20601
20703
  let existingLines = [];
@@ -20641,7 +20743,7 @@ async function ensureGitignore(configDir) {
20641
20743
  }
20642
20744
  }
20643
20745
  function ensureGitignoreSync(configDir) {
20644
- const gitignorePath = join8(configDir, ".gitignore");
20746
+ const gitignorePath = join10(configDir, ".gitignore");
20645
20747
  try {
20646
20748
  let content;
20647
20749
  let existingLines = [];
@@ -20680,8 +20782,8 @@ function ensureGitignoreSync(configDir) {
20680
20782
  }
20681
20783
  }
20682
20784
  function getLegacyWindowsConfigDir() {
20683
- return join8(
20684
- process.env.APPDATA || join8(homedir3(), "AppData", "Roaming"),
20785
+ return join10(
20786
+ process.env.APPDATA || join10(homedir3(), "AppData", "Roaming"),
20685
20787
  "opencode"
20686
20788
  );
20687
20789
  }
@@ -20689,15 +20791,15 @@ function getConfigDir2() {
20689
20791
  if (process.env.OPENCODE_CONFIG_DIR) {
20690
20792
  return process.env.OPENCODE_CONFIG_DIR;
20691
20793
  }
20692
- const xdgConfig2 = process.env.XDG_CONFIG_HOME || join8(homedir3(), ".config");
20693
- return join8(xdgConfig2, "opencode");
20794
+ const xdgConfig2 = process.env.XDG_CONFIG_HOME || join10(homedir3(), ".config");
20795
+ return join10(xdgConfig2, "opencode");
20694
20796
  }
20695
20797
  function migrateLegacyWindowsConfig() {
20696
20798
  if (process.platform !== "win32") {
20697
20799
  return false;
20698
20800
  }
20699
- const newPath = join8(getConfigDir2(), "antigravity-accounts.json");
20700
- const legacyPath = join8(
20801
+ const newPath = join10(getConfigDir2(), "antigravity-accounts.json");
20802
+ const legacyPath = join10(
20701
20803
  getLegacyWindowsConfigDir(),
20702
20804
  "antigravity-accounts.json"
20703
20805
  );
@@ -20732,11 +20834,11 @@ function migrateLegacyWindowsConfig() {
20732
20834
  }
20733
20835
  }
20734
20836
  function getStoragePathWithMigration() {
20735
- const newPath = join8(getConfigDir2(), "antigravity-accounts.json");
20837
+ const newPath = join10(getConfigDir2(), "antigravity-accounts.json");
20736
20838
  if (process.platform === "win32") {
20737
20839
  migrateLegacyWindowsConfig();
20738
20840
  if (!existsSync3(newPath)) {
20739
- const legacyPath = join8(
20841
+ const legacyPath = join10(
20740
20842
  getLegacyWindowsConfigDir(),
20741
20843
  "antigravity-accounts.json"
20742
20844
  );
@@ -21683,7 +21785,7 @@ async function startOAuthListener({
21683
21785
 
21684
21786
  // src/setup.ts
21685
21787
  import { lstat as lstat5, readFile as readFile10 } from "node:fs/promises";
21686
- import { join as join15, resolve as resolve13 } from "node:path";
21788
+ import { join as join17, resolve as resolve13 } from "node:path";
21687
21789
 
21688
21790
  // src/auth-method-labels.ts
21689
21791
  var OPENCODE2_POOL_AUTH_LABEL = "Google (antigravity-auth pool, browser)";
@@ -21929,7 +22031,7 @@ async function select2(terminal, items, options) {
21929
22031
  import { createHash as createHash9, randomBytes as randomBytes3, randomUUID as randomUUID14 } from "node:crypto";
21930
22032
  import { constants as fsConstants2 } from "node:fs";
21931
22033
  import { chmod as chmod3, mkdir as mkdir12, open as open10, readFile as readFile9, realpath as realpath4, rename as rename9, stat as stat7, unlink as unlink9 } from "node:fs/promises";
21932
- import { basename as basename4, dirname as dirname16, extname as extname2, isAbsolute as isAbsolute3, join as join10, resolve as resolve12 } from "node:path";
22034
+ import { basename as basename4, dirname as dirname16, extname as extname2, isAbsolute as isAbsolute3, join as join12, resolve as resolve12 } from "node:path";
21933
22035
  import { ClaustrumCredentialError as ClaustrumCredentialError5, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
21934
22036
 
21935
22037
  // src/common-auth-embedded/fs/lock-constants.js
@@ -21951,7 +22053,7 @@ var WRITER_LOCK_CONSTANTS2 = Object.freeze({
21951
22053
  // src/common-auth-embedded/fs/refresh-file-lock.js
21952
22054
  import { randomUUID as randomUUID13 } from "node:crypto";
21953
22055
  import { mkdir as mkdir11, open as open9, readFile as readFile8, rename as rename8, rm as rm5, stat as stat6 } from "node:fs/promises";
21954
- import { dirname as dirname15, join as join9 } from "node:path";
22056
+ import { dirname as dirname15, join as join11 } from "node:path";
21955
22057
 
21956
22058
  // src/common-auth-embedded/fs/with-lock.js
21957
22059
  function lockPathFor2(target, name) {
@@ -21986,7 +22088,7 @@ function acquireRefreshFileLock2(options) {
21986
22088
  }
21987
22089
  async function acquireRefreshFileLockWithClock2(options) {
21988
22090
  const lockPath = lockPathFor2(options.path, options.name);
21989
- const legacyOwnerPath = join9(lockPath, "owner.json");
22091
+ const legacyOwnerPath = join11(lockPath, "owner.json");
21990
22092
  const ownerId = randomUUID13();
21991
22093
  const now = options.now ?? Date.now;
21992
22094
  let renewTimer = null;
@@ -22029,7 +22131,7 @@ async function acquireRefreshFileLockWithClock2(options) {
22029
22131
  let terminalIOError;
22030
22132
  let renewalInFlight = null;
22031
22133
  const evictPath = `${lockPath}.evicting`;
22032
- const evictOwnerPath = join9(evictPath, "owner.json");
22134
+ const evictOwnerPath = join11(evictPath, "owner.json");
22033
22135
  const evictOwnerId = randomUUID13();
22034
22136
  const EVICT_TTL = 5e3;
22035
22137
  const MAX_STEAL_ATTEMPTS = 8;
@@ -22600,7 +22702,13 @@ var ENROLLMENT_SCHEMA2 = 1;
22600
22702
  var ENROLLMENT_FILE_MAX_BYTES2 = 16 * 1024;
22601
22703
  var ENROLLMENT_LOCK_TTL_MS2 = 3e4;
22602
22704
  var TOKEN_RE2 = /^[0-9a-f]{64}$/;
22705
+ var UNSUPPORTED_ENROLLMENT_CODE2 = "unknown_method";
22603
22706
  var TERMINAL_ENROLLMENT_CODES2 = /* @__PURE__ */ new Set([
22707
+ // The daemon's answer to an operation it does not implement: a vault built
22708
+ // before the enrollment ceremony. It arrives as a transport Error frame with
22709
+ // no class, which claustrum-client before 0.13.0 labels transient/retry, but
22710
+ // asking again can never succeed.
22711
+ UNSUPPORTED_ENROLLMENT_CODE2,
22604
22712
  "invalid_params",
22605
22713
  "pending_exists",
22606
22714
  "not_found",
@@ -22630,7 +22738,7 @@ function getClaustrumEnrollmentPaths2(tokenPath) {
22630
22738
  const extension = extname2(tokenPath) || ".json";
22631
22739
  const stem = basename4(tokenPath, extname2(tokenPath));
22632
22740
  return {
22633
- statePath: join10(dirname16(tokenPath), `${stem}-state${extension}`),
22741
+ statePath: join12(dirname16(tokenPath), `${stem}-state${extension}`),
22634
22742
  tokenPath
22635
22743
  };
22636
22744
  }
@@ -22638,7 +22746,7 @@ function hostEnrollmentPaths2(input) {
22638
22746
  const override = input.override?.trim();
22639
22747
  if (override && !isAbsolute3(override) && !input.cwd)
22640
22748
  throw new ClaustrumConsumerError2("invalid-state", "A relative Claustrum enrollment override needs a base directory");
22641
- const tokenPath = override ? isAbsolute3(override) ? override : resolve12(input.cwd, override) : join10(input.stateDir, `${input.host}-enrollment.json`);
22749
+ const tokenPath = override ? isAbsolute3(override) ? override : resolve12(input.cwd, override) : join12(input.stateDir, `${input.host}-enrollment.json`);
22642
22750
  return getClaustrumEnrollmentPaths2(tokenPath);
22643
22751
  }
22644
22752
  function isRecord9(value) {
@@ -22871,7 +22979,7 @@ async function writeStateAtomic2(path2, state, ancestorOptions = {}) {
22871
22979
  }
22872
22980
  if (windowsPrivateFiles2)
22873
22981
  return writePrivateAtomic2(path2, bytes);
22874
- const temporary = join10(parent, `.${basename4(path2)}.${process.pid}.${randomUUID14()}.tmp`);
22982
+ const temporary = join12(parent, `.${basename4(path2)}.${process.pid}.${randomUUID14()}.tmp`);
22875
22983
  let descriptor;
22876
22984
  let created = false;
22877
22985
  try {
@@ -23095,6 +23203,18 @@ var ClaustrumEnrollmentManager2 = class {
23095
23203
  retryCode: refusal3.code
23096
23204
  };
23097
23205
  }
23206
+ if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE2) {
23207
+ await lock.assertOwned();
23208
+ await unlink9(this.#paths.statePath).catch((cause) => {
23209
+ if (cause.code !== "ENOENT")
23210
+ throw cause;
23211
+ });
23212
+ return {
23213
+ state: "unavailable",
23214
+ proposedName: state.proposedName,
23215
+ code: refusal3.code
23216
+ };
23217
+ }
23098
23218
  return this.#block(state, refusal3.code);
23099
23219
  }
23100
23220
  }
@@ -23372,8 +23492,8 @@ function recordSetupEnrollment(failure, enrollment) {
23372
23492
  // src/common-auth-embedded/setup/detect.js
23373
23493
  import { accessSync, constants as constants3, existsSync as existsSync5, readFileSync as readFileSync3, realpathSync, statSync as statSync5 } from "node:fs";
23374
23494
  import { mkdtemp, rm as rm6 } from "node:fs/promises";
23375
- import { tmpdir } from "node:os";
23376
- import { join as join11 } from "node:path";
23495
+ import { tmpdir as tmpdir3 } from "node:os";
23496
+ import { join as join13 } from "node:path";
23377
23497
  import { parse } from "jsonc-parser";
23378
23498
 
23379
23499
  // src/common-auth-embedded/setup/paths.js
@@ -23544,7 +23664,7 @@ async function detectHosts(plugin, io = {}) {
23544
23664
  return null;
23545
23665
  let root;
23546
23666
  try {
23547
- root = await mkdtemp(join11(tmpdir(), "common-auth-setup-version-"));
23667
+ root = await mkdtemp(join13(tmpdir3(), "common-auth-setup-version-"));
23548
23668
  const probeEnv = {
23549
23669
  ...env3,
23550
23670
  HOME: root,
@@ -23613,6 +23733,8 @@ import { writeEnrollmentTokenFile as writeEnrollmentTokenFile3 } from "@cortexki
23613
23733
  var WINDOWS_CIM_TIMEOUT_MS = 45e3;
23614
23734
  var HOSTS = /* @__PURE__ */ new Set(["opencode", "litecode", "opencode2", "pi"]);
23615
23735
  var RUNTIMES = /* @__PURE__ */ new Set(["node", "bun"]);
23736
+ var WINDOWS_FENCE_FILTER = [...HOSTS, ...RUNTIMES].map((name) => `Name LIKE '${name}%'`).join(" OR ");
23737
+ var WINDOWS_FENCE_QUERY = `$ErrorActionPreference = 'Stop'; $rows = @(Get-CimInstance Win32_Process -Filter "${WINDOWS_FENCE_FILTER}" | Select-Object Name,ProcessId,CommandLine); ConvertTo-Json -Compress -Depth 3 -InputObject @{ complete = $true; processes = $rows }`;
23616
23738
  var PI_SCRIPT_PATTERN = /(?:^|[/\\])pi-coding-agent[/\\]dist[/\\](?:(?:bundle|bun)[/\\])?cli\.m?js$/i;
23617
23739
  function commandArguments(command) {
23618
23740
  return [...command.matchAll(/"([^"]*)"|(\S+)/g)].map((match) => match[1] ?? match[2] ?? "");
@@ -23752,6 +23874,29 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
23752
23874
  }
23753
23875
  };
23754
23876
  try {
23877
+ if (windows && options.hostImagesOnly) {
23878
+ const details = await inspect("CIM", "powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", WINDOWS_FENCE_QUERY], WINDOWS_CIM_TIMEOUT_MS);
23879
+ if (details.exitCode !== 0)
23880
+ throw new ProcessInspectionError(inspection);
23881
+ const value = JSON.parse(details.stdout);
23882
+ if (!value || typeof value !== "object" || !("complete" in value) || value.complete !== true || !("processes" in value))
23883
+ throw new ProcessInspectionError(inspection);
23884
+ const listed = value.processes;
23885
+ const rows = listed === null ? [] : Array.isArray(listed) ? listed : [listed];
23886
+ const processes2 = [];
23887
+ for (const row of rows) {
23888
+ if (!row || typeof row !== "object" || !("Name" in row) || typeof row.Name !== "string" || !("ProcessId" in row) || !Number.isSafeInteger(row.ProcessId) || row.ProcessId < 0 || !("CommandLine" in row))
23889
+ throw new ProcessInspectionError(inspection);
23890
+ const pid = row.ProcessId;
23891
+ if (!/^(?:node|bun)\.exe$/i.test(row.Name))
23892
+ processes2.push({ pid, command: row.Name });
23893
+ else if (typeof row.CommandLine === "string")
23894
+ processes2.push({ pid, command: row.CommandLine });
23895
+ else if (pid !== selfPid)
23896
+ throw new ProcessInspectionError(inspection);
23897
+ }
23898
+ return processes2;
23899
+ }
23755
23900
  const result = await inspect(windows ? "tasklist" : "ps", windows ? "tasklist.exe" : "ps", windows ? ["/fo", "csv", "/nh"] : ["-eo", "pid,command"]);
23756
23901
  if (result.exitCode !== 0)
23757
23902
  throw new ProcessInspectionError(inspection);
@@ -23821,7 +23966,11 @@ function createProcessFence(runner = defaultCommandRunner, options = {}) {
23821
23966
  const isHost = (entry) => entry.pid !== selfPid && hostName(entry.command) !== null;
23822
23967
  return {
23823
23968
  async listRunningHosts(env3) {
23824
- return (await listSetupProcesses(runner, { ...options, env: env3 })).filter(isHost);
23969
+ return (await listSetupProcesses(runner, {
23970
+ ...options,
23971
+ env: env3,
23972
+ hostImagesOnly: true
23973
+ })).filter(isHost);
23825
23974
  },
23826
23975
  async previewRunningHosts(env3) {
23827
23976
  const processes = await listSetupProcesses(runner, {
@@ -23845,8 +23994,27 @@ async function assertHostsStopped(fence, env3) {
23845
23994
 
23846
23995
  // src/common-auth-embedded/setup/enroll.js
23847
23996
  var ENROLLMENT_INCOMPLETE_MESSAGE = "Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.";
23997
+ var UNSUPPORTED_VAULT_MESSAGE = "This Claustrum vault does not support connecting plugins yet, so setup cannot connect to it. Run setup without --claustrum to use local accounts.";
23998
+ var ENROLLMENT_WAIT_MS = 3e5;
23999
+ var APPROVAL_POLL_MS = 1e3;
24000
+ var PROPOSE_BACKOFF_MS = [1e3, 2e3, 4e3, 8e3, 16e3, 3e4];
24001
+ function safeCode(code2) {
24002
+ return code2 && /^[a-z][a-z0-9_]{0,63}$/.test(code2) ? code2 : "unknown";
24003
+ }
23848
24004
  var HostNotEnrolledError = class extends Error {
24005
+ reason;
24006
+ lastErrorCode;
24007
+ constructor(message, details) {
24008
+ super(message);
24009
+ this.name = "HostNotEnrolledError";
24010
+ this.reason = details.reason;
24011
+ if (details.lastErrorCode !== void 0)
24012
+ this.lastErrorCode = safeCode(details.lastErrorCode);
24013
+ }
23849
24014
  };
24015
+ function approveCommand(requestId, name) {
24016
+ return `ck auth enroll approve --request-id ${requestId} --name ${name}`;
24017
+ }
23850
24018
  async function connectSetupHost(plugin, host, io, terminal, fence) {
23851
24019
  const { name, paths: input } = plugin.vault.hosts[host];
23852
24020
  const paths = hostEnrollmentPaths2(input);
@@ -23855,54 +24023,94 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
23855
24023
  connectionFile: plugin.vault.connectionFile,
23856
24024
  handshakeTimeoutMs: 2e3
23857
24025
  }).catch(() => {
23858
- throw new HostNotEnrolledError("Claustrum connection failed; start ck and rerun setup.");
24026
+ throw new HostNotEnrolledError("Claustrum connection failed; start ck and rerun setup.", { reason: "connection-failed" });
23859
24027
  });
24028
+ const now = io.now ?? (() => performance.now());
24029
+ const wait2 = io.wait ?? delay;
23860
24030
  try {
23861
24031
  const manager = new ClaustrumEnrollmentManager2({
23862
24032
  proposedName: name,
23863
24033
  paths,
23864
- client: {
23865
- enrollPropose: async (input2) => {
23866
- await fence();
23867
- return client.enrollPropose(input2);
23868
- },
23869
- enrollPoll: async (input2) => {
23870
- await fence();
23871
- return client.enrollPoll(input2);
23872
- }
23873
- },
24034
+ // Each tick of the wait below checks the fence once, just before
24035
+ // reconcile proposes or polls. Checking again inside every vault call
24036
+ // doubled the process listings per tick, and on Windows each listing
24037
+ // starts PowerShell.
24038
+ client,
23874
24039
  writeTokenFile: async (path2, file) => {
23875
24040
  await fence();
23876
24041
  await writeEnrollmentTokenFile3(path2, file);
23877
24042
  }
23878
24043
  });
24044
+ printLine2(terminal, `Asking the vault to connect ${name}\u2026`);
24045
+ const deadline = now() + ENROLLMENT_WAIT_MS;
23879
24046
  let printedRequest;
23880
- for (let tick = 0; tick < 300; tick++) {
24047
+ let lastCode;
24048
+ let reportedCode;
24049
+ let failedProposals = 0;
24050
+ for (; ; ) {
23881
24051
  await fence();
23882
24052
  const status = await manager.reconcile();
23883
24053
  if (status.state === "approved") {
23884
24054
  printLine2(terminal, `Connected ${host} to Claustrum.`);
23885
24055
  return;
23886
24056
  }
24057
+ if (status.state === "unavailable" && status.code === UNSUPPORTED_ENROLLMENT_CODE2)
24058
+ throw new HostNotEnrolledError(UNSUPPORTED_VAULT_MESSAGE, {
24059
+ reason: "unsupported-vault",
24060
+ lastErrorCode: status.code
24061
+ });
23887
24062
  if (status.state !== "pending" && status.state !== "busy")
23888
- throw new HostNotEnrolledError("Claustrum enrollment refused; inspect its status with ck before rerunning setup.");
23889
- if (status.state === "pending" && status.requestId && status.requestId !== printedRequest) {
23890
- if (!/^[a-zA-Z0-9_-]+$/.test(status.requestId))
23891
- throw new HostNotEnrolledError("Invalid enrollment request id.");
23892
- printedRequest = status.requestId;
23893
- printLine2(terminal, "Waiting for approval. In another terminal, run:");
23894
- printLine2(terminal, ` ck auth enroll approve --request-id ${status.requestId} --name ${name}`);
23895
- printLine2(terminal, `Enrollment files: ${paths.statePath}, ${paths.tokenPath}`);
23896
- }
23897
- await (io.wait ?? delay)(1e3);
23898
- }
23899
- throw new HostNotEnrolledError("Claustrum approval is still pending; approve with ck and rerun setup.");
24063
+ throw new HostNotEnrolledError("Claustrum enrollment refused; inspect its status with ck before rerunning setup.", {
24064
+ reason: "refused",
24065
+ ..."code" in status && { lastErrorCode: status.code }
24066
+ });
24067
+ let pause = APPROVAL_POLL_MS;
24068
+ if (status.state === "busy")
24069
+ lastCode = "busy";
24070
+ else if (status.retryCode)
24071
+ lastCode = status.retryCode;
24072
+ if (status.state === "pending" && status.requestId) {
24073
+ failedProposals = 0;
24074
+ if (status.requestId !== printedRequest) {
24075
+ if (!/^[a-zA-Z0-9_-]+$/.test(status.requestId))
24076
+ throw new HostNotEnrolledError("Invalid enrollment request id.", {
24077
+ reason: "invalid-request"
24078
+ });
24079
+ printedRequest = status.requestId;
24080
+ printLine2(terminal, "Waiting for approval. In another terminal, run:");
24081
+ printLine2(terminal, ` ${approveCommand(status.requestId, name)}`);
24082
+ printLine2(terminal, `Enrollment files: ${paths.statePath}, ${paths.tokenPath}`);
24083
+ }
24084
+ } else if (status.state === "pending" && status.retryCode) {
24085
+ pause = PROPOSE_BACKOFF_MS[Math.min(failedProposals, PROPOSE_BACKOFF_MS.length - 1)] ?? APPROVAL_POLL_MS;
24086
+ failedProposals++;
24087
+ const code3 = safeCode(status.retryCode);
24088
+ if (code3 !== reportedCode) {
24089
+ reportedCode = code3;
24090
+ printLine2(terminal, `The vault has not created the request yet (${code3}); retrying.`);
24091
+ }
24092
+ }
24093
+ const remaining = deadline - now();
24094
+ if (remaining <= 0)
24095
+ break;
24096
+ await wait2(Math.min(pause, remaining));
24097
+ }
24098
+ if (printedRequest)
24099
+ throw new HostNotEnrolledError(`Claustrum approval is still pending. In another terminal, run: ${approveCommand(printedRequest, name)} and then rerun setup.`, {
24100
+ reason: "approval-pending",
24101
+ ...lastCode !== void 0 && { lastErrorCode: lastCode }
24102
+ });
24103
+ const code2 = safeCode(lastCode);
24104
+ throw new HostNotEnrolledError(`The vault never created the enrollment request (last error: ${code2}). Check that ck is running, then rerun setup.`, { reason: "request-not-created", lastErrorCode: code2 });
23900
24105
  } catch (error) {
23901
- if (error instanceof ProcessFenceViolationError || error instanceof ProcessInspectionError)
24106
+ if (error instanceof ProcessFenceViolationError || error instanceof ProcessInspectionError || // Built above from fixed text and vetted values only.
24107
+ error instanceof HostNotEnrolledError)
23902
24108
  throw error;
23903
- if (error instanceof HostNotEnrolledError)
23904
- throw new HostNotEnrolledError(ENROLLMENT_INCOMPLETE_MESSAGE);
23905
- throw new Error(ENROLLMENT_INCOMPLETE_MESSAGE);
24109
+ const code2 = error?.code;
24110
+ throw new HostNotEnrolledError(ENROLLMENT_INCOMPLETE_MESSAGE, {
24111
+ reason: "incomplete",
24112
+ ...typeof code2 === "string" && { lastErrorCode: code2 }
24113
+ });
23906
24114
  } finally {
23907
24115
  client.close();
23908
24116
  }
@@ -23940,7 +24148,7 @@ import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2,
23940
24148
  // src/common-auth-embedded/setup/config-write.js
23941
24149
  import { randomUUID as randomUUID15 } from "node:crypto";
23942
24150
  import { mkdir as mkdir13, open as open11, rename as rename10, stat as stat9, unlink as unlink10 } from "node:fs/promises";
23943
- import { basename as basename5, dirname as dirname17, join as join12 } from "node:path";
24151
+ import { basename as basename5, dirname as dirname17, join as join14 } from "node:path";
23944
24152
  import { setTimeout as delay2 } from "node:timers/promises";
23945
24153
  async function writeHostConfigAtomic(file, content, options = {}) {
23946
24154
  const windows = (options.platform ?? process.platform) === "win32";
@@ -23955,7 +24163,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
23955
24163
  throw error;
23956
24164
  }
23957
24165
  }
23958
- const stage = join12(parent, `.${basename5(file)}.${(options.stageName ?? randomUUID15)()}.tmp`);
24166
+ const stage = join14(parent, `.${basename5(file)}.${(options.stageName ?? randomUUID15)()}.tmp`);
23959
24167
  let created = false;
23960
24168
  try {
23961
24169
  const handle = await open11(stage, "wx", mode ?? 438);
@@ -24321,28 +24529,28 @@ ${write.content}`);
24321
24529
 
24322
24530
  // src/plugin/vault-activation.ts
24323
24531
  import { homedir as homedir5 } from "node:os";
24324
- import { join as join13 } from "node:path";
24532
+ import { join as join15 } from "node:path";
24325
24533
  function nativeOpenCodeAuthPath(env3 = process.env, home = homedir5()) {
24326
- return join13(
24327
- env3.XDG_DATA_HOME || join13(home, ".local", "share"),
24534
+ return join15(
24535
+ env3.XDG_DATA_HOME || join15(home, ".local", "share"),
24328
24536
  "opencode",
24329
24537
  "auth.json"
24330
24538
  );
24331
24539
  }
24332
24540
 
24333
24541
  // src/plugin/vault-custody.ts
24334
- import { dirname as dirname18, join as join14 } from "node:path";
24542
+ import { dirname as dirname18, join as join16 } from "node:path";
24335
24543
  var OPENCODE_VAULT_PROVIDER = "google";
24336
24544
  var OPENCODE_VAULT_HOST = "opencode";
24337
24545
  var OPENCODE_VAULT_ENROLLMENT_NAME = getAntigravityVaultEnrollmentName(OPENCODE_VAULT_HOST);
24338
24546
  var OPENCODE_VAULT_DIR_NAME = "antigravity-auth-vault";
24339
24547
  function openCodeVaultPaths(accountFile) {
24340
- const dir = join14(dirname18(accountFile), OPENCODE_VAULT_DIR_NAME);
24548
+ const dir = join16(dirname18(accountFile), OPENCODE_VAULT_DIR_NAME);
24341
24549
  return {
24342
24550
  dir,
24343
- modeFile: join14(dir, "opencode-mode.json"),
24344
- rosterFile: join14(dir, "opencode-roster.json"),
24345
- stateFile: join14(dir, "opencode-state.json")
24551
+ modeFile: join16(dir, "opencode-mode.json"),
24552
+ rosterFile: join16(dir, "opencode-roster.json"),
24553
+ stateFile: join16(dir, "opencode-state.json")
24346
24554
  };
24347
24555
  }
24348
24556
  var LOCAL_MODE = Object.freeze({
@@ -24358,7 +24566,7 @@ var OPENCODE_VAULT_GRANT_COMMAND = `ck auth grant --principal enrolled:${OPENCOD
24358
24566
  // src/setup.ts
24359
24567
  var PI_PLACEHOLDER_KEY = "antigravity-vault-custody";
24360
24568
  function nativeAuthPath(host, context) {
24361
- return host === "opencode" ? nativeOpenCodeAuthPath() : join15(context.piAgentDir, "auth.json");
24569
+ return host === "opencode" ? nativeOpenCodeAuthPath() : join17(context.piAgentDir, "auth.json");
24362
24570
  }
24363
24571
  function provider(host) {
24364
24572
  return host === "opencode" ? OPENCODE_VAULT_PROVIDER : ANTIGRAVITY_PROVIDER_ID;
@@ -24479,7 +24687,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
24479
24687
  const { openPiSlot: openPiSlot2 } = await loadCommonAuthPiSlot();
24480
24688
  if ((await openPiSlot2({
24481
24689
  authPath: nativeAuthPath(host, context),
24482
- stashPath: join15(piDir, "google-login-stash.json"),
24690
+ stashPath: join17(piDir, "google-login-stash.json"),
24483
24691
  provider: ANTIGRAVITY_PROVIDER_ID,
24484
24692
  placeholderKey: PI_PLACEHOLDER_KEY
24485
24693
  }).inspect()).slot === "placeholder")
@@ -24516,7 +24724,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
24516
24724
  const { openPiSlot: openPiSlot2 } = await loadCommonAuthPiSlot();
24517
24725
  const inspection = await openPiSlot2({
24518
24726
  authPath: nativeAuthPath("pi", context),
24519
- stashPath: join15(piDir, "google-login-stash.json"),
24727
+ stashPath: join17(piDir, "google-login-stash.json"),
24520
24728
  provider: ANTIGRAVITY_PROVIDER_ID,
24521
24729
  placeholderKey: PI_PLACEHOLDER_KEY
24522
24730
  }).inspect();
@@ -24635,7 +24843,7 @@ Setup has not completed the OpenCode 2 native Google connection.
24635
24843
  await assertSetupHostsStopped();
24636
24844
  await openPiSlot2({
24637
24845
  authPath: nativeAuthPath(host, context),
24638
- stashPath: join15(piDir, "google-login-stash.json"),
24846
+ stashPath: join17(piDir, "google-login-stash.json"),
24639
24847
  provider: ANTIGRAVITY_PROVIDER_ID,
24640
24848
  placeholderKey: PI_PLACEHOLDER_KEY
24641
24849
  }).enterVault();