@git-stunts/git-cas 5.3.2 → 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.
Files changed (173) hide show
  1. package/ADVANCED_GUIDE.md +1027 -0
  2. package/ARCHITECTURE.md +514 -0
  3. package/CHANGELOG.md +449 -5
  4. package/CODE_OF_CONDUCT.md +33 -0
  5. package/GUIDE.md +926 -0
  6. package/README.md +106 -366
  7. package/SECURITY.md +993 -0
  8. package/SUPPORT.md +54 -0
  9. package/UPGRADING.md +299 -0
  10. package/bin/actions.js +70 -21
  11. package/bin/agent/cli.js +51 -0
  12. package/bin/agent/commands/doctor.js +99 -0
  13. package/bin/agent/commands/index.js +1489 -0
  14. package/bin/agent/input.js +619 -0
  15. package/bin/agent/passphrase-source.js +123 -0
  16. package/bin/agent/protocol.js +193 -0
  17. package/bin/build-version.js +64 -0
  18. package/bin/credentials.js +425 -0
  19. package/bin/git-cas.js +595 -449
  20. package/bin/passphrase-source.js +266 -0
  21. package/bin/restore-output-target.js +28 -0
  22. package/bin/ui/blocks/asset-card.js +109 -0
  23. package/bin/ui/blocks/health-dashboard.js +149 -0
  24. package/bin/ui/blocks/heatmap-block.js +67 -0
  25. package/bin/ui/blocks/merkle-explorer.js +163 -0
  26. package/bin/ui/blocks/operation-feed.js +176 -0
  27. package/bin/ui/blocks/wizard-block.js +168 -0
  28. package/bin/ui/components/short-sha.js +36 -0
  29. package/bin/ui/context.js +56 -1
  30. package/bin/ui/dashboard-cmds.js +1578 -13
  31. package/bin/ui/dashboard-view.js +612 -145
  32. package/bin/ui/dashboard.js +1255 -212
  33. package/bin/ui/encryption-card.js +69 -26
  34. package/bin/ui/heatmap.js +26 -54
  35. package/bin/ui/history-timeline.js +51 -19
  36. package/bin/ui/manifest-view.js +115 -60
  37. package/bin/ui/merkle-dag.js +83 -0
  38. package/bin/ui/progress.js +15 -9
  39. package/bin/ui/repo-treemap.js +328 -0
  40. package/bin/ui/shaders/bak-sneppen.js +180 -0
  41. package/bin/ui/shaders/fractal-zoom.js +99 -0
  42. package/bin/ui/shaders/merkle-tree.js +142 -0
  43. package/bin/ui/shaders/organic-flow.js +96 -0
  44. package/bin/ui/shaders/phase-portrait.js +93 -0
  45. package/bin/ui/store-wizard.js +367 -0
  46. package/bin/ui/theme.js +155 -0
  47. package/bin/ui/vault-report.js +495 -0
  48. package/build-info.json +4 -0
  49. package/docs/API.md +2254 -0
  50. package/docs/ENCRYPTION_MODES.md +33 -0
  51. package/docs/EXTENDING.md +174 -0
  52. package/docs/STORE_RESTORE_PIPELINE.md +199 -0
  53. package/docs/THREAT_MODEL.md +269 -0
  54. package/docs/VAULT_INTERNALS.md +251 -0
  55. package/docs/WALKTHROUGH.md +1868 -0
  56. package/docs/demo.gif +0 -0
  57. package/docs/releases/v6.0.0.md +104 -0
  58. package/examples/README.md +260 -0
  59. package/index.d.ts +273 -80
  60. package/index.js +220 -59
  61. package/package.json +35 -6
  62. package/scripts/migrate-encryption.js +680 -0
  63. package/src/domain/bytes/ByteLayout.js +96 -0
  64. package/src/domain/encoding/base64.js +91 -0
  65. package/src/domain/encoding/hex.js +14 -0
  66. package/src/domain/encoding/utf8.js +123 -0
  67. package/src/domain/encryption/schemes.js +132 -0
  68. package/src/domain/errors/CannotRemoveLastRecipientError.js +10 -0
  69. package/src/domain/errors/CasError.d.ts +28 -0
  70. package/src/domain/errors/CasError.js +43 -6
  71. package/src/domain/errors/Codes.js +54 -0
  72. package/src/domain/errors/DekUnwrapFailedError.js +10 -0
  73. package/src/domain/errors/GitError.js +10 -0
  74. package/src/domain/errors/GitPlumbingInitializationError.js +10 -0
  75. package/src/domain/errors/IntegrityError.js +10 -0
  76. package/src/domain/errors/InvalidChunkingStrategyError.js +10 -0
  77. package/src/domain/errors/InvalidOidError.js +10 -0
  78. package/src/domain/errors/InvalidOptionsError.js +10 -0
  79. package/src/domain/errors/ManifestIntegrityError.js +10 -0
  80. package/src/domain/errors/ManifestNotFoundError.js +10 -0
  81. package/src/domain/errors/NoMatchingRecipientError.js +10 -0
  82. package/src/domain/errors/PersistenceCapabilityRequiredError.js +10 -0
  83. package/src/domain/errors/PortNotImplementedError.js +10 -0
  84. package/src/domain/errors/RecipientAlreadyExistsError.js +10 -0
  85. package/src/domain/errors/RecipientNotFoundError.js +10 -0
  86. package/src/domain/errors/RestoreTooLargeError.js +10 -0
  87. package/src/domain/errors/RotationNotSupportedError.js +10 -0
  88. package/src/domain/errors/createCasError.js +68 -0
  89. package/src/domain/errors/index.js +20 -0
  90. package/src/domain/helpers/buildKdfMetadata.js +4 -2
  91. package/src/domain/helpers/codecBytes.js +34 -0
  92. package/src/domain/helpers/gitRefErrors.js +84 -0
  93. package/src/domain/helpers/scryptMaxmem.js +22 -0
  94. package/src/domain/outcomes/RestoreFailure.js +15 -0
  95. package/src/domain/outcomes/RestoreOutcome.js +11 -0
  96. package/src/domain/outcomes/RestoreSuccess.js +34 -0
  97. package/src/domain/outcomes/StoreFailure.js +15 -0
  98. package/src/domain/outcomes/StoreOutcome.js +11 -0
  99. package/src/domain/outcomes/StoreSuccess.js +17 -0
  100. package/src/domain/schemas/ManifestSchema.d.ts +40 -9
  101. package/src/domain/schemas/ManifestSchema.js +67 -13
  102. package/src/domain/services/CasService.d.ts +153 -53
  103. package/src/domain/services/CasService.js +322 -837
  104. package/src/domain/services/ChunkRepository.js +268 -0
  105. package/src/domain/services/CompressionStreams.js +72 -0
  106. package/src/domain/services/ConvergentEncryption.js +128 -0
  107. package/src/domain/services/GitTreeBuilder.js +86 -0
  108. package/src/domain/services/IntegrityVerifier.js +199 -0
  109. package/src/domain/services/KeyResolver.js +49 -42
  110. package/src/domain/services/ManifestDiff.js +56 -0
  111. package/src/domain/services/ManifestRepository.js +286 -0
  112. package/src/domain/services/PrefetchWindow.js +48 -0
  113. package/src/domain/services/RecipientService.js +157 -0
  114. package/src/domain/services/RedactingObservability.js +169 -0
  115. package/src/domain/services/RestorePipeline.js +68 -0
  116. package/src/domain/services/StorePipeline.js +201 -0
  117. package/src/domain/services/VaultKeyVerifier.js +101 -0
  118. package/src/domain/services/VaultMetadataCodec.js +206 -0
  119. package/src/domain/services/VaultMutationRetryPolicy.js +105 -0
  120. package/src/domain/services/VaultPersistence.js +410 -0
  121. package/src/domain/services/VaultPrivacyIndex.js +191 -0
  122. package/src/domain/services/VaultService.js +749 -251
  123. package/src/domain/services/VaultStateCache.js +225 -0
  124. package/src/domain/services/VaultTreeCodec.js +121 -0
  125. package/src/domain/services/rotateVaultPassphrase.js +37 -20
  126. package/src/domain/strategies/Aad.js +39 -0
  127. package/src/domain/strategies/FramedRecordCodec.js +204 -0
  128. package/src/domain/strategies/RestoreCompressed.js +40 -0
  129. package/src/domain/strategies/RestoreConvergent.js +44 -0
  130. package/src/domain/strategies/RestoreFramed.js +55 -0
  131. package/src/domain/strategies/RestorePlain.js +37 -0
  132. package/src/domain/strategies/RestoreStrategy.js +35 -0
  133. package/src/domain/strategies/RestoreWhole.js +135 -0
  134. package/src/domain/strategies/StoreConvergent.js +28 -0
  135. package/src/domain/strategies/StoreFramed.js +39 -0
  136. package/src/domain/strategies/StorePlain.js +20 -0
  137. package/src/domain/strategies/StoreStrategy.js +61 -0
  138. package/src/domain/strategies/StoreWhole.js +34 -0
  139. package/src/domain/value-objects/Chunk.js +1 -2
  140. package/src/domain/value-objects/EncryptionMetadata.js +87 -0
  141. package/src/domain/value-objects/Manifest.d.ts +40 -4
  142. package/src/domain/value-objects/Manifest.js +61 -20
  143. package/src/domain/value-objects/Oid.js +45 -0
  144. package/src/domain/value-objects/Slug.js +124 -0
  145. package/src/domain/value-objects/StoreEncryptionConfig.js +114 -0
  146. package/src/helpers/aesGcmMeta.js +55 -0
  147. package/src/helpers/canonicalBase64.js +1 -0
  148. package/src/helpers/kdfPolicy.js +194 -0
  149. package/src/infrastructure/adapters/BunCryptoAdapter.js +124 -8
  150. package/src/infrastructure/adapters/FileIOHelper.js +180 -13
  151. package/src/infrastructure/adapters/GitPersistenceAdapter.js +235 -42
  152. package/src/infrastructure/adapters/GitPlumbingFactoryAdapter.js +62 -0
  153. package/src/infrastructure/adapters/GitRefAdapter.js +19 -6
  154. package/src/infrastructure/adapters/NodeCompressionAdapter.js +64 -0
  155. package/src/infrastructure/adapters/NodeCryptoAdapter.js +130 -10
  156. package/src/infrastructure/adapters/WebCryptoAdapter.js +187 -77
  157. package/src/infrastructure/chunkers/CdcChunker.js +53 -19
  158. package/src/infrastructure/chunkers/FixedChunker.js +15 -7
  159. package/src/infrastructure/chunkers/resolveChunker.js +10 -6
  160. package/src/infrastructure/codecs/CborCodec.js +3 -3
  161. package/src/infrastructure/codecs/JsonCodec.js +5 -5
  162. package/src/infrastructure/createGitPlumbing.js +22 -0
  163. package/src/package-version.js +1 -0
  164. package/src/ports/ChunkingPort.js +3 -3
  165. package/src/ports/CodecPort.js +4 -4
  166. package/src/ports/CompressionPort.js +57 -0
  167. package/src/ports/CryptoPort.js +138 -50
  168. package/src/ports/GitPersistencePort.js +32 -2
  169. package/src/ports/GitPlumbingFactoryPort.js +16 -0
  170. package/src/ports/GitRefPort.js +1 -1
  171. package/src/types/ambient.d.ts +10 -5
  172. package/test/CONVENTIONS.md +94 -0
  173. package/test/cycles/README.md +13 -0
package/README.md CHANGED
@@ -1,398 +1,138 @@
1
- # @git-stunts/git-cas
1
+ # git-cas
2
2
 
3
- <img width="420" alt="git-cas" src="https://github.com/user-attachments/assets/e7cb63b9-25b7-4369-b053-4a35962ccee4" />
3
+ > Modern open-source systems still rely on centralized infrastructure to distribute binary artifacts, even when their source code is fully decentralized. This creates a fragile dependency: if hosting endpoints are blocked, degraded, or removed, critical artifacts become unavailable or unverifiable.
4
+ >
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.
4
6
 
5
- ## JESSIE, STOP—
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.
6
8
 
7
- > Hold on. He’s turning Git into a blob store. Let him cook.
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.
8
10
 
9
- **Most potent clone available on GitHub (legally).**
11
+ [![npm version](https://img.shields.io/npm/v/@git-stunts/git-cas)](https://www.npmjs.com/package/@git-stunts/git-cas)
12
+ [![License](https://img.shields.io/github/license/git-stunts/git-cas)](./LICENSE)
10
13
 
11
- ### Git, freebased: pure CAS that’ll knock your SHAs off. LFS hates this repo.
14
+ ![git-cas demo](./docs/demo.gif)
12
15
 
13
- Git isn’t source control.
14
- Git is a content-addressed object database.
15
- We use the object database.
16
+ ## Why git-cas?
16
17
 
17
- `git-cas` chunks files into Git blobs (dedupe for free), optionally encrypts them, and emits a manifest + a real Git tree so you can commit/tag/ref it like any other artifact.
18
+ Unlike traditional LFS which moves files to external servers, `git-cas` treats the Git object database as a first-class storage substrate.
18
19
 
19
- ## What you get
20
+ - **Deduplication by Default**: Content-defined chunking (CDC) with Buzhash rolling hash identifies repeated patterns across files and versions, minimizing repository growth.
21
+ - **Cryptographic Trust**: Every chunk is verified against a SHA-256 digest. Optional AES-256-GCM encryption with multi-recipient envelope support ensures privacy at rest, and `framed` binds per-frame AAD to prevent cross-manifest blob swaps.
22
+ - **GC-Safe Vault**: Named assets are indexed through a stable ref (`refs/cas/vault`) with optimistic concurrency, preventing Git garbage collection from reclaiming referenced blobs.
23
+ - **Key Lifecycle**: Envelope encryption separates DEKs from KEKs. Rotate passphrases across an entire vault without re-encrypting data blobs. Privacy mode HMAC-hashes slug names to prevent metadata discovery.
24
+ - **Runtime-Adaptive**: A single core supports Node.js 22+, Bun, and Deno through a strict hexagonal port architecture with runtime-specific crypto adapters.
20
25
 
21
- - **Dedupe for free** Git already hashes objects. We just lean into it.
22
- - **Chunked storage** big files become stable, reusable blobs. Fixed-size or content-defined chunking (CDC).
23
- - **Optional AES-256-GCM encryption** store secrets without leaking plaintext into the ODB.
24
- - **Multi-recipient encryption** envelope model (DEK/KEK) — add/remove access without re-encrypting data.
25
- - **Key rotation** rotate keys without re-encrypting data blobs. Respond to compromise in seconds.
26
- - **Compression** gzip before encryption — smaller blobs, same round-trip.
27
- - **Passphrase encryption** derive keys from passphrases via PBKDF2 or scrypt — no raw key management.
28
- - **Merkle manifests** large files auto-split into sub-manifests for scalability.
29
- - **Manifests** a tiny explicit index of chunks + metadata (JSON/CBOR).
30
- - **Tree output** generates standard Git trees so assets snap into commits cleanly.
31
- - **Full round-trip** store, tree, and restore — get your bytes back, verified.
32
- - **Lifecycle management** `readManifest`, `inspectAsset`, `collectReferencedChunks` — inspect trees, plan deletions, audit storage.
33
- - **Vault** GC-safe ref-based storage. One ref (`refs/cas/vault`) indexes all assets by slug. No more silent data loss from `git gc`.
34
- - **Interactive dashboard** `git cas inspect` with chunk heatmap, animated progress bars, and rich manifest views.
35
- - **Verify & JSON output** `git cas verify` checks integrity; `--json` on all current human-facing commands provides convenient structured output for CI/scripting.
26
+ ## Quick Start
36
27
 
37
- **Use it for:** binary assets, build artifacts, model weights, data packs, secret bundles, weird experiments, etc.
28
+ Existing v5 users should read [UPGRADING.md](./UPGRADING.md) and run
29
+ `npm run upgrade` in dry-run mode before restoring old encrypted vault entries.
30
+ For the release overview, see the
31
+ [v6.0.0 Release Notes](./docs/releases/v6.0.0.md).
38
32
 
39
- <img src="./docs/demo.gif" alt="git-cas demo" />
33
+ ### 1. CLI Usage
40
34
 
41
- ## What's new in v5.3.1
42
-
43
- **Patch release — repeated chunk tree fix.**
44
-
45
- - **Unique chunk tree entries** — `createTree()` and `_createMerkleTree()` now emit one tree entry per unique chunk digest instead of repeating the same filename for repeated chunk occurrences.
46
- - **Manifest remains authoritative** — chunk order and multiplicity still come entirely from the manifest; restore behavior is unchanged.
47
- - **Clean `git fsck` on repetitive files** — repetitive content no longer yields duplicate tree filenames or `duplicateEntries` errors.
48
- - **New regressions** — unit and integration coverage now exercises repeated-chunk files and validates real Git tree integrity with `git fsck --full`.
49
-
50
- See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
51
-
52
- ## What's new in v5.3.0
53
-
54
- **M16 Capstone — audit remediation, CLI configuration, and security hardening.**
55
-
56
- - **`.casrc` config file** — JSON config at repo root sets defaults for all CLI flags (chunk size, strategy, concurrency, codec, compression, CDC params).
57
- - **CLI store/restore flags** — all library-level options now accessible from the command line: `--gzip`, `--strategy`, `--chunk-size`, `--concurrency`, `--codec`, `--merkle-threshold`, and CDC-specific flags.
58
- - **Passphrase-file support** — `--vault-passphrase-file <path>` on store, restore, and vault rotate (use `-` for stdin).
59
- - **Memory restore guard** — `maxRestoreBufferSize` (default 512 MiB) prevents unbounded memory allocation on encrypted/compressed restore.
60
- - **Web Crypto encryption buffer guard** — `maxEncryptionBufferSize` (default 512 MiB) for the one-shot AES-GCM API.
61
- - **Orphaned blob tracking** — `STREAM_ERROR` now includes `meta.orphanedBlobs` for cleanup after partial store failures.
62
- - **KDF brute-force awareness** — `decryption_failed` metric + CLI rate-limiting delay on `INTEGRITY_ERROR`.
63
- - **Encryption counter** — vault metadata tracks `encryptionCount` with observability warning near GCM nonce bound.
64
- - **Lifecycle method rename** — `inspectAsset()` / `collectReferencedChunks()` replace `deleteAsset()` / `findOrphanedChunks()` (old names preserved as deprecated aliases).
65
- - **FixedChunker O(n²) fix** — pre-allocated buffer replaces `Buffer.concat()` loop.
66
- - **Chunk size upper bound** — 100 MiB max enforced across all chunkers.
67
- - **Constructor validation** — `chunkSize`, `maxRestoreBufferSize`, `maxEncryptionBufferSize` validated at construction time.
68
- - **Cross-runtime portability** — `Error.captureStackTrace` guarded, crypto adapter contracts normalized.
69
-
70
- ## What's new in v5.2.3
71
-
72
- **Internal refactoring — no breaking API changes.** The facade, CasService, and crypto adapters were restructured for better separation of concerns:
73
-
74
- - **Consistent async `sha256()`** — `NodeCryptoAdapter.sha256()` now returns `Promise<string>` like Bun and Web adapters, fixing a Liskov Substitution violation.
75
- - **`KeyResolver` extracted** — ~170 lines of key resolution logic (DEK wrap/unwrap, passphrase derivation, envelope recipients) moved from CasService (1085 → 909 lines) into a dedicated `KeyResolver` service.
76
- - **Facade decomposed** — `createCryptoAdapter`, `resolveChunker`, `FileIOHelper`, `rotateVaultPassphrase`, and `buildKdfMetadata` extracted from the monolithic `index.js` into focused modules.
77
- - **Barrel re-exports** — 10 re-export-only modules converted to `export { default as X } from '...'` form.
78
-
79
- See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
80
-
81
- ## What's new in v5.2.1
82
-
83
- Bug fix: `rotateVaultPassphrase` now honours `kdfOptions.algorithm` — previously the `--algorithm` flag was silently ignored, always reusing the old KDF algorithm. CLI flag tables in `docs/API.md` are now split per command with `--cwd` documented.
84
-
85
- See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
86
-
87
- ## What's new in v5.2.0
88
-
89
- **Key rotation without re-encrypting data** — Rotate a recipient's key by re-wrapping the DEK. Data blobs are never touched. Respond to key compromise in seconds, not hours.
90
-
91
- ```js
92
- // Rotate a single recipient's key
93
- const rotated = await cas.rotateKey({
94
- manifest, oldKey: aliceOldKey, newKey: aliceNewKey, label: 'alice',
95
- });
96
-
97
- // Rotate the vault passphrase (all entries, atomic commit)
98
- const { commitOid, rotatedSlugs, skippedSlugs } = await cas.rotateVaultPassphrase({
99
- oldPassphrase: 'old-secret', newPassphrase: 'new-secret',
100
- });
101
- ```
35
+ Initialize a vault and store your first asset.
102
36
 
103
37
  ```bash
104
- # Rotate a recipient key
105
- git cas rotate --slug prod-secrets --old-key-file old.key --new-key-file new.key
106
-
107
- # Rotate vault passphrase
108
- git cas vault rotate --old-passphrase old-secret --new-passphrase new-secret
38
+ git init
39
+ git-cas vault init
40
+ git-cas store data.bin --slug assets/v1 --tree
41
+ git-cas restore --slug assets/v1 --out data-restored.bin
109
42
  ```
110
43
 
111
- See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
112
-
113
- ## What's new in v5.1.0
114
-
115
- **Multi-recipient envelope encryption** — Each file is encrypted with a random DEK; recipient KEKs wrap the DEK. Add or remove team members without re-encrypting data.
44
+ ### 2. TUI Cockpit
116
45
 
117
- ```js
118
- // API: store for multiple recipients
119
- const manifest = await cas.storeFile({
120
- filePath: './secrets.tar.gz',
121
- slug: 'prod-secrets',
122
- recipients: [
123
- { label: 'alice', key: aliceKey },
124
- { label: 'bob', key: bobKey },
125
- ],
126
- });
127
-
128
- // Add a recipient later (no re-encryption)
129
- const updated = await cas.addRecipient({
130
- manifest, existingKey: aliceKey, newRecipientKey: carolKey, label: 'carol',
131
- });
132
-
133
- // List / remove recipients
134
- const labels = await cas.listRecipients({ manifest });
135
- const trimmed = await cas.removeRecipient({ manifest, label: 'bob' });
136
- ```
46
+ Navigate your stored assets through the reader-first interactive dashboard.
137
47
 
138
48
  ```bash
139
- # CLI: store with multiple recipients
140
- git cas store ./secrets.tar.gz --slug prod-secrets \
141
- --recipient alice:./keys/alice.key \
142
- --recipient bob:./keys/bob.key --tree
143
-
144
- # Manage recipients
145
- git cas recipient list prod-secrets
146
- git cas recipient add prod-secrets --label carol --key-file ./keys/carol.key --existing-key-file ./keys/alice.key
147
- git cas recipient remove prod-secrets --label bob
49
+ git-cas vault dashboard
148
50
  ```
149
51
 
150
- See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
151
-
152
- ## What's new in v5.0.0
52
+ ### 3. Library Ingress
153
53
 
154
- **Content-defined chunking (CDC)** — Fixed-size chunking invalidates every chunk after an edit. CDC uses a buzhash rolling hash to find natural boundaries, limiting the blast radius to 1–2 chunks. Benchmarked at 98.4% chunk reuse on small edits vs 32% for fixed.
54
+ Integrate managed blob storage directly into your TypeScript or JavaScript application.
155
55
 
156
56
  ```js
157
- const cas = new ContentAddressableStore({
158
- plumbing,
159
- chunking: { strategy: 'cdc', targetChunkSize: 262144, minChunkSize: 65536, maxChunkSize: 1048576 },
160
- });
57
+ import ContentAddressableStore from '@git-stunts/git-cas';
58
+ const cas = await ContentAddressableStore.open({ cwd: '.' });
59
+ const manifest = await cas.storeFile({ filePath: './asset.bin', slug: 'app/asset' });
161
60
  ```
162
61
 
163
- **`ChunkingPort`** — new hexagonal port abstracts chunking strategy. `FixedChunker` and `CdcChunker` adapters ship out of the box. Bring your own chunker by extending `ChunkingPort`.
164
-
165
- See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
166
-
167
- ## What's new in v4.0.1
168
-
169
- **`git cas verify`** — verify stored asset integrity from the CLI without restoring (`git cas verify --slug my-asset`).
170
-
171
- **`--json` everywhere** — all commands now support `--json` for structured output. Pipe `git cas vault list --json | jq` in CI.
172
-
173
- **CryptoPort base class** — shared key validation, metadata building, and KDF normalization. All three adapters (Node/Bun/Web) inherit from a single source of truth.
174
-
175
- **Centralized error handling** — `runAction` wrapper with CasError codes and actionable hints (e.g., "Provide --key-file or --vault-passphrase").
176
-
177
- **Vault list filtering** — `git cas vault list --filter "photos/*"` with TTY-aware table formatting.
178
-
179
- See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
180
-
181
- ## What's new in v4.0.0
182
-
183
- **ObservabilityPort** — `CasService` no longer extends `EventEmitter`. A new hexagonal `ObservabilityPort` decouples the domain from Node's event infrastructure. Three adapters ship out of the box: `SilentObserver` (no-op default), `EventEmitterObserver` (backward-compatible event bridge), and `StatsCollector` (metric accumulator).
184
-
185
- **Streaming restore** — `restoreStream()` returns an `AsyncIterable<Buffer>` with O(chunkSize) memory for unencrypted files. `restoreFile()` now writes via `createWriteStream` + `pipeline` instead of buffering.
186
-
187
- **Parallel chunk I/O** — new `concurrency` option gates store writes and restore reads through a counting semaphore. `concurrency: 4` can significantly speed up large-file operations.
188
-
189
- See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
190
-
191
- ## What's new in v3.1.0
192
-
193
- **Interactive vault dashboard** — `git cas inspect --slug my-asset` renders a rich TUI with chunk heatmap, encryption card, and history timeline. Animated progress bars for long store/restore operations.
194
-
195
- See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
196
-
197
- ## What's new in v3.0.0
198
-
199
- **Vault** — GC-safe ref-based storage under `refs/cas/vault`. Assets are indexed by slug and survive `git gc`. Full CLI: `git cas vault init`, `list`, `info`, `remove`, `history`. Store with `--tree` to vault automatically.
200
-
201
- See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
202
-
203
- ## What's new in v2.0.0
204
-
205
- **Compression** — `compression: { algorithm: 'gzip' }` on `store()`. Compression runs before encryption. Decompression on `restore()` is automatic.
206
-
207
- **Passphrase-based encryption** — Pass `passphrase` instead of `encryptionKey`. Keys are derived via PBKDF2 (default) or scrypt. KDF parameters are stored in the manifest for deterministic re-derivation. Use `deriveKey()` directly for manual control.
208
-
209
- **Merkle tree manifests** — When chunk count exceeds `merkleThreshold` (default: 1000), manifests are automatically split into sub-manifests stored as separate blobs. `readManifest()` transparently reconstitutes them. Full backward compatibility with v1 manifests.
210
-
211
- See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
212
-
213
- ## Install
214
-
215
- ```bash
216
- npm install @git-stunts/git-cas
217
- ```
218
-
219
- ```bash
220
- npx jsr add @git-stunts/git-cas
221
- ```
222
-
223
- ## Usage (Node API)
224
-
225
- ```js
226
- import GitPlumbing from '@git-stunts/plumbing';
227
- import ContentAddressableStore from '@git-stunts/cas';
228
-
229
- const git = new GitPlumbing({ cwd: './assets-repo' });
230
- const cas = new ContentAddressableStore({ plumbing: git });
231
-
232
- // Store a file -> returns a manifest (chunk list + metadata)
233
- const manifest = await cas.storeFile({
234
- filePath: './image.png',
235
- slug: 'my-image',
236
- encryptionKey: myKeyBuffer, // optional (32 bytes)
237
- });
238
-
239
- // Turn the manifest into a Git tree OID
240
- const treeOid = await cas.createTree({ manifest });
241
-
242
- // Restore later — get your bytes back, integrity-verified
243
- await cas.restoreFile({ manifest, outputPath: './restored.png' });
244
-
245
- // Read the manifest back from a tree OID
246
- const m = await cas.readManifest({ treeOid });
247
-
248
- // Lifecycle: inspect deletion impact, collect referenced chunks
249
- const { slug, chunksOrphaned } = await cas.inspectAsset({ treeOid });
250
- const { referenced, total } = await cas.collectReferencedChunks({ treeOids: [treeOid] });
251
-
252
- // v2.0.0: Compressed + passphrase-encrypted store
253
- const manifest2 = await cas.storeFile({
254
- filePath: './image.png',
255
- slug: 'my-image',
256
- passphrase: 'my secret passphrase',
257
- compression: { algorithm: 'gzip' },
258
- });
259
- ```
260
-
261
- ## CLI (git plugin)
262
-
263
- `git-cas` installs as a Git subcommand:
264
-
265
- ```bash
266
- # Store a file — prints manifest JSON
267
- git cas store ./image.png --slug my-image
268
-
269
- # Store and vault the tree OID (GC-safe)
270
- git cas store ./image.png --slug my-image --tree
271
-
272
- # Restore from a vault slug
273
- git cas restore --slug my-image --out ./restored.png
274
-
275
- # Restore from a direct tree OID
276
- git cas restore --oid <tree-oid> --out ./restored.png
277
-
278
- # Verify integrity without restoring
279
- git cas verify --slug my-image
280
-
281
- # Inspect manifest (interactive dashboard)
282
- git cas inspect --slug my-image
283
-
284
- # Vault management
285
- git cas vault init
286
- git cas vault list # TTY table
287
- git cas vault list --json # structured JSON
288
- git cas vault list --filter "photos/*" # glob filter
289
- git cas vault info my-image
290
- git cas vault remove my-image
291
- git cas vault history
292
-
293
- # Multi-recipient encryption
294
- git cas store ./secret.bin --slug shared \
295
- --recipient alice:./keys/alice.key \
296
- --recipient bob:./keys/bob.key --tree
297
- git cas recipient list shared
298
- git cas recipient add shared --label carol --key-file ./keys/carol.key --existing-key-file ./keys/alice.key
299
- git cas recipient remove shared --label bob
300
-
301
- # Key rotation (no re-encryption)
302
- git cas rotate --slug shared --old-key-file old.key --new-key-file new.key
303
- git cas rotate --slug shared --old-key-file old.key --new-key-file new.key --label alice
304
-
305
- # Vault passphrase rotation
306
- git cas vault rotate --old-passphrase old-secret --new-passphrase new-secret
307
-
308
- # Encrypted vault round-trip (passphrase via env var or --vault-passphrase flag)
309
- export GIT_CAS_PASSPHRASE="secret"
310
- git cas vault init
311
- git cas store ./secret.bin --slug vault-entry --tree
312
- git cas restore --slug vault-entry --out ./decrypted.bin
313
-
314
- # Compression, chunking, codec, concurrency
315
- git cas store ./data.bin --slug my-data --tree --gzip
316
- git cas store ./data.bin --slug my-data --tree --strategy cdc
317
- git cas store ./data.bin --slug my-data --tree --chunk-size 65536 --concurrency 4
318
- git cas store ./data.bin --slug my-data --tree --codec cbor
319
-
320
- # Restore with concurrency
321
- git cas restore --slug my-data --out ./data.bin --concurrency 4
322
-
323
- # JSON output on any command (for CI/scripting)
324
- git cas store ./data.bin --slug my-data --tree --json
325
- ```
326
-
327
- ### `.casrc` — Project Config File
328
-
329
- Place a `.casrc` JSON file at the repository root to set defaults for CLI flags.
330
- CLI flags always take precedence over `.casrc` values.
331
-
332
- ```json
333
- {
334
- "chunkSize": 65536,
335
- "strategy": "cdc",
336
- "concurrency": 4,
337
- "codec": "json",
338
- "compression": "gzip",
339
- "merkleThreshold": 500,
340
- "maxRestoreBufferSize": 1073741824,
341
- "cdc": {
342
- "minChunkSize": 8192,
343
- "targetChunkSize": 32768,
344
- "maxChunkSize": 131072
345
- }
346
- }
347
- ```
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 |
117
+
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.
348
119
 
349
120
  ## Documentation
350
121
 
351
- - [Guide](./GUIDE.md) — progressive walkthrough
352
- - [API Reference](./docs/API.md) — full method documentation
353
- - [Architecture](./ARCHITECTURE.md) — hexagonal design overview
354
- - [Security](./SECURITY.md) — crypto design and threat model
355
-
356
- ## When to use git-cas (and when not to)
357
-
358
- ### "I just want screenshots in my README"
359
-
360
- Use an **orphan branch**. Seriously. It's 5 git commands, zero dependencies, and GitHub renders the images inline. Google "git orphan branch assets" — that's all you need. git-cas is overkill for public images and demo GIFs.
361
-
362
- ### "I need encrypted secrets / large binaries / deduplicated assets in a Git repo"
363
-
364
- That's git-cas. The orphan branch gives you none of:
365
-
366
- | | Orphan branch | git-cas |
367
- |---|---|---|
368
- | **Encryption** | None — plaintext forever in history | AES-256-GCM + passphrase KDF + multi-recipient + key rotation |
369
- | **Large files** | Bloats `git clone` for everyone | Chunked, restored on demand |
370
- | **Dedup** | None | Chunk-level content addressing |
371
- | **Integrity** | Git SHA-1 | SHA-256 per chunk + GCM auth tag |
372
- | **Lifecycle** | `git rm` (still in reflog) | Vault with audit trail + `git gc` reclaims |
373
- | **Compression** | None | gzip before encryption |
374
-
375
- ### "Why not Git LFS?"
376
-
377
- Because sometimes you want the Git object database to be the store — deterministic, content-addressed, locally replicable, commit-addressable — with no external server, no LFS endpoint, and no second system to manage.
378
-
379
- If your team uses GitHub and needs file locking + web UI previews, use LFS. If you want encrypted, self-contained, server-free binary storage that travels with `git clone`, use git-cas.
380
-
381
- ---
382
-
383
- > _THIS HASH’LL KNOCK YOUR SHAs OFF! FIRST COMMIT’S FREE, MAN._
384
-
385
- <img width="420" alt="dhtux" src="https://github.com/user-attachments/assets/f2c13357-22c7-4685-83ce-7eccd747e2fe" />
386
-
387
- ---
388
-
389
- ## License
390
-
391
- Apache-2.0
392
- Copyright © 2026 [James Ross](https://github.com/flyingrobots)
122
+ - **[Guide](./GUIDE.md)**: Productive path, library/CLI usage, vault workflows, and the feature coverage map.
123
+ - **[Advanced Guide](./ADVANCED_GUIDE.md)**: CDC internals, direct service contracts, security limits, operational tooling, and performance baselines.
124
+ - **[Architecture](./ARCHITECTURE.md)**: The authoritative system map — Facade, Domain, Ports, and Adapters.
125
+ - **[Extending](./docs/EXTENDING.md)**: Custom adapter contracts and extension-point checklist.
126
+ - **[Store/Restore Pipeline](./docs/STORE_RESTORE_PIPELINE.md)**: Maintainer state machines for byte storage, restore, tree publication, and vault boundaries.
127
+ - **[Vault Internals](./docs/VAULT_INTERNALS.md)**: Maintainer map for vault persistence, caching, codecs, privacy indexing, key verification, and retry policy.
128
+ - **[Security](./SECURITY.md)**: Threat models, trust boundaries, and encryption internals.
129
+ - **[Agent API](./docs/API.md)**: JSONL agent protocol for CI/CD automation.
130
+ - **[Workflow](https://github.com/git-stunts/git-cas/blob/main/WORKFLOW.md)**: Repo work doctrine, cycles, and invariants.
131
+ - **[Contributing](https://github.com/git-stunts/git-cas/blob/main/CONTRIBUTING.md)**, **[Code of Conduct](./CODE_OF_CONDUCT.md)**, and **[Support](./SUPPORT.md)**: Project participation and help paths.
132
+ - **[v6.0.0 Release Notes](./docs/releases/v6.0.0.md)**: Major-release summary, upgrade call-to-action, and publication notes.
133
+ - **[Upgrading](./UPGRADING.md)**: Migration guide for v5 → v6.
134
+ - **[Changelog](./CHANGELOG.md)**: Version history and migration notes.
393
135
 
394
136
  ---
395
137
 
396
- <p align="center">
397
- <sub>Built by <a href="https://github.com/flyingrobots">FLYING ROBOTS</a></sub>
398
- </p>
138
+ Built with terminal ambition by [FLYING ROBOTS](https://github.com/flyingrobots)