@openai/codex-security 0.9.1 → 0.10.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 (444) hide show
  1. package/README.md +37 -788
  2. package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
  3. package/_bundled_plugin/.mcp.json +3 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
  5. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  6. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  7. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  12. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  13. package/_bundled_plugin/mcp/server.mjs.br +0 -0
  14. package/_bundled_plugin/references/access-advisory.md +1 -1
  15. package/_bundled_plugin/references/artifact-storage.md +1 -1
  16. package/_bundled_plugin/references/baseline-auditor.md +18 -0
  17. package/_bundled_plugin/references/core-scan.md +5 -42
  18. package/_bundled_plugin/references/final-report.md +1 -1
  19. package/_bundled_plugin/references/focused-investigator.md +13 -0
  20. package/_bundled_plugin/references/scan-prologue.md +2 -2
  21. package/_bundled_plugin/references/scan-runtime.md +4 -2
  22. package/_bundled_plugin/references/security-guidance.md +14 -1
  23. package/_bundled_plugin/references/threat-model.md +1 -0
  24. package/_bundled_plugin/references/validate-scan-findings.md +3 -0
  25. package/_bundled_plugin/scripts/deep_scan_workbench.py +30 -12
  26. package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
  27. package/_bundled_plugin/scripts/finalize_scan_contract.py +47 -9
  28. package/_bundled_plugin/scripts/launch_codex_security_mcp +54 -16
  29. package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +2 -0
  30. package/_bundled_plugin/scripts/posix_scan_local_files.py +26 -1
  31. package/_bundled_plugin/scripts/snapshot_sqlite.py +8 -2
  32. package/_bundled_plugin/scripts/windows_scan_local_files.py +216 -25
  33. package/_bundled_plugin/scripts/workbench/handoff.py +55 -25
  34. package/_bundled_plugin/scripts/workbench/storage.py +25 -5
  35. package/_bundled_plugin/scripts/workbench_cli.py +24 -2
  36. package/_bundled_plugin/scripts/workbench_constants.py +2 -0
  37. package/_bundled_plugin/scripts/workbench_db.py +257 -268
  38. package/_bundled_plugin/scripts/workbench_feedback.py +49 -4
  39. package/_bundled_plugin/scripts/workbench_native_indexes.py +226 -29
  40. package/_bundled_plugin/scripts/workbench_progress.py +159 -3
  41. package/_bundled_plugin/scripts/workbench_publication.py +2 -3
  42. package/_bundled_plugin/scripts/workbench_remediation.py +142 -2
  43. package/_bundled_plugin/scripts/workbench_saved_results.py +48 -8
  44. package/_bundled_plugin/scripts/workbench_scan_history.py +291 -134
  45. package/_bundled_plugin/scripts/workbench_scan_start.py +208 -11
  46. package/_bundled_plugin/scripts/workbench_scan_usage.py +36 -10
  47. package/_bundled_plugin/scripts/workbench_schema.py +220 -14
  48. package/_bundled_plugin/scripts/workbench_setup.py +1 -1
  49. package/_bundled_plugin/scripts/workbench_source_scopes.py +8 -0
  50. package/_bundled_plugin/scripts/workbench_target.py +486 -85
  51. package/_bundled_plugin/scripts/workbench_target_state.py +1108 -22
  52. package/_bundled_plugin/shared/workbench-history-repairs.json +64 -14
  53. package/_bundled_plugin/shared/workbench-migrations.json +66 -0
  54. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +4 -2
  55. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +2 -2
  56. package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -0
  57. package/_bundled_plugin/skills/publish-findings/SKILL.md +26 -160
  58. package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
  59. package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +2 -2
  60. package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +3 -58
  61. package/_bundled_plugin/skills/publish-findings/scripts/collector_paths.py +63 -0
  62. package/_bundled_plugin/skills/security-scan/SKILL.md +9 -46
  63. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +2 -2
  64. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -21
  65. package/_bundled_plugin/skills/security-scan/references/managed-scan.md +11 -0
  66. package/_bundled_plugin/skills/security-scan/references/scan-results.md +15 -0
  67. package/_bundled_plugin/skills/security-scan/references/scoped-paths.md +23 -0
  68. package/_bundled_plugin/skills/security-scan/references/sdk-files.md +24 -0
  69. package/bin/codex-security.mjs +2 -2
  70. package/dist/api.d.ts +7 -1
  71. package/dist/api.d.ts.map +1 -1
  72. package/dist/api.js +459 -157
  73. package/dist/api.js.map +1 -1
  74. package/dist/armorcode-findings.d.ts +9 -0
  75. package/dist/armorcode-findings.d.ts.map +1 -0
  76. package/dist/armorcode-findings.js +145 -0
  77. package/dist/armorcode-findings.js.map +1 -0
  78. package/dist/artifact-export.d.ts +2 -0
  79. package/dist/artifact-export.d.ts.map +1 -1
  80. package/dist/artifact-export.js +29 -13
  81. package/dist/artifact-export.js.map +1 -1
  82. package/dist/auth.d.ts +6 -2
  83. package/dist/auth.d.ts.map +1 -1
  84. package/dist/auth.js +33 -12
  85. package/dist/auth.js.map +1 -1
  86. package/dist/batch-cost.d.ts +18 -0
  87. package/dist/batch-cost.d.ts.map +1 -0
  88. package/dist/batch-cost.js +41 -0
  89. package/dist/batch-cost.js.map +1 -0
  90. package/dist/blackduck-findings.d.ts +1 -1
  91. package/dist/blackduck-findings.d.ts.map +1 -1
  92. package/dist/blackduck-findings.js +5 -18
  93. package/dist/blackduck-findings.js.map +1 -1
  94. package/dist/bundled-plugin.d.ts +4 -0
  95. package/dist/bundled-plugin.d.ts.map +1 -0
  96. package/dist/bundled-plugin.js +23 -0
  97. package/dist/bundled-plugin.js.map +1 -0
  98. package/dist/classify-scan-severity.d.ts +1 -1
  99. package/dist/classify-scan-severity.d.ts.map +1 -1
  100. package/dist/classify-scan-severity.js +11 -3
  101. package/dist/classify-scan-severity.js.map +1 -1
  102. package/dist/classify-severity-diagnostics.d.ts +10 -0
  103. package/dist/classify-severity-diagnostics.d.ts.map +1 -0
  104. package/dist/classify-severity-diagnostics.js +57 -0
  105. package/dist/classify-severity-diagnostics.js.map +1 -0
  106. package/dist/classify-severity-records.d.ts +4 -0
  107. package/dist/classify-severity-records.d.ts.map +1 -1
  108. package/dist/classify-severity-records.js +35 -8
  109. package/dist/classify-severity-records.js.map +1 -1
  110. package/dist/classify-severity.d.ts.map +1 -1
  111. package/dist/classify-severity.js +9 -6
  112. package/dist/classify-severity.js.map +1 -1
  113. package/dist/cli-argument.d.ts +4 -0
  114. package/dist/cli-argument.d.ts.map +1 -0
  115. package/dist/cli-argument.js +17 -0
  116. package/dist/cli-argument.js.map +1 -0
  117. package/dist/cli-help.d.ts +1 -1
  118. package/dist/cli-help.d.ts.map +1 -1
  119. package/dist/cli-help.js +71 -29
  120. package/dist/cli-help.js.map +1 -1
  121. package/dist/cli-hook.d.ts +3 -0
  122. package/dist/cli-hook.d.ts.map +1 -0
  123. package/dist/cli-hook.js +87 -0
  124. package/dist/cli-hook.js.map +1 -0
  125. package/dist/cli-integrations.d.ts +13 -0
  126. package/dist/cli-integrations.d.ts.map +1 -0
  127. package/dist/cli-integrations.js +333 -0
  128. package/dist/cli-integrations.js.map +1 -0
  129. package/dist/cli-mcp.d.ts +15 -0
  130. package/dist/cli-mcp.d.ts.map +1 -0
  131. package/dist/cli-mcp.js +178 -0
  132. package/dist/cli-mcp.js.map +1 -0
  133. package/dist/cli-token-view.d.ts +10 -0
  134. package/dist/cli-token-view.d.ts.map +1 -0
  135. package/dist/cli-token-view.js +41 -0
  136. package/dist/cli-token-view.js.map +1 -0
  137. package/dist/cli.d.ts +8 -3
  138. package/dist/cli.d.ts.map +1 -1
  139. package/dist/cli.js +1860 -903
  140. package/dist/cli.js.map +1 -1
  141. package/dist/cloud-publish.d.ts.map +1 -1
  142. package/dist/cloud-publish.js +33 -31
  143. package/dist/cloud-publish.js.map +1 -1
  144. package/dist/codex-sdk-environment.d.ts +6 -0
  145. package/dist/codex-sdk-environment.d.ts.map +1 -1
  146. package/dist/codex-sdk-environment.js +19 -0
  147. package/dist/codex-sdk-environment.js.map +1 -1
  148. package/dist/command-words.d.ts +3 -0
  149. package/dist/command-words.d.ts.map +1 -0
  150. package/dist/command-words.js +46 -0
  151. package/dist/command-words.js.map +1 -0
  152. package/dist/component-plan.d.ts.map +1 -1
  153. package/dist/component-plan.js +3 -3
  154. package/dist/component-plan.js.map +1 -1
  155. package/dist/component-scan.d.ts +3 -1
  156. package/dist/component-scan.d.ts.map +1 -1
  157. package/dist/component-scan.js +40 -7
  158. package/dist/component-scan.js.map +1 -1
  159. package/dist/config.d.ts +1 -1
  160. package/dist/config.d.ts.map +1 -1
  161. package/dist/config.js +30 -1
  162. package/dist/config.js.map +1 -1
  163. package/dist/continuum-aws.d.ts +6 -0
  164. package/dist/continuum-aws.d.ts.map +1 -0
  165. package/dist/continuum-aws.js +202 -0
  166. package/dist/continuum-aws.js.map +1 -0
  167. package/dist/continuum-collector.d.ts +44 -0
  168. package/dist/continuum-collector.d.ts.map +1 -0
  169. package/dist/continuum-collector.js +266 -0
  170. package/dist/continuum-collector.js.map +1 -0
  171. package/dist/continuum-findings.d.ts +31 -2
  172. package/dist/continuum-findings.d.ts.map +1 -1
  173. package/dist/continuum-findings.js +497 -59
  174. package/dist/continuum-findings.js.map +1 -1
  175. package/dist/contract.d.ts +1 -0
  176. package/dist/contract.d.ts.map +1 -1
  177. package/dist/contract.js +3 -0
  178. package/dist/contract.js.map +1 -1
  179. package/dist/cost.d.ts.map +1 -1
  180. package/dist/cost.js +1 -45
  181. package/dist/cost.js.map +1 -1
  182. package/dist/crowdstrike-findings.d.ts +7 -0
  183. package/dist/crowdstrike-findings.d.ts.map +1 -0
  184. package/dist/crowdstrike-findings.js +210 -0
  185. package/dist/crowdstrike-findings.js.map +1 -0
  186. package/dist/custom-validation-prompt.d.ts +1 -1
  187. package/dist/custom-validation-prompt.d.ts.map +1 -1
  188. package/dist/custom-validation-prompt.js +29 -19
  189. package/dist/custom-validation-prompt.js.map +1 -1
  190. package/dist/deduplication/local.d.ts +3 -1
  191. package/dist/deduplication/local.d.ts.map +1 -1
  192. package/dist/deduplication/local.js +8 -1
  193. package/dist/deduplication/local.js.map +1 -1
  194. package/dist/deduplication/refusal.d.ts.map +1 -1
  195. package/dist/deduplication/refusal.js +2 -1
  196. package/dist/deduplication/refusal.js.map +1 -1
  197. package/dist/deduplication/scan.d.ts +2 -0
  198. package/dist/deduplication/scan.d.ts.map +1 -1
  199. package/dist/deduplication/scan.js +24 -7
  200. package/dist/deduplication/scan.js.map +1 -1
  201. package/dist/deep-scan.d.ts.map +1 -1
  202. package/dist/deep-scan.js +16 -15
  203. package/dist/deep-scan.js.map +1 -1
  204. package/dist/endor-findings.d.ts +2 -2
  205. package/dist/endor-findings.d.ts.map +1 -1
  206. package/dist/endor-findings.js +6 -23
  207. package/dist/endor-findings.js.map +1 -1
  208. package/dist/errors.d.ts +3 -1
  209. package/dist/errors.d.ts.map +1 -1
  210. package/dist/errors.js +7 -3
  211. package/dist/errors.js.map +1 -1
  212. package/dist/executable-path.d.ts +3 -0
  213. package/dist/executable-path.d.ts.map +1 -1
  214. package/dist/executable-path.js +26 -0
  215. package/dist/executable-path.js.map +1 -1
  216. package/dist/external-findings-import.d.ts.map +1 -1
  217. package/dist/external-findings-import.js +12 -1
  218. package/dist/external-findings-import.js.map +1 -1
  219. package/dist/external-findings-local.d.ts +66 -4
  220. package/dist/external-findings-local.d.ts.map +1 -1
  221. package/dist/external-findings-local.js +258 -59
  222. package/dist/external-findings-local.js.map +1 -1
  223. package/dist/external-findings-publish.d.ts +6 -1
  224. package/dist/external-findings-publish.d.ts.map +1 -1
  225. package/dist/external-findings-publish.js +330 -1633
  226. package/dist/external-findings-publish.js.map +1 -1
  227. package/dist/external-findings-read.d.ts +11 -2
  228. package/dist/external-findings-read.d.ts.map +1 -1
  229. package/dist/external-findings-read.js +56 -53
  230. package/dist/external-findings-read.js.map +1 -1
  231. package/dist/external-findings.d.ts +1 -1
  232. package/dist/external-findings.d.ts.map +1 -1
  233. package/dist/external-findings.js +12 -1
  234. package/dist/external-findings.js.map +1 -1
  235. package/dist/external-import-contract.d.ts +6 -11
  236. package/dist/external-import-contract.d.ts.map +1 -1
  237. package/dist/external-import-contract.js +35 -177
  238. package/dist/external-import-contract.js.map +1 -1
  239. package/dist/external-import-models.d.ts +1 -1
  240. package/dist/external-import-models.d.ts.map +1 -1
  241. package/dist/external-import-models.js.map +1 -1
  242. package/dist/finding-prompt.d.ts.map +1 -1
  243. package/dist/finding-prompt.js +2 -2
  244. package/dist/finding-prompt.js.map +1 -1
  245. package/dist/github-dependabot-findings.d.ts.map +1 -1
  246. package/dist/github-dependabot-findings.js +3 -4
  247. package/dist/github-dependabot-findings.js.map +1 -1
  248. package/dist/github-findings.d.ts.map +1 -1
  249. package/dist/github-findings.js +19 -287
  250. package/dist/github-findings.js.map +1 -1
  251. package/dist/host-protocol.d.ts +6 -0
  252. package/dist/host-protocol.d.ts.map +1 -1
  253. package/dist/host-protocol.js +11 -1
  254. package/dist/host-protocol.js.map +1 -1
  255. package/dist/host-records-protocol.d.ts +2 -0
  256. package/dist/host-records-protocol.d.ts.map +1 -1
  257. package/dist/host-records-protocol.js +4 -0
  258. package/dist/host-records-protocol.js.map +1 -1
  259. package/dist/hosted-remediation.d.ts +1 -0
  260. package/dist/hosted-remediation.d.ts.map +1 -1
  261. package/dist/hosted-remediation.js +23 -3
  262. package/dist/hosted-remediation.js.map +1 -1
  263. package/dist/index.d.ts +5 -3
  264. package/dist/index.d.ts.map +1 -1
  265. package/dist/index.js +3 -1
  266. package/dist/index.js.map +1 -1
  267. package/dist/inspector-findings.d.ts.map +1 -1
  268. package/dist/inspector-findings.js +19 -35
  269. package/dist/inspector-findings.js.map +1 -1
  270. package/dist/knowledge-base.d.ts +1 -1
  271. package/dist/knowledge-base.d.ts.map +1 -1
  272. package/dist/knowledge-base.js +34 -27
  273. package/dist/knowledge-base.js.map +1 -1
  274. package/dist/linear.d.ts +11 -0
  275. package/dist/linear.d.ts.map +1 -1
  276. package/dist/linear.js.map +1 -1
  277. package/dist/local-git-metadata.d.ts +5 -2
  278. package/dist/local-git-metadata.d.ts.map +1 -1
  279. package/dist/local-git-metadata.js +8 -4
  280. package/dist/local-git-metadata.js.map +1 -1
  281. package/dist/multiscan.d.ts +4 -0
  282. package/dist/multiscan.d.ts.map +1 -1
  283. package/dist/multiscan.js +83 -39
  284. package/dist/multiscan.js.map +1 -1
  285. package/dist/opengrep-findings.d.ts +4 -2
  286. package/dist/opengrep-findings.d.ts.map +1 -1
  287. package/dist/opengrep-findings.js +39 -22
  288. package/dist/opengrep-findings.js.map +1 -1
  289. package/dist/private-finding-import.d.ts +8 -13
  290. package/dist/private-finding-import.d.ts.map +1 -1
  291. package/dist/private-finding-import.js +69 -129
  292. package/dist/private-finding-import.js.map +1 -1
  293. package/dist/project-config-schema.d.ts +2 -0
  294. package/dist/project-config-schema.d.ts.map +1 -1
  295. package/dist/project-config-schema.js +1 -0
  296. package/dist/project-config-schema.js.map +1 -1
  297. package/dist/project-config.d.ts +1 -0
  298. package/dist/project-config.d.ts.map +1 -1
  299. package/dist/project-config.js +56 -13
  300. package/dist/project-config.js.map +1 -1
  301. package/dist/prompt-files.d.ts +7 -2
  302. package/dist/prompt-files.d.ts.map +1 -1
  303. package/dist/prompt-files.js +42 -20
  304. package/dist/prompt-files.js.map +1 -1
  305. package/dist/provider-profile.d.ts.map +1 -1
  306. package/dist/provider-profile.js +4 -9
  307. package/dist/provider-profile.js.map +1 -1
  308. package/dist/publication.d.ts +1 -1
  309. package/dist/publication.d.ts.map +1 -1
  310. package/dist/publication.js.map +1 -1
  311. package/dist/record.d.ts +1 -5
  312. package/dist/record.d.ts.map +1 -1
  313. package/dist/record.js +3 -51
  314. package/dist/record.js.map +1 -1
  315. package/dist/remediation.d.ts.map +1 -1
  316. package/dist/remediation.js +3 -1
  317. package/dist/remediation.js.map +1 -1
  318. package/dist/runtime.d.ts +35 -7
  319. package/dist/runtime.d.ts.map +1 -1
  320. package/dist/runtime.js +782 -153
  321. package/dist/runtime.js.map +1 -1
  322. package/dist/saved-scan-bootstrap.d.ts +6 -1
  323. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  324. package/dist/saved-scan-bootstrap.js +267 -115
  325. package/dist/saved-scan-bootstrap.js.map +1 -1
  326. package/dist/scan-archive-path.d.ts +2 -0
  327. package/dist/scan-archive-path.d.ts.map +1 -0
  328. package/dist/scan-archive-path.js +5 -0
  329. package/dist/scan-archive-path.js.map +1 -0
  330. package/dist/scan-comparison.d.ts +20 -2
  331. package/dist/scan-comparison.d.ts.map +1 -1
  332. package/dist/scan-comparison.js +26 -5
  333. package/dist/scan-comparison.js.map +1 -1
  334. package/dist/scan-dashboard.d.ts +1 -0
  335. package/dist/scan-dashboard.d.ts.map +1 -1
  336. package/dist/scan-dashboard.js +18 -2
  337. package/dist/scan-dashboard.js.map +1 -1
  338. package/dist/scan-executor.d.ts.map +1 -1
  339. package/dist/scan-executor.js +4 -2
  340. package/dist/scan-executor.js.map +1 -1
  341. package/dist/scan-history-renderer.d.ts +1 -0
  342. package/dist/scan-history-renderer.d.ts.map +1 -1
  343. package/dist/scan-history-renderer.js +25 -9
  344. package/dist/scan-history-renderer.js.map +1 -1
  345. package/dist/scan-logs.d.ts.map +1 -1
  346. package/dist/scan-logs.js +28 -4
  347. package/dist/scan-logs.js.map +1 -1
  348. package/dist/scan-settings.d.ts +1 -0
  349. package/dist/scan-settings.d.ts.map +1 -1
  350. package/dist/scan-settings.js +1 -0
  351. package/dist/scan-settings.js.map +1 -1
  352. package/dist/scanner-import.d.ts +5 -11
  353. package/dist/scanner-import.d.ts.map +1 -1
  354. package/dist/scanner-import.js +16 -89
  355. package/dist/scanner-import.js.map +1 -1
  356. package/dist/security-policy.d.ts.map +1 -1
  357. package/dist/security-policy.js +26 -6
  358. package/dist/security-policy.js.map +1 -1
  359. package/dist/semgrep-findings.d.ts.map +1 -1
  360. package/dist/semgrep-findings.js +14 -48
  361. package/dist/semgrep-findings.js.map +1 -1
  362. package/dist/semgrep-platform-findings.d.ts +20 -70
  363. package/dist/semgrep-platform-findings.d.ts.map +1 -1
  364. package/dist/semgrep-platform-findings.js +116 -333
  365. package/dist/semgrep-platform-findings.js.map +1 -1
  366. package/dist/severity-review.d.ts.map +1 -1
  367. package/dist/severity-review.js +1 -0
  368. package/dist/severity-review.js.map +1 -1
  369. package/dist/snyk-findings.d.ts +2 -0
  370. package/dist/snyk-findings.d.ts.map +1 -1
  371. package/dist/snyk-findings.js +5 -8
  372. package/dist/snyk-findings.js.map +1 -1
  373. package/dist/snyk-rest-findings.d.ts +3 -20
  374. package/dist/snyk-rest-findings.d.ts.map +1 -1
  375. package/dist/snyk-rest-findings.js +45 -217
  376. package/dist/snyk-rest-findings.js.map +1 -1
  377. package/dist/sonar-findings.d.ts +1 -1
  378. package/dist/sonar-findings.d.ts.map +1 -1
  379. package/dist/sonar-findings.js +2 -4
  380. package/dist/sonar-findings.js.map +1 -1
  381. package/dist/sonar-import.d.ts +3 -0
  382. package/dist/sonar-import.d.ts.map +1 -1
  383. package/dist/sonar-import.js +28 -30
  384. package/dist/sonar-import.js.map +1 -1
  385. package/dist/stored-finding-projection.d.ts +6 -0
  386. package/dist/stored-finding-projection.d.ts.map +1 -0
  387. package/dist/stored-finding-projection.js +129 -0
  388. package/dist/stored-finding-projection.js.map +1 -0
  389. package/dist/stored-findings-publication.d.ts +23 -0
  390. package/dist/stored-findings-publication.d.ts.map +1 -0
  391. package/dist/stored-findings-publication.js +169 -0
  392. package/dist/stored-findings-publication.js.map +1 -0
  393. package/dist/targets.d.ts +8 -1
  394. package/dist/targets.d.ts.map +1 -1
  395. package/dist/targets.js +103 -23
  396. package/dist/targets.js.map +1 -1
  397. package/dist/tenable-findings.d.ts +1 -4
  398. package/dist/tenable-findings.d.ts.map +1 -1
  399. package/dist/tenable-findings.js.map +1 -1
  400. package/dist/trivy-findings.d.ts.map +1 -1
  401. package/dist/trivy-findings.js +0 -11
  402. package/dist/trivy-findings.js.map +1 -1
  403. package/dist/trusted-executable.d.ts +7 -0
  404. package/dist/trusted-executable.d.ts.map +1 -1
  405. package/dist/trusted-executable.js +148 -37
  406. package/dist/trusted-executable.js.map +1 -1
  407. package/dist/value.js +3 -1
  408. package/dist/value.js.map +1 -1
  409. package/dist/veracode-findings.d.ts +1 -3
  410. package/dist/veracode-findings.d.ts.map +1 -1
  411. package/dist/veracode-findings.js +13 -38
  412. package/dist/veracode-findings.js.map +1 -1
  413. package/dist/version.d.ts +3 -1
  414. package/dist/version.d.ts.map +1 -1
  415. package/dist/version.js +184 -32
  416. package/dist/version.js.map +1 -1
  417. package/dist/wiz-findings.d.ts +2 -2
  418. package/dist/wiz-findings.d.ts.map +1 -1
  419. package/dist/wiz-findings.js +14 -92
  420. package/dist/wiz-findings.js.map +1 -1
  421. package/docs/classify-severity-records.md +30 -0
  422. package/docs/cli.md +537 -124
  423. package/docs/findings-service.md +22 -9
  424. package/docs/hosted-remediation.md +13 -4
  425. package/docs/sdk.md +918 -0
  426. package/package.json +15 -6
  427. package/schemas/external-findings.schema.json +2 -1
  428. package/schemas/project-config.schema.json +5 -0
  429. package/dist/hosted-scanner-v1.d.ts +0 -6
  430. package/dist/hosted-scanner-v1.d.ts.map +0 -1
  431. package/dist/hosted-scanner-v1.js +0 -60
  432. package/dist/hosted-scanner-v1.js.map +0 -1
  433. package/dist/reader-selection.d.ts +0 -15
  434. package/dist/reader-selection.d.ts.map +0 -1
  435. package/dist/reader-selection.js +0 -89
  436. package/dist/reader-selection.js.map +0 -1
  437. package/dist/semgrep-platform-v1.d.ts +0 -6
  438. package/dist/semgrep-platform-v1.d.ts.map +0 -1
  439. package/dist/semgrep-platform-v1.js +0 -83
  440. package/dist/semgrep-platform-v1.js.map +0 -1
  441. package/dist/snyk-rest-v1.d.ts +0 -28
  442. package/dist/snyk-rest-v1.d.ts.map +0 -1
  443. package/dist/snyk-rest-v1.js +0 -132
  444. package/dist/snyk-rest-v1.js.map +0 -1
@@ -8,11 +8,11 @@ import os
8
8
  import sqlite3
9
9
  import sys
10
10
  from collections.abc import Iterable, Iterator
11
+ from fractions import Fraction
11
12
  from functools import cache
12
13
  from itertools import chain
13
14
  from pathlib import Path, PurePosixPath
14
15
  from typing import Any, Callable
15
- from urllib.parse import urlsplit
16
16
 
17
17
  # Some plugin hosts launch Python with safe-path isolation enabled.
18
18
  sys.path.insert(0, str(Path(__file__).resolve().parent))
@@ -26,13 +26,39 @@ from finalize_scan_contract import (
26
26
  from report_projection import SEVERITY_ORDER
27
27
  from review_state import review_state
28
28
  from workbench_constants import ARTIFACTS, FINDINGS_PAGE_MAX, PRIMARY_FINDING_LOCATION_SQL
29
- from workbench_scan_start import scan_target_identity
30
29
  from workbench_scan_usage import stored_scan_cost_fields
31
30
  from workbench_source_scopes import public_scan_recipe
32
- from workbench_target import git_output, require_scan_target_identity
31
+ from workbench_target import (
32
+ require_remediation_target,
33
+ require_scan_target_identity,
34
+ verified_windows_checkout,
35
+ )
36
+ from workbench_target_state import (
37
+ RepositoryIdentityCache,
38
+ _timestamp_ns,
39
+ repository_relative_path,
40
+ same_repository_worktree,
41
+ scan_repository_generation,
42
+ )
33
43
  from workbench_validation import timestamp_key
34
44
 
35
45
 
46
+ def reads_missing_history(args: argparse.Namespace, path: Path) -> bool:
47
+ """Select an in-memory database only for history reads on a fresh profile."""
48
+ if args.command not in {"list-scans", "list-repositories", "list-global-findings"} and not (
49
+ args.command == "get-scan" and not (args.request_id or args.action_token)
50
+ ):
51
+ return False
52
+ try:
53
+ path.lstat()
54
+ except FileNotFoundError:
55
+ return True
56
+ except OSError:
57
+ # The ordinary connection reports inaccessible storage.
58
+ pass
59
+ return False
60
+
61
+
36
62
  def rename_scan(connection: sqlite3.Connection, scan: sqlite3.Row, name: str) -> dict[str, Any]:
37
63
  name = name.strip()
38
64
  if not name:
@@ -53,6 +79,26 @@ def scan_recipe(scan: sqlite3.Row) -> dict[str, Any]:
53
79
  }
54
80
 
55
81
 
82
+ def expected_coverage_mode(scan: sqlite3.Row) -> str:
83
+ """Return the coverage mode implied by the recorded scope, scan mode, and diff target kind."""
84
+ if scan["mode"] == "diff":
85
+ mode = {
86
+ "commit": "commit",
87
+ "range": "branch_diff",
88
+ "working_tree": "working_tree",
89
+ }.get(scan["diff_target_kind"])
90
+ if mode is None:
91
+ raise SystemExit("This migrated diff scan does not have a validated change set.")
92
+ return mode
93
+ if scan["scope"] != "." or (
94
+ "recipe_json" in scan.keys()
95
+ and scan["recipe_json"] is not None
96
+ and json.loads(scan["recipe_json"])["target"]["kind"] == "paths"
97
+ ):
98
+ return "scoped_path"
99
+ return "deep_repository" if scan["mode"] == "deep" else "repository"
100
+
101
+
56
102
  def preserve_sealed_completion(
57
103
  binding: dict[str, Any], manifest: dict[str, Any] | None
58
104
  ) -> dict[str, Any]:
@@ -68,15 +114,34 @@ def preserve_sealed_completion(
68
114
  return binding
69
115
 
70
116
 
117
+ def _windows_resume_checkout(scan: sqlite3.Row) -> Path:
118
+ from workbench_scan_start import scan_target_identity
119
+
120
+ replaced = "Cannot resume: the original checkout is missing or was replaced."
121
+ try:
122
+ repository = require_remediation_target(scan["target_path"])
123
+ except SystemExit as exc:
124
+ raise SystemExit(replaced) from exc
125
+ with verified_windows_checkout(scan, repository, replaced_message=replaced):
126
+ expected = (scan["target_revision"], scan["target_snapshot_digest"])
127
+ current = scan_target_identity(
128
+ repository, None, expected_digest=scan["target_snapshot_digest"]
129
+ )
130
+ if current[:2] != expected:
131
+ raise SystemExit("Cannot resume: the original checkout revision or contents changed.")
132
+ return repository
133
+
134
+
71
135
  def cli_scan_resume(
72
136
  wb: Any,
73
137
  connection: sqlite3.Connection,
74
138
  scan: sqlite3.Row,
75
139
  workspace: sqlite3.Row,
76
140
  ) -> dict[str, Any]:
141
+
77
142
  scan = scan_with_progress(connection, scan["id"])
78
- if scan["mode"] != "deep" or scan["recipe_json"] is None:
79
- raise SystemExit("Resume requires a Deep Scan with a saved CLI launch recipe.")
143
+ if scan["mode"] not in {"standard", "deep"} or scan["recipe_json"] is None:
144
+ raise SystemExit("Resume requires a Standard or Deep Scan with a saved CLI launch recipe.")
80
145
  if scan["status"] != "running" or scan["canceled_at"] is not None:
81
146
  raise SystemExit(
82
147
  "Resume requires a running scan; completed, failed, and canceled scans cannot resume."
@@ -97,21 +162,51 @@ def cli_scan_resume(
97
162
  run["status"] not in {"running", "succeeded"} or run["cancel_requested"]
98
163
  ):
99
164
  raise SystemExit("This Deep Scan has stopped and cannot resume.")
100
- try:
101
- repository = require_scan_target_identity(scan)
102
- except SystemExit as exc:
103
- raise SystemExit(
104
- "Cannot resume: the original checkout is missing or was replaced."
105
- ) from exc
106
- if scan_target_identity(repository, None) != (
107
- scan["target_revision"],
108
- scan["target_snapshot_digest"],
109
- scan["target_device"],
110
- scan["target_inode"],
111
- ):
112
- raise SystemExit("Cannot resume: the original checkout revision or contents changed.")
165
+ if os.name == "nt":
166
+ try:
167
+ repository = _windows_resume_checkout(scan)
168
+ except OSError as exc:
169
+ raise SystemExit(f"Cannot verify the original Windows checkout: {exc}") from exc
170
+ else:
171
+ from workbench_scan_start import scan_target_identity
172
+
173
+ try:
174
+ repository = require_scan_target_identity(scan)
175
+ except SystemExit as exc:
176
+ raise SystemExit(
177
+ "Cannot resume: the original checkout is missing or was replaced."
178
+ ) from exc
179
+ if scan_target_identity(
180
+ repository, None, expected_digest=scan["target_snapshot_digest"]
181
+ ) != (
182
+ scan["target_revision"],
183
+ scan["target_snapshot_digest"],
184
+ scan["target_device"],
185
+ scan["target_inode"],
186
+ ):
187
+ raise SystemExit("Cannot resume: the original checkout revision or contents changed.")
113
188
  recipe = wb.parse_scan_recipe(scan["recipe_json"], repository)
114
189
  scan_dir = wb.require_canonical_scan_directory(Path(scan["scan_dir"]))
190
+ if os.name == "nt":
191
+ from windows_scan_local_files import DEEP_RESUME_DIRECTORY, deep_resume_output_identity
192
+
193
+ identity = scan["windows_resume_output_identity"]
194
+ if identity is not None:
195
+ try:
196
+ current = deep_resume_output_identity(scan_dir)
197
+ except OSError as exc:
198
+ raise SystemExit(
199
+ f"Cannot verify the registered Windows resume output: {exc}"
200
+ ) from exc
201
+ if current != json.loads(identity):
202
+ raise SystemExit(
203
+ "Cannot resume: the original Windows output directory was replaced."
204
+ )
205
+ elif not any(entry != scan_dir / DEEP_RESUME_DIRECTORY for entry in scan_dir.iterdir()):
206
+ raise SystemExit(
207
+ "Cannot resume this empty Windows output because its original directory identity "
208
+ f"was not saved. Start a new scan with 'codex-security scans rerun {scan['id']}'."
209
+ )
115
210
  result = {
116
211
  "contract": wb.scan_contract(scan),
117
212
  "lifecycle": json.loads(scan["lifecycle_json"]),
@@ -215,59 +310,61 @@ def _windows_path_key(value: str) -> str:
215
310
 
216
311
 
217
312
  def _same_repository(
313
+ connection: sqlite3.Connection,
218
314
  before: sqlite3.Row,
219
315
  after: sqlite3.Row,
220
316
  *,
221
- after_git: Callable[..., str | None] | None = None,
317
+ identities: RepositoryIdentityCache | None = None,
222
318
  ) -> bool:
223
- if before["target_id"] is not None and before["target_id"] == after["target_id"]:
224
- return True
225
- before_target = Path(before["target_path"])
226
- after_target = Path(after["target_path"])
227
- if before_target.resolve() == after_target.resolve():
319
+ before_stored = scan_repository_generation(before)
320
+ after_stored = scan_repository_generation(after)
321
+ if before_stored is not None and before_stored == after_stored:
228
322
  return True
229
- common_dir = ("rev-parse", "--path-format=absolute", "--git-common-dir")
230
- after_git = after_git or git_output
231
- before_git_dir = git_output(before_target, *common_dir)
323
+ if before["target_id"] and before["target_id"] == after["target_id"]:
324
+ return before_stored is None or after_stored is None
325
+ identities = identities or RepositoryIdentityCache(connection)
326
+ before_state = identities.for_row(before)
327
+ after_state = identities.for_row(after)
328
+ if (
329
+ not before_state.ownership_matches
330
+ or not after_state.ownership_matches
331
+ or before_stored is not None
332
+ and before_stored != before_state.live_identity
333
+ or after_stored is not None
334
+ and after_stored != after_state.live_identity
335
+ ):
336
+ return False
232
337
  if (
233
- before_git_dir is not None
234
- and (after_git_dir := after_git(after_target, *common_dir)) is not None
235
- and Path(before_git_dir).resolve() == Path(after_git_dir).resolve()
338
+ before_state.resolved_path is not None
339
+ and before_state.resolved_path == after_state.resolved_path
236
340
  ):
341
+ return before_stored is None or after_stored is None
342
+ if before_state.repository is None or after_state.repository is None:
343
+ if same_repository_worktree(Path(before_state.target_path), Path(after_state.target_path)):
344
+ return True
345
+ before_relative = repository_relative_path(Path(before_state.target_path))
346
+ after_relative = repository_relative_path(Path(after_state.target_path))
347
+ after_origin = identities.origin(after_state)
348
+ return (
349
+ before_relative is not None
350
+ and before_relative == after_relative
351
+ and after_origin is not None
352
+ and identities.origin(before_state) == after_origin
353
+ )
354
+ before_identity = before_state.live_identity
355
+ after_identity = after_state.live_identity
356
+ if before_identity is not None and before_identity == after_identity:
237
357
  return True
238
- origin = ("remote", "get-url", "origin")
239
- before_origin = _repository_origin(git_output(before_target, *origin))
240
- return before_origin is not None and before_origin == _repository_origin(
241
- after_git(after_target, *origin)
358
+ if before_identity is None or after_identity is None:
359
+ return False
360
+ after_origin = identities.origin(after_state)
361
+ return (
362
+ after_origin is not None
363
+ and identities.origin(before_state) == after_origin
364
+ and before_state.repository.relative_path == after_state.repository.relative_path
242
365
  )
243
366
 
244
367
 
245
- def _repository_origin(remote: str | None) -> tuple[str, str] | None:
246
- if remote is None:
247
- return None
248
- if "://" in remote:
249
- try:
250
- parsed = urlsplit(remote)
251
- port = parsed.port
252
- except ValueError:
253
- return None
254
- if parsed.scheme not in {"https", "ssh"} or parsed.hostname is None:
255
- return None
256
- if parsed.query or parsed.fragment:
257
- return None
258
- host = parsed.hostname
259
- if port is not None and port != {"https": 443, "ssh": 22}[parsed.scheme]:
260
- host = f"{host}:{port}"
261
- path = parsed.path
262
- else:
263
- authority, separator, path = remote.partition(":")
264
- if not separator or "?" in path or "#" in path:
265
- return None
266
- host = authority.rsplit("@", 1)[-1]
267
- path = path.strip("/").removesuffix(".git")
268
- return (host.lower(), path) if host and path else None
269
-
270
-
271
368
  SCAN_SUMMARY_COLUMNS = """
272
369
  scans.*,
273
370
  lifecycle.snapshot AS lifecycle_json,
@@ -363,30 +460,27 @@ def list_scans(
363
460
  connection.create_function("codex_security_path_key", 1, _windows_path_key)
364
461
  clauses: list[str] = []
365
462
  values: list[Any] = []
463
+ worktree_order = ""
366
464
  if args is not None and args.repository:
367
- repository = Path(args.repository).expanduser().resolve()
368
- requested_repository = connection.execute(
369
- """
370
- SELECT COALESCE((SELECT id FROM security_targets WHERE current_path = ?), '') AS target_id,
371
- ? AS target_path
372
- """,
373
- (str(repository), str(repository)),
374
- ).fetchone()
375
- requested_git = cache(git_output)
376
- related_target_ids = [
377
- target["target_id"]
378
- for target in connection.execute(
379
- "SELECT id AS target_id, current_path AS target_path FROM security_targets"
380
- )
381
- if _same_repository(target, requested_repository, after_git=requested_git)
382
- ]
383
- repository_clauses = ["scans.target_path = ?"]
384
- values.append(str(repository))
385
- if related_target_ids:
386
- placeholders = ", ".join("?" for _ in related_target_ids)
387
- repository_clauses.append(f"scans.target_id IN ({placeholders})")
388
- values.extend(related_target_ids)
389
- clauses.append(f"({' OR '.join(repository_clauses)})")
465
+ repository = Path(args.repository).expanduser().absolute()
466
+ identities = RepositoryIdentityCache(connection)
467
+ repository = Path(identities.history_path(str(repository)))
468
+ clause, scope_values = identities.scope_for_path(str(repository)).sql(
469
+ supports_generation=identities.supports_generation
470
+ )
471
+ clauses.append(clause)
472
+ values.extend(scope_values)
473
+ if getattr(args, "prefer_worktree", False):
474
+
475
+ @cache
476
+ def in_worktree(target_path: str) -> bool:
477
+ try:
478
+ return repository.samefile(target_path)
479
+ except OSError:
480
+ return False
481
+
482
+ connection.create_function("in_worktree", 1, in_worktree)
483
+ worktree_order = "in_worktree(scans.target_path) DESC,"
390
484
  if args is not None and args.scan_root:
391
485
  scan_root = str(Path(args.scan_root).expanduser().resolve())
392
486
  prefix = scan_root.rstrip(os.sep) + os.sep
@@ -433,7 +527,7 @@ def list_scans(
433
527
  f"""
434
528
  {SCAN_SUMMARY_QUERY}
435
529
  {where}
436
- ORDER BY
530
+ ORDER BY {worktree_order}
437
531
  CASE WHEN scans.status = 'running' AND scans.canceled_at IS NULL THEN 0 ELSE 1 END,
438
532
  MAX(julianday(upper(scans.updated_at)), julianday(upper(progress.updated_at))) DESC,
439
533
  julianday(upper(scans.started_at)) DESC,
@@ -442,7 +536,11 @@ def list_scans(
442
536
  """,
443
537
  values,
444
538
  ).fetchall()
445
- result = {"scans": [scan_summary(row) for row in rows[:limit]]}
539
+ scans = [scan_summary(row) for row in rows[:limit]]
540
+ if worktree_order:
541
+ for scan in scans:
542
+ scan["inCurrentWorktree"] = in_worktree(scan["targetPath"])
543
+ result = {"scans": scans}
446
544
  if limit is not None:
447
545
  result.update(
448
546
  {
@@ -454,6 +552,17 @@ def list_scans(
454
552
  return result
455
553
 
456
554
 
555
+ def _scan_completion_order(scan: sqlite3.Row) -> tuple[int, int | Fraction, str]:
556
+ sequence = scan["completion_sequence"] if "completion_sequence" in scan.keys() else None
557
+ if sequence is not None:
558
+ return (1, sequence, scan["id"])
559
+ completed_at = scan["completed_at"] if "completed_at" in scan.keys() else None
560
+ timestamp = _timestamp_ns(completed_at)
561
+ if timestamp is None:
562
+ timestamp = _timestamp_ns(scan["started_at"])
563
+ return (0, timestamp if timestamp is not None else 0, scan["id"])
564
+
565
+
457
566
  _FindingSites = dict[tuple[str, str | None, PurePosixPath, int, int], dict[str, Any] | None]
458
567
  # Match the first location shown by compactFinding in finding-catalogue.ts.
459
568
  _COMPARISON_LOCATION_RANK = {"root_control": 0, "expected_control": 1, "concrete_implementation": 1}
@@ -485,11 +594,14 @@ def _cross_mode_context(
485
594
  findings: dict[str, list[dict[str, Any]]],
486
595
  sites: dict[str, _FindingSites],
487
596
  ) -> dict[str, Any]:
488
- # Different repository subdirectories can share both the Git revision and clean digest.
597
+ # The saved generation includes the relative target path in a linked worktree.
598
+ same_target = before["target_id"] is not None and before["target_id"] == after["target_id"]
599
+ if not same_target:
600
+ generation = scan_repository_generation(before)
601
+ same_target = generation is not None and generation == scan_repository_generation(after)
489
602
  if (
490
603
  {before["mode"], after["mode"]} != {"standard", "deep"}
491
- or before["target_id"] is None
492
- or before["target_id"] != after["target_id"]
604
+ or not same_target
493
605
  or before["target_revision"] != after["target_revision"]
494
606
  or before["target_snapshot_digest"] is None
495
607
  or before["target_snapshot_digest"] != after["target_snapshot_digest"]
@@ -516,77 +628,85 @@ def list_unmatched_scan_pairs(
516
628
  backfill_finding_details: Callable[[sqlite3.Connection, sqlite3.Row], None],
517
629
  read_coverage: Callable[[sqlite3.Row], dict[str, Any]],
518
630
  ) -> dict[str, Any]:
519
- repository = Path(args.repository).expanduser().resolve()
520
- requested = connection.execute(
521
- """
522
- SELECT COALESCE((SELECT id FROM security_targets WHERE current_path = ?), '') AS target_id,
523
- ? AS target_path
524
- """,
525
- (str(repository), str(repository)),
526
- ).fetchone()
527
- selected = []
528
- requested_git = cache(git_output)
529
- membership: dict[tuple[str | None, str], bool] = {}
530
- for scan in connection.execute("SELECT * FROM scans WHERE status = 'complete'"):
531
- target = (scan["target_id"], scan["target_path"])
532
- if target not in membership:
533
- membership[target] = _same_repository(scan, requested, after_git=requested_git)
534
- if membership[target]:
535
- selected.append(scan)
536
-
537
- selected.sort(key=lambda scan: (timestamp_key(scan["started_at"]), scan["id"]))
631
+ requested_repository = Path(args.repository).expanduser().absolute()
632
+ repository = requested_repository.resolve()
633
+ identities = RepositoryIdentityCache(connection)
634
+ requested = identities.for_path(str(requested_repository))
635
+ if identities.supports_identity:
636
+ requested.require_owner()
637
+ clause, values = identities.scope_for_path(str(requested_repository)).sql(
638
+ supports_generation=identities.supports_generation
639
+ )
640
+ selected = connection.execute(
641
+ f"SELECT * FROM scans WHERE status = 'complete' AND {clause}",
642
+ values,
643
+ ).fetchall()
644
+
645
+ focus_scan_id = getattr(args, "after_scan_id", None)
646
+ if focus_scan_id is None:
647
+ selected.sort(key=lambda scan: (timestamp_key(scan["started_at"]), scan["id"]))
648
+ else:
649
+ selected.sort(key=_scan_completion_order)
650
+ scan_ids = [scan["id"] for scan in selected]
538
651
 
539
652
  available = []
540
- for selected_index, scan in enumerate(selected):
653
+ for scan in selected:
541
654
  try:
542
655
  read_coverage(scan)
543
656
  except SystemExit:
544
657
  continue
545
- available.append((selected_index, scan))
658
+ available.append(scan)
546
659
 
547
660
  saved_pairs = {
548
- (row["before_scan_id"], row["after_scan_id"])
661
+ frozenset((row["before_scan_id"], row["after_scan_id"]))
549
662
  for row in connection.execute("SELECT before_scan_id, after_scan_id FROM scan_comparisons")
550
663
  }
664
+ if focus_scan_id is not None and focus_scan_id not in scan_ids:
665
+ raise SystemExit("The scan to match is not a completed scan in this repository.")
551
666
  batches = []
552
667
  skipped = 0
553
668
  matching_findings: dict[str, list[dict[str, Any]]] = {}
669
+ compact = os.environ.get("CODEX_SECURITY_MATCHING_PLAN_FORMAT") == "compact"
554
670
  sites: dict[str, _FindingSites] = {}
555
671
  known_links: list[sqlite3.Row] | None = None
556
- for index, (selected_index, after) in enumerate(available):
672
+ for index, after in enumerate(available):
673
+ if focus_scan_id is not None and after["id"] != focus_scan_id:
674
+ continue
675
+ candidates = [
676
+ before
677
+ for before in available[:index]
678
+ if _same_repository(connection, before, after, identities=identities)
679
+ ]
557
680
  previous = [
558
681
  before
559
- for _, before in available[:index]
560
- if args.force or (before["id"], after["id"]) not in saved_pairs
682
+ for before in candidates
683
+ if args.force or frozenset((before["id"], after["id"])) not in saved_pairs
561
684
  ]
562
- skipped += index - len(previous)
685
+ skipped += len(candidates) - len(previous)
563
686
  if not previous:
564
687
  continue
565
688
  if known_links is None:
566
- known_links = (
567
- []
568
- if args.force
569
- else _saved_finding_links(connection, {scan["id"] for scan in selected})
570
- )
689
+ known_links = [] if args.force else _saved_finding_links(connection, set(scan_ids))
571
690
  for scan in (*previous, after):
572
691
  if scan["id"] not in matching_findings:
573
692
  backfill_finding_details(connection, scan)
574
693
  matching_findings[scan["id"]] = [
575
694
  _matching_input(row) for row in _scan_findings(connection, scan["id"]).values()
576
695
  ]
577
- known_groups = _known_finding_groups(
578
- known_links,
579
- {scan["id"] for scan in selected[: selected_index + 1]},
580
- )
696
+ known_groups = []
697
+ if known_links:
698
+ # Unavailable scans can still contribute a saved finding identity.
699
+ through_after = set(scan_ids[: scan_ids.index(after["id"]) + 1])
700
+ known_groups = _known_finding_groups(known_links, through_after)
581
701
  batches.append(
582
702
  {
583
- "afterFindings": matching_findings[after["id"]],
584
703
  "afterScanId": after["id"],
704
+ **({} if compact else {"afterFindings": matching_findings[after["id"]]}),
585
705
  "beforeScans": [
586
706
  {
587
707
  **_cross_mode_context(before, after, matching_findings, sites),
588
- "findings": matching_findings[before["id"]],
589
708
  "scanId": before["id"],
709
+ **({} if compact else {"findings": matching_findings[before["id"]]}),
590
710
  }
591
711
  for before in previous
592
712
  ],
@@ -594,6 +714,7 @@ def list_unmatched_scan_pairs(
594
714
  }
595
715
  )
596
716
  return {
717
+ **({"findingsByScanId": matching_findings} if compact else {}),
597
718
  "batches": batches,
598
719
  "repository": str(repository),
599
720
  "scanCount": len(selected),
@@ -666,7 +787,7 @@ def compare_scans(
666
787
  raise SystemExit("Select two different scans to compare.")
667
788
  if before["status"] != "complete" or after["status"] != "complete":
668
789
  raise SystemExit("Only completed scans can be compared.")
669
- if not _same_repository(before, after):
790
+ if not _same_repository(connection, before, after):
670
791
  raise SystemExit("Semantic scan comparisons require the same repository target.")
671
792
  cached = connection.execute(
672
793
  "SELECT result_json FROM scan_comparisons WHERE before_scan_id = ? AND after_scan_id = ?",
@@ -683,7 +804,7 @@ def compare_scans(
683
804
  f"'codex-security scans compare {after['id']} {before['id']}'."
684
805
  )
685
806
  raise SystemExit(
686
- "No saved matches for these scans. Run 'codex-security scans match BEFORE AFTER' first."
807
+ "No saved matches for these scans. Run 'codex-security scans compare BEFORE AFTER' first."
687
808
  )
688
809
  if include_matching_inputs and backfill_finding_details is not None:
689
810
  backfill_finding_details(connection, before)
@@ -801,14 +922,13 @@ def compare_scans(
801
922
  for pair in related
802
923
  ]
803
924
  if include_matching_inputs:
925
+ identities = RepositoryIdentityCache(connection)
804
926
  after_key = (timestamp_key(after["started_at"]), after["id"])
805
927
  known_scan_ids = {
806
928
  scan["id"]
807
- for scan in connection.execute(
808
- "SELECT id, started_at, target_id, target_path FROM scans WHERE status = 'complete'"
809
- )
929
+ for scan in connection.execute("SELECT * FROM scans WHERE status = 'complete'")
810
930
  if (timestamp_key(scan["started_at"]), scan["id"]) <= after_key
811
- and _same_repository(scan, after)
931
+ and _same_repository(connection, scan, after, identities=identities)
812
932
  }
813
933
  excluded_pairs = {(before["id"], after["id"]), (after["id"], before["id"])}
814
934
  known_groups = _known_finding_groups(
@@ -847,7 +967,7 @@ def save_scan_comparison(
847
967
  raise SystemExit("Select two different scans to compare.")
848
968
  if before["status"] != "complete" or after["status"] != "complete":
849
969
  raise SystemExit("Only completed scans can be compared.")
850
- if not _same_repository(before, after):
970
+ if not _same_repository(connection, before, after):
851
971
  raise SystemExit("Semantic scan comparisons require the same repository target.")
852
972
  read_coverage(after)
853
973
  allowed = {
@@ -928,8 +1048,10 @@ def save_scan_comparison(
928
1048
  with connection:
929
1049
  connection.execute("BEGIN IMMEDIATE")
930
1050
  connection.execute(
931
- "DELETE FROM scan_comparisons WHERE before_scan_id = ? AND after_scan_id = ?",
932
- (before["id"], after["id"]),
1051
+ "DELETE FROM scan_comparisons "
1052
+ "WHERE (before_scan_id = ? AND after_scan_id = ?) "
1053
+ "OR (before_scan_id = ? AND after_scan_id = ?)",
1054
+ (before["id"], after["id"], after["id"], before["id"]),
933
1055
  )
934
1056
  connection.execute(
935
1057
  """
@@ -1091,6 +1213,41 @@ def finding_relations(
1091
1213
  return result
1092
1214
 
1093
1215
 
1216
+ def finding_management_updated_at(connection: sqlite3.Connection, scan_id: str) -> str | None:
1217
+ return connection.execute(
1218
+ """
1219
+ SELECT MAX(updated_at)
1220
+ FROM (
1221
+ SELECT triage.updated_at
1222
+ FROM finding_triage AS triage
1223
+ JOIN finding_occurrences AS occurrences ON occurrences.id = triage.occurrence_id
1224
+ WHERE occurrences.scan_id = ?
1225
+ UNION ALL
1226
+ SELECT remediation.updated_at
1227
+ FROM finding_remediation_attempts AS remediation
1228
+ JOIN finding_occurrences AS occurrences ON occurrences.id = remediation.occurrence_id
1229
+ WHERE occurrences.scan_id = ?
1230
+ )
1231
+ """,
1232
+ (scan_id, scan_id),
1233
+ ).fetchone()[0]
1234
+
1235
+
1236
+ def finding_triage_result(connection: sqlite3.Connection, occurrence_id: str) -> dict[str, Any]:
1237
+ row = connection.execute(
1238
+ "SELECT status, close_reason, note, updated_at FROM finding_triage WHERE occurrence_id = ?",
1239
+ (occurrence_id,),
1240
+ ).fetchone()
1241
+ if row is None:
1242
+ return {"status": "open"}
1243
+ return {
1244
+ "closeReason": row["close_reason"],
1245
+ "note": row["note"],
1246
+ "status": row["status"],
1247
+ "updatedAt": row["updated_at"],
1248
+ }
1249
+
1250
+
1094
1251
  def finding_matches(
1095
1252
  connection: sqlite3.Connection, occurrence_id: str, scan_id: str, started_at: str
1096
1253
  ) -> tuple[list[dict[str, Any]], str, list[str]]: