@openai/codex-security 0.1.7 → 0.1.9

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 (65) hide show
  1. package/README.md +23 -11
  2. package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
  3. package/_bundled_plugin/mcp/server.mjs +1 -1
  4. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  6. package/_bundled_plugin/preflight/capability-profiles.toml +2 -2
  7. package/_bundled_plugin/references/config-preflight.md +6 -6
  8. package/_bundled_plugin/references/desktop-config-preflight.md +11 -0
  9. package/_bundled_plugin/references/final-report.md +10 -14
  10. package/_bundled_plugin/references/scan-artifacts.md +17 -17
  11. package/_bundled_plugin/references/shared-hard-rules.md +2 -2
  12. package/_bundled_plugin/scripts/deep_scan_workbench.py +422 -48
  13. package/_bundled_plugin/scripts/generate_rank_input.py +118 -1
  14. package/_bundled_plugin/scripts/workbench_cli.py +1 -50
  15. package/_bundled_plugin/scripts/workbench_constants.py +0 -3
  16. package/_bundled_plugin/scripts/workbench_db.py +7 -297
  17. package/_bundled_plugin/scripts/workbench_progress.py +11 -0
  18. package/_bundled_plugin/scripts/workbench_scan_history.py +8 -64
  19. package/_bundled_plugin/scripts/workbench_target.py +2 -6
  20. package/_bundled_plugin/scripts/workbench_validation.py +0 -211
  21. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +10 -10
  22. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +25 -43
  23. package/_bundled_plugin/skills/finding-discovery/SKILL.md +2 -4
  24. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +11 -23
  25. package/_bundled_plugin/skills/security-scan/SKILL.md +89 -26
  26. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +25 -0
  27. package/_bundled_plugin/skills/security-scan/references/repository-wide-scan.md +11 -38
  28. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +5 -6
  29. package/_bundled_plugin/skills/triage-finding/SKILL.md +6 -14
  30. package/_bundled_plugin/skills/validation/SKILL.md +9 -9
  31. package/dist/api.d.ts +3 -1
  32. package/dist/api.d.ts.map +1 -1
  33. package/dist/api.js +113 -82
  34. package/dist/api.js.map +1 -1
  35. package/dist/auth.d.ts.map +1 -1
  36. package/dist/auth.js +18 -71
  37. package/dist/auth.js.map +1 -1
  38. package/dist/cli.d.ts +1 -1
  39. package/dist/cli.d.ts.map +1 -1
  40. package/dist/cli.js +57 -136
  41. package/dist/cli.js.map +1 -1
  42. package/dist/contract.d.ts.map +1 -1
  43. package/dist/contract.js +7 -228
  44. package/dist/contract.js.map +1 -1
  45. package/dist/cost.d.ts.map +1 -1
  46. package/dist/cost.js +0 -4
  47. package/dist/cost.js.map +1 -1
  48. package/dist/knowledge-base.js +4 -4
  49. package/dist/knowledge-base.js.map +1 -1
  50. package/dist/multiscan.d.ts +5 -1
  51. package/dist/multiscan.d.ts.map +1 -1
  52. package/dist/multiscan.js +232 -26
  53. package/dist/multiscan.js.map +1 -1
  54. package/dist/runtime.d.ts +13 -1
  55. package/dist/runtime.d.ts.map +1 -1
  56. package/dist/runtime.js +136 -242
  57. package/dist/runtime.js.map +1 -1
  58. package/dist/version.d.ts +1 -1
  59. package/dist/version.js +1 -1
  60. package/dist/version.js.map +1 -1
  61. package/dist/worker-progress.d.ts.map +1 -1
  62. package/dist/worker-progress.js +8 -29
  63. package/dist/worker-progress.js.map +1 -1
  64. package/package.json +3 -3
  65. package/_bundled_plugin/mcp/mcp-app.html.br +0 -0
@@ -74,7 +74,6 @@ from workbench_constants import (
74
74
  FINDING_TITLE_BYTES,
75
75
  FINDINGS_PAGE_MAX,
76
76
  FINDINGS_RESULT_LIMIT,
77
- PATCH_ARTIFACT_MAX_BYTES,
78
77
  PATCH_PREVIEW_BYTES,
79
78
  SQLITE_RETRY_ATTEMPTS,
80
79
  )
@@ -121,8 +120,6 @@ from workbench_target import (
121
120
  from workbench_target_state import backfill_security_targets, ensure_security_target
122
121
  from workbench_validation import (
123
122
  bounded_output_text,
124
- capability_preflight_input,
125
- capability_preflight_json,
126
123
  optional_text,
127
124
  parse_scan_cost,
128
125
  path_within_scope,
@@ -246,39 +243,6 @@ def connect() -> sqlite3.Connection:
246
243
  raise AssertionError("SQLite retry loop exhausted unexpectedly.")
247
244
 
248
245
 
249
- def setup_preference(connection: sqlite3.Connection) -> dict[str, bool]:
250
- row = connection.execute(
251
- "SELECT skip_setup_ui FROM setup_preferences WHERE singleton = 1"
252
- ).fetchone()
253
- return {"skipSetupUi": bool(row["skip_setup_ui"]) if row is not None else False}
254
-
255
-
256
- def record_setup_ui_disabled(connection: sqlite3.Connection, timestamp: str) -> None:
257
- connection.execute(
258
- """
259
- INSERT INTO setup_preferences (singleton, skip_setup_ui, updated_at)
260
- VALUES (1, ?, ?)
261
- ON CONFLICT(singleton) DO UPDATE SET
262
- skip_setup_ui = excluded.skip_setup_ui,
263
- updated_at = excluded.updated_at
264
- """,
265
- (1, timestamp),
266
- )
267
-
268
-
269
- def disable_setup_ui(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
270
- workspace_id = require_uuid(args.workspace_id, "workspace-id")
271
- try:
272
- connection.execute("BEGIN IMMEDIATE")
273
- require_workspace(connection, workspace_id)
274
- record_setup_ui_disabled(connection, now())
275
- connection.commit()
276
- except BaseException:
277
- connection.rollback()
278
- raise
279
- return workspace_state(connection, workspace_id)
280
-
281
-
282
246
  def apply_migrations(connection: sqlite3.Connection) -> None:
283
247
  apply_schema_migrations(connection, MIGRATIONS, now, backfill_security_targets)
284
248
 
@@ -730,13 +694,6 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
730
694
  diff_content_digest = inspected["diffTarget"].get("contentDigest")
731
695
  except SystemExit:
732
696
  pass
733
- preflight_json = capability_preflight_json(
734
- capability_preflight_input(
735
- args.capability_preflight_json, args.capability_preflight_json_file
736
- ),
737
- checked_target_path=target_path,
738
- checked_mode=args.mode,
739
- )
740
697
  with connection:
741
698
  target_id = (
742
699
  ensure_security_target(connection, target_path) if target_path is not None else None
@@ -747,8 +704,8 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
747
704
  id, thread_id, target_id, target_path, target_title, target_summary,
748
705
  default_scope, default_mode,
749
706
  user_context, diff_target_kind, diff_base_revision, diff_head_revision,
750
- diff_content_digest, capability_preflight_json, created_at, updated_at
751
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
707
+ diff_content_digest, created_at, updated_at
708
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
752
709
  """,
753
710
  (
754
711
  workspace_id,
@@ -764,7 +721,6 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
764
721
  diff_base_revision,
765
722
  diff_head_revision,
766
723
  diff_content_digest,
767
- preflight_json,
768
724
  timestamp,
769
725
  timestamp,
770
726
  ),
@@ -772,55 +728,6 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
772
728
  return workspace_state(connection, workspace_id)
773
729
 
774
730
 
775
- def latest_workspace(connection: sqlite3.Connection, thread_id: str) -> dict[str, Any]:
776
- thread_id = optional_text(thread_id, maximum=512)
777
- if thread_id is None:
778
- raise SystemExit("thread-id is required.")
779
- row = connection.execute(
780
- """
781
- SELECT workspaces.id
782
- FROM workspaces
783
- LEFT JOIN scans ON scans.id = workspaces.active_scan_id
784
- WHERE workspaces.thread_id = ?
785
- ORDER BY
786
- CASE WHEN scans.status = 'running' THEN 0 ELSE 1 END,
787
- CASE WHEN scans.status = 'running' THEN
788
- MAX(
789
- workspaces.updated_at,
790
- scans.updated_at,
791
- COALESCE((
792
- SELECT MAX(progress.updated_at)
793
- FROM scan_progress AS progress
794
- WHERE progress.scan_id = scans.id
795
- ), '')
796
- )
797
- ELSE
798
- MAX(
799
- workspaces.updated_at,
800
- COALESCE((
801
- SELECT MAX(triage.updated_at)
802
- FROM finding_triage AS triage
803
- JOIN finding_occurrences AS occurrences
804
- ON occurrences.id = triage.occurrence_id
805
- WHERE occurrences.scan_id = scans.id
806
- ), ''),
807
- COALESCE((
808
- SELECT MAX(remediation.updated_at)
809
- FROM finding_remediation_attempts AS remediation
810
- JOIN finding_occurrences AS occurrences
811
- ON occurrences.id = remediation.occurrence_id
812
- WHERE occurrences.scan_id = scans.id
813
- ), '')
814
- )
815
- END DESC,
816
- workspaces.created_at DESC
817
- LIMIT 1
818
- """,
819
- (thread_id,),
820
- ).fetchone()
821
- return {"workspace": workspace_state(connection, row["id"]) if row is not None else None}
822
-
823
-
824
731
  def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
825
732
  workspace = require_workspace(connection, args.workspace_id)
826
733
  if workspace["active_scan_id"]:
@@ -858,7 +765,7 @@ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) ->
858
765
  SET target_id = ?, target_path = ?, target_title = ?, target_summary = ?, default_scope = ?,
859
766
  default_mode = ?, user_context = ?, diff_target_kind = ?,
860
767
  diff_base_revision = ?, diff_head_revision = ?, diff_content_digest = ?,
861
- diff_resolution_id = NULL, submitted = 1, updated_at = ?
768
+ submitted = 1, updated_at = ?
862
769
  WHERE id = ? AND active_scan_id IS NULL
863
770
  """,
864
771
  (
@@ -884,136 +791,6 @@ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) ->
884
791
  return workspace_state(connection, workspace["id"])
885
792
 
886
793
 
887
- def set_capability_preflight(
888
- connection: sqlite3.Connection, args: argparse.Namespace
889
- ) -> dict[str, Any]:
890
- workspace = require_workspace(connection, args.workspace_id)
891
- if workspace["active_scan_id"]:
892
- raise SystemExit("Cannot update capability preflight after a scan has started.")
893
- checked_target_path = str(require_target(args.checked_target_path))
894
- preflight_json = capability_preflight_json(
895
- capability_preflight_input(
896
- args.capability_preflight_json, args.capability_preflight_json_file
897
- ),
898
- checked_target_path=checked_target_path,
899
- checked_mode=args.checked_mode,
900
- )
901
- timestamp = now()
902
- with connection:
903
- updated = connection.execute(
904
- """
905
- UPDATE workspaces
906
- SET capability_preflight_json = ?, updated_at = ?
907
- WHERE id = ? AND active_scan_id IS NULL
908
- """,
909
- (preflight_json, timestamp, workspace["id"]),
910
- )
911
- if updated.rowcount != 1:
912
- raise SystemExit("Cannot update capability preflight after a scan has started.")
913
- return workspace_state(connection, workspace["id"])
914
-
915
-
916
- def begin_diff_resolution(
917
- connection: sqlite3.Connection, args: argparse.Namespace
918
- ) -> dict[str, Any]:
919
- workspace = require_workspace(connection, args.workspace_id)
920
- request_id = require_uuid(args.request_id, "request-id")
921
- if workspace["active_scan_id"]:
922
- raise SystemExit("Cannot resolve a new change set while this workspace has a scan.")
923
- target = require_target(args.target_path)
924
- require_review_changes_target(target)
925
- target_title = (
926
- workspace["target_title"] if workspace["target_path"] == str(target) else target.name
927
- )
928
- timestamp = now()
929
- with connection:
930
- target_id = ensure_security_target(connection, str(target))
931
- updated = connection.execute(
932
- """
933
- UPDATE workspaces
934
- SET target_id = ?, target_path = ?, target_title = ?, target_summary = NULL,
935
- default_scope = '.', default_mode = 'diff',
936
- user_context = ?, diff_target_kind = NULL, diff_base_revision = NULL,
937
- diff_head_revision = NULL, diff_content_digest = NULL,
938
- diff_resolution_id = ?, submitted = 0, updated_at = ?
939
- WHERE id = ? AND active_scan_id IS NULL
940
- """,
941
- (
942
- target_id,
943
- str(target),
944
- target_title,
945
- user_text(args.user_context),
946
- request_id,
947
- timestamp,
948
- workspace["id"],
949
- ),
950
- )
951
- if updated.rowcount != 1:
952
- raise SystemExit("Cannot resolve a new change set while this workspace has a scan.")
953
- return workspace_state(connection, workspace["id"])
954
-
955
-
956
- def cancel_diff_resolution(
957
- connection: sqlite3.Connection, args: argparse.Namespace
958
- ) -> dict[str, Any]:
959
- workspace = require_workspace(connection, args.workspace_id)
960
- request_id = require_uuid(args.request_id, "request-id")
961
- timestamp = now()
962
- with connection:
963
- connection.execute(
964
- """
965
- UPDATE workspaces
966
- SET diff_resolution_id = NULL, updated_at = ?
967
- WHERE id = ? AND diff_resolution_id = ?
968
- """,
969
- (timestamp, workspace["id"], request_id),
970
- )
971
- return workspace_state(connection, workspace["id"])
972
-
973
-
974
- def set_diff_target(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
975
- workspace = require_workspace(connection, args.workspace_id)
976
- request_id = require_uuid(args.request_id, "request-id")
977
- if workspace["active_scan_id"]:
978
- raise SystemExit("Cannot resolve a new change set while this workspace has a scan.")
979
- if workspace["diff_resolution_id"] != request_id:
980
- raise SystemExit("This change-resolution request is no longer active.")
981
- target = require_target(workspace["target_path"])
982
- require_scannable_target(target)
983
- diff_target = require_diff_target(
984
- target,
985
- args.diff_target_kind,
986
- args.diff_base_revision,
987
- args.diff_head_revision,
988
- args.diff_content_digest,
989
- )
990
- timestamp = now()
991
- with connection:
992
- updated = connection.execute(
993
- """
994
- UPDATE workspaces
995
- SET target_summary = ?, default_scope = '.', default_mode = 'diff',
996
- diff_target_kind = ?, diff_base_revision = ?, diff_head_revision = ?,
997
- diff_content_digest = ?, diff_resolution_id = NULL,
998
- submitted = 0, updated_at = ?
999
- WHERE id = ? AND diff_resolution_id = ? AND active_scan_id IS NULL
1000
- """,
1001
- (
1002
- optional_text(args.target_summary, maximum=2400),
1003
- diff_target["kind"],
1004
- diff_target["baseRevision"],
1005
- diff_target["headRevision"],
1006
- diff_target.get("contentDigest"),
1007
- timestamp,
1008
- workspace["id"],
1009
- request_id,
1010
- ),
1011
- )
1012
- if updated.rowcount != 1:
1013
- raise SystemExit("This change-resolution request is no longer active.")
1014
- return workspace_state(connection, workspace["id"])
1015
-
1016
-
1017
794
  def scan_target_root(scan_root: str | None, target: Path) -> Path:
1018
795
  root = Path(scan_root).expanduser().resolve() if scan_root else state_dir() / "scans"
1019
796
  target_root = (root / safe_segment(target.name)).resolve()
@@ -1176,10 +953,6 @@ def _start_prompt_driven_scan(
1176
953
 
1177
954
  connection.execute("BEGIN IMMEDIATE")
1178
955
  try:
1179
- if not headless_standard and not setup_preference(connection)["skipSetupUi"]:
1180
- raise SystemExit(
1181
- "Prompt-only scanning requires the persisted setup UI opt-out preference."
1182
- )
1183
956
  current_target = require_remediation_target(target_path)
1184
957
  current_diff_target = (
1185
958
  require_diff_target(
@@ -1238,20 +1011,6 @@ def _start_prompt_driven_scan(
1238
1011
  if existing is not None:
1239
1012
  connection.commit()
1240
1013
  return {**scan_context(connection, existing["id"]), "startDisposition": "joined"}
1241
- if headless_standard and not setup_preference(connection)["skipSetupUi"]:
1242
- pending = connection.execute(
1243
- """
1244
- SELECT 1 FROM workspaces
1245
- WHERE thread_id = ? AND target_path = ? AND default_scope = ?
1246
- AND default_mode = 'standard' AND active_scan_id IS NULL LIMIT 1
1247
- """,
1248
- (thread_id, target_path, scope),
1249
- ).fetchone()
1250
- if pending is not None:
1251
- raise SystemExit(
1252
- "A matching Codex Security setup workspace is waiting for Start scan. "
1253
- "Finish that setup and retry with its scanId."
1254
- )
1255
1014
  target_root.mkdir(parents=True, exist_ok=True)
1256
1015
  workspace_id = str(uuid.uuid4())
1257
1016
  scan_id = str(uuid.uuid4())
@@ -2682,18 +2441,12 @@ def require_scan_relative_file(scan: sqlite3.Row, value: str) -> str:
2682
2441
  def require_matching_patch_digest(scan: sqlite3.Row, patch_path: str, patch_digest: str) -> None:
2683
2442
  digest = hashlib.sha256()
2684
2443
  with open_scan_local_file(Path(scan["scan_dir"]), patch_path) as patch:
2685
- require_bounded_patch_artifact(patch)
2686
2444
  while chunk := patch.read(1024 * 1024):
2687
2445
  digest.update(chunk)
2688
2446
  if f"sha256:{digest.hexdigest()}" != patch_digest:
2689
2447
  raise SystemExit("Patch digest does not match the scan-local patch file.")
2690
2448
 
2691
2449
 
2692
- def require_bounded_patch_artifact(patch: Any) -> None:
2693
- if os.fstat(patch.fileno()).st_size > PATCH_ARTIFACT_MAX_BYTES:
2694
- raise SystemExit("Patch artifact must be no larger than 2 MiB.")
2695
-
2696
-
2697
2450
  def open_scan_local_file(scan_dir: Path, relative_path: str) -> Any:
2698
2451
  parsed = PurePosixPath(relative_path)
2699
2452
  if parsed.is_absolute() or not parsed.parts or ".." in parsed.parts:
@@ -2809,9 +2562,7 @@ def workspace_state(
2809
2562
  result: dict[str, Any] = {
2810
2563
  "id": workspace["id"],
2811
2564
  "diffTarget": persisted_diff_target,
2812
- "diffResolutionId": workspace["diff_resolution_id"],
2813
2565
  "mode": workspace["default_mode"],
2814
- "recentTargets": [],
2815
2566
  "scope": workspace["default_scope"],
2816
2567
  "setup": {"submitted": bool(workspace["submitted"])},
2817
2568
  "setupValidation": {"error": None, "valid": bool(workspace["submitted"])},
@@ -2821,8 +2572,6 @@ def workspace_state(
2821
2572
  "updatedAt": workspace["updated_at"],
2822
2573
  "userContext": workspace["user_context"],
2823
2574
  }
2824
- if workspace["capability_preflight_json"]:
2825
- result["capabilityPreflight"] = json.loads(workspace["capability_preflight_json"])
2826
2575
  selected_scan_id = result_scan_id or workspace["active_scan_id"]
2827
2576
  if selected_scan_id:
2828
2577
  selected_scan = require_scan(connection, selected_scan_id)
@@ -2854,7 +2603,6 @@ def workspace_state(
2854
2603
  except SystemExit:
2855
2604
  pass
2856
2605
  result["diffTarget"] = validated_diff_target or persisted_diff_target
2857
- result["recentTargets"] = recent_targets(connection)
2858
2606
  result["setupValidation"] = {
2859
2607
  "error": setup_error,
2860
2608
  "valid": setup_error is None and bool(target_metadata),
@@ -2864,28 +2612,6 @@ def workspace_state(
2864
2612
  return result
2865
2613
 
2866
2614
 
2867
- def recent_targets(connection: sqlite3.Connection) -> list[dict[str, Any]]:
2868
- targets: list[dict[str, Any]] = []
2869
- rows = connection.execute(
2870
- """
2871
- SELECT target_path, MAX(updated_at) AS last_used_at
2872
- FROM workspaces
2873
- WHERE submitted = 1 AND target_path IS NOT NULL
2874
- GROUP BY target_path
2875
- ORDER BY last_used_at DESC
2876
- """
2877
- )
2878
- for row in rows:
2879
- try:
2880
- inspected = inspect_target(row["target_path"])
2881
- except SystemExit:
2882
- continue
2883
- targets.append(inspected)
2884
- if len(targets) == 5:
2885
- break
2886
- return targets
2887
-
2888
-
2889
2615
  def scan_context(
2890
2616
  connection: sqlite3.Connection,
2891
2617
  scan_id: str,
@@ -3417,7 +3143,6 @@ def patch_artifact_preview(
3417
3143
  at_line_start = True
3418
3144
  try:
3419
3145
  with open_scan_local_file(scan_dir, relative_path) as patch:
3420
- require_bounded_patch_artifact(patch)
3421
3146
  while chunk := patch.readline(1024 * 1024):
3422
3147
  digest.update(chunk)
3423
3148
  if len(preview) <= PATCH_PREVIEW_BYTES:
@@ -3574,6 +3299,7 @@ def main() -> None:
3574
3299
  require_canonical_scan_directory=require_canonical_scan_directory,
3575
3300
  safe_segment=safe_segment,
3576
3301
  compact_timestamp=compact_timestamp,
3302
+ scan_completion_lock=scan_completion_lock,
3577
3303
  )
3578
3304
  )
3579
3305
  if args.command == "inspect-target":
@@ -3585,30 +3311,12 @@ def main() -> None:
3585
3311
  print(json.dumps(result, allow_nan=False, sort_keys=True))
3586
3312
  return
3587
3313
  with closing(connect()) as connection:
3588
- if args.command == "get-setup-preference":
3589
- result = setup_preference(connection)
3590
- elif args.command == "disable-setup-ui":
3591
- result = disable_setup_ui(connection, args)
3592
- elif args.command == "create-workspace":
3314
+ if args.command == "create-workspace":
3593
3315
  result = create_workspace(connection, args)
3594
3316
  elif args.command == "get-workspace":
3595
3317
  result = workspace_state(connection, args.workspace_id, thread_id=args.thread_id)
3596
- elif args.command == "get-latest-workspace":
3597
- result = latest_workspace(connection, args.thread_id)
3598
- elif args.command == "list-workspace-scans":
3599
- result = scan_history.list_workspace_scans(
3600
- connection, args, require_workspace=require_workspace
3601
- )
3602
- elif args.command == "begin-diff-resolution":
3603
- result = begin_diff_resolution(connection, args)
3604
- elif args.command == "cancel-diff-resolution":
3605
- result = cancel_diff_resolution(connection, args)
3606
- elif args.command == "set-diff-target":
3607
- result = set_diff_target(connection, args)
3608
3318
  elif args.command == "save-workspace":
3609
3319
  result = save_workspace(connection, args)
3610
- elif args.command == "set-capability-preflight":
3611
- result = set_capability_preflight(connection, args)
3612
3320
  elif args.command == "start-scan":
3613
3321
  result = start_scan(connection, args)
3614
3322
  elif args.command == "start-prompt-only-scan":
@@ -3619,6 +3327,8 @@ def main() -> None:
3619
3327
  result = deep_scan.begin_deep_scan(connection, args)
3620
3328
  elif args.command == "get-deep-scan":
3621
3329
  result = deep_scan.get_deep_scan(connection, args)
3330
+ elif args.command == "claim-deep-scan-coordinator":
3331
+ result = deep_scan.claim_deep_scan_coordinator(connection, args)
3622
3332
  elif args.command == "upsert-deep-scan-worker":
3623
3333
  result = deep_scan.upsert_deep_scan_worker(connection, args)
3624
3334
  elif args.command == "claim-deep-scan-dedup":
@@ -8,6 +8,7 @@ from pathlib import Path
8
8
  from typing import Any, Callable
9
9
 
10
10
  sys.path.insert(0, str(Path(__file__).resolve().parent))
11
+ from deep_scan_workbench import require_current_coordinator
11
12
  from workbench.handoff import require_current_continuation
12
13
  from workbench_constants import PHASES
13
14
  from workbench_validation import optional_text, require_uuid, user_text
@@ -175,6 +176,16 @@ def update_progress(
175
176
  scan = require_scan(connection, scan_id)
176
177
  if scan["status"] != "running":
177
178
  raise SystemExit("Only a running scan can update progress.")
179
+ if scan["mode"] == "deep":
180
+ coordinator = connection.execute(
181
+ "SELECT * FROM deep_scan_runs WHERE scan_id = ?", (scan_id,)
182
+ ).fetchone()
183
+ if coordinator is not None and (
184
+ coordinator["status"] == "running" or args.coordinator_generation is not None
185
+ ):
186
+ require_current_coordinator(coordinator, args)
187
+ elif args.coordinator_generation is not None:
188
+ raise SystemExit("Coordinator leases apply only to Deep Scan progress.")
178
189
  require_current_continuation(
179
190
  scan,
180
191
  args.claim_token,
@@ -75,60 +75,6 @@ def _repository_origin(target: Path) -> tuple[str, str] | None:
75
75
  return (host.lower(), path) if host and path else None
76
76
 
77
77
 
78
- def list_workspace_scans(
79
- connection: sqlite3.Connection,
80
- args: argparse.Namespace,
81
- *,
82
- require_workspace: Callable[[sqlite3.Connection, str], sqlite3.Row],
83
- ) -> dict[str, Any]:
84
- workspace = require_workspace(connection, args.workspace_id)
85
- total = connection.execute(
86
- "SELECT COUNT(*) FROM scans WHERE workspace_id = ?", (workspace["id"],)
87
- ).fetchone()[0]
88
- rows = connection.execute(
89
- """
90
- SELECT id, mode, status, phase, scope, target_revision,
91
- seal_manifest_digest, started_at, completed_at, canceled_at,
92
- updated_at, failure_message, completion_warnings_json
93
- FROM scans
94
- WHERE workspace_id = ?
95
- ORDER BY created_at DESC, id DESC
96
- LIMIT ? OFFSET ?
97
- """,
98
- (workspace["id"], args.limit, args.offset),
99
- ).fetchall()
100
- next_offset = args.offset + len(rows)
101
- return {
102
- "limit": args.limit,
103
- "nextOffset": next_offset if next_offset < total else None,
104
- "offset": args.offset,
105
- "scans": [
106
- {
107
- "canceledAt": row["canceled_at"],
108
- "completedAt": row["completed_at"],
109
- "failureMessage": row["failure_message"],
110
- "mode": row["mode"],
111
- "phase": row["phase"],
112
- "scanId": row["id"],
113
- "scope": row["scope"],
114
- "sealed": row["seal_manifest_digest"] is not None,
115
- "startedAt": row["started_at"],
116
- "status": "canceled" if row["canceled_at"] else row["status"],
117
- "targetRevision": row["target_revision"],
118
- "updatedAt": row["updated_at"],
119
- **(
120
- {"warnings": json.loads(row["completion_warnings_json"])}
121
- if row["completion_warnings_json"] != "[]"
122
- else {}
123
- ),
124
- }
125
- for row in rows
126
- ],
127
- "total": total,
128
- "workspaceId": workspace["id"],
129
- }
130
-
131
-
132
78
  def list_scans(
133
79
  connection: sqlite3.Connection, args: argparse.Namespace | None = None
134
80
  ) -> dict[str, Any]:
@@ -310,7 +256,7 @@ def list_unmatched_scan_pairs(
310
256
  }
311
257
  batches = []
312
258
  skipped = 0
313
- backfilled: set[str] = set()
259
+ matching_findings: dict[str, list[dict[str, Any]]] = {}
314
260
  for index, after in enumerate(available):
315
261
  previous = [
316
262
  before
@@ -321,21 +267,19 @@ def list_unmatched_scan_pairs(
321
267
  if not previous:
322
268
  continue
323
269
  for scan in (*previous, after):
324
- if scan["id"] not in backfilled:
270
+ if scan["id"] not in matching_findings:
325
271
  backfill_finding_details(connection, scan)
326
- backfilled.add(scan["id"])
272
+ matching_findings[scan["id"]] = [
273
+ _matching_input(row)
274
+ for row in _scan_findings(connection, scan["id"]).values()
275
+ ]
327
276
  batches.append(
328
277
  {
329
- "afterFindings": [
330
- _matching_input(row) for row in _scan_findings(connection, after["id"]).values()
331
- ],
278
+ "afterFindings": matching_findings[after["id"]],
332
279
  "afterScanId": after["id"],
333
280
  "beforeScans": [
334
281
  {
335
- "findings": [
336
- _matching_input(row)
337
- for row in _scan_findings(connection, before["id"]).values()
338
- ],
282
+ "findings": matching_findings[before["id"]],
339
283
  "scanId": before["id"],
340
284
  }
341
285
  for before in previous
@@ -495,9 +495,8 @@ def require_remediation_target(value: str) -> Path:
495
495
 
496
496
  def require_scan_target_identity(scan: sqlite3.Row) -> Path:
497
497
  target = require_remediation_target(scan["target_path"])
498
- expected_device = scan["target_device"]
499
498
  expected_inode = scan["target_inode"]
500
- if expected_device is None or expected_inode is None:
499
+ if expected_inode is None:
501
500
  raise SystemExit(
502
501
  "Remediation is unavailable because this scan does not record checkout identity. "
503
502
  "Start a new scan."
@@ -508,10 +507,7 @@ def require_scan_target_identity(scan: sqlite3.Row) -> Path:
508
507
  raise SystemExit(
509
508
  "Remediation is unavailable because the selected checkout is no longer accessible."
510
509
  ) from exc
511
- if not (
512
- stored_filesystem_identity_matches(expected_device, metadata.st_dev)
513
- and stored_filesystem_identity_matches(expected_inode, metadata.st_ino)
514
- ):
510
+ if not stored_filesystem_identity_matches(expected_inode, metadata.st_ino):
515
511
  raise SystemExit(
516
512
  "Remediation is unavailable because the selected checkout path was replaced. "
517
513
  "Start a new scan."