@openai/codex-security 0.1.23 → 0.1.25

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 (135) hide show
  1. package/README.md +200 -23
  2. package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
  3. package/_bundled_plugin/.mcp.json +1 -0
  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/references/scan-contract.md +10 -0
  7. package/_bundled_plugin/scripts/deep_scan_workbench.py +6 -1
  8. package/_bundled_plugin/scripts/finalize_scan_contract.py +27 -78
  9. package/_bundled_plugin/scripts/generate_in_scope_files.py +2 -8
  10. package/_bundled_plugin/scripts/generate_rank_input.py +1 -5
  11. package/_bundled_plugin/scripts/rank_preview.py +12 -1
  12. package/_bundled_plugin/scripts/report_projection.py +8 -14
  13. package/_bundled_plugin/scripts/validate_scan_contract.py +1 -3
  14. package/_bundled_plugin/scripts/windows_scan_local_files.py +5 -15
  15. package/_bundled_plugin/scripts/workbench_cli.py +14 -1
  16. package/_bundled_plugin/scripts/workbench_dashboard.py +41 -18
  17. package/_bundled_plugin/scripts/workbench_db.py +127 -541
  18. package/_bundled_plugin/scripts/workbench_finding_workflows.py +31 -13
  19. package/_bundled_plugin/scripts/workbench_findings.py +8 -3
  20. package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -2
  21. package/_bundled_plugin/scripts/workbench_publication.py +520 -0
  22. package/_bundled_plugin/scripts/workbench_remediation.py +37 -0
  23. package/_bundled_plugin/scripts/workbench_saved_results.py +298 -90
  24. package/_bundled_plugin/scripts/workbench_scan_history.py +375 -68
  25. package/_bundled_plugin/scripts/workbench_scan_usage.py +9 -33
  26. package/_bundled_plugin/scripts/workbench_schema.py +49 -21
  27. package/_bundled_plugin/scripts/workbench_target.py +96 -17
  28. package/_bundled_plugin/scripts/workbench_validation.py +1 -5
  29. package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +1 -5
  30. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +6 -1
  31. package/dist/api.d.ts +18 -3
  32. package/dist/api.d.ts.map +1 -1
  33. package/dist/api.js +350 -28
  34. package/dist/api.js.map +1 -1
  35. package/dist/auth.d.ts.map +1 -1
  36. package/dist/auth.js +35 -3
  37. package/dist/auth.js.map +1 -1
  38. package/dist/cli.d.ts +2 -0
  39. package/dist/cli.d.ts.map +1 -1
  40. package/dist/cli.js +118 -35
  41. package/dist/cli.js.map +1 -1
  42. package/dist/component-plan.d.ts.map +1 -1
  43. package/dist/component-plan.js +4 -2
  44. package/dist/component-plan.js.map +1 -1
  45. package/dist/component-scan.d.ts.map +1 -1
  46. package/dist/component-scan.js +21 -6
  47. package/dist/component-scan.js.map +1 -1
  48. package/dist/config.d.ts.map +1 -1
  49. package/dist/config.js +46 -2
  50. package/dist/config.js.map +1 -1
  51. package/dist/cost.d.ts +1 -0
  52. package/dist/cost.d.ts.map +1 -1
  53. package/dist/cost.js +23 -11
  54. package/dist/cost.js.map +1 -1
  55. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  56. package/dist/deduplication/checkpointed-review.js +2 -1
  57. package/dist/deduplication/checkpointed-review.js.map +1 -1
  58. package/dist/deduplication/codex-review.d.ts +3 -0
  59. package/dist/deduplication/codex-review.d.ts.map +1 -1
  60. package/dist/deduplication/codex-review.js +122 -36
  61. package/dist/deduplication/codex-review.js.map +1 -1
  62. package/dist/deduplication/deduplication-prompts.d.ts +4 -3
  63. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  64. package/dist/deduplication/deduplication-prompts.js +18 -9
  65. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  66. package/dist/deduplication/deduplication-reviewer.d.ts +2 -7
  67. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  68. package/dist/deduplication/deduplication-reviewer.js +46 -24
  69. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  70. package/dist/deduplication/deduplication.d.ts.map +1 -1
  71. package/dist/deduplication/deduplication.js +186 -23
  72. package/dist/deduplication/deduplication.js.map +1 -1
  73. package/dist/deduplication/scan.d.ts +9 -1
  74. package/dist/deduplication/scan.d.ts.map +1 -1
  75. package/dist/deduplication/scan.js +24 -7
  76. package/dist/deduplication/scan.js.map +1 -1
  77. package/dist/deep-progress.d.ts +21 -0
  78. package/dist/deep-progress.d.ts.map +1 -0
  79. package/dist/deep-progress.js +108 -0
  80. package/dist/deep-progress.js.map +1 -0
  81. package/dist/errors.d.ts +13 -0
  82. package/dist/errors.d.ts.map +1 -1
  83. package/dist/errors.js +7 -0
  84. package/dist/errors.js.map +1 -1
  85. package/dist/index.d.ts +6 -5
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +2 -2
  88. package/dist/index.js.map +1 -1
  89. package/dist/mock-scan.d.ts +4 -0
  90. package/dist/mock-scan.d.ts.map +1 -0
  91. package/dist/mock-scan.js +210 -0
  92. package/dist/mock-scan.js.map +1 -0
  93. package/dist/publish.d.ts.map +1 -1
  94. package/dist/publish.js +2 -2
  95. package/dist/publish.js.map +1 -1
  96. package/dist/runtime.d.ts +1 -0
  97. package/dist/runtime.d.ts.map +1 -1
  98. package/dist/runtime.js +54 -14
  99. package/dist/runtime.js.map +1 -1
  100. package/dist/scan-activity.d.ts.map +1 -1
  101. package/dist/scan-activity.js +12 -2
  102. package/dist/scan-activity.js.map +1 -1
  103. package/dist/scan-comparison.d.ts +11 -2
  104. package/dist/scan-comparison.d.ts.map +1 -1
  105. package/dist/scan-comparison.js +237 -39
  106. package/dist/scan-comparison.js.map +1 -1
  107. package/dist/scan-dashboard.d.ts +3 -1
  108. package/dist/scan-dashboard.d.ts.map +1 -1
  109. package/dist/scan-dashboard.js +70 -3
  110. package/dist/scan-dashboard.js.map +1 -1
  111. package/dist/scan-history-renderer.d.ts.map +1 -1
  112. package/dist/scan-history-renderer.js +21 -0
  113. package/dist/scan-history-renderer.js.map +1 -1
  114. package/dist/server/api.d.ts +6 -0
  115. package/dist/server/api.d.ts.map +1 -0
  116. package/dist/server/api.js +4 -0
  117. package/dist/server/api.js.map +1 -0
  118. package/dist/server/dashboard/app.css +1 -1
  119. package/dist/server/embeddings.d.ts +2 -1
  120. package/dist/server/embeddings.d.ts.map +1 -1
  121. package/dist/server/embeddings.js +8 -3
  122. package/dist/server/embeddings.js.map +1 -1
  123. package/dist/server/index.js +2 -28
  124. package/dist/server/index.js.map +1 -1
  125. package/dist/server/serve.d.ts +2 -0
  126. package/dist/server/serve.d.ts.map +1 -0
  127. package/dist/server/serve.js +28 -0
  128. package/dist/server/serve.js.map +1 -0
  129. package/dist/targets.d.ts.map +1 -1
  130. package/dist/targets.js +3 -5
  131. package/dist/targets.js.map +1 -1
  132. package/dist/version.d.ts +1 -1
  133. package/dist/version.js +1 -1
  134. package/dist/version.js.map +1 -1
  135. package/package.json +10 -5
@@ -4,11 +4,10 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  import argparse
7
- import csv
8
7
  import errno
9
8
  import hashlib
10
- import io
11
9
  import json
10
+ import math
12
11
  import os
13
12
  import re
14
13
  import sqlite3
@@ -21,7 +20,6 @@ from contextlib import closing, contextmanager
21
20
  from datetime import datetime, timedelta, timezone
22
21
  from pathlib import Path, PurePosixPath
23
22
  from typing import Any
24
- from urllib.parse import quote
25
23
 
26
24
  try:
27
25
  import fcntl as posix_file_lock
@@ -37,11 +35,14 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))
37
35
  import deep_scan_workbench as deep_scan
38
36
  import workbench_native_indexes as native_indexes
39
37
  import workbench_progress as progress
38
+ import workbench_publication as publication
40
39
  import workbench_remediation as remediation
41
40
  import workbench_saved_results as saved_results
42
41
  import workbench_scan_history as scan_history
43
42
  import workbench_scan_usage as scan_usage
44
- from filesystem_identity import serialize_filesystem_identity as serialize_filesystem_identity
43
+ from filesystem_identity import (
44
+ serialize_filesystem_identity as serialize_filesystem_identity,
45
+ )
45
46
  from filesystem_identity import (
46
47
  stored_filesystem_identity_matches as stored_filesystem_identity_matches,
47
48
  )
@@ -51,11 +52,9 @@ from finalize_scan_contract import (
51
52
  RecoverableContractError,
52
53
  _prepare_scan_finalization,
53
54
  _write_prepared_scan_finalization,
54
- csv_cell,
55
55
  finalize_scan,
56
56
  finding_candidate_id,
57
57
  open_scan_local_file_descriptor,
58
- write_sarif_projection,
59
58
  write_scan_local_bytes,
60
59
  )
61
60
  from finding_preview import bounded_finding_details
@@ -80,8 +79,8 @@ from workbench_constants import (
80
79
  PATCH_PREVIEW_BYTES,
81
80
  SQLITE_RETRY_ATTEMPTS,
82
81
  )
83
- from workbench_feedback import get_scan_feedback
84
82
  from workbench_dashboard import dashboard
83
+ from workbench_feedback import get_scan_feedback
85
84
  from workbench_finding_index import index_findings
86
85
  from workbench_finding_workflows import finding_workflow, register_workflow_scan
87
86
  from workbench_findings import (
@@ -1023,7 +1022,10 @@ def _start_prompt_driven_scan(
1023
1022
  ).fetchone()
1024
1023
  if existing is not None:
1025
1024
  connection.commit()
1026
- return {**scan_context(connection, existing["id"]), "startDisposition": "joined"}
1025
+ return {
1026
+ **scan_context(connection, existing["id"]),
1027
+ "startDisposition": "joined",
1028
+ }
1027
1029
  target_root.mkdir(parents=True, exist_ok=True)
1028
1030
  workspace_id = str(uuid.uuid4())
1029
1031
  scan_id = str(uuid.uuid4())
@@ -1134,7 +1136,10 @@ def pin_legacy_manifest_digest(
1134
1136
 
1135
1137
 
1136
1138
  def complete_scan(
1137
- connection: sqlite3.Connection, args: argparse.Namespace, *, prepare_only: bool = False
1139
+ connection: sqlite3.Connection,
1140
+ args: argparse.Namespace,
1141
+ *,
1142
+ prepare_only: bool = False,
1138
1143
  ) -> dict[str, Any]:
1139
1144
  scan_id = require_uuid(args.scan_id, "scan-id")
1140
1145
  cost_json = None if prepare_only else parse_scan_cost(args.cost_json)
@@ -1347,8 +1352,7 @@ def budget_exhausted_draft(
1347
1352
  existing_deferred = {
1348
1353
  item.get("candidateId", item.get("id"))
1349
1354
  for item in coverage["deferred"]
1350
- if isinstance(item, dict)
1351
- and isinstance(item.get("candidateId", item.get("id")), str)
1355
+ if isinstance(item, dict) and isinstance(item.get("candidateId", item.get("id")), str)
1352
1356
  }
1353
1357
  existing_surfaces = {
1354
1358
  item.get("id")
@@ -1551,9 +1555,7 @@ def complete_scan_locked(
1551
1555
  wrote = True
1552
1556
  manifest, findings, _ = _write_prepared_scan_finalization(prepared)
1553
1557
  except ContractError as exc:
1554
- if wrote or (
1555
- scan["mode"] == "deep" and not isinstance(exc, RecoverableContractError)
1556
- ):
1558
+ if wrote or (scan["mode"] == "deep" and not isinstance(exc, RecoverableContractError)):
1557
1559
  args = argparse.Namespace(claim_token=claim_token, cost_json=cost_json)
1558
1560
  args.message, args.scan_id = str(exc), scan_id
1559
1561
  fail_scan_locked(connection, args)
@@ -1788,6 +1790,31 @@ def set_scan_thread(connection: sqlite3.Connection, args: argparse.Namespace) ->
1788
1790
  return {"scanId": scan["id"], "threadId": args.thread_id}
1789
1791
 
1790
1792
 
1793
+ def set_scan_cost_limit(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
1794
+ scan_id = require_uuid(args.scan_id, "scan-id")
1795
+ limit = args.max_cost_usd
1796
+ if not math.isfinite(limit) or limit <= 0:
1797
+ raise SystemExit("The scan cost limit must be a positive finite USD amount.")
1798
+ with scan_completion_lock(scan_id), connection:
1799
+ scan = require_scan(connection, scan_id)
1800
+ if scan["status"] != "running" or scan["recipe_json"] is None:
1801
+ raise SystemExit("Only a running CLI scan can increase its cost limit.")
1802
+ recipe = json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json)
1803
+ previous = recipe.get("maxCostUsd")
1804
+ if (
1805
+ not isinstance(previous, (int, float))
1806
+ or isinstance(previous, bool)
1807
+ or limit <= previous
1808
+ ):
1809
+ raise SystemExit("The new cost limit must exceed the current limit.")
1810
+ recipe["maxCostUsd"] = limit
1811
+ connection.execute(
1812
+ "UPDATE scans SET recipe_json = ?, updated_at = ? WHERE id = ?",
1813
+ (json.dumps(recipe, allow_nan=False), now(), scan["id"]),
1814
+ )
1815
+ return {"scanId": scan["id"], "maxCostUsd": limit}
1816
+
1817
+
1791
1818
  def parse_scan_recipe(value: str, repository: Path) -> dict[str, Any]:
1792
1819
  if len(value.encode("utf-8")) > SCAN_RECIPE_MAX_BYTES:
1793
1820
  raise SystemExit("Scan launch recipe must be no larger than 256 KiB.")
@@ -1861,20 +1888,10 @@ def preserve_scan_results_locked(connection: sqlite3.Connection, scan_id: str) -
1861
1888
  return saved_results.preserve_scan_results_locked(_WORKBENCH_DB_CONTEXT, connection, scan_id)
1862
1889
 
1863
1890
 
1864
- def refresh_stopped_scan_results(
1865
- connection: sqlite3.Connection, scan_id: str, *, strict: bool = False
1866
- ) -> None:
1867
- saved_results.refresh_stopped_scan_results(
1868
- _WORKBENCH_DB_CONTEXT, connection, scan_id, strict=strict
1869
- )
1870
-
1871
-
1872
- def refresh_all_stopped_scan_results(connection: sqlite3.Connection) -> None:
1873
- scan_ids = [
1874
- row["id"] for row in connection.execute("SELECT id FROM scans WHERE status = 'failed'")
1875
- ]
1876
- for scan_id in scan_ids:
1877
- refresh_stopped_scan_results(connection, scan_id)
1891
+ def recover_scan_results(
1892
+ connection: sqlite3.Connection, args: argparse.Namespace
1893
+ ) -> dict[str, Any]:
1894
+ return saved_results.recover_scan_results(_WORKBENCH_DB_CONTEXT, connection, args)
1878
1895
 
1879
1896
 
1880
1897
  def preserve_scan_results(
@@ -1969,7 +1986,14 @@ def set_finding_triage(connection: sqlite3.Connection, args: argparse.Namespace)
1969
1986
  id, occurrence_id, status, close_reason, note, created_at
1970
1987
  ) VALUES (?, ?, ?, ?, ?, ?)
1971
1988
  """,
1972
- (str(uuid.uuid4()), occurrence["id"], args.status, close_reason, note, timestamp),
1989
+ (
1990
+ str(uuid.uuid4()),
1991
+ occurrence["id"],
1992
+ args.status,
1993
+ close_reason,
1994
+ note,
1995
+ timestamp,
1996
+ ),
1973
1997
  )
1974
1998
  connection.execute(
1975
1999
  """
@@ -2330,8 +2354,8 @@ def set_finding_remediation(
2330
2354
  )
2331
2355
  if current["pending_action_claim_token"] != action_token:
2332
2356
  raise SystemExit("This remediation host request is owned by a different action token.")
2333
- require_remediation_transition(current["state"], args.state)
2334
- require_pending_remediation_action(current, args.state)
2357
+ remediation.require_transition(current["state"], args.state)
2358
+ remediation.require_pending_action(current, args.state)
2335
2359
  patch_path = current["patch_path"]
2336
2360
  if args.patch_path is not None:
2337
2361
  requested_patch_path = require_scan_relative_file(scan, args.patch_path)
@@ -2432,494 +2456,15 @@ def set_finding_remediation(
2432
2456
  return scan_context(connection, occurrence["scan_id"])
2433
2457
 
2434
2458
 
2435
- def linear_publication_input(
2436
- args: argparse.Namespace, *, recording: bool
2437
- ) -> tuple[dict[str, Any], dict[str, str], list[dict[str, str]]]:
2438
- payload = read_json_object(Path(args.input_file))
2439
- required = {"scanId", "scanDirectory", "destination", "findings"}
2440
- if recording:
2441
- required.add("publications")
2442
- if set(payload) != required:
2443
- raise SystemExit("Linear publication input contains unexpected or missing fields.")
2444
-
2445
- scan_id = payload["scanId"]
2446
- scan_directory = payload["scanDirectory"]
2447
- destination = payload["destination"]
2448
- findings = payload["findings"]
2449
- if not isinstance(scan_id, str) or not isinstance(scan_directory, str):
2450
- raise SystemExit("Linear publication input must identify the exact completed scan.")
2451
- if (
2452
- not isinstance(destination, dict)
2453
- or not {"type", "teamId"}.issubset(destination)
2454
- or not set(destination).issubset({"type", "teamId", "projectId"})
2455
- or destination.get("type") != "linear"
2456
- or not isinstance(destination.get("teamId"), str)
2457
- or not destination["teamId"].strip()
2458
- or (
2459
- "projectId" in destination
2460
- and (
2461
- not isinstance(destination["projectId"], str)
2462
- or not destination["projectId"].strip()
2463
- )
2464
- )
2465
- ):
2466
- raise SystemExit("Linear publication input must identify the exact team and optional project.")
2467
- if not isinstance(findings, list):
2468
- raise SystemExit("Linear publication input must include the planned scan findings.")
2469
-
2470
- seen_finding_ids: set[str] = set()
2471
- seen_occurrence_ids: set[str] = set()
2472
- for finding in findings:
2473
- if (
2474
- not isinstance(finding, dict)
2475
- or set(finding) != {"findingId", "occurrenceId"}
2476
- or not isinstance(finding.get("findingId"), str)
2477
- or not finding["findingId"].strip()
2478
- or not isinstance(finding.get("occurrenceId"), str)
2479
- or not finding["occurrenceId"].strip()
2480
- ):
2481
- raise SystemExit("Linear publication input contains an invalid finding identity.")
2482
- if (
2483
- finding["findingId"] in seen_finding_ids
2484
- or finding["occurrenceId"] in seen_occurrence_ids
2485
- ):
2486
- raise SystemExit("Linear publication input repeats a finding or occurrence.")
2487
- seen_finding_ids.add(finding["findingId"])
2488
- seen_occurrence_ids.add(finding["occurrenceId"])
2489
-
2490
- return payload, destination, findings
2491
-
2492
-
2493
- def verify_linear_publication_scan(
2494
- connection: sqlite3.Connection,
2495
- payload: dict[str, Any],
2496
- findings: list[dict[str, str]],
2497
- ) -> sqlite3.Row:
2498
- try:
2499
- scan = require_scan(connection, payload["scanId"])
2500
- except SystemExit as exc:
2501
- raise SystemExit(
2502
- "The completed scan is not present in the local Codex Security scan-history database. "
2503
- "Use the state directory where the scan was completed."
2504
- ) from exc
2505
- if scan["id"] != payload["scanId"]:
2506
- raise SystemExit("Linear publication must use the exact completed scan identifier.")
2507
- if scan["status"] != "complete":
2508
- raise SystemExit("Only completed scans can publish findings to Linear.")
2509
-
2510
- requested_directory = require_canonical_scan_directory(Path(payload["scanDirectory"]))
2511
- recorded_directory = require_canonical_scan_directory(Path(scan["scan_dir"]))
2512
- if os.path.normcase(requested_directory) != os.path.normcase(recorded_directory):
2513
- raise SystemExit(
2514
- "The selected scan directory does not match its local Codex Security scan history."
2515
- )
2516
- if "seal_manifest_digest" in scan.keys():
2517
- require_recorded_manifest_digest(scan, recorded_directory)
2518
-
2519
- stored_findings = {
2520
- row["id"]: row["finding_id"]
2521
- for row in connection.execute(
2522
- "SELECT id, finding_id FROM finding_occurrences WHERE scan_id = ?",
2523
- (scan["id"],),
2524
- )
2525
- }
2526
- for finding in findings:
2527
- if stored_findings.get(finding["occurrenceId"]) != finding["findingId"]:
2528
- raise SystemExit(
2529
- "A selected finding or occurrence does not belong to the completed scan "
2530
- "in local Codex Security scan history."
2531
- )
2532
- if len(stored_findings) != len(findings):
2533
- raise SystemExit(
2534
- "The completed scan findings do not exactly match local Codex Security scan history."
2535
- )
2536
- return scan
2459
+ _WORKBENCH_PUBLICATION_CONTEXT: publication.WorkbenchPublicationContext
2537
2460
 
2538
2461
 
2539
2462
  def inspect_linear_publication(args: argparse.Namespace) -> dict[str, Any]:
2540
- payload, destination, findings = linear_publication_input(args, recording=False)
2541
- database_uri = f"file:{quote(str(database_path()), safe='')}?mode=ro"
2542
- with closing(sqlite3.connect(database_uri, uri=True, timeout=5)) as connection:
2543
- connection.row_factory = sqlite3.Row
2544
- connection.execute("BEGIN")
2545
- scan = verify_linear_publication_scan(connection, payload, findings)
2546
- recorded: dict[str, dict[str, str]] = {}
2547
- if connection.execute(
2548
- "SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'finding_publications'"
2549
- ).fetchone():
2550
- for row in connection.execute(
2551
- """
2552
- SELECT finding_id, occurrence_id, external_id, external_url
2553
- FROM finding_publications
2554
- WHERE scan_id = ? AND destination_type = ? AND team_id = ? AND project_id IS ?
2555
- ORDER BY created_at, external_id
2556
- """,
2557
- (
2558
- scan["id"],
2559
- destination["type"],
2560
- destination["teamId"],
2561
- destination.get("projectId"),
2562
- ),
2563
- ):
2564
- recorded.setdefault(
2565
- row["occurrence_id"],
2566
- {
2567
- "findingId": row["finding_id"],
2568
- "occurrenceId": row["occurrence_id"],
2569
- "issueIdentifier": row["external_id"],
2570
- **({"url": row["external_url"]} if row["external_url"] is not None else {}),
2571
- },
2572
- )
2573
- return {
2574
- "scanId": scan["id"],
2575
- "destination": destination,
2576
- "findingCount": len(findings),
2577
- "recorded": [
2578
- recorded[finding["occurrenceId"]]
2579
- for finding in findings
2580
- if finding["occurrenceId"] in recorded
2581
- ],
2582
- }
2583
-
2584
-
2585
- def prepare_linear_publication(
2586
- connection: sqlite3.Connection, args: argparse.Namespace
2587
- ) -> dict[str, Any]:
2588
- payload, destination, findings = linear_publication_input(args, recording=False)
2589
- connection.execute("BEGIN IMMEDIATE")
2590
- try:
2591
- scan = verify_linear_publication_scan(connection, payload, findings)
2592
- result = {
2593
- "scanId": scan["id"],
2594
- "destination": destination,
2595
- "findingCount": len(findings),
2596
- }
2597
- connection.commit()
2598
- except BaseException:
2599
- connection.rollback()
2600
- raise
2601
- return result
2602
-
2603
-
2604
- def record_linear_publications(
2605
- connection: sqlite3.Connection, args: argparse.Namespace
2606
- ) -> dict[str, Any]:
2607
- payload, destination, findings = linear_publication_input(args, recording=True)
2608
- publications = payload["publications"]
2609
- if not isinstance(publications, list):
2610
- raise SystemExit("Linear publication results must be an array.")
2611
- planned = {finding["findingId"]: finding["occurrenceId"] for finding in findings}
2612
- current: dict[str, dict[str, str]] = {}
2613
- external_ids: set[str] = set()
2614
- for publication in publications:
2615
- if (
2616
- not isinstance(publication, dict)
2617
- or not {"findingId", "occurrenceId", "issueIdentifier"}.issubset(publication)
2618
- or not set(publication).issubset(
2619
- {"findingId", "occurrenceId", "issueIdentifier", "url"}
2620
- )
2621
- or not isinstance(publication.get("findingId"), str)
2622
- or not isinstance(publication.get("occurrenceId"), str)
2623
- or not isinstance(publication.get("issueIdentifier"), str)
2624
- or not publication["issueIdentifier"].strip()
2625
- or (
2626
- "url" in publication
2627
- and (
2628
- not isinstance(publication["url"], str)
2629
- or not publication["url"].strip()
2630
- )
2631
- )
2632
- ):
2633
- raise SystemExit("Linear publication results contain an invalid issue association.")
2634
- finding_id = publication["findingId"]
2635
- issue_identifier = publication["issueIdentifier"]
2636
- if planned.get(finding_id) != publication["occurrenceId"]:
2637
- raise SystemExit(
2638
- "A created Linear issue does not match its planned finding and occurrence."
2639
- )
2640
- if finding_id in current or issue_identifier in external_ids:
2641
- raise SystemExit("Linear publication results repeat a finding or issue identifier.")
2642
- current[finding_id] = publication
2643
- external_ids.add(issue_identifier)
2644
-
2645
- connection.execute("BEGIN IMMEDIATE")
2646
- try:
2647
- scan = verify_linear_publication_scan(connection, payload, findings)
2648
- timestamp = now()
2649
- for publication in publications:
2650
- conflicting = connection.execute(
2651
- """
2652
- SELECT occurrence_id, external_url
2653
- FROM finding_publications
2654
- WHERE destination_type = ? AND team_id = ? AND project_id IS ?
2655
- AND external_id = ?
2656
- """,
2657
- (
2658
- destination["type"],
2659
- destination["teamId"],
2660
- destination.get("projectId"),
2661
- publication["issueIdentifier"],
2662
- ),
2663
- ).fetchone()
2664
- if conflicting is not None and conflicting["occurrence_id"] != publication[
2665
- "occurrenceId"
2666
- ]:
2667
- raise SystemExit("This Linear issue is already associated with a different finding.")
2668
- if (
2669
- conflicting is not None
2670
- and "url" in publication
2671
- and conflicting["external_url"] != publication["url"]
2672
- ):
2673
- raise SystemExit("This Linear issue is already associated with a different URL.")
2674
-
2675
- connection.execute(
2676
- """
2677
- INSERT INTO finding_publications (
2678
- scan_id, finding_id, occurrence_id, destination_type,
2679
- team_id, project_id, external_id, external_url, created_at
2680
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
2681
- ON CONFLICT DO NOTHING
2682
- """,
2683
- (
2684
- scan["id"],
2685
- publication["findingId"],
2686
- publication["occurrenceId"],
2687
- destination["type"],
2688
- destination["teamId"],
2689
- destination.get("projectId"),
2690
- publication["issueIdentifier"],
2691
- publication.get("url"),
2692
- timestamp,
2693
- ),
2694
- )
2695
-
2696
- created = []
2697
- for finding in findings:
2698
- publication = current.get(finding["findingId"])
2699
- if publication is None:
2700
- continue
2701
- row = connection.execute(
2702
- """
2703
- SELECT finding_id, occurrence_id, external_id, external_url
2704
- FROM finding_publications
2705
- WHERE scan_id = ? AND occurrence_id = ? AND destination_type = ?
2706
- AND team_id = ? AND project_id IS ? AND external_id = ?
2707
- """,
2708
- (
2709
- scan["id"],
2710
- publication["occurrenceId"],
2711
- destination["type"],
2712
- destination["teamId"],
2713
- destination.get("projectId"),
2714
- publication["issueIdentifier"],
2715
- ),
2716
- ).fetchone()
2717
- if row is None:
2718
- raise SystemExit("A created Linear issue could not be read from scan history.")
2719
- created.append(
2720
- {
2721
- "findingId": row["finding_id"],
2722
- "occurrenceId": row["occurrence_id"],
2723
- "issueIdentifier": row["external_id"],
2724
- **({"url": row["external_url"]} if row["external_url"] is not None else {}),
2725
- }
2726
- )
2727
- result = {"scanId": scan["id"], "destination": destination, "created": created}
2728
- connection.commit()
2729
- except BaseException:
2730
- connection.rollback()
2731
- raise
2732
- return result
2463
+ return publication.inspect_linear_publication(_WORKBENCH_PUBLICATION_CONTEXT, args)
2733
2464
 
2734
2465
 
2735
2466
  def export_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
2736
- refresh_stopped_scan_results(connection, args.scan_id, strict=True)
2737
- scan = require_scan(connection, args.scan_id)
2738
- if scan["status"] != "complete" and not (
2739
- scan["status"] == "failed" and scan["seal_manifest_digest"]
2740
- ):
2741
- raise SystemExit(
2742
- "Findings can be exported after the scan completes or preserves stopped results."
2743
- )
2744
- scan_dir = require_canonical_scan_directory(Path(scan["scan_dir"]))
2745
- require_recorded_manifest_digest(scan, scan_dir)
2746
- verify_manifest_binding(scan, read_json_object(scan_dir / ARTIFACTS["manifest"]))
2747
- try:
2748
- manifest, _, _ = finalize_scan(
2749
- scan_dir,
2750
- expected_coverage_mode=expected_coverage_mode(scan),
2751
- )
2752
- except ContractError as exc:
2753
- raise SystemExit(str(exc)) from exc
2754
- verify_manifest_binding(scan, manifest)
2755
- manifest_digest = published_manifest_digest(scan_dir, manifest)
2756
- pin_legacy_manifest_digest(connection, scan["id"], manifest_digest)
2757
- if args.format == "json":
2758
- path = artifact_path(scan_dir, ARTIFACTS["findings"], required=True)
2759
- elif args.format == "sarif":
2760
- try:
2761
- write_sarif_projection(scan_dir)
2762
- except ContractError as exc:
2763
- raise SystemExit(str(exc)) from exc
2764
- path = artifact_path(scan_dir, "exports/results.sarif", required=True)
2765
- else:
2766
- path = write_csv_export(connection, scan)
2767
- if path is None:
2768
- raise SystemExit(f"Could not export Codex Security findings as {args.format.upper()}.")
2769
- return {
2770
- "export": {"format": args.format, "path": str(path)},
2771
- "scan": scan_result(connection, scan),
2772
- "workspace": workspace_state(connection, scan["workspace_id"]),
2773
- }
2774
-
2775
-
2776
- def write_csv_export(connection: sqlite3.Connection, scan: sqlite3.Row) -> Path:
2777
- scan_dir = require_canonical_scan_directory(Path(scan["scan_dir"]))
2778
- output = io.StringIO(newline="")
2779
- writer = csv.writer(output)
2780
- deep_scan = scan["mode"] == "deep"
2781
- candidate_ids_by_occurrence: dict[str, str] = {}
2782
- if deep_scan:
2783
- findings_document = read_json_object(scan_dir / ARTIFACTS["findings"])
2784
- findings = findings_document.get("findings")
2785
- if not isinstance(findings, list):
2786
- raise SystemExit("findings.json must contain a findings array.")
2787
- for finding in findings:
2788
- if not isinstance(finding, dict):
2789
- raise SystemExit("findings.json entries must be objects.")
2790
- occurrence_id = finding.get("occurrenceId")
2791
- candidate_id = finding_candidate_id(finding)
2792
- if isinstance(occurrence_id, str) and isinstance(candidate_id, str):
2793
- candidate_ids_by_occurrence[occurrence_id] = candidate_id
2794
- columns = (
2795
- "occurrence_id",
2796
- "finding_id",
2797
- *(("candidate_id",) if deep_scan else ()),
2798
- "title",
2799
- "summary",
2800
- "severity",
2801
- "confidence",
2802
- "status",
2803
- "close_reason",
2804
- "note",
2805
- "remediation",
2806
- "path",
2807
- "start_line",
2808
- "end_line",
2809
- )
2810
- writer.writerow(columns)
2811
- for row in finding_export_rows(connection, scan["id"]):
2812
- writer.writerow(
2813
- (
2814
- csv_cell(row["occurrence_id"]),
2815
- csv_cell(row["finding_id"]),
2816
- *(
2817
- (csv_cell(candidate_ids_by_occurrence.get(row["occurrence_id"])),)
2818
- if deep_scan
2819
- else ()
2820
- ),
2821
- csv_cell(row["title"]),
2822
- csv_cell(row["summary"]),
2823
- csv_cell(row["severity"]),
2824
- csv_cell(row["confidence"]),
2825
- csv_cell(row["status"]),
2826
- csv_cell(row["close_reason"]),
2827
- csv_cell(row["note"]),
2828
- csv_cell(row["remediation"]),
2829
- csv_cell(row["relative_path"]),
2830
- row["start_line"],
2831
- row["end_line"],
2832
- )
2833
- )
2834
- try:
2835
- write_scan_local_bytes(
2836
- scan_dir,
2837
- "exports/findings.csv",
2838
- output.getvalue().encode("utf-8"),
2839
- )
2840
- except ContractError as exc:
2841
- raise SystemExit(
2842
- "exports: expected a regular directory inside the scan directory."
2843
- ) from exc
2844
- destination = scan_dir / "exports" / "findings.csv"
2845
- path = available_artifact_path(scan_dir, destination)
2846
- if path is None:
2847
- raise SystemExit("findings.csv: expected a regular file inside the scan directory.")
2848
- return path
2849
-
2850
-
2851
- def finding_export_rows(connection: sqlite3.Connection, scan_id: str) -> sqlite3.Cursor:
2852
- return connection.execute(
2853
- """
2854
- SELECT
2855
- occurrences.id AS occurrence_id,
2856
- occurrences.finding_id,
2857
- occurrences.title,
2858
- occurrences.summary,
2859
- occurrences.severity,
2860
- occurrences.confidence,
2861
- occurrences.remediation,
2862
- COALESCE(triage.status, 'open') AS status,
2863
- triage.close_reason,
2864
- triage.note,
2865
- locations.relative_path,
2866
- locations.start_line,
2867
- locations.end_line
2868
- FROM finding_occurrences AS occurrences
2869
- LEFT JOIN finding_triage AS triage ON triage.occurrence_id = occurrences.id
2870
- LEFT JOIN finding_locations AS locations
2871
- ON locations.occurrence_id = occurrences.id
2872
- AND locations.sort_order = (
2873
- SELECT primary_location.sort_order
2874
- FROM finding_locations AS primary_location
2875
- WHERE primary_location.occurrence_id = occurrences.id
2876
- ORDER BY
2877
- CASE WHEN primary_location.role = 'root_control' THEN 0 ELSE 1 END,
2878
- primary_location.sort_order
2879
- LIMIT 1
2880
- )
2881
- WHERE occurrences.scan_id = ?
2882
- ORDER BY occurrences.created_at, occurrences.id
2883
- """,
2884
- (scan_id,),
2885
- )
2886
-
2887
-
2888
- def require_remediation_transition(current: str, requested: str) -> None:
2889
- allowed = {
2890
- "requested": {"requested", "generated", "failed"},
2891
- "generated": {"generated", "applied", "failed"},
2892
- "applied": {"applied", "verifying", "failed"},
2893
- "verifying": {"verifying", "verified", "failed"},
2894
- "verified": {"verifying", "verified"},
2895
- "failed": {"generated", "applied", "verifying", "verified", "failed"},
2896
- }
2897
- if requested not in allowed.get(current, set()):
2898
- raise SystemExit(f"Finding remediation cannot move from {current} to {requested}.")
2899
-
2900
-
2901
- def require_pending_remediation_action(current: sqlite3.Row, requested: str) -> None:
2902
- pending_action = current["pending_action"]
2903
- if pending_action is not None:
2904
- allowed = {
2905
- "generate": {"generated", "failed"},
2906
- "apply": {"applied", "failed"},
2907
- "verify": {"verifying", "verified", "failed"},
2908
- }
2909
- if requested not in allowed[pending_action]:
2910
- raise SystemExit(
2911
- f"Pending remediation action {pending_action} cannot record state {requested}."
2912
- )
2913
- return
2914
- required_action = {
2915
- ("requested", "generated"): "generate",
2916
- ("generated", "applied"): "apply",
2917
- ("applied", "verifying"): "verify",
2918
- }.get((current["state"], requested))
2919
- if required_action is not None:
2920
- raise SystemExit(
2921
- f"Request {required_action} before recording remediation state {requested}."
2922
- )
2467
+ return publication.export_findings(_WORKBENCH_PUBLICATION_CONTEXT, connection, args)
2923
2468
 
2924
2469
 
2925
2470
  def require_reviewed_patch_applied(
@@ -3090,8 +2635,8 @@ def workspace_state(
3090
2635
  workspace_id: str,
3091
2636
  *,
3092
2637
  result_scan_id: str | None = None,
2638
+ result_scan: dict[str, Any] | None = None,
3093
2639
  thread_id: str | None = None,
3094
- refresh_stopped: bool = False,
3095
2640
  ) -> dict[str, Any]:
3096
2641
  workspace = require_workspace(connection, workspace_id)
3097
2642
  if thread_id is not None and workspace["thread_id"] != optional_text(thread_id, maximum=512):
@@ -3112,11 +2657,11 @@ def workspace_state(
3112
2657
  }
3113
2658
  selected_scan_id = result_scan_id or workspace["active_scan_id"]
3114
2659
  if selected_scan_id:
3115
- if refresh_stopped:
3116
- refresh_stopped_scan_results(connection, selected_scan_id)
3117
2660
  selected_scan = require_scan(connection, selected_scan_id)
3118
2661
  result["userContext"] = selected_scan["user_context"]
3119
- result["results"] = scan_result(connection, selected_scan)
2662
+ result["results"] = (
2663
+ result_scan if result_scan is not None else scan_result(connection, selected_scan)
2664
+ )
3120
2665
  return result
3121
2666
 
3122
2667
  target_metadata = None
@@ -3158,14 +2703,17 @@ def scan_context(
3158
2703
  occurrence_id: str | None = None,
3159
2704
  ) -> dict[str, Any]:
3160
2705
  scan = require_scan(connection, scan_id)
3161
- workspace = workspace_state(connection, scan["workspace_id"], result_scan_id=scan["id"])
2706
+ result = scan_result(connection, scan, occurrence_id=occurrence_id)
2707
+ workspace_result = result if occurrence_id is None else scan_result(connection, scan)
2708
+ workspace = workspace_state(
2709
+ connection,
2710
+ scan["workspace_id"],
2711
+ result_scan_id=scan["id"],
2712
+ result_scan=workspace_result,
2713
+ )
3162
2714
  context = {
3163
2715
  "otherRunningDeepScans": deep_scan.other_running_deep_scans(connection, scan["id"]),
3164
- "scan": (
3165
- workspace["results"]
3166
- if occurrence_id is None
3167
- else scan_result(connection, scan, occurrence_id=occurrence_id)
3168
- ),
2716
+ "scan": result,
3169
2717
  "workspace": workspace,
3170
2718
  }
3171
2719
  if scan["recipe_json"] is not None:
@@ -3175,7 +2723,6 @@ def scan_context(
3175
2723
 
3176
2724
 
3177
2725
  def list_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
3178
- refresh_stopped_scan_results(connection, args.scan_id)
3179
2726
  scan = require_scan(connection, args.scan_id)
3180
2727
  backfill_legacy_finding_details(connection, scan)
3181
2728
  limit = min(args.limit, FINDINGS_PAGE_MAX)
@@ -3201,9 +2748,13 @@ def list_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> d
3201
2748
  values,
3202
2749
  ).fetchone()[0]
3203
2750
  next_offset = args.offset + len(rows)
2751
+ relations = scan_history.finding_relations(connection, scan["id"], (row["id"] for row in rows))
3204
2752
  return {
3205
2753
  "findingsPage": {
3206
- "findings": [finding_result(connection, scan, row) for row in rows],
2754
+ "findings": [
2755
+ finding_result(connection, scan, row, related=relations.get(row["id"], []))
2756
+ for row in rows
2757
+ ],
3207
2758
  "limit": limit,
3208
2759
  "nextOffset": next_offset if next_offset < total else None,
3209
2760
  "offset": args.offset,
@@ -3293,8 +2844,12 @@ def scan_result(
3293
2844
  progress_result["independentReviews"] = {
3294
2845
  "active": independent_reviews["active"],
3295
2846
  "completed": independent_reviews["completed"],
2847
+ "maximum": independent_reviews["maximum"],
3296
2848
  "consolidating": independent_reviews["consolidating"],
3297
2849
  }
2850
+ relations = scan_history.finding_relations(
2851
+ connection, scan["id"], (row["id"] for row in occurrence_rows)
2852
+ )
3298
2853
  return {
3299
2854
  "artifacts": artifacts,
3300
2855
  "canceledAt": scan["canceled_at"],
@@ -3302,7 +2857,10 @@ def scan_result(
3302
2857
  "contract": scan_contract(scan),
3303
2858
  "continuationThreadId": scan["continuation_thread_id"],
3304
2859
  "failureMessage": scan["failure_message"],
3305
- "findings": [finding_result(connection, scan, row) for row in occurrence_rows],
2860
+ "findings": [
2861
+ finding_result(connection, scan, row, related=relations.get(row["id"], []))
2862
+ for row in occurrence_rows
2863
+ ],
3306
2864
  "findingCount": finding_count,
3307
2865
  "findingsTruncated": finding_count > len(occurrence_rows),
3308
2866
  "severityCounts": severity_counts,
@@ -3317,6 +2875,9 @@ def scan_result(
3317
2875
  "remediationAvailable": remediation_available,
3318
2876
  "remediationUnavailableReason": remediation_unavailable_reason,
3319
2877
  "reportAvailable": "markdownReport" in artifacts,
2878
+ "resultsRecoveryNeeded": saved_results.scan_results_recovery_needed(
2879
+ _WORKBENCH_DB_CONTEXT, connection, scan
2880
+ ),
3320
2881
  "scanDir": scan["scan_dir"],
3321
2882
  "scanId": scan["id"],
3322
2883
  "scope": scan["scope"],
@@ -3449,6 +3010,8 @@ def finding_result(
3449
3010
  connection: sqlite3.Connection,
3450
3011
  scan: sqlite3.Row,
3451
3012
  occurrence: sqlite3.Row,
3013
+ *,
3014
+ related: list[dict[str, Any]],
3452
3015
  ) -> dict[str, Any]:
3453
3016
  details = bounded_finding_details(read_finding_details(occurrence["details_json"]))
3454
3017
  confidence = details.get("confidence")
@@ -3513,6 +3076,8 @@ def finding_result(
3513
3076
  result["matches"] = matches
3514
3077
  result["knownSince"] = known_since
3515
3078
  result["knownScanIds"] = known_scan_ids
3079
+ if related:
3080
+ result["related"] = related
3516
3081
  result.pop("artifactPaths", None)
3517
3082
  source_excerpt = finding_source_excerpt(scan, target, locations)
3518
3083
  if source_excerpt:
@@ -3768,9 +3333,7 @@ def require_canonical_scan_directory(scan_dir: Path) -> Path:
3768
3333
  # Re-check privacy so a shared parent cannot be used to substitute forged artifacts.
3769
3334
  if os.name != "nt":
3770
3335
  if stat.S_IMODE(metadata.st_mode) & 0o077:
3771
- raise SystemExit(
3772
- "Scan directory must not be accessible to other users (chmod 700)."
3773
- )
3336
+ raise SystemExit("Scan directory must not be accessible to other users (chmod 700).")
3774
3337
  geteuid = getattr(os, "geteuid", None)
3775
3338
  effective_uid = geteuid() if geteuid is not None else None
3776
3339
  if effective_uid is not None and metadata.st_uid != effective_uid:
@@ -3780,9 +3343,7 @@ def require_canonical_scan_directory(scan_dir: Path) -> Path:
3780
3343
  parent_metadata = parent.lstat()
3781
3344
  except OSError as exc:
3782
3345
  raise SystemExit("Scan output parent could not be inspected.") from exc
3783
- if not stat.S_ISDIR(parent_metadata.st_mode) or stat.S_ISLNK(
3784
- parent_metadata.st_mode
3785
- ):
3346
+ if not stat.S_ISDIR(parent_metadata.st_mode) or stat.S_ISLNK(parent_metadata.st_mode):
3786
3347
  raise SystemExit("Scan output parent must be a non-symlink directory.")
3787
3348
  if effective_uid is not None and parent_metadata.st_uid not in {
3788
3349
  0,
@@ -3816,6 +3377,25 @@ def reject_non_finite_json(value: str) -> None:
3816
3377
  raise ValueError(f"non-finite JSON number {value!r} is not supported")
3817
3378
 
3818
3379
 
3380
+ _WORKBENCH_PUBLICATION_CONTEXT = publication.WorkbenchPublicationContext(
3381
+ ARTIFACTS=ARTIFACTS,
3382
+ artifact_path=artifact_path,
3383
+ available_artifact_path=available_artifact_path,
3384
+ database_path=database_path,
3385
+ expected_coverage_mode=expected_coverage_mode,
3386
+ now=now,
3387
+ pin_legacy_manifest_digest=pin_legacy_manifest_digest,
3388
+ published_manifest_digest=published_manifest_digest,
3389
+ read_json_object=read_json_object,
3390
+ require_canonical_scan_directory=require_canonical_scan_directory,
3391
+ require_recorded_manifest_digest=require_recorded_manifest_digest,
3392
+ require_scan=require_scan,
3393
+ scan_result=scan_result,
3394
+ verify_manifest_binding=verify_manifest_binding,
3395
+ workspace_state=workspace_state,
3396
+ )
3397
+
3398
+
3819
3399
  _WORKBENCH_DB_CONTEXT = saved_results.WorkbenchDbContext(
3820
3400
  ARTIFACTS=ARTIFACTS,
3821
3401
  artifact_path=artifact_path,
@@ -3884,7 +3464,6 @@ def main() -> None:
3884
3464
  connection,
3885
3465
  args.workspace_id,
3886
3466
  thread_id=args.thread_id,
3887
- refresh_stopped=True,
3888
3467
  )
3889
3468
  elif args.command == "save-workspace":
3890
3469
  result = save_workspace(connection, args)
@@ -3913,12 +3492,10 @@ def main() -> None:
3913
3492
  elif args.command == "record-deep-scan-publication-failure":
3914
3493
  result = deep_scan.record_deep_scan_publication_failure(connection, args)
3915
3494
  elif args.command == "get-scan":
3916
- refresh_stopped_scan_results(connection, args.scan_id)
3917
3495
  result = scan_context(connection, args.scan_id, args.occurrence_id)
3918
3496
  elif args.command == "get-scan-feedback":
3919
3497
  result = get_scan_feedback(connection, require_scan(connection, args.scan_id))
3920
3498
  elif args.command == "list-scans":
3921
- refresh_all_stopped_scan_results(connection)
3922
3499
  result = scan_history.list_scans(connection, args)
3923
3500
  elif args.command == "list-unmatched-scan-pairs":
3924
3501
  result = scan_history.list_unmatched_scan_pairs(
@@ -3931,6 +3508,8 @@ def main() -> None:
3931
3508
  result = register_cli_scan(connection, args)
3932
3509
  elif args.command == "set-scan-thread":
3933
3510
  result = set_scan_thread(connection, args)
3511
+ elif args.command == "set-scan-cost-limit":
3512
+ result = set_scan_cost_limit(connection, args)
3934
3513
  elif args.command == "get-scan-recipe":
3935
3514
  result = get_scan_recipe(connection, args)
3936
3515
  elif args.command == "compare-scans":
@@ -3952,10 +3531,8 @@ def main() -> None:
3952
3531
  read_coverage=coverage_for_comparison,
3953
3532
  )
3954
3533
  elif args.command == "list-global-findings":
3955
- refresh_all_stopped_scan_results(connection)
3956
3534
  result = native_indexes.list_global_findings(connection, args)
3957
3535
  elif args.command == "list-repositories":
3958
- refresh_all_stopped_scan_results(connection)
3959
3536
  result = native_indexes.list_repositories(connection, args)
3960
3537
  elif args.command == "list-findings":
3961
3538
  result = list_findings(connection, args)
@@ -3975,6 +3552,8 @@ def main() -> None:
3975
3552
  result = fail_scan(connection, args)
3976
3553
  elif args.command == "preserve-scan-results":
3977
3554
  result = preserve_scan_results(connection, args)
3555
+ elif args.command == "recover-scan-results":
3556
+ result = recover_scan_results(connection, args)
3978
3557
  elif args.command == "write-scan-draft":
3979
3558
  result = write_scan_draft(connection, args)
3980
3559
  elif args.command == "mark-handoff-delivered":
@@ -4025,14 +3604,19 @@ def main() -> None:
4025
3604
  result = release_finding_remediation_claim(connection, args)
4026
3605
  elif args.command == "cancel-finding-remediation-request":
4027
3606
  result = scan_context(
4028
- connection, remediation.cancel_finding_remediation_request(connection, args)
3607
+ connection,
3608
+ remediation.cancel_finding_remediation_request(connection, args),
4029
3609
  )
4030
3610
  elif args.command == "set-finding-remediation":
4031
3611
  result = set_finding_remediation(connection, args)
4032
3612
  elif args.command == "prepare-linear-publication":
4033
- result = prepare_linear_publication(connection, args)
3613
+ result = publication.prepare_linear_publication(
3614
+ _WORKBENCH_PUBLICATION_CONTEXT, connection, args
3615
+ )
4034
3616
  elif args.command == "record-linear-publications":
4035
- result = record_linear_publications(connection, args)
3617
+ result = publication.record_linear_publications(
3618
+ _WORKBENCH_PUBLICATION_CONTEXT, connection, args
3619
+ )
4036
3620
  elif args.command == "export-findings":
4037
3621
  result = export_findings(connection, args)
4038
3622
  elif args.command == "database-info":
@@ -4043,7 +3627,9 @@ def main() -> None:
4043
3627
  result = dashboard(connection, json.load(sys.stdin))
4044
3628
  elif args.command == "store-findings":
4045
3629
  payload = json.load(sys.stdin)
4046
- result = store_findings(connection, payload["entries"], now(), payload.get("repositoryId"))
3630
+ result = store_findings(
3631
+ connection, payload["entries"], now(), payload.get("repositoryId")
3632
+ )
4047
3633
  elif args.command == "find-potential-duplicates":
4048
3634
  result = find_potential_duplicates(connection, args.finding_id, args.repository_id)
4049
3635
  elif args.command == "store-dedupe-groups":