@openai/codex-security 0.1.31 → 0.3.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 +442 -2434
- package/_bundled_plugin/.app.json +5 -1
- package/_bundled_plugin/.codex-plugin/plugin.json +9 -5
- package/_bundled_plugin/.mcp.json +3 -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 +7 -214
- 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 +563 -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 +5 -5
- package/_bundled_plugin/references/config-preflight.md +1 -5
- package/_bundled_plugin/references/core-scan.md +34 -10
- package/_bundled_plugin/references/final-report.md +13 -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 +3 -4
- package/_bundled_plugin/references/scan-contract.md +11 -6
- 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 +2 -2
- package/_bundled_plugin/schemas/coverage.schema.json +23 -47
- 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 +71 -192
- package/_bundled_plugin/schemas/scan-manifest.schema.json +83 -95
- 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 +245 -356
- 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 +29 -69
- package/_bundled_plugin/scripts/deep_scan_config.py +9 -11
- package/_bundled_plugin/scripts/deep_scan_workbench.py +208 -363
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -5
- package/_bundled_plugin/scripts/finalize_scan_contract.py +733 -375
- package/_bundled_plugin/scripts/finding_preview.py +81 -91
- package/_bundled_plugin/scripts/generate_in_scope_files.py +48 -102
- package/_bundled_plugin/scripts/generate_rank_input.py +117 -888
- package/_bundled_plugin/scripts/launch_codex_security_mcp +35 -6
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +5 -5
- package/_bundled_plugin/scripts/rank_preview.py +43 -902
- package/_bundled_plugin/scripts/report_projection.py +143 -219
- package/_bundled_plugin/scripts/snapshot_sqlite.py +6 -1
- package/_bundled_plugin/scripts/threat_model_projection.py +161 -0
- 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 +59 -9
- 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 +21 -6
- package/_bundled_plugin/scripts/workbench_cli.py +99 -190
- package/_bundled_plugin/scripts/workbench_constants.py +6 -14
- package/_bundled_plugin/scripts/workbench_db.py +524 -672
- package/_bundled_plugin/scripts/workbench_feedback.py +6 -3
- package/_bundled_plugin/scripts/workbench_finding_index.py +20 -7
- 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 +28 -18
- package/_bundled_plugin/scripts/workbench_progress.py +26 -92
- package/_bundled_plugin/scripts/workbench_publication.py +77 -116
- package/_bundled_plugin/scripts/workbench_remediation.py +14 -20
- package/_bundled_plugin/scripts/workbench_saved_results.py +1402 -263
- package/_bundled_plugin/scripts/workbench_scan_history.py +57 -57
- package/_bundled_plugin/scripts/workbench_scan_start.py +109 -52
- package/_bundled_plugin/scripts/workbench_scan_usage.py +30 -49
- package/_bundled_plugin/scripts/workbench_schema.py +71 -1370
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +16 -7
- package/_bundled_plugin/scripts/workbench_target.py +526 -150
- package/_bundled_plugin/scripts/workbench_target_state.py +1 -5
- package/_bundled_plugin/scripts/workbench_validation.py +19 -44
- package/_bundled_plugin/shared/workbench-history-repairs.json +218 -0
- package/_bundled_plugin/shared/workbench-migrations.json +397 -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 +6 -6
- package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +1 -1
- 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-diff-scan/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/security-scan/SKILL.md +22 -7
- package/_bundled_plugin/skills/security-scan/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +13 -1
- package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
- package/_bundled_plugin/skills/track-findings/SKILL.md +46 -178
- package/_bundled_plugin/skills/track-findings/agents/openai.yaml +1 -1
- 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 -15
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +970 -553
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +70 -0
- package/dist/artifact-export.d.ts.map +1 -0
- package/dist/artifact-export.js +292 -0
- package/dist/artifact-export.js.map +1 -0
- package/dist/auth.d.ts +2 -6
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +27 -12
- package/dist/auth.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +9 -9
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-scan-severity.d.ts.map +1 -1
- package/dist/classify-scan-severity.js +2 -5
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity.d.ts +28 -17
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +16 -35
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts +3 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +285 -0
- package/dist/cli-help.js.map +1 -0
- 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 +22 -24
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1660 -1556
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +11 -17
- 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-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +1 -2
- package/dist/codex-prompt.js.map +1 -1
- package/dist/codex-sdk-environment.d.ts +3 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -0
- package/dist/codex-sdk-environment.js +68 -0
- package/dist/codex-sdk-environment.js.map +1 -0
- package/dist/component-plan.d.ts +2 -5
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +38 -34
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +7 -5
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +54 -44
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +93 -104
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +15 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +124 -348
- 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 +75 -34
- 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 +116 -134
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +7 -6
- 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 +23 -16
- 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 +33 -20
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +9 -1
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +129 -20
- 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 +26 -4
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +59 -47
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.d.ts.map +1 -1
- package/dist/deduplication/deduplication.js +59 -113
- 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.map +1 -1
- package/dist/deduplication/records-protocol.js +12 -28
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +188 -12
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +34 -24
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/review.d.ts +7 -0
- package/dist/deduplication/review.d.ts.map +1 -1
- package/dist/deduplication/review.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 +159 -44
- 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 +7 -23
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-progress.d.ts +2 -1
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +32 -47
- 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 +5 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -7
- package/dist/errors.js.map +1 -1
- package/dist/feedback.d.ts.map +1 -1
- package/dist/feedback.js +53 -21
- package/dist/feedback.js.map +1 -1
- package/dist/finding-catalogue.d.ts.map +1 -1
- package/dist/finding-catalogue.js +26 -30
- 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 +18 -13
- 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 +16 -44
- package/dist/findings-import.js.map +1 -1
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +9 -4
- package/dist/github.js.map +1 -1
- package/dist/import-scan.d.ts.map +1 -1
- package/dist/import-scan.js +49 -39
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +11 -5
- 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 +115 -47
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js +4 -10
- 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 +24 -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 +225 -153
- 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 +69 -14
- package/dist/owner-evidence.js.map +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +5 -6
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config-schema.d.ts +10 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +5 -3
- package/dist/project-config.js.map +1 -1
- package/dist/prompt-files.d.ts +0 -1
- package/dist/prompt-files.d.ts.map +1 -1
- package/dist/prompt-files.js +2 -4
- package/dist/prompt-files.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 +40 -79
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +48 -76
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts +1 -2
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +7 -16
- 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 +138 -199
- package/dist/publish.js.map +1 -1
- package/dist/record.d.ts +2 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +4 -0
- package/dist/record.js.map +1 -0
- 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/result.d.ts +4 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +7 -0
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +25 -17
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +619 -255
- 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 +16 -32
- package/dist/saved-scan.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +19 -30
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +31 -18
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +307 -347
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +3 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +351 -92
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +55 -15
- 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 +14 -12
- 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 +18 -3
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +5 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +4 -0
- package/dist/scan-settings.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 +15 -33
- package/dist/security-policy-cli.js.map +1 -1
- package/dist/security-policy.d.ts +17 -9
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +131 -98
- 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 +11 -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 +55 -55
- 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 +20 -32
- 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 +6 -5
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +15 -10
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +12 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +124 -62
- package/dist/targets.js.map +1 -1
- package/dist/trusted-executable.d.ts +6 -1
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +28 -9
- package/dist/trusted-executable.js.map +1 -1
- package/dist/value.d.ts +2 -0
- package/dist/value.d.ts.map +1 -0
- package/dist/value.js +27 -0
- package/dist/value.js.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +3 -6
- package/dist/version.js.map +1 -1
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -2
- package/dist/windows-path.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 +2 -0
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +40 -46
- package/dist/worker-progress.js.map +1 -1
- package/docs/cli.md +1778 -0
- package/docs/dedupe-records.md +24 -0
- package/docs/findings-service.md +402 -0
- package/package.json +23 -23
- package/schemas/project-config.schema.json +5 -0
- package/_bundled_plugin/schemas/tools/worker-threat-model.schema.json +0 -18
- package/_bundled_plugin/scripts/normalize_candidates.py +0 -338
- 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 -119
- 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/findings-service.d.ts +0 -20
- package/dist/server/findings-service.d.ts.map +0 -1
- package/dist/server/findings-service.js +0 -31
- package/dist/server/findings-service.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 -6
- package/dist/server/routes.d.ts.map +0 -1
- package/dist/server/routes.js +0 -86
- 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 -17
- 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
|
@@ -9,24 +9,18 @@ import os
|
|
|
9
9
|
import shutil
|
|
10
10
|
import sqlite3
|
|
11
11
|
import sys
|
|
12
|
-
import tempfile
|
|
13
12
|
import uuid
|
|
14
|
-
from
|
|
13
|
+
from contextlib import nullcontext
|
|
15
14
|
from datetime import datetime, timedelta
|
|
16
15
|
from pathlib import Path
|
|
17
16
|
from typing import Any, Callable
|
|
18
17
|
|
|
19
18
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
19
|
+
import workbench_saved_results as saved_results
|
|
20
20
|
from deep_scan_config import resolve_deep_scan_config
|
|
21
|
-
from filesystem_identity import serialize_filesystem_identity
|
|
22
|
-
from finalize_scan_contract import _read_scan_local_json
|
|
23
21
|
from workbench.handoff import require_current_continuation
|
|
24
|
-
from
|
|
25
|
-
|
|
26
|
-
directory_snapshot_regular_file_count,
|
|
27
|
-
git_revision,
|
|
28
|
-
worktree_content_digest,
|
|
29
|
-
)
|
|
22
|
+
from workbench.storage import create_private_directory
|
|
23
|
+
from workbench_target import directory_snapshot_regular_file_count
|
|
30
24
|
from workbench_validation import optional_text, require_uuid, user_context_argument
|
|
31
25
|
|
|
32
26
|
DEEP_SCAN_WORKER_KINDS = ("setup", "discovery", "dedup")
|
|
@@ -136,42 +130,20 @@ def non_negative_int(value: str) -> int:
|
|
|
136
130
|
return parsed
|
|
137
131
|
|
|
138
132
|
|
|
139
|
-
|
|
140
|
-
class DeepScanDependencies:
|
|
141
|
-
now: Callable[[], str]
|
|
142
|
-
state_dir: Callable[[], Path]
|
|
143
|
-
require_scan: Callable[[sqlite3.Connection, str], sqlite3.Row]
|
|
144
|
-
require_workspace: Callable[[sqlite3.Connection, str], sqlite3.Row]
|
|
145
|
-
require_target: Callable[[str], Path]
|
|
146
|
-
require_remediation_target: Callable[[str], Path]
|
|
147
|
-
require_scannable_target: Callable[[Path], None]
|
|
148
|
-
require_scope: Callable[[str, str, Path], str]
|
|
149
|
-
ensure_security_target: Callable[[sqlite3.Connection, str], str]
|
|
150
|
-
require_canonical_scan_directory: Callable[[Path], Path]
|
|
151
|
-
safe_segment: Callable[[str], str]
|
|
152
|
-
compact_timestamp: Callable[[], str]
|
|
153
|
-
scan_completion_lock: Callable[[str], Any]
|
|
154
|
-
preserve_stopped_results: Callable[[sqlite3.Connection, str], None]
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
_dependencies: DeepScanDependencies | None = None
|
|
133
|
+
_dependencies: Any = None
|
|
158
134
|
|
|
159
135
|
|
|
160
|
-
def configure(dependencies:
|
|
136
|
+
def configure(dependencies: Any) -> None:
|
|
161
137
|
global _dependencies
|
|
162
138
|
_dependencies = dependencies
|
|
163
139
|
|
|
164
140
|
|
|
165
|
-
def dependencies() ->
|
|
141
|
+
def dependencies() -> Any:
|
|
166
142
|
if _dependencies is None:
|
|
167
143
|
raise RuntimeError("Deep Scan workbench dependencies are not configured.")
|
|
168
144
|
return _dependencies
|
|
169
145
|
|
|
170
146
|
|
|
171
|
-
def now() -> str:
|
|
172
|
-
return dependencies().now()
|
|
173
|
-
|
|
174
|
-
|
|
175
147
|
def _bounded_error_text(message: str, maximum: int) -> str:
|
|
176
148
|
if len(message) <= maximum:
|
|
177
149
|
return message
|
|
@@ -206,54 +178,6 @@ def _parse_timestamp(value: str) -> datetime:
|
|
|
206
178
|
return datetime.fromisoformat(value)
|
|
207
179
|
|
|
208
180
|
|
|
209
|
-
def state_dir() -> Path:
|
|
210
|
-
return dependencies().state_dir()
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
def require_scan(connection: sqlite3.Connection, scan_id: str) -> sqlite3.Row:
|
|
214
|
-
return dependencies().require_scan(connection, scan_id)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
def require_workspace(connection: sqlite3.Connection, workspace_id: str) -> sqlite3.Row:
|
|
218
|
-
return dependencies().require_workspace(connection, workspace_id)
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
def require_target(value: str) -> Path:
|
|
222
|
-
return dependencies().require_target(value)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
def require_remediation_target(value: str) -> Path:
|
|
226
|
-
return dependencies().require_remediation_target(value)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
def require_scannable_target(target: Path) -> None:
|
|
230
|
-
dependencies().require_scannable_target(target)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
def require_scope(scope: str, mode: str, target: Path) -> str:
|
|
234
|
-
return dependencies().require_scope(scope, mode, target)
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
def ensure_security_target(connection: sqlite3.Connection, target_path: str) -> str:
|
|
238
|
-
return dependencies().ensure_security_target(connection, target_path)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
def require_canonical_scan_directory(scan_dir: Path) -> Path:
|
|
242
|
-
return dependencies().require_canonical_scan_directory(scan_dir)
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
def safe_segment(value: str) -> str:
|
|
246
|
-
return dependencies().safe_segment(value)
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
def compact_timestamp() -> str:
|
|
250
|
-
return dependencies().compact_timestamp()
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
def scan_completion_lock(scan_id: str) -> Any:
|
|
254
|
-
return dependencies().scan_completion_lock(scan_id)
|
|
255
|
-
|
|
256
|
-
|
|
257
181
|
def require_deep_scan_run(connection: sqlite3.Connection, scan_id: str) -> sqlite3.Row:
|
|
258
182
|
scan_id = require_uuid(scan_id, "scan-id")
|
|
259
183
|
row = connection.execute(
|
|
@@ -265,7 +189,7 @@ def require_deep_scan_run(connection: sqlite3.Connection, scan_id: str) -> sqlit
|
|
|
265
189
|
|
|
266
190
|
|
|
267
191
|
def deep_scan_deadline_reached(run: sqlite3.Row) -> bool:
|
|
268
|
-
elapsed = _parse_timestamp(now()) - _parse_timestamp(str(run["created_at"]))
|
|
192
|
+
elapsed = _parse_timestamp(dependencies().now()) - _parse_timestamp(str(run["created_at"]))
|
|
269
193
|
return elapsed.total_seconds() / 3600 >= run["max_time_hours"]
|
|
270
194
|
|
|
271
195
|
|
|
@@ -275,7 +199,7 @@ def require_deep_scan_ready_for_parent_completion(
|
|
|
275
199
|
if scan["mode"] != "deep":
|
|
276
200
|
return
|
|
277
201
|
run = connection.execute(
|
|
278
|
-
"SELECT status, manifest_path FROM deep_scan_runs WHERE scan_id = ?",
|
|
202
|
+
"SELECT status, manifest_path, terminal_reason FROM deep_scan_runs WHERE scan_id = ?",
|
|
279
203
|
(scan["id"],),
|
|
280
204
|
).fetchone()
|
|
281
205
|
if run is None or run["status"] != "succeeded" or run["manifest_path"] is None:
|
|
@@ -283,13 +207,91 @@ def require_deep_scan_ready_for_parent_completion(
|
|
|
283
207
|
"Deep Scan discovery orchestration must finish and persist its manifest before "
|
|
284
208
|
"the parent scan can be completed."
|
|
285
209
|
)
|
|
210
|
+
if run["terminal_reason"] == "capped":
|
|
211
|
+
require_deep_scan_workers_finished(connection, scan["id"], "capped")
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def require_deep_scan_workers_finished(
|
|
215
|
+
connection: sqlite3.Connection,
|
|
216
|
+
scan_id: str,
|
|
217
|
+
terminal_reason: str,
|
|
218
|
+
*,
|
|
219
|
+
has_omitted_workers: bool = False,
|
|
220
|
+
) -> None:
|
|
221
|
+
"""Check execution state for coordinator completion and resumed parent publication."""
|
|
222
|
+
failed_worker = connection.execute(
|
|
223
|
+
"""
|
|
224
|
+
SELECT 1 FROM deep_scan_workers AS failed
|
|
225
|
+
WHERE failed.scan_id = ? AND failed.status = 'failed'
|
|
226
|
+
AND (? != 'saturated' OR failed.kind != 'discovery')
|
|
227
|
+
AND (
|
|
228
|
+
failed.kind != 'dedup'
|
|
229
|
+
OR NOT EXISTS (
|
|
230
|
+
SELECT 1 FROM deep_scan_dedup_inputs AS failed_inputs
|
|
231
|
+
WHERE failed_inputs.dedup_worker_id = failed.id
|
|
232
|
+
)
|
|
233
|
+
OR EXISTS (
|
|
234
|
+
SELECT 1 FROM deep_scan_dedup_inputs AS failed_inputs
|
|
235
|
+
WHERE failed_inputs.dedup_worker_id = failed.id
|
|
236
|
+
AND NOT EXISTS (
|
|
237
|
+
SELECT 1
|
|
238
|
+
FROM deep_scan_dedup_inputs AS replacement_inputs
|
|
239
|
+
JOIN deep_scan_workers AS replacement
|
|
240
|
+
ON replacement.scan_id = replacement_inputs.scan_id
|
|
241
|
+
AND replacement.id = replacement_inputs.dedup_worker_id
|
|
242
|
+
WHERE replacement_inputs.scan_id = failed.scan_id
|
|
243
|
+
AND replacement_inputs.discovery_worker_id =
|
|
244
|
+
failed_inputs.discovery_worker_id
|
|
245
|
+
AND replacement.kind = 'dedup'
|
|
246
|
+
AND replacement.status = 'succeeded'
|
|
247
|
+
)
|
|
248
|
+
)
|
|
249
|
+
)
|
|
250
|
+
LIMIT 1
|
|
251
|
+
""",
|
|
252
|
+
(scan_id, terminal_reason),
|
|
253
|
+
).fetchone()
|
|
254
|
+
if failed_worker is not None:
|
|
255
|
+
raise SystemExit("Deep Scan cannot finish after a worker has failed.")
|
|
256
|
+
active_worker = connection.execute(
|
|
257
|
+
"""
|
|
258
|
+
SELECT 1 FROM deep_scan_workers
|
|
259
|
+
WHERE scan_id = ? AND status IN ('queued', 'running')
|
|
260
|
+
LIMIT 1
|
|
261
|
+
""",
|
|
262
|
+
(scan_id,),
|
|
263
|
+
).fetchone()
|
|
264
|
+
if active_worker is not None:
|
|
265
|
+
raise SystemExit("Deep Scan cannot finish while workers are active.")
|
|
266
|
+
merging_worker = connection.execute(
|
|
267
|
+
"""
|
|
268
|
+
SELECT 1 FROM deep_scan_workers
|
|
269
|
+
WHERE scan_id = ? AND merge_state = 'merging'
|
|
270
|
+
LIMIT 1
|
|
271
|
+
""",
|
|
272
|
+
(scan_id,),
|
|
273
|
+
).fetchone()
|
|
274
|
+
if merging_worker is not None:
|
|
275
|
+
raise SystemExit("Deep Scan cannot finish while discovery output is merging.")
|
|
276
|
+
if terminal_reason == "capped" and has_omitted_workers:
|
|
277
|
+
raise SystemExit("Deep Scan capped completion cannot declare omitted buffered workers.")
|
|
278
|
+
if (
|
|
279
|
+
terminal_reason == "capped"
|
|
280
|
+
and connection.execute(
|
|
281
|
+
"SELECT 1 FROM deep_scan_workers WHERE scan_id = ? "
|
|
282
|
+
"AND kind = 'discovery' AND merge_state = 'buffered' LIMIT 1",
|
|
283
|
+
(scan_id,),
|
|
284
|
+
).fetchone()
|
|
285
|
+
is not None
|
|
286
|
+
):
|
|
287
|
+
raise SystemExit("Deep Scan cannot finish capped while discovery output remains buffered.")
|
|
286
288
|
|
|
287
289
|
|
|
288
290
|
def require_owned_scan(
|
|
289
291
|
connection: sqlite3.Connection, scan_id: str, thread_id: str
|
|
290
292
|
) -> tuple[sqlite3.Row, sqlite3.Row]:
|
|
291
|
-
scan = require_scan(connection, scan_id)
|
|
292
|
-
workspace = require_workspace(connection, scan["workspace_id"])
|
|
293
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
294
|
+
workspace = dependencies().require_workspace(connection, scan["workspace_id"])
|
|
293
295
|
owner = optional_text(thread_id, maximum=512)
|
|
294
296
|
if owner is None:
|
|
295
297
|
raise SystemExit("thread-id is required.")
|
|
@@ -311,7 +313,7 @@ def deep_scan_path(
|
|
|
311
313
|
raise SystemExit(f"{label} must be an absolute path inside the scan directory.")
|
|
312
314
|
try:
|
|
313
315
|
resolved = supplied.resolve(strict=True)
|
|
314
|
-
scan_dir = require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
316
|
+
scan_dir = dependencies().require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
315
317
|
resolved.relative_to(scan_dir)
|
|
316
318
|
except (OSError, RuntimeError, ValueError) as exc:
|
|
317
319
|
raise SystemExit(f"{label} must be an existing path inside the scan directory.") from exc
|
|
@@ -395,23 +397,18 @@ def publication_matches_snapshot(publication: Path, snapshot: Path) -> bool:
|
|
|
395
397
|
|
|
396
398
|
def canonical_discovery_artifacts(scan: sqlite3.Row) -> dict[str, str]:
|
|
397
399
|
discovery_dir = Path(scan["scan_dir"]) / "artifacts" / "02_discovery"
|
|
398
|
-
artifacts = {
|
|
399
|
-
"inScopeFilesPath": discovery_dir / "in_scope_files.txt",
|
|
400
|
-
"candidateLedgerPath": discovery_dir / "candidate_ledger.jsonl",
|
|
401
|
-
}
|
|
402
|
-
labels = {
|
|
403
|
-
"inScopeFilesPath": "Canonical in-scope inventory path",
|
|
404
|
-
"candidateLedgerPath": "Canonical candidate ledger path",
|
|
405
|
-
}
|
|
406
400
|
return {
|
|
407
|
-
name: deep_scan_path(scan, str(
|
|
408
|
-
for name,
|
|
401
|
+
name: deep_scan_path(scan, str(discovery_dir / filename), label, kind="file")
|
|
402
|
+
for name, filename, label in (
|
|
403
|
+
("inScopeFilesPath", "in_scope_files.txt", "Canonical in-scope inventory path"),
|
|
404
|
+
("candidateLedgerPath", "candidate_ledger.jsonl", "Canonical candidate ledger path"),
|
|
405
|
+
)
|
|
409
406
|
}
|
|
410
407
|
|
|
411
408
|
|
|
412
409
|
def deep_scan_state(connection: sqlite3.Connection, scan_id: str) -> dict[str, Any]:
|
|
413
410
|
run = require_deep_scan_run(connection, scan_id)
|
|
414
|
-
scan = require_scan(connection, run["scan_id"])
|
|
411
|
+
scan = dependencies().require_scan(connection, run["scan_id"])
|
|
415
412
|
worker_rows = connection.execute(
|
|
416
413
|
"""
|
|
417
414
|
SELECT *
|
|
@@ -453,7 +450,13 @@ def deep_scan_state(connection: sqlite3.Connection, scan_id: str) -> dict[str, A
|
|
|
453
450
|
"scanId": run["scan_id"],
|
|
454
451
|
"targetPath": scan["target_path"],
|
|
455
452
|
"scope": scan["scope"],
|
|
456
|
-
"
|
|
453
|
+
"includePaths": dependencies().requested_scan_paths(scan),
|
|
454
|
+
"filePaths": dependencies().requested_scan_file_paths(scan),
|
|
455
|
+
"userContext": (
|
|
456
|
+
json.loads(run["discovery_user_context_json"])
|
|
457
|
+
if run["discovery_user_context_json"] is not None
|
|
458
|
+
else scan["user_context"]
|
|
459
|
+
),
|
|
457
460
|
"scanDir": scan["scan_dir"],
|
|
458
461
|
"schemaVersion": run["schema_version"],
|
|
459
462
|
"workflowVersion": run["workflow_version"],
|
|
@@ -519,7 +522,7 @@ def independent_review_progress(
|
|
|
519
522
|
"active": int(active),
|
|
520
523
|
"completed": int(run["completion_sequence"]),
|
|
521
524
|
"maximum": int(run["max_discovery_runs"]),
|
|
522
|
-
"consolidating": run["phase"]
|
|
525
|
+
"consolidating": run["phase"] in {"reducing", "terminal"},
|
|
523
526
|
"updatedAt": str(run["updated_at"]),
|
|
524
527
|
}
|
|
525
528
|
|
|
@@ -582,9 +585,9 @@ def ensure_deep_scan_run(
|
|
|
582
585
|
INSERT INTO deep_scan_runs (
|
|
583
586
|
scan_id, schema_version, workflow_version, status, phase,
|
|
584
587
|
workers, subagents, stop_after_no_new, stop_after_consecutive_errors,
|
|
585
|
-
max_discovery_runs, max_time_hours,
|
|
588
|
+
max_discovery_runs, max_time_hours, discovery_user_context_json,
|
|
586
589
|
created_at, updated_at
|
|
587
|
-
) VALUES (?, 1, ?, 'running', 'setup', ?, ?, ?, ?, ?, ?, ?, ?)
|
|
590
|
+
) VALUES (?, 1, ?, 'running', 'setup', ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
588
591
|
""",
|
|
589
592
|
(
|
|
590
593
|
scan["id"],
|
|
@@ -595,6 +598,7 @@ def ensure_deep_scan_run(
|
|
|
595
598
|
config["stopAfterConsecutiveErrors"],
|
|
596
599
|
config["maxDiscoveryRuns"],
|
|
597
600
|
config["maxTimeHours"],
|
|
601
|
+
json.dumps(scan["user_context"]),
|
|
598
602
|
timestamp,
|
|
599
603
|
timestamp,
|
|
600
604
|
),
|
|
@@ -628,6 +632,7 @@ def terminal_deep_scan_for_target_snapshot(
|
|
|
628
632
|
thread_id: str,
|
|
629
633
|
target_path: str,
|
|
630
634
|
scope: str,
|
|
635
|
+
user_context: str | None,
|
|
631
636
|
revision: str,
|
|
632
637
|
snapshot_digest: str,
|
|
633
638
|
target_device: int | str,
|
|
@@ -637,7 +642,8 @@ def terminal_deep_scan_for_target_snapshot(
|
|
|
637
642
|
|
|
638
643
|
A continuation may safely consume a finished coordinator manifest while the
|
|
639
644
|
parent scan is still open. It must not adopt live orchestration owned by a
|
|
640
|
-
different thread, or reuse results
|
|
645
|
+
different thread, or reuse results for a different repository snapshot or
|
|
646
|
+
original discovery context.
|
|
641
647
|
"""
|
|
642
648
|
return connection.execute(
|
|
643
649
|
"""
|
|
@@ -647,6 +653,7 @@ def terminal_deep_scan_for_target_snapshot(
|
|
|
647
653
|
JOIN workspaces ON workspaces.id = scans.workspace_id
|
|
648
654
|
WHERE scans.target_path = ?
|
|
649
655
|
AND scans.scope = ?
|
|
656
|
+
AND deep_scan_runs.discovery_user_context_json = ?
|
|
650
657
|
AND scans.mode = 'deep'
|
|
651
658
|
AND scans.status = 'running'
|
|
652
659
|
AND scans.canceled_at IS NULL
|
|
@@ -670,6 +677,7 @@ def terminal_deep_scan_for_target_snapshot(
|
|
|
670
677
|
(
|
|
671
678
|
target_path,
|
|
672
679
|
scope,
|
|
680
|
+
json.dumps(user_context),
|
|
673
681
|
revision,
|
|
674
682
|
snapshot_digest,
|
|
675
683
|
target_device,
|
|
@@ -686,8 +694,8 @@ def begin_deep_scan_for_scan(
|
|
|
686
694
|
args: argparse.Namespace,
|
|
687
695
|
) -> dict[str, Any]:
|
|
688
696
|
scan_id = require_uuid(scan_id, "scan-id")
|
|
689
|
-
candidate = require_scan(connection, scan_id)
|
|
690
|
-
workspace = require_workspace(connection, candidate["workspace_id"])
|
|
697
|
+
candidate = dependencies().require_scan(connection, scan_id)
|
|
698
|
+
workspace = dependencies().require_workspace(connection, candidate["workspace_id"])
|
|
691
699
|
if (
|
|
692
700
|
candidate["mode"] == "deep"
|
|
693
701
|
and candidate["status"] == "running"
|
|
@@ -701,7 +709,7 @@ def begin_deep_scan_for_scan(
|
|
|
701
709
|
args.claim_token,
|
|
702
710
|
error_message="Deep Scan orchestration is owned by another continuation.",
|
|
703
711
|
)
|
|
704
|
-
timestamp = now()
|
|
712
|
+
timestamp = dependencies().now()
|
|
705
713
|
with connection:
|
|
706
714
|
claimed_workspace = connection.execute(
|
|
707
715
|
"UPDATE workspaces SET thread_id = ?, updated_at = ? "
|
|
@@ -746,45 +754,36 @@ def begin_deep_scan_for_scan(
|
|
|
746
754
|
if workflow_version is None:
|
|
747
755
|
raise SystemExit("workflow-version is required.")
|
|
748
756
|
connection.execute("BEGIN IMMEDIATE")
|
|
749
|
-
|
|
757
|
+
with connection:
|
|
750
758
|
scan, _ = require_owned_scan(connection, scan_id, thread_id)
|
|
751
759
|
require_current_continuation(
|
|
752
760
|
scan,
|
|
753
761
|
args.claim_token,
|
|
754
762
|
error_message="Deep Scan orchestration is owned by another continuation.",
|
|
755
763
|
)
|
|
756
|
-
ensure_deep_scan_run(connection, scan, config, workflow_version, now())
|
|
757
|
-
connection.commit()
|
|
758
|
-
except BaseException:
|
|
759
|
-
connection.rollback()
|
|
760
|
-
raise
|
|
764
|
+
ensure_deep_scan_run(connection, scan, config, workflow_version, dependencies().now())
|
|
761
765
|
return deep_scan_result(connection, scan_id, start_disposition="created")
|
|
762
766
|
|
|
763
767
|
|
|
764
768
|
def begin_deep_scan_for_target(
|
|
765
769
|
connection: sqlite3.Connection, args: argparse.Namespace, thread_id: str
|
|
766
770
|
) -> dict[str, Any]:
|
|
767
|
-
target = require_target(args.target_path)
|
|
768
|
-
require_scannable_target(target)
|
|
769
|
-
scope = require_scope(args.scope, "deep", target)
|
|
771
|
+
target = dependencies().require_target(args.target_path)
|
|
772
|
+
dependencies().require_scannable_target(target)
|
|
773
|
+
scope = dependencies().require_scope(args.scope, "deep", target)
|
|
770
774
|
target_path = str(target)
|
|
771
775
|
existing = existing_deep_scan_for_target(connection, thread_id, target_path, scope)
|
|
772
776
|
if existing is not None:
|
|
773
777
|
return begin_deep_scan_for_scan(connection, existing["id"], thread_id, args)
|
|
778
|
+
user_context = user_context_argument(args)
|
|
774
779
|
target_metadata = target.stat()
|
|
775
|
-
|
|
776
|
-
target_snapshot_digest =
|
|
777
|
-
directory_content_digest(target)
|
|
778
|
-
if revision == "unversioned"
|
|
779
|
-
else worktree_content_digest(target)
|
|
780
|
-
)
|
|
781
|
-
target_device = serialize_filesystem_identity(target_metadata.st_dev)
|
|
782
|
-
target_inode = serialize_filesystem_identity(target_metadata.st_ino)
|
|
780
|
+
target_identity = dependencies().scan_target_identity(target, None, metadata=target_metadata)
|
|
781
|
+
revision, target_snapshot_digest, target_device, target_inode = target_identity
|
|
783
782
|
scope_file_count = directory_snapshot_regular_file_count(
|
|
784
783
|
target if scope == "." else target / scope
|
|
785
784
|
)
|
|
786
785
|
connection.execute("BEGIN IMMEDIATE")
|
|
787
|
-
|
|
786
|
+
with connection:
|
|
788
787
|
existing = existing_deep_scan_for_target(connection, thread_id, target_path, scope)
|
|
789
788
|
if existing is not None:
|
|
790
789
|
existing_run = connection.execute(
|
|
@@ -795,14 +794,16 @@ def begin_deep_scan_for_target(
|
|
|
795
794
|
workflow_version = optional_text(args.workflow_version, maximum=256)
|
|
796
795
|
if workflow_version is None:
|
|
797
796
|
raise SystemExit("workflow-version is required.")
|
|
798
|
-
ensure_deep_scan_run(
|
|
797
|
+
ensure_deep_scan_run(
|
|
798
|
+
connection, existing, config, workflow_version, dependencies().now()
|
|
799
|
+
)
|
|
799
800
|
connection.commit()
|
|
800
801
|
return deep_scan_result(
|
|
801
802
|
connection,
|
|
802
803
|
existing["id"],
|
|
803
804
|
start_disposition="joined" if existing_run is not None else "created",
|
|
804
805
|
)
|
|
805
|
-
current_target = require_remediation_target(target_path)
|
|
806
|
+
current_target = dependencies().require_remediation_target(target_path)
|
|
806
807
|
current_metadata = current_target.stat()
|
|
807
808
|
if (current_metadata.st_dev, current_metadata.st_ino) != (
|
|
808
809
|
target_metadata.st_dev,
|
|
@@ -816,6 +817,7 @@ def begin_deep_scan_for_target(
|
|
|
816
817
|
thread_id,
|
|
817
818
|
target_path,
|
|
818
819
|
scope,
|
|
820
|
+
user_context,
|
|
819
821
|
revision,
|
|
820
822
|
target_snapshot_digest,
|
|
821
823
|
target_device,
|
|
@@ -832,26 +834,17 @@ def begin_deep_scan_for_target(
|
|
|
832
834
|
workflow_version = optional_text(args.workflow_version, maximum=256)
|
|
833
835
|
if workflow_version is None:
|
|
834
836
|
raise SystemExit("workflow-version is required.")
|
|
835
|
-
root = (
|
|
836
|
-
|
|
837
|
-
)
|
|
838
|
-
target_root = (root / safe_segment(target.name)).resolve()
|
|
837
|
+
root = dependencies().resolve_scan_root(args.scan_root)
|
|
838
|
+
target_root = (root / dependencies().safe_segment(target.name)).resolve()
|
|
839
839
|
if target_root == target or target in target_root.parents:
|
|
840
840
|
raise SystemExit("The scan artifact directory must be outside the selected target.")
|
|
841
|
-
target_root
|
|
842
|
-
user_context = user_context_argument(args)
|
|
841
|
+
create_private_directory(target_root)
|
|
843
842
|
model = optional_text(args.model, maximum=200)
|
|
844
843
|
reasoning_effort = optional_text(args.reasoning_effort, maximum=32)
|
|
845
844
|
workspace_id = str(uuid.uuid4())
|
|
846
845
|
scan_id = str(uuid.uuid4())
|
|
847
|
-
timestamp = now()
|
|
848
|
-
target_id = ensure_security_target(connection, target_path)
|
|
849
|
-
scan_dir = Path(
|
|
850
|
-
tempfile.mkdtemp(
|
|
851
|
-
prefix=f"{safe_segment(revision)}_{compact_timestamp()}_",
|
|
852
|
-
dir=target_root,
|
|
853
|
-
)
|
|
854
|
-
).resolve()
|
|
846
|
+
timestamp = dependencies().now()
|
|
847
|
+
target_id = dependencies().ensure_security_target(connection, target_path)
|
|
855
848
|
connection.execute(
|
|
856
849
|
"""
|
|
857
850
|
INSERT INTO workspaces (
|
|
@@ -871,55 +864,27 @@ def begin_deep_scan_for_target(
|
|
|
871
864
|
timestamp,
|
|
872
865
|
),
|
|
873
866
|
)
|
|
874
|
-
connection.execute(
|
|
875
|
-
""
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
target_inode,
|
|
893
|
-
scope,
|
|
894
|
-
user_context,
|
|
895
|
-
thread_id,
|
|
896
|
-
str(scan_dir),
|
|
897
|
-
model,
|
|
898
|
-
reasoning_effort,
|
|
899
|
-
timestamp,
|
|
900
|
-
timestamp,
|
|
901
|
-
timestamp,
|
|
902
|
-
),
|
|
903
|
-
)
|
|
904
|
-
connection.execute(
|
|
905
|
-
"""
|
|
906
|
-
INSERT INTO scan_progress (
|
|
907
|
-
scan_id, scope_file_count, review_items_total, review_items_completed,
|
|
908
|
-
reportable_findings_count, updated_at
|
|
909
|
-
) VALUES (?, ?, 0, 0, 0, ?)
|
|
910
|
-
""",
|
|
911
|
-
(scan_id, scope_file_count, timestamp),
|
|
912
|
-
)
|
|
913
|
-
connection.execute(
|
|
914
|
-
"UPDATE workspaces SET active_scan_id = ?, updated_at = ? WHERE id = ?",
|
|
915
|
-
(scan_id, timestamp, workspace_id),
|
|
867
|
+
workspace = connection.execute(
|
|
868
|
+
"SELECT * FROM workspaces WHERE id = ?", (workspace_id,)
|
|
869
|
+
).fetchone()
|
|
870
|
+
dependencies().insert_running_scan(
|
|
871
|
+
connection,
|
|
872
|
+
scan_id=scan_id,
|
|
873
|
+
workspace=workspace,
|
|
874
|
+
target=target,
|
|
875
|
+
scope=scope,
|
|
876
|
+
diff_target=None,
|
|
877
|
+
target_identity=target_identity,
|
|
878
|
+
target_root=target_root,
|
|
879
|
+
target_summary=None,
|
|
880
|
+
scope_file_count=scope_file_count,
|
|
881
|
+
timestamp=timestamp,
|
|
882
|
+
handoff_status="delivered",
|
|
883
|
+
model=model,
|
|
884
|
+
reasoning_effort=reasoning_effort,
|
|
916
885
|
)
|
|
917
|
-
scan = require_scan(connection, scan_id)
|
|
886
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
918
887
|
ensure_deep_scan_run(connection, scan, config, workflow_version, timestamp)
|
|
919
|
-
connection.commit()
|
|
920
|
-
except BaseException:
|
|
921
|
-
connection.rollback()
|
|
922
|
-
raise
|
|
923
888
|
return deep_scan_result(connection, scan_id, start_disposition="created")
|
|
924
889
|
|
|
925
890
|
|
|
@@ -973,6 +938,7 @@ def coordinator_lease_is_live(
|
|
|
973
938
|
if heartbeat["coordinatorGeneration"] == run["coordinator_generation"]:
|
|
974
939
|
heartbeat_time = max(heartbeat_time, _parse_timestamp(heartbeat["updatedAt"]))
|
|
975
940
|
except (OSError, KeyError, TypeError, ValueError):
|
|
941
|
+
# Missing or invalid heartbeat files leave the persisted lease timestamp in effect.
|
|
976
942
|
pass
|
|
977
943
|
current_time = _parse_timestamp(timestamp)
|
|
978
944
|
return heartbeat_time > current_time - timedelta(seconds=DEEP_SCAN_COORDINATOR_LEASE_SECONDS)
|
|
@@ -994,7 +960,7 @@ def claim_deep_scan_coordinator(
|
|
|
994
960
|
connection: sqlite3.Connection, args: argparse.Namespace
|
|
995
961
|
) -> dict[str, Any]:
|
|
996
962
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
997
|
-
with scan_completion_lock(scan_id):
|
|
963
|
+
with dependencies().scan_completion_lock(scan_id):
|
|
998
964
|
return claim_deep_scan_coordinator_locked(connection, args, scan_id)
|
|
999
965
|
|
|
1000
966
|
|
|
@@ -1002,7 +968,7 @@ def claim_deep_scan_coordinator_locked(
|
|
|
1002
968
|
connection: sqlite3.Connection, args: argparse.Namespace, scan_id: str
|
|
1003
969
|
) -> dict[str, Any]:
|
|
1004
970
|
connection.execute("BEGIN IMMEDIATE")
|
|
1005
|
-
|
|
971
|
+
with connection:
|
|
1006
972
|
scan, _ = require_owned_scan(connection, scan_id, args.thread_id)
|
|
1007
973
|
require_current_continuation(
|
|
1008
974
|
scan,
|
|
@@ -1010,7 +976,7 @@ def claim_deep_scan_coordinator_locked(
|
|
|
1010
976
|
error_message="Deep Scan orchestration is owned by another continuation.",
|
|
1011
977
|
)
|
|
1012
978
|
run, _ = require_running_deep_scan(connection, scan_id)
|
|
1013
|
-
timestamp = now()
|
|
979
|
+
timestamp = dependencies().now()
|
|
1014
980
|
if args.coordinator_generation is not None:
|
|
1015
981
|
require_current_coordinator(run, args)
|
|
1016
982
|
disposition = "claimed"
|
|
@@ -1034,10 +1000,6 @@ def claim_deep_scan_coordinator_locked(
|
|
|
1034
1000
|
""",
|
|
1035
1001
|
(int(args.coordinator_generation != run["coordinator_generation"]), timestamp, scan_id),
|
|
1036
1002
|
)
|
|
1037
|
-
connection.commit()
|
|
1038
|
-
except BaseException:
|
|
1039
|
-
connection.rollback()
|
|
1040
|
-
raise
|
|
1041
1003
|
return {
|
|
1042
1004
|
**deep_scan_result(connection, scan_id),
|
|
1043
1005
|
"coordinatorDisposition": disposition,
|
|
@@ -1122,7 +1084,7 @@ def recover_expired_coordinator(
|
|
|
1122
1084
|
|
|
1123
1085
|
|
|
1124
1086
|
def recover_candidate_ledger_publication(connection: sqlite3.Connection, scan_id: str) -> None:
|
|
1125
|
-
scan = require_scan(connection, scan_id)
|
|
1087
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
1126
1088
|
ledger = Path(scan["scan_dir"]) / "artifacts" / "02_discovery" / "candidate_ledger.jsonl"
|
|
1127
1089
|
backups = sorted(
|
|
1128
1090
|
ledger.parent.glob(f".{ledger.name}.*.backup"),
|
|
@@ -1173,7 +1135,7 @@ def require_running_deep_scan(
|
|
|
1173
1135
|
connection: sqlite3.Connection, scan_id: str
|
|
1174
1136
|
) -> tuple[sqlite3.Row, sqlite3.Row]:
|
|
1175
1137
|
run = require_deep_scan_run(connection, scan_id)
|
|
1176
|
-
scan = require_scan(connection, run["scan_id"])
|
|
1138
|
+
scan = dependencies().require_scan(connection, run["scan_id"])
|
|
1177
1139
|
if run["status"] != "running" or run["cancel_requested"]:
|
|
1178
1140
|
raise SystemExit("Only a running Deep Scan can update orchestration state.")
|
|
1179
1141
|
if scan["status"] != "running" or scan["canceled_at"] is not None:
|
|
@@ -1199,10 +1161,10 @@ def upsert_deep_scan_worker(
|
|
|
1199
1161
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
1200
1162
|
worker_id = require_uuid(args.worker_id, "worker-id")
|
|
1201
1163
|
connection.execute("BEGIN IMMEDIATE")
|
|
1202
|
-
|
|
1164
|
+
with connection:
|
|
1203
1165
|
run = require_deep_scan_run(connection, scan_id)
|
|
1204
1166
|
require_current_coordinator(run, args)
|
|
1205
|
-
scan = require_scan(connection, scan_id)
|
|
1167
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
1206
1168
|
existing = connection.execute(
|
|
1207
1169
|
"SELECT * FROM deep_scan_workers WHERE id = ?", (worker_id,)
|
|
1208
1170
|
).fetchone()
|
|
@@ -1245,7 +1207,7 @@ def upsert_deep_scan_worker(
|
|
|
1245
1207
|
if args.result_manifest_path
|
|
1246
1208
|
else None
|
|
1247
1209
|
)
|
|
1248
|
-
timestamp = now()
|
|
1210
|
+
timestamp = dependencies().now()
|
|
1249
1211
|
if existing is None:
|
|
1250
1212
|
if args.kind == "dedup":
|
|
1251
1213
|
raise SystemExit("Create dedup workers with claim-deep-scan-dedup.")
|
|
@@ -1420,10 +1382,6 @@ def upsert_deep_scan_worker(
|
|
|
1420
1382
|
worker_id,
|
|
1421
1383
|
),
|
|
1422
1384
|
)
|
|
1423
|
-
connection.commit()
|
|
1424
|
-
except BaseException:
|
|
1425
|
-
connection.rollback()
|
|
1426
|
-
raise
|
|
1427
1385
|
return deep_scan_result(connection, scan_id)
|
|
1428
1386
|
|
|
1429
1387
|
|
|
@@ -1436,7 +1394,7 @@ def claim_deep_scan_dedup(
|
|
|
1436
1394
|
if len(set(input_ids)) != len(input_ids):
|
|
1437
1395
|
raise SystemExit("Dedup input worker IDs must be unique.")
|
|
1438
1396
|
connection.execute("BEGIN IMMEDIATE")
|
|
1439
|
-
|
|
1397
|
+
with connection:
|
|
1440
1398
|
run, scan = require_running_deep_scan(connection, scan_id)
|
|
1441
1399
|
require_current_coordinator(run, args)
|
|
1442
1400
|
prompt_path = deep_scan_path(scan, args.prompt_path, "Dedup prompt path", kind="file")
|
|
@@ -1526,7 +1484,7 @@ def claim_deep_scan_dedup(
|
|
|
1526
1484
|
if minimum_inputs == 2
|
|
1527
1485
|
else "A Deep Scan dedup requires at least one buffered discovery result."
|
|
1528
1486
|
)
|
|
1529
|
-
timestamp = now()
|
|
1487
|
+
timestamp = dependencies().now()
|
|
1530
1488
|
connection.execute(
|
|
1531
1489
|
"""
|
|
1532
1490
|
INSERT INTO deep_scan_workers (
|
|
@@ -1565,10 +1523,6 @@ def claim_deep_scan_dedup(
|
|
|
1565
1523
|
""",
|
|
1566
1524
|
(timestamp, scan_id),
|
|
1567
1525
|
)
|
|
1568
|
-
connection.commit()
|
|
1569
|
-
except BaseException:
|
|
1570
|
-
connection.rollback()
|
|
1571
|
-
raise
|
|
1572
1526
|
return deep_scan_result(connection, scan_id)
|
|
1573
1527
|
|
|
1574
1528
|
|
|
@@ -1576,7 +1530,7 @@ def commit_deep_scan_dedup(
|
|
|
1576
1530
|
connection: sqlite3.Connection, args: argparse.Namespace
|
|
1577
1531
|
) -> dict[str, Any]:
|
|
1578
1532
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
1579
|
-
with scan_completion_lock(scan_id):
|
|
1533
|
+
with dependencies().scan_completion_lock(scan_id):
|
|
1580
1534
|
return commit_deep_scan_dedup_locked(connection, args, scan_id)
|
|
1581
1535
|
|
|
1582
1536
|
|
|
@@ -1590,7 +1544,7 @@ def commit_deep_scan_dedup_locked(
|
|
|
1590
1544
|
try:
|
|
1591
1545
|
run = require_deep_scan_run(connection, scan_id)
|
|
1592
1546
|
require_current_coordinator(run, args)
|
|
1593
|
-
scan = require_scan(connection, scan_id)
|
|
1547
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
1594
1548
|
worker = require_deep_scan_worker(connection, worker_id)
|
|
1595
1549
|
if worker["scan_id"] != scan_id or worker["kind"] != "dedup":
|
|
1596
1550
|
raise SystemExit("Dedup worker does not belong to this Deep Scan.")
|
|
@@ -1652,7 +1606,7 @@ def commit_deep_scan_dedup_locked(
|
|
|
1652
1606
|
str(publication_copy),
|
|
1653
1607
|
canonical_candidate_ledger_path,
|
|
1654
1608
|
)
|
|
1655
|
-
timestamp = now()
|
|
1609
|
+
timestamp = dependencies().now()
|
|
1656
1610
|
connection.execute(
|
|
1657
1611
|
"""
|
|
1658
1612
|
UPDATE deep_scan_workers
|
|
@@ -1702,7 +1656,7 @@ def commit_deep_scan_dedup_locked(
|
|
|
1702
1656
|
|
|
1703
1657
|
def finish_deep_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1704
1658
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
1705
|
-
with scan_completion_lock(scan_id):
|
|
1659
|
+
with dependencies().scan_completion_lock(scan_id):
|
|
1706
1660
|
return finish_deep_scan_locked(connection, args, scan_id)
|
|
1707
1661
|
|
|
1708
1662
|
|
|
@@ -1719,7 +1673,7 @@ def finish_deep_scan_locked(
|
|
|
1719
1673
|
try:
|
|
1720
1674
|
run = require_deep_scan_run(connection, scan_id)
|
|
1721
1675
|
require_current_coordinator(run, args)
|
|
1722
|
-
scan = require_scan(connection, scan_id)
|
|
1676
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
1723
1677
|
manifest_path = (
|
|
1724
1678
|
deep_scan_output_path(scan, args.manifest_path, "Deep Scan coordinator manifest path")
|
|
1725
1679
|
if args.staged_manifest_path
|
|
@@ -1729,63 +1683,6 @@ def finish_deep_scan_locked(
|
|
|
1729
1683
|
)
|
|
1730
1684
|
standard_scan_manifest = manifest_path == str(Path(scan["scan_dir"]) / "scan-manifest.json")
|
|
1731
1685
|
|
|
1732
|
-
failure_capped = False
|
|
1733
|
-
if (
|
|
1734
|
-
standard_scan_manifest
|
|
1735
|
-
and args.terminal_reason == "capped"
|
|
1736
|
-
and (run["status"] == "running" or omitted_worker_ids)
|
|
1737
|
-
):
|
|
1738
|
-
for artifact_name in ("scan-manifest.json", "findings.json", "coverage.json"):
|
|
1739
|
-
deep_scan_path(
|
|
1740
|
-
scan,
|
|
1741
|
-
str(Path(scan["scan_dir"]) / artifact_name),
|
|
1742
|
-
f"Canonical parent {artifact_name}",
|
|
1743
|
-
kind="file",
|
|
1744
|
-
)
|
|
1745
|
-
coverage = _read_scan_local_json(
|
|
1746
|
-
Path(scan["scan_dir"]), "coverage.json", "Canonical parent coverage.json"
|
|
1747
|
-
)
|
|
1748
|
-
deferred = coverage.get("deferred")
|
|
1749
|
-
failure_capped = (
|
|
1750
|
-
coverage.get("completeness") == "partial"
|
|
1751
|
-
and isinstance(deferred, list)
|
|
1752
|
-
and any(
|
|
1753
|
-
isinstance(item, dict)
|
|
1754
|
-
and isinstance(item.get("reason"), str)
|
|
1755
|
-
and item["reason"].startswith("Deep Scan stopped before completion: ")
|
|
1756
|
-
for item in deferred
|
|
1757
|
-
)
|
|
1758
|
-
and connection.execute(
|
|
1759
|
-
"""
|
|
1760
|
-
SELECT 1 FROM deep_scan_workers
|
|
1761
|
-
WHERE scan_id = ? AND kind = 'dedup' AND status = 'succeeded'
|
|
1762
|
-
LIMIT 1
|
|
1763
|
-
""",
|
|
1764
|
-
(scan_id,),
|
|
1765
|
-
).fetchone()
|
|
1766
|
-
is not None
|
|
1767
|
-
)
|
|
1768
|
-
if failure_capped and run["status"] == "running":
|
|
1769
|
-
require_running_deep_scan(connection, scan_id)
|
|
1770
|
-
connection.execute(
|
|
1771
|
-
"""
|
|
1772
|
-
UPDATE deep_scan_workers
|
|
1773
|
-
SET merge_state = 'buffered', updated_at = ?
|
|
1774
|
-
WHERE scan_id = ? AND kind = 'discovery' AND status = 'succeeded'
|
|
1775
|
-
AND merge_state = 'merging'
|
|
1776
|
-
AND id IN (
|
|
1777
|
-
SELECT inputs.discovery_worker_id
|
|
1778
|
-
FROM deep_scan_dedup_inputs AS inputs
|
|
1779
|
-
JOIN deep_scan_workers AS reducers
|
|
1780
|
-
ON reducers.id = inputs.dedup_worker_id
|
|
1781
|
-
AND reducers.scan_id = inputs.scan_id
|
|
1782
|
-
WHERE inputs.scan_id = ?
|
|
1783
|
-
AND reducers.kind = 'dedup'
|
|
1784
|
-
AND reducers.status IN ('failed', 'canceled')
|
|
1785
|
-
)
|
|
1786
|
-
""",
|
|
1787
|
-
(now(), scan_id, scan_id),
|
|
1788
|
-
)
|
|
1789
1686
|
buffered_worker_ids = [
|
|
1790
1687
|
row["id"]
|
|
1791
1688
|
for row in connection.execute(
|
|
@@ -1798,9 +1695,10 @@ def finish_deep_scan_locked(
|
|
|
1798
1695
|
(scan_id,),
|
|
1799
1696
|
)
|
|
1800
1697
|
]
|
|
1698
|
+
# Historical succeeded runs retain their exact omitted-worker replay contract.
|
|
1801
1699
|
omissions_match = (
|
|
1802
1700
|
set(omitted_worker_ids) == set(buffered_worker_ids)
|
|
1803
|
-
if args.terminal_reason == "saturated" or
|
|
1701
|
+
if args.terminal_reason == "saturated" or run["status"] == "succeeded"
|
|
1804
1702
|
else not omitted_worker_ids and not buffered_worker_ids
|
|
1805
1703
|
)
|
|
1806
1704
|
if run["status"] == "succeeded":
|
|
@@ -1816,7 +1714,7 @@ def finish_deep_scan_locked(
|
|
|
1816
1714
|
if run["manifest_path"] is None:
|
|
1817
1715
|
connection.execute(
|
|
1818
1716
|
"UPDATE deep_scan_runs SET manifest_path = ?, updated_at = ? WHERE scan_id = ?",
|
|
1819
|
-
(manifest_path, now(), scan_id),
|
|
1717
|
+
(manifest_path, dependencies().now(), scan_id),
|
|
1820
1718
|
)
|
|
1821
1719
|
connection.commit()
|
|
1822
1720
|
return deep_scan_result(connection, scan_id)
|
|
@@ -1832,7 +1730,6 @@ def finish_deep_scan_locked(
|
|
|
1832
1730
|
args.terminal_reason == "capped"
|
|
1833
1731
|
and run["discovery_runs_dispatched"] < run["max_discovery_runs"]
|
|
1834
1732
|
and not deep_scan_deadline_reached(run)
|
|
1835
|
-
and not failure_capped
|
|
1836
1733
|
):
|
|
1837
1734
|
raise SystemExit(
|
|
1838
1735
|
"Deep Scan cannot finish capped before reaching its configured maximum."
|
|
@@ -1873,71 +1770,16 @@ def finish_deep_scan_locked(
|
|
|
1873
1770
|
)
|
|
1874
1771
|
if successful_reducer is None and not zero_discovery_deadline:
|
|
1875
1772
|
raise SystemExit("Deep Scan cannot finish without a successful dedup worker.")
|
|
1876
|
-
failed_worker = connection.execute(
|
|
1877
|
-
"""
|
|
1878
|
-
SELECT 1 FROM deep_scan_workers AS failed
|
|
1879
|
-
WHERE failed.scan_id = ? AND failed.status = 'failed'
|
|
1880
|
-
AND (? != 'saturated' OR failed.kind != 'discovery')
|
|
1881
|
-
AND (
|
|
1882
|
-
failed.kind != 'dedup'
|
|
1883
|
-
OR NOT EXISTS (
|
|
1884
|
-
SELECT 1 FROM deep_scan_dedup_inputs AS failed_inputs
|
|
1885
|
-
WHERE failed_inputs.dedup_worker_id = failed.id
|
|
1886
|
-
)
|
|
1887
|
-
OR EXISTS (
|
|
1888
|
-
SELECT 1 FROM deep_scan_dedup_inputs AS failed_inputs
|
|
1889
|
-
WHERE failed_inputs.dedup_worker_id = failed.id
|
|
1890
|
-
AND NOT EXISTS (
|
|
1891
|
-
SELECT 1
|
|
1892
|
-
FROM deep_scan_dedup_inputs AS replacement_inputs
|
|
1893
|
-
JOIN deep_scan_workers AS replacement
|
|
1894
|
-
ON replacement.scan_id = replacement_inputs.scan_id
|
|
1895
|
-
AND replacement.id = replacement_inputs.dedup_worker_id
|
|
1896
|
-
WHERE replacement_inputs.scan_id = failed.scan_id
|
|
1897
|
-
AND replacement_inputs.discovery_worker_id =
|
|
1898
|
-
failed_inputs.discovery_worker_id
|
|
1899
|
-
AND replacement.kind = 'dedup'
|
|
1900
|
-
AND replacement.status = 'succeeded'
|
|
1901
|
-
)
|
|
1902
|
-
)
|
|
1903
|
-
)
|
|
1904
|
-
LIMIT 1
|
|
1905
|
-
""",
|
|
1906
|
-
(scan_id, args.terminal_reason),
|
|
1907
|
-
).fetchone()
|
|
1908
|
-
if failed_worker is not None and not failure_capped:
|
|
1909
|
-
raise SystemExit("Deep Scan cannot finish after a worker has failed.")
|
|
1910
1773
|
if args.terminal_reason == "saturated":
|
|
1911
|
-
#
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
(scan_id,),
|
|
1921
|
-
).fetchone()
|
|
1922
|
-
if active_worker is not None:
|
|
1923
|
-
raise SystemExit("Deep Scan cannot finish while workers are active.")
|
|
1924
|
-
merging_worker = connection.execute(
|
|
1925
|
-
"""
|
|
1926
|
-
SELECT 1 FROM deep_scan_workers
|
|
1927
|
-
WHERE scan_id = ? AND merge_state = 'merging'
|
|
1928
|
-
LIMIT 1
|
|
1929
|
-
""",
|
|
1930
|
-
(scan_id,),
|
|
1931
|
-
).fetchone()
|
|
1932
|
-
if merging_worker is not None:
|
|
1933
|
-
raise SystemExit("Deep Scan cannot finish while discovery output is merging.")
|
|
1934
|
-
if args.terminal_reason == "capped" and omitted_worker_ids and not failure_capped:
|
|
1935
|
-
raise SystemExit("Deep Scan capped completion cannot declare omitted buffered workers.")
|
|
1936
|
-
if args.terminal_reason == "capped" and buffered_worker_ids and not failure_capped:
|
|
1937
|
-
raise SystemExit(
|
|
1938
|
-
"Deep Scan cannot finish capped while discovery output remains buffered."
|
|
1939
|
-
)
|
|
1940
|
-
if (args.terminal_reason == "saturated" or failure_capped) and not omissions_match:
|
|
1774
|
+
# Saturation cancels surplus workers, including failed cancellation writes.
|
|
1775
|
+
cancel_active_workers(connection, scan_id, dependencies().now())
|
|
1776
|
+
require_deep_scan_workers_finished(
|
|
1777
|
+
connection,
|
|
1778
|
+
scan_id,
|
|
1779
|
+
args.terminal_reason,
|
|
1780
|
+
has_omitted_workers=bool(omitted_worker_ids),
|
|
1781
|
+
)
|
|
1782
|
+
if args.terminal_reason == "saturated" and not omissions_match:
|
|
1941
1783
|
raise SystemExit(
|
|
1942
1784
|
f"Deep Scan {args.terminal_reason} completion must exactly identify all buffered discovery "
|
|
1943
1785
|
"workers with --omitted-worker-id."
|
|
@@ -1950,18 +1792,23 @@ def finish_deep_scan_locked(
|
|
|
1950
1792
|
kind="file",
|
|
1951
1793
|
)
|
|
1952
1794
|
promotion = promote_staged_file(staged_manifest_path, manifest_path)
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1795
|
+
with (
|
|
1796
|
+
saved_results.preserve_deep_deadline_draft(dependencies(), connection, scan)
|
|
1797
|
+
if zero_discovery_deadline and standard_scan_manifest
|
|
1798
|
+
else nullcontext()
|
|
1799
|
+
):
|
|
1800
|
+
timestamp = dependencies().now()
|
|
1801
|
+
connection.execute(
|
|
1802
|
+
"""
|
|
1803
|
+
UPDATE deep_scan_runs
|
|
1804
|
+
SET status = 'succeeded', phase = 'terminal', terminal_reason = ?,
|
|
1805
|
+
manifest_path = ?, completed_at = ?, updated_at = ?
|
|
1806
|
+
WHERE scan_id = ?
|
|
1807
|
+
""",
|
|
1808
|
+
(args.terminal_reason, manifest_path, timestamp, timestamp, scan_id),
|
|
1809
|
+
)
|
|
1810
|
+
cancel_active_workers(connection, scan_id, timestamp)
|
|
1811
|
+
connection.commit()
|
|
1965
1812
|
except BaseException:
|
|
1966
1813
|
connection.rollback()
|
|
1967
1814
|
if promotion is not None:
|
|
@@ -1974,7 +1821,7 @@ def finish_deep_scan_locked(
|
|
|
1974
1821
|
|
|
1975
1822
|
def fail_deep_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1976
1823
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
1977
|
-
with scan_completion_lock(scan_id):
|
|
1824
|
+
with dependencies().scan_completion_lock(scan_id):
|
|
1978
1825
|
return fail_deep_scan_locked(connection, args, scan_id)
|
|
1979
1826
|
|
|
1980
1827
|
|
|
@@ -1989,7 +1836,7 @@ def fail_deep_scan_locked(
|
|
|
1989
1836
|
try:
|
|
1990
1837
|
run = require_deep_scan_run(connection, scan_id)
|
|
1991
1838
|
require_current_coordinator(run, args)
|
|
1992
|
-
scan = require_scan(connection, scan_id)
|
|
1839
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
1993
1840
|
manifest_path = None
|
|
1994
1841
|
if args.manifest_path:
|
|
1995
1842
|
manifest_path = (
|
|
@@ -2002,6 +1849,8 @@ def fail_deep_scan_locked(
|
|
|
2002
1849
|
kind="file",
|
|
2003
1850
|
)
|
|
2004
1851
|
)
|
|
1852
|
+
elif run["manifest_path"] == str(Path(scan["scan_dir"]) / "scan-manifest.json"):
|
|
1853
|
+
manifest_path = run["manifest_path"]
|
|
2005
1854
|
if run["status"] in {"failed", "interrupted"} or scan["status"] == "failed":
|
|
2006
1855
|
if (
|
|
2007
1856
|
run["status"] == args.deep_status
|
|
@@ -2036,7 +1885,7 @@ def fail_deep_scan_locked(
|
|
|
2036
1885
|
kind="file",
|
|
2037
1886
|
)
|
|
2038
1887
|
promotion = promote_staged_file(staged_manifest_path, manifest_path)
|
|
2039
|
-
timestamp = now()
|
|
1888
|
+
timestamp = dependencies().now()
|
|
2040
1889
|
connection.execute(
|
|
2041
1890
|
"""
|
|
2042
1891
|
UPDATE deep_scan_runs
|
|
@@ -2080,12 +1929,12 @@ def record_deep_scan_publication_failure(
|
|
|
2080
1929
|
message = optional_text(args.message, maximum=2400)
|
|
2081
1930
|
if message is None:
|
|
2082
1931
|
raise SystemExit("message is required.")
|
|
2083
|
-
with scan_completion_lock(scan_id):
|
|
1932
|
+
with dependencies().scan_completion_lock(scan_id):
|
|
2084
1933
|
connection.execute("BEGIN IMMEDIATE")
|
|
2085
|
-
|
|
1934
|
+
with connection:
|
|
2086
1935
|
run = require_deep_scan_run(connection, scan_id)
|
|
2087
1936
|
require_current_coordinator(run, args)
|
|
2088
|
-
scan = require_scan(connection, scan_id)
|
|
1937
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
2089
1938
|
if (
|
|
2090
1939
|
run["status"] not in {"failed", "canceled", "interrupted"}
|
|
2091
1940
|
or scan["status"] != "failed"
|
|
@@ -2097,7 +1946,7 @@ def record_deep_scan_publication_failure(
|
|
|
2097
1946
|
connection.commit()
|
|
2098
1947
|
return deep_scan_result(connection, scan_id)
|
|
2099
1948
|
if run["publication_error_message"] != message:
|
|
2100
|
-
timestamp = now()
|
|
1949
|
+
timestamp = dependencies().now()
|
|
2101
1950
|
connection.execute(
|
|
2102
1951
|
"""
|
|
2103
1952
|
UPDATE deep_scan_runs
|
|
@@ -2106,10 +1955,6 @@ def record_deep_scan_publication_failure(
|
|
|
2106
1955
|
""",
|
|
2107
1956
|
(message, timestamp, scan_id),
|
|
2108
1957
|
)
|
|
2109
|
-
connection.commit()
|
|
2110
|
-
except BaseException:
|
|
2111
|
-
connection.rollback()
|
|
2112
|
-
raise
|
|
2113
1958
|
return deep_scan_result(connection, scan_id)
|
|
2114
1959
|
|
|
2115
1960
|
|
|
@@ -2118,7 +1963,7 @@ def clear_deep_scan_publication_failure(connection: sqlite3.Connection, scan_id:
|
|
|
2118
1963
|
connection.execute(
|
|
2119
1964
|
"UPDATE deep_scan_runs SET publication_error_message = NULL, updated_at = ? "
|
|
2120
1965
|
"WHERE scan_id = ? AND publication_error_message IS NOT NULL",
|
|
2121
|
-
(now(), scan_id),
|
|
1966
|
+
(dependencies().now(), scan_id),
|
|
2122
1967
|
)
|
|
2123
1968
|
|
|
2124
1969
|
|