@git-stunts/git-cas 6.0.0 → 6.0.1
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/ADVANCED_GUIDE.md +111 -90
- package/CHANGELOG.md +59 -3
- package/GUIDE.md +242 -188
- package/README.md +57 -211
- package/bin/ui/dashboard.js +442 -183
- package/bin/ui/store-wizard.js +90 -19
- package/build-info.json +2 -2
- package/docs/API.md +74 -44
- package/index.d.ts +89 -39
- package/index.js +67 -15
- package/package.json +1 -1
- package/src/domain/services/CasService.d.ts +41 -26
- package/src/domain/services/CasService.js +53 -32
- package/src/domain/services/ChunkRepository.js +50 -12
- package/src/infrastructure/adapters/FileIOHelper.js +33 -31
- package/src/infrastructure/chunkers/resolveChunker.js +7 -5
- package/src/package-version.js +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
>
|
|
5
5
|
> `git-cas` addresses this by making artifact distribution inherit Git’s existing replication model, allowing binaries to be stored, verified, and transported anywhere Git can operate, including mirrored networks, constrained environments, or fully offline contexts.
|
|
6
6
|
|
|
7
|
-
`git-cas`
|
|
7
|
+
`git-cas` is an industrial-grade Content-Addressable Storage (CAS) engine backed by Git’s object database. Its Security First posture makes explicit restore boundaries, bounded metadata reads, authenticated encryption, and legacy-scheme rejection the default. Stored content is chunked, deduplicated, and optionally encrypted — keeping high-fidelity assets and security-sensitive files directly within your repository history.
|
|
8
8
|
|
|
9
9
|
`git-cas` is designed for the architect who demands mathematical certainty and the operator who needs a stable foundation for artifact storage. It scales from simple binary blob management to multi-recipient envelope-encrypted vaults with key rotation, privacy-mode slug hashing, and Merkle-style manifests for assets of any size.
|
|
10
10
|
|
|
@@ -59,216 +59,61 @@ const cas = await ContentAddressableStore.open({ cwd: '.' });
|
|
|
59
59
|
const manifest = await cas.storeFile({ filePath: './asset.bin', slug: 'app/asset' });
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
##
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
Encryption
|
|
82
|
-
`framed` use fresh random 96-bit nonces; `convergent` derives per-chunk keys
|
|
83
|
-
and nonces deterministically from the plaintext content hash to preserve
|
|
84
|
-
deduplication.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
Two manifest versions handle assets of any size:
|
|
118
|
-
|
|
119
|
-
- **Version 1**: A flat manifest blob listing all chunk digests. Suitable for most assets.
|
|
120
|
-
- **Version 2**: A Merkle-style manifest that splits the chunk list into
|
|
121
|
-
sub-manifests, each independently addressable and schema-validated.
|
|
122
|
-
Automatically engaged when chunk count exceeds 1,000 by default, with
|
|
123
|
-
per-operation `merkleThreshold` overrides available on store calls.
|
|
124
|
-
Sub-manifest arrays are capped at 10,000 entries.
|
|
125
|
-
|
|
126
|
-
Every manifest carries an **integrity hash** — the SHA-256 of the codec-encoded content — verified on every read to detect corruption or tampering. Two codecs are available: **JSON** (human-readable, default) and **CBOR** (binary, compact).
|
|
127
|
-
|
|
128
|
-
Manifest diffing is available via `diffManifests()` for comparing two manifests and identifying changed, added, or removed chunks.
|
|
129
|
-
|
|
130
|
-
### Vault
|
|
131
|
-
|
|
132
|
-
The vault is a GC-safe named asset index stored at `refs/cas/vault`. It is the control plane for managing stored content.
|
|
133
|
-
|
|
134
|
-
- **CRUD**: Add, remove, list, and resolve named entries.
|
|
135
|
-
- **Encryption**: Vault entries can be encrypted with a passphrase.
|
|
136
|
-
- **Privacy mode**: HMAC-hashed slug names prevent metadata discovery — an observer cannot determine what assets are stored without the passphrase.
|
|
137
|
-
- **Encryption count tracking**: The vault tracks how many times each entry has been encrypted under the current nonce context, issuing rotation warnings as limits approach.
|
|
138
|
-
- **Passphrase verifier**: Encrypted vault metadata authenticates the derived
|
|
139
|
-
vault key even before the first entry is added, so wrong passphrases fail
|
|
140
|
-
before empty-vault writes are accepted.
|
|
141
|
-
- **Passphrase rotation**: Rotate the vault passphrase across all entries in a single operation without re-encrypting data blobs.
|
|
142
|
-
- **Optimistic concurrency**: Vault writes use compare-and-swap semantics with automatic retry on conflict, ensuring safe concurrent access.
|
|
143
|
-
|
|
144
|
-
### Restore Modes
|
|
145
|
-
|
|
146
|
-
Three restore surfaces cover different memory and latency profiles:
|
|
147
|
-
|
|
148
|
-
| Method | Behavior | Bounded? |
|
|
149
|
-
|---|---|---|
|
|
150
|
-
| `restore()` | Buffered reassembly to memory | Yes — capped by `maxRestoreBufferSize` |
|
|
151
|
-
| `restoreFile()` | Atomic temp-file write with auth-then-rename | Yes — streams through disk for plaintext, framed, convergent, and uncompressed whole |
|
|
152
|
-
| `restoreStream()` | Async iterable yielding chunks | Yes — frame-by-frame for framed scheme |
|
|
153
|
-
|
|
154
|
-
`restoreFile()` writes tentative plaintext to a temporary file, verifies authentication, and renames into place only after verification succeeds. For `framed`, all three surfaces provide true streaming restore with per-frame authentication. Parallel chunk restore is supported via a prefetch window (`PrefetchWindow`) when concurrency is greater than 1, enabling ordered parallel reads for faster restores.
|
|
155
|
-
|
|
156
|
-
```js
|
|
157
|
-
await cas.restoreFile({
|
|
158
|
-
manifest,
|
|
159
|
-
outputPath: './restored.bin',
|
|
160
|
-
baseDirectory: process.cwd(),
|
|
161
|
-
});
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### CLI
|
|
165
|
-
|
|
166
|
-
The `git-cas` command-line interface exposes the full feature set:
|
|
167
|
-
|
|
168
|
-
| Command | Purpose |
|
|
169
|
-
|---|---|
|
|
170
|
-
| `git-cas store` | Store a file into the CAS |
|
|
171
|
-
| `git-cas tree` | Create a Git tree from a manifest JSON file |
|
|
172
|
-
| `git-cas inspect` | Inspect a stored manifest and optional chunk heatmap |
|
|
173
|
-
| `git-cas restore` | Restore content by vault slug or tree OID |
|
|
174
|
-
| `git-cas verify` | Verify chunk integrity for a stored asset |
|
|
175
|
-
| `git-cas doctor` | Diagnose vault health and integrity |
|
|
176
|
-
| `git-cas vault init` | Initialize a new vault |
|
|
177
|
-
| `git-cas vault list` | List vault entries |
|
|
178
|
-
| `git-cas vault stats` | Summarize vault size, dedupe, and encryption coverage |
|
|
179
|
-
| `git-cas vault remove` | Remove a vault entry |
|
|
180
|
-
| `git-cas vault info` | Show metadata for one vault entry |
|
|
181
|
-
| `git-cas vault history` | Show vault commit history |
|
|
182
|
-
| `git-cas vault rotate` | Rotate the vault passphrase |
|
|
183
|
-
| `git-cas vault dashboard` | Interactive TUI for vault navigation |
|
|
184
|
-
| `git-cas rotate` | Rotate an asset encryption key wrapper |
|
|
185
|
-
| `git-cas recipient add/remove/list` | Manage envelope encryption recipients |
|
|
186
|
-
|
|
187
|
-
`git-cas doctor` reports both chunk-reference dedupe and byte-level efficiency:
|
|
188
|
-
logical manifest size versus unique chunk bytes. For privacy-enabled vaults,
|
|
189
|
-
pass `--key-file`, `--vault-passphrase-file -`, or `--os-keychain-target` so the
|
|
190
|
-
doctor can decrypt the privacy index before scanning entries.
|
|
191
|
-
|
|
192
|
-
**Agent CLI**: `git-cas agent` exposes the same store/tree/restore/inspect/verify/doctor/rotate/recipient/vault surface through a newline-delimited protocol for CI/CD automation and programmatic integrations. Request payloads can be passed through `--request <json>` or stdin; responses stream back as JSON events on stdout.
|
|
193
|
-
|
|
194
|
-
### Security Hardening
|
|
195
|
-
|
|
196
|
-
Beyond the core encryption primitives, `git-cas` enforces a set of defensive limits:
|
|
197
|
-
|
|
198
|
-
- **Hex validation**: All OID and digest fields are schema-validated as strict hexadecimal strings.
|
|
199
|
-
- **scrypt memory cap**: Combined scrypt memory budget is hard-capped at 1 GiB.
|
|
200
|
-
- **Sub-manifest array limit**: Merkle sub-manifests are capped at 10,000 entries.
|
|
201
|
-
- **Restore path boundary**: `restoreFile()` requires `baseDirectory` and refuses output paths that escape it.
|
|
202
|
-
- **Metadata blob cap**: Manifest and sub-manifest blob reads default to a
|
|
203
|
-
10 MiB `maxBlobSize` safety limit. The default Git adapter honors the
|
|
204
|
-
facade/service `maxBlobSize` option through its adapter-level read limit.
|
|
205
|
-
- **Concurrency cap**: Parallel operations are bounded at 64.
|
|
206
|
-
- **Frame size cap**: `frameBytes` is capped at 64 MiB.
|
|
207
|
-
- **Timing oracle elimination**: Recipient trial decryption uses constant-time comparison to prevent timing-based key identification.
|
|
208
|
-
- **Source validation**: Async iterables passed to `store()` are validated before processing begins.
|
|
209
|
-
- **Salt enforcement**: KDF salts must be at least 16 bytes.
|
|
210
|
-
- **Nonce rotation**: Encryption count tracking warns before nonce reuse becomes a concern.
|
|
211
|
-
- **Legacy scheme rejection**: Attempting to use a legacy encryption scheme (`whole-v1`, `whole-v2`, `framed-v1`, `framed-v2`, `convergent-v1`) throws a `LEGACY_SCHEME` error with migration guidance (see [UPGRADING.md](./UPGRADING.md)).
|
|
212
|
-
|
|
213
|
-
## Streaming Surface
|
|
214
|
-
|
|
215
|
-
| Surface | Streaming API? | Non-streaming API? | Notes |
|
|
216
|
-
|---|---|---|---|
|
|
217
|
-
| Write | `store({ source, ... })`, `storeFile(...)` | No dedicated non-streaming store facade | Write ingress is stream-based. CDC + encryption defaults to `convergent` (per-chunk deterministic encryption preserving dedup). Fixed + encryption defaults to `framed`. |
|
|
218
|
-
| Read: plaintext | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | True chunk-by-chunk streaming restore. |
|
|
219
|
-
| Read: encrypted `whole` | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | `restoreStream()` is the buffered compatibility path. Uncompressed `restoreFile()` verifies chunks, streams tentative plaintext through whole-object AES-GCM decryption into a temp-file path, and renames into place only after auth succeeds. AAD (slug) is always bound. On Web Crypto runtimes this decrypt step is still one-shot internally, bounded by `maxDecryptionBufferSize`. |
|
|
220
|
-
| Read: encrypted `framed` | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | True authenticated streaming restore. Plaintext is yielded frame-by-frame after each frame is verified. Per-frame AAD is always bound. |
|
|
221
|
-
| Read: compressed-only | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | Plaintext + gzip now streams end-to-end. `restoreFile()` streams gunzip output through a bounded temp-file path. |
|
|
222
|
-
| Read: compressed + `whole` | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | Auth must complete before gunzip. `restoreFile()` therefore preserves the auth-before-decompress boundary and may buffer the encrypted compressed payload; use `framed` or `convergent` for large compressed encrypted assets. |
|
|
223
|
-
| Read: compressed + `framed` | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | Streaming decrypt, then streaming gunzip. |
|
|
224
|
-
| Read: encrypted `convergent` | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | True per-chunk streaming restore. Each chunk is decrypted individually using a key derived from its content hash. Parallel chunk restore via prefetch window when concurrency > 1. |
|
|
225
|
-
| Read: compressed + `convergent` | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | Per-chunk convergent decrypt, then streaming gunzip. |
|
|
226
|
-
| Verify | No streaming verify surface | `verifyIntegrity(manifest, options?)` | Verifies chunk digests for all content. `whole` auth-checks the full ciphertext; `framed` parses and auth-checks every frame; `convergent` decrypts each chunk and verifies plaintext digests. |
|
|
227
|
-
|
|
228
|
-
Runtime note: `framed` is the honest cross-runtime streaming answer. On Node and Bun, `whole restoreFile()` has the stronger low-memory path; on Web Crypto runtimes such as Deno, `whole` remains bounded-buffer rather than true streaming.
|
|
229
|
-
|
|
230
|
-
## Architecture
|
|
231
|
-
|
|
232
|
-
`git-cas` follows a strict hexagonal (ports and adapters) architecture. The domain core has zero knowledge of runtime-specific APIs.
|
|
233
|
-
|
|
234
|
-
```
|
|
235
|
-
┌─────────────────────┐
|
|
236
|
-
│ ContentAddressable │
|
|
237
|
-
│ Store (Facade) │
|
|
238
|
-
└──────────┬──────────┘
|
|
239
|
-
│
|
|
240
|
-
┌──────────▼──────────┐
|
|
241
|
-
│ CasService │
|
|
242
|
-
│ (Domain Core) │
|
|
243
|
-
└──┬──┬──┬──┬──┬──┬───┘
|
|
244
|
-
│ │ │ │ │ │
|
|
245
|
-
┌──────────────┘ │ │ │ │ └──────────────┐
|
|
246
|
-
│ ┌────────┘ │ │ └────────┐ │
|
|
247
|
-
▼ ▼ ▼ ▼ ▼ ▼
|
|
248
|
-
┌────────┐┌────────┐┌────────┐┌────────┐┌────────┐┌────────┐
|
|
249
|
-
│Persist.││ Crypto ││ Codec ││Compress││Chunking││Observe.│
|
|
250
|
-
│ Port ││ Port ││ Port ││ Port ││ Port ││ Port │
|
|
251
|
-
└───┬────┘└───┬────┘└───┬────┘└───┬────┘└───┬────┘└───┬────┘
|
|
252
|
-
│ │ │ │ │ │
|
|
253
|
-
▼ ▼ ▼ ▼ ▼ ▼
|
|
254
|
-
GitODB Node/Bun JSON or Node gzip Fixed or Event
|
|
255
|
-
/Deno CBOR adapter CDC/ Emitter
|
|
256
|
-
Crypto Buzhash
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
**Ports** define the contracts. **Adapters** implement them for specific runtimes. Swap any adapter without touching domain logic.
|
|
260
|
-
|
|
261
|
-
The core byte contract is `Uint8Array`. Node `Buffer` values still work at the
|
|
262
|
-
Node boundary because `Buffer` extends `Uint8Array`, but the domain, ports,
|
|
263
|
-
chunkers, codecs, and shared helpers do not depend on Node-specific byte APIs.
|
|
264
|
-
|
|
265
|
-
## Multi-Runtime Support
|
|
266
|
-
|
|
267
|
-
| Runtime | Version | Crypto Backend | Status |
|
|
268
|
-
|---|---|---|---|
|
|
269
|
-
| **Node.js** | 22+ | `node:crypto` | Primary — full streaming support |
|
|
270
|
-
| **Bun** | Latest | `node:crypto` compat | Tested via Docker |
|
|
271
|
-
| **Deno** | Latest | Web Crypto API | Tested via Docker; `whole` decrypt is bounded-buffer |
|
|
62
|
+
## Capability Map
|
|
63
|
+
|
|
64
|
+
The README is the front door. Detailed mechanics live in the guide set:
|
|
65
|
+
|
|
66
|
+
| Need | Start Here |
|
|
67
|
+
| ------------------------------------------------------- | ------------------------------------------------------------ |
|
|
68
|
+
| Productive library and CLI workflows | [Developer Guide](./GUIDE.md) |
|
|
69
|
+
| Restore memory behavior | [Streaming and restore matrix](./GUIDE.md#streaming-surface) |
|
|
70
|
+
| Encryption scheme selection | [Encryption Modes](./docs/ENCRYPTION_MODES.md) |
|
|
71
|
+
| CDC internals, Merkle manifests, KDF policy, and tuning | [Advanced Guide](./ADVANCED_GUIDE.md) |
|
|
72
|
+
| Ports, adapters, and collaborator boundaries | [Architecture](./ARCHITECTURE.md) |
|
|
73
|
+
| v5 to v6 migration | [Upgrading](./UPGRADING.md) |
|
|
74
|
+
|
|
75
|
+
Core capabilities:
|
|
76
|
+
|
|
77
|
+
- **Content-addressed storage**: chunks are addressed by SHA-256 digest and
|
|
78
|
+
integrity-verified on read.
|
|
79
|
+
- **Deduplication**: fixed chunking and content-defined chunking (CDC) support
|
|
80
|
+
predictable or shift-resistant chunk boundaries.
|
|
81
|
+
- **Encryption**: AES-256-GCM with authenticated metadata. `whole` and
|
|
82
|
+
`framed` use fresh random 96-bit nonces; `convergent` derives per-chunk keys
|
|
83
|
+
and nonces deterministically from the plaintext content hash to preserve
|
|
84
|
+
deduplication.
|
|
85
|
+
- **Vault indexing**: named assets live under `refs/cas/vault` so Git garbage
|
|
86
|
+
collection does not reclaim referenced blobs.
|
|
87
|
+
- **Envelope recipients**: multi-recipient key wrapping and recipient rotation
|
|
88
|
+
avoid re-encrypting data blobs.
|
|
89
|
+
- **Operational diagnostics**: `git-cas doctor` validates vault health and
|
|
90
|
+
reports deduplication efficiency.
|
|
91
|
+
|
|
92
|
+
## Safety Snapshot
|
|
93
|
+
|
|
94
|
+
The v6 line is Security First by default:
|
|
95
|
+
|
|
96
|
+
- `restoreFile()` requires `baseDirectory` and refuses output paths that escape
|
|
97
|
+
it.
|
|
98
|
+
- Manifest and sub-manifest blob reads default to a 10 MiB `maxBlobSize` safety
|
|
99
|
+
limit.
|
|
100
|
+
- Legacy encryption scheme identifiers throw `LEGACY_SCHEME` with migration
|
|
101
|
+
guidance.
|
|
102
|
+
- KDF parameters, salts, frame sizes, restore buffers, and concurrency are
|
|
103
|
+
policy-bounded.
|
|
104
|
+
- Recipient trial decryption and vault verifier checks use constant-time
|
|
105
|
+
comparisons.
|
|
106
|
+
|
|
107
|
+
For the full hardening table, see
|
|
108
|
+
[Advanced Guide: Security Hardening Summary](./ADVANCED_GUIDE.md#security-hardening-summary).
|
|
109
|
+
|
|
110
|
+
## Runtime Support
|
|
111
|
+
|
|
112
|
+
| Runtime | Version | Crypto Backend | Status |
|
|
113
|
+
| ----------- | ------- | -------------------- | ---------------------------------------------------- |
|
|
114
|
+
| **Node.js** | 22+ | `node:crypto` | Primary — full streaming support |
|
|
115
|
+
| **Bun** | Latest | `node:crypto` compat | Tested via Docker |
|
|
116
|
+
| **Deno** | Latest | Web Crypto API | Tested via Docker; `whole` decrypt is bounded-buffer |
|
|
272
117
|
|
|
273
118
|
All three runtimes are tested in CI on every push. The hexagonal architecture isolates runtime differences behind the `CryptoPort` boundary, so the domain core is runtime-agnostic.
|
|
274
119
|
|
|
@@ -289,4 +134,5 @@ All three runtimes are tested in CI on every push. The hexagonal architecture is
|
|
|
289
134
|
- **[Changelog](./CHANGELOG.md)**: Version history and migration notes.
|
|
290
135
|
|
|
291
136
|
---
|
|
137
|
+
|
|
292
138
|
Built with terminal ambition by [FLYING ROBOTS](https://github.com/flyingrobots)
|