@openai/codex-security 0.8.2 → 0.9.1
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 +201 -178
- package/_bundled_plugin/.app.json +4 -0
- package/_bundled_plugin/.mcp.json +6 -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 +51 -14
- 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/core-scan.md +14 -5
- package/_bundled_plugin/references/default-severity-rubric.md +33 -0
- package/_bundled_plugin/references/final-report.md +5 -3
- package/_bundled_plugin/references/finding-detail-fields.md +19 -18
- 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/threat-model.md +1 -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 +188 -454
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +317 -377
- package/_bundled_plugin/scripts/finding_preview.py +25 -29
- package/_bundled_plugin/scripts/launch_codex_security_mcp +1 -0
- package/_bundled_plugin/scripts/legacy_findings.py +148 -0
- package/_bundled_plugin/scripts/posix_scan_local_files.py +198 -0
- package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
- package/_bundled_plugin/scripts/report_projection.py +167 -178
- 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 +1 -0
- package/_bundled_plugin/scripts/threat_model_projection.py +22 -26
- package/_bundled_plugin/scripts/validate_scan_contract.py +9 -7
- package/_bundled_plugin/scripts/windows_scan_local_files.py +600 -72
- package/_bundled_plugin/scripts/workbench/__init__.py +1 -1
- package/_bundled_plugin/scripts/workbench/handoff.py +47 -0
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +38 -75
- 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 +152 -248
- 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 +71 -7
- package/_bundled_plugin/scripts/workbench_cli.py +121 -14
- package/_bundled_plugin/scripts/workbench_constants.py +19 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
- package/_bundled_plugin/scripts/workbench_db.py +550 -492
- package/_bundled_plugin/scripts/workbench_feedback.py +8 -7
- package/_bundled_plugin/scripts/workbench_finding_index.py +1 -0
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +90 -4
- package/_bundled_plugin/scripts/workbench_native_indexes.py +29 -33
- package/_bundled_plugin/scripts/workbench_progress.py +10 -1
- package/_bundled_plugin/scripts/workbench_publication.py +14 -10
- package/_bundled_plugin/scripts/workbench_remediation.py +508 -11
- package/_bundled_plugin/scripts/workbench_saved_results.py +132 -77
- package/_bundled_plugin/scripts/workbench_scan_history.py +139 -80
- package/_bundled_plugin/scripts/workbench_scan_start.py +84 -25
- package/_bundled_plugin/scripts/workbench_scan_usage.py +666 -117
- package/_bundled_plugin/scripts/workbench_schema.py +44 -55
- package/_bundled_plugin/scripts/workbench_setup.py +251 -0
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +33 -23
- package/_bundled_plugin/scripts/workbench_target.py +330 -66
- package/_bundled_plugin/scripts/workbench_target_state.py +3 -0
- package/_bundled_plugin/scripts/workbench_validation.py +44 -12
- package/_bundled_plugin/shared/workbench-history-repairs.json +19 -16
- package/_bundled_plugin/shared/workbench-migrations.json +53 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
- package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
- package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +6 -4
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
- package/_bundled_plugin/skills/fix-finding/SKILL.md +19 -2
- package/_bundled_plugin/skills/publish-findings/SKILL.md +81 -45
- package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +5 -24
- package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +464 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +36 -9
- package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
- package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +12 -6
- package/dist/api.d.ts +45 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1144 -411
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +10 -7
- package/dist/auth.js.map +1 -1
- 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 +8 -0
- package/dist/blackduck-findings.d.ts.map +1 -0
- package/dist/blackduck-findings.js +320 -0
- package/dist/blackduck-findings.js.map +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +51 -36
- package/dist/bulk-scan-discovery.js.map +1 -1
- 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-severity-records.d.ts +6 -9
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +9 -21
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts +4 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +30 -13
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +14 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2112 -1266
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +2 -2
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-prompt.d.ts +2 -0
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +6 -0
- package/dist/codex-prompt.js.map +1 -1
- package/dist/component-scan.d.ts +16 -3
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +32 -6
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +221 -65
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts +7 -0
- package/dist/continuum-findings.d.ts.map +1 -0
- package/dist/continuum-findings.js +225 -0
- package/dist/continuum-findings.js.map +1 -0
- package/dist/contract-values.d.ts +30 -0
- package/dist/contract-values.d.ts.map +1 -0
- package/dist/contract-values.js +78 -0
- package/dist/contract-values.js.map +1 -0
- package/dist/contract.d.ts +2 -20
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +58 -669
- package/dist/contract.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 -115
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +61 -4
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +2560 -100
- 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 +5 -0
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts +2 -0
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +4 -0
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +4 -4
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +2 -2
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +11 -4
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/finding-schema.d.ts +19 -1
- package/dist/deduplication/finding-schema.d.ts.map +1 -1
- package/dist/deduplication/finding-schema.js +25 -0
- package/dist/deduplication/finding-schema.js.map +1 -1
- package/dist/deduplication/local.d.ts +2 -2
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +5 -10
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/records.d.ts +8 -2
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +36 -8
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/refusal.d.ts.map +1 -1
- package/dist/deduplication/refusal.js +25 -5
- package/dist/deduplication/refusal.js.map +1 -1
- package/dist/deduplication/scan.d.ts +3 -0
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +1 -1
- 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 +13 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +262 -7
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -2
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +2 -66
- 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 +108 -80
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +9 -2
- package/dist/errors.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 +11 -16
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +15 -4
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +619 -225
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +20 -6
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +2356 -308
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +28 -2
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +174 -81
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +17 -3
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +153 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +33 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +335 -51
- 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/finding-retrieval.d.ts +3 -3
- package/dist/finding-retrieval.d.ts.map +1 -1
- package/dist/finding-retrieval.js.map +1 -1
- package/dist/finding-workflow.d.ts +6 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +2 -2
- package/dist/finding-workflow.js.map +1 -1
- 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/git-remote.d.ts +4 -0
- package/dist/git-remote.d.ts.map +1 -1
- package/dist/git-remote.js +20 -0
- package/dist/git-remote.js.map +1 -1
- package/dist/github-advisories.d.ts +3 -12
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +9 -31
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +22 -20
- 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 +392 -79
- package/dist/github-findings.js.map +1 -1
- package/dist/github.d.ts +17 -7
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +43 -30
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +2 -2
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +10 -11
- package/dist/host-records-protocol.d.ts.map +1 -1
- package/dist/host-records-protocol.js +69 -9
- package/dist/host-records-protocol.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-scan-protocol.js +2 -2
- package/dist/hosted-scan-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts +15 -0
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +71 -44
- 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/hosted-scanner-v1.d.ts +6 -0
- package/dist/hosted-scanner-v1.d.ts.map +1 -0
- package/dist/hosted-scanner-v1.js +60 -0
- package/dist/hosted-scanner-v1.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 +24 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +58 -81
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +86 -10
- package/dist/knowledge-base.js.map +1 -1
- package/dist/local-git-metadata.d.ts +5 -0
- package/dist/local-git-metadata.d.ts.map +1 -0
- package/dist/local-git-metadata.js +130 -0
- package/dist/local-git-metadata.js.map +1 -0
- package/dist/multiscan.d.ts +6 -4
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +160 -77
- 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 +1 -0
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +49 -31
- 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/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +90 -35
- package/dist/patch-tui.js.map +1 -1
- 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 +341 -0
- package/dist/private-finding-import.d.ts.map +1 -0
- package/dist/private-finding-import.js +411 -0
- package/dist/private-finding-import.js.map +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -2
- package/dist/project-config.js.map +1 -1
- package/dist/provider-profile.d.ts +11 -3
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +80 -11
- 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.js +7 -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/reader-selection.d.ts +15 -0
- package/dist/reader-selection.d.ts.map +1 -0
- package/dist/reader-selection.js +89 -0
- package/dist/reader-selection.js.map +1 -0
- package/dist/record.d.ts +6 -1
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +53 -2
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts +3 -1
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +28 -2
- 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 +6 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +3 -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 +22 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +408 -162
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +1 -0
- package/dist/saved-scan-bootstrap.d.ts.map +1 -1
- package/dist/saved-scan-bootstrap.js +18 -15
- package/dist/saved-scan-bootstrap.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +172 -64
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +10 -5
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +68 -25
- 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 +91 -79
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +12 -1
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js +22 -2
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +31 -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 +106 -77
- 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 +64 -6
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +406 -48
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +17 -0
- package/dist/scanner-repository-url.d.ts.map +1 -0
- package/dist/scanner-repository-url.js +71 -0
- package/dist/scanner-repository-url.js.map +1 -0
- package/dist/security-policy.d.ts +1 -1
- package/dist/security-policy.d.ts.map +1 -1
- 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 +124 -88
- 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 +213 -0
- package/dist/semgrep-platform-findings.d.ts.map +1 -0
- package/dist/semgrep-platform-findings.js +1078 -0
- package/dist/semgrep-platform-findings.js.map +1 -0
- package/dist/semgrep-platform-v1.d.ts +6 -0
- package/dist/semgrep-platform-v1.d.ts.map +1 -0
- package/dist/semgrep-platform-v1.js +83 -0
- package/dist/semgrep-platform-v1.js.map +1 -0
- 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/severity-rubric.d.ts +20 -0
- package/dist/severity-rubric.d.ts.map +1 -0
- package/dist/severity-rubric.js +73 -0
- package/dist/severity-rubric.js.map +1 -0
- package/dist/severity-store.js +15 -5
- package/dist/severity-store.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 +7 -2
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +108 -84
- package/dist/snyk-findings.js.map +1 -1
- package/dist/snyk-rest-findings.d.ts +76 -0
- package/dist/snyk-rest-findings.d.ts.map +1 -0
- package/dist/snyk-rest-findings.js +1051 -0
- package/dist/snyk-rest-findings.js.map +1 -0
- package/dist/snyk-rest-v1.d.ts +28 -0
- package/dist/snyk-rest-v1.d.ts.map +1 -0
- package/dist/snyk-rest-v1.js +132 -0
- package/dist/snyk-rest-v1.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 +16 -0
- package/dist/sonar-collector.d.ts.map +1 -0
- package/dist/sonar-collector.js +380 -0
- package/dist/sonar-collector.js.map +1 -0
- package/dist/sonar-findings.d.ts +49 -0
- package/dist/sonar-findings.d.ts.map +1 -0
- package/dist/sonar-findings.js +288 -0
- package/dist/sonar-findings.js.map +1 -0
- package/dist/sonar-import.d.ts +111 -0
- package/dist/sonar-import.d.ts.map +1 -0
- package/dist/sonar-import.js +277 -0
- package/dist/sonar-import.js.map +1 -0
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +2 -1
- package/dist/suggest-owners.js.map +1 -1
- 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 +5 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +73 -31
- package/dist/targets.js.map +1 -1
- package/dist/tenable-findings.d.ts +9 -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-columns.d.ts +4 -0
- package/dist/terminal-columns.d.ts.map +1 -0
- package/dist/terminal-columns.js +19 -0
- package/dist/terminal-columns.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 +435 -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/validation-records.d.ts +0 -3
- package/dist/validation-records.d.ts.map +1 -1
- package/dist/validation-records.js +1 -17
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +9 -0
- package/dist/veracode-findings.d.ts.map +1 -0
- package/dist/veracode-findings.js +409 -0
- package/dist/veracode-findings.js.map +1 -0
- 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 +27 -1
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-csv.d.ts +2 -2
- package/dist/wiz-csv.d.ts.map +1 -1
- package/dist/wiz-csv.js +1 -3
- package/dist/wiz-csv.js.map +1 -1
- package/dist/wiz-findings.d.ts +14 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +143 -50
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +28 -13
- package/docs/cli.md +623 -843
- package/docs/dedupe-records.md +54 -24
- package/docs/findings-service.md +87 -47
- package/docs/hosted-remediation.md +14 -7
- package/docs/hosted-scans.md +64 -41
- package/docs/telemetry.md +236 -0
- package/docs/validate-records.md +78 -44
- package/package.json +19 -17
- package/schemas/external-findings.schema.json +14 -1
- package/schemas/hosted-scan-v2.fixture.json +16 -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/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
- package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
- package/dist/deduplication/records-protocol.d.ts +0 -4
- package/dist/deduplication/records-protocol.d.ts.map +0 -1
- package/dist/deduplication/records-protocol.js +0 -49
- package/dist/deduplication/records-protocol.js.map +0 -1
- 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 -120
- package/dist/finding-normalization.js.map +0 -1
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { validateExternalEvidenceJson, validateExternalReport, } from "./external-import-contract.js";
|
|
1
|
+
import { previousAdmission, validateExternalEvidenceJson, validateExternalReport, } from "./external-import-contract.js";
|
|
3
2
|
import { canonicalJson } from "./record.js";
|
|
4
3
|
import { errorMessage } from "./errors.js";
|
|
5
|
-
import { messageText, parseNativeJsonResult, projectNativeJsonResult, sourceRepositoryUrl, } from "./native-json-findings.js";
|
|
6
|
-
import { array, readScannerJson, record,
|
|
4
|
+
import { messageText, nativeResultPath, parseNativeJsonResult, projectNativeJsonResult, sourceRepositoryUrl, } from "./native-json-findings.js";
|
|
5
|
+
import { trackReaderSelection, array, readScannerJson, record, requiredText, stableId, } from "./scanner-import.js";
|
|
6
|
+
// Occurrences are sorted by ID and can retain traces from nonadjacent input rows.
|
|
7
|
+
const sourcePositions = new WeakMap();
|
|
8
|
+
export function getOpenGrepSourcePositions(findings) {
|
|
9
|
+
return Array.isArray(findings) ? sourcePositions.get(findings) : undefined;
|
|
10
|
+
}
|
|
7
11
|
/** Import native scanner evidence without assigning a Codex assessment. */
|
|
8
12
|
export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
9
13
|
const document = record(input, "OpenGrep report");
|
|
@@ -27,7 +31,10 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
27
31
|
excluded: [],
|
|
28
32
|
report: structuredClone(report),
|
|
29
33
|
};
|
|
34
|
+
const selection = trackReaderSelection(output);
|
|
30
35
|
function exclude(position, id, error) {
|
|
36
|
+
if (id && error instanceof Error && previousAdmission(error) !== undefined)
|
|
37
|
+
selection.uncertainIds.add(id);
|
|
31
38
|
output.excluded.push({
|
|
32
39
|
position,
|
|
33
40
|
source_finding_id: id,
|
|
@@ -86,6 +93,8 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
86
93
|
smallestProjectionBytes = Math.min(smallestProjectionBytes, projectedBytes);
|
|
87
94
|
}
|
|
88
95
|
catch (error) {
|
|
96
|
+
if (error instanceof Error && previousAdmission(error) !== undefined)
|
|
97
|
+
selection.uncertainIds.add(id);
|
|
89
98
|
singletonErrors.set(observation, errorMessage(error));
|
|
90
99
|
}
|
|
91
100
|
}
|
|
@@ -118,15 +127,7 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
118
127
|
for (const [index, value] of values.entries()) {
|
|
119
128
|
let id = null;
|
|
120
129
|
try {
|
|
121
|
-
const parsed = parseNativeJsonResult(value, "OpenGrep");
|
|
122
|
-
if (parsed.path !== null) {
|
|
123
|
-
// Validate the emitted spelling across platforms, keeping literal POSIX backslashes.
|
|
124
|
-
const path = posix.normalize(parsed.rawPath);
|
|
125
|
-
parsed.path =
|
|
126
|
-
relativePath(posix.normalize(path.replaceAll("\\", "/"))) === null
|
|
127
|
-
? null
|
|
128
|
-
: path;
|
|
129
|
-
}
|
|
130
|
+
const parsed = parseNativeJsonResult(value, "OpenGrep", nativeResultPath);
|
|
130
131
|
// Native fingerprint counters change when another analysis pass adds matches.
|
|
131
132
|
// A source move creates a new occurrence; this is not cross-revision matching.
|
|
132
133
|
id = stableId("opengrep-location", [
|
|
@@ -146,24 +147,37 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
146
147
|
exclude(index + 1, id, error);
|
|
147
148
|
}
|
|
148
149
|
}
|
|
150
|
+
const positions = new Map();
|
|
149
151
|
for (const [id, observations] of [...groups].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
152
|
+
if (observations.length === 1) {
|
|
153
|
+
const { position } = observations[0];
|
|
154
|
+
selection.append(position, id, () => {
|
|
155
|
+
const evidence = projectGroup(observations);
|
|
156
|
+
positions.set(id, [position]);
|
|
157
|
+
return evidence;
|
|
158
|
+
});
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const ordered = observations
|
|
162
|
+
.flatMap((observation) => {
|
|
163
|
+
try {
|
|
164
|
+
const result = structuredClone(observation.parsed.result);
|
|
165
|
+
// The group adds these same raw bytes when choosing a representative
|
|
166
|
+
// and deciding which traces fit alongside it.
|
|
167
|
+
validateExternalEvidenceJson({ source_data: { results: [result] } }, target, 0, (previousBytes, currentBytes) => {
|
|
168
|
+
if (previousBytes !== currentBytes)
|
|
169
|
+
selection.uncertainIds.add(id);
|
|
170
|
+
});
|
|
171
|
+
observation.parsed.result = result;
|
|
172
|
+
return [{ observation, key: canonicalJson(result) }];
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
exclude(observation.position, id, error);
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
})
|
|
179
|
+
.sort((left, right) => left.key < right.key ? -1 : left.key > right.key ? 1 : 0)
|
|
180
|
+
.map(({ observation }) => observation);
|
|
167
181
|
if (!ordered.length)
|
|
168
182
|
continue;
|
|
169
183
|
let retained = ordered;
|
|
@@ -182,7 +196,10 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
182
196
|
throw error;
|
|
183
197
|
evidence = projectGroup(retained);
|
|
184
198
|
}
|
|
199
|
+
if (previousAdmission(evidence) === null)
|
|
200
|
+
selection.uncertainIds.add(id);
|
|
185
201
|
output.findings.push({ source_finding_id: id, evidence });
|
|
202
|
+
positions.set(id, retained.map(({ position }) => position));
|
|
186
203
|
}
|
|
187
204
|
catch (error) {
|
|
188
205
|
for (const observation of retained)
|
|
@@ -190,7 +207,8 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
190
207
|
}
|
|
191
208
|
}
|
|
192
209
|
output.excluded.sort((left, right) => left.position - right.position);
|
|
193
|
-
|
|
210
|
+
sourcePositions.set(output.findings, positions);
|
|
211
|
+
return selection.finish();
|
|
194
212
|
}
|
|
195
213
|
export async function readOpenGrepFindings(path, options, target = "cloud") {
|
|
196
214
|
return normalizeOpenGrepFindings(await readScannerJson(path), options, target);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opengrep-findings.js","sourceRoot":"","sources":["../src/opengrep-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,GAEvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,EACL,eAAe,EACf,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,QAAQ,GACT,MAAM,qBAAqB,CAAC;AAO7B,2EAA2E;AAC3E,MAAM,UAAU,yBAAyB,CACvC,KAAc,EACd,OAA8B,EAC9B,MAAM,GAAyB,OAAO;IAEtC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,E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,CAAC,QAAQ,CAAC,CAAC;YACpC,CAAC;YACD,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,iBAAiB,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC5D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,KAAK,MAAM,WAAW,IAAI,QAAQ;gBAChC,OAAO,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IACD,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IACtE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,IAAY,EACZ,OAA8B,EAC9B,MAAM,GAAyB,OAAO;IAEtC,OAAO,yBAAyB,CAC9B,MAAM,eAAe,CAAC,IAAI,CAAC,EAC3B,OAAO,EACP,MAAM,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { posix } from \"node:path\";\nimport {\n validateExternalEvidenceJson,\n validateExternalReport,\n type ExternalImportTarget,\n} from \"./external-import-contract.js\";\nimport { canonicalJson } from \"./record.js\";\nimport { errorMessage } from \"./errors.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport {\n messageText,\n parseNativeJsonResult,\n projectNativeJsonResult,\n sourceRepositoryUrl,\n} from \"./native-json-findings.js\";\nimport {\n array,\n readScannerJson,\n record,\n relativePath,\n requiredText,\n stableId,\n} from \"./scanner-import.js\";\n\nexport interface OpenGrepImportOptions {\n /** Source repository declared by the caller, independent of the destination. */\n sourceRepositoryUrl: string;\n}\n\n/** Import native scanner evidence without assigning a Codex assessment. */\nexport function normalizeOpenGrepFindings(\n input: unknown,\n options: OpenGrepImportOptions,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const document = record(input, \"OpenGrep report\");\n const repositoryUrl = sourceRepositoryUrl(\n options?.sourceRepositoryUrl,\n \"OpenGrep\",\n );\n const version = requiredText(document[\"version\"], \"OpenGrep version\");\n const { results, ...report } = document;\n const values = array(results, \"OpenGrep results\");\n const errors = array(report[\"errors\"], \"OpenGrep errors\");\n validateExternalReport(report);\n const projection = {\n origin: \"OpenGrep\",\n repositoryUrl,\n severity: () => \"unknown\",\n reportContext: { version },\n target,\n scanErrorCount: errors.length,\n };\n const output: ExternalFindings = {\n read: values.length,\n findings: [],\n excluded: [],\n report: structuredClone(report),\n };\n type Observation = {\n position: number;\n parsed: ReturnType<typeof parseNativeJsonResult>;\n };\n function exclude(position: number, id: string | null, error: unknown) {\n output.excluded.push({\n position,\n source_finding_id: id,\n reason: errorMessage(error),\n });\n }\n function projectGroup(observations: Observation[]) {\n const results = observations.map(({ parsed }) => parsed.result);\n if (results.length === 1)\n return projectNativeJsonResult(observations[0]!.parsed, {\n ...projection,\n observations: results,\n });\n const sourceData = {\n report: { version },\n scan_error_count: errors.length,\n results,\n };\n // Replacing [] with the same raw results adds the same wire bytes to every candidate.\n const rawBytes =\n validateExternalEvidenceJson({ source_data: sourceData }, target) -\n validateExternalEvidenceJson(\n { source_data: { ...sourceData, results: [] } },\n target,\n );\n let projectionError: unknown;\n for (const { parsed } of observations) {\n try {\n const evidence = projectNativeJsonResult(parsed, {\n ...projection,\n observations: [],\n });\n validateExternalEvidenceJson(evidence, target, rawBytes);\n evidence.source_data![\"results\"] = results;\n return evidence;\n } catch (error) {\n projectionError ??= error;\n }\n }\n throw projectionError;\n }\n function retainPublishableTraces(observations: Observation[], id: string) {\n const emptyWrapperBytes = validateExternalEvidenceJson(\n { source_data: { results: [] } },\n target,\n );\n function sizeWithTrace(observation: Observation, evidenceBytes: number) {\n return validateExternalEvidenceJson(\n { source_data: { results: [observation.parsed.result] } },\n target,\n evidenceBytes - emptyWrapperBytes,\n );\n }\n const singletonErrors = new Map<Observation, string>();\n let smallestProjectionBytes = Infinity;\n let coreRawBytes = 0;\n for (const observation of observations) {\n try {\n const evidence = projectNativeJsonResult(observation.parsed, {\n ...projection,\n observations: [],\n });\n const projectedBytes = validateExternalEvidenceJson(evidence, target);\n const singletonBytes = sizeWithTrace(observation, projectedBytes);\n coreRawBytes += singletonBytes - projectedBytes;\n smallestProjectionBytes = Math.min(\n smallestProjectionBytes,\n projectedBytes,\n );\n } catch (error) {\n singletonErrors.set(observation, errorMessage(error));\n }\n }\n if (!singletonErrors.size) return observations;\n // Reserve every independently publishable trace, including the commas in\n // their results array, before trying raw-only traces in canonical order.\n const coreCount = observations.length - singletonErrors.size;\n let groupBytes = smallestProjectionBytes + coreRawBytes + coreCount - 1;\n return observations.filter((observation) => {\n let reason = singletonErrors.get(observation);\n if (reason === undefined) return true;\n if (coreCount) {\n try {\n groupBytes = sizeWithTrace(observation, groupBytes + 1);\n return true;\n } catch (error) {\n const groupReason = errorMessage(error);\n if (groupReason !== reason)\n reason = `${groupReason} This trace also fails standalone validation. ${reason}`;\n }\n }\n exclude(observation.position, id, reason);\n return false;\n });\n }\n const groups = new Map<string, Observation[]>();\n for (const [index, value] of values.entries()) {\n let id: string | null = null;\n try {\n const parsed = parseNativeJsonResult(value, \"OpenGrep\");\n if (parsed.path !== null) {\n // Validate the emitted spelling across platforms, keeping literal POSIX backslashes.\n const path = posix.normalize(parsed.rawPath);\n parsed.path =\n relativePath(posix.normalize(path.replaceAll(\"\\\\\", \"/\"))) === null\n ? null\n : path;\n }\n // Native fingerprint counters change when another analysis pass adds matches.\n // A source move creates a new occurrence; this is not cross-revision matching.\n id = stableId(\"opengrep-location\", [\n parsed.rule,\n parsed.path ?? parsed.rawPath,\n parsed.line,\n parsed.column,\n parsed.endLine,\n parsed.endColumn,\n ]);\n messageText(parsed.extra[\"message\"], \"OpenGrep\");\n const group = groups.get(id) ?? [];\n group.push({ position: index + 1, parsed });\n groups.set(id, group);\n } catch (error) {\n exclude(index + 1, id, error);\n }\n }\n for (const [id, observations] of [...groups].sort(([left], [right]) =>\n left < right ? -1 : left > right ? 1 : 0,\n )) {\n const ordered =\n observations.length === 1\n ? observations\n : observations\n .flatMap((observation) => {\n try {\n const result = structuredClone(observation.parsed.result);\n validateExternalEvidenceJson(\n { source_data: { results: [result] } },\n target,\n );\n observation.parsed.result = result;\n return [{ observation, key: canonicalJson(result) }];\n } catch (error) {\n exclude(observation.position, id, error);\n return [];\n }\n })\n .sort((left, right) =>\n left.key < right.key ? -1 : left.key > right.key ? 1 : 0,\n )\n .map(({ observation }) => observation);\n if (!ordered.length) continue;\n let retained = ordered;\n try {\n let evidence;\n try {\n evidence = projectGroup(retained);\n } catch (error) {\n if (retained.length === 1) throw error;\n retained = retainPublishableTraces(retained, id);\n if (!retained.length) continue;\n if (retained.length === ordered.length) throw error;\n evidence = projectGroup(retained);\n }\n output.findings.push({ source_finding_id: id, evidence });\n } catch (error) {\n for (const observation of retained)\n exclude(observation.position, id, error);\n }\n }\n output.excluded.sort((left, right) => left.position - right.position);\n return output;\n}\n\nexport async function readOpenGrepFindings(\n path: string,\n options: OpenGrepImportOptions,\n target: ExternalImportTarget = \"cloud\",\n): Promise<ExternalFindings> {\n return normalizeOpenGrepFindings(\n await readScannerJson(path),\n options,\n target,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"opengrep-findings.js","sourceRoot":"","sources":["../src/opengrep-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,4BAA4B,EAC5B,sBAAsB,GAEvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,oBAAoB,EACpB,KAAK,EACL,eAAe,EACf,MAAM,EACN,YAAY,EACZ,QAAQ,GAC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,SAAS,CAAC,GAAG,CACX,EAAE,EACF,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,CACzC,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,KAAK,MAAM,WAAW,IAAI,QAAQ;gBAChC,OAAO,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IACD,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IACtE,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAChD,OAAO,SAAS,CAAC,MAAM,EAAE,CAAC;AAC5B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,IAAY,EACZ,OAA8B,EAC9B,MAAM,GAAyB,OAAO;IAEtC,OAAO,yBAAyB,CAC9B,MAAM,eAAe,CAAC,IAAI,CAAC,EAC3B,OAAO,EACP,MAAM,CACP,CAAC;AACJ,CAAC","sourcesContent":["import {\n previousAdmission,\n validateExternalEvidenceJson,\n validateExternalReport,\n type ExternalImportTarget,\n} from \"./external-import-contract.js\";\nimport { canonicalJson } from \"./record.js\";\nimport { errorMessage } from \"./errors.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport {\n messageText,\n nativeResultPath,\n parseNativeJsonResult,\n projectNativeJsonResult,\n sourceRepositoryUrl,\n} from \"./native-json-findings.js\";\nimport {\n trackReaderSelection,\n array,\n readScannerJson,\n record,\n requiredText,\n stableId,\n} from \"./scanner-import.js\";\n\nexport interface OpenGrepImportOptions {\n /** Source repository declared by the caller, independent of the destination. */\n sourceRepositoryUrl: string;\n}\n\n// Occurrences are sorted by ID and can retain traces from nonadjacent input rows.\nconst sourcePositions = new WeakMap<\n ExternalFindings[\"findings\"],\n ReadonlyMap<string, readonly number[]>\n>();\n\nexport function getOpenGrepSourcePositions(findings: unknown) {\n return Array.isArray(findings) ? sourcePositions.get(findings) : undefined;\n}\n\n/** Import native scanner evidence without assigning a Codex assessment. */\nexport function normalizeOpenGrepFindings(\n input: unknown,\n options: OpenGrepImportOptions,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const document = record(input, \"OpenGrep report\");\n const repositoryUrl = sourceRepositoryUrl(\n options?.sourceRepositoryUrl,\n \"OpenGrep\",\n );\n const version = requiredText(document[\"version\"], \"OpenGrep version\");\n const { results, ...report } = document;\n const values = array(results, \"OpenGrep results\");\n const errors = array(report[\"errors\"], \"OpenGrep errors\");\n validateExternalReport(report);\n const projection = {\n origin: \"OpenGrep\",\n repositoryUrl,\n severity: () => \"unknown\",\n reportContext: { version },\n target,\n scanErrorCount: errors.length,\n };\n const output: ExternalFindings = {\n read: values.length,\n findings: [],\n excluded: [],\n report: structuredClone(report),\n };\n const selection = trackReaderSelection(output);\n type Observation = {\n position: number;\n parsed: ReturnType<typeof parseNativeJsonResult>;\n };\n function exclude(position: number, id: string | null, error: unknown) {\n if (id && error instanceof Error && previousAdmission(error) !== undefined)\n selection.uncertainIds.add(id);\n output.excluded.push({\n position,\n source_finding_id: id,\n reason: errorMessage(error),\n });\n }\n function projectGroup(observations: Observation[]) {\n const results = observations.map(({ parsed }) => parsed.result);\n if (results.length === 1)\n return projectNativeJsonResult(observations[0]!.parsed, {\n ...projection,\n observations: results,\n });\n const sourceData = {\n report: { version },\n scan_error_count: errors.length,\n results,\n };\n // Replacing [] with the same raw results adds the same wire bytes to every candidate.\n const rawBytes =\n validateExternalEvidenceJson({ source_data: sourceData }, target) -\n validateExternalEvidenceJson(\n { source_data: { ...sourceData, results: [] } },\n target,\n );\n let projectionError: unknown;\n for (const { parsed } of observations) {\n try {\n const evidence = projectNativeJsonResult(parsed, {\n ...projection,\n observations: [],\n });\n validateExternalEvidenceJson(evidence, target, rawBytes);\n evidence.source_data![\"results\"] = results;\n return evidence;\n } catch (error) {\n projectionError ??= error;\n }\n }\n throw projectionError;\n }\n function retainPublishableTraces(observations: Observation[], id: string) {\n const emptyWrapperBytes = validateExternalEvidenceJson(\n { source_data: { results: [] } },\n target,\n );\n function sizeWithTrace(observation: Observation, evidenceBytes: number) {\n return validateExternalEvidenceJson(\n { source_data: { results: [observation.parsed.result] } },\n target,\n evidenceBytes - emptyWrapperBytes,\n );\n }\n const singletonErrors = new Map<Observation, string>();\n let smallestProjectionBytes = Infinity;\n let coreRawBytes = 0;\n for (const observation of observations) {\n try {\n const evidence = projectNativeJsonResult(observation.parsed, {\n ...projection,\n observations: [],\n });\n const projectedBytes = validateExternalEvidenceJson(evidence, target);\n const singletonBytes = sizeWithTrace(observation, projectedBytes);\n coreRawBytes += singletonBytes - projectedBytes;\n smallestProjectionBytes = Math.min(\n smallestProjectionBytes,\n projectedBytes,\n );\n } catch (error) {\n if (error instanceof Error && previousAdmission(error) !== undefined)\n selection.uncertainIds.add(id);\n singletonErrors.set(observation, errorMessage(error));\n }\n }\n if (!singletonErrors.size) return observations;\n // Reserve every independently publishable trace, including the commas in\n // their results array, before trying raw-only traces in canonical order.\n const coreCount = observations.length - singletonErrors.size;\n let groupBytes = smallestProjectionBytes + coreRawBytes + coreCount - 1;\n return observations.filter((observation) => {\n let reason = singletonErrors.get(observation);\n if (reason === undefined) return true;\n if (coreCount) {\n try {\n groupBytes = sizeWithTrace(observation, groupBytes + 1);\n return true;\n } catch (error) {\n const groupReason = errorMessage(error);\n if (groupReason !== reason)\n reason = `${groupReason} This trace also fails standalone validation. ${reason}`;\n }\n }\n exclude(observation.position, id, reason);\n return false;\n });\n }\n const groups = new Map<string, Observation[]>();\n for (const [index, value] of values.entries()) {\n let id: string | null = null;\n try {\n const parsed = parseNativeJsonResult(value, \"OpenGrep\", nativeResultPath);\n // Native fingerprint counters change when another analysis pass adds matches.\n // A source move creates a new occurrence; this is not cross-revision matching.\n id = stableId(\"opengrep-location\", [\n parsed.rule,\n parsed.path ?? parsed.rawPath,\n parsed.line,\n parsed.column,\n parsed.endLine,\n parsed.endColumn,\n ]);\n messageText(parsed.extra[\"message\"], \"OpenGrep\");\n const group = groups.get(id) ?? [];\n group.push({ position: index + 1, parsed });\n groups.set(id, group);\n } catch (error) {\n exclude(index + 1, id, error);\n }\n }\n const positions = new Map<string, number[]>();\n for (const [id, observations] of [...groups].sort(([left], [right]) =>\n left < right ? -1 : left > right ? 1 : 0,\n )) {\n if (observations.length === 1) {\n const { position } = observations[0]!;\n selection.append(position, id, () => {\n const evidence = projectGroup(observations);\n positions.set(id, [position]);\n return evidence;\n });\n continue;\n }\n const ordered = observations\n .flatMap((observation) => {\n try {\n const result = structuredClone(observation.parsed.result);\n // The group adds these same raw bytes when choosing a representative\n // and deciding which traces fit alongside it.\n validateExternalEvidenceJson(\n { source_data: { results: [result] } },\n target,\n 0,\n (previousBytes, currentBytes) => {\n if (previousBytes !== currentBytes)\n selection.uncertainIds.add(id);\n },\n );\n observation.parsed.result = result;\n return [{ observation, key: canonicalJson(result) }];\n } catch (error) {\n exclude(observation.position, id, error);\n return [];\n }\n })\n .sort((left, right) =>\n left.key < right.key ? -1 : left.key > right.key ? 1 : 0,\n )\n .map(({ observation }) => observation);\n if (!ordered.length) continue;\n let retained = ordered;\n try {\n let evidence;\n try {\n evidence = projectGroup(retained);\n } catch (error) {\n if (retained.length === 1) throw error;\n retained = retainPublishableTraces(retained, id);\n if (!retained.length) continue;\n if (retained.length === ordered.length) throw error;\n evidence = projectGroup(retained);\n }\n if (previousAdmission(evidence) === null) selection.uncertainIds.add(id);\n output.findings.push({ source_finding_id: id, evidence });\n positions.set(\n id,\n retained.map(({ position }) => position),\n );\n } catch (error) {\n for (const observation of retained)\n exclude(observation.position, id, error);\n }\n }\n output.excluded.sort((left, right) => left.position - right.position);\n sourcePositions.set(output.findings, positions);\n return selection.finish();\n}\n\nexport async function readOpenGrepFindings(\n path: string,\n options: OpenGrepImportOptions,\n target: ExternalImportTarget = \"cloud\",\n): Promise<ExternalFindings> {\n return normalizeOpenGrepFindings(\n await readScannerJson(path),\n options,\n target,\n );\n}\n"]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { ScanUsageMeasurement } from "./cost.js";
|
|
2
|
+
export type OperationOutcome = "completed" | "failed" | "canceled" | "unresolved";
|
|
3
|
+
export type OperationFailureCategory = "configuration" | "authentication" | "input" | "budget" | "execution" | "canceled";
|
|
4
|
+
/** Content-free operational receipts. IDs are for joins, never metric labels. */
|
|
5
|
+
export interface OperationTelemetryEvent {
|
|
6
|
+
schemaVersion: 1;
|
|
7
|
+
eventId: string;
|
|
8
|
+
operationId: string;
|
|
9
|
+
attemptId: string;
|
|
10
|
+
parentAttemptId?: string;
|
|
11
|
+
/** Resumed scans share a cumulative measurement scope; never sum those receipts. */
|
|
12
|
+
usageScopeId: string;
|
|
13
|
+
occurredAt: string;
|
|
14
|
+
observedAt: string;
|
|
15
|
+
type: "attempt_started" | "attempt_finished";
|
|
16
|
+
command: "scan" | "patch" | "validate" | "policy" | "verify-fix" | "assess-patch-risk";
|
|
17
|
+
surface: "cli" | "sdk";
|
|
18
|
+
packageVersion: string;
|
|
19
|
+
mode?: "standard" | "deep";
|
|
20
|
+
resumed: boolean;
|
|
21
|
+
/** True when this call returned a saved result without starting new work. */
|
|
22
|
+
reusedResult?: boolean;
|
|
23
|
+
outcome?: OperationOutcome;
|
|
24
|
+
failureCategory?: OperationFailureCategory;
|
|
25
|
+
durationMs?: number;
|
|
26
|
+
measurement?: Readonly<ScanUsageMeasurement>;
|
|
27
|
+
findingCount?: number;
|
|
28
|
+
reviewedSurfaceCount?: number;
|
|
29
|
+
deferredCount?: number;
|
|
30
|
+
pluginVersion?: string;
|
|
31
|
+
providerFamily?: string;
|
|
32
|
+
validationDisposition?: "reportable" | "suppressed" | "not_applicable" | "deferred";
|
|
33
|
+
artifactComplete?: boolean;
|
|
34
|
+
collection: {
|
|
35
|
+
persisted: number;
|
|
36
|
+
writeFailures: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
interface OperationTelemetryOptions {
|
|
40
|
+
directory: string;
|
|
41
|
+
protectedRepository?: string;
|
|
42
|
+
protectedOutput?: string;
|
|
43
|
+
command: OperationTelemetryEvent["command"];
|
|
44
|
+
surface: OperationTelemetryEvent["surface"];
|
|
45
|
+
mode?: OperationTelemetryEvent["mode"];
|
|
46
|
+
resumeScanId?: string;
|
|
47
|
+
deferPersistence?: boolean;
|
|
48
|
+
context?: {
|
|
49
|
+
operationId: string;
|
|
50
|
+
parentAttemptId?: string;
|
|
51
|
+
};
|
|
52
|
+
onEvent?: (event: Readonly<OperationTelemetryEvent>) => void;
|
|
53
|
+
onError?: (error: unknown) => void;
|
|
54
|
+
}
|
|
55
|
+
/** Local journal only. Export, acknowledgement and retention belong to the host. */
|
|
56
|
+
export declare class OperationTelemetry {
|
|
57
|
+
#private;
|
|
58
|
+
readonly attemptId: `${string}-${string}-${string}-${string}-${string}`;
|
|
59
|
+
operationId: string;
|
|
60
|
+
measurement: Readonly<ScanUsageMeasurement> | undefined;
|
|
61
|
+
reusedResult: boolean;
|
|
62
|
+
nativeTurnFailed: boolean;
|
|
63
|
+
constructor(options: OperationTelemetryOptions);
|
|
64
|
+
get context(): {
|
|
65
|
+
operationId: string;
|
|
66
|
+
attemptId: `${string}-${string}-${string}-${string}-${string}`;
|
|
67
|
+
parentAttemptId?: string | undefined;
|
|
68
|
+
};
|
|
69
|
+
start(): Promise<void>;
|
|
70
|
+
/** Callers establish repository and artifact protection before any writes. */
|
|
71
|
+
activatePersistence(protectedRoots: readonly string[], savedOutput?: string): Promise<void>;
|
|
72
|
+
bindScan(scanId: string): Promise<void>;
|
|
73
|
+
describe(runtime: Pick<OperationTelemetryEvent, "pluginVersion" | "providerFamily">): void;
|
|
74
|
+
finish(outcome: OperationOutcome, details?: Pick<OperationTelemetryEvent, "failureCategory" | "findingCount" | "artifactComplete" | "reviewedSurfaceCount" | "deferredCount" | "validationDisposition">): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
/** Read durable receipts, retaining explicit evidence of truncated/corrupt records. */
|
|
77
|
+
export declare function readOperationTelemetry(stateDirectory: string): Promise<{
|
|
78
|
+
events: OperationTelemetryEvent[];
|
|
79
|
+
parseFailures: number;
|
|
80
|
+
}>;
|
|
81
|
+
/** Attempts without a terminal receipt remain unresolved, including process loss. */
|
|
82
|
+
export declare function summarizeOperationTelemetry(events: readonly OperationTelemetryEvent[]): {
|
|
83
|
+
operations: number;
|
|
84
|
+
successfulOperations: number;
|
|
85
|
+
attempts: number;
|
|
86
|
+
outcomes: {
|
|
87
|
+
completed: number;
|
|
88
|
+
failed: number;
|
|
89
|
+
canceled: number;
|
|
90
|
+
unresolved: number;
|
|
91
|
+
};
|
|
92
|
+
usageCoverage: {
|
|
93
|
+
complete: number;
|
|
94
|
+
partial: number;
|
|
95
|
+
unavailable: number;
|
|
96
|
+
};
|
|
97
|
+
durationMs: number[];
|
|
98
|
+
observedCostUsd: number;
|
|
99
|
+
pricedAttempts: number;
|
|
100
|
+
reusedAttempts: number;
|
|
101
|
+
duplicates: number;
|
|
102
|
+
};
|
|
103
|
+
export {};
|
|
104
|
+
//# sourceMappingURL=operation-telemetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-telemetry.d.ts","sourceRoot":"","sources":["../src/operation-telemetry.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAStD,MAAM,MAAM,gBAAgB,GAC1B,WAAW,GAAG,QAAQ,GAAG,UAAU,GAAG,YAAY,CAAC;AACrD,MAAM,MAAM,wBAAwB,GAChC,eAAe,GACf,gBAAgB,GAChB,OAAO,GACP,QAAQ,GACR,WAAW,GACX,UAAU,CAAC;AAEf,iFAAiF;AACjF,MAAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,CAAC,CAAC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uBAAuB,EACrB,iBAAiB,GACjB,cAAc,GACd,kBAAkB,GAClB,sBAAsB,GACtB,eAAe,GACf,uBAAuB,CACrB,GACL,OAAO,CAAC,IAAI,CAAC,CAoBf;CAwEF;AAED,uFAAuF;AACvF,wBAAsB,sBAAsB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5E,MAAM,EAAE,uBAAuB,EAAE,CAAC;IAClC,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC,CAyCD;AAED,qFAAqF;AACrF,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,SAAS,uBAAuB,EAAE;;;;;;;;;;;;;;;;;;;;EA4D3C"}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { appendFile, mkdir, readFile, readdir, writeFile, } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { canonicalConfigPath, requireOutputOutsideRepositories, requireSecureOutputAncestry, } from "./runtime.js";
|
|
5
|
+
import { gitProtectionRoots } from "./targets.js";
|
|
6
|
+
import { VERSION } from "./version.js";
|
|
7
|
+
/** Local journal only. Export, acknowledgement and retention belong to the host. */
|
|
8
|
+
export class OperationTelemetry {
|
|
9
|
+
attemptId = randomUUID();
|
|
10
|
+
operationId;
|
|
11
|
+
measurement;
|
|
12
|
+
reusedResult = false;
|
|
13
|
+
nativeTurnFailed = false;
|
|
14
|
+
#started = performance.now();
|
|
15
|
+
#startedAt = new Date().toISOString();
|
|
16
|
+
#options;
|
|
17
|
+
#directory;
|
|
18
|
+
#persisted = 0;
|
|
19
|
+
#writeFailures = 0;
|
|
20
|
+
#ready = false;
|
|
21
|
+
#runtime = {};
|
|
22
|
+
#finished = false;
|
|
23
|
+
#usageScopeId = this.attemptId;
|
|
24
|
+
#deferred;
|
|
25
|
+
#startedEvent;
|
|
26
|
+
constructor(options) {
|
|
27
|
+
this.#options = options;
|
|
28
|
+
this.operationId = options.context?.operationId ?? randomUUID();
|
|
29
|
+
this.#directory = join(options.directory, "telemetry");
|
|
30
|
+
this.#deferred = options.deferPersistence === true;
|
|
31
|
+
}
|
|
32
|
+
get context() {
|
|
33
|
+
return {
|
|
34
|
+
operationId: this.operationId,
|
|
35
|
+
attemptId: this.attemptId,
|
|
36
|
+
...(this.#options.context?.parentAttemptId === undefined
|
|
37
|
+
? {}
|
|
38
|
+
: { parentAttemptId: this.#options.context.parentAttemptId }),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async start() {
|
|
42
|
+
if (!this.#deferred)
|
|
43
|
+
await this.#preparePersistence();
|
|
44
|
+
await this.#emit("attempt_started");
|
|
45
|
+
}
|
|
46
|
+
/** Callers establish repository and artifact protection before any writes. */
|
|
47
|
+
async activatePersistence(protectedRoots, savedOutput) {
|
|
48
|
+
if (!this.#deferred || this.#finished)
|
|
49
|
+
return;
|
|
50
|
+
this.#deferred = false;
|
|
51
|
+
await this.#preparePersistence(protectedRoots, savedOutput);
|
|
52
|
+
if (this.#startedEvent !== undefined) {
|
|
53
|
+
const event = {
|
|
54
|
+
...this.#startedEvent,
|
|
55
|
+
...this.context,
|
|
56
|
+
usageScopeId: this.#usageScopeId,
|
|
57
|
+
collection: {
|
|
58
|
+
persisted: this.#persisted + (this.#ready ? 1 : 0),
|
|
59
|
+
writeFailures: this.#writeFailures,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
if (this.#ready)
|
|
63
|
+
await this.#persist(event);
|
|
64
|
+
if (this.#options.resumeScanId !== undefined)
|
|
65
|
+
this.#notify(event);
|
|
66
|
+
}
|
|
67
|
+
this.#startedEvent = undefined;
|
|
68
|
+
}
|
|
69
|
+
async #preparePersistence(additionalRoots = [], savedOutput) {
|
|
70
|
+
try {
|
|
71
|
+
const protectedRoots = [...additionalRoots];
|
|
72
|
+
for (const output of [this.#options.protectedOutput, savedOutput]) {
|
|
73
|
+
if (output !== undefined)
|
|
74
|
+
protectedRoots.push(await canonicalConfigPath(output));
|
|
75
|
+
}
|
|
76
|
+
if (this.#options.protectedRepository !== undefined) {
|
|
77
|
+
const repository = await canonicalConfigPath(this.#options.protectedRepository);
|
|
78
|
+
protectedRoots.push(repository, ...(await gitProtectionRoots(this.#options.protectedRepository)));
|
|
79
|
+
}
|
|
80
|
+
if (protectedRoots.length > 0) {
|
|
81
|
+
requireOutputOutsideRepositories(protectedRoots, await canonicalConfigPath(this.#directory), "runtime");
|
|
82
|
+
}
|
|
83
|
+
await requireSecureOutputAncestry(this.#directory);
|
|
84
|
+
await mkdir(this.#directory, { recursive: true, mode: 0o700 });
|
|
85
|
+
this.#ready = true;
|
|
86
|
+
if (this.#options.resumeScanId !== undefined) {
|
|
87
|
+
try {
|
|
88
|
+
const saved = JSON.parse(await readFile(this.#bindingPath(this.#options.resumeScanId), "utf8"));
|
|
89
|
+
this.operationId = saved.operationId;
|
|
90
|
+
this.#usageScopeId = saved.usageScopeId;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (error.code !== "ENOENT")
|
|
94
|
+
this.#error(error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
this.#error(error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async bindScan(scanId) {
|
|
103
|
+
if (!this.#ready)
|
|
104
|
+
return;
|
|
105
|
+
try {
|
|
106
|
+
await writeFile(this.#bindingPath(scanId), JSON.stringify({
|
|
107
|
+
...this.context,
|
|
108
|
+
usageScopeId: this.#usageScopeId,
|
|
109
|
+
}), {
|
|
110
|
+
mode: 0o600,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
this.#error(error);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
describe(runtime) {
|
|
118
|
+
this.#runtime = runtime;
|
|
119
|
+
}
|
|
120
|
+
async finish(outcome, details = {}) {
|
|
121
|
+
if (this.#finished)
|
|
122
|
+
return;
|
|
123
|
+
this.#finished = true;
|
|
124
|
+
if (this.#startedEvent !== undefined &&
|
|
125
|
+
this.#options.resumeScanId !== undefined) {
|
|
126
|
+
this.#notify(this.#startedEvent);
|
|
127
|
+
this.#startedEvent = undefined;
|
|
128
|
+
}
|
|
129
|
+
await this.#emit("attempt_finished", {
|
|
130
|
+
outcome,
|
|
131
|
+
reusedResult: this.reusedResult,
|
|
132
|
+
durationMs: Math.max(0, performance.now() - this.#started),
|
|
133
|
+
...(this.measurement === undefined
|
|
134
|
+
? {}
|
|
135
|
+
: { measurement: this.measurement }),
|
|
136
|
+
...this.#runtime,
|
|
137
|
+
...details,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
#bindingPath(scanId) {
|
|
141
|
+
return join(this.#directory, `${createHash("sha256").update(scanId).digest("hex")}.binding.json`);
|
|
142
|
+
}
|
|
143
|
+
#error(error) {
|
|
144
|
+
this.#writeFailures++;
|
|
145
|
+
try {
|
|
146
|
+
this.#options.onError?.(error);
|
|
147
|
+
}
|
|
148
|
+
catch { }
|
|
149
|
+
}
|
|
150
|
+
async #persist(event) {
|
|
151
|
+
try {
|
|
152
|
+
await appendFile(join(this.#directory, `${this.attemptId}.jsonl`), `${JSON.stringify(event)}\n`, { mode: 0o600 });
|
|
153
|
+
this.#persisted++;
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
this.#error(error);
|
|
157
|
+
event.collection = {
|
|
158
|
+
persisted: this.#persisted,
|
|
159
|
+
writeFailures: this.#writeFailures,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async #emit(type, details = {}) {
|
|
164
|
+
const time = new Date().toISOString();
|
|
165
|
+
const event = {
|
|
166
|
+
schemaVersion: 1,
|
|
167
|
+
eventId: `${this.attemptId}:${type}`,
|
|
168
|
+
...this.context,
|
|
169
|
+
usageScopeId: this.#usageScopeId,
|
|
170
|
+
occurredAt: type === "attempt_started" ? this.#startedAt : time,
|
|
171
|
+
observedAt: time,
|
|
172
|
+
type,
|
|
173
|
+
command: this.#options.command,
|
|
174
|
+
surface: this.#options.surface,
|
|
175
|
+
packageVersion: VERSION,
|
|
176
|
+
...(this.#options.mode === undefined ? {} : { mode: this.#options.mode }),
|
|
177
|
+
resumed: this.#options.resumeScanId !== undefined,
|
|
178
|
+
...details,
|
|
179
|
+
collection: {
|
|
180
|
+
persisted: this.#persisted + (this.#ready ? 1 : 0),
|
|
181
|
+
writeFailures: this.#writeFailures,
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
if (this.#ready)
|
|
185
|
+
await this.#persist(event);
|
|
186
|
+
else if (this.#deferred && type === "attempt_started") {
|
|
187
|
+
this.#startedEvent = event;
|
|
188
|
+
// Resume identity is restored only after the caller protects output paths.
|
|
189
|
+
if (this.#options.resumeScanId !== undefined)
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
this.#notify(event);
|
|
193
|
+
}
|
|
194
|
+
#notify(event) {
|
|
195
|
+
// Observers cannot delay or fail the operation. Replay uses the same event ID.
|
|
196
|
+
void Promise.resolve()
|
|
197
|
+
.then(() => this.#options.onEvent?.(event))
|
|
198
|
+
.catch(() => { });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/** Read durable receipts, retaining explicit evidence of truncated/corrupt records. */
|
|
202
|
+
export async function readOperationTelemetry(stateDirectory) {
|
|
203
|
+
const directory = join(stateDirectory, "telemetry");
|
|
204
|
+
const events = [];
|
|
205
|
+
let parseFailures = 0;
|
|
206
|
+
const names = await readdir(directory).catch((error) => {
|
|
207
|
+
if (error.code === "ENOENT")
|
|
208
|
+
return [];
|
|
209
|
+
throw error;
|
|
210
|
+
});
|
|
211
|
+
for (const name of names.filter((name) => name.endsWith(".jsonl")).sort()) {
|
|
212
|
+
for (const line of (await readFile(join(directory, name), "utf8")).split("\n")) {
|
|
213
|
+
if (!line)
|
|
214
|
+
continue;
|
|
215
|
+
try {
|
|
216
|
+
const event = JSON.parse(line);
|
|
217
|
+
if (event.schemaVersion !== 1 ||
|
|
218
|
+
typeof event.eventId !== "string" ||
|
|
219
|
+
typeof event.attemptId !== "string" ||
|
|
220
|
+
typeof event.operationId !== "string" ||
|
|
221
|
+
typeof event.usageScopeId !== "string" ||
|
|
222
|
+
!["attempt_started", "attempt_finished"].includes(event.type) ||
|
|
223
|
+
((event.type === "attempt_finished" || event.outcome !== undefined) &&
|
|
224
|
+
!["completed", "failed", "canceled", "unresolved"].includes(event.outcome ?? "")) ||
|
|
225
|
+
(event.measurement !== undefined &&
|
|
226
|
+
!["complete", "partial", "unavailable"].includes(event.measurement?.coverage))) {
|
|
227
|
+
parseFailures++;
|
|
228
|
+
}
|
|
229
|
+
else
|
|
230
|
+
events.push(event);
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
parseFailures++;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return { events, parseFailures };
|
|
238
|
+
}
|
|
239
|
+
/** Attempts without a terminal receipt remain unresolved, including process loss. */
|
|
240
|
+
export function summarizeOperationTelemetry(events) {
|
|
241
|
+
const seen = new Set();
|
|
242
|
+
const attempts = new Map();
|
|
243
|
+
let duplicates = 0;
|
|
244
|
+
for (const event of events) {
|
|
245
|
+
if (seen.has(event.eventId)) {
|
|
246
|
+
duplicates++;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
seen.add(event.eventId);
|
|
250
|
+
const previous = attempts.get(event.attemptId);
|
|
251
|
+
if (previous?.type !== "attempt_finished" ||
|
|
252
|
+
event.type === "attempt_finished")
|
|
253
|
+
attempts.set(event.attemptId, event);
|
|
254
|
+
}
|
|
255
|
+
const operations = new Map();
|
|
256
|
+
const outcomes = { completed: 0, failed: 0, canceled: 0, unresolved: 0 };
|
|
257
|
+
const usageCoverage = { complete: 0, partial: 0, unavailable: 0 };
|
|
258
|
+
const durationMs = [];
|
|
259
|
+
let observedCostUsd = 0;
|
|
260
|
+
let pricedAttempts = 0;
|
|
261
|
+
let reusedAttempts = 0;
|
|
262
|
+
const costsByScope = new Map();
|
|
263
|
+
for (const event of attempts.values()) {
|
|
264
|
+
operations.set(event.operationId, operations.get(event.operationId) === true ||
|
|
265
|
+
event.outcome === "completed");
|
|
266
|
+
outcomes[event.outcome ?? "unresolved"]++;
|
|
267
|
+
if (event.reusedResult === true)
|
|
268
|
+
reusedAttempts++;
|
|
269
|
+
else
|
|
270
|
+
usageCoverage[event.measurement?.coverage ?? "unavailable"]++;
|
|
271
|
+
if (event.durationMs !== undefined)
|
|
272
|
+
durationMs.push(event.durationMs);
|
|
273
|
+
if (event.measurement?.cost != null) {
|
|
274
|
+
costsByScope.set(event.usageScopeId, Math.max(costsByScope.get(event.usageScopeId) ?? 0, event.measurement.cost.estimatedUsd));
|
|
275
|
+
pricedAttempts++;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
for (const cost of costsByScope.values())
|
|
279
|
+
observedCostUsd += cost;
|
|
280
|
+
return {
|
|
281
|
+
operations: operations.size,
|
|
282
|
+
successfulOperations: [...operations.values()].filter(Boolean).length,
|
|
283
|
+
attempts: attempts.size,
|
|
284
|
+
outcomes,
|
|
285
|
+
usageCoverage,
|
|
286
|
+
durationMs,
|
|
287
|
+
observedCostUsd,
|
|
288
|
+
pricedAttempts,
|
|
289
|
+
reusedAttempts,
|
|
290
|
+
duplicates,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=operation-telemetry.js.map
|