@openai/codex-security 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +437 -2692
- package/_bundled_plugin/.app.json +5 -1
- package/_bundled_plugin/.codex-plugin/plugin.json +4 -0
- package/_bundled_plugin/.mcp.json +2 -0
- package/_bundled_plugin/examples/completed-scan/coverage.json +0 -1
- package/_bundled_plugin/examples/completed-scan/report.md +28 -26
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +1 -1
- package/_bundled_plugin/mcp/helpers.mjs +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +6 -213
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/permission-profile-preflight.mjs +556 -0
- package/_bundled_plugin/mcp/server.mjs +1 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/preflight/capability-profiles.toml +0 -13
- package/_bundled_plugin/references/artifact-storage.md +2 -2
- package/_bundled_plugin/references/config-preflight.md +0 -4
- package/_bundled_plugin/references/core-scan.md +21 -9
- package/_bundled_plugin/references/final-report.md +11 -13
- package/_bundled_plugin/references/finding-detail-fields.md +90 -80
- package/_bundled_plugin/references/sarif-adapter.md +1 -1
- package/_bundled_plugin/references/scan-artifacts.md +1 -2
- package/_bundled_plugin/references/scan-contract.md +9 -4
- package/_bundled_plugin/references/scan-prologue.md +12 -0
- package/_bundled_plugin/references/security-guidance.md +2 -2
- package/_bundled_plugin/references/standalone-validation.md +11 -0
- package/_bundled_plugin/references/threat-model.md +1 -1
- package/_bundled_plugin/schemas/coverage.schema.json +43 -170
- package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +2 -24
- package/_bundled_plugin/schemas/definitions/discovery-candidate.schema.json +49 -25
- package/_bundled_plugin/schemas/findings.schema.json +159 -567
- package/_bundled_plugin/schemas/patch-risk-assessment.schema.json +106 -119
- package/_bundled_plugin/schemas/scan-manifest.schema.json +78 -220
- package/_bundled_plugin/schemas/tools/candidate-attack-paths.schema.json +91 -83
- package/_bundled_plugin/schemas/tools/candidate-validations.schema.json +35 -64
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +5 -2
- package/_bundled_plugin/schemas/tools/discovery-candidates.schema.json +6 -55
- package/_bundled_plugin/schemas/tools/review-items.schema.json +2 -38
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +169 -294
- package/_bundled_plugin/scripts/codex_profile.mjs +239 -0
- package/_bundled_plugin/scripts/codex_session.mjs +53 -0
- package/_bundled_plugin/scripts/config_preflight.py +26 -62
- package/_bundled_plugin/scripts/deep_scan_config.py +9 -11
- package/_bundled_plugin/scripts/deep_scan_workbench.py +129 -150
- package/_bundled_plugin/scripts/finalize_scan_contract.py +321 -237
- package/_bundled_plugin/scripts/finding_preview.py +39 -9
- package/_bundled_plugin/scripts/generate_in_scope_files.py +27 -77
- package/_bundled_plugin/scripts/generate_rank_input.py +115 -926
- package/_bundled_plugin/scripts/launch_codex_security_mcp +35 -10
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +5 -5
- package/_bundled_plugin/scripts/rank_preview.py +42 -918
- package/_bundled_plugin/scripts/report_projection.py +150 -183
- package/_bundled_plugin/scripts/snapshot_sqlite.py +6 -1
- package/_bundled_plugin/scripts/threat_model_projection.py +4 -7
- package/_bundled_plugin/scripts/validate_scan_contract.py +4 -34
- package/_bundled_plugin/scripts/validate_tracking_source.py +3 -13
- package/_bundled_plugin/scripts/windows_scan_local_files.py +48 -3
- package/_bundled_plugin/scripts/workbench/handoff.py +25 -50
- package/_bundled_plugin/scripts/workbench/runtime_toml.py +22 -0
- package/_bundled_plugin/scripts/workbench/storage.py +10 -6
- package/_bundled_plugin/scripts/workbench_cli.py +102 -184
- package/_bundled_plugin/scripts/workbench_db.py +463 -464
- package/_bundled_plugin/scripts/workbench_feedback.py +6 -3
- package/_bundled_plugin/scripts/workbench_finding_index.py +19 -1
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +18 -4
- package/_bundled_plugin/scripts/workbench_local_dedupe.py +136 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +27 -14
- package/_bundled_plugin/scripts/workbench_progress.py +14 -58
- package/_bundled_plugin/scripts/workbench_publication.py +234 -289
- package/_bundled_plugin/scripts/workbench_remediation.py +12 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +172 -49
- package/_bundled_plugin/scripts/workbench_scan_history.py +57 -57
- package/_bundled_plugin/scripts/workbench_scan_start.py +105 -41
- package/_bundled_plugin/scripts/workbench_scan_usage.py +194 -42
- package/_bundled_plugin/scripts/workbench_schema.py +37 -1151
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +11 -1
- package/_bundled_plugin/scripts/workbench_target.py +430 -142
- package/_bundled_plugin/scripts/workbench_validation.py +31 -28
- package/_bundled_plugin/shared/workbench-history-repairs.json +218 -0
- package/_bundled_plugin/shared/workbench-migrations.json +414 -0
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +15 -4
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +54 -0
- package/_bundled_plugin/skills/cloud-findings/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/finding-discovery/SKILL.md +3 -3
- package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +50 -20
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +8 -14
- package/_bundled_plugin/skills/security-scan/SKILL.md +22 -7
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +15 -1
- package/_bundled_plugin/skills/threat-model/SKILL.md +1 -1
- package/_bundled_plugin/skills/track-findings/SKILL.md +48 -176
- package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +16 -24
- package/_bundled_plugin/skills/track-findings/references/jira.md +15 -61
- package/_bundled_plugin/skills/triage-finding/SKILL.md +50 -289
- package/_bundled_plugin/skills/triage-finding/agents/openai.yaml +2 -2
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +23 -43
- package/_bundled_plugin/skills/triage-finding/references/triage-result-contract.md +7 -1
- package/bin/codex-security.mjs +9 -2
- package/dist/api.d.ts +63 -10
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1015 -383
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +1 -1
- package/dist/artifact-export.d.ts.map +1 -1
- package/dist/artifact-export.js +28 -13
- package/dist/artifact-export.js.map +1 -1
- package/dist/auth.d.ts +2 -6
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +19 -9
- package/dist/auth.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +1 -0
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-severity.d.ts +26 -9
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +13 -30
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +17 -13
- package/dist/cli-help.js.map +1 -1
- package/dist/cli-signals.d.ts +8 -0
- package/dist/cli-signals.d.ts.map +1 -0
- package/dist/cli-signals.js +28 -0
- package/dist/cli-signals.js.map +1 -0
- package/dist/cli.d.ts +4 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1102 -905
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +10 -9
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codeowners.d.ts +19 -0
- package/dist/codeowners.d.ts.map +1 -0
- package/dist/codeowners.js +138 -0
- package/dist/codeowners.js.map +1 -0
- package/dist/codex-sdk-environment.d.ts +1 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -1
- package/dist/codex-sdk-environment.js +40 -2
- package/dist/codex-sdk-environment.js.map +1 -1
- package/dist/component-plan.d.ts +2 -5
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +39 -31
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +6 -5
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +25 -36
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +64 -74
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +16 -3
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +91 -255
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts +13 -6
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +14 -4
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +10 -2
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +102 -104
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +6 -5
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts +1 -2
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +9 -3
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts +4 -2
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js +23 -9
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +8 -6
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +128 -19
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +5 -2
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +18 -4
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +27 -5
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +58 -48
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.d.ts.map +1 -1
- package/dist/deduplication/deduplication.js +19 -51
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/diagnostics.d.ts +17 -0
- package/dist/deduplication/diagnostics.d.ts.map +1 -0
- package/dist/deduplication/diagnostics.js +5 -0
- package/dist/deduplication/diagnostics.js.map +1 -0
- package/dist/deduplication/finding-schema.d.ts.map +1 -1
- package/dist/deduplication/finding-schema.js +7 -1
- package/dist/deduplication/finding-schema.js.map +1 -1
- package/dist/deduplication/local.d.ts +31 -0
- package/dist/deduplication/local.d.ts.map +1 -0
- package/dist/deduplication/local.js +166 -0
- package/dist/deduplication/local.js.map +1 -0
- package/dist/deduplication/records-protocol.d.ts +3 -8
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +11 -184
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +186 -11
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +10 -18
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/scan.d.ts +9 -3
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +158 -39
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +2 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +4 -4
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-progress.d.ts +17 -1
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +19 -17
- package/dist/deep-progress.js.map +1 -1
- package/dist/deep-scan.d.ts +20 -0
- package/dist/deep-scan.d.ts.map +1 -0
- package/dist/deep-scan.js +113 -0
- package/dist/deep-scan.js.map +1 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -1
- package/dist/executable-path.d.ts +2 -0
- package/dist/executable-path.d.ts.map +1 -0
- package/dist/executable-path.js +12 -0
- package/dist/executable-path.js.map +1 -0
- package/dist/feedback.d.ts +1 -4
- package/dist/feedback.d.ts.map +1 -1
- package/dist/feedback.js +54 -22
- package/dist/feedback.js.map +1 -1
- package/dist/finding-catalogue.d.ts.map +1 -1
- package/dist/finding-catalogue.js +4 -8
- package/dist/finding-catalogue.js.map +1 -1
- package/dist/finding-normalization.d.ts +5 -0
- package/dist/finding-normalization.d.ts.map +1 -0
- package/dist/finding-normalization.js +120 -0
- package/dist/finding-normalization.js.map +1 -0
- package/dist/finding-retrieval.d.ts +9 -0
- package/dist/finding-retrieval.d.ts.map +1 -1
- package/dist/finding-retrieval.js.map +1 -1
- package/dist/finding-workflow.d.ts +13 -8
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +14 -6
- package/dist/finding-workflow.js.map +1 -1
- package/dist/findings-client.d.ts +2 -1
- package/dist/findings-client.d.ts.map +1 -1
- package/dist/findings-client.js +36 -9
- package/dist/findings-client.js.map +1 -1
- package/dist/findings-errors.d.ts +16 -0
- package/dist/findings-errors.d.ts.map +1 -0
- package/dist/findings-errors.js +24 -0
- package/dist/findings-errors.js.map +1 -0
- package/dist/findings-import.d.ts +1 -1
- package/dist/findings-import.d.ts.map +1 -1
- package/dist/findings-import.js +12 -30
- package/dist/findings-import.js.map +1 -1
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +7 -1
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +19 -0
- package/dist/host-protocol.d.ts.map +1 -0
- package/dist/host-protocol.js +270 -0
- package/dist/host-protocol.js.map +1 -0
- package/dist/hosted-scan-protocol.d.ts +4 -0
- package/dist/hosted-scan-protocol.d.ts.map +1 -0
- package/dist/hosted-scan-protocol.js +25 -0
- package/dist/hosted-scan-protocol.js.map +1 -0
- package/dist/hosted-scan.d.ts +117 -0
- package/dist/hosted-scan.d.ts.map +1 -0
- package/dist/hosted-scan.js +260 -0
- package/dist/hosted-scan.js.map +1 -0
- package/dist/import-scan.d.ts.map +1 -1
- package/dist/import-scan.js +48 -38
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts +7 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +114 -46
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js +2 -7
- package/dist/linear.js.map +1 -1
- package/dist/mock-scan.d.ts.map +1 -1
- package/dist/mock-scan.js +0 -1
- package/dist/mock-scan.js.map +1 -1
- package/dist/models.d.ts +0 -2
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/multiscan.d.ts +9 -3
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +240 -135
- package/dist/multiscan.js.map +1 -1
- package/dist/owner-evidence.d.ts +10 -2
- package/dist/owner-evidence.d.ts.map +1 -1
- package/dist/owner-evidence.js +67 -8
- package/dist/owner-evidence.js.map +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +3 -2
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config.js +3 -3
- package/dist/project-config.js.map +1 -1
- package/dist/provider-profile.d.ts +21 -0
- package/dist/provider-profile.d.ts.map +1 -0
- package/dist/provider-profile.js +133 -0
- package/dist/provider-profile.js.map +1 -0
- package/dist/publication-events.d.ts +6 -8
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +25 -50
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +95 -109
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts +1 -4
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +2 -13
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts +1 -5
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +109 -160
- package/dist/publish.js.map +1 -1
- package/dist/request-metadata.d.ts +9 -0
- package/dist/request-metadata.d.ts.map +1 -0
- package/dist/request-metadata.js +13 -0
- package/dist/request-metadata.js.map +1 -0
- package/dist/runtime.d.ts +20 -6
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +407 -148
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +14 -0
- package/dist/saved-scan-bootstrap.d.ts.map +1 -0
- package/dist/saved-scan-bootstrap.js +261 -0
- package/dist/saved-scan-bootstrap.js.map +1 -0
- package/dist/saved-scan.d.ts +1 -1
- package/dist/saved-scan.d.ts.map +1 -1
- package/dist/saved-scan.js +6 -12
- package/dist/saved-scan.js.map +1 -1
- package/dist/scan-activity.js +11 -8
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +28 -15
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +276 -281
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +3 -0
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +345 -77
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +104 -0
- package/dist/scan-executor.d.ts.map +1 -0
- package/dist/scan-executor.js +62 -0
- package/dist/scan-executor.js.map +1 -0
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +54 -13
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-inputs.d.ts +6 -0
- package/dist/scan-inputs.d.ts.map +1 -0
- package/dist/scan-inputs.js +71 -0
- package/dist/scan-inputs.js.map +1 -0
- package/dist/scan-logs.d.ts +2 -3
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +12 -6
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-sessions.d.ts +4 -0
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +17 -0
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-skill-paths.d.ts +8 -0
- package/dist/scan-skill-paths.d.ts.map +1 -0
- package/dist/scan-skill-paths.js +47 -0
- package/dist/scan-skill-paths.js.map +1 -0
- package/dist/security-policy-cli.d.ts.map +1 -1
- package/dist/security-policy-cli.js +7 -27
- package/dist/security-policy-cli.js.map +1 -1
- package/dist/security-policy.d.ts +9 -5
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +33 -14
- package/dist/security-policy.js.map +1 -1
- package/dist/server/api.d.ts +0 -1
- package/dist/server/api.d.ts.map +1 -1
- package/dist/server/api.js +0 -1
- package/dist/server/api.js.map +1 -1
- package/dist/server/embeddings.d.ts +3 -1
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +10 -3
- package/dist/server/embeddings.js.map +1 -1
- package/dist/server/errors.d.ts +5 -2
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/errors.js +7 -0
- package/dist/server/errors.js.map +1 -1
- package/dist/server/sqlite-store.d.ts +0 -2
- package/dist/server/sqlite-store.d.ts.map +1 -1
- package/dist/server/sqlite-store.js +54 -44
- package/dist/server/sqlite-store.js.map +1 -1
- package/dist/server/storage.d.ts +0 -2
- package/dist/server/storage.d.ts.map +1 -1
- package/dist/server/storage.js.map +1 -1
- package/dist/severity-store.js +19 -24
- package/dist/severity-store.js.map +1 -1
- package/dist/standalone-validation-prompt.d.ts +2 -0
- package/dist/standalone-validation-prompt.d.ts.map +1 -0
- package/dist/standalone-validation-prompt.js +10 -0
- package/dist/standalone-validation-prompt.js.map +1 -0
- package/dist/suggest-owners.d.ts +4 -2
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +11 -5
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +11 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +123 -72
- package/dist/targets.js.map +1 -1
- package/dist/trusted-executable.d.ts +2 -2
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +8 -6
- package/dist/trusted-executable.js.map +1 -1
- package/dist/value.js +7 -0
- package/dist/value.js.map +1 -1
- package/dist/version.js.map +1 -1
- package/dist/workbench-arguments.d.ts +3 -0
- package/dist/workbench-arguments.d.ts.map +1 -0
- package/dist/workbench-arguments.js +15 -0
- package/dist/workbench-arguments.js.map +1 -0
- package/dist/worker-progress.d.ts +44 -11
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +48 -49
- package/dist/worker-progress.js.map +1 -1
- package/docs/cli.md +1788 -0
- package/docs/findings-service.md +402 -0
- package/docs/hosted-scans.md +242 -0
- package/package.json +23 -22
- package/schemas/hosted-scan-v2.fixture.json +145 -0
- package/_bundled_plugin/schemas/tools/worker-threat-model.schema.json +0 -18
- package/_bundled_plugin/scripts/workbench_dashboard.py +0 -159
- package/_bundled_plugin/scripts/workbench_findings.py +0 -221
- package/_bundled_plugin/scripts/workbench_severity.py +0 -122
- package/_bundled_plugin/skills/assess-patch-risk/scripts/validate_patch_risk_assessment.py +0 -163
- package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +0 -276
- package/dist/server/dashboard/app.css +0 -2
- package/dist/server/dashboard/app.js +0 -66
- package/dist/server/dashboard/index.html +0 -18
- package/dist/server/dashboard-types.d.ts +0 -48
- package/dist/server/dashboard-types.d.ts.map +0 -1
- package/dist/server/dashboard-types.js +0 -2
- package/dist/server/dashboard-types.js.map +0 -1
- package/dist/server/dashboard.d.ts +0 -6
- package/dist/server/dashboard.d.ts.map +0 -1
- package/dist/server/dashboard.js +0 -59
- package/dist/server/dashboard.js.map +0 -1
- package/dist/server/index.d.ts +0 -2
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js +0 -6
- package/dist/server/index.js.map +0 -1
- package/dist/server/routes.d.ts +0 -7
- package/dist/server/routes.d.ts.map +0 -1
- package/dist/server/routes.js +0 -98
- package/dist/server/routes.js.map +0 -1
- package/dist/server/serve.d.ts +0 -2
- package/dist/server/serve.d.ts.map +0 -1
- package/dist/server/serve.js +0 -28
- package/dist/server/serve.js.map +0 -1
- package/dist/server/server.d.ts +0 -10
- package/dist/server/server.d.ts.map +0 -1
- package/dist/server/server.js +0 -16
- package/dist/server/server.js.map +0 -1
- package/dist/server/validation.d.ts +0 -17
- package/dist/server/validation.d.ts.map +0 -1
- package/dist/server/validation.js +0 -53
- package/dist/server/validation.js.map +0 -1
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3
|
+
import { readScanFile, safeScopePath } from "./contract.js";
|
|
4
|
+
import { isRecord } from "./record.js";
|
|
5
|
+
import { VERSION } from "./version.js";
|
|
6
|
+
import { ScanExecutionError, } from "./scan-executor.js";
|
|
7
|
+
import { realpath } from "node:fs/promises";
|
|
8
|
+
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { CodexSecurity } from "./api.js";
|
|
11
|
+
import { ScanInterruptedError, errorMessage } from "./errors.js";
|
|
12
|
+
import { normalizeRepository, repositoryRevision } from "./targets.js";
|
|
13
|
+
import { isWithin } from "./trusted-executable.js";
|
|
14
|
+
/** Hosted v2 mirrors repository/paths targets; only Standard scans are supported. */
|
|
15
|
+
export const HostedScanInputSchema = z.strictObject({
|
|
16
|
+
version: z.literal(2),
|
|
17
|
+
repository: z.string().min(1),
|
|
18
|
+
revision: z.string().regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/),
|
|
19
|
+
scope: z
|
|
20
|
+
.strictObject({ paths: z.array(z.string().min(1)).min(1) })
|
|
21
|
+
.optional(),
|
|
22
|
+
outputDirectory: z.string().min(1),
|
|
23
|
+
stateDirectory: z.string().min(1),
|
|
24
|
+
model: z.string().min(1),
|
|
25
|
+
reasoningEffort: z.enum(["low", "medium", "high", "xhigh"]),
|
|
26
|
+
identity: z.strictObject({
|
|
27
|
+
runId: z.string().min(1),
|
|
28
|
+
attemptId: z.string().min(1),
|
|
29
|
+
buildId: z.string().min(1),
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
export class HostedScanPreparationError extends Error {
|
|
33
|
+
reason;
|
|
34
|
+
constructor(reason, message) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.reason = reason;
|
|
37
|
+
this.name = "HostedScanPreparationError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function normalizeHostedScope(path) {
|
|
41
|
+
const parts = path.split(process.platform === "win32" ? /[/\\]/ : "/");
|
|
42
|
+
if (path.length === 0 ||
|
|
43
|
+
path.includes("\0") ||
|
|
44
|
+
isAbsolute(path) ||
|
|
45
|
+
(process.platform === "win32" && /^[a-z]:/i.test(path)) ||
|
|
46
|
+
parts.includes("..")) {
|
|
47
|
+
throw new HostedScanPreparationError("scope_syntax", "Use non-empty repository-relative folders or files without parent traversal or NUL characters.");
|
|
48
|
+
}
|
|
49
|
+
const normalized = parts
|
|
50
|
+
.filter((part) => part !== "" && part !== ".")
|
|
51
|
+
.join("/");
|
|
52
|
+
try {
|
|
53
|
+
return safeScopePath(normalized || ".");
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
throw new HostedScanPreparationError("scope_syntax", `${JSON.stringify(path)} cannot be used as scan scope: the output contract requires UTF-8 repository-relative paths without drive prefixes, backslashes, or control characters.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function comparePaths(left, right) {
|
|
60
|
+
return Buffer.compare(Buffer.from(left), Buffer.from(right));
|
|
61
|
+
}
|
|
62
|
+
export function normalizeHostedPaths(paths = ["."]) {
|
|
63
|
+
if (paths.length === 0)
|
|
64
|
+
throw new HostedScanPreparationError("scope_syntax", "An explicit path scope must not be empty. Omit scope to scan the repository.");
|
|
65
|
+
const normalized = [...new Set(paths.map(normalizeHostedScope))].sort(comparePaths);
|
|
66
|
+
if (normalized.length > 1 && normalized.includes("."))
|
|
67
|
+
throw new HostedScanPreparationError("scope_syntax", "Repository scope cannot be mixed with narrower paths.");
|
|
68
|
+
return normalized;
|
|
69
|
+
}
|
|
70
|
+
/** Validate every path at the frozen commit before registering a scan/executing. */
|
|
71
|
+
async function prepareHostedScan(input, signal) {
|
|
72
|
+
const scope = { paths: normalizeHostedPaths(input.scope?.paths) };
|
|
73
|
+
const repository = await normalizeRepository(input.repository);
|
|
74
|
+
if ((await repositoryRevision(repository, signal)) !== input.revision)
|
|
75
|
+
throw new HostedScanPreparationError("revision_mismatch", "Checkout does not match the frozen revision.");
|
|
76
|
+
for (const path of scope.paths) {
|
|
77
|
+
const selected = resolve(repository, path);
|
|
78
|
+
let target;
|
|
79
|
+
try {
|
|
80
|
+
target = await realpath(selected);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (!(error instanceof Error) ||
|
|
84
|
+
!("code" in error) ||
|
|
85
|
+
error.code !== "ENOENT")
|
|
86
|
+
throw error;
|
|
87
|
+
throw new HostedScanPreparationError("scope_missing", `${path} does not exist at the selected revision. Update the paths and start a new scan.`);
|
|
88
|
+
}
|
|
89
|
+
if (!isWithin(repository, target))
|
|
90
|
+
throw new HostedScanPreparationError("scope_outside_repository", `${path} resolves outside the repository.`);
|
|
91
|
+
if (target !== selected) {
|
|
92
|
+
const canonical = relative(repository, target).split(sep).join("/") || ".";
|
|
93
|
+
throw new HostedScanPreparationError("scope_alias", `${path} resolves to ${canonical}. Use the canonical repository path and start a new scan.`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
repository,
|
|
98
|
+
revision: input.revision,
|
|
99
|
+
scope,
|
|
100
|
+
identity: input.identity,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function hostedScanEnvironment(stateDirectory) {
|
|
104
|
+
const environment = {
|
|
105
|
+
PATH: process.env["PATH"] ?? "",
|
|
106
|
+
CODEX_SECURITY_STATE_DIR: resolve(stateDirectory),
|
|
107
|
+
};
|
|
108
|
+
for (const key of [
|
|
109
|
+
"SYSTEMROOT",
|
|
110
|
+
"WINDIR",
|
|
111
|
+
"PATHEXT",
|
|
112
|
+
"TMPDIR",
|
|
113
|
+
"TEMP",
|
|
114
|
+
"TMP",
|
|
115
|
+
])
|
|
116
|
+
if (process.env[key] !== undefined)
|
|
117
|
+
environment[key] = process.env[key];
|
|
118
|
+
return environment;
|
|
119
|
+
}
|
|
120
|
+
/** One invocation, with only scan-domain state. The host decides retry/reconciliation. */
|
|
121
|
+
export async function runHostedScan(value, options) {
|
|
122
|
+
const input = HostedScanInputSchema.parse(value);
|
|
123
|
+
const context = await prepareHostedScan(input, options.signal);
|
|
124
|
+
let execution;
|
|
125
|
+
let request;
|
|
126
|
+
let scanId;
|
|
127
|
+
const onEvent = (event) => {
|
|
128
|
+
void Promise.resolve()
|
|
129
|
+
.then(() => options.onEvent?.(event))
|
|
130
|
+
.catch(() => { });
|
|
131
|
+
};
|
|
132
|
+
const client = new CodexSecurity({
|
|
133
|
+
codexOverrides: {
|
|
134
|
+
model: input.model,
|
|
135
|
+
model_reasoning_effort: input.reasoningEffort,
|
|
136
|
+
},
|
|
137
|
+
}, {
|
|
138
|
+
environment: hostedScanEnvironment(input.stateDirectory),
|
|
139
|
+
hostedScan: {
|
|
140
|
+
context,
|
|
141
|
+
executor: {
|
|
142
|
+
async run(value, runOptions) {
|
|
143
|
+
request = value;
|
|
144
|
+
execution = await options.executor.run(value, runOptions);
|
|
145
|
+
return execution;
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
onEvent,
|
|
149
|
+
},
|
|
150
|
+
createCodex() {
|
|
151
|
+
throw new Error("Local inference is unavailable in hosted mode.");
|
|
152
|
+
},
|
|
153
|
+
}, { surface: "sdk" });
|
|
154
|
+
let outputDirectory = resolve(input.outputDirectory);
|
|
155
|
+
const base = () => ({
|
|
156
|
+
version: 2,
|
|
157
|
+
...context,
|
|
158
|
+
outputDirectory,
|
|
159
|
+
...(scanId === undefined ? {} : { scanId }),
|
|
160
|
+
...(request === undefined
|
|
161
|
+
? {}
|
|
162
|
+
: {
|
|
163
|
+
pluginVersion: request.runtime.pluginVersion,
|
|
164
|
+
}),
|
|
165
|
+
provenance: {
|
|
166
|
+
cliVersion: VERSION,
|
|
167
|
+
buildId: input.identity.buildId,
|
|
168
|
+
...(request === undefined
|
|
169
|
+
? {}
|
|
170
|
+
: { pluginVersion: request.runtime.pluginVersion }),
|
|
171
|
+
},
|
|
172
|
+
...(execution === undefined ? {} : { execution }),
|
|
173
|
+
});
|
|
174
|
+
try {
|
|
175
|
+
const result = await client.run(context.repository, {
|
|
176
|
+
target: context.scope.paths[0] === "."
|
|
177
|
+
? "repository"
|
|
178
|
+
: context.scope.paths.map((path) => `./${path}`),
|
|
179
|
+
mode: "standard",
|
|
180
|
+
outputDir: outputDirectory,
|
|
181
|
+
signal: options.signal,
|
|
182
|
+
onOutputDirReady(path) {
|
|
183
|
+
outputDirectory = path;
|
|
184
|
+
},
|
|
185
|
+
onScanRegistered(scan) {
|
|
186
|
+
scanId = scan.scanId;
|
|
187
|
+
outputDirectory = scan.scanDir;
|
|
188
|
+
},
|
|
189
|
+
onProgress(progress) {
|
|
190
|
+
onEvent({ type: "progress", progress });
|
|
191
|
+
},
|
|
192
|
+
onActivity(activity) {
|
|
193
|
+
onEvent({ type: "activity", activity });
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
if (result.manifest.scan.target.revision !== context.revision ||
|
|
197
|
+
(await repositoryRevision(context.repository, options.signal)) !==
|
|
198
|
+
context.revision)
|
|
199
|
+
throw new Error("Checkout changed from the frozen revision during execution.");
|
|
200
|
+
if (!isDeepStrictEqual([...result.manifest.scan.scope.includePaths].sort(comparePaths), context.scope.paths) ||
|
|
201
|
+
result.manifest.scan.scope.excludePaths.length !== 0)
|
|
202
|
+
throw new Error("Completed artifacts do not match the requested scope.");
|
|
203
|
+
const sources = result.manifest.scan["preservedSources"];
|
|
204
|
+
const names = new Set([
|
|
205
|
+
"scan-manifest.json",
|
|
206
|
+
"findings.json",
|
|
207
|
+
"coverage.json",
|
|
208
|
+
"report.md",
|
|
209
|
+
...result.manifest.scan.artifacts.map((artifact) => artifact.path),
|
|
210
|
+
...(isRecord(sources) ? Object.keys(sources) : []),
|
|
211
|
+
]);
|
|
212
|
+
const artifacts = await Promise.all([...names].sort().map(async (path) => {
|
|
213
|
+
const contents = await readScanFile(outputDirectory, path, path);
|
|
214
|
+
return {
|
|
215
|
+
path,
|
|
216
|
+
sha256: createHash("sha256").update(contents).digest("hex"),
|
|
217
|
+
bytes: Buffer.byteLength(contents),
|
|
218
|
+
};
|
|
219
|
+
}));
|
|
220
|
+
return {
|
|
221
|
+
...base(),
|
|
222
|
+
status: "completed",
|
|
223
|
+
artifacts,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
if (error instanceof ScanExecutionError)
|
|
228
|
+
execution = error.result;
|
|
229
|
+
return {
|
|
230
|
+
...base(),
|
|
231
|
+
status: execution?.status === "acceptance_unknown"
|
|
232
|
+
? "acceptance_unknown"
|
|
233
|
+
: options.signal?.aborted ||
|
|
234
|
+
execution?.status === "canceled" ||
|
|
235
|
+
error instanceof ScanInterruptedError
|
|
236
|
+
? "canceled"
|
|
237
|
+
: "failed",
|
|
238
|
+
error: errorMessage(error),
|
|
239
|
+
artifacts: [],
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
finally {
|
|
243
|
+
try {
|
|
244
|
+
await client.close();
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
onEvent({
|
|
248
|
+
type: "activity",
|
|
249
|
+
activity: {
|
|
250
|
+
id: "runtime.cleanup",
|
|
251
|
+
kind: "message",
|
|
252
|
+
status: "failed",
|
|
253
|
+
description: `Hosted scan cleanup failed: ${errorMessage(error)}`,
|
|
254
|
+
paths: [],
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
//# sourceMappingURL=hosted-scan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosted-scan.js","sourceRoot":"","sources":["../src/hosted-scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACL,kBAAkB,GAKnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAA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AE;oBACR,EAAE,EAAE,iBAAiB;oBACrB,IAAI,EAAE,SAAS;oBACf,MAAM,EAAE,QAAQ;oBAChB,WAAW,EAAE,+BAA+B,YAAY,CAAC,KAAK,CAAC,EAAE;oBACjE,KAAK,EAAE,EAAE;iBACV;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport { readScanFile, safeScopePath } from \"./contract.js\";\nimport { isRecord } from \"./record.js\";\nimport { VERSION } from \"./version.js\";\nimport {\n ScanExecutionError,\n type ScanExecutor,\n type ScanExecutionResult,\n type ScanExecutionEvent,\n type ScanExecutionRequest,\n} from \"./scan-executor.js\";\nexport type { ScanExecutor, ScanExecutionRequest } from \"./scan-executor.js\";\nimport { realpath } from \"node:fs/promises\";\nimport { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { z } from \"zod\";\nimport { CodexSecurity } from \"./api.js\";\nimport { ScanInterruptedError, errorMessage } from \"./errors.js\";\nimport { normalizeRepository, repositoryRevision } from \"./targets.js\";\nimport { isWithin } from \"./trusted-executable.js\";\n\n/** Hosted v2 mirrors repository/paths targets; only Standard scans are supported. */\nexport const HostedScanInputSchema = z.strictObject({\n version: z.literal(2),\n repository: z.string().min(1),\n revision: z.string().regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/),\n scope: z\n .strictObject({ paths: z.array(z.string().min(1)).min(1) })\n .optional(),\n outputDirectory: z.string().min(1),\n stateDirectory: z.string().min(1),\n model: z.string().min(1),\n reasoningEffort: z.enum([\"low\", \"medium\", \"high\", \"xhigh\"]),\n identity: z.strictObject({\n runId: z.string().min(1),\n attemptId: z.string().min(1),\n buildId: z.string().min(1),\n }),\n});\n\nexport type HostedScanInput = z.infer<typeof HostedScanInputSchema>;\nexport class HostedScanPreparationError extends Error {\n constructor(\n readonly reason:\n | \"scope_syntax\"\n | \"scope_missing\"\n | \"scope_outside_repository\"\n | \"scope_alias\"\n | \"revision_mismatch\",\n message: string,\n ) {\n super(message);\n this.name = \"HostedScanPreparationError\";\n }\n}\n\nexport function normalizeHostedScope(path: string): string {\n const parts = path.split(process.platform === \"win32\" ? /[/\\\\]/ : \"/\");\n if (\n path.length === 0 ||\n path.includes(\"\\0\") ||\n isAbsolute(path) ||\n (process.platform === \"win32\" && /^[a-z]:/i.test(path)) ||\n parts.includes(\"..\")\n ) {\n throw new HostedScanPreparationError(\n \"scope_syntax\",\n \"Use non-empty repository-relative folders or files without parent traversal or NUL characters.\",\n );\n }\n const normalized = parts\n .filter((part) => part !== \"\" && part !== \".\")\n .join(\"/\");\n try {\n return safeScopePath(normalized || \".\");\n } catch {\n throw new HostedScanPreparationError(\n \"scope_syntax\",\n `${JSON.stringify(path)} cannot be used as scan scope: the output contract requires UTF-8 repository-relative paths without drive prefixes, backslashes, or control characters.`,\n );\n }\n}\n\nfunction comparePaths(left: string, right: string): number {\n return Buffer.compare(Buffer.from(left), Buffer.from(right));\n}\n\nexport function normalizeHostedPaths(\n paths: readonly string[] = [\".\"],\n): string[] {\n if (paths.length === 0)\n throw new HostedScanPreparationError(\n \"scope_syntax\",\n \"An explicit path scope must not be empty. Omit scope to scan the repository.\",\n );\n const normalized = [...new Set(paths.map(normalizeHostedScope))].sort(\n comparePaths,\n );\n if (normalized.length > 1 && normalized.includes(\".\"))\n throw new HostedScanPreparationError(\n \"scope_syntax\",\n \"Repository scope cannot be mixed with narrower paths.\",\n );\n return normalized;\n}\n\n/** Validate every path at the frozen commit before registering a scan/executing. */\nasync function prepareHostedScan(input: HostedScanInput, signal?: AbortSignal) {\n const scope = { paths: normalizeHostedPaths(input.scope?.paths) };\n const repository = await normalizeRepository(input.repository);\n if ((await repositoryRevision(repository, signal)) !== input.revision)\n throw new HostedScanPreparationError(\n \"revision_mismatch\",\n \"Checkout does not match the frozen revision.\",\n );\n for (const path of scope.paths) {\n const selected = resolve(repository, path);\n let target: string;\n try {\n target = await realpath(selected);\n } catch (error) {\n if (\n !(error instanceof Error) ||\n !(\"code\" in error) ||\n error.code !== \"ENOENT\"\n )\n throw error;\n throw new HostedScanPreparationError(\n \"scope_missing\",\n `${path} does not exist at the selected revision. Update the paths and start a new scan.`,\n );\n }\n if (!isWithin(repository, target))\n throw new HostedScanPreparationError(\n \"scope_outside_repository\",\n `${path} resolves outside the repository.`,\n );\n if (target !== selected) {\n const canonical =\n relative(repository, target).split(sep).join(\"/\") || \".\";\n throw new HostedScanPreparationError(\n \"scope_alias\",\n `${path} resolves to ${canonical}. Use the canonical repository path and start a new scan.`,\n );\n }\n }\n return {\n repository,\n revision: input.revision,\n scope,\n identity: input.identity,\n };\n}\n\nfunction hostedScanEnvironment(stateDirectory: string): Record<string, string> {\n const environment: Record<string, string> = {\n PATH: process.env[\"PATH\"] ?? \"\",\n CODEX_SECURITY_STATE_DIR: resolve(stateDirectory),\n };\n for (const key of [\n \"SYSTEMROOT\",\n \"WINDIR\",\n \"PATHEXT\",\n \"TMPDIR\",\n \"TEMP\",\n \"TMP\",\n ])\n if (process.env[key] !== undefined) environment[key] = process.env[key]!;\n return environment;\n}\n\nexport interface HostedScanOptions {\n executor: ScanExecutor;\n signal?: AbortSignal;\n onEvent?: (event: ScanExecutionEvent) => void;\n}\n\n/** One invocation, with only scan-domain state. The host decides retry/reconciliation. */\nexport async function runHostedScan(\n value: HostedScanInput,\n options: HostedScanOptions,\n) {\n const input = HostedScanInputSchema.parse(value);\n const context = await prepareHostedScan(input, options.signal);\n let execution: ScanExecutionResult | undefined;\n let request: ScanExecutionRequest | undefined;\n let scanId: string | undefined;\n const onEvent = (event: ScanExecutionEvent): void => {\n void Promise.resolve()\n .then(() => options.onEvent?.(event))\n .catch(() => {});\n };\n const client = new CodexSecurity(\n {\n codexOverrides: {\n model: input.model,\n model_reasoning_effort: input.reasoningEffort,\n },\n },\n {\n environment: hostedScanEnvironment(input.stateDirectory),\n hostedScan: {\n context,\n executor: {\n async run(value, runOptions) {\n request = value;\n execution = await options.executor.run(value, runOptions);\n return execution;\n },\n },\n onEvent,\n },\n createCodex() {\n throw new Error(\"Local inference is unavailable in hosted mode.\");\n },\n },\n { surface: \"sdk\" },\n );\n let outputDirectory = resolve(input.outputDirectory);\n const base = () => ({\n version: 2 as const,\n ...context,\n outputDirectory,\n ...(scanId === undefined ? {} : { scanId }),\n ...(request === undefined\n ? {}\n : {\n pluginVersion: request.runtime.pluginVersion,\n }),\n provenance: {\n cliVersion: VERSION,\n buildId: input.identity.buildId,\n ...(request === undefined\n ? {}\n : { pluginVersion: request.runtime.pluginVersion }),\n },\n ...(execution === undefined ? {} : { execution }),\n });\n try {\n const result = await client.run(context.repository, {\n target:\n context.scope.paths[0] === \".\"\n ? \"repository\"\n : context.scope.paths.map((path) => `./${path}`),\n mode: \"standard\",\n outputDir: outputDirectory,\n signal: options.signal,\n onOutputDirReady(path) {\n outputDirectory = path;\n },\n onScanRegistered(scan) {\n scanId = scan.scanId;\n outputDirectory = scan.scanDir;\n },\n onProgress(progress) {\n onEvent({ type: \"progress\", progress });\n },\n onActivity(activity) {\n onEvent({ type: \"activity\", activity });\n },\n });\n if (\n result.manifest.scan.target.revision !== context.revision ||\n (await repositoryRevision(context.repository, options.signal)) !==\n context.revision\n )\n throw new Error(\n \"Checkout changed from the frozen revision during execution.\",\n );\n if (\n !isDeepStrictEqual(\n [...result.manifest.scan.scope.includePaths].sort(comparePaths),\n context.scope.paths,\n ) ||\n result.manifest.scan.scope.excludePaths.length !== 0\n )\n throw new Error(\"Completed artifacts do not match the requested scope.\");\n const sources = result.manifest.scan[\"preservedSources\"];\n const names = new Set([\n \"scan-manifest.json\",\n \"findings.json\",\n \"coverage.json\",\n \"report.md\",\n ...result.manifest.scan.artifacts.map((artifact) => artifact.path),\n ...(isRecord(sources) ? Object.keys(sources) : []),\n ]);\n const artifacts = await Promise.all(\n [...names].sort().map(async (path) => {\n const contents = await readScanFile(outputDirectory, path, path);\n return {\n path,\n sha256: createHash(\"sha256\").update(contents).digest(\"hex\"),\n bytes: Buffer.byteLength(contents),\n };\n }),\n );\n return {\n ...base(),\n status: \"completed\" as const,\n artifacts,\n };\n } catch (error) {\n if (error instanceof ScanExecutionError) execution = error.result;\n return {\n ...base(),\n status:\n execution?.status === \"acceptance_unknown\"\n ? (\"acceptance_unknown\" as const)\n : options.signal?.aborted ||\n execution?.status === \"canceled\" ||\n error instanceof ScanInterruptedError\n ? (\"canceled\" as const)\n : (\"failed\" as const),\n error: errorMessage(error),\n artifacts: [],\n };\n } finally {\n try {\n await client.close();\n } catch (error) {\n onEvent({\n type: \"activity\",\n activity: {\n id: \"runtime.cleanup\",\n kind: \"message\",\n status: \"failed\",\n description: `Hosted scan cleanup failed: ${errorMessage(error)}`,\n paths: [],\n },\n });\n }\n }\n}\n\nexport type HostedScanResult = Awaited<ReturnType<typeof runHostedScan>>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-scan.d.ts","sourceRoot":"","sources":["../src/import-scan.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"import-scan.d.ts","sourceRoot":"","sources":["../src/import-scan.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAWvD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAYL,mBAAmB,EACnB,YAAY,EAEZ,KAAK,kBAAkB,EAExB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,IAAI,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,YAAY,CAAC,EAAE,OAAO,YAAY,CAAC;IACnC,mBAAmB,CAAC,EAAE,OAAO,mBAAmB,CAAC;CAClD;AAmDD,mFAAmF;AACnF,wBAAsB,UAAU,CAC9B,OAAO,EAAE,iBAAiB,EAC1B,YAAY,GAAE,sBAA2B,GACxC,OAAO,CAAC,UAAU,GAAG,iBAAiB,CAAC,CAqPzC"}
|
package/dist/import-scan.js
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { workbenchArgs } from "./workbench-arguments.js";
|
|
1
10
|
import { createHash } from "node:crypto";
|
|
2
11
|
import { constants } from "node:fs";
|
|
3
12
|
import { lstat, mkdir, mkdtemp, open, readFile, realpath, writeFile, } from "node:fs/promises";
|
|
4
13
|
import { tmpdir } from "node:os";
|
|
5
14
|
import { basename, dirname, join, resolve } from "node:path";
|
|
15
|
+
import { pathToFileURL } from "node:url";
|
|
6
16
|
import { loadContract, sameCheckedFileDevice } from "./contract.js";
|
|
7
17
|
import { CodexSecurityError, ScanInterruptedError, errorMessage, } from "./errors.js";
|
|
8
18
|
import { bindImportedFindings, parseImportedFindings, } from "./findings-import.js";
|
|
9
19
|
import { ScanResult } from "./result.js";
|
|
10
|
-
import { cleanupSdkDirectory, codexSecurityStateDirectory, expandHome, pluginMetadata,
|
|
20
|
+
import { bundledPluginRoot, cleanupSdkDirectory, codexSecurityStateDirectory, expandHome, pluginMetadata, prepareScanRegistrationOutput, preparePersistentOutputRoot, requireOutputOutsideRepository, requirePrivateOutputDirectory, requireSecureOutputAncestry, resolvePluginPath, resolvePluginPython, runWorkbench, validateOutputDir, } from "./runtime.js";
|
|
11
21
|
const IMPORT_DESCRIPTION = "Imported findings; no security analysis was performed. Coverage is unknown. Source locations describe the imported reports.";
|
|
12
22
|
async function readImportSource(inputPath, signal) {
|
|
13
23
|
signal?.throwIfAborted();
|
|
@@ -56,7 +66,21 @@ export async function importScan(options, dependencies = {}) {
|
|
|
56
66
|
let scanDir = "";
|
|
57
67
|
try {
|
|
58
68
|
const pluginRoot = await resolvePluginPath(options.config?.pluginPath, workspace, signal);
|
|
59
|
-
const findings = await parseImportedFindings(
|
|
69
|
+
const findings = await parseImportedFindings(new TextDecoder("utf-8", { fatal: true }).decode(source), options.format, pluginRoot);
|
|
70
|
+
const helper = (await import(__rewriteRelativeImportExtension(pathToFileURL(join(await bundledPluginRoot(), "mcp/helpers.mjs")).href))).default;
|
|
71
|
+
try {
|
|
72
|
+
helper.parseCurrentFindings(findings.map((finding) => {
|
|
73
|
+
// Import assigns new identities and retains source metadata as provenance.
|
|
74
|
+
const { findingId, occurrenceId, fingerprints, writeup, ...content } = finding;
|
|
75
|
+
return {
|
|
76
|
+
...content,
|
|
77
|
+
provenance: { source: `${options.format}_import` },
|
|
78
|
+
};
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
throw new CodexSecurityError(`Imported findings do not match the current scan-draft finding contract: ${errorMessage(error)}`, { cause: error });
|
|
83
|
+
}
|
|
60
84
|
signal?.throwIfAborted();
|
|
61
85
|
await validateOutputDir(options.outputDir, options.archiveExisting);
|
|
62
86
|
if (options.dryRun) {
|
|
@@ -98,10 +122,7 @@ export async function importScan(options, dependencies = {}) {
|
|
|
98
122
|
const outputRoot = options.outputDir === undefined
|
|
99
123
|
? await preparePersistentOutputRoot(stateDirectory, "scans", "imports")
|
|
100
124
|
: undefined;
|
|
101
|
-
|
|
102
|
-
scanDir = await prepareOutputDir(options.outputDir, "import", outputRoot, (path) => requireOutputOutsideRepository(repository, path), options.archiveExisting, (path) => {
|
|
103
|
-
archivedScanDir = path;
|
|
104
|
-
});
|
|
125
|
+
scanDir = await prepareScanRegistrationOutput(options.outputDir, "import", outputRoot, (path) => requireOutputOutsideRepository(repository, path), options.archiveExisting);
|
|
105
126
|
const workbenchOptions = {
|
|
106
127
|
python,
|
|
107
128
|
pluginRoot,
|
|
@@ -109,21 +130,14 @@ export async function importScan(options, dependencies = {}) {
|
|
|
109
130
|
signal,
|
|
110
131
|
failureMessage: "Could not save the imported scan",
|
|
111
132
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
"--repository",
|
|
133
|
+
signal?.throwIfAborted();
|
|
134
|
+
const registration = await workbench(workbenchOptions, workbenchArgs("register-cli-scan", {
|
|
115
135
|
repository,
|
|
116
|
-
"--scan-dir",
|
|
117
136
|
scanDir,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
: ["--archived-scan-dir", archivedScanDir]),
|
|
123
|
-
...(options.parentScanId === undefined
|
|
124
|
-
? []
|
|
125
|
-
: ["--parent-scan-id", options.parentScanId]),
|
|
126
|
-
], JSON.stringify({
|
|
137
|
+
registrationJsonStdin: true,
|
|
138
|
+
archiveExisting: Boolean(options.archiveExisting),
|
|
139
|
+
parentScanId: options.parentScanId,
|
|
140
|
+
}), JSON.stringify({
|
|
127
141
|
recipe: {
|
|
128
142
|
repository,
|
|
129
143
|
target: { kind: "repository", paths: [] },
|
|
@@ -141,6 +155,7 @@ export async function importScan(options, dependencies = {}) {
|
|
|
141
155
|
throw new CodexSecurityError("The workbench returned an invalid import scan registration.");
|
|
142
156
|
}
|
|
143
157
|
activeScan = { id: scanId, options: workbenchOptions };
|
|
158
|
+
signal?.throwIfAborted();
|
|
144
159
|
const bound = bindImportedFindings(findings, options.format, scanId, targetId);
|
|
145
160
|
const sourceRef = `artifacts/import/source.${options.format}`;
|
|
146
161
|
await mkdir(join(scanDir, "artifacts", "import"), { recursive: true });
|
|
@@ -165,17 +180,18 @@ export async function importScan(options, dependencies = {}) {
|
|
|
165
180
|
},
|
|
166
181
|
"findings.json": { findings: bound },
|
|
167
182
|
"coverage.json": {
|
|
168
|
-
completeness: "unknown",
|
|
169
183
|
inventoryStrategy: "custom",
|
|
170
|
-
surfaces:
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
184
|
+
surfaces: findings.length
|
|
185
|
+
? [
|
|
186
|
+
{
|
|
187
|
+
id: "import",
|
|
188
|
+
label: basename(inputPath),
|
|
189
|
+
disposition: "reported",
|
|
190
|
+
receiptRefs: [sourceRef],
|
|
191
|
+
notes: IMPORT_DESCRIPTION,
|
|
192
|
+
},
|
|
193
|
+
]
|
|
194
|
+
: [],
|
|
179
195
|
explicitExclusions: [],
|
|
180
196
|
deferred: [],
|
|
181
197
|
},
|
|
@@ -183,11 +199,7 @@ export async function importScan(options, dependencies = {}) {
|
|
|
183
199
|
for (const [name, document] of Object.entries(documents)) {
|
|
184
200
|
await writeFile(join(scanDir, name), `${JSON.stringify(document, null, 2)}\n`, { flag: "wx", signal });
|
|
185
201
|
}
|
|
186
|
-
await workbench(workbenchOptions,
|
|
187
|
-
"prepare-scan-completion",
|
|
188
|
-
"--scan-id",
|
|
189
|
-
scanId,
|
|
190
|
-
]);
|
|
202
|
+
await workbench(workbenchOptions, workbenchArgs("prepare-scan-completion", { scanId }));
|
|
191
203
|
// Finalization normally recovers partial output. An import must retain every supplied row.
|
|
192
204
|
const contract = await loadContract(scanDir, {
|
|
193
205
|
pluginRoot,
|
|
@@ -197,8 +209,7 @@ export async function importScan(options, dependencies = {}) {
|
|
|
197
209
|
});
|
|
198
210
|
const expectedIds = new Set(bound.map((finding) => finding.findingId));
|
|
199
211
|
if (contract.findings.findings.length !== findings.length ||
|
|
200
|
-
contract.findings.findings.some((finding) => !expectedIds.delete(finding.findingId))
|
|
201
|
-
expectedIds.size !== 0) {
|
|
212
|
+
contract.findings.findings.some((finding) => !expectedIds.delete(finding.findingId))) {
|
|
202
213
|
throw new CodexSecurityError("Import finalization did not preserve every input finding; the scan was not completed.");
|
|
203
214
|
}
|
|
204
215
|
await workbench(workbenchOptions, ["complete-scan", "--scan-id", scanId]);
|
|
@@ -220,8 +231,7 @@ export async function importScan(options, dependencies = {}) {
|
|
|
220
231
|
"fail-scan",
|
|
221
232
|
"--scan-id",
|
|
222
233
|
activeScan.id,
|
|
223
|
-
|
|
224
|
-
errorMessage(error).slice(0, 2400),
|
|
234
|
+
`--message=${errorMessage(error).slice(0, 2400)}`,
|
|
225
235
|
]).catch(() => undefined);
|
|
226
236
|
}
|
|
227
237
|
if (signal?.aborted) {
|
package/dist/import-scan.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-scan.js","sourceRoot":"","sources":["../src/import-scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,EAAE,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AC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CACpD;YACD,WAAW,CAAC,IAAI,KAAK,CAAC,EACtB,CAAC;YACD,MAAM,IAAI,kBAAkB,CAC1B,uFAAuF,CACxF,CAAC;QACJ,CAAC;QACD,MAAM,SAAS,CAAC,gBAAgB,EAAE,CAAC,eAAe,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;QAC1E,UAAU,GAAG,SAAS,CAAC;QACvB,OAAO,IAAI,UAAU,CAAC;YACpB,GAAG,QAAQ;YACX,OAAO;YACP,QAAQ,EAAE,EAAE;YACZ,UAAU,EAAE;gBACV,MAAM,EAAE,WAAW;gBACnB,QAAQ,EAAE,IAAI;gBACd,aAAa,EAAE,kBAAkB;aAClC;SACF,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,MAAM,SAAS,CAAC,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE;gBAC5D,WAAW;gBACX,WAAW;gBACX,UAAU,CAAC,EAAE;gBACb,WAAW;gBACX,YAAY,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;aACnC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;QACD,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,oBAAoB,CAC5B,wCAAwC,EACxC,OAAO,EACP,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,MAAM,mBAAmB,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { constants } from \"node:fs\";\nimport {\n lstat,\n mkdir,\n mkdtemp,\n open,\n readFile,\n realpath,\n writeFile,\n} from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { basename, dirname, join, resolve } from \"node:path\";\nimport type { CodexSecurityConfig } from \"./config.js\";\nimport { loadContract, sameCheckedFileDevice } from \"./contract.js\";\nimport {\n CodexSecurityError,\n ScanInterruptedError,\n errorMessage,\n} from \"./errors.js\";\nimport {\n bindImportedFindings,\n parseImportedFindings,\n} from \"./findings-import.js\";\nimport { ScanResult } from \"./result.js\";\nimport {\n cleanupSdkDirectory,\n codexSecurityStateDirectory,\n expandHome,\n pluginMetadata,\n prepareOutputDir,\n preparePersistentOutputRoot,\n requireOutputOutsideRepository,\n requirePrivateOutputDirectory,\n requireSecureOutputAncestry,\n resolvePluginPath,\n resolvePluginPython,\n runWorkbench,\n validateOutputDir,\n type ProcessEnvironment,\n type WorkbenchCommandOptions,\n} from \"./runtime.js\";\n\nexport interface ImportScanOptions {\n sourcePath: string;\n format: \"csv\" | \"json\";\n config?: CodexSecurityConfig;\n outputDir?: string;\n archiveExisting?: boolean;\n dryRun?: boolean;\n parentScanId?: string;\n signal?: AbortSignal;\n}\n\nexport interface ImportScanPreview {\n dryRun: true;\n inputPath: string;\n format: \"csv\" | \"json\";\n findingCount: number;\n}\n\nexport interface ImportScanDependencies {\n environment?: ProcessEnvironment;\n runWorkbench?: typeof runWorkbench;\n resolvePluginPython?: typeof resolvePluginPython;\n}\n\nconst IMPORT_DESCRIPTION =\n \"Imported findings; no security analysis was performed. Coverage is unknown. Source locations describe the imported reports.\";\n\nasync function readImportSource(\n inputPath: string,\n signal?: AbortSignal,\n): Promise<Buffer> {\n signal?.throwIfAborted();\n const selected = await lstat(inputPath, { bigint: true });\n if (!selected.isFile()) {\n throw new CodexSecurityError(\"Import source must be a regular file.\");\n }\n for (let parent = dirname(inputPath); ; parent = dirname(parent)) {\n signal?.throwIfAborted();\n if ((await lstat(parent)).isSymbolicLink()) {\n throw new CodexSecurityError(\n \"Import source must not traverse directory links. Use the direct filesystem path.\",\n );\n }\n if (dirname(parent) === parent) break;\n }\n const path = join(await realpath(dirname(inputPath)), basename(inputPath));\n const file = await open(\n path,\n constants.O_RDONLY |\n (constants.O_NOFOLLOW ?? 0) |\n (constants.O_NONBLOCK ?? 0),\n );\n try {\n signal?.throwIfAborted();\n const opened = await file.stat({ bigint: true });\n const current = await lstat(path, { bigint: true });\n if (\n !opened.isFile() ||\n !current.isFile() ||\n current.dev !== selected.dev ||\n current.ino !== selected.ino ||\n !(await sameCheckedFileDevice(file, { path, metadata: selected }, opened))\n ) {\n throw new CodexSecurityError(\n \"Import source must remain the selected regular file.\",\n );\n }\n return await file.readFile({ signal });\n } finally {\n await file.close();\n }\n}\n\n/** Save supplied findings through the normal scan completion and indexing flow. */\nexport async function importScan(\n options: ImportScanOptions,\n dependencies: ImportScanDependencies = {},\n): Promise<ScanResult | ImportScanPreview> {\n const { signal } = options;\n const environment = dependencies.environment ?? process.env;\n const inputPath = resolve(expandHome(options.sourcePath, environment));\n const source = await readImportSource(inputPath, signal);\n const workspace = await mkdtemp(\n join(await realpath(tmpdir()), \"codex-security-import-\"),\n );\n const workbench = dependencies.runWorkbench ?? runWorkbench;\n let activeScan: { id: string; options: WorkbenchCommandOptions } | undefined;\n let scanDir = \"\";\n try {\n const pluginRoot = await resolvePluginPath(\n options.config?.pluginPath,\n workspace,\n signal,\n );\n const findings = await parseImportedFindings(\n source.toString(\"utf8\"),\n options.format,\n pluginRoot,\n );\n signal?.throwIfAborted();\n await validateOutputDir(options.outputDir, options.archiveExisting);\n if (options.dryRun) {\n return {\n dryRun: true,\n inputPath,\n format: options.format,\n findingCount: findings.length,\n };\n }\n const plugin = await pluginMetadata(pluginRoot);\n const stateDirectory = codexSecurityStateDirectory(environment);\n const digest = createHash(\"sha256\")\n .update(options.format)\n .update(\"\\0\")\n .update(source)\n .digest(\"hex\");\n // A retained input directory is the scan target, independent of the caller's repository.\n const repository = await preparePersistentOutputRoot(\n stateDirectory,\n \"imports\",\n `${options.format}-${digest}`,\n );\n requirePrivateOutputDirectory(await lstat(repository), repository);\n await requireSecureOutputAncestry(repository);\n const sourcePath = join(repository, `source.${options.format}`);\n try {\n await writeFile(sourcePath, source, { flag: \"wx\", signal });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"EEXIST\") throw error;\n if (!(await readFile(sourcePath, { signal })).equals(source)) {\n throw new CodexSecurityError(\"The retained import source has changed.\");\n }\n }\n const python = await (\n dependencies.resolvePluginPython ?? resolvePluginPython\n )({\n configuredPath: options.config?.pythonPath,\n environment,\n protectedRoot: repository,\n signal,\n });\n const outputRoot =\n options.outputDir === undefined\n ? await preparePersistentOutputRoot(stateDirectory, \"scans\", \"imports\")\n : undefined;\n let archivedScanDir: string | undefined;\n scanDir = await prepareOutputDir(\n options.outputDir,\n \"import\",\n outputRoot,\n (path) => requireOutputOutsideRepository(repository, path),\n options.archiveExisting,\n (path) => {\n archivedScanDir = path;\n },\n );\n const workbenchOptions: WorkbenchCommandOptions = {\n python,\n pluginRoot,\n environment: { ...environment, CODEX_SECURITY_STATE_DIR: stateDirectory },\n signal,\n failureMessage: \"Could not save the imported scan\",\n };\n const registration = await workbench(\n workbenchOptions,\n [\n \"register-cli-scan\",\n \"--repository\",\n repository,\n \"--scan-dir\",\n scanDir,\n \"--registration-json-stdin\",\n ...(options.archiveExisting ? [\"--archive-existing\"] : []),\n ...(archivedScanDir === undefined\n ? []\n : [\"--archived-scan-dir\", archivedScanDir]),\n ...(options.parentScanId === undefined\n ? []\n : [\"--parent-scan-id\", options.parentScanId]),\n ],\n JSON.stringify({\n recipe: {\n repository,\n target: { kind: \"repository\", paths: [] },\n mode: \"standard\",\n pluginVersion: plugin.version,\n config: {},\n import: { format: options.format, sourcePath },\n },\n }),\n );\n const scanId = registration[\"scanId\"];\n const targetId = registration[\"targetId\"];\n if (\n typeof scanId !== \"string\" ||\n typeof targetId !== \"string\" ||\n registration[\"scanDir\"] !== scanDir\n ) {\n throw new CodexSecurityError(\n \"The workbench returned an invalid import scan registration.\",\n );\n }\n activeScan = { id: scanId, options: workbenchOptions };\n const bound = bindImportedFindings(\n findings,\n options.format,\n scanId,\n targetId,\n );\n const sourceRef = `artifacts/import/source.${options.format}`;\n await mkdir(join(scanDir, \"artifacts\", \"import\"), { recursive: true });\n await writeFile(join(scanDir, sourceRef), source, { flag: \"wx\", signal });\n const documents: Record<string, unknown> = {\n \"scan-manifest.json\": {\n scan: {\n target: { kind: \"directory_snapshot\" },\n scope: {\n summary: IMPORT_DESCRIPTION,\n runtimeStatus: \"imported\",\n limitations: [IMPORT_DESCRIPTION],\n },\n extensions: {\n import: {\n format: options.format,\n sourceRef,\n findingCount: findings.length,\n },\n },\n },\n },\n \"findings.json\": { findings: bound },\n \"coverage.json\": {\n completeness: \"unknown\",\n inventoryStrategy: \"custom\",\n surfaces: [\n {\n id: \"import\",\n label: basename(inputPath),\n disposition: \"reported\",\n receiptRefs: [sourceRef],\n notes: IMPORT_DESCRIPTION,\n },\n ],\n explicitExclusions: [],\n deferred: [],\n },\n };\n for (const [name, document] of Object.entries(documents)) {\n await writeFile(\n join(scanDir, name),\n `${JSON.stringify(document, null, 2)}\\n`,\n { flag: \"wx\", signal },\n );\n }\n await workbench(workbenchOptions, [\n \"prepare-scan-completion\",\n \"--scan-id\",\n scanId,\n ]);\n // Finalization normally recovers partial output. An import must retain every supplied row.\n const contract = await loadContract(scanDir, {\n pluginRoot,\n expectedScanId: scanId,\n workbenchValidated: true,\n signal,\n });\n const expectedIds = new Set(bound.map((finding) => finding.findingId));\n if (\n contract.findings.findings.length !== findings.length ||\n contract.findings.findings.some(\n (finding) => !expectedIds.delete(finding.findingId),\n ) ||\n expectedIds.size !== 0\n ) {\n throw new CodexSecurityError(\n \"Import finalization did not preserve every input finding; the scan was not completed.\",\n );\n }\n await workbench(workbenchOptions, [\"complete-scan\", \"--scan-id\", scanId]);\n activeScan = undefined;\n return new ScanResult({\n ...contract,\n scanDir,\n threadId: \"\",\n turnResult: {\n status: \"completed\",\n imported: true,\n finalResponse: IMPORT_DESCRIPTION,\n },\n });\n } catch (error) {\n if (activeScan !== undefined) {\n await workbench({ ...activeScan.options, signal: undefined }, [\n \"fail-scan\",\n \"--scan-id\",\n activeScan.id,\n \"--message\",\n errorMessage(error).slice(0, 2400),\n ]).catch(() => undefined);\n }\n if (signal?.aborted) {\n throw new ScanInterruptedError(\n \"Codex Security import was interrupted.\",\n scanDir,\n { cause: error },\n );\n }\n throw error;\n } finally {\n await cleanupSdkDirectory(workspace);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"import-scan.js","sourceRoot":"","sources":["../src/import-scan.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,2BAA2B,EAC3B,UAAU,EACV,cAAc,EACd,6BAA6B,EAC7B,2BAA2B,EAC3B,8BAA8B,EA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S,CAAC,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["import { workbenchArgs } from \"./workbench-arguments.js\";\nimport { createHash } from \"node:crypto\";\nimport { constants } from \"node:fs\";\nimport {\n lstat,\n mkdir,\n mkdtemp,\n open,\n readFile,\n realpath,\n writeFile,\n} from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { basename, dirname, join, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { CodexSecurityConfig } from \"./config.js\";\nimport { loadContract, sameCheckedFileDevice } from \"./contract.js\";\nimport {\n CodexSecurityError,\n ScanInterruptedError,\n errorMessage,\n} from \"./errors.js\";\nimport {\n bindImportedFindings,\n parseImportedFindings,\n} from \"./findings-import.js\";\nimport { ScanResult } from \"./result.js\";\nimport {\n bundledPluginRoot,\n cleanupSdkDirectory,\n codexSecurityStateDirectory,\n expandHome,\n pluginMetadata,\n prepareScanRegistrationOutput,\n preparePersistentOutputRoot,\n requireOutputOutsideRepository,\n requirePrivateOutputDirectory,\n requireSecureOutputAncestry,\n resolvePluginPath,\n resolvePluginPython,\n runWorkbench,\n validateOutputDir,\n type ProcessEnvironment,\n type WorkbenchCommandOptions,\n} from \"./runtime.js\";\n\nexport interface ImportScanOptions {\n sourcePath: string;\n format: \"csv\" | \"json\";\n config?: CodexSecurityConfig;\n outputDir?: string;\n archiveExisting?: boolean;\n dryRun?: boolean;\n parentScanId?: string;\n signal?: AbortSignal;\n}\n\nexport interface ImportScanPreview {\n dryRun: true;\n inputPath: string;\n format: \"csv\" | \"json\";\n findingCount: number;\n}\n\nexport interface ImportScanDependencies {\n environment?: ProcessEnvironment;\n runWorkbench?: typeof runWorkbench;\n resolvePluginPython?: typeof resolvePluginPython;\n}\n\nconst IMPORT_DESCRIPTION =\n \"Imported findings; no security analysis was performed. Coverage is unknown. Source locations describe the imported reports.\";\n\nasync function readImportSource(\n inputPath: string,\n signal?: AbortSignal,\n): Promise<Buffer> {\n signal?.throwIfAborted();\n const selected = await lstat(inputPath, { bigint: true });\n if (!selected.isFile()) {\n throw new CodexSecurityError(\"Import source must be a regular file.\");\n }\n for (let parent = dirname(inputPath); ; parent = dirname(parent)) {\n signal?.throwIfAborted();\n if ((await lstat(parent)).isSymbolicLink()) {\n throw new CodexSecurityError(\n \"Import source must not traverse directory links. Use the direct filesystem path.\",\n );\n }\n if (dirname(parent) === parent) break;\n }\n const path = join(await realpath(dirname(inputPath)), basename(inputPath));\n const file = await open(\n path,\n constants.O_RDONLY |\n (constants.O_NOFOLLOW ?? 0) |\n (constants.O_NONBLOCK ?? 0),\n );\n try {\n signal?.throwIfAborted();\n const opened = await file.stat({ bigint: true });\n const current = await lstat(path, { bigint: true });\n if (\n !opened.isFile() ||\n !current.isFile() ||\n current.dev !== selected.dev ||\n current.ino !== selected.ino ||\n !(await sameCheckedFileDevice(file, { path, metadata: selected }, opened))\n ) {\n throw new CodexSecurityError(\n \"Import source must remain the selected regular file.\",\n );\n }\n return await file.readFile({ signal });\n } finally {\n await file.close();\n }\n}\n\n/** Save supplied findings through the normal scan completion and indexing flow. */\nexport async function importScan(\n options: ImportScanOptions,\n dependencies: ImportScanDependencies = {},\n): Promise<ScanResult | ImportScanPreview> {\n const { signal } = options;\n const environment = dependencies.environment ?? process.env;\n const inputPath = resolve(expandHome(options.sourcePath, environment));\n const source = await readImportSource(inputPath, signal);\n const workspace = await mkdtemp(\n join(await realpath(tmpdir()), \"codex-security-import-\"),\n );\n const workbench = dependencies.runWorkbench ?? runWorkbench;\n let activeScan: { id: string; options: WorkbenchCommandOptions } | undefined;\n let scanDir = \"\";\n try {\n const pluginRoot = await resolvePluginPath(\n options.config?.pluginPath,\n workspace,\n signal,\n );\n const findings = await parseImportedFindings(\n new TextDecoder(\"utf-8\", { fatal: true }).decode(source),\n options.format,\n pluginRoot,\n );\n const helper = (\n await import(\n pathToFileURL(join(await bundledPluginRoot(), \"mcp/helpers.mjs\")).href\n )\n ).default;\n try {\n helper.parseCurrentFindings(\n findings.map((finding) => {\n // Import assigns new identities and retains source metadata as provenance.\n const { findingId, occurrenceId, fingerprints, writeup, ...content } =\n finding;\n return {\n ...content,\n provenance: { source: `${options.format}_import` },\n };\n }),\n );\n } catch (error) {\n throw new CodexSecurityError(\n `Imported findings do not match the current scan-draft finding contract: ${errorMessage(error)}`,\n { cause: error },\n );\n }\n signal?.throwIfAborted();\n await validateOutputDir(options.outputDir, options.archiveExisting);\n if (options.dryRun) {\n return {\n dryRun: true,\n inputPath,\n format: options.format,\n findingCount: findings.length,\n };\n }\n const plugin = await pluginMetadata(pluginRoot);\n const stateDirectory = codexSecurityStateDirectory(environment);\n const digest = createHash(\"sha256\")\n .update(options.format)\n .update(\"\\0\")\n .update(source)\n .digest(\"hex\");\n // A retained input directory is the scan target, independent of the caller's repository.\n const repository = await preparePersistentOutputRoot(\n stateDirectory,\n \"imports\",\n `${options.format}-${digest}`,\n );\n requirePrivateOutputDirectory(await lstat(repository), repository);\n await requireSecureOutputAncestry(repository);\n const sourcePath = join(repository, `source.${options.format}`);\n try {\n await writeFile(sourcePath, source, { flag: \"wx\", signal });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"EEXIST\") throw error;\n if (!(await readFile(sourcePath, { signal })).equals(source)) {\n throw new CodexSecurityError(\"The retained import source has changed.\");\n }\n }\n const python = await (\n dependencies.resolvePluginPython ?? resolvePluginPython\n )({\n configuredPath: options.config?.pythonPath,\n environment,\n protectedRoot: repository,\n signal,\n });\n const outputRoot =\n options.outputDir === undefined\n ? await preparePersistentOutputRoot(stateDirectory, \"scans\", \"imports\")\n : undefined;\n scanDir = await prepareScanRegistrationOutput(\n options.outputDir,\n \"import\",\n outputRoot,\n (path) => requireOutputOutsideRepository(repository, path),\n options.archiveExisting,\n );\n const workbenchOptions: WorkbenchCommandOptions = {\n python,\n pluginRoot,\n environment: { ...environment, CODEX_SECURITY_STATE_DIR: stateDirectory },\n signal,\n failureMessage: \"Could not save the imported scan\",\n };\n signal?.throwIfAborted();\n const registration = await workbench(\n workbenchOptions,\n workbenchArgs(\"register-cli-scan\", {\n repository,\n scanDir,\n registrationJsonStdin: true,\n archiveExisting: Boolean(options.archiveExisting),\n parentScanId: options.parentScanId,\n }),\n JSON.stringify({\n recipe: {\n repository,\n target: { kind: \"repository\", paths: [] },\n mode: \"standard\",\n pluginVersion: plugin.version,\n config: {},\n import: { format: options.format, sourcePath },\n },\n }),\n );\n const scanId = registration[\"scanId\"];\n const targetId = registration[\"targetId\"];\n if (\n typeof scanId !== \"string\" ||\n typeof targetId !== \"string\" ||\n registration[\"scanDir\"] !== scanDir\n ) {\n throw new CodexSecurityError(\n \"The workbench returned an invalid import scan registration.\",\n );\n }\n activeScan = { id: scanId, options: workbenchOptions };\n signal?.throwIfAborted();\n const bound = bindImportedFindings(\n findings,\n options.format,\n scanId,\n targetId,\n );\n const sourceRef = `artifacts/import/source.${options.format}`;\n await mkdir(join(scanDir, \"artifacts\", \"import\"), { recursive: true });\n await writeFile(join(scanDir, sourceRef), source, { flag: \"wx\", signal });\n const documents: Record<string, unknown> = {\n \"scan-manifest.json\": {\n scan: {\n target: { kind: \"directory_snapshot\" },\n scope: {\n summary: IMPORT_DESCRIPTION,\n runtimeStatus: \"imported\",\n limitations: [IMPORT_DESCRIPTION],\n },\n extensions: {\n import: {\n format: options.format,\n sourceRef,\n findingCount: findings.length,\n },\n },\n },\n },\n \"findings.json\": { findings: bound },\n \"coverage.json\": {\n inventoryStrategy: \"custom\",\n surfaces: findings.length\n ? [\n {\n id: \"import\",\n label: basename(inputPath),\n disposition: \"reported\",\n receiptRefs: [sourceRef],\n notes: IMPORT_DESCRIPTION,\n },\n ]\n : [],\n explicitExclusions: [],\n deferred: [],\n },\n };\n for (const [name, document] of Object.entries(documents)) {\n await writeFile(\n join(scanDir, name),\n `${JSON.stringify(document, null, 2)}\\n`,\n { flag: \"wx\", signal },\n );\n }\n await workbench(\n workbenchOptions,\n workbenchArgs(\"prepare-scan-completion\", { scanId }),\n );\n // Finalization normally recovers partial output. An import must retain every supplied row.\n const contract = await loadContract(scanDir, {\n pluginRoot,\n expectedScanId: scanId,\n workbenchValidated: true,\n signal,\n });\n const expectedIds = new Set(bound.map((finding) => finding.findingId));\n if (\n contract.findings.findings.length !== findings.length ||\n contract.findings.findings.some(\n (finding) => !expectedIds.delete(finding.findingId),\n )\n ) {\n throw new CodexSecurityError(\n \"Import finalization did not preserve every input finding; the scan was not completed.\",\n );\n }\n await workbench(workbenchOptions, [\"complete-scan\", \"--scan-id\", scanId]);\n activeScan = undefined;\n return new ScanResult({\n ...contract,\n scanDir,\n threadId: \"\",\n turnResult: {\n status: \"completed\",\n imported: true,\n finalResponse: IMPORT_DESCRIPTION,\n },\n });\n } catch (error) {\n if (activeScan !== undefined) {\n await workbench({ ...activeScan.options, signal: undefined }, [\n \"fail-scan\",\n \"--scan-id\",\n activeScan.id,\n `--message=${errorMessage(error).slice(0, 2400)}`,\n ]).catch(() => undefined);\n }\n if (signal?.aborted) {\n throw new ScanInterruptedError(\n \"Codex Security import was interrupted.\",\n scanDir,\n { cause: error },\n );\n }\n throw error;\n } finally {\n await cleanupSdkDirectory(workspace);\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export { exportArtifact } from "./artifact-export.js";
|
|
2
2
|
export type { ExportArtifactOptions, ArtifactExportResult, } from "./artifact-export.js";
|
|
3
3
|
export { CodexSecurity, createSecurity } from "./api.js";
|
|
4
|
+
export { runHostedScan, HostedScanInputSchema, HostedScanPreparationError, } from "./hosted-scan.js";
|
|
5
|
+
export type { HostedScanInput, HostedScanOptions, HostedScanResult, } from "./hosted-scan.js";
|
|
6
|
+
export type { ScanExecutor, ScanExecutionRequest, ScanExecutionResult, ScanExecutionEvent, } from "./scan-executor.js";
|
|
4
7
|
export { loadProjectConfig, resolveProjectConfig } from "./project-config.js";
|
|
5
8
|
export type { ResolvedProjectConfig, ProjectConfigProvenance, } from "./project-config.js";
|
|
6
9
|
export type { ProjectConfigInput, ProjectScope, } from "./project-config-schema.js";
|
|
7
10
|
export type { ScanSettings } from "./scan-settings.js";
|
|
8
11
|
export { classifySeverity } from "./classify-severity.js";
|
|
9
12
|
export { suggestOwners } from "./suggest-owners.js";
|
|
10
|
-
export type { OwnerFinding, OwnerIdentity, OwnerSuggestion, OwnerSuggestions, SuggestOwnersOptions, } from "./suggest-owners.js";
|
|
13
|
+
export type { OwnerFinding, CodeownerIdentity, OwnerIdentity, OwnerSuggestion, OwnerSuggestions, SuggestOwnersOptions, } from "./suggest-owners.js";
|
|
11
14
|
export type { ClassifySeverityOptions, SeverityClassificationFinding, SeverityClassification, SeverityAssessment, } from "./classify-severity.js";
|
|
12
15
|
export { classifyScanSeverity, classifyScanDirectorySeverity, } from "./classify-scan-severity.js";
|
|
13
16
|
export type { ClassifyScanSeverityOptions, ScanSeverityClassification, } from "./classify-scan-severity.js";
|
|
@@ -16,17 +19,18 @@ export type { ComponentDeduplicationSummary, ComponentReceipt, ComponentScanOpti
|
|
|
16
19
|
export { normalizeComponentPlan, planComponents } from "./component-plan.js";
|
|
17
20
|
export type { ComponentPlan, ComponentPlanningOptions, } from "./component-plan.js";
|
|
18
21
|
export { estimateScanCost } from "./cost.js";
|
|
19
|
-
export type { ScanCost, ScanSessionEvent } from "./cost.js";
|
|
22
|
+
export type { ScanCost, ScanSessionEvent, ScanWorkerEvent } from "./cost.js";
|
|
23
|
+
export type { ScanTokenUsage } from "./cost-model.js";
|
|
20
24
|
export type { DeepScanProgress } from "./deep-progress.js";
|
|
21
25
|
export type { CustomValidationResult } from "./custom-validation.js";
|
|
22
26
|
export type { ScanActivity, ScanActivityStatus } from "./scan-activity.js";
|
|
23
27
|
export { matchScanFindings } from "./scan-comparison.js";
|
|
24
28
|
export type { ScanComparisonInput, ScanComparisonOptions, ScanComparisonProgress, ScanComparisonResult, } from "./scan-comparison.js";
|
|
25
|
-
export type { CodexSecurityMetadata, DeepScanOptions, ScanAuthMode, ScanAuthentication, ScanBudget, ScanOptions, ScanPreflight, ScanReconnectDetails, ScanTrustedAccessStatus, ScanWarningDetails, ValidationOptions, ValidationResult, } from "./api.js";
|
|
29
|
+
export type { CodexSecurityMetadata, DeepScanOptions, PatchOptions, PatchResult, ScanAuthMode, ScanAuthentication, ScanBudget, ScanOptions, ScanPreflight, ScanReconnectDetails, ScanTrustedAccessStatus, ScanWarningDetails, ValidationOptions, ValidationResult, } from "./api.js";
|
|
26
30
|
export type { ScanPhase, ScanProgress, ScanWorkerPhase, ScanWorkerStatus, } from "./worker-progress.js";
|
|
27
31
|
export { CodexLoginHandle } from "./auth.js";
|
|
28
32
|
export type { AccountStatus, LoginResult } from "./auth.js";
|
|
29
|
-
export { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, ContractValidationError, DeduplicationReviewError, IncompleteScanError, InvalidTargetError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
33
|
+
export { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, ContractValidationError, DeduplicationReviewError, IncompleteScanError, InvalidTargetError, LocalPluginBootstrapError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
30
34
|
export type { DeduplicationReviewFailureCategory, DeduplicationReviewFailureMetadata, DeduplicationReviewStage, ProtectedScanPathKind, } from "./errors.js";
|
|
31
35
|
export { DEFAULT_CODEX_CONFIG, mergedCodexConfig, writeCodexConfig, } from "./config.js";
|
|
32
36
|
export type { CodexSecurityConfig, JsonObject, JsonValue } from "./config.js";
|
|
@@ -44,6 +48,9 @@ export type { DeduplicationReviewRequest, DeduplicationReviewAttribution, Dedupl
|
|
|
44
48
|
export { deduplicateScan, deduplicateScanDirectory, } from "./deduplication/scan.js";
|
|
45
49
|
export type { DeduplicateScanDirectoryOptions, DeduplicateScanOptions, DeduplicateScanResult, } from "./deduplication/scan.js";
|
|
46
50
|
export type { DeduplicationRefusal } from "./deduplication/deduplication.js";
|
|
51
|
+
export type { FindingEmbeddingBinding } from "./deduplication/local.js";
|
|
52
|
+
export type { DeduplicationDiagnostic, DeduplicationDiagnosticObserver, } from "./deduplication/diagnostics.js";
|
|
53
|
+
export type { FindingEmbedder } from "./server/embeddings.js";
|
|
47
54
|
export { importGitHubCodeScanningAlerts } from "./github.js";
|
|
48
55
|
export type { GitHubCodeScanningImportOptions, ImportedGitHubCodeScanningAlert, } from "./github.js";
|
|
49
56
|
export type { CheckScanPublicationOptions, CheckScanPublicationResult, PublishScanOptions, PublishScanProgress, PublishScanResult, } from "./publish.js";
|