@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
@@ -54,6 +54,7 @@ from finalize_scan_contract import (
54
54
  open_scan_local_file_descriptor,
55
55
  )
56
56
  from finding_preview import bounded_finding_details
57
+ from windows_scan_local_files import pin_replay_metadata
57
58
  from workbench import handoff
58
59
  from workbench.storage import (
59
60
  create_private_directory,
@@ -76,7 +77,6 @@ from workbench_constants import (
76
77
  FINDING_SUMMARY_BYTES,
77
78
  FINDING_TITLE_BYTES,
78
79
  FINDINGS_RESULT_LIMIT,
79
- PATCH_PREVIEW_BYTES,
80
80
  SQLITE_RETRY_ATTEMPTS,
81
81
  )
82
82
  from workbench_feedback import get_scan_feedback
@@ -86,6 +86,10 @@ from workbench_scan_start import (
86
86
  archive_scan,
87
87
  insert_running_scan,
88
88
  loaded_plugin_version,
89
+ parse_scan_recipe,
90
+ prepare_cli_scan_target,
91
+ register_windows_resume_output,
92
+ restore_cli_scan_archive,
89
93
  safe_segment,
90
94
  scan_diff_identity,
91
95
  scan_target_identity,
@@ -93,6 +97,8 @@ from workbench_scan_start import (
93
97
  )
94
98
  from workbench_schema import (
95
99
  MIGRATIONS,
100
+ migration_target_paths,
101
+ recorded_git_checkout_roots,
96
102
  )
97
103
  from workbench_schema import (
98
104
  apply_migrations as apply_schema_migrations,
@@ -113,10 +119,12 @@ from workbench_source_scopes import (
113
119
  capture_source_scopes,
114
120
  expected_target_kinds,
115
121
  public_scan_recipe,
122
+ requested_exclude_paths,
116
123
  requested_scan_paths,
117
124
  safe_source_path,
118
125
  )
119
126
  from workbench_target import (
127
+ checked_scan_target,
120
128
  clean_worktree_content_digest,
121
129
  copy_directory_excluding,
122
130
  copy_git_worktree_files,
@@ -130,16 +138,25 @@ from workbench_target import (
130
138
  git_submodule_entries,
131
139
  git_target_metadata,
132
140
  git_worktree_context,
141
+ rejected_checkout_roots,
133
142
  remediation_checkout_snapshot,
134
143
  require_remediation_target,
135
144
  require_scan_target_identity,
136
145
  require_scan_target_unchanged,
137
146
  restore_directory_junctions,
138
147
  scan_target_warning,
148
+ scoped_git_discovery,
149
+ scoped_regular_file_count,
139
150
  worktree_content_digest,
140
151
  worktree_content_digest_for_context,
141
152
  )
142
- from workbench_target_state import backfill_security_targets, ensure_security_target
153
+ from workbench_target_state import (
154
+ RepositoryScanScope,
155
+ backfill_security_targets,
156
+ ensure_security_target,
157
+ register_security_target,
158
+ require_scan_checkout_owner,
159
+ )
143
160
  from workbench_validation import (
144
161
  bounded_output_text,
145
162
  optional_text,
@@ -238,13 +255,21 @@ def release_completion_file_lock(descriptor: int) -> None:
238
255
  windows_file_lock.locking(descriptor, windows_file_lock.LK_UNLCK, 1)
239
256
 
240
257
 
241
- def connect(*, deferred: bool = False) -> sqlite3.Connection:
258
+ def connect(
259
+ *,
260
+ deferred: bool = False,
261
+ discovery_roots: tuple[Path, ...] = (),
262
+ in_memory: bool = False,
263
+ ) -> sqlite3.Connection:
242
264
  """Open the workbench SQLite database and bring its schema up to date.
243
265
 
244
266
  Args:
245
267
  deferred (bool): Let the first migration attempt defer its write lock.
246
268
  Retries after lock contention use an immediate transaction.
247
269
 
270
+ discovery_roots: Additional local paths for bounded target discovery.
271
+ in_memory: Keep a fresh profile read entirely in memory.
272
+
248
273
  Returns:
249
274
  sqlite3.Connection: A caller-owned connection with named rows, foreign
250
275
  keys enabled, and write-ahead logging.
@@ -260,13 +285,14 @@ def connect(*, deferred: bool = False) -> sqlite3.Connection:
260
285
  "the scanned repository."
261
286
  )
262
287
  try:
263
- create_private_directory(path.parent)
288
+ if not in_memory:
289
+ create_private_directory(path.parent)
264
290
  except OSError:
265
291
  print(guidance, file=sys.stderr)
266
292
  raise
267
293
  for attempt in range(SQLITE_RETRY_ATTEMPTS):
268
294
  try:
269
- connection = sqlite3.connect(path, timeout=5)
295
+ connection = sqlite3.connect(":memory:" if in_memory else path, timeout=5)
270
296
  except sqlite3.OperationalError:
271
297
  print(guidance, file=sys.stderr)
272
298
  raise
@@ -275,9 +301,12 @@ def connect(*, deferred: bool = False) -> sqlite3.Connection:
275
301
  connection.execute("PRAGMA foreign_keys = ON")
276
302
  connection.execute("PRAGMA busy_timeout = 5000")
277
303
  # Keep writer admission retries; readers only wait when a repair needs to write.
278
- apply_migrations(connection, immediate=not deferred or attempt > 0)
304
+ apply_migrations(
305
+ connection, immediate=not deferred or attempt > 0, discovery_roots=discovery_roots
306
+ )
279
307
  connection.execute("PRAGMA journal_mode = WAL")
280
- path.chmod(0o600)
308
+ if not in_memory:
309
+ path.chmod(0o600)
281
310
  return connection
282
311
  except sqlite3.OperationalError as exc:
283
312
  connection.close()
@@ -288,9 +317,30 @@ def connect(*, deferred: bool = False) -> sqlite3.Connection:
288
317
  raise AssertionError("SQLite retry loop exhausted unexpectedly.")
289
318
 
290
319
 
291
- def apply_migrations(connection: sqlite3.Connection, *, immediate: bool = False) -> None:
320
+ def begin_immediate_with_retry(connection: sqlite3.Connection) -> None:
321
+ for attempt in range(SQLITE_RETRY_ATTEMPTS):
322
+ try:
323
+ connection.execute("BEGIN IMMEDIATE")
324
+ return
325
+ except sqlite3.OperationalError as exc:
326
+ if attempt == SQLITE_RETRY_ATTEMPTS - 1 or not sqlite_busy(exc):
327
+ raise
328
+ time.sleep(0.05 * (2**attempt))
329
+
330
+
331
+ def apply_migrations(
332
+ connection: sqlite3.Connection,
333
+ *,
334
+ immediate: bool = False,
335
+ discovery_roots: tuple[Path, ...] = (),
336
+ ) -> None:
292
337
  apply_schema_migrations(
293
- connection, MIGRATIONS, now, backfill_security_targets, immediate=immediate
338
+ connection,
339
+ MIGRATIONS,
340
+ now,
341
+ backfill_security_targets,
342
+ immediate=immediate,
343
+ discovery_roots=discovery_roots,
294
344
  )
295
345
 
296
346
 
@@ -329,7 +379,7 @@ def scan_contract(scan: sqlite3.Row) -> dict[str, Any]:
329
379
  return {
330
380
  "diffTarget": stored_diff_target(scan),
331
381
  "scope": {
332
- "requiredExcludePaths": [],
382
+ "requiredExcludePaths": requested_exclude_paths(scan),
333
383
  "requestedPath": scan["scope"],
334
384
  "filePaths": requested_scan_file_paths(scan),
335
385
  **(
@@ -342,24 +392,7 @@ def scan_contract(scan: sqlite3.Row) -> dict[str, Any]:
342
392
  }
343
393
 
344
394
 
345
- def expected_coverage_mode(scan: sqlite3.Row) -> str:
346
- """Return the coverage mode implied by the recorded scope, scan mode, and diff target kind."""
347
- if scan["mode"] == "diff":
348
- mode = {
349
- "commit": "commit",
350
- "range": "branch_diff",
351
- "working_tree": "working_tree",
352
- }.get(scan["diff_target_kind"])
353
- if mode is None:
354
- raise SystemExit("This migrated diff scan does not have a validated change set.")
355
- return mode
356
- if scan["scope"] != "." or (
357
- "recipe_json" in scan.keys()
358
- and scan["recipe_json"] is not None
359
- and json.loads(scan["recipe_json"])["target"]["kind"] == "paths"
360
- ):
361
- return "scoped_path"
362
- return "deep_repository" if scan["mode"] == "deep" else "repository"
395
+ expected_coverage_mode = scan_history.expected_coverage_mode
363
396
 
364
397
 
365
398
  def workbench_completion_binding(
@@ -460,7 +493,7 @@ def verify_manifest_binding(scan: sqlite3.Row, manifest: dict[str, Any]) -> None
460
493
  include_paths = scope.get("includePaths")
461
494
  if not isinstance(include_paths, list):
462
495
  raise SystemExit("scan-manifest.json scope includePaths must be an array.")
463
- if scope.get("excludePaths") != []:
496
+ if scope.get("excludePaths") != expected_contract["scope"]["requiredExcludePaths"]:
464
497
  raise SystemExit(
465
498
  "scan-manifest.json scope excludePaths must match the workbench scan scope."
466
499
  )
@@ -530,6 +563,8 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
530
563
  diff_content_digest = (
531
564
  optional_text(args.diff_content_digest, maximum=128) if args.mode == "diff" else None
532
565
  )
566
+ target_path_unvalidated = False
567
+ rejected_roots = None
533
568
  if target_path:
534
569
  try:
535
570
  inspected = inspect_setup_values(
@@ -549,11 +584,17 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
549
584
  diff_head_revision = inspected["diffTarget"]["headRevision"]
550
585
  diff_content_digest = inspected["diffTarget"].get("contentDigest")
551
586
  except SystemExit:
552
- # Preserve an incomplete setup so workspace_state can report its validation error.
553
- pass
587
+ # Setup may fail on scope even when the target itself is valid.
588
+ try:
589
+ require_target(target_path)
590
+ except SystemExit:
591
+ target_path_unvalidated = True
592
+ rejected_roots = rejected_checkout_roots(target_path)
554
593
  with connection:
555
594
  target_id = (
556
- ensure_security_target(connection, target_path) if target_path is not None else None
595
+ ensure_security_target(connection, target_path)
596
+ if target_path is not None and not target_path_unvalidated
597
+ else None
557
598
  )
558
599
  connection.execute(
559
600
  """
@@ -561,8 +602,8 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
561
602
  id, thread_id, target_id, target_path, target_title, target_summary,
562
603
  default_scope, default_mode,
563
604
  user_context, diff_target_kind, diff_base_revision, diff_head_revision,
564
- diff_content_digest, created_at, updated_at
565
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
605
+ diff_content_digest, created_at, updated_at, target_path_unvalidated, rejected_checkout_roots_json
606
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
566
607
  """,
567
608
  (
568
609
  workspace_id,
@@ -580,6 +621,8 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
580
621
  diff_content_digest,
581
622
  timestamp,
582
623
  timestamp,
624
+ target_path_unvalidated,
625
+ json.dumps(rejected_roots) if rejected_roots is not None else None,
583
626
  ),
584
627
  )
585
628
  return workspace_state(connection, workspace_id)
@@ -614,7 +657,10 @@ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) ->
614
657
  SET target_id = ?, target_path = ?, target_title = ?, target_summary = ?, default_scope = ?,
615
658
  default_mode = ?, user_context = ?, diff_target_kind = ?,
616
659
  diff_base_revision = ?, diff_head_revision = ?, diff_content_digest = ?,
617
- deep_scan_config_json = ?, submitted = 1, updated_at = ?
660
+ deep_scan_config_json = ?, submitted = 1, updated_at = ?, target_path_unvalidated = 0,
661
+ -- JSON null keeps PATH discovery disabled after a legacy rejection.
662
+ rejected_checkout_roots_json = COALESCE(rejected_checkout_roots_json,
663
+ CASE WHEN target_path_unvalidated = 1 AND target_id IS NULL THEN 'null' END)
618
664
  WHERE id = ? AND active_scan_id IS NULL
619
665
  """,
620
666
  (
@@ -665,7 +711,8 @@ def require_working_tree_unchanged(target: Path, diff_target: dict[str, str] | N
665
711
  and diff_target["kind"] == "working_tree"
666
712
  and (
667
713
  git_revision(target) != diff_target["headRevision"]
668
- or worktree_content_digest(target) != diff_target["contentDigest"]
714
+ or worktree_content_digest(target, expected_digest=diff_target["contentDigest"])
715
+ != diff_target["contentDigest"]
669
716
  )
670
717
  ):
671
718
  raise SystemExit("The selected scan target changed while the scan was starting. Try again.")
@@ -687,6 +734,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
687
734
  (workspace["id"],),
688
735
  ).fetchone()
689
736
  if active is not None:
737
+ require_scan_checkout_owner(connection, active)
690
738
  return workspace_state(connection, workspace["id"], result_scan_id=active["id"])
691
739
  workspace_version = workspace["updated_at"]
692
740
  scan_id = str(uuid.uuid4())
@@ -736,6 +784,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
736
784
  (workspace["id"],),
737
785
  ).fetchone()
738
786
  if active is not None:
787
+ require_scan_checkout_owner(connection, active)
739
788
  if manages_transaction:
740
789
  connection.commit()
741
790
  return workspace_state(connection, workspace["id"], result_scan_id=active["id"])
@@ -762,6 +811,11 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
762
811
  "This Codex thread already has an active Deep Scan for the selected "
763
812
  "target and scope. Rejoin that scan instead of starting another one."
764
813
  )
814
+ registration = register_security_target(connection, str(current_target))
815
+ if registration.target_id != workspace["target_id"]:
816
+ raise SystemExit(
817
+ "The saved workspace no longer matches the selected repository target."
818
+ )
765
819
  insert_running_scan(
766
820
  connection,
767
821
  scan_id=scan_id,
@@ -770,6 +824,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
770
824
  scope=scope,
771
825
  diff_target=diff_target,
772
826
  target_identity=target_identity,
827
+ repository_generation=registration.repository_generation,
773
828
  source_scopes=source_scopes,
774
829
  target_root=target_root,
775
830
  target_summary=target_summary,
@@ -889,6 +944,7 @@ def _start_prompt_driven_scan(
889
944
  ),
890
945
  ).fetchone()
891
946
  if existing is not None:
947
+ require_scan_checkout_owner(connection, existing)
892
948
  connection.commit()
893
949
  return {
894
950
  **scan_context(connection, existing["id"], model_thread_id=thread_id),
@@ -898,7 +954,8 @@ def _start_prompt_driven_scan(
898
954
  workspace_id = str(uuid.uuid4())
899
955
  scan_id = str(uuid.uuid4())
900
956
  timestamp = now()
901
- target_id = ensure_security_target(connection, target_path)
957
+ registration = register_security_target(connection, target_path)
958
+ target_id = registration.target_id
902
959
  connection.execute(
903
960
  """
904
961
  INSERT INTO workspaces (
@@ -931,6 +988,7 @@ def _start_prompt_driven_scan(
931
988
  scope=scope,
932
989
  diff_target=diff_target,
933
990
  target_identity=target_identity,
991
+ repository_generation=registration.repository_generation,
934
992
  source_scopes=source_scopes,
935
993
  target_root=target_root,
936
994
  target_summary=target_summary,
@@ -1379,6 +1437,7 @@ def complete_scan_locked(
1379
1437
  for kind, filename in ARTIFACTS.items()
1380
1438
  }
1381
1439
  manifest_digest = published_manifest_digest(scan_dir, manifest)
1440
+ reported_count = progress.reported_scope_file_count(_WORKBENCH_DB_CONTEXT, scan)
1382
1441
  if prepare_only:
1383
1442
  connection.execute("BEGIN IMMEDIATE")
1384
1443
  with connection:
@@ -1388,6 +1447,22 @@ def complete_scan_locked(
1388
1447
  )
1389
1448
  if updated.rowcount != 1:
1390
1449
  raise SystemExit("Only a running scan can be prepared for completion.")
1450
+ if reported_count is not None:
1451
+ connection.execute(
1452
+ """
1453
+ UPDATE scan_progress SET scope_file_count = ?, updated_at = ?
1454
+ WHERE scan_id = (SELECT id FROM scans WHERE id = ? AND scan_dir = ?
1455
+ AND handoff_status = ? AND handoff_claim_token IS ?)
1456
+ """,
1457
+ (
1458
+ reported_count,
1459
+ completion_timestamp,
1460
+ scan_id,
1461
+ scan["scan_dir"],
1462
+ scan["handoff_status"],
1463
+ scan["handoff_claim_token"],
1464
+ ),
1465
+ )
1391
1466
  context = scan_context(connection, scan["id"])
1392
1467
  context["targetWarnings"] = target_warnings
1393
1468
  return context
@@ -1430,6 +1505,8 @@ def complete_scan_locked(
1430
1505
  connection.commit()
1431
1506
  return scan_context(connection, scan["id"])
1432
1507
  deep_scan.require_deep_scan_ready_for_parent_completion(connection, scan)
1508
+ if scan["scan_dir"] != str(scan_dir):
1509
+ reported_count = None
1433
1510
  connection.execute("DELETE FROM scan_artifacts WHERE scan_id = ?", (scan["id"],))
1434
1511
  for kind, path in artifacts.items():
1435
1512
  if path is not None:
@@ -1445,10 +1522,17 @@ def complete_scan_locked(
1445
1522
  UPDATE scan_progress
1446
1523
  SET reportable_findings_count = ?, phase_items_total = ?,
1447
1524
  phase_items_completed = ?, phase_progress_unit = 'report_artifacts',
1448
- updated_at = ?
1525
+ scope_file_count = COALESCE(?, scope_file_count), updated_at = ?
1449
1526
  WHERE scan_id = ?
1450
1527
  """,
1451
- (finding_count, len(artifacts), len(artifacts), timestamp, scan["id"]),
1528
+ (
1529
+ finding_count,
1530
+ len(artifacts),
1531
+ len(artifacts),
1532
+ reported_count,
1533
+ timestamp,
1534
+ scan["id"],
1535
+ ),
1452
1536
  )
1453
1537
  updated = connection.execute(
1454
1538
  """
@@ -1498,25 +1582,32 @@ def register_cli_scan(
1498
1582
  *,
1499
1583
  before_archive: Callable[[], None] | None = None,
1500
1584
  ) -> dict[str, Any]:
1501
- """Register a CLI scan and its selected target before execution begins.
1585
+ """Register the scan recipe and target identity, archiving any previous output atomically."""
1586
+ # A selected plugin may replace __main__ while delegating to this workbench.
1587
+ before_output_change = before_archive or getattr(
1588
+ sys, "_codex_security_before_output_change", None
1589
+ )
1590
+
1591
+ def acknowledge_output_change() -> None:
1592
+ nonlocal before_output_change
1593
+ if before_output_change is not None:
1594
+ before_output_change()
1595
+ before_output_change = None
1502
1596
 
1503
- Record the launch recipe and target identity with the new scan. When reusing
1504
- an output directory, coordinate archiving with registration so previous results
1505
- can still be located. Return the scan ID, contract, and target metadata.
1506
- """
1507
1597
  repository = require_target(args.repository)
1508
1598
  require_scannable_target(repository)
1509
- scan_dir = None
1510
1599
  if not args.archive_existing or args.archived_scan_dir is not None:
1511
1600
  # Preserve early output rejection when this call will not move the directory.
1512
- scan_dir = require_cli_scan_directory(repository, args)
1601
+ require_cli_scan_directory(repository, args)
1513
1602
  user_context = None
1514
1603
  workflow_id = None
1604
+ hosted = False
1515
1605
  surface = None
1516
1606
  package_version = None
1517
1607
  if args.registration_json_stdin:
1518
1608
  registration = json.load(sys.stdin)
1519
1609
  recipe_json = json.dumps(registration["recipe"], ensure_ascii=False, separators=(",", ":"))
1610
+ hosted = registration.get("hosted") is True
1520
1611
  user_context = registration.get("userContext")
1521
1612
  workflow_id = registration.get("workflowId")
1522
1613
  if registration.get("surface") in ("cli", "sdk"):
@@ -1554,14 +1645,29 @@ def register_cli_scan(
1554
1645
  raise SystemExit("Working-tree HEAD changed before the scan started.")
1555
1646
  diff_target["contentDigest"] = worktree_content_digest(repository)
1556
1647
  mode = "diff" if diff_target is not None else recipe["mode"]
1557
- target_identity = scan_target_identity(repository, diff_target)
1648
+ target_identity, resume_target = prepare_cli_scan_target(
1649
+ repository, diff_target, mode, launch_kind
1650
+ )
1558
1651
  source_scopes = capture_source_scopes(
1559
1652
  repository,
1560
1653
  target_identity,
1561
1654
  paths or ["."],
1562
1655
  diff_target_kind=diff_target["kind"] if diff_target is not None else None,
1563
1656
  )
1564
- scope_file_count = scan_scope_file_count(repository, paths or ["."], diff_target)
1657
+ exclusions = recipe.get("excludePaths", [])
1658
+ scope_file_count = (
1659
+ (
1660
+ diff_scope_file_count(repository, diff_target, exclusions)
1661
+ if diff_target is not None
1662
+ else scoped_regular_file_count(repository, paths or ["."], exclusions)
1663
+ )
1664
+ if exclusions
1665
+ else (
1666
+ scoped_regular_file_count(repository, paths)
1667
+ if mode == "standard" and len(paths) > 1
1668
+ else scan_scope_file_count(repository, paths or ["."], diff_target)
1669
+ )
1670
+ )
1565
1671
  require_working_tree_unchanged(repository, diff_target)
1566
1672
  parent_scan_id = (
1567
1673
  require_uuid(args.parent_scan_id, "parent-scan-id")
@@ -1577,9 +1683,19 @@ def register_cli_scan(
1577
1683
  with ExitStack() as archive:
1578
1684
  deadline = None
1579
1685
  while True:
1580
- if scan_dir is None:
1581
- # Wait for any previous archive to finish before inspecting its replacement.
1582
- scan_dir = require_cli_scan_directory(repository, args)
1686
+ registration = register_security_target(connection, str(repository))
1687
+ target_id = registration.target_id
1688
+ if parent_scan_id is not None:
1689
+ parent = require_scan(connection, parent_scan_id)
1690
+ parent_scope = RepositoryScanScope(
1691
+ registration.repository_generation, target_id
1692
+ )
1693
+ if not parent_scope.contains(parent):
1694
+ raise SystemExit(
1695
+ "A rerun must belong to the same repository as its parent scan."
1696
+ )
1697
+ # Revalidate the output and its owner under the current write lock.
1698
+ scan_dir = require_cli_scan_directory(repository, args)
1583
1699
  try:
1584
1700
  archived_scan_dir = archive.enter_context(
1585
1701
  archive_scan(
@@ -1588,7 +1704,7 @@ def register_cli_scan(
1588
1704
  scan_dir,
1589
1705
  timestamp,
1590
1706
  require_canonical_scan_directory,
1591
- before_archive=before_archive,
1707
+ before_archive=acknowledge_output_change,
1592
1708
  )
1593
1709
  )
1594
1710
  break
@@ -1607,18 +1723,9 @@ def register_cli_scan(
1607
1723
  if remaining <= 0:
1608
1724
  raise
1609
1725
  connection.rollback()
1610
- before_archive = None # The host already acknowledged this registration.
1611
1726
  scan_dir = None # Revalidate the directory and its owner under the next lock.
1612
1727
  time.sleep(min(0.05, remaining))
1613
1728
  connection.execute("BEGIN IMMEDIATE")
1614
- target_id = ensure_security_target(connection, str(repository))
1615
- if parent_scan_id is not None:
1616
- parent = require_scan(connection, parent_scan_id)
1617
- if parent["target_id"] != target_id:
1618
- raise SystemExit(
1619
- "A rerun must belong to the same repository as its parent scan."
1620
- )
1621
-
1622
1729
  connection.execute(
1623
1730
  """
1624
1731
  INSERT INTO workspaces (
@@ -1648,6 +1755,7 @@ def register_cli_scan(
1648
1755
  scope=scope,
1649
1756
  diff_target=diff_target,
1650
1757
  target_identity=target_identity,
1758
+ repository_generation=registration.repository_generation,
1651
1759
  source_scopes=source_scopes,
1652
1760
  target_root=scan_dir.parent,
1653
1761
  target_summary=None,
@@ -1658,6 +1766,7 @@ def register_cli_scan(
1658
1766
  surface=surface,
1659
1767
  package_version=package_version,
1660
1768
  launch_kind=launch_kind,
1769
+ hosted=hosted,
1661
1770
  )
1662
1771
  connection.execute(
1663
1772
  "UPDATE scans SET recipe_json = ?, parent_scan_id = ?, user_context = ? WHERE id = ?",
@@ -1670,6 +1779,12 @@ def register_cli_scan(
1670
1779
  )
1671
1780
  if workflow_id is not None:
1672
1781
  register_workflow_scan(connection, workflow_id, scan_id, str(scan_dir), timestamp)
1782
+ if resume_target is not None:
1783
+ archive.enter_context(
1784
+ register_windows_resume_output(
1785
+ connection, scan_id, scan_dir, resume_target, acknowledge_output_change
1786
+ )
1787
+ )
1673
1788
  scan = connection.execute(
1674
1789
  "SELECT scans.*, snapshot AS lifecycle_json FROM scans "
1675
1790
  "JOIN scan_lifecycles ON scan_id = scans.id WHERE scans.id = ?",
@@ -1683,6 +1798,12 @@ def register_cli_scan(
1683
1798
  **({"archivedScanDir": str(archived_scan_dir)} if archived_scan_dir is not None else {}),
1684
1799
  "contract": scan_contract(scan),
1685
1800
  "lifecycle": json.loads(scan["lifecycle_json"]),
1801
+ **({"phase": scan["phase"]} if mode == "standard" else {}),
1802
+ **(
1803
+ {"canSaveTimeBudgetStart": True}
1804
+ if "maxTimeMinutes" in recipe and mode in {"standard", "diff"}
1805
+ else {}
1806
+ ),
1686
1807
  "scanDir": str(scan_dir),
1687
1808
  "scanId": scan_id,
1688
1809
  "scopeFileCount": scope_file_count,
@@ -1695,8 +1816,11 @@ def set_scan_thread(connection: sqlite3.Connection, args: argparse.Namespace) ->
1695
1816
  scan = require_scan(connection, args.scan_id)
1696
1817
  with connection:
1697
1818
  connection.execute(
1698
- "UPDATE scans SET continuation_thread_id = ?, updated_at = ? WHERE id = ?",
1699
- (args.thread_id, now(), scan["id"]),
1819
+ """UPDATE scans SET continuation_thread_id = ?1, updated_at = ?2,
1820
+ recipe_json = CASE WHEN ?3 IS NULL THEN recipe_json
1821
+ ELSE json_insert(recipe_json, '$.timeBudgetStartedAt', ?3) END
1822
+ WHERE id = ?4""",
1823
+ (args.thread_id, now(), getattr(args, "time_budget_started_at", None), scan["id"]),
1700
1824
  )
1701
1825
  return {"scanId": scan["id"], "threadId": args.thread_id}
1702
1826
 
@@ -1726,55 +1850,6 @@ def set_scan_cost_limit(connection: sqlite3.Connection, args: argparse.Namespace
1726
1850
  return {"scanId": scan["id"], "maxCostUsd": limit}
1727
1851
 
1728
1852
 
1729
- def parse_scan_recipe(value: str, repository: Path) -> dict[str, Any]:
1730
- try:
1731
- recipe = json.loads(value, parse_constant=reject_non_finite_json)
1732
- except (TypeError, UnicodeError, ValueError) as exc:
1733
- raise SystemExit("Scan launch recipe must be a valid JSON object.") from exc
1734
- if not isinstance(recipe, dict):
1735
- raise SystemExit("Scan launch recipe must be a JSON object.")
1736
- requested_repository = recipe.get("repository")
1737
- if (
1738
- not isinstance(requested_repository, str)
1739
- or require_target(requested_repository) != repository
1740
- ):
1741
- raise SystemExit("Scan launch recipe repository must match the scanned repository.")
1742
- if recipe.get("mode") not in {"standard", "deep"}:
1743
- raise SystemExit("Scan launch recipe mode must be standard or deep.")
1744
- if not isinstance(recipe.get("config"), dict):
1745
- raise SystemExit("Scan launch recipe config must be a JSON object.")
1746
- target = recipe.get("target")
1747
- if not isinstance(target, dict) or target.get("kind") not in {
1748
- "repository",
1749
- "paths",
1750
- "refs",
1751
- "working_tree",
1752
- }:
1753
- raise SystemExit("Scan launch recipe target must identify a supported scan target.")
1754
- paths = target.get("paths")
1755
- if not isinstance(paths, list) or not all(isinstance(path, str) for path in paths):
1756
- raise SystemExit("Scan launch recipe target paths must be an array of strings.")
1757
- if target["kind"] == "paths" and not paths:
1758
- raise SystemExit("A scoped scan launch recipe must include at least one target path.")
1759
- if target["kind"] != "paths" and paths:
1760
- raise SystemExit("Only scoped scan launch recipes can include target paths.")
1761
- for path in paths:
1762
- candidate = PurePosixPath(path)
1763
- if (
1764
- not path
1765
- or candidate.is_absolute()
1766
- or ".." in candidate.parts
1767
- or "\\" in path
1768
- or not (repository / candidate).exists()
1769
- or not (repository / candidate).resolve().is_relative_to(repository)
1770
- ):
1771
- raise SystemExit("Scan launch recipe target paths must exist inside the repository.")
1772
- if target["kind"] in {"refs", "working_tree"}:
1773
- if not isinstance(target.get("base"), str) or not isinstance(target.get("head"), str):
1774
- raise SystemExit("Diff scan launch recipes require resolved base and head revisions.")
1775
- return recipe
1776
-
1777
-
1778
1853
  def coverage_summary_for_history(scan: sqlite3.Row) -> dict[str, Any]:
1779
1854
  return scan_history.coverage_summary_for_history(
1780
1855
  _WORKBENCH_DB_CONTEXT, scan, require_canonical_scan_directory
@@ -2340,7 +2415,9 @@ def require_reviewed_patch_applied(
2340
2415
  ) -> str | None:
2341
2416
  target = require_scan_target_identity(scan)
2342
2417
  _, content_digest = remediation_checkout_snapshot(
2343
- scan, expected_revision=remediation["base_revision"]
2418
+ scan,
2419
+ expected_revision=remediation["base_revision"],
2420
+ expected_digest=remediation["base_content_digest"],
2344
2421
  )
2345
2422
  if content_digest == remediation["base_content_digest"]:
2346
2423
  raise SystemExit(
@@ -2350,12 +2427,17 @@ def require_reviewed_patch_applied(
2350
2427
  excluded = (Path(scan["scan_dir"]),)
2351
2428
  # Unborn repositories still need their config while metadata junctions are deferred.
2352
2429
  git_dir = git_output(target, "rev-parse", "--absolute-git-dir")
2430
+ metadata = Path(git_dir) if git_dir is not None else None
2353
2431
  if not unversioned:
2354
2432
  repository, pathspec = git_worktree_context(target)
2355
2433
  if git_dir is None:
2356
2434
  raise SystemExit("Could not inspect the selected Git working tree.")
2357
2435
  excluded += tuple(path for path, _ in git_submodule_entries(target))
2358
- with tempfile.TemporaryDirectory(prefix="codex-security-remediation-") as temporary:
2436
+ with (
2437
+ tempfile.TemporaryDirectory(prefix="codex-security-remediation-") as temporary,
2438
+ ExitStack() as pins,
2439
+ ):
2440
+ pinned_metadata = pin_replay_metadata(pins, metadata, Path(temporary))
2359
2441
  reviewed_patch = Path(temporary) / "reviewed.patch"
2360
2442
  digest = hashlib.sha256()
2361
2443
  with open_scan_local_file(Path(scan["scan_dir"]), patch_path) as source:
@@ -2371,36 +2453,30 @@ def require_reviewed_patch_applied(
2371
2453
  junctions = copy_directory_excluding(target, checkout, excluded)
2372
2454
  else:
2373
2455
  _, junctions = copy_git_worktree_files(target, checkout_root, excluded)
2374
- arguments = ["apply", "--reverse", "--whitespace=nowarn"]
2375
- if unversioned:
2376
- arguments.append("--no-index")
2377
- elif pathspec != ".":
2378
- arguments.append(f"--directory={pathspec}")
2379
- arguments.append(str(reviewed_patch))
2380
- applied = git_command(
2381
- checkout if unversioned else checkout_root,
2382
- *arguments,
2383
- text=False,
2384
- git_dir=Path(git_dir) if git_dir is not None else None,
2385
- work_tree=checkout_root if git_dir is not None else None,
2456
+ short, replay_root = remediation_state.reverse_reviewed_patch(
2457
+ target,
2458
+ checkout_root,
2459
+ metadata,
2460
+ pinned_metadata,
2461
+ remediation["patch_digest"],
2462
+ pins,
2463
+ reviewed_patch,
2464
+ None if unversioned else pathspec,
2386
2465
  )
2387
- if applied.returncode != 0:
2388
- raise SystemExit(
2389
- "The selected checkout does not contain the reviewed remediation patch. Apply exactly that patch before recording it as applied."
2390
- )
2391
2466
  restore_directory_junctions(
2392
2467
  target if unversioned else repository,
2393
2468
  checkout if unversioned else checkout_root,
2394
2469
  junctions,
2395
2470
  )
2396
2471
  reverted_digest = (
2397
- directory_content_digest(checkout)
2472
+ directory_content_digest(checkout, replay_git_dir=replay_root)
2398
2473
  if unversioned
2399
2474
  else worktree_content_digest_for_context(
2400
2475
  checkout_root,
2401
2476
  pathspec or ".",
2402
- git_dir=Path(git_dir),
2477
+ git_dir=short or metadata,
2403
2478
  work_tree=checkout_root,
2479
+ expected_digest=remediation["base_content_digest"],
2404
2480
  )
2405
2481
  )
2406
2482
  if reverted_digest != remediation["base_content_digest"] and unversioned:
@@ -2410,12 +2486,16 @@ def require_reviewed_patch_applied(
2410
2486
  checkout,
2411
2487
  "-c",
2412
2488
  "core.autocrlf=input",
2413
- *arguments,
2489
+ "apply",
2490
+ "--reverse",
2491
+ "--whitespace=nowarn",
2492
+ "--no-index",
2493
+ str(reviewed_patch),
2414
2494
  text=True,
2415
2495
  )
2416
2496
  if applied_without_conversion.returncode == 0:
2417
2497
  restore_directory_junctions(target, checkout, junctions)
2418
- reverted_digest = directory_content_digest(checkout)
2498
+ reverted_digest = directory_content_digest(checkout, replay_git_dir=replay_root)
2419
2499
  if reverted_digest != remediation["base_content_digest"]:
2420
2500
  raise SystemExit(
2421
2501
  "The selected checkout contains changes outside the reviewed patch. Remove them before recording the patch as applied."
@@ -2430,9 +2510,6 @@ def require_remediation_checkout_unchanged(
2430
2510
  require_applied_content: bool = False,
2431
2511
  require_base_content: bool = False,
2432
2512
  ) -> None:
2433
- _, content_digest = remediation_checkout_snapshot(
2434
- scan, expected_revision=remediation["base_revision"]
2435
- )
2436
2513
  expected_digest = (
2437
2514
  remediation["applied_content_digest"]
2438
2515
  if require_applied_content
@@ -2440,6 +2517,9 @@ def require_remediation_checkout_unchanged(
2440
2517
  if require_base_content
2441
2518
  else None
2442
2519
  )
2520
+ _, content_digest = remediation_checkout_snapshot(
2521
+ scan, expected_revision=remediation["base_revision"], expected_digest=expected_digest
2522
+ )
2443
2523
  if expected_digest is not None and content_digest != expected_digest:
2444
2524
  raise SystemExit(
2445
2525
  "Working-tree contents changed. Regenerate the remediation patch against the current checkout."
@@ -2608,8 +2688,8 @@ def get_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[s
2608
2688
  ).fetchone()
2609
2689
  if scan is None:
2610
2690
  raise SystemExit("Codex Security scan not found.")
2611
- progress, _ = scan_progress_result(connection, scan)
2612
- return {"scan": {"progress": progress}}
2691
+ progress_result, _ = progress.scan_progress_result(connection, scan)
2692
+ return {"scan": {"progress": progress_result}}
2613
2693
  request_id = getattr(args, "request_id", None)
2614
2694
  action_token = getattr(args, "action_token", None)
2615
2695
  if request_id is not None or action_token is not None:
@@ -2718,45 +2798,6 @@ def list_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> d
2718
2798
  }
2719
2799
 
2720
2800
 
2721
- def scan_progress_result(
2722
- connection: sqlite3.Connection, scan: sqlite3.Row
2723
- ) -> tuple[dict[str, Any], str]:
2724
- independent_reviews = (
2725
- deep_scan.independent_review_progress(
2726
- connection, scan["id"], parent_running=scan["status"] == "running"
2727
- )
2728
- if scan["mode"] == "deep"
2729
- else None
2730
- )
2731
- progress_result = {
2732
- "candidates": {"reportable": scan["reportable_findings_count"]},
2733
- "coverage": {
2734
- "closedRows": scan["review_items_completed"],
2735
- "filesTotal": scan["scope_file_count"],
2736
- "worklistRows": scan["review_items_total"],
2737
- },
2738
- "phase": scan["phase"],
2739
- "phaseProgress": {
2740
- "completed": scan["phase_items_completed"],
2741
- "total": scan["phase_items_total"],
2742
- "unit": scan["phase_progress_unit"],
2743
- },
2744
- "preflightProgress": {
2745
- "completed": scan["preflight_checks_completed"],
2746
- "total": scan["preflight_checks_total"],
2747
- },
2748
- "preflightIssues": json.loads(scan["preflight_issues_json"]),
2749
- "reviewPass": scan["deep_review_pass"],
2750
- "status": "canceled" if scan["canceled_at"] else scan["status"],
2751
- "updatedAt": scan["progress_updated_at"],
2752
- }
2753
- review_updated_at = ""
2754
- if independent_reviews is not None:
2755
- review_updated_at = str(independent_reviews.pop("updatedAt"))
2756
- progress_result["independentReviews"] = independent_reviews
2757
- return progress_result, review_updated_at
2758
-
2759
-
2760
2801
  def scan_result(
2761
2802
  connection: sqlite3.Connection,
2762
2803
  scan: sqlite3.Row,
@@ -2813,7 +2854,7 @@ def scan_result(
2813
2854
  }
2814
2855
  finding_count = sum(severity_counts.values())
2815
2856
  remediation_available, remediation_unavailable_reason = remediation_availability(scan)
2816
- progress_result, review_updated_at = scan_progress_result(connection, scan)
2857
+ progress_result, review_updated_at = progress.scan_progress_result(connection, scan)
2817
2858
  relations = scan_history.finding_relations(
2818
2859
  connection, scan["id"], (row["id"] for row in occurrence_rows)
2819
2860
  )
@@ -2872,7 +2913,8 @@ def remediation_availability(scan: sqlite3.Row) -> tuple[bool, str | None]:
2872
2913
  if scan["status"] != "complete":
2873
2914
  return False, remediation_state.SCAN_STATUS_ERROR
2874
2915
  try:
2875
- current_revision = git_revision(require_scan_target_identity(scan))
2916
+ with checked_scan_target(scan) as target:
2917
+ current_revision = git_revision(target)
2876
2918
  except SystemExit as exc:
2877
2919
  return False, str(exc)
2878
2920
  expected_revision = scan["target_revision"]
@@ -2930,15 +2972,7 @@ def backfill_legacy_finding_details(connection: sqlite3.Connection, scan: sqlite
2930
2972
  if not updates:
2931
2973
  return
2932
2974
 
2933
- # Reads normally avoid writer admission, but legacy details still need a write.
2934
- for attempt in range(SQLITE_RETRY_ATTEMPTS):
2935
- try:
2936
- connection.execute("BEGIN IMMEDIATE")
2937
- break
2938
- except sqlite3.OperationalError as exc:
2939
- if attempt == SQLITE_RETRY_ATTEMPTS - 1 or not sqlite_busy(exc):
2940
- raise
2941
- time.sleep(0.05 * (2**attempt))
2975
+ begin_immediate_with_retry(connection)
2942
2976
  with connection:
2943
2977
  current = require_scan(connection, scan["id"])
2944
2978
  recorded_digest = current["seal_manifest_digest"]
@@ -3137,39 +3171,10 @@ def read_finding_details(value: str) -> dict[str, Any]:
3137
3171
  return details if isinstance(details, dict) else {}
3138
3172
 
3139
3173
 
3140
- def finding_management_updated_at(connection: sqlite3.Connection, scan_id: str) -> str | None:
3141
- return connection.execute(
3142
- """
3143
- SELECT MAX(updated_at)
3144
- FROM (
3145
- SELECT triage.updated_at
3146
- FROM finding_triage AS triage
3147
- JOIN finding_occurrences AS occurrences ON occurrences.id = triage.occurrence_id
3148
- WHERE occurrences.scan_id = ?
3149
- UNION ALL
3150
- SELECT remediation.updated_at
3151
- FROM finding_remediation_attempts AS remediation
3152
- JOIN finding_occurrences AS occurrences ON occurrences.id = remediation.occurrence_id
3153
- WHERE occurrences.scan_id = ?
3154
- )
3155
- """,
3156
- (scan_id, scan_id),
3157
- ).fetchone()[0]
3174
+ finding_management_updated_at = scan_history.finding_management_updated_at
3158
3175
 
3159
3176
 
3160
- def finding_triage_result(connection: sqlite3.Connection, occurrence_id: str) -> dict[str, Any]:
3161
- row = connection.execute(
3162
- "SELECT status, close_reason, note, updated_at FROM finding_triage WHERE occurrence_id = ?",
3163
- (occurrence_id,),
3164
- ).fetchone()
3165
- if row is None:
3166
- return {"status": "open"}
3167
- return {
3168
- "closeReason": row["close_reason"],
3169
- "note": row["note"],
3170
- "status": row["status"],
3171
- "updatedAt": row["updated_at"],
3172
- }
3177
+ finding_triage_result = scan_history.finding_triage_result
3173
3178
 
3174
3179
 
3175
3180
  def finding_remediation_result(
@@ -3219,48 +3224,9 @@ def finding_remediation_result(
3219
3224
  def patch_artifact_preview(
3220
3225
  scan_dir: Path, relative_path: str | None, expected_digest: str | None
3221
3226
  ) -> tuple[str | None, dict[str, int | bool] | None]:
3222
- if relative_path is None or expected_digest is None:
3223
- return None, None
3224
- digest = hashlib.sha256()
3225
- preview = bytearray()
3226
- additions = 0
3227
- deletions = 0
3228
- file_count = 0
3229
- old_headers = 0
3230
- new_headers = 0
3231
- at_line_start = True
3232
- try:
3233
- with open_scan_local_file(scan_dir, relative_path) as patch:
3234
- while chunk := patch.readline(1024 * 1024):
3235
- digest.update(chunk)
3236
- if len(preview) <= PATCH_PREVIEW_BYTES:
3237
- preview.extend(chunk[: PATCH_PREVIEW_BYTES + 1 - len(preview)])
3238
- if at_line_start:
3239
- if chunk.startswith(b"diff --git "):
3240
- file_count += 1
3241
- elif chunk.startswith(b"+++ "):
3242
- new_headers += 1
3243
- elif chunk.startswith(b"--- "):
3244
- old_headers += 1
3245
- elif chunk.startswith(b"+"):
3246
- additions += 1
3247
- elif chunk.startswith(b"-"):
3248
- deletions += 1
3249
- at_line_start = chunk.endswith(b"\n")
3250
- except SystemExit:
3251
- return None, None
3252
- if f"sha256:{digest.hexdigest()}" != expected_digest:
3253
- return None, None
3254
- preview_truncated = len(preview) > PATCH_PREVIEW_BYTES
3255
- preview_text = preview[:PATCH_PREVIEW_BYTES].decode("utf-8", errors="replace")
3256
- if preview_truncated:
3257
- preview_text = f"{preview_text}\n... patch preview truncated ..."
3258
- return preview_text, {
3259
- "additions": additions,
3260
- "deletions": deletions,
3261
- "fileCount": file_count or min(old_headers, new_headers),
3262
- "previewTruncated": preview_truncated,
3263
- }
3227
+ return remediation_state.patch_artifact_preview(
3228
+ scan_dir, relative_path, expected_digest, open_scan_local_file
3229
+ )
3264
3230
 
3265
3231
 
3266
3232
  def available_artifact_path(scan_dir: Path, candidate: Path) -> Path | None:
@@ -3297,7 +3263,7 @@ def require_canonical_scan_directory(scan_dir: Path, *, writable_output: bool =
3297
3263
  try:
3298
3264
  metadata = scan_dir.lstat()
3299
3265
  resolved = scan_dir.resolve(strict=True)
3300
- except OSError as exc:
3266
+ except (OSError, RuntimeError) as exc:
3301
3267
  raise SystemExit(
3302
3268
  "Scan directory must be an existing canonical non-symlink directory."
3303
3269
  ) from exc
@@ -3373,11 +3339,31 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
3373
3339
  raise SystemExit(73) from None
3374
3340
  print(json.dumps(result, allow_nan=False, sort_keys=True))
3375
3341
  return
3376
- with closing(
3377
- connect(
3378
- deferred=args.command in {"get-scan", "read-scan-usage", "list-scans", "database-info"}
3379
- )
3380
- ) as connection:
3342
+ command_targets = tuple(
3343
+ Path(value).expanduser()
3344
+ for field in ("target_path", "repository")
3345
+ if (value := getattr(args, field, None))
3346
+ )
3347
+ with (
3348
+ closing(
3349
+ connect(
3350
+ deferred=args.command
3351
+ in {
3352
+ "get-scan",
3353
+ "read-scan-usage",
3354
+ "list-scans",
3355
+ "database-info",
3356
+ "update-progress",
3357
+ },
3358
+ discovery_roots=command_targets,
3359
+ in_memory=scan_history.reads_missing_history(args, database_path()),
3360
+ )
3361
+ ) as connection,
3362
+ scoped_git_discovery(
3363
+ lambda: [*migration_target_paths(connection), *command_targets],
3364
+ recorded_git_roots=lambda: recorded_git_checkout_roots(connection),
3365
+ ),
3366
+ ):
3381
3367
  remediation_state.require_available(connection, args, require_scan)
3382
3368
  handlers = {
3383
3369
  "create-workspace": create_workspace,
@@ -3394,6 +3380,9 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
3394
3380
  "record-deep-scan-publication-failure": deep_scan.record_deep_scan_publication_failure,
3395
3381
  "list-scans": scan_history.list_scans,
3396
3382
  "register-cli-scan": partial(register_cli_scan, before_archive=before_archive),
3383
+ "restore-cli-scan-archive": partial(
3384
+ restore_cli_scan_archive, canonical_directory=require_canonical_scan_directory
3385
+ ),
3397
3386
  "set-scan-thread": set_scan_thread,
3398
3387
  "set-scan-cost-limit": set_scan_cost_limit,
3399
3388
  "read-scan-usage": read_scan_usage,