@openai/codex-security 0.1.14 → 0.1.15
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/README.md +74 -19
- package/_bundled_plugin/.app.json +5 -0
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/examples/completed-scan/report.md +96 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/references/config-preflight.md +5 -1
- package/_bundled_plugin/references/core-scan.md +6 -15
- package/_bundled_plugin/references/final-report.md +1 -1
- package/_bundled_plugin/references/scan-artifacts.md +1 -1
- package/_bundled_plugin/references/threat-model.md +64 -0
- package/_bundled_plugin/schemas/findings.schema.json +327 -2
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +286 -4
- package/_bundled_plugin/scripts/config_preflight.py +20 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +12 -6
- package/_bundled_plugin/scripts/finalize_scan_contract.py +322 -33
- package/_bundled_plugin/scripts/finding_preview.py +81 -19
- package/_bundled_plugin/scripts/report_projection.py +253 -33
- package/_bundled_plugin/scripts/validate_scan_contract.py +5 -2
- package/_bundled_plugin/scripts/workbench_cli.py +7 -1
- package/_bundled_plugin/scripts/workbench_remediation.py +2 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +4 -0
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +2 -2
- package/_bundled_plugin/skills/security-scan/SKILL.md +1 -1
- package/_bundled_plugin/skills/threat-model/SKILL.md +6 -49
- package/dist/api.d.ts +5 -73
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +259 -209
- package/dist/api.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts +3 -3
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +8 -7
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/cli.d.ts +18 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +782 -120
- package/dist/cli.js.map +1 -1
- package/dist/codex-prompt.d.ts +4 -0
- package/dist/codex-prompt.d.ts.map +1 -0
- package/dist/codex-prompt.js +14 -0
- package/dist/codex-prompt.js.map +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +198 -2
- package/dist/contract.js.map +1 -1
- package/dist/cost.d.ts +7 -0
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +68 -47
- package/dist/cost.js.map +1 -1
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +9 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/linear.d.ts +19 -0
- package/dist/linear.d.ts.map +1 -0
- package/dist/linear.js +106 -0
- package/dist/linear.js.map +1 -0
- package/dist/models.d.ts +89 -2
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +7 -6
- package/dist/multiscan.js.map +1 -1
- package/dist/patch-tui.d.ts +28 -0
- package/dist/patch-tui.d.ts.map +1 -0
- package/dist/patch-tui.js +384 -0
- package/dist/patch-tui.js.map +1 -0
- package/dist/publish.d.ts +2 -2
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +4 -8
- package/dist/publish.js.map +1 -1
- package/dist/runtime.d.ts +10 -7
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +63 -35
- package/dist/runtime.js.map +1 -1
- package/dist/scan-comparison.d.ts +2 -1
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +17 -15
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +2 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +219 -11
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/targets.d.ts +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +4 -2
- package/dist/targets.js.map +1 -1
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +26 -11
- package/dist/trusted-executable.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +7 -3
- package/_bundled_plugin/skills/threat-model/references/threat-model-guidance.md +0 -48
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
3
|
+
import { basename, isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { stripVTControlCharacters } from "node:util";
|
|
5
|
+
import { Box, Text, render, useApp, useInput, useStdout } from "ink";
|
|
6
|
+
import { useMemo, useRef, useState } from "react";
|
|
7
|
+
import { safeErrorMessage } from "./errors.js";
|
|
8
|
+
const SEVERITY_COLORS = {
|
|
9
|
+
critical: "redBright",
|
|
10
|
+
high: "red",
|
|
11
|
+
medium: "yellow",
|
|
12
|
+
low: "blueBright",
|
|
13
|
+
};
|
|
14
|
+
const SEVERITIES = Object.keys(SEVERITY_COLORS);
|
|
15
|
+
const HEADING = /^[A-Z][A-Z ]+$/u;
|
|
16
|
+
const SOURCE_LINE = /^([› ]\s*\d* │ )(.*)$/u;
|
|
17
|
+
const DETAIL_ORDER = [
|
|
18
|
+
"summary",
|
|
19
|
+
"severity",
|
|
20
|
+
"confidence",
|
|
21
|
+
"rootCause",
|
|
22
|
+
"validation",
|
|
23
|
+
"attackPath",
|
|
24
|
+
"impact",
|
|
25
|
+
"likelihood",
|
|
26
|
+
"reachability",
|
|
27
|
+
"prerequisites",
|
|
28
|
+
"counterevidence",
|
|
29
|
+
"limitations",
|
|
30
|
+
"locations",
|
|
31
|
+
"codeEvidence",
|
|
32
|
+
"remediation",
|
|
33
|
+
"remediationTests",
|
|
34
|
+
"preventiveControls",
|
|
35
|
+
"taxonomy",
|
|
36
|
+
"findingId",
|
|
37
|
+
"occurrenceId",
|
|
38
|
+
];
|
|
39
|
+
function safeText(value) {
|
|
40
|
+
return stripVTControlCharacters(safeErrorMessage(String(value)))
|
|
41
|
+
.replaceAll(/\r\n?/gu, "\n")
|
|
42
|
+
.replaceAll(/[\u0000-\u0009\u000B-\u001F\u007F-\u009F\u2028\u2029]/gu, " ");
|
|
43
|
+
}
|
|
44
|
+
function safeLine(value) {
|
|
45
|
+
return safeText(value).replaceAll("\n", " ");
|
|
46
|
+
}
|
|
47
|
+
function fieldLabel(value) {
|
|
48
|
+
return safeLine(value)
|
|
49
|
+
.replaceAll(/([a-z\d])([A-Z])/gu, "$1 $2")
|
|
50
|
+
.replaceAll("_", " ")
|
|
51
|
+
.replaceAll(/\b(cwe|id)\b/giu, (match) => match.toUpperCase())
|
|
52
|
+
.replace(/^./u, (match) => match.toUpperCase());
|
|
53
|
+
}
|
|
54
|
+
function detailLines(value, indent = "", evidence) {
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
return value.flatMap((entry) => {
|
|
57
|
+
const lines = detailLines(entry, `${indent} `, evidence);
|
|
58
|
+
return lines.length === 0
|
|
59
|
+
? []
|
|
60
|
+
: [`${indent}• ${lines[0].trimStart()}`, ...lines.slice(1)];
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (typeof value !== "object" || value === null) {
|
|
64
|
+
return safeText(value)
|
|
65
|
+
.split("\n")
|
|
66
|
+
.map((line) => `${indent}${line}`);
|
|
67
|
+
}
|
|
68
|
+
return Object.entries(value).flatMap(([key, entry]) => {
|
|
69
|
+
if (entry === null ||
|
|
70
|
+
entry === undefined ||
|
|
71
|
+
(Array.isArray(entry) && entry.length === 0)) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
if (key === "level") {
|
|
75
|
+
const level = safeLine(entry);
|
|
76
|
+
return [
|
|
77
|
+
`${indent}${level.replace(/^./u, (match) => match.toUpperCase())}`,
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
if ((key === "summary" || key === "rationale") &&
|
|
81
|
+
typeof entry === "string") {
|
|
82
|
+
return detailLines(entry, indent, evidence);
|
|
83
|
+
}
|
|
84
|
+
if (key === "evidenceRefs" && Array.isArray(entry)) {
|
|
85
|
+
return [
|
|
86
|
+
`${indent}Evidence:`,
|
|
87
|
+
...entry.map((reference) => {
|
|
88
|
+
const item = evidence?.get(String(reference));
|
|
89
|
+
return item === undefined
|
|
90
|
+
? `${indent} • ${safeLine(reference)}`
|
|
91
|
+
: `${indent} • ${safeLine(item.label)} · ${safeLine(item.path)}:${item.startLine}`;
|
|
92
|
+
}),
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
if (key === "cwe" && Array.isArray(entry)) {
|
|
96
|
+
return [`${indent}CWE: ${entry.map(safeLine).join(", ")}`];
|
|
97
|
+
}
|
|
98
|
+
if (typeof entry === "object" ||
|
|
99
|
+
(typeof entry === "string" && entry.includes("\n"))) {
|
|
100
|
+
return [
|
|
101
|
+
`${indent}${fieldLabel(key)}:`,
|
|
102
|
+
...detailLines(entry, `${indent} `, evidence),
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
return [`${indent}${fieldLabel(key)}: ${safeLine(entry)}`];
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function numberedCode(lines, startLine, location) {
|
|
109
|
+
const numberWidth = String(startLine + lines.length - 1).length;
|
|
110
|
+
return lines.map((line, index) => {
|
|
111
|
+
const number = startLine + index;
|
|
112
|
+
const highlighted = location !== undefined &&
|
|
113
|
+
number >= location.startLine &&
|
|
114
|
+
number <= (location.endLine ?? location.startLine);
|
|
115
|
+
return `${highlighted ? "›" : " "} ${String(number).padStart(numberWidth)} │ ${safeLine(line)}`;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function locationSource(repository, location) {
|
|
119
|
+
try {
|
|
120
|
+
const root = realpathSync(repository);
|
|
121
|
+
const path = realpathSync(resolve(root, location.path));
|
|
122
|
+
const inside = relative(root, path);
|
|
123
|
+
if (inside === ".." ||
|
|
124
|
+
inside.startsWith(`..${sep}`) ||
|
|
125
|
+
isAbsolute(inside)) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
const source = readFileSync(path, "utf8").split(/\r?\n/u);
|
|
129
|
+
const first = Math.max(0, location.startLine - 4);
|
|
130
|
+
const last = Math.min(source.length, (location.endLine ?? location.startLine) + 3);
|
|
131
|
+
return numberedCode(source.slice(first, last), first + 1, location);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function matchesSeverity(finding, severity) {
|
|
138
|
+
return (SEVERITIES.indexOf(finding.severity.level) <=
|
|
139
|
+
SEVERITIES.indexOf(severity));
|
|
140
|
+
}
|
|
141
|
+
function findingLines(finding, repository, width) {
|
|
142
|
+
const evidenceById = new Map((finding.codeEvidence ?? []).map((item) => [item.id, item]));
|
|
143
|
+
const fields = [
|
|
144
|
+
...DETAIL_ORDER.map((key) => [key, finding[key]]),
|
|
145
|
+
...Object.entries(finding).filter(([key]) => key !== "title" &&
|
|
146
|
+
!DETAIL_ORDER.includes(key)),
|
|
147
|
+
];
|
|
148
|
+
const lines = [safeLine(finding.title), ""];
|
|
149
|
+
for (const [key, value] of fields) {
|
|
150
|
+
if (value === null ||
|
|
151
|
+
value === undefined ||
|
|
152
|
+
(Array.isArray(value) && value.length === 0)) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
lines.push(fieldLabel(key).toUpperCase());
|
|
156
|
+
if (key === "codeEvidence" && Array.isArray(value)) {
|
|
157
|
+
for (const evidence of value) {
|
|
158
|
+
const { label, path, startLine, endLine, code, explanation, ...other } = evidence;
|
|
159
|
+
const location = `${safeLine(path)}:${startLine}${endLine === undefined ? "" : `–${endLine}`}`;
|
|
160
|
+
lines.push(label ? `${safeLine(label)} · ${location}` : location, ...numberedCode(safeText(code).split("\n"), startLine), ...safeText(explanation).split("\n"), ...detailLines(other, " ", evidenceById));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else if (key === "locations" && Array.isArray(value)) {
|
|
164
|
+
for (const location of value) {
|
|
165
|
+
const { path, startLine, endLine, role, ...other } = location;
|
|
166
|
+
lines.push(`${safeLine(path)}:${startLine}${endLine === undefined ? "" : `–${endLine}`}${role === undefined ? "" : ` · ${safeLine(role)}`}`, ...locationSource(repository, location), ...detailLines(other, " ", evidenceById));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
lines.push(...detailLines(value, "", evidenceById));
|
|
171
|
+
}
|
|
172
|
+
lines.push("");
|
|
173
|
+
}
|
|
174
|
+
return lines.flatMap((line) => {
|
|
175
|
+
if (line.length === 0)
|
|
176
|
+
return [""];
|
|
177
|
+
const source = SOURCE_LINE.exec(line);
|
|
178
|
+
const prefix = source?.[1] ?? "";
|
|
179
|
+
const continuation = source
|
|
180
|
+
? `${prefix[0]}${" ".repeat(prefix.length - 3)}│ `
|
|
181
|
+
: "";
|
|
182
|
+
const available = Math.max(1, width - prefix.length);
|
|
183
|
+
const wrapped = [];
|
|
184
|
+
let remaining = source?.[2] ?? line;
|
|
185
|
+
do {
|
|
186
|
+
const boundary = remaining.length <= available
|
|
187
|
+
? -1
|
|
188
|
+
: remaining.lastIndexOf(" ", available);
|
|
189
|
+
const split = boundary > 0 && remaining.slice(0, boundary).trim().length > 0
|
|
190
|
+
? boundary
|
|
191
|
+
: available;
|
|
192
|
+
wrapped.push(`${wrapped.length === 0 ? prefix : continuation}${remaining.slice(0, split)}`);
|
|
193
|
+
remaining = remaining.slice(split);
|
|
194
|
+
if (source === null)
|
|
195
|
+
remaining = remaining.trimStart();
|
|
196
|
+
} while (remaining.length > 0);
|
|
197
|
+
return wrapped;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function FindingDetailLine({ line, section, title, severity, color, }) {
|
|
201
|
+
const heading = HEADING.test(line);
|
|
202
|
+
const accent = color ? "cyan" : undefined;
|
|
203
|
+
const muted = color ? "gray" : undefined;
|
|
204
|
+
const severityColor = color ? SEVERITY_COLORS[severity] : undefined;
|
|
205
|
+
if (title || heading) {
|
|
206
|
+
return (_jsx(Text, { bold: true, wrap: "truncate-end", children: line }));
|
|
207
|
+
}
|
|
208
|
+
if ((section === "SEVERITY" && line.toLowerCase() === severity) ||
|
|
209
|
+
(section === "CONFIDENCE" && /^(high|medium|low)$/iu.test(line))) {
|
|
210
|
+
return (_jsxs(Text, { bold: true, color: section === "SEVERITY" ? severityColor : undefined, wrap: "truncate-end", children: ["\u25CF ", line] }));
|
|
211
|
+
}
|
|
212
|
+
const source = SOURCE_LINE.exec(line);
|
|
213
|
+
if (source !== null) {
|
|
214
|
+
return (_jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: line.startsWith("›") ? severityColor : muted, children: source[1] }), _jsx(Text, { bold: line.startsWith("›"), children: source[2] })] }));
|
|
215
|
+
}
|
|
216
|
+
const location = /^(.*?)(\S+:\d+(?:–\d+)?)(.*)$/u.exec(line);
|
|
217
|
+
if (location !== null &&
|
|
218
|
+
(section === "LOCATIONS" || section === "CODE EVIDENCE")) {
|
|
219
|
+
return (_jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { children: location[1] }), _jsx(Text, { color: accent, children: location[2] }), _jsx(Text, { color: muted, children: location[3] })] }));
|
|
220
|
+
}
|
|
221
|
+
const labeled = /^(\s*(?:• |[A-Za-z][\w ]*:))(.*)$/u.exec(line);
|
|
222
|
+
if (labeled !== null) {
|
|
223
|
+
return (_jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: muted, children: labeled[1] }), labeled[2]] }));
|
|
224
|
+
}
|
|
225
|
+
return _jsx(Text, { wrap: "truncate-end", children: line || " " });
|
|
226
|
+
}
|
|
227
|
+
export function PatchTui({ repository, findings, onComplete, color = process.env["NO_COLOR"] === undefined, }) {
|
|
228
|
+
const { exit } = useApp();
|
|
229
|
+
const { stdout } = useStdout();
|
|
230
|
+
const [pane, setPane] = useState("findings");
|
|
231
|
+
const [focused, setFocused] = useState(0);
|
|
232
|
+
const focusedFinding = useRef(focused);
|
|
233
|
+
const [offset, setOffset] = useState(0);
|
|
234
|
+
const [preset, setPreset] = useState("low");
|
|
235
|
+
const [instructions, setInstructions] = useState({});
|
|
236
|
+
const [createPullRequest, setCreatePullRequest] = useState(false);
|
|
237
|
+
const [editing, setEditing] = useState(null);
|
|
238
|
+
const [draft, setDraft] = useState("");
|
|
239
|
+
const [selected, setSelected] = useState(() => new Set(findings.map(({ occurrenceId }) => occurrenceId)));
|
|
240
|
+
const rows = stdout.rows ?? 28;
|
|
241
|
+
const columns = stdout.columns ?? 100;
|
|
242
|
+
const visibleRows = Math.max(4, rows - 15);
|
|
243
|
+
const listStart = Math.max(0, Math.min(focused - visibleRows + 1, findings.length - visibleRows));
|
|
244
|
+
const current = findings[focused];
|
|
245
|
+
const details = useMemo(() => findingLines(current, repository, Math.max(18, Math.floor(columns * 0.58) - 7)), [columns, current, repository]);
|
|
246
|
+
const maximumOffset = Math.max(0, details.length - visibleRows);
|
|
247
|
+
const accent = color ? "cyan" : undefined;
|
|
248
|
+
const muted = color ? "gray" : undefined;
|
|
249
|
+
const instructionColor = color ? "magentaBright" : undefined;
|
|
250
|
+
const success = color ? "green" : undefined;
|
|
251
|
+
const severityColor = (severity) => color ? SEVERITY_COLORS[severity] : undefined;
|
|
252
|
+
const findingsColor = pane === "findings" && editing === null ? accent : muted;
|
|
253
|
+
const detailsColor = pane === "details" && editing === null ? accent : muted;
|
|
254
|
+
const currentInstructions = instructions[current.occurrenceId];
|
|
255
|
+
const selectedFindings = findings.filter(({ occurrenceId }) => selected.has(occurrenceId));
|
|
256
|
+
const presetMatches = findings.every((finding) => selected.has(finding.occurrenceId) === matchesSeverity(finding, preset));
|
|
257
|
+
useInput((input, key) => {
|
|
258
|
+
if (editing !== null) {
|
|
259
|
+
if (key.escape) {
|
|
260
|
+
setEditing(null);
|
|
261
|
+
}
|
|
262
|
+
else if (key.return) {
|
|
263
|
+
setInstructions((previous) => {
|
|
264
|
+
const next = { ...previous };
|
|
265
|
+
if (draft.trim().length === 0)
|
|
266
|
+
delete next[editing];
|
|
267
|
+
else
|
|
268
|
+
next[editing] = draft.trim();
|
|
269
|
+
return next;
|
|
270
|
+
});
|
|
271
|
+
setEditing(null);
|
|
272
|
+
}
|
|
273
|
+
else if (key.backspace || key.delete) {
|
|
274
|
+
setDraft((previous) => previous.slice(0, -1));
|
|
275
|
+
}
|
|
276
|
+
else if (!key.ctrl && !key.meta && input.length > 0) {
|
|
277
|
+
setDraft((previous) => previous + input);
|
|
278
|
+
}
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (key.escape || input === "q" || (key.ctrl && input === "c")) {
|
|
282
|
+
onComplete(null);
|
|
283
|
+
exit();
|
|
284
|
+
}
|
|
285
|
+
else if (key.return || input === "p") {
|
|
286
|
+
if (selectedFindings.length === 0) {
|
|
287
|
+
onComplete(null);
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
const severity = selectedFindings.reduce((lowest, finding) => matchesSeverity(finding, lowest)
|
|
291
|
+
? lowest
|
|
292
|
+
: finding.severity.level, "critical");
|
|
293
|
+
const findingInstructions = Object.fromEntries(Object.entries(instructions).filter(([occurrenceId]) => selected.has(occurrenceId)));
|
|
294
|
+
onComplete({
|
|
295
|
+
severity,
|
|
296
|
+
occurrenceIds: selectedFindings.map(({ occurrenceId }) => occurrenceId),
|
|
297
|
+
...(Object.keys(findingInstructions).length === 0
|
|
298
|
+
? {}
|
|
299
|
+
: { instructions: findingInstructions }),
|
|
300
|
+
...(createPullRequest ? { createPullRequest: true } : {}),
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
exit();
|
|
304
|
+
}
|
|
305
|
+
else if (input === "r") {
|
|
306
|
+
setCreatePullRequest((previous) => !previous);
|
|
307
|
+
}
|
|
308
|
+
else if (input === "i") {
|
|
309
|
+
const occurrenceId = findings[focusedFinding.current].occurrenceId;
|
|
310
|
+
setDraft(instructions[occurrenceId] ?? "");
|
|
311
|
+
setEditing(occurrenceId);
|
|
312
|
+
}
|
|
313
|
+
else if (key.tab || key.leftArrow || key.rightArrow || input === "d") {
|
|
314
|
+
setPane(pane === "findings" ? "details" : "findings");
|
|
315
|
+
}
|
|
316
|
+
else if (key.upArrow || key.downArrow || input === "j" || input === "k") {
|
|
317
|
+
const direction = key.downArrow || input === "j" ? 1 : -1;
|
|
318
|
+
if (pane === "findings") {
|
|
319
|
+
focusedFinding.current = Math.max(0, Math.min(findings.length - 1, focusedFinding.current + direction));
|
|
320
|
+
setFocused(focusedFinding.current);
|
|
321
|
+
setOffset(0);
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
setOffset(Math.max(0, Math.min(maximumOffset, offset + direction)));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
else if (key.pageUp || key.pageDown) {
|
|
328
|
+
setOffset(Math.max(0, Math.min(maximumOffset, offset + (key.pageDown ? 1 : -1) * visibleRows)));
|
|
329
|
+
}
|
|
330
|
+
else if (input === " ") {
|
|
331
|
+
const next = new Set(selected);
|
|
332
|
+
const occurrenceId = findings[focusedFinding.current].occurrenceId;
|
|
333
|
+
if (next.has(occurrenceId))
|
|
334
|
+
next.delete(occurrenceId);
|
|
335
|
+
else
|
|
336
|
+
next.add(occurrenceId);
|
|
337
|
+
setSelected(next);
|
|
338
|
+
}
|
|
339
|
+
else if (input === "a" || input === "n") {
|
|
340
|
+
setSelected(new Set(input === "a" ? findings.map(({ occurrenceId }) => occurrenceId) : []));
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
const severity = SEVERITIES[Number(input) - 1];
|
|
344
|
+
if (severity !== undefined) {
|
|
345
|
+
setPreset(severity);
|
|
346
|
+
setSelected(new Set(findings
|
|
347
|
+
.filter((finding) => matchesSeverity(finding, severity))
|
|
348
|
+
.map(({ occurrenceId }) => occurrenceId)));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
return (_jsxs(Box, { flexDirection: "column", height: Math.max(15, rows - 1), paddingX: 1, children: [_jsxs(Box, { justifyContent: "space-between", marginBottom: 1, children: [_jsxs(Text, { bold: true, children: [_jsx(Text, { color: accent, children: "CODEX SECURITY" }), " ", safeLine(basename(repository))] }), _jsxs(Text, { children: [_jsxs(Text, { bold: true, color: selected.size === 0 ? muted : success, children: [selected.size, "/", findings.length] }), _jsx(Text, { dimColor: true, children: " selected \u00B7 " }), _jsx(Text, { color: presetMatches ? severityColor(preset) : accent, children: presetMatches ? `${preset} and above` : "custom" })] })] }), _jsxs(Box, { height: visibleRows + 3, children: [_jsxs(Box, { borderStyle: "round", borderColor: findingsColor, flexDirection: "column", overflow: "hidden", paddingX: 1, width: "40%", children: [_jsx(Text, { bold: true, color: findingsColor, children: "FINDINGS" }), findings
|
|
353
|
+
.slice(listStart, listStart + visibleRows)
|
|
354
|
+
.map((finding, index) => {
|
|
355
|
+
const active = listStart + index === focused;
|
|
356
|
+
const checked = selected.has(finding.occurrenceId);
|
|
357
|
+
return (_jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: active ? accent : muted, children: active ? "› " : " " }), _jsx(Text, { color: checked ? success : muted, children: checked ? "[✓] " : "[ ] " }), _jsx(Text, { bold: true, color: severityColor(finding.severity.level), children: finding.severity.level.toUpperCase() }), " ", instructions[finding.occurrenceId] !== undefined ? (_jsx(Text, { color: instructionColor, children: "\u270E " })) : null, _jsx(Text, { color: active && color ? "whiteBright" : undefined, children: safeLine(finding.title) })] }, finding.occurrenceId));
|
|
358
|
+
})] }), _jsxs(Box, { borderStyle: "round", borderColor: detailsColor, flexDirection: "column", flexGrow: 1, marginLeft: 1, overflow: "hidden", paddingX: 1, children: [_jsxs(Text, { bold: true, color: detailsColor, children: ["DETAILS", details.length > visibleRows
|
|
359
|
+
? ` ${offset + 1}–${Math.min(details.length, offset + visibleRows)}/${details.length}`
|
|
360
|
+
: ""] }), details.slice(offset, offset + visibleRows).map((line, index) => (_jsx(FindingDetailLine, { line: line, section: details
|
|
361
|
+
.slice(0, offset + index + 1)
|
|
362
|
+
.findLast((entry) => HEADING.test(entry)), title: offset + index === 0, severity: current.severity.level, color: color }, offset + index)))] })] }), _jsxs(Box, { borderStyle: "round", borderColor: editing === null ? muted : instructionColor, flexDirection: "column", height: 5, overflow: "hidden", paddingX: 1, children: [_jsxs(Box, { justifyContent: "space-between", children: [_jsx(Text, { bold: true, color: instructionColor, children: "PATCH INSTRUCTIONS" }), _jsx(Text, { dimColor: true, children: editing === null ? "i edit" : "Enter save · Esc cancel" })] }), editing === null ? (_jsx(Text, { color: currentInstructions ? instructionColor : muted, wrap: "wrap", children: currentInstructions === undefined
|
|
363
|
+
? "Add instructions for this finding."
|
|
364
|
+
: safeText(currentInstructions) })) : (_jsxs(Text, { wrap: "truncate-start", children: [_jsx(Text, { color: instructionColor, children: safeLine(draft) }), _jsx(Text, { inverse: true, children: " " })] }))] }), _jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: createPullRequest ? success : muted, children: createPullRequest ? "[✓]" : "[ ]" }), " Create GitHub pull request after patching ", _jsx(Text, { dimColor: true, children: "(r toggle)" })] }), _jsxs(Text, { dimColor: true, wrap: "truncate-end", children: [_jsx(Text, { color: accent, children: "\u2191\u2193" }), " browse \u00B7 ", _jsx(Text, { color: accent, children: "Tab" }), " ", "details \u00B7 ", _jsx(Text, { color: accent, children: "Space" }), " select \u00B7", " ", _jsx(Text, { color: instructionColor, children: "i" }), " instructions \u00B7 a/n all/none"] }), _jsxs(Text, { dimColor: true, wrap: "truncate-end", children: [_jsx(Text, { color: severityColor("critical"), children: "1" }), " critical \u00B7", " ", _jsx(Text, { color: severityColor("high"), children: "2" }), " high \u00B7", " ", _jsx(Text, { color: severityColor("medium"), children: "3" }), " medium \u00B7", " ", _jsx(Text, { color: severityColor("low"), children: "4" }), " low \u00B7", " ", _jsx(Text, { color: success, children: "Enter" }), " patch \u00B7 q skip"] })] }));
|
|
365
|
+
}
|
|
366
|
+
export async function runPatchTui(repository, findings, { stdin = process.stdin, stdout = process.stderr, color, } = {}) {
|
|
367
|
+
if (!stdin.isTTY || !stdout.isTTY) {
|
|
368
|
+
throw new Error("Interactive patch selection requires a terminal.");
|
|
369
|
+
}
|
|
370
|
+
let selection = null;
|
|
371
|
+
stdout.write("\u001B[?1049h");
|
|
372
|
+
try {
|
|
373
|
+
stdin.resume();
|
|
374
|
+
const instance = render(_jsx(PatchTui, { repository: repository, findings: findings, color: color, onComplete: (value) => {
|
|
375
|
+
selection = value;
|
|
376
|
+
} }), { stdin, stdout, exitOnCtrlC: false, patchConsole: false });
|
|
377
|
+
await instance.waitUntilExit();
|
|
378
|
+
return selection;
|
|
379
|
+
}
|
|
380
|
+
finally {
|
|
381
|
+
stdout.write("\u001B[?1049l");
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
//# sourceMappingURL=patch-tui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-tui.js","sourceRoot":"","sources":["../src/patch-tui.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,MAAM,eAAe,GAAG;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C;IAC5C,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAC9B,IAAI,CAAC;QACH,KAAK,CAAC,MAAM,EAAE,CAAC;QACf,MAAM,QAAQ,GAAG,MAAM,CACrB,KAAC,QAAQ,IACP,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE;gBACpB,SAAS,GAAG,KAAK,CAAC;YACpB,CAAC,GACD,EACF,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,CAC3D,CAAC;QACF,MAAM,QAAQ,CAAC,aAAa,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC;IACnB,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAChC,CAAC;AACH,CAAC","sourcesContent":["import { readFileSync, realpathSync } from \"node:fs\";\nimport { basename, isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { stripVTControlCharacters } from \"node:util\";\nimport { Box, Text, render, useApp, useInput, useStdout } from \"ink\";\nimport { useMemo, useRef, useState } from \"react\";\nimport { safeErrorMessage } from \"./errors.js\";\nimport type { Finding, FindingCodeEvidence } from \"./models.js\";\n\nconst SEVERITY_COLORS = {\n critical: \"redBright\",\n high: \"red\",\n medium: \"yellow\",\n low: \"blueBright\",\n} as const;\n\ntype PatchSeverity = keyof typeof SEVERITY_COLORS;\n\nconst SEVERITIES = Object.keys(SEVERITY_COLORS) as PatchSeverity[];\nconst HEADING = /^[A-Z][A-Z ]+$/u;\nconst SOURCE_LINE = /^([› ]\\s*\\d* │ )(.*)$/u;\n\nconst DETAIL_ORDER = [\n \"summary\",\n \"severity\",\n \"confidence\",\n \"rootCause\",\n \"validation\",\n \"attackPath\",\n \"impact\",\n \"likelihood\",\n \"reachability\",\n \"prerequisites\",\n \"counterevidence\",\n \"limitations\",\n \"locations\",\n \"codeEvidence\",\n \"remediation\",\n \"remediationTests\",\n \"preventiveControls\",\n \"taxonomy\",\n \"findingId\",\n \"occurrenceId\",\n] as const;\n\nexport interface PatchSelection {\n severity: PatchSeverity;\n occurrenceIds: string[];\n instructions?: Record<string, string>;\n createPullRequest?: boolean;\n}\n\ninterface PatchTuiProps {\n repository: string;\n findings: readonly Finding[];\n onComplete(selection: PatchSelection | null): void;\n color?: boolean;\n}\n\nfunction safeText(value: unknown): string {\n return stripVTControlCharacters(safeErrorMessage(String(value)))\n .replaceAll(/\\r\\n?/gu, \"\\n\")\n .replaceAll(/[\\u0000-\\u0009\\u000B-\\u001F\\u007F-\\u009F\\u2028\\u2029]/gu, \" \");\n}\n\nfunction safeLine(value: unknown): string {\n return safeText(value).replaceAll(\"\\n\", \" \");\n}\n\nfunction fieldLabel(value: string): string {\n return safeLine(value)\n .replaceAll(/([a-z\\d])([A-Z])/gu, \"$1 $2\")\n .replaceAll(\"_\", \" \")\n .replaceAll(/\\b(cwe|id)\\b/giu, (match) => match.toUpperCase())\n .replace(/^./u, (match) => match.toUpperCase());\n}\n\nfunction detailLines(\n value: unknown,\n indent = \"\",\n evidence?: ReadonlyMap<string, FindingCodeEvidence>,\n): string[] {\n if (Array.isArray(value)) {\n return value.flatMap((entry) => {\n const lines = detailLines(entry, `${indent} `, evidence);\n return lines.length === 0\n ? []\n : [`${indent}• ${lines[0]!.trimStart()}`, ...lines.slice(1)];\n });\n }\n if (typeof value !== \"object\" || value === null) {\n return safeText(value)\n .split(\"\\n\")\n .map((line) => `${indent}${line}`);\n }\n\n return Object.entries(value).flatMap(([key, entry]) => {\n if (\n entry === null ||\n entry === undefined ||\n (Array.isArray(entry) && entry.length === 0)\n ) {\n return [];\n }\n if (key === \"level\") {\n const level = safeLine(entry);\n return [\n `${indent}${level.replace(/^./u, (match) => match.toUpperCase())}`,\n ];\n }\n if (\n (key === \"summary\" || key === \"rationale\") &&\n typeof entry === \"string\"\n ) {\n return detailLines(entry, indent, evidence);\n }\n if (key === \"evidenceRefs\" && Array.isArray(entry)) {\n return [\n `${indent}Evidence:`,\n ...entry.map((reference) => {\n const item = evidence?.get(String(reference));\n return item === undefined\n ? `${indent} • ${safeLine(reference)}`\n : `${indent} • ${safeLine(item.label)} · ${safeLine(item.path)}:${item.startLine}`;\n }),\n ];\n }\n if (key === \"cwe\" && Array.isArray(entry)) {\n return [`${indent}CWE: ${entry.map(safeLine).join(\", \")}`];\n }\n if (\n typeof entry === \"object\" ||\n (typeof entry === \"string\" && entry.includes(\"\\n\"))\n ) {\n return [\n `${indent}${fieldLabel(key)}:`,\n ...detailLines(entry, `${indent} `, evidence),\n ];\n }\n return [`${indent}${fieldLabel(key)}: ${safeLine(entry)}`];\n });\n}\n\nfunction numberedCode(\n lines: readonly string[],\n startLine: number,\n location?: Finding[\"locations\"][number],\n): string[] {\n const numberWidth = String(startLine + lines.length - 1).length;\n return lines.map((line, index) => {\n const number = startLine + index;\n const highlighted =\n location !== undefined &&\n number >= location.startLine &&\n number <= (location.endLine ?? location.startLine);\n return `${highlighted ? \"›\" : \" \"} ${String(number).padStart(numberWidth)} │ ${safeLine(line)}`;\n });\n}\n\nfunction locationSource(\n repository: string,\n location: Finding[\"locations\"][number],\n): string[] {\n try {\n const root = realpathSync(repository);\n const path = realpathSync(resolve(root, location.path));\n const inside = relative(root, path);\n if (\n inside === \"..\" ||\n inside.startsWith(`..${sep}`) ||\n isAbsolute(inside)\n ) {\n return [];\n }\n\n const source = readFileSync(path, \"utf8\").split(/\\r?\\n/u);\n const first = Math.max(0, location.startLine - 4);\n const last = Math.min(\n source.length,\n (location.endLine ?? location.startLine) + 3,\n );\n return numberedCode(source.slice(first, last), first + 1, location);\n } catch {\n return [];\n }\n}\n\nfunction matchesSeverity(finding: Finding, severity: PatchSeverity): boolean {\n return (\n SEVERITIES.indexOf(finding.severity.level as PatchSeverity) <=\n SEVERITIES.indexOf(severity)\n );\n}\n\nfunction findingLines(\n finding: Finding,\n repository: string,\n width: number,\n): string[] {\n const evidenceById = new Map(\n (finding.codeEvidence ?? []).map((item) => [item.id, item]),\n );\n const fields = [\n ...DETAIL_ORDER.map((key) => [key, finding[key]] as const),\n ...Object.entries(finding).filter(\n ([key]) =>\n key !== \"title\" &&\n !DETAIL_ORDER.includes(key as (typeof DETAIL_ORDER)[number]),\n ),\n ];\n\n const lines = [safeLine(finding.title), \"\"];\n for (const [key, value] of fields) {\n if (\n value === null ||\n value === undefined ||\n (Array.isArray(value) && value.length === 0)\n ) {\n continue;\n }\n lines.push(fieldLabel(key).toUpperCase());\n if (key === \"codeEvidence\" && Array.isArray(value)) {\n for (const evidence of value as FindingCodeEvidence[]) {\n const { label, path, startLine, endLine, code, explanation, ...other } =\n evidence;\n const location = `${safeLine(path)}:${startLine}${\n endLine === undefined ? \"\" : `–${endLine}`\n }`;\n lines.push(\n label ? `${safeLine(label)} · ${location}` : location,\n ...numberedCode(safeText(code).split(\"\\n\"), startLine),\n ...safeText(explanation).split(\"\\n\"),\n ...detailLines(other, \" \", evidenceById),\n );\n }\n } else if (key === \"locations\" && Array.isArray(value)) {\n for (const location of value as Finding[\"locations\"]) {\n const { path, startLine, endLine, role, ...other } = location;\n lines.push(\n `${safeLine(path)}:${startLine}${endLine === undefined ? \"\" : `–${endLine}`}${\n role === undefined ? \"\" : ` · ${safeLine(role)}`\n }`,\n ...locationSource(repository, location),\n ...detailLines(other, \" \", evidenceById),\n );\n }\n } else {\n lines.push(...detailLines(value, \"\", evidenceById));\n }\n lines.push(\"\");\n }\n\n return lines.flatMap((line) => {\n if (line.length === 0) return [\"\"];\n const source = SOURCE_LINE.exec(line);\n const prefix = source?.[1] ?? \"\";\n const continuation = source\n ? `${prefix[0]}${\" \".repeat(prefix.length - 3)}│ `\n : \"\";\n const available = Math.max(1, width - prefix.length);\n const wrapped: string[] = [];\n let remaining = source?.[2] ?? line;\n do {\n const boundary =\n remaining.length <= available\n ? -1\n : remaining.lastIndexOf(\" \", available);\n const split =\n boundary > 0 && remaining.slice(0, boundary).trim().length > 0\n ? boundary\n : available;\n wrapped.push(\n `${wrapped.length === 0 ? prefix : continuation}${remaining.slice(0, split)}`,\n );\n remaining = remaining.slice(split);\n if (source === null) remaining = remaining.trimStart();\n } while (remaining.length > 0);\n return wrapped;\n });\n}\n\nfunction FindingDetailLine({\n line,\n section,\n title,\n severity,\n color,\n}: {\n line: string;\n section: string | undefined;\n title: boolean;\n severity: PatchSeverity;\n color: boolean;\n}): React.JSX.Element {\n const heading = HEADING.test(line);\n const accent = color ? \"cyan\" : undefined;\n const muted = color ? \"gray\" : undefined;\n const severityColor = color ? SEVERITY_COLORS[severity] : undefined;\n\n if (title || heading) {\n return (\n <Text bold wrap=\"truncate-end\">\n {line}\n </Text>\n );\n }\n\n if (\n (section === \"SEVERITY\" && line.toLowerCase() === severity) ||\n (section === \"CONFIDENCE\" && /^(high|medium|low)$/iu.test(line))\n ) {\n return (\n <Text\n bold\n color={section === \"SEVERITY\" ? severityColor : undefined}\n wrap=\"truncate-end\"\n >\n ● {line}\n </Text>\n );\n }\n\n const source = SOURCE_LINE.exec(line);\n if (source !== null) {\n return (\n <Text wrap=\"truncate-end\">\n <Text color={line.startsWith(\"›\") ? severityColor : muted}>\n {source[1]}\n </Text>\n <Text bold={line.startsWith(\"›\")}>{source[2]}</Text>\n </Text>\n );\n }\n\n const location = /^(.*?)(\\S+:\\d+(?:–\\d+)?)(.*)$/u.exec(line);\n if (\n location !== null &&\n (section === \"LOCATIONS\" || section === \"CODE EVIDENCE\")\n ) {\n return (\n <Text wrap=\"truncate-end\">\n <Text>{location[1]}</Text>\n <Text color={accent}>{location[2]}</Text>\n <Text color={muted}>{location[3]}</Text>\n </Text>\n );\n }\n\n const labeled = /^(\\s*(?:• |[A-Za-z][\\w ]*:))(.*)$/u.exec(line);\n if (labeled !== null) {\n return (\n <Text wrap=\"truncate-end\">\n <Text color={muted}>{labeled[1]}</Text>\n {labeled[2]}\n </Text>\n );\n }\n\n return <Text wrap=\"truncate-end\">{line || \" \"}</Text>;\n}\n\nexport function PatchTui({\n repository,\n findings,\n onComplete,\n color = process.env[\"NO_COLOR\"] === undefined,\n}: PatchTuiProps): React.JSX.Element {\n const { exit } = useApp();\n const { stdout } = useStdout();\n const [pane, setPane] = useState<\"findings\" | \"details\">(\"findings\");\n const [focused, setFocused] = useState(0);\n const focusedFinding = useRef(focused);\n const [offset, setOffset] = useState(0);\n const [preset, setPreset] = useState<PatchSeverity>(\"low\");\n const [instructions, setInstructions] = useState<Record<string, string>>({});\n const [createPullRequest, setCreatePullRequest] = useState(false);\n const [editing, setEditing] = useState<string | null>(null);\n const [draft, setDraft] = useState(\"\");\n const [selected, setSelected] = useState(\n () => new Set(findings.map(({ occurrenceId }) => occurrenceId)),\n );\n const rows = stdout.rows ?? 28;\n const columns = stdout.columns ?? 100;\n const visibleRows = Math.max(4, rows - 15);\n const listStart = Math.max(\n 0,\n Math.min(focused - visibleRows + 1, findings.length - visibleRows),\n );\n const current = findings[focused]!;\n const details = useMemo(\n () =>\n findingLines(\n current,\n repository,\n Math.max(18, Math.floor(columns * 0.58) - 7),\n ),\n [columns, current, repository],\n );\n const maximumOffset = Math.max(0, details.length - visibleRows);\n const accent = color ? \"cyan\" : undefined;\n const muted = color ? \"gray\" : undefined;\n const instructionColor = color ? \"magentaBright\" : undefined;\n const success = color ? \"green\" : undefined;\n const severityColor = (severity: PatchSeverity) =>\n color ? SEVERITY_COLORS[severity] : undefined;\n const findingsColor =\n pane === \"findings\" && editing === null ? accent : muted;\n const detailsColor = pane === \"details\" && editing === null ? accent : muted;\n const currentInstructions = instructions[current.occurrenceId];\n const selectedFindings = findings.filter(({ occurrenceId }) =>\n selected.has(occurrenceId),\n );\n const presetMatches = findings.every(\n (finding) =>\n selected.has(finding.occurrenceId) === matchesSeverity(finding, preset),\n );\n\n useInput((input, key) => {\n if (editing !== null) {\n if (key.escape) {\n setEditing(null);\n } else if (key.return) {\n setInstructions((previous) => {\n const next = { ...previous };\n if (draft.trim().length === 0) delete next[editing];\n else next[editing] = draft.trim();\n return next;\n });\n setEditing(null);\n } else if (key.backspace || key.delete) {\n setDraft((previous) => previous.slice(0, -1));\n } else if (!key.ctrl && !key.meta && input.length > 0) {\n setDraft((previous) => previous + input);\n }\n return;\n }\n\n if (key.escape || input === \"q\" || (key.ctrl && input === \"c\")) {\n onComplete(null);\n exit();\n } else if (key.return || input === \"p\") {\n if (selectedFindings.length === 0) {\n onComplete(null);\n } else {\n const severity = selectedFindings.reduce<PatchSeverity>(\n (lowest, finding) =>\n matchesSeverity(finding, lowest)\n ? lowest\n : (finding.severity.level as PatchSeverity),\n \"critical\",\n );\n const findingInstructions = Object.fromEntries(\n Object.entries(instructions).filter(([occurrenceId]) =>\n selected.has(occurrenceId),\n ),\n );\n onComplete({\n severity,\n occurrenceIds: selectedFindings.map(\n ({ occurrenceId }) => occurrenceId,\n ),\n ...(Object.keys(findingInstructions).length === 0\n ? {}\n : { instructions: findingInstructions }),\n ...(createPullRequest ? { createPullRequest: true } : {}),\n });\n }\n exit();\n } else if (input === \"r\") {\n setCreatePullRequest((previous) => !previous);\n } else if (input === \"i\") {\n const occurrenceId = findings[focusedFinding.current]!.occurrenceId;\n setDraft(instructions[occurrenceId] ?? \"\");\n setEditing(occurrenceId);\n } else if (key.tab || key.leftArrow || key.rightArrow || input === \"d\") {\n setPane(pane === \"findings\" ? \"details\" : \"findings\");\n } else if (key.upArrow || key.downArrow || input === \"j\" || input === \"k\") {\n const direction = key.downArrow || input === \"j\" ? 1 : -1;\n if (pane === \"findings\") {\n focusedFinding.current = Math.max(\n 0,\n Math.min(findings.length - 1, focusedFinding.current + direction),\n );\n setFocused(focusedFinding.current);\n setOffset(0);\n } else {\n setOffset(Math.max(0, Math.min(maximumOffset, offset + direction)));\n }\n } else if (key.pageUp || key.pageDown) {\n setOffset(\n Math.max(\n 0,\n Math.min(\n maximumOffset,\n offset + (key.pageDown ? 1 : -1) * visibleRows,\n ),\n ),\n );\n } else if (input === \" \") {\n const next = new Set(selected);\n const occurrenceId = findings[focusedFinding.current]!.occurrenceId;\n if (next.has(occurrenceId)) next.delete(occurrenceId);\n else next.add(occurrenceId);\n setSelected(next);\n } else if (input === \"a\" || input === \"n\") {\n setSelected(\n new Set(\n input === \"a\" ? findings.map(({ occurrenceId }) => occurrenceId) : [],\n ),\n );\n } else {\n const severity = SEVERITIES[Number(input) - 1];\n if (severity !== undefined) {\n setPreset(severity);\n setSelected(\n new Set(\n findings\n .filter((finding) => matchesSeverity(finding, severity))\n .map(({ occurrenceId }) => occurrenceId),\n ),\n );\n }\n }\n });\n\n return (\n <Box flexDirection=\"column\" height={Math.max(15, rows - 1)} paddingX={1}>\n <Box justifyContent=\"space-between\" marginBottom={1}>\n <Text bold>\n <Text color={accent}>CODEX SECURITY</Text>\n {\" \"}\n {safeLine(basename(repository))}\n </Text>\n <Text>\n <Text bold color={selected.size === 0 ? muted : success}>\n {selected.size}/{findings.length}\n </Text>\n <Text dimColor> selected · </Text>\n <Text color={presetMatches ? severityColor(preset) : accent}>\n {presetMatches ? `${preset} and above` : \"custom\"}\n </Text>\n </Text>\n </Box>\n\n <Box height={visibleRows + 3}>\n <Box\n borderStyle=\"round\"\n borderColor={findingsColor}\n flexDirection=\"column\"\n overflow=\"hidden\"\n paddingX={1}\n width=\"40%\"\n >\n <Text bold color={findingsColor}>\n FINDINGS\n </Text>\n {findings\n .slice(listStart, listStart + visibleRows)\n .map((finding, index) => {\n const active = listStart + index === focused;\n const checked = selected.has(finding.occurrenceId);\n return (\n <Text key={finding.occurrenceId} wrap=\"truncate-end\">\n <Text color={active ? accent : muted}>\n {active ? \"› \" : \" \"}\n </Text>\n <Text color={checked ? success : muted}>\n {checked ? \"[✓] \" : \"[ ] \"}\n </Text>\n <Text\n bold\n color={severityColor(\n finding.severity.level as PatchSeverity,\n )}\n >\n {finding.severity.level.toUpperCase()}\n </Text>{\" \"}\n {instructions[finding.occurrenceId] !== undefined ? (\n <Text color={instructionColor}>✎ </Text>\n ) : null}\n <Text color={active && color ? \"whiteBright\" : undefined}>\n {safeLine(finding.title)}\n </Text>\n </Text>\n );\n })}\n </Box>\n\n <Box\n borderStyle=\"round\"\n borderColor={detailsColor}\n flexDirection=\"column\"\n flexGrow={1}\n marginLeft={1}\n overflow=\"hidden\"\n paddingX={1}\n >\n <Text bold color={detailsColor}>\n DETAILS\n {details.length > visibleRows\n ? ` ${offset + 1}–${Math.min(details.length, offset + visibleRows)}/${details.length}`\n : \"\"}\n </Text>\n {details.slice(offset, offset + visibleRows).map((line, index) => (\n <FindingDetailLine\n key={offset + index}\n line={line}\n section={details\n .slice(0, offset + index + 1)\n .findLast((entry) => HEADING.test(entry))}\n title={offset + index === 0}\n severity={current.severity.level as PatchSeverity}\n color={color}\n />\n ))}\n </Box>\n </Box>\n\n <Box\n borderStyle=\"round\"\n borderColor={editing === null ? muted : instructionColor}\n flexDirection=\"column\"\n height={5}\n overflow=\"hidden\"\n paddingX={1}\n >\n <Box justifyContent=\"space-between\">\n <Text bold color={instructionColor}>\n PATCH INSTRUCTIONS\n </Text>\n <Text dimColor>\n {editing === null ? \"i edit\" : \"Enter save · Esc cancel\"}\n </Text>\n </Box>\n {editing === null ? (\n <Text\n color={currentInstructions ? instructionColor : muted}\n wrap=\"wrap\"\n >\n {currentInstructions === undefined\n ? \"Add instructions for this finding.\"\n : safeText(currentInstructions)}\n </Text>\n ) : (\n <Text wrap=\"truncate-start\">\n <Text color={instructionColor}>{safeLine(draft)}</Text>\n <Text inverse> </Text>\n </Text>\n )}\n </Box>\n\n <Text wrap=\"truncate-end\">\n <Text color={createPullRequest ? success : muted}>\n {createPullRequest ? \"[✓]\" : \"[ ]\"}\n </Text>\n {\" Create GitHub pull request after patching \"}\n <Text dimColor>(r toggle)</Text>\n </Text>\n\n <Text dimColor wrap=\"truncate-end\">\n <Text color={accent}>↑↓</Text> browse · <Text color={accent}>Tab</Text>{\" \"}\n details · <Text color={accent}>Space</Text> select ·{\" \"}\n <Text color={instructionColor}>i</Text> instructions · a/n all/none\n </Text>\n <Text dimColor wrap=\"truncate-end\">\n <Text color={severityColor(\"critical\")}>1</Text> critical ·{\" \"}\n <Text color={severityColor(\"high\")}>2</Text> high ·{\" \"}\n <Text color={severityColor(\"medium\")}>3</Text> medium ·{\" \"}\n <Text color={severityColor(\"low\")}>4</Text> low ·{\" \"}\n <Text color={success}>Enter</Text> patch · q skip\n </Text>\n </Box>\n );\n}\n\nexport async function runPatchTui(\n repository: string,\n findings: readonly Finding[],\n {\n stdin = process.stdin,\n stdout = process.stderr,\n color,\n }: {\n stdin?: NodeJS.ReadStream;\n stdout?: NodeJS.WriteStream;\n color?: boolean;\n } = {},\n): Promise<PatchSelection | null> {\n if (!stdin.isTTY || !stdout.isTTY) {\n throw new Error(\"Interactive patch selection requires a terminal.\");\n }\n\n let selection: PatchSelection | null = null;\n stdout.write(\"\\u001B[?1049h\");\n try {\n stdin.resume();\n const instance = render(\n <PatchTui\n repository={repository}\n findings={findings}\n color={color}\n onComplete={(value) => {\n selection = value;\n }}\n />,\n { stdin, stdout, exitOnCtrlC: false, patchConsole: false },\n );\n await instance.waitUntilExit();\n return selection;\n } finally {\n stdout.write(\"\\u001B[?1049l\");\n }\n}\n"]}
|
package/dist/publish.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type LinearClientFactory } from "./linear.js";
|
|
2
2
|
import { prepareScanPublication, type LinearPublicationDestination, type PreparedPublicationIssue } from "./publication.js";
|
|
3
3
|
import { preparePublicationStore, recordPublishedIssues } from "./publication-store.js";
|
|
4
4
|
import { type CodexCommand } from "./runtime.js";
|
|
@@ -64,7 +64,7 @@ export interface PublicationCodexResult {
|
|
|
64
64
|
}
|
|
65
65
|
export interface PublishScanDependencies {
|
|
66
66
|
environment?: NodeJS.ProcessEnv;
|
|
67
|
-
linearClient?:
|
|
67
|
+
linearClient?: LinearClientFactory<"users" | "createIssue">;
|
|
68
68
|
prepare?: typeof prepareScanPublication;
|
|
69
69
|
resolveCodex?: (environment: NodeJS.ProcessEnv) => CodexCommand;
|
|
70
70
|
runCodex?: (command: CodexCommand, args: readonly string[], input: string, environment: NodeJS.ProcessEnv, onEvent?: (event: unknown) => void, signal?: AbortSignal) => Promise<PublicationCodexResult>;
|
package/dist/publish.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAiBA,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,KAAK,4BAA4B,EACjC,KAAK,wBAAwB,EAE9B,MAAM,kBAAkB,CAAC;AAK1B,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,QAAQ,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC;CACnD;AAED,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACvC;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;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IAC5D,OAAO,CAAC,EAAE,OAAO,sBAAsB,CAAC;IACxC,YAAY,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,UAAU,KAAK,YAAY,CAAC;IAChE,QAAQ,CAAC,EAAE,CACT,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,CAAC,UAAU,EAC9B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,EAClC,MAAM,CAAC,EAAE,WAAW,KACjB,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACrC,uBAAuB,CAAC,EAAE,OAAO,uBAAuB,CAAC;IACzD,qBAAqB,CAAC,EAAE,OAAO,qBAAqB,CAAC;IACrD,YAAY,CAAC,EAAE,CACb,MAAM,EAAE,iBAAiB,EACzB,WAAW,EAAE,MAAM,CAAC,UAAU,KAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB;AAED,wBAAsB,WAAW,CAC/B,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAE5B;AAED,wBAAsB,mBAAmB,CACvC,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,kBAAkB,EAC3B,YAAY,GAAE,uBAA4B,GACzC,OAAO,CAAC,iBAAiB,CAAC,CAqP5B"}
|
package/dist/publish.js
CHANGED
|
@@ -2,8 +2,8 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
3
|
import { appendFile, mkdir, mkdtemp, readFile, rm, writeFile, } from "node:fs/promises";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
import { LinearClient } from "@linear/sdk";
|
|
6
5
|
import { CodexSecurityError, ConfigurationError, safeErrorMessage, } from "./errors.js";
|
|
6
|
+
import { createLinearClient, resolveLinearApiKey, } from "./linear.js";
|
|
7
7
|
import { prepareScanPublication, } from "./publication.js";
|
|
8
8
|
import { collectPublicationEvents, matchPublicationIssue, } from "./publication-events.js";
|
|
9
9
|
import { preparePublicationStore, recordPublishedIssues, } from "./publication-store.js";
|
|
@@ -23,9 +23,7 @@ export async function publishScanInternal(scanDirectory, options, dependencies =
|
|
|
23
23
|
throw new ConfigurationError("A Linear project cannot be blank when provided.");
|
|
24
24
|
}
|
|
25
25
|
const environment = dependencies.environment ?? process.env;
|
|
26
|
-
const linearApiKey = options.linearApiKey
|
|
27
|
-
environment["CODEX_SECURITY_LINEAR_API_KEY"]?.trim() ||
|
|
28
|
-
undefined;
|
|
26
|
+
const linearApiKey = resolveLinearApiKey(environment, options.linearApiKey);
|
|
29
27
|
if (options.assigneeId !== undefined && linearApiKey === undefined) {
|
|
30
28
|
throw new ConfigurationError("A Linear API key is required to select a publication assignee.");
|
|
31
29
|
}
|
|
@@ -52,12 +50,10 @@ export async function publishScanInternal(scanDirectory, options, dependencies =
|
|
|
52
50
|
options.signal?.throwIfAborted();
|
|
53
51
|
const linearClient = linearApiKey === undefined
|
|
54
52
|
? undefined
|
|
55
|
-
: (
|
|
56
|
-
((configuration) => new LinearClient(configuration)))({
|
|
53
|
+
: createLinearClient({
|
|
57
54
|
apiKey: linearApiKey,
|
|
58
|
-
redirect: "error",
|
|
59
55
|
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
60
|
-
});
|
|
56
|
+
}, dependencies.linearClient);
|
|
61
57
|
let assigneeId = options.assigneeId;
|
|
62
58
|
if (linearClient !== undefined && assigneeId?.includes("@")) {
|
|
63
59
|
const users = await linearClient.users({
|