@git-stunts/git-cas 5.3.2 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ADVANCED_GUIDE.md +1006 -0
- package/ARCHITECTURE.md +514 -0
- package/CHANGELOG.md +393 -5
- package/CODE_OF_CONDUCT.md +33 -0
- package/GUIDE.md +872 -0
- package/README.md +219 -325
- package/SECURITY.md +993 -0
- package/SUPPORT.md +54 -0
- package/UPGRADING.md +299 -0
- package/bin/actions.js +70 -21
- package/bin/agent/cli.js +51 -0
- package/bin/agent/commands/doctor.js +99 -0
- package/bin/agent/commands/index.js +1489 -0
- package/bin/agent/input.js +619 -0
- package/bin/agent/passphrase-source.js +123 -0
- package/bin/agent/protocol.js +193 -0
- package/bin/build-version.js +64 -0
- package/bin/credentials.js +425 -0
- package/bin/git-cas.js +595 -449
- package/bin/passphrase-source.js +266 -0
- package/bin/restore-output-target.js +28 -0
- package/bin/ui/blocks/asset-card.js +109 -0
- package/bin/ui/blocks/health-dashboard.js +149 -0
- package/bin/ui/blocks/heatmap-block.js +67 -0
- package/bin/ui/blocks/merkle-explorer.js +163 -0
- package/bin/ui/blocks/operation-feed.js +176 -0
- package/bin/ui/blocks/wizard-block.js +168 -0
- package/bin/ui/components/short-sha.js +36 -0
- package/bin/ui/context.js +56 -1
- package/bin/ui/dashboard-cmds.js +1578 -13
- package/bin/ui/dashboard-view.js +612 -145
- package/bin/ui/dashboard.js +998 -214
- package/bin/ui/encryption-card.js +69 -26
- package/bin/ui/heatmap.js +26 -54
- package/bin/ui/history-timeline.js +51 -19
- package/bin/ui/manifest-view.js +115 -60
- package/bin/ui/merkle-dag.js +83 -0
- package/bin/ui/progress.js +15 -9
- package/bin/ui/repo-treemap.js +328 -0
- package/bin/ui/shaders/bak-sneppen.js +180 -0
- package/bin/ui/shaders/fractal-zoom.js +99 -0
- package/bin/ui/shaders/merkle-tree.js +142 -0
- package/bin/ui/shaders/organic-flow.js +96 -0
- package/bin/ui/shaders/phase-portrait.js +93 -0
- package/bin/ui/store-wizard.js +296 -0
- package/bin/ui/theme.js +155 -0
- package/bin/ui/vault-report.js +495 -0
- package/build-info.json +4 -0
- package/docs/API.md +2224 -0
- package/docs/ENCRYPTION_MODES.md +33 -0
- package/docs/EXTENDING.md +174 -0
- package/docs/STORE_RESTORE_PIPELINE.md +199 -0
- package/docs/THREAT_MODEL.md +269 -0
- package/docs/VAULT_INTERNALS.md +251 -0
- package/docs/WALKTHROUGH.md +1868 -0
- package/docs/demo.gif +0 -0
- package/docs/releases/v6.0.0.md +104 -0
- package/examples/README.md +260 -0
- package/index.d.ts +208 -65
- package/index.js +163 -54
- package/package.json +35 -6
- package/scripts/migrate-encryption.js +680 -0
- package/src/domain/bytes/ByteLayout.js +96 -0
- package/src/domain/encoding/base64.js +91 -0
- package/src/domain/encoding/hex.js +14 -0
- package/src/domain/encoding/utf8.js +123 -0
- package/src/domain/encryption/schemes.js +132 -0
- package/src/domain/errors/CannotRemoveLastRecipientError.js +10 -0
- package/src/domain/errors/CasError.d.ts +28 -0
- package/src/domain/errors/CasError.js +43 -6
- package/src/domain/errors/Codes.js +54 -0
- package/src/domain/errors/DekUnwrapFailedError.js +10 -0
- package/src/domain/errors/GitError.js +10 -0
- package/src/domain/errors/GitPlumbingInitializationError.js +10 -0
- package/src/domain/errors/IntegrityError.js +10 -0
- package/src/domain/errors/InvalidChunkingStrategyError.js +10 -0
- package/src/domain/errors/InvalidOidError.js +10 -0
- package/src/domain/errors/InvalidOptionsError.js +10 -0
- package/src/domain/errors/ManifestIntegrityError.js +10 -0
- package/src/domain/errors/ManifestNotFoundError.js +10 -0
- package/src/domain/errors/NoMatchingRecipientError.js +10 -0
- package/src/domain/errors/PersistenceCapabilityRequiredError.js +10 -0
- package/src/domain/errors/PortNotImplementedError.js +10 -0
- package/src/domain/errors/RecipientAlreadyExistsError.js +10 -0
- package/src/domain/errors/RecipientNotFoundError.js +10 -0
- package/src/domain/errors/RestoreTooLargeError.js +10 -0
- package/src/domain/errors/RotationNotSupportedError.js +10 -0
- package/src/domain/errors/createCasError.js +68 -0
- package/src/domain/errors/index.js +20 -0
- package/src/domain/helpers/buildKdfMetadata.js +4 -2
- package/src/domain/helpers/codecBytes.js +34 -0
- package/src/domain/helpers/gitRefErrors.js +84 -0
- package/src/domain/helpers/scryptMaxmem.js +22 -0
- package/src/domain/outcomes/RestoreFailure.js +15 -0
- package/src/domain/outcomes/RestoreOutcome.js +11 -0
- package/src/domain/outcomes/RestoreSuccess.js +34 -0
- package/src/domain/outcomes/StoreFailure.js +15 -0
- package/src/domain/outcomes/StoreOutcome.js +11 -0
- package/src/domain/outcomes/StoreSuccess.js +17 -0
- package/src/domain/schemas/ManifestSchema.d.ts +40 -9
- package/src/domain/schemas/ManifestSchema.js +67 -13
- package/src/domain/services/CasService.d.ts +123 -38
- package/src/domain/services/CasService.js +298 -834
- package/src/domain/services/ChunkRepository.js +230 -0
- package/src/domain/services/CompressionStreams.js +72 -0
- package/src/domain/services/ConvergentEncryption.js +128 -0
- package/src/domain/services/GitTreeBuilder.js +86 -0
- package/src/domain/services/IntegrityVerifier.js +199 -0
- package/src/domain/services/KeyResolver.js +49 -42
- package/src/domain/services/ManifestDiff.js +56 -0
- package/src/domain/services/ManifestRepository.js +286 -0
- package/src/domain/services/PrefetchWindow.js +48 -0
- package/src/domain/services/RecipientService.js +157 -0
- package/src/domain/services/RedactingObservability.js +169 -0
- package/src/domain/services/RestorePipeline.js +68 -0
- package/src/domain/services/StorePipeline.js +201 -0
- package/src/domain/services/VaultKeyVerifier.js +101 -0
- package/src/domain/services/VaultMetadataCodec.js +206 -0
- package/src/domain/services/VaultMutationRetryPolicy.js +105 -0
- package/src/domain/services/VaultPersistence.js +410 -0
- package/src/domain/services/VaultPrivacyIndex.js +191 -0
- package/src/domain/services/VaultService.js +749 -251
- package/src/domain/services/VaultStateCache.js +225 -0
- package/src/domain/services/VaultTreeCodec.js +121 -0
- package/src/domain/services/rotateVaultPassphrase.js +37 -20
- package/src/domain/strategies/Aad.js +39 -0
- package/src/domain/strategies/FramedRecordCodec.js +204 -0
- package/src/domain/strategies/RestoreCompressed.js +40 -0
- package/src/domain/strategies/RestoreConvergent.js +44 -0
- package/src/domain/strategies/RestoreFramed.js +55 -0
- package/src/domain/strategies/RestorePlain.js +37 -0
- package/src/domain/strategies/RestoreStrategy.js +35 -0
- package/src/domain/strategies/RestoreWhole.js +135 -0
- package/src/domain/strategies/StoreConvergent.js +28 -0
- package/src/domain/strategies/StoreFramed.js +39 -0
- package/src/domain/strategies/StorePlain.js +20 -0
- package/src/domain/strategies/StoreStrategy.js +61 -0
- package/src/domain/strategies/StoreWhole.js +34 -0
- package/src/domain/value-objects/Chunk.js +1 -2
- package/src/domain/value-objects/EncryptionMetadata.js +87 -0
- package/src/domain/value-objects/Manifest.d.ts +40 -4
- package/src/domain/value-objects/Manifest.js +61 -20
- package/src/domain/value-objects/Oid.js +45 -0
- package/src/domain/value-objects/Slug.js +124 -0
- package/src/domain/value-objects/StoreEncryptionConfig.js +114 -0
- package/src/helpers/aesGcmMeta.js +55 -0
- package/src/helpers/canonicalBase64.js +1 -0
- package/src/helpers/kdfPolicy.js +194 -0
- package/src/infrastructure/adapters/BunCryptoAdapter.js +124 -8
- package/src/infrastructure/adapters/FileIOHelper.js +178 -13
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +235 -42
- package/src/infrastructure/adapters/GitPlumbingFactoryAdapter.js +62 -0
- package/src/infrastructure/adapters/GitRefAdapter.js +19 -6
- package/src/infrastructure/adapters/NodeCompressionAdapter.js +64 -0
- package/src/infrastructure/adapters/NodeCryptoAdapter.js +130 -10
- package/src/infrastructure/adapters/WebCryptoAdapter.js +187 -77
- package/src/infrastructure/chunkers/CdcChunker.js +53 -19
- package/src/infrastructure/chunkers/FixedChunker.js +15 -7
- package/src/infrastructure/chunkers/resolveChunker.js +3 -1
- package/src/infrastructure/codecs/CborCodec.js +3 -3
- package/src/infrastructure/codecs/JsonCodec.js +5 -5
- package/src/infrastructure/createGitPlumbing.js +22 -0
- package/src/package-version.js +1 -0
- package/src/ports/ChunkingPort.js +3 -3
- package/src/ports/CodecPort.js +4 -4
- package/src/ports/CompressionPort.js +57 -0
- package/src/ports/CryptoPort.js +138 -50
- package/src/ports/GitPersistencePort.js +32 -2
- package/src/ports/GitPlumbingFactoryPort.js +16 -0
- package/src/ports/GitRefPort.js +1 -1
- package/src/types/ambient.d.ts +10 -5
- package/test/CONVENTIONS.md +94 -0
- package/test/cycles/README.md +13 -0
package/SUPPORT.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Support
|
|
2
|
+
|
|
3
|
+
This project is maintained as an open-source library and CLI. Support is
|
|
4
|
+
best-effort unless a separate commercial agreement exists.
|
|
5
|
+
|
|
6
|
+
## Maintainer Contact
|
|
7
|
+
|
|
8
|
+
Primary maintainer: [James Ross](mailto:james@flyingrobots.dev).
|
|
9
|
+
|
|
10
|
+
Use GitHub issues for normal bugs, documentation corrections, and feature
|
|
11
|
+
requests. Use private email for conduct reports, suspected vulnerabilities, or
|
|
12
|
+
anything that should not be posted publicly.
|
|
13
|
+
|
|
14
|
+
## Before Opening an Issue
|
|
15
|
+
|
|
16
|
+
Check these documents first:
|
|
17
|
+
|
|
18
|
+
- [README.md](./README.md) for quick start and feature overview
|
|
19
|
+
- [GUIDE.md](./GUIDE.md) for normal CLI and library workflows
|
|
20
|
+
- [ADVANCED_GUIDE.md](./ADVANCED_GUIDE.md) for internals, security limits, and
|
|
21
|
+
direct service construction
|
|
22
|
+
- [docs/EXTENDING.md](./docs/EXTENDING.md) for custom adapters and extension
|
|
23
|
+
points
|
|
24
|
+
- [SECURITY.md](./SECURITY.md) for security boundaries and vulnerability
|
|
25
|
+
handling
|
|
26
|
+
- [CHANGELOG.md](./CHANGELOG.md) and [UPGRADING.md](./UPGRADING.md) for release
|
|
27
|
+
and migration notes
|
|
28
|
+
|
|
29
|
+
## What To Include
|
|
30
|
+
|
|
31
|
+
For bugs or usage questions, include:
|
|
32
|
+
|
|
33
|
+
- `git-cas` version
|
|
34
|
+
- runtime and version (`node --version`, Bun, or Deno)
|
|
35
|
+
- operating system
|
|
36
|
+
- the exact command or API call
|
|
37
|
+
- the relevant manifest/vault shape with secrets removed
|
|
38
|
+
- full error output, including `CasError.code` and `meta` when available
|
|
39
|
+
- whether the repository is bare or worktree-backed
|
|
40
|
+
|
|
41
|
+
Do not paste passphrases, raw encryption keys, key files, private vault
|
|
42
|
+
contents, or unreduced proprietary artifacts into public issues.
|
|
43
|
+
|
|
44
|
+
## Security Reports
|
|
45
|
+
|
|
46
|
+
Do not open public issues for suspected vulnerabilities. Use the private
|
|
47
|
+
reporting path in [SECURITY.md](./SECURITY.md) and include a minimal
|
|
48
|
+
reproduction, impact assessment, affected versions, and any known mitigations.
|
|
49
|
+
|
|
50
|
+
## Expected Response
|
|
51
|
+
|
|
52
|
+
Issues with clear reproductions and release impact are handled first. Feature
|
|
53
|
+
requests should describe the user workflow, the current friction, and why the
|
|
54
|
+
existing facade, CLI, agent, or extension points cannot cover the need.
|
package/UPGRADING.md
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# Upgrading to git-cas v6.0.0
|
|
2
|
+
|
|
3
|
+
v6.0.0 is a major release that simplifies the encryption model, hardens security defaults, and cleans up the architecture. This guide covers every breaking change and what you need to do.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
If you have an existing vault with encrypted assets:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# See what needs migration (safe — no changes made)
|
|
11
|
+
npm run upgrade
|
|
12
|
+
|
|
13
|
+
# Apply the migration using stdin for the content passphrase
|
|
14
|
+
printf '%s\n' '<your-content-passphrase>' | npm run upgrade -- --execute --passphrase-file -
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
If you only use the library API (no vault), skip to [API Changes](#api-changes).
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Critical Breaking Changes
|
|
22
|
+
|
|
23
|
+
### `restoreFile()` Requires `baseDirectory`
|
|
24
|
+
|
|
25
|
+
`restoreFile()` now requires an explicit directory boundary. This prevents a
|
|
26
|
+
repository-controlled output path from writing outside the directory your
|
|
27
|
+
application intended to restore into.
|
|
28
|
+
|
|
29
|
+
v5 accepted an output path by itself:
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
await cas.restoreFile({ manifest, outputPath: './restored.bin' });
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
v6 requires the restore boundary:
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
await cas.restoreFile({
|
|
39
|
+
manifest,
|
|
40
|
+
outputPath: './restored.bin',
|
|
41
|
+
baseDirectory: process.cwd(),
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Use `process.cwd()` only when the caller is a trusted local CLI or script. Server
|
|
46
|
+
and automation contexts should pass an application-controlled restore directory,
|
|
47
|
+
for example a job workspace or tenant-scoped artifact directory.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Encryption Scheme Simplification
|
|
52
|
+
|
|
53
|
+
### What Changed
|
|
54
|
+
|
|
55
|
+
v5 had 5 encryption scheme identifiers. v6 has 3:
|
|
56
|
+
|
|
57
|
+
| v5 Scheme | v6 Scheme | Migration |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| `whole-v1` | `whole` | **Re-encryption required** (v1 had no AAD) |
|
|
60
|
+
| `whole-v2` | `whole` | Rename only (already had AAD) |
|
|
61
|
+
| `framed-v1` | `framed` | **Re-encryption required** (v1 had no AAD) |
|
|
62
|
+
| `framed-v2` | `framed` | Rename only (already had AAD) |
|
|
63
|
+
| `convergent-v1` | `convergent` | Rename only |
|
|
64
|
+
|
|
65
|
+
### Why
|
|
66
|
+
|
|
67
|
+
Version suffixes on scheme names were compatibility cruft. AAD (Additional Authenticated Data) binding is now unconditional — every `whole` and `framed` manifest binds the slug to the ciphertext, preventing cross-manifest blob substitution attacks.
|
|
68
|
+
|
|
69
|
+
### What Happens if You Don't Migrate
|
|
70
|
+
|
|
71
|
+
Any call to `readManifest()`, `restore()`, `restoreFile()`, or `restoreStream()` on a v5 manifest will throw:
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
CasError: Legacy encryption scheme "framed-v1" is no longer supported.
|
|
75
|
+
Run scripts/migrate-encryption.js to upgrade this manifest.
|
|
76
|
+
[code: LEGACY_SCHEME]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### How to Migrate
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Dry-run: see what needs migration
|
|
83
|
+
npm run upgrade
|
|
84
|
+
|
|
85
|
+
# Execute: migrate all vault entries using stdin for the content passphrase
|
|
86
|
+
printf '%s\n' '<passphrase>' | npm run upgrade -- --execute --passphrase-file -
|
|
87
|
+
|
|
88
|
+
# Or read the content passphrase from a file
|
|
89
|
+
npm run upgrade -- --execute --passphrase-file ./content-passphrase.txt
|
|
90
|
+
|
|
91
|
+
# Or migrate entries encrypted with a raw 32-byte key
|
|
92
|
+
npm run upgrade -- --execute --key-file ./asset.key
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The migration script has two modes:
|
|
96
|
+
|
|
97
|
+
- **Fast mode** (v2 schemes + convergent): renames the scheme in the manifest metadata. No re-encryption. Seconds.
|
|
98
|
+
- **Full mode** (v1 schemes): restores through the legacy pipeline (decrypts without AAD), then re-stores with the current scheme (encrypts with AAD). Requires exactly one content credential source: `--passphrase-file <path>`, `--key-file`, or inline `--passphrase` for compatibility.
|
|
99
|
+
|
|
100
|
+
Privacy-enabled vaults need the vault encryption key to list and update slugs.
|
|
101
|
+
If the vault passphrase differs from the content passphrase, pass
|
|
102
|
+
`--vault-passphrase-file`, `--vault-key-file`, or inline `--vault-passphrase`
|
|
103
|
+
for compatibility. When no explicit vault key option is provided, the content
|
|
104
|
+
passphrase from `--passphrase-file` or `--passphrase` is reused for the privacy
|
|
105
|
+
vault.
|
|
106
|
+
|
|
107
|
+
Inline `--passphrase` and `--vault-passphrase` remain accepted, but they print a
|
|
108
|
+
warning because command-line arguments can leak through shell history, process
|
|
109
|
+
listings, CI logs, and terminal transcripts.
|
|
110
|
+
|
|
111
|
+
Recipient-encrypted v1 manifests are not automatically full-migrated because
|
|
112
|
+
preserving recipient access requires the original recipient key set. Re-store
|
|
113
|
+
those assets with current recipients after restoring them with a matching
|
|
114
|
+
recipient key.
|
|
115
|
+
|
|
116
|
+
Original blobs are never deleted — Git's garbage collection only removes unreferenced objects after `git gc`.
|
|
117
|
+
|
|
118
|
+
### Vault Passphrase Verifier Migration
|
|
119
|
+
|
|
120
|
+
New encrypted vaults write `encryption.verifier` into `.vault.json`. The
|
|
121
|
+
verifier lets `git-cas` reject a wrong vault passphrase even when the encrypted
|
|
122
|
+
vault has no entries yet.
|
|
123
|
+
|
|
124
|
+
Existing encrypted vaults from older release candidates may not have verifier
|
|
125
|
+
metadata. They continue to work. The next vault write that provides the vault
|
|
126
|
+
encryption key, such as:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
printf '%s\n' '<vault-passphrase>' \
|
|
130
|
+
| git-cas store ./asset.bin --tree --slug assets/example --vault-passphrase-file -
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
adds the verifier automatically. If you are maintaining custom tooling that
|
|
134
|
+
derives vault keys manually, call `verifyVaultKey({ encryptionKey })` after
|
|
135
|
+
derivation. A result with `requiresMigration: true` means the vault predates the
|
|
136
|
+
verifier and the next keyed vault write will add it.
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Default Scheme Changes
|
|
141
|
+
|
|
142
|
+
### What Changed
|
|
143
|
+
|
|
144
|
+
| Scenario | v5 Default | v6 Default |
|
|
145
|
+
|---|---|---|
|
|
146
|
+
| CDC chunking + encryption | `framed-v1` | `convergent` |
|
|
147
|
+
| Fixed chunking + encryption | `framed-v1` | `framed` |
|
|
148
|
+
| Explicit `whole` | `whole-v1` | `whole` |
|
|
149
|
+
|
|
150
|
+
### What This Means
|
|
151
|
+
|
|
152
|
+
- **Convergent encryption** is now the default when using CDC chunking with encryption. This means deduplication works even with encrypted content — identical plaintext chunks produce identical ciphertext.
|
|
153
|
+
- If you were explicitly passing `encryption: { scheme: 'framed-v1' }`, change to `encryption: { scheme: 'framed' }`.
|
|
154
|
+
- If you were relying on the old default and want to keep framed encryption with CDC, pass `encryption: { scheme: 'framed' }` explicitly.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## API Changes
|
|
159
|
+
|
|
160
|
+
### Byte Types
|
|
161
|
+
|
|
162
|
+
Public byte-oriented APIs now use `Uint8Array` instead of Node-specific
|
|
163
|
+
`Buffer` types:
|
|
164
|
+
|
|
165
|
+
- `store({ source })` expects `AsyncIterable<Uint8Array>`.
|
|
166
|
+
- `restore()` returns `{ buffer: Uint8Array, bytesWritten }`.
|
|
167
|
+
- `restoreStream()` yields `Uint8Array` chunks.
|
|
168
|
+
- Port implementations for crypto, compression, chunking, persistence, and
|
|
169
|
+
codecs should accept and return `Uint8Array`.
|
|
170
|
+
|
|
171
|
+
Node callers can still pass `Buffer` values because `Buffer` is a
|
|
172
|
+
`Uint8Array` subclass. Code that calls `buffer.equals(...)` on restore results
|
|
173
|
+
should compare with `Buffer.from(buffer).equals(...)` or use a runtime-neutral
|
|
174
|
+
byte comparison helper.
|
|
175
|
+
|
|
176
|
+
### CasService Constructor (Library Users)
|
|
177
|
+
|
|
178
|
+
**If you use `ContentAddressableStore` (the facade):** No changes needed. The facade handles all defaults.
|
|
179
|
+
|
|
180
|
+
**If you use `CasService` directly:**
|
|
181
|
+
|
|
182
|
+
```diff
|
|
183
|
+
- const service = new CasService({
|
|
184
|
+
- persistence, codec, crypto, observability,
|
|
185
|
+
- });
|
|
186
|
+
|
|
187
|
+
+ import { FixedChunker, NodeCompressionAdapter } from '@git-stunts/git-cas';
|
|
188
|
+
+
|
|
189
|
+
+ const service = new CasService({
|
|
190
|
+
+ persistence, codec, crypto, observability,
|
|
191
|
+
+ chunker: new FixedChunker({ chunkSize: 256 * 1024 }),
|
|
192
|
+
+ compressionAdapter: new NodeCompressionAdapter(),
|
|
193
|
+
+ });
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
`chunker` and `compressionAdapter` are now **required**. They were previously optional with internal defaults — the defaults moved to the facade layer to keep the domain service free of infrastructure imports.
|
|
197
|
+
|
|
198
|
+
### New CryptoPort Methods
|
|
199
|
+
|
|
200
|
+
If you implement a custom `CryptoPort`, you must add these methods:
|
|
201
|
+
|
|
202
|
+
```js
|
|
203
|
+
// HMAC-SHA256 (used by vault privacy mode)
|
|
204
|
+
hmacSha256(key, data) { /* return 32-byte Uint8Array or Promise<Uint8Array> */ }
|
|
205
|
+
|
|
206
|
+
// Deterministic encryption (used by convergent encryption)
|
|
207
|
+
encryptBufferWithNonce(buffer, key, nonce) { /* return { buf, tag } */ }
|
|
208
|
+
decryptBufferWithNonceTag(buffer, key, nonce, tag) { /* return Uint8Array */ }
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
The shipped adapters (`NodeCryptoAdapter`, `BunCryptoAdapter`, `WebCryptoAdapter`) already implement these.
|
|
212
|
+
|
|
213
|
+
### Encryption Metadata Schema
|
|
214
|
+
|
|
215
|
+
Encrypted manifests now **require** the `scheme` field. Pre-v5.2 manifests that omitted `scheme` will fail schema validation. The migration script handles this.
|
|
216
|
+
|
|
217
|
+
### New Manifest Fields
|
|
218
|
+
|
|
219
|
+
- **`formatVersion`**: Semver string (e.g., `"6.0.0"`) stamped into new manifests. Identifies which library version wrote the manifest. Optional on read — old manifests without it still parse.
|
|
220
|
+
- **`manifestHash`**: SHA-256 of the codec-encoded manifest content. Verified on read. Catches corruption. Optional on read.
|
|
221
|
+
|
|
222
|
+
### New Exports
|
|
223
|
+
|
|
224
|
+
```js
|
|
225
|
+
// Standalone manifest diffing
|
|
226
|
+
import { diffManifests } from '@git-stunts/git-cas';
|
|
227
|
+
|
|
228
|
+
// Or as a static method
|
|
229
|
+
import ContentAddressableStore from '@git-stunts/git-cas';
|
|
230
|
+
ContentAddressableStore.diffManifests(oldManifest, newManifest);
|
|
231
|
+
|
|
232
|
+
// Compression port for custom adapters
|
|
233
|
+
import { CompressionPort, NodeCompressionAdapter } from '@git-stunts/git-cas';
|
|
234
|
+
|
|
235
|
+
// Scheme constants
|
|
236
|
+
import { SCHEME_WHOLE, SCHEME_FRAMED, SCHEME_CONVERGENT } from '@git-stunts/git-cas';
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Behavioral Changes
|
|
240
|
+
|
|
241
|
+
| Change | Impact |
|
|
242
|
+
|---|---|
|
|
243
|
+
| Plaintext + gzip restore now streams | Lower memory usage. Should be transparent. |
|
|
244
|
+
| AAD always on for `whole` and `framed` | Cannot opt out. v1-style no-AAD is gone. |
|
|
245
|
+
| Manifest integrity hash verified on read | Corrupted manifests that previously loaded will now throw `MANIFEST_INTEGRITY_ERROR`. |
|
|
246
|
+
| KDF policy enforced in `deriveKey()` | Dangerously weak params (e.g., 1 PBKDF2 iteration) now throw `KDF_POLICY_VIOLATION`. |
|
|
247
|
+
| Concurrency capped at 64 | Was unbounded. Unlikely to affect real usage. |
|
|
248
|
+
| frameBytes capped at 64 MiB | Was unbounded. Unlikely to affect real usage. |
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## New Features (Non-Breaking)
|
|
253
|
+
|
|
254
|
+
These are new capabilities that don't require migration:
|
|
255
|
+
|
|
256
|
+
- **Convergent encryption** — CDC dedup works with encryption
|
|
257
|
+
- **FastCDC dual-mask normalization** — tighter chunk size distribution (default on)
|
|
258
|
+
- **Manifest integrity hash** — SHA-256 checksum on manifests
|
|
259
|
+
- **Vault privacy mode** — HMAC-hashed slug names
|
|
260
|
+
- **Manifest diffing** — compare two manifests by chunk digest
|
|
261
|
+
- **Parallel chunk restore** — prefetch window for concurrent reads
|
|
262
|
+
- **CompressionPort** — pluggable compression (shipped: gzip via NodeCompressionAdapter)
|
|
263
|
+
- **ConvergentEncryption service** — extracted domain service
|
|
264
|
+
- **PrefetchWindow** — ordered parallel read primitive
|
|
265
|
+
- **Scheme truth module** — `src/domain/encryption/schemes.js`
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## Troubleshooting
|
|
270
|
+
|
|
271
|
+
### `LEGACY_SCHEME` error on restore
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
CasError: Legacy encryption scheme "whole-v1" is no longer supported.
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Run `printf '%s\n' '<pass>' | npm run upgrade -- --execute --passphrase-file -`
|
|
278
|
+
or
|
|
279
|
+
`npm run upgrade -- --execute --key-file <path>` to migrate.
|
|
280
|
+
|
|
281
|
+
### `KDF_POLICY_VIOLATION` on deriveKey
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
CasError: deriveKey KDF field "iterations" must be between 100000 and 2000000
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
v6 enforces minimum KDF parameters. Increase iterations to at least 100,000 (PBKDF2) or cost to at least 16,384 (scrypt).
|
|
288
|
+
|
|
289
|
+
### `MANIFEST_INTEGRITY_ERROR` on readManifest
|
|
290
|
+
|
|
291
|
+
```
|
|
292
|
+
CasError: Manifest integrity check failed: hash mismatch
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
The manifest blob was corrupted or tampered with after storage. The original data may still be recoverable from Git's object database if the corruption was in the tree, not the blob.
|
|
296
|
+
|
|
297
|
+
### Constructor throws "chunker is required"
|
|
298
|
+
|
|
299
|
+
You're using `CasService` directly. Either switch to the `ContentAddressableStore` facade (recommended) or inject a `chunker` and `compressionAdapter` manually. See [API Changes](#casservice-constructor-library-users).
|
package/bin/actions.js
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
* CLI error handler — wraps command actions with structured error output.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
/** @typedef {{ code?: string, message?: string }} ErrorLike */
|
|
5
|
+
/** @typedef {{ code?: string, documentationUrl?: string, message?: string }} ErrorLike */
|
|
6
|
+
/** @typedef {{ code?: string, documentationUrl?: string, message: string }} ErrorPayload */
|
|
6
7
|
|
|
7
8
|
/** @type {Readonly<Record<string, string>>} */
|
|
8
9
|
const HINTS = {
|
|
9
|
-
|
|
10
|
+
INVALID_INPUT: 'Check the agent command name and required input fields',
|
|
11
|
+
MISSING_KEY:
|
|
12
|
+
'Provide --key-file, --vault-passphrase, --vault-passphrase-file, or --os-keychain-target',
|
|
10
13
|
MANIFEST_NOT_FOUND: 'Verify the tree OID contains a manifest',
|
|
11
14
|
VAULT_ENTRY_NOT_FOUND: "Run 'git cas vault list' to see available entries",
|
|
12
15
|
VAULT_ENTRY_EXISTS: 'Use --force to overwrite',
|
|
@@ -16,7 +19,10 @@ const HINTS = {
|
|
|
16
19
|
RECIPIENT_NOT_FOUND: 'No recipient with that label exists in the manifest',
|
|
17
20
|
RECIPIENT_ALREADY_EXISTS: 'A recipient with that label already exists',
|
|
18
21
|
CANNOT_REMOVE_LAST_RECIPIENT: 'At least one recipient must remain in the manifest',
|
|
19
|
-
ROTATION_NOT_SUPPORTED:
|
|
22
|
+
ROTATION_NOT_SUPPORTED:
|
|
23
|
+
'Key rotation requires envelope encryption — store with --recipient first',
|
|
24
|
+
VAULT_METADATA_INVALID: 'Initialize an encrypted vault before rotating its passphrase',
|
|
25
|
+
VAULT_CONFLICT: 'Retry the vault rotation after concurrent vault updates settle',
|
|
20
26
|
};
|
|
21
27
|
|
|
22
28
|
/**
|
|
@@ -26,20 +32,55 @@ const HINTS = {
|
|
|
26
32
|
* @param {boolean} json - Whether to output JSON.
|
|
27
33
|
*/
|
|
28
34
|
function writeError(err, json) {
|
|
29
|
-
const
|
|
30
|
-
const code = typeof err?.code === 'string' ? err.code : undefined;
|
|
35
|
+
const payload = toErrorPayload(err);
|
|
31
36
|
if (json) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
writeJsonError(payload);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
writeTextError(payload);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {ErrorLike} err
|
|
45
|
+
* @returns {ErrorPayload}
|
|
46
|
+
*/
|
|
47
|
+
function toErrorPayload(err) {
|
|
48
|
+
return {
|
|
49
|
+
message: err?.message ?? String(err),
|
|
50
|
+
code: typeof err?.code === 'string' ? err.code : undefined,
|
|
51
|
+
documentationUrl: typeof err?.documentationUrl === 'string'
|
|
52
|
+
? err.documentationUrl
|
|
53
|
+
: undefined,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {ErrorPayload} payload
|
|
59
|
+
*/
|
|
60
|
+
function writeJsonError({ code, documentationUrl, message }) {
|
|
61
|
+
/** @type {{ error: string, code?: string, documentationUrl?: string }} */
|
|
62
|
+
const obj = { error: message };
|
|
63
|
+
if (code) {
|
|
64
|
+
obj.code = code;
|
|
65
|
+
}
|
|
66
|
+
if (documentationUrl) {
|
|
67
|
+
obj.documentationUrl = documentationUrl;
|
|
68
|
+
}
|
|
69
|
+
process.stderr.write(`${JSON.stringify(obj)}\n`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {ErrorPayload} payload
|
|
74
|
+
*/
|
|
75
|
+
function writeTextError({ code, documentationUrl, message }) {
|
|
76
|
+
const prefix = code ? `error [${code}]: ` : 'error: ';
|
|
77
|
+
process.stderr.write(`${prefix}${message}\n`);
|
|
78
|
+
if (documentationUrl) {
|
|
79
|
+
process.stderr.write(`docs: ${documentationUrl}\n`);
|
|
80
|
+
}
|
|
81
|
+
const hint = getHint(code);
|
|
82
|
+
if (hint) {
|
|
83
|
+
process.stderr.write(`hint: ${hint}\n`);
|
|
43
84
|
}
|
|
44
85
|
}
|
|
45
86
|
|
|
@@ -62,7 +103,9 @@ function getHint(code) {
|
|
|
62
103
|
* @returns {Promise<void>}
|
|
63
104
|
*/
|
|
64
105
|
function defaultDelay(ms) {
|
|
65
|
-
return new Promise((resolve) => {
|
|
106
|
+
return new Promise((resolve) => {
|
|
107
|
+
setTimeout(resolve, ms);
|
|
108
|
+
});
|
|
66
109
|
}
|
|
67
110
|
|
|
68
111
|
/**
|
|
@@ -73,10 +116,16 @@ function defaultDelay(ms) {
|
|
|
73
116
|
* @param {{ delay?: (ms: number) => Promise<void>, setExitCode?: (code: number) => void }} [options] - Injectable dependencies.
|
|
74
117
|
* @returns {(...args: any[]) => Promise<void>} Wrapped action.
|
|
75
118
|
*/
|
|
76
|
-
export function runAction(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
119
|
+
export function runAction(
|
|
120
|
+
fn,
|
|
121
|
+
getJson,
|
|
122
|
+
{
|
|
123
|
+
delay = defaultDelay,
|
|
124
|
+
setExitCode = (code) => {
|
|
125
|
+
process.exitCode = code;
|
|
126
|
+
},
|
|
127
|
+
} = {}
|
|
128
|
+
) {
|
|
80
129
|
return async (/** @type {any[]} */ ...args) => {
|
|
81
130
|
try {
|
|
82
131
|
await fn(...args);
|
package/bin/agent/cli.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AGENT_EXIT_CODES, createAgentSession, getAgentExitCode } from './protocol.js';
|
|
2
|
+
import { executeAgentCommand } from './commands/index.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string[]} argv
|
|
6
|
+
* @returns {{ command: string, args: string[] }}
|
|
7
|
+
*/
|
|
8
|
+
function resolveCommand(argv) {
|
|
9
|
+
if (argv.length === 0) {
|
|
10
|
+
return { command: 'agent', args: [] };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (argv[0] === 'vault' || argv[0] === 'recipient') {
|
|
14
|
+
if (!argv[1]) {
|
|
15
|
+
return { command: argv[0], args: [] };
|
|
16
|
+
}
|
|
17
|
+
return { command: `${argv[0]}.${argv[1]}`, args: argv.slice(2) };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return { command: argv[0], args: argv.slice(1) };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {string[]} argv
|
|
25
|
+
* @param {{ stdout?: Pick<NodeJS.WriteStream, 'write'>, stderr?: Pick<NodeJS.WriteStream, 'write'>, stdin?: NodeJS.ReadStream }} [deps]
|
|
26
|
+
* @returns {Promise<void>}
|
|
27
|
+
*/
|
|
28
|
+
export async function runAgentCli(
|
|
29
|
+
argv,
|
|
30
|
+
{ stdout = process.stdout, stderr = process.stderr, stdin = process.stdin } = {}
|
|
31
|
+
) {
|
|
32
|
+
const { command, args } = resolveCommand(argv);
|
|
33
|
+
const session = createAgentSession({ command, stdout, stderr });
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const outcome = await executeAgentCommand(command, args, { stdin, session });
|
|
37
|
+
const exitCode = outcome.exitCode ?? AGENT_EXIT_CODES.SUCCESS;
|
|
38
|
+
process.exitCode = exitCode;
|
|
39
|
+
session.writeResult(outcome.data);
|
|
40
|
+
session.writeEnd({ ok: exitCode === AGENT_EXIT_CODES.SUCCESS, exitCode });
|
|
41
|
+
} catch (err) {
|
|
42
|
+
const exitCode = getAgentExitCode(err);
|
|
43
|
+
process.exitCode = exitCode;
|
|
44
|
+
if (err instanceof Error && err.code === 'NEEDS_INPUT') {
|
|
45
|
+
session.writeNeedsInput(err);
|
|
46
|
+
} else {
|
|
47
|
+
session.writeError(err);
|
|
48
|
+
}
|
|
49
|
+
session.writeEnd({ ok: false, exitCode });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { inspectVaultHealth } from '../../ui/vault-report.js';
|
|
2
|
+
import { resolveAgentPassphraseSource } from '../passphrase-source.js';
|
|
3
|
+
import { resolveAgentDiagnosticEncryptionKey } from '../../credentials.js';
|
|
4
|
+
import {
|
|
5
|
+
assignPositionals,
|
|
6
|
+
createCas,
|
|
7
|
+
invalidInput,
|
|
8
|
+
normalizeInputAliases,
|
|
9
|
+
parseAgentInput,
|
|
10
|
+
readAgentPassphraseFile,
|
|
11
|
+
selectStartInput,
|
|
12
|
+
writeAgentStart,
|
|
13
|
+
} from '../input.js';
|
|
14
|
+
import { AGENT_EXIT_CODES } from '../protocol.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {string[]} args
|
|
18
|
+
* @param {NodeJS.ReadStream} stdin
|
|
19
|
+
* @param {ReturnType<typeof import('../protocol.js').createAgentSession>} session
|
|
20
|
+
* @returns {Promise<{ exitCode: number, data: Record<string, any> }>}
|
|
21
|
+
*/
|
|
22
|
+
export default async function doctorCommand(args, stdin, session) {
|
|
23
|
+
const { values, positionals, requestSource } = await parseAgentInput(
|
|
24
|
+
args,
|
|
25
|
+
{
|
|
26
|
+
cwd: { type: 'string' },
|
|
27
|
+
'key-file': { type: 'string' },
|
|
28
|
+
'vault-passphrase': { type: 'string' },
|
|
29
|
+
'vault-passphrase-file': { type: 'string' },
|
|
30
|
+
'os-keychain-target': { type: 'string' },
|
|
31
|
+
'os-keychain-account': { type: 'string' },
|
|
32
|
+
},
|
|
33
|
+
stdin
|
|
34
|
+
);
|
|
35
|
+
assignPositionals(positionals, []);
|
|
36
|
+
const input = normalizeInputAliases({ ...values, requestSource });
|
|
37
|
+
writeAgentStart(session, selectStartInput(input, [
|
|
38
|
+
'cwd',
|
|
39
|
+
'keyFile',
|
|
40
|
+
'vaultPassphrase',
|
|
41
|
+
'vaultPassphraseFile',
|
|
42
|
+
'osKeychainTarget',
|
|
43
|
+
'osKeychainAccount',
|
|
44
|
+
]));
|
|
45
|
+
|
|
46
|
+
const cas = await createCas(input.cwd || '.');
|
|
47
|
+
const encryptionKey = await resolveAgentDiagnosticEncryptionKey(cas, input, {
|
|
48
|
+
stdin,
|
|
49
|
+
onWarning: (warning) => session.writeWarning?.(warning),
|
|
50
|
+
resolveVaultPassphrase,
|
|
51
|
+
errorFactory: invalidInput,
|
|
52
|
+
});
|
|
53
|
+
const report = await inspectVaultHealth(cas, { encryptionKey });
|
|
54
|
+
const exitCode =
|
|
55
|
+
report.status === 'ok' ? AGENT_EXIT_CODES.SUCCESS : AGENT_EXIT_CODES.VERIFICATION_FAILED;
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
exitCode,
|
|
59
|
+
data: { report },
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {Record<string, any>} input
|
|
65
|
+
* @param {string | undefined} requestSource
|
|
66
|
+
* @param {{ stdin?: NodeJS.ReadStream, onWarning?: (warning: Record<string, any>) => void }} [options]
|
|
67
|
+
* @returns {Promise<string | undefined>}
|
|
68
|
+
*/
|
|
69
|
+
async function resolveVaultPassphrase(input, requestSource, options = {}) {
|
|
70
|
+
return await resolveAgentPassphraseSource({
|
|
71
|
+
label: 'Passphrase',
|
|
72
|
+
inlineValue: input.vaultPassphrase,
|
|
73
|
+
fileValue: input.vaultPassphraseFile,
|
|
74
|
+
osKeychainTarget: input.osKeychainTarget,
|
|
75
|
+
osKeychainAccount: input.osKeychainAccount,
|
|
76
|
+
requestSource,
|
|
77
|
+
readPassphraseFile: (filePath) => readAgentPassphraseFile(filePath, options),
|
|
78
|
+
resolveInlinePassphrase,
|
|
79
|
+
errorFactory: invalidInput,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @param {string} label
|
|
85
|
+
* @param {unknown} value
|
|
86
|
+
* @returns {string | undefined}
|
|
87
|
+
*/
|
|
88
|
+
function resolveInlinePassphrase(label, value) {
|
|
89
|
+
if (value === undefined) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const passphrase = String(value);
|
|
94
|
+
if (!passphrase.trim()) {
|
|
95
|
+
throw invalidInput(`${label} must not be empty`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return passphrase;
|
|
99
|
+
}
|