@cortexkit/opencode-antigravity-auth 3.0.9 → 3.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/cli.js +803 -281
  2. package/dist/cli.js.map +4 -4
  3. package/dist/cli.meta.json +142 -53
  4. package/dist/index.js +1114 -471
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +152 -63
  7. package/dist/server.js +1145 -502
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +3 -1
  11. package/dist/src/common-auth-embedded/claustrum/consumer.js +25 -21
  12. package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +5 -0
  13. package/dist/src/common-auth-embedded/claustrum/enrollment.js +27 -0
  14. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -0
  15. package/dist/src/common-auth-embedded/claustrum/index.js +1 -0
  16. package/dist/src/common-auth-embedded/claustrum/quota-writer.d.ts +18 -0
  17. package/dist/src/common-auth-embedded/claustrum/quota-writer.js +253 -0
  18. package/dist/src/common-auth-embedded/claustrum/roster.d.ts +18 -2
  19. package/dist/src/common-auth-embedded/claustrum/roster.js +100 -43
  20. package/dist/src/common-auth-embedded/fs/private-files.d.ts +2 -0
  21. package/dist/src/common-auth-embedded/fs/private-files.js +49 -3
  22. package/dist/src/common-auth-embedded/fs/with-lock.d.ts +1 -0
  23. package/dist/src/common-auth-embedded/fs/with-lock.js +2 -0
  24. package/dist/src/common-auth-embedded/quota/format.d.ts +19 -0
  25. package/dist/src/common-auth-embedded/quota/format.js +50 -5
  26. package/dist/src/common-auth-embedded/quota/index.d.ts +3 -3
  27. package/dist/src/common-auth-embedded/quota/index.js +2 -2
  28. package/dist/src/common-auth-embedded/quota/map.d.ts +24 -1
  29. package/dist/src/common-auth-embedded/quota/map.js +31 -6
  30. package/dist/src/common-auth-embedded/quota/merge.d.ts +6 -1
  31. package/dist/src/common-auth-embedded/quota/merge.js +17 -3
  32. package/dist/src/common-auth-embedded/quota/projection.d.ts +3 -1
  33. package/dist/src/common-auth-embedded/quota/projection.js +3 -1
  34. package/dist/src/common-auth-embedded/setup/enroll.d.ts +34 -0
  35. package/dist/src/common-auth-embedded/setup/enroll.js +116 -34
  36. package/dist/src/common-auth-embedded/setup/index.d.ts +1 -0
  37. package/dist/src/common-auth-embedded/setup/index.js +1 -0
  38. package/dist/src/common-auth-embedded/setup/process-fence.d.ts +14 -0
  39. package/dist/src/common-auth-embedded/setup/process-fence.js +61 -4
  40. package/dist/src/common-auth-embedded/setup/types.d.ts +5 -0
  41. package/dist/src/common-auth-embedded/source-output.json +115 -91
  42. package/dist/src/plugin/lifecycle.d.ts.map +1 -1
  43. package/dist/src/plugin/lifecycle.js +48 -27
  44. package/dist/src/plugin/lifecycle.js.map +1 -1
  45. package/dist/src/plugin/request-helpers.d.ts +5 -0
  46. package/dist/src/plugin/request-helpers.d.ts.map +1 -1
  47. package/dist/src/plugin/request-helpers.js +1 -0
  48. package/dist/src/plugin/request-helpers.js.map +1 -1
  49. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  50. package/dist/src/plugin/shared/request-services.js +125 -7
  51. package/dist/src/plugin/shared/request-services.js.map +1 -1
  52. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  53. package/dist/src/plugin/vault-custody.js +13 -3
  54. package/dist/src/plugin/vault-custody.js.map +1 -1
  55. package/dist/tui-build-map.json +25 -25
  56. package/dist/tui-ga-build-map.json +21 -21
  57. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +3 -1
  58. package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +5 -0
  59. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -0
  60. package/dist/types/src/common-auth-embedded/claustrum/quota-writer.d.ts +18 -0
  61. package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +18 -2
  62. package/dist/types/src/common-auth-embedded/quota/format.d.ts +19 -0
  63. package/dist/types/src/common-auth-embedded/quota/index.d.ts +3 -3
  64. package/dist/types/src/common-auth-embedded/quota/map.d.ts +24 -1
  65. package/dist/types/src/common-auth-embedded/quota/merge.d.ts +6 -1
  66. package/dist/types/src/common-auth-embedded/quota/projection.d.ts +3 -1
  67. package/dist/types/src/common-auth-embedded/setup/enroll.d.ts +34 -0
  68. package/dist/types/src/common-auth-embedded/setup/index.d.ts +1 -0
  69. package/dist/types/src/common-auth-embedded/setup/process-fence.d.ts +14 -0
  70. package/dist/types/src/common-auth-embedded/setup/types.d.ts +5 -0
  71. package/dist/types/src/plugin/config/schema.d.ts +2 -2
  72. package/dist/types/src/plugin/lifecycle.d.ts.map +1 -1
  73. package/dist/types/src/plugin/request-helpers.d.ts +5 -0
  74. package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
  75. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  76. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  77. package/package.json +2 -2
  78. package/src/common-auth-embedded/claustrum/consumer.d.ts +3 -1
  79. package/src/common-auth-embedded/claustrum/consumer.js +25 -21
  80. package/src/common-auth-embedded/claustrum/enrollment.d.ts +5 -0
  81. package/src/common-auth-embedded/claustrum/enrollment.js +27 -0
  82. package/src/common-auth-embedded/claustrum/index.d.ts +1 -0
  83. package/src/common-auth-embedded/claustrum/index.js +1 -0
  84. package/src/common-auth-embedded/claustrum/quota-writer.d.ts +18 -0
  85. package/src/common-auth-embedded/claustrum/quota-writer.js +253 -0
  86. package/src/common-auth-embedded/claustrum/roster.d.ts +18 -2
  87. package/src/common-auth-embedded/claustrum/roster.js +100 -43
  88. package/src/common-auth-embedded/fs/private-files.d.ts +2 -0
  89. package/src/common-auth-embedded/fs/private-files.js +49 -3
  90. package/src/common-auth-embedded/fs/with-lock.d.ts +1 -0
  91. package/src/common-auth-embedded/fs/with-lock.js +2 -0
  92. package/src/common-auth-embedded/quota/format.d.ts +19 -0
  93. package/src/common-auth-embedded/quota/format.js +50 -5
  94. package/src/common-auth-embedded/quota/index.d.ts +3 -3
  95. package/src/common-auth-embedded/quota/index.js +2 -2
  96. package/src/common-auth-embedded/quota/map.d.ts +24 -1
  97. package/src/common-auth-embedded/quota/map.js +31 -6
  98. package/src/common-auth-embedded/quota/merge.d.ts +6 -1
  99. package/src/common-auth-embedded/quota/merge.js +17 -3
  100. package/src/common-auth-embedded/quota/projection.d.ts +3 -1
  101. package/src/common-auth-embedded/quota/projection.js +3 -1
  102. package/src/common-auth-embedded/setup/enroll.d.ts +34 -0
  103. package/src/common-auth-embedded/setup/enroll.js +116 -34
  104. package/src/common-auth-embedded/setup/index.d.ts +1 -0
  105. package/src/common-auth-embedded/setup/index.js +1 -0
  106. package/src/common-auth-embedded/setup/process-fence.d.ts +14 -0
  107. package/src/common-auth-embedded/setup/process-fence.js +61 -4
  108. package/src/common-auth-embedded/setup/types.d.ts +5 -0
  109. package/src/common-auth-embedded/source-output.json +115 -91
  110. package/src/tui-compiled/common-auth-embedded/fs/private-files.js +49 -3
  111. package/src/tui-compiled/common-auth-embedded/quota/format.js +50 -5
  112. package/src/tui-compiled/common-auth-embedded/quota/index.js +2 -2
  113. package/src/tui-compiled/common-auth-embedded/quota/map.js +31 -6
  114. package/src/tui-compiled/common-auth-embedded/quota/merge.js +17 -3
  115. package/src/tui-compiled/common-auth-embedded/quota/projection.js +3 -1
  116. package/src/tui-ga-compiled/shared/1ff34afa7c42d196-projection.js +3 -1
  117. package/src/tui-ga-compiled/shared/77138df80c7ae006-map.js +31 -6
  118. package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +50 -5
  119. package/src/tui-ga-compiled/shared/bf17cbee28e58197-index.js +2 -2
  120. package/src/tui-ga-compiled/shared/ecc214300932dfb6-merge.js +17 -3
  121. package/src/tui-ga-raw/shared/1ff34afa7c42d196-projection.js +3 -1
  122. package/src/tui-ga-raw/shared/77138df80c7ae006-map.js +31 -6
  123. package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +50 -5
  124. package/src/tui-ga-raw/shared/bf17cbee28e58197-index.js +2 -2
  125. package/src/tui-ga-raw/shared/ecc214300932dfb6-merge.js +17 -3
  126. package/src/tui-raw/common-auth-embedded/fs/private-files.js +49 -3
  127. package/src/tui-raw/common-auth-embedded/quota/format.js +50 -5
  128. package/src/tui-raw/common-auth-embedded/quota/index.js +2 -2
  129. package/src/tui-raw/common-auth-embedded/quota/map.js +31 -6
  130. package/src/tui-raw/common-auth-embedded/quota/merge.js +17 -3
  131. package/src/tui-raw/common-auth-embedded/quota/projection.js +3 -1
package/dist/cli.js CHANGED
@@ -65,6 +65,12 @@ function isQuotaCounter(value) {
65
65
  function isQuotaCounters(value) {
66
66
  return isRecord2(value) && Object.values(value).every(isQuotaCounter);
67
67
  }
68
+ function isBoolean(value) {
69
+ return typeof value === "boolean";
70
+ }
71
+ function isQuotaCredits(value) {
72
+ return isRecord2(value) && typeof value.hasCredits === "boolean" && typeof value.unlimited === "boolean" && optional2(value, "balance", isFiniteNumber) && optional2(value, "overageLimitReached", isBoolean) && isFiniteNumber(value.checkedAt);
73
+ }
68
74
  function readQuotaCounters(value) {
69
75
  if (!isRecord2(value))
70
76
  return void 0;
@@ -76,11 +82,16 @@ function decodeQuotaMap(value) {
76
82
  return value;
77
83
  if (!isRecord2(value))
78
84
  return void 0;
79
- const { counters: rawCounters, ...rest } = value;
85
+ const { counters: rawCounters, credits: rawCredits, ...rest } = value;
80
86
  if (!isQuotaMap(rest))
81
87
  return void 0;
82
88
  const counters = readQuotaCounters(rawCounters);
83
- return { ...rest, ...counters === void 0 ? {} : { counters } };
89
+ const credits = isQuotaCredits(rawCredits) ? rawCredits : void 0;
90
+ return {
91
+ ...rest,
92
+ ...counters === void 0 ? {} : { counters },
93
+ ...credits === void 0 ? {} : { credits }
94
+ };
84
95
  }
85
96
  function isQuotaMap(value) {
86
97
  if (!isRecord2(value) || !Array.isArray(value.limits))
@@ -94,7 +105,7 @@ function isQuotaMap(value) {
94
105
  return false;
95
106
  seen.add(key);
96
107
  }
97
- return optional2(value, "budget", isCreditBudgetEntry) && optional2(value, "counters", isQuotaCounters);
108
+ return optional2(value, "budget", isCreditBudgetEntry) && optional2(value, "counters", isQuotaCounters) && optional2(value, "credits", isQuotaCredits);
98
109
  }
99
110
  var ALL_SCOPE, DEFAULT_REQUIRED_LABELS;
100
111
  var init_map = __esm({
@@ -157,7 +168,7 @@ function isQuotaObservation(value) {
157
168
  }
158
169
  if (!coverage.every(isObservedPair))
159
170
  return false;
160
- return (value.budget === void 0 || isObservedBudget(value.budget)) && (value.counters === void 0 || isQuotaCounters(value.counters));
171
+ return (value.budget === void 0 || isObservedBudget(value.budget)) && (value.counters === void 0 || isQuotaCounters(value.counters)) && (value.credits === void 0 || isQuotaCredits(value.credits));
161
172
  }
162
173
  function compareEntries(left, right) {
163
174
  if (left.scope !== right.scope)
@@ -183,6 +194,14 @@ function mergeCounters(stored, observed) {
183
194
  }
184
195
  return counters.size === 0 ? void 0 : Object.fromEntries(counters);
185
196
  }
197
+ function mergeCredits(stored, observed) {
198
+ if (observed === void 0)
199
+ return stored;
200
+ if (stored !== void 0 && observed.checkedAt < stored.checkedAt) {
201
+ return stored;
202
+ }
203
+ return { ...observed };
204
+ }
186
205
  function mergeQuotaObservation(stored, observation) {
187
206
  const decoded = stored === void 0 ? void 0 : decodeQuotaMap(stored);
188
207
  if (stored !== void 0 && decoded === void 0) {
@@ -226,14 +245,16 @@ function mergeQuotaObservation(stored, observation) {
226
245
  const existing = entries.get(key);
227
246
  entries.set(key, existing === void 0 || existing.kind === "absent" ? { scope, label: pair.label, kind: "absent", checkedAt: at } : { scope, label: pair.label, kind: "retired", retiredAt: at });
228
247
  }
229
- const { limits: _limits, budget: _budget, counters: _counters, ...unknownKeys } = base;
248
+ const { limits: _limits, budget: _budget, counters: _counters, credits: _credits, ...unknownKeys } = base;
230
249
  const budget = mergeBudget(base.budget, observation.budget, at);
231
250
  const counters = mergeCounters(base.counters, observation.counters);
251
+ const credits = mergeCredits(base.credits, observation.credits);
232
252
  return {
233
253
  ...unknownKeys,
234
254
  limits: [...entries.values()].sort(compareEntries),
235
255
  ...budget === void 0 ? {} : { budget },
236
- ...counters === void 0 ? {} : { counters }
256
+ ...counters === void 0 ? {} : { counters },
257
+ ...credits === void 0 ? {} : { credits }
237
258
  };
238
259
  }
239
260
  var QuotaCodecError;
@@ -328,6 +349,13 @@ function quotaWindowParts(quota, options) {
328
349
  const parts = windows.map(({ part }) => part);
329
350
  return age === void 0 ? { windows: parts } : { windows: parts, age };
330
351
  }
352
+ function withShortNames(windows) {
353
+ const abbreviations = scopeAbbreviations(windows.filter(({ part, scope }) => part.kind === "window" && scope !== ALL_SCOPE).map(({ scope }) => scope));
354
+ for (const window of windows) {
355
+ window.part.short = window.part.kind === "budget" ? "cr" : window.scope === ALL_SCOPE ? window.part.name : abbreviations.get(window.scope) ?? window.scope;
356
+ }
357
+ return windows;
358
+ }
331
359
  function scopedWindowParts(quota, options) {
332
360
  if (!quota)
333
361
  return { windows: [] };
@@ -341,6 +369,7 @@ function scopedWindowParts(quota, options) {
341
369
  part: {
342
370
  kind: "window",
343
371
  name: quotaWindowName(limit),
372
+ short: "",
344
373
  figure: percentLeft(limit.remainingPercent ?? 0),
345
374
  remainingPercent,
346
375
  checkedAt: limit.checkedAt,
@@ -358,6 +387,7 @@ function scopedWindowParts(quota, options) {
358
387
  part: {
359
388
  kind: "budget",
360
389
  name: "credits",
390
+ short: "",
361
391
  figure,
362
392
  ...remainingPercent === void 0 ? {} : { remainingPercent: clampPercent(remainingPercent) },
363
393
  checkedAt: budget.checkedAt,
@@ -365,6 +395,7 @@ function scopedWindowParts(quota, options) {
365
395
  }
366
396
  });
367
397
  }
398
+ withShortNames(windows);
368
399
  if (windows.length > 0) {
369
400
  const age = now - Math.min(...windows.map(({ part }) => part.checkedAt));
370
401
  if (age > (options.staleAfterMs ?? QUOTA_STALE_AFTER_MS)) {
@@ -444,15 +475,14 @@ function narrowTextParts(quota, options) {
444
475
  return grouped;
445
476
  const general = windows.filter(({ part, scope }) => part.kind === "window" && scope === ALL_SCOPE);
446
477
  const scoped = windows.filter(({ part, scope }) => part.kind === "window" && scope !== ALL_SCOPE);
447
- const abbreviations = scopeAbbreviations(scoped.map(({ scope }) => scope));
448
478
  const budget = windows.find(({ part }) => part.kind === "budget");
449
479
  const budgetLeft = budget?.spent ? 0 : budget?.part.remainingPercent;
450
480
  const extras = [
451
- ...scoped.map(({ scope, part }) => ({
452
- label: abbreviations.get(scope) ?? scope,
481
+ ...scoped.map(({ part }) => ({
482
+ label: part.short,
453
483
  remaining: part.remainingPercent ?? 0
454
484
  })),
455
- ...budgetLeft === void 0 ? [] : [{ label: "cr", remaining: budgetLeft }]
485
+ ...budgetLeft === void 0 || budget === void 0 ? [] : [{ label: budget.part.short, remaining: budgetLeft }]
456
486
  ];
457
487
  const tightest = extras.reduce((best, item) => best === void 0 || item.remaining < best.remaining ? item : best, void 0);
458
488
  const pieces = general.map(({ part }) => `${part.name} ${wholePercent(part.remainingPercent ?? 0)}%`);
@@ -480,6 +510,16 @@ function formatQuota(quota, options) {
480
510
  return parts.join(" \xB7 ");
481
511
  return quota && quota.limits.length > 0 ? NO_LIMITS_REPORTED : NO_QUOTA_READING;
482
512
  }
513
+ function quotaCreditsText(credits) {
514
+ if (credits === void 0)
515
+ return void 0;
516
+ if (credits.unlimited)
517
+ return "Unlimited";
518
+ if (!credits.hasCredits)
519
+ return void 0;
520
+ const { balance } = credits;
521
+ return typeof balance === "number" && Number.isFinite(balance) && balance > 0 ? `${Math.round(balance)} credits` : "Available";
522
+ }
483
523
  var QUOTA_STALE_AFTER_MS, NO_QUOTA_READING, NO_LIMITS_REPORTED, NARROW_GROUP_LIMIT;
484
524
  var init_format = __esm({
485
525
  "../core/dist/common-auth-embedded/quota/format.js"() {
@@ -561,12 +601,14 @@ function projectQuota(map, scope = ALL_SCOPE) {
561
601
  const checkedAt = stamped.length > 0 ? Math.min(...stamped.map((limit) => limit.checkedAt)) : void 0;
562
602
  const budget = map?.budget?.kind === "reading" ? projectBudget(map.budget) : void 0;
563
603
  const counters = readQuotaCounters(map?.counters);
604
+ const credits = isQuotaCredits(map?.credits) ? map.credits : void 0;
564
605
  return {
565
606
  scope,
566
607
  limits,
567
608
  ...checkedAt === void 0 ? {} : { checkedAt },
568
609
  ...budget === void 0 ? {} : { budget },
569
- ...counters === void 0 ? {} : { counters }
610
+ ...counters === void 0 ? {} : { counters },
611
+ ...credits === void 0 ? {} : { credits }
570
612
  };
571
613
  }
572
614
  function budgetExhaustedResetAt(quota, now) {
@@ -609,12 +651,14 @@ __export(quota_exports, {
609
651
  emptyQuotaMap: () => emptyQuotaMap,
610
652
  formatQuota: () => formatQuota,
611
653
  futureResetAt: () => futureResetAt,
654
+ isQuotaCredits: () => isQuotaCredits,
612
655
  isQuotaMap: () => isQuotaMap,
613
656
  isQuotaObservation: () => isQuotaObservation,
614
657
  isQuotaStale: () => isQuotaStale,
615
658
  mergeQuotaObservation: () => mergeQuotaObservation,
616
659
  projectQuota: () => projectQuota,
617
660
  quotaCodec: () => quotaCodec2,
661
+ quotaCreditsText: () => quotaCreditsText,
618
662
  quotaTextParts: () => quotaTextParts,
619
663
  quotaWindowName: () => quotaWindowName,
620
664
  quotaWindowParts: () => quotaWindowParts,
@@ -721,7 +765,8 @@ var init_identity = __esm({
721
765
  // ../core/dist/common-auth-embedded/fs/private-files.js
722
766
  import { randomUUID as randomUUID5 } from "node:crypto";
723
767
  import { lstat as lstat2, readFile as readFile4, rename as rename3, unlink as unlink5 } from "node:fs/promises";
724
- import { dirname as dirname5, resolve as resolve2 } from "node:path";
768
+ import { tmpdir } from "node:os";
769
+ import { dirname as dirname5, join as join4, resolve as resolve2 } from "node:path";
725
770
  function ioCode(detail) {
726
771
  if (detail?.reason === "io-error") {
727
772
  if (detail.win32Code === 2 || detail.win32Code === 3)
@@ -731,8 +776,31 @@ function ioCode(detail) {
731
776
  }
732
777
  return detail?.code ?? "ERR_PRIVATE_FILE";
733
778
  }
779
+ function privateFilesUnavailable(cause) {
780
+ return Object.assign(new Error("Windows private-files native addon is unavailable", { cause }), {
781
+ code: "ERR_PRIVATE_FILES_UNAVAILABLE",
782
+ reason: PRIVATE_FILES_UNAVAILABLE_REASON
783
+ });
784
+ }
785
+ function isUnavailable(api, error) {
786
+ return error instanceof api.PrivateFilesUnavailableError || error?.code === "ERR_PRIVATE_FILES_UNAVAILABLE";
787
+ }
788
+ async function assertNativeAddonLoads(api) {
789
+ try {
790
+ await api.verifyPrivatePath(join4(tmpdir(), `.common-auth-private-files-probe-${randomUUID5()}`), "file");
791
+ } catch (error) {
792
+ if (isUnavailable(api, error))
793
+ throw privateFilesUnavailable(error);
794
+ }
795
+ }
734
796
  function loadBackend() {
735
- backend ??= import("@cortexkit/private-files");
797
+ backend ??= import("@cortexkit/private-files").then(async (api) => {
798
+ if (windowsPrivateFiles)
799
+ await assertNativeAddonLoads(api);
800
+ return api;
801
+ }, (cause) => {
802
+ throw windowsPrivateFiles ? privateFilesUnavailable(cause) : cause;
803
+ });
736
804
  return backend;
737
805
  }
738
806
  async function privateOperation(path2, stage, operation) {
@@ -958,12 +1026,13 @@ async function writePrivateAtomic(path2, bytes, options = {}) {
958
1026
  });
959
1027
  }
960
1028
  }
961
- var windowsPrivateFiles, migrationNotices, backend, PrivateFileError, safeParentOptionsForTest;
1029
+ var windowsPrivateFiles, migrationNotices, backend, PRIVATE_FILES_UNAVAILABLE_REASON, PrivateFileError, safeParentOptionsForTest;
962
1030
  var init_private_files = __esm({
963
1031
  "../core/dist/common-auth-embedded/fs/private-files.js"() {
964
1032
  "use strict";
965
1033
  windowsPrivateFiles = process.platform === "win32";
966
1034
  migrationNotices = /* @__PURE__ */ new Set();
1035
+ PRIVATE_FILES_UNAVAILABLE_REASON = "native-addon-unavailable";
967
1036
  PrivateFileError = class extends Error {
968
1037
  path;
969
1038
  stage;
@@ -978,7 +1047,7 @@ var init_private_files = __esm({
978
1047
  orphanPath;
979
1048
  constructor(path2, stage, cause) {
980
1049
  const detail = cause;
981
- super(`Private file refused at ${stage}: ${path2} (${detail?.reason ?? detail?.code ?? "io-error"}). Use a safe parent directory. Repair only a named secret file in safe ancestry whose owner the published policy trusts, without changing its owner or any existing directory. Previously exposed credentials may need rotation. Windows requires the private-files native prebuild and an ACL-persisting local filesystem such as NTFS.`, { cause });
1050
+ super(detail?.code === "ERR_PRIVATE_FILES_UNAVAILABLE" ? `Private file refused at ${stage}: ${path2} (${PRIVATE_FILES_UNAVAILABLE_REASON}). The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.` : `Private file refused at ${stage}: ${path2} (${detail?.reason ?? detail?.code ?? "io-error"}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
982
1051
  this.path = path2;
983
1052
  this.stage = stage;
984
1053
  this.name = "PrivateFileError";
@@ -1089,7 +1158,7 @@ var init_atomic_write = __esm({
1089
1158
  // ../core/dist/common-auth-embedded/fs/refresh-file-lock.js
1090
1159
  import { randomUUID as randomUUID7 } from "node:crypto";
1091
1160
  import { mkdir as mkdir7, open as open4, readFile as readFile5, rename as rename5, rm as rm4, stat as stat3 } from "node:fs/promises";
1092
- import { dirname as dirname7, join as join4 } from "node:path";
1161
+ import { dirname as dirname7, join as join5 } from "node:path";
1093
1162
  async function createExclusiveText(path2, text2) {
1094
1163
  const handle = await open4(path2, "wx", 384);
1095
1164
  try {
@@ -1107,7 +1176,7 @@ function acquireRefreshFileLock(options) {
1107
1176
  }
1108
1177
  async function acquireRefreshFileLockWithClock(options) {
1109
1178
  const lockPath = lockPathFor(options.path, options.name);
1110
- const legacyOwnerPath = join4(lockPath, "owner.json");
1179
+ const legacyOwnerPath = join5(lockPath, "owner.json");
1111
1180
  const ownerId = randomUUID7();
1112
1181
  const now = options.now ?? Date.now;
1113
1182
  let renewTimer = null;
@@ -1115,8 +1184,8 @@ async function acquireRefreshFileLockWithClock(options) {
1115
1184
  let releaseConfirmed = false;
1116
1185
  let loss;
1117
1186
  let resolveLoss;
1118
- const lostPromise = new Promise((resolve13) => {
1119
- resolveLoss = resolve13;
1187
+ const lostPromise = new Promise((resolve15) => {
1188
+ resolveLoss = resolve15;
1120
1189
  });
1121
1190
  function notifyTimerStep(event) {
1122
1191
  try {
@@ -1150,7 +1219,7 @@ async function acquireRefreshFileLockWithClock(options) {
1150
1219
  let terminalIOError;
1151
1220
  let renewalInFlight = null;
1152
1221
  const evictPath = `${lockPath}.evicting`;
1153
- const evictOwnerPath = join4(evictPath, "owner.json");
1222
+ const evictOwnerPath = join5(evictPath, "owner.json");
1154
1223
  const evictOwnerId = randomUUID7();
1155
1224
  const EVICT_TTL = 5e3;
1156
1225
  const MAX_STEAL_ATTEMPTS = 8;
@@ -1273,7 +1342,7 @@ async function acquireRefreshFileLockWithClock(options) {
1273
1342
  }
1274
1343
  }
1275
1344
  async function backoff() {
1276
- await new Promise((resolve13) => setTimeout(resolve13, Math.floor(Math.random() * 4)));
1345
+ await new Promise((resolve15) => setTimeout(resolve15, Math.floor(Math.random() * 4)));
1277
1346
  }
1278
1347
  async function readLockState(notifyReady = true) {
1279
1348
  if (notifyReady && options.onStep)
@@ -1723,6 +1792,7 @@ function lockPathFor(target, name) {
1723
1792
  async function withLock(target, options, fn) {
1724
1793
  const started = performance.now();
1725
1794
  for (; ; ) {
1795
+ options.signal?.throwIfAborted();
1726
1796
  const lock = await acquireRefreshFileLock({
1727
1797
  path: target,
1728
1798
  name: options.name,
@@ -1733,6 +1803,7 @@ async function withLock(target, options, fn) {
1733
1803
  });
1734
1804
  if (lock) {
1735
1805
  try {
1806
+ options.signal?.throwIfAborted();
1736
1807
  return await fn(lock);
1737
1808
  } finally {
1738
1809
  await lock.release();
@@ -1746,7 +1817,7 @@ async function withLock(target, options, fn) {
1746
1817
  timeoutMs: options.timeoutMs
1747
1818
  });
1748
1819
  }
1749
- await new Promise((resolve13) => setTimeout(resolve13, Math.min(25, Math.ceil(remaining))));
1820
+ await new Promise((resolve15) => setTimeout(resolve15, Math.min(25, Math.ceil(remaining))));
1750
1821
  }
1751
1822
  }
1752
1823
  var LockContentionError, LockOwnershipError;
@@ -1782,13 +1853,13 @@ function assertNotInsideHook(operation) {
1782
1853
  function runInsideHook(operation, fn) {
1783
1854
  return insideHook.run(operation, async () => await fn());
1784
1855
  }
1785
- async function callFailureHook(operation, hook, rowId2, error, logger) {
1856
+ async function callFailureHook(operation, hook, rowId2, error, logger2) {
1786
1857
  if (!hook)
1787
1858
  return;
1788
1859
  try {
1789
1860
  await runInsideHook(operation, () => hook(rowId2, error));
1790
1861
  } catch (hookError) {
1791
- logger?.warn("store failure hook threw; the original failure stands", {
1862
+ logger2?.warn("store failure hook threw; the original failure stands", {
1792
1863
  operation,
1793
1864
  rowId: rowId2,
1794
1865
  error: hookError instanceof Error ? hookError.message : String(hookError)
@@ -1865,7 +1936,7 @@ async function acquirePoolLock(spec, defaults, env3) {
1865
1936
  });
1866
1937
  }
1867
1938
  const jitter = Math.floor(Math.random() * (options.retryMs + 1));
1868
- await new Promise((resolve13) => setTimeout(resolve13, Math.min(options.retryMs + jitter, remaining)));
1939
+ await new Promise((resolve15) => setTimeout(resolve15, Math.min(options.retryMs + jitter, remaining)));
1869
1940
  }
1870
1941
  }
1871
1942
  function definedOnly(spec) {
@@ -2943,11 +3014,11 @@ var init_mutate = __esm({
2943
3014
  if (isRecord4(this.state.accounts) && Object.hasOwn(this.state.accounts, id))
2944
3015
  delete this.state.accounts[id];
2945
3016
  }
2946
- setStateAccount(id, fields) {
3017
+ setStateAccount(id, fields2) {
2947
3018
  if (!isRecord4(this.state.accounts))
2948
3019
  this.state.accounts = {};
2949
3020
  Object.defineProperty(this.state.accounts, id, {
2950
- value: fields,
3021
+ value: fields2,
2951
3022
  enumerable: true,
2952
3023
  writable: true,
2953
3024
  configurable: true
@@ -4496,12 +4567,12 @@ var init_pull = __esm({
4496
4567
  firedAtLoad;
4497
4568
  logger;
4498
4569
  inflight = /* @__PURE__ */ new Set();
4499
- constructor(rt, hook, onFailure, firedAtLoad, logger) {
4570
+ constructor(rt, hook, onFailure, firedAtLoad, logger2) {
4500
4571
  this.rt = rt;
4501
4572
  this.hook = hook;
4502
4573
  this.onFailure = onFailure;
4503
4574
  this.firedAtLoad = firedAtLoad;
4504
- this.logger = logger;
4575
+ this.logger = logger2;
4505
4576
  }
4506
4577
  fire(id, reason) {
4507
4578
  if (!this.hook)
@@ -5583,15 +5654,15 @@ function createRedactor(options = {}) {
5583
5654
  return SECRET_KEY_EXACT.test(key) || normalized.includes("apikey") || normalized.endsWith("secret") || normalized.endsWith("password") || normalized.endsWith("token") && !normalized.endsWith("tokens") || !!options.extraSecretKeys?.(normalized);
5584
5655
  }
5585
5656
  function errorEntries(error) {
5586
- const fields = error;
5657
+ const fields2 = error;
5587
5658
  const entries = [
5588
5659
  ["name", error.name],
5589
5660
  ["message", error.message],
5590
5661
  ["stack", error.stack]
5591
5662
  ];
5592
5663
  for (const key of ["code", "status", "cause"])
5593
- if (fields[key] !== void 0)
5594
- entries.push([key, fields[key]]);
5664
+ if (fields2[key] !== void 0)
5665
+ entries.push([key, fields2[key]]);
5595
5666
  const listed = new Set(entries.map(([key]) => key));
5596
5667
  for (const entry of Object.entries(error))
5597
5668
  if (!listed.has(entry[0]))
@@ -5833,7 +5904,7 @@ function createEngine(options) {
5833
5904
  } catch {
5834
5905
  }
5835
5906
  }
5836
- function schedule() {
5907
+ function schedule2() {
5837
5908
  if (!timer)
5838
5909
  timer = setTimeout(() => {
5839
5910
  timer = void 0;
@@ -5875,7 +5946,7 @@ function createEngine(options) {
5875
5946
  void flushed.catch(() => {
5876
5947
  });
5877
5948
  } else
5878
- schedule();
5949
+ schedule2();
5879
5950
  } catch {
5880
5951
  }
5881
5952
  }
@@ -6746,9 +6817,9 @@ function findAction(sections, request) {
6746
6817
  return actions?.find((action) => action.id === request.actionId);
6747
6818
  }
6748
6819
  function createCommandMenu(options) {
6749
- const logger = options.logger ?? createLogger2("commands");
6820
+ const logger2 = options.logger ?? createLogger2("commands");
6750
6821
  const redact3 = createTextRedactor(options.redaction);
6751
- const seam = { logger, redact: redact3 };
6822
+ const seam = { logger: logger2, redact: redact3 };
6752
6823
  const now = options.now ?? Date.now;
6753
6824
  const extras = options.extras ?? [];
6754
6825
  const replaced = options.replace ?? {};
@@ -6775,7 +6846,7 @@ function createCommandMenu(options) {
6775
6846
  content: await section.build(invocation)
6776
6847
  };
6777
6848
  } catch (error) {
6778
- logger.warn("command menu section failed to build", {
6849
+ logger2.warn("command menu section failed to build", {
6779
6850
  command: options.command,
6780
6851
  section: id,
6781
6852
  error: redact3(error instanceof Error ? error.message : String(error))
@@ -6862,7 +6933,7 @@ function createCommandMenu(options) {
6862
6933
  };
6863
6934
  } catch (error) {
6864
6935
  const failure = projectFailure(error);
6865
- logger.warn("command menu action failed", {
6936
+ logger2.warn("command menu action failed", {
6866
6937
  command: options.command,
6867
6938
  section: request.sectionId,
6868
6939
  action: request.actionId,
@@ -7474,7 +7545,7 @@ async function select(terminal, items, options) {
7474
7545
  writeLine("");
7475
7546
  renderedLines = lines;
7476
7547
  };
7477
- return new Promise((resolve13) => {
7548
+ return new Promise((resolve15) => {
7478
7549
  const wasRaw = stdin.isRaw ?? false;
7479
7550
  const cleanup2 = () => {
7480
7551
  if (cleaned)
@@ -7494,7 +7565,7 @@ async function select(terminal, items, options) {
7494
7565
  };
7495
7566
  const finish = (value) => {
7496
7567
  cleanup2();
7497
- resolve13(value);
7568
+ resolve15(value);
7498
7569
  };
7499
7570
  const onSignal = () => finish(null);
7500
7571
  const onKey = (data) => {
@@ -7534,7 +7605,7 @@ async function select(terminal, items, options) {
7534
7605
  stdin.setRawMode(true);
7535
7606
  } catch {
7536
7607
  cleanup2();
7537
- resolve13(null);
7608
+ resolve15(null);
7538
7609
  return;
7539
7610
  }
7540
7611
  stdin.resume();
@@ -8817,7 +8888,7 @@ var init_any_signal = __esm({
8817
8888
  import { createHash as createHash5, randomBytes as randomBytes2, randomUUID as randomUUID10 } from "node:crypto";
8818
8889
  import { constants as fsConstants } from "node:fs";
8819
8890
  import { chmod as chmod2, mkdir as mkdir8, open as open6, readFile as readFile6, realpath as realpath3, rename as rename6, stat as stat4, unlink as unlink6 } from "node:fs/promises";
8820
- import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join5, resolve as resolve5 } from "node:path";
8891
+ import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join6, resolve as resolve5 } from "node:path";
8821
8892
  import { ClaustrumCredentialError as ClaustrumCredentialError2, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
8822
8893
  function classifyEnrollmentError(error) {
8823
8894
  if (!(error instanceof ClaustrumCredentialError2))
@@ -8843,7 +8914,7 @@ function getClaustrumEnrollmentPaths(tokenPath) {
8843
8914
  const extension = extname(tokenPath) || ".json";
8844
8915
  const stem = basename3(tokenPath, extname(tokenPath));
8845
8916
  return {
8846
- statePath: join5(dirname9(tokenPath), `${stem}-state${extension}`),
8917
+ statePath: join6(dirname9(tokenPath), `${stem}-state${extension}`),
8847
8918
  tokenPath
8848
8919
  };
8849
8920
  }
@@ -8851,7 +8922,7 @@ function hostEnrollmentPaths(input) {
8851
8922
  const override = input.override?.trim();
8852
8923
  if (override && !isAbsolute2(override) && !input.cwd)
8853
8924
  throw new ClaustrumConsumerError("invalid-state", "A relative Claustrum enrollment override needs a base directory");
8854
- const tokenPath = override ? isAbsolute2(override) ? override : resolve5(input.cwd, override) : join5(input.stateDir, `${input.host}-enrollment.json`);
8925
+ const tokenPath = override ? isAbsolute2(override) ? override : resolve5(input.cwd, override) : join6(input.stateDir, `${input.host}-enrollment.json`);
8855
8926
  return getClaustrumEnrollmentPaths(tokenPath);
8856
8927
  }
8857
8928
  function isRecord6(value) {
@@ -8980,13 +9051,13 @@ async function readBoundedJson(path2) {
8980
9051
  await descriptor.close();
8981
9052
  }
8982
9053
  }
8983
- function accountRecords(text2, fields) {
9054
+ function accountRecords(text2, fields2) {
8984
9055
  const records = [];
8985
9056
  for (const line of text2.split("\n")) {
8986
9057
  if (line.trim() === "" || line.startsWith("#"))
8987
9058
  continue;
8988
9059
  const parts = line.split(":");
8989
- if (parts.length !== fields || !/^[^\s:,]+$/.test(parts[0] ?? "") || !/^\d+$/.test(parts[2] ?? "") || !Number.isSafeInteger(Number(parts[2])) || fields === 7 && (!/^\d+$/.test(parts[3] ?? "") || !Number.isSafeInteger(Number(parts[3]))) || fields === 4 && parts[3] !== "" && !/^[^\s:,]+(?:,[^\s:,]+)*$/.test(parts[3] ?? ""))
9060
+ if (parts.length !== fields2 || !/^[^\s:,]+$/.test(parts[0] ?? "") || !/^\d+$/.test(parts[2] ?? "") || !Number.isSafeInteger(Number(parts[2])) || fields2 === 7 && (!/^\d+$/.test(parts[3] ?? "") || !Number.isSafeInteger(Number(parts[3]))) || fields2 === 4 && parts[3] !== "" && !/^[^\s:,]+(?:,[^\s:,]+)*$/.test(parts[3] ?? ""))
8990
9061
  return void 0;
8991
9062
  records.push(parts);
8992
9063
  }
@@ -9084,7 +9155,7 @@ async function writeStateAtomic(path2, state, ancestorOptions = {}) {
9084
9155
  }
9085
9156
  if (windowsPrivateFiles)
9086
9157
  return writePrivateAtomic(path2, bytes);
9087
- const temporary = join5(parent, `.${basename3(path2)}.${process.pid}.${randomUUID10()}.tmp`);
9158
+ const temporary = join6(parent, `.${basename3(path2)}.${process.pid}.${randomUUID10()}.tmp`);
9088
9159
  let descriptor;
9089
9160
  let created = false;
9090
9161
  try {
@@ -9261,7 +9332,7 @@ async function disconnectClaustrumEnrollment(paths, proposedName) {
9261
9332
  await lock.release();
9262
9333
  }
9263
9334
  }
9264
- var ENROLLMENT_SCHEMA, ENROLLMENT_FILE_MAX_BYTES, ENROLLMENT_LOCK_TTL_MS, TOKEN_RE, TERMINAL_ENROLLMENT_CODES, RETRYABLE_ENROLLMENT_CODES, ClaustrumEnrollmentManager;
9335
+ var ENROLLMENT_SCHEMA, ENROLLMENT_FILE_MAX_BYTES, ENROLLMENT_LOCK_TTL_MS, TOKEN_RE, UNSUPPORTED_ENROLLMENT_CODE, TERMINAL_ENROLLMENT_CODES, RETRYABLE_ENROLLMENT_CODES, ClaustrumEnrollmentManager;
9265
9336
  var init_enrollment = __esm({
9266
9337
  "../core/dist/common-auth-embedded/claustrum/enrollment.js"() {
9267
9338
  "use strict";
@@ -9272,7 +9343,13 @@ var init_enrollment = __esm({
9272
9343
  ENROLLMENT_FILE_MAX_BYTES = 16 * 1024;
9273
9344
  ENROLLMENT_LOCK_TTL_MS = 3e4;
9274
9345
  TOKEN_RE = /^[0-9a-f]{64}$/;
9346
+ UNSUPPORTED_ENROLLMENT_CODE = "unknown_method";
9275
9347
  TERMINAL_ENROLLMENT_CODES = /* @__PURE__ */ new Set([
9348
+ // The daemon's answer to an operation it does not implement: a vault built
9349
+ // before the enrollment ceremony. It arrives as a transport Error frame with
9350
+ // no class, which claustrum-client before 0.13.0 labels transient/retry, but
9351
+ // asking again can never succeed.
9352
+ UNSUPPORTED_ENROLLMENT_CODE,
9276
9353
  "invalid_params",
9277
9354
  "pending_exists",
9278
9355
  "not_found",
@@ -9406,6 +9483,18 @@ var init_enrollment = __esm({
9406
9483
  retryCode: refusal3.code
9407
9484
  };
9408
9485
  }
9486
+ if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE) {
9487
+ await lock.assertOwned();
9488
+ await unlink6(this.#paths.statePath).catch((cause) => {
9489
+ if (cause.code !== "ENOENT")
9490
+ throw cause;
9491
+ });
9492
+ return {
9493
+ state: "unavailable",
9494
+ proposedName: state.proposedName,
9495
+ code: refusal3.code
9496
+ };
9497
+ }
9409
9498
  return this.#block(state, refusal3.code);
9410
9499
  }
9411
9500
  }
@@ -9536,9 +9625,9 @@ function scopedRetryReason(served, current) {
9536
9625
  return "version-unchanged";
9537
9626
  return "rotated";
9538
9627
  }
9539
- function decideScopedRetryAfter401(site, served, current, logger = defaultLogger) {
9628
+ function decideScopedRetryAfter401(site, served, current, logger2 = defaultLogger) {
9540
9629
  const retry = isScopedCredentialRotation(served, current);
9541
- logger.debug("scoped 401 re-authorized", {
9630
+ logger2.debug("scoped 401 re-authorized", {
9542
9631
  site,
9543
9632
  credentialId: served.credentialId,
9544
9633
  servedVersion: served.recordVersion,
@@ -10111,6 +10200,7 @@ var init_interlock = __esm({
10111
10200
 
10112
10201
  // ../core/dist/common-auth-embedded/claustrum/roster.js
10113
10202
  import { createHash as createHash6 } from "node:crypto";
10203
+ import { resolve as resolve6 } from "node:path";
10114
10204
  function hash(value) {
10115
10205
  return createHash6("sha256").update(value).digest("hex");
10116
10206
  }
@@ -10331,7 +10421,7 @@ async function readVaultRoster(path2) {
10331
10421
  return decodeRoster(value);
10332
10422
  }
10333
10423
  async function mutateVaultRoster(path2, change, options = {}) {
10334
- return withLock(path2, WRITE_LOCK, async (lock) => {
10424
+ return withLock(path2, { ...WRITE_LOCK, signal: options.signal }, async (lock) => {
10335
10425
  const current = await readVaultRoster(path2);
10336
10426
  const { next, result } = await change(current, {
10337
10427
  assertOwned: () => lock.assertOwned()
@@ -10341,6 +10431,7 @@ async function mutateVaultRoster(path2, change, options = {}) {
10341
10431
  await writeJsonAtomic2(path2, next, {
10342
10432
  beforeRename: async () => {
10343
10433
  await options.beforePublish?.();
10434
+ options.signal?.throwIfAborted();
10344
10435
  await lock.assertOwned();
10345
10436
  }
10346
10437
  });
@@ -10390,43 +10481,51 @@ function receiptFence(row, receipt2) {
10390
10481
  return "bind";
10391
10482
  return "refuse";
10392
10483
  }
10393
- function recordVaultQuota(path2, input) {
10394
- return mutateVaultRoster(path2, (current) => {
10395
- const row = current?.rows.find((entry) => entry.routeId === input.routeId);
10396
- const fence = !current || !row ? "refuse" : receiptFence(row, input);
10397
- if (!current || !row || fence === "refuse")
10398
- return { result: false };
10399
- const quota = mergeQuotaObservation(row.quota, input.observation);
10400
- const bound = fence === "bind" ? { accountIdentity: input.accountIdentity, unclaimed: true } : {};
10401
- return {
10402
- next: {
10403
- ...current,
10404
- rows: current.rows.map((entry) => entry === row ? { ...entry, ...bound, quota } : entry)
10405
- },
10406
- result: true
10407
- };
10484
+ async function recordVaultQuota(path2, input) {
10485
+ const { routeId, observation, ...receipt2 } = input;
10486
+ return enqueueFencedVaultQuota(path2, {
10487
+ routeId,
10488
+ observation,
10489
+ accountIdentity: receipt2.accountIdentity,
10490
+ receipt: receipt2
10408
10491
  });
10409
10492
  }
10493
+ async function enqueueFencedVaultQuota(path2, publication2) {
10494
+ if (!isQuotaObservation(publication2.observation))
10495
+ return false;
10496
+ const current = pendingVaultQuota(path2, await readVaultRoster(path2));
10497
+ if (!applyVaultQuota(current, publication2).kept)
10498
+ return false;
10499
+ return enqueueVaultQuota(path2, publication2);
10500
+ }
10410
10501
  function recordVaultAccountQuota(path2, input) {
10411
- return mutateVaultRoster(path2, (current) => {
10412
- const row = current?.rows.find((entry) => entry.routeId === input.routeId);
10413
- if (!current || !row || row.accountIdentity === void 0 || row.accountIdentity !== input.accountIdentity)
10414
- return { result: false };
10415
- const quota = mergeQuotaObservation(row.quota, input.observation);
10416
- return {
10417
- next: {
10418
- ...current,
10419
- rows: current.rows.map((entry) => entry === row ? { ...entry, quota } : entry)
10420
- },
10421
- result: true
10422
- };
10423
- });
10502
+ return enqueueFencedVaultQuota(path2, input);
10503
+ }
10504
+ function applyVaultQuota(current, input) {
10505
+ const row = current?.rows.find((entry) => entry.routeId === input.routeId);
10506
+ const fence = !row ? "refuse" : input.receipt ? receiptFence(row, input.receipt) : row.accountIdentity !== void 0 && row.accountIdentity === input.accountIdentity ? "hold" : "refuse";
10507
+ if (!current || !row || fence === "refuse")
10508
+ return { roster: current, kept: false };
10509
+ const quota = mergeQuotaObservation(row.quota, input.observation);
10510
+ const bound = fence === "bind" ? { accountIdentity: input.accountIdentity, unclaimed: true } : {};
10511
+ return {
10512
+ roster: {
10513
+ ...current,
10514
+ rows: current.rows.map((entry) => entry === row ? { ...entry, ...bound, quota } : entry)
10515
+ },
10516
+ kept: true
10517
+ };
10518
+ }
10519
+ function forgetPendingVaultDiscovery(path2) {
10520
+ pendingDiscoveries.delete(resolve6(path2));
10424
10521
  }
10425
10522
  async function refreshVaultRoster(options) {
10426
10523
  options.signal?.throwIfAborted();
10427
10524
  const active2 = async () => await options.isActive?.() ?? true;
10428
- if (!await active2())
10525
+ if (!await active2()) {
10526
+ forgetPendingVaultDiscovery(options.path);
10429
10527
  return void 0;
10528
+ }
10430
10529
  const lease = await acquireRefreshFileLock({
10431
10530
  ...DISCOVERY_LEASE,
10432
10531
  path: options.path,
@@ -10439,8 +10538,18 @@ async function refreshVaultRoster(options) {
10439
10538
  throw new ClaustrumConsumerError("roster-busy", "Claustrum account discovery is already in progress");
10440
10539
  return persisted;
10441
10540
  }
10541
+ const key = resolve6(options.path);
10542
+ let discovered;
10442
10543
  try {
10443
- const inventory = await options.custody.discover(options.signal);
10544
+ const previous = await readVaultRoster(options.path);
10545
+ const pending = pendingDiscoveries.get(key);
10546
+ discovered = pending && (pending.previousView === previous?.view || pending.inventory.view === previous?.view) ? pending : {
10547
+ inventory: await options.custody.discover(options.signal),
10548
+ previousView: previous?.view
10549
+ };
10550
+ pendingDiscoveries.delete(key);
10551
+ const { inventory } = discovered;
10552
+ options.onInventory?.(inventory);
10444
10553
  options.signal?.throwIfAborted();
10445
10554
  return await mutateVaultRoster(options.path, async (current) => {
10446
10555
  if (!await active2())
@@ -10451,7 +10560,16 @@ async function refreshVaultRoster(options) {
10451
10560
  const next = projectVaultRoster(current, inventory, projection);
10452
10561
  const changed = JSON.stringify(current) !== JSON.stringify(next);
10453
10562
  return { ...changed && { next }, result: next };
10563
+ }, {
10564
+ beforePublish: async () => {
10565
+ options.signal?.throwIfAborted();
10566
+ await lease.assertOwned();
10567
+ }
10454
10568
  });
10569
+ } catch (error) {
10570
+ if (error instanceof LockContentionError && discovered && !options.signal?.aborted && await active2())
10571
+ pendingDiscoveries.set(key, discovered);
10572
+ throw error;
10455
10573
  } finally {
10456
10574
  await lease.release();
10457
10575
  }
@@ -10488,7 +10606,7 @@ function resolveVaultPrimary(input) {
10488
10606
  ...previous && previous.accountIdentity !== identity && { replaced: previous }
10489
10607
  };
10490
10608
  }
10491
- var DEFAULT_ROUTE_PREFIX, SKIPPED_REASONS, WRITE_LOCK, DISCOVERY_LEASE;
10609
+ var DEFAULT_ROUTE_PREFIX, SKIPPED_REASONS, WRITE_LOCK, DISCOVERY_LEASE, pendingDiscoveries;
10492
10610
  var init_roster = __esm({
10493
10611
  "../core/dist/common-auth-embedded/claustrum/roster.js"() {
10494
10612
  "use strict";
@@ -10497,6 +10615,8 @@ var init_roster = __esm({
10497
10615
  init_quota();
10498
10616
  init_errors2();
10499
10617
  init_interlock();
10618
+ init_quota_writer();
10619
+ init_quota_writer();
10500
10620
  DEFAULT_ROUTE_PREFIX = "vault:";
10501
10621
  SKIPPED_REASONS = /* @__PURE__ */ new Set([
10502
10622
  "empty credential id",
@@ -10507,9 +10627,238 @@ var init_roster = __esm({
10507
10627
  WRITE_LOCK = {
10508
10628
  name: "claustrum-roster-write",
10509
10629
  ttlMs: 1e4,
10510
- timeoutMs: 5e3
10630
+ timeoutMs: 5e3,
10631
+ renew: true
10511
10632
  };
10512
10633
  DISCOVERY_LEASE = { name: "claustrum-roster", ttlMs: 3e4 };
10634
+ pendingDiscoveries = /* @__PURE__ */ new Map();
10635
+ }
10636
+ });
10637
+
10638
+ // ../core/dist/common-auth-embedded/claustrum/quota-writer.js
10639
+ import { resolve as resolve7 } from "node:path";
10640
+ function writerFor(path2) {
10641
+ const key = resolve7(path2);
10642
+ let writer = writers.get(key);
10643
+ if (!writer) {
10644
+ writer = {
10645
+ path: key,
10646
+ pending: /* @__PURE__ */ new Map(),
10647
+ listeners: /* @__PURE__ */ new Set(),
10648
+ wake: /* @__PURE__ */ new Set(),
10649
+ abort: new AbortController(),
10650
+ failures: 0,
10651
+ draining: false,
10652
+ order: 0
10653
+ };
10654
+ writers.set(key, writer);
10655
+ }
10656
+ return writer;
10657
+ }
10658
+ function retainVaultQuotaWriter(path2, listener) {
10659
+ const writer = writerFor(path2);
10660
+ writer.listeners.add(listener);
10661
+ let released;
10662
+ return () => released ??= (() => {
10663
+ writer.listeners.delete(listener);
10664
+ return writer.listeners.size ? Promise.resolve() : drainVaultQuota(path2);
10665
+ })();
10666
+ }
10667
+ function fields(publication2) {
10668
+ const result = /* @__PURE__ */ new Map();
10669
+ const { observation } = publication2;
10670
+ const witness = JSON.stringify([
10671
+ publication2.routeId,
10672
+ publication2.receipt?.credentialId,
10673
+ publication2.receipt?.accountIdentitySource,
10674
+ publication2.receipt?.expectedAccountIdentity
10675
+ ]);
10676
+ const add = (key, at, part) => result.set(`${witness}:${key}`, {
10677
+ at,
10678
+ order: 0,
10679
+ publication: { ...publication2, observation: part }
10680
+ });
10681
+ const keyFor = (scope, label) => JSON.stringify([scope ?? "all", label]);
10682
+ const read = /* @__PURE__ */ new Set();
10683
+ for (const reading of observation.readings ?? []) {
10684
+ const key = keyFor(reading.scope, reading.label);
10685
+ read.add(key);
10686
+ add(key, observation.checkedAt, {
10687
+ checkedAt: observation.checkedAt,
10688
+ readings: [{ ...reading }]
10689
+ });
10690
+ }
10691
+ for (const pair of observation.coverage ?? []) {
10692
+ const key = keyFor(pair.scope, pair.label);
10693
+ if (!read.has(key))
10694
+ add(key, observation.checkedAt, {
10695
+ checkedAt: observation.checkedAt,
10696
+ coverage: [{ ...pair }]
10697
+ });
10698
+ }
10699
+ if (observation.budget)
10700
+ add("budget", observation.checkedAt, {
10701
+ checkedAt: observation.checkedAt,
10702
+ budget: { ...observation.budget }
10703
+ });
10704
+ for (const [name, counter] of Object.entries(observation.counters ?? {})) {
10705
+ add(`counter:${name}`, counter.checkedAt, {
10706
+ checkedAt: observation.checkedAt,
10707
+ counters: { [name]: { ...counter } }
10708
+ });
10709
+ }
10710
+ if (observation.credits)
10711
+ add("credits", observation.credits.checkedAt, {
10712
+ checkedAt: observation.checkedAt,
10713
+ credits: { ...observation.credits }
10714
+ });
10715
+ if (!result.size)
10716
+ add("empty", observation.checkedAt, { checkedAt: observation.checkedAt });
10717
+ return result;
10718
+ }
10719
+ function enqueueVaultQuota(path2, publication2) {
10720
+ if (!isQuotaObservation(publication2.observation))
10721
+ return Promise.resolve(false);
10722
+ const writer = writerFor(path2);
10723
+ const account = JSON.stringify([
10724
+ publication2.accountIdentity ?? null,
10725
+ publication2.accountIdentity === void 0 ? publication2.routeId : null
10726
+ ]);
10727
+ const pending = writer.pending.get(account) ?? /* @__PURE__ */ new Map();
10728
+ for (const [key, field] of fields(publication2)) {
10729
+ const previous = pending.get(key);
10730
+ if (!previous || field.at >= previous.at) {
10731
+ field.order = ++writer.order;
10732
+ if (field.publication.observation.coverage)
10733
+ field.priorReading = previous?.publication.observation.readings ? previous.publication : previous?.priorReading;
10734
+ pending.set(key, field);
10735
+ }
10736
+ }
10737
+ if (pending.size)
10738
+ writer.pending.set(account, pending);
10739
+ for (const listener of writer.listeners)
10740
+ listener(publication2);
10741
+ schedule(writer, COALESCE_MS);
10742
+ return Promise.resolve(true);
10743
+ }
10744
+ function orderedFields(pending) {
10745
+ return [...pending.values()].flatMap((account) => [...account.values()]).sort((a, b) => a.order - b.order);
10746
+ }
10747
+ function pendingVaultQuota(path2, roster) {
10748
+ const writer = writers.get(resolve7(path2));
10749
+ if (writer) {
10750
+ for (const field of orderedFields(writer.pending)) {
10751
+ if (field.priorReading)
10752
+ roster = applyVaultQuota(roster, field.priorReading).roster;
10753
+ roster = applyVaultQuota(roster, field.publication).roster;
10754
+ }
10755
+ }
10756
+ return roster;
10757
+ }
10758
+ function schedule(writer, delay3) {
10759
+ if (writer.running || writer.timer || !writer.pending.size || writer.abort.signal.aborted)
10760
+ return;
10761
+ writer.timer = setTimeout(() => {
10762
+ writer.timer = void 0;
10763
+ flush(writer);
10764
+ }, delay3);
10765
+ if (!writer.draining)
10766
+ writer.timer.unref?.();
10767
+ }
10768
+ function flush(writer) {
10769
+ if (writer.running || writer.abort.signal.aborted)
10770
+ return;
10771
+ const batch = new Map([...writer.pending].map(([account, pending]) => [
10772
+ account,
10773
+ new Map(pending)
10774
+ ]));
10775
+ writer.running = (async () => {
10776
+ try {
10777
+ await mutateVaultRoster(writer.path, (current) => {
10778
+ let next = current;
10779
+ for (const field of orderedFields(batch)) {
10780
+ if (field.priorReading)
10781
+ next = applyVaultQuota(next, field.priorReading).roster;
10782
+ next = applyVaultQuota(next, field.publication).roster;
10783
+ }
10784
+ return { ...next !== current && { next }, result: void 0 };
10785
+ }, { signal: writer.abort.signal });
10786
+ for (const [account, fields2] of batch) {
10787
+ const pending = writer.pending.get(account);
10788
+ for (const [key, field] of fields2) {
10789
+ if (pending?.get(key) === field)
10790
+ pending.delete(key);
10791
+ }
10792
+ if (!pending?.size)
10793
+ writer.pending.delete(account);
10794
+ }
10795
+ writer.failures = 0;
10796
+ } catch (error) {
10797
+ if (!writer.abort.signal.aborted && writer.failures++ === 0) {
10798
+ logger.warn("vault quota publication delayed; retrying", {
10799
+ error: error instanceof Error ? error.message : String(error)
10800
+ });
10801
+ }
10802
+ } finally {
10803
+ writer.running = void 0;
10804
+ for (const wake of writer.wake)
10805
+ wake();
10806
+ const backoff = writer.failures ? Math.min(5e3, 100 * 2 ** Math.min(writer.failures, 6)) * (0.5 + Math.random()) : COALESCE_MS;
10807
+ schedule(writer, backoff);
10808
+ }
10809
+ })();
10810
+ }
10811
+ async function drainVaultQuota(path2, timeoutMs = 1e3) {
10812
+ const key = resolve7(path2);
10813
+ const writer = writers.get(key);
10814
+ if (!writer)
10815
+ return;
10816
+ writer.draining = true;
10817
+ clearTimeout(writer.timer);
10818
+ writer.timer = void 0;
10819
+ let deadline;
10820
+ let wake;
10821
+ const drained = new Promise((done) => {
10822
+ wake = () => {
10823
+ if (!writer.pending.size || writer.abort.signal.aborted)
10824
+ done();
10825
+ };
10826
+ writer.wake.add(wake);
10827
+ wake();
10828
+ });
10829
+ try {
10830
+ if (writer.pending.size)
10831
+ flush(writer);
10832
+ await Promise.race([
10833
+ drained,
10834
+ new Promise((done) => {
10835
+ deadline = setTimeout(done, Math.max(0, timeoutMs));
10836
+ })
10837
+ ]);
10838
+ } finally {
10839
+ clearTimeout(deadline);
10840
+ if (wake)
10841
+ writer.wake.delete(wake);
10842
+ writer.draining = false;
10843
+ if (!writer.listeners.size) {
10844
+ writer.abort.abort();
10845
+ clearTimeout(writer.timer);
10846
+ writer.pending.clear();
10847
+ if (writers.get(key) === writer)
10848
+ writers.delete(key);
10849
+ }
10850
+ }
10851
+ }
10852
+ var writers, logger, COALESCE_MS;
10853
+ var init_quota_writer = __esm({
10854
+ "../core/dist/common-auth-embedded/claustrum/quota-writer.js"() {
10855
+ "use strict";
10856
+ init_logger();
10857
+ init_quota();
10858
+ init_roster();
10859
+ writers = /* @__PURE__ */ new Map();
10860
+ logger = createLogger2("claustrum");
10861
+ COALESCE_MS = 100;
10513
10862
  }
10514
10863
  });
10515
10864
 
@@ -10524,6 +10873,7 @@ var init_consumer = __esm({
10524
10873
  init_enrollment();
10525
10874
  init_errors2();
10526
10875
  init_insula();
10876
+ init_quota_writer();
10527
10877
  init_roster();
10528
10878
  init_watch();
10529
10879
  ClaustrumConsumer = class {
@@ -10547,9 +10897,13 @@ var init_consumer = __esm({
10547
10897
  #insulaSkips = /* @__PURE__ */ new Map();
10548
10898
  /** When this instance last completed a discovery, by `now`. */
10549
10899
  #discoveredAt;
10900
+ #releaseQuotaWriter;
10550
10901
  constructor(options) {
10551
10902
  this.#options = options;
10552
10903
  this.#logger = options.logger ?? createLogger2("claustrum");
10904
+ this.#releaseQuotaWriter = retainVaultQuotaWriter(options.rosterPath, (publication2) => {
10905
+ this.#roster = applyVaultQuota(this.#roster, publication2).roster;
10906
+ });
10553
10907
  }
10554
10908
  #assertOpen(signal) {
10555
10909
  this.#shutdown.signal.throwIfAborted();
@@ -10563,7 +10917,7 @@ var init_consumer = __esm({
10563
10917
  this.#shutdown.signal,
10564
10918
  ...signal ? [signal] : []
10565
10919
  ]);
10566
- return new Promise((resolve13, reject) => {
10920
+ return new Promise((resolve15, reject) => {
10567
10921
  const cleanup2 = () => {
10568
10922
  combined.signal.removeEventListener("abort", abort);
10569
10923
  combined.dispose();
@@ -10578,7 +10932,7 @@ var init_consumer = __esm({
10578
10932
  if (combined.signal.aborted)
10579
10933
  reject(combined.signal.reason);
10580
10934
  else
10581
- resolve13(value);
10935
+ resolve15(value);
10582
10936
  }, (error) => {
10583
10937
  cleanup2();
10584
10938
  reject(error);
@@ -10678,11 +11032,9 @@ var init_consumer = __esm({
10678
11032
  let discovered;
10679
11033
  const roster = await refreshVaultRoster({
10680
11034
  path: this.#options.rosterPath,
10681
- custody: {
10682
- discover: async (signal) => {
10683
- discovered = await custody.discover(signal);
10684
- return discovered;
10685
- }
11035
+ custody,
11036
+ onInventory: (inventory) => {
11037
+ discovered = inventory;
10686
11038
  },
10687
11039
  isActive: () => this.#active(),
10688
11040
  signal: this.#shutdown.signal,
@@ -10695,7 +11047,7 @@ var init_consumer = __esm({
10695
11047
  });
10696
11048
  this.#assertOpen();
10697
11049
  const changed = roster?.view !== this.#roster?.view;
10698
- this.#roster = roster;
11050
+ this.#roster = pendingVaultQuota(this.#options.rosterPath, roster);
10699
11051
  custody.retain(roster?.rows ?? []);
10700
11052
  if (discovered && roster?.view !== void 0)
10701
11053
  this.#grantReach = discovered.grantReach ? { view: roster.view, reach: discovered.grantReach } : void 0;
@@ -10831,7 +11183,7 @@ var init_consumer = __esm({
10831
11183
  return void 0;
10832
11184
  try {
10833
11185
  await readClaustrumEnrollmentToken(this.#options.tokenPath);
10834
- const roster = await readVaultRoster(this.#options.rosterPath);
11186
+ const roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
10835
11187
  const row = roster?.rows.find((entry) => entry.routeId === routeId);
10836
11188
  return this.#normalizeInsulaQuota(row?.accountIdentity);
10837
11189
  } catch {
@@ -10845,7 +11197,7 @@ var init_consumer = __esm({
10845
11197
  return { miss: "unreachable" };
10846
11198
  try {
10847
11199
  await readClaustrumEnrollmentToken(this.#options.tokenPath);
10848
- const roster = await readVaultRoster(this.#options.rosterPath);
11200
+ const roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
10849
11201
  const account = roster?.rows.find((row) => row.routeId === routeId)?.accountIdentity;
10850
11202
  if (!account || !this.#insula)
10851
11203
  return { miss: "unreachable" };
@@ -10895,7 +11247,7 @@ var init_consumer = __esm({
10895
11247
  this.#insula = void 0;
10896
11248
  throw new ClaustrumConsumerError("not-active", "Claustrum scoped custody is not active");
10897
11249
  }
10898
- const current = await readVaultRoster(this.#options.rosterPath);
11250
+ const current = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
10899
11251
  this.#assertOpen(signal);
10900
11252
  const observed = roster.rows.find((row) => row.routeId === routeId);
10901
11253
  const configured = current?.rows.find((row) => row.routeId === routeId);
@@ -10974,13 +11326,13 @@ var init_consumer = __esm({
10974
11326
  async decline(routeId) {
10975
11327
  this.#assertOpen();
10976
11328
  await declineVaultRoute(this.#options.rosterPath, routeId);
10977
- this.#roster = await readVaultRoster(this.#options.rosterPath);
11329
+ this.#roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
10978
11330
  this.#custody?.retain(this.#roster?.rows ?? []);
10979
11331
  }
10980
11332
  async accept(routeId) {
10981
11333
  this.#assertOpen();
10982
11334
  await acceptVaultRoute(this.#options.rosterPath, routeId);
10983
- this.#roster = await readVaultRoster(this.#options.rosterPath);
11335
+ this.#roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
10984
11336
  }
10985
11337
  /**
10986
11338
  * Store a quota or profile observation for a vault route. The receipt the
@@ -10990,7 +11342,7 @@ var init_consumer = __esm({
10990
11342
  */
10991
11343
  async recordQuota(routeId, observation, attempt) {
10992
11344
  this.#assertOpen();
10993
- const kept = await recordVaultQuota(this.#options.rosterPath, {
11345
+ return recordVaultQuota(this.#options.rosterPath, {
10994
11346
  routeId,
10995
11347
  observation,
10996
11348
  credentialId: attempt.credentialId,
@@ -11002,27 +11354,21 @@ var init_consumer = __esm({
11002
11354
  expectedAccountIdentity: attempt.expectedAccountIdentity
11003
11355
  }
11004
11356
  });
11005
- if (kept)
11006
- this.#roster = await readVaultRoster(this.#options.rosterPath);
11007
- return kept;
11008
11357
  }
11009
11358
  /**
11010
11359
  * Store a background observation that belongs to an account rather than to
11011
11360
  * a served credential (an insula reading from `cachedInsulaQuotaForRoute`).
11012
11361
  * It lands only while the route is still bound to that known account, so no
11013
11362
  * credential fetch is needed and a replaced account's reading is dropped.
11014
- * The in-memory roster is reloaded from the file, without a vault call.
11363
+ * Memory updates immediately; durable publication is detached and coalesced.
11015
11364
  */
11016
11365
  async recordAccountQuota(routeId, accountIdentity, observation) {
11017
11366
  this.#assertOpen();
11018
- const kept = await recordVaultAccountQuota(this.#options.rosterPath, {
11367
+ return recordVaultAccountQuota(this.#options.rosterPath, {
11019
11368
  routeId,
11020
11369
  accountIdentity,
11021
11370
  observation
11022
11371
  });
11023
- if (kept)
11024
- this.#roster = await readVaultRoster(this.#options.rosterPath);
11025
- return kept;
11026
11372
  }
11027
11373
  close() {
11028
11374
  if (this.#shutdown.signal.aborted)
@@ -11037,6 +11383,13 @@ var init_consumer = __esm({
11037
11383
  this.#insula = void 0;
11038
11384
  this.#roster = void 0;
11039
11385
  this.#grantReach = void 0;
11386
+ void this.#releaseQuotaWriter();
11387
+ forgetPendingVaultDiscovery(this.#options.rosterPath);
11388
+ }
11389
+ /** Close immediately; the last consumer also waits for the writer's bounded drain. */
11390
+ async dispose() {
11391
+ this.close();
11392
+ await this.#releaseQuotaWriter();
11040
11393
  }
11041
11394
  };
11042
11395
  }
@@ -11079,6 +11432,7 @@ __export(claustrum_exports, {
11079
11432
  declineAccount: () => declineAccount,
11080
11433
  declineVaultRoute: () => declineVaultRoute,
11081
11434
  disconnectClaustrumEnrollment: () => disconnectClaustrumEnrollment,
11435
+ drainVaultQuota: () => drainVaultQuota,
11082
11436
  enrollmentAuthority: () => enrollmentAuthority,
11083
11437
  enrollmentName: () => enrollmentName,
11084
11438
  getClaustrumEnrollmentPaths: () => getClaustrumEnrollmentPaths,
@@ -11117,6 +11471,7 @@ var init_claustrum = __esm({
11117
11471
  init_host_slot();
11118
11472
  init_insula();
11119
11473
  init_interlock();
11474
+ init_quota_writer();
11120
11475
  init_roster();
11121
11476
  init_watch();
11122
11477
  }
@@ -11197,7 +11552,7 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
11197
11552
  if (!released && lastUpdate + RENEWAL_STALE < Date.now())
11198
11553
  compromise();
11199
11554
  }
11200
- function schedule(delay3 = UPDATE) {
11555
+ function schedule2(delay3 = UPDATE) {
11201
11556
  if (released)
11202
11557
  return;
11203
11558
  timer = setTimeout(() => {
@@ -11211,7 +11566,7 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
11211
11566
  if (errorCode(error) === "ENOENT" || lastUpdate + RENEWAL_STALE < Date.now())
11212
11567
  compromise();
11213
11568
  else
11214
- schedule(1e3);
11569
+ schedule2(1e3);
11215
11570
  }
11216
11571
  async function update() {
11217
11572
  assertFresh();
@@ -11244,14 +11599,14 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
11244
11599
  mtime = next.getTime();
11245
11600
  lastUpdate = Date.now();
11246
11601
  active.set(path2, { ...identity, mtime, renewedAt: lastUpdate });
11247
- schedule();
11602
+ schedule2();
11248
11603
  }
11249
11604
  onRenew?.(async () => {
11250
11605
  if (timer)
11251
11606
  clearTimeout(timer);
11252
11607
  await update();
11253
11608
  });
11254
- schedule();
11609
+ schedule2();
11255
11610
  return {
11256
11611
  assertFresh,
11257
11612
  async release() {
@@ -11310,7 +11665,7 @@ var init_lock = __esm({
11310
11665
  import { createHash as createHash7 } from "node:crypto";
11311
11666
  import { constants as constants2 } from "node:fs";
11312
11667
  import { lstat as lstat3, mkdir as mkdir10, open as open7, unlink as unlink7 } from "node:fs/promises";
11313
- import { dirname as dirname10, resolve as resolve6 } from "node:path";
11668
+ import { dirname as dirname10, resolve as resolve8 } from "node:path";
11314
11669
  import { setTimeout as sleep2 } from "node:timers/promises";
11315
11670
  function rootSpans(text2) {
11316
11671
  let i = text2.indexOf("{") + 1;
@@ -11511,8 +11866,8 @@ function createPiSlot(options, onStep, hooks) {
11511
11866
  if (!provider2 || !options.authPath || !options.stashPath || !placeholderKey || placeholderKey.startsWith("!") || placeholderKey.includes("$") || !Number.isFinite(timeout) || timeout < 0) {
11512
11867
  throw new PiSlotError("invalid-options");
11513
11868
  }
11514
- const authPath = resolve6(options.authPath);
11515
- const stashPath = resolve6(options.stashPath);
11869
+ const authPath = resolve8(options.authPath);
11870
+ const stashPath = resolve8(options.stashPath);
11516
11871
  if (authPath === stashPath || stashPath === `${authPath}.lock`) {
11517
11872
  throw new PiSlotError("invalid-options");
11518
11873
  }
@@ -11682,7 +12037,7 @@ var init_pi_slot = __esm({
11682
12037
  // src/cli.ts
11683
12038
  import { execFile } from "node:child_process";
11684
12039
  import { realpathSync as realpathSync2 } from "node:fs";
11685
- import { resolve as resolve12 } from "node:path";
12040
+ import { resolve as resolve14 } from "node:path";
11686
12041
  import { createInterface } from "node:readline/promises";
11687
12042
  import { fileURLToPath as fileURLToPath2 } from "node:url";
11688
12043
  import { promisify } from "node:util";
@@ -16524,7 +16879,7 @@ async function rmEvictingDir(evictingPath) {
16524
16879
  });
16525
16880
  }
16526
16881
  async function sleep(ms) {
16527
- await new Promise((resolve13) => setTimeout(resolve13, ms));
16882
+ await new Promise((resolve15) => setTimeout(resolve15, ms));
16528
16883
  }
16529
16884
  async function acquireFencedFileLock(options) {
16530
16885
  const lockPath = `${options.path}.${options.name}.lock`;
@@ -16640,8 +16995,8 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
16640
16995
  let released = false;
16641
16996
  let lost = false;
16642
16997
  let lostResolve = null;
16643
- let lostPromise = new Promise((resolve13) => {
16644
- lostResolve = resolve13;
16998
+ let lostPromise = new Promise((resolve15) => {
16999
+ lostResolve = resolve15;
16645
17000
  });
16646
17001
  const markLost = () => {
16647
17002
  if (lost)
@@ -16651,9 +17006,9 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
16651
17006
  clearInterval(renewTimer);
16652
17007
  renewTimer = null;
16653
17008
  }
16654
- const resolve13 = lostResolve;
17009
+ const resolve15 = lostResolve;
16655
17010
  lostResolve = null;
16656
- resolve13?.();
17011
+ resolve15?.();
16657
17012
  };
16658
17013
  const setupRenew = () => {
16659
17014
  if (options.renew === false)
@@ -16877,7 +17232,7 @@ var AccountStorageUnreadableError = class extends Error {
16877
17232
  }
16878
17233
  };
16879
17234
  var RETRY_DELAYS_MS = [100, 200, 400, 800, 1e3];
16880
- var DEFAULT_SLEEP = (ms) => new Promise((resolve13) => setTimeout(resolve13, ms));
17235
+ var DEFAULT_SLEEP = (ms) => new Promise((resolve15) => setTimeout(resolve15, ms));
16881
17236
  var DEFAULT_BUILD_BACKUP_PATH = (path2, now) => `${path2}.corrupt-${now.toISOString().replace(/[:.]/g, "-")}`;
16882
17237
  async function ensureSecurePermissions(path2) {
16883
17238
  try {
@@ -17388,7 +17743,7 @@ function getHttpsProxy(url) {
17388
17743
  }
17389
17744
  }
17390
17745
  function waitForHead(socket, timeoutMs, onTimeout) {
17391
- return new Promise((resolve13, reject) => {
17746
+ return new Promise((resolve15, reject) => {
17392
17747
  let buffer = Buffer2.alloc(0);
17393
17748
  const timeout = setTimeout(() => {
17394
17749
  onTimeout();
@@ -17411,7 +17766,7 @@ function waitForHead(socket, timeoutMs, onTimeout) {
17411
17766
  return;
17412
17767
  const head = buffer.subarray(0, marker).toString("latin1");
17413
17768
  const leftover = buffer.subarray(marker + 4);
17414
- cleanup2(() => resolve13({ head, leftover }));
17769
+ cleanup2(() => resolve15({ head, leftover }));
17415
17770
  };
17416
17771
  socket.on("data", onData);
17417
17772
  socket.once("error", onError);
@@ -17425,7 +17780,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
17425
17780
  port: Number(proxyUrl.port || DEFAULT_PROXY_PORT),
17426
17781
  signal: signal ?? void 0
17427
17782
  });
17428
- await new Promise((resolve13, reject) => {
17783
+ await new Promise((resolve15, reject) => {
17429
17784
  const timeout = setTimeout(() => {
17430
17785
  onDebug?.(`agy transport proxy connect timeout after ${timeoutMs}ms`);
17431
17786
  proxySocket.destroy();
@@ -17434,7 +17789,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
17434
17789
  const cleanup2 = () => clearTimeout(timeout);
17435
17790
  proxySocket.once("connect", () => {
17436
17791
  cleanup2();
17437
- resolve13();
17792
+ resolve15();
17438
17793
  });
17439
17794
  proxySocket.once("error", (error) => {
17440
17795
  cleanup2();
@@ -17459,7 +17814,7 @@ Host: ${targetHost}:${targetPort}\r
17459
17814
  if (leftover.length > 0) {
17460
17815
  proxySocket.unshift(leftover);
17461
17816
  }
17462
- return await new Promise((resolve13, reject) => {
17817
+ return await new Promise((resolve15, reject) => {
17463
17818
  const tlsOptions = {
17464
17819
  socket: proxySocket,
17465
17820
  servername: targetHost,
@@ -17474,7 +17829,7 @@ Host: ${targetHost}:${targetPort}\r
17474
17829
  const cleanup2 = () => clearTimeout(timeout);
17475
17830
  tlsSocket.once("secureConnect", () => {
17476
17831
  cleanup2();
17477
- resolve13(tlsSocket);
17832
+ resolve15(tlsSocket);
17478
17833
  });
17479
17834
  tlsSocket.once("error", (error) => {
17480
17835
  cleanup2();
@@ -17483,7 +17838,7 @@ Host: ${targetHost}:${targetPort}\r
17483
17838
  });
17484
17839
  }
17485
17840
  async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
17486
- return await new Promise((resolve13, reject) => {
17841
+ return await new Promise((resolve15, reject) => {
17487
17842
  const tlsOptions = {
17488
17843
  host: targetUrl.hostname,
17489
17844
  port: Number(targetUrl.port || DEFAULT_HTTPS_PORT),
@@ -17499,7 +17854,7 @@ async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
17499
17854
  const cleanup2 = () => clearTimeout(timeout);
17500
17855
  socket.once("secureConnect", () => {
17501
17856
  cleanup2();
17502
- resolve13(socket);
17857
+ resolve15(socket);
17503
17858
  });
17504
17859
  socket.once("error", (error) => {
17505
17860
  cleanup2();
@@ -18137,15 +18492,15 @@ function maskSensitiveIdentifier(value) {
18137
18492
 
18138
18493
  // ../core/dist/pi-paths.js
18139
18494
  import { homedir } from "node:os";
18140
- import { dirname as dirname11, join as join6 } from "node:path";
18495
+ import { dirname as dirname11, join as join7 } from "node:path";
18141
18496
  function getPiConfigDir() {
18142
- return process.env.PI_AGENT_DIR?.trim() || join6(homedir(), ".pi", "agent");
18497
+ return process.env.PI_AGENT_DIR?.trim() || join7(homedir(), ".pi", "agent");
18143
18498
  }
18144
18499
  function getPiAntigravityAuthFile() {
18145
- return process.env.PI_ANTIGRAVITY_AUTH_FILE?.trim() || join6(getPiConfigDir(), "antigravity-accounts.json");
18500
+ return process.env.PI_ANTIGRAVITY_AUTH_FILE?.trim() || join7(getPiConfigDir(), "antigravity-accounts.json");
18146
18501
  }
18147
18502
  function getPiAntigravityVaultDir() {
18148
- return join6(dirname11(getPiAntigravityAuthFile()), "antigravity-auth-vault");
18503
+ return join7(dirname11(getPiAntigravityAuthFile()), "antigravity-auth-vault");
18149
18504
  }
18150
18505
 
18151
18506
  // ../core/dist/project.js
@@ -18172,8 +18527,8 @@ function getDefaultTierId(allowedTiers) {
18172
18527
  return allowedTiers[0]?.id;
18173
18528
  }
18174
18529
  function wait(ms) {
18175
- return new Promise((resolve13) => {
18176
- setTimeout(resolve13, ms);
18530
+ return new Promise((resolve15) => {
18531
+ setTimeout(resolve15, ms);
18177
18532
  });
18178
18533
  }
18179
18534
  function extractManagedProjectId(payload) {
@@ -18729,11 +19084,16 @@ function mostConstrainedWindow(windows) {
18729
19084
  };
18730
19085
  }
18731
19086
  function poolForBucketId(bucketId) {
18732
- if (bucketId.startsWith("gemini-"))
18733
- return "gemini";
18734
- if (bucketId.startsWith("3p-"))
18735
- return "non-gemini";
18736
- return null;
19087
+ switch (bucketId) {
19088
+ case "gemini-5h":
19089
+ case "gemini-weekly":
19090
+ return "gemini";
19091
+ case "3p-5h":
19092
+ case "3p-weekly":
19093
+ return "non-gemini";
19094
+ default:
19095
+ return null;
19096
+ }
18737
19097
  }
18738
19098
  function parseDescriptionModelCount(description) {
18739
19099
  const prefixMatch = description.match(/^[^:]+:\s*/);
@@ -18754,31 +19114,60 @@ function windowDurationMs(window) {
18754
19114
  }
18755
19115
  }
18756
19116
  function aggregateQuotaSummary(response) {
18757
- const groups = {};
18758
- let totalCount = 0;
19117
+ const windowsByPool = {
19118
+ gemini: /* @__PURE__ */ new Map(),
19119
+ "non-gemini": /* @__PURE__ */ new Map()
19120
+ };
19121
+ const modelCounts = {
19122
+ gemini: 0,
19123
+ "non-gemini": 0
19124
+ };
19125
+ const seenBucketIds = /* @__PURE__ */ new Set();
19126
+ const duplicateBucketIds = /* @__PURE__ */ new Set();
18759
19127
  for (const group of response.groups) {
18760
- const windows = [];
19128
+ const contributingPools = /* @__PURE__ */ new Set();
18761
19129
  for (const bucket of group.buckets) {
18762
- const pool2 = poolForBucketId(bucket.bucketId);
18763
- if (!pool2)
19130
+ if (bucket.disabled === true)
19131
+ continue;
19132
+ const pool = poolForBucketId(bucket.bucketId);
19133
+ if (!pool)
18764
19134
  continue;
18765
- windows.push({
19135
+ contributingPools.add(pool);
19136
+ const window = {
18766
19137
  window: bucket.window,
18767
19138
  remainingFraction: normalizeRemainingFraction(bucket.remainingFraction),
18768
19139
  resetTime: bucket.resetTime
18769
- });
19140
+ };
19141
+ const previous = windowsByPool[pool].get(bucket.bucketId);
19142
+ if (seenBucketIds.has(bucket.bucketId)) {
19143
+ duplicateBucketIds.add(bucket.bucketId);
19144
+ } else {
19145
+ seenBucketIds.add(bucket.bucketId);
19146
+ }
19147
+ if (!previous || window.remainingFraction < previous.remainingFraction) {
19148
+ windowsByPool[pool].set(bucket.bucketId, window);
19149
+ }
18770
19150
  }
19151
+ const modelCount = group.description ? parseDescriptionModelCount(group.description) : 0;
19152
+ for (const pool of contributingPools)
19153
+ modelCounts[pool] += modelCount;
19154
+ }
19155
+ if (duplicateBucketIds.size > 0) {
19156
+ log4.debug("duplicate quota summary bucket ids", {
19157
+ bucketIds: [...duplicateBucketIds].sort()
19158
+ });
19159
+ }
19160
+ const groups = {};
19161
+ let totalCount = 0;
19162
+ for (const pool of ["gemini", "non-gemini"]) {
19163
+ const windows = [...windowsByPool[pool].values()];
18771
19164
  if (windows.length === 0)
18772
19165
  continue;
18773
19166
  windows.sort((a, b) => windowDurationMs(a.window) - windowDurationMs(b.window));
18774
19167
  const constrained = mostConstrainedWindow(windows);
18775
- const recognizedBucket = group.buckets.find((bucket) => poolForBucketId(bucket.bucketId));
18776
- if (!recognizedBucket)
18777
- continue;
18778
- const pool = poolForBucketId(recognizedBucket.bucketId);
18779
- if (!pool || !constrained)
19168
+ if (!constrained)
18780
19169
  continue;
18781
- const modelCount = group.description ? parseDescriptionModelCount(group.description) : 0;
19170
+ const modelCount = modelCounts[pool];
18782
19171
  groups[pool] = {
18783
19172
  remainingFraction: constrained.remainingFraction,
18784
19173
  resetTime: constrained.resetTime,
@@ -19014,17 +19403,18 @@ import {
19014
19403
  writeFileSync
19015
19404
  } from "node:fs";
19016
19405
  import { homedir as homedir3 } from "node:os";
19017
- import { dirname as dirname14, join as join8, resolve as resolve9 } from "node:path";
19406
+ import { dirname as dirname14, join as join10, resolve as resolve11 } from "node:path";
19018
19407
 
19019
19408
  // src/common-auth-embedded/logger/engine.js
19020
19409
  import { appendFileSync as appendFileSync2, chmodSync as chmodSync2, existsSync as existsSync2, renameSync as renameSync2, statSync as statSync3 } from "node:fs";
19021
19410
  import { open as open8 } from "node:fs/promises";
19022
- import { dirname as dirname13, resolve as resolve8 } from "node:path";
19411
+ import { dirname as dirname13, resolve as resolve10 } from "node:path";
19023
19412
 
19024
19413
  // src/common-auth-embedded/fs/private-files.js
19025
19414
  import { randomUUID as randomUUID11 } from "node:crypto";
19026
19415
  import { lstat as lstat4, readFile as readFile7, rename as rename7, unlink as unlink8 } from "node:fs/promises";
19027
- import { dirname as dirname12, resolve as resolve7 } from "node:path";
19416
+ import { tmpdir as tmpdir2 } from "node:os";
19417
+ import { dirname as dirname12, join as join8, resolve as resolve9 } from "node:path";
19028
19418
  var windowsPrivateFiles2 = process.platform === "win32";
19029
19419
  var migrationNotices2 = /* @__PURE__ */ new Set();
19030
19420
  function ioCode2(detail) {
@@ -19037,8 +19427,32 @@ function ioCode2(detail) {
19037
19427
  return detail?.code ?? "ERR_PRIVATE_FILE";
19038
19428
  }
19039
19429
  var backend2;
19430
+ var PRIVATE_FILES_UNAVAILABLE_REASON2 = "native-addon-unavailable";
19431
+ function privateFilesUnavailable2(cause) {
19432
+ return Object.assign(new Error("Windows private-files native addon is unavailable", { cause }), {
19433
+ code: "ERR_PRIVATE_FILES_UNAVAILABLE",
19434
+ reason: PRIVATE_FILES_UNAVAILABLE_REASON2
19435
+ });
19436
+ }
19437
+ function isUnavailable2(api, error) {
19438
+ return error instanceof api.PrivateFilesUnavailableError || error?.code === "ERR_PRIVATE_FILES_UNAVAILABLE";
19439
+ }
19440
+ async function assertNativeAddonLoads2(api) {
19441
+ try {
19442
+ await api.verifyPrivatePath(join8(tmpdir2(), `.common-auth-private-files-probe-${randomUUID11()}`), "file");
19443
+ } catch (error) {
19444
+ if (isUnavailable2(api, error))
19445
+ throw privateFilesUnavailable2(error);
19446
+ }
19447
+ }
19040
19448
  function loadBackend2() {
19041
- backend2 ??= import("@cortexkit/private-files");
19449
+ backend2 ??= import("@cortexkit/private-files").then(async (api) => {
19450
+ if (windowsPrivateFiles2)
19451
+ await assertNativeAddonLoads2(api);
19452
+ return api;
19453
+ }, (cause) => {
19454
+ throw windowsPrivateFiles2 ? privateFilesUnavailable2(cause) : cause;
19455
+ });
19042
19456
  return backend2;
19043
19457
  }
19044
19458
  var PrivateFileError2 = class extends Error {
@@ -19055,7 +19469,7 @@ var PrivateFileError2 = class extends Error {
19055
19469
  orphanPath;
19056
19470
  constructor(path2, stage, cause) {
19057
19471
  const detail = cause;
19058
- super(`Private file refused at ${stage}: ${path2} (${detail?.reason ?? detail?.code ?? "io-error"}). Use a safe parent directory. Repair only a named secret file in safe ancestry whose owner the published policy trusts, without changing its owner or any existing directory. Previously exposed credentials may need rotation. Windows requires the private-files native prebuild and an ACL-persisting local filesystem such as NTFS.`, { cause });
19472
+ super(detail?.code === "ERR_PRIVATE_FILES_UNAVAILABLE" ? `Private file refused at ${stage}: ${path2} (${PRIVATE_FILES_UNAVAILABLE_REASON2}). The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.` : `Private file refused at ${stage}: ${path2} (${detail?.reason ?? detail?.code ?? "io-error"}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
19059
19473
  this.path = path2;
19060
19474
  this.stage = stage;
19061
19475
  this.name = "PrivateFileError";
@@ -19075,7 +19489,7 @@ async function privateOperation2(path2, stage, operation) {
19075
19489
  }
19076
19490
  var safeParentOptionsForTest2;
19077
19491
  async function verifySafeDirectory2(path2, options) {
19078
- path2 = resolve7(path2);
19492
+ path2 = resolve9(path2);
19079
19493
  options ??= safeParentOptionsForTest2;
19080
19494
  await privateOperation2(path2, "safe-parent", async () => {
19081
19495
  const result = await (await loadBackend2()).verifySafeParent(path2, options);
@@ -19090,7 +19504,7 @@ async function verifySafeDirectory2(path2, options) {
19090
19504
  });
19091
19505
  }
19092
19506
  async function verifyPrivate2(path2, kind, migrate = false) {
19093
- path2 = resolve7(path2);
19507
+ path2 = resolve9(path2);
19094
19508
  if (kind === "directory")
19095
19509
  return verifySafeDirectory2(path2);
19096
19510
  await privateOperation2(path2, "verify", async () => {
@@ -19125,7 +19539,7 @@ async function verifyPrivate2(path2, kind, migrate = false) {
19125
19539
  });
19126
19540
  }
19127
19541
  async function ensurePrivateDirectory3(path2, _migrate = false, options) {
19128
- path2 = resolve7(path2);
19542
+ path2 = resolve9(path2);
19129
19543
  await privateOperation2(path2, "directory", async () => {
19130
19544
  const api = await loadBackend2();
19131
19545
  try {
@@ -19156,7 +19570,7 @@ async function readPrivateText2(path2, migrate = false) {
19156
19570
  async function readPrivateBuffer2(path2, migrate = false) {
19157
19571
  if (!windowsPrivateFiles2)
19158
19572
  return readFile7(path2);
19159
- path2 = resolve7(path2);
19573
+ path2 = resolve9(path2);
19160
19574
  if (migrate) {
19161
19575
  await verifySafeDirectory2(dirname12(path2));
19162
19576
  await verifyPrivate2(path2, "file", true);
@@ -19164,20 +19578,20 @@ async function readPrivateBuffer2(path2, migrate = false) {
19164
19578
  return privateOperation2(path2, "read", async () => (await loadBackend2()).readOwnerOnly(path2));
19165
19579
  }
19166
19580
  async function createPrivateBytes2(path2, bytes) {
19167
- await verifySafeDirectory2(dirname12(resolve7(path2)));
19581
+ await verifySafeDirectory2(dirname12(resolve9(path2)));
19168
19582
  await privateOperation2(path2, "create", async () => {
19169
- await (await loadBackend2()).createPrivateFile(resolve7(path2), bytes);
19583
+ await (await loadBackend2()).createPrivateFile(resolve9(path2), bytes);
19170
19584
  });
19171
19585
  }
19172
19586
  async function createPrivateDirectoryExclusive2(path2) {
19173
- await verifySafeDirectory2(dirname12(resolve7(path2)));
19587
+ await verifySafeDirectory2(dirname12(resolve9(path2)));
19174
19588
  await privateOperation2(path2, "directory-create", async () => {
19175
- await (await loadBackend2()).createOwnerOnly(resolve7(path2), { kind: "dir" });
19589
+ await (await loadBackend2()).createOwnerOnly(resolve9(path2), { kind: "dir" });
19176
19590
  });
19177
19591
  }
19178
19592
  async function replaceWindowsFile2(from, to, options = {}) {
19179
- from = resolve7(from);
19180
- to = resolve7(to);
19593
+ from = resolve9(from);
19594
+ to = resolve9(to);
19181
19595
  const now = options.now ?? (() => performance.now());
19182
19596
  const start = now();
19183
19597
  const leaseDeadline = options.deadline ?? Infinity;
@@ -19220,7 +19634,7 @@ async function replaceWindowsFile2(from, to, options = {}) {
19220
19634
  throw error;
19221
19635
  }
19222
19636
  async function writePrivateAtomic2(path2, bytes, options = {}) {
19223
- path2 = resolve7(path2);
19637
+ path2 = resolve9(path2);
19224
19638
  await ensurePrivateDirectory3(dirname12(path2));
19225
19639
  try {
19226
19640
  await verifyPrivate2(path2, "file", true);
@@ -19228,7 +19642,7 @@ async function writePrivateAtomic2(path2, bytes, options = {}) {
19228
19642
  if (error.code !== "ENOENT")
19229
19643
  throw error;
19230
19644
  }
19231
- const stage = resolve7(options.stagePath ?? `${path2}.${randomUUID11()}.tmp`);
19645
+ const stage = resolve9(options.stagePath ?? `${path2}.${randomUUID11()}.tmp`);
19232
19646
  if (dirname12(stage) !== dirname12(path2))
19233
19647
  throw new PrivateFileError2(path2, "stage-directory", { code: "EXDEV" });
19234
19648
  let created = false;
@@ -19304,15 +19718,15 @@ function createRedactor2(options = {}) {
19304
19718
  return SECRET_KEY_EXACT2.test(key) || normalized.includes("apikey") || normalized.endsWith("secret") || normalized.endsWith("password") || normalized.endsWith("token") && !normalized.endsWith("tokens") || !!options.extraSecretKeys?.(normalized);
19305
19719
  }
19306
19720
  function errorEntries(error) {
19307
- const fields = error;
19721
+ const fields2 = error;
19308
19722
  const entries = [
19309
19723
  ["name", error.name],
19310
19724
  ["message", error.message],
19311
19725
  ["stack", error.stack]
19312
19726
  ];
19313
19727
  for (const key of ["code", "status", "cause"])
19314
- if (fields[key] !== void 0)
19315
- entries.push([key, fields[key]]);
19728
+ if (fields2[key] !== void 0)
19729
+ entries.push([key, fields2[key]]);
19316
19730
  const listed = new Set(entries.map(([key]) => key));
19317
19731
  for (const entry of Object.entries(error))
19318
19732
  if (!listed.has(entry[0]))
@@ -19413,7 +19827,7 @@ async function openWindowsFile2(sink, file) {
19413
19827
  return sink.handle;
19414
19828
  }
19415
19829
  async function flushWindowsFile2(sink, file, text2) {
19416
- file = resolve8(file);
19830
+ file = resolve10(file);
19417
19831
  try {
19418
19832
  if (sink.file !== file)
19419
19833
  await closeWindowsFile2(sink);
@@ -19550,7 +19964,7 @@ function createEngine2(options) {
19550
19964
  } catch {
19551
19965
  }
19552
19966
  }
19553
- function schedule() {
19967
+ function schedule2() {
19554
19968
  if (!timer)
19555
19969
  timer = setTimeout(() => {
19556
19970
  timer = void 0;
@@ -19592,7 +20006,7 @@ function createEngine2(options) {
19592
20006
  void flushed.catch(() => {
19593
20007
  });
19594
20008
  } else
19595
- schedule();
20009
+ schedule2();
19596
20010
  } catch {
19597
20011
  }
19598
20012
  }
@@ -19647,7 +20061,7 @@ import {
19647
20061
  unlinkSync
19648
20062
  } from "node:fs";
19649
20063
  import { homedir as homedir2 } from "node:os";
19650
- import { join as join7 } from "node:path";
20064
+ import { join as join9 } from "node:path";
19651
20065
  import { env } from "node:process";
19652
20066
 
19653
20067
  // src/plugin/logging-utils.ts
@@ -19778,16 +20192,16 @@ var liveLogFilePaths = /* @__PURE__ */ new Set();
19778
20192
  function getConfigDir() {
19779
20193
  const platform = process.platform;
19780
20194
  if (platform === "win32") {
19781
- return join7(
19782
- env.APPDATA || join7(homedir2(), "AppData", "Roaming"),
20195
+ return join9(
20196
+ env.APPDATA || join9(homedir2(), "AppData", "Roaming"),
19783
20197
  "opencode"
19784
20198
  );
19785
20199
  }
19786
- const xdgConfig2 = env.XDG_CONFIG_HOME || join7(homedir2(), ".config");
19787
- return join7(xdgConfig2, "opencode");
20200
+ const xdgConfig2 = env.XDG_CONFIG_HOME || join9(homedir2(), ".config");
20201
+ return join9(xdgConfig2, "opencode");
19788
20202
  }
19789
20203
  function getLogsDir(customLogDir) {
19790
- const logsDir = customLogDir || join7(getConfigDir(), "antigravity-logs");
20204
+ const logsDir = customLogDir || join9(getConfigDir(), "antigravity-logs");
19791
20205
  try {
19792
20206
  mkdirSync(logsDir, { recursive: true, mode: 448 });
19793
20207
  } catch {
@@ -19798,9 +20212,9 @@ function createLogFilePath(customLogDir) {
19798
20212
  const logsDir = getLogsDir(customLogDir);
19799
20213
  cleanupOldLogs(logsDir, 25);
19800
20214
  const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
19801
- let candidate = join7(logsDir, `antigravity-debug-${timestamp}.log`);
20215
+ let candidate = join9(logsDir, `antigravity-debug-${timestamp}.log`);
19802
20216
  for (let suffix = 2; liveLogFilePaths.has(candidate); suffix++) {
19803
- candidate = join7(logsDir, `antigravity-debug-${timestamp}-${suffix}.log`);
20217
+ candidate = join9(logsDir, `antigravity-debug-${timestamp}-${suffix}.log`);
19804
20218
  }
19805
20219
  return candidate;
19806
20220
  }
@@ -19808,7 +20222,7 @@ function cleanupOldLogs(logsDir, maxFiles) {
19808
20222
  try {
19809
20223
  const files = readdirSync(logsDir).filter(
19810
20224
  (file) => file.startsWith("antigravity-debug-") && file.endsWith(".log")
19811
- ).map((file) => join7(logsDir, file));
20225
+ ).map((file) => join9(logsDir, file));
19812
20226
  if (files.length <= maxFiles) {
19813
20227
  return;
19814
20228
  }
@@ -20151,13 +20565,13 @@ function closeDebugLog() {
20151
20565
  if (!state || !current) return Promise.resolve();
20152
20566
  state.logStream = null;
20153
20567
  if (state.logFilePath) liveLogFilePaths.delete(state.logFilePath);
20154
- return new Promise((resolve13) => {
20155
- current.once("close", () => resolve13());
20156
- current.once("error", () => resolve13());
20568
+ return new Promise((resolve15) => {
20569
+ current.once("close", () => resolve15());
20570
+ current.once("error", () => resolve15());
20157
20571
  try {
20158
20572
  current.end();
20159
20573
  } catch {
20160
- resolve13();
20574
+ resolve15();
20161
20575
  }
20162
20576
  });
20163
20577
  }
@@ -20283,7 +20697,7 @@ var GITIGNORE_ENTRIES = [
20283
20697
  "antigravity-logs/"
20284
20698
  ];
20285
20699
  async function ensureGitignore(configDir) {
20286
- const gitignorePath = join8(configDir, ".gitignore");
20700
+ const gitignorePath = join10(configDir, ".gitignore");
20287
20701
  try {
20288
20702
  let content;
20289
20703
  let existingLines = [];
@@ -20329,7 +20743,7 @@ async function ensureGitignore(configDir) {
20329
20743
  }
20330
20744
  }
20331
20745
  function ensureGitignoreSync(configDir) {
20332
- const gitignorePath = join8(configDir, ".gitignore");
20746
+ const gitignorePath = join10(configDir, ".gitignore");
20333
20747
  try {
20334
20748
  let content;
20335
20749
  let existingLines = [];
@@ -20368,8 +20782,8 @@ function ensureGitignoreSync(configDir) {
20368
20782
  }
20369
20783
  }
20370
20784
  function getLegacyWindowsConfigDir() {
20371
- return join8(
20372
- process.env.APPDATA || join8(homedir3(), "AppData", "Roaming"),
20785
+ return join10(
20786
+ process.env.APPDATA || join10(homedir3(), "AppData", "Roaming"),
20373
20787
  "opencode"
20374
20788
  );
20375
20789
  }
@@ -20377,15 +20791,15 @@ function getConfigDir2() {
20377
20791
  if (process.env.OPENCODE_CONFIG_DIR) {
20378
20792
  return process.env.OPENCODE_CONFIG_DIR;
20379
20793
  }
20380
- const xdgConfig2 = process.env.XDG_CONFIG_HOME || join8(homedir3(), ".config");
20381
- return join8(xdgConfig2, "opencode");
20794
+ const xdgConfig2 = process.env.XDG_CONFIG_HOME || join10(homedir3(), ".config");
20795
+ return join10(xdgConfig2, "opencode");
20382
20796
  }
20383
20797
  function migrateLegacyWindowsConfig() {
20384
20798
  if (process.platform !== "win32") {
20385
20799
  return false;
20386
20800
  }
20387
- const newPath = join8(getConfigDir2(), "antigravity-accounts.json");
20388
- const legacyPath = join8(
20801
+ const newPath = join10(getConfigDir2(), "antigravity-accounts.json");
20802
+ const legacyPath = join10(
20389
20803
  getLegacyWindowsConfigDir(),
20390
20804
  "antigravity-accounts.json"
20391
20805
  );
@@ -20420,11 +20834,11 @@ function migrateLegacyWindowsConfig() {
20420
20834
  }
20421
20835
  }
20422
20836
  function getStoragePathWithMigration() {
20423
- const newPath = join8(getConfigDir2(), "antigravity-accounts.json");
20837
+ const newPath = join10(getConfigDir2(), "antigravity-accounts.json");
20424
20838
  if (process.platform === "win32") {
20425
20839
  migrateLegacyWindowsConfig();
20426
20840
  if (!existsSync3(newPath)) {
20427
- const legacyPath = join8(
20841
+ const legacyPath = join10(
20428
20842
  getLegacyWindowsConfigDir(),
20429
20843
  "antigravity-accounts.json"
20430
20844
  );
@@ -20455,7 +20869,7 @@ var LegacyAccountPoolRetiredError = class extends Error {
20455
20869
  };
20456
20870
  async function assertLegacyPoolInUse(legacyPath) {
20457
20871
  try {
20458
- await assertLegacyAccountStorageWritable(resolve9(legacyPath));
20872
+ await assertLegacyAccountStorageWritable(resolve11(legacyPath));
20459
20873
  } catch (error) {
20460
20874
  throw new LegacyAccountPoolRetiredError(legacyPath, { cause: error });
20461
20875
  }
@@ -20475,7 +20889,7 @@ function refusalMessage(admission) {
20475
20889
  }
20476
20890
  async function bindingOf(options) {
20477
20891
  const now = options.now ?? (() => Date.now());
20478
- const legacyPath = resolve9(options.legacyPath ?? getStoragePath());
20892
+ const legacyPath = resolve11(options.legacyPath ?? getStoragePath());
20479
20893
  return {
20480
20894
  legacyPath,
20481
20895
  now,
@@ -20543,7 +20957,7 @@ async function openAccountStore(options) {
20543
20957
  }
20544
20958
  function initializeFreshAccountStoreFor(modules, options = {}) {
20545
20959
  return initializeFreshAccountStore(modules, {
20546
- legacyPath: resolve9(options.legacyPath ?? getStoragePath()),
20960
+ legacyPath: resolve11(options.legacyPath ?? getStoragePath()),
20547
20961
  now: options.now ?? (() => Date.now())
20548
20962
  });
20549
20963
  }
@@ -20873,14 +21287,14 @@ async function fetchQuotaPayloads(options) {
20873
21287
  };
20874
21288
  }
20875
21289
  function untilQuotaAborted(pending, signal) {
20876
- return new Promise((resolve13, reject) => {
21290
+ return new Promise((resolve15, reject) => {
20877
21291
  const abort = () => reject(signal.reason);
20878
21292
  if (signal.aborted) abort();
20879
21293
  else signal.addEventListener("abort", abort, { once: true });
20880
21294
  void pending.then(
20881
21295
  (value) => {
20882
21296
  signal.removeEventListener("abort", abort);
20883
- resolve13(value);
21297
+ resolve15(value);
20884
21298
  },
20885
21299
  (error) => {
20886
21300
  signal.removeEventListener("abort", abort);
@@ -21162,12 +21576,12 @@ async function startOAuthListener({
21162
21576
  let resolveCallback;
21163
21577
  let rejectCallback;
21164
21578
  let timeoutHandle;
21165
- const callbackPromise = new Promise((resolve13, reject) => {
21579
+ const callbackPromise = new Promise((resolve15, reject) => {
21166
21580
  resolveCallback = (url) => {
21167
21581
  if (settled) return;
21168
21582
  settled = true;
21169
21583
  if (timeoutHandle) clearTimeout(timeoutHandle);
21170
- resolve13(url);
21584
+ resolve15(url);
21171
21585
  };
21172
21586
  rejectCallback = (error) => {
21173
21587
  if (settled) return;
@@ -21326,7 +21740,7 @@ async function startOAuthListener({
21326
21740
  });
21327
21741
  });
21328
21742
  const bindAddress = getBindAddress();
21329
- await new Promise((resolve13, reject) => {
21743
+ await new Promise((resolve15, reject) => {
21330
21744
  const handleError = (error) => {
21331
21745
  server.off("error", handleError);
21332
21746
  if (error.code === "EADDRINUSE") {
@@ -21342,7 +21756,7 @@ async function startOAuthListener({
21342
21756
  server.once("error", handleError);
21343
21757
  server.listen(port, bindAddress, () => {
21344
21758
  server.off("error", handleError);
21345
- resolve13();
21759
+ resolve15();
21346
21760
  });
21347
21761
  });
21348
21762
  server.on("error", (error) => {
@@ -21350,7 +21764,7 @@ async function startOAuthListener({
21350
21764
  });
21351
21765
  return {
21352
21766
  waitForCallback: () => callbackPromise,
21353
- close: () => new Promise((resolve13, reject) => {
21767
+ close: () => new Promise((resolve15, reject) => {
21354
21768
  server.close((error) => {
21355
21769
  if (error && error.code !== "ERR_SERVER_NOT_RUNNING") {
21356
21770
  reject(error);
@@ -21359,7 +21773,7 @@ async function startOAuthListener({
21359
21773
  if (!settled) {
21360
21774
  rejectCallback(new Error("OAuth listener closed before callback"));
21361
21775
  }
21362
- resolve13();
21776
+ resolve15();
21363
21777
  });
21364
21778
  })
21365
21779
  };
@@ -21371,7 +21785,7 @@ async function startOAuthListener({
21371
21785
 
21372
21786
  // src/setup.ts
21373
21787
  import { lstat as lstat5, readFile as readFile10 } from "node:fs/promises";
21374
- import { join as join15, resolve as resolve11 } from "node:path";
21788
+ import { join as join17, resolve as resolve13 } from "node:path";
21375
21789
 
21376
21790
  // src/auth-method-labels.ts
21377
21791
  var OPENCODE2_POOL_AUTH_LABEL = "Google (antigravity-auth pool, browser)";
@@ -21543,7 +21957,7 @@ async function select2(terminal, items, options) {
21543
21957
  writeLine("");
21544
21958
  renderedLines = lines;
21545
21959
  };
21546
- return new Promise((resolve13) => {
21960
+ return new Promise((resolve15) => {
21547
21961
  const wasRaw = stdin.isRaw ?? false;
21548
21962
  const cleanup2 = () => {
21549
21963
  if (cleaned)
@@ -21563,7 +21977,7 @@ async function select2(terminal, items, options) {
21563
21977
  };
21564
21978
  const finish = (value) => {
21565
21979
  cleanup2();
21566
- resolve13(value);
21980
+ resolve15(value);
21567
21981
  };
21568
21982
  const onSignal = () => finish(null);
21569
21983
  const onKey = (data) => {
@@ -21603,7 +22017,7 @@ async function select2(terminal, items, options) {
21603
22017
  stdin.setRawMode(true);
21604
22018
  } catch {
21605
22019
  cleanup2();
21606
- resolve13(null);
22020
+ resolve15(null);
21607
22021
  return;
21608
22022
  }
21609
22023
  stdin.resume();
@@ -21617,7 +22031,7 @@ async function select2(terminal, items, options) {
21617
22031
  import { createHash as createHash9, randomBytes as randomBytes3, randomUUID as randomUUID14 } from "node:crypto";
21618
22032
  import { constants as fsConstants2 } from "node:fs";
21619
22033
  import { chmod as chmod3, mkdir as mkdir12, open as open10, readFile as readFile9, realpath as realpath4, rename as rename9, stat as stat7, unlink as unlink9 } from "node:fs/promises";
21620
- import { basename as basename4, dirname as dirname16, extname as extname2, isAbsolute as isAbsolute3, join as join10, resolve as resolve10 } from "node:path";
22034
+ import { basename as basename4, dirname as dirname16, extname as extname2, isAbsolute as isAbsolute3, join as join12, resolve as resolve12 } from "node:path";
21621
22035
  import { ClaustrumCredentialError as ClaustrumCredentialError5, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
21622
22036
 
21623
22037
  // src/common-auth-embedded/fs/lock-constants.js
@@ -21639,7 +22053,7 @@ var WRITER_LOCK_CONSTANTS2 = Object.freeze({
21639
22053
  // src/common-auth-embedded/fs/refresh-file-lock.js
21640
22054
  import { randomUUID as randomUUID13 } from "node:crypto";
21641
22055
  import { mkdir as mkdir11, open as open9, readFile as readFile8, rename as rename8, rm as rm5, stat as stat6 } from "node:fs/promises";
21642
- import { dirname as dirname15, join as join9 } from "node:path";
22056
+ import { dirname as dirname15, join as join11 } from "node:path";
21643
22057
 
21644
22058
  // src/common-auth-embedded/fs/with-lock.js
21645
22059
  function lockPathFor2(target, name) {
@@ -21674,7 +22088,7 @@ function acquireRefreshFileLock2(options) {
21674
22088
  }
21675
22089
  async function acquireRefreshFileLockWithClock2(options) {
21676
22090
  const lockPath = lockPathFor2(options.path, options.name);
21677
- const legacyOwnerPath = join9(lockPath, "owner.json");
22091
+ const legacyOwnerPath = join11(lockPath, "owner.json");
21678
22092
  const ownerId = randomUUID13();
21679
22093
  const now = options.now ?? Date.now;
21680
22094
  let renewTimer = null;
@@ -21682,8 +22096,8 @@ async function acquireRefreshFileLockWithClock2(options) {
21682
22096
  let releaseConfirmed = false;
21683
22097
  let loss;
21684
22098
  let resolveLoss;
21685
- const lostPromise = new Promise((resolve13) => {
21686
- resolveLoss = resolve13;
22099
+ const lostPromise = new Promise((resolve15) => {
22100
+ resolveLoss = resolve15;
21687
22101
  });
21688
22102
  function notifyTimerStep(event) {
21689
22103
  try {
@@ -21717,7 +22131,7 @@ async function acquireRefreshFileLockWithClock2(options) {
21717
22131
  let terminalIOError;
21718
22132
  let renewalInFlight = null;
21719
22133
  const evictPath = `${lockPath}.evicting`;
21720
- const evictOwnerPath = join9(evictPath, "owner.json");
22134
+ const evictOwnerPath = join11(evictPath, "owner.json");
21721
22135
  const evictOwnerId = randomUUID13();
21722
22136
  const EVICT_TTL = 5e3;
21723
22137
  const MAX_STEAL_ATTEMPTS = 8;
@@ -21840,7 +22254,7 @@ async function acquireRefreshFileLockWithClock2(options) {
21840
22254
  }
21841
22255
  }
21842
22256
  async function backoff() {
21843
- await new Promise((resolve13) => setTimeout(resolve13, Math.floor(Math.random() * 4)));
22257
+ await new Promise((resolve15) => setTimeout(resolve15, Math.floor(Math.random() * 4)));
21844
22258
  }
21845
22259
  async function readLockState(notifyReady = true) {
21846
22260
  if (notifyReady && options.onStep)
@@ -22288,7 +22702,13 @@ var ENROLLMENT_SCHEMA2 = 1;
22288
22702
  var ENROLLMENT_FILE_MAX_BYTES2 = 16 * 1024;
22289
22703
  var ENROLLMENT_LOCK_TTL_MS2 = 3e4;
22290
22704
  var TOKEN_RE2 = /^[0-9a-f]{64}$/;
22705
+ var UNSUPPORTED_ENROLLMENT_CODE2 = "unknown_method";
22291
22706
  var TERMINAL_ENROLLMENT_CODES2 = /* @__PURE__ */ new Set([
22707
+ // The daemon's answer to an operation it does not implement: a vault built
22708
+ // before the enrollment ceremony. It arrives as a transport Error frame with
22709
+ // no class, which claustrum-client before 0.13.0 labels transient/retry, but
22710
+ // asking again can never succeed.
22711
+ UNSUPPORTED_ENROLLMENT_CODE2,
22292
22712
  "invalid_params",
22293
22713
  "pending_exists",
22294
22714
  "not_found",
@@ -22318,7 +22738,7 @@ function getClaustrumEnrollmentPaths2(tokenPath) {
22318
22738
  const extension = extname2(tokenPath) || ".json";
22319
22739
  const stem = basename4(tokenPath, extname2(tokenPath));
22320
22740
  return {
22321
- statePath: join10(dirname16(tokenPath), `${stem}-state${extension}`),
22741
+ statePath: join12(dirname16(tokenPath), `${stem}-state${extension}`),
22322
22742
  tokenPath
22323
22743
  };
22324
22744
  }
@@ -22326,7 +22746,7 @@ function hostEnrollmentPaths2(input) {
22326
22746
  const override = input.override?.trim();
22327
22747
  if (override && !isAbsolute3(override) && !input.cwd)
22328
22748
  throw new ClaustrumConsumerError2("invalid-state", "A relative Claustrum enrollment override needs a base directory");
22329
- const tokenPath = override ? isAbsolute3(override) ? override : resolve10(input.cwd, override) : join10(input.stateDir, `${input.host}-enrollment.json`);
22749
+ const tokenPath = override ? isAbsolute3(override) ? override : resolve12(input.cwd, override) : join12(input.stateDir, `${input.host}-enrollment.json`);
22330
22750
  return getClaustrumEnrollmentPaths2(tokenPath);
22331
22751
  }
22332
22752
  function isRecord9(value) {
@@ -22455,13 +22875,13 @@ async function readBoundedJson2(path2) {
22455
22875
  await descriptor.close();
22456
22876
  }
22457
22877
  }
22458
- function accountRecords2(text2, fields) {
22878
+ function accountRecords2(text2, fields2) {
22459
22879
  const records = [];
22460
22880
  for (const line of text2.split("\n")) {
22461
22881
  if (line.trim() === "" || line.startsWith("#"))
22462
22882
  continue;
22463
22883
  const parts = line.split(":");
22464
- if (parts.length !== fields || !/^[^\s:,]+$/.test(parts[0] ?? "") || !/^\d+$/.test(parts[2] ?? "") || !Number.isSafeInteger(Number(parts[2])) || fields === 7 && (!/^\d+$/.test(parts[3] ?? "") || !Number.isSafeInteger(Number(parts[3]))) || fields === 4 && parts[3] !== "" && !/^[^\s:,]+(?:,[^\s:,]+)*$/.test(parts[3] ?? ""))
22884
+ if (parts.length !== fields2 || !/^[^\s:,]+$/.test(parts[0] ?? "") || !/^\d+$/.test(parts[2] ?? "") || !Number.isSafeInteger(Number(parts[2])) || fields2 === 7 && (!/^\d+$/.test(parts[3] ?? "") || !Number.isSafeInteger(Number(parts[3]))) || fields2 === 4 && parts[3] !== "" && !/^[^\s:,]+(?:,[^\s:,]+)*$/.test(parts[3] ?? ""))
22465
22885
  return void 0;
22466
22886
  records.push(parts);
22467
22887
  }
@@ -22559,7 +22979,7 @@ async function writeStateAtomic2(path2, state, ancestorOptions = {}) {
22559
22979
  }
22560
22980
  if (windowsPrivateFiles2)
22561
22981
  return writePrivateAtomic2(path2, bytes);
22562
- const temporary = join10(parent, `.${basename4(path2)}.${process.pid}.${randomUUID14()}.tmp`);
22982
+ const temporary = join12(parent, `.${basename4(path2)}.${process.pid}.${randomUUID14()}.tmp`);
22563
22983
  let descriptor;
22564
22984
  let created = false;
22565
22985
  try {
@@ -22783,6 +23203,18 @@ var ClaustrumEnrollmentManager2 = class {
22783
23203
  retryCode: refusal3.code
22784
23204
  };
22785
23205
  }
23206
+ if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE2) {
23207
+ await lock.assertOwned();
23208
+ await unlink9(this.#paths.statePath).catch((cause) => {
23209
+ if (cause.code !== "ENOENT")
23210
+ throw cause;
23211
+ });
23212
+ return {
23213
+ state: "unavailable",
23214
+ proposedName: state.proposedName,
23215
+ code: refusal3.code
23216
+ };
23217
+ }
22786
23218
  return this.#block(state, refusal3.code);
22787
23219
  }
22788
23220
  }
@@ -22921,7 +23353,7 @@ var ByteTail = class {
22921
23353
  };
22922
23354
  var defaultCommandRunner = {
22923
23355
  run(file, args, options = {}) {
22924
- return new Promise((resolve13) => {
23356
+ return new Promise((resolve15) => {
22925
23357
  const started = performance.now();
22926
23358
  const timeoutMs = options.timeoutMs ?? 15e3;
22927
23359
  const stderr = new ByteTail();
@@ -22939,7 +23371,7 @@ var defaultCommandRunner = {
22939
23371
  stdio: ["ignore", "pipe", "pipe"]
22940
23372
  });
22941
23373
  } catch {
22942
- resolve13({
23374
+ resolve15({
22943
23375
  exitCode: 1,
22944
23376
  stdout: "",
22945
23377
  stderr: "",
@@ -22974,7 +23406,7 @@ var defaultCommandRunner = {
22974
23406
  settled = true;
22975
23407
  if (timer)
22976
23408
  clearTimeout(timer);
22977
- resolve13({
23409
+ resolve15({
22978
23410
  exitCode: spawnError ? 1 : outputExceeded ? 1 : code2 ?? 1,
22979
23411
  stdout: Buffer.concat(stdout, stdoutLength).toString("utf8"),
22980
23412
  stderr: stderr.toString(),
@@ -23060,8 +23492,8 @@ function recordSetupEnrollment(failure, enrollment) {
23060
23492
  // src/common-auth-embedded/setup/detect.js
23061
23493
  import { accessSync, constants as constants3, existsSync as existsSync5, readFileSync as readFileSync3, realpathSync, statSync as statSync5 } from "node:fs";
23062
23494
  import { mkdtemp, rm as rm6 } from "node:fs/promises";
23063
- import { tmpdir } from "node:os";
23064
- import { join as join11 } from "node:path";
23495
+ import { tmpdir as tmpdir3 } from "node:os";
23496
+ import { join as join13 } from "node:path";
23065
23497
  import { parse } from "jsonc-parser";
23066
23498
 
23067
23499
  // src/common-auth-embedded/setup/paths.js
@@ -23232,7 +23664,7 @@ async function detectHosts(plugin, io = {}) {
23232
23664
  return null;
23233
23665
  let root;
23234
23666
  try {
23235
- root = await mkdtemp(join11(tmpdir(), "common-auth-setup-version-"));
23667
+ root = await mkdtemp(join13(tmpdir3(), "common-auth-setup-version-"));
23236
23668
  const probeEnv = {
23237
23669
  ...env3,
23238
23670
  HOME: root,
@@ -23301,6 +23733,8 @@ import { writeEnrollmentTokenFile as writeEnrollmentTokenFile3 } from "@cortexki
23301
23733
  var WINDOWS_CIM_TIMEOUT_MS = 45e3;
23302
23734
  var HOSTS = /* @__PURE__ */ new Set(["opencode", "litecode", "opencode2", "pi"]);
23303
23735
  var RUNTIMES = /* @__PURE__ */ new Set(["node", "bun"]);
23736
+ var WINDOWS_FENCE_FILTER = [...HOSTS, ...RUNTIMES].map((name) => `Name LIKE '${name}%'`).join(" OR ");
23737
+ var WINDOWS_FENCE_QUERY = `$ErrorActionPreference = 'Stop'; $rows = @(Get-CimInstance Win32_Process -Filter "${WINDOWS_FENCE_FILTER}" | Select-Object Name,ProcessId,CommandLine); ConvertTo-Json -Compress -Depth 3 -InputObject @{ complete = $true; processes = $rows }`;
23304
23738
  var PI_SCRIPT_PATTERN = /(?:^|[/\\])pi-coding-agent[/\\]dist[/\\](?:(?:bundle|bun)[/\\])?cli\.m?js$/i;
23305
23739
  function commandArguments(command) {
23306
23740
  return [...command.matchAll(/"([^"]*)"|(\S+)/g)].map((match) => match[1] ?? match[2] ?? "");
@@ -23403,6 +23837,7 @@ Please quit all OpenCode, LiteCode, and Pi processes before running setup.`);
23403
23837
  };
23404
23838
  async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
23405
23839
  const windows = (options.platform ?? process.platform) === "win32";
23840
+ const selfPid = options.selfPid ?? process.pid;
23406
23841
  let inspection = {
23407
23842
  step: windows ? "tasklist" : "ps",
23408
23843
  exitCode: null,
@@ -23439,6 +23874,29 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
23439
23874
  }
23440
23875
  };
23441
23876
  try {
23877
+ if (windows && options.hostImagesOnly) {
23878
+ const details = await inspect("CIM", "powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", WINDOWS_FENCE_QUERY], WINDOWS_CIM_TIMEOUT_MS);
23879
+ if (details.exitCode !== 0)
23880
+ throw new ProcessInspectionError(inspection);
23881
+ const value = JSON.parse(details.stdout);
23882
+ if (!value || typeof value !== "object" || !("complete" in value) || value.complete !== true || !("processes" in value))
23883
+ throw new ProcessInspectionError(inspection);
23884
+ const listed = value.processes;
23885
+ const rows = listed === null ? [] : Array.isArray(listed) ? listed : [listed];
23886
+ const processes2 = [];
23887
+ for (const row of rows) {
23888
+ if (!row || typeof row !== "object" || !("Name" in row) || typeof row.Name !== "string" || !("ProcessId" in row) || !Number.isSafeInteger(row.ProcessId) || row.ProcessId < 0 || !("CommandLine" in row))
23889
+ throw new ProcessInspectionError(inspection);
23890
+ const pid = row.ProcessId;
23891
+ if (!/^(?:node|bun)\.exe$/i.test(row.Name))
23892
+ processes2.push({ pid, command: row.Name });
23893
+ else if (typeof row.CommandLine === "string")
23894
+ processes2.push({ pid, command: row.CommandLine });
23895
+ else if (pid !== selfPid)
23896
+ throw new ProcessInspectionError(inspection);
23897
+ }
23898
+ return processes2;
23899
+ }
23442
23900
  const result = await inspect(windows ? "tasklist" : "ps", windows ? "tasklist.exe" : "ps", windows ? ["/fo", "csv", "/nh"] : ["-eo", "pid,command"]);
23443
23901
  if (result.exitCode !== 0)
23444
23902
  throw new ProcessInspectionError(inspection);
@@ -23471,7 +23929,7 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
23471
23929
  }
23472
23930
  if (!processes.length)
23473
23931
  throw new ProcessInspectionError(inspection);
23474
- const runtimes = processes.filter((entry) => entry.pid !== process.pid && /^(?:node|bun)\.exe$/i.test(entry.command));
23932
+ const runtimes = processes.filter((entry) => entry.pid !== selfPid && /^(?:node|bun)\.exe$/i.test(entry.command));
23475
23933
  if (windows && runtimes.length && options.inspectRuntimes !== false) {
23476
23934
  const details = await inspect("CIM", "powershell.exe", [
23477
23935
  "-NoProfile",
@@ -23504,10 +23962,15 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
23504
23962
  }
23505
23963
  }
23506
23964
  function createProcessFence(runner = defaultCommandRunner, options = {}) {
23507
- const isHost = (entry) => entry.pid !== process.pid && hostName(entry.command) !== null;
23965
+ const selfPid = options.selfPid ?? process.pid;
23966
+ const isHost = (entry) => entry.pid !== selfPid && hostName(entry.command) !== null;
23508
23967
  return {
23509
23968
  async listRunningHosts(env3) {
23510
- return (await listSetupProcesses(runner, { ...options, env: env3 })).filter(isHost);
23969
+ return (await listSetupProcesses(runner, {
23970
+ ...options,
23971
+ env: env3,
23972
+ hostImagesOnly: true
23973
+ })).filter(isHost);
23511
23974
  },
23512
23975
  async previewRunningHosts(env3) {
23513
23976
  const processes = await listSetupProcesses(runner, {
@@ -23518,7 +23981,7 @@ function createProcessFence(runner = defaultCommandRunner, options = {}) {
23518
23981
  const windows = (options.platform ?? process.platform) === "win32";
23519
23982
  return {
23520
23983
  hosts: processes.filter(isHost),
23521
- uncheckedRuntimes: windows ? processes.filter((entry) => entry.pid !== process.pid && /^(?:node|bun)\.exe$/i.test(entry.command)).length : 0
23984
+ uncheckedRuntimes: windows ? processes.filter((entry) => entry.pid !== selfPid && /^(?:node|bun)\.exe$/i.test(entry.command)).length : 0
23522
23985
  };
23523
23986
  }
23524
23987
  };
@@ -23531,8 +23994,27 @@ async function assertHostsStopped(fence, env3) {
23531
23994
 
23532
23995
  // src/common-auth-embedded/setup/enroll.js
23533
23996
  var ENROLLMENT_INCOMPLETE_MESSAGE = "Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.";
23997
+ var UNSUPPORTED_VAULT_MESSAGE = "This Claustrum vault does not support connecting plugins yet, so setup cannot connect to it. Run setup without --claustrum to use local accounts.";
23998
+ var ENROLLMENT_WAIT_MS = 3e5;
23999
+ var APPROVAL_POLL_MS = 1e3;
24000
+ var PROPOSE_BACKOFF_MS = [1e3, 2e3, 4e3, 8e3, 16e3, 3e4];
24001
+ function safeCode(code2) {
24002
+ return code2 && /^[a-z][a-z0-9_]{0,63}$/.test(code2) ? code2 : "unknown";
24003
+ }
23534
24004
  var HostNotEnrolledError = class extends Error {
24005
+ reason;
24006
+ lastErrorCode;
24007
+ constructor(message, details) {
24008
+ super(message);
24009
+ this.name = "HostNotEnrolledError";
24010
+ this.reason = details.reason;
24011
+ if (details.lastErrorCode !== void 0)
24012
+ this.lastErrorCode = safeCode(details.lastErrorCode);
24013
+ }
23535
24014
  };
24015
+ function approveCommand(requestId, name) {
24016
+ return `ck auth enroll approve --request-id ${requestId} --name ${name}`;
24017
+ }
23536
24018
  async function connectSetupHost(plugin, host, io, terminal, fence) {
23537
24019
  const { name, paths: input } = plugin.vault.hosts[host];
23538
24020
  const paths = hostEnrollmentPaths2(input);
@@ -23541,54 +24023,94 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
23541
24023
  connectionFile: plugin.vault.connectionFile,
23542
24024
  handshakeTimeoutMs: 2e3
23543
24025
  }).catch(() => {
23544
- throw new HostNotEnrolledError("Claustrum connection failed; start ck and rerun setup.");
24026
+ throw new HostNotEnrolledError("Claustrum connection failed; start ck and rerun setup.", { reason: "connection-failed" });
23545
24027
  });
24028
+ const now = io.now ?? (() => performance.now());
24029
+ const wait2 = io.wait ?? delay;
23546
24030
  try {
23547
24031
  const manager = new ClaustrumEnrollmentManager2({
23548
24032
  proposedName: name,
23549
24033
  paths,
23550
- client: {
23551
- enrollPropose: async (input2) => {
23552
- await fence();
23553
- return client.enrollPropose(input2);
23554
- },
23555
- enrollPoll: async (input2) => {
23556
- await fence();
23557
- return client.enrollPoll(input2);
23558
- }
23559
- },
24034
+ // Each tick of the wait below checks the fence once, just before
24035
+ // reconcile proposes or polls. Checking again inside every vault call
24036
+ // doubled the process listings per tick, and on Windows each listing
24037
+ // starts PowerShell.
24038
+ client,
23560
24039
  writeTokenFile: async (path2, file) => {
23561
24040
  await fence();
23562
24041
  await writeEnrollmentTokenFile3(path2, file);
23563
24042
  }
23564
24043
  });
24044
+ printLine2(terminal, `Asking the vault to connect ${name}\u2026`);
24045
+ const deadline = now() + ENROLLMENT_WAIT_MS;
23565
24046
  let printedRequest;
23566
- for (let tick = 0; tick < 300; tick++) {
24047
+ let lastCode;
24048
+ let reportedCode;
24049
+ let failedProposals = 0;
24050
+ for (; ; ) {
23567
24051
  await fence();
23568
24052
  const status = await manager.reconcile();
23569
24053
  if (status.state === "approved") {
23570
24054
  printLine2(terminal, `Connected ${host} to Claustrum.`);
23571
24055
  return;
23572
24056
  }
24057
+ if (status.state === "unavailable" && status.code === UNSUPPORTED_ENROLLMENT_CODE2)
24058
+ throw new HostNotEnrolledError(UNSUPPORTED_VAULT_MESSAGE, {
24059
+ reason: "unsupported-vault",
24060
+ lastErrorCode: status.code
24061
+ });
23573
24062
  if (status.state !== "pending" && status.state !== "busy")
23574
- throw new HostNotEnrolledError("Claustrum enrollment refused; inspect its status with ck before rerunning setup.");
23575
- if (status.state === "pending" && status.requestId && status.requestId !== printedRequest) {
23576
- if (!/^[a-zA-Z0-9_-]+$/.test(status.requestId))
23577
- throw new HostNotEnrolledError("Invalid enrollment request id.");
23578
- printedRequest = status.requestId;
23579
- printLine2(terminal, "Waiting for approval. In another terminal, run:");
23580
- printLine2(terminal, ` ck auth enroll approve --request-id ${status.requestId} --name ${name}`);
23581
- printLine2(terminal, `Enrollment files: ${paths.statePath}, ${paths.tokenPath}`);
23582
- }
23583
- await (io.wait ?? delay)(1e3);
23584
- }
23585
- throw new HostNotEnrolledError("Claustrum approval is still pending; approve with ck and rerun setup.");
24063
+ throw new HostNotEnrolledError("Claustrum enrollment refused; inspect its status with ck before rerunning setup.", {
24064
+ reason: "refused",
24065
+ ..."code" in status && { lastErrorCode: status.code }
24066
+ });
24067
+ let pause = APPROVAL_POLL_MS;
24068
+ if (status.state === "busy")
24069
+ lastCode = "busy";
24070
+ else if (status.retryCode)
24071
+ lastCode = status.retryCode;
24072
+ if (status.state === "pending" && status.requestId) {
24073
+ failedProposals = 0;
24074
+ if (status.requestId !== printedRequest) {
24075
+ if (!/^[a-zA-Z0-9_-]+$/.test(status.requestId))
24076
+ throw new HostNotEnrolledError("Invalid enrollment request id.", {
24077
+ reason: "invalid-request"
24078
+ });
24079
+ printedRequest = status.requestId;
24080
+ printLine2(terminal, "Waiting for approval. In another terminal, run:");
24081
+ printLine2(terminal, ` ${approveCommand(status.requestId, name)}`);
24082
+ printLine2(terminal, `Enrollment files: ${paths.statePath}, ${paths.tokenPath}`);
24083
+ }
24084
+ } else if (status.state === "pending" && status.retryCode) {
24085
+ pause = PROPOSE_BACKOFF_MS[Math.min(failedProposals, PROPOSE_BACKOFF_MS.length - 1)] ?? APPROVAL_POLL_MS;
24086
+ failedProposals++;
24087
+ const code3 = safeCode(status.retryCode);
24088
+ if (code3 !== reportedCode) {
24089
+ reportedCode = code3;
24090
+ printLine2(terminal, `The vault has not created the request yet (${code3}); retrying.`);
24091
+ }
24092
+ }
24093
+ const remaining = deadline - now();
24094
+ if (remaining <= 0)
24095
+ break;
24096
+ await wait2(Math.min(pause, remaining));
24097
+ }
24098
+ if (printedRequest)
24099
+ throw new HostNotEnrolledError(`Claustrum approval is still pending. In another terminal, run: ${approveCommand(printedRequest, name)} and then rerun setup.`, {
24100
+ reason: "approval-pending",
24101
+ ...lastCode !== void 0 && { lastErrorCode: lastCode }
24102
+ });
24103
+ const code2 = safeCode(lastCode);
24104
+ throw new HostNotEnrolledError(`The vault never created the enrollment request (last error: ${code2}). Check that ck is running, then rerun setup.`, { reason: "request-not-created", lastErrorCode: code2 });
23586
24105
  } catch (error) {
23587
- if (error instanceof ProcessFenceViolationError || error instanceof ProcessInspectionError)
24106
+ if (error instanceof ProcessFenceViolationError || error instanceof ProcessInspectionError || // Built above from fixed text and vetted values only.
24107
+ error instanceof HostNotEnrolledError)
23588
24108
  throw error;
23589
- if (error instanceof HostNotEnrolledError)
23590
- throw new HostNotEnrolledError(ENROLLMENT_INCOMPLETE_MESSAGE);
23591
- throw new Error(ENROLLMENT_INCOMPLETE_MESSAGE);
24109
+ const code2 = error?.code;
24110
+ throw new HostNotEnrolledError(ENROLLMENT_INCOMPLETE_MESSAGE, {
24111
+ reason: "incomplete",
24112
+ ...typeof code2 === "string" && { lastErrorCode: code2 }
24113
+ });
23592
24114
  } finally {
23593
24115
  client.close();
23594
24116
  }
@@ -23626,7 +24148,7 @@ import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2,
23626
24148
  // src/common-auth-embedded/setup/config-write.js
23627
24149
  import { randomUUID as randomUUID15 } from "node:crypto";
23628
24150
  import { mkdir as mkdir13, open as open11, rename as rename10, stat as stat9, unlink as unlink10 } from "node:fs/promises";
23629
- import { basename as basename5, dirname as dirname17, join as join12 } from "node:path";
24151
+ import { basename as basename5, dirname as dirname17, join as join14 } from "node:path";
23630
24152
  import { setTimeout as delay2 } from "node:timers/promises";
23631
24153
  async function writeHostConfigAtomic(file, content, options = {}) {
23632
24154
  const windows = (options.platform ?? process.platform) === "win32";
@@ -23641,7 +24163,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
23641
24163
  throw error;
23642
24164
  }
23643
24165
  }
23644
- const stage = join12(parent, `.${basename5(file)}.${(options.stageName ?? randomUUID15)()}.tmp`);
24166
+ const stage = join14(parent, `.${basename5(file)}.${(options.stageName ?? randomUUID15)()}.tmp`);
23645
24167
  let created = false;
23646
24168
  try {
23647
24169
  const handle = await open11(stage, "wx", mode ?? 438);
@@ -24007,28 +24529,28 @@ ${write.content}`);
24007
24529
 
24008
24530
  // src/plugin/vault-activation.ts
24009
24531
  import { homedir as homedir5 } from "node:os";
24010
- import { join as join13 } from "node:path";
24532
+ import { join as join15 } from "node:path";
24011
24533
  function nativeOpenCodeAuthPath(env3 = process.env, home = homedir5()) {
24012
- return join13(
24013
- env3.XDG_DATA_HOME || join13(home, ".local", "share"),
24534
+ return join15(
24535
+ env3.XDG_DATA_HOME || join15(home, ".local", "share"),
24014
24536
  "opencode",
24015
24537
  "auth.json"
24016
24538
  );
24017
24539
  }
24018
24540
 
24019
24541
  // src/plugin/vault-custody.ts
24020
- import { dirname as dirname18, join as join14 } from "node:path";
24542
+ import { dirname as dirname18, join as join16 } from "node:path";
24021
24543
  var OPENCODE_VAULT_PROVIDER = "google";
24022
24544
  var OPENCODE_VAULT_HOST = "opencode";
24023
24545
  var OPENCODE_VAULT_ENROLLMENT_NAME = getAntigravityVaultEnrollmentName(OPENCODE_VAULT_HOST);
24024
24546
  var OPENCODE_VAULT_DIR_NAME = "antigravity-auth-vault";
24025
24547
  function openCodeVaultPaths(accountFile) {
24026
- const dir = join14(dirname18(accountFile), OPENCODE_VAULT_DIR_NAME);
24548
+ const dir = join16(dirname18(accountFile), OPENCODE_VAULT_DIR_NAME);
24027
24549
  return {
24028
24550
  dir,
24029
- modeFile: join14(dir, "opencode-mode.json"),
24030
- rosterFile: join14(dir, "opencode-roster.json"),
24031
- stateFile: join14(dir, "opencode-state.json")
24551
+ modeFile: join16(dir, "opencode-mode.json"),
24552
+ rosterFile: join16(dir, "opencode-roster.json"),
24553
+ stateFile: join16(dir, "opencode-state.json")
24032
24554
  };
24033
24555
  }
24034
24556
  var LOCAL_MODE = Object.freeze({
@@ -24044,7 +24566,7 @@ var OPENCODE_VAULT_GRANT_COMMAND = `ck auth grant --principal enrolled:${OPENCOD
24044
24566
  // src/setup.ts
24045
24567
  var PI_PLACEHOLDER_KEY = "antigravity-vault-custody";
24046
24568
  function nativeAuthPath(host, context) {
24047
- return host === "opencode" ? nativeOpenCodeAuthPath() : join15(context.piAgentDir, "auth.json");
24569
+ return host === "opencode" ? nativeOpenCodeAuthPath() : join17(context.piAgentDir, "auth.json");
24048
24570
  }
24049
24571
  function provider(host) {
24050
24572
  return host === "opencode" ? OPENCODE_VAULT_PROVIDER : ANTIGRAVITY_PROVIDER_ID;
@@ -24100,7 +24622,7 @@ async function writeNativeSlot(host, slot, context, expectedAuthority = "local")
24100
24622
  beforeRename: async () => {
24101
24623
  await assertSetupHostsStopped();
24102
24624
  const claustrum = await loadCommonAuthClaustrum();
24103
- const stateDir = host === "opencode" ? openCodeVaultPaths(resolve11(getStoragePath())).dir : getPiAntigravityVaultDir();
24625
+ const stateDir = host === "opencode" ? openCodeVaultPaths(resolve13(getStoragePath())).dir : getPiAntigravityVaultDir();
24104
24626
  if (await claustrum.enrollmentAuthority(
24105
24627
  claustrum.hostEnrollmentPaths({ stateDir, host }),
24106
24628
  `antigravity-auth-${host}`
@@ -24130,7 +24652,7 @@ async function persistPiSetupLogin(result, context) {
24130
24652
  }
24131
24653
  async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
24132
24654
  const claustrum = await loadCommonAuthClaustrum();
24133
- const opencode = openCodeVaultPaths(resolve11(getStoragePath()));
24655
+ const opencode = openCodeVaultPaths(resolve13(getStoragePath()));
24134
24656
  const piDir = getPiAntigravityVaultDir();
24135
24657
  const hosts = {
24136
24658
  opencode: {
@@ -24149,7 +24671,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
24149
24671
  const assertLocal = async (host, context) => {
24150
24672
  if (host === "opencode")
24151
24673
  return assertLocalOpenCodeLogin(
24152
- resolve11(getStoragePath()),
24674
+ resolve13(getStoragePath()),
24153
24675
  context.opencodeGeneration
24154
24676
  );
24155
24677
  if (await authority(host) !== "local")
@@ -24165,7 +24687,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
24165
24687
  const { openPiSlot: openPiSlot2 } = await loadCommonAuthPiSlot();
24166
24688
  if ((await openPiSlot2({
24167
24689
  authPath: nativeAuthPath(host, context),
24168
- stashPath: join15(piDir, "google-login-stash.json"),
24690
+ stashPath: join17(piDir, "google-login-stash.json"),
24169
24691
  provider: ANTIGRAVITY_PROVIDER_ID,
24170
24692
  placeholderKey: PI_PLACEHOLDER_KEY
24171
24693
  }).inspect()).slot === "placeholder")
@@ -24202,7 +24724,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
24202
24724
  const { openPiSlot: openPiSlot2 } = await loadCommonAuthPiSlot();
24203
24725
  const inspection = await openPiSlot2({
24204
24726
  authPath: nativeAuthPath("pi", context),
24205
- stashPath: join15(piDir, "google-login-stash.json"),
24727
+ stashPath: join17(piDir, "google-login-stash.json"),
24206
24728
  provider: ANTIGRAVITY_PROVIDER_ID,
24207
24729
  placeholderKey: PI_PLACEHOLDER_KEY
24208
24730
  }).inspect();
@@ -24321,7 +24843,7 @@ Setup has not completed the OpenCode 2 native Google connection.
24321
24843
  await assertSetupHostsStopped();
24322
24844
  await openPiSlot2({
24323
24845
  authPath: nativeAuthPath(host, context),
24324
- stashPath: join15(piDir, "google-login-stash.json"),
24846
+ stashPath: join17(piDir, "google-login-stash.json"),
24325
24847
  provider: ANTIGRAVITY_PROVIDER_ID,
24326
24848
  placeholderKey: PI_PLACEHOLDER_KEY
24327
24849
  }).enterVault();
@@ -24681,7 +25203,7 @@ function createDefaultCliDependencies() {
24681
25203
  throw new Error(
24682
25204
  "Pi setup requires its detected native agent directory."
24683
25205
  );
24684
- const legacyPath = resolve12(getStoragePath());
25206
+ const legacyPath = resolve14(getStoragePath());
24685
25207
  const repository = host === "pi" ? void 0 : await prepareCliLoginStore(legacyPath, context?.opencodeGeneration);
24686
25208
  try {
24687
25209
  return await performOAuthLogin(request, {
@@ -24841,7 +25363,7 @@ async function readAccountStore(legacyPath) {
24841
25363
  function createDefaultAccountStoreOperations() {
24842
25364
  const offline = { processesStopped: true };
24843
25365
  return {
24844
- legacyPath: () => resolve12(getStoragePath()),
25366
+ legacyPath: () => resolve14(getStoragePath()),
24845
25367
  migrate: async (legacyPath) => createAccountMigrationFactory(await loadCommonAuthStoreModules())({
24846
25368
  legacyPath,
24847
25369
  offline,