@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
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,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,mBAAmB,EACnB,2BAA2B,EAC3B,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,2BAA2B,EAC3B,8BAA8B,EAC9B,6BAA6B,EAC7B,2BAA2B,EAC3B,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,GAGlB,MAAM,cAAc,CAAC;AA0BtB,MAAM,kBAAkB,GACtB,6HAA6H,CAAC;AAEhI,KAAK,UAAU,gBAAgB,CAC7B,SAAiB,EACjB,MAAoB;IAEpB,MAAM,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AE,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,EAC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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,aAAa,YAAY,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE;aAClD,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 { 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
|
@@ -7,7 +7,7 @@ export type { ProjectConfigInput, ProjectScope, } from "./project-config-schema.
|
|
|
7
7
|
export type { ScanSettings } from "./scan-settings.js";
|
|
8
8
|
export { classifySeverity } from "./classify-severity.js";
|
|
9
9
|
export { suggestOwners } from "./suggest-owners.js";
|
|
10
|
-
export type { OwnerFinding, OwnerIdentity, OwnerSuggestion, OwnerSuggestions, SuggestOwnersOptions, } from "./suggest-owners.js";
|
|
10
|
+
export type { OwnerFinding, CodeownerIdentity, OwnerIdentity, OwnerSuggestion, OwnerSuggestions, SuggestOwnersOptions, } from "./suggest-owners.js";
|
|
11
11
|
export type { ClassifySeverityOptions, SeverityClassificationFinding, SeverityClassification, SeverityAssessment, } from "./classify-severity.js";
|
|
12
12
|
export { classifyScanSeverity, classifyScanDirectorySeverity, } from "./classify-scan-severity.js";
|
|
13
13
|
export type { ClassifyScanSeverityOptions, ScanSeverityClassification, } from "./classify-scan-severity.js";
|
|
@@ -16,17 +16,18 @@ export type { ComponentDeduplicationSummary, ComponentReceipt, ComponentScanOpti
|
|
|
16
16
|
export { normalizeComponentPlan, planComponents } from "./component-plan.js";
|
|
17
17
|
export type { ComponentPlan, ComponentPlanningOptions, } from "./component-plan.js";
|
|
18
18
|
export { estimateScanCost } from "./cost.js";
|
|
19
|
-
export type { ScanCost, ScanSessionEvent } from "./cost.js";
|
|
19
|
+
export type { ScanCost, ScanSessionEvent, ScanWorkerEvent } from "./cost.js";
|
|
20
|
+
export type { ScanTokenUsage } from "./cost-model.js";
|
|
20
21
|
export type { DeepScanProgress } from "./deep-progress.js";
|
|
21
22
|
export type { CustomValidationResult } from "./custom-validation.js";
|
|
22
23
|
export type { ScanActivity, ScanActivityStatus } from "./scan-activity.js";
|
|
23
24
|
export { matchScanFindings } from "./scan-comparison.js";
|
|
24
25
|
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";
|
|
26
|
+
export type { CodexSecurityMetadata, DeepScanOptions, PatchOptions, PatchResult, ScanAuthMode, ScanAuthentication, ScanBudget, ScanOptions, ScanPreflight, ScanReconnectDetails, ScanTrustedAccessStatus, ScanWarningDetails, ValidationOptions, ValidationResult, } from "./api.js";
|
|
26
27
|
export type { ScanPhase, ScanProgress, ScanWorkerPhase, ScanWorkerStatus, } from "./worker-progress.js";
|
|
27
28
|
export { CodexLoginHandle } from "./auth.js";
|
|
28
29
|
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";
|
|
30
|
+
export { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, ContractValidationError, DeduplicationReviewError, IncompleteScanError, InvalidTargetError, LocalPluginBootstrapError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
30
31
|
export type { DeduplicationReviewFailureCategory, DeduplicationReviewFailureMetadata, DeduplicationReviewStage, ProtectedScanPathKind, } from "./errors.js";
|
|
31
32
|
export { DEFAULT_CODEX_CONFIG, mergedCodexConfig, writeCodexConfig, } from "./config.js";
|
|
32
33
|
export type { CodexSecurityConfig, JsonObject, JsonValue } from "./config.js";
|
|
@@ -44,6 +45,9 @@ export type { DeduplicationReviewRequest, DeduplicationReviewAttribution, Dedupl
|
|
|
44
45
|
export { deduplicateScan, deduplicateScanDirectory, } from "./deduplication/scan.js";
|
|
45
46
|
export type { DeduplicateScanDirectoryOptions, DeduplicateScanOptions, DeduplicateScanResult, } from "./deduplication/scan.js";
|
|
46
47
|
export type { DeduplicationRefusal } from "./deduplication/deduplication.js";
|
|
48
|
+
export type { FindingEmbeddingBinding } from "./deduplication/local.js";
|
|
49
|
+
export type { DeduplicationDiagnostic, DeduplicationDiagnosticObserver, } from "./deduplication/diagnostics.js";
|
|
50
|
+
export type { FindingEmbedder } from "./server/embeddings.js";
|
|
47
51
|
export { importGitHubCodeScanningAlerts } from "./github.js";
|
|
48
52
|
export type { GitHubCodeScanningImportOptions, ImportedGitHubCodeScanningAlert, } from "./github.js";
|
|
49
53
|
export type { CheckScanPublicationOptions, CheckScanPublicationResult, PublishScanOptions, PublishScanProgress, PublishScanResult, } from "./publish.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EACV,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,YAAY,EACV,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,kBAAkB,EAClB,YAAY,GACb,MAAM,4BAA4B,CAAC;AACpC,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,E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B,EACjB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,0BAA0B,EAC1B,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC3E,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export { normalizeComponentPlan, planComponents } from "./component-plan.js";
|
|
|
9
9
|
export { estimateScanCost } from "./cost.js";
|
|
10
10
|
export { matchScanFindings } from "./scan-comparison.js";
|
|
11
11
|
export { CodexLoginHandle } from "./auth.js";
|
|
12
|
-
export { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, ContractValidationError, DeduplicationReviewError, IncompleteScanError, InvalidTargetError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
12
|
+
export { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, ContractValidationError, DeduplicationReviewError, IncompleteScanError, InvalidTargetError, LocalPluginBootstrapError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
13
13
|
export { DEFAULT_CODEX_CONFIG, mergedCodexConfig, writeCodexConfig, } from "./config.js";
|
|
14
14
|
export { loadContract, requireScanFile } from "./contract.js";
|
|
15
15
|
export { resolveSecurityPolicyTarget, securityPolicyDiff, } from "./security-policy.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAKtD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAU9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAKtD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAU9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAepD,OAAO,EACL,oBAAoB,EACpB,6BAA6B,GAC9B,MAAM,6BAA6B,CAAC;AAKrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQxD,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAK7E,OAAO,EAAE,gBAAgB,EAAE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AAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export { exportArtifact } from \"./artifact-export.js\";\nexport type {\n ExportArtifactOptions,\n ArtifactExportResult,\n} from \"./artifact-export.js\";\nexport { CodexSecurity, createSecurity } from \"./api.js\";\nexport { loadProjectConfig, resolveProjectConfig } from \"./project-config.js\";\nexport type {\n ResolvedProjectConfig,\n ProjectConfigProvenance,\n} from \"./project-config.js\";\nexport type {\n ProjectConfigInput,\n ProjectScope,\n} from \"./project-config-schema.js\";\nexport type { ScanSettings } from \"./scan-settings.js\";\nexport { classifySeverity } from \"./classify-severity.js\";\nexport { suggestOwners } from \"./suggest-owners.js\";\nexport type {\n OwnerFinding,\n CodeownerIdentity,\n OwnerIdentity,\n OwnerSuggestion,\n OwnerSuggestions,\n SuggestOwnersOptions,\n} from \"./suggest-owners.js\";\nexport type {\n ClassifySeverityOptions,\n SeverityClassificationFinding,\n SeverityClassification,\n SeverityAssessment,\n} from \"./classify-severity.js\";\nexport {\n classifyScanSeverity,\n classifyScanDirectorySeverity,\n} from \"./classify-scan-severity.js\";\nexport type {\n ClassifyScanSeverityOptions,\n ScanSeverityClassification,\n} from \"./classify-scan-severity.js\";\nexport { runComponentScans } from \"./component-scan.js\";\nexport type {\n ComponentDeduplicationSummary,\n ComponentReceipt,\n ComponentScanOptions,\n ComponentScanEvent,\n ComponentScanResult,\n} from \"./component-scan.js\";\nexport { normalizeComponentPlan, planComponents } from \"./component-plan.js\";\nexport type {\n ComponentPlan,\n ComponentPlanningOptions,\n} from \"./component-plan.js\";\nexport { estimateScanCost } from \"./cost.js\";\nexport type { ScanCost, ScanSessionEvent, ScanWorkerEvent } from \"./cost.js\";\nexport type { ScanTokenUsage } from \"./cost-model.js\";\nexport type { DeepScanProgress } from \"./deep-progress.js\";\nexport type { CustomValidationResult } from \"./custom-validation.js\";\nexport type { ScanActivity, ScanActivityStatus } from \"./scan-activity.js\";\nexport { matchScanFindings } from \"./scan-comparison.js\";\nexport type {\n ScanComparisonInput,\n ScanComparisonOptions,\n ScanComparisonProgress,\n ScanComparisonResult,\n} from \"./scan-comparison.js\";\nexport type {\n CodexSecurityMetadata,\n DeepScanOptions,\n PatchOptions,\n PatchResult,\n ScanAuthMode,\n ScanAuthentication,\n ScanBudget,\n ScanOptions,\n ScanPreflight,\n ScanReconnectDetails,\n ScanTrustedAccessStatus,\n ScanWarningDetails,\n ValidationOptions,\n ValidationResult,\n} from \"./api.js\";\nexport type {\n ScanPhase,\n ScanProgress,\n ScanWorkerPhase,\n ScanWorkerStatus,\n} from \"./worker-progress.js\";\nexport { CodexLoginHandle } from \"./auth.js\";\nexport type { AccountStatus, LoginResult } from \"./auth.js\";\n\nexport {\n AuthenticationRequiredError,\n CodexSecurityError,\n ConfigurationError,\n ContractValidationError,\n DeduplicationReviewError,\n IncompleteScanError,\n InvalidTargetError,\n LocalPluginBootstrapError,\n OutputDirectoryError,\n OutputDirectoryNotEmptyError,\n OutputInsideProtectedRootError,\n PluginBootstrapError,\n PluginPythonUnavailableError,\n SandboxUnavailableError,\n ScanCostLimitExceededError,\n ScanInterruptedError,\n} from \"./errors.js\";\nexport type {\n DeduplicationReviewFailureCategory,\n DeduplicationReviewFailureMetadata,\n DeduplicationReviewStage,\n ProtectedScanPathKind,\n} from \"./errors.js\";\nexport {\n DEFAULT_CODEX_CONFIG,\n mergedCodexConfig,\n writeCodexConfig,\n} from \"./config.js\";\nexport type { CodexSecurityConfig, JsonObject, JsonValue } from \"./config.js\";\nexport { loadContract, requireScanFile } from \"./contract.js\";\nexport type { LoadedContract, ScanExpectation } from \"./contract.js\";\nexport type * from \"./models.js\";\nexport {\n resolveSecurityPolicyTarget,\n securityPolicyDiff,\n} from \"./security-policy.js\";\nexport type {\n SecurityPolicyDraft,\n SecurityPolicyOptions,\n SecurityPolicyPreflight,\n SecurityPolicyStage,\n SecurityPolicyTarget,\n} from \"./security-policy.js\";\nexport { checkScanPublication, publishScan } from \"./publish.js\";\nexport { publishScanToCustom } from \"./custom-publish.js\";\nexport type {\n PublishScanToCustomOptions,\n CustomPublicationResult,\n} from \"./custom-publish.js\";\nexport { deduplicateRecords } from \"./deduplication/records.js\";\nexport type {\n DeduplicateRecordsInput,\n DeduplicateRecordsOptions,\n DeduplicateRecordsResult,\n} from \"./deduplication/records.js\";\nexport type {\n DeduplicationReviewRequest,\n DeduplicationReviewAttribution,\n DeduplicationReviewRunner,\n} from \"./deduplication/review.js\";\nexport {\n deduplicateScan,\n deduplicateScanDirectory,\n} from \"./deduplication/scan.js\";\nexport type {\n DeduplicateScanDirectoryOptions,\n DeduplicateScanOptions,\n DeduplicateScanResult,\n} from \"./deduplication/scan.js\";\nexport type { DeduplicationRefusal } from \"./deduplication/deduplication.js\";\nexport type { FindingEmbeddingBinding } from \"./deduplication/local.js\";\nexport type {\n DeduplicationDiagnostic,\n DeduplicationDiagnosticObserver,\n} from \"./deduplication/diagnostics.js\";\nexport type { FindingEmbedder } from \"./server/embeddings.js\";\nexport { importGitHubCodeScanningAlerts } from \"./github.js\";\nexport type {\n GitHubCodeScanningImportOptions,\n ImportedGitHubCodeScanningAlert,\n} from \"./github.js\";\nexport type {\n CheckScanPublicationOptions,\n CheckScanPublicationResult,\n PublishScanOptions,\n PublishScanProgress,\n PublishScanResult,\n} from \"./publish.js\";\nexport { ScanResult } from \"./result.js\";\nexport type {\n RepositoryFinding,\n ScanResultOptions,\n TurnResultMetadata,\n} from \"./result.js\";\nexport {\n bootstrapPlugin,\n bundledPluginRoot,\n cleanupSdkDirectory,\n createIsolatedHome,\n createMarketplace,\n extractPluginZip,\n importAmbientAuth,\n MARKETPLACE_NAME,\n pluginExecutionEnvironment,\n pluginMetadata,\n PLUGIN_NAME,\n prepareOutputDir,\n resolveCodexCommand,\n resolvePluginPath,\n resolvePluginPython,\n validateOutputDir,\n} from \"./runtime.js\";\nexport type {\n CodexCommand,\n PluginInstall,\n PluginPythonOptions,\n ProcessEnvironment,\n} from \"./runtime.js\";\nexport {\n DiffTarget,\n normalizeRepository,\n normalizeTarget,\n repositoryRevision,\n validateMode,\n} from \"./targets.js\";\nexport type { NormalizedTarget, ScanMode, ScanTarget } from \"./targets.js\";\nexport type { AbsolutePath } from \"./config-path.js\";\nexport { BUNDLED_PLUGIN_VERSION, VERSION } from \"./version.js\";\n"]}
|
package/dist/knowledge-base.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export interface PreparedKnowledgeBase {
|
|
2
2
|
path: string;
|
|
3
3
|
sources: string[];
|
|
4
|
+
protectedRoots: string[];
|
|
4
5
|
cleanup(): Promise<void>;
|
|
5
6
|
}
|
|
6
|
-
export
|
|
7
|
+
export interface KnowledgeBaseSnapshot {
|
|
8
|
+
readonly sources: readonly string[];
|
|
9
|
+
readonly protectedRoots?: readonly string[];
|
|
10
|
+
readonly documents: Readonly<Record<string, string>>;
|
|
11
|
+
}
|
|
12
|
+
export declare function prepareKnowledgeBase(input: readonly string[] | KnowledgeBaseSnapshot, signal?: AbortSignal, directory?: string): Promise<PreparedKnowledgeBase>;
|
|
7
13
|
//# sourceMappingURL=knowledge-base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knowledge-base.d.ts","sourceRoot":"","sources":["../src/knowledge-base.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"knowledge-base.d.ts","sourceRoot":"","sources":["../src/knowledge-base.ts"],"names":[],"mappings":"AA8BA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACtD;AAyFD,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,qBAAqB,EAChD,MAAM,CAAC,EAAE,WAAW,EACpB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,CAAC,CAyChC"}
|
package/dist/knowledge-base.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { constants } from "node:fs";
|
|
2
|
-
import { lstat, mkdtemp, readFile, readdir, realpath, rm, writeFile, } from "node:fs/promises";
|
|
2
|
+
import { lstat, mkdtemp, readFile, readdir, realpath, rm, stat, writeFile, } from "node:fs/promises";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { basename, extname, join, resolve } from "node:path";
|
|
5
5
|
import { unzipSync } from "fflate";
|
|
6
|
+
import { ConfigurationError, errorMessage } from "./errors.js";
|
|
6
7
|
import { expandHome } from "./runtime.js";
|
|
8
|
+
import { gitMarkerRoot, isGitMetadataDirectory, nullIfMissingFile, } from "./targets.js";
|
|
7
9
|
const DOCUMENT_EXTENSIONS = new Set([
|
|
8
10
|
".md",
|
|
9
11
|
".markdown",
|
|
@@ -11,35 +13,36 @@ const DOCUMENT_EXTENSIONS = new Set([
|
|
|
11
13
|
".pdf",
|
|
12
14
|
".docx",
|
|
13
15
|
]);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const documents = new Set();
|
|
17
|
-
for (const requested of paths) {
|
|
18
|
-
signal?.throwIfAborted();
|
|
19
|
-
if (!requested.trim())
|
|
20
|
-
throw new Error("Knowledge base paths cannot be empty.");
|
|
21
|
-
const path = resolve(expandHome(requested));
|
|
22
|
-
const metadata = await lstat(path);
|
|
23
|
-
if (metadata.isSymbolicLink()) {
|
|
24
|
-
throw new Error(`Knowledge base paths cannot be symbolic links: ${path}`);
|
|
25
|
-
}
|
|
26
|
-
if (!metadata.isFile() && !metadata.isDirectory()) {
|
|
27
|
-
throw new Error(`Knowledge base path is not a file or directory: ${path}`);
|
|
28
|
-
}
|
|
29
|
-
const source = await realpath(path);
|
|
30
|
-
const selected = metadata.isDirectory()
|
|
31
|
-
? await discover(source, signal)
|
|
32
|
-
: [source];
|
|
33
|
-
if (selected.length === 0) {
|
|
34
|
-
throw new Error(`Knowledge base directory contains no supported documents: ${path}`);
|
|
35
|
-
}
|
|
36
|
-
for (const document of selected) {
|
|
37
|
-
documents.add(document);
|
|
38
|
-
}
|
|
39
|
-
sources.add(source);
|
|
40
|
-
}
|
|
41
|
-
const path = await mkdtemp(join(directory ?? tmpdir(), "codex-security-knowledge-"));
|
|
16
|
+
/** @internal Extract once so campaign identity and workers use identical inputs. */
|
|
17
|
+
export async function readKnowledgeBaseSnapshot(paths, signal) {
|
|
42
18
|
try {
|
|
19
|
+
const sources = new Set();
|
|
20
|
+
const documents = new Set();
|
|
21
|
+
for (const requested of paths) {
|
|
22
|
+
signal?.throwIfAborted();
|
|
23
|
+
if (!requested.trim())
|
|
24
|
+
throw new Error("Knowledge base paths cannot be empty.");
|
|
25
|
+
const path = resolve(expandHome(requested));
|
|
26
|
+
const metadata = await lstat(path);
|
|
27
|
+
if (metadata.isSymbolicLink()) {
|
|
28
|
+
throw new Error(`Knowledge base paths cannot be symbolic links: ${path}`);
|
|
29
|
+
}
|
|
30
|
+
if (!metadata.isFile() && !metadata.isDirectory()) {
|
|
31
|
+
throw new Error(`Knowledge base path is not a file or directory: ${path}`);
|
|
32
|
+
}
|
|
33
|
+
const source = await realpath(path);
|
|
34
|
+
const selected = metadata.isDirectory()
|
|
35
|
+
? (await discover(source, signal)).sort()
|
|
36
|
+
: [source];
|
|
37
|
+
if (selected.length === 0) {
|
|
38
|
+
throw new Error(`Knowledge base directory contains no supported documents: ${path}`);
|
|
39
|
+
}
|
|
40
|
+
for (const document of selected) {
|
|
41
|
+
documents.add(document);
|
|
42
|
+
}
|
|
43
|
+
sources.add(source);
|
|
44
|
+
}
|
|
45
|
+
const extracted = {};
|
|
43
46
|
let index = 0;
|
|
44
47
|
for (const document of documents) {
|
|
45
48
|
signal?.throwIfAborted();
|
|
@@ -53,7 +56,7 @@ export async function prepareKnowledgeBase(paths, signal, directory) {
|
|
|
53
56
|
});
|
|
54
57
|
const extension = extname(document).toLowerCase();
|
|
55
58
|
const text = extension === ".pdf"
|
|
56
|
-
? await extractPdf(document, bytes)
|
|
59
|
+
? await extractPdf(document, bytes, signal)
|
|
57
60
|
: extension === ".docx"
|
|
58
61
|
? extractDocx(document, bytes)
|
|
59
62
|
: decodeText(document, bytes);
|
|
@@ -63,23 +66,63 @@ export async function prepareKnowledgeBase(paths, signal, directory) {
|
|
|
63
66
|
const name = `${index}-${basename(document)}.txt`;
|
|
64
67
|
// The prefix and suffix can exceed the filesystem's 255-byte name limit.
|
|
65
68
|
const filename = Buffer.byteLength(name) > 255 ? `${index}.txt` : name;
|
|
66
|
-
|
|
67
|
-
encoding: "utf8",
|
|
68
|
-
mode: 0o600,
|
|
69
|
-
signal,
|
|
70
|
-
});
|
|
69
|
+
extracted[filename] = text;
|
|
71
70
|
index++;
|
|
72
71
|
}
|
|
72
|
+
return {
|
|
73
|
+
sources: [...sources],
|
|
74
|
+
protectedRoots: await Promise.all([...sources].map(async (source) => (await gitMarkerRoot(source, signal, "outermost")) ?? source)),
|
|
75
|
+
documents: extracted,
|
|
76
|
+
};
|
|
73
77
|
}
|
|
74
78
|
catch (error) {
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
if (signal?.aborted || error instanceof ConfigurationError)
|
|
80
|
+
throw error;
|
|
81
|
+
throw new ConfigurationError(errorMessage(error), { cause: error });
|
|
77
82
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
}
|
|
84
|
+
export async function prepareKnowledgeBase(input, signal, directory) {
|
|
85
|
+
try {
|
|
86
|
+
const snapshot = "documents" in input
|
|
87
|
+
? input
|
|
88
|
+
: await readKnowledgeBaseSnapshot(input, signal);
|
|
89
|
+
const protectedRoots = snapshot.protectedRoots === undefined
|
|
90
|
+
? await Promise.all(snapshot.sources.map(async (source) => (await gitMarkerRoot(source, signal, "outermost")) ?? source))
|
|
91
|
+
: [...snapshot.protectedRoots];
|
|
92
|
+
const path = await mkdtemp(join(directory ?? tmpdir(), "codex-security-knowledge-"));
|
|
93
|
+
try {
|
|
94
|
+
for (const [filename, text] of Object.entries(snapshot.documents)) {
|
|
95
|
+
signal?.throwIfAborted();
|
|
96
|
+
await writeFile(join(path, filename), text, {
|
|
97
|
+
encoding: "utf8",
|
|
98
|
+
mode: 0o600,
|
|
99
|
+
signal,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
await rm(path, { recursive: true, force: true });
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
path,
|
|
109
|
+
sources: [...snapshot.sources],
|
|
110
|
+
protectedRoots,
|
|
111
|
+
cleanup: () => rm(path, { recursive: true, force: true }),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (signal?.aborted || error instanceof ConfigurationError)
|
|
116
|
+
throw error;
|
|
117
|
+
throw new ConfigurationError(errorMessage(error), { cause: error });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** @internal Read the same extracted document text used by scans. */
|
|
121
|
+
export async function readKnowledgeBaseDocuments(paths, signal) {
|
|
122
|
+
const { documents } = await readKnowledgeBaseSnapshot(paths, signal);
|
|
123
|
+
return Object.keys(documents)
|
|
124
|
+
.sort()
|
|
125
|
+
.map((name) => documents[name]);
|
|
83
126
|
}
|
|
84
127
|
async function discover(directory, signal) {
|
|
85
128
|
signal?.throwIfAborted();
|
|
@@ -88,9 +131,24 @@ async function discover(directory, signal) {
|
|
|
88
131
|
signal?.throwIfAborted();
|
|
89
132
|
for (const entry of entries) {
|
|
90
133
|
signal?.throwIfAborted();
|
|
91
|
-
if (entry.name.toLowerCase()
|
|
134
|
+
if ((process.platform === "win32" ? entry.name.toLowerCase() : entry.name) ===
|
|
135
|
+
".git")
|
|
92
136
|
continue;
|
|
93
137
|
const path = join(directory, entry.name);
|
|
138
|
+
if (entry.name.toLowerCase() === ".git") {
|
|
139
|
+
const marker = await stat(join(directory, ".git"), {
|
|
140
|
+
bigint: true,
|
|
141
|
+
}).catch(nullIfMissingFile);
|
|
142
|
+
if (marker !== null) {
|
|
143
|
+
const candidate = await lstat(path, { bigint: true });
|
|
144
|
+
if (candidate.dev === marker.dev && candidate.ino === marker.ino) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (entry.isDirectory() && (await isGitMetadataDirectory(path, signal))) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
94
152
|
if (entry.isDirectory()) {
|
|
95
153
|
for (const document of await discover(path, signal)) {
|
|
96
154
|
documents.push(document);
|
|
@@ -127,7 +185,7 @@ function decodeText(path, bytes) {
|
|
|
127
185
|
});
|
|
128
186
|
}
|
|
129
187
|
}
|
|
130
|
-
async function extractPdf(path, bytes) {
|
|
188
|
+
async function extractPdf(path, bytes, signal) {
|
|
131
189
|
try {
|
|
132
190
|
const { getDocument, VerbosityLevel } = await import("pdfjs-dist/legacy/build/pdf.mjs");
|
|
133
191
|
const loadingTask = getDocument({
|
|
@@ -139,7 +197,9 @@ async function extractPdf(path, bytes) {
|
|
|
139
197
|
const document = await loadingTask.promise;
|
|
140
198
|
const pages = [];
|
|
141
199
|
for (let number = 1; number <= document.numPages; number++) {
|
|
200
|
+
signal?.throwIfAborted();
|
|
142
201
|
const content = await (await document.getPage(number)).getTextContent();
|
|
202
|
+
signal?.throwIfAborted();
|
|
143
203
|
pages.push(content.items
|
|
144
204
|
.map((item) => ("str" in item ? item.str : ""))
|
|
145
205
|
.join(" "));
|
|
@@ -151,6 +211,8 @@ async function extractPdf(path, bytes) {
|
|
|
151
211
|
}
|
|
152
212
|
}
|
|
153
213
|
catch (error) {
|
|
214
|
+
if (signal?.aborted)
|
|
215
|
+
throw error;
|
|
154
216
|
throw new Error(`Cannot extract text from knowledge base PDF: ${path}`, {
|
|
155
217
|
cause: error,
|
|
156
218
|
});
|
|
@@ -177,7 +239,8 @@ function extractDocx(path, bytes) {
|
|
|
177
239
|
}
|
|
178
240
|
return decodeXml(xml
|
|
179
241
|
.replace(/<\/(?:\w+:)?p\s*>/gu, "\n")
|
|
180
|
-
.replace(/<(?:\w+:)?
|
|
242
|
+
.replace(/<(?:\w+:)?(?:br|cr)\b[^>]*>/gu, "\n")
|
|
243
|
+
.replace(/<(?:\w+:)?tab\b[^>]*>/gu, "\t")
|
|
181
244
|
.replace(/<[^>]+>/gu, ""));
|
|
182
245
|
}
|
|
183
246
|
catch (error) {
|
|
@@ -198,7 +261,12 @@ function decodeXml(value) {
|
|
|
198
261
|
if (!name.startsWith("#"))
|
|
199
262
|
return entities[name.toLowerCase()] ?? entity;
|
|
200
263
|
const hexadecimal = name[1]?.toLowerCase() === "x";
|
|
201
|
-
|
|
264
|
+
const codePoint = Number.parseInt(name.slice(hexadecimal ? 2 : 1), hexadecimal ? 16 : 10);
|
|
265
|
+
if (codePoint > 0x10ffff ||
|
|
266
|
+
(codePoint >= 0xd800 && codePoint <= 0xdfff)) {
|
|
267
|
+
return entity;
|
|
268
|
+
}
|
|
269
|
+
return String.fromCodePoint(codePoint);
|
|
202
270
|
});
|
|
203
271
|
}
|
|
204
272
|
//# sourceMappingURL=knowledge-base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knowledge-base.js","sourceRoot":"","sources":["../src/knowledge-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EACL,KAAK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CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,SAAS,CACd,GAAG;aACA,OAAO,CAAC,qBAAqB,EAAE,IAAI,CAAC;aACpC,OAAO,CAAC,2BAA2B,EAAE,IAAI,CAAC;aAC1C,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAC5B,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,iDAAiD,IAAI,EAAE,EAAE;YACvE,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAC,KAAa;IAC9B,MAAM,QAAQ,GAA2B;QACvC,GAAG,EAAE,GAAG;QACR,EAAE,EAAE,GAAG;QACP,EAAE,EAAE,GAAG;QACP,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,GAAG;KACV,CAAC;IACF,OAAO,KAAK,CAAC,OAAO,CAClB,4CAA4C,EAC5C,CAAC,MAAM,EAAE,IAAY,EAAE,EAAE;QACvB,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,MAAM,CAAC;QACzE,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,GAAG,CAAC;QACnD,OAAO,MAAM,CAAC,aAAa,CACzB,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACxE,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { constants } from \"node:fs\";\nimport {\n lstat,\n mkdtemp,\n readFile,\n readdir,\n realpath,\n rm,\n writeFile,\n} from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { basename, extname, join, resolve } from \"node:path\";\nimport { unzipSync } from \"fflate\";\nimport { expandHome } from \"./runtime.js\";\n\nconst DOCUMENT_EXTENSIONS = new Set([\n \".md\",\n \".markdown\",\n \".txt\",\n \".pdf\",\n \".docx\",\n]);\n\nexport interface PreparedKnowledgeBase {\n path: string;\n sources: string[];\n cleanup(): Promise<void>;\n}\n\nexport async function prepareKnowledgeBase(\n paths: readonly string[],\n signal?: AbortSignal,\n directory?: string,\n): Promise<PreparedKnowledgeBase> {\n const sources = new Set<string>();\n const documents = new Set<string>();\n\n for (const requested of paths) {\n signal?.throwIfAborted();\n if (!requested.trim())\n throw new Error(\"Knowledge base paths cannot be empty.\");\n const path = resolve(expandHome(requested));\n const metadata = await lstat(path);\n if (metadata.isSymbolicLink()) {\n throw new Error(`Knowledge base paths cannot be symbolic links: ${path}`);\n }\n if (!metadata.isFile() && !metadata.isDirectory()) {\n throw new Error(\n `Knowledge base path is not a file or directory: ${path}`,\n );\n }\n\n const source = await realpath(path);\n const selected = metadata.isDirectory()\n ? await discover(source, signal)\n : [source];\n if (selected.length === 0) {\n throw new Error(\n `Knowledge base directory contains no supported documents: ${path}`,\n );\n }\n for (const document of selected) {\n documents.add(document);\n }\n sources.add(source);\n }\n\n const path = await mkdtemp(\n join(directory ?? tmpdir(), \"codex-security-knowledge-\"),\n );\n try {\n let index = 0;\n for (const document of documents) {\n signal?.throwIfAborted();\n const metadata = await lstat(document);\n if (process.platform !== \"win32\" && (metadata.mode & 0o444) === 0) {\n throw new Error(`Knowledge base document is not readable: ${document}`);\n }\n const bytes = await readFile(document, {\n flag: constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0),\n signal,\n });\n const extension = extname(document).toLowerCase();\n const text =\n extension === \".pdf\"\n ? await extractPdf(document, bytes)\n : extension === \".docx\"\n ? extractDocx(document, bytes)\n : decodeText(document, bytes);\n if ((extension === \".pdf\" || extension === \".docx\") && !text.trim()) {\n throw new Error(\n `Knowledge base document contains no extractable text: ${document}`,\n );\n }\n const name = `${index}-${basename(document)}.txt`;\n // The prefix and suffix can exceed the filesystem's 255-byte name limit.\n const filename = Buffer.byteLength(name) > 255 ? `${index}.txt` : name;\n await writeFile(join(path, filename), text, {\n encoding: \"utf8\",\n mode: 0o600,\n signal,\n });\n index++;\n }\n } catch (error) {\n await rm(path, { recursive: true, force: true });\n throw error;\n }\n\n return {\n path,\n sources: [...sources],\n cleanup: () => rm(path, { recursive: true, force: true }),\n };\n}\n\nasync function discover(\n directory: string,\n signal?: AbortSignal,\n): Promise<string[]> {\n signal?.throwIfAborted();\n const documents: string[] = [];\n const entries = await readdir(directory, { withFileTypes: true });\n signal?.throwIfAborted();\n for (const entry of entries) {\n signal?.throwIfAborted();\n if (entry.name.toLowerCase() === \".git\") continue;\n const path = join(directory, entry.name);\n if (entry.isDirectory()) {\n for (const document of await discover(path, signal)) {\n documents.push(document);\n }\n } else if (entry.isFile()) {\n if (!DOCUMENT_EXTENSIONS.has(extname(path).toLowerCase())) {\n const bytes = await readFile(path, {\n flag: constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0),\n signal,\n });\n try {\n decodeText(path, bytes);\n } catch {\n continue;\n }\n }\n documents.push(path);\n }\n }\n return documents;\n}\n\nfunction decodeText(path: string, bytes: Uint8Array): string {\n if (bytes.includes(0)) {\n throw new Error(`Knowledge base document contains binary data: ${path}`);\n }\n try {\n return new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n } catch (error) {\n throw new Error(`Knowledge base document is not valid UTF-8: ${path}`, {\n cause: error,\n });\n }\n}\n\nasync function extractPdf(path: string, bytes: Uint8Array): Promise<string> {\n try {\n const { getDocument, VerbosityLevel } =\n await import(\"pdfjs-dist/legacy/build/pdf.mjs\");\n const loadingTask = getDocument({\n data: new Uint8Array(bytes),\n stopAtErrors: true,\n verbosity: VerbosityLevel.ERRORS,\n });\n try {\n const document = await loadingTask.promise;\n const pages: string[] = [];\n for (let number = 1; number <= document.numPages; number++) {\n const content = await (await document.getPage(number)).getTextContent();\n pages.push(\n content.items\n .map((item) => (\"str\" in item ? item.str : \"\"))\n .join(\" \"),\n );\n }\n return pages.join(\"\\n\");\n } finally {\n await loadingTask.destroy();\n }\n } catch (error) {\n throw new Error(`Cannot extract text from knowledge base PDF: ${path}`, {\n cause: error,\n });\n }\n}\n\nfunction extractDocx(path: string, bytes: Uint8Array): string {\n try {\n const files = unzipSync(bytes, {\n filter: (file) => {\n if (file.name !== \"word/document.xml\") return false;\n if (file.originalSize > 25 * 1024 * 1024) {\n throw new Error(\"DOCX document text exceeds 25 MB.\");\n }\n return true;\n },\n });\n const document = files[\"word/document.xml\"];\n if (document === undefined) throw new Error(\"Missing word/document.xml.\");\n const xml = decodeText(path, document);\n if (\n !/<(?:\\w+:)?document\\b[^>]*>[\\s\\S]*<\\/(?:\\w+:)?document\\s*>/u.test(xml)\n ) {\n throw new Error(\"Malformed word/document.xml.\");\n }\n return decodeXml(\n xml\n .replace(/<\\/(?:\\w+:)?p\\s*>/gu, \"\\n\")\n .replace(/<(?:\\w+:)?tab\\b[^>]*\\/>/gu, \"\\t\")\n .replace(/<[^>]+>/gu, \"\"),\n );\n } catch (error) {\n throw new Error(`Cannot extract text from knowledge base DOCX: ${path}`, {\n cause: error,\n });\n }\n}\n\nfunction decodeXml(value: string): string {\n const entities: Record<string, string> = {\n amp: \"&\",\n lt: \"<\",\n gt: \">\",\n quot: '\"',\n apos: \"'\",\n };\n return value.replace(\n /&(amp|lt|gt|quot|apos|#\\d+|#x[\\da-f]+);/giu,\n (entity, name: string) => {\n if (!name.startsWith(\"#\")) return entities[name.toLowerCase()] ?? entity;\n const hexadecimal = name[1]?.toLowerCase() === \"x\";\n return String.fromCodePoint(\n Number.parseInt(name.slice(hexadecimal ? 2 : 1), hexadecimal ? 16 : 10),\n );\n },\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"knowledge-base.js","sourceRoot":"","sources":["../src/knowledge-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SA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T,IAAI,EAAE,GAAG;KACV,CAAC;IACF,OAAO,KAAK,CAAC,OAAO,CAClB,4CAA4C,EAC5C,CAAC,MAAM,EAAE,IAAY,EAAE,EAAE;QACvB,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,MAAM,CAAC;QACzE,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,GAAG,CAAC;QACnD,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAC/B,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAC/B,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CACtB,CAAC;QACF,IACE,SAAS,GAAG,QAAQ;YACpB,CAAC,SAAS,IAAI,MAAM,IAAI,SAAS,IAAI,MAAM,CAAC,EAC5C,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,OAAO,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { constants } from \"node:fs\";\nimport {\n lstat,\n mkdtemp,\n readFile,\n readdir,\n realpath,\n rm,\n stat,\n writeFile,\n} from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { basename, extname, join, resolve } from \"node:path\";\nimport { unzipSync } from \"fflate\";\nimport { ConfigurationError, errorMessage } from \"./errors.js\";\nimport { expandHome } from \"./runtime.js\";\nimport {\n gitMarkerRoot,\n isGitMetadataDirectory,\n nullIfMissingFile,\n} from \"./targets.js\";\n\nconst DOCUMENT_EXTENSIONS = new Set([\n \".md\",\n \".markdown\",\n \".txt\",\n \".pdf\",\n \".docx\",\n]);\n\nexport interface PreparedKnowledgeBase {\n path: string;\n sources: string[];\n protectedRoots: string[];\n cleanup(): Promise<void>;\n}\n\nexport interface KnowledgeBaseSnapshot {\n readonly sources: readonly string[];\n readonly protectedRoots?: readonly string[];\n readonly documents: Readonly<Record<string, string>>;\n}\n\n/** @internal Extract once so campaign identity and workers use identical inputs. */\nexport async function readKnowledgeBaseSnapshot(\n paths: readonly string[],\n signal?: AbortSignal,\n): Promise<KnowledgeBaseSnapshot> {\n try {\n const sources = new Set<string>();\n const documents = new Set<string>();\n\n for (const requested of paths) {\n signal?.throwIfAborted();\n if (!requested.trim())\n throw new Error(\"Knowledge base paths cannot be empty.\");\n const path = resolve(expandHome(requested));\n const metadata = await lstat(path);\n if (metadata.isSymbolicLink()) {\n throw new Error(\n `Knowledge base paths cannot be symbolic links: ${path}`,\n );\n }\n if (!metadata.isFile() && !metadata.isDirectory()) {\n throw new Error(\n `Knowledge base path is not a file or directory: ${path}`,\n );\n }\n\n const source = await realpath(path);\n const selected = metadata.isDirectory()\n ? (await discover(source, signal)).sort()\n : [source];\n if (selected.length === 0) {\n throw new Error(\n `Knowledge base directory contains no supported documents: ${path}`,\n );\n }\n for (const document of selected) {\n documents.add(document);\n }\n sources.add(source);\n }\n\n const extracted: Record<string, string> = {};\n let index = 0;\n for (const document of documents) {\n signal?.throwIfAborted();\n const metadata = await lstat(document);\n if (process.platform !== \"win32\" && (metadata.mode & 0o444) === 0) {\n throw new Error(`Knowledge base document is not readable: ${document}`);\n }\n const bytes = await readFile(document, {\n flag: constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0),\n signal,\n });\n const extension = extname(document).toLowerCase();\n const text =\n extension === \".pdf\"\n ? await extractPdf(document, bytes, signal)\n : extension === \".docx\"\n ? extractDocx(document, bytes)\n : decodeText(document, bytes);\n if ((extension === \".pdf\" || extension === \".docx\") && !text.trim()) {\n throw new Error(\n `Knowledge base document contains no extractable text: ${document}`,\n );\n }\n const name = `${index}-${basename(document)}.txt`;\n // The prefix and suffix can exceed the filesystem's 255-byte name limit.\n const filename = Buffer.byteLength(name) > 255 ? `${index}.txt` : name;\n extracted[filename] = text;\n index++;\n }\n return {\n sources: [...sources],\n protectedRoots: await Promise.all(\n [...sources].map(\n async (source) =>\n (await gitMarkerRoot(source, signal, \"outermost\")) ?? source,\n ),\n ),\n documents: extracted,\n };\n } catch (error) {\n if (signal?.aborted || error instanceof ConfigurationError) throw error;\n throw new ConfigurationError(errorMessage(error), { cause: error });\n }\n}\n\nexport async function prepareKnowledgeBase(\n input: readonly string[] | KnowledgeBaseSnapshot,\n signal?: AbortSignal,\n directory?: string,\n): Promise<PreparedKnowledgeBase> {\n try {\n const snapshot =\n \"documents\" in input\n ? input\n : await readKnowledgeBaseSnapshot(input, signal);\n const protectedRoots =\n snapshot.protectedRoots === undefined\n ? await Promise.all(\n snapshot.sources.map(\n async (source) =>\n (await gitMarkerRoot(source, signal, \"outermost\")) ?? source,\n ),\n )\n : [...snapshot.protectedRoots];\n const path = await mkdtemp(\n join(directory ?? tmpdir(), \"codex-security-knowledge-\"),\n );\n try {\n for (const [filename, text] of Object.entries(snapshot.documents)) {\n signal?.throwIfAborted();\n await writeFile(join(path, filename), text, {\n encoding: \"utf8\",\n mode: 0o600,\n signal,\n });\n }\n } catch (error) {\n await rm(path, { recursive: true, force: true });\n throw error;\n }\n return {\n path,\n sources: [...snapshot.sources],\n protectedRoots,\n cleanup: () => rm(path, { recursive: true, force: true }),\n };\n } catch (error) {\n if (signal?.aborted || error instanceof ConfigurationError) throw error;\n throw new ConfigurationError(errorMessage(error), { cause: error });\n }\n}\n\n/** @internal Read the same extracted document text used by scans. */\nexport async function readKnowledgeBaseDocuments(\n paths: readonly string[],\n signal?: AbortSignal,\n): Promise<string[]> {\n const { documents } = await readKnowledgeBaseSnapshot(paths, signal);\n return Object.keys(documents)\n .sort()\n .map((name) => documents[name]!);\n}\n\nasync function discover(\n directory: string,\n signal?: AbortSignal,\n): Promise<string[]> {\n signal?.throwIfAborted();\n const documents: string[] = [];\n const entries = await readdir(directory, { withFileTypes: true });\n signal?.throwIfAborted();\n for (const entry of entries) {\n signal?.throwIfAborted();\n if (\n (process.platform === \"win32\" ? entry.name.toLowerCase() : entry.name) ===\n \".git\"\n )\n continue;\n const path = join(directory, entry.name);\n if (entry.name.toLowerCase() === \".git\") {\n const marker = await stat(join(directory, \".git\"), {\n bigint: true,\n }).catch(nullIfMissingFile);\n if (marker !== null) {\n const candidate = await lstat(path, { bigint: true });\n if (candidate.dev === marker.dev && candidate.ino === marker.ino) {\n continue;\n }\n }\n if (entry.isDirectory() && (await isGitMetadataDirectory(path, signal))) {\n continue;\n }\n }\n if (entry.isDirectory()) {\n for (const document of await discover(path, signal)) {\n documents.push(document);\n }\n } else if (entry.isFile()) {\n if (!DOCUMENT_EXTENSIONS.has(extname(path).toLowerCase())) {\n const bytes = await readFile(path, {\n flag: constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0),\n signal,\n });\n try {\n decodeText(path, bytes);\n } catch {\n continue;\n }\n }\n documents.push(path);\n }\n }\n return documents;\n}\n\nfunction decodeText(path: string, bytes: Uint8Array): string {\n if (bytes.includes(0)) {\n throw new Error(`Knowledge base document contains binary data: ${path}`);\n }\n try {\n return new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n } catch (error) {\n throw new Error(`Knowledge base document is not valid UTF-8: ${path}`, {\n cause: error,\n });\n }\n}\n\nasync function extractPdf(\n path: string,\n bytes: Uint8Array,\n signal?: AbortSignal,\n): Promise<string> {\n try {\n const { getDocument, VerbosityLevel } =\n await import(\"pdfjs-dist/legacy/build/pdf.mjs\");\n const loadingTask = getDocument({\n data: new Uint8Array(bytes),\n stopAtErrors: true,\n verbosity: VerbosityLevel.ERRORS,\n });\n try {\n const document = await loadingTask.promise;\n const pages: string[] = [];\n for (let number = 1; number <= document.numPages; number++) {\n signal?.throwIfAborted();\n const content = await (await document.getPage(number)).getTextContent();\n signal?.throwIfAborted();\n pages.push(\n content.items\n .map((item) => (\"str\" in item ? item.str : \"\"))\n .join(\" \"),\n );\n }\n return pages.join(\"\\n\");\n } finally {\n await loadingTask.destroy();\n }\n } catch (error) {\n if (signal?.aborted) throw error;\n throw new Error(`Cannot extract text from knowledge base PDF: ${path}`, {\n cause: error,\n });\n }\n}\n\nfunction extractDocx(path: string, bytes: Uint8Array): string {\n try {\n const files = unzipSync(bytes, {\n filter: (file) => {\n if (file.name !== \"word/document.xml\") return false;\n if (file.originalSize > 25 * 1024 * 1024) {\n throw new Error(\"DOCX document text exceeds 25 MB.\");\n }\n return true;\n },\n });\n const document = files[\"word/document.xml\"];\n if (document === undefined) throw new Error(\"Missing word/document.xml.\");\n const xml = decodeText(path, document);\n if (\n !/<(?:\\w+:)?document\\b[^>]*>[\\s\\S]*<\\/(?:\\w+:)?document\\s*>/u.test(xml)\n ) {\n throw new Error(\"Malformed word/document.xml.\");\n }\n return decodeXml(\n xml\n .replace(/<\\/(?:\\w+:)?p\\s*>/gu, \"\\n\")\n .replace(/<(?:\\w+:)?(?:br|cr)\\b[^>]*>/gu, \"\\n\")\n .replace(/<(?:\\w+:)?tab\\b[^>]*>/gu, \"\\t\")\n .replace(/<[^>]+>/gu, \"\"),\n );\n } catch (error) {\n throw new Error(`Cannot extract text from knowledge base DOCX: ${path}`, {\n cause: error,\n });\n }\n}\n\nfunction decodeXml(value: string): string {\n const entities: Record<string, string> = {\n amp: \"&\",\n lt: \"<\",\n gt: \">\",\n quot: '\"',\n apos: \"'\",\n };\n return value.replace(\n /&(amp|lt|gt|quot|apos|#\\d+|#x[\\da-f]+);/giu,\n (entity, name: string) => {\n if (!name.startsWith(\"#\")) return entities[name.toLowerCase()] ?? entity;\n const hexadecimal = name[1]?.toLowerCase() === \"x\";\n const codePoint = Number.parseInt(\n name.slice(hexadecimal ? 2 : 1),\n hexadecimal ? 16 : 10,\n );\n if (\n codePoint > 0x10ffff ||\n (codePoint >= 0xd800 && codePoint <= 0xdfff)\n ) {\n return entity;\n }\n return String.fromCodePoint(codePoint);\n },\n );\n}\n"]}
|
package/dist/linear.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linear.d.ts","sourceRoot":"","sources":["../src/linear.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"linear.d.ts","sourceRoot":"","sources":["../src/linear.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,YAAY,EAEb,MAAM,aAAa,CAAC;AAIrB,MAAM,MAAM,mBAAmB,CAC7B,MAAM,SAAS,MAAM,YAAY,GAAG,OAAO,GAAG,UAAU,IACtD,CACF,OAAO,EAAE,qBAAqB,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,KACnD,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;AAEhC,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,CAAC,UAAU,EAC9B,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAMpB;AAED,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,MAAM,YAAY,EAClE,OAAO,EAAE,qBAAqB,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,EACtD,OAAO,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,GACpC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAG5B;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,QAAQ,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE;IAChD,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC;IAC/B,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAqG3B;AAaD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG;IACnD,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAYA"}
|
package/dist/linear.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseJson } from "./value.js";
|
|
1
2
|
import { AuthenticationLinearError, ForbiddenLinearError, LinearClient, RatelimitedLinearError, } from "@linear/sdk";
|
|
2
3
|
import { CodexSecurityError, errorMessage } from "./errors.js";
|
|
3
4
|
export function resolveLinearApiKey(environment, explicit) {
|
|
@@ -91,13 +92,7 @@ export async function importLinearIssues(options) {
|
|
|
91
92
|
function linearIssueFilter(input) {
|
|
92
93
|
if (input === undefined)
|
|
93
94
|
return {};
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
filter = JSON.parse(input);
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
filter = null;
|
|
100
|
-
}
|
|
95
|
+
const filter = parseJson(() => input);
|
|
101
96
|
if (typeof filter === "object" && filter !== null && !Array.isArray(filter)) {
|
|
102
97
|
return filter;
|
|
103
98
|
}
|