@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/ARCHITECTURE.md CHANGED
@@ -11,12 +11,17 @@ metadata exposure, see [docs/THREAT_MODEL.md](./docs/THREAT_MODEL.md).
11
11
 
12
12
  `git-cas` uses Git as the storage substrate, not as a user-facing abstraction.
13
13
 
14
- At a high level, the system does four things:
14
+ At a high level, the system does five things:
15
15
 
16
16
  1. turns input bytes into chunk blobs stored in Git
17
17
  2. records how to rebuild those bytes in a manifest
18
- 3. emits a Git tree that keeps the manifest and chunk blobs reachable
19
- 4. optionally indexes trees by slug through a GC-safe vault ref
18
+ 3. exposes assets, pages, and bundles through opaque application handles
19
+ 4. retains or publishes handle graphs through explicit lifecycle policies
20
+ 5. inspects repository reachability and managed-storage health without mutation
21
+
22
+ Low-level blob, manifest, and tree operations remain available. Application
23
+ code can use the higher-level capabilities without constructing Git trees,
24
+ persisting naked object IDs, or implementing its own cache ref protocol.
20
25
 
21
26
  The same core supports:
22
27
 
@@ -81,6 +86,27 @@ credential resolution share `bin/credentials.js` so raw key files,
81
86
  passphrase-derived vault keys, and encrypted restore input requirements stay
82
87
  consistent across human and machine command surfaces.
83
88
 
89
+ Application-facing lifecycle capabilities sit above the same CAS and Git
90
+ ports:
91
+
92
+ ```mermaid
93
+ flowchart TD
94
+ APP[Application]
95
+ HANDLE[Assets / Pages / Bundles]
96
+ POLICY[Retention / Publication / Cache / Expiring Set]
97
+ CAS[CAS Pipeline]
98
+ GIT[Git Objects and Refs]
99
+ DOCTOR[Repository Diagnostics]
100
+
101
+ APP --> HANDLE
102
+ HANDLE --> CAS
103
+ HANDLE --> POLICY
104
+ CAS --> GIT
105
+ POLICY --> GIT
106
+ DOCTOR --> GIT
107
+ APP --> DOCTOR
108
+ ```
109
+
84
110
  ## Store Pipeline
85
111
 
86
112
  ```
@@ -117,6 +143,10 @@ The public entrypoint is [index.js](./index.js).
117
143
  observability adapters
118
144
  - exposes convenience methods like `storeFile()` and `restoreFile()`
119
145
  - exposes `rootSets.open()` for mutable current-generation Git reachability
146
+ - exposes opaque `assets`, `pages`, and `bundles` capability groups
147
+ - exposes `retention`, `publications`, `caches`, and `expiringSets` for explicit
148
+ reachability and lifecycle policy
149
+ - exposes read-only repository evidence through `diagnostics.doctor()`
120
150
 
121
151
  The facade is orchestration glue. It is not the storage engine itself.
122
152
 
@@ -145,6 +175,31 @@ The facade is orchestration glue. It is not the storage engine itself.
145
175
  `RootSetPersistence`, `RootSetMetadataCodec`, and `RootSetTreeCodec` own the
146
176
  ref, metadata, and real Git reachability boundaries.
147
177
 
178
+ - **`AssetService`, `PageService`, and `BundleService`** — stage application
179
+ payloads behind immutable opaque handles. Pages enforce bounded blob size;
180
+ bundles build deterministic bounded-fanout trees and support targeted member
181
+ traversal without hydrating the complete structure.
182
+
183
+ - **`RetentionService` and `PublicationService`** — validate complete handle
184
+ graphs, then either retain them in a RootSet with generation-scoped evidence
185
+ or publish them atomically under an allowlisted application ref.
186
+
187
+ - **`CacheSetRegistry` and `CacheSet`** — own cache index generations,
188
+ compare-and-swap replacement, TTL, entry and logical-byte limits,
189
+ approximate-LRU sweeps, coalesced touches, doctor, and authoritative repair
190
+ under `refs/cas/caches/*`. `CacheAcquisitionRegistry` atomically verifies a
191
+ selected cache generation and creates a scoped anchor under
192
+ `refs/cas/cache-acquisitions/*`; acquisition release is explicit,
193
+ idempotent, and generation-checked.
194
+
195
+ - **`ExpiringSetRegistry` and `ExpiringSet`** — own digest-only replay markers
196
+ under `refs/cas/expiring/*`. Admission is atomic, membership reads are
197
+ side-effect free, and only expired entries can be released.
198
+
199
+ - **`RepositoryDoctor`** — streams object, ref, reflog-reachability, and safe
200
+ prune-dry-run evidence to classify repository objects and summarize managed
201
+ CacheSet, RootSet, ExpiringSet, and Vault usage.
202
+
148
203
  - **`KeyResolver`** — resolves key sources: passphrase-derived keys via KDF,
149
204
  envelope recipient DEK wrapping and unwrapping. `CasService` delegates all key
150
205
  material resolution through `this.keyResolver`.
@@ -200,6 +255,14 @@ The facade is orchestration glue. It is not the storage engine itself.
200
255
  - **`Oid`** — immutable Git object identifier value with 40- or 64-hex
201
256
  validation.
202
257
  - **`RootSetRef`** — immutable validated ref below `refs/cas/rootsets/`.
258
+ - **`AssetHandle`, `PageHandle`, and `BundleHandle`** — canonical repository-
259
+ independent locators for validated application payload graphs.
260
+ - **`RetentionWitness`** — immutable evidence naming the generation and real
261
+ Git tree edge that retained or published a handle graph.
262
+ - **`CacheKey`, `CachePolicy`, `CacheHit`, and `CacheSetRef`** — validated cache
263
+ identity, policy, lookup evidence, and namespace boundaries.
264
+ - **`ExpiringMarker`, `ExpiringSetKey`, and `ExpiringSetRef`** — validated
265
+ replay-marker evidence, domain-separated key identity, and namespace refs.
203
266
  - **`Slug`** — immutable vault slug representation. It enforces vault slug
204
267
  limits and exposes `.toTreePath()` for the percent-encoded Git tree-entry name
205
268
  used by plain vault trees.
@@ -249,6 +312,8 @@ with methods that throw "not implemented" by default.
249
312
  - **`CompressionPort`** — compress/decompress for both byte arrays and streams.
250
313
  - **`ObservabilityPort`** — metrics, logs, and spans without binding the domain
251
314
  to any runtime event API.
315
+ - **`RepositoryInspectionPort`** — non-mutating streams for objects, refs,
316
+ reachable IDs, safe prunable candidates, and reachable physical bytes.
252
317
 
253
318
  ### Infrastructure (`src/infrastructure/`)
254
319
 
@@ -267,6 +332,9 @@ Git:
267
332
  `@git-stunts/plumbing` to shell out to the `git` CLI.
268
333
  - **`GitRefAdapter`** — `GitRefPort` implementation using
269
334
  `@git-stunts/plumbing`.
335
+ - **`GitRepositoryInspectionAdapter`** — `RepositoryInspectionPort`
336
+ implementation using streamed Git inventories and plumbing's non-mutating
337
+ prunable-object inspection.
270
338
 
271
339
  Compression:
272
340
  - **`NodeCompressionAdapter`** — `CompressionPort` backed by `node:zlib`.
@@ -362,6 +430,51 @@ For Merkle assets the tree contains:
362
430
  Chunk blobs are deduplicated at the tree-entry level by digest. The manifest
363
431
  still remains authoritative for repeated-chunk order and multiplicity.
364
432
 
433
+ ### Application Handles And Structured Materializations
434
+
435
+ An opaque handle is a canonical content locator, not a durability claim. Asset
436
+ handles identify existing CAS trees. Page handles identify bounded immutable
437
+ blobs. Bundle handles identify deterministic descriptor trees whose leaves are
438
+ assets, pages, or nested bundles.
439
+
440
+ Bundle traversal reads only the descriptor path and selected payload required
441
+ for a named member. Validation re-enforces persisted path, descriptor-byte,
442
+ fanout, and nesting limits before a graph is retained or published.
443
+
444
+ ### Retention And Publication
445
+
446
+ RootSets, CacheSets, ExpiringSets, application publications, and the Vault all
447
+ make objects Git-reachable, but they encode different lifecycle contracts:
448
+
449
+ | Surface | Ref namespace | Lifecycle |
450
+ | --- | --- | --- |
451
+ | RootSet | `refs/cas/rootsets/*` | Caller-managed current generation |
452
+ | CacheSet | `refs/cas/caches/*` | TTL/capacity/approximate-LRU managed cache |
453
+ | Cache acquisition | `refs/cas/cache-acquisitions/*` | Explicit caller scope over one cache generation |
454
+ | ExpiringSet | `refs/cas/expiring/*` | Expiry-only replay protection |
455
+ | Publication | Caller-allowlisted ref | Application-controlled causal history |
456
+ | Vault | `refs/cas/vault` | History-preserving named assets |
457
+
458
+ High-level retention, CacheSet, cache acquisition, ExpiringSet, and application
459
+ publication operations return generation-scoped retention evidence. Replacing
460
+ a parentless current-generation head releases old edges when no other ref or
461
+ reflog reaches them; Git's normal grace and pruning policy still controls
462
+ physical deletion. A cache acquisition temporarily retains the complete
463
+ selected generation, not only the requested target, and must be released when
464
+ consumption ends.
465
+
466
+ ### Repository Diagnostics
467
+
468
+ `cas.diagnostics.doctor()` reports total, anchored, orphaned, volatile, and
469
+ unreachable object evidence plus managed-storage summaries, including active
470
+ cache-acquisition count and age. Ref and reflog reachability defines anchored
471
+ objects; volatile objects come only from safe prune dry-run output for the
472
+ selected expiry cutoff.
473
+
474
+ The report names limits Git cannot prove exactly, including per-owner
475
+ deduplicated physical bytes and packed-object age. The inspection surface has
476
+ no object-write, ref-update, GC, or destructive prune operation.
477
+
365
478
  ### Vault
366
479
 
367
480
  The vault is a GC-safe slug index rooted at `refs/cas/vault`.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,123 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [6.3.0] — 2026-07-17
11
+
12
+ ### Added
13
+
14
+ - **Scoped cache acquisitions** — `CacheSet.acquire()` now performs a bounded,
15
+ reference-only lookup and atomically anchors the selected cache generation
16
+ for an explicit caller lifetime. Acquisitions carry separate pinned
17
+ retention evidence, release idempotently with a generation check, expose
18
+ bounded inspection and operational cleanup, and appear in repository doctor
19
+ with count and age evidence. Clock skew leaves structurally valid retention
20
+ healthy while reporting an unknown age and explicit diagnostic issue.
21
+ Real-Git coverage proves active acquisitions
22
+ survive aggressive prune without making lookup reads scale with target graph
23
+ size. Canonical one-segment namespace refs, symbolic-ref preflight,
24
+ no-dereference mutations across ordinary managed refs and acquisition refs,
25
+ post-conflict ref-type checks, and hard Git inventory limits preserve
26
+ ownership boundaries under hostile or malformed refs. Unknown ref-type
27
+ evidence fails doctor health closed. Acquisition capabilities remain optional
28
+ on the base Git ref port, the existing retention-kind and diagnostic-kind
29
+ unions remain unchanged, and the new doctor group is type-optional for
30
+ compatibility with existing consumers. Production Git checked-delete
31
+ conflicts fail closed because Git 2.43 cannot atomically prove that a missing
32
+ direct ref is not an enumerator-invisible dangling symbolic ref.
33
+
34
+ ### Fixed
35
+
36
+ - **Pre-push Git environment isolation** — repository-local `GIT_*` variables
37
+ exported by Git hooks are cleared before lint and tests run, so child
38
+ processes can create and inspect independent temporary repositories. The
39
+ hook fails closed if Git cannot enumerate the local variables.
40
+
41
+ ### Documentation
42
+
43
+ - **v6.2.0 publication evidence** — records the signed tag identity, successful
44
+ release workflow, npm integrity and SLSA provenance, final GitHub Release,
45
+ and the registry gate that unlocks downstream application adoption.
46
+
47
+ ## [6.2.0] — 2026-07-13
48
+
49
+ ### Added
50
+
51
+ - **Application storage ownership contract** — cycle API-0047 defines opaque
52
+ asset/bundle/page handles, generic application publication, generation-scoped
53
+ retention witnesses, RootSet-backed cache collections, expiry-safe replay
54
+ storage, and repository/cache diagnostics as the `v6.2.0` implementation
55
+ boundary. Invariant I-002 makes `git-cas` the owner of physical CAS and cache
56
+ lifecycle while applications retain domain and causal semantics.
57
+ - **Opaque asset lifecycle API** — `cas.assets.put()` and `assets.open()` stream
58
+ through the existing CAS pipeline using immutable, canonical `AssetHandle`
59
+ values. Staged results explicitly report that the operation created no root,
60
+ while `cas.retention.retain()` returns generation-scoped evidence for the
61
+ exact RootSet tree edge that made the graph reachable.
62
+ - **Structured bundle and page storage** — `cas.pages` stores bounded immutable
63
+ blobs with content-deduplicated `PageHandle` values. `cas.bundles.put()` and
64
+ `putOrdered()` build deterministic bounded fanout trees from named streams or
65
+ nested handles; `getMember()` and `openMember()` traverse only the selected
66
+ descriptor path and payload.
67
+ - **Portable structured validation** — imported page handles are size-checked
68
+ without hydrating their blobs, while bundle validation re-enforces persisted
69
+ member, path, descriptor-byte, fanout, and nesting limits before retention or
70
+ publication.
71
+ - **Generic application publication** — `cas.publications.commit()` validates
72
+ handle graphs, bounded ordered commit parents, commit messages, explicit ref
73
+ allowlists, reserved Git/CAS namespaces, and expected heads before
74
+ compare-and-swap publication. Success returns a `RetentionWitness`; stale
75
+ heads report structured expected, observed, and attempted-commit evidence.
76
+ - **Portable handle validation** — canonical SHA-1 and SHA-256 handle tokens
77
+ contain no repository location, survive clone and mirror transfer, and fail
78
+ explicitly when their referenced graph is absent or has the wrong codec or
79
+ Git object type.
80
+ - **Managed cache lifecycle** — `cas.caches.open()` now owns immutable
81
+ structured indexes under `refs/cas/caches/*`, compare-and-swap replacement,
82
+ TTL and approximate-LRU sweeps, entry and logical-byte limits, coalesced
83
+ explicit touches, retention witnesses, bounded inspection, doctor, and
84
+ authoritative repair. Cache misses never write durable metadata.
85
+ - **Streaming bundle inventory and accounting** — `bundles.iterateMembers()`
86
+ yields canonical descriptors without allocating a member array, while bundle
87
+ validation reports deterministic transitive logical bytes with repeated
88
+ child handles charged once per bundle root.
89
+ - **Expiry-safe replay sets** — `expiringSets.open()` now provides atomic
90
+ add-if-absent replay markers under `refs/cas/expiring/*`, digest-only
91
+ canonical metadata, read-only membership checks, expiry-only sweeps,
92
+ bounded inspection, doctor evidence, and immutable retention witnesses.
93
+ The capability intentionally exposes no live remove, repair, capacity, or
94
+ recency eviction path.
95
+ - **Repository-wide diagnostics** — `cas.diagnostics.doctor()` streams all Git
96
+ objects, refs, and reflog reachability; classifies anchored, orphaned, and
97
+ dry-run-prunable loose objects; reports repository physical bytes where Git
98
+ can prove them; and summarizes bounded CacheSet, RootSet, ExpiringSet, and
99
+ Vault usage. Per-owner physical bytes and packed-object age remain explicit
100
+ unknowns, and concurrent inventory changes fail closed.
101
+
102
+ ### Changed
103
+
104
+ - **6.2.0 release verification** — `pnpm run release:verify` passed all 13
105
+ steps with 6,124 observed tests across Node, Bun, Deno, and all three
106
+ real-Git integration runtimes. npm and JSR metadata now agree on `6.2.0`;
107
+ build stamping, npm package inspection, and the JSR publish dry-run passed.
108
+ - **Safe prune inspection dependency** — repository diagnostics require
109
+ `@git-stunts/plumbing` 3.1.0, whose public API fixes the exact non-mutating
110
+ `git prune --dry-run --verbose --no-progress --expire=<cutoff>` contract.
111
+
112
+ - **Git object size port** — `GitPersistencePort.readObjectSize()` and the Git
113
+ adapter use object metadata to enforce page bounds without materializing
114
+ content.
115
+ - **Ordered commit parents** — `GitRefPort.createCommit()` now accepts an
116
+ additive `parentOids` array while retaining the existing single-`parentOid`
117
+ compatibility input. Create-only ref updates derive the Git null OID width
118
+ from the repository's commit ID instead of assuming SHA-1.
119
+ - **Root-set mutation context** — `RootSet.mutate()` callbacks now receive the
120
+ observed ref, head OID, and tree OID as an additive second argument, allowing
121
+ generation-scoped evidence to remain correct across conflict retries.
122
+ - **Git object metadata port** — `GitPersistencePort.readObjectType()` and
123
+ `readObjectSize()` now use structured `git cat-file --batch-check` output,
124
+ inspecting targets without materializing content or parsing missing-object
125
+ stderr.
126
+
10
127
  ## [6.1.0] — 2026-07-11
11
128
 
12
129
  ### Added
@@ -28,8 +145,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
28
145
 
29
146
  ### Changed
30
147
 
31
- - **Git object type port** — `GitPersistencePort.readObjectType()` and the Git
32
- adapter now inspect target type without materializing object content.
33
148
  - **GitHub Issues as canonical tracker** — release milestones, goalposts, slices,
34
149
  and follow-on work now live in GitHub Issues and Milestones. Repo Markdown
35
150
  carries design docs, witnesses, release history, public docs, and archived
package/GUIDE.md CHANGED
@@ -51,6 +51,7 @@ limits, and port contracts live in the advanced guide.
51
51
  | Feature Area | Covered Here | Advanced Coverage |
52
52
  | ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
53
53
  | Facade lifecycle, JSON/CBOR factories, full constructor | [Library Quick Start](#library-quick-start), [Configuration Reference](#configuration-reference) | [Direct CasService and Custom Port Contracts](./ADVANCED_GUIDE.md#direct-casservice-and-custom-port-contracts) |
54
+ | Opaque assets, pages, bundles, retention evidence, publication | [Library Quick Start](#library-quick-start), [Application Storage Lifecycle](#application-storage-lifecycle), [Structured Materializations](#structured-materializations) | [Application Storage API](./docs/API.md#application-storage) |
54
55
  | Direct `CasService` construction | [Configuration Reference](#configuration-reference) notes the facade/direct split | [Direct CasService and Custom Port Contracts](./ADVANCED_GUIDE.md#direct-casservice-and-custom-port-contracts) |
55
56
  | File, stream, tree, vault-safe store workflows | [Store Operations](#store-operations), [Vault Management](#vault-management) | [Store/Restore Pipeline](./docs/STORE_RESTORE_PIPELINE.md), [Manifest Integrity Hash](./ADVANCED_GUIDE.md#manifest-integrity-hash), [Merkle Manifests](./ADVANCED_GUIDE.md#merkle-manifests) |
56
57
  | Restore modes and bounded memory behavior | [Restore Modes](#restore-modes) | [Store/Restore Pipeline](./docs/STORE_RESTORE_PIPELINE.md), [Parallel Chunk Restore](./ADVANCED_GUIDE.md#parallel-chunk-restore), [Streaming Decompression](./ADVANCED_GUIDE.md#streaming-decompression) |
@@ -70,31 +71,131 @@ limits, and port contracts live in the advanced guide.
70
71
 
71
72
  ## Library Quick Start
72
73
 
73
- A complete init-store-tree-restore cycle:
74
+ A complete stage-retain-open cycle:
74
75
 
75
76
  ```js
76
- import ContentAddressableStore from '@git-stunts/git-cas';
77
+ import { createReadStream } from 'node:fs';
78
+ import ContentAddressableStore, { AssetHandle } from '@git-stunts/git-cas';
77
79
 
78
- // 1. Initialize
79
80
  const cas = await ContentAddressableStore.open({ cwd: '/path/to/repo' });
80
81
 
81
- // 2. Store a file
82
- const manifest = await cas.storeFile({
83
- filePath: './photo.jpg',
82
+ // Stage bytes and receive an immutable content handle. This creates no root.
83
+ const staged = await cas.assets.put({
84
+ source: createReadStream('./photo.jpg'),
84
85
  slug: 'photos/vacation',
86
+ filename: 'photo.jpg',
85
87
  });
86
88
 
87
- // 3. Create a Git tree (persists the manifest + chunks as a tree object)
88
- const treeOid = await cas.createTree({ manifest });
89
+ // Make the graph Git-reachable through a current-generation RootSet.
90
+ const retained = await cas.retention.retain({
91
+ handle: staged.handle,
92
+ root: { ref: 'refs/cas/rootsets/photos', name: 'vacation' },
93
+ policy: 'pinned',
94
+ });
89
95
 
90
- // 4. Add to the vault index (GC-safe ref)
91
- await cas.addToVault({ slug: 'photos/vacation', treeOid });
96
+ // Stream the payload without exposing its manifest or chunk OIDs.
97
+ for await (const chunk of cas.assets.open({ handle: staged.handle })) {
98
+ consume(chunk);
99
+ }
92
100
 
93
- // 5. Restore later
94
- const readBack = await cas.readManifest({ treeOid });
95
- const { buffer } = await cas.restore({ manifest: readBack });
101
+ console.log(retained.witness.root.generation);
96
102
  ```
97
103
 
104
+ Node's file stream is an `AsyncIterable<Uint8Array>`; Bun and Deno callers can
105
+ supply their native async byte streams through the same contract.
106
+
107
+ ## Application Storage Lifecycle
108
+
109
+ The ordinary application boundary separates content identity from retention:
110
+
111
+ 1. `cas.assets.put()` streams bytes through the existing chunking, compression,
112
+ encryption, and deduplication pipeline. It returns a `StagedAsset` whose
113
+ immutable `AssetHandle` locates the resulting manifest tree.
114
+ 2. A staged result says this operation created no reachability root. It does
115
+ not claim that globally deduplicated objects are unreachable through every
116
+ other ref.
117
+ 3. `cas.retention.retain()` installs the handle under a RootSet and returns a
118
+ `RetentionWitness` naming the exact generation and tree path observed.
119
+ 4. `cas.publications.commit()` validates the handle graph, creates an
120
+ application commit with caller-controlled ordered parents, and updates an
121
+ explicitly allowed application ref by compare-and-swap.
122
+
123
+ Handles have a canonical, repository-location-independent token form:
124
+
125
+ ```js
126
+ const token = staged.handle.toString();
127
+ const sameHandle = AssetHandle.parse(token);
128
+ ```
129
+
130
+ The token is portable only with its referenced Git object graph. Opening it in
131
+ a clone or mirror succeeds after the graph is transferred; opening it in a
132
+ repository without that graph fails with `HANDLE_TARGET_MISSING`.
133
+
134
+ ### Structured Materializations
135
+
136
+ Use pages for bounded immutable index/trie nodes and bundles for a named,
137
+ independently addressable materialization. `putOrdered()` accepts an iterable
138
+ that is already sorted by canonical member path, so construction does not need
139
+ to collect the complete member set.
140
+
141
+ ```js
142
+ const nodes = await cas.pages.put({ source: encodedNodePage });
143
+ const edges = await cas.pages.put({ source: encodedEdgePage });
144
+ const materialization = await cas.bundles.putOrdered({
145
+ members: (async function* members() {
146
+ yield ['edges/root', edges.handle];
147
+ yield ['nodes/root', nodes.handle];
148
+ yield ['state/frontier', encodedFrontier];
149
+ })(),
150
+ });
151
+
152
+ for await (const chunk of cas.bundles.openMember({
153
+ handle: materialization.handle,
154
+ path: 'nodes/root',
155
+ })) {
156
+ consume(chunk);
157
+ }
158
+ ```
159
+
160
+ Bundle fanout trees contain direct Git edges to every member graph. Retaining
161
+ the bundle handle therefore retains its transitive pages and assets. Targeted
162
+ lookup reads only the descriptor path and selected payload; retention and
163
+ publication perform full bounded graph validation. Identical page bytes and
164
+ identically constructed bundles produce identical handles.
165
+
166
+ ### Generic Application Publication
167
+
168
+ Publication is disabled until the facade receives an explicit application-ref
169
+ allowlist. The `refs/cas/*` namespace is always reserved.
170
+
171
+ ```js
172
+ const cas = await ContentAddressableStore.open({
173
+ cwd: '/path/to/repo',
174
+ applicationRefPrefixes: ['refs/my-app/'],
175
+ });
176
+
177
+ const publication = await cas.publications.commit({
178
+ root: staged.handle,
179
+ commit: {
180
+ message: 'Publish vacation photo',
181
+ parents: previousCommitId === null ? [] : [previousCommitId],
182
+ },
183
+ ref: {
184
+ name: 'refs/my-app/assets',
185
+ expected: previousCommitId,
186
+ },
187
+ });
188
+ ```
189
+
190
+ `expected` is mandatory, including `null` for create-only publication. A stale
191
+ head fails with `PUBLICATION_CONFLICT` and includes `expected`, `observed`, and
192
+ the attempted commit ID. The returned witness is generation-scoped: it proves
193
+ what the ref reached when publication succeeded, not that a mutable ref still
194
+ points there later.
195
+
196
+ `pinned` is a retention-policy term. It means ordinary cache eviction must not
197
+ release the entry; it does not create or imply a Git pack `.keep` file.
198
+
98
199
  ### Factory Methods
99
200
 
100
201
  | Factory | Codec | Use Case |
package/README.md CHANGED
@@ -23,6 +23,19 @@ Unlike traditional LFS which moves files to external servers, `git-cas` treats t
23
23
  - **Mutable Root Sets**: Cache and derived-state trees can be anchored under
24
24
  `refs/cas/rootsets/*` while live, then become collectible after eviction,
25
25
  without vault history retaining every prior generation.
26
+ - **Managed Cache Sets**: Applications can store handles under
27
+ `refs/cas/caches/*` with TTL, entry and logical-byte limits, approximate LRU
28
+ eviction, immutable retention evidence, bounded inspection, repair, and
29
+ scoped acquisitions that keep a selected generation reachable during use.
30
+ Cache indexes and object reachability remain git-cas responsibilities.
31
+ - **Expiry-Safe Replay Sets**: Security-sensitive markers can live under
32
+ `refs/cas/expiring/*` with atomic add-if-absent, digest-only metadata, and
33
+ expiry-only release. Live markers have no remove, repair, capacity, or LRU
34
+ path that could shorten their acceptance window.
35
+ - **Opaque Application Handles**: Applications stage assets, immutable pages,
36
+ and deterministic structured bundles through validated handles, then retain
37
+ or publish them with generation-scoped evidence instead of managing Git
38
+ objects, trees, or payload OIDs directly.
26
39
  - **Key Lifecycle**: Envelope encryption separates DEKs from KEKs. Rotate passphrases across an entire vault without re-encrypting data blobs. Privacy mode HMAC-hashes slug names to prevent metadata discovery.
27
40
  - **Runtime-Adaptive**: A single core supports Node.js 22+, Bun, and Deno through a strict hexagonal port architecture with runtime-specific crypto adapters.
28
41
 
@@ -31,7 +44,7 @@ Unlike traditional LFS which moves files to external servers, `git-cas` treats t
31
44
  Existing v5 users should read [UPGRADING.md](./UPGRADING.md) and run
32
45
  `npm run upgrade` in dry-run mode before restoring old encrypted vault entries.
33
46
  For the release overview, see the
34
- [v6.1.0 Release Notes](./docs/releases/v6.1.0.md).
47
+ [v6.3.0 Release Notes](./docs/releases/v6.3.0.md).
35
48
 
36
49
  ### 1. CLI Usage
37
50
 
@@ -57,11 +70,26 @@ git-cas vault dashboard
57
70
  Integrate managed blob storage directly into your TypeScript or JavaScript application.
58
71
 
59
72
  ```js
73
+ import { createReadStream } from 'node:fs';
60
74
  import ContentAddressableStore from '@git-stunts/git-cas';
75
+
61
76
  const cas = await ContentAddressableStore.open({ cwd: '.' });
62
- const manifest = await cas.storeFile({ filePath: './asset.bin', slug: 'app/asset' });
77
+ const staged = await cas.assets.put({
78
+ source: createReadStream('./asset.bin'),
79
+ slug: 'app/asset',
80
+ filename: 'asset.bin',
81
+ });
82
+ const retained = await cas.retention.retain({
83
+ handle: staged.handle,
84
+ root: { ref: 'refs/cas/rootsets/my-app', name: 'app/asset' },
85
+ policy: 'pinned',
86
+ });
63
87
  ```
64
88
 
89
+ `staged.handle` is a content locator, not a durability promise. The returned
90
+ retention witness identifies the exact Git generation and tree edge that made
91
+ the asset reachable.
92
+
65
93
  ## Capability Map
66
94
 
67
95
  The README is the front door. Detailed mechanics live in the guide set:
@@ -73,7 +101,12 @@ The README is the front door. Detailed mechanics live in the guide set:
73
101
  | Encryption scheme selection | [Encryption Modes](./docs/ENCRYPTION_MODES.md) |
74
102
  | CDC internals, Merkle manifests, KDF policy, and tuning | [Advanced Guide](./ADVANCED_GUIDE.md) |
75
103
  | Ports, adapters, and collaborator boundaries | [Architecture](./ARCHITECTURE.md) |
104
+ | Assets, pages, bundles, retention, and publication | [Application storage](./docs/API.md#application-storage) |
76
105
  | GC retention for caches and derived state | [Root Sets](./docs/API.md#root-sets) |
106
+ | Managed TTL and capacity caches | [Cache Sets](./docs/API.md#cache-sets) |
107
+ | Scoped protection while consuming a cache hit | [Cache acquisitions](./docs/API.md#acquire-and-release) |
108
+ | Durable replay markers with expiry-only release | [Expiring Sets](./docs/API.md#expiring-sets) |
109
+ | Repository reachability and git-cas usage evidence | [Repository Diagnostics](./docs/API.md#repository-diagnostics) |
77
110
  | v5 to v6 migration | [Upgrading](./UPGRADING.md) |
78
111
 
79
112
  Core capabilities:
@@ -91,10 +124,28 @@ Core capabilities:
91
124
  - **Root-set retention**: current cache entries live under caller-owned
92
125
  `refs/cas/rootsets/*` refs. Entries are Git-reachable while present, and old
93
126
  set generations are not retained as commit history.
127
+ - **Managed cache lifecycle**: `caches.open()` owns immutable cache indexes,
128
+ compare-and-swap replacement, expiry, capacity eviction, retention
129
+ witnesses, diagnostics, and repair. Reads do not write access metadata;
130
+ callers opt into coalesced access updates with `touch()`.
131
+ - **Scoped cache acquisitions**: `cache.acquire()` performs a reference-only
132
+ lookup and atomically anchors the selected cache generation for the caller's
133
+ explicit lifetime. `release()` is idempotent, while inspection and checked
134
+ cleanup make abandoned acquisition refs observable and recoverable.
135
+ - **Expiry-safe replay lifecycle**: `expiringSets.open()` atomically retains
136
+ digest-only replay markers through their declared window. `contains()` is
137
+ read-only, and `sweep()` can release only markers whose expiry has passed.
138
+ - **Application storage**: `assets`, `pages`, `bundles`, `retention`, and
139
+ `publications` compose streaming CAS writes, bounded structured
140
+ materializations, targeted member reads, reachability roots,
141
+ compare-and-swap refs, and immutable lifecycle evidence.
94
142
  - **Envelope recipients**: multi-recipient key wrapping and recipient rotation
95
143
  avoid re-encrypting data blobs.
96
- - **Operational diagnostics**: `git-cas doctor` validates vault health and
97
- reports deduplication efficiency.
144
+ - **Operational diagnostics**: `cas.diagnostics.doctor()` streams repository
145
+ object/ref evidence, classifies anchored, orphaned, and volatile objects,
146
+ and summarizes cache acquisitions, CacheSet, RootSet, ExpiringSet, and Vault
147
+ usage without mutating Git. The `git-cas doctor` CLI continues to validate
148
+ vault health.
98
149
 
99
150
  ## Safety Snapshot
100
151
 
@@ -139,6 +190,11 @@ All three runtimes are tested in CI on every push. The hexagonal architecture is
139
190
  - **[v6.0.0 Release Notes](./docs/releases/v6.0.0.md)**: Major-release summary, upgrade call-to-action, and publication notes.
140
191
  - **[v6.1.0 Release Notes](./docs/releases/v6.1.0.md)**: Root-set retention,
141
192
  doctor/repair, and GC-policy guidance.
193
+ - **[v6.2.0 Release Notes](./docs/releases/v6.2.0.md)**: Opaque application
194
+ storage, managed cache and replay lifecycles, retention evidence, and
195
+ repository diagnostics.
196
+ - **[v6.3.0 Release Notes](./docs/releases/v6.3.0.md)**: Lifetime-safe,
197
+ reference-only cache acquisitions with explicit release and doctor evidence.
142
198
  - **[Upgrading](./UPGRADING.md)**: Migration guide for v5 → v6.
143
199
  - **[Changelog](./CHANGELOG.md)**: Version history and migration notes.
144
200
 
package/UPGRADING.md CHANGED
@@ -2,6 +2,81 @@
2
2
 
3
3
  v6.0.0 is a major release that simplifies the encryption model, hardens security defaults, and cleans up the architecture. This guide covers every breaking change and what you need to do.
4
4
 
5
+ ## v6.2.0 To v6.3.0
6
+
7
+ v6.3.0 is API-additive and does not require stored-data migration. It adds
8
+ scoped cache acquisitions for consumers that must keep a cache hit reachable
9
+ between lookup and use.
10
+
11
+ `CacheSet.get()` retains its existing complete-validation semantics, but a
12
+ returned hit is only an observation. Use `acquire()` when consumption may
13
+ overlap replacement, expiry, eviction, removal, or destructive Git cleanup:
14
+
15
+ ```javascript
16
+ const acquisition = await cache.acquire(materializationKey);
17
+ if (acquisition) {
18
+ try {
19
+ await consume(acquisition.hit.handle);
20
+ } finally {
21
+ await acquisition.release();
22
+ }
23
+ }
24
+ ```
25
+
26
+ An acquisition anchors the exact observed cache generation until explicit,
27
+ idempotent release. It intentionally has no automatic TTL: age is diagnostic
28
+ evidence, not proof that a consumer is dead. Recovery tooling can use
29
+ `cache.inspectAcquisitions({ limit })` and generation-checked
30
+ `cache.releaseAcquisition(...)`; `cas.diagnostics.doctor()` reports bounded
31
+ count, age, truncation, malformed-ref, and clock-skew evidence.
32
+
33
+ See [v6.3.0 Release Notes](./docs/releases/v6.3.0.md) and
34
+ [Acquire And Release](./docs/API.md#acquire-and-release) for the complete
35
+ lifetime and recovery contract.
36
+
37
+ ## v6.1.0 To v6.2.0
38
+
39
+ v6.2.0 is API-additive and does not require stored-data migration. It adds
40
+ high-level application storage, managed cache and replay lifecycles, immutable
41
+ retention evidence, and repository-wide diagnostics.
42
+
43
+ Applications should stop treating a naked Git object ID stored in JSON as a
44
+ durability guarantee. Stage content through `assets`, `pages`, or `bundles`,
45
+ then retain or publish the returned opaque handle through the policy surface
46
+ that matches its lifecycle:
47
+
48
+ ```javascript
49
+ const staged = await cas.assets.put({
50
+ source,
51
+ slug: 'warp/materialization',
52
+ filename: 'materialization.bin',
53
+ });
54
+
55
+ const cache = await cas.caches.open({
56
+ namespace: 'git-warp/materializations',
57
+ policy: { maxEntries: 10_000, maxBytes: 2 * 1024 * 1024 * 1024 },
58
+ });
59
+ const stored = await cache.put(cacheKey, staged.handle, {
60
+ retention: 'evictable',
61
+ expiresAt: new Date(Date.now() + 14 * 24 * 60 * 60 * 1000),
62
+ });
63
+ ```
64
+
65
+ Existing root sets and vault entries remain valid. Before running destructive
66
+ Git cleanup, applications migrating an existing object-ID index must first
67
+ enumerate every still-live object, validate that it still exists, and adopt it
68
+ into a RootSet or rebuild it through the appropriate high-level API. Neither
69
+ repair nor diagnostics can recover an object that Git already pruned.
70
+
71
+ Use `cas.diagnostics.doctor()` before and after migration to inspect anchored,
72
+ orphaned, and grace-expired object counts plus managed CacheSet, RootSet,
73
+ ExpiringSet, and Vault usage. The doctor is read-only; it never runs Git GC or
74
+ prune. Repository diagnostics require `@git-stunts/plumbing` 3.1.0 or newer.
75
+
76
+ See [v6.2.0 Release Notes](./docs/releases/v6.2.0.md) and
77
+ [Application Storage](./docs/API.md#application-storage) for the complete
78
+ capability and policy map.
79
+
5
80
  ## v6.0.1 To v6.1.0
6
81
 
7
82
  v6.1.0 is API-additive and does not require stored-data migration. It adds root
package/build-info.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "sha": "65eda79",
3
- "timestamp": "2026-07-11T22:16:25.638Z"
2
+ "sha": "33f4171",
3
+ "timestamp": "2026-07-17T08:24:15.545Z"
4
4
  }