@git-stunts/git-cas 6.2.0 → 6.4.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.
package/ARCHITECTURE.md CHANGED
@@ -187,7 +187,10 @@ The facade is orchestration glue. It is not the storage engine itself.
187
187
  - **`CacheSetRegistry` and `CacheSet`** — own cache index generations,
188
188
  compare-and-swap replacement, TTL, entry and logical-byte limits,
189
189
  approximate-LRU sweeps, coalesced touches, doctor, and authoritative repair
190
- under `refs/cas/caches/*`.
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.
191
194
 
192
195
  - **`ExpiringSetRegistry` and `ExpiringSet`** — own digest-only replay markers
193
196
  under `refs/cas/expiring/*`. Admission is atomic, membership reads are
@@ -447,21 +450,26 @@ make objects Git-reachable, but they encode different lifecycle contracts:
447
450
  | --- | --- | --- |
448
451
  | RootSet | `refs/cas/rootsets/*` | Caller-managed current generation |
449
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 |
450
454
  | ExpiringSet | `refs/cas/expiring/*` | Expiry-only replay protection |
451
455
  | Publication | Caller-allowlisted ref | Application-controlled causal history |
452
456
  | Vault | `refs/cas/vault` | History-preserving named assets |
453
457
 
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
+ 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.
458
465
 
459
466
  ### Repository Diagnostics
460
467
 
461
468
  `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.
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.
465
473
 
466
474
  The report names limits Git cannot prove exactly, including per-owner
467
475
  deduplicated physical bytes and packed-object age. The inspection surface has
package/CHANGELOG.md CHANGED
@@ -7,6 +7,69 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [6.4.0] — 2026-07-17
11
+
12
+ ### Added
13
+
14
+ - **Scoped staging workspaces** — `cas.workspaces.open()` now provides a
15
+ renewable, RootSet-backed lifetime for intermediate asset, page, and bundle
16
+ writes. Staging returns only after its typed handle is reachable from the
17
+ exact workspace generation; checkpoint compaction, witness-checked
18
+ destination-first cache or publication promotion, idempotent checked
19
+ release, and serialized mutations preserve explicit ownership under
20
+ concurrency. Expiry is
21
+ observable posture rather than automatic revocation. Namespace-bounded
22
+ inspection and checked sweep expose root count, age, expiry, logical content
23
+ bytes, unique direct-root object bytes, invalid state, conflicts, and
24
+ truncation. Repository doctor includes the same workspace inventory without
25
+ claiming deduplicated or packed physical-byte attribution. Workspace
26
+ witnesses reuse the existing `root-set` kind, and workspace-detail truncation
27
+ uses a dedicated code without widening closed public discriminant unions.
28
+
29
+ ### Fixed
30
+
31
+ - **RootSet structured lock retries** — exact managed `update-ref --no-deref`
32
+ lock races surfaced as `GIT_REPOSITORY_LOCKED` now normalize to
33
+ `ROOT_SET_CONFLICT`, allowing the existing bounded retry policy to run.
34
+ Structured lock failures for other refs remain terminal.
35
+
36
+ ## [6.3.0] — 2026-07-17
37
+
38
+ ### Added
39
+
40
+ - **Scoped cache acquisitions** — `CacheSet.acquire()` now performs a bounded,
41
+ reference-only lookup and atomically anchors the selected cache generation
42
+ for an explicit caller lifetime. Acquisitions carry separate pinned
43
+ retention evidence, release idempotently with a generation check, expose
44
+ bounded inspection and operational cleanup, and appear in repository doctor
45
+ with count and age evidence. Clock skew leaves structurally valid retention
46
+ healthy while reporting an unknown age and explicit diagnostic issue.
47
+ Real-Git coverage proves active acquisitions
48
+ survive aggressive prune without making lookup reads scale with target graph
49
+ size. Canonical one-segment namespace refs, symbolic-ref preflight,
50
+ no-dereference mutations across ordinary managed refs and acquisition refs,
51
+ post-conflict ref-type checks, and hard Git inventory limits preserve
52
+ ownership boundaries under hostile or malformed refs. Unknown ref-type
53
+ evidence fails doctor health closed. Acquisition capabilities remain optional
54
+ on the base Git ref port, the existing retention-kind and diagnostic-kind
55
+ unions remain unchanged, and the new doctor group is type-optional for
56
+ compatibility with existing consumers. Production Git checked-delete
57
+ conflicts fail closed because Git 2.43 cannot atomically prove that a missing
58
+ direct ref is not an enumerator-invisible dangling symbolic ref.
59
+
60
+ ### Fixed
61
+
62
+ - **Pre-push Git environment isolation** — repository-local `GIT_*` variables
63
+ exported by Git hooks are cleared before lint and tests run, so child
64
+ processes can create and inspect independent temporary repositories. The
65
+ hook fails closed if Git cannot enumerate the local variables.
66
+
67
+ ### Documentation
68
+
69
+ - **v6.2.0 publication evidence** — records the signed tag identity, successful
70
+ release workflow, npm integrity and SLSA provenance, final GitHub Release,
71
+ and the registry gate that unlocks downstream application adoption.
72
+
10
73
  ## [6.2.0] — 2026-07-13
11
74
 
12
75
  ### Added
package/README.md CHANGED
@@ -25,7 +25,8 @@ Unlike traditional LFS which moves files to external servers, `git-cas` treats t
25
25
  without vault history retaining every prior generation.
26
26
  - **Managed Cache Sets**: Applications can store handles under
27
27
  `refs/cas/caches/*` with TTL, entry and logical-byte limits, approximate LRU
28
- eviction, immutable retention evidence, bounded inspection, and repair.
28
+ eviction, immutable retention evidence, bounded inspection, repair, and
29
+ scoped acquisitions that keep a selected generation reachable during use.
29
30
  Cache indexes and object reachability remain git-cas responsibilities.
30
31
  - **Expiry-Safe Replay Sets**: Security-sensitive markers can live under
31
32
  `refs/cas/expiring/*` with atomic add-if-absent, digest-only metadata, and
@@ -43,7 +44,7 @@ Unlike traditional LFS which moves files to external servers, `git-cas` treats t
43
44
  Existing v5 users should read [UPGRADING.md](./UPGRADING.md) and run
44
45
  `npm run upgrade` in dry-run mode before restoring old encrypted vault entries.
45
46
  For the release overview, see the
46
- [v6.2.0 Release Notes](./docs/releases/v6.2.0.md).
47
+ [v6.4.0 Release Notes](./docs/releases/v6.4.0.md).
47
48
 
48
49
  ### 1. CLI Usage
49
50
 
@@ -101,8 +102,10 @@ The README is the front door. Detailed mechanics live in the guide set:
101
102
  | CDC internals, Merkle manifests, KDF policy, and tuning | [Advanced Guide](./ADVANCED_GUIDE.md) |
102
103
  | Ports, adapters, and collaborator boundaries | [Architecture](./ARCHITECTURE.md) |
103
104
  | Assets, pages, bundles, retention, and publication | [Application storage](./docs/API.md#application-storage) |
105
+ | Temporary retention during multi-step composition | [Scoped staging workspaces](./docs/API.md#scoped-staging-workspaces) |
104
106
  | GC retention for caches and derived state | [Root Sets](./docs/API.md#root-sets) |
105
107
  | Managed TTL and capacity caches | [Cache Sets](./docs/API.md#cache-sets) |
108
+ | Scoped protection while consuming a cache hit | [Cache acquisitions](./docs/API.md#acquire-and-release) |
106
109
  | Durable replay markers with expiry-only release | [Expiring Sets](./docs/API.md#expiring-sets) |
107
110
  | Repository reachability and git-cas usage evidence | [Repository Diagnostics](./docs/API.md#repository-diagnostics) |
108
111
  | v5 to v6 migration | [Upgrading](./UPGRADING.md) |
@@ -126,6 +129,10 @@ Core capabilities:
126
129
  compare-and-swap replacement, expiry, capacity eviction, retention
127
130
  witnesses, diagnostics, and repair. Reads do not write access metadata;
128
131
  callers opt into coalesced access updates with `touch()`.
132
+ - **Scoped cache acquisitions**: `cache.acquire()` performs a reference-only
133
+ lookup and atomically anchors the selected cache generation for the caller's
134
+ explicit lifetime. `release()` is idempotent, while inspection and checked
135
+ cleanup make abandoned acquisition refs observable and recoverable.
129
136
  - **Expiry-safe replay lifecycle**: `expiringSets.open()` atomically retains
130
137
  digest-only replay markers through their declared window. `contains()` is
131
138
  read-only, and `sweep()` can release only markers whose expiry has passed.
@@ -133,12 +140,17 @@ Core capabilities:
133
140
  `publications` compose streaming CAS writes, bounded structured
134
141
  materializations, targeted member reads, reachability roots,
135
142
  compare-and-swap refs, and immutable lifecycle evidence.
143
+ - **Scoped staging workspaces**: `workspaces.open()` mirrors application writes
144
+ behind one renewable temporary RootSet, returns only after each handle is
145
+ anchored, promotes destination-first, and exposes bounded age, expiry,
146
+ logical-content, and direct-root diagnostics with opaque cleanup pagination.
136
147
  - **Envelope recipients**: multi-recipient key wrapping and recipient rotation
137
148
  avoid re-encrypting data blobs.
138
149
  - **Operational diagnostics**: `cas.diagnostics.doctor()` streams repository
139
150
  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.
151
+ and summarizes workspaces, cache acquisitions, CacheSet, RootSet,
152
+ ExpiringSet, and Vault usage without mutating Git. The `git-cas doctor` CLI
153
+ continues to validate vault health.
142
154
 
143
155
  ## Safety Snapshot
144
156
 
@@ -186,6 +198,10 @@ All three runtimes are tested in CI on every push. The hexagonal architecture is
186
198
  - **[v6.2.0 Release Notes](./docs/releases/v6.2.0.md)**: Opaque application
187
199
  storage, managed cache and replay lifecycles, retention evidence, and
188
200
  repository diagnostics.
201
+ - **[v6.3.0 Release Notes](./docs/releases/v6.3.0.md)**: Lifetime-safe,
202
+ reference-only cache acquisitions with explicit release and doctor evidence.
203
+ - **[v6.4.0 Release Notes](./docs/releases/v6.4.0.md)**: Scoped staging
204
+ workspaces for temporary multi-object reachability, promotion, and cleanup.
189
205
  - **[Upgrading](./UPGRADING.md)**: Migration guide for v5 → v6.
190
206
  - **[Changelog](./CHANGELOG.md)**: Version history and migration notes.
191
207
 
package/UPGRADING.md CHANGED
@@ -2,6 +2,80 @@
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.3.0 To v6.4.0
6
+
7
+ v6.4.0 is API-additive and does not require stored-data migration. It adds
8
+ scoped staging workspaces for applications that construct one durable result
9
+ from many intermediate assets, pages, or bundles.
10
+
11
+ Do not use a CacheSet as temporary construction storage. Open one workspace,
12
+ stage the intermediate values through it, compact the retained roots after an
13
+ aggregate becomes transitively complete, and promote only the terminal handle:
14
+
15
+ ```javascript
16
+ const workspace = await cas.workspaces.open({
17
+ namespace: 'my-application/materializations',
18
+ ttlMs: 2 * 60 * 60 * 1000,
19
+ });
20
+
21
+ try {
22
+ const page = await workspace.pages.put({ source: encodedPage });
23
+ const bundle = await workspace.bundles.putOrdered({
24
+ members: [['pages/result.cbor', page.handle]],
25
+ });
26
+ await workspace.checkpoint({ handles: [bundle.handle] });
27
+ await workspace.promoteToCache({ cache, key, handle: bundle.handle });
28
+ } finally {
29
+ await workspace.release();
30
+ }
31
+ ```
32
+
33
+ Every returned staged value is anchored by an exact workspace generation.
34
+ Promotion requires matching destination retention evidence before source
35
+ release. Expiry is diagnostic posture, not automatic deletion; abandoned
36
+ workspaces remain reachable until a caller traverses bounded `inspect()` or
37
+ `sweep()` pages using `nextCursor`.
38
+
39
+ The interval between writing an object and publishing the workspace ref still
40
+ depends on Git's ordinary unreachable-object grace period. Concurrent
41
+ immediate-expiry pruning inside that interval is unsupported.
42
+
43
+ See [v6.4.0 Release Notes](./docs/releases/v6.4.0.md) and
44
+ [Scoped Staging Workspaces](./docs/API.md#scoped-staging-workspaces) for the
45
+ complete retention, promotion, and recovery contract.
46
+
47
+ ## v6.2.0 To v6.3.0
48
+
49
+ v6.3.0 is API-additive and does not require stored-data migration. It adds
50
+ scoped cache acquisitions for consumers that must keep a cache hit reachable
51
+ between lookup and use.
52
+
53
+ `CacheSet.get()` retains its existing complete-validation semantics, but a
54
+ returned hit is only an observation. Use `acquire()` when consumption may
55
+ overlap replacement, expiry, eviction, removal, or destructive Git cleanup:
56
+
57
+ ```javascript
58
+ const acquisition = await cache.acquire(materializationKey);
59
+ if (acquisition) {
60
+ try {
61
+ await consume(acquisition.hit.handle);
62
+ } finally {
63
+ await acquisition.release();
64
+ }
65
+ }
66
+ ```
67
+
68
+ An acquisition anchors the exact observed cache generation until explicit,
69
+ idempotent release. It intentionally has no automatic TTL: age is diagnostic
70
+ evidence, not proof that a consumer is dead. Recovery tooling can use
71
+ `cache.inspectAcquisitions({ limit })` and generation-checked
72
+ `cache.releaseAcquisition(...)`; `cas.diagnostics.doctor()` reports bounded
73
+ count, age, truncation, malformed-ref, and clock-skew evidence.
74
+
75
+ See [v6.3.0 Release Notes](./docs/releases/v6.3.0.md) and
76
+ [Acquire And Release](./docs/API.md#acquire-and-release) for the complete
77
+ lifetime and recovery contract.
78
+
5
79
  ## v6.1.0 To v6.2.0
6
80
 
7
81
  v6.2.0 is API-additive and does not require stored-data migration. It adds
package/build-info.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "sha": "432c5d9",
3
- "timestamp": "2026-07-13T20:08:16.092Z"
2
+ "sha": "d47af74",
3
+ "timestamp": "2026-07-18T02:58:21.403Z"
4
4
  }
package/docs/API.md CHANGED
@@ -16,17 +16,18 @@ should treat restored data, chunker output, codec output, and keys as
16
16
 
17
17
  1. [ContentAddressableStore](#contentaddressablestore)
18
18
  2. [Application Storage](#application-storage)
19
- 3. [Root Sets](#root-sets)
20
- 4. [Cache Sets](#cache-sets)
21
- 5. [Expiring Sets](#expiring-sets)
22
- 6. [Repository Diagnostics](#repository-diagnostics)
23
- 7. [Vault](#vault)
24
- 8. [CasService](#casservice)
25
- 9. [Events](#events)
26
- 10. [Value Objects](#value-objects)
27
- 11. [Ports](#ports)
28
- 12. [Codecs](#codecs)
29
- 13. [Error Codes](#error-codes)
19
+ 3. [Scoped Staging Workspaces](#scoped-staging-workspaces)
20
+ 4. [Root Sets](#root-sets)
21
+ 5. [Cache Sets](#cache-sets)
22
+ 6. [Expiring Sets](#expiring-sets)
23
+ 7. [Repository Diagnostics](#repository-diagnostics)
24
+ 8. [Vault](#vault)
25
+ 9. [CasService](#casservice)
26
+ 10. [Events](#events)
27
+ 11. [Value Objects](#value-objects)
28
+ 12. [Ports](#ports)
29
+ 13. [Codecs](#codecs)
30
+ 14. [Error Codes](#error-codes)
30
31
 
31
32
  ## ContentAddressableStore
32
33
 
@@ -1239,6 +1240,137 @@ generation later.
1239
1240
  `toJSON()` serializes `handle` to its canonical token and copies the root
1240
1241
  evidence fields.
1241
1242
 
1243
+ ## Scoped Staging Workspaces
1244
+
1245
+ Scoped staging workspaces retain intermediate application handles while a
1246
+ caller builds a larger asset or bundle. They are the high-level temporary
1247
+ reachability API. Use them instead of managing Git refs, raw CAS objects, or a
1248
+ general CacheSet as a build scratchpad.
1249
+
1250
+ ```javascript
1251
+ const workspace = await cas.workspaces.open({
1252
+ namespace: 'git-warp/materializations',
1253
+ ttlMs: 2 * 60 * 60 * 1000,
1254
+ });
1255
+
1256
+ try {
1257
+ const first = await workspace.pages.put({ source: firstShard });
1258
+ const second = await workspace.pages.put({ source: secondShard });
1259
+ const bundle = await workspace.bundles.putOrdered({
1260
+ members: [
1261
+ ['shards/first.cbor', first.handle],
1262
+ ['shards/second.cbor', second.handle],
1263
+ ],
1264
+ });
1265
+
1266
+ await workspace.checkpoint({ handles: [bundle.handle] });
1267
+ return await workspace.promoteToCache({
1268
+ cache,
1269
+ key: materializationKey,
1270
+ handle: bundle.handle,
1271
+ options: { retention: 'evictable' },
1272
+ });
1273
+ } finally {
1274
+ await workspace.release();
1275
+ }
1276
+ ```
1277
+
1278
+ `cas.workspaces.open({ namespace, ttlMs })` creates an in-memory workspace. It
1279
+ does not create a Git ref until the first successful stage or checkpoint. The
1280
+ default TTL is two hours; the maximum is seven days. `ttlMs` must be a positive
1281
+ safe integer.
1282
+
1283
+ The workspace mirrors only application-storage writes:
1284
+
1285
+ ```javascript
1286
+ await workspace.assets.put(options);
1287
+ await workspace.assets.adopt(options);
1288
+ await workspace.pages.put(options);
1289
+ await workspace.bundles.put(options);
1290
+ await workspace.bundles.putOrdered(options);
1291
+ ```
1292
+
1293
+ Each method returns only after a direct workspace generation reaches the
1294
+ returned typed handle. The result is otherwise the ordinary staged result plus
1295
+ a workspace `RetentionWitness`. Calls on one workspace serialize their ref
1296
+ mutations so concurrent staging cannot silently lose an accumulated root.
1297
+
1298
+ This guarantee starts when the method returns. Like all Git object composition,
1299
+ the object-write-to-ref-update interval still relies on Git's ordinary
1300
+ unreachable-object grace period. Running immediate-expiry prune concurrently
1301
+ inside that interval is unsupported.
1302
+
1303
+ ### Checkpoint, renew, promote, and release
1304
+
1305
+ `checkpoint({ handles })` replaces the active roots with the unique supplied
1306
+ handles. Use it after an aggregate bundle transitively reaches its components.
1307
+ An empty checkpoint removes active targets and installs a descriptor-only lease
1308
+ generation, leaving the workspace available for later staging.
1309
+
1310
+ `renew()` preserves the current target set and advances its lease descriptor.
1311
+ Successful staging, checkpoint, and promotion preparation also renew the
1312
+ workspace.
1313
+
1314
+ `promoteToCache({ cache, key, handle, options })` and
1315
+ `promoteToPublication({ handle, commit, ref })` establish destination
1316
+ retention before releasing the workspace. The promoted handle must belong to
1317
+ the active generation. The destination must return an anchored witness for the
1318
+ exact handle, ref, and generation. Rejection, missing evidence, or destination
1319
+ failure leaves the workspace intact and reports
1320
+ `WORKSPACE_PROMOTION_NOT_RETAINED` where applicable. If destination retention
1321
+ succeeds but workspace cleanup conflicts, the operation fails with
1322
+ `WORKSPACE_PROMOTION_CLEANUP_PENDING`; its metadata distinguishes retained
1323
+ destination state from pending temporary cleanup.
1324
+
1325
+ `release()` is idempotent for one workspace object and deletes only its exact
1326
+ observed direct-ref generation. A conflicting generation or symbolic ref fails
1327
+ closed. Calling any staging, checkpoint, renewal, or promotion method after a
1328
+ successful release fails with `WORKSPACE_RELEASED`.
1329
+
1330
+ ### Inspect and sweep
1331
+
1332
+ Workspace expiry is operational posture, not automatic revocation. An expired
1333
+ workspace remains Git-reachable until an explicit checked sweep removes it.
1334
+
1335
+ ```javascript
1336
+ const inspection = await cas.workspaces.inspect({
1337
+ namespace: 'git-warp/materializations',
1338
+ limit: 100,
1339
+ });
1340
+
1341
+ let cursor = null;
1342
+ do {
1343
+ const cleanup = await cas.workspaces.sweep({
1344
+ namespace: 'git-warp/materializations',
1345
+ limit: 100,
1346
+ cursor,
1347
+ });
1348
+ cursor = cleanup.nextCursor;
1349
+ } while (cursor !== null);
1350
+ ```
1351
+
1352
+ Inspection is namespace-scoped and bounded. Each record reports identity,
1353
+ generation, direct-root count, creation time, age, expiry, posture, and two
1354
+ different byte measures:
1355
+
1356
+ - `logicalBytes` sums the validated semantic content size reported by each
1357
+ retained typed handle. Overlapping handles can describe overlapping content.
1358
+ - `rootObjectBytes` sums each unique direct Git root object's loose logical
1359
+ size. It excludes transitive support, deduplication attribution, pack
1360
+ compression, and filesystem overhead.
1361
+
1362
+ Inspection validates the canonical target name, typed handle, OID, Git object
1363
+ type, and complete application handle graph. Invalid persisted state produces
1364
+ `posture: 'invalid'` with structured issue evidence instead of a guessed byte
1365
+ count.
1366
+
1367
+ `sweep()` deletes only records observed as expired, direct, and still at the
1368
+ same generation. Inspection and sweep return an opaque `nextCursor` whenever
1369
+ `truncated` is true; pass that cursor to the next call so active or invalid
1370
+ records cannot starve later expired workspaces. The sweep result reports
1371
+ inspected, changed, conflicted, missing, and truncated counts. Sweep never
1372
+ removes active or invalid records.
1373
+
1242
1374
  ## Root Sets
1243
1375
 
1244
1376
  Root sets retain a mutable current set of Git blobs or trees. They are intended
@@ -1511,6 +1643,71 @@ generation, and immutable retention evidence.
1511
1643
  `accessedAt` is at least `accessResolutionMs` old, coalescing approximate-LRU
1512
1644
  updates without turning every read into a Git ref mutation.
1513
1645
 
1646
+ ### acquire And release
1647
+
1648
+ Use `acquire(key)` when the caller will consume a cached handle while another
1649
+ writer may replace, remove, expire, or sweep that cache entry:
1650
+
1651
+ ```javascript
1652
+ const acquisition = await cache.acquire('optic:user:alice');
1653
+ if (acquisition) {
1654
+ try {
1655
+ await consume(acquisition.hit.handle);
1656
+ } finally {
1657
+ await acquisition.release();
1658
+ }
1659
+ }
1660
+ ```
1661
+
1662
+ `acquire()` returns an immutable `CacheAcquisition` or `null`. It performs a
1663
+ reference-only cache lookup: the operation reads the bounded index path and
1664
+ does not recursively materialize or validate the target handle graph. It then
1665
+ atomically verifies the observed cache ref generation and creates a unique ref
1666
+ under `refs/cas/cache-acquisitions/<encoded-namespace>/*` that names that
1667
+ generation. The namespace occupies exactly one encoded ref segment, preventing
1668
+ parent and child cache namespaces from overlapping during inspection.
1669
+ If a writer changes the cache generation during this transaction, acquisition
1670
+ retries against a fresh bounded lookup up to five times and then fails with
1671
+ `CACHE_ACQUISITION_CONFLICT`.
1672
+
1673
+ The acquisition carries the original `hit`, a separate pinned retention
1674
+ `evidence` witness, its opaque `id`, and `acquiredAt`. The witness keeps the
1675
+ existing `cache-set` root kind because the retained object is a cache-set
1676
+ generation; its acquisition ref identifies the scoped retention mechanism.
1677
+ This preserves the public closed `RetentionRootKind` union. The ref temporarily
1678
+ keeps the complete selected cache generation reachable, including the requested
1679
+ target. This is intentionally stronger than a bare cache observation and must
1680
+ not be left open after consumption.
1681
+
1682
+ `release()` preflights and rejects a symbolic acquisition ref that is already
1683
+ observable, then generation-checks a no-dereference deletion. Git 2.43 cannot
1684
+ atomically assert both ref type and OID. If another process installs a same-OID
1685
+ symbolic ref after preflight, Git may delete that managed ref name; `--no-deref`
1686
+ ensures it never deletes or updates the symbolic referent. This API claims
1687
+ authority containment under that race, not race-free ref-type rejection.
1688
+ Release through one `CacheAcquisition` object is idempotent: the call that
1689
+ deletes the ref reports `changed: true`; later calls reuse its receipt and report
1690
+ `changed: false`. Concurrent calls on that object share one operation. A
1691
+ mismatched or otherwise unprovable direct generation fails closed with
1692
+ `CACHE_ACQUISITION_RELEASE_CONFLICT`.
1693
+ There is no implicit TTL because elapsed time alone cannot prove that a live
1694
+ caller has finished using the handle.
1695
+
1696
+ The production Git adapter applies the same authority boundary to ordinary
1697
+ managed RootSet, publication, and vault ref movement: it rejects a symbolic ref
1698
+ observed before mutation and always invokes `git update-ref --no-deref`. A
1699
+ post-probe ref-type race may replace the managed name itself, but cannot redirect
1700
+ the update into a symbolic referent.
1701
+
1702
+ Existing custom ref and crypto adapters remain valid for `get()`, `put()`,
1703
+ `replace()`, `remove()`, `sweep()`, and `touch()`. Acquisition operations add
1704
+ capability requirements only when invoked: atomic `anchorRef`, checked
1705
+ `deleteRef`, streaming `iterateRefs`, and 16-byte `randomBytes`. A missing
1706
+ capability fails the acquisition operation with `CACHE_ACQUISITION_INVALID`;
1707
+ it does not prevent the cache from opening or change existing operations. The
1708
+ three ref capabilities remain optional on the public base port so existing
1709
+ structural adapters continue to type-check.
1710
+
1514
1711
  ### remove And sweep
1515
1712
 
1516
1713
  ```javascript
@@ -1538,6 +1735,7 @@ Logical-byte accounting is versioned and deterministic:
1538
1735
  ```javascript
1539
1736
  const first = await cache.inspect({ limit: 100 });
1540
1737
  const next = await cache.inspect({ limit: 100, cursor: first.nextCursor });
1738
+ const active = await cache.inspectAcquisitions({ limit: 100 });
1541
1739
  const report = await cache.doctor();
1542
1740
  ```
1543
1741
 
@@ -1548,6 +1746,26 @@ parentless generation, RootSet edge, structured bundle support graph, key
1548
1746
  digests, target handles, canonical metadata, accounting version, persisted
1549
1747
  summary, and capacity posture.
1550
1748
 
1749
+ `inspectAcquisitions()` streams only this cache namespace's acquisition refs.
1750
+ It returns opaque IDs, generation OIDs, acquisition timestamps, and key digests
1751
+ from a work-bounded first page of at most 1,000 entries; it does not disclose
1752
+ original cache keys. The result's `truncated` flag means at least one more entry
1753
+ exists. Cleanup releases the returned entries and repeats inspection while
1754
+ `truncated` is true. There is intentionally no cursor that can scan through an
1755
+ unbounded skipped prefix. Operational repair releases an abandoned acquisition
1756
+ with an explicit generation check:
1757
+
1758
+ ```javascript
1759
+ await cache.releaseAcquisition({
1760
+ id: active.entries[0].id,
1761
+ expectedGeneration: active.entries[0].generation,
1762
+ });
1763
+ ```
1764
+
1765
+ Normal callers should retain the `CacheAcquisition` object and call its
1766
+ `release()` method. The lower-level cleanup method exists for doctor/repair
1767
+ workflows and refuses to delete a ref whose generation no longer matches.
1768
+
1551
1769
  ### repair
1552
1770
 
1553
1771
  ```javascript
@@ -1698,17 +1916,20 @@ const report = await cas.diagnostics.doctor({
1698
1916
  });
1699
1917
 
1700
1918
  console.log(report.repository.objects);
1919
+ console.log(report.usage.acquisitions);
1701
1920
  console.log(report.usage.caches);
1921
+ console.log(report.usage.workspaces);
1702
1922
  console.log(report.limitations);
1703
1923
  ```
1704
1924
 
1705
1925
  Pass either `gracePeriodMs` or an exact canonical `expiresBefore` UTC timestamp,
1706
1926
  not both. The default grace period is 14 days. `maxCollectionsPerKind` bounds
1707
- detailed CacheSet, RootSet, and ExpiringSet rows from 1 through 1000; its default
1708
- is 100. Every managed collection is still inspected sequentially and included
1709
- in `totals`. Coverage reports `observed`, `inspected`, `detailed`, and
1710
- `complete`, so detail truncation is visible instead of silently dropping
1711
- managed refs or undercounting repository usage.
1927
+ detailed cache-acquisition, CacheSet, RootSet, ExpiringSet, and workspace rows
1928
+ from 1 through 1000; its default is 100. Every managed collection or
1929
+ acquisition is still inspected sequentially and included in `totals`. Coverage reports
1930
+ `observed`, `inspected`, `detailed`, and `complete`, so detail truncation is
1931
+ visible instead of silently dropping managed refs or undercounting repository
1932
+ usage.
1712
1933
 
1713
1934
  The reachability classes have precise operational meanings:
1714
1935
 
@@ -1735,11 +1956,34 @@ in its inventory, while object disk sizes exclude pack indexes, bitmaps, and
1735
1956
  other repository metadata. These facts appear in `limitations` rather than
1736
1957
  being estimated.
1737
1958
 
1738
- Cache summaries report entry count, deterministic logical bytes, age, expiry,
1739
- capacity policy, and pinned/evictable counts. RootSet policy counts and Vault
1740
- entry counts are reported independently from reachability. A privacy-mode
1741
- vault remains healthy but reports `entryCount: null` because repository doctor
1742
- does not request or retain vault key material.
1959
+ Acquisition summaries report active count, oldest and newest acquisition time,
1960
+ and maximum age; detailed entries expose opaque IDs and never original cache
1961
+ keys. If an acquisition timestamp is later than the doctor clock, the direct
1962
+ retention ref remains healthy, `ageMs` is `null`, and the entry reports
1963
+ `CACHE_ACQUISITION_CLOCK_SKEW`; elapsed time is evidence, not ref validity.
1964
+ `maxAgeMs` is `null` when any active acquisition age is incomparable. Cache
1965
+ summaries report entry count, deterministic logical bytes, age,
1966
+ expiry, capacity policy, and pinned/evictable counts. RootSet policy counts and
1967
+ Vault entry counts are reported independently from reachability. Workspace
1968
+ summaries report active and expired counts, validated logical bytes, and unique
1969
+ direct-root object bytes; detailed rows carry creation age, exact expiry, and
1970
+ invalid-state evidence. Neither workspace byte field is physical residency. A
1971
+ privacy-mode vault remains healthy but reports `entryCount: null` because
1972
+ repository doctor does not request or retain vault key material.
1973
+
1974
+ Git's `for-each-ref` does not enumerate dangling symbolic refs. Repository
1975
+ doctor therefore reports symbolic acquisition refs that Git returns, but does
1976
+ not claim exhaustive inventory of dangling symbolic acquisition refs. An
1977
+ inspection adapter that omits `symref` evidence makes the acquisition group and
1978
+ overall doctor report unhealthy rather than treating unknown ref type as a
1979
+ regular ref. Direct acquire, release, and cleanup operations independently
1980
+ preflight with `symbolic-ref`; no-dereference mutations contain post-probe races
1981
+ to the managed ref name. After a checked-delete conflict, release probes ref
1982
+ type and direct-ref inventory for diagnostic evidence, then fails closed. Git
1983
+ 2.43 cannot atomically prove that an absent direct ref is not an
1984
+ enumerator-invisible dangling symbolic ref, so the production adapter does not
1985
+ infer an idempotent miss from that conflict. Recovery code can re-inspect the
1986
+ bounded acquisition namespace before deciding that cleanup is complete.
1743
1987
 
1744
1988
  Object and ref inventories are consumed as streams, and managed collections are
1745
1989
  inspected one at a time. Runtime memory is bounded by stream windows,
@@ -2657,6 +2901,10 @@ for await (const oid of port.iterateReachableObjectIds()) {
2657
2901
  for await (const object of port.iteratePrunableObjects({ expiresBefore })) {
2658
2902
  // safe dry-run evidence only
2659
2903
  }
2904
+
2905
+ for await (const ref of port.iterateRefs({ prefix: 'refs/cas/cache-acquisitions/' })) {
2906
+ // streamed repository diagnostics; ref.symref exposes symbolic targets
2907
+ }
2660
2908
  ```
2661
2909
 
2662
2910
  `GitRepositoryInspectionAdapter` requires `@git-stunts/plumbing` 3.1.0 or
@@ -3061,8 +3309,12 @@ new CasError({ message, code, meta, documentationUrl });
3061
3309
  | `CACHE_ENTRY_INVALID` | Entry metadata, retention, expiry, handle identity, or key digest is invalid | CacheSet writes and reads |
3062
3310
  | `CACHE_STATE_INVALID` | Cache state, structured index, counts, or namespace is inconsistent | CacheSet reads, `doctor()`, and `repair()` |
3063
3311
  | `CACHE_POLICY_INVALID` | Cache entry, byte, access-resolution, or repair bound is invalid | `caches.open()`, CacheSet policy operations |
3312
+ | `CACHE_ACQUISITION_INVALID` | Acquisition identity, timestamp, dependency, or inspection option is invalid | `acquire()`, acquisition inspection, and release |
3313
+ | `CACHE_ACQUISITION_CONFLICT` | Cache generation changed throughout bounded acquisition retries | `acquire()` |
3314
+ | `CACHE_ACQUISITION_RELEASE_CONFLICT` | Acquisition ref no longer names the generation supplied for checked cleanup | `release()` and `releaseAcquisition()` |
3064
3315
  | `CACHE_LOGICAL_SIZE_UNKNOWN` | A target has no deterministic safe-integer logical size | `put()`, `replace()`, accounting, and repair |
3065
3316
  | `CACHE_CONFLICT` | Concurrent cache update exhausted bounded compare-and-swap retries | CacheSet mutations and repair |
3317
+ | `GIT_REF_CONFLICT` | A checked Git ref deletion observed an unexpected target | Semantic ref adapters and checked acquisition cleanup |
3066
3318
  | `RETENTION_WITNESS_INVALID` | Witness policy, reachability, root evidence, generation, or timestamp is invalid | `RetentionWitness` |
3067
3319
  | `PUBLICATION_INVALID` | Publication message, parent list, expected head, dependency, or clock input is invalid | `publications.commit()` |
3068
3320
  | `PUBLICATION_REF_FORBIDDEN` | Target ref is invalid, reserved, or outside configured application namespaces | `publications.commit()` |
@@ -3079,6 +3331,16 @@ new CasError({ message, code, meta, documentationUrl });
3079
3331
  | `ROOT_SET_METADATA_INVALID` | `.rootset.json` is malformed, non-canonical, or belongs to another ref | `read()`, `list()`, `doctor()` |
3080
3332
  | `ROOT_SET_TREE_INVALID` | Metadata and the Git tree's actual reachability edges disagree | `read()`, `list()`, `doctor()` |
3081
3333
  | `ROOT_SET_REF_UPDATE_FAILED` | Root-set ref update failed for a non-conflict reason | Root-set mutations and repair |
3334
+ | `WORKSPACE_REF_INVALID` | Workspace ref namespace, identity, epoch, or canonical encoding is invalid | Workspace creation, inspection, and cleanup |
3335
+ | `WORKSPACE_DESCRIPTOR_INVALID` | Workspace lease descriptor is malformed, non-canonical, inconsistent, or outside bounds | Workspace renewal, inspection, and cleanup |
3336
+ | `WORKSPACE_STATE_INVALID` | Retained target names, handles, OIDs, types, counts, or byte evidence disagree | Workspace staging, checkpoint, inspection, and doctor |
3337
+ | `WORKSPACE_TTL_INVALID` | Workspace TTL or computed expiry is outside supported bounds | `workspaces.open()`, staging, checkpoint, and renewal |
3338
+ | `WORKSPACE_CONFLICT` | Workspace generation changed during a checked operation | Workspace inspection and sweep |
3339
+ | `WORKSPACE_RELEASED` | A mutating operation targeted an already released workspace | Workspace staging, checkpoint, renewal, and promotion |
3340
+ | `WORKSPACE_RETENTION_FAILED` | A low-level stage succeeded but its handle could not be proven in a workspace generation; metadata carries the staged receipt | Workspace asset, page, and bundle staging |
3341
+ | `WORKSPACE_HANDLE_NOT_RETAINED` | Promotion requested a handle absent from the active workspace generation | `promoteToCache()`, `promoteToPublication()` |
3342
+ | `WORKSPACE_PROMOTION_NOT_RETAINED` | Destination did not return exact anchored retention evidence, so the workspace remains active | `promoteToCache()`, `promoteToPublication()` |
3343
+ | `WORKSPACE_PROMOTION_CLEANUP_PENDING` | Destination retention succeeded but checked workspace release failed | `promoteToCache()`, `promoteToPublication()` |
3082
3344
  | `REPOSITORY_INSPECTION_INVALID` | Repository doctor options, Git output, dependencies, or safe-integer totals are invalid | `cas.diagnostics.doctor()`, repository inspection adapter |
3083
3345
  | `VAULT_ENTRY_NOT_FOUND` | Slug does not exist in vault | `removeFromVault()`, `resolveVaultEntry()` |
3084
3346
  | `VAULT_ENTRY_EXISTS` | Slug already exists (use `force` to overwrite) | `addToVault()` |