@openai/codex-security 0.8.3 → 0.10.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 +36 -746
- package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
- package/_bundled_plugin/.mcp.json +7 -1
- package/_bundled_plugin/examples/completed-scan/findings.json +16 -4
- package/_bundled_plugin/examples/completed-scan/report.md +11 -8
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +4 -2
- package/_bundled_plugin/mcp/fzstd-LICENSE.txt +21 -0
- package/_bundled_plugin/mcp/helpers.mjs +2 -11
- package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +3 -210
- 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/package.json +1 -0
- package/_bundled_plugin/mcp/permission-profile-preflight.mjs +5 -2
- package/_bundled_plugin/mcp/server.mjs +2 -11
- package/_bundled_plugin/mcp/server.mjs.br +0 -0
- package/_bundled_plugin/mcp/session-decompression.mjs +712 -0
- package/_bundled_plugin/references/artifact-storage.md +1 -1
- package/_bundled_plugin/references/baseline-auditor.md +18 -0
- package/_bundled_plugin/references/core-scan.md +5 -42
- package/_bundled_plugin/references/default-severity-rubric.md +9 -4
- package/_bundled_plugin/references/final-report.md +5 -3
- package/_bundled_plugin/references/finding-detail-fields.md +18 -18
- package/_bundled_plugin/references/focused-investigator.md +13 -0
- package/_bundled_plugin/references/sarif-adapter.md +8 -2
- package/_bundled_plugin/references/scan-artifacts.md +21 -12
- package/_bundled_plugin/references/scan-contract.md +27 -33
- package/_bundled_plugin/references/scan-prologue.md +2 -2
- package/_bundled_plugin/references/scan-runtime.md +4 -2
- package/_bundled_plugin/references/security-guidance.md +14 -1
- package/_bundled_plugin/references/validate-scan-findings.md +3 -0
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +2 -2
- package/_bundled_plugin/scripts/check_deep_scan_target.py +97 -0
- package/_bundled_plugin/scripts/codex_profile.mjs +7 -1
- package/_bundled_plugin/scripts/deep_scan_config.py +20 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +192 -352
- package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +182 -230
- package/_bundled_plugin/scripts/finding_preview.py +20 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp +55 -16
- package/_bundled_plugin/scripts/legacy_findings.py +148 -0
- package/_bundled_plugin/scripts/posix_scan_local_files.py +37 -1
- package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
- package/_bundled_plugin/scripts/report_projection.py +81 -43
- package/_bundled_plugin/scripts/review_state.py +8 -2
- package/_bundled_plugin/scripts/servicenow_avit.py +20 -0
- package/_bundled_plugin/scripts/snapshot_sqlite.py +9 -2
- package/_bundled_plugin/scripts/threat_model_projection.py +22 -26
- package/_bundled_plugin/scripts/validate_scan_contract.py +7 -1
- package/_bundled_plugin/scripts/windows_scan_local_files.py +582 -20
- package/_bundled_plugin/scripts/workbench/__init__.py +1 -1
- package/_bundled_plugin/scripts/workbench/handoff.py +100 -23
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +30 -51
- package/_bundled_plugin/scripts/workbench/retained_records.py +18 -30
- package/_bundled_plugin/scripts/workbench/runtime_toml.py +4 -1
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +9 -17
- package/_bundled_plugin/scripts/workbench/saved_outputs.py +9 -0
- package/_bundled_plugin/scripts/workbench/saved_sources.py +47 -40
- package/_bundled_plugin/scripts/workbench/storage.py +91 -7
- package/_bundled_plugin/scripts/workbench_cli.py +54 -14
- package/_bundled_plugin/scripts/workbench_constants.py +12 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
- package/_bundled_plugin/scripts/workbench_db.py +562 -303
- package/_bundled_plugin/scripts/workbench_feedback.py +57 -11
- package/_bundled_plugin/scripts/workbench_finding_index.py +1 -0
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +4 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +238 -41
- package/_bundled_plugin/scripts/workbench_progress.py +169 -4
- package/_bundled_plugin/scripts/workbench_publication.py +16 -13
- package/_bundled_plugin/scripts/workbench_remediation.py +155 -2
- package/_bundled_plugin/scripts/workbench_saved_results.py +176 -81
- package/_bundled_plugin/scripts/workbench_scan_history.py +398 -174
- package/_bundled_plugin/scripts/workbench_scan_start.py +224 -31
- package/_bundled_plugin/scripts/workbench_scan_usage.py +675 -73
- package/_bundled_plugin/scripts/workbench_schema.py +258 -63
- package/_bundled_plugin/scripts/workbench_setup.py +14 -2
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +18 -0
- package/_bundled_plugin/scripts/workbench_target.py +594 -136
- package/_bundled_plugin/scripts/workbench_target_state.py +1110 -21
- package/_bundled_plugin/scripts/workbench_validation.py +43 -3
- package/_bundled_plugin/shared/workbench-history-repairs.json +77 -35
- package/_bundled_plugin/shared/workbench-migrations.json +100 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +5 -5
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
- package/_bundled_plugin/skills/fix-finding/SKILL.md +2 -1
- package/_bundled_plugin/skills/publish-findings/SKILL.md +24 -153
- package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
- package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +3 -3
- package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +409 -0
- package/_bundled_plugin/skills/publish-findings/scripts/collect_continuum.py +224 -0
- package/_bundled_plugin/skills/publish-findings/scripts/collector_paths.py +63 -0
- package/_bundled_plugin/skills/security-scan/SKILL.md +9 -46
- package/_bundled_plugin/skills/security-scan/agents/openai.yaml +2 -2
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -21
- package/_bundled_plugin/skills/security-scan/references/managed-scan.md +11 -0
- package/_bundled_plugin/skills/security-scan/references/scan-results.md +15 -0
- package/_bundled_plugin/skills/security-scan/references/scoped-paths.md +23 -0
- package/_bundled_plugin/skills/security-scan/references/sdk-files.md +24 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +22 -1
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -2
- package/bin/codex-security.mjs +2 -2
- package/dist/api.d.ts +45 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1192 -427
- package/dist/api.js.map +1 -1
- package/dist/armorcode-findings.d.ts +9 -0
- package/dist/armorcode-findings.d.ts.map +1 -0
- package/dist/armorcode-findings.js +145 -0
- package/dist/armorcode-findings.js.map +1 -0
- package/dist/artifact-export.d.ts +2 -0
- package/dist/artifact-export.d.ts.map +1 -1
- package/dist/artifact-export.js +29 -13
- package/dist/artifact-export.js.map +1 -1
- package/dist/auth.d.ts +6 -2
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +37 -18
- package/dist/auth.js.map +1 -1
- package/dist/batch-cost.d.ts +18 -0
- package/dist/batch-cost.d.ts.map +1 -0
- package/dist/batch-cost.js +41 -0
- package/dist/batch-cost.js.map +1 -0
- package/dist/bedrock-oss-pricing.d.ts +6 -0
- package/dist/bedrock-oss-pricing.d.ts.map +1 -0
- package/dist/bedrock-oss-pricing.js +58 -0
- package/dist/bedrock-oss-pricing.js.map +1 -0
- package/dist/bedrock-pricing.d.ts +15 -0
- package/dist/bedrock-pricing.d.ts.map +1 -0
- package/dist/bedrock-pricing.js +117 -0
- package/dist/bedrock-pricing.js.map +1 -0
- package/dist/blackduck-findings.d.ts +1 -1
- package/dist/blackduck-findings.d.ts.map +1 -1
- package/dist/blackduck-findings.js +24 -22
- package/dist/blackduck-findings.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +4 -4
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/bundled-plugin.d.ts +4 -0
- package/dist/bundled-plugin.d.ts.map +1 -0
- package/dist/bundled-plugin.js +23 -0
- package/dist/bundled-plugin.js.map +1 -0
- package/dist/checkmarx-evidence.d.ts +19 -0
- package/dist/checkmarx-evidence.d.ts.map +1 -0
- package/dist/checkmarx-evidence.js +36 -0
- package/dist/checkmarx-evidence.js.map +1 -0
- package/dist/checkmarx-findings.d.ts +4 -0
- package/dist/checkmarx-findings.d.ts.map +1 -0
- package/dist/checkmarx-findings.js +27 -0
- package/dist/checkmarx-findings.js.map +1 -0
- package/dist/checkmarx-one.d.ts +4 -0
- package/dist/checkmarx-one.d.ts.map +1 -0
- package/dist/checkmarx-one.js +53 -0
- package/dist/checkmarx-one.js.map +1 -0
- package/dist/checkmarx-repository.d.ts +12 -0
- package/dist/checkmarx-repository.d.ts.map +1 -0
- package/dist/checkmarx-repository.js +181 -0
- package/dist/checkmarx-repository.js.map +1 -0
- package/dist/checkmarx-xml.d.ts +12 -0
- package/dist/checkmarx-xml.d.ts.map +1 -0
- package/dist/checkmarx-xml.js +196 -0
- package/dist/checkmarx-xml.js.map +1 -0
- package/dist/classify-scan-severity.d.ts +1 -1
- package/dist/classify-scan-severity.d.ts.map +1 -1
- package/dist/classify-scan-severity.js +11 -3
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity-records.d.ts +1 -9
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +3 -13
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +11 -10
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-argument.d.ts +4 -0
- package/dist/cli-argument.d.ts.map +1 -0
- package/dist/cli-argument.js +17 -0
- package/dist/cli-argument.js.map +1 -0
- package/dist/cli-help.d.ts +1 -1
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +71 -29
- package/dist/cli-help.js.map +1 -1
- package/dist/cli-hook.d.ts +3 -0
- package/dist/cli-hook.d.ts.map +1 -0
- package/dist/cli-hook.js +87 -0
- package/dist/cli-hook.js.map +1 -0
- package/dist/cli-integrations.d.ts +13 -0
- package/dist/cli-integrations.d.ts.map +1 -0
- package/dist/cli-integrations.js +333 -0
- package/dist/cli-integrations.js.map +1 -0
- package/dist/cli-mcp.d.ts +15 -0
- package/dist/cli-mcp.d.ts.map +1 -0
- package/dist/cli-mcp.js +178 -0
- package/dist/cli-mcp.js.map +1 -0
- package/dist/cli-token-view.d.ts +10 -0
- package/dist/cli-token-view.d.ts.map +1 -0
- package/dist/cli-token-view.js +41 -0
- package/dist/cli-token-view.js.map +1 -0
- package/dist/cli.d.ts +16 -8
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3382 -2017
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +35 -33
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-sdk-environment.d.ts +6 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -1
- package/dist/codex-sdk-environment.js +19 -0
- package/dist/codex-sdk-environment.js.map +1 -1
- package/dist/command-words.d.ts +3 -0
- package/dist/command-words.d.ts.map +1 -0
- package/dist/command-words.js +46 -0
- package/dist/command-words.js.map +1 -0
- package/dist/component-scan.d.ts +19 -4
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +67 -9
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +130 -67
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts +1 -1
- package/dist/continuum-findings.d.ts.map +1 -1
- package/dist/continuum-findings.js +149 -19
- package/dist/continuum-findings.js.map +1 -1
- package/dist/contract-values.d.ts +2 -0
- package/dist/contract-values.d.ts.map +1 -1
- package/dist/contract-values.js +12 -9
- package/dist/contract-values.js.map +1 -1
- package/dist/cost-model.d.ts +13 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +66 -112
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +42 -3
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +484 -149
- package/dist/cost.js.map +1 -1
- package/dist/custom-publish.d.ts +4 -0
- package/dist/custom-publish.d.ts.map +1 -1
- package/dist/custom-publish.js +40 -3
- package/dist/custom-publish.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +29 -19
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/local.d.ts +4 -2
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +9 -2
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/refusal.d.ts.map +1 -1
- package/dist/deduplication/refusal.js +26 -5
- package/dist/deduplication/refusal.js.map +1 -1
- package/dist/deduplication/scan.d.ts +5 -0
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +24 -7
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +0 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +22 -33
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-scan-defaults.d.ts +2 -0
- package/dist/deep-scan-defaults.d.ts.map +1 -1
- package/dist/deep-scan-defaults.js +28 -1
- package/dist/deep-scan-defaults.js.map +1 -1
- package/dist/deep-scan.d.ts +2 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +44 -19
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -1
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +1 -1
- package/dist/default-severity-rubric.js.map +1 -1
- package/dist/endor-findings.d.ts +3 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +86 -45
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.d.ts +4 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +15 -4
- package/dist/errors.js.map +1 -1
- package/dist/executable-path.d.ts +3 -0
- package/dist/executable-path.d.ts.map +1 -1
- package/dist/executable-path.js +26 -0
- package/dist/executable-path.js.map +1 -1
- package/dist/external-findings-import.d.ts +5 -3
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +19 -7
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +69 -5
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +537 -108
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +13 -6
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +895 -1142
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +21 -2
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +130 -68
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +15 -3
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +54 -2
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +8 -12
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +51 -184
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/feedback.d.ts.map +1 -1
- package/dist/feedback.js +5 -4
- package/dist/feedback.js.map +1 -1
- package/dist/finding-prompt.d.ts +5 -0
- package/dist/finding-prompt.d.ts.map +1 -0
- package/dist/finding-prompt.js +32 -0
- package/dist/finding-prompt.js.map +1 -0
- package/dist/findings-client.d.ts +1 -0
- package/dist/findings-client.d.ts.map +1 -1
- package/dist/findings-client.js +27 -3
- package/dist/findings-client.js.map +1 -1
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +0 -2
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +18 -8
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts +4 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +73 -316
- package/dist/github-findings.js.map +1 -1
- package/dist/hosted-git-remotes.d.ts +5 -0
- package/dist/hosted-git-remotes.d.ts.map +1 -0
- package/dist/hosted-git-remotes.js +285 -0
- package/dist/hosted-git-remotes.js.map +1 -0
- package/dist/hosted-git-repository.d.ts +28 -0
- package/dist/hosted-git-repository.d.ts.map +1 -0
- package/dist/hosted-git-repository.js +222 -0
- package/dist/hosted-git-repository.js.map +1 -0
- package/dist/hosted-remediation.d.ts +1 -0
- package/dist/hosted-remediation.d.ts.map +1 -1
- package/dist/hosted-remediation.js +23 -3
- package/dist/hosted-remediation.js.map +1 -1
- package/dist/hosted-scan-protocol.js +2 -2
- package/dist/hosted-scan-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +16 -11
- package/dist/hosted-scan.js.map +1 -1
- package/dist/hosted-scanner-http.d.ts +21 -0
- package/dist/hosted-scanner-http.d.ts.map +1 -0
- package/dist/hosted-scanner-http.js +204 -0
- package/dist/hosted-scanner-http.js.map +1 -0
- package/dist/import-scan.d.ts.map +1 -1
- package/dist/import-scan.js +3 -0
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +21 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +52 -86
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.d.ts +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +102 -32
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts +11 -0
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js.map +1 -1
- package/dist/local-git-metadata.d.ts +5 -2
- package/dist/local-git-metadata.d.ts.map +1 -1
- package/dist/local-git-metadata.js +8 -5
- package/dist/local-git-metadata.js.map +1 -1
- package/dist/multiscan.d.ts +10 -4
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +217 -102
- package/dist/multiscan.js.map +1 -1
- package/dist/native-json-findings.d.ts +2 -1
- package/dist/native-json-findings.d.ts.map +1 -1
- package/dist/native-json-findings.js +12 -2
- package/dist/native-json-findings.js.map +1 -1
- package/dist/opengrep-findings.d.ts +5 -2
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +54 -33
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/operation-telemetry.d.ts +104 -0
- package/dist/operation-telemetry.d.ts.map +1 -0
- package/dist/operation-telemetry.js +293 -0
- package/dist/operation-telemetry.js.map +1 -0
- package/dist/plugin-python-probe.d.ts +4 -0
- package/dist/plugin-python-probe.d.ts.map +1 -0
- package/dist/plugin-python-probe.js +10 -0
- package/dist/plugin-python-probe.js.map +1 -0
- package/dist/private-finding-import.d.ts +99 -9
- package/dist/private-finding-import.d.ts.map +1 -1
- package/dist/private-finding-import.js +116 -152
- package/dist/private-finding-import.js.map +1 -1
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +53 -13
- package/dist/project-config.js.map +1 -1
- package/dist/prompt-files.d.ts +7 -2
- package/dist/prompt-files.d.ts.map +1 -1
- package/dist/prompt-files.js +42 -20
- package/dist/prompt-files.js.map +1 -1
- package/dist/provider-profile.d.ts +1 -1
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +12 -10
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication-telemetry.d.ts +45 -0
- package/dist/publication-telemetry.d.ts.map +1 -0
- package/dist/publication-telemetry.js +50 -0
- package/dist/publication-telemetry.js.map +1 -0
- package/dist/publication.d.ts +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts +4 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +42 -2
- package/dist/publish.js.map +1 -1
- package/dist/record.d.ts +1 -5
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +3 -51
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts +1 -4
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +6 -8
- package/dist/remediation.js.map +1 -1
- package/dist/request-metadata.d.ts +3 -0
- package/dist/request-metadata.d.ts.map +1 -1
- package/dist/request-metadata.js +9 -0
- package/dist/request-metadata.js.map +1 -1
- package/dist/result.d.ts +4 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +1 -1
- package/dist/result.js.map +1 -1
- package/dist/retry-windows-rename.d.ts +8 -0
- package/dist/retry-windows-rename.d.ts.map +1 -0
- package/dist/retry-windows-rename.js +24 -0
- package/dist/retry-windows-rename.js.map +1 -0
- package/dist/runtime.d.ts +54 -6
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1084 -256
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +7 -1
- package/dist/saved-scan-bootstrap.d.ts.map +1 -1
- package/dist/saved-scan-bootstrap.js +269 -114
- package/dist/saved-scan-bootstrap.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +141 -56
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-archive-path.d.ts +2 -0
- package/dist/scan-archive-path.d.ts.map +1 -0
- package/dist/scan-archive-path.js +5 -0
- package/dist/scan-archive-path.js.map +1 -0
- package/dist/scan-comparison.d.ts +10 -5
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +66 -17
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +7 -6
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +92 -43
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +10 -1
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js +24 -2
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts +1 -0
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +34 -28
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts +12 -0
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +131 -78
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-measurement.d.ts +26 -0
- package/dist/scan-measurement.d.ts.map +1 -0
- package/dist/scan-measurement.js +77 -0
- package/dist/scan-measurement.js.map +1 -0
- package/dist/scan-progress.d.ts +1 -0
- package/dist/scan-progress.d.ts.map +1 -1
- package/dist/scan-progress.js +3 -0
- package/dist/scan-progress.js.map +1 -1
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +4 -1
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +1 -1
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +1 -24
- package/dist/scan-settings.js.map +1 -1
- package/dist/scanner-import.d.ts +25 -13
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +216 -97
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +4 -1
- package/dist/scanner-repository-url.d.ts.map +1 -1
- package/dist/scanner-repository-url.js +10 -6
- package/dist/scanner-repository-url.js.map +1 -1
- package/dist/security-policy.d.ts +1 -1
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +26 -6
- package/dist/security-policy.js.map +1 -1
- package/dist/semgrep-findings.d.ts +6 -3
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +72 -42
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-guardian-findings.d.ts +38 -0
- package/dist/semgrep-guardian-findings.d.ts.map +1 -0
- package/dist/semgrep-guardian-findings.js +165 -0
- package/dist/semgrep-guardian-findings.js.map +1 -0
- package/dist/semgrep-platform-collector.d.ts +26 -0
- package/dist/semgrep-platform-collector.d.ts.map +1 -0
- package/dist/semgrep-platform-collector.js +108 -0
- package/dist/semgrep-platform-collector.js.map +1 -0
- package/dist/semgrep-platform-findings.d.ts +157 -6
- package/dist/semgrep-platform-findings.d.ts.map +1 -1
- package/dist/semgrep-platform-findings.js +766 -103
- package/dist/semgrep-platform-findings.js.map +1 -1
- package/dist/server/api.d.ts +1 -1
- package/dist/server/api.d.ts.map +1 -1
- package/dist/server/api.js.map +1 -1
- package/dist/server/embedding-tokenizer.cdx.json +33 -0
- package/dist/server/embedding-tokenizer.d.ts +2 -0
- package/dist/server/embedding-tokenizer.d.ts.map +1 -0
- package/dist/server/embedding-tokenizer.js +322 -0
- package/dist/server/embedding-tokenizer.js.map +6 -0
- package/dist/server/embeddings.d.ts +16 -2
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +35 -5
- package/dist/server/embeddings.js.map +1 -1
- package/dist/session-lines.d.ts +5 -0
- package/dist/session-lines.d.ts.map +1 -0
- package/dist/session-lines.js +60 -0
- package/dist/session-lines.js.map +1 -0
- package/dist/severity-review.d.ts +3 -1
- package/dist/severity-review.d.ts.map +1 -1
- package/dist/severity-review.js +3 -2
- package/dist/severity-review.js.map +1 -1
- package/dist/skill-authentication.d.ts +1 -0
- package/dist/skill-authentication.d.ts.map +1 -1
- package/dist/skill-authentication.js +1 -0
- package/dist/skill-authentication.js.map +1 -1
- package/dist/snyk-findings.d.ts +9 -2
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +90 -70
- package/dist/snyk-findings.js.map +1 -1
- package/dist/snyk-rest-findings.d.ts +59 -0
- package/dist/snyk-rest-findings.d.ts.map +1 -0
- package/dist/snyk-rest-findings.js +879 -0
- package/dist/snyk-rest-findings.js.map +1 -0
- package/dist/snyk-token-origin.d.ts +4 -0
- package/dist/snyk-token-origin.d.ts.map +1 -0
- package/dist/snyk-token-origin.js +82 -0
- package/dist/snyk-token-origin.js.map +1 -0
- package/dist/sonar-collector.d.ts.map +1 -1
- package/dist/sonar-collector.js +0 -3
- package/dist/sonar-collector.js.map +1 -1
- package/dist/sonar-findings.d.ts +1 -1
- package/dist/sonar-findings.d.ts.map +1 -1
- package/dist/sonar-findings.js +2 -4
- package/dist/sonar-findings.js.map +1 -1
- package/dist/sonar-import.d.ts +3 -0
- package/dist/sonar-import.d.ts.map +1 -1
- package/dist/sonar-import.js +30 -34
- package/dist/sonar-import.js.map +1 -1
- package/dist/stored-finding-projection.d.ts +6 -0
- package/dist/stored-finding-projection.d.ts.map +1 -0
- package/dist/stored-finding-projection.js +104 -0
- package/dist/stored-finding-projection.js.map +1 -0
- package/dist/stored-findings-publication.d.ts +23 -0
- package/dist/stored-findings-publication.d.ts.map +1 -0
- package/dist/stored-findings-publication.js +169 -0
- package/dist/stored-findings-publication.js.map +1 -0
- package/dist/target-drift.d.ts +9 -0
- package/dist/target-drift.d.ts.map +1 -0
- package/dist/target-drift.js +27 -0
- package/dist/target-drift.js.map +1 -0
- package/dist/targets.d.ts +8 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +131 -42
- package/dist/targets.js.map +1 -1
- package/dist/tenable-findings.d.ts +6 -0
- package/dist/tenable-findings.d.ts.map +1 -0
- package/dist/tenable-findings.js +122 -0
- package/dist/tenable-findings.js.map +1 -0
- package/dist/terminal-stream.d.ts +13 -0
- package/dist/terminal-stream.d.ts.map +1 -0
- package/dist/terminal-stream.js +35 -0
- package/dist/terminal-stream.js.map +1 -0
- package/dist/trivy-findings.d.ts +19 -0
- package/dist/trivy-findings.d.ts.map +1 -0
- package/dist/trivy-findings.js +424 -0
- package/dist/trivy-findings.js.map +1 -0
- package/dist/trivy-import.d.ts +19 -0
- package/dist/trivy-import.d.ts.map +1 -0
- package/dist/trivy-import.js +151 -0
- package/dist/trivy-import.js.map +1 -0
- package/dist/trusted-executable.d.ts +6 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +140 -37
- package/dist/trusted-executable.js.map +1 -1
- package/dist/validation-records.js +1 -1
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +1 -1
- package/dist/veracode-findings.d.ts.map +1 -1
- package/dist/veracode-findings.js +19 -6
- package/dist/veracode-findings.js.map +1 -1
- package/dist/version.d.ts +3 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +184 -32
- package/dist/version.js.map +1 -1
- package/dist/vertex-pricing.d.ts +8 -0
- package/dist/vertex-pricing.d.ts.map +1 -0
- package/dist/vertex-pricing.js +20 -0
- package/dist/vertex-pricing.js.map +1 -0
- package/dist/windows-path.d.ts +1 -0
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +26 -1
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-findings.d.ts +6 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +65 -89
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +27 -12
- package/docs/cli.md +853 -639
- package/docs/dedupe-records.md +44 -24
- package/docs/findings-service.md +84 -44
- package/docs/hosted-remediation.md +27 -11
- package/docs/hosted-scans.md +50 -42
- package/docs/sdk.md +903 -0
- package/docs/telemetry.md +236 -0
- package/docs/validate-records.md +78 -44
- package/package.json +23 -16
- package/schemas/external-findings.schema.json +4 -1
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +0 -96
- package/dist/external-imports-feature.d.ts +0 -6
- package/dist/external-imports-feature.d.ts.map +0 -1
- package/dist/external-imports-feature.js +0 -51
- package/dist/external-imports-feature.js.map +0 -1
- package/dist/finding-normalization.d.ts +0 -5
- package/dist/finding-normalization.d.ts.map +0 -1
- package/dist/finding-normalization.js +0 -155
- package/dist/finding-normalization.js.map +0 -1
- package/dist/reader-selection.d.ts +0 -13
- package/dist/reader-selection.d.ts.map +0 -1
- package/dist/reader-selection.js +0 -81
- package/dist/reader-selection.js.map +0 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { isIPv4 } from "node:net";
|
|
2
|
+
import { cloudRepositoryUrlKey, repositoryUrlKey, } from "./external-import-contract.js";
|
|
3
|
+
import { isGitHubCloudHost } from "./git-remote.js";
|
|
4
|
+
// Git treats a colon followed by "//" as the start of a URL transport.
|
|
5
|
+
const scpRemote = /^(?:([^@/:\s?#]+)@)?(\[[^\]]+\]|[^@/:\s?#]+):(?!\/\/)(.+)$/u;
|
|
6
|
+
const sshRemote = /^(?:ssh|git\+ssh|ssh\+git):\/\/([^/]+?)(?:\/|%2[fF])/u;
|
|
7
|
+
/** A native file URL or an unambiguous local path. */
|
|
8
|
+
export function isLocalGitRemote(remote) {
|
|
9
|
+
if (remote.includes("://"))
|
|
10
|
+
return remote.startsWith("file://");
|
|
11
|
+
const colon = remote.indexOf(":");
|
|
12
|
+
return colon < 0 || remote.slice(0, colon).includes("/");
|
|
13
|
+
}
|
|
14
|
+
export function isWindowsGitDrive(remote) {
|
|
15
|
+
// Git for Windows accepts one character or up to four consecutive non-ASCII bytes before a drive colon.
|
|
16
|
+
return (process.platform === "win32" &&
|
|
17
|
+
!remote.includes("://") &&
|
|
18
|
+
/^(?:.|[\u0080-\u07ff]{2}):(?!:)/su.test(remote));
|
|
19
|
+
}
|
|
20
|
+
function parseScpRemote(remote) {
|
|
21
|
+
return !isLocalGitRemote(remote) &&
|
|
22
|
+
!remote.includes("://") &&
|
|
23
|
+
!/^[a-z\d][a-z\d+.-]*::/iu.test(remote)
|
|
24
|
+
? scpRemote.exec(remote)
|
|
25
|
+
: null;
|
|
26
|
+
}
|
|
27
|
+
function sshAuthority(host) {
|
|
28
|
+
if (/[\/\\?#@\s\x00-\x1f\x7f]/u.test(host))
|
|
29
|
+
return null;
|
|
30
|
+
// Git passes a leading plus on decimal ports through to OpenSSH.
|
|
31
|
+
const parse = (authority) => URL.parse("ssh://" + authority.replace(/:\+(\d+)$/u, ":$1"));
|
|
32
|
+
const parsed = parse(host);
|
|
33
|
+
if (parsed)
|
|
34
|
+
return parsed;
|
|
35
|
+
// Git accepts brackets around DNS names, with an SSH port inside or after the brackets.
|
|
36
|
+
const bracketed = /^\[([^\]]+)\](?::(\+?\d*))?$/u.exec(host);
|
|
37
|
+
// An empty port outside the brackets is ignored, but an inner trailing colon is a hostname byte.
|
|
38
|
+
if (!bracketed || bracketed[1].endsWith(":"))
|
|
39
|
+
return null;
|
|
40
|
+
const [, name, port] = bracketed;
|
|
41
|
+
return parse(name + (port ? `:${port}` : ""));
|
|
42
|
+
}
|
|
43
|
+
/** Git decodes URI escapes once except for NUL, and sends SCP bytes literally. */
|
|
44
|
+
export function gitTransportBytes(raw, scpStyle) {
|
|
45
|
+
const bytes = Buffer.from(raw).toString("latin1");
|
|
46
|
+
return scpStyle
|
|
47
|
+
? bytes
|
|
48
|
+
: bytes.replace(/%(?!00)([\da-f]{2})/giu, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
49
|
+
}
|
|
50
|
+
/** Decode only URI escapes whose ASCII bytes cannot introduce a delimiter. */
|
|
51
|
+
export function decodeUnreserved(value) {
|
|
52
|
+
return value.replace(/%([0-9a-f]{2})/giu, (escape, hex) => {
|
|
53
|
+
const byte = String.fromCharCode(parseInt(hex, 16));
|
|
54
|
+
return /^[a-z0-9._~-]$/iu.test(byte) ? byte : escape.toUpperCase();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** Represent upload-pack path bytes relative to an HTTP repository origin. */
|
|
58
|
+
export function gitPathToHttpPath(bytes) {
|
|
59
|
+
return bytes
|
|
60
|
+
.replace(/^\//u, "")
|
|
61
|
+
.replace(/[%\x00-\x20\x7f-\xff]/gu, (byte) => "%" + byte.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0"));
|
|
62
|
+
}
|
|
63
|
+
/** Ignore the optional DNS root dot for provider classification only. */
|
|
64
|
+
export function gitServiceHostname(hostname) {
|
|
65
|
+
return hostname.replace(/\.$/u, "");
|
|
66
|
+
}
|
|
67
|
+
export function isPublicGitHost(host) {
|
|
68
|
+
return (isGitHubCloudHost(host) || host === "gitlab.com" || host === "bitbucket.org");
|
|
69
|
+
}
|
|
70
|
+
/** Public SSH-over-443 hosts share the HTTPS hostname after the first DNS label. */
|
|
71
|
+
function publicGitSsh443Host(hostname) {
|
|
72
|
+
switch (gitServiceHostname(hostname)) {
|
|
73
|
+
case "ssh.github.com":
|
|
74
|
+
case "altssh.gitlab.com":
|
|
75
|
+
case "altssh.bitbucket.org":
|
|
76
|
+
return hostname.slice(hostname.indexOf(".") + 1);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function matchesHttpsHost(url, hostname) {
|
|
80
|
+
const source = url && URL.parse(url);
|
|
81
|
+
return (!!source &&
|
|
82
|
+
source.protocol === "https:" &&
|
|
83
|
+
source.hostname.toLowerCase() === hostname);
|
|
84
|
+
}
|
|
85
|
+
/** Standard public SSH aliases, plus a hosted SCM established by the caller. */
|
|
86
|
+
export function normalizeHostedGitRepositoryUrl(remote, source, trustedScm) {
|
|
87
|
+
// A projected single-project report may retain only its SSH spelling.
|
|
88
|
+
return normalizeGitSshAlias(remote, (host) => (trustedScm || isPublicGitHost(gitServiceHostname(host))) &&
|
|
89
|
+
matchesHttpsHost(source ?? `https://${host}`, host));
|
|
90
|
+
}
|
|
91
|
+
function normalizeGitSshAlias(repository, isAliasHost) {
|
|
92
|
+
const isGitSshUser = (username, hostname) => (username === "git" && hostname === "github.com") ||
|
|
93
|
+
(isAliasHost(hostname) &&
|
|
94
|
+
(username === "git" ||
|
|
95
|
+
username ===
|
|
96
|
+
/^([^.]+)\.ghe\.com$/u.exec(gitServiceHostname(hostname))?.[1]));
|
|
97
|
+
const hostedAlias = (url, user, path, scpStyle) => {
|
|
98
|
+
const hostname = url.hostname.toLowerCase();
|
|
99
|
+
const standard = isGitSshUser(user, hostname) && (url.port === "" || url.port === "22");
|
|
100
|
+
const alternate = user === "git" && url.port === "443" && publicGitSsh443Host(hostname);
|
|
101
|
+
if (!standard && !alternate)
|
|
102
|
+
return repository;
|
|
103
|
+
const bytes = gitTransportBytes(path, scpStyle);
|
|
104
|
+
if (/[?#\\]/u.test(bytes) || /(?:^|\/)\.{1,2}(?:\/|$)/u.test(bytes))
|
|
105
|
+
return repository;
|
|
106
|
+
return `https://${alternate || hostname}/${gitPathToHttpPath(bytes)}`;
|
|
107
|
+
};
|
|
108
|
+
const scp = parseScpRemote(repository);
|
|
109
|
+
if (scp) {
|
|
110
|
+
if (!scp[1])
|
|
111
|
+
return repository;
|
|
112
|
+
const authority = sshAuthority(scp[2]);
|
|
113
|
+
return authority
|
|
114
|
+
? hostedAlias(authority, scp[1], scp[3], true)
|
|
115
|
+
: repository;
|
|
116
|
+
}
|
|
117
|
+
// Git separates the decoded authority from the path at the first slash.
|
|
118
|
+
const ssh = sshRemote.exec(repository);
|
|
119
|
+
if (ssh && !/[\t\r\n]/u.test(repository)) {
|
|
120
|
+
const authority = gitTransportBytes(ssh[1], false);
|
|
121
|
+
const login = /^([^@:]+)@([^@]+)$/u.exec(authority);
|
|
122
|
+
if (!login || /[/\\%?#\s]/u.test(authority))
|
|
123
|
+
return repository;
|
|
124
|
+
const url = sshAuthority(login[2]);
|
|
125
|
+
if (url)
|
|
126
|
+
return hostedAlias(url, login[1], "/" + repository.slice(ssh[0].length), false);
|
|
127
|
+
}
|
|
128
|
+
return repository;
|
|
129
|
+
}
|
|
130
|
+
function hostedHttpAuthority(authority) {
|
|
131
|
+
if (/[%@\\\s]/u.test(authority))
|
|
132
|
+
return authority;
|
|
133
|
+
const hostname = URL.parse(`https://${authority}/`)?.hostname;
|
|
134
|
+
// Hostname serialization handles IP literals and IDNA. The connector distinguishes explicit ports.
|
|
135
|
+
const port = /:\d*$/u.exec(authority)?.[0] ?? "";
|
|
136
|
+
return hostname ? hostname + port : authority;
|
|
137
|
+
}
|
|
138
|
+
function hostedHttpPath(path) {
|
|
139
|
+
const segments = [];
|
|
140
|
+
for (const segment of path.split("/")) {
|
|
141
|
+
// Git's HTTP transport resolves literal dot segments before sending the path.
|
|
142
|
+
if (segment === "..") {
|
|
143
|
+
segments.pop();
|
|
144
|
+
}
|
|
145
|
+
else if (segment !== ".") {
|
|
146
|
+
const spelling = segment.replace(/\P{ASCII}+/gu, (text) => encodeURIComponent(text.toWellFormed()));
|
|
147
|
+
const decoded = decodeUnreserved(spelling);
|
|
148
|
+
segments.push(decoded === "." || decoded === ".." ? segment.toUpperCase() : decoded);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (/(?:^|\/)\.{1,2}$/u.test(path))
|
|
152
|
+
segments.push("");
|
|
153
|
+
return segments.join("/");
|
|
154
|
+
}
|
|
155
|
+
/** Compare the HTTP request path a browser and Git would send for the same link. */
|
|
156
|
+
export function ambiguousHostedHttpPath(value) {
|
|
157
|
+
const path = /^https?:\/\/[^/?#]+\/([^?#]*)/iu.exec(value)?.[1];
|
|
158
|
+
if (path === undefined)
|
|
159
|
+
return false;
|
|
160
|
+
const web = URL.parse(value)?.pathname.slice(1);
|
|
161
|
+
return (web !== undefined &&
|
|
162
|
+
path !== web &&
|
|
163
|
+
hostedHttpPath(path) !== hostedHttpPath(web));
|
|
164
|
+
}
|
|
165
|
+
/** Compare hosted HTTP repository spellings without changing the retained evidence. */
|
|
166
|
+
export function hostedRepositoryUrlKey(value, github = false, knownGitSuffix = false, target = "local") {
|
|
167
|
+
const url = value.replace(/^(https?:\/\/)([^/?#]+)\/([^?#]*)/iu, (_, scheme, authority, path) => scheme +
|
|
168
|
+
(target === "cloud" && ambiguousGitIpHost(value)
|
|
169
|
+
? authority.toLowerCase()
|
|
170
|
+
: hostedHttpAuthority(authority)) +
|
|
171
|
+
"/" +
|
|
172
|
+
hostedHttpPath(path));
|
|
173
|
+
if (github)
|
|
174
|
+
return cloudRepositoryUrlKey(url);
|
|
175
|
+
const host = URL.parse(url)?.hostname ?? "";
|
|
176
|
+
const service = /^https?:\/\//iu.test(url) ? gitServiceHostname(host) : host;
|
|
177
|
+
if (service !== host && isGitHubCloudHost(service))
|
|
178
|
+
return cloudRepositoryUrlKey(url);
|
|
179
|
+
// An arbitrary Git server can serve different repositories at /repo and /repo.git.
|
|
180
|
+
const key = repositoryUrlKey(url);
|
|
181
|
+
return !knownGitSuffix && !isPublicGitHost(service) && /\.git\/?$/u.test(url)
|
|
182
|
+
? key + ".git"
|
|
183
|
+
: key;
|
|
184
|
+
}
|
|
185
|
+
/** The Git HTTP Host and TLS server name can differ from the web URL's parsed IP literal. */
|
|
186
|
+
export function ambiguousGitIpHost(url) {
|
|
187
|
+
const host = URL.parse(url)?.hostname;
|
|
188
|
+
if (!host || (!isIPv4(host) && !host.startsWith("[")))
|
|
189
|
+
return false;
|
|
190
|
+
const authority = /^https?:\/\/([^/?#]*)/iu.exec(url)?.[1] ?? "";
|
|
191
|
+
const rawHost = authority
|
|
192
|
+
.slice(authority.lastIndexOf("@") + 1)
|
|
193
|
+
.replace(/:\d*$/u, "");
|
|
194
|
+
return rawHost.toLowerCase() !== host;
|
|
195
|
+
}
|
|
196
|
+
/** Match a Git checkout to an independently selected hosted repository. */
|
|
197
|
+
export function hostedRepositoryMatches(source, remote) {
|
|
198
|
+
if (!/^https?:\/\//iu.test(source.url))
|
|
199
|
+
return remote === source.url;
|
|
200
|
+
const github = source.platform === "github";
|
|
201
|
+
const url = normalizeHostedGitRepositoryUrl(remote, source.url, github || source.platform === "gitlab");
|
|
202
|
+
const userinfo = /^https?:\/\/([^/?#]*)@/iu.exec(url)?.[1] ?? "";
|
|
203
|
+
// Git passes raw URL paths to its HTTP transport. Do not turn backslashes,
|
|
204
|
+
// controls or an encoded traversal into a match via web URL serialization.
|
|
205
|
+
if (!/^https?:\/\//iu.test(url) ||
|
|
206
|
+
/[\\\x00-\x20\x7f?#]/u.test(url) ||
|
|
207
|
+
// libcurl accepts encoded userinfo but rejects multiple literal authority delimiters.
|
|
208
|
+
userinfo.includes("@") ||
|
|
209
|
+
// Git rejects a decoded line feed in credentials and libcurl rejects a NUL in usernames.
|
|
210
|
+
/%0a/iu.test(userinfo) ||
|
|
211
|
+
/^[^:]*%00/u.test(userinfo) ||
|
|
212
|
+
ambiguousGitIpHost(url) ||
|
|
213
|
+
ambiguousHostedHttpPath(url))
|
|
214
|
+
return false;
|
|
215
|
+
// The local checkout's credentials and default HTTP port don't change the server path.
|
|
216
|
+
const key = (value) => hostedRepositoryUrlKey(value.replace(/^(https?:\/\/)([^/?#\\]+)\//iu, (match, scheme, authority) => {
|
|
217
|
+
const parsed = URL.parse(scheme + authority);
|
|
218
|
+
return parsed ? scheme + parsed.host + "/" : match;
|
|
219
|
+
}), github, source.gitlab || source.platform === "gitlab");
|
|
220
|
+
return key(url) === key(source.url);
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=hosted-git-repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosted-git-repository.js","sourceRoot":"","sources":["../src/hosted-git-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MA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D,CAAC,CACF,EACD,MAAM,EACN,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAC9C,CAAC;IACJ,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { isIPv4 } from \"node:net\";\nimport {\n type ExternalImportTarget,\n cloudRepositoryUrlKey,\n repositoryUrlKey,\n} from \"./external-import-contract.js\";\nimport { isGitHubCloudHost } from \"./git-remote.js\";\n\n// Git treats a colon followed by \"//\" as the start of a URL transport.\nconst scpRemote = /^(?:([^@/:\\s?#]+)@)?(\\[[^\\]]+\\]|[^@/:\\s?#]+):(?!\\/\\/)(.+)$/u;\n\nconst sshRemote = /^(?:ssh|git\\+ssh|ssh\\+git):\\/\\/([^/]+?)(?:\\/|%2[fF])/u;\n\n/** A native file URL or an unambiguous local path. */\nexport function isLocalGitRemote(remote: string): boolean {\n if (remote.includes(\"://\")) return remote.startsWith(\"file://\");\n const colon = remote.indexOf(\":\");\n return colon < 0 || remote.slice(0, colon).includes(\"/\");\n}\n\nexport function isWindowsGitDrive(remote: string): boolean {\n // Git for Windows accepts one character or up to four consecutive non-ASCII bytes before a drive colon.\n return (\n process.platform === \"win32\" &&\n !remote.includes(\"://\") &&\n /^(?:.|[\\u0080-\\u07ff]{2}):(?!:)/su.test(remote)\n );\n}\n\nfunction parseScpRemote(remote: string): RegExpExecArray | null {\n return !isLocalGitRemote(remote) &&\n !remote.includes(\"://\") &&\n !/^[a-z\\d][a-z\\d+.-]*::/iu.test(remote)\n ? scpRemote.exec(remote)\n : null;\n}\n\nfunction sshAuthority(host: string): URL | null {\n if (/[\\/\\\\?#@\\s\\x00-\\x1f\\x7f]/u.test(host)) return null;\n // Git passes a leading plus on decimal ports through to OpenSSH.\n const parse = (authority: string) =>\n URL.parse(\"ssh://\" + authority.replace(/:\\+(\\d+)$/u, \":$1\"));\n const parsed = parse(host);\n if (parsed) return parsed;\n // Git accepts brackets around DNS names, with an SSH port inside or after the brackets.\n const bracketed = /^\\[([^\\]]+)\\](?::(\\+?\\d*))?$/u.exec(host);\n // An empty port outside the brackets is ignored, but an inner trailing colon is a hostname byte.\n if (!bracketed || bracketed[1]!.endsWith(\":\")) return null;\n const [, name, port] = bracketed;\n return parse(name + (port ? `:${port}` : \"\"));\n}\n\n/** Git decodes URI escapes once except for NUL, and sends SCP bytes literally. */\nexport function gitTransportBytes(raw: string, scpStyle: boolean): string {\n const bytes = Buffer.from(raw).toString(\"latin1\");\n return scpStyle\n ? bytes\n : bytes.replace(/%(?!00)([\\da-f]{2})/giu, (_, hex: string) =>\n String.fromCharCode(parseInt(hex, 16)),\n );\n}\n\n/** Decode only URI escapes whose ASCII bytes cannot introduce a delimiter. */\nexport function decodeUnreserved(value: string): string {\n return value.replace(/%([0-9a-f]{2})/giu, (escape, hex: string) => {\n const byte = String.fromCharCode(parseInt(hex, 16));\n return /^[a-z0-9._~-]$/iu.test(byte) ? byte : escape.toUpperCase();\n });\n}\n\n/** Represent upload-pack path bytes relative to an HTTP repository origin. */\nexport function gitPathToHttpPath(bytes: string): string {\n return bytes\n .replace(/^\\//u, \"\")\n .replace(\n /[%\\x00-\\x20\\x7f-\\xff]/gu,\n (byte) =>\n \"%\" + byte.charCodeAt(0).toString(16).toUpperCase().padStart(2, \"0\"),\n );\n}\n\n/** Ignore the optional DNS root dot for provider classification only. */\nexport function gitServiceHostname(hostname: string): string {\n return hostname.replace(/\\.$/u, \"\");\n}\n\nexport function isPublicGitHost(host: string): boolean {\n return (\n isGitHubCloudHost(host) || host === \"gitlab.com\" || host === \"bitbucket.org\"\n );\n}\n\n/** Public SSH-over-443 hosts share the HTTPS hostname after the first DNS label. */\nfunction publicGitSsh443Host(hostname: string): string | undefined {\n switch (gitServiceHostname(hostname)) {\n case \"ssh.github.com\":\n case \"altssh.gitlab.com\":\n case \"altssh.bitbucket.org\":\n return hostname.slice(hostname.indexOf(\".\") + 1);\n }\n}\n\nfunction matchesHttpsHost(url: string | undefined, hostname: string): boolean {\n const source = url && URL.parse(url);\n return (\n !!source &&\n source.protocol === \"https:\" &&\n source.hostname.toLowerCase() === hostname\n );\n}\n\n/** Standard public SSH aliases, plus a hosted SCM established by the caller. */\nexport function normalizeHostedGitRepositoryUrl(\n remote: string,\n source: string | undefined,\n trustedScm: boolean,\n): string {\n // A projected single-project report may retain only its SSH spelling.\n return normalizeGitSshAlias(\n remote,\n (host) =>\n (trustedScm || isPublicGitHost(gitServiceHostname(host))) &&\n matchesHttpsHost(source ?? `https://${host}`, host),\n );\n}\n\nfunction normalizeGitSshAlias(\n repository: string,\n isAliasHost: (host: string) => boolean,\n): string {\n const isGitSshUser = (username: string, hostname: string) =>\n (username === \"git\" && hostname === \"github.com\") ||\n (isAliasHost(hostname) &&\n (username === \"git\" ||\n username ===\n /^([^.]+)\\.ghe\\.com$/u.exec(gitServiceHostname(hostname))?.[1]));\n const hostedAlias = (\n url: URL,\n user: string,\n path: string,\n scpStyle: boolean,\n ) => {\n const hostname = url.hostname.toLowerCase();\n const standard =\n isGitSshUser(user, hostname) && (url.port === \"\" || url.port === \"22\");\n const alternate =\n user === \"git\" && url.port === \"443\" && publicGitSsh443Host(hostname);\n if (!standard && !alternate) return repository;\n const bytes = gitTransportBytes(path, scpStyle);\n if (/[?#\\\\]/u.test(bytes) || /(?:^|\\/)\\.{1,2}(?:\\/|$)/u.test(bytes))\n return repository;\n return `https://${alternate || hostname}/${gitPathToHttpPath(bytes)}`;\n };\n const scp = parseScpRemote(repository);\n if (scp) {\n if (!scp[1]) return repository;\n const authority = sshAuthority(scp[2]!);\n return authority\n ? hostedAlias(authority, scp[1], scp[3]!, true)\n : repository;\n }\n // Git separates the decoded authority from the path at the first slash.\n const ssh = sshRemote.exec(repository);\n if (ssh && !/[\\t\\r\\n]/u.test(repository)) {\n const authority = gitTransportBytes(ssh[1]!, false);\n const login = /^([^@:]+)@([^@]+)$/u.exec(authority);\n if (!login || /[/\\\\%?#\\s]/u.test(authority)) return repository;\n const url = sshAuthority(login[2]!);\n if (url)\n return hostedAlias(\n url,\n login[1]!,\n \"/\" + repository.slice(ssh[0].length),\n false,\n );\n }\n return repository;\n}\n\nfunction hostedHttpAuthority(authority: string): string {\n if (/[%@\\\\\\s]/u.test(authority)) return authority;\n const hostname = URL.parse(`https://${authority}/`)?.hostname;\n // Hostname serialization handles IP literals and IDNA. The connector distinguishes explicit ports.\n const port = /:\\d*$/u.exec(authority)?.[0] ?? \"\";\n return hostname ? hostname + port : authority;\n}\n\nfunction hostedHttpPath(path: string): string {\n const segments: string[] = [];\n for (const segment of path.split(\"/\")) {\n // Git's HTTP transport resolves literal dot segments before sending the path.\n if (segment === \"..\") {\n segments.pop();\n } else if (segment !== \".\") {\n const spelling = segment.replace(/\\P{ASCII}+/gu, (text) =>\n encodeURIComponent(text.toWellFormed()),\n );\n const decoded = decodeUnreserved(spelling);\n segments.push(\n decoded === \".\" || decoded === \"..\" ? segment.toUpperCase() : decoded,\n );\n }\n }\n if (/(?:^|\\/)\\.{1,2}$/u.test(path)) segments.push(\"\");\n return segments.join(\"/\");\n}\n\n/** Compare the HTTP request path a browser and Git would send for the same link. */\nexport function ambiguousHostedHttpPath(value: string): boolean {\n const path = /^https?:\\/\\/[^/?#]+\\/([^?#]*)/iu.exec(value)?.[1];\n if (path === undefined) return false;\n const web = URL.parse(value)?.pathname.slice(1);\n return (\n web !== undefined &&\n path !== web &&\n hostedHttpPath(path) !== hostedHttpPath(web)\n );\n}\n\n/** Compare hosted HTTP repository spellings without changing the retained evidence. */\nexport function hostedRepositoryUrlKey(\n value: string,\n github = false,\n knownGitSuffix = false,\n target: ExternalImportTarget = \"local\",\n): string {\n const url = value.replace(\n /^(https?:\\/\\/)([^/?#]+)\\/([^?#]*)/iu,\n (_, scheme: string, authority: string, path: string) =>\n scheme +\n (target === \"cloud\" && ambiguousGitIpHost(value)\n ? authority.toLowerCase()\n : hostedHttpAuthority(authority)) +\n \"/\" +\n hostedHttpPath(path),\n );\n if (github) return cloudRepositoryUrlKey(url);\n const host = URL.parse(url)?.hostname ?? \"\";\n const service = /^https?:\\/\\//iu.test(url) ? gitServiceHostname(host) : host;\n if (service !== host && isGitHubCloudHost(service))\n return cloudRepositoryUrlKey(url);\n // An arbitrary Git server can serve different repositories at /repo and /repo.git.\n const key = repositoryUrlKey(url);\n return !knownGitSuffix && !isPublicGitHost(service) && /\\.git\\/?$/u.test(url)\n ? key + \".git\"\n : key;\n}\n\n/** The Git HTTP Host and TLS server name can differ from the web URL's parsed IP literal. */\nexport function ambiguousGitIpHost(url: string): boolean {\n const host = URL.parse(url)?.hostname;\n if (!host || (!isIPv4(host) && !host.startsWith(\"[\"))) return false;\n const authority = /^https?:\\/\\/([^/?#]*)/iu.exec(url)?.[1] ?? \"\";\n const rawHost = authority\n .slice(authority.lastIndexOf(\"@\") + 1)\n .replace(/:\\d*$/u, \"\");\n return rawHost.toLowerCase() !== host;\n}\n\n/** Match a Git checkout to an independently selected hosted repository. */\nexport function hostedRepositoryMatches(\n source: { url: string; platform?: string; gitlab?: boolean },\n remote: string,\n): boolean {\n if (!/^https?:\\/\\//iu.test(source.url)) return remote === source.url;\n const github = source.platform === \"github\";\n const url = normalizeHostedGitRepositoryUrl(\n remote,\n source.url,\n github || source.platform === \"gitlab\",\n );\n const userinfo = /^https?:\\/\\/([^/?#]*)@/iu.exec(url)?.[1] ?? \"\";\n // Git passes raw URL paths to its HTTP transport. Do not turn backslashes,\n // controls or an encoded traversal into a match via web URL serialization.\n if (\n !/^https?:\\/\\//iu.test(url) ||\n /[\\\\\\x00-\\x20\\x7f?#]/u.test(url) ||\n // libcurl accepts encoded userinfo but rejects multiple literal authority delimiters.\n userinfo.includes(\"@\") ||\n // Git rejects a decoded line feed in credentials and libcurl rejects a NUL in usernames.\n /%0a/iu.test(userinfo) ||\n /^[^:]*%00/u.test(userinfo) ||\n ambiguousGitIpHost(url) ||\n ambiguousHostedHttpPath(url)\n )\n return false;\n // The local checkout's credentials and default HTTP port don't change the server path.\n const key = (value: string) =>\n hostedRepositoryUrlKey(\n value.replace(\n /^(https?:\\/\\/)([^/?#\\\\]+)\\//iu,\n (match, scheme: string, authority: string) => {\n const parsed = URL.parse(scheme + authority);\n return parsed ? scheme + parsed.host + \"/\" : match;\n },\n ),\n github,\n source.gitlab || source.platform === \"gitlab\",\n );\n return key(url) === key(source.url);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hosted-remediation.d.ts","sourceRoot":"","sources":["../src/hosted-remediation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAKL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;kBAmBvC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAC1C,OAAO,4BAA4B,CACpC,CAAC;AAEF,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,CAAC,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,sBAAsB,CAAC,WAAW,CAAC,CAAC;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,sBAAsB,CAAC,UAAU,CAAC,CAAC;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;IAC3D,OAAO,EAAE,iBAAiB,GAAG,WAAW,CAAC;IACzC,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;CAC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
|
48
48
|
const pluginRoot = await bundledPluginRoot();
|
|
49
49
|
const { version: pluginVersion } = await pluginMetadata(pluginRoot);
|
|
50
|
-
|
|
50
|
+
let prompt = await remediationPrompt({
|
|
51
51
|
operation: input.operation,
|
|
52
52
|
pluginRoot,
|
|
53
53
|
contents: [
|
|
@@ -59,6 +59,13 @@ export async function runHostedRemediation(value, options) {
|
|
|
59
59
|
validationInstructions: input.validationInstructions,
|
|
60
60
|
verificationMode: input.verificationMode,
|
|
61
61
|
});
|
|
62
|
+
if (input.operation === "patch") {
|
|
63
|
+
prompt = [
|
|
64
|
+
"Work in the supplied checkout and leave all patch edits uncommitted for the host to capture, even if repository or validation instructions ask you to commit or use a separate worktree.",
|
|
65
|
+
`Keep HEAD at the pinned revision ${input.revision}. Before returning, check git rev-parse HEAD and git status --short to confirm the revision and the files you report.`,
|
|
66
|
+
prompt,
|
|
67
|
+
].join("\n");
|
|
68
|
+
}
|
|
62
69
|
const target = {
|
|
63
70
|
version: 1,
|
|
64
71
|
operation: input.operation,
|
|
@@ -98,8 +105,21 @@ export async function runHostedRemediation(value, options) {
|
|
|
98
105
|
throw new Error("Execution receipt does not match the remediation request.");
|
|
99
106
|
if (execution.status !== "completed")
|
|
100
107
|
return { ...base, status: execution.status, execution };
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
const revision = await repositoryRevision(repository);
|
|
109
|
+
if (revision === null)
|
|
110
|
+
throw new Error("Could not resolve HEAD after remediation execution.");
|
|
111
|
+
if (revision !== input.revision) {
|
|
112
|
+
return {
|
|
113
|
+
...base,
|
|
114
|
+
status: "failed",
|
|
115
|
+
execution,
|
|
116
|
+
error: {
|
|
117
|
+
code: "INVALID_RESULT",
|
|
118
|
+
reason: "revision_changed",
|
|
119
|
+
message: "Checkout changed from the frozen revision during execution.",
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
103
123
|
const response = execution.finalResponse ?? "";
|
|
104
124
|
const outcome = input.operation === "patch"
|
|
105
125
|
? { patch: parseFindingPatch(response, input.finding.id) }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hosted-remediation.js","sourceRoot":"","sources":["../src/hosted-remediation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,iBAAiB,EACjB,sBAAsB,GAGvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,yBAAyB,GAE1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,YAAY,CAAC;IACzD,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACrB,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,iCAAiC,CAAC;IAC7D,OAAO,EAAE,CAAC,CAAC,YAAY,CAAC;QACtB,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACrB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;KAClC,CAAC;IACF,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;I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ACH;SACA,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACrD,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,KAAK,QAAQ,CAAC,EAAE,CAAC;QAC5E,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;IACJ,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { z } from \"zod\";\nimport { errorMessage } from \"./errors.js\";\nimport { bundledPluginRoot, pluginMetadata } from \"./runtime.js\";\nimport { normalizeRepository, repositoryRevision } from \"./targets.js\";\nimport {\n parseFindingPatch,\n parseFindingVerifications,\n remediationPrompt,\n VerificationModeSchema,\n type FindingPatch,\n type FindingVerification,\n} from \"./remediation.js\";\nimport {\n ScanExecutionResultSchema,\n type ScanExecutionResult,\n} from \"./scan-executor.js\";\nimport { VERSION } from \"./version.js\";\n\nexport const HostedRemediationInputSchema = z.strictObject({\n version: z.literal(1),\n operation: z.enum([\"patch\", \"verify\"]),\n repository: z.string().min(1),\n revision: z.string().regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/),\n finding: z.strictObject({\n id: z.string().min(1),\n context: z.string().trim().min(1),\n }),\n instructions: z.string().optional(),\n validationInstructions: z.string().optional(),\n verificationMode: VerificationModeSchema.optional(),\n model: z.string().min(1),\n reasoningEffort: z.string(),\n identity: z.strictObject({\n runId: z.string().min(1),\n attemptId: z.string().min(1),\n buildId: z.string().min(1),\n }),\n});\n\nexport type HostedRemediationInput = z.infer<\n typeof HostedRemediationInputSchema\n>;\n\nexport interface RemediationExecutionRequest {\n version: 1;\n requestId: string;\n operation: HostedRemediationInput[\"operation\"];\n repository: string;\n revision: string;\n identity: HostedRemediationInput[\"identity\"];\n findingId: string;\n prompt: string;\n model: string;\n reasoningEffort: HostedRemediationInput[\"reasoningEffort\"];\n sandbox: \"workspace-write\" | \"read-only\";\n runtime: { pluginRoot: string; pluginVersion: string };\n}\n\nexport type RemediationExecutionResult = ScanExecutionResult;\nexport type RemediationExecutionEvent = Readonly<Record<string, unknown>>;\n\nexport interface RemediationExecutor {\n /** Submit once and settle cancellation with the host's recorded receipt. */\n run(\n request: RemediationExecutionRequest,\n options: {\n signal: AbortSignal;\n onEvent?: (event: RemediationExecutionEvent) => void;\n },\n ): Promise<RemediationExecutionResult>;\n}\n\nexport interface HostedRemediationOptions {\n executor: RemediationExecutor;\n signal?: AbortSignal;\n onEvent?: (event: RemediationExecutionEvent) => void;\n}\n\nexport interface HostedRemediationResult {\n version: 1;\n operation: HostedRemediationInput[\"operation\"];\n repository: string;\n revision: string;\n identity: HostedRemediationInput[\"identity\"];\n findingId: string;\n status: RemediationExecutionResult[\"status\"];\n provenance: { cliVersion: string; pluginVersion: string; buildId: string };\n execution?: RemediationExecutionResult;\n patch?: FindingPatch;\n verification?: FindingVerification;\n error?: { code: string; message: string };\n}\n\nexport class HostedRemediationPreparationError extends Error {\n readonly reason = \"revision_mismatch\";\n constructor() {\n super(\"Checkout does not match the frozen revision.\");\n this.name = \"HostedRemediationPreparationError\";\n }\n}\n\n/**\n * Run one patch or verification through the supplied host executor.\n * The host prepares the candidate checkout, enforces the requested sandbox,\n * and owns patch artifacts, durable attempts, usage, and reconciliation.\n */\nexport async function runHostedRemediation(\n value: HostedRemediationInput,\n options: HostedRemediationOptions,\n): Promise<HostedRemediationResult> {\n const input = HostedRemediationInputSchema.parse(value);\n const signal = options.signal ?? new AbortController().signal;\n signal.throwIfAborted();\n const repository = await normalizeRepository(input.repository, signal);\n if ((await repositoryRevision(repository, signal)) !== input.revision)\n throw new HostedRemediationPreparationError();\n const pluginRoot = await bundledPluginRoot();\n const { version: pluginVersion } = await pluginMetadata(pluginRoot);\n const prompt = await remediationPrompt({\n operation: input.operation,\n pluginRoot,\n contents: [\n { occurrenceId: input.finding.id, context: input.finding.context },\n ],\n structuredPatch: true,\n verificationIds: [input.finding.id],\n instructions: input.instructions,\n validationInstructions: input.validationInstructions,\n verificationMode: input.verificationMode,\n });\n const target = {\n version: 1 as const,\n operation: input.operation,\n repository,\n revision: input.revision,\n identity: input.identity,\n findingId: input.finding.id,\n };\n const request: RemediationExecutionRequest = {\n ...target,\n requestId: randomUUID(),\n prompt,\n model: input.model,\n reasoningEffort: input.reasoningEffort,\n sandbox: input.operation === \"verify\" ? \"read-only\" : \"workspace-write\",\n runtime: { pluginRoot, pluginVersion },\n };\n const base = {\n ...target,\n provenance: {\n cliVersion: VERSION,\n pluginVersion,\n buildId: input.identity.buildId,\n },\n };\n let execution: RemediationExecutionResult | undefined;\n const onEvent = (event: RemediationExecutionEvent) => {\n void Promise.resolve()\n .then(() => options.onEvent?.(event))\n .catch(() => {});\n };\n try {\n signal.throwIfAborted();\n execution = await options.executor.run(request, { signal, onEvent });\n ScanExecutionResultSchema.parse(execution);\n if (execution.requestId !== request.requestId)\n throw new Error(\n \"Execution receipt does not match the remediation request.\",\n );\n if (execution.status !== \"completed\")\n return { ...base, status: execution.status, execution };\n if ((await repositoryRevision(repository)) !== input.revision)\n throw new Error(\n \"Checkout changed from the frozen revision during execution.\",\n );\n const response = execution.finalResponse ?? \"\";\n const outcome =\n input.operation === \"patch\"\n ? { patch: parseFindingPatch(response, input.finding.id) }\n : {\n verification: parseHostedVerification(response, input.finding.id),\n };\n return { ...base, status: \"completed\", execution, ...outcome };\n } catch (error) {\n return {\n ...base,\n status: signal.aborted && execution === undefined ? \"canceled\" : \"failed\",\n ...(execution === undefined ? {} : { execution }),\n error: {\n code: execution === undefined ? \"EXECUTION_FAILED\" : \"INVALID_RESULT\",\n message: errorMessage(error),\n },\n };\n }\n}\n\nfunction parseHostedVerification(response: string, findingId: string) {\n const verification = parseFindingVerifications(response, [findingId])[0]!;\n if (verification.status !== \"fixed\") return verification;\n // Recognize SDK 0.6.0 checks in the original report without requiring them.\n const checks = z\n .array(\n z.object({\n name: z.string().trim().min(1),\n status: z.enum([\"passed\", \"failed\", \"not_run\"]),\n evidence: z.string().trim().min(1),\n command: z.string().trim().min(1).optional(),\n }),\n )\n .safeParse(JSON.parse(response).results[0].checks);\n if (checks.success && checks.data.some(({ status }) => status !== \"passed\")) {\n throw new Error(\n \"A fixed verification result contradicts a failed or unrun required check.\",\n );\n }\n return verification;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hosted-remediation.js","sourceRoot":"","sources":["../src/hosted-remediation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,iBAAiB,EACjB,sBAAsB,GAGvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,yBAAyB,GAE1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,YAAY,CAAC;IACzD,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACrB,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,iCAAiC,CAAC;IAC7D,OAAO,EAAE,CAAC,CAAC,YAAY,CAAC;Q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AS,uBAAuB,CAAC,QAAgB,EAAE,SAAiB;IAClE,MAAM,YAAY,GAAG,yBAAyB,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC;IAC1E,IAAI,YAAY,CAAC,MAAM,KAAK,OAAO;QAAE,OAAO,YAAY,CAAC;IACzD,4EAA4E;IAC5E,MAAM,MAAM,GAAG,CAAC;SACb,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9B,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC/C,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAClC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;KAC7C,CAAC,CACH;SACA,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACrD,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,KAAK,QAAQ,CAAC,EAAE,CAAC;QAC5E,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;IACJ,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { z } from \"zod\";\nimport { errorMessage } from \"./errors.js\";\nimport { bundledPluginRoot, pluginMetadata } from \"./runtime.js\";\nimport { normalizeRepository, repositoryRevision } from \"./targets.js\";\nimport {\n parseFindingPatch,\n parseFindingVerifications,\n remediationPrompt,\n VerificationModeSchema,\n type FindingPatch,\n type FindingVerification,\n} from \"./remediation.js\";\nimport {\n ScanExecutionResultSchema,\n type ScanExecutionResult,\n} from \"./scan-executor.js\";\nimport { VERSION } from \"./version.js\";\n\nexport const HostedRemediationInputSchema = z.strictObject({\n version: z.literal(1),\n operation: z.enum([\"patch\", \"verify\"]),\n repository: z.string().min(1),\n revision: z.string().regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/),\n finding: z.strictObject({\n id: z.string().min(1),\n context: z.string().trim().min(1),\n }),\n instructions: z.string().optional(),\n validationInstructions: z.string().optional(),\n verificationMode: VerificationModeSchema.optional(),\n model: z.string().min(1),\n reasoningEffort: z.string(),\n identity: z.strictObject({\n runId: z.string().min(1),\n attemptId: z.string().min(1),\n buildId: z.string().min(1),\n }),\n});\n\nexport type HostedRemediationInput = z.infer<\n typeof HostedRemediationInputSchema\n>;\n\nexport interface RemediationExecutionRequest {\n version: 1;\n requestId: string;\n operation: HostedRemediationInput[\"operation\"];\n repository: string;\n revision: string;\n identity: HostedRemediationInput[\"identity\"];\n findingId: string;\n prompt: string;\n model: string;\n reasoningEffort: HostedRemediationInput[\"reasoningEffort\"];\n sandbox: \"workspace-write\" | \"read-only\";\n runtime: { pluginRoot: string; pluginVersion: string };\n}\n\nexport type RemediationExecutionResult = ScanExecutionResult;\nexport type RemediationExecutionEvent = Readonly<Record<string, unknown>>;\n\nexport interface RemediationExecutor {\n /** Submit once and settle cancellation with the host's recorded receipt. */\n run(\n request: RemediationExecutionRequest,\n options: {\n signal: AbortSignal;\n onEvent?: (event: RemediationExecutionEvent) => void;\n },\n ): Promise<RemediationExecutionResult>;\n}\n\nexport interface HostedRemediationOptions {\n executor: RemediationExecutor;\n signal?: AbortSignal;\n onEvent?: (event: RemediationExecutionEvent) => void;\n}\n\nexport interface HostedRemediationResult {\n version: 1;\n operation: HostedRemediationInput[\"operation\"];\n repository: string;\n revision: string;\n identity: HostedRemediationInput[\"identity\"];\n findingId: string;\n status: RemediationExecutionResult[\"status\"];\n provenance: { cliVersion: string; pluginVersion: string; buildId: string };\n execution?: RemediationExecutionResult;\n patch?: FindingPatch;\n verification?: FindingVerification;\n error?: { code: string; message: string; reason?: \"revision_changed\" };\n}\n\nexport class HostedRemediationPreparationError extends Error {\n readonly reason = \"revision_mismatch\";\n constructor() {\n super(\"Checkout does not match the frozen revision.\");\n this.name = \"HostedRemediationPreparationError\";\n }\n}\n\n/**\n * Run one patch or verification through the supplied host executor.\n * The host prepares the candidate checkout, enforces the requested sandbox,\n * and owns patch artifacts, durable attempts, usage, and reconciliation.\n */\nexport async function runHostedRemediation(\n value: HostedRemediationInput,\n options: HostedRemediationOptions,\n): Promise<HostedRemediationResult> {\n const input = HostedRemediationInputSchema.parse(value);\n const signal = options.signal ?? new AbortController().signal;\n signal.throwIfAborted();\n const repository = await normalizeRepository(input.repository, signal);\n if ((await repositoryRevision(repository, signal)) !== input.revision)\n throw new HostedRemediationPreparationError();\n const pluginRoot = await bundledPluginRoot();\n const { version: pluginVersion } = await pluginMetadata(pluginRoot);\n let prompt = await remediationPrompt({\n operation: input.operation,\n pluginRoot,\n contents: [\n { occurrenceId: input.finding.id, context: input.finding.context },\n ],\n structuredPatch: true,\n verificationIds: [input.finding.id],\n instructions: input.instructions,\n validationInstructions: input.validationInstructions,\n verificationMode: input.verificationMode,\n });\n if (input.operation === \"patch\") {\n prompt = [\n \"Work in the supplied checkout and leave all patch edits uncommitted for the host to capture, even if repository or validation instructions ask you to commit or use a separate worktree.\",\n `Keep HEAD at the pinned revision ${input.revision}. Before returning, check git rev-parse HEAD and git status --short to confirm the revision and the files you report.`,\n prompt,\n ].join(\"\\n\");\n }\n const target = {\n version: 1 as const,\n operation: input.operation,\n repository,\n revision: input.revision,\n identity: input.identity,\n findingId: input.finding.id,\n };\n const request: RemediationExecutionRequest = {\n ...target,\n requestId: randomUUID(),\n prompt,\n model: input.model,\n reasoningEffort: input.reasoningEffort,\n sandbox: input.operation === \"verify\" ? \"read-only\" : \"workspace-write\",\n runtime: { pluginRoot, pluginVersion },\n };\n const base = {\n ...target,\n provenance: {\n cliVersion: VERSION,\n pluginVersion,\n buildId: input.identity.buildId,\n },\n };\n let execution: RemediationExecutionResult | undefined;\n const onEvent = (event: RemediationExecutionEvent) => {\n void Promise.resolve()\n .then(() => options.onEvent?.(event))\n .catch(() => {});\n };\n try {\n signal.throwIfAborted();\n execution = await options.executor.run(request, { signal, onEvent });\n ScanExecutionResultSchema.parse(execution);\n if (execution.requestId !== request.requestId)\n throw new Error(\n \"Execution receipt does not match the remediation request.\",\n );\n if (execution.status !== \"completed\")\n return { ...base, status: execution.status, execution };\n const revision = await repositoryRevision(repository);\n if (revision === null)\n throw new Error(\"Could not resolve HEAD after remediation execution.\");\n if (revision !== input.revision) {\n return {\n ...base,\n status: \"failed\",\n execution,\n error: {\n code: \"INVALID_RESULT\",\n reason: \"revision_changed\",\n message:\n \"Checkout changed from the frozen revision during execution.\",\n },\n };\n }\n const response = execution.finalResponse ?? \"\";\n const outcome =\n input.operation === \"patch\"\n ? { patch: parseFindingPatch(response, input.finding.id) }\n : {\n verification: parseHostedVerification(response, input.finding.id),\n };\n return { ...base, status: \"completed\", execution, ...outcome };\n } catch (error) {\n return {\n ...base,\n status: signal.aborted && execution === undefined ? \"canceled\" : \"failed\",\n ...(execution === undefined ? {} : { execution }),\n error: {\n code: execution === undefined ? \"EXECUTION_FAILED\" : \"INVALID_RESULT\",\n message: errorMessage(error),\n },\n };\n }\n}\n\nfunction parseHostedVerification(response: string, findingId: string) {\n const verification = parseFindingVerifications(response, [findingId])[0]!;\n if (verification.status !== \"fixed\") return verification;\n // Recognize SDK 0.6.0 checks in the original report without requiring them.\n const checks = z\n .array(\n z.object({\n name: z.string().trim().min(1),\n status: z.enum([\"passed\", \"failed\", \"not_run\"]),\n evidence: z.string().trim().min(1),\n command: z.string().trim().min(1).optional(),\n }),\n )\n .safeParse(JSON.parse(response).results[0].checks);\n if (checks.success && checks.data.some(({ status }) => status !== \"passed\")) {\n throw new Error(\n \"A fixed verification result contradicts a failed or unrun required check.\",\n );\n }\n return verification;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { runHostProtocol } from "./host-protocol.js";
|
|
2
|
-
import { HostedScanPreparationError,
|
|
2
|
+
import { HostedScanPreparationError, runHostedScanInternal, } from "./hosted-scan.js";
|
|
3
3
|
import { ScanExecutionEventSchema, ScanExecutionResultSchema, } from "./scan-executor.js";
|
|
4
4
|
export async function runHostedScanProtocol(input, output, signal) {
|
|
5
5
|
return await runHostProtocol(input, output, {
|
|
@@ -9,7 +9,7 @@ export async function runHostedScanProtocol(input, output, signal) {
|
|
|
9
9
|
errorData: (error) => error instanceof HostedScanPreparationError
|
|
10
10
|
? { reason: error.reason }
|
|
11
11
|
: undefined,
|
|
12
|
-
run: async (params, execute, signal, onEvent) => await
|
|
12
|
+
run: async (params, execute, signal, onEvent) => await runHostedScanInternal("cli", params, {
|
|
13
13
|
signal,
|
|
14
14
|
onEvent,
|
|
15
15
|
executor: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hosted-scan-protocol.js","sourceRoot":"","sources":["../src/hosted-scan-protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAEL,0BAA0B,EAC1B,
|
|
1
|
+
{"version":3,"file":"hosted-scan-protocol.js","sourceRoot":"","sources":["../src/hosted-scan-protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAEL,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,KAAe,EACf,MAA6C,EAC7C,MAAoB;IAEpB,OAAO,MAAM,eAAe,CAC1B,KAAK,EACL,MAAM,EACN;QACE,KAAK,EAAE,MAAM;QACb,aAAa,EAAE,eAAe;QAC9B,wBAAwB,EAAE,IAAI;QAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CACnB,KAAK,YAAY,0BAA0B;YACzC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE;YAC1B,CAAC,CAAC,SAAS;QACf,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAC9C,MAAM,qBAAqB,CAAC,KAAK,EAAE,MAAyB,EAAE;YAC5D,MAAM;YACN,OAAO;YACP,QAAQ,EAAE;gBACR,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAC9B,yBAAyB,CAAC,KAAK,CAC7B,MAAM,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;oBAClD,MAAM,MAAM,GAAG,wBAAwB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;oBACzD,IAAI,MAAM,CAAC,OAAO;wBAAE,OAAO,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACrD,CAAC,CAAC,CACH;aACJ;SACF,CAAC;KACL,EACD,MAAM,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { Readable } from \"node:stream\";\nimport { runHostProtocol } from \"./host-protocol.js\";\nimport {\n type HostedScanInput,\n HostedScanPreparationError,\n runHostedScanInternal,\n} from \"./hosted-scan.js\";\nimport {\n ScanExecutionEventSchema,\n ScanExecutionResultSchema,\n} from \"./scan-executor.js\";\n\nexport async function runHostedScanProtocol(\n input: Readable,\n output: Parameters<typeof runHostProtocol>[1],\n signal?: AbortSignal,\n): Promise<number> {\n return await runHostProtocol(\n input,\n output,\n {\n label: \"Scan\",\n requestMethod: \"execution.run\",\n awaitCancellationReceipt: true,\n errorData: (error) =>\n error instanceof HostedScanPreparationError\n ? { reason: error.reason }\n : undefined,\n run: async (params, execute, signal, onEvent) =>\n await runHostedScanInternal(\"cli\", params as HostedScanInput, {\n signal,\n onEvent,\n executor: {\n run: async (request, options) =>\n ScanExecutionResultSchema.parse(\n await execute(request.requestId, request, (event) => {\n const parsed = ScanExecutionEventSchema.safeParse(event);\n if (parsed.success) options.onEvent?.(parsed.data);\n }),\n ),\n },\n }),\n },\n signal,\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hosted-scan.d.ts","sourceRoot":"","sources":["../src/hosted-scan.ts"],"names":[],"mappings":"AASA,OAAO,
|
|
1
|
+
{"version":3,"file":"hosted-scan.d.ts","sourceRoot":"","sources":["../src/hosted-scan.ts"],"names":[],"mappings":"AASA,OAAO,EAGL,KAAK,YAAY,EAEjB,KAAK,kBAAkB,EAExB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG7E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,qFAAqF;AACrF,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;kBAuBhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACpE,qBAAa,0BAA2B,SAAQ,KAAK;IAEjD,QAAQ,CAAC,MAAM,EACX,cAAc,GACd,eAAe,GACf,0BAA0B,GAC1B,aAAa,GACb,mBAAmB;IANzB,YACW,MAAM,EACX,cAAc,GACd,eAAe,GACf,0BAA0B,GAC1B,aAAa,GACb,mBAAmB,EACvB,OAAO,EAAE,MAAM,EAIhB;CACF;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAyBzD;AAMD,wBAAgB,oBAAoB,CAClC,KAAK,GAAE,SAAS,MAAM,EAAU,GAC/B,MAAM,EAAE,CAeV;AAiED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,YAAY,CAAC;IACvB,4FAA4F;IAC5F,UAAU,CAAC,EAAE;QACX,WAAW,CAAC,OAAO,EAAE;YAAE,KAAK,CAAC,EAAE,MAAM,CAAC;YAAC,oBAAoB,CAAC,EAAE,MAAM,CAAA;SAAE,GAAG;YACvE,GAAG,CACD,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;gBAAE,YAAY,CAAC,EAAE,OAAO,CAAC;gBAAC,MAAM,CAAC,EAAE,WAAW,CAAA;aAAE,GACxD,OAAO,CAAC;gBAAE,aAAa,EAAE,MAAM,CAAA;aAAE,CAAC,CAAC;SACvC,CAAC;KACH,CAAC;IACF,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;CAC/C;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAC3B,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,iBAAiB;;;;QAef,KAAK;;;;;;;;;;;;aAYL,CAAC;;;;;;;;;;;;;;;;;;;;;;YA6IA,WAAW;;;;;;;;;;;QAzJZ,KAAK;;;;;;;;;;;;aAYL,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;GAxBb;AAwMD,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC"}
|
package/dist/hosted-scan.js
CHANGED
|
@@ -3,13 +3,13 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
3
3
|
import { readScanFile, safeScopePath, validatedFileDigests, } from "./contract.js";
|
|
4
4
|
import { isRecord } from "./record.js";
|
|
5
5
|
import { VERSION } from "./version.js";
|
|
6
|
-
import { ScanExecutionError, } from "./scan-executor.js";
|
|
6
|
+
import { hostedScanFailureStatus, ScanExecutionError, } from "./scan-executor.js";
|
|
7
7
|
import { realpath } from "node:fs/promises";
|
|
8
8
|
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { CodexSecurity } from "./api.js";
|
|
11
11
|
import { severityRubricSnapshotSchema } from "./classify-severity-records.js";
|
|
12
|
-
import {
|
|
12
|
+
import { errorMessage } from "./errors.js";
|
|
13
13
|
import { abortable, normalizeRepository, repositoryRevision, } from "./targets.js";
|
|
14
14
|
import { isWithin } from "./trusted-executable.js";
|
|
15
15
|
/** Hosted v2 mirrors repository/paths targets; only Standard scans are supported. */
|
|
@@ -118,7 +118,11 @@ function hostedScanEnvironment(stateDirectory) {
|
|
|
118
118
|
return environment;
|
|
119
119
|
}
|
|
120
120
|
/** One invocation, with only scan-domain state. The host decides retry/reconciliation. */
|
|
121
|
-
export
|
|
121
|
+
export function runHostedScan(value, options) {
|
|
122
|
+
return runHostedScanInternal("sdk", value, options);
|
|
123
|
+
}
|
|
124
|
+
/** @internal */
|
|
125
|
+
export async function runHostedScanInternal(surface, value, options) {
|
|
122
126
|
const input = HostedScanInputSchema.parse(value);
|
|
123
127
|
const context = {
|
|
124
128
|
repository: input.repository,
|
|
@@ -132,6 +136,7 @@ export async function runHostedScan(value, options) {
|
|
|
132
136
|
let execution;
|
|
133
137
|
let request;
|
|
134
138
|
let scanId;
|
|
139
|
+
let stoppedStatus;
|
|
135
140
|
let outputDirectory = resolve(input.outputDirectory);
|
|
136
141
|
const base = () => ({
|
|
137
142
|
version: 2,
|
|
@@ -193,7 +198,7 @@ export async function runHostedScan(value, options) {
|
|
|
193
198
|
createCodex() {
|
|
194
199
|
throw new Error("Local inference is unavailable in hosted mode.");
|
|
195
200
|
},
|
|
196
|
-
}, { surface
|
|
201
|
+
}, { surface });
|
|
197
202
|
try {
|
|
198
203
|
const result = await client.run(context.repository, {
|
|
199
204
|
target: context.scope.paths[0] === "."
|
|
@@ -210,6 +215,10 @@ export async function runHostedScan(value, options) {
|
|
|
210
215
|
scanId = scan.scanId;
|
|
211
216
|
outputDirectory = scan.scanDir;
|
|
212
217
|
},
|
|
218
|
+
onLifecycle(scan) {
|
|
219
|
+
if (scan.status === "canceled" || scan.status === "failed")
|
|
220
|
+
stoppedStatus = scan.status;
|
|
221
|
+
},
|
|
213
222
|
onProgress(progress) {
|
|
214
223
|
onEvent({ type: "progress", progress });
|
|
215
224
|
},
|
|
@@ -262,15 +271,11 @@ export async function runHostedScan(value, options) {
|
|
|
262
271
|
catch (error) {
|
|
263
272
|
if (error instanceof ScanExecutionError)
|
|
264
273
|
execution = error.result;
|
|
274
|
+
const status = hostedScanFailureStatus(error, options.signal, execution);
|
|
265
275
|
return {
|
|
266
276
|
...base(),
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
: options.signal?.aborted ||
|
|
270
|
-
execution?.status === "canceled" ||
|
|
271
|
-
error instanceof ScanInterruptedError
|
|
272
|
-
? "canceled"
|
|
273
|
-
: "failed",
|
|
277
|
+
// A late abort during cleanup cannot change an already committed failure.
|
|
278
|
+
status: status === "acceptance_unknown" ? status : (stoppedStatus ?? status),
|
|
274
279
|
error: errorMessage(error),
|
|
275
280
|
artifacts: [],
|
|
276
281
|
};
|