@openai/codex-security 0.4.0 → 0.5.0

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 (180) hide show
  1. package/README.md +45 -9
  2. package/_bundled_plugin/.mcp.json +1 -0
  3. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  4. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  5. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  6. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  7. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  8. package/_bundled_plugin/references/core-scan.md +2 -0
  9. package/_bundled_plugin/references/final-report.md +5 -1
  10. package/_bundled_plugin/references/investigation-time-budget.md +11 -0
  11. package/_bundled_plugin/references/sarif-adapter.md +1 -0
  12. package/_bundled_plugin/references/scan-prologue.md +2 -6
  13. package/_bundled_plugin/references/scan-runtime.md +15 -0
  14. package/_bundled_plugin/references/threat-model.md +2 -0
  15. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +5 -1
  16. package/_bundled_plugin/scripts/deep_scan_workbench.py +7 -0
  17. package/_bundled_plugin/scripts/finalize_scan_contract.py +80 -43
  18. package/_bundled_plugin/scripts/finding_preview.py +5 -3
  19. package/_bundled_plugin/scripts/generate_rank_input.py +1 -0
  20. package/_bundled_plugin/scripts/launch_codex_security_mcp +39 -4
  21. package/_bundled_plugin/scripts/snapshot_sqlite.py +7 -0
  22. package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -1
  23. package/_bundled_plugin/scripts/workbench_cli.py +0 -3
  24. package/_bundled_plugin/scripts/workbench_constants.py +4 -0
  25. package/_bundled_plugin/scripts/workbench_db.py +56 -33
  26. package/_bundled_plugin/scripts/workbench_progress.py +0 -50
  27. package/_bundled_plugin/scripts/workbench_scan_history.py +3 -2
  28. package/_bundled_plugin/scripts/workbench_scan_start.py +12 -4
  29. package/_bundled_plugin/scripts/workbench_scan_usage.py +190 -30
  30. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  31. package/_bundled_plugin/scripts/workbench_source_excerpt.py +74 -51
  32. package/_bundled_plugin/scripts/workbench_source_scopes.py +388 -0
  33. package/_bundled_plugin/scripts/workbench_target.py +7 -5
  34. package/_bundled_plugin/scripts/workbench_validation.py +37 -1
  35. package/_bundled_plugin/shared/workbench-history-repairs.json +19 -0
  36. package/_bundled_plugin/shared/workbench-migrations.json +5 -0
  37. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +1 -1
  38. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +4 -2
  39. package/_bundled_plugin/skills/security-scan/SKILL.md +3 -1
  40. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
  41. package/dist/api.d.ts +3 -2
  42. package/dist/api.d.ts.map +1 -1
  43. package/dist/api.js +54 -36
  44. package/dist/api.js.map +1 -1
  45. package/dist/artifact-export.d.ts +2 -1
  46. package/dist/artifact-export.d.ts.map +1 -1
  47. package/dist/artifact-export.js +38 -23
  48. package/dist/artifact-export.js.map +1 -1
  49. package/dist/classify-severity-records.d.ts +76 -0
  50. package/dist/classify-severity-records.d.ts.map +1 -0
  51. package/dist/classify-severity-records.js +141 -0
  52. package/dist/classify-severity-records.js.map +1 -0
  53. package/dist/classify-severity.d.ts +1 -23
  54. package/dist/classify-severity.d.ts.map +1 -1
  55. package/dist/classify-severity.js +3 -24
  56. package/dist/classify-severity.js.map +1 -1
  57. package/dist/cli-help.d.ts.map +1 -1
  58. package/dist/cli-help.js +2 -0
  59. package/dist/cli-help.js.map +1 -1
  60. package/dist/cli.d.ts +4 -2
  61. package/dist/cli.d.ts.map +1 -1
  62. package/dist/cli.js +136 -147
  63. package/dist/cli.js.map +1 -1
  64. package/dist/cloud-publish.js +1 -1
  65. package/dist/cloud-publish.js.map +1 -1
  66. package/dist/codex-sdk-environment.js +1 -1
  67. package/dist/codex-sdk-environment.js.map +1 -1
  68. package/dist/config.d.ts +12 -0
  69. package/dist/config.d.ts.map +1 -1
  70. package/dist/config.js +10 -4
  71. package/dist/config.js.map +1 -1
  72. package/dist/contract.d.ts +5 -0
  73. package/dist/contract.d.ts.map +1 -1
  74. package/dist/contract.js +65 -17
  75. package/dist/contract.js.map +1 -1
  76. package/dist/cost-model.d.ts.map +1 -1
  77. package/dist/cost-model.js +7 -2
  78. package/dist/cost-model.js.map +1 -1
  79. package/dist/custom-validation-prompt.js +3 -3
  80. package/dist/custom-validation-prompt.js.map +1 -1
  81. package/dist/deduplication/deduplication-prompts.d.ts +1 -1
  82. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  83. package/dist/deduplication/deduplication-prompts.js +2 -2
  84. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  85. package/dist/deduplication/records.js +1 -1
  86. package/dist/deduplication/records.js.map +1 -1
  87. package/dist/deduplication/scan.d.ts.map +1 -1
  88. package/dist/deduplication/scan.js +10 -9
  89. package/dist/deduplication/scan.js.map +1 -1
  90. package/dist/deep-config.d.ts +4 -1
  91. package/dist/deep-config.d.ts.map +1 -1
  92. package/dist/deep-config.js +21 -1
  93. package/dist/deep-config.js.map +1 -1
  94. package/dist/findings-import.d.ts +1 -1
  95. package/dist/findings-import.d.ts.map +1 -1
  96. package/dist/findings-import.js +3 -3
  97. package/dist/findings-import.js.map +1 -1
  98. package/dist/git-remote.d.ts +10 -0
  99. package/dist/git-remote.d.ts.map +1 -0
  100. package/dist/git-remote.js +24 -0
  101. package/dist/git-remote.js.map +1 -0
  102. package/dist/github.d.ts.map +1 -1
  103. package/dist/github.js +5 -7
  104. package/dist/github.js.map +1 -1
  105. package/dist/host-protocol.js +1 -1
  106. package/dist/host-protocol.js.map +1 -1
  107. package/dist/host-records-protocol.d.ts +15 -0
  108. package/dist/host-records-protocol.d.ts.map +1 -0
  109. package/dist/host-records-protocol.js +15 -0
  110. package/dist/host-records-protocol.js.map +1 -0
  111. package/dist/hosted-scan.d.ts +1 -6
  112. package/dist/hosted-scan.d.ts.map +1 -1
  113. package/dist/hosted-scan.js +2 -2
  114. package/dist/hosted-scan.js.map +1 -1
  115. package/dist/index.d.ts +4 -0
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +2 -0
  118. package/dist/index.js.map +1 -1
  119. package/dist/knowledge-base.d.ts.map +1 -1
  120. package/dist/knowledge-base.js +87 -7
  121. package/dist/knowledge-base.js.map +1 -1
  122. package/dist/multiscan.d.ts.map +1 -1
  123. package/dist/multiscan.js +62 -28
  124. package/dist/multiscan.js.map +1 -1
  125. package/dist/patch-publication.d.ts +26 -0
  126. package/dist/patch-publication.d.ts.map +1 -0
  127. package/dist/patch-publication.js +105 -0
  128. package/dist/patch-publication.js.map +1 -0
  129. package/dist/patch-tui.d.ts.map +1 -1
  130. package/dist/patch-tui.js +4 -1
  131. package/dist/patch-tui.js.map +1 -1
  132. package/dist/project-config-schema.d.ts +2 -0
  133. package/dist/project-config-schema.d.ts.map +1 -1
  134. package/dist/project-config-schema.js +1 -0
  135. package/dist/project-config-schema.js.map +1 -1
  136. package/dist/project-config.d.ts +1 -0
  137. package/dist/project-config.d.ts.map +1 -1
  138. package/dist/project-config.js +16 -6
  139. package/dist/project-config.js.map +1 -1
  140. package/dist/publication.d.ts.map +1 -1
  141. package/dist/publication.js +135 -19
  142. package/dist/publication.js.map +1 -1
  143. package/dist/publish.d.ts.map +1 -1
  144. package/dist/publish.js +39 -25
  145. package/dist/publish.js.map +1 -1
  146. package/dist/runtime.d.ts.map +1 -1
  147. package/dist/runtime.js +83 -22
  148. package/dist/runtime.js.map +1 -1
  149. package/dist/scan-settings.d.ts +1 -0
  150. package/dist/scan-settings.d.ts.map +1 -1
  151. package/dist/scan-settings.js +7 -1
  152. package/dist/scan-settings.js.map +1 -1
  153. package/dist/scan-time-budget.d.ts +9 -0
  154. package/dist/scan-time-budget.d.ts.map +1 -0
  155. package/dist/scan-time-budget.js +16 -0
  156. package/dist/scan-time-budget.js.map +1 -0
  157. package/dist/severity-review.d.ts +29 -0
  158. package/dist/severity-review.d.ts.map +1 -0
  159. package/dist/severity-review.js +47 -0
  160. package/dist/severity-review.js.map +1 -0
  161. package/dist/validation-records.d.ts +38 -0
  162. package/dist/validation-records.d.ts.map +1 -0
  163. package/dist/validation-records.js +76 -0
  164. package/dist/validation-records.js.map +1 -0
  165. package/dist/version.d.ts.map +1 -1
  166. package/dist/version.js +4 -2
  167. package/dist/version.js.map +1 -1
  168. package/dist/worker-progress.d.ts +2 -6
  169. package/dist/worker-progress.d.ts.map +1 -1
  170. package/dist/worker-progress.js +1 -43
  171. package/dist/worker-progress.js.map +1 -1
  172. package/docs/classify-severity-records.md +89 -0
  173. package/docs/cli.md +269 -33
  174. package/docs/validate-records.md +69 -0
  175. package/package.json +12 -10
  176. package/schemas/project-config.schema.json +7 -1
  177. package/_bundled_plugin/preflight/capability-profiles.toml +0 -76
  178. package/_bundled_plugin/references/config-preflight.md +0 -93
  179. package/_bundled_plugin/references/desktop-config-preflight.md +0 -11
  180. package/_bundled_plugin/scripts/config_preflight.py +0 -911
package/dist/cli.js CHANGED
@@ -28,11 +28,15 @@ import { isRecord as isJsonObject } from "./record.js";
28
28
  import { suggestOwnersInternal } from "./suggest-owners.js";
29
29
  import { parseImportedFindings } from "./findings-import.js";
30
30
  import { publishScanToCustom } from "./custom-publish.js";
31
+ import { publishPatchReview, resolvePatchReviewPublisher, } from "./patch-publication.js";
31
32
  import { DEFAULT_DEDUPE_CONCURRENCY } from "./deduplication/deduplication.js";
32
33
  import { savedScanWorkbench } from "./saved-scan-bootstrap.js";
33
34
  import { deduplicateScanInternal } from "./deduplication/scan.js";
34
35
  import { runRecordsProtocol } from "./deduplication/records-protocol.js";
36
+ import { runHostRecordsProtocol } from "./host-records-protocol.js";
37
+ import { classifySeverityRecords, } from "./classify-severity-records.js";
35
38
  import { runHostedScanProtocol } from "./hosted-scan-protocol.js";
39
+ import { runValidationRecordsProtocol } from "./validation-records.js";
36
40
  import { classifyScanSeverityInternal, classifyScanDirectorySeverityInternal, } from "./classify-scan-severity.js";
37
41
  import { resolveCompletedScan, resolveWorkflowScan, } from "./saved-scan.js";
38
42
  import { publishFindingsCsvToCloud, publishScanToCloud, } from "./cloud-publish.js";
@@ -69,7 +73,7 @@ import { resolveTrustedExecutable } from "./trusted-executable.js";
69
73
  import { BUNDLED_PLUGIN_VERSION, checkForUpdate, CODEX_EXECUTABLE_VERSION, CODEX_SDK_VERSION, formatUpdateNotice, updateNoticeEnabled, VERSION, } from "./version.js";
70
74
  import { readProjectConfig, resolveScanSettings, projectScopeTarget, configurationSources, projectConfigStarter, } from "./project-config.js";
71
75
  import { resolveConfigPath } from "./config-path.js";
72
- import { resolveDeepScanConfig } from "./deep-config.js";
76
+ import { deepScanOptions, resolveDeepScanConfig } from "./deep-config.js";
73
77
  import { SCAN_MODES } from "./scan-modes.js";
74
78
  import { DEEP_SCAN_SETTINGS, DeepScanSettingsSchema, DEFAULT_SCAN_AUTH, FailureSeveritySchema, REPORTABLE_SEVERITIES, SCAN_SEVERITIES, ScanSettingsSchema, pickScanSettings, meetsSeverity, } from "./scan-settings.js";
75
79
  const PROGRESS_REFRESH_MILLISECONDS = 1_000;
@@ -116,7 +120,13 @@ const PROJECT_CONFIG_OPTION = optionValue("--config")
116
120
  .describe("Load a trusted YAML/JSON file (default: CODEX_SECURITY_PROJECT_CONFIG, otherwise no file).");
117
121
  const EXPORT_DEFAULT_OUTPUTS = ARTIFACT_EXPORT_FILENAMES;
118
122
  const PROVIDER_OPTION = z
119
- .enum(["openai", "openrouter", "fireworks", "amazon-bedrock"])
123
+ .enum([
124
+ "openai",
125
+ "openrouter",
126
+ "fireworks",
127
+ "cheaperinference",
128
+ "amazon-bedrock",
129
+ ])
120
130
  .default("openai")
121
131
  .describe("Inference provider for scans.");
122
132
  const positiveInteger = z.number().int().positive();
@@ -656,7 +666,7 @@ const DEFAULT_DEPENDENCIES = {
656
666
  return options?.trim === false ? stdout : stdout.trim();
657
667
  },
658
668
  exportFindings: runArtifactExport,
659
- runWorkbench: async (args, input, signal, pythonPath) => {
669
+ runWorkbench: async (args, input, signal, pythonPath, protectedRoot) => {
660
670
  const environment = {
661
671
  ...exportEnvironment(),
662
672
  CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(),
@@ -665,6 +675,7 @@ const DEFAULT_DEPENDENCIES = {
665
675
  python: await resolvePluginPython({
666
676
  configuredPath: pythonPath,
667
677
  environment,
678
+ protectedRoot,
668
679
  signal,
669
680
  }),
670
681
  pluginRoot: await bundledPluginRoot(),
@@ -1000,7 +1011,10 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
1000
1011
  }
1001
1012
  }
1002
1013
  export async function main(argv = process.argv.slice(2), output = process.stdout, errorOutput = process.stderr, dependencies = DEFAULT_DEPENDENCIES) {
1003
- if (((argv[0] === "dedupe" && argv.includes("--records")) ||
1014
+ if ((((argv[0] === "dedupe" ||
1015
+ argv[0] === "validate" ||
1016
+ argv[0] === "classify-severity") &&
1017
+ argv.includes("--records")) ||
1004
1018
  (argv[0] === "scan" &&
1005
1019
  argv.some((arg) => arg === "--host" || arg.startsWith("--host=")))) &&
1006
1020
  !argv.includes("--help") &&
@@ -1009,14 +1023,21 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1009
1023
  if (argv.length !== 2 || (argv[0] === "scan" && argv[1] !== "--host")) {
1010
1024
  errorOutput.write(argv[0] === "scan"
1011
1025
  ? "codex-security: --host must be used alone with scan.\n"
1012
- : "codex-security: --records must be used alone with dedupe.\n");
1026
+ : `codex-security: --records must be used alone with ${argv[0]}.\n`);
1013
1027
  return 2;
1014
1028
  }
1015
1029
  const controller = new AbortController();
1016
1030
  const removeSignals = listenForAbort(dependencies, controller);
1017
1031
  let exitCode;
1018
1032
  try {
1019
- const code = await (argv[0] === "scan" ? runHostedScanProtocol : runRecordsProtocol)(dependencies.recordsInput ?? process.stdin, output, controller.signal);
1033
+ const runProtocol = argv[0] === "scan"
1034
+ ? runHostedScanProtocol
1035
+ : argv[0] === "validate"
1036
+ ? runValidationRecordsProtocol
1037
+ : runRecordsProtocol;
1038
+ const code = argv[0] === "classify-severity"
1039
+ ? await runHostRecordsProtocol(dependencies.recordsInput ?? process.stdin, output, (value, options) => classifySeverityRecords(value, options), controller.signal)
1040
+ : await runProtocol(dependencies.recordsInput ?? process.stdin, output, controller.signal);
1020
1041
  exitCode =
1021
1042
  controller.signal.reason === "SIGINT"
1022
1043
  ? 130
@@ -1067,9 +1088,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1067
1088
  return incurError({ code, message: outcome.error, exitCode });
1068
1089
  };
1069
1090
  const runImport = (options) => runScanImport(options, errorOutput, dependencies);
1070
- const history = async (args, select = (value) => value, pythonPath) => {
1091
+ const history = async (args, select = (value) => value, pythonPath, protectedRoot) => {
1071
1092
  try {
1072
- return await select(await dependencies.runWorkbench(args, undefined, undefined, pythonPath));
1093
+ return await select(await dependencies.runWorkbench(args, undefined, undefined, pythonPath, protectedRoot));
1073
1094
  }
1074
1095
  catch (error) {
1075
1096
  errorOutput.write(`codex-security: ${diagnosticLines(error)}\n`);
@@ -1077,7 +1098,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1077
1098
  throw error;
1078
1099
  }
1079
1100
  };
1080
- const latestScans = async (count = 1, status = "complete", pythonPath) => {
1101
+ const latestScans = async (count = 1, status = "complete", pythonPath, protectedRoot) => {
1081
1102
  const result = await history(workbenchArgs("list-scans", {
1082
1103
  repository: dependencies.currentDirectory(),
1083
1104
  status: status === "complete" ? "complete" : undefined,
@@ -1090,7 +1111,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1090
1111
  : `At least ${count} ${kind} scans are required for the current repository.`);
1091
1112
  }
1092
1113
  return value;
1093
- }, pythonPath);
1114
+ }, pythonPath, protectedRoot);
1094
1115
  return result?.["scans"];
1095
1116
  };
1096
1117
  const runMatching = async (operation, selection) => {
@@ -2424,6 +2445,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2424
2445
  .optional()
2425
2446
  .describe("Git base ref for --working-tree (default: HEAD)."),
2426
2447
  mode: ScanSettingsSchema.shape.mode.describe("Scan mode (default: standard); deep supports repository and path targets."),
2448
+ maxTime: ScanSettingsSchema.shape.maxTimeMinutes,
2427
2449
  ...DEEP_SCAN_OPTION_SCHEMAS,
2428
2450
  ...modelOptions(`OpenAI model to use (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.model}).`).shape,
2429
2451
  provider: PROVIDER_OPTION,
@@ -2498,6 +2520,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2498
2520
  knowledgeBasePaths: options.knowledgeBase,
2499
2521
  failureSeverity: options.failOnSeverity,
2500
2522
  maxCostUsd: options.maxCost,
2523
+ maxTimeMinutes: options.maxTime,
2501
2524
  codexOverrides: parseCodexOverrides(options.codex, options.model, options.effort, options.provider, project?.input.codex),
2502
2525
  }, directory, scope.sources);
2503
2526
  if (options.archiveExisting && settings.outputDir === undefined) {
@@ -2660,11 +2683,15 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2660
2683
  },
2661
2684
  })
2662
2685
  .command("classify-severity", {
2663
- description: "Assess severity for saved findings.",
2664
- hint: "Use --rubric to classify findings with a policy. The assessment is saved separately.",
2686
+ description: "Assess severity for saved findings or canonical records.",
2687
+ hint: "Use --rubric for saved findings or --records alone for host-provided classification.",
2665
2688
  destructive: true,
2666
2689
  mcp: false,
2667
2690
  options: z.object({
2691
+ records: z
2692
+ .boolean()
2693
+ .default(false)
2694
+ .describe("Classify canonical records through host-provided reviews over version 1 JSON-RPC; use alone."),
2668
2695
  reprocess: z
2669
2696
  .boolean()
2670
2697
  .default(false)
@@ -2690,6 +2717,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2690
2717
  }),
2691
2718
  output: z.record(z.string(), z.unknown()).optional(),
2692
2719
  async run({ options }) {
2720
+ if (options.records)
2721
+ throw new CodexSecurityError("Use classify-severity --records alone.");
2693
2722
  const controller = new AbortController();
2694
2723
  const removeSignals = listenForAbort(dependencies, controller);
2695
2724
  try {
@@ -2868,7 +2897,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2868
2897
  : "Deduplication canceled. Findings are unchanged."
2869
2898
  : diagnosticValue(error)}\n`);
2870
2899
  exitCode = interruptedExitCode(controller.signal) ?? 2;
2871
- return undefined;
2900
+ throw error;
2872
2901
  }
2873
2902
  finally {
2874
2903
  removeSignals();
@@ -2967,6 +2996,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2967
2996
  codexOverrides: parseCodexOverrides(options.codex, options.model, options.effort, options.provider, project?.input.codex),
2968
2997
  }, directory);
2969
2998
  const settings = resolved.options;
2999
+ deepScanOptions(settings);
2970
3000
  if (settings.outputDir === undefined)
2971
3001
  throw new ConfigurationError("--output-dir or output.directory is required for component scans.");
2972
3002
  const config = {
@@ -3157,14 +3187,6 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3157
3187
  };
3158
3188
  const resolved = resolveScanSettings(project, overrides, currentDirectory);
3159
3189
  const settings = resolved.options;
3160
- // A CSV row may choose a different mode; resolve the same file for both
3161
- // modes so inactive deep defaults remain available to deep rows.
3162
- const scanOptionsByMode = project === undefined
3163
- ? undefined
3164
- : Object.fromEntries(SCAN_MODES.map((mode) => [
3165
- mode,
3166
- resolveScanSettings(project, { ...overrides, mode }, currentDirectory).options,
3167
- ]));
3168
3190
  let inputPath;
3169
3191
  let outputDir;
3170
3192
  let githubHost;
@@ -3191,6 +3213,12 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3191
3213
  inputPath = resolveCliPath(currentDirectory, args.input);
3192
3214
  outputDir = settings.outputDir;
3193
3215
  }
3216
+ const scanOptionsByMode = project === undefined
3217
+ ? undefined
3218
+ : Object.fromEntries(SCAN_MODES.map((mode) => [
3219
+ mode,
3220
+ resolveScanSettings(project, { ...overrides, mode }, currentDirectory).options,
3221
+ ]));
3194
3222
  const result = await runMultiscan({
3195
3223
  inputPath,
3196
3224
  outputDir,
@@ -3355,13 +3383,19 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3355
3383
  throw new CodexSecurityError("--scan cannot be combined with a result directory.");
3356
3384
  }
3357
3385
  const format = resolveArtifactFormat(options.artifact, options.exportFormat);
3386
+ const sourceRoot = options.sourceRoot === undefined
3387
+ ? undefined
3388
+ : resolveCliPath(currentDirectory, options.sourceRoot);
3389
+ const protectedRoot = sourceRoot === undefined
3390
+ ? undefined
3391
+ : [currentDirectory, sourceRoot];
3358
3392
  let scanDir = args.scanDir;
3359
3393
  if (scanDir === undefined) {
3360
3394
  const scanId = options.scan ??
3361
- (await latestScans(1, "complete", options.python))?.[0]?.scanId;
3395
+ (await latestScans(1, "complete", options.python, protectedRoot))?.[0]?.scanId;
3362
3396
  if (scanId === undefined)
3363
3397
  return;
3364
- scanDir = await resolveSavedArtifactDirectory(scanId, options.artifact, format, (args) => dependencies.runWorkbench(args, undefined, undefined, options.python));
3398
+ scanDir = await resolveSavedArtifactDirectory(scanId, options.artifact, format, (args) => dependencies.runWorkbench(args, undefined, undefined, options.python, protectedRoot));
3365
3399
  }
3366
3400
  const arguments_ = {
3367
3401
  scanDir: resolveCliPath(currentDirectory, scanDir),
@@ -3370,9 +3404,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3370
3404
  output: options.output === "-"
3371
3405
  ? "-"
3372
3406
  : resolveCliPath(currentDirectory, options.output ?? EXPORT_DEFAULT_OUTPUTS[format]),
3373
- sourceRoot: options.sourceRoot === undefined
3374
- ? undefined
3375
- : resolveCliPath(currentDirectory, options.sourceRoot),
3407
+ sourceRoot,
3376
3408
  pythonPath: options.python,
3377
3409
  };
3378
3410
  try {
@@ -3402,6 +3434,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3402
3434
  },
3403
3435
  })
3404
3436
  .command("validate", {
3437
+ hint: "Use --records alone for host-provided reviews over JSON-RPC.",
3405
3438
  description: "Assess candidate security findings using source evidence only.",
3406
3439
  destructive: false,
3407
3440
  mcp: false,
@@ -3412,6 +3445,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3412
3445
  .describe("Finding text or a file containing findings."),
3413
3446
  }),
3414
3447
  options: z.object({
3448
+ records: z
3449
+ .boolean()
3450
+ .default(false)
3451
+ .describe("Run the versioned validation JSON-RPC protocol on stdin/stdout; use alone."),
3415
3452
  auth: SKILL_AUTH_OPTION,
3416
3453
  ...SKILL_CONFIG_OPTIONS.shape,
3417
3454
  context: optionValue("--context")
@@ -3431,6 +3468,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3431
3468
  async run({ options }) {
3432
3469
  let knowledgeBase;
3433
3470
  try {
3471
+ if (options.records)
3472
+ throw new CodexSecurityError("Use validate --records alone.");
3434
3473
  if (options.knowledgeBase.length > 0) {
3435
3474
  knowledgeBase = await prepareKnowledgeBase(options.knowledgeBase.map((path) => resolveCliPath(dependencies.currentDirectory(), path)));
3436
3475
  }
@@ -4083,6 +4122,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
4083
4122
  const directory = dependencies.currentDirectory();
4084
4123
  const project = await selectedProjectConfig(options.config, dependencies);
4085
4124
  const resolved = resolveScanSettings(project, {}, directory);
4125
+ deepScanOptions(resolved.options);
4086
4126
  const codex = await mergedCodexConfig(resolved.config);
4087
4127
  const deep = resolved.options.mode === "deep"
4088
4128
  ? await resolveDeepScanConfig(resolved.options, join(scanCodexHome(dependencies.environment), "codex-security", "config.toml"))
@@ -4554,6 +4594,10 @@ async function prepareScanArgumentsFromRecipe(recipe, parentScanId, { scanPrompt
4554
4594
  throw new CodexSecurityError("The saved scan recipe contains an invalid cost limit.");
4555
4595
  }
4556
4596
  const deepScan = DeepScanSettingsSchema.optional().safeParse(recipe["deepScan"]);
4597
+ const maxTimeMinutes = ScanSettingsSchema.shape.maxTimeMinutes.safeParse(recipe["maxTimeMinutes"]);
4598
+ if (!maxTimeMinutes.success) {
4599
+ throw new CodexSecurityError("The saved scan recipe contains an invalid investigation time limit.");
4600
+ }
4557
4601
  if (!deepScan.success) {
4558
4602
  throw new CodexSecurityError("The saved scan recipe contains invalid deep scan settings.");
4559
4603
  }
@@ -4606,6 +4650,7 @@ async function prepareScanArgumentsFromRecipe(recipe, parentScanId, { scanPrompt
4606
4650
  : { ...config, approval_policy: "never" },
4607
4651
  failureSeverity: threshold.data,
4608
4652
  maxCostUsd,
4653
+ maxTimeMinutes: maxTimeMinutes.data,
4609
4654
  dryRun: false,
4610
4655
  parentScanId,
4611
4656
  ...(recipe["mock"] === true ? { mock: true } : {}),
@@ -4796,12 +4841,48 @@ async function selectSavedFindings(identifiers, requestedScanId, severity, depen
4796
4841
  finding.findingId === identifier))) {
4797
4842
  throw new CodexSecurityError("The requested finding does not belong to the selected scan.");
4798
4843
  }
4844
+ const fullFindings = selected.length === 0
4845
+ ? []
4846
+ : await (dependencies.readSavedFindings ?? readSavedFindings)(scan.scanId, dependencies.runWorkbench);
4847
+ const byOccurrence = new Map(fullFindings.map((finding) => [finding.occurrenceId, finding]));
4799
4848
  return {
4800
4849
  repository: scan.targetPath,
4801
4850
  scanId: scan.scanId,
4802
- findings: selected,
4851
+ findings: selected.map((finding) => {
4852
+ const full = byOccurrence.get(finding.occurrenceId);
4853
+ if (full === undefined || full.findingId !== finding.findingId) {
4854
+ throw new CodexSecurityError(`Finding ${finding.occurrenceId} is missing from the saved scan artifacts.`);
4855
+ }
4856
+ const hydrated = { ...finding, ...full };
4857
+ // Sealed artifacts supply evidence; the workbench owns live and derived state.
4858
+ for (const key of [
4859
+ "createdAt",
4860
+ "triage",
4861
+ "remediationState",
4862
+ "matches",
4863
+ "knownSince",
4864
+ "knownScanIds",
4865
+ "related",
4866
+ "sourceExcerpt",
4867
+ "artifactPaths",
4868
+ ]) {
4869
+ if (Object.hasOwn(finding, key))
4870
+ hydrated[key] = finding[key];
4871
+ else
4872
+ delete hydrated[key];
4873
+ }
4874
+ return hydrated;
4875
+ }),
4803
4876
  };
4804
4877
  }
4878
+ async function readSavedFindings(scanId, workbench) {
4879
+ const directory = await resolveSavedArtifactDirectory(scanId, "findings", "json", workbench);
4880
+ const { findings } = await loadContract(directory, {
4881
+ pluginRoot: await bundledPluginRoot(),
4882
+ expectedScanId: scanId,
4883
+ });
4884
+ return findings.findings;
4885
+ }
4805
4886
  function patchExitCode(patches) {
4806
4887
  if (patches.some(({ status }) => status === "failed"))
4807
4888
  return 2;
@@ -4841,77 +4922,17 @@ async function publishPatchBranch(repository, branch, body, stderr, dependencies
4841
4922
  const run = (command, args) => dependencies.runRepositoryCommand(command, args, repository);
4842
4923
  try {
4843
4924
  const remote = await run("git", ["remote", "get-url", "--push", "origin"]);
4844
- const host = patchRemoteHost(remote);
4845
- const gitlabHost = dependencies.environment["GITLAB_HOST"] ||
4846
- dependencies.environment["GITLAB_URI"] ||
4847
- dependencies.environment["GL_HOST"];
4848
- const gitlab = host === "gitlab.com" ||
4849
- (host !== undefined &&
4850
- gitlabHost !== undefined &&
4851
- host ===
4852
- patchRemoteHost(gitlabHost.includes("://") ? gitlabHost : `https://${gitlabHost}`));
4853
- const command = gitlab ? "glab" : "gh";
4854
- const gitlabRepository = remote.includes("://")
4855
- ? remote
4856
- : `ssh://${remote.replace(":", "/")}`;
4857
- let url = await run(command, gitlab
4858
- ? [
4859
- "mr",
4860
- "list",
4861
- "--all",
4862
- "--source-branch",
4863
- branch,
4864
- "--output",
4865
- "json",
4866
- "--jq",
4867
- "map(select(.source_project_id == .target_project_id))[0].web_url // empty",
4868
- "--repo",
4869
- gitlabRepository,
4870
- ]
4871
- : [
4872
- "pr",
4873
- "list",
4874
- "--head",
4875
- branch,
4876
- "--state",
4877
- "all",
4878
- "--json",
4879
- "url",
4880
- "--jq",
4881
- ".[0].url // empty",
4882
- ]);
4883
- if (!url) {
4884
- await run("git", ["push", "--set-upstream", "origin", branch]);
4885
- url = await run(command, gitlab
4886
- ? [
4887
- "mr",
4888
- "create",
4889
- "--draft",
4890
- "--head",
4891
- gitlabRepository,
4892
- "--source-branch",
4893
- branch,
4894
- "--title",
4895
- PATCH_PR_TITLE,
4896
- "--description",
4897
- gitlabPatchDescription(body),
4898
- "--yes",
4899
- "--repo",
4900
- gitlabRepository,
4901
- ]
4902
- : [
4903
- "pr",
4904
- "create",
4905
- "--draft",
4906
- "--head",
4907
- branch,
4908
- "--title",
4909
- PATCH_PR_TITLE,
4910
- "--body",
4911
- body,
4912
- ]);
4913
- }
4914
- stderr.write(`${gitlab ? "Merge" : "Pull"} request: ${safePatchText(url)}\n`);
4925
+ const publisher = resolvePatchReviewPublisher(remote, dependencies.environment, run);
4926
+ const url = await publishPatchReview({
4927
+ branch,
4928
+ title: PATCH_PR_TITLE,
4929
+ body,
4930
+ publisher,
4931
+ pushBranch: async (branch) => {
4932
+ await run("git", ["push", "--set-upstream", "origin", branch]);
4933
+ },
4934
+ });
4935
+ stderr.write(`${publisher.label}: ${safePatchText(url)}\n`);
4915
4936
  return { branch, url };
4916
4937
  }
4917
4938
  catch (error) {
@@ -4919,20 +4940,6 @@ async function publishPatchBranch(repository, branch, body, stderr, dependencies
4919
4940
  throw error;
4920
4941
  }
4921
4942
  }
4922
- function gitlabPatchDescription(body) {
4923
- // GitLab ignores quick actions inside its native fenced blockquotes. Choose
4924
- // a fence the report cannot close after quick-action CR removal; preserve its
4925
- // original bytes and end the outer quote at EOF.
4926
- let fenceLength = 3;
4927
- for (const match of body.replaceAll("\r", "").matchAll(/^[ \t]*(>+)/gmu))
4928
- fenceLength = Math.max(fenceLength, match[1].length + 1);
4929
- return `${">".repeat(fenceLength)}\n${body}`;
4930
- }
4931
- function patchRemoteHost(remote) {
4932
- if (remote.includes("://"))
4933
- return new URL(remote).hostname.toLowerCase();
4934
- return /^(?:[^@/]+@)?([^:/]+):[^/]/u.exec(remote)?.[1]?.toLowerCase();
4935
- }
4936
4943
  async function resumePatchPullRequest(repository, branch, stderr, dependencies) {
4937
4944
  const run = (args) => dependencies.runRepositoryCommand("git", args, repository);
4938
4945
  const commit = await run([
@@ -5983,6 +5990,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
5983
5990
  let failed = false;
5984
5991
  let failure;
5985
5992
  try {
5993
+ deepScanOptions(arguments_);
5986
5994
  const directory = dependencies.currentDirectory();
5987
5995
  repository = arguments_.repository ?? directory;
5988
5996
  const target = arguments_.target;
@@ -6026,7 +6034,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
6026
6034
  }
6027
6035
  selectedAuthentication = arguments_.mock
6028
6036
  ? null
6029
- : scanAuthentication(dependencies.environment, auth, provider, hasCommandAuth(effectiveConfiguration));
6037
+ : scanAuthentication(dependencies.environment, auth, provider, hasCommandAuth(effectiveConfiguration), arguments_.dryRun);
6030
6038
  diagnostic("scan.configuration", {
6031
6039
  cli_version: VERSION,
6032
6040
  bundled_plugin_version: BUNDLED_PLUGIN_VERSION,
@@ -6334,32 +6342,20 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
6334
6342
  progress.startTimer(runningMessage());
6335
6343
  },
6336
6344
  onWorkerStatus: (status) => {
6337
- const update = status.kind === "preflight"
6338
- ? `preflight:${status.delegation}:${status.configuredSlots}`
6339
- : `dispatch:${status.phase}:${status.planned}:${status.started}`;
6345
+ const update = `dispatch:${status.phase}:${status.planned}:${status.started}`;
6340
6346
  if (update === lastWorkerUpdate)
6341
6347
  return;
6342
6348
  lastWorkerUpdate = update;
6343
- if (status.kind === "preflight") {
6344
- diagnostic("worker.preflight", {
6345
- delegation: status.delegation,
6346
- configured_slots: status.configuredSlots,
6347
- });
6348
- }
6349
- else {
6350
- diagnostic("worker.phase", {
6351
- phase: status.phase,
6352
- planned: status.planned,
6353
- started: status.started,
6354
- });
6355
- workerCapacity = { planned: status.planned, started: status.started };
6356
- phase = scanPhase(status.phase);
6357
- }
6349
+ diagnostic("worker.phase", {
6350
+ phase: status.phase,
6351
+ planned: status.planned,
6352
+ started: status.started,
6353
+ });
6354
+ workerCapacity = { planned: status.planned, started: status.started };
6355
+ phase = scanPhase(status.phase);
6358
6356
  const message = workerStatusMessage(status);
6359
6357
  if (dashboard !== null) {
6360
- if (status.kind === "dispatch") {
6361
- dashboard.setStage(scanPhase(status.phase));
6362
- }
6358
+ dashboard.setStage(scanPhase(status.phase));
6363
6359
  dashboard.note(message);
6364
6360
  return;
6365
6361
  }
@@ -6862,10 +6858,14 @@ async function readDeepScanStop(result, maxCostUsd, runWorkbench) {
6862
6858
  }
6863
6859
  const elapsedHours = (Date.parse(state.completedAt) - Date.parse(state.createdAt)) / 3_600_000;
6864
6860
  if (elapsedHours >= maxTimeHours) {
6861
+ let maxTimeMinutes = maxTimeHours * 60;
6862
+ const roundedMinutes = Number(maxTimeMinutes.toPrecision(15));
6863
+ if (roundedMinutes / 60 === maxTimeHours)
6864
+ maxTimeMinutes = roundedMinutes;
6865
6865
  return {
6866
- reason: `Reached the ${maxTimeHours}-hour time limit. More issues may remain.`,
6866
+ reason: `Reached the ${maxTimeMinutes}-minute time limit. More issues may remain.`,
6867
6867
  nextStep: maxTimeHours < 96
6868
- ? "To scan further, rerun with a higher --max-time-hours."
6868
+ ? `To scan further, rerun with --max-time greater than ${maxTimeMinutes}.`
6869
6869
  : "To scan a smaller part of the repository, rerun with --path.",
6870
6870
  };
6871
6871
  }
@@ -7199,17 +7199,6 @@ export function parseCodexOverrides(values, model, effort, provider, defaults) {
7199
7199
  return result;
7200
7200
  }
7201
7201
  function workerStatusMessage(status) {
7202
- if (status.kind === "preflight") {
7203
- if (status.delegation === "unavailable") {
7204
- return "Preflight: worker delegation unavailable; continuing without delegated workers.";
7205
- }
7206
- if (status.delegation === "unknown") {
7207
- return "Preflight: worker delegation could not be confirmed; continuing scan.";
7208
- }
7209
- return status.configuredSlots === null
7210
- ? "Preflight: worker delegation supported."
7211
- : `Preflight: worker delegation supported (up to ${status.configuredSlots} worker slots).`;
7212
- }
7213
7202
  if (status.started === status.planned) {
7214
7203
  return `Scan phase: ${scanPhase(status.phase)} (${status.started} ${status.started === 1 ? "worker" : "workers"}).`;
7215
7204
  }