@openai/codex-security 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +437 -2692
- package/_bundled_plugin/.app.json +5 -1
- package/_bundled_plugin/.codex-plugin/plugin.json +4 -0
- package/_bundled_plugin/.mcp.json +2 -0
- package/_bundled_plugin/examples/completed-scan/coverage.json +0 -1
- package/_bundled_plugin/examples/completed-scan/report.md +28 -26
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +1 -1
- package/_bundled_plugin/mcp/helpers.mjs +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +6 -213
- 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/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/permission-profile-preflight.mjs +556 -0
- package/_bundled_plugin/mcp/server.mjs +1 -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/preflight/capability-profiles.toml +0 -13
- package/_bundled_plugin/references/artifact-storage.md +2 -2
- package/_bundled_plugin/references/config-preflight.md +0 -4
- package/_bundled_plugin/references/core-scan.md +21 -9
- package/_bundled_plugin/references/final-report.md +11 -13
- package/_bundled_plugin/references/finding-detail-fields.md +90 -80
- package/_bundled_plugin/references/sarif-adapter.md +1 -1
- package/_bundled_plugin/references/scan-artifacts.md +1 -2
- package/_bundled_plugin/references/scan-contract.md +9 -4
- package/_bundled_plugin/references/scan-prologue.md +12 -0
- package/_bundled_plugin/references/security-guidance.md +2 -2
- package/_bundled_plugin/references/standalone-validation.md +11 -0
- package/_bundled_plugin/references/threat-model.md +1 -1
- package/_bundled_plugin/schemas/coverage.schema.json +43 -170
- package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +2 -24
- package/_bundled_plugin/schemas/definitions/discovery-candidate.schema.json +49 -25
- package/_bundled_plugin/schemas/findings.schema.json +159 -567
- package/_bundled_plugin/schemas/patch-risk-assessment.schema.json +106 -119
- package/_bundled_plugin/schemas/scan-manifest.schema.json +78 -220
- package/_bundled_plugin/schemas/tools/candidate-attack-paths.schema.json +91 -83
- package/_bundled_plugin/schemas/tools/candidate-validations.schema.json +35 -64
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +5 -2
- package/_bundled_plugin/schemas/tools/discovery-candidates.schema.json +6 -55
- package/_bundled_plugin/schemas/tools/review-items.schema.json +2 -38
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +169 -294
- package/_bundled_plugin/scripts/codex_profile.mjs +239 -0
- package/_bundled_plugin/scripts/codex_session.mjs +53 -0
- package/_bundled_plugin/scripts/config_preflight.py +26 -62
- package/_bundled_plugin/scripts/deep_scan_config.py +9 -11
- package/_bundled_plugin/scripts/deep_scan_workbench.py +129 -150
- package/_bundled_plugin/scripts/finalize_scan_contract.py +321 -237
- package/_bundled_plugin/scripts/finding_preview.py +39 -9
- package/_bundled_plugin/scripts/generate_in_scope_files.py +27 -77
- package/_bundled_plugin/scripts/generate_rank_input.py +115 -926
- package/_bundled_plugin/scripts/launch_codex_security_mcp +35 -10
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +5 -5
- package/_bundled_plugin/scripts/rank_preview.py +42 -918
- package/_bundled_plugin/scripts/report_projection.py +150 -183
- package/_bundled_plugin/scripts/snapshot_sqlite.py +6 -1
- package/_bundled_plugin/scripts/threat_model_projection.py +4 -7
- package/_bundled_plugin/scripts/validate_scan_contract.py +4 -34
- package/_bundled_plugin/scripts/validate_tracking_source.py +3 -13
- package/_bundled_plugin/scripts/windows_scan_local_files.py +48 -3
- package/_bundled_plugin/scripts/workbench/handoff.py +25 -50
- package/_bundled_plugin/scripts/workbench/runtime_toml.py +22 -0
- package/_bundled_plugin/scripts/workbench/storage.py +10 -6
- package/_bundled_plugin/scripts/workbench_cli.py +102 -184
- package/_bundled_plugin/scripts/workbench_db.py +463 -464
- package/_bundled_plugin/scripts/workbench_feedback.py +6 -3
- package/_bundled_plugin/scripts/workbench_finding_index.py +19 -1
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +18 -4
- package/_bundled_plugin/scripts/workbench_local_dedupe.py +136 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +27 -14
- package/_bundled_plugin/scripts/workbench_progress.py +14 -58
- package/_bundled_plugin/scripts/workbench_publication.py +234 -289
- package/_bundled_plugin/scripts/workbench_remediation.py +12 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +172 -49
- package/_bundled_plugin/scripts/workbench_scan_history.py +57 -57
- package/_bundled_plugin/scripts/workbench_scan_start.py +105 -41
- package/_bundled_plugin/scripts/workbench_scan_usage.py +194 -42
- package/_bundled_plugin/scripts/workbench_schema.py +37 -1151
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +11 -1
- package/_bundled_plugin/scripts/workbench_target.py +430 -142
- package/_bundled_plugin/scripts/workbench_validation.py +31 -28
- package/_bundled_plugin/shared/workbench-history-repairs.json +218 -0
- package/_bundled_plugin/shared/workbench-migrations.json +414 -0
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +15 -4
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +54 -0
- package/_bundled_plugin/skills/cloud-findings/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/finding-discovery/SKILL.md +3 -3
- package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +50 -20
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +8 -14
- package/_bundled_plugin/skills/security-scan/SKILL.md +22 -7
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +15 -1
- package/_bundled_plugin/skills/threat-model/SKILL.md +1 -1
- package/_bundled_plugin/skills/track-findings/SKILL.md +48 -176
- package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +16 -24
- package/_bundled_plugin/skills/track-findings/references/jira.md +15 -61
- package/_bundled_plugin/skills/triage-finding/SKILL.md +50 -289
- package/_bundled_plugin/skills/triage-finding/agents/openai.yaml +2 -2
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +23 -43
- package/_bundled_plugin/skills/triage-finding/references/triage-result-contract.md +7 -1
- package/bin/codex-security.mjs +9 -2
- package/dist/api.d.ts +63 -10
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1015 -383
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +1 -1
- package/dist/artifact-export.d.ts.map +1 -1
- package/dist/artifact-export.js +28 -13
- package/dist/artifact-export.js.map +1 -1
- package/dist/auth.d.ts +2 -6
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +19 -9
- package/dist/auth.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +1 -0
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-severity.d.ts +26 -9
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +13 -30
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +17 -13
- package/dist/cli-help.js.map +1 -1
- package/dist/cli-signals.d.ts +8 -0
- package/dist/cli-signals.d.ts.map +1 -0
- package/dist/cli-signals.js +28 -0
- package/dist/cli-signals.js.map +1 -0
- package/dist/cli.d.ts +4 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1102 -905
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +10 -9
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codeowners.d.ts +19 -0
- package/dist/codeowners.d.ts.map +1 -0
- package/dist/codeowners.js +138 -0
- package/dist/codeowners.js.map +1 -0
- package/dist/codex-sdk-environment.d.ts +1 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -1
- package/dist/codex-sdk-environment.js +40 -2
- package/dist/codex-sdk-environment.js.map +1 -1
- package/dist/component-plan.d.ts +2 -5
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +39 -31
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +6 -5
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +25 -36
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +64 -74
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +16 -3
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +91 -255
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts +13 -6
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +14 -4
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +10 -2
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +102 -104
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +6 -5
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts +1 -2
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +9 -3
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts +4 -2
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js +23 -9
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +8 -6
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +128 -19
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +5 -2
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +18 -4
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +27 -5
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +58 -48
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.d.ts.map +1 -1
- package/dist/deduplication/deduplication.js +19 -51
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/diagnostics.d.ts +17 -0
- package/dist/deduplication/diagnostics.d.ts.map +1 -0
- package/dist/deduplication/diagnostics.js +5 -0
- package/dist/deduplication/diagnostics.js.map +1 -0
- package/dist/deduplication/finding-schema.d.ts.map +1 -1
- package/dist/deduplication/finding-schema.js +7 -1
- package/dist/deduplication/finding-schema.js.map +1 -1
- package/dist/deduplication/local.d.ts +31 -0
- package/dist/deduplication/local.d.ts.map +1 -0
- package/dist/deduplication/local.js +166 -0
- package/dist/deduplication/local.js.map +1 -0
- package/dist/deduplication/records-protocol.d.ts +3 -8
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +11 -184
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +186 -11
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +10 -18
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/scan.d.ts +9 -3
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +158 -39
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +2 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +4 -4
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-progress.d.ts +17 -1
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +19 -17
- package/dist/deep-progress.js.map +1 -1
- package/dist/deep-scan.d.ts +20 -0
- package/dist/deep-scan.d.ts.map +1 -0
- package/dist/deep-scan.js +113 -0
- package/dist/deep-scan.js.map +1 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -1
- package/dist/executable-path.d.ts +2 -0
- package/dist/executable-path.d.ts.map +1 -0
- package/dist/executable-path.js +12 -0
- package/dist/executable-path.js.map +1 -0
- package/dist/feedback.d.ts +1 -4
- package/dist/feedback.d.ts.map +1 -1
- package/dist/feedback.js +54 -22
- package/dist/feedback.js.map +1 -1
- package/dist/finding-catalogue.d.ts.map +1 -1
- package/dist/finding-catalogue.js +4 -8
- package/dist/finding-catalogue.js.map +1 -1
- package/dist/finding-normalization.d.ts +5 -0
- package/dist/finding-normalization.d.ts.map +1 -0
- package/dist/finding-normalization.js +120 -0
- package/dist/finding-normalization.js.map +1 -0
- package/dist/finding-retrieval.d.ts +9 -0
- package/dist/finding-retrieval.d.ts.map +1 -1
- package/dist/finding-retrieval.js.map +1 -1
- package/dist/finding-workflow.d.ts +13 -8
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +14 -6
- package/dist/finding-workflow.js.map +1 -1
- package/dist/findings-client.d.ts +2 -1
- package/dist/findings-client.d.ts.map +1 -1
- package/dist/findings-client.js +36 -9
- package/dist/findings-client.js.map +1 -1
- package/dist/findings-errors.d.ts +16 -0
- package/dist/findings-errors.d.ts.map +1 -0
- package/dist/findings-errors.js +24 -0
- package/dist/findings-errors.js.map +1 -0
- package/dist/findings-import.d.ts +1 -1
- package/dist/findings-import.d.ts.map +1 -1
- package/dist/findings-import.js +12 -30
- package/dist/findings-import.js.map +1 -1
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +7 -1
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +19 -0
- package/dist/host-protocol.d.ts.map +1 -0
- package/dist/host-protocol.js +270 -0
- package/dist/host-protocol.js.map +1 -0
- package/dist/hosted-scan-protocol.d.ts +4 -0
- package/dist/hosted-scan-protocol.d.ts.map +1 -0
- package/dist/hosted-scan-protocol.js +25 -0
- package/dist/hosted-scan-protocol.js.map +1 -0
- package/dist/hosted-scan.d.ts +117 -0
- package/dist/hosted-scan.d.ts.map +1 -0
- package/dist/hosted-scan.js +260 -0
- package/dist/hosted-scan.js.map +1 -0
- package/dist/import-scan.d.ts.map +1 -1
- package/dist/import-scan.js +48 -38
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts +7 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +114 -46
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js +2 -7
- package/dist/linear.js.map +1 -1
- package/dist/mock-scan.d.ts.map +1 -1
- package/dist/mock-scan.js +0 -1
- package/dist/mock-scan.js.map +1 -1
- package/dist/models.d.ts +0 -2
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/multiscan.d.ts +9 -3
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +240 -135
- package/dist/multiscan.js.map +1 -1
- package/dist/owner-evidence.d.ts +10 -2
- package/dist/owner-evidence.d.ts.map +1 -1
- package/dist/owner-evidence.js +67 -8
- package/dist/owner-evidence.js.map +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +3 -2
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config.js +3 -3
- package/dist/project-config.js.map +1 -1
- package/dist/provider-profile.d.ts +21 -0
- package/dist/provider-profile.d.ts.map +1 -0
- package/dist/provider-profile.js +133 -0
- package/dist/provider-profile.js.map +1 -0
- package/dist/publication-events.d.ts +6 -8
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +25 -50
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +95 -109
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts +1 -4
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +2 -13
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts +1 -5
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +109 -160
- package/dist/publish.js.map +1 -1
- package/dist/request-metadata.d.ts +9 -0
- package/dist/request-metadata.d.ts.map +1 -0
- package/dist/request-metadata.js +13 -0
- package/dist/request-metadata.js.map +1 -0
- package/dist/runtime.d.ts +20 -6
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +407 -148
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +14 -0
- package/dist/saved-scan-bootstrap.d.ts.map +1 -0
- package/dist/saved-scan-bootstrap.js +261 -0
- package/dist/saved-scan-bootstrap.js.map +1 -0
- package/dist/saved-scan.d.ts +1 -1
- package/dist/saved-scan.d.ts.map +1 -1
- package/dist/saved-scan.js +6 -12
- package/dist/saved-scan.js.map +1 -1
- package/dist/scan-activity.js +11 -8
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +28 -15
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +276 -281
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +3 -0
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +345 -77
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +104 -0
- package/dist/scan-executor.d.ts.map +1 -0
- package/dist/scan-executor.js +62 -0
- package/dist/scan-executor.js.map +1 -0
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +54 -13
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-inputs.d.ts +6 -0
- package/dist/scan-inputs.d.ts.map +1 -0
- package/dist/scan-inputs.js +71 -0
- package/dist/scan-inputs.js.map +1 -0
- package/dist/scan-logs.d.ts +2 -3
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +12 -6
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-sessions.d.ts +4 -0
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +17 -0
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-skill-paths.d.ts +8 -0
- package/dist/scan-skill-paths.d.ts.map +1 -0
- package/dist/scan-skill-paths.js +47 -0
- package/dist/scan-skill-paths.js.map +1 -0
- package/dist/security-policy-cli.d.ts.map +1 -1
- package/dist/security-policy-cli.js +7 -27
- package/dist/security-policy-cli.js.map +1 -1
- package/dist/security-policy.d.ts +9 -5
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +33 -14
- package/dist/security-policy.js.map +1 -1
- package/dist/server/api.d.ts +0 -1
- package/dist/server/api.d.ts.map +1 -1
- package/dist/server/api.js +0 -1
- package/dist/server/api.js.map +1 -1
- package/dist/server/embeddings.d.ts +3 -1
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +10 -3
- package/dist/server/embeddings.js.map +1 -1
- package/dist/server/errors.d.ts +5 -2
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/errors.js +7 -0
- package/dist/server/errors.js.map +1 -1
- package/dist/server/sqlite-store.d.ts +0 -2
- package/dist/server/sqlite-store.d.ts.map +1 -1
- package/dist/server/sqlite-store.js +54 -44
- package/dist/server/sqlite-store.js.map +1 -1
- package/dist/server/storage.d.ts +0 -2
- package/dist/server/storage.d.ts.map +1 -1
- package/dist/server/storage.js.map +1 -1
- package/dist/severity-store.js +19 -24
- package/dist/severity-store.js.map +1 -1
- package/dist/standalone-validation-prompt.d.ts +2 -0
- package/dist/standalone-validation-prompt.d.ts.map +1 -0
- package/dist/standalone-validation-prompt.js +10 -0
- package/dist/standalone-validation-prompt.js.map +1 -0
- package/dist/suggest-owners.d.ts +4 -2
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +11 -5
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +11 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +123 -72
- package/dist/targets.js.map +1 -1
- package/dist/trusted-executable.d.ts +2 -2
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +8 -6
- package/dist/trusted-executable.js.map +1 -1
- package/dist/value.js +7 -0
- package/dist/value.js.map +1 -1
- package/dist/version.js.map +1 -1
- package/dist/workbench-arguments.d.ts +3 -0
- package/dist/workbench-arguments.d.ts.map +1 -0
- package/dist/workbench-arguments.js +15 -0
- package/dist/workbench-arguments.js.map +1 -0
- package/dist/worker-progress.d.ts +44 -11
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +48 -49
- package/dist/worker-progress.js.map +1 -1
- package/docs/cli.md +1788 -0
- package/docs/findings-service.md +402 -0
- package/docs/hosted-scans.md +242 -0
- package/package.json +23 -22
- package/schemas/hosted-scan-v2.fixture.json +145 -0
- package/_bundled_plugin/schemas/tools/worker-threat-model.schema.json +0 -18
- package/_bundled_plugin/scripts/workbench_dashboard.py +0 -159
- package/_bundled_plugin/scripts/workbench_findings.py +0 -221
- package/_bundled_plugin/scripts/workbench_severity.py +0 -122
- package/_bundled_plugin/skills/assess-patch-risk/scripts/validate_patch_risk_assessment.py +0 -163
- package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +0 -276
- package/dist/server/dashboard/app.css +0 -2
- package/dist/server/dashboard/app.js +0 -66
- package/dist/server/dashboard/index.html +0 -18
- package/dist/server/dashboard-types.d.ts +0 -48
- package/dist/server/dashboard-types.d.ts.map +0 -1
- package/dist/server/dashboard-types.js +0 -2
- package/dist/server/dashboard-types.js.map +0 -1
- package/dist/server/dashboard.d.ts +0 -6
- package/dist/server/dashboard.d.ts.map +0 -1
- package/dist/server/dashboard.js +0 -59
- package/dist/server/dashboard.js.map +0 -1
- package/dist/server/index.d.ts +0 -2
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js +0 -6
- package/dist/server/index.js.map +0 -1
- package/dist/server/routes.d.ts +0 -7
- package/dist/server/routes.d.ts.map +0 -1
- package/dist/server/routes.js +0 -98
- package/dist/server/routes.js.map +0 -1
- package/dist/server/serve.d.ts +0 -2
- package/dist/server/serve.d.ts.map +0 -1
- package/dist/server/serve.js +0 -28
- package/dist/server/serve.js.map +0 -1
- package/dist/server/server.d.ts +0 -10
- package/dist/server/server.d.ts.map +0 -1
- package/dist/server/server.js +0 -16
- package/dist/server/server.js.map +0 -1
- package/dist/server/validation.d.ts +0 -17
- package/dist/server/validation.d.ts.map +0 -1
- package/dist/server/validation.js +0 -53
- package/dist/server/validation.js.map +0 -1
|
@@ -16,8 +16,10 @@ import sys
|
|
|
16
16
|
import tempfile
|
|
17
17
|
import time
|
|
18
18
|
import uuid
|
|
19
|
+
from collections.abc import Callable
|
|
19
20
|
from contextlib import closing, contextmanager, nullcontext
|
|
20
21
|
from datetime import datetime, timedelta, timezone
|
|
22
|
+
from functools import partial
|
|
21
23
|
from pathlib import Path, PurePosixPath
|
|
22
24
|
from types import SimpleNamespace
|
|
23
25
|
from typing import Any
|
|
@@ -37,17 +39,10 @@ import deep_scan_workbench as deep_scan
|
|
|
37
39
|
import workbench_native_indexes as native_indexes
|
|
38
40
|
import workbench_progress as progress
|
|
39
41
|
import workbench_publication as publication
|
|
40
|
-
import workbench_remediation as
|
|
42
|
+
import workbench_remediation as remediation_state
|
|
41
43
|
import workbench_saved_results as saved_results
|
|
42
44
|
import workbench_scan_history as scan_history
|
|
43
45
|
import workbench_scan_usage as scan_usage
|
|
44
|
-
import workbench_severity as severity
|
|
45
|
-
from filesystem_identity import (
|
|
46
|
-
serialize_filesystem_identity as serialize_filesystem_identity,
|
|
47
|
-
)
|
|
48
|
-
from filesystem_identity import (
|
|
49
|
-
stored_filesystem_identity_matches as stored_filesystem_identity_matches,
|
|
50
|
-
)
|
|
51
46
|
from finalize_scan_contract import (
|
|
52
47
|
PRODUCER_NAME,
|
|
53
48
|
ContractError,
|
|
@@ -82,18 +77,10 @@ from workbench_constants import (
|
|
|
82
77
|
PATCH_PREVIEW_BYTES,
|
|
83
78
|
SQLITE_RETRY_ATTEMPTS,
|
|
84
79
|
)
|
|
85
|
-
from workbench_dashboard import dashboard
|
|
86
80
|
from workbench_feedback import get_scan_feedback
|
|
87
81
|
from workbench_finding_index import index_findings
|
|
88
82
|
from workbench_finding_workflows import finding_workflow, register_workflow_scan
|
|
89
|
-
from
|
|
90
|
-
find_potential_duplicates,
|
|
91
|
-
list_dedupe_groups,
|
|
92
|
-
list_stored_findings,
|
|
93
|
-
store_dedupe_groups,
|
|
94
|
-
store_findings,
|
|
95
|
-
)
|
|
96
|
-
from workbench_remediation import remediation_claim_is_active
|
|
83
|
+
from workbench_local_dedupe import local_dedupe
|
|
97
84
|
from workbench_scan_start import (
|
|
98
85
|
archive_scan,
|
|
99
86
|
insert_running_scan,
|
|
@@ -102,18 +89,12 @@ from workbench_scan_start import (
|
|
|
102
89
|
scan_target_identity,
|
|
103
90
|
stored_diff_target,
|
|
104
91
|
)
|
|
105
|
-
from workbench_scan_start import (
|
|
106
|
-
compact_timestamp as compact_timestamp,
|
|
107
|
-
)
|
|
108
92
|
from workbench_schema import (
|
|
109
93
|
MIGRATIONS,
|
|
110
94
|
)
|
|
111
95
|
from workbench_schema import (
|
|
112
96
|
apply_migrations as apply_schema_migrations,
|
|
113
97
|
)
|
|
114
|
-
from workbench_schema import (
|
|
115
|
-
sql_statements as sql_statements,
|
|
116
|
-
)
|
|
117
98
|
from workbench_source_excerpt import finding_source_excerpt, safe_source_path
|
|
118
99
|
from workbench_target import (
|
|
119
100
|
clean_worktree_content_digest,
|
|
@@ -133,6 +114,7 @@ from workbench_target import (
|
|
|
133
114
|
require_git_worktree_head,
|
|
134
115
|
require_remediation_target,
|
|
135
116
|
require_scan_target_identity,
|
|
117
|
+
restore_directory_junctions,
|
|
136
118
|
scan_target_warning,
|
|
137
119
|
worktree_content_digest,
|
|
138
120
|
worktree_content_digest_for_context,
|
|
@@ -236,9 +218,22 @@ def release_completion_file_lock(descriptor: int) -> None:
|
|
|
236
218
|
|
|
237
219
|
def connect(*, deferred: bool = False) -> sqlite3.Connection:
|
|
238
220
|
path = database_path()
|
|
239
|
-
|
|
221
|
+
guidance = (
|
|
222
|
+
f"Workbench database: {path}. Ensure the state directory and SQLite journal files "
|
|
223
|
+
"are writable, or set CODEX_SECURITY_STATE_DIR to a writable directory outside "
|
|
224
|
+
"the scanned repository."
|
|
225
|
+
)
|
|
226
|
+
try:
|
|
227
|
+
create_private_directory(path.parent)
|
|
228
|
+
except OSError:
|
|
229
|
+
print(guidance, file=sys.stderr)
|
|
230
|
+
raise
|
|
240
231
|
for attempt in range(SQLITE_RETRY_ATTEMPTS):
|
|
241
|
-
|
|
232
|
+
try:
|
|
233
|
+
connection = sqlite3.connect(path, timeout=5)
|
|
234
|
+
except sqlite3.OperationalError:
|
|
235
|
+
print(guidance, file=sys.stderr)
|
|
236
|
+
raise
|
|
242
237
|
try:
|
|
243
238
|
connection.row_factory = sqlite3.Row
|
|
244
239
|
connection.execute("PRAGMA foreign_keys = ON")
|
|
@@ -251,6 +246,7 @@ def connect(*, deferred: bool = False) -> sqlite3.Connection:
|
|
|
251
246
|
except sqlite3.OperationalError as exc:
|
|
252
247
|
connection.close()
|
|
253
248
|
if attempt == SQLITE_RETRY_ATTEMPTS - 1 or not sqlite_busy(exc):
|
|
249
|
+
print(guidance, file=sys.stderr)
|
|
254
250
|
raise
|
|
255
251
|
time.sleep(0.05 * (2**attempt))
|
|
256
252
|
raise AssertionError("SQLite retry loop exhausted unexpectedly.")
|
|
@@ -333,7 +329,11 @@ def require_diff_target(
|
|
|
333
329
|
if commit is None:
|
|
334
330
|
raise SystemExit(f"Commit is not available in the local checkout: {head}")
|
|
335
331
|
parent_line = next(
|
|
336
|
-
(
|
|
332
|
+
(
|
|
333
|
+
line
|
|
334
|
+
for line in commit.split(b"\n\n", 1)[0].splitlines()
|
|
335
|
+
if line.startswith(b"parent ")
|
|
336
|
+
),
|
|
337
337
|
None,
|
|
338
338
|
)
|
|
339
339
|
if parent_line is None:
|
|
@@ -405,7 +405,7 @@ def inspect_setup_values(
|
|
|
405
405
|
def require_review_changes_target(target: Path) -> str:
|
|
406
406
|
revision = require_git_worktree_head(target)
|
|
407
407
|
repository_root = git_output(target, "rev-parse", "--show-toplevel")
|
|
408
|
-
if repository_root is None or Path(repository_root).
|
|
408
|
+
if repository_root is None or not Path(repository_root).samefile(target):
|
|
409
409
|
raise SystemExit(
|
|
410
410
|
"Review changes requires the checked-out Git repository root as the target."
|
|
411
411
|
)
|
|
@@ -441,6 +441,20 @@ def requested_scan_paths(scan: sqlite3.Row) -> list[str]:
|
|
|
441
441
|
return [scan["scope"]]
|
|
442
442
|
|
|
443
443
|
|
|
444
|
+
def requested_scan_file_paths(scan: sqlite3.Row) -> list[str]:
|
|
445
|
+
# Older scans did not record path kinds. Retain their lexical scope semantics
|
|
446
|
+
# rather than infer the original target from a possibly changed checkout.
|
|
447
|
+
if scan["recipe_json"] is None:
|
|
448
|
+
return []
|
|
449
|
+
recipe = json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json)
|
|
450
|
+
return recipe.get("scopeFilePaths", [])
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def requested_finding_scope(scan: sqlite3.Row) -> list[tuple[str, bool]]:
|
|
454
|
+
files = {PurePosixPath(path) for path in requested_scan_file_paths(scan)}
|
|
455
|
+
return [(path, PurePosixPath(path) in files) for path in requested_scan_paths(scan)]
|
|
456
|
+
|
|
457
|
+
|
|
444
458
|
def scan_contract(scan: sqlite3.Row) -> dict[str, Any]:
|
|
445
459
|
target = Path(scan["target_path"])
|
|
446
460
|
target_contract = {
|
|
@@ -462,6 +476,7 @@ def scan_contract(scan: sqlite3.Row) -> dict[str, Any]:
|
|
|
462
476
|
"scope": {
|
|
463
477
|
"requiredExcludePaths": [],
|
|
464
478
|
"requestedPath": scan["scope"],
|
|
479
|
+
"filePaths": requested_scan_file_paths(scan),
|
|
465
480
|
**(
|
|
466
481
|
{"requiredIncludePaths": requested_scan_paths(scan)}
|
|
467
482
|
if scan["mode"] != "diff"
|
|
@@ -607,7 +622,7 @@ def verify_manifest_binding(scan: sqlite3.Row, manifest: dict[str, Any]) -> None
|
|
|
607
622
|
|
|
608
623
|
|
|
609
624
|
def require_scope(scope: str, mode: str, target: Path) -> str:
|
|
610
|
-
value = scope.strip()
|
|
625
|
+
value = scope if scope.strip() else "."
|
|
611
626
|
requested_scope = Path(value)
|
|
612
627
|
if "\\" in value and (os.name != "nt" or not requested_scope.is_absolute()):
|
|
613
628
|
raise SystemExit("Scan scope must use repository-relative POSIX paths.")
|
|
@@ -621,6 +636,8 @@ def require_scope(scope: str, mode: str, target: Path) -> str:
|
|
|
621
636
|
except (RuntimeError, ValueError) as exc:
|
|
622
637
|
raise SystemExit("Scan scope must stay inside the scanned target.") from exc
|
|
623
638
|
normalized = relative_scope.as_posix() or "."
|
|
639
|
+
if not normalized.strip():
|
|
640
|
+
normalized = "./" + normalized
|
|
624
641
|
if mode == "deep" and normalized != ".":
|
|
625
642
|
raise SystemExit("Deep Scan is repository-wide and cannot use a scoped path.")
|
|
626
643
|
if not resolved_scope.is_dir():
|
|
@@ -666,8 +683,10 @@ def resolve_scan_id(connection: sqlite3.Connection, scan_id: str) -> str:
|
|
|
666
683
|
def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
667
684
|
workspace_id = require_uuid(args.workspace_id, "workspace-id")
|
|
668
685
|
timestamp = now()
|
|
669
|
-
target_path = optional_text(args.target_path, maximum=4096)
|
|
670
|
-
default_scope = optional_text(args.scope, maximum=4096)
|
|
686
|
+
target_path = args.target_path if optional_text(args.target_path, maximum=4096) else None
|
|
687
|
+
default_scope = args.scope if optional_text(args.scope, maximum=4096) else "."
|
|
688
|
+
if any(len(value) > 4096 for value in (target_path, default_scope) if value is not None):
|
|
689
|
+
raise SystemExit("Text value must be no longer than 4096 characters.")
|
|
671
690
|
diff_target_kind = args.diff_target_kind if args.mode == "diff" else None
|
|
672
691
|
diff_base_revision = (
|
|
673
692
|
optional_text(args.diff_base_revision, maximum=512) if args.mode == "diff" else None
|
|
@@ -697,6 +716,7 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
|
|
|
697
716
|
diff_head_revision = inspected["diffTarget"]["headRevision"]
|
|
698
717
|
diff_content_digest = inspected["diffTarget"].get("contentDigest")
|
|
699
718
|
except SystemExit:
|
|
719
|
+
# Preserve an incomplete setup so workspace_state can report its validation error.
|
|
700
720
|
pass
|
|
701
721
|
with connection:
|
|
702
722
|
target_id = (
|
|
@@ -780,10 +800,7 @@ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) ->
|
|
|
780
800
|
scope,
|
|
781
801
|
args.mode,
|
|
782
802
|
user_context_argument(args),
|
|
783
|
-
diff_target
|
|
784
|
-
diff_target["baseRevision"] if diff_target else None,
|
|
785
|
-
diff_target["headRevision"] if diff_target else None,
|
|
786
|
-
diff_target.get("contentDigest") if diff_target else None,
|
|
803
|
+
*scan_diff_identity(diff_target or None),
|
|
787
804
|
timestamp,
|
|
788
805
|
workspace["id"],
|
|
789
806
|
),
|
|
@@ -943,130 +960,148 @@ def _start_prompt_driven_scan(
|
|
|
943
960
|
target_identity = scan_target_identity(target, diff_target)
|
|
944
961
|
target_root = scan_target_root(args.scan_root, target)
|
|
945
962
|
|
|
946
|
-
connection.execute("
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
):
|
|
964
|
-
raise SystemExit(
|
|
965
|
-
"The selected scan target changed while the scan was starting. Try again."
|
|
963
|
+
busy_timeout = int(connection.execute("PRAGMA busy_timeout").fetchone()[0])
|
|
964
|
+
for attempt in range(SQLITE_RETRY_ATTEMPTS):
|
|
965
|
+
try:
|
|
966
|
+
# Wait before hashing, then release the writer slot while reading the target.
|
|
967
|
+
connection.execute("BEGIN IMMEDIATE")
|
|
968
|
+
connection.rollback()
|
|
969
|
+
current_target = require_remediation_target(target_path)
|
|
970
|
+
current_diff_target = (
|
|
971
|
+
require_diff_target(
|
|
972
|
+
current_target,
|
|
973
|
+
args.diff_target_kind,
|
|
974
|
+
args.diff_base_revision,
|
|
975
|
+
args.diff_head_revision,
|
|
976
|
+
args.diff_content_digest,
|
|
977
|
+
)
|
|
978
|
+
if args.mode == "diff"
|
|
979
|
+
else None
|
|
966
980
|
)
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
AND workspaces.user_context IS ? AND workspaces.target_summary IS ?
|
|
974
|
-
AND workspaces.diff_target_kind IS ? AND workspaces.diff_base_revision IS ?
|
|
975
|
-
AND workspaces.diff_head_revision IS ? AND workspaces.diff_content_digest IS ?
|
|
976
|
-
AND workspaces.submitted = 1 AND scans.target_revision = ?
|
|
977
|
-
AND scans.target_snapshot_digest IS ? AND scans.target_device = ?
|
|
978
|
-
AND scans.target_inode = ? AND scans.status = 'running'
|
|
979
|
-
AND scans.handoff_status = 'delivered'
|
|
980
|
-
AND (
|
|
981
|
-
(? = 0 AND scans.handoff_claim_token IS NULL)
|
|
982
|
-
OR (
|
|
983
|
-
? = 1 AND scans.handoff_claim_token IS NOT NULL
|
|
984
|
-
AND scans.continuation_thread_id = ?
|
|
985
|
-
)
|
|
981
|
+
if (
|
|
982
|
+
scan_target_identity(current_target, current_diff_target) != target_identity
|
|
983
|
+
or scan_diff_identity(current_diff_target) != diff_identity
|
|
984
|
+
):
|
|
985
|
+
raise SystemExit(
|
|
986
|
+
"The selected scan target changed while the scan was starting. Try again."
|
|
986
987
|
)
|
|
987
|
-
|
|
988
|
-
""
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
user_context,
|
|
995
|
-
target_summary,
|
|
996
|
-
*diff_identity,
|
|
997
|
-
*target_identity,
|
|
998
|
-
int(headless_standard),
|
|
999
|
-
int(headless_standard),
|
|
1000
|
-
thread_id,
|
|
1001
|
-
),
|
|
1002
|
-
).fetchone()
|
|
1003
|
-
if existing is not None:
|
|
1004
|
-
connection.commit()
|
|
1005
|
-
return {
|
|
1006
|
-
**scan_context(connection, existing["id"]),
|
|
1007
|
-
"startDisposition": "joined",
|
|
1008
|
-
}
|
|
1009
|
-
create_private_directory(target_root)
|
|
1010
|
-
workspace_id = str(uuid.uuid4())
|
|
1011
|
-
scan_id = str(uuid.uuid4())
|
|
1012
|
-
timestamp = now()
|
|
1013
|
-
target_id = ensure_security_target(connection, target_path)
|
|
1014
|
-
connection.execute(
|
|
1015
|
-
"""
|
|
1016
|
-
INSERT INTO workspaces (
|
|
1017
|
-
id, thread_id, target_id, target_path, target_title, target_summary, default_scope,
|
|
1018
|
-
default_mode, user_context, diff_target_kind, diff_base_revision,
|
|
1019
|
-
diff_head_revision, diff_content_digest, submitted, created_at, updated_at
|
|
1020
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)
|
|
1021
|
-
""",
|
|
1022
|
-
(
|
|
1023
|
-
workspace_id,
|
|
1024
|
-
thread_id,
|
|
1025
|
-
target_id,
|
|
1026
|
-
target_path,
|
|
1027
|
-
target.name,
|
|
1028
|
-
target_summary,
|
|
1029
|
-
scope,
|
|
1030
|
-
args.mode,
|
|
1031
|
-
user_context,
|
|
1032
|
-
*diff_identity,
|
|
1033
|
-
timestamp,
|
|
1034
|
-
timestamp,
|
|
1035
|
-
),
|
|
1036
|
-
)
|
|
1037
|
-
workspace = require_workspace(connection, workspace_id)
|
|
1038
|
-
insert_running_scan(
|
|
1039
|
-
connection,
|
|
1040
|
-
scan_id=scan_id,
|
|
1041
|
-
workspace=workspace,
|
|
1042
|
-
target=target,
|
|
1043
|
-
scope=scope,
|
|
1044
|
-
diff_target=diff_target,
|
|
1045
|
-
target_identity=target_identity,
|
|
1046
|
-
target_root=target_root,
|
|
1047
|
-
target_summary=target_summary,
|
|
1048
|
-
scope_file_count=scope_file_count,
|
|
1049
|
-
timestamp=timestamp,
|
|
1050
|
-
handoff_status="delivered",
|
|
1051
|
-
model=args.model,
|
|
1052
|
-
reasoning_effort=args.reasoning_effort,
|
|
1053
|
-
)
|
|
1054
|
-
if headless_standard:
|
|
1055
|
-
claimed = connection.execute(
|
|
988
|
+
# If another writer arrived during hashing, retry without waiting on a stale hash.
|
|
989
|
+
connection.execute("PRAGMA busy_timeout = 0")
|
|
990
|
+
try:
|
|
991
|
+
connection.execute("BEGIN IMMEDIATE")
|
|
992
|
+
finally:
|
|
993
|
+
connection.execute(f"PRAGMA busy_timeout = {busy_timeout}")
|
|
994
|
+
existing = connection.execute(
|
|
1056
995
|
"""
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
WHERE
|
|
1060
|
-
AND
|
|
996
|
+
SELECT scans.* FROM scans
|
|
997
|
+
JOIN workspaces ON workspaces.active_scan_id = scans.id
|
|
998
|
+
WHERE workspaces.thread_id = ? AND workspaces.target_path = ?
|
|
999
|
+
AND workspaces.default_scope = ? AND workspaces.default_mode = ?
|
|
1000
|
+
AND workspaces.user_context IS ? AND workspaces.target_summary IS ?
|
|
1001
|
+
AND workspaces.diff_target_kind IS ? AND workspaces.diff_base_revision IS ?
|
|
1002
|
+
AND workspaces.diff_head_revision IS ? AND workspaces.diff_content_digest IS ?
|
|
1003
|
+
AND workspaces.submitted = 1 AND scans.target_revision = ?
|
|
1004
|
+
AND scans.target_snapshot_digest IS ? AND scans.target_device = ?
|
|
1005
|
+
AND scans.target_inode = ? AND scans.status = 'running'
|
|
1006
|
+
AND scans.handoff_status = 'delivered'
|
|
1007
|
+
AND (
|
|
1008
|
+
(? = 0 AND scans.handoff_claim_token IS NULL)
|
|
1009
|
+
OR (
|
|
1010
|
+
? = 1 AND scans.handoff_claim_token IS NOT NULL
|
|
1011
|
+
AND scans.continuation_thread_id = ?
|
|
1012
|
+
)
|
|
1013
|
+
)
|
|
1014
|
+
ORDER BY scans.updated_at DESC, scans.started_at DESC, scans.id LIMIT 1
|
|
1061
1015
|
""",
|
|
1062
|
-
(
|
|
1016
|
+
(
|
|
1017
|
+
thread_id,
|
|
1018
|
+
target_path,
|
|
1019
|
+
scope,
|
|
1020
|
+
args.mode,
|
|
1021
|
+
user_context,
|
|
1022
|
+
target_summary,
|
|
1023
|
+
*diff_identity,
|
|
1024
|
+
*target_identity,
|
|
1025
|
+
int(headless_standard),
|
|
1026
|
+
int(headless_standard),
|
|
1027
|
+
thread_id,
|
|
1028
|
+
),
|
|
1029
|
+
).fetchone()
|
|
1030
|
+
if existing is not None:
|
|
1031
|
+
connection.commit()
|
|
1032
|
+
return {
|
|
1033
|
+
**scan_context(connection, existing["id"]),
|
|
1034
|
+
"startDisposition": "joined",
|
|
1035
|
+
}
|
|
1036
|
+
create_private_directory(target_root)
|
|
1037
|
+
workspace_id = str(uuid.uuid4())
|
|
1038
|
+
scan_id = str(uuid.uuid4())
|
|
1039
|
+
timestamp = now()
|
|
1040
|
+
target_id = ensure_security_target(connection, target_path)
|
|
1041
|
+
connection.execute(
|
|
1042
|
+
"""
|
|
1043
|
+
INSERT INTO workspaces (
|
|
1044
|
+
id, thread_id, target_id, target_path, target_title, target_summary, default_scope,
|
|
1045
|
+
default_mode, user_context, diff_target_kind, diff_base_revision,
|
|
1046
|
+
diff_head_revision, diff_content_digest, submitted, created_at, updated_at
|
|
1047
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)
|
|
1048
|
+
""",
|
|
1049
|
+
(
|
|
1050
|
+
workspace_id,
|
|
1051
|
+
thread_id,
|
|
1052
|
+
target_id,
|
|
1053
|
+
target_path,
|
|
1054
|
+
target.name,
|
|
1055
|
+
target_summary,
|
|
1056
|
+
scope,
|
|
1057
|
+
args.mode,
|
|
1058
|
+
user_context,
|
|
1059
|
+
*diff_identity,
|
|
1060
|
+
timestamp,
|
|
1061
|
+
timestamp,
|
|
1062
|
+
),
|
|
1063
1063
|
)
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1064
|
+
workspace = require_workspace(connection, workspace_id)
|
|
1065
|
+
insert_running_scan(
|
|
1066
|
+
connection,
|
|
1067
|
+
scan_id=scan_id,
|
|
1068
|
+
workspace=workspace,
|
|
1069
|
+
target=target,
|
|
1070
|
+
scope=scope,
|
|
1071
|
+
diff_target=diff_target,
|
|
1072
|
+
target_identity=target_identity,
|
|
1073
|
+
target_root=target_root,
|
|
1074
|
+
target_summary=target_summary,
|
|
1075
|
+
scope_file_count=scope_file_count,
|
|
1076
|
+
timestamp=timestamp,
|
|
1077
|
+
handoff_status="delivered",
|
|
1078
|
+
model=args.model,
|
|
1079
|
+
reasoning_effort=args.reasoning_effort,
|
|
1080
|
+
)
|
|
1081
|
+
if headless_standard:
|
|
1082
|
+
claimed = connection.execute(
|
|
1083
|
+
"""
|
|
1084
|
+
UPDATE scans
|
|
1085
|
+
SET handoff_claim_token = ?, continuation_thread_id = ?
|
|
1086
|
+
WHERE id = ? AND status = 'running' AND handoff_status = 'delivered'
|
|
1087
|
+
AND handoff_claim_token IS NULL AND continuation_thread_id IS NULL
|
|
1088
|
+
""",
|
|
1089
|
+
(str(uuid.uuid4()), thread_id, scan_id),
|
|
1090
|
+
)
|
|
1091
|
+
if claimed.rowcount != 1:
|
|
1092
|
+
raise SystemExit(
|
|
1093
|
+
"Codex Security headless scan ownership could not be recorded."
|
|
1094
|
+
)
|
|
1095
|
+
connection.commit()
|
|
1096
|
+
break
|
|
1097
|
+
except sqlite3.OperationalError as exc:
|
|
1098
|
+
connection.rollback()
|
|
1099
|
+
if attempt == SQLITE_RETRY_ATTEMPTS - 1 or not sqlite_busy(exc):
|
|
1100
|
+
raise
|
|
1101
|
+
time.sleep(0.05 * (2**attempt))
|
|
1102
|
+
except BaseException:
|
|
1103
|
+
connection.rollback()
|
|
1104
|
+
raise
|
|
1070
1105
|
return {**scan_context(connection, scan_id), "startDisposition": "created"}
|
|
1071
1106
|
|
|
1072
1107
|
|
|
@@ -1127,9 +1162,43 @@ def complete_scan(
|
|
|
1127
1162
|
cost_json,
|
|
1128
1163
|
prepare_only=prepare_only,
|
|
1129
1164
|
thread_id=getattr(args, "thread_id", None),
|
|
1165
|
+
turn_id=getattr(args, "turn_id", None),
|
|
1130
1166
|
)
|
|
1131
1167
|
|
|
1132
1168
|
|
|
1169
|
+
def finalize_scan_usage(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1170
|
+
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
1171
|
+
with scan_completion_lock(scan_id):
|
|
1172
|
+
scan = require_scan(connection, scan_id)
|
|
1173
|
+
stored = json.loads(scan["cost_json"]) if scan["cost_json"] is not None else {}
|
|
1174
|
+
usage = stored.get("usage", {})
|
|
1175
|
+
completion = usage.get("completion")
|
|
1176
|
+
if scan["status"] != "complete" or not completion:
|
|
1177
|
+
raise SystemExit("The scan has no pending completion usage.")
|
|
1178
|
+
if completion["threadId"] != args.thread_id or completion["turnId"] != args.turn_id:
|
|
1179
|
+
raise SystemExit("The scan usage belongs to a different completion turn.")
|
|
1180
|
+
if not completion["finalized"]:
|
|
1181
|
+
usage = scan_usage.collect_scan_usage(
|
|
1182
|
+
connection,
|
|
1183
|
+
scan,
|
|
1184
|
+
thread_id=args.thread_id,
|
|
1185
|
+
completed_turn_id=args.turn_id,
|
|
1186
|
+
)
|
|
1187
|
+
if usage["coverage"] == "unavailable":
|
|
1188
|
+
return scan_context(connection, scan_id)
|
|
1189
|
+
if args.turn_status != "completed":
|
|
1190
|
+
if usage["coverage"] == "complete":
|
|
1191
|
+
usage["coverage"] = "partial"
|
|
1192
|
+
usage["warnings"] = [*usage.get("warnings", []), f"scan_turn_{args.turn_status}"]
|
|
1193
|
+
usage["completion"] = {**completion, "finalized": True}
|
|
1194
|
+
cost_json = parse_scan_cost(json.dumps({**stored, "usage": usage}))
|
|
1195
|
+
with connection:
|
|
1196
|
+
connection.execute(
|
|
1197
|
+
"UPDATE scans SET cost_json = ? WHERE id = ?", (cost_json, scan_id)
|
|
1198
|
+
)
|
|
1199
|
+
return scan_context(connection, scan_id)
|
|
1200
|
+
|
|
1201
|
+
|
|
1133
1202
|
def complete_budget_exhausted_scan(
|
|
1134
1203
|
connection: sqlite3.Connection, args: argparse.Namespace
|
|
1135
1204
|
) -> dict[str, Any]:
|
|
@@ -1305,12 +1374,11 @@ def budget_exhausted_draft(
|
|
|
1305
1374
|
manifest = {
|
|
1306
1375
|
"scan": {
|
|
1307
1376
|
"target": target,
|
|
1308
|
-
"scope": {"limitations": [warning]
|
|
1377
|
+
"scope": {"limitations": [warning]},
|
|
1309
1378
|
}
|
|
1310
1379
|
}
|
|
1311
1380
|
findings = {"findings": []}
|
|
1312
1381
|
coverage = {
|
|
1313
|
-
"completeness": "partial",
|
|
1314
1382
|
"inventoryStrategy": (
|
|
1315
1383
|
"scoped_path" if expected_coverage_mode(scan) == "scoped_path" else "repository"
|
|
1316
1384
|
),
|
|
@@ -1396,7 +1464,7 @@ def budget_exhausted_draft(
|
|
|
1396
1464
|
"reason": "Validation was deferred because the scan reached its cost limit.",
|
|
1397
1465
|
}
|
|
1398
1466
|
)
|
|
1399
|
-
coverage
|
|
1467
|
+
coverage.pop("completeness", None)
|
|
1400
1468
|
for name, payload in (
|
|
1401
1469
|
("findings.json", findings),
|
|
1402
1470
|
("coverage.json", coverage),
|
|
@@ -1420,6 +1488,7 @@ def complete_scan_locked(
|
|
|
1420
1488
|
*,
|
|
1421
1489
|
prepare_only: bool = False,
|
|
1422
1490
|
thread_id: str | None = None,
|
|
1491
|
+
turn_id: str | None = None,
|
|
1423
1492
|
) -> dict[str, Any]:
|
|
1424
1493
|
scan = require_scan(connection, scan_id)
|
|
1425
1494
|
if scan["status"] == "complete":
|
|
@@ -1517,17 +1586,33 @@ def complete_scan_locked(
|
|
|
1517
1586
|
scan_dir,
|
|
1518
1587
|
expected_coverage_mode=expected_coverage_mode(scan),
|
|
1519
1588
|
completion_binding=completion_binding,
|
|
1520
|
-
|
|
1589
|
+
recover_unsealed=scan["mode"] != "deep",
|
|
1590
|
+
allow_missing_writeups=True,
|
|
1521
1591
|
draft_documents=draft_documents,
|
|
1592
|
+
finding_scope=requested_finding_scope(scan) if scan["mode"] == "deep" else None,
|
|
1522
1593
|
)
|
|
1594
|
+
warnings.extend(warning for warning in prepared.warnings if warning not in warnings)
|
|
1523
1595
|
add_warning()
|
|
1596
|
+
if prepared.warnings:
|
|
1597
|
+
# Save the explanation before publication removes the broken reference,
|
|
1598
|
+
# so a retry after failed publication retains it.
|
|
1599
|
+
with connection:
|
|
1600
|
+
connection.execute(
|
|
1601
|
+
"UPDATE scans SET completion_warnings_json = ? WHERE id = ? AND status = 'running'",
|
|
1602
|
+
(json.dumps(warnings), scan_id),
|
|
1603
|
+
)
|
|
1524
1604
|
wrote = True
|
|
1525
1605
|
manifest, findings, _ = _write_prepared_scan_finalization(
|
|
1526
1606
|
prepared, projection_warnings=warnings
|
|
1527
1607
|
)
|
|
1528
1608
|
except ContractError as exc:
|
|
1529
|
-
|
|
1609
|
+
# Only a coordinator-selected parent is fenced for output-write replay.
|
|
1610
|
+
selected_deep_parent = scan["mode"] == "deep" and deep_scan.require_deep_scan_run(
|
|
1611
|
+
connection, scan_id
|
|
1612
|
+
)["manifest_path"] == str(scan_dir / ARTIFACTS["manifest"])
|
|
1613
|
+
if (wrote and not selected_deep_parent) or (
|
|
1530
1614
|
scan["mode"] == "deep"
|
|
1615
|
+
and not wrote
|
|
1531
1616
|
and not already_sealed
|
|
1532
1617
|
and not isinstance(exc, RecoverableContractError)
|
|
1533
1618
|
):
|
|
@@ -1560,9 +1645,21 @@ def complete_scan_locked(
|
|
|
1560
1645
|
thread_id=thread_id,
|
|
1561
1646
|
completed_at=completion_timestamp,
|
|
1562
1647
|
)
|
|
1648
|
+
if thread_id is not None and turn_id is not None:
|
|
1649
|
+
measured_usage["completion"] = {
|
|
1650
|
+
"threadId": thread_id,
|
|
1651
|
+
"turnId": turn_id,
|
|
1652
|
+
"finalized": False,
|
|
1653
|
+
}
|
|
1654
|
+
if measured_usage["coverage"] == "complete":
|
|
1655
|
+
measured_usage["coverage"] = "partial"
|
|
1656
|
+
measured_usage["warnings"] = [
|
|
1657
|
+
*measured_usage.get("warnings", []),
|
|
1658
|
+
"turn_in_progress",
|
|
1659
|
+
]
|
|
1563
1660
|
cost_json = parse_scan_cost(scan_usage.measured_scan_cost_json(measured_usage))
|
|
1564
1661
|
connection.execute("BEGIN IMMEDIATE")
|
|
1565
|
-
|
|
1662
|
+
with connection:
|
|
1566
1663
|
timestamp = manifest["scan"]["completedAt"]
|
|
1567
1664
|
scan = require_scan(connection, scan["id"])
|
|
1568
1665
|
if scan["status"] == "complete":
|
|
@@ -1614,24 +1711,36 @@ def complete_scan_locked(
|
|
|
1614
1711
|
)
|
|
1615
1712
|
if updated.rowcount != 1:
|
|
1616
1713
|
raise SystemExit("Only a running scan can be completed.")
|
|
1617
|
-
connection.commit()
|
|
1618
|
-
except BaseException:
|
|
1619
|
-
connection.rollback()
|
|
1620
|
-
raise
|
|
1621
1714
|
context = scan_context(connection, scan["id"])
|
|
1622
1715
|
context["targetWarnings"] = target_warnings
|
|
1623
1716
|
return context
|
|
1624
1717
|
|
|
1625
1718
|
|
|
1626
|
-
def
|
|
1627
|
-
repository = require_target(args.repository)
|
|
1628
|
-
require_scannable_target(repository)
|
|
1719
|
+
def require_cli_scan_directory(repository: Path, args: argparse.Namespace) -> Path:
|
|
1629
1720
|
scan_dir = require_canonical_scan_directory(Path(args.scan_dir).expanduser())
|
|
1630
|
-
if scan_dir == repository or repository in scan_dir.parents:
|
|
1631
|
-
raise SystemExit(
|
|
1632
|
-
|
|
1721
|
+
if scan_dir == repository or repository in scan_dir.parents or scan_dir in repository.parents:
|
|
1722
|
+
raise SystemExit(
|
|
1723
|
+
"The scan artifact directory must be outside and not contain the selected target."
|
|
1724
|
+
)
|
|
1725
|
+
if (not args.archive_existing or args.archived_scan_dir is not None) and next(
|
|
1726
|
+
scan_dir.iterdir(), None
|
|
1727
|
+
) is not None:
|
|
1633
1728
|
raise SystemExit("The scan artifact directory must be empty before the scan starts.")
|
|
1729
|
+
return scan_dir
|
|
1730
|
+
|
|
1634
1731
|
|
|
1732
|
+
def register_cli_scan(
|
|
1733
|
+
connection: sqlite3.Connection,
|
|
1734
|
+
args: argparse.Namespace,
|
|
1735
|
+
*,
|
|
1736
|
+
before_archive: Callable[[], None] | None = None,
|
|
1737
|
+
) -> dict[str, Any]:
|
|
1738
|
+
repository = require_target(args.repository)
|
|
1739
|
+
require_scannable_target(repository)
|
|
1740
|
+
scan_dir = None
|
|
1741
|
+
if not args.archive_existing or args.archived_scan_dir is not None:
|
|
1742
|
+
# Preserve early output rejection when this call will not move the directory.
|
|
1743
|
+
scan_dir = require_cli_scan_directory(repository, args)
|
|
1635
1744
|
user_context = None
|
|
1636
1745
|
workflow_id = None
|
|
1637
1746
|
if args.registration_json_stdin:
|
|
@@ -1644,6 +1753,10 @@ def register_cli_scan(connection: sqlite3.Connection, args: argparse.Namespace)
|
|
|
1644
1753
|
recipe = parse_scan_recipe(recipe_json, repository)
|
|
1645
1754
|
requested_target = recipe["target"]
|
|
1646
1755
|
paths = requested_target["paths"]
|
|
1756
|
+
# Capture host-observed kinds once; resumes and publication use the saved recipe.
|
|
1757
|
+
recipe.pop("scopeFilePaths", None)
|
|
1758
|
+
if file_paths := [path for path in paths if (repository / path).is_file()]:
|
|
1759
|
+
recipe["scopeFilePaths"] = file_paths
|
|
1647
1760
|
scope = paths[0] if len(paths) == 1 else "."
|
|
1648
1761
|
diff_target = None
|
|
1649
1762
|
if requested_target["kind"] in {"refs", "working_tree"}:
|
|
@@ -1681,63 +1794,81 @@ def register_cli_scan(connection: sqlite3.Connection, args: argparse.Namespace)
|
|
|
1681
1794
|
workspace_id = str(uuid.uuid4())
|
|
1682
1795
|
|
|
1683
1796
|
connection.execute("BEGIN IMMEDIATE")
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
raise SystemExit("A rerun must belong to the same repository as its parent scan.")
|
|
1691
|
-
|
|
1692
|
-
connection.execute(
|
|
1693
|
-
"""
|
|
1694
|
-
INSERT INTO workspaces (
|
|
1695
|
-
id, target_id, target_path, target_title, default_scope, default_mode,
|
|
1696
|
-
diff_target_kind, diff_base_revision, diff_head_revision,
|
|
1697
|
-
diff_content_digest, submitted, created_at, updated_at
|
|
1698
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)
|
|
1699
|
-
""",
|
|
1700
|
-
(
|
|
1701
|
-
workspace_id,
|
|
1702
|
-
target_id,
|
|
1703
|
-
str(repository),
|
|
1704
|
-
repository.name,
|
|
1705
|
-
scope,
|
|
1706
|
-
mode,
|
|
1707
|
-
*scan_diff_identity(diff_target),
|
|
1708
|
-
timestamp,
|
|
1709
|
-
timestamp,
|
|
1710
|
-
),
|
|
1711
|
-
)
|
|
1712
|
-
workspace = require_workspace(connection, workspace_id)
|
|
1713
|
-
insert_running_scan(
|
|
1797
|
+
try:
|
|
1798
|
+
if scan_dir is None:
|
|
1799
|
+
# Host archiving temporarily removes the output directory. Wait for
|
|
1800
|
+
# the existing writer before inspecting its replacement.
|
|
1801
|
+
scan_dir = require_cli_scan_directory(repository, args)
|
|
1802
|
+
with archive_scan(
|
|
1714
1803
|
connection,
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1804
|
+
args,
|
|
1805
|
+
scan_dir,
|
|
1806
|
+
timestamp,
|
|
1807
|
+
require_canonical_scan_directory,
|
|
1808
|
+
before_archive=before_archive,
|
|
1809
|
+
) as archived_scan_dir:
|
|
1810
|
+
target_id = ensure_security_target(connection, str(repository))
|
|
1811
|
+
if parent_scan_id is not None:
|
|
1812
|
+
parent = require_scan(connection, parent_scan_id)
|
|
1813
|
+
if parent["target_id"] != target_id:
|
|
1814
|
+
raise SystemExit(
|
|
1815
|
+
"A rerun must belong to the same repository as its parent scan."
|
|
1816
|
+
)
|
|
1817
|
+
|
|
1818
|
+
connection.execute(
|
|
1819
|
+
"""
|
|
1820
|
+
INSERT INTO workspaces (
|
|
1821
|
+
id, target_id, target_path, target_title, default_scope, default_mode,
|
|
1822
|
+
diff_target_kind, diff_base_revision, diff_head_revision,
|
|
1823
|
+
diff_content_digest, submitted, created_at, updated_at
|
|
1824
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)
|
|
1825
|
+
""",
|
|
1826
|
+
(
|
|
1827
|
+
workspace_id,
|
|
1828
|
+
target_id,
|
|
1829
|
+
str(repository),
|
|
1830
|
+
repository.name,
|
|
1831
|
+
scope,
|
|
1832
|
+
mode,
|
|
1833
|
+
*scan_diff_identity(diff_target),
|
|
1834
|
+
timestamp,
|
|
1835
|
+
timestamp,
|
|
1836
|
+
),
|
|
1837
|
+
)
|
|
1838
|
+
workspace = require_workspace(connection, workspace_id)
|
|
1839
|
+
insert_running_scan(
|
|
1840
|
+
connection,
|
|
1841
|
+
scan_id=scan_id,
|
|
1842
|
+
workspace=workspace,
|
|
1843
|
+
target=repository,
|
|
1844
|
+
scope=scope,
|
|
1845
|
+
diff_target=diff_target,
|
|
1846
|
+
target_identity=target_identity,
|
|
1847
|
+
target_root=scan_dir.parent,
|
|
1848
|
+
target_summary=None,
|
|
1849
|
+
scope_file_count=scope_file_count,
|
|
1850
|
+
timestamp=timestamp,
|
|
1851
|
+
handoff_status="delivered",
|
|
1852
|
+
scan_dir=scan_dir,
|
|
1853
|
+
)
|
|
1854
|
+
connection.execute(
|
|
1855
|
+
"UPDATE scans SET recipe_json = ?, parent_scan_id = ?, user_context = ? WHERE id = ?",
|
|
1856
|
+
(
|
|
1857
|
+
json.dumps(recipe, allow_nan=False, separators=(",", ":"), sort_keys=True),
|
|
1858
|
+
parent_scan_id,
|
|
1859
|
+
user_context,
|
|
1860
|
+
scan_id,
|
|
1861
|
+
),
|
|
1862
|
+
)
|
|
1863
|
+
if workflow_id is not None:
|
|
1864
|
+
register_workflow_scan(connection, workflow_id, scan_id, str(scan_dir), timestamp)
|
|
1865
|
+
connection.commit()
|
|
1866
|
+
except BaseException:
|
|
1867
|
+
connection.rollback()
|
|
1868
|
+
raise
|
|
1739
1869
|
scan = require_scan(connection, scan_id)
|
|
1740
1870
|
return {
|
|
1871
|
+
**({"archivedScanDir": str(archived_scan_dir)} if archived_scan_dir is not None else {}),
|
|
1741
1872
|
"contract": scan_contract(scan),
|
|
1742
1873
|
"scanDir": str(scan_dir),
|
|
1743
1874
|
"scanId": scan_id,
|
|
@@ -1835,24 +1966,6 @@ def coverage_for_comparison(scan: sqlite3.Row) -> dict[str, Any]:
|
|
|
1835
1966
|
return saved_results.coverage_for_comparison(_WORKBENCH_DB_CONTEXT, scan)
|
|
1836
1967
|
|
|
1837
1968
|
|
|
1838
|
-
def preserve_scan_results_locked(connection: sqlite3.Connection, scan_id: str) -> bool:
|
|
1839
|
-
return saved_results.preserve_scan_results_locked(_WORKBENCH_DB_CONTEXT, connection, scan_id)
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
def recover_scan_results(
|
|
1843
|
-
connection: sqlite3.Connection, args: argparse.Namespace
|
|
1844
|
-
) -> dict[str, Any]:
|
|
1845
|
-
return saved_results.recover_scan_results(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
def fail_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1849
|
-
return saved_results.fail_scan(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
def cancel_scan_locked(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1853
|
-
return saved_results.cancel_scan_locked(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
1969
|
def preserve_stopped_results_after_transition(connection: sqlite3.Connection, scan_id: str) -> None:
|
|
1857
1970
|
saved_results.preserve_stopped_results_after_transition(
|
|
1858
1971
|
_WORKBENCH_DB_CONTEXT, connection, scan_id
|
|
@@ -1887,7 +2000,7 @@ def set_finding_triage(connection: sqlite3.Connection, args: argparse.Namespace)
|
|
|
1887
2000
|
and remediation["pending_action"] is not None
|
|
1888
2001
|
and not (
|
|
1889
2002
|
remediation["state"] == "failed"
|
|
1890
|
-
and not remediation_claim_is_active(remediation)
|
|
2003
|
+
and not remediation_state.remediation_claim_is_active(remediation)
|
|
1891
2004
|
)
|
|
1892
2005
|
):
|
|
1893
2006
|
raise SystemExit(
|
|
@@ -1957,7 +2070,7 @@ def request_finding_remediation(
|
|
|
1957
2070
|
) -> dict[str, Any]:
|
|
1958
2071
|
request_id = require_uuid(args.request_id, "request-id")
|
|
1959
2072
|
action_token = require_uuid(args.action_token, "action-token")
|
|
1960
|
-
|
|
2073
|
+
with connection:
|
|
1961
2074
|
occurrence = require_occurrence(connection, args.occurrence_id)
|
|
1962
2075
|
require_finding_open(connection, occurrence["id"])
|
|
1963
2076
|
scan = require_scan(connection, occurrence["scan_id"])
|
|
@@ -1999,7 +2112,7 @@ def request_finding_remediation(
|
|
|
1999
2112
|
"verifying",
|
|
2000
2113
|
}
|
|
2001
2114
|
if active_operation and (
|
|
2002
|
-
latest["state"] != "failed" or remediation_claim_is_active(latest)
|
|
2115
|
+
latest["state"] != "failed" or remediation_state.remediation_claim_is_active(latest)
|
|
2003
2116
|
):
|
|
2004
2117
|
raise SystemExit(
|
|
2005
2118
|
"Finish or retry the active remediation operation before regenerating."
|
|
@@ -2046,10 +2159,6 @@ def request_finding_remediation(
|
|
|
2046
2159
|
timestamp,
|
|
2047
2160
|
),
|
|
2048
2161
|
)
|
|
2049
|
-
connection.commit()
|
|
2050
|
-
except BaseException:
|
|
2051
|
-
connection.rollback()
|
|
2052
|
-
raise
|
|
2053
2162
|
return scan_context(connection, occurrence["scan_id"])
|
|
2054
2163
|
|
|
2055
2164
|
|
|
@@ -2058,16 +2167,11 @@ def request_finding_remediation_action(
|
|
|
2058
2167
|
) -> dict[str, Any]:
|
|
2059
2168
|
request_id = require_uuid(args.request_id, "request-id")
|
|
2060
2169
|
action_token = require_uuid(args.action_token, "action-token")
|
|
2061
|
-
|
|
2170
|
+
with connection:
|
|
2062
2171
|
occurrence = require_occurrence(connection, args.occurrence_id)
|
|
2063
2172
|
require_finding_open(connection, occurrence["id"])
|
|
2064
2173
|
scan = require_scan(connection, occurrence["scan_id"])
|
|
2065
|
-
current =
|
|
2066
|
-
"SELECT * FROM finding_remediation_attempts WHERE request_id = ?",
|
|
2067
|
-
(request_id,),
|
|
2068
|
-
).fetchone()
|
|
2069
|
-
if current is None or current["occurrence_id"] != occurrence["id"]:
|
|
2070
|
-
raise SystemExit("Codex Security finding remediation request not found.")
|
|
2174
|
+
current = remediation_state.require_request(connection, request_id, occurrence)
|
|
2071
2175
|
if current["pending_action"] is not None:
|
|
2072
2176
|
if (
|
|
2073
2177
|
current["pending_action"] == args.action
|
|
@@ -2122,10 +2226,6 @@ def request_finding_remediation_action(
|
|
|
2122
2226
|
raise SystemExit(
|
|
2123
2227
|
"This remediation request changed. Refresh it before recording an update."
|
|
2124
2228
|
)
|
|
2125
|
-
connection.commit()
|
|
2126
|
-
except BaseException:
|
|
2127
|
-
connection.rollback()
|
|
2128
|
-
raise
|
|
2129
2229
|
return scan_context(connection, occurrence["scan_id"])
|
|
2130
2230
|
|
|
2131
2231
|
|
|
@@ -2135,16 +2235,11 @@ def claim_finding_remediation_resend(
|
|
|
2135
2235
|
request_id = require_uuid(args.request_id, "request-id")
|
|
2136
2236
|
action_token = require_uuid(args.action_token, "action-token")
|
|
2137
2237
|
connection.execute("BEGIN IMMEDIATE")
|
|
2138
|
-
|
|
2238
|
+
with connection:
|
|
2139
2239
|
timestamp = now()
|
|
2140
2240
|
occurrence = require_occurrence(connection, args.occurrence_id)
|
|
2141
2241
|
require_finding_open(connection, occurrence["id"])
|
|
2142
|
-
current =
|
|
2143
|
-
"SELECT * FROM finding_remediation_attempts WHERE request_id = ?",
|
|
2144
|
-
(request_id,),
|
|
2145
|
-
).fetchone()
|
|
2146
|
-
if current is None or current["occurrence_id"] != occurrence["id"]:
|
|
2147
|
-
raise SystemExit("Codex Security finding remediation request not found.")
|
|
2242
|
+
current = remediation_state.require_request(connection, request_id, occurrence)
|
|
2148
2243
|
if current["pending_action"] is None:
|
|
2149
2244
|
raise SystemExit("This remediation attempt does not have a pending host request.")
|
|
2150
2245
|
if current["pending_action_claim_token"] == action_token:
|
|
@@ -2154,7 +2249,6 @@ def claim_finding_remediation_resend(
|
|
|
2154
2249
|
return result
|
|
2155
2250
|
delivered_at = current["pending_action_delivered_at"]
|
|
2156
2251
|
if delivered_at is not None:
|
|
2157
|
-
claimed_token = action_token
|
|
2158
2252
|
updated = connection.execute(
|
|
2159
2253
|
"""
|
|
2160
2254
|
UPDATE finding_remediation_attempts
|
|
@@ -2177,7 +2271,6 @@ def claim_finding_remediation_resend(
|
|
|
2177
2271
|
"This remediation worker is still within its execution lease. Retry later."
|
|
2178
2272
|
)
|
|
2179
2273
|
else:
|
|
2180
|
-
claimed_token = action_token
|
|
2181
2274
|
updated = connection.execute(
|
|
2182
2275
|
"""
|
|
2183
2276
|
UPDATE finding_remediation_attempts
|
|
@@ -2202,12 +2295,8 @@ def claim_finding_remediation_resend(
|
|
|
2202
2295
|
unavailable = "This remediation host request is still owned by another panel. Retry after its lease expires."
|
|
2203
2296
|
if updated.rowcount != 1:
|
|
2204
2297
|
raise SystemExit(unavailable)
|
|
2205
|
-
connection.commit()
|
|
2206
|
-
except BaseException:
|
|
2207
|
-
connection.rollback()
|
|
2208
|
-
raise
|
|
2209
2298
|
result = scan_context(connection, occurrence["scan_id"])
|
|
2210
|
-
result["actionToken"] =
|
|
2299
|
+
result["actionToken"] = action_token
|
|
2211
2300
|
return result
|
|
2212
2301
|
|
|
2213
2302
|
|
|
@@ -2267,12 +2356,7 @@ def set_finding_remediation(
|
|
|
2267
2356
|
occurrence = require_occurrence(connection, args.occurrence_id)
|
|
2268
2357
|
require_finding_open(connection, occurrence["id"])
|
|
2269
2358
|
scan = require_scan(connection, occurrence["scan_id"])
|
|
2270
|
-
current =
|
|
2271
|
-
"SELECT * FROM finding_remediation_attempts WHERE request_id = ?",
|
|
2272
|
-
(request_id,),
|
|
2273
|
-
).fetchone()
|
|
2274
|
-
if current is None or current["occurrence_id"] != occurrence["id"]:
|
|
2275
|
-
raise SystemExit("Codex Security finding remediation request not found.")
|
|
2359
|
+
current = remediation_state.require_request(connection, request_id, occurrence)
|
|
2276
2360
|
if current["version"] != args.expected_version:
|
|
2277
2361
|
raise SystemExit(
|
|
2278
2362
|
"This remediation request changed. Refresh it before recording an update."
|
|
@@ -2283,8 +2367,8 @@ def set_finding_remediation(
|
|
|
2283
2367
|
)
|
|
2284
2368
|
if current["pending_action_claim_token"] != action_token:
|
|
2285
2369
|
raise SystemExit("This remediation host request is owned by a different action token.")
|
|
2286
|
-
|
|
2287
|
-
|
|
2370
|
+
remediation_state.require_transition(current["state"], args.state)
|
|
2371
|
+
remediation_state.require_pending_action(current, args.state)
|
|
2288
2372
|
patch_path = current["patch_path"]
|
|
2289
2373
|
if args.patch_path is not None:
|
|
2290
2374
|
requested_patch_path = require_scan_relative_file(scan, args.patch_path)
|
|
@@ -2381,10 +2465,6 @@ def set_finding_remediation(
|
|
|
2381
2465
|
return scan_context(connection, occurrence["scan_id"])
|
|
2382
2466
|
|
|
2383
2467
|
|
|
2384
|
-
def export_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
2385
|
-
return publication.export_findings(_WORKBENCH_PUBLICATION_CONTEXT, connection, args)
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
2468
|
def require_reviewed_patch_applied(
|
|
2389
2469
|
scan: sqlite3.Row, remediation: sqlite3.Row, patch_path: str
|
|
2390
2470
|
) -> str | None:
|
|
@@ -2398,11 +2478,10 @@ def require_reviewed_patch_applied(
|
|
|
2398
2478
|
)
|
|
2399
2479
|
unversioned = remediation["base_revision"] == "unversioned"
|
|
2400
2480
|
excluded = (Path(scan["scan_dir"]),)
|
|
2401
|
-
|
|
2402
|
-
|
|
2481
|
+
# Unborn repositories still need their config while metadata junctions are deferred.
|
|
2482
|
+
git_dir = git_output(target, "rev-parse", "--absolute-git-dir")
|
|
2403
2483
|
if not unversioned:
|
|
2404
|
-
|
|
2405
|
-
git_dir = git_output(target, "rev-parse", "--absolute-git-dir")
|
|
2484
|
+
repository, pathspec = git_worktree_context(target)
|
|
2406
2485
|
if git_dir is None:
|
|
2407
2486
|
raise SystemExit("Could not inspect the selected Git working tree.")
|
|
2408
2487
|
excluded += tuple(path for path, _ in git_submodule_entries(target))
|
|
@@ -2419,9 +2498,9 @@ def require_reviewed_patch_applied(
|
|
|
2419
2498
|
checkout_root = Path(temporary) / "checkout"
|
|
2420
2499
|
if unversioned:
|
|
2421
2500
|
checkout = checkout_root
|
|
2422
|
-
copy_directory_excluding(target, checkout, excluded)
|
|
2501
|
+
junctions = copy_directory_excluding(target, checkout, excluded)
|
|
2423
2502
|
else:
|
|
2424
|
-
copy_git_worktree_files(target, checkout_root, excluded)
|
|
2503
|
+
_, junctions = copy_git_worktree_files(target, checkout_root, excluded)
|
|
2425
2504
|
arguments = ["apply", "--reverse", "--whitespace=nowarn"]
|
|
2426
2505
|
if unversioned:
|
|
2427
2506
|
arguments.append("--no-index")
|
|
@@ -2439,6 +2518,11 @@ def require_reviewed_patch_applied(
|
|
|
2439
2518
|
raise SystemExit(
|
|
2440
2519
|
"The selected checkout does not contain the reviewed remediation patch. Apply exactly that patch before recording it as applied."
|
|
2441
2520
|
)
|
|
2521
|
+
restore_directory_junctions(
|
|
2522
|
+
target if unversioned else repository,
|
|
2523
|
+
checkout if unversioned else checkout_root,
|
|
2524
|
+
junctions,
|
|
2525
|
+
)
|
|
2442
2526
|
reverted_digest = (
|
|
2443
2527
|
directory_content_digest(checkout)
|
|
2444
2528
|
if unversioned
|
|
@@ -2451,11 +2535,16 @@ def require_reviewed_patch_applied(
|
|
|
2451
2535
|
)
|
|
2452
2536
|
if reverted_digest != remediation["base_content_digest"] and unversioned:
|
|
2453
2537
|
checkout = Path(temporary) / "checkout-lf"
|
|
2454
|
-
copy_directory_excluding(target, checkout, excluded)
|
|
2538
|
+
junctions = copy_directory_excluding(target, checkout, excluded)
|
|
2455
2539
|
applied_without_conversion = git_command(
|
|
2456
|
-
checkout,
|
|
2540
|
+
checkout,
|
|
2541
|
+
"-c",
|
|
2542
|
+
"core.autocrlf=input",
|
|
2543
|
+
*arguments,
|
|
2544
|
+
text=True,
|
|
2457
2545
|
)
|
|
2458
2546
|
if applied_without_conversion.returncode == 0:
|
|
2547
|
+
restore_directory_junctions(target, checkout, junctions)
|
|
2459
2548
|
reverted_digest = directory_content_digest(checkout)
|
|
2460
2549
|
if reverted_digest != remediation["base_content_digest"]:
|
|
2461
2550
|
raise SystemExit(
|
|
@@ -2502,15 +2591,14 @@ def require_sha256_digest(value: str, label: str) -> str:
|
|
|
2502
2591
|
|
|
2503
2592
|
|
|
2504
2593
|
def require_scan_relative_file(scan: sqlite3.Row, value: str) -> str:
|
|
2505
|
-
|
|
2506
|
-
|
|
2594
|
+
if len(value) > 4096:
|
|
2595
|
+
raise SystemExit("Text value must be no longer than 4096 characters.")
|
|
2596
|
+
if not value.strip() or "\\" in value:
|
|
2507
2597
|
raise SystemExit("Patch path must identify a scan-local regular file.")
|
|
2508
|
-
parsed = PurePosixPath(
|
|
2598
|
+
parsed = PurePosixPath(value)
|
|
2509
2599
|
if parsed.is_absolute() or ".." in parsed.parts:
|
|
2510
2600
|
raise SystemExit("Patch path must identify a scan-local regular file.")
|
|
2511
|
-
|
|
2512
|
-
if path is None:
|
|
2513
|
-
raise SystemExit("Patch path must identify a scan-local regular file.")
|
|
2601
|
+
artifact_path(Path(scan["scan_dir"]), parsed.as_posix(), required=True)
|
|
2514
2602
|
return parsed.as_posix()
|
|
2515
2603
|
|
|
2516
2604
|
|
|
@@ -2604,6 +2692,7 @@ def workspace_state(
|
|
|
2604
2692
|
target = require_target(workspace["target_path"])
|
|
2605
2693
|
target_metadata = git_target_metadata(target)
|
|
2606
2694
|
except SystemExit:
|
|
2695
|
+
# Target metadata is optional; retain the original setup error for the caller.
|
|
2607
2696
|
pass
|
|
2608
2697
|
result["diffTarget"] = validated_diff_target or persisted_diff_target
|
|
2609
2698
|
result["setupValidation"] = {
|
|
@@ -2761,13 +2850,10 @@ def scan_result(
|
|
|
2761
2850
|
"status": "canceled" if scan["canceled_at"] else scan["status"],
|
|
2762
2851
|
"updatedAt": progress["updated_at"],
|
|
2763
2852
|
}
|
|
2853
|
+
review_updated_at = ""
|
|
2764
2854
|
if independent_reviews is not None:
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
"completed": independent_reviews["completed"],
|
|
2768
|
-
"maximum": independent_reviews["maximum"],
|
|
2769
|
-
"consolidating": independent_reviews["consolidating"],
|
|
2770
|
-
}
|
|
2855
|
+
review_updated_at = str(independent_reviews.pop("updatedAt"))
|
|
2856
|
+
progress_result["independentReviews"] = independent_reviews
|
|
2771
2857
|
relations = scan_history.finding_relations(
|
|
2772
2858
|
connection, scan["id"], (row["id"] for row in occurrence_rows)
|
|
2773
2859
|
)
|
|
@@ -2794,6 +2880,7 @@ def scan_result(
|
|
|
2794
2880
|
"mode": scan["mode"],
|
|
2795
2881
|
"model": scan["model"],
|
|
2796
2882
|
"diffTarget": stored_diff_target(scan),
|
|
2883
|
+
"name": scan["name"],
|
|
2797
2884
|
"progress": progress_result,
|
|
2798
2885
|
"reasoningEffort": scan["reasoning_effort"],
|
|
2799
2886
|
"remediationAvailable": remediation_available,
|
|
@@ -2811,7 +2898,7 @@ def scan_result(
|
|
|
2811
2898
|
"updatedAt": max(
|
|
2812
2899
|
scan["updated_at"],
|
|
2813
2900
|
progress["updated_at"],
|
|
2814
|
-
|
|
2901
|
+
review_updated_at,
|
|
2815
2902
|
finding_management_updated_at(connection, scan["id"]) or "",
|
|
2816
2903
|
),
|
|
2817
2904
|
"userContext": scan["user_context"],
|
|
@@ -2821,7 +2908,7 @@ def scan_result(
|
|
|
2821
2908
|
|
|
2822
2909
|
def remediation_availability(scan: sqlite3.Row) -> tuple[bool, str | None]:
|
|
2823
2910
|
if scan["status"] != "complete":
|
|
2824
|
-
return False,
|
|
2911
|
+
return False, remediation_state.SCAN_STATUS_ERROR
|
|
2825
2912
|
try:
|
|
2826
2913
|
current_revision = git_revision(require_scan_target_identity(scan))
|
|
2827
2914
|
except SystemExit as exc:
|
|
@@ -3115,8 +3202,7 @@ def finding_remediation_result(
|
|
|
3115
3202
|
row = connection.execute(
|
|
3116
3203
|
"""
|
|
3117
3204
|
SELECT remediation.request_id, remediation.state, remediation.version,
|
|
3118
|
-
remediation.base_revision, remediation.
|
|
3119
|
-
remediation.applied_content_digest, remediation.pending_action,
|
|
3205
|
+
remediation.base_revision, remediation.pending_action,
|
|
3120
3206
|
remediation.pending_action_claimed_at, remediation.pending_action_claim_token,
|
|
3121
3207
|
remediation.pending_action_delivered_at,
|
|
3122
3208
|
remediation.patch_path, remediation.patch_digest, remediation.summary,
|
|
@@ -3286,22 +3372,18 @@ def read_json_object(path: Path) -> dict[str, Any]:
|
|
|
3286
3372
|
return payload
|
|
3287
3373
|
|
|
3288
3374
|
|
|
3289
|
-
_WORKBENCH_PUBLICATION_CONTEXT = SimpleNamespace(**globals())
|
|
3375
|
+
_WORKBENCH_PUBLICATION_CONTEXT = _WORKBENCH_DB_CONTEXT = SimpleNamespace(**globals())
|
|
3290
3376
|
|
|
3291
3377
|
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
def main() -> None:
|
|
3378
|
+
def main(*, before_archive: Callable[[], None] | None = None) -> None:
|
|
3296
3379
|
# Workbench callers send UTF-8 even when Windows uses a legacy code page.
|
|
3297
3380
|
sys.stdin.reconfigure(encoding="utf-8")
|
|
3298
3381
|
args = parse_args(__doc__)
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
preserve_stopped_results=preserve_stopped_results_after_transition,
|
|
3303
|
-
)
|
|
3382
|
+
command_context = SimpleNamespace(
|
|
3383
|
+
**globals(),
|
|
3384
|
+
preserve_stopped_results=preserve_stopped_results_after_transition,
|
|
3304
3385
|
)
|
|
3386
|
+
deep_scan.configure(command_context)
|
|
3305
3387
|
if args.command == "resolve-scan-root":
|
|
3306
3388
|
print(json.dumps({"scanRoot": str(resolve_scan_root(args.scan_root))}))
|
|
3307
3389
|
return
|
|
@@ -3324,58 +3406,83 @@ def main() -> None:
|
|
|
3324
3406
|
if args.command in {"save-artifact", "read-artifact"}:
|
|
3325
3407
|
print(json.dumps(saved_results.read_or_save_artifact(args)))
|
|
3326
3408
|
return
|
|
3327
|
-
if args.command == "
|
|
3328
|
-
result =
|
|
3329
|
-
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
3330
|
-
return
|
|
3331
|
-
if args.command == "inspect-linear-publication":
|
|
3332
|
-
result = publication.inspect_linear_publication(_WORKBENCH_PUBLICATION_CONTEXT, args)
|
|
3409
|
+
if args.command == "finding-issues":
|
|
3410
|
+
result = publication.finding_issues(_WORKBENCH_PUBLICATION_CONTEXT, json.load(sys.stdin))
|
|
3333
3411
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
3334
3412
|
return
|
|
3335
3413
|
with closing(
|
|
3336
3414
|
connect(deferred=args.command in {"get-scan", "list-scans", "database-info"})
|
|
3337
3415
|
) as connection:
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3416
|
+
remediation_state.require_available(connection, args, require_scan)
|
|
3417
|
+
handlers = {
|
|
3418
|
+
"create-workspace": create_workspace,
|
|
3419
|
+
"save-workspace": save_workspace,
|
|
3420
|
+
"start-scan": start_scan,
|
|
3421
|
+
"begin-deep-scan": deep_scan.begin_deep_scan,
|
|
3422
|
+
"get-deep-scan": deep_scan.get_deep_scan,
|
|
3423
|
+
"claim-deep-scan-coordinator": deep_scan.claim_deep_scan_coordinator,
|
|
3424
|
+
"upsert-deep-scan-worker": deep_scan.upsert_deep_scan_worker,
|
|
3425
|
+
"claim-deep-scan-dedup": deep_scan.claim_deep_scan_dedup,
|
|
3426
|
+
"commit-deep-scan-dedup": deep_scan.commit_deep_scan_dedup,
|
|
3427
|
+
"finish-deep-scan": deep_scan.finish_deep_scan,
|
|
3428
|
+
"fail-deep-scan": deep_scan.fail_deep_scan,
|
|
3429
|
+
"record-deep-scan-publication-failure": deep_scan.record_deep_scan_publication_failure,
|
|
3430
|
+
"list-scans": scan_history.list_scans,
|
|
3431
|
+
"register-cli-scan": partial(register_cli_scan, before_archive=before_archive),
|
|
3432
|
+
"set-scan-thread": set_scan_thread,
|
|
3433
|
+
"set-scan-cost-limit": set_scan_cost_limit,
|
|
3434
|
+
"finalize-scan-usage": finalize_scan_usage,
|
|
3435
|
+
"list-global-findings": native_indexes.list_global_findings,
|
|
3436
|
+
"list-repositories": native_indexes.list_repositories,
|
|
3437
|
+
"list-findings": list_findings,
|
|
3438
|
+
"complete-budget-exhausted-scan": complete_budget_exhausted_scan,
|
|
3439
|
+
"set-finding-triage": set_finding_triage,
|
|
3440
|
+
"request-finding-remediation": request_finding_remediation,
|
|
3441
|
+
"request-finding-remediation-action": request_finding_remediation_action,
|
|
3442
|
+
"claim-finding-remediation-resend": claim_finding_remediation_resend,
|
|
3443
|
+
"mark-finding-remediation-delivered": mark_finding_remediation_delivered,
|
|
3444
|
+
"release-finding-remediation-claim": release_finding_remediation_claim,
|
|
3445
|
+
"set-finding-remediation": set_finding_remediation,
|
|
3446
|
+
"update-progress": partial(progress.update_progress, command_context),
|
|
3447
|
+
"update-scan-context": partial(progress.update_context, command_context),
|
|
3448
|
+
"cancel-scan": partial(saved_results.cancel_scan, _WORKBENCH_DB_CONTEXT),
|
|
3449
|
+
"fail-scan": partial(saved_results.fail_scan, _WORKBENCH_DB_CONTEXT),
|
|
3450
|
+
"preserve-scan-results": partial(
|
|
3451
|
+
saved_results.preserve_scan_results, _WORKBENCH_DB_CONTEXT
|
|
3452
|
+
),
|
|
3453
|
+
"recover-scan-results": partial(
|
|
3454
|
+
saved_results.recover_scan_results, _WORKBENCH_DB_CONTEXT
|
|
3455
|
+
),
|
|
3456
|
+
"write-scan-draft": partial(saved_results.write_scan_draft, _WORKBENCH_DB_CONTEXT),
|
|
3457
|
+
"save-scan-artifact": partial(saved_results.save_scan_artifact, _WORKBENCH_DB_CONTEXT),
|
|
3458
|
+
"mark-handoff-delivered": partial(handoff.mark_handoff_delivered, command_context),
|
|
3459
|
+
"claim-handoff-delivery": partial(handoff.claim_handoff_delivery, command_context),
|
|
3460
|
+
"release-handoff-delivery": partial(handoff.release_handoff_delivery, command_context),
|
|
3461
|
+
"attach-scan-continuation-thread": partial(
|
|
3462
|
+
handoff.attach_scan_continuation_thread, command_context
|
|
3463
|
+
),
|
|
3464
|
+
"export-findings": partial(publication.export_findings, _WORKBENCH_PUBLICATION_CONTEXT),
|
|
3465
|
+
}
|
|
3466
|
+
if handler := handlers.get(args.command):
|
|
3467
|
+
result = handler(connection, args)
|
|
3341
3468
|
elif args.command == "get-workspace":
|
|
3342
3469
|
result = workspace_state(
|
|
3343
3470
|
connection,
|
|
3344
3471
|
args.workspace_id,
|
|
3345
3472
|
thread_id=args.thread_id,
|
|
3346
3473
|
)
|
|
3347
|
-
elif args.command == "save-workspace":
|
|
3348
|
-
result = save_workspace(connection, args)
|
|
3349
|
-
elif args.command == "start-scan":
|
|
3350
|
-
result = start_scan(connection, args)
|
|
3351
3474
|
elif args.command == "start-prompt-only-scan":
|
|
3352
3475
|
result = _start_prompt_driven_scan(connection, args, headless_standard=False)
|
|
3353
3476
|
elif args.command == "start-headless-standard-scan":
|
|
3354
3477
|
result = _start_prompt_driven_scan(connection, args, headless_standard=True)
|
|
3355
|
-
elif args.command == "begin-deep-scan":
|
|
3356
|
-
result = deep_scan.begin_deep_scan(connection, args)
|
|
3357
|
-
elif args.command == "get-deep-scan":
|
|
3358
|
-
result = deep_scan.get_deep_scan(connection, args)
|
|
3359
|
-
elif args.command == "claim-deep-scan-coordinator":
|
|
3360
|
-
result = deep_scan.claim_deep_scan_coordinator(connection, args)
|
|
3361
|
-
elif args.command == "upsert-deep-scan-worker":
|
|
3362
|
-
result = deep_scan.upsert_deep_scan_worker(connection, args)
|
|
3363
|
-
elif args.command == "claim-deep-scan-dedup":
|
|
3364
|
-
result = deep_scan.claim_deep_scan_dedup(connection, args)
|
|
3365
|
-
elif args.command == "commit-deep-scan-dedup":
|
|
3366
|
-
result = deep_scan.commit_deep_scan_dedup(connection, args)
|
|
3367
|
-
elif args.command == "finish-deep-scan":
|
|
3368
|
-
result = deep_scan.finish_deep_scan(connection, args)
|
|
3369
|
-
elif args.command == "fail-deep-scan":
|
|
3370
|
-
result = deep_scan.fail_deep_scan(connection, args)
|
|
3371
|
-
elif args.command == "record-deep-scan-publication-failure":
|
|
3372
|
-
result = deep_scan.record_deep_scan_publication_failure(connection, args)
|
|
3373
3478
|
elif args.command == "get-scan":
|
|
3374
3479
|
result = scan_context(connection, args.scan_id, args.occurrence_id)
|
|
3480
|
+
elif args.command == "rename-scan":
|
|
3481
|
+
result = scan_history.rename_scan(
|
|
3482
|
+
connection, require_scan(connection, args.scan_id), args.name
|
|
3483
|
+
)
|
|
3375
3484
|
elif args.command == "get-scan-feedback":
|
|
3376
3485
|
result = get_scan_feedback(connection, require_scan(connection, args.scan_id))
|
|
3377
|
-
elif args.command == "list-scans":
|
|
3378
|
-
result = scan_history.list_scans(connection, args)
|
|
3379
3486
|
elif args.command == "list-unmatched-scan-pairs":
|
|
3380
3487
|
result = scan_history.list_unmatched_scan_pairs(
|
|
3381
3488
|
connection,
|
|
@@ -3383,27 +3490,16 @@ def main() -> None:
|
|
|
3383
3490
|
backfill_finding_details=backfill_legacy_finding_details,
|
|
3384
3491
|
read_coverage=coverage_for_comparison,
|
|
3385
3492
|
)
|
|
3386
|
-
elif args.command == "register-cli-scan":
|
|
3387
|
-
result = register_cli_scan(connection, args)
|
|
3388
|
-
elif args.command == "set-scan-thread":
|
|
3389
|
-
result = set_scan_thread(connection, args)
|
|
3390
|
-
elif args.command == "set-scan-cost-limit":
|
|
3391
|
-
result = set_scan_cost_limit(connection, args)
|
|
3392
3493
|
elif args.command == "get-scan-recipe":
|
|
3393
3494
|
result = scan_history.scan_recipe(require_scan(connection, args.scan_id))
|
|
3394
3495
|
elif args.command == "get-cli-scan-resume":
|
|
3395
3496
|
scan = require_scan(connection, args.scan_id)
|
|
3396
3497
|
try:
|
|
3397
3498
|
result = scan_history.cli_scan_resume(
|
|
3499
|
+
command_context,
|
|
3398
3500
|
connection,
|
|
3399
3501
|
scan,
|
|
3400
3502
|
require_workspace(connection, scan["workspace_id"]),
|
|
3401
|
-
parse_scan_recipe=parse_scan_recipe,
|
|
3402
|
-
scan_contract=scan_contract,
|
|
3403
|
-
require_scan_directory=require_canonical_scan_directory,
|
|
3404
|
-
artifact_path=artifact_path,
|
|
3405
|
-
read_json_object=read_json_object,
|
|
3406
|
-
workbench_completion_binding=workbench_completion_binding,
|
|
3407
3503
|
)
|
|
3408
3504
|
except SystemExit as exc:
|
|
3409
3505
|
if not args.allow_unavailable:
|
|
@@ -3427,118 +3523,21 @@ def main() -> None:
|
|
|
3427
3523
|
require_scan=require_scan,
|
|
3428
3524
|
read_coverage=coverage_for_comparison,
|
|
3429
3525
|
)
|
|
3430
|
-
elif args.command == "list-global-findings":
|
|
3431
|
-
result = native_indexes.list_global_findings(connection, args)
|
|
3432
|
-
elif args.command == "list-repositories":
|
|
3433
|
-
result = native_indexes.list_repositories(connection, args)
|
|
3434
|
-
elif args.command == "list-findings":
|
|
3435
|
-
result = list_findings(connection, args)
|
|
3436
|
-
elif args.command in {"update-progress", "update-scan-context"}:
|
|
3437
|
-
result = progress.update(
|
|
3438
|
-
connection, args, now, require_scan, require_workspace, scan_context
|
|
3439
|
-
)
|
|
3440
3526
|
elif args.command in {"prepare-scan-completion", "complete-scan"}:
|
|
3441
3527
|
result = complete_scan(
|
|
3442
3528
|
connection, args, prepare_only=args.command == "prepare-scan-completion"
|
|
3443
3529
|
)
|
|
3444
|
-
elif args.command == "complete-budget-exhausted-scan":
|
|
3445
|
-
result = complete_budget_exhausted_scan(connection, args)
|
|
3446
|
-
elif args.command == "cancel-scan":
|
|
3447
|
-
result = saved_results.cancel_scan(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
3448
|
-
elif args.command == "fail-scan":
|
|
3449
|
-
result = fail_scan(connection, args)
|
|
3450
|
-
elif args.command == "preserve-scan-results":
|
|
3451
|
-
result = saved_results.preserve_scan_results(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
3452
|
-
elif args.command == "recover-scan-results":
|
|
3453
|
-
result = recover_scan_results(connection, args)
|
|
3454
|
-
elif args.command == "write-scan-draft":
|
|
3455
|
-
result = saved_results.write_scan_draft(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
3456
|
-
elif args.command == "save-scan-artifact":
|
|
3457
|
-
result = saved_results.save_scan_artifact(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
3458
|
-
elif args.command == "mark-handoff-delivered":
|
|
3459
|
-
result = handoff.mark_handoff_delivered(
|
|
3460
|
-
connection,
|
|
3461
|
-
args,
|
|
3462
|
-
now=now,
|
|
3463
|
-
require_scan=require_scan,
|
|
3464
|
-
require_workspace=require_workspace,
|
|
3465
|
-
workspace_state=workspace_state,
|
|
3466
|
-
)
|
|
3467
|
-
elif args.command == "claim-handoff-delivery":
|
|
3468
|
-
result = handoff.claim_handoff_delivery(
|
|
3469
|
-
connection,
|
|
3470
|
-
args,
|
|
3471
|
-
now=now,
|
|
3472
|
-
require_scan=require_scan,
|
|
3473
|
-
stale_claim_before=stale_claim_before,
|
|
3474
|
-
workspace_state=workspace_state,
|
|
3475
|
-
)
|
|
3476
|
-
elif args.command == "release-handoff-delivery":
|
|
3477
|
-
result = handoff.release_handoff_delivery(
|
|
3478
|
-
connection,
|
|
3479
|
-
args,
|
|
3480
|
-
now=now,
|
|
3481
|
-
require_scan=require_scan,
|
|
3482
|
-
workspace_state=workspace_state,
|
|
3483
|
-
)
|
|
3484
|
-
elif args.command == "attach-scan-continuation-thread":
|
|
3485
|
-
result = handoff.attach_scan_continuation_thread(
|
|
3486
|
-
connection,
|
|
3487
|
-
args,
|
|
3488
|
-
now=now,
|
|
3489
|
-
require_scan=require_scan,
|
|
3490
|
-
workspace_state=workspace_state,
|
|
3491
|
-
)
|
|
3492
|
-
elif args.command == "set-finding-triage":
|
|
3493
|
-
result = set_finding_triage(connection, args)
|
|
3494
|
-
elif args.command == "request-finding-remediation":
|
|
3495
|
-
result = request_finding_remediation(connection, args)
|
|
3496
|
-
elif args.command == "request-finding-remediation-action":
|
|
3497
|
-
result = request_finding_remediation_action(connection, args)
|
|
3498
|
-
elif args.command == "claim-finding-remediation-resend":
|
|
3499
|
-
result = claim_finding_remediation_resend(connection, args)
|
|
3500
|
-
elif args.command == "mark-finding-remediation-delivered":
|
|
3501
|
-
result = mark_finding_remediation_delivered(connection, args)
|
|
3502
|
-
elif args.command == "release-finding-remediation-claim":
|
|
3503
|
-
result = release_finding_remediation_claim(connection, args)
|
|
3504
3530
|
elif args.command == "cancel-finding-remediation-request":
|
|
3505
3531
|
result = scan_context(
|
|
3506
3532
|
connection,
|
|
3507
|
-
|
|
3508
|
-
)
|
|
3509
|
-
elif args.command == "set-finding-remediation":
|
|
3510
|
-
result = set_finding_remediation(connection, args)
|
|
3511
|
-
elif args.command == "prepare-linear-publication":
|
|
3512
|
-
result = publication.prepare_linear_publication(
|
|
3513
|
-
_WORKBENCH_PUBLICATION_CONTEXT, connection, args
|
|
3533
|
+
remediation_state.cancel_finding_remediation_request(connection, args),
|
|
3514
3534
|
)
|
|
3515
|
-
elif args.command == "record-linear-publications":
|
|
3516
|
-
result = publication.record_linear_publications(
|
|
3517
|
-
_WORKBENCH_PUBLICATION_CONTEXT, connection, args
|
|
3518
|
-
)
|
|
3519
|
-
elif args.command == "export-findings":
|
|
3520
|
-
result = export_findings(connection, args)
|
|
3521
3535
|
elif args.command == "database-info":
|
|
3522
3536
|
result = {"databasePath": str(database_path())}
|
|
3523
|
-
elif args.command == "
|
|
3524
|
-
result =
|
|
3537
|
+
elif args.command == "local-dedupe":
|
|
3538
|
+
result = local_dedupe(connection, json.load(sys.stdin), now())
|
|
3525
3539
|
elif args.command == "finding-workflow":
|
|
3526
3540
|
result = finding_workflow(connection, json.load(sys.stdin), now())
|
|
3527
|
-
elif args.command == "dashboard":
|
|
3528
|
-
result = dashboard(connection, json.load(sys.stdin))
|
|
3529
|
-
elif args.command == "store-findings":
|
|
3530
|
-
payload = json.load(sys.stdin)
|
|
3531
|
-
result = store_findings(
|
|
3532
|
-
connection, payload["entries"], now(), payload.get("repositoryId")
|
|
3533
|
-
)
|
|
3534
|
-
elif args.command == "find-potential-duplicates":
|
|
3535
|
-
result = find_potential_duplicates(connection, args.finding_id, args.repository_id)
|
|
3536
|
-
elif args.command == "store-dedupe-groups":
|
|
3537
|
-
result = store_dedupe_groups(connection, json.load(sys.stdin)["groups"], now())
|
|
3538
|
-
elif args.command == "list-dedupe-groups":
|
|
3539
|
-
result = list_dedupe_groups(connection, args.finding_id)
|
|
3540
|
-
elif args.command == "list-stored-findings":
|
|
3541
|
-
result = list_stored_findings(connection, limit=args.limit, offset=args.offset)
|
|
3542
3541
|
else:
|
|
3543
3542
|
raise SystemExit(f"Unknown command: {args.command}")
|
|
3544
3543
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|