@git-stunts/git-cas 6.0.0 → 6.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.
@@ -137,10 +137,18 @@ const FULL_COLUMNS = [
137
137
  ];
138
138
 
139
139
  function formatSize(bytes) {
140
- if (!Number.isFinite(bytes)) { return '-'; }
141
- if (bytes < 1024) { return `${bytes}B`; }
142
- if (bytes < 1024 * 1024) { return `${(bytes / 1024).toFixed(1)}K`; }
143
- if (bytes < 1024 * 1024 * 1024) { return `${(bytes / (1024 * 1024)).toFixed(1)}M`; }
140
+ if (!Number.isFinite(bytes)) {
141
+ return '-';
142
+ }
143
+ if (bytes < 1024) {
144
+ return `${bytes}B`;
145
+ }
146
+ if (bytes < 1024 * 1024) {
147
+ return `${(bytes / 1024).toFixed(1)}K`;
148
+ }
149
+ if (bytes < 1024 * 1024 * 1024) {
150
+ return `${(bytes / (1024 * 1024)).toFixed(1)}M`;
151
+ }
144
152
  return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)}G`;
145
153
  }
146
154
 
@@ -153,20 +161,30 @@ function manifestFor(entry, manifestCache) {
153
161
  }
154
162
 
155
163
  function cryptoLabel(manifest) {
156
- if (!manifest) { return '-'; }
157
- if (manifest.encryption?.encrypted || manifest.encryption?.recipients?.length || manifest.encryption) {
164
+ if (!manifest) {
165
+ return '-';
166
+ }
167
+ if (
168
+ manifest.encryption?.encrypted ||
169
+ manifest.encryption?.recipients?.length ||
170
+ manifest.encryption
171
+ ) {
158
172
  return 'encrypted';
159
173
  }
160
174
  return 'plain';
161
175
  }
162
176
 
163
177
  function formatLabel(manifest) {
164
- if (!manifest) { return '-'; }
178
+ if (!manifest) {
179
+ return '-';
180
+ }
165
181
  return manifest.formatVersion ?? (manifest.version ? `v${manifest.version}` : 'manifest');
166
182
  }
167
183
 
168
184
  function chunkLabel(manifest) {
169
- if (!manifest) { return '-'; }
185
+ if (!manifest) {
186
+ return '-';
187
+ }
170
188
  const chunks = manifest.chunks?.length ?? 0;
171
189
  const subManifests = manifest.subManifests?.length ?? 0;
172
190
  return subManifests > 0 ? `${chunks}+${subManifests}` : String(chunks);
@@ -199,7 +217,9 @@ function sourceEquals(left, right) {
199
217
 
200
218
  function filterEntries(entries, filterText, manifestCache) {
201
219
  const query = filterText.trim().toLowerCase();
202
- if (!query) { return entries; }
220
+ if (!query) {
221
+ return entries;
222
+ }
203
223
  return entries.filter((entry) => {
204
224
  const manifest = manifestFor(entry, manifestCache);
205
225
  const haystack = [
@@ -208,7 +228,10 @@ function filterEntries(entries, filterText, manifestCache) {
208
228
  manifest?.integrity,
209
229
  manifest?.hash,
210
230
  ...(manifest?.chunks ?? []).flatMap((chunk) => [chunk.digest, chunk.blob]),
211
- ].filter(Boolean).join(' ').toLowerCase();
231
+ ]
232
+ .filter(Boolean)
233
+ .join(' ')
234
+ .toLowerCase();
212
235
  return haystack.includes(query);
213
236
  });
214
237
  }
@@ -227,7 +250,9 @@ function syncExplorer(model, patch = {}) {
227
250
  }
228
251
 
229
252
  function selectedEntry(model) {
230
- return model.filtered[Math.min(model.table.focusRow, Math.max(0, model.filtered.length - 1))] ?? null;
253
+ return (
254
+ model.filtered[Math.min(model.table.focusRow, Math.max(0, model.filtered.length - 1))] ?? null
255
+ );
231
256
  }
232
257
 
233
258
  function selectedManifest(model) {
@@ -239,7 +264,11 @@ function maybeLoadSelectedManifest(model, deps) {
239
264
  if (!entry || model.manifestCache.has(entry.slug) || model.loadingSlug === entry.slug) {
240
265
  return null;
241
266
  }
242
- return loadManifestCmd(deps.cas, { slug: entry.slug, treeOid: entry.treeOid, source: model.source });
267
+ return loadManifestCmd(deps.cas, {
268
+ slug: entry.slug,
269
+ treeOid: entry.treeOid,
270
+ source: model.source,
271
+ });
243
272
  }
244
273
 
245
274
  function createShellState(columns, rows, source) {
@@ -279,7 +308,11 @@ function createExplorerState(rows) {
279
308
  manifestCache: new Map(),
280
309
  loadingSlug: null,
281
310
  error: null,
282
- table: createNavigableTableState({ columns: FULL_COLUMNS, rows: [], height: tableHeight(rows) }),
311
+ table: createNavigableTableState({
312
+ columns: FULL_COLUMNS,
313
+ rows: [],
314
+ height: tableHeight(rows),
315
+ }),
283
316
  palette: null,
284
317
  showHelp: false,
285
318
  };
@@ -332,7 +365,12 @@ function checkVaultAuthCmd(cas) {
332
365
  }
333
366
  try {
334
367
  const all = await cas.listVault();
335
- return { type: 'vault-auth-check', encrypted: Boolean(metadata?.encryption), entryCount: all.length, metadata };
368
+ return {
369
+ type: 'vault-auth-check',
370
+ encrypted: Boolean(metadata?.encryption),
371
+ entryCount: all.length,
372
+ metadata,
373
+ };
336
374
  } catch {
337
375
  return { type: 'vault-auth-check', encrypted: false, entryCount: 0, metadata: null };
338
376
  }
@@ -341,7 +379,9 @@ function checkVaultAuthCmd(cas) {
341
379
 
342
380
  async function deriveVaultKey(cas, metadata, passphrase) {
343
381
  const kdf = metadata?.encryption?.kdf;
344
- if (!kdf) { throw new Error('Missing vault encryption KDF metadata'); }
382
+ if (!kdf) {
383
+ throw new Error('Missing vault encryption KDF metadata');
384
+ }
345
385
  const { key } = await cas.deriveKey({
346
386
  passphrase,
347
387
  salt: Buffer.from(kdf.salt, 'base64'),
@@ -377,22 +417,33 @@ function verifyPassphraseCmd(cas, passphrase) {
377
417
  ? { type: 'vault-auth-ok', encryptionKey }
378
418
  : { type: 'vault-auth-fail', error: 'Wrong passphrase' };
379
419
  } catch (err) {
380
- const authErrorCodes = ['INTEGRITY_ERROR', 'DEK_UNWRAP_FAILED', 'MISSING_KEY', 'NO_MATCHING_RECIPIENT'];
381
- const msg = authErrorCodes.includes(err.code) ? 'Wrong passphrase' : (err.message ?? String(err));
420
+ const authErrorCodes = [
421
+ 'INTEGRITY_ERROR',
422
+ 'DEK_UNWRAP_FAILED',
423
+ 'MISSING_KEY',
424
+ 'NO_MATCHING_RECIPIENT',
425
+ ];
426
+ const msg = authErrorCodes.includes(err.code)
427
+ ? 'Wrong passphrase'
428
+ : (err.message ?? String(err));
382
429
  return { type: 'vault-auth-fail', error: msg };
383
430
  }
384
431
  };
385
432
  }
386
433
 
387
434
  function casForModel(cas, model) {
388
- if (!model.vaultEncryptionKey) { return cas; }
435
+ if (!model.vaultEncryptionKey) {
436
+ return cas;
437
+ }
389
438
  return new Proxy(cas, {
390
439
  get(target, prop, receiver) {
391
440
  if (prop === 'listVault') {
392
- return (options = {}) => target.listVault({ ...options, encryptionKey: model.vaultEncryptionKey });
441
+ return (options = {}) =>
442
+ target.listVault({ ...options, encryptionKey: model.vaultEncryptionKey });
393
443
  }
394
444
  if (prop === 'addToVault') {
395
- return (options = {}) => target.addToVault({ ...options, encryptionKey: model.vaultEncryptionKey });
445
+ return (options = {}) =>
446
+ target.addToVault({ ...options, encryptionKey: model.vaultEncryptionKey });
396
447
  }
397
448
  const value = Reflect.get(target, prop, receiver);
398
449
  return typeof value === 'function' ? value.bind(target) : value;
@@ -400,20 +451,48 @@ function casForModel(cas, model) {
400
451
  });
401
452
  }
402
453
 
454
+ const WIZARD_GZIP_COMPRESSION = Object.freeze({ algorithm: 'gzip' });
455
+ const WIZARD_CHUNKING_CONFIG = Object.freeze({
456
+ fixed: Object.freeze({ strategy: 'fixed' }),
457
+ cdc: Object.freeze({ strategy: 'cdc' }),
458
+ });
459
+ const WIZARD_MISSING_PASSPHRASE_MESSAGE = 'Encryption passphrase is required';
460
+
461
+ function validateStoreWizardPlan(wizard) {
462
+ if (!wizard.passphrase) {
463
+ return wizard.encryption === 'none' ? null : WIZARD_MISSING_PASSPHRASE_MESSAGE;
464
+ }
465
+ return null;
466
+ }
467
+
468
+ function storeWizardEncryptionOptions(wizard) {
469
+ if (wizard.encryption === 'none') {
470
+ return {};
471
+ }
472
+ if (wizard.encryption === 'convergent') {
473
+ return { passphrase: wizard.passphrase, encryption: { scheme: 'convergent' } };
474
+ }
475
+ return { passphrase: wizard.passphrase };
476
+ }
477
+
478
+ function buildStoreWizardOptions(wizard) {
479
+ return {
480
+ filePath: wizard.filePath,
481
+ slug: wizard.slug,
482
+ ...storeWizardEncryptionOptions(wizard),
483
+ ...(wizard.compression ? { compression: WIZARD_GZIP_COMPRESSION } : {}),
484
+ chunking: WIZARD_CHUNKING_CONFIG[wizard.chunking],
485
+ };
486
+ }
487
+
403
488
  function runStoreWizardCmd(cas, wizard) {
404
489
  return async () => {
405
490
  try {
406
- if (wizard.encryption !== 'none') {
407
- return {
408
- type: 'store-error',
409
- error: 'The TUI store path currently supports plaintext store plans only. Use the CLI for passphrase or convergent encryption.',
410
- };
491
+ const validationError = validateStoreWizardPlan(wizard);
492
+ if (validationError) {
493
+ return { type: 'store-error', error: validationError };
411
494
  }
412
- const manifest = await cas.storeFile({
413
- filePath: wizard.filePath,
414
- slug: wizard.slug,
415
- ...(wizard.compression ? { compression: { algorithm: 'gzip' } } : {}),
416
- });
495
+ const manifest = await cas.storeFile(buildStoreWizardOptions(wizard));
417
496
  const treeOid = await cas.createTree({ manifest });
418
497
  await cas.addToVault({ slug: wizard.slug, treeOid, force: true });
419
498
  return { type: 'store-complete', slug: wizard.slug, treeOid, manifest };
@@ -425,28 +504,31 @@ function runStoreWizardCmd(cas, wizard) {
425
504
 
426
505
  function enterDashboard(model, deps) {
427
506
  const cas = casForModel(deps.cas, model);
428
- return [{
429
- ...model,
430
- phase: 'dashboard',
431
- promptEnter: false,
432
- authError: null,
433
- status: 'loading entries',
434
- }, [
435
- loadEntriesCmd(cas, model.source),
436
- loadBranchCmd(cas),
437
- loadRefsCmd(cas),
438
- ]];
507
+ return [
508
+ {
509
+ ...model,
510
+ phase: 'dashboard',
511
+ promptEnter: false,
512
+ authError: null,
513
+ status: 'loading entries',
514
+ },
515
+ [loadEntriesCmd(cas, model.source), loadBranchCmd(cas), loadRefsCmd(cas)],
516
+ ];
439
517
  }
440
518
 
441
519
  function pushToast(model, spec) {
442
520
  return {
443
521
  ...model,
444
- notifications: pushNotification(model.notifications, {
445
- variant: 'TOAST',
446
- placement: 'LOWER_RIGHT',
447
- width: 42,
448
- ...spec,
449
- }, Date.now()),
522
+ notifications: pushNotification(
523
+ model.notifications,
524
+ {
525
+ variant: 'TOAST',
526
+ placement: 'LOWER_RIGHT',
527
+ width: 42,
528
+ ...spec,
529
+ },
530
+ Date.now()
531
+ ),
450
532
  };
451
533
  }
452
534
 
@@ -467,35 +549,46 @@ function handleTickMsg(msg, model, deps) {
467
549
  const now = Date.now();
468
550
  const elapsed = now - (model.lastTickTime || now);
469
551
  const fps = elapsed > 0 ? Math.round(1000 / elapsed) : 0;
470
- return [{
471
- ...model,
472
- titleTimeMs: (model.titleTimeMs || 0) + TITLE_TICK_MS,
473
- lastTickTime: now,
474
- fps: model.lastTickTime ? fps : 0,
475
- }, [deps.tick(TITLE_TICK_MS, { type: 'title-tick' })]];
552
+ return [
553
+ {
554
+ ...model,
555
+ titleTimeMs: (model.titleTimeMs || 0) + TITLE_TICK_MS,
556
+ lastTickTime: now,
557
+ fps: model.lastTickTime ? fps : 0,
558
+ },
559
+ [deps.tick(TITLE_TICK_MS, { type: 'title-tick' })],
560
+ ];
476
561
  }
477
562
 
478
563
  function handleVaultAuthCheck(msg, model) {
479
564
  if (msg.encrypted) {
480
- return [{
565
+ return [
566
+ {
567
+ ...model,
568
+ phase: 'password',
569
+ metadata: msg.metadata,
570
+ vaultEntryCount: msg.entryCount,
571
+ status: 'vault locked',
572
+ },
573
+ [],
574
+ ];
575
+ }
576
+ return [
577
+ {
481
578
  ...model,
482
- phase: 'password',
483
579
  metadata: msg.metadata,
580
+ promptEnter: true,
484
581
  vaultEntryCount: msg.entryCount,
485
- status: 'vault locked',
486
- }, []];
487
- }
488
- return [{
489
- ...model,
490
- metadata: msg.metadata,
491
- promptEnter: true,
492
- vaultEntryCount: msg.entryCount,
493
- status: 'vault ready',
494
- }, []];
582
+ status: 'vault ready',
583
+ },
584
+ [],
585
+ ];
495
586
  }
496
587
 
497
588
  function handleLoadedEntries(msg, model, deps) {
498
- if (!sourceEquals(msg.source, model.source)) { return [model, []]; }
589
+ if (!sourceEquals(msg.source, model.source)) {
590
+ return [model, []];
591
+ }
499
592
  const next = syncExplorer(model, {
500
593
  entries: msg.entries,
501
594
  metadata: msg.metadata,
@@ -503,14 +596,16 @@ function handleLoadedEntries(msg, model, deps) {
503
596
  error: null,
504
597
  });
505
598
  const manifestCmd = maybeLoadSelectedManifest(next, deps);
506
- return [next, [
507
- loadStatsCmd(deps.cas, msg.entries, model.source),
508
- ...(manifestCmd ? [manifestCmd] : []),
509
- ]];
599
+ return [
600
+ next,
601
+ [loadStatsCmd(deps.cas, msg.entries, model.source), ...(manifestCmd ? [manifestCmd] : [])],
602
+ ];
510
603
  }
511
604
 
512
605
  function handleLoadedManifest(msg, model) {
513
- if (!sourceEquals(msg.source, model.source)) { return [model, []]; }
606
+ if (!sourceEquals(msg.source, model.source)) {
607
+ return [model, []];
608
+ }
514
609
  const manifestCache = new Map(model.manifestCache);
515
610
  manifestCache.set(msg.slug, msg.manifest);
516
611
  return [syncExplorer(model, { manifestCache, loadingSlug: null }), []];
@@ -548,17 +643,30 @@ function handleLoadedRefsMsg(msg, model) {
548
643
  }
549
644
 
550
645
  function handleLoadedStatsMsg(msg, model) {
551
- if (!sourceEquals(msg.source, model.source)) { return [model, []]; }
646
+ if (!sourceEquals(msg.source, model.source)) {
647
+ return [model, []];
648
+ }
552
649
  return [{ ...model, statsStatus: 'ready', statsReport: msg.stats, statsError: null }, []];
553
650
  }
554
651
 
555
652
  function handleLoadedDoctorMsg(msg, model) {
556
- if (!sourceEquals(msg.source, model.source)) { return [model, []]; }
653
+ if (!sourceEquals(msg.source, model.source)) {
654
+ return [model, []];
655
+ }
557
656
  return [{ ...model, doctorStatus: 'ready', doctorReport: msg.report, doctorError: null }, []];
558
657
  }
559
658
 
560
659
  function handleLoadedTreemapMsg(msg, model) {
561
- return [{ ...model, treemapStatus: 'ready', treemapReport: msg.report, treemapFocus: 0, treemapError: null }, []];
660
+ return [
661
+ {
662
+ ...model,
663
+ treemapStatus: 'ready',
664
+ treemapReport: msg.report,
665
+ treemapFocus: 0,
666
+ treemapError: null,
667
+ },
668
+ [],
669
+ ];
562
670
  }
563
671
 
564
672
  function handleLoadedBranchMsg(msg, model) {
@@ -568,19 +676,34 @@ function handleLoadedBranchMsg(msg, model) {
568
676
  function handleStoreCompleteMsg(msg, model, deps) {
569
677
  const manifestCache = new Map(model.manifestCache);
570
678
  manifestCache.set(msg.slug, msg.manifest);
571
- const next = pushToast({
572
- ...syncExplorer(model, { manifestCache, storeWizard: null }),
573
- operationFeed: completeLatestOperation(model.operationFeed, msg.slug, null),
574
- }, { title: 'Stored asset', message: `${msg.slug} -> ${shortenSha(msg.treeOid)}`, tone: 'SUCCESS' });
575
- return [next, [loadEntriesCmd(casForModel(deps.cas, model), model.source), ...notificationTick(next, deps)]];
679
+ const next = pushToast(
680
+ {
681
+ ...syncExplorer(model, { manifestCache, storeWizard: null }),
682
+ operationFeed: completeLatestOperation(model.operationFeed, msg.slug, null),
683
+ },
684
+ { title: 'Stored asset', message: `${msg.slug} -> ${shortenSha(msg.treeOid)}`, tone: 'SUCCESS' }
685
+ );
686
+ return [
687
+ next,
688
+ [loadEntriesCmd(casForModel(deps.cas, model), model.source), ...notificationTick(next, deps)],
689
+ ];
576
690
  }
577
691
 
578
692
  function handleStoreErrorMsg(msg, model, deps) {
579
- const next = pushToast({
580
- ...model,
581
- storeWizard: model.storeWizard ? { ...model.storeWizard, step: 'error', error: msg.error } : null,
582
- operationFeed: completeLatestOperation(model.operationFeed, model.storeWizard?.slug ?? 'store', msg.error),
583
- }, { title: 'Store failed', message: msg.error, tone: 'ERROR' });
693
+ const next = pushToast(
694
+ {
695
+ ...model,
696
+ storeWizard: model.storeWizard
697
+ ? { ...model.storeWizard, step: 'error', error: msg.error }
698
+ : null,
699
+ operationFeed: completeLatestOperation(
700
+ model.operationFeed,
701
+ model.storeWizard?.slug ?? 'store',
702
+ msg.error
703
+ ),
704
+ },
705
+ { title: 'Store failed', message: msg.error, tone: 'ERROR' }
706
+ );
584
707
  return [next, notificationTick(next, deps)];
585
708
  }
586
709
 
@@ -608,15 +731,25 @@ function handleAppMsg(msg, model, deps) {
608
731
  }
609
732
 
610
733
  function handleTitleKey(msg, model, deps) {
611
- if (msg.key === '`') { return [{ ...model, showPerfHud: !model.showPerfHud }, []]; }
612
- if (msg.key === 'q' || msg.key === 'escape') { return [model, [quit()]]; }
613
- if (msg.key === 'enter' && model.promptEnter) { return enterDashboard(model, deps); }
734
+ if (msg.key === '`') {
735
+ return [{ ...model, showPerfHud: !model.showPerfHud }, []];
736
+ }
737
+ if (msg.key === 'q' || msg.key === 'escape') {
738
+ return [model, [quit()]];
739
+ }
740
+ if (msg.key === 'enter' && model.promptEnter) {
741
+ return enterDashboard(model, deps);
742
+ }
614
743
  return [model, []];
615
744
  }
616
745
 
617
746
  function handlePasswordKey(msg, model, deps) {
618
- if (msg.key === '`') { return [{ ...model, showPerfHud: !model.showPerfHud }, []]; }
619
- if (msg.key === 'escape') { return [model, [quit()]]; }
747
+ if (msg.key === '`') {
748
+ return [{ ...model, showPerfHud: !model.showPerfHud }, []];
749
+ }
750
+ if (msg.key === 'escape') {
751
+ return [model, [quit()]];
752
+ }
620
753
  if (msg.key === 'enter') {
621
754
  return [{ ...model, authError: null }, [verifyPassphraseCmd(deps.cas, model.passphrase)]];
622
755
  }
@@ -657,7 +790,9 @@ function openPalette(model) {
657
790
 
658
791
  function selectPaletteItem(model, deps) {
659
792
  const item = cpSelectedItem(model.palette);
660
- if (!item) { return [{ ...model, palette: null }, []]; }
793
+ if (!item) {
794
+ return [{ ...model, palette: null }, []];
795
+ }
661
796
  const selected = model.entries.find((entry) => entry.slug === item.id);
662
797
  const next = syncExplorer(model, {
663
798
  workspace: 'explorer',
@@ -689,32 +824,50 @@ const PALETTE_KEY_ACTIONS = {
689
824
  };
690
825
 
691
826
  function paletteAction(msg) {
692
- if (msg.ctrl && msg.key === 'n') { return 'next'; }
693
- if (msg.ctrl && msg.key === 'p') { return 'previous'; }
694
- if (msg.ctrl && msg.key === 'd') { return 'pageDown'; }
695
- if (msg.ctrl && msg.key === 'u') { return 'pageUp'; }
827
+ if (msg.ctrl && msg.key === 'n') {
828
+ return 'next';
829
+ }
830
+ if (msg.ctrl && msg.key === 'p') {
831
+ return 'previous';
832
+ }
833
+ if (msg.ctrl && msg.key === 'd') {
834
+ return 'pageDown';
835
+ }
836
+ if (msg.ctrl && msg.key === 'u') {
837
+ return 'pageUp';
838
+ }
696
839
  return PALETTE_KEY_ACTIONS[msg.key] ?? null;
697
840
  }
698
841
 
699
842
  function paletteQueryForKey(msg, palette) {
700
- if (msg.key === 'backspace') { return palette.query.slice(0, -1); }
701
- if (msg.key.length === 1 && !msg.ctrl && !msg.alt) { return `${palette.query}${msg.key}`; }
843
+ if (msg.key === 'backspace') {
844
+ return palette.query.slice(0, -1);
845
+ }
846
+ if (msg.key.length === 1 && !msg.ctrl && !msg.alt) {
847
+ return `${palette.query}${msg.key}`;
848
+ }
702
849
  return null;
703
850
  }
704
851
 
705
852
  function handlePaletteKey(msg, model, deps) {
706
- if (!model.palette) { return [model, []]; }
853
+ if (!model.palette) {
854
+ return [model, []];
855
+ }
707
856
  const action = paletteAction(msg);
708
- if (action) { return PALETTE_ACTIONS[action](msg, model, deps); }
857
+ if (action) {
858
+ return PALETTE_ACTIONS[action](msg, model, deps);
859
+ }
709
860
  const query = paletteQueryForKey(msg, model.palette);
710
- return query === null
711
- ? [model, []]
712
- : [{ ...model, palette: cpFilter(model.palette, query) }, []];
861
+ return query === null ? [model, []] : [{ ...model, palette: cpFilter(model.palette, query) }, []];
713
862
  }
714
863
 
715
864
  function handleFilterKey(msg, model) {
716
- if (msg.key === 'escape') { return [syncExplorer(model, { filtering: false }), []]; }
717
- if (msg.key === 'enter') { return [syncExplorer(model, { filtering: false }), []]; }
865
+ if (msg.key === 'escape') {
866
+ return [syncExplorer(model, { filtering: false }), []];
867
+ }
868
+ if (msg.key === 'enter') {
869
+ return [syncExplorer(model, { filtering: false }), []];
870
+ }
718
871
  if (msg.key === 'backspace') {
719
872
  return [syncExplorer(model, { filterText: model.filterText.slice(0, -1) }), []];
720
873
  }
@@ -736,9 +889,13 @@ const LEDGER_NAVIGATORS = {
736
889
  };
737
890
 
738
891
  function handleExplorerNavigation(msg, model, deps) {
739
- if (model.focusPane !== 'ledger') { return null; }
892
+ if (model.focusPane !== 'ledger') {
893
+ return null;
894
+ }
740
895
  const navigate = LEDGER_NAVIGATORS[msg.key];
741
- if (!navigate) { return null; }
896
+ if (!navigate) {
897
+ return null;
898
+ }
742
899
  const next = { ...model, table: navigate(model.table), chunkFocus: 0 };
743
900
  const manifestCmd = maybeLoadSelectedManifest(next, deps);
744
901
  return [next, manifestCmd ? [manifestCmd] : []];
@@ -762,19 +919,35 @@ function moveChunkFocus(model, delta) {
762
919
  }
763
920
 
764
921
  function detailDeltaForKey(key, model) {
765
- if (key === 'j' || key === 'down') { return 1; }
766
- if (key === 'k' || key === 'up') { return -1; }
767
- if (key === 'd' || key === 'pagedown') { return chunkPageStep(model); }
768
- if (key === 'u' || key === 'pageup') { return -chunkPageStep(model); }
922
+ if (key === 'j' || key === 'down') {
923
+ return 1;
924
+ }
925
+ if (key === 'k' || key === 'up') {
926
+ return -1;
927
+ }
928
+ if (key === 'd' || key === 'pagedown') {
929
+ return chunkPageStep(model);
930
+ }
931
+ if (key === 'u' || key === 'pageup') {
932
+ return -chunkPageStep(model);
933
+ }
769
934
  return null;
770
935
  }
771
936
 
772
937
  function handleDetailNavigation(msg, model) {
773
- if (model.focusPane !== 'detail' || model.explorerMode === 'ledger') { return null; }
774
- if (selectedChunks(model).length === 0) { return null; }
938
+ if (model.focusPane !== 'detail' || model.explorerMode === 'ledger') {
939
+ return null;
940
+ }
941
+ if (selectedChunks(model).length === 0) {
942
+ return null;
943
+ }
775
944
  const delta = detailDeltaForKey(msg.key, model);
776
- if (delta !== null) { return moveChunkFocus(model, delta); }
777
- if (msg.key === 'g') { return [{ ...model, chunkFocus: 0 }, []]; }
945
+ if (delta !== null) {
946
+ return moveChunkFocus(model, delta);
947
+ }
948
+ if (msg.key === 'g') {
949
+ return [{ ...model, chunkFocus: 0 }, []];
950
+ }
778
951
  return null;
779
952
  }
780
953
 
@@ -782,23 +955,37 @@ function switchWorkspace(model, workspace, deps) {
782
955
  const next = { ...model, workspace, showHelp: false };
783
956
  if (workspace === 'atlas' && next.treemapStatus === 'idle') {
784
957
  const cas = casForModel(deps.cas, next);
785
- return [{ ...next, treemapStatus: 'loading' }, [loadTreemapCmd(cas, {
786
- source: next.source,
787
- scope: next.treemapScope,
788
- worktreeMode: next.treemapWorktreeMode,
789
- drillPath: next.treemapPath,
790
- })]];
958
+ return [
959
+ { ...next, treemapStatus: 'loading' },
960
+ [
961
+ loadTreemapCmd(cas, {
962
+ source: next.source,
963
+ scope: next.treemapScope,
964
+ worktreeMode: next.treemapWorktreeMode,
965
+ drillPath: next.treemapPath,
966
+ }),
967
+ ],
968
+ ];
791
969
  }
792
970
  if (workspace === 'operations' && next.statsStatus === 'idle') {
793
- return [{ ...next, statsStatus: 'loading' }, [loadStatsCmd(deps.cas, next.entries, next.source)]];
971
+ return [
972
+ { ...next, statsStatus: 'loading' },
973
+ [loadStatsCmd(deps.cas, next.entries, next.source)],
974
+ ];
794
975
  }
795
976
  return [next, []];
796
977
  }
797
978
 
798
979
  function handleWorkspaceKey(msg, model, deps) {
799
- if (msg.key === '1' || msg.key === 'e') { return switchWorkspace(model, 'explorer', deps); }
800
- if (msg.key === '2' || msg.key === 'a') { return switchWorkspace(model, 'atlas', deps); }
801
- if (msg.key === '3' || msg.key === 'o') { return switchWorkspace(model, 'operations', deps); }
980
+ if (msg.key === '1' || msg.key === 'e') {
981
+ return switchWorkspace(model, 'explorer', deps);
982
+ }
983
+ if (msg.key === '2' || msg.key === 'a') {
984
+ return switchWorkspace(model, 'atlas', deps);
985
+ }
986
+ if (msg.key === '3' || msg.key === 'o') {
987
+ return switchWorkspace(model, 'operations', deps);
988
+ }
802
989
  return null;
803
990
  }
804
991
 
@@ -830,9 +1017,15 @@ function toggleInspectorMode(model, deps) {
830
1017
  }
831
1018
 
832
1019
  function handleExplorerModeKey(msg, model, deps) {
833
- if (msg.key === 'enter') { return toggleExplorerDetail(model, deps); }
834
- if (msg.key === 'm') { return cycleMerkleMode(model); }
835
- if (msg.key === 'i') { return toggleInspectorMode(model, deps); }
1020
+ if (msg.key === 'enter') {
1021
+ return toggleExplorerDetail(model, deps);
1022
+ }
1023
+ if (msg.key === 'm') {
1024
+ return cycleMerkleMode(model);
1025
+ }
1026
+ if (msg.key === 'i') {
1027
+ return toggleInspectorMode(model, deps);
1028
+ }
836
1029
  return null;
837
1030
  }
838
1031
 
@@ -841,26 +1034,38 @@ function handleExplorerKey(msg, model, deps) {
841
1034
  return [{ ...model, focusPane: model.focusPane === 'ledger' ? 'detail' : 'ledger' }, []];
842
1035
  }
843
1036
  const detailNav = handleDetailNavigation(msg, model);
844
- if (detailNav) { return detailNav; }
1037
+ if (detailNav) {
1038
+ return detailNav;
1039
+ }
845
1040
  const nav = handleExplorerNavigation(msg, model, deps);
846
- if (nav) { return nav; }
1041
+ if (nav) {
1042
+ return nav;
1043
+ }
847
1044
  return handleExplorerModeKey(msg, model, deps);
848
1045
  }
849
1046
 
850
1047
  function reloadTreemap(model, deps, patch = {}) {
851
1048
  const next = { ...model, ...patch, treemapStatus: 'loading', treemapError: null };
852
- return [next, [loadTreemapCmd(casForModel(deps.cas, next), {
853
- source: next.source,
854
- scope: next.treemapScope,
855
- worktreeMode: next.treemapWorktreeMode,
856
- drillPath: next.treemapPath,
857
- })]];
1049
+ return [
1050
+ next,
1051
+ [
1052
+ loadTreemapCmd(casForModel(deps.cas, next), {
1053
+ source: next.source,
1054
+ scope: next.treemapScope,
1055
+ worktreeMode: next.treemapWorktreeMode,
1056
+ drillPath: next.treemapPath,
1057
+ }),
1058
+ ],
1059
+ ];
858
1060
  }
859
1061
 
860
1062
  function focusAtlasTile(model, delta) {
861
1063
  const tiles = model.treemapReport?.tiles ?? [];
862
1064
  const maxFocus = Math.max(0, tiles.length - 1);
863
- return [{ ...model, treemapFocus: Math.max(0, Math.min(model.treemapFocus + delta, maxFocus)) }, []];
1065
+ return [
1066
+ { ...model, treemapFocus: Math.max(0, Math.min(model.treemapFocus + delta, maxFocus)) },
1067
+ [],
1068
+ ];
864
1069
  }
865
1070
 
866
1071
  function drillIntoAtlasTile(model, deps) {
@@ -893,8 +1098,16 @@ const ATLAS_KEY_ACTIONS = {
893
1098
  const ATLAS_ACTIONS = {
894
1099
  next: (_msg, model) => focusAtlasTile(model, 1),
895
1100
  previous: (_msg, model) => focusAtlasTile(model, -1),
896
- scope: (_msg, model, deps) => reloadTreemap(model, deps, { treemapScope: model.treemapScope === 'repository' ? 'source' : 'repository', treemapPath: [] }),
897
- worktreeMode: (_msg, model, deps) => reloadTreemap(model, deps, { treemapWorktreeMode: model.treemapWorktreeMode === 'tracked' ? 'ignored' : 'tracked', treemapPath: [] }),
1101
+ scope: (_msg, model, deps) =>
1102
+ reloadTreemap(model, deps, {
1103
+ treemapScope: model.treemapScope === 'repository' ? 'source' : 'repository',
1104
+ treemapPath: [],
1105
+ }),
1106
+ worktreeMode: (_msg, model, deps) =>
1107
+ reloadTreemap(model, deps, {
1108
+ treemapWorktreeMode: model.treemapWorktreeMode === 'tracked' ? 'ignored' : 'tracked',
1109
+ treemapPath: [],
1110
+ }),
898
1111
  reload: (_msg, model, deps) => reloadTreemap(model, deps),
899
1112
  drillIn: (_msg, model, deps) => drillIntoAtlasTile(model, deps),
900
1113
  drillOut: (_msg, model, deps) => drillOutAtlasTile(model, deps),
@@ -908,17 +1121,20 @@ function handleAtlasKey(msg, model, deps) {
908
1121
  function startOperation(operationFeed, slug) {
909
1122
  return {
910
1123
  ...operationFeed,
911
- entries: [{
912
- id: `store-${slug}-${Date.now()}`,
913
- type: 'store',
914
- slug,
915
- status: 'running',
916
- startTime: Date.now(),
917
- endTime: null,
918
- chunksTotal: 0,
919
- chunksProcessed: 0,
920
- error: null,
921
- }, ...operationFeed.entries].slice(0, operationFeed.maxEntries),
1124
+ entries: [
1125
+ {
1126
+ id: `store-${slug}-${Date.now()}`,
1127
+ type: 'store',
1128
+ slug,
1129
+ status: 'running',
1130
+ startTime: Date.now(),
1131
+ endTime: null,
1132
+ chunksTotal: 0,
1133
+ chunksProcessed: 0,
1134
+ error: null,
1135
+ },
1136
+ ...operationFeed.entries,
1137
+ ].slice(0, operationFeed.maxEntries),
922
1138
  };
923
1139
  }
924
1140
 
@@ -926,7 +1142,9 @@ function completeLatestOperation(operationFeed, slug, error) {
926
1142
  return {
927
1143
  ...operationFeed,
928
1144
  entries: operationFeed.entries.map((entry, index) => {
929
- if (index !== 0 || entry.slug !== slug) { return entry; }
1145
+ if (index !== 0 || entry.slug !== slug) {
1146
+ return entry;
1147
+ }
930
1148
  return {
931
1149
  ...entry,
932
1150
  status: error ? 'error' : 'done',
@@ -938,42 +1156,59 @@ function completeLatestOperation(operationFeed, slug, error) {
938
1156
  }
939
1157
 
940
1158
  function handleWizardKey(msg, model, deps) {
941
- if (!model.storeWizard) { return null; }
1159
+ if (!model.storeWizard) {
1160
+ return null;
1161
+ }
942
1162
  if (msg.key === 'escape') {
943
1163
  return [{ ...model, storeWizard: null }, []];
944
1164
  }
945
1165
  const nextWizard = wizardHandleKey(model.storeWizard, msg.key);
946
1166
  if (nextWizard.step === 'storing') {
947
- return [{
948
- ...model,
949
- storeWizard: nextWizard,
950
- operationFeed: startOperation(model.operationFeed, nextWizard.slug),
951
- }, [runStoreWizardCmd(casForModel(deps.cas, model), nextWizard)]];
1167
+ return [
1168
+ {
1169
+ ...model,
1170
+ storeWizard: nextWizard,
1171
+ operationFeed: startOperation(model.operationFeed, nextWizard.slug),
1172
+ },
1173
+ [runStoreWizardCmd(casForModel(deps.cas, model), nextWizard)],
1174
+ ];
952
1175
  }
953
1176
  return [{ ...model, storeWizard: nextWizard }, []];
954
1177
  }
955
1178
 
956
1179
  function handleOperationsKey(msg, model, deps) {
957
- if (msg.key === 'n') { return [{ ...model, storeWizard: createWizardState() }, []]; }
1180
+ if (msg.key === 'n') {
1181
+ return [{ ...model, storeWizard: createWizardState() }, []];
1182
+ }
958
1183
  if (msg.key === 's') {
959
- return [{ ...model, statsStatus: 'loading', statsError: null }, [loadStatsCmd(deps.cas, model.entries, model.source)]];
1184
+ return [
1185
+ { ...model, statsStatus: 'loading', statsError: null },
1186
+ [loadStatsCmd(deps.cas, model.entries, model.source)],
1187
+ ];
960
1188
  }
961
1189
  if (msg.key === 'x') {
962
- return [{
963
- ...model,
964
- doctorStatus: 'loading',
965
- doctorError: null,
966
- }, [loadDoctorCmd(deps.cas, {
967
- source: model.source,
968
- entries: model.entries,
969
- encryptionKey: model.vaultEncryptionKey,
970
- })]];
1190
+ return [
1191
+ {
1192
+ ...model,
1193
+ doctorStatus: 'loading',
1194
+ doctorError: null,
1195
+ },
1196
+ [
1197
+ loadDoctorCmd(deps.cas, {
1198
+ source: model.source,
1199
+ entries: model.entries,
1200
+ encryptionKey: model.vaultEncryptionKey,
1201
+ }),
1202
+ ],
1203
+ ];
971
1204
  }
972
1205
  return null;
973
1206
  }
974
1207
 
975
1208
  function handleQuitConfirmKey(msg, model) {
976
- if (msg.key === 'y' || msg.key === 'enter') { return [model, [quit()]]; }
1209
+ if (msg.key === 'y' || msg.key === 'enter') {
1210
+ return [model, [quit()]];
1211
+ }
977
1212
  if (msg.key === 'n' || msg.key === 'escape' || msg.key === 'q') {
978
1213
  return [{ ...model, quitConfirm: false }, []];
979
1214
  }
@@ -993,12 +1228,18 @@ function clearDashboardOverlays(model) {
993
1228
  }
994
1229
 
995
1230
  function handleOverlayShortcut(msg, model) {
996
- if (msg.key === 'escape') { return [clearDashboardOverlays(model), []]; }
997
- if (msg.key === 'f2') { return [{ ...model, settingsOpen: !model.settingsOpen, showHelp: false, palette: null }, []]; }
1231
+ if (msg.key === 'escape') {
1232
+ return [clearDashboardOverlays(model), []];
1233
+ }
1234
+ if (msg.key === 'f2') {
1235
+ return [{ ...model, settingsOpen: !model.settingsOpen, showHelp: false, palette: null }, []];
1236
+ }
998
1237
  if (msg.key === '?' || (msg.shift && msg.key === '/')) {
999
1238
  return [{ ...model, showHelp: !model.showHelp, palette: null }, []];
1000
1239
  }
1001
- if (msg.key === 'q') { return [{ ...model, quitConfirm: true }, []]; }
1240
+ if (msg.key === 'q') {
1241
+ return [{ ...model, quitConfirm: true }, []];
1242
+ }
1002
1243
  return null;
1003
1244
  }
1004
1245
 
@@ -1006,15 +1247,21 @@ function handleSearchShortcut(msg, model) {
1006
1247
  if (msg.key === '/' && !msg.ctrl) {
1007
1248
  return [syncExplorer(model, { workspace: 'explorer', filtering: true, palette: null }), []];
1008
1249
  }
1009
- if ((msg.ctrl && msg.key === 'p') || msg.key === ':') { return [openPalette(model), []]; }
1250
+ if ((msg.ctrl && msg.key === 'p') || msg.key === ':') {
1251
+ return [openPalette(model), []];
1252
+ }
1010
1253
  return null;
1011
1254
  }
1012
1255
 
1013
1256
  function handleGlobalDashboardKey(msg, model, deps) {
1014
1257
  const overlay = handleOverlayShortcut(msg, model);
1015
- if (overlay) { return overlay; }
1258
+ if (overlay) {
1259
+ return overlay;
1260
+ }
1016
1261
  const search = handleSearchShortcut(msg, model);
1017
- if (search) { return search; }
1262
+ if (search) {
1263
+ return search;
1264
+ }
1018
1265
  return handleWorkspaceKey(msg, model, deps);
1019
1266
  }
1020
1267
 
@@ -1030,19 +1277,31 @@ function handleWorkspaceSpecificKey(msg, model, deps) {
1030
1277
  }
1031
1278
 
1032
1279
  function handleDashboardKey(msg, model, deps) {
1033
- if (model.quitConfirm) { return handleQuitConfirmKey(msg, model); }
1034
- if (model.palette) { return handlePaletteKey(msg, model, deps); }
1280
+ if (model.quitConfirm) {
1281
+ return handleQuitConfirmKey(msg, model);
1282
+ }
1283
+ if (model.palette) {
1284
+ return handlePaletteKey(msg, model, deps);
1285
+ }
1035
1286
  const wizard = handleWizardKey(msg, model, deps);
1036
- if (wizard) { return wizard; }
1037
- if (model.filtering) { return handleFilterKey(msg, model); }
1287
+ if (wizard) {
1288
+ return wizard;
1289
+ }
1290
+ if (model.filtering) {
1291
+ return handleFilterKey(msg, model);
1292
+ }
1038
1293
  const global = handleGlobalDashboardKey(msg, model, deps);
1039
1294
  return global ?? handleWorkspaceSpecificKey(msg, model, deps) ?? [model, []];
1040
1295
  }
1041
1296
 
1042
1297
  function handleUpdate(msg, model, deps) {
1043
1298
  if (msg.type === 'key') {
1044
- if (model.phase === 'title') { return handleTitleKey(msg, model, deps); }
1045
- if (model.phase === 'password') { return handlePasswordKey(msg, model, deps); }
1299
+ if (model.phase === 'title') {
1300
+ return handleTitleKey(msg, model, deps);
1301
+ }
1302
+ if (model.phase === 'password') {
1303
+ return handlePasswordKey(msg, model, deps);
1304
+ }
1046
1305
  return handleDashboardKey(msg, model, deps);
1047
1306
  }
1048
1307
  if (msg.type === 'resize') {
@@ -1053,10 +1312,10 @@ function handleUpdate(msg, model, deps) {
1053
1312
 
1054
1313
  export function createDashboardApp(deps) {
1055
1314
  return {
1056
- init: () => [createInitModel(deps.ctx, deps.source), [
1057
- checkVaultAuthCmd(deps.cas),
1058
- deps.tick(TITLE_TICK_MS, { type: 'title-tick' }),
1059
- ]],
1315
+ init: () => [
1316
+ createInitModel(deps.ctx, deps.source),
1317
+ [checkVaultAuthCmd(deps.cas), deps.tick(TITLE_TICK_MS, { type: 'title-tick' })],
1318
+ ],
1060
1319
  update: (msg, model) => handleUpdate(msg, model, deps),
1061
1320
  view: (model) => renderDashboard(model, deps),
1062
1321
  };