@cortexkit/opencode-antigravity-auth 3.0.40 → 3.0.41

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 (226) hide show
  1. package/dist/cli.js +278 -81
  2. package/dist/cli.js.map +3 -3
  3. package/dist/cli.meta.json +29 -29
  4. package/dist/index.js +6890 -3708
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +1234 -259
  7. package/dist/server.js +6433 -3197
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/common-auth-embedded/commands/builtins.d.ts +20 -1
  11. package/dist/src/common-auth-embedded/commands/builtins.js +28 -12
  12. package/dist/src/common-auth-embedded/commands/index.d.ts +1 -1
  13. package/dist/src/common-auth-embedded/commands/menu.d.ts +6 -1
  14. package/dist/src/common-auth-embedded/commands/menu.js +1 -0
  15. package/dist/src/common-auth-embedded/fs/file-read-cache.js +9 -5
  16. package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +11 -0
  17. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +146 -2
  18. package/dist/src/common-auth-embedded/fs/with-lock.d.ts +2 -0
  19. package/dist/src/common-auth-embedded/fs/with-lock.js +1 -1
  20. package/dist/src/common-auth-embedded/settings/define.d.ts +35 -0
  21. package/dist/src/common-auth-embedded/settings/define.js +52 -0
  22. package/dist/src/common-auth-embedded/settings/descriptors.d.ts +97 -0
  23. package/dist/src/common-auth-embedded/settings/descriptors.js +81 -0
  24. package/dist/src/common-auth-embedded/settings/edit.d.ts +24 -0
  25. package/dist/src/common-auth-embedded/settings/edit.js +229 -0
  26. package/dist/src/common-auth-embedded/settings/fs.js +19 -0
  27. package/dist/src/common-auth-embedded/settings/handle.d.ts +30 -0
  28. package/dist/src/common-auth-embedded/settings/handle.js +228 -0
  29. package/dist/src/common-auth-embedded/settings/index.d.ts +10 -0
  30. package/dist/src/common-auth-embedded/settings/index.js +7 -0
  31. package/dist/src/common-auth-embedded/settings/lock-errors.js +15 -0
  32. package/dist/src/common-auth-embedded/settings/move.d.ts +76 -0
  33. package/dist/src/common-auth-embedded/settings/move.js +351 -0
  34. package/dist/src/common-auth-embedded/settings/parse.d.ts +24 -0
  35. package/dist/src/common-auth-embedded/settings/parse.js +65 -0
  36. package/dist/src/common-auth-embedded/settings/paths.d.ts +12 -0
  37. package/dist/src/common-auth-embedded/settings/paths.js +48 -0
  38. package/dist/src/common-auth-embedded/settings/refusal.d.ts +7 -0
  39. package/dist/src/common-auth-embedded/settings/refusal.js +15 -0
  40. package/dist/src/common-auth-embedded/settings/resolve.d.ts +15 -0
  41. package/dist/src/common-auth-embedded/settings/resolve.js +51 -0
  42. package/dist/src/common-auth-embedded/settings/schema.d.ts +29 -0
  43. package/dist/src/common-auth-embedded/settings/schema.js +81 -0
  44. package/dist/src/common-auth-embedded/settings/snapshot.d.ts +24 -0
  45. package/dist/src/common-auth-embedded/settings/snapshot.js +150 -0
  46. package/dist/src/common-auth-embedded/settings/update.js +139 -0
  47. package/dist/src/common-auth-embedded/settings/write.js +88 -0
  48. package/dist/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  49. package/dist/src/common-auth-embedded/setup/command-error.js +3 -2
  50. package/dist/src/common-auth-embedded/setup/command.js +5 -1
  51. package/dist/src/common-auth-embedded/setup/enroll.js +3 -3
  52. package/dist/src/common-auth-embedded/setup/enrollment-access.js +13 -4
  53. package/dist/src/common-auth-embedded/setup/types.d.ts +4 -0
  54. package/dist/src/common-auth-embedded/source-output.json +291 -55
  55. package/dist/src/common-auth-embedded/tui-prefs/watcher.js +196 -0
  56. package/dist/src/ga/tui/host-ga.js +1 -1
  57. package/dist/src/ga/tui/host-ga.js.map +1 -1
  58. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  59. package/dist/src/plugin/command-apply.d.ts +43 -3
  60. package/dist/src/plugin/command-apply.d.ts.map +1 -1
  61. package/dist/src/plugin/command-apply.js +92 -12
  62. package/dist/src/plugin/command-apply.js.map +1 -1
  63. package/dist/src/plugin/commands.d.ts +5 -1
  64. package/dist/src/plugin/commands.d.ts.map +1 -1
  65. package/dist/src/plugin/commands.js +4 -3
  66. package/dist/src/plugin/commands.js.map +1 -1
  67. package/dist/src/plugin/config/writer.d.ts +10 -3
  68. package/dist/src/plugin/config/writer.d.ts.map +1 -1
  69. package/dist/src/plugin/config/writer.js +30 -22
  70. package/dist/src/plugin/config/writer.js.map +1 -1
  71. package/dist/src/plugin/fetch-interceptor.d.ts +8 -3
  72. package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
  73. package/dist/src/plugin/fetch-interceptor.js +1 -0
  74. package/dist/src/plugin/fetch-interceptor.js.map +1 -1
  75. package/dist/src/plugin/ga-location-services.d.ts +3 -1
  76. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  77. package/dist/src/plugin/ga-location-services.js +35 -5
  78. package/dist/src/plugin/ga-location-services.js.map +1 -1
  79. package/dist/src/plugin/index.d.ts.map +1 -1
  80. package/dist/src/plugin/index.js +65 -15
  81. package/dist/src/plugin/index.js.map +1 -1
  82. package/dist/src/plugin/killswitch.d.ts +20 -0
  83. package/dist/src/plugin/killswitch.d.ts.map +1 -1
  84. package/dist/src/plugin/killswitch.js +14 -4
  85. package/dist/src/plugin/killswitch.js.map +1 -1
  86. package/dist/src/plugin/operator-settings.d.ts +6 -0
  87. package/dist/src/plugin/operator-settings.d.ts.map +1 -1
  88. package/dist/src/plugin/operator-settings.js.map +1 -1
  89. package/dist/src/plugin/request-helpers.d.ts +5 -0
  90. package/dist/src/plugin/request-helpers.d.ts.map +1 -1
  91. package/dist/src/plugin/request-helpers.js +11 -2
  92. package/dist/src/plugin/request-helpers.js.map +1 -1
  93. package/dist/src/plugin/shared/request-services.d.ts +10 -1
  94. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  95. package/dist/src/plugin/shared/request-services.js +91 -13
  96. package/dist/src/plugin/shared/request-services.js.map +1 -1
  97. package/dist/src/plugin/shared/runtime.d.ts +15 -0
  98. package/dist/src/plugin/shared/runtime.d.ts.map +1 -1
  99. package/dist/src/plugin/shared/runtime.js +43 -11
  100. package/dist/src/plugin/shared/runtime.js.map +1 -1
  101. package/dist/src/plugin/shared/vault-menu.d.ts +11 -1
  102. package/dist/src/plugin/shared/vault-menu.d.ts.map +1 -1
  103. package/dist/src/plugin/shared/vault-menu.js +33 -7
  104. package/dist/src/plugin/shared/vault-menu.js.map +1 -1
  105. package/dist/src/settings/core-settings.d.ts +7 -0
  106. package/dist/src/settings/core-settings.d.ts.map +1 -0
  107. package/dist/src/settings/core-settings.js +7 -0
  108. package/dist/src/settings/core-settings.js.map +1 -0
  109. package/dist/src/settings/legacy.d.ts +89 -0
  110. package/dist/src/settings/legacy.d.ts.map +1 -0
  111. package/dist/src/settings/legacy.js +184 -0
  112. package/dist/src/settings/legacy.js.map +1 -0
  113. package/dist/src/settings/location.d.ts +22 -0
  114. package/dist/src/settings/location.d.ts.map +1 -0
  115. package/dist/src/settings/location.js +49 -0
  116. package/dist/src/settings/location.js.map +1 -0
  117. package/dist/src/settings/move.d.ts +38 -0
  118. package/dist/src/settings/move.d.ts.map +1 -0
  119. package/dist/src/settings/move.js +83 -0
  120. package/dist/src/settings/move.js.map +1 -0
  121. package/dist/src/settings/protection.d.ts +11 -0
  122. package/dist/src/settings/protection.d.ts.map +1 -0
  123. package/dist/src/settings/protection.js +17 -0
  124. package/dist/src/settings/protection.js.map +1 -0
  125. package/dist/src/settings/report.d.ts +33 -0
  126. package/dist/src/settings/report.d.ts.map +1 -0
  127. package/dist/src/settings/report.js +103 -0
  128. package/dist/src/settings/report.js.map +1 -0
  129. package/dist/src/settings/runtime.d.ts +145 -0
  130. package/dist/src/settings/runtime.d.ts.map +1 -0
  131. package/dist/src/settings/runtime.js +697 -0
  132. package/dist/src/settings/runtime.js.map +1 -0
  133. package/dist/tui-build-map.json +1 -1
  134. package/dist/tui-ga-build-map.json +5 -5
  135. package/dist/types/src/common-auth-embedded/commands/builtins.d.ts +20 -1
  136. package/dist/types/src/common-auth-embedded/commands/index.d.ts +1 -1
  137. package/dist/types/src/common-auth-embedded/commands/menu.d.ts +6 -1
  138. package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +11 -0
  139. package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  140. package/dist/types/src/common-auth-embedded/setup/types.d.ts +4 -0
  141. package/dist/types/src/plugin/command-apply.d.ts +43 -3
  142. package/dist/types/src/plugin/command-apply.d.ts.map +1 -1
  143. package/dist/types/src/plugin/commands.d.ts +5 -1
  144. package/dist/types/src/plugin/commands.d.ts.map +1 -1
  145. package/dist/types/src/plugin/config/writer.d.ts +10 -3
  146. package/dist/types/src/plugin/config/writer.d.ts.map +1 -1
  147. package/dist/types/src/plugin/fetch-interceptor.d.ts +8 -3
  148. package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
  149. package/dist/types/src/plugin/ga-location-services.d.ts +3 -1
  150. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  151. package/dist/types/src/plugin/index.d.ts.map +1 -1
  152. package/dist/types/src/plugin/killswitch.d.ts +20 -0
  153. package/dist/types/src/plugin/killswitch.d.ts.map +1 -1
  154. package/dist/types/src/plugin/operator-settings.d.ts +6 -0
  155. package/dist/types/src/plugin/operator-settings.d.ts.map +1 -1
  156. package/dist/types/src/plugin/request-helpers.d.ts +5 -0
  157. package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
  158. package/dist/types/src/plugin/shared/request-services.d.ts +10 -1
  159. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  160. package/dist/types/src/plugin/shared/runtime.d.ts +15 -0
  161. package/dist/types/src/plugin/shared/runtime.d.ts.map +1 -1
  162. package/dist/types/src/plugin/shared/vault-menu.d.ts +11 -1
  163. package/dist/types/src/plugin/shared/vault-menu.d.ts.map +1 -1
  164. package/dist/types/src/settings/core-settings.d.ts +7 -0
  165. package/dist/types/src/settings/core-settings.d.ts.map +1 -0
  166. package/dist/types/src/settings/legacy.d.ts +89 -0
  167. package/dist/types/src/settings/legacy.d.ts.map +1 -0
  168. package/dist/types/src/settings/location.d.ts +22 -0
  169. package/dist/types/src/settings/location.d.ts.map +1 -0
  170. package/dist/types/src/settings/move.d.ts +38 -0
  171. package/dist/types/src/settings/move.d.ts.map +1 -0
  172. package/dist/types/src/settings/protection.d.ts +11 -0
  173. package/dist/types/src/settings/protection.d.ts.map +1 -0
  174. package/dist/types/src/settings/report.d.ts +33 -0
  175. package/dist/types/src/settings/report.d.ts.map +1 -0
  176. package/dist/types/src/settings/runtime.d.ts +145 -0
  177. package/dist/types/src/settings/runtime.d.ts.map +1 -0
  178. package/package.json +3 -2
  179. package/src/common-auth-embedded/commands/builtins.d.ts +20 -1
  180. package/src/common-auth-embedded/commands/builtins.js +28 -12
  181. package/src/common-auth-embedded/commands/index.d.ts +1 -1
  182. package/src/common-auth-embedded/commands/menu.d.ts +6 -1
  183. package/src/common-auth-embedded/commands/menu.js +1 -0
  184. package/src/common-auth-embedded/fs/file-read-cache.js +9 -5
  185. package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +11 -0
  186. package/src/common-auth-embedded/fs/refresh-file-lock.js +146 -2
  187. package/src/common-auth-embedded/fs/with-lock.d.ts +2 -0
  188. package/src/common-auth-embedded/fs/with-lock.js +1 -1
  189. package/src/common-auth-embedded/settings/define.d.ts +35 -0
  190. package/src/common-auth-embedded/settings/define.js +52 -0
  191. package/src/common-auth-embedded/settings/descriptors.d.ts +97 -0
  192. package/src/common-auth-embedded/settings/descriptors.js +81 -0
  193. package/src/common-auth-embedded/settings/edit.d.ts +24 -0
  194. package/src/common-auth-embedded/settings/edit.js +229 -0
  195. package/src/common-auth-embedded/settings/fs.js +19 -0
  196. package/src/common-auth-embedded/settings/handle.d.ts +30 -0
  197. package/src/common-auth-embedded/settings/handle.js +228 -0
  198. package/src/common-auth-embedded/settings/index.d.ts +10 -0
  199. package/src/common-auth-embedded/settings/index.js +7 -0
  200. package/src/common-auth-embedded/settings/lock-errors.js +15 -0
  201. package/src/common-auth-embedded/settings/move.d.ts +76 -0
  202. package/src/common-auth-embedded/settings/move.js +351 -0
  203. package/src/common-auth-embedded/settings/parse.d.ts +24 -0
  204. package/src/common-auth-embedded/settings/parse.js +65 -0
  205. package/src/common-auth-embedded/settings/paths.d.ts +12 -0
  206. package/src/common-auth-embedded/settings/paths.js +48 -0
  207. package/src/common-auth-embedded/settings/refusal.d.ts +7 -0
  208. package/src/common-auth-embedded/settings/refusal.js +15 -0
  209. package/src/common-auth-embedded/settings/resolve.d.ts +15 -0
  210. package/src/common-auth-embedded/settings/resolve.js +51 -0
  211. package/src/common-auth-embedded/settings/schema.d.ts +29 -0
  212. package/src/common-auth-embedded/settings/schema.js +81 -0
  213. package/src/common-auth-embedded/settings/snapshot.d.ts +24 -0
  214. package/src/common-auth-embedded/settings/snapshot.js +150 -0
  215. package/src/common-auth-embedded/settings/update.js +139 -0
  216. package/src/common-auth-embedded/settings/write.js +88 -0
  217. package/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  218. package/src/common-auth-embedded/setup/command-error.js +3 -2
  219. package/src/common-auth-embedded/setup/command.js +5 -1
  220. package/src/common-auth-embedded/setup/enroll.js +3 -3
  221. package/src/common-auth-embedded/setup/enrollment-access.js +13 -4
  222. package/src/common-auth-embedded/setup/types.d.ts +4 -0
  223. package/src/common-auth-embedded/source-output.json +291 -55
  224. package/src/common-auth-embedded/tui-prefs/watcher.js +196 -0
  225. package/src/tui-ga-compiled/host-ga.js +1 -1
  226. package/src/tui-ga-raw/host-ga.tsx +1 -1
package/dist/cli.js CHANGED
@@ -8772,8 +8772,8 @@ var init_lock_record = __esm({
8772
8772
 
8773
8773
  // ../core/dist/common-auth-embedded/fs/refresh-file-lock.js
8774
8774
  import { randomUUID as randomUUID7 } from "node:crypto";
8775
- import { link as link2, lstat as lstat3, mkdir as mkdir7, open as open4, readFile as readFile5, rename as rename6, rm as rm4, stat as stat3 } from "node:fs/promises";
8776
- import { dirname as dirname7, join as join5 } from "node:path";
8775
+ import { link as link2, lstat as lstat3, mkdir as mkdir7, open as open4, readdir, readFile as readFile5, rename as rename6, rm as rm4, stat as stat3, unlink as unlink6 } from "node:fs/promises";
8776
+ import { basename as basename3, dirname as dirname7, join as join5 } from "node:path";
8777
8777
  async function createExclusiveText(path2, text2) {
8778
8778
  const tempPath = `${path2}.${randomUUID7()}.tmp`;
8779
8779
  let handle;
@@ -8828,6 +8828,83 @@ async function writeExclusiveText(path2, text2) {
8828
8828
  await handle.close();
8829
8829
  }
8830
8830
  }
8831
+ function isStagingName(name, lockName) {
8832
+ const prefix = `${lockName}.`;
8833
+ const suffix = ".tmp";
8834
+ if (!name.startsWith(prefix) || !name.endsWith(suffix))
8835
+ return false;
8836
+ return STAGING_UUID.test(name.slice(prefix.length, -suffix.length));
8837
+ }
8838
+ function sameStagingFile(a, b) {
8839
+ return a.dev === b.dev && a.ino === b.ino && a.size === b.size && a.mtimeMs === b.mtimeMs && a.birthtimeMs === b.birthtimeMs;
8840
+ }
8841
+ async function readStagedOwner(path2) {
8842
+ const before = await lstat3(path2);
8843
+ if (!before.isFile() || before.isSymbolicLink())
8844
+ return void 0;
8845
+ if (before.size > STAGING_SWEEP_MAX_BYTES)
8846
+ return void 0;
8847
+ const handle = await open4(path2, "r");
8848
+ let text2;
8849
+ try {
8850
+ if (!sameStagingFile(before, await handle.stat()))
8851
+ return void 0;
8852
+ text2 = await handle.readFile("utf8");
8853
+ } finally {
8854
+ await handle.close();
8855
+ }
8856
+ let record3;
8857
+ try {
8858
+ record3 = JSON.parse(text2);
8859
+ } catch {
8860
+ return void 0;
8861
+ }
8862
+ if (!record3 || typeof record3 !== "object" || Array.isArray(record3))
8863
+ return void 0;
8864
+ const keys = Object.keys(record3).sort();
8865
+ if (keys.length !== 2 || keys[0] !== "expiresAt" || keys[1] !== "ownerId")
8866
+ return void 0;
8867
+ const { ownerId, expiresAt } = record3;
8868
+ if (typeof ownerId !== "string" || !STAGING_UUID.test(ownerId))
8869
+ return void 0;
8870
+ if (typeof expiresAt !== "number" || !Number.isFinite(expiresAt))
8871
+ return void 0;
8872
+ return { identity: before, expiresAt };
8873
+ }
8874
+ async function sweepAbandonedStaging(lockPath, ttlMs, now) {
8875
+ const directory = dirname7(lockPath);
8876
+ const lockName = basename3(lockPath);
8877
+ const hooks = stagingSweepTestHooks;
8878
+ const names = await (hooks?.readdir ?? readdir)(directory);
8879
+ const candidates = names.filter((name) => isStagingName(name, lockName)).slice(0, STAGING_SWEEP_MAX_CANDIDATES);
8880
+ const marginMs = Math.max(Number.isFinite(ttlMs) ? ttlMs : 0, STAGING_SWEEP_MIN_AGE_MS);
8881
+ for (const name of candidates) {
8882
+ const path2 = join5(directory, name);
8883
+ try {
8884
+ if (now() - (await lstat3(path2)).mtimeMs < marginMs)
8885
+ continue;
8886
+ const staged = await readStagedOwner(path2);
8887
+ if (!staged || !(staged.expiresAt < now() - marginMs))
8888
+ continue;
8889
+ if (hooks?.beforeUnlink)
8890
+ await hooks.beforeUnlink(path2);
8891
+ const current = await readStagedOwner(path2);
8892
+ if (!current || !sameStagingFile(staged.identity, current.identity) || !(current.expiresAt < now() - marginMs))
8893
+ continue;
8894
+ await (hooks?.unlink ?? unlink6)(path2);
8895
+ } catch {
8896
+ }
8897
+ }
8898
+ }
8899
+ function startStagingSweep(lockPath, ttlMs, now) {
8900
+ if (sweptLockPaths.has(lockPath))
8901
+ return;
8902
+ sweptLockPaths.add(lockPath);
8903
+ const sweep = Promise.resolve().then(() => sweepAbandonedStaging(lockPath, ttlMs, now)).catch(() => {
8904
+ });
8905
+ pendingStagingSweeps.add(sweep);
8906
+ void sweep.finally(() => pendingStagingSweeps.delete(sweep));
8907
+ }
8831
8908
  function isLostMarkerRaceError(error) {
8832
8909
  const code2 = error?.code;
8833
8910
  return code2 === "ENOENT" || !windowsPrivateFiles && (code2 === "EINVAL" || code2 === "ENOTDIR");
@@ -9520,6 +9597,7 @@ async function acquireRefreshFileLockWithClock(options) {
9520
9597
  return null;
9521
9598
  }
9522
9599
  scheduleRenewal();
9600
+ startStagingSweep(lockPath, options.ttlMs, now);
9523
9601
  return {
9524
9602
  ownerId,
9525
9603
  whenLost: () => lostPromise,
@@ -9626,13 +9704,19 @@ async function acquireRefreshFileLockWithClock(options) {
9626
9704
  }
9627
9705
  };
9628
9706
  }
9629
- var leaseCreationTestHooks, setRefreshLockRenewalTimeout, clearRefreshLockRenewalTimeout, evictionMarkerTestHooks, OWNERLESS_MARKER_GRACE_MS;
9707
+ var leaseCreationTestHooks, STAGING_UUID, STAGING_SWEEP_MIN_AGE_MS, STAGING_SWEEP_MAX_CANDIDATES, STAGING_SWEEP_MAX_BYTES, sweptLockPaths, pendingStagingSweeps, stagingSweepTestHooks, setRefreshLockRenewalTimeout, clearRefreshLockRenewalTimeout, evictionMarkerTestHooks, OWNERLESS_MARKER_GRACE_MS;
9630
9708
  var init_refresh_file_lock = __esm({
9631
9709
  "../core/dist/common-auth-embedded/fs/refresh-file-lock.js"() {
9632
9710
  "use strict";
9633
9711
  init_lock_record();
9634
9712
  init_private_files();
9635
9713
  init_with_lock();
9714
+ STAGING_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
9715
+ STAGING_SWEEP_MIN_AGE_MS = 10 * 6e4;
9716
+ STAGING_SWEEP_MAX_CANDIDATES = 256;
9717
+ STAGING_SWEEP_MAX_BYTES = 4096;
9718
+ sweptLockPaths = /* @__PURE__ */ new Set();
9719
+ pendingStagingSweeps = /* @__PURE__ */ new Set();
9636
9720
  setRefreshLockRenewalTimeout = globalThis.setTimeout.bind(globalThis);
9637
9721
  clearRefreshLockRenewalTimeout = globalThis.clearTimeout.bind(globalThis);
9638
9722
  OWNERLESS_MARKER_GRACE_MS = 1e3;
@@ -13498,9 +13582,9 @@ var init_refresh = __esm({
13498
13582
  // ../core/dist/common-auth-embedded/fs/file-read-cache.js
13499
13583
  import { lstat as lstat4, stat as stat4 } from "node:fs/promises";
13500
13584
  import { resolve as resolve6 } from "node:path";
13501
- async function identity(path2, followSymlinks) {
13585
+ async function identity(path2, probe) {
13502
13586
  try {
13503
- const metadata = await (followSymlinks ? stat4(path2) : lstat4(path2));
13587
+ const metadata = await probe(path2);
13504
13588
  return metadata.isFile() ? metadata : void 0;
13505
13589
  } catch (error) {
13506
13590
  return error.code === "ENOENT" ? "absent" : void 0;
@@ -13516,15 +13600,15 @@ var init_file_read_cache = __esm({
13516
13600
  "../core/dist/common-auth-embedded/fs/file-read-cache.js"() {
13517
13601
  "use strict";
13518
13602
  FileReadCache = class {
13519
- #followSymlinks;
13603
+ #probe;
13520
13604
  #entries = /* @__PURE__ */ new Map();
13521
13605
  constructor(options = {}) {
13522
- this.#followSymlinks = options.followSymlinks ?? false;
13606
+ this.#probe = options.followSymlinks ? (path2) => (options.stat ?? stat4)(path2) : (path2) => (options.lstat ?? lstat4)(path2);
13523
13607
  }
13524
13608
  async read(paths, read, validateHit) {
13525
13609
  const resolvedPaths = paths.map((path2) => resolve6(path2));
13526
13610
  const key = JSON.stringify(resolvedPaths);
13527
- const probed = await Promise.all(resolvedPaths.map((path2) => identity(path2, this.#followSymlinks)));
13611
+ const probed = await Promise.all(resolvedPaths.map((path2) => identity(path2, this.#probe)));
13528
13612
  const identities = probed.every((entry) => entry !== void 0) ? probed : void 0;
13529
13613
  const cached = this.#entries.get(key);
13530
13614
  if (identities && cached && identities.every((entry, index) => {
@@ -14627,15 +14711,30 @@ function addedText(name, result) {
14627
14711
  function failureMessage(error) {
14628
14712
  return projectFailure(error).text;
14629
14713
  }
14714
+ function settingsPort(options) {
14715
+ if (options.settings)
14716
+ return options.settings;
14717
+ const { store, extraLocks } = options;
14718
+ const locks = extraLocks ? { extraLocks } : {};
14719
+ return {
14720
+ async read() {
14721
+ const read = await store.readSettings();
14722
+ return read.status === "error" ? {} : read.settings;
14723
+ },
14724
+ async update(mutator) {
14725
+ await store.updateSettings(mutator, locks);
14726
+ }
14727
+ };
14728
+ }
14630
14729
  async function snapshot(options) {
14631
14730
  const { store } = options;
14632
14731
  const load = await store.read();
14633
- const read = await store.readSettings();
14732
+ const settings = await settingsPort(options).read();
14634
14733
  const vault = await options.routing?.vaultOrder?.();
14635
14734
  return {
14636
14735
  load,
14637
14736
  rows: distinctRows(load),
14638
- settings: read.status === "error" ? {} : read.settings,
14737
+ settings,
14639
14738
  ...vault ? { vault } : {}
14640
14739
  };
14641
14740
  }
@@ -14897,6 +14996,7 @@ function vaultNames(vault) {
14897
14996
  function routingSection(options, snap) {
14898
14997
  const { store, extraLocks } = options;
14899
14998
  const locks = extraLocks ? { extraLocks } : {};
14999
+ const port = settingsPort(options);
14900
15000
  const choices = [
14901
15001
  { value: "ordered", label: "Ordered (roster order)" },
14902
15002
  ...options.routing?.orderedVariants ?? [],
@@ -14925,10 +15025,10 @@ function routingSection(options, snap) {
14925
15025
  ],
14926
15026
  run: async ({ values }) => {
14927
15027
  const mode = String(values.mode);
14928
- await store.updateSettings((settings) => {
15028
+ await port.update((settings) => {
14929
15029
  settings.routing = { ...record(settings.routing), mode };
14930
15030
  return void 0;
14931
- }, locks);
15031
+ });
14932
15032
  return `Routing mode set to ${choices.find((choice) => choice.value === mode)?.label ?? mode}.`;
14933
15033
  }
14934
15034
  }
@@ -14981,13 +15081,13 @@ function routingSection(options, snap) {
14981
15081
  run: async ({ values }) => {
14982
15082
  const value = String(values.maxSameAccountWait);
14983
15083
  const maxSameAccountWait = value === "max" ? "max" : Number(value);
14984
- await store.updateSettings((settings) => {
15084
+ await port.update((settings) => {
14985
15085
  settings.routing = {
14986
15086
  ...record(settings.routing),
14987
15087
  maxSameAccountWait
14988
15088
  };
14989
15089
  return void 0;
14990
- }, locks);
15090
+ });
14991
15091
  return `${waitLabel} set to ${waitName(value)}.`;
14992
15092
  }
14993
15093
  });
@@ -15020,8 +15120,7 @@ function floorNames(options, snap) {
15020
15120
  return (label) => names.get(label) ?? label;
15021
15121
  }
15022
15122
  function limitsSection(options, snap) {
15023
- const { store, extraLocks } = options;
15024
- const locks = extraLocks ? { extraLocks } : {};
15123
+ const port = settingsPort(options);
15025
15124
  const killswitch = record(snap.settings.killswitch);
15026
15125
  const enabled = killswitch.enabled === true;
15027
15126
  const floors = record(killswitch.accounts);
@@ -15052,7 +15151,7 @@ function limitsSection(options, snap) {
15052
15151
  ...typeof own[label] === "number" ? { value: own[label] } : {}
15053
15152
  })),
15054
15153
  run: async ({ values }) => {
15055
- await store.updateSettings((settings) => {
15154
+ await port.update((settings) => {
15056
15155
  const next = record(settings.killswitch);
15057
15156
  const accounts = record(next.accounts);
15058
15157
  const mine = record(accounts[row.id]);
@@ -15073,7 +15172,7 @@ function limitsSection(options, snap) {
15073
15172
  delete next.accounts;
15074
15173
  settings.killswitch = next;
15075
15174
  return void 0;
15076
- }, locks);
15175
+ });
15077
15176
  return `Floors updated for ${name}.`;
15078
15177
  }
15079
15178
  }
@@ -15103,13 +15202,13 @@ function limitsSection(options, snap) {
15103
15202
  ],
15104
15203
  run: async ({ values }) => {
15105
15204
  const on = values.enabled === true;
15106
- await store.updateSettings((settings) => {
15205
+ await port.update((settings) => {
15107
15206
  settings.killswitch = {
15108
15207
  ...record(settings.killswitch),
15109
15208
  enabled: on
15110
15209
  };
15111
15210
  return void 0;
15112
- }, locks);
15211
+ });
15113
15212
  return `Killswitch ${on ? "on" : "off"}.`;
15114
15213
  }
15115
15214
  }
@@ -15247,6 +15346,7 @@ function createCommandMenu(options) {
15247
15346
  store,
15248
15347
  now,
15249
15348
  ...options.extraLocks ? { extraLocks: options.extraLocks } : {},
15349
+ ...options.settings ? { settings: options.settings } : {},
15250
15350
  ...options.accounts ? { accounts: options.accounts } : {},
15251
15351
  ...options.quota ? { quota: options.quota } : {},
15252
15352
  ...options.routing ? { routing: options.routing } : {},
@@ -17390,8 +17490,8 @@ var init_any_signal = __esm({
17390
17490
  // ../core/dist/common-auth-embedded/claustrum/enrollment.js
17391
17491
  import { createHash as createHash5, randomBytes as randomBytes2, randomUUID as randomUUID10 } from "node:crypto";
17392
17492
  import { constants as fsConstants } from "node:fs";
17393
- import { chmod as chmod2, mkdir as mkdir8, open as open6, readFile as readFile6, realpath as realpath3, rename as rename7, stat as stat5, unlink as unlink6 } from "node:fs/promises";
17394
- import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join7, resolve as resolve8 } from "node:path";
17493
+ import { chmod as chmod2, mkdir as mkdir8, open as open6, readFile as readFile6, realpath as realpath3, rename as rename7, stat as stat5, unlink as unlink7 } from "node:fs/promises";
17494
+ import { basename as basename4, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join7, resolve as resolve8 } from "node:path";
17395
17495
  import { ClaustrumCredentialError as ClaustrumCredentialError3, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
17396
17496
  function classifyEnrollmentError(error) {
17397
17497
  if (!(error instanceof ClaustrumCredentialError3))
@@ -17438,7 +17538,7 @@ function connectClaustrumEnrollmentClient(options) {
17438
17538
  }
17439
17539
  function getClaustrumEnrollmentPaths(tokenPath) {
17440
17540
  const extension = extname(tokenPath) || ".json";
17441
- const stem = basename3(tokenPath, extname(tokenPath));
17541
+ const stem = basename4(tokenPath, extname(tokenPath));
17442
17542
  return {
17443
17543
  statePath: join7(dirname9(tokenPath), `${stem}-state${extension}`),
17444
17544
  tokenPath
@@ -17690,7 +17790,7 @@ async function writeStateAtomic(path2, state, ancestorOptions = {}) {
17690
17790
  }
17691
17791
  if (windowsPrivateFiles)
17692
17792
  return writePrivateAtomic(path2, bytes);
17693
- const temporary = join7(parent, `.${basename3(path2)}.${process.pid}.${randomUUID10()}.tmp`);
17793
+ const temporary = join7(parent, `.${basename4(path2)}.${process.pid}.${randomUUID10()}.tmp`);
17694
17794
  let descriptor;
17695
17795
  let created = false;
17696
17796
  try {
@@ -17707,7 +17807,7 @@ async function writeStateAtomic(path2, state, ancestorOptions = {}) {
17707
17807
  await descriptor?.close().catch(() => {
17708
17808
  });
17709
17809
  if (created)
17710
- await unlink6(temporary).catch(() => {
17810
+ await unlink7(temporary).catch(() => {
17711
17811
  });
17712
17812
  }
17713
17813
  }
@@ -17844,7 +17944,7 @@ async function resetClaustrumEnrollmentState(paths, proposedName) {
17844
17944
  if (state.phase === "pending")
17845
17945
  return "refused-pending";
17846
17946
  await lock.assertOwned();
17847
- await unlink6(paths.statePath);
17947
+ await unlink7(paths.statePath);
17848
17948
  return "reset";
17849
17949
  } finally {
17850
17950
  await lock.release();
@@ -17852,7 +17952,7 @@ async function resetClaustrumEnrollmentState(paths, proposedName) {
17852
17952
  }
17853
17953
  async function removeIfPresent(path2) {
17854
17954
  try {
17855
- await unlink6(path2);
17955
+ await unlink7(path2);
17856
17956
  return true;
17857
17957
  } catch (error) {
17858
17958
  if (error.code === "ENOENT")
@@ -18089,7 +18189,7 @@ var init_enrollment = __esm({
18089
18189
  }
18090
18190
  if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE) {
18091
18191
  await lock.assertOwned();
18092
- await unlink6(this.#paths.statePath).catch((cause) => {
18192
+ await unlink7(this.#paths.statePath).catch((cause) => {
18093
18193
  if (cause.code !== "ENOENT")
18094
18194
  throw cause;
18095
18195
  });
@@ -20914,7 +21014,7 @@ var init_consumer = __esm({
20914
21014
  // ../core/dist/common-auth-embedded/claustrum/hub.js
20915
21015
  import { createHash as createHash7 } from "node:crypto";
20916
21016
  import { channel as channel2 } from "node:diagnostics_channel";
20917
- import { readdir, stat as stat7 } from "node:fs/promises";
21017
+ import { readdir as readdir2, stat as stat7 } from "node:fs/promises";
20918
21018
  import { dirname as dirname10, join as join8, resolve as resolve11 } from "node:path";
20919
21019
  function canonicalJson3(value, path2 = /* @__PURE__ */ new Set()) {
20920
21020
  if (value === null)
@@ -21648,7 +21748,7 @@ var init_hub = __esm({
21648
21748
  const name = `${entry.provider}.json`;
21649
21749
  const candidates = [join8(this.#generationDirectory, name)];
21650
21750
  try {
21651
- for (const key of await readdir(this.#generationDirectory))
21751
+ for (const key of await readdir2(this.#generationDirectory))
21652
21752
  if (key !== this.#key && FINGERPRINT.test(key))
21653
21753
  candidates.push(join8(this.#generationDirectory, key, name));
21654
21754
  } catch {
@@ -22230,7 +22330,7 @@ var init_lock = __esm({
22230
22330
  // ../core/dist/common-auth-embedded/pi-slot/slot.js
22231
22331
  import { createHash as createHash8 } from "node:crypto";
22232
22332
  import { constants as constants2 } from "node:fs";
22233
- import { lstat as lstat5, mkdir as mkdir10, open as open7, unlink as unlink7 } from "node:fs/promises";
22333
+ import { lstat as lstat5, mkdir as mkdir10, open as open7, unlink as unlink8 } from "node:fs/promises";
22234
22334
  import { dirname as dirname11, resolve as resolve12 } from "node:path";
22235
22335
  import { setTimeout as sleep2 } from "node:timers/promises";
22236
22336
  function rootSpans(text2) {
@@ -22508,7 +22608,7 @@ function createPiSlot(options, onStep, hooks) {
22508
22608
  }
22509
22609
  async function deleteStash(assertLock) {
22510
22610
  assertLock();
22511
- await unlink7(stashPath);
22611
+ await unlink8(stashPath);
22512
22612
  await syncDir(dirname11(stashPath));
22513
22613
  onStep?.("stash-deleted");
22514
22614
  }
@@ -23722,7 +23822,7 @@ var init_capture_sink2 = __esm({
23722
23822
 
23723
23823
  // src/common-auth-embedded/fs/private-files.js
23724
23824
  import { randomUUID as randomUUID11 } from "node:crypto";
23725
- import { lstat as lstat6, readFile as readFile7, rename as rename8, unlink as unlink8 } from "node:fs/promises";
23825
+ import { lstat as lstat6, readFile as readFile7, rename as rename8, unlink as unlink9 } from "node:fs/promises";
23726
23826
  import { tmpdir as tmpdir2 } from "node:os";
23727
23827
  import { dirname as dirname13, join as join10, resolve as resolve13 } from "node:path";
23728
23828
  function ioCode2(detail) {
@@ -23973,7 +24073,7 @@ async function writePrivateAtomic2(path2, bytes, options = {}) {
23973
24073
  Object.assign(error, outcome);
23974
24074
  if (created) {
23975
24075
  try {
23976
- await unlink8(stage);
24076
+ await unlink9(stage);
23977
24077
  } catch {
23978
24078
  error.orphanPath = stage;
23979
24079
  }
@@ -23983,7 +24083,7 @@ async function writePrivateAtomic2(path2, bytes, options = {}) {
23983
24083
  throw error;
23984
24084
  } finally {
23985
24085
  if (created)
23986
- await unlink8(stage).catch(() => {
24086
+ await unlink9(stage).catch(() => {
23987
24087
  });
23988
24088
  }
23989
24089
  }
@@ -24714,7 +24814,7 @@ var init_process_heartbeat = __esm({
24714
24814
  });
24715
24815
 
24716
24816
  // src/version-fence.ts
24717
- import { readdir as readdir2, readFile as readFile9, stat as stat9, unlink as unlink9 } from "node:fs/promises";
24817
+ import { readdir as readdir3, readFile as readFile9, stat as stat9, unlink as unlink10 } from "node:fs/promises";
24718
24818
  import { homedir as homedir3, uptime } from "node:os";
24719
24819
  import { join as join12 } from "node:path";
24720
24820
  function defaultStateHome() {
@@ -24782,7 +24882,7 @@ function pidFrom(name, pattern) {
24782
24882
  }
24783
24883
  async function list2(dir) {
24784
24884
  try {
24785
- return { ok: true, names: await readdir2(dir) };
24885
+ return { ok: true, names: await readdir3(dir) };
24786
24886
  } catch (error) {
24787
24887
  const code2 = error.code;
24788
24888
  if (code2 === "ENOENT") return { ok: true, names: [] };
@@ -24844,7 +24944,7 @@ async function staleRecord(path2, record3, boot, heartbeat) {
24844
24944
  if (heartbeat) {
24845
24945
  try {
24846
24946
  if (await readFile9(path2, "utf8") === record3.text) {
24847
- await unlink9(path2);
24947
+ await unlink10(path2);
24848
24948
  log5.debug("Removed stale pre-boot heartbeat", { path: path2 });
24849
24949
  }
24850
24950
  } catch {
@@ -25055,14 +25155,14 @@ import { createHash as createHash10 } from "node:crypto";
25055
25155
  import {
25056
25156
  chmod as chmod4,
25057
25157
  mkdir as mkdir12,
25058
- readdir as readdir3,
25158
+ readdir as readdir4,
25059
25159
  readFile as readFile10,
25060
25160
  rename as rename10,
25061
25161
  rmdir as rmdir2,
25062
25162
  stat as stat10,
25063
- unlink as unlink10
25163
+ unlink as unlink11
25064
25164
  } from "node:fs/promises";
25065
- import { basename as basename4, dirname as dirname15, join as join13, resolve as resolve16 } from "node:path";
25165
+ import { basename as basename5, dirname as dirname15, join as join13, resolve as resolve16 } from "node:path";
25066
25166
  function refusalMessage(stateDir, errorClass2) {
25067
25167
  if (errorClass2 === "ERR_PRIVATE_FILES_SECURITY")
25068
25168
  return `antigravity-auth cannot start: ${stateDir} is not a folder only your user can access, or it is a link, so the plugin will not use it (${errorClass2}). Replace it with a plain folder of your own, then restart OpenCode.`;
@@ -25111,7 +25211,7 @@ function errorClass(error) {
25111
25211
  function errorFile(error) {
25112
25212
  const { path: path2, stage } = error ?? {};
25113
25213
  return {
25114
- ...typeof path2 === "string" && path2 ? { file: basename4(path2) } : {},
25214
+ ...typeof path2 === "string" && path2 ? { file: basename5(path2) } : {},
25115
25215
  ...typeof stage === "string" && stage ? { stage } : {}
25116
25216
  };
25117
25217
  }
@@ -25482,9 +25582,9 @@ function storeFolder(anchor) {
25482
25582
  return `${anchor}.store`;
25483
25583
  }
25484
25584
  async function storeArtefacts(anchor) {
25485
- const names = await readdir3(dirname15(anchor)).catch(() => []);
25486
- const store = basename4(storeFolder(anchor));
25487
- const pool = basename4(anchor);
25585
+ const names = await readdir4(dirname15(anchor)).catch(() => []);
25586
+ const store = basename5(storeFolder(anchor));
25587
+ const pool = basename5(anchor);
25488
25588
  return names.filter(
25489
25589
  (name) => name === store || name.startsWith(`${pool}.store.`) || name.startsWith(pool) && name.endsWith(".tmp")
25490
25590
  ).length;
@@ -25498,7 +25598,7 @@ async function abandonUnpublishedStore(location, stateAnchor, log9) {
25498
25598
  await rename10(folder, archived).catch((error) => {
25499
25599
  if (error.code !== "ENOENT") throw error;
25500
25600
  });
25501
- await unlink10(accountStorePointerPath(stateAnchor)).catch(() => {
25601
+ await unlink11(accountStorePointerPath(stateAnchor)).catch(() => {
25502
25602
  });
25503
25603
  log9.info(
25504
25604
  "antigravity-auth set an unfinished account store aside before starting its move again",
@@ -25629,7 +25729,7 @@ async function writeStateHomeStoreForward(id, stateAnchor, configAnchor = legacy
25629
25729
  const forward = {
25630
25730
  schemaVersion: 2,
25631
25731
  id,
25632
- directoryBasename: basename4(storeFolder(stateAnchor)),
25732
+ directoryBasename: basename5(storeFolder(stateAnchor)),
25633
25733
  relocatedTo: { legacyPath: stateAnchor, id }
25634
25734
  };
25635
25735
  const fs3 = await loadCommonAuthFs();
@@ -25690,7 +25790,7 @@ async function moveFiles(location, files, markerPath, layoutLock, input) {
25690
25790
  for (const path2 of listed) {
25691
25791
  if (wanted.has(path2)) continue;
25692
25792
  await layoutLock.assertOwned();
25693
- await unlink10(path2).catch((error) => {
25793
+ await unlink11(path2).catch((error) => {
25694
25794
  if (error.code !== "ENOENT") throw error;
25695
25795
  });
25696
25796
  }
@@ -25829,7 +25929,7 @@ async function removeOldSignatureCache(location, path2, layoutLock, steps, log9)
25829
25929
  try {
25830
25930
  if (!await exists2(path2)) return;
25831
25931
  await beforeRemove(path2, layoutLock, steps);
25832
- await unlink10(path2);
25932
+ await unlink11(path2);
25833
25933
  } catch (error) {
25834
25934
  if (error?.code === "ENOENT") return;
25835
25935
  logOnce(
@@ -25932,7 +26032,7 @@ async function removeMovedVaultStateLeftover(vaultDir, accountFile) {
25932
26032
  if (!marker?.oldDir || marker.oldDir !== location.key) return;
25933
26033
  const leftover = vaultStateFile(files).old;
25934
26034
  if (!await isVaultShapedKeptState(files)) return;
25935
- await unlink10(leftover).catch((error) => {
26035
+ await unlink11(leftover).catch((error) => {
25936
26036
  if (error.code !== "ENOENT") throw error;
25937
26037
  });
25938
26038
  await rmdir2(files.vault.old).catch(() => {
@@ -25941,7 +26041,7 @@ async function removeMovedVaultStateLeftover(vaultDir, accountFile) {
25941
26041
  async function vaultFiles(dir) {
25942
26042
  let entries;
25943
26043
  try {
25944
- entries = await readdir3(dir, { withFileTypes: true });
26044
+ entries = await readdir4(dir, { withFileTypes: true });
25945
26045
  } catch (error) {
25946
26046
  const code2 = error.code;
25947
26047
  if (code2 === "ENOENT" || code2 === "ENOTDIR") return [];
@@ -26050,7 +26150,7 @@ function isWindowsSharingError(error, platform) {
26050
26150
  const code2 = error?.code;
26051
26151
  return platform === "win32" && (code2 === "EBUSY" || code2 === "EPERM" || code2 === "EACCES");
26052
26152
  }
26053
- async function unlinkIfIdentical(file, stateDir, guard, io = { platform: process.platform, readFile: readFile10, unlink: unlink10 }) {
26153
+ async function unlinkIfIdentical(file, stateDir, guard, io = { platform: process.platform, readFile: readFile10, unlink: unlink11 }) {
26054
26154
  const started = performance.now();
26055
26155
  for (const delay3 of SHARING_RETRY_DELAYS_MS) {
26056
26156
  if (delay3 > 0) await new Promise((done) => setTimeout(done, delay3));
@@ -26182,7 +26282,7 @@ async function writeManifest(stateDir, paths) {
26182
26282
  );
26183
26283
  }
26184
26284
  async function removeManifest(stateDir) {
26185
- await unlink10(join13(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE)).catch(
26285
+ await unlink11(join13(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE)).catch(
26186
26286
  (error) => {
26187
26287
  if (error.code !== "ENOENT") throw error;
26188
26288
  }
@@ -28647,16 +28747,16 @@ async function select2(terminal, items, options) {
28647
28747
  // src/common-auth-embedded/claustrum/enrollment.js
28648
28748
  import { createHash as createHash12, randomBytes as randomBytes3, randomUUID as randomUUID15 } from "node:crypto";
28649
28749
  import { constants as fsConstants2 } from "node:fs";
28650
- import { chmod as chmod5, mkdir as mkdir14, open as open10, readFile as readFile12, realpath as realpath4, rename as rename12, stat as stat13, unlink as unlink11 } from "node:fs/promises";
28651
- import { basename as basename5, dirname as dirname19, extname as extname2, isAbsolute as isAbsolute4, join as join18, resolve as resolve21 } from "node:path";
28750
+ import { chmod as chmod5, mkdir as mkdir14, open as open10, readFile as readFile12, realpath as realpath4, rename as rename12, stat as stat13, unlink as unlink13 } from "node:fs/promises";
28751
+ import { basename as basename7, dirname as dirname19, extname as extname2, isAbsolute as isAbsolute4, join as join18, resolve as resolve21 } from "node:path";
28652
28752
  import { ClaustrumCredentialError as ClaustrumCredentialError9, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
28653
28753
 
28654
28754
  // src/common-auth-embedded/fs/file-read-cache.js
28655
28755
  import { lstat as lstat7, stat as stat11 } from "node:fs/promises";
28656
28756
  import { resolve as resolve19 } from "node:path";
28657
- async function identity2(path2, followSymlinks) {
28757
+ async function identity2(path2, probe) {
28658
28758
  try {
28659
- const metadata = await (followSymlinks ? stat11(path2) : lstat7(path2));
28759
+ const metadata = await probe(path2);
28660
28760
  return metadata.isFile() ? metadata : void 0;
28661
28761
  } catch (error) {
28662
28762
  return error.code === "ENOENT" ? "absent" : void 0;
@@ -28668,15 +28768,15 @@ function sameIdentity2(left, right) {
28668
28768
  return left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
28669
28769
  }
28670
28770
  var FileReadCache2 = class {
28671
- #followSymlinks;
28771
+ #probe;
28672
28772
  #entries = /* @__PURE__ */ new Map();
28673
28773
  constructor(options = {}) {
28674
- this.#followSymlinks = options.followSymlinks ?? false;
28774
+ this.#probe = options.followSymlinks ? (path2) => (options.stat ?? stat11)(path2) : (path2) => (options.lstat ?? lstat7)(path2);
28675
28775
  }
28676
28776
  async read(paths, read, validateHit) {
28677
28777
  const resolvedPaths = paths.map((path2) => resolve19(path2));
28678
28778
  const key = JSON.stringify(resolvedPaths);
28679
- const probed = await Promise.all(resolvedPaths.map((path2) => identity2(path2, this.#followSymlinks)));
28779
+ const probed = await Promise.all(resolvedPaths.map((path2) => identity2(path2, this.#probe)));
28680
28780
  const identities = probed.every((entry) => entry !== void 0) ? probed : void 0;
28681
28781
  const cached = this.#entries.get(key);
28682
28782
  if (identities && cached && identities.every((entry, index) => {
@@ -28724,8 +28824,8 @@ init_private_files2();
28724
28824
 
28725
28825
  // src/common-auth-embedded/fs/refresh-file-lock.js
28726
28826
  import { randomUUID as randomUUID14 } from "node:crypto";
28727
- import { link as link3, lstat as lstat8, mkdir as mkdir13, open as open9, readFile as readFile11, rename as rename11, rm as rm6, stat as stat12 } from "node:fs/promises";
28728
- import { dirname as dirname18, join as join17 } from "node:path";
28827
+ import { link as link3, lstat as lstat8, mkdir as mkdir13, open as open9, readdir as readdir5, readFile as readFile11, rename as rename11, rm as rm6, stat as stat12, unlink as unlink12 } from "node:fs/promises";
28828
+ import { basename as basename6, dirname as dirname18, join as join17 } from "node:path";
28729
28829
 
28730
28830
  // src/common-auth-embedded/fs/lock-record.js
28731
28831
  init_private_files2();
@@ -28833,6 +28933,90 @@ async function writeExclusiveText2(path2, text2) {
28833
28933
  await handle.close();
28834
28934
  }
28835
28935
  }
28936
+ var STAGING_UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
28937
+ var STAGING_SWEEP_MIN_AGE_MS2 = 10 * 6e4;
28938
+ var STAGING_SWEEP_MAX_CANDIDATES2 = 256;
28939
+ var STAGING_SWEEP_MAX_BYTES2 = 4096;
28940
+ var sweptLockPaths2 = /* @__PURE__ */ new Set();
28941
+ var pendingStagingSweeps2 = /* @__PURE__ */ new Set();
28942
+ var stagingSweepTestHooks2;
28943
+ function isStagingName2(name, lockName) {
28944
+ const prefix = `${lockName}.`;
28945
+ const suffix = ".tmp";
28946
+ if (!name.startsWith(prefix) || !name.endsWith(suffix))
28947
+ return false;
28948
+ return STAGING_UUID2.test(name.slice(prefix.length, -suffix.length));
28949
+ }
28950
+ function sameStagingFile2(a, b) {
28951
+ return a.dev === b.dev && a.ino === b.ino && a.size === b.size && a.mtimeMs === b.mtimeMs && a.birthtimeMs === b.birthtimeMs;
28952
+ }
28953
+ async function readStagedOwner2(path2) {
28954
+ const before = await lstat8(path2);
28955
+ if (!before.isFile() || before.isSymbolicLink())
28956
+ return void 0;
28957
+ if (before.size > STAGING_SWEEP_MAX_BYTES2)
28958
+ return void 0;
28959
+ const handle = await open9(path2, "r");
28960
+ let text2;
28961
+ try {
28962
+ if (!sameStagingFile2(before, await handle.stat()))
28963
+ return void 0;
28964
+ text2 = await handle.readFile("utf8");
28965
+ } finally {
28966
+ await handle.close();
28967
+ }
28968
+ let record3;
28969
+ try {
28970
+ record3 = JSON.parse(text2);
28971
+ } catch {
28972
+ return void 0;
28973
+ }
28974
+ if (!record3 || typeof record3 !== "object" || Array.isArray(record3))
28975
+ return void 0;
28976
+ const keys = Object.keys(record3).sort();
28977
+ if (keys.length !== 2 || keys[0] !== "expiresAt" || keys[1] !== "ownerId")
28978
+ return void 0;
28979
+ const { ownerId, expiresAt } = record3;
28980
+ if (typeof ownerId !== "string" || !STAGING_UUID2.test(ownerId))
28981
+ return void 0;
28982
+ if (typeof expiresAt !== "number" || !Number.isFinite(expiresAt))
28983
+ return void 0;
28984
+ return { identity: before, expiresAt };
28985
+ }
28986
+ async function sweepAbandonedStaging2(lockPath, ttlMs, now) {
28987
+ const directory = dirname18(lockPath);
28988
+ const lockName = basename6(lockPath);
28989
+ const hooks = stagingSweepTestHooks2;
28990
+ const names = await (hooks?.readdir ?? readdir5)(directory);
28991
+ const candidates = names.filter((name) => isStagingName2(name, lockName)).slice(0, STAGING_SWEEP_MAX_CANDIDATES2);
28992
+ const marginMs = Math.max(Number.isFinite(ttlMs) ? ttlMs : 0, STAGING_SWEEP_MIN_AGE_MS2);
28993
+ for (const name of candidates) {
28994
+ const path2 = join17(directory, name);
28995
+ try {
28996
+ if (now() - (await lstat8(path2)).mtimeMs < marginMs)
28997
+ continue;
28998
+ const staged = await readStagedOwner2(path2);
28999
+ if (!staged || !(staged.expiresAt < now() - marginMs))
29000
+ continue;
29001
+ if (hooks?.beforeUnlink)
29002
+ await hooks.beforeUnlink(path2);
29003
+ const current = await readStagedOwner2(path2);
29004
+ if (!current || !sameStagingFile2(staged.identity, current.identity) || !(current.expiresAt < now() - marginMs))
29005
+ continue;
29006
+ await (hooks?.unlink ?? unlink12)(path2);
29007
+ } catch {
29008
+ }
29009
+ }
29010
+ }
29011
+ function startStagingSweep2(lockPath, ttlMs, now) {
29012
+ if (sweptLockPaths2.has(lockPath))
29013
+ return;
29014
+ sweptLockPaths2.add(lockPath);
29015
+ const sweep = Promise.resolve().then(() => sweepAbandonedStaging2(lockPath, ttlMs, now)).catch(() => {
29016
+ });
29017
+ pendingStagingSweeps2.add(sweep);
29018
+ void sweep.finally(() => pendingStagingSweeps2.delete(sweep));
29019
+ }
28836
29020
  var setRefreshLockRenewalTimeout2 = globalThis.setTimeout.bind(globalThis);
28837
29021
  var clearRefreshLockRenewalTimeout2 = globalThis.clearTimeout.bind(globalThis);
28838
29022
  function isLostMarkerRaceError2(error) {
@@ -29529,6 +29713,7 @@ async function acquireRefreshFileLockWithClock2(options) {
29529
29713
  return null;
29530
29714
  }
29531
29715
  scheduleRenewal();
29716
+ startStagingSweep2(lockPath, options.ttlMs, now);
29532
29717
  return {
29533
29718
  ownerId,
29534
29719
  whenLost: () => lostPromise,
@@ -29797,7 +29982,7 @@ function connectClaustrumEnrollmentClient2(options) {
29797
29982
  }
29798
29983
  function getClaustrumEnrollmentPaths2(tokenPath) {
29799
29984
  const extension = extname2(tokenPath) || ".json";
29800
- const stem = basename5(tokenPath, extname2(tokenPath));
29985
+ const stem = basename7(tokenPath, extname2(tokenPath));
29801
29986
  return {
29802
29987
  statePath: join18(dirname19(tokenPath), `${stem}-state${extension}`),
29803
29988
  tokenPath
@@ -30049,7 +30234,7 @@ async function writeStateAtomic2(path2, state, ancestorOptions = {}) {
30049
30234
  }
30050
30235
  if (windowsPrivateFiles2)
30051
30236
  return writePrivateAtomic2(path2, bytes);
30052
- const temporary = join18(parent, `.${basename5(path2)}.${process.pid}.${randomUUID15()}.tmp`);
30237
+ const temporary = join18(parent, `.${basename7(path2)}.${process.pid}.${randomUUID15()}.tmp`);
30053
30238
  let descriptor;
30054
30239
  let created = false;
30055
30240
  try {
@@ -30066,7 +30251,7 @@ async function writeStateAtomic2(path2, state, ancestorOptions = {}) {
30066
30251
  await descriptor?.close().catch(() => {
30067
30252
  });
30068
30253
  if (created)
30069
- await unlink11(temporary).catch(() => {
30254
+ await unlink13(temporary).catch(() => {
30070
30255
  });
30071
30256
  }
30072
30257
  }
@@ -30348,7 +30533,7 @@ var ClaustrumEnrollmentManager2 = class {
30348
30533
  }
30349
30534
  if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE2) {
30350
30535
  await lock.assertOwned();
30351
- await unlink11(this.#paths.statePath).catch((cause) => {
30536
+ await unlink13(this.#paths.statePath).catch((cause) => {
30352
30537
  if (cause.code !== "ENOENT")
30353
30538
  throw cause;
30354
30539
  });
@@ -30440,7 +30625,7 @@ async function resetClaustrumEnrollmentState2(paths, proposedName) {
30440
30625
  if (state.phase === "pending")
30441
30626
  return "refused-pending";
30442
30627
  await lock.assertOwned();
30443
- await unlink11(paths.statePath);
30628
+ await unlink13(paths.statePath);
30444
30629
  return "reset";
30445
30630
  } finally {
30446
30631
  await lock.release();
@@ -30603,11 +30788,17 @@ async function confirmEnrollmentAccess(client, status, tokenPath, configuredGran
30603
30788
  grantCommand: `ck auth grant --principal ${shellArgument(`enrolled:${status.approvedName}`)} --selector-kind ${grant.selector.exact === void 0 ? "category" : "exact"} --selector ${shellArgument(grant.selector.exact ?? grant.selector.category)} --operation ${grant.operation}`
30604
30789
  }
30605
30790
  }));
30791
+ const access = {
30792
+ grants,
30793
+ ...status.requestedGrantsStatus !== void 0 && {
30794
+ requestedGrantsStatus: status.requestedGrantsStatus
30795
+ }
30796
+ };
30606
30797
  if (status.requestedGrantsStatus === "dropped")
30607
- return { state: "older-vault", grants };
30798
+ return { ...access, state: "older-vault" };
30608
30799
  try {
30609
30800
  if (!client.listScoped)
30610
- return { state: "unconfirmed", grants };
30801
+ return { ...access, state: "unconfirmed" };
30611
30802
  const { token } = await readClaustrumEnrollmentToken2(tokenPath);
30612
30803
  const inventory = await client.listScoped(token);
30613
30804
  const confirmed = grants.map((entry) => ({
@@ -30615,6 +30806,7 @@ async function confirmEnrollmentAccess(client, status, tokenPath, configuredGran
30615
30806
  reachableLogins: inventory.rows.filter((row) => row.operations.includes(entry.grant.operation) && (entry.grant.selector.exact !== void 0 ? row.id === entry.grant.selector.exact : row.categories.includes(entry.grant.selector.category))).length
30616
30807
  }));
30617
30808
  return {
30809
+ ...access,
30618
30810
  state: confirmed.every((entry) => entry.reachableLogins > 0) ? "reachable" : confirmed.some((entry) => entry.reachableLogins > 0) ? "partial" : "no-logins",
30619
30811
  grants: confirmed.map((entry) => {
30620
30812
  if (entry.reachableLogins === 0)
@@ -30624,10 +30816,12 @@ async function confirmEnrollmentAccess(client, status, tokenPath, configuredGran
30624
30816
  })
30625
30817
  };
30626
30818
  } catch {
30627
- return { state: "unconfirmed", grants };
30819
+ return { ...access, state: "unconfirmed" };
30628
30820
  }
30629
30821
  }
30630
- function enrollmentAccessLines(access) {
30822
+ function enrollmentAccessLines(access, grantFallback = "setup") {
30823
+ if (grantFallback === "plugin" && access.requestedGrantsStatus !== "sent")
30824
+ return [];
30631
30825
  const lines = [];
30632
30826
  const remedy = access.grants.some((entry) => entry.grantCommand) ? "run:" : "check ck auth status for the approved name before granting access.";
30633
30827
  if (access.state === "older-vault")
@@ -30689,8 +30883,9 @@ var OUTCOME_TEXT = {
30689
30883
  "not-enrolled": "not connected",
30690
30884
  unknown: "unknown, check with ck auth status"
30691
30885
  };
30692
- function setupEnrollmentLine({ host, outcome, access }) {
30693
- return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}${access ? ` \u2014 ${enrollmentAccessLines(access).join("\n")}` : ""}`;
30886
+ function setupEnrollmentLine({ host, outcome, access }, grantFallback = "setup") {
30887
+ const lines = access ? enrollmentAccessLines(access, grantFallback) : [];
30888
+ return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}${lines.length ? ` \u2014 ${lines.join("\n")}` : ""}`;
30694
30889
  }
30695
30890
  var recordedEnrollment = /* @__PURE__ */ new WeakMap();
30696
30891
  function recordSetupEnrollment(failure, enrollment) {
@@ -31228,7 +31423,7 @@ function approveCommand(requestId, name) {
31228
31423
  async function connectSetupHost(plugin, host, io, terminal, fence) {
31229
31424
  if (hasVaultHost2())
31230
31425
  throw new Error(VAULT_HOST_CONNECT_REFUSAL2);
31231
- const { name, displayName, requestedGrants, paths: input } = plugin.vault.hosts[host];
31426
+ const { name, displayName, requestedGrants, grantFallback, paths: input } = plugin.vault.hosts[host];
31232
31427
  const paths = hostEnrollmentPaths2(input);
31233
31428
  await fence();
31234
31429
  const client = await (io.connect ?? connectClaustrumEnrollmentClient2)({
@@ -31261,7 +31456,7 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31261
31456
  printLine2(terminal, `Already connected as ${initial.approvedName ?? initial.proposedName}.`);
31262
31457
  const access = await confirmEnrollmentAccess(client, initial, paths.tokenPath, requestedGrants);
31263
31458
  if (access)
31264
- for (const line of enrollmentAccessLines(access))
31459
+ for (const line of enrollmentAccessLines(access, grantFallback))
31265
31460
  printLine2(terminal, line);
31266
31461
  return access;
31267
31462
  }
@@ -31277,7 +31472,7 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31277
31472
  printLine2(terminal, `Connected ${host} to Claustrum.`);
31278
31473
  const access = await confirmEnrollmentAccess(client, status, paths.tokenPath, requestedGrants);
31279
31474
  if (access)
31280
- for (const line of enrollmentAccessLines(access))
31475
+ for (const line of enrollmentAccessLines(access, grantFallback))
31281
31476
  printLine2(terminal, line);
31282
31477
  return access;
31283
31478
  }
@@ -31476,8 +31671,8 @@ import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2,
31476
31671
 
31477
31672
  // src/common-auth-embedded/setup/config-write.js
31478
31673
  import { randomUUID as randomUUID16 } from "node:crypto";
31479
- import { mkdir as mkdir15, open as open11, rename as rename13, stat as stat15, unlink as unlink12 } from "node:fs/promises";
31480
- import { basename as basename6, dirname as dirname20, join as join20 } from "node:path";
31674
+ import { mkdir as mkdir15, open as open11, rename as rename13, stat as stat15, unlink as unlink14 } from "node:fs/promises";
31675
+ import { basename as basename8, dirname as dirname20, join as join20 } from "node:path";
31481
31676
  import { setTimeout as delay2 } from "node:timers/promises";
31482
31677
  async function writeHostConfigAtomic(file, content, options = {}) {
31483
31678
  const windows = (options.platform ?? process.platform) === "win32";
@@ -31492,7 +31687,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
31492
31687
  throw error;
31493
31688
  }
31494
31689
  }
31495
- const stage = join20(parent, `.${basename6(file)}.${(options.stageName ?? randomUUID16)()}.tmp`);
31690
+ const stage = join20(parent, `.${basename8(file)}.${(options.stageName ?? randomUUID16)()}.tmp`);
31496
31691
  let created = false;
31497
31692
  try {
31498
31693
  const handle = await open11(stage, "wx", mode ?? 438);
@@ -31522,7 +31717,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
31522
31717
  }
31523
31718
  } finally {
31524
31719
  if (created)
31525
- await unlink12(stage).catch(() => {
31720
+ await unlink14(stage).catch(() => {
31526
31721
  });
31527
31722
  }
31528
31723
  }
@@ -31715,6 +31910,8 @@ function validatePlugin(plugin) {
31715
31910
  throw new Error("Setup requires lowercase vault names containing only letters, digits and dashes.");
31716
31911
  if (host.requestedGrants !== void 0 && !validEnrollmentRequestedGrants2(host.requestedGrants))
31717
31912
  throw new Error("invalid Claustrum enrollment requested grants");
31913
+ if (host.grantFallback !== void 0 && host.grantFallback !== "setup" && host.grantFallback !== "plugin")
31914
+ throw new Error("invalid Claustrum enrollment grant fallback");
31718
31915
  }
31719
31916
  }
31720
31917
  async function enrollmentReport(plugin, hosts, recorded, recordedAccess) {
@@ -31903,7 +32100,7 @@ ${write.content}`);
31903
32100
  const report = await enrollmentReport(plugin, hosts, enrollment, enrollmentAccess);
31904
32101
  recordSetupEnrollment(error, report);
31905
32102
  for (const entry of report)
31906
- printLine2(terminal, setupEnrollmentLine(entry));
32103
+ printLine2(terminal, setupEnrollmentLine(entry, plugin.vault.hosts[entry.host].grantFallback));
31907
32104
  } catch {
31908
32105
  }
31909
32106
  throw error;