@cortexkit/opencode-antigravity-auth 3.1.2 → 3.1.5

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 (64) hide show
  1. package/README.md +3 -2
  2. package/dist/cli.js +171 -80
  3. package/dist/cli.js.map +4 -4
  4. package/dist/cli.meta.json +100 -27
  5. package/dist/index.js +369 -176
  6. package/dist/index.js.map +4 -4
  7. package/dist/index.meta.json +109 -36
  8. package/dist/server.js +367 -174
  9. package/dist/server.js.map +4 -4
  10. package/dist/server.meta.json +1 -1
  11. package/dist/src/common-auth-embedded/auth-menu/login.js +4 -1
  12. package/dist/src/common-auth-embedded/fs/canonical-file-path.js +6 -2
  13. package/dist/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +2 -2
  14. package/dist/src/common-auth-embedded/routing-accessor/cache-policy.js +1 -0
  15. package/dist/src/common-auth-embedded/setup/command.js +40 -19
  16. package/dist/src/common-auth-embedded/setup/enroll.d.ts +2 -1
  17. package/dist/src/common-auth-embedded/setup/enroll.js +12 -7
  18. package/dist/src/common-auth-embedded/setup/process-fence.d.ts +9 -0
  19. package/dist/src/common-auth-embedded/setup/process-fence.js +52 -8
  20. package/dist/src/common-auth-embedded/setup/process-guard.d.ts +12 -0
  21. package/dist/src/common-auth-embedded/setup/process-guard.js +32 -0
  22. package/dist/src/common-auth-embedded/setup/register.d.ts +2 -1
  23. package/dist/src/common-auth-embedded/setup/register.js +12 -2
  24. package/dist/src/common-auth-embedded/source-output.json +69 -53
  25. package/dist/src/common-auth-embedded/store/index.d.ts +1 -1
  26. package/dist/src/common-auth-embedded/store/index.js +1 -1
  27. package/dist/src/common-auth-embedded/store/settings.d.ts +8 -0
  28. package/dist/src/common-auth-embedded/store/settings.js +14 -4
  29. package/dist/src/plugin/__fixtures__/verified-store.d.ts +1 -1
  30. package/dist/src/plugin/__fixtures__/verified-store.js +4 -4
  31. package/dist/src/plugin/shared/request-services.d.ts +1 -0
  32. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  33. package/dist/src/plugin/shared/request-services.js +81 -24
  34. package/dist/src/plugin/shared/request-services.js.map +1 -1
  35. package/dist/tui-build-map.json +1 -1
  36. package/dist/tui-ga-build-map.json +1 -1
  37. package/dist/types/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +2 -2
  38. package/dist/types/src/common-auth-embedded/setup/enroll.d.ts +2 -1
  39. package/dist/types/src/common-auth-embedded/setup/process-fence.d.ts +9 -0
  40. package/dist/types/src/common-auth-embedded/setup/process-guard.d.ts +12 -0
  41. package/dist/types/src/common-auth-embedded/setup/register.d.ts +2 -1
  42. package/dist/types/src/common-auth-embedded/store/index.d.ts +1 -1
  43. package/dist/types/src/common-auth-embedded/store/settings.d.ts +8 -0
  44. package/dist/types/src/plugin/shared/request-services.d.ts +1 -0
  45. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  46. package/package.json +2 -2
  47. package/src/common-auth-embedded/auth-menu/login.js +4 -1
  48. package/src/common-auth-embedded/fs/canonical-file-path.js +6 -2
  49. package/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +2 -2
  50. package/src/common-auth-embedded/routing-accessor/cache-policy.js +1 -0
  51. package/src/common-auth-embedded/setup/command.js +40 -19
  52. package/src/common-auth-embedded/setup/enroll.d.ts +2 -1
  53. package/src/common-auth-embedded/setup/enroll.js +12 -7
  54. package/src/common-auth-embedded/setup/process-fence.d.ts +9 -0
  55. package/src/common-auth-embedded/setup/process-fence.js +52 -8
  56. package/src/common-auth-embedded/setup/process-guard.d.ts +12 -0
  57. package/src/common-auth-embedded/setup/process-guard.js +32 -0
  58. package/src/common-auth-embedded/setup/register.d.ts +2 -1
  59. package/src/common-auth-embedded/setup/register.js +12 -2
  60. package/src/common-auth-embedded/source-output.json +69 -53
  61. package/src/common-auth-embedded/store/index.d.ts +1 -1
  62. package/src/common-auth-embedded/store/index.js +1 -1
  63. package/src/common-auth-embedded/store/settings.d.ts +8 -0
  64. package/src/common-auth-embedded/store/settings.js +14 -4
package/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # `@cortexkit/opencode-antigravity-auth`
2
2
 
3
- One package for OpenCode 1.x (V1) and OpenCode 2.x general availability (GA), with server and terminal user interface (TUI) entries. Use Google sign-in for the Antigravity model catalog, a local account pool with rotation and quota limits, and the `/antigravity` menu/sidebar. The bundled `antigravity-auth` CLI provides account and quota commands; read its [standalone login pool-replacement behavior](docs/COMMANDS.md#standalone-cli) before using it with an existing pool.
3
+ > [!CAUTION]
4
+ > **Using this plugin can get your Google account suspended.** Using it, or any proxy for Antigravity, violates Google's Terms of Service. Since mid-November 2026, users report that Google is suspending whole Google accounts for Antigravity use through third-party tools, with `403 PERMISSION_DENIED` / `TOS_VIOLATION`; the suspension also blocks Google's own Antigravity CLI ([#74](https://github.com/cortexkit/antigravity-auth/issues/74)). Earlier reports include bans and shadow-bans. Don't use an account you can't afford to lose. The project is not endorsed by Google; use it at your own risk. Never include credentials, account files, or raw request/response dumps in Git or support reports.
4
5
 
5
- > Using this plugin or any proxy for Antigravity violates Google's Terms of Service. Account holders have reported suspensions, bans, and shadow-bans. The project is not endorsed by Google; use it at your own risk. Never include credentials, account files, or raw request/response dumps in Git or support reports.
6
+ One package for OpenCode 1.x (V1) and OpenCode 2.x general availability (GA), with server and terminal user interface (TUI) entries. Use Google sign-in for the Antigravity model catalog, a local account pool with rotation and quota limits, and the `/antigravity` menu/sidebar. The bundled `antigravity-auth` CLI provides account and quota commands; read its [standalone login pool-replacement behavior](docs/COMMANDS.md#standalone-cli) before using it with an existing pool.
6
7
 
7
8
  This guide describes the current source tree, not an announcement that an unreleased version is available on npm. See the [project overview](../../README.md) and [current models and evidence caveats](docs/MODEL-VARIANTS.md): Gemini 4 Carbon and Argon offer Low, Medium and High; their MEDIUM/HIGH thinking levels and toolConfig omission remain unverified live. Carbon defaults to 262,144 output tokens and uses the ordinary Gemini quota pool until a Carbon bucket is observed.
8
9
 
package/dist/cli.js CHANGED
@@ -759,12 +759,12 @@ async function replaceWindowsFile(from, to, options = {}) {
759
759
  const delays = [0, 10, 20, 40, 80, 100];
760
760
  let original;
761
761
  let attempts2 = 0;
762
- for (const delay3 of delays) {
762
+ for (const delay4 of delays) {
763
763
  const deadline = Math.min(retryDeadline ?? Infinity, leaseDeadline);
764
764
  if (now() >= deadline)
765
765
  break;
766
- if (delay3)
767
- await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay3, Math.max(0, deadline - now())));
766
+ if (delay4)
767
+ await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay4, Math.max(0, deadline - now())));
768
768
  if (now() >= deadline)
769
769
  break;
770
770
  const fenceStart = now();
@@ -6989,9 +6989,9 @@ async function acquireWithRetry(path2, sleep3) {
6989
6989
  return lock;
6990
6990
  }
6991
6991
  if (attempt < RETRY_DELAYS_MS.length) {
6992
- const delay3 = RETRY_DELAYS_MS[attempt];
6993
- if (delay3 !== void 0) {
6994
- await sleep3(delay3);
6992
+ const delay4 = RETRY_DELAYS_MS[attempt];
6993
+ if (delay4 !== void 0) {
6994
+ await sleep3(delay4);
6995
6995
  }
6996
6996
  }
6997
6997
  }
@@ -13391,11 +13391,11 @@ var init_quota_writer = __esm({
13391
13391
  overlay(rows) {
13392
13392
  return rows.map((row) => this.overlayRow(row));
13393
13393
  }
13394
- schedule(delay3) {
13394
+ schedule(delay4) {
13395
13395
  if (this.running || this.timer || !this.pending.size || this.stopped)
13396
13396
  return;
13397
13397
  const remaining = this.closed ? 0 : (this.committedAt ?? -Infinity) + QUOTA_COMMIT_INTERVAL_MS - this.clock.now();
13398
- this.timer = this.clock.schedule(Math.max(delay3, remaining), () => {
13398
+ this.timer = this.clock.schedule(Math.max(delay4, remaining), () => {
13399
13399
  this.timer = void 0;
13400
13400
  return this.flush();
13401
13401
  });
@@ -13495,8 +13495,8 @@ var init_quota_writer = __esm({
13495
13495
  this.running = void 0;
13496
13496
  for (const wake of this.wake)
13497
13497
  wake();
13498
- const delay3 = this.failures ? Math.min(5e3, 100 * 2 ** Math.min(this.failures, 6)) * (0.5 + Math.random()) : COALESCE_MS;
13499
- this.schedule(delay3);
13498
+ const delay4 = this.failures ? Math.min(5e3, 100 * 2 ** Math.min(this.failures, 6)) * (0.5 + Math.random()) : COALESCE_MS;
13499
+ this.schedule(delay4);
13500
13500
  }
13501
13501
  })();
13502
13502
  return this.running;
@@ -13844,14 +13844,17 @@ function settingsRefusal(message) {
13844
13844
  message
13845
13845
  });
13846
13846
  }
13847
- async function readPoolSettings(rt) {
13848
- const read = async ([configPath = rt.ctx.configPath] = []) => {
13849
- const result2 = await readPoolConfig(configPath);
13847
+ function readPoolSettings(rt) {
13848
+ return readPoolSettingsAt(rt.ctx.configPath);
13849
+ }
13850
+ async function readPoolSettingsAt(configPath) {
13851
+ const read = async ([path2 = configPath] = []) => {
13852
+ const result2 = await readPoolConfig(path2);
13850
13853
  if (result2.status === "error")
13851
13854
  return { status: "error", file: "config", reason: result2.reason };
13852
13855
  return { status: result2.status, settings: settingsOf2(result2.config) };
13853
13856
  };
13854
- const result = windowsPrivateFiles ? await read() : await settingsCache.read([rt.ctx.configPath], read);
13857
+ const result = windowsPrivateFiles ? await read() : await settingsCache.read([configPath], read);
13855
13858
  return structuredClone(result);
13856
13859
  }
13857
13860
  async function updatePoolSettings(rt, mutator, options = {}) {
@@ -14064,6 +14067,7 @@ __export(store_exports, {
14064
14067
  countUnknownIdentityRows: () => countUnknownIdentityRows,
14065
14068
  fingerprintOf: () => fingerprintOf,
14066
14069
  openPoolStore: () => openPoolStore,
14070
+ readPoolSettingsAt: () => readPoolSettingsAt,
14067
14071
  rowLockKey: () => rowLockKey
14068
14072
  });
14069
14073
  var init_store = __esm({
@@ -14081,6 +14085,9 @@ var init_store = __esm({
14081
14085
 
14082
14086
  // ../core/dist/common-auth-embedded/fs/canonical-file-path.js
14083
14087
  import { basename as basename4, dirname as dirname9, join as join7, resolve as resolve7 } from "node:path";
14088
+ function symlinkLoop(file) {
14089
+ return Object.assign(new Error(`ELOOP: too many symbolic links encountered, realpath '${file}'`), { code: "ELOOP", syscall: "realpath", path: file });
14090
+ }
14084
14091
  async function canonicalFilePath(file, fs3) {
14085
14092
  let target = file;
14086
14093
  for (let hops = 0; ; hops++) {
@@ -14096,7 +14103,7 @@ async function canonicalFilePath(file, fs3) {
14096
14103
  if (!isSymlink)
14097
14104
  return target;
14098
14105
  if (hops >= maxSymlinkHops)
14099
- throw new Error("Too many file symlink hops");
14106
+ throw symlinkLoop(file);
14100
14107
  target = resolve7(dirname9(target), await fs3.readlink(target));
14101
14108
  }
14102
14109
  }
@@ -14115,7 +14122,7 @@ function canonicalFilePathSync(file, fs3) {
14115
14122
  if (!isSymlink)
14116
14123
  return target;
14117
14124
  if (hops >= maxSymlinkHops)
14118
- throw new Error("Too many file symlink hops");
14125
+ throw symlinkLoop(file);
14119
14126
  target = resolve7(dirname9(target), fs3.readlinkSync(target));
14120
14127
  }
14121
14128
  }
@@ -16229,11 +16236,12 @@ var init_doctor = __esm({
16229
16236
 
16230
16237
  // ../core/dist/common-auth-embedded/auth-menu/login.js
16231
16238
  import { spawn as defaultSpawn } from "node:child_process";
16239
+ import { win32 } from "node:path";
16232
16240
  function openBrowserForMenu(url, platform = process.platform, spawn2 = defaultSpawn) {
16233
16241
  try {
16234
16242
  if (platform === "win32") {
16235
16243
  const command = `Start-Process '${url.replaceAll("'", "''")}'`;
16236
- const child2 = spawn2("powershell.exe", [
16244
+ const child2 = spawn2(win32.resolve(process.env.SystemRoot ?? process.env.windir ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe"), [
16237
16245
  "-NoProfile",
16238
16246
  "-NonInteractive",
16239
16247
  "-WindowStyle",
@@ -17176,12 +17184,12 @@ var init_watch = __esm({
17176
17184
  this.#options.logger?.debug("claustrum vault watch", { mode, reason });
17177
17185
  this.#options.onMode?.(mode);
17178
17186
  }
17179
- #later(delay3, run) {
17187
+ #later(delay4, run) {
17180
17188
  this.#timer = (this.#options.setTimeoutImpl ?? setTimeout)(() => {
17181
17189
  this.#timer = void 0;
17182
17190
  if (!this.#stopped)
17183
17191
  run();
17184
- }, delay3);
17192
+ }, delay4);
17185
17193
  this.#timer.unref?.();
17186
17194
  }
17187
17195
  async #open(resubscribed) {
@@ -17253,10 +17261,10 @@ var init_watch = __esm({
17253
17261
  const now = (this.#options.now ?? Date.now)();
17254
17262
  if (watch.acceptedAt !== void 0 && now - watch.acceptedAt >= SAFETY_POLL_MS)
17255
17263
  this.#closes = 0;
17256
- const delay3 = Math.min(RESUBSCRIBE_BACKOFF_MS * 2 ** Math.min(this.#closes, 16), WATCH_RETRY_MS);
17264
+ const delay4 = Math.min(RESUBSCRIBE_BACKOFF_MS * 2 ** Math.min(this.#closes, 16), WATCH_RETRY_MS);
17257
17265
  this.#closes++;
17258
17266
  this.#setMode("polling", "resubscribing");
17259
- this.#later(delay3, () => void this.#open(true));
17267
+ this.#later(delay4, () => void this.#open(true));
17260
17268
  return;
17261
17269
  }
17262
17270
  this.#fallback(end.kind);
@@ -17547,12 +17555,12 @@ var init_insula = __esm({
17547
17555
  watch?.handle?.stop();
17548
17556
  this.#mode = "polling";
17549
17557
  }
17550
- #later(delay3) {
17558
+ #later(delay4) {
17551
17559
  this.#timer = (this.#timers.setTimeoutImpl ?? setTimeout)(() => {
17552
17560
  this.#timer = void 0;
17553
17561
  if (this.#watchers > 0 && !this.#watch)
17554
17562
  this.#open();
17555
- }, delay3);
17563
+ }, delay4);
17556
17564
  this.#timer.unref?.();
17557
17565
  }
17558
17566
  #open() {
@@ -17600,10 +17608,10 @@ var init_insula = __esm({
17600
17608
  return;
17601
17609
  }
17602
17610
  if (watch.notices > 0) {
17603
- const delay3 = Math.min(RESUBSCRIBE_BACKOFF_MS * 2 ** Math.min(this.#closes, 16), WATCH_RETRY_MS);
17611
+ const delay4 = Math.min(RESUBSCRIBE_BACKOFF_MS * 2 ** Math.min(this.#closes, 16), WATCH_RETRY_MS);
17604
17612
  this.#closes++;
17605
17613
  this.#mode = "polling";
17606
- this.#later(delay3);
17614
+ this.#later(delay4);
17607
17615
  return;
17608
17616
  }
17609
17617
  this.#mode = "fallback";
@@ -19292,9 +19300,9 @@ var init_custody = __esm({
19292
19300
  users: 0,
19293
19301
  error,
19294
19302
  pending: Promise.resolve().then(async () => {
19295
- let delay3 = 250;
19303
+ let delay4 = 250;
19296
19304
  for (; ; ) {
19297
- await this.#receiptBackoff(delay3, controller.signal);
19305
+ await this.#receiptBackoff(delay4, controller.signal);
19298
19306
  try {
19299
19307
  return await this.#authorizeFresh(identity3, token, controller.signal);
19300
19308
  } catch (failure) {
@@ -19302,7 +19310,7 @@ var init_custody = __esm({
19302
19310
  if (classifyVaultFailure(failure) !== "unreachable")
19303
19311
  throw failure;
19304
19312
  created.error = failure;
19305
- delay3 = Math.min(delay3 * 2, 1e3);
19313
+ delay4 = Math.min(delay4 * 2, 1e3);
19306
19314
  }
19307
19315
  }
19308
19316
  })
@@ -19356,7 +19364,7 @@ var init_custody = __esm({
19356
19364
  }
19357
19365
  }
19358
19366
  }
19359
- #receiptBackoff(delay3, signal) {
19367
+ #receiptBackoff(delay4, signal) {
19360
19368
  this.#check(signal);
19361
19369
  return new Promise((resolve25, reject) => {
19362
19370
  const abort = () => {
@@ -19367,7 +19375,7 @@ var init_custody = __esm({
19367
19375
  const timer = this.#setTimeout(() => {
19368
19376
  signal.removeEventListener("abort", abort);
19369
19377
  resolve25();
19370
- }, delay3);
19378
+ }, delay4);
19371
19379
  timer.unref?.();
19372
19380
  signal.addEventListener("abort", abort, { once: true });
19373
19381
  if (signal.aborted)
@@ -20391,11 +20399,11 @@ function pendingVaultQuota(path2, roster) {
20391
20399
  function hasPendingVaultQuota(path2) {
20392
20400
  return !!writers.get(resolve11(path2))?.pending.size;
20393
20401
  }
20394
- function schedule(writer, delay3) {
20402
+ function schedule(writer, delay4) {
20395
20403
  if (writer.running || writer.timer || !writer.pending.size || writer.abort.signal.aborted)
20396
20404
  return;
20397
20405
  const remaining = writer.draining ? 0 : (writer.committedAt ?? -Infinity) + QUOTA_COMMIT_INTERVAL_MS - writer.clock.now();
20398
- writer.timer = writer.clock.schedule(Math.max(delay3, remaining), () => {
20406
+ writer.timer = writer.clock.schedule(Math.max(delay4, remaining), () => {
20399
20407
  writer.timer = void 0;
20400
20408
  return flush(writer);
20401
20409
  });
@@ -20832,13 +20840,13 @@ var init_consumer = __esm({
20832
20840
  }
20833
20841
  if (this.#shutdown.signal.aborted)
20834
20842
  return;
20835
- const delay3 = this.#options.pollIntervalMs ?? 5e3;
20836
- if (delay3 <= 0)
20843
+ const delay4 = this.#options.pollIntervalMs ?? 5e3;
20844
+ if (delay4 <= 0)
20837
20845
  return;
20838
20846
  this.#timer = (this.#options.setTimeoutImpl ?? setTimeout)(() => {
20839
20847
  this.#timer = void 0;
20840
20848
  void this.#track(tick());
20841
- }, delay3);
20849
+ }, delay4);
20842
20850
  this.#timer.unref?.();
20843
20851
  };
20844
20852
  void this.#track(tick());
@@ -22308,13 +22316,13 @@ var init_hub = __esm({
22308
22316
  }
22309
22317
  if (this.#shutdown.signal.aborted)
22310
22318
  return;
22311
- const delay3 = this.#options.pollIntervalMs ?? 5e3;
22312
- if (delay3 <= 0)
22319
+ const delay4 = this.#options.pollIntervalMs ?? 5e3;
22320
+ if (delay4 <= 0)
22313
22321
  return;
22314
22322
  this.#timer = (this.#options.setTimeoutImpl ?? setTimeout)(() => {
22315
22323
  this.#timer = void 0;
22316
22324
  void this.#track(this.#tick());
22317
- }, delay3);
22325
+ }, delay4);
22318
22326
  this.#timer.unref?.();
22319
22327
  }
22320
22328
  /**
@@ -22605,12 +22613,12 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
22605
22613
  if (!released && lastUpdate + RENEWAL_STALE < Date.now())
22606
22614
  compromise();
22607
22615
  }
22608
- function schedule2(delay3 = UPDATE) {
22616
+ function schedule2(delay4 = UPDATE) {
22609
22617
  if (released)
22610
22618
  return;
22611
22619
  timer = setTimeout(() => {
22612
22620
  void update();
22613
- }, delay3);
22621
+ }, delay4);
22614
22622
  timer.unref();
22615
22623
  }
22616
22624
  function retry(error) {
@@ -24379,12 +24387,12 @@ async function replaceWindowsFile2(from, to, options = {}) {
24379
24387
  const delays = [0, 10, 20, 40, 80, 100];
24380
24388
  let original;
24381
24389
  let attempts2 = 0;
24382
- for (const delay3 of delays) {
24390
+ for (const delay4 of delays) {
24383
24391
  const deadline = Math.min(retryDeadline ?? Infinity, leaseDeadline);
24384
24392
  if (now() >= deadline)
24385
24393
  break;
24386
- if (delay3)
24387
- await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay3, Math.max(0, deadline - now())));
24394
+ if (delay4)
24395
+ await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay4, Math.max(0, deadline - now())));
24388
24396
  if (now() >= deadline)
24389
24397
  break;
24390
24398
  const fenceStart = now();
@@ -26550,8 +26558,8 @@ function isWindowsSharingError(error, platform) {
26550
26558
  }
26551
26559
  async function unlinkIfIdentical(file, stateDir, guard, io = { platform: process.platform, readFile: readFile10, unlink: unlink11 }) {
26552
26560
  const started = performance.now();
26553
- for (const delay3 of SHARING_RETRY_DELAYS_MS) {
26554
- if (delay3 > 0) await new Promise((done) => setTimeout(done, delay3));
26561
+ for (const delay4 of SHARING_RETRY_DELAYS_MS) {
26562
+ if (delay4 > 0) await new Promise((done) => setTimeout(done, delay4));
26555
26563
  let same;
26556
26564
  try {
26557
26565
  same = (await io.readFile(file.old)).equals(await io.readFile(file.next));
@@ -31303,12 +31311,12 @@ import { parse } from "jsonc-parser";
31303
31311
 
31304
31312
  // src/common-auth-embedded/setup/paths.js
31305
31313
  import { homedir as homedir6 } from "node:os";
31306
- import { posix, win32 } from "node:path";
31314
+ import { posix, win32 as win322 } from "node:path";
31307
31315
  import { fileURLToPath } from "node:url";
31308
31316
  function setupPaths(io = {}) {
31309
31317
  const env3 = io.env ?? process.env;
31310
31318
  const platform = io.platform ?? process.platform;
31311
- const path2 = platform === "win32" ? win32 : posix;
31319
+ const path2 = platform === "win32" ? win322 : posix;
31312
31320
  const home = io.home ?? (platform === "win32" ? env3.USERPROFILE : env3.HOME) ?? homedir6();
31313
31321
  const cwd = io.cwd ?? process.cwd();
31314
31322
  const absolute = (value) => path2.resolve(cwd, value);
@@ -31535,7 +31543,20 @@ import { setTimeout as delay } from "node:timers/promises";
31535
31543
  import { writeEnrollmentTokenFile as writeEnrollmentTokenFile3 } from "@cortexkit/claustrum-client";
31536
31544
 
31537
31545
  // src/common-auth-embedded/setup/process-fence.js
31546
+ import { statSync as statSync6 } from "node:fs";
31547
+ import { win32 as win323 } from "node:path";
31538
31548
  var WINDOWS_CIM_TIMEOUT_MS = 45e3;
31549
+ var WINDOWS_ARM_POWERSHELL_TIMEOUT_MS = 9e4;
31550
+ function isFile(file) {
31551
+ try {
31552
+ return statSync6(file).isFile();
31553
+ } catch {
31554
+ return false;
31555
+ }
31556
+ }
31557
+ function windowsEnv(env3, name) {
31558
+ return Object.entries(env3).find(([key]) => key.toUpperCase() === name.toUpperCase())?.[1];
31559
+ }
31539
31560
  var HOSTS = /* @__PURE__ */ new Set(["opencode", "litecode", "opencode2", "pi"]);
31540
31561
  var RUNTIMES = /* @__PURE__ */ new Set(["node", "bun"]);
31541
31562
  var WINDOWS_FENCE_FILTER = [...HOSTS, ...RUNTIMES].map((name) => `Name LIKE '${name}%'`).join(" OR ");
@@ -31607,6 +31628,7 @@ function hostName(command) {
31607
31628
  var ProcessInspectionError = class extends Error {
31608
31629
  code = "process-inspection-failed";
31609
31630
  step;
31631
+ program;
31610
31632
  exitCode;
31611
31633
  signal;
31612
31634
  timedOut;
@@ -31615,6 +31637,7 @@ var ProcessInspectionError = class extends Error {
31615
31637
  super("Process inspection failed; setup cannot prove hosts are stopped.");
31616
31638
  this.name = "ProcessInspectionError";
31617
31639
  this.step = details.step;
31640
+ this.program = details.program;
31618
31641
  this.exitCode = details.exitCode;
31619
31642
  this.signal = details.signal;
31620
31643
  this.timedOut = details.timedOut;
@@ -31642,6 +31665,8 @@ Please quit all OpenCode, LiteCode, and Pi processes before running setup.`);
31642
31665
  };
31643
31666
  async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
31644
31667
  const windows = (options.platform ?? process.platform) === "win32";
31668
+ const env3 = options.env ?? process.env;
31669
+ const system32 = windows ? win323.resolve(windowsEnv(env3, "SystemRoot") ?? windowsEnv(env3, "windir") ?? "C:\\Windows", "System32") : "";
31645
31670
  const selfPid = options.selfPid ?? process.pid;
31646
31671
  let inspection = {
31647
31672
  step: windows ? "tasklist" : "ps",
@@ -31650,10 +31675,11 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
31650
31675
  timedOut: false,
31651
31676
  durationMs: 0
31652
31677
  };
31653
- const inspect = async (step, file, args, timeoutMs) => {
31678
+ const inspect = async (step, file, args, timeoutMs, program) => {
31654
31679
  const started = performance.now();
31655
31680
  inspection = {
31656
31681
  step,
31682
+ ...program && { program },
31657
31683
  exitCode: null,
31658
31684
  signal: null,
31659
31685
  timedOut: false,
@@ -31666,6 +31692,7 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
31666
31692
  });
31667
31693
  inspection = {
31668
31694
  step,
31695
+ ...program && { program },
31669
31696
  exitCode: result.exitCode,
31670
31697
  signal: result.signal ?? null,
31671
31698
  timedOut: result.timedOut ?? false,
@@ -31678,9 +31705,23 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
31678
31705
  options.onStep?.({ ...inspection });
31679
31706
  }
31680
31707
  };
31708
+ const inspectCim = (args) => {
31709
+ const pwsh = win323.resolve(windowsEnv(env3, "ProgramFiles") ?? "C:\\Program Files", "PowerShell", "7", "pwsh.exe");
31710
+ const program = (options.isFile ?? isFile)(pwsh) ? "pwsh" : "powershell";
31711
+ const arm64 = (windowsEnv(env3, "PROCESSOR_ARCHITEW6432") ?? windowsEnv(env3, "PROCESSOR_ARCHITECTURE"))?.toUpperCase() === "ARM64";
31712
+ const slow = program === "powershell" && arm64;
31713
+ if (slow)
31714
+ options.onProgress?.("Checking that OpenCode and Pi are not running. Without PowerShell 7 this can take up to a minute on Windows ARM; installing PowerShell 7 makes it fast.");
31715
+ return inspect("CIM", program === "pwsh" ? pwsh : win323.resolve(system32, "WindowsPowerShell", "v1.0", "powershell.exe"), args, slow ? WINDOWS_ARM_POWERSHELL_TIMEOUT_MS : WINDOWS_CIM_TIMEOUT_MS, program);
31716
+ };
31681
31717
  try {
31682
31718
  if (windows && options.hostImagesOnly) {
31683
- const details = await inspect("CIM", "powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", WINDOWS_FENCE_QUERY], WINDOWS_CIM_TIMEOUT_MS);
31719
+ const details = await inspectCim([
31720
+ "-NoProfile",
31721
+ "-NonInteractive",
31722
+ "-Command",
31723
+ WINDOWS_FENCE_QUERY
31724
+ ]);
31684
31725
  if (details.exitCode !== 0)
31685
31726
  throw new ProcessInspectionError(inspection);
31686
31727
  const value = JSON.parse(details.stdout);
@@ -31702,7 +31743,7 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
31702
31743
  }
31703
31744
  return processes2;
31704
31745
  }
31705
- const result = await inspect(windows ? "tasklist" : "ps", windows ? "tasklist.exe" : "ps", windows ? ["/fo", "csv", "/nh"] : ["-eo", "pid,command"]);
31746
+ const result = await inspect(windows ? "tasklist" : "ps", windows ? win323.resolve(system32, "tasklist.exe") : "ps", windows ? ["/fo", "csv", "/nh"] : ["-eo", "pid,command"]);
31706
31747
  if (result.exitCode !== 0)
31707
31748
  throw new ProcessInspectionError(inspection);
31708
31749
  const processes = [];
@@ -31736,12 +31777,12 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
31736
31777
  throw new ProcessInspectionError(inspection);
31737
31778
  const runtimes = processes.filter((entry) => entry.pid !== selfPid && /^(?:node|bun)\.exe$/i.test(entry.command));
31738
31779
  if (windows && runtimes.length && options.inspectRuntimes !== false) {
31739
- const details = await inspect("CIM", "powershell.exe", [
31780
+ const details = await inspectCim([
31740
31781
  "-NoProfile",
31741
31782
  "-NonInteractive",
31742
31783
  "-Command",
31743
31784
  `$ErrorActionPreference = 'Stop'; Get-CimInstance Win32_Process -Filter "Name = 'node.exe' OR Name = 'bun.exe'" | Select-Object ProcessId,CommandLine | ConvertTo-Json -Compress`
31744
- ], WINDOWS_CIM_TIMEOUT_MS);
31785
+ ]);
31745
31786
  if (details.exitCode !== 0)
31746
31787
  throw new ProcessInspectionError(inspection);
31747
31788
  const value = JSON.parse(details.stdout || "null");
@@ -31797,6 +31838,36 @@ async function assertHostsStopped(fence, env3) {
31797
31838
  throw new ProcessFenceViolationError(active2);
31798
31839
  }
31799
31840
 
31841
+ // src/common-auth-embedded/setup/process-guard.js
31842
+ var SetupProcessGuard = class {
31843
+ inspect;
31844
+ now;
31845
+ #checkedAt;
31846
+ constructor(inspect, now = () => performance.now()) {
31847
+ this.inspect = inspect;
31848
+ this.now = now;
31849
+ }
31850
+ async check(options = {}) {
31851
+ if (options.reuse && this.#checkedAt !== void 0) {
31852
+ const age = this.now() - this.#checkedAt;
31853
+ if (age >= 0 && age < 5e3)
31854
+ return;
31855
+ }
31856
+ this.#checkedAt = void 0;
31857
+ await this.inspect();
31858
+ this.#checkedAt = this.now();
31859
+ }
31860
+ /** Callbacks, writes and waits can all make an earlier inspection stale. */
31861
+ async step(run) {
31862
+ this.#checkedAt = void 0;
31863
+ try {
31864
+ return await run();
31865
+ } finally {
31866
+ this.#checkedAt = void 0;
31867
+ }
31868
+ }
31869
+ };
31870
+
31800
31871
  // src/common-auth-embedded/setup/enroll.js
31801
31872
  var ENROLLMENT_INCOMPLETE_MESSAGE = "Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.";
31802
31873
  var UNSUPPORTED_VAULT_MESSAGE = 'This Claustrum vault is too old to connect plugins. Run ck upgrade to move to Claustrum v0.2.0 or newer (read "Upgrading from v0.1.3" in its release notes first), or run setup without --claustrum to use local accounts.';
@@ -31825,7 +31896,8 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31825
31896
  throw new Error(VAULT_HOST_CONNECT_REFUSAL2);
31826
31897
  const { name, displayName, requestedGrants, grantFallback, paths: input } = plugin.vault.hosts[host];
31827
31898
  const paths = hostEnrollmentPaths2(input);
31828
- await fence();
31899
+ const guard = typeof fence === "function" ? new SetupProcessGuard(fence, io.now) : fence;
31900
+ await guard.check({ reuse: true });
31829
31901
  const client = await (io.connect ?? connectClaustrumEnrollmentClient2)({
31830
31902
  connectionFile: plugin.vault.connectionFile,
31831
31903
  handshakeTimeoutMs: 2e3
@@ -31846,11 +31918,10 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31846
31918
  // starts PowerShell.
31847
31919
  client,
31848
31920
  writeTokenFile: async (path2, file) => {
31849
- await fence();
31850
- await writeEnrollmentTokenFile3(path2, file);
31921
+ await guard.check();
31922
+ await guard.step(() => writeEnrollmentTokenFile3(path2, file));
31851
31923
  }
31852
31924
  });
31853
- await fence();
31854
31925
  const initial = await manager.status();
31855
31926
  if (initial.state === "approved") {
31856
31927
  printLine2(terminal, `Already connected as ${initial.approvedName ?? initial.proposedName}.`);
@@ -31867,7 +31938,8 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31867
31938
  let reportedCode;
31868
31939
  let failedProposals = 0;
31869
31940
  for (; ; ) {
31870
- const status = await manager.reconcile();
31941
+ await guard.check({ reuse: true });
31942
+ const status = await guard.step(() => manager.reconcile());
31871
31943
  if (status.state === "approved") {
31872
31944
  printLine2(terminal, `Connected ${host} to Claustrum.`);
31873
31945
  const access = await confirmEnrollmentAccess(client, status, paths.tokenPath, requestedGrants);
@@ -31915,8 +31987,8 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31915
31987
  const remaining = deadline - now();
31916
31988
  if (remaining <= 0)
31917
31989
  break;
31918
- await wait2(Math.min(pause, remaining));
31919
- await fence();
31990
+ await guard.step(() => wait2(Math.min(pause, remaining)));
31991
+ await guard.check();
31920
31992
  }
31921
31993
  if (printedRequest)
31922
31994
  throw new HostNotEnrolledError(`Claustrum approval is still pending. In another terminal, run: ${approveCommand(printedRequest, name)} and then rerun setup.`, {
@@ -32066,6 +32138,8 @@ async function selectSetupHosts(terminal, found) {
32066
32138
  }
32067
32139
 
32068
32140
  // src/common-auth-embedded/setup/register.js
32141
+ import { rename as rename14 } from "node:fs/promises";
32142
+ import { setTimeout as delay3 } from "node:timers/promises";
32069
32143
  import { domainToUnicode } from "node:url";
32070
32144
  import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2, parseTree } from "jsonc-parser";
32071
32145
 
@@ -32275,12 +32349,15 @@ function planOpenCodeRegistration(plugin, generation, io = {}) {
32275
32349
  });
32276
32350
  }
32277
32351
  async function registerOpenCode(writes, beforeWrite) {
32352
+ const guard = typeof beforeWrite === "function" ? new SetupProcessGuard(beforeWrite) : beforeWrite;
32278
32353
  for (const write of writes) {
32279
32354
  if (!write.changed)
32280
32355
  continue;
32281
- await beforeWrite?.();
32282
32356
  await writeHostConfigAtomic(write.path, write.content, {
32283
- beforeRename: beforeWrite
32357
+ // Only the rename publishes host-readable config; recheck on every retry.
32358
+ beforeRename: guard ? () => guard.check({ reuse: true }) : void 0,
32359
+ rename: guard ? (from, to) => guard.step(() => rename14(from, to)) : void 0,
32360
+ wait: guard ? (ms) => guard.step(() => delay3(ms)) : void 0
32284
32361
  });
32285
32362
  }
32286
32363
  }
@@ -32379,7 +32456,11 @@ async function runSetup(plugin, argv = [], io = {}) {
32379
32456
  return { hosts, dryRun: options.dryRun, mode: "local", detection };
32380
32457
  }
32381
32458
  const { env: env3, platform } = setupPaths(io);
32382
- const fence = io.fence ?? createProcessFence(io.runner ?? defaultCommandRunner, { platform });
32459
+ const fence = io.fence ?? createProcessFence(io.runner ?? defaultCommandRunner, {
32460
+ platform,
32461
+ isFile: io.fs?.isFile.bind(io.fs),
32462
+ onProgress: (line) => printLine2(terminal, line)
32463
+ });
32383
32464
  const stopped = async () => {
32384
32465
  try {
32385
32466
  await assertHostsStopped(fence, env3);
@@ -32389,6 +32470,7 @@ async function runSetup(plugin, argv = [], io = {}) {
32389
32470
  throw error;
32390
32471
  }
32391
32472
  };
32473
+ const guard = new SetupProcessGuard(stopped, io.now);
32392
32474
  printLine2(terminal, "Checking that OpenCode and Pi are not running\u2026");
32393
32475
  if (options.dryRun) {
32394
32476
  try {
@@ -32404,16 +32486,17 @@ async function runSetup(plugin, argv = [], io = {}) {
32404
32486
  if (error instanceof ProcessInspectionError)
32405
32487
  printLine2(terminal, error.refusalText);
32406
32488
  }
32407
- } else
32408
- await stopped();
32489
+ } else {
32490
+ await guard.check();
32491
+ }
32409
32492
  if ((options.claustrum || options.enrollOnly) && !detection.claustrum.available)
32410
32493
  throw new Error("Claustrum is not available. Start ck, or omit vault-only flags and use --no-claustrum for local sign-in.");
32411
32494
  let useVault = options.claustrum || options.enrollOnly;
32412
32495
  if (!useVault && !options.login && !options.noClaustrum && !assumeYes && detection.claustrum.available && isInteractive2(terminal)) {
32413
- const choice = await select2(terminal, [
32496
+ const choice = await guard.step(() => select2(terminal, [
32414
32497
  { label: "No", value: false },
32415
32498
  { label: "Yes", value: true }
32416
- ], { message: "Connect these hosts to the Claustrum vault?" });
32499
+ ], { message: "Connect these hosts to the Claustrum vault?" }));
32417
32500
  if (choice === null) {
32418
32501
  printLine2(terminal, "Setup cancelled. Nothing was changed.");
32419
32502
  return { hosts: [], dryRun: options.dryRun, mode: "local", detection };
@@ -32464,13 +32547,14 @@ ${write.content}`);
32464
32547
  const enrollmentAccess = /* @__PURE__ */ new Map();
32465
32548
  try {
32466
32549
  for (const host of hosts) {
32467
- await stopped();
32468
- await plugin.beforeSignIn?.(host, context);
32469
- await stopped();
32550
+ if (plugin.beforeSignIn) {
32551
+ await guard.check({ reuse: true });
32552
+ await guard.step(() => plugin.beforeSignIn?.(host, context));
32553
+ }
32470
32554
  if (useVault) {
32471
32555
  enrollment.set(host, "unknown");
32472
32556
  try {
32473
- const access = await connectSetupHost(plugin, host, io, terminal, stopped);
32557
+ const access = await connectSetupHost(plugin, host, io, terminal, guard);
32474
32558
  if (access)
32475
32559
  enrollmentAccess.set(host, access);
32476
32560
  } catch (error) {
@@ -32479,19 +32563,26 @@ ${write.content}`);
32479
32563
  throw error;
32480
32564
  }
32481
32565
  enrollment.set(host, "enrolled");
32482
- } else
32483
- await plugin.signInLocal(host, context);
32484
- await stopped();
32566
+ } else {
32567
+ await guard.check({ reuse: true });
32568
+ await guard.step(() => plugin.signInLocal(host, context));
32569
+ }
32485
32570
  if (options.enrollOnly)
32486
32571
  continue;
32487
- await plugin.beforeRegister?.(host, mode, context);
32488
- await stopped();
32572
+ if (plugin.beforeRegister) {
32573
+ await guard.check({ reuse: true });
32574
+ await guard.step(() => plugin.beforeRegister?.(host, mode, context));
32575
+ }
32489
32576
  if (host === "opencode")
32490
- await registerOpenCode(writes, stopped);
32491
- else
32492
- await registerPi(plugin, detection.pi.executable, io);
32493
- await stopped();
32494
- await plugin.migrate?.(host, context);
32577
+ await registerOpenCode(writes, guard);
32578
+ else {
32579
+ await guard.check({ reuse: true });
32580
+ await guard.step(() => registerPi(plugin, detection.pi.executable, io));
32581
+ }
32582
+ if (plugin.migrate) {
32583
+ await guard.check({ reuse: true });
32584
+ await guard.step(() => plugin.migrate?.(host, context));
32585
+ }
32495
32586
  }
32496
32587
  } catch (error) {
32497
32588
  if (enrollment.size === 0)