@openai/codex-security 0.1.12 → 0.1.13
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 +145 -16
- package/_bundled_plugin/scripts/workbench_cli.py +4 -0
- package/_bundled_plugin/scripts/workbench_db.py +258 -0
- package/_bundled_plugin/scripts/workbench_scan_usage.py +26 -0
- package/_bundled_plugin/scripts/workbench_schema.py +40 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +16 -3
- package/dist/api.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts +5 -1
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +24 -7
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +576 -18
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts +12 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +30 -2
- package/dist/contract.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/publication-events.d.ts +16 -0
- package/dist/publication-events.d.ts.map +1 -0
- package/dist/publication-events.js +141 -0
- package/dist/publication-events.js.map +1 -0
- package/dist/publication-store.d.ts +5 -0
- package/dist/publication-store.d.ts.map +1 -0
- package/dist/publication-store.js +102 -0
- package/dist/publication-store.js.map +1 -0
- package/dist/publication.d.ts +27 -0
- package/dist/publication.d.ts.map +1 -0
- package/dist/publication.js +207 -0
- package/dist/publication.js.map +1 -0
- package/dist/publish.d.ts +77 -0
- package/dist/publish.d.ts.map +1 -0
- package/dist/publish.js +748 -0
- package/dist/publish.js.map +1 -0
- package/dist/scan-dashboard.d.ts +2 -0
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +25 -8
- package/dist/scan-dashboard.js.map +1 -1
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -7,6 +7,7 @@ import { cwd } from "node:process";
|
|
|
7
7
|
import { createInterface } from "node:readline";
|
|
8
8
|
import { Readable, Writable as NodeWritable } from "node:stream";
|
|
9
9
|
import { pipeline } from "node:stream/promises";
|
|
10
|
+
import { stripVTControlCharacters } from "node:util";
|
|
10
11
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
11
12
|
import { Cli, z } from "incur";
|
|
12
13
|
import { parse as parseToml } from "smol-toml";
|
|
@@ -17,8 +18,10 @@ import { DEFAULT_CODEX_CONFIG, EXTERNAL_CODEX_PROVIDERS, isExternalModelProvider
|
|
|
17
18
|
import { formatUsd } from "./cost.js";
|
|
18
19
|
import { CodexSecurityError, ConfigurationError, InvalidTargetError, OutputDirectoryError, OutputInsideProtectedRootError, PluginPythonUnavailableError, errorMessage, safeErrorMessage, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
19
20
|
import { runMultiscan } from "./multiscan.js";
|
|
21
|
+
import { publishScan, } from "./publish.js";
|
|
20
22
|
import { bundledPluginRoot, codexSecurityCredentialHome, codexSecurityStateDirectory, expandHome, prepareCodexSecurityCredentialHome, resolveCodexCommand, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, } from "./runtime.js";
|
|
21
23
|
import { matchScanFindingsInternal, } from "./scan-comparison.js";
|
|
24
|
+
import { scanActivitiesFromEvent } from "./scan-activity.js";
|
|
22
25
|
import { readScanLogs } from "./scan-logs.js";
|
|
23
26
|
import { renderScanHistory, } from "./scan-history-renderer.js";
|
|
24
27
|
import { ScanDashboard } from "./scan-dashboard.js";
|
|
@@ -31,6 +34,9 @@ const SCAN_HISTORY_OUTPUT_OPTION = /^--(?:format|filter-output|full-output|token
|
|
|
31
34
|
const HIDE_CURSOR = "\u001B[?25l";
|
|
32
35
|
const SHOW_CURSOR = "\u001B[?25h";
|
|
33
36
|
const CHILD_TERMINATION_GRACE_MS = 1_000;
|
|
37
|
+
const PUBLICATION_GRAPHEME_SEGMENTER = new Intl.Segmenter(undefined, {
|
|
38
|
+
granularity: "grapheme",
|
|
39
|
+
});
|
|
34
40
|
const REPORTABLE_SEVERITIES = [
|
|
35
41
|
"critical",
|
|
36
42
|
"high",
|
|
@@ -92,6 +98,11 @@ const VALUE_OPTIONS = new Set([
|
|
|
92
98
|
"--token-offset",
|
|
93
99
|
"--scan-root",
|
|
94
100
|
"--reason",
|
|
101
|
+
"--to",
|
|
102
|
+
"--linear-team",
|
|
103
|
+
"--linear-api-key",
|
|
104
|
+
"--project",
|
|
105
|
+
"--linear-assignee",
|
|
95
106
|
]);
|
|
96
107
|
const PROVIDER_OPTION = z
|
|
97
108
|
.enum(["openai", "openrouter", "fireworks", "amazon-bedrock"])
|
|
@@ -100,6 +111,225 @@ const PROVIDER_OPTION = z
|
|
|
100
111
|
function optionValue(flag) {
|
|
101
112
|
return z.string().min(1, `${flag} must not be empty.`);
|
|
102
113
|
}
|
|
114
|
+
function publicationScanAge(timestamp, now) {
|
|
115
|
+
const completedAt = Date.parse(timestamp);
|
|
116
|
+
if (!Number.isFinite(completedAt))
|
|
117
|
+
return "unknown";
|
|
118
|
+
const elapsed = Math.max(0, now - completedAt);
|
|
119
|
+
const units = [
|
|
120
|
+
["year", 365 * 24 * 60 * 60 * 1_000],
|
|
121
|
+
["month", 30 * 24 * 60 * 60 * 1_000],
|
|
122
|
+
["week", 7 * 24 * 60 * 60 * 1_000],
|
|
123
|
+
["day", 24 * 60 * 60 * 1_000],
|
|
124
|
+
["hour", 60 * 60 * 1_000],
|
|
125
|
+
["minute", 60 * 1_000],
|
|
126
|
+
["second", 1_000],
|
|
127
|
+
];
|
|
128
|
+
for (const [unit, duration] of units) {
|
|
129
|
+
const count = Math.floor(elapsed / duration);
|
|
130
|
+
if (count > 0) {
|
|
131
|
+
return `${count} ${unit}${count === 1 ? "" : "s"} ago`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return "just now";
|
|
135
|
+
}
|
|
136
|
+
function publicationDisplayWidth(value) {
|
|
137
|
+
const segments = PUBLICATION_GRAPHEME_SEGMENTER.segment(stripVTControlCharacters(value));
|
|
138
|
+
let width = 0;
|
|
139
|
+
for (const { segment } of segments) {
|
|
140
|
+
if (/^[\p{Mark}\p{Cf}]+$/u.test(segment))
|
|
141
|
+
continue;
|
|
142
|
+
width +=
|
|
143
|
+
/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Emoji_Presentation}\p{Regional_Indicator}\u3000-\u303F\uFF01-\uFF60\uFFE0-\uFFE6\u20E3\uFE0F]/u.test(segment)
|
|
144
|
+
? 2
|
|
145
|
+
: 1;
|
|
146
|
+
}
|
|
147
|
+
return width;
|
|
148
|
+
}
|
|
149
|
+
function padPublicationColumn(value, width) {
|
|
150
|
+
return `${value}${" ".repeat(width - publicationDisplayWidth(value))}`;
|
|
151
|
+
}
|
|
152
|
+
function publicationIssueUrl(value) {
|
|
153
|
+
if (value === undefined ||
|
|
154
|
+
value !== value.trim() ||
|
|
155
|
+
value !== stripVTControlCharacters(value) ||
|
|
156
|
+
/[\u0000-\u001F\u007F-\u009F\u2028\u2029]/u.test(value) ||
|
|
157
|
+
safeErrorMessage(value) !== value) {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
let url;
|
|
161
|
+
try {
|
|
162
|
+
url = new URL(value);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
if (url.protocol !== "https:" ||
|
|
168
|
+
(url.hostname !== "linear.app" && !url.hostname.endsWith(".linear.app")) ||
|
|
169
|
+
url.username.length > 0 ||
|
|
170
|
+
url.password.length > 0 ||
|
|
171
|
+
url.search.length > 0 ||
|
|
172
|
+
url.hash.length > 0) {
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
function renderPublicationSummary(result, color) {
|
|
178
|
+
const created = result.created.length;
|
|
179
|
+
const failed = result.failed.length;
|
|
180
|
+
const marker = failed === 0 ? "✓" : "!";
|
|
181
|
+
const title = failed === 0
|
|
182
|
+
? "Linear publication complete"
|
|
183
|
+
: "Linear publication completed with failures";
|
|
184
|
+
const heading = color
|
|
185
|
+
? `\u001B[${failed === 0 ? "32" : "33"}m${marker}\u001B[39m \u001B[1m${title}\u001B[22m`
|
|
186
|
+
: `${marker} ${title}`;
|
|
187
|
+
const lines = [heading, ""];
|
|
188
|
+
for (const issue of result.created.slice(0, 5)) {
|
|
189
|
+
const identifier = stripVTControlCharacters(safeErrorMessage(issue.issueIdentifier))
|
|
190
|
+
.replaceAll(/[\u0000-\u001F\u007F-\u009F\u2028\u2029]/gu, " ")
|
|
191
|
+
.replace(/\s+/gu, " ")
|
|
192
|
+
.trim() || "Unknown Linear issue";
|
|
193
|
+
const url = publicationIssueUrl(issue.url);
|
|
194
|
+
lines.push(` ${identifier}${url === undefined ? "" : ` ${url}`}`);
|
|
195
|
+
}
|
|
196
|
+
if (created > 5)
|
|
197
|
+
lines.push(" ...");
|
|
198
|
+
if (created > 0)
|
|
199
|
+
lines.push("");
|
|
200
|
+
lines.push(`${created} total issue${created === 1 ? "" : "s"} created`, `${failed} total issue${failed === 1 ? "" : "s"} failed`);
|
|
201
|
+
return `${lines.join("\n")}\n`;
|
|
202
|
+
}
|
|
203
|
+
class PublicationProgressPresenter {
|
|
204
|
+
#stream;
|
|
205
|
+
#dependencies;
|
|
206
|
+
#repository;
|
|
207
|
+
#seenActivities = new Set();
|
|
208
|
+
#dashboard = null;
|
|
209
|
+
constructor(stream, dependencies, repository) {
|
|
210
|
+
this.#stream = stream;
|
|
211
|
+
this.#dependencies = dependencies;
|
|
212
|
+
this.#repository = repository;
|
|
213
|
+
}
|
|
214
|
+
start() {
|
|
215
|
+
if (this.#stream.isTTY !== true ||
|
|
216
|
+
this.#dependencies.environment["CI"] !== undefined ||
|
|
217
|
+
this.#dependencies.environment["TERM"] === "dumb") {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const dashboard = new ScanDashboard(this.#stream, {
|
|
221
|
+
repository: this.#repository,
|
|
222
|
+
presentation: "publication",
|
|
223
|
+
clock: this.#dependencies,
|
|
224
|
+
color: this.#dependencies.environment["NO_COLOR"] === undefined,
|
|
225
|
+
sanitize: safeErrorMessage,
|
|
226
|
+
});
|
|
227
|
+
dashboard.setStage("Connecting to Linear");
|
|
228
|
+
try {
|
|
229
|
+
dashboard.start();
|
|
230
|
+
this.#dashboard = dashboard;
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
try {
|
|
234
|
+
dashboard.stop();
|
|
235
|
+
}
|
|
236
|
+
catch { }
|
|
237
|
+
this.#dashboard = null;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
stop() {
|
|
241
|
+
try {
|
|
242
|
+
this.#dashboard?.stop();
|
|
243
|
+
}
|
|
244
|
+
catch { }
|
|
245
|
+
this.#dashboard = null;
|
|
246
|
+
}
|
|
247
|
+
observe(event) {
|
|
248
|
+
if (event.type === "started") {
|
|
249
|
+
if (this.#dashboard !== null) {
|
|
250
|
+
this.#dashboard.setPublicationProgress(0, event.total);
|
|
251
|
+
this.#dashboard.setStage(`Publishing findings · 0/${event.total}`);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
this.#write(`Publishing ${event.total} finding${event.total === 1 ? "" : "s"} to Linear.`);
|
|
255
|
+
}
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (event.type === "codex_event") {
|
|
259
|
+
if (typeof event.event !== "object" ||
|
|
260
|
+
event.event === null ||
|
|
261
|
+
Array.isArray(event.event)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
for (const activity of scanActivitiesFromEvent(event.event, this.#repository)) {
|
|
265
|
+
const item = event.event["item"];
|
|
266
|
+
const tool = typeof item === "object" && item !== null && !Array.isArray(item)
|
|
267
|
+
? item["tool"]
|
|
268
|
+
: undefined;
|
|
269
|
+
const hidesShellCommand = activity.kind === "command" ||
|
|
270
|
+
(activity.kind === "tool" &&
|
|
271
|
+
typeof tool === "string" &&
|
|
272
|
+
/^(?:exec|exec_command|shell_command|shell|apply_patch)$/u.test(tool));
|
|
273
|
+
const visibleActivity = hidesShellCommand
|
|
274
|
+
? {
|
|
275
|
+
...activity,
|
|
276
|
+
description: "Saving Linear publication results",
|
|
277
|
+
paths: [],
|
|
278
|
+
}
|
|
279
|
+
: activity;
|
|
280
|
+
if (this.#dashboard !== null) {
|
|
281
|
+
this.#dashboard.record(visibleActivity);
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
const key = `${visibleActivity.id}\0${visibleActivity.description}`;
|
|
285
|
+
if (this.#seenActivities.has(key))
|
|
286
|
+
continue;
|
|
287
|
+
this.#seenActivities.add(key);
|
|
288
|
+
const label = visibleActivity.kind === "reasoning"
|
|
289
|
+
? "Codex"
|
|
290
|
+
: visibleActivity.kind === "message"
|
|
291
|
+
? "Codex"
|
|
292
|
+
: "Tool";
|
|
293
|
+
this.#write(`${label}: ${visibleActivity.description}`, true);
|
|
294
|
+
}
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (event.type === "issue_completed") {
|
|
298
|
+
const detail = event.error === undefined
|
|
299
|
+
? `Created ${event.issueIdentifier ?? event.findingId}`
|
|
300
|
+
: `Failed ${event.findingId}: ${event.error}`;
|
|
301
|
+
if (this.#dashboard !== null) {
|
|
302
|
+
this.#dashboard.setPublicationProgress(event.completed, event.total);
|
|
303
|
+
this.#dashboard.setStage(`Publishing findings · ${event.completed}/${event.total}`);
|
|
304
|
+
this.#dashboard.note(detail);
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
this.#write(`[${event.completed}/${event.total}] ${detail}`, true);
|
|
308
|
+
}
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const summary = `Published ${event.created}/${event.total} finding${event.total === 1 ? "" : "s"}${event.failed === 0 ? "" : ` (${event.failed} failed)`}.`;
|
|
312
|
+
if (this.#dashboard !== null) {
|
|
313
|
+
this.#dashboard.setPublicationProgress(event.created + event.failed, event.total);
|
|
314
|
+
this.#dashboard.setStage(summary);
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
this.#write(summary);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
#write(message, compact = false) {
|
|
321
|
+
const sanitized = diagnosticValue(safeErrorMessage(message));
|
|
322
|
+
if (!compact) {
|
|
323
|
+
this.#stream.write(`${sanitized}\n`);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const width = Math.max(24, Math.min(this.#stream.columns ?? 120, 160));
|
|
327
|
+
const visible = sanitized.length <= width
|
|
328
|
+
? sanitized
|
|
329
|
+
: `${sanitized.slice(0, width - 1)}…`;
|
|
330
|
+
this.#stream.write(`${visible}\n`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
103
333
|
function effortOption() {
|
|
104
334
|
return z
|
|
105
335
|
.enum(MODEL_REASONING_EFFORTS, {
|
|
@@ -458,7 +688,7 @@ export function exportEnvironment(environment = process.env) {
|
|
|
458
688
|
.map((key) => [key, environment[key]]));
|
|
459
689
|
}
|
|
460
690
|
export async function main(argv = process.argv.slice(2), output = process.stdout, errorOutput = process.stderr, dependencies = DEFAULT_DEPENDENCIES) {
|
|
461
|
-
argv =
|
|
691
|
+
argv = defaultListCommand(argv);
|
|
462
692
|
const positionals = [];
|
|
463
693
|
const argumentError = validateCliArguments(argv, positionals);
|
|
464
694
|
if (argumentError !== undefined) {
|
|
@@ -487,6 +717,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
487
717
|
let frameworkExit;
|
|
488
718
|
let frameworkOutput = "";
|
|
489
719
|
let renderedHistory;
|
|
720
|
+
let renderedPublication;
|
|
490
721
|
const history = async (args, select = (value) => value) => {
|
|
491
722
|
try {
|
|
492
723
|
return await select(await dependencies.runWorkbench(args));
|
|
@@ -497,6 +728,25 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
497
728
|
return undefined;
|
|
498
729
|
}
|
|
499
730
|
};
|
|
731
|
+
const latestScans = async (count = 1, status = "complete") => {
|
|
732
|
+
const result = await history([
|
|
733
|
+
"list-scans",
|
|
734
|
+
"--repository",
|
|
735
|
+
dependencies.currentDirectory(),
|
|
736
|
+
...(status === "complete" ? ["--status", "complete"] : []),
|
|
737
|
+
"--limit",
|
|
738
|
+
String(count),
|
|
739
|
+
], (value) => {
|
|
740
|
+
if (value["scans"].length < count) {
|
|
741
|
+
const kind = status === "complete" ? "completed" : "saved";
|
|
742
|
+
throw new CodexSecurityError(count === 1
|
|
743
|
+
? `No ${kind} scans found for the current repository.`
|
|
744
|
+
: `At least ${count} ${kind} scans are required for the current repository.`);
|
|
745
|
+
}
|
|
746
|
+
return value;
|
|
747
|
+
});
|
|
748
|
+
return result?.["scans"];
|
|
749
|
+
};
|
|
500
750
|
const matchScanPair = async (beforeId, afterId, force = false) => history([
|
|
501
751
|
"compare-scans",
|
|
502
752
|
"--before-scan-id",
|
|
@@ -638,7 +888,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
638
888
|
scanId: z
|
|
639
889
|
.string()
|
|
640
890
|
.min(1)
|
|
641
|
-
.
|
|
891
|
+
.optional()
|
|
892
|
+
.describe("Scan ID or unique prefix (default: latest completed)."),
|
|
642
893
|
}),
|
|
643
894
|
options: z.object({
|
|
644
895
|
showLinkedFindings: z
|
|
@@ -648,7 +899,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
648
899
|
}),
|
|
649
900
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
650
901
|
async run({ args, format, options }) {
|
|
651
|
-
|
|
902
|
+
const scanId = args.scanId ?? (await latestScans())?.[0]?.scanId;
|
|
903
|
+
if (scanId === undefined)
|
|
904
|
+
return;
|
|
905
|
+
return presentHistory(await history(["get-scan", "--scan-id", scanId], (value) => {
|
|
652
906
|
const { scan, recipe, parentScanId } = value;
|
|
653
907
|
return {
|
|
654
908
|
...scan,
|
|
@@ -665,11 +919,15 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
665
919
|
scanId: z
|
|
666
920
|
.string()
|
|
667
921
|
.min(1)
|
|
668
|
-
.
|
|
922
|
+
.optional()
|
|
923
|
+
.describe("Scan identifier or unique prefix (default: latest)."),
|
|
669
924
|
}),
|
|
670
925
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
671
926
|
async run({ args }) {
|
|
672
|
-
|
|
927
|
+
const scanId = args.scanId ?? (await latestScans(1, "any"))?.[0]?.scanId;
|
|
928
|
+
if (scanId === undefined)
|
|
929
|
+
return;
|
|
930
|
+
return await history(["get-scan", "--scan-id", scanId], async (value) => {
|
|
673
931
|
const scan = value["scan"];
|
|
674
932
|
const threadId = scan.continuationThreadId;
|
|
675
933
|
if (!threadId) {
|
|
@@ -696,7 +954,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
696
954
|
destructive: true,
|
|
697
955
|
mcp: false,
|
|
698
956
|
args: z.object({
|
|
699
|
-
scanId: z
|
|
957
|
+
scanId: z
|
|
958
|
+
.string()
|
|
959
|
+
.min(1)
|
|
960
|
+
.optional()
|
|
961
|
+
.describe("Saved scan identifier (default: latest completed scan)."),
|
|
700
962
|
}),
|
|
701
963
|
options: z.object({
|
|
702
964
|
verbose: z
|
|
@@ -706,14 +968,17 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
706
968
|
}),
|
|
707
969
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
708
970
|
async run({ args, error: incurError, options }) {
|
|
971
|
+
const scanId = args.scanId ?? (await latestScans())?.[0]?.scanId;
|
|
972
|
+
if (scanId === undefined)
|
|
973
|
+
return;
|
|
709
974
|
let scanArguments;
|
|
710
975
|
try {
|
|
711
976
|
const { recipe } = await dependencies.runWorkbench([
|
|
712
977
|
"get-scan-recipe",
|
|
713
978
|
"--scan-id",
|
|
714
|
-
|
|
979
|
+
scanId,
|
|
715
980
|
]);
|
|
716
|
-
scanArguments = scanArgumentsFromRecipe(recipe,
|
|
981
|
+
scanArguments = scanArgumentsFromRecipe(recipe, scanId);
|
|
717
982
|
scanArguments.verbose = options.verbose;
|
|
718
983
|
}
|
|
719
984
|
catch (error) {
|
|
@@ -784,16 +1049,303 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
784
1049
|
destructive: true,
|
|
785
1050
|
mcp: false,
|
|
786
1051
|
args: z.object({
|
|
787
|
-
beforeId: z
|
|
788
|
-
|
|
1052
|
+
beforeId: z
|
|
1053
|
+
.string()
|
|
1054
|
+
.min(1)
|
|
1055
|
+
.optional()
|
|
1056
|
+
.describe("Earlier saved scan identifier."),
|
|
1057
|
+
afterId: z
|
|
1058
|
+
.string()
|
|
1059
|
+
.min(1)
|
|
1060
|
+
.optional()
|
|
1061
|
+
.describe("Later saved scan identifier (default: latest completed)."),
|
|
789
1062
|
}),
|
|
790
1063
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
791
1064
|
async run({ args, format }) {
|
|
792
|
-
|
|
1065
|
+
let { beforeId, afterId } = args;
|
|
1066
|
+
if (beforeId === undefined) {
|
|
1067
|
+
const scans = await latestScans(2);
|
|
1068
|
+
if (scans === undefined)
|
|
1069
|
+
return;
|
|
1070
|
+
beforeId = scans[1].scanId;
|
|
1071
|
+
afterId = scans[0].scanId;
|
|
1072
|
+
}
|
|
1073
|
+
else if (afterId === undefined) {
|
|
1074
|
+
afterId = (await latestScans())?.[0]?.scanId;
|
|
1075
|
+
if (afterId === undefined)
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
return presentHistory(await matchScanPair(beforeId, afterId), "compare", format);
|
|
1079
|
+
},
|
|
1080
|
+
});
|
|
1081
|
+
const publication = Cli.create("publish", {
|
|
1082
|
+
description: "Publish completed Codex Security scan findings.",
|
|
1083
|
+
}).command("scan", {
|
|
1084
|
+
description: "Publish every finding from a completed scan to Linear.",
|
|
1085
|
+
destructive: true,
|
|
1086
|
+
mcp: false,
|
|
1087
|
+
args: z.object({
|
|
1088
|
+
scanDir: z
|
|
1089
|
+
.string()
|
|
1090
|
+
.optional()
|
|
1091
|
+
.describe("Completed scan directory; omit to select a saved scan."),
|
|
1092
|
+
}),
|
|
1093
|
+
options: z.object({
|
|
1094
|
+
to: z.literal("linear").describe("Publication destination."),
|
|
1095
|
+
linearTeam: optionValue("--linear-team")
|
|
1096
|
+
.optional()
|
|
1097
|
+
.describe("Linear team ID; defaults to CODEX_SECURITY_LINEAR_TEAM."),
|
|
1098
|
+
linearApiKey: optionValue("--linear-api-key")
|
|
1099
|
+
.optional()
|
|
1100
|
+
.describe("Linear personal API key; defaults to CODEX_SECURITY_LINEAR_API_KEY."),
|
|
1101
|
+
project: optionValue("--project")
|
|
1102
|
+
.optional()
|
|
1103
|
+
.describe("Optional Linear project ID; defaults to CODEX_SECURITY_LINEAR_PROJECT."),
|
|
1104
|
+
linearAssignee: optionValue("--linear-assignee")
|
|
1105
|
+
.optional()
|
|
1106
|
+
.describe("Linear assignee email or user ID; omit to leave issues unassigned."),
|
|
1107
|
+
dryRun: z
|
|
1108
|
+
.boolean()
|
|
1109
|
+
.default(false)
|
|
1110
|
+
.describe("Preview the findings without creating Linear issues."),
|
|
1111
|
+
}),
|
|
1112
|
+
output: z.record(z.string(), z.unknown()).optional(),
|
|
1113
|
+
async run({ args, format, formatExplicit, options }) {
|
|
1114
|
+
const controller = new AbortController();
|
|
1115
|
+
let presentation;
|
|
1116
|
+
const cancel = (signal) => {
|
|
1117
|
+
presentation?.stop();
|
|
1118
|
+
controller.abort(signal);
|
|
1119
|
+
};
|
|
1120
|
+
const onInterrupt = () => cancel("SIGINT");
|
|
1121
|
+
const onTerminate = () => cancel("SIGTERM");
|
|
1122
|
+
let observingSignals = false;
|
|
1123
|
+
try {
|
|
1124
|
+
const selectedApiKey = options.linearApiKey ??
|
|
1125
|
+
dependencies.environment["CODEX_SECURITY_LINEAR_API_KEY"];
|
|
1126
|
+
const linearApiKey = selectedApiKey?.trim() || undefined;
|
|
1127
|
+
if (options.linearApiKey !== undefined && linearApiKey === undefined) {
|
|
1128
|
+
throw new CodexSecurityError("--linear-api-key must not be empty.");
|
|
1129
|
+
}
|
|
1130
|
+
const assigneeId = options.linearAssignee?.trim();
|
|
1131
|
+
if (options.linearAssignee !== undefined && !assigneeId) {
|
|
1132
|
+
throw new CodexSecurityError("--linear-assignee must not be empty.");
|
|
1133
|
+
}
|
|
1134
|
+
if (assigneeId !== undefined && linearApiKey === undefined) {
|
|
1135
|
+
throw new CodexSecurityError("--linear-assignee requires --linear-api-key or CODEX_SECURITY_LINEAR_API_KEY.");
|
|
1136
|
+
}
|
|
1137
|
+
const teamId = options.linearTeam?.trim() ||
|
|
1138
|
+
dependencies.environment["CODEX_SECURITY_LINEAR_TEAM"]?.trim();
|
|
1139
|
+
if (!teamId) {
|
|
1140
|
+
throw new CodexSecurityError("--linear-team or CODEX_SECURITY_LINEAR_TEAM is required.");
|
|
1141
|
+
}
|
|
1142
|
+
const selectedProject = options.project?.trim();
|
|
1143
|
+
if (options.project !== undefined && !selectedProject) {
|
|
1144
|
+
throw new CodexSecurityError("--project must not be empty.");
|
|
1145
|
+
}
|
|
1146
|
+
const projectId = selectedProject ||
|
|
1147
|
+
dependencies.environment["CODEX_SECURITY_LINEAR_PROJECT"]?.trim() ||
|
|
1148
|
+
undefined;
|
|
1149
|
+
let scanDir = args.scanDir;
|
|
1150
|
+
let publicationRepository = scanDir === undefined ? "scan" : basename(scanDir);
|
|
1151
|
+
if (scanDir === undefined) {
|
|
1152
|
+
const prompt = dependencies.publishPrompt ??
|
|
1153
|
+
createBulkScanDiscoveryDependencies({
|
|
1154
|
+
output: errorOutput,
|
|
1155
|
+
now: dependencies.now,
|
|
1156
|
+
currentDirectory: dependencies.currentDirectory,
|
|
1157
|
+
}).prompt;
|
|
1158
|
+
if (!prompt.isInteractive()) {
|
|
1159
|
+
throw new CodexSecurityError("Interactive scan selection requires a terminal. Provide a completed scan directory: codex-security publish scan /path/to/sealed-scan --to linear --linear-team TEAM_ID.");
|
|
1160
|
+
}
|
|
1161
|
+
const saved = await dependencies.runWorkbench([
|
|
1162
|
+
"list-scans",
|
|
1163
|
+
"--status",
|
|
1164
|
+
"complete",
|
|
1165
|
+
]);
|
|
1166
|
+
const listedScans = saved["scans"];
|
|
1167
|
+
if (!Array.isArray(listedScans)) {
|
|
1168
|
+
throw new CodexSecurityError("Could not read completed Codex Security scans.");
|
|
1169
|
+
}
|
|
1170
|
+
const scans = (await Promise.all(listedScans.map(async (scan) => {
|
|
1171
|
+
if (!isJsonObject(scan))
|
|
1172
|
+
return undefined;
|
|
1173
|
+
const directory = scan["scanDir"];
|
|
1174
|
+
if (typeof directory !== "string" || directory.length === 0) {
|
|
1175
|
+
return undefined;
|
|
1176
|
+
}
|
|
1177
|
+
const metadata = await lstat(resolve(dependencies.currentDirectory(), directory)).catch(() => undefined);
|
|
1178
|
+
return metadata?.isDirectory() === true &&
|
|
1179
|
+
!metadata.isSymbolicLink()
|
|
1180
|
+
? scan
|
|
1181
|
+
: undefined;
|
|
1182
|
+
}))).filter((scan) => scan !== undefined);
|
|
1183
|
+
const now = dependencies.now();
|
|
1184
|
+
const emphasizeRepository = errorOutput.isTTY === true &&
|
|
1185
|
+
dependencies.environment["NO_COLOR"] === undefined &&
|
|
1186
|
+
dependencies.environment["TERM"] !== "dumb";
|
|
1187
|
+
const repositories = new Map();
|
|
1188
|
+
const rows = scans.flatMap((scan) => {
|
|
1189
|
+
if (!isJsonObject(scan))
|
|
1190
|
+
return [];
|
|
1191
|
+
const progress = scan["progress"];
|
|
1192
|
+
const scanId = scan["scanId"];
|
|
1193
|
+
const directory = scan["scanDir"];
|
|
1194
|
+
if (typeof scanId !== "string" ||
|
|
1195
|
+
scanId.length === 0 ||
|
|
1196
|
+
typeof directory !== "string" ||
|
|
1197
|
+
directory.length === 0 ||
|
|
1198
|
+
progress === undefined ||
|
|
1199
|
+
!isJsonObject(progress) ||
|
|
1200
|
+
progress["status"] !== "complete") {
|
|
1201
|
+
return [];
|
|
1202
|
+
}
|
|
1203
|
+
const targetSummary = scan["targetSummary"];
|
|
1204
|
+
const targetPath = scan["targetPath"];
|
|
1205
|
+
const repository = stripVTControlCharacters(typeof targetSummary === "string" && targetSummary.trim()
|
|
1206
|
+
? targetSummary.trim()
|
|
1207
|
+
: typeof targetPath === "string" && targetPath.trim()
|
|
1208
|
+
? basename(targetPath)
|
|
1209
|
+
: "unknown repository")
|
|
1210
|
+
.replaceAll(/[\u0000-\u001F\u007F-\u009F]/gu, " ")
|
|
1211
|
+
.replace(/\s+/gu, " ")
|
|
1212
|
+
.trim();
|
|
1213
|
+
const completedAt = scan["completedAt"];
|
|
1214
|
+
const startedAt = scan["startedAt"];
|
|
1215
|
+
const updatedAt = scan["updatedAt"];
|
|
1216
|
+
const timestamp = typeof completedAt === "string" && completedAt
|
|
1217
|
+
? completedAt
|
|
1218
|
+
: typeof startedAt === "string" && startedAt
|
|
1219
|
+
? startedAt
|
|
1220
|
+
: typeof updatedAt === "string" && updatedAt
|
|
1221
|
+
? updatedAt
|
|
1222
|
+
: "unknown date";
|
|
1223
|
+
const findingCount = scan["findingCount"];
|
|
1224
|
+
const findings = typeof findingCount === "number"
|
|
1225
|
+
? `${findingCount} finding${findingCount === 1 ? "" : "s"}`
|
|
1226
|
+
: "unknown findings";
|
|
1227
|
+
const shortScanId = `...${stripVTControlCharacters(scanId)
|
|
1228
|
+
.replaceAll(/[\u0000-\u001F\u007F-\u009F]/gu, " ")
|
|
1229
|
+
.replace(/\s+/gu, " ")
|
|
1230
|
+
.slice(-6)}`;
|
|
1231
|
+
repositories.set(directory, repository);
|
|
1232
|
+
return [
|
|
1233
|
+
{
|
|
1234
|
+
repository,
|
|
1235
|
+
findings,
|
|
1236
|
+
age: publicationScanAge(timestamp, now),
|
|
1237
|
+
scanId: shortScanId,
|
|
1238
|
+
value: directory,
|
|
1239
|
+
},
|
|
1240
|
+
];
|
|
1241
|
+
});
|
|
1242
|
+
if (rows.length === 0) {
|
|
1243
|
+
throw new CodexSecurityError("No completed Codex Security scans are available to publish.");
|
|
1244
|
+
}
|
|
1245
|
+
const repositoryWidth = Math.max(publicationDisplayWidth("REPOSITORY"), ...rows.map(({ repository }) => publicationDisplayWidth(repository)));
|
|
1246
|
+
const findingsWidth = Math.max(publicationDisplayWidth("FINDINGS"), ...rows.map(({ findings }) => publicationDisplayWidth(findings)));
|
|
1247
|
+
const ageWidth = Math.max(publicationDisplayWidth("AGE"), ...rows.map(({ age }) => publicationDisplayWidth(age)));
|
|
1248
|
+
const header = [
|
|
1249
|
+
padPublicationColumn("REPOSITORY", repositoryWidth),
|
|
1250
|
+
padPublicationColumn("FINDINGS", findingsWidth),
|
|
1251
|
+
padPublicationColumn("AGE", ageWidth),
|
|
1252
|
+
"SCAN ID",
|
|
1253
|
+
].join(" ");
|
|
1254
|
+
const choices = rows.map((row) => {
|
|
1255
|
+
const repository = emphasizeRepository
|
|
1256
|
+
? `\u001B[1m${row.repository}\u001B[22m`
|
|
1257
|
+
: row.repository;
|
|
1258
|
+
return {
|
|
1259
|
+
label: [
|
|
1260
|
+
padPublicationColumn(repository, repositoryWidth),
|
|
1261
|
+
padPublicationColumn(row.findings, findingsWidth),
|
|
1262
|
+
padPublicationColumn(row.age, ageWidth),
|
|
1263
|
+
row.scanId,
|
|
1264
|
+
].join(" "),
|
|
1265
|
+
short: `${repository} · ${row.scanId}`,
|
|
1266
|
+
value: row.value,
|
|
1267
|
+
};
|
|
1268
|
+
});
|
|
1269
|
+
scanDir = await prompt.select("Which completed scan would you like to publish?", choices, { header });
|
|
1270
|
+
publicationRepository =
|
|
1271
|
+
repositories.get(scanDir) ?? basename(scanDir);
|
|
1272
|
+
}
|
|
1273
|
+
const progress = new PublicationProgressPresenter(errorOutput, dependencies, publicationRepository);
|
|
1274
|
+
presentation = progress;
|
|
1275
|
+
if (!options.dryRun) {
|
|
1276
|
+
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
1277
|
+
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
1278
|
+
observingSignals = true;
|
|
1279
|
+
progress.start();
|
|
1280
|
+
}
|
|
1281
|
+
let result;
|
|
1282
|
+
try {
|
|
1283
|
+
result = await (dependencies.publishScan ?? publishScan)(resolve(dependencies.currentDirectory(), scanDir), {
|
|
1284
|
+
destination: options.to,
|
|
1285
|
+
teamId,
|
|
1286
|
+
...(projectId === undefined ? {} : { projectId }),
|
|
1287
|
+
dryRun: options.dryRun,
|
|
1288
|
+
...(linearApiKey === undefined ? {} : { linearApiKey }),
|
|
1289
|
+
...(assigneeId === undefined ? {} : { assigneeId }),
|
|
1290
|
+
...(options.dryRun
|
|
1291
|
+
? {}
|
|
1292
|
+
: {
|
|
1293
|
+
signal: controller.signal,
|
|
1294
|
+
onProgress: (event) => progress.observe(event),
|
|
1295
|
+
}),
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
finally {
|
|
1299
|
+
progress.stop();
|
|
1300
|
+
}
|
|
1301
|
+
controller.signal.throwIfAborted();
|
|
1302
|
+
if (result.failed.length > 0)
|
|
1303
|
+
exitCode = 2;
|
|
1304
|
+
if ("warnings" in result && Array.isArray(result.warnings)) {
|
|
1305
|
+
for (const warning of result.warnings) {
|
|
1306
|
+
if (typeof warning !== "string")
|
|
1307
|
+
continue;
|
|
1308
|
+
errorOutput.write(`codex-security: ${diagnosticValue(safeErrorMessage(warning))}\n`);
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
if (format === "toon" &&
|
|
1312
|
+
!formatExplicit &&
|
|
1313
|
+
!options.dryRun &&
|
|
1314
|
+
!argv.some((argument) => SCAN_HISTORY_OUTPUT_OPTION.test(argument))) {
|
|
1315
|
+
renderedPublication = renderPublicationSummary(result, output.isTTY === true &&
|
|
1316
|
+
dependencies.environment["NO_COLOR"] === undefined &&
|
|
1317
|
+
dependencies.environment["TERM"] !== "dumb");
|
|
1318
|
+
}
|
|
1319
|
+
return { ...result };
|
|
1320
|
+
}
|
|
1321
|
+
catch (error) {
|
|
1322
|
+
const signal = controller.signal.reason;
|
|
1323
|
+
if (signal === "SIGINT" || signal === "SIGTERM") {
|
|
1324
|
+
const reason = signal === "SIGINT"
|
|
1325
|
+
? "Publication canceled by Ctrl-C."
|
|
1326
|
+
: "Publication terminated by SIGTERM.";
|
|
1327
|
+
const recovery = error === signal
|
|
1328
|
+
? ""
|
|
1329
|
+
: ` ${diagnosticValue(safeErrorMessage(error))}`;
|
|
1330
|
+
errorOutput.write(`codex-security: ${reason}${recovery}\n`);
|
|
1331
|
+
exitCode = signal === "SIGINT" ? 130 : 143;
|
|
1332
|
+
}
|
|
1333
|
+
else {
|
|
1334
|
+
errorOutput.write(`codex-security: ${errorMessage(error)}\n`);
|
|
1335
|
+
exitCode = 2;
|
|
1336
|
+
}
|
|
1337
|
+
return undefined;
|
|
1338
|
+
}
|
|
1339
|
+
finally {
|
|
1340
|
+
if (observingSignals) {
|
|
1341
|
+
dependencies.removeSignalListener("SIGINT", onInterrupt);
|
|
1342
|
+
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
793
1345
|
},
|
|
794
1346
|
});
|
|
795
1347
|
const cli = Cli.create("codex-security", {
|
|
796
|
-
description: "Run, validate, patch, and
|
|
1348
|
+
description: "Run, validate, patch, export, and publish Codex Security findings.",
|
|
797
1349
|
version: VERSION,
|
|
798
1350
|
mcp: {
|
|
799
1351
|
command: "npx --yes @openai/codex-security --mcp",
|
|
@@ -1048,6 +1600,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1048
1600
|
})
|
|
1049
1601
|
.command(scanHistory)
|
|
1050
1602
|
.command(findingFeedback)
|
|
1603
|
+
.command(publication)
|
|
1051
1604
|
.command("bulk-scan", {
|
|
1052
1605
|
description: "Discover repositories and run resumable bulk security scans.",
|
|
1053
1606
|
destructive: true,
|
|
@@ -1213,7 +1766,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1213
1766
|
args: z.object({
|
|
1214
1767
|
scanDir: z
|
|
1215
1768
|
.string()
|
|
1216
|
-
.
|
|
1769
|
+
.optional()
|
|
1770
|
+
.describe("Completed scan directory (default: latest completed)."),
|
|
1217
1771
|
}),
|
|
1218
1772
|
options: z
|
|
1219
1773
|
.object({
|
|
@@ -1237,8 +1791,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1237
1791
|
}),
|
|
1238
1792
|
async run({ args, options }) {
|
|
1239
1793
|
const currentDirectory = dependencies.currentDirectory();
|
|
1794
|
+
const scanDir = args.scanDir ?? (await latestScans())?.[0]?.scanDir;
|
|
1795
|
+
if (scanDir === undefined)
|
|
1796
|
+
return;
|
|
1240
1797
|
exitCode = await runExport({
|
|
1241
|
-
scanDir: resolve(currentDirectory,
|
|
1798
|
+
scanDir: resolve(currentDirectory, scanDir),
|
|
1242
1799
|
format: options.exportFormat,
|
|
1243
1800
|
output: options.output === "-"
|
|
1244
1801
|
? "-"
|
|
@@ -1462,7 +2019,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1462
2019
|
if (frameworkOutput.length === 0)
|
|
1463
2020
|
return exitCode;
|
|
1464
2021
|
try {
|
|
1465
|
-
await writeCliOutput(output, renderedHistory ?? frameworkOutput);
|
|
2022
|
+
await writeCliOutput(output, renderedPublication ?? renderedHistory ?? frameworkOutput);
|
|
1466
2023
|
return exitCode;
|
|
1467
2024
|
}
|
|
1468
2025
|
catch (error) {
|
|
@@ -1470,14 +2027,14 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1470
2027
|
return 2;
|
|
1471
2028
|
}
|
|
1472
2029
|
}
|
|
1473
|
-
function
|
|
2030
|
+
function defaultListCommand(argv) {
|
|
1474
2031
|
const commandIndex = argv.findIndex((value, index) => {
|
|
1475
2032
|
if (value.startsWith("-"))
|
|
1476
2033
|
return false;
|
|
1477
2034
|
return index === 0 || !VALUE_OPTIONS.has(argv[index - 1]);
|
|
1478
2035
|
});
|
|
1479
2036
|
if (commandIndex < 0 ||
|
|
1480
|
-
argv[commandIndex]
|
|
2037
|
+
!["scans", "findings"].includes(argv[commandIndex]) ||
|
|
1481
2038
|
argv.includes("--help") ||
|
|
1482
2039
|
argv.includes("-h")) {
|
|
1483
2040
|
return argv;
|
|
@@ -1594,6 +2151,7 @@ function validateCliArguments(argv, positionals) {
|
|
|
1594
2151
|
"scans",
|
|
1595
2152
|
"findings",
|
|
1596
2153
|
"export",
|
|
2154
|
+
"publish",
|
|
1597
2155
|
"validate",
|
|
1598
2156
|
"patch",
|
|
1599
2157
|
"login",
|
|
@@ -1633,7 +2191,7 @@ function validateCliArguments(argv, positionals) {
|
|
|
1633
2191
|
return "Markdown output is not supported for scan results.";
|
|
1634
2192
|
}
|
|
1635
2193
|
}
|
|
1636
|
-
const nestedCommand = command === "scans" || command === "findings";
|
|
2194
|
+
const nestedCommand = command === "scans" || command === "findings" || command === "publish";
|
|
1637
2195
|
const subcommand = nestedCommand ? argv[commandIndex + 1] : undefined;
|
|
1638
2196
|
if (command === "info") {
|
|
1639
2197
|
const metadataFields = new Set([
|