@git-stunts/git-cas 6.0.1 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/ARCHITECTURE.md +120 -6
  2. package/CHANGELOG.md +98 -1
  3. package/GUIDE.md +114 -13
  4. package/README.md +60 -4
  5. package/UPGRADING.md +71 -1
  6. package/build-info.json +2 -2
  7. package/docs/API.md +934 -7
  8. package/docs/WALKTHROUGH.md +46 -0
  9. package/docs/releases/v6.1.0.md +75 -0
  10. package/docs/releases/v6.2.0.md +131 -0
  11. package/index.d.ts +974 -1
  12. package/index.js +354 -1
  13. package/package.json +8 -6
  14. package/src/domain/errors/Codes.js +48 -0
  15. package/src/domain/helpers/assertCanonicalTimestamp.js +15 -0
  16. package/src/domain/helpers/handleTarget.js +48 -0
  17. package/src/domain/helpers/isCanonicalCollectionKey.js +35 -0
  18. package/src/domain/services/AssetService.js +213 -0
  19. package/src/domain/services/BundleDescriptorCodec.js +286 -0
  20. package/src/domain/services/BundleFanoutBuilder.js +247 -0
  21. package/src/domain/services/BundleService.js +848 -0
  22. package/src/domain/services/CacheCandidateHeap.js +71 -0
  23. package/src/domain/services/CacheIndex.js +362 -0
  24. package/src/domain/services/CacheMetadataCodec.js +164 -0
  25. package/src/domain/services/CachePolicyEnforcer.js +144 -0
  26. package/src/domain/services/CacheSet.js +703 -0
  27. package/src/domain/services/CacheSetRegistry.js +88 -0
  28. package/src/domain/services/CasService.d.ts +3 -1
  29. package/src/domain/services/ExpiringSet.js +496 -0
  30. package/src/domain/services/ExpiringSetIndex.js +254 -0
  31. package/src/domain/services/ExpiringSetMetadataCodec.js +160 -0
  32. package/src/domain/services/ExpiringSetRegistry.js +101 -0
  33. package/src/domain/services/PageService.js +175 -0
  34. package/src/domain/services/PublicationService.js +315 -0
  35. package/src/domain/services/RepositoryDoctor.js +649 -0
  36. package/src/domain/services/RetentionService.js +120 -0
  37. package/src/domain/services/RootSet.js +281 -0
  38. package/src/domain/services/RootSetMetadataCodec.js +259 -0
  39. package/src/domain/services/RootSetPersistence.js +335 -0
  40. package/src/domain/services/RootSetRegistry.js +44 -0
  41. package/src/domain/services/RootSetRetryPolicy.js +87 -0
  42. package/src/domain/services/RootSetTreeCodec.js +95 -0
  43. package/src/domain/services/StagingEvidence.js +39 -0
  44. package/src/domain/value-objects/ApplicationHandle.js +40 -0
  45. package/src/domain/value-objects/AssetHandle.js +163 -0
  46. package/src/domain/value-objects/BundleHandle.js +32 -0
  47. package/src/domain/value-objects/BundleLimits.js +80 -0
  48. package/src/domain/value-objects/BundlePath.js +78 -0
  49. package/src/domain/value-objects/CacheHit.js +93 -0
  50. package/src/domain/value-objects/CacheKey.js +32 -0
  51. package/src/domain/value-objects/CachePolicy.js +59 -0
  52. package/src/domain/value-objects/CacheSetRef.js +40 -0
  53. package/src/domain/value-objects/CollectionNamespace.js +54 -0
  54. package/src/domain/value-objects/ExpiringMarker.js +81 -0
  55. package/src/domain/value-objects/ExpiringSetKey.js +28 -0
  56. package/src/domain/value-objects/ExpiringSetRef.js +42 -0
  57. package/src/domain/value-objects/OpaqueHandle.js +171 -0
  58. package/src/domain/value-objects/PageHandle.js +34 -0
  59. package/src/domain/value-objects/RetentionWitness.js +101 -0
  60. package/src/domain/value-objects/RootSetRef.js +88 -0
  61. package/src/domain/value-objects/StagedAsset.js +63 -0
  62. package/src/domain/value-objects/StagedBundle.js +66 -0
  63. package/src/domain/value-objects/StagedPage.js +47 -0
  64. package/src/infrastructure/adapters/GitPersistenceAdapter.js +57 -0
  65. package/src/infrastructure/adapters/GitRefAdapter.js +26 -5
  66. package/src/infrastructure/adapters/GitRepositoryInspectionAdapter.js +164 -0
  67. package/src/package-version.js +1 -1
  68. package/src/ports/GitPersistencePort.js +20 -1
  69. package/src/ports/GitRefPort.js +10 -0
  70. package/src/ports/RepositoryInspectionPort.js +33 -0
package/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
  ```
@@ -116,6 +142,11 @@ The public entrypoint is [index.js](./index.js).
116
142
  - wires persistence, ref, codec, crypto, chunking, compression, and
117
143
  observability adapters
118
144
  - exposes convenience methods like `storeFile()` and `restoreFile()`
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()`
119
150
 
120
151
  The facade is orchestration glue. It is not the storage engine itself.
121
152
 
@@ -138,6 +169,34 @@ The facade is orchestration glue. It is not the storage engine itself.
138
169
  `VaultPrivacyIndex`, vault-key verification to `VaultKeyVerifier`, retry timing
139
170
  to `VaultMutationRetryPolicy`, and slug validation to `Slug`.
140
171
 
172
+ - **`RootSetRegistry` and `RootSet`** — open and mutate caller-owned refs under
173
+ `refs/cas/rootsets/*`. Root-set mutations retain only the current generation,
174
+ validate target existence and type, and use bounded compare-and-swap retries.
175
+ `RootSetPersistence`, `RootSetMetadataCodec`, and `RootSetTreeCodec` own the
176
+ ref, metadata, and real Git reachability boundaries.
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
+
141
200
  - **`KeyResolver`** — resolves key sources: passphrase-derived keys via KDF,
142
201
  envelope recipient DEK wrapping and unwrapping. `CasService` delegates all key
143
202
  material resolution through `this.keyResolver`.
@@ -190,7 +249,17 @@ The facade is orchestration glue. It is not the storage engine itself.
190
249
 
191
250
  - **`Manifest`** — immutable representation of stored asset metadata.
192
251
  - **`Chunk`** — immutable representation of one manifest chunk entry.
193
- - **`Oid`** — immutable Git object identifier value with 40-hex validation.
252
+ - **`Oid`** — immutable Git object identifier value with 40- or 64-hex
253
+ validation.
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.
194
263
  - **`Slug`** — immutable vault slug representation. It enforces vault slug
195
264
  limits and exposes `.toTreePath()` for the percent-encoded Git tree-entry name
196
265
  used by plain vault trees.
@@ -232,14 +301,16 @@ with methods that throw "not implemented" by default.
232
301
  mode.
233
302
  - **`GitPersistencePort`** — blob read/write, tree read/write, and
234
303
  `readBlobStream` for streaming chunk retrieval.
235
- - **`GitRefPort`** — ref resolution, commit creation, and compare-and-swap ref
236
- updates.
304
+ - **`GitRefPort`** — ref/tree/parent resolution, commit creation, and
305
+ compare-and-swap ref updates.
237
306
  - **`ChunkingPort`** — strategy interface for fixed-size and content-defined
238
307
  chunking.
239
308
  - **`CodecPort`** — manifest serialization and deserialization.
240
309
  - **`CompressionPort`** — compress/decompress for both byte arrays and streams.
241
310
  - **`ObservabilityPort`** — metrics, logs, and spans without binding the domain
242
311
  to any runtime event API.
312
+ - **`RepositoryInspectionPort`** — non-mutating streams for objects, refs,
313
+ reachable IDs, safe prunable candidates, and reachable physical bytes.
243
314
 
244
315
  ### Infrastructure (`src/infrastructure/`)
245
316
 
@@ -258,6 +329,9 @@ Git:
258
329
  `@git-stunts/plumbing` to shell out to the `git` CLI.
259
330
  - **`GitRefAdapter`** — `GitRefPort` implementation using
260
331
  `@git-stunts/plumbing`.
332
+ - **`GitRepositoryInspectionAdapter`** — `RepositoryInspectionPort`
333
+ implementation using streamed Git inventories and plumbing's non-mutating
334
+ prunable-object inspection.
261
335
 
262
336
  Compression:
263
337
  - **`NodeCompressionAdapter`** — `CompressionPort` backed by `node:zlib`.
@@ -353,6 +427,46 @@ For Merkle assets the tree contains:
353
427
  Chunk blobs are deduplicated at the tree-entry level by digest. The manifest
354
428
  still remains authoritative for repeated-chunk order and multiplicity.
355
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
+
356
470
  ### Vault
357
471
 
358
472
  The vault is a GC-safe slug index rooted at `refs/cas/vault`.
package/CHANGELOG.md CHANGED
@@ -7,8 +7,101 @@ 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
+
90
+ ## [6.1.0] — 2026-07-11
91
+
10
92
  ### Added
11
93
 
94
+ - **Mutable GC-safe root sets** — `cas.rootSets.open()` now anchors named blob
95
+ and tree OIDs under `refs/cas/rootsets/*` while entries are live. Root-set
96
+ generations use parentless commits so removed targets can become prunable
97
+ instead of remaining reachable through storage history.
98
+ - **Root-set doctor and repair** — root sets validate ref, metadata, tree-edge,
99
+ target-existence, and target-type truth; report retention policy separately
100
+ from Git reachability; and can rebuild a malformed head from an authoritative
101
+ live-entry list.
102
+ - **Root-set compare-and-swap mutations** — `put()`, `remove()`, `replace()`,
103
+ and `mutate()` use bounded conflict retries without silently losing
104
+ concurrent updates.
12
105
  - **GitHub tracker templates** — added issue forms for goalposts, slices, bugs,
13
106
  debt, and ideas, plus a pull request template that links issues, design proof,
14
107
  validation, and release impact.
@@ -23,8 +116,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
23
116
  version-neutral, `STATUS.md` records the latest docs validation snapshot,
24
117
  `CLAUDE.md` delegates to `AGENTS.md`, and the stale root `GRAVEYARD.md` file
25
118
  has been removed.
119
+ - **6.1.0 release verification** — `npm run release:verify -- --skip-jsr`
120
+ passed 12/12 steps with 5,521 observed tests across Node, Bun, Deno, and all
121
+ three integration runtimes. JSR remains intentionally skipped behind the
122
+ documented upstream toolchain gate.
26
123
 
27
- ## [6.0.1] — 2026-05-09
124
+ ## [6.0.1] — 2026-06-13
28
125
 
29
126
  ### Added
30
127
 
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
@@ -20,6 +20,21 @@ Unlike traditional LFS which moves files to external servers, `git-cas` treats t
20
20
  - **Deduplication by Default**: Content-defined chunking (CDC) with Buzhash rolling hash identifies repeated patterns across files and versions, minimizing repository growth.
21
21
  - **Cryptographic Trust**: Every chunk is verified against a SHA-256 digest. Optional AES-256-GCM encryption with multi-recipient envelope support ensures privacy at rest, and `framed` binds per-frame AAD to prevent cross-manifest blob swaps.
22
22
  - **GC-Safe Vault**: Named assets are indexed through a stable ref (`refs/cas/vault`) with optimistic concurrency, preventing Git garbage collection from reclaiming referenced blobs.
23
+ - **Mutable Root Sets**: Cache and derived-state trees can be anchored under
24
+ `refs/cas/rootsets/*` while live, then become collectible after eviction,
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.
23
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.
24
39
  - **Runtime-Adaptive**: A single core supports Node.js 22+, Bun, and Deno through a strict hexagonal port architecture with runtime-specific crypto adapters.
25
40
 
@@ -28,7 +43,7 @@ Unlike traditional LFS which moves files to external servers, `git-cas` treats t
28
43
  Existing v5 users should read [UPGRADING.md](./UPGRADING.md) and run
29
44
  `npm run upgrade` in dry-run mode before restoring old encrypted vault entries.
30
45
  For the release overview, see the
31
- [v6.0.0 Release Notes](./docs/releases/v6.0.0.md).
46
+ [v6.2.0 Release Notes](./docs/releases/v6.2.0.md).
32
47
 
33
48
  ### 1. CLI Usage
34
49
 
@@ -54,11 +69,26 @@ git-cas vault dashboard
54
69
  Integrate managed blob storage directly into your TypeScript or JavaScript application.
55
70
 
56
71
  ```js
72
+ import { createReadStream } from 'node:fs';
57
73
  import ContentAddressableStore from '@git-stunts/git-cas';
74
+
58
75
  const cas = await ContentAddressableStore.open({ cwd: '.' });
59
- 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
+ });
60
86
  ```
61
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
+
62
92
  ## Capability Map
63
93
 
64
94
  The README is the front door. Detailed mechanics live in the guide set:
@@ -70,6 +100,11 @@ The README is the front door. Detailed mechanics live in the guide set:
70
100
  | Encryption scheme selection | [Encryption Modes](./docs/ENCRYPTION_MODES.md) |
71
101
  | CDC internals, Merkle manifests, KDF policy, and tuning | [Advanced Guide](./ADVANCED_GUIDE.md) |
72
102
  | Ports, adapters, and collaborator boundaries | [Architecture](./ARCHITECTURE.md) |
103
+ | Assets, pages, bundles, retention, and publication | [Application storage](./docs/API.md#application-storage) |
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) |
73
108
  | v5 to v6 migration | [Upgrading](./UPGRADING.md) |
74
109
 
75
110
  Core capabilities:
@@ -84,10 +119,26 @@ Core capabilities:
84
119
  deduplication.
85
120
  - **Vault indexing**: named assets live under `refs/cas/vault` so Git garbage
86
121
  collection does not reclaim referenced blobs.
122
+ - **Root-set retention**: current cache entries live under caller-owned
123
+ `refs/cas/rootsets/*` refs. Entries are Git-reachable while present, and old
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.
87
136
  - **Envelope recipients**: multi-recipient key wrapping and recipient rotation
88
137
  avoid re-encrypting data blobs.
89
- - **Operational diagnostics**: `git-cas doctor` validates vault health and
90
- 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.
91
142
 
92
143
  ## Safety Snapshot
93
144
 
@@ -130,6 +181,11 @@ All three runtimes are tested in CI on every push. The hexagonal architecture is
130
181
  - **[Workflow](https://github.com/git-stunts/git-cas/blob/main/WORKFLOW.md)**: Repo work doctrine, cycles, and invariants.
131
182
  - **[Contributing](https://github.com/git-stunts/git-cas/blob/main/CONTRIBUTING.md)**, **[Code of Conduct](./CODE_OF_CONDUCT.md)**, and **[Support](./SUPPORT.md)**: Project participation and help paths.
132
183
  - **[v6.0.0 Release Notes](./docs/releases/v6.0.0.md)**: Major-release summary, upgrade call-to-action, and publication notes.
184
+ - **[v6.1.0 Release Notes](./docs/releases/v6.1.0.md)**: Root-set retention,
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.
133
189
  - **[Upgrading](./UPGRADING.md)**: Migration guide for v5 → v6.
134
190
  - **[Changelog](./CHANGELOG.md)**: Version history and migration notes.
135
191
 
package/UPGRADING.md CHANGED
@@ -1,7 +1,77 @@
1
- # Upgrading to git-cas v6.0.0
1
+ # Upgrading git-cas
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
+
48
+ ## v6.0.1 To v6.1.0
49
+
50
+ v6.1.0 is API-additive and does not require stored-data migration. It adds root
51
+ sets for mutable, GC-safe retention of cache and derived-state objects.
52
+
53
+ Applications that persisted tree OIDs only inside JSON should adopt every
54
+ still-live OID before running destructive Git cleanup:
55
+
56
+ ```javascript
57
+ const rootSet = await cas.rootSets.open({
58
+ ref: 'refs/cas/rootsets/my-application/cache',
59
+ });
60
+
61
+ await rootSet.repair({
62
+ entries: liveRecords.map((record) => ({
63
+ name: record.id,
64
+ oid: record.treeOid,
65
+ type: 'tree',
66
+ retention: 'evictable',
67
+ })),
68
+ });
69
+ ```
70
+
71
+ Repair cannot recover objects that Git already pruned. Verify
72
+ `(await rootSet.doctor()).healthy` before garbage collection. Existing vault
73
+ entries and ordinary branch/tag references need no change.
74
+
5
75
  ## Quick Start
6
76
 
7
77
  If you have an existing vault with encrypted assets:
package/build-info.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "sha": "b3aaedc",
3
- "timestamp": "2026-06-29T19:41:41.301Z"
2
+ "sha": "432c5d9",
3
+ "timestamp": "2026-07-13T20:08:16.092Z"
4
4
  }