@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/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('3.0.0');
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 encryption key from --key-file or --vault-passphrase.
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
- if (!opts.vaultPassphrase) {
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, opts.vaultPassphrase);
78
+ return deriveVaultKey(cas, metadata, passphrase);
60
79
  }
61
- process.stderr.write('warning: --vault-passphrase ignored (vault is not encrypted)\n');
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
- process.stderr.write('error: Provide --slug or --oid, not both\n');
85
- process.exit(1);
89
+ throw new Error('Provide --slug or --oid, not both');
86
90
  }
87
91
  if (!opts.slug && !opts.oid) {
88
- process.stderr.write('error: Provide --slug <slug> or --oid <tree-oid>\n');
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
- try {
107
- const cas = createCas(opts.cwd);
108
- const encryptionKey = await resolveEncryptionKey(cas, opts);
109
- const storeOpts = { filePath: file, slug: opts.slug };
110
- if (encryptionKey) {
111
- storeOpts.encryptionKey = encryptionKey;
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
- const manifest = await cas.storeFile(storeOpts);
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
- if (opts.tree) {
117
- const treeOid = await cas.createTree({ manifest });
118
- await cas.addToVault({ slug: opts.slug, treeOid, force: !!opts.force });
119
- process.stdout.write(`${treeOid}\n`);
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(`${JSON.stringify(manifest.toJSON(), null, 2)}\n`);
139
+ process.stdout.write(`${treeOid}\n`);
122
140
  }
123
- } catch (err) {
124
- process.stderr.write(`error: ${err.message}\n`);
125
- process.exit(1);
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
- try {
139
- const cas = createCas(opts.cwd);
140
- const raw = readFileSync(opts.manifest, 'utf8');
141
- const manifest = new Manifest(JSON.parse(raw));
142
- const treeOid = await cas.createTree({ manifest });
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
- try {
164
- validateRestoreFlags(opts);
165
- const cas = createCas(opts.cwd);
166
- const treeOid = opts.oid || await cas.resolveVaultEntry({ slug: opts.slug });
167
- const service = await cas.getService();
168
- const manifest = await readManifestFromTree(service, treeOid);
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
- const restoreOpts = { manifest };
171
- const encryptionKey = await resolveEncryptionKey(cas, opts);
172
- if (encryptionKey) {
173
- restoreOpts.encryptionKey = encryptionKey;
174
- }
217
+ const restoreOpts = { manifest };
218
+ const encryptionKey = await resolveEncryptionKey(cas, opts);
219
+ if (encryptionKey) {
220
+ restoreOpts.encryptionKey = encryptionKey;
221
+ }
175
222
 
176
- const { bytesWritten } = await cas.restoreFile({
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
- 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);
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
- 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);
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
- try {
245
- const cas = createCas(opts.cwd);
246
- const { removedTreeOid } = await cas.removeFromVault({ slug });
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
- try {
263
- const cas = createCas(opts.cwd);
264
- const treeOid = await cas.resolveVaultEntry({ slug });
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
- } catch (err) {
268
- process.stderr.write(`error: ${err.message}\n`);
269
- process.exit(1);
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
- .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}`);
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
- const output = await plumbing.execute({ args });
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
+ }