@openai/codex-security 0.8.3 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (534) hide show
  1. package/README.md +192 -151
  2. package/_bundled_plugin/.mcp.json +5 -1
  3. package/_bundled_plugin/examples/completed-scan/findings.json +16 -4
  4. package/_bundled_plugin/examples/completed-scan/report.md +11 -8
  5. package/_bundled_plugin/examples/completed-scan/scan-manifest.json +4 -2
  6. package/_bundled_plugin/mcp/fzstd-LICENSE.txt +21 -0
  7. package/_bundled_plugin/mcp/helpers.mjs +2 -11
  8. package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
  9. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +3 -210
  10. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  13. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  14. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  15. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  16. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  17. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  18. package/_bundled_plugin/mcp/package.json +1 -0
  19. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +5 -2
  20. package/_bundled_plugin/mcp/server.mjs +2 -11
  21. package/_bundled_plugin/mcp/server.mjs.br +0 -0
  22. package/_bundled_plugin/mcp/session-decompression.mjs +712 -0
  23. package/_bundled_plugin/references/default-severity-rubric.md +9 -4
  24. package/_bundled_plugin/references/final-report.md +5 -3
  25. package/_bundled_plugin/references/finding-detail-fields.md +18 -18
  26. package/_bundled_plugin/references/sarif-adapter.md +8 -2
  27. package/_bundled_plugin/references/scan-artifacts.md +21 -12
  28. package/_bundled_plugin/references/scan-contract.md +27 -33
  29. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +2 -2
  30. package/_bundled_plugin/scripts/check_deep_scan_target.py +97 -0
  31. package/_bundled_plugin/scripts/codex_profile.mjs +7 -1
  32. package/_bundled_plugin/scripts/deep_scan_config.py +20 -1
  33. package/_bundled_plugin/scripts/deep_scan_workbench.py +165 -342
  34. package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
  35. package/_bundled_plugin/scripts/finalize_scan_contract.py +153 -227
  36. package/_bundled_plugin/scripts/finding_preview.py +20 -0
  37. package/_bundled_plugin/scripts/launch_codex_security_mcp +1 -0
  38. package/_bundled_plugin/scripts/legacy_findings.py +148 -0
  39. package/_bundled_plugin/scripts/posix_scan_local_files.py +11 -0
  40. package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
  41. package/_bundled_plugin/scripts/report_projection.py +81 -43
  42. package/_bundled_plugin/scripts/review_state.py +8 -2
  43. package/_bundled_plugin/scripts/servicenow_avit.py +20 -0
  44. package/_bundled_plugin/scripts/snapshot_sqlite.py +1 -0
  45. package/_bundled_plugin/scripts/threat_model_projection.py +22 -26
  46. package/_bundled_plugin/scripts/validate_scan_contract.py +7 -1
  47. package/_bundled_plugin/scripts/windows_scan_local_files.py +388 -17
  48. package/_bundled_plugin/scripts/workbench/__init__.py +1 -1
  49. package/_bundled_plugin/scripts/workbench/handoff.py +47 -0
  50. package/_bundled_plugin/scripts/workbench/retained_coverage.py +30 -51
  51. package/_bundled_plugin/scripts/workbench/retained_records.py +18 -30
  52. package/_bundled_plugin/scripts/workbench/runtime_toml.py +4 -1
  53. package/_bundled_plugin/scripts/workbench/saved_coverage.py +9 -17
  54. package/_bundled_plugin/scripts/workbench/saved_outputs.py +9 -0
  55. package/_bundled_plugin/scripts/workbench/saved_sources.py +47 -40
  56. package/_bundled_plugin/scripts/workbench/storage.py +71 -7
  57. package/_bundled_plugin/scripts/workbench_cli.py +30 -12
  58. package/_bundled_plugin/scripts/workbench_constants.py +10 -0
  59. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
  60. package/_bundled_plugin/scripts/workbench_db.py +369 -137
  61. package/_bundled_plugin/scripts/workbench_feedback.py +8 -7
  62. package/_bundled_plugin/scripts/workbench_finding_index.py +1 -0
  63. package/_bundled_plugin/scripts/workbench_finding_workflows.py +4 -0
  64. package/_bundled_plugin/scripts/workbench_native_indexes.py +12 -12
  65. package/_bundled_plugin/scripts/workbench_progress.py +10 -1
  66. package/_bundled_plugin/scripts/workbench_publication.py +14 -10
  67. package/_bundled_plugin/scripts/workbench_remediation.py +13 -0
  68. package/_bundled_plugin/scripts/workbench_saved_results.py +132 -77
  69. package/_bundled_plugin/scripts/workbench_scan_history.py +117 -55
  70. package/_bundled_plugin/scripts/workbench_scan_start.py +83 -24
  71. package/_bundled_plugin/scripts/workbench_scan_usage.py +644 -68
  72. package/_bundled_plugin/scripts/workbench_schema.py +44 -55
  73. package/_bundled_plugin/scripts/workbench_setup.py +13 -1
  74. package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
  75. package/_bundled_plugin/scripts/workbench_source_scopes.py +18 -0
  76. package/_bundled_plugin/scripts/workbench_target.py +127 -56
  77. package/_bundled_plugin/scripts/workbench_target_state.py +3 -0
  78. package/_bundled_plugin/scripts/workbench_validation.py +43 -3
  79. package/_bundled_plugin/shared/workbench-history-repairs.json +19 -23
  80. package/_bundled_plugin/shared/workbench-migrations.json +34 -0
  81. package/_bundled_plugin/skills/cloud-findings/SKILL.md +5 -5
  82. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
  83. package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -1
  84. package/_bundled_plugin/skills/publish-findings/SKILL.md +32 -25
  85. package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
  86. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +3 -3
  87. package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +464 -0
  88. package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +22 -1
  89. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -2
  90. package/dist/api.d.ts +39 -4
  91. package/dist/api.d.ts.map +1 -1
  92. package/dist/api.js +774 -292
  93. package/dist/api.js.map +1 -1
  94. package/dist/auth.d.ts.map +1 -1
  95. package/dist/auth.js +4 -6
  96. package/dist/auth.js.map +1 -1
  97. package/dist/bedrock-oss-pricing.d.ts +6 -0
  98. package/dist/bedrock-oss-pricing.d.ts.map +1 -0
  99. package/dist/bedrock-oss-pricing.js +58 -0
  100. package/dist/bedrock-oss-pricing.js.map +1 -0
  101. package/dist/bedrock-pricing.d.ts +15 -0
  102. package/dist/bedrock-pricing.d.ts.map +1 -0
  103. package/dist/bedrock-pricing.js +117 -0
  104. package/dist/bedrock-pricing.js.map +1 -0
  105. package/dist/blackduck-findings.d.ts.map +1 -1
  106. package/dist/blackduck-findings.js +35 -20
  107. package/dist/blackduck-findings.js.map +1 -1
  108. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  109. package/dist/bulk-scan-discovery.js +4 -4
  110. package/dist/bulk-scan-discovery.js.map +1 -1
  111. package/dist/checkmarx-evidence.d.ts +19 -0
  112. package/dist/checkmarx-evidence.d.ts.map +1 -0
  113. package/dist/checkmarx-evidence.js +36 -0
  114. package/dist/checkmarx-evidence.js.map +1 -0
  115. package/dist/checkmarx-findings.d.ts +4 -0
  116. package/dist/checkmarx-findings.d.ts.map +1 -0
  117. package/dist/checkmarx-findings.js +27 -0
  118. package/dist/checkmarx-findings.js.map +1 -0
  119. package/dist/checkmarx-one.d.ts +4 -0
  120. package/dist/checkmarx-one.d.ts.map +1 -0
  121. package/dist/checkmarx-one.js +53 -0
  122. package/dist/checkmarx-one.js.map +1 -0
  123. package/dist/checkmarx-repository.d.ts +12 -0
  124. package/dist/checkmarx-repository.d.ts.map +1 -0
  125. package/dist/checkmarx-repository.js +181 -0
  126. package/dist/checkmarx-repository.js.map +1 -0
  127. package/dist/checkmarx-xml.d.ts +12 -0
  128. package/dist/checkmarx-xml.d.ts.map +1 -0
  129. package/dist/checkmarx-xml.js +196 -0
  130. package/dist/checkmarx-xml.js.map +1 -0
  131. package/dist/classify-severity-records.d.ts +1 -9
  132. package/dist/classify-severity-records.d.ts.map +1 -1
  133. package/dist/classify-severity-records.js +3 -13
  134. package/dist/classify-severity-records.js.map +1 -1
  135. package/dist/classify-severity.d.ts.map +1 -1
  136. package/dist/classify-severity.js +2 -4
  137. package/dist/classify-severity.js.map +1 -1
  138. package/dist/cli.d.ts +11 -5
  139. package/dist/cli.d.ts.map +1 -1
  140. package/dist/cli.js +1734 -1238
  141. package/dist/cli.js.map +1 -1
  142. package/dist/cloud-publish.js +2 -2
  143. package/dist/cloud-publish.js.map +1 -1
  144. package/dist/component-scan.d.ts +16 -3
  145. package/dist/component-scan.d.ts.map +1 -1
  146. package/dist/component-scan.js +27 -2
  147. package/dist/component-scan.js.map +1 -1
  148. package/dist/config.d.ts.map +1 -1
  149. package/dist/config.js +100 -66
  150. package/dist/config.js.map +1 -1
  151. package/dist/continuum-findings.d.ts.map +1 -1
  152. package/dist/continuum-findings.js +80 -12
  153. package/dist/continuum-findings.js.map +1 -1
  154. package/dist/contract-values.d.ts +2 -0
  155. package/dist/contract-values.d.ts.map +1 -1
  156. package/dist/contract-values.js +12 -9
  157. package/dist/contract-values.js.map +1 -1
  158. package/dist/cost-model.d.ts +13 -1
  159. package/dist/cost-model.d.ts.map +1 -1
  160. package/dist/cost-model.js +66 -112
  161. package/dist/cost-model.js.map +1 -1
  162. package/dist/cost.d.ts +42 -3
  163. package/dist/cost.d.ts.map +1 -1
  164. package/dist/cost.js +483 -104
  165. package/dist/cost.js.map +1 -1
  166. package/dist/custom-publish.d.ts +4 -0
  167. package/dist/custom-publish.d.ts.map +1 -1
  168. package/dist/custom-publish.js +40 -3
  169. package/dist/custom-publish.js.map +1 -1
  170. package/dist/deduplication/local.d.ts +2 -2
  171. package/dist/deduplication/local.d.ts.map +1 -1
  172. package/dist/deduplication/local.js +2 -2
  173. package/dist/deduplication/local.js.map +1 -1
  174. package/dist/deduplication/refusal.d.ts.map +1 -1
  175. package/dist/deduplication/refusal.js +25 -5
  176. package/dist/deduplication/refusal.js.map +1 -1
  177. package/dist/deduplication/scan.d.ts +3 -0
  178. package/dist/deduplication/scan.d.ts.map +1 -1
  179. package/dist/deduplication/scan.js +1 -1
  180. package/dist/deduplication/scan.js.map +1 -1
  181. package/dist/deep-config.d.ts +0 -1
  182. package/dist/deep-config.d.ts.map +1 -1
  183. package/dist/deep-config.js +22 -33
  184. package/dist/deep-config.js.map +1 -1
  185. package/dist/deep-scan-defaults.d.ts +2 -0
  186. package/dist/deep-scan-defaults.d.ts.map +1 -1
  187. package/dist/deep-scan-defaults.js +28 -1
  188. package/dist/deep-scan-defaults.js.map +1 -1
  189. package/dist/deep-scan.d.ts +2 -0
  190. package/dist/deep-scan.d.ts.map +1 -1
  191. package/dist/deep-scan.js +28 -4
  192. package/dist/deep-scan.js.map +1 -1
  193. package/dist/default-severity-rubric.d.ts +1 -1
  194. package/dist/default-severity-rubric.d.ts.map +1 -1
  195. package/dist/default-severity-rubric.js +1 -1
  196. package/dist/default-severity-rubric.js.map +1 -1
  197. package/dist/endor-findings.d.ts +3 -1
  198. package/dist/endor-findings.d.ts.map +1 -1
  199. package/dist/endor-findings.js +103 -45
  200. package/dist/endor-findings.js.map +1 -1
  201. package/dist/errors.d.ts +1 -1
  202. package/dist/errors.d.ts.map +1 -1
  203. package/dist/errors.js +8 -1
  204. package/dist/errors.js.map +1 -1
  205. package/dist/external-findings-import.d.ts +5 -3
  206. package/dist/external-findings-import.d.ts.map +1 -1
  207. package/dist/external-findings-import.js +7 -6
  208. package/dist/external-findings-import.js.map +1 -1
  209. package/dist/external-findings-local.d.ts +7 -5
  210. package/dist/external-findings-local.d.ts.map +1 -1
  211. package/dist/external-findings-local.js +337 -89
  212. package/dist/external-findings-local.js.map +1 -1
  213. package/dist/external-findings-publish.d.ts +8 -6
  214. package/dist/external-findings-publish.d.ts.map +1 -1
  215. package/dist/external-findings-publish.js +1318 -258
  216. package/dist/external-findings-publish.js.map +1 -1
  217. package/dist/external-findings-read.d.ts +20 -2
  218. package/dist/external-findings-read.d.ts.map +1 -1
  219. package/dist/external-findings-read.js +148 -66
  220. package/dist/external-findings-read.js.map +1 -1
  221. package/dist/external-findings.d.ts +15 -3
  222. package/dist/external-findings.d.ts.map +1 -1
  223. package/dist/external-findings.js +42 -1
  224. package/dist/external-findings.js.map +1 -1
  225. package/dist/external-import-contract.d.ts +5 -1
  226. package/dist/external-import-contract.d.ts.map +1 -1
  227. package/dist/external-import-contract.js +23 -9
  228. package/dist/external-import-contract.js.map +1 -1
  229. package/dist/external-import-models.d.ts +1 -1
  230. package/dist/external-import-models.d.ts.map +1 -1
  231. package/dist/external-import-models.js.map +1 -1
  232. package/dist/feedback.d.ts.map +1 -1
  233. package/dist/feedback.js +5 -4
  234. package/dist/feedback.js.map +1 -1
  235. package/dist/finding-prompt.d.ts +5 -0
  236. package/dist/finding-prompt.d.ts.map +1 -0
  237. package/dist/finding-prompt.js +32 -0
  238. package/dist/finding-prompt.js.map +1 -0
  239. package/dist/findings-client.d.ts +1 -0
  240. package/dist/findings-client.d.ts.map +1 -1
  241. package/dist/findings-client.js +27 -3
  242. package/dist/findings-client.js.map +1 -1
  243. package/dist/github-advisories.d.ts.map +1 -1
  244. package/dist/github-advisories.js +0 -2
  245. package/dist/github-advisories.js.map +1 -1
  246. package/dist/github-dependabot-findings.d.ts.map +1 -1
  247. package/dist/github-dependabot-findings.js +15 -4
  248. package/dist/github-dependabot-findings.js.map +1 -1
  249. package/dist/github-findings.d.ts +4 -1
  250. package/dist/github-findings.d.ts.map +1 -1
  251. package/dist/github-findings.js +55 -30
  252. package/dist/github-findings.js.map +1 -1
  253. package/dist/hosted-git-remotes.d.ts +5 -0
  254. package/dist/hosted-git-remotes.d.ts.map +1 -0
  255. package/dist/hosted-git-remotes.js +285 -0
  256. package/dist/hosted-git-remotes.js.map +1 -0
  257. package/dist/hosted-git-repository.d.ts +28 -0
  258. package/dist/hosted-git-repository.d.ts.map +1 -0
  259. package/dist/hosted-git-repository.js +222 -0
  260. package/dist/hosted-git-repository.js.map +1 -0
  261. package/dist/hosted-scan-protocol.js +2 -2
  262. package/dist/hosted-scan-protocol.js.map +1 -1
  263. package/dist/hosted-scan.d.ts.map +1 -1
  264. package/dist/hosted-scan.js +16 -11
  265. package/dist/hosted-scan.js.map +1 -1
  266. package/dist/hosted-scanner-http.d.ts +21 -0
  267. package/dist/hosted-scanner-http.d.ts.map +1 -0
  268. package/dist/hosted-scanner-http.js +204 -0
  269. package/dist/hosted-scanner-http.js.map +1 -0
  270. package/dist/hosted-scanner-v1.d.ts +6 -0
  271. package/dist/hosted-scanner-v1.d.ts.map +1 -0
  272. package/dist/hosted-scanner-v1.js +60 -0
  273. package/dist/hosted-scanner-v1.js.map +1 -0
  274. package/dist/import-scan.d.ts.map +1 -1
  275. package/dist/import-scan.js +3 -0
  276. package/dist/import-scan.js.map +1 -1
  277. package/dist/index.d.ts +18 -7
  278. package/dist/index.d.ts.map +1 -1
  279. package/dist/index.js +10 -2
  280. package/dist/index.js.map +1 -1
  281. package/dist/inspector-findings.d.ts.map +1 -1
  282. package/dist/inspector-findings.js +47 -65
  283. package/dist/inspector-findings.js.map +1 -1
  284. package/dist/knowledge-base.d.ts.map +1 -1
  285. package/dist/knowledge-base.js +68 -5
  286. package/dist/knowledge-base.js.map +1 -1
  287. package/dist/local-git-metadata.d.ts +1 -1
  288. package/dist/local-git-metadata.d.ts.map +1 -1
  289. package/dist/local-git-metadata.js +1 -2
  290. package/dist/local-git-metadata.js.map +1 -1
  291. package/dist/multiscan.d.ts +6 -4
  292. package/dist/multiscan.d.ts.map +1 -1
  293. package/dist/multiscan.js +138 -65
  294. package/dist/multiscan.js.map +1 -1
  295. package/dist/native-json-findings.d.ts +2 -1
  296. package/dist/native-json-findings.d.ts.map +1 -1
  297. package/dist/native-json-findings.js +12 -2
  298. package/dist/native-json-findings.js.map +1 -1
  299. package/dist/opengrep-findings.d.ts +1 -0
  300. package/dist/opengrep-findings.d.ts.map +1 -1
  301. package/dist/opengrep-findings.js +17 -13
  302. package/dist/opengrep-findings.js.map +1 -1
  303. package/dist/operation-telemetry.d.ts +104 -0
  304. package/dist/operation-telemetry.d.ts.map +1 -0
  305. package/dist/operation-telemetry.js +293 -0
  306. package/dist/operation-telemetry.js.map +1 -0
  307. package/dist/plugin-python-probe.d.ts +4 -0
  308. package/dist/plugin-python-probe.d.ts.map +1 -0
  309. package/dist/plugin-python-probe.js +10 -0
  310. package/dist/plugin-python-probe.js.map +1 -0
  311. package/dist/private-finding-import.d.ts +97 -2
  312. package/dist/private-finding-import.d.ts.map +1 -1
  313. package/dist/private-finding-import.js +58 -34
  314. package/dist/private-finding-import.js.map +1 -1
  315. package/dist/provider-profile.d.ts +1 -1
  316. package/dist/provider-profile.d.ts.map +1 -1
  317. package/dist/provider-profile.js +8 -1
  318. package/dist/provider-profile.js.map +1 -1
  319. package/dist/publication-telemetry.d.ts +45 -0
  320. package/dist/publication-telemetry.d.ts.map +1 -0
  321. package/dist/publication-telemetry.js +50 -0
  322. package/dist/publication-telemetry.js.map +1 -0
  323. package/dist/publish.d.ts +4 -0
  324. package/dist/publish.d.ts.map +1 -1
  325. package/dist/publish.js +42 -2
  326. package/dist/publish.js.map +1 -1
  327. package/dist/reader-selection.d.ts +2 -0
  328. package/dist/reader-selection.d.ts.map +1 -1
  329. package/dist/reader-selection.js +8 -0
  330. package/dist/reader-selection.js.map +1 -1
  331. package/dist/remediation.d.ts +1 -4
  332. package/dist/remediation.d.ts.map +1 -1
  333. package/dist/remediation.js +3 -7
  334. package/dist/remediation.js.map +1 -1
  335. package/dist/request-metadata.d.ts +3 -0
  336. package/dist/request-metadata.d.ts.map +1 -1
  337. package/dist/request-metadata.js +9 -0
  338. package/dist/request-metadata.js.map +1 -1
  339. package/dist/result.d.ts +4 -0
  340. package/dist/result.d.ts.map +1 -1
  341. package/dist/result.js +1 -1
  342. package/dist/result.js.map +1 -1
  343. package/dist/retry-windows-rename.d.ts +8 -0
  344. package/dist/retry-windows-rename.d.ts.map +1 -0
  345. package/dist/retry-windows-rename.js +24 -0
  346. package/dist/retry-windows-rename.js.map +1 -0
  347. package/dist/runtime.d.ts +20 -0
  348. package/dist/runtime.d.ts.map +1 -1
  349. package/dist/runtime.js +313 -110
  350. package/dist/runtime.js.map +1 -1
  351. package/dist/saved-scan-bootstrap.d.ts +1 -0
  352. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  353. package/dist/saved-scan-bootstrap.js +18 -15
  354. package/dist/saved-scan-bootstrap.js.map +1 -1
  355. package/dist/scan-activity.d.ts.map +1 -1
  356. package/dist/scan-activity.js +141 -56
  357. package/dist/scan-activity.js.map +1 -1
  358. package/dist/scan-comparison.d.ts +10 -5
  359. package/dist/scan-comparison.d.ts.map +1 -1
  360. package/dist/scan-comparison.js +60 -15
  361. package/dist/scan-comparison.js.map +1 -1
  362. package/dist/scan-dashboard.d.ts +6 -6
  363. package/dist/scan-dashboard.d.ts.map +1 -1
  364. package/dist/scan-dashboard.js +75 -42
  365. package/dist/scan-dashboard.js.map +1 -1
  366. package/dist/scan-executor.d.ts +10 -1
  367. package/dist/scan-executor.d.ts.map +1 -1
  368. package/dist/scan-executor.js +22 -2
  369. package/dist/scan-executor.js.map +1 -1
  370. package/dist/scan-history-renderer.d.ts.map +1 -1
  371. package/dist/scan-history-renderer.js +9 -19
  372. package/dist/scan-history-renderer.js.map +1 -1
  373. package/dist/scan-logs.d.ts +12 -0
  374. package/dist/scan-logs.d.ts.map +1 -1
  375. package/dist/scan-logs.js +106 -77
  376. package/dist/scan-logs.js.map +1 -1
  377. package/dist/scan-measurement.d.ts +26 -0
  378. package/dist/scan-measurement.d.ts.map +1 -0
  379. package/dist/scan-measurement.js +77 -0
  380. package/dist/scan-measurement.js.map +1 -0
  381. package/dist/scan-progress.d.ts +1 -0
  382. package/dist/scan-progress.d.ts.map +1 -1
  383. package/dist/scan-progress.js +3 -0
  384. package/dist/scan-progress.js.map +1 -1
  385. package/dist/scan-sessions.d.ts.map +1 -1
  386. package/dist/scan-sessions.js +4 -1
  387. package/dist/scan-sessions.js.map +1 -1
  388. package/dist/scan-settings.d.ts +1 -1
  389. package/dist/scan-settings.d.ts.map +1 -1
  390. package/dist/scan-settings.js +1 -24
  391. package/dist/scan-settings.js.map +1 -1
  392. package/dist/scanner-import.d.ts +20 -2
  393. package/dist/scanner-import.d.ts.map +1 -1
  394. package/dist/scanner-import.js +200 -8
  395. package/dist/scanner-import.js.map +1 -1
  396. package/dist/scanner-repository-url.d.ts +4 -1
  397. package/dist/scanner-repository-url.d.ts.map +1 -1
  398. package/dist/scanner-repository-url.js +10 -6
  399. package/dist/scanner-repository-url.js.map +1 -1
  400. package/dist/security-policy.d.ts +1 -1
  401. package/dist/security-policy.d.ts.map +1 -1
  402. package/dist/security-policy.js.map +1 -1
  403. package/dist/semgrep-findings.d.ts +6 -3
  404. package/dist/semgrep-findings.d.ts.map +1 -1
  405. package/dist/semgrep-findings.js +107 -43
  406. package/dist/semgrep-findings.js.map +1 -1
  407. package/dist/semgrep-guardian-findings.d.ts +38 -0
  408. package/dist/semgrep-guardian-findings.d.ts.map +1 -0
  409. package/dist/semgrep-guardian-findings.js +165 -0
  410. package/dist/semgrep-guardian-findings.js.map +1 -0
  411. package/dist/semgrep-platform-collector.d.ts +26 -0
  412. package/dist/semgrep-platform-collector.d.ts.map +1 -0
  413. package/dist/semgrep-platform-collector.js +108 -0
  414. package/dist/semgrep-platform-collector.js.map +1 -0
  415. package/dist/semgrep-platform-findings.d.ts +207 -6
  416. package/dist/semgrep-platform-findings.d.ts.map +1 -1
  417. package/dist/semgrep-platform-findings.js +983 -103
  418. package/dist/semgrep-platform-findings.js.map +1 -1
  419. package/dist/semgrep-platform-v1.d.ts +6 -0
  420. package/dist/semgrep-platform-v1.d.ts.map +1 -0
  421. package/dist/semgrep-platform-v1.js +83 -0
  422. package/dist/semgrep-platform-v1.js.map +1 -0
  423. package/dist/server/api.d.ts +1 -1
  424. package/dist/server/api.d.ts.map +1 -1
  425. package/dist/server/api.js.map +1 -1
  426. package/dist/server/embedding-tokenizer.cdx.json +33 -0
  427. package/dist/server/embedding-tokenizer.d.ts +2 -0
  428. package/dist/server/embedding-tokenizer.d.ts.map +1 -0
  429. package/dist/server/embedding-tokenizer.js +322 -0
  430. package/dist/server/embedding-tokenizer.js.map +6 -0
  431. package/dist/server/embeddings.d.ts +16 -2
  432. package/dist/server/embeddings.d.ts.map +1 -1
  433. package/dist/server/embeddings.js +35 -5
  434. package/dist/server/embeddings.js.map +1 -1
  435. package/dist/session-lines.d.ts +5 -0
  436. package/dist/session-lines.d.ts.map +1 -0
  437. package/dist/session-lines.js +60 -0
  438. package/dist/session-lines.js.map +1 -0
  439. package/dist/severity-review.d.ts +3 -1
  440. package/dist/severity-review.d.ts.map +1 -1
  441. package/dist/severity-review.js +3 -2
  442. package/dist/severity-review.js.map +1 -1
  443. package/dist/skill-authentication.d.ts +1 -0
  444. package/dist/skill-authentication.d.ts.map +1 -1
  445. package/dist/skill-authentication.js +1 -0
  446. package/dist/skill-authentication.js.map +1 -1
  447. package/dist/snyk-findings.d.ts +7 -2
  448. package/dist/snyk-findings.d.ts.map +1 -1
  449. package/dist/snyk-findings.js +93 -70
  450. package/dist/snyk-findings.js.map +1 -1
  451. package/dist/snyk-rest-findings.d.ts +76 -0
  452. package/dist/snyk-rest-findings.d.ts.map +1 -0
  453. package/dist/snyk-rest-findings.js +1051 -0
  454. package/dist/snyk-rest-findings.js.map +1 -0
  455. package/dist/snyk-rest-v1.d.ts +28 -0
  456. package/dist/snyk-rest-v1.d.ts.map +1 -0
  457. package/dist/snyk-rest-v1.js +132 -0
  458. package/dist/snyk-rest-v1.js.map +1 -0
  459. package/dist/snyk-token-origin.d.ts +4 -0
  460. package/dist/snyk-token-origin.d.ts.map +1 -0
  461. package/dist/snyk-token-origin.js +82 -0
  462. package/dist/snyk-token-origin.js.map +1 -0
  463. package/dist/sonar-collector.d.ts.map +1 -1
  464. package/dist/sonar-collector.js +0 -3
  465. package/dist/sonar-collector.js.map +1 -1
  466. package/dist/sonar-import.d.ts.map +1 -1
  467. package/dist/sonar-import.js +2 -4
  468. package/dist/sonar-import.js.map +1 -1
  469. package/dist/target-drift.d.ts +9 -0
  470. package/dist/target-drift.d.ts.map +1 -0
  471. package/dist/target-drift.js +27 -0
  472. package/dist/target-drift.js.map +1 -0
  473. package/dist/targets.d.ts +2 -0
  474. package/dist/targets.d.ts.map +1 -1
  475. package/dist/targets.js +56 -20
  476. package/dist/targets.js.map +1 -1
  477. package/dist/tenable-findings.d.ts +9 -0
  478. package/dist/tenable-findings.d.ts.map +1 -0
  479. package/dist/tenable-findings.js +122 -0
  480. package/dist/tenable-findings.js.map +1 -0
  481. package/dist/terminal-stream.d.ts +13 -0
  482. package/dist/terminal-stream.d.ts.map +1 -0
  483. package/dist/terminal-stream.js +35 -0
  484. package/dist/terminal-stream.js.map +1 -0
  485. package/dist/trivy-findings.d.ts +19 -0
  486. package/dist/trivy-findings.d.ts.map +1 -0
  487. package/dist/trivy-findings.js +435 -0
  488. package/dist/trivy-findings.js.map +1 -0
  489. package/dist/trivy-import.d.ts +19 -0
  490. package/dist/trivy-import.d.ts.map +1 -0
  491. package/dist/trivy-import.js +151 -0
  492. package/dist/trivy-import.js.map +1 -0
  493. package/dist/validation-records.js +1 -1
  494. package/dist/validation-records.js.map +1 -1
  495. package/dist/veracode-findings.d.ts +2 -0
  496. package/dist/veracode-findings.d.ts.map +1 -1
  497. package/dist/veracode-findings.js +49 -11
  498. package/dist/veracode-findings.js.map +1 -1
  499. package/dist/vertex-pricing.d.ts +8 -0
  500. package/dist/vertex-pricing.d.ts.map +1 -0
  501. package/dist/vertex-pricing.js +20 -0
  502. package/dist/vertex-pricing.js.map +1 -0
  503. package/dist/windows-path.d.ts +1 -0
  504. package/dist/windows-path.d.ts.map +1 -1
  505. package/dist/windows-path.js +26 -1
  506. package/dist/windows-path.js.map +1 -1
  507. package/dist/wiz-findings.d.ts +4 -0
  508. package/dist/wiz-findings.d.ts.map +1 -1
  509. package/dist/wiz-findings.js +57 -3
  510. package/dist/wiz-findings.js.map +1 -1
  511. package/docs/classify-severity-records.md +27 -12
  512. package/docs/cli.md +497 -550
  513. package/docs/dedupe-records.md +44 -24
  514. package/docs/findings-service.md +66 -39
  515. package/docs/hosted-remediation.md +14 -7
  516. package/docs/hosted-scans.md +50 -42
  517. package/docs/telemetry.md +236 -0
  518. package/docs/validate-records.md +78 -44
  519. package/package.json +18 -15
  520. package/schemas/external-findings.schema.json +3 -1
  521. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  522. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  523. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  524. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  525. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  526. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +0 -96
  527. package/dist/external-imports-feature.d.ts +0 -6
  528. package/dist/external-imports-feature.d.ts.map +0 -1
  529. package/dist/external-imports-feature.js +0 -51
  530. package/dist/external-imports-feature.js.map +0 -1
  531. package/dist/finding-normalization.d.ts +0 -5
  532. package/dist/finding-normalization.d.ts.map +0 -1
  533. package/dist/finding-normalization.js +0 -155
  534. package/dist/finding-normalization.js.map +0 -1
@@ -4,9 +4,9 @@ import { basename, dirname, join } from "node:path";
4
4
  import { parse as parseToml } from "smol-toml";
5
5
  import { writeCodexConfig } from "./config.js";
6
6
  import { canonicalConfigPath } from "./runtime.js";
7
- import { DEFAULT_DEEP_SCAN_SETTINGS } from "./deep-scan-defaults.js";
7
+ import { DEEP_SCAN_SETTINGS, DEFAULT_DEEP_SCAN_SETTINGS, hoursConflict, } from "./deep-scan-defaults.js";
8
8
  import { CodexSecurityError } from "./errors.js";
9
- import { DEFAULT_SCAN_MODE, DEEP_SCAN_SETTINGS, DeepScanSettingsSchema, ScanSettingsSchema, } from "./scan-settings.js";
9
+ import { DEFAULT_SCAN_MODE, DeepScanSettingsSchema, ScanSettingsSchema, } from "./scan-settings.js";
10
10
  export function deepScanOptions(options) {
11
11
  const selected = {};
12
12
  const minutes = ScanSettingsSchema.shape.maxTimeMinutes.safeParse(options.maxTimeMinutes);
@@ -27,9 +27,7 @@ export function deepScanOptions(options) {
27
27
  throw new CodexSecurityError("Deep scan maxTimeMinutes / --max-time must be no greater than 5760 minutes.");
28
28
  }
29
29
  const hours = minutes.data / 60;
30
- if (selected.maxTimeHours !== undefined &&
31
- Math.abs(selected.maxTimeHours - hours) >
32
- Number.EPSILON * Math.max(selected.maxTimeHours, hours)) {
30
+ if (hoursConflict(hours, selected.maxTimeHours)) {
33
31
  throw new CodexSecurityError("Conflicting maxTimeMinutes / --max-time and maxTimeHours / --max-time-hours settings.");
34
32
  }
35
33
  selected.maxTimeHours = hours;
@@ -66,32 +64,27 @@ export async function resolveDeepScanConfig(options, source, signal) {
66
64
  if (unknown.length > 0) {
67
65
  throw new CodexSecurityError(`Unknown Codex Security Deep Scan configuration ${unknown.join(", ")} in ${source}.`);
68
66
  }
69
- const settings = {
70
- ...DEFAULT_DEEP_SCAN_SETTINGS,
71
- };
67
+ const settings = { ...DEFAULT_DEEP_SCAN_SETTINGS };
72
68
  const sources = {};
73
69
  for (const [name, key] of DEEP_SCAN_SETTINGS) {
74
- let value = Object.hasOwn(configured, key)
75
- ? configured[key]
76
- : DEFAULT_DEEP_SCAN_SETTINGS[name];
77
- if (name === "workers" && value === "auto")
78
- value = DEFAULT_DEEP_SCAN_SETTINGS.workers;
79
- if (explicit[name] !== undefined)
80
- value = explicit[name];
70
+ const legacy = Object.hasOwn(configured, key) ? configured[key] : undefined;
71
+ const override = explicit[name];
81
72
  sources[name] =
82
- explicit[name] !== undefined
73
+ override !== undefined
83
74
  ? "override"
84
- : Object.hasOwn(configured, key)
75
+ : legacy !== undefined
85
76
  ? "legacy"
86
77
  : "default";
87
- settings[name] = requireDeepScanValue(name, value, sources[name] === "legacy" ? `${key} in ${source}` : name);
78
+ const value = override ?? legacy ?? settings[name];
79
+ settings[name] = requireDeepScanValue(name, name === "workers" && value === "auto"
80
+ ? DEFAULT_DEEP_SCAN_SETTINGS.workers
81
+ : value, sources[name] === "legacy" ? `${key} in ${source}` : name);
88
82
  }
89
83
  return {
90
84
  settings,
91
85
  sources,
92
86
  source,
93
87
  document,
94
- overrides: explicit,
95
88
  };
96
89
  }
97
90
  export async function writeDeepScanConfig(destination, resolved, workerRuntime) {
@@ -99,26 +92,22 @@ export async function writeDeepScanConfig(destination, resolved, workerRuntime)
99
92
  canonicalConfigPath(resolved.source),
100
93
  runtimeConfigPath(destination),
101
94
  ]);
102
- let document = resolved.document;
103
- const sameFile = source === target;
104
- if (sameFile) {
105
- if (Object.keys(resolved.overrides).length === 0)
106
- return;
107
- document = await readDeepScanDocument(destination);
108
- }
109
- // An isolated runtime needs a complete snapshot. An ambient file keeps
110
- // inherited defaults unset so future releases can still update them.
111
- const settings = sameFile ? resolved.overrides : resolved.settings;
112
- const retainAmbientSettings = sameFile &&
113
- DEEP_SCAN_SETTINGS.some(([name]) => settings[name] === undefined);
95
+ const ambient = source === target;
96
+ const fields = DEEP_SCAN_SETTINGS.filter(([name]) => !ambient || resolved.sources[name] === "override");
97
+ if (fields.length === 0)
98
+ return;
99
+ const document = ambient
100
+ ? await readDeepScanDocument(destination)
101
+ : resolved.document;
102
+ // A complete snapshot replaces the Deep table. Partial ambient writes preserve other keys.
114
103
  await writeCodexConfig(destination, {
115
104
  ...document,
116
105
  ...(workerRuntime === undefined ? {} : { worker_runtime: workerRuntime }),
117
106
  deep_scan: {
118
- ...(retainAmbientSettings
107
+ ...(fields.length < DEEP_SCAN_SETTINGS.length
119
108
  ? document["deep_scan"]
120
109
  : {}),
121
- ...Object.fromEntries(DEEP_SCAN_SETTINGS.filter(([name]) => settings[name] !== undefined).map(([name, key]) => [key, settings[name]])),
110
+ ...Object.fromEntries(fields.map(([name, key]) => [key, resolved.settings[name]])),
122
111
  },
123
112
  });
124
113
  }
@@ -1 +1 @@
1
- {"version":3,"file":"deep-config.js","sourceRoot":"","sources":["../src/deep-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,KAAK,IAAI,SAAS,EAAkB,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAmB,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,GAEnB,MAAM,oBAAoB,CAAC;AAe5B,MAAM,UAAU,eAAe,CAC7B,OAAuE;IAEvE,MAAM,QAAQ,GAAoB,EAAE,CAAC;IACrC,MAAM,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAC/D,OAAO,CAAC,cAAc,CACvB,CAAC;IACF,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACrB,MAAM,IAAI,kBAAkB,CAC1B,0EAA0E,CAC3E,CAAC;IACJ,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,kBAAkB,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI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A+C,MAAM,GAAG,EACxD,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["import { isRecord } from \"./record.js\";\nimport { lstat, readFile } from \"node:fs/promises\";\nimport { basename, dirname, join } from \"node:path\";\nimport { parse as parseToml, type TomlTable } from \"smol-toml\";\nimport { writeCodexConfig, type JsonObject } from \"./config.js\";\nimport { canonicalConfigPath } from \"./runtime.js\";\nimport { DEFAULT_DEEP_SCAN_SETTINGS } from \"./deep-scan-defaults.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport {\n DEFAULT_SCAN_MODE,\n DEEP_SCAN_SETTINGS,\n DeepScanSettingsSchema,\n ScanSettingsSchema,\n type DeepScanOptions,\n} from \"./scan-settings.js\";\nimport type { ScanMode } from \"./scan-modes.js\";\n\nexport type DeepScanSources = Record<\n keyof DeepScanOptions,\n \"default\" | \"legacy\" | \"override\"\n>;\nexport interface ResolvedDeepScanConfig {\n settings: Required<DeepScanOptions>;\n sources: DeepScanSources;\n source: string;\n document: TomlTable;\n overrides: DeepScanOptions;\n}\n\nexport function deepScanOptions(\n options: DeepScanOptions & { mode?: ScanMode; maxTimeMinutes?: number },\n): DeepScanOptions {\n const selected: DeepScanOptions = {};\n const minutes = ScanSettingsSchema.shape.maxTimeMinutes.safeParse(\n options.maxTimeMinutes,\n );\n if (!minutes.success) {\n throw new CodexSecurityError(\n \"maxTimeMinutes / --max-time must be a finite positive number of minutes.\",\n );\n }\n for (const [name] of DEEP_SCAN_SETTINGS) {\n const value = options[name];\n if (value === undefined) continue;\n if ((options.mode ?? DEFAULT_SCAN_MODE) !== \"deep\") {\n throw new CodexSecurityError(\"Deep scan settings require deep mode.\");\n }\n selected[name] = requireDeepScanValue(name, value, name);\n }\n if (minutes.data !== undefined && options.mode === \"deep\") {\n if (minutes.data > 5760) {\n throw new CodexSecurityError(\n \"Deep scan maxTimeMinutes / --max-time must be no greater than 5760 minutes.\",\n );\n }\n const hours = minutes.data / 60;\n if (\n selected.maxTimeHours !== undefined &&\n Math.abs(selected.maxTimeHours - hours) >\n Number.EPSILON * Math.max(selected.maxTimeHours, hours)\n ) {\n throw new CodexSecurityError(\n \"Conflicting maxTimeMinutes / --max-time and maxTimeHours / --max-time-hours settings.\",\n );\n }\n selected.maxTimeHours = hours;\n }\n if (\n minutes.data !== undefined &&\n !Number.isFinite(new Date(Date.now() + minutes.data * 60_000).getTime())\n ) {\n throw new CodexSecurityError(\n \"maxTimeMinutes / --max-time must produce a deadline within the supported date range.\",\n );\n }\n return selected;\n}\n\nfunction requireDeepScanValue(\n name: keyof DeepScanOptions,\n value: unknown,\n label: string,\n): number {\n const parsed = DeepScanSettingsSchema.shape[name].unwrap().safeParse(value);\n if (!parsed.success) {\n throw new CodexSecurityError(\n `Deep scan ${label} ${parsed.error.issues[0]!.message}.`,\n );\n }\n return parsed.data;\n}\n\nexport async function resolveDeepScanConfig(\n options: DeepScanOptions & { maxTimeMinutes?: number },\n source: string,\n signal?: AbortSignal,\n): Promise<ResolvedDeepScanConfig> {\n const explicit = deepScanOptions({ ...options, mode: \"deep\" });\n let document: TomlTable = {};\n // Complete saved settings do not depend on today's ambient configuration.\n if (!DEEP_SCAN_SETTINGS.every(([name]) => explicit[name] !== undefined)) {\n document = await readDeepScanDocument(source, signal);\n }\n const existing = document[\"deep_scan\"];\n if (\n existing !== undefined &&\n (!isRecord(existing) ||\n ![Object.prototype, null].includes(Object.getPrototypeOf(existing)))\n ) {\n throw new CodexSecurityError(\n `Codex Security configuration [deep_scan] at ${source} must be a TOML table.`,\n );\n }\n const configured = (existing ?? {}) as TomlTable;\n const keys = new Set<string>(DEEP_SCAN_SETTINGS.map(([, key]) => key));\n const unknown = Object.keys(configured).filter((key) => !keys.has(key));\n if (unknown.length > 0) {\n throw new CodexSecurityError(\n `Unknown Codex Security Deep Scan configuration ${unknown.join(\", \")} in ${source}.`,\n );\n }\n const settings = {\n ...DEFAULT_DEEP_SCAN_SETTINGS,\n } as Required<DeepScanOptions>;\n const sources = {} as DeepScanSources;\n for (const [name, key] of DEEP_SCAN_SETTINGS) {\n let value = Object.hasOwn(configured, key)\n ? configured[key]\n : DEFAULT_DEEP_SCAN_SETTINGS[name];\n if (name === \"workers\" && value === \"auto\")\n value = DEFAULT_DEEP_SCAN_SETTINGS.workers;\n if (explicit[name] !== undefined) value = explicit[name];\n sources[name] =\n explicit[name] !== undefined\n ? \"override\"\n : Object.hasOwn(configured, key)\n ? \"legacy\"\n : \"default\";\n settings[name] = requireDeepScanValue(\n name,\n value,\n sources[name] === \"legacy\" ? `${key} in ${source}` : name,\n );\n }\n return {\n settings,\n sources,\n source,\n document,\n overrides: explicit,\n };\n}\n\nexport async function writeDeepScanConfig(\n destination: string,\n resolved: ResolvedDeepScanConfig,\n workerRuntime?: JsonObject,\n): Promise<void> {\n const [source, target] = await Promise.all([\n canonicalConfigPath(resolved.source),\n runtimeConfigPath(destination),\n ]);\n let document = resolved.document;\n const sameFile = source === target;\n if (sameFile) {\n if (Object.keys(resolved.overrides).length === 0) return;\n document = await readDeepScanDocument(destination);\n }\n // An isolated runtime needs a complete snapshot. An ambient file keeps\n // inherited defaults unset so future releases can still update them.\n const settings = sameFile ? resolved.overrides : resolved.settings;\n const retainAmbientSettings =\n sameFile &&\n DEEP_SCAN_SETTINGS.some(([name]) => settings[name] === undefined);\n await writeCodexConfig(destination, {\n ...document,\n ...(workerRuntime === undefined ? {} : { worker_runtime: workerRuntime }),\n deep_scan: {\n ...(retainAmbientSettings\n ? (document[\"deep_scan\"] as TomlTable | undefined)\n : {}),\n ...Object.fromEntries(\n DEEP_SCAN_SETTINGS.filter(([name]) => settings[name] !== undefined).map(\n ([name, key]) => [key, settings[name]],\n ),\n ),\n },\n } as JsonObject);\n}\n\nasync function runtimeConfigPath(path: string): Promise<string> {\n try {\n return await canonicalConfigPath(path);\n } catch (error) {\n if (\n (error as NodeJS.ErrnoException).code !== \"ELOOP\" ||\n !(await lstat(path)).isSymbolicLink()\n )\n throw error;\n // A stale cyclic file link is replaced by writeCodexConfig's atomic rename.\n // Errors resolving its parent (or the ambient source) still fail the write.\n return join(await canonicalConfigPath(dirname(path)), basename(path));\n }\n}\n\nasync function readDeepScanDocument(\n source: string,\n signal?: AbortSignal,\n): Promise<TomlTable> {\n try {\n return parseToml(await readFile(source, { encoding: \"utf8\", signal }));\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw new CodexSecurityError(\n `Cannot read Codex Security configuration at ${source}.`,\n { cause: error },\n );\n }\n return {};\n }\n}\n"]}
1
+ {"version":3,"file":"deep-config.js","sourceRoot":"","sources":["../src/deep-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,KAAK,IAAI,SAAS,EAAkB,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAmB,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,aAAa,GACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,kBAAkB,GAEnB,MAAM,oBAAoB,CAAC;AAc5B,MAAM,UAAU,eAAe,CAC7B,OAAuE;IAEvE,MAAM,QAAQ,GAAoB,EAAE,CAAC;IACrC,MAAM,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAC/D,OAAO,CAAC,cAAc,CACvB,CAAC;IACF,IAAI,CAAC,OAAO,CAAC,OAAO,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js\";\nimport { lstat, readFile } from \"node:fs/promises\";\nimport { basename, dirname, join } from \"node:path\";\nimport { parse as parseToml, type TomlTable } from \"smol-toml\";\nimport { writeCodexConfig, type JsonObject } from \"./config.js\";\nimport { canonicalConfigPath } from \"./runtime.js\";\nimport {\n DEEP_SCAN_SETTINGS,\n DEFAULT_DEEP_SCAN_SETTINGS,\n hoursConflict,\n} from \"./deep-scan-defaults.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport {\n DEFAULT_SCAN_MODE,\n DeepScanSettingsSchema,\n ScanSettingsSchema,\n type DeepScanOptions,\n} from \"./scan-settings.js\";\nimport type { ScanMode } from \"./scan-modes.js\";\n\nexport type DeepScanSources = Record<\n keyof DeepScanOptions,\n \"default\" | \"legacy\" | \"override\"\n>;\nexport interface ResolvedDeepScanConfig {\n settings: Required<DeepScanOptions>;\n sources: DeepScanSources;\n source: string;\n document: TomlTable;\n}\n\nexport function deepScanOptions(\n options: DeepScanOptions & { mode?: ScanMode; maxTimeMinutes?: number },\n): DeepScanOptions {\n const selected: DeepScanOptions = {};\n const minutes = ScanSettingsSchema.shape.maxTimeMinutes.safeParse(\n options.maxTimeMinutes,\n );\n if (!minutes.success) {\n throw new CodexSecurityError(\n \"maxTimeMinutes / --max-time must be a finite positive number of minutes.\",\n );\n }\n for (const [name] of DEEP_SCAN_SETTINGS) {\n const value = options[name];\n if (value === undefined) continue;\n if ((options.mode ?? DEFAULT_SCAN_MODE) !== \"deep\") {\n throw new CodexSecurityError(\"Deep scan settings require deep mode.\");\n }\n selected[name] = requireDeepScanValue(name, value, name);\n }\n if (minutes.data !== undefined && options.mode === \"deep\") {\n if (minutes.data > 5760) {\n throw new CodexSecurityError(\n \"Deep scan maxTimeMinutes / --max-time must be no greater than 5760 minutes.\",\n );\n }\n const hours = minutes.data / 60;\n if (hoursConflict(hours, selected.maxTimeHours)) {\n throw new CodexSecurityError(\n \"Conflicting maxTimeMinutes / --max-time and maxTimeHours / --max-time-hours settings.\",\n );\n }\n selected.maxTimeHours = hours;\n }\n if (\n minutes.data !== undefined &&\n !Number.isFinite(new Date(Date.now() + minutes.data * 60_000).getTime())\n ) {\n throw new CodexSecurityError(\n \"maxTimeMinutes / --max-time must produce a deadline within the supported date range.\",\n );\n }\n return selected;\n}\n\nfunction requireDeepScanValue(\n name: keyof DeepScanOptions,\n value: unknown,\n label: string,\n): number {\n const parsed = DeepScanSettingsSchema.shape[name].unwrap().safeParse(value);\n if (!parsed.success) {\n throw new CodexSecurityError(\n `Deep scan ${label} ${parsed.error.issues[0]!.message}.`,\n );\n }\n return parsed.data;\n}\n\nexport async function resolveDeepScanConfig(\n options: DeepScanOptions & { maxTimeMinutes?: number },\n source: string,\n signal?: AbortSignal,\n): Promise<ResolvedDeepScanConfig> {\n const explicit = deepScanOptions({ ...options, mode: \"deep\" });\n let document: TomlTable = {};\n // Complete saved settings do not depend on today's ambient configuration.\n if (!DEEP_SCAN_SETTINGS.every(([name]) => explicit[name] !== undefined)) {\n document = await readDeepScanDocument(source, signal);\n }\n const existing = document[\"deep_scan\"];\n if (\n existing !== undefined &&\n (!isRecord(existing) ||\n ![Object.prototype, null].includes(Object.getPrototypeOf(existing)))\n ) {\n throw new CodexSecurityError(\n `Codex Security configuration [deep_scan] at ${source} must be a TOML table.`,\n );\n }\n const configured = (existing ?? {}) as TomlTable;\n const keys = new Set<string>(DEEP_SCAN_SETTINGS.map(([, key]) => key));\n const unknown = Object.keys(configured).filter((key) => !keys.has(key));\n if (unknown.length > 0) {\n throw new CodexSecurityError(\n `Unknown Codex Security Deep Scan configuration ${unknown.join(\", \")} in ${source}.`,\n );\n }\n const settings: Required<DeepScanOptions> = { ...DEFAULT_DEEP_SCAN_SETTINGS };\n const sources = {} as DeepScanSources;\n for (const [name, key] of DEEP_SCAN_SETTINGS) {\n const legacy = Object.hasOwn(configured, key) ? configured[key] : undefined;\n const override = explicit[name];\n sources[name] =\n override !== undefined\n ? \"override\"\n : legacy !== undefined\n ? \"legacy\"\n : \"default\";\n const value = override ?? legacy ?? settings[name];\n settings[name] = requireDeepScanValue(\n name,\n name === \"workers\" && value === \"auto\"\n ? DEFAULT_DEEP_SCAN_SETTINGS.workers\n : value,\n sources[name] === \"legacy\" ? `${key} in ${source}` : name,\n );\n }\n return {\n settings,\n sources,\n source,\n document,\n };\n}\n\nexport async function writeDeepScanConfig(\n destination: string,\n resolved: ResolvedDeepScanConfig,\n workerRuntime?: JsonObject,\n): Promise<void> {\n const [source, target] = await Promise.all([\n canonicalConfigPath(resolved.source),\n runtimeConfigPath(destination),\n ]);\n const ambient = source === target;\n const fields = DEEP_SCAN_SETTINGS.filter(\n ([name]) => !ambient || resolved.sources[name] === \"override\",\n );\n if (fields.length === 0) return;\n const document = ambient\n ? await readDeepScanDocument(destination)\n : resolved.document;\n // A complete snapshot replaces the Deep table. Partial ambient writes preserve other keys.\n await writeCodexConfig(destination, {\n ...document,\n ...(workerRuntime === undefined ? {} : { worker_runtime: workerRuntime }),\n deep_scan: {\n ...(fields.length < DEEP_SCAN_SETTINGS.length\n ? (document[\"deep_scan\"] as TomlTable | undefined)\n : {}),\n ...Object.fromEntries(\n fields.map(([name, key]) => [key, resolved.settings[name]]),\n ),\n },\n } as JsonObject);\n}\n\nasync function runtimeConfigPath(path: string): Promise<string> {\n try {\n return await canonicalConfigPath(path);\n } catch (error) {\n if (\n (error as NodeJS.ErrnoException).code !== \"ELOOP\" ||\n !(await lstat(path)).isSymbolicLink()\n )\n throw error;\n // A stale cyclic file link is replaced by writeCodexConfig's atomic rename.\n // Errors resolving its parent (or the ambient source) still fail the write.\n return join(await canonicalConfigPath(dirname(path)), basename(path));\n }\n}\n\nasync function readDeepScanDocument(\n source: string,\n signal?: AbortSignal,\n): Promise<TomlTable> {\n try {\n return parseToml(await readFile(source, { encoding: \"utf8\", signal }));\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw new CodexSecurityError(\n `Cannot read Codex Security configuration at ${source}.`,\n { cause: error },\n );\n }\n return {};\n }\n}\n"]}
@@ -6,4 +6,6 @@ export declare const DEFAULT_DEEP_SCAN_SETTINGS: {
6
6
  readonly maxDiscoveryRuns: 40;
7
7
  readonly maxTimeHours: 96;
8
8
  };
9
+ export declare const DEEP_SCAN_SETTINGS: readonly [readonly ["workers", "workers", "workers", "--workers"], readonly ["subagents", "subagents", "subagents_per_worker", "--subagents"], readonly ["stopAfterNoNew", "stop_after_no_new", "stop_after_no_new", "--stop-after-no-new"], readonly ["stopAfterConsecutiveErrors", "stop_after_consecutive_errors", "stop_after_consecutive_errors", null], readonly ["maxDiscoveryRuns", "max_discovery_runs", "max_discovery_runs", "--max-discovery-runs"], readonly ["maxTimeHours", "max_time_hours", "max_time_hours", "--max-time-hours"]];
10
+ export declare function hoursConflict(hours: number, prior?: number): boolean;
9
11
  //# sourceMappingURL=deep-scan-defaults.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deep-scan-defaults.d.ts","sourceRoot":"","sources":["../src/deep-scan-defaults.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,0BAA0B;aACrC,OAAO,EAAE,CAAC;aACV,SAAS,EAAE,CAAC;aACZ,cAAc,EAAE,CAAC;aACjB,0BAA0B,EAAE,CAAC;aAC7B,gBAAgB,EAAE,EAAE;aACpB,YAAY,EAAE,EAAE;CACR,CAAC"}
1
+ {"version":3,"file":"deep-scan-defaults.d.ts","sourceRoot":"","sources":["../src/deep-scan-defaults.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,0BAA0B;aACrC,OAAO,EAAE,CAAC;aACV,SAAS,EAAE,CAAC;aACZ,cAAc,EAAE,CAAC;aACjB,0BAA0B,EAAE,CAAC;aAC7B,gBAAgB,EAAE,EAAE;aACpB,YAAY,EAAE,EAAE;CACR,CAAC;AAGX,eAAO,MAAM,kBAAkB,sBAC5B,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,aAC5C,WAAW,EAAE,WAAW,EAAE,sBAAsB,EAAE,aAAa,aAE9D,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,aAGrB,4BAA4B,EAC5B,+BAA+B,EAC/B,+BAA+B,mBAI/B,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,aAEvB,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAC/D,CAAC;AAEX,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAQ,WAEzD"}
@@ -1,4 +1,4 @@
1
- // Generated from the plugin deep_scan_defaults.json. Run pnpm build.
1
+ // Generated from the plugin Deep Scan defaults and settings. Run pnpm build.
2
2
  export const DEFAULT_DEEP_SCAN_SETTINGS = {
3
3
  workers: 4,
4
4
  subagents: 3,
@@ -7,4 +7,31 @@ export const DEFAULT_DEEP_SCAN_SETTINGS = {
7
7
  maxDiscoveryRuns: 40,
8
8
  maxTimeHours: 96,
9
9
  };
10
+ // SDK name, legacy TOML key, project key, and CLI flag (when exposed).
11
+ export const DEEP_SCAN_SETTINGS = [
12
+ ["workers", "workers", "workers", "--workers"],
13
+ ["subagents", "subagents", "subagents_per_worker", "--subagents"],
14
+ [
15
+ "stopAfterNoNew",
16
+ "stop_after_no_new",
17
+ "stop_after_no_new",
18
+ "--stop-after-no-new",
19
+ ],
20
+ [
21
+ "stopAfterConsecutiveErrors",
22
+ "stop_after_consecutive_errors",
23
+ "stop_after_consecutive_errors",
24
+ null,
25
+ ],
26
+ [
27
+ "maxDiscoveryRuns",
28
+ "max_discovery_runs",
29
+ "max_discovery_runs",
30
+ "--max-discovery-runs",
31
+ ],
32
+ ["maxTimeHours", "max_time_hours", "max_time_hours", "--max-time-hours"],
33
+ ];
34
+ export function hoursConflict(hours, prior = hours) {
35
+ return Math.abs(prior - hours) > Number.EPSILON * Math.max(prior, hours);
36
+ }
10
37
  //# sourceMappingURL=deep-scan-defaults.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"deep-scan-defaults.js","sourceRoot":"","sources":["../src/deep-scan-defaults.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,OAAO,EAAE,CAAC;IACV,SAAS,EAAE,CAAC;IACZ,cAAc,EAAE,CAAC;IACjB,0BAA0B,EAAE,CAAC;IAC7B,gBAAgB,EAAE,EAAE;IACpB,YAAY,EAAE,EAAE;CACR,CAAC","sourcesContent":["// Generated from the plugin deep_scan_defaults.json. Run pnpm build.\nexport const DEFAULT_DEEP_SCAN_SETTINGS = {\n workers: 4,\n subagents: 3,\n stopAfterNoNew: 4,\n stopAfterConsecutiveErrors: 3,\n maxDiscoveryRuns: 40,\n maxTimeHours: 96,\n} as const;\n"]}
1
+ {"version":3,"file":"deep-scan-defaults.js","sourceRoot":"","sources":["../src/deep-scan-defaults.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,OAAO,EAAE,CAAC;IACV,SAAS,EAAE,CAAC;IACZ,cAAc,EAAE,CAAC;IACjB,0BAA0B,EAAE,CAAC;IAC7B,gBAAgB,EAAE,EAAE;IACpB,YAAY,EAAE,EAAE;CACR,CAAC;AAEX,uEAAuE;AACvE,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,CAAC;IAC9C,CAAC,WAAW,EAAE,WAAW,EAAE,sBAAsB,EAAE,aAAa,CAAC;IACjE;QACE,gBAAgB;QAChB,mBAAmB;QACnB,mBAAmB;QACnB,qBAAqB;KACtB;IACD;QACE,4BAA4B;QAC5B,+BAA+B;QAC/B,+BAA+B;QAC/B,IAAI;KACL;IACD;QACE,kBAAkB;QAClB,oBAAoB;QACpB,oBAAoB;QACpB,sBAAsB;KACvB;IACD,CAAC,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,CAAC;CAChE,CAAC;AAEX,MAAM,UAAU,aAAa,CAAC,KAAa,EAAE,KAAK,GAAG,KAAK;IACxD,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["// Generated from the plugin Deep Scan defaults and settings. Run pnpm build.\nexport const DEFAULT_DEEP_SCAN_SETTINGS = {\n workers: 4,\n subagents: 3,\n stopAfterNoNew: 4,\n stopAfterConsecutiveErrors: 3,\n maxDiscoveryRuns: 40,\n maxTimeHours: 96,\n} as const;\n\n// SDK name, legacy TOML key, project key, and CLI flag (when exposed).\nexport const DEEP_SCAN_SETTINGS = [\n [\"workers\", \"workers\", \"workers\", \"--workers\"],\n [\"subagents\", \"subagents\", \"subagents_per_worker\", \"--subagents\"],\n [\n \"stopAfterNoNew\",\n \"stop_after_no_new\",\n \"stop_after_no_new\",\n \"--stop-after-no-new\",\n ],\n [\n \"stopAfterConsecutiveErrors\",\n \"stop_after_consecutive_errors\",\n \"stop_after_consecutive_errors\",\n null,\n ],\n [\n \"maxDiscoveryRuns\",\n \"max_discovery_runs\",\n \"max_discovery_runs\",\n \"--max-discovery-runs\",\n ],\n [\"maxTimeHours\", \"max_time_hours\", \"max_time_hours\", \"--max-time-hours\"],\n] as const;\n\nexport function hoursConflict(hours: number, prior = hours) {\n return Math.abs(prior - hours) > Number.EPSILON * Math.max(prior, hours);\n}\n"]}
@@ -1,7 +1,9 @@
1
1
  import type { CodexOptions } from "@openai/codex-sdk";
2
2
  import { type JsonObject } from "./config.js";
3
3
  import { type CodexCommand } from "./runtime.js";
4
+ export type DeepScanDiagnostic = Readonly<Record<string, string | number>>;
4
5
  export interface DirectDeepScanOptions {
6
+ onDiagnostic?: (event: DeepScanDiagnostic) => void;
5
7
  codexOptions: CodexOptions & {
6
8
  nativeProfile?: string;
7
9
  };
@@ -1 +1 @@
1
- {"version":3,"file":"deep-scan.d.ts","sourceRoot":"","sources":["../src/deep-scan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A2B,CACzC,MAAM,EAAE,UAAU,EAClB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC,MAAM,EAAE,CAkGV;AAGD,eAAO,MAAM,8BAA8B;aACzC,YAAY,EAAE,CAAC;aACf,mBAAmB,EAAE,CAAC;aACtB,wBAAwB,EAAE,CAAC;aAC3B,aAAa,EAAE,CAAC;CACR,CAAC;AAEX,2EAA2E;AAC3E,wBAAuB,WAAW,CAChC,OAAO,EAAE,qBAAqB,GAC7B,cAAc,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC,CA6ED"}
package/dist/deep-scan.js CHANGED
@@ -15,7 +15,7 @@ import { bundledCodexSdkEnvironment, resolveBundledCodexExecutable, } from "./co
15
15
  import { CodexSecurityError } from "./errors.js";
16
16
  import { deepMerge, inlineToml, } from "./config.js";
17
17
  import { isRecord } from "./record.js";
18
- import { executablePathForSpawn, PLUGIN_NAME, runCodexCommand, } from "./runtime.js";
18
+ import { executablePathForSpawn, isDisconnectedChildStdin, PLUGIN_NAME, runCodexCommand, } from "./runtime.js";
19
19
  import { resolveTrustedExecutable } from "./trusted-executable.js";
20
20
  import { nativePermissionPreflight, nativeProfileClient, withCodexPreflightLock, } from "./provider-profile.js";
21
21
  // The stock SDK emits one flag per leaf, including literal dotted keys in order.
@@ -286,7 +286,11 @@ export async function* runDeepScan(options) {
286
286
  : undefined;
287
287
  if (node === null)
288
288
  throw new CodexSecurityError("Node.js is not available on PATH.");
289
- const output = await runEngine(node?.executable ?? process.execPath, [join(options.pluginRoot, "mcp", "server.mjs"), "--deep-scan-engine"], node?.environment ?? environment, JSON.stringify({ scanId: options.scanId, ...session }), options.signal);
289
+ const output = await runEngine(node?.executable ?? process.execPath, [join(options.pluginRoot, "mcp", "server.mjs"), "--deep-scan-engine"], node?.environment ?? environment, JSON.stringify({
290
+ scanId: options.scanId,
291
+ ...session,
292
+ ...(options.onDiagnostic && { diagnosticsVersion: 1 }),
293
+ }), options.signal, options.onDiagnostic);
290
294
  const completed = JSON.parse(output);
291
295
  if (completed.scanId !== options.scanId ||
292
296
  completed.manifestPath !== join(options.scanDir, "scan-manifest.json")) {
@@ -299,12 +303,32 @@ export async function* runDeepScan(options) {
299
303
  usage: { ...DIRECT_DEEP_SCAN_CONTROL_USAGE },
300
304
  };
301
305
  }
302
- function runEngine(command, args, env, request, signal) {
306
+ function runEngine(command, args, env, request, signal, onDiagnostic) {
303
307
  signal.throwIfAborted();
304
308
  const child = spawn(executablePathForSpawn(command), args, {
305
309
  env,
306
310
  windowsHide: true,
311
+ serialization: "json",
312
+ stdio: onDiagnostic ? ["pipe", "pipe", "pipe", "ipc"] : "pipe",
307
313
  });
314
+ if (onDiagnostic) {
315
+ child.on("message", (message) => {
316
+ if (!isRecord(message) || typeof message["event"] !== "string")
317
+ return;
318
+ const fields = {};
319
+ for (const [name, value] of Object.entries(message)) {
320
+ if (/^[a-zA-Z][a-zA-Z0-9]*$/u.test(name) &&
321
+ (typeof value === "number" || typeof value === "string"))
322
+ fields[name] = value;
323
+ }
324
+ try {
325
+ void Promise.resolve(onDiagnostic(fields)).catch(() => { });
326
+ }
327
+ catch {
328
+ // The optional diagnostic sink cannot stop the scan.
329
+ }
330
+ });
331
+ }
308
332
  // EOF requests graceful coordinator/worker cleanup on Windows as well as Unix.
309
333
  // Keep the control pipe open until completion or explicit cancellation.
310
334
  const cancel = () => child.stdin.end();
@@ -321,7 +345,7 @@ function runEngine(command, args, env, request, signal) {
321
345
  processError = error;
322
346
  });
323
347
  child.stdin.on("error", (error) => {
324
- if (!["EPIPE", "ECONNRESET", "EOF", "ERR_STREAM_DESTROYED"].includes(error.code ?? ""))
348
+ if (!isDisconnectedChildStdin(error))
325
349
  processError = error;
326
350
  });
327
351
  const result = new Promise((resolve, reject) => {
@@ -1 +1 @@
1
- {"version":3,"file":"deep-scan.js","sourceRoot":"","sources":["../src/deep-scan.ts"],"names":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C,CAAC;IACH,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAA4B,EAAE,EAAE;QACvD,IACE,CAAC,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC,QAAQ,CAC9D,KAAK,CAAC,IAAI,IAAI,EAAE,CACjB;YAED,YAAY,GAAG,KAAK,CAAC;IACzB,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrD,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YAC3B,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC5C,IAAI,MAAM,CAAC,OAAO;gBAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;iBACrC,IAAI,YAAY;gBAAE,MAAM,CAAC,YAAY,CAAC,CAAC;iBACvC,IAAI,IAAI,KAAK,CAAC;gBACjB,MAAM,CACJ,IAAI,kBAAkB,CACpB,MAAM,CAAC,IAAI,EAAE,IAAI,qCAAqC,IAAI,GAAG,CAC9D,CACF,CAAC;;gBACC,OAAO,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAClC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,IAAI,MAAM,CAAC,OAAO;QAAE,MAAM,EAAE,CAAC;IAC7B,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { realpathSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { CodexOptions } from \"@openai/codex-sdk\";\nimport { parse } from \"smol-toml\";\nimport {\n bundledCodexSdkEnvironment,\n resolveBundledCodexExecutable,\n} from \"./codex-sdk-environment.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport {\n deepMerge,\n inlineToml,\n type JsonObject,\n type JsonValue,\n} from \"./config.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n executablePathForSpawn,\n PLUGIN_NAME,\n runCodexCommand,\n type CodexCommand,\n} from \"./runtime.js\";\nimport { resolveTrustedExecutable } from \"./trusted-executable.js\";\nimport {\n nativePermissionPreflight,\n nativeProfileClient,\n withCodexPreflightLock,\n} from \"./provider-profile.js\";\n\nexport interface DirectDeepScanOptions {\n codexOptions: CodexOptions & { nativeProfile?: string };\n preflightCommand: CodexCommand;\n pluginRoot: string;\n repository: string;\n scanDir: string;\n scanId: string;\n prompt: string;\n signal: AbortSignal;\n}\n\n// The stock SDK emits one flag per leaf, including literal dotted keys in order.\nfunction sdkConfigFlags(config: JsonObject, prefix = \"\"): string[] {\n return Object.entries(config).flatMap(([key, value]) => {\n const path = prefix ? `${prefix}.${key}` : key;\n return isRecord(value) && Object.keys(value).length\n ? sdkConfigFlags(value, path)\n : [`${path}=${inlineToml(value)}`];\n });\n}\n\n// An older custom launcher must start in the caller's directory. Only use\n// supplied routing when its app-server cannot read the scan at startup.\nfunction suppliedParentRouting(\n overrides: readonly string[],\n): JsonObject | undefined {\n try {\n const config: JsonObject = Object.create(null);\n for (const override of overrides) {\n const equals = override.indexOf(\"=\");\n const key = override.slice(0, equals).trim();\n if (!/^(?:features|mcp_servers)(?:\\.|$)/u.test(key)) continue;\n const path = key.split(\".\");\n const leaf = path.pop()!;\n let table = config;\n for (const part of path) {\n const next = Object.hasOwn(table, part) ? table[part] : undefined;\n const child =\n table === config[\"features\"] && part === \"code_mode\"\n ? codeModeTable(next)\n : next;\n table = table[part] = Object.assign(\n Object.create(null),\n isRecord(child) ? child : {},\n );\n }\n const value = parse(`value=${override.slice(equals + 1)}`)[\n \"value\"\n ] as JsonValue;\n const priorMode =\n key === \"features.code_mode\" ? codeModeTable(table[leaf]) : undefined;\n const newMode = priorMode && codeModeTable(value);\n table[leaf] =\n priorMode && newMode ? deepMerge({ ...priorMode }, newMode) : value;\n }\n const servers = config[\"mcp_servers\"];\n const owner = isRecord(servers) ? servers[PLUGIN_NAME] : undefined;\n // Even a supplied transport can inherit a machine-level direct opt-out.\n if (isRecord(owner) && !Array.isArray(owner[\"omit_tools_from\"])) return;\n return config;\n } catch {\n // Leave malformed settings for exec's own parser.\n return undefined;\n }\n}\n\n// Codex merges a structured Code Mode setting with its boolean shorthand.\nfunction codeModeTable(value: JsonValue | undefined): JsonObject | undefined {\n if (typeof value === \"boolean\") return { enabled: value };\n return isRecord(value) ? value : undefined;\n}\n\n/** Read the same native layers and CLI overrides as the parent before adding its tool. */\nexport async function readDeepScanParentConfig(\n options: Pick<\n DirectDeepScanOptions,\n \"codexOptions\" | \"preflightCommand\" | \"scanDir\" | \"signal\"\n > & {\n plugin?: { marketplacePath: string; pluginName: string };\n pluginServers?: Record<string, unknown>;\n },\n): Promise<JsonObject | undefined> {\n const { codexOptions, preflightCommand: command } = options;\n const config = codexOptions.config ?? {};\n // The provider-profile launcher emits whole top-level tables instead.\n const overrides =\n codexOptions.nativeProfile === undefined\n ? sdkConfigFlags(config)\n : (await nativeProfileClient()).profileConfigOverrides(config);\n const environment = bundledCodexSdkEnvironment(command.command, {\n ...codexOptions.env,\n ...(codexOptions.apiKey === undefined\n ? {}\n : { CODEX_API_KEY: codexOptions.apiKey }),\n });\n const configOverrides = [\n ...overrides,\n ...(codexOptions.configOverrides ?? []),\n ];\n // Subcommand help does not load a project. A global --cd is ignored by\n // older app-servers, so require support on the subcommand itself.\n const help = await runCodexCommand(\n command,\n [\"app-server\", \"--cd\", options.scanDir, \"--help\"],\n environment,\n undefined,\n options.signal,\n );\n const supportsCd =\n help.success && /^\\s*(?:-C,\\s*)?--cd\\s+<[^>\\n]+>/mu.test(help.stdout);\n if (!supportsCd) {\n // The bundled command is the native executable itself. A custom launcher\n // can use its own working directory to resolve scripts and other inputs.\n if (\n resolve(options.scanDir) !== process.cwd() &&\n !isBundledExecutable(command.command)\n )\n return options.plugin\n ? undefined\n : suppliedParentRouting(configOverrides);\n if (environment[\"CODEX_HOME\"])\n environment[\"CODEX_HOME\"] = resolve(environment[\"CODEX_HOME\"]);\n }\n\n const native = await nativePermissionPreflight();\n return withCodexPreflightLock(environment, options.signal, () =>\n native.readDeepScanRuntimeConfig(\n {\n codexPath: command.command,\n commandArgs: command.args,\n cwd: supportsCd ? process.cwd() : options.scanDir,\n ...(supportsCd && { configCwd: options.scanDir }),\n configOverrides,\n env: environment,\n signal: options.signal,\n context: \"parent-config\",\n plugin: options.plugin,\n },\n (\n config: JsonObject,\n hasEmptyCatalog: (server: string) => Promise<boolean>,\n ) => inspectFilteredPeers(config, options.pluginServers, hasEmptyCatalog),\n ),\n );\n}\n\nfunction isBundledExecutable(command: string): boolean {\n try {\n return (\n realpathSync.native(command) ===\n realpathSync.native(resolveBundledCodexExecutable())\n );\n } catch {\n return false; // An installation may supply only an external launcher.\n }\n}\n\nasync function inspectFilteredPeers(\n config: JsonObject,\n pluginServers: Record<string, unknown> | undefined,\n hasEmptyCatalog: (server: string) => Promise<boolean>,\n): Promise<JsonObject> {\n const configured = isRecord(config[\"mcp_servers\"])\n ? config[\"mcp_servers\"]\n : {};\n const owner = configured[PLUGIN_NAME];\n if (\n isRecord(owner) &&\n (owner[\"command\"] ||\n owner[\"url\"] ||\n Array.isArray(owner[\"omit_tools_from\"]))\n )\n return config;\n const servers = { ...pluginServers, ...configured };\n const registration = servers[PLUGIN_NAME];\n if (!isRecord(registration) || registration[\"enabled\"] === false)\n return config;\n const routing = { ...configured };\n for (const [name, settings] of Object.entries(servers)) {\n if (\n name === PLUGIN_NAME ||\n !isRecord(settings) ||\n settings[\"enabled\"] === false ||\n ![\"codex_security\", \"mcp__codex_security\"].includes(\n normalizedServerName(name),\n )\n )\n continue;\n if (\n ![settings[\"enabled_tools\"], settings[\"disabled_tools\"]].some(\n (tools) => Array.isArray(tools) && tools.length > 0,\n )\n )\n continue;\n if (await hasEmptyCatalog(name)) {\n // This view is used only to select a namespace. Never change the peer's config.\n routing[name] = { enabled_tools: [] };\n }\n }\n return { ...config, mcp_servers: routing };\n}\n\nfunction normalizedServerName(server: string): string {\n return server.replace(/[-.:@/]/gu, \"_\");\n}\n\n/** Keep direct dispatch scoped to the original SDK coordinator turn and MCP server. */\nexport function deepScanParentToolOverrides(\n config: JsonObject,\n pluginServers: Record<string, unknown>,\n): string[] {\n const features = config[\"features\"] ?? {};\n if (!isRecord(features)) return [];\n const mode = features[\"code_mode\"];\n if (mode !== undefined && typeof mode !== \"boolean\" && !isRecord(mode))\n return [];\n const direct =\n (isRecord(mode) ? mode[\"direct_only_tool_namespaces\"] : undefined) ?? [];\n if (!Array.isArray(direct)) return [];\n\n const owner = PLUGIN_NAME;\n const bare = \"codex_security\";\n const prefixed = \"mcp__codex_security\";\n let required = [prefixed, bare];\n const overrides: string[] = [];\n const configured = config[\"mcp_servers\"];\n // Native registrations take precedence over the selected plugin's entries.\n const servers: Record<string, unknown> = {\n ...pluginServers,\n ...(isRecord(configured) ? configured : {}),\n };\n const ownerConfig = servers[owner];\n if (!isRecord(ownerConfig) || ownerConfig[\"enabled\"] === false) return [];\n const omitted = ownerConfig[\"omit_tools_from\"];\n if (Array.isArray(omitted) && omitted.includes(\"direct\")) return [];\n // A raw transport or an existing omission leaf can be updated in place.\n // Adding a new registration would shadow a plugin's transport and policy.\n if (\n isRecord(configured) &&\n Object.hasOwn(configured, owner) &&\n (Array.isArray(omitted) ||\n typeof ownerConfig[\"command\"] === \"string\" ||\n typeof ownerConfig[\"url\"] === \"string\")\n ) {\n if (omitted != null && !Array.isArray(omitted)) return [];\n const surfaces = omitted ?? [];\n if (surfaces.includes(\"code_mode\") && surfaces.includes(\"deferred\"))\n return [];\n return [\n `mcp_servers.${owner}.omit_tools_from=${inlineToml([...new Set([...surfaces, \"code_mode\", \"deferred\"])])}`,\n ];\n }\n const option = features[\"non_prefixed_mcp_tool_names\"];\n const enabled =\n option === true || (isRecord(option) && option[\"enabled\"] === true);\n const selected = isRecord(option) ? option[\"server_names\"] : undefined;\n function namespace(server: string): string {\n const name = normalizedServerName(server);\n const omitPrefix =\n enabled && (!Array.isArray(selected) || selected.includes(server));\n return omitPrefix || name.startsWith(\"mcp__\") ? name : `mcp__${name}`;\n }\n const occupied = new Set(\n Object.entries(servers)\n .filter(\n ([server, settings]) =>\n server !== owner &&\n isRecord(settings) &&\n settings[\"enabled\"] !== false &&\n (!Array.isArray(settings[\"enabled_tools\"]) ||\n settings[\"enabled_tools\"].length > 0),\n )\n .map(([server]) => namespace(server)),\n );\n const current = namespace(owner);\n if (occupied.has(current)) {\n const excluded = isRecord(mode) ? mode[\"excluded_tool_namespaces\"] : null;\n const routed = Array.isArray(excluded) ? [...direct, ...excluded] : direct;\n // Moving the owner also renames its peers. Keep names that the caller\n // explicitly routed or excluded from Code Mode.\n if (\n current === bare ||\n occupied.has(bare) ||\n routed.some(\n (name) =>\n name === current ||\n (typeof name === \"string\" &&\n /^mcp__codex_security_[0-9a-f]{12}$/u.test(name)),\n ) ||\n (option != null && !enabled)\n )\n return [];\n overrides.push(\n `features.non_prefixed_mcp_tool_names=${inlineToml({\n enabled: true,\n server_names: [...(Array.isArray(selected) ? selected : []), owner],\n })}`,\n );\n required = [bare];\n } else if (occupied.has(prefixed) || occupied.has(bare)) {\n required = [current];\n }\n if (!required.every((name) => direct.includes(name))) {\n overrides.push(\n `features.code_mode.direct_only_tool_namespaces=${inlineToml([...new Set([...direct, ...required])])}`,\n );\n }\n return overrides;\n}\n\n// The direct coordinator records context but never calls a model itself.\nexport const DIRECT_DEEP_SCAN_CONTROL_USAGE = {\n input_tokens: 0,\n cached_input_tokens: 0,\n cache_write_input_tokens: 0,\n output_tokens: 0,\n} as const;\n\n/** Run the same coordinator as the plugin, without a parent model turn. */\nexport async function* runDeepScan(\n options: DirectDeepScanOptions,\n): AsyncGenerator<{\n type: string;\n [key: string]: unknown;\n}> {\n const native = await import(\n pathToFileURL(\n join(options.pluginRoot, \"mcp\", \"permission-profile-preflight.mjs\"),\n ).href\n );\n const profile = await import(\n pathToFileURL(join(options.pluginRoot, \"scripts\", \"codex_profile.mjs\")).href\n );\n const configured = options.codexOptions;\n const command = options.preflightCommand;\n const environment = bundledCodexSdkEnvironment(command.command, {\n ...configured.env,\n ...(configured.apiKey === undefined\n ? {}\n : { CODEX_API_KEY: configured.apiKey }),\n });\n const session = (await withCodexPreflightLock(\n environment,\n options.signal,\n () =>\n native.prepareCliDeepScanSession({\n codexPath: command.command,\n commandArgs: command.args,\n cwd: options.scanDir,\n env: environment,\n configOverrides: [\n ...profile.profileConfigOverrides(configured.config ?? {}),\n ...(configured.configOverrides ?? []),\n // This session only records native context; workers keep their own snapshot.\n \"features.plugins=false\",\n ],\n signal: options.signal,\n prompt:\n options.prompt +\n \"\\n\\nThe host runs this Deep Scan coordinator directly and owns finalization. This saved request supplies context for later follow-up; do not start a replacement scan.\",\n }),\n )) as {\n threadId: string;\n model: string;\n reasoningEffort?: string;\n permissionProfile: unknown;\n };\n yield { type: \"thread.started\", thread_id: session.threadId };\n options.signal.throwIfAborted();\n const node = process.versions[\"bun\"]\n ? await resolveTrustedExecutable(\"node\", environment, [options.repository])\n : undefined;\n if (node === null)\n throw new CodexSecurityError(\"Node.js is not available on PATH.\");\n const output = await runEngine(\n node?.executable ?? process.execPath,\n [join(options.pluginRoot, \"mcp\", \"server.mjs\"), \"--deep-scan-engine\"],\n node?.environment ?? environment,\n JSON.stringify({ scanId: options.scanId, ...session }),\n options.signal,\n );\n const completed = JSON.parse(output);\n if (\n completed.scanId !== options.scanId ||\n completed.manifestPath !== join(options.scanDir, \"scan-manifest.json\")\n ) {\n throw new CodexSecurityError(\n \"Deep Scan engine returned results for a different scan.\",\n );\n }\n // The control session makes no model calls. Worker usage is read by the\n // existing scan tracker from the native sessions below this scan directory.\n yield {\n type: \"turn.completed\",\n usage: { ...DIRECT_DEEP_SCAN_CONTROL_USAGE },\n };\n}\n\nfunction runEngine(\n command: string,\n args: string[],\n env: NodeJS.ProcessEnv,\n request: string,\n signal: AbortSignal,\n): Promise<string> {\n signal.throwIfAborted();\n const child = spawn(executablePathForSpawn(command), args, {\n env,\n windowsHide: true,\n });\n // EOF requests graceful coordinator/worker cleanup on Windows as well as Unix.\n // Keep the control pipe open until completion or explicit cancellation.\n const cancel = () => child.stdin.end();\n let stdout = \"\";\n let stderr = \"\";\n let processError: Error | undefined;\n child.stdout.setEncoding(\"utf8\").on(\"data\", (chunk) => {\n stdout += chunk;\n });\n child.stderr.setEncoding(\"utf8\").on(\"data\", (chunk) => {\n stderr += chunk;\n });\n child.once(\"error\", (error) => {\n processError = error;\n });\n child.stdin.on(\"error\", (error: NodeJS.ErrnoException) => {\n if (\n ![\"EPIPE\", \"ECONNRESET\", \"EOF\", \"ERR_STREAM_DESTROYED\"].includes(\n error.code ?? \"\",\n )\n )\n processError = error;\n });\n const result = new Promise<string>((resolve, reject) => {\n child.once(\"close\", (code) => {\n signal.removeEventListener(\"abort\", cancel);\n if (signal.aborted) reject(signal.reason);\n else if (processError) reject(processError);\n else if (code !== 0)\n reject(\n new CodexSecurityError(\n stderr.trim() || `Deep Scan engine exited with code ${code}.`,\n ),\n );\n else resolve(stdout);\n });\n });\n child.stdin.write(request + \"\\n\");\n signal.addEventListener(\"abort\", cancel, { once: true });\n if (signal.aborted) cancel();\n return result;\n}\n"]}
1
+ {"version":3,"file":"deep-scan.js","sourceRoot":"","sources":["../src/deep-scan.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAuC,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CA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AAO;gBAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;iBACrC,IAAI,YAAY;gBAAE,MAAM,CAAC,YAAY,CAAC,CAAC;iBACvC,IAAI,IAAI,KAAK,CAAC;gBACjB,MAAM,CACJ,IAAI,kBAAkB,CACpB,MAAM,CAAC,IAAI,EAAE,IAAI,qCAAqC,IAAI,GAAG,CAC9D,CACF,CAAC;;gBACC,OAAO,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAClC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,IAAI,MAAM,CAAC,OAAO;QAAE,MAAM,EAAE,CAAC;IAC7B,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { spawn, type ChildProcessWithoutNullStreams } from \"node:child_process\";\nimport { realpathSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { CodexOptions } from \"@openai/codex-sdk\";\nimport { parse } from \"smol-toml\";\nimport {\n bundledCodexSdkEnvironment,\n resolveBundledCodexExecutable,\n} from \"./codex-sdk-environment.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport {\n deepMerge,\n inlineToml,\n type JsonObject,\n type JsonValue,\n} from \"./config.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n executablePathForSpawn,\n isDisconnectedChildStdin,\n PLUGIN_NAME,\n runCodexCommand,\n type CodexCommand,\n} from \"./runtime.js\";\nimport { resolveTrustedExecutable } from \"./trusted-executable.js\";\nimport {\n nativePermissionPreflight,\n nativeProfileClient,\n withCodexPreflightLock,\n} from \"./provider-profile.js\";\n\nexport type DeepScanDiagnostic = Readonly<Record<string, string | number>>;\n\nexport interface DirectDeepScanOptions {\n onDiagnostic?: (event: DeepScanDiagnostic) => void;\n codexOptions: CodexOptions & { nativeProfile?: string };\n preflightCommand: CodexCommand;\n pluginRoot: string;\n repository: string;\n scanDir: string;\n scanId: string;\n prompt: string;\n signal: AbortSignal;\n}\n\n// The stock SDK emits one flag per leaf, including literal dotted keys in order.\nfunction sdkConfigFlags(config: JsonObject, prefix = \"\"): string[] {\n return Object.entries(config).flatMap(([key, value]) => {\n const path = prefix ? `${prefix}.${key}` : key;\n return isRecord(value) && Object.keys(value).length\n ? sdkConfigFlags(value, path)\n : [`${path}=${inlineToml(value)}`];\n });\n}\n\n// An older custom launcher must start in the caller's directory. Only use\n// supplied routing when its app-server cannot read the scan at startup.\nfunction suppliedParentRouting(\n overrides: readonly string[],\n): JsonObject | undefined {\n try {\n const config: JsonObject = Object.create(null);\n for (const override of overrides) {\n const equals = override.indexOf(\"=\");\n const key = override.slice(0, equals).trim();\n if (!/^(?:features|mcp_servers)(?:\\.|$)/u.test(key)) continue;\n const path = key.split(\".\");\n const leaf = path.pop()!;\n let table = config;\n for (const part of path) {\n const next = Object.hasOwn(table, part) ? table[part] : undefined;\n const child =\n table === config[\"features\"] && part === \"code_mode\"\n ? codeModeTable(next)\n : next;\n table = table[part] = Object.assign(\n Object.create(null),\n isRecord(child) ? child : {},\n );\n }\n const value = parse(`value=${override.slice(equals + 1)}`)[\n \"value\"\n ] as JsonValue;\n const priorMode =\n key === \"features.code_mode\" ? codeModeTable(table[leaf]) : undefined;\n const newMode = priorMode && codeModeTable(value);\n table[leaf] =\n priorMode && newMode ? deepMerge({ ...priorMode }, newMode) : value;\n }\n const servers = config[\"mcp_servers\"];\n const owner = isRecord(servers) ? servers[PLUGIN_NAME] : undefined;\n // Even a supplied transport can inherit a machine-level direct opt-out.\n if (isRecord(owner) && !Array.isArray(owner[\"omit_tools_from\"])) return;\n return config;\n } catch {\n // Leave malformed settings for exec's own parser.\n return undefined;\n }\n}\n\n// Codex merges a structured Code Mode setting with its boolean shorthand.\nfunction codeModeTable(value: JsonValue | undefined): JsonObject | undefined {\n if (typeof value === \"boolean\") return { enabled: value };\n return isRecord(value) ? value : undefined;\n}\n\n/** Read the same native layers and CLI overrides as the parent before adding its tool. */\nexport async function readDeepScanParentConfig(\n options: Pick<\n DirectDeepScanOptions,\n \"codexOptions\" | \"preflightCommand\" | \"scanDir\" | \"signal\"\n > & {\n plugin?: { marketplacePath: string; pluginName: string };\n pluginServers?: Record<string, unknown>;\n },\n): Promise<JsonObject | undefined> {\n const { codexOptions, preflightCommand: command } = options;\n const config = codexOptions.config ?? {};\n // The provider-profile launcher emits whole top-level tables instead.\n const overrides =\n codexOptions.nativeProfile === undefined\n ? sdkConfigFlags(config)\n : (await nativeProfileClient()).profileConfigOverrides(config);\n const environment = bundledCodexSdkEnvironment(command.command, {\n ...codexOptions.env,\n ...(codexOptions.apiKey === undefined\n ? {}\n : { CODEX_API_KEY: codexOptions.apiKey }),\n });\n const configOverrides = [\n ...overrides,\n ...(codexOptions.configOverrides ?? []),\n ];\n // Subcommand help does not load a project. A global --cd is ignored by\n // older app-servers, so require support on the subcommand itself.\n const help = await runCodexCommand(\n command,\n [\"app-server\", \"--cd\", options.scanDir, \"--help\"],\n environment,\n undefined,\n options.signal,\n );\n const supportsCd =\n help.success && /^\\s*(?:-C,\\s*)?--cd\\s+<[^>\\n]+>/mu.test(help.stdout);\n if (!supportsCd) {\n // The bundled command is the native executable itself. A custom launcher\n // can use its own working directory to resolve scripts and other inputs.\n if (\n resolve(options.scanDir) !== process.cwd() &&\n !isBundledExecutable(command.command)\n )\n return options.plugin\n ? undefined\n : suppliedParentRouting(configOverrides);\n if (environment[\"CODEX_HOME\"])\n environment[\"CODEX_HOME\"] = resolve(environment[\"CODEX_HOME\"]);\n }\n\n const native = await nativePermissionPreflight();\n return withCodexPreflightLock(environment, options.signal, () =>\n native.readDeepScanRuntimeConfig(\n {\n codexPath: command.command,\n commandArgs: command.args,\n cwd: supportsCd ? process.cwd() : options.scanDir,\n ...(supportsCd && { configCwd: options.scanDir }),\n configOverrides,\n env: environment,\n signal: options.signal,\n context: \"parent-config\",\n plugin: options.plugin,\n },\n (\n config: JsonObject,\n hasEmptyCatalog: (server: string) => Promise<boolean>,\n ) => inspectFilteredPeers(config, options.pluginServers, hasEmptyCatalog),\n ),\n );\n}\n\nfunction isBundledExecutable(command: string): boolean {\n try {\n return (\n realpathSync.native(command) ===\n realpathSync.native(resolveBundledCodexExecutable())\n );\n } catch {\n return false; // An installation may supply only an external launcher.\n }\n}\n\nasync function inspectFilteredPeers(\n config: JsonObject,\n pluginServers: Record<string, unknown> | undefined,\n hasEmptyCatalog: (server: string) => Promise<boolean>,\n): Promise<JsonObject> {\n const configured = isRecord(config[\"mcp_servers\"])\n ? config[\"mcp_servers\"]\n : {};\n const owner = configured[PLUGIN_NAME];\n if (\n isRecord(owner) &&\n (owner[\"command\"] ||\n owner[\"url\"] ||\n Array.isArray(owner[\"omit_tools_from\"]))\n )\n return config;\n const servers = { ...pluginServers, ...configured };\n const registration = servers[PLUGIN_NAME];\n if (!isRecord(registration) || registration[\"enabled\"] === false)\n return config;\n const routing = { ...configured };\n for (const [name, settings] of Object.entries(servers)) {\n if (\n name === PLUGIN_NAME ||\n !isRecord(settings) ||\n settings[\"enabled\"] === false ||\n ![\"codex_security\", \"mcp__codex_security\"].includes(\n normalizedServerName(name),\n )\n )\n continue;\n if (\n ![settings[\"enabled_tools\"], settings[\"disabled_tools\"]].some(\n (tools) => Array.isArray(tools) && tools.length > 0,\n )\n )\n continue;\n if (await hasEmptyCatalog(name)) {\n // This view is used only to select a namespace. Never change the peer's config.\n routing[name] = { enabled_tools: [] };\n }\n }\n return { ...config, mcp_servers: routing };\n}\n\nfunction normalizedServerName(server: string): string {\n return server.replace(/[-.:@/]/gu, \"_\");\n}\n\n/** Keep direct dispatch scoped to the original SDK coordinator turn and MCP server. */\nexport function deepScanParentToolOverrides(\n config: JsonObject,\n pluginServers: Record<string, unknown>,\n): string[] {\n const features = config[\"features\"] ?? {};\n if (!isRecord(features)) return [];\n const mode = features[\"code_mode\"];\n if (mode !== undefined && typeof mode !== \"boolean\" && !isRecord(mode))\n return [];\n const direct =\n (isRecord(mode) ? mode[\"direct_only_tool_namespaces\"] : undefined) ?? [];\n if (!Array.isArray(direct)) return [];\n\n const owner = PLUGIN_NAME;\n const bare = \"codex_security\";\n const prefixed = \"mcp__codex_security\";\n let required = [prefixed, bare];\n const overrides: string[] = [];\n const configured = config[\"mcp_servers\"];\n // Native registrations take precedence over the selected plugin's entries.\n const servers: Record<string, unknown> = {\n ...pluginServers,\n ...(isRecord(configured) ? configured : {}),\n };\n const ownerConfig = servers[owner];\n if (!isRecord(ownerConfig) || ownerConfig[\"enabled\"] === false) return [];\n const omitted = ownerConfig[\"omit_tools_from\"];\n if (Array.isArray(omitted) && omitted.includes(\"direct\")) return [];\n // A raw transport or an existing omission leaf can be updated in place.\n // Adding a new registration would shadow a plugin's transport and policy.\n if (\n isRecord(configured) &&\n Object.hasOwn(configured, owner) &&\n (Array.isArray(omitted) ||\n typeof ownerConfig[\"command\"] === \"string\" ||\n typeof ownerConfig[\"url\"] === \"string\")\n ) {\n if (omitted != null && !Array.isArray(omitted)) return [];\n const surfaces = omitted ?? [];\n if (surfaces.includes(\"code_mode\") && surfaces.includes(\"deferred\"))\n return [];\n return [\n `mcp_servers.${owner}.omit_tools_from=${inlineToml([...new Set([...surfaces, \"code_mode\", \"deferred\"])])}`,\n ];\n }\n const option = features[\"non_prefixed_mcp_tool_names\"];\n const enabled =\n option === true || (isRecord(option) && option[\"enabled\"] === true);\n const selected = isRecord(option) ? option[\"server_names\"] : undefined;\n function namespace(server: string): string {\n const name = normalizedServerName(server);\n const omitPrefix =\n enabled && (!Array.isArray(selected) || selected.includes(server));\n return omitPrefix || name.startsWith(\"mcp__\") ? name : `mcp__${name}`;\n }\n const occupied = new Set(\n Object.entries(servers)\n .filter(\n ([server, settings]) =>\n server !== owner &&\n isRecord(settings) &&\n settings[\"enabled\"] !== false &&\n (!Array.isArray(settings[\"enabled_tools\"]) ||\n settings[\"enabled_tools\"].length > 0),\n )\n .map(([server]) => namespace(server)),\n );\n const current = namespace(owner);\n if (occupied.has(current)) {\n const excluded = isRecord(mode) ? mode[\"excluded_tool_namespaces\"] : null;\n const routed = Array.isArray(excluded) ? [...direct, ...excluded] : direct;\n // Moving the owner also renames its peers. Keep names that the caller\n // explicitly routed or excluded from Code Mode.\n if (\n current === bare ||\n occupied.has(bare) ||\n routed.some(\n (name) =>\n name === current ||\n (typeof name === \"string\" &&\n /^mcp__codex_security_[0-9a-f]{12}$/u.test(name)),\n ) ||\n (option != null && !enabled)\n )\n return [];\n overrides.push(\n `features.non_prefixed_mcp_tool_names=${inlineToml({\n enabled: true,\n server_names: [...(Array.isArray(selected) ? selected : []), owner],\n })}`,\n );\n required = [bare];\n } else if (occupied.has(prefixed) || occupied.has(bare)) {\n required = [current];\n }\n if (!required.every((name) => direct.includes(name))) {\n overrides.push(\n `features.code_mode.direct_only_tool_namespaces=${inlineToml([...new Set([...direct, ...required])])}`,\n );\n }\n return overrides;\n}\n\n// The direct coordinator records context but never calls a model itself.\nexport const DIRECT_DEEP_SCAN_CONTROL_USAGE = {\n input_tokens: 0,\n cached_input_tokens: 0,\n cache_write_input_tokens: 0,\n output_tokens: 0,\n} as const;\n\n/** Run the same coordinator as the plugin, without a parent model turn. */\nexport async function* runDeepScan(\n options: DirectDeepScanOptions,\n): AsyncGenerator<{\n type: string;\n [key: string]: unknown;\n}> {\n const native = await import(\n pathToFileURL(\n join(options.pluginRoot, \"mcp\", \"permission-profile-preflight.mjs\"),\n ).href\n );\n const profile = await import(\n pathToFileURL(join(options.pluginRoot, \"scripts\", \"codex_profile.mjs\")).href\n );\n const configured = options.codexOptions;\n const command = options.preflightCommand;\n const environment = bundledCodexSdkEnvironment(command.command, {\n ...configured.env,\n ...(configured.apiKey === undefined\n ? {}\n : { CODEX_API_KEY: configured.apiKey }),\n });\n const session = (await withCodexPreflightLock(\n environment,\n options.signal,\n () =>\n native.prepareCliDeepScanSession({\n codexPath: command.command,\n commandArgs: command.args,\n cwd: options.scanDir,\n env: environment,\n configOverrides: [\n ...profile.profileConfigOverrides(configured.config ?? {}),\n ...(configured.configOverrides ?? []),\n // This session only records native context; workers keep their own snapshot.\n \"features.plugins=false\",\n ],\n signal: options.signal,\n prompt:\n options.prompt +\n \"\\n\\nThe host runs this Deep Scan coordinator directly and owns finalization. This saved request supplies context for later follow-up; do not start a replacement scan.\",\n }),\n )) as {\n threadId: string;\n model: string;\n reasoningEffort?: string;\n permissionProfile: unknown;\n };\n yield { type: \"thread.started\", thread_id: session.threadId };\n options.signal.throwIfAborted();\n const node = process.versions[\"bun\"]\n ? await resolveTrustedExecutable(\"node\", environment, [options.repository])\n : undefined;\n if (node === null)\n throw new CodexSecurityError(\"Node.js is not available on PATH.\");\n const output = await runEngine(\n node?.executable ?? process.execPath,\n [join(options.pluginRoot, \"mcp\", \"server.mjs\"), \"--deep-scan-engine\"],\n node?.environment ?? environment,\n JSON.stringify({\n scanId: options.scanId,\n ...session,\n ...(options.onDiagnostic && { diagnosticsVersion: 1 }),\n }),\n options.signal,\n options.onDiagnostic,\n );\n const completed = JSON.parse(output);\n if (\n completed.scanId !== options.scanId ||\n completed.manifestPath !== join(options.scanDir, \"scan-manifest.json\")\n ) {\n throw new CodexSecurityError(\n \"Deep Scan engine returned results for a different scan.\",\n );\n }\n // The control session makes no model calls. Worker usage is read by the\n // existing scan tracker from the native sessions below this scan directory.\n yield {\n type: \"turn.completed\",\n usage: { ...DIRECT_DEEP_SCAN_CONTROL_USAGE },\n };\n}\n\nfunction runEngine(\n command: string,\n args: string[],\n env: NodeJS.ProcessEnv,\n request: string,\n signal: AbortSignal,\n onDiagnostic: DirectDeepScanOptions[\"onDiagnostic\"],\n): Promise<string> {\n signal.throwIfAborted();\n const child = spawn(executablePathForSpawn(command), args, {\n env,\n windowsHide: true,\n serialization: \"json\",\n stdio: onDiagnostic ? [\"pipe\", \"pipe\", \"pipe\", \"ipc\"] : \"pipe\",\n }) as ChildProcessWithoutNullStreams;\n if (onDiagnostic) {\n child.on(\"message\", (message) => {\n if (!isRecord(message) || typeof message[\"event\"] !== \"string\") return;\n const fields: Record<string, string | number> = {};\n for (const [name, value] of Object.entries(message)) {\n if (\n /^[a-zA-Z][a-zA-Z0-9]*$/u.test(name) &&\n (typeof value === \"number\" || typeof value === \"string\")\n )\n fields[name] = value;\n }\n try {\n void Promise.resolve(onDiagnostic(fields)).catch(() => {});\n } catch {\n // The optional diagnostic sink cannot stop the scan.\n }\n });\n }\n // EOF requests graceful coordinator/worker cleanup on Windows as well as Unix.\n // Keep the control pipe open until completion or explicit cancellation.\n const cancel = () => child.stdin.end();\n let stdout = \"\";\n let stderr = \"\";\n let processError: Error | undefined;\n child.stdout.setEncoding(\"utf8\").on(\"data\", (chunk) => {\n stdout += chunk;\n });\n child.stderr.setEncoding(\"utf8\").on(\"data\", (chunk) => {\n stderr += chunk;\n });\n child.once(\"error\", (error) => {\n processError = error;\n });\n child.stdin.on(\"error\", (error: NodeJS.ErrnoException) => {\n if (!isDisconnectedChildStdin(error)) processError = error;\n });\n const result = new Promise<string>((resolve, reject) => {\n child.once(\"close\", (code) => {\n signal.removeEventListener(\"abort\", cancel);\n if (signal.aborted) reject(signal.reason);\n else if (processError) reject(processError);\n else if (code !== 0)\n reject(\n new CodexSecurityError(\n stderr.trim() || `Deep Scan engine exited with code ${code}.`,\n ),\n );\n else resolve(stdout);\n });\n });\n child.stdin.write(request + \"\\n\");\n signal.addEventListener(\"abort\", cancel, { once: true });\n if (signal.aborted) cancel();\n return result;\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const defaultSeverityRubric = "# Severity guidance\n\nJudge the attacker's actual starting access, the security boundary crossed, and the additional unauthorized harm. Keep confidence separate from severity and identify the missing fact that could change the assessment. Missing proof alone does not establish that a broader attack is impossible; do not invent an attack path or downgrade merely because exploitation was not demonstrated.\n\n## Critical\n\nReserve Critical for consequential, strongly supported compromise meeting all three conditions:\n- Access: an unauthenticated internet attacker, ordinary external user, or publicly admitted untrusted workload can exploit the interface without employee-only access, an invitation, an approved business relationship, or compromise of a trusted supplier.\n- Impact: crossing an important security boundary enables consequential access to protected data, privileged actions, meaningful code execution, workload escape, or comparable compromise of the affected system.\n- Evidence: demonstrated exploitation or strong source-backed validation establishes the complete attack path.\n\nSecond-order attacks can qualify: an external attacker plants data that a trusted user or system later processes, causing consequential unauthorized access or privileged actions.\n\n## High\n\nAssign High when a realistic, evidenced path gives a lower-trust attacker a substantial unauthorized capability they did not already possess. Internal users, partners, invited collaborators, and admitted untrusted workloads can qualify; unauthenticated internet access is not required. Consequences include sensitive customer or business data or reusable credentials, account takeover, meaningful cross-tenant access or actions as another user, control of production workloads or deployments, privileged identities, encryption keys or important isolation boundaries, or significant repeatable disruption of a critical or shared service. A dangerous function, production label, internal access, or the existence of a privileged credential alone is insufficient: identify the lower-trust actor, boundary crossing, and consequential new capability.\n\n## Medium\n\nAssign Medium to a credible vulnerability with concretely bounded impact, such as nonsecret operational information, narrow unauthorized changes, contained disruption of a noncritical service, or isolated development or staging systems without a consequential pivot. A fully demonstrated vulnerability can still be Medium. Base a downgrade on verified constraints, not on an assumption that missing evidence rules out broader harm.\n\n## Low\n\nAssign Low to a supported security weakness with minor additional unauthorized harm and verified limits on its scope, sensitivity, or duration, such as a small information exposure with little security value or a narrowly contained nuisance. Do not use Low as a substitute for uncertainty about a potentially serious path.\n\n## Informational\n\nAssign Informational to a hardening opportunity or observation for which the supplied evidence establishes no additional unauthorized capability or security impact. Explain why it is informational rather than treating missing proof of exploitation as proof of safety. Administrative records that do not describe a security finding may be excluded; exclusion is distinct from severity.\n";
1
+ export declare const defaultSeverityRubric = "# Severity guidance\n\nJudge the attacker's actual starting access, the security boundary crossed, and the additional unauthorized harm. Keep confidence separate from severity and identify the missing fact that could change the assessment. Missing proof alone does not establish that a broader attack is impossible; do not invent an attack path or downgrade merely because exploitation was not demonstrated.\n\n## Critical\n\nReserve Critical for consequential, strongly supported compromise meeting all three conditions:\n\n- **Access.** An unauthenticated internet attacker, ordinary external user, or publicly admitted untrusted workload can exploit the interface without employee-only access, an invitation, an approved business relationship, or compromise of a trusted supplier.\n- **Impact.** Crossing an important security boundary enables consequential access to protected data, privileged actions, meaningful code execution, workload escape, or comparable compromise of the affected system.\n- **Evidence.** Demonstrated exploitation or strong source-backed validation establishes the complete attack path.\n\nSecond-order attacks can qualify: an external attacker plants data that a trusted user or system later processes, causing consequential unauthorized access or privileged actions.\n\n## High\n\nAssign High when the evidence establishes all three conditions:\n\n- **Access.** A lower-trust actor can reach the affected operation. Internal users, partners, invited collaborators, and admitted untrusted workloads can qualify.\n- **Impact.** Crossing the boundary grants a substantial new capability. Examples include access to sensitive customer or business data or reusable credentials, account takeover, meaningful cross-tenant access or actions as another user, control of production workloads or deployments, privileged identities, encryption keys or important isolation boundaries, and significant repeatable disruption of a critical or shared service.\n- **Evidence.** Identify a realistic path from the actor's existing access to the new capability. A dangerous function, production label, internal access, or privileged credential alone leaves that path unproven.\n\n## Medium\n\nAssign Medium to a credible vulnerability with concretely bounded impact, such as nonsecret operational information, narrow unauthorized changes, contained disruption of a noncritical service, or isolated development or staging systems without a consequential pivot. A fully demonstrated vulnerability can still be Medium. Base a downgrade on verified constraints, not on an assumption that missing evidence rules out broader harm.\n\n## Low\n\nAssign Low to a supported security weakness with minor additional unauthorized harm and verified limits on its scope, sensitivity, or duration, such as a small information exposure with little security value or a narrowly contained nuisance. Do not use Low as a substitute for uncertainty about a potentially serious path.\n\n## Informational\n\nAssign Informational to a hardening opportunity or observation for which the supplied evidence establishes no additional unauthorized capability or security impact. Explain why it is informational rather than treating missing proof of exploitation as proof of safety. Administrative records that do not describe a security finding may be excluded; exclusion is distinct from severity.\n";
2
2
  //# sourceMappingURL=default-severity-rubric.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"default-severity-rubric.d.ts","sourceRoot":"","sources":["../src/default-severity-rubric.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,qBAAqB,8wGAC2uG,CAAC"}
1
+ {"version":3,"file":"default-severity-rubric.d.ts","sourceRoot":"","sources":["../src/default-severity-rubric.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,qBAAqB,0zGACuxG,CAAC"}
@@ -1,3 +1,3 @@
1
1
  // Generated from the plugin references/default-severity-rubric.md. Run pnpm build.
2
- export const defaultSeverityRubric = "# Severity guidance\n\nJudge the attacker's actual starting access, the security boundary crossed, and the additional unauthorized harm. Keep confidence separate from severity and identify the missing fact that could change the assessment. Missing proof alone does not establish that a broader attack is impossible; do not invent an attack path or downgrade merely because exploitation was not demonstrated.\n\n## Critical\n\nReserve Critical for consequential, strongly supported compromise meeting all three conditions:\n- Access: an unauthenticated internet attacker, ordinary external user, or publicly admitted untrusted workload can exploit the interface without employee-only access, an invitation, an approved business relationship, or compromise of a trusted supplier.\n- Impact: crossing an important security boundary enables consequential access to protected data, privileged actions, meaningful code execution, workload escape, or comparable compromise of the affected system.\n- Evidence: demonstrated exploitation or strong source-backed validation establishes the complete attack path.\n\nSecond-order attacks can qualify: an external attacker plants data that a trusted user or system later processes, causing consequential unauthorized access or privileged actions.\n\n## High\n\nAssign High when a realistic, evidenced path gives a lower-trust attacker a substantial unauthorized capability they did not already possess. Internal users, partners, invited collaborators, and admitted untrusted workloads can qualify; unauthenticated internet access is not required. Consequences include sensitive customer or business data or reusable credentials, account takeover, meaningful cross-tenant access or actions as another user, control of production workloads or deployments, privileged identities, encryption keys or important isolation boundaries, or significant repeatable disruption of a critical or shared service. A dangerous function, production label, internal access, or the existence of a privileged credential alone is insufficient: identify the lower-trust actor, boundary crossing, and consequential new capability.\n\n## Medium\n\nAssign Medium to a credible vulnerability with concretely bounded impact, such as nonsecret operational information, narrow unauthorized changes, contained disruption of a noncritical service, or isolated development or staging systems without a consequential pivot. A fully demonstrated vulnerability can still be Medium. Base a downgrade on verified constraints, not on an assumption that missing evidence rules out broader harm.\n\n## Low\n\nAssign Low to a supported security weakness with minor additional unauthorized harm and verified limits on its scope, sensitivity, or duration, such as a small information exposure with little security value or a narrowly contained nuisance. Do not use Low as a substitute for uncertainty about a potentially serious path.\n\n## Informational\n\nAssign Informational to a hardening opportunity or observation for which the supplied evidence establishes no additional unauthorized capability or security impact. Explain why it is informational rather than treating missing proof of exploitation as proof of safety. Administrative records that do not describe a security finding may be excluded; exclusion is distinct from severity.\n";
2
+ export const defaultSeverityRubric = "# Severity guidance\n\nJudge the attacker's actual starting access, the security boundary crossed, and the additional unauthorized harm. Keep confidence separate from severity and identify the missing fact that could change the assessment. Missing proof alone does not establish that a broader attack is impossible; do not invent an attack path or downgrade merely because exploitation was not demonstrated.\n\n## Critical\n\nReserve Critical for consequential, strongly supported compromise meeting all three conditions:\n\n- **Access.** An unauthenticated internet attacker, ordinary external user, or publicly admitted untrusted workload can exploit the interface without employee-only access, an invitation, an approved business relationship, or compromise of a trusted supplier.\n- **Impact.** Crossing an important security boundary enables consequential access to protected data, privileged actions, meaningful code execution, workload escape, or comparable compromise of the affected system.\n- **Evidence.** Demonstrated exploitation or strong source-backed validation establishes the complete attack path.\n\nSecond-order attacks can qualify: an external attacker plants data that a trusted user or system later processes, causing consequential unauthorized access or privileged actions.\n\n## High\n\nAssign High when the evidence establishes all three conditions:\n\n- **Access.** A lower-trust actor can reach the affected operation. Internal users, partners, invited collaborators, and admitted untrusted workloads can qualify.\n- **Impact.** Crossing the boundary grants a substantial new capability. Examples include access to sensitive customer or business data or reusable credentials, account takeover, meaningful cross-tenant access or actions as another user, control of production workloads or deployments, privileged identities, encryption keys or important isolation boundaries, and significant repeatable disruption of a critical or shared service.\n- **Evidence.** Identify a realistic path from the actor's existing access to the new capability. A dangerous function, production label, internal access, or privileged credential alone leaves that path unproven.\n\n## Medium\n\nAssign Medium to a credible vulnerability with concretely bounded impact, such as nonsecret operational information, narrow unauthorized changes, contained disruption of a noncritical service, or isolated development or staging systems without a consequential pivot. A fully demonstrated vulnerability can still be Medium. Base a downgrade on verified constraints, not on an assumption that missing evidence rules out broader harm.\n\n## Low\n\nAssign Low to a supported security weakness with minor additional unauthorized harm and verified limits on its scope, sensitivity, or duration, such as a small information exposure with little security value or a narrowly contained nuisance. Do not use Low as a substitute for uncertainty about a potentially serious path.\n\n## Informational\n\nAssign Informational to a hardening opportunity or observation for which the supplied evidence establishes no additional unauthorized capability or security impact. Explain why it is informational rather than treating missing proof of exploitation as proof of safety. Administrative records that do not describe a security finding may be excluded; exclusion is distinct from severity.\n";
3
3
  //# sourceMappingURL=default-severity-rubric.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"default-severity-rubric.js","sourceRoot":"","sources":["../src/default-severity-rubric.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,CAAC,MAAM,qBAAqB,GAChC,2wGAA2wG,CAAC","sourcesContent":["// Generated from the plugin references/default-severity-rubric.md. Run pnpm build.\nexport const defaultSeverityRubric =\n \"# Severity guidance\\n\\nJudge the attacker's actual starting access, the security boundary crossed, and the additional unauthorized harm. Keep confidence separate from severity and identify the missing fact that could change the assessment. Missing proof alone does not establish that a broader attack is impossible; do not invent an attack path or downgrade merely because exploitation was not demonstrated.\\n\\n## Critical\\n\\nReserve Critical for consequential, strongly supported compromise meeting all three conditions:\\n- Access: an unauthenticated internet attacker, ordinary external user, or publicly admitted untrusted workload can exploit the interface without employee-only access, an invitation, an approved business relationship, or compromise of a trusted supplier.\\n- Impact: crossing an important security boundary enables consequential access to protected data, privileged actions, meaningful code execution, workload escape, or comparable compromise of the affected system.\\n- Evidence: demonstrated exploitation or strong source-backed validation establishes the complete attack path.\\n\\nSecond-order attacks can qualify: an external attacker plants data that a trusted user or system later processes, causing consequential unauthorized access or privileged actions.\\n\\n## High\\n\\nAssign High when a realistic, evidenced path gives a lower-trust attacker a substantial unauthorized capability they did not already possess. Internal users, partners, invited collaborators, and admitted untrusted workloads can qualify; unauthenticated internet access is not required. Consequences include sensitive customer or business data or reusable credentials, account takeover, meaningful cross-tenant access or actions as another user, control of production workloads or deployments, privileged identities, encryption keys or important isolation boundaries, or significant repeatable disruption of a critical or shared service. A dangerous function, production label, internal access, or the existence of a privileged credential alone is insufficient: identify the lower-trust actor, boundary crossing, and consequential new capability.\\n\\n## Medium\\n\\nAssign Medium to a credible vulnerability with concretely bounded impact, such as nonsecret operational information, narrow unauthorized changes, contained disruption of a noncritical service, or isolated development or staging systems without a consequential pivot. A fully demonstrated vulnerability can still be Medium. Base a downgrade on verified constraints, not on an assumption that missing evidence rules out broader harm.\\n\\n## Low\\n\\nAssign Low to a supported security weakness with minor additional unauthorized harm and verified limits on its scope, sensitivity, or duration, such as a small information exposure with little security value or a narrowly contained nuisance. Do not use Low as a substitute for uncertainty about a potentially serious path.\\n\\n## Informational\\n\\nAssign Informational to a hardening opportunity or observation for which the supplied evidence establishes no additional unauthorized capability or security impact. Explain why it is informational rather than treating missing proof of exploitation as proof of safety. Administrative records that do not describe a security finding may be excluded; exclusion is distinct from severity.\\n\";\n"]}
1
+ {"version":3,"file":"default-severity-rubric.js","sourceRoot":"","sources":["../src/default-severity-rubric.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,CAAC,MAAM,qBAAqB,GAChC,uzGAAuzG,CAAC","sourcesContent":["// Generated from the plugin references/default-severity-rubric.md. Run pnpm build.\nexport const defaultSeverityRubric =\n \"# Severity guidance\\n\\nJudge the attacker's actual starting access, the security boundary crossed, and the additional unauthorized harm. Keep confidence separate from severity and identify the missing fact that could change the assessment. Missing proof alone does not establish that a broader attack is impossible; do not invent an attack path or downgrade merely because exploitation was not demonstrated.\\n\\n## Critical\\n\\nReserve Critical for consequential, strongly supported compromise meeting all three conditions:\\n\\n- **Access.** An unauthenticated internet attacker, ordinary external user, or publicly admitted untrusted workload can exploit the interface without employee-only access, an invitation, an approved business relationship, or compromise of a trusted supplier.\\n- **Impact.** Crossing an important security boundary enables consequential access to protected data, privileged actions, meaningful code execution, workload escape, or comparable compromise of the affected system.\\n- **Evidence.** Demonstrated exploitation or strong source-backed validation establishes the complete attack path.\\n\\nSecond-order attacks can qualify: an external attacker plants data that a trusted user or system later processes, causing consequential unauthorized access or privileged actions.\\n\\n## High\\n\\nAssign High when the evidence establishes all three conditions:\\n\\n- **Access.** A lower-trust actor can reach the affected operation. Internal users, partners, invited collaborators, and admitted untrusted workloads can qualify.\\n- **Impact.** Crossing the boundary grants a substantial new capability. Examples include access to sensitive customer or business data or reusable credentials, account takeover, meaningful cross-tenant access or actions as another user, control of production workloads or deployments, privileged identities, encryption keys or important isolation boundaries, and significant repeatable disruption of a critical or shared service.\\n- **Evidence.** Identify a realistic path from the actor's existing access to the new capability. A dangerous function, production label, internal access, or privileged credential alone leaves that path unproven.\\n\\n## Medium\\n\\nAssign Medium to a credible vulnerability with concretely bounded impact, such as nonsecret operational information, narrow unauthorized changes, contained disruption of a noncritical service, or isolated development or staging systems without a consequential pivot. A fully demonstrated vulnerability can still be Medium. Base a downgrade on verified constraints, not on an assumption that missing evidence rules out broader harm.\\n\\n## Low\\n\\nAssign Low to a supported security weakness with minor additional unauthorized harm and verified limits on its scope, sensitivity, or duration, such as a small information exposure with little security value or a narrowly contained nuisance. Do not use Low as a substitute for uncertainty about a potentially serious path.\\n\\n## Informational\\n\\nAssign Informational to a hardening opportunity or observation for which the supplied evidence establishes no additional unauthorized capability or security impact. Explain why it is informational rather than treating missing proof of exploitation as proof of safety. Administrative records that do not describe a security finding may be excluded; exclusion is distinct from severity.\\n\";\n"]}
@@ -1,7 +1,9 @@
1
- import type { ExternalImportTarget } from "./external-import-contract.js";
1
+ import { type ExternalImportTarget } from "./external-import-contract.js";
2
2
  import type { ExternalFindings } from "./external-findings.js";
3
3
  /** Saved Endor Finding objects, an array, or an unmasked ListFindingsResponse. */
4
4
  export declare function normalizeEndorFindings(input: unknown, target?: ExternalImportTarget): ExternalFindings;
5
+ /** A native upload would ask the worker to reconstruct fields that Cloud could not accept. */
6
+ export declare function requiresStructuredEndorReport(findings: ExternalFindings): boolean;
5
7
  /** Endor's documented SARIF producer uses properties.finding-uuid, not its rule name. */
6
8
  export declare function normalizeEndorSarif(input: unknown, target?: ExternalImportTarget): ExternalFindings;
7
9
  export declare function readEndorFindings(path: string, target?: ExternalImportTarget): Promise<ExternalFindings>;
@@ -1 +1 @@
1
- {"version":3,"file":"endor-findings.d.ts","sourceRoot":"","sources":["../src/endor-findings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAE1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAgC/D,kFAAkF;AAClF,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,oBAA8B,GACrC,gBAAgB,CA8IlB;AAED,yFAAyF;AACzF,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,oBAA8B,GACrC,gBAAgB,CAsHlB;AAED,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,oBAA8B,GACrC,OAAO,CAAC,gBAAgB,CAAC,CAE3B"}
1
+ {"version":3,"file":"endor-findings.d.ts","sourceRoot":"","sources":["../src/endor-findings.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAiG/D,kFAAkF;AAClF,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,oBAA8B,GACrC,gBAAgB,CAElB;AAID,8FAA8F;AAC9F,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,gBAAgB,WAEvE;AA6KD,yFAAyF;AACzF,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,oBAA8B,GACrC,gBAAgB,CA4GlB;AAED,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,oBAA8B,GACrC,OAAO,CAAC,gBAAgB,CAAC,CAE3B"}