@git-stunts/git-cas 5.2.1 → 5.3.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 +100 -0
- package/README.md +67 -5
- package/bin/actions.js +38 -8
- package/bin/config.js +203 -0
- package/bin/git-cas.js +200 -54
- package/bin/ui/context.js +13 -0
- package/bin/ui/dashboard-cmds.js +14 -6
- package/bin/ui/dashboard-view.js +55 -6
- package/bin/ui/dashboard.js +109 -7
- package/bin/ui/encryption-card.js +2 -2
- package/bin/ui/heatmap.js +20 -2
- package/bin/ui/history-timeline.js +8 -6
- package/bin/ui/manifest-view.js +37 -8
- package/bin/ui/passphrase-prompt.js +100 -0
- package/bin/ui/progress.js +60 -38
- package/index.d.ts +20 -1
- package/index.js +74 -218
- package/package.json +2 -1
- package/src/domain/errors/CasError.js +3 -1
- package/src/domain/helpers/buildKdfMetadata.js +18 -0
- package/src/domain/services/CasService.d.ts +21 -1
- package/src/domain/services/CasService.js +134 -228
- package/src/domain/services/KeyResolver.js +220 -0
- package/src/domain/services/Semaphore.js +2 -2
- package/src/domain/services/VaultService.js +72 -29
- package/src/domain/services/rotateVaultPassphrase.js +143 -0
- package/src/infrastructure/adapters/BunCryptoAdapter.js +38 -6
- package/src/infrastructure/adapters/EventEmitterObserver.js +19 -7
- package/src/infrastructure/adapters/FileIOHelper.js +64 -0
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +21 -5
- package/src/infrastructure/adapters/GitRefAdapter.js +27 -5
- package/src/infrastructure/adapters/NodeCryptoAdapter.js +49 -8
- package/src/infrastructure/adapters/SilentObserver.js +15 -0
- package/src/infrastructure/adapters/StatsCollector.js +15 -1
- package/src/infrastructure/adapters/WebCryptoAdapter.js +120 -42
- package/src/infrastructure/adapters/createCryptoAdapter.js +25 -0
- package/src/infrastructure/chunkers/CdcChunker.js +5 -0
- package/src/infrastructure/chunkers/FixedChunker.js +28 -8
- package/src/infrastructure/chunkers/resolveChunker.js +45 -0
- package/src/infrastructure/codecs/CborCodec.js +11 -3
- package/src/infrastructure/codecs/JsonCodec.js +10 -2
- package/src/ports/CodecPort.js +3 -3
- package/src/ports/CryptoPort.js +56 -23
- package/src/ports/GitPersistencePort.js +4 -4
- package/src/ports/GitRefPort.js +10 -10
- package/src/types/ambient.d.ts +37 -0
package/bin/ui/dashboard-view.js
CHANGED
|
@@ -6,8 +6,18 @@ import { badge } from '@flyingrobots/bijou';
|
|
|
6
6
|
import { flex, viewport } from '@flyingrobots/bijou-tui';
|
|
7
7
|
import { renderManifestView } from './manifest-view.js';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {import('./dashboard.js').DashModel} DashModel
|
|
11
|
+
* @typedef {import('./dashboard.js').DashDeps} DashDeps
|
|
12
|
+
* @typedef {import('@flyingrobots/bijou').BijouContext} BijouContext
|
|
13
|
+
* @typedef {import('../../src/domain/value-objects/Manifest.js').default} Manifest
|
|
14
|
+
*/
|
|
15
|
+
|
|
9
16
|
/**
|
|
10
17
|
* Format bytes as compact string.
|
|
18
|
+
*
|
|
19
|
+
* @param {number} bytes
|
|
20
|
+
* @returns {string}
|
|
11
21
|
*/
|
|
12
22
|
function formatSize(bytes) {
|
|
13
23
|
if (bytes < 1024) { return `${bytes}B`; }
|
|
@@ -18,6 +28,9 @@ function formatSize(bytes) {
|
|
|
18
28
|
|
|
19
29
|
/**
|
|
20
30
|
* Format manifest stats for the list.
|
|
31
|
+
*
|
|
32
|
+
* @param {Manifest} manifest
|
|
33
|
+
* @returns {string}
|
|
21
34
|
*/
|
|
22
35
|
function formatStats(manifest) {
|
|
23
36
|
const m = manifest.toJSON ? manifest.toJSON() : manifest;
|
|
@@ -26,6 +39,11 @@ function formatStats(manifest) {
|
|
|
26
39
|
|
|
27
40
|
/**
|
|
28
41
|
* Render a single list item.
|
|
42
|
+
*
|
|
43
|
+
* @param {{ slug: string, treeOid: string }} entry
|
|
44
|
+
* @param {number} index
|
|
45
|
+
* @param {{ model: DashModel, width?: number }} opts
|
|
46
|
+
* @returns {string}
|
|
29
47
|
*/
|
|
30
48
|
function renderListItem(entry, index, opts) {
|
|
31
49
|
const prefix = index === opts.model.cursor ? '> ' : ' ';
|
|
@@ -37,6 +55,11 @@ function renderListItem(entry, index, opts) {
|
|
|
37
55
|
|
|
38
56
|
/**
|
|
39
57
|
* Compute visible window for cursor scrolling.
|
|
58
|
+
*
|
|
59
|
+
* @param {number} cursor
|
|
60
|
+
* @param {number} total
|
|
61
|
+
* @param {number} height
|
|
62
|
+
* @returns {{ start: number, end: number }}
|
|
40
63
|
*/
|
|
41
64
|
function visibleRange(cursor, total, height) {
|
|
42
65
|
const start = Math.max(0, Math.min(cursor - Math.floor(height / 2), total - height));
|
|
@@ -45,6 +68,10 @@ function visibleRange(cursor, total, height) {
|
|
|
45
68
|
|
|
46
69
|
/**
|
|
47
70
|
* Render the header line.
|
|
71
|
+
*
|
|
72
|
+
* @param {DashModel} model
|
|
73
|
+
* @param {BijouContext} ctx
|
|
74
|
+
* @returns {string}
|
|
48
75
|
*/
|
|
49
76
|
function renderHeader(model, ctx) {
|
|
50
77
|
const parts = [];
|
|
@@ -58,9 +85,13 @@ function renderHeader(model, ctx) {
|
|
|
58
85
|
|
|
59
86
|
/**
|
|
60
87
|
* Render the list pane.
|
|
88
|
+
*
|
|
89
|
+
* @param {DashModel} model
|
|
90
|
+
* @param {{ height: number, width?: number }} size
|
|
91
|
+
* @returns {string}
|
|
61
92
|
*/
|
|
62
93
|
function renderListPane(model, size) {
|
|
63
|
-
const clamp = (s) => (size.width ? s.slice(0, size.width) : s);
|
|
94
|
+
const clamp = (/** @type {string} */ s) => (typeof size.width === 'number' && size.width > 0 ? s.slice(0, size.width) : s);
|
|
64
95
|
const filterLine = model.filtering ? clamp(`/${model.filterText}\u2588`) : '';
|
|
65
96
|
const listHeight = model.filtering ? size.height - 1 : size.height;
|
|
66
97
|
const items = model.filtered;
|
|
@@ -86,6 +117,11 @@ function renderListPane(model, size) {
|
|
|
86
117
|
|
|
87
118
|
/**
|
|
88
119
|
* Pad content to target height, optionally appending a suffix line.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} content
|
|
122
|
+
* @param {number} height
|
|
123
|
+
* @param {string} suffix
|
|
124
|
+
* @returns {string}
|
|
89
125
|
*/
|
|
90
126
|
function padToHeight(content, height, suffix) {
|
|
91
127
|
const lines = content.split('\n');
|
|
@@ -95,6 +131,10 @@ function padToHeight(content, height, suffix) {
|
|
|
95
131
|
|
|
96
132
|
/**
|
|
97
133
|
* Render the detail pane with viewport scrolling.
|
|
134
|
+
*
|
|
135
|
+
* @param {DashModel} model
|
|
136
|
+
* @param {{ width: number, height: number, ctx: BijouContext }} opts
|
|
137
|
+
* @returns {string}
|
|
98
138
|
*/
|
|
99
139
|
function renderDetailPane(model, opts) {
|
|
100
140
|
const entry = model.filtered[model.cursor];
|
|
@@ -107,26 +147,35 @@ function renderDetailPane(model, opts) {
|
|
|
107
147
|
|
|
108
148
|
/**
|
|
109
149
|
* Render the body with list and detail panes.
|
|
150
|
+
*
|
|
151
|
+
* @param {DashModel} model
|
|
152
|
+
* @param {DashDeps} deps
|
|
153
|
+
* @param {{ width: number, height: number }} size
|
|
154
|
+
* @returns {string}
|
|
110
155
|
*/
|
|
111
156
|
function renderBody(model, deps, size) {
|
|
112
157
|
const listBasis = Math.floor(size.width * 0.35);
|
|
113
158
|
return flex(
|
|
114
159
|
{ 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 },
|
|
160
|
+
{ content: (/** @type {number} */ w, /** @type {number} */ h) => renderListPane(model, { height: h, width: w }), basis: listBasis },
|
|
161
|
+
{ content: (/** @type {number} */ w, /** @type {number} */ h) => renderDetailPane(model, { width: w, height: h, ctx: deps.ctx }), flex: 1 },
|
|
117
162
|
);
|
|
118
163
|
}
|
|
119
164
|
|
|
120
165
|
/**
|
|
121
166
|
* Render the full dashboard layout.
|
|
167
|
+
*
|
|
168
|
+
* @param {DashModel} model
|
|
169
|
+
* @param {DashDeps} deps
|
|
170
|
+
* @returns {string}
|
|
122
171
|
*/
|
|
123
172
|
export function renderDashboard(model, deps) {
|
|
124
173
|
return flex(
|
|
125
174
|
{ direction: 'column', width: model.columns, height: model.rows },
|
|
126
175
|
{ 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 },
|
|
176
|
+
{ content: (/** @type {number} */ w, /** @type {number} */ _h) => '\u2500'.repeat(w), basis: 1 },
|
|
177
|
+
{ content: (/** @type {number} */ w, /** @type {number} */ h) => renderBody(model, deps, { width: w, height: h }), flex: 1 },
|
|
178
|
+
{ content: (/** @type {number} */ w, /** @type {number} */ _h) => '\u2500'.repeat(w), basis: 1 },
|
|
130
179
|
{ content: 'j/k Navigate enter Load / Filter J/K Scroll q Quit', basis: 1 },
|
|
131
180
|
);
|
|
132
181
|
}
|
package/bin/ui/dashboard.js
CHANGED
|
@@ -7,8 +7,61 @@ import { createNodeContext } from '@flyingrobots/bijou-node';
|
|
|
7
7
|
import { loadEntriesCmd, loadManifestCmd } from './dashboard-cmds.js';
|
|
8
8
|
import { renderDashboard } from './dashboard-view.js';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {import('@flyingrobots/bijou').BijouContext} BijouContext
|
|
12
|
+
* @typedef {import('@flyingrobots/bijou-tui').KeyMsg} KeyMsg
|
|
13
|
+
* @typedef {import('@flyingrobots/bijou-tui').ResizeMsg} ResizeMsg
|
|
14
|
+
* @typedef {import('@flyingrobots/bijou-tui').Cmd<DashMsg>} DashCmd
|
|
15
|
+
* @typedef {import('@flyingrobots/bijou-tui').KeyMap<DashAction>} DashKeyMap
|
|
16
|
+
* @typedef {import('../../index.js').default} ContentAddressableStore
|
|
17
|
+
* @typedef {import('../../src/domain/value-objects/Manifest.js').default} Manifest
|
|
18
|
+
* @typedef {{ slug: string, treeOid: string }} VaultEntry
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {{ type: 'quit' }
|
|
23
|
+
* | { type: 'move', delta: number }
|
|
24
|
+
* | { type: 'select' }
|
|
25
|
+
* | { type: 'filter-start' }
|
|
26
|
+
* | { type: 'scroll-detail', delta: number }
|
|
27
|
+
* } DashAction
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {{ type: 'loaded-entries', entries: VaultEntry[], metadata: any }
|
|
32
|
+
* | { type: 'loaded-manifest', slug: string, manifest: Manifest }
|
|
33
|
+
* | { type: 'load-error', source: string, slug?: string, error: string }
|
|
34
|
+
* } DashMsg
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {Object} DashModel
|
|
39
|
+
* @property {string} status
|
|
40
|
+
* @property {number} columns
|
|
41
|
+
* @property {number} rows
|
|
42
|
+
* @property {VaultEntry[]} entries
|
|
43
|
+
* @property {VaultEntry[]} filtered
|
|
44
|
+
* @property {number} cursor
|
|
45
|
+
* @property {string} filterText
|
|
46
|
+
* @property {boolean} filtering
|
|
47
|
+
* @property {any} metadata
|
|
48
|
+
* @property {Map<string, Manifest>} manifestCache
|
|
49
|
+
* @property {string | null} loadingSlug
|
|
50
|
+
* @property {number} detailScroll
|
|
51
|
+
* @property {string | null} error
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {Object} DashDeps
|
|
56
|
+
* @property {DashKeyMap} keyMap
|
|
57
|
+
* @property {ContentAddressableStore} cas
|
|
58
|
+
* @property {BijouContext} ctx
|
|
59
|
+
*/
|
|
60
|
+
|
|
10
61
|
/**
|
|
11
62
|
* Create keyboard bindings for normal mode.
|
|
63
|
+
*
|
|
64
|
+
* @returns {DashKeyMap}
|
|
12
65
|
*/
|
|
13
66
|
export function createKeyBindings() {
|
|
14
67
|
return createKeyMap()
|
|
@@ -25,6 +78,8 @@ export function createKeyBindings() {
|
|
|
25
78
|
|
|
26
79
|
/**
|
|
27
80
|
* Create the initial model.
|
|
81
|
+
*
|
|
82
|
+
* @returns {DashModel}
|
|
28
83
|
*/
|
|
29
84
|
function createInitModel() {
|
|
30
85
|
return {
|
|
@@ -46,19 +101,28 @@ function createInitModel() {
|
|
|
46
101
|
|
|
47
102
|
/**
|
|
48
103
|
* Apply filter text to entries.
|
|
104
|
+
*
|
|
105
|
+
* @param {VaultEntry[]} entries
|
|
106
|
+
* @param {string} text
|
|
107
|
+
* @returns {VaultEntry[]}
|
|
49
108
|
*/
|
|
50
109
|
function applyFilter(entries, text) {
|
|
51
110
|
if (!text) { return entries; }
|
|
52
|
-
return entries.filter(e => e.slug.includes(text));
|
|
111
|
+
return entries.filter((/** @type {VaultEntry} */ e) => e.slug.includes(text));
|
|
53
112
|
}
|
|
54
113
|
|
|
55
114
|
/**
|
|
56
115
|
* Handle the loaded-entries message.
|
|
116
|
+
*
|
|
117
|
+
* @param {DashMsg & { type: 'loaded-entries' }} msg
|
|
118
|
+
* @param {DashModel} model
|
|
119
|
+
* @param {ContentAddressableStore} cas
|
|
120
|
+
* @returns {[DashModel, DashCmd[]]}
|
|
57
121
|
*/
|
|
58
122
|
function handleLoadedEntries(msg, model, cas) {
|
|
59
123
|
const filtered = applyFilter(msg.entries, model.filterText);
|
|
60
124
|
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));
|
|
125
|
+
const cmds = /** @type {DashCmd[]} */ (msg.entries.map((/** @type {VaultEntry} */ e) => loadManifestCmd(cas, e.slug, e.treeOid)));
|
|
62
126
|
return [{
|
|
63
127
|
...model,
|
|
64
128
|
status: 'ready',
|
|
@@ -71,6 +135,10 @@ function handleLoadedEntries(msg, model, cas) {
|
|
|
71
135
|
|
|
72
136
|
/**
|
|
73
137
|
* Handle a loaded-manifest message.
|
|
138
|
+
*
|
|
139
|
+
* @param {DashMsg & { type: 'loaded-manifest' }} msg
|
|
140
|
+
* @param {DashModel} model
|
|
141
|
+
* @returns {[DashModel, DashCmd[]]}
|
|
74
142
|
*/
|
|
75
143
|
function handleLoadedManifest(msg, model) {
|
|
76
144
|
const cache = new Map(model.manifestCache);
|
|
@@ -80,6 +148,10 @@ function handleLoadedManifest(msg, model) {
|
|
|
80
148
|
|
|
81
149
|
/**
|
|
82
150
|
* Handle cursor movement.
|
|
151
|
+
*
|
|
152
|
+
* @param {{ type: 'move', delta: number }} msg
|
|
153
|
+
* @param {DashModel} model
|
|
154
|
+
* @returns {[DashModel, DashCmd[]]}
|
|
83
155
|
*/
|
|
84
156
|
function handleMove(msg, model) {
|
|
85
157
|
const max = model.filtered.length - 1;
|
|
@@ -89,6 +161,10 @@ function handleMove(msg, model) {
|
|
|
89
161
|
|
|
90
162
|
/**
|
|
91
163
|
* Handle filter key input in filter mode.
|
|
164
|
+
*
|
|
165
|
+
* @param {KeyMsg} msg
|
|
166
|
+
* @param {DashModel} model
|
|
167
|
+
* @returns {[DashModel, DashCmd[]]}
|
|
92
168
|
*/
|
|
93
169
|
function handleFilterKey(msg, model) {
|
|
94
170
|
if (msg.key === 'escape' || msg.key === 'enter') {
|
|
@@ -109,18 +185,27 @@ function handleFilterKey(msg, model) {
|
|
|
109
185
|
|
|
110
186
|
/**
|
|
111
187
|
* Handle select (enter key) to load manifest.
|
|
188
|
+
*
|
|
189
|
+
* @param {DashModel} model
|
|
190
|
+
* @param {DashDeps} deps
|
|
191
|
+
* @returns {[DashModel, DashCmd[]]}
|
|
112
192
|
*/
|
|
113
193
|
function handleSelect(model, deps) {
|
|
114
194
|
const entry = model.filtered[model.cursor];
|
|
115
195
|
if (!entry || model.manifestCache.has(entry.slug)) {
|
|
116
196
|
return [model, []];
|
|
117
197
|
}
|
|
118
|
-
const cmd = loadManifestCmd(deps.cas, entry.slug, entry.treeOid);
|
|
198
|
+
const cmd = /** @type {DashCmd} */ (loadManifestCmd(deps.cas, entry.slug, entry.treeOid));
|
|
119
199
|
return [{ ...model, loadingSlug: entry.slug }, [cmd]];
|
|
120
200
|
}
|
|
121
201
|
|
|
122
202
|
/**
|
|
123
203
|
* Handle keymap actions.
|
|
204
|
+
*
|
|
205
|
+
* @param {DashAction} action
|
|
206
|
+
* @param {DashModel} model
|
|
207
|
+
* @param {DashDeps} deps
|
|
208
|
+
* @returns {[DashModel, DashCmd[]]}
|
|
124
209
|
*/
|
|
125
210
|
function handleAction(action, model, deps) {
|
|
126
211
|
if (action.type === 'quit') { return [model, [quit()]]; }
|
|
@@ -138,6 +223,11 @@ function handleAction(action, model, deps) {
|
|
|
138
223
|
|
|
139
224
|
/**
|
|
140
225
|
* Handle app-level messages (data loading results).
|
|
226
|
+
*
|
|
227
|
+
* @param {DashMsg} msg
|
|
228
|
+
* @param {DashModel} model
|
|
229
|
+
* @param {ContentAddressableStore} cas
|
|
230
|
+
* @returns {[DashModel, DashCmd[]]}
|
|
141
231
|
*/
|
|
142
232
|
function handleAppMsg(msg, model, cas) {
|
|
143
233
|
if (msg.type === 'loaded-entries') { return handleLoadedEntries(msg, model, cas); }
|
|
@@ -153,6 +243,11 @@ function handleAppMsg(msg, model, cas) {
|
|
|
153
243
|
|
|
154
244
|
/**
|
|
155
245
|
* Route all update messages to the appropriate handler.
|
|
246
|
+
*
|
|
247
|
+
* @param {KeyMsg | ResizeMsg | DashMsg} msg
|
|
248
|
+
* @param {DashModel} model
|
|
249
|
+
* @param {DashDeps} deps
|
|
250
|
+
* @returns {[DashModel, DashCmd[]]}
|
|
156
251
|
*/
|
|
157
252
|
function handleUpdate(msg, model, deps) {
|
|
158
253
|
if (msg.type === 'key' && model.filtering) {
|
|
@@ -166,22 +261,27 @@ function handleUpdate(msg, model, deps) {
|
|
|
166
261
|
if (msg.type === 'resize') {
|
|
167
262
|
return [{ ...model, columns: msg.columns, rows: msg.rows }, []];
|
|
168
263
|
}
|
|
169
|
-
return handleAppMsg(msg, model, deps.cas);
|
|
264
|
+
return handleAppMsg(/** @type {DashMsg} */ (msg), model, deps.cas);
|
|
170
265
|
}
|
|
171
266
|
|
|
172
267
|
/**
|
|
173
268
|
* Create the TEA app object for the dashboard.
|
|
269
|
+
*
|
|
270
|
+
* @param {DashDeps} deps
|
|
271
|
+
* @returns {import('@flyingrobots/bijou-tui').App<DashModel, DashMsg>}
|
|
174
272
|
*/
|
|
175
273
|
export function createDashboardApp(deps) {
|
|
176
274
|
return {
|
|
177
|
-
init: () => [createInitModel(), [loadEntriesCmd(deps.cas)]],
|
|
178
|
-
update: (msg, model) => handleUpdate(msg, model, deps),
|
|
179
|
-
view: (model) => renderDashboard(model, deps),
|
|
275
|
+
init: () => /** @type {[DashModel, DashCmd[]]} */ ([createInitModel(), [/** @type {DashCmd} */ (loadEntriesCmd(deps.cas))]]),
|
|
276
|
+
update: (/** @type {KeyMsg | ResizeMsg | DashMsg} */ msg, /** @type {DashModel} */ model) => handleUpdate(msg, model, deps),
|
|
277
|
+
view: (/** @type {DashModel} */ model) => renderDashboard(model, deps),
|
|
180
278
|
};
|
|
181
279
|
}
|
|
182
280
|
|
|
183
281
|
/**
|
|
184
282
|
* Print static list for non-TTY environments.
|
|
283
|
+
*
|
|
284
|
+
* @param {ContentAddressableStore} cas
|
|
185
285
|
*/
|
|
186
286
|
async function printStaticList(cas) {
|
|
187
287
|
const entries = await cas.listVault();
|
|
@@ -192,6 +292,8 @@ async function printStaticList(cas) {
|
|
|
192
292
|
|
|
193
293
|
/**
|
|
194
294
|
* Launch the interactive vault dashboard.
|
|
295
|
+
*
|
|
296
|
+
* @param {ContentAddressableStore} cas
|
|
195
297
|
*/
|
|
196
298
|
export async function launchDashboard(cas) {
|
|
197
299
|
if (!process.stdout.isTTY) {
|
|
@@ -9,7 +9,7 @@ import { getCliContext } from './context.js';
|
|
|
9
9
|
* Render an encryption info card for the vault.
|
|
10
10
|
*
|
|
11
11
|
* @param {Object} options
|
|
12
|
-
* @param {
|
|
12
|
+
* @param {import('../../index.js').VaultMetadata | null} options.metadata - Vault metadata (from getVaultMetadata()).
|
|
13
13
|
* @param {boolean} [options.unlocked] - Whether a key/passphrase was provided.
|
|
14
14
|
* @returns {string}
|
|
15
15
|
*/
|
|
@@ -33,7 +33,7 @@ export function renderEncryptionCard({ metadata, unlocked = false }) {
|
|
|
33
33
|
];
|
|
34
34
|
|
|
35
35
|
if (kdf.algorithm === 'pbkdf2') {
|
|
36
|
-
rows.push(` iterations ${kdf.iterations.toLocaleString()}`);
|
|
36
|
+
rows.push(` iterations ${/** @type {number} */ (kdf.iterations).toLocaleString()}`);
|
|
37
37
|
} else if (kdf.algorithm === 'scrypt') {
|
|
38
38
|
rows.push(` cost ${kdf.cost}`);
|
|
39
39
|
rows.push(` blockSize ${kdf.blockSize}`);
|
package/bin/ui/heatmap.js
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
import { gradientText } from '@flyingrobots/bijou';
|
|
6
6
|
import { getCliContext } from './context.js';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {import('../../src/domain/value-objects/Manifest.js').ManifestData} ManifestData
|
|
10
|
+
* @typedef {import('../../src/domain/value-objects/Manifest.js').SubManifestRef} SubManifestRef
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** @type {import('@flyingrobots/bijou').GradientStop[]} */
|
|
8
14
|
const GRADIENT_STOPS = [
|
|
9
15
|
{ pos: 0, color: [0, 255, 255] },
|
|
10
16
|
{ pos: 1, color: [255, 0, 255] },
|
|
@@ -12,6 +18,9 @@ const GRADIENT_STOPS = [
|
|
|
12
18
|
|
|
13
19
|
/**
|
|
14
20
|
* Format bytes as human-readable string.
|
|
21
|
+
*
|
|
22
|
+
* @param {number} bytes
|
|
23
|
+
* @returns {string}
|
|
15
24
|
*/
|
|
16
25
|
function formatBytes(bytes) {
|
|
17
26
|
if (bytes < 1024) {
|
|
@@ -28,6 +37,11 @@ function formatBytes(bytes) {
|
|
|
28
37
|
|
|
29
38
|
/**
|
|
30
39
|
* Build the block grid string from chunks.
|
|
40
|
+
*
|
|
41
|
+
* @param {ManifestData['chunks']} chunks
|
|
42
|
+
* @param {Set<number>} boundaries
|
|
43
|
+
* @param {number} width
|
|
44
|
+
* @returns {string}
|
|
31
45
|
*/
|
|
32
46
|
function buildGrid(chunks, boundaries, width) {
|
|
33
47
|
let grid = '';
|
|
@@ -56,6 +70,10 @@ function buildGrid(chunks, boundaries, width) {
|
|
|
56
70
|
|
|
57
71
|
/**
|
|
58
72
|
* Build the legend line.
|
|
73
|
+
*
|
|
74
|
+
* @param {ManifestData['chunks']} chunks
|
|
75
|
+
* @param {SubManifestRef[]} subManifests
|
|
76
|
+
* @returns {string}
|
|
59
77
|
*/
|
|
60
78
|
function buildLegend(chunks, subManifests) {
|
|
61
79
|
const chunkSize = chunks.length > 0 ? chunks[0].size : 0;
|
|
@@ -73,12 +91,12 @@ function buildLegend(chunks, subManifests) {
|
|
|
73
91
|
* Render a chunk heatmap for a manifest.
|
|
74
92
|
*
|
|
75
93
|
* @param {Object} options
|
|
76
|
-
* @param {
|
|
94
|
+
* @param {ManifestData | { toJSON(): ManifestData }} options.manifest - The manifest (Manifest instance or plain ManifestData).
|
|
77
95
|
* @returns {string}
|
|
78
96
|
*/
|
|
79
97
|
export function renderHeatmap({ manifest }) {
|
|
80
98
|
const ctx = getCliContext();
|
|
81
|
-
const m =
|
|
99
|
+
const m = /** @type {ManifestData} */ ('toJSON' in manifest ? manifest.toJSON() : manifest);
|
|
82
100
|
const chunks = m.chunks || [];
|
|
83
101
|
|
|
84
102
|
if (chunks.length === 0) {
|
|
@@ -34,6 +34,7 @@ function parseCommitLine(line) {
|
|
|
34
34
|
return { oid, operation: match[1], slug: match[2] || null };
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/** @type {Record<string, string>} */
|
|
37
38
|
const STATUS_MAP = {
|
|
38
39
|
init: 'info',
|
|
39
40
|
add: 'success',
|
|
@@ -65,14 +66,15 @@ export function renderHistoryTimeline(gitLogOutput, options = {}) {
|
|
|
65
66
|
const start = (page - 1) * perPage;
|
|
66
67
|
const pageLines = lines.slice(start, start + perPage);
|
|
67
68
|
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
const parsed = pageLines.map(parseCommitLine).filter(Boolean);
|
|
70
|
+
const events = parsed.map((entry) => {
|
|
71
|
+
const { oid, operation, slug } = /** @type {{ oid: string, operation: string, slug: string | null }} */ (entry);
|
|
72
|
+
return {
|
|
72
73
|
label: slug ? `vault: ${operation} ${slug}` : `vault: ${operation}`,
|
|
73
74
|
description: oid,
|
|
74
|
-
status: STATUS_MAP[operation] || 'pending',
|
|
75
|
-
}
|
|
75
|
+
status: /** @type {import('@flyingrobots/bijou').BaseStatusKey} */ (STATUS_MAP[operation] || 'pending'),
|
|
76
|
+
};
|
|
77
|
+
});
|
|
76
78
|
|
|
77
79
|
let output = timeline(events, { ctx });
|
|
78
80
|
|
package/bin/ui/manifest-view.js
CHANGED
|
@@ -5,8 +5,16 @@
|
|
|
5
5
|
import { box, badge, table, tree, headerBox } from '@flyingrobots/bijou';
|
|
6
6
|
import { getCliContext } from './context.js';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {import('../../src/domain/value-objects/Manifest.js').ManifestData} ManifestData
|
|
10
|
+
* @typedef {import('@flyingrobots/bijou').BijouContext} BijouContext
|
|
11
|
+
*/
|
|
12
|
+
|
|
8
13
|
/**
|
|
9
14
|
* Format bytes as human-readable string.
|
|
15
|
+
*
|
|
16
|
+
* @param {number} bytes
|
|
17
|
+
* @returns {string}
|
|
10
18
|
*/
|
|
11
19
|
function formatBytes(bytes) {
|
|
12
20
|
if (bytes < 1024) {
|
|
@@ -23,6 +31,10 @@ function formatBytes(bytes) {
|
|
|
23
31
|
|
|
24
32
|
/**
|
|
25
33
|
* Build the header badges line.
|
|
34
|
+
*
|
|
35
|
+
* @param {ManifestData} m
|
|
36
|
+
* @param {BijouContext} ctx
|
|
37
|
+
* @returns {string}
|
|
26
38
|
*/
|
|
27
39
|
function renderBadges(m, ctx) {
|
|
28
40
|
const badges = [badge(`v${m.version}`, { ctx })];
|
|
@@ -40,6 +52,10 @@ function renderBadges(m, ctx) {
|
|
|
40
52
|
|
|
41
53
|
/**
|
|
42
54
|
* Build the encryption section.
|
|
55
|
+
*
|
|
56
|
+
* @param {NonNullable<ManifestData['encryption']>} enc
|
|
57
|
+
* @param {BijouContext} ctx
|
|
58
|
+
* @returns {string}
|
|
43
59
|
*/
|
|
44
60
|
function renderEncryptionSection(enc, ctx) {
|
|
45
61
|
const rows = [` algorithm ${enc.algorithm}`];
|
|
@@ -63,14 +79,18 @@ function renderEncryptionSection(enc, ctx) {
|
|
|
63
79
|
|
|
64
80
|
/**
|
|
65
81
|
* Build the chunks section.
|
|
82
|
+
*
|
|
83
|
+
* @param {ManifestData['chunks']} chunks
|
|
84
|
+
* @param {BijouContext} ctx
|
|
85
|
+
* @returns {string}
|
|
66
86
|
*/
|
|
67
87
|
function renderChunksSection(chunks, ctx) {
|
|
68
88
|
const displayChunks = chunks.slice(0, 20);
|
|
69
|
-
const chunkRows = displayChunks.map(c => [
|
|
89
|
+
const chunkRows = displayChunks.map((/** @type {{ index: number, size: number, digest: string, blob?: string }} */ c) => [
|
|
70
90
|
String(c.index),
|
|
71
91
|
formatBytes(c.size),
|
|
72
|
-
`${c.digest.slice(0, 12)}
|
|
73
|
-
`${c.blob.slice(0, 12)}
|
|
92
|
+
typeof c.digest === 'string' ? `${c.digest.slice(0, 12)}...` : '-',
|
|
93
|
+
typeof c.blob === 'string' ? `${c.blob.slice(0, 12)}...` : '-',
|
|
74
94
|
]);
|
|
75
95
|
const chunkTable = table({
|
|
76
96
|
columns: [{ header: '#' }, { header: 'Size' }, { header: 'Digest' }, { header: 'Blob' }],
|
|
@@ -85,6 +105,10 @@ function renderChunksSection(chunks, ctx) {
|
|
|
85
105
|
|
|
86
106
|
/**
|
|
87
107
|
* Build the metadata section.
|
|
108
|
+
*
|
|
109
|
+
* @param {ManifestData} m
|
|
110
|
+
* @param {BijouContext} ctx
|
|
111
|
+
* @returns {string}
|
|
88
112
|
*/
|
|
89
113
|
function renderMetadataSection(m, ctx) {
|
|
90
114
|
const meta = [
|
|
@@ -98,24 +122,29 @@ function renderMetadataSection(m, ctx) {
|
|
|
98
122
|
|
|
99
123
|
/**
|
|
100
124
|
* Build the sub-manifests section.
|
|
125
|
+
*
|
|
126
|
+
* @param {ManifestData} m
|
|
127
|
+
* @param {BijouContext} ctx
|
|
128
|
+
* @returns {string}
|
|
101
129
|
*/
|
|
102
130
|
function renderSubManifestsSection(m, ctx) {
|
|
103
|
-
const
|
|
131
|
+
const subs = m.subManifests || [];
|
|
132
|
+
const nodes = subs.map((/** @type {import('../../src/domain/value-objects/Manifest.js').SubManifestRef} */ sm, /** @type {number} */ i) => ({
|
|
104
133
|
label: `sub-${i} ${sm.chunkCount} chunks start: ${sm.startIndex} oid: ${sm.oid.slice(0, 8)}...`,
|
|
105
134
|
}));
|
|
106
|
-
return `${headerBox(`Sub-manifests (${
|
|
135
|
+
return `${headerBox(`Sub-manifests (${subs.length})`, { ctx })}\n${tree(nodes, { ctx })}`;
|
|
107
136
|
}
|
|
108
137
|
|
|
109
138
|
/**
|
|
110
139
|
* Render a full manifest anatomy view.
|
|
111
140
|
*
|
|
112
141
|
* @param {Object} options
|
|
113
|
-
* @param {
|
|
114
|
-
* @param {
|
|
142
|
+
* @param {ManifestData | { toJSON(): ManifestData }} options.manifest - The manifest (Manifest instance or plain ManifestData).
|
|
143
|
+
* @param {BijouContext} [options.ctx] - Optional bijou context override.
|
|
115
144
|
* @returns {string}
|
|
116
145
|
*/
|
|
117
146
|
export function renderManifestView({ manifest, ctx = getCliContext() }) {
|
|
118
|
-
const m =
|
|
147
|
+
const m = /** @type {ManifestData} */ ('toJSON' in manifest ? manifest.toJSON() : manifest);
|
|
119
148
|
const sections = [renderBadges(m, ctx), renderMetadataSection(m, ctx)];
|
|
120
149
|
|
|
121
150
|
if (m.encryption) {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline';
|
|
2
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Prompts for a passphrase on stderr with echo disabled.
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} [options]
|
|
8
|
+
* @param {boolean} [options.confirm=false] - Require confirmation (ask twice).
|
|
9
|
+
* @returns {Promise<string>}
|
|
10
|
+
*/
|
|
11
|
+
export async function promptPassphrase({ confirm = false } = {}) {
|
|
12
|
+
if (!process.stdin.isTTY) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
'Cannot prompt for passphrase: stdin is not a TTY. ' +
|
|
15
|
+
'Use --vault-passphrase-file or GIT_CAS_PASSPHRASE.',
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
const pass = await readHidden('Passphrase: ');
|
|
19
|
+
if (!pass) {
|
|
20
|
+
throw new Error('Passphrase must not be empty');
|
|
21
|
+
}
|
|
22
|
+
if (confirm) {
|
|
23
|
+
const pass2 = await readHidden('Confirm passphrase: ');
|
|
24
|
+
if (pass !== pass2) {
|
|
25
|
+
throw new Error('Passphrases do not match');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return pass;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Warns to stderr if the file at `filePath` is group- or world-readable.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} filePath
|
|
35
|
+
*/
|
|
36
|
+
async function warnInsecurePermissions(filePath) {
|
|
37
|
+
try {
|
|
38
|
+
const st = await stat(filePath);
|
|
39
|
+
if (st.mode & 0o077) {
|
|
40
|
+
process.stderr.write(
|
|
41
|
+
`warning: ${filePath} has insecure permissions — consider chmod 600\n`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
} catch {
|
|
45
|
+
// stat may fail on non-Unix or non-existent paths; silently skip.
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Reads a passphrase from a file path, or from stdin when path is '-'.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} filePath - File path, or '-' for stdin.
|
|
53
|
+
* @returns {Promise<string>}
|
|
54
|
+
*/
|
|
55
|
+
export async function readPassphraseFile(filePath) {
|
|
56
|
+
if (filePath === '-') {
|
|
57
|
+
const chunks = [];
|
|
58
|
+
for await (const chunk of process.stdin) {
|
|
59
|
+
chunks.push(chunk);
|
|
60
|
+
}
|
|
61
|
+
const stdinResult = Buffer.concat(chunks).toString('utf8').replace(/\r?\n$/, '');
|
|
62
|
+
if (!stdinResult) { throw new Error('Passphrase must not be empty'); }
|
|
63
|
+
return stdinResult;
|
|
64
|
+
}
|
|
65
|
+
await warnInsecurePermissions(filePath);
|
|
66
|
+
const content = await readFile(filePath, 'utf8');
|
|
67
|
+
const trimmed = content.replace(/\r?\n$/, '');
|
|
68
|
+
if (!trimmed) { throw new Error('Passphrase must not be empty'); }
|
|
69
|
+
return trimmed;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Reads a line with echo disabled.
|
|
74
|
+
*
|
|
75
|
+
* Uses Node.js private API `rl._writeToOutput` to suppress echo —
|
|
76
|
+
* this is an intentional access to an undocumented API for password
|
|
77
|
+
* input, as there is no public readline API for hidden input.
|
|
78
|
+
*
|
|
79
|
+
* @param {string} prompt - Prompt text.
|
|
80
|
+
* @returns {Promise<string>}
|
|
81
|
+
*/
|
|
82
|
+
function readHidden(prompt) {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
const rl = createInterface({
|
|
85
|
+
input: process.stdin,
|
|
86
|
+
output: process.stderr,
|
|
87
|
+
terminal: true,
|
|
88
|
+
});
|
|
89
|
+
process.stderr.write(prompt);
|
|
90
|
+
rl.on('error', reject);
|
|
91
|
+
rl.on('close', () => reject(new Error('readline closed without input')));
|
|
92
|
+
rl.question('', (answer) => {
|
|
93
|
+
rl.removeAllListeners('close');
|
|
94
|
+
rl.close();
|
|
95
|
+
process.stderr.write('\n');
|
|
96
|
+
resolve(answer);
|
|
97
|
+
});
|
|
98
|
+
rl._writeToOutput = () => {};
|
|
99
|
+
});
|
|
100
|
+
}
|