@git-stunts/git-cas 6.0.1 → 6.2.0

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 (70) hide show
  1. package/ARCHITECTURE.md +120 -6
  2. package/CHANGELOG.md +98 -1
  3. package/GUIDE.md +114 -13
  4. package/README.md +60 -4
  5. package/UPGRADING.md +71 -1
  6. package/build-info.json +2 -2
  7. package/docs/API.md +934 -7
  8. package/docs/WALKTHROUGH.md +46 -0
  9. package/docs/releases/v6.1.0.md +75 -0
  10. package/docs/releases/v6.2.0.md +131 -0
  11. package/index.d.ts +974 -1
  12. package/index.js +354 -1
  13. package/package.json +8 -6
  14. package/src/domain/errors/Codes.js +48 -0
  15. package/src/domain/helpers/assertCanonicalTimestamp.js +15 -0
  16. package/src/domain/helpers/handleTarget.js +48 -0
  17. package/src/domain/helpers/isCanonicalCollectionKey.js +35 -0
  18. package/src/domain/services/AssetService.js +213 -0
  19. package/src/domain/services/BundleDescriptorCodec.js +286 -0
  20. package/src/domain/services/BundleFanoutBuilder.js +247 -0
  21. package/src/domain/services/BundleService.js +848 -0
  22. package/src/domain/services/CacheCandidateHeap.js +71 -0
  23. package/src/domain/services/CacheIndex.js +362 -0
  24. package/src/domain/services/CacheMetadataCodec.js +164 -0
  25. package/src/domain/services/CachePolicyEnforcer.js +144 -0
  26. package/src/domain/services/CacheSet.js +703 -0
  27. package/src/domain/services/CacheSetRegistry.js +88 -0
  28. package/src/domain/services/CasService.d.ts +3 -1
  29. package/src/domain/services/ExpiringSet.js +496 -0
  30. package/src/domain/services/ExpiringSetIndex.js +254 -0
  31. package/src/domain/services/ExpiringSetMetadataCodec.js +160 -0
  32. package/src/domain/services/ExpiringSetRegistry.js +101 -0
  33. package/src/domain/services/PageService.js +175 -0
  34. package/src/domain/services/PublicationService.js +315 -0
  35. package/src/domain/services/RepositoryDoctor.js +649 -0
  36. package/src/domain/services/RetentionService.js +120 -0
  37. package/src/domain/services/RootSet.js +281 -0
  38. package/src/domain/services/RootSetMetadataCodec.js +259 -0
  39. package/src/domain/services/RootSetPersistence.js +335 -0
  40. package/src/domain/services/RootSetRegistry.js +44 -0
  41. package/src/domain/services/RootSetRetryPolicy.js +87 -0
  42. package/src/domain/services/RootSetTreeCodec.js +95 -0
  43. package/src/domain/services/StagingEvidence.js +39 -0
  44. package/src/domain/value-objects/ApplicationHandle.js +40 -0
  45. package/src/domain/value-objects/AssetHandle.js +163 -0
  46. package/src/domain/value-objects/BundleHandle.js +32 -0
  47. package/src/domain/value-objects/BundleLimits.js +80 -0
  48. package/src/domain/value-objects/BundlePath.js +78 -0
  49. package/src/domain/value-objects/CacheHit.js +93 -0
  50. package/src/domain/value-objects/CacheKey.js +32 -0
  51. package/src/domain/value-objects/CachePolicy.js +59 -0
  52. package/src/domain/value-objects/CacheSetRef.js +40 -0
  53. package/src/domain/value-objects/CollectionNamespace.js +54 -0
  54. package/src/domain/value-objects/ExpiringMarker.js +81 -0
  55. package/src/domain/value-objects/ExpiringSetKey.js +28 -0
  56. package/src/domain/value-objects/ExpiringSetRef.js +42 -0
  57. package/src/domain/value-objects/OpaqueHandle.js +171 -0
  58. package/src/domain/value-objects/PageHandle.js +34 -0
  59. package/src/domain/value-objects/RetentionWitness.js +101 -0
  60. package/src/domain/value-objects/RootSetRef.js +88 -0
  61. package/src/domain/value-objects/StagedAsset.js +63 -0
  62. package/src/domain/value-objects/StagedBundle.js +66 -0
  63. package/src/domain/value-objects/StagedPage.js +47 -0
  64. package/src/infrastructure/adapters/GitPersistenceAdapter.js +57 -0
  65. package/src/infrastructure/adapters/GitRefAdapter.js +26 -5
  66. package/src/infrastructure/adapters/GitRepositoryInspectionAdapter.js +164 -0
  67. package/src/package-version.js +1 -1
  68. package/src/ports/GitPersistencePort.js +20 -1
  69. package/src/ports/GitRefPort.js +10 -0
  70. package/src/ports/RepositoryInspectionPort.js +33 -0
package/index.d.ts CHANGED
@@ -41,6 +41,349 @@ export type {
41
41
  RecipientEntry,
42
42
  EncryptionScheme,
43
43
  };
44
+
45
+ export interface AssetHandleData {
46
+ version: 1;
47
+ kind: 'asset';
48
+ format: 'manifest-tree';
49
+ codec: string;
50
+ hashAlgorithm: 'sha1' | 'sha256';
51
+ oid: string;
52
+ }
53
+
54
+ export interface AssetHandleInit {
55
+ version?: 1;
56
+ kind?: 'asset';
57
+ format?: 'manifest-tree';
58
+ codec: string;
59
+ hashAlgorithm?: 'sha1' | 'sha256';
60
+ oid: string;
61
+ }
62
+
63
+ export type AssetHandleInput = AssetHandle | AssetHandleData | AssetHandleInit | string;
64
+
65
+ /** Repository-independent locator for one validated git-cas asset graph. */
66
+ export declare class AssetHandle implements AssetHandleData {
67
+ readonly version: 1;
68
+ readonly kind: 'asset';
69
+ readonly format: 'manifest-tree';
70
+ readonly codec: string;
71
+ readonly hashAlgorithm: 'sha1' | 'sha256';
72
+ readonly oid: string;
73
+ constructor(value: AssetHandleInit);
74
+ static from(value: AssetHandleInput): AssetHandle;
75
+ static parse(token: string): AssetHandle;
76
+ toString(): string;
77
+ toJSON(): AssetHandleData;
78
+ }
79
+
80
+ export interface PageHandleData {
81
+ version: 1;
82
+ kind: 'page';
83
+ format: 'blob';
84
+ codec: 'raw';
85
+ hashAlgorithm: 'sha1' | 'sha256';
86
+ oid: string;
87
+ }
88
+
89
+ export interface PageHandleInit {
90
+ version?: 1;
91
+ kind?: 'page';
92
+ format?: 'blob';
93
+ codec?: 'raw';
94
+ hashAlgorithm?: 'sha1' | 'sha256';
95
+ oid: string;
96
+ }
97
+
98
+ export type PageHandleInput = PageHandle | PageHandleData | PageHandleInit | string;
99
+
100
+ /** Repository-independent locator for one immutable raw page blob. */
101
+ export declare class PageHandle implements PageHandleData {
102
+ readonly version: 1;
103
+ readonly kind: 'page';
104
+ readonly format: 'blob';
105
+ readonly codec: 'raw';
106
+ readonly hashAlgorithm: 'sha1' | 'sha256';
107
+ readonly oid: string;
108
+ constructor(value: PageHandleInit);
109
+ static from(value: PageHandleInput): PageHandle;
110
+ static parse(token: string): PageHandle;
111
+ toString(): string;
112
+ toJSON(): PageHandleData;
113
+ }
114
+
115
+ export interface BundleHandleData {
116
+ version: 1;
117
+ kind: 'bundle';
118
+ format: 'fanout-tree';
119
+ codec: string;
120
+ hashAlgorithm: 'sha1' | 'sha256';
121
+ oid: string;
122
+ }
123
+
124
+ export interface BundleHandleInit {
125
+ version?: 1;
126
+ kind?: 'bundle';
127
+ format?: 'fanout-tree';
128
+ codec: string;
129
+ hashAlgorithm?: 'sha1' | 'sha256';
130
+ oid: string;
131
+ }
132
+
133
+ export type BundleHandleInput = BundleHandle | BundleHandleData | BundleHandleInit | string;
134
+
135
+ /** Repository-independent locator for one structured fanout bundle tree. */
136
+ export declare class BundleHandle implements BundleHandleData {
137
+ readonly version: 1;
138
+ readonly kind: 'bundle';
139
+ readonly format: 'fanout-tree';
140
+ readonly codec: string;
141
+ readonly hashAlgorithm: 'sha1' | 'sha256';
142
+ readonly oid: string;
143
+ constructor(value: BundleHandleInit);
144
+ static from(value: BundleHandleInput): BundleHandle;
145
+ static parse(token: string): BundleHandle;
146
+ toString(): string;
147
+ toJSON(): BundleHandleData;
148
+ }
149
+
150
+ export type ApplicationHandle = AssetHandle | BundleHandle | PageHandle;
151
+ export type ApplicationHandleInput = AssetHandleInput | BundleHandleInput | PageHandleInput;
152
+
153
+ export interface StagedAssetData {
154
+ version: 1;
155
+ state: 'staged';
156
+ handle: string;
157
+ asset: { slug: string; filename: string; size: number };
158
+ retention: {
159
+ policy: null;
160
+ reachability: 'unanchored';
161
+ protection: 'not-established';
162
+ };
163
+ observedAt: string;
164
+ }
165
+
166
+ /** Result for an asset graph written without a reachability root. */
167
+ export declare class StagedAsset {
168
+ readonly version: 1;
169
+ readonly state: 'staged';
170
+ readonly handle: AssetHandle;
171
+ readonly asset: Readonly<{ slug: string; filename: string; size: number }>;
172
+ readonly retention: Readonly<{
173
+ policy: null;
174
+ reachability: 'unanchored';
175
+ protection: 'not-established';
176
+ }>;
177
+ readonly observedAt: string;
178
+ constructor(value: {
179
+ handle: AssetHandleInput;
180
+ slug: string;
181
+ filename: string;
182
+ size: number;
183
+ observedAt: string;
184
+ });
185
+ toJSON(): StagedAssetData;
186
+ }
187
+
188
+ export interface StagedPageData {
189
+ version: 1;
190
+ state: 'staged';
191
+ handle: string;
192
+ page: { size: number };
193
+ retention: {
194
+ policy: null;
195
+ reachability: 'unanchored';
196
+ protection: 'not-established';
197
+ };
198
+ observedAt: string;
199
+ }
200
+
201
+ /** Result for a page blob written without a reachability root. */
202
+ export declare class StagedPage {
203
+ readonly version: 1;
204
+ readonly state: 'staged';
205
+ readonly handle: PageHandle;
206
+ readonly page: Readonly<{ size: number }>;
207
+ readonly retention: Readonly<{
208
+ policy: null;
209
+ reachability: 'unanchored';
210
+ protection: 'not-established';
211
+ }>;
212
+ readonly observedAt: string;
213
+ constructor(value: { handle: PageHandleInput; size: number; observedAt: string });
214
+ toJSON(): StagedPageData;
215
+ }
216
+
217
+ export interface BundleLimits {
218
+ maxMembers: number;
219
+ maxMemberPathBytes: number;
220
+ maxDescriptorBytes: number;
221
+ maxFanoutEntries: number;
222
+ maxFanoutDepth: number;
223
+ }
224
+
225
+ export interface StagedBundleData {
226
+ version: 1;
227
+ state: 'staged';
228
+ handle: string;
229
+ bundle: { memberCount: number; indexDepth: number; descriptorBytes: number };
230
+ limits: BundleLimits;
231
+ retention: {
232
+ policy: null;
233
+ reachability: 'unanchored';
234
+ protection: 'not-established';
235
+ };
236
+ observedAt: string;
237
+ }
238
+
239
+ /** Result for a structured bundle written without a reachability root. */
240
+ export declare class StagedBundle {
241
+ readonly version: 1;
242
+ readonly state: 'staged';
243
+ readonly handle: BundleHandle;
244
+ readonly bundle: Readonly<{
245
+ memberCount: number;
246
+ indexDepth: number;
247
+ descriptorBytes: number;
248
+ }>;
249
+ readonly limits: Readonly<BundleLimits>;
250
+ readonly retention: Readonly<{
251
+ policy: null;
252
+ reachability: 'unanchored';
253
+ protection: 'not-established';
254
+ }>;
255
+ readonly observedAt: string;
256
+ constructor(value: {
257
+ handle: BundleHandleInput;
258
+ memberCount: number;
259
+ indexDepth: number;
260
+ descriptorBytes: number;
261
+ limits: BundleLimits;
262
+ observedAt: string;
263
+ });
264
+ toJSON(): StagedBundleData;
265
+ }
266
+
267
+ export type RetentionPolicy = 'pinned' | 'evictable';
268
+ export type RetentionReachability = 'anchored' | 'orphaned' | 'volatile';
269
+ export type RetentionRootKind = 'root-set' | 'publication' | 'cache-set' | 'expiring-set';
270
+
271
+ export interface RetentionRoot {
272
+ kind: RetentionRootKind;
273
+ namespace: string;
274
+ ref: string;
275
+ generation: string;
276
+ path: string;
277
+ }
278
+
279
+ export interface RetentionWitnessData {
280
+ version: 1;
281
+ handle: string;
282
+ policy: RetentionPolicy;
283
+ reachability: RetentionReachability;
284
+ root: RetentionRoot;
285
+ observedAt: string;
286
+ }
287
+
288
+ /** Immutable evidence for one observed retaining Git generation. */
289
+ export declare class RetentionWitness {
290
+ readonly version: 1;
291
+ readonly handle: ApplicationHandle;
292
+ readonly policy: RetentionPolicy;
293
+ readonly reachability: RetentionReachability;
294
+ readonly root: Readonly<RetentionRoot>;
295
+ readonly observedAt: string;
296
+ constructor(value: {
297
+ handle: ApplicationHandleInput;
298
+ policy: RetentionPolicy;
299
+ reachability: RetentionReachability;
300
+ root: RetentionRoot;
301
+ observedAt: string;
302
+ });
303
+ toJSON(): RetentionWitnessData;
304
+ }
305
+
306
+ export interface CachePolicyData {
307
+ maxEntries: number;
308
+ maxBytes: number | null;
309
+ accessResolutionMs: number;
310
+ }
311
+
312
+ export type CachePolicyOptions = Partial<CachePolicyData>;
313
+
314
+ /** Immutable admission and eviction policy for one CacheSet. */
315
+ export declare class CachePolicy implements CachePolicyData {
316
+ readonly maxEntries: number;
317
+ readonly maxBytes: number | null;
318
+ readonly accessResolutionMs: number;
319
+ constructor(value?: CachePolicyOptions);
320
+ static from(value?: CachePolicy | CachePolicyOptions): CachePolicy;
321
+ toJSON(): CachePolicyData;
322
+ }
323
+
324
+ export interface CacheHitData {
325
+ key: string;
326
+ handle: string;
327
+ policy: RetentionPolicy;
328
+ expiresAt: string | null;
329
+ logicalBytes: number;
330
+ createdAt: string;
331
+ accessedAt: string;
332
+ generation: string;
333
+ evidence: RetentionWitnessData;
334
+ }
335
+
336
+ /** Immutable result for one live cache entry. */
337
+ export declare class CacheHit {
338
+ readonly key: string;
339
+ readonly handle: ApplicationHandle;
340
+ readonly policy: RetentionPolicy;
341
+ readonly expiresAt: string | null;
342
+ readonly logicalBytes: number;
343
+ readonly createdAt: string;
344
+ readonly accessedAt: string;
345
+ readonly generation: string;
346
+ readonly evidence: RetentionWitness;
347
+ constructor(value: {
348
+ key: string;
349
+ handle: ApplicationHandleInput;
350
+ policy: RetentionPolicy;
351
+ expiresAt: string | null;
352
+ logicalBytes: number;
353
+ createdAt: string;
354
+ accessedAt: string;
355
+ generation: string;
356
+ evidence: RetentionWitness | ConstructorParameters<typeof RetentionWitness>[0];
357
+ });
358
+ toJSON(): CacheHitData;
359
+ }
360
+
361
+ export interface ExpiringMarkerData {
362
+ version: 1;
363
+ keyDigest: string;
364
+ expiresAt: string;
365
+ createdAt: string;
366
+ generation: string;
367
+ evidence: RetentionWitnessData;
368
+ }
369
+
370
+ /** Immutable evidence for one live replay marker. */
371
+ export declare class ExpiringMarker {
372
+ readonly version: 1;
373
+ readonly keyDigest: string;
374
+ readonly expiresAt: string;
375
+ readonly createdAt: string;
376
+ readonly generation: string;
377
+ readonly evidence: RetentionWitness;
378
+ constructor(value: {
379
+ keyDigest: string;
380
+ expiresAt: string;
381
+ createdAt: string;
382
+ generation: string;
383
+ evidence: RetentionWitness | ConstructorParameters<typeof RetentionWitness>[0];
384
+ });
385
+ toJSON(): ExpiringMarkerData;
386
+ }
44
387
  export type {
45
388
  CryptoPort,
46
389
  CodecPort,
@@ -138,7 +481,7 @@ export declare class CryptoPortBase {
138
481
  export declare class GitPersistencePortBase {
139
482
  writeBlob(content: Uint8Array): Promise<string>;
140
483
  writeTree(entries: string[]): Promise<string>;
141
- readBlob(oid: string): Promise<Uint8Array>;
484
+ readBlob(oid: string, maxBytes?: number): Promise<Uint8Array>;
142
485
  readBlobStream(oid: string): Promise<AsyncIterable<Uint8Array>>;
143
486
  readTree(
144
487
  treeOid: string
@@ -150,6 +493,8 @@ export declare class GitPersistencePortBase {
150
493
  iterateTree(
151
494
  treeOid: string
152
495
  ): AsyncIterable<{ mode: string; type: string; oid: string; name: string }>;
496
+ readObjectType(oid: string): Promise<string>;
497
+ readObjectSize(oid: string): Promise<number>;
153
498
  setMaxBlobSize?(maxBlobSize: number): void;
154
499
  }
155
500
 
@@ -157,9 +502,11 @@ export declare class GitPersistencePortBase {
157
502
  export declare class GitRefPortBase {
158
503
  resolveRef(ref: string): Promise<string>;
159
504
  resolveTree(commitOid: string): Promise<string>;
505
+ resolveParents(commitOid: string): Promise<string[]>;
160
506
  createCommit(options: {
161
507
  treeOid: string;
162
508
  parentOid?: string | null;
509
+ parentOids?: string[];
163
510
  message: string;
164
511
  }): Promise<string>;
165
512
  updateRef(options: {
@@ -181,6 +528,31 @@ export declare class GitRefAdapter extends GitRefPortBase {
181
528
  constructor(options: { plumbing: unknown; policy?: unknown });
182
529
  }
183
530
 
531
+ export type RepositoryObjectType = 'blob' | 'tree' | 'commit' | 'tag';
532
+
533
+ export interface RepositoryObjectRecord {
534
+ readonly oid: string;
535
+ readonly type: RepositoryObjectType;
536
+ readonly logicalBytes: number;
537
+ readonly physicalBytes: number;
538
+ }
539
+
540
+ /** Abstract non-mutating repository inspection port. */
541
+ export declare class RepositoryInspectionPort {
542
+ iterateObjects(): AsyncIterable<RepositoryObjectRecord>;
543
+ iterateReachableObjectIds(): AsyncIterable<string>;
544
+ iteratePrunableObjects(options: {
545
+ expiresBefore: string;
546
+ }): AsyncIterable<Pick<RepositoryObjectRecord, 'oid' | 'type'>>;
547
+ iterateRefs(): AsyncIterable<{ readonly ref: string; readonly oid: string }>;
548
+ reachablePhysicalBytes(): Promise<number>;
549
+ }
550
+
551
+ /** Git-backed implementation of repository inspection. */
552
+ export declare class GitRepositoryInspectionAdapter extends RepositoryInspectionPort {
553
+ constructor(options: { plumbing: unknown; policy?: unknown });
554
+ }
555
+
184
556
  /** Node.js crypto implementation of CryptoPort. */
185
557
  export declare class NodeCryptoAdapter extends CryptoPortBase {
186
558
  constructor();
@@ -262,6 +634,16 @@ export interface ContentAddressableStoreOptions {
262
634
  maxRestoreBufferSize?: number;
263
635
  /** Safety limit for readBlob metadata in bytes. @default 10485760 (10 MiB) */
264
636
  maxBlobSize?: number;
637
+ /** Maximum immutable page size in bytes. @default 16777216 (16 MiB) */
638
+ maxPageSize?: number;
639
+ /** Repository-wide maximum bundle admission limits. */
640
+ bundleLimits?: Partial<BundleLimits>;
641
+ /** Maximum nested bundle depth. @default 32 */
642
+ maxBundleNestingDepth?: number;
643
+ /** Application-owned ref prefixes permitted for generic publication. */
644
+ applicationRefPrefixes?: string[];
645
+ /** Injectable clock used for deterministic lifecycle evidence. */
646
+ clock?: { now(): Date };
265
647
  }
266
648
 
267
649
  /** Options for {@link ContentAddressableStore.open}. */
@@ -287,6 +669,274 @@ export interface VaultEntry {
287
669
  treeOid: string;
288
670
  }
289
671
 
672
+ export type RootSetEntryType = 'blob' | 'tree';
673
+ export type RootSetRetention = RetentionPolicy;
674
+
675
+ /** One Git object retained by a root set while the entry is present. */
676
+ export interface RootSetEntry {
677
+ name: string;
678
+ oid: string;
679
+ type: RootSetEntryType;
680
+ retention: RootSetRetention;
681
+ }
682
+
683
+ export interface RootSetState {
684
+ ref: string;
685
+ headOid: string | null;
686
+ treeOid: string | null;
687
+ entries: RootSetEntry[];
688
+ }
689
+
690
+ export interface RootSetMutationResult {
691
+ changed: boolean;
692
+ commitOid: string | null;
693
+ treeOid: string | null;
694
+ entries: RootSetEntry[];
695
+ }
696
+
697
+ export interface RootSetDoctorResult {
698
+ healthy: boolean;
699
+ ref: string;
700
+ headOid?: string | null;
701
+ treeOid?: string | null;
702
+ entryCount?: number;
703
+ entries?: RootSetEntry[];
704
+ policyCounts?: { pinned: number; evictable: number };
705
+ reachabilityCounts?: {
706
+ anchored: number;
707
+ missing: number;
708
+ unknown: number;
709
+ orphaned: number;
710
+ volatile: number;
711
+ };
712
+ targets?: Array<RootSetEntry & {
713
+ exists: boolean | null;
714
+ actualType: string | null;
715
+ reachability: 'anchored' | 'missing' | 'unknown';
716
+ }>;
717
+ issues?: Array<Record<string, unknown>>;
718
+ error?: { code: string; message: string };
719
+ }
720
+
721
+ export declare class RootSet {
722
+ readonly ref: string;
723
+ read(): Promise<RootSetState>;
724
+ list(): Promise<RootSetEntry[]>;
725
+ contains(name: string): Promise<boolean>;
726
+ put(entry: Omit<RootSetEntry, 'retention'> & { retention?: RootSetRetention }): Promise<
727
+ RootSetMutationResult & { entry: RootSetEntry; previous: RootSetEntry | null }
728
+ >;
729
+ remove(options: { name: string }): Promise<
730
+ RootSetMutationResult & { removed: RootSetEntry | null }
731
+ >;
732
+ replace(options: {
733
+ entries: Iterable<RootSetEntry>;
734
+ expectedHeadOid?: string | null;
735
+ }): Promise<RootSetMutationResult>;
736
+ mutate(
737
+ mutator: (
738
+ entries: ReadonlyArray<Readonly<RootSetEntry>>,
739
+ state: Readonly<Omit<RootSetState, 'entries'>>,
740
+ ) => Iterable<RootSetEntry> | Promise<Iterable<RootSetEntry>>,
741
+ options?: { expectedHeadOid?: string | null },
742
+ ): Promise<RootSetMutationResult>;
743
+ doctor(): Promise<RootSetDoctorResult>;
744
+ repair(options: { entries: Iterable<RootSetEntry> }): Promise<{
745
+ repaired: true;
746
+ commitOid: string;
747
+ treeOid: string;
748
+ entries: RootSetEntry[];
749
+ }>;
750
+ }
751
+
752
+ export declare class RootSetRegistry {
753
+ open(options: {
754
+ ref: string;
755
+ retry?: { maxAttempts?: number; baseDelayMs?: number };
756
+ }): RootSet;
757
+ }
758
+
759
+ export interface CacheEntryOptions {
760
+ retention?: RetentionPolicy;
761
+ expiresAt?: Date | string | null;
762
+ expectedHandle?: ApplicationHandleInput;
763
+ }
764
+
765
+ export interface CachePolicyReport {
766
+ readonly satisfied: boolean;
767
+ readonly entryCount: number;
768
+ readonly logicalBytes: number;
769
+ readonly pinnedEntries: number;
770
+ readonly evictableEntries: number;
771
+ readonly expiredEntries: number;
772
+ readonly limits: Readonly<CachePolicyData>;
773
+ }
774
+
775
+ export interface CacheStoreResult {
776
+ readonly changed: boolean;
777
+ readonly accepted: boolean;
778
+ readonly hit: CacheHit | null;
779
+ readonly previous: CacheHit | null;
780
+ readonly generation: string | null;
781
+ readonly policy: CachePolicyReport | null;
782
+ readonly witness: RetentionWitness | null;
783
+ }
784
+
785
+ export interface CacheMutationResult {
786
+ readonly changed: boolean;
787
+ readonly generation: string | null;
788
+ readonly policy: CachePolicyReport | null;
789
+ readonly witness: RetentionWitness | null;
790
+ }
791
+
792
+ export interface CacheEntryMetadata {
793
+ readonly version: 1;
794
+ readonly accountingVersion: 1;
795
+ readonly key: string;
796
+ readonly keyDigest: string;
797
+ readonly handle: string;
798
+ readonly policy: RetentionPolicy;
799
+ readonly expiresAt: string | null;
800
+ readonly logicalBytes: number;
801
+ readonly createdAt: string;
802
+ readonly accessedAt: string;
803
+ }
804
+
805
+ export interface CacheState {
806
+ readonly version: 1;
807
+ readonly accountingVersion: 1;
808
+ readonly namespace: string;
809
+ readonly policy: CachePolicyData;
810
+ readonly entryCount: number;
811
+ readonly logicalBytes: number;
812
+ readonly pinnedEntries: number;
813
+ readonly evictableEntries: number;
814
+ readonly expiredEntries: number;
815
+ readonly createdAt: string;
816
+ readonly updatedAt: string;
817
+ readonly oldestAccessedAt: string | null;
818
+ readonly nextExpiry: string | null;
819
+ }
820
+
821
+ export interface CacheInspection {
822
+ readonly namespace: string;
823
+ readonly ref: string;
824
+ readonly generation: string | null;
825
+ readonly state: Readonly<CacheState> | null;
826
+ readonly observed: Readonly<Omit<CacheState, 'version' | 'accountingVersion' | 'namespace' | 'policy' | 'createdAt' | 'updatedAt'>> | null;
827
+ readonly policy: CachePolicyReport | null;
828
+ readonly entries: ReadonlyArray<Readonly<CacheEntryMetadata>>;
829
+ readonly nextCursor: string | null;
830
+ }
831
+
832
+ /** RootSet-backed lifecycle manager for application cache handles. */
833
+ export declare class CacheSet {
834
+ private constructor();
835
+ readonly ref: string;
836
+ get(key: string): Promise<CacheHit | null>;
837
+ put(key: string, handle: ApplicationHandleInput, options?: CacheEntryOptions): Promise<CacheStoreResult>;
838
+ replace(key: string, handle: ApplicationHandleInput, options?: CacheEntryOptions): Promise<CacheStoreResult>;
839
+ remove(key: string): Promise<CacheMutationResult & { readonly removed: CacheHit | null }>;
840
+ touch(key: string): Promise<CacheMutationResult & { readonly hit: CacheHit | null }>;
841
+ sweep(): Promise<CacheMutationResult & { readonly removed: number }>;
842
+ inspect(options?: { limit?: number; cursor?: string | null }): Promise<CacheInspection>;
843
+ doctor(): Promise<Readonly<{
844
+ healthy: boolean;
845
+ root: RootSetDoctorResult;
846
+ state?: Readonly<CacheState>;
847
+ observed?: CacheInspection['observed'];
848
+ policy?: CachePolicyReport;
849
+ issues: ReadonlyArray<Record<string, unknown>>;
850
+ }>>;
851
+ repair(options: {
852
+ entries: Iterable<{
853
+ key: string;
854
+ handle: ApplicationHandleInput;
855
+ retention?: RetentionPolicy;
856
+ expiresAt?: Date | string | null;
857
+ createdAt?: Date | string;
858
+ accessedAt?: Date | string;
859
+ }> | AsyncIterable<{
860
+ key: string;
861
+ handle: ApplicationHandleInput;
862
+ retention?: RetentionPolicy;
863
+ expiresAt?: Date | string | null;
864
+ createdAt?: Date | string;
865
+ accessedAt?: Date | string;
866
+ }>;
867
+ policy?: CachePolicyOptions;
868
+ }): Promise<Readonly<{
869
+ repaired: true;
870
+ generation: string;
871
+ policy: CachePolicyReport;
872
+ witness: RetentionWitness;
873
+ }>>;
874
+ }
875
+
876
+ export interface ExpiringSetSummary {
877
+ readonly entryCount: number;
878
+ readonly liveEntries: number;
879
+ readonly expiredEntries: number;
880
+ readonly nextExpiry: string | null;
881
+ }
882
+
883
+ export interface ExpiringSetState extends ExpiringSetSummary {
884
+ readonly version: 1;
885
+ readonly namespace: string;
886
+ readonly createdAt: string;
887
+ readonly updatedAt: string;
888
+ }
889
+
890
+ export interface ExpiringMarkerInspection {
891
+ readonly keyDigest: string;
892
+ readonly expiresAt: string;
893
+ readonly createdAt: string;
894
+ readonly status: 'live' | 'expired';
895
+ readonly evidence: RetentionWitness;
896
+ }
897
+
898
+ export interface ExpiringSetInspection {
899
+ readonly namespace: string;
900
+ readonly ref: string;
901
+ readonly generation: string | null;
902
+ readonly state: Readonly<ExpiringSetState> | null;
903
+ readonly observed: Readonly<ExpiringSetSummary>;
904
+ readonly markers: ReadonlyArray<Readonly<ExpiringMarkerInspection>>;
905
+ readonly nextCursor: string | null;
906
+ }
907
+
908
+ export interface ExpiringSetAddResult {
909
+ readonly changed: boolean;
910
+ readonly admitted: boolean;
911
+ readonly marker: ExpiringMarker | null;
912
+ readonly generation: string | null;
913
+ readonly witness: RetentionWitness | null;
914
+ }
915
+
916
+ export interface ExpiringSetSweepResult {
917
+ readonly changed: boolean;
918
+ readonly removed: number;
919
+ readonly generation: string | null;
920
+ readonly witness: RetentionWitness | null;
921
+ }
922
+
923
+ /** RootSet-backed replay marker set with expiry-only release semantics. */
924
+ export declare class ExpiringSet {
925
+ private constructor();
926
+ readonly ref: string;
927
+ contains(key: string): Promise<boolean>;
928
+ addIfAbsent(key: string, options: { expiresAt: Date | string }): Promise<ExpiringSetAddResult>;
929
+ sweep(): Promise<ExpiringSetSweepResult>;
930
+ inspect(options?: { limit?: number; cursor?: string | null }): Promise<ExpiringSetInspection>;
931
+ doctor(): Promise<Readonly<{
932
+ healthy: boolean;
933
+ root: RootSetDoctorResult;
934
+ state?: Readonly<ExpiringSetState> | null;
935
+ observed?: Readonly<ExpiringSetSummary>;
936
+ issues: ReadonlyArray<Record<string, unknown>>;
937
+ }>>;
938
+ }
939
+
290
940
  /** Encrypted vault key verifier stored in .vault.json. */
291
941
  export interface VaultEncryptionVerifier {
292
942
  version: 1;
@@ -412,6 +1062,192 @@ export declare class VaultService {
412
1062
  getVaultMetadata(): Promise<VaultMetadata | null>;
413
1063
  }
414
1064
 
1065
+ export interface RepositoryDoctorOptions {
1066
+ /** Canonical UTC cutoff passed to safe prune inspection. Mutually exclusive with gracePeriodMs. */
1067
+ expiresBefore?: string;
1068
+ /** Relative grace period. Defaults to 14 days. Mutually exclusive with expiresBefore. */
1069
+ gracePeriodMs?: number;
1070
+ /** Maximum detailed CacheSet, RootSet, and ExpiringSet reports per kind. @default 100 */
1071
+ maxCollectionsPerKind?: number;
1072
+ }
1073
+
1074
+ export interface RepositoryObjectMetric {
1075
+ readonly objectCount: number | null;
1076
+ readonly physicalBytes: number | null;
1077
+ }
1078
+
1079
+ export interface RepositoryObjectInventory {
1080
+ readonly total: RepositoryObjectMetric & { readonly logicalBytes: number };
1081
+ readonly anchored: RepositoryObjectMetric;
1082
+ readonly orphaned: RepositoryObjectMetric;
1083
+ readonly volatile: RepositoryObjectMetric;
1084
+ readonly unreachable: RepositoryObjectMetric;
1085
+ }
1086
+
1087
+ export interface RepositoryCollectionCoverage {
1088
+ readonly observed: number;
1089
+ readonly inspected: number;
1090
+ readonly detailed: number;
1091
+ readonly complete: boolean;
1092
+ }
1093
+
1094
+ export interface RepositoryDiagnosticLimitation {
1095
+ readonly code: string;
1096
+ readonly message: string;
1097
+ readonly kind?: 'caches' | 'rootSets' | 'expiringSets';
1098
+ readonly observed?: number;
1099
+ readonly inspected?: number;
1100
+ readonly detailed?: number;
1101
+ }
1102
+
1103
+ export interface RepositoryCacheUsage {
1104
+ readonly namespace: string;
1105
+ readonly ref: string;
1106
+ readonly generation: string;
1107
+ readonly healthy: boolean;
1108
+ readonly entryCount: number | null;
1109
+ readonly logicalBytes: number | null;
1110
+ readonly physicalBytes: null;
1111
+ readonly retention: {
1112
+ readonly pinnedEntries: number | null;
1113
+ readonly evictableEntries: number | null;
1114
+ } | null;
1115
+ readonly reachability: 'anchored';
1116
+ readonly age: {
1117
+ readonly createdAt: string | null;
1118
+ readonly updatedAt: string | null;
1119
+ readonly oldestAccessedAt: string | null;
1120
+ } | null;
1121
+ readonly expiry: {
1122
+ readonly expiredEntries: number;
1123
+ readonly nextExpiry: string | null;
1124
+ } | null;
1125
+ readonly policy: Readonly<CachePolicyData> | null;
1126
+ readonly issues: ReadonlyArray<Record<string, unknown>>;
1127
+ }
1128
+
1129
+ export interface RepositoryRootSetUsage {
1130
+ readonly ref: string;
1131
+ readonly generation: string;
1132
+ readonly healthy: boolean;
1133
+ readonly entryCount: number | null;
1134
+ readonly physicalBytes: null;
1135
+ readonly retention: {
1136
+ readonly pinnedEntries: number | null;
1137
+ readonly evictableEntries: number | null;
1138
+ } | null;
1139
+ readonly reachability: RootSetDoctorResult['reachabilityCounts'] | 'anchored' | null;
1140
+ readonly issues: ReadonlyArray<Record<string, unknown>>;
1141
+ }
1142
+
1143
+ export interface RepositoryExpiringSetUsage {
1144
+ readonly namespace: string;
1145
+ readonly ref: string;
1146
+ readonly generation: string;
1147
+ readonly healthy: boolean;
1148
+ readonly entryCount: number | null;
1149
+ readonly physicalBytes: null;
1150
+ readonly reachability: 'anchored';
1151
+ readonly age: {
1152
+ readonly createdAt: string | null;
1153
+ readonly updatedAt: string | null;
1154
+ } | null;
1155
+ readonly expiry: {
1156
+ readonly liveEntries: number;
1157
+ readonly expiredEntries: number;
1158
+ readonly nextExpiry: string | null;
1159
+ } | null;
1160
+ readonly issues: ReadonlyArray<Record<string, unknown>>;
1161
+ }
1162
+
1163
+ export interface RepositoryVaultUsage {
1164
+ readonly ref: string;
1165
+ readonly present: boolean;
1166
+ readonly healthy: boolean;
1167
+ readonly generation: string | null;
1168
+ readonly entryCount: number | null;
1169
+ readonly physicalBytes: null;
1170
+ readonly privacy: boolean | null;
1171
+ readonly reachability: 'anchored' | null;
1172
+ readonly issues: ReadonlyArray<Record<string, unknown>>;
1173
+ }
1174
+
1175
+ export interface RepositoryDoctorReport {
1176
+ readonly version: 1;
1177
+ readonly healthy: boolean;
1178
+ readonly observedAt: string;
1179
+ readonly completedAt: string;
1180
+ readonly policy: {
1181
+ readonly gracePeriodMs: number | null;
1182
+ readonly expiresBefore: string;
1183
+ readonly maxCollectionsPerKind: number;
1184
+ };
1185
+ readonly repository: {
1186
+ readonly objects: RepositoryObjectInventory;
1187
+ readonly roots: {
1188
+ readonly refCount: number;
1189
+ readonly reflogsIncluded: true;
1190
+ readonly reflogCount: null;
1191
+ };
1192
+ readonly evidence: {
1193
+ readonly anchoredInventory: 'refs-and-reflogs';
1194
+ readonly prunableInspection: 'dry-run';
1195
+ readonly mutatesRepository: false;
1196
+ };
1197
+ };
1198
+ readonly usage: {
1199
+ readonly caches: {
1200
+ readonly healthy: boolean;
1201
+ readonly coverage: RepositoryCollectionCoverage;
1202
+ readonly totals: {
1203
+ readonly entryCount: number | null;
1204
+ readonly logicalBytes: number | null;
1205
+ readonly pinnedEntries: number | null;
1206
+ readonly evictableEntries: number | null;
1207
+ readonly expiredEntries: number | null;
1208
+ };
1209
+ readonly entries: ReadonlyArray<RepositoryCacheUsage>;
1210
+ };
1211
+ readonly rootSets: {
1212
+ readonly healthy: boolean;
1213
+ readonly coverage: RepositoryCollectionCoverage;
1214
+ readonly totals: {
1215
+ readonly entryCount: number | null;
1216
+ readonly pinnedEntries: number | null;
1217
+ readonly evictableEntries: number | null;
1218
+ };
1219
+ readonly entries: ReadonlyArray<RepositoryRootSetUsage>;
1220
+ };
1221
+ readonly expiringSets: {
1222
+ readonly healthy: boolean;
1223
+ readonly coverage: RepositoryCollectionCoverage;
1224
+ readonly totals: {
1225
+ readonly entryCount: number | null;
1226
+ readonly liveEntries: number | null;
1227
+ readonly expiredEntries: number | null;
1228
+ };
1229
+ readonly entries: ReadonlyArray<RepositoryExpiringSetUsage>;
1230
+ };
1231
+ readonly vault: RepositoryVaultUsage;
1232
+ };
1233
+ readonly limitations: ReadonlyArray<RepositoryDiagnosticLimitation>;
1234
+ }
1235
+
1236
+ /** Repository-wide, non-mutating diagnostics domain service. */
1237
+ export declare class RepositoryDoctor {
1238
+ constructor(options: {
1239
+ repository: RepositoryInspectionPort;
1240
+ rootSets: { open(options: { ref: string }): RootSet | Promise<RootSet> };
1241
+ caches: { open(options: { namespace: string }): CacheSet | Promise<CacheSet> };
1242
+ expiringSets: {
1243
+ open(options: { namespace: string }): ExpiringSet | Promise<ExpiringSet>;
1244
+ };
1245
+ vault: Pick<VaultService, 'getVaultMetadata' | 'readState'>;
1246
+ clock?: { now(): Date };
1247
+ });
1248
+ doctor(options?: RepositoryDoctorOptions): Promise<RepositoryDoctorReport>;
1249
+ }
1250
+
415
1251
  /** Result of comparing two manifests by chunk digest. */
416
1252
  export interface ManifestDiffResult {
417
1253
  added: Chunk[];
@@ -437,6 +1273,125 @@ export const SCHEME_FRAMED: 'framed';
437
1273
  /** Encryption scheme constant for convergent (dedup-preserving) encryption. */
438
1274
  export const SCHEME_CONVERGENT: 'convergent';
439
1275
 
1276
+ export interface AssetPutOptions {
1277
+ source: AsyncIterable<Uint8Array>;
1278
+ slug: string;
1279
+ filename?: string;
1280
+ encryptionKey?: Uint8Array;
1281
+ passphrase?: string;
1282
+ encryption?: StoreEncryptionOptions;
1283
+ kdfOptions?: Omit<DeriveKeyOptions, 'passphrase'>;
1284
+ compression?: { algorithm: 'gzip' };
1285
+ recipients?: Array<{ label: string; key: Uint8Array }>;
1286
+ merkleThreshold?: number;
1287
+ chunking?: ChunkingConfig;
1288
+ }
1289
+
1290
+ export interface AssetCapability {
1291
+ put(options: AssetPutOptions): Promise<StagedAsset>;
1292
+ adopt(options: { treeOid: string }): Promise<StagedAsset>;
1293
+ open(options: {
1294
+ handle: AssetHandleInput;
1295
+ encryptionKey?: Uint8Array;
1296
+ passphrase?: string;
1297
+ }): AsyncIterable<Uint8Array>;
1298
+ }
1299
+
1300
+ export type PageSource =
1301
+ | Uint8Array
1302
+ | Iterable<Uint8Array>
1303
+ | AsyncIterable<Uint8Array>;
1304
+
1305
+ export interface PageCapability {
1306
+ put(options: { source: PageSource; maxBytes?: number }): Promise<StagedPage>;
1307
+ get(options: { handle: PageHandleInput; maxBytes?: number }): Promise<Uint8Array>;
1308
+ open(options: { handle: PageHandleInput }): AsyncIterable<Uint8Array>;
1309
+ }
1310
+
1311
+ export type BundleMemberInput =
1312
+ | ApplicationHandleInput
1313
+ | PageSource
1314
+ | { source: PageSource; maxBytes?: number };
1315
+
1316
+ export interface BundleMember {
1317
+ readonly version: 1;
1318
+ readonly path: string;
1319
+ readonly handle: ApplicationHandle;
1320
+ readonly type: 'blob' | 'tree';
1321
+ readonly size: number | null;
1322
+ readonly logicalBytes: number;
1323
+ }
1324
+
1325
+ export interface BundleCapability {
1326
+ put(options: {
1327
+ members:
1328
+ | Record<string, BundleMemberInput>
1329
+ | Map<string, BundleMemberInput>
1330
+ | Array<[string, BundleMemberInput]>;
1331
+ limits?: Partial<BundleLimits>;
1332
+ }): Promise<StagedBundle>;
1333
+ putOrdered(options: {
1334
+ members:
1335
+ | Iterable<[string, BundleMemberInput]>
1336
+ | AsyncIterable<[string, BundleMemberInput]>;
1337
+ limits?: Partial<BundleLimits>;
1338
+ }): Promise<StagedBundle>;
1339
+ getMember(options: {
1340
+ handle: BundleHandleInput;
1341
+ path: string;
1342
+ }): Promise<BundleMember | null>;
1343
+ iterateMembers(options: { handle: BundleHandleInput }): AsyncIterable<BundleMember>;
1344
+ openMember(options: { handle: BundleHandleInput; path: string }): AsyncIterable<Uint8Array>;
1345
+ }
1346
+
1347
+ export interface CacheCapability {
1348
+ open(options: {
1349
+ namespace: string;
1350
+ policy?: CachePolicyOptions;
1351
+ retry?: { maxAttempts?: number; baseDelayMs?: number };
1352
+ }): Promise<CacheSet>;
1353
+ }
1354
+
1355
+ export interface ExpiringSetCapability {
1356
+ open(options: {
1357
+ namespace: string;
1358
+ retry?: { maxAttempts?: number; baseDelayMs?: number };
1359
+ }): Promise<ExpiringSet>;
1360
+ }
1361
+
1362
+ export interface DiagnosticsCapability {
1363
+ doctor(options?: RepositoryDoctorOptions): Promise<RepositoryDoctorReport>;
1364
+ }
1365
+
1366
+ export interface RetentionResult {
1367
+ readonly changed: boolean;
1368
+ readonly witness: RetentionWitness;
1369
+ }
1370
+
1371
+ export interface RetentionCapability {
1372
+ retain(options: {
1373
+ handle: ApplicationHandleInput;
1374
+ root: { ref: string; name: string };
1375
+ policy?: RetentionPolicy;
1376
+ }): Promise<RetentionResult>;
1377
+ }
1378
+
1379
+ export interface PublicationResult {
1380
+ readonly operation: 'publication';
1381
+ readonly commitId: string;
1382
+ readonly ref: string;
1383
+ readonly root: ApplicationHandle;
1384
+ readonly witness: RetentionWitness;
1385
+ }
1386
+
1387
+ export interface PublicationCapability {
1388
+ commit(options: {
1389
+ root: ApplicationHandleInput;
1390
+ commit: { message: string; parents?: string[] };
1391
+ ref: { name: string; expected: string | null };
1392
+ }): Promise<PublicationResult>;
1393
+ }
1394
+
440
1395
  /**
441
1396
  * High-level facade for the Content Addressable Store library.
442
1397
  *
@@ -448,8 +1403,26 @@ export default class ContentAddressableStore {
448
1403
 
449
1404
  get chunkSize(): number;
450
1405
 
1406
+ readonly rootSets: {
1407
+ open(options: {
1408
+ ref: string;
1409
+ retry?: { maxAttempts?: number; baseDelayMs?: number };
1410
+ }): Promise<RootSet>;
1411
+ };
1412
+
1413
+ readonly caches: CacheCapability;
1414
+ readonly expiringSets: ExpiringSetCapability;
1415
+ readonly diagnostics: DiagnosticsCapability;
1416
+
1417
+ readonly assets: AssetCapability;
1418
+ readonly pages: PageCapability;
1419
+ readonly bundles: BundleCapability;
1420
+ readonly retention: RetentionCapability;
1421
+ readonly publications: PublicationCapability;
1422
+
451
1423
  getService(): Promise<CasService>;
452
1424
  getVaultService(): Promise<VaultService>;
1425
+ getRootSetRegistry(): Promise<RootSetRegistry>;
453
1426
 
454
1427
  static open(options?: ContentAddressableStoreOpenOptions): Promise<ContentAddressableStore>;
455
1428