@git-stunts/git-cas 2.0.0 → 3.1.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 +66 -1
- package/README.md +63 -15
- package/bin/git-cas.js +286 -41
- package/bin/ui/context.js +54 -0
- package/bin/ui/dashboard-cmds.js +34 -0
- package/bin/ui/dashboard-view.js +132 -0
- package/bin/ui/dashboard.js +204 -0
- package/bin/ui/encryption-card.js +49 -0
- package/bin/ui/heatmap.js +103 -0
- package/bin/ui/history-timeline.js +84 -0
- package/bin/ui/manifest-view.js +135 -0
- package/bin/ui/progress.js +126 -0
- package/index.d.ts +133 -2
- package/index.js +76 -9
- package/package.json +10 -1
- package/src/domain/services/VaultService.js +445 -0
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +11 -11
- package/src/infrastructure/adapters/GitRefAdapter.js +67 -0
- package/src/ports/GitRefPort.js +48 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,72 @@ 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.1.0] — Bijou (2026-02-27)
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Interactive vault dashboard** (`git cas vault dashboard`) — TEA-based TUI with split-pane layout, manifest detail view, keyboard navigation (`j`/`k`/`Enter`/`/`), and real-time filtering.
|
|
12
|
+
- **Manifest inspector** (`git cas inspect <tree-oid>`) — renders manifest details with chunk table, encryption info, and compression badges.
|
|
13
|
+
- **Progress bars** for `store` and `restore` operations — animated progress with throughput reporting, auto-disabled in non-TTY environments.
|
|
14
|
+
- **History timeline** (`git cas vault history --pretty`) — color-coded, paginated timeline view of vault commit history.
|
|
15
|
+
- **Encryption info card** (`git cas vault info --encryption`) — detailed KDF parameters and encryption configuration display.
|
|
16
|
+
- **Chunk heatmap** — chunk-size distribution grid with colored legend, displayed in manifest detail views.
|
|
17
|
+
- `--quiet` / `-q` flag to suppress all progress output.
|
|
18
|
+
- `GIT_CAS_PASSPHRASE` environment variable — alternative to `--vault-passphrase` flag for passphrase-based encryption.
|
|
19
|
+
- New runtime dependencies: `@flyingrobots/bijou`, `@flyingrobots/bijou-node`, `@flyingrobots/bijou-tui`.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
- CLI `restore` now uses the canonical `readManifest` path instead of duplicating manifest resolution logic.
|
|
23
|
+
- Progress trackers wrapped in `try`/`finally` to prevent event listener leaks when `storeFile` or `restoreFile` throws.
|
|
24
|
+
- Dashboard filter and error lines clamped to pane width to prevent wrapping artifacts in narrow terminals.
|
|
25
|
+
- Dashboard differentiates entry vs manifest load errors — a single manifest preload failure no longer sets global error state.
|
|
26
|
+
- Dashboard clamps cursor position after applying filter on entry load.
|
|
27
|
+
- Passphrase resolution uses nullish coalescing for correct falsy-value handling.
|
|
28
|
+
- Locale-agnostic number formatting in encryption card tests.
|
|
29
|
+
- Consolidated duplicated restore flag validation into `validateRestoreFlags()`.
|
|
30
|
+
- Eliminated `vi.mock('node:fs')` pattern in progress tests for Bun Docker compatibility.
|
|
31
|
+
|
|
32
|
+
## [3.0.0] — Vault (2026-02-08)
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
- **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.
|
|
36
|
+
- `initVault()` — initialize the vault, optionally with passphrase-based encryption (vault-level KDF policy).
|
|
37
|
+
- `addToVault()` — add or update an entry by slug + tree OID, with `force` flag for overwrites.
|
|
38
|
+
- `listVault()` — list all entries sorted by slug.
|
|
39
|
+
- `removeFromVault()` — remove an entry by slug.
|
|
40
|
+
- `resolveVaultEntry()` — resolve a slug to its tree OID.
|
|
41
|
+
- `getVaultMetadata()` — inspect vault metadata (encryption config, version).
|
|
42
|
+
- Vault metadata (`.vault.json`) supports versioning and optional encryption configuration.
|
|
43
|
+
- CAS-safe writes with automatic retry (up to 3 attempts with exponential backoff) on concurrent update conflicts.
|
|
44
|
+
- Strict slug validation: rejects empty strings, `..` traversal, control characters, oversized segments.
|
|
45
|
+
- New CLI subcommands: `vault init`, `vault list`, `vault info <slug>`, `vault remove <slug>`, `vault history`.
|
|
46
|
+
- CLI `store --tree` now auto-vaults the entry (adds to vault after creating tree).
|
|
47
|
+
- CLI `restore` now supports `--slug` (resolve via vault) and `--oid` (direct tree OID) flags.
|
|
48
|
+
- CLI `--vault-passphrase` flag for vault-level encryption on `store`, `restore`, and `vault init`.
|
|
49
|
+
- New error codes: `INVALID_SLUG`, `VAULT_ENTRY_NOT_FOUND`, `VAULT_ENTRY_EXISTS`, `VAULT_CONFLICT`, `VAULT_METADATA_INVALID`, `VAULT_ENCRYPTION_ALREADY_CONFIGURED`.
|
|
50
|
+
- TypeScript declarations for `VaultEntry`, `VaultMetadata`, `VaultState`, `VaultService`, `GitRefPort` types.
|
|
51
|
+
- `VaultService` — first-class domain service with proper port/adapter separation (hexagonal architecture).
|
|
52
|
+
- `GitRefPort` and `GitRefAdapter` — new port/adapter for Git ref and commit operations.
|
|
53
|
+
- `getVaultService()` on facade exposes the underlying `VaultService` for advanced usage.
|
|
54
|
+
- Vault-specific integration tests (`test/integration/vault.test.js`).
|
|
55
|
+
- 46 vault unit tests + facade delegation smoke test.
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
- `#validateMetadata` now requires `kdf.keyLength` in encryption metadata, preventing downstream KDF failures from manually edited `.vault.json` files.
|
|
59
|
+
- `#casUpdateRef` now preserves the original error in `VAULT_CONFLICT` meta for better diagnostics.
|
|
60
|
+
- CLI `--vault-passphrase` now emits a stderr warning when the vault is not encrypted, instead of silently ignoring the passphrase.
|
|
61
|
+
- `vault history` command now uses `VAULT_REF` constant instead of hardcoded string.
|
|
62
|
+
- API docs: fixed invalid import path `@git-stunts/cas/vault` → `@git-stunts/cas`.
|
|
63
|
+
- API docs: fixed `_readVaultState()` → `readState()` in error codes table.
|
|
64
|
+
- API docs and GUIDE: added `text` language identifier to fenced code blocks (markdownlint MD040).
|
|
65
|
+
- CLI version string updated from `2.0.0` to `3.0.0`.
|
|
66
|
+
- CLI `vault history --max-count` now validates input as a positive integer.
|
|
67
|
+
- Stale JSDoc in `GitPersistenceAdapter` corrected (removed mention of retries).
|
|
68
|
+
- CLI uses `program.parseAsync()` instead of `program.parse()` to prevent Bun from hanging on async action handlers.
|
|
69
|
+
|
|
70
|
+
### Changed
|
|
71
|
+
- **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.
|
|
72
|
+
- CLI `restore` command no longer takes a positional `<tree-oid>` argument. Use `--oid <tree-oid>` or `--slug <slug>` instead.
|
|
73
|
+
- Purged completed milestones (M1–M7) and their task cards from ROADMAP.md, reducing it from 3,153 to 1,675 lines.
|
|
9
74
|
|
|
10
75
|
## [2.0.0] — M7 Horizon (2026-02-08)
|
|
11
76
|
|
package/README.md
CHANGED
|
@@ -28,9 +28,12 @@ We use the object database.
|
|
|
28
28
|
- **Tree output** generates standard Git trees so assets snap into commits cleanly.
|
|
29
29
|
- **Full round-trip** store, tree, and restore — get your bytes back, verified.
|
|
30
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`.
|
|
31
32
|
|
|
32
33
|
**Use it for:** binary assets, build artifacts, model weights, data packs, secret bundles, weird experiments, etc.
|
|
33
34
|
|
|
35
|
+
<img src="./docs/demo.gif" alt="git-cas demo" />
|
|
36
|
+
|
|
34
37
|
## What's new in v2.0.0
|
|
35
38
|
|
|
36
39
|
**Compression** — `compression: { algorithm: 'gzip' }` on `store()`. Compression runs before encryption. Decompression on `restore()` is automatic.
|
|
@@ -41,6 +44,28 @@ We use the object database.
|
|
|
41
44
|
|
|
42
45
|
See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
|
|
43
46
|
|
|
47
|
+
## What's new in v3.1.0
|
|
48
|
+
|
|
49
|
+
**Interactive vault dashboard** — `git cas vault dashboard` launches a full TUI with split-pane layout, manifest detail view, keyboard navigation, and real-time filtering. Browse entries, inspect chunks, and view encryption status without memorizing CLI flags.
|
|
50
|
+
|
|
51
|
+
**Progress bars** — `store` and `restore` now show animated progress with throughput reporting. Suppress with `--quiet`.
|
|
52
|
+
|
|
53
|
+
**Pretty history** — `git cas vault history --pretty` renders a color-coded, paginated timeline of vault commits.
|
|
54
|
+
|
|
55
|
+
**Inspect command** — `git cas inspect <tree-oid>` renders manifest details with chunk table, encryption info, and compression badges.
|
|
56
|
+
|
|
57
|
+
See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm install @git-stunts/git-cas
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npx jsr add @git-stunts/git-cas
|
|
67
|
+
```
|
|
68
|
+
|
|
44
69
|
## Usage (Node API)
|
|
45
70
|
|
|
46
71
|
```js
|
|
@@ -87,30 +112,53 @@ const manifest2 = await cas.storeFile({
|
|
|
87
112
|
# Store a file — prints manifest JSON
|
|
88
113
|
git cas store ./image.png --slug my-image
|
|
89
114
|
|
|
90
|
-
# Store and
|
|
115
|
+
# Store and vault the tree OID (GC-safe)
|
|
91
116
|
git cas store ./image.png --slug my-image --tree
|
|
92
117
|
|
|
93
|
-
#
|
|
94
|
-
git cas
|
|
118
|
+
# Restore from a vault slug
|
|
119
|
+
git cas restore --slug my-image --out ./restored.png
|
|
120
|
+
|
|
121
|
+
# Restore from a direct tree OID
|
|
122
|
+
git cas restore --oid <tree-oid> --out ./restored.png
|
|
95
123
|
|
|
96
|
-
#
|
|
97
|
-
git cas
|
|
124
|
+
# Vault management
|
|
125
|
+
git cas vault init
|
|
126
|
+
git cas vault list
|
|
127
|
+
git cas vault info my-image
|
|
128
|
+
git cas vault remove my-image
|
|
129
|
+
git cas vault history
|
|
98
130
|
|
|
99
|
-
# Encrypted round-trip (
|
|
100
|
-
|
|
101
|
-
git cas
|
|
131
|
+
# Encrypted vault round-trip (passphrase via env var or --vault-passphrase flag)
|
|
132
|
+
export GIT_CAS_PASSPHRASE="secret"
|
|
133
|
+
git cas vault init
|
|
134
|
+
git cas store ./secret.bin --slug vault-entry --tree
|
|
135
|
+
git cas restore --slug vault-entry --out ./decrypted.bin
|
|
102
136
|
```
|
|
103
137
|
|
|
104
|
-
##
|
|
138
|
+
## When to use git-cas (and when not to)
|
|
139
|
+
|
|
140
|
+
### "I just want screenshots in my README"
|
|
141
|
+
|
|
142
|
+
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.
|
|
143
|
+
|
|
144
|
+
### "I need encrypted secrets / large binaries / deduplicated assets in a Git repo"
|
|
145
|
+
|
|
146
|
+
That's git-cas. The orphan branch gives you none of:
|
|
147
|
+
|
|
148
|
+
| | Orphan branch | git-cas |
|
|
149
|
+
|---|---|---|
|
|
150
|
+
| **Encryption** | None — plaintext forever in history | AES-256-GCM + passphrase KDF |
|
|
151
|
+
| **Large files** | Bloats `git clone` for everyone | Chunked, restored on demand |
|
|
152
|
+
| **Dedup** | None | Chunk-level content addressing |
|
|
153
|
+
| **Integrity** | Git SHA-1 | SHA-256 per chunk + GCM auth tag |
|
|
154
|
+
| **Lifecycle** | `git rm` (still in reflog) | Vault with audit trail + `git gc` reclaims |
|
|
155
|
+
| **Compression** | None | gzip before encryption |
|
|
105
156
|
|
|
106
|
-
|
|
157
|
+
### "Why not Git LFS?"
|
|
107
158
|
|
|
108
|
-
|
|
109
|
-
- content-addressed
|
|
110
|
-
- locally replicable
|
|
111
|
-
- commit-addressable
|
|
159
|
+
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.
|
|
112
160
|
|
|
113
|
-
|
|
161
|
+
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.
|
|
114
162
|
|
|
115
163
|
---
|
|
116
164
|
|
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
|
+
import { createStoreProgress, createRestoreProgress } from './ui/progress.js';
|
|
9
|
+
import { renderEncryptionCard } from './ui/encryption-card.js';
|
|
10
|
+
import { renderHistoryTimeline } from './ui/history-timeline.js';
|
|
11
|
+
import { renderManifestView } from './ui/manifest-view.js';
|
|
12
|
+
import { renderHeatmap } from './ui/heatmap.js';
|
|
8
13
|
|
|
9
14
|
program
|
|
10
15
|
.name('git-cas')
|
|
11
16
|
.description('Content Addressable Storage backed by Git')
|
|
12
|
-
.version('1.
|
|
17
|
+
.version('3.1.0')
|
|
18
|
+
.option('-q, --quiet', 'Suppress progress output');
|
|
13
19
|
|
|
14
20
|
/**
|
|
15
21
|
* Read a 32-byte raw encryption key from a file.
|
|
16
22
|
*/
|
|
17
23
|
function readKeyFile(keyFilePath) {
|
|
18
|
-
|
|
19
|
-
return key;
|
|
24
|
+
return readFileSync(keyFilePath);
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
/**
|
|
23
28
|
* Create a CAS instance for the given working directory.
|
|
24
29
|
*/
|
|
25
30
|
function createCas(cwd) {
|
|
26
|
-
const
|
|
31
|
+
const runner = ShellRunnerFactory.create();
|
|
32
|
+
const plumbing = new GitPlumbing({ runner, cwd });
|
|
27
33
|
return new ContentAddressableStore({ plumbing });
|
|
28
34
|
}
|
|
29
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Derive the encryption key from vault metadata + passphrase.
|
|
38
|
+
*/
|
|
39
|
+
async function deriveVaultKey(cas, metadata, passphrase) {
|
|
40
|
+
const { kdf } = metadata.encryption;
|
|
41
|
+
const { key } = await cas.deriveKey({
|
|
42
|
+
passphrase,
|
|
43
|
+
salt: Buffer.from(kdf.salt, 'base64'),
|
|
44
|
+
algorithm: kdf.algorithm,
|
|
45
|
+
iterations: kdf.iterations,
|
|
46
|
+
cost: kdf.cost,
|
|
47
|
+
blockSize: kdf.blockSize,
|
|
48
|
+
parallelization: kdf.parallelization,
|
|
49
|
+
});
|
|
50
|
+
return key;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Resolve passphrase from --vault-passphrase flag or GIT_CAS_PASSPHRASE env var.
|
|
55
|
+
*/
|
|
56
|
+
function resolvePassphrase(opts) {
|
|
57
|
+
return opts.vaultPassphrase ?? process.env.GIT_CAS_PASSPHRASE;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Resolve encryption key from --key-file or --vault-passphrase / GIT_CAS_PASSPHRASE.
|
|
62
|
+
*/
|
|
63
|
+
async function resolveEncryptionKey(cas, opts) {
|
|
64
|
+
if (opts.keyFile) {
|
|
65
|
+
return readKeyFile(opts.keyFile);
|
|
66
|
+
}
|
|
67
|
+
const passphrase = resolvePassphrase(opts);
|
|
68
|
+
if (!passphrase) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const metadata = await cas.getVaultMetadata();
|
|
72
|
+
if (metadata?.encryption) {
|
|
73
|
+
return deriveVaultKey(cas, metadata, passphrase);
|
|
74
|
+
}
|
|
75
|
+
process.stderr.write('warning: passphrase ignored (vault is not encrypted)\n');
|
|
76
|
+
return undefined;
|
|
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,36 @@ 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 (prefer GIT_CAS_PASSPHRASE env var)')
|
|
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
|
-
const
|
|
114
|
+
const service = await cas.getService();
|
|
115
|
+
const progress = createStoreProgress({
|
|
116
|
+
filePath: file, chunkSize: cas.chunkSize, quiet: program.opts().quiet,
|
|
117
|
+
});
|
|
118
|
+
progress.attach(service);
|
|
119
|
+
let manifest;
|
|
120
|
+
try {
|
|
121
|
+
manifest = await cas.storeFile(storeOpts);
|
|
122
|
+
} finally {
|
|
123
|
+
progress.detach();
|
|
124
|
+
}
|
|
53
125
|
|
|
54
126
|
if (opts.tree) {
|
|
55
127
|
const treeOid = await cas.createTree({ manifest });
|
|
56
|
-
|
|
128
|
+
await cas.addToVault({ slug: opts.slug, treeOid, force: !!opts.force });
|
|
129
|
+
process.stdout.write(`${treeOid}\n`);
|
|
57
130
|
} else {
|
|
58
|
-
process.stdout.write(`${JSON.stringify(manifest.toJSON(), null, 2)
|
|
131
|
+
process.stdout.write(`${JSON.stringify(manifest.toJSON(), null, 2)}\n`);
|
|
59
132
|
}
|
|
60
133
|
} catch (err) {
|
|
61
134
|
process.stderr.write(`error: ${err.message}\n`);
|
|
@@ -77,7 +150,37 @@ program
|
|
|
77
150
|
const raw = readFileSync(opts.manifest, 'utf8');
|
|
78
151
|
const manifest = new Manifest(JSON.parse(raw));
|
|
79
152
|
const treeOid = await cas.createTree({ manifest });
|
|
80
|
-
process.stdout.write(`${treeOid
|
|
153
|
+
process.stdout.write(`${treeOid}\n`);
|
|
154
|
+
} catch (err) {
|
|
155
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// ---------------------------------------------------------------------------
|
|
161
|
+
// inspect
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
program
|
|
164
|
+
.command('inspect')
|
|
165
|
+
.description('Inspect a stored manifest')
|
|
166
|
+
.option('--slug <slug>', 'Resolve tree OID from vault slug')
|
|
167
|
+
.option('--oid <tree-oid>', 'Direct tree OID')
|
|
168
|
+
.option('--heatmap', 'Show chunk heatmap visualization')
|
|
169
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
170
|
+
.action(async (opts) => {
|
|
171
|
+
try {
|
|
172
|
+
validateRestoreFlags(opts);
|
|
173
|
+
const cas = createCas(opts.cwd);
|
|
174
|
+
const treeOid = opts.oid || await cas.resolveVaultEntry({ slug: opts.slug });
|
|
175
|
+
const manifest = await cas.readManifest({ treeOid });
|
|
176
|
+
|
|
177
|
+
if (opts.heatmap) {
|
|
178
|
+
process.stdout.write(renderHeatmap({ manifest }));
|
|
179
|
+
} else if (process.stdout.isTTY) {
|
|
180
|
+
process.stdout.write(renderManifestView({ manifest }));
|
|
181
|
+
} else {
|
|
182
|
+
process.stdout.write(`${JSON.stringify(manifest.toJSON(), null, 2)}\n`);
|
|
183
|
+
}
|
|
81
184
|
} catch (err) {
|
|
82
185
|
process.stderr.write(`error: ${err.message}\n`);
|
|
83
186
|
process.exit(1);
|
|
@@ -88,48 +191,190 @@ program
|
|
|
88
191
|
// restore
|
|
89
192
|
// ---------------------------------------------------------------------------
|
|
90
193
|
program
|
|
91
|
-
.command('restore
|
|
194
|
+
.command('restore')
|
|
92
195
|
.description('Restore a file from a Git CAS tree')
|
|
93
196
|
.requiredOption('--out <path>', 'Output file path')
|
|
197
|
+
.option('--slug <slug>', 'Resolve tree OID from vault slug')
|
|
198
|
+
.option('--oid <tree-oid>', 'Direct tree OID')
|
|
94
199
|
.option('--key-file <path>', 'Path to 32-byte raw encryption key file')
|
|
200
|
+
.option('--vault-passphrase <pass>', 'Vault-level passphrase for decryption (prefer GIT_CAS_PASSPHRASE env var)')
|
|
95
201
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
96
|
-
.action(async (
|
|
202
|
+
.action(async (opts) => {
|
|
97
203
|
try {
|
|
204
|
+
validateRestoreFlags(opts);
|
|
98
205
|
const cas = createCas(opts.cwd);
|
|
206
|
+
const treeOid = opts.oid || await cas.resolveVaultEntry({ slug: opts.slug });
|
|
207
|
+
const manifest = await cas.readManifest({ treeOid });
|
|
208
|
+
|
|
209
|
+
const restoreOpts = { manifest };
|
|
210
|
+
const encryptionKey = await resolveEncryptionKey(cas, opts);
|
|
211
|
+
if (encryptionKey) {
|
|
212
|
+
restoreOpts.encryptionKey = encryptionKey;
|
|
213
|
+
}
|
|
214
|
+
|
|
99
215
|
const service = await cas.getService();
|
|
216
|
+
const progress = createRestoreProgress({
|
|
217
|
+
totalChunks: manifest.chunks.length, quiet: program.opts().quiet,
|
|
218
|
+
});
|
|
219
|
+
progress.attach(service);
|
|
220
|
+
let bytesWritten;
|
|
221
|
+
try {
|
|
222
|
+
({ bytesWritten } = await cas.restoreFile({
|
|
223
|
+
...restoreOpts,
|
|
224
|
+
outputPath: opts.out,
|
|
225
|
+
}));
|
|
226
|
+
} finally {
|
|
227
|
+
progress.detach();
|
|
228
|
+
}
|
|
229
|
+
process.stdout.write(`${bytesWritten}\n`);
|
|
230
|
+
} catch (err) {
|
|
231
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
232
|
+
process.exit(1);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
100
235
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
236
|
+
// ---------------------------------------------------------------------------
|
|
237
|
+
// vault init
|
|
238
|
+
// ---------------------------------------------------------------------------
|
|
239
|
+
const vault = program
|
|
240
|
+
.command('vault')
|
|
241
|
+
.description('Manage the CAS vault');
|
|
242
|
+
|
|
243
|
+
vault
|
|
244
|
+
.command('init')
|
|
245
|
+
.description('Initialize the vault')
|
|
246
|
+
.option('--vault-passphrase <pass>', 'Passphrase for vault-level encryption (prefer GIT_CAS_PASSPHRASE env var)')
|
|
247
|
+
.option('--algorithm <alg>', 'KDF algorithm (pbkdf2 or scrypt)', 'pbkdf2')
|
|
248
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
249
|
+
.action(async (opts) => {
|
|
250
|
+
try {
|
|
251
|
+
const cas = createCas(opts.cwd);
|
|
252
|
+
const initOpts = {};
|
|
253
|
+
const passphrase = resolvePassphrase(opts);
|
|
254
|
+
if (passphrase) {
|
|
255
|
+
initOpts.passphrase = passphrase;
|
|
256
|
+
initOpts.kdfOptions = { algorithm: opts.algorithm };
|
|
109
257
|
}
|
|
258
|
+
const { commitOid } = await cas.initVault(initOpts);
|
|
259
|
+
process.stdout.write(`${commitOid}\n`);
|
|
260
|
+
} catch (err) {
|
|
261
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
262
|
+
process.exit(1);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// ---------------------------------------------------------------------------
|
|
267
|
+
// vault list
|
|
268
|
+
// ---------------------------------------------------------------------------
|
|
269
|
+
vault
|
|
270
|
+
.command('list')
|
|
271
|
+
.description('List vault entries')
|
|
272
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
273
|
+
.action(async (opts) => {
|
|
274
|
+
try {
|
|
275
|
+
const cas = createCas(opts.cwd);
|
|
276
|
+
const entries = await cas.listVault();
|
|
277
|
+
for (const { slug, treeOid } of entries) {
|
|
278
|
+
process.stdout.write(`${slug}\t${treeOid}\n`);
|
|
279
|
+
}
|
|
280
|
+
} catch (err) {
|
|
281
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
282
|
+
process.exit(1);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
110
285
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
286
|
+
// ---------------------------------------------------------------------------
|
|
287
|
+
// vault remove
|
|
288
|
+
// ---------------------------------------------------------------------------
|
|
289
|
+
vault
|
|
290
|
+
.command('remove <slug>')
|
|
291
|
+
.description('Remove an entry from the vault')
|
|
292
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
293
|
+
.action(async (slug, opts) => {
|
|
294
|
+
try {
|
|
295
|
+
const cas = createCas(opts.cwd);
|
|
296
|
+
const { removedTreeOid } = await cas.removeFromVault({ slug });
|
|
297
|
+
process.stdout.write(`${removedTreeOid}\n`);
|
|
298
|
+
} catch (err) {
|
|
299
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
300
|
+
process.exit(1);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
117
303
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
304
|
+
// ---------------------------------------------------------------------------
|
|
305
|
+
// vault info
|
|
306
|
+
// ---------------------------------------------------------------------------
|
|
307
|
+
vault
|
|
308
|
+
.command('info <slug>')
|
|
309
|
+
.description('Show info for a vault entry')
|
|
310
|
+
.option('--encryption', 'Show vault encryption details')
|
|
311
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
312
|
+
.action(async (slug, opts) => {
|
|
313
|
+
try {
|
|
314
|
+
const cas = createCas(opts.cwd);
|
|
315
|
+
const treeOid = await cas.resolveVaultEntry({ slug });
|
|
316
|
+
process.stdout.write(`slug\t${slug}\n`);
|
|
317
|
+
process.stdout.write(`tree\t${treeOid}\n`);
|
|
318
|
+
if (opts.encryption) {
|
|
319
|
+
const metadata = await cas.getVaultMetadata();
|
|
320
|
+
process.stdout.write(`\n${renderEncryptionCard({ metadata })}\n`);
|
|
121
321
|
}
|
|
322
|
+
} catch (err) {
|
|
323
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
324
|
+
process.exit(1);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
122
327
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
328
|
+
// ---------------------------------------------------------------------------
|
|
329
|
+
// vault history
|
|
330
|
+
// ---------------------------------------------------------------------------
|
|
331
|
+
vault
|
|
332
|
+
.command('history')
|
|
333
|
+
.description('Show vault commit history')
|
|
334
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
335
|
+
.option('-n, --max-count <n>', 'Limit number of commits')
|
|
336
|
+
.option('--pretty', 'Render as color-coded timeline')
|
|
337
|
+
.action(async (opts) => {
|
|
338
|
+
try {
|
|
339
|
+
const runner = ShellRunnerFactory.create();
|
|
340
|
+
const plumbing = new GitPlumbing({ runner, cwd: opts.cwd || '.' });
|
|
341
|
+
const args = ['log', '--oneline', ContentAddressableStore.VAULT_REF];
|
|
342
|
+
if (opts.maxCount) {
|
|
343
|
+
const n = parseInt(opts.maxCount, 10);
|
|
344
|
+
if (Number.isNaN(n) || n <= 0) {
|
|
345
|
+
process.stderr.write('error: --max-count must be a positive integer\n');
|
|
346
|
+
process.exit(1);
|
|
347
|
+
}
|
|
348
|
+
args.push(`-${n}`);
|
|
349
|
+
}
|
|
350
|
+
const output = await plumbing.execute({ args });
|
|
351
|
+
if (opts.pretty && process.stdout.isTTY) {
|
|
352
|
+
process.stdout.write(`${renderHistoryTimeline(output)}\n`);
|
|
353
|
+
} else {
|
|
354
|
+
process.stdout.write(`${output}\n`);
|
|
355
|
+
}
|
|
356
|
+
} catch (err) {
|
|
357
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
358
|
+
process.exit(1);
|
|
359
|
+
}
|
|
360
|
+
});
|
|
127
361
|
|
|
128
|
-
|
|
362
|
+
// ---------------------------------------------------------------------------
|
|
363
|
+
// vault dashboard
|
|
364
|
+
// ---------------------------------------------------------------------------
|
|
365
|
+
vault
|
|
366
|
+
.command('dashboard')
|
|
367
|
+
.description('Interactive vault explorer')
|
|
368
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
369
|
+
.action(async (opts) => {
|
|
370
|
+
try {
|
|
371
|
+
const cas = createCas(opts.cwd);
|
|
372
|
+
const { launchDashboard } = await import('./ui/dashboard.js');
|
|
373
|
+
await launchDashboard(cas);
|
|
129
374
|
} catch (err) {
|
|
130
375
|
process.stderr.write(`error: ${err.message}\n`);
|
|
131
376
|
process.exit(1);
|
|
132
377
|
}
|
|
133
378
|
});
|
|
134
379
|
|
|
135
|
-
program.
|
|
380
|
+
await program.parseAsync();
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared bijou context configured for CLI use (writes to stderr).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { createBijou } from '@flyingrobots/bijou';
|
|
6
|
+
import { nodeRuntime, chalkStyle } from '@flyingrobots/bijou-node';
|
|
7
|
+
|
|
8
|
+
let ctx = null;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Returns a bijou context that writes to stderr instead of stdout.
|
|
12
|
+
* Stdout is reserved for structured output (OIDs, JSON).
|
|
13
|
+
*/
|
|
14
|
+
export function getCliContext() {
|
|
15
|
+
if (ctx) {
|
|
16
|
+
return ctx;
|
|
17
|
+
}
|
|
18
|
+
const runtime = nodeRuntime();
|
|
19
|
+
const noColor = runtime.env('NO_COLOR') !== undefined;
|
|
20
|
+
ctx = createBijou({
|
|
21
|
+
runtime,
|
|
22
|
+
io: stderrIO(),
|
|
23
|
+
style: chalkStyle(noColor),
|
|
24
|
+
});
|
|
25
|
+
return ctx;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function stderrIO() {
|
|
29
|
+
return {
|
|
30
|
+
write(data) {
|
|
31
|
+
process.stderr.write(data);
|
|
32
|
+
},
|
|
33
|
+
question() {
|
|
34
|
+
throw new Error('question() not supported in CLI context');
|
|
35
|
+
},
|
|
36
|
+
rawInput() {
|
|
37
|
+
throw new Error('rawInput() not supported in CLI context');
|
|
38
|
+
},
|
|
39
|
+
onResize(callback) {
|
|
40
|
+
const handler = () => {
|
|
41
|
+
callback(process.stderr.columns ?? 80, process.stderr.rows ?? 24);
|
|
42
|
+
};
|
|
43
|
+
process.stderr.on('resize', handler);
|
|
44
|
+
return { dispose() { process.stderr.removeListener('resize', handler); } };
|
|
45
|
+
},
|
|
46
|
+
setInterval(callback, ms) {
|
|
47
|
+
const id = globalThis.setInterval(callback, ms);
|
|
48
|
+
return { dispose() { globalThis.clearInterval(id); } };
|
|
49
|
+
},
|
|
50
|
+
readFile() { throw new Error('readFile() not supported'); },
|
|
51
|
+
readDir() { throw new Error('readDir() not supported'); },
|
|
52
|
+
joinPath(...segments) { return segments.join('/'); },
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Async command factories for the vault dashboard.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Load vault entries and metadata in parallel.
|
|
7
|
+
*/
|
|
8
|
+
export function loadEntriesCmd(cas) {
|
|
9
|
+
return async () => {
|
|
10
|
+
try {
|
|
11
|
+
const [entries, metadata] = await Promise.all([
|
|
12
|
+
cas.listVault(),
|
|
13
|
+
cas.getVaultMetadata(),
|
|
14
|
+
]);
|
|
15
|
+
return { type: 'loaded-entries', entries, metadata };
|
|
16
|
+
} catch (err) {
|
|
17
|
+
return { type: 'load-error', source: 'entries', error: err.message };
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Load a single manifest by slug and tree OID.
|
|
24
|
+
*/
|
|
25
|
+
export function loadManifestCmd(cas, slug, treeOid) {
|
|
26
|
+
return async () => {
|
|
27
|
+
try {
|
|
28
|
+
const manifest = await cas.readManifest({ treeOid });
|
|
29
|
+
return { type: 'loaded-manifest', slug, manifest };
|
|
30
|
+
} catch (err) {
|
|
31
|
+
return { type: 'load-error', source: 'manifest', slug, error: err.message };
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|