@cortexkit/opencode-antigravity-auth 3.0.39 → 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 (262) hide show
  1. package/dist/cli.js +535 -112
  2. package/dist/cli.js.map +4 -4
  3. package/dist/cli.meta.json +67 -38
  4. package/dist/index.js +6899 -3288
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +1503 -465
  7. package/dist/server.js +7028 -3363
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +25 -4
  11. package/dist/src/common-auth-embedded/claustrum/enrollment.js +81 -4
  12. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  13. package/dist/src/common-auth-embedded/claustrum/index.js +1 -1
  14. package/dist/src/common-auth-embedded/commands/builtins.d.ts +20 -1
  15. package/dist/src/common-auth-embedded/commands/builtins.js +28 -12
  16. package/dist/src/common-auth-embedded/commands/index.d.ts +1 -1
  17. package/dist/src/common-auth-embedded/commands/menu.d.ts +6 -1
  18. package/dist/src/common-auth-embedded/commands/menu.js +1 -0
  19. package/dist/src/common-auth-embedded/fs/file-read-cache.js +9 -5
  20. package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +11 -0
  21. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +146 -2
  22. package/dist/src/common-auth-embedded/fs/with-lock.d.ts +2 -0
  23. package/dist/src/common-auth-embedded/fs/with-lock.js +1 -1
  24. package/dist/src/common-auth-embedded/settings/define.d.ts +35 -0
  25. package/dist/src/common-auth-embedded/settings/define.js +52 -0
  26. package/dist/src/common-auth-embedded/settings/descriptors.d.ts +97 -0
  27. package/dist/src/common-auth-embedded/settings/descriptors.js +81 -0
  28. package/dist/src/common-auth-embedded/settings/edit.d.ts +24 -0
  29. package/dist/src/common-auth-embedded/settings/edit.js +229 -0
  30. package/dist/src/common-auth-embedded/settings/fs.js +19 -0
  31. package/dist/src/common-auth-embedded/settings/handle.d.ts +30 -0
  32. package/dist/src/common-auth-embedded/settings/handle.js +228 -0
  33. package/dist/src/common-auth-embedded/settings/index.d.ts +10 -0
  34. package/dist/src/common-auth-embedded/settings/index.js +7 -0
  35. package/dist/src/common-auth-embedded/settings/lock-errors.js +15 -0
  36. package/dist/src/common-auth-embedded/settings/move.d.ts +76 -0
  37. package/dist/src/common-auth-embedded/settings/move.js +351 -0
  38. package/dist/src/common-auth-embedded/settings/parse.d.ts +24 -0
  39. package/dist/src/common-auth-embedded/settings/parse.js +65 -0
  40. package/dist/src/common-auth-embedded/settings/paths.d.ts +12 -0
  41. package/dist/src/common-auth-embedded/settings/paths.js +48 -0
  42. package/dist/src/common-auth-embedded/settings/refusal.d.ts +7 -0
  43. package/dist/src/common-auth-embedded/settings/refusal.js +15 -0
  44. package/dist/src/common-auth-embedded/settings/resolve.d.ts +15 -0
  45. package/dist/src/common-auth-embedded/settings/resolve.js +51 -0
  46. package/dist/src/common-auth-embedded/settings/schema.d.ts +29 -0
  47. package/dist/src/common-auth-embedded/settings/schema.js +81 -0
  48. package/dist/src/common-auth-embedded/settings/snapshot.d.ts +24 -0
  49. package/dist/src/common-auth-embedded/settings/snapshot.js +150 -0
  50. package/dist/src/common-auth-embedded/settings/update.js +139 -0
  51. package/dist/src/common-auth-embedded/settings/write.js +88 -0
  52. package/dist/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  53. package/dist/src/common-auth-embedded/setup/command-error.js +4 -2
  54. package/dist/src/common-auth-embedded/setup/command.js +23 -6
  55. package/dist/src/common-auth-embedded/setup/enroll.d.ts +2 -2
  56. package/dist/src/common-auth-embedded/setup/enroll.js +13 -3
  57. package/dist/src/common-auth-embedded/setup/enrollment-access.js +86 -0
  58. package/dist/src/common-auth-embedded/setup/index.d.ts +1 -1
  59. package/dist/src/common-auth-embedded/setup/types.d.ts +16 -1
  60. package/dist/src/common-auth-embedded/source-output.json +314 -70
  61. package/dist/src/common-auth-embedded/tui-prefs/watcher.js +196 -0
  62. package/dist/src/ga/tui/host-ga.js +1 -1
  63. package/dist/src/ga/tui/host-ga.js.map +1 -1
  64. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  65. package/dist/src/plugin/command-apply.d.ts +43 -3
  66. package/dist/src/plugin/command-apply.d.ts.map +1 -1
  67. package/dist/src/plugin/command-apply.js +92 -12
  68. package/dist/src/plugin/command-apply.js.map +1 -1
  69. package/dist/src/plugin/commands.d.ts +5 -1
  70. package/dist/src/plugin/commands.d.ts.map +1 -1
  71. package/dist/src/plugin/commands.js +4 -3
  72. package/dist/src/plugin/commands.js.map +1 -1
  73. package/dist/src/plugin/config/writer.d.ts +10 -3
  74. package/dist/src/plugin/config/writer.d.ts.map +1 -1
  75. package/dist/src/plugin/config/writer.js +30 -22
  76. package/dist/src/plugin/config/writer.js.map +1 -1
  77. package/dist/src/plugin/fetch-interceptor.d.ts +8 -3
  78. package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
  79. package/dist/src/plugin/fetch-interceptor.js +1 -0
  80. package/dist/src/plugin/fetch-interceptor.js.map +1 -1
  81. package/dist/src/plugin/ga-location-services.d.ts +3 -1
  82. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  83. package/dist/src/plugin/ga-location-services.js +35 -5
  84. package/dist/src/plugin/ga-location-services.js.map +1 -1
  85. package/dist/src/plugin/index.d.ts.map +1 -1
  86. package/dist/src/plugin/index.js +65 -15
  87. package/dist/src/plugin/index.js.map +1 -1
  88. package/dist/src/plugin/killswitch.d.ts +20 -0
  89. package/dist/src/plugin/killswitch.d.ts.map +1 -1
  90. package/dist/src/plugin/killswitch.js +14 -4
  91. package/dist/src/plugin/killswitch.js.map +1 -1
  92. package/dist/src/plugin/logger.d.ts +3 -1
  93. package/dist/src/plugin/logger.d.ts.map +1 -1
  94. package/dist/src/plugin/logger.js +15 -7
  95. package/dist/src/plugin/logger.js.map +1 -1
  96. package/dist/src/plugin/operator-settings.d.ts +6 -0
  97. package/dist/src/plugin/operator-settings.d.ts.map +1 -1
  98. package/dist/src/plugin/operator-settings.js.map +1 -1
  99. package/dist/src/plugin/request-helpers.d.ts +5 -0
  100. package/dist/src/plugin/request-helpers.d.ts.map +1 -1
  101. package/dist/src/plugin/request-helpers.js +11 -2
  102. package/dist/src/plugin/request-helpers.js.map +1 -1
  103. package/dist/src/plugin/shared/request-services.d.ts +10 -1
  104. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  105. package/dist/src/plugin/shared/request-services.js +125 -22
  106. package/dist/src/plugin/shared/request-services.js.map +1 -1
  107. package/dist/src/plugin/shared/runtime.d.ts +15 -0
  108. package/dist/src/plugin/shared/runtime.d.ts.map +1 -1
  109. package/dist/src/plugin/shared/runtime.js +43 -11
  110. package/dist/src/plugin/shared/runtime.js.map +1 -1
  111. package/dist/src/plugin/shared/vault-billing.d.ts +30 -0
  112. package/dist/src/plugin/shared/vault-billing.d.ts.map +1 -0
  113. package/dist/src/plugin/shared/vault-billing.js +196 -0
  114. package/dist/src/plugin/shared/vault-billing.js.map +1 -0
  115. package/dist/src/plugin/shared/vault-menu.d.ts +11 -1
  116. package/dist/src/plugin/shared/vault-menu.d.ts.map +1 -1
  117. package/dist/src/plugin/shared/vault-menu.js +33 -7
  118. package/dist/src/plugin/shared/vault-menu.js.map +1 -1
  119. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  120. package/dist/src/plugin/vault-custody.js +3 -0
  121. package/dist/src/plugin/vault-custody.js.map +1 -1
  122. package/dist/src/settings/core-settings.d.ts +7 -0
  123. package/dist/src/settings/core-settings.d.ts.map +1 -0
  124. package/dist/src/settings/core-settings.js +7 -0
  125. package/dist/src/settings/core-settings.js.map +1 -0
  126. package/dist/src/settings/legacy.d.ts +89 -0
  127. package/dist/src/settings/legacy.d.ts.map +1 -0
  128. package/dist/src/settings/legacy.js +184 -0
  129. package/dist/src/settings/legacy.js.map +1 -0
  130. package/dist/src/settings/location.d.ts +22 -0
  131. package/dist/src/settings/location.d.ts.map +1 -0
  132. package/dist/src/settings/location.js +49 -0
  133. package/dist/src/settings/location.js.map +1 -0
  134. package/dist/src/settings/move.d.ts +38 -0
  135. package/dist/src/settings/move.d.ts.map +1 -0
  136. package/dist/src/settings/move.js +83 -0
  137. package/dist/src/settings/move.js.map +1 -0
  138. package/dist/src/settings/protection.d.ts +11 -0
  139. package/dist/src/settings/protection.d.ts.map +1 -0
  140. package/dist/src/settings/protection.js +17 -0
  141. package/dist/src/settings/protection.js.map +1 -0
  142. package/dist/src/settings/report.d.ts +33 -0
  143. package/dist/src/settings/report.d.ts.map +1 -0
  144. package/dist/src/settings/report.js +103 -0
  145. package/dist/src/settings/report.js.map +1 -0
  146. package/dist/src/settings/runtime.d.ts +145 -0
  147. package/dist/src/settings/runtime.d.ts.map +1 -0
  148. package/dist/src/settings/runtime.js +697 -0
  149. package/dist/src/settings/runtime.js.map +1 -0
  150. package/dist/src/setup.d.ts.map +1 -1
  151. package/dist/src/setup.js +12 -0
  152. package/dist/src/setup.js.map +1 -1
  153. package/dist/tui-build-map.json +1 -1
  154. package/dist/tui-ga-build-map.json +5 -5
  155. package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +25 -4
  156. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  157. package/dist/types/src/common-auth-embedded/commands/builtins.d.ts +20 -1
  158. package/dist/types/src/common-auth-embedded/commands/index.d.ts +1 -1
  159. package/dist/types/src/common-auth-embedded/commands/menu.d.ts +6 -1
  160. package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +11 -0
  161. package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  162. package/dist/types/src/common-auth-embedded/setup/enroll.d.ts +2 -2
  163. package/dist/types/src/common-auth-embedded/setup/index.d.ts +1 -1
  164. package/dist/types/src/common-auth-embedded/setup/types.d.ts +16 -1
  165. package/dist/types/src/plugin/command-apply.d.ts +43 -3
  166. package/dist/types/src/plugin/command-apply.d.ts.map +1 -1
  167. package/dist/types/src/plugin/commands.d.ts +5 -1
  168. package/dist/types/src/plugin/commands.d.ts.map +1 -1
  169. package/dist/types/src/plugin/config/writer.d.ts +10 -3
  170. package/dist/types/src/plugin/config/writer.d.ts.map +1 -1
  171. package/dist/types/src/plugin/fetch-interceptor.d.ts +8 -3
  172. package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
  173. package/dist/types/src/plugin/ga-location-services.d.ts +3 -1
  174. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  175. package/dist/types/src/plugin/index.d.ts.map +1 -1
  176. package/dist/types/src/plugin/killswitch.d.ts +20 -0
  177. package/dist/types/src/plugin/killswitch.d.ts.map +1 -1
  178. package/dist/types/src/plugin/logger.d.ts +3 -1
  179. package/dist/types/src/plugin/logger.d.ts.map +1 -1
  180. package/dist/types/src/plugin/operator-settings.d.ts +6 -0
  181. package/dist/types/src/plugin/operator-settings.d.ts.map +1 -1
  182. package/dist/types/src/plugin/request-helpers.d.ts +5 -0
  183. package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
  184. package/dist/types/src/plugin/shared/request-services.d.ts +10 -1
  185. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  186. package/dist/types/src/plugin/shared/runtime.d.ts +15 -0
  187. package/dist/types/src/plugin/shared/runtime.d.ts.map +1 -1
  188. package/dist/types/src/plugin/shared/vault-billing.d.ts +30 -0
  189. package/dist/types/src/plugin/shared/vault-billing.d.ts.map +1 -0
  190. package/dist/types/src/plugin/shared/vault-menu.d.ts +11 -1
  191. package/dist/types/src/plugin/shared/vault-menu.d.ts.map +1 -1
  192. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  193. package/dist/types/src/settings/core-settings.d.ts +7 -0
  194. package/dist/types/src/settings/core-settings.d.ts.map +1 -0
  195. package/dist/types/src/settings/legacy.d.ts +89 -0
  196. package/dist/types/src/settings/legacy.d.ts.map +1 -0
  197. package/dist/types/src/settings/location.d.ts +22 -0
  198. package/dist/types/src/settings/location.d.ts.map +1 -0
  199. package/dist/types/src/settings/move.d.ts +38 -0
  200. package/dist/types/src/settings/move.d.ts.map +1 -0
  201. package/dist/types/src/settings/protection.d.ts +11 -0
  202. package/dist/types/src/settings/protection.d.ts.map +1 -0
  203. package/dist/types/src/settings/report.d.ts +33 -0
  204. package/dist/types/src/settings/report.d.ts.map +1 -0
  205. package/dist/types/src/settings/runtime.d.ts +145 -0
  206. package/dist/types/src/settings/runtime.d.ts.map +1 -0
  207. package/dist/types/src/setup.d.ts.map +1 -1
  208. package/package.json +4 -3
  209. package/src/common-auth-embedded/claustrum/enrollment.d.ts +25 -4
  210. package/src/common-auth-embedded/claustrum/enrollment.js +81 -4
  211. package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  212. package/src/common-auth-embedded/claustrum/index.js +1 -1
  213. package/src/common-auth-embedded/commands/builtins.d.ts +20 -1
  214. package/src/common-auth-embedded/commands/builtins.js +28 -12
  215. package/src/common-auth-embedded/commands/index.d.ts +1 -1
  216. package/src/common-auth-embedded/commands/menu.d.ts +6 -1
  217. package/src/common-auth-embedded/commands/menu.js +1 -0
  218. package/src/common-auth-embedded/fs/file-read-cache.js +9 -5
  219. package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +11 -0
  220. package/src/common-auth-embedded/fs/refresh-file-lock.js +146 -2
  221. package/src/common-auth-embedded/fs/with-lock.d.ts +2 -0
  222. package/src/common-auth-embedded/fs/with-lock.js +1 -1
  223. package/src/common-auth-embedded/settings/define.d.ts +35 -0
  224. package/src/common-auth-embedded/settings/define.js +52 -0
  225. package/src/common-auth-embedded/settings/descriptors.d.ts +97 -0
  226. package/src/common-auth-embedded/settings/descriptors.js +81 -0
  227. package/src/common-auth-embedded/settings/edit.d.ts +24 -0
  228. package/src/common-auth-embedded/settings/edit.js +229 -0
  229. package/src/common-auth-embedded/settings/fs.js +19 -0
  230. package/src/common-auth-embedded/settings/handle.d.ts +30 -0
  231. package/src/common-auth-embedded/settings/handle.js +228 -0
  232. package/src/common-auth-embedded/settings/index.d.ts +10 -0
  233. package/src/common-auth-embedded/settings/index.js +7 -0
  234. package/src/common-auth-embedded/settings/lock-errors.js +15 -0
  235. package/src/common-auth-embedded/settings/move.d.ts +76 -0
  236. package/src/common-auth-embedded/settings/move.js +351 -0
  237. package/src/common-auth-embedded/settings/parse.d.ts +24 -0
  238. package/src/common-auth-embedded/settings/parse.js +65 -0
  239. package/src/common-auth-embedded/settings/paths.d.ts +12 -0
  240. package/src/common-auth-embedded/settings/paths.js +48 -0
  241. package/src/common-auth-embedded/settings/refusal.d.ts +7 -0
  242. package/src/common-auth-embedded/settings/refusal.js +15 -0
  243. package/src/common-auth-embedded/settings/resolve.d.ts +15 -0
  244. package/src/common-auth-embedded/settings/resolve.js +51 -0
  245. package/src/common-auth-embedded/settings/schema.d.ts +29 -0
  246. package/src/common-auth-embedded/settings/schema.js +81 -0
  247. package/src/common-auth-embedded/settings/snapshot.d.ts +24 -0
  248. package/src/common-auth-embedded/settings/snapshot.js +150 -0
  249. package/src/common-auth-embedded/settings/update.js +139 -0
  250. package/src/common-auth-embedded/settings/write.js +88 -0
  251. package/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  252. package/src/common-auth-embedded/setup/command-error.js +4 -2
  253. package/src/common-auth-embedded/setup/command.js +23 -6
  254. package/src/common-auth-embedded/setup/enroll.d.ts +2 -2
  255. package/src/common-auth-embedded/setup/enroll.js +13 -3
  256. package/src/common-auth-embedded/setup/enrollment-access.js +86 -0
  257. package/src/common-auth-embedded/setup/index.d.ts +1 -1
  258. package/src/common-auth-embedded/setup/types.d.ts +16 -1
  259. package/src/common-auth-embedded/source-output.json +314 -70
  260. package/src/common-auth-embedded/tui-prefs/watcher.js +196 -0
  261. package/src/tui-ga-compiled/host-ga.js +1 -1
  262. 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))
@@ -17414,12 +17514,31 @@ function validEnrollmentDisplayName(displayName) {
17414
17514
  const length = Array.from(displayName).length;
17415
17515
  return length >= 1 && length <= 40 && !/[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u200b-\u200d\u2060\ufeff]/u.test(displayName);
17416
17516
  }
17517
+ function validEnrollmentRequestedGrants(grants) {
17518
+ return Array.isArray(grants) && grants.length >= 1 && grants.length <= 4 && Array.from(grants).every((grant) => {
17519
+ if (!isRecord6(grant) || Object.keys(grant).length !== 2 || grant.operation !== "read" && grant.operation !== "list" || !isRecord6(grant.selector))
17520
+ return false;
17521
+ const keys = Object.keys(grant.selector);
17522
+ const key = keys[0];
17523
+ return keys.length === 1 && (key === "category" || key === "exact") && typeof grant.selector[key] === "string" && grant.selector[key].trim().length > 0;
17524
+ });
17525
+ }
17526
+ function grantProposal(state) {
17527
+ return {
17528
+ ...state.requestedGrants !== void 0 && {
17529
+ requestedGrants: state.requestedGrants
17530
+ },
17531
+ ...state.requestedGrantsStatus !== void 0 && {
17532
+ requestedGrantsStatus: state.requestedGrantsStatus
17533
+ }
17534
+ };
17535
+ }
17417
17536
  function connectClaustrumEnrollmentClient(options) {
17418
17537
  return ClaustrumWireClient.connect(options);
17419
17538
  }
17420
17539
  function getClaustrumEnrollmentPaths(tokenPath) {
17421
17540
  const extension = extname(tokenPath) || ".json";
17422
- const stem = basename3(tokenPath, extname(tokenPath));
17541
+ const stem = basename4(tokenPath, extname(tokenPath));
17423
17542
  return {
17424
17543
  statePath: join7(dirname9(tokenPath), `${stem}-state${extension}`),
17425
17544
  tokenPath
@@ -17449,6 +17568,7 @@ function decodeEnrollmentState(value) {
17449
17568
  throw invalidState();
17450
17569
  }
17451
17570
  if (value.phase === "pending") {
17571
+ const grants = decodeGrantProposal(value);
17452
17572
  if (!TOKEN_RE.test(String(value.requestSecret ?? "")) || value.requestId !== void 0 && (typeof value.requestId !== "string" || value.requestId.length === 0) || !validTimestamp(value.createdAt) || !validTimestamp(value.updatedAt)) {
17453
17573
  throw invalidState();
17454
17574
  }
@@ -17461,10 +17581,12 @@ function decodeEnrollmentState(value) {
17461
17581
  requestId: value.requestId
17462
17582
  },
17463
17583
  createdAt: value.createdAt,
17464
- updatedAt: value.updatedAt
17584
+ updatedAt: value.updatedAt,
17585
+ ...grants
17465
17586
  };
17466
17587
  }
17467
17588
  if (value.phase === "approved") {
17589
+ const grants = decodeGrantProposal(value);
17468
17590
  if (value.approvedName !== void 0 && (typeof value.approvedName !== "string" || value.approvedName.length === 0) || !validGeneration(value.tokenGeneration) || !validTimestamp(value.updatedAt)) {
17469
17591
  throw invalidState();
17470
17592
  }
@@ -17476,7 +17598,8 @@ function decodeEnrollmentState(value) {
17476
17598
  approvedName: value.approvedName
17477
17599
  },
17478
17600
  tokenGeneration: value.tokenGeneration,
17479
- updatedAt: value.updatedAt
17601
+ updatedAt: value.updatedAt,
17602
+ ...grants
17480
17603
  };
17481
17604
  }
17482
17605
  if (value.phase === "denied" || value.phase === "blocked") {
@@ -17495,6 +17618,11 @@ function decodeEnrollmentState(value) {
17495
17618
  }
17496
17619
  throw invalidState();
17497
17620
  }
17621
+ function decodeGrantProposal(value) {
17622
+ if (value.requestedGrants !== void 0 && !validEnrollmentRequestedGrants(value.requestedGrants) || value.requestedGrantsStatus !== void 0 && (value.requestedGrants === void 0 || value.requestedGrantsStatus !== "sent" && value.requestedGrantsStatus !== "dropped"))
17623
+ return {};
17624
+ return grantProposal(value);
17625
+ }
17498
17626
  function decodeTokenFile(value) {
17499
17627
  if (!isRecord6(value) || !TOKEN_RE.test(String(value.token ?? "")) || !validGeneration(value.token_generation)) {
17500
17628
  throw new ClaustrumConsumerError("invalid-token", "invalid Claustrum enrollment token file");
@@ -17662,7 +17790,7 @@ async function writeStateAtomic(path2, state, ancestorOptions = {}) {
17662
17790
  }
17663
17791
  if (windowsPrivateFiles)
17664
17792
  return writePrivateAtomic(path2, bytes);
17665
- const temporary = join7(parent, `.${basename3(path2)}.${process.pid}.${randomUUID10()}.tmp`);
17793
+ const temporary = join7(parent, `.${basename4(path2)}.${process.pid}.${randomUUID10()}.tmp`);
17666
17794
  let descriptor;
17667
17795
  let created = false;
17668
17796
  try {
@@ -17679,7 +17807,7 @@ async function writeStateAtomic(path2, state, ancestorOptions = {}) {
17679
17807
  await descriptor?.close().catch(() => {
17680
17808
  });
17681
17809
  if (created)
17682
- await unlink6(temporary).catch(() => {
17810
+ await unlink7(temporary).catch(() => {
17683
17811
  });
17684
17812
  }
17685
17813
  }
@@ -17708,7 +17836,8 @@ async function readEnrollmentStatus(paths, proposedName) {
17708
17836
  ...state?.phase === "approved" && state.approvedName !== void 0 && {
17709
17837
  approvedName: state.approvedName
17710
17838
  },
17711
- tokenGeneration: token.token_generation
17839
+ tokenGeneration: token.token_generation,
17840
+ ...state && (state.phase === "approved" || state.phase === "pending") && grantProposal(state)
17712
17841
  }
17713
17842
  };
17714
17843
  }
@@ -17767,7 +17896,8 @@ function statusFromState(state) {
17767
17896
  return {
17768
17897
  state: "pending",
17769
17898
  proposedName: state.proposedName,
17770
- ...state.requestId !== void 0 && { requestId: state.requestId }
17899
+ ...state.requestId !== void 0 && { requestId: state.requestId },
17900
+ ...grantProposal(state)
17771
17901
  };
17772
17902
  }
17773
17903
  if (state.phase === "approved") {
@@ -17777,7 +17907,8 @@ function statusFromState(state) {
17777
17907
  ...state.approvedName !== void 0 && {
17778
17908
  approvedName: state.approvedName
17779
17909
  },
17780
- tokenGeneration: state.tokenGeneration
17910
+ tokenGeneration: state.tokenGeneration,
17911
+ ...grantProposal(state)
17781
17912
  };
17782
17913
  }
17783
17914
  if (state.phase === "denied")
@@ -17813,7 +17944,7 @@ async function resetClaustrumEnrollmentState(paths, proposedName) {
17813
17944
  if (state.phase === "pending")
17814
17945
  return "refused-pending";
17815
17946
  await lock.assertOwned();
17816
- await unlink6(paths.statePath);
17947
+ await unlink7(paths.statePath);
17817
17948
  return "reset";
17818
17949
  } finally {
17819
17950
  await lock.release();
@@ -17821,7 +17952,7 @@ async function resetClaustrumEnrollmentState(paths, proposedName) {
17821
17952
  }
17822
17953
  async function removeIfPresent(path2) {
17823
17954
  try {
17824
- await unlink6(path2);
17955
+ await unlink7(path2);
17825
17956
  return true;
17826
17957
  } catch (error) {
17827
17958
  if (error.code === "ENOENT")
@@ -17897,6 +18028,7 @@ var init_enrollment = __esm({
17897
18028
  #paths;
17898
18029
  #proposedName;
17899
18030
  #displayName;
18031
+ #requestedGrants;
17900
18032
  #now;
17901
18033
  #mintSecret;
17902
18034
  #writeTokenFile;
@@ -17904,6 +18036,12 @@ var init_enrollment = __esm({
17904
18036
  constructor(options) {
17905
18037
  if (options.displayName !== void 0 && !validEnrollmentDisplayName(options.displayName))
17906
18038
  throw new ClaustrumConsumerError("invalid-state", "invalid Claustrum enrollment display name");
18039
+ if (options.requestedGrants !== void 0 && !validEnrollmentRequestedGrants(options.requestedGrants))
18040
+ throw new ClaustrumConsumerError("invalid-state", "invalid Claustrum enrollment requested grants");
18041
+ this.#requestedGrants = options.requestedGrants?.map((grant) => ({
18042
+ selector: { ...grant.selector },
18043
+ operation: grant.operation
18044
+ }));
17907
18045
  this.#ancestorOptions = options.ancestorOptions ?? {};
17908
18046
  this.#client = options.client;
17909
18047
  this.#paths = options.paths;
@@ -17954,6 +18092,7 @@ var init_enrollment = __esm({
17954
18092
  phase: "approved",
17955
18093
  proposedName: state?.proposedName ?? this.#proposedName,
17956
18094
  tokenGeneration: token.token_generation,
18095
+ ...state && grantProposal(state),
17957
18096
  updatedAt: this.#now()
17958
18097
  };
17959
18098
  await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -17965,7 +18104,8 @@ var init_enrollment = __esm({
17965
18104
  ...state.phase === "approved" && state.approvedName !== void 0 && {
17966
18105
  approvedName: state.approvedName
17967
18106
  },
17968
- tokenGeneration: token.token_generation
18107
+ tokenGeneration: token.token_generation,
18108
+ ...state.phase === "approved" && grantProposal(state)
17969
18109
  };
17970
18110
  }
17971
18111
  if (state?.phase === "approved") {
@@ -17989,7 +18129,10 @@ var init_enrollment = __esm({
17989
18129
  proposedName: this.#proposedName,
17990
18130
  requestSecret: this.#mintSecret(),
17991
18131
  createdAt: now,
17992
- updatedAt: now
18132
+ updatedAt: now,
18133
+ ...this.#requestedGrants !== void 0 && {
18134
+ requestedGrants: this.#requestedGrants
18135
+ }
17993
18136
  };
17994
18137
  if (!TOKEN_RE.test(state.requestSecret))
17995
18138
  throw new ClaustrumConsumerError("invalid-state", "invalid minted Claustrum enrollment secret");
@@ -18003,22 +18146,33 @@ var init_enrollment = __esm({
18003
18146
  requestSecretHash
18004
18147
  };
18005
18148
  let proposed;
18149
+ let requestedGrantsStatus = state.requestedGrantsStatus;
18006
18150
  try {
18007
18151
  proposed = await this.#client.enrollPropose({
18008
18152
  ...proposal,
18009
18153
  ...this.#displayName !== void 0 && {
18010
18154
  displayName: this.#displayName
18155
+ },
18156
+ ...state.requestedGrants !== void 0 && {
18157
+ requestedGrants: state.requestedGrants
18011
18158
  }
18012
18159
  });
18160
+ if (state.requestedGrants !== void 0)
18161
+ requestedGrantsStatus = "sent";
18013
18162
  } catch (error) {
18014
- if (this.#displayName === void 0 || !(error instanceof ClaustrumCredentialError3) || error.code !== "invalid_params")
18163
+ if (this.#displayName === void 0 && state.requestedGrants === void 0 || !(error instanceof ClaustrumCredentialError3) || error.code !== "invalid_params")
18015
18164
  throw error;
18016
18165
  proposed = await this.#client.enrollPropose(proposal);
18166
+ if (state.requestedGrants !== void 0)
18167
+ requestedGrantsStatus = "dropped";
18017
18168
  }
18018
18169
  state = {
18019
18170
  ...state,
18020
18171
  requestId: proposed.requestId,
18021
- updatedAt: this.#now()
18172
+ updatedAt: this.#now(),
18173
+ ...requestedGrantsStatus !== void 0 && {
18174
+ requestedGrantsStatus
18175
+ }
18022
18176
  };
18023
18177
  await writeStateAtomic(this.#paths.statePath, state, this.#ancestorOptions);
18024
18178
  } catch (error) {
@@ -18029,12 +18183,13 @@ var init_enrollment = __esm({
18029
18183
  return {
18030
18184
  state: "pending",
18031
18185
  proposedName: state.proposedName,
18032
- retryCode: refusal3.code
18186
+ retryCode: refusal3.code,
18187
+ ...grantProposal(state)
18033
18188
  };
18034
18189
  }
18035
18190
  if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE) {
18036
18191
  await lock.assertOwned();
18037
- await unlink6(this.#paths.statePath).catch((cause) => {
18192
+ await unlink7(this.#paths.statePath).catch((cause) => {
18038
18193
  if (cause.code !== "ENOENT")
18039
18194
  throw cause;
18040
18195
  });
@@ -18079,6 +18234,7 @@ var init_enrollment = __esm({
18079
18234
  proposedName: state.proposedName,
18080
18235
  approvedName: outcome.name,
18081
18236
  tokenGeneration: outcome.tokenGeneration,
18237
+ ...grantProposal(state),
18082
18238
  updatedAt: this.#now()
18083
18239
  };
18084
18240
  await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -18092,7 +18248,8 @@ var init_enrollment = __esm({
18092
18248
  state: "pending",
18093
18249
  proposedName: state.proposedName,
18094
18250
  requestId,
18095
- retryCode: refusal3.code
18251
+ retryCode: refusal3.code,
18252
+ ...grantProposal(state)
18096
18253
  };
18097
18254
  }
18098
18255
  return this.#block(state, refusal3.code);
@@ -20857,7 +21014,7 @@ var init_consumer = __esm({
20857
21014
  // ../core/dist/common-auth-embedded/claustrum/hub.js
20858
21015
  import { createHash as createHash7 } from "node:crypto";
20859
21016
  import { channel as channel2 } from "node:diagnostics_channel";
20860
- import { readdir, stat as stat7 } from "node:fs/promises";
21017
+ import { readdir as readdir2, stat as stat7 } from "node:fs/promises";
20861
21018
  import { dirname as dirname10, join as join8, resolve as resolve11 } from "node:path";
20862
21019
  function canonicalJson3(value, path2 = /* @__PURE__ */ new Set()) {
20863
21020
  if (value === null)
@@ -21591,7 +21748,7 @@ var init_hub = __esm({
21591
21748
  const name = `${entry.provider}.json`;
21592
21749
  const candidates = [join8(this.#generationDirectory, name)];
21593
21750
  try {
21594
- for (const key of await readdir(this.#generationDirectory))
21751
+ for (const key of await readdir2(this.#generationDirectory))
21595
21752
  if (key !== this.#key && FINGERPRINT.test(key))
21596
21753
  candidates.push(join8(this.#generationDirectory, key, name));
21597
21754
  } catch {
@@ -21917,6 +22074,7 @@ __export(claustrum_exports, {
21917
22074
  resetClaustrumEnrollmentState: () => resetClaustrumEnrollmentState,
21918
22075
  resolveVaultPrimary: () => resolveVaultPrimary,
21919
22076
  validEnrollmentDisplayName: () => validEnrollmentDisplayName,
22077
+ validEnrollmentRequestedGrants: () => validEnrollmentRequestedGrants,
21920
22078
  vaultAuthority: () => vaultAuthority,
21921
22079
  vaultRosterSeed: () => vaultRosterSeed,
21922
22080
  vaultRoutingRows: () => vaultRoutingRows
@@ -22172,7 +22330,7 @@ var init_lock = __esm({
22172
22330
  // ../core/dist/common-auth-embedded/pi-slot/slot.js
22173
22331
  import { createHash as createHash8 } from "node:crypto";
22174
22332
  import { constants as constants2 } from "node:fs";
22175
- 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";
22176
22334
  import { dirname as dirname11, resolve as resolve12 } from "node:path";
22177
22335
  import { setTimeout as sleep2 } from "node:timers/promises";
22178
22336
  function rootSpans(text2) {
@@ -22450,7 +22608,7 @@ function createPiSlot(options, onStep, hooks) {
22450
22608
  }
22451
22609
  async function deleteStash(assertLock) {
22452
22610
  assertLock();
22453
- await unlink7(stashPath);
22611
+ await unlink8(stashPath);
22454
22612
  await syncDir(dirname11(stashPath));
22455
22613
  onStep?.("stash-deleted");
22456
22614
  }
@@ -23664,7 +23822,7 @@ var init_capture_sink2 = __esm({
23664
23822
 
23665
23823
  // src/common-auth-embedded/fs/private-files.js
23666
23824
  import { randomUUID as randomUUID11 } from "node:crypto";
23667
- 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";
23668
23826
  import { tmpdir as tmpdir2 } from "node:os";
23669
23827
  import { dirname as dirname13, join as join10, resolve as resolve13 } from "node:path";
23670
23828
  function ioCode2(detail) {
@@ -23915,7 +24073,7 @@ async function writePrivateAtomic2(path2, bytes, options = {}) {
23915
24073
  Object.assign(error, outcome);
23916
24074
  if (created) {
23917
24075
  try {
23918
- await unlink8(stage);
24076
+ await unlink9(stage);
23919
24077
  } catch {
23920
24078
  error.orphanPath = stage;
23921
24079
  }
@@ -23925,7 +24083,7 @@ async function writePrivateAtomic2(path2, bytes, options = {}) {
23925
24083
  throw error;
23926
24084
  } finally {
23927
24085
  if (created)
23928
- await unlink8(stage).catch(() => {
24086
+ await unlink9(stage).catch(() => {
23929
24087
  });
23930
24088
  }
23931
24089
  }
@@ -24656,7 +24814,7 @@ var init_process_heartbeat = __esm({
24656
24814
  });
24657
24815
 
24658
24816
  // src/version-fence.ts
24659
- 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";
24660
24818
  import { homedir as homedir3, uptime } from "node:os";
24661
24819
  import { join as join12 } from "node:path";
24662
24820
  function defaultStateHome() {
@@ -24724,7 +24882,7 @@ function pidFrom(name, pattern) {
24724
24882
  }
24725
24883
  async function list2(dir) {
24726
24884
  try {
24727
- return { ok: true, names: await readdir2(dir) };
24885
+ return { ok: true, names: await readdir3(dir) };
24728
24886
  } catch (error) {
24729
24887
  const code2 = error.code;
24730
24888
  if (code2 === "ENOENT") return { ok: true, names: [] };
@@ -24786,7 +24944,7 @@ async function staleRecord(path2, record3, boot, heartbeat) {
24786
24944
  if (heartbeat) {
24787
24945
  try {
24788
24946
  if (await readFile9(path2, "utf8") === record3.text) {
24789
- await unlink9(path2);
24947
+ await unlink10(path2);
24790
24948
  log5.debug("Removed stale pre-boot heartbeat", { path: path2 });
24791
24949
  }
24792
24950
  } catch {
@@ -24997,14 +25155,14 @@ import { createHash as createHash10 } from "node:crypto";
24997
25155
  import {
24998
25156
  chmod as chmod4,
24999
25157
  mkdir as mkdir12,
25000
- readdir as readdir3,
25158
+ readdir as readdir4,
25001
25159
  readFile as readFile10,
25002
25160
  rename as rename10,
25003
25161
  rmdir as rmdir2,
25004
25162
  stat as stat10,
25005
- unlink as unlink10
25163
+ unlink as unlink11
25006
25164
  } from "node:fs/promises";
25007
- 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";
25008
25166
  function refusalMessage(stateDir, errorClass2) {
25009
25167
  if (errorClass2 === "ERR_PRIVATE_FILES_SECURITY")
25010
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.`;
@@ -25053,7 +25211,7 @@ function errorClass(error) {
25053
25211
  function errorFile(error) {
25054
25212
  const { path: path2, stage } = error ?? {};
25055
25213
  return {
25056
- ...typeof path2 === "string" && path2 ? { file: basename4(path2) } : {},
25214
+ ...typeof path2 === "string" && path2 ? { file: basename5(path2) } : {},
25057
25215
  ...typeof stage === "string" && stage ? { stage } : {}
25058
25216
  };
25059
25217
  }
@@ -25424,9 +25582,9 @@ function storeFolder(anchor) {
25424
25582
  return `${anchor}.store`;
25425
25583
  }
25426
25584
  async function storeArtefacts(anchor) {
25427
- const names = await readdir3(dirname15(anchor)).catch(() => []);
25428
- const store = basename4(storeFolder(anchor));
25429
- const pool = basename4(anchor);
25585
+ const names = await readdir4(dirname15(anchor)).catch(() => []);
25586
+ const store = basename5(storeFolder(anchor));
25587
+ const pool = basename5(anchor);
25430
25588
  return names.filter(
25431
25589
  (name) => name === store || name.startsWith(`${pool}.store.`) || name.startsWith(pool) && name.endsWith(".tmp")
25432
25590
  ).length;
@@ -25440,7 +25598,7 @@ async function abandonUnpublishedStore(location, stateAnchor, log9) {
25440
25598
  await rename10(folder, archived).catch((error) => {
25441
25599
  if (error.code !== "ENOENT") throw error;
25442
25600
  });
25443
- await unlink10(accountStorePointerPath(stateAnchor)).catch(() => {
25601
+ await unlink11(accountStorePointerPath(stateAnchor)).catch(() => {
25444
25602
  });
25445
25603
  log9.info(
25446
25604
  "antigravity-auth set an unfinished account store aside before starting its move again",
@@ -25571,7 +25729,7 @@ async function writeStateHomeStoreForward(id, stateAnchor, configAnchor = legacy
25571
25729
  const forward = {
25572
25730
  schemaVersion: 2,
25573
25731
  id,
25574
- directoryBasename: basename4(storeFolder(stateAnchor)),
25732
+ directoryBasename: basename5(storeFolder(stateAnchor)),
25575
25733
  relocatedTo: { legacyPath: stateAnchor, id }
25576
25734
  };
25577
25735
  const fs3 = await loadCommonAuthFs();
@@ -25632,7 +25790,7 @@ async function moveFiles(location, files, markerPath, layoutLock, input) {
25632
25790
  for (const path2 of listed) {
25633
25791
  if (wanted.has(path2)) continue;
25634
25792
  await layoutLock.assertOwned();
25635
- await unlink10(path2).catch((error) => {
25793
+ await unlink11(path2).catch((error) => {
25636
25794
  if (error.code !== "ENOENT") throw error;
25637
25795
  });
25638
25796
  }
@@ -25771,7 +25929,7 @@ async function removeOldSignatureCache(location, path2, layoutLock, steps, log9)
25771
25929
  try {
25772
25930
  if (!await exists2(path2)) return;
25773
25931
  await beforeRemove(path2, layoutLock, steps);
25774
- await unlink10(path2);
25932
+ await unlink11(path2);
25775
25933
  } catch (error) {
25776
25934
  if (error?.code === "ENOENT") return;
25777
25935
  logOnce(
@@ -25874,7 +26032,7 @@ async function removeMovedVaultStateLeftover(vaultDir, accountFile) {
25874
26032
  if (!marker?.oldDir || marker.oldDir !== location.key) return;
25875
26033
  const leftover = vaultStateFile(files).old;
25876
26034
  if (!await isVaultShapedKeptState(files)) return;
25877
- await unlink10(leftover).catch((error) => {
26035
+ await unlink11(leftover).catch((error) => {
25878
26036
  if (error.code !== "ENOENT") throw error;
25879
26037
  });
25880
26038
  await rmdir2(files.vault.old).catch(() => {
@@ -25883,7 +26041,7 @@ async function removeMovedVaultStateLeftover(vaultDir, accountFile) {
25883
26041
  async function vaultFiles(dir) {
25884
26042
  let entries;
25885
26043
  try {
25886
- entries = await readdir3(dir, { withFileTypes: true });
26044
+ entries = await readdir4(dir, { withFileTypes: true });
25887
26045
  } catch (error) {
25888
26046
  const code2 = error.code;
25889
26047
  if (code2 === "ENOENT" || code2 === "ENOTDIR") return [];
@@ -25992,7 +26150,7 @@ function isWindowsSharingError(error, platform) {
25992
26150
  const code2 = error?.code;
25993
26151
  return platform === "win32" && (code2 === "EBUSY" || code2 === "EPERM" || code2 === "EACCES");
25994
26152
  }
25995
- 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 }) {
25996
26154
  const started = performance.now();
25997
26155
  for (const delay3 of SHARING_RETRY_DELAYS_MS) {
25998
26156
  if (delay3 > 0) await new Promise((done) => setTimeout(done, delay3));
@@ -26124,7 +26282,7 @@ async function writeManifest(stateDir, paths) {
26124
26282
  );
26125
26283
  }
26126
26284
  async function removeManifest(stateDir) {
26127
- await unlink10(join13(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE)).catch(
26285
+ await unlink11(join13(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE)).catch(
26128
26286
  (error) => {
26129
26287
  if (error.code !== "ENOENT") throw error;
26130
26288
  }
@@ -27307,8 +27465,8 @@ var init_debug = __esm({
27307
27465
  // src/plugin/logger.ts
27308
27466
  function createLocationLogger(options) {
27309
27467
  let configuredLevel = options.level ? LOG_LEVEL_FROM_OPERATOR[options.level] ?? "debug" : "debug";
27310
- const emit = (record3) => {
27311
- if (options.sink && options.sinkEnabled()) {
27468
+ const emit = (record3, alwaysHost = false) => {
27469
+ if (options.sink && (alwaysHost || options.sinkEnabled())) {
27312
27470
  try {
27313
27471
  const pending = options.sink(record3);
27314
27472
  if (isThenable(pending)) {
@@ -27327,26 +27485,33 @@ function createLocationLogger(options) {
27327
27485
  }
27328
27486
  }
27329
27487
  };
27330
- const engine = createLoggerInstance2({
27488
+ const createEngine3 = (alwaysHost) => createLoggerInstance2({
27331
27489
  level: () => configuredLevel,
27332
27490
  extraSecretKeys: isProviderSecretKey,
27333
27491
  extraValuePatterns: OAUTH_REDIRECT_VALUE_PATTERNS,
27334
27492
  captureSink: ({ channel: channel3, level, message, data }) => {
27335
27493
  const extra = data !== null && typeof data === "object" && !Array.isArray(data) ? Object.fromEntries(Object.entries(data)) : void 0;
27336
- emit({
27337
- service: channel3,
27338
- level: level === "trace" ? "debug" : level,
27339
- message,
27340
- extra
27341
- });
27494
+ emit(
27495
+ {
27496
+ service: channel3,
27497
+ level: level === "trace" ? "debug" : level,
27498
+ message,
27499
+ extra
27500
+ },
27501
+ alwaysHost
27502
+ );
27342
27503
  }
27343
27504
  });
27505
+ const engine = createEngine3(false);
27506
+ const hostEngine = createEngine3(true);
27344
27507
  return {
27345
27508
  createLogger(module) {
27346
27509
  const channel3 = engine.createLogger(`antigravity.${module}`);
27510
+ const hostChannel = hostEngine.createLogger(`antigravity.${module}`);
27347
27511
  return {
27348
27512
  debug: (message, extra) => channel3.debug(message, extra),
27349
27513
  info: (message, extra) => channel3.info(message, extra),
27514
+ hostInfo: (message, extra) => hostChannel.info(message, extra),
27350
27515
  warn: (message, extra) => channel3.warn(message, extra),
27351
27516
  error: (message, extra) => channel3.error(message, extra)
27352
27517
  };
@@ -27390,6 +27555,10 @@ function createLogger4(module) {
27390
27555
  return {
27391
27556
  debug: (message, extra) => log9("debug", message, extra),
27392
27557
  info: (message, extra) => log9("info", message, extra),
27558
+ hostInfo: (message, extra) => {
27559
+ channel3 ??= getLegacyLogger().createLogger(module);
27560
+ channel3.hostInfo?.(message, extra);
27561
+ },
27393
27562
  warn: (message, extra) => log9("warn", message, extra),
27394
27563
  error: (message, extra) => log9("error", message, extra)
27395
27564
  };
@@ -28578,16 +28747,16 @@ async function select2(terminal, items, options) {
28578
28747
  // src/common-auth-embedded/claustrum/enrollment.js
28579
28748
  import { createHash as createHash12, randomBytes as randomBytes3, randomUUID as randomUUID15 } from "node:crypto";
28580
28749
  import { constants as fsConstants2 } from "node:fs";
28581
- 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";
28582
- 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";
28583
28752
  import { ClaustrumCredentialError as ClaustrumCredentialError9, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
28584
28753
 
28585
28754
  // src/common-auth-embedded/fs/file-read-cache.js
28586
28755
  import { lstat as lstat7, stat as stat11 } from "node:fs/promises";
28587
28756
  import { resolve as resolve19 } from "node:path";
28588
- async function identity2(path2, followSymlinks) {
28757
+ async function identity2(path2, probe) {
28589
28758
  try {
28590
- const metadata = await (followSymlinks ? stat11(path2) : lstat7(path2));
28759
+ const metadata = await probe(path2);
28591
28760
  return metadata.isFile() ? metadata : void 0;
28592
28761
  } catch (error) {
28593
28762
  return error.code === "ENOENT" ? "absent" : void 0;
@@ -28599,15 +28768,15 @@ function sameIdentity2(left, right) {
28599
28768
  return left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
28600
28769
  }
28601
28770
  var FileReadCache2 = class {
28602
- #followSymlinks;
28771
+ #probe;
28603
28772
  #entries = /* @__PURE__ */ new Map();
28604
28773
  constructor(options = {}) {
28605
- this.#followSymlinks = options.followSymlinks ?? false;
28774
+ this.#probe = options.followSymlinks ? (path2) => (options.stat ?? stat11)(path2) : (path2) => (options.lstat ?? lstat7)(path2);
28606
28775
  }
28607
28776
  async read(paths, read, validateHit) {
28608
28777
  const resolvedPaths = paths.map((path2) => resolve19(path2));
28609
28778
  const key = JSON.stringify(resolvedPaths);
28610
- 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)));
28611
28780
  const identities = probed.every((entry) => entry !== void 0) ? probed : void 0;
28612
28781
  const cached = this.#entries.get(key);
28613
28782
  if (identities && cached && identities.every((entry, index) => {
@@ -28655,8 +28824,8 @@ init_private_files2();
28655
28824
 
28656
28825
  // src/common-auth-embedded/fs/refresh-file-lock.js
28657
28826
  import { randomUUID as randomUUID14 } from "node:crypto";
28658
- 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";
28659
- 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";
28660
28829
 
28661
28830
  // src/common-auth-embedded/fs/lock-record.js
28662
28831
  init_private_files2();
@@ -28764,6 +28933,90 @@ async function writeExclusiveText2(path2, text2) {
28764
28933
  await handle.close();
28765
28934
  }
28766
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
+ }
28767
29020
  var setRefreshLockRenewalTimeout2 = globalThis.setTimeout.bind(globalThis);
28768
29021
  var clearRefreshLockRenewalTimeout2 = globalThis.clearTimeout.bind(globalThis);
28769
29022
  function isLostMarkerRaceError2(error) {
@@ -29460,6 +29713,7 @@ async function acquireRefreshFileLockWithClock2(options) {
29460
29713
  return null;
29461
29714
  }
29462
29715
  scheduleRenewal();
29716
+ startStagingSweep2(lockPath, options.ttlMs, now);
29463
29717
  return {
29464
29718
  ownerId,
29465
29719
  whenLost: () => lostPromise,
@@ -29704,12 +29958,31 @@ function validEnrollmentDisplayName2(displayName) {
29704
29958
  const length = Array.from(displayName).length;
29705
29959
  return length >= 1 && length <= 40 && !/[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u200b-\u200d\u2060\ufeff]/u.test(displayName);
29706
29960
  }
29961
+ function validEnrollmentRequestedGrants2(grants) {
29962
+ return Array.isArray(grants) && grants.length >= 1 && grants.length <= 4 && Array.from(grants).every((grant) => {
29963
+ if (!isRecord10(grant) || Object.keys(grant).length !== 2 || grant.operation !== "read" && grant.operation !== "list" || !isRecord10(grant.selector))
29964
+ return false;
29965
+ const keys = Object.keys(grant.selector);
29966
+ const key = keys[0];
29967
+ return keys.length === 1 && (key === "category" || key === "exact") && typeof grant.selector[key] === "string" && grant.selector[key].trim().length > 0;
29968
+ });
29969
+ }
29970
+ function grantProposal2(state) {
29971
+ return {
29972
+ ...state.requestedGrants !== void 0 && {
29973
+ requestedGrants: state.requestedGrants
29974
+ },
29975
+ ...state.requestedGrantsStatus !== void 0 && {
29976
+ requestedGrantsStatus: state.requestedGrantsStatus
29977
+ }
29978
+ };
29979
+ }
29707
29980
  function connectClaustrumEnrollmentClient2(options) {
29708
29981
  return ClaustrumWireClient2.connect(options);
29709
29982
  }
29710
29983
  function getClaustrumEnrollmentPaths2(tokenPath) {
29711
29984
  const extension = extname2(tokenPath) || ".json";
29712
- const stem = basename5(tokenPath, extname2(tokenPath));
29985
+ const stem = basename7(tokenPath, extname2(tokenPath));
29713
29986
  return {
29714
29987
  statePath: join18(dirname19(tokenPath), `${stem}-state${extension}`),
29715
29988
  tokenPath
@@ -29739,6 +30012,7 @@ function decodeEnrollmentState2(value) {
29739
30012
  throw invalidState2();
29740
30013
  }
29741
30014
  if (value.phase === "pending") {
30015
+ const grants = decodeGrantProposal2(value);
29742
30016
  if (!TOKEN_RE2.test(String(value.requestSecret ?? "")) || value.requestId !== void 0 && (typeof value.requestId !== "string" || value.requestId.length === 0) || !validTimestamp2(value.createdAt) || !validTimestamp2(value.updatedAt)) {
29743
30017
  throw invalidState2();
29744
30018
  }
@@ -29751,10 +30025,12 @@ function decodeEnrollmentState2(value) {
29751
30025
  requestId: value.requestId
29752
30026
  },
29753
30027
  createdAt: value.createdAt,
29754
- updatedAt: value.updatedAt
30028
+ updatedAt: value.updatedAt,
30029
+ ...grants
29755
30030
  };
29756
30031
  }
29757
30032
  if (value.phase === "approved") {
30033
+ const grants = decodeGrantProposal2(value);
29758
30034
  if (value.approvedName !== void 0 && (typeof value.approvedName !== "string" || value.approvedName.length === 0) || !validGeneration2(value.tokenGeneration) || !validTimestamp2(value.updatedAt)) {
29759
30035
  throw invalidState2();
29760
30036
  }
@@ -29766,7 +30042,8 @@ function decodeEnrollmentState2(value) {
29766
30042
  approvedName: value.approvedName
29767
30043
  },
29768
30044
  tokenGeneration: value.tokenGeneration,
29769
- updatedAt: value.updatedAt
30045
+ updatedAt: value.updatedAt,
30046
+ ...grants
29770
30047
  };
29771
30048
  }
29772
30049
  if (value.phase === "denied" || value.phase === "blocked") {
@@ -29785,6 +30062,11 @@ function decodeEnrollmentState2(value) {
29785
30062
  }
29786
30063
  throw invalidState2();
29787
30064
  }
30065
+ function decodeGrantProposal2(value) {
30066
+ if (value.requestedGrants !== void 0 && !validEnrollmentRequestedGrants2(value.requestedGrants) || value.requestedGrantsStatus !== void 0 && (value.requestedGrants === void 0 || value.requestedGrantsStatus !== "sent" && value.requestedGrantsStatus !== "dropped"))
30067
+ return {};
30068
+ return grantProposal2(value);
30069
+ }
29788
30070
  function decodeTokenFile2(value) {
29789
30071
  if (!isRecord10(value) || !TOKEN_RE2.test(String(value.token ?? "")) || !validGeneration2(value.token_generation)) {
29790
30072
  throw new ClaustrumConsumerError2("invalid-token", "invalid Claustrum enrollment token file");
@@ -29952,7 +30234,7 @@ async function writeStateAtomic2(path2, state, ancestorOptions = {}) {
29952
30234
  }
29953
30235
  if (windowsPrivateFiles2)
29954
30236
  return writePrivateAtomic2(path2, bytes);
29955
- const temporary = join18(parent, `.${basename5(path2)}.${process.pid}.${randomUUID15()}.tmp`);
30237
+ const temporary = join18(parent, `.${basename7(path2)}.${process.pid}.${randomUUID15()}.tmp`);
29956
30238
  let descriptor;
29957
30239
  let created = false;
29958
30240
  try {
@@ -29969,7 +30251,7 @@ async function writeStateAtomic2(path2, state, ancestorOptions = {}) {
29969
30251
  await descriptor?.close().catch(() => {
29970
30252
  });
29971
30253
  if (created)
29972
- await unlink11(temporary).catch(() => {
30254
+ await unlink13(temporary).catch(() => {
29973
30255
  });
29974
30256
  }
29975
30257
  }
@@ -29999,7 +30281,8 @@ async function readEnrollmentStatus2(paths, proposedName) {
29999
30281
  ...state?.phase === "approved" && state.approvedName !== void 0 && {
30000
30282
  approvedName: state.approvedName
30001
30283
  },
30002
- tokenGeneration: token.token_generation
30284
+ tokenGeneration: token.token_generation,
30285
+ ...state && (state.phase === "approved" || state.phase === "pending") && grantProposal2(state)
30003
30286
  }
30004
30287
  };
30005
30288
  }
@@ -30047,12 +30330,19 @@ async function vaultAuthority3(paths, proposedName) {
30047
30330
  return "host";
30048
30331
  return enrollmentAuthority2(paths, proposedName);
30049
30332
  }
30333
+ async function readClaustrumEnrollmentToken2(tokenPath) {
30334
+ const value = await readBoundedJson2(tokenPath);
30335
+ if (value === void 0)
30336
+ throw new ClaustrumConsumerError2("not-enrolled", "Claustrum enrollment is not configured");
30337
+ return decodeTokenFile2(value);
30338
+ }
30050
30339
  function statusFromState2(state) {
30051
30340
  if (state.phase === "pending") {
30052
30341
  return {
30053
30342
  state: "pending",
30054
30343
  proposedName: state.proposedName,
30055
- ...state.requestId !== void 0 && { requestId: state.requestId }
30344
+ ...state.requestId !== void 0 && { requestId: state.requestId },
30345
+ ...grantProposal2(state)
30056
30346
  };
30057
30347
  }
30058
30348
  if (state.phase === "approved") {
@@ -30062,7 +30352,8 @@ function statusFromState2(state) {
30062
30352
  ...state.approvedName !== void 0 && {
30063
30353
  approvedName: state.approvedName
30064
30354
  },
30065
- tokenGeneration: state.tokenGeneration
30355
+ tokenGeneration: state.tokenGeneration,
30356
+ ...grantProposal2(state)
30066
30357
  };
30067
30358
  }
30068
30359
  if (state.phase === "denied")
@@ -30081,6 +30372,7 @@ var ClaustrumEnrollmentManager2 = class {
30081
30372
  #paths;
30082
30373
  #proposedName;
30083
30374
  #displayName;
30375
+ #requestedGrants;
30084
30376
  #now;
30085
30377
  #mintSecret;
30086
30378
  #writeTokenFile;
@@ -30088,6 +30380,12 @@ var ClaustrumEnrollmentManager2 = class {
30088
30380
  constructor(options) {
30089
30381
  if (options.displayName !== void 0 && !validEnrollmentDisplayName2(options.displayName))
30090
30382
  throw new ClaustrumConsumerError2("invalid-state", "invalid Claustrum enrollment display name");
30383
+ if (options.requestedGrants !== void 0 && !validEnrollmentRequestedGrants2(options.requestedGrants))
30384
+ throw new ClaustrumConsumerError2("invalid-state", "invalid Claustrum enrollment requested grants");
30385
+ this.#requestedGrants = options.requestedGrants?.map((grant) => ({
30386
+ selector: { ...grant.selector },
30387
+ operation: grant.operation
30388
+ }));
30091
30389
  this.#ancestorOptions = options.ancestorOptions ?? {};
30092
30390
  this.#client = options.client;
30093
30391
  this.#paths = options.paths;
@@ -30138,6 +30436,7 @@ var ClaustrumEnrollmentManager2 = class {
30138
30436
  phase: "approved",
30139
30437
  proposedName: state?.proposedName ?? this.#proposedName,
30140
30438
  tokenGeneration: token.token_generation,
30439
+ ...state && grantProposal2(state),
30141
30440
  updatedAt: this.#now()
30142
30441
  };
30143
30442
  await writeStateAtomic2(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -30149,7 +30448,8 @@ var ClaustrumEnrollmentManager2 = class {
30149
30448
  ...state.phase === "approved" && state.approvedName !== void 0 && {
30150
30449
  approvedName: state.approvedName
30151
30450
  },
30152
- tokenGeneration: token.token_generation
30451
+ tokenGeneration: token.token_generation,
30452
+ ...state.phase === "approved" && grantProposal2(state)
30153
30453
  };
30154
30454
  }
30155
30455
  if (state?.phase === "approved") {
@@ -30173,7 +30473,10 @@ var ClaustrumEnrollmentManager2 = class {
30173
30473
  proposedName: this.#proposedName,
30174
30474
  requestSecret: this.#mintSecret(),
30175
30475
  createdAt: now,
30176
- updatedAt: now
30476
+ updatedAt: now,
30477
+ ...this.#requestedGrants !== void 0 && {
30478
+ requestedGrants: this.#requestedGrants
30479
+ }
30177
30480
  };
30178
30481
  if (!TOKEN_RE2.test(state.requestSecret))
30179
30482
  throw new ClaustrumConsumerError2("invalid-state", "invalid minted Claustrum enrollment secret");
@@ -30187,22 +30490,33 @@ var ClaustrumEnrollmentManager2 = class {
30187
30490
  requestSecretHash
30188
30491
  };
30189
30492
  let proposed;
30493
+ let requestedGrantsStatus = state.requestedGrantsStatus;
30190
30494
  try {
30191
30495
  proposed = await this.#client.enrollPropose({
30192
30496
  ...proposal,
30193
30497
  ...this.#displayName !== void 0 && {
30194
30498
  displayName: this.#displayName
30499
+ },
30500
+ ...state.requestedGrants !== void 0 && {
30501
+ requestedGrants: state.requestedGrants
30195
30502
  }
30196
30503
  });
30504
+ if (state.requestedGrants !== void 0)
30505
+ requestedGrantsStatus = "sent";
30197
30506
  } catch (error) {
30198
- if (this.#displayName === void 0 || !(error instanceof ClaustrumCredentialError9) || error.code !== "invalid_params")
30507
+ if (this.#displayName === void 0 && state.requestedGrants === void 0 || !(error instanceof ClaustrumCredentialError9) || error.code !== "invalid_params")
30199
30508
  throw error;
30200
30509
  proposed = await this.#client.enrollPropose(proposal);
30510
+ if (state.requestedGrants !== void 0)
30511
+ requestedGrantsStatus = "dropped";
30201
30512
  }
30202
30513
  state = {
30203
30514
  ...state,
30204
30515
  requestId: proposed.requestId,
30205
- updatedAt: this.#now()
30516
+ updatedAt: this.#now(),
30517
+ ...requestedGrantsStatus !== void 0 && {
30518
+ requestedGrantsStatus
30519
+ }
30206
30520
  };
30207
30521
  await writeStateAtomic2(this.#paths.statePath, state, this.#ancestorOptions);
30208
30522
  } catch (error) {
@@ -30213,12 +30527,13 @@ var ClaustrumEnrollmentManager2 = class {
30213
30527
  return {
30214
30528
  state: "pending",
30215
30529
  proposedName: state.proposedName,
30216
- retryCode: refusal3.code
30530
+ retryCode: refusal3.code,
30531
+ ...grantProposal2(state)
30217
30532
  };
30218
30533
  }
30219
30534
  if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE2) {
30220
30535
  await lock.assertOwned();
30221
- await unlink11(this.#paths.statePath).catch((cause) => {
30536
+ await unlink13(this.#paths.statePath).catch((cause) => {
30222
30537
  if (cause.code !== "ENOENT")
30223
30538
  throw cause;
30224
30539
  });
@@ -30263,6 +30578,7 @@ var ClaustrumEnrollmentManager2 = class {
30263
30578
  proposedName: state.proposedName,
30264
30579
  approvedName: outcome.name,
30265
30580
  tokenGeneration: outcome.tokenGeneration,
30581
+ ...grantProposal2(state),
30266
30582
  updatedAt: this.#now()
30267
30583
  };
30268
30584
  await writeStateAtomic2(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -30276,7 +30592,8 @@ var ClaustrumEnrollmentManager2 = class {
30276
30592
  state: "pending",
30277
30593
  proposedName: state.proposedName,
30278
30594
  requestId,
30279
- retryCode: refusal3.code
30595
+ retryCode: refusal3.code,
30596
+ ...grantProposal2(state)
30280
30597
  };
30281
30598
  }
30282
30599
  return this.#block(state, refusal3.code);
@@ -30308,7 +30625,7 @@ async function resetClaustrumEnrollmentState2(paths, proposedName) {
30308
30625
  if (state.phase === "pending")
30309
30626
  return "refused-pending";
30310
30627
  await lock.assertOwned();
30311
- await unlink11(paths.statePath);
30628
+ await unlink13(paths.statePath);
30312
30629
  return "reset";
30313
30630
  } finally {
30314
30631
  await lock.release();
@@ -30455,6 +30772,77 @@ function runResolvedCommand(runner, platform, file, args, env3, timeoutMs = 15e3
30455
30772
  return runner.run(file, args, { env: env3, timeoutMs });
30456
30773
  }
30457
30774
 
30775
+ // src/common-auth-embedded/setup/enrollment-access.js
30776
+ function shellArgument(value) {
30777
+ if (/^[a-zA-Z0-9_:@./-]+$/.test(value))
30778
+ return value;
30779
+ return process.platform === "win32" ? `'${value.replaceAll("'", "''")}'` : `'${value.replaceAll("'", "'\\''")}'`;
30780
+ }
30781
+ async function confirmEnrollmentAccess(client, status, tokenPath, configuredGrants) {
30782
+ const requestedGrants = status.requestedGrants ?? configuredGrants;
30783
+ if (!requestedGrants)
30784
+ return void 0;
30785
+ const grants = requestedGrants.map((grant) => ({
30786
+ grant,
30787
+ ...status.approvedName !== void 0 && {
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}`
30789
+ }
30790
+ }));
30791
+ const access = {
30792
+ grants,
30793
+ ...status.requestedGrantsStatus !== void 0 && {
30794
+ requestedGrantsStatus: status.requestedGrantsStatus
30795
+ }
30796
+ };
30797
+ if (status.requestedGrantsStatus === "dropped")
30798
+ return { ...access, state: "older-vault" };
30799
+ try {
30800
+ if (!client.listScoped)
30801
+ return { ...access, state: "unconfirmed" };
30802
+ const { token } = await readClaustrumEnrollmentToken2(tokenPath);
30803
+ const inventory = await client.listScoped(token);
30804
+ const confirmed = grants.map((entry) => ({
30805
+ ...entry,
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
30807
+ }));
30808
+ return {
30809
+ ...access,
30810
+ state: confirmed.every((entry) => entry.reachableLogins > 0) ? "reachable" : confirmed.some((entry) => entry.reachableLogins > 0) ? "partial" : "no-logins",
30811
+ grants: confirmed.map((entry) => {
30812
+ if (entry.reachableLogins === 0)
30813
+ return entry;
30814
+ const { grantCommand: _, ...reachable } = entry;
30815
+ return reachable;
30816
+ })
30817
+ };
30818
+ } catch {
30819
+ return { ...access, state: "unconfirmed" };
30820
+ }
30821
+ }
30822
+ function enrollmentAccessLines(access, grantFallback = "setup") {
30823
+ if (grantFallback === "plugin" && access.requestedGrantsStatus !== "sent")
30824
+ return [];
30825
+ const lines = [];
30826
+ const remedy = access.grants.some((entry) => entry.grantCommand) ? "run:" : "check ck auth status for the approved name before granting access.";
30827
+ if (access.state === "older-vault")
30828
+ lines.push(`Approved. This vault is too old to grant access with the approval; ${remedy}`);
30829
+ else if (access.state === "no-logins")
30830
+ lines.push(`Approved, but no logins are reachable yet; ${remedy}`);
30831
+ else if (access.state === "partial")
30832
+ lines.push(`Approved, but some requested access has no reachable logins yet; ${remedy}`);
30833
+ else if (access.state === "unconfirmed")
30834
+ lines.push(`Approved, but access could not be confirmed; ${access.grants.some((entry) => entry.grantCommand) ? "check ck auth status or run:" : remedy}`);
30835
+ for (const { grant, reachableLogins, grantCommand } of access.grants) {
30836
+ if (reachableLogins !== void 0 && reachableLogins > 0) {
30837
+ const target = grant.selector.exact === void 0 ? `the vault's ${JSON.stringify(grant.selector.category)} accounts` : `credential ${JSON.stringify(grant.selector.exact)}`;
30838
+ lines.push(`Confirmed ${grant.operation} access to ${target} (${reachableLogins} reachable ${reachableLogins === 1 ? "login" : "logins"}).`);
30839
+ }
30840
+ if (grantCommand)
30841
+ lines.push(` ${grantCommand}`);
30842
+ }
30843
+ return lines;
30844
+ }
30845
+
30458
30846
  // src/common-auth-embedded/setup/command-error.js
30459
30847
  var PI_INSTALL_ERROR_MESSAGE = "Pi install failed; run pi install after checking your npm connection.";
30460
30848
  function utf8Tail(value) {
@@ -30495,8 +30883,9 @@ var OUTCOME_TEXT = {
30495
30883
  "not-enrolled": "not connected",
30496
30884
  unknown: "unknown, check with ck auth status"
30497
30885
  };
30498
- function setupEnrollmentLine({ host, outcome }) {
30499
- return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}`;
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")}` : ""}`;
30500
30889
  }
30501
30890
  var recordedEnrollment = /* @__PURE__ */ new WeakMap();
30502
30891
  function recordSetupEnrollment(failure, enrollment) {
@@ -31034,7 +31423,7 @@ function approveCommand(requestId, name) {
31034
31423
  async function connectSetupHost(plugin, host, io, terminal, fence) {
31035
31424
  if (hasVaultHost2())
31036
31425
  throw new Error(VAULT_HOST_CONNECT_REFUSAL2);
31037
- const { name, displayName, paths: input } = plugin.vault.hosts[host];
31426
+ const { name, displayName, requestedGrants, grantFallback, paths: input } = plugin.vault.hosts[host];
31038
31427
  const paths = hostEnrollmentPaths2(input);
31039
31428
  await fence();
31040
31429
  const client = await (io.connect ?? connectClaustrumEnrollmentClient2)({
@@ -31049,6 +31438,7 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31049
31438
  const manager = new ClaustrumEnrollmentManager2({
31050
31439
  proposedName: name,
31051
31440
  displayName,
31441
+ requestedGrants,
31052
31442
  paths,
31053
31443
  // Each tick of the wait below checks the fence once, just before
31054
31444
  // reconcile proposes or polls. Checking again inside every vault call
@@ -31064,7 +31454,11 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31064
31454
  const initial = await manager.status();
31065
31455
  if (initial.state === "approved") {
31066
31456
  printLine2(terminal, `Already connected as ${initial.approvedName ?? initial.proposedName}.`);
31067
- return;
31457
+ const access = await confirmEnrollmentAccess(client, initial, paths.tokenPath, requestedGrants);
31458
+ if (access)
31459
+ for (const line of enrollmentAccessLines(access, grantFallback))
31460
+ printLine2(terminal, line);
31461
+ return access;
31068
31462
  }
31069
31463
  printLine2(terminal, `Asking the vault to connect ${name}\u2026`);
31070
31464
  const deadline = now() + ENROLLMENT_WAIT_MS;
@@ -31076,7 +31470,11 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31076
31470
  const status = await manager.reconcile();
31077
31471
  if (status.state === "approved") {
31078
31472
  printLine2(terminal, `Connected ${host} to Claustrum.`);
31079
- return;
31473
+ const access = await confirmEnrollmentAccess(client, status, paths.tokenPath, requestedGrants);
31474
+ if (access)
31475
+ for (const line of enrollmentAccessLines(access, grantFallback))
31476
+ printLine2(terminal, line);
31477
+ return access;
31080
31478
  }
31081
31479
  if (status.state === "unavailable" && status.code === UNSUPPORTED_ENROLLMENT_CODE2)
31082
31480
  throw new HostNotEnrolledError(UNSUPPORTED_VAULT_MESSAGE, {
@@ -31273,8 +31671,8 @@ import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2,
31273
31671
 
31274
31672
  // src/common-auth-embedded/setup/config-write.js
31275
31673
  import { randomUUID as randomUUID16 } from "node:crypto";
31276
- import { mkdir as mkdir15, open as open11, rename as rename13, stat as stat15, unlink as unlink12 } from "node:fs/promises";
31277
- 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";
31278
31676
  import { setTimeout as delay2 } from "node:timers/promises";
31279
31677
  async function writeHostConfigAtomic(file, content, options = {}) {
31280
31678
  const windows = (options.platform ?? process.platform) === "win32";
@@ -31289,7 +31687,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
31289
31687
  throw error;
31290
31688
  }
31291
31689
  }
31292
- const stage = join20(parent, `.${basename6(file)}.${(options.stageName ?? randomUUID16)()}.tmp`);
31690
+ const stage = join20(parent, `.${basename8(file)}.${(options.stageName ?? randomUUID16)()}.tmp`);
31293
31691
  let created = false;
31294
31692
  try {
31295
31693
  const handle = await open11(stage, "wx", mode ?? 438);
@@ -31319,7 +31717,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
31319
31717
  }
31320
31718
  } finally {
31321
31719
  if (created)
31322
- await unlink12(stage).catch(() => {
31720
+ await unlink14(stage).catch(() => {
31323
31721
  });
31324
31722
  }
31325
31723
  }
@@ -31510,12 +31908,17 @@ function validatePlugin(plugin) {
31510
31908
  for (const host of Object.values(plugin.vault.hosts)) {
31511
31909
  if (!/^[a-z0-9][a-z0-9-]*$/.test(host.name))
31512
31910
  throw new Error("Setup requires lowercase vault names containing only letters, digits and dashes.");
31911
+ if (host.requestedGrants !== void 0 && !validEnrollmentRequestedGrants2(host.requestedGrants))
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");
31513
31915
  }
31514
31916
  }
31515
- async function enrollmentReport(plugin, hosts, recorded) {
31917
+ async function enrollmentReport(plugin, hosts, recorded, recordedAccess) {
31516
31918
  const report = [];
31517
31919
  for (const host of hosts) {
31518
31920
  let outcome = recorded.get(host) ?? "not-enrolled";
31921
+ let access = recordedAccess.get(host);
31519
31922
  if (outcome === "unknown") {
31520
31923
  const { name, paths } = plugin.vault.hosts[host];
31521
31924
  const authority = await vaultAuthority3(hostEnrollmentPaths2(paths), name).catch(() => "unreadable");
@@ -31523,8 +31926,13 @@ async function enrollmentReport(plugin, hosts, recorded) {
31523
31926
  outcome = "enrolled";
31524
31927
  else if (authority === "local")
31525
31928
  outcome = "not-enrolled";
31929
+ if (outcome === "enrolled") {
31930
+ const status = await readClaustrumEnrollmentStatus2(hostEnrollmentPaths2(paths), name).catch(() => void 0);
31931
+ if (status?.state === "approved")
31932
+ access = await confirmEnrollmentAccess({}, status, hostEnrollmentPaths2(paths).tokenPath, plugin.vault.hosts[host].requestedGrants);
31933
+ }
31526
31934
  }
31527
- report.push({ host, outcome });
31935
+ report.push({ host, outcome, ...access && { access } });
31528
31936
  }
31529
31937
  return report;
31530
31938
  }
@@ -31653,6 +32061,7 @@ ${write.content}`);
31653
32061
  piAgentDir: detection.pi.directory
31654
32062
  };
31655
32063
  const enrollment = /* @__PURE__ */ new Map();
32064
+ const enrollmentAccess = /* @__PURE__ */ new Map();
31656
32065
  try {
31657
32066
  for (const host of hosts) {
31658
32067
  await stopped();
@@ -31661,7 +32070,9 @@ ${write.content}`);
31661
32070
  if (useVault) {
31662
32071
  enrollment.set(host, "unknown");
31663
32072
  try {
31664
- await connectSetupHost(plugin, host, io, terminal, stopped);
32073
+ const access = await connectSetupHost(plugin, host, io, terminal, stopped);
32074
+ if (access)
32075
+ enrollmentAccess.set(host, access);
31665
32076
  } catch (error) {
31666
32077
  if (error instanceof HostNotEnrolledError)
31667
32078
  enrollment.set(host, "not-enrolled");
@@ -31686,10 +32097,10 @@ ${write.content}`);
31686
32097
  if (enrollment.size === 0)
31687
32098
  throw error;
31688
32099
  try {
31689
- const report = await enrollmentReport(plugin, hosts, enrollment);
32100
+ const report = await enrollmentReport(plugin, hosts, enrollment, enrollmentAccess);
31690
32101
  recordSetupEnrollment(error, report);
31691
32102
  for (const entry of report)
31692
- printLine2(terminal, setupEnrollmentLine(entry));
32103
+ printLine2(terminal, setupEnrollmentLine(entry, plugin.vault.hosts[entry.host].grantFallback));
31693
32104
  } catch {
31694
32105
  }
31695
32106
  throw error;
@@ -31830,6 +32241,12 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
31830
32241
  opencode: {
31831
32242
  name: OPENCODE_VAULT_ENROLLMENT_NAME,
31832
32243
  displayName: "Antigravity sign-in for OpenCode",
32244
+ requestedGrants: [
32245
+ {
32246
+ selector: { category: "antigravity-native" },
32247
+ operation: "read"
32248
+ }
32249
+ ],
31833
32250
  // Read at each use: a real run settles the vault folder in
31834
32251
  // `beforeSignIn`, which may move it after this plugin is built.
31835
32252
  paths: {
@@ -31842,6 +32259,12 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
31842
32259
  pi: {
31843
32260
  name: "antigravity-auth-pi",
31844
32261
  displayName: "Antigravity sign-in for Pi",
32262
+ requestedGrants: [
32263
+ {
32264
+ selector: { category: "antigravity-native" },
32265
+ operation: "read"
32266
+ }
32267
+ ],
31845
32268
  paths: { stateDir: piDir, host: "pi" }
31846
32269
  }
31847
32270
  };