@git-stunts/git-cas 3.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/README.md +54 -14
- package/bin/actions.js +54 -0
- package/bin/git-cas.js +254 -134
- 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/bin/ui/vault-list.js +63 -0
- package/index.d.ts +41 -1
- package/index.js +42 -8
- package/package.json +10 -1
- package/src/domain/services/CasService.d.ts +18 -2
- package/src/domain/services/CasService.js +181 -69
- package/src/domain/services/Semaphore.js +47 -0
- package/src/infrastructure/adapters/BunCryptoAdapter.js +12 -68
- package/src/infrastructure/adapters/EventEmitterObserver.js +70 -0
- package/src/infrastructure/adapters/NodeCryptoAdapter.js +11 -74
- package/src/infrastructure/adapters/SilentObserver.js +11 -0
- package/src/infrastructure/adapters/StatsCollector.js +45 -0
- package/src/infrastructure/adapters/WebCryptoAdapter.js +26 -81
- package/src/ports/CryptoPort.js +92 -1
- package/src/ports/ObservabilityPort.js +33 -0
package/bin/git-cas.js
CHANGED
|
@@ -3,13 +3,24 @@
|
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
4
|
import { program } from 'commander';
|
|
5
5
|
import GitPlumbing, { ShellRunnerFactory } from '@git-stunts/plumbing';
|
|
6
|
-
import ContentAddressableStore from '../index.js';
|
|
6
|
+
import ContentAddressableStore, { EventEmitterObserver } 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';
|
|
13
|
+
import { runAction } from './actions.js';
|
|
14
|
+
import { filterEntries, formatTable, formatTabSeparated } from './ui/vault-list.js';
|
|
15
|
+
|
|
16
|
+
const getJson = () => program.opts().json;
|
|
8
17
|
|
|
9
18
|
program
|
|
10
19
|
.name('git-cas')
|
|
11
20
|
.description('Content Addressable Storage backed by Git')
|
|
12
|
-
.version('
|
|
21
|
+
.version('4.0.1')
|
|
22
|
+
.option('-q, --quiet', 'Suppress progress output')
|
|
23
|
+
.option('--json', 'Output results as JSON');
|
|
13
24
|
|
|
14
25
|
/**
|
|
15
26
|
* Read a 32-byte raw encryption key from a file.
|
|
@@ -19,12 +30,12 @@ function readKeyFile(keyFilePath) {
|
|
|
19
30
|
}
|
|
20
31
|
|
|
21
32
|
/**
|
|
22
|
-
* Create a CAS instance for the given working directory.
|
|
33
|
+
* Create a CAS instance for the given working directory with an optional observability adapter.
|
|
23
34
|
*/
|
|
24
|
-
function createCas(cwd) {
|
|
35
|
+
function createCas(cwd, { observability } = {}) {
|
|
25
36
|
const runner = ShellRunnerFactory.create();
|
|
26
37
|
const plumbing = new GitPlumbing({ runner, cwd });
|
|
27
|
-
return new ContentAddressableStore({ plumbing });
|
|
38
|
+
return new ContentAddressableStore({ plumbing, observability });
|
|
28
39
|
}
|
|
29
40
|
|
|
30
41
|
/**
|
|
@@ -45,48 +56,40 @@ async function deriveVaultKey(cas, metadata, passphrase) {
|
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
/**
|
|
48
|
-
* Resolve
|
|
59
|
+
* Resolve passphrase from --vault-passphrase flag or GIT_CAS_PASSPHRASE env var.
|
|
60
|
+
*/
|
|
61
|
+
function resolvePassphrase(opts) {
|
|
62
|
+
return opts.vaultPassphrase ?? process.env.GIT_CAS_PASSPHRASE;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Resolve encryption key from --key-file or --vault-passphrase / GIT_CAS_PASSPHRASE.
|
|
49
67
|
*/
|
|
50
68
|
async function resolveEncryptionKey(cas, opts) {
|
|
51
69
|
if (opts.keyFile) {
|
|
52
70
|
return readKeyFile(opts.keyFile);
|
|
53
71
|
}
|
|
54
|
-
|
|
72
|
+
const passphrase = resolvePassphrase(opts);
|
|
73
|
+
if (!passphrase) {
|
|
55
74
|
return undefined;
|
|
56
75
|
}
|
|
57
76
|
const metadata = await cas.getVaultMetadata();
|
|
58
77
|
if (metadata?.encryption) {
|
|
59
|
-
return deriveVaultKey(cas, metadata,
|
|
78
|
+
return deriveVaultKey(cas, metadata, passphrase);
|
|
60
79
|
}
|
|
61
|
-
process.stderr.write('warning:
|
|
80
|
+
process.stderr.write('warning: passphrase ignored (vault is not encrypted)\n');
|
|
62
81
|
return undefined;
|
|
63
82
|
}
|
|
64
83
|
|
|
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
84
|
/**
|
|
80
85
|
* Validate --slug / --oid flags (exactly one required).
|
|
81
86
|
*/
|
|
82
87
|
function validateRestoreFlags(opts) {
|
|
83
88
|
if (opts.slug && opts.oid) {
|
|
84
|
-
|
|
85
|
-
process.exit(1);
|
|
89
|
+
throw new Error('Provide --slug or --oid, not both');
|
|
86
90
|
}
|
|
87
91
|
if (!opts.slug && !opts.oid) {
|
|
88
|
-
|
|
89
|
-
process.exit(1);
|
|
92
|
+
throw new Error('Provide --slug <slug> or --oid <tree-oid>');
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
|
|
@@ -100,31 +103,47 @@ program
|
|
|
100
103
|
.option('--key-file <path>', 'Path to 32-byte raw encryption key file')
|
|
101
104
|
.option('--tree', 'Also create a Git tree and print its OID')
|
|
102
105
|
.option('--force', 'Overwrite existing vault entry')
|
|
103
|
-
.option('--vault-passphrase <pass>', 'Vault-level passphrase for encryption')
|
|
106
|
+
.option('--vault-passphrase <pass>', 'Vault-level passphrase for encryption (prefer GIT_CAS_PASSPHRASE env var)')
|
|
104
107
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
105
|
-
.action(async (file, opts) => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
.action(runAction(async (file, opts) => {
|
|
109
|
+
const json = program.opts().json;
|
|
110
|
+
const quiet = program.opts().quiet || json;
|
|
111
|
+
const observer = new EventEmitterObserver();
|
|
112
|
+
const cas = createCas(opts.cwd, { observability: observer });
|
|
113
|
+
const encryptionKey = await resolveEncryptionKey(cas, opts);
|
|
114
|
+
if (opts.force && !opts.tree) {
|
|
115
|
+
throw new Error('--force requires --tree');
|
|
116
|
+
}
|
|
117
|
+
const storeOpts = { filePath: file, slug: opts.slug };
|
|
118
|
+
if (encryptionKey) {
|
|
119
|
+
storeOpts.encryptionKey = encryptionKey;
|
|
120
|
+
}
|
|
113
121
|
|
|
114
|
-
|
|
122
|
+
const progress = createStoreProgress({
|
|
123
|
+
filePath: file, chunkSize: cas.chunkSize, quiet,
|
|
124
|
+
});
|
|
125
|
+
progress.attach(observer);
|
|
126
|
+
let manifest;
|
|
127
|
+
try {
|
|
128
|
+
manifest = await cas.storeFile(storeOpts);
|
|
129
|
+
} finally {
|
|
130
|
+
progress.detach();
|
|
131
|
+
}
|
|
115
132
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
133
|
+
if (opts.tree) {
|
|
134
|
+
const treeOid = await cas.createTree({ manifest });
|
|
135
|
+
await cas.addToVault({ slug: opts.slug, treeOid, force: !!opts.force });
|
|
136
|
+
if (json) {
|
|
137
|
+
process.stdout.write(`${JSON.stringify({ treeOid })}\n`);
|
|
120
138
|
} else {
|
|
121
|
-
process.stdout.write(`${
|
|
139
|
+
process.stdout.write(`${treeOid}\n`);
|
|
122
140
|
}
|
|
123
|
-
}
|
|
124
|
-
process.
|
|
125
|
-
|
|
141
|
+
} else if (json) {
|
|
142
|
+
process.stdout.write(`${JSON.stringify({ manifest: manifest.toJSON() })}\n`);
|
|
143
|
+
} else {
|
|
144
|
+
process.stdout.write(`${JSON.stringify(manifest.toJSON(), null, 2)}\n`);
|
|
126
145
|
}
|
|
127
|
-
});
|
|
146
|
+
}, getJson));
|
|
128
147
|
|
|
129
148
|
// ---------------------------------------------------------------------------
|
|
130
149
|
// tree
|
|
@@ -134,18 +153,46 @@ program
|
|
|
134
153
|
.description('Create a Git tree from a manifest')
|
|
135
154
|
.requiredOption('--manifest <path>', 'Path to manifest JSON file')
|
|
136
155
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
137
|
-
.action(async (opts) => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
156
|
+
.action(runAction(async (opts) => {
|
|
157
|
+
const cas = createCas(opts.cwd);
|
|
158
|
+
const raw = readFileSync(opts.manifest, 'utf8');
|
|
159
|
+
const manifest = new Manifest(JSON.parse(raw));
|
|
160
|
+
const treeOid = await cas.createTree({ manifest });
|
|
161
|
+
const json = program.opts().json;
|
|
162
|
+
if (json) {
|
|
163
|
+
process.stdout.write(`${JSON.stringify({ treeOid })}\n`);
|
|
164
|
+
} else {
|
|
143
165
|
process.stdout.write(`${treeOid}\n`);
|
|
144
|
-
} catch (err) {
|
|
145
|
-
process.stderr.write(`error: ${err.message}\n`);
|
|
146
|
-
process.exit(1);
|
|
147
166
|
}
|
|
148
|
-
});
|
|
167
|
+
}, getJson));
|
|
168
|
+
|
|
169
|
+
// ---------------------------------------------------------------------------
|
|
170
|
+
// inspect
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
program
|
|
173
|
+
.command('inspect')
|
|
174
|
+
.description('Inspect a stored manifest')
|
|
175
|
+
.option('--slug <slug>', 'Resolve tree OID from vault slug')
|
|
176
|
+
.option('--oid <tree-oid>', 'Direct tree OID')
|
|
177
|
+
.option('--heatmap', 'Show chunk heatmap visualization')
|
|
178
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
179
|
+
.action(runAction(async (opts) => {
|
|
180
|
+
validateRestoreFlags(opts);
|
|
181
|
+
const cas = createCas(opts.cwd);
|
|
182
|
+
const treeOid = opts.oid || await cas.resolveVaultEntry({ slug: opts.slug });
|
|
183
|
+
const manifest = await cas.readManifest({ treeOid });
|
|
184
|
+
const json = program.opts().json;
|
|
185
|
+
|
|
186
|
+
if (json) {
|
|
187
|
+
process.stdout.write(`${JSON.stringify(manifest.toJSON())}\n`);
|
|
188
|
+
} else if (opts.heatmap) {
|
|
189
|
+
process.stdout.write(renderHeatmap({ manifest }));
|
|
190
|
+
} else if (process.stdout.isTTY) {
|
|
191
|
+
process.stdout.write(renderManifestView({ manifest }));
|
|
192
|
+
} else {
|
|
193
|
+
process.stdout.write(`${JSON.stringify(manifest.toJSON(), null, 2)}\n`);
|
|
194
|
+
}
|
|
195
|
+
}, getJson));
|
|
149
196
|
|
|
150
197
|
// ---------------------------------------------------------------------------
|
|
151
198
|
// restore
|
|
@@ -157,32 +204,68 @@ program
|
|
|
157
204
|
.option('--slug <slug>', 'Resolve tree OID from vault slug')
|
|
158
205
|
.option('--oid <tree-oid>', 'Direct tree OID')
|
|
159
206
|
.option('--key-file <path>', 'Path to 32-byte raw encryption key file')
|
|
160
|
-
.option('--vault-passphrase <pass>', 'Vault-level passphrase for decryption')
|
|
207
|
+
.option('--vault-passphrase <pass>', 'Vault-level passphrase for decryption (prefer GIT_CAS_PASSPHRASE env var)')
|
|
161
208
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
162
|
-
.action(async (opts) => {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
209
|
+
.action(runAction(async (opts) => {
|
|
210
|
+
validateRestoreFlags(opts);
|
|
211
|
+
const quiet = program.opts().quiet || program.opts().json;
|
|
212
|
+
const observer = new EventEmitterObserver();
|
|
213
|
+
const cas = createCas(opts.cwd, { observability: observer });
|
|
214
|
+
const treeOid = opts.oid || await cas.resolveVaultEntry({ slug: opts.slug });
|
|
215
|
+
const manifest = await cas.readManifest({ treeOid });
|
|
169
216
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
217
|
+
const restoreOpts = { manifest };
|
|
218
|
+
const encryptionKey = await resolveEncryptionKey(cas, opts);
|
|
219
|
+
if (encryptionKey) {
|
|
220
|
+
restoreOpts.encryptionKey = encryptionKey;
|
|
221
|
+
}
|
|
175
222
|
|
|
176
|
-
|
|
223
|
+
const progress = createRestoreProgress({
|
|
224
|
+
totalChunks: manifest.chunks.length, quiet,
|
|
225
|
+
});
|
|
226
|
+
progress.attach(observer);
|
|
227
|
+
let bytesWritten;
|
|
228
|
+
try {
|
|
229
|
+
({ bytesWritten } = await cas.restoreFile({
|
|
177
230
|
...restoreOpts,
|
|
178
231
|
outputPath: opts.out,
|
|
179
|
-
});
|
|
232
|
+
}));
|
|
233
|
+
} finally {
|
|
234
|
+
progress.detach();
|
|
235
|
+
}
|
|
236
|
+
const json = program.opts().json;
|
|
237
|
+
if (json) {
|
|
238
|
+
process.stdout.write(`${JSON.stringify({ bytesWritten })}\n`);
|
|
239
|
+
} else {
|
|
180
240
|
process.stdout.write(`${bytesWritten}\n`);
|
|
181
|
-
} catch (err) {
|
|
182
|
-
process.stderr.write(`error: ${err.message}\n`);
|
|
183
|
-
process.exit(1);
|
|
184
241
|
}
|
|
185
|
-
});
|
|
242
|
+
}, getJson));
|
|
243
|
+
|
|
244
|
+
// ---------------------------------------------------------------------------
|
|
245
|
+
// verify
|
|
246
|
+
// ---------------------------------------------------------------------------
|
|
247
|
+
program
|
|
248
|
+
.command('verify')
|
|
249
|
+
.description('Verify integrity of a stored asset (checks blob hashes; no key needed)')
|
|
250
|
+
.option('--slug <slug>', 'Resolve tree OID from vault slug')
|
|
251
|
+
.option('--oid <tree-oid>', 'Direct tree OID')
|
|
252
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
253
|
+
.action(runAction(async (opts) => {
|
|
254
|
+
validateRestoreFlags(opts);
|
|
255
|
+
const cas = createCas(opts.cwd);
|
|
256
|
+
const treeOid = opts.oid || await cas.resolveVaultEntry({ slug: opts.slug });
|
|
257
|
+
const manifest = await cas.readManifest({ treeOid });
|
|
258
|
+
const ok = await cas.verifyIntegrity(manifest);
|
|
259
|
+
const json = program.opts().json;
|
|
260
|
+
if (json) {
|
|
261
|
+
process.stdout.write(`${JSON.stringify({ ok, slug: manifest.slug, chunks: manifest.chunks.length })}\n`);
|
|
262
|
+
} else {
|
|
263
|
+
process.stdout.write(ok ? 'ok\n' : `fail: ${manifest.slug}\n`);
|
|
264
|
+
}
|
|
265
|
+
if (!ok) {
|
|
266
|
+
process.exitCode = 1;
|
|
267
|
+
}
|
|
268
|
+
}, getJson));
|
|
186
269
|
|
|
187
270
|
// ---------------------------------------------------------------------------
|
|
188
271
|
// vault init
|
|
@@ -194,24 +277,25 @@ const vault = program
|
|
|
194
277
|
vault
|
|
195
278
|
.command('init')
|
|
196
279
|
.description('Initialize the vault')
|
|
197
|
-
.option('--vault-passphrase <pass>', 'Passphrase for vault-level encryption')
|
|
280
|
+
.option('--vault-passphrase <pass>', 'Passphrase for vault-level encryption (prefer GIT_CAS_PASSPHRASE env var)')
|
|
198
281
|
.option('--algorithm <alg>', 'KDF algorithm (pbkdf2 or scrypt)', 'pbkdf2')
|
|
199
282
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
200
|
-
.action(async (opts) => {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
283
|
+
.action(runAction(async (opts) => {
|
|
284
|
+
const cas = createCas(opts.cwd);
|
|
285
|
+
const initOpts = {};
|
|
286
|
+
const passphrase = resolvePassphrase(opts);
|
|
287
|
+
if (passphrase) {
|
|
288
|
+
initOpts.passphrase = passphrase;
|
|
289
|
+
initOpts.kdfOptions = { algorithm: opts.algorithm };
|
|
290
|
+
}
|
|
291
|
+
const { commitOid } = await cas.initVault(initOpts);
|
|
292
|
+
const json = program.opts().json;
|
|
293
|
+
if (json) {
|
|
294
|
+
process.stdout.write(`${JSON.stringify({ commitOid })}\n`);
|
|
295
|
+
} else {
|
|
209
296
|
process.stdout.write(`${commitOid}\n`);
|
|
210
|
-
} catch (err) {
|
|
211
|
-
process.stderr.write(`error: ${err.message}\n`);
|
|
212
|
-
process.exit(1);
|
|
213
297
|
}
|
|
214
|
-
});
|
|
298
|
+
}, getJson));
|
|
215
299
|
|
|
216
300
|
// ---------------------------------------------------------------------------
|
|
217
301
|
// vault list
|
|
@@ -219,19 +303,21 @@ vault
|
|
|
219
303
|
vault
|
|
220
304
|
.command('list')
|
|
221
305
|
.description('List vault entries')
|
|
306
|
+
.option('--filter <pattern>', 'Filter entries by glob pattern')
|
|
222
307
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
223
|
-
.action(async (opts) => {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
process.
|
|
232
|
-
|
|
308
|
+
.action(runAction(async (opts) => {
|
|
309
|
+
const cas = createCas(opts.cwd);
|
|
310
|
+
const all = await cas.listVault();
|
|
311
|
+
const entries = filterEntries(all, opts.filter);
|
|
312
|
+
const json = program.opts().json;
|
|
313
|
+
if (json) {
|
|
314
|
+
process.stdout.write(`${JSON.stringify(entries)}\n`);
|
|
315
|
+
} else if (process.stdout.isTTY) {
|
|
316
|
+
process.stdout.write(formatTable(entries));
|
|
317
|
+
} else {
|
|
318
|
+
process.stdout.write(formatTabSeparated(entries));
|
|
233
319
|
}
|
|
234
|
-
});
|
|
320
|
+
}, getJson));
|
|
235
321
|
|
|
236
322
|
// ---------------------------------------------------------------------------
|
|
237
323
|
// vault remove
|
|
@@ -240,16 +326,16 @@ vault
|
|
|
240
326
|
.command('remove <slug>')
|
|
241
327
|
.description('Remove an entry from the vault')
|
|
242
328
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
243
|
-
.action(async (slug, opts) => {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
329
|
+
.action(runAction(async (slug, opts) => {
|
|
330
|
+
const cas = createCas(opts.cwd);
|
|
331
|
+
const { commitOid, removedTreeOid } = await cas.removeFromVault({ slug });
|
|
332
|
+
const json = program.opts().json;
|
|
333
|
+
if (json) {
|
|
334
|
+
process.stdout.write(`${JSON.stringify({ commitOid, removedTreeOid })}\n`);
|
|
335
|
+
} else {
|
|
247
336
|
process.stdout.write(`${removedTreeOid}\n`);
|
|
248
|
-
} catch (err) {
|
|
249
|
-
process.stderr.write(`error: ${err.message}\n`);
|
|
250
|
-
process.exit(1);
|
|
251
337
|
}
|
|
252
|
-
});
|
|
338
|
+
}, getJson));
|
|
253
339
|
|
|
254
340
|
// ---------------------------------------------------------------------------
|
|
255
341
|
// vault info
|
|
@@ -257,18 +343,30 @@ vault
|
|
|
257
343
|
vault
|
|
258
344
|
.command('info <slug>')
|
|
259
345
|
.description('Show info for a vault entry')
|
|
346
|
+
.option('--encryption', 'Show vault encryption details')
|
|
260
347
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
261
|
-
.action(async (slug, opts) => {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
348
|
+
.action(runAction(async (slug, opts) => {
|
|
349
|
+
const cas = createCas(opts.cwd);
|
|
350
|
+
const treeOid = await cas.resolveVaultEntry({ slug });
|
|
351
|
+
const json = program.opts().json;
|
|
352
|
+
if (json) {
|
|
353
|
+
const result = { slug, treeOid };
|
|
354
|
+
if (opts.encryption) {
|
|
355
|
+
const metadata = await cas.getVaultMetadata();
|
|
356
|
+
if (metadata?.encryption) {
|
|
357
|
+
result.encryption = metadata.encryption;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
361
|
+
} else {
|
|
265
362
|
process.stdout.write(`slug\t${slug}\n`);
|
|
266
363
|
process.stdout.write(`tree\t${treeOid}\n`);
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
364
|
+
if (opts.encryption) {
|
|
365
|
+
const metadata = await cas.getVaultMetadata();
|
|
366
|
+
process.stdout.write(`\n${renderEncryptionCard({ metadata })}\n`);
|
|
367
|
+
}
|
|
270
368
|
}
|
|
271
|
-
});
|
|
369
|
+
}, getJson));
|
|
272
370
|
|
|
273
371
|
// ---------------------------------------------------------------------------
|
|
274
372
|
// vault history
|
|
@@ -278,25 +376,47 @@ vault
|
|
|
278
376
|
.description('Show vault commit history')
|
|
279
377
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
280
378
|
.option('-n, --max-count <n>', 'Limit number of commits')
|
|
281
|
-
.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
process.exit(1);
|
|
291
|
-
}
|
|
292
|
-
args.push(`-${n}`);
|
|
379
|
+
.option('--pretty', 'Render as color-coded timeline')
|
|
380
|
+
.action(runAction(async (opts) => {
|
|
381
|
+
const runner = ShellRunnerFactory.create();
|
|
382
|
+
const plumbing = new GitPlumbing({ runner, cwd: opts.cwd || '.' });
|
|
383
|
+
const args = ['log', '--oneline', ContentAddressableStore.VAULT_REF];
|
|
384
|
+
if (opts.maxCount) {
|
|
385
|
+
const n = parseInt(opts.maxCount, 10);
|
|
386
|
+
if (Number.isNaN(n) || n <= 0) {
|
|
387
|
+
throw new Error('--max-count must be a positive integer');
|
|
293
388
|
}
|
|
294
|
-
|
|
389
|
+
args.push(`-${n}`);
|
|
390
|
+
}
|
|
391
|
+
const output = await plumbing.execute({ args });
|
|
392
|
+
const json = program.opts().json;
|
|
393
|
+
if (json) {
|
|
394
|
+
const history = output
|
|
395
|
+
.split('\n')
|
|
396
|
+
.filter(Boolean)
|
|
397
|
+
.map((line) => {
|
|
398
|
+
const [commitOid, ...messageParts] = line.trim().split(/\s+/);
|
|
399
|
+
return { commitOid, message: messageParts.join(' ') };
|
|
400
|
+
});
|
|
401
|
+
process.stdout.write(`${JSON.stringify(history)}\n`);
|
|
402
|
+
} else if (opts.pretty && process.stdout.isTTY) {
|
|
403
|
+
process.stdout.write(`${renderHistoryTimeline(output)}\n`);
|
|
404
|
+
} else {
|
|
295
405
|
process.stdout.write(`${output}\n`);
|
|
296
|
-
} catch (err) {
|
|
297
|
-
process.stderr.write(`error: ${err.message}\n`);
|
|
298
|
-
process.exit(1);
|
|
299
406
|
}
|
|
300
|
-
});
|
|
407
|
+
}, getJson));
|
|
408
|
+
|
|
409
|
+
// ---------------------------------------------------------------------------
|
|
410
|
+
// vault dashboard
|
|
411
|
+
// ---------------------------------------------------------------------------
|
|
412
|
+
vault
|
|
413
|
+
.command('dashboard')
|
|
414
|
+
.description('Interactive vault explorer')
|
|
415
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
416
|
+
.action(runAction(async (opts) => {
|
|
417
|
+
const cas = createCas(opts.cwd);
|
|
418
|
+
const { launchDashboard } = await import('./ui/dashboard.js');
|
|
419
|
+
await launchDashboard(cas);
|
|
420
|
+
}, getJson));
|
|
301
421
|
|
|
302
|
-
await program.parseAsync();
|
|
422
|
+
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
|
+
}
|