@cortexkit/opencode-openai-auth 1.16.0 → 1.17.2

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 (49) hide show
  1. package/dist/bin.js +2 -2
  2. package/dist/{index-9q49makj.js → index-2dqwctzp.js} +1 -1
  3. package/dist/{index-cwsxvbag.js → index-4thkhwyp.js} +2 -2
  4. package/dist/{index-7rh2vrrx.js → index-6pakkcrn.js} +1 -1
  5. package/dist/index-7ea4dbe9.js +8 -0
  6. package/dist/{index-mrt0rqtz.js → index-b2pc3ze2.js} +1 -1
  7. package/dist/{index-78q36xet.js → index-emcf633z.js} +1 -1
  8. package/dist/{index-qtkf7nzb.js → index-h8ychf80.js} +2 -2
  9. package/dist/{index-dyc6v3ba.js → index-jmzh060w.js} +27 -27
  10. package/dist/{index-chp9keaz.js → index-q7d43xxn.js} +2 -2
  11. package/dist/index-qjh3h3wr.js +101 -0
  12. package/dist/{index-2r3vgg9c.js → index-srdm5a4d.js} +2 -2
  13. package/dist/{index-29mjazwp.js → index-t09qaj5w.js} +2 -2
  14. package/dist/{index-t4dwp124.js → index-vjk4wv2b.js} +1 -1
  15. package/dist/{index-ryj7dj32.js → index-y1b9ka54.js} +26 -26
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/rpc/port-file.js +1 -1
  19. package/dist/rpc/protocol.js +1 -1
  20. package/dist/rpc/rpc-client.js +1 -1
  21. package/dist/rpc/rpc-dir.js +1 -1
  22. package/dist/sidebar-state.js +1 -1
  23. package/dist/{token-19s0jcbk.js → token-6ya278eg.js} +1 -1
  24. package/dist/token-util-ynanp4np.js +1 -0
  25. package/dist/tui-preferences.js +1 -1
  26. package/dist/v2/server.d.ts +1 -1
  27. package/dist/v2/server.js +2 -2
  28. package/package.json +2 -2
  29. package/src/tui-compiled/raw/shared/0766d78c6f481f18-watcher.js +9 -2
  30. package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +147 -2
  31. package/src/tui-compiled/raw/shared/352d228be2832bd4-hub.js +47 -1
  32. package/src/tui-compiled/raw/shared/44449e891fab9fbc-edit.js +48 -2
  33. package/src/tui-compiled/raw/shared/5f4bc45522ab9bc6-update.js +19 -18
  34. package/src/tui-compiled/raw/shared/6948d70969aa7a55-fs.js +1 -0
  35. package/src/tui-compiled/raw/shared/cf4c37f3975c3a8d-canonical-file-path.js +53 -0
  36. package/src/tui-compiled/raw/shared/e8d3c8da776ef9cd-index.js +1 -1
  37. package/src/tui-compiled/raw/shared/ec971142548df90e-index.js +3 -0
  38. package/src/tui-compiled/runtime/shared/0766d78c6f481f18-watcher.js +9 -2
  39. package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +147 -2
  40. package/src/tui-compiled/runtime/shared/352d228be2832bd4-hub.js +47 -1
  41. package/src/tui-compiled/runtime/shared/44449e891fab9fbc-edit.js +48 -2
  42. package/src/tui-compiled/runtime/shared/5f4bc45522ab9bc6-update.js +19 -18
  43. package/src/tui-compiled/runtime/shared/6948d70969aa7a55-fs.js +1 -0
  44. package/src/tui-compiled/runtime/shared/cf4c37f3975c3a8d-canonical-file-path.js +53 -0
  45. package/src/tui-compiled/runtime/shared/e8d3c8da776ef9cd-index.js +1 -1
  46. package/src/tui-compiled/runtime/shared/ec971142548df90e-index.js +3 -0
  47. package/dist/index-4tpqkbv9.js +0 -101
  48. package/dist/index-ea3ykjex.js +0 -8
  49. package/dist/token-util-3pv487zf.js +0 -1
@@ -65,6 +65,10 @@ export function decideScopedRetryAfter401(site, served, current, logger = defaul
65
65
  export const SERVING_MARGIN_MS = 300_000;
66
66
  /** A kept receipt needs a minute of headroom, not the vault's refresh demand. */
67
67
  export const KEPT_RECEIPT_MARGIN_MS = 60_000;
68
+ /** Maximum request-path wait for a vault read without a usable kept receipt. */
69
+ export const VAULT_RECEIPT_WAIT_MS = 10_000;
70
+ /** Only the first minute of each observed outage earns a request-path wait. */
71
+ export const VAULT_YOUNG_OUTAGE_MS = 60_000;
68
72
  function invalidMaterial() {
69
73
  return new ClaustrumConsumerError('invalid-material', 'Claustrum returned invalid credential material');
70
74
  }
@@ -198,7 +202,10 @@ export class ClaustrumScopedCustody {
198
202
  #setTimeout;
199
203
  #clearTimeout;
200
204
  #outage = false;
205
+ #outageSince = 0;
206
+ #outageWaitSpent = false;
201
207
  #outageError = new ClaustrumUnreachableError();
208
+ #receiptWaits = new Map();
202
209
  #probeTimer;
203
210
  #probing = false;
204
211
  #lastProbeAt = -Infinity;
@@ -277,6 +284,8 @@ export class ClaustrumScopedCustody {
277
284
  if (this.#closed || this.#outage)
278
285
  return;
279
286
  this.#outage = true;
287
+ this.#outageSince = this.#now();
288
+ this.#outageWaitSpent = false;
280
289
  this.#outageError =
281
290
  error instanceof ClaustrumCredentialError
282
291
  ? error
@@ -582,11 +591,13 @@ export class ClaustrumScopedCustody {
582
591
  /** Ask the vault while reachable; retain one validated receipt in memory only. */
583
592
  async authorize(identity, signal, routeId = 'vault') {
584
593
  this.#check(signal);
594
+ const startedAt = this.#now();
585
595
  const { credentialId, credentialType, accountIdentity } = identity;
586
596
  let kept = this.#kept.get(credentialId);
587
597
  if (kept &&
588
598
  (kept.attempt.credentialType !== credentialType ||
589
- kept.attempt.expectedAccountIdentity !== accountIdentity)) {
599
+ kept.attempt.expectedAccountIdentity !== accountIdentity ||
600
+ !this.#usable(kept.attempt))) {
590
601
  this.forget(credentialId);
591
602
  kept = undefined;
592
603
  }
@@ -605,7 +616,22 @@ export class ClaustrumScopedCustody {
605
616
  return this.#serveKept(credentialId, kept, token, routeId);
606
617
  }
607
618
  try {
608
- const attempt = await this.#authorizeFresh({ credentialId, credentialType, accountIdentity }, token, signal);
619
+ let attempt;
620
+ try {
621
+ // Once recovery is in flight, later arrivals join it rather than
622
+ // issuing another immediate read into the same known outage.
623
+ const recovering = this.#outage &&
624
+ this.#receiptWaits.has(this.#receiptWaitKey({ credentialId, credentialType, accountIdentity }, token));
625
+ if (recovering)
626
+ throw this.#outageError;
627
+ attempt = await this.#authorizeFresh({ credentialId, credentialType, accountIdentity }, token, signal);
628
+ }
629
+ catch (error) {
630
+ this.#check(signal);
631
+ if (classifyVaultFailure(error) !== 'unreachable' || kept)
632
+ throw error;
633
+ attempt = await this.#waitForReceipt({ credentialId, credentialType, accountIdentity }, token, startedAt, error, signal);
634
+ }
609
635
  this.#kept.set(credentialId, { attempt, routeId, since: null });
610
636
  this.#usageServed.set(credentialId, { ...identity });
611
637
  return attempt;
@@ -619,6 +645,122 @@ export class ClaustrumScopedCustody {
619
645
  return this.#serveKept(credentialId, kept, token, routeId, error);
620
646
  }
621
647
  }
648
+ #receiptWaitKey(identity, token) {
649
+ // Never share authorization across a changed enrollment or account binding.
650
+ return JSON.stringify([
651
+ identity.credentialId,
652
+ identity.credentialType,
653
+ identity.accountIdentity,
654
+ token,
655
+ ]);
656
+ }
657
+ async #waitForReceipt(identity, token, startedAt, error, signal) {
658
+ // Measure from the first unreachable observation, even at cold start.
659
+ // Otherwise a process that never connected would charge every request 10 s
660
+ // for an arbitrarily long outage. Any vault answer starts a new window.
661
+ // Once one wait has run out in this outage, the outage has outlasted the
662
+ // bound: later cold reads fail at once. Without that, a host that tries its
663
+ // accounts in turn would pay the full wait once per account.
664
+ const remaining = VAULT_RECEIPT_WAIT_MS - (this.#now() - startedAt);
665
+ if (remaining <= 0 ||
666
+ this.#outageWaitSpent ||
667
+ this.#now() - this.#outageSince >= VAULT_YOUNG_OUTAGE_MS)
668
+ throw error;
669
+ const key = this.#receiptWaitKey(identity, token);
670
+ let wait = this.#receiptWaits.get(key);
671
+ if (!wait) {
672
+ const controller = new AbortController();
673
+ const created = {
674
+ controller,
675
+ users: 0,
676
+ error,
677
+ pending: Promise.resolve().then(async () => {
678
+ let delay = 250;
679
+ for (;;) {
680
+ await this.#receiptBackoff(delay, controller.signal);
681
+ try {
682
+ return await this.#authorizeFresh(identity, token, controller.signal);
683
+ }
684
+ catch (failure) {
685
+ this.#check(controller.signal);
686
+ if (classifyVaultFailure(failure) !== 'unreachable')
687
+ throw failure;
688
+ created.error = failure;
689
+ delay = Math.min(delay * 2, 1_000);
690
+ }
691
+ }
692
+ }),
693
+ };
694
+ wait = created;
695
+ this.#receiptWaits.set(key, wait);
696
+ const remove = () => {
697
+ if (this.#receiptWaits.get(key) === created)
698
+ this.#receiptWaits.delete(key);
699
+ };
700
+ void wait.pending.then(remove, remove);
701
+ }
702
+ const shared = wait;
703
+ shared.users++;
704
+ let timer;
705
+ let abort;
706
+ try {
707
+ const attempt = await Promise.race([
708
+ shared.pending,
709
+ new Promise((_resolve, reject) => {
710
+ timer = this.#setTimeout(() => {
711
+ if (this.#outage)
712
+ this.#outageWaitSpent = true;
713
+ reject(shared.error);
714
+ }, remaining);
715
+ timer.unref?.();
716
+ if (signal) {
717
+ abort = () => reject(signal.reason);
718
+ signal.addEventListener('abort', abort, { once: true });
719
+ if (signal.aborted)
720
+ abort();
721
+ }
722
+ }),
723
+ ]);
724
+ this.#check(signal);
725
+ // Each physical send owns its receipt and later failure report, even
726
+ // when several requests shared the same recovery read.
727
+ const receipt = Object.freeze(Object.defineProperty({ ...attempt }, 'accessToken', {
728
+ value: attempt.accessToken,
729
+ enumerable: false,
730
+ }));
731
+ this.#provenance.set(receipt, { token });
732
+ return receipt;
733
+ }
734
+ finally {
735
+ if (timer)
736
+ this.#clearTimeout(timer);
737
+ if (abort)
738
+ signal?.removeEventListener('abort', abort);
739
+ if (--shared.users === 0) {
740
+ shared.controller.abort();
741
+ if (this.#receiptWaits.get(key) === shared)
742
+ this.#receiptWaits.delete(key);
743
+ }
744
+ }
745
+ }
746
+ #receiptBackoff(delay, signal) {
747
+ this.#check(signal);
748
+ return new Promise((resolve, reject) => {
749
+ const abort = () => {
750
+ this.#clearTimeout(timer);
751
+ signal.removeEventListener('abort', abort);
752
+ reject(signal.reason);
753
+ };
754
+ const timer = this.#setTimeout(() => {
755
+ signal.removeEventListener('abort', abort);
756
+ resolve();
757
+ }, delay);
758
+ timer.unref?.();
759
+ signal.addEventListener('abort', abort, { once: true });
760
+ if (signal.aborted)
761
+ abort();
762
+ });
763
+ }
622
764
  #serveKept(credentialId, kept, token, routeId, error = this.#outageError) {
623
765
  // A concurrent refusal or 401 may already have discarded this entry.
624
766
  if (!kept ||
@@ -876,6 +1018,9 @@ export class ClaustrumScopedCustody {
876
1018
  if (this.#closed)
877
1019
  return;
878
1020
  this.#closed = true;
1021
+ for (const wait of this.#receiptWaits.values())
1022
+ wait.controller.abort();
1023
+ this.#receiptWaits.clear();
879
1024
  if (this.#probeTimer)
880
1025
  this.#clearTimeout(this.#probeTimer);
881
1026
  this.#probeTimer = undefined;
@@ -159,6 +159,13 @@ export class ClaustrumDiscoveryHub {
159
159
  #own;
160
160
  #watch;
161
161
  #run;
162
+ /**
163
+ * Member commit fan-outs still running, each until every one of its
164
+ * commits has settled. Only a run whose generation ended can leave one
165
+ * behind while another run starts; `#discover` waits for them before it
166
+ * reads the files it lists over.
167
+ */
168
+ #fanOuts = new Set();
162
169
  /** The hub's last authority read; undefined before the first one. */
163
170
  #active;
164
171
  /** Counts inactive transitions, so local work started before one stops. */
@@ -665,6 +672,15 @@ export class ClaustrumDiscoveryHub {
665
672
  // Folders that could not be made owner-only fail every member's commit,
666
673
  // as an unreadable base fails its member's: each is marked pending.
667
674
  const folders = await this.#ensureRosterDirectories().then(() => undefined, (error) => error instanceof Error ? error : new Error(String(error)));
675
+ // A generation that ended may still have member commits in flight. A
676
+ // commit that passed its last generation check just before vault mode
677
+ // went off still renames its file afterwards, so its older listing can
678
+ // land after this run read that file. The base-view rule below would
679
+ // then take it for another process's newer commit and keep it over this
680
+ // list. The files are read only once every such commit has settled.
681
+ await this.#settleFanOuts();
682
+ if (!this.#live(generation))
683
+ return undefined;
668
684
  // What each member's file held before the list. Another process may
669
685
  // commit while this list runs; the base-view rule then keeps its newer
670
686
  // roster rather than replacing it with this older listing. Each file is
@@ -696,9 +712,17 @@ export class ClaustrumDiscoveryHub {
696
712
  // does), so no commit ever holds two members' locks and no order between
697
713
  // members is needed. The results are then published in member order.
698
714
  const members = this.#open();
699
- const commits = await Promise.all(members.map((entry) => entry.hooks && !entry.closed
715
+ const fanOut = Promise.all(members.map((entry) => entry.hooks && !entry.closed
700
716
  ? this.#commit(entry, entry.hooks, inventory, folders ?? bases.get(entry), generation)
701
717
  : undefined));
718
+ this.#fanOuts.add(fanOut);
719
+ let commits;
720
+ try {
721
+ commits = await fanOut;
722
+ }
723
+ finally {
724
+ this.#fanOuts.delete(fanOut);
725
+ }
702
726
  if (!this.#live(generation))
703
727
  return undefined;
704
728
  const errors = new Map();
@@ -813,6 +837,28 @@ export class ClaustrumDiscoveryHub {
813
837
  return { error };
814
838
  }
815
839
  }
840
+ /**
841
+ * Wait until no member commit fan-out of an earlier run is still running.
842
+ * Each of them belongs to a generation that ended, so its commits fail or
843
+ * finish at their next generation check and this wait stays short.
844
+ */
845
+ async #settleFanOuts() {
846
+ if (!this.#fanOuts.size)
847
+ return;
848
+ const phaseDiagnostics = channel('common-auth.claustrum.phases');
849
+ const phase = (name) => {
850
+ if (phaseDiagnostics.hasSubscribers)
851
+ phaseDiagnostics.publish({ logger: this.#logger, phase: name });
852
+ };
853
+ phase('earlier fan-out drain begin');
854
+ try {
855
+ while (this.#fanOuts.size)
856
+ await Promise.allSettled([...this.#fanOuts]);
857
+ }
858
+ finally {
859
+ phase('earlier fan-out drain end');
860
+ }
861
+ }
816
862
  /**
817
863
  * Create the roster folders under the state folder (`rosters`, this host
818
864
  * generation and this key) owner-only, as every other Claustrum private
@@ -37,7 +37,12 @@ function descriptorAtPath(descriptor, path) {
37
37
  }
38
38
  return current;
39
39
  }
40
- function destination(declaration, setting, value, { host, model }) {
40
+ function destination(declaration, setting, value, { host, model }, level) {
41
+ if (level !== undefined) {
42
+ return level === 'default' && !isJsonObject(value)
43
+ ? [setting]
44
+ : [setting, level];
45
+ }
41
46
  if (declaration.overrides !== undefined && isJsonObject(value)) {
42
47
  if (declaration.overrides.model &&
43
48
  model !== undefined &&
@@ -75,6 +80,20 @@ function checkPath(parsed, path) {
75
80
  invalid();
76
81
  }
77
82
  }
83
+ function preservePlainDefault(parsed, setting) {
84
+ const node = parsed.tree && findNodeAtLocation(parsed.tree, [setting]);
85
+ if (!node)
86
+ invalid();
87
+ // Keep the original value text so comments inside a list survive promotion.
88
+ const value = parsed.text.slice(node.offset, node.offset + node.length);
89
+ return parseForEdit(applyEdits(parsed.text, [
90
+ {
91
+ offset: node.offset,
92
+ length: node.length,
93
+ content: `{ "default": ${value} }`,
94
+ },
95
+ ]));
96
+ }
78
97
  /** Remove only the member's own tokens; intervening comment lines belong to neither neighbor. */
79
98
  function removeMember(text, tree, path) {
80
99
  const property = tree && findNodeAtLocation(tree, path)?.parent;
@@ -157,6 +176,18 @@ export function applySettingsEdits(definition, source, edits, context) {
157
176
  if (!Object.hasOwn(definition.settings, edit.setting))
158
177
  invalid();
159
178
  const declaration = definition.settings[edit.setting];
179
+ if (edit.level !== undefined) {
180
+ if (edit.path !== undefined)
181
+ invalid();
182
+ if (edit.level === 'default') {
183
+ if (declaration.overrides === undefined)
184
+ invalid();
185
+ }
186
+ else if ((edit.level !== 'opencode' && edit.level !== 'pi') ||
187
+ !declaration.overrides?.host) {
188
+ invalid();
189
+ }
190
+ }
160
191
  if (edit.path !== undefined &&
161
192
  declaration.value.kind !== 'object' &&
162
193
  declaration.value.kind !== 'record')
@@ -170,9 +201,24 @@ export function applySettingsEdits(definition, source, edits, context) {
170
201
  const units = [];
171
202
  for (const edit of edits) {
172
203
  const declaration = definition.settings[edit.setting];
204
+ if (edit.level !== undefined &&
205
+ edit.level !== 'default' &&
206
+ !isJsonObject(working.value[edit.setting])) {
207
+ if (edit.remove === true)
208
+ continue;
209
+ if (Object.hasOwn(working.value, edit.setting)) {
210
+ working = preservePlainDefault(working, edit.setting);
211
+ }
212
+ // Earlier root edits now refer to the override's default, if it exists.
213
+ for (const unit of units) {
214
+ if (unit.path.length === 1 && unit.path[0] === edit.setting) {
215
+ unit.path.push('default');
216
+ }
217
+ }
218
+ }
173
219
  const base = edit.path !== undefined
174
220
  ? [edit.setting]
175
- : destination(declaration, edit.setting, working.value[edit.setting], context);
221
+ : destination(declaration, edit.setting, working.value[edit.setting], context, edit.level);
176
222
  const path = [...base, ...(edit.path ?? [])];
177
223
  checkPath(working, path);
178
224
  units.push(resolutionUnit(declaration.value, base, edit.path ?? []));
@@ -1,6 +1,8 @@
1
- import { basename, dirname, join } from "node:path";
1
+ import { dirname } from "node:path";
2
+ import { canonicalFilePath } from "./cf4c37f3975c3a8d-canonical-file-path.js";
2
3
  import { ensurePrivateDirectory } from "./375d9cca2def037d-private-files.js";
3
4
  import { withLock } from "./4825e03209d6ae3e-with-lock.js";
5
+ import { deepFreeze } from "./5803fadb30af0ec0-descriptors.js";
4
6
  import { applySettingsEdits, } from "./44449e891fab9fbc-edit.js";
5
7
  import { SettingsFs } from "./6948d70969aa7a55-fs.js";
6
8
  import { rethrowSettingsLockError } from "./eac0bed49f3d4110-lock-errors.js";
@@ -18,25 +20,9 @@ function unavailable(file, cause) {
18
20
  }
19
21
  async function writeTarget(file) {
20
22
  try {
21
- return await SettingsFs.realpath(file);
23
+ return await canonicalFilePath(file, SettingsFs);
22
24
  }
23
25
  catch (error) {
24
- if (error.code !== 'ENOENT')
25
- unavailable(file, error);
26
- try {
27
- await SettingsFs.lstat(file);
28
- }
29
- catch (lstatError) {
30
- if (lstatError.code !== 'ENOENT')
31
- unavailable(file, lstatError);
32
- try {
33
- return join(await SettingsFs.realpath(dirname(file)), basename(file));
34
- }
35
- catch (parentError) {
36
- unavailable(file, parentError);
37
- }
38
- }
39
- // A directory entry whose realpath is missing is a dangling symlink.
40
26
  unavailable(file, error);
41
27
  }
42
28
  }
@@ -97,6 +83,21 @@ export async function updateSettings(definition, options, edits, context) {
97
83
  if (Number.isInteger(version) && version > 1) {
98
84
  throw new SettingsRefusal('settings-newer-version', 'Settings were written by a newer version');
99
85
  }
86
+ if (typeof edits === 'function') {
87
+ const planned = edits(deepFreeze(missing
88
+ ? { status: 'missing' }
89
+ : {
90
+ status: 'ready',
91
+ document: structuredClone(parsed.value),
92
+ }));
93
+ if (planned !== null &&
94
+ (typeof planned === 'object' || typeof planned === 'function') &&
95
+ 'then' in planned &&
96
+ typeof planned.then === 'function') {
97
+ throw new SettingsRefusal('settings-invalid-value', 'Settings update plans must be synchronous');
98
+ }
99
+ edits = planned;
100
+ }
100
101
  if (!parsed.tree) {
101
102
  source = `${parsed.hasBom ? '\uFEFF' : ''}// ${definition.plugin} settings\n{\n "schema_version": 1\n}\n`;
102
103
  }
@@ -3,6 +3,7 @@ const defaults = {
3
3
  readFile: fs.readFile,
4
4
  stat: fs.stat,
5
5
  lstat: fs.lstat,
6
+ readlink: fs.readlink,
6
7
  realpath: fs.realpath,
7
8
  open: fs.open,
8
9
  rename: fs.rename,
@@ -0,0 +1,53 @@
1
+ import { basename, dirname, join, resolve } from "node:path";
2
+ const maxSymlinkHops = 40;
3
+ /**
4
+ * Canonical path of a file that other processes may replace by write-and-rename.
5
+ *
6
+ * On Linux, Bun's realpath on such a file can answer "<file> (deleted)" (Bun
7
+ * 1.3) or ENOENT (Bun 1.4) during the rename. So this resolves the folder with
8
+ * realpath and appends the name, then follows a file symlink one readlink hop at
9
+ * a time, at most 40 hops. A missing file resolves to its would-be path; a
10
+ * dangling link or a loop throws. Pass `node:fs/promises` (or a test double).
11
+ */
12
+ export async function canonicalFilePath(file, fs) {
13
+ let target = file;
14
+ for (let hops = 0;; hops++) {
15
+ // Bun can report an unlinked inode's " (deleted)" name for realpath(file).
16
+ target = join(await fs.realpath(dirname(target)), basename(target));
17
+ let isSymlink;
18
+ try {
19
+ isSymlink = (await fs.lstat(target)).isSymbolicLink();
20
+ }
21
+ catch (error) {
22
+ if (error.code === 'ENOENT' && hops === 0)
23
+ return target;
24
+ throw error;
25
+ }
26
+ if (!isSymlink)
27
+ return target;
28
+ if (hops >= maxSymlinkHops)
29
+ throw new Error('Too many file symlink hops');
30
+ target = resolve(dirname(target), await fs.readlink(target));
31
+ }
32
+ }
33
+ /** Synchronous counterpart of canonicalFilePath; pass `node:fs`. */
34
+ export function canonicalFilePathSync(file, fs) {
35
+ let target = file;
36
+ for (let hops = 0;; hops++) {
37
+ target = join(fs.realpathSync(dirname(target)), basename(target));
38
+ let isSymlink;
39
+ try {
40
+ isSymlink = fs.lstatSync(target).isSymbolicLink();
41
+ }
42
+ catch (error) {
43
+ if (error.code === 'ENOENT' && hops === 0)
44
+ return target;
45
+ throw error;
46
+ }
47
+ if (!isSymlink)
48
+ return target;
49
+ if (hops >= maxSymlinkHops)
50
+ throw new Error('Too many file symlink hops');
51
+ target = resolve(dirname(target), fs.readlinkSync(target));
52
+ }
53
+ }
@@ -9,7 +9,7 @@ import { insulaUsageTransport } from "./d0f0b6be200311af-insula.js";
9
9
  export { ClaustrumCredentialError, } from "@cortexkit/claustrum-client";
10
10
  export { ClaustrumUnreachableError, classifyVaultFailure, VAULT_FAILURE_CLASSES, } from "./94f53cfd572ba4bb-availability.js";
11
11
  export { ClaustrumConsumer, DEFAULT_CONNECT_TIMEOUT_MS, } from "./169b2b4bf30909bc-consumer.js";
12
- export { ClaustrumScopedCustody, decideScopedRetryAfter401, isScopedCredentialRotation, KEPT_RECEIPT_MARGIN_MS, SERVING_MARGIN_MS, } from "./0f77ebc3c914c9c6-custody.js";
12
+ export { ClaustrumScopedCustody, decideScopedRetryAfter401, isScopedCredentialRotation, KEPT_RECEIPT_MARGIN_MS, SERVING_MARGIN_MS, VAULT_RECEIPT_WAIT_MS, VAULT_YOUNG_OUTAGE_MS, } from "./0f77ebc3c914c9c6-custody.js";
13
13
  export { ClaustrumEnrollmentManager, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, validEnrollmentDisplayName, validEnrollmentRequestedGrants, vaultAuthority, } from "./b9588ad4725c1d10-enrollment.js";
14
14
  export { ClaustrumConsumerError, } from "./ca0fccaba1d87af4-errors.js";
15
15
  export { connectVaultHost, hasVaultHost, VAULT_HOST_CONNECT_REFUSAL, VAULT_HOST_STATUS, } from "./c97089ed4243981c-host.js";
@@ -1,4 +1,7 @@
1
1
  export { writeJsonAtomic } from "./7211cfec06a298bc-atomic-write.js";
2
+ // Canonical path of a file other processes may atomically replace: resolves
3
+ // the folder, never the file itself (see canonical-file-path.ts).
4
+ export { canonicalFilePath, canonicalFilePathSync, } from "./cf4c37f3975c3a8d-canonical-file-path.js";
2
5
  export { WRITER_LOCK_CONSTANTS } from "./9b4da614c45f9cd0-lock-constants.js";
3
6
  export { PrivateFileError } from "./375d9cca2def037d-private-files.js";
4
7
  // The try-once lock underneath withLock, for callers that hold a lock across