@git-stunts/git-cas 1.6.2 → 3.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/CHANGELOG.md +75 -1
- package/README.md +56 -8
- package/bin/git-cas.js +205 -38
- package/index.d.ts +149 -4
- package/index.js +112 -12
- package/package.json +1 -1
- package/src/domain/schemas/ManifestSchema.d.ts +27 -0
- package/src/domain/schemas/ManifestSchema.js +27 -0
- package/src/domain/services/CasService.d.ts +29 -1
- package/src/domain/services/CasService.js +253 -30
- package/src/domain/services/VaultService.js +445 -0
- package/src/domain/value-objects/Manifest.d.ts +30 -0
- package/src/domain/value-objects/Manifest.js +6 -0
- package/src/infrastructure/adapters/BunCryptoAdapter.js +35 -2
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +11 -11
- package/src/infrastructure/adapters/GitRefAdapter.js +67 -0
- package/src/infrastructure/adapters/NodeCryptoAdapter.js +40 -1
- package/src/infrastructure/adapters/WebCryptoAdapter.js +58 -0
- package/src/ports/CryptoPort.js +17 -0
- package/src/ports/GitRefPort.js +48 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,81 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [
|
|
8
|
+
## [3.0.0] — Vault (2026-02-08)
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Vault** — GC-safe ref-based storage via `refs/cas/vault`. A single Git ref pointing to a commit chain indexes all stored assets by slug. `git gc` can no longer silently discard stored data.
|
|
12
|
+
- `initVault()` — initialize the vault, optionally with passphrase-based encryption (vault-level KDF policy).
|
|
13
|
+
- `addToVault()` — add or update an entry by slug + tree OID, with `force` flag for overwrites.
|
|
14
|
+
- `listVault()` — list all entries sorted by slug.
|
|
15
|
+
- `removeFromVault()` — remove an entry by slug.
|
|
16
|
+
- `resolveVaultEntry()` — resolve a slug to its tree OID.
|
|
17
|
+
- `getVaultMetadata()` — inspect vault metadata (encryption config, version).
|
|
18
|
+
- Vault metadata (`.vault.json`) supports versioning and optional encryption configuration.
|
|
19
|
+
- CAS-safe writes with automatic retry (up to 3 attempts with exponential backoff) on concurrent update conflicts.
|
|
20
|
+
- Strict slug validation: rejects empty strings, `..` traversal, control characters, oversized segments.
|
|
21
|
+
- New CLI subcommands: `vault init`, `vault list`, `vault info <slug>`, `vault remove <slug>`, `vault history`.
|
|
22
|
+
- CLI `store --tree` now auto-vaults the entry (adds to vault after creating tree).
|
|
23
|
+
- CLI `restore` now supports `--slug` (resolve via vault) and `--oid` (direct tree OID) flags.
|
|
24
|
+
- CLI `--vault-passphrase` flag for vault-level encryption on `store`, `restore`, and `vault init`.
|
|
25
|
+
- New error codes: `INVALID_SLUG`, `VAULT_ENTRY_NOT_FOUND`, `VAULT_ENTRY_EXISTS`, `VAULT_CONFLICT`, `VAULT_METADATA_INVALID`, `VAULT_ENCRYPTION_ALREADY_CONFIGURED`.
|
|
26
|
+
- TypeScript declarations for `VaultEntry`, `VaultMetadata`, `VaultState`, `VaultService`, `GitRefPort` types.
|
|
27
|
+
- `VaultService` — first-class domain service with proper port/adapter separation (hexagonal architecture).
|
|
28
|
+
- `GitRefPort` and `GitRefAdapter` — new port/adapter for Git ref and commit operations.
|
|
29
|
+
- `getVaultService()` on facade exposes the underlying `VaultService` for advanced usage.
|
|
30
|
+
- Vault-specific integration tests (`test/integration/vault.test.js`).
|
|
31
|
+
- 46 vault unit tests + facade delegation smoke test.
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
- `#validateMetadata` now requires `kdf.keyLength` in encryption metadata, preventing downstream KDF failures from manually edited `.vault.json` files.
|
|
35
|
+
- `#casUpdateRef` now preserves the original error in `VAULT_CONFLICT` meta for better diagnostics.
|
|
36
|
+
- CLI `--vault-passphrase` now emits a stderr warning when the vault is not encrypted, instead of silently ignoring the passphrase.
|
|
37
|
+
- `vault history` command now uses `VAULT_REF` constant instead of hardcoded string.
|
|
38
|
+
- API docs: fixed invalid import path `@git-stunts/cas/vault` → `@git-stunts/cas`.
|
|
39
|
+
- API docs: fixed `_readVaultState()` → `readState()` in error codes table.
|
|
40
|
+
- API docs and GUIDE: added `text` language identifier to fenced code blocks (markdownlint MD040).
|
|
41
|
+
- CLI version string updated from `2.0.0` to `3.0.0`.
|
|
42
|
+
- CLI `vault history --max-count` now validates input as a positive integer.
|
|
43
|
+
- Stale JSDoc in `GitPersistenceAdapter` corrected (removed mention of retries).
|
|
44
|
+
- CLI uses `program.parseAsync()` instead of `program.parse()` to prevent Bun from hanging on async action handlers.
|
|
45
|
+
|
|
46
|
+
### Changed
|
|
47
|
+
- **Vault promoted to domain layer** — all vault logic extracted from facade (`index.js`) into `VaultService` (`src/domain/services/VaultService.js`) with `GitRefPort`/`GitRefAdapter` for ref operations. Facade now delegates to VaultService.
|
|
48
|
+
- CLI `restore` command no longer takes a positional `<tree-oid>` argument. Use `--oid <tree-oid>` or `--slug <slug>` instead.
|
|
49
|
+
- Purged completed milestones (M1–M7) and their task cards from ROADMAP.md, reducing it from 3,153 to 1,675 lines.
|
|
50
|
+
|
|
51
|
+
## [2.0.0] — M7 Horizon (2026-02-08)
|
|
52
|
+
|
|
53
|
+
### Added
|
|
54
|
+
- **Compression support** (Task 7.1): Optional gzip compression pipeline via `compression: { algorithm: 'gzip' }` option on `store()`. Compression is applied before encryption when both are enabled. Manifests include a new optional `compression` field. Decompression on `restore()` is automatic.
|
|
55
|
+
- **KDF support** (Task 7.2): Passphrase-based encryption using PBKDF2 or scrypt via `deriveKey()` method and `passphrase` option on `store()`/`restore()`. KDF parameters are stored in `manifest.encryption.kdf` for deterministic re-derivation. All three crypto adapters (Node, Bun, Web) implement `deriveKey()`.
|
|
56
|
+
- **Merkle tree manifests** (Task 7.3): Large manifests (chunk count exceeding `merkleThreshold`, default 1000) are automatically split into sub-manifests stored as separate blobs. Root manifest uses `version: 2` with `subManifests` references. `readManifest()` transparently reconstitutes v2 manifests into flat chunk lists. Full backward compatibility with v1 manifests.
|
|
57
|
+
- New schema fields: `version`, `compression`, `subManifests` on `ManifestSchema`; `kdf` on `EncryptionSchema`.
|
|
58
|
+
- New error code: `INVALID_OPTIONS` for mutually exclusive options or unsupported option values.
|
|
59
|
+
- 62 new unit tests across three new test suites (compression, KDF, Merkle) plus expanded error tests.
|
|
60
|
+
- Updated API reference (`docs/API.md`), guide (`GUIDE.md`), and README with v2.0.0 feature documentation.
|
|
61
|
+
|
|
62
|
+
### Changed
|
|
63
|
+
- **BREAKING**: Manifest schema now includes `version` field (defaults to 1). Existing v1 manifests are fully backward-compatible.
|
|
64
|
+
- `CasService` constructor accepts new `merkleThreshold` option (must be a positive integer).
|
|
65
|
+
- `ContentAddressableStore` constructor now accepts and forwards `merkleThreshold` to `CasService`.
|
|
66
|
+
- `store()` and `storeFile()` accept `passphrase`, `kdfOptions`, and `compression` options.
|
|
67
|
+
- `restore()` accepts `passphrase` option.
|
|
68
|
+
- Static imports for `createGzip` and `Readable` in `CasService` (previously dynamic imports on every call).
|
|
69
|
+
|
|
70
|
+
### Fixed
|
|
71
|
+
- **Sub-manifest blobs are now included as tree entries** (`sub-manifest-N.json`), preventing them from being garbage-collected by `git gc`.
|
|
72
|
+
- `storeFile()` now forwards `passphrase`, `kdfOptions`, and `compression` options to `store()` (previously silently dropped).
|
|
73
|
+
- `store()` and `restore()` reject when both `passphrase` and `encryptionKey` are provided (`INVALID_OPTIONS`).
|
|
74
|
+
- `store()` rejects unsupported compression algorithms (`INVALID_OPTIONS`).
|
|
75
|
+
- `restore()` throws a descriptive error when passphrase is provided but manifest lacks KDF metadata.
|
|
76
|
+
- Decompression errors are now wrapped as `CasError` with code `INTEGRITY_ERROR` (previously raw zlib errors).
|
|
77
|
+
- `NodeCryptoAdapter.deriveKey()` uses `Buffer.from(salt)` for base64 encoding, preventing corrupt output when salt is a `Uint8Array`.
|
|
78
|
+
- `WebCryptoAdapter.deriveKey()` now validates KDF algorithm and throws for unsupported values instead of silently falling through to scrypt.
|
|
79
|
+
- `WebCryptoAdapter` scrypt derivation now throws a descriptive error when `node:crypto` is unavailable (e.g. in browsers).
|
|
80
|
+
- Orphaned JSDoc blocks for `restore()`, `verifyIntegrity()`, and `store()` reattached to their correct methods.
|
|
81
|
+
- Stale cross-reference in GUIDE.md ("Section 10" → "Section 13").
|
|
82
|
+
- API.md method signatures updated to include all v2 parameters.
|
|
9
83
|
|
|
10
84
|
## [1.6.2] — OIDC publishing + JSR docs coverage (2026-02-07)
|
|
11
85
|
|
package/README.md
CHANGED
|
@@ -21,13 +21,45 @@ We use the object database.
|
|
|
21
21
|
- **Dedupe for free** Git already hashes objects. We just lean into it.
|
|
22
22
|
- **Chunked storage** big files become stable, reusable blobs.
|
|
23
23
|
- **Optional AES-256-GCM encryption** store secrets without leaking plaintext into the ODB.
|
|
24
|
+
- **Compression** gzip before encryption — smaller blobs, same round-trip.
|
|
25
|
+
- **Passphrase encryption** derive keys from passphrases via PBKDF2 or scrypt — no raw key management.
|
|
26
|
+
- **Merkle manifests** large files auto-split into sub-manifests for scalability.
|
|
24
27
|
- **Manifests** a tiny explicit index of chunks + metadata (JSON/CBOR).
|
|
25
28
|
- **Tree output** generates standard Git trees so assets snap into commits cleanly.
|
|
26
29
|
- **Full round-trip** store, tree, and restore — get your bytes back, verified.
|
|
27
30
|
- **Lifecycle management** `readManifest`, `deleteAsset`, `findOrphanedChunks` — inspect trees, plan deletions, audit storage.
|
|
31
|
+
- **Vault** GC-safe ref-based storage. One ref (`refs/cas/vault`) indexes all assets by slug. No more silent data loss from `git gc`.
|
|
28
32
|
|
|
29
33
|
**Use it for:** binary assets, build artifacts, model weights, data packs, secret bundles, weird experiments, etc.
|
|
30
34
|
|
|
35
|
+
## What's new in v2.0.0
|
|
36
|
+
|
|
37
|
+
**Compression** — `compression: { algorithm: 'gzip' }` on `store()`. Compression runs before encryption. Decompression on `restore()` is automatic.
|
|
38
|
+
|
|
39
|
+
**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.
|
|
40
|
+
|
|
41
|
+
**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.
|
|
42
|
+
|
|
43
|
+
See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
|
|
44
|
+
|
|
45
|
+
## What's new in v3.0.0
|
|
46
|
+
|
|
47
|
+
**Vault** — GC-safe ref-based storage. A single Git ref (`refs/cas/vault`) indexes all stored assets by slug, so `git gc` can no longer silently discard your data. Initialize with `vault init`, store with `--tree`, restore by `--slug`.
|
|
48
|
+
|
|
49
|
+
**CLI breaking change** — `git cas restore` no longer takes a positional `<tree-oid>` argument. Use `--oid <tree-oid>` or `--slug <slug>` instead.
|
|
50
|
+
|
|
51
|
+
See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm install @git-stunts/git-cas
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npx jsr add @git-stunts/git-cas
|
|
61
|
+
```
|
|
62
|
+
|
|
31
63
|
## Usage (Node API)
|
|
32
64
|
|
|
33
65
|
```js
|
|
@@ -56,6 +88,14 @@ const m = await cas.readManifest({ treeOid });
|
|
|
56
88
|
// Lifecycle: inspect deletion impact, find orphaned chunks
|
|
57
89
|
const { slug, chunksOrphaned } = await cas.deleteAsset({ treeOid });
|
|
58
90
|
const { referenced, total } = await cas.findOrphanedChunks({ treeOids: [treeOid] });
|
|
91
|
+
|
|
92
|
+
// v2.0.0: Compressed + passphrase-encrypted store
|
|
93
|
+
const manifest2 = await cas.storeFile({
|
|
94
|
+
filePath: './image.png',
|
|
95
|
+
slug: 'my-image',
|
|
96
|
+
passphrase: 'my secret passphrase',
|
|
97
|
+
compression: { algorithm: 'gzip' },
|
|
98
|
+
});
|
|
59
99
|
```
|
|
60
100
|
|
|
61
101
|
## CLI (git plugin)
|
|
@@ -66,18 +106,26 @@ const { referenced, total } = await cas.findOrphanedChunks({ treeOids: [treeOid]
|
|
|
66
106
|
# Store a file — prints manifest JSON
|
|
67
107
|
git cas store ./image.png --slug my-image
|
|
68
108
|
|
|
69
|
-
# Store and
|
|
109
|
+
# Store and vault the tree OID (GC-safe)
|
|
70
110
|
git cas store ./image.png --slug my-image --tree
|
|
71
111
|
|
|
72
|
-
#
|
|
73
|
-
git cas
|
|
112
|
+
# Restore from a vault slug
|
|
113
|
+
git cas restore --slug my-image --out ./restored.png
|
|
114
|
+
|
|
115
|
+
# Restore from a direct tree OID
|
|
116
|
+
git cas restore --oid <tree-oid> --out ./restored.png
|
|
74
117
|
|
|
75
|
-
#
|
|
76
|
-
git cas
|
|
118
|
+
# Vault management
|
|
119
|
+
git cas vault init
|
|
120
|
+
git cas vault list
|
|
121
|
+
git cas vault info my-image
|
|
122
|
+
git cas vault remove my-image
|
|
123
|
+
git cas vault history
|
|
77
124
|
|
|
78
|
-
# Encrypted round-trip
|
|
79
|
-
git cas
|
|
80
|
-
git cas
|
|
125
|
+
# Encrypted vault round-trip
|
|
126
|
+
git cas vault init --vault-passphrase "secret"
|
|
127
|
+
git cas store ./secret.bin --slug vault-entry --tree --vault-passphrase "secret"
|
|
128
|
+
git cas restore --slug vault-entry --out ./decrypted.bin --vault-passphrase "secret"
|
|
81
129
|
```
|
|
82
130
|
|
|
83
131
|
## Why not Git LFS?
|
package/bin/git-cas.js
CHANGED
|
@@ -2,31 +2,94 @@
|
|
|
2
2
|
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
4
|
import { program } from 'commander';
|
|
5
|
-
import GitPlumbing from '@git-stunts/plumbing';
|
|
5
|
+
import GitPlumbing, { ShellRunnerFactory } from '@git-stunts/plumbing';
|
|
6
6
|
import ContentAddressableStore from '../index.js';
|
|
7
7
|
import Manifest from '../src/domain/value-objects/Manifest.js';
|
|
8
8
|
|
|
9
9
|
program
|
|
10
10
|
.name('git-cas')
|
|
11
11
|
.description('Content Addressable Storage backed by Git')
|
|
12
|
-
.version('
|
|
12
|
+
.version('3.0.0');
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Read a 32-byte raw encryption key from a file.
|
|
16
16
|
*/
|
|
17
17
|
function readKeyFile(keyFilePath) {
|
|
18
|
-
|
|
19
|
-
return key;
|
|
18
|
+
return readFileSync(keyFilePath);
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* Create a CAS instance for the given working directory.
|
|
24
23
|
*/
|
|
25
24
|
function createCas(cwd) {
|
|
26
|
-
const
|
|
25
|
+
const runner = ShellRunnerFactory.create();
|
|
26
|
+
const plumbing = new GitPlumbing({ runner, cwd });
|
|
27
27
|
return new ContentAddressableStore({ plumbing });
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Derive the encryption key from vault metadata + passphrase.
|
|
32
|
+
*/
|
|
33
|
+
async function deriveVaultKey(cas, metadata, passphrase) {
|
|
34
|
+
const { kdf } = metadata.encryption;
|
|
35
|
+
const { key } = await cas.deriveKey({
|
|
36
|
+
passphrase,
|
|
37
|
+
salt: Buffer.from(kdf.salt, 'base64'),
|
|
38
|
+
algorithm: kdf.algorithm,
|
|
39
|
+
iterations: kdf.iterations,
|
|
40
|
+
cost: kdf.cost,
|
|
41
|
+
blockSize: kdf.blockSize,
|
|
42
|
+
parallelization: kdf.parallelization,
|
|
43
|
+
});
|
|
44
|
+
return key;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Resolve encryption key from --key-file or --vault-passphrase.
|
|
49
|
+
*/
|
|
50
|
+
async function resolveEncryptionKey(cas, opts) {
|
|
51
|
+
if (opts.keyFile) {
|
|
52
|
+
return readKeyFile(opts.keyFile);
|
|
53
|
+
}
|
|
54
|
+
if (!opts.vaultPassphrase) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const metadata = await cas.getVaultMetadata();
|
|
58
|
+
if (metadata?.encryption) {
|
|
59
|
+
return deriveVaultKey(cas, metadata, opts.vaultPassphrase);
|
|
60
|
+
}
|
|
61
|
+
process.stderr.write('warning: --vault-passphrase ignored (vault is not encrypted)\n');
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Read the manifest from a tree OID.
|
|
67
|
+
*/
|
|
68
|
+
async function readManifestFromTree(service, treeOid) {
|
|
69
|
+
const entries = await service.persistence.readTree(treeOid);
|
|
70
|
+
const entry = entries.find((e) => e.name.startsWith('manifest.'));
|
|
71
|
+
if (!entry) {
|
|
72
|
+
process.stderr.write('error: No manifest found in tree\n');
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
const blob = await service.persistence.readBlob(entry.oid);
|
|
76
|
+
return new Manifest(service.codec.decode(blob));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Validate --slug / --oid flags (exactly one required).
|
|
81
|
+
*/
|
|
82
|
+
function validateRestoreFlags(opts) {
|
|
83
|
+
if (opts.slug && opts.oid) {
|
|
84
|
+
process.stderr.write('error: Provide --slug or --oid, not both\n');
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
if (!opts.slug && !opts.oid) {
|
|
88
|
+
process.stderr.write('error: Provide --slug <slug> or --oid <tree-oid>\n');
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
30
93
|
// ---------------------------------------------------------------------------
|
|
31
94
|
// store
|
|
32
95
|
// ---------------------------------------------------------------------------
|
|
@@ -36,26 +99,26 @@ program
|
|
|
36
99
|
.requiredOption('--slug <slug>', 'Asset slug identifier')
|
|
37
100
|
.option('--key-file <path>', 'Path to 32-byte raw encryption key file')
|
|
38
101
|
.option('--tree', 'Also create a Git tree and print its OID')
|
|
102
|
+
.option('--force', 'Overwrite existing vault entry')
|
|
103
|
+
.option('--vault-passphrase <pass>', 'Vault-level passphrase for encryption')
|
|
39
104
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
40
105
|
.action(async (file, opts) => {
|
|
41
106
|
try {
|
|
42
107
|
const cas = createCas(opts.cwd);
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (opts.keyFile) {
|
|
49
|
-
storeOpts.encryptionKey = readKeyFile(opts.keyFile);
|
|
108
|
+
const encryptionKey = await resolveEncryptionKey(cas, opts);
|
|
109
|
+
const storeOpts = { filePath: file, slug: opts.slug };
|
|
110
|
+
if (encryptionKey) {
|
|
111
|
+
storeOpts.encryptionKey = encryptionKey;
|
|
50
112
|
}
|
|
51
113
|
|
|
52
114
|
const manifest = await cas.storeFile(storeOpts);
|
|
53
115
|
|
|
54
116
|
if (opts.tree) {
|
|
55
117
|
const treeOid = await cas.createTree({ manifest });
|
|
56
|
-
|
|
118
|
+
await cas.addToVault({ slug: opts.slug, treeOid, force: !!opts.force });
|
|
119
|
+
process.stdout.write(`${treeOid}\n`);
|
|
57
120
|
} else {
|
|
58
|
-
process.stdout.write(`${JSON.stringify(manifest.toJSON(), null, 2)
|
|
121
|
+
process.stdout.write(`${JSON.stringify(manifest.toJSON(), null, 2)}\n`);
|
|
59
122
|
}
|
|
60
123
|
} catch (err) {
|
|
61
124
|
process.stderr.write(`error: ${err.message}\n`);
|
|
@@ -77,7 +140,7 @@ program
|
|
|
77
140
|
const raw = readFileSync(opts.manifest, 'utf8');
|
|
78
141
|
const manifest = new Manifest(JSON.parse(raw));
|
|
79
142
|
const treeOid = await cas.createTree({ manifest });
|
|
80
|
-
process.stdout.write(`${treeOid
|
|
143
|
+
process.stdout.write(`${treeOid}\n`);
|
|
81
144
|
} catch (err) {
|
|
82
145
|
process.stderr.write(`error: ${err.message}\n`);
|
|
83
146
|
process.exit(1);
|
|
@@ -88,43 +151,32 @@ program
|
|
|
88
151
|
// restore
|
|
89
152
|
// ---------------------------------------------------------------------------
|
|
90
153
|
program
|
|
91
|
-
.command('restore
|
|
154
|
+
.command('restore')
|
|
92
155
|
.description('Restore a file from a Git CAS tree')
|
|
93
156
|
.requiredOption('--out <path>', 'Output file path')
|
|
157
|
+
.option('--slug <slug>', 'Resolve tree OID from vault slug')
|
|
158
|
+
.option('--oid <tree-oid>', 'Direct tree OID')
|
|
94
159
|
.option('--key-file <path>', 'Path to 32-byte raw encryption key file')
|
|
160
|
+
.option('--vault-passphrase <pass>', 'Vault-level passphrase for decryption')
|
|
95
161
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
96
|
-
.action(async (
|
|
162
|
+
.action(async (opts) => {
|
|
97
163
|
try {
|
|
164
|
+
validateRestoreFlags(opts);
|
|
98
165
|
const cas = createCas(opts.cwd);
|
|
166
|
+
const treeOid = opts.oid || await cas.resolveVaultEntry({ slug: opts.slug });
|
|
99
167
|
const service = await cas.getService();
|
|
100
|
-
|
|
101
|
-
// Read the tree to find the manifest
|
|
102
|
-
const entries = await service.persistence.readTree(treeOid);
|
|
103
|
-
const manifestEntry = entries.find(
|
|
104
|
-
(e) => e.name.startsWith('manifest.'),
|
|
105
|
-
);
|
|
106
|
-
if (!manifestEntry) {
|
|
107
|
-
process.stderr.write('error: No manifest found in tree\n');
|
|
108
|
-
process.exit(1);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const manifestBlob = await service.persistence.readBlob(
|
|
112
|
-
manifestEntry.oid,
|
|
113
|
-
);
|
|
114
|
-
const manifest = new Manifest(
|
|
115
|
-
service.codec.decode(manifestBlob),
|
|
116
|
-
);
|
|
168
|
+
const manifest = await readManifestFromTree(service, treeOid);
|
|
117
169
|
|
|
118
170
|
const restoreOpts = { manifest };
|
|
119
|
-
|
|
120
|
-
|
|
171
|
+
const encryptionKey = await resolveEncryptionKey(cas, opts);
|
|
172
|
+
if (encryptionKey) {
|
|
173
|
+
restoreOpts.encryptionKey = encryptionKey;
|
|
121
174
|
}
|
|
122
175
|
|
|
123
176
|
const { bytesWritten } = await cas.restoreFile({
|
|
124
177
|
...restoreOpts,
|
|
125
178
|
outputPath: opts.out,
|
|
126
179
|
});
|
|
127
|
-
|
|
128
180
|
process.stdout.write(`${bytesWritten}\n`);
|
|
129
181
|
} catch (err) {
|
|
130
182
|
process.stderr.write(`error: ${err.message}\n`);
|
|
@@ -132,4 +184,119 @@ program
|
|
|
132
184
|
}
|
|
133
185
|
});
|
|
134
186
|
|
|
135
|
-
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
// vault init
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
const vault = program
|
|
191
|
+
.command('vault')
|
|
192
|
+
.description('Manage the CAS vault');
|
|
193
|
+
|
|
194
|
+
vault
|
|
195
|
+
.command('init')
|
|
196
|
+
.description('Initialize the vault')
|
|
197
|
+
.option('--vault-passphrase <pass>', 'Passphrase for vault-level encryption')
|
|
198
|
+
.option('--algorithm <alg>', 'KDF algorithm (pbkdf2 or scrypt)', 'pbkdf2')
|
|
199
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
200
|
+
.action(async (opts) => {
|
|
201
|
+
try {
|
|
202
|
+
const cas = createCas(opts.cwd);
|
|
203
|
+
const initOpts = {};
|
|
204
|
+
if (opts.vaultPassphrase) {
|
|
205
|
+
initOpts.passphrase = opts.vaultPassphrase;
|
|
206
|
+
initOpts.kdfOptions = { algorithm: opts.algorithm };
|
|
207
|
+
}
|
|
208
|
+
const { commitOid } = await cas.initVault(initOpts);
|
|
209
|
+
process.stdout.write(`${commitOid}\n`);
|
|
210
|
+
} catch (err) {
|
|
211
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
212
|
+
process.exit(1);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// ---------------------------------------------------------------------------
|
|
217
|
+
// vault list
|
|
218
|
+
// ---------------------------------------------------------------------------
|
|
219
|
+
vault
|
|
220
|
+
.command('list')
|
|
221
|
+
.description('List vault entries')
|
|
222
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
223
|
+
.action(async (opts) => {
|
|
224
|
+
try {
|
|
225
|
+
const cas = createCas(opts.cwd);
|
|
226
|
+
const entries = await cas.listVault();
|
|
227
|
+
for (const { slug, treeOid } of entries) {
|
|
228
|
+
process.stdout.write(`${slug}\t${treeOid}\n`);
|
|
229
|
+
}
|
|
230
|
+
} catch (err) {
|
|
231
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
232
|
+
process.exit(1);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// ---------------------------------------------------------------------------
|
|
237
|
+
// vault remove
|
|
238
|
+
// ---------------------------------------------------------------------------
|
|
239
|
+
vault
|
|
240
|
+
.command('remove <slug>')
|
|
241
|
+
.description('Remove an entry from the vault')
|
|
242
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
243
|
+
.action(async (slug, opts) => {
|
|
244
|
+
try {
|
|
245
|
+
const cas = createCas(opts.cwd);
|
|
246
|
+
const { removedTreeOid } = await cas.removeFromVault({ slug });
|
|
247
|
+
process.stdout.write(`${removedTreeOid}\n`);
|
|
248
|
+
} catch (err) {
|
|
249
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
250
|
+
process.exit(1);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// ---------------------------------------------------------------------------
|
|
255
|
+
// vault info
|
|
256
|
+
// ---------------------------------------------------------------------------
|
|
257
|
+
vault
|
|
258
|
+
.command('info <slug>')
|
|
259
|
+
.description('Show info for a vault entry')
|
|
260
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
261
|
+
.action(async (slug, opts) => {
|
|
262
|
+
try {
|
|
263
|
+
const cas = createCas(opts.cwd);
|
|
264
|
+
const treeOid = await cas.resolveVaultEntry({ slug });
|
|
265
|
+
process.stdout.write(`slug\t${slug}\n`);
|
|
266
|
+
process.stdout.write(`tree\t${treeOid}\n`);
|
|
267
|
+
} catch (err) {
|
|
268
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
269
|
+
process.exit(1);
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
// ---------------------------------------------------------------------------
|
|
274
|
+
// vault history
|
|
275
|
+
// ---------------------------------------------------------------------------
|
|
276
|
+
vault
|
|
277
|
+
.command('history')
|
|
278
|
+
.description('Show vault commit history')
|
|
279
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
280
|
+
.option('-n, --max-count <n>', 'Limit number of commits')
|
|
281
|
+
.action(async (opts) => {
|
|
282
|
+
try {
|
|
283
|
+
const runner = ShellRunnerFactory.create();
|
|
284
|
+
const plumbing = new GitPlumbing({ runner, cwd: opts.cwd || '.' });
|
|
285
|
+
const args = ['log', '--oneline', ContentAddressableStore.VAULT_REF];
|
|
286
|
+
if (opts.maxCount) {
|
|
287
|
+
const n = parseInt(opts.maxCount, 10);
|
|
288
|
+
if (Number.isNaN(n) || n <= 0) {
|
|
289
|
+
process.stderr.write('error: --max-count must be a positive integer\n');
|
|
290
|
+
process.exit(1);
|
|
291
|
+
}
|
|
292
|
+
args.push(`-${n}`);
|
|
293
|
+
}
|
|
294
|
+
const output = await plumbing.execute({ args });
|
|
295
|
+
process.stdout.write(`${output}\n`);
|
|
296
|
+
} catch (err) {
|
|
297
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
298
|
+
process.exit(1);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
await program.parseAsync();
|