@git-stunts/git-cas 7.0.0 → 7.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 (55) hide show
  1. package/ARCHITECTURE.md +15 -0
  2. package/CHANGELOG.md +57 -0
  3. package/README.md +16 -4
  4. package/build-info.json +2 -2
  5. package/docs/API.md +111 -0
  6. package/docs/releases/v7.1.0.md +25 -0
  7. package/docs/releases/v7.2.0.md +15 -0
  8. package/index.d.ts +15 -0
  9. package/index.js +30 -0
  10. package/package.json +5 -3
  11. package/src/domain/errors/Codes.js +1 -0
  12. package/src/domain/errors/ReservationStorageError.js +9 -0
  13. package/src/domain/services/ReservationCustodyObjects.js +171 -0
  14. package/src/domain/services/ReservationCustodyStore.js +149 -0
  15. package/src/domain/services/ReservationIndex.js +241 -0
  16. package/src/domain/services/ReservationIndexNode.js +78 -0
  17. package/src/domain/services/ReservationLedger.js +326 -0
  18. package/src/domain/services/ReservationLedgerStore.js +141 -0
  19. package/src/domain/services/ReservationListing.js +40 -0
  20. package/src/domain/services/ReservationNamespace.d.ts +135 -0
  21. package/src/domain/services/ReservationNamespace.js +51 -0
  22. package/src/domain/services/ReservationNamespaceRegistry.js +89 -0
  23. package/src/domain/services/ReservationRecord.js +166 -0
  24. package/src/domain/services/ReservationScan.js +54 -0
  25. package/src/domain/value-objects/ReservationCursor.d.ts +11 -0
  26. package/src/domain/value-objects/ReservationCursor.js +31 -0
  27. package/src/domain/value-objects/ReservationCustodyDescriptor.js +47 -0
  28. package/src/domain/value-objects/ReservationCustodySnapshot.js +16 -0
  29. package/src/domain/value-objects/ReservationEvidence.js +26 -0
  30. package/src/domain/value-objects/ReservationEvidenceRead.js +22 -0
  31. package/src/domain/value-objects/ReservationEvidenceRoots.js +72 -0
  32. package/src/domain/value-objects/ReservationIndeterminate.js +17 -0
  33. package/src/domain/value-objects/ReservationInspection.js +21 -0
  34. package/src/domain/value-objects/ReservationKey.js +26 -0
  35. package/src/domain/value-objects/ReservationLedgerHeader.js +15 -0
  36. package/src/domain/value-objects/ReservationLedgerRefusal.js +21 -0
  37. package/src/domain/value-objects/ReservationLedgerSnapshot.js +27 -0
  38. package/src/domain/value-objects/ReservationListRequest.js +35 -0
  39. package/src/domain/value-objects/ReservationListUnavailable.js +17 -0
  40. package/src/domain/value-objects/ReservationOpenIndeterminate.js +15 -0
  41. package/src/domain/value-objects/ReservationOpenRefusal.js +14 -0
  42. package/src/domain/value-objects/ReservationPage.js +27 -0
  43. package/src/domain/value-objects/ReservationPolicy.js +24 -0
  44. package/src/domain/value-objects/ReservationRefusal.js +23 -0
  45. package/src/domain/value-objects/ReservationResult.js +27 -0
  46. package/src/domain/value-objects/ReservationSupport.js +22 -0
  47. package/src/infrastructure/adapters/GitRefAdapter.js +7 -0
  48. package/src/infrastructure/codecs/ReservationCustodyCodec.js +54 -0
  49. package/src/infrastructure/codecs/ReservationLedgerCodec.js +48 -0
  50. package/src/infrastructure/codecs/ReservationRecordCodec.js +54 -0
  51. package/src/package-version.js +1 -1
  52. package/src/ports/GitRefPort.js +11 -0
  53. package/src/ports/ReservationCustodyCodecPort.js +14 -0
  54. package/src/ports/ReservationLedgerCodecPort.js +14 -0
  55. package/src/ports/ReservationRecordCodecPort.js +14 -0
package/ARCHITECTURE.md CHANGED
@@ -143,6 +143,8 @@ The public entrypoint is [index.js](./index.js).
143
143
  observability adapters
144
144
  - exposes convenience methods like `storeFile()` and `restoreFile()`
145
145
  - exposes `rootSets.open()` for mutable current-generation Git reachability
146
+ - exposes the v7.1.0 `reservations.open()` hard record-slot authority,
147
+ ordered custody, reconciliation and bounded snapshot inspection
146
148
  - exposes opaque `assets`, `pages`, and `bundles` capability groups
147
149
  - exposes `retention`, `publications`, `caches`, and `expiringSets` for explicit
148
150
  reachability and lifecycle policy
@@ -474,6 +476,19 @@ make objects Git-reachable, but they encode different lifecycle contracts:
474
476
  | ExpiringSet | `refs/cas/expiring/*` | Expiry-only replay protection |
475
477
  | Publication | Caller-allowlisted ref | Application-controlled causal history |
476
478
  | Vault | `refs/cas/vault` | History-preserving named assets |
479
+ | Reservation ledger | `refs/cas/reservations/*` | Fixed policy, charged attempts and terminal tombstones |
480
+ | Reservation custody | `refs/cas/reservation-custody/*` | Original/final evidence retained through real Git edges |
481
+
482
+ The reservation namespace is installed at open, even with zero attempts.
483
+ `ReservationLedger` owns all lifecycle decisions; the facade supplies validated
484
+ evidence and never executes application effects. `ReservationListing` traverses
485
+ one immutable ledger with a bounded index-node budget, independent of admission.
486
+ Its cursor is a position, not a pin: GC may make an older snapshot unavailable.
487
+ Point inspection observes ledger and custody separately; it makes no multi-ref
488
+ snapshot claim. See the [public contract](docs/API.md#durable-reservations)
489
+ and [cycle0063 design](https://github.com/git-stunts/git-cas/blob/4782052214269c72acc95f63191e89897059bb56/docs/design/0063-durable-reservations/durable-reservations.md).
490
+ The capability is published in v7.1.0; [#162](https://github.com/git-stunts/git-cas/issues/162)
491
+ retains release and registry-consumer evidence.
477
492
 
478
493
  High-level retention, CacheSet, cache acquisition, ExpiringSet, and application
479
494
  publication operations return generation-scoped retention evidence. Replacing
package/CHANGELOG.md CHANGED
@@ -7,6 +7,63 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [7.2.0] — 2026-11-06
11
+
12
+ ### Changed
13
+
14
+ - The reservation index is now a path-compressed trie (#167). A record sits at
15
+ the shortest route prefix no other record shares, so a ledger update writes
16
+ one record blob and about log16(records) trees instead of 64. A 7.1.0 index
17
+ still reads and updates without migration. git-cas 7.1.0 refuses an index
18
+ written by this version as corrupt on read, list and recovery, so every
19
+ process that reads or writes a clone's reservation ledger must upgrade
20
+ together.
21
+
22
+ ## [7.1.0] — 2026-11-02
23
+
24
+ ### Added
25
+
26
+ - Add the `cas.reservations.open()` capability with durable record-slot
27
+ policy, lifecycle operations, exact original/final page retrieval and bounded
28
+ snapshot listing. Reconciliation finishes installed storage phases or cleans
29
+ cancelled residue; it never arms or executes an application effect. Cursors
30
+ bind namespace, snapshot and phase filter; unavailable snapshots do not
31
+ silently restart. Native fault/race/GC and finite cost/residency witnesses
32
+ accompany the implementation. Record-slot limits are not physical-byte
33
+ quotas, and CAS never executes or retries application effects.
34
+
35
+ ### Internal
36
+
37
+ - Define the durable retention reservation protocol for #157. The private
38
+ transition core and its tests were the first implementation checkpoint.
39
+ - Add the private reservation point index and canonical record codec. Lookups
40
+ and updates follow one bounded 64-digit path; corrupt tree names cannot
41
+ masquerade as absent attempts. Native SHA-1/SHA-256 fixtures verify tree
42
+ persistence through reopen and GC under explicit harness roots.
43
+ - Add private durable record-slot admission: immutable namespace policy and
44
+ charged count publish with the attempt index through one checked parentless
45
+ ledger ref. Exact retries recover at capacity; response loss stays uncertain
46
+ unless the same attempt is observed installed. Add exact direct/symbolic ref
47
+ inspection to the ref port and native adapter. Separate native processes
48
+ verify capacity-one contention, exact retries, lost acknowledgements and
49
+ reopen/GC in both object formats.
50
+ - Add private ordered evidence custody and lifecycle publication. Preparation
51
+ pins actual page/support/history edges before its ledger acknowledgement;
52
+ settlement retains preparation as a commit parent. Only a freshly
53
+ acknowledged armed transition permits an external effect. Cancellation
54
+ first publishes its terminal tombstone and refund, then deletes its exact
55
+ pin; failed cleanup leaves retryable residue. Recovery verifies required
56
+ custody rather than trusting an armed record alone. Native races, GC and
57
+ before/after faults at every durable ref boundary cover both object formats.
58
+ The public facade now composes this protocol without a second lifecycle.
59
+
60
+ ### Fixed
61
+
62
+ - Install the Deno CI image from the existing frozen pnpm dependency graph and
63
+ run Deno in manual `node_modules` mode across CI and release verification.
64
+ Fresh Deno resolution no longer selects
65
+ unrelated newer transitive releases before the runtime tests can start (#159).
66
+
10
67
  ## [7.0.0] — 2026-11-01
11
68
 
12
69
  ### Breaking Changes
package/README.md CHANGED
@@ -52,11 +52,23 @@ Unlike traditional LFS which moves files to external servers, `git-cas` treats t
52
52
 
53
53
  Existing v5 users should read [UPGRADING.md](./UPGRADING.md) and run
54
54
  `npm run upgrade` in dry-run mode before restoring old encrypted vault entries.
55
- The v7.0.0 security candidate changes the public schema dependency to Zod 4.
55
+ The published v7.0.0 release changes the public schema dependency to Zod 4.
56
56
  Before upgrading, read the [migration guidance](./UPGRADING.md#v6512-to-v700-candidate)
57
- and [candidate release notes](./docs/releases/v7.0.0.md). This candidate requires
58
- published Plumbing 3.3.3. Publication and registry verification remain tracked in
59
- [#154](https://github.com/git-stunts/git-cas/issues/154).
57
+ and [release notes](./docs/releases/v7.0.0.md). This release requires
58
+ published Plumbing 3.3.3. [Release and registry evidence](https://github.com/git-stunts/git-cas/issues/154)
59
+ records its publication.
60
+
61
+ Published v7.1.0 adds [durable reservations](./docs/API.md#durable-reservations):
62
+ hard record-slot admission before an application effect, pinned evidence and
63
+ bounded recovery/inspection. See the [release notes](./docs/releases/v7.1.0.md)
64
+ and [publication and fresh registry-consumer evidence](https://github.com/git-stunts/git-cas/issues/162).
65
+ The signed tag, npm gitHead and successful release workflow agree on `18f87dd`.
66
+
67
+ The v7.2.0 release candidate path-compresses the reservation index, so a ledger
68
+ update writes about log16(records) trees instead of 64. A 7.1.0 index still
69
+ reads and updates, but 7.1.0 refuses an index 7.2.0 has written; see the
70
+ [release notes](./docs/releases/v7.2.0.md) and
71
+ [#169](https://github.com/git-stunts/git-cas/issues/169).
60
72
 
61
73
  The published v6.5.12 release bounds object-metadata requests so root sets with more than 1000 targets (936 for SHA-256) validate within Plumbing's cat-file request limits. Admission still rejects missing and mismatched targets before publication; see [v6.5.12 Release Notes](./docs/releases/v6.5.12.md).
62
74
 
package/build-info.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "sha": "ae3a81c",
3
- "timestamp": "2026-11-01T23:22:13.038Z"
2
+ "sha": "3008b4a",
3
+ "timestamp": "2026-11-06T16:16:00.271Z"
4
4
  }
package/docs/API.md CHANGED
@@ -3645,3 +3645,114 @@ Different error codes include different metadata:
3645
3645
  originalError: <Error>
3646
3646
  }
3647
3647
  ```
3648
+
3649
+
3650
+ ## Durable Reservations
3651
+
3652
+ This API is available in published v7.1.0 and is absent from v7.0.0.
3653
+ [Issue #162](https://github.com/git-stunts/git-cas/issues/162) retains publication
3654
+ and fresh registry-consumer verification.
3655
+
3656
+ `cas.reservations.open({ namespace, capacity: { unit: 'record-slot', limit } })`
3657
+ installs or verifies an immutable namespace policy, including an empty ledger
3658
+ before the first attempt. The limit is a positive safe integer. Record slots
3659
+ are logical permanent-record capacity, not physical-byte quotas. Open returns:
3660
+
3661
+ - `opened`: a frozen `ReservationNamespace` with operations below, `policy` and
3662
+ `openedRevision` (the ledger observed by open).
3663
+ - `refused`: `policy-mismatch` or `contention`, plus the requested policy.
3664
+ - `indeterminate`: the requested policy and an `Error` cause. Retry the same
3665
+ namespace/policy; do not treat an unavailable observation as absence.
3666
+
3667
+ Each attempt uses `{ key, binding }`: a printable ASCII key of 1–128 bytes and a
3668
+ canonical lowercase SHA-256 request binding. The application computes and owns
3669
+ that binding's meaning. Exact-key retries recover the same attempt; different
3670
+ bindings refuse. Cancelled keys remain terminal tombstones.
3671
+
3672
+ | Method | Meaning |
3673
+ | --- | --- |
3674
+ | `reserve(identity)` | Atomically charge one slot, or recover the exact existing attempt |
3675
+ | `prepare({ ...identity, evidence })` | Pin original evidence, then acknowledge preparation |
3676
+ | `arm(identity)` | Verify preparation and compete for the one fresh effect permission |
3677
+ | `settle({ ...identity, evidence })` | Pin final evidence while retaining the original, then acknowledge settlement |
3678
+ | `cancel(identity)` | Cancel only an unarmed/unsettled attempt; publish refund before exact pin cleanup |
3679
+ | `reconcile(identity)` | Complete supported storage transitions or cancelled cleanup without application execution |
3680
+ | `inspect(identity)` | Observe ledger metadata and current custody separately |
3681
+ | `readEvidence({ ...identity, stage })` | Read acknowledged `preparation` or `settlement` page/support metadata |
3682
+ | `list({ cursor, phase, limit, nodeBudget })` | Traverse ledger claims at one immutable snapshot |
3683
+
3684
+ Lifecycle outcomes have `status`, a validated `record` and the ledger `revision`.
3685
+ Success statuses are `admitted`, `prepared`, fresh `armed`, `settled`, `cancelled`
3686
+ or `recovered`. Expected failures are `refused` values with the attempted key,
3687
+ binding and finite reason. Operational uncertainty is `indeterminate`, with the
3688
+ same identity and its retained `Error` cause. Invalid inputs throw typed CAS
3689
+ errors. A recovered armed record is not a new `armed` acknowledgement.
3690
+
3691
+ ```javascript
3692
+ const opened = await cas.reservations.open({
3693
+ namespace: 'application/observations',
3694
+ capacity: { unit: 'record-slot', limit: 1000 },
3695
+ });
3696
+
3697
+ if (opened.status === 'opened') {
3698
+ // attempt is the application's stable { key, binding } for this operation.
3699
+ const admission = await opened.reserve(attempt);
3700
+ if (admission.status === 'admitted' || admission.status === 'recovered') {
3701
+ const prepared = await opened.prepare({ ...attempt, evidence: originalEvidence });
3702
+ if (prepared.status === 'prepared' || prepared.status === 'recovered') {
3703
+ const permission = await opened.arm(attempt);
3704
+ if (permission.status === 'armed') {
3705
+ // Only this branch may perform the application's irreversible effect.
3706
+ // The application records its own effect outcome and calls settle.
3707
+ }
3708
+ }
3709
+ }
3710
+ }
3711
+ ```
3712
+
3713
+ The snippet names caller-supplied `attempt` and `originalEvidence`; CAS never
3714
+ executes the application operation. A lost arming response can leave an armed
3715
+ charge even if the effect never ran. Retry/inspection returns already-armed or
3716
+ recovered evidence, never a second permission. Time, process death and local
3717
+ resource closure do not release that charge. A prepared read may settle
3718
+ without arming; its settlement competes with cancellation.
3719
+
3720
+ `evidence` contains `record: Uint8Array`, optional `supports: [{ type, oid }]`
3721
+ for blob/tree targets, and optional `parents: [commitOid]`. The page is copied
3722
+ and limited to 16 MiB; there are at most 64 supports and 63 external parents.
3723
+ All OIDs must be canonical and refer to the declared object types. The final
3724
+ custody commit also retains preparation as its first parent. These are storage
3725
+ boundary inputs; CAS does not validate application receipt semantics or walk
3726
+ every descendant of a support tree.
3727
+
3728
+ `readEvidence` returns `read` with the attempt, ledger/custody revisions, stage
3729
+ and an `evidence` value. Its `record` getter returns a new byte copy each time;
3730
+ `roots` describes the supports and external parents. An unacknowledged phase
3731
+ returns `not-prepared`/`not-settled`; cancelled attempts refuse. Missing required
3732
+ custody is indeterminate. Reading preparation does not create a new retention
3733
+ promise if another caller cancels concurrently.
3734
+
3735
+ `inspect` returns `inspected`, the ledger record/revision, policy, charged count
3736
+ and `custody` (a validated generation or null). It does not load page bytes.
3737
+ Ledger and pin are sequential observations, not an atomic multi-ref snapshot.
3738
+ A cancelled record may still have pin residue. `reconcile` can remove that
3739
+ residue without a second refund, or finish a valid installed preparation/final
3740
+ pin's ledger transition. It never arms, replaces evidence, releases an armed
3741
+ charge or decides what happened in an external application.
3742
+
3743
+ Listing returns `page` with snapshot policy/count/revision, frozen `records`,
3744
+ `visitedNodes` and `next`. The limit is 1–100 records (default 100); the budget
3745
+ is 129–8192 index objects (default 1024). Every traversed tree or record, including
3746
+ cursor seeking, spends this budget. Ledger/header validation is fixed extra
3747
+ bounded work. The traversal stack is at most 64 bounded nodes, with at most 100
3748
+ output records. A phase filter can produce an empty page with a continuation;
3749
+ there is no hidden scan to fill it.
3750
+
3751
+ A cursor binds namespace, ledger revision, last visited route and phase filter.
3752
+ Its fields can be serialized and supplied to another process. It is a position,
3753
+ not an authorization token or retention pin. Concurrent writes do not change
3754
+ its snapshot. If GC removes the snapshot, listing returns `unavailable` with
3755
+ that cursor and the cause, without partial records or a silent restart. Start a
3756
+ new listing explicitly when a fresh snapshot is appropriate. Listing verifies
3757
+ ledger claims along visited paths; use point inspection for live custody.
3758
+ Unvisited subtrees are not audited, and metadata/tombstones can grow with work.
@@ -0,0 +1,25 @@
1
+ # git-cas v7.1.0: durable reservation admission
2
+
3
+ This release adds `cas.reservations.open()` for applications that must reserve permanent record capacity before an irreversible effect. The implementation merged in [PR #158](https://github.com/git-stunts/git-cas/pull/158). [Issue #162](https://github.com/git-stunts/git-cas/issues/162) records the completed release gates, publication and fresh public-registry consumer verification. Signed tag `v7.1.0`, npm gitHead and the successful [release workflow](https://github.com/git-stunts/git-cas/actions/runs/41483019826) identify source `18f87ddb08857209d9e2e6ff30337515c0eaee4d`. The [GitHub Release](https://github.com/git-stunts/git-cas/releases/tag/v7.1.0) is published.
4
+
5
+ ## Contract
6
+
7
+ A namespace has an immutable, positive safe-integer record-slot limit. `reserve()` charges one slot for an exact key and request binding. An identical retry recovers that attempt even at capacity; a different binding refuses. `prepare()` pins original evidence before acknowledging preparation. Only a freshly acknowledged `arm()` transition permits the application to execute its effect. Recovery of an armed attempt never issues a second permit.
8
+
9
+ `settle()` pins final evidence while retaining the original preparation. `cancel()` refunds only an unarmed, unsettled attempt, first recording its terminal tombstone and then removing its exact custody pin. Failed cleanup remains retryable residue. `reconcile()` repairs installed storage phases without executing or replaying application effects. `readEvidence()` returns exact original or final pages; bounded listing binds its cursor to one immutable ledger snapshot and phase filter.
10
+
11
+ Record-slot capacity is not a physical-byte quota. Evidence pages are at most 16 MiB, with at most 64 blob/tree support roots and 63 caller-supplied commit parents. Listing returns at most 100 records and visits at most 8,192 index nodes per call. A cursor is not a retention pin; GC can make an old listing snapshot unavailable. No cross-ref atomic snapshot, TTL reclamation, application authorization or physical power-loss guarantee is supplied.
12
+
13
+ ## Compatibility
14
+
15
+ The API is additive to v7.0.0. Existing assets, caches, encryption, handles and refs keep their contracts. New reservation namespaces use `refs/cas/reservations/*` and `refs/cas/reservation-custody/*`. New content manifests carry producing-package `formatVersion: "7.1.0"`; this remains separate from the manifest schema version. Zod 4 and published Plumbing `^3.3.3` remain required.
16
+
17
+ Deno CI and release commands now install the frozen pnpm project graph and execute with `--node-modules-dir=manual`. This removes fresh Deno transitive resolution from those paths without changing dependency ranges. The separate unlocked Bun image-install follow-up remains [#161](https://github.com/git-stunts/git-cas/issues/161).
18
+
19
+ ## Evidence and limits
20
+
21
+ The [implementation witnesses](https://github.com/git-stunts/git-cas/blob/4782052214269c72acc95f63191e89897059bb56/docs/design/0063-durable-reservations/witness/README.md) separate state-machine tests, selected corruption, native multi-process races, injected write-boundary failures, process death, reopen and real Git GC in SHA-1 and SHA-256 stores. The [finite cost witness](https://github.com/git-stunts/git-cas/blob/4782052214269c72acc95f63191e89897059bb56/docs/design/0063-durable-reservations/witness/native-cost.md) measures stores of 1, 17 and 129 attempts using 4 KiB pages. It does not claim universal constant memory or performance parity across runtimes.
22
+
23
+ PR #158's current-head hosted lint, unit and Node/Bun/Deno jobs passed. The maintainer explicitly authorized an admin merge after reviewer quota and file-count limits prevented independent approval. The [cycle retrospective](https://github.com/git-stunts/git-cas/blob/d50c77238e8b956fb70c2d51d2dcf9663c09c789/docs/method/retro/0063-durable-reservations/durable-reservations.md) preserves that distinction. All 14 release steps passed on merged main across separate runtime phases, with 8,265 passing test observations and 18 existing runtime-specific skips. The earlier combined-worker Deno failure remains recorded; fresh isolated Deno verification and the tagged release workflow passed. A fresh npm consumer verified lifecycle, refusal, original/final evidence, close/reopen and real Git GC in SHA-1 and SHA-256 stores. #162 retains both candidate and published artifact identities; they are separate builds.
24
+
25
+ git-warp must install this published artifact before claiming adoption. WARP authorization, observation receipts, Coordinates and shared custody integration remain outside this storage release.
@@ -0,0 +1,15 @@
1
+ # git-cas v7.2.0: path-compressed reservation index
2
+
3
+ This release candidate makes each reservation ledger update write about log16(records) index trees instead of 64. The change merged in [PR #168](https://github.com/git-stunts/git-cas/pull/168) for [#167](https://github.com/git-stunts/git-cas/issues/167). [Issue #169](https://github.com/git-stunts/git-cas/issues/169) tracks release verification and publication. This document claims no published 7.2.0 artifact.
4
+
5
+ ## Change
6
+
7
+ The reservation index was a 16-way trie with one tree per hex digit of a key's 64-digit route, so every record sat 64 trees deep and every update rewrote all 64. A record now sits at the shortest route prefix no other record shares. Inserting a key that meets another key's record pushes both down to the first digit where their routes differ. Sixty-four levels remain the worst case, so the documented listing and node bounds are unchanged.
8
+
9
+ Measured in a native repository after 400 prior records, one `reserve` wrote 68 objects under 7.1.0 and writes 7 under this release, in both SHA-1 and SHA-256 stores (`test/integration/reservation-index-cost.test.js`).
10
+
11
+ ## Compatibility
12
+
13
+ The public API is unchanged. An index written by 7.1.0 places every record at full depth, which is a valid uncompressed trie: it reads, updates and lists without migration, and new keys branch off early.
14
+
15
+ git-cas 7.1.0 refuses an index written by this release as `RESERVATION_CORRUPT` on read, list and recovery. The failure is loud rather than silent, but every process that reads or writes a clone's reservation ledger must upgrade together, and downgrading after 7.2.0 has written a ledger is not supported.
package/index.d.ts CHANGED
@@ -16,6 +16,17 @@ import type {
16
16
  import Chunk from './src/domain/value-objects/Chunk.js';
17
17
  import CasService from './src/domain/services/CasService.js';
18
18
  import CasError from './src/domain/errors/CasError.js';
19
+ import type { ReservationCapability } from './src/domain/services/ReservationNamespace.js';
20
+ export { default as ReservationNamespace } from './src/domain/services/ReservationNamespace.js';
21
+ export { default as ReservationCursor } from './src/domain/value-objects/ReservationCursor.js';
22
+ export type {
23
+ ReservationPhase, ReservationIdentity, ReservationCapacity, ReservationPolicy,
24
+ ReservationRecordView, ReservationEvidenceInput, ReservationRoots, ReservationCustodyView,
25
+ ReservationRefusalReason, ReservationRefused, ReservationIndeterminate, ReservationAcknowledgement, ReservationAcknowledgedStatus,
26
+ ReservationOutcome, ReservationInspection, ReservationEvidenceRead, ReservationCursorData,
27
+ ReservationListOptions, ReservationPage, ReservationListUnavailable, ReservationOpenRefusal,
28
+ ReservationOpenIndeterminate, ReservationOpenOutcome, ReservationCapability,
29
+ } from './src/domain/services/ReservationNamespace.js';
19
30
  import type {
20
31
  CryptoPort,
21
32
  CodecPort,
@@ -543,6 +554,8 @@ export declare class GitPersistencePortBase {
543
554
 
544
555
  /** Abstract port for Git ref and commit operations. */
545
556
  export declare class GitRefPortBase {
557
+ /** Exact direct/symbolic posture; a dangling symbolic ref is not absent. */
558
+ inspectRef?(ref: string): Promise<{ oid: string | null; symref: string | null }>;
546
559
  resolveRef(ref: string): Promise<string>;
547
560
  resolveTree(commitOid: string): Promise<string>;
548
561
  resolveParents(commitOid: string): Promise<string[]>;
@@ -600,6 +613,7 @@ export declare class GitPersistenceAdapter extends GitPersistencePortBase {
600
613
  /** Git-backed implementation of the ref port. */
601
614
  export declare class GitRefAdapter extends GitRefPortBase {
602
615
  constructor(options: { plumbing: unknown; policy?: unknown });
616
+ inspectRef(ref: string): Promise<{ oid: string | null; symref: string | null }>;
603
617
  anchorRef(options: {
604
618
  sourceRef: string;
605
619
  expectedSourceOid: string;
@@ -1804,6 +1818,7 @@ export default class ContentAddressableStore {
1804
1818
  };
1805
1819
 
1806
1820
  readonly caches: CacheCapability;
1821
+ readonly reservations: ReservationCapability;
1807
1822
  readonly expiringSets: ExpiringSetCapability;
1808
1823
  readonly workspaces: WorkspaceCapability;
1809
1824
  readonly diagnostics: DiagnosticsCapability;
package/index.js CHANGED
@@ -10,6 +10,12 @@ import CasService from './src/domain/services/CasService.js';
10
10
  import VaultService from './src/domain/services/VaultService.js';
11
11
  import RootSet from './src/domain/services/RootSet.js';
12
12
  import RootSetRegistry from './src/domain/services/RootSetRegistry.js';
13
+ import ReservationNamespaceRegistry from './src/domain/services/ReservationNamespaceRegistry.js';
14
+ import ReservationIndex from './src/domain/services/ReservationIndex.js';
15
+ import ReservationLedgerStore from './src/domain/services/ReservationLedgerStore.js';
16
+ import ReservationRecordCodec from './src/infrastructure/codecs/ReservationRecordCodec.js';
17
+ import ReservationLedgerCodec from './src/infrastructure/codecs/ReservationLedgerCodec.js';
18
+ import ReservationCustodyCodec from './src/infrastructure/codecs/ReservationCustodyCodec.js';
13
19
  import AssetService from './src/domain/services/AssetService.js';
14
20
  import BundleService from './src/domain/services/BundleService.js';
15
21
  import CacheSet from './src/domain/services/CacheSet.js';
@@ -100,6 +106,8 @@ export { default as StagedPage } from './src/domain/value-objects/StagedPage.js'
100
106
  export { default as RetentionWitness } from './src/domain/value-objects/RetentionWitness.js';
101
107
  export { default as CacheHit } from './src/domain/value-objects/CacheHit.js';
102
108
  export { default as CachePolicy } from './src/domain/value-objects/CachePolicy.js';
109
+ export { default as ReservationNamespace } from './src/domain/services/ReservationNamespace.js';
110
+ export { default as ReservationCursor } from './src/domain/value-objects/ReservationCursor.js';
103
111
  export { default as ExpiringMarker } from './src/domain/value-objects/ExpiringMarker.js';
104
112
  export { default as EventEmitterObserver } from './src/infrastructure/adapters/EventEmitterObserver.js';
105
113
  export { default as StatsCollector } from './src/infrastructure/adapters/StatsCollector.js';
@@ -195,6 +203,14 @@ export default class ContentAddressableStore {
195
203
  }
196
204
 
197
205
  #installCapabilities() {
206
+ this.#installCollectionCapabilities();
207
+ this.#installApplicationCapabilities();
208
+ }
209
+
210
+ #installCollectionCapabilities() {
211
+ this.reservations = Object.freeze({
212
+ open: async (options) => (await this.#getReservationRegistry()).open(options),
213
+ });
198
214
  this.rootSets = Object.freeze({
199
215
  open: async (options) => (await this.#getRootSetRegistry()).open(options),
200
216
  });
@@ -212,6 +228,9 @@ export default class ContentAddressableStore {
212
228
  this.diagnostics = Object.freeze({
213
229
  doctor: async (options) => (await this.#getRepositoryDoctor()).doctor(options),
214
230
  });
231
+ }
232
+
233
+ #installApplicationCapabilities() {
215
234
  this.assets = Object.freeze({
216
235
  put: async (options) => (await this.#getAssetService()).put(options),
217
236
  putBatch: async (options) => (await this.#getAssetService()).putBatch(options),
@@ -260,6 +279,7 @@ export default class ContentAddressableStore {
260
279
  #vault = null;
261
280
  /** @type {RootSetRegistry|null} */
262
281
  #rootSetRegistry = null;
282
+ #reservationRegistry = null;
263
283
  /** @type {CacheSetRegistry|null} */
264
284
  #cacheSetRegistry = null;
265
285
  /** @type {ExpiringSetRegistry|null} */
@@ -436,6 +456,16 @@ export default class ContentAddressableStore {
436
456
  return this.#rootSetRegistry;
437
457
  }
438
458
 
459
+ async #getReservationRegistry() {
460
+ const { persistence, crypto } = await this.#getService();
461
+ this.#reservationRegistry ??= new ReservationNamespaceRegistry({
462
+ persistence, refs: this.#ref, crypto, custodyCodec: new ReservationCustodyCodec(),
463
+ index: new ReservationIndex({ persistence, crypto, codec: new ReservationRecordCodec() }),
464
+ store: new ReservationLedgerStore({ persistence, refs: this.#ref, codec: new ReservationLedgerCodec() }),
465
+ });
466
+ return this.#reservationRegistry;
467
+ }
468
+
439
469
  /** @returns {Promise<CacheSetRegistry>} */
440
470
  async #getCacheSetRegistry() {
441
471
  await this.#getService();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@git-stunts/git-cas",
3
- "version": "7.0.0",
3
+ "version": "7.2.0",
4
4
  "description": "Content-addressed storage backed by Git's object database, with optional encryption and pluggable codecs",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -58,7 +58,9 @@
58
58
  "CHANGELOG.md",
59
59
  "docs/releases/v6.5.11.md",
60
60
  "docs/releases/v6.5.12.md",
61
- "docs/releases/v7.0.0.md"
61
+ "docs/releases/v7.0.0.md",
62
+ "docs/releases/v7.1.0.md",
63
+ "docs/releases/v7.2.0.md"
62
64
  ],
63
65
  "engines": {
64
66
  "node": ">=22.0.0"
@@ -97,7 +99,7 @@
97
99
  "test:integration": "docker compose run --build --rm test-node pnpm vitest run test/integration --no-file-parallelism",
98
100
  "test:integration:node": "docker compose run --build --rm test-node npx vitest run test/integration --no-file-parallelism",
99
101
  "test:integration:bun": "docker compose run --build --rm test-bun bunx vitest run test/integration --no-file-parallelism",
100
- "test:integration:deno": "docker compose run --build --rm test-deno deno run -A npm:vitest run test/integration --no-file-parallelism",
102
+ "test:integration:deno": "docker compose run --build --rm test-deno deno run --node-modules-dir=manual -A npm:vitest run test/integration --no-file-parallelism",
101
103
  "test:platforms": "docker compose run --build --rm test-node && docker compose run --build --rm test-bun && docker compose run --build --rm test-deno",
102
104
  "benchmark": "docker compose run --build --rm test-node pnpm vitest bench test/benchmark",
103
105
  "benchmark:local": "vitest bench test/benchmark",
@@ -67,6 +67,7 @@ const ErrorCodes = Object.freeze({
67
67
  RECIPIENT_NOT_FOUND: 'RECIPIENT_NOT_FOUND',
68
68
  REPOSITORY_INSPECTION_INVALID: 'REPOSITORY_INSPECTION_INVALID',
69
69
  RESOURCE_CLOSED: 'RESOURCE_CLOSED',
70
+ RESERVATION_CORRUPT: 'RESERVATION_CORRUPT',
70
71
  RESTORE_TOO_LARGE: 'RESTORE_TOO_LARGE',
71
72
  RETENTION_WITNESS_INVALID: 'RETENTION_WITNESS_INVALID',
72
73
  ROOT_SET_CONFLICT: 'ROOT_SET_CONFLICT',
@@ -0,0 +1,9 @@
1
+ import CasError from './CasError.js';
2
+ import { ErrorCodes } from './Codes.js';
3
+
4
+ /** Invalid reservation storage evidence; never a known absence or a refund. */
5
+ export default class ReservationStorageError extends CasError {
6
+ constructor(message, meta = {}) {
7
+ super(message, ErrorCodes.RESERVATION_CORRUPT, meta);
8
+ }
9
+ }
@@ -0,0 +1,171 @@
1
+ import GitPersistencePort from '../../ports/GitPersistencePort.js';
2
+ import GitRefPort from '../../ports/GitRefPort.js';
3
+ import ReservationCustodyCodecPort, { RESERVATION_CUSTODY_MAX_BYTES } from '../../ports/ReservationCustodyCodecPort.js';
4
+ import ReservationEvidence, { RESERVATION_PAGE_MAX_BYTES } from '../value-objects/ReservationEvidence.js';
5
+ import ReservationCustodyDescriptor from '../value-objects/ReservationCustodyDescriptor.js';
6
+ import ReservationCustodySnapshot from '../value-objects/ReservationCustodySnapshot.js';
7
+ import ReservationRecord from './ReservationRecord.js';
8
+ import CollectionNamespace from '../value-objects/CollectionNamespace.js';
9
+ import Oid from '../value-objects/Oid.js';
10
+ import InvalidOptionsError from '../errors/InvalidOptionsError.js';
11
+ import ReservationStorageError from '../errors/ReservationStorageError.js';
12
+
13
+ const COMMIT_MAX_BYTES = 16 * 1024;
14
+ const ROOT_MAX_BYTES = 2 * 1024;
15
+ const SUPPORT_TREE_MAX_BYTES = 8 * 1024;
16
+
17
+ /** Bounded immutable custody objects. This class never creates or deletes refs. */
18
+ export default class ReservationCustodyObjects {
19
+ #persistence;
20
+ #refs;
21
+ #codec;
22
+
23
+ constructor({ namespace, persistence, refs, codec }) {
24
+ if (!(persistence instanceof GitPersistencePort) || !(refs instanceof GitRefPort) ||
25
+ !(codec instanceof ReservationCustodyCodecPort)) {
26
+ throw new InvalidOptionsError('Custody objects require persistence, ref and descriptor codec ports');
27
+ }
28
+ this.namespace = CollectionNamespace.from(namespace).toString();
29
+ this.#persistence = persistence;
30
+ this.#refs = refs;
31
+ this.#codec = codec;
32
+ Object.freeze(this);
33
+ }
34
+
35
+ async describe({ attempt, evidence, preparation = null }) {
36
+ if (!(attempt instanceof ReservationRecord) || !(evidence instanceof ReservationEvidence)) {
37
+ throw new InvalidOptionsError('Custody description requires an attempt and validated evidence');
38
+ }
39
+ await this.#assertRoots(evidence.roots);
40
+ const recordOid = await this.#persistence.writeBlob(evidence.record);
41
+ return new ReservationCustodyDescriptor({
42
+ namespace: this.namespace, key: attempt.key, binding: attempt.binding,
43
+ stage: preparation === null ? 'preparation' : 'settlement', preparation,
44
+ recordOid, roots: evidence.roots,
45
+ });
46
+ }
47
+
48
+ async write(descriptor) {
49
+ this.#assertDescriptor(descriptor);
50
+ await this.#assertPayload(descriptor);
51
+ const bytes = this.#codec.encode(descriptor);
52
+ if (!(bytes instanceof Uint8Array) || bytes.length > RESERVATION_CUSTODY_MAX_BYTES) {
53
+ throw new ReservationStorageError('Encoded custody descriptor exceeds its bound');
54
+ }
55
+ const metadata = await this.#persistence.writeBlob(bytes);
56
+ const support = await this.#persistence.writeTree(descriptor.roots.toTreeLines());
57
+ const treeOid = await this.#persistence.writeTree([
58
+ `100644 blob ${metadata}\tdescriptor`, `100644 blob ${descriptor.recordOid}\trecord`, `040000 tree ${support}\tsupport`,
59
+ ]);
60
+ for (const oid of [metadata, support, treeOid]) {
61
+ assertSameFormat(oid, descriptor.recordOid);
62
+ }
63
+ const revision = await this.#refs.createCommit({
64
+ treeOid, parentOids: descriptor.parents, message: `git-cas reservation ${descriptor.stage} v1`,
65
+ });
66
+ return new ReservationCustodySnapshot({ descriptor, revision });
67
+ }
68
+
69
+ async read(revision) {
70
+ await this.#assertObject(revision, { type: 'commit', maxBytes: COMMIT_MAX_BYTES });
71
+ const root = await this.#refs.resolveTree(revision);
72
+ assertSameFormat(root, revision);
73
+ await this.#assertObject(root, { type: 'tree', maxBytes: ROOT_MAX_BYTES });
74
+ const entries = await this.#persistence.readTree(root);
75
+ const { metadata, record, support } = rootEntries(entries, revision);
76
+ await this.#assertObject(metadata, { type: 'blob', maxBytes: RESERVATION_CUSTODY_MAX_BYTES });
77
+ const descriptor = this.#codec.decode(await this.#persistence.readBlob(metadata, RESERVATION_CUSTODY_MAX_BYTES));
78
+ this.#assertDescriptor(descriptor);
79
+ if (descriptor.recordOid !== record) {
80
+ throw new ReservationStorageError('Custody record edge disagrees with its descriptor');
81
+ }
82
+ const parents = await this.#refs.resolveParents(revision);
83
+ assertParents(parents, descriptor.parents);
84
+ await this.#assertObject(support, { type: 'tree', maxBytes: SUPPORT_TREE_MAX_BYTES });
85
+ descriptor.roots.assertTree(await this.#persistence.readTree(support));
86
+ await this.#assertPayload(descriptor);
87
+ return new ReservationCustodySnapshot({ descriptor, revision });
88
+ }
89
+
90
+ async readEvidence(revision) {
91
+ const { descriptor } = await this.read(revision);
92
+ return new ReservationEvidence({
93
+ record: await this.#persistence.readBlob(descriptor.recordOid, RESERVATION_PAGE_MAX_BYTES),
94
+ supports: descriptor.roots.supports, parents: descriptor.roots.parents,
95
+ });
96
+ }
97
+
98
+ #assertDescriptor(descriptor) {
99
+ if (!(descriptor instanceof ReservationCustodyDescriptor) || descriptor.namespace !== this.namespace) {
100
+ throw new ReservationStorageError('Custody descriptor does not belong to this namespace');
101
+ }
102
+ }
103
+
104
+ async #assertPayload(descriptor) {
105
+ await this.#assertObject(descriptor.recordOid, { type: 'blob', maxBytes: RESERVATION_PAGE_MAX_BYTES });
106
+ await this.#assertRoots(descriptor.roots);
107
+ if (descriptor.preparation !== null) {
108
+ await this.#assertObject(descriptor.preparation, { type: 'commit', maxBytes: COMMIT_MAX_BYTES });
109
+ }
110
+ }
111
+
112
+ async #assertRoots(roots) {
113
+ for (const item of roots.supports) {
114
+ await this.#assertObject(item.oid, { type: item.type, maxBytes: Number.MAX_SAFE_INTEGER });
115
+ }
116
+ for (const parent of roots.parents) {
117
+ await this.#assertObject(parent, { type: 'commit', maxBytes: Number.MAX_SAFE_INTEGER });
118
+ }
119
+ }
120
+
121
+ async #assertObject(oid, { type, maxBytes }) {
122
+ assertOid(oid);
123
+ const [actualType, size] = await Promise.all([
124
+ this.#persistence.readObjectType(oid), this.#persistence.readObjectSize(oid),
125
+ ]);
126
+ if (actualType !== type || !Number.isSafeInteger(size) || size < 0 || size > maxBytes) {
127
+ throw new ReservationStorageError('Custody object type or byte bound is invalid', { oid, type, size });
128
+ }
129
+ }
130
+ }
131
+
132
+ function rootEntries(entries, revision) {
133
+ if (!Array.isArray(entries) || entries.length !== 3) {
134
+ throw new ReservationStorageError('Custody root must have exactly three entries');
135
+ }
136
+ const metadata = rootEntry(entries, { name: 'descriptor', type: 'blob', mode: '100644' });
137
+ const record = rootEntry(entries, { name: 'record', type: 'blob', mode: '100644' });
138
+ const support = rootEntry(entries, { name: 'support', type: 'tree', mode: '040000' });
139
+ for (const oid of [metadata, record, support]) {
140
+ assertSameFormat(oid, revision);
141
+ }
142
+ return { metadata, record, support };
143
+ }
144
+
145
+ function rootEntry(entries, { name, type, mode }) {
146
+ const entry = entries.find((item) => item.name === name);
147
+ if (!entry || entry.type !== type || entry.mode !== mode) {
148
+ throw new ReservationStorageError('Custody root entry is invalid', { name });
149
+ }
150
+ return entry.oid;
151
+ }
152
+
153
+ function assertParents(actual, expected) {
154
+ if (!Array.isArray(actual) || actual.length !== expected.length || actual.some((oid, i) => oid !== expected[i])) {
155
+ throw new ReservationStorageError('Custody commit parents disagree with its descriptor');
156
+ }
157
+ }
158
+
159
+ function assertSameFormat(left, right) {
160
+ assertOid(left);
161
+ assertOid(right);
162
+ if (left.length !== right.length) {
163
+ throw new ReservationStorageError('Custody changed Git object format');
164
+ }
165
+ }
166
+
167
+ function assertOid(value) {
168
+ if (!Oid.isValid(value) || value !== value.toLowerCase()) {
169
+ throw new ReservationStorageError('Custody requires canonical Git OIDs');
170
+ }
171
+ }