@git-stunts/git-cas 2.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -1
- package/README.md +63 -15
- package/bin/git-cas.js +286 -41
- package/bin/ui/context.js +54 -0
- package/bin/ui/dashboard-cmds.js +34 -0
- package/bin/ui/dashboard-view.js +132 -0
- package/bin/ui/dashboard.js +204 -0
- package/bin/ui/encryption-card.js +49 -0
- package/bin/ui/heatmap.js +103 -0
- package/bin/ui/history-timeline.js +84 -0
- package/bin/ui/manifest-view.js +135 -0
- package/bin/ui/progress.js +126 -0
- package/index.d.ts +133 -2
- package/index.js +76 -9
- package/package.json +10 -1
- package/src/domain/services/VaultService.js +445 -0
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +11 -11
- package/src/infrastructure/adapters/GitRefAdapter.js +67 -0
- package/src/ports/GitRefPort.js +48 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure render functions for the vault dashboard.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { badge } from '@flyingrobots/bijou';
|
|
6
|
+
import { flex, viewport } from '@flyingrobots/bijou-tui';
|
|
7
|
+
import { renderManifestView } from './manifest-view.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Format bytes as compact string.
|
|
11
|
+
*/
|
|
12
|
+
function formatSize(bytes) {
|
|
13
|
+
if (bytes < 1024) { return `${bytes}B`; }
|
|
14
|
+
if (bytes < 1024 * 1024) { return `${(bytes / 1024).toFixed(1)}K`; }
|
|
15
|
+
if (bytes < 1024 * 1024 * 1024) { return `${(bytes / (1024 * 1024)).toFixed(1)}M`; }
|
|
16
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)}G`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Format manifest stats for the list.
|
|
21
|
+
*/
|
|
22
|
+
function formatStats(manifest) {
|
|
23
|
+
const m = manifest.toJSON ? manifest.toJSON() : manifest;
|
|
24
|
+
return `${formatSize(m.size)} ${m.chunks?.length ?? 0}c`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Render a single list item.
|
|
29
|
+
*/
|
|
30
|
+
function renderListItem(entry, index, opts) {
|
|
31
|
+
const prefix = index === opts.model.cursor ? '> ' : ' ';
|
|
32
|
+
const manifest = opts.model.manifestCache.get(entry.slug);
|
|
33
|
+
const stats = manifest ? formatStats(manifest) : '...';
|
|
34
|
+
const line = `${prefix}${entry.slug} ${stats}`;
|
|
35
|
+
return opts.width ? line.slice(0, opts.width) : line;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Compute visible window for cursor scrolling.
|
|
40
|
+
*/
|
|
41
|
+
function visibleRange(cursor, total, height) {
|
|
42
|
+
const start = Math.max(0, Math.min(cursor - Math.floor(height / 2), total - height));
|
|
43
|
+
return { start: Math.max(0, start), end: Math.min(Math.max(0, start) + height, total) };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Render the header line.
|
|
48
|
+
*/
|
|
49
|
+
function renderHeader(model, ctx) {
|
|
50
|
+
const parts = [];
|
|
51
|
+
if (model.metadata?.encryption) {
|
|
52
|
+
parts.push(badge('encrypted', { variant: 'warning', ctx }));
|
|
53
|
+
}
|
|
54
|
+
parts.push(`${model.entries.length} entries`);
|
|
55
|
+
parts.push('refs/cas/vault');
|
|
56
|
+
return parts.join(' ');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Render the list pane.
|
|
61
|
+
*/
|
|
62
|
+
function renderListPane(model, size) {
|
|
63
|
+
const clamp = (s) => (size.width ? s.slice(0, size.width) : s);
|
|
64
|
+
const filterLine = model.filtering ? clamp(`/${model.filterText}\u2588`) : '';
|
|
65
|
+
const listHeight = model.filtering ? size.height - 1 : size.height;
|
|
66
|
+
const items = model.filtered;
|
|
67
|
+
|
|
68
|
+
if (items.length === 0) {
|
|
69
|
+
const msg = clamp(
|
|
70
|
+
model.status === 'loading'
|
|
71
|
+
? 'Loading...'
|
|
72
|
+
: model.error
|
|
73
|
+
? `Error: ${model.error}`
|
|
74
|
+
: 'No entries',
|
|
75
|
+
);
|
|
76
|
+
return padToHeight(msg, listHeight, filterLine);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const { start, end } = visibleRange(model.cursor, items.length, listHeight);
|
|
80
|
+
const lines = [];
|
|
81
|
+
for (let i = start; i < end; i++) {
|
|
82
|
+
lines.push(renderListItem(items[i], i, { model, width: size.width }));
|
|
83
|
+
}
|
|
84
|
+
return padToHeight(lines.join('\n'), listHeight, filterLine);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Pad content to target height, optionally appending a suffix line.
|
|
89
|
+
*/
|
|
90
|
+
function padToHeight(content, height, suffix) {
|
|
91
|
+
const lines = content.split('\n');
|
|
92
|
+
while (lines.length < height) { lines.push(''); }
|
|
93
|
+
return suffix ? `${lines.join('\n')}\n${suffix}` : lines.join('\n');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Render the detail pane with viewport scrolling.
|
|
98
|
+
*/
|
|
99
|
+
function renderDetailPane(model, opts) {
|
|
100
|
+
const entry = model.filtered[model.cursor];
|
|
101
|
+
if (!entry) { return ''; }
|
|
102
|
+
const manifest = model.manifestCache.get(entry.slug);
|
|
103
|
+
if (!manifest) { return 'Loading manifest...'; }
|
|
104
|
+
const content = renderManifestView({ manifest, ctx: opts.ctx });
|
|
105
|
+
return viewport({ width: opts.width, height: opts.height, content, scrollY: model.detailScroll });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Render the body with list and detail panes.
|
|
110
|
+
*/
|
|
111
|
+
function renderBody(model, deps, size) {
|
|
112
|
+
const listBasis = Math.floor(size.width * 0.35);
|
|
113
|
+
return flex(
|
|
114
|
+
{ direction: 'row', width: size.width, height: size.height, gap: 1 },
|
|
115
|
+
{ content: (w, h) => renderListPane(model, { height: h, width: w }), basis: listBasis },
|
|
116
|
+
{ content: (w, h) => renderDetailPane(model, { width: w, height: h, ctx: deps.ctx }), flex: 1 },
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Render the full dashboard layout.
|
|
122
|
+
*/
|
|
123
|
+
export function renderDashboard(model, deps) {
|
|
124
|
+
return flex(
|
|
125
|
+
{ direction: 'column', width: model.columns, height: model.rows },
|
|
126
|
+
{ content: renderHeader(model, deps.ctx), basis: 1 },
|
|
127
|
+
{ content: (w, _h) => '\u2500'.repeat(w), basis: 1 },
|
|
128
|
+
{ content: (w, h) => renderBody(model, deps, { width: w, height: h }), flex: 1 },
|
|
129
|
+
{ content: (w, _h) => '\u2500'.repeat(w), basis: 1 },
|
|
130
|
+
{ content: 'j/k Navigate enter Load / Filter J/K Scroll q Quit', basis: 1 },
|
|
131
|
+
);
|
|
132
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TEA app shell for the vault dashboard.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { run, quit, createKeyMap } from '@flyingrobots/bijou-tui';
|
|
6
|
+
import { createNodeContext } from '@flyingrobots/bijou-node';
|
|
7
|
+
import { loadEntriesCmd, loadManifestCmd } from './dashboard-cmds.js';
|
|
8
|
+
import { renderDashboard } from './dashboard-view.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create keyboard bindings for normal mode.
|
|
12
|
+
*/
|
|
13
|
+
export function createKeyBindings() {
|
|
14
|
+
return createKeyMap()
|
|
15
|
+
.bind('q', 'Quit', { type: 'quit' })
|
|
16
|
+
.bind('j', 'Down', { type: 'move', delta: 1 })
|
|
17
|
+
.bind('down', 'Down', { type: 'move', delta: 1 })
|
|
18
|
+
.bind('k', 'Up', { type: 'move', delta: -1 })
|
|
19
|
+
.bind('up', 'Up', { type: 'move', delta: -1 })
|
|
20
|
+
.bind('enter', 'Load', { type: 'select' })
|
|
21
|
+
.bind('/', 'Filter', { type: 'filter-start' })
|
|
22
|
+
.bind('shift+j', 'Scroll down', { type: 'scroll-detail', delta: 3 })
|
|
23
|
+
.bind('shift+k', 'Scroll up', { type: 'scroll-detail', delta: -3 });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Create the initial model.
|
|
28
|
+
*/
|
|
29
|
+
function createInitModel() {
|
|
30
|
+
return {
|
|
31
|
+
status: 'loading',
|
|
32
|
+
columns: process.stdout.columns ?? 80,
|
|
33
|
+
rows: process.stdout.rows ?? 24,
|
|
34
|
+
entries: [],
|
|
35
|
+
filtered: [],
|
|
36
|
+
cursor: 0,
|
|
37
|
+
filterText: '',
|
|
38
|
+
filtering: false,
|
|
39
|
+
metadata: null,
|
|
40
|
+
manifestCache: new Map(),
|
|
41
|
+
loadingSlug: null,
|
|
42
|
+
detailScroll: 0,
|
|
43
|
+
error: null,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Apply filter text to entries.
|
|
49
|
+
*/
|
|
50
|
+
function applyFilter(entries, text) {
|
|
51
|
+
if (!text) { return entries; }
|
|
52
|
+
return entries.filter(e => e.slug.includes(text));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Handle the loaded-entries message.
|
|
57
|
+
*/
|
|
58
|
+
function handleLoadedEntries(msg, model, cas) {
|
|
59
|
+
const filtered = applyFilter(msg.entries, model.filterText);
|
|
60
|
+
const cursor = Math.max(0, Math.min(model.cursor, filtered.length - 1));
|
|
61
|
+
const cmds = msg.entries.map(e => loadManifestCmd(cas, e.slug, e.treeOid));
|
|
62
|
+
return [{
|
|
63
|
+
...model,
|
|
64
|
+
status: 'ready',
|
|
65
|
+
entries: msg.entries,
|
|
66
|
+
filtered,
|
|
67
|
+
cursor,
|
|
68
|
+
metadata: msg.metadata,
|
|
69
|
+
}, cmds];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Handle a loaded-manifest message.
|
|
74
|
+
*/
|
|
75
|
+
function handleLoadedManifest(msg, model) {
|
|
76
|
+
const cache = new Map(model.manifestCache);
|
|
77
|
+
cache.set(msg.slug, msg.manifest);
|
|
78
|
+
return [{ ...model, manifestCache: cache }, []];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Handle cursor movement.
|
|
83
|
+
*/
|
|
84
|
+
function handleMove(msg, model) {
|
|
85
|
+
const max = model.filtered.length - 1;
|
|
86
|
+
const cursor = Math.max(0, Math.min(max, model.cursor + msg.delta));
|
|
87
|
+
return [{ ...model, cursor, detailScroll: 0 }, []];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Handle filter key input in filter mode.
|
|
92
|
+
*/
|
|
93
|
+
function handleFilterKey(msg, model) {
|
|
94
|
+
if (msg.key === 'escape' || msg.key === 'enter') {
|
|
95
|
+
return [{ ...model, filtering: false }, []];
|
|
96
|
+
}
|
|
97
|
+
if (msg.key === 'backspace') {
|
|
98
|
+
const text = model.filterText.slice(0, -1);
|
|
99
|
+
const filtered = applyFilter(model.entries, text);
|
|
100
|
+
return [{ ...model, filterText: text, filtered, cursor: 0 }, []];
|
|
101
|
+
}
|
|
102
|
+
if (msg.key.length === 1) {
|
|
103
|
+
const text = model.filterText + msg.key;
|
|
104
|
+
const filtered = applyFilter(model.entries, text);
|
|
105
|
+
return [{ ...model, filterText: text, filtered, cursor: 0 }, []];
|
|
106
|
+
}
|
|
107
|
+
return [model, []];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Handle select (enter key) to load manifest.
|
|
112
|
+
*/
|
|
113
|
+
function handleSelect(model, deps) {
|
|
114
|
+
const entry = model.filtered[model.cursor];
|
|
115
|
+
if (!entry || model.manifestCache.has(entry.slug)) {
|
|
116
|
+
return [model, []];
|
|
117
|
+
}
|
|
118
|
+
const cmd = loadManifestCmd(deps.cas, entry.slug, entry.treeOid);
|
|
119
|
+
return [{ ...model, loadingSlug: entry.slug }, [cmd]];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Handle keymap actions.
|
|
124
|
+
*/
|
|
125
|
+
function handleAction(action, model, deps) {
|
|
126
|
+
if (action.type === 'quit') { return [model, [quit()]]; }
|
|
127
|
+
if (action.type === 'move') { return handleMove(action, model); }
|
|
128
|
+
if (action.type === 'filter-start') {
|
|
129
|
+
return [{ ...model, filtering: true, filterText: '', filtered: model.entries, cursor: 0 }, []];
|
|
130
|
+
}
|
|
131
|
+
if (action.type === 'scroll-detail') {
|
|
132
|
+
const scroll = Math.max(0, model.detailScroll + action.delta);
|
|
133
|
+
return [{ ...model, detailScroll: scroll }, []];
|
|
134
|
+
}
|
|
135
|
+
if (action.type === 'select') { return handleSelect(model, deps); }
|
|
136
|
+
return [model, []];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Handle app-level messages (data loading results).
|
|
141
|
+
*/
|
|
142
|
+
function handleAppMsg(msg, model, cas) {
|
|
143
|
+
if (msg.type === 'loaded-entries') { return handleLoadedEntries(msg, model, cas); }
|
|
144
|
+
if (msg.type === 'loaded-manifest') { return handleLoadedManifest(msg, model); }
|
|
145
|
+
if (msg.type === 'load-error') {
|
|
146
|
+
if (msg.source === 'manifest') {
|
|
147
|
+
return [model, []];
|
|
148
|
+
}
|
|
149
|
+
return [{ ...model, status: 'error', error: msg.error }, []];
|
|
150
|
+
}
|
|
151
|
+
return [model, []];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Route all update messages to the appropriate handler.
|
|
156
|
+
*/
|
|
157
|
+
function handleUpdate(msg, model, deps) {
|
|
158
|
+
if (msg.type === 'key' && model.filtering) {
|
|
159
|
+
return handleFilterKey(msg, model);
|
|
160
|
+
}
|
|
161
|
+
if (msg.type === 'key') {
|
|
162
|
+
const action = deps.keyMap.handle(msg);
|
|
163
|
+
if (action) { return handleAction(action, model, deps); }
|
|
164
|
+
return [model, []];
|
|
165
|
+
}
|
|
166
|
+
if (msg.type === 'resize') {
|
|
167
|
+
return [{ ...model, columns: msg.columns, rows: msg.rows }, []];
|
|
168
|
+
}
|
|
169
|
+
return handleAppMsg(msg, model, deps.cas);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Create the TEA app object for the dashboard.
|
|
174
|
+
*/
|
|
175
|
+
export function createDashboardApp(deps) {
|
|
176
|
+
return {
|
|
177
|
+
init: () => [createInitModel(), [loadEntriesCmd(deps.cas)]],
|
|
178
|
+
update: (msg, model) => handleUpdate(msg, model, deps),
|
|
179
|
+
view: (model) => renderDashboard(model, deps),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Print static list for non-TTY environments.
|
|
185
|
+
*/
|
|
186
|
+
async function printStaticList(cas) {
|
|
187
|
+
const entries = await cas.listVault();
|
|
188
|
+
for (const { slug, treeOid } of entries) {
|
|
189
|
+
process.stdout.write(`${slug}\t${treeOid}\n`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Launch the interactive vault dashboard.
|
|
195
|
+
*/
|
|
196
|
+
export async function launchDashboard(cas) {
|
|
197
|
+
if (!process.stdout.isTTY) {
|
|
198
|
+
return printStaticList(cas);
|
|
199
|
+
}
|
|
200
|
+
const ctx = createNodeContext();
|
|
201
|
+
const keyMap = createKeyBindings();
|
|
202
|
+
const deps = { keyMap, cas, ctx };
|
|
203
|
+
return run(createDashboardApp(deps), { ctx });
|
|
204
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encryption info card — visual summary of vault crypto configuration.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { box, badge, headerBox } from '@flyingrobots/bijou';
|
|
6
|
+
import { getCliContext } from './context.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Render an encryption info card for the vault.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object} options
|
|
12
|
+
* @param {Object|null} options.metadata - Vault metadata (from getVaultMetadata()).
|
|
13
|
+
* @param {boolean} [options.unlocked] - Whether a key/passphrase was provided.
|
|
14
|
+
* @returns {string}
|
|
15
|
+
*/
|
|
16
|
+
export function renderEncryptionCard({ metadata, unlocked = false }) {
|
|
17
|
+
const ctx = getCliContext();
|
|
18
|
+
|
|
19
|
+
if (!metadata?.encryption) {
|
|
20
|
+
return box('No encryption configured', { ctx });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const { encryption } = metadata;
|
|
24
|
+
const { kdf } = encryption;
|
|
25
|
+
|
|
26
|
+
const status = unlocked
|
|
27
|
+
? badge('unlocked', { variant: 'success', ctx })
|
|
28
|
+
: badge('locked', { variant: 'error', ctx });
|
|
29
|
+
|
|
30
|
+
const rows = [
|
|
31
|
+
` cipher ${encryption.cipher}`,
|
|
32
|
+
` kdf ${kdf.algorithm}`,
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
if (kdf.algorithm === 'pbkdf2') {
|
|
36
|
+
rows.push(` iterations ${kdf.iterations.toLocaleString()}`);
|
|
37
|
+
} else if (kdf.algorithm === 'scrypt') {
|
|
38
|
+
rows.push(` cost ${kdf.cost}`);
|
|
39
|
+
rows.push(` blockSize ${kdf.blockSize}`);
|
|
40
|
+
rows.push(` parallel ${kdf.parallelization}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
rows.push(` key length ${kdf.keyLength} bytes`);
|
|
44
|
+
rows.push(` salt ${kdf.salt.slice(0, 12)}...`);
|
|
45
|
+
rows.push(` status ${status}`);
|
|
46
|
+
|
|
47
|
+
const content = rows.join('\n');
|
|
48
|
+
return `${headerBox('Encryption', { ctx })}\n${box(content, { ctx })}`;
|
|
49
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chunk heatmap visualization — visual block map of chunks.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { gradientText } from '@flyingrobots/bijou';
|
|
6
|
+
import { getCliContext } from './context.js';
|
|
7
|
+
|
|
8
|
+
const GRADIENT_STOPS = [
|
|
9
|
+
{ pos: 0, color: [0, 255, 255] },
|
|
10
|
+
{ pos: 1, color: [255, 0, 255] },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Format bytes as human-readable string.
|
|
15
|
+
*/
|
|
16
|
+
function formatBytes(bytes) {
|
|
17
|
+
if (bytes < 1024) {
|
|
18
|
+
return `${bytes} B`;
|
|
19
|
+
}
|
|
20
|
+
if (bytes < 1024 * 1024) {
|
|
21
|
+
return `${(bytes / 1024).toFixed(1)} KiB`;
|
|
22
|
+
}
|
|
23
|
+
if (bytes < 1024 * 1024 * 1024) {
|
|
24
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
|
|
25
|
+
}
|
|
26
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GiB`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Build the block grid string from chunks.
|
|
31
|
+
*/
|
|
32
|
+
function buildGrid(chunks, boundaries, width) {
|
|
33
|
+
let grid = '';
|
|
34
|
+
let col = 0;
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
37
|
+
if (boundaries.has(i) && col > 0) {
|
|
38
|
+
grid += '\n';
|
|
39
|
+
col = 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
grid += '\u2588';
|
|
43
|
+
col++;
|
|
44
|
+
|
|
45
|
+
if (col >= width) {
|
|
46
|
+
grid += '\n';
|
|
47
|
+
col = 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (col > 0) {
|
|
52
|
+
grid += '\n';
|
|
53
|
+
}
|
|
54
|
+
return grid;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Build the legend line.
|
|
59
|
+
*/
|
|
60
|
+
function buildLegend(chunks, subManifests) {
|
|
61
|
+
const chunkSize = chunks.length > 0 ? chunks[0].size : 0;
|
|
62
|
+
const parts = [`${chunks.length} chunks`];
|
|
63
|
+
if (subManifests.length) {
|
|
64
|
+
parts.push(`${subManifests.length} sub-manifests`);
|
|
65
|
+
}
|
|
66
|
+
if (chunkSize) {
|
|
67
|
+
parts.push(`${formatBytes(chunkSize)}/chunk`);
|
|
68
|
+
}
|
|
69
|
+
return parts.join(' ');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Render a chunk heatmap for a manifest.
|
|
74
|
+
*
|
|
75
|
+
* @param {Object} options
|
|
76
|
+
* @param {Object} options.manifest - The manifest (from readManifest).
|
|
77
|
+
* @returns {string}
|
|
78
|
+
*/
|
|
79
|
+
export function renderHeatmap({ manifest }) {
|
|
80
|
+
const ctx = getCliContext();
|
|
81
|
+
const m = manifest.toJSON ? manifest.toJSON() : manifest;
|
|
82
|
+
const chunks = m.chunks || [];
|
|
83
|
+
|
|
84
|
+
if (chunks.length === 0) {
|
|
85
|
+
return 'No chunks to display\n';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const width = Math.min(60, (ctx.runtime.columns || 80) - 10);
|
|
89
|
+
const subManifests = m.subManifests || [];
|
|
90
|
+
|
|
91
|
+
const boundaries = new Set();
|
|
92
|
+
for (const sm of subManifests) {
|
|
93
|
+
if (sm.startIndex > 0) {
|
|
94
|
+
boundaries.add(sm.startIndex);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const grid = buildGrid(chunks, boundaries, width);
|
|
99
|
+
const colored = gradientText(grid, GRADIENT_STOPS, { style: ctx.style });
|
|
100
|
+
const legend = buildLegend(chunks, subManifests);
|
|
101
|
+
|
|
102
|
+
return `${colored}\n${legend}\n`;
|
|
103
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault history as a color-coded timeline.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { timeline, paginator } from '@flyingrobots/bijou';
|
|
6
|
+
import { getCliContext } from './context.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Parse a vault commit line into structured data.
|
|
10
|
+
* Input format: "eff5569 vault: add photos/beach"
|
|
11
|
+
*
|
|
12
|
+
* @param {string} line
|
|
13
|
+
* @returns {{ oid: string, operation: string, slug: string|null }|null}
|
|
14
|
+
*/
|
|
15
|
+
function parseCommitLine(line) {
|
|
16
|
+
const trimmed = line.trim();
|
|
17
|
+
if (!trimmed) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const spaceIdx = trimmed.indexOf(' ');
|
|
22
|
+
if (spaceIdx === -1) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const oid = trimmed.slice(0, spaceIdx);
|
|
27
|
+
const message = trimmed.slice(spaceIdx + 1);
|
|
28
|
+
|
|
29
|
+
const match = message.match(/^vault:\s*(init|add|update|remove)\s*(.*)$/);
|
|
30
|
+
if (!match) {
|
|
31
|
+
return { oid, operation: 'unknown', slug: message };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return { oid, operation: match[1], slug: match[2] || null };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const STATUS_MAP = {
|
|
38
|
+
init: 'info',
|
|
39
|
+
add: 'success',
|
|
40
|
+
update: 'warning',
|
|
41
|
+
remove: 'error',
|
|
42
|
+
unknown: 'pending',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Render vault history as a color-coded timeline.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} gitLogOutput - Raw output from `git log --oneline`.
|
|
49
|
+
* @param {Object} [options]
|
|
50
|
+
* @param {number} [options.page] - Current page (1-based).
|
|
51
|
+
* @param {number} [options.perPage] - Entries per page (default 20).
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
export function renderHistoryTimeline(gitLogOutput, options = {}) {
|
|
55
|
+
const ctx = getCliContext();
|
|
56
|
+
const perPage = options.perPage ?? 20;
|
|
57
|
+
const page = options.page ?? 1;
|
|
58
|
+
|
|
59
|
+
const lines = gitLogOutput.split('\n').filter(Boolean);
|
|
60
|
+
if (lines.length === 0) {
|
|
61
|
+
return 'No history\n';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const totalPages = Math.ceil(lines.length / perPage);
|
|
65
|
+
const start = (page - 1) * perPage;
|
|
66
|
+
const pageLines = lines.slice(start, start + perPage);
|
|
67
|
+
|
|
68
|
+
const events = pageLines
|
|
69
|
+
.map(parseCommitLine)
|
|
70
|
+
.filter(Boolean)
|
|
71
|
+
.map(({ oid, operation, slug }) => ({
|
|
72
|
+
label: slug ? `vault: ${operation} ${slug}` : `vault: ${operation}`,
|
|
73
|
+
description: oid,
|
|
74
|
+
status: STATUS_MAP[operation] || 'pending',
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
let output = timeline(events, { ctx });
|
|
78
|
+
|
|
79
|
+
if (totalPages > 1) {
|
|
80
|
+
output += `\n${paginator({ current: page, total: totalPages, ctx })}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return output;
|
|
84
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manifest anatomy view — rich visual breakdown of a manifest.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { box, badge, table, tree, headerBox } from '@flyingrobots/bijou';
|
|
6
|
+
import { getCliContext } from './context.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Format bytes as human-readable string.
|
|
10
|
+
*/
|
|
11
|
+
function formatBytes(bytes) {
|
|
12
|
+
if (bytes < 1024) {
|
|
13
|
+
return `${bytes} B`;
|
|
14
|
+
}
|
|
15
|
+
if (bytes < 1024 * 1024) {
|
|
16
|
+
return `${(bytes / 1024).toFixed(1)} KiB`;
|
|
17
|
+
}
|
|
18
|
+
if (bytes < 1024 * 1024 * 1024) {
|
|
19
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
|
|
20
|
+
}
|
|
21
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GiB`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Build the header badges line.
|
|
26
|
+
*/
|
|
27
|
+
function renderBadges(m, ctx) {
|
|
28
|
+
const badges = [badge(`v${m.version}`, { ctx })];
|
|
29
|
+
if (m.encryption) {
|
|
30
|
+
badges.push(badge('encrypted', { variant: 'warning', ctx }));
|
|
31
|
+
}
|
|
32
|
+
if (m.compression) {
|
|
33
|
+
badges.push(badge(m.compression.algorithm, { variant: 'info', ctx }));
|
|
34
|
+
}
|
|
35
|
+
if (m.subManifests?.length) {
|
|
36
|
+
badges.push(badge('merkle', { variant: 'info', ctx }));
|
|
37
|
+
}
|
|
38
|
+
return badges.join(' ');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Build the encryption section.
|
|
43
|
+
*/
|
|
44
|
+
function renderEncryptionSection(enc, ctx) {
|
|
45
|
+
const rows = [` algorithm ${enc.algorithm}`];
|
|
46
|
+
if (enc.kdf) {
|
|
47
|
+
rows.push(` kdf ${enc.kdf.algorithm}`);
|
|
48
|
+
if (enc.kdf.iterations) {
|
|
49
|
+
rows.push(` iterations ${enc.kdf.iterations.toLocaleString()}`);
|
|
50
|
+
}
|
|
51
|
+
if (enc.kdf.cost) {
|
|
52
|
+
rows.push(` cost ${enc.kdf.cost}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (enc.nonce) {
|
|
56
|
+
rows.push(` nonce ${enc.nonce.slice(0, 16)}...`);
|
|
57
|
+
}
|
|
58
|
+
if (enc.tag) {
|
|
59
|
+
rows.push(` tag ${enc.tag.slice(0, 16)}...`);
|
|
60
|
+
}
|
|
61
|
+
return `${headerBox('Encryption', { ctx })}\n${box(rows.join('\n'), { ctx })}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Build the chunks section.
|
|
66
|
+
*/
|
|
67
|
+
function renderChunksSection(chunks, ctx) {
|
|
68
|
+
const displayChunks = chunks.slice(0, 20);
|
|
69
|
+
const chunkRows = displayChunks.map(c => [
|
|
70
|
+
String(c.index),
|
|
71
|
+
formatBytes(c.size),
|
|
72
|
+
`${c.digest.slice(0, 12)}...`,
|
|
73
|
+
`${c.blob.slice(0, 12)}...`,
|
|
74
|
+
]);
|
|
75
|
+
const chunkTable = table({
|
|
76
|
+
columns: [{ header: '#' }, { header: 'Size' }, { header: 'Digest' }, { header: 'Blob' }],
|
|
77
|
+
rows: chunkRows,
|
|
78
|
+
ctx,
|
|
79
|
+
});
|
|
80
|
+
const suffix = chunks.length > 20
|
|
81
|
+
? `\n ...and ${chunks.length - 20} more`
|
|
82
|
+
: '';
|
|
83
|
+
return `${headerBox(`Chunks (${chunks.length})`, { ctx })}\n${chunkTable}${suffix}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Build the metadata section.
|
|
88
|
+
*/
|
|
89
|
+
function renderMetadataSection(m, ctx) {
|
|
90
|
+
const meta = [
|
|
91
|
+
` slug ${m.slug}`,
|
|
92
|
+
` filename ${m.filename}`,
|
|
93
|
+
` size ${formatBytes(m.size)}`,
|
|
94
|
+
` chunks ${m.chunks?.length ?? 0}`,
|
|
95
|
+
];
|
|
96
|
+
return `${headerBox('Metadata', { ctx })}\n${box(meta.join('\n'), { ctx })}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Build the sub-manifests section.
|
|
101
|
+
*/
|
|
102
|
+
function renderSubManifestsSection(m, ctx) {
|
|
103
|
+
const nodes = m.subManifests.map((sm, i) => ({
|
|
104
|
+
label: `sub-${i} ${sm.chunkCount} chunks start: ${sm.startIndex} oid: ${sm.oid.slice(0, 8)}...`,
|
|
105
|
+
}));
|
|
106
|
+
return `${headerBox(`Sub-manifests (${m.subManifests.length})`, { ctx })}\n${tree(nodes, { ctx })}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Render a full manifest anatomy view.
|
|
111
|
+
*
|
|
112
|
+
* @param {Object} options
|
|
113
|
+
* @param {Object} options.manifest - The manifest (from readManifest).
|
|
114
|
+
* @param {Object} [options.ctx] - Optional bijou context override.
|
|
115
|
+
* @returns {string}
|
|
116
|
+
*/
|
|
117
|
+
export function renderManifestView({ manifest, ctx = getCliContext() }) {
|
|
118
|
+
const m = manifest.toJSON ? manifest.toJSON() : manifest;
|
|
119
|
+
const sections = [renderBadges(m, ctx), renderMetadataSection(m, ctx)];
|
|
120
|
+
|
|
121
|
+
if (m.encryption) {
|
|
122
|
+
sections.push(renderEncryptionSection(m.encryption, ctx));
|
|
123
|
+
}
|
|
124
|
+
if (m.compression) {
|
|
125
|
+
sections.push(`${headerBox('Compression', { ctx })}\n${box(` algorithm ${m.compression.algorithm}`, { ctx })}`);
|
|
126
|
+
}
|
|
127
|
+
if (m.subManifests?.length) {
|
|
128
|
+
sections.push(renderSubManifestsSection(m, ctx));
|
|
129
|
+
}
|
|
130
|
+
if (m.chunks?.length) {
|
|
131
|
+
sections.push(renderChunksSection(m.chunks, ctx));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return `${sections.join('\n\n')}\n`;
|
|
135
|
+
}
|