@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
@@ -19,8 +19,9 @@ from report_projection import SEVERITY_ORDER
19
19
  from workbench_constants import ARTIFACTS, FINDINGS_PAGE_MAX
20
20
  from workbench_scan_start import scan_target_identity
21
21
  from workbench_scan_usage import stored_scan_cost_fields
22
+ from workbench_source_scopes import public_scan_recipe
22
23
  from workbench_target import git_output, require_scan_target_identity
23
- from workbench_validation import reject_non_finite_json, timestamp_key
24
+ from workbench_validation import timestamp_key
24
25
 
25
26
 
26
27
  def rename_scan(connection: sqlite3.Connection, scan: sqlite3.Row, name: str) -> dict[str, Any]:
@@ -37,7 +38,7 @@ def scan_recipe(scan: sqlite3.Row) -> dict[str, Any]:
37
38
  raise SystemExit("This scan does not have a saved launch recipe.")
38
39
  return {
39
40
  "parentScanId": scan["parent_scan_id"],
40
- "recipe": json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json),
41
+ "recipe": public_scan_recipe(scan),
41
42
  "scanId": scan["id"],
42
43
  }
43
44
 
@@ -201,6 +202,69 @@ def _repository_origin(target: Path) -> tuple[str, str] | None:
201
202
  return (host.lower(), path) if host and path else None
202
203
 
203
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
+
204
268
  def list_scans(
205
269
  connection: sqlite3.Connection, args: argparse.Namespace | None = None
206
270
  ) -> dict[str, Any]:
@@ -280,20 +344,7 @@ def list_scans(
280
344
  values.extend((limit + 1, args.offset))
281
345
  rows = connection.execute(
282
346
  f"""
283
- SELECT
284
- scans.*,
285
- progress.reportable_findings_count,
286
- progress.scope_file_count,
287
- progress.review_items_completed,
288
- progress.review_items_total,
289
- progress.updated_at AS progress_updated_at,
290
- (
291
- SELECT COUNT(*)
292
- FROM finding_occurrences AS occurrences
293
- WHERE occurrences.scan_id = scans.id
294
- ) AS finding_count
295
- FROM scans
296
- JOIN scan_progress AS progress ON progress.scan_id = scans.id
347
+ {SCAN_SUMMARY_QUERY}
297
348
  {where}
298
349
  ORDER BY
299
350
  CASE WHEN scans.status = 'running' AND scans.canceled_at IS NULL THEN 0 ELSE 1 END,
@@ -304,53 +355,7 @@ def list_scans(
304
355
  """,
305
356
  values,
306
357
  ).fetchall()
307
- result = {
308
- "scans": [
309
- {
310
- "completedAt": row["completed_at"],
311
- "continuationThreadId": row["continuation_thread_id"],
312
- **stored_scan_cost_fields(row["cost_json"]),
313
- "findingCount": row["finding_count"],
314
- "handoffStatus": row["handoff_status"],
315
- "mode": row["mode"],
316
- "model": row["model"],
317
- "name": row["name"],
318
- "parentScanId": row["parent_scan_id"],
319
- "progress": {
320
- "candidates": {"reportable": row["reportable_findings_count"]},
321
- "coverage": {
322
- "closedRows": row["review_items_completed"],
323
- "filesTotal": row["scope_file_count"],
324
- "worklistRows": row["review_items_total"],
325
- },
326
- "phase": row["phase"],
327
- "status": "canceled" if row["canceled_at"] else row["status"],
328
- "updatedAt": row["progress_updated_at"],
329
- },
330
- "recipeAvailable": row["recipe_json"] is not None,
331
- "reasoningEffort": row["reasoning_effort"],
332
- "scanDir": row["scan_dir"],
333
- "scanId": row["id"],
334
- "scope": row["scope"],
335
- "startedAt": row["started_at"],
336
- "targetId": row["target_id"],
337
- "targetPath": row["target_path"],
338
- "targetRevision": row["target_revision"],
339
- "targetSummary": row["target_summary"],
340
- "updatedAt": max(
341
- row["updated_at"],
342
- row["progress_updated_at"],
343
- key=lambda value: (timestamp_key(value), value),
344
- ),
345
- **(
346
- {"warnings": json.loads(row["completion_warnings_json"])}
347
- if row["completion_warnings_json"] != "[]"
348
- else {}
349
- ),
350
- }
351
- for row in rows[:limit]
352
- ]
353
- }
358
+ result = {"scans": [scan_summary(row) for row in rows[:limit]]}
354
359
  if limit is not None:
355
360
  result.update(
356
361
  {
@@ -379,19 +384,19 @@ def list_unmatched_scan_pairs(
379
384
  ).fetchone()
380
385
  selected = [
381
386
  scan
382
- for scan in connection.execute(
383
- "SELECT * FROM scans WHERE status = 'complete' ORDER BY started_at, id"
384
- )
387
+ for scan in connection.execute("SELECT * FROM scans WHERE status = 'complete'")
385
388
  if _same_repository(scan, requested)
386
389
  ]
387
390
 
391
+ selected.sort(key=lambda scan: (timestamp_key(scan["started_at"]), scan["id"]))
392
+
388
393
  available = []
389
- for scan in selected:
394
+ for selected_index, scan in enumerate(selected):
390
395
  try:
391
396
  read_coverage(scan)
392
397
  except SystemExit:
393
398
  continue
394
- available.append(scan)
399
+ available.append((selected_index, scan))
395
400
 
396
401
  saved_pairs = {
397
402
  (row["before_scan_id"], row["after_scan_id"])
@@ -401,10 +406,10 @@ def list_unmatched_scan_pairs(
401
406
  skipped = 0
402
407
  matching_findings: dict[str, list[dict[str, Any]]] = {}
403
408
  known_links: list[sqlite3.Row] | None = None
404
- for index, after in enumerate(available):
409
+ for index, (selected_index, after) in enumerate(available):
405
410
  previous = [
406
411
  before
407
- for before in available[:index]
412
+ for _, before in available[:index]
408
413
  if args.force or (before["id"], after["id"]) not in saved_pairs
409
414
  ]
410
415
  skipped += index - len(previous)
@@ -424,11 +429,7 @@ def list_unmatched_scan_pairs(
424
429
  ]
425
430
  known_groups = _known_finding_groups(
426
431
  known_links,
427
- {
428
- scan["id"]
429
- for scan in selected
430
- if (scan["started_at"], scan["id"]) <= (after["started_at"], after["id"])
431
- },
432
+ {scan["id"] for scan in selected[: selected_index + 1]},
432
433
  )
433
434
  batches.append(
434
435
  {
@@ -666,14 +667,14 @@ def compare_scans(
666
667
  for pair in related
667
668
  ]
668
669
  if include_matching_inputs:
670
+ after_key = (timestamp_key(after["started_at"]), after["id"])
669
671
  known_scan_ids = {
670
672
  scan["id"]
671
673
  for scan in connection.execute(
672
- "SELECT * FROM scans WHERE status = 'complete' "
673
- "AND (started_at < ? OR (started_at = ? AND id <= ?))",
674
- (after["started_at"], after["started_at"], after["id"]),
674
+ "SELECT id, started_at, target_id, target_path FROM scans WHERE status = 'complete'"
675
675
  )
676
- if _same_repository(scan, after)
676
+ if (timestamp_key(scan["started_at"]), scan["id"]) <= after_key
677
+ and _same_repository(scan, after)
677
678
  }
678
679
  excluded_pairs = {(before["id"], after["id"]), (after["id"], before["id"])}
679
680
  known_groups = _known_finding_groups(
@@ -989,7 +990,8 @@ def finding_matches(
989
990
  )
990
991
  )
991
992
  known_scans = sorted(
992
- {(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]),
993
995
  )
994
996
  included = {occurrence_id, *(row["occurrence_id"] for row in rows)}
995
997
  rows.extend(
@@ -13,6 +13,7 @@ from collections.abc import Callable, Iterator
13
13
  from contextlib import contextmanager
14
14
  from datetime import datetime, timezone
15
15
  from pathlib import Path
16
+ from typing import Any
16
17
 
17
18
  # Some plugin hosts launch Python with safe-path isolation enabled.
18
19
  sys.path.insert(0, str(Path(__file__).resolve().parent))
@@ -160,8 +161,13 @@ def archive_scan(
160
161
  archived_scan_dir.rmdir()
161
162
  scan_dir.rename(archived_scan_dir)
162
163
  moved = True
163
- scan_dir.mkdir(mode=0o700)
164
- scan_dir.chmod(0o700)
164
+ if os.name == "nt":
165
+ from windows_scan_local_files import create_directory_with_same_dacl
166
+
167
+ create_directory_with_same_dacl(scan_dir, archived_scan_dir)
168
+ else:
169
+ scan_dir.mkdir(mode=0o700)
170
+ scan_dir.chmod(0o700)
165
171
  if previous_scan is not None:
166
172
  connection.execute(
167
173
  "UPDATE scans SET scan_dir = ?, updated_at = ? WHERE id = ?",
@@ -221,6 +227,7 @@ def insert_running_scan(
221
227
  scope: str,
222
228
  diff_target: dict[str, str] | None,
223
229
  target_identity: tuple[str, str | None, int | str, int | str],
230
+ source_scopes: dict[str, Any],
224
231
  target_root: Path,
225
232
  target_summary: str | None,
226
233
  scope_file_count: int,
@@ -244,11 +251,11 @@ def insert_running_scan(
244
251
  """
245
252
  INSERT INTO scans (
246
253
  id, workspace_id, target_id, target_path, target_revision, target_snapshot_digest,
247
- target_device, target_inode, scope, mode, user_context,
254
+ target_device, target_inode, source_scopes_json, scope, mode, user_context,
248
255
  deep_scan_owner_thread_id, diff_target_kind, diff_base_revision,
249
256
  diff_head_revision, diff_content_digest, target_summary, scan_dir, model,
250
257
  reasoning_effort, status, phase, handoff_status, started_at, created_at, updated_at
251
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
258
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
252
259
  'running', 'preflight', ?, ?, ?, ?)
253
260
  """,
254
261
  (
@@ -257,6 +264,7 @@ def insert_running_scan(
257
264
  workspace["target_id"],
258
265
  str(target),
259
266
  *target_identity,
267
+ json.dumps(source_scopes, allow_nan=False, separators=(",", ":"), sort_keys=True),
260
268
  scope,
261
269
  workspace["default_mode"],
262
270
  user_context,