@openai/codex-security 0.2.0 → 0.3.0

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 (463) hide show
  1. package/README.md +437 -2692
  2. package/_bundled_plugin/.app.json +5 -1
  3. package/_bundled_plugin/.codex-plugin/plugin.json +9 -5
  4. package/_bundled_plugin/.mcp.json +2 -0
  5. package/_bundled_plugin/examples/completed-scan/coverage.json +0 -1
  6. package/_bundled_plugin/examples/completed-scan/report.md +28 -26
  7. package/_bundled_plugin/examples/completed-scan/scan-manifest.json +1 -1
  8. package/_bundled_plugin/mcp/helpers.mjs +1 -0
  9. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  10. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +6 -213
  11. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  13. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  14. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  15. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  16. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  17. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  18. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  19. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +563 -0
  20. package/_bundled_plugin/mcp/server.mjs +1 -0
  21. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  22. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  23. package/_bundled_plugin/preflight/capability-profiles.toml +0 -13
  24. package/_bundled_plugin/references/artifact-storage.md +2 -2
  25. package/_bundled_plugin/references/config-preflight.md +0 -4
  26. package/_bundled_plugin/references/core-scan.md +21 -9
  27. package/_bundled_plugin/references/final-report.md +10 -12
  28. package/_bundled_plugin/references/finding-detail-fields.md +90 -80
  29. package/_bundled_plugin/references/sarif-adapter.md +1 -1
  30. package/_bundled_plugin/references/scan-artifacts.md +1 -2
  31. package/_bundled_plugin/references/scan-contract.md +9 -4
  32. package/_bundled_plugin/references/scan-prologue.md +12 -0
  33. package/_bundled_plugin/references/security-guidance.md +2 -2
  34. package/_bundled_plugin/references/standalone-validation.md +11 -0
  35. package/_bundled_plugin/references/threat-model.md +1 -1
  36. package/_bundled_plugin/schemas/coverage.schema.json +1 -47
  37. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +2 -24
  38. package/_bundled_plugin/schemas/definitions/discovery-candidate.schema.json +49 -25
  39. package/_bundled_plugin/schemas/findings.schema.json +71 -192
  40. package/_bundled_plugin/schemas/scan-manifest.schema.json +18 -45
  41. package/_bundled_plugin/schemas/tools/candidate-attack-paths.schema.json +91 -83
  42. package/_bundled_plugin/schemas/tools/candidate-validations.schema.json +35 -64
  43. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +5 -2
  44. package/_bundled_plugin/schemas/tools/discovery-candidates.schema.json +6 -55
  45. package/_bundled_plugin/schemas/tools/review-items.schema.json +2 -38
  46. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +169 -294
  47. package/_bundled_plugin/scripts/codex_profile.mjs +239 -0
  48. package/_bundled_plugin/scripts/codex_session.mjs +53 -0
  49. package/_bundled_plugin/scripts/config_preflight.py +26 -62
  50. package/_bundled_plugin/scripts/deep_scan_config.py +9 -11
  51. package/_bundled_plugin/scripts/deep_scan_workbench.py +129 -150
  52. package/_bundled_plugin/scripts/finalize_scan_contract.py +315 -232
  53. package/_bundled_plugin/scripts/finding_preview.py +39 -9
  54. package/_bundled_plugin/scripts/generate_in_scope_files.py +27 -77
  55. package/_bundled_plugin/scripts/generate_rank_input.py +99 -829
  56. package/_bundled_plugin/scripts/launch_codex_security_mcp +35 -10
  57. package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +5 -5
  58. package/_bundled_plugin/scripts/rank_preview.py +42 -918
  59. package/_bundled_plugin/scripts/report_projection.py +117 -172
  60. package/_bundled_plugin/scripts/snapshot_sqlite.py +6 -1
  61. package/_bundled_plugin/scripts/threat_model_projection.py +4 -7
  62. package/_bundled_plugin/scripts/validate_scan_contract.py +4 -34
  63. package/_bundled_plugin/scripts/validate_tracking_source.py +3 -13
  64. package/_bundled_plugin/scripts/windows_scan_local_files.py +48 -3
  65. package/_bundled_plugin/scripts/workbench/handoff.py +25 -50
  66. package/_bundled_plugin/scripts/workbench/runtime_toml.py +22 -0
  67. package/_bundled_plugin/scripts/workbench/storage.py +10 -6
  68. package/_bundled_plugin/scripts/workbench_cli.py +94 -179
  69. package/_bundled_plugin/scripts/workbench_db.py +427 -463
  70. package/_bundled_plugin/scripts/workbench_feedback.py +6 -3
  71. package/_bundled_plugin/scripts/workbench_finding_index.py +19 -1
  72. package/_bundled_plugin/scripts/workbench_finding_workflows.py +18 -4
  73. package/_bundled_plugin/scripts/workbench_local_dedupe.py +136 -0
  74. package/_bundled_plugin/scripts/workbench_native_indexes.py +27 -14
  75. package/_bundled_plugin/scripts/workbench_progress.py +14 -58
  76. package/_bundled_plugin/scripts/workbench_publication.py +33 -57
  77. package/_bundled_plugin/scripts/workbench_remediation.py +12 -0
  78. package/_bundled_plugin/scripts/workbench_saved_results.py +172 -49
  79. package/_bundled_plugin/scripts/workbench_scan_history.py +57 -57
  80. package/_bundled_plugin/scripts/workbench_scan_start.py +105 -41
  81. package/_bundled_plugin/scripts/workbench_scan_usage.py +23 -34
  82. package/_bundled_plugin/scripts/workbench_schema.py +37 -1151
  83. package/_bundled_plugin/scripts/workbench_source_excerpt.py +11 -1
  84. package/_bundled_plugin/scripts/workbench_target.py +430 -142
  85. package/_bundled_plugin/scripts/workbench_validation.py +16 -27
  86. package/_bundled_plugin/shared/workbench-history-repairs.json +218 -0
  87. package/_bundled_plugin/shared/workbench-migrations.json +397 -0
  88. package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +15 -4
  89. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -0
  90. package/_bundled_plugin/skills/cloud-findings/SKILL.md +54 -0
  91. package/_bundled_plugin/skills/cloud-findings/agents/openai.yaml +4 -0
  92. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
  93. package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +1 -1
  94. package/_bundled_plugin/skills/finding-discovery/SKILL.md +3 -3
  95. package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +50 -20
  96. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +8 -14
  97. package/_bundled_plugin/skills/security-diff-scan/agents/openai.yaml +1 -1
  98. package/_bundled_plugin/skills/security-scan/SKILL.md +22 -7
  99. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +1 -1
  100. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +1 -1
  101. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +13 -1
  102. package/_bundled_plugin/skills/threat-model/SKILL.md +1 -1
  103. package/_bundled_plugin/skills/track-findings/SKILL.md +46 -178
  104. package/_bundled_plugin/skills/track-findings/agents/openai.yaml +1 -1
  105. package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +16 -24
  106. package/_bundled_plugin/skills/track-findings/references/jira.md +15 -61
  107. package/_bundled_plugin/skills/triage-finding/SKILL.md +50 -289
  108. package/_bundled_plugin/skills/triage-finding/agents/openai.yaml +2 -2
  109. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +23 -43
  110. package/_bundled_plugin/skills/triage-finding/references/triage-result-contract.md +7 -1
  111. package/bin/codex-security.mjs +9 -2
  112. package/dist/api.d.ts +60 -10
  113. package/dist/api.d.ts.map +1 -1
  114. package/dist/api.js +803 -380
  115. package/dist/api.js.map +1 -1
  116. package/dist/artifact-export.d.ts +1 -1
  117. package/dist/artifact-export.d.ts.map +1 -1
  118. package/dist/artifact-export.js +28 -13
  119. package/dist/artifact-export.js.map +1 -1
  120. package/dist/auth.d.ts +2 -6
  121. package/dist/auth.d.ts.map +1 -1
  122. package/dist/auth.js +19 -9
  123. package/dist/auth.js.map +1 -1
  124. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  125. package/dist/bulk-scan-discovery.js +1 -0
  126. package/dist/bulk-scan-discovery.js.map +1 -1
  127. package/dist/classify-severity.d.ts +26 -9
  128. package/dist/classify-severity.d.ts.map +1 -1
  129. package/dist/classify-severity.js +13 -30
  130. package/dist/classify-severity.js.map +1 -1
  131. package/dist/cli-help.d.ts.map +1 -1
  132. package/dist/cli-help.js +17 -13
  133. package/dist/cli-help.js.map +1 -1
  134. package/dist/cli-signals.d.ts +8 -0
  135. package/dist/cli-signals.d.ts.map +1 -0
  136. package/dist/cli-signals.js +28 -0
  137. package/dist/cli-signals.js.map +1 -0
  138. package/dist/cli.d.ts +4 -3
  139. package/dist/cli.d.ts.map +1 -1
  140. package/dist/cli.js +1087 -900
  141. package/dist/cli.js.map +1 -1
  142. package/dist/cloud-publish.d.ts.map +1 -1
  143. package/dist/cloud-publish.js +10 -9
  144. package/dist/cloud-publish.js.map +1 -1
  145. package/dist/codeowners.d.ts +19 -0
  146. package/dist/codeowners.d.ts.map +1 -0
  147. package/dist/codeowners.js +138 -0
  148. package/dist/codeowners.js.map +1 -0
  149. package/dist/codex-sdk-environment.d.ts +1 -0
  150. package/dist/codex-sdk-environment.d.ts.map +1 -1
  151. package/dist/codex-sdk-environment.js +40 -2
  152. package/dist/codex-sdk-environment.js.map +1 -1
  153. package/dist/component-plan.d.ts +2 -5
  154. package/dist/component-plan.d.ts.map +1 -1
  155. package/dist/component-plan.js +38 -30
  156. package/dist/component-plan.js.map +1 -1
  157. package/dist/component-scan.d.ts +6 -5
  158. package/dist/component-scan.d.ts.map +1 -1
  159. package/dist/component-scan.js +23 -35
  160. package/dist/component-scan.js.map +1 -1
  161. package/dist/config.d.ts.map +1 -1
  162. package/dist/config.js +64 -74
  163. package/dist/config.js.map +1 -1
  164. package/dist/contract.d.ts +15 -3
  165. package/dist/contract.d.ts.map +1 -1
  166. package/dist/contract.js +87 -252
  167. package/dist/contract.js.map +1 -1
  168. package/dist/cost-model.d.ts +13 -6
  169. package/dist/cost-model.d.ts.map +1 -1
  170. package/dist/cost-model.js +14 -4
  171. package/dist/cost-model.js.map +1 -1
  172. package/dist/cost.d.ts +10 -2
  173. package/dist/cost.d.ts.map +1 -1
  174. package/dist/cost.js +102 -104
  175. package/dist/cost.js.map +1 -1
  176. package/dist/custom-validation-prompt.d.ts.map +1 -1
  177. package/dist/custom-validation-prompt.js +6 -5
  178. package/dist/custom-validation-prompt.js.map +1 -1
  179. package/dist/custom-validation.d.ts +1 -2
  180. package/dist/custom-validation.d.ts.map +1 -1
  181. package/dist/custom-validation.js +9 -3
  182. package/dist/custom-validation.js.map +1 -1
  183. package/dist/deduplication/checkpointed-review.d.ts +4 -2
  184. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  185. package/dist/deduplication/checkpointed-review.js +23 -9
  186. package/dist/deduplication/checkpointed-review.js.map +1 -1
  187. package/dist/deduplication/codex-review.d.ts +7 -1
  188. package/dist/deduplication/codex-review.d.ts.map +1 -1
  189. package/dist/deduplication/codex-review.js +126 -17
  190. package/dist/deduplication/codex-review.js.map +1 -1
  191. package/dist/deduplication/deduplication-prompts.d.ts +5 -2
  192. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  193. package/dist/deduplication/deduplication-prompts.js +18 -4
  194. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  195. package/dist/deduplication/deduplication-reviewer.d.ts +26 -4
  196. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  197. package/dist/deduplication/deduplication-reviewer.js +57 -47
  198. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  199. package/dist/deduplication/deduplication.d.ts.map +1 -1
  200. package/dist/deduplication/deduplication.js +19 -51
  201. package/dist/deduplication/deduplication.js.map +1 -1
  202. package/dist/deduplication/diagnostics.d.ts +17 -0
  203. package/dist/deduplication/diagnostics.d.ts.map +1 -0
  204. package/dist/deduplication/diagnostics.js +5 -0
  205. package/dist/deduplication/diagnostics.js.map +1 -0
  206. package/dist/deduplication/finding-schema.d.ts.map +1 -1
  207. package/dist/deduplication/finding-schema.js +7 -1
  208. package/dist/deduplication/finding-schema.js.map +1 -1
  209. package/dist/deduplication/local.d.ts +31 -0
  210. package/dist/deduplication/local.d.ts.map +1 -0
  211. package/dist/deduplication/local.js +166 -0
  212. package/dist/deduplication/local.js.map +1 -0
  213. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  214. package/dist/deduplication/records-protocol.js +11 -24
  215. package/dist/deduplication/records-protocol.js.map +1 -1
  216. package/dist/deduplication/records.d.ts +186 -11
  217. package/dist/deduplication/records.d.ts.map +1 -1
  218. package/dist/deduplication/records.js +10 -18
  219. package/dist/deduplication/records.js.map +1 -1
  220. package/dist/deduplication/scan.d.ts +9 -3
  221. package/dist/deduplication/scan.d.ts.map +1 -1
  222. package/dist/deduplication/scan.js +158 -39
  223. package/dist/deduplication/scan.js.map +1 -1
  224. package/dist/deep-config.d.ts +2 -1
  225. package/dist/deep-config.d.ts.map +1 -1
  226. package/dist/deep-config.js +4 -4
  227. package/dist/deep-config.js.map +1 -1
  228. package/dist/deep-progress.d.ts +2 -0
  229. package/dist/deep-progress.d.ts.map +1 -1
  230. package/dist/deep-progress.js +13 -10
  231. package/dist/deep-progress.js.map +1 -1
  232. package/dist/deep-scan.d.ts +20 -0
  233. package/dist/deep-scan.d.ts.map +1 -0
  234. package/dist/deep-scan.js +113 -0
  235. package/dist/deep-scan.js.map +1 -0
  236. package/dist/errors.d.ts +2 -0
  237. package/dist/errors.d.ts.map +1 -1
  238. package/dist/errors.js +2 -0
  239. package/dist/errors.js.map +1 -1
  240. package/dist/feedback.d.ts.map +1 -1
  241. package/dist/feedback.js +53 -21
  242. package/dist/feedback.js.map +1 -1
  243. package/dist/finding-catalogue.d.ts.map +1 -1
  244. package/dist/finding-catalogue.js +4 -8
  245. package/dist/finding-catalogue.js.map +1 -1
  246. package/dist/finding-normalization.d.ts +5 -0
  247. package/dist/finding-normalization.d.ts.map +1 -0
  248. package/dist/finding-normalization.js +120 -0
  249. package/dist/finding-normalization.js.map +1 -0
  250. package/dist/finding-retrieval.d.ts +9 -0
  251. package/dist/finding-retrieval.d.ts.map +1 -1
  252. package/dist/finding-retrieval.js.map +1 -1
  253. package/dist/finding-workflow.d.ts +13 -8
  254. package/dist/finding-workflow.d.ts.map +1 -1
  255. package/dist/finding-workflow.js +14 -6
  256. package/dist/finding-workflow.js.map +1 -1
  257. package/dist/findings-client.d.ts +2 -1
  258. package/dist/findings-client.d.ts.map +1 -1
  259. package/dist/findings-client.js +36 -9
  260. package/dist/findings-client.js.map +1 -1
  261. package/dist/findings-errors.d.ts +16 -0
  262. package/dist/findings-errors.d.ts.map +1 -0
  263. package/dist/findings-errors.js +24 -0
  264. package/dist/findings-errors.js.map +1 -0
  265. package/dist/findings-import.d.ts +1 -1
  266. package/dist/findings-import.d.ts.map +1 -1
  267. package/dist/findings-import.js +12 -30
  268. package/dist/findings-import.js.map +1 -1
  269. package/dist/github.d.ts.map +1 -1
  270. package/dist/github.js +7 -1
  271. package/dist/github.js.map +1 -1
  272. package/dist/import-scan.d.ts.map +1 -1
  273. package/dist/import-scan.js +48 -38
  274. package/dist/import-scan.js.map +1 -1
  275. package/dist/index.d.ts +8 -4
  276. package/dist/index.d.ts.map +1 -1
  277. package/dist/index.js +1 -1
  278. package/dist/index.js.map +1 -1
  279. package/dist/knowledge-base.d.ts +7 -1
  280. package/dist/knowledge-base.d.ts.map +1 -1
  281. package/dist/knowledge-base.js +114 -46
  282. package/dist/knowledge-base.js.map +1 -1
  283. package/dist/linear.d.ts.map +1 -1
  284. package/dist/linear.js +2 -7
  285. package/dist/linear.js.map +1 -1
  286. package/dist/mock-scan.d.ts.map +1 -1
  287. package/dist/mock-scan.js +0 -1
  288. package/dist/mock-scan.js.map +1 -1
  289. package/dist/models.d.ts +0 -2
  290. package/dist/models.d.ts.map +1 -1
  291. package/dist/models.js.map +1 -1
  292. package/dist/multiscan.d.ts +9 -3
  293. package/dist/multiscan.d.ts.map +1 -1
  294. package/dist/multiscan.js +193 -126
  295. package/dist/multiscan.js.map +1 -1
  296. package/dist/owner-evidence.d.ts +10 -2
  297. package/dist/owner-evidence.d.ts.map +1 -1
  298. package/dist/owner-evidence.js +67 -8
  299. package/dist/owner-evidence.js.map +1 -1
  300. package/dist/patch-tui.d.ts.map +1 -1
  301. package/dist/patch-tui.js +3 -2
  302. package/dist/patch-tui.js.map +1 -1
  303. package/dist/project-config.js +3 -3
  304. package/dist/project-config.js.map +1 -1
  305. package/dist/provider-profile.d.ts +21 -0
  306. package/dist/provider-profile.d.ts.map +1 -0
  307. package/dist/provider-profile.js +133 -0
  308. package/dist/provider-profile.js.map +1 -0
  309. package/dist/publication-events.d.ts +6 -8
  310. package/dist/publication-events.d.ts.map +1 -1
  311. package/dist/publication-events.js +25 -50
  312. package/dist/publication-events.js.map +1 -1
  313. package/dist/publication-store.d.ts.map +1 -1
  314. package/dist/publication-store.js +40 -64
  315. package/dist/publication-store.js.map +1 -1
  316. package/dist/publication.d.ts +1 -2
  317. package/dist/publication.d.ts.map +1 -1
  318. package/dist/publication.js +2 -8
  319. package/dist/publication.js.map +1 -1
  320. package/dist/publish.d.ts +1 -5
  321. package/dist/publish.d.ts.map +1 -1
  322. package/dist/publish.js +109 -160
  323. package/dist/publish.js.map +1 -1
  324. package/dist/request-metadata.d.ts +9 -0
  325. package/dist/request-metadata.d.ts.map +1 -0
  326. package/dist/request-metadata.js +13 -0
  327. package/dist/request-metadata.js.map +1 -0
  328. package/dist/runtime.d.ts +15 -4
  329. package/dist/runtime.d.ts.map +1 -1
  330. package/dist/runtime.js +430 -138
  331. package/dist/runtime.js.map +1 -1
  332. package/dist/saved-scan-bootstrap.d.ts +14 -0
  333. package/dist/saved-scan-bootstrap.d.ts.map +1 -0
  334. package/dist/saved-scan-bootstrap.js +261 -0
  335. package/dist/saved-scan-bootstrap.js.map +1 -0
  336. package/dist/saved-scan.d.ts +1 -1
  337. package/dist/saved-scan.d.ts.map +1 -1
  338. package/dist/saved-scan.js +6 -12
  339. package/dist/saved-scan.js.map +1 -1
  340. package/dist/scan-activity.js +11 -8
  341. package/dist/scan-activity.js.map +1 -1
  342. package/dist/scan-comparison.d.ts +28 -15
  343. package/dist/scan-comparison.d.ts.map +1 -1
  344. package/dist/scan-comparison.js +276 -281
  345. package/dist/scan-comparison.js.map +1 -1
  346. package/dist/scan-dashboard.d.ts +3 -0
  347. package/dist/scan-dashboard.d.ts.map +1 -1
  348. package/dist/scan-dashboard.js +345 -77
  349. package/dist/scan-dashboard.js.map +1 -1
  350. package/dist/scan-history-renderer.d.ts.map +1 -1
  351. package/dist/scan-history-renderer.js +54 -13
  352. package/dist/scan-history-renderer.js.map +1 -1
  353. package/dist/scan-inputs.d.ts +6 -0
  354. package/dist/scan-inputs.d.ts.map +1 -0
  355. package/dist/scan-inputs.js +71 -0
  356. package/dist/scan-inputs.js.map +1 -0
  357. package/dist/scan-logs.d.ts +2 -3
  358. package/dist/scan-logs.d.ts.map +1 -1
  359. package/dist/scan-logs.js +12 -6
  360. package/dist/scan-logs.js.map +1 -1
  361. package/dist/scan-sessions.d.ts +4 -0
  362. package/dist/scan-sessions.d.ts.map +1 -1
  363. package/dist/scan-sessions.js +17 -0
  364. package/dist/scan-sessions.js.map +1 -1
  365. package/dist/scan-skill-paths.d.ts +8 -0
  366. package/dist/scan-skill-paths.d.ts.map +1 -0
  367. package/dist/scan-skill-paths.js +47 -0
  368. package/dist/scan-skill-paths.js.map +1 -0
  369. package/dist/security-policy-cli.d.ts.map +1 -1
  370. package/dist/security-policy-cli.js +7 -27
  371. package/dist/security-policy-cli.js.map +1 -1
  372. package/dist/security-policy.d.ts +9 -5
  373. package/dist/security-policy.d.ts.map +1 -1
  374. package/dist/security-policy.js +33 -14
  375. package/dist/security-policy.js.map +1 -1
  376. package/dist/server/api.d.ts +0 -1
  377. package/dist/server/api.d.ts.map +1 -1
  378. package/dist/server/api.js +0 -1
  379. package/dist/server/api.js.map +1 -1
  380. package/dist/server/embeddings.d.ts +3 -1
  381. package/dist/server/embeddings.d.ts.map +1 -1
  382. package/dist/server/embeddings.js +10 -3
  383. package/dist/server/embeddings.js.map +1 -1
  384. package/dist/server/errors.d.ts +5 -2
  385. package/dist/server/errors.d.ts.map +1 -1
  386. package/dist/server/errors.js +7 -0
  387. package/dist/server/errors.js.map +1 -1
  388. package/dist/server/sqlite-store.d.ts +0 -2
  389. package/dist/server/sqlite-store.d.ts.map +1 -1
  390. package/dist/server/sqlite-store.js +54 -44
  391. package/dist/server/sqlite-store.js.map +1 -1
  392. package/dist/server/storage.d.ts +0 -2
  393. package/dist/server/storage.d.ts.map +1 -1
  394. package/dist/server/storage.js.map +1 -1
  395. package/dist/severity-store.js +19 -24
  396. package/dist/severity-store.js.map +1 -1
  397. package/dist/standalone-validation-prompt.d.ts +2 -0
  398. package/dist/standalone-validation-prompt.d.ts.map +1 -0
  399. package/dist/standalone-validation-prompt.js +10 -0
  400. package/dist/standalone-validation-prompt.js.map +1 -0
  401. package/dist/suggest-owners.d.ts +4 -2
  402. package/dist/suggest-owners.d.ts.map +1 -1
  403. package/dist/suggest-owners.js +11 -5
  404. package/dist/suggest-owners.js.map +1 -1
  405. package/dist/targets.d.ts +11 -0
  406. package/dist/targets.d.ts.map +1 -1
  407. package/dist/targets.js +106 -47
  408. package/dist/targets.js.map +1 -1
  409. package/dist/trusted-executable.d.ts +2 -2
  410. package/dist/trusted-executable.d.ts.map +1 -1
  411. package/dist/trusted-executable.js +8 -6
  412. package/dist/trusted-executable.js.map +1 -1
  413. package/dist/value.js +7 -0
  414. package/dist/value.js.map +1 -1
  415. package/dist/version.js.map +1 -1
  416. package/dist/workbench-arguments.d.ts +3 -0
  417. package/dist/workbench-arguments.d.ts.map +1 -0
  418. package/dist/workbench-arguments.js +15 -0
  419. package/dist/workbench-arguments.js.map +1 -0
  420. package/dist/worker-progress.d.ts +1 -0
  421. package/dist/worker-progress.d.ts.map +1 -1
  422. package/dist/worker-progress.js +27 -12
  423. package/dist/worker-progress.js.map +1 -1
  424. package/docs/cli.md +1778 -0
  425. package/docs/findings-service.md +402 -0
  426. package/package.json +18 -19
  427. package/_bundled_plugin/schemas/tools/worker-threat-model.schema.json +0 -18
  428. package/_bundled_plugin/scripts/workbench_dashboard.py +0 -159
  429. package/_bundled_plugin/scripts/workbench_findings.py +0 -221
  430. package/_bundled_plugin/scripts/workbench_severity.py +0 -122
  431. package/_bundled_plugin/skills/assess-patch-risk/scripts/validate_patch_risk_assessment.py +0 -163
  432. package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +0 -276
  433. package/dist/server/dashboard/app.css +0 -2
  434. package/dist/server/dashboard/app.js +0 -66
  435. package/dist/server/dashboard/index.html +0 -18
  436. package/dist/server/dashboard-types.d.ts +0 -48
  437. package/dist/server/dashboard-types.d.ts.map +0 -1
  438. package/dist/server/dashboard-types.js +0 -2
  439. package/dist/server/dashboard-types.js.map +0 -1
  440. package/dist/server/dashboard.d.ts +0 -6
  441. package/dist/server/dashboard.d.ts.map +0 -1
  442. package/dist/server/dashboard.js +0 -59
  443. package/dist/server/dashboard.js.map +0 -1
  444. package/dist/server/index.d.ts +0 -2
  445. package/dist/server/index.d.ts.map +0 -1
  446. package/dist/server/index.js +0 -6
  447. package/dist/server/index.js.map +0 -1
  448. package/dist/server/routes.d.ts +0 -7
  449. package/dist/server/routes.d.ts.map +0 -1
  450. package/dist/server/routes.js +0 -98
  451. package/dist/server/routes.js.map +0 -1
  452. package/dist/server/serve.d.ts +0 -2
  453. package/dist/server/serve.d.ts.map +0 -1
  454. package/dist/server/serve.js +0 -28
  455. package/dist/server/serve.js.map +0 -1
  456. package/dist/server/server.d.ts +0 -10
  457. package/dist/server/server.d.ts.map +0 -1
  458. package/dist/server/server.js +0 -16
  459. package/dist/server/server.js.map +0 -1
  460. package/dist/server/validation.d.ts +0 -17
  461. package/dist/server/validation.d.ts.map +0 -1
  462. package/dist/server/validation.js +0 -53
  463. package/dist/server/validation.js.map +0 -1
@@ -16,8 +16,10 @@ import sys
16
16
  import tempfile
17
17
  import time
18
18
  import uuid
19
+ from collections.abc import Callable
19
20
  from contextlib import closing, contextmanager, nullcontext
20
21
  from datetime import datetime, timedelta, timezone
22
+ from functools import partial
21
23
  from pathlib import Path, PurePosixPath
22
24
  from types import SimpleNamespace
23
25
  from typing import Any
@@ -37,17 +39,10 @@ import deep_scan_workbench as deep_scan
37
39
  import workbench_native_indexes as native_indexes
38
40
  import workbench_progress as progress
39
41
  import workbench_publication as publication
40
- import workbench_remediation as remediation
42
+ import workbench_remediation as remediation_state
41
43
  import workbench_saved_results as saved_results
42
44
  import workbench_scan_history as scan_history
43
45
  import workbench_scan_usage as scan_usage
44
- import workbench_severity as severity
45
- from filesystem_identity import (
46
- serialize_filesystem_identity as serialize_filesystem_identity,
47
- )
48
- from filesystem_identity import (
49
- stored_filesystem_identity_matches as stored_filesystem_identity_matches,
50
- )
51
46
  from finalize_scan_contract import (
52
47
  PRODUCER_NAME,
53
48
  ContractError,
@@ -82,18 +77,10 @@ from workbench_constants import (
82
77
  PATCH_PREVIEW_BYTES,
83
78
  SQLITE_RETRY_ATTEMPTS,
84
79
  )
85
- from workbench_dashboard import dashboard
86
80
  from workbench_feedback import get_scan_feedback
87
81
  from workbench_finding_index import index_findings
88
82
  from workbench_finding_workflows import finding_workflow, register_workflow_scan
89
- from workbench_findings import (
90
- find_potential_duplicates,
91
- list_dedupe_groups,
92
- list_stored_findings,
93
- store_dedupe_groups,
94
- store_findings,
95
- )
96
- from workbench_remediation import remediation_claim_is_active
83
+ from workbench_local_dedupe import local_dedupe
97
84
  from workbench_scan_start import (
98
85
  archive_scan,
99
86
  insert_running_scan,
@@ -102,18 +89,12 @@ from workbench_scan_start import (
102
89
  scan_target_identity,
103
90
  stored_diff_target,
104
91
  )
105
- from workbench_scan_start import (
106
- compact_timestamp as compact_timestamp,
107
- )
108
92
  from workbench_schema import (
109
93
  MIGRATIONS,
110
94
  )
111
95
  from workbench_schema import (
112
96
  apply_migrations as apply_schema_migrations,
113
97
  )
114
- from workbench_schema import (
115
- sql_statements as sql_statements,
116
- )
117
98
  from workbench_source_excerpt import finding_source_excerpt, safe_source_path
118
99
  from workbench_target import (
119
100
  clean_worktree_content_digest,
@@ -133,6 +114,7 @@ from workbench_target import (
133
114
  require_git_worktree_head,
134
115
  require_remediation_target,
135
116
  require_scan_target_identity,
117
+ restore_directory_junctions,
136
118
  scan_target_warning,
137
119
  worktree_content_digest,
138
120
  worktree_content_digest_for_context,
@@ -236,9 +218,22 @@ def release_completion_file_lock(descriptor: int) -> None:
236
218
 
237
219
  def connect(*, deferred: bool = False) -> sqlite3.Connection:
238
220
  path = database_path()
239
- create_private_directory(path.parent)
221
+ guidance = (
222
+ f"Workbench database: {path}. Ensure the state directory and SQLite journal files "
223
+ "are writable, or set CODEX_SECURITY_STATE_DIR to a writable directory outside "
224
+ "the scanned repository."
225
+ )
226
+ try:
227
+ create_private_directory(path.parent)
228
+ except OSError:
229
+ print(guidance, file=sys.stderr)
230
+ raise
240
231
  for attempt in range(SQLITE_RETRY_ATTEMPTS):
241
- connection = sqlite3.connect(path, timeout=5)
232
+ try:
233
+ connection = sqlite3.connect(path, timeout=5)
234
+ except sqlite3.OperationalError:
235
+ print(guidance, file=sys.stderr)
236
+ raise
242
237
  try:
243
238
  connection.row_factory = sqlite3.Row
244
239
  connection.execute("PRAGMA foreign_keys = ON")
@@ -251,6 +246,7 @@ def connect(*, deferred: bool = False) -> sqlite3.Connection:
251
246
  except sqlite3.OperationalError as exc:
252
247
  connection.close()
253
248
  if attempt == SQLITE_RETRY_ATTEMPTS - 1 or not sqlite_busy(exc):
249
+ print(guidance, file=sys.stderr)
254
250
  raise
255
251
  time.sleep(0.05 * (2**attempt))
256
252
  raise AssertionError("SQLite retry loop exhausted unexpectedly.")
@@ -333,7 +329,11 @@ def require_diff_target(
333
329
  if commit is None:
334
330
  raise SystemExit(f"Commit is not available in the local checkout: {head}")
335
331
  parent_line = next(
336
- (line for line in commit.splitlines() if line.startswith(b"parent ")),
332
+ (
333
+ line
334
+ for line in commit.split(b"\n\n", 1)[0].splitlines()
335
+ if line.startswith(b"parent ")
336
+ ),
337
337
  None,
338
338
  )
339
339
  if parent_line is None:
@@ -405,7 +405,7 @@ def inspect_setup_values(
405
405
  def require_review_changes_target(target: Path) -> str:
406
406
  revision = require_git_worktree_head(target)
407
407
  repository_root = git_output(target, "rev-parse", "--show-toplevel")
408
- if repository_root is None or Path(repository_root).resolve() != target:
408
+ if repository_root is None or not Path(repository_root).samefile(target):
409
409
  raise SystemExit(
410
410
  "Review changes requires the checked-out Git repository root as the target."
411
411
  )
@@ -441,6 +441,20 @@ def requested_scan_paths(scan: sqlite3.Row) -> list[str]:
441
441
  return [scan["scope"]]
442
442
 
443
443
 
444
+ def requested_scan_file_paths(scan: sqlite3.Row) -> list[str]:
445
+ # Older scans did not record path kinds. Retain their lexical scope semantics
446
+ # rather than infer the original target from a possibly changed checkout.
447
+ if scan["recipe_json"] is None:
448
+ return []
449
+ recipe = json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json)
450
+ return recipe.get("scopeFilePaths", [])
451
+
452
+
453
+ def requested_finding_scope(scan: sqlite3.Row) -> list[tuple[str, bool]]:
454
+ files = {PurePosixPath(path) for path in requested_scan_file_paths(scan)}
455
+ return [(path, PurePosixPath(path) in files) for path in requested_scan_paths(scan)]
456
+
457
+
444
458
  def scan_contract(scan: sqlite3.Row) -> dict[str, Any]:
445
459
  target = Path(scan["target_path"])
446
460
  target_contract = {
@@ -462,6 +476,7 @@ def scan_contract(scan: sqlite3.Row) -> dict[str, Any]:
462
476
  "scope": {
463
477
  "requiredExcludePaths": [],
464
478
  "requestedPath": scan["scope"],
479
+ "filePaths": requested_scan_file_paths(scan),
465
480
  **(
466
481
  {"requiredIncludePaths": requested_scan_paths(scan)}
467
482
  if scan["mode"] != "diff"
@@ -607,7 +622,7 @@ def verify_manifest_binding(scan: sqlite3.Row, manifest: dict[str, Any]) -> None
607
622
 
608
623
 
609
624
  def require_scope(scope: str, mode: str, target: Path) -> str:
610
- value = scope.strip() or "."
625
+ value = scope if scope.strip() else "."
611
626
  requested_scope = Path(value)
612
627
  if "\\" in value and (os.name != "nt" or not requested_scope.is_absolute()):
613
628
  raise SystemExit("Scan scope must use repository-relative POSIX paths.")
@@ -621,6 +636,8 @@ def require_scope(scope: str, mode: str, target: Path) -> str:
621
636
  except (RuntimeError, ValueError) as exc:
622
637
  raise SystemExit("Scan scope must stay inside the scanned target.") from exc
623
638
  normalized = relative_scope.as_posix() or "."
639
+ if not normalized.strip():
640
+ normalized = "./" + normalized
624
641
  if mode == "deep" and normalized != ".":
625
642
  raise SystemExit("Deep Scan is repository-wide and cannot use a scoped path.")
626
643
  if not resolved_scope.is_dir():
@@ -666,8 +683,10 @@ def resolve_scan_id(connection: sqlite3.Connection, scan_id: str) -> str:
666
683
  def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
667
684
  workspace_id = require_uuid(args.workspace_id, "workspace-id")
668
685
  timestamp = now()
669
- target_path = optional_text(args.target_path, maximum=4096)
670
- default_scope = optional_text(args.scope, maximum=4096) or "."
686
+ target_path = args.target_path if optional_text(args.target_path, maximum=4096) else None
687
+ default_scope = args.scope if optional_text(args.scope, maximum=4096) else "."
688
+ if any(len(value) > 4096 for value in (target_path, default_scope) if value is not None):
689
+ raise SystemExit("Text value must be no longer than 4096 characters.")
671
690
  diff_target_kind = args.diff_target_kind if args.mode == "diff" else None
672
691
  diff_base_revision = (
673
692
  optional_text(args.diff_base_revision, maximum=512) if args.mode == "diff" else None
@@ -697,6 +716,7 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
697
716
  diff_head_revision = inspected["diffTarget"]["headRevision"]
698
717
  diff_content_digest = inspected["diffTarget"].get("contentDigest")
699
718
  except SystemExit:
719
+ # Preserve an incomplete setup so workspace_state can report its validation error.
700
720
  pass
701
721
  with connection:
702
722
  target_id = (
@@ -780,10 +800,7 @@ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) ->
780
800
  scope,
781
801
  args.mode,
782
802
  user_context_argument(args),
783
- diff_target["kind"] if diff_target else None,
784
- diff_target["baseRevision"] if diff_target else None,
785
- diff_target["headRevision"] if diff_target else None,
786
- diff_target.get("contentDigest") if diff_target else None,
803
+ *scan_diff_identity(diff_target or None),
787
804
  timestamp,
788
805
  workspace["id"],
789
806
  ),
@@ -943,130 +960,148 @@ def _start_prompt_driven_scan(
943
960
  target_identity = scan_target_identity(target, diff_target)
944
961
  target_root = scan_target_root(args.scan_root, target)
945
962
 
946
- connection.execute("BEGIN IMMEDIATE")
947
- try:
948
- current_target = require_remediation_target(target_path)
949
- current_diff_target = (
950
- require_diff_target(
951
- current_target,
952
- args.diff_target_kind,
953
- args.diff_base_revision,
954
- args.diff_head_revision,
955
- args.diff_content_digest,
956
- )
957
- if args.mode == "diff"
958
- else None
959
- )
960
- if (
961
- scan_target_identity(current_target, current_diff_target) != target_identity
962
- or scan_diff_identity(current_diff_target) != diff_identity
963
- ):
964
- raise SystemExit(
965
- "The selected scan target changed while the scan was starting. Try again."
963
+ busy_timeout = int(connection.execute("PRAGMA busy_timeout").fetchone()[0])
964
+ for attempt in range(SQLITE_RETRY_ATTEMPTS):
965
+ try:
966
+ # Wait before hashing, then release the writer slot while reading the target.
967
+ connection.execute("BEGIN IMMEDIATE")
968
+ connection.rollback()
969
+ current_target = require_remediation_target(target_path)
970
+ current_diff_target = (
971
+ require_diff_target(
972
+ current_target,
973
+ args.diff_target_kind,
974
+ args.diff_base_revision,
975
+ args.diff_head_revision,
976
+ args.diff_content_digest,
977
+ )
978
+ if args.mode == "diff"
979
+ else None
966
980
  )
967
- existing = connection.execute(
968
- """
969
- SELECT scans.* FROM scans
970
- JOIN workspaces ON workspaces.active_scan_id = scans.id
971
- WHERE workspaces.thread_id = ? AND workspaces.target_path = ?
972
- AND workspaces.default_scope = ? AND workspaces.default_mode = ?
973
- AND workspaces.user_context IS ? AND workspaces.target_summary IS ?
974
- AND workspaces.diff_target_kind IS ? AND workspaces.diff_base_revision IS ?
975
- AND workspaces.diff_head_revision IS ? AND workspaces.diff_content_digest IS ?
976
- AND workspaces.submitted = 1 AND scans.target_revision = ?
977
- AND scans.target_snapshot_digest IS ? AND scans.target_device = ?
978
- AND scans.target_inode = ? AND scans.status = 'running'
979
- AND scans.handoff_status = 'delivered'
980
- AND (
981
- (? = 0 AND scans.handoff_claim_token IS NULL)
982
- OR (
983
- ? = 1 AND scans.handoff_claim_token IS NOT NULL
984
- AND scans.continuation_thread_id = ?
985
- )
981
+ if (
982
+ scan_target_identity(current_target, current_diff_target) != target_identity
983
+ or scan_diff_identity(current_diff_target) != diff_identity
984
+ ):
985
+ raise SystemExit(
986
+ "The selected scan target changed while the scan was starting. Try again."
986
987
  )
987
- ORDER BY scans.updated_at DESC, scans.started_at DESC, scans.id LIMIT 1
988
- """,
989
- (
990
- thread_id,
991
- target_path,
992
- scope,
993
- args.mode,
994
- user_context,
995
- target_summary,
996
- *diff_identity,
997
- *target_identity,
998
- int(headless_standard),
999
- int(headless_standard),
1000
- thread_id,
1001
- ),
1002
- ).fetchone()
1003
- if existing is not None:
1004
- connection.commit()
1005
- return {
1006
- **scan_context(connection, existing["id"]),
1007
- "startDisposition": "joined",
1008
- }
1009
- create_private_directory(target_root)
1010
- workspace_id = str(uuid.uuid4())
1011
- scan_id = str(uuid.uuid4())
1012
- timestamp = now()
1013
- target_id = ensure_security_target(connection, target_path)
1014
- connection.execute(
1015
- """
1016
- INSERT INTO workspaces (
1017
- id, thread_id, target_id, target_path, target_title, target_summary, default_scope,
1018
- default_mode, user_context, diff_target_kind, diff_base_revision,
1019
- diff_head_revision, diff_content_digest, submitted, created_at, updated_at
1020
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)
1021
- """,
1022
- (
1023
- workspace_id,
1024
- thread_id,
1025
- target_id,
1026
- target_path,
1027
- target.name,
1028
- target_summary,
1029
- scope,
1030
- args.mode,
1031
- user_context,
1032
- *diff_identity,
1033
- timestamp,
1034
- timestamp,
1035
- ),
1036
- )
1037
- workspace = require_workspace(connection, workspace_id)
1038
- insert_running_scan(
1039
- connection,
1040
- scan_id=scan_id,
1041
- workspace=workspace,
1042
- target=target,
1043
- scope=scope,
1044
- diff_target=diff_target,
1045
- target_identity=target_identity,
1046
- target_root=target_root,
1047
- target_summary=target_summary,
1048
- scope_file_count=scope_file_count,
1049
- timestamp=timestamp,
1050
- handoff_status="delivered",
1051
- model=args.model,
1052
- reasoning_effort=args.reasoning_effort,
1053
- )
1054
- if headless_standard:
1055
- claimed = connection.execute(
988
+ # If another writer arrived during hashing, retry without waiting on a stale hash.
989
+ connection.execute("PRAGMA busy_timeout = 0")
990
+ try:
991
+ connection.execute("BEGIN IMMEDIATE")
992
+ finally:
993
+ connection.execute(f"PRAGMA busy_timeout = {busy_timeout}")
994
+ existing = connection.execute(
995
+ """
996
+ SELECT scans.* FROM scans
997
+ JOIN workspaces ON workspaces.active_scan_id = scans.id
998
+ WHERE workspaces.thread_id = ? AND workspaces.target_path = ?
999
+ AND workspaces.default_scope = ? AND workspaces.default_mode = ?
1000
+ AND workspaces.user_context IS ? AND workspaces.target_summary IS ?
1001
+ AND workspaces.diff_target_kind IS ? AND workspaces.diff_base_revision IS ?
1002
+ AND workspaces.diff_head_revision IS ? AND workspaces.diff_content_digest IS ?
1003
+ AND workspaces.submitted = 1 AND scans.target_revision = ?
1004
+ AND scans.target_snapshot_digest IS ? AND scans.target_device = ?
1005
+ AND scans.target_inode = ? AND scans.status = 'running'
1006
+ AND scans.handoff_status = 'delivered'
1007
+ AND (
1008
+ (? = 0 AND scans.handoff_claim_token IS NULL)
1009
+ OR (
1010
+ ? = 1 AND scans.handoff_claim_token IS NOT NULL
1011
+ AND scans.continuation_thread_id = ?
1012
+ )
1013
+ )
1014
+ ORDER BY scans.updated_at DESC, scans.started_at DESC, scans.id LIMIT 1
1015
+ """,
1016
+ (
1017
+ thread_id,
1018
+ target_path,
1019
+ scope,
1020
+ args.mode,
1021
+ user_context,
1022
+ target_summary,
1023
+ *diff_identity,
1024
+ *target_identity,
1025
+ int(headless_standard),
1026
+ int(headless_standard),
1027
+ thread_id,
1028
+ ),
1029
+ ).fetchone()
1030
+ if existing is not None:
1031
+ connection.commit()
1032
+ return {
1033
+ **scan_context(connection, existing["id"]),
1034
+ "startDisposition": "joined",
1035
+ }
1036
+ create_private_directory(target_root)
1037
+ workspace_id = str(uuid.uuid4())
1038
+ scan_id = str(uuid.uuid4())
1039
+ timestamp = now()
1040
+ target_id = ensure_security_target(connection, target_path)
1041
+ connection.execute(
1056
1042
  """
1057
- UPDATE scans
1058
- SET handoff_claim_token = ?, continuation_thread_id = ?
1059
- WHERE id = ? AND status = 'running' AND handoff_status = 'delivered'
1060
- AND handoff_claim_token IS NULL AND continuation_thread_id IS NULL
1043
+ INSERT INTO workspaces (
1044
+ id, thread_id, target_id, target_path, target_title, target_summary, default_scope,
1045
+ default_mode, user_context, diff_target_kind, diff_base_revision,
1046
+ diff_head_revision, diff_content_digest, submitted, created_at, updated_at
1047
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)
1061
1048
  """,
1062
- (str(uuid.uuid4()), thread_id, scan_id),
1049
+ (
1050
+ workspace_id,
1051
+ thread_id,
1052
+ target_id,
1053
+ target_path,
1054
+ target.name,
1055
+ target_summary,
1056
+ scope,
1057
+ args.mode,
1058
+ user_context,
1059
+ *diff_identity,
1060
+ timestamp,
1061
+ timestamp,
1062
+ ),
1063
1063
  )
1064
- if claimed.rowcount != 1:
1065
- raise SystemExit("Codex Security headless scan ownership could not be recorded.")
1066
- connection.commit()
1067
- except BaseException:
1068
- connection.rollback()
1069
- raise
1064
+ workspace = require_workspace(connection, workspace_id)
1065
+ insert_running_scan(
1066
+ connection,
1067
+ scan_id=scan_id,
1068
+ workspace=workspace,
1069
+ target=target,
1070
+ scope=scope,
1071
+ diff_target=diff_target,
1072
+ target_identity=target_identity,
1073
+ target_root=target_root,
1074
+ target_summary=target_summary,
1075
+ scope_file_count=scope_file_count,
1076
+ timestamp=timestamp,
1077
+ handoff_status="delivered",
1078
+ model=args.model,
1079
+ reasoning_effort=args.reasoning_effort,
1080
+ )
1081
+ if headless_standard:
1082
+ claimed = connection.execute(
1083
+ """
1084
+ UPDATE scans
1085
+ SET handoff_claim_token = ?, continuation_thread_id = ?
1086
+ WHERE id = ? AND status = 'running' AND handoff_status = 'delivered'
1087
+ AND handoff_claim_token IS NULL AND continuation_thread_id IS NULL
1088
+ """,
1089
+ (str(uuid.uuid4()), thread_id, scan_id),
1090
+ )
1091
+ if claimed.rowcount != 1:
1092
+ raise SystemExit(
1093
+ "Codex Security headless scan ownership could not be recorded."
1094
+ )
1095
+ connection.commit()
1096
+ break
1097
+ except sqlite3.OperationalError as exc:
1098
+ connection.rollback()
1099
+ if attempt == SQLITE_RETRY_ATTEMPTS - 1 or not sqlite_busy(exc):
1100
+ raise
1101
+ time.sleep(0.05 * (2**attempt))
1102
+ except BaseException:
1103
+ connection.rollback()
1104
+ raise
1070
1105
  return {**scan_context(connection, scan_id), "startDisposition": "created"}
1071
1106
 
1072
1107
 
@@ -1305,12 +1340,11 @@ def budget_exhausted_draft(
1305
1340
  manifest = {
1306
1341
  "scan": {
1307
1342
  "target": target,
1308
- "scope": {"limitations": [warning], "validationMode": "incomplete"},
1343
+ "scope": {"limitations": [warning]},
1309
1344
  }
1310
1345
  }
1311
1346
  findings = {"findings": []}
1312
1347
  coverage = {
1313
- "completeness": "partial",
1314
1348
  "inventoryStrategy": (
1315
1349
  "scoped_path" if expected_coverage_mode(scan) == "scoped_path" else "repository"
1316
1350
  ),
@@ -1396,7 +1430,7 @@ def budget_exhausted_draft(
1396
1430
  "reason": "Validation was deferred because the scan reached its cost limit.",
1397
1431
  }
1398
1432
  )
1399
- coverage["completeness"] = "partial"
1433
+ coverage.pop("completeness", None)
1400
1434
  for name, payload in (
1401
1435
  ("findings.json", findings),
1402
1436
  ("coverage.json", coverage),
@@ -1517,17 +1551,33 @@ def complete_scan_locked(
1517
1551
  scan_dir,
1518
1552
  expected_coverage_mode=expected_coverage_mode(scan),
1519
1553
  completion_binding=completion_binding,
1520
- completion_warnings=warnings if scan["mode"] != "deep" else None,
1554
+ recover_unsealed=scan["mode"] != "deep",
1555
+ allow_missing_writeups=True,
1521
1556
  draft_documents=draft_documents,
1557
+ finding_scope=requested_finding_scope(scan) if scan["mode"] == "deep" else None,
1522
1558
  )
1559
+ warnings.extend(warning for warning in prepared.warnings if warning not in warnings)
1523
1560
  add_warning()
1561
+ if prepared.warnings:
1562
+ # Save the explanation before publication removes the broken reference,
1563
+ # so a retry after failed publication retains it.
1564
+ with connection:
1565
+ connection.execute(
1566
+ "UPDATE scans SET completion_warnings_json = ? WHERE id = ? AND status = 'running'",
1567
+ (json.dumps(warnings), scan_id),
1568
+ )
1524
1569
  wrote = True
1525
1570
  manifest, findings, _ = _write_prepared_scan_finalization(
1526
1571
  prepared, projection_warnings=warnings
1527
1572
  )
1528
1573
  except ContractError as exc:
1529
- if wrote or (
1574
+ # Only a coordinator-selected parent is fenced for output-write replay.
1575
+ selected_deep_parent = scan["mode"] == "deep" and deep_scan.require_deep_scan_run(
1576
+ connection, scan_id
1577
+ )["manifest_path"] == str(scan_dir / ARTIFACTS["manifest"])
1578
+ if (wrote and not selected_deep_parent) or (
1530
1579
  scan["mode"] == "deep"
1580
+ and not wrote
1531
1581
  and not already_sealed
1532
1582
  and not isinstance(exc, RecoverableContractError)
1533
1583
  ):
@@ -1562,7 +1612,7 @@ def complete_scan_locked(
1562
1612
  )
1563
1613
  cost_json = parse_scan_cost(scan_usage.measured_scan_cost_json(measured_usage))
1564
1614
  connection.execute("BEGIN IMMEDIATE")
1565
- try:
1615
+ with connection:
1566
1616
  timestamp = manifest["scan"]["completedAt"]
1567
1617
  scan = require_scan(connection, scan["id"])
1568
1618
  if scan["status"] == "complete":
@@ -1614,24 +1664,36 @@ def complete_scan_locked(
1614
1664
  )
1615
1665
  if updated.rowcount != 1:
1616
1666
  raise SystemExit("Only a running scan can be completed.")
1617
- connection.commit()
1618
- except BaseException:
1619
- connection.rollback()
1620
- raise
1621
1667
  context = scan_context(connection, scan["id"])
1622
1668
  context["targetWarnings"] = target_warnings
1623
1669
  return context
1624
1670
 
1625
1671
 
1626
- def register_cli_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
1627
- repository = require_target(args.repository)
1628
- require_scannable_target(repository)
1672
+ def require_cli_scan_directory(repository: Path, args: argparse.Namespace) -> Path:
1629
1673
  scan_dir = require_canonical_scan_directory(Path(args.scan_dir).expanduser())
1630
- if scan_dir == repository or repository in scan_dir.parents:
1631
- raise SystemExit("The scan artifact directory must be outside the selected target.")
1632
- if next(scan_dir.iterdir(), None) is not None:
1674
+ if scan_dir == repository or repository in scan_dir.parents or scan_dir in repository.parents:
1675
+ raise SystemExit(
1676
+ "The scan artifact directory must be outside and not contain the selected target."
1677
+ )
1678
+ if (not args.archive_existing or args.archived_scan_dir is not None) and next(
1679
+ scan_dir.iterdir(), None
1680
+ ) is not None:
1633
1681
  raise SystemExit("The scan artifact directory must be empty before the scan starts.")
1682
+ return scan_dir
1683
+
1634
1684
 
1685
+ def register_cli_scan(
1686
+ connection: sqlite3.Connection,
1687
+ args: argparse.Namespace,
1688
+ *,
1689
+ before_archive: Callable[[], None] | None = None,
1690
+ ) -> dict[str, Any]:
1691
+ repository = require_target(args.repository)
1692
+ require_scannable_target(repository)
1693
+ scan_dir = None
1694
+ if not args.archive_existing or args.archived_scan_dir is not None:
1695
+ # Preserve early output rejection when this call will not move the directory.
1696
+ scan_dir = require_cli_scan_directory(repository, args)
1635
1697
  user_context = None
1636
1698
  workflow_id = None
1637
1699
  if args.registration_json_stdin:
@@ -1644,6 +1706,10 @@ def register_cli_scan(connection: sqlite3.Connection, args: argparse.Namespace)
1644
1706
  recipe = parse_scan_recipe(recipe_json, repository)
1645
1707
  requested_target = recipe["target"]
1646
1708
  paths = requested_target["paths"]
1709
+ # Capture host-observed kinds once; resumes and publication use the saved recipe.
1710
+ recipe.pop("scopeFilePaths", None)
1711
+ if file_paths := [path for path in paths if (repository / path).is_file()]:
1712
+ recipe["scopeFilePaths"] = file_paths
1647
1713
  scope = paths[0] if len(paths) == 1 else "."
1648
1714
  diff_target = None
1649
1715
  if requested_target["kind"] in {"refs", "working_tree"}:
@@ -1681,63 +1747,81 @@ def register_cli_scan(connection: sqlite3.Connection, args: argparse.Namespace)
1681
1747
  workspace_id = str(uuid.uuid4())
1682
1748
 
1683
1749
  connection.execute("BEGIN IMMEDIATE")
1684
- with connection:
1685
- archive_scan(connection, args, scan_dir, timestamp, require_canonical_scan_directory)
1686
- target_id = ensure_security_target(connection, str(repository))
1687
- if parent_scan_id is not None:
1688
- parent = require_scan(connection, parent_scan_id)
1689
- if parent["target_id"] != target_id:
1690
- raise SystemExit("A rerun must belong to the same repository as its parent scan.")
1691
-
1692
- connection.execute(
1693
- """
1694
- INSERT INTO workspaces (
1695
- id, target_id, target_path, target_title, default_scope, default_mode,
1696
- diff_target_kind, diff_base_revision, diff_head_revision,
1697
- diff_content_digest, submitted, created_at, updated_at
1698
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)
1699
- """,
1700
- (
1701
- workspace_id,
1702
- target_id,
1703
- str(repository),
1704
- repository.name,
1705
- scope,
1706
- mode,
1707
- *scan_diff_identity(diff_target),
1708
- timestamp,
1709
- timestamp,
1710
- ),
1711
- )
1712
- workspace = require_workspace(connection, workspace_id)
1713
- insert_running_scan(
1750
+ try:
1751
+ if scan_dir is None:
1752
+ # Host archiving temporarily removes the output directory. Wait for
1753
+ # the existing writer before inspecting its replacement.
1754
+ scan_dir = require_cli_scan_directory(repository, args)
1755
+ with archive_scan(
1714
1756
  connection,
1715
- scan_id=scan_id,
1716
- workspace=workspace,
1717
- target=repository,
1718
- scope=scope,
1719
- diff_target=diff_target,
1720
- target_identity=target_identity,
1721
- target_root=scan_dir.parent,
1722
- target_summary=None,
1723
- scope_file_count=scope_file_count,
1724
- timestamp=timestamp,
1725
- handoff_status="delivered",
1726
- scan_dir=scan_dir,
1727
- )
1728
- connection.execute(
1729
- "UPDATE scans SET recipe_json = ?, parent_scan_id = ?, user_context = ? WHERE id = ?",
1730
- (
1731
- json.dumps(recipe, allow_nan=False, separators=(",", ":"), sort_keys=True),
1732
- parent_scan_id,
1733
- user_context,
1734
- scan_id,
1735
- ),
1736
- )
1737
- if workflow_id is not None:
1738
- register_workflow_scan(connection, workflow_id, scan_id, str(scan_dir), timestamp)
1757
+ args,
1758
+ scan_dir,
1759
+ timestamp,
1760
+ require_canonical_scan_directory,
1761
+ before_archive=before_archive,
1762
+ ) as archived_scan_dir:
1763
+ target_id = ensure_security_target(connection, str(repository))
1764
+ if parent_scan_id is not None:
1765
+ parent = require_scan(connection, parent_scan_id)
1766
+ if parent["target_id"] != target_id:
1767
+ raise SystemExit(
1768
+ "A rerun must belong to the same repository as its parent scan."
1769
+ )
1770
+
1771
+ connection.execute(
1772
+ """
1773
+ INSERT INTO workspaces (
1774
+ id, target_id, target_path, target_title, default_scope, default_mode,
1775
+ diff_target_kind, diff_base_revision, diff_head_revision,
1776
+ diff_content_digest, submitted, created_at, updated_at
1777
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)
1778
+ """,
1779
+ (
1780
+ workspace_id,
1781
+ target_id,
1782
+ str(repository),
1783
+ repository.name,
1784
+ scope,
1785
+ mode,
1786
+ *scan_diff_identity(diff_target),
1787
+ timestamp,
1788
+ timestamp,
1789
+ ),
1790
+ )
1791
+ workspace = require_workspace(connection, workspace_id)
1792
+ insert_running_scan(
1793
+ connection,
1794
+ scan_id=scan_id,
1795
+ workspace=workspace,
1796
+ target=repository,
1797
+ scope=scope,
1798
+ diff_target=diff_target,
1799
+ target_identity=target_identity,
1800
+ target_root=scan_dir.parent,
1801
+ target_summary=None,
1802
+ scope_file_count=scope_file_count,
1803
+ timestamp=timestamp,
1804
+ handoff_status="delivered",
1805
+ scan_dir=scan_dir,
1806
+ )
1807
+ connection.execute(
1808
+ "UPDATE scans SET recipe_json = ?, parent_scan_id = ?, user_context = ? WHERE id = ?",
1809
+ (
1810
+ json.dumps(recipe, allow_nan=False, separators=(",", ":"), sort_keys=True),
1811
+ parent_scan_id,
1812
+ user_context,
1813
+ scan_id,
1814
+ ),
1815
+ )
1816
+ if workflow_id is not None:
1817
+ register_workflow_scan(connection, workflow_id, scan_id, str(scan_dir), timestamp)
1818
+ connection.commit()
1819
+ except BaseException:
1820
+ connection.rollback()
1821
+ raise
1739
1822
  scan = require_scan(connection, scan_id)
1740
1823
  return {
1824
+ **({"archivedScanDir": str(archived_scan_dir)} if archived_scan_dir is not None else {}),
1741
1825
  "contract": scan_contract(scan),
1742
1826
  "scanDir": str(scan_dir),
1743
1827
  "scanId": scan_id,
@@ -1835,24 +1919,6 @@ def coverage_for_comparison(scan: sqlite3.Row) -> dict[str, Any]:
1835
1919
  return saved_results.coverage_for_comparison(_WORKBENCH_DB_CONTEXT, scan)
1836
1920
 
1837
1921
 
1838
- def preserve_scan_results_locked(connection: sqlite3.Connection, scan_id: str) -> bool:
1839
- return saved_results.preserve_scan_results_locked(_WORKBENCH_DB_CONTEXT, connection, scan_id)
1840
-
1841
-
1842
- def recover_scan_results(
1843
- connection: sqlite3.Connection, args: argparse.Namespace
1844
- ) -> dict[str, Any]:
1845
- return saved_results.recover_scan_results(_WORKBENCH_DB_CONTEXT, connection, args)
1846
-
1847
-
1848
- def fail_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
1849
- return saved_results.fail_scan(_WORKBENCH_DB_CONTEXT, connection, args)
1850
-
1851
-
1852
- def cancel_scan_locked(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
1853
- return saved_results.cancel_scan_locked(_WORKBENCH_DB_CONTEXT, connection, args)
1854
-
1855
-
1856
1922
  def preserve_stopped_results_after_transition(connection: sqlite3.Connection, scan_id: str) -> None:
1857
1923
  saved_results.preserve_stopped_results_after_transition(
1858
1924
  _WORKBENCH_DB_CONTEXT, connection, scan_id
@@ -1887,7 +1953,7 @@ def set_finding_triage(connection: sqlite3.Connection, args: argparse.Namespace)
1887
1953
  and remediation["pending_action"] is not None
1888
1954
  and not (
1889
1955
  remediation["state"] == "failed"
1890
- and not remediation_claim_is_active(remediation)
1956
+ and not remediation_state.remediation_claim_is_active(remediation)
1891
1957
  )
1892
1958
  ):
1893
1959
  raise SystemExit(
@@ -1957,7 +2023,7 @@ def request_finding_remediation(
1957
2023
  ) -> dict[str, Any]:
1958
2024
  request_id = require_uuid(args.request_id, "request-id")
1959
2025
  action_token = require_uuid(args.action_token, "action-token")
1960
- try:
2026
+ with connection:
1961
2027
  occurrence = require_occurrence(connection, args.occurrence_id)
1962
2028
  require_finding_open(connection, occurrence["id"])
1963
2029
  scan = require_scan(connection, occurrence["scan_id"])
@@ -1999,7 +2065,7 @@ def request_finding_remediation(
1999
2065
  "verifying",
2000
2066
  }
2001
2067
  if active_operation and (
2002
- latest["state"] != "failed" or remediation_claim_is_active(latest)
2068
+ latest["state"] != "failed" or remediation_state.remediation_claim_is_active(latest)
2003
2069
  ):
2004
2070
  raise SystemExit(
2005
2071
  "Finish or retry the active remediation operation before regenerating."
@@ -2046,10 +2112,6 @@ def request_finding_remediation(
2046
2112
  timestamp,
2047
2113
  ),
2048
2114
  )
2049
- connection.commit()
2050
- except BaseException:
2051
- connection.rollback()
2052
- raise
2053
2115
  return scan_context(connection, occurrence["scan_id"])
2054
2116
 
2055
2117
 
@@ -2058,16 +2120,11 @@ def request_finding_remediation_action(
2058
2120
  ) -> dict[str, Any]:
2059
2121
  request_id = require_uuid(args.request_id, "request-id")
2060
2122
  action_token = require_uuid(args.action_token, "action-token")
2061
- try:
2123
+ with connection:
2062
2124
  occurrence = require_occurrence(connection, args.occurrence_id)
2063
2125
  require_finding_open(connection, occurrence["id"])
2064
2126
  scan = require_scan(connection, occurrence["scan_id"])
2065
- current = connection.execute(
2066
- "SELECT * FROM finding_remediation_attempts WHERE request_id = ?",
2067
- (request_id,),
2068
- ).fetchone()
2069
- if current is None or current["occurrence_id"] != occurrence["id"]:
2070
- raise SystemExit("Codex Security finding remediation request not found.")
2127
+ current = remediation_state.require_request(connection, request_id, occurrence)
2071
2128
  if current["pending_action"] is not None:
2072
2129
  if (
2073
2130
  current["pending_action"] == args.action
@@ -2122,10 +2179,6 @@ def request_finding_remediation_action(
2122
2179
  raise SystemExit(
2123
2180
  "This remediation request changed. Refresh it before recording an update."
2124
2181
  )
2125
- connection.commit()
2126
- except BaseException:
2127
- connection.rollback()
2128
- raise
2129
2182
  return scan_context(connection, occurrence["scan_id"])
2130
2183
 
2131
2184
 
@@ -2135,16 +2188,11 @@ def claim_finding_remediation_resend(
2135
2188
  request_id = require_uuid(args.request_id, "request-id")
2136
2189
  action_token = require_uuid(args.action_token, "action-token")
2137
2190
  connection.execute("BEGIN IMMEDIATE")
2138
- try:
2191
+ with connection:
2139
2192
  timestamp = now()
2140
2193
  occurrence = require_occurrence(connection, args.occurrence_id)
2141
2194
  require_finding_open(connection, occurrence["id"])
2142
- current = connection.execute(
2143
- "SELECT * FROM finding_remediation_attempts WHERE request_id = ?",
2144
- (request_id,),
2145
- ).fetchone()
2146
- if current is None or current["occurrence_id"] != occurrence["id"]:
2147
- raise SystemExit("Codex Security finding remediation request not found.")
2195
+ current = remediation_state.require_request(connection, request_id, occurrence)
2148
2196
  if current["pending_action"] is None:
2149
2197
  raise SystemExit("This remediation attempt does not have a pending host request.")
2150
2198
  if current["pending_action_claim_token"] == action_token:
@@ -2154,7 +2202,6 @@ def claim_finding_remediation_resend(
2154
2202
  return result
2155
2203
  delivered_at = current["pending_action_delivered_at"]
2156
2204
  if delivered_at is not None:
2157
- claimed_token = action_token
2158
2205
  updated = connection.execute(
2159
2206
  """
2160
2207
  UPDATE finding_remediation_attempts
@@ -2177,7 +2224,6 @@ def claim_finding_remediation_resend(
2177
2224
  "This remediation worker is still within its execution lease. Retry later."
2178
2225
  )
2179
2226
  else:
2180
- claimed_token = action_token
2181
2227
  updated = connection.execute(
2182
2228
  """
2183
2229
  UPDATE finding_remediation_attempts
@@ -2202,12 +2248,8 @@ def claim_finding_remediation_resend(
2202
2248
  unavailable = "This remediation host request is still owned by another panel. Retry after its lease expires."
2203
2249
  if updated.rowcount != 1:
2204
2250
  raise SystemExit(unavailable)
2205
- connection.commit()
2206
- except BaseException:
2207
- connection.rollback()
2208
- raise
2209
2251
  result = scan_context(connection, occurrence["scan_id"])
2210
- result["actionToken"] = claimed_token
2252
+ result["actionToken"] = action_token
2211
2253
  return result
2212
2254
 
2213
2255
 
@@ -2267,12 +2309,7 @@ def set_finding_remediation(
2267
2309
  occurrence = require_occurrence(connection, args.occurrence_id)
2268
2310
  require_finding_open(connection, occurrence["id"])
2269
2311
  scan = require_scan(connection, occurrence["scan_id"])
2270
- current = connection.execute(
2271
- "SELECT * FROM finding_remediation_attempts WHERE request_id = ?",
2272
- (request_id,),
2273
- ).fetchone()
2274
- if current is None or current["occurrence_id"] != occurrence["id"]:
2275
- raise SystemExit("Codex Security finding remediation request not found.")
2312
+ current = remediation_state.require_request(connection, request_id, occurrence)
2276
2313
  if current["version"] != args.expected_version:
2277
2314
  raise SystemExit(
2278
2315
  "This remediation request changed. Refresh it before recording an update."
@@ -2283,8 +2320,8 @@ def set_finding_remediation(
2283
2320
  )
2284
2321
  if current["pending_action_claim_token"] != action_token:
2285
2322
  raise SystemExit("This remediation host request is owned by a different action token.")
2286
- remediation.require_transition(current["state"], args.state)
2287
- remediation.require_pending_action(current, args.state)
2323
+ remediation_state.require_transition(current["state"], args.state)
2324
+ remediation_state.require_pending_action(current, args.state)
2288
2325
  patch_path = current["patch_path"]
2289
2326
  if args.patch_path is not None:
2290
2327
  requested_patch_path = require_scan_relative_file(scan, args.patch_path)
@@ -2381,10 +2418,6 @@ def set_finding_remediation(
2381
2418
  return scan_context(connection, occurrence["scan_id"])
2382
2419
 
2383
2420
 
2384
- def export_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
2385
- return publication.export_findings(_WORKBENCH_PUBLICATION_CONTEXT, connection, args)
2386
-
2387
-
2388
2421
  def require_reviewed_patch_applied(
2389
2422
  scan: sqlite3.Row, remediation: sqlite3.Row, patch_path: str
2390
2423
  ) -> str | None:
@@ -2398,11 +2431,10 @@ def require_reviewed_patch_applied(
2398
2431
  )
2399
2432
  unversioned = remediation["base_revision"] == "unversioned"
2400
2433
  excluded = (Path(scan["scan_dir"]),)
2401
- git_dir = None
2402
- pathspec = None
2434
+ # Unborn repositories still need their config while metadata junctions are deferred.
2435
+ git_dir = git_output(target, "rev-parse", "--absolute-git-dir")
2403
2436
  if not unversioned:
2404
- _, pathspec = git_worktree_context(target)
2405
- git_dir = git_output(target, "rev-parse", "--absolute-git-dir")
2437
+ repository, pathspec = git_worktree_context(target)
2406
2438
  if git_dir is None:
2407
2439
  raise SystemExit("Could not inspect the selected Git working tree.")
2408
2440
  excluded += tuple(path for path, _ in git_submodule_entries(target))
@@ -2419,9 +2451,9 @@ def require_reviewed_patch_applied(
2419
2451
  checkout_root = Path(temporary) / "checkout"
2420
2452
  if unversioned:
2421
2453
  checkout = checkout_root
2422
- copy_directory_excluding(target, checkout, excluded)
2454
+ junctions = copy_directory_excluding(target, checkout, excluded)
2423
2455
  else:
2424
- copy_git_worktree_files(target, checkout_root, excluded)
2456
+ _, junctions = copy_git_worktree_files(target, checkout_root, excluded)
2425
2457
  arguments = ["apply", "--reverse", "--whitespace=nowarn"]
2426
2458
  if unversioned:
2427
2459
  arguments.append("--no-index")
@@ -2439,6 +2471,11 @@ def require_reviewed_patch_applied(
2439
2471
  raise SystemExit(
2440
2472
  "The selected checkout does not contain the reviewed remediation patch. Apply exactly that patch before recording it as applied."
2441
2473
  )
2474
+ restore_directory_junctions(
2475
+ target if unversioned else repository,
2476
+ checkout if unversioned else checkout_root,
2477
+ junctions,
2478
+ )
2442
2479
  reverted_digest = (
2443
2480
  directory_content_digest(checkout)
2444
2481
  if unversioned
@@ -2451,11 +2488,16 @@ def require_reviewed_patch_applied(
2451
2488
  )
2452
2489
  if reverted_digest != remediation["base_content_digest"] and unversioned:
2453
2490
  checkout = Path(temporary) / "checkout-lf"
2454
- copy_directory_excluding(target, checkout, excluded)
2491
+ junctions = copy_directory_excluding(target, checkout, excluded)
2455
2492
  applied_without_conversion = git_command(
2456
- checkout, "-c", "core.autocrlf=input", *arguments, text=True
2493
+ checkout,
2494
+ "-c",
2495
+ "core.autocrlf=input",
2496
+ *arguments,
2497
+ text=True,
2457
2498
  )
2458
2499
  if applied_without_conversion.returncode == 0:
2500
+ restore_directory_junctions(target, checkout, junctions)
2459
2501
  reverted_digest = directory_content_digest(checkout)
2460
2502
  if reverted_digest != remediation["base_content_digest"]:
2461
2503
  raise SystemExit(
@@ -2502,15 +2544,14 @@ def require_sha256_digest(value: str, label: str) -> str:
2502
2544
 
2503
2545
 
2504
2546
  def require_scan_relative_file(scan: sqlite3.Row, value: str) -> str:
2505
- normalized = optional_text(value, maximum=4096)
2506
- if normalized is None or "\\" in normalized:
2547
+ if len(value) > 4096:
2548
+ raise SystemExit("Text value must be no longer than 4096 characters.")
2549
+ if not value.strip() or "\\" in value:
2507
2550
  raise SystemExit("Patch path must identify a scan-local regular file.")
2508
- parsed = PurePosixPath(normalized)
2551
+ parsed = PurePosixPath(value)
2509
2552
  if parsed.is_absolute() or ".." in parsed.parts:
2510
2553
  raise SystemExit("Patch path must identify a scan-local regular file.")
2511
- path = artifact_path(Path(scan["scan_dir"]), parsed.as_posix(), required=True)
2512
- if path is None:
2513
- raise SystemExit("Patch path must identify a scan-local regular file.")
2554
+ artifact_path(Path(scan["scan_dir"]), parsed.as_posix(), required=True)
2514
2555
  return parsed.as_posix()
2515
2556
 
2516
2557
 
@@ -2604,6 +2645,7 @@ def workspace_state(
2604
2645
  target = require_target(workspace["target_path"])
2605
2646
  target_metadata = git_target_metadata(target)
2606
2647
  except SystemExit:
2648
+ # Target metadata is optional; retain the original setup error for the caller.
2607
2649
  pass
2608
2650
  result["diffTarget"] = validated_diff_target or persisted_diff_target
2609
2651
  result["setupValidation"] = {
@@ -2761,13 +2803,10 @@ def scan_result(
2761
2803
  "status": "canceled" if scan["canceled_at"] else scan["status"],
2762
2804
  "updatedAt": progress["updated_at"],
2763
2805
  }
2806
+ review_updated_at = ""
2764
2807
  if independent_reviews is not None:
2765
- progress_result["independentReviews"] = {
2766
- "active": independent_reviews["active"],
2767
- "completed": independent_reviews["completed"],
2768
- "maximum": independent_reviews["maximum"],
2769
- "consolidating": independent_reviews["consolidating"],
2770
- }
2808
+ review_updated_at = str(independent_reviews.pop("updatedAt"))
2809
+ progress_result["independentReviews"] = independent_reviews
2771
2810
  relations = scan_history.finding_relations(
2772
2811
  connection, scan["id"], (row["id"] for row in occurrence_rows)
2773
2812
  )
@@ -2794,6 +2833,7 @@ def scan_result(
2794
2833
  "mode": scan["mode"],
2795
2834
  "model": scan["model"],
2796
2835
  "diffTarget": stored_diff_target(scan),
2836
+ "name": scan["name"],
2797
2837
  "progress": progress_result,
2798
2838
  "reasoningEffort": scan["reasoning_effort"],
2799
2839
  "remediationAvailable": remediation_available,
@@ -2811,7 +2851,7 @@ def scan_result(
2811
2851
  "updatedAt": max(
2812
2852
  scan["updated_at"],
2813
2853
  progress["updated_at"],
2814
- str(independent_reviews["updatedAt"]) if independent_reviews is not None else "",
2854
+ review_updated_at,
2815
2855
  finding_management_updated_at(connection, scan["id"]) or "",
2816
2856
  ),
2817
2857
  "userContext": scan["user_context"],
@@ -2821,7 +2861,7 @@ def scan_result(
2821
2861
 
2822
2862
  def remediation_availability(scan: sqlite3.Row) -> tuple[bool, str | None]:
2823
2863
  if scan["status"] != "complete":
2824
- return False, remediation.SCAN_STATUS_ERROR
2864
+ return False, remediation_state.SCAN_STATUS_ERROR
2825
2865
  try:
2826
2866
  current_revision = git_revision(require_scan_target_identity(scan))
2827
2867
  except SystemExit as exc:
@@ -3115,8 +3155,7 @@ def finding_remediation_result(
3115
3155
  row = connection.execute(
3116
3156
  """
3117
3157
  SELECT remediation.request_id, remediation.state, remediation.version,
3118
- remediation.base_revision, remediation.base_content_digest,
3119
- remediation.applied_content_digest, remediation.pending_action,
3158
+ remediation.base_revision, remediation.pending_action,
3120
3159
  remediation.pending_action_claimed_at, remediation.pending_action_claim_token,
3121
3160
  remediation.pending_action_delivered_at,
3122
3161
  remediation.patch_path, remediation.patch_digest, remediation.summary,
@@ -3286,22 +3325,18 @@ def read_json_object(path: Path) -> dict[str, Any]:
3286
3325
  return payload
3287
3326
 
3288
3327
 
3289
- _WORKBENCH_PUBLICATION_CONTEXT = SimpleNamespace(**globals())
3290
-
3328
+ _WORKBENCH_PUBLICATION_CONTEXT = _WORKBENCH_DB_CONTEXT = SimpleNamespace(**globals())
3291
3329
 
3292
- _WORKBENCH_DB_CONTEXT = SimpleNamespace(**globals())
3293
3330
 
3294
-
3295
- def main() -> None:
3331
+ def main(*, before_archive: Callable[[], None] | None = None) -> None:
3296
3332
  # Workbench callers send UTF-8 even when Windows uses a legacy code page.
3297
3333
  sys.stdin.reconfigure(encoding="utf-8")
3298
3334
  args = parse_args(__doc__)
3299
- deep_scan.configure(
3300
- SimpleNamespace(
3301
- **globals(),
3302
- preserve_stopped_results=preserve_stopped_results_after_transition,
3303
- )
3335
+ command_context = SimpleNamespace(
3336
+ **globals(),
3337
+ preserve_stopped_results=preserve_stopped_results_after_transition,
3304
3338
  )
3339
+ deep_scan.configure(command_context)
3305
3340
  if args.command == "resolve-scan-root":
3306
3341
  print(json.dumps({"scanRoot": str(resolve_scan_root(args.scan_root))}))
3307
3342
  return
@@ -3324,58 +3359,95 @@ def main() -> None:
3324
3359
  if args.command in {"save-artifact", "read-artifact"}:
3325
3360
  print(json.dumps(saved_results.read_or_save_artifact(args)))
3326
3361
  return
3327
- if args.command == "read-severity-classification":
3328
- result = severity.read_classification(database_path(), args.scan_id)
3329
- print(json.dumps(result, allow_nan=False, sort_keys=True))
3330
- return
3331
3362
  if args.command == "inspect-linear-publication":
3332
- result = publication.inspect_linear_publication(_WORKBENCH_PUBLICATION_CONTEXT, args)
3363
+ result = publication.inspect_linear_publication(
3364
+ _WORKBENCH_PUBLICATION_CONTEXT, read_json_object(Path(args.input_file))
3365
+ )
3333
3366
  print(json.dumps(result, allow_nan=False, sort_keys=True))
3334
3367
  return
3335
3368
  with closing(
3336
3369
  connect(deferred=args.command in {"get-scan", "list-scans", "database-info"})
3337
3370
  ) as connection:
3338
- remediation.require_available(connection, args, require_scan)
3339
- if args.command == "create-workspace":
3340
- result = create_workspace(connection, args)
3371
+ remediation_state.require_available(connection, args, require_scan)
3372
+ handlers = {
3373
+ "create-workspace": create_workspace,
3374
+ "save-workspace": save_workspace,
3375
+ "start-scan": start_scan,
3376
+ "begin-deep-scan": deep_scan.begin_deep_scan,
3377
+ "get-deep-scan": deep_scan.get_deep_scan,
3378
+ "claim-deep-scan-coordinator": deep_scan.claim_deep_scan_coordinator,
3379
+ "upsert-deep-scan-worker": deep_scan.upsert_deep_scan_worker,
3380
+ "claim-deep-scan-dedup": deep_scan.claim_deep_scan_dedup,
3381
+ "commit-deep-scan-dedup": deep_scan.commit_deep_scan_dedup,
3382
+ "finish-deep-scan": deep_scan.finish_deep_scan,
3383
+ "fail-deep-scan": deep_scan.fail_deep_scan,
3384
+ "record-deep-scan-publication-failure": deep_scan.record_deep_scan_publication_failure,
3385
+ "list-scans": scan_history.list_scans,
3386
+ "register-cli-scan": partial(register_cli_scan, before_archive=before_archive),
3387
+ "set-scan-thread": set_scan_thread,
3388
+ "set-scan-cost-limit": set_scan_cost_limit,
3389
+ "list-global-findings": native_indexes.list_global_findings,
3390
+ "list-repositories": native_indexes.list_repositories,
3391
+ "list-findings": list_findings,
3392
+ "complete-budget-exhausted-scan": complete_budget_exhausted_scan,
3393
+ "set-finding-triage": set_finding_triage,
3394
+ "request-finding-remediation": request_finding_remediation,
3395
+ "request-finding-remediation-action": request_finding_remediation_action,
3396
+ "claim-finding-remediation-resend": claim_finding_remediation_resend,
3397
+ "mark-finding-remediation-delivered": mark_finding_remediation_delivered,
3398
+ "release-finding-remediation-claim": release_finding_remediation_claim,
3399
+ "set-finding-remediation": set_finding_remediation,
3400
+ "update-progress": partial(progress.update_progress, command_context),
3401
+ "update-scan-context": partial(progress.update_context, command_context),
3402
+ "cancel-scan": partial(saved_results.cancel_scan, _WORKBENCH_DB_CONTEXT),
3403
+ "fail-scan": partial(saved_results.fail_scan, _WORKBENCH_DB_CONTEXT),
3404
+ "preserve-scan-results": partial(
3405
+ saved_results.preserve_scan_results, _WORKBENCH_DB_CONTEXT
3406
+ ),
3407
+ "recover-scan-results": partial(
3408
+ saved_results.recover_scan_results, _WORKBENCH_DB_CONTEXT
3409
+ ),
3410
+ "write-scan-draft": partial(saved_results.write_scan_draft, _WORKBENCH_DB_CONTEXT),
3411
+ "save-scan-artifact": partial(saved_results.save_scan_artifact, _WORKBENCH_DB_CONTEXT),
3412
+ "mark-handoff-delivered": partial(handoff.mark_handoff_delivered, command_context),
3413
+ "claim-handoff-delivery": partial(handoff.claim_handoff_delivery, command_context),
3414
+ "release-handoff-delivery": partial(handoff.release_handoff_delivery, command_context),
3415
+ "attach-scan-continuation-thread": partial(
3416
+ handoff.attach_scan_continuation_thread, command_context
3417
+ ),
3418
+ "prepare-linear-publication": partial(
3419
+ publication.prepare_linear_publication, _WORKBENCH_PUBLICATION_CONTEXT
3420
+ ),
3421
+ "record-linear-publications": partial(
3422
+ publication.record_linear_publications, _WORKBENCH_PUBLICATION_CONTEXT
3423
+ ),
3424
+ "export-findings": partial(publication.export_findings, _WORKBENCH_PUBLICATION_CONTEXT),
3425
+ }
3426
+ if handler := handlers.get(args.command):
3427
+ payload = (
3428
+ read_json_object(Path(args.input_file))
3429
+ if args.command in {"prepare-linear-publication", "record-linear-publications"}
3430
+ else args
3431
+ )
3432
+ result = handler(connection, payload)
3341
3433
  elif args.command == "get-workspace":
3342
3434
  result = workspace_state(
3343
3435
  connection,
3344
3436
  args.workspace_id,
3345
3437
  thread_id=args.thread_id,
3346
3438
  )
3347
- elif args.command == "save-workspace":
3348
- result = save_workspace(connection, args)
3349
- elif args.command == "start-scan":
3350
- result = start_scan(connection, args)
3351
3439
  elif args.command == "start-prompt-only-scan":
3352
3440
  result = _start_prompt_driven_scan(connection, args, headless_standard=False)
3353
3441
  elif args.command == "start-headless-standard-scan":
3354
3442
  result = _start_prompt_driven_scan(connection, args, headless_standard=True)
3355
- elif args.command == "begin-deep-scan":
3356
- result = deep_scan.begin_deep_scan(connection, args)
3357
- elif args.command == "get-deep-scan":
3358
- result = deep_scan.get_deep_scan(connection, args)
3359
- elif args.command == "claim-deep-scan-coordinator":
3360
- result = deep_scan.claim_deep_scan_coordinator(connection, args)
3361
- elif args.command == "upsert-deep-scan-worker":
3362
- result = deep_scan.upsert_deep_scan_worker(connection, args)
3363
- elif args.command == "claim-deep-scan-dedup":
3364
- result = deep_scan.claim_deep_scan_dedup(connection, args)
3365
- elif args.command == "commit-deep-scan-dedup":
3366
- result = deep_scan.commit_deep_scan_dedup(connection, args)
3367
- elif args.command == "finish-deep-scan":
3368
- result = deep_scan.finish_deep_scan(connection, args)
3369
- elif args.command == "fail-deep-scan":
3370
- result = deep_scan.fail_deep_scan(connection, args)
3371
- elif args.command == "record-deep-scan-publication-failure":
3372
- result = deep_scan.record_deep_scan_publication_failure(connection, args)
3373
3443
  elif args.command == "get-scan":
3374
3444
  result = scan_context(connection, args.scan_id, args.occurrence_id)
3445
+ elif args.command == "rename-scan":
3446
+ result = scan_history.rename_scan(
3447
+ connection, require_scan(connection, args.scan_id), args.name
3448
+ )
3375
3449
  elif args.command == "get-scan-feedback":
3376
3450
  result = get_scan_feedback(connection, require_scan(connection, args.scan_id))
3377
- elif args.command == "list-scans":
3378
- result = scan_history.list_scans(connection, args)
3379
3451
  elif args.command == "list-unmatched-scan-pairs":
3380
3452
  result = scan_history.list_unmatched_scan_pairs(
3381
3453
  connection,
@@ -3383,27 +3455,16 @@ def main() -> None:
3383
3455
  backfill_finding_details=backfill_legacy_finding_details,
3384
3456
  read_coverage=coverage_for_comparison,
3385
3457
  )
3386
- elif args.command == "register-cli-scan":
3387
- result = register_cli_scan(connection, args)
3388
- elif args.command == "set-scan-thread":
3389
- result = set_scan_thread(connection, args)
3390
- elif args.command == "set-scan-cost-limit":
3391
- result = set_scan_cost_limit(connection, args)
3392
3458
  elif args.command == "get-scan-recipe":
3393
3459
  result = scan_history.scan_recipe(require_scan(connection, args.scan_id))
3394
3460
  elif args.command == "get-cli-scan-resume":
3395
3461
  scan = require_scan(connection, args.scan_id)
3396
3462
  try:
3397
3463
  result = scan_history.cli_scan_resume(
3464
+ command_context,
3398
3465
  connection,
3399
3466
  scan,
3400
3467
  require_workspace(connection, scan["workspace_id"]),
3401
- parse_scan_recipe=parse_scan_recipe,
3402
- scan_contract=scan_contract,
3403
- require_scan_directory=require_canonical_scan_directory,
3404
- artifact_path=artifact_path,
3405
- read_json_object=read_json_object,
3406
- workbench_completion_binding=workbench_completion_binding,
3407
3468
  )
3408
3469
  except SystemExit as exc:
3409
3470
  if not args.allow_unavailable:
@@ -3427,118 +3488,21 @@ def main() -> None:
3427
3488
  require_scan=require_scan,
3428
3489
  read_coverage=coverage_for_comparison,
3429
3490
  )
3430
- elif args.command == "list-global-findings":
3431
- result = native_indexes.list_global_findings(connection, args)
3432
- elif args.command == "list-repositories":
3433
- result = native_indexes.list_repositories(connection, args)
3434
- elif args.command == "list-findings":
3435
- result = list_findings(connection, args)
3436
- elif args.command in {"update-progress", "update-scan-context"}:
3437
- result = progress.update(
3438
- connection, args, now, require_scan, require_workspace, scan_context
3439
- )
3440
3491
  elif args.command in {"prepare-scan-completion", "complete-scan"}:
3441
3492
  result = complete_scan(
3442
3493
  connection, args, prepare_only=args.command == "prepare-scan-completion"
3443
3494
  )
3444
- elif args.command == "complete-budget-exhausted-scan":
3445
- result = complete_budget_exhausted_scan(connection, args)
3446
- elif args.command == "cancel-scan":
3447
- result = saved_results.cancel_scan(_WORKBENCH_DB_CONTEXT, connection, args)
3448
- elif args.command == "fail-scan":
3449
- result = fail_scan(connection, args)
3450
- elif args.command == "preserve-scan-results":
3451
- result = saved_results.preserve_scan_results(_WORKBENCH_DB_CONTEXT, connection, args)
3452
- elif args.command == "recover-scan-results":
3453
- result = recover_scan_results(connection, args)
3454
- elif args.command == "write-scan-draft":
3455
- result = saved_results.write_scan_draft(_WORKBENCH_DB_CONTEXT, connection, args)
3456
- elif args.command == "save-scan-artifact":
3457
- result = saved_results.save_scan_artifact(_WORKBENCH_DB_CONTEXT, connection, args)
3458
- elif args.command == "mark-handoff-delivered":
3459
- result = handoff.mark_handoff_delivered(
3460
- connection,
3461
- args,
3462
- now=now,
3463
- require_scan=require_scan,
3464
- require_workspace=require_workspace,
3465
- workspace_state=workspace_state,
3466
- )
3467
- elif args.command == "claim-handoff-delivery":
3468
- result = handoff.claim_handoff_delivery(
3469
- connection,
3470
- args,
3471
- now=now,
3472
- require_scan=require_scan,
3473
- stale_claim_before=stale_claim_before,
3474
- workspace_state=workspace_state,
3475
- )
3476
- elif args.command == "release-handoff-delivery":
3477
- result = handoff.release_handoff_delivery(
3478
- connection,
3479
- args,
3480
- now=now,
3481
- require_scan=require_scan,
3482
- workspace_state=workspace_state,
3483
- )
3484
- elif args.command == "attach-scan-continuation-thread":
3485
- result = handoff.attach_scan_continuation_thread(
3486
- connection,
3487
- args,
3488
- now=now,
3489
- require_scan=require_scan,
3490
- workspace_state=workspace_state,
3491
- )
3492
- elif args.command == "set-finding-triage":
3493
- result = set_finding_triage(connection, args)
3494
- elif args.command == "request-finding-remediation":
3495
- result = request_finding_remediation(connection, args)
3496
- elif args.command == "request-finding-remediation-action":
3497
- result = request_finding_remediation_action(connection, args)
3498
- elif args.command == "claim-finding-remediation-resend":
3499
- result = claim_finding_remediation_resend(connection, args)
3500
- elif args.command == "mark-finding-remediation-delivered":
3501
- result = mark_finding_remediation_delivered(connection, args)
3502
- elif args.command == "release-finding-remediation-claim":
3503
- result = release_finding_remediation_claim(connection, args)
3504
3495
  elif args.command == "cancel-finding-remediation-request":
3505
3496
  result = scan_context(
3506
3497
  connection,
3507
- remediation.cancel_finding_remediation_request(connection, args),
3508
- )
3509
- elif args.command == "set-finding-remediation":
3510
- result = set_finding_remediation(connection, args)
3511
- elif args.command == "prepare-linear-publication":
3512
- result = publication.prepare_linear_publication(
3513
- _WORKBENCH_PUBLICATION_CONTEXT, connection, args
3498
+ remediation_state.cancel_finding_remediation_request(connection, args),
3514
3499
  )
3515
- elif args.command == "record-linear-publications":
3516
- result = publication.record_linear_publications(
3517
- _WORKBENCH_PUBLICATION_CONTEXT, connection, args
3518
- )
3519
- elif args.command == "export-findings":
3520
- result = export_findings(connection, args)
3521
3500
  elif args.command == "database-info":
3522
3501
  result = {"databasePath": str(database_path())}
3523
- elif args.command == "severity-classification":
3524
- result = severity.checkpoint(connection, json.load(sys.stdin), now())
3502
+ elif args.command == "local-dedupe":
3503
+ result = local_dedupe(connection, json.load(sys.stdin), now())
3525
3504
  elif args.command == "finding-workflow":
3526
3505
  result = finding_workflow(connection, json.load(sys.stdin), now())
3527
- elif args.command == "dashboard":
3528
- result = dashboard(connection, json.load(sys.stdin))
3529
- elif args.command == "store-findings":
3530
- payload = json.load(sys.stdin)
3531
- result = store_findings(
3532
- connection, payload["entries"], now(), payload.get("repositoryId")
3533
- )
3534
- elif args.command == "find-potential-duplicates":
3535
- result = find_potential_duplicates(connection, args.finding_id, args.repository_id)
3536
- elif args.command == "store-dedupe-groups":
3537
- result = store_dedupe_groups(connection, json.load(sys.stdin)["groups"], now())
3538
- elif args.command == "list-dedupe-groups":
3539
- result = list_dedupe_groups(connection, args.finding_id)
3540
- elif args.command == "list-stored-findings":
3541
- result = list_stored_findings(connection, limit=args.limit, offset=args.offset)
3542
3506
  else:
3543
3507
  raise SystemExit(f"Unknown command: {args.command}")
3544
3508
  print(json.dumps(result, allow_nan=False, sort_keys=True))