@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/dist/server.js CHANGED
@@ -761,12 +761,12 @@ async function replaceWindowsFile(from, to, options = {}) {
761
761
  const delays = [0, 10, 20, 40, 80, 100];
762
762
  let original;
763
763
  let attempts2 = 0;
764
- for (const delay3 of delays) {
764
+ for (const delay4 of delays) {
765
765
  const deadline = Math.min(retryDeadline ?? Infinity, leaseDeadline);
766
766
  if (now() >= deadline)
767
767
  break;
768
- if (delay3)
769
- await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay3, Math.max(0, deadline - now())));
768
+ if (delay4)
769
+ await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay4, Math.max(0, deadline - now())));
770
770
  if (now() >= deadline)
771
771
  break;
772
772
  const fenceStart = now();
@@ -4563,8 +4563,8 @@ var init_model_registry = __esm({
4563
4563
  // ../core/dist/rotation.js
4564
4564
  function unconfirmedRateLimitDelayMs(retryAfter, now = Date.now()) {
4565
4565
  const value = retryAfter?.trim();
4566
- const delay3 = value ? /^\d+(?:\.\d+)?$/.test(value) ? Number(value) * 1e3 : Date.parse(value) - now : Number.NaN;
4567
- return Number.isFinite(delay3) ? Math.min(UNCONFIRMED_RATE_LIMIT_MAX_MS, Math.max(UNCONFIRMED_RATE_LIMIT_MIN_MS, delay3)) : UNCONFIRMED_RATE_LIMIT_MIN_MS;
4566
+ const delay4 = value ? /^\d+(?:\.\d+)?$/.test(value) ? Number(value) * 1e3 : Date.parse(value) - now : Number.NaN;
4567
+ return Number.isFinite(delay4) ? Math.min(UNCONFIRMED_RATE_LIMIT_MAX_MS, Math.max(UNCONFIRMED_RATE_LIMIT_MIN_MS, delay4)) : UNCONFIRMED_RATE_LIMIT_MIN_MS;
4568
4568
  }
4569
4569
  function parseRateLimitReason(reason, message, status) {
4570
4570
  if (status === 529 || status === 503)
@@ -4706,7 +4706,7 @@ var init_rotation = __esm({
4706
4706
  UNCONFIRMED_RATE_LIMIT_MIN_MS = 5e3;
4707
4707
  UNCONFIRMED_RATE_LIMIT_MAX_MS = 3e4;
4708
4708
  MAX_UNCONFIRMED_RATE_LIMIT_RETRIES = 2;
4709
- UNCONFIRMED_RATE_LIMIT_MESSAGE = "Antigravity could not confirm a temporary request limit. Try again later or change the agent system prompt.";
4709
+ UNCONFIRMED_RATE_LIMIT_MESSAGE = "Antigravity refused the request without a stated reason. If this keeps happening, change the agent system prompt or wait before sending another request.";
4710
4710
  DEFAULT_HEALTH_SCORE_CONFIG = {
4711
4711
  initial: 70,
4712
4712
  successReward: 1,
@@ -8911,9 +8911,9 @@ async function acquireWithRetry(path5, sleep5) {
8911
8911
  return lock;
8912
8912
  }
8913
8913
  if (attempt < RETRY_DELAYS_MS.length) {
8914
- const delay3 = RETRY_DELAYS_MS[attempt];
8915
- if (delay3 !== void 0) {
8916
- await sleep5(delay3);
8914
+ const delay4 = RETRY_DELAYS_MS[attempt];
8915
+ if (delay4 !== void 0) {
8916
+ await sleep5(delay4);
8917
8917
  }
8918
8918
  }
8919
8919
  }
@@ -17625,11 +17625,11 @@ var init_quota_writer = __esm({
17625
17625
  overlay(rows) {
17626
17626
  return rows.map((row) => this.overlayRow(row));
17627
17627
  }
17628
- schedule(delay3) {
17628
+ schedule(delay4) {
17629
17629
  if (this.running || this.timer || !this.pending.size || this.stopped)
17630
17630
  return;
17631
17631
  const remaining = this.closed ? 0 : (this.committedAt ?? -Infinity) + QUOTA_COMMIT_INTERVAL_MS - this.clock.now();
17632
- this.timer = this.clock.schedule(Math.max(delay3, remaining), () => {
17632
+ this.timer = this.clock.schedule(Math.max(delay4, remaining), () => {
17633
17633
  this.timer = void 0;
17634
17634
  return this.flush();
17635
17635
  });
@@ -17729,8 +17729,8 @@ var init_quota_writer = __esm({
17729
17729
  this.running = void 0;
17730
17730
  for (const wake of this.wake)
17731
17731
  wake();
17732
- const delay3 = this.failures ? Math.min(5e3, 100 * 2 ** Math.min(this.failures, 6)) * (0.5 + Math.random()) : COALESCE_MS;
17733
- this.schedule(delay3);
17732
+ const delay4 = this.failures ? Math.min(5e3, 100 * 2 ** Math.min(this.failures, 6)) * (0.5 + Math.random()) : COALESCE_MS;
17733
+ this.schedule(delay4);
17734
17734
  }
17735
17735
  })();
17736
17736
  return this.running;
@@ -20470,11 +20470,12 @@ var init_doctor = __esm({
20470
20470
 
20471
20471
  // ../core/dist/common-auth-embedded/auth-menu/login.js
20472
20472
  import { spawn as defaultSpawn } from "node:child_process";
20473
+ import { win32 } from "node:path";
20473
20474
  function openBrowserForMenu(url, platform = process.platform, spawn2 = defaultSpawn) {
20474
20475
  try {
20475
20476
  if (platform === "win32") {
20476
20477
  const command = `Start-Process '${url.replaceAll("'", "''")}'`;
20477
- const child2 = spawn2("powershell.exe", [
20478
+ const child2 = spawn2(win32.resolve(process.env.SystemRoot ?? process.env.windir ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe"), [
20478
20479
  "-NoProfile",
20479
20480
  "-NonInteractive",
20480
20481
  "-WindowStyle",
@@ -21417,12 +21418,12 @@ var init_watch = __esm({
21417
21418
  this.#options.logger?.debug("claustrum vault watch", { mode, reason });
21418
21419
  this.#options.onMode?.(mode);
21419
21420
  }
21420
- #later(delay3, run) {
21421
+ #later(delay4, run) {
21421
21422
  this.#timer = (this.#options.setTimeoutImpl ?? setTimeout)(() => {
21422
21423
  this.#timer = void 0;
21423
21424
  if (!this.#stopped)
21424
21425
  run();
21425
- }, delay3);
21426
+ }, delay4);
21426
21427
  this.#timer.unref?.();
21427
21428
  }
21428
21429
  async #open(resubscribed) {
@@ -21494,10 +21495,10 @@ var init_watch = __esm({
21494
21495
  const now = (this.#options.now ?? Date.now)();
21495
21496
  if (watch2.acceptedAt !== void 0 && now - watch2.acceptedAt >= SAFETY_POLL_MS)
21496
21497
  this.#closes = 0;
21497
- const delay3 = Math.min(RESUBSCRIBE_BACKOFF_MS * 2 ** Math.min(this.#closes, 16), WATCH_RETRY_MS);
21498
+ const delay4 = Math.min(RESUBSCRIBE_BACKOFF_MS * 2 ** Math.min(this.#closes, 16), WATCH_RETRY_MS);
21498
21499
  this.#closes++;
21499
21500
  this.#setMode("polling", "resubscribing");
21500
- this.#later(delay3, () => void this.#open(true));
21501
+ this.#later(delay4, () => void this.#open(true));
21501
21502
  return;
21502
21503
  }
21503
21504
  this.#fallback(end.kind);
@@ -21788,12 +21789,12 @@ var init_insula = __esm({
21788
21789
  watch2?.handle?.stop();
21789
21790
  this.#mode = "polling";
21790
21791
  }
21791
- #later(delay3) {
21792
+ #later(delay4) {
21792
21793
  this.#timer = (this.#timers.setTimeoutImpl ?? setTimeout)(() => {
21793
21794
  this.#timer = void 0;
21794
21795
  if (this.#watchers > 0 && !this.#watch)
21795
21796
  this.#open();
21796
- }, delay3);
21797
+ }, delay4);
21797
21798
  this.#timer.unref?.();
21798
21799
  }
21799
21800
  #open() {
@@ -21841,10 +21842,10 @@ var init_insula = __esm({
21841
21842
  return;
21842
21843
  }
21843
21844
  if (watch2.notices > 0) {
21844
- const delay3 = Math.min(RESUBSCRIBE_BACKOFF_MS * 2 ** Math.min(this.#closes, 16), WATCH_RETRY_MS);
21845
+ const delay4 = Math.min(RESUBSCRIBE_BACKOFF_MS * 2 ** Math.min(this.#closes, 16), WATCH_RETRY_MS);
21845
21846
  this.#closes++;
21846
21847
  this.#mode = "polling";
21847
- this.#later(delay3);
21848
+ this.#later(delay4);
21848
21849
  return;
21849
21850
  }
21850
21851
  this.#mode = "fallback";
@@ -23533,9 +23534,9 @@ var init_custody = __esm({
23533
23534
  users: 0,
23534
23535
  error,
23535
23536
  pending: Promise.resolve().then(async () => {
23536
- let delay3 = 250;
23537
+ let delay4 = 250;
23537
23538
  for (; ; ) {
23538
- await this.#receiptBackoff(delay3, controller.signal);
23539
+ await this.#receiptBackoff(delay4, controller.signal);
23539
23540
  try {
23540
23541
  return await this.#authorizeFresh(identity4, token, controller.signal);
23541
23542
  } catch (failure2) {
@@ -23543,7 +23544,7 @@ var init_custody = __esm({
23543
23544
  if (classifyVaultFailure(failure2) !== "unreachable")
23544
23545
  throw failure2;
23545
23546
  created.error = failure2;
23546
- delay3 = Math.min(delay3 * 2, 1e3);
23547
+ delay4 = Math.min(delay4 * 2, 1e3);
23547
23548
  }
23548
23549
  }
23549
23550
  })
@@ -23597,7 +23598,7 @@ var init_custody = __esm({
23597
23598
  }
23598
23599
  }
23599
23600
  }
23600
- #receiptBackoff(delay3, signal) {
23601
+ #receiptBackoff(delay4, signal) {
23601
23602
  this.#check(signal);
23602
23603
  return new Promise((resolve33, reject) => {
23603
23604
  const abort = () => {
@@ -23608,7 +23609,7 @@ var init_custody = __esm({
23608
23609
  const timer = this.#setTimeout(() => {
23609
23610
  signal.removeEventListener("abort", abort);
23610
23611
  resolve33();
23611
- }, delay3);
23612
+ }, delay4);
23612
23613
  timer.unref?.();
23613
23614
  signal.addEventListener("abort", abort, { once: true });
23614
23615
  if (signal.aborted)
@@ -24632,11 +24633,11 @@ function pendingVaultQuota(path5, roster) {
24632
24633
  function hasPendingVaultQuota(path5) {
24633
24634
  return !!writers.get(resolve11(path5))?.pending.size;
24634
24635
  }
24635
- function schedule(writer, delay3) {
24636
+ function schedule(writer, delay4) {
24636
24637
  if (writer.running || writer.timer || !writer.pending.size || writer.abort.signal.aborted)
24637
24638
  return;
24638
24639
  const remaining = writer.draining ? 0 : (writer.committedAt ?? -Infinity) + QUOTA_COMMIT_INTERVAL_MS - writer.clock.now();
24639
- writer.timer = writer.clock.schedule(Math.max(delay3, remaining), () => {
24640
+ writer.timer = writer.clock.schedule(Math.max(delay4, remaining), () => {
24640
24641
  writer.timer = void 0;
24641
24642
  return flush(writer);
24642
24643
  });
@@ -25073,13 +25074,13 @@ var init_consumer = __esm({
25073
25074
  }
25074
25075
  if (this.#shutdown.signal.aborted)
25075
25076
  return;
25076
- const delay3 = this.#options.pollIntervalMs ?? 5e3;
25077
- if (delay3 <= 0)
25077
+ const delay4 = this.#options.pollIntervalMs ?? 5e3;
25078
+ if (delay4 <= 0)
25078
25079
  return;
25079
25080
  this.#timer = (this.#options.setTimeoutImpl ?? setTimeout)(() => {
25080
25081
  this.#timer = void 0;
25081
25082
  void this.#track(tick());
25082
- }, delay3);
25083
+ }, delay4);
25083
25084
  this.#timer.unref?.();
25084
25085
  };
25085
25086
  void this.#track(tick());
@@ -26549,13 +26550,13 @@ var init_hub = __esm({
26549
26550
  }
26550
26551
  if (this.#shutdown.signal.aborted)
26551
26552
  return;
26552
- const delay3 = this.#options.pollIntervalMs ?? 5e3;
26553
- if (delay3 <= 0)
26553
+ const delay4 = this.#options.pollIntervalMs ?? 5e3;
26554
+ if (delay4 <= 0)
26554
26555
  return;
26555
26556
  this.#timer = (this.#options.setTimeoutImpl ?? setTimeout)(() => {
26556
26557
  this.#timer = void 0;
26557
26558
  void this.#track(this.#tick());
26558
- }, delay3);
26559
+ }, delay4);
26559
26560
  this.#timer.unref?.();
26560
26561
  }
26561
26562
  /**
@@ -26846,12 +26847,12 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
26846
26847
  if (!released && lastUpdate + RENEWAL_STALE < Date.now())
26847
26848
  compromise();
26848
26849
  }
26849
- function schedule2(delay3 = UPDATE) {
26850
+ function schedule2(delay4 = UPDATE) {
26850
26851
  if (released)
26851
26852
  return;
26852
26853
  timer = setTimeout(() => {
26853
26854
  void update();
26854
- }, delay3);
26855
+ }, delay4);
26855
26856
  timer.unref();
26856
26857
  }
26857
26858
  function retry(error) {
@@ -27634,6 +27635,12 @@ var init_harness_identity = __esm({
27634
27635
  "opencode.ai/docs"
27635
27636
  ];
27636
27637
  HARNESS_IDENTITY_REWRITES = [
27638
+ {
27639
+ // Antigravity refuses requests carrying this stock Pi docs bullet with a
27640
+ // false quota error. Remove its codemode clause, retaining other docs pointers.
27641
+ pattern: /^(- When asked about: extensions \(docs\/extensions\.md, examples\/extensions\/\), themes \(docs\/themes\.md\), skills \(docs\/skills\.md\), prompt templates \(docs\/prompt-templates\.md\), TUI components \(docs\/tui\.md\), keybindings \(docs\/keybindings\.md\), SDK integrations \(docs\/sdk\.md\), custom providers \(docs\/custom-provider\.md\), adding models \(docs\/models\.md\), packages \(docs\/packages\.md\), environment variables \(docs\/environment-variables\.md\), MCP servers \(docs\/mcp\.md\)), codemode scripts and non-LLM models such as classifiers and image models \(docs\/codemode\.md\)\n/gm,
27642
+ replacement: "$1\n"
27643
+ },
27637
27644
  {
27638
27645
  pattern: /\btools\.opencode\b/g,
27639
27646
  replacement: "tools['opencode']"
@@ -27650,6 +27657,10 @@ var init_harness_identity = __esm({
27650
27657
  pattern: /if OpenCode honestly/g,
27651
27658
  replacement: "if the assistant honestly"
27652
27659
  },
27660
+ {
27661
+ pattern: /You are a coding assistant running inside (?:pi, a coding agent harness|Pi-Bolt, a build of pi \(a coding agent harness\) compiled ahead of time)\.(?=$|\s)/g,
27662
+ replacement: "You are a coding assistant."
27663
+ },
27653
27664
  {
27654
27665
  pattern: /running inside Pi-Bolt, a build of pi \(a coding agent harness\) compiled ahead of time/gi,
27655
27666
  replacement: "running inside your development environment"
@@ -27710,7 +27721,7 @@ var init_pre_response_deadline = __esm({
27710
27721
  "../core/dist/pre-response-deadline.js"() {
27711
27722
  "use strict";
27712
27723
  PRE_RESPONSE_DEADLINE_MS = 6e5;
27713
- PRE_RESPONSE_TIMEOUT_MESSAGE = "Antigravity did not begin a response within the pre-response time limit. Check your connection and try again later.";
27724
+ PRE_RESPONSE_TIMEOUT_MESSAGE = "Antigravity did not begin a response within the pre-response time limit. Check your connection before sending another request.";
27714
27725
  PreResponseTimeoutError = class extends Error {
27715
27726
  code = 412;
27716
27727
  status = "FAILED_PRECONDITION";
@@ -28788,7 +28799,7 @@ function isSchemaObject(value) {
28788
28799
  function describeValue(value) {
28789
28800
  return JSON.stringify(value) ?? String(value);
28790
28801
  }
28791
- function normalizeNullableTypeArray(schema) {
28802
+ function normalizeNullableTypeArray(schema, unionHints) {
28792
28803
  if (!Array.isArray(schema.type))
28793
28804
  return schema;
28794
28805
  if (schema.type.length === 0 || schema.type.some((type) => typeof type !== "string" || !ALLOWED_JSON_SCHEMA_TYPES.has(type.toLowerCase()))) {
@@ -28799,7 +28810,37 @@ function normalizeNullableTypeArray(schema) {
28799
28810
  ];
28800
28811
  const nonNull = types.filter((type) => type !== "null");
28801
28812
  if (nonNull.length > 1) {
28802
- return schema;
28813
+ if (!unionHints)
28814
+ return schema;
28815
+ const { type: _type, ...base } = schema;
28816
+ if (types.includes("null"))
28817
+ base.nullable = true;
28818
+ const coversEveryType = ["object", "array", "string", "boolean"].every((type) => nonNull.includes(type)) && (nonNull.includes("number") || nonNull.includes("integer"));
28819
+ if (!coversEveryType && (Array.isArray(base.anyOf) || Array.isArray(base.oneOf))) {
28820
+ unionHints.push("type: additional union constraints omitted.");
28821
+ return base;
28822
+ }
28823
+ const branches = nonNull.map((type) => {
28824
+ const branch = { type };
28825
+ for (const key of TYPE_ARRAY_BRANCH_FIELDS[type] ?? []) {
28826
+ if (!Object.hasOwn(base, key))
28827
+ continue;
28828
+ if (key === "enum" && (!Array.isArray(base.enum) || !base.enum.every((value) => typeof value === "string")))
28829
+ continue;
28830
+ branch[key] = base[key];
28831
+ }
28832
+ return branch;
28833
+ });
28834
+ for (const key of /* @__PURE__ */ new Set([
28835
+ ...Object.values(TYPE_ARRAY_BRANCH_FIELDS).flat(),
28836
+ "minProperties",
28837
+ "maxProperties"
28838
+ ])) {
28839
+ if (key === "enum" && Array.isArray(base.enum) && !base.enum.every((value) => typeof value === "string"))
28840
+ continue;
28841
+ delete base[key];
28842
+ }
28843
+ return coversEveryType ? base : { ...base, anyOf: branches };
28803
28844
  }
28804
28845
  return {
28805
28846
  ...schema,
@@ -28917,7 +28958,7 @@ function toGeminiSchema(schema, options = {}) {
28917
28958
  return schema;
28918
28959
  }
28919
28960
  const numericConstraintHints = [];
28920
- const inputSchema = normalizeNullableTypeArray(mergeSchemaAllOf(schema, numericConstraintHints));
28961
+ const inputSchema = normalizeNullableTypeArray(mergeSchemaAllOf(schema, numericConstraintHints), options.claudeValidated ? void 0 : numericConstraintHints);
28921
28962
  const schemaType = typeof inputSchema.type === "string" ? inputSchema.type.toUpperCase() : void 0;
28922
28963
  let result = {};
28923
28964
  const propertyNames = /* @__PURE__ */ new Set();
@@ -29268,7 +29309,7 @@ function wrapToolsAsFunctionDeclarations(payload) {
29268
29309
  passthroughToolCount: passthroughTools.length + (hasWebSearchTool && functionDeclarations.length === 0 ? 1 : 0)
29269
29310
  };
29270
29311
  }
29271
- var ALLOWED_SCHEMA_FIELDS, NUMERIC_SCHEMA_CONSTRAINTS, ALLOWED_JSON_SCHEMA_TYPES, CLAUDE_VALIDATED_HINT_FIELDS, VALID_ASPECT_RATIOS;
29312
+ var ALLOWED_SCHEMA_FIELDS, NUMERIC_SCHEMA_CONSTRAINTS, ALLOWED_JSON_SCHEMA_TYPES, TYPE_ARRAY_BRANCH_FIELDS, CLAUDE_VALIDATED_HINT_FIELDS, VALID_ASPECT_RATIOS;
29272
29313
  var init_gemini = __esm({
29273
29314
  "../core/dist/transform/gemini.js"() {
29274
29315
  "use strict";
@@ -29318,6 +29359,30 @@ var init_gemini = __esm({
29318
29359
  "object",
29319
29360
  "null"
29320
29361
  ]);
29362
+ TYPE_ARRAY_BRANCH_FIELDS = {
29363
+ object: [
29364
+ "properties",
29365
+ "required",
29366
+ "propertyOrdering",
29367
+ "additionalProperties"
29368
+ ],
29369
+ array: ["items", "minItems", "maxItems"],
29370
+ string: ["enum", "format", "minLength", "maxLength", "pattern"],
29371
+ number: [
29372
+ "minimum",
29373
+ "maximum",
29374
+ "exclusiveMinimum",
29375
+ "exclusiveMaximum",
29376
+ "multipleOf"
29377
+ ],
29378
+ integer: [
29379
+ "minimum",
29380
+ "maximum",
29381
+ "exclusiveMinimum",
29382
+ "exclusiveMaximum",
29383
+ "multipleOf"
29384
+ ]
29385
+ };
29321
29386
  CLAUDE_VALIDATED_HINT_FIELDS = /* @__PURE__ */ new Set([
29322
29387
  "minLength",
29323
29388
  "maxLength",
@@ -29982,6 +30047,15 @@ function assertRosterBinding(roster, attribution, claustrum) {
29982
30047
  if (!roster || !row?.enabled || row.state !== "active" || row.stale === true || row.unclaimed === true || row.credentialId !== attribution.credentialId || row.accountIdentity !== attribution.accountIdentity || claustrum.isDeclined(roster.declined, attribution.credentialId, attribution.accountIdentity))
29983
30048
  throw new VaultProviderStateError("binding-stale", "the vault route no longer serves the attributed credential and account");
29984
30049
  }
30050
+ function quotaBoundState(current, attribution) {
30051
+ if (current?.quota === void 0 || current.observed.routeId === attribution.routeId && current.observed.credentialId === attribution.credentialId)
30052
+ return current;
30053
+ return Object.freeze({
30054
+ observed: current.observed,
30055
+ ...current.metadata !== void 0 ? { metadata: current.metadata } : {},
30056
+ ...current.extensions !== void 0 ? { extensions: current.extensions } : {}
30057
+ });
30058
+ }
29985
30059
  async function commitVaultProviderState(input2) {
29986
30060
  const { claustrum, fs: fs7, statePath } = input2;
29987
30061
  input2.signal?.throwIfAborted();
@@ -29997,7 +30071,7 @@ async function commitVaultProviderState(input2) {
29997
30071
  const file = await readVaultProviderState(statePath);
29998
30072
  input2.signal?.throwIfAborted();
29999
30073
  const current = vaultAccountState(file, identity4);
30000
- const requested = input2.update(current);
30074
+ const requested = input2.update(quotaBoundState(current, attribution));
30001
30075
  if (isRecord9(requested) && typeof requested.then === "function")
30002
30076
  throw new VaultProviderStateError("invalid-update", "a state update must be synchronous");
30003
30077
  if (requested === void 0)
@@ -30105,7 +30179,7 @@ async function commitVaultProviderStates(input2) {
30105
30179
  const identity4 = entry.attribution.accountIdentity;
30106
30180
  const current = Object.hasOwn(accounts, identity4) ? accounts[identity4] : void 0;
30107
30181
  try {
30108
- const requested = entry.update(current);
30182
+ const requested = entry.update(quotaBoundState(current, entry.attribution));
30109
30183
  if (isRecord9(requested) && typeof requested.then === "function")
30110
30184
  throw new VaultProviderStateError("invalid-update", "a state update must be synchronous");
30111
30185
  if (requested === void 0 || requested === null && !current) {
@@ -30534,7 +30608,7 @@ var init_vault_enrollment_authority = __esm({
30534
30608
  "use strict";
30535
30609
  init_common_auth_runtime();
30536
30610
  UNSUPPORTED_VAULT_CODE = "unknown_method";
30537
- VAULT_ACCOUNT_REMEDY = "Vault account access is unavailable. Connect accounts in the vault, or disconnect the vault to use local accounts.";
30611
+ VAULT_ACCOUNT_REMEDY = "Vault account access is not ready. Connect accounts in the vault, or disconnect the vault to use local accounts.";
30538
30612
  }
30539
30613
  });
30540
30614
 
@@ -30853,12 +30927,12 @@ async function replaceWindowsFile2(from, to, options = {}) {
30853
30927
  const delays = [0, 10, 20, 40, 80, 100];
30854
30928
  let original;
30855
30929
  let attempts2 = 0;
30856
- for (const delay3 of delays) {
30930
+ for (const delay4 of delays) {
30857
30931
  const deadline = Math.min(retryDeadline ?? Infinity, leaseDeadline);
30858
30932
  if (now() >= deadline)
30859
30933
  break;
30860
- if (delay3)
30861
- await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay3, Math.max(0, deadline - now())));
30934
+ if (delay4)
30935
+ await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay4, Math.max(0, deadline - now())));
30862
30936
  if (now() >= deadline)
30863
30937
  break;
30864
30938
  const fenceStart = now();
@@ -34280,8 +34354,8 @@ function isWindowsSharingError(error, platform) {
34280
34354
  }
34281
34355
  async function unlinkIfIdentical(file, stateDir, guard, io = { platform: process.platform, readFile: readFile15, unlink: unlink12 }) {
34282
34356
  const started = performance.now();
34283
- for (const delay3 of SHARING_RETRY_DELAYS_MS) {
34284
- if (delay3 > 0) await new Promise((done) => setTimeout(done, delay3));
34357
+ for (const delay4 of SHARING_RETRY_DELAYS_MS) {
34358
+ if (delay4 > 0) await new Promise((done) => setTimeout(done, delay4));
34285
34359
  let same;
34286
34360
  try {
34287
34361
  same = (await io.readFile(file.old)).equals(await io.readFile(file.next));
@@ -38855,7 +38929,7 @@ async function moveSettingsOnce(options) {
38855
38929
  }
38856
38930
 
38857
38931
  // ../core/dist/common-auth-embedded/settings/paths.js
38858
- import { posix, win32 } from "node:path";
38932
+ import { posix, win32 as win322 } from "node:path";
38859
38933
  function isAbsoluteForPlatform(path5, platform) {
38860
38934
  if (platform !== "win32")
38861
38935
  return path5.startsWith("/");
@@ -38866,7 +38940,7 @@ function isAbsoluteForPlatform(path5, platform) {
38866
38940
  return /^[\\/]{2}[^\\/]+[\\/][^\\/]+/.test(path5);
38867
38941
  }
38868
38942
  function cortexkitConfigDir({ env: env3, platform, homedir: homedir17 }) {
38869
- const paths = platform === "win32" ? win32 : posix;
38943
+ const paths = platform === "win32" ? win322 : posix;
38870
38944
  const absolute = (value) => value !== void 0 && isAbsoluteForPlatform(value, platform);
38871
38945
  let base;
38872
38946
  if (absolute(env3.XDG_CONFIG_HOME)) {
@@ -38889,7 +38963,7 @@ function settingsFilePath({ plugin: plugin2, override, ...options }) {
38889
38963
  if (override && isAbsoluteForPlatform(override, options.platform)) {
38890
38964
  return override;
38891
38965
  }
38892
- const paths = options.platform === "win32" ? win32 : posix;
38966
+ const paths = options.platform === "win32" ? win322 : posix;
38893
38967
  return paths.join(cortexkitConfigDir(options), `${plugin2}.jsonc`);
38894
38968
  }
38895
38969
 
@@ -42525,14 +42599,14 @@ var BackgroundVaultQuotaRefresh = class {
42525
42599
  this.abortTick();
42526
42600
  await this.inFlight;
42527
42601
  }
42528
- schedule(delay3, intervalWait = null) {
42602
+ schedule(delay4, intervalWait = null) {
42529
42603
  if (this.disposed || !this.started) return;
42530
42604
  this.intervalWait = intervalWait;
42531
42605
  this.timer = setTimeout(() => {
42532
42606
  this.timer = null;
42533
42607
  this.intervalWait = null;
42534
42608
  void this.tick();
42535
- }, delay3);
42609
+ }, delay4);
42536
42610
  this.timer.unref?.();
42537
42611
  }
42538
42612
  /** One serialized tick; also used by deterministic composition tests. */
@@ -46347,11 +46421,11 @@ function createSyntheticTextResponse(text2, extraHeaders = {}) {
46347
46421
  });
46348
46422
  }
46349
46423
  var NATIVE_GOOGLE_ERROR_MESSAGES = {
46350
- operator_policy: "Antigravity account pool is unavailable under the operator quota policy. Adjust the quota floor in /antigravity \u2192 Limits or refresh quota.",
46351
- soft_quota: 'Antigravity account pool is unavailable under the quota protection policy. Add accounts, wait for quota reset, or turn off soft quota protection with `"soft_quota_threshold_percent": 100` in antigravity-auth.jsonc.',
46424
+ operator_policy: "Antigravity account pool is blocked by the operator quota policy. Adjust the quota floor in /antigravity \u2192 Limits or refresh quota.",
46425
+ soft_quota: 'Antigravity account pool is blocked by quota protection. Add accounts, wait for quota reset, or turn off soft quota protection with `"soft_quota_threshold_percent": 100` in antigravity-auth.jsonc.',
46352
46426
  pool_unavailable: "Antigravity account pool has no account available within the configured wait limit. Add accounts with `opencode auth login` or wait for quota reset.",
46353
46427
  model_unavailable: "The requested Antigravity model is not available to the configured accounts. Choose another model.",
46354
- routing_refused: "Routing has no Antigravity account available for this request right now; try again later.",
46428
+ routing_refused: "Routing has no Antigravity account available for this request right now. Wait before sending another request.",
46355
46429
  missing_access_token: "Missing access token. Run `opencode auth login` to reauthenticate.",
46356
46430
  empty_response: "Antigravity returned an empty response after the internal retry attempts."
46357
46431
  };
@@ -49241,6 +49315,7 @@ function routingHandle(sessionId) {
49241
49315
  var CACHE_WARM_STOP_REASONS = [
49242
49316
  "cost-cap",
49243
49317
  "count-cap",
49318
+ "deadline-missed",
49244
49319
  "outside-hours",
49245
49320
  "session-ended",
49246
49321
  "unsupported"
@@ -50665,7 +50740,7 @@ function createRequestExecutor(deps) {
50665
50740
  error: {
50666
50741
  code: 412,
50667
50742
  status: "FAILED_PRECONDITION",
50668
- message: "This Antigravity thinking level is unavailable. Choose another thinking level."
50743
+ message: "This Antigravity thinking level is not offered. Choose another thinking level."
50669
50744
  }
50670
50745
  }),
50671
50746
  { status: 412, headers: { "Content-Type": "application/json" } }
@@ -52390,9 +52465,8 @@ function createRequestExecutor(deps) {
52390
52465
  const originalError = recoveryError.originalError || {
52391
52466
  error: { message: "Thinking recovery triggered" }
52392
52467
  };
52393
- const recoveryMessage = `${originalError.error?.message || "Session recovery failed"}
52394
-
52395
- [RECOVERY] Thinking block corruption could not be resolved. Try starting a new session.`;
52468
+ log18.debug("thinking-recovery-failed", { error: originalError });
52469
+ const recoveryMessage = "Antigravity could not repair the conversation's thinking blocks. Start a new session.";
52396
52470
  return new Response(
52397
52471
  JSON.stringify({
52398
52472
  type: "error",
@@ -52672,9 +52746,9 @@ init_version_fence();
52672
52746
 
52673
52747
  // src/settings/location.ts
52674
52748
  import { realpath as realpath5 } from "node:fs/promises";
52675
- import { posix as posix2, win32 as win322 } from "node:path";
52749
+ import { posix as posix2, win32 as win323 } from "node:path";
52676
52750
  async function folderIdentity(folder, platform) {
52677
- const paths = platform === "win32" ? win322 : posix2;
52751
+ const paths = platform === "win32" ? win323 : posix2;
52678
52752
  try {
52679
52753
  return await realpath5(folder);
52680
52754
  } catch {
@@ -52683,7 +52757,7 @@ async function folderIdentity(folder, platform) {
52683
52757
  }
52684
52758
  async function resolveSettingsLocation(options) {
52685
52759
  const { env: env3, platform, homedir: homedir17 } = options;
52686
- const paths = platform === "win32" ? win322 : posix2;
52760
+ const paths = platform === "win32" ? win323 : posix2;
52687
52761
  const override = env3.OPENCODE_ANTIGRAVITY_AUTH_SETTINGS_FILE;
52688
52762
  const file = settingsFilePath({
52689
52763
  plugin: "antigravity-auth",
@@ -53060,12 +53134,12 @@ function createSettingsRuntime(options) {
53060
53134
  void enqueue(refreshAll);
53061
53135
  });
53062
53136
  };
53063
- const scheduleAttempt = (delay3) => {
53137
+ const scheduleAttempt = (delay4) => {
53064
53138
  if (disposed) return;
53065
53139
  retryTimer = setTimeout(() => {
53066
53140
  retryTimer = void 0;
53067
53141
  void enqueue(attemptMove);
53068
- }, delay3);
53142
+ }, delay4);
53069
53143
  retryTimer.unref?.();
53070
53144
  };
53071
53145
  const attemptMove = async () => {
@@ -58032,6 +58106,7 @@ async function pipeResponse(upstream, response, onFailure, onHandoff) {
58032
58106
  return;
58033
58107
  }
58034
58108
  const extraHeaders = collectForwardedHeaders(upstream.headers);
58109
+ if (upstream.status >= 400) extraHeaders["x-should-retry"] = "false";
58035
58110
  writeResponseHead(response, upstream.status, contentType, extraHeaders);
58036
58111
  response.flushHeaders();
58037
58112
  onHandoff();
@@ -61102,12 +61177,12 @@ import { parse } from "jsonc-parser";
61102
61177
 
61103
61178
  // src/common-auth-embedded/setup/paths.js
61104
61179
  import { homedir as homedir11 } from "node:os";
61105
- import { posix as posix3, win32 as win323 } from "node:path";
61180
+ import { posix as posix3, win32 as win324 } from "node:path";
61106
61181
  import { fileURLToPath } from "node:url";
61107
61182
  function setupPaths(io = {}) {
61108
61183
  const env3 = io.env ?? process.env;
61109
61184
  const platform = io.platform ?? process.platform;
61110
- const path5 = platform === "win32" ? win323 : posix3;
61185
+ const path5 = platform === "win32" ? win324 : posix3;
61111
61186
  const home = io.home ?? (platform === "win32" ? env3.USERPROFILE : env3.HOME) ?? homedir11();
61112
61187
  const cwd = io.cwd ?? process.cwd();
61113
61188
  const absolute = (value) => path5.resolve(cwd, value);
@@ -61334,7 +61409,20 @@ import { setTimeout as delay } from "node:timers/promises";
61334
61409
  import { writeEnrollmentTokenFile as writeEnrollmentTokenFile3 } from "@cortexkit/claustrum-client";
61335
61410
 
61336
61411
  // src/common-auth-embedded/setup/process-fence.js
61412
+ import { statSync as statSync7 } from "node:fs";
61413
+ import { win32 as win325 } from "node:path";
61337
61414
  var WINDOWS_CIM_TIMEOUT_MS = 45e3;
61415
+ var WINDOWS_ARM_POWERSHELL_TIMEOUT_MS = 9e4;
61416
+ function isFile(file) {
61417
+ try {
61418
+ return statSync7(file).isFile();
61419
+ } catch {
61420
+ return false;
61421
+ }
61422
+ }
61423
+ function windowsEnv(env3, name) {
61424
+ return Object.entries(env3).find(([key]) => key.toUpperCase() === name.toUpperCase())?.[1];
61425
+ }
61338
61426
  var HOSTS = /* @__PURE__ */ new Set(["opencode", "litecode", "opencode2", "pi"]);
61339
61427
  var RUNTIMES = /* @__PURE__ */ new Set(["node", "bun"]);
61340
61428
  var WINDOWS_FENCE_FILTER = [...HOSTS, ...RUNTIMES].map((name) => `Name LIKE '${name}%'`).join(" OR ");
@@ -61406,6 +61494,7 @@ function hostName(command) {
61406
61494
  var ProcessInspectionError = class extends Error {
61407
61495
  code = "process-inspection-failed";
61408
61496
  step;
61497
+ program;
61409
61498
  exitCode;
61410
61499
  signal;
61411
61500
  timedOut;
@@ -61414,6 +61503,7 @@ var ProcessInspectionError = class extends Error {
61414
61503
  super("Process inspection failed; setup cannot prove hosts are stopped.");
61415
61504
  this.name = "ProcessInspectionError";
61416
61505
  this.step = details.step;
61506
+ this.program = details.program;
61417
61507
  this.exitCode = details.exitCode;
61418
61508
  this.signal = details.signal;
61419
61509
  this.timedOut = details.timedOut;
@@ -61441,6 +61531,8 @@ Please quit all OpenCode, LiteCode, and Pi processes before running setup.`);
61441
61531
  };
61442
61532
  async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
61443
61533
  const windows2 = (options.platform ?? process.platform) === "win32";
61534
+ const env3 = options.env ?? process.env;
61535
+ const system32 = windows2 ? win325.resolve(windowsEnv(env3, "SystemRoot") ?? windowsEnv(env3, "windir") ?? "C:\\Windows", "System32") : "";
61444
61536
  const selfPid = options.selfPid ?? process.pid;
61445
61537
  let inspection = {
61446
61538
  step: windows2 ? "tasklist" : "ps",
@@ -61449,10 +61541,11 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
61449
61541
  timedOut: false,
61450
61542
  durationMs: 0
61451
61543
  };
61452
- const inspect = async (step, file, args, timeoutMs) => {
61544
+ const inspect = async (step, file, args, timeoutMs, program) => {
61453
61545
  const started = performance.now();
61454
61546
  inspection = {
61455
61547
  step,
61548
+ ...program && { program },
61456
61549
  exitCode: null,
61457
61550
  signal: null,
61458
61551
  timedOut: false,
@@ -61465,6 +61558,7 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
61465
61558
  });
61466
61559
  inspection = {
61467
61560
  step,
61561
+ ...program && { program },
61468
61562
  exitCode: result.exitCode,
61469
61563
  signal: result.signal ?? null,
61470
61564
  timedOut: result.timedOut ?? false,
@@ -61477,9 +61571,23 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
61477
61571
  options.onStep?.({ ...inspection });
61478
61572
  }
61479
61573
  };
61574
+ const inspectCim = (args) => {
61575
+ const pwsh = win325.resolve(windowsEnv(env3, "ProgramFiles") ?? "C:\\Program Files", "PowerShell", "7", "pwsh.exe");
61576
+ const program = (options.isFile ?? isFile)(pwsh) ? "pwsh" : "powershell";
61577
+ const arm64 = (windowsEnv(env3, "PROCESSOR_ARCHITEW6432") ?? windowsEnv(env3, "PROCESSOR_ARCHITECTURE"))?.toUpperCase() === "ARM64";
61578
+ const slow = program === "powershell" && arm64;
61579
+ if (slow)
61580
+ 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.");
61581
+ return inspect("CIM", program === "pwsh" ? pwsh : win325.resolve(system32, "WindowsPowerShell", "v1.0", "powershell.exe"), args, slow ? WINDOWS_ARM_POWERSHELL_TIMEOUT_MS : WINDOWS_CIM_TIMEOUT_MS, program);
61582
+ };
61480
61583
  try {
61481
61584
  if (windows2 && options.hostImagesOnly) {
61482
- const details = await inspect("CIM", "powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", WINDOWS_FENCE_QUERY], WINDOWS_CIM_TIMEOUT_MS);
61585
+ const details = await inspectCim([
61586
+ "-NoProfile",
61587
+ "-NonInteractive",
61588
+ "-Command",
61589
+ WINDOWS_FENCE_QUERY
61590
+ ]);
61483
61591
  if (details.exitCode !== 0)
61484
61592
  throw new ProcessInspectionError(inspection);
61485
61593
  const value = JSON.parse(details.stdout);
@@ -61501,7 +61609,7 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
61501
61609
  }
61502
61610
  return processes2;
61503
61611
  }
61504
- const result = await inspect(windows2 ? "tasklist" : "ps", windows2 ? "tasklist.exe" : "ps", windows2 ? ["/fo", "csv", "/nh"] : ["-eo", "pid,command"]);
61612
+ const result = await inspect(windows2 ? "tasklist" : "ps", windows2 ? win325.resolve(system32, "tasklist.exe") : "ps", windows2 ? ["/fo", "csv", "/nh"] : ["-eo", "pid,command"]);
61505
61613
  if (result.exitCode !== 0)
61506
61614
  throw new ProcessInspectionError(inspection);
61507
61615
  const processes = [];
@@ -61535,12 +61643,12 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
61535
61643
  throw new ProcessInspectionError(inspection);
61536
61644
  const runtimes = processes.filter((entry) => entry.pid !== selfPid && /^(?:node|bun)\.exe$/i.test(entry.command));
61537
61645
  if (windows2 && runtimes.length && options.inspectRuntimes !== false) {
61538
- const details = await inspect("CIM", "powershell.exe", [
61646
+ const details = await inspectCim([
61539
61647
  "-NoProfile",
61540
61648
  "-NonInteractive",
61541
61649
  "-Command",
61542
61650
  `$ErrorActionPreference = 'Stop'; Get-CimInstance Win32_Process -Filter "Name = 'node.exe' OR Name = 'bun.exe'" | Select-Object ProcessId,CommandLine | ConvertTo-Json -Compress`
61543
- ], WINDOWS_CIM_TIMEOUT_MS);
61651
+ ]);
61544
61652
  if (details.exitCode !== 0)
61545
61653
  throw new ProcessInspectionError(inspection);
61546
61654
  const value = JSON.parse(details.stdout || "null");
@@ -61596,6 +61704,36 @@ async function assertHostsStopped(fence, env3) {
61596
61704
  throw new ProcessFenceViolationError(active2);
61597
61705
  }
61598
61706
 
61707
+ // src/common-auth-embedded/setup/process-guard.js
61708
+ var SetupProcessGuard = class {
61709
+ inspect;
61710
+ now;
61711
+ #checkedAt;
61712
+ constructor(inspect, now = () => performance.now()) {
61713
+ this.inspect = inspect;
61714
+ this.now = now;
61715
+ }
61716
+ async check(options = {}) {
61717
+ if (options.reuse && this.#checkedAt !== void 0) {
61718
+ const age = this.now() - this.#checkedAt;
61719
+ if (age >= 0 && age < 5e3)
61720
+ return;
61721
+ }
61722
+ this.#checkedAt = void 0;
61723
+ await this.inspect();
61724
+ this.#checkedAt = this.now();
61725
+ }
61726
+ /** Callbacks, writes and waits can all make an earlier inspection stale. */
61727
+ async step(run) {
61728
+ this.#checkedAt = void 0;
61729
+ try {
61730
+ return await run();
61731
+ } finally {
61732
+ this.#checkedAt = void 0;
61733
+ }
61734
+ }
61735
+ };
61736
+
61599
61737
  // src/common-auth-embedded/setup/enroll.js
61600
61738
  var ENROLLMENT_INCOMPLETE_MESSAGE = "Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.";
61601
61739
  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.';
@@ -61624,7 +61762,8 @@ async function connectSetupHost(plugin2, host, io, terminal, fence) {
61624
61762
  throw new Error(VAULT_HOST_CONNECT_REFUSAL2);
61625
61763
  const { name, displayName, requestedGrants, grantFallback, paths: input2 } = plugin2.vault.hosts[host];
61626
61764
  const paths = hostEnrollmentPaths2(input2);
61627
- await fence();
61765
+ const guard = typeof fence === "function" ? new SetupProcessGuard(fence, io.now) : fence;
61766
+ await guard.check({ reuse: true });
61628
61767
  const client = await (io.connect ?? connectClaustrumEnrollmentClient2)({
61629
61768
  connectionFile: plugin2.vault.connectionFile,
61630
61769
  handshakeTimeoutMs: 2e3
@@ -61645,11 +61784,10 @@ async function connectSetupHost(plugin2, host, io, terminal, fence) {
61645
61784
  // starts PowerShell.
61646
61785
  client,
61647
61786
  writeTokenFile: async (path5, file) => {
61648
- await fence();
61649
- await writeEnrollmentTokenFile3(path5, file);
61787
+ await guard.check();
61788
+ await guard.step(() => writeEnrollmentTokenFile3(path5, file));
61650
61789
  }
61651
61790
  });
61652
- await fence();
61653
61791
  const initial = await manager.status();
61654
61792
  if (initial.state === "approved") {
61655
61793
  printLine2(terminal, `Already connected as ${initial.approvedName ?? initial.proposedName}.`);
@@ -61666,7 +61804,8 @@ async function connectSetupHost(plugin2, host, io, terminal, fence) {
61666
61804
  let reportedCode;
61667
61805
  let failedProposals = 0;
61668
61806
  for (; ; ) {
61669
- const status = await manager.reconcile();
61807
+ await guard.check({ reuse: true });
61808
+ const status = await guard.step(() => manager.reconcile());
61670
61809
  if (status.state === "approved") {
61671
61810
  printLine2(terminal, `Connected ${host} to Claustrum.`);
61672
61811
  const access = await confirmEnrollmentAccess(client, status, paths.tokenPath, requestedGrants);
@@ -61714,8 +61853,8 @@ async function connectSetupHost(plugin2, host, io, terminal, fence) {
61714
61853
  const remaining = deadline - now();
61715
61854
  if (remaining <= 0)
61716
61855
  break;
61717
- await wait2(Math.min(pause, remaining));
61718
- await fence();
61856
+ await guard.step(() => wait2(Math.min(pause, remaining)));
61857
+ await guard.check();
61719
61858
  }
61720
61859
  if (printedRequest)
61721
61860
  throw new HostNotEnrolledError(`Claustrum approval is still pending. In another terminal, run: ${approveCommand(printedRequest, name)} and then rerun setup.`, {
@@ -61865,6 +62004,8 @@ async function selectSetupHosts(terminal, found) {
61865
62004
  }
61866
62005
 
61867
62006
  // src/common-auth-embedded/setup/register.js
62007
+ import { rename as rename15 } from "node:fs/promises";
62008
+ import { setTimeout as delay3 } from "node:timers/promises";
61868
62009
  import { domainToUnicode } from "node:url";
61869
62010
  import { applyEdits as applyEdits2, createScanner as createScanner2, findNodeAtLocation as findNodeAtLocation2, modify as modify2, parse as parse2, parseTree as parseTree2 } from "jsonc-parser";
61870
62011
 
@@ -62074,12 +62215,15 @@ function planOpenCodeRegistration(plugin2, generation, io = {}) {
62074
62215
  });
62075
62216
  }
62076
62217
  async function registerOpenCode(writes, beforeWrite) {
62218
+ const guard = typeof beforeWrite === "function" ? new SetupProcessGuard(beforeWrite) : beforeWrite;
62077
62219
  for (const write of writes) {
62078
62220
  if (!write.changed)
62079
62221
  continue;
62080
- await beforeWrite?.();
62081
62222
  await writeHostConfigAtomic(write.path, write.content, {
62082
- beforeRename: beforeWrite
62223
+ // Only the rename publishes host-readable config; recheck on every retry.
62224
+ beforeRename: guard ? () => guard.check({ reuse: true }) : void 0,
62225
+ rename: guard ? (from, to) => guard.step(() => rename15(from, to)) : void 0,
62226
+ wait: guard ? (ms) => guard.step(() => delay3(ms)) : void 0
62083
62227
  });
62084
62228
  }
62085
62229
  }
@@ -62178,7 +62322,11 @@ async function runSetup(plugin2, argv = [], io = {}) {
62178
62322
  return { hosts, dryRun: options.dryRun, mode: "local", detection };
62179
62323
  }
62180
62324
  const { env: env3, platform } = setupPaths(io);
62181
- const fence = io.fence ?? createProcessFence(io.runner ?? defaultCommandRunner, { platform });
62325
+ const fence = io.fence ?? createProcessFence(io.runner ?? defaultCommandRunner, {
62326
+ platform,
62327
+ isFile: io.fs?.isFile.bind(io.fs),
62328
+ onProgress: (line) => printLine2(terminal, line)
62329
+ });
62182
62330
  const stopped = async () => {
62183
62331
  try {
62184
62332
  await assertHostsStopped(fence, env3);
@@ -62188,6 +62336,7 @@ async function runSetup(plugin2, argv = [], io = {}) {
62188
62336
  throw error;
62189
62337
  }
62190
62338
  };
62339
+ const guard = new SetupProcessGuard(stopped, io.now);
62191
62340
  printLine2(terminal, "Checking that OpenCode and Pi are not running\u2026");
62192
62341
  if (options.dryRun) {
62193
62342
  try {
@@ -62203,16 +62352,17 @@ async function runSetup(plugin2, argv = [], io = {}) {
62203
62352
  if (error instanceof ProcessInspectionError)
62204
62353
  printLine2(terminal, error.refusalText);
62205
62354
  }
62206
- } else
62207
- await stopped();
62355
+ } else {
62356
+ await guard.check();
62357
+ }
62208
62358
  if ((options.claustrum || options.enrollOnly) && !detection.claustrum.available)
62209
62359
  throw new Error("Claustrum is not available. Start ck, or omit vault-only flags and use --no-claustrum for local sign-in.");
62210
62360
  let useVault = options.claustrum || options.enrollOnly;
62211
62361
  if (!useVault && !options.login && !options.noClaustrum && !assumeYes && detection.claustrum.available && isInteractive2(terminal)) {
62212
- const choice = await select2(terminal, [
62362
+ const choice = await guard.step(() => select2(terminal, [
62213
62363
  { label: "No", value: false },
62214
62364
  { label: "Yes", value: true }
62215
- ], { message: "Connect these hosts to the Claustrum vault?" });
62365
+ ], { message: "Connect these hosts to the Claustrum vault?" }));
62216
62366
  if (choice === null) {
62217
62367
  printLine2(terminal, "Setup cancelled. Nothing was changed.");
62218
62368
  return { hosts: [], dryRun: options.dryRun, mode: "local", detection };
@@ -62263,13 +62413,14 @@ ${write.content}`);
62263
62413
  const enrollmentAccess = /* @__PURE__ */ new Map();
62264
62414
  try {
62265
62415
  for (const host of hosts) {
62266
- await stopped();
62267
- await plugin2.beforeSignIn?.(host, context);
62268
- await stopped();
62416
+ if (plugin2.beforeSignIn) {
62417
+ await guard.check({ reuse: true });
62418
+ await guard.step(() => plugin2.beforeSignIn?.(host, context));
62419
+ }
62269
62420
  if (useVault) {
62270
62421
  enrollment.set(host, "unknown");
62271
62422
  try {
62272
- const access = await connectSetupHost(plugin2, host, io, terminal, stopped);
62423
+ const access = await connectSetupHost(plugin2, host, io, terminal, guard);
62273
62424
  if (access)
62274
62425
  enrollmentAccess.set(host, access);
62275
62426
  } catch (error) {
@@ -62278,19 +62429,26 @@ ${write.content}`);
62278
62429
  throw error;
62279
62430
  }
62280
62431
  enrollment.set(host, "enrolled");
62281
- } else
62282
- await plugin2.signInLocal(host, context);
62283
- await stopped();
62432
+ } else {
62433
+ await guard.check({ reuse: true });
62434
+ await guard.step(() => plugin2.signInLocal(host, context));
62435
+ }
62284
62436
  if (options.enrollOnly)
62285
62437
  continue;
62286
- await plugin2.beforeRegister?.(host, mode, context);
62287
- await stopped();
62438
+ if (plugin2.beforeRegister) {
62439
+ await guard.check({ reuse: true });
62440
+ await guard.step(() => plugin2.beforeRegister?.(host, mode, context));
62441
+ }
62288
62442
  if (host === "opencode")
62289
- await registerOpenCode(writes, stopped);
62290
- else
62291
- await registerPi(plugin2, detection.pi.executable, io);
62292
- await stopped();
62293
- await plugin2.migrate?.(host, context);
62443
+ await registerOpenCode(writes, guard);
62444
+ else {
62445
+ await guard.check({ reuse: true });
62446
+ await guard.step(() => registerPi(plugin2, detection.pi.executable, io));
62447
+ }
62448
+ if (plugin2.migrate) {
62449
+ await guard.check({ reuse: true });
62450
+ await guard.step(() => plugin2.migrate?.(host, context));
62451
+ }
62294
62452
  }
62295
62453
  } catch (error) {
62296
62454
  if (enrollment.size === 0)
@@ -63953,7 +64111,7 @@ function isSessionId(value) {
63953
64111
  // src/common-auth-embedded/rpc/port-file.js
63954
64112
  init_private_files2();
63955
64113
  import { createHash as createHash21, randomUUID as randomUUID25 } from "node:crypto";
63956
- import { chmod as chmod7, mkdir as mkdir20, open as open13, readdir as readdir7, rename as rename15, rmdir as rmdir3, stat as stat20, unlink as unlink16 } from "node:fs/promises";
64114
+ import { chmod as chmod7, mkdir as mkdir20, open as open13, readdir as readdir7, rename as rename16, rmdir as rmdir3, stat as stat20, unlink as unlink16 } from "node:fs/promises";
63957
64115
  import { uptime as uptime2 } from "node:os";
63958
64116
  import { join as join43, resolve as resolve31 } from "node:path";
63959
64117
  function staleBefore(clock2) {
@@ -64035,7 +64193,7 @@ async function writePortFile(dir, entry, options = {}) {
64035
64193
  await handle.chmod(384);
64036
64194
  await handle.close();
64037
64195
  handle = void 0;
64038
- await rename15(tmp, target);
64196
+ await rename16(tmp, target);
64039
64197
  created = false;
64040
64198
  } finally {
64041
64199
  await handle?.close().catch(() => {