@cortexkit/opencode-antigravity-auth 3.1.4 → 3.1.7

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 (58) hide show
  1. package/README.md +3 -2
  2. package/dist/cli.js +158 -74
  3. package/dist/cli.js.map +4 -4
  4. package/dist/cli.meta.json +92 -19
  5. package/dist/index.js +263 -106
  6. package/dist/index.js.map +4 -4
  7. package/dist/index.meta.json +104 -31
  8. package/dist/server.js +262 -104
  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/routing-accessor/cache-policy.d.ts +2 -2
  13. package/dist/src/common-auth-embedded/routing-accessor/cache-policy.js +1 -0
  14. package/dist/src/common-auth-embedded/setup/command.js +40 -19
  15. package/dist/src/common-auth-embedded/setup/enroll.d.ts +2 -1
  16. package/dist/src/common-auth-embedded/setup/enroll.js +12 -7
  17. package/dist/src/common-auth-embedded/setup/process-fence.d.ts +9 -0
  18. package/dist/src/common-auth-embedded/setup/process-fence.js +52 -8
  19. package/dist/src/common-auth-embedded/setup/process-guard.d.ts +12 -0
  20. package/dist/src/common-auth-embedded/setup/process-guard.js +32 -0
  21. package/dist/src/common-auth-embedded/setup/register.d.ts +2 -1
  22. package/dist/src/common-auth-embedded/setup/register.js +12 -2
  23. package/dist/src/common-auth-embedded/source-output.json +54 -38
  24. package/dist/src/ga/server/index.d.ts +1 -1
  25. package/dist/src/ga/server/index.d.ts.map +1 -1
  26. package/dist/src/ga/server/index.js +6 -0
  27. package/dist/src/ga/server/index.js.map +1 -1
  28. package/dist/src/plugin/__fixtures__/verified-store.d.ts +1 -1
  29. package/dist/src/plugin/__fixtures__/verified-store.js +4 -4
  30. package/dist/src/plugin/request-helpers.js +3 -3
  31. package/dist/src/plugin/request-helpers.js.map +1 -1
  32. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  33. package/dist/src/plugin/shared/request-services.js +5 -2
  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/ga/server/index.d.ts +1 -1
  43. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  44. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  45. package/package.json +2 -2
  46. package/src/common-auth-embedded/auth-menu/login.js +4 -1
  47. package/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +2 -2
  48. package/src/common-auth-embedded/routing-accessor/cache-policy.js +1 -0
  49. package/src/common-auth-embedded/setup/command.js +40 -19
  50. package/src/common-auth-embedded/setup/enroll.d.ts +2 -1
  51. package/src/common-auth-embedded/setup/enroll.js +12 -7
  52. package/src/common-auth-embedded/setup/process-fence.d.ts +9 -0
  53. package/src/common-auth-embedded/setup/process-fence.js +52 -8
  54. package/src/common-auth-embedded/setup/process-guard.d.ts +12 -0
  55. package/src/common-auth-embedded/setup/process-guard.js +32 -0
  56. package/src/common-auth-embedded/setup/register.d.ts +2 -1
  57. package/src/common-auth-embedded/setup/register.js +12 -2
  58. package/src/common-auth-embedded/source-output.json +54 -38
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;
@@ -16236,11 +16236,12 @@ var init_doctor = __esm({
16236
16236
 
16237
16237
  // ../core/dist/common-auth-embedded/auth-menu/login.js
16238
16238
  import { spawn as defaultSpawn } from "node:child_process";
16239
+ import { win32 } from "node:path";
16239
16240
  function openBrowserForMenu(url, platform = process.platform, spawn2 = defaultSpawn) {
16240
16241
  try {
16241
16242
  if (platform === "win32") {
16242
16243
  const command = `Start-Process '${url.replaceAll("'", "''")}'`;
16243
- 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"), [
16244
16245
  "-NoProfile",
16245
16246
  "-NonInteractive",
16246
16247
  "-WindowStyle",
@@ -17183,12 +17184,12 @@ var init_watch = __esm({
17183
17184
  this.#options.logger?.debug("claustrum vault watch", { mode, reason });
17184
17185
  this.#options.onMode?.(mode);
17185
17186
  }
17186
- #later(delay3, run) {
17187
+ #later(delay4, run) {
17187
17188
  this.#timer = (this.#options.setTimeoutImpl ?? setTimeout)(() => {
17188
17189
  this.#timer = void 0;
17189
17190
  if (!this.#stopped)
17190
17191
  run();
17191
- }, delay3);
17192
+ }, delay4);
17192
17193
  this.#timer.unref?.();
17193
17194
  }
17194
17195
  async #open(resubscribed) {
@@ -17260,10 +17261,10 @@ var init_watch = __esm({
17260
17261
  const now = (this.#options.now ?? Date.now)();
17261
17262
  if (watch.acceptedAt !== void 0 && now - watch.acceptedAt >= SAFETY_POLL_MS)
17262
17263
  this.#closes = 0;
17263
- 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);
17264
17265
  this.#closes++;
17265
17266
  this.#setMode("polling", "resubscribing");
17266
- this.#later(delay3, () => void this.#open(true));
17267
+ this.#later(delay4, () => void this.#open(true));
17267
17268
  return;
17268
17269
  }
17269
17270
  this.#fallback(end.kind);
@@ -17554,12 +17555,12 @@ var init_insula = __esm({
17554
17555
  watch?.handle?.stop();
17555
17556
  this.#mode = "polling";
17556
17557
  }
17557
- #later(delay3) {
17558
+ #later(delay4) {
17558
17559
  this.#timer = (this.#timers.setTimeoutImpl ?? setTimeout)(() => {
17559
17560
  this.#timer = void 0;
17560
17561
  if (this.#watchers > 0 && !this.#watch)
17561
17562
  this.#open();
17562
- }, delay3);
17563
+ }, delay4);
17563
17564
  this.#timer.unref?.();
17564
17565
  }
17565
17566
  #open() {
@@ -17607,10 +17608,10 @@ var init_insula = __esm({
17607
17608
  return;
17608
17609
  }
17609
17610
  if (watch.notices > 0) {
17610
- 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);
17611
17612
  this.#closes++;
17612
17613
  this.#mode = "polling";
17613
- this.#later(delay3);
17614
+ this.#later(delay4);
17614
17615
  return;
17615
17616
  }
17616
17617
  this.#mode = "fallback";
@@ -19299,9 +19300,9 @@ var init_custody = __esm({
19299
19300
  users: 0,
19300
19301
  error,
19301
19302
  pending: Promise.resolve().then(async () => {
19302
- let delay3 = 250;
19303
+ let delay4 = 250;
19303
19304
  for (; ; ) {
19304
- await this.#receiptBackoff(delay3, controller.signal);
19305
+ await this.#receiptBackoff(delay4, controller.signal);
19305
19306
  try {
19306
19307
  return await this.#authorizeFresh(identity3, token, controller.signal);
19307
19308
  } catch (failure) {
@@ -19309,7 +19310,7 @@ var init_custody = __esm({
19309
19310
  if (classifyVaultFailure(failure) !== "unreachable")
19310
19311
  throw failure;
19311
19312
  created.error = failure;
19312
- delay3 = Math.min(delay3 * 2, 1e3);
19313
+ delay4 = Math.min(delay4 * 2, 1e3);
19313
19314
  }
19314
19315
  }
19315
19316
  })
@@ -19363,7 +19364,7 @@ var init_custody = __esm({
19363
19364
  }
19364
19365
  }
19365
19366
  }
19366
- #receiptBackoff(delay3, signal) {
19367
+ #receiptBackoff(delay4, signal) {
19367
19368
  this.#check(signal);
19368
19369
  return new Promise((resolve25, reject) => {
19369
19370
  const abort = () => {
@@ -19374,7 +19375,7 @@ var init_custody = __esm({
19374
19375
  const timer = this.#setTimeout(() => {
19375
19376
  signal.removeEventListener("abort", abort);
19376
19377
  resolve25();
19377
- }, delay3);
19378
+ }, delay4);
19378
19379
  timer.unref?.();
19379
19380
  signal.addEventListener("abort", abort, { once: true });
19380
19381
  if (signal.aborted)
@@ -20398,11 +20399,11 @@ function pendingVaultQuota(path2, roster) {
20398
20399
  function hasPendingVaultQuota(path2) {
20399
20400
  return !!writers.get(resolve11(path2))?.pending.size;
20400
20401
  }
20401
- function schedule(writer, delay3) {
20402
+ function schedule(writer, delay4) {
20402
20403
  if (writer.running || writer.timer || !writer.pending.size || writer.abort.signal.aborted)
20403
20404
  return;
20404
20405
  const remaining = writer.draining ? 0 : (writer.committedAt ?? -Infinity) + QUOTA_COMMIT_INTERVAL_MS - writer.clock.now();
20405
- writer.timer = writer.clock.schedule(Math.max(delay3, remaining), () => {
20406
+ writer.timer = writer.clock.schedule(Math.max(delay4, remaining), () => {
20406
20407
  writer.timer = void 0;
20407
20408
  return flush(writer);
20408
20409
  });
@@ -20839,13 +20840,13 @@ var init_consumer = __esm({
20839
20840
  }
20840
20841
  if (this.#shutdown.signal.aborted)
20841
20842
  return;
20842
- const delay3 = this.#options.pollIntervalMs ?? 5e3;
20843
- if (delay3 <= 0)
20843
+ const delay4 = this.#options.pollIntervalMs ?? 5e3;
20844
+ if (delay4 <= 0)
20844
20845
  return;
20845
20846
  this.#timer = (this.#options.setTimeoutImpl ?? setTimeout)(() => {
20846
20847
  this.#timer = void 0;
20847
20848
  void this.#track(tick());
20848
- }, delay3);
20849
+ }, delay4);
20849
20850
  this.#timer.unref?.();
20850
20851
  };
20851
20852
  void this.#track(tick());
@@ -22315,13 +22316,13 @@ var init_hub = __esm({
22315
22316
  }
22316
22317
  if (this.#shutdown.signal.aborted)
22317
22318
  return;
22318
- const delay3 = this.#options.pollIntervalMs ?? 5e3;
22319
- if (delay3 <= 0)
22319
+ const delay4 = this.#options.pollIntervalMs ?? 5e3;
22320
+ if (delay4 <= 0)
22320
22321
  return;
22321
22322
  this.#timer = (this.#options.setTimeoutImpl ?? setTimeout)(() => {
22322
22323
  this.#timer = void 0;
22323
22324
  void this.#track(this.#tick());
22324
- }, delay3);
22325
+ }, delay4);
22325
22326
  this.#timer.unref?.();
22326
22327
  }
22327
22328
  /**
@@ -22612,12 +22613,12 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
22612
22613
  if (!released && lastUpdate + RENEWAL_STALE < Date.now())
22613
22614
  compromise();
22614
22615
  }
22615
- function schedule2(delay3 = UPDATE) {
22616
+ function schedule2(delay4 = UPDATE) {
22616
22617
  if (released)
22617
22618
  return;
22618
22619
  timer = setTimeout(() => {
22619
22620
  void update();
22620
- }, delay3);
22621
+ }, delay4);
22621
22622
  timer.unref();
22622
22623
  }
22623
22624
  function retry(error) {
@@ -24386,12 +24387,12 @@ async function replaceWindowsFile2(from, to, options = {}) {
24386
24387
  const delays = [0, 10, 20, 40, 80, 100];
24387
24388
  let original;
24388
24389
  let attempts2 = 0;
24389
- for (const delay3 of delays) {
24390
+ for (const delay4 of delays) {
24390
24391
  const deadline = Math.min(retryDeadline ?? Infinity, leaseDeadline);
24391
24392
  if (now() >= deadline)
24392
24393
  break;
24393
- if (delay3)
24394
- 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())));
24395
24396
  if (now() >= deadline)
24396
24397
  break;
24397
24398
  const fenceStart = now();
@@ -26557,8 +26558,8 @@ function isWindowsSharingError(error, platform) {
26557
26558
  }
26558
26559
  async function unlinkIfIdentical(file, stateDir, guard, io = { platform: process.platform, readFile: readFile10, unlink: unlink11 }) {
26559
26560
  const started = performance.now();
26560
- for (const delay3 of SHARING_RETRY_DELAYS_MS) {
26561
- 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));
26562
26563
  let same;
26563
26564
  try {
26564
26565
  same = (await io.readFile(file.old)).equals(await io.readFile(file.next));
@@ -31310,12 +31311,12 @@ import { parse } from "jsonc-parser";
31310
31311
 
31311
31312
  // src/common-auth-embedded/setup/paths.js
31312
31313
  import { homedir as homedir6 } from "node:os";
31313
- import { posix, win32 } from "node:path";
31314
+ import { posix, win32 as win322 } from "node:path";
31314
31315
  import { fileURLToPath } from "node:url";
31315
31316
  function setupPaths(io = {}) {
31316
31317
  const env3 = io.env ?? process.env;
31317
31318
  const platform = io.platform ?? process.platform;
31318
- const path2 = platform === "win32" ? win32 : posix;
31319
+ const path2 = platform === "win32" ? win322 : posix;
31319
31320
  const home = io.home ?? (platform === "win32" ? env3.USERPROFILE : env3.HOME) ?? homedir6();
31320
31321
  const cwd = io.cwd ?? process.cwd();
31321
31322
  const absolute = (value) => path2.resolve(cwd, value);
@@ -31542,7 +31543,20 @@ import { setTimeout as delay } from "node:timers/promises";
31542
31543
  import { writeEnrollmentTokenFile as writeEnrollmentTokenFile3 } from "@cortexkit/claustrum-client";
31543
31544
 
31544
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";
31545
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
+ }
31546
31560
  var HOSTS = /* @__PURE__ */ new Set(["opencode", "litecode", "opencode2", "pi"]);
31547
31561
  var RUNTIMES = /* @__PURE__ */ new Set(["node", "bun"]);
31548
31562
  var WINDOWS_FENCE_FILTER = [...HOSTS, ...RUNTIMES].map((name) => `Name LIKE '${name}%'`).join(" OR ");
@@ -31614,6 +31628,7 @@ function hostName(command) {
31614
31628
  var ProcessInspectionError = class extends Error {
31615
31629
  code = "process-inspection-failed";
31616
31630
  step;
31631
+ program;
31617
31632
  exitCode;
31618
31633
  signal;
31619
31634
  timedOut;
@@ -31622,6 +31637,7 @@ var ProcessInspectionError = class extends Error {
31622
31637
  super("Process inspection failed; setup cannot prove hosts are stopped.");
31623
31638
  this.name = "ProcessInspectionError";
31624
31639
  this.step = details.step;
31640
+ this.program = details.program;
31625
31641
  this.exitCode = details.exitCode;
31626
31642
  this.signal = details.signal;
31627
31643
  this.timedOut = details.timedOut;
@@ -31649,6 +31665,8 @@ Please quit all OpenCode, LiteCode, and Pi processes before running setup.`);
31649
31665
  };
31650
31666
  async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
31651
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") : "";
31652
31670
  const selfPid = options.selfPid ?? process.pid;
31653
31671
  let inspection = {
31654
31672
  step: windows ? "tasklist" : "ps",
@@ -31657,10 +31675,11 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
31657
31675
  timedOut: false,
31658
31676
  durationMs: 0
31659
31677
  };
31660
- const inspect = async (step, file, args, timeoutMs) => {
31678
+ const inspect = async (step, file, args, timeoutMs, program) => {
31661
31679
  const started = performance.now();
31662
31680
  inspection = {
31663
31681
  step,
31682
+ ...program && { program },
31664
31683
  exitCode: null,
31665
31684
  signal: null,
31666
31685
  timedOut: false,
@@ -31673,6 +31692,7 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
31673
31692
  });
31674
31693
  inspection = {
31675
31694
  step,
31695
+ ...program && { program },
31676
31696
  exitCode: result.exitCode,
31677
31697
  signal: result.signal ?? null,
31678
31698
  timedOut: result.timedOut ?? false,
@@ -31685,9 +31705,23 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
31685
31705
  options.onStep?.({ ...inspection });
31686
31706
  }
31687
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
+ };
31688
31717
  try {
31689
31718
  if (windows && options.hostImagesOnly) {
31690
- 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
+ ]);
31691
31725
  if (details.exitCode !== 0)
31692
31726
  throw new ProcessInspectionError(inspection);
31693
31727
  const value = JSON.parse(details.stdout);
@@ -31709,7 +31743,7 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
31709
31743
  }
31710
31744
  return processes2;
31711
31745
  }
31712
- 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"]);
31713
31747
  if (result.exitCode !== 0)
31714
31748
  throw new ProcessInspectionError(inspection);
31715
31749
  const processes = [];
@@ -31743,12 +31777,12 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
31743
31777
  throw new ProcessInspectionError(inspection);
31744
31778
  const runtimes = processes.filter((entry) => entry.pid !== selfPid && /^(?:node|bun)\.exe$/i.test(entry.command));
31745
31779
  if (windows && runtimes.length && options.inspectRuntimes !== false) {
31746
- const details = await inspect("CIM", "powershell.exe", [
31780
+ const details = await inspectCim([
31747
31781
  "-NoProfile",
31748
31782
  "-NonInteractive",
31749
31783
  "-Command",
31750
31784
  `$ErrorActionPreference = 'Stop'; Get-CimInstance Win32_Process -Filter "Name = 'node.exe' OR Name = 'bun.exe'" | Select-Object ProcessId,CommandLine | ConvertTo-Json -Compress`
31751
- ], WINDOWS_CIM_TIMEOUT_MS);
31785
+ ]);
31752
31786
  if (details.exitCode !== 0)
31753
31787
  throw new ProcessInspectionError(inspection);
31754
31788
  const value = JSON.parse(details.stdout || "null");
@@ -31804,6 +31838,36 @@ async function assertHostsStopped(fence, env3) {
31804
31838
  throw new ProcessFenceViolationError(active2);
31805
31839
  }
31806
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
+
31807
31871
  // src/common-auth-embedded/setup/enroll.js
31808
31872
  var ENROLLMENT_INCOMPLETE_MESSAGE = "Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.";
31809
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.';
@@ -31832,7 +31896,8 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31832
31896
  throw new Error(VAULT_HOST_CONNECT_REFUSAL2);
31833
31897
  const { name, displayName, requestedGrants, grantFallback, paths: input } = plugin.vault.hosts[host];
31834
31898
  const paths = hostEnrollmentPaths2(input);
31835
- await fence();
31899
+ const guard = typeof fence === "function" ? new SetupProcessGuard(fence, io.now) : fence;
31900
+ await guard.check({ reuse: true });
31836
31901
  const client = await (io.connect ?? connectClaustrumEnrollmentClient2)({
31837
31902
  connectionFile: plugin.vault.connectionFile,
31838
31903
  handshakeTimeoutMs: 2e3
@@ -31853,11 +31918,10 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31853
31918
  // starts PowerShell.
31854
31919
  client,
31855
31920
  writeTokenFile: async (path2, file) => {
31856
- await fence();
31857
- await writeEnrollmentTokenFile3(path2, file);
31921
+ await guard.check();
31922
+ await guard.step(() => writeEnrollmentTokenFile3(path2, file));
31858
31923
  }
31859
31924
  });
31860
- await fence();
31861
31925
  const initial = await manager.status();
31862
31926
  if (initial.state === "approved") {
31863
31927
  printLine2(terminal, `Already connected as ${initial.approvedName ?? initial.proposedName}.`);
@@ -31874,7 +31938,8 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31874
31938
  let reportedCode;
31875
31939
  let failedProposals = 0;
31876
31940
  for (; ; ) {
31877
- const status = await manager.reconcile();
31941
+ await guard.check({ reuse: true });
31942
+ const status = await guard.step(() => manager.reconcile());
31878
31943
  if (status.state === "approved") {
31879
31944
  printLine2(terminal, `Connected ${host} to Claustrum.`);
31880
31945
  const access = await confirmEnrollmentAccess(client, status, paths.tokenPath, requestedGrants);
@@ -31922,8 +31987,8 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31922
31987
  const remaining = deadline - now();
31923
31988
  if (remaining <= 0)
31924
31989
  break;
31925
- await wait2(Math.min(pause, remaining));
31926
- await fence();
31990
+ await guard.step(() => wait2(Math.min(pause, remaining)));
31991
+ await guard.check();
31927
31992
  }
31928
31993
  if (printedRequest)
31929
31994
  throw new HostNotEnrolledError(`Claustrum approval is still pending. In another terminal, run: ${approveCommand(printedRequest, name)} and then rerun setup.`, {
@@ -32073,6 +32138,8 @@ async function selectSetupHosts(terminal, found) {
32073
32138
  }
32074
32139
 
32075
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";
32076
32143
  import { domainToUnicode } from "node:url";
32077
32144
  import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2, parseTree } from "jsonc-parser";
32078
32145
 
@@ -32282,12 +32349,15 @@ function planOpenCodeRegistration(plugin, generation, io = {}) {
32282
32349
  });
32283
32350
  }
32284
32351
  async function registerOpenCode(writes, beforeWrite) {
32352
+ const guard = typeof beforeWrite === "function" ? new SetupProcessGuard(beforeWrite) : beforeWrite;
32285
32353
  for (const write of writes) {
32286
32354
  if (!write.changed)
32287
32355
  continue;
32288
- await beforeWrite?.();
32289
32356
  await writeHostConfigAtomic(write.path, write.content, {
32290
- 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
32291
32361
  });
32292
32362
  }
32293
32363
  }
@@ -32386,7 +32456,11 @@ async function runSetup(plugin, argv = [], io = {}) {
32386
32456
  return { hosts, dryRun: options.dryRun, mode: "local", detection };
32387
32457
  }
32388
32458
  const { env: env3, platform } = setupPaths(io);
32389
- 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
+ });
32390
32464
  const stopped = async () => {
32391
32465
  try {
32392
32466
  await assertHostsStopped(fence, env3);
@@ -32396,6 +32470,7 @@ async function runSetup(plugin, argv = [], io = {}) {
32396
32470
  throw error;
32397
32471
  }
32398
32472
  };
32473
+ const guard = new SetupProcessGuard(stopped, io.now);
32399
32474
  printLine2(terminal, "Checking that OpenCode and Pi are not running\u2026");
32400
32475
  if (options.dryRun) {
32401
32476
  try {
@@ -32411,16 +32486,17 @@ async function runSetup(plugin, argv = [], io = {}) {
32411
32486
  if (error instanceof ProcessInspectionError)
32412
32487
  printLine2(terminal, error.refusalText);
32413
32488
  }
32414
- } else
32415
- await stopped();
32489
+ } else {
32490
+ await guard.check();
32491
+ }
32416
32492
  if ((options.claustrum || options.enrollOnly) && !detection.claustrum.available)
32417
32493
  throw new Error("Claustrum is not available. Start ck, or omit vault-only flags and use --no-claustrum for local sign-in.");
32418
32494
  let useVault = options.claustrum || options.enrollOnly;
32419
32495
  if (!useVault && !options.login && !options.noClaustrum && !assumeYes && detection.claustrum.available && isInteractive2(terminal)) {
32420
- const choice = await select2(terminal, [
32496
+ const choice = await guard.step(() => select2(terminal, [
32421
32497
  { label: "No", value: false },
32422
32498
  { label: "Yes", value: true }
32423
- ], { message: "Connect these hosts to the Claustrum vault?" });
32499
+ ], { message: "Connect these hosts to the Claustrum vault?" }));
32424
32500
  if (choice === null) {
32425
32501
  printLine2(terminal, "Setup cancelled. Nothing was changed.");
32426
32502
  return { hosts: [], dryRun: options.dryRun, mode: "local", detection };
@@ -32471,13 +32547,14 @@ ${write.content}`);
32471
32547
  const enrollmentAccess = /* @__PURE__ */ new Map();
32472
32548
  try {
32473
32549
  for (const host of hosts) {
32474
- await stopped();
32475
- await plugin.beforeSignIn?.(host, context);
32476
- await stopped();
32550
+ if (plugin.beforeSignIn) {
32551
+ await guard.check({ reuse: true });
32552
+ await guard.step(() => plugin.beforeSignIn?.(host, context));
32553
+ }
32477
32554
  if (useVault) {
32478
32555
  enrollment.set(host, "unknown");
32479
32556
  try {
32480
- const access = await connectSetupHost(plugin, host, io, terminal, stopped);
32557
+ const access = await connectSetupHost(plugin, host, io, terminal, guard);
32481
32558
  if (access)
32482
32559
  enrollmentAccess.set(host, access);
32483
32560
  } catch (error) {
@@ -32486,19 +32563,26 @@ ${write.content}`);
32486
32563
  throw error;
32487
32564
  }
32488
32565
  enrollment.set(host, "enrolled");
32489
- } else
32490
- await plugin.signInLocal(host, context);
32491
- await stopped();
32566
+ } else {
32567
+ await guard.check({ reuse: true });
32568
+ await guard.step(() => plugin.signInLocal(host, context));
32569
+ }
32492
32570
  if (options.enrollOnly)
32493
32571
  continue;
32494
- await plugin.beforeRegister?.(host, mode, context);
32495
- await stopped();
32572
+ if (plugin.beforeRegister) {
32573
+ await guard.check({ reuse: true });
32574
+ await guard.step(() => plugin.beforeRegister?.(host, mode, context));
32575
+ }
32496
32576
  if (host === "opencode")
32497
- await registerOpenCode(writes, stopped);
32498
- else
32499
- await registerPi(plugin, detection.pi.executable, io);
32500
- await stopped();
32501
- 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
+ }
32502
32586
  }
32503
32587
  } catch (error) {
32504
32588
  if (enrollment.size === 0)