check-post 0.2.0 → 0.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/dist/ui/tui/App.js +103 -41
- package/package.json +1 -1
package/dist/ui/tui/App.js
CHANGED
|
@@ -17,7 +17,6 @@ export function App({ pipeline, header, execute, initialNodes }) {
|
|
|
17
17
|
const [selected, setSelected] = useState(0);
|
|
18
18
|
const [follow, setFollow] = useState(true);
|
|
19
19
|
const [view, setView] = useState('list');
|
|
20
|
-
const [detailOffset, setDetailOffset] = useState(0);
|
|
21
20
|
const [running, setRunning] = useState(false);
|
|
22
21
|
const [gate, setGate] = useState(null);
|
|
23
22
|
const [notice, setNotice] = useState(null);
|
|
@@ -104,17 +103,8 @@ export function App({ pipeline, header, execute, initialNodes }) {
|
|
|
104
103
|
exit();
|
|
105
104
|
return;
|
|
106
105
|
}
|
|
107
|
-
if (view === 'detail')
|
|
108
|
-
|
|
109
|
-
setView('list');
|
|
110
|
-
setDetailOffset(0);
|
|
111
|
-
}
|
|
112
|
-
else if (key.upArrow)
|
|
113
|
-
setDetailOffset((o) => Math.max(0, o - 1));
|
|
114
|
-
else if (key.downArrow)
|
|
115
|
-
setDetailOffset((o) => o + 1);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
106
|
+
if (view === 'detail')
|
|
107
|
+
return; // the Detail component handles its own keys
|
|
118
108
|
if (key.upArrow) {
|
|
119
109
|
setFollow(false);
|
|
120
110
|
setSelected((i) => Math.max(0, i - 1));
|
|
@@ -138,15 +128,13 @@ export function App({ pipeline, header, execute, initialNodes }) {
|
|
|
138
128
|
}
|
|
139
129
|
else if (input === 'o' && current) {
|
|
140
130
|
const target = current.kind === 'stage' ? current.file : current.dir;
|
|
141
|
-
const editor
|
|
142
|
-
const child = spawn(editor, [target], { detached: true, stdio: 'ignore' });
|
|
131
|
+
const { editor, child } = openInEditor(target);
|
|
143
132
|
child.on('error', () => setNotice(`Could not open editor "${editor}". Set CHECKPOST_EDITOR.`));
|
|
144
|
-
child.unref();
|
|
145
133
|
setNotice(`Opening ${path.relative(pipeline.root, target)} in ${editor}`);
|
|
146
134
|
}
|
|
147
135
|
});
|
|
148
136
|
if (view === 'detail' && current) {
|
|
149
|
-
return _jsx(Detail, { node: current, state: states[current.id], log: logs[current.id] ?? [],
|
|
137
|
+
return (_jsx(Detail, { node: current, state: states[current.id], log: logs[current.id] ?? [], pipeline: pipeline, onBack: () => setView('list') }, current.id));
|
|
150
138
|
}
|
|
151
139
|
const logLines = current ? (logs[current.id] ?? []) : [];
|
|
152
140
|
const logHeight = Math.max(4, Math.min(12, rows - rowsList.length - 10));
|
|
@@ -174,34 +162,108 @@ function GateBox({ gate }) {
|
|
|
174
162
|
}
|
|
175
163
|
return (_jsxs(Box, { borderStyle: "round", borderColor: "red", paddingX: 1, flexDirection: "column", children: [_jsx(Text, { color: "red", bold: true, children: "\u2716 GATE RED \u00B7 not ready to deploy" }), gate.reasons.slice(0, 6).map((r, i) => (_jsxs(Text, { color: "gray", children: ["\u2022 ", r] }, i)))] }));
|
|
176
164
|
}
|
|
177
|
-
|
|
165
|
+
const SEVERITY_ORDER = ['critical', 'high', 'medium', 'low', 'info'];
|
|
166
|
+
const GUI_EDITORS = new Set(['code', 'code-insiders', 'cursor', 'windsurf', 'codium']);
|
|
167
|
+
/** Open a file (optionally at a line) in the configured editor, detached from the TUI. */
|
|
168
|
+
export function openInEditor(file, line) {
|
|
169
|
+
const editor = process.env.CHECKPOST_EDITOR || 'code';
|
|
170
|
+
const args = line && GUI_EDITORS.has(path.basename(editor)) ? ['-g', `${file}:${line}`] : [file];
|
|
171
|
+
const child = spawn(editor, args, { detached: true, stdio: 'ignore' });
|
|
172
|
+
child.unref();
|
|
173
|
+
return { editor, child };
|
|
174
|
+
}
|
|
175
|
+
/** Rough number of terminal rows a finding takes, used to keep the selection on screen. */
|
|
176
|
+
function findingHeight(f, width) {
|
|
177
|
+
const rowsFor = (text) => Math.max(1, Math.ceil(text.length / Math.max(20, width)));
|
|
178
|
+
return 1 + rowsFor(f.message) + (f.suggestion ? rowsFor('→ ' + f.suggestion) : 0) + 1;
|
|
179
|
+
}
|
|
180
|
+
function Detail({ node, state, log, pipeline, onBack, }) {
|
|
181
|
+
const { rows, columns } = useWindowSize();
|
|
178
182
|
const result = state?.result;
|
|
179
|
-
const
|
|
183
|
+
const findings = result?.findings ?? [];
|
|
184
|
+
const [selected, setSelected] = useState(0);
|
|
185
|
+
const [logOffset, setLogOffset] = useState(0);
|
|
186
|
+
const [notice, setNotice] = useState(null);
|
|
187
|
+
const top = useRef(0);
|
|
188
|
+
const failOn = node.kind === 'stage' ? node.config.fail_on : 'high';
|
|
189
|
+
const numWidth = String(findings.length).length;
|
|
190
|
+
const bodyIndent = 2 + 2 * numWidth + 1 + 2; // "❯ " + "n/N" + gap
|
|
191
|
+
const bodyWidth = columns - bodyIndent - 2;
|
|
192
|
+
useInput((input, key) => {
|
|
193
|
+
if (key.escape || key.leftArrow || key.backspace)
|
|
194
|
+
return onBack();
|
|
195
|
+
if (findings.length) {
|
|
196
|
+
if (key.upArrow)
|
|
197
|
+
setSelected((i) => Math.max(0, i - 1));
|
|
198
|
+
else if (key.downArrow)
|
|
199
|
+
setSelected((i) => Math.min(findings.length - 1, i + 1));
|
|
200
|
+
else if (key.pageUp)
|
|
201
|
+
setSelected((i) => Math.max(0, i - 5));
|
|
202
|
+
else if (key.pageDown)
|
|
203
|
+
setSelected((i) => Math.min(findings.length - 1, i + 5));
|
|
204
|
+
else if (input === 'g')
|
|
205
|
+
setSelected(0);
|
|
206
|
+
else if (input === 'G')
|
|
207
|
+
setSelected(findings.length - 1);
|
|
208
|
+
else if (input === 'o' || key.return) {
|
|
209
|
+
const f = findings[selected];
|
|
210
|
+
if (!f?.file)
|
|
211
|
+
return setNotice('This finding has no file location.');
|
|
212
|
+
const { editor, child } = openInEditor(path.resolve(pipeline.root, f.file), f.line);
|
|
213
|
+
child.on('error', () => setNotice(`Could not open editor "${editor}". Set CHECKPOST_EDITOR.`));
|
|
214
|
+
setNotice(`Opening ${findingLocation(f)} in ${editor}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else if (key.upArrow)
|
|
218
|
+
setLogOffset((o) => Math.max(0, o - 1));
|
|
219
|
+
else if (key.downArrow)
|
|
220
|
+
setLogOffset((o) => Math.min(Math.max(0, log.length - 1), o + 1));
|
|
221
|
+
});
|
|
222
|
+
const status = state?.status ?? 'pending';
|
|
223
|
+
const header = node.kind === 'stage'
|
|
224
|
+
? `${node.name} · ${typeLabel(node)}${node.type !== 'command' ? ` · fail_on: ${node.config.fail_on}` : ''}`
|
|
225
|
+
: node.name;
|
|
226
|
+
const counts = SEVERITY_ORDER.map((sev) => [sev, findings.filter((f) => f.severity === sev).length]).filter(([, n]) => n > 0);
|
|
227
|
+
const blockingCount = findings.filter((f) => isBlocking(f, failOn)).length;
|
|
228
|
+
// Fixed chrome: header, rule, summary (estimated), counts, rule, ..., rule, footer, notice.
|
|
229
|
+
const summaryRows = result?.summary ? Math.ceil(result.summary.length / Math.max(20, columns - 2)) : 0;
|
|
230
|
+
const available = Math.max(4, rows - 7 - summaryRows - (result?.error ? 1 : 0));
|
|
231
|
+
let body;
|
|
232
|
+
let position = '';
|
|
180
233
|
if (node.kind === 'group') {
|
|
181
|
-
|
|
234
|
+
body = _jsxs(Text, { children: ["Group with ", node.children.length, " items. Select a stage inside it to see details."] });
|
|
235
|
+
}
|
|
236
|
+
else if (findings.length) {
|
|
237
|
+
// Keep the selected finding visible: scroll the window only when the selection leaves it.
|
|
238
|
+
const heights = findings.map((f) => findingHeight(f, bodyWidth));
|
|
239
|
+
const fits = (from, to) => heights.slice(from, to + 1).reduce((a, b) => a + b, 0) <= available;
|
|
240
|
+
if (selected < top.current)
|
|
241
|
+
top.current = selected;
|
|
242
|
+
while (top.current < selected && !fits(top.current, selected))
|
|
243
|
+
top.current++;
|
|
244
|
+
let end = top.current;
|
|
245
|
+
while (end + 1 < findings.length && fits(top.current, end + 1))
|
|
246
|
+
end++;
|
|
247
|
+
const hiddenAbove = top.current;
|
|
248
|
+
const hiddenBelow = findings.length - 1 - end;
|
|
249
|
+
position = `${selected + 1}/${findings.length}`;
|
|
250
|
+
body = (_jsxs(Box, { flexDirection: "column", children: [hiddenAbove > 0 && _jsxs(Text, { color: "gray", children: [" \u2191 ", hiddenAbove, " more above"] }), findings.slice(top.current, end + 1).map((f, i) => {
|
|
251
|
+
const index = top.current + i;
|
|
252
|
+
const isSel = index === selected;
|
|
253
|
+
const blocking = isBlocking(f, failOn);
|
|
254
|
+
const num = `${String(index + 1).padStart(numWidth)}/${findings.length}`;
|
|
255
|
+
return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: "cyan", bold: true, children: isSel ? '❯ ' : ' ' }), _jsx(Text, { inverse: isSel, bold: isSel, color: isSel ? undefined : 'gray', children: num }), ' ', _jsx(Text, { backgroundColor: SEVERITY_COLOR[f.severity], color: "black", bold: true, children: ` ${f.severity.toUpperCase()} `.padEnd(10) }), blocking ? _jsx(Text, { color: "red", bold: true, children: " \u25CF blocking" }) : _jsx(Text, { color: "gray", children: ' ' }), ' ', _jsx(Text, { underline: isSel, bold: isSel, children: findingLocation(f) || '(no location)' })] }), _jsx(Box, { paddingLeft: bodyIndent, children: _jsx(Text, { color: isSel ? undefined : 'gray', children: f.message }) }), f.suggestion && (_jsx(Box, { paddingLeft: bodyIndent, children: _jsxs(Text, { color: isSel ? 'green' : 'gray', children: ["\u2192 ", f.suggestion] }) }))] }, index));
|
|
256
|
+
}), hiddenBelow > 0 && _jsxs(Text, { color: "gray", children: [" \u2193 ", hiddenBelow, " more below"] })] }));
|
|
182
257
|
}
|
|
183
258
|
else {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (
|
|
187
|
-
lines
|
|
188
|
-
|
|
189
|
-
result.findings.forEach((f, i) => {
|
|
190
|
-
const blocking = isBlocking(f, node.config.fail_on);
|
|
191
|
-
lines.push(_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: SEVERITY_COLOR[f.severity], bold: true, children: f.severity.toUpperCase().padEnd(9) }), _jsx(Text, { underline: true, children: findingLocation(f) }), blocking && _jsx(Text, { color: "red", children: " (blocking)" })] }), _jsxs(Text, { children: [' ', f.message] }), f.suggestion && _jsxs(Text, { color: "gray", children: [' ', "\u2192 ", f.suggestion] })] }, `f${i}`));
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
else if (node.type === 'command' || !result) {
|
|
195
|
-
lines.push(_jsx(Text, { color: "gray", children: "Log:" }, "lt"));
|
|
196
|
-
log.forEach((line, i) => lines.push(_jsxs(Text, { children: [" ", line] }, `l${i}`)));
|
|
197
|
-
}
|
|
198
|
-
if (result?.logFile)
|
|
199
|
-
lines.push(_jsxs(Text, { color: "gray", children: ["Full log: ", path.relative(pipeline.root, result.logFile)] }, "lf"));
|
|
259
|
+
const visible = Math.max(4, available);
|
|
260
|
+
const start = Math.min(logOffset, Math.max(0, log.length - visible));
|
|
261
|
+
if (log.length)
|
|
262
|
+
position = `lines ${start + 1}-${Math.min(log.length, start + visible)}/${log.length}`;
|
|
263
|
+
body = (_jsxs(Box, { flexDirection: "column", children: [result?.status === 'passed' && node.type !== 'command' && _jsx(Text, { color: "green", children: "No findings." }), log.slice(start, start + visible).map((line, i) => (_jsxs(Text, { wrap: "truncate-end", children: [' ', line] }, i))), result?.logFile && _jsxs(Text, { color: "gray", children: ["Full log: ", path.relative(pipeline.root, result.logFile)] })] }));
|
|
200
264
|
}
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
: node.name;
|
|
206
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, children: [' ', _jsx(Text, { color: STATUS_COLOR[state?.status ?? 'pending'], children: STATUS_ICON[state?.status ?? 'pending'] }), " ", header, result?.costUsd ? _jsxs(Text, { color: "gray", children: [" \u00B7 $", result.costUsd.toFixed(3)] }) : null] }), _jsx(Text, { color: "gray", children: '─'.repeat(60) }), lines.slice(start, start + visible), _jsx(Text, { color: "gray", children: '─'.repeat(60) }), _jsx(Text, { color: "gray", children: " \u2191\u2193 scroll esc back q quit" })] }));
|
|
265
|
+
const rule = _jsx(Text, { color: "gray", children: '─'.repeat(Math.max(20, Math.min(columns - 1, 100))) });
|
|
266
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, children: [' ', _jsx(Text, { color: STATUS_COLOR[status], children: STATUS_ICON[status] }), " ", header, result?.costUsd ? _jsxs(Text, { color: "gray", children: [" \u00B7 $", result.costUsd.toFixed(3)] }) : null] }), rule, result?.summary && (_jsx(Box, { paddingLeft: 1, children: _jsx(Text, { color: "gray", children: result.summary }) })), result?.error && (_jsx(Box, { paddingLeft: 1, children: _jsxs(Text, { color: "red", children: ["Error: ", result.error] }) })), findings.length > 0 && (_jsxs(Text, { children: [' ', _jsxs(Text, { bold: true, children: [findings.length, " finding", findings.length === 1 ? '' : 's'] }), counts.map(([sev, n]) => (_jsxs(Text, { children: [' ', _jsx(Text, { color: SEVERITY_COLOR[sev], children: "\u25A0" }), " ", n, " ", sev] }, sev))), _jsxs(Text, { color: blockingCount ? 'red' : 'green', children: [' · ', blockingCount ? `${blockingCount} blocking (fail_on: ${failOn})` : `none blocking (fail_on: ${failOn})`] })] })), rule, body, rule, notice && _jsxs(Text, { color: "yellow", children: [" ", notice] }), _jsxs(Text, { color: "gray", children: [findings.length
|
|
267
|
+
? ' ↑↓ select PgUp/PgDn jump g/G first/last enter/o open in editor esc back q quit'
|
|
268
|
+
: ' ↑↓ scroll esc back q quit', position && _jsxs(Text, { color: "cyan", children: [' ', position] })] })] }));
|
|
207
269
|
}
|