@openai/codex-security 0.1.11 → 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 +195 -49
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/.mcp.json +2 -0
- package/_bundled_plugin/examples/completed-scan/coverage.json +1 -1
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +2 -2
- 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/preflight/capability-profiles.toml +1 -34
- package/_bundled_plugin/references/config-preflight.md +11 -13
- package/_bundled_plugin/references/core-scan.md +94 -0
- package/_bundled_plugin/references/final-report.md +6 -6
- package/_bundled_plugin/references/scan-artifacts.md +15 -14
- package/_bundled_plugin/references/scan-prologue.md +27 -0
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +1 -106
- package/_bundled_plugin/scripts/config_preflight.py +40 -3
- package/_bundled_plugin/scripts/deep_scan_config.py +8 -5
- package/_bundled_plugin/scripts/deep_scan_workbench.py +103 -35
- package/_bundled_plugin/scripts/finalize_scan_contract.py +29 -17
- package/_bundled_plugin/scripts/finding_preview.py +122 -6
- package/_bundled_plugin/scripts/generate_in_scope_files.py +39 -17
- package/_bundled_plugin/scripts/generate_rank_input.py +21 -3
- package/_bundled_plugin/scripts/normalize_candidates.py +5 -5
- package/_bundled_plugin/scripts/report_projection.py +1 -19
- package/_bundled_plugin/scripts/workbench_cli.py +4 -0
- package/_bundled_plugin/scripts/workbench_db.py +280 -29
- package/_bundled_plugin/scripts/workbench_progress.py +0 -5
- package/_bundled_plugin/scripts/workbench_scan_usage.py +69 -8
- package/_bundled_plugin/scripts/workbench_schema.py +41 -20
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +8 -11
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +24 -110
- package/_bundled_plugin/skills/security-scan/SKILL.md +5 -88
- package/_bundled_plugin/skills/threat-model/SKILL.md +4 -2
- package/_bundled_plugin/skills/track-findings/SKILL.md +1 -1
- package/_bundled_plugin/skills/triage-finding/SKILL.md +5 -6
- package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +6 -7
- package/_bundled_plugin/skills/validation/SKILL.md +9 -12
- package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +3 -2
- package/_bundled_plugin/skills/vulnerability-writeup/references/report-format.md +1 -1
- package/dist/api.d.ts +1 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +195 -59
- 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 +38 -9
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/cli.d.ts +9 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +764 -60
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.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/cost.d.ts.map +1 -1
- package/dist/cost.js +10 -1
- package/dist/cost.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/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +10 -3
- package/dist/knowledge-base.js.map +1 -1
- package/dist/multiscan.d.ts +1 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +77 -18
- package/dist/multiscan.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/runtime.d.ts.map +1 -1
- package/dist/runtime.js +15 -44
- package/dist/runtime.js.map +1 -1
- package/dist/scan-dashboard.d.ts +7 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +86 -20
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-logs.d.ts +2 -0
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +97 -37
- package/dist/scan-logs.js.map +1 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +20 -11
- package/dist/targets.js.map +1 -1
- package/dist/trusted-executable.js +1 -1
- package/dist/trusted-executable.js.map +1 -1
- package/dist/version.d.ts +3 -3
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +6 -4
- package/dist/version.js.map +1 -1
- package/package.json +5 -4
- package/_bundled_plugin/references/shared-hard-rules.md +0 -15
- package/_bundled_plugin/scripts/validate_report_format.py +0 -138
- package/_bundled_plugin/skills/security-scan/references/repository-wide-scan.md +0 -33
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { execFileSync, spawn } from "node:child_process";
|
|
3
3
|
import { accessSync, constants, existsSync, lstatSync, realpathSync, writeSync, } from "node:fs";
|
|
4
|
-
import { mkdir, readFile, realpath,
|
|
4
|
+
import { lstat, mkdir, open, readFile, realpath, writeFile, } from "node:fs/promises";
|
|
5
5
|
import { basename, dirname, isAbsolute, join, parse, relative, resolve, sep, win32, } from "node:path";
|
|
6
6
|
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",
|
|
@@ -47,6 +53,7 @@ const MODEL_REASONING_EFFORTS = [
|
|
|
47
53
|
"medium",
|
|
48
54
|
"high",
|
|
49
55
|
"xhigh",
|
|
56
|
+
"max",
|
|
50
57
|
];
|
|
51
58
|
const DEFAULT_SCAN_MODEL_CONFIGURATION = scanModelConfiguration(DEFAULT_CODEX_CONFIG);
|
|
52
59
|
const CODEX_OVERRIDE_DESCRIPTION = 'Repeat TOML KEY=VALUE; e.g. model_reasoning_effort="high" or features.multi_agent_v2.max_concurrent_threads_per_session=4.';
|
|
@@ -91,6 +98,11 @@ const VALUE_OPTIONS = new Set([
|
|
|
91
98
|
"--token-offset",
|
|
92
99
|
"--scan-root",
|
|
93
100
|
"--reason",
|
|
101
|
+
"--to",
|
|
102
|
+
"--linear-team",
|
|
103
|
+
"--linear-api-key",
|
|
104
|
+
"--project",
|
|
105
|
+
"--linear-assignee",
|
|
94
106
|
]);
|
|
95
107
|
const PROVIDER_OPTION = z
|
|
96
108
|
.enum(["openai", "openrouter", "fireworks", "amazon-bedrock"])
|
|
@@ -99,10 +111,229 @@ const PROVIDER_OPTION = z
|
|
|
99
111
|
function optionValue(flag) {
|
|
100
112
|
return z.string().min(1, `${flag} must not be empty.`);
|
|
101
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
|
+
}
|
|
102
333
|
function effortOption() {
|
|
103
334
|
return z
|
|
104
335
|
.enum(MODEL_REASONING_EFFORTS, {
|
|
105
|
-
error: "--effort must be minimal, low, medium, high, or
|
|
336
|
+
error: "--effort must be minimal, low, medium, high, xhigh, or max.",
|
|
106
337
|
})
|
|
107
338
|
.optional()
|
|
108
339
|
.describe(`Model reasoning effort (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.reasoningEffort}).`);
|
|
@@ -139,25 +370,58 @@ const DEEP_SCAN_OPTION_SCHEMAS = {
|
|
|
139
370
|
.optional()
|
|
140
371
|
.describe("Maximum deep-scan discovery hours (default: 96; maximum: 96)."),
|
|
141
372
|
};
|
|
142
|
-
async function readPromptFiles(directory, scanPromptFile, postScanPromptFile) {
|
|
373
|
+
async function readPromptFiles(directory, scanPromptFile, postScanPromptFile, repository = directory) {
|
|
143
374
|
const [scanPrompt, postScanPrompt] = await Promise.all([
|
|
144
375
|
scanPromptFile === undefined
|
|
145
376
|
? undefined
|
|
146
|
-
:
|
|
377
|
+
: readRegularInputFile(resolve(directory, scanPromptFile), repository),
|
|
147
378
|
postScanPromptFile === undefined
|
|
148
379
|
? undefined
|
|
149
|
-
:
|
|
380
|
+
: readRegularInputFile(resolve(directory, postScanPromptFile), repository),
|
|
150
381
|
]);
|
|
151
382
|
return {
|
|
152
383
|
...(scanPrompt?.trim() ? { scanPrompt } : {}),
|
|
153
384
|
...(postScanPrompt?.trim() ? { postScanPrompt } : {}),
|
|
154
385
|
};
|
|
155
386
|
}
|
|
387
|
+
async function readRegularInputFile(path, repository, metadata) {
|
|
388
|
+
const selected = metadata ?? (await lstat(path));
|
|
389
|
+
if (!selected.isFile()) {
|
|
390
|
+
throw new CodexSecurityError("Input files must be regular files.");
|
|
391
|
+
}
|
|
392
|
+
const canonicalRepository = await realpath(repository);
|
|
393
|
+
const canonicalParent = await realpath(dirname(path));
|
|
394
|
+
if (isOutsidePath(relative(canonicalRepository, canonicalParent))) {
|
|
395
|
+
for (let ancestor = dirname(path);; ancestor = dirname(ancestor)) {
|
|
396
|
+
if (!isOutsidePath(relative(canonicalRepository, await realpath(ancestor)))) {
|
|
397
|
+
throw new CodexSecurityError("Input files must not follow repository directory links outside the selected repository.");
|
|
398
|
+
}
|
|
399
|
+
if (dirname(ancestor) === ancestor) {
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
const file = await open(join(canonicalParent, basename(path)), constants.O_RDONLY |
|
|
405
|
+
(constants.O_NOFOLLOW ?? 0) |
|
|
406
|
+
(constants.O_NONBLOCK ?? 0));
|
|
407
|
+
try {
|
|
408
|
+
const opened = await file.stat();
|
|
409
|
+
if (!opened.isFile() ||
|
|
410
|
+
opened.dev !== selected.dev ||
|
|
411
|
+
opened.ino !== selected.ino) {
|
|
412
|
+
throw new CodexSecurityError("Input files must remain regular files.");
|
|
413
|
+
}
|
|
414
|
+
return await file.readFile({ encoding: "utf8" });
|
|
415
|
+
}
|
|
416
|
+
finally {
|
|
417
|
+
await file.close();
|
|
418
|
+
}
|
|
419
|
+
}
|
|
156
420
|
const DEFAULT_DEPENDENCIES = {
|
|
157
421
|
createSecurity: (config) => createSecurityInternal(config, { surface: "cli" }),
|
|
158
422
|
environment: process.env,
|
|
159
423
|
prepareAuthenticationHome: prepareCodexSecurityCredentialHome,
|
|
160
|
-
checkForUpdate: () => checkForUpdate({ environment: process.env }),
|
|
424
|
+
checkForUpdate: (signal) => checkForUpdate({ environment: process.env, signal }),
|
|
161
425
|
hasStoredChatGPTSignIn: async () => {
|
|
162
426
|
const environment = Object.fromEntries(Object.entries(process.env).filter(([name]) => name.toUpperCase() !== "OPENAI_API_KEY" &&
|
|
163
427
|
name.toUpperCase() !== "CODEX_API_KEY"));
|
|
@@ -424,13 +688,14 @@ export function exportEnvironment(environment = process.env) {
|
|
|
424
688
|
.map((key) => [key, environment[key]]));
|
|
425
689
|
}
|
|
426
690
|
export async function main(argv = process.argv.slice(2), output = process.stdout, errorOutput = process.stderr, dependencies = DEFAULT_DEPENDENCIES) {
|
|
427
|
-
argv =
|
|
691
|
+
argv = defaultListCommand(argv);
|
|
428
692
|
const positionals = [];
|
|
429
693
|
const argumentError = validateCliArguments(argv, positionals);
|
|
430
694
|
if (argumentError !== undefined) {
|
|
431
695
|
errorOutput.write(`codex-security: ${argumentError}\n`);
|
|
432
696
|
return 2;
|
|
433
697
|
}
|
|
698
|
+
const updateController = new AbortController();
|
|
434
699
|
const pendingUpdate = errorOutput.isTTY === true &&
|
|
435
700
|
argv.length > 0 &&
|
|
436
701
|
argv[0] !== "completions" &&
|
|
@@ -444,12 +709,15 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
444
709
|
"--dry-run",
|
|
445
710
|
].includes(argument)) &&
|
|
446
711
|
updateNoticeEnabled(dependencies.environment)
|
|
447
|
-
? dependencies
|
|
712
|
+
? dependencies
|
|
713
|
+
.checkForUpdate(updateController.signal)
|
|
714
|
+
.catch(() => undefined)
|
|
448
715
|
: undefined;
|
|
449
716
|
let exitCode = 0;
|
|
450
717
|
let frameworkExit;
|
|
451
718
|
let frameworkOutput = "";
|
|
452
719
|
let renderedHistory;
|
|
720
|
+
let renderedPublication;
|
|
453
721
|
const history = async (args, select = (value) => value) => {
|
|
454
722
|
try {
|
|
455
723
|
return await select(await dependencies.runWorkbench(args));
|
|
@@ -460,6 +728,25 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
460
728
|
return undefined;
|
|
461
729
|
}
|
|
462
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
|
+
};
|
|
463
750
|
const matchScanPair = async (beforeId, afterId, force = false) => history([
|
|
464
751
|
"compare-scans",
|
|
465
752
|
"--before-scan-id",
|
|
@@ -601,7 +888,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
601
888
|
scanId: z
|
|
602
889
|
.string()
|
|
603
890
|
.min(1)
|
|
604
|
-
.
|
|
891
|
+
.optional()
|
|
892
|
+
.describe("Scan ID or unique prefix (default: latest completed)."),
|
|
605
893
|
}),
|
|
606
894
|
options: z.object({
|
|
607
895
|
showLinkedFindings: z
|
|
@@ -611,7 +899,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
611
899
|
}),
|
|
612
900
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
613
901
|
async run({ args, format, options }) {
|
|
614
|
-
|
|
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) => {
|
|
615
906
|
const { scan, recipe, parentScanId } = value;
|
|
616
907
|
return {
|
|
617
908
|
...scan,
|
|
@@ -628,11 +919,15 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
628
919
|
scanId: z
|
|
629
920
|
.string()
|
|
630
921
|
.min(1)
|
|
631
|
-
.
|
|
922
|
+
.optional()
|
|
923
|
+
.describe("Scan identifier or unique prefix (default: latest)."),
|
|
632
924
|
}),
|
|
633
925
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
634
926
|
async run({ args }) {
|
|
635
|
-
|
|
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) => {
|
|
636
931
|
const scan = value["scan"];
|
|
637
932
|
const threadId = scan.continuationThreadId;
|
|
638
933
|
if (!threadId) {
|
|
@@ -642,6 +937,14 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
642
937
|
scanId: scan.scanId,
|
|
643
938
|
threadId,
|
|
644
939
|
codexHome: codexSecurityCredentialHome(dependencies.environment),
|
|
940
|
+
scanDirectory: scan.mode === "deep" ? scan.scanDir : undefined,
|
|
941
|
+
completedAt: scan.progress?.status === "running"
|
|
942
|
+
? null
|
|
943
|
+
: scan.progress?.status === "complete" ||
|
|
944
|
+
scan.progress?.status === "failed" ||
|
|
945
|
+
scan.progress?.status === "canceled"
|
|
946
|
+
? scan.progress.updatedAt ?? ""
|
|
947
|
+
: "",
|
|
645
948
|
}));
|
|
646
949
|
});
|
|
647
950
|
},
|
|
@@ -651,7 +954,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
651
954
|
destructive: true,
|
|
652
955
|
mcp: false,
|
|
653
956
|
args: z.object({
|
|
654
|
-
scanId: z
|
|
957
|
+
scanId: z
|
|
958
|
+
.string()
|
|
959
|
+
.min(1)
|
|
960
|
+
.optional()
|
|
961
|
+
.describe("Saved scan identifier (default: latest completed scan)."),
|
|
655
962
|
}),
|
|
656
963
|
options: z.object({
|
|
657
964
|
verbose: z
|
|
@@ -661,14 +968,17 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
661
968
|
}),
|
|
662
969
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
663
970
|
async run({ args, error: incurError, options }) {
|
|
971
|
+
const scanId = args.scanId ?? (await latestScans())?.[0]?.scanId;
|
|
972
|
+
if (scanId === undefined)
|
|
973
|
+
return;
|
|
664
974
|
let scanArguments;
|
|
665
975
|
try {
|
|
666
976
|
const { recipe } = await dependencies.runWorkbench([
|
|
667
977
|
"get-scan-recipe",
|
|
668
978
|
"--scan-id",
|
|
669
|
-
|
|
979
|
+
scanId,
|
|
670
980
|
]);
|
|
671
|
-
scanArguments = scanArgumentsFromRecipe(recipe,
|
|
981
|
+
scanArguments = scanArgumentsFromRecipe(recipe, scanId);
|
|
672
982
|
scanArguments.verbose = options.verbose;
|
|
673
983
|
}
|
|
674
984
|
catch (error) {
|
|
@@ -739,16 +1049,303 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
739
1049
|
destructive: true,
|
|
740
1050
|
mcp: false,
|
|
741
1051
|
args: z.object({
|
|
742
|
-
beforeId: z
|
|
743
|
-
|
|
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)."),
|
|
744
1062
|
}),
|
|
745
1063
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
746
1064
|
async run({ args, format }) {
|
|
747
|
-
|
|
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
|
+
}
|
|
748
1345
|
},
|
|
749
1346
|
});
|
|
750
1347
|
const cli = Cli.create("codex-security", {
|
|
751
|
-
description: "Run, validate, patch, and
|
|
1348
|
+
description: "Run, validate, patch, export, and publish Codex Security findings.",
|
|
752
1349
|
version: VERSION,
|
|
753
1350
|
mcp: {
|
|
754
1351
|
command: "npx --yes @openai/codex-security --mcp",
|
|
@@ -1003,6 +1600,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1003
1600
|
})
|
|
1004
1601
|
.command(scanHistory)
|
|
1005
1602
|
.command(findingFeedback)
|
|
1603
|
+
.command(publication)
|
|
1006
1604
|
.command("bulk-scan", {
|
|
1007
1605
|
description: "Discover repositories and run resumable bulk security scans.",
|
|
1008
1606
|
destructive: true,
|
|
@@ -1051,6 +1649,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1051
1649
|
.positive()
|
|
1052
1650
|
.default(1)
|
|
1053
1651
|
.describe("Maximum scan attempts per repository."),
|
|
1652
|
+
maxCost: z
|
|
1653
|
+
.number()
|
|
1654
|
+
.positive()
|
|
1655
|
+
.optional()
|
|
1656
|
+
.describe("Stop each repository attempt if estimated USD cost exceeds AMOUNT."),
|
|
1054
1657
|
pluginPath: z
|
|
1055
1658
|
.string()
|
|
1056
1659
|
.min(1)
|
|
@@ -1120,6 +1723,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1120
1723
|
workers: options.workers,
|
|
1121
1724
|
mode: options.mode,
|
|
1122
1725
|
maxAttempts: options.maxAttempts,
|
|
1726
|
+
...(options.maxCost === undefined
|
|
1727
|
+
? {}
|
|
1728
|
+
: { maxCostUsd: options.maxCost }),
|
|
1123
1729
|
knowledgeBasePaths: options.knowledgeBase,
|
|
1124
1730
|
...prompts,
|
|
1125
1731
|
config: {
|
|
@@ -1160,7 +1766,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1160
1766
|
args: z.object({
|
|
1161
1767
|
scanDir: z
|
|
1162
1768
|
.string()
|
|
1163
|
-
.
|
|
1769
|
+
.optional()
|
|
1770
|
+
.describe("Completed scan directory (default: latest completed)."),
|
|
1164
1771
|
}),
|
|
1165
1772
|
options: z
|
|
1166
1773
|
.object({
|
|
@@ -1184,8 +1791,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1184
1791
|
}),
|
|
1185
1792
|
async run({ args, options }) {
|
|
1186
1793
|
const currentDirectory = dependencies.currentDirectory();
|
|
1794
|
+
const scanDir = args.scanDir ?? (await latestScans())?.[0]?.scanDir;
|
|
1795
|
+
if (scanDir === undefined)
|
|
1796
|
+
return;
|
|
1187
1797
|
exitCode = await runExport({
|
|
1188
|
-
scanDir: resolve(currentDirectory,
|
|
1798
|
+
scanDir: resolve(currentDirectory, scanDir),
|
|
1189
1799
|
format: options.exportFormat,
|
|
1190
1800
|
output: options.output === "-"
|
|
1191
1801
|
? "-"
|
|
@@ -1379,21 +1989,27 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1379
1989
|
};
|
|
1380
1990
|
},
|
|
1381
1991
|
});
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
if (
|
|
1395
|
-
|
|
1992
|
+
let notice;
|
|
1993
|
+
try {
|
|
1994
|
+
await cli.serve(argv.flatMap((argument) => argument.startsWith("--format=")
|
|
1995
|
+
? ["--format", argument.slice("--format=".length)]
|
|
1996
|
+
: [argument]), {
|
|
1997
|
+
stdout: (value) => {
|
|
1998
|
+
frameworkOutput += value;
|
|
1999
|
+
},
|
|
2000
|
+
exit: (code) => {
|
|
2001
|
+
frameworkExit = code;
|
|
2002
|
+
},
|
|
2003
|
+
});
|
|
2004
|
+
if (pendingUpdate !== undefined) {
|
|
2005
|
+
notice = await Promise.race([pendingUpdate, undefined]);
|
|
2006
|
+
}
|
|
1396
2007
|
}
|
|
2008
|
+
finally {
|
|
2009
|
+
updateController.abort();
|
|
2010
|
+
}
|
|
2011
|
+
if (notice !== undefined)
|
|
2012
|
+
errorOutput.write(formatUpdateNotice(notice));
|
|
1397
2013
|
if (frameworkExit !== undefined) {
|
|
1398
2014
|
if (exitCode !== 0)
|
|
1399
2015
|
return exitCode;
|
|
@@ -1403,7 +2019,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1403
2019
|
if (frameworkOutput.length === 0)
|
|
1404
2020
|
return exitCode;
|
|
1405
2021
|
try {
|
|
1406
|
-
await writeCliOutput(output, renderedHistory ?? frameworkOutput);
|
|
2022
|
+
await writeCliOutput(output, renderedPublication ?? renderedHistory ?? frameworkOutput);
|
|
1407
2023
|
return exitCode;
|
|
1408
2024
|
}
|
|
1409
2025
|
catch (error) {
|
|
@@ -1411,14 +2027,14 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1411
2027
|
return 2;
|
|
1412
2028
|
}
|
|
1413
2029
|
}
|
|
1414
|
-
function
|
|
2030
|
+
function defaultListCommand(argv) {
|
|
1415
2031
|
const commandIndex = argv.findIndex((value, index) => {
|
|
1416
2032
|
if (value.startsWith("-"))
|
|
1417
2033
|
return false;
|
|
1418
2034
|
return index === 0 || !VALUE_OPTIONS.has(argv[index - 1]);
|
|
1419
2035
|
});
|
|
1420
2036
|
if (commandIndex < 0 ||
|
|
1421
|
-
argv[commandIndex]
|
|
2037
|
+
!["scans", "findings"].includes(argv[commandIndex]) ||
|
|
1422
2038
|
argv.includes("--help") ||
|
|
1423
2039
|
argv.includes("-h")) {
|
|
1424
2040
|
return argv;
|
|
@@ -1535,6 +2151,7 @@ function validateCliArguments(argv, positionals) {
|
|
|
1535
2151
|
"scans",
|
|
1536
2152
|
"findings",
|
|
1537
2153
|
"export",
|
|
2154
|
+
"publish",
|
|
1538
2155
|
"validate",
|
|
1539
2156
|
"patch",
|
|
1540
2157
|
"login",
|
|
@@ -1574,7 +2191,7 @@ function validateCliArguments(argv, positionals) {
|
|
|
1574
2191
|
return "Markdown output is not supported for scan results.";
|
|
1575
2192
|
}
|
|
1576
2193
|
}
|
|
1577
|
-
const nestedCommand = command === "scans" || command === "findings";
|
|
2194
|
+
const nestedCommand = command === "scans" || command === "findings" || command === "publish";
|
|
1578
2195
|
const subcommand = nestedCommand ? argv[commandIndex + 1] : undefined;
|
|
1579
2196
|
if (command === "info") {
|
|
1580
2197
|
const metadataFields = new Set([
|
|
@@ -1736,7 +2353,7 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
1736
2353
|
localDeviceRoot !== normalizedDeviceRoot);
|
|
1737
2354
|
if (!windowsNetworkPath) {
|
|
1738
2355
|
const path = resolve(directory, input);
|
|
1739
|
-
const metadata = await
|
|
2356
|
+
const metadata = await lstat(path).catch((error) => {
|
|
1740
2357
|
if (typeof error === "object" &&
|
|
1741
2358
|
error !== null &&
|
|
1742
2359
|
"code" in error &&
|
|
@@ -1753,7 +2370,7 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
1753
2370
|
throw new CodexSecurityError("Finding and issue inputs must be files or literal text.");
|
|
1754
2371
|
}
|
|
1755
2372
|
try {
|
|
1756
|
-
contentsOrLiteral = await
|
|
2373
|
+
contentsOrLiteral = await readRegularInputFile(path, directory, metadata);
|
|
1757
2374
|
}
|
|
1758
2375
|
catch {
|
|
1759
2376
|
throw new CodexSecurityError("Could not read the finding or issue input.");
|
|
@@ -1938,6 +2555,29 @@ function diagnosticValue(value) {
|
|
|
1938
2555
|
return errorMessage(value).replaceAll(/[\u0000-\u001F\u007F\u0085\u2028\u2029]/gu, " ");
|
|
1939
2556
|
}
|
|
1940
2557
|
async function runScan(arguments_, errorOutput, dependencies, interactive = true) {
|
|
2558
|
+
const observeTerminalErrors = typeof errorOutput.on === "function" &&
|
|
2559
|
+
typeof errorOutput.off === "function";
|
|
2560
|
+
const ignoreTerminalError = () => { };
|
|
2561
|
+
if (observeTerminalErrors) {
|
|
2562
|
+
errorOutput.on?.("error", ignoreTerminalError);
|
|
2563
|
+
}
|
|
2564
|
+
try {
|
|
2565
|
+
return await executeScan(arguments_, errorOutput, dependencies, interactive);
|
|
2566
|
+
}
|
|
2567
|
+
finally {
|
|
2568
|
+
if (observeTerminalErrors) {
|
|
2569
|
+
try {
|
|
2570
|
+
errorOutput.write("", () => {
|
|
2571
|
+
queueMicrotask(() => errorOutput.off?.("error", ignoreTerminalError));
|
|
2572
|
+
});
|
|
2573
|
+
}
|
|
2574
|
+
catch {
|
|
2575
|
+
errorOutput.off?.("error", ignoreTerminalError);
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
async function executeScan(arguments_, errorOutput, dependencies, interactive = true) {
|
|
1941
2581
|
let scanDir = null;
|
|
1942
2582
|
let requestedSignal = null;
|
|
1943
2583
|
let firstSignalAt = 0;
|
|
@@ -1974,6 +2614,16 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
1974
2614
|
});
|
|
1975
2615
|
};
|
|
1976
2616
|
const preparationAbortController = new AbortController();
|
|
2617
|
+
const stopPresentation = () => {
|
|
2618
|
+
try {
|
|
2619
|
+
dashboard?.stop();
|
|
2620
|
+
}
|
|
2621
|
+
catch { }
|
|
2622
|
+
try {
|
|
2623
|
+
progress?.stopTimer();
|
|
2624
|
+
}
|
|
2625
|
+
catch { }
|
|
2626
|
+
};
|
|
1977
2627
|
const signalListener = (signal) => () => {
|
|
1978
2628
|
if (requestedSignal !== null) {
|
|
1979
2629
|
// Launchers and terminals can deliver the same initial signal twice.
|
|
@@ -1983,8 +2633,7 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
1983
2633
|
return;
|
|
1984
2634
|
}
|
|
1985
2635
|
requestedSignal = signal;
|
|
1986
|
-
|
|
1987
|
-
progress?.stopTimer();
|
|
2636
|
+
stopPresentation();
|
|
1988
2637
|
if (progress?.interactive === true) {
|
|
1989
2638
|
try {
|
|
1990
2639
|
dependencies.writeSynchronously(errorOutput, SHOW_CURSOR);
|
|
@@ -2018,9 +2667,10 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2018
2667
|
let failed = false;
|
|
2019
2668
|
let failure;
|
|
2020
2669
|
try {
|
|
2021
|
-
const
|
|
2670
|
+
const directory = dependencies.currentDirectory();
|
|
2671
|
+
const repository = arguments_.repository ?? directory;
|
|
2022
2672
|
const target = targetFromArguments(arguments_);
|
|
2023
|
-
const prompts = await readPromptFiles(
|
|
2673
|
+
const prompts = await readPromptFiles(directory, arguments_.scanPromptFile, arguments_.postScanPromptFile, resolve(directory, repository));
|
|
2024
2674
|
const config = {
|
|
2025
2675
|
pluginPath: arguments_.pluginPath,
|
|
2026
2676
|
pythonPath: arguments_.pythonPath,
|
|
@@ -2089,6 +2739,7 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2089
2739
|
if (progress.interactive && !arguments_.dryRun && !verbose) {
|
|
2090
2740
|
dashboard = new ScanDashboard(errorOutput, {
|
|
2091
2741
|
repository,
|
|
2742
|
+
mode: arguments_.mode,
|
|
2092
2743
|
model: scanModelConfiguration(await mergedCodexConfig(config)),
|
|
2093
2744
|
...(arguments_.maxCostUsd === undefined
|
|
2094
2745
|
? {}
|
|
@@ -2130,7 +2781,14 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2130
2781
|
progress.startTimer(arguments_.dryRun ? "Validating scan inputs" : "Preparing scan");
|
|
2131
2782
|
}
|
|
2132
2783
|
else {
|
|
2133
|
-
|
|
2784
|
+
try {
|
|
2785
|
+
dashboard.start();
|
|
2786
|
+
}
|
|
2787
|
+
catch {
|
|
2788
|
+
dashboard = null;
|
|
2789
|
+
progress = new Progress(errorOutput, dependencies, false);
|
|
2790
|
+
progress.startTimer("Preparing scan");
|
|
2791
|
+
}
|
|
2134
2792
|
}
|
|
2135
2793
|
security = dependencies.createSecurity(config);
|
|
2136
2794
|
const options = {
|
|
@@ -2372,8 +3030,7 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2372
3030
|
failure = error;
|
|
2373
3031
|
}
|
|
2374
3032
|
finally {
|
|
2375
|
-
|
|
2376
|
-
progress?.stopTimer();
|
|
3033
|
+
stopPresentation();
|
|
2377
3034
|
if (security !== null) {
|
|
2378
3035
|
diagnostic("runtime.cleanup.started");
|
|
2379
3036
|
await security.close().then(() => diagnostic("runtime.cleanup.completed"), (error) => {
|
|
@@ -2440,6 +3097,7 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2440
3097
|
: undefined,
|
|
2441
3098
|
verified: effectivePreflight.authentication.verified,
|
|
2442
3099
|
});
|
|
3100
|
+
progress?.stopTimer();
|
|
2443
3101
|
return { exitCode: 0, data: { dryRun: true, ...effectivePreflight } };
|
|
2444
3102
|
}
|
|
2445
3103
|
if (result === null) {
|
|
@@ -2472,14 +3130,17 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2472
3130
|
});
|
|
2473
3131
|
if (targetWarnings.length > 0) {
|
|
2474
3132
|
errorOutput.write("codex-security: Scan target changed during execution; results do not represent the current checkout.\n");
|
|
3133
|
+
progress?.stopTimer();
|
|
2475
3134
|
return { exitCode: 2, data: scanData };
|
|
2476
3135
|
}
|
|
2477
3136
|
if (incomplete) {
|
|
2478
3137
|
errorOutput.write(threshold === undefined
|
|
2479
3138
|
? `codex-security: Scan coverage is ${result.coverage.completeness}; results may be incomplete.\n`
|
|
2480
3139
|
: `codex-security: Cannot evaluate the failure policy: coverage is ${result.coverage.completeness}.\n`);
|
|
3140
|
+
progress?.stopTimer();
|
|
2481
3141
|
return { exitCode: 2, data: scanData };
|
|
2482
3142
|
}
|
|
3143
|
+
progress?.stopTimer();
|
|
2483
3144
|
return { exitCode: blockingCount > 0 ? 1 : 0, data: scanData };
|
|
2484
3145
|
}
|
|
2485
3146
|
// Filesystem and OS syscall failures cannot originate from the model transport,
|
|
@@ -2837,6 +3498,10 @@ export class Progress {
|
|
|
2837
3498
|
#timerMessage = null;
|
|
2838
3499
|
#timerLineActive = false;
|
|
2839
3500
|
#cursorHidden = false;
|
|
3501
|
+
#observingStreamErrors = false;
|
|
3502
|
+
#streamErrorsActive = false;
|
|
3503
|
+
#streamErrorGeneration = 0;
|
|
3504
|
+
#onStreamError = () => { };
|
|
2840
3505
|
constructor(stream = process.stderr, dependencies = DEFAULT_DEPENDENCIES, interactive = true) {
|
|
2841
3506
|
this.#stream = stream;
|
|
2842
3507
|
this.#dependencies = dependencies;
|
|
@@ -2850,9 +3515,11 @@ export class Progress {
|
|
|
2850
3515
|
return Math.max(0, Math.floor((this.#dependencies.now() - this.#startedAt) / 1_000));
|
|
2851
3516
|
}
|
|
2852
3517
|
stage(message) {
|
|
3518
|
+
this.#observeStreamErrors();
|
|
2853
3519
|
this.#stream.write(`${this.#line(message)}\n`);
|
|
2854
3520
|
}
|
|
2855
3521
|
startTimer(message) {
|
|
3522
|
+
this.#observeStreamErrors();
|
|
2856
3523
|
if (!this.interactive) {
|
|
2857
3524
|
this.stage(message);
|
|
2858
3525
|
return;
|
|
@@ -2860,22 +3527,51 @@ export class Progress {
|
|
|
2860
3527
|
this.#stream.write(HIDE_CURSOR);
|
|
2861
3528
|
this.#cursorHidden = true;
|
|
2862
3529
|
this.#renderTimer(message);
|
|
2863
|
-
this.#timer = this.#dependencies.setInterval(() =>
|
|
3530
|
+
this.#timer = this.#dependencies.setInterval(() => {
|
|
3531
|
+
try {
|
|
3532
|
+
this.#renderTimer(message);
|
|
3533
|
+
}
|
|
3534
|
+
catch { }
|
|
3535
|
+
}, PROGRESS_REFRESH_MILLISECONDS);
|
|
2864
3536
|
this.#timerMessage = message;
|
|
2865
3537
|
}
|
|
2866
3538
|
stopTimer() {
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
this.#
|
|
2874
|
-
|
|
3539
|
+
try {
|
|
3540
|
+
if (this.#timer !== null) {
|
|
3541
|
+
this.#dependencies.clearInterval(this.#timer);
|
|
3542
|
+
this.#timer = null;
|
|
3543
|
+
}
|
|
3544
|
+
this.#timerMessage = null;
|
|
3545
|
+
if (this.#timerLineActive) {
|
|
3546
|
+
this.#stream.write("\n");
|
|
3547
|
+
this.#timerLineActive = false;
|
|
3548
|
+
}
|
|
3549
|
+
if (this.#cursorHidden) {
|
|
3550
|
+
this.#stream.write(SHOW_CURSOR);
|
|
3551
|
+
this.#cursorHidden = false;
|
|
3552
|
+
}
|
|
2875
3553
|
}
|
|
2876
|
-
|
|
2877
|
-
this.#
|
|
2878
|
-
|
|
3554
|
+
finally {
|
|
3555
|
+
if (this.#observingStreamErrors) {
|
|
3556
|
+
this.#streamErrorsActive = false;
|
|
3557
|
+
const generation = this.#streamErrorGeneration;
|
|
3558
|
+
try {
|
|
3559
|
+
this.#stream.write("", () => {
|
|
3560
|
+
queueMicrotask(() => {
|
|
3561
|
+
if (generation === this.#streamErrorGeneration &&
|
|
3562
|
+
!this.#streamErrorsActive &&
|
|
3563
|
+
this.#observingStreamErrors) {
|
|
3564
|
+
this.#stream.off?.("error", this.#onStreamError);
|
|
3565
|
+
this.#observingStreamErrors = false;
|
|
3566
|
+
}
|
|
3567
|
+
});
|
|
3568
|
+
});
|
|
3569
|
+
}
|
|
3570
|
+
catch {
|
|
3571
|
+
this.#stream.off?.("error", this.#onStreamError);
|
|
3572
|
+
this.#observingStreamErrors = false;
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
2879
3575
|
}
|
|
2880
3576
|
}
|
|
2881
3577
|
writeAboveTimer(write) {
|
|
@@ -2898,6 +3594,14 @@ export class Progress {
|
|
|
2898
3594
|
const seconds = elapsedSeconds % 60;
|
|
2899
3595
|
return `[${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}] ${message}`;
|
|
2900
3596
|
}
|
|
3597
|
+
#observeStreamErrors() {
|
|
3598
|
+
this.#streamErrorsActive = true;
|
|
3599
|
+
this.#streamErrorGeneration += 1;
|
|
3600
|
+
if (!this.#observingStreamErrors && this.#stream.on !== undefined) {
|
|
3601
|
+
this.#stream.on("error", this.#onStreamError);
|
|
3602
|
+
this.#observingStreamErrors = true;
|
|
3603
|
+
}
|
|
3604
|
+
}
|
|
2901
3605
|
#renderTimer(message) {
|
|
2902
3606
|
this.#stream.write(`${this.#timerLineActive ? "\r" : ""}${this.#line(message)}`);
|
|
2903
3607
|
this.#timerLineActive = true;
|