@openai/codex-security 0.1.15 → 0.1.17

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.
Files changed (109) hide show
  1. package/README.md +204 -4
  2. package/_bundled_plugin/.app.json +1 -1
  3. package/_bundled_plugin/.mcp.json +9 -3
  4. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  6. package/_bundled_plugin/references/config-preflight.md +1 -1
  7. package/_bundled_plugin/references/sarif-adapter.md +5 -1
  8. package/_bundled_plugin/scripts/deep_scan_workbench.py +34 -6
  9. package/_bundled_plugin/scripts/finalize_scan_contract.py +121 -32
  10. package/_bundled_plugin/scripts/generate_in_scope_files.py +20 -0
  11. package/_bundled_plugin/scripts/generate_rank_input.py +23 -7
  12. package/_bundled_plugin/scripts/launch_codex_security_mcp +32 -0
  13. package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +27 -0
  14. package/_bundled_plugin/scripts/workbench_cli.py +22 -15
  15. package/_bundled_plugin/scripts/workbench_db.py +35 -35
  16. package/_bundled_plugin/scripts/workbench_progress.py +6 -3
  17. package/_bundled_plugin/scripts/workbench_scan_history.py +17 -2
  18. package/_bundled_plugin/scripts/workbench_target.py +36 -5
  19. package/_bundled_plugin/scripts/workbench_validation.py +9 -0
  20. package/_bundled_plugin/skills/fix-finding/SKILL.md +17 -1
  21. package/_bundled_plugin/skills/verify-fix/SKILL.md +44 -0
  22. package/_bundled_plugin/skills/verify-fix/agents/openai.yaml +4 -0
  23. package/dist/api.d.ts +16 -1
  24. package/dist/api.d.ts.map +1 -1
  25. package/dist/api.js +180 -11
  26. package/dist/api.js.map +1 -1
  27. package/dist/cli.d.ts +12 -5
  28. package/dist/cli.d.ts.map +1 -1
  29. package/dist/cli.js +781 -62
  30. package/dist/cli.js.map +1 -1
  31. package/dist/component-plan.d.ts +15 -0
  32. package/dist/component-plan.d.ts.map +1 -0
  33. package/dist/component-plan.js +145 -0
  34. package/dist/component-plan.js.map +1 -0
  35. package/dist/component-scan.d.ts +83 -0
  36. package/dist/component-scan.d.ts.map +1 -0
  37. package/dist/component-scan.js +279 -0
  38. package/dist/component-scan.js.map +1 -0
  39. package/dist/contract.d.ts +8 -2
  40. package/dist/contract.d.ts.map +1 -1
  41. package/dist/contract.js +27 -8
  42. package/dist/contract.js.map +1 -1
  43. package/dist/cost-model.d.ts +20 -0
  44. package/dist/cost-model.d.ts.map +1 -0
  45. package/dist/cost-model.js +86 -0
  46. package/dist/cost-model.js.map +1 -0
  47. package/dist/cost.d.ts +2 -11
  48. package/dist/cost.d.ts.map +1 -1
  49. package/dist/cost.js +15 -95
  50. package/dist/cost.js.map +1 -1
  51. package/dist/custom-validation-prompt.d.ts +4 -0
  52. package/dist/custom-validation-prompt.d.ts.map +1 -0
  53. package/dist/custom-validation-prompt.js +94 -0
  54. package/dist/custom-validation-prompt.js.map +1 -0
  55. package/dist/custom-validation.d.ts +45 -0
  56. package/dist/custom-validation.d.ts.map +1 -0
  57. package/dist/custom-validation.js +292 -0
  58. package/dist/custom-validation.js.map +1 -0
  59. package/dist/errors.d.ts +1 -1
  60. package/dist/errors.d.ts.map +1 -1
  61. package/dist/errors.js +1 -1
  62. package/dist/errors.js.map +1 -1
  63. package/dist/index.d.ts +6 -1
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +2 -0
  66. package/dist/index.js.map +1 -1
  67. package/dist/multiscan.d.ts +1 -0
  68. package/dist/multiscan.d.ts.map +1 -1
  69. package/dist/multiscan.js +53 -5
  70. package/dist/multiscan.js.map +1 -1
  71. package/dist/patch-tui.js +1 -1
  72. package/dist/patch-tui.js.map +1 -1
  73. package/dist/publication.d.ts.map +1 -1
  74. package/dist/publication.js +3 -4
  75. package/dist/publication.js.map +1 -1
  76. package/dist/runtime.d.ts +4 -2
  77. package/dist/runtime.d.ts.map +1 -1
  78. package/dist/runtime.js +109 -38
  79. package/dist/runtime.js.map +1 -1
  80. package/dist/scan-comparison.d.ts +12 -5
  81. package/dist/scan-comparison.d.ts.map +1 -1
  82. package/dist/scan-comparison.js +72 -28
  83. package/dist/scan-comparison.js.map +1 -1
  84. package/dist/scan-dashboard.d.ts +9 -2
  85. package/dist/scan-dashboard.d.ts.map +1 -1
  86. package/dist/scan-dashboard.js +205 -7
  87. package/dist/scan-dashboard.js.map +1 -1
  88. package/dist/scan-logs.d.ts.map +1 -1
  89. package/dist/scan-logs.js +5 -21
  90. package/dist/scan-logs.js.map +1 -1
  91. package/dist/scan-sessions.d.ts +4 -0
  92. package/dist/scan-sessions.d.ts.map +1 -0
  93. package/dist/scan-sessions.js +35 -0
  94. package/dist/scan-sessions.js.map +1 -0
  95. package/dist/targets.d.ts.map +1 -1
  96. package/dist/targets.js +16 -1
  97. package/dist/targets.js.map +1 -1
  98. package/dist/version.d.ts.map +1 -1
  99. package/dist/version.js +2 -20
  100. package/dist/version.js.map +1 -1
  101. package/dist/windows-path.d.ts +3 -0
  102. package/dist/windows-path.d.ts.map +1 -0
  103. package/dist/windows-path.js +16 -0
  104. package/dist/windows-path.js.map +1 -0
  105. package/dist/worker-progress.d.ts +1 -0
  106. package/dist/worker-progress.d.ts.map +1 -1
  107. package/dist/worker-progress.js +12 -0
  108. package/dist/worker-progress.js.map +1 -1
  109. package/package.json +8 -2
@@ -2,6 +2,7 @@ import { basename, isAbsolute } from "node:path";
2
2
  import { pathToFileURL } from "node:url";
3
3
  import { stripVTControlCharacters } from "node:util";
4
4
  import { formatUsd } from "./cost.js";
5
+ import { scanPhaseLabel } from "./worker-progress.js";
5
6
  const HIDE_CURSOR = "\u001B[?25l";
6
7
  const SHOW_CURSOR = "\u001B[?25h";
7
8
  const ENTER_ALTERNATE_SCREEN = "\u001B[?1049h";
@@ -35,6 +36,11 @@ export class ScanDashboard {
35
36
  #stream;
36
37
  #options;
37
38
  #startedAt;
39
+ #finishedAt = null;
40
+ #components = [];
41
+ #selectedComponent = 0;
42
+ #showComponent = false;
43
+ #componentResult = null;
38
44
  #activities = [];
39
45
  #details = [];
40
46
  #detailsCache = null;
@@ -52,6 +58,10 @@ export class ScanDashboard {
52
58
  #onStreamError = () => { };
53
59
  #onInput = (chunk) => {
54
60
  const input = typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
61
+ if (this.#options.presentation === "components") {
62
+ this.#componentInput(input);
63
+ return;
64
+ }
55
65
  let lines = 0;
56
66
  for (const key of input.match(/[\u0003\u0004\u0015dam1-9]|\u001B\[(?:[ABHF]|[1456]~)/gu) ?? []) {
57
67
  if (key === "\u0003") {
@@ -61,7 +71,8 @@ export class ScanDashboard {
61
71
  lines = 0;
62
72
  }
63
73
  else if (/^[dam1-9]$/u.test(key)) {
64
- if (this.#options.presentation === "publication")
74
+ if (this.#options.presentation !== undefined &&
75
+ this.#options.presentation !== "scan")
65
76
  continue;
66
77
  if (key !== "d" && this.#view !== "details")
67
78
  continue;
@@ -185,6 +196,82 @@ export class ScanDashboard {
185
196
  this.#stage = stage;
186
197
  this.#refresh();
187
198
  }
199
+ setComponents(receipts) {
200
+ this.#components = receipts.map((receipt) => {
201
+ const dashboard = new ScanDashboard(this.#stream, {
202
+ ...this.#options,
203
+ presentation: "scan",
204
+ mode: "standard",
205
+ componentName: receipt.name,
206
+ });
207
+ dashboard.setStage("Queued");
208
+ dashboard.note(`Scope: ${receipt.paths.join(", ")}`);
209
+ return { receipt: { ...receipt }, dashboard };
210
+ });
211
+ this.showComponents("Scanning components");
212
+ }
213
+ updateComponent(receipt) {
214
+ const component = this.#components.find(({ receipt: current }) => current.id === receipt.id);
215
+ if (component === undefined)
216
+ return;
217
+ const { dashboard } = component;
218
+ if (receipt.status !== component.receipt.status) {
219
+ if (receipt.status === "started") {
220
+ dashboard.#startedAt = this.#options.clock.now();
221
+ dashboard.setStage("Preparing scan");
222
+ }
223
+ else if (receipt.status !== "pending") {
224
+ dashboard.#finishedAt = this.#options.clock.now();
225
+ dashboard.setStage(componentStatus(receipt));
226
+ dashboard.note(receipt.error ??
227
+ `${componentStatus(receipt)} · ${receipt.findingCount ?? 0} findings before deduplication`);
228
+ }
229
+ }
230
+ if (receipt.cost !== undefined)
231
+ dashboard.setCost(receipt.cost);
232
+ component.receipt = { ...receipt };
233
+ this.#refresh();
234
+ }
235
+ recordComponentEvent(event) {
236
+ const dashboard = this.#components.find(({ receipt }) => receipt.id === event.componentId)?.dashboard;
237
+ if (dashboard === undefined)
238
+ return;
239
+ switch (event.type) {
240
+ case "progress":
241
+ dashboard.setFiles(event.value);
242
+ dashboard.setStage(scanPhaseLabel(event.value.phase));
243
+ break;
244
+ case "activity":
245
+ dashboard.record(event.value);
246
+ break;
247
+ case "session":
248
+ dashboard.recordDetails(event.value);
249
+ break;
250
+ case "cost":
251
+ dashboard.setCost(event.value);
252
+ break;
253
+ case "workers":
254
+ if (event.value.kind === "dispatch")
255
+ dashboard.setStage(scanPhaseLabel(event.value.phase));
256
+ break;
257
+ case "warning":
258
+ dashboard.note(event.value);
259
+ break;
260
+ }
261
+ this.#refresh();
262
+ }
263
+ showComponents(stage) {
264
+ this.#showComponent = false;
265
+ this.setStage(stage);
266
+ }
267
+ finishComponents(result) {
268
+ this.#componentResult = result;
269
+ this.showComponents(result.failed ||
270
+ result.incomplete ||
271
+ result.deduplication?.status === "incomplete"
272
+ ? "Finished with partial results"
273
+ : "Complete");
274
+ }
188
275
  setFiles(files) {
189
276
  this.#files = files;
190
277
  this.#refresh();
@@ -268,11 +355,22 @@ export class ScanDashboard {
268
355
  catch { }
269
356
  }
270
357
  #render() {
358
+ this.#stream.write(this.#frame());
359
+ }
360
+ #frame() {
361
+ if (this.#options.presentation === "components") {
362
+ return this.#showComponent
363
+ ? this.#components[this.#selectedComponent].dashboard.#frame()
364
+ : this.#componentFrame();
365
+ }
271
366
  const publication = this.#options.presentation === "publication";
367
+ const verification = this.#options.presentation === "verification";
368
+ const findingProgress = publication || verification;
272
369
  const width = this.#width();
273
370
  const activityRows = this.#activityRows();
274
371
  const divider = ` ${"─".repeat(Math.max(0, width - 4))}`;
275
- const elapsed = Math.max(0, Math.floor((this.#options.clock.now() - this.#startedAt) / 1_000));
372
+ const elapsed = Math.max(0, Math.floor(((this.#finishedAt ?? this.#options.clock.now()) - this.#startedAt) /
373
+ 1_000));
276
374
  const time = formatElapsed(elapsed);
277
375
  const files = this.#files === null
278
376
  ? "waiting for inventory"
@@ -292,7 +390,7 @@ export class ScanDashboard {
292
390
  const activity = history.slice(first, first + activityRows);
293
391
  if (activity.length === 0) {
294
392
  activity.push({
295
- text: ` [${formatLocalTime(this.#options.clock.now())}] · Waiting for ${this.#view === "details" ? "session events" : publication ? "publication activity" : "scan activity"}…`,
393
+ text: ` [${formatLocalTime(this.#options.clock.now())}] · Waiting for ${this.#view === "details" ? "session events" : publication ? "publication activity" : verification ? "verification activity" : "scan activity"}…`,
296
394
  kind: "path",
297
395
  });
298
396
  }
@@ -302,19 +400,21 @@ export class ScanDashboard {
302
400
  let scrollStatus = this.#scrollOffset === 0
303
401
  ? "Ctrl+C to exit"
304
402
  : `${formatCount(this.#scrollOffset)} ${this.#scrollOffset === 1 ? "line" : "lines"} above live · Ctrl+C to exit`;
305
- if (!publication && this.#options.input?.isTTY === true) {
403
+ if (!findingProgress && this.#options.input?.isTTY === true) {
306
404
  scrollStatus =
307
405
  this.#view === "details"
308
406
  ? `d activity · a/m/1-9 source · ${scrollStatus}`
309
407
  : `d details · ${scrollStatus}`;
310
408
  }
409
+ if (this.#options.componentName !== undefined)
410
+ scrollStatus = `Esc components · ${scrollStatus}`;
311
411
  const model = this.#options.model;
312
412
  const lines = [
313
- ` CODEX SECURITY · ${publication ? "PUBLISH · " : ""}${basename(this.#options.repository)}${model === undefined ? "" : ` · ${model.model} (${model.reasoningEffort})`}${this.#view === "details" ? ` · DETAILS${this.#source === "all" ? "" : ` · ${typeof this.#source === "number" ? `worker ${this.#source}` : this.#source}`}` : ""}`,
413
+ ` CODEX SECURITY · ${publication ? "PUBLISH · " : verification ? "VERIFY-FIX · " : ""}${basename(this.#options.repository)}${this.#options.componentName === undefined ? "" : ` · ${this.#options.componentName}`}${model === undefined ? "" : ` · ${model.model} (${model.reasoningEffort})`}${this.#view === "details" ? ` · DETAILS${this.#source === "all" ? "" : ` · ${typeof this.#source === "number" ? `worker ${this.#source}` : this.#source}`}` : ""}`,
314
414
  divider,
315
415
  ...activity,
316
416
  divider,
317
- ...(publication
417
+ ...(findingProgress
318
418
  ? [
319
419
  ` STAGE ${this.#stage}`,
320
420
  ` FINDINGS ${this.#publicationProgress === null ? "waiting for findings" : `${formatCount(this.#publicationProgress.completed)} / ${formatCount(this.#publicationProgress.total)} processed`}`,
@@ -328,7 +428,11 @@ export class ScanDashboard {
328
428
  ]),
329
429
  ` TIME ${time} · ${scrollStatus}`,
330
430
  ];
331
- this.#stream.write(CURSOR_HOME +
431
+ return this.#formatFrame(lines);
432
+ }
433
+ #formatFrame(lines) {
434
+ const width = this.#width();
435
+ return (CURSOR_HOME +
332
436
  lines
333
437
  .map((line, index) => {
334
438
  const text = typeof line === "string" ? line : line.text;
@@ -351,6 +455,91 @@ export class ScanDashboard {
351
455
  })
352
456
  .join("\n"));
353
457
  }
458
+ #componentInput(input) {
459
+ for (const key of input.match(/\u001B\[(?:[ABHF]|[1456]~)|[\u0003\u0004\u0015\r\n\u001Bbdam1-9]/gu) ?? []) {
460
+ if (key === "\u0003") {
461
+ this.#options.onInterrupt?.();
462
+ }
463
+ else if (this.#showComponent) {
464
+ if (key === "\u001B" || key === "b")
465
+ this.#showComponent = false;
466
+ else
467
+ this.#components[this.#selectedComponent].dashboard.#onInput(key);
468
+ }
469
+ else if ((key === "\r" || key === "\n") &&
470
+ this.#components.length > 0) {
471
+ this.#showComponent = true;
472
+ }
473
+ else {
474
+ const change = key === "\u001B[A"
475
+ ? -1
476
+ : key === "\u001B[B"
477
+ ? 1
478
+ : key === "\u001B[5~"
479
+ ? -this.#componentRows()
480
+ : key === "\u001B[6~"
481
+ ? this.#componentRows()
482
+ : 0;
483
+ this.#selectedComponent = Math.max(0, Math.min(this.#components.length - 1, this.#selectedComponent + change));
484
+ if (key === "\u001B[H" || key === "\u001B[1~")
485
+ this.#selectedComponent = 0;
486
+ if (key === "\u001B[F" || key === "\u001B[4~")
487
+ this.#selectedComponent = Math.max(0, this.#components.length - 1);
488
+ }
489
+ }
490
+ this.#refresh();
491
+ }
492
+ #componentRows() {
493
+ return Math.max(1, (this.#stream.rows ?? 24) - 11);
494
+ }
495
+ #componentFrame() {
496
+ const width = this.#width();
497
+ const rows = this.#componentRows();
498
+ const first = Math.max(0, Math.min(this.#selectedComponent - Math.floor(rows / 2), this.#components.length - rows));
499
+ const nameWidth = Math.max(10, width - 61);
500
+ const row = (marker, name, status, files, findings, cost) => ` ${marker} ${fitLine(this.#options.sanitize?.(name) ?? name, nameWidth).padEnd(nameWidth)} ${fitLine(status, 24).padEnd(24)} ${files.padStart(11)} ${findings.padStart(8)} ${cost.padStart(8)}`;
501
+ const table = this.#components
502
+ .slice(first, first + rows)
503
+ .map(({ receipt, dashboard }, index) => {
504
+ const files = dashboard.#files;
505
+ return row(first + index === this.#selectedComponent ? "›" : " ", receipt.name, receipt.status === "started"
506
+ ? dashboard.#stage
507
+ : componentStatus(receipt), files === null
508
+ ? "—"
509
+ : `${formatCount(files.filesCompleted)}/${formatCount(files.filesTotal)}`, receipt.findingCount === undefined
510
+ ? "—"
511
+ : formatCount(receipt.findingCount), dashboard.#cost === null
512
+ ? "—"
513
+ : formatUsd(dashboard.#cost.estimatedUsd));
514
+ });
515
+ if (table.length === 0)
516
+ table.push(` ${this.#stage}…`);
517
+ while (table.length < rows)
518
+ table.push("");
519
+ const count = (status) => this.#components.filter(({ receipt }) => receipt.status === status)
520
+ .length;
521
+ const selected = this.#components[this.#selectedComponent]?.receipt;
522
+ const costs = this.#components.flatMap(({ dashboard }) => dashboard.#cost === null ? [] : [dashboard.#cost.estimatedUsd]);
523
+ const rawFindings = this.#components.reduce((sum, { receipt }) => sum + (receipt.findingCount ?? 0), 0);
524
+ const findings = this.#componentResult === null
525
+ ? `${rawFindings} findings before deduplication`
526
+ : `${this.#componentResult.sourceFindingCount} findings → ${this.#componentResult.findingCount} groups${this.#componentResult.deduplication?.status === "incomplete" ? " · matching incomplete" : ""}`;
527
+ const divider = ` ${"─".repeat(Math.max(0, width - 4))}`;
528
+ return this.#formatFrame([
529
+ ` CODEX SECURITY · COMPONENTS · ${basename(this.#options.repository)}`,
530
+ divider,
531
+ ` ${count("completed")} complete · ${count("started")} running · ${count("pending")} queued · ${count("incomplete")} incomplete · ${count("failed")} failed`,
532
+ "",
533
+ row(" ", "Component", "Status", "Files", "Findings", "Cost"),
534
+ ...table,
535
+ divider,
536
+ ` SCOPE ${selected?.paths.join(", ") ?? "waiting for component plan"}`,
537
+ ` STATUS ${selected?.error ?? findings}`,
538
+ ` COST ${costs.length === 0 ? "waiting for usage" : formatUsd(costs.reduce((sum, value) => sum + value, 0))} · component scans only`,
539
+ ` STAGE ${this.#stage}`,
540
+ ` TIME ${formatElapsed(Math.max(0, Math.floor((this.#options.clock.now() - this.#startedAt) / 1_000)))} · ↑↓ select · Enter activity · Ctrl+C cancel`,
541
+ ]);
542
+ }
354
543
  #width() {
355
544
  return Math.max(1, Math.min(this.#stream.columns ?? 88, 160));
356
545
  }
@@ -601,6 +790,15 @@ function isFileInventory(activity) {
601
790
  function formatElapsed(seconds) {
602
791
  return `${String(Math.floor(seconds / 60)).padStart(2, "0")}:${String(seconds % 60).padStart(2, "0")}`;
603
792
  }
793
+ function componentStatus(receipt) {
794
+ return {
795
+ pending: "Queued",
796
+ started: "Running",
797
+ completed: "Complete",
798
+ incomplete: "Incomplete",
799
+ failed: "Failed",
800
+ }[receipt.status];
801
+ }
604
802
  function formatLocalTime(timestamp) {
605
803
  const date = new Date(timestamp);
606
804
  return [date.getHours(), date.getMinutes(), date.getSeconds()]