@openai/codex-security 0.1.25 → 0.1.27
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.
- package/README.md +616 -34
- package/_bundled_plugin/.app.json +0 -5
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/.mcp.json +2 -0
- package/_bundled_plugin/mcp/helpers.mjs +24 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/COPYRIGHT-library.html +5556 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +5989 -0
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/licenses/Apache-2.0.txt +73 -0
- package/_bundled_plugin/mcp/native/licenses/BSD-2-Clause.txt +9 -0
- package/_bundled_plugin/mcp/native/licenses/MIT.txt +9 -0
- package/_bundled_plugin/mcp/native/licenses/Unicode-3.0.txt +39 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/references/config-preflight.md +4 -2
- package/_bundled_plugin/references/core-scan.md +1 -1
- package/_bundled_plugin/references/final-report.md +5 -3
- package/_bundled_plugin/references/scan-artifacts.md +5 -1
- package/_bundled_plugin/references/scan-contract.md +42 -38
- package/_bundled_plugin/references/security-guidance.md +7 -1
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +27 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +6 -1
- package/_bundled_plugin/scripts/finalize_scan_contract.py +2 -5
- package/_bundled_plugin/scripts/generate_in_scope_files.py +2 -2
- package/_bundled_plugin/scripts/generate_rank_input.py +8 -1
- package/_bundled_plugin/scripts/launch_codex_security_mcp +6 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +43 -9
- package/_bundled_plugin/scripts/rank_preview.py +4 -1
- package/_bundled_plugin/scripts/report_projection.py +1 -1
- package/_bundled_plugin/scripts/workbench_cli.py +7 -0
- package/_bundled_plugin/scripts/workbench_db.py +44 -31
- package/_bundled_plugin/scripts/workbench_saved_results.py +41 -22
- package/_bundled_plugin/scripts/workbench_scan_history.py +117 -2
- package/_bundled_plugin/scripts/workbench_scan_usage.py +7 -6
- package/_bundled_plugin/scripts/workbench_schema.py +31 -0
- package/_bundled_plugin/scripts/workbench_severity.py +119 -0
- package/_bundled_plugin/scripts/workbench_validation.py +4 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +5 -3
- package/_bundled_plugin/skills/define-security-policy/SKILL.md +3 -3
- package/_bundled_plugin/skills/verify-fix/SKILL.md +5 -1
- package/dist/api.d.ts +7 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +485 -65
- package/dist/api.js.map +1 -1
- package/dist/auth.js +10 -0
- package/dist/auth.js.map +1 -1
- package/dist/classify-scan-severity.d.ts +16 -0
- package/dist/classify-scan-severity.d.ts.map +1 -0
- package/dist/classify-scan-severity.js +96 -0
- package/dist/classify-scan-severity.js.map +1 -0
- package/dist/classify-severity.d.ts +38 -0
- package/dist/classify-severity.d.ts.map +1 -0
- package/dist/classify-severity.js +185 -0
- package/dist/classify-severity.js.map +1 -0
- package/dist/cli.d.ts +23 -4
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1277 -357
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +2 -207
- package/dist/cloud-publish.js.map +1 -1
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +116 -32
- package/dist/component-plan.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +17 -2
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +5 -10
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts +16 -0
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +57 -3
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +38 -9
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.js +1 -1
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +6 -1
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +72 -17
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +1 -1
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.d.ts +2 -0
- package/dist/deduplication/deduplication.d.ts.map +1 -1
- package/dist/deduplication/deduplication.js +99 -26
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/retry.d.ts +3 -0
- package/dist/deduplication/retry.d.ts.map +1 -0
- package/dist/deduplication/retry.js +15 -0
- package/dist/deduplication/retry.js.map +1 -0
- package/dist/deduplication/scan.d.ts +2 -0
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +4 -2
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/feedback.d.ts +20 -0
- package/dist/feedback.d.ts.map +1 -0
- package/dist/feedback.js +121 -0
- package/dist/feedback.js.map +1 -0
- package/dist/finding-catalogue.d.ts +11 -0
- package/dist/finding-catalogue.d.ts.map +1 -0
- package/dist/finding-catalogue.js +150 -0
- package/dist/finding-catalogue.js.map +1 -0
- package/dist/findings-client.d.ts +7 -1
- package/dist/findings-client.d.ts.map +1 -1
- package/dist/findings-client.js +55 -10
- package/dist/findings-client.js.map +1 -1
- package/dist/findings-import.d.ts +44 -0
- package/dist/findings-import.d.ts.map +1 -0
- package/dist/findings-import.js +302 -0
- package/dist/findings-import.js.map +1 -0
- package/dist/import-scan.d.ts +27 -0
- package/dist/import-scan.d.ts.map +1 -0
- package/dist/import-scan.js +236 -0
- package/dist/import-scan.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +2 -2
- package/dist/knowledge-base.js.map +1 -1
- package/dist/multiscan.d.ts +2 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +144 -52
- package/dist/multiscan.js.map +1 -1
- package/dist/patch-tui.js +1 -1
- package/dist/patch-tui.js.map +1 -1
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +7 -2
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +9 -4
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts +9 -0
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +45 -5
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts +4 -2
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +2 -2
- package/dist/publish.js.map +1 -1
- package/dist/runtime.d.ts +5 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +8 -2
- package/dist/runtime.js.map +1 -1
- package/dist/scan-comparison.d.ts +42 -37
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +535 -161
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +19 -6
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +5 -0
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts +29 -0
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +36 -5
- package/dist/scan-logs.js.map +1 -1
- package/dist/security-policy-cli.d.ts +39 -0
- package/dist/security-policy-cli.d.ts.map +1 -0
- package/dist/security-policy-cli.js +193 -0
- package/dist/security-policy-cli.js.map +1 -0
- package/dist/security-policy.d.ts +80 -0
- package/dist/security-policy.d.ts.map +1 -0
- package/dist/security-policy.js +672 -0
- package/dist/security-policy.js.map +1 -0
- package/dist/severity-store.d.ts +2 -0
- package/dist/severity-store.d.ts.map +1 -0
- package/dist/severity-store.js +111 -0
- package/dist/severity-store.js.map +1 -0
- package/dist/targets.d.ts +8 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +243 -14
- package/dist/targets.js.map +1 -1
- package/dist/thread-source.d.ts +1 -0
- package/dist/thread-source.d.ts.map +1 -1
- package/dist/thread-source.js +1 -0
- package/dist/thread-source.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +10 -6
- package/_bundled_plugin/scripts/resolve_security_md.py +0 -158
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
setlocal DisableDelayedExpansion
|
|
3
3
|
|
|
4
4
|
set "CODEX_SECURITY_MCP_SCRIPT=%~dp0..\mcp\server.mjs"
|
|
5
|
+
if "%~1"=="--helper" (
|
|
6
|
+
set "CODEX_SECURITY_MCP_SCRIPT=%~dp0..\mcp\helpers.mjs"
|
|
7
|
+
goto launch
|
|
8
|
+
)
|
|
5
9
|
|
|
6
10
|
rem This process waits for Node and must not keep the installed plugin directory locked.
|
|
7
11
|
if "%~d0"=="" (cd /d "%SystemRoot%") else (cd /d "%~d0\")
|
|
@@ -10,18 +14,48 @@ if errorlevel 1 (
|
|
|
10
14
|
exit /b 1
|
|
11
15
|
)
|
|
12
16
|
|
|
17
|
+
:launch
|
|
13
18
|
rem WindowsApps can expose a Node path that exists but cannot be executed.
|
|
14
19
|
rem Prefer relocated user-writable runtimes before probing packaged paths.
|
|
15
|
-
if defined LOCALAPPDATA for /d %%D in ("%LOCALAPPDATA%\OpenAI\Codex\runtimes\cua_node\*") do if exist "%%~fD\bin\node.exe" (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if defined
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
if defined LOCALAPPDATA for /d %%D in ("%LOCALAPPDATA%\OpenAI\Codex\runtimes\cua_node\*") do if exist "%%~fD\bin\node.exe" (
|
|
21
|
+
set "CODEX_SECURITY_MCP_NODE=%%~fD\bin\node.exe"
|
|
22
|
+
goto run
|
|
23
|
+
)
|
|
24
|
+
if defined XDG_CACHE_HOME if exist "%XDG_CACHE_HOME%\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe" (
|
|
25
|
+
set "CODEX_SECURITY_MCP_NODE=%XDG_CACHE_HOME%\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe"
|
|
26
|
+
goto run
|
|
27
|
+
)
|
|
28
|
+
if defined USERPROFILE if exist "%USERPROFILE%\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe" (
|
|
29
|
+
set "CODEX_SECURITY_MCP_NODE=%USERPROFILE%\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe"
|
|
30
|
+
goto run
|
|
31
|
+
)
|
|
32
|
+
if defined CODEX_MCP_NODE_PATH if exist "%CODEX_MCP_NODE_PATH%" (
|
|
33
|
+
set "CODEX_SECURITY_MCP_NODE=%CODEX_MCP_NODE_PATH%"
|
|
34
|
+
goto run
|
|
35
|
+
)
|
|
36
|
+
if defined CODEX_BROWSER_USE_NODE_PATH if exist "%CODEX_BROWSER_USE_NODE_PATH%" (
|
|
37
|
+
set "CODEX_SECURITY_MCP_NODE=%CODEX_BROWSER_USE_NODE_PATH%"
|
|
38
|
+
goto run
|
|
39
|
+
)
|
|
40
|
+
if defined CODEX_ELECTRON_RESOURCES_PATH if exist "%CODEX_ELECTRON_RESOURCES_PATH%\cua_node\bin\node.exe" (
|
|
41
|
+
set "CODEX_SECURITY_MCP_NODE=%CODEX_ELECTRON_RESOURCES_PATH%\cua_node\bin\node.exe"
|
|
42
|
+
goto run
|
|
43
|
+
)
|
|
44
|
+
if defined CODEX_CLI_PATH for %%I in ("%CODEX_CLI_PATH%") do if exist "%%~dpIcua_node\bin\node.exe" (
|
|
45
|
+
set "CODEX_SECURITY_MCP_NODE=%%~dpIcua_node\bin\node.exe"
|
|
46
|
+
goto run
|
|
47
|
+
)
|
|
22
48
|
|
|
23
|
-
|
|
24
|
-
|
|
49
|
+
rem Resolve Node from PATH once and launch that exact executable.
|
|
50
|
+
set "CODEX_SECURITY_MCP_SEARCH_PATH=%PATH:"=%"
|
|
51
|
+
for %%I in (node.exe) do set "CODEX_SECURITY_MCP_NODE=%%~$CODEX_SECURITY_MCP_SEARCH_PATH:I"
|
|
52
|
+
if defined CODEX_SECURITY_MCP_NODE goto run
|
|
25
53
|
|
|
26
54
|
echo Codex Security could not find a Node runtime. Reinstall or update Codex, or set CODEX_MCP_NODE_PATH to an executable Node runtime. 1>&2
|
|
27
55
|
exit /b 127
|
|
56
|
+
|
|
57
|
+
:run
|
|
58
|
+
rem Direct invocation also chains batch shims without CALL reparsing paths.
|
|
59
|
+
"%CODEX_SECURITY_MCP_NODE%" "%CODEX_SECURITY_MCP_SCRIPT%" %*
|
|
60
|
+
if "%~1"=="--helper" exit /b %errorlevel%
|
|
61
|
+
exit
|
|
@@ -17,10 +17,12 @@ TEXT_CODE_EXTENSIONS = {
|
|
|
17
17
|
".c",
|
|
18
18
|
".cc",
|
|
19
19
|
".cfg",
|
|
20
|
+
".cjs",
|
|
20
21
|
".clj",
|
|
21
22
|
".cpp",
|
|
22
23
|
".cs",
|
|
23
24
|
".css",
|
|
25
|
+
".cts",
|
|
24
26
|
".cue",
|
|
25
27
|
".cxx",
|
|
26
28
|
".dart",
|
|
@@ -41,6 +43,7 @@ TEXT_CODE_EXTENSIONS = {
|
|
|
41
43
|
".lua",
|
|
42
44
|
".mjs",
|
|
43
45
|
".mm",
|
|
46
|
+
".mts",
|
|
44
47
|
".php",
|
|
45
48
|
".proto",
|
|
46
49
|
".ps1",
|
|
@@ -62,7 +65,7 @@ TEXT_CODE_EXTENSIONS = {
|
|
|
62
65
|
".yml",
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
JAVASCRIPT_EXTENSIONS = {".js", ".jsx", ".mjs", ".ts", ".tsx", ".vue"}
|
|
68
|
+
JAVASCRIPT_EXTENSIONS = {".cjs", ".cts", ".js", ".jsx", ".mjs", ".mts", ".ts", ".tsx", ".vue"}
|
|
66
69
|
JAVA_LIKE_EXTENSIONS = {".c", ".cc", ".cpp", ".cs", ".cxx", ".h", ".hpp", ".java", ".mm"}
|
|
67
70
|
BRACE_LANGUAGE_EXTENSIONS = {
|
|
68
71
|
*JAVASCRIPT_EXTENSIONS,
|
|
@@ -814,7 +814,7 @@ def build_report_markdown(
|
|
|
814
814
|
"",
|
|
815
815
|
_text(
|
|
816
816
|
scope.get("summary"),
|
|
817
|
-
"The scan
|
|
817
|
+
"The scan was configured for the include paths and exclusions listed below.",
|
|
818
818
|
),
|
|
819
819
|
"",
|
|
820
820
|
f"- Scan mode: {coverage['mode']}",
|
|
@@ -167,6 +167,10 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
167
167
|
get_scan_recipe = subparsers.add_parser("get-scan-recipe")
|
|
168
168
|
get_scan_recipe.add_argument("--scan-id", required=True)
|
|
169
169
|
|
|
170
|
+
get_cli_scan_resume = subparsers.add_parser("get-cli-scan-resume")
|
|
171
|
+
get_cli_scan_resume.add_argument("--scan-id", required=True)
|
|
172
|
+
get_cli_scan_resume.add_argument("--allow-unavailable", action="store_true")
|
|
173
|
+
|
|
170
174
|
compare_scans = subparsers.add_parser("compare-scans")
|
|
171
175
|
compare_scans.add_argument("--before-scan-id", required=True)
|
|
172
176
|
compare_scans.add_argument("--after-scan-id", required=True)
|
|
@@ -354,6 +358,9 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
354
358
|
subparsers.add_parser("database-info")
|
|
355
359
|
subparsers.add_parser("dashboard")
|
|
356
360
|
subparsers.add_parser("finding-workflow")
|
|
361
|
+
subparsers.add_parser("severity-classification")
|
|
362
|
+
severity = subparsers.add_parser("read-severity-classification")
|
|
363
|
+
severity.add_argument("--scan-id", required=True)
|
|
357
364
|
subparsers.add_parser("store-findings")
|
|
358
365
|
subparsers.add_parser("store-dedupe-groups")
|
|
359
366
|
dedupe_groups = subparsers.add_parser("list-dedupe-groups")
|
|
@@ -40,6 +40,7 @@ import workbench_remediation as remediation
|
|
|
40
40
|
import workbench_saved_results as saved_results
|
|
41
41
|
import workbench_scan_history as scan_history
|
|
42
42
|
import workbench_scan_usage as scan_usage
|
|
43
|
+
import workbench_severity as severity
|
|
43
44
|
from filesystem_identity import (
|
|
44
45
|
serialize_filesystem_identity as serialize_filesystem_identity,
|
|
45
46
|
)
|
|
@@ -137,6 +138,7 @@ from workbench_validation import (
|
|
|
137
138
|
optional_text,
|
|
138
139
|
parse_scan_cost,
|
|
139
140
|
path_within_scope,
|
|
141
|
+
reject_non_finite_json,
|
|
140
142
|
require_close_note,
|
|
141
143
|
require_occurrence,
|
|
142
144
|
require_uuid,
|
|
@@ -502,7 +504,9 @@ def expected_coverage_mode(scan: sqlite3.Row) -> str:
|
|
|
502
504
|
return "deep_repository" if scan["mode"] == "deep" else "repository"
|
|
503
505
|
|
|
504
506
|
|
|
505
|
-
def workbench_completion_binding(
|
|
507
|
+
def workbench_completion_binding(
|
|
508
|
+
scan: sqlite3.Row, completed_at: str, manifest: dict[str, Any] | None = None
|
|
509
|
+
) -> dict[str, Any]:
|
|
506
510
|
contract = scan_contract(scan)
|
|
507
511
|
target_contract = contract["target"]
|
|
508
512
|
plugin_manifest = read_json_object(
|
|
@@ -531,7 +535,7 @@ def workbench_completion_binding(scan: sqlite3.Row, completed_at: str) -> dict[s
|
|
|
531
535
|
"excludePaths": contract["scope"]["requiredExcludePaths"],
|
|
532
536
|
}
|
|
533
537
|
|
|
534
|
-
|
|
538
|
+
binding: dict[str, Any] = {
|
|
535
539
|
"scanId": scan["id"],
|
|
536
540
|
"startedAt": scan["started_at"],
|
|
537
541
|
"completedAt": completed_at,
|
|
@@ -541,6 +545,7 @@ def workbench_completion_binding(scan: sqlite3.Row, completed_at: str) -> dict[s
|
|
|
541
545
|
"scope": scope,
|
|
542
546
|
"coverageMode": expected_coverage_mode(scan),
|
|
543
547
|
}
|
|
548
|
+
return scan_history.preserve_sealed_completion(binding, manifest)
|
|
544
549
|
|
|
545
550
|
|
|
546
551
|
def verify_manifest_binding(scan: sqlite3.Row, manifest: dict[str, Any]) -> None:
|
|
@@ -1483,8 +1488,8 @@ def complete_scan_locked(
|
|
|
1483
1488
|
add_warning()
|
|
1484
1489
|
scan_dir = require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
1485
1490
|
completion_timestamp = now()
|
|
1486
|
-
completion_binding = workbench_completion_binding(scan, completion_timestamp)
|
|
1487
1491
|
current_manifest_path = artifact_path(scan_dir, ARTIFACTS["manifest"], required=False)
|
|
1492
|
+
current_manifest = None
|
|
1488
1493
|
if current_manifest_path is not None:
|
|
1489
1494
|
current_manifest = read_json_object(current_manifest_path)
|
|
1490
1495
|
if (
|
|
@@ -1502,8 +1507,8 @@ def complete_scan_locked(
|
|
|
1502
1507
|
or current_manifest["scan"].get("artifacts") is not None
|
|
1503
1508
|
)
|
|
1504
1509
|
)
|
|
1510
|
+
completion_binding = workbench_completion_binding(scan, completion_timestamp, current_manifest)
|
|
1505
1511
|
if scan["recipe_json"] is not None:
|
|
1506
|
-
draft_artifacts: dict[str, Path] = {}
|
|
1507
1512
|
missing_drafts = []
|
|
1508
1513
|
for file_name in (
|
|
1509
1514
|
ARTIFACTS["manifest"],
|
|
@@ -1515,27 +1520,22 @@ def complete_scan_locked(
|
|
|
1515
1520
|
except FileNotFoundError:
|
|
1516
1521
|
missing_drafts.append(file_name)
|
|
1517
1522
|
continue
|
|
1518
|
-
|
|
1519
|
-
if draft_path is not None:
|
|
1520
|
-
draft_artifacts[file_name] = draft_path
|
|
1523
|
+
artifact_path(scan_dir, file_name, required=True)
|
|
1521
1524
|
if missing_drafts:
|
|
1522
1525
|
raise SystemExit(
|
|
1523
1526
|
"Scan agent did not create required draft artifacts: "
|
|
1524
1527
|
f"{', '.join(missing_drafts)}. Check that the scan agent can run shell "
|
|
1525
1528
|
"commands and write to the scan directory before retrying."
|
|
1526
1529
|
)
|
|
1527
|
-
manifest = read_json_object(draft_artifacts[ARTIFACTS["manifest"]])
|
|
1528
|
-
manifest_scan = manifest.get("scan")
|
|
1529
|
-
if isinstance(manifest_scan, dict) and manifest_scan.get("sealedAt") is not None:
|
|
1530
|
-
completion_binding["startedAt"] = manifest_scan.get("startedAt")
|
|
1531
|
-
completion_binding["completedAt"] = manifest_scan.get("completedAt")
|
|
1532
1530
|
wrote = False
|
|
1533
1531
|
try:
|
|
1534
1532
|
prepared = _prepare_scan_finalization(
|
|
1535
1533
|
scan_dir,
|
|
1536
1534
|
expected_coverage_mode=expected_coverage_mode(scan),
|
|
1537
1535
|
completion_binding=completion_binding,
|
|
1538
|
-
|
|
1536
|
+
# Save the finished Deep result as submitted. Worker drafts and
|
|
1537
|
+
# recovery repairs belong to the stopped-scan path.
|
|
1538
|
+
completion_warnings=warnings if scan["mode"] != "deep" else None,
|
|
1539
1539
|
draft_documents=saved_results.merge_saved_results(
|
|
1540
1540
|
scan_dir,
|
|
1541
1541
|
scan["id"],
|
|
@@ -1548,14 +1548,18 @@ def complete_scan_locked(
|
|
|
1548
1548
|
stopped=False,
|
|
1549
1549
|
reason="",
|
|
1550
1550
|
)
|
|
1551
|
-
if current_manifest_path is not None and not already_sealed
|
|
1551
|
+
if scan["mode"] != "deep" and current_manifest_path is not None and not already_sealed
|
|
1552
1552
|
else None,
|
|
1553
1553
|
)
|
|
1554
1554
|
add_warning()
|
|
1555
1555
|
wrote = True
|
|
1556
1556
|
manifest, findings, _ = _write_prepared_scan_finalization(prepared)
|
|
1557
1557
|
except ContractError as exc:
|
|
1558
|
-
if wrote or (
|
|
1558
|
+
if wrote or (
|
|
1559
|
+
scan["mode"] == "deep"
|
|
1560
|
+
and not already_sealed
|
|
1561
|
+
and not isinstance(exc, RecoverableContractError)
|
|
1562
|
+
):
|
|
1559
1563
|
args = argparse.Namespace(claim_token=claim_token, cost_json=cost_json)
|
|
1560
1564
|
args.message, args.scan_id = str(exc), scan_id
|
|
1561
1565
|
fail_scan_locked(connection, args)
|
|
@@ -1866,17 +1870,6 @@ def parse_scan_recipe(value: str, repository: Path) -> dict[str, Any]:
|
|
|
1866
1870
|
return recipe
|
|
1867
1871
|
|
|
1868
1872
|
|
|
1869
|
-
def get_scan_recipe(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1870
|
-
scan = require_scan(connection, args.scan_id)
|
|
1871
|
-
if scan["recipe_json"] is None:
|
|
1872
|
-
raise SystemExit("This scan does not have a saved launch recipe.")
|
|
1873
|
-
return {
|
|
1874
|
-
"parentScanId": scan["parent_scan_id"],
|
|
1875
|
-
"recipe": json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json),
|
|
1876
|
-
"scanId": scan["id"],
|
|
1877
|
-
}
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
1873
|
_WORKBENCH_DB_CONTEXT: saved_results.WorkbenchDbContext
|
|
1881
1874
|
|
|
1882
1875
|
|
|
@@ -3373,10 +3366,6 @@ def read_json_object(path: Path) -> dict[str, Any]:
|
|
|
3373
3366
|
return payload
|
|
3374
3367
|
|
|
3375
3368
|
|
|
3376
|
-
def reject_non_finite_json(value: str) -> None:
|
|
3377
|
-
raise ValueError(f"non-finite JSON number {value!r} is not supported")
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
3369
|
_WORKBENCH_PUBLICATION_CONTEXT = publication.WorkbenchPublicationContext(
|
|
3381
3370
|
ARTIFACTS=ARTIFACTS,
|
|
3382
3371
|
artifact_path=artifact_path,
|
|
@@ -3451,6 +3440,10 @@ def main() -> None:
|
|
|
3451
3440
|
result = inspect_setup(args)
|
|
3452
3441
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
3453
3442
|
return
|
|
3443
|
+
if args.command == "read-severity-classification":
|
|
3444
|
+
result = severity.read_classification(database_path(), args.scan_id)
|
|
3445
|
+
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
3446
|
+
return
|
|
3454
3447
|
if args.command == "inspect-linear-publication":
|
|
3455
3448
|
result = inspect_linear_publication(args)
|
|
3456
3449
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
@@ -3511,7 +3504,25 @@ def main() -> None:
|
|
|
3511
3504
|
elif args.command == "set-scan-cost-limit":
|
|
3512
3505
|
result = set_scan_cost_limit(connection, args)
|
|
3513
3506
|
elif args.command == "get-scan-recipe":
|
|
3514
|
-
result =
|
|
3507
|
+
result = scan_history.scan_recipe(require_scan(connection, args.scan_id))
|
|
3508
|
+
elif args.command == "get-cli-scan-resume":
|
|
3509
|
+
scan = require_scan(connection, args.scan_id)
|
|
3510
|
+
try:
|
|
3511
|
+
result = scan_history.cli_scan_resume(
|
|
3512
|
+
connection,
|
|
3513
|
+
scan,
|
|
3514
|
+
require_workspace(connection, scan["workspace_id"]),
|
|
3515
|
+
parse_scan_recipe=parse_scan_recipe,
|
|
3516
|
+
scan_contract=scan_contract,
|
|
3517
|
+
require_scan_directory=require_canonical_scan_directory,
|
|
3518
|
+
artifact_path=artifact_path,
|
|
3519
|
+
read_json_object=read_json_object,
|
|
3520
|
+
workbench_completion_binding=workbench_completion_binding,
|
|
3521
|
+
)
|
|
3522
|
+
except SystemExit as exc:
|
|
3523
|
+
if not args.allow_unavailable:
|
|
3524
|
+
raise
|
|
3525
|
+
result = {"unavailable": str(exc)}
|
|
3515
3526
|
elif args.command == "compare-scans":
|
|
3516
3527
|
result = scan_history.compare_scans(
|
|
3517
3528
|
connection,
|
|
@@ -3621,6 +3632,8 @@ def main() -> None:
|
|
|
3621
3632
|
result = export_findings(connection, args)
|
|
3622
3633
|
elif args.command == "database-info":
|
|
3623
3634
|
result = {"databasePath": str(database_path())}
|
|
3635
|
+
elif args.command == "severity-classification":
|
|
3636
|
+
result = severity.checkpoint(connection, json.load(sys.stdin), now())
|
|
3624
3637
|
elif args.command == "finding-workflow":
|
|
3625
3638
|
result = finding_workflow(connection, json.load(sys.stdin), now())
|
|
3626
3639
|
elif args.command == "dashboard":
|
|
@@ -112,13 +112,13 @@ def _latest_successful_reducer(workers: list[Any]) -> Any | None:
|
|
|
112
112
|
)
|
|
113
113
|
|
|
114
114
|
|
|
115
|
-
def _saved_result_paths(scan_dir: Path, workers: list[Any]) -> Iterator[str]:
|
|
115
|
+
def _saved_result_paths(scan_dir: Path, workers: list[Any]) -> Iterator[tuple[str, str | None]]:
|
|
116
116
|
latest_reducer = _latest_successful_reducer(workers)
|
|
117
117
|
|
|
118
|
-
def checkpoints(directory: str) -> Iterator[str]:
|
|
118
|
+
def checkpoints(directory: str, kind: str | None = None) -> Iterator[tuple[str, str | None]]:
|
|
119
119
|
for name in _children(scan_dir, directory):
|
|
120
120
|
if re.fullmatch(r"[0-9a-f]{64}\.json", name):
|
|
121
|
-
yield f"{directory}/{name}"
|
|
121
|
+
yield f"{directory}/{name}", kind
|
|
122
122
|
|
|
123
123
|
yield from checkpoints("checkpoints")
|
|
124
124
|
for worker in workers:
|
|
@@ -137,25 +137,32 @@ def _saved_result_paths(scan_dir: Path, workers: list[Any]) -> Iterator[str]:
|
|
|
137
137
|
if re.fullmatch(r"attempt-\d+", name)
|
|
138
138
|
]
|
|
139
139
|
for directory in directories:
|
|
140
|
-
checkpoint_paths = list(checkpoints(f"{directory}/checkpoints"))
|
|
140
|
+
checkpoint_paths = list(checkpoints(f"{directory}/checkpoints", worker["kind"]))
|
|
141
141
|
if worker["kind"] == "discovery" or checkpoint_paths:
|
|
142
|
-
yield f"{directory}/result.json"
|
|
142
|
+
yield f"{directory}/result.json", worker["kind"]
|
|
143
143
|
yield from checkpoint_paths
|
|
144
144
|
if worker["result_manifest_path"] and (
|
|
145
145
|
worker["kind"] == "discovery"
|
|
146
146
|
or (latest_reducer is not None and worker["id"] == latest_reducer["id"])
|
|
147
147
|
):
|
|
148
148
|
try:
|
|
149
|
-
yield
|
|
149
|
+
yield (
|
|
150
|
+
Path(worker["result_manifest_path"]).relative_to(scan_dir).as_posix(),
|
|
151
|
+
worker["kind"],
|
|
152
|
+
)
|
|
150
153
|
except ValueError:
|
|
151
154
|
continue
|
|
152
155
|
|
|
153
156
|
|
|
154
|
-
def _read_saved_result(
|
|
157
|
+
def _read_saved_result(
|
|
158
|
+
scan_dir: Path, relative: str, scan_id: str, *, kind: str | None = None
|
|
159
|
+
) -> tuple[dict[str, Any], str]:
|
|
155
160
|
draft = _read_scan_local_json(scan_dir, relative, "Saved scan checkpoint")
|
|
156
161
|
if draft.get("scanId") != scan_id:
|
|
157
162
|
raise ContractError("checkpoint belongs to a different scan")
|
|
158
|
-
if not isinstance(draft.get("findings"), list) or not isinstance(
|
|
163
|
+
if not isinstance(draft.get("findings"), list) or not isinstance(
|
|
164
|
+
draft.get("coverage", {} if kind == "dedup" else None), dict
|
|
165
|
+
):
|
|
159
166
|
raise ContractError("checkpoint has no semantic findings or coverage")
|
|
160
167
|
return draft, _digest(draft)
|
|
161
168
|
|
|
@@ -207,13 +214,13 @@ def _saved_results_changed(db: Any, connection: Any, scan: Any) -> bool:
|
|
|
207
214
|
"FROM deep_scan_workers WHERE scan_id = ?",
|
|
208
215
|
(scan["id"],),
|
|
209
216
|
).fetchall()
|
|
210
|
-
paths =
|
|
217
|
+
paths = dict(_saved_result_paths(scan_dir, workers))
|
|
211
218
|
frozen_sources = scan["retained_source_digests_json"]
|
|
212
219
|
|
|
213
220
|
def has_saved_source() -> bool:
|
|
214
221
|
for path in paths:
|
|
215
222
|
try:
|
|
216
|
-
_read_saved_result(scan_dir, path, scan["id"])
|
|
223
|
+
_read_saved_result(scan_dir, path, scan["id"], kind=paths[path])
|
|
217
224
|
return True
|
|
218
225
|
except (ContractError, OSError, ValueError):
|
|
219
226
|
continue
|
|
@@ -244,7 +251,9 @@ def _saved_results_changed(db: Any, connection: Any, scan: Any) -> bool:
|
|
|
244
251
|
current_sources = dict(published_sources)
|
|
245
252
|
for path in paths:
|
|
246
253
|
try:
|
|
247
|
-
_, current_sources[path] = _read_saved_result(
|
|
254
|
+
_, current_sources[path] = _read_saved_result(
|
|
255
|
+
scan_dir, path, scan["id"], kind=paths[path]
|
|
256
|
+
)
|
|
248
257
|
except (ContractError, OSError, ValueError):
|
|
249
258
|
continue
|
|
250
259
|
return current_sources != published_sources
|
|
@@ -290,23 +299,26 @@ def _recovery_source_digests(db: Any, connection: Any, scan: Any) -> tuple[dict[
|
|
|
290
299
|
else:
|
|
291
300
|
include_parent = True
|
|
292
301
|
|
|
302
|
+
workers = connection.execute(
|
|
303
|
+
"SELECT id, kind, status, completed_at, artifact_dir, result_manifest_path "
|
|
304
|
+
"FROM deep_scan_workers WHERE scan_id = ?",
|
|
305
|
+
(scan["id"],),
|
|
306
|
+
).fetchall()
|
|
307
|
+
paths = dict(_saved_result_paths(scan_dir, workers))
|
|
293
308
|
recovery_sources = dict(frozen_sources or {})
|
|
294
309
|
for relative, expected_digest in recovery_sources.items():
|
|
295
310
|
try:
|
|
296
|
-
_, digest = _read_saved_result(scan_dir, relative, scan["id"])
|
|
311
|
+
_, digest = _read_saved_result(scan_dir, relative, scan["id"], kind=paths.get(relative))
|
|
297
312
|
except (ContractError, OSError, ValueError) as exc:
|
|
298
313
|
raise ContractError("Frozen stopped-scan checkpoint set is incomplete.") from exc
|
|
299
314
|
if digest != expected_digest:
|
|
300
315
|
raise ContractError("checkpoint changed after the scan stopped")
|
|
301
316
|
|
|
302
|
-
|
|
303
|
-
"SELECT id, kind, status, completed_at, artifact_dir, result_manifest_path "
|
|
304
|
-
"FROM deep_scan_workers WHERE scan_id = ?",
|
|
305
|
-
(scan["id"],),
|
|
306
|
-
).fetchall()
|
|
307
|
-
for relative in set(_saved_result_paths(scan_dir, workers)) - recovery_sources.keys():
|
|
317
|
+
for relative in paths.keys() - recovery_sources.keys():
|
|
308
318
|
try:
|
|
309
|
-
_, recovery_sources[relative] = _read_saved_result(
|
|
319
|
+
_, recovery_sources[relative] = _read_saved_result(
|
|
320
|
+
scan_dir, relative, scan["id"], kind=paths[relative]
|
|
321
|
+
)
|
|
310
322
|
except (ContractError, OSError, ValueError):
|
|
311
323
|
continue
|
|
312
324
|
return recovery_sources, include_parent
|
|
@@ -489,6 +501,7 @@ def merge_saved_results(
|
|
|
489
501
|
parent_preserved_sources = recorded
|
|
490
502
|
source_digests.update(parent_preserved_sources)
|
|
491
503
|
paths: dict[str, str | None] = {}
|
|
504
|
+
reducer_paths: set[str] = set()
|
|
492
505
|
current_results: set[str] = set()
|
|
493
506
|
reducer_outputs: list[tuple[Any, str, list[str], int]] = []
|
|
494
507
|
reducer = _latest_successful_reducer(workers)
|
|
@@ -497,6 +510,7 @@ def merge_saved_results(
|
|
|
497
510
|
try:
|
|
498
511
|
latest_reducer = Path(reducer["result_manifest_path"]).relative_to(scan_dir).as_posix()
|
|
499
512
|
paths[latest_reducer] = None
|
|
513
|
+
reducer_paths.add(latest_reducer)
|
|
500
514
|
except ValueError:
|
|
501
515
|
warnings.append("Skipped a reducer result outside the scan directory.")
|
|
502
516
|
|
|
@@ -526,6 +540,7 @@ def merge_saved_results(
|
|
|
526
540
|
paths[result_path] = None
|
|
527
541
|
for checkpoint_path in checkpoint_paths:
|
|
528
542
|
paths[checkpoint_path] = None
|
|
543
|
+
reducer_paths.update([result_path, *checkpoint_paths])
|
|
529
544
|
reducer_outputs.append((reducer_worker, result_path, checkpoint_paths, attempt))
|
|
530
545
|
|
|
531
546
|
reducer_output(output, int(worker["attempt"] or 0), worker)
|
|
@@ -570,11 +585,15 @@ def merge_saved_results(
|
|
|
570
585
|
|
|
571
586
|
for relative, worker_id in paths.items():
|
|
572
587
|
try:
|
|
573
|
-
draft, digest = _read_saved_result(
|
|
588
|
+
draft, digest = _read_saved_result(
|
|
589
|
+
scan_dir, relative, scan_id, kind="dedup" if relative in reducer_paths else None
|
|
590
|
+
)
|
|
574
591
|
if frozen_source_digests is not None and frozen_source_digests[relative] != digest:
|
|
575
592
|
raise ContractError("checkpoint changed after the scan stopped")
|
|
576
593
|
source_digests[relative] = digest
|
|
577
|
-
|
|
594
|
+
# Recovery expects coverage, but reducer results only contain findings
|
|
595
|
+
# and context. Add an empty value after hashing the original result.
|
|
596
|
+
sources.append((relative, {"coverage": {}, **draft}, worker_id))
|
|
578
597
|
except (ContractError, OSError, ValueError) as exc:
|
|
579
598
|
if (scan_dir / relative).exists():
|
|
580
599
|
warnings.append(f"Preserved unreadable checkpoint {relative}: {exc}")
|
|
@@ -645,7 +664,7 @@ def merge_saved_results(
|
|
|
645
664
|
manifest["scan"]["preservedSources"] = source_digests
|
|
646
665
|
coverage = (
|
|
647
666
|
copy.deepcopy(parent["coverage"])
|
|
648
|
-
if parent
|
|
667
|
+
if parent and parent["coverage"]
|
|
649
668
|
else {
|
|
650
669
|
"completeness": "partial",
|
|
651
670
|
"mode": binding["coverageMode"],
|
|
@@ -14,10 +14,125 @@ from urllib.parse import urlsplit
|
|
|
14
14
|
|
|
15
15
|
# Some plugin hosts launch Python with safe-path isolation enabled.
|
|
16
16
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
17
|
+
from finalize_scan_contract import ContractError, _prepare_scan_finalization
|
|
17
18
|
from report_projection import SEVERITY_ORDER
|
|
18
|
-
from workbench_constants import FINDINGS_PAGE_MAX
|
|
19
|
+
from workbench_constants import ARTIFACTS, FINDINGS_PAGE_MAX
|
|
20
|
+
from workbench_scan_start import scan_target_identity
|
|
19
21
|
from workbench_scan_usage import stored_scan_cost_fields
|
|
20
|
-
from workbench_target import git_output
|
|
22
|
+
from workbench_target import git_output, require_scan_target_identity
|
|
23
|
+
from workbench_validation import reject_non_finite_json
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def scan_recipe(scan: sqlite3.Row) -> dict[str, Any]:
|
|
27
|
+
if scan["recipe_json"] is None:
|
|
28
|
+
raise SystemExit("This scan does not have a saved launch recipe.")
|
|
29
|
+
return {
|
|
30
|
+
"parentScanId": scan["parent_scan_id"],
|
|
31
|
+
"recipe": json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json),
|
|
32
|
+
"scanId": scan["id"],
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def preserve_sealed_completion(
|
|
37
|
+
binding: dict[str, Any], manifest: dict[str, Any] | None
|
|
38
|
+
) -> dict[str, Any]:
|
|
39
|
+
manifest_scan = manifest.get("scan") if manifest is not None else None
|
|
40
|
+
if isinstance(manifest_scan, dict) and manifest_scan.get("sealedAt") is not None:
|
|
41
|
+
# Keep the original producer; finalization still validates schema, seal and owner.
|
|
42
|
+
binding["startedAt"] = manifest_scan.get("startedAt")
|
|
43
|
+
binding["completedAt"] = manifest_scan.get("completedAt")
|
|
44
|
+
producer = manifest_scan.get("producer")
|
|
45
|
+
if isinstance(producer, dict):
|
|
46
|
+
binding["producer"]["version"] = producer.get("version")
|
|
47
|
+
return binding
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def cli_scan_resume(
|
|
51
|
+
connection: sqlite3.Connection,
|
|
52
|
+
scan: sqlite3.Row,
|
|
53
|
+
workspace: sqlite3.Row,
|
|
54
|
+
*,
|
|
55
|
+
parse_scan_recipe: Callable[[str, Path], dict[str, Any]],
|
|
56
|
+
scan_contract: Callable[[sqlite3.Row], dict[str, Any]],
|
|
57
|
+
require_scan_directory: Callable[[Path], Path],
|
|
58
|
+
artifact_path: Callable[..., Path | None],
|
|
59
|
+
read_json_object: Callable[[Path], dict[str, Any]],
|
|
60
|
+
workbench_completion_binding: Callable[..., dict[str, Any]],
|
|
61
|
+
) -> dict[str, Any]:
|
|
62
|
+
if scan["mode"] != "deep" or scan["recipe_json"] is None:
|
|
63
|
+
raise SystemExit("Resume requires a Deep Scan with a saved CLI launch recipe.")
|
|
64
|
+
if scan["status"] != "running" or scan["canceled_at"] is not None:
|
|
65
|
+
raise SystemExit(
|
|
66
|
+
"Resume requires a running scan; completed, failed, and canceled scans cannot resume."
|
|
67
|
+
)
|
|
68
|
+
thread_id = scan["continuation_thread_id"]
|
|
69
|
+
owner = scan["deep_scan_owner_thread_id"] or workspace["thread_id"]
|
|
70
|
+
if (
|
|
71
|
+
not thread_id
|
|
72
|
+
or (owner is not None and owner != thread_id)
|
|
73
|
+
or scan["handoff_status"] != "delivered"
|
|
74
|
+
or scan["handoff_claim_token"] is not None
|
|
75
|
+
):
|
|
76
|
+
raise SystemExit("Resume requires the original owning CLI session.")
|
|
77
|
+
run = connection.execute(
|
|
78
|
+
"SELECT status, cancel_requested FROM deep_scan_runs WHERE scan_id = ?", (scan["id"],)
|
|
79
|
+
).fetchone()
|
|
80
|
+
if run is not None and (
|
|
81
|
+
run["status"] not in {"running", "succeeded"} or run["cancel_requested"]
|
|
82
|
+
):
|
|
83
|
+
raise SystemExit("This Deep Scan has stopped and cannot resume.")
|
|
84
|
+
try:
|
|
85
|
+
repository = require_scan_target_identity(scan)
|
|
86
|
+
except SystemExit as exc:
|
|
87
|
+
raise SystemExit(
|
|
88
|
+
"Cannot resume: the original checkout is missing or was replaced."
|
|
89
|
+
) from exc
|
|
90
|
+
if scan_target_identity(repository, None) != (
|
|
91
|
+
scan["target_revision"],
|
|
92
|
+
scan["target_snapshot_digest"],
|
|
93
|
+
scan["target_device"],
|
|
94
|
+
scan["target_inode"],
|
|
95
|
+
):
|
|
96
|
+
raise SystemExit("Cannot resume: the original checkout revision or contents changed.")
|
|
97
|
+
recipe = parse_scan_recipe(scan["recipe_json"], repository)
|
|
98
|
+
scan_dir = require_scan_directory(Path(scan["scan_dir"]))
|
|
99
|
+
progress = connection.execute(
|
|
100
|
+
"SELECT scope_file_count FROM scan_progress WHERE scan_id = ?", (scan["id"],)
|
|
101
|
+
).fetchone()
|
|
102
|
+
result = {
|
|
103
|
+
"contract": scan_contract(scan),
|
|
104
|
+
"recipe": recipe,
|
|
105
|
+
"scanDir": str(scan_dir),
|
|
106
|
+
"scanId": scan["id"],
|
|
107
|
+
"scopeFileCount": progress["scope_file_count"],
|
|
108
|
+
"startedAt": scan["started_at"],
|
|
109
|
+
"targetId": scan["target_id"],
|
|
110
|
+
"targetRevision": scan["target_revision"],
|
|
111
|
+
"threadId": thread_id,
|
|
112
|
+
"userContext": scan["user_context"],
|
|
113
|
+
}
|
|
114
|
+
# Active coordinators may still be writing drafts. Validate sealed results
|
|
115
|
+
# before attaching to a coordinator that has finished.
|
|
116
|
+
if run is not None and run["status"] == "succeeded":
|
|
117
|
+
manifest_path = artifact_path(scan_dir, ARTIFACTS["manifest"], required=False)
|
|
118
|
+
if manifest_path is not None:
|
|
119
|
+
manifest = read_json_object(manifest_path)
|
|
120
|
+
manifest_scan = manifest.get("scan")
|
|
121
|
+
if isinstance(manifest_scan, dict) and (
|
|
122
|
+
manifest_scan.get("sealedAt") is not None
|
|
123
|
+
or manifest_scan.get("artifacts") is not None
|
|
124
|
+
):
|
|
125
|
+
try:
|
|
126
|
+
binding = workbench_completion_binding(scan, scan["started_at"], manifest)
|
|
127
|
+
_prepare_scan_finalization(
|
|
128
|
+
scan_dir,
|
|
129
|
+
expected_coverage_mode=binding["coverageMode"],
|
|
130
|
+
completion_binding=binding,
|
|
131
|
+
)
|
|
132
|
+
result["sealedProducerVersion"] = manifest_scan["producer"]["version"]
|
|
133
|
+
except ContractError as exc:
|
|
134
|
+
raise SystemExit(f"Cannot resume sealed scan: {exc}") from exc
|
|
135
|
+
return result
|
|
21
136
|
|
|
22
137
|
|
|
23
138
|
def _windows_path_key(value: str) -> str:
|
|
@@ -501,19 +501,20 @@ def _is_owned_task_start(
|
|
|
501
501
|
turn_id = payload.get("turn_id")
|
|
502
502
|
if not isinstance(turn_id, str) or not turn_id:
|
|
503
503
|
return False
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
504
|
+
# Fresh Codex worker thread/turn IDs use a same-process monotonic UUIDv7 generator.
|
|
505
|
+
thread_order = _uuid7_order(thread_id)
|
|
506
|
+
turn_order = _uuid7_order(turn_id)
|
|
507
|
+
if thread_order is None:
|
|
507
508
|
return True
|
|
508
|
-
return
|
|
509
|
+
return turn_order is not None and turn_order >= thread_order
|
|
509
510
|
|
|
510
511
|
|
|
511
|
-
def
|
|
512
|
+
def _uuid7_order(value: str) -> int | None:
|
|
512
513
|
try:
|
|
513
514
|
parsed = uuid.UUID(value)
|
|
514
515
|
except ValueError:
|
|
515
516
|
return None
|
|
516
|
-
return parsed.int
|
|
517
|
+
return parsed.int if parsed.version == 7 else None
|
|
517
518
|
|
|
518
519
|
|
|
519
520
|
def _token_snapshot(payload: Mapping[str, Any]) -> dict[str, int] | None:
|