@openai/codex-security 0.6.0 → 0.8.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 (308) hide show
  1. package/README.md +76 -39
  2. package/_bundled_plugin/.mcp.json +1 -0
  3. package/_bundled_plugin/examples/completed-scan/findings.json +34 -34
  4. package/_bundled_plugin/examples/completed-scan/report.md +22 -31
  5. package/_bundled_plugin/examples/completed-scan/scan-manifest.json +27 -29
  6. package/_bundled_plugin/examples/{completed-scan → legacy-completed-scan}/coverage.json +1 -0
  7. package/_bundled_plugin/examples/legacy-completed-scan/findings.json +57 -0
  8. package/_bundled_plugin/examples/legacy-completed-scan/report.md +98 -0
  9. package/_bundled_plugin/examples/legacy-completed-scan/scan-manifest.json +43 -0
  10. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  11. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  12. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +1 -1
  13. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  14. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  15. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  16. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  17. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  18. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  19. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  20. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  21. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  22. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  23. package/_bundled_plugin/references/access-advisory.md +11 -0
  24. package/_bundled_plugin/references/core-scan.md +30 -77
  25. package/_bundled_plugin/references/final-report.md +50 -184
  26. package/_bundled_plugin/references/scan-artifacts.md +5 -5
  27. package/_bundled_plugin/references/scan-contract.md +12 -12
  28. package/_bundled_plugin/references/scan-prologue.md +1 -1
  29. package/_bundled_plugin/references/scan-runtime.md +1 -5
  30. package/_bundled_plugin/references/threat-model.md +33 -41
  31. package/_bundled_plugin/schemas/coverage.schema.json +12 -1
  32. package/_bundled_plugin/schemas/scan-manifest.schema.json +37 -11
  33. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +38 -1
  34. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +5 -5
  35. package/_bundled_plugin/scripts/deep_scan_config.py +39 -39
  36. package/_bundled_plugin/scripts/deep_scan_workbench.py +146 -86
  37. package/_bundled_plugin/scripts/finalize_scan_contract.py +249 -76
  38. package/_bundled_plugin/scripts/report_projection.py +49 -17
  39. package/_bundled_plugin/scripts/review_state.py +68 -0
  40. package/_bundled_plugin/scripts/threat_model_projection.py +4 -2
  41. package/_bundled_plugin/scripts/validate_scan_contract.py +1 -2
  42. package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -14
  43. package/_bundled_plugin/scripts/workbench/retained_coverage.py +3230 -0
  44. package/_bundled_plugin/scripts/workbench/retained_records.py +627 -0
  45. package/_bundled_plugin/scripts/workbench/saved_coverage.py +651 -8
  46. package/_bundled_plugin/scripts/workbench/saved_outputs.py +72 -0
  47. package/_bundled_plugin/scripts/workbench/saved_sources.py +730 -0
  48. package/_bundled_plugin/scripts/workbench_cli.py +3 -0
  49. package/_bundled_plugin/scripts/workbench_constants.py +0 -1
  50. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +479 -0
  51. package/_bundled_plugin/scripts/workbench_db.py +55 -171
  52. package/_bundled_plugin/scripts/workbench_feedback.py +0 -1
  53. package/_bundled_plugin/scripts/workbench_finding_workflows.py +51 -9
  54. package/_bundled_plugin/scripts/workbench_native_indexes.py +56 -44
  55. package/_bundled_plugin/scripts/workbench_saved_results.py +808 -2389
  56. package/_bundled_plugin/scripts/workbench_scan_history.py +77 -7
  57. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  58. package/_bundled_plugin/scripts/workbench_source_scopes.py +4 -1
  59. package/_bundled_plugin/scripts/workbench_target.py +142 -17
  60. package/_bundled_plugin/scripts/workbench_validation.py +9 -2
  61. package/_bundled_plugin/shared/workbench-history-repairs.json +21 -0
  62. package/_bundled_plugin/shared/workbench-migrations.json +28 -0
  63. package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +3 -14
  64. package/_bundled_plugin/skills/assess-patch-risk/references/windows-validation.md +14 -0
  65. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +38 -103
  66. package/_bundled_plugin/skills/attack-path-analysis/references/attack-path-facts.md +11 -73
  67. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +57 -116
  68. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +28 -51
  69. package/_bundled_plugin/skills/define-security-policy/SKILL.md +9 -9
  70. package/_bundled_plugin/skills/finding-discovery/SKILL.md +26 -140
  71. package/_bundled_plugin/skills/fix-finding/SKILL.md +9 -28
  72. package/_bundled_plugin/skills/propose-security-hardening/SKILL.md +28 -218
  73. package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +29 -424
  74. package/_bundled_plugin/skills/publish-findings/SKILL.md +32 -24
  75. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +64 -0
  76. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +12 -12
  77. package/_bundled_plugin/skills/security-scan/SKILL.md +29 -17
  78. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +11 -17
  79. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +52 -69
  80. package/_bundled_plugin/skills/threat-model/SKILL.md +16 -9
  81. package/_bundled_plugin/skills/track-findings/SKILL.md +1 -1
  82. package/_bundled_plugin/skills/triage-finding/SKILL.md +5 -15
  83. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -6
  84. package/_bundled_plugin/skills/validation/SKILL.md +42 -104
  85. package/_bundled_plugin/skills/validation/references/validation-guidance.md +21 -106
  86. package/_bundled_plugin/skills/verify-fix/SKILL.md +4 -2
  87. package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +21 -159
  88. package/_bundled_plugin/skills/vulnerability-writeup/references/report-format.md +18 -60
  89. package/dist/api.d.ts +5 -3
  90. package/dist/api.d.ts.map +1 -1
  91. package/dist/api.js +359 -53
  92. package/dist/api.js.map +1 -1
  93. package/dist/auth.d.ts.map +1 -1
  94. package/dist/auth.js +4 -1
  95. package/dist/auth.js.map +1 -1
  96. package/dist/cli.d.ts +2 -2
  97. package/dist/cli.d.ts.map +1 -1
  98. package/dist/cli.js +696 -430
  99. package/dist/cli.js.map +1 -1
  100. package/dist/cloud-publish.d.ts.map +1 -1
  101. package/dist/cloud-publish.js +2 -23
  102. package/dist/cloud-publish.js.map +1 -1
  103. package/dist/component-scan.d.ts +8 -2
  104. package/dist/component-scan.d.ts.map +1 -1
  105. package/dist/component-scan.js +2 -0
  106. package/dist/component-scan.js.map +1 -1
  107. package/dist/contract.d.ts +5 -2
  108. package/dist/contract.d.ts.map +1 -1
  109. package/dist/contract.js +93 -45
  110. package/dist/contract.js.map +1 -1
  111. package/dist/cost.d.ts +18 -0
  112. package/dist/cost.d.ts.map +1 -1
  113. package/dist/cost.js +107 -12
  114. package/dist/cost.js.map +1 -1
  115. package/dist/coverage-presentation.d.ts +6 -0
  116. package/dist/coverage-presentation.d.ts.map +1 -0
  117. package/dist/coverage-presentation.js +34 -0
  118. package/dist/coverage-presentation.js.map +1 -0
  119. package/dist/custom-publish.js +2 -2
  120. package/dist/custom-publish.js.map +1 -1
  121. package/dist/custom-validation-prompt.js +5 -5
  122. package/dist/custom-validation-prompt.js.map +1 -1
  123. package/dist/custom-validation.d.ts.map +1 -1
  124. package/dist/custom-validation.js +47 -19
  125. package/dist/custom-validation.js.map +1 -1
  126. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  127. package/dist/deduplication/checkpointed-review.js +3 -1
  128. package/dist/deduplication/checkpointed-review.js.map +1 -1
  129. package/dist/deduplication/codex-review.d.ts.map +1 -1
  130. package/dist/deduplication/codex-review.js +2 -2
  131. package/dist/deduplication/codex-review.js.map +1 -1
  132. package/dist/deduplication/deduplication-prompts.d.ts +1 -0
  133. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  134. package/dist/deduplication/deduplication-prompts.js +3 -0
  135. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  136. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  137. package/dist/deduplication/records-protocol.js +21 -1
  138. package/dist/deduplication/records-protocol.js.map +1 -1
  139. package/dist/deduplication/scan.d.ts.map +1 -1
  140. package/dist/deduplication/scan.js +9 -7
  141. package/dist/deduplication/scan.js.map +1 -1
  142. package/dist/endor-findings.d.ts +4 -3
  143. package/dist/endor-findings.d.ts.map +1 -1
  144. package/dist/endor-findings.js +16 -11
  145. package/dist/endor-findings.js.map +1 -1
  146. package/dist/external-findings-import.d.ts.map +1 -1
  147. package/dist/external-findings-import.js +13 -5
  148. package/dist/external-findings-import.js.map +1 -1
  149. package/dist/external-findings-local.d.ts +1 -0
  150. package/dist/external-findings-local.d.ts.map +1 -1
  151. package/dist/external-findings-local.js +14 -3
  152. package/dist/external-findings-local.js.map +1 -1
  153. package/dist/external-findings-publish.d.ts +2 -1
  154. package/dist/external-findings-publish.d.ts.map +1 -1
  155. package/dist/external-findings-publish.js +64 -28
  156. package/dist/external-findings-publish.js.map +1 -1
  157. package/dist/external-findings-read.d.ts +12 -1
  158. package/dist/external-findings-read.d.ts.map +1 -1
  159. package/dist/external-findings-read.js +25 -6
  160. package/dist/external-findings-read.js.map +1 -1
  161. package/dist/external-findings.d.ts +2 -0
  162. package/dist/external-findings.d.ts.map +1 -1
  163. package/dist/external-findings.js.map +1 -1
  164. package/dist/external-import-contract.d.ts +7 -1
  165. package/dist/external-import-contract.d.ts.map +1 -1
  166. package/dist/external-import-contract.js +63 -31
  167. package/dist/external-import-contract.js.map +1 -1
  168. package/dist/external-imports-feature.d.ts +6 -0
  169. package/dist/external-imports-feature.d.ts.map +1 -0
  170. package/dist/external-imports-feature.js +51 -0
  171. package/dist/external-imports-feature.js.map +1 -0
  172. package/dist/finding-workflow.d.ts +24 -5
  173. package/dist/finding-workflow.d.ts.map +1 -1
  174. package/dist/finding-workflow.js +24 -9
  175. package/dist/finding-workflow.js.map +1 -1
  176. package/dist/github-advisories.d.ts.map +1 -1
  177. package/dist/github-advisories.js +3 -1
  178. package/dist/github-advisories.js.map +1 -1
  179. package/dist/github-findings.d.ts +4 -3
  180. package/dist/github-findings.d.ts.map +1 -1
  181. package/dist/github-findings.js +16 -14
  182. package/dist/github-findings.js.map +1 -1
  183. package/dist/host-protocol.d.ts +1 -1
  184. package/dist/host-protocol.d.ts.map +1 -1
  185. package/dist/host-protocol.js +2 -2
  186. package/dist/host-protocol.js.map +1 -1
  187. package/dist/hosted-remediation.d.ts.map +1 -1
  188. package/dist/hosted-remediation.js +19 -2
  189. package/dist/hosted-remediation.js.map +1 -1
  190. package/dist/hosted-scan.d.ts +1 -1
  191. package/dist/hosted-scan.d.ts.map +1 -1
  192. package/dist/hosted-scan.js +0 -6
  193. package/dist/hosted-scan.js.map +1 -1
  194. package/dist/import-scan.js +17 -17
  195. package/dist/import-scan.js.map +1 -1
  196. package/dist/index.d.ts +4 -3
  197. package/dist/index.d.ts.map +1 -1
  198. package/dist/index.js +2 -1
  199. package/dist/index.js.map +1 -1
  200. package/dist/knowledge-base.d.ts +1 -0
  201. package/dist/knowledge-base.d.ts.map +1 -1
  202. package/dist/knowledge-base.js +20 -8
  203. package/dist/knowledge-base.js.map +1 -1
  204. package/dist/mock-scan.d.ts +1 -2
  205. package/dist/mock-scan.d.ts.map +1 -1
  206. package/dist/mock-scan.js +12 -17
  207. package/dist/mock-scan.js.map +1 -1
  208. package/dist/models.d.ts +10 -1
  209. package/dist/models.d.ts.map +1 -1
  210. package/dist/models.js.map +1 -1
  211. package/dist/multiscan.d.ts.map +1 -1
  212. package/dist/multiscan.js +1 -6
  213. package/dist/multiscan.js.map +1 -1
  214. package/dist/native-json-findings.d.ts +30 -0
  215. package/dist/native-json-findings.d.ts.map +1 -0
  216. package/dist/native-json-findings.js +114 -0
  217. package/dist/native-json-findings.js.map +1 -0
  218. package/dist/opengrep-findings.d.ts +10 -0
  219. package/dist/opengrep-findings.d.ts.map +1 -0
  220. package/dist/opengrep-findings.js +198 -0
  221. package/dist/opengrep-findings.js.map +1 -0
  222. package/dist/owner-evidence.d.ts +2 -0
  223. package/dist/owner-evidence.d.ts.map +1 -1
  224. package/dist/owner-evidence.js +2 -1
  225. package/dist/owner-evidence.js.map +1 -1
  226. package/dist/patch-tui.d.ts.map +1 -1
  227. package/dist/patch-tui.js +2 -0
  228. package/dist/patch-tui.js.map +1 -1
  229. package/dist/publication.js +1 -2
  230. package/dist/publication.js.map +1 -1
  231. package/dist/publish.d.ts +2 -0
  232. package/dist/publish.d.ts.map +1 -1
  233. package/dist/publish.js +1 -1
  234. package/dist/publish.js.map +1 -1
  235. package/dist/record.d.ts +1 -0
  236. package/dist/record.d.ts.map +1 -1
  237. package/dist/record.js +10 -0
  238. package/dist/record.js.map +1 -1
  239. package/dist/remediation.d.ts +1 -25
  240. package/dist/remediation.d.ts.map +1 -1
  241. package/dist/remediation.js +3 -24
  242. package/dist/remediation.js.map +1 -1
  243. package/dist/result.d.ts +5 -3
  244. package/dist/result.d.ts.map +1 -1
  245. package/dist/result.js +9 -6
  246. package/dist/result.js.map +1 -1
  247. package/dist/runtime.d.ts.map +1 -1
  248. package/dist/runtime.js +7 -7
  249. package/dist/runtime.js.map +1 -1
  250. package/dist/scan-dashboard.d.ts +5 -3
  251. package/dist/scan-dashboard.d.ts.map +1 -1
  252. package/dist/scan-dashboard.js +79 -26
  253. package/dist/scan-dashboard.js.map +1 -1
  254. package/dist/scan-history-renderer.d.ts.map +1 -1
  255. package/dist/scan-history-renderer.js +9 -3
  256. package/dist/scan-history-renderer.js.map +1 -1
  257. package/dist/scan-owner-suggestions.d.ts +1 -1
  258. package/dist/scan-owner-suggestions.d.ts.map +1 -1
  259. package/dist/scan-owner-suggestions.js +4 -4
  260. package/dist/scan-owner-suggestions.js.map +1 -1
  261. package/dist/scan-usage-display.d.ts +8 -0
  262. package/dist/scan-usage-display.d.ts.map +1 -0
  263. package/dist/scan-usage-display.js +46 -0
  264. package/dist/scan-usage-display.js.map +1 -0
  265. package/dist/scanner-import.d.ts +1 -1
  266. package/dist/scanner-import.d.ts.map +1 -1
  267. package/dist/scanner-import.js +7 -3
  268. package/dist/scanner-import.js.map +1 -1
  269. package/dist/security-policy.d.ts.map +1 -1
  270. package/dist/security-policy.js +17 -22
  271. package/dist/security-policy.js.map +1 -1
  272. package/dist/semgrep-findings.d.ts +4 -3
  273. package/dist/semgrep-findings.d.ts.map +1 -1
  274. package/dist/semgrep-findings.js +22 -89
  275. package/dist/semgrep-findings.js.map +1 -1
  276. package/dist/skill-authentication.d.ts +18 -0
  277. package/dist/skill-authentication.d.ts.map +1 -0
  278. package/dist/skill-authentication.js +82 -0
  279. package/dist/skill-authentication.js.map +1 -0
  280. package/dist/snyk-findings.d.ts +5 -4
  281. package/dist/snyk-findings.d.ts.map +1 -1
  282. package/dist/snyk-findings.js +18 -17
  283. package/dist/snyk-findings.js.map +1 -1
  284. package/dist/suggest-owners.d.ts +4 -1
  285. package/dist/suggest-owners.d.ts.map +1 -1
  286. package/dist/suggest-owners.js +53 -21
  287. package/dist/suggest-owners.js.map +1 -1
  288. package/dist/targets.d.ts.map +1 -1
  289. package/dist/targets.js +4 -1
  290. package/dist/targets.js.map +1 -1
  291. package/dist/wiz-csv.d.ts +2 -1
  292. package/dist/wiz-csv.d.ts.map +1 -1
  293. package/dist/wiz-csv.js +3 -3
  294. package/dist/wiz-csv.js.map +1 -1
  295. package/dist/wiz-findings.d.ts +2 -1
  296. package/dist/wiz-findings.d.ts.map +1 -1
  297. package/dist/wiz-findings.js +27 -23
  298. package/dist/wiz-findings.js.map +1 -1
  299. package/docs/classify-severity-records.md +3 -4
  300. package/docs/cli.md +171 -41
  301. package/docs/dedupe-records.md +15 -1
  302. package/docs/findings-service.md +119 -118
  303. package/docs/hosted-remediation.md +19 -17
  304. package/docs/hosted-scans.md +37 -11
  305. package/package.json +9 -9
  306. package/_bundled_plugin/scripts/generate_in_scope_files.py +0 -277
  307. package/_bundled_plugin/scripts/generate_rank_input.py +0 -350
  308. package/_bundled_plugin/scripts/rank_preview.py +0 -129
@@ -43,6 +43,7 @@ import workbench_remediation as remediation_state
43
43
  import workbench_saved_results as saved_results
44
44
  import workbench_scan_history as scan_history
45
45
  import workbench_scan_usage as scan_usage
46
+ from deep_scan_config import resolve_deep_scan_setup
46
47
  from finalize_scan_contract import (
47
48
  PRODUCER_NAME,
48
49
  ContractError,
@@ -50,9 +51,8 @@ from finalize_scan_contract import (
50
51
  _prepare_scan_finalization,
51
52
  _write_prepared_scan_finalization,
52
53
  finalize_scan,
53
- finding_candidate_id,
54
+ manifest_is_sealed,
54
55
  open_scan_local_file_descriptor,
55
- write_scan_local_bytes,
56
56
  )
57
57
  from finding_preview import bounded_finding_details
58
58
  from workbench import handoff
@@ -122,6 +122,7 @@ from workbench_target import (
122
122
  require_git_worktree_head,
123
123
  require_remediation_target,
124
124
  require_scan_target_identity,
125
+ require_scan_target_unchanged,
125
126
  restore_directory_junctions,
126
127
  scan_target_warning,
127
128
  worktree_content_digest,
@@ -739,10 +740,7 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
739
740
  return workspace_state(connection, workspace_id)
740
741
 
741
742
 
742
- def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
743
- workspace = require_workspace(connection, args.workspace_id)
744
- if workspace["active_scan_id"]:
745
- raise SystemExit("This workspace already has a scan. Open a new workspace to change setup.")
743
+ def inspect_selected_setup(args: argparse.Namespace) -> dict[str, Any]:
746
744
  inspected = inspect_setup_values(
747
745
  args.target_path,
748
746
  args.scope,
@@ -752,6 +750,20 @@ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) ->
752
750
  args.diff_head_revision,
753
751
  args.diff_content_digest,
754
752
  )
753
+ if args.mode == "deep":
754
+ inspected["deepScanConfig"] = resolve_deep_scan_setup(
755
+ os.cpu_count() or 1, args.deep_scan_project_json
756
+ )
757
+ elif args.deep_scan_project_json is not None:
758
+ raise SystemExit("Project Deep Scan settings require Deep Scan mode.")
759
+ return inspected
760
+
761
+
762
+ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
763
+ workspace = require_workspace(connection, args.workspace_id)
764
+ if workspace["active_scan_id"]:
765
+ raise SystemExit("This workspace already has a scan. Open a new workspace to change setup.")
766
+ inspected = inspect_selected_setup(args)
755
767
  target = Path(inspected["target"]["targetPath"])
756
768
  scope = inspected["scope"]
757
769
  target_path = str(target)
@@ -776,7 +788,7 @@ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) ->
776
788
  SET target_id = ?, target_path = ?, target_title = ?, target_summary = ?, default_scope = ?,
777
789
  default_mode = ?, user_context = ?, diff_target_kind = ?,
778
790
  diff_base_revision = ?, diff_head_revision = ?, diff_content_digest = ?,
779
- submitted = 1, updated_at = ?
791
+ deep_scan_config_json = ?, submitted = 1, updated_at = ?
780
792
  WHERE id = ? AND active_scan_id IS NULL
781
793
  """,
782
794
  (
@@ -788,6 +800,7 @@ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) ->
788
800
  args.mode,
789
801
  user_context_argument(args),
790
802
  *scan_diff_identity(diff_target or None),
803
+ json.dumps(inspected["deepScanConfig"]) if "deepScanConfig" in inspected else None,
791
804
  timestamp,
792
805
  workspace["id"],
793
806
  ),
@@ -1250,7 +1263,7 @@ def complete_budget_exhausted_scan(
1250
1263
  if run["manifest_path"] == str(scan_dir / "scan-manifest.json")
1251
1264
  else budget_exhausted_candidates(scan, scan_dir)
1252
1265
  )
1253
- warning = optional_text(args.message, maximum=2400)
1266
+ warning = optional_text(args.message)
1254
1267
  if warning is None:
1255
1268
  warning = (
1256
1269
  f"Deep Scan reached its cost limit after an estimated "
@@ -1340,151 +1353,9 @@ def budget_exhausted_candidates(scan: sqlite3.Row, scan_dir: Path) -> list[dict[
1340
1353
 
1341
1354
 
1342
1355
  def budget_exhausted_draft(
1343
- scan: sqlite3.Row,
1344
- scan_dir: Path,
1345
- candidates: list[dict[str, Any]],
1346
- warning: str,
1356
+ scan: sqlite3.Row, scan_dir: Path, candidates: list[dict[str, Any]], warning: str
1347
1357
  ) -> None:
1348
- documents: dict[str, dict[str, Any]] = {}
1349
- for name in ("scan-manifest.json", "findings.json", "coverage.json"):
1350
- path = artifact_path(scan_dir, name, required=False)
1351
- if path is not None:
1352
- documents[name] = read_json_object(path)
1353
- if documents and len(documents) != 3:
1354
- raise SystemExit("Budget-exhausted scan contains an incomplete canonical scan draft.")
1355
-
1356
- if documents:
1357
- manifest = documents["scan-manifest.json"]
1358
- findings = documents["findings.json"]
1359
- coverage = documents["coverage.json"]
1360
- if not isinstance(manifest.get("scan"), dict) or not isinstance(
1361
- findings.get("findings"), list
1362
- ):
1363
- raise SystemExit("Budget-exhausted scan contains an invalid canonical scan draft.")
1364
- for key in ("surfaces", "explicitExclusions", "deferred"):
1365
- if not isinstance(coverage.get(key), list):
1366
- raise SystemExit("Budget-exhausted scan contains invalid canonical coverage.")
1367
- if manifest["scan"].get("sealedAt") is not None or manifest["scan"].get("artifacts"):
1368
- raise SystemExit("Budget-exhausted scan cannot replace an already sealed scan draft.")
1369
- else:
1370
- contract = scan_contract(scan)
1371
- target_contract = contract["target"]
1372
- target: dict[str, Any] = {
1373
- "kind": target_contract["allowedKinds"][0],
1374
- "targetId": target_contract["targetId"],
1375
- "displayName": target_contract["displayName"],
1376
- }
1377
- if scan["target_revision"] != "unversioned":
1378
- target["revision"] = scan["target_revision"]
1379
- if "requiredSnapshotDigest" in target_contract:
1380
- target["snapshotDigest"] = target_contract["requiredSnapshotDigest"]
1381
- manifest = {
1382
- "scan": {
1383
- "target": target,
1384
- "scope": {"limitations": [warning]},
1385
- }
1386
- }
1387
- findings = {"findings": []}
1388
- coverage = {
1389
- "inventoryStrategy": (
1390
- "scoped_path" if expected_coverage_mode(scan) == "scoped_path" else "repository"
1391
- ),
1392
- "surfaces": [],
1393
- "explicitExclusions": [],
1394
- "deferred": [],
1395
- }
1396
-
1397
- findings_by_candidate = {
1398
- candidate_id
1399
- for finding in findings["findings"]
1400
- if isinstance(finding, dict)
1401
- and isinstance(candidate_id := finding_candidate_id(finding), str)
1402
- }
1403
- existing_deferred = {
1404
- item.get("candidateId", item.get("id"))
1405
- for item in coverage["deferred"]
1406
- if isinstance(item, dict) and isinstance(item.get("candidateId", item.get("id")), str)
1407
- }
1408
- existing_surfaces = {
1409
- item.get("id")
1410
- for item in coverage["surfaces"]
1411
- if isinstance(item, dict) and isinstance(item.get("id"), str)
1412
- }
1413
- for candidate in candidates:
1414
- candidate_id = candidate["candidate_id"]
1415
- if candidate_id in findings_by_candidate or candidate_id in existing_deferred:
1416
- continue
1417
- paths = list(dict.fromkeys(location["path"] for location in candidate["locations"]))
1418
- surface_id = f"candidate-{candidate_id}"
1419
- validation = candidate.get("validation")
1420
- validation = validation.get("disposition") if isinstance(validation, dict) else None
1421
- attack = candidate.get("attack_path")
1422
- attack = attack.get("decision") if isinstance(attack, dict) else None
1423
- disposition = (
1424
- "needs_follow_up"
1425
- if validation == "deferred" or attack == "deferred"
1426
- else "not_applicable"
1427
- if validation == "not_applicable"
1428
- else "rejected"
1429
- if validation == "suppressed" or attack == "ignore"
1430
- else "needs_follow_up"
1431
- )
1432
- if surface_id not in existing_surfaces:
1433
- coverage["surfaces"].append(
1434
- {
1435
- "id": surface_id,
1436
- "label": candidate["summary"],
1437
- "disposition": disposition,
1438
- "notes": candidate["evidence"],
1439
- "receiptRefs": [],
1440
- }
1441
- )
1442
- existing_surfaces.add(surface_id)
1443
- if disposition != "needs_follow_up":
1444
- continue
1445
- coverage["deferred"].append(
1446
- {
1447
- "id": candidate_id,
1448
- "candidateId": candidate_id,
1449
- "reason": (
1450
- "Validation was deferred because the scan reached its cost limit: "
1451
- f"{candidate['summary']}. Evidence: {candidate['evidence']}"
1452
- ),
1453
- "paths": paths,
1454
- "surfaceIds": [surface_id],
1455
- }
1456
- )
1457
- if not any(
1458
- isinstance(item, dict)
1459
- and isinstance(reason := item.get("reason"), str)
1460
- and (
1461
- reason == "Validation was deferred because the scan reached its cost limit."
1462
- or reason.startswith(
1463
- "Validation was deferred because the scan reached its cost limit: "
1464
- )
1465
- )
1466
- for item in coverage["deferred"]
1467
- ):
1468
- coverage["deferred"].append(
1469
- {
1470
- "id": "scan-cost-limit",
1471
- "reason": "Validation was deferred because the scan reached its cost limit.",
1472
- }
1473
- )
1474
- coverage.pop("completeness", None)
1475
- for name, payload in (
1476
- ("findings.json", findings),
1477
- ("coverage.json", coverage),
1478
- ("scan-manifest.json", manifest),
1479
- ):
1480
- try:
1481
- write_scan_local_bytes(
1482
- scan_dir,
1483
- name,
1484
- (json.dumps(payload, allow_nan=False, indent=2, sort_keys=True) + "\n").encode(),
1485
- )
1486
- except (ContractError, OSError, TypeError, ValueError) as exc:
1487
- raise SystemExit(f"Budget-exhausted scan draft could not be saved: {exc}") from exc
1358
+ saved_results.budget_exhausted_draft(sys.modules[__name__], scan, scan_dir, candidates, warning)
1488
1359
 
1489
1360
 
1490
1361
  def complete_scan_locked(
@@ -1529,10 +1400,7 @@ def complete_scan_locked(
1529
1400
  already_sealed = (
1530
1401
  current_manifest_path is not None
1531
1402
  and isinstance(current_manifest.get("scan"), dict)
1532
- and (
1533
- current_manifest["scan"].get("sealedAt") is not None
1534
- or current_manifest["scan"].get("artifacts") is not None
1535
- )
1403
+ and manifest_is_sealed(current_manifest["scan"])
1536
1404
  )
1537
1405
  completion_binding = workbench_completion_binding(scan, completion_timestamp, current_manifest)
1538
1406
  if scan["recipe_json"] is not None:
@@ -1540,7 +1408,6 @@ def complete_scan_locked(
1540
1408
  for file_name in (
1541
1409
  ARTIFACTS["manifest"],
1542
1410
  ARTIFACTS["findings"],
1543
- ARTIFACTS["coverage"],
1544
1411
  ):
1545
1412
  try:
1546
1413
  (scan_dir / file_name).lstat()
@@ -1575,6 +1442,7 @@ def complete_scan_locked(
1575
1442
  ).fetchall(),
1576
1443
  warnings,
1577
1444
  stopped=False,
1445
+ scan_mode=scan["mode"],
1578
1446
  reason="",
1579
1447
  )
1580
1448
  if merge_parent_draft
@@ -1600,9 +1468,9 @@ def complete_scan_locked(
1600
1468
  )
1601
1469
  warnings.extend(warning for warning in prepared.warnings if warning not in warnings)
1602
1470
  add_warning()
1603
- if prepared.warnings:
1604
- # Save the explanation before publication removes the broken reference,
1605
- # so a retry after failed publication retains it.
1471
+ if warnings != json.loads(scan["completion_warnings_json"]):
1472
+ # Persist all observed warnings before output writes can fail, so
1473
+ # stopped-result publication and retries retain those diagnostics.
1606
1474
  with connection:
1607
1475
  connection.execute(
1608
1476
  "UPDATE scans SET completion_warnings_json = ? WHERE id = ? AND status = 'running'",
@@ -1978,6 +1846,12 @@ def parse_scan_recipe(value: str, repository: Path) -> dict[str, Any]:
1978
1846
  return recipe
1979
1847
 
1980
1848
 
1849
+ def coverage_summary_for_history(scan: sqlite3.Row) -> dict[str, Any]:
1850
+ return scan_history.coverage_summary_for_history(
1851
+ _WORKBENCH_DB_CONTEXT, scan, require_canonical_scan_directory
1852
+ )
1853
+
1854
+
1981
1855
  def coverage_for_comparison(scan: sqlite3.Row) -> dict[str, Any]:
1982
1856
  return saved_results.coverage_for_comparison(_WORKBENCH_DB_CONTEXT, scan)
1983
1857
 
@@ -2670,6 +2544,11 @@ def workspace_state(
2670
2544
  "mode": workspace["default_mode"],
2671
2545
  "scope": workspace["default_scope"],
2672
2546
  "setup": {"submitted": bool(workspace["submitted"])},
2547
+ **(
2548
+ {"deepScanConfig": json.loads(workspace["deep_scan_config_json"])}
2549
+ if workspace["deep_scan_config_json"] is not None
2550
+ else {}
2551
+ ),
2673
2552
  "setupValidation": {"error": None, "valid": bool(workspace["submitted"])},
2674
2553
  "targetPath": workspace["target_path"],
2675
2554
  "targetSummary": workspace["target_summary"],
@@ -2745,6 +2624,17 @@ def scan_context(
2745
2624
  return context
2746
2625
 
2747
2626
 
2627
+ def get_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
2628
+ result = scan_context(connection, args.scan_id, args.occurrence_id)
2629
+ if result["scan"]["progress"]["status"] != "running":
2630
+ scan = require_scan(connection, args.scan_id)
2631
+ try:
2632
+ result["scan"] = dict(result["scan"], coverage=coverage_summary_for_history(scan))
2633
+ except (OSError, RuntimeError, SystemExit):
2634
+ pass # Historical artifacts may no longer be available or verifiable.
2635
+ return result
2636
+
2637
+
2748
2638
  def list_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
2749
2639
  scan = require_scan(connection, args.scan_id)
2750
2640
  backfill_legacy_finding_details(connection, scan)
@@ -3421,16 +3311,7 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
3421
3311
  print(json.dumps(result, allow_nan=False, sort_keys=True))
3422
3312
  return
3423
3313
  if args.command == "inspect-setup":
3424
- result = inspect_setup_values(
3425
- args.target_path,
3426
- args.scope,
3427
- args.mode,
3428
- args.diff_target_kind,
3429
- args.diff_base_revision,
3430
- args.diff_head_revision,
3431
- args.diff_content_digest,
3432
- )
3433
- print(json.dumps(result, allow_nan=False, sort_keys=True))
3314
+ print(json.dumps(inspect_selected_setup(args), allow_nan=False, sort_keys=True))
3434
3315
  return
3435
3316
  if args.command in {"save-artifact", "read-artifact"}:
3436
3317
  print(json.dumps(saved_results.read_or_save_artifact(args)))
@@ -3448,6 +3329,7 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
3448
3329
  "save-workspace": save_workspace,
3449
3330
  "start-scan": start_scan,
3450
3331
  "begin-deep-scan": deep_scan.begin_deep_scan,
3332
+ "acknowledge-deep-scan-result": deep_scan.acknowledge_deep_scan_result,
3451
3333
  "get-deep-scan": deep_scan.get_deep_scan,
3452
3334
  "claim-deep-scan-coordinator": deep_scan.claim_deep_scan_coordinator,
3453
3335
  "upsert-deep-scan-worker": deep_scan.upsert_deep_scan_worker,
@@ -3505,7 +3387,9 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
3505
3387
  elif args.command == "start-headless-standard-scan":
3506
3388
  result = _start_prompt_driven_scan(connection, args, headless_standard=True)
3507
3389
  elif args.command == "get-scan":
3508
- result = scan_context(connection, args.scan_id, args.occurrence_id)
3390
+ if args.check_target:
3391
+ require_scan_target_unchanged(require_scan(connection, args.scan_id))
3392
+ result = get_scan(connection, args)
3509
3393
  elif args.command == "rename-scan":
3510
3394
  result = scan_history.rename_scan(
3511
3395
  connection, require_scan(connection, args.scan_id), args.name
@@ -64,7 +64,6 @@ def get_scan_feedback(connection: sqlite3.Connection, scan: sqlite3.Row) -> dict
64
64
  ORDER BY julianday(upper(updated_at)) DESC,
65
65
  julianday(upper(source_completed_at)) DESC,
66
66
  source_scan_id DESC, finding_id DESC
67
- LIMIT 50
68
67
  """,
69
68
  (scan["target_id"], scan["id"]),
70
69
  )
@@ -6,12 +6,19 @@ import argparse
6
6
  import hashlib
7
7
  import json
8
8
  import sqlite3
9
+ import stat
9
10
  import sys
10
11
  from pathlib import Path
11
12
  from typing import Any
12
13
 
13
14
  sys.path.insert(0, str(Path(__file__).resolve().parent))
14
- from workbench_target import directory_content_digest, git_bytes, git_revision
15
+ from workbench_target import (
16
+ UnreadableLocalFile,
17
+ UnsupportedLocalFileType,
18
+ directory_content_digest,
19
+ git_bytes,
20
+ git_revision,
21
+ )
15
22
 
16
23
  WORKFLOW_BINDINGS = {
17
24
  "repositoryPath": "repository_path",
@@ -123,7 +130,24 @@ def finding_workflow(
123
130
  if payload["action"] == "get":
124
131
  return {"workflow": read_workflow(connection, workflow_id)}
125
132
  if payload["action"] == "source":
126
- target = Path(payload["repository"]).resolve(strict=True)
133
+ evidence = payload.get("evidence") is True
134
+ if evidence:
135
+ try:
136
+ target = Path(payload["repository"])
137
+ metadata = target.lstat()
138
+ if (
139
+ not target.is_absolute()
140
+ or not stat.S_ISDIR(metadata.st_mode)
141
+ or getattr(metadata, "st_reparse_tag", 0) & 0x20000000
142
+ or target.resolve(strict=True) != target
143
+ ):
144
+ raise UnreadableLocalFile("The validation evidence directory was replaced.")
145
+ except (OSError, RuntimeError, UnreadableLocalFile):
146
+ if payload.get("optional") is True:
147
+ return {"source": None}
148
+ raise
149
+ else:
150
+ target = Path(payload["repository"]).resolve(strict=True)
127
151
  private_paths = payload.get("privateStatePaths", [])
128
152
  if not isinstance(private_paths, list) or any(
129
153
  not isinstance(path, str) or not Path(path).is_absolute() for path in private_paths
@@ -133,18 +157,31 @@ def finding_workflow(
133
157
  excluded = tuple(path for path in excluded if path.is_relative_to(target))
134
158
  if target in excluded:
135
159
  raise SystemExit("Private runtime storage must not exclude the repository root.")
160
+ try:
161
+ content = directory_content_digest(
162
+ target,
163
+ excluded=excluded,
164
+ include_ignored=True,
165
+ include_git_metadata=evidence,
166
+ )
167
+ except (UnsupportedLocalFileType, UnreadableLocalFile, OSError):
168
+ if payload.get("optional") is True:
169
+ return {"source": None}
170
+ raise
136
171
  return {
137
172
  "source": {
138
173
  "repository": str(target),
139
- "revision": "unversioned" if payload.get("gitDisabled") else git_revision(target),
174
+ "revision": (
175
+ "unversioned"
176
+ if evidence or payload.get("gitDisabled")
177
+ else git_revision(target)
178
+ ),
140
179
  "refsDigest": hashlib.sha256(
141
180
  b""
142
- if payload.get("gitDisabled")
181
+ if evidence or payload.get("gitDisabled")
143
182
  else (git_bytes(target, "show-ref") or b"").strip()
144
183
  ).hexdigest(),
145
- "content": directory_content_digest(
146
- target, excluded=excluded, include_ignored=True
147
- ),
184
+ "content": content,
148
185
  **({"privateStatePaths": [str(path) for path in excluded]} if excluded else {}),
149
186
  }
150
187
  }
@@ -158,15 +195,20 @@ def finding_workflow(
158
195
  binding = payload["binding"]
159
196
  source = binding["source"]
160
197
  scope = binding["scope"]
198
+ on_conflict = (
199
+ "DO UPDATE SET result_json = excluded.result_json, created_at = excluded.created_at"
200
+ if payload.get("replace") is True and binding.get("stage") == "scan-validation"
201
+ else "DO NOTHING"
202
+ )
161
203
  with connection:
162
204
  connection.execute(
163
- """INSERT INTO finding_workflow_reviews
205
+ f"""INSERT INTO finding_workflow_reviews
164
206
  (workflow_id, review_key, review_contract_version, codex_version,
165
207
  source_repository_path, source_revision, source_refs_digest, source_content_digest,
166
208
  scope_repository_id, scope_all_repositories, model, effort, settings_digest,
167
209
  prompt_digest, contract_digest, result_json, created_at)
168
210
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
169
- ON CONFLICT(workflow_id, review_key) DO NOTHING""",
211
+ ON CONFLICT(workflow_id, review_key) {on_conflict}""",
170
212
  (
171
213
  workflow_id,
172
214
  payload["key"],
@@ -1,6 +1,7 @@
1
1
  """Read-only native findings and repository indexes for the Security workbench."""
2
2
 
3
3
  import argparse
4
+ import os
4
5
  import sqlite3
5
6
  import sys
6
7
  from collections import Counter
@@ -204,63 +205,74 @@ def list_repositories(
204
205
  args: argparse.Namespace | None = None,
205
206
  ) -> dict[str, Any]:
206
207
  scan_count_by_target = Counter()
207
- latest_scan_by_target: dict[str, dict[str, Any]] = {}
208
- for scan in (
209
- scan_history.scan_summary(row)
210
- for row in connection.execute(
211
- f"""{scan_history.SCAN_SUMMARY_QUERY}
212
- ORDER BY julianday(upper(scans.started_at)) DESC, scans.id DESC
213
- """
214
- ).fetchall()
215
- ):
216
- scan_count_by_target[scan["targetId"]] += 1
217
- latest_scan_by_target.setdefault(scan["targetId"], scan)
208
+ latest_by_target: dict[str, tuple[sqlite3.Row, dict[str, Any] | None]] = {}
209
+ for row in connection.execute(
210
+ f"""
211
+ SELECT targets.id AS repository_id, targets.display_name, targets.current_path,
212
+ {scan_history.SCAN_SUMMARY_COLUMNS}
213
+ FROM security_targets AS targets
214
+ LEFT JOIN scans ON scans.target_id = targets.id
215
+ AND scans.id IN (SELECT scan_id FROM scan_progress)
216
+ LEFT JOIN scan_progress AS progress ON progress.scan_id = scans.id
217
+ ORDER BY julianday(upper(scans.started_at)) DESC, scans.id DESC, targets.id
218
+ """
219
+ ).fetchall():
220
+ scan = scan_history.scan_summary(row) if row["id"] is not None else None
221
+ target_id = row["repository_id"]
222
+ if scan is not None:
223
+ scan_count_by_target[target_id] += 1
224
+ latest_by_target.setdefault(target_id, (row, scan))
218
225
 
219
226
  open_findings_by_target = Counter(
220
227
  row["target_id"] for row in _indexed_findings(connection) if row["status"] == "open"
221
228
  )
222
- targets = {row["id"]: row for row in connection.execute("SELECT * FROM security_targets")}
223
229
  repositories = [
224
230
  {
225
- "checkoutAvailable": Path(target["current_path"]).is_dir(),
226
231
  "displayName": target["display_name"],
227
232
  "latestScan": latest_scan,
228
- "openFindingsCount": open_findings_by_target.get(target_id, 0),
233
+ "openFindingsCount": open_findings_by_target[target_id]
234
+ if latest_scan is not None
235
+ else 0,
229
236
  "scanCount": scan_count_by_target[target_id],
230
237
  "targetId": target_id,
231
238
  "targetPath": target["current_path"],
232
239
  }
233
- for target_id, latest_scan in latest_scan_by_target.items()
234
- if (target := targets.get(target_id)) is not None
235
- ]
236
- if args is None:
237
- return {"repositories": repositories}
238
-
239
- query = args.query.strip().casefold() if args.query else ""
240
- repositories = [
241
- repository
242
- for repository in repositories
243
- if (args.target_id is None or repository["targetId"] == args.target_id)
244
- and args.status != "not_scanned"
245
- and (args.status != "open_findings" or repository["openFindingsCount"] > 0)
246
- and (
247
- not query
248
- or query in repository["displayName"].casefold()
249
- or query in repository["targetPath"].casefold()
250
- )
240
+ for target_id, (target, latest_scan) in latest_by_target.items()
251
241
  ]
252
- if args.limit is None and args.offset == 0:
253
- return {"repositories": repositories}
254
-
255
- limit = min(args.limit or FINDINGS_PAGE_MAX, FINDINGS_PAGE_MAX)
256
- page = repositories[args.offset : args.offset + limit]
257
- next_offset = args.offset + len(page)
258
- return {
259
- "repositories": page,
260
- "limit": limit,
261
- "nextOffset": next_offset if next_offset < len(repositories) else None,
262
- "offset": args.offset,
263
- }
242
+ pagination = {}
243
+ if args is not None:
244
+ query = args.query.strip().casefold() if args.query else ""
245
+ repositories = [
246
+ repository
247
+ for repository in repositories
248
+ if (args.target_id is None or repository["targetId"] == args.target_id)
249
+ and (args.status != "scanned" or repository["scanCount"] > 0)
250
+ and (args.status != "not_scanned" or repository["scanCount"] == 0)
251
+ and (args.status != "open_findings" or repository["openFindingsCount"] > 0)
252
+ and (
253
+ not query
254
+ or query in repository["displayName"].casefold()
255
+ or query in repository["targetPath"].casefold()
256
+ )
257
+ ]
258
+ if args.limit is not None or args.offset:
259
+ limit = min(args.limit or FINDINGS_PAGE_MAX, FINDINGS_PAGE_MAX)
260
+ end = args.offset + limit
261
+ pagination = {
262
+ "limit": limit,
263
+ "nextOffset": end if end < len(repositories) else None,
264
+ "offset": args.offset,
265
+ }
266
+ repositories = repositories[args.offset : end]
267
+ for repository in repositories:
268
+ path = os.path.expanduser(repository["targetPath"])
269
+ try:
270
+ repository["checkoutAvailable"] = Path(path).is_absolute() and os.path.isdir(
271
+ os.path.realpath(path)
272
+ )
273
+ except (OSError, RecursionError):
274
+ repository["checkoutAvailable"] = False
275
+ return {"repositories": repositories, **pagination}
264
276
 
265
277
 
266
278
  if __name__ == "__main__":