@openai/codex-security 0.3.0 → 0.5.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 (244) hide show
  1. package/README.md +45 -9
  2. package/_bundled_plugin/.codex-plugin/plugin.json +5 -5
  3. package/_bundled_plugin/.mcp.json +1 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  6. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  7. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +13 -20
  8. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  9. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  10. package/_bundled_plugin/references/core-scan.md +2 -0
  11. package/_bundled_plugin/references/final-report.md +5 -1
  12. package/_bundled_plugin/references/investigation-time-budget.md +11 -0
  13. package/_bundled_plugin/references/sarif-adapter.md +1 -0
  14. package/_bundled_plugin/references/scan-prologue.md +2 -6
  15. package/_bundled_plugin/references/scan-runtime.md +15 -0
  16. package/_bundled_plugin/references/threat-model.md +2 -0
  17. package/_bundled_plugin/schemas/coverage.schema.json +45 -126
  18. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +5 -1
  19. package/_bundled_plugin/schemas/findings.schema.json +140 -427
  20. package/_bundled_plugin/schemas/patch-risk-assessment.schema.json +106 -119
  21. package/_bundled_plugin/schemas/scan-manifest.schema.json +73 -188
  22. package/_bundled_plugin/scripts/deep_scan_workbench.py +7 -0
  23. package/_bundled_plugin/scripts/finalize_scan_contract.py +87 -49
  24. package/_bundled_plugin/scripts/finding_preview.py +5 -3
  25. package/_bundled_plugin/scripts/generate_rank_input.py +26 -106
  26. package/_bundled_plugin/scripts/launch_codex_security_mcp +39 -4
  27. package/_bundled_plugin/scripts/report_projection.py +35 -13
  28. package/_bundled_plugin/scripts/snapshot_sqlite.py +7 -0
  29. package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -1
  30. package/_bundled_plugin/scripts/workbench_cli.py +9 -9
  31. package/_bundled_plugin/scripts/workbench_constants.py +4 -0
  32. package/_bundled_plugin/scripts/workbench_db.py +103 -45
  33. package/_bundled_plugin/scripts/workbench_progress.py +0 -50
  34. package/_bundled_plugin/scripts/workbench_publication.py +216 -247
  35. package/_bundled_plugin/scripts/workbench_scan_history.py +3 -2
  36. package/_bundled_plugin/scripts/workbench_scan_start.py +12 -4
  37. package/_bundled_plugin/scripts/workbench_scan_usage.py +360 -37
  38. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  39. package/_bundled_plugin/scripts/workbench_source_excerpt.py +74 -51
  40. package/_bundled_plugin/scripts/workbench_source_scopes.py +388 -0
  41. package/_bundled_plugin/scripts/workbench_target.py +7 -5
  42. package/_bundled_plugin/scripts/workbench_validation.py +52 -2
  43. package/_bundled_plugin/shared/workbench-history-repairs.json +19 -0
  44. package/_bundled_plugin/shared/workbench-migrations.json +22 -0
  45. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +1 -1
  46. package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +1 -1
  47. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +4 -2
  48. package/_bundled_plugin/skills/security-diff-scan/agents/openai.yaml +1 -1
  49. package/_bundled_plugin/skills/security-scan/SKILL.md +4 -2
  50. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +1 -1
  51. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -3
  52. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +2 -0
  53. package/_bundled_plugin/skills/track-findings/SKILL.md +8 -4
  54. package/_bundled_plugin/skills/track-findings/agents/openai.yaml +1 -1
  55. package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +1 -1
  56. package/dist/api.d.ts +6 -2
  57. package/dist/api.d.ts.map +1 -1
  58. package/dist/api.js +266 -39
  59. package/dist/api.js.map +1 -1
  60. package/dist/artifact-export.d.ts +2 -1
  61. package/dist/artifact-export.d.ts.map +1 -1
  62. package/dist/artifact-export.js +38 -23
  63. package/dist/artifact-export.js.map +1 -1
  64. package/dist/classify-severity-records.d.ts +76 -0
  65. package/dist/classify-severity-records.d.ts.map +1 -0
  66. package/dist/classify-severity-records.js +141 -0
  67. package/dist/classify-severity-records.js.map +1 -0
  68. package/dist/classify-severity.d.ts +1 -23
  69. package/dist/classify-severity.d.ts.map +1 -1
  70. package/dist/classify-severity.js +3 -24
  71. package/dist/classify-severity.js.map +1 -1
  72. package/dist/cli-help.d.ts.map +1 -1
  73. package/dist/cli-help.js +2 -0
  74. package/dist/cli-help.js.map +1 -1
  75. package/dist/cli.d.ts +4 -2
  76. package/dist/cli.d.ts.map +1 -1
  77. package/dist/cli.js +148 -149
  78. package/dist/cli.js.map +1 -1
  79. package/dist/cloud-publish.js +1 -1
  80. package/dist/cloud-publish.js.map +1 -1
  81. package/dist/codex-sdk-environment.js +1 -1
  82. package/dist/codex-sdk-environment.js.map +1 -1
  83. package/dist/component-plan.js +1 -1
  84. package/dist/component-plan.js.map +1 -1
  85. package/dist/component-scan.d.ts.map +1 -1
  86. package/dist/component-scan.js +5 -4
  87. package/dist/component-scan.js.map +1 -1
  88. package/dist/config.d.ts +12 -0
  89. package/dist/config.d.ts.map +1 -1
  90. package/dist/config.js +10 -4
  91. package/dist/config.js.map +1 -1
  92. package/dist/contract.d.ts +6 -0
  93. package/dist/contract.d.ts.map +1 -1
  94. package/dist/contract.js +69 -20
  95. package/dist/contract.js.map +1 -1
  96. package/dist/cost-model.d.ts.map +1 -1
  97. package/dist/cost-model.js +7 -2
  98. package/dist/cost-model.js.map +1 -1
  99. package/dist/custom-validation-prompt.js +3 -3
  100. package/dist/custom-validation-prompt.js.map +1 -1
  101. package/dist/deduplication/codex-review.d.ts +1 -5
  102. package/dist/deduplication/codex-review.d.ts.map +1 -1
  103. package/dist/deduplication/codex-review.js +2 -2
  104. package/dist/deduplication/codex-review.js.map +1 -1
  105. package/dist/deduplication/deduplication-prompts.d.ts +1 -1
  106. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  107. package/dist/deduplication/deduplication-prompts.js +2 -2
  108. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  109. package/dist/deduplication/deduplication-reviewer.d.ts +1 -1
  110. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  111. package/dist/deduplication/deduplication-reviewer.js +1 -1
  112. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  113. package/dist/deduplication/records-protocol.d.ts +3 -8
  114. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  115. package/dist/deduplication/records-protocol.js +11 -171
  116. package/dist/deduplication/records-protocol.js.map +1 -1
  117. package/dist/deduplication/records.js +1 -1
  118. package/dist/deduplication/records.js.map +1 -1
  119. package/dist/deduplication/scan.d.ts.map +1 -1
  120. package/dist/deduplication/scan.js +10 -9
  121. package/dist/deduplication/scan.js.map +1 -1
  122. package/dist/deep-config.d.ts +4 -1
  123. package/dist/deep-config.d.ts.map +1 -1
  124. package/dist/deep-config.js +21 -1
  125. package/dist/deep-config.js.map +1 -1
  126. package/dist/deep-progress.d.ts +15 -1
  127. package/dist/deep-progress.d.ts.map +1 -1
  128. package/dist/deep-progress.js +15 -16
  129. package/dist/deep-progress.js.map +1 -1
  130. package/dist/executable-path.d.ts +2 -0
  131. package/dist/executable-path.d.ts.map +1 -0
  132. package/dist/executable-path.js +12 -0
  133. package/dist/executable-path.js.map +1 -0
  134. package/dist/feedback.d.ts +1 -4
  135. package/dist/feedback.d.ts.map +1 -1
  136. package/dist/feedback.js +1 -1
  137. package/dist/feedback.js.map +1 -1
  138. package/dist/findings-import.d.ts +1 -1
  139. package/dist/findings-import.d.ts.map +1 -1
  140. package/dist/findings-import.js +3 -3
  141. package/dist/findings-import.js.map +1 -1
  142. package/dist/git-remote.d.ts +10 -0
  143. package/dist/git-remote.d.ts.map +1 -0
  144. package/dist/git-remote.js +24 -0
  145. package/dist/git-remote.js.map +1 -0
  146. package/dist/github.d.ts.map +1 -1
  147. package/dist/github.js +5 -7
  148. package/dist/github.js.map +1 -1
  149. package/dist/host-protocol.d.ts +19 -0
  150. package/dist/host-protocol.d.ts.map +1 -0
  151. package/dist/host-protocol.js +270 -0
  152. package/dist/host-protocol.js.map +1 -0
  153. package/dist/host-records-protocol.d.ts +15 -0
  154. package/dist/host-records-protocol.d.ts.map +1 -0
  155. package/dist/host-records-protocol.js +15 -0
  156. package/dist/host-records-protocol.js.map +1 -0
  157. package/dist/hosted-scan-protocol.d.ts +4 -0
  158. package/dist/hosted-scan-protocol.d.ts.map +1 -0
  159. package/dist/hosted-scan-protocol.js +25 -0
  160. package/dist/hosted-scan-protocol.js.map +1 -0
  161. package/dist/hosted-scan.d.ts +112 -0
  162. package/dist/hosted-scan.d.ts.map +1 -0
  163. package/dist/hosted-scan.js +260 -0
  164. package/dist/hosted-scan.js.map +1 -0
  165. package/dist/index.d.ts +7 -0
  166. package/dist/index.d.ts.map +1 -1
  167. package/dist/index.js +3 -0
  168. package/dist/index.js.map +1 -1
  169. package/dist/knowledge-base.d.ts.map +1 -1
  170. package/dist/knowledge-base.js +87 -7
  171. package/dist/knowledge-base.js.map +1 -1
  172. package/dist/multiscan.d.ts.map +1 -1
  173. package/dist/multiscan.js +108 -36
  174. package/dist/multiscan.js.map +1 -1
  175. package/dist/patch-publication.d.ts +26 -0
  176. package/dist/patch-publication.d.ts.map +1 -0
  177. package/dist/patch-publication.js +105 -0
  178. package/dist/patch-publication.js.map +1 -0
  179. package/dist/patch-tui.d.ts.map +1 -1
  180. package/dist/patch-tui.js +4 -1
  181. package/dist/patch-tui.js.map +1 -1
  182. package/dist/project-config-schema.d.ts +2 -0
  183. package/dist/project-config-schema.d.ts.map +1 -1
  184. package/dist/project-config-schema.js +1 -0
  185. package/dist/project-config-schema.js.map +1 -1
  186. package/dist/project-config.d.ts +1 -0
  187. package/dist/project-config.d.ts.map +1 -1
  188. package/dist/project-config.js +16 -6
  189. package/dist/project-config.js.map +1 -1
  190. package/dist/publication-store.d.ts.map +1 -1
  191. package/dist/publication-store.js +73 -63
  192. package/dist/publication-store.js.map +1 -1
  193. package/dist/publication.d.ts +0 -2
  194. package/dist/publication.d.ts.map +1 -1
  195. package/dist/publication.js +135 -24
  196. package/dist/publication.js.map +1 -1
  197. package/dist/publish.d.ts.map +1 -1
  198. package/dist/publish.js +39 -25
  199. package/dist/publish.js.map +1 -1
  200. package/dist/runtime.d.ts +5 -2
  201. package/dist/runtime.d.ts.map +1 -1
  202. package/dist/runtime.js +86 -58
  203. package/dist/runtime.js.map +1 -1
  204. package/dist/scan-executor.d.ts +104 -0
  205. package/dist/scan-executor.d.ts.map +1 -0
  206. package/dist/scan-executor.js +62 -0
  207. package/dist/scan-executor.js.map +1 -0
  208. package/dist/scan-settings.d.ts +1 -0
  209. package/dist/scan-settings.d.ts.map +1 -1
  210. package/dist/scan-settings.js +7 -1
  211. package/dist/scan-settings.js.map +1 -1
  212. package/dist/scan-time-budget.d.ts +9 -0
  213. package/dist/scan-time-budget.d.ts.map +1 -0
  214. package/dist/scan-time-budget.js +16 -0
  215. package/dist/scan-time-budget.js.map +1 -0
  216. package/dist/severity-review.d.ts +29 -0
  217. package/dist/severity-review.d.ts.map +1 -0
  218. package/dist/severity-review.js +47 -0
  219. package/dist/severity-review.js.map +1 -0
  220. package/dist/targets.d.ts.map +1 -1
  221. package/dist/targets.js +17 -25
  222. package/dist/targets.js.map +1 -1
  223. package/dist/validation-records.d.ts +38 -0
  224. package/dist/validation-records.d.ts.map +1 -0
  225. package/dist/validation-records.js +76 -0
  226. package/dist/validation-records.js.map +1 -0
  227. package/dist/version.d.ts.map +1 -1
  228. package/dist/version.js +4 -2
  229. package/dist/version.js.map +1 -1
  230. package/dist/worker-progress.d.ts +43 -15
  231. package/dist/worker-progress.d.ts.map +1 -1
  232. package/dist/worker-progress.js +22 -80
  233. package/dist/worker-progress.js.map +1 -1
  234. package/docs/classify-severity-records.md +89 -0
  235. package/docs/cli.md +281 -35
  236. package/docs/hosted-scans.md +242 -0
  237. package/docs/validate-records.md +69 -0
  238. package/package.json +18 -14
  239. package/schemas/hosted-scan-v2.fixture.json +145 -0
  240. package/schemas/project-config.schema.json +7 -1
  241. package/_bundled_plugin/preflight/capability-profiles.toml +0 -76
  242. package/_bundled_plugin/references/config-preflight.md +0 -93
  243. package/_bundled_plugin/references/desktop-config-preflight.md +0 -11
  244. package/_bundled_plugin/scripts/config_preflight.py +0 -911
@@ -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,
@@ -1162,9 +1163,43 @@ def complete_scan(
1162
1163
  cost_json,
1163
1164
  prepare_only=prepare_only,
1164
1165
  thread_id=getattr(args, "thread_id", None),
1166
+ turn_id=getattr(args, "turn_id", None),
1165
1167
  )
1166
1168
 
1167
1169
 
1170
+ def finalize_scan_usage(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
1171
+ scan_id = require_uuid(args.scan_id, "scan-id")
1172
+ with scan_completion_lock(scan_id):
1173
+ scan = require_scan(connection, scan_id)
1174
+ stored = json.loads(scan["cost_json"]) if scan["cost_json"] is not None else {}
1175
+ usage = stored.get("usage", {})
1176
+ completion = usage.get("completion")
1177
+ if scan["status"] != "complete" or not completion:
1178
+ raise SystemExit("The scan has no pending completion usage.")
1179
+ if completion["threadId"] != args.thread_id or completion["turnId"] != args.turn_id:
1180
+ raise SystemExit("The scan usage belongs to a different completion turn.")
1181
+ if not completion["finalized"]:
1182
+ usage = scan_usage.collect_scan_usage(
1183
+ connection,
1184
+ scan,
1185
+ thread_id=args.thread_id,
1186
+ completed_turn_id=args.turn_id,
1187
+ )
1188
+ if usage["coverage"] == "unavailable":
1189
+ return scan_context(connection, scan_id)
1190
+ if args.turn_status != "completed":
1191
+ if usage["coverage"] == "complete":
1192
+ usage["coverage"] = "partial"
1193
+ usage["warnings"] = [*usage.get("warnings", []), f"scan_turn_{args.turn_status}"]
1194
+ usage["completion"] = {**completion, "finalized": True}
1195
+ cost_json = parse_scan_cost(json.dumps({**stored, "usage": usage}))
1196
+ with connection:
1197
+ connection.execute(
1198
+ "UPDATE scans SET cost_json = ? WHERE id = ?", (cost_json, scan_id)
1199
+ )
1200
+ return scan_context(connection, scan_id)
1201
+
1202
+
1168
1203
  def complete_budget_exhausted_scan(
1169
1204
  connection: sqlite3.Connection, args: argparse.Namespace
1170
1205
  ) -> dict[str, Any]:
@@ -1454,6 +1489,7 @@ def complete_scan_locked(
1454
1489
  *,
1455
1490
  prepare_only: bool = False,
1456
1491
  thread_id: str | None = None,
1492
+ turn_id: str | None = None,
1457
1493
  ) -> dict[str, Any]:
1458
1494
  scan = require_scan(connection, scan_id)
1459
1495
  if scan["status"] == "complete":
@@ -1603,14 +1639,27 @@ def complete_scan_locked(
1603
1639
  context["targetWarnings"] = target_warnings
1604
1640
  return context
1605
1641
 
1606
- if cost_json is None:
1607
- measured_usage = scan_usage.collect_scan_usage(
1642
+ cost_fields = scan_usage.stored_scan_cost_fields(cost_json)
1643
+ if "usage" not in cost_fields:
1644
+ cost_fields["usage"] = scan_usage.collect_scan_usage(
1608
1645
  connection,
1609
1646
  scan,
1610
1647
  thread_id=thread_id,
1611
1648
  completed_at=completion_timestamp,
1612
1649
  )
1613
- cost_json = parse_scan_cost(scan_usage.measured_scan_cost_json(measured_usage))
1650
+ measured_usage = cost_fields["usage"]
1651
+ if thread_id is not None and turn_id is not None:
1652
+ measured_usage["completion"] = {
1653
+ "threadId": thread_id,
1654
+ "turnId": turn_id,
1655
+ "finalized": False,
1656
+ }
1657
+ if measured_usage["coverage"] == "complete":
1658
+ measured_usage["coverage"] = "partial"
1659
+ measured_usage["warnings"] = sorted(
1660
+ {*measured_usage.get("warnings", []), "turn_in_progress"}
1661
+ )
1662
+ cost_json = parse_scan_cost(json.dumps(cost_fields))
1614
1663
  connection.execute("BEGIN IMMEDIATE")
1615
1664
  with connection:
1616
1665
  timestamp = manifest["scan"]["completedAt"]
@@ -1706,6 +1755,7 @@ def register_cli_scan(
1706
1755
  recipe = parse_scan_recipe(recipe_json, repository)
1707
1756
  requested_target = recipe["target"]
1708
1757
  paths = requested_target["paths"]
1758
+ recipe.pop("_codexSecurityFileScopes", None)
1709
1759
  # Capture host-observed kinds once; resumes and publication use the saved recipe.
1710
1760
  recipe.pop("scopeFilePaths", None)
1711
1761
  if file_paths := [path for path in paths if (repository / path).is_file()]:
@@ -1727,6 +1777,12 @@ def register_cli_scan(
1727
1777
  diff_target["contentDigest"] = worktree_content_digest(repository)
1728
1778
  mode = "diff" if diff_target is not None else recipe["mode"]
1729
1779
  target_identity = scan_target_identity(repository, diff_target)
1780
+ source_scopes = capture_source_scopes(
1781
+ repository,
1782
+ target_identity,
1783
+ paths or ["."],
1784
+ diff_target_kind=diff_target["kind"] if diff_target is not None else None,
1785
+ )
1730
1786
  scope_file_count = (
1731
1787
  directory_snapshot_regular_file_count(repository)
1732
1788
  if not paths
@@ -1797,6 +1853,7 @@ def register_cli_scan(
1797
1853
  scope=scope,
1798
1854
  diff_target=diff_target,
1799
1855
  target_identity=target_identity,
1856
+ source_scopes=source_scopes,
1800
1857
  target_root=scan_dir.parent,
1801
1858
  target_summary=None,
1802
1859
  scope_file_count=scope_file_count,
@@ -2678,7 +2735,7 @@ def scan_context(
2678
2735
  }
2679
2736
  if scan["recipe_json"] is not None:
2680
2737
  context["parentScanId"] = scan["parent_scan_id"]
2681
- context["recipe"] = json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json)
2738
+ context["recipe"] = public_scan_recipe(scan)
2682
2739
  return context
2683
2740
 
2684
2741
 
@@ -2976,6 +3033,7 @@ def finding_result(
2976
3033
  severity = details.get("severity")
2977
3034
  severity = severity if isinstance(severity, dict) else {}
2978
3035
  locations = []
3036
+ excerpt_locations = []
2979
3037
  try:
2980
3038
  target = require_scan_target_identity(scan)
2981
3039
  except SystemExit:
@@ -2990,10 +3048,20 @@ def finding_result(
2990
3048
  """,
2991
3049
  (occurrence["id"], FINDING_LOCATIONS_LIMIT),
2992
3050
  ):
3051
+ display_path = bounded_output_text(row["relative_path"], FINDING_LOCATION_PATH_BYTES)
3052
+ if display_path == row["relative_path"]:
3053
+ excerpt_locations.append(
3054
+ {
3055
+ "endLine": row["end_line"],
3056
+ "path": row["relative_path"],
3057
+ "role": row["role"],
3058
+ "startLine": row["start_line"],
3059
+ }
3060
+ )
2993
3061
  absolute_path = safe_source_path(target, row["relative_path"]) if target else None
2994
3062
  location = {
2995
3063
  "endLine": row["end_line"],
2996
- "path": bounded_output_text(row["relative_path"], FINDING_LOCATION_PATH_BYTES),
3064
+ "path": display_path,
2997
3065
  "role": (
2998
3066
  bounded_output_text(row["role"], FINDING_LOCATION_ROLE_BYTES)
2999
3067
  if row["role"] is not None
@@ -3035,7 +3103,9 @@ def finding_result(
3035
3103
  result["knownScanIds"] = known_scan_ids
3036
3104
  if related:
3037
3105
  result["related"] = related
3038
- source_excerpt = finding_source_excerpt(scan, target, locations)
3106
+ source_excerpt = finding_source_excerpt(
3107
+ scan, target, excerpt_locations, requested_scan_paths(scan)
3108
+ )
3039
3109
  if source_excerpt:
3040
3110
  result["sourceExcerpt"] = source_excerpt
3041
3111
  artifact_paths = finding_artifact_paths(Path(scan["scan_dir"]), details)
@@ -3359,10 +3429,8 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
3359
3429
  if args.command in {"save-artifact", "read-artifact"}:
3360
3430
  print(json.dumps(saved_results.read_or_save_artifact(args)))
3361
3431
  return
3362
- if args.command == "inspect-linear-publication":
3363
- result = publication.inspect_linear_publication(
3364
- _WORKBENCH_PUBLICATION_CONTEXT, read_json_object(Path(args.input_file))
3365
- )
3432
+ if args.command == "finding-issues":
3433
+ result = publication.finding_issues(_WORKBENCH_PUBLICATION_CONTEXT, json.load(sys.stdin))
3366
3434
  print(json.dumps(result, allow_nan=False, sort_keys=True))
3367
3435
  return
3368
3436
  with closing(
@@ -3386,6 +3454,7 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
3386
3454
  "register-cli-scan": partial(register_cli_scan, before_archive=before_archive),
3387
3455
  "set-scan-thread": set_scan_thread,
3388
3456
  "set-scan-cost-limit": set_scan_cost_limit,
3457
+ "finalize-scan-usage": finalize_scan_usage,
3389
3458
  "list-global-findings": native_indexes.list_global_findings,
3390
3459
  "list-repositories": native_indexes.list_repositories,
3391
3460
  "list-findings": list_findings,
@@ -3415,21 +3484,10 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
3415
3484
  "attach-scan-continuation-thread": partial(
3416
3485
  handoff.attach_scan_continuation_thread, command_context
3417
3486
  ),
3418
- "prepare-linear-publication": partial(
3419
- publication.prepare_linear_publication, _WORKBENCH_PUBLICATION_CONTEXT
3420
- ),
3421
- "record-linear-publications": partial(
3422
- publication.record_linear_publications, _WORKBENCH_PUBLICATION_CONTEXT
3423
- ),
3424
3487
  "export-findings": partial(publication.export_findings, _WORKBENCH_PUBLICATION_CONTEXT),
3425
3488
  }
3426
3489
  if handler := handlers.get(args.command):
3427
- payload = (
3428
- read_json_object(Path(args.input_file))
3429
- if args.command in {"prepare-linear-publication", "record-linear-publications"}
3430
- else args
3431
- )
3432
- result = handler(connection, payload)
3490
+ result = handler(connection, args)
3433
3491
  elif args.command == "get-workspace":
3434
3492
  result = workspace_state(
3435
3493
  connection,
@@ -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
  (