@cortexkit/opencode-antigravity-auth 3.0.38 → 3.0.40

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 (129) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +865 -357
  3. package/dist/cli.js.map +4 -4
  4. package/dist/cli.meta.json +136 -39
  5. package/dist/index.js +1509 -657
  6. package/dist/index.js.map +4 -4
  7. package/dist/index.meta.json +188 -49
  8. package/dist/server.js +1662 -803
  9. package/dist/server.js.map +4 -4
  10. package/dist/server.meta.json +1 -1
  11. package/dist/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
  12. package/dist/src/common-auth-embedded/claustrum/availability.js +9 -1
  13. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
  14. package/dist/src/common-auth-embedded/claustrum/custody.js +89 -31
  15. package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +29 -4
  16. package/dist/src/common-auth-embedded/claustrum/enrollment.js +110 -2
  17. package/dist/src/common-auth-embedded/claustrum/host.js +11 -7
  18. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  19. package/dist/src/common-auth-embedded/claustrum/index.js +1 -1
  20. package/dist/src/common-auth-embedded/fs/lock-record.js +55 -0
  21. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +148 -92
  22. package/dist/src/common-auth-embedded/fs/with-lock.js +19 -13
  23. package/dist/src/common-auth-embedded/quota-sidebar/index.d.ts +2 -36
  24. package/dist/src/common-auth-embedded/quota-sidebar/index.tsx +49 -607
  25. package/dist/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
  26. package/dist/src/common-auth-embedded/routing-accessor/cache-policy.js +11 -0
  27. package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
  28. package/dist/src/common-auth-embedded/routing-accessor/index.js +136 -5
  29. package/dist/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  30. package/dist/src/common-auth-embedded/setup/command-error.js +3 -2
  31. package/dist/src/common-auth-embedded/setup/command.js +18 -5
  32. package/dist/src/common-auth-embedded/setup/enroll.d.ts +2 -2
  33. package/dist/src/common-auth-embedded/setup/enroll.js +14 -3
  34. package/dist/src/common-auth-embedded/setup/enrollment-access.js +77 -0
  35. package/dist/src/common-auth-embedded/setup/index.d.ts +1 -1
  36. package/dist/src/common-auth-embedded/setup/types.d.ts +13 -1
  37. package/dist/src/common-auth-embedded/source-output.json +95 -79
  38. package/dist/src/ga/tui/host-ga.d.ts +20 -3
  39. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  40. package/dist/src/ga/tui/host-ga.js +102 -25
  41. package/dist/src/ga/tui/host-ga.js.map +1 -1
  42. package/dist/src/plugin/__fixtures__/release-model-ids.d.ts.map +1 -1
  43. package/dist/src/plugin/__fixtures__/release-model-ids.js +1 -0
  44. package/dist/src/plugin/__fixtures__/release-model-ids.js.map +1 -1
  45. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  46. package/dist/src/plugin/ga-location-services.d.ts +1 -0
  47. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  48. package/dist/src/plugin/ga-location-services.js +6 -0
  49. package/dist/src/plugin/ga-location-services.js.map +1 -1
  50. package/dist/src/plugin/logger.d.ts +3 -1
  51. package/dist/src/plugin/logger.d.ts.map +1 -1
  52. package/dist/src/plugin/logger.js +15 -7
  53. package/dist/src/plugin/logger.js.map +1 -1
  54. package/dist/src/plugin/request.d.ts.map +1 -1
  55. package/dist/src/plugin/request.js +3 -1
  56. package/dist/src/plugin/request.js.map +1 -1
  57. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  58. package/dist/src/plugin/shared/request-services.js +34 -9
  59. package/dist/src/plugin/shared/request-services.js.map +1 -1
  60. package/dist/src/plugin/shared/vault-billing.d.ts +30 -0
  61. package/dist/src/plugin/shared/vault-billing.d.ts.map +1 -0
  62. package/dist/src/plugin/shared/vault-billing.js +196 -0
  63. package/dist/src/plugin/shared/vault-billing.js.map +1 -0
  64. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  65. package/dist/src/plugin/vault-custody.js +3 -0
  66. package/dist/src/plugin/vault-custody.js.map +1 -1
  67. package/dist/src/setup.d.ts.map +1 -1
  68. package/dist/src/setup.js +14 -0
  69. package/dist/src/setup.js.map +1 -1
  70. package/dist/tui-build-map.json +19 -5
  71. package/dist/tui-ga-build-map.json +23 -9
  72. package/dist/types/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
  73. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
  74. package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +29 -4
  75. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  76. package/dist/types/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
  77. package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
  78. package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  79. package/dist/types/src/common-auth-embedded/setup/enroll.d.ts +2 -2
  80. package/dist/types/src/common-auth-embedded/setup/index.d.ts +1 -1
  81. package/dist/types/src/common-auth-embedded/setup/types.d.ts +13 -1
  82. package/dist/types/src/plugin/ga-location-services.d.ts +1 -0
  83. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  84. package/dist/types/src/plugin/logger.d.ts +3 -1
  85. package/dist/types/src/plugin/logger.d.ts.map +1 -1
  86. package/dist/types/src/plugin/request.d.ts.map +1 -1
  87. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  88. package/dist/types/src/plugin/shared/vault-billing.d.ts +30 -0
  89. package/dist/types/src/plugin/shared/vault-billing.d.ts.map +1 -0
  90. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  91. package/dist/types/src/setup.d.ts.map +1 -1
  92. package/package.json +4 -3
  93. package/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
  94. package/src/common-auth-embedded/claustrum/availability.js +9 -1
  95. package/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
  96. package/src/common-auth-embedded/claustrum/custody.js +89 -31
  97. package/src/common-auth-embedded/claustrum/enrollment.d.ts +29 -4
  98. package/src/common-auth-embedded/claustrum/enrollment.js +110 -2
  99. package/src/common-auth-embedded/claustrum/host.js +11 -7
  100. package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  101. package/src/common-auth-embedded/claustrum/index.js +1 -1
  102. package/src/common-auth-embedded/fs/lock-record.js +55 -0
  103. package/src/common-auth-embedded/fs/refresh-file-lock.js +148 -92
  104. package/src/common-auth-embedded/fs/with-lock.js +19 -13
  105. package/src/common-auth-embedded/quota-sidebar/index.d.ts +2 -36
  106. package/src/common-auth-embedded/quota-sidebar/index.tsx +49 -607
  107. package/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
  108. package/src/common-auth-embedded/routing-accessor/cache-policy.js +11 -0
  109. package/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
  110. package/src/common-auth-embedded/routing-accessor/index.js +136 -5
  111. package/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  112. package/src/common-auth-embedded/setup/command-error.js +3 -2
  113. package/src/common-auth-embedded/setup/command.js +18 -5
  114. package/src/common-auth-embedded/setup/enroll.d.ts +2 -2
  115. package/src/common-auth-embedded/setup/enroll.js +14 -3
  116. package/src/common-auth-embedded/setup/enrollment-access.js +77 -0
  117. package/src/common-auth-embedded/setup/index.d.ts +1 -1
  118. package/src/common-auth-embedded/setup/types.d.ts +13 -1
  119. package/src/common-auth-embedded/source-output.json +95 -79
  120. package/src/tui-compiled/common-auth-embedded/quota-sidebar/index.js +36 -674
  121. package/src/tui-compiled/shared/a75d0d866c227b3f-index.js +678 -0
  122. package/src/tui-ga-compiled/host-ga.js +86 -26
  123. package/src/tui-ga-compiled/shared/a75d0d866c227b3f-index.js +678 -0
  124. package/src/tui-ga-compiled/shared/e4ec36f367492969-index.js +36 -674
  125. package/src/tui-ga-raw/host-ga.tsx +122 -25
  126. package/src/tui-ga-raw/shared/a75d0d866c227b3f-index.tsx +681 -0
  127. package/src/tui-ga-raw/shared/e4ec36f367492969-index.tsx +49 -607
  128. package/src/tui-raw/common-auth-embedded/quota-sidebar/index.tsx +49 -607
  129. package/src/tui-raw/shared/a75d0d866c227b3f-index.tsx +681 -0
@@ -68,6 +68,42 @@ export function enrollmentName(plugin, host) {
68
68
  throw new ClaustrumConsumerError('invalid-state', 'Claustrum enrollment names use lowercase letters, digits and dashes');
69
69
  return `${plugin}-${host}`;
70
70
  }
71
+ /** Match the vault's plain-text, code-point limit before proposing a display name. */
72
+ export function validEnrollmentDisplayName(displayName) {
73
+ const length = Array.from(displayName).length;
74
+ return (length >= 1 &&
75
+ length <= 40 &&
76
+ !/[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u200b-\u200d\u2060\ufeff]/u.test(displayName));
77
+ }
78
+ /** Reject malformed permissions before a compatibility retry can omit them. */
79
+ export function validEnrollmentRequestedGrants(grants) {
80
+ return (Array.isArray(grants) &&
81
+ grants.length >= 1 &&
82
+ grants.length <= 4 &&
83
+ Array.from(grants).every((grant) => {
84
+ if (!isRecord(grant) ||
85
+ Object.keys(grant).length !== 2 ||
86
+ (grant.operation !== 'read' && grant.operation !== 'list') ||
87
+ !isRecord(grant.selector))
88
+ return false;
89
+ const keys = Object.keys(grant.selector);
90
+ const key = keys[0];
91
+ return (keys.length === 1 &&
92
+ (key === 'category' || key === 'exact') &&
93
+ typeof grant.selector[key] === 'string' &&
94
+ grant.selector[key].trim().length > 0);
95
+ }));
96
+ }
97
+ function grantProposal(state) {
98
+ return {
99
+ ...(state.requestedGrants !== undefined && {
100
+ requestedGrants: state.requestedGrants,
101
+ }),
102
+ ...(state.requestedGrantsStatus !== undefined && {
103
+ requestedGrantsStatus: state.requestedGrantsStatus,
104
+ }),
105
+ };
106
+ }
71
107
  /**
72
108
  * Connect the enrollment ceremony. Setup calls this; the request path never
73
109
  * does. `connectionFile` is required because this library reads no
@@ -122,6 +158,7 @@ function decodeEnrollmentState(value) {
122
158
  throw invalidState();
123
159
  }
124
160
  if (value.phase === 'pending') {
161
+ const grants = decodeGrantProposal(value);
125
162
  if (!TOKEN_RE.test(String(value.requestSecret ?? '')) ||
126
163
  (value.requestId !== undefined &&
127
164
  (typeof value.requestId !== 'string' ||
@@ -140,9 +177,11 @@ function decodeEnrollmentState(value) {
140
177
  }),
141
178
  createdAt: value.createdAt,
142
179
  updatedAt: value.updatedAt,
180
+ ...grants,
143
181
  };
144
182
  }
145
183
  if (value.phase === 'approved') {
184
+ const grants = decodeGrantProposal(value);
146
185
  if ((value.approvedName !== undefined &&
147
186
  (typeof value.approvedName !== 'string' ||
148
187
  value.approvedName.length === 0)) ||
@@ -159,6 +198,7 @@ function decodeEnrollmentState(value) {
159
198
  }),
160
199
  tokenGeneration: value.tokenGeneration,
161
200
  updatedAt: value.updatedAt,
201
+ ...grants,
162
202
  };
163
203
  }
164
204
  if (value.phase === 'denied' || value.phase === 'blocked') {
@@ -178,6 +218,18 @@ function decodeEnrollmentState(value) {
178
218
  }
179
219
  throw invalidState();
180
220
  }
221
+ function decodeGrantProposal(value) {
222
+ // Optional proposal metadata from a newer version must not invalidate an
223
+ // existing enrollment when a plugin is downgraded. Never infer access from it.
224
+ if ((value.requestedGrants !== undefined &&
225
+ !validEnrollmentRequestedGrants(value.requestedGrants)) ||
226
+ (value.requestedGrantsStatus !== undefined &&
227
+ (value.requestedGrants === undefined ||
228
+ (value.requestedGrantsStatus !== 'sent' &&
229
+ value.requestedGrantsStatus !== 'dropped'))))
230
+ return {};
231
+ return grantProposal(value);
232
+ }
181
233
  function decodeTokenFile(value) {
182
234
  if (!isRecord(value) ||
183
235
  !TOKEN_RE.test(String(value.token ?? '')) ||
@@ -445,6 +497,9 @@ async function readEnrollmentStatus(paths, proposedName) {
445
497
  approvedName: state.approvedName,
446
498
  }),
447
499
  tokenGeneration: token.token_generation,
500
+ ...(state &&
501
+ (state.phase === 'approved' || state.phase === 'pending') &&
502
+ grantProposal(state)),
448
503
  },
449
504
  };
450
505
  }
@@ -527,6 +582,7 @@ function statusFromState(state) {
527
582
  state: 'pending',
528
583
  proposedName: state.proposedName,
529
584
  ...(state.requestId !== undefined && { requestId: state.requestId }),
585
+ ...grantProposal(state),
530
586
  };
531
587
  }
532
588
  if (state.phase === 'approved') {
@@ -537,6 +593,7 @@ function statusFromState(state) {
537
593
  approvedName: state.approvedName,
538
594
  }),
539
595
  tokenGeneration: state.tokenGeneration,
596
+ ...grantProposal(state),
540
597
  };
541
598
  }
542
599
  if (state.phase === 'denied')
@@ -559,15 +616,28 @@ export class ClaustrumEnrollmentManager {
559
616
  #client;
560
617
  #paths;
561
618
  #proposedName;
619
+ #displayName;
620
+ #requestedGrants;
562
621
  #now;
563
622
  #mintSecret;
564
623
  #writeTokenFile;
565
624
  #ancestorOptions;
566
625
  constructor(options) {
626
+ if (options.displayName !== undefined &&
627
+ !validEnrollmentDisplayName(options.displayName))
628
+ throw new ClaustrumConsumerError('invalid-state', 'invalid Claustrum enrollment display name');
629
+ if (options.requestedGrants !== undefined &&
630
+ !validEnrollmentRequestedGrants(options.requestedGrants))
631
+ throw new ClaustrumConsumerError('invalid-state', 'invalid Claustrum enrollment requested grants');
632
+ this.#requestedGrants = options.requestedGrants?.map((grant) => ({
633
+ selector: { ...grant.selector },
634
+ operation: grant.operation,
635
+ }));
567
636
  this.#ancestorOptions = options.ancestorOptions ?? {};
568
637
  this.#client = options.client;
569
638
  this.#paths = options.paths;
570
639
  this.#proposedName = options.proposedName;
640
+ this.#displayName = options.displayName;
571
641
  this.#now = options.now ?? Date.now;
572
642
  this.#mintSecret =
573
643
  options.mintSecret ?? (() => randomBytes(32).toString('hex'));
@@ -615,6 +685,7 @@ export class ClaustrumEnrollmentManager {
615
685
  phase: 'approved',
616
686
  proposedName: state?.proposedName ?? this.#proposedName,
617
687
  tokenGeneration: token.token_generation,
688
+ ...(state && grantProposal(state)),
618
689
  updatedAt: this.#now(),
619
690
  };
620
691
  await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -628,6 +699,7 @@ export class ClaustrumEnrollmentManager {
628
699
  approvedName: state.approvedName,
629
700
  }),
630
701
  tokenGeneration: token.token_generation,
702
+ ...(state.phase === 'approved' && grantProposal(state)),
631
703
  };
632
704
  }
633
705
  if (state?.phase === 'approved') {
@@ -652,6 +724,9 @@ export class ClaustrumEnrollmentManager {
652
724
  requestSecret: this.#mintSecret(),
653
725
  createdAt: now,
654
726
  updatedAt: now,
727
+ ...(this.#requestedGrants !== undefined && {
728
+ requestedGrants: this.#requestedGrants,
729
+ }),
655
730
  };
656
731
  if (!TOKEN_RE.test(state.requestSecret))
657
732
  throw new ClaustrumConsumerError('invalid-state', 'invalid minted Claustrum enrollment secret');
@@ -665,14 +740,44 @@ export class ClaustrumEnrollmentManager {
665
740
  const requestSecretHash = createHash('sha256')
666
741
  .update(Buffer.from(state.requestSecret, 'hex'))
667
742
  .digest('hex');
668
- const proposed = await this.#client.enrollPropose({
743
+ const proposal = {
669
744
  name: state.proposedName,
670
745
  requestSecretHash,
671
- });
746
+ };
747
+ let proposed;
748
+ let requestedGrantsStatus = state.requestedGrantsStatus;
749
+ try {
750
+ proposed = await this.#client.enrollPropose({
751
+ ...proposal,
752
+ ...(this.#displayName !== undefined && {
753
+ displayName: this.#displayName,
754
+ }),
755
+ ...(state.requestedGrants !== undefined && {
756
+ requestedGrants: state.requestedGrants,
757
+ }),
758
+ });
759
+ if (state.requestedGrants !== undefined)
760
+ requestedGrantsStatus = 'sent';
761
+ }
762
+ catch (error) {
763
+ if ((this.#displayName === undefined &&
764
+ state.requestedGrants === undefined) ||
765
+ !(error instanceof ClaustrumCredentialError) ||
766
+ error.code !== 'invalid_params')
767
+ throw error;
768
+ // Both optional fields were validated locally. Older vaults reject
769
+ // either field without storing a proposal, so retry the plain shape once.
770
+ proposed = await this.#client.enrollPropose(proposal);
771
+ if (state.requestedGrants !== undefined)
772
+ requestedGrantsStatus = 'dropped';
773
+ }
672
774
  state = {
673
775
  ...state,
674
776
  requestId: proposed.requestId,
675
777
  updatedAt: this.#now(),
778
+ ...(requestedGrantsStatus !== undefined && {
779
+ requestedGrantsStatus,
780
+ }),
676
781
  };
677
782
  await writeStateAtomic(this.#paths.statePath, state, this.#ancestorOptions);
678
783
  }
@@ -685,6 +790,7 @@ export class ClaustrumEnrollmentManager {
685
790
  state: 'pending',
686
791
  proposedName: state.proposedName,
687
792
  retryCode: refusal.code,
793
+ ...grantProposal(state),
688
794
  };
689
795
  }
690
796
  // A vault without the ceremony cannot hold a request for this
@@ -741,6 +847,7 @@ export class ClaustrumEnrollmentManager {
741
847
  proposedName: state.proposedName,
742
848
  approvedName: outcome.name,
743
849
  tokenGeneration: outcome.tokenGeneration,
850
+ ...grantProposal(state),
744
851
  updatedAt: this.#now(),
745
852
  };
746
853
  await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -756,6 +863,7 @@ export class ClaustrumEnrollmentManager {
756
863
  proposedName: state.proposedName,
757
864
  requestId,
758
865
  retryCode: refusal.code,
866
+ ...grantProposal(state),
759
867
  };
760
868
  }
761
869
  return this.#block(state, refusal.code);
@@ -29,7 +29,10 @@ function hostError(error) {
29
29
  (typeof value.code === 'string' &&
30
30
  classifyVaultFailure(Object.assign(new Error(), { code: value.code })) ===
31
31
  'unreachable'))
32
- return new ClaustrumUnreachableError();
32
+ return new ClaustrumUnreachableError(value.reason === 'host-accessor-missing' ||
33
+ value.reason === 'host-accessor-failed'
34
+ ? value.reason
35
+ : undefined);
33
36
  return error;
34
37
  }
35
38
  function call(operation) {
@@ -101,13 +104,14 @@ export function connectVaultHost(pluginId) {
101
104
  throw new ClaustrumUnreachableError();
102
105
  try {
103
106
  const accessor = globalThis[Symbol.for('cortexkit.vault')];
104
- if (typeof accessor !== 'function')
105
- throw new ClaustrumUnreachableError();
106
- const client = wrapHostClient(accessor(pluginId));
107
- hostClients.add(client);
108
- return client;
107
+ if (typeof accessor === 'function') {
108
+ const client = wrapHostClient(accessor(pluginId));
109
+ hostClients.add(client);
110
+ return client;
111
+ }
109
112
  }
110
113
  catch {
111
- throw new ClaustrumUnreachableError();
114
+ throw new ClaustrumUnreachableError('host-accessor-failed');
112
115
  }
116
+ throw new ClaustrumUnreachableError('host-accessor-missing');
113
117
  }
@@ -4,7 +4,7 @@ export { ClaustrumCredentialError, type ClaustrumReporterSource, type Enrollment
4
4
  export { ClaustrumUnreachableError, classifyVaultFailure, VAULT_FAILURE_CLASSES, type VaultFailureClass, } from './availability.js';
5
5
  export { ClaustrumConsumer, type ClaustrumConsumerOptions, type ClaustrumWatchState, DEFAULT_CONNECT_TIMEOUT_MS, type SendOptions, } from './consumer.js';
6
6
  export { type AccountIdentitySource, type ClassifyingClaustrumFamily, type ClaustrumFamily, type ClaustrumFamilyInput, type ClaustrumRosterWatch, type ClaustrumRosterWatchOptions, type ClaustrumScopedAttempt, type ClaustrumScopedClient, ClaustrumScopedCustody, type ClaustrumScopedIdentity, decideScopedRetryAfter401, type IdentityParser, isScopedCredentialRotation, KEPT_RECEIPT_MARGIN_MS, type KeptReceiptState, type ScopedRetryReason, SERVING_MARGIN_MS, type SkippedVaultReason, type SkippedVaultRecord, type VaultCredential, type VaultCredentialType, type VaultGrantReach, type VaultGrantTuple, type VaultInventory, type VaultRowFacts, } from './custody.js';
7
- export { type ClaustrumEnrollmentClient, type ClaustrumEnrollmentConnection, type ClaustrumEnrollmentDisconnectResult, ClaustrumEnrollmentManager, type ClaustrumEnrollmentPaths, type ClaustrumEnrollmentResetResult, type ClaustrumEnrollmentStatus, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, type EnrollmentDisposition, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, vaultAuthority, } from './enrollment.js';
7
+ export { type ClaustrumEnrollmentClient, type ClaustrumEnrollmentConnection, type ClaustrumEnrollmentDisconnectResult, ClaustrumEnrollmentManager, type ClaustrumEnrollmentPaths, type ClaustrumEnrollmentResetResult, type ClaustrumEnrollmentStatus, type ClaustrumRequestedGrant, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, type EnrollmentDisposition, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, validEnrollmentDisplayName, validEnrollmentRequestedGrants, vaultAuthority, } from './enrollment.js';
8
8
  export { ClaustrumConsumerError, type ClaustrumConsumerFailureKind, type ClaustrumLogger, } from './errors.js';
9
9
  export { connectVaultHost, hasVaultHost, VAULT_HOST_CONNECT_REFUSAL, VAULT_HOST_STATUS, } from './host.js';
10
10
  export { assertHostSlotMatchesMode, assertNotCustodyPlaceholder, CUSTODY_PLACEHOLDER_PREFIX, classifyHostSlot, custodyPlaceholder, custodyPlaceholderKey, type HostSlotContent, isCustodyPlaceholder, isCustodyPlaceholderValue, } from './host-slot.js';
@@ -10,7 +10,7 @@ export { ClaustrumCredentialError, } from '@cortexkit/claustrum-client';
10
10
  export { ClaustrumUnreachableError, classifyVaultFailure, VAULT_FAILURE_CLASSES, } from './availability.js';
11
11
  export { ClaustrumConsumer, DEFAULT_CONNECT_TIMEOUT_MS, } from './consumer.js';
12
12
  export { ClaustrumScopedCustody, decideScopedRetryAfter401, isScopedCredentialRotation, KEPT_RECEIPT_MARGIN_MS, SERVING_MARGIN_MS, } from './custody.js';
13
- export { ClaustrumEnrollmentManager, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, vaultAuthority, } from './enrollment.js';
13
+ export { ClaustrumEnrollmentManager, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, validEnrollmentDisplayName, validEnrollmentRequestedGrants, vaultAuthority, } from './enrollment.js';
14
14
  export { ClaustrumConsumerError, } from './errors.js';
15
15
  export { connectVaultHost, hasVaultHost, VAULT_HOST_CONNECT_REFUSAL, VAULT_HOST_STATUS, } from './host.js';
16
16
  export { assertHostSlotMatchesMode, assertNotCustodyPlaceholder, CUSTODY_PLACEHOLDER_PREFIX, classifyHostSlot, custodyPlaceholder, custodyPlaceholderKey, isCustodyPlaceholder, isCustodyPlaceholderValue, } from './host-slot.js';
@@ -0,0 +1,55 @@
1
+ import { resolve } from 'node:path';
2
+ import { PrivateFileError } from './private-files.js';
3
+ /** A failed open is not evidence of deletion until the same path disappears. */
4
+ export class DisappearedLockRecordError extends Error {
5
+ path;
6
+ code = 'ENOENT';
7
+ constructor(path, cause) {
8
+ super(`Lock record disappeared: ${path}`, { cause });
9
+ this.path = path;
10
+ }
11
+ }
12
+ export function isWindowsAccessDeniedRead(error, paths) {
13
+ return (error instanceof PrivateFileError &&
14
+ error.reason === 'io-error' &&
15
+ error.win32Code === 5 &&
16
+ (error.stage === 'read' || error.stage === 'verify') &&
17
+ paths.some((path) => resolve(path) === error.path));
18
+ }
19
+ /**
20
+ * An exclusive create at the lock or eviction-directory name can fail with
21
+ * ACCESS_DENIED (5) while a holder's delete of that name is still pending. No
22
+ * reread settles a create refusal, so callers retry only under their existing
23
+ * bound and never infer staleness from it. owner.json is deliberately not a
24
+ * candidate: a marker directory created exclusively a moment ago cannot hold a
25
+ * delete-pending old owner.json, so a 5 there is a real refusal and the caller
26
+ * removes the directory it just created.
27
+ */
28
+ export function isWindowsAccessDeniedCreate(error, paths, stage) {
29
+ return (error instanceof PrivateFileError &&
30
+ error.reason === 'io-error' &&
31
+ error.win32Code === 5 &&
32
+ error.stage === stage &&
33
+ paths.some((path) => resolve(path) === error.path));
34
+ }
35
+ export async function readLockRecord(path, read) {
36
+ try {
37
+ return await read();
38
+ }
39
+ catch (error) {
40
+ if (!isWindowsAccessDeniedRead(error, [path]))
41
+ throw error;
42
+ // Windows commonly maps STATUS_DELETE_PENDING to ACCESS_DENIED (5),
43
+ // which can also mean a permission refusal, not a sharing violation.
44
+ // Only a successful fresh read or ENOENT resolves that ambiguity. A
45
+ // persistent refusal escapes to the caller's existing deadline/backoff.
46
+ try {
47
+ return await read();
48
+ }
49
+ catch (recheckError) {
50
+ if (recheckError.code === 'ENOENT')
51
+ throw new DisappearedLockRecordError(path, error);
52
+ throw error;
53
+ }
54
+ }
55
+ }