@openai/codex-security 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (396) hide show
  1. package/README.md +45 -57
  2. package/_bundled_plugin/.app.json +4 -0
  3. package/_bundled_plugin/.mcp.json +1 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  6. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
  7. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  13. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  14. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  15. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +46 -12
  16. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  17. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  18. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  19. package/_bundled_plugin/references/artifact-storage.md +1 -1
  20. package/_bundled_plugin/references/core-scan.md +14 -5
  21. package/_bundled_plugin/references/default-severity-rubric.md +28 -0
  22. package/_bundled_plugin/references/finding-detail-fields.md +1 -0
  23. package/_bundled_plugin/references/threat-model.md +1 -0
  24. package/_bundled_plugin/scripts/deep_scan_workbench.py +23 -112
  25. package/_bundled_plugin/scripts/finalize_scan_contract.py +167 -153
  26. package/_bundled_plugin/scripts/finding_preview.py +5 -29
  27. package/_bundled_plugin/scripts/posix_scan_local_files.py +187 -0
  28. package/_bundled_plugin/scripts/report_projection.py +87 -136
  29. package/_bundled_plugin/scripts/validate_scan_contract.py +2 -6
  30. package/_bundled_plugin/scripts/windows_scan_local_files.py +212 -55
  31. package/_bundled_plugin/scripts/workbench/retained_coverage.py +8 -24
  32. package/_bundled_plugin/scripts/workbench/saved_coverage.py +143 -231
  33. package/_bundled_plugin/scripts/workbench_cli.py +102 -13
  34. package/_bundled_plugin/scripts/workbench_constants.py +9 -0
  35. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +0 -17
  36. package/_bundled_plugin/scripts/workbench_db.py +187 -363
  37. package/_bundled_plugin/scripts/workbench_finding_workflows.py +86 -4
  38. package/_bundled_plugin/scripts/workbench_native_indexes.py +17 -21
  39. package/_bundled_plugin/scripts/workbench_remediation.py +495 -11
  40. package/_bundled_plugin/scripts/workbench_saved_results.py +0 -66
  41. package/_bundled_plugin/scripts/workbench_scan_history.py +22 -25
  42. package/_bundled_plugin/scripts/workbench_scan_start.py +1 -1
  43. package/_bundled_plugin/scripts/workbench_scan_usage.py +25 -52
  44. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  45. package/_bundled_plugin/scripts/workbench_setup.py +239 -0
  46. package/_bundled_plugin/scripts/workbench_source_scopes.py +15 -23
  47. package/_bundled_plugin/scripts/workbench_target.py +120 -35
  48. package/_bundled_plugin/scripts/workbench_validation.py +1 -9
  49. package/_bundled_plugin/shared/workbench-history-repairs.json +7 -0
  50. package/_bundled_plugin/shared/workbench-migrations.json +19 -0
  51. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
  52. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
  53. package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
  54. package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
  55. package/_bundled_plugin/skills/cloud-findings/SKILL.md +2 -0
  56. package/_bundled_plugin/skills/fix-finding/SKILL.md +18 -1
  57. package/_bundled_plugin/skills/publish-findings/SKILL.md +68 -35
  58. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
  59. package/_bundled_plugin/skills/resolve-dependency-alert/SKILL.md +18 -0
  60. package/_bundled_plugin/skills/resolve-dependency-alert/agents/openai.yaml +4 -0
  61. package/_bundled_plugin/skills/threat-model-visualize/SKILL.md +83 -0
  62. package/_bundled_plugin/skills/threat-model-visualize/agents/openai.yaml +4 -0
  63. package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-overview.svg +366 -0
  64. package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-path.svg +558 -0
  65. package/_bundled_plugin/skills/threat-model-visualize/assets/control-effects.js +85 -0
  66. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.css +17 -0
  67. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.html +38 -0
  68. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.js +372 -0
  69. package/_bundled_plugin/skills/threat-model-visualize/assets/route-paths.js +71 -0
  70. package/_bundled_plugin/skills/threat-model-visualize/assets/source-roles.js +47 -0
  71. package/_bundled_plugin/skills/threat-model-visualize/assets/svg-layout.js +149 -0
  72. package/_bundled_plugin/skills/threat-model-visualize/references/context-explorer.md +21 -0
  73. package/_bundled_plugin/skills/threat-model-visualize/references/view-model.md +49 -0
  74. package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +569 -0
  75. package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
  76. package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
  77. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -4
  78. package/dist/api.d.ts +6 -1
  79. package/dist/api.d.ts.map +1 -1
  80. package/dist/api.js +414 -163
  81. package/dist/api.js.map +1 -1
  82. package/dist/auth.js +7 -2
  83. package/dist/auth.js.map +1 -1
  84. package/dist/blackduck-findings.d.ts +8 -0
  85. package/dist/blackduck-findings.d.ts.map +1 -0
  86. package/dist/blackduck-findings.js +305 -0
  87. package/dist/blackduck-findings.js.map +1 -0
  88. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  89. package/dist/bulk-scan-discovery.js +51 -36
  90. package/dist/bulk-scan-discovery.js.map +1 -1
  91. package/dist/classify-severity-records.d.ts +5 -0
  92. package/dist/classify-severity-records.d.ts.map +1 -1
  93. package/dist/classify-severity-records.js +6 -8
  94. package/dist/classify-severity-records.js.map +1 -1
  95. package/dist/classify-severity.d.ts +4 -1
  96. package/dist/classify-severity.d.ts.map +1 -1
  97. package/dist/classify-severity.js +28 -9
  98. package/dist/classify-severity.js.map +1 -1
  99. package/dist/cli.d.ts +3 -0
  100. package/dist/cli.d.ts.map +1 -1
  101. package/dist/cli.js +635 -266
  102. package/dist/cli.js.map +1 -1
  103. package/dist/codex-prompt.d.ts +2 -0
  104. package/dist/codex-prompt.d.ts.map +1 -1
  105. package/dist/codex-prompt.js +6 -0
  106. package/dist/codex-prompt.js.map +1 -1
  107. package/dist/component-scan.d.ts.map +1 -1
  108. package/dist/component-scan.js +6 -5
  109. package/dist/component-scan.js.map +1 -1
  110. package/dist/config.d.ts +2 -1
  111. package/dist/config.d.ts.map +1 -1
  112. package/dist/config.js +162 -40
  113. package/dist/config.js.map +1 -1
  114. package/dist/continuum-findings.d.ts +7 -0
  115. package/dist/continuum-findings.d.ts.map +1 -0
  116. package/dist/continuum-findings.js +157 -0
  117. package/dist/continuum-findings.js.map +1 -0
  118. package/dist/contract-values.d.ts +28 -0
  119. package/dist/contract-values.d.ts.map +1 -0
  120. package/dist/contract-values.js +75 -0
  121. package/dist/contract-values.js.map +1 -0
  122. package/dist/contract.d.ts +2 -20
  123. package/dist/contract.d.ts.map +1 -1
  124. package/dist/contract.js +58 -669
  125. package/dist/contract.js.map +1 -1
  126. package/dist/cost-model.d.ts.map +1 -1
  127. package/dist/cost-model.js +1 -4
  128. package/dist/cost-model.js.map +1 -1
  129. package/dist/cost.d.ts +19 -1
  130. package/dist/cost.d.ts.map +1 -1
  131. package/dist/cost.js +2120 -39
  132. package/dist/cost.js.map +1 -1
  133. package/dist/custom-validation-prompt.d.ts +1 -1
  134. package/dist/custom-validation-prompt.d.ts.map +1 -1
  135. package/dist/custom-validation-prompt.js +5 -0
  136. package/dist/custom-validation-prompt.js.map +1 -1
  137. package/dist/custom-validation.d.ts +2 -0
  138. package/dist/custom-validation.d.ts.map +1 -1
  139. package/dist/custom-validation.js +6 -2
  140. package/dist/custom-validation.js.map +1 -1
  141. package/dist/deduplication/deduplication-prompts.d.ts +4 -4
  142. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  143. package/dist/deduplication/deduplication-prompts.js +2 -2
  144. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  145. package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
  146. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  147. package/dist/deduplication/deduplication-reviewer.js +12 -5
  148. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  149. package/dist/deduplication/deduplication.js.map +1 -1
  150. package/dist/deduplication/finding-schema.d.ts +19 -1
  151. package/dist/deduplication/finding-schema.d.ts.map +1 -1
  152. package/dist/deduplication/finding-schema.js +25 -0
  153. package/dist/deduplication/finding-schema.js.map +1 -1
  154. package/dist/deduplication/local.d.ts.map +1 -1
  155. package/dist/deduplication/local.js +3 -8
  156. package/dist/deduplication/local.js.map +1 -1
  157. package/dist/deduplication/records.d.ts +11 -3
  158. package/dist/deduplication/records.d.ts.map +1 -1
  159. package/dist/deduplication/records.js +48 -16
  160. package/dist/deduplication/records.js.map +1 -1
  161. package/dist/deep-scan.d.ts +11 -0
  162. package/dist/deep-scan.d.ts.map +1 -1
  163. package/dist/deep-scan.js +235 -4
  164. package/dist/deep-scan.js.map +1 -1
  165. package/dist/default-severity-rubric.d.ts +1 -2
  166. package/dist/default-severity-rubric.d.ts.map +1 -1
  167. package/dist/default-severity-rubric.js +2 -66
  168. package/dist/default-severity-rubric.js.map +1 -1
  169. package/dist/endor-findings.d.ts.map +1 -1
  170. package/dist/endor-findings.js +44 -89
  171. package/dist/endor-findings.js.map +1 -1
  172. package/dist/errors.js +1 -1
  173. package/dist/errors.js.map +1 -1
  174. package/dist/external-findings-import.d.ts.map +1 -1
  175. package/dist/external-findings-import.js +11 -15
  176. package/dist/external-findings-import.js.map +1 -1
  177. package/dist/external-findings-local.d.ts +12 -1
  178. package/dist/external-findings-local.d.ts.map +1 -1
  179. package/dist/external-findings-local.js +411 -184
  180. package/dist/external-findings-local.js.map +1 -1
  181. package/dist/external-findings-publish.d.ts +15 -1
  182. package/dist/external-findings-publish.d.ts.map +1 -1
  183. package/dist/external-findings-publish.js +1238 -226
  184. package/dist/external-findings-publish.js.map +1 -1
  185. package/dist/external-findings-read.d.ts +10 -0
  186. package/dist/external-findings-read.d.ts.map +1 -1
  187. package/dist/external-findings-read.js +71 -51
  188. package/dist/external-findings-read.js.map +1 -1
  189. package/dist/external-findings.d.ts +13 -0
  190. package/dist/external-findings.d.ts.map +1 -1
  191. package/dist/external-findings.js +124 -1
  192. package/dist/external-findings.js.map +1 -1
  193. package/dist/external-import-contract.d.ts +29 -1
  194. package/dist/external-import-contract.d.ts.map +1 -1
  195. package/dist/external-import-contract.js +314 -44
  196. package/dist/external-import-contract.js.map +1 -1
  197. package/dist/external-import-models.d.ts +1 -1
  198. package/dist/external-import-models.d.ts.map +1 -1
  199. package/dist/external-import-models.js.map +1 -1
  200. package/dist/finding-normalization.d.ts +1 -1
  201. package/dist/finding-normalization.d.ts.map +1 -1
  202. package/dist/finding-normalization.js +46 -11
  203. package/dist/finding-normalization.js.map +1 -1
  204. package/dist/finding-retrieval.d.ts +3 -3
  205. package/dist/finding-retrieval.d.ts.map +1 -1
  206. package/dist/finding-retrieval.js.map +1 -1
  207. package/dist/finding-workflow.d.ts +6 -1
  208. package/dist/finding-workflow.d.ts.map +1 -1
  209. package/dist/finding-workflow.js +2 -2
  210. package/dist/finding-workflow.js.map +1 -1
  211. package/dist/git-remote.d.ts +4 -0
  212. package/dist/git-remote.d.ts.map +1 -1
  213. package/dist/git-remote.js +20 -0
  214. package/dist/git-remote.js.map +1 -1
  215. package/dist/github-advisories.d.ts +3 -12
  216. package/dist/github-advisories.d.ts.map +1 -1
  217. package/dist/github-advisories.js +9 -29
  218. package/dist/github-advisories.js.map +1 -1
  219. package/dist/github-dependabot-findings.d.ts.map +1 -1
  220. package/dist/github-dependabot-findings.js +7 -16
  221. package/dist/github-dependabot-findings.js.map +1 -1
  222. package/dist/github-findings.d.ts.map +1 -1
  223. package/dist/github-findings.js +344 -56
  224. package/dist/github-findings.js.map +1 -1
  225. package/dist/github.d.ts +17 -7
  226. package/dist/github.d.ts.map +1 -1
  227. package/dist/github.js +43 -30
  228. package/dist/github.js.map +1 -1
  229. package/dist/host-protocol.d.ts +7 -2
  230. package/dist/host-protocol.d.ts.map +1 -1
  231. package/dist/host-protocol.js +27 -3
  232. package/dist/host-protocol.js.map +1 -1
  233. package/dist/host-records-protocol.d.ts +10 -11
  234. package/dist/host-records-protocol.d.ts.map +1 -1
  235. package/dist/host-records-protocol.js +69 -9
  236. package/dist/host-records-protocol.js.map +1 -1
  237. package/dist/hosted-scan.d.ts +15 -0
  238. package/dist/hosted-scan.d.ts.map +1 -1
  239. package/dist/hosted-scan.js +55 -33
  240. package/dist/hosted-scan.js.map +1 -1
  241. package/dist/index.d.ts +8 -0
  242. package/dist/index.d.ts.map +1 -1
  243. package/dist/index.js +7 -0
  244. package/dist/index.js.map +1 -1
  245. package/dist/inspector-findings.d.ts +9 -0
  246. package/dist/inspector-findings.d.ts.map +1 -0
  247. package/dist/inspector-findings.js +512 -0
  248. package/dist/inspector-findings.js.map +1 -0
  249. package/dist/knowledge-base.js +18 -5
  250. package/dist/knowledge-base.js.map +1 -1
  251. package/dist/local-git-metadata.d.ts +5 -0
  252. package/dist/local-git-metadata.d.ts.map +1 -0
  253. package/dist/local-git-metadata.js +131 -0
  254. package/dist/local-git-metadata.js.map +1 -0
  255. package/dist/multiscan.d.ts.map +1 -1
  256. package/dist/multiscan.js +22 -12
  257. package/dist/multiscan.js.map +1 -1
  258. package/dist/opengrep-findings.d.ts.map +1 -1
  259. package/dist/opengrep-findings.js +34 -20
  260. package/dist/opengrep-findings.js.map +1 -1
  261. package/dist/patch-tui.d.ts +1 -1
  262. package/dist/patch-tui.d.ts.map +1 -1
  263. package/dist/patch-tui.js +94 -36
  264. package/dist/patch-tui.js.map +1 -1
  265. package/dist/private-finding-import.d.ts +246 -0
  266. package/dist/private-finding-import.d.ts.map +1 -0
  267. package/dist/private-finding-import.js +387 -0
  268. package/dist/private-finding-import.js.map +1 -0
  269. package/dist/project-config.d.ts.map +1 -1
  270. package/dist/project-config.js +2 -2
  271. package/dist/project-config.js.map +1 -1
  272. package/dist/provider-profile.d.ts +10 -2
  273. package/dist/provider-profile.d.ts.map +1 -1
  274. package/dist/provider-profile.js +72 -10
  275. package/dist/provider-profile.js.map +1 -1
  276. package/dist/publication.js +7 -1
  277. package/dist/publication.js.map +1 -1
  278. package/dist/reader-selection.d.ts +13 -0
  279. package/dist/reader-selection.d.ts.map +1 -0
  280. package/dist/reader-selection.js +81 -0
  281. package/dist/reader-selection.js.map +1 -0
  282. package/dist/record.d.ts +6 -1
  283. package/dist/record.d.ts.map +1 -1
  284. package/dist/record.js +53 -2
  285. package/dist/record.js.map +1 -1
  286. package/dist/remediation.d.ts +5 -0
  287. package/dist/remediation.d.ts.map +1 -1
  288. package/dist/remediation.js +30 -0
  289. package/dist/remediation.js.map +1 -1
  290. package/dist/result.d.ts +2 -0
  291. package/dist/result.d.ts.map +1 -1
  292. package/dist/result.js +3 -1
  293. package/dist/result.js.map +1 -1
  294. package/dist/runtime.d.ts +5 -3
  295. package/dist/runtime.d.ts.map +1 -1
  296. package/dist/runtime.js +110 -57
  297. package/dist/runtime.js.map +1 -1
  298. package/dist/scan-activity.js +40 -17
  299. package/dist/scan-activity.js.map +1 -1
  300. package/dist/scan-comparison.d.ts +1 -1
  301. package/dist/scan-comparison.d.ts.map +1 -1
  302. package/dist/scan-comparison.js +11 -13
  303. package/dist/scan-comparison.js.map +1 -1
  304. package/dist/scan-dashboard.d.ts +1 -0
  305. package/dist/scan-dashboard.d.ts.map +1 -1
  306. package/dist/scan-dashboard.js +37 -48
  307. package/dist/scan-dashboard.js.map +1 -1
  308. package/dist/scan-executor.d.ts +2 -0
  309. package/dist/scan-executor.d.ts.map +1 -1
  310. package/dist/scan-executor.js.map +1 -1
  311. package/dist/scan-history-renderer.d.ts.map +1 -1
  312. package/dist/scan-history-renderer.js +22 -9
  313. package/dist/scan-history-renderer.js.map +1 -1
  314. package/dist/scan-logs.d.ts.map +1 -1
  315. package/dist/scan-logs.js +5 -5
  316. package/dist/scan-logs.js.map +1 -1
  317. package/dist/scanner-import.d.ts +48 -3
  318. package/dist/scanner-import.d.ts.map +1 -1
  319. package/dist/scanner-import.js +214 -39
  320. package/dist/scanner-import.js.map +1 -1
  321. package/dist/scanner-repository-url.d.ts +14 -0
  322. package/dist/scanner-repository-url.d.ts.map +1 -0
  323. package/dist/scanner-repository-url.js +67 -0
  324. package/dist/scanner-repository-url.js.map +1 -0
  325. package/dist/semgrep-findings.d.ts.map +1 -1
  326. package/dist/semgrep-findings.js +50 -88
  327. package/dist/semgrep-findings.js.map +1 -1
  328. package/dist/semgrep-platform-findings.d.ts +12 -0
  329. package/dist/semgrep-platform-findings.d.ts.map +1 -0
  330. package/dist/semgrep-platform-findings.js +198 -0
  331. package/dist/semgrep-platform-findings.js.map +1 -0
  332. package/dist/severity-rubric.d.ts +20 -0
  333. package/dist/severity-rubric.d.ts.map +1 -0
  334. package/dist/severity-rubric.js +73 -0
  335. package/dist/severity-rubric.js.map +1 -0
  336. package/dist/severity-store.js +15 -5
  337. package/dist/severity-store.js.map +1 -1
  338. package/dist/snyk-findings.d.ts.map +1 -1
  339. package/dist/snyk-findings.js +97 -106
  340. package/dist/snyk-findings.js.map +1 -1
  341. package/dist/sonar-collector.d.ts +16 -0
  342. package/dist/sonar-collector.d.ts.map +1 -0
  343. package/dist/sonar-collector.js +383 -0
  344. package/dist/sonar-collector.js.map +1 -0
  345. package/dist/sonar-findings.d.ts +49 -0
  346. package/dist/sonar-findings.d.ts.map +1 -0
  347. package/dist/sonar-findings.js +288 -0
  348. package/dist/sonar-findings.js.map +1 -0
  349. package/dist/sonar-import.d.ts +111 -0
  350. package/dist/sonar-import.d.ts.map +1 -0
  351. package/dist/sonar-import.js +279 -0
  352. package/dist/sonar-import.js.map +1 -0
  353. package/dist/suggest-owners.d.ts.map +1 -1
  354. package/dist/suggest-owners.js +2 -1
  355. package/dist/suggest-owners.js.map +1 -1
  356. package/dist/targets.d.ts +3 -0
  357. package/dist/targets.d.ts.map +1 -1
  358. package/dist/targets.js +18 -12
  359. package/dist/targets.js.map +1 -1
  360. package/dist/terminal-columns.d.ts +4 -0
  361. package/dist/terminal-columns.d.ts.map +1 -0
  362. package/dist/terminal-columns.js +19 -0
  363. package/dist/terminal-columns.js.map +1 -0
  364. package/dist/validation-records.d.ts +0 -3
  365. package/dist/validation-records.d.ts.map +1 -1
  366. package/dist/validation-records.js +0 -16
  367. package/dist/validation-records.js.map +1 -1
  368. package/dist/veracode-findings.d.ts +7 -0
  369. package/dist/veracode-findings.d.ts.map +1 -0
  370. package/dist/veracode-findings.js +371 -0
  371. package/dist/veracode-findings.js.map +1 -0
  372. package/dist/windows-path.d.ts.map +1 -1
  373. package/dist/windows-path.js +1 -0
  374. package/dist/windows-path.js.map +1 -1
  375. package/dist/wiz-csv.d.ts +2 -2
  376. package/dist/wiz-csv.d.ts.map +1 -1
  377. package/dist/wiz-csv.js +1 -3
  378. package/dist/wiz-csv.js.map +1 -1
  379. package/dist/wiz-findings.d.ts +10 -2
  380. package/dist/wiz-findings.d.ts.map +1 -1
  381. package/dist/wiz-findings.js +88 -49
  382. package/dist/wiz-findings.js.map +1 -1
  383. package/docs/classify-severity-records.md +1 -1
  384. package/docs/cli.md +320 -481
  385. package/docs/dedupe-records.md +27 -4
  386. package/docs/findings-service.md +21 -8
  387. package/docs/hosted-scans.md +16 -1
  388. package/package.json +9 -10
  389. package/schemas/external-findings.schema.json +12 -1
  390. package/schemas/hosted-scan-v2.fixture.json +16 -1
  391. package/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
  392. package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
  393. package/dist/deduplication/records-protocol.d.ts +0 -4
  394. package/dist/deduplication/records-protocol.d.ts.map +0 -1
  395. package/dist/deduplication/records-protocol.js +0 -35
  396. package/dist/deduplication/records-protocol.js.map +0 -1
@@ -11,7 +11,7 @@ import sys
11
11
  import uuid
12
12
  from datetime import datetime, timedelta
13
13
  from pathlib import Path
14
- from typing import Any, Callable
14
+ from typing import Any
15
15
 
16
16
  sys.path.insert(0, str(Path(__file__).resolve().parent))
17
17
  import workbench_saved_results as saved_results
@@ -22,118 +22,11 @@ from workbench_source_scopes import capture_source_scopes
22
22
  from workbench_target import directory_snapshot_regular_file_count
23
23
  from workbench_validation import optional_text, require_uuid, user_context_argument
24
24
 
25
- DEEP_SCAN_WORKER_KINDS = ("setup", "discovery", "dedup")
26
- DEEP_SCAN_WORKER_STATUSES = ("queued", "running", "succeeded", "failed", "canceled")
27
- DEEP_SCAN_REPLACEABLE_FAILURE_KINDS = (
28
- "policy_refusal",
29
- "transient_error",
30
- "invalid_discovery_artifacts",
31
- )
32
- DEEP_SCAN_TERMINAL_REASONS = ("saturated", "capped")
33
- DEEP_SCAN_WORKFLOW_VERSION = "deep-security-scan/v1"
34
25
  DEEP_SCAN_COORDINATOR_LEASE_SECONDS = 30
35
26
  DEEP_SCAN_LEGACY_COORDINATOR_GRACE_SECONDS = 120
36
27
  DEEP_SCAN_PUBLICATION_ERROR_SEPARATOR = "\nOriginal Deep Scan failure:\n"
37
28
 
38
29
 
39
- def register_subcommands(subparsers: Any, positive_int: Callable[[str], int]) -> None:
40
- begin_deep_scan = subparsers.add_parser("begin-deep-scan")
41
- begin_deep_scan.add_argument("--thread-id", required=True)
42
- begin_target = begin_deep_scan.add_mutually_exclusive_group(required=True)
43
- begin_target.add_argument("--scan-id")
44
- begin_target.add_argument("--target-path")
45
- begin_deep_scan.add_argument("--scope", default=".")
46
- begin_user_context = begin_deep_scan.add_mutually_exclusive_group()
47
- begin_user_context.add_argument("--user-context")
48
- begin_user_context.add_argument("--user-context-stdin", action="store_true")
49
- begin_deep_scan.add_argument("--scan-root")
50
- begin_deep_scan.add_argument("--claim-token")
51
- begin_deep_scan.add_argument("--model")
52
- begin_deep_scan.add_argument("--reasoning-effort")
53
- begin_deep_scan.add_argument("--available-parallelism", type=positive_int)
54
- begin_deep_scan.add_argument("--deep-scan-project-json")
55
- begin_deep_scan.add_argument("--project-config-path")
56
- begin_deep_scan.add_argument("--join-only", action="store_true")
57
- begin_deep_scan.add_argument("--workflow-version", default=DEEP_SCAN_WORKFLOW_VERSION)
58
-
59
- get_deep_scan = subparsers.add_parser("get-deep-scan")
60
- get_deep_scan.add_argument("--scan-id", required=True)
61
- get_deep_scan.add_argument("--thread-id", required=True)
62
-
63
- acknowledge_result = subparsers.add_parser("acknowledge-deep-scan-result")
64
- acknowledge_result.add_argument("--scan-id", required=True)
65
-
66
- claim_coordinator = subparsers.add_parser("claim-deep-scan-coordinator")
67
- claim_coordinator.add_argument("--scan-id", required=True)
68
- claim_coordinator.add_argument("--thread-id", required=True)
69
- claim_coordinator.add_argument("--claim-token")
70
- claim_coordinator.add_argument("--coordinator-generation", type=positive_int)
71
-
72
- upsert_deep_worker = subparsers.add_parser("upsert-deep-scan-worker")
73
- upsert_deep_worker.add_argument("--scan-id", required=True)
74
- upsert_deep_worker.add_argument("--worker-id", required=True)
75
- upsert_deep_worker.add_argument("--kind", choices=DEEP_SCAN_WORKER_KINDS, required=True)
76
- upsert_deep_worker.add_argument("--status", choices=DEEP_SCAN_WORKER_STATUSES, required=True)
77
- upsert_deep_worker.add_argument("--prompt-path", required=True)
78
- upsert_deep_worker.add_argument("--artifact-dir", required=True)
79
- upsert_deep_worker.add_argument("--result-manifest-path")
80
- upsert_deep_worker.add_argument("--attempt", type=non_negative_int)
81
- upsert_deep_worker.add_argument("--sdk-thread-id")
82
- upsert_deep_worker.add_argument("--error-message")
83
- upsert_deep_worker.add_argument(
84
- "--replaceable-failure-kind", choices=DEEP_SCAN_REPLACEABLE_FAILURE_KINDS
85
- )
86
- upsert_deep_worker.add_argument("--coordinator-generation", type=positive_int)
87
-
88
- claim_deep_dedup = subparsers.add_parser("claim-deep-scan-dedup")
89
- claim_deep_dedup.add_argument("--scan-id", required=True)
90
- claim_deep_dedup.add_argument("--worker-id", required=True)
91
- claim_deep_dedup.add_argument("--prompt-path", required=True)
92
- claim_deep_dedup.add_argument("--artifact-dir", required=True)
93
- claim_deep_dedup.add_argument("--input-worker-id", action="append", required=True)
94
- claim_deep_dedup.add_argument("--coordinator-generation", type=positive_int)
95
-
96
- commit_deep_dedup = subparsers.add_parser("commit-deep-scan-dedup")
97
- commit_deep_dedup.add_argument("--scan-id", required=True)
98
- commit_deep_dedup.add_argument("--worker-id", required=True)
99
- commit_deep_dedup.add_argument("--result-manifest-path", required=True)
100
- commit_deep_dedup.add_argument("--candidate-ledger-path")
101
- commit_deep_dedup.add_argument("--new-findings-count", type=non_negative_int, required=True)
102
- commit_deep_dedup.add_argument("--coordinator-generation", type=positive_int)
103
-
104
- finish_deep_scan = subparsers.add_parser("finish-deep-scan")
105
- finish_deep_scan.add_argument("--scan-id", required=True)
106
- finish_deep_scan.add_argument(
107
- "--terminal-reason", choices=DEEP_SCAN_TERMINAL_REASONS, required=True
108
- )
109
- finish_deep_scan.add_argument("--manifest-path", required=True)
110
- finish_deep_scan.add_argument("--staged-manifest-path")
111
- finish_deep_scan.add_argument("--omitted-worker-id", action="append", default=[])
112
- finish_deep_scan.add_argument("--coordinator-generation", type=positive_int)
113
-
114
- fail_deep_scan = subparsers.add_parser("fail-deep-scan")
115
- fail_deep_scan.add_argument("--scan-id", required=True)
116
- fail_deep_scan.add_argument("--message", required=True)
117
- fail_deep_scan.add_argument("--manifest-path")
118
- fail_deep_scan.add_argument("--staged-manifest-path")
119
- fail_deep_scan.add_argument(
120
- "--deep-status", choices=("failed", "interrupted"), default="failed"
121
- )
122
- fail_deep_scan.add_argument("--coordinator-generation", type=positive_int)
123
-
124
- publication_failure = subparsers.add_parser("record-deep-scan-publication-failure")
125
- publication_failure.add_argument("--scan-id", required=True)
126
- publication_failure.add_argument("--message", required=True)
127
- publication_failure.add_argument("--coordinator-generation", type=positive_int)
128
-
129
-
130
- def non_negative_int(value: str) -> int:
131
- parsed = int(value)
132
- if parsed < 0:
133
- raise argparse.ArgumentTypeError("expected a non-negative integer")
134
- return parsed
135
-
136
-
137
30
  _dependencies: Any = None
138
31
 
139
32
 
@@ -432,9 +325,12 @@ def deep_scan_state(connection: sqlite3.Connection, scan_id: str) -> dict[str, A
432
325
  "A capped Deep Scan without completed discoveries requires an empty "
433
326
  "candidate ledger."
434
327
  )
328
+ recipe = json.loads(scan["recipe_json"]) if scan["recipe_json"] is not None else {}
435
329
  return {
436
330
  "scanId": run["scan_id"],
437
331
  "sdkOwnsCompletion": scan["recipe_json"] is not None,
332
+ "serviceTier": run["service_tier"],
333
+ **({"severityRubric": recipe["severityRubric"]} if "severityRubric" in recipe else {}),
438
334
  "targetPath": scan["target_path"],
439
335
  "scope": scan["scope"],
440
336
  "includePaths": dependencies().requested_scan_paths(scan),
@@ -562,6 +458,7 @@ def ensure_deep_scan_run(
562
458
  workflow_version: str,
563
459
  timestamp: str,
564
460
  *,
461
+ service_tier: str | None,
565
462
  pending_target_project_path: str | None = None,
566
463
  ) -> sqlite3.Row:
567
464
  existing = connection.execute(
@@ -579,8 +476,8 @@ def ensure_deep_scan_run(
579
476
  scan_id, schema_version, workflow_version, status, phase,
580
477
  workers, subagents, stop_after_no_new, stop_after_consecutive_errors,
581
478
  max_discovery_runs, max_time_hours, discovery_user_context_json,
582
- created_at, updated_at, pending_target_project_path
583
- ) VALUES (?, 1, ?, 'running', 'setup', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
479
+ created_at, updated_at, service_tier, pending_target_project_path
480
+ ) VALUES (?, 1, ?, 'running', 'setup', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
584
481
  """,
585
482
  (
586
483
  scan["id"],
@@ -594,6 +491,7 @@ def ensure_deep_scan_run(
594
491
  json.dumps(scan["user_context"]),
595
492
  timestamp,
596
493
  timestamp,
494
+ service_tier,
597
495
  pending_target_project_path,
598
496
  ),
599
497
  )
@@ -768,7 +666,14 @@ def begin_deep_scan_for_scan(
768
666
  "UPDATE workspaces SET deep_scan_config_json = ? WHERE id = ? AND deep_scan_config_json IS NULL",
769
667
  (json.dumps(configuration), workspace["id"]),
770
668
  )
771
- ensure_deep_scan_run(connection, scan, config, workflow_version, dependencies().now())
669
+ ensure_deep_scan_run(
670
+ connection,
671
+ scan,
672
+ config,
673
+ workflow_version,
674
+ dependencies().now(),
675
+ service_tier=args.service_tier,
676
+ )
772
677
  return deep_scan_result(connection, scan_id, start_disposition="created")
773
678
 
774
679
 
@@ -917,6 +822,7 @@ def begin_deep_scan_for_target(
917
822
  config,
918
823
  workflow_version,
919
824
  timestamp,
825
+ service_tier=args.service_tier,
920
826
  pending_target_project_path=project_path,
921
827
  )
922
828
  return deep_scan_result(connection, scan_id, start_disposition="created")
@@ -2040,6 +1946,11 @@ def fail_from_parent_scan(
2040
1946
  message: str | None,
2041
1947
  timestamp: str,
2042
1948
  ) -> None:
1949
+ # Parent failure may supersede a prepared seal even after the coordinator succeeded.
1950
+ connection.execute(
1951
+ "UPDATE deep_scan_runs SET terminal_reviewed_surface_count = NULL WHERE scan_id = ?",
1952
+ (scan_id,),
1953
+ )
2043
1954
  connection.execute(
2044
1955
  """
2045
1956
  UPDATE deep_scan_runs
@@ -2057,7 +1968,7 @@ def cancel_from_parent_scan(connection: sqlite3.Connection, scan_id: str, timest
2057
1968
  """
2058
1969
  UPDATE deep_scan_runs
2059
1970
  SET status = 'canceled', phase = 'terminal', cancel_requested = 1,
2060
- completed_at = ?, updated_at = ?
1971
+ terminal_reviewed_surface_count = NULL, completed_at = ?, updated_at = ?
2061
1972
  WHERE scan_id = ? AND status IN ('running', 'succeeded')
2062
1973
  """,
2063
1974
  (timestamp, timestamp, scan_id),
@@ -14,10 +14,11 @@ import json
14
14
  import math
15
15
  import os
16
16
  import re
17
- import secrets
18
17
  import stat
19
18
  import struct
20
19
  import sys
20
+ from collections.abc import Callable, Iterator
21
+ from contextlib import contextmanager
21
22
  from datetime import datetime, timezone
22
23
  from pathlib import Path, PurePosixPath
23
24
  from typing import Any, NamedTuple, TextIO
@@ -28,6 +29,10 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))
28
29
  import report_projection
29
30
  import servicenow_avit
30
31
  import threat_model_projection
32
+ from posix_scan_local_files import (
33
+ descriptor_relative_writes_available as _descriptor_relative_writes_available,
34
+ )
35
+ from posix_scan_local_files import managed_fd, stage_write
31
36
  from review_state import checkpoint_review_state, review_state, review_summary
32
37
 
33
38
  SCHEMA_VERSION = "1.0"
@@ -500,15 +505,6 @@ def _is_windows() -> bool:
500
505
  return os.name == "nt"
501
506
 
502
507
 
503
- def _descriptor_relative_writes_available() -> bool:
504
- # os.replace accepts src_dir_fd/dst_dir_fd wherever descriptor-relative
505
- # os.rename is supported, but Python lists only os.rename in supports_dir_fd.
506
- required_operations = (os.mkdir, os.open, os.rename, os.stat, os.unlink)
507
- return hasattr(os, "O_NOFOLLOW") and all(
508
- operation in os.supports_dir_fd for operation in required_operations
509
- )
510
-
511
-
512
508
  def _windows_scan_local_files() -> Any:
513
509
  """Load the Win32 backend and shared stream comparison lazily."""
514
510
  import windows_scan_local_files
@@ -534,13 +530,12 @@ def _open_verified_scan_directory(
534
530
  raise _scan_local_directory_error(
535
531
  "scan directory: expected an existing non-symlink directory", exc
536
532
  ) from exc
537
- opened = os.fstat(descriptor)
538
- opened_identity = (opened.st_dev, opened.st_ino)
539
- if opened_identity != observed_identity or (
540
- expected_root_identity is not None and opened_identity != expected_root_identity
541
- ):
533
+ try:
534
+ if not os.path.samestat(expected, os.fstat(descriptor)):
535
+ raise ContractError("scan directory: changed while it was being opened")
536
+ except BaseException:
542
537
  os.close(descriptor)
543
- raise ContractError("scan directory: changed while it was being opened")
538
+ raise
544
539
  return descriptor
545
540
 
546
541
 
@@ -560,23 +555,41 @@ def scan_root_identity(scan_dir: Path) -> tuple[Path, tuple[int, int]]:
560
555
  os.close(descriptor)
561
556
 
562
557
 
563
- def _open_scan_local_directory(root_fd: int, parts: tuple[str, ...], *, create: bool) -> int:
558
+ def _open_scan_local_directory(
559
+ root_fd: int,
560
+ parts: tuple[str, ...],
561
+ *,
562
+ create: bool,
563
+ owner_read_write: bool = False,
564
+ sync_parents: bool = False,
565
+ ) -> int:
564
566
  descriptor = os.dup(root_fd)
565
567
  try:
566
568
  for part in parts:
569
+ if sync_parents:
570
+ os.fsync(descriptor)
567
571
  if create:
568
572
  try:
569
573
  os.mkdir(part, mode=0o700, dir_fd=descriptor)
570
574
  except FileExistsError:
571
575
  # The open below verifies that an existing entry is a real directory.
572
576
  pass
573
- next_descriptor = os.open(
577
+ else:
578
+ if owner_read_write:
579
+ mode = os.stat(part, dir_fd=descriptor, follow_symlinks=False).st_mode
580
+ if mode & stat.S_IRWXU != stat.S_IRWXU:
581
+ os.rmdir(part, dir_fd=descriptor)
582
+ raise ScanLocalIOError(
583
+ f"{part}: process umask prevents owner access to the new directory"
584
+ )
585
+ parent_descriptor = descriptor
586
+ descriptor = os.open(
574
587
  part,
575
588
  os.O_RDONLY | getattr(os, "O_DIRECTORY", 0) | getattr(os, "O_NOFOLLOW", 0),
576
- dir_fd=descriptor,
589
+ dir_fd=parent_descriptor,
577
590
  )
578
- os.close(descriptor)
579
- descriptor = next_descriptor
591
+ # If closing the parent fails, cleanup now owns the child.
592
+ os.close(parent_descriptor)
580
593
  return descriptor
581
594
  except BaseException:
582
595
  os.close(descriptor)
@@ -766,6 +779,40 @@ def _sha256_scan_local_file(scan_dir: Path, relative_path: str, context: str) ->
766
779
  return digest.hexdigest()
767
780
 
768
781
 
782
+ def scan_local_file_version(descriptor: int) -> tuple[os.stat_result, int]:
783
+ metadata = os.fstat(descriptor)
784
+ changed = (
785
+ _windows_scan_local_files().file_change_time(descriptor)
786
+ if _is_windows()
787
+ else metadata.st_ctime_ns
788
+ )
789
+ return metadata, changed
790
+
791
+
792
+ def _scan_local_write_path(
793
+ scan_dir: Path, relative_path: str, external_name: bool
794
+ ) -> tuple[Path, str]:
795
+ scan_dir = _require_scan_directory(scan_dir)
796
+ if external_name:
797
+ if relative_path in {"", ".", ".."} or "/" in relative_path or "\0" in relative_path:
798
+ raise ContractError("external output path: expected a safe file name")
799
+ else:
800
+ relative_path = _require_portable_relative_path(relative_path, "scan-local output path")
801
+ return scan_dir, relative_path
802
+
803
+
804
+ @contextmanager
805
+ def _windows_write_errors(backend: Any, relative_path: str) -> Iterator[None]:
806
+ try:
807
+ yield
808
+ except FileExistsError:
809
+ raise
810
+ except backend.WindowsScanLocalPathError as exc:
811
+ raise ContractError(f"{relative_path}: {exc}") from exc
812
+ except OSError as exc:
813
+ raise ScanLocalIOError(f"{relative_path}: {exc}") from exc
814
+
815
+
769
816
  def write_scan_local_bytes(
770
817
  scan_dir: Path,
771
818
  relative_path: str,
@@ -774,111 +821,96 @@ def write_scan_local_bytes(
774
821
  external_name: bool = False,
775
822
  expected_root_identity: tuple[int, int] | None = None,
776
823
  owner_read_write: bool = False,
824
+ replace_existing: bool = True,
777
825
  ) -> None:
778
- scan_dir = _require_scan_directory(scan_dir)
779
- if external_name:
780
- if relative_path in {"", ".", ".."} or "/" in relative_path or "\0" in relative_path:
781
- raise ContractError("external output path: expected a safe file name")
782
- else:
783
- relative_path = _require_portable_relative_path(relative_path, "scan-local output path")
784
- path = scan_dir / relative_path
826
+ if _is_windows() and not _descriptor_relative_writes_available():
827
+ scan_dir, relative_path = _scan_local_write_path(scan_dir, relative_path, external_name)
828
+ backend = _windows_scan_local_files()
829
+ with _windows_write_errors(backend, relative_path):
830
+ backend.atomic_write(
831
+ scan_dir,
832
+ relative_path,
833
+ payload,
834
+ expected_root_identity=expected_root_identity,
835
+ replace_existing=replace_existing,
836
+ )
837
+ return
838
+ with stage_scan_local_bytes(
839
+ scan_dir,
840
+ relative_path,
841
+ payload,
842
+ external_name=external_name,
843
+ expected_root_identity=expected_root_identity,
844
+ owner_read_write=owner_read_write,
845
+ replace_existing=replace_existing,
846
+ ) as publish:
847
+ publish()
848
+
849
+
850
+ @contextmanager
851
+ def stage_scan_local_bytes(
852
+ scan_dir: Path,
853
+ relative_path: str,
854
+ payload: bytes,
855
+ *,
856
+ external_name: bool = False,
857
+ expected_root_identity: tuple[int, int] | None = None,
858
+ owner_read_write: bool = False,
859
+ replace_existing: bool = False,
860
+ ) -> Iterator[Callable[..., tuple[os.stat_result, int]]]:
861
+ scan_dir, relative_path = _scan_local_write_path(scan_dir, relative_path, external_name)
785
862
  if not _descriptor_relative_writes_available():
786
863
  if not _is_windows():
787
864
  raise ContractError("scan-local output requires descriptor-relative file operations")
788
865
  backend = _windows_scan_local_files()
789
- try:
790
- backend.atomic_write(
866
+ with _windows_write_errors(backend, relative_path):
867
+ with backend.stage_write(
791
868
  scan_dir,
792
869
  relative_path,
793
870
  payload,
794
871
  expected_root_identity=expected_root_identity,
795
- )
796
- except backend.WindowsScanLocalPathError as exc:
797
- raise ContractError(f"{relative_path}: {exc}") from exc
798
- except OSError as exc:
799
- raise ScanLocalIOError(f"{relative_path}: {exc}") from exc
872
+ replace_existing=replace_existing,
873
+ ) as publish:
874
+ yield publish
800
875
  return
801
- root_fd: int | None = None
802
- parent_fd: int | None = None
803
- temp_name: str | None = None
804
- try:
805
- root_fd = _open_verified_scan_directory(scan_dir, expected_root_identity)
876
+ with managed_fd(_open_verified_scan_directory(scan_dir, expected_root_identity)) as root_fd:
806
877
  parts = PurePosixPath(relative_path).parts
807
878
  try:
808
- parent_fd = _open_scan_local_directory(root_fd, parts[:-1], create=True)
879
+ parent_fd = _open_scan_local_directory(
880
+ root_fd, parts[:-1], create=True, owner_read_write=owner_read_write
881
+ )
809
882
  except OSError as exc:
810
883
  raise _scan_local_directory_error(
811
884
  f"{relative_path}: expected a path inside the scan directory", exc
812
885
  ) from exc
813
- # The held descriptor is the authority for the validated parent. A
814
- # concurrent rename cannot redirect later operations through a
815
- # replacement path or link.
816
- try:
817
- metadata = os.stat(parts[-1], dir_fd=parent_fd, follow_symlinks=False)
818
- except FileNotFoundError:
819
- pass
820
- else:
821
- if not stat.S_ISREG(metadata.st_mode):
822
- raise ContractError(f"{relative_path}: expected a regular non-symlink file")
823
- try:
824
- existing_fd = os.open(
825
- parts[-1],
826
- os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0) | getattr(os, "O_NONBLOCK", 0),
827
- dir_fd=parent_fd,
828
- )
829
- except OSError as exc:
830
- if exc.errno not in {errno.ENOENT, errno.EACCES, errno.EPERM}:
831
- raise
832
- else:
833
- try:
834
- opened = os.fstat(existing_fd)
835
- if not stat.S_ISREG(opened.st_mode):
836
- raise ContractError(f"{relative_path}: expected a regular non-symlink file")
837
- if (opened.st_dev, opened.st_ino) != (
838
- metadata.st_dev,
839
- metadata.st_ino,
840
- ):
841
- raise ContractError(f"{relative_path}: changed while it was being opened")
842
- if expected_root_identity is not None and opened.st_size == len(payload):
843
- try:
844
- with os.fdopen(existing_fd, "rb") as handle:
845
- existing_fd = -1
846
- if _windows_scan_local_files().stream_matches_payload(
847
- handle, payload
848
- ):
849
- return
850
- except OSError:
851
- # A failed content comparison still allows an atomic replacement.
852
- pass
853
- finally:
854
- if existing_fd >= 0:
855
- os.close(existing_fd)
856
- temp_name = f".{path.name}.{secrets.token_hex(8)}.tmp"
857
- temp_fd = os.open(temp_name, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600, dir_fd=parent_fd)
858
- with os.fdopen(temp_fd, "wb") as handle:
859
- if owner_read_write:
860
- # Generated Markdown must remain editable under a restrictive umask.
861
- os.fchmod(handle.fileno(), 0o600)
862
- handle.write(payload)
863
- handle.flush()
864
- os.fsync(handle.fileno())
865
- os.replace(temp_name, parts[-1], src_dir_fd=parent_fd, dst_dir_fd=parent_fd)
866
- temp_name = None
867
- finally:
868
- try:
869
- if temp_name is not None and parent_fd is not None:
870
- try:
871
- os.unlink(temp_name, dir_fd=parent_fd)
872
- except FileNotFoundError:
873
- # The temporary file is already gone, so cleanup is complete.
874
- pass
875
- finally:
876
- try:
877
- if parent_fd is not None:
878
- os.close(parent_fd)
879
- finally:
880
- if root_fd is not None:
881
- os.close(root_fd)
886
+
887
+ with managed_fd(parent_fd):
888
+
889
+ def check_parent(directory: Path) -> None:
890
+ # Admission can follow an archive while the staged parent stays open.
891
+ root = os.fstat(root_fd)
892
+ with (
893
+ managed_fd(
894
+ _open_verified_scan_directory(directory, (root.st_dev, root.st_ino))
895
+ ) as current,
896
+ managed_fd(
897
+ _open_scan_local_directory(current, parts[:-1], create=False)
898
+ ) as parent,
899
+ ):
900
+ if not os.path.samestat(os.fstat(parent_fd), os.fstat(parent)):
901
+ raise ContractError(f"{relative_path}: parent changed before publication")
902
+
903
+ with stage_write(
904
+ parent_fd,
905
+ relative_path,
906
+ payload,
907
+ owner_read_write=owner_read_write,
908
+ replace_existing=replace_existing,
909
+ compare_existing=expected_root_identity is not None,
910
+ check_parent=check_parent,
911
+ contract_error=ContractError,
912
+ ) as publish:
913
+ yield publish
882
914
 
883
915
 
884
916
  def _remove_scan_local_file_if_exists(scan_dir: Path, relative_path: str) -> None:
@@ -1842,6 +1874,18 @@ def _validate_coverage(manifest: dict[str, Any], coverage: dict[str, Any], scan_
1842
1874
  _require_safe_json_value(coverage, "coverage.json")
1843
1875
 
1844
1876
 
1877
+ def _require_unique_artifact_path(artifact: Any, context: str, collision_keys: set[str]) -> str:
1878
+ if not isinstance(artifact, dict):
1879
+ raise ContractError(f"{context}: expected an object")
1880
+ value = _require_str(artifact, "path", context)
1881
+ path = _require_portable_relative_path(value, f"{context}.path")
1882
+ collision_key = path.lower()
1883
+ if collision_key in collision_keys:
1884
+ raise ContractError(f"{context}.path: duplicate artifact path")
1885
+ collision_keys.add(collision_key)
1886
+ return path
1887
+
1888
+
1845
1889
  def _validate_manifest(manifest: dict[str, Any]) -> None:
1846
1890
  if manifest.get("documentType") != "codex-security.scan-manifest":
1847
1891
  raise ContractError("manifest.documentType: expected codex-security.scan-manifest")
@@ -1873,16 +1917,8 @@ def _validate_manifest(manifest: dict[str, Any]) -> None:
1873
1917
  artifact_collision_keys: set[str] = set()
1874
1918
  for index, artifact in enumerate(artifacts):
1875
1919
  context = f"manifest.scan.artifacts[{index}]"
1876
- if not isinstance(artifact, dict):
1877
- raise ContractError(f"{context}: expected an object")
1878
- path = _require_portable_relative_path(
1879
- _require_str(artifact, "path", context), f"{context}.path"
1880
- )
1881
- collision_key = path.lower()
1882
- if collision_key in artifact_collision_keys:
1883
- raise ContractError(f"{context}.path: duplicate artifact path")
1920
+ path = _require_unique_artifact_path(artifact, context, artifact_collision_keys)
1884
1921
  artifact_paths.add(path)
1885
- artifact_collision_keys.add(collision_key)
1886
1922
  _require_str(artifact, "sha256", context)
1887
1923
  _require_str(artifact, "mediaType", context)
1888
1924
  for required_path in ("findings.json", *(["coverage.json"] if "coverageRef" in scan else [])):
@@ -2201,17 +2237,9 @@ def _legacy_sealed_findings_for_validation(findings: dict[str, Any]) -> dict[str
2201
2237
  legacy_evidence = finding.get("code_evidence")
2202
2238
  if isinstance(legacy_evidence, list):
2203
2239
  compatible_legacy_evidence = []
2204
- for evidence in legacy_evidence:
2205
- if not isinstance(evidence, dict):
2206
- continue
2240
+ for evidence in report_projection.code_evidence_rows(legacy_evidence):
2207
2241
  evidence_id = evidence.get("id")
2208
- evidence_code = evidence.get("code")
2209
- if (
2210
- not isinstance(evidence_id, str)
2211
- or not evidence_id.strip()
2212
- or not isinstance(evidence_code, str)
2213
- or not evidence_code.strip()
2214
- ):
2242
+ if not isinstance(evidence_id, str) or not evidence_id.strip():
2215
2243
  continue
2216
2244
  if evidence_id in evidence_ids:
2217
2245
  continue
@@ -2520,23 +2548,17 @@ def _finding_evidence_strength(finding: dict[str, Any]) -> int:
2520
2548
  section = finding.get(section_name)
2521
2549
  if not isinstance(section, dict):
2522
2550
  continue
2523
- for evidence_name in ("codeEvidence", "code_evidence"):
2524
- embedded = section.get(evidence_name)
2525
- if not isinstance(embedded, list):
2551
+ for item in report_projection.embedded_code_evidence(section):
2552
+ code = item["code"]
2553
+ if code in seen_codes:
2526
2554
  continue
2527
- for item in embedded:
2528
- if not isinstance(item, dict):
2555
+ evidence_id = item.get("id")
2556
+ if isinstance(evidence_id, str) and evidence_id.strip():
2557
+ if evidence_id in seen_ids:
2529
2558
  continue
2530
- code = item.get("code")
2531
- if not isinstance(code, str) or not code.strip() or code in seen_codes:
2532
- continue
2533
- evidence_id = item.get("id")
2534
- if isinstance(evidence_id, str) and evidence_id.strip():
2535
- if evidence_id in seen_ids:
2536
- continue
2537
- seen_ids.add(evidence_id)
2538
- seen_codes.add(code)
2539
- strength += 1
2559
+ seen_ids.add(evidence_id)
2560
+ seen_codes.add(code)
2561
+ strength += 1
2540
2562
  code = section.get("code")
2541
2563
  if isinstance(code, str) and code.strip() and code not in seen_codes:
2542
2564
  seen_codes.add(code)
@@ -2776,15 +2798,7 @@ def _validate_existing_seal(
2776
2798
  artifact_collision_keys: set[str] = set()
2777
2799
  for index, artifact in enumerate(artifacts):
2778
2800
  context = f"manifest.scan.artifacts[{index}]"
2779
- if not isinstance(artifact, dict):
2780
- raise ContractError(f"{context}: expected an object")
2781
- path = _require_portable_relative_path(
2782
- _require_str(artifact, "path", context), f"{context}.path"
2783
- )
2784
- collision_key = path.lower()
2785
- if collision_key in artifact_collision_keys:
2786
- raise ContractError(f"{context}.path: duplicate artifact path")
2787
- artifact_collision_keys.add(collision_key)
2801
+ path = _require_unique_artifact_path(artifact, context, artifact_collision_keys)
2788
2802
  expected_sha256 = _require_str(artifact, "sha256", context)
2789
2803
  contents = (artifact_contents or {}).get(path)
2790
2804
  actual_sha256 = (