@openai/codex-security 0.8.1 → 0.8.3

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 (396) hide show
  1. package/README.md +45 -57
  2. package/_bundled_plugin/.app.json +4 -0
  3. package/_bundled_plugin/.mcp.json +1 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  6. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
  7. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  13. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  14. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  15. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +46 -12
  16. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  17. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  18. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  19. package/_bundled_plugin/references/artifact-storage.md +1 -1
  20. package/_bundled_plugin/references/core-scan.md +14 -5
  21. package/_bundled_plugin/references/default-severity-rubric.md +28 -0
  22. package/_bundled_plugin/references/finding-detail-fields.md +1 -0
  23. package/_bundled_plugin/references/threat-model.md +1 -0
  24. package/_bundled_plugin/scripts/deep_scan_workbench.py +23 -112
  25. package/_bundled_plugin/scripts/finalize_scan_contract.py +167 -153
  26. package/_bundled_plugin/scripts/finding_preview.py +5 -29
  27. package/_bundled_plugin/scripts/posix_scan_local_files.py +187 -0
  28. package/_bundled_plugin/scripts/report_projection.py +87 -136
  29. package/_bundled_plugin/scripts/validate_scan_contract.py +2 -6
  30. package/_bundled_plugin/scripts/windows_scan_local_files.py +212 -55
  31. package/_bundled_plugin/scripts/workbench/retained_coverage.py +8 -24
  32. package/_bundled_plugin/scripts/workbench/saved_coverage.py +143 -231
  33. package/_bundled_plugin/scripts/workbench_cli.py +102 -13
  34. package/_bundled_plugin/scripts/workbench_constants.py +9 -0
  35. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +0 -17
  36. package/_bundled_plugin/scripts/workbench_db.py +187 -363
  37. package/_bundled_plugin/scripts/workbench_finding_workflows.py +86 -4
  38. package/_bundled_plugin/scripts/workbench_native_indexes.py +17 -21
  39. package/_bundled_plugin/scripts/workbench_remediation.py +495 -11
  40. package/_bundled_plugin/scripts/workbench_saved_results.py +0 -66
  41. package/_bundled_plugin/scripts/workbench_scan_history.py +22 -25
  42. package/_bundled_plugin/scripts/workbench_scan_start.py +1 -1
  43. package/_bundled_plugin/scripts/workbench_scan_usage.py +25 -52
  44. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  45. package/_bundled_plugin/scripts/workbench_setup.py +239 -0
  46. package/_bundled_plugin/scripts/workbench_source_scopes.py +15 -23
  47. package/_bundled_plugin/scripts/workbench_target.py +120 -35
  48. package/_bundled_plugin/scripts/workbench_validation.py +1 -9
  49. package/_bundled_plugin/shared/workbench-history-repairs.json +7 -0
  50. package/_bundled_plugin/shared/workbench-migrations.json +19 -0
  51. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
  52. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
  53. package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
  54. package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
  55. package/_bundled_plugin/skills/cloud-findings/SKILL.md +2 -0
  56. package/_bundled_plugin/skills/fix-finding/SKILL.md +18 -1
  57. package/_bundled_plugin/skills/publish-findings/SKILL.md +68 -35
  58. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
  59. package/_bundled_plugin/skills/resolve-dependency-alert/SKILL.md +18 -0
  60. package/_bundled_plugin/skills/resolve-dependency-alert/agents/openai.yaml +4 -0
  61. package/_bundled_plugin/skills/threat-model-visualize/SKILL.md +83 -0
  62. package/_bundled_plugin/skills/threat-model-visualize/agents/openai.yaml +4 -0
  63. package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-overview.svg +366 -0
  64. package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-path.svg +558 -0
  65. package/_bundled_plugin/skills/threat-model-visualize/assets/control-effects.js +85 -0
  66. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.css +17 -0
  67. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.html +38 -0
  68. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.js +372 -0
  69. package/_bundled_plugin/skills/threat-model-visualize/assets/route-paths.js +71 -0
  70. package/_bundled_plugin/skills/threat-model-visualize/assets/source-roles.js +47 -0
  71. package/_bundled_plugin/skills/threat-model-visualize/assets/svg-layout.js +149 -0
  72. package/_bundled_plugin/skills/threat-model-visualize/references/context-explorer.md +21 -0
  73. package/_bundled_plugin/skills/threat-model-visualize/references/view-model.md +49 -0
  74. package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +569 -0
  75. package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
  76. package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
  77. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -4
  78. package/dist/api.d.ts +6 -1
  79. package/dist/api.d.ts.map +1 -1
  80. package/dist/api.js +414 -163
  81. package/dist/api.js.map +1 -1
  82. package/dist/auth.js +7 -2
  83. package/dist/auth.js.map +1 -1
  84. package/dist/blackduck-findings.d.ts +8 -0
  85. package/dist/blackduck-findings.d.ts.map +1 -0
  86. package/dist/blackduck-findings.js +305 -0
  87. package/dist/blackduck-findings.js.map +1 -0
  88. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  89. package/dist/bulk-scan-discovery.js +51 -36
  90. package/dist/bulk-scan-discovery.js.map +1 -1
  91. package/dist/classify-severity-records.d.ts +5 -0
  92. package/dist/classify-severity-records.d.ts.map +1 -1
  93. package/dist/classify-severity-records.js +6 -8
  94. package/dist/classify-severity-records.js.map +1 -1
  95. package/dist/classify-severity.d.ts +4 -1
  96. package/dist/classify-severity.d.ts.map +1 -1
  97. package/dist/classify-severity.js +28 -9
  98. package/dist/classify-severity.js.map +1 -1
  99. package/dist/cli.d.ts +3 -0
  100. package/dist/cli.d.ts.map +1 -1
  101. package/dist/cli.js +635 -266
  102. package/dist/cli.js.map +1 -1
  103. package/dist/codex-prompt.d.ts +2 -0
  104. package/dist/codex-prompt.d.ts.map +1 -1
  105. package/dist/codex-prompt.js +6 -0
  106. package/dist/codex-prompt.js.map +1 -1
  107. package/dist/component-scan.d.ts.map +1 -1
  108. package/dist/component-scan.js +6 -5
  109. package/dist/component-scan.js.map +1 -1
  110. package/dist/config.d.ts +2 -1
  111. package/dist/config.d.ts.map +1 -1
  112. package/dist/config.js +162 -40
  113. package/dist/config.js.map +1 -1
  114. package/dist/continuum-findings.d.ts +7 -0
  115. package/dist/continuum-findings.d.ts.map +1 -0
  116. package/dist/continuum-findings.js +157 -0
  117. package/dist/continuum-findings.js.map +1 -0
  118. package/dist/contract-values.d.ts +28 -0
  119. package/dist/contract-values.d.ts.map +1 -0
  120. package/dist/contract-values.js +75 -0
  121. package/dist/contract-values.js.map +1 -0
  122. package/dist/contract.d.ts +2 -20
  123. package/dist/contract.d.ts.map +1 -1
  124. package/dist/contract.js +58 -669
  125. package/dist/contract.js.map +1 -1
  126. package/dist/cost-model.d.ts.map +1 -1
  127. package/dist/cost-model.js +1 -4
  128. package/dist/cost-model.js.map +1 -1
  129. package/dist/cost.d.ts +19 -1
  130. package/dist/cost.d.ts.map +1 -1
  131. package/dist/cost.js +2120 -39
  132. package/dist/cost.js.map +1 -1
  133. package/dist/custom-validation-prompt.d.ts +1 -1
  134. package/dist/custom-validation-prompt.d.ts.map +1 -1
  135. package/dist/custom-validation-prompt.js +5 -0
  136. package/dist/custom-validation-prompt.js.map +1 -1
  137. package/dist/custom-validation.d.ts +2 -0
  138. package/dist/custom-validation.d.ts.map +1 -1
  139. package/dist/custom-validation.js +6 -2
  140. package/dist/custom-validation.js.map +1 -1
  141. package/dist/deduplication/deduplication-prompts.d.ts +4 -4
  142. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  143. package/dist/deduplication/deduplication-prompts.js +2 -2
  144. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  145. package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
  146. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  147. package/dist/deduplication/deduplication-reviewer.js +12 -5
  148. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  149. package/dist/deduplication/deduplication.js.map +1 -1
  150. package/dist/deduplication/finding-schema.d.ts +19 -1
  151. package/dist/deduplication/finding-schema.d.ts.map +1 -1
  152. package/dist/deduplication/finding-schema.js +25 -0
  153. package/dist/deduplication/finding-schema.js.map +1 -1
  154. package/dist/deduplication/local.d.ts.map +1 -1
  155. package/dist/deduplication/local.js +3 -8
  156. package/dist/deduplication/local.js.map +1 -1
  157. package/dist/deduplication/records.d.ts +11 -3
  158. package/dist/deduplication/records.d.ts.map +1 -1
  159. package/dist/deduplication/records.js +48 -16
  160. package/dist/deduplication/records.js.map +1 -1
  161. package/dist/deep-scan.d.ts +11 -0
  162. package/dist/deep-scan.d.ts.map +1 -1
  163. package/dist/deep-scan.js +235 -4
  164. package/dist/deep-scan.js.map +1 -1
  165. package/dist/default-severity-rubric.d.ts +1 -2
  166. package/dist/default-severity-rubric.d.ts.map +1 -1
  167. package/dist/default-severity-rubric.js +2 -66
  168. package/dist/default-severity-rubric.js.map +1 -1
  169. package/dist/endor-findings.d.ts.map +1 -1
  170. package/dist/endor-findings.js +44 -89
  171. package/dist/endor-findings.js.map +1 -1
  172. package/dist/errors.js +1 -1
  173. package/dist/errors.js.map +1 -1
  174. package/dist/external-findings-import.d.ts.map +1 -1
  175. package/dist/external-findings-import.js +11 -15
  176. package/dist/external-findings-import.js.map +1 -1
  177. package/dist/external-findings-local.d.ts +12 -1
  178. package/dist/external-findings-local.d.ts.map +1 -1
  179. package/dist/external-findings-local.js +411 -184
  180. package/dist/external-findings-local.js.map +1 -1
  181. package/dist/external-findings-publish.d.ts +15 -1
  182. package/dist/external-findings-publish.d.ts.map +1 -1
  183. package/dist/external-findings-publish.js +1238 -226
  184. package/dist/external-findings-publish.js.map +1 -1
  185. package/dist/external-findings-read.d.ts +10 -0
  186. package/dist/external-findings-read.d.ts.map +1 -1
  187. package/dist/external-findings-read.js +71 -51
  188. package/dist/external-findings-read.js.map +1 -1
  189. package/dist/external-findings.d.ts +13 -0
  190. package/dist/external-findings.d.ts.map +1 -1
  191. package/dist/external-findings.js +124 -1
  192. package/dist/external-findings.js.map +1 -1
  193. package/dist/external-import-contract.d.ts +29 -1
  194. package/dist/external-import-contract.d.ts.map +1 -1
  195. package/dist/external-import-contract.js +314 -44
  196. package/dist/external-import-contract.js.map +1 -1
  197. package/dist/external-import-models.d.ts +1 -1
  198. package/dist/external-import-models.d.ts.map +1 -1
  199. package/dist/external-import-models.js.map +1 -1
  200. package/dist/finding-normalization.d.ts +1 -1
  201. package/dist/finding-normalization.d.ts.map +1 -1
  202. package/dist/finding-normalization.js +46 -11
  203. package/dist/finding-normalization.js.map +1 -1
  204. package/dist/finding-retrieval.d.ts +3 -3
  205. package/dist/finding-retrieval.d.ts.map +1 -1
  206. package/dist/finding-retrieval.js.map +1 -1
  207. package/dist/finding-workflow.d.ts +6 -1
  208. package/dist/finding-workflow.d.ts.map +1 -1
  209. package/dist/finding-workflow.js +2 -2
  210. package/dist/finding-workflow.js.map +1 -1
  211. package/dist/git-remote.d.ts +4 -0
  212. package/dist/git-remote.d.ts.map +1 -1
  213. package/dist/git-remote.js +20 -0
  214. package/dist/git-remote.js.map +1 -1
  215. package/dist/github-advisories.d.ts +3 -12
  216. package/dist/github-advisories.d.ts.map +1 -1
  217. package/dist/github-advisories.js +9 -29
  218. package/dist/github-advisories.js.map +1 -1
  219. package/dist/github-dependabot-findings.d.ts.map +1 -1
  220. package/dist/github-dependabot-findings.js +7 -16
  221. package/dist/github-dependabot-findings.js.map +1 -1
  222. package/dist/github-findings.d.ts.map +1 -1
  223. package/dist/github-findings.js +344 -56
  224. package/dist/github-findings.js.map +1 -1
  225. package/dist/github.d.ts +17 -7
  226. package/dist/github.d.ts.map +1 -1
  227. package/dist/github.js +43 -30
  228. package/dist/github.js.map +1 -1
  229. package/dist/host-protocol.d.ts +7 -2
  230. package/dist/host-protocol.d.ts.map +1 -1
  231. package/dist/host-protocol.js +27 -3
  232. package/dist/host-protocol.js.map +1 -1
  233. package/dist/host-records-protocol.d.ts +10 -11
  234. package/dist/host-records-protocol.d.ts.map +1 -1
  235. package/dist/host-records-protocol.js +69 -9
  236. package/dist/host-records-protocol.js.map +1 -1
  237. package/dist/hosted-scan.d.ts +15 -0
  238. package/dist/hosted-scan.d.ts.map +1 -1
  239. package/dist/hosted-scan.js +55 -33
  240. package/dist/hosted-scan.js.map +1 -1
  241. package/dist/index.d.ts +8 -0
  242. package/dist/index.d.ts.map +1 -1
  243. package/dist/index.js +7 -0
  244. package/dist/index.js.map +1 -1
  245. package/dist/inspector-findings.d.ts +9 -0
  246. package/dist/inspector-findings.d.ts.map +1 -0
  247. package/dist/inspector-findings.js +512 -0
  248. package/dist/inspector-findings.js.map +1 -0
  249. package/dist/knowledge-base.js +18 -5
  250. package/dist/knowledge-base.js.map +1 -1
  251. package/dist/local-git-metadata.d.ts +5 -0
  252. package/dist/local-git-metadata.d.ts.map +1 -0
  253. package/dist/local-git-metadata.js +131 -0
  254. package/dist/local-git-metadata.js.map +1 -0
  255. package/dist/multiscan.d.ts.map +1 -1
  256. package/dist/multiscan.js +22 -12
  257. package/dist/multiscan.js.map +1 -1
  258. package/dist/opengrep-findings.d.ts.map +1 -1
  259. package/dist/opengrep-findings.js +34 -20
  260. package/dist/opengrep-findings.js.map +1 -1
  261. package/dist/patch-tui.d.ts +1 -1
  262. package/dist/patch-tui.d.ts.map +1 -1
  263. package/dist/patch-tui.js +94 -36
  264. package/dist/patch-tui.js.map +1 -1
  265. package/dist/private-finding-import.d.ts +246 -0
  266. package/dist/private-finding-import.d.ts.map +1 -0
  267. package/dist/private-finding-import.js +387 -0
  268. package/dist/private-finding-import.js.map +1 -0
  269. package/dist/project-config.d.ts.map +1 -1
  270. package/dist/project-config.js +2 -2
  271. package/dist/project-config.js.map +1 -1
  272. package/dist/provider-profile.d.ts +10 -2
  273. package/dist/provider-profile.d.ts.map +1 -1
  274. package/dist/provider-profile.js +72 -10
  275. package/dist/provider-profile.js.map +1 -1
  276. package/dist/publication.js +7 -1
  277. package/dist/publication.js.map +1 -1
  278. package/dist/reader-selection.d.ts +13 -0
  279. package/dist/reader-selection.d.ts.map +1 -0
  280. package/dist/reader-selection.js +81 -0
  281. package/dist/reader-selection.js.map +1 -0
  282. package/dist/record.d.ts +6 -1
  283. package/dist/record.d.ts.map +1 -1
  284. package/dist/record.js +53 -2
  285. package/dist/record.js.map +1 -1
  286. package/dist/remediation.d.ts +5 -0
  287. package/dist/remediation.d.ts.map +1 -1
  288. package/dist/remediation.js +30 -0
  289. package/dist/remediation.js.map +1 -1
  290. package/dist/result.d.ts +2 -0
  291. package/dist/result.d.ts.map +1 -1
  292. package/dist/result.js +3 -1
  293. package/dist/result.js.map +1 -1
  294. package/dist/runtime.d.ts +5 -3
  295. package/dist/runtime.d.ts.map +1 -1
  296. package/dist/runtime.js +110 -57
  297. package/dist/runtime.js.map +1 -1
  298. package/dist/scan-activity.js +40 -17
  299. package/dist/scan-activity.js.map +1 -1
  300. package/dist/scan-comparison.d.ts +1 -1
  301. package/dist/scan-comparison.d.ts.map +1 -1
  302. package/dist/scan-comparison.js +11 -13
  303. package/dist/scan-comparison.js.map +1 -1
  304. package/dist/scan-dashboard.d.ts +1 -0
  305. package/dist/scan-dashboard.d.ts.map +1 -1
  306. package/dist/scan-dashboard.js +37 -48
  307. package/dist/scan-dashboard.js.map +1 -1
  308. package/dist/scan-executor.d.ts +2 -0
  309. package/dist/scan-executor.d.ts.map +1 -1
  310. package/dist/scan-executor.js.map +1 -1
  311. package/dist/scan-history-renderer.d.ts.map +1 -1
  312. package/dist/scan-history-renderer.js +22 -9
  313. package/dist/scan-history-renderer.js.map +1 -1
  314. package/dist/scan-logs.d.ts.map +1 -1
  315. package/dist/scan-logs.js +5 -5
  316. package/dist/scan-logs.js.map +1 -1
  317. package/dist/scanner-import.d.ts +48 -3
  318. package/dist/scanner-import.d.ts.map +1 -1
  319. package/dist/scanner-import.js +214 -39
  320. package/dist/scanner-import.js.map +1 -1
  321. package/dist/scanner-repository-url.d.ts +14 -0
  322. package/dist/scanner-repository-url.d.ts.map +1 -0
  323. package/dist/scanner-repository-url.js +67 -0
  324. package/dist/scanner-repository-url.js.map +1 -0
  325. package/dist/semgrep-findings.d.ts.map +1 -1
  326. package/dist/semgrep-findings.js +50 -88
  327. package/dist/semgrep-findings.js.map +1 -1
  328. package/dist/semgrep-platform-findings.d.ts +12 -0
  329. package/dist/semgrep-platform-findings.d.ts.map +1 -0
  330. package/dist/semgrep-platform-findings.js +198 -0
  331. package/dist/semgrep-platform-findings.js.map +1 -0
  332. package/dist/severity-rubric.d.ts +20 -0
  333. package/dist/severity-rubric.d.ts.map +1 -0
  334. package/dist/severity-rubric.js +73 -0
  335. package/dist/severity-rubric.js.map +1 -0
  336. package/dist/severity-store.js +15 -5
  337. package/dist/severity-store.js.map +1 -1
  338. package/dist/snyk-findings.d.ts.map +1 -1
  339. package/dist/snyk-findings.js +97 -106
  340. package/dist/snyk-findings.js.map +1 -1
  341. package/dist/sonar-collector.d.ts +16 -0
  342. package/dist/sonar-collector.d.ts.map +1 -0
  343. package/dist/sonar-collector.js +383 -0
  344. package/dist/sonar-collector.js.map +1 -0
  345. package/dist/sonar-findings.d.ts +49 -0
  346. package/dist/sonar-findings.d.ts.map +1 -0
  347. package/dist/sonar-findings.js +288 -0
  348. package/dist/sonar-findings.js.map +1 -0
  349. package/dist/sonar-import.d.ts +111 -0
  350. package/dist/sonar-import.d.ts.map +1 -0
  351. package/dist/sonar-import.js +279 -0
  352. package/dist/sonar-import.js.map +1 -0
  353. package/dist/suggest-owners.d.ts.map +1 -1
  354. package/dist/suggest-owners.js +2 -1
  355. package/dist/suggest-owners.js.map +1 -1
  356. package/dist/targets.d.ts +3 -0
  357. package/dist/targets.d.ts.map +1 -1
  358. package/dist/targets.js +18 -12
  359. package/dist/targets.js.map +1 -1
  360. package/dist/terminal-columns.d.ts +4 -0
  361. package/dist/terminal-columns.d.ts.map +1 -0
  362. package/dist/terminal-columns.js +19 -0
  363. package/dist/terminal-columns.js.map +1 -0
  364. package/dist/validation-records.d.ts +0 -3
  365. package/dist/validation-records.d.ts.map +1 -1
  366. package/dist/validation-records.js +0 -16
  367. package/dist/validation-records.js.map +1 -1
  368. package/dist/veracode-findings.d.ts +7 -0
  369. package/dist/veracode-findings.d.ts.map +1 -0
  370. package/dist/veracode-findings.js +371 -0
  371. package/dist/veracode-findings.js.map +1 -0
  372. package/dist/windows-path.d.ts.map +1 -1
  373. package/dist/windows-path.js +1 -0
  374. package/dist/windows-path.js.map +1 -1
  375. package/dist/wiz-csv.d.ts +2 -2
  376. package/dist/wiz-csv.d.ts.map +1 -1
  377. package/dist/wiz-csv.js +1 -3
  378. package/dist/wiz-csv.js.map +1 -1
  379. package/dist/wiz-findings.d.ts +10 -2
  380. package/dist/wiz-findings.d.ts.map +1 -1
  381. package/dist/wiz-findings.js +88 -49
  382. package/dist/wiz-findings.js.map +1 -1
  383. package/docs/classify-severity-records.md +1 -1
  384. package/docs/cli.md +320 -481
  385. package/docs/dedupe-records.md +27 -4
  386. package/docs/findings-service.md +21 -8
  387. package/docs/hosted-scans.md +16 -1
  388. package/package.json +9 -10
  389. package/schemas/external-findings.schema.json +12 -1
  390. package/schemas/hosted-scan-v2.fixture.json +16 -1
  391. package/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
  392. package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
  393. package/dist/deduplication/records-protocol.d.ts +0 -4
  394. package/dist/deduplication/records-protocol.d.ts.map +0 -1
  395. package/dist/deduplication/records-protocol.js +0 -35
  396. package/dist/deduplication/records-protocol.js.map +0 -1
package/dist/api.js CHANGED
@@ -15,24 +15,25 @@ import { randomUUID } from "node:crypto";
15
15
  import { tmpdir } from "node:os";
16
16
  import { isDeepStrictEqual } from "node:util";
17
17
  import { pathToFileURL } from "node:url";
18
- import { basename, dirname, isAbsolute, join, posix, relative, resolve, sep, win32, } from "node:path";
18
+ import { basename, dirname, isAbsolute, join, parse as parsePath, posix, relative, resolve, sep, win32, } from "node:path";
19
19
  import { Codex, } from "@openai/codex-sdk";
20
20
  import { z } from "zod";
21
21
  import { readThreatModelPath } from "./artifact-export.js";
22
22
  import { scanSkillConfig } from "./scan-skill-paths.js";
23
23
  import { isRecord } from "./record.js";
24
24
  import { STATIC_VERIFICATION_INSTRUCTIONS, VerificationModeSchema, } from "./remediation.js";
25
- import { createProfileCodex, createProviderProfile, providerPreflightCommand, } from "./provider-profile.js";
25
+ import { createProfileCodex, createProviderProfile, privateReplayOverrides, providerPreflightCommand, } from "./provider-profile.js";
26
26
  import { CODEX_AUTH_CONFIG_KEYS, NO_CREDENTIALS_MESSAGE, accountStatus, configuredCodexHome, CodexLoginHandle, loginApiKey as persistApiKey, logout as codexLogout, withoutOpenAiApiKeys, } from "./auth.js";
27
27
  import { jsonForPrompt, pluginPythonCommand, shellEnvironmentReference, } from "./codex-prompt.js";
28
- import { DEFAULT_CODEX_CONFIG, EXTERNAL_CODEX_PROVIDERS, inlineToml, isExternalModelProvider, hasCommandAuth, mergedCodexConfig, resolveCodexProfile, resolveCommandAuthConfig, scanApprovalPolicy, scanCyberAccessConfig, scanModelConfiguration, scanModelProvider, structuredCodexConfig, writeCodexConfig, } from "./config.js";
28
+ import { EXTERNAL_CODEX_PROVIDERS, inlineToml, isExternalModelProvider, hasCommandAuth, mergedCodexConfig, resolveCodexProfile, resolveCommandAuthConfig, MODEL_FILE_SETTINGS, resolveNestedConfigPaths, scanApprovalPolicy, scanCyberAccessConfig, scanModelConfiguration, scanModelProvider, scanProviderEnvKey, structuredCodexConfig, writeCodexConfig, } from "./config.js";
29
29
  import { estimateScanCost, ScanCostTracker, } from "./cost.js";
30
30
  import { ScanProgressTracker } from "./scan-progress.js";
31
31
  import { findScanSession } from "./scan-logs.js";
32
- import { DIRECT_DEEP_SCAN_CONTROL_USAGE, runDeepScan } from "./deep-scan.js";
32
+ import { DIRECT_DEEP_SCAN_CONTROL_USAGE, deepScanParentToolOverrides, readDeepScanParentConfig, runDeepScan, } from "./deep-scan.js";
33
+ import { getDefaultSeverityRubric, readSeverityRubricFile, severityRubricInstructions, severityRubricSchema, } from "./severity-rubric.js";
33
34
  import { deepScanOptions, resolveDeepScanConfig, writeDeepScanConfig, } from "./deep-config.js";
34
35
  import { DEFAULT_SCAN_AUTH, DEFAULT_SCAN_MODE, SCAN_AUTH_MODES, ScanSettingsSchema, } from "./scan-settings.js";
35
- import { resolveScanPrompts } from "./prompt-files.js";
36
+ import { readRegularInputFile, resolveScanPrompts } from "./prompt-files.js";
36
37
  import { readScanTimeBudgetPolicy, renderScanTimeBudgetPolicy, scanTimeBudget, } from "./scan-time-budget.js";
37
38
  import { standaloneValidationPrompt } from "./standalone-validation-prompt.js";
38
39
  export { SCAN_AUTH_MODES } from "./scan-settings.js";
@@ -55,7 +56,7 @@ import { CODEX_SECURITY_THREAD_SOURCES } from "./thread-source.js";
55
56
  import { codexSecurityRequestContext } from "./request-metadata.js";
56
57
  import { CODEX_EXECUTABLE_VERSION, CODEX_SDK_VERSION } from "./version.js";
57
58
  import { bundledCodexSdkEnvironment } from "./codex-sdk-environment.js";
58
- import { canonicalConfigPath, acquireCodexSecurityCredentialHomeLock, withCredentialHomeLock, bootstrapPlugin, bundledPluginRoot, cleanupSdkDirectory, codexSecurityCredentialAllowsAmbientImport, codexSecurityCredentialHome, codexSecurityHasStoredFileCredentials, codexSecurityStateDirectory, codexExecutableReadPaths, createIsolatedHome, executablePathForSpawn, expandHome, importAmbientAuth, prepareCodexSecurityCredentialHome, preserveCodexSecurityPluginRegistration, pluginExecutionEnvironment, environmentWithGit, pluginMetadata, planOutputArchive, prepareScanArtifactRestorer, prepareOutputDir, prepareScanRegistrationOutput, preparePersistentOutputRoot, probeCodexSandbox, requireModelSafeOutputDir, requireOutputOutsideRepositories, requireOutputOutsideRepository, requirePrivateCredentialHome, requirePrivatePolicyOutputDirectory, resolveCodexCommand, resolvePluginPath, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, validateOutputDir, } from "./runtime.js";
59
+ import { canonicalConfigPath, acquireCodexSecurityCredentialHomeLock, withCredentialHomeLock, bootstrapPlugin, bundledPluginRoot, cleanupSdkDirectory, codexSecurityCredentialAllowsAmbientImport, codexSecurityCredentialHome, codexSecurityHasStoredFileCredentials, codexSecurityStateDirectory, codexExecutableReadPaths, createIsolatedHome, executablePathForSpawn, expandHome, importAmbientAuth, prepareCodexSecurityCredentialHome, preserveCodexSecurityPluginRegistration, pluginExecutionEnvironment, environmentWithGit, pluginMetadata, planOutputArchive, prepareScanArtifactRestorer, prepareOutputDir, prepareScanRegistrationOutput, preparePersistentOutputRoot, probeCodexSandbox, requireModelSafeOutputDir, requireOutputOutsideRepositories, requireOutputOutsideRepository, requirePrivateCredentialHome, preparePolicyOutputDirectory, resolveCodexCommand, resolvePluginPath, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, validateOutputDir, } from "./runtime.js";
59
60
  import { enclosingGitWorktreeRoot, normalizeRepository, normalizeTarget, gitMarkerRoot, repositoryRevision, resolveRepositoryPath, validatedGitEnvironment, validateCommittedDiffCheckout, validateMode, } from "./targets.js";
60
61
  import { inspectTrustedExecutable, isWithin, } from "./trusted-executable.js";
61
62
  const DEEP_SCAN_CONFIG_PATH_ENVIRONMENT = "CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH";
@@ -165,9 +166,13 @@ export class CodexSecurity {
165
166
  // Reject the removed experimental option rather than starting local inference.
166
167
  if ("hosted" in options)
167
168
  throw new CodexSecurityError("Use runHostedScan with an executor for hosted execution.");
169
+ options = {
170
+ ...options,
171
+ severityRubric: options.severityRubric && { ...options.severityRubric },
172
+ };
168
173
  return await this.#trackOperation(() => options.workflowId === undefined
169
- ? this.#run(repository, { ...options })
170
- : this.#runWorkflow(repository, { ...options }, options.workflowId));
174
+ ? this.#run(repository, options)
175
+ : this.#runWorkflow(repository, options, options.workflowId));
171
176
  }
172
177
  async #runWorkflow(repository, options, workflowId) {
173
178
  this.#requireOpen();
@@ -192,6 +197,8 @@ export class CodexSecurity {
192
197
  ? undefined
193
198
  : resolve(expandHome(options.outputDir)),
194
199
  workflowId: undefined,
200
+ severityRubric: undefined,
201
+ rubricPath: undefined,
195
202
  signal: undefined,
196
203
  auth: undefined,
197
204
  archiveExisting: undefined,
@@ -203,7 +210,7 @@ export class CodexSecurity {
203
210
  let metadata = state.stages.scan.result;
204
211
  let completed = state.stages.scan.status === "completed";
205
212
  if (!completed) {
206
- const scan = await workflow.registeredScan(state.scanId);
213
+ const { scan, recipe } = await workflow.registeredScan(state.scanId);
207
214
  completed =
208
215
  scan["progress"]?.["status"] ===
209
216
  "complete";
@@ -212,6 +219,8 @@ export class CodexSecurity {
212
219
  threadId: scan["continuationThreadId"] ?? "",
213
220
  turnResult: { status: "completed" },
214
221
  };
222
+ else
223
+ local.retryRecipe = isRecord(recipe) ? recipe : {};
215
224
  }
216
225
  if (completed) {
217
226
  const contract = await loadContract(state.scanDir, {
@@ -219,13 +228,16 @@ export class CodexSecurity {
219
228
  expectedScanId: state.scanId,
220
229
  signal,
221
230
  });
222
- await workflow.bind({ artifactDigest: scanArtifactDigest(contract) });
231
+ const verified = await workflow.bind({
232
+ artifactDigest: scanArtifactDigest(contract),
233
+ });
223
234
  metadata ??= { threadId: "", turnResult: { status: "completed" } };
224
235
  await workflow.complete("scan", metadata);
225
236
  return new ScanResult({
226
237
  ...contract,
227
238
  scanDir: state.scanDir,
228
239
  ...metadata,
240
+ recordedCost: verified.recordedCost,
229
241
  threatModelPath: await readThreatModelPath(state.scanDir, {
230
242
  pythonPath: this.config.pythonPath,
231
243
  protectedRoot: local.protectedRoot,
@@ -758,7 +770,7 @@ export class CodexSecurity {
758
770
  const knowledgeBase = await prepareKnowledgeBase(options.knowledgeBaseSnapshot ?? options.knowledgeBasePaths, options.signal);
759
771
  await knowledgeBase.cleanup();
760
772
  }
761
- const configuration = await mergedCodexConfig(this.config);
773
+ const configuration = await mergedCodexConfig(this.config, scanCodexHome(this.#dependencies.environment));
762
774
  const model = scanModelConfiguration(configuration);
763
775
  const modelProvider = scanModelProvider(configuration);
764
776
  validateScanCostLimit(options.maxCostUsd, model.model);
@@ -779,7 +791,7 @@ export class CodexSecurity {
779
791
  : {}),
780
792
  outputDir: inputs.outputDir,
781
793
  ...(archiveDir === null ? {} : { archiveDir }),
782
- authentication: scanAuthentication(this.#dependencies.environment, options.auth, modelProvider, hasCommandAuth(configuration), true),
794
+ authentication: scanAuthentication(this.#dependencies.environment, options.auth, modelProvider, hasCommandAuth(configuration), true, scanProviderEnvKey(configuration)),
783
795
  ...model,
784
796
  ...(typeof modelProvider === "string" ? { modelProvider } : {}),
785
797
  ...(options.maxCostUsd === undefined
@@ -863,8 +875,8 @@ export class CodexSecurity {
863
875
  outputDir = await (this.#dependencies.prepareOutputDir ?? prepareOutputDir)(inputs.outputDir ?? undefined, `${basename(target.repository)}-policy`, root, (path) => requireOutputOutsideRepositories(inputs.protectedRoots, path));
864
876
  requireOutputOutsideRepositories(inputs.protectedRoots, outputDir);
865
877
  requireModelSafeOutputDir(outputDir);
866
- await (this.#dependencies.requirePrivatePolicyOutputDirectory ??
867
- requirePrivatePolicyOutputDirectory)(outputDir);
878
+ await (this.#dependencies.preparePolicyOutputDirectory ??
879
+ preparePolicyOutputDirectory)(outputDir);
868
880
  if (options.knowledgeBasePaths?.length) {
869
881
  knowledgeBase = await prepareKnowledgeBase(options.knowledgeBasePaths, signal, outputDir);
870
882
  }
@@ -1067,8 +1079,11 @@ export class CodexSecurity {
1067
1079
  let knowledgeBase = null;
1068
1080
  let costTracker = null;
1069
1081
  let scanProgressTracker = null;
1082
+ let savedProviderProfile;
1070
1083
  let artifactRestorationFailure = null;
1071
- let customValidationComplete = false;
1084
+ const customValidation = {
1085
+ status: "pending",
1086
+ };
1072
1087
  let completionCost = null;
1073
1088
  let scanTurnStatus = null;
1074
1089
  let budgetRecovery = null;
@@ -1147,7 +1162,7 @@ export class CodexSecurity {
1147
1162
  const { runtime, runtimeHome, effectiveConfig, preflightConfig, modelProvider, authentication, approvalPolicy, python, } = session;
1148
1163
  let git = {
1149
1164
  executable: null,
1150
- environment: selectedScanEnvironment(runtime.environment, options.auth, modelProvider),
1165
+ environment: selectedScanEnvironment(runtime.environment, options.auth, modelProvider, session.externalProvider?.env_key),
1151
1166
  };
1152
1167
  for (const root of [
1153
1168
  (await gitMarkerRoot(repo, signal, "outermost")) ?? repo,
@@ -1183,7 +1198,7 @@ export class CodexSecurity {
1183
1198
  }
1184
1199
  checkOpen();
1185
1200
  const workerProviderEnvironment = {
1186
- ...withoutOpenAiApiKeys(selectedScanEnvironment(runtime.environment, options.auth, modelProvider)),
1201
+ ...withoutOpenAiApiKeys(selectedScanEnvironment(runtime.environment, options.auth, modelProvider, session.externalProvider?.env_key)),
1187
1202
  ...(session.apiKey === null
1188
1203
  ? {}
1189
1204
  : {
@@ -1270,24 +1285,52 @@ export class CodexSecurity {
1270
1285
  let reviewedFileCount = 0;
1271
1286
  let latestPhase = "preflight";
1272
1287
  let reviewItems;
1273
- const reportProgress = (progress) => {
1274
- if (scopeFileCount === null ||
1275
- progress.filesTotal > scopeFileCount ||
1276
- progress.filesCompleted < reviewedFileCount) {
1288
+ let lastProgress = null;
1289
+ const progressKey = (progress) => `${progress.phase}:${progress.filesCompleted}:${progress.filesTotal}:${progress.reviewItems?.completed}:${progress.reviewItems?.total}`;
1290
+ const reportProgress = (progress, source) => {
1291
+ const liveEvent = source?.reconciled === true ? undefined : source?.event;
1292
+ if (liveEvent !== undefined &&
1293
+ !tracker.recordParentProgress(progress, liveEvent))
1294
+ return;
1295
+ const inventory = source?.inventory === true ||
1296
+ (progress.phase === "discovery" &&
1297
+ reviewedFileCount === 0 &&
1298
+ progress.filesCompleted === 0);
1299
+ const filesTotal = inventory ? progress.filesTotal : scopeFileCount;
1300
+ if (filesTotal === null ||
1301
+ progress.filesTotal > filesTotal ||
1302
+ (source?.inventory !== true &&
1303
+ progress.filesCompleted < reviewedFileCount)) {
1304
+ if (liveEvent !== undefined)
1305
+ tracker.deferParentInventory(liveEvent);
1277
1306
  return;
1278
1307
  }
1308
+ if (inventory) {
1309
+ scopeFileCount = filesTotal;
1310
+ tracker.setExpectedFilesTotal(filesTotal);
1311
+ }
1279
1312
  reviewedFileCount = progress.filesCompleted;
1280
- if (mode === "deep" ||
1313
+ if (liveEvent !== undefined)
1314
+ tracker.acceptParentProgress(progress, liveEvent);
1315
+ if (source !== undefined ||
1316
+ mode === "deep" ||
1281
1317
  scanPhaseSchema.options.indexOf(progress.phase) >
1282
1318
  scanPhaseSchema.options.indexOf(latestPhase)) {
1283
1319
  latestPhase = progress.phase;
1284
1320
  }
1285
- notifyObserver(options, "onProgress")({
1321
+ const update = {
1286
1322
  ...progress,
1287
- phase: latestPhase,
1288
- filesTotal: scopeFileCount,
1323
+ phase: customValidation.status === "running"
1324
+ ? "validation"
1325
+ : latestPhase,
1326
+ filesTotal,
1289
1327
  ...(reviewItems === undefined ? {} : { reviewItems }),
1290
- });
1328
+ };
1329
+ const key = progressKey(update);
1330
+ if (lastProgress === key)
1331
+ return;
1332
+ lastProgress = key;
1333
+ notifyObserver(options, "onProgress")(update);
1291
1334
  };
1292
1335
  const reportWorkerStatus = (status) => {
1293
1336
  if (mode !== "deep") {
@@ -1341,11 +1384,15 @@ export class CodexSecurity {
1341
1384
  : (event) => notifyObserver(options, "onSessionEvent")(event),
1342
1385
  onProgress: options.onProgress === undefined
1343
1386
  ? undefined
1344
- : (progress) => reportProgress({
1387
+ : (progress, source) => reportProgress({
1345
1388
  ...progress,
1346
- // Worker counts belong to the parent scan's current phase.
1347
- phase: mode === "deep" ? progress.phase : latestPhase,
1348
- }),
1389
+ // Only worker counts use the last accepted parent phase.
1390
+ phase: mode === "deep" ||
1391
+ (source !== undefined &&
1392
+ (source.reconciled !== true || !source.worker))
1393
+ ? progress.phase
1394
+ : latestPhase,
1395
+ }, source),
1349
1396
  onCost: options.onCost === undefined && options.maxCostUsd === undefined
1350
1397
  ? undefined
1351
1398
  : (cost, complete) => {
@@ -1403,14 +1450,74 @@ export class CodexSecurity {
1403
1450
  onError: reportTrackingError,
1404
1451
  });
1405
1452
  costTracker = tracker;
1453
+ // Saved launches reload the native file; preflight uses resolved values.
1454
+ const profileName = effectiveConfig["profile"];
1455
+ const inlineProfiles = effectiveConfig["profiles"];
1456
+ const fileProfile = typeof profileName === "string" &&
1457
+ !(isRecord(inlineProfiles) && isRecord(inlineProfiles[profileName]));
1458
+ const overrides = this.config.codexOverrides ?? {};
1459
+ const recipeConfig = {
1460
+ ...(fileProfile
1461
+ ? scanPreflightCodexConfig(overrides)
1462
+ : preflightConfig),
1463
+ approval_policy: approvalPolicy,
1464
+ };
1465
+ // Reruns allocate a new output directory; retain the original file origins.
1466
+ for (const key of MODEL_FILE_SETTINGS) {
1467
+ const value = workerRuntimeConfig[key];
1468
+ if (typeof value !== "string" ||
1469
+ (fileProfile && !(key in recipeConfig)))
1470
+ continue;
1471
+ recipeConfig[key] = value;
1472
+ const profiles = recipeConfig["profiles"];
1473
+ if (typeof profileName === "string" &&
1474
+ isRecord(profiles) &&
1475
+ isRecord(profiles[profileName]) &&
1476
+ typeof profiles[profileName][key] === "string") {
1477
+ recipeConfig["profiles"] = {
1478
+ ...profiles,
1479
+ [profileName]: { ...profiles[profileName], [key]: value },
1480
+ };
1481
+ }
1482
+ }
1483
+ if (fileProfile) {
1484
+ recipeConfig["profile"] = profileName;
1485
+ delete recipeConfig["skills"];
1486
+ // Reload inherited file settings, retaining explicit refinements omitted
1487
+ // from the readable recipe in the existing private replay snapshot.
1488
+ delete recipeConfig["model_providers"];
1489
+ const replayOverrides = privateReplayOverrides(overrides, recipeConfig);
1490
+ resolveNestedConfigPaths(replayOverrides, scanDir);
1491
+ if (options.resumeScanId === undefined &&
1492
+ Object.keys(replayOverrides).length > 0) {
1493
+ savedProviderProfile = await createProviderProfile(codexSecurityCredentialHome(this.#dependencies.environment), replayOverrides, { replay: true });
1494
+ }
1495
+ }
1406
1496
  const scanKnowledge = knowledgeBase === null ? undefined : options.knowledgeBaseSnapshot;
1497
+ let severityRubric;
1498
+ if (this.#dependencies.hostedScan === undefined &&
1499
+ options.resumeScanId === undefined) {
1500
+ if (inputs.retryRecipe !== undefined)
1501
+ severityRubric = severityRubricSchema
1502
+ .optional()
1503
+ .parse(inputs.retryRecipe["severityRubric"]);
1504
+ else if (options.severityRubric !== undefined)
1505
+ severityRubric = severityRubricSchema.parse(options.severityRubric);
1506
+ else if (options.rubricPath !== undefined)
1507
+ severityRubric = await readSeverityRubricFile(resolve(expandHome(options.rubricPath)), protectedRoot);
1508
+ else
1509
+ severityRubric = await getDefaultSeverityRubric({
1510
+ environment: this.#dependencies.environment,
1511
+ signal,
1512
+ });
1513
+ }
1407
1514
  const recipe = scanRecipe({
1408
1515
  repository: repo,
1409
1516
  target: normalized,
1410
1517
  mode,
1411
1518
  repositoryRevision: expectation.repositoryRevision,
1412
1519
  pluginVersion: runtime.plugin.version,
1413
- config: { ...preflightConfig, approval_policy: approvalPolicy },
1520
+ config: recipeConfig,
1414
1521
  failOnSeverity: options.failureSeverity,
1415
1522
  knowledgeBasePaths: knowledgeBase?.sources,
1416
1523
  maxCostUsd: options.maxCostUsd,
@@ -1420,8 +1527,16 @@ export class CodexSecurity {
1420
1527
  cyberAccessProgram: options.cyberAccessProgram,
1421
1528
  ownerSuggestions: options.ownerSuggestions,
1422
1529
  });
1530
+ if (savedProviderProfile !== undefined) {
1531
+ recipe["providerProfile"] = {
1532
+ name: savedProviderProfile.name,
1533
+ home: "managed",
1534
+ };
1535
+ }
1423
1536
  if (options.scanPrompt?.trim())
1424
1537
  recipe["requiresScanPrompt"] = true;
1538
+ if (severityRubric !== undefined)
1539
+ recipe["severityRubric"] = severityRubric;
1425
1540
  recipe["scanInputs"] = scanInputIdentity(options.scanPrompt, scanKnowledge);
1426
1541
  if (options.safetyIdentifier !== undefined)
1427
1542
  recipe["safetyIdentifier"] = options.safetyIdentifier;
@@ -1457,7 +1572,49 @@ export class CodexSecurity {
1457
1572
  recipe,
1458
1573
  userContext: options.scanPrompt,
1459
1574
  workflowId: options.workflowId,
1460
- }));
1575
+ })).catch(async (error) => {
1576
+ const profile = savedProviderProfile;
1577
+ if (profile !== undefined) {
1578
+ // Registration can commit before cancellation or an output error.
1579
+ // Delete the snapshot only after confirming no saved recipe owns it.
1580
+ savedProviderProfile = undefined;
1581
+ try {
1582
+ const lookupOptions = {
1583
+ ...workbenchOptions,
1584
+ signal: undefined,
1585
+ };
1586
+ const { scans } = await workbench(lookupOptions, [
1587
+ "list-scans",
1588
+ "--scan-root",
1589
+ scanDir,
1590
+ ]);
1591
+ let referenced = false;
1592
+ for (const scan of scans) {
1593
+ if (scan["recipeAvailable"] === false)
1594
+ continue;
1595
+ const { recipe: savedRecipe } = await workbench(lookupOptions, [
1596
+ "get-scan-recipe",
1597
+ "--scan-id",
1598
+ scan["scanId"],
1599
+ ]);
1600
+ if (isRecord(savedRecipe) &&
1601
+ isRecord(savedRecipe["providerProfile"]) &&
1602
+ savedRecipe["providerProfile"]["name"] === profile.name) {
1603
+ referenced = true;
1604
+ break;
1605
+ }
1606
+ }
1607
+ if (!referenced)
1608
+ savedProviderProfile = profile;
1609
+ }
1610
+ catch {
1611
+ // An unavailable receipt cannot establish that cleanup is safe.
1612
+ }
1613
+ }
1614
+ throw error;
1615
+ });
1616
+ // The registered recipe now owns the private snapshot, including after completion.
1617
+ savedProviderProfile = undefined;
1461
1618
  const scanId = registration["scanId"];
1462
1619
  const resumeThreadId = options.resumeScanId === undefined
1463
1620
  ? undefined
@@ -1482,6 +1639,9 @@ export class CodexSecurity {
1482
1639
  expectation.pluginVersion = registration["sealedProducerVersion"];
1483
1640
  }
1484
1641
  const savedInputs = savedRecipe["scanInputs"];
1642
+ severityRubric = severityRubricSchema
1643
+ .optional()
1644
+ .parse(savedRecipe["severityRubric"]);
1485
1645
  if (isRecord(savedInputs) &&
1486
1646
  workflowDigest(savedInputs["knowledgeBase"]) !==
1487
1647
  workflowDigest(recipe["scanInputs"]["knowledgeBase"])) {
@@ -1603,7 +1763,7 @@ export class CodexSecurity {
1603
1763
  const basePrompt = scanPrompt(await targetInstruction(normalized, shellPluginRoot, this.#dependencies.hostedScan !== undefined), mode, skillName, scanId, knowledgeBase !== null, options.resumeScanId !== undefined &&
1604
1764
  typeof registration["userContext"] === "string"
1605
1765
  ? registration["userContext"]
1606
- : options.scanPrompt, options.maxCostUsd !== undefined, discoveryPrompt, modelProvider, options.ownerSuggestions);
1766
+ : options.scanPrompt, options.maxCostUsd !== undefined, discoveryPrompt, modelProvider, options.ownerSuggestions, severityRubric);
1607
1767
  checkOpen();
1608
1768
  const feedback = await workbench({
1609
1769
  ...workbenchOptions,
@@ -1679,54 +1839,98 @@ export class CodexSecurity {
1679
1839
  ? {}
1680
1840
  : { CODEX_SECURITY_TARGET_PATHS_FILE: targetPathsFile }),
1681
1841
  };
1682
- const { codex, environment, codexOptions } = await this.#createSessionCodex(session, { command: "scan", mode }, runtimePaths, options.auth, git, mode === "deep" && !directDeepScan
1683
- ? deepScanParentConfig(session.sessionConfig)
1684
- : undefined);
1842
+ const { codex, environment, codexOptions } = await this.#createSessionCodex(session, { command: "scan", mode }, runtimePaths, options.auth, git);
1685
1843
  const threadOptions = {
1686
1844
  threadSource: CODEX_SECURITY_THREAD_SOURCES.scan,
1687
1845
  workingDirectory: scanDir,
1688
1846
  skipGitRepoCheck: true,
1689
1847
  approvalPolicy,
1690
1848
  };
1691
- let thread;
1692
- if (typeof resumeThreadId === "string") {
1693
- if (codex.resumeThread === undefined) {
1849
+ const turnOptions = {
1850
+ signal,
1851
+ cyberAccessProgram: options.cyberAccessProgram,
1852
+ };
1853
+ const postScanPrompt = options.postScanPrompt;
1854
+ const openThread = (client, id) => {
1855
+ if (typeof id !== "string")
1856
+ return client.startThread(threadOptions);
1857
+ if (!client.resumeThread)
1694
1858
  throw new CodexSecurityError("The configured Codex client does not support resuming sessions.");
1695
- }
1696
- thread = codex.resumeThread(resumeThreadId, threadOptions);
1859
+ return client.resumeThread(id, threadOptions);
1860
+ };
1861
+ if (typeof resumeThreadId === "string") {
1697
1862
  tracker.start(resumeThreadId);
1698
1863
  if (budgetRecovery !== null)
1699
1864
  budgetRecovery.threadId = resumeThreadId;
1700
1865
  await tracker.refresh().catch(reportTrackingError);
1701
- checkOpen();
1702
- }
1703
- else {
1704
- thread = codex.startThread(threadOptions);
1705
1866
  }
1706
- const serializedPaths = normalized.kind === "paths" ? jsonForPrompt(normalized.paths) : null;
1707
1867
  checkOpen();
1708
- if (serializedPaths !== null && targetPathsFile !== null) {
1709
- await writeFile(targetPathsFile, `${serializedPaths}\n`, {
1868
+ if (normalized.kind === "paths" && targetPathsFile !== null) {
1869
+ await writeFile(targetPathsFile, `${jsonForPrompt(normalized.paths)}\n`, {
1710
1870
  flag: "wx",
1711
1871
  mode: 0o400,
1712
1872
  signal,
1713
1873
  });
1714
1874
  await chmod(targetPathsFile, 0o400);
1875
+ checkOpen();
1876
+ }
1877
+ let parentCodex = codex;
1878
+ const pluginServers = mode === "deep" && !directDeepScan && !this.#dependencies.hostedScan
1879
+ ? await readInstalledDeepScanPluginServers(runtime.plugin.installedRoot)
1880
+ : undefined;
1881
+ if (pluginServers !== undefined) {
1882
+ // The scan is already registered when native routing is inspected.
1883
+ if (postScanPrompt?.trim()) {
1884
+ runPostScan = () => openThread(codex, resumeThreadId).runStreamed(postScanPrompt, turnOptions);
1885
+ }
1886
+ const parentConfig = await (this.#dependencies.readDeepScanParentConfig ??
1887
+ readDeepScanParentConfig)({
1888
+ codexOptions,
1889
+ preflightCommand: await this.#providerPreflightCommand(effectiveConfig),
1890
+ scanDir,
1891
+ signal,
1892
+ ...(pluginServers !== "native" && { pluginServers }),
1893
+ ...(pluginServers === "native" && {
1894
+ plugin: {
1895
+ marketplacePath: join(runtime.plugin.marketplaceRoot, ".agents", "plugins", "marketplace.json"),
1896
+ pluginName: runtime.plugin.name,
1897
+ },
1898
+ }),
1899
+ });
1900
+ const overrides = parentConfig === undefined
1901
+ ? []
1902
+ : deepScanParentToolOverrides(parentConfig, pluginServers === "native" ? {} : pluginServers);
1903
+ if (overrides.length > 0) {
1904
+ // Only the coordinator turn needs to keep its MCP call outside a yielding cell.
1905
+ parentCodex = await this.#dependencies.createCodex({
1906
+ ...codexOptions,
1907
+ configOverrides: [
1908
+ ...(codexOptions.configOverrides ?? []),
1909
+ ...overrides,
1910
+ ],
1911
+ });
1912
+ }
1913
+ runPostScan = null;
1715
1914
  }
1716
1915
  checkOpen();
1717
- const turnOptions = {
1718
- signal,
1719
- cyberAccessProgram: options.cyberAccessProgram,
1720
- };
1721
- const postScanPrompt = options.postScanPrompt;
1916
+ const thread = openThread(parentCodex, resumeThreadId);
1917
+ let scanThreadId = thread.id;
1722
1918
  if (postScanPrompt?.trim()) {
1723
- runPostScan = () => thread.runStreamed(postScanPrompt, turnOptions);
1919
+ runPostScan = () => {
1920
+ if ((parentCodex !== codex || directDeepScan) &&
1921
+ scanThreadId !== null) {
1922
+ return openThread(codex, scanThreadId).runStreamed(postScanPrompt, turnOptions);
1923
+ }
1924
+ const followUp = parentCodex === codex ? thread : codex.startThread(threadOptions);
1925
+ return followUp.runStreamed(postScanPrompt, turnOptions);
1926
+ };
1724
1927
  }
1725
1928
  if (mode === "standard" && options.maxTimeMinutes !== undefined) {
1726
1929
  const timePolicy = await readScanTimeBudgetPolicy(runtime.plugin.pluginRoot);
1727
1930
  checkOpen();
1728
1931
  prompt += `\n\n${renderScanTimeBudgetPolicy(timePolicy, scanTimeBudget(options.maxTimeMinutes, (this.#dependencies.now ?? Date.now)()))}`;
1729
1932
  }
1933
+ tracker.beginParentTurn(resumeThreadId !== undefined);
1730
1934
  const events = directDeepScan
1731
1935
  ? (this.#dependencies.runDeepScan ?? runDeepScan)({
1732
1936
  codexOptions,
@@ -1762,15 +1966,7 @@ export class CodexSecurity {
1762
1966
  if (resumeThreadId !== undefined && threadId !== resumeThreadId) {
1763
1967
  throw new CodexSecurityError("Codex did not resume the original scan session.");
1764
1968
  }
1765
- if (directDeepScan && postScanPrompt?.trim()) {
1766
- runPostScan = () => {
1767
- if (codex.resumeThread === undefined)
1768
- throw new CodexSecurityError("The configured Codex client does not support resuming sessions.");
1769
- return codex
1770
- .resumeThread(threadId, threadOptions)
1771
- .runStreamed(postScanPrompt, turnOptions);
1772
- };
1773
- }
1969
+ scanThreadId = threadId;
1774
1970
  if (resumeThreadId !== undefined) {
1775
1971
  return;
1776
1972
  }
@@ -1798,12 +1994,14 @@ export class CodexSecurity {
1798
1994
  scanId,
1799
1995
  pluginRoot: runtime.plugin.installedRoot,
1800
1996
  prompt: options.validationPrompt,
1997
+ severityRubric,
1801
1998
  falsePositives: falsePositiveExamples,
1802
1999
  signal,
1803
2000
  run: async (validationPrompt, outputSchema) => {
1804
2001
  // This turn follows the primary scan's reporting phase.
1805
2002
  scanProgressTracker?.stop();
1806
2003
  latestPhase = "validation";
2004
+ customValidation.status = "running";
1807
2005
  if (scopeFileCount !== null)
1808
2006
  reportProgress({
1809
2007
  phase: "validation",
@@ -1835,7 +2033,7 @@ export class CodexSecurity {
1835
2033
  return turn.finalResponse;
1836
2034
  },
1837
2035
  });
1838
- customValidationComplete = true;
2036
+ customValidation.status = "complete";
1839
2037
  }
1840
2038
  budgetAbortController.abort();
1841
2039
  const snapshot = await tracker.stop(usage).catch((error) => {
@@ -1879,16 +2077,10 @@ export class CodexSecurity {
1879
2077
  onTrustedAccessStatus: options.onTrustedAccessStatus,
1880
2078
  onReconnect: options.onReconnect,
1881
2079
  onActivity: options.onActivity,
1882
- onProgress: (progress) => {
1883
- if (progress.phase === "discovery" &&
1884
- progress.filesCompleted === 0 &&
1885
- reviewedFileCount === 0 &&
1886
- progress.filesTotal !== scopeFileCount) {
1887
- scopeFileCount = progress.filesTotal;
1888
- tracker.setExpectedFilesTotal(scopeFileCount);
1889
- }
1890
- reportProgress(progress);
1891
- },
2080
+ onProgressItem: options.onProgress === undefined
2081
+ ? undefined
2082
+ : (event) => tracker.recordParentItem(event),
2083
+ onProgress: reportProgress,
1892
2084
  onWorkerStatus: reportWorkerStatus,
1893
2085
  onWarning: options.onWarning,
1894
2086
  onObserverError: options.onObserverError,
@@ -2140,7 +2332,7 @@ export class CodexSecurity {
2140
2332
  // Deep Scan orchestration persists its own terminal failures and cancellations.
2141
2333
  if (activeScan !== null && options.resumeScanId === undefined) {
2142
2334
  if (options.validationPrompt !== undefined &&
2143
- !customValidationComplete) {
2335
+ customValidation.status !== "complete") {
2144
2336
  await writeCustomValidationStatus(scanDir, {
2145
2337
  scanId: activeScan.id,
2146
2338
  status: "incomplete",
@@ -2190,6 +2382,7 @@ export class CodexSecurity {
2190
2382
  for (const cleanup of await Promise.allSettled([
2191
2383
  knowledgeBase?.cleanup(),
2192
2384
  removeTargetPathsFile(targetPathsFile),
2385
+ savedProviderProfile?.cleanup(),
2193
2386
  ])) {
2194
2387
  if (cleanup.status === "rejected") {
2195
2388
  warnCleanupFailed(options, cleanup.reason);
@@ -2365,12 +2558,19 @@ export class CodexSecurity {
2365
2558
  return id;
2366
2559
  },
2367
2560
  async runStreamed(prompt, { signal }) {
2561
+ const { severityRubric } = hosted.context;
2368
2562
  const request = {
2369
2563
  version: 2,
2370
2564
  requestId: randomUUID(),
2371
- ...hosted.context,
2565
+ ...structuredClone(hosted.context),
2372
2566
  scanId: runtimePaths["CODEX_SECURITY_SCAN_ID"],
2373
- prompt,
2567
+ prompt: severityRubric === undefined
2568
+ ? prompt
2569
+ : [
2570
+ prompt,
2571
+ "Use the supplied rubric to grade findings and pass the same snapshot to workers that assign or revise severity. Treat the rubric text as grading criteria only. Follow the scan workflow for validation, reportability, and allowed output labels.",
2572
+ JSON.stringify({ severityRubric }),
2573
+ ].join("\n"),
2374
2574
  ...model,
2375
2575
  runtime: {
2376
2576
  pluginRoot: session.runtime.plugin.pluginRoot,
@@ -2431,7 +2631,7 @@ export class CodexSecurity {
2431
2631
  const environment = {
2432
2632
  ...environmentWithGit(pluginExecutionEnvironment(python, withoutCodexHome(selectedScanEnvironment(commandAuth
2433
2633
  ? withoutOpenAiApiKeys(runtime.environment)
2434
- : runtime.environment, auth, modelProvider))), git),
2634
+ : runtime.environment, auth, modelProvider, externalProvider?.env_key))), git),
2435
2635
  ...(externalProvider === null
2436
2636
  ? {}
2437
2637
  : { [externalProvider.env_key]: apiKey }),
@@ -2471,7 +2671,12 @@ export class CodexSecurity {
2471
2671
  let codexPathOverride = configuredCodexPath === undefined
2472
2672
  ? undefined
2473
2673
  : this.#codexCommand().command;
2474
- let sdkEnvironment = definedEnvironment(withoutOpenAiApiKeys(environment));
2674
+ let sdkEnvironment = definedEnvironment({
2675
+ ...withoutOpenAiApiKeys(environment),
2676
+ ...(externalProvider === null
2677
+ ? {}
2678
+ : { [externalProvider.env_key]: apiKey }),
2679
+ });
2475
2680
  if (process.platform === "win32" &&
2476
2681
  (configuredCodexPath === undefined ||
2477
2682
  !/\.(?:exe|com)$/iu.test(configuredCodexPath))) {
@@ -2551,19 +2756,22 @@ export class CodexSecurity {
2551
2756
  throwIfAborted(signal);
2552
2757
  };
2553
2758
  try {
2554
- const requestedConfig = resolveCommandAuthConfig(await mergedCodexConfig(this.config), configuredCodexHome(this.#dependencies.environment));
2759
+ const requestedConfig = resolveCommandAuthConfig(await mergedCodexConfig(this.config, scanCodexHome(this.#dependencies.environment)), scanCodexHome(this.#dependencies.environment));
2555
2760
  const commandAuth = hasCommandAuth(requestedConfig);
2556
2761
  const modelProvider = scanModelProvider(requestedConfig);
2557
2762
  const externalProvider = !commandAuth && isExternalModelProvider(modelProvider)
2558
- ? EXTERNAL_CODEX_PROVIDERS[modelProvider]
2763
+ ? {
2764
+ ...EXTERNAL_CODEX_PROVIDERS[modelProvider],
2765
+ env_key: scanProviderEnvKey(requestedConfig),
2766
+ }
2559
2767
  : null;
2560
- let authentication = scanAuthentication(this.#dependencies.environment, options.auth, modelProvider, commandAuth);
2768
+ let authentication = scanAuthentication(this.#dependencies.environment, options.auth, modelProvider, commandAuth, false, externalProvider?.env_key);
2561
2769
  const apiKey = authentication.method === "api_key"
2562
- ? environmentApiKey(this.#dependencies.environment, modelProvider)
2770
+ ? environmentApiKey(this.#dependencies.environment, modelProvider, externalProvider?.env_key)
2563
2771
  : null;
2564
2772
  const scanEnvironment = selectedScanEnvironment(commandAuth
2565
2773
  ? withoutOpenAiApiKeys(this.#dependencies.environment)
2566
- : this.#dependencies.environment, options.auth, modelProvider);
2774
+ : this.#dependencies.environment, options.auth, modelProvider, externalProvider?.env_key);
2567
2775
  if (this.#dependencies.prepareRuntime === undefined) {
2568
2776
  const credentialHome = await prepareCodexSecurityCredentialHome(scanEnvironment, (path) => requireOutputOutsideRepositories(protectedRoots, path, "runtime"));
2569
2777
  releaseCredentialHome = await acquireCodexSecurityCredentialHomeLock(credentialHome, signal);
@@ -2642,7 +2850,7 @@ export class CodexSecurity {
2642
2850
  throw new AuthenticationRequiredError(NO_CREDENTIALS_MESSAGE);
2643
2851
  }
2644
2852
  if (!commandAuth)
2645
- authentication = await runtimeScanAuthentication(this.#dependencies.environment, runtime.codexHome, options.auth, modelProvider);
2853
+ authentication = await runtimeScanAuthentication(this.#dependencies.environment, runtime.codexHome, options.auth, modelProvider, externalProvider?.env_key);
2646
2854
  if (options.safetyIdentifier !== undefined &&
2647
2855
  authentication.method !== "api_key" &&
2648
2856
  !(authentication.method === "stored_credentials" &&
@@ -2693,7 +2901,8 @@ export class CodexSecurity {
2693
2901
  resolveCodexCommand(this.#dependencies.environment));
2694
2902
  }
2695
2903
  async #providerPreflightCommand(config) {
2696
- return await providerPreflightCommand(this.#codexCommand(), config ?? (await mergedCodexConfig(this.config)));
2904
+ return await providerPreflightCommand(this.#codexCommand(), config ??
2905
+ (await mergedCodexConfig(this.config, scanCodexHome(this.#dependencies.environment))));
2697
2906
  }
2698
2907
  async #refreshPersistentRuntime(runtime, environment, signal, mergedConfig) {
2699
2908
  throwIfAborted(signal);
@@ -2719,7 +2928,7 @@ export class CodexSecurity {
2719
2928
  }
2720
2929
  }
2721
2930
  async #validatePolicyInputs(target, options, signal) {
2722
- policyCodexConfig(await mergedCodexConfig(this.config));
2931
+ policyCodexConfig(await mergedCodexConfig(this.config, scanCodexHome(this.#dependencies.environment)));
2723
2932
  const sources = await inspectSecurityPolicySources(target, signal);
2724
2933
  const protectedRoots = [
2725
2934
  ...new Set([
@@ -2779,10 +2988,7 @@ export class CodexSecurity {
2779
2988
  notifyObserver(options, "onOutputDirReady")(scanDir);
2780
2989
  }
2781
2990
  const revision = await repositoryRevision(local.repository, signal);
2782
- const { model } = scanModelConfiguration({
2783
- ...DEFAULT_CODEX_CONFIG,
2784
- ...this.config.codexOverrides,
2785
- });
2991
+ const { model } = scanModelConfiguration(await mergedCodexConfig(this.config, scanCodexHome(this.#dependencies.environment)));
2786
2992
  const workbenchOptions = {
2787
2993
  python,
2788
2994
  pluginRoot,
@@ -2990,7 +3196,7 @@ export class CodexSecurity {
2990
3196
  const modelProvider = scanModelProvider(requestedConfig);
2991
3197
  const processEnvironment = selectedScanEnvironment(hasCommandAuth(requestedConfig)
2992
3198
  ? withoutOpenAiApiKeys(this.#dependencies.environment)
2993
- : this.#dependencies.environment, auth, modelProvider);
3199
+ : this.#dependencies.environment, auth, modelProvider, scanProviderEnvKey(requestedConfig));
2994
3200
  const codexHome = await realpath(codexSecurityCredentialHome(processEnvironment));
2995
3201
  let bootstrapWorkspace;
2996
3202
  let deepScanConfigDirectory;
@@ -3158,8 +3364,12 @@ export async function runScanEvents(options) {
3158
3364
  for (const activity of scanActivitiesFromEvent(event, options.expectation.repository)) {
3159
3365
  notifyObserver(options, "onActivity")(activity);
3160
3366
  }
3367
+ options.onProgressItem?.(event);
3161
3368
  for (const progress of scanProgressUpdatesFromEvent(event)) {
3162
- notifyObserver(options, "onProgress")(progress);
3369
+ notifyObserver({
3370
+ onProgress: (update) => options.onProgress?.(update, { event }),
3371
+ onObserverError: options.onObserverError,
3372
+ }, "onProgress")(progress);
3163
3373
  }
3164
3374
  const workerStatus = workerStatusFromEvent(event);
3165
3375
  if (workerStatus !== null) {
@@ -3183,7 +3393,7 @@ export async function runScanEvents(options) {
3183
3393
  const { status, threadId, finalResponse, lastStreamError } = turn;
3184
3394
  let { usage } = turn;
3185
3395
  if (options.signal.aborted) {
3186
- throw new ScanInterruptedError(`Codex Security scan was interrupted; partial output remains at ${options.scanDir}.`, options.scanDir);
3396
+ throw new ScanInterruptedError(`Codex Security scan was interrupted; output directory: ${options.scanDir}.`, options.scanDir);
3187
3397
  }
3188
3398
  if (status !== "completed") {
3189
3399
  throw new IncompleteScanError(lastStreamError ??
@@ -3231,7 +3441,7 @@ export async function runScanEvents(options) {
3231
3441
  ...(options.model === undefined ? {} : { model: options.model }),
3232
3442
  }, threadId, options.scanDir, options.pluginRoot, options.expectation, options.signal, options.workbenchValidated, options.pythonPath, options.protectedRoot);
3233
3443
  if (options.signal.aborted) {
3234
- throw new ScanInterruptedError(`Codex Security scan was interrupted; partial output remains at ${options.scanDir}.`, options.scanDir);
3444
+ throw new ScanInterruptedError(`Codex Security scan was interrupted; output directory: ${options.scanDir}.`, options.scanDir);
3235
3445
  }
3236
3446
  return result;
3237
3447
  }
@@ -3240,7 +3450,7 @@ export async function runScanEvents(options) {
3240
3450
  throw options.signal.reason;
3241
3451
  }
3242
3452
  if (options.signal.aborted && !(error instanceof ScanInterruptedError)) {
3243
- throw new ScanInterruptedError(`Codex Security scan was interrupted; partial output remains at ${options.scanDir}.`, options.scanDir, { cause: error });
3453
+ throw new ScanInterruptedError(`Codex Security scan was interrupted; output directory: ${options.scanDir}.`, options.scanDir, { cause: error });
3244
3454
  }
3245
3455
  throw error;
3246
3456
  }
@@ -3329,7 +3539,7 @@ function trustedAccessWarning(status, authentication) {
3329
3539
  : "your Trusted Access for Cyber status";
3330
3540
  return `Some cybersecurity requests or findings may be refused because ${access} could not be verified. Check ${apiOrganization ? "your organization's access" : "your access"} or apply at ${applicationUrl}.`;
3331
3541
  }
3332
- function scanPrompt(targetDescription, mode, skillName, scanId, hasKnowledgeBase = false, additionalPrompt, enforceCostLimit = false, discoveryPrompt, modelProvider, ownerSuggestions = false) {
3542
+ function scanPrompt(targetDescription, mode, skillName, scanId, hasKnowledgeBase = false, additionalPrompt, enforceCostLimit = false, discoveryPrompt, modelProvider, ownerSuggestions = false, severityRubric) {
3333
3543
  const python = pluginPythonCommand();
3334
3544
  const customValidation = discoveryPrompt !== undefined;
3335
3545
  return [
@@ -3411,6 +3621,7 @@ function scanPrompt(targetDescription, mode, skillName, scanId, hasKnowledgeBase
3411
3621
  : [
3412
3622
  "Use record_codex_security_scan_draft and complete_codex_security_scan as directed by the selected skill; the workbench owns authoritative metadata, finalization, report generation, and sealing.",
3413
3623
  ]),
3624
+ ...(severityRubric ? [severityRubricInstructions(severityRubric)] : []),
3414
3625
  ...(additionalPrompt?.trim()
3415
3626
  ? ["Additional scan instructions:", additionalPrompt]
3416
3627
  : []),
@@ -3583,7 +3794,7 @@ async function collectResult(turnResult, threadId, scanDir, pluginRoot, expectat
3583
3794
  }),
3584
3795
  });
3585
3796
  }
3586
- export function scanAuthentication(environment, auth = DEFAULT_SCAN_AUTH, modelProvider, commandAuth = false, preflight = false) {
3797
+ export function scanAuthentication(environment, auth = DEFAULT_SCAN_AUTH, modelProvider, commandAuth = false, preflight = false, providerEnvKey) {
3587
3798
  if (!SCAN_AUTH_MODES.includes(auth)) {
3588
3799
  throw new TypeError("Scan authentication mode must be auto, chatgpt, or api-key.");
3589
3800
  }
@@ -3608,13 +3819,17 @@ export function scanAuthentication(environment, auth = DEFAULT_SCAN_AUTH, modelP
3608
3819
  if (auth === "chatgpt" && !isExternalModelProvider(modelProvider)) {
3609
3820
  return { method: "stored_credentials", verified: false };
3610
3821
  }
3611
- const key = environmentApiKeyEntry(environment, modelProvider);
3822
+ const key = environmentApiKeyEntry(environment, modelProvider, providerEnvKey);
3612
3823
  if (key === null && isExternalModelProvider(modelProvider)) {
3613
3824
  const provider = EXTERNAL_CODEX_PROVIDERS[modelProvider];
3614
3825
  if (preflight && auth === "auto") {
3615
- return { method: "api_key", source: provider.env_key, verified: false };
3826
+ return {
3827
+ method: "api_key",
3828
+ source: providerEnvKey ?? provider.env_key,
3829
+ verified: false,
3830
+ };
3616
3831
  }
3617
- throw new AuthenticationRequiredError(`Set ${provider.env_key} to run a scan through ${provider.name}.`);
3832
+ throw new AuthenticationRequiredError(`Set ${providerEnvKey ?? provider.env_key} to run a scan through ${provider.name}.`);
3618
3833
  }
3619
3834
  if (auth === "api-key" &&
3620
3835
  key === null &&
@@ -3640,8 +3855,8 @@ export function formatEnvironmentVariableRemovalGuidance(names) {
3640
3855
  return `remove ${names.slice(0, -1).join(", ")}, and ${names[names.length - 1]} from the environment`;
3641
3856
  }
3642
3857
  /** @internal */
3643
- export async function runtimeScanAuthentication(environment, codexHome, auth = "auto", modelProvider) {
3644
- const authentication = scanAuthentication(environment, auth, modelProvider);
3858
+ export async function runtimeScanAuthentication(environment, codexHome, auth = "auto", modelProvider, providerEnvKey) {
3859
+ const authentication = scanAuthentication(environment, auth, modelProvider, false, false, providerEnvKey);
3645
3860
  if (authentication.method !== "stored_credentials")
3646
3861
  return authentication;
3647
3862
  try {
@@ -3662,24 +3877,35 @@ export async function runtimeScanAuthentication(environment, codexHome, auth = "
3662
3877
  return authentication;
3663
3878
  }
3664
3879
  /** @internal */
3665
- export function selectedScanEnvironment(environment, auth = "auto", modelProvider) {
3666
- const selectedProviderKey = isExternalModelProvider(modelProvider)
3880
+ export function selectedScanEnvironment(environment, auth = "auto", modelProvider, providerEnvKey) {
3881
+ const standardProviderKey = isExternalModelProvider(modelProvider)
3667
3882
  ? EXTERNAL_CODEX_PROVIDERS[modelProvider].env_key
3668
3883
  : null;
3884
+ const selectedProviderKey = standardProviderKey === null
3885
+ ? null
3886
+ : (providerEnvKey ?? standardProviderKey);
3669
3887
  const bedrockProvider = modelProvider === "amazon-bedrock";
3670
3888
  if (auth !== "chatgpt" && selectedProviderKey === null && !bedrockProvider) {
3671
3889
  return environment;
3672
3890
  }
3673
- return Object.fromEntries(Object.entries(withoutOpenAiApiKeys(environment)).filter(([name]) => {
3891
+ const selected = Object.fromEntries(Object.entries(environment).filter(([name]) => {
3674
3892
  const key = name.toUpperCase();
3893
+ if (key === "OPENAI_API_KEY" || key === "CODEX_API_KEY") {
3894
+ return (selectedProviderKey !== null &&
3895
+ key === selectedProviderKey.toUpperCase());
3896
+ }
3675
3897
  if (key === "OPENROUTER_API_KEY" ||
3676
3898
  key === "FIREWORKS_API_KEY" ||
3677
3899
  key === "CHEAPER_INFERENCE_API_KEY") {
3678
3900
  return (!bedrockProvider &&
3679
- (selectedProviderKey === null || key === selectedProviderKey));
3901
+ (selectedProviderKey === null ||
3902
+ key === standardProviderKey ||
3903
+ key === selectedProviderKey.toUpperCase()));
3680
3904
  }
3681
3905
  return true;
3682
3906
  }));
3907
+ forwardExternalImportSetting(environment, selected);
3908
+ return selected;
3683
3909
  }
3684
3910
  function notifyObserver(options, observerName) {
3685
3911
  const observer = options[observerName];
@@ -3691,12 +3917,13 @@ function notifyObserver(options, observerName) {
3691
3917
  .catch(() => { });
3692
3918
  };
3693
3919
  }
3694
- function environmentApiKey(environment, modelProvider) {
3695
- return environmentApiKeyEntry(environment, modelProvider)?.value ?? null;
3920
+ function environmentApiKey(environment, modelProvider, providerEnvKey) {
3921
+ return (environmentApiKeyEntry(environment, modelProvider, providerEnvKey)?.value ??
3922
+ null);
3696
3923
  }
3697
- function environmentApiKeyEntry(environment, modelProvider) {
3924
+ function environmentApiKeyEntry(environment, modelProvider, providerEnvKey) {
3698
3925
  const keys = isExternalModelProvider(modelProvider)
3699
- ? [EXTERNAL_CODEX_PROVIDERS[modelProvider].env_key]
3926
+ ? [providerEnvKey ?? EXTERNAL_CODEX_PROVIDERS[modelProvider].env_key]
3700
3927
  : ["OPENAI_API_KEY", "CODEX_API_KEY"];
3701
3928
  for (const requested of keys) {
3702
3929
  const value = environmentValue(environment, requested)?.trim();
@@ -3773,34 +4000,6 @@ export function classifyConnectionFailure(error) {
3773
4000
  return "timeout";
3774
4001
  return "unknown";
3775
4002
  }
3776
- function deepScanParentConfig(config) {
3777
- const resolved = resolveCodexProfile(config);
3778
- const features = resolved["features"] ?? {};
3779
- if (!isRecord(features))
3780
- return resolved;
3781
- const mode = features["code_mode"];
3782
- const settings = typeof mode === "boolean" ? { enabled: mode } : (mode ?? {});
3783
- // Leave malformed user settings for the native config parser to reject.
3784
- if (!isRecord(settings))
3785
- return resolved;
3786
- const direct = settings["direct_only_tool_namespaces"] ?? [];
3787
- if (!Array.isArray(direct))
3788
- return resolved;
3789
- // The native parent waits for direct tool calls before it can end its turn.
3790
- // A code-mode cell can yield the still-running coordinator to the model.
3791
- return {
3792
- ...resolved,
3793
- features: {
3794
- ...features,
3795
- code_mode: {
3796
- ...settings,
3797
- direct_only_tool_namespaces: [
3798
- ...new Set([...direct, "mcp__codex_security", "codex_security"]),
3799
- ],
3800
- },
3801
- },
3802
- };
3803
- }
3804
4003
  export function scanRuntimeCodexConfig(config, protectedCredentialHome) {
3805
4004
  const approvalPolicy = scanApprovalPolicy(config);
3806
4005
  const hardened = structuredClone(config);
@@ -3816,6 +4015,7 @@ export function scanRuntimeCodexConfig(config, protectedCredentialHome) {
3816
4015
  delete profile["default_permissions"];
3817
4016
  delete profile["permissions"];
3818
4017
  delete profile["sandbox_mode"];
4018
+ delete profile["allow_login_shell"];
3819
4019
  }
3820
4020
  }
3821
4021
  return {
@@ -3932,6 +4132,8 @@ export function scanPreflightCodexConfig(config) {
3932
4132
  "cli_daybreak",
3933
4133
  "api_key_cyber_access_programs",
3934
4134
  "api_key_model_discovery",
4135
+ "shell_tool",
4136
+ "unified_exec",
3935
4137
  ]) {
3936
4138
  if (typeof value[key] === "boolean")
3937
4139
  result[key] = value[key];
@@ -3953,8 +4155,23 @@ export function scanPreflightCodexConfig(config) {
3953
4155
  result["multi_agent_v2"] = sanitized;
3954
4156
  }
3955
4157
  }
4158
+ const codeMode = value["code_mode"];
4159
+ if (typeof codeMode === "boolean" || isRecord(codeMode)) {
4160
+ result["code_mode"] = structuredClone(codeMode);
4161
+ }
3956
4162
  return result;
3957
4163
  };
4164
+ const copyWorkerSettings = (result, source) => {
4165
+ for (const key of [
4166
+ ...MODEL_FILE_SETTINGS,
4167
+ "model_verbosity",
4168
+ "web_search",
4169
+ ]) {
4170
+ const value = source[key];
4171
+ if (typeof value === "string")
4172
+ result[key] = value;
4173
+ }
4174
+ };
3958
4175
  const executionConfig = (source) => {
3959
4176
  const result = {};
3960
4177
  if (typeof source["daybreak"] === "boolean") {
@@ -3971,6 +4188,7 @@ export function scanPreflightCodexConfig(config) {
3971
4188
  if (safeString(value))
3972
4189
  result[key] = value;
3973
4190
  }
4191
+ copyWorkerSettings(result, source);
3974
4192
  const features = capabilityFeatures(source["features"]);
3975
4193
  if (Object.keys(features).length > 0)
3976
4194
  result["features"] = features;
@@ -4006,6 +4224,7 @@ export function scanPreflightCodexConfig(config) {
4006
4224
  const resolved = resolveCodexProfile(config);
4007
4225
  const result = executionConfig(safeProfileName(config["profile"]) ? config : resolved);
4008
4226
  // Keep effective execution settings even when preflight filters the profile name.
4227
+ copyWorkerSettings(result, resolved);
4009
4228
  for (const key of ["model_reasoning_summary", "service_tier"]) {
4010
4229
  const value = resolved[key];
4011
4230
  if (safeString(value))
@@ -4016,9 +4235,12 @@ export function scanPreflightCodexConfig(config) {
4016
4235
  }
4017
4236
  const resolvedFeatures = capabilityFeatures(resolved["features"]);
4018
4237
  for (const key of [
4238
+ "code_mode",
4019
4239
  "cli_daybreak",
4020
4240
  "api_key_cyber_access_programs",
4021
4241
  "api_key_model_discovery",
4242
+ "shell_tool",
4243
+ "unified_exec",
4022
4244
  ]) {
4023
4245
  if (resolvedFeatures[key] !== undefined) {
4024
4246
  result["features"] = {
@@ -4027,20 +4249,23 @@ export function scanPreflightCodexConfig(config) {
4027
4249
  };
4028
4250
  }
4029
4251
  }
4030
- const selectedProfile = safeProfileName(config["profile"])
4031
- ? config["profile"]
4252
+ const profileName = config["profile"];
4253
+ const profiles = config["profiles"];
4254
+ const selectedProfile = safeProfileName(profileName) &&
4255
+ isRecord(profiles) &&
4256
+ isRecord(profiles[profileName])
4257
+ ? profileName
4032
4258
  : undefined;
4033
4259
  if (selectedProfile !== undefined) {
4034
4260
  result["profile"] = selectedProfile;
4035
4261
  }
4036
- const profiles = config["profiles"];
4037
4262
  if (isRecord(profiles)) {
4038
4263
  const sanitized = {};
4039
4264
  for (const [name, profile] of Object.entries(profiles)) {
4040
4265
  if (!safeProfileName(name) || !isRecord(profile))
4041
4266
  continue;
4042
4267
  const projected = executionConfig(profile);
4043
- if (Object.keys(projected).length === 0)
4268
+ if (Object.keys(projected).length === 0 && name !== selectedProfile)
4044
4269
  continue;
4045
4270
  sanitized[name] = projected;
4046
4271
  }
@@ -4111,6 +4336,7 @@ async function requireCurrentDeepScanPlugin(runtime) {
4111
4336
  function selectedWorkerRuntimeConfig(config, selectedProvider, workingDirectory, environment) {
4112
4337
  const provider = typeof selectedProvider === "string" ? selectedProvider : undefined;
4113
4338
  const resolved = resolveCodexProfile(config);
4339
+ resolveNestedConfigPaths(resolved, workingDirectory);
4114
4340
  const providers = resolved["model_providers"];
4115
4341
  const providerEnvironmentNames = isRecord(providers)
4116
4342
  ? Object.values(providers)
@@ -4134,12 +4360,7 @@ function selectedWorkerRuntimeConfig(config, selectedProvider, workingDirectory,
4134
4360
  return value === undefined ? [] : [[name, value]];
4135
4361
  }));
4136
4362
  // Workers use separate directories; preserve the parent scan's native paths.
4137
- for (const key of [
4138
- "model_instructions_file",
4139
- "experimental_compact_prompt_file",
4140
- "model_catalog_json",
4141
- "sqlite_home",
4142
- ]) {
4363
+ for (const key of [...MODEL_FILE_SETTINGS, "sqlite_home"]) {
4143
4364
  const file = resolved[key];
4144
4365
  if (typeof file === "string") {
4145
4366
  resolved[key] = resolve(workingDirectory, expandHome(file, environment));
@@ -4154,23 +4375,53 @@ function selectedWorkerRuntimeConfig(config, selectedProvider, workingDirectory,
4154
4375
  ...(isRecord(providers) ? { model_providers: providers } : {}),
4155
4376
  };
4156
4377
  }
4157
- async function pluginSupportsIsolatedDeepScanConfig(pluginRoot) {
4158
- let configuration;
4378
+ /** Read the declaration selected by the installed Codex plugin manifest. */
4379
+ async function readInstalledDeepScanPluginServers(installedRoot) {
4380
+ const read = async (path) => JSON.parse(await readRegularInputFile(join(installedRoot, path), installedRoot));
4159
4381
  try {
4160
- configuration = JSON.parse(await readFile(join(pluginRoot, ".mcp.json"), "utf8"));
4382
+ const portable = await read("plugin.json").catch(() => undefined);
4383
+ // A portable manifest owns MCP. Its legacy overlay only forwards environment variables.
4384
+ if (isRecord(portable) &&
4385
+ typeof portable["$schema"] === "string" &&
4386
+ portable["$schema"].startsWith("https://agent-plugins.org/schemas/"))
4387
+ return "native";
4388
+ const manifest = await read(".codex-plugin/plugin.json");
4389
+ if (!isRecord(manifest))
4390
+ return;
4391
+ let source = manifest["mcpServers"];
4392
+ if (!isRecord(source)) {
4393
+ const path = typeof source === "string" && source.startsWith("./")
4394
+ ? source.slice(2)
4395
+ : "";
4396
+ // Native Codex ignores invalid selectors and uses the installed default.
4397
+ const valid = path &&
4398
+ !parsePath(path).root &&
4399
+ !path.split(sep === "\\" ? /[/\\]/u : "/").includes("..");
4400
+ source = await read(valid ? path : ".mcp.json");
4401
+ }
4402
+ if (!isRecord(source))
4403
+ return;
4404
+ return isRecord(source["mcpServers"]) ? source["mcpServers"] : source;
4161
4405
  }
4162
4406
  catch {
4163
- return false;
4407
+ return undefined;
4164
4408
  }
4165
- if (!isRecord(configuration))
4166
- return false;
4167
- const servers = configuration["mcpServers"];
4168
- if (!isRecord(servers))
4169
- return false;
4170
- const server = servers["codex-security"];
4171
- if (!isRecord(server))
4172
- return false;
4173
- const environment = server["env_vars"];
4409
+ }
4410
+ async function readDeepScanPluginServers(pluginRoot) {
4411
+ try {
4412
+ const configuration = JSON.parse(await readFile(join(pluginRoot, ".mcp.json"), "utf8"));
4413
+ const servers = isRecord(configuration)
4414
+ ? configuration["mcpServers"]
4415
+ : undefined;
4416
+ return isRecord(servers) ? servers : undefined;
4417
+ }
4418
+ catch {
4419
+ return undefined;
4420
+ }
4421
+ }
4422
+ async function pluginSupportsIsolatedDeepScanConfig(pluginRoot) {
4423
+ const server = (await readDeepScanPluginServers(pluginRoot))?.["codex-security"];
4424
+ const environment = isRecord(server) ? server["env_vars"] : undefined;
4174
4425
  return (Array.isArray(environment) &&
4175
4426
  environment.includes(DEEP_SCAN_CONFIG_PATH_ENVIRONMENT));
4176
4427
  }
@@ -4180,7 +4431,7 @@ function throwIfAborted(signal, scanDir = "") {
4180
4431
  if (signal.reason instanceof ScanCostLimitExceededError)
4181
4432
  throw signal.reason;
4182
4433
  const message = scanDir
4183
- ? `Codex Security scan was interrupted; partial output remains at ${scanDir}.`
4434
+ ? `Codex Security scan was interrupted; output directory: ${scanDir}.`
4184
4435
  : "Codex Security scan was interrupted during preparation.";
4185
4436
  throw new ScanInterruptedError(message, scanDir, { cause: signal.reason });
4186
4437
  }