@git-stunts/git-cas 6.5.5 → 6.5.6

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.
@@ -5,18 +5,14 @@
5
5
  import { boxSurface, createSurface, parseAnsiToSurface } from '@flyingrobots/bijou';
6
6
  import {
7
7
  canvas,
8
- commandPaletteSurface,
9
- drawer,
10
8
  hstackSurface,
11
- modal,
12
9
  navigableTableSurface,
13
10
  placeSurface,
14
- renderNotificationStack,
15
11
  statusBarSurface,
16
12
  vstackSurface,
17
13
  } from '@flyingrobots/bijou-tui';
18
14
  import { renderRepoTreemapMap, renderRepoTreemapSidebar } from './repo-treemap.js';
19
- import { shellRule, themeText } from './theme.js';
15
+ import { GIT_CAS_THEME, shellRule, themeText } from './theme.js';
20
16
  import { renderChunkTable, renderMerkleExplorer } from './blocks/merkle-explorer.js';
21
17
  import { renderHealthDashboard } from './blocks/health-dashboard.js';
22
18
  import { renderOperationFeed } from './blocks/operation-feed.js';
@@ -28,12 +24,17 @@ import { shortShaStatus } from './components/short-sha.js';
28
24
  /** @typedef {import('./dashboard.js').DashDeps} DashDeps */
29
25
  /** @typedef {import('./dashboard.js').DashSource} DashSource */
30
26
 
31
- const BG = '#25313a';
32
- const HELP_WIDTH = 58;
27
+ function uiColor(ctx, tokenName) {
28
+ return ctx.theme.theme.ui[tokenName]?.hex ?? GIT_CAS_THEME.ui[tokenName].hex;
29
+ }
33
30
 
34
31
  function sourceLabel(source) {
35
- if (source.type === 'vault') { return 'vault'; }
36
- if (source.type === 'ref') { return `ref ${source.ref}`; }
32
+ if (source.type === 'vault') {
33
+ return 'vault';
34
+ }
35
+ if (source.type === 'ref') {
36
+ return `ref ${source.ref}`;
37
+ }
37
38
  return `oid ${source.treeOid}`;
38
39
  }
39
40
 
@@ -41,13 +42,21 @@ function textSurface(content, width, height) {
41
42
  return parseAnsiToSurface(content, Math.max(1, width), Math.max(1, height));
42
43
  }
43
44
 
44
- function blank(width, height) {
45
- return createSurface(Math.max(1, width), Math.max(1, height), { char: ' ', bg: BG });
45
+ function blank(ctx, width, height) {
46
+ return createSurface(Math.max(1, width), Math.max(1, height), {
47
+ char: ' ',
48
+ bg: uiColor(ctx, 'canvas'),
49
+ });
46
50
  }
47
51
 
48
52
  function verticalRail(ctx, height) {
49
- return textSurface(Array.from({ length: Math.max(1, height) }, () =>
50
- themeText(ctx, '│', { tone: 'accent', bold: true })).join('\n'), 1, height);
53
+ return textSurface(
54
+ Array.from({ length: Math.max(1, height) }, () =>
55
+ themeText(ctx, '│', { tone: 'accent', bold: true })
56
+ ).join('\n'),
57
+ 1,
58
+ height
59
+ );
51
60
  }
52
61
 
53
62
  function panel({ title, body, width, height, ctx, active = false }) {
@@ -55,9 +64,10 @@ function panel({ title, body, width, height, ctx, active = false }) {
55
64
  const safeHeight = Math.max(3, height);
56
65
  const innerWidth = Math.max(1, safeWidth - 2);
57
66
  const innerHeight = Math.max(1, safeHeight - 2);
58
- const bodySurface = typeof body === 'string'
59
- ? textSurface(body, innerWidth, innerHeight)
60
- : placeSurface(body, { width: innerWidth, height: innerHeight });
67
+ const bodySurface =
68
+ typeof body === 'string'
69
+ ? textSurface(body, innerWidth, innerHeight)
70
+ : placeSurface(body, { width: innerWidth, height: innerHeight });
61
71
  const boxed = boxSurface(bodySurface, {
62
72
  ctx,
63
73
  title,
@@ -66,7 +76,9 @@ function panel({ title, body, width, height, ctx, active = false }) {
66
76
  bgToken: ctx.theme.theme.surface.primary,
67
77
  });
68
78
  const placed = placeSurface(boxed, { width: safeWidth, height: safeHeight });
69
- if (active) { placed.blit(verticalRail(ctx, safeHeight), 0, 0); }
79
+ if (active) {
80
+ placed.blit(verticalRail(ctx, safeHeight), 0, 0);
81
+ }
70
82
  return placed;
71
83
  }
72
84
 
@@ -87,10 +99,18 @@ function metricLine(model, ctx) {
87
99
  }
88
100
 
89
101
  function formatSize(bytes) {
90
- if (!Number.isFinite(bytes)) { return '-'; }
91
- if (bytes < 1024) { return `${bytes}B`; }
92
- if (bytes < 1024 * 1024) { return `${(bytes / 1024).toFixed(1)}K`; }
93
- if (bytes < 1024 * 1024 * 1024) { return `${(bytes / (1024 * 1024)).toFixed(1)}M`; }
102
+ if (!Number.isFinite(bytes)) {
103
+ return '-';
104
+ }
105
+ if (bytes < 1024) {
106
+ return `${bytes}B`;
107
+ }
108
+ if (bytes < 1024 * 1024) {
109
+ return `${(bytes / 1024).toFixed(1)}K`;
110
+ }
111
+ if (bytes < 1024 * 1024 * 1024) {
112
+ return `${(bytes / (1024 * 1024)).toFixed(1)}M`;
113
+ }
94
114
  return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)}G`;
95
115
  }
96
116
 
@@ -100,56 +120,41 @@ function workspaceTabs(model, ctx) {
100
120
  ['atlas', '2 Atlas'],
101
121
  ['operations', '3 Operations'],
102
122
  ];
103
- return tabs.map(([id, label]) => {
104
- const active = model.workspace === id;
105
- return themeText(ctx, active ? `▌ ${label}` : ` ${label}`, { tone: active ? 'brand' : 'secondary', bold: active });
106
- }).join(' ');
107
- }
108
-
109
- function renderHeaderSurface(model, deps, width) {
110
- const left = themeText(deps.ctx, ' git-cas cockpit', { tone: 'brand', bold: true });
111
- const center = workspaceTabs(model, deps.ctx);
112
- const right = model.gitBranch ? themeText(deps.ctx, model.gitBranch, { tone: 'info' }) : themeText(deps.ctx, model.status, { tone: 'secondary' });
113
- const first = statusBarSurface({ left, center, right, width });
123
+ return tabs
124
+ .map(([id, label]) => {
125
+ const active = model.workspace === id;
126
+ return themeText(ctx, active ? `▌ ${label}` : ` ${label}`, {
127
+ tone: active ? 'brand' : 'secondary',
128
+ bold: active,
129
+ });
130
+ })
131
+ .join(' ');
132
+ }
133
+
134
+ function renderWorkspaceSurface(model, deps, width) {
135
+ const left = workspaceTabs(model, deps.ctx);
136
+ const right = model.gitBranch
137
+ ? themeText(deps.ctx, model.gitBranch, { tone: 'info' })
138
+ : themeText(deps.ctx, model.status, { tone: 'secondary' });
139
+ const first = statusBarSurface({ left: ` ${left}`, right, width });
114
140
  const economics = statusBarSurface({
115
141
  left: ` ${metricLine(model, deps.ctx)}`,
116
142
  right: themeText(deps.ctx, sourceLabel(model.source), { tone: 'primary' }),
117
143
  width,
118
144
  });
119
- const filter = model.filtering
120
- ? `${themeText(deps.ctx, 'filter', { tone: 'accent' })} /${model.filterText}█`
121
- : `${themeText(deps.ctx, 'filter', { tone: 'accent' })} ${model.filterText ? `/${model.filterText}` : 'none'}`;
145
+ const search = `${themeText(deps.ctx, 'search', { tone: 'accent' })} ${model.filterText || 'all assets'}`;
146
+ const detailStatus = selectedShaFooter(model);
122
147
  const third = statusBarSurface({
123
- left: ` ${filter}`,
124
- right: model.error ? themeText(deps.ctx, model.error, { tone: 'danger' }) : '',
148
+ left: ` ${search}`,
149
+ right: model.error
150
+ ? themeText(deps.ctx, model.error, { tone: 'danger' })
151
+ : themeText(deps.ctx, detailStatus ?? '', { tone: 'info' }),
125
152
  width,
126
153
  });
127
154
  const rule = textSurface(shellRule(deps.ctx, width), width, 1);
128
155
  return vstackSurface(first, economics, third, rule);
129
156
  }
130
157
 
131
- function renderFooterSurface(model, ctx, width) {
132
- const left = model.quitConfirm
133
- ? themeText(ctx, 'Quit? y/enter confirm, n/escape cancel', { tone: 'warning' })
134
- : themeText(ctx, '? help / filter ctrl+p palette F2 settings q quit', { tone: 'subdued' });
135
- const rightByWorkspace = {
136
- explorer: model.focusPane === 'detail'
137
- ? 'tab focus j/k chunk u/d page enter ledger'
138
- : 'tab focus j/k rows enter detail m merkle',
139
- atlas: 'j/k focus +/- drill t scope i ignored',
140
- operations: 'n store s stats x doctor',
141
- };
142
- const detailStatus = selectedShaFooter(model);
143
- const footer = statusBarSurface({
144
- left: ` ${left}`,
145
- right: detailStatus
146
- ? themeText(ctx, detailStatus, { tone: 'info' })
147
- : themeText(ctx, rightByWorkspace[model.workspace], { tone: 'secondary' }),
148
- width,
149
- });
150
- return vstackSurface(textSurface(shellRule(ctx, width), width, 1), footer);
151
- }
152
-
153
158
  export function tableSchema(width) {
154
159
  if (width >= 110) {
155
160
  const slugWidth = Math.max(18, Math.min(36, width - 82));
@@ -188,42 +193,53 @@ export function tableSchema(width) {
188
193
  };
189
194
  }
190
195
 
191
- export function renderDashboard(model, deps) {
192
- if (model.phase === 'title' || model.phase === 'password') {
193
- return renderTitleScreen(model, deps);
196
+ export function renderDashboard(model, deps, options = {}) {
197
+ const renderModel = {
198
+ ...model,
199
+ columns: options.width ?? model.columns,
200
+ rows: options.height ?? model.rows,
201
+ };
202
+ if (renderModel.phase === 'title' || renderModel.phase === 'password') {
203
+ return renderTitleScreen(renderModel, deps);
194
204
  }
195
205
 
196
- const width = Math.max(1, model.columns);
197
- const height = Math.max(1, model.rows);
198
- const screen = createSurface(width, height, { char: ' ', bg: BG });
199
- const header = renderHeaderSurface(model, deps, width);
200
- const footer = renderFooterSurface(model, deps.ctx, width);
201
- const bodyHeight = Math.max(1, height - header.height - footer.height);
202
- const body = renderBody(model, deps, { width: Math.max(1, width - 1), height: bodyHeight });
203
-
204
- screen.blit(vstackSurface(header, hstackSurface(0, verticalRail(deps.ctx, bodyHeight), body), footer), 0, 0);
205
- renderOverlays(model, deps, { screen, width, height });
206
+ const width = Math.max(1, renderModel.columns);
207
+ const height = Math.max(1, renderModel.rows);
208
+ const screen = createSurface(width, height, {
209
+ char: ' ',
210
+ bg: uiColor(deps.ctx, 'canvas'),
211
+ });
212
+ const header = renderWorkspaceSurface(renderModel, deps, width);
213
+ const bodyHeight = Math.max(1, height - header.height);
214
+ const body = renderBody(renderModel, deps, { width: Math.max(1, width - 1), height: bodyHeight });
215
+
216
+ screen.blit(
217
+ vstackSurface(header, hstackSurface(0, verticalRail(deps.ctx, bodyHeight), body)),
218
+ 0,
219
+ 0
220
+ );
221
+ renderPageOverlay(renderModel, deps, { screen, width, height });
206
222
  return screen;
207
223
  }
208
224
 
209
225
  function renderTitleScreen(model, deps) {
210
226
  const { columns: width, rows: height } = model;
211
- const screen = createSurface(width, height, { char: ' ', bg: BG });
227
+ const screen = createSurface(width, height, {
228
+ char: ' ',
229
+ bg: uiColor(deps.ctx, 'canvas'),
230
+ });
212
231
  const { ctx } = deps;
213
232
  const innerW = Math.min(56, width);
214
233
 
215
- screen.blit(canvas(width, height, organicFlowShader, {
216
- time: (model.titleTimeMs ?? 0) / 1000,
217
- resolution: 'braille',
218
- uniforms: { entryCount: model.vaultEntryCount, width, height },
219
- }), 0, 0);
220
-
221
- if (model.showPerfHud) {
222
- const fpsText = ` ${model.fps} FPS `;
223
- const hud = parseAnsiToSurface(fpsText, fpsText.length, 1);
224
- hud.fill({ char: ' ', bg: '#000000', fg: '#ffffff' });
225
- screen.blit(hud, 0, 0);
226
- }
234
+ screen.blit(
235
+ canvas(width, height, organicFlowShader, {
236
+ time: (model.titleTimeMs ?? 0) / 1000,
237
+ resolution: 'braille',
238
+ uniforms: { entryCount: model.vaultEntryCount, width, height },
239
+ }),
240
+ 0,
241
+ 0
242
+ );
227
243
 
228
244
  const surfaces = titlePanelSurfaces(model, ctx, innerW);
229
245
 
@@ -234,7 +250,11 @@ function renderTitleScreen(model, deps) {
234
250
  borderToken: ctx.theme.theme.border.primary,
235
251
  bgToken: ctx.theme.theme.surface.overlay,
236
252
  });
237
- screen.blit(titlePanel, Math.max(0, Math.floor((width - titlePanel.width) / 2)), Math.max(0, Math.floor((height - titlePanel.height) / 3)));
253
+ screen.blit(
254
+ titlePanel,
255
+ Math.max(0, Math.floor((width - titlePanel.width) / 2)),
256
+ Math.max(0, Math.floor((height - titlePanel.height) / 3))
257
+ );
238
258
  return screen;
239
259
  }
240
260
 
@@ -254,7 +274,14 @@ function titlePhaseSurfaces(model, ctx, width) {
254
274
  const tone = model.promptEnter ? 'success' : 'subdued';
255
275
  const surfaces = [textSurface(themeText(ctx, status, { tone }), width, 1)];
256
276
  if (model.promptEnter) {
257
- surfaces.push(createSurface(1, 1), textSurface(themeText(ctx, 'enter to continue | escape to quit', { tone: 'subdued' }), width, 1));
277
+ surfaces.push(
278
+ createSurface(1, 1),
279
+ textSurface(
280
+ themeText(ctx, 'enter to continue | escape to quit', { tone: 'subdued' }),
281
+ width,
282
+ 1
283
+ )
284
+ );
258
285
  }
259
286
  return surfaces;
260
287
  }
@@ -262,20 +289,43 @@ function titlePhaseSurfaces(model, ctx, width) {
262
289
  function passwordPhaseSurfaces(model, ctx, width) {
263
290
  const mask = '•'.repeat(model.passphrase.length);
264
291
  const surfaces = [
265
- textSurface(themeText(ctx, 'Vault is encrypted. Enter passphrase to unlock.', { tone: 'warning' }), width, 1),
292
+ textSurface(
293
+ themeText(ctx, 'Vault is encrypted. Enter passphrase to unlock.', { tone: 'warning' }),
294
+ width,
295
+ 1
296
+ ),
266
297
  createSurface(1, 1),
267
- hstackSurface(1, createSurface(2, 1), textSurface(themeText(ctx, 'Passphrase:', { tone: 'accent' }), 11, 1), textSurface(`${mask}█`, Math.max(1, width - 14), 1)),
298
+ hstackSurface(
299
+ 1,
300
+ createSurface(2, 1),
301
+ textSurface(themeText(ctx, 'Passphrase:', { tone: 'accent' }), 11, 1),
302
+ textSurface(`${mask}█`, Math.max(1, width - 14), 1)
303
+ ),
268
304
  ];
269
305
  if (model.authError) {
270
- surfaces.push(createSurface(1, 1), hstackSurface(1, createSurface(2, 1), textSurface(themeText(ctx, model.authError, { tone: 'danger' }), Math.max(1, width - 3), 1)));
306
+ surfaces.push(
307
+ createSurface(1, 1),
308
+ hstackSurface(
309
+ 1,
310
+ createSurface(2, 1),
311
+ textSurface(themeText(ctx, model.authError, { tone: 'danger' }), Math.max(1, width - 3), 1)
312
+ )
313
+ );
271
314
  }
272
- surfaces.push(createSurface(1, 1), textSurface(themeText(ctx, 'enter to unlock | escape to quit', { tone: 'subdued' }), width, 1));
315
+ surfaces.push(
316
+ createSurface(1, 1),
317
+ textSurface(themeText(ctx, 'enter to unlock | escape to quit', { tone: 'subdued' }), width, 1)
318
+ );
273
319
  return surfaces;
274
320
  }
275
321
 
276
322
  function renderBody(model, deps, options) {
277
- if (model.workspace === 'atlas') { return renderAtlasWorkspace(model, deps, options); }
278
- if (model.workspace === 'operations') { return renderOperationsWorkspace(model, deps, options); }
323
+ if (model.workspace === 'atlas') {
324
+ return renderAtlasWorkspace(model, deps, options);
325
+ }
326
+ if (model.workspace === 'operations') {
327
+ return renderOperationsWorkspace(model, deps, options);
328
+ }
279
329
  return renderExplorerWorkspace(model, deps, options);
280
330
  }
281
331
 
@@ -285,8 +335,8 @@ function renderExplorerWorkspace(model, deps, options) {
285
335
  const detailHeight = Math.max(4, options.height - ledgerHeight - 1);
286
336
  return vstackSurface(
287
337
  renderLedgerPanel(model, deps.ctx, { width: options.width, height: ledgerHeight }),
288
- blank(options.width, 1),
289
- renderInspectorPanel(model, deps.ctx, { width: options.width, height: detailHeight }),
338
+ blank(deps.ctx, options.width, 1),
339
+ renderInspectorPanel(model, deps.ctx, { width: options.width, height: detailHeight })
290
340
  );
291
341
  }
292
342
  const gap = 2;
@@ -295,26 +345,40 @@ function renderExplorerWorkspace(model, deps, options) {
295
345
  return hstackSurface(
296
346
  gap,
297
347
  renderLedgerPanel(model, deps.ctx, { width: ledgerWidth, height: options.height }),
298
- renderInspectorPanel(model, deps.ctx, { width: inspectorWidth, height: options.height }),
348
+ renderInspectorPanel(model, deps.ctx, { width: inspectorWidth, height: options.height })
299
349
  );
300
350
  }
301
351
 
302
352
  function renderLedgerPanel(model, ctx, box) {
303
353
  const { width, height } = box;
304
354
  const schema = tableSchema(Math.max(20, width - 2));
305
- const projectedRows = model.table.rows.map((row) => schema.indexes.map((index) => row[index] ?? ''));
306
- const tableSurface = navigableTableSurface({
307
- columns: schema.columns,
308
- rows: projectedRows,
309
- focusRow: model.table.focusRow,
310
- scrollY: model.table.scrollY,
311
- height: Math.max(1, height - 5),
312
- }, { ctx });
313
- return panel({ title: 'Asset Ledger', body: tableSurface, width, height, ctx, active: model.focusPane === 'ledger' });
355
+ const projectedRows = model.table.rows.map((row) =>
356
+ schema.indexes.map((index) => row[index] ?? '')
357
+ );
358
+ const tableSurface = navigableTableSurface(
359
+ {
360
+ columns: schema.columns,
361
+ rows: projectedRows,
362
+ focusRow: model.table.focusRow,
363
+ scrollY: model.table.scrollY,
364
+ height: Math.max(1, height - 5),
365
+ },
366
+ { ctx }
367
+ );
368
+ return panel({
369
+ title: 'Asset Ledger',
370
+ body: tableSurface,
371
+ width,
372
+ height,
373
+ ctx,
374
+ active: model.focusPane === 'ledger',
375
+ });
314
376
  }
315
377
 
316
378
  function selectedEntry(model) {
317
- return model.filtered[Math.min(model.table.focusRow, Math.max(0, model.filtered.length - 1))] ?? null;
379
+ return (
380
+ model.filtered[Math.min(model.table.focusRow, Math.max(0, model.filtered.length - 1))] ?? null
381
+ );
318
382
  }
319
383
 
320
384
  function manifestData(manifest) {
@@ -333,9 +397,13 @@ function selectedChunk(model) {
333
397
  }
334
398
 
335
399
  function selectedShaFooter(model) {
336
- if (model.workspace !== 'explorer' || model.focusPane !== 'detail') { return null; }
400
+ if (model.workspace !== 'explorer' || model.focusPane !== 'detail') {
401
+ return null;
402
+ }
337
403
  const chunk = selectedChunk(model);
338
- if (!chunk) { return null; }
404
+ if (!chunk) {
405
+ return null;
406
+ }
339
407
  const digest = shortShaStatus('digest', chunk.digest);
340
408
  const blob = shortShaStatus('blob', chunk.blob);
341
409
  return [`#${chunk.index}`, digest, blob].filter(Boolean).join(' ');
@@ -346,7 +414,14 @@ function renderInspectorPanel(model, ctx, box) {
346
414
  const entry = selectedEntry(model);
347
415
  const manifest = selectedManifest(model);
348
416
  if (!entry) {
349
- return panel({ title: 'Inspector', body: 'No asset selected.', width, height, ctx, active: model.focusPane === 'detail' });
417
+ return panel({
418
+ title: 'Inspector',
419
+ body: 'No asset selected.',
420
+ width,
421
+ height,
422
+ ctx,
423
+ active: model.focusPane === 'detail',
424
+ });
350
425
  }
351
426
  if (model.explorerMode === 'merkle') {
352
427
  return panel({
@@ -362,9 +437,23 @@ function renderInspectorPanel(model, ctx, box) {
362
437
  const body = manifest
363
438
  ? renderManifestDetail({ model, manifest, ctx, box: { width, height } })
364
439
  : `Loading manifest for ${entry.slug}...\n${entry.treeOid}`;
365
- return panel({ title: 'Manifest Ledger', body, width, height, ctx, active: model.focusPane === 'detail' });
440
+ return panel({
441
+ title: 'Manifest Ledger',
442
+ body,
443
+ width,
444
+ height,
445
+ ctx,
446
+ active: model.focusPane === 'detail',
447
+ });
366
448
  }
367
- return panel({ title: 'Inspector', body: renderInspectorBody(entry, manifest, ctx), width, height, ctx, active: model.focusPane === 'detail' });
449
+ return panel({
450
+ title: 'Inspector',
451
+ body: renderInspectorBody(entry, manifest, ctx),
452
+ width,
453
+ height,
454
+ ctx,
455
+ active: model.focusPane === 'detail',
456
+ });
368
457
  }
369
458
 
370
459
  function renderInspectorBody(entry, manifest, ctx) {
@@ -383,7 +472,9 @@ function renderInspectorBody(entry, manifest, ctx) {
383
472
  `${themeText(ctx, 'compress', { tone: 'accent' })} ${manifest.compression?.algorithm ?? 'none'}`,
384
473
  `${themeText(ctx, 'format', { tone: 'accent' })} ${manifest.formatVersion ?? manifest.version ?? '-'}`,
385
474
  '',
386
- themeText(ctx, 'enter detail | tab detail focus | ctrl+p digest search', { tone: 'subdued' }),
475
+ themeText(ctx, 'enter detail | tab detail focus | ctrl+p digest search', {
476
+ tone: 'subdued',
477
+ })
387
478
  );
388
479
  return lines.join('\n');
389
480
  }
@@ -404,18 +495,26 @@ function renderManifestDetail({ model, manifest, ctx, box }) {
404
495
  '',
405
496
  themeText(ctx, `Chunk Ledger (${chunks.length})`, { tone: 'info', bold: true }),
406
497
  ];
407
- if (chunks.length === 0) { return lines.concat('No chunks.').join('\n'); }
408
- return lines.concat(renderChunkTable(manifest, ctx, {
409
- selectedIndex: Math.min(model.chunkFocus ?? 0, chunks.length - 1),
410
- pageSize: pageSizeForDetail(box.height),
411
- width: Math.max(24, box.width - 4),
412
- })).join('\n');
498
+ if (chunks.length === 0) {
499
+ return lines.concat('No chunks.').join('\n');
500
+ }
501
+ return lines
502
+ .concat(
503
+ renderChunkTable(manifest, ctx, {
504
+ selectedIndex: Math.min(model.chunkFocus ?? 0, chunks.length - 1),
505
+ pageSize: pageSizeForDetail(box.height),
506
+ width: Math.max(24, box.width - 4),
507
+ })
508
+ )
509
+ .join('\n');
413
510
  }
414
511
 
415
512
  function renderMerkleBody({ model, manifest, ctx, box }) {
416
- if (!manifest) { return 'No manifest loaded.'; }
513
+ if (!manifest) {
514
+ return 'No manifest loaded.';
515
+ }
417
516
  const tabs = ['table', 'tree', 'dag']
418
- .map((item) => item === model.merkleMode ? `[${item}]` : ` ${item} `)
517
+ .map((item) => (item === model.merkleMode ? `[${item}]` : ` ${item} `))
419
518
  .join(' ');
420
519
  if (model.merkleMode !== 'table') {
421
520
  return `${themeText(ctx, tabs, { tone: 'accent' })}\n\n${renderMerkleExplorer(manifest, model.merkleMode, ctx)}`;
@@ -427,15 +526,42 @@ function renderMerkleBody({ model, manifest, ctx, box }) {
427
526
  })}`;
428
527
  }
429
528
 
529
+ function renderAtlasBriefing(sidebar, ctx) {
530
+ return [
531
+ themeText(ctx, 'Overview', { tone: 'accent', bold: true }),
532
+ sidebar.overview,
533
+ '',
534
+ themeText(ctx, 'Focused Region', { tone: 'accent', bold: true }),
535
+ sidebar.focused,
536
+ '',
537
+ themeText(ctx, 'Legend', { tone: 'accent', bold: true }),
538
+ sidebar.legend,
539
+ '',
540
+ themeText(ctx, 'Largest Regions', { tone: 'accent', bold: true }),
541
+ sidebar.regions,
542
+ '',
543
+ sidebar.notes,
544
+ ]
545
+ .filter((section) => section !== null && section !== undefined)
546
+ .join('\n');
547
+ }
548
+
430
549
  function renderAtlasWorkspace(model, deps, options) {
431
550
  const gap = options.width >= 76 ? 2 : 1;
432
551
  const sidebarWidth = Math.min(44, Math.max(28, Math.floor(options.width * 0.34)));
433
552
  const mapWidth = Math.max(20, options.width - sidebarWidth - gap);
434
553
  if (!model.treemapReport) {
435
- const body = model.treemapStatus === 'error'
436
- ? `Atlas unavailable\n\n${model.treemapError}`
437
- : 'Loading repository atlas...';
438
- return panel({ title: 'Repository Atlas', body, width: options.width, height: options.height, ctx: deps.ctx });
554
+ const body =
555
+ model.treemapStatus === 'error'
556
+ ? `Atlas unavailable\n\n${model.treemapError}`
557
+ : 'Loading repository atlas...';
558
+ return panel({
559
+ title: 'Repository Atlas',
560
+ body,
561
+ width: options.width,
562
+ height: options.height,
563
+ ctx: deps.ctx,
564
+ });
439
565
  }
440
566
  const selected = model.treemapReport.tiles?.[model.treemapFocus]?.id ?? null;
441
567
  const map = renderRepoTreemapMap(model.treemapReport, {
@@ -450,25 +576,23 @@ function renderAtlasWorkspace(model, deps, options) {
450
576
  height: Math.max(4, options.height - 2),
451
577
  selectedTileId: selected,
452
578
  });
453
- const briefing = [
454
- themeText(deps.ctx, 'Overview', { tone: 'accent', bold: true }),
455
- sidebar.overview,
456
- '',
457
- themeText(deps.ctx, 'Focused Region', { tone: 'accent', bold: true }),
458
- sidebar.focused,
459
- '',
460
- themeText(deps.ctx, 'Legend', { tone: 'accent', bold: true }),
461
- sidebar.legend,
462
- '',
463
- themeText(deps.ctx, 'Largest Regions', { tone: 'accent', bold: true }),
464
- sidebar.regions,
465
- '',
466
- sidebar.notes,
467
- ].filter(Boolean).join('\n');
579
+ const briefing = renderAtlasBriefing(sidebar, deps.ctx);
468
580
  return hstackSurface(
469
581
  gap,
470
- panel({ title: 'Repository Atlas', body: map, width: mapWidth, height: options.height, ctx: deps.ctx }),
471
- panel({ title: 'Atlas Briefing', body: briefing, width: sidebarWidth, height: options.height, ctx: deps.ctx }),
582
+ panel({
583
+ title: 'Repository Atlas',
584
+ body: map,
585
+ width: mapWidth,
586
+ height: options.height,
587
+ ctx: deps.ctx,
588
+ }),
589
+ panel({
590
+ title: 'Atlas Briefing',
591
+ body: briefing,
592
+ width: sidebarWidth,
593
+ height: options.height,
594
+ ctx: deps.ctx,
595
+ })
472
596
  );
473
597
  }
474
598
 
@@ -477,7 +601,10 @@ function renderOperationsWorkspace(model, deps, options) {
477
601
  const topHeight = Math.max(8, Math.floor(options.height / 2));
478
602
  return vstackSurface(
479
603
  renderEconomicsPanel(model, deps.ctx, { width: options.width, height: topHeight }),
480
- renderOpsDetailPanel(model, deps.ctx, { width: options.width, height: Math.max(4, options.height - topHeight) }),
604
+ renderOpsDetailPanel(model, deps.ctx, {
605
+ width: options.width,
606
+ height: Math.max(4, options.height - topHeight),
607
+ })
481
608
  );
482
609
  }
483
610
  const gap = 2;
@@ -486,22 +613,24 @@ function renderOperationsWorkspace(model, deps, options) {
486
613
  return hstackSurface(
487
614
  gap,
488
615
  renderEconomicsPanel(model, deps.ctx, { width: leftWidth, height: options.height }),
489
- renderOpsDetailPanel(model, deps.ctx, { width: rightWidth, height: options.height }),
616
+ renderOpsDetailPanel(model, deps.ctx, { width: rightWidth, height: options.height })
490
617
  );
491
618
  }
492
619
 
493
620
  function renderEconomicsPanel(model, ctx, box) {
494
621
  const { width, height } = box;
495
- const body = model.statsStatus === 'ready' && model.statsReport
496
- ? renderStats(model.statsReport, ctx)
497
- : `${themeText(ctx, 'Vault Economics', { tone: 'brand', bold: true })}\n\nStats are ${model.statsStatus}. Press s to refresh.`;
622
+ const body =
623
+ model.statsStatus === 'ready' && model.statsReport
624
+ ? renderStats(model.statsReport, ctx)
625
+ : `${themeText(ctx, 'Vault Economics', { tone: 'brand', bold: true })}\n\nStats are ${model.statsStatus}. Press s to refresh.`;
498
626
  return panel({ title: 'Vault Economics', body, width, height, ctx });
499
627
  }
500
628
 
501
629
  function renderStats(stats, ctx) {
502
- const chunking = Object.entries(stats.chunkingStrategies ?? {})
503
- .map(([strategy, count]) => `${strategy}:${count}`)
504
- .join(', ') || '-';
630
+ const chunking =
631
+ Object.entries(stats.chunkingStrategies ?? {})
632
+ .map(([strategy, count]) => `${strategy}:${count}`)
633
+ .join(', ') || '-';
505
634
  return [
506
635
  `${themeText(ctx, 'entries', { tone: 'accent' })} ${stats.entries}`,
507
636
  `${themeText(ctx, 'logical size', { tone: 'accent' })} ${formatSize(stats.totalLogicalSize)}`,
@@ -517,9 +646,12 @@ function renderStats(stats, ctx) {
517
646
 
518
647
  function renderOpsDetailPanel(model, ctx, box) {
519
648
  const { width, height } = box;
520
- const doctor = model.doctorStatus === 'ready' && model.doctorReport
521
- ? (typeof model.doctorReport === 'string' ? model.doctorReport : renderHealthDashboard(model.doctorReport, ctx))
522
- : `Doctor status: ${model.doctorStatus}\nPress x to run a sweep.`;
649
+ const doctor =
650
+ model.doctorStatus === 'ready' && model.doctorReport
651
+ ? typeof model.doctorReport === 'string'
652
+ ? model.doctorReport
653
+ : renderHealthDashboard(model.doctorReport, ctx)
654
+ : `Doctor status: ${model.doctorStatus}\nPress x to run a sweep.`;
523
655
  const feed = renderOperationFeed(model.operationFeed, ctx);
524
656
  return panel({
525
657
  title: 'Operations Deck',
@@ -530,115 +662,21 @@ function renderOpsDetailPanel(model, ctx, box) {
530
662
  });
531
663
  }
532
664
 
533
- function renderOverlays(model, deps, options) {
534
- if (model.settingsOpen) {
535
- blitOverlay(options.screen, renderSettingsDrawer(model, deps, options));
536
- }
537
- if (model.palette) {
538
- const width = Math.min(84, Math.max(24, options.width - 6));
539
- const palette = panel({
540
- title: 'Command Palette',
541
- body: commandPaletteSurface(model.palette, { width: width - 2, ctx: deps.ctx, showScrollbar: true }),
542
- width,
543
- height: Math.min(14, options.height - 4),
544
- ctx: deps.ctx,
545
- });
546
- options.screen.blit(palette, centerX(options.width, palette.width), topThirdY(options.height, palette.height));
547
- }
548
- if (model.showHelp) {
549
- const help = renderHelpSurface(model, deps.ctx, { width: Math.min(HELP_WIDTH, options.width - 4), height: Math.min(20, options.height - 4) });
550
- options.screen.blit(help, centerX(options.width, help.width), topThirdY(options.height, help.height));
551
- }
665
+ function renderPageOverlay(model, deps, options) {
552
666
  if (model.storeWizard) {
553
- const wizard = renderWizardSurface(model.storeWizard, { width: options.width, height: options.height, ctx: deps.ctx });
554
- options.screen.blit(wizard, centerX(options.width, wizard.width), topThirdY(options.height, wizard.height));
555
- }
556
- if (model.quitConfirm) {
557
- blitOverlay(options.screen, modal({
558
- title: 'Quit git-cas?',
559
- body: 'Leave the cockpit session now?',
560
- hint: 'Y / Enter confirm | N / Esc cancel',
561
- width: Math.min(52, options.width - 4),
562
- screenWidth: options.width,
563
- screenHeight: options.height,
564
- borderToken: deps.ctx.theme.theme.border.warning,
565
- bgToken: deps.ctx.theme.theme.surface.overlay,
667
+ const wizard = renderWizardSurface(model.storeWizard, {
668
+ width: options.width,
669
+ height: options.height,
566
670
  ctx: deps.ctx,
567
- }));
568
- }
569
- for (const overlay of renderNotificationStack(model.notifications, {
570
- screenWidth: options.width,
571
- screenHeight: options.height,
572
- ctx: deps.ctx,
573
- margin: 1,
574
- gap: 1,
575
- })) {
576
- blitOverlay(options.screen, overlay);
671
+ });
672
+ options.screen.blit(
673
+ wizard,
674
+ centerX(options.width, wizard.width),
675
+ topThirdY(options.height, wizard.height)
676
+ );
577
677
  }
578
678
  }
579
679
 
580
- function vaultStatus(model) {
581
- if (model.metadata?.encryption && model.vaultEncryptionKey) { return 'encrypted / unlocked'; }
582
- if (model.metadata?.encryption) { return 'encrypted / locked'; }
583
- return 'plaintext vault';
584
- }
585
-
586
- function renderSettingsDrawer(model, deps, options) {
587
- const { ctx } = deps;
588
- const body = [
589
- themeText(ctx, 'Cockpit Settings', { tone: 'brand', bold: true }),
590
- '',
591
- `${themeText(ctx, 'theme', { tone: 'accent' })} bright cockpit`,
592
- `${themeText(ctx, 'workspace', { tone: 'accent' })} ${model.workspace}`,
593
- `${themeText(ctx, 'focus', { tone: 'accent' })} ${model.focusPane ?? '-'}`,
594
- `${themeText(ctx, 'source', { tone: 'accent' })} ${sourceLabel(model.source)}`,
595
- `${themeText(ctx, 'vault', { tone: 'accent' })} ${vaultStatus(model)}`,
596
- `${themeText(ctx, 'short SHA', { tone: 'accent' })} selected chunk expands in footer`,
597
- '',
598
- themeText(ctx, 'F2 closes this drawer.', { tone: 'subdued' }),
599
- ].join('\n');
600
- return drawer({
601
- content: body,
602
- anchor: 'right',
603
- width: Math.min(46, Math.max(28, options.width - 4)),
604
- screenWidth: options.width,
605
- screenHeight: options.height,
606
- title: 'Settings',
607
- borderToken: ctx.theme.theme.border.primary,
608
- bgToken: ctx.theme.theme.surface.overlay,
609
- ctx,
610
- });
611
- }
612
-
613
- function renderHelpSurface(model, ctx, box) {
614
- const lines = [
615
- themeText(ctx, 'Frame', { tone: 'accent', bold: true }),
616
- '1/e Explorer 2/a Atlas 3/o Operations',
617
- '? Help F2 Settings q Quit',
618
- 'Esc Close overlay',
619
- '',
620
- themeText(ctx, 'Explorer', { tone: 'accent', bold: true }),
621
- 'Tab focus / Filter Ctrl+P Search digest',
622
- 'j/k rows/chunks u/d page Enter detail',
623
- 'm Merkle lens i Inspector mode',
624
- '',
625
- themeText(ctx, 'Atlas', { tone: 'accent', bold: true }),
626
- 'j/k focus + Drill in - Drill out',
627
- 't Scope i Path mode r Reload',
628
- '',
629
- themeText(ctx, 'Operations', { tone: 'accent', bold: true }),
630
- 'n Store wizard s Stats x Doctor',
631
- '',
632
- `Active workspace: ${model.workspace}`,
633
- ];
634
- return panel({ title: 'Help', body: lines.join('\n'), width: box.width, height: box.height, ctx });
635
- }
636
-
637
- function blitOverlay(screen, overlay) {
638
- const surface = overlay.surface ?? textSurface(overlay.content, Math.max(1, overlay.content.split('\n').reduce((max, line) => Math.max(max, line.length), 0)), overlay.content.split('\n').length);
639
- screen.blit(surface, overlay.col, overlay.row);
640
- }
641
-
642
680
  function centerX(containerWidth, overlayWidth) {
643
681
  return Math.max(0, Math.floor((containerWidth - overlayWidth) / 2));
644
682
  }