@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
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { canonicalJson } from "./record.js";
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import { validateExternalEvidenceJson, validateExternalReport, } from "./external-import-contract.js";
|
|
3
|
+
import { canonicalJson, isRecord } from "./record.js";
|
|
4
4
|
import { errorMessage } from "./errors.js";
|
|
5
|
-
import { messageText, parseNativeJsonResult, projectNativeJsonResult, sourceRepositoryUrl, } from "./native-json-findings.js";
|
|
6
|
-
import {
|
|
5
|
+
import { messageText, nativeResultPath, parseNativeJsonResult, projectNativeJsonResult, sourceRepositoryUrl, } from "./native-json-findings.js";
|
|
6
|
+
import { appendFinding, array, scannerJsonReader, record, requiredText, stableId, } from "./scanner-import.js";
|
|
7
|
+
// Occurrences are sorted by ID and can retain traces from nonadjacent input rows.
|
|
8
|
+
const sourcePositions = new WeakMap();
|
|
9
|
+
export function getOpenGrepSourcePositions(findings) {
|
|
10
|
+
return Array.isArray(findings) ? sourcePositions.get(findings) : undefined;
|
|
11
|
+
}
|
|
7
12
|
/** Import native scanner evidence without assigning a Codex assessment. */
|
|
8
13
|
export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
9
14
|
const document = record(input, "OpenGrep report");
|
|
@@ -13,24 +18,49 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
13
18
|
const values = array(results, "OpenGrep results");
|
|
14
19
|
const errors = array(report["errors"], "OpenGrep errors");
|
|
15
20
|
validateExternalReport(report);
|
|
21
|
+
return projectOpenGrepResults(values, repositoryUrl, version, errors.length, target, report);
|
|
22
|
+
}
|
|
23
|
+
/** Reproject a retained native occurrence without changing SDK- or agent-authored evidence. */
|
|
24
|
+
export function projectStoredOpenGrepFinding(finding) {
|
|
25
|
+
const { evidence } = finding;
|
|
26
|
+
const native = evidence.source_data;
|
|
27
|
+
const traces = native?.["results"];
|
|
28
|
+
const context = native?.["report"];
|
|
29
|
+
const version = isRecord(context) && context["version"];
|
|
30
|
+
const count = native?.["scan_error_count"];
|
|
31
|
+
const repositoryUrl = evidence.details?.repository?.url;
|
|
32
|
+
if (evidence.details?.scanner_origin !== "OpenGrep" ||
|
|
33
|
+
!repositoryUrl ||
|
|
34
|
+
!Array.isArray(traces) ||
|
|
35
|
+
typeof version !== "string" ||
|
|
36
|
+
typeof count !== "number" ||
|
|
37
|
+
!Number.isSafeInteger(count) ||
|
|
38
|
+
count < 0)
|
|
39
|
+
return undefined;
|
|
40
|
+
const project = (target) => projectOpenGrepResults(traces, repositoryUrl, version, count, target);
|
|
41
|
+
const local = project("local");
|
|
42
|
+
if (local.findings.length !== 1 ||
|
|
43
|
+
local.excluded.length ||
|
|
44
|
+
!isDeepStrictEqual(local.findings[0], finding))
|
|
45
|
+
return undefined;
|
|
46
|
+
return project("cloud");
|
|
47
|
+
}
|
|
48
|
+
function projectOpenGrepResults(values, repositoryUrl, version, scanErrorCount, target, report) {
|
|
16
49
|
const projection = {
|
|
17
50
|
origin: "OpenGrep",
|
|
18
51
|
repositoryUrl,
|
|
19
52
|
severity: () => "unknown",
|
|
20
53
|
reportContext: { version },
|
|
21
54
|
target,
|
|
22
|
-
scanErrorCount
|
|
55
|
+
scanErrorCount,
|
|
23
56
|
};
|
|
24
57
|
const output = {
|
|
25
58
|
read: values.length,
|
|
26
59
|
findings: [],
|
|
27
60
|
excluded: [],
|
|
28
|
-
report: structuredClone(report),
|
|
61
|
+
...(report && { report: structuredClone(report) }),
|
|
29
62
|
};
|
|
30
|
-
const selection = trackReaderSelection(output);
|
|
31
63
|
function exclude(position, id, error) {
|
|
32
|
-
if (id && error instanceof Error && previousAdmission(error) !== undefined)
|
|
33
|
-
selection.uncertainIds.add(id);
|
|
34
64
|
output.excluded.push({
|
|
35
65
|
position,
|
|
36
66
|
source_finding_id: id,
|
|
@@ -46,7 +76,7 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
46
76
|
});
|
|
47
77
|
const sourceData = {
|
|
48
78
|
report: { version },
|
|
49
|
-
scan_error_count:
|
|
79
|
+
scan_error_count: scanErrorCount,
|
|
50
80
|
results,
|
|
51
81
|
};
|
|
52
82
|
// Replacing [] with the same raw results adds the same wire bytes to every candidate.
|
|
@@ -89,8 +119,6 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
89
119
|
smallestProjectionBytes = Math.min(smallestProjectionBytes, projectedBytes);
|
|
90
120
|
}
|
|
91
121
|
catch (error) {
|
|
92
|
-
if (error instanceof Error && previousAdmission(error) !== undefined)
|
|
93
|
-
selection.uncertainIds.add(id);
|
|
94
122
|
singletonErrors.set(observation, errorMessage(error));
|
|
95
123
|
}
|
|
96
124
|
}
|
|
@@ -123,15 +151,7 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
123
151
|
for (const [index, value] of values.entries()) {
|
|
124
152
|
let id = null;
|
|
125
153
|
try {
|
|
126
|
-
const parsed = parseNativeJsonResult(value, "OpenGrep");
|
|
127
|
-
if (parsed.path !== null) {
|
|
128
|
-
// Validate the emitted spelling across platforms, keeping literal POSIX backslashes.
|
|
129
|
-
const path = posix.normalize(parsed.rawPath);
|
|
130
|
-
parsed.path =
|
|
131
|
-
relativePath(posix.normalize(path.replaceAll("\\", "/"))) === null
|
|
132
|
-
? null
|
|
133
|
-
: path;
|
|
134
|
-
}
|
|
154
|
+
const parsed = parseNativeJsonResult(value, "OpenGrep", nativeResultPath);
|
|
135
155
|
// Native fingerprint counters change when another analysis pass adds matches.
|
|
136
156
|
// A source move creates a new occurrence; this is not cross-revision matching.
|
|
137
157
|
id = stableId("opengrep-location", [
|
|
@@ -151,9 +171,15 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
151
171
|
exclude(index + 1, id, error);
|
|
152
172
|
}
|
|
153
173
|
}
|
|
174
|
+
const positions = new Map();
|
|
154
175
|
for (const [id, observations] of [...groups].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)) {
|
|
155
176
|
if (observations.length === 1) {
|
|
156
|
-
|
|
177
|
+
const { position } = observations[0];
|
|
178
|
+
appendFinding(output, position, id, () => {
|
|
179
|
+
const evidence = projectGroup(observations);
|
|
180
|
+
positions.set(id, [position]);
|
|
181
|
+
return evidence;
|
|
182
|
+
});
|
|
157
183
|
continue;
|
|
158
184
|
}
|
|
159
185
|
const ordered = observations
|
|
@@ -162,10 +188,7 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
162
188
|
const result = structuredClone(observation.parsed.result);
|
|
163
189
|
// The group adds these same raw bytes when choosing a representative
|
|
164
190
|
// and deciding which traces fit alongside it.
|
|
165
|
-
validateExternalEvidenceJson({ source_data: { results: [result] } }, target
|
|
166
|
-
if (previousBytes !== currentBytes)
|
|
167
|
-
selection.uncertainIds.add(id);
|
|
168
|
-
});
|
|
191
|
+
validateExternalEvidenceJson({ source_data: { results: [result] } }, target);
|
|
169
192
|
observation.parsed.result = result;
|
|
170
193
|
return [{ observation, key: canonicalJson(result) }];
|
|
171
194
|
}
|
|
@@ -194,9 +217,8 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
194
217
|
throw error;
|
|
195
218
|
evidence = projectGroup(retained);
|
|
196
219
|
}
|
|
197
|
-
if (previousAdmission(evidence) === null)
|
|
198
|
-
selection.uncertainIds.add(id);
|
|
199
220
|
output.findings.push({ source_finding_id: id, evidence });
|
|
221
|
+
positions.set(id, retained.map(({ position }) => position));
|
|
200
222
|
}
|
|
201
223
|
catch (error) {
|
|
202
224
|
for (const observation of retained)
|
|
@@ -204,9 +226,8 @@ export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
|
204
226
|
}
|
|
205
227
|
}
|
|
206
228
|
output.excluded.sort((left, right) => left.position - right.position);
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
export async function readOpenGrepFindings(path, options, target = "cloud") {
|
|
210
|
-
return normalizeOpenGrepFindings(await readScannerJson(path), options, target);
|
|
229
|
+
sourcePositions.set(output.findings, positions);
|
|
230
|
+
return output;
|
|
211
231
|
}
|
|
232
|
+
export const readOpenGrepFindings = scannerJsonReader(normalizeOpenGrepFindings);
|
|
212
233
|
//# sourceMappingURL=opengrep-findings.js.map
|
|
@@ -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,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,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,oBAAoB,EACpB,KAAK,EACL,eAAe,E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AAW,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,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 { posix } from \"node:path\";\nimport {\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 parseNativeJsonResult,\n projectNativeJsonResult,\n sourceRepositoryUrl,\n} from \"./native-json-findings.js\";\nimport {\n trackReaderSelection,\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 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\");\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 if (observations.length === 1) {\n selection.append(observations[0]!.position, id, () =>\n projectGroup(observations),\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 } 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 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"]}
|
|
1
|
+
{"version":3,"file":"opengrep-findings.js","sourceRoot":"","sources":["../src/opengrep-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,GAEvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,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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,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CACnD,yBAAyB,CAC1B,CAAC","sourcesContent":["import { isDeepStrictEqual } from \"node:util\";\nimport {\n validateExternalEvidenceJson,\n validateExternalReport,\n type ExternalImportTarget,\n} from \"./external-import-contract.js\";\nimport { canonicalJson, isRecord } from \"./record.js\";\nimport { errorMessage } from \"./errors.js\";\nimport type { ExternalFinding, ExternalFindings } from \"./external-findings.js\";\nimport {\n messageText,\n nativeResultPath,\n parseNativeJsonResult,\n projectNativeJsonResult,\n sourceRepositoryUrl,\n} from \"./native-json-findings.js\";\nimport {\n appendFinding,\n array,\n scannerJsonReader,\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 return projectOpenGrepResults(\n values,\n repositoryUrl,\n version,\n errors.length,\n target,\n report,\n );\n}\n\n/** Reproject a retained native occurrence without changing SDK- or agent-authored evidence. */\nexport function projectStoredOpenGrepFinding(\n finding: ExternalFinding,\n): ExternalFindings | undefined {\n const { evidence } = finding;\n const native = evidence.source_data;\n const traces = native?.[\"results\"];\n const context = native?.[\"report\"];\n const version = isRecord(context) && context[\"version\"];\n const count = native?.[\"scan_error_count\"];\n const repositoryUrl = evidence.details?.repository?.url;\n if (\n evidence.details?.scanner_origin !== \"OpenGrep\" ||\n !repositoryUrl ||\n !Array.isArray(traces) ||\n typeof version !== \"string\" ||\n typeof count !== \"number\" ||\n !Number.isSafeInteger(count) ||\n count < 0\n )\n return undefined;\n const project = (target: ExternalImportTarget) =>\n projectOpenGrepResults(traces, repositoryUrl, version, count, target);\n const local = project(\"local\");\n if (\n local.findings.length !== 1 ||\n local.excluded.length ||\n !isDeepStrictEqual(local.findings[0], finding)\n )\n return undefined;\n return project(\"cloud\");\n}\n\nfunction projectOpenGrepResults(\n values: unknown[],\n repositoryUrl: string,\n version: string,\n scanErrorCount: number,\n target: ExternalImportTarget,\n report?: ExternalFindings[\"report\"],\n): ExternalFindings {\n const projection = {\n origin: \"OpenGrep\",\n repositoryUrl,\n severity: () => \"unknown\",\n reportContext: { version },\n target,\n scanErrorCount,\n };\n const output: ExternalFindings = {\n read: values.length,\n findings: [],\n excluded: [],\n ...(report && { 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: scanErrorCount,\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\", 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 appendFinding(output, 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 );\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 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 output;\n}\n\nexport const readOpenGrepFindings = scannerJsonReader(\n normalizeOpenGrepFindings,\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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EAAE,eAAe,GAAG,gBAAgB,CAAC,GACzE,IAAI,CAEN;IAEK,MAAM,CACV,OAAO,EAAE,gBAAgB,EACzB,OAAO,GAAE,IAAI,CACX,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
|