@openai/codex-security 0.5.0 → 0.6.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 (299) hide show
  1. package/README.md +93 -2
  2. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  3. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  4. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  5. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +60 -9
  6. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  7. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  8. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +1 -1
  9. package/_bundled_plugin/scripts/finalize_scan_contract.py +12 -1
  10. package/_bundled_plugin/scripts/generate_in_scope_files.py +6 -6
  11. package/_bundled_plugin/scripts/generate_rank_input.py +12 -6
  12. package/_bundled_plugin/scripts/report_projection.py +2 -1
  13. package/_bundled_plugin/scripts/threat_model_projection.py +1 -3
  14. package/_bundled_plugin/scripts/workbench/saved_coverage.py +234 -0
  15. package/_bundled_plugin/scripts/workbench_cli.py +5 -7
  16. package/_bundled_plugin/scripts/workbench_db.py +12 -6
  17. package/_bundled_plugin/scripts/workbench_finding_workflows.py +2 -0
  18. package/_bundled_plugin/scripts/workbench_native_indexes.py +10 -7
  19. package/_bundled_plugin/scripts/workbench_publication.py +4 -3
  20. package/_bundled_plugin/scripts/workbench_remediation.py +5 -1
  21. package/_bundled_plugin/scripts/workbench_saved_results.py +542 -148
  22. package/_bundled_plugin/scripts/workbench_scan_history.py +79 -78
  23. package/_bundled_plugin/scripts/workbench_scan_usage.py +61 -13
  24. package/_bundled_plugin/scripts/workbench_target.py +21 -7
  25. package/_bundled_plugin/scripts/workbench_validation.py +21 -18
  26. package/_bundled_plugin/shared/workbench-migrations.json +26 -0
  27. package/_bundled_plugin/skills/fix-finding/SKILL.md +16 -8
  28. package/_bundled_plugin/skills/publish-findings/SKILL.md +130 -0
  29. package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +6 -0
  30. package/_bundled_plugin/skills/verify-fix/SKILL.md +4 -2
  31. package/dist/api.d.ts +4 -1
  32. package/dist/api.d.ts.map +1 -1
  33. package/dist/api.js +233 -91
  34. package/dist/api.js.map +1 -1
  35. package/dist/classify-scan-severity.d.ts.map +1 -1
  36. package/dist/classify-scan-severity.js +16 -18
  37. package/dist/classify-scan-severity.js.map +1 -1
  38. package/dist/classify-severity-records.d.ts +5 -2
  39. package/dist/classify-severity-records.d.ts.map +1 -1
  40. package/dist/classify-severity-records.js +40 -34
  41. package/dist/classify-severity-records.js.map +1 -1
  42. package/dist/classify-severity.d.ts +5 -1
  43. package/dist/classify-severity.d.ts.map +1 -1
  44. package/dist/classify-severity.js +20 -30
  45. package/dist/classify-severity.js.map +1 -1
  46. package/dist/cli-daybreak.d.ts +5 -0
  47. package/dist/cli-daybreak.d.ts.map +1 -0
  48. package/dist/cli-daybreak.js +89 -0
  49. package/dist/cli-daybreak.js.map +1 -0
  50. package/dist/cli-help.d.ts.map +1 -1
  51. package/dist/cli-help.js +1 -0
  52. package/dist/cli-help.js.map +1 -1
  53. package/dist/cli.d.ts +12 -1
  54. package/dist/cli.d.ts.map +1 -1
  55. package/dist/cli.js +1224 -596
  56. package/dist/cli.js.map +1 -1
  57. package/dist/cloud-endpoint.d.ts +6 -0
  58. package/dist/cloud-endpoint.d.ts.map +1 -0
  59. package/dist/cloud-endpoint.js +51 -0
  60. package/dist/cloud-endpoint.js.map +1 -0
  61. package/dist/cloud-publish.d.ts.map +1 -1
  62. package/dist/cloud-publish.js +7 -5
  63. package/dist/cloud-publish.js.map +1 -1
  64. package/dist/codeowners.js +2 -2
  65. package/dist/codeowners.js.map +1 -1
  66. package/dist/component-plan.d.ts.map +1 -1
  67. package/dist/component-plan.js +3 -2
  68. package/dist/component-plan.js.map +1 -1
  69. package/dist/component-scan.js +2 -2
  70. package/dist/component-scan.js.map +1 -1
  71. package/dist/config.d.ts.map +1 -1
  72. package/dist/config.js +5 -1
  73. package/dist/config.js.map +1 -1
  74. package/dist/cost.d.ts +2 -1
  75. package/dist/cost.d.ts.map +1 -1
  76. package/dist/cost.js +17 -8
  77. package/dist/cost.js.map +1 -1
  78. package/dist/custom-validation.d.ts.map +1 -1
  79. package/dist/custom-validation.js +2 -5
  80. package/dist/custom-validation.js.map +1 -1
  81. package/dist/deduplication/codex-review.d.ts.map +1 -1
  82. package/dist/deduplication/codex-review.js +8 -6
  83. package/dist/deduplication/codex-review.js.map +1 -1
  84. package/dist/deduplication/local.d.ts.map +1 -1
  85. package/dist/deduplication/local.js +5 -2
  86. package/dist/deduplication/local.js.map +1 -1
  87. package/dist/deduplication/retry.d.ts.map +1 -1
  88. package/dist/deduplication/retry.js +5 -0
  89. package/dist/deduplication/retry.js.map +1 -1
  90. package/dist/deduplication/scan.js +5 -1
  91. package/dist/deduplication/scan.js.map +1 -1
  92. package/dist/deep-scan.d.ts +6 -0
  93. package/dist/deep-scan.d.ts.map +1 -1
  94. package/dist/deep-scan.js +8 -6
  95. package/dist/deep-scan.js.map +1 -1
  96. package/dist/default-severity-rubric.d.ts +3 -0
  97. package/dist/default-severity-rubric.d.ts.map +1 -0
  98. package/dist/default-severity-rubric.js +67 -0
  99. package/dist/default-severity-rubric.js.map +1 -0
  100. package/dist/endor-findings.d.ts +7 -0
  101. package/dist/endor-findings.d.ts.map +1 -0
  102. package/dist/endor-findings.js +233 -0
  103. package/dist/endor-findings.js.map +1 -0
  104. package/dist/external-findings-import.d.ts +5 -0
  105. package/dist/external-findings-import.d.ts.map +1 -0
  106. package/dist/external-findings-import.js +38 -0
  107. package/dist/external-findings-import.js.map +1 -0
  108. package/dist/external-findings-local.d.ts +63 -0
  109. package/dist/external-findings-local.d.ts.map +1 -0
  110. package/dist/external-findings-local.js +337 -0
  111. package/dist/external-findings-local.js.map +1 -0
  112. package/dist/external-findings-publish.d.ts +73 -0
  113. package/dist/external-findings-publish.d.ts.map +1 -0
  114. package/dist/external-findings-publish.js +713 -0
  115. package/dist/external-findings-publish.js.map +1 -0
  116. package/dist/external-findings-read.d.ts +6 -0
  117. package/dist/external-findings-read.d.ts.map +1 -0
  118. package/dist/external-findings-read.js +88 -0
  119. package/dist/external-findings-read.js.map +1 -0
  120. package/dist/external-findings.d.ts +21 -0
  121. package/dist/external-findings.d.ts.map +1 -0
  122. package/dist/external-findings.js +2 -0
  123. package/dist/external-findings.js.map +1 -0
  124. package/dist/external-import-contract.d.ts +13 -0
  125. package/dist/external-import-contract.d.ts.map +1 -0
  126. package/dist/external-import-contract.js +254 -0
  127. package/dist/external-import-contract.js.map +1 -0
  128. package/dist/external-import-models.d.ts +362 -0
  129. package/dist/external-import-models.d.ts.map +1 -0
  130. package/dist/external-import-models.js +3 -0
  131. package/dist/external-import-models.js.map +1 -0
  132. package/dist/finding-workflow.d.ts +1 -1
  133. package/dist/finding-workflow.d.ts.map +1 -1
  134. package/dist/finding-workflow.js +2 -1
  135. package/dist/finding-workflow.js.map +1 -1
  136. package/dist/findings-import.d.ts.map +1 -1
  137. package/dist/findings-import.js +23 -3
  138. package/dist/findings-import.js.map +1 -1
  139. package/dist/github-advisories.d.ts +386 -0
  140. package/dist/github-advisories.d.ts.map +1 -0
  141. package/dist/github-advisories.js +131 -0
  142. package/dist/github-advisories.js.map +1 -0
  143. package/dist/github-findings.d.ts +10 -0
  144. package/dist/github-findings.d.ts.map +1 -0
  145. package/dist/github-findings.js +256 -0
  146. package/dist/github-findings.js.map +1 -0
  147. package/dist/host-protocol.d.ts +1 -0
  148. package/dist/host-protocol.d.ts.map +1 -1
  149. package/dist/host-protocol.js +1 -1
  150. package/dist/host-protocol.js.map +1 -1
  151. package/dist/hosted-remediation-protocol.d.ts +6 -0
  152. package/dist/hosted-remediation-protocol.d.ts.map +1 -0
  153. package/dist/hosted-remediation-protocol.js +32 -0
  154. package/dist/hosted-remediation-protocol.js.map +1 -0
  155. package/dist/hosted-remediation.d.ts +93 -0
  156. package/dist/hosted-remediation.d.ts.map +1 -0
  157. package/dist/hosted-remediation.js +124 -0
  158. package/dist/hosted-remediation.js.map +1 -0
  159. package/dist/hosted-scan.d.ts +16 -0
  160. package/dist/hosted-scan.d.ts.map +1 -1
  161. package/dist/hosted-scan.js +14 -2
  162. package/dist/hosted-scan.js.map +1 -1
  163. package/dist/import-scan.d.ts +1 -0
  164. package/dist/import-scan.d.ts.map +1 -1
  165. package/dist/import-scan.js +5 -1
  166. package/dist/import-scan.js.map +1 -1
  167. package/dist/index.d.ts +18 -1
  168. package/dist/index.d.ts.map +1 -1
  169. package/dist/index.js +10 -0
  170. package/dist/index.js.map +1 -1
  171. package/dist/multiscan.d.ts.map +1 -1
  172. package/dist/multiscan.js +3 -1
  173. package/dist/multiscan.js.map +1 -1
  174. package/dist/project-config-schema.d.ts +2 -0
  175. package/dist/project-config-schema.d.ts.map +1 -1
  176. package/dist/project-config-schema.js +1 -0
  177. package/dist/project-config-schema.js.map +1 -1
  178. package/dist/project-config.d.ts +1 -0
  179. package/dist/project-config.d.ts.map +1 -1
  180. package/dist/project-config.js +15 -9
  181. package/dist/project-config.js.map +1 -1
  182. package/dist/publish.d.ts +2 -0
  183. package/dist/publish.d.ts.map +1 -1
  184. package/dist/publish.js +9 -0
  185. package/dist/publish.js.map +1 -1
  186. package/dist/remediation.d.ts +69 -0
  187. package/dist/remediation.d.ts.map +1 -0
  188. package/dist/remediation.js +121 -0
  189. package/dist/remediation.js.map +1 -0
  190. package/dist/request-metadata.d.ts +17 -7
  191. package/dist/request-metadata.d.ts.map +1 -1
  192. package/dist/request-metadata.js +43 -8
  193. package/dist/request-metadata.js.map +1 -1
  194. package/dist/result.d.ts +4 -0
  195. package/dist/result.d.ts.map +1 -1
  196. package/dist/result.js +10 -0
  197. package/dist/result.js.map +1 -1
  198. package/dist/runtime.d.ts +1 -0
  199. package/dist/runtime.d.ts.map +1 -1
  200. package/dist/runtime.js +24 -15
  201. package/dist/runtime.js.map +1 -1
  202. package/dist/saved-scan-bootstrap.d.ts +1 -0
  203. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  204. package/dist/saved-scan-bootstrap.js +16 -4
  205. package/dist/saved-scan-bootstrap.js.map +1 -1
  206. package/dist/scan-activity.js +8 -8
  207. package/dist/scan-activity.js.map +1 -1
  208. package/dist/scan-comparison.d.ts.map +1 -1
  209. package/dist/scan-comparison.js +15 -9
  210. package/dist/scan-comparison.js.map +1 -1
  211. package/dist/scan-dashboard.d.ts.map +1 -1
  212. package/dist/scan-dashboard.js +12 -6
  213. package/dist/scan-dashboard.js.map +1 -1
  214. package/dist/scan-executor.d.ts +5 -1
  215. package/dist/scan-executor.d.ts.map +1 -1
  216. package/dist/scan-executor.js +9 -8
  217. package/dist/scan-executor.js.map +1 -1
  218. package/dist/scan-owner-suggestions.d.ts +8 -0
  219. package/dist/scan-owner-suggestions.d.ts.map +1 -0
  220. package/dist/scan-owner-suggestions.js +33 -0
  221. package/dist/scan-owner-suggestions.js.map +1 -0
  222. package/dist/{deep-progress.d.ts → scan-progress.d.ts} +15 -7
  223. package/dist/scan-progress.d.ts.map +1 -0
  224. package/dist/scan-progress.js +138 -0
  225. package/dist/scan-progress.js.map +1 -0
  226. package/dist/scan-settings.d.ts +1 -0
  227. package/dist/scan-settings.d.ts.map +1 -1
  228. package/dist/scan-settings.js +4 -0
  229. package/dist/scan-settings.js.map +1 -1
  230. package/dist/scanner-import.d.ts +20 -0
  231. package/dist/scanner-import.d.ts.map +1 -0
  232. package/dist/scanner-import.js +204 -0
  233. package/dist/scanner-import.js.map +1 -0
  234. package/dist/security-policy-diff.d.ts +2 -0
  235. package/dist/security-policy-diff.d.ts.map +1 -0
  236. package/dist/security-policy-diff.js +197 -0
  237. package/dist/security-policy-diff.js.map +1 -0
  238. package/dist/security-policy.d.ts +7 -3
  239. package/dist/security-policy.d.ts.map +1 -1
  240. package/dist/security-policy.js +11 -57
  241. package/dist/security-policy.js.map +1 -1
  242. package/dist/semgrep-findings.d.ts +9 -0
  243. package/dist/semgrep-findings.d.ts.map +1 -0
  244. package/dist/semgrep-findings.js +293 -0
  245. package/dist/semgrep-findings.js.map +1 -0
  246. package/dist/server/embeddings.d.ts.map +1 -1
  247. package/dist/server/embeddings.js +4 -0
  248. package/dist/server/embeddings.js.map +1 -1
  249. package/dist/server/sqlite-store.d.ts.map +1 -1
  250. package/dist/server/sqlite-store.js +14 -2
  251. package/dist/server/sqlite-store.js.map +1 -1
  252. package/dist/severity-review.d.ts +3 -0
  253. package/dist/severity-review.d.ts.map +1 -1
  254. package/dist/severity-review.js +19 -0
  255. package/dist/severity-review.js.map +1 -1
  256. package/dist/severity-store.js +11 -3
  257. package/dist/severity-store.js.map +1 -1
  258. package/dist/snyk-findings.d.ts +9 -0
  259. package/dist/snyk-findings.d.ts.map +1 -0
  260. package/dist/snyk-findings.js +349 -0
  261. package/dist/snyk-findings.js.map +1 -0
  262. package/dist/targets.d.ts +2 -2
  263. package/dist/targets.d.ts.map +1 -1
  264. package/dist/targets.js +12 -2
  265. package/dist/targets.js.map +1 -1
  266. package/dist/timestamps.d.ts +3 -0
  267. package/dist/timestamps.d.ts.map +1 -0
  268. package/dist/timestamps.js +14 -0
  269. package/dist/timestamps.js.map +1 -0
  270. package/dist/version.d.ts +1 -1
  271. package/dist/version.d.ts.map +1 -1
  272. package/dist/version.js +13 -2
  273. package/dist/version.js.map +1 -1
  274. package/dist/wiz-csv.d.ts +8 -0
  275. package/dist/wiz-csv.d.ts.map +1 -0
  276. package/dist/wiz-csv.js +116 -0
  277. package/dist/wiz-csv.js.map +1 -0
  278. package/dist/wiz-findings.d.ts +4 -0
  279. package/dist/wiz-findings.d.ts.map +1 -0
  280. package/dist/wiz-findings.js +460 -0
  281. package/dist/wiz-findings.js.map +1 -0
  282. package/dist/workbench-arguments.d.ts.map +1 -1
  283. package/dist/workbench-arguments.js +9 -3
  284. package/dist/workbench-arguments.js.map +1 -1
  285. package/dist/worker-progress.d.ts +11 -1
  286. package/dist/worker-progress.d.ts.map +1 -1
  287. package/dist/worker-progress.js +11 -1
  288. package/dist/worker-progress.js.map +1 -1
  289. package/docs/classify-severity-records.md +28 -10
  290. package/docs/cli.md +788 -46
  291. package/docs/findings-service.md +7 -2
  292. package/docs/hosted-remediation.md +134 -0
  293. package/docs/hosted-scans.md +20 -3
  294. package/package.json +9 -6
  295. package/schemas/external-findings.schema.json +1421 -0
  296. package/schemas/project-config.schema.json +4 -0
  297. package/dist/deep-progress.d.ts.map +0 -1
  298. package/dist/deep-progress.js +0 -92
  299. package/dist/deep-progress.js.map +0 -1
@@ -202,6 +202,69 @@ def _repository_origin(target: Path) -> tuple[str, str] | None:
202
202
  return (host.lower(), path) if host and path else None
203
203
 
204
204
 
205
+ SCAN_SUMMARY_QUERY = """
206
+ SELECT
207
+ scans.*,
208
+ progress.reportable_findings_count,
209
+ progress.scope_file_count,
210
+ progress.review_items_completed,
211
+ progress.review_items_total,
212
+ progress.updated_at AS progress_updated_at,
213
+ (
214
+ SELECT COUNT(*)
215
+ FROM finding_occurrences AS occurrences
216
+ WHERE occurrences.scan_id = scans.id
217
+ ) AS finding_count
218
+ FROM scans
219
+ JOIN scan_progress AS progress ON progress.scan_id = scans.id
220
+ """
221
+
222
+
223
+ def scan_summary(row: sqlite3.Row) -> dict[str, Any]:
224
+ return {
225
+ "completedAt": row["completed_at"],
226
+ "continuationThreadId": row["continuation_thread_id"],
227
+ **stored_scan_cost_fields(row["cost_json"]),
228
+ "findingCount": row["finding_count"],
229
+ "handoffStatus": row["handoff_status"],
230
+ "mode": row["mode"],
231
+ "model": row["model"],
232
+ "name": row["name"],
233
+ "parentScanId": row["parent_scan_id"],
234
+ "progress": {
235
+ "candidates": {"reportable": row["reportable_findings_count"]},
236
+ "coverage": {
237
+ "closedRows": row["review_items_completed"],
238
+ "filesTotal": row["scope_file_count"],
239
+ "worklistRows": row["review_items_total"],
240
+ },
241
+ "phase": row["phase"],
242
+ "status": "canceled" if row["canceled_at"] else row["status"],
243
+ "updatedAt": row["progress_updated_at"],
244
+ },
245
+ "recipeAvailable": row["recipe_json"] is not None,
246
+ "reasoningEffort": row["reasoning_effort"],
247
+ "scanDir": row["scan_dir"],
248
+ "scanId": row["id"],
249
+ "scope": row["scope"],
250
+ "startedAt": row["started_at"],
251
+ "targetId": row["target_id"],
252
+ "targetPath": row["target_path"],
253
+ "targetRevision": row["target_revision"],
254
+ "targetSummary": row["target_summary"],
255
+ "updatedAt": max(
256
+ row["updated_at"],
257
+ row["progress_updated_at"],
258
+ key=lambda value: (timestamp_key(value), value),
259
+ ),
260
+ **(
261
+ {"warnings": json.loads(row["completion_warnings_json"])}
262
+ if row["completion_warnings_json"] != "[]"
263
+ else {}
264
+ ),
265
+ }
266
+
267
+
205
268
  def list_scans(
206
269
  connection: sqlite3.Connection, args: argparse.Namespace | None = None
207
270
  ) -> dict[str, Any]:
@@ -281,20 +344,7 @@ def list_scans(
281
344
  values.extend((limit + 1, args.offset))
282
345
  rows = connection.execute(
283
346
  f"""
284
- SELECT
285
- scans.*,
286
- progress.reportable_findings_count,
287
- progress.scope_file_count,
288
- progress.review_items_completed,
289
- progress.review_items_total,
290
- progress.updated_at AS progress_updated_at,
291
- (
292
- SELECT COUNT(*)
293
- FROM finding_occurrences AS occurrences
294
- WHERE occurrences.scan_id = scans.id
295
- ) AS finding_count
296
- FROM scans
297
- JOIN scan_progress AS progress ON progress.scan_id = scans.id
347
+ {SCAN_SUMMARY_QUERY}
298
348
  {where}
299
349
  ORDER BY
300
350
  CASE WHEN scans.status = 'running' AND scans.canceled_at IS NULL THEN 0 ELSE 1 END,
@@ -305,53 +355,7 @@ def list_scans(
305
355
  """,
306
356
  values,
307
357
  ).fetchall()
308
- result = {
309
- "scans": [
310
- {
311
- "completedAt": row["completed_at"],
312
- "continuationThreadId": row["continuation_thread_id"],
313
- **stored_scan_cost_fields(row["cost_json"]),
314
- "findingCount": row["finding_count"],
315
- "handoffStatus": row["handoff_status"],
316
- "mode": row["mode"],
317
- "model": row["model"],
318
- "name": row["name"],
319
- "parentScanId": row["parent_scan_id"],
320
- "progress": {
321
- "candidates": {"reportable": row["reportable_findings_count"]},
322
- "coverage": {
323
- "closedRows": row["review_items_completed"],
324
- "filesTotal": row["scope_file_count"],
325
- "worklistRows": row["review_items_total"],
326
- },
327
- "phase": row["phase"],
328
- "status": "canceled" if row["canceled_at"] else row["status"],
329
- "updatedAt": row["progress_updated_at"],
330
- },
331
- "recipeAvailable": row["recipe_json"] is not None,
332
- "reasoningEffort": row["reasoning_effort"],
333
- "scanDir": row["scan_dir"],
334
- "scanId": row["id"],
335
- "scope": row["scope"],
336
- "startedAt": row["started_at"],
337
- "targetId": row["target_id"],
338
- "targetPath": row["target_path"],
339
- "targetRevision": row["target_revision"],
340
- "targetSummary": row["target_summary"],
341
- "updatedAt": max(
342
- row["updated_at"],
343
- row["progress_updated_at"],
344
- key=lambda value: (timestamp_key(value), value),
345
- ),
346
- **(
347
- {"warnings": json.loads(row["completion_warnings_json"])}
348
- if row["completion_warnings_json"] != "[]"
349
- else {}
350
- ),
351
- }
352
- for row in rows[:limit]
353
- ]
354
- }
358
+ result = {"scans": [scan_summary(row) for row in rows[:limit]]}
355
359
  if limit is not None:
356
360
  result.update(
357
361
  {
@@ -380,19 +384,19 @@ def list_unmatched_scan_pairs(
380
384
  ).fetchone()
381
385
  selected = [
382
386
  scan
383
- for scan in connection.execute(
384
- "SELECT * FROM scans WHERE status = 'complete' ORDER BY started_at, id"
385
- )
387
+ for scan in connection.execute("SELECT * FROM scans WHERE status = 'complete'")
386
388
  if _same_repository(scan, requested)
387
389
  ]
388
390
 
391
+ selected.sort(key=lambda scan: (timestamp_key(scan["started_at"]), scan["id"]))
392
+
389
393
  available = []
390
- for scan in selected:
394
+ for selected_index, scan in enumerate(selected):
391
395
  try:
392
396
  read_coverage(scan)
393
397
  except SystemExit:
394
398
  continue
395
- available.append(scan)
399
+ available.append((selected_index, scan))
396
400
 
397
401
  saved_pairs = {
398
402
  (row["before_scan_id"], row["after_scan_id"])
@@ -402,10 +406,10 @@ def list_unmatched_scan_pairs(
402
406
  skipped = 0
403
407
  matching_findings: dict[str, list[dict[str, Any]]] = {}
404
408
  known_links: list[sqlite3.Row] | None = None
405
- for index, after in enumerate(available):
409
+ for index, (selected_index, after) in enumerate(available):
406
410
  previous = [
407
411
  before
408
- for before in available[:index]
412
+ for _, before in available[:index]
409
413
  if args.force or (before["id"], after["id"]) not in saved_pairs
410
414
  ]
411
415
  skipped += index - len(previous)
@@ -425,11 +429,7 @@ def list_unmatched_scan_pairs(
425
429
  ]
426
430
  known_groups = _known_finding_groups(
427
431
  known_links,
428
- {
429
- scan["id"]
430
- for scan in selected
431
- if (scan["started_at"], scan["id"]) <= (after["started_at"], after["id"])
432
- },
432
+ {scan["id"] for scan in selected[: selected_index + 1]},
433
433
  )
434
434
  batches.append(
435
435
  {
@@ -667,14 +667,14 @@ def compare_scans(
667
667
  for pair in related
668
668
  ]
669
669
  if include_matching_inputs:
670
+ after_key = (timestamp_key(after["started_at"]), after["id"])
670
671
  known_scan_ids = {
671
672
  scan["id"]
672
673
  for scan in connection.execute(
673
- "SELECT * FROM scans WHERE status = 'complete' "
674
- "AND (started_at < ? OR (started_at = ? AND id <= ?))",
675
- (after["started_at"], after["started_at"], after["id"]),
674
+ "SELECT id, started_at, target_id, target_path FROM scans WHERE status = 'complete'"
676
675
  )
677
- if _same_repository(scan, after)
676
+ if (timestamp_key(scan["started_at"]), scan["id"]) <= after_key
677
+ and _same_repository(scan, after)
678
678
  }
679
679
  excluded_pairs = {(before["id"], after["id"]), (after["id"], before["id"])}
680
680
  known_groups = _known_finding_groups(
@@ -990,7 +990,8 @@ def finding_matches(
990
990
  )
991
991
  )
992
992
  known_scans = sorted(
993
- {(started_at, scan_id)} | {(row["started_at"], row["scan_id"]) for row in linked_rows}
993
+ {(started_at, scan_id)} | {(row["started_at"], row["scan_id"]) for row in linked_rows},
994
+ key=lambda scan: (timestamp_key(scan[0]), scan[1]),
994
995
  )
995
996
  included = {occurrence_id, *(row["occurrence_id"] for row in rows)}
996
997
  rows.extend(
@@ -127,6 +127,7 @@ def collect_scan_usage(
127
127
  rate_limits: dict[str, dict[str, Any]] = {}
128
128
  tokens_updated_at = None
129
129
  accepted_thread_ids: set[str] = set()
130
+ measured_thread_ids: set[str] = set()
130
131
  excluded_thread_ids: set[str] = set()
131
132
  for session in sessions:
132
133
  if session.parent_thread_id in excluded_thread_ids:
@@ -145,6 +146,10 @@ def collect_scan_usage(
145
146
  started_at=started_at,
146
147
  completed_at=stopped_at,
147
148
  completed_turn_id=completed_turn_id if session.thread_id == thread_id else None,
149
+ is_scan_owner=(
150
+ scan["mode"] == "deep"
151
+ and session.thread_id == scan["deep_scan_owner_thread_id"]
152
+ ),
148
153
  )
149
154
  except (OSError, UnicodeError, ValueError):
150
155
  missing_thread_ids.add(session.thread_id)
@@ -160,6 +165,13 @@ def collect_scan_usage(
160
165
  missing_thread_ids.add(session.thread_id)
161
166
  continue
162
167
  accepted_thread_ids.add(session.thread_id)
168
+ for key, snapshot in usage.rate_limits.items():
169
+ if key not in rate_limits or snapshot["observedAt"] > rate_limits[key]["observedAt"]:
170
+ rate_limits[key] = snapshot
171
+ if "token_usage_unavailable" in usage.warnings:
172
+ missing_thread_ids.add(session.thread_id)
173
+ continue
174
+ measured_thread_ids.add(session.thread_id)
163
175
  role = by_role["parent" if session.thread_id in parent_ids else "workers"]
164
176
  _add_token_usage(role, usage.tokens)
165
177
  role["threadCount"] += 1
@@ -167,19 +179,22 @@ def collect_scan_usage(
167
179
  tokens_updated_at = max(
168
180
  tokens_updated_at or usage.tokens_updated_at, usage.tokens_updated_at
169
181
  )
170
- for key, snapshot in usage.rate_limits.items():
171
- if key not in rate_limits or snapshot["observedAt"] > rate_limits[key]["observedAt"]:
172
- rate_limits[key] = snapshot
173
182
 
174
183
  if not accepted_thread_ids:
175
184
  return _unavailable_usage("scan_thread_unavailable", warnings=warnings)
185
+ if not measured_thread_ids:
186
+ return _unavailable_usage(
187
+ "token_usage_unavailable", warnings=warnings, rate_limits=rate_limits
188
+ )
176
189
 
177
190
  if any(
178
191
  usage["cachedInputTokens"] + usage["cacheWriteInputTokens"] > usage["inputTokens"]
179
192
  or usage["totalTokens"] != usage["inputTokens"] + usage["outputTokens"]
180
193
  for usage in by_role.values()
181
194
  ):
182
- return _unavailable_usage("token_breakdown_unavailable", warnings=warnings)
195
+ return _unavailable_usage(
196
+ "token_breakdown_unavailable", warnings=warnings, rate_limits=rate_limits
197
+ )
183
198
 
184
199
  if completed_turn_id is not None and tokens_updated_at is not None:
185
200
  stopped_at = max(stopped_at, tokens_updated_at)
@@ -187,7 +202,7 @@ def collect_scan_usage(
187
202
  "coverage": "partial" if missing_thread_ids or warnings else "complete",
188
203
  "source": "codex_rollout",
189
204
  **{key: sum(role[key] for role in by_role.values()) for key in TOKEN_FIELDS.values()},
190
- "threadCount": len(accepted_thread_ids),
205
+ "threadCount": len(measured_thread_ids),
191
206
  "byRole": by_role,
192
207
  "window": {"startedAt": started_at.isoformat(), "endedAt": stopped_at.isoformat()},
193
208
  "observedAt": observed_at.isoformat(),
@@ -228,8 +243,8 @@ def _scan_root_thread_ids(
228
243
  for row in connection.execute(
229
244
  """
230
245
  SELECT DISTINCT sdk_thread_id
231
- FROM deep_scan_workers
232
- WHERE scan_id = ? AND sdk_thread_id IS NOT NULL
246
+ FROM deep_scan_worker_threads
247
+ WHERE scan_id = ?
233
248
  ORDER BY sdk_thread_id
234
249
  """,
235
250
  (scan["id"],),
@@ -472,6 +487,7 @@ def _read_rollout_usage(
472
487
  started_at: datetime,
473
488
  completed_at: datetime | None,
474
489
  completed_turn_id: str | None = None,
490
+ is_scan_owner: bool = False,
475
491
  ) -> RolloutUsage:
476
492
  result = RolloutUsage(_empty_token_usage(), set(), None, {})
477
493
  total = result.tokens
@@ -484,6 +500,7 @@ def _read_rollout_usage(
484
500
  response_ids: set[str] = set()
485
501
  current_turn_id: str | None = None
486
502
  completed_turn_measured = False
503
+ direct_control_session = False
487
504
  started_turns: set[str] = set()
488
505
  open_turns: set[str] = set()
489
506
  closed_turns: set[str] = set()
@@ -525,6 +542,13 @@ def _read_rollout_usage(
525
542
  and not recorded_parent
526
543
  and not payload.get("forked_from_id")
527
544
  )
545
+ # prepareCliDeepScanSession creates this owner through app-server
546
+ # without a model turn, so its initial token usage is known zero.
547
+ direct_control_session = (
548
+ boundary_reached
549
+ and is_scan_owner
550
+ and payload.get("originator") == "codex_security_deep_scan"
551
+ )
528
552
  continue
529
553
 
530
554
  if not isinstance(payload, dict):
@@ -550,6 +574,19 @@ def _read_rollout_usage(
550
574
  if not boundary_reached:
551
575
  continue
552
576
  if event.get("type") == "event_msg" and payload.get("type") == "task_started":
577
+ # The same owner can resume as a model-backed coordinator. Only
578
+ # a provably post-scan turn leaves the original control zero intact.
579
+ task_started_at = _timestamp(event.get("timestamp"))
580
+ if (
581
+ completed_at is None
582
+ or task_started_at is None
583
+ or task_started_at <= completed_at
584
+ or (
585
+ completed_turn_id is not None
586
+ and payload.get("turn_id") == completed_turn_id
587
+ )
588
+ ):
589
+ direct_control_session = False
553
590
  if (
554
591
  completed_turn_id is not None
555
592
  and current_turn_id == completed_turn_id
@@ -722,11 +759,13 @@ def _read_rollout_usage(
722
759
  _add_token_usage(total, response_usage if response_usage is not None else legacy_usage)
723
760
  if not boundary_reached:
724
761
  warnings.add("thread_ownership_unavailable")
762
+ elif result.tokens_updated_at is None and not direct_control_session:
763
+ warnings.add("token_usage_unavailable")
725
764
  if completed_turn_id is not None:
726
765
  open_turns.discard(completed_turn_id)
727
766
  if open_turns:
728
767
  warnings.add("turn_in_progress")
729
- if boundary_reached and result.tokens_updated_at is None:
768
+ if boundary_reached and result.tokens_updated_at is None and not direct_control_session:
730
769
  warnings.add("token_record_missing")
731
770
  if closed_turns - measured_turns:
732
771
  warnings.add("token_record_missing")
@@ -846,7 +885,8 @@ def _usage_counts(usage: object) -> dict[str, int] | None:
846
885
  input_tokens = usage.get("input_tokens")
847
886
  cached_input_tokens = usage.get("cached_input_tokens", 0)
848
887
  if (
849
- cache_write == 0
888
+ type(cache_write) is int
889
+ and cache_write == 0
850
890
  and type(legacy_cache_write) is int
851
891
  and legacy_cache_write > 0
852
892
  and type(input_tokens) is int
@@ -890,18 +930,26 @@ def _timestamp(value: object) -> datetime | None:
890
930
  if value.endswith("Z")
891
931
  else datetime.fromisoformat(value)
892
932
  )
893
- except ValueError:
933
+ return parsed.astimezone(timezone.utc) if parsed.tzinfo is not None else None
934
+ except (ValueError, OverflowError):
894
935
  return None
895
- return parsed.astimezone(timezone.utc) if parsed.tzinfo is not None else None
896
936
 
897
937
 
898
- def _unavailable_usage(reason: str, *, warnings: set[str] | None = None) -> dict[str, Any]:
899
- return {
938
+ def _unavailable_usage(
939
+ reason: str,
940
+ *,
941
+ warnings: set[str] | None = None,
942
+ rate_limits: dict[str, dict[str, Any]] | None = None,
943
+ ) -> dict[str, Any]:
944
+ result: dict[str, Any] = {
900
945
  "coverage": "unavailable",
901
946
  "source": "codex_rollout",
902
947
  "threadCount": 0,
903
948
  "warnings": sorted({reason, *(warnings or set())}),
904
949
  }
950
+ if rate_limits:
951
+ result["accountRateLimits"] = [rate_limits[key] for key in sorted(rate_limits)]
952
+ return result
905
953
 
906
954
 
907
955
  def _reject_nonstandard_json_number(value: str) -> None:
@@ -24,6 +24,7 @@ from rank_preview import DEFAULT_PREVIEW_READ_BYTES, is_binary_sample
24
24
  from windows_scan_local_files import copy_directory_junction
25
25
  from workbench_constants import GIT_REPOSITORY_ENVIRONMENT
26
26
 
27
+ SOURCE_METADATA_DIRECTORIES = {".git", ".svn"}
27
28
  _WINDOWS = os.name == "nt"
28
29
 
29
30
 
@@ -447,10 +448,16 @@ def worktree_content_digest_for_context(
447
448
  ) -> str:
448
449
  digest = hashlib.sha256()
449
450
  update_digest_field(digest, b"format", b"codex-security-snapshot/v1")
451
+ source_pathspecs = [
452
+ f":(literal){pathspec}",
453
+ ":(top,glob,exclude)**/.svn",
454
+ ":(top,glob,exclude)**/.svn/**",
455
+ ]
450
456
  tracked_ok = _update_digest_field_from_git(
451
457
  digest,
452
458
  b"tracked-diff",
453
459
  repository,
460
+ "--no-literal-pathspecs",
454
461
  "diff",
455
462
  "--binary",
456
463
  "--full-index",
@@ -459,18 +466,19 @@ def worktree_content_digest_for_context(
459
466
  "--ignore-submodules=none",
460
467
  "HEAD",
461
468
  "--",
462
- pathspec,
469
+ *source_pathspecs,
463
470
  git_dir=git_dir,
464
471
  work_tree=work_tree,
465
472
  )
466
473
  untracked = git_bytes(
467
474
  repository,
475
+ "--no-literal-pathspecs",
468
476
  "ls-files",
469
477
  "--others",
470
478
  "--exclude-standard",
471
479
  "-z",
472
480
  "--",
473
- pathspec,
481
+ *source_pathspecs,
474
482
  git_dir=git_dir,
475
483
  work_tree=work_tree,
476
484
  )
@@ -673,6 +681,8 @@ def git_directory_snapshot_paths(target: Path) -> list[Path] | None:
673
681
  nested_worktrees: set[tuple[int, int]] = set()
674
682
  for entry in (entry for entry in listed.split(b"\0") if entry):
675
683
  relative = Path(os.fsdecode(entry[2:]))
684
+ if not SOURCE_METADATA_DIRECTORIES.isdisjoint(relative.parts):
685
+ continue
676
686
  if scope_depth:
677
687
  if len(relative.parts) <= scope_depth:
678
688
  continue
@@ -744,6 +754,8 @@ def git_directory_snapshot_paths(target: Path) -> list[Path] | None:
744
754
  while pending:
745
755
  children: list[Path] = []
746
756
  for path in pending:
757
+ if not SOURCE_METADATA_DIRECTORIES.isdisjoint(path.relative_to(target).parts):
758
+ continue
747
759
  try:
748
760
  path = _directory_link_boundary(target, path, linked_prefixes)
749
761
  metadata = path.lstat()
@@ -764,7 +776,7 @@ def git_directory_snapshot_paths(target: Path) -> list[Path] | None:
764
776
  continue
765
777
  candidates: dict[bytes, Path] = {}
766
778
  for path in children:
767
- if os.path.normcase(path.name) == ".git":
779
+ if os.path.normcase(path.name) in SOURCE_METADATA_DIRECTORIES:
768
780
  continue
769
781
  try:
770
782
  metadata = path.lstat()
@@ -812,7 +824,7 @@ def source_directory_snapshot_paths(
812
824
  parent = Path(directory)
813
825
  for name in directories[:]:
814
826
  path = parent / name
815
- if name == ".git" or path in excluded:
827
+ if name in SOURCE_METADATA_DIRECTORIES or path in excluded:
816
828
  directories.remove(name)
817
829
  continue
818
830
  paths.append(path)
@@ -820,7 +832,9 @@ def source_directory_snapshot_paths(
820
832
  if getattr(path.lstat(), "st_reparse_tag", 0) & 0x20000000:
821
833
  directories.remove(name)
822
834
  paths.extend(
823
- parent / name for name in files if name != ".git" and parent / name not in excluded
835
+ parent / name
836
+ for name in files
837
+ if name not in SOURCE_METADATA_DIRECTORIES and parent / name not in excluded
824
838
  )
825
839
  return sorted(paths)
826
840
 
@@ -843,7 +857,7 @@ def directory_content_digest(
843
857
  else git_directory_snapshot_paths(target)
844
858
  )
845
859
  if paths is None:
846
- paths = source_directory_snapshot_paths(target)
860
+ paths = source_directory_snapshot_paths(target, excluded)
847
861
  digest = hashlib.sha256()
848
862
  update_digest_field(digest, b"format", b"codex-security-directory/v1")
849
863
  for path in paths:
@@ -1058,7 +1072,7 @@ def git_target_metadata(target: Path) -> dict[str, Any]:
1058
1072
  branch = git_output(target, "symbolic-ref", "--quiet", "--short", "HEAD")
1059
1073
  metadata.update({"branch": branch, "detachedHead": revision is not None and branch is None})
1060
1074
  if revision is not None:
1061
- subject = git_bytes(target, "show", "-s", "--format=%s", "HEAD")
1075
+ subject = git_bytes(target, "show", "-s", "--no-show-signature", "--format=%s", "HEAD")
1062
1076
  metadata.update(
1063
1077
  {
1064
1078
  "commitSubject": (subject or b"").decode("utf-8", errors="replace").strip() or None,
@@ -69,16 +69,19 @@ SCAN_USAGE_TOKEN_KEYS = tuple(TOKEN_FIELDS.values())
69
69
 
70
70
  def _valid_legacy_scan_cost(cost: object) -> bool:
71
71
  token_keys = ("inputTokens", "cachedInputTokens", "cacheWriteInputTokens", "outputTokens")
72
- return (
73
- isinstance(cost, dict)
74
- and isinstance(cost.get("model"), str)
75
- and bool(cost["model"])
76
- and all(type(cost.get(key)) is int and cost[key] >= 0 for key in token_keys)
77
- and cost["cachedInputTokens"] + cost["cacheWriteInputTokens"] <= cost["inputTokens"]
78
- and type(cost.get("estimatedUsd")) in (int, float)
79
- and math.isfinite(cost["estimatedUsd"])
80
- and cost["estimatedUsd"] >= 0
81
- )
72
+ try:
73
+ return (
74
+ isinstance(cost, dict)
75
+ and isinstance(cost.get("model"), str)
76
+ and bool(cost["model"])
77
+ and all(type(cost.get(key)) is int and cost[key] >= 0 for key in token_keys)
78
+ and cost["cachedInputTokens"] + cost["cacheWriteInputTokens"] <= cost["inputTokens"]
79
+ and type(cost.get("estimatedUsd")) in (int, float)
80
+ and math.isfinite(cost["estimatedUsd"])
81
+ and cost["estimatedUsd"] >= 0
82
+ )
83
+ except OverflowError:
84
+ return False
82
85
 
83
86
 
84
87
  def _valid_measured_scan_usage(usage: object) -> bool:
@@ -87,7 +90,7 @@ def _valid_measured_scan_usage(usage: object) -> bool:
87
90
  coverage = usage.get("coverage")
88
91
  thread_count = usage.get("threadCount")
89
92
  if (
90
- coverage not in {"complete", "partial", "unavailable"}
93
+ coverage not in ("complete", "partial", "unavailable")
91
94
  or usage.get("source") != "codex_rollout"
92
95
  or type(thread_count) is not int
93
96
  or thread_count < 0
@@ -117,9 +120,15 @@ def _valid_measured_scan_usage(usage: object) -> bool:
117
120
  or len(set(warnings)) != len(warnings)
118
121
  ):
119
122
  return False
123
+ if "accountRateLimits" in usage:
124
+ limits = usage["accountRateLimits"]
125
+ if not isinstance(limits, list) or not all(
126
+ valid_account_rate_limit(limit) for limit in limits
127
+ ):
128
+ return False
120
129
  if coverage == "unavailable":
121
130
  return thread_count == 0 and set(usage).issubset(
122
- {"coverage", "source", "threadCount", "warnings", "completion"}
131
+ {"coverage", "source", "threadCount", "warnings", "completion", "accountRateLimits"}
123
132
  )
124
133
 
125
134
  allowed_keys = {
@@ -174,12 +183,6 @@ def _valid_measured_scan_usage(usage: object) -> bool:
174
183
  return False
175
184
  if any(sum(role[key] for role in roles.values()) != usage[key] for key in keys):
176
185
  return False
177
- if "accountRateLimits" in usage:
178
- limits = usage["accountRateLimits"]
179
- if not isinstance(limits, list) or not all(
180
- valid_account_rate_limit(limit) for limit in limits
181
- ):
182
- return False
183
186
  return True
184
187
 
185
188
 
@@ -415,5 +415,31 @@
415
415
  "version": 50,
416
416
  "name": "persist authorized source excerpt scopes",
417
417
  "statements": ["ALTER TABLE scans ADD COLUMN source_scopes_json TEXT;"]
418
+ },
419
+ {
420
+ "version": 51,
421
+ "name": "preserve deep scan worker thread history",
422
+ "statements": [
423
+ "CREATE TABLE deep_scan_worker_threads (\n scan_id TEXT NOT NULL REFERENCES scans(id) ON DELETE CASCADE,\n worker_id TEXT NOT NULL,\n sdk_thread_id TEXT NOT NULL,\n PRIMARY KEY (scan_id, worker_id, sdk_thread_id)\n);",
424
+ "INSERT INTO deep_scan_worker_threads (scan_id, worker_id, sdk_thread_id)\nSELECT scan_id, id, sdk_thread_id FROM deep_scan_workers\nWHERE sdk_thread_id IS NOT NULL;",
425
+ "CREATE TRIGGER record_deep_scan_worker_thread_insert\nAFTER INSERT ON deep_scan_workers\nWHEN NEW.sdk_thread_id IS NOT NULL\nBEGIN\n INSERT OR IGNORE INTO deep_scan_worker_threads (scan_id, worker_id, sdk_thread_id)\n VALUES (NEW.scan_id, NEW.id, NEW.sdk_thread_id);\nEND;",
426
+ "CREATE TRIGGER record_deep_scan_worker_thread_update\nAFTER UPDATE OF sdk_thread_id ON deep_scan_workers\nWHEN NEW.sdk_thread_id IS NOT NULL\nBEGIN\n INSERT OR IGNORE INTO deep_scan_worker_threads (scan_id, worker_id, sdk_thread_id)\n VALUES (NEW.scan_id, NEW.id, NEW.sdk_thread_id);\nEND;"
427
+ ]
428
+ },
429
+ {
430
+ "version": 52,
431
+ "name": "record severity classification review counts",
432
+ "statements": [
433
+ "ALTER TABLE finding_severity_assessments ADD COLUMN classification_runs INTEGER CHECK (classification_runs BETWEEN 1 AND 10);",
434
+ "ALTER TABLE scan_severity_assessments ADD COLUMN classification_runs INTEGER CHECK (classification_runs BETWEEN 1 AND 10);",
435
+ "ALTER TABLE scan_severity_classifications ADD COLUMN classification_runs INTEGER CHECK (classification_runs BETWEEN 1 AND 10);"
436
+ ]
437
+ },
438
+ {
439
+ "version": 53,
440
+ "name": "store external source findings without assessments",
441
+ "statements": [
442
+ "CREATE TABLE external_source_reports (\n id TEXT PRIMARY KEY,\n repository TEXT NOT NULL,\n provider TEXT NOT NULL,\n source_key TEXT NOT NULL,\n source_finding_id TEXT NOT NULL,\n evidence_json TEXT NOT NULL,\n version INTEGER NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n UNIQUE (repository, provider, source_key, source_finding_id)\n);"
443
+ ]
418
444
  }
419
445
  ]