@git-stunts/git-cas 6.1.0 → 6.3.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 (69) hide show
  1. package/ARCHITECTURE.md +116 -3
  2. package/CHANGELOG.md +117 -2
  3. package/GUIDE.md +114 -13
  4. package/README.md +60 -4
  5. package/UPGRADING.md +75 -0
  6. package/build-info.json +2 -2
  7. package/docs/API.md +867 -16
  8. package/docs/releases/v6.2.0.md +131 -0
  9. package/docs/releases/v6.3.0.md +96 -0
  10. package/index.d.ts +972 -2
  11. package/index.js +326 -1
  12. package/package.json +4 -2
  13. package/src/domain/errors/Codes.js +39 -0
  14. package/src/domain/helpers/assertCanonicalTimestamp.js +15 -0
  15. package/src/domain/helpers/handleTarget.js +48 -0
  16. package/src/domain/helpers/isCanonicalCollectionKey.js +35 -0
  17. package/src/domain/services/AssetService.js +213 -0
  18. package/src/domain/services/BundleDescriptorCodec.js +286 -0
  19. package/src/domain/services/BundleFanoutBuilder.js +247 -0
  20. package/src/domain/services/BundleService.js +848 -0
  21. package/src/domain/services/CacheAcquisitionInventory.js +123 -0
  22. package/src/domain/services/CacheAcquisitionRegistry.js +188 -0
  23. package/src/domain/services/CacheCandidateHeap.js +71 -0
  24. package/src/domain/services/CacheIndex.js +362 -0
  25. package/src/domain/services/CacheMetadataCodec.js +164 -0
  26. package/src/domain/services/CachePolicyEnforcer.js +144 -0
  27. package/src/domain/services/CacheSet.js +754 -0
  28. package/src/domain/services/CacheSetRegistry.js +95 -0
  29. package/src/domain/services/CasService.d.ts +2 -1
  30. package/src/domain/services/ExpiringSet.js +496 -0
  31. package/src/domain/services/ExpiringSetIndex.js +254 -0
  32. package/src/domain/services/ExpiringSetMetadataCodec.js +160 -0
  33. package/src/domain/services/ExpiringSetRegistry.js +101 -0
  34. package/src/domain/services/PageService.js +175 -0
  35. package/src/domain/services/PublicationService.js +315 -0
  36. package/src/domain/services/RepositoryDoctor.js +676 -0
  37. package/src/domain/services/RetentionService.js +120 -0
  38. package/src/domain/services/RootSet.js +10 -6
  39. package/src/domain/services/RootSetMetadataCodec.js +8 -2
  40. package/src/domain/services/RootSetPersistence.js +3 -2
  41. package/src/domain/services/StagingEvidence.js +39 -0
  42. package/src/domain/value-objects/ApplicationHandle.js +40 -0
  43. package/src/domain/value-objects/AssetHandle.js +163 -0
  44. package/src/domain/value-objects/BundleHandle.js +32 -0
  45. package/src/domain/value-objects/BundleLimits.js +80 -0
  46. package/src/domain/value-objects/BundlePath.js +78 -0
  47. package/src/domain/value-objects/CacheAcquisition.js +88 -0
  48. package/src/domain/value-objects/CacheAcquisitionRef.js +129 -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 +106 -0
  60. package/src/domain/value-objects/StagedAsset.js +63 -0
  61. package/src/domain/value-objects/StagedBundle.js +66 -0
  62. package/src/domain/value-objects/StagedPage.js +47 -0
  63. package/src/infrastructure/adapters/GitPersistenceAdapter.js +48 -20
  64. package/src/infrastructure/adapters/GitRefAdapter.js +318 -7
  65. package/src/infrastructure/adapters/GitRepositoryInspectionAdapter.js +182 -0
  66. package/src/package-version.js +1 -1
  67. package/src/ports/GitPersistencePort.js +11 -1
  68. package/src/ports/GitRefPort.js +46 -0
  69. package/src/ports/RepositoryInspectionPort.js +36 -0
package/index.d.ts CHANGED
@@ -41,6 +41,382 @@ 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 =
270
+ | 'root-set'
271
+ | 'publication'
272
+ | 'cache-set'
273
+ | 'expiring-set';
274
+
275
+ export interface RetentionRoot {
276
+ kind: RetentionRootKind;
277
+ namespace: string;
278
+ ref: string;
279
+ generation: string;
280
+ path: string;
281
+ }
282
+
283
+ export interface RetentionWitnessData {
284
+ version: 1;
285
+ handle: string;
286
+ policy: RetentionPolicy;
287
+ reachability: RetentionReachability;
288
+ root: RetentionRoot;
289
+ observedAt: string;
290
+ }
291
+
292
+ /** Immutable evidence for one observed retaining Git generation. */
293
+ export declare class RetentionWitness {
294
+ readonly version: 1;
295
+ readonly handle: ApplicationHandle;
296
+ readonly policy: RetentionPolicy;
297
+ readonly reachability: RetentionReachability;
298
+ readonly root: Readonly<RetentionRoot>;
299
+ readonly observedAt: string;
300
+ constructor(value: {
301
+ handle: ApplicationHandleInput;
302
+ policy: RetentionPolicy;
303
+ reachability: RetentionReachability;
304
+ root: RetentionRoot;
305
+ observedAt: string;
306
+ });
307
+ toJSON(): RetentionWitnessData;
308
+ }
309
+
310
+ export interface CachePolicyData {
311
+ maxEntries: number;
312
+ maxBytes: number | null;
313
+ accessResolutionMs: number;
314
+ }
315
+
316
+ export type CachePolicyOptions = Partial<CachePolicyData>;
317
+
318
+ /** Immutable admission and eviction policy for one CacheSet. */
319
+ export declare class CachePolicy implements CachePolicyData {
320
+ readonly maxEntries: number;
321
+ readonly maxBytes: number | null;
322
+ readonly accessResolutionMs: number;
323
+ constructor(value?: CachePolicyOptions);
324
+ static from(value?: CachePolicy | CachePolicyOptions): CachePolicy;
325
+ toJSON(): CachePolicyData;
326
+ }
327
+
328
+ export interface CacheHitData {
329
+ key: string;
330
+ handle: string;
331
+ policy: RetentionPolicy;
332
+ expiresAt: string | null;
333
+ logicalBytes: number;
334
+ createdAt: string;
335
+ accessedAt: string;
336
+ generation: string;
337
+ evidence: RetentionWitnessData;
338
+ }
339
+
340
+ /** Immutable result for one live cache entry. */
341
+ export declare class CacheHit {
342
+ readonly key: string;
343
+ readonly handle: ApplicationHandle;
344
+ readonly policy: RetentionPolicy;
345
+ readonly expiresAt: string | null;
346
+ readonly logicalBytes: number;
347
+ readonly createdAt: string;
348
+ readonly accessedAt: string;
349
+ readonly generation: string;
350
+ readonly evidence: RetentionWitness;
351
+ constructor(value: {
352
+ key: string;
353
+ handle: ApplicationHandleInput;
354
+ policy: RetentionPolicy;
355
+ expiresAt: string | null;
356
+ logicalBytes: number;
357
+ createdAt: string;
358
+ accessedAt: string;
359
+ generation: string;
360
+ evidence: RetentionWitness | ConstructorParameters<typeof RetentionWitness>[0];
361
+ });
362
+ toJSON(): CacheHitData;
363
+ }
364
+
365
+ export interface CacheAcquisitionRelease {
366
+ readonly id: string;
367
+ readonly generation: string;
368
+ readonly changed: boolean;
369
+ readonly releasedAt: string;
370
+ }
371
+
372
+ /** Active, explicitly releasable retention scope for one cache hit. */
373
+ export interface CacheAcquisition {
374
+ readonly id: string;
375
+ readonly hit: CacheHit;
376
+ readonly evidence: RetentionWitness;
377
+ readonly acquiredAt: string;
378
+ release(): Promise<CacheAcquisitionRelease>;
379
+ }
380
+
381
+ export interface CacheAcquisitionInspectionEntry {
382
+ readonly id: string;
383
+ readonly generation: string;
384
+ readonly acquiredAt: string;
385
+ readonly keyDigest: string;
386
+ }
387
+
388
+ export interface CacheAcquisitionInspection {
389
+ readonly namespace: string;
390
+ readonly entries: ReadonlyArray<CacheAcquisitionInspectionEntry>;
391
+ readonly truncated: boolean;
392
+ }
393
+
394
+ export interface ExpiringMarkerData {
395
+ version: 1;
396
+ keyDigest: string;
397
+ expiresAt: string;
398
+ createdAt: string;
399
+ generation: string;
400
+ evidence: RetentionWitnessData;
401
+ }
402
+
403
+ /** Immutable evidence for one live replay marker. */
404
+ export declare class ExpiringMarker {
405
+ readonly version: 1;
406
+ readonly keyDigest: string;
407
+ readonly expiresAt: string;
408
+ readonly createdAt: string;
409
+ readonly generation: string;
410
+ readonly evidence: RetentionWitness;
411
+ constructor(value: {
412
+ keyDigest: string;
413
+ expiresAt: string;
414
+ createdAt: string;
415
+ generation: string;
416
+ evidence: RetentionWitness | ConstructorParameters<typeof RetentionWitness>[0];
417
+ });
418
+ toJSON(): ExpiringMarkerData;
419
+ }
44
420
  export type {
45
421
  CryptoPort,
46
422
  CodecPort,
@@ -138,7 +514,7 @@ export declare class CryptoPortBase {
138
514
  export declare class GitPersistencePortBase {
139
515
  writeBlob(content: Uint8Array): Promise<string>;
140
516
  writeTree(entries: string[]): Promise<string>;
141
- readBlob(oid: string): Promise<Uint8Array>;
517
+ readBlob(oid: string, maxBytes?: number): Promise<Uint8Array>;
142
518
  readBlobStream(oid: string): Promise<AsyncIterable<Uint8Array>>;
143
519
  readTree(
144
520
  treeOid: string
@@ -151,6 +527,7 @@ export declare class GitPersistencePortBase {
151
527
  treeOid: string
152
528
  ): AsyncIterable<{ mode: string; type: string; oid: string; name: string }>;
153
529
  readObjectType(oid: string): Promise<string>;
530
+ readObjectSize(oid: string): Promise<number>;
154
531
  setMaxBlobSize?(maxBlobSize: number): void;
155
532
  }
156
533
 
@@ -162,6 +539,7 @@ export declare class GitRefPortBase {
162
539
  createCommit(options: {
163
540
  treeOid: string;
164
541
  parentOid?: string | null;
542
+ parentOids?: string[];
165
543
  message: string;
166
544
  }): Promise<string>;
167
545
  updateRef(options: {
@@ -170,6 +548,16 @@ export declare class GitRefPortBase {
170
548
  /** Expected current OID for CAS; null means the ref must not exist. */
171
549
  expectedOldOid?: string | null;
172
550
  }): Promise<void>;
551
+ anchorRef?(options: {
552
+ sourceRef: string;
553
+ expectedSourceOid: string;
554
+ targetRef: string;
555
+ }): Promise<boolean>;
556
+ deleteRef?(options: { ref: string; expectedOldOid: string }): Promise<boolean>;
557
+ iterateRefs?(options: {
558
+ prefix?: string;
559
+ limit: number;
560
+ }): AsyncIterable<{ ref: string; oid: string; symref: string | null }>;
173
561
  }
174
562
 
175
563
  /** Git-backed implementation of the persistence port. */
@@ -181,6 +569,50 @@ export declare class GitPersistenceAdapter extends GitPersistencePortBase {
181
569
  /** Git-backed implementation of the ref port. */
182
570
  export declare class GitRefAdapter extends GitRefPortBase {
183
571
  constructor(options: { plumbing: unknown; policy?: unknown });
572
+ anchorRef(options: {
573
+ sourceRef: string;
574
+ expectedSourceOid: string;
575
+ targetRef: string;
576
+ }): Promise<boolean>;
577
+ deleteRef(options: { ref: string; expectedOldOid: string }): Promise<boolean>;
578
+ iterateRefs(options: {
579
+ prefix?: string;
580
+ limit: number;
581
+ }): AsyncIterable<{ ref: string; oid: string; symref: string | null }>;
582
+ }
583
+
584
+ export type RepositoryObjectType = 'blob' | 'tree' | 'commit' | 'tag';
585
+
586
+ export interface RepositoryObjectRecord {
587
+ readonly oid: string;
588
+ readonly type: RepositoryObjectType;
589
+ readonly logicalBytes: number;
590
+ readonly physicalBytes: number;
591
+ }
592
+
593
+ export interface RepositoryRefRecord {
594
+ readonly ref: string;
595
+ readonly oid: string;
596
+ /** Present when the inspection adapter can distinguish symbolic refs. */
597
+ readonly symref?: string | null;
598
+ }
599
+
600
+ /** Abstract non-mutating repository inspection port. */
601
+ export declare class RepositoryInspectionPort {
602
+ iterateObjects(): AsyncIterable<RepositoryObjectRecord>;
603
+ iterateReachableObjectIds(): AsyncIterable<string>;
604
+ iteratePrunableObjects(options: {
605
+ expiresBefore: string;
606
+ }): AsyncIterable<Pick<RepositoryObjectRecord, 'oid' | 'type'>>;
607
+ iterateRefs(options?: {
608
+ prefix?: string;
609
+ }): AsyncIterable<RepositoryRefRecord>;
610
+ reachablePhysicalBytes(): Promise<number>;
611
+ }
612
+
613
+ /** Git-backed implementation of repository inspection. */
614
+ export declare class GitRepositoryInspectionAdapter extends RepositoryInspectionPort {
615
+ constructor(options: { plumbing: unknown; policy?: unknown });
184
616
  }
185
617
 
186
618
  /** Node.js crypto implementation of CryptoPort. */
@@ -264,6 +696,16 @@ export interface ContentAddressableStoreOptions {
264
696
  maxRestoreBufferSize?: number;
265
697
  /** Safety limit for readBlob metadata in bytes. @default 10485760 (10 MiB) */
266
698
  maxBlobSize?: number;
699
+ /** Maximum immutable page size in bytes. @default 16777216 (16 MiB) */
700
+ maxPageSize?: number;
701
+ /** Repository-wide maximum bundle admission limits. */
702
+ bundleLimits?: Partial<BundleLimits>;
703
+ /** Maximum nested bundle depth. @default 32 */
704
+ maxBundleNestingDepth?: number;
705
+ /** Application-owned ref prefixes permitted for generic publication. */
706
+ applicationRefPrefixes?: string[];
707
+ /** Injectable clock used for deterministic lifecycle evidence. */
708
+ clock?: { now(): Date };
267
709
  }
268
710
 
269
711
  /** Options for {@link ContentAddressableStore.open}. */
@@ -290,7 +732,7 @@ export interface VaultEntry {
290
732
  }
291
733
 
292
734
  export type RootSetEntryType = 'blob' | 'tree';
293
- export type RootSetRetention = 'pinned' | 'evictable';
735
+ export type RootSetRetention = RetentionPolicy;
294
736
 
295
737
  /** One Git object retained by a root set while the entry is present. */
296
738
  export interface RootSetEntry {
@@ -356,6 +798,7 @@ export declare class RootSet {
356
798
  mutate(
357
799
  mutator: (
358
800
  entries: ReadonlyArray<Readonly<RootSetEntry>>,
801
+ state: Readonly<Omit<RootSetState, 'entries'>>,
359
802
  ) => Iterable<RootSetEntry> | Promise<Iterable<RootSetEntry>>,
360
803
  options?: { expectedHeadOid?: string | null },
361
804
  ): Promise<RootSetMutationResult>;
@@ -375,6 +818,195 @@ export declare class RootSetRegistry {
375
818
  }): RootSet;
376
819
  }
377
820
 
821
+ export interface CacheEntryOptions {
822
+ retention?: RetentionPolicy;
823
+ expiresAt?: Date | string | null;
824
+ expectedHandle?: ApplicationHandleInput;
825
+ }
826
+
827
+ export interface CachePolicyReport {
828
+ readonly satisfied: boolean;
829
+ readonly entryCount: number;
830
+ readonly logicalBytes: number;
831
+ readonly pinnedEntries: number;
832
+ readonly evictableEntries: number;
833
+ readonly expiredEntries: number;
834
+ readonly limits: Readonly<CachePolicyData>;
835
+ }
836
+
837
+ export interface CacheStoreResult {
838
+ readonly changed: boolean;
839
+ readonly accepted: boolean;
840
+ readonly hit: CacheHit | null;
841
+ readonly previous: CacheHit | null;
842
+ readonly generation: string | null;
843
+ readonly policy: CachePolicyReport | null;
844
+ readonly witness: RetentionWitness | null;
845
+ }
846
+
847
+ export interface CacheMutationResult {
848
+ readonly changed: boolean;
849
+ readonly generation: string | null;
850
+ readonly policy: CachePolicyReport | null;
851
+ readonly witness: RetentionWitness | null;
852
+ }
853
+
854
+ export interface CacheEntryMetadata {
855
+ readonly version: 1;
856
+ readonly accountingVersion: 1;
857
+ readonly key: string;
858
+ readonly keyDigest: string;
859
+ readonly handle: string;
860
+ readonly policy: RetentionPolicy;
861
+ readonly expiresAt: string | null;
862
+ readonly logicalBytes: number;
863
+ readonly createdAt: string;
864
+ readonly accessedAt: string;
865
+ }
866
+
867
+ export interface CacheState {
868
+ readonly version: 1;
869
+ readonly accountingVersion: 1;
870
+ readonly namespace: string;
871
+ readonly policy: CachePolicyData;
872
+ readonly entryCount: number;
873
+ readonly logicalBytes: number;
874
+ readonly pinnedEntries: number;
875
+ readonly evictableEntries: number;
876
+ readonly expiredEntries: number;
877
+ readonly createdAt: string;
878
+ readonly updatedAt: string;
879
+ readonly oldestAccessedAt: string | null;
880
+ readonly nextExpiry: string | null;
881
+ }
882
+
883
+ export interface CacheInspection {
884
+ readonly namespace: string;
885
+ readonly ref: string;
886
+ readonly generation: string | null;
887
+ readonly state: Readonly<CacheState> | null;
888
+ readonly observed: Readonly<Omit<CacheState, 'version' | 'accountingVersion' | 'namespace' | 'policy' | 'createdAt' | 'updatedAt'>> | null;
889
+ readonly policy: CachePolicyReport | null;
890
+ readonly entries: ReadonlyArray<Readonly<CacheEntryMetadata>>;
891
+ readonly nextCursor: string | null;
892
+ }
893
+
894
+ /** RootSet-backed lifecycle manager for application cache handles. */
895
+ export declare class CacheSet {
896
+ private constructor();
897
+ readonly ref: string;
898
+ get(key: string): Promise<CacheHit | null>;
899
+ acquire(key: string): Promise<CacheAcquisition | null>;
900
+ inspectAcquisitions(options?: {
901
+ limit?: number;
902
+ }): Promise<CacheAcquisitionInspection>;
903
+ releaseAcquisition(options: {
904
+ id: string;
905
+ expectedGeneration: string;
906
+ }): Promise<CacheAcquisitionRelease>;
907
+ put(key: string, handle: ApplicationHandleInput, options?: CacheEntryOptions): Promise<CacheStoreResult>;
908
+ replace(key: string, handle: ApplicationHandleInput, options?: CacheEntryOptions): Promise<CacheStoreResult>;
909
+ remove(key: string): Promise<CacheMutationResult & { readonly removed: CacheHit | null }>;
910
+ touch(key: string): Promise<CacheMutationResult & { readonly hit: CacheHit | null }>;
911
+ sweep(): Promise<CacheMutationResult & { readonly removed: number }>;
912
+ inspect(options?: { limit?: number; cursor?: string | null }): Promise<CacheInspection>;
913
+ doctor(): Promise<Readonly<{
914
+ healthy: boolean;
915
+ root: RootSetDoctorResult;
916
+ state?: Readonly<CacheState>;
917
+ observed?: CacheInspection['observed'];
918
+ policy?: CachePolicyReport;
919
+ issues: ReadonlyArray<Record<string, unknown>>;
920
+ }>>;
921
+ repair(options: {
922
+ entries: Iterable<{
923
+ key: string;
924
+ handle: ApplicationHandleInput;
925
+ retention?: RetentionPolicy;
926
+ expiresAt?: Date | string | null;
927
+ createdAt?: Date | string;
928
+ accessedAt?: Date | string;
929
+ }> | AsyncIterable<{
930
+ key: string;
931
+ handle: ApplicationHandleInput;
932
+ retention?: RetentionPolicy;
933
+ expiresAt?: Date | string | null;
934
+ createdAt?: Date | string;
935
+ accessedAt?: Date | string;
936
+ }>;
937
+ policy?: CachePolicyOptions;
938
+ }): Promise<Readonly<{
939
+ repaired: true;
940
+ generation: string;
941
+ policy: CachePolicyReport;
942
+ witness: RetentionWitness;
943
+ }>>;
944
+ }
945
+
946
+ export interface ExpiringSetSummary {
947
+ readonly entryCount: number;
948
+ readonly liveEntries: number;
949
+ readonly expiredEntries: number;
950
+ readonly nextExpiry: string | null;
951
+ }
952
+
953
+ export interface ExpiringSetState extends ExpiringSetSummary {
954
+ readonly version: 1;
955
+ readonly namespace: string;
956
+ readonly createdAt: string;
957
+ readonly updatedAt: string;
958
+ }
959
+
960
+ export interface ExpiringMarkerInspection {
961
+ readonly keyDigest: string;
962
+ readonly expiresAt: string;
963
+ readonly createdAt: string;
964
+ readonly status: 'live' | 'expired';
965
+ readonly evidence: RetentionWitness;
966
+ }
967
+
968
+ export interface ExpiringSetInspection {
969
+ readonly namespace: string;
970
+ readonly ref: string;
971
+ readonly generation: string | null;
972
+ readonly state: Readonly<ExpiringSetState> | null;
973
+ readonly observed: Readonly<ExpiringSetSummary>;
974
+ readonly markers: ReadonlyArray<Readonly<ExpiringMarkerInspection>>;
975
+ readonly nextCursor: string | null;
976
+ }
977
+
978
+ export interface ExpiringSetAddResult {
979
+ readonly changed: boolean;
980
+ readonly admitted: boolean;
981
+ readonly marker: ExpiringMarker | null;
982
+ readonly generation: string | null;
983
+ readonly witness: RetentionWitness | null;
984
+ }
985
+
986
+ export interface ExpiringSetSweepResult {
987
+ readonly changed: boolean;
988
+ readonly removed: number;
989
+ readonly generation: string | null;
990
+ readonly witness: RetentionWitness | null;
991
+ }
992
+
993
+ /** RootSet-backed replay marker set with expiry-only release semantics. */
994
+ export declare class ExpiringSet {
995
+ private constructor();
996
+ readonly ref: string;
997
+ contains(key: string): Promise<boolean>;
998
+ addIfAbsent(key: string, options: { expiresAt: Date | string }): Promise<ExpiringSetAddResult>;
999
+ sweep(): Promise<ExpiringSetSweepResult>;
1000
+ inspect(options?: { limit?: number; cursor?: string | null }): Promise<ExpiringSetInspection>;
1001
+ doctor(): Promise<Readonly<{
1002
+ healthy: boolean;
1003
+ root: RootSetDoctorResult;
1004
+ state?: Readonly<ExpiringSetState> | null;
1005
+ observed?: Readonly<ExpiringSetSummary>;
1006
+ issues: ReadonlyArray<Record<string, unknown>>;
1007
+ }>>;
1008
+ }
1009
+
378
1010
  /** Encrypted vault key verifier stored in .vault.json. */
379
1011
  export interface VaultEncryptionVerifier {
380
1012
  version: 1;
@@ -500,6 +1132,215 @@ export declare class VaultService {
500
1132
  getVaultMetadata(): Promise<VaultMetadata | null>;
501
1133
  }
502
1134
 
1135
+ export interface RepositoryDoctorOptions {
1136
+ /** Canonical UTC cutoff passed to safe prune inspection. Mutually exclusive with gracePeriodMs. */
1137
+ expiresBefore?: string;
1138
+ /** Relative grace period. Defaults to 14 days. Mutually exclusive with expiresBefore. */
1139
+ gracePeriodMs?: number;
1140
+ /** Maximum detailed CacheSet, RootSet, and ExpiringSet reports per kind. @default 100 */
1141
+ maxCollectionsPerKind?: number;
1142
+ }
1143
+
1144
+ export interface RepositoryObjectMetric {
1145
+ readonly objectCount: number | null;
1146
+ readonly physicalBytes: number | null;
1147
+ }
1148
+
1149
+ export interface RepositoryObjectInventory {
1150
+ readonly total: RepositoryObjectMetric & { readonly logicalBytes: number };
1151
+ readonly anchored: RepositoryObjectMetric;
1152
+ readonly orphaned: RepositoryObjectMetric;
1153
+ readonly volatile: RepositoryObjectMetric;
1154
+ readonly unreachable: RepositoryObjectMetric;
1155
+ }
1156
+
1157
+ export interface RepositoryCollectionCoverage {
1158
+ readonly observed: number;
1159
+ readonly inspected: number;
1160
+ readonly detailed: number;
1161
+ readonly complete: boolean;
1162
+ }
1163
+
1164
+ export interface RepositoryDiagnosticLimitation {
1165
+ readonly code: string;
1166
+ readonly message: string;
1167
+ readonly kind?: 'caches' | 'rootSets' | 'expiringSets';
1168
+ readonly observed?: number;
1169
+ readonly inspected?: number;
1170
+ readonly detailed?: number;
1171
+ }
1172
+
1173
+ export interface RepositoryCacheUsage {
1174
+ readonly namespace: string;
1175
+ readonly ref: string;
1176
+ readonly generation: string;
1177
+ readonly healthy: boolean;
1178
+ readonly entryCount: number | null;
1179
+ readonly logicalBytes: number | null;
1180
+ readonly physicalBytes: null;
1181
+ readonly retention: {
1182
+ readonly pinnedEntries: number | null;
1183
+ readonly evictableEntries: number | null;
1184
+ } | null;
1185
+ readonly reachability: 'anchored';
1186
+ readonly age: {
1187
+ readonly createdAt: string | null;
1188
+ readonly updatedAt: string | null;
1189
+ readonly oldestAccessedAt: string | null;
1190
+ } | null;
1191
+ readonly expiry: {
1192
+ readonly expiredEntries: number;
1193
+ readonly nextExpiry: string | null;
1194
+ } | null;
1195
+ readonly policy: Readonly<CachePolicyData> | null;
1196
+ readonly issues: ReadonlyArray<Record<string, unknown>>;
1197
+ }
1198
+
1199
+ export interface RepositoryCacheAcquisitionUsage {
1200
+ readonly id?: string;
1201
+ readonly namespace?: string;
1202
+ readonly ref?: string;
1203
+ readonly generation: string;
1204
+ readonly acquiredAt?: string;
1205
+ readonly ageMs?: number | null;
1206
+ readonly healthy: boolean;
1207
+ readonly issues: ReadonlyArray<Record<string, unknown>>;
1208
+ }
1209
+
1210
+ export interface RepositoryRootSetUsage {
1211
+ readonly ref: string;
1212
+ readonly generation: string;
1213
+ readonly healthy: boolean;
1214
+ readonly entryCount: number | null;
1215
+ readonly physicalBytes: null;
1216
+ readonly retention: {
1217
+ readonly pinnedEntries: number | null;
1218
+ readonly evictableEntries: number | null;
1219
+ } | null;
1220
+ readonly reachability: RootSetDoctorResult['reachabilityCounts'] | 'anchored' | null;
1221
+ readonly issues: ReadonlyArray<Record<string, unknown>>;
1222
+ }
1223
+
1224
+ export interface RepositoryExpiringSetUsage {
1225
+ readonly namespace: string;
1226
+ readonly ref: string;
1227
+ readonly generation: string;
1228
+ readonly healthy: boolean;
1229
+ readonly entryCount: number | null;
1230
+ readonly physicalBytes: null;
1231
+ readonly reachability: 'anchored';
1232
+ readonly age: {
1233
+ readonly createdAt: string | null;
1234
+ readonly updatedAt: string | null;
1235
+ } | null;
1236
+ readonly expiry: {
1237
+ readonly liveEntries: number;
1238
+ readonly expiredEntries: number;
1239
+ readonly nextExpiry: string | null;
1240
+ } | null;
1241
+ readonly issues: ReadonlyArray<Record<string, unknown>>;
1242
+ }
1243
+
1244
+ export interface RepositoryVaultUsage {
1245
+ readonly ref: string;
1246
+ readonly present: boolean;
1247
+ readonly healthy: boolean;
1248
+ readonly generation: string | null;
1249
+ readonly entryCount: number | null;
1250
+ readonly physicalBytes: null;
1251
+ readonly privacy: boolean | null;
1252
+ readonly reachability: 'anchored' | null;
1253
+ readonly issues: ReadonlyArray<Record<string, unknown>>;
1254
+ }
1255
+
1256
+ export interface RepositoryDoctorReport {
1257
+ readonly version: 1;
1258
+ readonly healthy: boolean;
1259
+ readonly observedAt: string;
1260
+ readonly completedAt: string;
1261
+ readonly policy: {
1262
+ readonly gracePeriodMs: number | null;
1263
+ readonly expiresBefore: string;
1264
+ readonly maxCollectionsPerKind: number;
1265
+ };
1266
+ readonly repository: {
1267
+ readonly objects: RepositoryObjectInventory;
1268
+ readonly roots: {
1269
+ readonly refCount: number;
1270
+ readonly reflogsIncluded: true;
1271
+ readonly reflogCount: null;
1272
+ };
1273
+ readonly evidence: {
1274
+ readonly anchoredInventory: 'refs-and-reflogs';
1275
+ readonly prunableInspection: 'dry-run';
1276
+ readonly mutatesRepository: false;
1277
+ };
1278
+ };
1279
+ readonly usage: {
1280
+ /** Present in reports produced by git-cas v6.3.0 and later. */
1281
+ readonly acquisitions?: {
1282
+ readonly healthy: boolean;
1283
+ readonly coverage: RepositoryCollectionCoverage;
1284
+ readonly totals: {
1285
+ readonly activeCount: number;
1286
+ readonly oldestAcquiredAt: string | null;
1287
+ readonly newestAcquiredAt: string | null;
1288
+ readonly maxAgeMs: number | null;
1289
+ };
1290
+ readonly entries: ReadonlyArray<RepositoryCacheAcquisitionUsage>;
1291
+ };
1292
+ readonly caches: {
1293
+ readonly healthy: boolean;
1294
+ readonly coverage: RepositoryCollectionCoverage;
1295
+ readonly totals: {
1296
+ readonly entryCount: number | null;
1297
+ readonly logicalBytes: number | null;
1298
+ readonly pinnedEntries: number | null;
1299
+ readonly evictableEntries: number | null;
1300
+ readonly expiredEntries: number | null;
1301
+ };
1302
+ readonly entries: ReadonlyArray<RepositoryCacheUsage>;
1303
+ };
1304
+ readonly rootSets: {
1305
+ readonly healthy: boolean;
1306
+ readonly coverage: RepositoryCollectionCoverage;
1307
+ readonly totals: {
1308
+ readonly entryCount: number | null;
1309
+ readonly pinnedEntries: number | null;
1310
+ readonly evictableEntries: number | null;
1311
+ };
1312
+ readonly entries: ReadonlyArray<RepositoryRootSetUsage>;
1313
+ };
1314
+ readonly expiringSets: {
1315
+ readonly healthy: boolean;
1316
+ readonly coverage: RepositoryCollectionCoverage;
1317
+ readonly totals: {
1318
+ readonly entryCount: number | null;
1319
+ readonly liveEntries: number | null;
1320
+ readonly expiredEntries: number | null;
1321
+ };
1322
+ readonly entries: ReadonlyArray<RepositoryExpiringSetUsage>;
1323
+ };
1324
+ readonly vault: RepositoryVaultUsage;
1325
+ };
1326
+ readonly limitations: ReadonlyArray<RepositoryDiagnosticLimitation>;
1327
+ }
1328
+
1329
+ /** Repository-wide, non-mutating diagnostics domain service. */
1330
+ export declare class RepositoryDoctor {
1331
+ constructor(options: {
1332
+ repository: RepositoryInspectionPort;
1333
+ rootSets: { open(options: { ref: string }): RootSet | Promise<RootSet> };
1334
+ caches: { open(options: { namespace: string }): CacheSet | Promise<CacheSet> };
1335
+ expiringSets: {
1336
+ open(options: { namespace: string }): ExpiringSet | Promise<ExpiringSet>;
1337
+ };
1338
+ vault: Pick<VaultService, 'getVaultMetadata' | 'readState'>;
1339
+ clock?: { now(): Date };
1340
+ });
1341
+ doctor(options?: RepositoryDoctorOptions): Promise<RepositoryDoctorReport>;
1342
+ }
1343
+
503
1344
  /** Result of comparing two manifests by chunk digest. */
504
1345
  export interface ManifestDiffResult {
505
1346
  added: Chunk[];
@@ -525,6 +1366,125 @@ export const SCHEME_FRAMED: 'framed';
525
1366
  /** Encryption scheme constant for convergent (dedup-preserving) encryption. */
526
1367
  export const SCHEME_CONVERGENT: 'convergent';
527
1368
 
1369
+ export interface AssetPutOptions {
1370
+ source: AsyncIterable<Uint8Array>;
1371
+ slug: string;
1372
+ filename?: string;
1373
+ encryptionKey?: Uint8Array;
1374
+ passphrase?: string;
1375
+ encryption?: StoreEncryptionOptions;
1376
+ kdfOptions?: Omit<DeriveKeyOptions, 'passphrase'>;
1377
+ compression?: { algorithm: 'gzip' };
1378
+ recipients?: Array<{ label: string; key: Uint8Array }>;
1379
+ merkleThreshold?: number;
1380
+ chunking?: ChunkingConfig;
1381
+ }
1382
+
1383
+ export interface AssetCapability {
1384
+ put(options: AssetPutOptions): Promise<StagedAsset>;
1385
+ adopt(options: { treeOid: string }): Promise<StagedAsset>;
1386
+ open(options: {
1387
+ handle: AssetHandleInput;
1388
+ encryptionKey?: Uint8Array;
1389
+ passphrase?: string;
1390
+ }): AsyncIterable<Uint8Array>;
1391
+ }
1392
+
1393
+ export type PageSource =
1394
+ | Uint8Array
1395
+ | Iterable<Uint8Array>
1396
+ | AsyncIterable<Uint8Array>;
1397
+
1398
+ export interface PageCapability {
1399
+ put(options: { source: PageSource; maxBytes?: number }): Promise<StagedPage>;
1400
+ get(options: { handle: PageHandleInput; maxBytes?: number }): Promise<Uint8Array>;
1401
+ open(options: { handle: PageHandleInput }): AsyncIterable<Uint8Array>;
1402
+ }
1403
+
1404
+ export type BundleMemberInput =
1405
+ | ApplicationHandleInput
1406
+ | PageSource
1407
+ | { source: PageSource; maxBytes?: number };
1408
+
1409
+ export interface BundleMember {
1410
+ readonly version: 1;
1411
+ readonly path: string;
1412
+ readonly handle: ApplicationHandle;
1413
+ readonly type: 'blob' | 'tree';
1414
+ readonly size: number | null;
1415
+ readonly logicalBytes: number;
1416
+ }
1417
+
1418
+ export interface BundleCapability {
1419
+ put(options: {
1420
+ members:
1421
+ | Record<string, BundleMemberInput>
1422
+ | Map<string, BundleMemberInput>
1423
+ | Array<[string, BundleMemberInput]>;
1424
+ limits?: Partial<BundleLimits>;
1425
+ }): Promise<StagedBundle>;
1426
+ putOrdered(options: {
1427
+ members:
1428
+ | Iterable<[string, BundleMemberInput]>
1429
+ | AsyncIterable<[string, BundleMemberInput]>;
1430
+ limits?: Partial<BundleLimits>;
1431
+ }): Promise<StagedBundle>;
1432
+ getMember(options: {
1433
+ handle: BundleHandleInput;
1434
+ path: string;
1435
+ }): Promise<BundleMember | null>;
1436
+ iterateMembers(options: { handle: BundleHandleInput }): AsyncIterable<BundleMember>;
1437
+ openMember(options: { handle: BundleHandleInput; path: string }): AsyncIterable<Uint8Array>;
1438
+ }
1439
+
1440
+ export interface CacheCapability {
1441
+ open(options: {
1442
+ namespace: string;
1443
+ policy?: CachePolicyOptions;
1444
+ retry?: { maxAttempts?: number; baseDelayMs?: number };
1445
+ }): Promise<CacheSet>;
1446
+ }
1447
+
1448
+ export interface ExpiringSetCapability {
1449
+ open(options: {
1450
+ namespace: string;
1451
+ retry?: { maxAttempts?: number; baseDelayMs?: number };
1452
+ }): Promise<ExpiringSet>;
1453
+ }
1454
+
1455
+ export interface DiagnosticsCapability {
1456
+ doctor(options?: RepositoryDoctorOptions): Promise<RepositoryDoctorReport>;
1457
+ }
1458
+
1459
+ export interface RetentionResult {
1460
+ readonly changed: boolean;
1461
+ readonly witness: RetentionWitness;
1462
+ }
1463
+
1464
+ export interface RetentionCapability {
1465
+ retain(options: {
1466
+ handle: ApplicationHandleInput;
1467
+ root: { ref: string; name: string };
1468
+ policy?: RetentionPolicy;
1469
+ }): Promise<RetentionResult>;
1470
+ }
1471
+
1472
+ export interface PublicationResult {
1473
+ readonly operation: 'publication';
1474
+ readonly commitId: string;
1475
+ readonly ref: string;
1476
+ readonly root: ApplicationHandle;
1477
+ readonly witness: RetentionWitness;
1478
+ }
1479
+
1480
+ export interface PublicationCapability {
1481
+ commit(options: {
1482
+ root: ApplicationHandleInput;
1483
+ commit: { message: string; parents?: string[] };
1484
+ ref: { name: string; expected: string | null };
1485
+ }): Promise<PublicationResult>;
1486
+ }
1487
+
528
1488
  /**
529
1489
  * High-level facade for the Content Addressable Store library.
530
1490
  *
@@ -543,6 +1503,16 @@ export default class ContentAddressableStore {
543
1503
  }): Promise<RootSet>;
544
1504
  };
545
1505
 
1506
+ readonly caches: CacheCapability;
1507
+ readonly expiringSets: ExpiringSetCapability;
1508
+ readonly diagnostics: DiagnosticsCapability;
1509
+
1510
+ readonly assets: AssetCapability;
1511
+ readonly pages: PageCapability;
1512
+ readonly bundles: BundleCapability;
1513
+ readonly retention: RetentionCapability;
1514
+ readonly publications: PublicationCapability;
1515
+
546
1516
  getService(): Promise<CasService>;
547
1517
  getVaultService(): Promise<VaultService>;
548
1518
  getRootSetRegistry(): Promise<RootSetRegistry>;