@openai/codex-security 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +437 -2692
- package/_bundled_plugin/.app.json +5 -1
- package/_bundled_plugin/.codex-plugin/plugin.json +9 -5
- 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 +563 -0
- package/_bundled_plugin/mcp/server.mjs +1 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/preflight/capability-profiles.toml +0 -13
- package/_bundled_plugin/references/artifact-storage.md +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 +10 -12
- 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 +1 -47
- package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +2 -24
- package/_bundled_plugin/schemas/definitions/discovery-candidate.schema.json +49 -25
- package/_bundled_plugin/schemas/findings.schema.json +71 -192
- package/_bundled_plugin/schemas/scan-manifest.schema.json +18 -45
- 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 +315 -232
- 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 +99 -829
- 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 +117 -172
- 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 +94 -179
- package/_bundled_plugin/scripts/workbench_db.py +427 -463
- 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 +33 -57
- 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 +23 -34
- 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 +16 -27
- package/_bundled_plugin/shared/workbench-history-repairs.json +218 -0
- package/_bundled_plugin/shared/workbench-migrations.json +397 -0
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +15 -4
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +54 -0
- package/_bundled_plugin/skills/cloud-findings/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/finding-discovery/SKILL.md +3 -3
- package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +50 -20
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +8 -14
- package/_bundled_plugin/skills/security-diff-scan/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/security-scan/SKILL.md +22 -7
- package/_bundled_plugin/skills/security-scan/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +1 -1
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +13 -1
- package/_bundled_plugin/skills/threat-model/SKILL.md +1 -1
- package/_bundled_plugin/skills/track-findings/SKILL.md +46 -178
- package/_bundled_plugin/skills/track-findings/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +16 -24
- package/_bundled_plugin/skills/track-findings/references/jira.md +15 -61
- package/_bundled_plugin/skills/triage-finding/SKILL.md +50 -289
- package/_bundled_plugin/skills/triage-finding/agents/openai.yaml +2 -2
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +23 -43
- package/_bundled_plugin/skills/triage-finding/references/triage-result-contract.md +7 -1
- package/bin/codex-security.mjs +9 -2
- package/dist/api.d.ts +60 -10
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +803 -380
- 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 +1087 -900
- 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 +38 -30
- 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 +23 -35
- 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 +15 -3
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +87 -252
- 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 +7 -1
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +126 -17
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +5 -2
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +18 -4
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +26 -4
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +57 -47
- 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.map +1 -1
- package/dist/deduplication/records-protocol.js +11 -24
- 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 +2 -0
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +13 -10
- 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/feedback.d.ts.map +1 -1
- package/dist/feedback.js +53 -21
- package/dist/feedback.js.map +1 -1
- package/dist/finding-catalogue.d.ts.map +1 -1
- package/dist/finding-catalogue.js +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/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 +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -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 +193 -126
- 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 +40 -64
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts +1 -2
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +2 -8
- 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 +15 -4
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +430 -138
- 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-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 +106 -47
- 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 +1 -0
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +27 -12
- package/dist/worker-progress.js.map +1 -1
- package/docs/cli.md +1778 -0
- package/docs/findings-service.md +402 -0
- package/package.json +18 -19
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hash, randomUUID } from "node:crypto";
|
|
2
|
-
import { z } from "
|
|
2
|
+
import { z } from "zod";
|
|
3
3
|
import { DeduplicationReviewError } from "../errors.js";
|
|
4
4
|
import { abortable } from "../targets.js";
|
|
5
5
|
import { FindingDeduplicator } from "./deduplication.js";
|
|
@@ -27,24 +27,18 @@ export function recordsReviewAttribution(findingIds, references, anchors) {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
const id = z.string().min(1);
|
|
30
|
-
const record = z
|
|
31
|
-
.object({
|
|
30
|
+
const record = z.strictObject({
|
|
32
31
|
id,
|
|
33
32
|
finding: z.unknown().transform((value) => requireFinding(value)),
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
const deduplicateRecordsInputSchema = z
|
|
37
|
-
.object({
|
|
33
|
+
});
|
|
34
|
+
const deduplicateRecordsInputSchema = z.strictObject({
|
|
38
35
|
version: z.literal(1),
|
|
39
36
|
observations: z.array(record),
|
|
40
|
-
candidateRelationships: z.array(z
|
|
41
|
-
.object({
|
|
37
|
+
candidateRelationships: z.array(z.strictObject({
|
|
42
38
|
observationId: id,
|
|
43
39
|
candidateObservationIds: z.array(id),
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
})
|
|
47
|
-
.strict();
|
|
40
|
+
})),
|
|
41
|
+
});
|
|
48
42
|
/** Pure records workflow: no retrieval, local model execution, or persistence. */
|
|
49
43
|
export async function deduplicateRecords(input, options) {
|
|
50
44
|
options.signal?.throwIfAborted();
|
|
@@ -77,7 +71,7 @@ export async function deduplicateRecords(input, options) {
|
|
|
77
71
|
groups: [],
|
|
78
72
|
unresolved: [],
|
|
79
73
|
};
|
|
80
|
-
const
|
|
74
|
+
const sourceFindingIds = [...relationships.keys()].map((id) => observations.get(id).findingId);
|
|
81
75
|
const reviewer = new CodexDeduplicationReviewer({
|
|
82
76
|
async run({ validate, findingIds, ...review }) {
|
|
83
77
|
try {
|
|
@@ -122,7 +116,7 @@ export async function deduplicateRecords(input, options) {
|
|
|
122
116
|
}, reviewer, options.signal, 1);
|
|
123
117
|
let groups;
|
|
124
118
|
try {
|
|
125
|
-
const decisions = await algorithm.run(
|
|
119
|
+
const decisions = await algorithm.run(sourceFindingIds);
|
|
126
120
|
options.signal?.throwIfAborted();
|
|
127
121
|
groups = decisions.duplicateGroups;
|
|
128
122
|
}
|
|
@@ -137,9 +131,7 @@ export async function deduplicateRecords(input, options) {
|
|
|
137
131
|
return result;
|
|
138
132
|
}
|
|
139
133
|
const grouped = new Set(groups.flat());
|
|
140
|
-
groups.push(...
|
|
141
|
-
.filter((finding) => !grouped.has(finding.findingId))
|
|
142
|
-
.map((finding) => [finding.findingId]));
|
|
134
|
+
groups.push(...sourceFindingIds.filter((id) => !grouped.has(id)).map((id) => [id]));
|
|
143
135
|
for (const group of groups) {
|
|
144
136
|
const observationIds = group.map((id) => references.get(id));
|
|
145
137
|
result.groups.push({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"records.js","sourceRoot":"","sources":["../../src/deduplication/records.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,CAAC,EAAE,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM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MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC,CAAC;QAC9D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;YACjB,2BAA2B,EAAE,cAAc,CAAC,CAAC,CAAE;YAC/C,cAAc;SACf,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { hash, randomUUID } from \"node:crypto\";\nimport { z } from \"incur\";\nimport { DeduplicationReviewError } from \"../errors.js\";\nimport type { Finding } from \"../models.js\";\nimport { abortable } from \"../targets.js\";\nimport type { CodexReview } from \"./codex-review.js\";\nimport { FindingDeduplicator } from \"./deduplication.js\";\nimport { CodexDeduplicationReviewer } from \"./deduplication-reviewer.js\";\nimport { findingSchema, requireFinding } from \"./finding-schema.js\";\nimport {\n sourceReviewInstructions,\n screeningInstructions,\n pairReviewInstructions,\n screeningFindingFormatInstructions,\n pairFindingFormatInstructions,\n} from \"./deduplication-prompts.js\";\nimport type {\n DeduplicationReviewAttribution,\n DeduplicationReviewRunner,\n} from \"./review.js\";\n\nexport function recordsReviewAttribution(\n findingIds: readonly string[] | undefined,\n references: ReadonlyMap<string, string>,\n anchors: ReadonlyMap<string, readonly string[]>,\n): DeduplicationReviewAttribution {\n if (!findingIds?.length)\n throw new Error(\"Records review is missing its comparison participants.\");\n const participants = new Set(\n findingIds.map((findingId) => {\n const observationId = references.get(findingId);\n if (observationId === undefined)\n throw new Error(`Unknown records review finding ID: ${findingId}`);\n return observationId;\n }),\n );\n const beneficiaryObservationIds = [\n ...participants.intersection(anchors),\n ].sort();\n if (beneficiaryObservationIds.length === 0)\n throw new Error(\"Records review has no incoming observation participants.\");\n return {\n version: 1,\n beneficiaryObservationIds,\n contextObservationIds: [...participants.difference(anchors)].sort(),\n };\n}\n\nconst id = z.string().min(1);\nconst record = z\n .object({\n id,\n finding: z.unknown().transform((value) => requireFinding(value)),\n })\n .strict();\n\nconst deduplicateRecordsInputSchema: z.ZodType<DeduplicateRecordsInput> = z\n .object({\n version: z.literal(1),\n observations: z.array(record),\n candidateRelationships: z.array(\n z\n .object({\n observationId: id,\n candidateObservationIds: z.array(id),\n })\n .strict(),\n ),\n })\n .strict();\n\nexport interface DeduplicateRecordsInput {\n version: 1;\n observations: { id: string; finding: Finding }[];\n candidateRelationships: {\n observationId: string;\n candidateObservationIds: string[];\n }[];\n}\nexport interface DeduplicateRecordsOptions {\n reviewRunner: DeduplicationReviewRunner;\n signal?: AbortSignal;\n}\nexport interface DeduplicateRecordsResult {\n version: 1;\n status: \"completed\" | \"unresolved\";\n groups: {\n representativeObservationId: string;\n observationIds: string[];\n }[];\n unresolved: {\n observationId: string;\n reason: \"review_failed\";\n message: string;\n }[];\n}\n\n/** Pure records workflow: no retrieval, local model execution, or persistence. */\nexport async function deduplicateRecords(\n input: DeduplicateRecordsInput,\n options: DeduplicateRecordsOptions,\n): Promise<DeduplicateRecordsResult> {\n options.signal?.throwIfAborted();\n // Snapshot before yielding: a host cannot mutate evidence during the review.\n const data = deduplicateRecordsInputSchema.parse(structuredClone(input));\n const references = new Map<string, string>();\n const observations = new Map<string, Finding>();\n for (const entry of data.observations) {\n if (observations.has(entry.id))\n throw new Error(`Duplicate observation ID: ${entry.id}`);\n // Original finding IDs can repeat across scans; host IDs identify observations.\n const findingId = `csf_${hash(\"sha256\", entry.id).slice(0, 24)}`;\n observations.set(entry.id, { ...entry.finding, findingId });\n references.set(findingId, entry.id);\n }\n const relationships = new Map<string, string[]>();\n for (const relation of data.candidateRelationships) {\n if (\n !observations.has(relation.observationId) ||\n relationships.has(relation.observationId)\n )\n throw new Error(\n \"Each candidate relationship must name a different supplied observation.\",\n );\n if (\n new Set(relation.candidateObservationIds).size !==\n relation.candidateObservationIds.length ||\n relation.candidateObservationIds.some(\n (id) => id === relation.observationId || !observations.has(id),\n )\n )\n throw new Error(\n \"Candidates must name distinct supplied observations other than the anchor.\",\n );\n relationships.set(relation.observationId, relation.candidateObservationIds);\n }\n const result: DeduplicateRecordsResult = {\n version: 1,\n status: \"completed\",\n groups: [],\n unresolved: [],\n };\n const sourceFindings = [...relationships.keys()].map((id) =>\n observations.get(id)!,\n );\n const reviewer = new CodexDeduplicationReviewer({\n async run<T>({\n validate,\n findingIds,\n ...review\n }: CodexReview<T>): Promise<T> {\n try {\n return await abortable(async () => {\n options.signal?.throwIfAborted();\n return validate(\n await options.reviewRunner.run(\n {\n ...review,\n requestId: randomUUID(),\n attribution: recordsReviewAttribution(\n findingIds,\n references,\n relationships,\n ),\n trustedInstructions: [\n sourceReviewInstructions,\n review.stage === \"screening\"\n ? screeningInstructions\n : pairReviewInstructions,\n review.stage === \"screening\"\n ? screeningFindingFormatInstructions\n : pairFindingFormatInstructions,\n ].join(\"\\n\\n\"),\n findingSchema: findingSchema(),\n },\n { signal: options.signal },\n ),\n );\n }, options.signal);\n } catch (error) {\n // Records mode discards the batch after any failed review.\n if (\n error instanceof DeduplicationReviewError &&\n error.metadata.category === \"refusal\"\n )\n throw new Error(error.message, { cause: error });\n throw error;\n }\n },\n });\n const algorithm = new FindingDeduplicator(\n {\n async potentialDuplicates(findingId) {\n const observationId = references.get(findingId)!;\n return {\n finding: observations.get(observationId)!,\n potentialDuplicates: relationships\n .get(observationId)!\n .map((id) => observations.get(id)!),\n };\n },\n },\n reviewer,\n options.signal,\n 1,\n );\n let groups: string[][];\n try {\n const decisions = await algorithm.run(\n sourceFindings.map((finding) => finding.findingId),\n );\n options.signal?.throwIfAborted();\n groups = decisions.duplicateGroups;\n } catch (error) {\n options.signal?.throwIfAborted();\n result.status = \"unresolved\";\n result.unresolved = [...relationships.keys()].map((id) => ({\n observationId: id,\n reason: \"review_failed\",\n message:\n error instanceof Error ? error.message : \"Review did not complete.\",\n }));\n return result;\n }\n const grouped = new Set(groups.flat());\n groups.push(\n ...sourceFindings\n .filter((finding) => !grouped.has(finding.findingId))\n .map((finding) => [finding.findingId]),\n );\n for (const group of groups) {\n const observationIds = group.map((id) => references.get(id)!);\n result.groups.push({\n representativeObservationId: observationIds[0]!,\n observationIds,\n });\n }\n return result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"records.js","sourceRoot":"","sources":["../../src/deduplication/records.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,kCAAkC,EAClC,6BAA6B,GAC9B,MAAM,4BAA4B,CAAC;AAMpC,MAAM,UAAU,wBAAwB,CACtC,UAAyC,EACzC,UAAuC,EACvC,OAA+C;IAE/C,IAAI,CAAC,UAAU,EAAE,MAAM;QACrB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,MAAM,YAAY,GAAG,IAAI,GAAG,CAC1B,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;QAC3B,MAAM,aAAa,GAAG,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAChD,IAAI,aAAa,KAAK,SAAS;YAC7B,MAAM,IAAI,KAAK,CAAC,sCAAsC,SAAS,EAAE,CAAC,CAAC;QACrE,OAAO,aAAa,CAAC;IACvB,CAAC,CAAC,CACH,CAAC;IACF,MAAM,yBAAyB,GAAG;QAChC,GAAG,YAAY,CAAC,YAAY,CA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AO,EACL,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B;SACtE,CAAC,CAAC,CAAC;QACJ,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,MAAM,CAAC,IAAI,CACT,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CACvE,CAAC;IACF,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC,CAAC;QAC9D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;YACjB,2BAA2B,EAAE,cAAc,CAAC,CAAC,CAAE;YAC/C,cAAc;SACf,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { hash, randomUUID } from \"node:crypto\";\nimport { z } from \"zod\";\nimport { DeduplicationReviewError } from \"../errors.js\";\nimport type { Finding } from \"../models.js\";\nimport { abortable } from \"../targets.js\";\nimport type { CodexReview } from \"./codex-review.js\";\nimport { FindingDeduplicator } from \"./deduplication.js\";\nimport { CodexDeduplicationReviewer } from \"./deduplication-reviewer.js\";\nimport { findingSchema, requireFinding } from \"./finding-schema.js\";\nimport {\n sourceReviewInstructions,\n screeningInstructions,\n pairReviewInstructions,\n screeningFindingFormatInstructions,\n pairFindingFormatInstructions,\n} from \"./deduplication-prompts.js\";\nimport type {\n DeduplicationReviewAttribution,\n DeduplicationReviewRunner,\n} from \"./review.js\";\n\nexport function recordsReviewAttribution(\n findingIds: readonly string[] | undefined,\n references: ReadonlyMap<string, string>,\n anchors: ReadonlyMap<string, readonly string[]>,\n): DeduplicationReviewAttribution {\n if (!findingIds?.length)\n throw new Error(\"Records review is missing its comparison participants.\");\n const participants = new Set(\n findingIds.map((findingId) => {\n const observationId = references.get(findingId);\n if (observationId === undefined)\n throw new Error(`Unknown records review finding ID: ${findingId}`);\n return observationId;\n }),\n );\n const beneficiaryObservationIds = [\n ...participants.intersection(anchors),\n ].sort();\n if (beneficiaryObservationIds.length === 0)\n throw new Error(\"Records review has no incoming observation participants.\");\n return {\n version: 1,\n beneficiaryObservationIds,\n contextObservationIds: [...participants.difference(anchors)].sort(),\n };\n}\n\nconst id = z.string().min(1);\nconst record = z.strictObject({\n id,\n finding: z.unknown().transform((value) => requireFinding(value)),\n});\n\nconst deduplicateRecordsInputSchema = z.strictObject({\n version: z.literal(1),\n observations: z.array(record),\n candidateRelationships: z.array(\n z.strictObject({\n observationId: id,\n candidateObservationIds: z.array(id),\n }),\n ),\n});\n\nexport interface DeduplicateRecordsInput extends z.infer<\n typeof deduplicateRecordsInputSchema\n> {}\nexport interface DeduplicateRecordsOptions {\n reviewRunner: DeduplicationReviewRunner;\n signal?: AbortSignal;\n}\nexport interface DeduplicateRecordsResult {\n version: 1;\n status: \"completed\" | \"unresolved\";\n groups: {\n representativeObservationId: string;\n observationIds: string[];\n }[];\n unresolved: {\n observationId: string;\n reason: \"review_failed\";\n message: string;\n }[];\n}\n\n/** Pure records workflow: no retrieval, local model execution, or persistence. */\nexport async function deduplicateRecords(\n input: DeduplicateRecordsInput,\n options: DeduplicateRecordsOptions,\n): Promise<DeduplicateRecordsResult> {\n options.signal?.throwIfAborted();\n // Snapshot before yielding: a host cannot mutate evidence during the review.\n const data = deduplicateRecordsInputSchema.parse(structuredClone(input));\n const references = new Map<string, string>();\n const observations = new Map<string, Finding>();\n for (const entry of data.observations) {\n if (observations.has(entry.id))\n throw new Error(`Duplicate observation ID: ${entry.id}`);\n // Original finding IDs can repeat across scans; host IDs identify observations.\n const findingId = `csf_${hash(\"sha256\", entry.id).slice(0, 24)}`;\n observations.set(entry.id, { ...entry.finding, findingId });\n references.set(findingId, entry.id);\n }\n const relationships = new Map<string, string[]>();\n for (const relation of data.candidateRelationships) {\n if (\n !observations.has(relation.observationId) ||\n relationships.has(relation.observationId)\n )\n throw new Error(\n \"Each candidate relationship must name a different supplied observation.\",\n );\n if (\n new Set(relation.candidateObservationIds).size !==\n relation.candidateObservationIds.length ||\n relation.candidateObservationIds.some(\n (id) => id === relation.observationId || !observations.has(id),\n )\n )\n throw new Error(\n \"Candidates must name distinct supplied observations other than the anchor.\",\n );\n relationships.set(relation.observationId, relation.candidateObservationIds);\n }\n const result: DeduplicateRecordsResult = {\n version: 1,\n status: \"completed\",\n groups: [],\n unresolved: [],\n };\n const sourceFindingIds = [...relationships.keys()].map(\n (id) => observations.get(id)!.findingId,\n );\n const reviewer = new CodexDeduplicationReviewer({\n async run<T>({\n validate,\n findingIds,\n ...review\n }: CodexReview<T>): Promise<T> {\n try {\n return await abortable(async () => {\n options.signal?.throwIfAborted();\n return validate(\n await options.reviewRunner.run(\n {\n ...review,\n requestId: randomUUID(),\n attribution: recordsReviewAttribution(\n findingIds,\n references,\n relationships,\n ),\n trustedInstructions: [\n sourceReviewInstructions,\n review.stage === \"screening\"\n ? screeningInstructions\n : pairReviewInstructions,\n review.stage === \"screening\"\n ? screeningFindingFormatInstructions\n : pairFindingFormatInstructions,\n ].join(\"\\n\\n\"),\n findingSchema: findingSchema(),\n },\n { signal: options.signal },\n ),\n );\n }, options.signal);\n } catch (error) {\n // Records mode discards the batch after any failed review.\n if (\n error instanceof DeduplicationReviewError &&\n error.metadata.category === \"refusal\"\n )\n throw new Error(error.message, { cause: error });\n throw error;\n }\n },\n });\n const algorithm = new FindingDeduplicator(\n {\n async potentialDuplicates(findingId) {\n const observationId = references.get(findingId)!;\n return {\n finding: observations.get(observationId)!,\n potentialDuplicates: relationships\n .get(observationId)!\n .map((id) => observations.get(id)!),\n };\n },\n },\n reviewer,\n options.signal,\n 1,\n );\n let groups: string[][];\n try {\n const decisions = await algorithm.run(sourceFindingIds);\n options.signal?.throwIfAborted();\n groups = decisions.duplicateGroups;\n } catch (error) {\n options.signal?.throwIfAborted();\n result.status = \"unresolved\";\n result.unresolved = [...relationships.keys()].map((id) => ({\n observationId: id,\n reason: \"review_failed\",\n message:\n error instanceof Error ? error.message : \"Review did not complete.\",\n }));\n return result;\n }\n const grouped = new Set(groups.flat());\n groups.push(\n ...sourceFindingIds.filter((id) => !grouped.has(id)).map((id) => [id]),\n );\n for (const group of groups) {\n const observationIds = group.map((id) => references.get(id)!);\n result.groups.push({\n representativeObservationId: observationIds[0]!,\n observationIds,\n });\n }\n return result;\n}\n"]}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { type DeduplicationResult } from "./deduplication.js";
|
|
2
|
+
import { type FindingEmbeddingBinding } from "./local.js";
|
|
3
|
+
import { type DeduplicationDiagnosticObserver } from "./diagnostics.js";
|
|
2
4
|
export interface DeduplicateScanOptions {
|
|
3
|
-
/** Resume the named
|
|
5
|
+
/** Resume the named findings workflow; remote mode includes custom publication. */
|
|
4
6
|
workflowId?: string;
|
|
5
|
-
/** Findings API
|
|
6
|
-
findingsUrl
|
|
7
|
+
/** Optional Findings API. Omit to prepare and deduplicate findings in local SQLite. */
|
|
8
|
+
findingsUrl?: string;
|
|
9
|
+
/** Custom vector space for local deduplication; cannot be combined with findingsUrl. */
|
|
10
|
+
embedding?: FindingEmbeddingBinding;
|
|
7
11
|
/** Search all repositories instead of the scan's targetId. Defaults to false. */
|
|
8
12
|
allRepositories?: boolean;
|
|
9
13
|
/** Shared concurrency limit for deduplication jobs. Defaults to 8. */
|
|
10
14
|
concurrency?: number;
|
|
15
|
+
/** Best-effort progress and native review diagnostics; observer failures are ignored. */
|
|
16
|
+
onDiagnostic?: DeduplicationDiagnosticObserver;
|
|
11
17
|
signal?: AbortSignal;
|
|
12
18
|
}
|
|
13
19
|
export interface DeduplicateScanDirectoryOptions extends DeduplicateScanOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/deduplication/scan.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/deduplication/scan.ts"],"names":[],"mappings":"AAiBA,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAqB5B,OAAO,EAAsB,KAAK,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAQ9E,OAAO,EAEL,KAAK,+BAA+B,EACrC,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,sBAAsB;IACrC,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uFAAuF;IACvF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wFAAwF;IACxF,SAAS,CAAC,EAAE,uBAAuB,CAAC;IACpC,iFAAiF;IACjF,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yFAAyF;IACzF,YAAY,CAAC,EAAE,+BAA+B,CAAC;IAC/C,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,+BAAgC,SAAQ,sBAAsB;IAC7E,qEAAqE;IACrE,UAAU,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB;IAChE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,8FAA8F;AAC9F,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,qBAAqB,CAAC,CAEhC;AAED,qFAAqF;AACrF,wBAAsB,wBAAwB,CAC5C,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,qBAAqB,CAAC,CAEhC"}
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { loadContractWithScanDirectory } from "../contract.js";
|
|
2
|
-
import {
|
|
2
|
+
import { environmentEntry } from "../auth.js";
|
|
3
|
+
import { bundledPluginRoot, codexSecurityStateDirectory, canonicalizeModelSafePath, } from "../runtime.js";
|
|
3
4
|
import { resolveCompletedScan, } from "../saved-scan.js";
|
|
4
|
-
import {
|
|
5
|
+
import { savedScanWorkbench } from "../saved-scan-bootstrap.js";
|
|
6
|
+
import { CodexReviewRunner, reviewSqliteHome } from "./codex-review.js";
|
|
7
|
+
import { mkdir } from "node:fs/promises";
|
|
8
|
+
import { isWithin } from "../trusted-executable.js";
|
|
5
9
|
import { FindingDeduplicator, deduplicationConcurrency, } from "./deduplication.js";
|
|
6
|
-
import {
|
|
10
|
+
import { CodexGroupingReviewer, } from "./deduplication-reviewer.js";
|
|
7
11
|
import { FindingsClient } from "../findings-client.js";
|
|
8
12
|
import { FindingWorkflow, workflowDestination, workflowDigest, } from "../finding-workflow.js";
|
|
9
13
|
import { publishScanToCustomInternal } from "../custom-publish.js";
|
|
10
14
|
import { CheckpointedReviewRunner, reviewSettingsDigest, } from "./checkpointed-review.js";
|
|
11
15
|
import { normalizeRepository } from "../targets.js";
|
|
16
|
+
import { LocalDeduplication } from "./local.js";
|
|
17
|
+
import { configuredCodexHome, readCodexHomeConfig } from "../auth.js";
|
|
18
|
+
import { CodexSecurityError } from "../errors.js";
|
|
19
|
+
import { comparisonEnvironment } from "../scan-comparison.js";
|
|
20
|
+
import { isDeepStrictEqual } from "node:util";
|
|
21
|
+
import { isRecord } from "../record.js";
|
|
22
|
+
import { resolveCodexProfile } from "../config.js";
|
|
23
|
+
import { savedSourceContext } from "./deduplication-prompts.js";
|
|
24
|
+
import { emitDiagnostic, } from "./diagnostics.js";
|
|
12
25
|
/** Review a saved scan against embedding candidates and persist accepted duplicate groups. */
|
|
13
26
|
export async function deduplicateScan(scanId, options) {
|
|
14
27
|
return await deduplicateScanInternal(scanId, options);
|
|
@@ -29,41 +42,47 @@ export async function deduplicateScanInternal(scanId, options, dependencies = {}
|
|
|
29
42
|
deduplicationConcurrency(options.concurrency);
|
|
30
43
|
const environment = dependencies.environment ?? process.env;
|
|
31
44
|
const pluginRoot = await bundledPluginRoot();
|
|
45
|
+
const bootstrap = dependencies.runWorkbench
|
|
46
|
+
? undefined
|
|
47
|
+
: await savedScanWorkbench(scanId, {
|
|
48
|
+
environment,
|
|
49
|
+
pluginRoot,
|
|
50
|
+
currentDirectory: dependencies.currentDirectory?.() ?? process.cwd(),
|
|
51
|
+
signal: options.signal,
|
|
52
|
+
});
|
|
32
53
|
const scan = await resolveCompletedScan(scanId, {
|
|
33
54
|
currentDirectory: dependencies.currentDirectory ?? (() => process.cwd()),
|
|
34
|
-
runWorkbench:
|
|
35
|
-
(
|
|
36
|
-
const stateEnvironment = workbenchEnvironment(environment);
|
|
37
|
-
return await runWorkbench({
|
|
38
|
-
environment: stateEnvironment,
|
|
39
|
-
pluginRoot,
|
|
40
|
-
python: await resolvePluginPython({
|
|
41
|
-
environment: stateEnvironment,
|
|
42
|
-
}),
|
|
43
|
-
signal: options.signal,
|
|
44
|
-
failureMessage: "Could not read Codex Security scan history",
|
|
45
|
-
}, args);
|
|
46
|
-
}),
|
|
55
|
+
runWorkbench: bootstrap ??
|
|
56
|
+
((args, input) => dependencies.runWorkbench(args, input, options.signal)),
|
|
47
57
|
});
|
|
48
|
-
return await deduplicateResolvedScan(scan.scanDir, scan["targetPath"], scan.scanId, options,
|
|
58
|
+
return await deduplicateResolvedScan(scan.scanDir, scan["targetPath"], scan.scanId, options, bootstrap
|
|
59
|
+
? { ...dependencies, environment: bootstrap.environment }
|
|
60
|
+
: dependencies, pluginRoot, false);
|
|
49
61
|
}
|
|
50
62
|
async function deduplicateResolvedScan(selectedDirectory, repositoryPath, expectedScanId, options, dependencies, pluginRoot, bindRepository) {
|
|
51
63
|
const environment = dependencies.environment ?? process.env;
|
|
64
|
+
if (options.embedding !== undefined && options.findingsUrl !== undefined)
|
|
65
|
+
throw new CodexSecurityError("Custom embeddings are only supported for local deduplication.");
|
|
52
66
|
const { contract, scanDirectory } = await loadContractWithScanDirectory(selectedDirectory, {
|
|
53
67
|
pluginRoot,
|
|
54
68
|
expectedScanId,
|
|
55
69
|
signal: options.signal,
|
|
56
70
|
});
|
|
57
71
|
const scanId = contract.manifest.scan.id;
|
|
58
|
-
const client = new FindingsClient(options.findingsUrl, options.signal, dependencies.fetch);
|
|
59
72
|
const scope = options.allRepositories === true
|
|
60
73
|
? { allRepositories: true }
|
|
61
74
|
: { repositoryId: contract.manifest.scan.target.targetId };
|
|
75
|
+
const injectedWorkbench = dependencies.runWorkbench;
|
|
76
|
+
const workbench = injectedWorkbench &&
|
|
77
|
+
(({ signal }, args, input) => injectedWorkbench(args, input, signal ?? options.signal));
|
|
78
|
+
const local = options.findingsUrl === undefined
|
|
79
|
+
? new LocalDeduplication(environment, scope, repositoryPath, options.signal, workbench, options.embedding)
|
|
80
|
+
: undefined;
|
|
81
|
+
const client = local ??
|
|
82
|
+
new FindingsClient(options.findingsUrl, options.signal, dependencies.fetch);
|
|
62
83
|
const workflow = options.workflowId === undefined
|
|
63
84
|
? undefined
|
|
64
|
-
: new FindingWorkflow(options.workflowId, environment,
|
|
65
|
-
? undefined
|
|
66
|
-
: (_options, args, input) => dependencies.runWorkbench(args, input));
|
|
85
|
+
: new FindingWorkflow(options.workflowId, environment, workbench, undefined, repositoryPath);
|
|
67
86
|
if (workflow) {
|
|
68
87
|
await workflow.protectArtifacts(scanDirectory);
|
|
69
88
|
await workflow.bind({
|
|
@@ -71,46 +90,146 @@ async function deduplicateResolvedScan(selectedDirectory, repositoryPath, expect
|
|
|
71
90
|
scanId,
|
|
72
91
|
scanDir: scanDirectory,
|
|
73
92
|
artifactDigest: workflowDigest(contract),
|
|
74
|
-
destination:
|
|
93
|
+
destination: local
|
|
94
|
+
? `sqlite:${codexSecurityStateDirectory(environment)}`
|
|
95
|
+
: workflowDestination(options.findingsUrl),
|
|
75
96
|
scope,
|
|
76
97
|
});
|
|
77
98
|
await workflow.complete("scan", null);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
99
|
+
if (!local)
|
|
100
|
+
await publishScanToCustomInternal(scanDirectory, {
|
|
101
|
+
findingsUrl: options.findingsUrl,
|
|
102
|
+
workflowId: options.workflowId,
|
|
103
|
+
expectedScanId: scanId,
|
|
104
|
+
signal: options.signal,
|
|
105
|
+
}, {
|
|
106
|
+
environment,
|
|
107
|
+
fetch: dependencies.fetch,
|
|
108
|
+
runWorkbench: workbench,
|
|
109
|
+
});
|
|
90
110
|
}
|
|
91
111
|
const dedupe = async () => {
|
|
112
|
+
if (local) {
|
|
113
|
+
await (workflow ?? new FindingWorkflow(scanId, environment)).protectArtifacts(scanDirectory);
|
|
114
|
+
emitDiagnostic(options.onDiagnostic, { event: "preparation.started" });
|
|
115
|
+
await local.prepare(contract.findings.findings, contract.manifest.scan.target.targetId);
|
|
116
|
+
emitDiagnostic(options.onDiagnostic, { event: "preparation.completed" });
|
|
117
|
+
}
|
|
92
118
|
const saved = (await workflow?.get())?.stages.dedupe;
|
|
93
119
|
if (saved?.pendingWrite) {
|
|
120
|
+
if (local &&
|
|
121
|
+
(saved.pendingWrite.local?.inputDigest !== local.inputDigest ||
|
|
122
|
+
workflowDigest(saved.pendingWrite.local.source) !==
|
|
123
|
+
workflowDigest(await workflow.sourceSnapshot(repositoryPath, saved.pendingWrite.local.gitDisabled, (saved.pendingWrite.local.source["privateStatePaths"] ??
|
|
124
|
+
[]))))) {
|
|
125
|
+
throw new CodexSecurityError("Local deduplication inputs changed. Use a new workflow ID to review them.");
|
|
126
|
+
}
|
|
94
127
|
await client.storeDedupeGroups(saved.pendingWrite.groups);
|
|
95
128
|
return saved.result;
|
|
96
129
|
}
|
|
130
|
+
const reviewEnvironment = dependencies.reviewer
|
|
131
|
+
? environment
|
|
132
|
+
: await (dependencies.resolveReviewEnvironment ?? comparisonEnvironment)(environment, undefined, options.signal);
|
|
133
|
+
const reviewConfiguration = dependencies.reviewer
|
|
134
|
+
? {}
|
|
135
|
+
: await modelConfigurationForReview(environment, reviewEnvironment, options.signal);
|
|
97
136
|
const runner = dependencies.reviewRunner ??
|
|
98
|
-
new CodexReviewRunner(
|
|
137
|
+
new CodexReviewRunner(reviewEnvironment, undefined, options.signal, repositoryPath, undefined, options.onDiagnostic, dependencies.surface ?? "sdk");
|
|
138
|
+
const privateStatePaths = [];
|
|
139
|
+
if (workflow && !dependencies.reviewer) {
|
|
140
|
+
const root = await canonicalizeModelSafePath(repositoryPath);
|
|
141
|
+
const sqliteHome = await canonicalizeModelSafePath(reviewSqliteHome(reviewEnvironment, reviewConfiguration));
|
|
142
|
+
if (isWithin(root, sqliteHome)) {
|
|
143
|
+
if (isWithin(sqliteHome, root))
|
|
144
|
+
throw new CodexSecurityError("Native SQLite storage must not be the reviewed repository root when checkpointing deduplication.");
|
|
145
|
+
// Create missing private parents before capturing source; native startup owns the database files.
|
|
146
|
+
await mkdir(sqliteHome, { recursive: true, mode: 0o700 });
|
|
147
|
+
privateStatePaths.push(sqliteHome);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const source = workflow
|
|
151
|
+
? await workflow.sourceSnapshot(repositoryPath, false, privateStatePaths)
|
|
152
|
+
: undefined;
|
|
99
153
|
const checkpoints = workflow
|
|
100
|
-
? new CheckpointedReviewRunner(workflow, runner,
|
|
154
|
+
? new CheckpointedReviewRunner(workflow, runner, source, scope, await reviewSettingsDigest(reviewEnvironment, reviewConfiguration), options.onDiagnostic)
|
|
101
155
|
: undefined;
|
|
156
|
+
const sourceRepositories = new Map(contract.findings.findings.map((finding) => [
|
|
157
|
+
finding.findingId,
|
|
158
|
+
[contract.manifest.scan.target.targetId],
|
|
159
|
+
]));
|
|
160
|
+
const sourceSnapshots = new Map();
|
|
102
161
|
const deduplicator = new FindingDeduplicator({
|
|
103
|
-
potentialDuplicates: (findingId) =>
|
|
162
|
+
potentialDuplicates: async (findingId) => {
|
|
163
|
+
const neighborhood = await client.potentialDuplicates(findingId, scope);
|
|
164
|
+
for (const finding of [
|
|
165
|
+
neighborhood.finding,
|
|
166
|
+
...neighborhood.potentialDuplicates,
|
|
167
|
+
]) {
|
|
168
|
+
const repositories = Object.hasOwn(neighborhood.repositoryIds ?? {}, finding.findingId)
|
|
169
|
+
? neighborhood.repositoryIds[finding.findingId]
|
|
170
|
+
: undefined;
|
|
171
|
+
if (repositories !== undefined)
|
|
172
|
+
sourceRepositories.set(finding.findingId, repositories);
|
|
173
|
+
else if (scope.repositoryId !== undefined)
|
|
174
|
+
sourceRepositories.set(finding.findingId, [scope.repositoryId]);
|
|
175
|
+
const snapshot = Object.hasOwn(neighborhood.sourceSnapshots ?? {}, finding.findingId)
|
|
176
|
+
? neighborhood.sourceSnapshots[finding.findingId]
|
|
177
|
+
: undefined;
|
|
178
|
+
if (snapshot !== undefined)
|
|
179
|
+
sourceSnapshots.set(finding.findingId, snapshot);
|
|
180
|
+
}
|
|
181
|
+
return neighborhood;
|
|
182
|
+
},
|
|
104
183
|
}, dependencies.reviewer ??
|
|
105
|
-
new
|
|
184
|
+
new CodexGroupingReviewer(checkpoints ?? runner, reviewConfiguration, (findings) => savedSourceContext(contract.manifest.scan.target.targetId, findings, sourceRepositories, sourceSnapshots)), options.signal, options.concurrency);
|
|
106
185
|
const reviewed = await deduplicator.run(contract.findings.findings.map((finding) => finding.findingId));
|
|
107
186
|
await checkpoints?.assertSourceUnchanged();
|
|
108
187
|
options.signal?.throwIfAborted();
|
|
109
188
|
const result = { scanId, ...reviewed };
|
|
110
|
-
await workflow?.prepareDedupe(result, {
|
|
189
|
+
await workflow?.prepareDedupe(result, {
|
|
190
|
+
groups: result.duplicateGroups,
|
|
191
|
+
...(local
|
|
192
|
+
? {
|
|
193
|
+
local: {
|
|
194
|
+
inputDigest: local.inputDigest,
|
|
195
|
+
source: source,
|
|
196
|
+
gitDisabled: environmentEntry(environment, "CODEX_SECURITY_GIT") === "",
|
|
197
|
+
},
|
|
198
|
+
}
|
|
199
|
+
: {}),
|
|
200
|
+
});
|
|
111
201
|
await client.storeDedupeGroups(result.duplicateGroups);
|
|
112
202
|
return result;
|
|
113
203
|
};
|
|
114
204
|
return workflow ? await workflow.run("dedupe", dedupe) : await dedupe();
|
|
115
205
|
}
|
|
206
|
+
async function modelConfigurationForReview(source, effective, signal) {
|
|
207
|
+
const selected = resolveCodexProfile(await readCodexHomeConfig(effective, signal));
|
|
208
|
+
if (configuredCodexHome(source) === configuredCodexHome(effective))
|
|
209
|
+
return selected;
|
|
210
|
+
const ambient = resolveCodexProfile(await readCodexHomeConfig(source, signal));
|
|
211
|
+
const providerIdentity = (config) => {
|
|
212
|
+
const provider = config["model_provider"] ?? "openai";
|
|
213
|
+
const definitions = config["model_providers"];
|
|
214
|
+
const definition = typeof provider === "string" &&
|
|
215
|
+
isRecord(definitions) &&
|
|
216
|
+
isRecord(definitions[provider])
|
|
217
|
+
? definitions[provider]
|
|
218
|
+
: undefined;
|
|
219
|
+
return {
|
|
220
|
+
provider,
|
|
221
|
+
baseUrl: definition?.["base_url"],
|
|
222
|
+
wireApi: definition?.["wire_api"] ?? "responses",
|
|
223
|
+
openaiBaseUrl: provider === "openai" ? config["openai_base_url"] : undefined,
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
// A managed sign-in home can contain only authentication/runtime settings.
|
|
227
|
+
// Keep compatible caller model choices without crossing provider namespaces.
|
|
228
|
+
if (isDeepStrictEqual(providerIdentity(ambient), providerIdentity(selected))) {
|
|
229
|
+
for (const key of ["model", "model_reasoning_effort"])
|
|
230
|
+
if (selected[key] === undefined && ambient[key] !== undefined)
|
|
231
|
+
selected[key] = ambient[key];
|
|
232
|
+
}
|
|
233
|
+
return selected;
|
|
234
|
+
}
|
|
116
235
|
//# sourceMappingURL=scan.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/deduplication/scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,oBAAoB,GAErB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EACL,mBAAmB,EACnB,wBAAwB,GAEzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,0BAA0B,GAE3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAwB,MAAM,uBAAuB,CAAC;AAE7E,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,cAAc,GACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EACL,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAyBpD,8FAA8F;AAC9F,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAc,EACd,OAA+B;IAE/B,OAAO,MAAM,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC;AAED,qFAAqF;AACrF,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,aAAqB,EACrB,OAAwC;IAExC,OAAO,MAAM,gCAAgC,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC;AASD,gBAAgB;AAChB,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,aAAqB,EACrB,OAAwC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AO,QAAQ,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["import { loadContractWithScanDirectory } from \"../contract.js\";\nimport {\n bundledPluginRoot,\n workbenchEnvironment,\n resolvePluginPython,\n runWorkbench,\n} from \"../runtime.js\";\nimport {\n resolveCompletedScan,\n type SavedScanDependencies,\n} from \"../saved-scan.js\";\nimport { CodexReviewRunner } from \"./codex-review.js\";\nimport {\n FindingDeduplicator,\n deduplicationConcurrency,\n type DeduplicationResult,\n} from \"./deduplication.js\";\nimport {\n CodexDeduplicationReviewer,\n type DeduplicationReviewer,\n} from \"./deduplication-reviewer.js\";\nimport { FindingsClient, type FindingsRequest } from \"../findings-client.js\";\nimport type { FindingSearchScope } from \"../finding-retrieval.js\";\nimport {\n FindingWorkflow,\n workflowDestination,\n workflowDigest,\n} from \"../finding-workflow.js\";\nimport { publishScanToCustomInternal } from \"../custom-publish.js\";\nimport {\n CheckpointedReviewRunner,\n reviewSettingsDigest,\n} from \"./checkpointed-review.js\";\nimport { normalizeRepository } from \"../targets.js\";\n\nexport interface DeduplicateScanOptions {\n /** Resume the named local findings workflow, including custom publication. */\n workflowId?: string;\n /** Findings API base URL. The scan's findings must already be indexed there. */\n findingsUrl: string;\n /** Search all repositories instead of the scan's targetId. Defaults to false. */\n allRepositories?: boolean;\n /** Shared concurrency limit for deduplication jobs. Defaults to 8. */\n concurrency?: number;\n signal?: AbortSignal;\n}\n\nexport interface DeduplicateScanDirectoryOptions extends DeduplicateScanOptions {\n /** Local repository checkout used to review duplicate candidates. */\n repository: string;\n /** Require the sealed artifacts to belong to this scan. */\n expectedScanId?: string;\n}\n\nexport interface DeduplicateScanResult extends DeduplicationResult {\n scanId: string;\n}\n\n/** Review a saved scan against embedding candidates and persist accepted duplicate groups. */\nexport async function deduplicateScan(\n scanId: string,\n options: DeduplicateScanOptions,\n): Promise<DeduplicateScanResult> {\n return await deduplicateScanInternal(scanId, options);\n}\n\n/** Review a complete, sealed scan directory without resolving local scan history. */\nexport async function deduplicateScanDirectory(\n scanDirectory: string,\n options: DeduplicateScanDirectoryOptions,\n): Promise<DeduplicateScanResult> {\n return await deduplicateScanDirectoryInternal(scanDirectory, options);\n}\n\ntype DeduplicateScanDependencies = Partial<SavedScanDependencies> & {\n environment?: NodeJS.ProcessEnv;\n reviewer?: DeduplicationReviewer;\n reviewRunner?: Pick<CodexReviewRunner, \"run\">;\n fetch?: FindingsRequest;\n};\n\n/** @internal */\nexport async function deduplicateScanDirectoryInternal(\n scanDirectory: string,\n options: DeduplicateScanDirectoryOptions,\n dependencies: DeduplicateScanDependencies = {},\n): Promise<DeduplicateScanResult> {\n options.signal?.throwIfAborted();\n deduplicationConcurrency(options.concurrency);\n return await deduplicateResolvedScan(\n scanDirectory,\n await normalizeRepository(options.repository, options.signal),\n options.expectedScanId,\n options,\n dependencies,\n await bundledPluginRoot(),\n true,\n );\n}\n\n/** @internal */\nexport async function deduplicateScanInternal(\n scanId: string,\n options: DeduplicateScanOptions,\n dependencies: DeduplicateScanDependencies = {},\n): Promise<DeduplicateScanResult> {\n options.signal?.throwIfAborted();\n deduplicationConcurrency(options.concurrency);\n const environment = dependencies.environment ?? process.env;\n const pluginRoot = await bundledPluginRoot();\n const scan = await resolveCompletedScan(scanId, {\n currentDirectory: dependencies.currentDirectory ?? (() => process.cwd()),\n runWorkbench:\n dependencies.runWorkbench ??\n (async (args) => {\n const stateEnvironment = workbenchEnvironment(environment);\n return await runWorkbench(\n {\n environment: stateEnvironment,\n pluginRoot,\n python: await resolvePluginPython({\n environment: stateEnvironment,\n }),\n signal: options.signal,\n failureMessage: \"Could not read Codex Security scan history\",\n },\n args,\n );\n }),\n });\n return await deduplicateResolvedScan(\n scan.scanDir,\n scan[\"targetPath\"] as string,\n scan.scanId,\n options,\n dependencies,\n pluginRoot,\n false,\n );\n}\n\nasync function deduplicateResolvedScan(\n selectedDirectory: string,\n repositoryPath: string,\n expectedScanId: string | undefined,\n options: DeduplicateScanOptions,\n dependencies: DeduplicateScanDependencies,\n pluginRoot: string,\n bindRepository: boolean,\n): Promise<DeduplicateScanResult> {\n const environment = dependencies.environment ?? process.env;\n const { contract, scanDirectory } = await loadContractWithScanDirectory(\n selectedDirectory,\n {\n pluginRoot,\n expectedScanId,\n signal: options.signal,\n },\n );\n const scanId = contract.manifest.scan.id;\n const client = new FindingsClient(\n options.findingsUrl,\n options.signal,\n dependencies.fetch,\n );\n const scope: FindingSearchScope =\n options.allRepositories === true\n ? { allRepositories: true }\n : { repositoryId: contract.manifest.scan.target.targetId };\n const workflow =\n options.workflowId === undefined\n ? undefined\n : new FindingWorkflow(\n options.workflowId,\n environment,\n dependencies.runWorkbench === undefined\n ? undefined\n : (_options, args, input) =>\n dependencies.runWorkbench!(args, input),\n );\n if (workflow) {\n await workflow.protectArtifacts(scanDirectory);\n await workflow.bind({\n ...(bindRepository ? { repositoryPath } : {}),\n scanId,\n scanDir: scanDirectory,\n artifactDigest: workflowDigest(contract),\n destination: workflowDestination(options.findingsUrl),\n scope,\n });\n await workflow.complete(\"scan\", null);\n await publishScanToCustomInternal(\n scanDirectory,\n {\n findingsUrl: options.findingsUrl,\n workflowId: options.workflowId,\n expectedScanId: scanId,\n signal: options.signal,\n },\n {\n environment,\n fetch: dependencies.fetch,\n runWorkbench:\n dependencies.runWorkbench === undefined\n ? undefined\n : (_options, args, input) =>\n dependencies.runWorkbench!(args, input),\n },\n );\n }\n const dedupe = async (): Promise<DeduplicateScanResult> => {\n const saved = (await workflow?.get())?.stages.dedupe;\n if (saved?.pendingWrite) {\n await client.storeDedupeGroups(saved.pendingWrite.groups);\n return saved.result as DeduplicateScanResult;\n }\n const runner =\n dependencies.reviewRunner ??\n new CodexReviewRunner(\n environment,\n undefined,\n options.signal,\n repositoryPath,\n );\n const checkpoints = workflow\n ? new CheckpointedReviewRunner(\n workflow,\n runner,\n await workflow.sourceSnapshot(repositoryPath),\n scope,\n await reviewSettingsDigest(environment),\n )\n : undefined;\n const deduplicator = new FindingDeduplicator(\n {\n potentialDuplicates: (findingId) =>\n client.potentialDuplicates(findingId, scope),\n },\n dependencies.reviewer ??\n new CodexDeduplicationReviewer(checkpoints ?? runner),\n options.signal,\n options.concurrency,\n );\n const reviewed = await deduplicator.run(\n contract.findings.findings.map((finding) => finding.findingId),\n );\n await checkpoints?.assertSourceUnchanged();\n options.signal?.throwIfAborted();\n const result: DeduplicateScanResult = { scanId, ...reviewed };\n await workflow?.prepareDedupe(result, { groups: result.duplicateGroups });\n await client.storeDedupeGroups(result.duplicateGroups);\n return result;\n };\n return workflow ? await workflow.run(\"dedupe\", dedupe) : await dedupe();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/deduplication/scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,iBAAiB,EAEjB,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,oBAAoB,GAErB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EACL,mBAAmB,EACnB,wBAAwB,GAEzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,qBAAqB,GAEtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAwB,MAAM,uBAAuB,CAAC;AAK7E,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,cAAc,GAC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,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YAC7B,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC;YACvB,CAAC,CAAC,SAAS,CAAC;QAChB,OAAO;YACL,QAAQ;YACR,OAAO,EAAE,UAAU,EAAE,CAAC,UAAU,CAAC;YACjC,OAAO,EAAE,UAAU,EAAE,CAAC,UAAU,CAAC,IAAI,WAAW;YAChD,aAAa,EACX,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS;SAChE,CAAC;IACJ,CAAC,CAAC;IACF,2EAA2E;IAC3E,6EAA6E;IAC7E,IACE,iBAAiB,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC,EACxE,CAAC;QACD,KAAK,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,wBAAwB,CAAC;YACnD,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,SAAS;gBAC3D,QAAQ,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { loadContractWithScanDirectory } from \"../contract.js\";\nimport type { CodexSecuritySurface } from \"../api.js\";\nimport { environmentEntry } from \"../auth.js\";\nimport {\n bundledPluginRoot,\n runWorkbench,\n codexSecurityStateDirectory,\n canonicalizeModelSafePath,\n} from \"../runtime.js\";\nimport {\n resolveCompletedScan,\n type SavedScanDependencies,\n} from \"../saved-scan.js\";\nimport { savedScanWorkbench } from \"../saved-scan-bootstrap.js\";\nimport { CodexReviewRunner, reviewSqliteHome } from \"./codex-review.js\";\nimport { mkdir } from \"node:fs/promises\";\nimport { isWithin } from \"../trusted-executable.js\";\nimport {\n FindingDeduplicator,\n deduplicationConcurrency,\n type DeduplicationResult,\n} from \"./deduplication.js\";\nimport {\n CodexGroupingReviewer,\n type DeduplicationReviewer,\n} from \"./deduplication-reviewer.js\";\nimport { FindingsClient, type FindingsRequest } from \"../findings-client.js\";\nimport type {\n FindingSearchScope,\n FindingSourceSnapshot,\n} from \"../finding-retrieval.js\";\nimport {\n FindingWorkflow,\n workflowDestination,\n workflowDigest,\n} from \"../finding-workflow.js\";\nimport { publishScanToCustomInternal } from \"../custom-publish.js\";\nimport {\n CheckpointedReviewRunner,\n reviewSettingsDigest,\n} from \"./checkpointed-review.js\";\nimport { normalizeRepository } from \"../targets.js\";\nimport { LocalDeduplication, type FindingEmbeddingBinding } from \"./local.js\";\nimport { configuredCodexHome, readCodexHomeConfig } from \"../auth.js\";\nimport { CodexSecurityError } from \"../errors.js\";\nimport { comparisonEnvironment } from \"../scan-comparison.js\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport { isRecord } from \"../record.js\";\nimport { resolveCodexProfile, type JsonObject } from \"../config.js\";\nimport { savedSourceContext } from \"./deduplication-prompts.js\";\nimport {\n emitDiagnostic,\n type DeduplicationDiagnosticObserver,\n} from \"./diagnostics.js\";\n\nexport interface DeduplicateScanOptions {\n /** Resume the named findings workflow; remote mode includes custom publication. */\n workflowId?: string;\n /** Optional Findings API. Omit to prepare and deduplicate findings in local SQLite. */\n findingsUrl?: string;\n /** Custom vector space for local deduplication; cannot be combined with findingsUrl. */\n embedding?: FindingEmbeddingBinding;\n /** Search all repositories instead of the scan's targetId. Defaults to false. */\n allRepositories?: boolean;\n /** Shared concurrency limit for deduplication jobs. Defaults to 8. */\n concurrency?: number;\n /** Best-effort progress and native review diagnostics; observer failures are ignored. */\n onDiagnostic?: DeduplicationDiagnosticObserver;\n signal?: AbortSignal;\n}\n\nexport interface DeduplicateScanDirectoryOptions extends DeduplicateScanOptions {\n /** Local repository checkout used to review duplicate candidates. */\n repository: string;\n /** Require the sealed artifacts to belong to this scan. */\n expectedScanId?: string;\n}\n\nexport interface DeduplicateScanResult extends DeduplicationResult {\n scanId: string;\n}\n\n/** Review a saved scan against embedding candidates and persist accepted duplicate groups. */\nexport async function deduplicateScan(\n scanId: string,\n options: DeduplicateScanOptions,\n): Promise<DeduplicateScanResult> {\n return await deduplicateScanInternal(scanId, options);\n}\n\n/** Review a complete, sealed scan directory without resolving local scan history. */\nexport async function deduplicateScanDirectory(\n scanDirectory: string,\n options: DeduplicateScanDirectoryOptions,\n): Promise<DeduplicateScanResult> {\n return await deduplicateScanDirectoryInternal(scanDirectory, options);\n}\n\ntype DeduplicateScanDependencies = Partial<SavedScanDependencies> & {\n surface?: CodexSecuritySurface;\n environment?: NodeJS.ProcessEnv;\n reviewer?: DeduplicationReviewer;\n reviewRunner?: Pick<CodexReviewRunner, \"run\">;\n resolveReviewEnvironment?: typeof comparisonEnvironment;\n fetch?: FindingsRequest;\n};\n\n/** @internal */\nexport async function deduplicateScanDirectoryInternal(\n scanDirectory: string,\n options: DeduplicateScanDirectoryOptions,\n dependencies: DeduplicateScanDependencies = {},\n): Promise<DeduplicateScanResult> {\n options.signal?.throwIfAborted();\n deduplicationConcurrency(options.concurrency);\n return await deduplicateResolvedScan(\n scanDirectory,\n await normalizeRepository(options.repository, options.signal),\n options.expectedScanId,\n options,\n dependencies,\n await bundledPluginRoot(),\n true,\n );\n}\n\n/** @internal */\nexport async function deduplicateScanInternal(\n scanId: string,\n options: DeduplicateScanOptions,\n dependencies: DeduplicateScanDependencies = {},\n): Promise<DeduplicateScanResult> {\n options.signal?.throwIfAborted();\n deduplicationConcurrency(options.concurrency);\n const environment = dependencies.environment ?? process.env;\n const pluginRoot = await bundledPluginRoot();\n const bootstrap = dependencies.runWorkbench\n ? undefined\n : await savedScanWorkbench(scanId, {\n environment,\n pluginRoot,\n currentDirectory: dependencies.currentDirectory?.() ?? process.cwd(),\n signal: options.signal,\n });\n const scan = await resolveCompletedScan(scanId, {\n currentDirectory: dependencies.currentDirectory ?? (() => process.cwd()),\n runWorkbench:\n bootstrap ??\n ((args, input) =>\n dependencies.runWorkbench!(args, input, options.signal)),\n });\n return await deduplicateResolvedScan(\n scan.scanDir,\n scan[\"targetPath\"] as string,\n scan.scanId,\n options,\n bootstrap\n ? { ...dependencies, environment: bootstrap.environment }\n : dependencies,\n pluginRoot,\n false,\n );\n}\n\nasync function deduplicateResolvedScan(\n selectedDirectory: string,\n repositoryPath: string,\n expectedScanId: string | undefined,\n options: DeduplicateScanOptions,\n dependencies: DeduplicateScanDependencies,\n pluginRoot: string,\n bindRepository: boolean,\n): Promise<DeduplicateScanResult> {\n const environment = dependencies.environment ?? process.env;\n if (options.embedding !== undefined && options.findingsUrl !== undefined)\n throw new CodexSecurityError(\n \"Custom embeddings are only supported for local deduplication.\",\n );\n const { contract, scanDirectory } = await loadContractWithScanDirectory(\n selectedDirectory,\n {\n pluginRoot,\n expectedScanId,\n signal: options.signal,\n },\n );\n const scanId = contract.manifest.scan.id;\n const scope: FindingSearchScope =\n options.allRepositories === true\n ? { allRepositories: true }\n : { repositoryId: contract.manifest.scan.target.targetId };\n const injectedWorkbench = dependencies.runWorkbench;\n const workbench: typeof runWorkbench | undefined =\n injectedWorkbench &&\n (({ signal }, args, input) =>\n injectedWorkbench(args, input, signal ?? options.signal));\n const local =\n options.findingsUrl === undefined\n ? new LocalDeduplication(\n environment,\n scope,\n repositoryPath,\n options.signal,\n workbench,\n options.embedding,\n )\n : undefined;\n const client =\n local ??\n new FindingsClient(\n options.findingsUrl!,\n options.signal,\n dependencies.fetch,\n );\n const workflow =\n options.workflowId === undefined\n ? undefined\n : new FindingWorkflow(\n options.workflowId,\n environment,\n workbench,\n undefined,\n repositoryPath,\n );\n if (workflow) {\n await workflow.protectArtifacts(scanDirectory);\n await workflow.bind({\n ...(bindRepository ? { repositoryPath } : {}),\n scanId,\n scanDir: scanDirectory,\n artifactDigest: workflowDigest(contract),\n destination: local\n ? `sqlite:${codexSecurityStateDirectory(environment)}`\n : workflowDestination(options.findingsUrl!),\n scope,\n });\n await workflow.complete(\"scan\", null);\n if (!local)\n await publishScanToCustomInternal(\n scanDirectory,\n {\n findingsUrl: options.findingsUrl!,\n workflowId: options.workflowId,\n expectedScanId: scanId,\n signal: options.signal,\n },\n {\n environment,\n fetch: dependencies.fetch,\n runWorkbench: workbench,\n },\n );\n }\n const dedupe = async (): Promise<DeduplicateScanResult> => {\n if (local) {\n await (\n workflow ?? new FindingWorkflow(scanId, environment)\n ).protectArtifacts(scanDirectory);\n emitDiagnostic(options.onDiagnostic, { event: \"preparation.started\" });\n await local.prepare(\n contract.findings.findings,\n contract.manifest.scan.target.targetId,\n );\n emitDiagnostic(options.onDiagnostic, { event: \"preparation.completed\" });\n }\n const saved = (await workflow?.get())?.stages.dedupe;\n if (saved?.pendingWrite) {\n if (\n local &&\n (saved.pendingWrite.local?.inputDigest !== local.inputDigest ||\n workflowDigest(saved.pendingWrite.local.source) !==\n workflowDigest(\n await workflow!.sourceSnapshot(\n repositoryPath,\n saved.pendingWrite.local.gitDisabled,\n (saved.pendingWrite.local.source[\"privateStatePaths\"] ??\n []) as string[],\n ),\n ))\n ) {\n throw new CodexSecurityError(\n \"Local deduplication inputs changed. Use a new workflow ID to review them.\",\n );\n }\n await client.storeDedupeGroups(saved.pendingWrite.groups);\n return saved.result as DeduplicateScanResult;\n }\n const reviewEnvironment = dependencies.reviewer\n ? environment\n : await (dependencies.resolveReviewEnvironment ?? comparisonEnvironment)(\n environment,\n undefined,\n options.signal,\n );\n const reviewConfiguration = dependencies.reviewer\n ? {}\n : await modelConfigurationForReview(\n environment,\n reviewEnvironment,\n options.signal,\n );\n const runner =\n dependencies.reviewRunner ??\n new CodexReviewRunner(\n reviewEnvironment,\n undefined,\n options.signal,\n repositoryPath,\n undefined,\n options.onDiagnostic,\n dependencies.surface ?? \"sdk\",\n );\n const privateStatePaths: string[] = [];\n if (workflow && !dependencies.reviewer) {\n const root = await canonicalizeModelSafePath(repositoryPath);\n const sqliteHome = await canonicalizeModelSafePath(\n reviewSqliteHome(reviewEnvironment, reviewConfiguration),\n );\n if (isWithin(root, sqliteHome)) {\n if (isWithin(sqliteHome, root))\n throw new CodexSecurityError(\n \"Native SQLite storage must not be the reviewed repository root when checkpointing deduplication.\",\n );\n // Create missing private parents before capturing source; native startup owns the database files.\n await mkdir(sqliteHome, { recursive: true, mode: 0o700 });\n privateStatePaths.push(sqliteHome);\n }\n }\n const source = workflow\n ? await workflow.sourceSnapshot(repositoryPath, false, privateStatePaths)\n : undefined;\n const checkpoints = workflow\n ? new CheckpointedReviewRunner(\n workflow,\n runner,\n source!,\n scope,\n await reviewSettingsDigest(reviewEnvironment, reviewConfiguration),\n options.onDiagnostic,\n )\n : undefined;\n const sourceRepositories = new Map<string, readonly string[]>(\n contract.findings.findings.map((finding) => [\n finding.findingId,\n [contract.manifest.scan.target.targetId],\n ]),\n );\n const sourceSnapshots = new Map<string, FindingSourceSnapshot>();\n const deduplicator = new FindingDeduplicator(\n {\n potentialDuplicates: async (findingId) => {\n const neighborhood = await client.potentialDuplicates(\n findingId,\n scope,\n );\n for (const finding of [\n neighborhood.finding,\n ...neighborhood.potentialDuplicates,\n ]) {\n const repositories = Object.hasOwn(\n neighborhood.repositoryIds ?? {},\n finding.findingId,\n )\n ? neighborhood.repositoryIds![finding.findingId]\n : undefined;\n if (repositories !== undefined)\n sourceRepositories.set(finding.findingId, repositories);\n else if (scope.repositoryId !== undefined)\n sourceRepositories.set(finding.findingId, [scope.repositoryId]);\n const snapshot = Object.hasOwn(\n neighborhood.sourceSnapshots ?? {},\n finding.findingId,\n )\n ? neighborhood.sourceSnapshots![finding.findingId]\n : undefined;\n if (snapshot !== undefined)\n sourceSnapshots.set(finding.findingId, snapshot);\n }\n return neighborhood;\n },\n },\n dependencies.reviewer ??\n new CodexGroupingReviewer(\n checkpoints ?? runner,\n reviewConfiguration,\n (findings) =>\n savedSourceContext(\n contract.manifest.scan.target.targetId,\n findings,\n sourceRepositories,\n sourceSnapshots,\n ),\n ),\n options.signal,\n options.concurrency,\n );\n const reviewed = await deduplicator.run(\n contract.findings.findings.map((finding) => finding.findingId),\n );\n await checkpoints?.assertSourceUnchanged();\n options.signal?.throwIfAborted();\n const result: DeduplicateScanResult = { scanId, ...reviewed };\n await workflow?.prepareDedupe(result, {\n groups: result.duplicateGroups,\n ...(local\n ? {\n local: {\n inputDigest: local.inputDigest,\n source: source!,\n gitDisabled:\n environmentEntry(environment, \"CODEX_SECURITY_GIT\") === \"\",\n },\n }\n : {}),\n });\n await client.storeDedupeGroups(result.duplicateGroups);\n return result;\n };\n return workflow ? await workflow.run(\"dedupe\", dedupe) : await dedupe();\n}\n\nasync function modelConfigurationForReview(\n source: NodeJS.ProcessEnv,\n effective: NodeJS.ProcessEnv,\n signal?: AbortSignal,\n): Promise<JsonObject> {\n const selected = resolveCodexProfile(\n await readCodexHomeConfig(effective, signal),\n );\n if (configuredCodexHome(source) === configuredCodexHome(effective))\n return selected;\n const ambient = resolveCodexProfile(\n await readCodexHomeConfig(source, signal),\n );\n const providerIdentity = (config: JsonObject) => {\n const provider = config[\"model_provider\"] ?? \"openai\";\n const definitions = config[\"model_providers\"];\n const definition =\n typeof provider === \"string\" &&\n isRecord(definitions) &&\n isRecord(definitions[provider])\n ? definitions[provider]\n : undefined;\n return {\n provider,\n baseUrl: definition?.[\"base_url\"],\n wireApi: definition?.[\"wire_api\"] ?? \"responses\",\n openaiBaseUrl:\n provider === \"openai\" ? config[\"openai_base_url\"] : undefined,\n };\n };\n // A managed sign-in home can contain only authentication/runtime settings.\n // Keep compatible caller model choices without crossing provider namespaces.\n if (\n isDeepStrictEqual(providerIdentity(ambient), providerIdentity(selected))\n ) {\n for (const key of [\"model\", \"model_reasoning_effort\"])\n if (selected[key] === undefined && ambient[key] !== undefined)\n selected[key] = ambient[key];\n }\n return selected;\n}\n"]}
|
package/dist/deep-config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type TomlTable } from "smol-toml";
|
|
2
|
+
import { type JsonObject } from "./config.js";
|
|
2
3
|
import { type DeepScanOptions } from "./scan-settings.js";
|
|
3
4
|
import type { ScanMode } from "./scan-modes.js";
|
|
4
5
|
export type DeepScanSources = Record<keyof DeepScanOptions, "default" | "legacy" | "override">;
|
|
@@ -13,5 +14,5 @@ export declare function deepScanOptions(options: DeepScanOptions & {
|
|
|
13
14
|
mode?: ScanMode;
|
|
14
15
|
}): DeepScanOptions;
|
|
15
16
|
export declare function resolveDeepScanConfig(options: DeepScanOptions, source: string, signal?: AbortSignal): Promise<ResolvedDeepScanConfig>;
|
|
16
|
-
export declare function writeDeepScanConfig(destination: string, resolved: ResolvedDeepScanConfig): Promise<void>;
|
|
17
|
+
export declare function writeDeepScanConfig(destination: string, resolved: ResolvedDeepScanConfig, workerRuntime?: JsonObject): Promise<void>;
|
|
17
18
|
//# sourceMappingURL=deep-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-config.d.ts","sourceRoot":"","sources":["../src/deep-config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deep-config.d.ts","sourceRoot":"","sources":["../src/deep-config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAIhE,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,MAAM,eAAe,GAAG,MAAM,CAClC,MAAM,eAAe,EACrB,SAAS,GAAG,QAAQ,GAAG,UAAU,CAClC,CAAC;AACF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;IACpC,OAAO,EAAE,eAAe,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,EAAE,eAAe,CAAC;CAC5B;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,eAAe,GAAG;IAAE,IAAI,CAAC,EAAE,QAAQ,CAAA;CAAE,GAC7C,eAAe,CAWjB;AAgBD,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,sBAAsB,CAAC,CAuDjC;AAED,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,sBAAsB,EAChC,aAAa,CAAC,EAAE,UAAU,GACzB,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
|
package/dist/deep-config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRecord } from "./record.js";
|
|
1
2
|
import { lstat, readFile } from "node:fs/promises";
|
|
2
3
|
import { basename, dirname, join } from "node:path";
|
|
3
4
|
import { parse as parseToml } from "smol-toml";
|
|
@@ -35,9 +36,7 @@ export async function resolveDeepScanConfig(options, source, signal) {
|
|
|
35
36
|
}
|
|
36
37
|
const existing = document["deep_scan"];
|
|
37
38
|
if (existing !== undefined &&
|
|
38
|
-
(
|
|
39
|
-
existing === null ||
|
|
40
|
-
Array.isArray(existing) ||
|
|
39
|
+
(!isRecord(existing) ||
|
|
41
40
|
![Object.prototype, null].includes(Object.getPrototypeOf(existing)))) {
|
|
42
41
|
throw new CodexSecurityError(`Codex Security configuration [deep_scan] at ${source} must be a TOML table.`);
|
|
43
42
|
}
|
|
@@ -75,7 +74,7 @@ export async function resolveDeepScanConfig(options, source, signal) {
|
|
|
75
74
|
overrides: explicit,
|
|
76
75
|
};
|
|
77
76
|
}
|
|
78
|
-
export async function writeDeepScanConfig(destination, resolved) {
|
|
77
|
+
export async function writeDeepScanConfig(destination, resolved, workerRuntime) {
|
|
79
78
|
const [source, target] = await Promise.all([
|
|
80
79
|
canonicalConfigPath(resolved.source),
|
|
81
80
|
runtimeConfigPath(destination),
|
|
@@ -94,6 +93,7 @@ export async function writeDeepScanConfig(destination, resolved) {
|
|
|
94
93
|
DEEP_SCAN_SETTINGS.some(([name]) => settings[name] === undefined);
|
|
95
94
|
await writeCodexConfig(destination, {
|
|
96
95
|
...document,
|
|
96
|
+
...(workerRuntime === undefined ? {} : { worker_runtime: workerRuntime }),
|
|
97
97
|
deep_scan: {
|
|
98
98
|
...(retainAmbientSettings
|
|
99
99
|
? document["deep_scan"]
|