@openai/codex-security 0.7.0 → 0.8.1

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 (187) hide show
  1. package/README.md +18 -12
  2. package/_bundled_plugin/.codex-plugin/plugin.json +1 -0
  3. package/_bundled_plugin/examples/completed-scan/findings.json +34 -34
  4. package/_bundled_plugin/examples/completed-scan/report.md +22 -31
  5. package/_bundled_plugin/examples/completed-scan/scan-manifest.json +27 -29
  6. package/_bundled_plugin/examples/{completed-scan → legacy-completed-scan}/coverage.json +1 -0
  7. package/_bundled_plugin/examples/legacy-completed-scan/findings.json +57 -0
  8. package/_bundled_plugin/examples/legacy-completed-scan/report.md +98 -0
  9. package/_bundled_plugin/examples/legacy-completed-scan/scan-manifest.json +43 -0
  10. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  11. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  12. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  13. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  14. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  15. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  16. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  17. package/_bundled_plugin/references/core-scan.md +2 -2
  18. package/_bundled_plugin/references/final-report.md +16 -6
  19. package/_bundled_plugin/references/scan-artifacts.md +6 -6
  20. package/_bundled_plugin/references/scan-contract.md +10 -12
  21. package/_bundled_plugin/references/threat-model.md +1 -1
  22. package/_bundled_plugin/schemas/scan-manifest.schema.json +36 -11
  23. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +5 -5
  24. package/_bundled_plugin/scripts/deep_scan_workbench.py +1 -1
  25. package/_bundled_plugin/scripts/finalize_scan_contract.py +97 -20
  26. package/_bundled_plugin/scripts/report_projection.py +5 -2
  27. package/_bundled_plugin/scripts/review_state.py +68 -0
  28. package/_bundled_plugin/scripts/servicenow_avit.py +107 -0
  29. package/_bundled_plugin/scripts/validate_scan_contract.py +1 -2
  30. package/_bundled_plugin/scripts/workbench/retained_coverage.py +49 -37
  31. package/_bundled_plugin/scripts/workbench/retained_records.py +7 -7
  32. package/_bundled_plugin/scripts/workbench/saved_coverage.py +15 -15
  33. package/_bundled_plugin/scripts/workbench/saved_sources.py +24 -6
  34. package/_bundled_plugin/scripts/workbench_constants.py +0 -1
  35. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +4 -4
  36. package/_bundled_plugin/scripts/workbench_db.py +5 -150
  37. package/_bundled_plugin/scripts/workbench_saved_results.py +169 -4
  38. package/_bundled_plugin/scripts/workbench_scan_history.py +12 -7
  39. package/_bundled_plugin/scripts/workbench_scan_start.py +4 -1
  40. package/_bundled_plugin/skills/publish-findings/SKILL.md +9 -3
  41. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +1 -1
  42. package/_bundled_plugin/skills/security-scan/SKILL.md +7 -7
  43. package/_bundled_plugin/skills/track-findings/SKILL.md +1 -1
  44. package/dist/api.d.ts.map +1 -1
  45. package/dist/api.js +50 -27
  46. package/dist/api.js.map +1 -1
  47. package/dist/artifact-export.d.ts +12 -3
  48. package/dist/artifact-export.d.ts.map +1 -1
  49. package/dist/artifact-export.js +30 -10
  50. package/dist/artifact-export.js.map +1 -1
  51. package/dist/cli-help.d.ts.map +1 -1
  52. package/dist/cli-help.js +1 -0
  53. package/dist/cli-help.js.map +1 -1
  54. package/dist/cli.d.ts +1 -1
  55. package/dist/cli.d.ts.map +1 -1
  56. package/dist/cli.js +69 -55
  57. package/dist/cli.js.map +1 -1
  58. package/dist/cloud-publish.d.ts.map +1 -1
  59. package/dist/cloud-publish.js +2 -23
  60. package/dist/cloud-publish.js.map +1 -1
  61. package/dist/contract.d.ts +4 -2
  62. package/dist/contract.d.ts.map +1 -1
  63. package/dist/contract.js +39 -21
  64. package/dist/contract.js.map +1 -1
  65. package/dist/custom-publish.js +2 -2
  66. package/dist/custom-publish.js.map +1 -1
  67. package/dist/custom-validation-prompt.d.ts.map +1 -1
  68. package/dist/custom-validation-prompt.js +14 -6
  69. package/dist/custom-validation-prompt.js.map +1 -1
  70. package/dist/custom-validation.d.ts.map +1 -1
  71. package/dist/custom-validation.js +17 -15
  72. package/dist/custom-validation.js.map +1 -1
  73. package/dist/deduplication/codex-review.d.ts.map +1 -1
  74. package/dist/deduplication/codex-review.js +2 -2
  75. package/dist/deduplication/codex-review.js.map +1 -1
  76. package/dist/deduplication/deduplication-prompts.d.ts +1 -0
  77. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  78. package/dist/deduplication/deduplication-prompts.js +3 -0
  79. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  80. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  81. package/dist/deduplication/records-protocol.js +21 -1
  82. package/dist/deduplication/records-protocol.js.map +1 -1
  83. package/dist/deduplication/scan.d.ts.map +1 -1
  84. package/dist/deduplication/scan.js +2 -2
  85. package/dist/deduplication/scan.js.map +1 -1
  86. package/dist/external-findings-local.d.ts +1 -0
  87. package/dist/external-findings-local.d.ts.map +1 -1
  88. package/dist/external-findings-local.js +25 -2
  89. package/dist/external-findings-local.js.map +1 -1
  90. package/dist/external-findings-publish.d.ts +1 -0
  91. package/dist/external-findings-publish.d.ts.map +1 -1
  92. package/dist/external-findings-publish.js +55 -26
  93. package/dist/external-findings-publish.js.map +1 -1
  94. package/dist/external-findings-read.d.ts +1 -0
  95. package/dist/external-findings-read.d.ts.map +1 -1
  96. package/dist/external-findings-read.js +10 -0
  97. package/dist/external-findings-read.js.map +1 -1
  98. package/dist/external-findings.d.ts +2 -0
  99. package/dist/external-findings.d.ts.map +1 -1
  100. package/dist/external-findings.js.map +1 -1
  101. package/dist/external-import-contract.d.ts +4 -0
  102. package/dist/external-import-contract.d.ts.map +1 -1
  103. package/dist/external-import-contract.js +34 -10
  104. package/dist/external-import-contract.js.map +1 -1
  105. package/dist/finding-workflow.d.ts +2 -0
  106. package/dist/finding-workflow.d.ts.map +1 -1
  107. package/dist/finding-workflow.js +3 -0
  108. package/dist/finding-workflow.js.map +1 -1
  109. package/dist/github-advisories.d.ts.map +1 -1
  110. package/dist/github-advisories.js +5 -5
  111. package/dist/github-advisories.js.map +1 -1
  112. package/dist/github-dependabot-findings.d.ts +6 -0
  113. package/dist/github-dependabot-findings.d.ts.map +1 -0
  114. package/dist/github-dependabot-findings.js +247 -0
  115. package/dist/github-dependabot-findings.js.map +1 -0
  116. package/dist/github-findings.d.ts.map +1 -1
  117. package/dist/github-findings.js +11 -4
  118. package/dist/github-findings.js.map +1 -1
  119. package/dist/github-identifiers.d.ts +4 -0
  120. package/dist/github-identifiers.d.ts.map +1 -0
  121. package/dist/github-identifiers.js +9 -0
  122. package/dist/github-identifiers.js.map +1 -0
  123. package/dist/github.d.ts.map +1 -1
  124. package/dist/github.js +4 -6
  125. package/dist/github.js.map +1 -1
  126. package/dist/host-protocol.d.ts +1 -1
  127. package/dist/host-protocol.d.ts.map +1 -1
  128. package/dist/host-protocol.js +2 -2
  129. package/dist/host-protocol.js.map +1 -1
  130. package/dist/hosted-scan.d.ts.map +1 -1
  131. package/dist/hosted-scan.js +13 -6
  132. package/dist/hosted-scan.js.map +1 -1
  133. package/dist/import-scan.js +16 -16
  134. package/dist/import-scan.js.map +1 -1
  135. package/dist/index.d.ts +2 -0
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/index.js +2 -0
  138. package/dist/index.js.map +1 -1
  139. package/dist/knowledge-base.js +3 -0
  140. package/dist/knowledge-base.js.map +1 -1
  141. package/dist/mock-scan.d.ts +1 -2
  142. package/dist/mock-scan.d.ts.map +1 -1
  143. package/dist/mock-scan.js +12 -17
  144. package/dist/mock-scan.js.map +1 -1
  145. package/dist/models.d.ts +9 -1
  146. package/dist/models.d.ts.map +1 -1
  147. package/dist/models.js.map +1 -1
  148. package/dist/multiscan.d.ts.map +1 -1
  149. package/dist/multiscan.js +1 -6
  150. package/dist/multiscan.js.map +1 -1
  151. package/dist/native-json-findings.d.ts +30 -0
  152. package/dist/native-json-findings.d.ts.map +1 -0
  153. package/dist/native-json-findings.js +114 -0
  154. package/dist/native-json-findings.js.map +1 -0
  155. package/dist/opengrep-findings.d.ts +10 -0
  156. package/dist/opengrep-findings.d.ts.map +1 -0
  157. package/dist/opengrep-findings.js +198 -0
  158. package/dist/opengrep-findings.js.map +1 -0
  159. package/dist/patch-tui.d.ts.map +1 -1
  160. package/dist/patch-tui.js +2 -0
  161. package/dist/patch-tui.js.map +1 -1
  162. package/dist/publication.js +1 -2
  163. package/dist/publication.js.map +1 -1
  164. package/dist/record.d.ts +1 -0
  165. package/dist/record.d.ts.map +1 -1
  166. package/dist/record.js +10 -0
  167. package/dist/record.js.map +1 -1
  168. package/dist/result.d.ts +5 -3
  169. package/dist/result.d.ts.map +1 -1
  170. package/dist/result.js +9 -6
  171. package/dist/result.js.map +1 -1
  172. package/dist/scan-history-renderer.js +1 -1
  173. package/dist/scan-history-renderer.js.map +1 -1
  174. package/dist/scanner-import.d.ts +0 -1
  175. package/dist/scanner-import.d.ts.map +1 -1
  176. package/dist/scanner-import.js +9 -9
  177. package/dist/scanner-import.js.map +1 -1
  178. package/dist/security-policy.d.ts.map +1 -1
  179. package/dist/security-policy.js +16 -2
  180. package/dist/security-policy.js.map +1 -1
  181. package/dist/semgrep-findings.d.ts.map +1 -1
  182. package/dist/semgrep-findings.js +15 -82
  183. package/dist/semgrep-findings.js.map +1 -1
  184. package/docs/cli.md +55 -10
  185. package/docs/dedupe-records.md +15 -1
  186. package/docs/hosted-scans.md +14 -0
  187. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -71,6 +71,7 @@ import { prepareKnowledgeBase, readKnowledgeBaseSnapshot, } from "./knowledge-ba
71
71
  import { restoreScanKnowledge, scanInputIdentity } from "./scan-inputs.js";
72
72
  import { workflowDigest } from "./finding-workflow.js";
73
73
  import { CodexSecurityError, AuthenticationRequiredError, ConfigurationError, InvalidTargetError, IncompleteScanError, LocalPluginBootstrapError, OutputDirectoryError, OutputInsideProtectedRootError, PluginPythonUnavailableError, errorMessage, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
74
+ import { GHSA_ID } from "./github-identifiers.js";
74
75
  import { GITHUB_ADVISORY_STATES, importGitHubAdvisories, } from "./github-advisories.js";
75
76
  import { GITHUB_ALERT_STATES, importGitHubCodeScanningAlerts, } from "./github.js";
76
77
  import { importLinearIssues, isLinearIssueIdentifier, resolveLinearApiKey, } from "./linear.js";
@@ -1608,7 +1609,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1608
1609
  typeof saved["scanDir"] !== "string") {
1609
1610
  throw new CodexSecurityError("The workbench returned invalid scan resume context.");
1610
1611
  }
1611
- scanArguments = await prepareScanArgumentsFromRecipe(saved["recipe"], saved["scanId"], {
1612
+ scanArguments = await prepareScanArgumentsFromRecipe(saved["recipe"], "resume", {
1612
1613
  scanPrompt: typeof saved["userContext"] === "string"
1613
1614
  ? saved["userContext"]
1614
1615
  : undefined,
@@ -1618,7 +1619,6 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1618
1619
  if (scanArguments.knowledgeBasePaths.length > 0) {
1619
1620
  scanArguments.knowledgeBaseSnapshot = await restoreScanKnowledge(scanArguments.outputDir, scanArguments.repository, saved["recipe"]["scanInputs"]);
1620
1621
  }
1621
- scanArguments.parentScanId = undefined;
1622
1622
  // Resume uses the installed engine with the saved recipe and checkpoints.
1623
1623
  scanArguments.expectedPluginVersion = undefined;
1624
1624
  scanArguments.verbose = options.verbose;
@@ -1709,7 +1709,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1709
1709
  });
1710
1710
  return finishScan(outcome, format, incurError, "SCAN_IMPORT_FAILED");
1711
1711
  }
1712
- scanArguments = await prepareScanArgumentsFromRecipe(recipe, parentScanId, {
1712
+ scanArguments = await prepareScanArgumentsFromRecipe(recipe, "rerun", {
1713
1713
  scanPromptFile: options.scanPromptFile === undefined
1714
1714
  ? undefined
1715
1715
  : resolveCliPath(dependencies.currentDirectory(), options.scanPromptFile),
@@ -1719,6 +1719,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1719
1719
  }, dependencies.currentDirectory());
1720
1720
  scanArguments.verbose = options.verbose;
1721
1721
  scanArguments.showCost = options.showCost;
1722
+ scanArguments.parentScanId = parentScanId;
1722
1723
  scanArguments.rerunInputIdentity = isJsonObject(recipe)
1723
1724
  ? (recipe["scanInputs"] ?? null)
1724
1725
  : null;
@@ -1771,7 +1772,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1771
1772
  },
1772
1773
  })
1773
1774
  .command("compare", {
1774
- description: "Match and compare findings and coverage between scans.",
1775
+ description: "Match and compare findings between scans.",
1775
1776
  destructive: true,
1776
1777
  mcp: false,
1777
1778
  args: z.object({
@@ -2297,14 +2298,14 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2297
2298
  let disabledImportInvocation = false;
2298
2299
  function registerFindingPublication() {
2299
2300
  publication.command("findings", {
2300
- description: "Preview and import selected Wiz, Snyk, Semgrep Code, Endor, or GitHub findings locally or to Cloud.",
2301
- hint: "For Snyk Open Source SCA vulnerabilities only, prefer native snyk test JSON or an official plugin snyk-findings-export/v1 bundle; Open Source SARIF 2.1.0 is also supported. Snyk licenses, Code, Container, IaC and platform backlogs are unsupported. For Semgrep Code, supply native JSON or SARIF and --source-repository-url. For Endor, supply native Finding JSON or endorctl SARIF 2.1.0. For GitHub, supply complete JSON/JSONL saved by import github or import github-advisories. GHSA advisories do not establish an installed dependency or applicability. For Wiz, prefer a native package vulnerability JSON report or named SAST/repository-secret/IaC JSON collections with repository metadata. Normalized JSONL and repository package-vulnerability CSV (SCA only, GitHub repositories) are also supported. Gzip is supported for each format; Wiz CSV does not cover SAST or cloud posture. Other Wiz CSV profiles, scan events, workload secrets, and cloud configuration exports are not supported. --to local stores unassessed evidence for a local repository path without Cloud login. --full-output requires --format json or --format jsonl.\nExample: codex-security publish findings selected-wiz.json --to local --repository ./project --provider wiz --source-key TENANT_ID/vulnerability-finding --dry-run --format json",
2301
+ description: "Preview and import a saved scanner report locally or to Cloud.",
2302
+ hint: "Choose the reader with --provider and keep --source-key stable for reimports. See the scanner import guide for accepted formats, repository requirements and export examples: https://github.com/openai/codex-security/blob/main/docs/scanner-imports/schema-guide.md. Gzip is supported. --to local stores unassessed evidence without Cloud login. --full-output requires --format json or --format jsonl.\nExample: codex-security publish findings selected-wiz.json --to local --repository ./project --provider wiz --source-key TENANT_ID/vulnerability-finding --dry-run --format json",
2302
2303
  destructive: true,
2303
2304
  mcp: false,
2304
2305
  args: z.object({
2305
2306
  file: z
2306
2307
  .string()
2307
- .describe("Snyk native test JSON, plugin SCA bundle or Open Source SARIF; Semgrep Code JSON/SARIF; Endor Finding JSON/endorctl SARIF; saved GitHub import output; native Wiz JSON, normalized JSONL, or repository package-vulnerability CSV."),
2308
+ .describe("Saved report in a format accepted by the selected reader."),
2308
2309
  }),
2309
2310
  options: z.object({
2310
2311
  to: z
@@ -2313,10 +2314,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2313
2314
  repository: optionValue("--repository").describe("Local repository path for --to local; authorized repository ID or URL for --to cloud."),
2314
2315
  provider: z
2315
2316
  .enum(EXTERNAL_FINDINGS_READERS)
2316
- .describe("Provider that produced these findings."),
2317
+ .describe("Select the file reader for this report. OpenGrep findings use the semgrep storage provider."),
2317
2318
  sourceRepositoryUrl: optionValue("--source-repository-url")
2318
2319
  .optional()
2319
- .describe("Required for Semgrep: source repository URL, checked against the Cloud destination or configured local Git remotes."),
2320
+ .describe("Required for Semgrep and OpenGrep: source repository URL, checked against the Cloud destination or configured local Git remotes."),
2320
2321
  sourceKey: optionValue("--source-key").describe("Stable vendor tenant and finding namespace; not a project selection filter."),
2321
2322
  dryRun: z
2322
2323
  .boolean()
@@ -2362,6 +2363,17 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2362
2363
  : `Publish these ${preview.findings.length} findings`;
2363
2364
  return prompt.confirm(`${action}${preview.excluded.length ? ` and skip ${preview.excluded.length} excluded records` : ""}?`, false, controller.signal);
2364
2365
  };
2366
+ const showScannerReport = (preview) => {
2367
+ if (options.provider !== "opengrep")
2368
+ return;
2369
+ writeDiagnostic("Reader: OpenGrep (stored provider: semgrep)\n");
2370
+ const diagnostics = preview.report?.["errors"];
2371
+ if (Array.isArray(diagnostics) && diagnostics.length) {
2372
+ writeDiagnostic(`Scanner diagnostics: ${diagnostics.length}. Scan coverage may be incomplete.\n`);
2373
+ for (const diagnostic of diagnostics)
2374
+ writeDiagnostic(`${diagnosticValue(JSON.stringify(diagnostic))}\n`);
2375
+ }
2376
+ };
2365
2377
  let lastProgress = "";
2366
2378
  const onProgress = (event) => {
2367
2379
  if (errorOutput.isTTY !== true)
@@ -2397,6 +2409,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2397
2409
  });
2398
2410
  const { preview } = prepared;
2399
2411
  const showPreview = () => {
2412
+ showScannerReport(preview);
2400
2413
  writeDiagnostic(`Local repository: ${diagnosticValue(preview.repository)}\nSource: ${preview.source.provider} / ${diagnosticValue(preview.source.source_key)}\nRead: ${preview.read} Ready: ${preview.findings.length} Excluded: ${preview.excluded.length}\n`);
2401
2414
  for (const excluded of preview.excluded)
2402
2415
  writeDiagnostic(`Excluded item ${excluded.position}: ${diagnosticValue(excluded.reason)}\n`);
@@ -2434,6 +2447,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2434
2447
  });
2435
2448
  const { preview } = prepared;
2436
2449
  const showPreview = () => {
2450
+ showScannerReport(preview);
2437
2451
  writeDiagnostic(`Cloud API: ${diagnosticValue(preview.cloudApiUrl)}\nAccount: ${diagnosticValue(preview.accountId)}\nDestination: ${diagnosticValue(preview.destination.url)} (${diagnosticValue(preview.destination.id)})\nEnvironment: ${[...new Set(preview.requests.map((request) => request.repository.environment_id))].map(diagnosticValue).join(", ")}\nSource: ${preview.source.provider} / ${diagnosticValue(preview.source.source_key)}\nRead: ${preview.read} Ready: ${preview.findings.length} Excluded: ${preview.excluded.length}${preview.resumed ? "\nResuming the saved submission." : ""}\n`);
2438
2452
  if (preview.cloudUrl)
2439
2453
  writeDiagnostic(`Cloud app: ${diagnosticValue(preview.cloudUrl)}\n`);
@@ -2613,7 +2627,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2613
2627
  }),
2614
2628
  options: z.object({
2615
2629
  githubAdvisory: z
2616
- .array(optionValue("--github-advisory").regex(/^GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$/iu, "GitHub advisory IDs must use GHSA-xxxx-xxxx-xxxx form."))
2630
+ .array(optionValue("--github-advisory").regex(GHSA_ID, "GitHub advisory IDs must use GHSA-xxxx-xxxx-xxxx form."))
2617
2631
  .default([])
2618
2632
  .describe("Exact GHSA ID; repeat to select a subset. Required for global advisories."),
2619
2633
  githubAdvisorySource: z
@@ -3769,7 +3783,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3769
3783
  errorOutput.write(`codex-security: ${scan.scanId}: Original session logs are unavailable. Preserving this attempt and starting a new one.\n`);
3770
3784
  return undefined;
3771
3785
  }
3772
- const recipe = await prepareScanArgumentsFromRecipe(saved["recipe"], scan.scanId, {
3786
+ const recipe = await prepareScanArgumentsFromRecipe(saved["recipe"], "resume", {
3773
3787
  scanPrompt: typeof saved["userContext"] === "string"
3774
3788
  ? saved["userContext"]
3775
3789
  : undefined,
@@ -3846,14 +3860,17 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3846
3860
  .describe("Saved artifact to export."),
3847
3861
  scan: optionValue("--scan")
3848
3862
  .optional()
3849
- .describe("Saved scan ID or unique prefix; cannot be combined with a result directory."),
3863
+ .describe("Saved scan ID, unique prefix, or latest completed scan ('latest')."),
3850
3864
  exportFormat: z
3851
- .enum(["csv", "json", "sarif", "md"])
3865
+ .enum(["csv", "json", "sarif", "md", "servicenow-avit"])
3852
3866
  .optional()
3853
- .describe("Findings: csv, json, or sarif (default); threat-model: md (default)."),
3867
+ .describe("Findings: csv, json, servicenow-avit, or sarif (default). Threat models use md."),
3868
+ avitTemplate: optionValue("--avit-template")
3869
+ .optional()
3870
+ .describe("Per-application CSV template required for servicenow-avit exports."),
3854
3871
  output: optionValue("--output")
3855
3872
  .optional()
3856
- .describe("FILE or '-' for stdout (default: results.sarif, findings.json, findings.csv, or threatmodel.md)."),
3873
+ .describe("FILE or '-' for stdout (default: results.sarif, findings.json, findings.csv, servicenow-avit.csv, or threatmodel.md)."),
3857
3874
  sourceRoot: optionValue("--source-root")
3858
3875
  .optional()
3859
3876
  .describe("Repository checkout used for SARIF source-line fingerprints."),
@@ -3874,7 +3891,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3874
3891
  if (args.scanDir !== undefined && options.scan !== undefined) {
3875
3892
  throw new CodexSecurityError("--scan cannot be combined with a result directory.");
3876
3893
  }
3877
- const format = resolveArtifactFormat(options.artifact, options.exportFormat);
3894
+ const format = resolveArtifactFormat(options.artifact, options.exportFormat, options.avitTemplate);
3878
3895
  const sourceRoot = options.sourceRoot === undefined
3879
3896
  ? undefined
3880
3897
  : resolveCliPath(currentDirectory, options.sourceRoot);
@@ -3883,31 +3900,36 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3883
3900
  : [currentDirectory, sourceRoot];
3884
3901
  let scanDir = args.scanDir;
3885
3902
  if (scanDir === undefined) {
3886
- const scanId = options.scan ??
3887
- (await latestScans(1, "complete", options.python, protectedRoot))?.[0]?.scanId;
3903
+ let scanId = options.scan;
3904
+ if (!scanId || scanId === "latest") {
3905
+ const scans = await latestScans(1, "complete", options.python, protectedRoot);
3906
+ scanId = scans?.[0]?.scanId;
3907
+ }
3888
3908
  if (scanId === undefined)
3889
3909
  return;
3890
- scanDir = await resolveSavedArtifactDirectory(scanId, options.artifact, format, (args) => dependencies.runWorkbench(args, undefined, undefined, options.python, protectedRoot));
3910
+ scanDir = await resolveSavedArtifactDirectory(scanId, options.artifact, (args) => dependencies.runWorkbench(args, undefined, undefined, options.python, protectedRoot));
3891
3911
  }
3892
- const arguments_ = {
3912
+ const destination = options.output ?? EXPORT_DEFAULT_OUTPUTS[format];
3913
+ const outputPath = destination === "-"
3914
+ ? "-"
3915
+ : resolveCliPath(currentDirectory, destination);
3916
+ const prepared = await resolveArtifactExportOutput({
3893
3917
  scanDir: resolveCliPath(currentDirectory, scanDir),
3894
3918
  artifact: options.artifact,
3895
3919
  format,
3896
- output: options.output === "-"
3897
- ? "-"
3898
- : resolveCliPath(currentDirectory, options.output ?? EXPORT_DEFAULT_OUTPUTS[format]),
3920
+ output: outputPath,
3899
3921
  sourceRoot,
3922
+ avitTemplate: options.avitTemplate,
3900
3923
  pythonPath: options.python,
3901
- };
3902
- const prepared = await resolveArtifactExportOutput(arguments_, dependencies.currentDirectory());
3903
- const contents = await dependencies.exportFindings(prepared, output);
3904
- if (arguments_.output === "-") {
3924
+ }, currentDirectory);
3925
+ const contents = await dependencies.exportFindings(prepared, output, errorOutput);
3926
+ if (outputPath === "-") {
3905
3927
  if (contents !== undefined) {
3906
3928
  await writeCliOutput(output, Buffer.from(contents));
3907
3929
  }
3908
3930
  }
3909
3931
  else {
3910
- errorOutput.write(`${arguments_.format.toUpperCase()}: ${arguments_.output}\n`);
3932
+ errorOutput.write(`${format.toUpperCase()}: ${outputPath}\n`);
3911
3933
  }
3912
3934
  exitCode = 0;
3913
3935
  }
@@ -4734,25 +4756,19 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
4734
4756
  !argv.includes("--schema")) {
4735
4757
  return `${command} does not support noninteractive JSON output; run it without --json, --format json, or --format jsonl.`;
4736
4758
  }
4737
- if (command === "export" &&
4738
- structuredOutput &&
4739
- argv.some((value, index) => value === "--output=-" ||
4740
- (value === "--output" && argv[index + 1] === "-")) &&
4741
- argv.some((value, index) => value === "--export-format=csv" ||
4742
- value === "--exportFormat=csv" ||
4743
- ((value === "--export-format" || value === "--exportFormat") &&
4744
- argv[index + 1] === "csv"))) {
4745
- return "CSV stdout cannot be combined with JSON output; write CSV to a file or omit --json.";
4746
- }
4747
- if (command === "export" &&
4748
- structuredOutput &&
4749
- argv.some((value, index) => value === "--output=-" ||
4750
- (value === "--output" && argv[index + 1] === "-")) &&
4751
- argv.some((value, index) => value === "--artifact=threat-model" ||
4752
- (value === "--artifact" && argv[index + 1] === "threat-model") ||
4753
- value === "--export-format=md" ||
4754
- (value === "--export-format" && argv[index + 1] === "md"))) {
4755
- return "Markdown stdout cannot be combined with JSON output; write Markdown to a file or omit --json.";
4759
+ if (command === "export" && structuredOutput) {
4760
+ const hasValue = (flag, value) => argv.some((arg, index) => arg === `${flag}=${value}` ||
4761
+ (arg === flag && argv[index + 1] === value));
4762
+ if (hasValue("--output", "-")) {
4763
+ if (["csv", "servicenow-avit"].some((format) => hasValue("--export-format", format) ||
4764
+ hasValue("--exportFormat", format))) {
4765
+ return "CSV stdout cannot be combined with JSON output; write CSV to a file or omit --json.";
4766
+ }
4767
+ if (hasValue("--artifact", "threat-model") ||
4768
+ hasValue("--export-format", "md")) {
4769
+ return "Markdown stdout cannot be combined with JSON output; write Markdown to a file or omit --json.";
4770
+ }
4771
+ }
4756
4772
  }
4757
4773
  if (command === "scan" && !argv.includes("--schema")) {
4758
4774
  if (argv.some((value) => value === "--filter-output" || value.startsWith("--filter-output="))) {
@@ -5094,13 +5110,12 @@ async function runScanImport(options, errorOutput, dependencies) {
5094
5110
  removeSignals();
5095
5111
  }
5096
5112
  }
5097
- async function prepareScanArgumentsFromRecipe(recipe, parentScanId, { scanPrompt, scanPromptFile, validationPromptFile, }, directory) {
5113
+ async function prepareScanArgumentsFromRecipe(recipe, operation, { scanPrompt, scanPromptFile, validationPromptFile, }, directory) {
5098
5114
  if (recipe === undefined || !isJsonObject(recipe)) {
5099
5115
  throw new CodexSecurityError("This scan does not have a saved launch recipe.");
5100
5116
  }
5101
- if (recipe["requiresScanPrompt"] === true &&
5102
- scanPrompt === undefined &&
5103
- scanPromptFile === undefined) {
5117
+ const requiresRerunPrompt = operation === "rerun" && recipe["requiresScanPrompt"] === true;
5118
+ if (requiresRerunPrompt && scanPromptFile === undefined) {
5104
5119
  throw new CodexSecurityError("This scan used additional instructions. Supply --scan-prompt-file to rerun it.");
5105
5120
  }
5106
5121
  if (recipe["validationMode"] === "custom" &&
@@ -5193,7 +5208,7 @@ async function prepareScanArgumentsFromRecipe(recipe, parentScanId, { scanPrompt
5193
5208
  throw new CodexSecurityError("The saved scan recipe contains invalid launch settings.");
5194
5209
  }
5195
5210
  const prompts = await resolveScanPrompts({ scanPrompt, scanPromptFile, validationPromptFile }, repository, directory);
5196
- if (recipe["requiresScanPrompt"] === true && !prompts.scanPrompt?.trim()) {
5211
+ if (requiresRerunPrompt && !prompts.scanPrompt?.trim()) {
5197
5212
  throw new CodexSecurityError("This scan used additional instructions. The --scan-prompt-file must not be empty.");
5198
5213
  }
5199
5214
  return {
@@ -5225,7 +5240,6 @@ async function prepareScanArgumentsFromRecipe(recipe, parentScanId, { scanPrompt
5225
5240
  maxCostUsd,
5226
5241
  maxTimeMinutes: maxTimeMinutes.data,
5227
5242
  dryRun: false,
5228
- parentScanId,
5229
5243
  ...(recipe["mock"] === true ? { mock: true } : {}),
5230
5244
  expectedPluginVersion: typeof recipe["pluginVersion"] === "string"
5231
5245
  ? recipe["pluginVersion"]
@@ -5468,7 +5482,7 @@ async function selectSavedFindings(identifiers, requestedScanId, severity, depen
5468
5482
  };
5469
5483
  }
5470
5484
  async function readSavedFindings(scanId, workbench) {
5471
- const directory = await resolveSavedArtifactDirectory(scanId, "findings", "json", workbench);
5485
+ const directory = await resolveSavedArtifactDirectory(scanId, "findings", workbench);
5472
5486
  const { findings } = await loadContract(directory, {
5473
5487
  pluginRoot: await bundledPluginRoot(),
5474
5488
  expectedScanId: scanId,
@@ -7819,7 +7833,7 @@ function printScanSummary(result, progress, errorOutput, color, showCost, deepSc
7819
7833
  ? ""
7820
7834
  : ` ${paint("THREAT MODEL", "1;36")} ${paint(errorMessage(threatModelPath), 4)}\n`) +
7821
7835
  `\n ${paint("FINDINGS", 1)} ${paint(`${findingCount}${findingSummary === "" ? "" : ` (${findingSummary})`}`, findingColor)}\n` +
7822
- ` ${paint("SCOPE", 1)} ${formatCoverageScope(result.coverage)}\n` +
7836
+ ` ${paint("SCOPE", 1)} ${formatCoverageScope({ mode: result.mode, ...result.manifest.scan.scope, explicitExclusions: result.review.excludedPaths.map((pattern) => ({ pattern, reason: "Excluded from review" })) })}\n` +
7823
7837
  (deepScanStop === undefined
7824
7838
  ? ""
7825
7839
  : ` ${paint("STOPPED", 1)} ${deepScanStop.reason}\n`) +