@openai/codex-security 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/README.md +52 -9
  2. package/_bundled_plugin/.mcp.json +1 -0
  3. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  4. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  5. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  6. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +60 -9
  7. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  8. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  9. package/_bundled_plugin/references/core-scan.md +2 -0
  10. package/_bundled_plugin/references/final-report.md +5 -1
  11. package/_bundled_plugin/references/investigation-time-budget.md +11 -0
  12. package/_bundled_plugin/references/sarif-adapter.md +1 -0
  13. package/_bundled_plugin/references/scan-prologue.md +2 -6
  14. package/_bundled_plugin/references/scan-runtime.md +15 -0
  15. package/_bundled_plugin/references/threat-model.md +2 -0
  16. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +6 -2
  17. package/_bundled_plugin/scripts/deep_scan_workbench.py +7 -0
  18. package/_bundled_plugin/scripts/finalize_scan_contract.py +92 -44
  19. package/_bundled_plugin/scripts/finding_preview.py +5 -3
  20. package/_bundled_plugin/scripts/generate_in_scope_files.py +6 -6
  21. package/_bundled_plugin/scripts/generate_rank_input.py +13 -6
  22. package/_bundled_plugin/scripts/launch_codex_security_mcp +39 -4
  23. package/_bundled_plugin/scripts/report_projection.py +2 -1
  24. package/_bundled_plugin/scripts/snapshot_sqlite.py +7 -0
  25. package/_bundled_plugin/scripts/threat_model_projection.py +1 -3
  26. package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -1
  27. package/_bundled_plugin/scripts/workbench/saved_coverage.py +234 -0
  28. package/_bundled_plugin/scripts/workbench_cli.py +5 -10
  29. package/_bundled_plugin/scripts/workbench_constants.py +4 -0
  30. package/_bundled_plugin/scripts/workbench_db.py +68 -39
  31. package/_bundled_plugin/scripts/workbench_native_indexes.py +10 -7
  32. package/_bundled_plugin/scripts/workbench_progress.py +0 -50
  33. package/_bundled_plugin/scripts/workbench_publication.py +4 -3
  34. package/_bundled_plugin/scripts/workbench_remediation.py +5 -1
  35. package/_bundled_plugin/scripts/workbench_saved_results.py +542 -148
  36. package/_bundled_plugin/scripts/workbench_scan_history.py +82 -80
  37. package/_bundled_plugin/scripts/workbench_scan_start.py +12 -4
  38. package/_bundled_plugin/scripts/workbench_scan_usage.py +246 -38
  39. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  40. package/_bundled_plugin/scripts/workbench_source_excerpt.py +74 -51
  41. package/_bundled_plugin/scripts/workbench_source_scopes.py +388 -0
  42. package/_bundled_plugin/scripts/workbench_target.py +28 -12
  43. package/_bundled_plugin/scripts/workbench_validation.py +52 -13
  44. package/_bundled_plugin/shared/workbench-history-repairs.json +19 -0
  45. package/_bundled_plugin/shared/workbench-migrations.json +15 -0
  46. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +1 -1
  47. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +4 -2
  48. package/_bundled_plugin/skills/security-scan/SKILL.md +3 -1
  49. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
  50. package/dist/api.d.ts +4 -3
  51. package/dist/api.d.ts.map +1 -1
  52. package/dist/api.js +215 -93
  53. package/dist/api.js.map +1 -1
  54. package/dist/artifact-export.d.ts +2 -1
  55. package/dist/artifact-export.d.ts.map +1 -1
  56. package/dist/artifact-export.js +38 -23
  57. package/dist/artifact-export.js.map +1 -1
  58. package/dist/classify-scan-severity.d.ts.map +1 -1
  59. package/dist/classify-scan-severity.js +16 -18
  60. package/dist/classify-scan-severity.js.map +1 -1
  61. package/dist/classify-severity-records.d.ts +76 -0
  62. package/dist/classify-severity-records.d.ts.map +1 -0
  63. package/dist/classify-severity-records.js +141 -0
  64. package/dist/classify-severity-records.js.map +1 -0
  65. package/dist/classify-severity.d.ts +1 -23
  66. package/dist/classify-severity.d.ts.map +1 -1
  67. package/dist/classify-severity.js +3 -24
  68. package/dist/classify-severity.js.map +1 -1
  69. package/dist/cli-daybreak.d.ts +5 -0
  70. package/dist/cli-daybreak.d.ts.map +1 -0
  71. package/dist/cli-daybreak.js +89 -0
  72. package/dist/cli-daybreak.js.map +1 -0
  73. package/dist/cli-help.d.ts.map +1 -1
  74. package/dist/cli-help.js +2 -0
  75. package/dist/cli-help.js.map +1 -1
  76. package/dist/cli.d.ts +9 -3
  77. package/dist/cli.d.ts.map +1 -1
  78. package/dist/cli.js +957 -738
  79. package/dist/cli.js.map +1 -1
  80. package/dist/cloud-publish.js +1 -1
  81. package/dist/cloud-publish.js.map +1 -1
  82. package/dist/codeowners.js +2 -2
  83. package/dist/codeowners.js.map +1 -1
  84. package/dist/codex-sdk-environment.js +1 -1
  85. package/dist/codex-sdk-environment.js.map +1 -1
  86. package/dist/component-plan.d.ts.map +1 -1
  87. package/dist/component-plan.js +3 -2
  88. package/dist/component-plan.js.map +1 -1
  89. package/dist/component-scan.js +2 -2
  90. package/dist/component-scan.js.map +1 -1
  91. package/dist/config.d.ts +12 -0
  92. package/dist/config.d.ts.map +1 -1
  93. package/dist/config.js +15 -5
  94. package/dist/config.js.map +1 -1
  95. package/dist/contract.d.ts +5 -0
  96. package/dist/contract.d.ts.map +1 -1
  97. package/dist/contract.js +65 -17
  98. package/dist/contract.js.map +1 -1
  99. package/dist/cost-model.d.ts.map +1 -1
  100. package/dist/cost-model.js +7 -2
  101. package/dist/cost-model.js.map +1 -1
  102. package/dist/cost.d.ts +2 -1
  103. package/dist/cost.d.ts.map +1 -1
  104. package/dist/cost.js +17 -8
  105. package/dist/cost.js.map +1 -1
  106. package/dist/custom-validation-prompt.js +3 -3
  107. package/dist/custom-validation-prompt.js.map +1 -1
  108. package/dist/custom-validation.d.ts.map +1 -1
  109. package/dist/custom-validation.js +2 -5
  110. package/dist/custom-validation.js.map +1 -1
  111. package/dist/deduplication/codex-review.d.ts.map +1 -1
  112. package/dist/deduplication/codex-review.js +8 -6
  113. package/dist/deduplication/codex-review.js.map +1 -1
  114. package/dist/deduplication/deduplication-prompts.d.ts +1 -1
  115. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  116. package/dist/deduplication/deduplication-prompts.js +2 -2
  117. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  118. package/dist/deduplication/local.d.ts.map +1 -1
  119. package/dist/deduplication/local.js +5 -2
  120. package/dist/deduplication/local.js.map +1 -1
  121. package/dist/deduplication/records.js +1 -1
  122. package/dist/deduplication/records.js.map +1 -1
  123. package/dist/deduplication/retry.d.ts.map +1 -1
  124. package/dist/deduplication/retry.js +5 -0
  125. package/dist/deduplication/retry.js.map +1 -1
  126. package/dist/deduplication/scan.d.ts.map +1 -1
  127. package/dist/deduplication/scan.js +15 -10
  128. package/dist/deduplication/scan.js.map +1 -1
  129. package/dist/deep-config.d.ts +4 -1
  130. package/dist/deep-config.d.ts.map +1 -1
  131. package/dist/deep-config.js +21 -1
  132. package/dist/deep-config.js.map +1 -1
  133. package/dist/deep-scan.d.ts +6 -0
  134. package/dist/deep-scan.d.ts.map +1 -1
  135. package/dist/deep-scan.js +8 -6
  136. package/dist/deep-scan.js.map +1 -1
  137. package/dist/findings-import.d.ts +1 -1
  138. package/dist/findings-import.d.ts.map +1 -1
  139. package/dist/findings-import.js +26 -6
  140. package/dist/findings-import.js.map +1 -1
  141. package/dist/git-remote.d.ts +10 -0
  142. package/dist/git-remote.d.ts.map +1 -0
  143. package/dist/git-remote.js +24 -0
  144. package/dist/git-remote.js.map +1 -0
  145. package/dist/github.d.ts.map +1 -1
  146. package/dist/github.js +5 -7
  147. package/dist/github.js.map +1 -1
  148. package/dist/host-protocol.d.ts +1 -0
  149. package/dist/host-protocol.d.ts.map +1 -1
  150. package/dist/host-protocol.js +2 -2
  151. package/dist/host-protocol.js.map +1 -1
  152. package/dist/host-records-protocol.d.ts +15 -0
  153. package/dist/host-records-protocol.d.ts.map +1 -0
  154. package/dist/host-records-protocol.js +15 -0
  155. package/dist/host-records-protocol.js.map +1 -0
  156. package/dist/hosted-remediation-protocol.d.ts +5 -0
  157. package/dist/hosted-remediation-protocol.d.ts.map +1 -0
  158. package/dist/hosted-remediation-protocol.js +26 -0
  159. package/dist/hosted-remediation-protocol.js.map +1 -0
  160. package/dist/hosted-remediation.d.ts +89 -0
  161. package/dist/hosted-remediation.d.ts.map +1 -0
  162. package/dist/hosted-remediation.js +122 -0
  163. package/dist/hosted-remediation.js.map +1 -0
  164. package/dist/hosted-scan.d.ts +1 -6
  165. package/dist/hosted-scan.d.ts.map +1 -1
  166. package/dist/hosted-scan.js +2 -2
  167. package/dist/hosted-scan.js.map +1 -1
  168. package/dist/import-scan.d.ts +1 -0
  169. package/dist/import-scan.d.ts.map +1 -1
  170. package/dist/import-scan.js +5 -1
  171. package/dist/import-scan.js.map +1 -1
  172. package/dist/index.d.ts +9 -1
  173. package/dist/index.d.ts.map +1 -1
  174. package/dist/index.js +4 -0
  175. package/dist/index.js.map +1 -1
  176. package/dist/knowledge-base.d.ts.map +1 -1
  177. package/dist/knowledge-base.js +87 -7
  178. package/dist/knowledge-base.js.map +1 -1
  179. package/dist/multiscan.d.ts.map +1 -1
  180. package/dist/multiscan.js +65 -29
  181. package/dist/multiscan.js.map +1 -1
  182. package/dist/patch-publication.d.ts +26 -0
  183. package/dist/patch-publication.d.ts.map +1 -0
  184. package/dist/patch-publication.js +105 -0
  185. package/dist/patch-publication.js.map +1 -0
  186. package/dist/patch-tui.d.ts.map +1 -1
  187. package/dist/patch-tui.js +4 -1
  188. package/dist/patch-tui.js.map +1 -1
  189. package/dist/project-config-schema.d.ts +2 -0
  190. package/dist/project-config-schema.d.ts.map +1 -1
  191. package/dist/project-config-schema.js +1 -0
  192. package/dist/project-config-schema.js.map +1 -1
  193. package/dist/project-config.d.ts +1 -0
  194. package/dist/project-config.d.ts.map +1 -1
  195. package/dist/project-config.js +29 -15
  196. package/dist/project-config.js.map +1 -1
  197. package/dist/publication.d.ts.map +1 -1
  198. package/dist/publication.js +135 -19
  199. package/dist/publication.js.map +1 -1
  200. package/dist/publish.d.ts +2 -0
  201. package/dist/publish.d.ts.map +1 -1
  202. package/dist/publish.js +48 -25
  203. package/dist/publish.js.map +1 -1
  204. package/dist/remediation.d.ts +63 -0
  205. package/dist/remediation.d.ts.map +1 -0
  206. package/dist/remediation.js +110 -0
  207. package/dist/remediation.js.map +1 -0
  208. package/dist/request-metadata.d.ts +17 -7
  209. package/dist/request-metadata.d.ts.map +1 -1
  210. package/dist/request-metadata.js +43 -8
  211. package/dist/request-metadata.js.map +1 -1
  212. package/dist/runtime.d.ts.map +1 -1
  213. package/dist/runtime.js +104 -36
  214. package/dist/runtime.js.map +1 -1
  215. package/dist/saved-scan-bootstrap.d.ts +1 -0
  216. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  217. package/dist/saved-scan-bootstrap.js +16 -4
  218. package/dist/saved-scan-bootstrap.js.map +1 -1
  219. package/dist/scan-activity.js +8 -8
  220. package/dist/scan-activity.js.map +1 -1
  221. package/dist/scan-comparison.d.ts.map +1 -1
  222. package/dist/scan-comparison.js +15 -9
  223. package/dist/scan-comparison.js.map +1 -1
  224. package/dist/scan-dashboard.d.ts.map +1 -1
  225. package/dist/scan-dashboard.js +12 -6
  226. package/dist/scan-dashboard.js.map +1 -1
  227. package/dist/scan-executor.d.ts +5 -1
  228. package/dist/scan-executor.d.ts.map +1 -1
  229. package/dist/scan-executor.js +9 -8
  230. package/dist/scan-executor.js.map +1 -1
  231. package/dist/{deep-progress.d.ts → scan-progress.d.ts} +15 -7
  232. package/dist/scan-progress.d.ts.map +1 -0
  233. package/dist/scan-progress.js +138 -0
  234. package/dist/scan-progress.js.map +1 -0
  235. package/dist/scan-settings.d.ts +1 -0
  236. package/dist/scan-settings.d.ts.map +1 -1
  237. package/dist/scan-settings.js +7 -1
  238. package/dist/scan-settings.js.map +1 -1
  239. package/dist/scan-time-budget.d.ts +9 -0
  240. package/dist/scan-time-budget.d.ts.map +1 -0
  241. package/dist/scan-time-budget.js +16 -0
  242. package/dist/scan-time-budget.js.map +1 -0
  243. package/dist/security-policy.js +1 -1
  244. package/dist/security-policy.js.map +1 -1
  245. package/dist/server/embeddings.d.ts.map +1 -1
  246. package/dist/server/embeddings.js +4 -0
  247. package/dist/server/embeddings.js.map +1 -1
  248. package/dist/server/sqlite-store.d.ts.map +1 -1
  249. package/dist/server/sqlite-store.js +14 -2
  250. package/dist/server/sqlite-store.js.map +1 -1
  251. package/dist/severity-review.d.ts +29 -0
  252. package/dist/severity-review.d.ts.map +1 -0
  253. package/dist/severity-review.js +47 -0
  254. package/dist/severity-review.js.map +1 -0
  255. package/dist/severity-store.js +4 -1
  256. package/dist/severity-store.js.map +1 -1
  257. package/dist/timestamps.d.ts +3 -0
  258. package/dist/timestamps.d.ts.map +1 -0
  259. package/dist/timestamps.js +14 -0
  260. package/dist/timestamps.js.map +1 -0
  261. package/dist/validation-records.d.ts +38 -0
  262. package/dist/validation-records.d.ts.map +1 -0
  263. package/dist/validation-records.js +76 -0
  264. package/dist/validation-records.js.map +1 -0
  265. package/dist/version.d.ts +1 -1
  266. package/dist/version.d.ts.map +1 -1
  267. package/dist/version.js +17 -4
  268. package/dist/version.js.map +1 -1
  269. package/dist/workbench-arguments.d.ts.map +1 -1
  270. package/dist/workbench-arguments.js +9 -3
  271. package/dist/workbench-arguments.js.map +1 -1
  272. package/dist/worker-progress.d.ts +13 -7
  273. package/dist/worker-progress.d.ts.map +1 -1
  274. package/dist/worker-progress.js +12 -44
  275. package/dist/worker-progress.js.map +1 -1
  276. package/docs/classify-severity-records.md +89 -0
  277. package/docs/cli.md +352 -45
  278. package/docs/findings-service.md +7 -2
  279. package/docs/hosted-remediation.md +117 -0
  280. package/docs/hosted-scans.md +8 -3
  281. package/docs/validate-records.md +69 -0
  282. package/package.json +13 -10
  283. package/schemas/project-config.schema.json +7 -1
  284. package/_bundled_plugin/preflight/capability-profiles.toml +0 -76
  285. package/_bundled_plugin/references/config-preflight.md +0 -93
  286. package/_bundled_plugin/references/desktop-config-preflight.md +0 -11
  287. package/_bundled_plugin/scripts/config_preflight.py +0 -911
  288. package/dist/deep-progress.d.ts.map +0 -1
  289. package/dist/deep-progress.js +0 -92
  290. package/dist/deep-progress.js.map +0 -1
@@ -0,0 +1,234 @@
1
+ """Project saved worker coverage and reconcile its published parent copies."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import copy
6
+ import hashlib
7
+ import json
8
+ from pathlib import Path
9
+ from typing import Any
10
+
11
+ from finalize_scan_contract import (
12
+ ContractError,
13
+ _normalize_unsealed_open_questions,
14
+ _require_portable_relative_path,
15
+ )
16
+
17
+
18
+ def _saved_coverage_id(item: dict[str, Any]) -> str:
19
+ if candidate_id := item.get("candidateId"):
20
+ return candidate_id
21
+ payload = json.dumps(
22
+ item, ensure_ascii=True, allow_nan=False, sort_keys=True, separators=(",", ":")
23
+ ).encode()
24
+ return f"saved-{hashlib.sha256(payload).hexdigest()[:16]}"
25
+
26
+
27
+ def _project_worker_coverage_row(item: Any, worker_id: str | None, field: str) -> Any:
28
+ row = copy.deepcopy(item)
29
+ if worker_id is None or not isinstance(row, dict):
30
+ return row
31
+ row["workerId"] = worker_id
32
+ if field == "openQuestions":
33
+ return row
34
+ # Reconcile raw checkpoint identities first. Anonymous output rows use the
35
+ # existing content identity, never their position in an earlier snapshot.
36
+ row.setdefault("id", _saved_coverage_id(row))
37
+ if isinstance(row.get("id"), str):
38
+ row["id"] = f"{worker_id}/{row['id']}"
39
+ if field == "deferred" and isinstance(row.get("surfaceIds"), list):
40
+ row["surfaceIds"] = [
41
+ f"{worker_id}/{identity}" if isinstance(identity, str) else identity
42
+ for identity in row["surfaceIds"]
43
+ ]
44
+ return row
45
+
46
+
47
+ def _coverage_comparison_row(row: Any, field: str) -> Any:
48
+ if field == "surfaces" and isinstance(row, dict):
49
+ row = {"receiptRefs": [], **row}
50
+ if isinstance(row["receiptRefs"], list):
51
+ refs = []
52
+ for ref in row["receiptRefs"]:
53
+ if isinstance(ref, str):
54
+ try:
55
+ ref = _require_portable_relative_path(ref, "Saved coverage receipt")
56
+ except ContractError:
57
+ pass # Leave malformed refs to the existing per-record recovery.
58
+ refs.append(ref)
59
+ row["receiptRefs"] = refs
60
+ return row
61
+ if field == "openQuestions":
62
+ coverage = {"openQuestions": [copy.deepcopy(row)]}
63
+ _normalize_unsealed_open_questions(coverage)
64
+ return next(iter(coverage["openQuestions"]), row)
65
+ return row
66
+
67
+
68
+ def _aggregate_worker_coverage_rows(rows: list[Any], worker_id: str, field: str) -> list[Any]:
69
+ """Match accepted aggregate IDs without changing raw recovery identities."""
70
+ reserved = {
71
+ row["id"] for row in rows if isinstance(row, dict) and isinstance(row.get("id"), str)
72
+ }
73
+ emitted: set[str] = set()
74
+ projected = []
75
+ for index, original in enumerate(rows):
76
+ row = copy.deepcopy(original)
77
+ if isinstance(row, dict) and field != "openQuestions":
78
+ generated = not isinstance(row.get("id"), str)
79
+ identity = str(index) if generated else row["id"]
80
+ base = identity
81
+ if generated or identity in emitted:
82
+ suffix = 2
83
+ while identity in reserved:
84
+ identity = f"{base}-{suffix}"
85
+ suffix += 1
86
+ reserved.add(identity)
87
+ emitted.add(identity)
88
+ row["id"] = identity
89
+ projected.append(
90
+ _coverage_comparison_row(_project_worker_coverage_row(row, worker_id, field), field)
91
+ )
92
+ return projected
93
+
94
+
95
+ def _prepare_worker_coverage_recovery(
96
+ sources: list[tuple[str, dict[str, Any], str | None]],
97
+ parent: dict[str, Any] | None,
98
+ source_order: dict[str, tuple[int, int]],
99
+ *,
100
+ enabled: bool,
101
+ ) -> tuple[
102
+ bool, list[tuple[dict[str, Any], str, dict[str, Any], dict[str, Any], dict[str, Any] | None]]
103
+ ]:
104
+ """Put bound worker evidence in parent coordinates without changing source files."""
105
+ workers = {owner for _, _, owner in sources if owner is not None}
106
+ parents = [
107
+ draft
108
+ for _, draft, owner in sorted(
109
+ sources, key=lambda source: source_order[source[0]], reverse=True
110
+ )
111
+ if owner is None
112
+ ]
113
+ if parent is not None:
114
+ # Prefer the selected parent over historical copies of a task's surface.
115
+ parents.insert(0, parent)
116
+ fields = ("surfaces", "explicitExclusions", "deferred", "openQuestions")
117
+ if not enabled:
118
+ enabled = any(
119
+ isinstance(row, dict)
120
+ and isinstance(row.get("workerId"), str)
121
+ and row["workerId"] in workers
122
+ and (
123
+ field == "openQuestions"
124
+ or (isinstance(row.get("id"), str) and row["id"].startswith(f"{row['workerId']}/"))
125
+ )
126
+ for draft in parents
127
+ for field in fields
128
+ for row in (
129
+ draft["coverage"].get(field, [])
130
+ if isinstance(draft["coverage"].get(field, []), list)
131
+ else []
132
+ )
133
+ )
134
+ if not enabled:
135
+ return False, []
136
+ projected: dict[str, list[Any]] = {field: [] for field in fields}
137
+ surface_sources: list[tuple[dict[str, Any], dict[str, Any]]] = []
138
+ task_sources: list[tuple[dict[str, Any], dict[str, Any]]] = []
139
+ surface_links: list[
140
+ tuple[dict[str, Any], str, dict[str, Any], dict[str, Any], dict[str, Any] | None]
141
+ ] = []
142
+ for relative, draft, owner in sources:
143
+ if owner is None:
144
+ continue
145
+ directory = Path(relative).parent
146
+ if directory.name == "checkpoints":
147
+ directory = directory.parent
148
+ for field in fields:
149
+ rows = draft["coverage"].get(field, [])
150
+ if not isinstance(rows, list):
151
+ continue
152
+ for index, row in enumerate(rows):
153
+ if field == "openQuestions" and isinstance(row, str):
154
+ row = {"question": row}
155
+ rows[index] = row
156
+ if not isinstance(row, dict):
157
+ continue
158
+ row["workerId"] = owner
159
+ if field == "surfaces" and isinstance(row.get("receiptRefs"), list):
160
+ refs = []
161
+ for ref in row["receiptRefs"]:
162
+ if isinstance(ref, str):
163
+ try:
164
+ normalized = _require_portable_relative_path(
165
+ ref, "Worker coverage receipt"
166
+ )
167
+ except ContractError:
168
+ pass # Leave malformed refs to the existing per-record recovery.
169
+ else:
170
+ if normalized.startswith("artifacts/"):
171
+ ref = f"{directory.as_posix()}/{normalized}"
172
+ refs.append(ref)
173
+ row["receiptRefs"] = refs
174
+ if field == "surfaces":
175
+ row.setdefault("receiptRefs", [])
176
+ aggregate_rows = _aggregate_worker_coverage_rows(rows, owner, field)
177
+ projected[field].extend(aggregate_rows)
178
+ if field in {"surfaces", "deferred"}:
179
+ originals = surface_sources if field == "surfaces" else task_sources
180
+ originals.extend(
181
+ (aggregate, row)
182
+ for aggregate, row in zip(aggregate_rows, rows)
183
+ if isinstance(aggregate, dict) and isinstance(row, dict)
184
+ )
185
+ # A canonical aggregate contains copies of the same worker evidence. Let
186
+ # the existing per-worker chronology reconcile those originals exactly once.
187
+ # Keep parent-only evidence when its bound worker source is unavailable.
188
+ for draft in parents:
189
+ if not draft["coverage"]:
190
+ continue
191
+ for field in fields:
192
+ rows = draft["coverage"].get(field, [])
193
+ if isinstance(rows, list):
194
+ if field == "surfaces":
195
+ tasks = draft["coverage"].get("deferred", [])
196
+ for row in rows:
197
+ if not isinstance(row, dict) or not isinstance(row.get("id"), str):
198
+ continue
199
+ matching_sources = [
200
+ original
201
+ for aggregate, original in surface_sources
202
+ if aggregate == _coverage_comparison_row(row, field)
203
+ ]
204
+ if not matching_sources:
205
+ continue
206
+ for task in tasks if isinstance(tasks, list) else []:
207
+ if (
208
+ isinstance(task, dict)
209
+ and isinstance(task.get("surfaceIds"), list)
210
+ and row["id"] in task["surfaceIds"]
211
+ ):
212
+ surface_links.extend(
213
+ (
214
+ task,
215
+ row["id"],
216
+ source,
217
+ row,
218
+ next(
219
+ (
220
+ original
221
+ for aggregate, original in task_sources
222
+ if aggregate == task
223
+ ),
224
+ None,
225
+ ),
226
+ )
227
+ for source in matching_sources
228
+ )
229
+ draft["coverage"][field] = [
230
+ row
231
+ for row in rows
232
+ if _coverage_comparison_row(row, field) not in projected[field]
233
+ ]
234
+ return True, surface_links
@@ -189,9 +189,6 @@ def parse_args(description: str) -> argparse.Namespace:
189
189
  update_progress.add_argument("--phase-items-total", type=deep_scan.non_negative_int)
190
190
  update_progress.add_argument("--phase-items-completed", type=deep_scan.non_negative_int)
191
191
  update_progress.add_argument("--phase-progress-unit", choices=PHASE_PROGRESS_UNITS)
192
- preflight_issues = update_progress.add_mutually_exclusive_group()
193
- preflight_issues.add_argument("--preflight-issues-json")
194
- preflight_issues.add_argument("--preflight-issues-json-stdin", action="store_true")
195
192
  update_progress.add_argument("--review-items-total", type=deep_scan.non_negative_int)
196
193
  update_progress.add_argument("--review-items-completed", type=deep_scan.non_negative_int)
197
194
  update_progress.add_argument("--reportable-findings-count", type=deep_scan.non_negative_int)
@@ -312,13 +309,11 @@ def parse_args(description: str) -> argparse.Namespace:
312
309
  subparsers.add_parser("database-info")
313
310
  subparsers.add_parser("finding-workflow")
314
311
  subparsers.add_parser("local-dedupe")
315
- arguments = sys.argv[1:]
316
- if "--user-context-stdin" in arguments:
317
- if arguments.count("--user-context-stdin") != 1 or "--user-context" in arguments:
318
- parser.error("pass exactly one user-context transport")
319
- index = arguments.index("--user-context-stdin")
320
- arguments[index] = "--user-context=" + sys.stdin.buffer.read().decode("utf-8")
321
- return parser.parse_args(arguments)
312
+ args = parser.parse_args()
313
+ if getattr(args, "user_context_stdin", False):
314
+ args.user_context = sys.stdin.buffer.read().decode("utf-8")
315
+ args.user_context_stdin = False
316
+ return args
322
317
 
323
318
 
324
319
  if __name__ == "__main__":
@@ -57,6 +57,10 @@ GIT_REPOSITORY_ENVIRONMENT = (
57
57
  "GIT_WORK_TREE",
58
58
  )
59
59
  EMPTY_GIT_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
60
+ EMPTY_GIT_TREES = {
61
+ "sha1": EMPTY_GIT_TREE,
62
+ "sha256": "6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321",
63
+ }
60
64
 
61
65
 
62
66
  def positive_int(value: str) -> int:
@@ -64,6 +64,7 @@ from workbench_constants import (
64
64
  DELIVERED_ACTION_LEASE_SECONDS,
65
65
  DIFF_TARGET_KINDS,
66
66
  EMPTY_GIT_TREE,
67
+ EMPTY_GIT_TREES,
67
68
  FINDING_ABSOLUTE_PATH_BYTES,
68
69
  FINDING_LEVEL_BYTES,
69
70
  FINDING_LOCATION_PATH_BYTES,
@@ -95,7 +96,14 @@ from workbench_schema import (
95
96
  from workbench_schema import (
96
97
  apply_migrations as apply_schema_migrations,
97
98
  )
98
- from workbench_source_excerpt import finding_source_excerpt, safe_source_path
99
+ from workbench_source_excerpt import finding_source_excerpt
100
+ from workbench_source_scopes import (
101
+ capture_source_scopes,
102
+ expected_target_kinds,
103
+ public_scan_recipe,
104
+ requested_scan_paths,
105
+ safe_source_path,
106
+ )
99
107
  from workbench_target import (
100
108
  clean_worktree_content_digest,
101
109
  copy_directory_excluding,
@@ -337,7 +345,7 @@ def require_diff_target(
337
345
  None,
338
346
  )
339
347
  if parent_line is None:
340
- parent = EMPTY_GIT_TREE
348
+ parent = EMPTY_GIT_TREES[git_output(target, "rev-parse", "--show-object-format")]
341
349
  else:
342
350
  parent = resolve_git_commit(
343
351
  target,
@@ -420,27 +428,6 @@ def require_scannable_target(target: Path) -> None:
420
428
  )
421
429
 
422
430
 
423
- def expected_target_kinds(scan: sqlite3.Row) -> list[str]:
424
- if scan["mode"] == "diff":
425
- return ["git_diff"]
426
- if scan["target_revision"] == "unversioned":
427
- return ["directory_snapshot"]
428
- if scan["target_snapshot_digest"] is None:
429
- return ["git_worktree", "git_revision"]
430
- if scan["target_snapshot_digest"] == clean_worktree_content_digest():
431
- return ["git_revision"]
432
- return ["git_worktree"]
433
-
434
-
435
- def requested_scan_paths(scan: sqlite3.Row) -> list[str]:
436
- if "recipe_json" in scan.keys() and scan["recipe_json"] is not None:
437
- recipe = json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json)
438
- target = recipe["target"]
439
- if target["kind"] == "paths":
440
- return target["paths"]
441
- return [scan["scope"]]
442
-
443
-
444
431
  def requested_scan_file_paths(scan: sqlite3.Row) -> list[str]:
445
432
  # Older scans did not record path kinds. Retain their lexical scope semantics
446
433
  # rather than infer the original target from a possibly changed checkout.
@@ -866,6 +853,12 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
866
853
  diff_target,
867
854
  metadata=target_metadata,
868
855
  )
856
+ source_scopes = capture_source_scopes(
857
+ target,
858
+ target_identity,
859
+ [scope],
860
+ diff_target_kind=diff_target["kind"] if diff_target is not None else None,
861
+ )
869
862
  target_root = scan_target_root(args.scan_root, target)
870
863
  create_private_directory(target_root)
871
864
  if manages_transaction:
@@ -914,6 +907,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
914
907
  scope=scope,
915
908
  diff_target=diff_target,
916
909
  target_identity=target_identity,
910
+ source_scopes=source_scopes,
917
911
  target_root=target_root,
918
912
  target_summary=target_summary,
919
913
  scope_file_count=scope_file_count,
@@ -958,6 +952,12 @@ def _start_prompt_driven_scan(
958
952
  )
959
953
  diff_identity = scan_diff_identity(diff_target)
960
954
  target_identity = scan_target_identity(target, diff_target)
955
+ source_scopes = capture_source_scopes(
956
+ target,
957
+ target_identity,
958
+ [scope],
959
+ diff_target_kind=diff_target["kind"] if diff_target is not None else None,
960
+ )
961
961
  target_root = scan_target_root(args.scan_root, target)
962
962
 
963
963
  busy_timeout = int(connection.execute("PRAGMA busy_timeout").fetchone()[0])
@@ -1070,6 +1070,7 @@ def _start_prompt_driven_scan(
1070
1070
  scope=scope,
1071
1071
  diff_target=diff_target,
1072
1072
  target_identity=target_identity,
1073
+ source_scopes=source_scopes,
1073
1074
  target_root=target_root,
1074
1075
  target_summary=target_summary,
1075
1076
  scope_file_count=scope_file_count,
@@ -1185,12 +1186,18 @@ def finalize_scan_usage(connection: sqlite3.Connection, args: argparse.Namespace
1185
1186
  completed_turn_id=args.turn_id,
1186
1187
  )
1187
1188
  if usage["coverage"] == "unavailable":
1188
- return scan_context(connection, scan_id)
1189
- if args.turn_status != "completed":
1190
- if usage["coverage"] == "complete":
1191
- usage["coverage"] = "partial"
1192
- usage["warnings"] = [*usage.get("warnings", []), f"scan_turn_{args.turn_status}"]
1193
- usage["completion"] = {**completion, "finalized": True}
1189
+ if not usage.get("accountRateLimits"):
1190
+ return scan_context(connection, scan_id)
1191
+ usage = {**stored["usage"], "accountRateLimits": usage["accountRateLimits"]}
1192
+ else:
1193
+ if args.turn_status != "completed":
1194
+ if usage["coverage"] == "complete":
1195
+ usage["coverage"] = "partial"
1196
+ usage["warnings"] = [
1197
+ *usage.get("warnings", []),
1198
+ f"scan_turn_{args.turn_status}",
1199
+ ]
1200
+ usage["completion"] = {**completion, "finalized": True}
1194
1201
  cost_json = parse_scan_cost(json.dumps({**stored, "usage": usage}))
1195
1202
  with connection:
1196
1203
  connection.execute(
@@ -1638,13 +1645,15 @@ def complete_scan_locked(
1638
1645
  context["targetWarnings"] = target_warnings
1639
1646
  return context
1640
1647
 
1641
- if cost_json is None:
1642
- measured_usage = scan_usage.collect_scan_usage(
1648
+ cost_fields = scan_usage.stored_scan_cost_fields(cost_json)
1649
+ if "usage" not in cost_fields:
1650
+ cost_fields["usage"] = scan_usage.collect_scan_usage(
1643
1651
  connection,
1644
1652
  scan,
1645
1653
  thread_id=thread_id,
1646
1654
  completed_at=completion_timestamp,
1647
1655
  )
1656
+ measured_usage = cost_fields["usage"]
1648
1657
  if thread_id is not None and turn_id is not None:
1649
1658
  measured_usage["completion"] = {
1650
1659
  "threadId": thread_id,
@@ -1653,11 +1662,10 @@ def complete_scan_locked(
1653
1662
  }
1654
1663
  if measured_usage["coverage"] == "complete":
1655
1664
  measured_usage["coverage"] = "partial"
1656
- measured_usage["warnings"] = [
1657
- *measured_usage.get("warnings", []),
1658
- "turn_in_progress",
1659
- ]
1660
- cost_json = parse_scan_cost(scan_usage.measured_scan_cost_json(measured_usage))
1665
+ measured_usage["warnings"] = sorted(
1666
+ {*measured_usage.get("warnings", []), "turn_in_progress"}
1667
+ )
1668
+ cost_json = parse_scan_cost(json.dumps(cost_fields))
1661
1669
  connection.execute("BEGIN IMMEDIATE")
1662
1670
  with connection:
1663
1671
  timestamp = manifest["scan"]["completedAt"]
@@ -1753,6 +1761,7 @@ def register_cli_scan(
1753
1761
  recipe = parse_scan_recipe(recipe_json, repository)
1754
1762
  requested_target = recipe["target"]
1755
1763
  paths = requested_target["paths"]
1764
+ recipe.pop("_codexSecurityFileScopes", None)
1756
1765
  # Capture host-observed kinds once; resumes and publication use the saved recipe.
1757
1766
  recipe.pop("scopeFilePaths", None)
1758
1767
  if file_paths := [path for path in paths if (repository / path).is_file()]:
@@ -1774,6 +1783,12 @@ def register_cli_scan(
1774
1783
  diff_target["contentDigest"] = worktree_content_digest(repository)
1775
1784
  mode = "diff" if diff_target is not None else recipe["mode"]
1776
1785
  target_identity = scan_target_identity(repository, diff_target)
1786
+ source_scopes = capture_source_scopes(
1787
+ repository,
1788
+ target_identity,
1789
+ paths or ["."],
1790
+ diff_target_kind=diff_target["kind"] if diff_target is not None else None,
1791
+ )
1777
1792
  scope_file_count = (
1778
1793
  directory_snapshot_regular_file_count(repository)
1779
1794
  if not paths
@@ -1844,6 +1859,7 @@ def register_cli_scan(
1844
1859
  scope=scope,
1845
1860
  diff_target=diff_target,
1846
1861
  target_identity=target_identity,
1862
+ source_scopes=source_scopes,
1847
1863
  target_root=scan_dir.parent,
1848
1864
  target_summary=None,
1849
1865
  scope_file_count=scope_file_count,
@@ -2725,7 +2741,7 @@ def scan_context(
2725
2741
  }
2726
2742
  if scan["recipe_json"] is not None:
2727
2743
  context["parentScanId"] = scan["parent_scan_id"]
2728
- context["recipe"] = json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json)
2744
+ context["recipe"] = public_scan_recipe(scan)
2729
2745
  return context
2730
2746
 
2731
2747
 
@@ -3023,6 +3039,7 @@ def finding_result(
3023
3039
  severity = details.get("severity")
3024
3040
  severity = severity if isinstance(severity, dict) else {}
3025
3041
  locations = []
3042
+ excerpt_locations = []
3026
3043
  try:
3027
3044
  target = require_scan_target_identity(scan)
3028
3045
  except SystemExit:
@@ -3037,10 +3054,20 @@ def finding_result(
3037
3054
  """,
3038
3055
  (occurrence["id"], FINDING_LOCATIONS_LIMIT),
3039
3056
  ):
3057
+ display_path = bounded_output_text(row["relative_path"], FINDING_LOCATION_PATH_BYTES)
3058
+ if display_path == row["relative_path"]:
3059
+ excerpt_locations.append(
3060
+ {
3061
+ "endLine": row["end_line"],
3062
+ "path": row["relative_path"],
3063
+ "role": row["role"],
3064
+ "startLine": row["start_line"],
3065
+ }
3066
+ )
3040
3067
  absolute_path = safe_source_path(target, row["relative_path"]) if target else None
3041
3068
  location = {
3042
3069
  "endLine": row["end_line"],
3043
- "path": bounded_output_text(row["relative_path"], FINDING_LOCATION_PATH_BYTES),
3070
+ "path": display_path,
3044
3071
  "role": (
3045
3072
  bounded_output_text(row["role"], FINDING_LOCATION_ROLE_BYTES)
3046
3073
  if row["role"] is not None
@@ -3082,7 +3109,9 @@ def finding_result(
3082
3109
  result["knownScanIds"] = known_scan_ids
3083
3110
  if related:
3084
3111
  result["related"] = related
3085
- source_excerpt = finding_source_excerpt(scan, target, locations)
3112
+ source_excerpt = finding_source_excerpt(
3113
+ scan, target, excerpt_locations, requested_scan_paths(scan)
3114
+ )
3086
3115
  if source_excerpt:
3087
3116
  result["sourceExcerpt"] = source_excerpt
3088
3117
  artifact_paths = finding_artifact_paths(Path(scan["scan_dir"]), details)
@@ -203,15 +203,18 @@ def list_repositories(
203
203
  connection: sqlite3.Connection,
204
204
  args: argparse.Namespace | None = None,
205
205
  ) -> dict[str, Any]:
206
- scans = scan_history.list_scans(connection)["scans"]
207
- scans_by_id = {scan["scanId"]: scan for scan in scans}
208
- scan_count_by_target = dict(Counter(scan["targetId"] for scan in scans))
209
-
206
+ scan_count_by_target = Counter()
210
207
  latest_scan_by_target: dict[str, dict[str, Any]] = {}
211
- for row in connection.execute(
212
- "SELECT id, target_id FROM scans ORDER BY julianday(upper(started_at)) DESC, id DESC"
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()
213
215
  ):
214
- latest_scan_by_target.setdefault(row["target_id"], scans_by_id[row["id"]])
216
+ scan_count_by_target[scan["targetId"]] += 1
217
+ latest_scan_by_target.setdefault(scan["targetId"], scan)
215
218
 
216
219
  open_findings_by_target = Counter(
217
220
  row["target_id"] for row in _indexed_findings(connection) if row["status"] == "open"
@@ -1,7 +1,6 @@
1
1
  """Progress transition helpers for the Codex Security workbench."""
2
2
 
3
3
  import argparse
4
- import json
5
4
  import sqlite3
6
5
  import sys
7
6
  from pathlib import Path
@@ -13,45 +12,6 @@ from workbench.handoff import require_current_continuation
13
12
  from workbench_constants import PHASES
14
13
  from workbench_validation import optional_text, require_uuid, user_context_argument
15
14
 
16
- MAX_PREFLIGHT_ISSUES = 32
17
-
18
-
19
- def _preflight_issue_text(value: Any, maximum: int, label: str) -> str:
20
- if not isinstance(value, str):
21
- raise SystemExit(f"Preflight issue {label} must be text.")
22
- normalized = value.strip()
23
- # Match JavaScript's UTF-16 code-unit length.
24
- if not normalized or len(normalized.encode("utf-16-le", errors="surrogatepass")) // 2 > maximum:
25
- raise SystemExit(f"Preflight issue {label} must contain 1 to {maximum} characters.")
26
- return normalized
27
-
28
-
29
- def preflight_issues_json(value: str | None) -> str | None:
30
- if value is None:
31
- return None
32
- try:
33
- payload = json.loads(value)
34
- except json.JSONDecodeError as exc:
35
- raise SystemExit("Preflight issues must be valid JSON.") from exc
36
- if not isinstance(payload, list) or len(payload) > MAX_PREFLIGHT_ISSUES:
37
- raise SystemExit(
38
- f"Preflight issues must be an array of at most {MAX_PREFLIGHT_ISSUES} objects."
39
- )
40
- expected_keys = {"capability", "reason", "severity", "status"}
41
- for index, issue in enumerate(payload):
42
- label = f"{index + 1}"
43
- if not isinstance(issue, dict) or set(issue) != expected_keys:
44
- raise SystemExit(
45
- f"Preflight issue {label} must contain capability, reason, severity, and status."
46
- )
47
- severity = issue.get("severity")
48
- status = issue.get("status")
49
- if severity not in {"block", "warn"} or status not in {"fail", "unknown"}:
50
- raise SystemExit(f"Preflight issue {label} has an invalid severity or status.")
51
- for field, maximum in (("capability", 128), ("reason", 1200)):
52
- issue[field] = _preflight_issue_text(issue.get(field), maximum, f"{label} {field}")
53
- return json.dumps(payload, ensure_ascii=True, separators=(",", ":"), sort_keys=True)
54
-
55
15
 
56
16
  def reportable_count(
57
17
  current_phase: str, requested_phase: str | None, count: int | None
@@ -115,10 +75,6 @@ def update_progress(
115
75
  scan_id = require_uuid(args.scan_id, "scan-id")
116
76
  model = optional_text(args.model, maximum=200)
117
77
  reasoning_effort = optional_text(args.reasoning_effort, maximum=32)
118
- preflight_issues = (
119
- sys.stdin.read() if args.preflight_issues_json_stdin else args.preflight_issues_json
120
- )
121
- serialized_preflight_issues = preflight_issues_json(preflight_issues)
122
78
  connection.execute("BEGIN IMMEDIATE")
123
79
  with connection:
124
80
  timestamp = wb.now()
@@ -142,11 +98,6 @@ def update_progress(
142
98
  )
143
99
  if args.deep_review_pass is not None and scan["mode"] != "deep":
144
100
  raise SystemExit("Only Deep Scan can record a deep review pass.")
145
- if serialized_preflight_issues is not None:
146
- if scan["mode"] == "deep":
147
- raise SystemExit("Deep Scan preflight progress is owned by its coordinator.")
148
- if scan["phase"] != "preflight" or args.phase not in {None, "preflight"}:
149
- raise SystemExit("Preflight issues can only be updated during preflight.")
150
101
  progress = connection.execute(
151
102
  "SELECT * FROM scan_progress WHERE scan_id = ?", (scan["id"],)
152
103
  ).fetchone()
@@ -194,7 +145,6 @@ def update_progress(
194
145
  updates.extend(["preflight_checks_total = ?", "preflight_checks_completed = ?"])
195
146
  values.extend([phase_total, phase_completed])
196
147
  for column, value in (
197
- ("preflight_issues_json", serialized_preflight_issues),
198
148
  ("review_items_total", args.review_items_total),
199
149
  ("review_items_completed", args.review_items_completed),
200
150
  (
@@ -332,7 +332,7 @@ def export_findings(
332
332
  "workspace": db.workspace_state(connection, scan["workspace_id"]),
333
333
  }
334
334
  try:
335
- manifest, _, _ = finalize_scan(
335
+ manifest, findings_document, _ = finalize_scan(
336
336
  scan_dir,
337
337
  expected_coverage_mode=db.expected_coverage_mode(scan),
338
338
  )
@@ -350,7 +350,8 @@ def export_findings(
350
350
  raise SystemExit(str(exc)) from exc
351
351
  path = db.artifact_path(scan_dir, "exports/results.sarif", required=True)
352
352
  else:
353
- path = write_csv_export(db, connection, scan)
353
+ path = write_csv_export(db, connection, scan, findings_document)
354
+ del findings_document
354
355
  if path is None:
355
356
  raise SystemExit(f"Could not export Codex Security findings as {args.format.upper()}.")
356
357
  return {
@@ -364,6 +365,7 @@ def write_csv_export(
364
365
  db: Any,
365
366
  connection: sqlite3.Connection,
366
367
  scan: sqlite3.Row,
368
+ findings_document: dict[str, Any],
367
369
  ) -> Path:
368
370
  scan_dir = db.require_canonical_scan_directory(Path(scan["scan_dir"]))
369
371
  output = io.StringIO(newline="")
@@ -371,7 +373,6 @@ def write_csv_export(
371
373
  deep_scan = scan["mode"] == "deep"
372
374
  candidate_ids_by_occurrence: dict[str, str] = {}
373
375
  if deep_scan:
374
- findings_document = db.read_json_object(scan_dir / db.ARTIFACTS["findings"])
375
376
  findings = findings_document.get("findings")
376
377
  if not isinstance(findings, list):
377
378
  raise SystemExit("findings.json must contain a findings array.")
@@ -147,7 +147,11 @@ def cancel_finding_remediation_request(
147
147
  connection.execute(
148
148
  """
149
149
  UPDATE finding_remediation_attempts
150
- SET pending_action = NULL, pending_action_claimed_at = NULL,
150
+ SET state = CASE
151
+ WHEN pending_action = 'verify' AND state = 'verifying' THEN 'applied'
152
+ ELSE state
153
+ END,
154
+ pending_action = NULL, pending_action_claimed_at = NULL,
151
155
  pending_action_claim_token = NULL, pending_action_delivered_at = NULL,
152
156
  version = version + 1, updated_at = ?
153
157
  WHERE request_id = ? AND pending_action_claim_token = ?