@git-stunts/git-cas 6.1.0 → 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 (64) hide show
  1. package/ARCHITECTURE.md +108 -3
  2. package/CHANGELOG.md +80 -2
  3. package/GUIDE.md +114 -13
  4. package/README.md +51 -4
  5. package/UPGRADING.md +43 -0
  6. package/build-info.json +2 -2
  7. package/docs/API.md +751 -16
  8. package/docs/releases/v6.2.0.md +131 -0
  9. package/index.d.ts +879 -2
  10. package/index.js +326 -1
  11. package/package.json +3 -2
  12. package/src/domain/errors/Codes.js +35 -0
  13. package/src/domain/helpers/assertCanonicalTimestamp.js +15 -0
  14. package/src/domain/helpers/handleTarget.js +48 -0
  15. package/src/domain/helpers/isCanonicalCollectionKey.js +35 -0
  16. package/src/domain/services/AssetService.js +213 -0
  17. package/src/domain/services/BundleDescriptorCodec.js +286 -0
  18. package/src/domain/services/BundleFanoutBuilder.js +247 -0
  19. package/src/domain/services/BundleService.js +848 -0
  20. package/src/domain/services/CacheCandidateHeap.js +71 -0
  21. package/src/domain/services/CacheIndex.js +362 -0
  22. package/src/domain/services/CacheMetadataCodec.js +164 -0
  23. package/src/domain/services/CachePolicyEnforcer.js +144 -0
  24. package/src/domain/services/CacheSet.js +703 -0
  25. package/src/domain/services/CacheSetRegistry.js +88 -0
  26. package/src/domain/services/CasService.d.ts +2 -1
  27. package/src/domain/services/ExpiringSet.js +496 -0
  28. package/src/domain/services/ExpiringSetIndex.js +254 -0
  29. package/src/domain/services/ExpiringSetMetadataCodec.js +160 -0
  30. package/src/domain/services/ExpiringSetRegistry.js +101 -0
  31. package/src/domain/services/PageService.js +175 -0
  32. package/src/domain/services/PublicationService.js +315 -0
  33. package/src/domain/services/RepositoryDoctor.js +649 -0
  34. package/src/domain/services/RetentionService.js +120 -0
  35. package/src/domain/services/RootSet.js +10 -6
  36. package/src/domain/services/RootSetMetadataCodec.js +8 -2
  37. package/src/domain/services/RootSetPersistence.js +3 -2
  38. package/src/domain/services/StagingEvidence.js +39 -0
  39. package/src/domain/value-objects/ApplicationHandle.js +40 -0
  40. package/src/domain/value-objects/AssetHandle.js +163 -0
  41. package/src/domain/value-objects/BundleHandle.js +32 -0
  42. package/src/domain/value-objects/BundleLimits.js +80 -0
  43. package/src/domain/value-objects/BundlePath.js +78 -0
  44. package/src/domain/value-objects/CacheHit.js +93 -0
  45. package/src/domain/value-objects/CacheKey.js +32 -0
  46. package/src/domain/value-objects/CachePolicy.js +59 -0
  47. package/src/domain/value-objects/CacheSetRef.js +40 -0
  48. package/src/domain/value-objects/CollectionNamespace.js +54 -0
  49. package/src/domain/value-objects/ExpiringMarker.js +81 -0
  50. package/src/domain/value-objects/ExpiringSetKey.js +28 -0
  51. package/src/domain/value-objects/ExpiringSetRef.js +42 -0
  52. package/src/domain/value-objects/OpaqueHandle.js +171 -0
  53. package/src/domain/value-objects/PageHandle.js +34 -0
  54. package/src/domain/value-objects/RetentionWitness.js +101 -0
  55. package/src/domain/value-objects/StagedAsset.js +63 -0
  56. package/src/domain/value-objects/StagedBundle.js +66 -0
  57. package/src/domain/value-objects/StagedPage.js +47 -0
  58. package/src/infrastructure/adapters/GitPersistenceAdapter.js +48 -20
  59. package/src/infrastructure/adapters/GitRefAdapter.js +6 -5
  60. package/src/infrastructure/adapters/GitRepositoryInspectionAdapter.js +164 -0
  61. package/src/package-version.js +1 -1
  62. package/src/ports/GitPersistencePort.js +11 -1
  63. package/src/ports/GitRefPort.js +1 -0
  64. package/src/ports/RepositoryInspectionPort.js +33 -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,28 @@ 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/*`.
191
+
192
+ - **`ExpiringSetRegistry` and `ExpiringSet`** — own digest-only replay markers
193
+ under `refs/cas/expiring/*`. Admission is atomic, membership reads are
194
+ side-effect free, and only expired entries can be released.
195
+
196
+ - **`RepositoryDoctor`** — streams object, ref, reflog-reachability, and safe
197
+ prune-dry-run evidence to classify repository objects and summarize managed
198
+ CacheSet, RootSet, ExpiringSet, and Vault usage.
199
+
148
200
  - **`KeyResolver`** — resolves key sources: passphrase-derived keys via KDF,
149
201
  envelope recipient DEK wrapping and unwrapping. `CasService` delegates all key
150
202
  material resolution through `this.keyResolver`.
@@ -200,6 +252,14 @@ The facade is orchestration glue. It is not the storage engine itself.
200
252
  - **`Oid`** — immutable Git object identifier value with 40- or 64-hex
201
253
  validation.
202
254
  - **`RootSetRef`** — immutable validated ref below `refs/cas/rootsets/`.
255
+ - **`AssetHandle`, `PageHandle`, and `BundleHandle`** — canonical repository-
256
+ independent locators for validated application payload graphs.
257
+ - **`RetentionWitness`** — immutable evidence naming the generation and real
258
+ Git tree edge that retained or published a handle graph.
259
+ - **`CacheKey`, `CachePolicy`, `CacheHit`, and `CacheSetRef`** — validated cache
260
+ identity, policy, lookup evidence, and namespace boundaries.
261
+ - **`ExpiringMarker`, `ExpiringSetKey`, and `ExpiringSetRef`** — validated
262
+ replay-marker evidence, domain-separated key identity, and namespace refs.
203
263
  - **`Slug`** — immutable vault slug representation. It enforces vault slug
204
264
  limits and exposes `.toTreePath()` for the percent-encoded Git tree-entry name
205
265
  used by plain vault trees.
@@ -249,6 +309,8 @@ with methods that throw "not implemented" by default.
249
309
  - **`CompressionPort`** — compress/decompress for both byte arrays and streams.
250
310
  - **`ObservabilityPort`** — metrics, logs, and spans without binding the domain
251
311
  to any runtime event API.
312
+ - **`RepositoryInspectionPort`** — non-mutating streams for objects, refs,
313
+ reachable IDs, safe prunable candidates, and reachable physical bytes.
252
314
 
253
315
  ### Infrastructure (`src/infrastructure/`)
254
316
 
@@ -267,6 +329,9 @@ Git:
267
329
  `@git-stunts/plumbing` to shell out to the `git` CLI.
268
330
  - **`GitRefAdapter`** — `GitRefPort` implementation using
269
331
  `@git-stunts/plumbing`.
332
+ - **`GitRepositoryInspectionAdapter`** — `RepositoryInspectionPort`
333
+ implementation using streamed Git inventories and plumbing's non-mutating
334
+ prunable-object inspection.
270
335
 
271
336
  Compression:
272
337
  - **`NodeCompressionAdapter`** — `CompressionPort` backed by `node:zlib`.
@@ -362,6 +427,46 @@ For Merkle assets the tree contains:
362
427
  Chunk blobs are deduplicated at the tree-entry level by digest. The manifest
363
428
  still remains authoritative for repeated-chunk order and multiplicity.
364
429
 
430
+ ### Application Handles And Structured Materializations
431
+
432
+ An opaque handle is a canonical content locator, not a durability claim. Asset
433
+ handles identify existing CAS trees. Page handles identify bounded immutable
434
+ blobs. Bundle handles identify deterministic descriptor trees whose leaves are
435
+ assets, pages, or nested bundles.
436
+
437
+ Bundle traversal reads only the descriptor path and selected payload required
438
+ for a named member. Validation re-enforces persisted path, descriptor-byte,
439
+ fanout, and nesting limits before a graph is retained or published.
440
+
441
+ ### Retention And Publication
442
+
443
+ RootSets, CacheSets, ExpiringSets, application publications, and the Vault all
444
+ make objects Git-reachable, but they encode different lifecycle contracts:
445
+
446
+ | Surface | Ref namespace | Lifecycle |
447
+ | --- | --- | --- |
448
+ | RootSet | `refs/cas/rootsets/*` | Caller-managed current generation |
449
+ | CacheSet | `refs/cas/caches/*` | TTL/capacity/approximate-LRU managed cache |
450
+ | ExpiringSet | `refs/cas/expiring/*` | Expiry-only replay protection |
451
+ | Publication | Caller-allowlisted ref | Application-controlled causal history |
452
+ | Vault | `refs/cas/vault` | History-preserving named assets |
453
+
454
+ High-level retention, CacheSet, ExpiringSet, and application publication
455
+ operations return generation-scoped retention evidence. Replacing a parentless
456
+ current-generation head releases old edges when no other ref or reflog reaches
457
+ them; Git's normal grace and pruning policy still controls physical deletion.
458
+
459
+ ### Repository Diagnostics
460
+
461
+ `cas.diagnostics.doctor()` reports total, anchored, orphaned, volatile, and
462
+ unreachable object evidence plus managed-storage summaries. Ref and reflog
463
+ reachability defines anchored objects; volatile objects come only from safe
464
+ prune dry-run output for the selected expiry cutoff.
465
+
466
+ The report names limits Git cannot prove exactly, including per-owner
467
+ deduplicated physical bytes and packed-object age. The inspection surface has
468
+ no object-write, ref-update, GC, or destructive prune operation.
469
+
365
470
  ### Vault
366
471
 
367
472
  The vault is a GC-safe slug index rooted at `refs/cas/vault`.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,86 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [6.2.0] — 2026-07-13
11
+
12
+ ### Added
13
+
14
+ - **Application storage ownership contract** — cycle API-0047 defines opaque
15
+ asset/bundle/page handles, generic application publication, generation-scoped
16
+ retention witnesses, RootSet-backed cache collections, expiry-safe replay
17
+ storage, and repository/cache diagnostics as the `v6.2.0` implementation
18
+ boundary. Invariant I-002 makes `git-cas` the owner of physical CAS and cache
19
+ lifecycle while applications retain domain and causal semantics.
20
+ - **Opaque asset lifecycle API** — `cas.assets.put()` and `assets.open()` stream
21
+ through the existing CAS pipeline using immutable, canonical `AssetHandle`
22
+ values. Staged results explicitly report that the operation created no root,
23
+ while `cas.retention.retain()` returns generation-scoped evidence for the
24
+ exact RootSet tree edge that made the graph reachable.
25
+ - **Structured bundle and page storage** — `cas.pages` stores bounded immutable
26
+ blobs with content-deduplicated `PageHandle` values. `cas.bundles.put()` and
27
+ `putOrdered()` build deterministic bounded fanout trees from named streams or
28
+ nested handles; `getMember()` and `openMember()` traverse only the selected
29
+ descriptor path and payload.
30
+ - **Portable structured validation** — imported page handles are size-checked
31
+ without hydrating their blobs, while bundle validation re-enforces persisted
32
+ member, path, descriptor-byte, fanout, and nesting limits before retention or
33
+ publication.
34
+ - **Generic application publication** — `cas.publications.commit()` validates
35
+ handle graphs, bounded ordered commit parents, commit messages, explicit ref
36
+ allowlists, reserved Git/CAS namespaces, and expected heads before
37
+ compare-and-swap publication. Success returns a `RetentionWitness`; stale
38
+ heads report structured expected, observed, and attempted-commit evidence.
39
+ - **Portable handle validation** — canonical SHA-1 and SHA-256 handle tokens
40
+ contain no repository location, survive clone and mirror transfer, and fail
41
+ explicitly when their referenced graph is absent or has the wrong codec or
42
+ Git object type.
43
+ - **Managed cache lifecycle** — `cas.caches.open()` now owns immutable
44
+ structured indexes under `refs/cas/caches/*`, compare-and-swap replacement,
45
+ TTL and approximate-LRU sweeps, entry and logical-byte limits, coalesced
46
+ explicit touches, retention witnesses, bounded inspection, doctor, and
47
+ authoritative repair. Cache misses never write durable metadata.
48
+ - **Streaming bundle inventory and accounting** — `bundles.iterateMembers()`
49
+ yields canonical descriptors without allocating a member array, while bundle
50
+ validation reports deterministic transitive logical bytes with repeated
51
+ child handles charged once per bundle root.
52
+ - **Expiry-safe replay sets** — `expiringSets.open()` now provides atomic
53
+ add-if-absent replay markers under `refs/cas/expiring/*`, digest-only
54
+ canonical metadata, read-only membership checks, expiry-only sweeps,
55
+ bounded inspection, doctor evidence, and immutable retention witnesses.
56
+ The capability intentionally exposes no live remove, repair, capacity, or
57
+ recency eviction path.
58
+ - **Repository-wide diagnostics** — `cas.diagnostics.doctor()` streams all Git
59
+ objects, refs, and reflog reachability; classifies anchored, orphaned, and
60
+ dry-run-prunable loose objects; reports repository physical bytes where Git
61
+ can prove them; and summarizes bounded CacheSet, RootSet, ExpiringSet, and
62
+ Vault usage. Per-owner physical bytes and packed-object age remain explicit
63
+ unknowns, and concurrent inventory changes fail closed.
64
+
65
+ ### Changed
66
+
67
+ - **6.2.0 release verification** — `pnpm run release:verify` passed all 13
68
+ steps with 6,124 observed tests across Node, Bun, Deno, and all three
69
+ real-Git integration runtimes. npm and JSR metadata now agree on `6.2.0`;
70
+ build stamping, npm package inspection, and the JSR publish dry-run passed.
71
+ - **Safe prune inspection dependency** — repository diagnostics require
72
+ `@git-stunts/plumbing` 3.1.0, whose public API fixes the exact non-mutating
73
+ `git prune --dry-run --verbose --no-progress --expire=<cutoff>` contract.
74
+
75
+ - **Git object size port** — `GitPersistencePort.readObjectSize()` and the Git
76
+ adapter use object metadata to enforce page bounds without materializing
77
+ content.
78
+ - **Ordered commit parents** — `GitRefPort.createCommit()` now accepts an
79
+ additive `parentOids` array while retaining the existing single-`parentOid`
80
+ compatibility input. Create-only ref updates derive the Git null OID width
81
+ from the repository's commit ID instead of assuming SHA-1.
82
+ - **Root-set mutation context** — `RootSet.mutate()` callbacks now receive the
83
+ observed ref, head OID, and tree OID as an additive second argument, allowing
84
+ generation-scoped evidence to remain correct across conflict retries.
85
+ - **Git object metadata port** — `GitPersistencePort.readObjectType()` and
86
+ `readObjectSize()` now use structured `git cat-file --batch-check` output,
87
+ inspecting targets without materializing content or parsing missing-object
88
+ stderr.
89
+
10
90
  ## [6.1.0] — 2026-07-11
11
91
 
12
92
  ### Added
@@ -28,8 +108,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
28
108
 
29
109
  ### Changed
30
110
 
31
- - **Git object type port** — `GitPersistencePort.readObjectType()` and the Git
32
- adapter now inspect target type without materializing object content.
33
111
  - **GitHub Issues as canonical tracker** — release milestones, goalposts, slices,
34
112
  and follow-on work now live in GitHub Issues and Milestones. Repo Markdown
35
113
  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,18 @@ 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, and repair.
29
+ Cache indexes and object reachability remain git-cas responsibilities.
30
+ - **Expiry-Safe Replay Sets**: Security-sensitive markers can live under
31
+ `refs/cas/expiring/*` with atomic add-if-absent, digest-only metadata, and
32
+ expiry-only release. Live markers have no remove, repair, capacity, or LRU
33
+ path that could shorten their acceptance window.
34
+ - **Opaque Application Handles**: Applications stage assets, immutable pages,
35
+ and deterministic structured bundles through validated handles, then retain
36
+ or publish them with generation-scoped evidence instead of managing Git
37
+ objects, trees, or payload OIDs directly.
26
38
  - **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
39
  - **Runtime-Adaptive**: A single core supports Node.js 22+, Bun, and Deno through a strict hexagonal port architecture with runtime-specific crypto adapters.
28
40
 
@@ -31,7 +43,7 @@ Unlike traditional LFS which moves files to external servers, `git-cas` treats t
31
43
  Existing v5 users should read [UPGRADING.md](./UPGRADING.md) and run
32
44
  `npm run upgrade` in dry-run mode before restoring old encrypted vault entries.
33
45
  For the release overview, see the
34
- [v6.1.0 Release Notes](./docs/releases/v6.1.0.md).
46
+ [v6.2.0 Release Notes](./docs/releases/v6.2.0.md).
35
47
 
36
48
  ### 1. CLI Usage
37
49
 
@@ -57,11 +69,26 @@ git-cas vault dashboard
57
69
  Integrate managed blob storage directly into your TypeScript or JavaScript application.
58
70
 
59
71
  ```js
72
+ import { createReadStream } from 'node:fs';
60
73
  import ContentAddressableStore from '@git-stunts/git-cas';
74
+
61
75
  const cas = await ContentAddressableStore.open({ cwd: '.' });
62
- const manifest = await cas.storeFile({ filePath: './asset.bin', slug: 'app/asset' });
76
+ const staged = await cas.assets.put({
77
+ source: createReadStream('./asset.bin'),
78
+ slug: 'app/asset',
79
+ filename: 'asset.bin',
80
+ });
81
+ const retained = await cas.retention.retain({
82
+ handle: staged.handle,
83
+ root: { ref: 'refs/cas/rootsets/my-app', name: 'app/asset' },
84
+ policy: 'pinned',
85
+ });
63
86
  ```
64
87
 
88
+ `staged.handle` is a content locator, not a durability promise. The returned
89
+ retention witness identifies the exact Git generation and tree edge that made
90
+ the asset reachable.
91
+
65
92
  ## Capability Map
66
93
 
67
94
  The README is the front door. Detailed mechanics live in the guide set:
@@ -73,7 +100,11 @@ The README is the front door. Detailed mechanics live in the guide set:
73
100
  | Encryption scheme selection | [Encryption Modes](./docs/ENCRYPTION_MODES.md) |
74
101
  | CDC internals, Merkle manifests, KDF policy, and tuning | [Advanced Guide](./ADVANCED_GUIDE.md) |
75
102
  | Ports, adapters, and collaborator boundaries | [Architecture](./ARCHITECTURE.md) |
103
+ | Assets, pages, bundles, retention, and publication | [Application storage](./docs/API.md#application-storage) |
76
104
  | GC retention for caches and derived state | [Root Sets](./docs/API.md#root-sets) |
105
+ | Managed TTL and capacity caches | [Cache Sets](./docs/API.md#cache-sets) |
106
+ | Durable replay markers with expiry-only release | [Expiring Sets](./docs/API.md#expiring-sets) |
107
+ | Repository reachability and git-cas usage evidence | [Repository Diagnostics](./docs/API.md#repository-diagnostics) |
77
108
  | v5 to v6 migration | [Upgrading](./UPGRADING.md) |
78
109
 
79
110
  Core capabilities:
@@ -91,10 +122,23 @@ Core capabilities:
91
122
  - **Root-set retention**: current cache entries live under caller-owned
92
123
  `refs/cas/rootsets/*` refs. Entries are Git-reachable while present, and old
93
124
  set generations are not retained as commit history.
125
+ - **Managed cache lifecycle**: `caches.open()` owns immutable cache indexes,
126
+ compare-and-swap replacement, expiry, capacity eviction, retention
127
+ witnesses, diagnostics, and repair. Reads do not write access metadata;
128
+ callers opt into coalesced access updates with `touch()`.
129
+ - **Expiry-safe replay lifecycle**: `expiringSets.open()` atomically retains
130
+ digest-only replay markers through their declared window. `contains()` is
131
+ read-only, and `sweep()` can release only markers whose expiry has passed.
132
+ - **Application storage**: `assets`, `pages`, `bundles`, `retention`, and
133
+ `publications` compose streaming CAS writes, bounded structured
134
+ materializations, targeted member reads, reachability roots,
135
+ compare-and-swap refs, and immutable lifecycle evidence.
94
136
  - **Envelope recipients**: multi-recipient key wrapping and recipient rotation
95
137
  avoid re-encrypting data blobs.
96
- - **Operational diagnostics**: `git-cas doctor` validates vault health and
97
- reports deduplication efficiency.
138
+ - **Operational diagnostics**: `cas.diagnostics.doctor()` streams repository
139
+ object/ref evidence, classifies anchored, orphaned, and volatile objects,
140
+ and summarizes CacheSet, RootSet, ExpiringSet, and Vault usage without
141
+ mutating Git. The `git-cas doctor` CLI continues to validate vault health.
98
142
 
99
143
  ## Safety Snapshot
100
144
 
@@ -139,6 +183,9 @@ All three runtimes are tested in CI on every push. The hexagonal architecture is
139
183
  - **[v6.0.0 Release Notes](./docs/releases/v6.0.0.md)**: Major-release summary, upgrade call-to-action, and publication notes.
140
184
  - **[v6.1.0 Release Notes](./docs/releases/v6.1.0.md)**: Root-set retention,
141
185
  doctor/repair, and GC-policy guidance.
186
+ - **[v6.2.0 Release Notes](./docs/releases/v6.2.0.md)**: Opaque application
187
+ storage, managed cache and replay lifecycles, retention evidence, and
188
+ repository diagnostics.
142
189
  - **[Upgrading](./UPGRADING.md)**: Migration guide for v5 → v6.
143
190
  - **[Changelog](./CHANGELOG.md)**: Version history and migration notes.
144
191
 
package/UPGRADING.md CHANGED
@@ -2,6 +2,49 @@
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.1.0 To v6.2.0
6
+
7
+ v6.2.0 is API-additive and does not require stored-data migration. It adds
8
+ high-level application storage, managed cache and replay lifecycles, immutable
9
+ retention evidence, and repository-wide diagnostics.
10
+
11
+ Applications should stop treating a naked Git object ID stored in JSON as a
12
+ durability guarantee. Stage content through `assets`, `pages`, or `bundles`,
13
+ then retain or publish the returned opaque handle through the policy surface
14
+ that matches its lifecycle:
15
+
16
+ ```javascript
17
+ const staged = await cas.assets.put({
18
+ source,
19
+ slug: 'warp/materialization',
20
+ filename: 'materialization.bin',
21
+ });
22
+
23
+ const cache = await cas.caches.open({
24
+ namespace: 'git-warp/materializations',
25
+ policy: { maxEntries: 10_000, maxBytes: 2 * 1024 * 1024 * 1024 },
26
+ });
27
+ const stored = await cache.put(cacheKey, staged.handle, {
28
+ retention: 'evictable',
29
+ expiresAt: new Date(Date.now() + 14 * 24 * 60 * 60 * 1000),
30
+ });
31
+ ```
32
+
33
+ Existing root sets and vault entries remain valid. Before running destructive
34
+ Git cleanup, applications migrating an existing object-ID index must first
35
+ enumerate every still-live object, validate that it still exists, and adopt it
36
+ into a RootSet or rebuild it through the appropriate high-level API. Neither
37
+ repair nor diagnostics can recover an object that Git already pruned.
38
+
39
+ Use `cas.diagnostics.doctor()` before and after migration to inspect anchored,
40
+ orphaned, and grace-expired object counts plus managed CacheSet, RootSet,
41
+ ExpiringSet, and Vault usage. The doctor is read-only; it never runs Git GC or
42
+ prune. Repository diagnostics require `@git-stunts/plumbing` 3.1.0 or newer.
43
+
44
+ See [v6.2.0 Release Notes](./docs/releases/v6.2.0.md) and
45
+ [Application Storage](./docs/API.md#application-storage) for the complete
46
+ capability and policy map.
47
+
5
48
  ## v6.0.1 To v6.1.0
6
49
 
7
50
  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": "432c5d9",
3
+ "timestamp": "2026-07-13T20:08:16.092Z"
4
4
  }