@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/runtime.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveBundledCodexExecutable } from "./codex-sdk-environment.js";
|
|
2
|
+
import { gitProtectionRoots } from "./targets.js";
|
|
3
|
+
import { isNonEmptyString, notify } from "./value.js";
|
|
2
4
|
import { execFile as execFileCallback, spawn } from "node:child_process";
|
|
3
5
|
import { randomUUID } from "node:crypto";
|
|
4
|
-
import { chmodSync, constants, createWriteStream,
|
|
6
|
+
import { chmodSync, constants, createWriteStream, } from "node:fs";
|
|
5
7
|
import { chmod, cp, copyFile, link, lstat, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm, rmdir, stat, utimes, writeFile, } from "node:fs/promises";
|
|
6
8
|
import { homedir, tmpdir } from "node:os";
|
|
7
9
|
import { createRequire } from "node:module";
|
|
8
|
-
import { basename, dirname, extname, join, relative, resolve, win32, } from "node:path";
|
|
10
|
+
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep, win32, } from "node:path";
|
|
9
11
|
import { fileURLToPath } from "node:url";
|
|
10
12
|
import { promisify } from "node:util";
|
|
11
13
|
import { pipeline } from "node:stream/promises";
|
|
@@ -13,13 +15,25 @@ import { crc32 } from "node:zlib";
|
|
|
13
15
|
import { setTimeout as delay } from "node:timers/promises";
|
|
14
16
|
import { openPromise as openZip } from "yauzl";
|
|
15
17
|
import { parse } from "smol-toml";
|
|
16
|
-
import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, errorMessage, abortReason, } from "./errors.js";
|
|
18
|
+
import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, LocalPluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, errorMessage, abortReason, } from "./errors.js";
|
|
17
19
|
import { isRecord } from "./record.js";
|
|
18
20
|
import { isWithin, resolveTrustedExecutable, } from "./trusted-executable.js";
|
|
19
21
|
import { isWindowsUnsafePathComponent, windowsUnsafePathComponent, } from "./windows-path.js";
|
|
20
22
|
const execFile = promisify(execFileCallback);
|
|
21
23
|
export const MARKETPLACE_NAME = "codex-security-sdk";
|
|
22
24
|
export const PLUGIN_NAME = "codex-security";
|
|
25
|
+
const MARKETPLACE_MANIFEST = `${JSON.stringify({
|
|
26
|
+
name: MARKETPLACE_NAME,
|
|
27
|
+
interface: { displayName: "Codex Security SDK" },
|
|
28
|
+
plugins: [
|
|
29
|
+
{
|
|
30
|
+
name: PLUGIN_NAME,
|
|
31
|
+
source: { source: "local", path: `./plugins/${PLUGIN_NAME}` },
|
|
32
|
+
policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
|
|
33
|
+
category: "Security",
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
}, null, 2)}\n`;
|
|
23
37
|
const MAX_ZIP_ENTRIES = 4_096;
|
|
24
38
|
const MAX_ZIP_CENTRAL_DIRECTORY = 16 * 1024 * 1024;
|
|
25
39
|
const MAX_ZIP_ENTRY_SIZE = 128 * 1024 * 1024;
|
|
@@ -72,19 +86,18 @@ except (module["ContractError"], OSError) as error:
|
|
|
72
86
|
`.trim();
|
|
73
87
|
const WINDOWS_CREDENTIAL_ACL_COMPLETE_PREFIX = "CODEX_SECURITY_ACL_COMPLETE:";
|
|
74
88
|
const WINDOWS_CREDENTIAL_DESCENDANTS_CHANGED_EXIT_CODE = 2;
|
|
75
|
-
function environmentValue(environment, requested) {
|
|
76
|
-
const exact = environment[requested]
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
?.trim();
|
|
89
|
+
function environmentValue(environment, requested, preserveWhitespace = false) {
|
|
90
|
+
const exact = environment[requested];
|
|
91
|
+
const value = exact?.trim()
|
|
92
|
+
? exact
|
|
93
|
+
: Object.entries(environment).find(([name, value]) => name.toUpperCase() === requested && value?.trim())?.[1];
|
|
94
|
+
return preserveWhitespace ? value : value?.trim();
|
|
82
95
|
}
|
|
83
96
|
export function codexSecurityStateDirectory(environment = process.env) {
|
|
84
97
|
const configured = environmentValue(environment, "CODEX_SECURITY_STATE_DIR");
|
|
85
98
|
const path = configured !== undefined
|
|
86
99
|
? resolve(expandHome(configured, environment))
|
|
87
|
-
: resolve(expandHome(environmentValue(environment, "CODEX_HOME") ??
|
|
100
|
+
: resolve(expandHome(environmentValue(environment, "CODEX_HOME", true) ??
|
|
88
101
|
join(homedir(), ".codex"), environment), "state", "plugins", "codex-security");
|
|
89
102
|
requireModelSafeOutputDir(path);
|
|
90
103
|
return path;
|
|
@@ -439,10 +452,10 @@ function windowsAceAllowsAncestorReplacement(rights, inheritanceFlags) {
|
|
|
439
452
|
if (/^0x[\da-f]+$/iu.test(rights)) {
|
|
440
453
|
return (BigInt(rights) & 0x100d0040n) !== 0n;
|
|
441
454
|
}
|
|
442
|
-
|
|
443
|
-
|
|
455
|
+
// Rights tokens stay aligned to pairs of UTF-16 code units.
|
|
456
|
+
for (const [right] of rights.matchAll(/[\s\S]{2}/g)) {
|
|
457
|
+
if (["FA", "GA", "FW", "GW", "SD", "WD", "WO", "DC", "DT"].includes(right))
|
|
444
458
|
return true;
|
|
445
|
-
}
|
|
446
459
|
}
|
|
447
460
|
return false;
|
|
448
461
|
}
|
|
@@ -777,6 +790,15 @@ async function secureWindowsCredentialHome(path) {
|
|
|
777
790
|
}
|
|
778
791
|
}
|
|
779
792
|
}
|
|
793
|
+
export async function withCredentialHomeLock(codexHome, operation, signal) {
|
|
794
|
+
const release = await acquireCodexSecurityCredentialHomeLock(codexHome, signal);
|
|
795
|
+
try {
|
|
796
|
+
return await operation();
|
|
797
|
+
}
|
|
798
|
+
finally {
|
|
799
|
+
await release();
|
|
800
|
+
}
|
|
801
|
+
}
|
|
780
802
|
export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal, securityOptions = {}) {
|
|
781
803
|
throwIfSignalAborted(signal);
|
|
782
804
|
const homeMetadata = await requireSecureCredentialHome(codexHome, securityOptions);
|
|
@@ -1099,11 +1121,125 @@ export async function preparePersistentOutputRoot(stateDirectory, category, repo
|
|
|
1099
1121
|
}
|
|
1100
1122
|
return root;
|
|
1101
1123
|
}
|
|
1102
|
-
const
|
|
1124
|
+
const WORKBENCH_ARGUMENTS_PROGRAM = String.raw `
|
|
1125
|
+
import json, sys
|
|
1126
|
+
sys.argv[2:] = json.loads(sys.stdin.buffer.readline())
|
|
1127
|
+
`;
|
|
1128
|
+
const WORKBENCH_SCRIPT_PROGRAM = String.raw `
|
|
1129
|
+
import runpy, sys
|
|
1130
|
+
sys.argv = sys.argv[1:]
|
|
1131
|
+
runpy.run_path(sys.argv[0], run_name="__main__")
|
|
1132
|
+
`;
|
|
1133
|
+
const ARCHIVE_READY = "codex-security-archive-ready\n";
|
|
1134
|
+
const ARCHIVE_REGISTRATION_PROGRAM = String.raw `
|
|
1135
|
+
import io, json, runpy, sys
|
|
1136
|
+
control = sys.stdin
|
|
1137
|
+
payload = json.loads(control.readline())
|
|
1138
|
+
sys.stdin = io.TextIOWrapper(io.BytesIO(payload.encode("utf-8")), encoding="utf-8")
|
|
1139
|
+
sys.argv = sys.argv[1:]
|
|
1140
|
+
workbench = runpy.run_path(sys.argv[0])
|
|
1141
|
+
def before_archive():
|
|
1142
|
+
sys.stdout.buffer.write(b"codex-security-archive-ready\n")
|
|
1143
|
+
sys.stdout.buffer.flush()
|
|
1144
|
+
if control.readline() != "\n":
|
|
1145
|
+
raise SystemExit("Scan registration canceled before archival.")
|
|
1146
|
+
workbench["main"](before_archive=before_archive)
|
|
1147
|
+
`;
|
|
1148
|
+
// Internal publication callers use only the SDK's bundled workbench.
|
|
1149
|
+
const PUBLICATION_PROGRAM = String.raw `
|
|
1150
|
+
import json, runpy, sys
|
|
1151
|
+
from contextlib import closing
|
|
1152
|
+
workbench = runpy.run_path(sys.argv[1])
|
|
1153
|
+
context = workbench["_WORKBENCH_PUBLICATION_CONTEXT"]
|
|
1154
|
+
payload = json.load(sys.stdin, parse_constant=workbench["reject_non_finite_json"])
|
|
1155
|
+
handler = getattr(workbench["publication"], sys.argv[2].replace("-", "_"))
|
|
1156
|
+
if sys.argv[2] == "inspect-linear-publication":
|
|
1157
|
+
result = handler(context, payload)
|
|
1158
|
+
else:
|
|
1159
|
+
with closing(workbench["connect"]()) as connection:
|
|
1160
|
+
result = handler(context, connection, payload)
|
|
1161
|
+
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
1162
|
+
`;
|
|
1103
1163
|
export async function runWorkbench(options, args, input) {
|
|
1104
1164
|
const script = join(options.pluginRoot, "scripts", "workbench_db.py");
|
|
1105
|
-
const
|
|
1106
|
-
|
|
1165
|
+
const signal = options.signal;
|
|
1166
|
+
const run = async (arguments_, input, archiveHandshake = false) => {
|
|
1167
|
+
const native = [
|
|
1168
|
+
"database-info",
|
|
1169
|
+
"store-findings",
|
|
1170
|
+
"list-stored-findings",
|
|
1171
|
+
"find-potential-duplicates",
|
|
1172
|
+
"store-dedupe-groups",
|
|
1173
|
+
"list-dedupe-groups",
|
|
1174
|
+
"dashboard",
|
|
1175
|
+
"severity-classification",
|
|
1176
|
+
"read-severity-classification",
|
|
1177
|
+
].includes(arguments_[0] ?? "");
|
|
1178
|
+
const node = native && process.versions["bun"]
|
|
1179
|
+
? await resolveTrustedExecutable("node", options.environment, [
|
|
1180
|
+
process.cwd(),
|
|
1181
|
+
options.currentDirectory ?? process.cwd(),
|
|
1182
|
+
...(typeof options.protectedRoot === "string"
|
|
1183
|
+
? [options.protectedRoot]
|
|
1184
|
+
: (options.protectedRoot ?? [])),
|
|
1185
|
+
])
|
|
1186
|
+
: undefined;
|
|
1187
|
+
if (node === null) {
|
|
1188
|
+
throw new Error("Node.js is not available on a trusted PATH.");
|
|
1189
|
+
}
|
|
1190
|
+
const command = native
|
|
1191
|
+
? (node?.executable ?? process.execPath)
|
|
1192
|
+
: (options.python ??= await resolvePluginPython({
|
|
1193
|
+
environment: options.environment,
|
|
1194
|
+
protectedRoot: options.protectedRoot,
|
|
1195
|
+
currentDirectory: options.currentDirectory,
|
|
1196
|
+
signal: options.signal,
|
|
1197
|
+
}));
|
|
1198
|
+
const stateDirectory = native
|
|
1199
|
+
? (options.stateDirectory ??
|
|
1200
|
+
codexSecurityStateDirectory(options.environment))
|
|
1201
|
+
: undefined;
|
|
1202
|
+
const publicationInput = input !== undefined &&
|
|
1203
|
+
arguments_.length === 1 &&
|
|
1204
|
+
[
|
|
1205
|
+
"inspect-linear-publication",
|
|
1206
|
+
"prepare-linear-publication",
|
|
1207
|
+
"record-linear-publications",
|
|
1208
|
+
].includes(arguments_[0]);
|
|
1209
|
+
// OS argv cannot carry NUL, but workbench text fields can.
|
|
1210
|
+
const framedArguments = !native && arguments_.some((argument) => argument.includes("\0"));
|
|
1211
|
+
let program = archiveHandshake
|
|
1212
|
+
? ARCHIVE_REGISTRATION_PROGRAM
|
|
1213
|
+
: publicationInput
|
|
1214
|
+
? PUBLICATION_PROGRAM
|
|
1215
|
+
: undefined;
|
|
1216
|
+
if (framedArguments)
|
|
1217
|
+
program =
|
|
1218
|
+
WORKBENCH_ARGUMENTS_PROGRAM + (program ?? WORKBENCH_SCRIPT_PROGRAM);
|
|
1219
|
+
const result = await runCodexCommand({ command }, native
|
|
1220
|
+
? [join(options.pluginRoot, "mcp", "helpers.mjs"), ...arguments_]
|
|
1221
|
+
: [
|
|
1222
|
+
"-I",
|
|
1223
|
+
"-X",
|
|
1224
|
+
"utf8",
|
|
1225
|
+
"-B",
|
|
1226
|
+
...(program === undefined ? [] : ["-c", program]),
|
|
1227
|
+
script,
|
|
1228
|
+
...(framedArguments ? [] : arguments_),
|
|
1229
|
+
], pluginHelperEnvironment(node?.environment ?? options.environment),
|
|
1230
|
+
// The SDK owns configuration normalization; the helper receives its resolved location.
|
|
1231
|
+
native
|
|
1232
|
+
? JSON.stringify(arguments_[0] === "database-info"
|
|
1233
|
+
? stateDirectory
|
|
1234
|
+
: {
|
|
1235
|
+
stateDirectory,
|
|
1236
|
+
payload: input === undefined ? undefined : JSON.parse(input),
|
|
1237
|
+
})
|
|
1238
|
+
: input, signal, archiveHandshake,
|
|
1239
|
+
// Match native argv's UTF-8 encoding for the private argument frame.
|
|
1240
|
+
framedArguments
|
|
1241
|
+
? `${JSON.stringify(arguments_.map((argument) => argument.toWellFormed()))}\n`
|
|
1242
|
+
: undefined);
|
|
1107
1243
|
if (!result.success) {
|
|
1108
1244
|
throw new Error(result.stderr.trim() ||
|
|
1109
1245
|
result.stdout.trim() ||
|
|
@@ -1113,45 +1249,18 @@ export async function runWorkbench(options, args, input) {
|
|
|
1113
1249
|
};
|
|
1114
1250
|
let stdout;
|
|
1115
1251
|
try {
|
|
1116
|
-
const
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
const key = JSON.stringify([options.python, script]);
|
|
1122
|
-
let support = workbenchComparisonSupport.get(key);
|
|
1123
|
-
if (support === undefined) {
|
|
1124
|
-
const help = await run(["save-scan-comparison", "--help"]);
|
|
1125
|
-
options.signal?.throwIfAborted();
|
|
1126
|
-
support = {
|
|
1127
|
-
stdin: help.includes("--matches-json-stdin"),
|
|
1128
|
-
related: help
|
|
1129
|
-
.replace(/\s+/gu, " ")
|
|
1130
|
-
.includes("Comparison payload supports related findings."),
|
|
1131
|
-
};
|
|
1132
|
-
workbenchComparisonSupport.set(key, support);
|
|
1133
|
-
}
|
|
1134
|
-
const comparison = JSON.parse(input);
|
|
1135
|
-
if (isRecord(comparison) && "related" in comparison && !support.related) {
|
|
1136
|
-
delete comparison["related"];
|
|
1137
|
-
input = JSON.stringify(comparison);
|
|
1138
|
-
}
|
|
1139
|
-
if (!support.stdin) {
|
|
1140
|
-
arguments_.splice(matchesStdinIndex, 1, "--matches-json", input);
|
|
1141
|
-
input = undefined;
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
stdout = await run(arguments_, input);
|
|
1252
|
+
const archiveHandshake = signal !== undefined &&
|
|
1253
|
+
args[0] === "register-cli-scan" &&
|
|
1254
|
+
args.includes("--archive-existing") &&
|
|
1255
|
+
!args.includes("--archived-scan-dir");
|
|
1256
|
+
stdout = await run(args, input, archiveHandshake);
|
|
1145
1257
|
}
|
|
1146
1258
|
catch (error) {
|
|
1147
1259
|
if (options.signal?.aborted)
|
|
1148
1260
|
throw error;
|
|
1149
1261
|
const detail = processErrorDetail(error);
|
|
1150
|
-
const databaseFailure = /\b(?:unable to open database file|attempt to write a readonly database|readonly database|disk i\/o error)\b/iu.test(detail);
|
|
1151
1262
|
const failure = options.failureMessage ?? "Could not run the Codex Security workbench";
|
|
1152
|
-
throw new CodexSecurityError(
|
|
1153
|
-
? `${failure}: cannot open the workbench database at ${join(codexSecurityStateDirectory(options.environment), "workbench.sqlite3")}. Ensure the state directory and SQLite journal files are writable, or set CODEX_SECURITY_STATE_DIR to a writable directory outside the scanned repository.`
|
|
1154
|
-
: `${failure}: ${detail}`, { cause: error });
|
|
1263
|
+
throw new CodexSecurityError(`${failure}: ${detail}`, { cause: error });
|
|
1155
1264
|
}
|
|
1156
1265
|
let result;
|
|
1157
1266
|
try {
|
|
@@ -1184,8 +1293,8 @@ export async function validateOutputDir(outputDirectory, archiveExisting = false
|
|
|
1184
1293
|
if (outputDirectory === undefined) {
|
|
1185
1294
|
return null;
|
|
1186
1295
|
}
|
|
1187
|
-
requireModelSafeOutputDir(outputDirectory);
|
|
1188
1296
|
const path = resolve(expandHome(outputDirectory));
|
|
1297
|
+
requireModelSafeOutputDir(path);
|
|
1189
1298
|
try {
|
|
1190
1299
|
const metadata = await lstat(path).catch(nullIfMissingFileError);
|
|
1191
1300
|
if (metadata !== null) {
|
|
@@ -1343,11 +1452,18 @@ export async function canonicalConfigPath(path) {
|
|
|
1343
1452
|
}
|
|
1344
1453
|
}
|
|
1345
1454
|
export async function prepareOutputDir(outputDirectory, repositoryName, temporaryRoot = tmpdir(), validateLocation, archiveExisting = false, onOutputArchived) {
|
|
1455
|
+
return prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, archiveExisting ? "archive" : "reject", onOutputArchived);
|
|
1456
|
+
}
|
|
1457
|
+
/** Leave archival to the scan registration transaction. */
|
|
1458
|
+
export async function prepareScanRegistrationOutput(outputDirectory, repositoryName, temporaryRoot = tmpdir(), validateLocation, archiveExisting = false) {
|
|
1459
|
+
return prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, archiveExisting ? "preserve" : "reject");
|
|
1460
|
+
}
|
|
1461
|
+
async function prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, existingOutput, onOutputArchived) {
|
|
1346
1462
|
if (outputDirectory === undefined) {
|
|
1347
1463
|
requireModelSafeOutputDir(temporaryRoot);
|
|
1348
1464
|
requireModelSafeOutputDir(await realpath(temporaryRoot));
|
|
1349
1465
|
}
|
|
1350
|
-
const path = await validateOutputDir(outputDirectory,
|
|
1466
|
+
const path = await validateOutputDir(outputDirectory, existingOutput !== "reject");
|
|
1351
1467
|
validateLocation?.(path ?? (await realpath(temporaryRoot)));
|
|
1352
1468
|
if (path === null) {
|
|
1353
1469
|
const created = await mkdtemp(join(temporaryRoot, `codex-security-${safePrefix(repositoryName)}-`));
|
|
@@ -1364,11 +1480,11 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
|
|
|
1364
1480
|
let createdRoot;
|
|
1365
1481
|
try {
|
|
1366
1482
|
let existing = await lstat(path).catch(nullIfMissingFileError);
|
|
1367
|
-
if (existing !== null &&
|
|
1483
|
+
if (existing !== null && existingOutput === "archive") {
|
|
1368
1484
|
const archiveDir = await planOutputArchive(path);
|
|
1369
1485
|
if (archiveDir !== null) {
|
|
1370
1486
|
await rename(path, archiveDir);
|
|
1371
|
-
onOutputArchived?.(archiveDir);
|
|
1487
|
+
notify(() => onOutputArchived?.(archiveDir));
|
|
1372
1488
|
existing = null;
|
|
1373
1489
|
}
|
|
1374
1490
|
}
|
|
@@ -1377,7 +1493,7 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
|
|
|
1377
1493
|
if ((process.umask() & 0o700) !== 0)
|
|
1378
1494
|
await chmod(path, 0o700);
|
|
1379
1495
|
}
|
|
1380
|
-
return await validatePreparedOutputDir(path, validateLocation);
|
|
1496
|
+
return await validatePreparedOutputDir(path, validateLocation, existingOutput === "preserve");
|
|
1381
1497
|
}
|
|
1382
1498
|
catch (error) {
|
|
1383
1499
|
if (createdRoot !== undefined) {
|
|
@@ -1390,7 +1506,7 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
|
|
|
1390
1506
|
});
|
|
1391
1507
|
}
|
|
1392
1508
|
}
|
|
1393
|
-
export async function validatePreparedOutputDir(path, validateLocation) {
|
|
1509
|
+
export async function validatePreparedOutputDir(path, validateLocation, allowNonempty = false) {
|
|
1394
1510
|
const metadata = await lstat(path);
|
|
1395
1511
|
if (!metadata.isDirectory()) {
|
|
1396
1512
|
throw new OutputDirectoryError(`Scan output is not a directory: ${path}`);
|
|
@@ -1399,7 +1515,7 @@ export async function validatePreparedOutputDir(path, validateLocation) {
|
|
|
1399
1515
|
requireModelSafeOutputDir(canonical);
|
|
1400
1516
|
validateLocation?.(canonical);
|
|
1401
1517
|
const entries = await readdir(canonical);
|
|
1402
|
-
if (entries.length !== 0) {
|
|
1518
|
+
if (!allowNonempty && entries.length !== 0) {
|
|
1403
1519
|
throw new OutputDirectoryError(`Scan output directory must be empty: ${path}`);
|
|
1404
1520
|
}
|
|
1405
1521
|
requirePrivateOutputDirectory(metadata, path);
|
|
@@ -1694,75 +1810,168 @@ async function rejectBackslashZipNames(path, signal) {
|
|
|
1694
1810
|
}
|
|
1695
1811
|
}
|
|
1696
1812
|
export async function resolvePluginPath(pluginPath, workspace, signal) {
|
|
1697
|
-
|
|
1698
|
-
|
|
1813
|
+
try {
|
|
1814
|
+
if (pluginPath === undefined) {
|
|
1815
|
+
return await bundledPluginRoot();
|
|
1816
|
+
}
|
|
1817
|
+
const path = resolve(expandHome(pluginPath));
|
|
1818
|
+
const metadata = await lstat(path).catch(() => null);
|
|
1819
|
+
if (metadata?.isFile() && extname(path).toLowerCase() === ".zip") {
|
|
1820
|
+
return await extractPluginZip(path, join(workspace, "extracted-plugin"), signal);
|
|
1821
|
+
}
|
|
1822
|
+
if (metadata?.isDirectory()) {
|
|
1823
|
+
throwIfSignalAborted(signal);
|
|
1824
|
+
return await validatePluginRoot(path);
|
|
1825
|
+
}
|
|
1826
|
+
throw new PluginBootstrapError(`Plugin path must be a directory or ZIP: ${path}`);
|
|
1699
1827
|
}
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1828
|
+
catch (error) {
|
|
1829
|
+
if (signal?.aborted || error instanceof LocalPluginBootstrapError)
|
|
1830
|
+
throw error;
|
|
1831
|
+
throw new LocalPluginBootstrapError(errorMessage(error), { cause: error });
|
|
1704
1832
|
}
|
|
1705
|
-
|
|
1833
|
+
}
|
|
1834
|
+
export async function createMarketplace(codexHome, pluginRoot, signal) {
|
|
1835
|
+
try {
|
|
1706
1836
|
throwIfSignalAborted(signal);
|
|
1707
|
-
|
|
1837
|
+
const root = await realpath(pluginRoot);
|
|
1838
|
+
const marketplace = join(codexHome, "sdk-marketplace");
|
|
1839
|
+
const pluginDestination = join(marketplace, "plugins", PLUGIN_NAME);
|
|
1840
|
+
await copyPluginTree(root, pluginDestination, signal);
|
|
1841
|
+
const projection = await pluginRuntimeProjection(pluginDestination, signal);
|
|
1842
|
+
for (const [path, file] of projection?.files ?? []) {
|
|
1843
|
+
const destination = join(pluginDestination, path);
|
|
1844
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
1845
|
+
await writeFile(destination, file.contents, { mode: file.mode, signal });
|
|
1846
|
+
if (file.mode !== undefined)
|
|
1847
|
+
await chmod(destination, file.mode);
|
|
1848
|
+
}
|
|
1849
|
+
await writeMarketplaceManifest(marketplace, signal);
|
|
1850
|
+
return marketplace;
|
|
1851
|
+
}
|
|
1852
|
+
catch (error) {
|
|
1853
|
+
if (signal?.aborted || error instanceof LocalPluginBootstrapError)
|
|
1854
|
+
throw error;
|
|
1855
|
+
throw new LocalPluginBootstrapError(errorMessage(error), { cause: error });
|
|
1708
1856
|
}
|
|
1709
|
-
throw new PluginBootstrapError(`Plugin path must be a directory or ZIP: ${path}`);
|
|
1710
1857
|
}
|
|
1711
|
-
|
|
1858
|
+
async function writeMarketplaceManifest(marketplace, signal) {
|
|
1712
1859
|
throwIfSignalAborted(signal);
|
|
1713
|
-
const root = await realpath(pluginRoot);
|
|
1714
|
-
const marketplace = join(codexHome, "sdk-marketplace");
|
|
1715
|
-
const pluginDestination = join(marketplace, "plugins", PLUGIN_NAME);
|
|
1716
|
-
await copyPluginTree(root, pluginDestination, signal);
|
|
1717
|
-
throwIfSignalAborted(signal);
|
|
1718
|
-
const manifest = {
|
|
1719
|
-
name: MARKETPLACE_NAME,
|
|
1720
|
-
interface: { displayName: "Codex Security SDK" },
|
|
1721
|
-
plugins: [
|
|
1722
|
-
{
|
|
1723
|
-
name: PLUGIN_NAME,
|
|
1724
|
-
source: { source: "local", path: `./plugins/${PLUGIN_NAME}` },
|
|
1725
|
-
policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
|
|
1726
|
-
category: "Security",
|
|
1727
|
-
},
|
|
1728
|
-
],
|
|
1729
|
-
};
|
|
1730
1860
|
const manifestPath = join(marketplace, ".agents", "plugins", "marketplace.json");
|
|
1731
1861
|
await mkdir(dirname(manifestPath), { recursive: true, mode: 0o700 });
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1862
|
+
const temporary = `${manifestPath}.${randomUUID()}.tmp`;
|
|
1863
|
+
try {
|
|
1864
|
+
await writeFile(temporary, MARKETPLACE_MANIFEST, {
|
|
1865
|
+
encoding: "utf8",
|
|
1866
|
+
flag: "wx",
|
|
1867
|
+
mode: 0o600,
|
|
1868
|
+
signal,
|
|
1869
|
+
});
|
|
1870
|
+
throwIfSignalAborted(signal);
|
|
1871
|
+
try {
|
|
1872
|
+
await rename(temporary, manifestPath);
|
|
1873
|
+
}
|
|
1874
|
+
catch (error) {
|
|
1875
|
+
// Concurrent replacement can fail on Windows after another repair wins.
|
|
1876
|
+
const published = await readFile(manifestPath, "utf8").catch(() => null);
|
|
1877
|
+
if (published !== MARKETPLACE_MANIFEST)
|
|
1878
|
+
throw error;
|
|
1879
|
+
}
|
|
1880
|
+
throwIfSignalAborted(signal);
|
|
1881
|
+
}
|
|
1882
|
+
finally {
|
|
1883
|
+
await rm(temporary, { force: true });
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
async function pluginRuntimeProjection(root, signal) {
|
|
1887
|
+
const path = join(root, ".mcp.json");
|
|
1888
|
+
// Keep the source link checks ahead of any configuration read.
|
|
1889
|
+
if (!(await lstat(path).catch(nullIfMissingFileError))?.isFile())
|
|
1890
|
+
return;
|
|
1891
|
+
const configuration = JSON.parse(await readFile(path, { encoding: "utf8", signal }));
|
|
1892
|
+
const servers = isRecord(configuration)
|
|
1893
|
+
? configuration["mcpServers"]
|
|
1894
|
+
: undefined;
|
|
1895
|
+
const server = isRecord(servers) ? servers[PLUGIN_NAME] : undefined;
|
|
1896
|
+
if (!isRecord(server) ||
|
|
1897
|
+
(server["command"] !== "./scripts/launch_codex_security_mcp" &&
|
|
1898
|
+
server["command"] !== "./scripts/launch_codex_security_mcp.cmd")) {
|
|
1899
|
+
return;
|
|
1900
|
+
}
|
|
1901
|
+
const environment = server["env_vars"];
|
|
1902
|
+
if (environment !== undefined && !Array.isArray(environment))
|
|
1903
|
+
return;
|
|
1904
|
+
if (!Array.isArray(environment) ||
|
|
1905
|
+
!environment.includes("CODEX_SECURITY_PLUGIN_ROOT")) {
|
|
1906
|
+
server["env_vars"] = [
|
|
1907
|
+
...(Array.isArray(environment) ? environment : []),
|
|
1908
|
+
"CODEX_SECURITY_PLUGIN_ROOT",
|
|
1909
|
+
];
|
|
1910
|
+
}
|
|
1911
|
+
const files = new Map();
|
|
1912
|
+
server["command"] =
|
|
1913
|
+
server["command"] === "./scripts/launch_codex_security_mcp.cmd"
|
|
1914
|
+
? "./scripts/launch_codex_security_mcp_sdk.cmd"
|
|
1915
|
+
: "./scripts/launch_codex_security_mcp_sdk";
|
|
1916
|
+
files.set("scripts/launch_codex_security_mcp_sdk", {
|
|
1917
|
+
contents: Buffer.from("#!/bin/sh\n" +
|
|
1918
|
+
'if [ -n "${CODEX_SECURITY_PLUGIN_ROOT:-}" ]; then\n' +
|
|
1919
|
+
' exec "$CODEX_SECURITY_PLUGIN_ROOT/scripts/launch_codex_security_mcp" "$@"\n' +
|
|
1920
|
+
"fi\n" +
|
|
1921
|
+
'exec "$(dirname "$0")/launch_codex_security_mcp" "$@"\n'),
|
|
1922
|
+
mode: 0o755,
|
|
1737
1923
|
});
|
|
1738
|
-
|
|
1739
|
-
|
|
1924
|
+
files.set("scripts/launch_codex_security_mcp_sdk.cmd", {
|
|
1925
|
+
contents: Buffer.from("@echo off\r\nsetlocal DisableDelayedExpansion\r\n" +
|
|
1926
|
+
"if not defined CODEX_SECURITY_PLUGIN_ROOT goto codex_security_sdk_original\r\n" +
|
|
1927
|
+
'"%CODEX_SECURITY_PLUGIN_ROOT%\\scripts\\launch_codex_security_mcp.cmd" %*\r\n' +
|
|
1928
|
+
"exit /b\r\n:codex_security_sdk_original\r\n" +
|
|
1929
|
+
'"%~dp0launch_codex_security_mcp.cmd" %*\r\n'),
|
|
1930
|
+
mode: 0o755,
|
|
1931
|
+
});
|
|
1932
|
+
files.set(".mcp.json", {
|
|
1933
|
+
contents: Buffer.from(`${JSON.stringify(configuration, null, 2)}\n`),
|
|
1934
|
+
});
|
|
1935
|
+
return { root, files };
|
|
1740
1936
|
}
|
|
1741
1937
|
export function resolveCodexCommand(environment = process.env) {
|
|
1742
1938
|
const configured = environmentValue(environment, "CODEX_CLI_PATH");
|
|
1743
|
-
const expanded = configured === undefined
|
|
1939
|
+
const expanded = configured === undefined
|
|
1940
|
+
? undefined
|
|
1941
|
+
: expandExecutableHome(configured, environment);
|
|
1744
1942
|
if (expanded &&
|
|
1745
1943
|
(process.platform !== "win32" || /\.(?:exe|com)$/iu.test(expanded))) {
|
|
1746
|
-
return {
|
|
1944
|
+
return {
|
|
1945
|
+
command: process.platform === "win32"
|
|
1946
|
+
? resolve(expanded)
|
|
1947
|
+
: isAbsolute(expanded)
|
|
1948
|
+
? expanded
|
|
1949
|
+
: `${process.cwd()}${sep}${expanded}`,
|
|
1950
|
+
};
|
|
1747
1951
|
}
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1952
|
+
return { command: resolveBundledCodexExecutable() };
|
|
1953
|
+
}
|
|
1954
|
+
export async function codexExecutableReadPaths(command) {
|
|
1955
|
+
const executable = await realpath(command);
|
|
1956
|
+
const packageJson = resolve(dirname(executable), "..", "package.json");
|
|
1751
1957
|
try {
|
|
1752
|
-
const
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
return
|
|
1958
|
+
const metadata = JSON.parse(await readFile(packageJson, "utf8"));
|
|
1959
|
+
if (metadata?.name !== "@openai/codex" ||
|
|
1960
|
+
typeof metadata.bin?.codex !== "string")
|
|
1961
|
+
return [executable];
|
|
1962
|
+
const launcher = await realpath(resolve(dirname(packageJson), metadata.bin.codex));
|
|
1963
|
+
if (launcher !== executable)
|
|
1964
|
+
return [executable];
|
|
1965
|
+
}
|
|
1966
|
+
catch {
|
|
1967
|
+
// A custom executable need not belong to a readable, valid npm package.
|
|
1968
|
+
return [executable];
|
|
1969
|
+
}
|
|
1970
|
+
// npm's entrypoint launches a native binary, which Linux re-executes in the sandbox.
|
|
1971
|
+
return [
|
|
1972
|
+
executable,
|
|
1973
|
+
await realpath(resolveBundledCodexExecutable(packageJson)),
|
|
1974
|
+
];
|
|
1766
1975
|
}
|
|
1767
1976
|
export function executablePathForSpawn(command) {
|
|
1768
1977
|
if (process.platform !== "win32" || !win32.isAbsolute(command))
|
|
@@ -1776,6 +1985,13 @@ export function executablePathForSpawn(command) {
|
|
|
1776
1985
|
export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
1777
1986
|
const root = await realpath(pluginRoot);
|
|
1778
1987
|
const { name, version } = await pluginMetadata(root);
|
|
1988
|
+
const projection = await pluginRuntimeProjection(root, options.signal).catch((error) => {
|
|
1989
|
+
if (options.signal?.aborted)
|
|
1990
|
+
throw error;
|
|
1991
|
+
throw new LocalPluginBootstrapError(errorMessage(error), {
|
|
1992
|
+
cause: error,
|
|
1993
|
+
});
|
|
1994
|
+
});
|
|
1779
1995
|
const marketplace = join(codexHome, "sdk-marketplace");
|
|
1780
1996
|
throwIfSignalAborted(options.signal);
|
|
1781
1997
|
const command = options.codexCommand ?? resolveCodexCommand(options.environment);
|
|
@@ -1786,20 +2002,23 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1786
2002
|
const run = options.runCodex ?? runPluginCommand;
|
|
1787
2003
|
const existing = await lstat(marketplace).catch(nullIfMissingFileError);
|
|
1788
2004
|
if (existing !== null && !existing.isDirectory()) {
|
|
1789
|
-
throw new
|
|
2005
|
+
throw new LocalPluginBootstrapError(`Codex Security plugin marketplace path must be a directory: ${marketplace}`);
|
|
1790
2006
|
}
|
|
1791
2007
|
const staged = existing === null
|
|
1792
2008
|
? null
|
|
1793
2009
|
: await pluginMetadata(join(marketplace, "plugins", PLUGIN_NAME)).catch(() => null);
|
|
1794
2010
|
const stagedRoot = join(marketplace, "plugins", PLUGIN_NAME);
|
|
1795
2011
|
const stagedMatches = staged?.version === version &&
|
|
1796
|
-
(await pluginContentsMatch(root, stagedRoot, options.signal));
|
|
2012
|
+
(await pluginContentsMatch(root, stagedRoot, options.signal, false, projection));
|
|
1797
2013
|
if (!stagedMatches) {
|
|
1798
2014
|
if (existing !== null) {
|
|
1799
2015
|
await rm(marketplace, { recursive: true, force: true });
|
|
1800
2016
|
}
|
|
1801
2017
|
await createMarketplace(codexHome, root, options.signal);
|
|
1802
2018
|
}
|
|
2019
|
+
else if ((await readFile(join(marketplace, ".agents", "plugins", "marketplace.json"), "utf8").catch(nullIfMissingFileError)) !== MARKETPLACE_MANIFEST) {
|
|
2020
|
+
await writeMarketplaceManifest(marketplace, options.signal);
|
|
2021
|
+
}
|
|
1803
2022
|
const config = await readFile(join(codexHome, "config.toml"), "utf8").catch((error) => {
|
|
1804
2023
|
if (nodeErrorCode(error) === "ENOENT")
|
|
1805
2024
|
return "";
|
|
@@ -1839,7 +2058,7 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1839
2058
|
isRecord(previous) &&
|
|
1840
2059
|
typeof previous["installedPath"] === "string" &&
|
|
1841
2060
|
previous["version"] === version &&
|
|
1842
|
-
(await pluginContentsMatch(root, previous["installedPath"], options.signal, true))) {
|
|
2061
|
+
(await pluginContentsMatch(root, previous["installedPath"], options.signal, true, projection))) {
|
|
1843
2062
|
return {
|
|
1844
2063
|
pluginRoot: root,
|
|
1845
2064
|
marketplaceRoot: marketplace,
|
|
@@ -1875,7 +2094,7 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1875
2094
|
version,
|
|
1876
2095
|
};
|
|
1877
2096
|
}
|
|
1878
|
-
async function pluginContentsMatch(source, destination, signal, allowExtraFiles = false) {
|
|
2097
|
+
async function pluginContentsMatch(source, destination, signal, allowExtraFiles = false, projection) {
|
|
1879
2098
|
throwIfSignalAborted(signal);
|
|
1880
2099
|
const sourceMetadata = await lstat(source);
|
|
1881
2100
|
const destinationMetadata = await lstat(destination).catch((error) => {
|
|
@@ -1887,26 +2106,44 @@ async function pluginContentsMatch(source, destination, signal, allowExtraFiles
|
|
|
1887
2106
|
if (destinationMetadata === null)
|
|
1888
2107
|
return false;
|
|
1889
2108
|
if (sourceMetadata.isFile() && destinationMetadata.isFile()) {
|
|
1890
|
-
|
|
1891
|
-
|
|
2109
|
+
const projected = projection?.files.get(relative(projection.root, source).split(sep).join("/"));
|
|
2110
|
+
if ((projected === undefined &&
|
|
2111
|
+
sourceMetadata.size !== destinationMetadata.size) ||
|
|
2112
|
+
((projected?.mode === undefined || process.platform !== "win32") &&
|
|
2113
|
+
((projected?.mode ?? sourceMetadata.mode) & 0o111) !==
|
|
2114
|
+
(destinationMetadata.mode & 0o111))) {
|
|
1892
2115
|
return false;
|
|
1893
2116
|
}
|
|
1894
2117
|
const [sourceBytes, destinationBytes] = await Promise.all([
|
|
1895
2118
|
readFile(source, { signal }),
|
|
1896
2119
|
readFile(destination, { signal }),
|
|
1897
2120
|
]);
|
|
1898
|
-
return sourceBytes.equals(destinationBytes);
|
|
2121
|
+
return (projected?.contents ?? sourceBytes).equals(destinationBytes);
|
|
1899
2122
|
}
|
|
1900
2123
|
if (!sourceMetadata.isDirectory() || !destinationMetadata.isDirectory()) {
|
|
1901
2124
|
return false;
|
|
1902
2125
|
}
|
|
1903
2126
|
const entries = await readdir(source);
|
|
2127
|
+
const projectedDirectory = projection === undefined
|
|
2128
|
+
? undefined
|
|
2129
|
+
: relative(projection.root, source).split(sep).join("/") || ".";
|
|
2130
|
+
const generated = [...(projection?.files ?? [])].filter(([path]) => dirname(path) === projectedDirectory && !entries.includes(basename(path)));
|
|
1904
2131
|
if (!allowExtraFiles &&
|
|
1905
|
-
entries.length !== (await readdir(destination)).length) {
|
|
2132
|
+
entries.length + generated.length !== (await readdir(destination)).length) {
|
|
1906
2133
|
return false;
|
|
1907
2134
|
}
|
|
2135
|
+
for (const [path, file] of generated) {
|
|
2136
|
+
const generatedPath = join(destination, basename(path));
|
|
2137
|
+
const metadata = await lstat(generatedPath).catch(nullIfMissingFileError);
|
|
2138
|
+
if (!metadata?.isFile() ||
|
|
2139
|
+
(process.platform !== "win32" &&
|
|
2140
|
+
(metadata.mode & 0o111) !== ((file.mode ?? 0o644) & 0o111)) ||
|
|
2141
|
+
!file.contents.equals(await readFile(generatedPath, { signal }))) {
|
|
2142
|
+
return false;
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
1908
2145
|
for (const entry of entries) {
|
|
1909
|
-
if (!(await pluginContentsMatch(join(source, entry), join(destination, entry), signal, allowExtraFiles))) {
|
|
2146
|
+
if (!(await pluginContentsMatch(join(source, entry), join(destination, entry), signal, allowExtraFiles, projection))) {
|
|
1910
2147
|
return false;
|
|
1911
2148
|
}
|
|
1912
2149
|
}
|
|
@@ -1922,32 +2159,50 @@ export async function pluginMetadata(root) {
|
|
|
1922
2159
|
manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
1923
2160
|
}
|
|
1924
2161
|
catch (error) {
|
|
1925
|
-
throw new
|
|
2162
|
+
throw new LocalPluginBootstrapError(`Invalid Codex plugin directory: ${root}`, {
|
|
1926
2163
|
cause: error,
|
|
1927
2164
|
});
|
|
1928
2165
|
}
|
|
1929
2166
|
if (!isRecord(manifest) || manifest["name"] !== PLUGIN_NAME) {
|
|
1930
|
-
throw new
|
|
2167
|
+
throw new LocalPluginBootstrapError("Plugin manifest must have name 'codex-security'.");
|
|
1931
2168
|
}
|
|
1932
2169
|
const version = manifest["version"];
|
|
1933
2170
|
if (typeof version !== "string" || version.trim().length === 0) {
|
|
1934
|
-
throw new
|
|
2171
|
+
throw new LocalPluginBootstrapError("Plugin manifest must have a non-empty version.");
|
|
1935
2172
|
}
|
|
1936
2173
|
return { name: PLUGIN_NAME, version };
|
|
1937
2174
|
}
|
|
1938
2175
|
export async function resolvePluginPython(options = {}) {
|
|
1939
2176
|
const environment = options.environment ?? process.env;
|
|
1940
|
-
const
|
|
2177
|
+
const requestedRoots = options.protectedRoot ?? process.cwd();
|
|
2178
|
+
const protectedRoot = typeof requestedRoots === "string" ? [requestedRoots] : [...requestedRoots];
|
|
2179
|
+
const callerDirectories = [
|
|
2180
|
+
process.cwd(),
|
|
2181
|
+
options.currentDirectory ?? process.cwd(),
|
|
2182
|
+
];
|
|
2183
|
+
// Preserve target and enclosing-checkout protection for every interpreter.
|
|
2184
|
+
for (const directory of new Set([...callerDirectories, ...protectedRoot])) {
|
|
2185
|
+
for (const checkout of await gitProtectionRoots(directory, options.signal))
|
|
2186
|
+
if (!protectedRoot.includes(checkout))
|
|
2187
|
+
protectedRoot.push(checkout);
|
|
2188
|
+
}
|
|
2189
|
+
// Named interpreters are ambient PATH discovery, even when PYTHON names one.
|
|
2190
|
+
// Explicit trusted paths and managed runtimes retain their existing precedence.
|
|
2191
|
+
const discoveryRoots = [...protectedRoot, ...callerDirectories];
|
|
1941
2192
|
if (options.configuredPath !== undefined) {
|
|
1942
|
-
return await requirePython(options.configuredPath, "configured plugin Python", environment,
|
|
2193
|
+
return await requirePython(options.configuredPath, "configured plugin Python", environment, isPythonPathCandidate(options.configuredPath)
|
|
2194
|
+
? protectedRoot
|
|
2195
|
+
: discoveryRoots, options.signal);
|
|
1943
2196
|
}
|
|
1944
2197
|
const inherited = environmentValue(environment, "PYTHON");
|
|
1945
2198
|
if (inherited) {
|
|
1946
|
-
return await requirePython(inherited, "PYTHON", environment, protectedRoot, options.signal);
|
|
2199
|
+
return await requirePython(inherited, "PYTHON", environment, isPythonPathCandidate(inherited) ? protectedRoot : discoveryRoots, options.signal);
|
|
1947
2200
|
}
|
|
1948
2201
|
const home = options.homeDirectory ?? homedir();
|
|
2202
|
+
const cacheDirectory = environmentValue(environment, "XDG_CACHE_HOME", true) ||
|
|
2203
|
+
join(home, ".cache");
|
|
1949
2204
|
const managedRoots = options.managedRuntimeRoots ?? [
|
|
1950
|
-
join(
|
|
2205
|
+
join(cacheDirectory, "codex-runtimes", "codex-primary-runtime"),
|
|
1951
2206
|
];
|
|
1952
2207
|
const relativeCandidates = process.platform === "win32"
|
|
1953
2208
|
? [
|
|
@@ -1970,7 +2225,7 @@ export async function resolvePluginPython(options = {}) {
|
|
|
1970
2225
|
for (const candidate of process.platform === "win32"
|
|
1971
2226
|
? ["python", "python3", "py"]
|
|
1972
2227
|
: ["python3", "python"]) {
|
|
1973
|
-
const resolved = await usablePython(candidate, environment,
|
|
2228
|
+
const resolved = await usablePython(candidate, environment, discoveryRoots, options.signal);
|
|
1974
2229
|
if (resolved !== null)
|
|
1975
2230
|
return resolved;
|
|
1976
2231
|
}
|
|
@@ -1981,6 +2236,7 @@ export function pluginExecutionEnvironment(python, environment = process.env) {
|
|
|
1981
2236
|
return {
|
|
1982
2237
|
...pythonUtf8Environment(environment),
|
|
1983
2238
|
PYTHON: python,
|
|
2239
|
+
CODEX_SECURITY_PYTHON_COMMAND: python,
|
|
1984
2240
|
CODEX_CLI_PATH: resolveCodexCommand(environment).command,
|
|
1985
2241
|
};
|
|
1986
2242
|
}
|
|
@@ -2013,12 +2269,15 @@ function pluginHelperEnvironment(environment) {
|
|
|
2013
2269
|
export async function cleanupSdkDirectory(path) {
|
|
2014
2270
|
await rm(path, { recursive: true, force: true });
|
|
2015
2271
|
}
|
|
2016
|
-
export async function runCodexCommand(command, args, environment, input, signal) {
|
|
2017
|
-
const
|
|
2272
|
+
export async function runCodexCommand(command, args, environment, input, signal, archiveHandshake = false, stdinPrefix) {
|
|
2273
|
+
const cancellation = archiveHandshake ? new AbortController() : undefined;
|
|
2274
|
+
const abort = () => cancellation?.abort(signal?.reason);
|
|
2275
|
+
let awaitingArchive = archiveHandshake;
|
|
2276
|
+
const child = spawn(executablePathForSpawn(command.command), [...(command.args ?? []), ...args], {
|
|
2018
2277
|
env: environment,
|
|
2019
2278
|
stdio: ["pipe", "pipe", "pipe"],
|
|
2020
2279
|
windowsHide: true,
|
|
2021
|
-
signal,
|
|
2280
|
+
signal: cancellation?.signal ?? signal,
|
|
2022
2281
|
});
|
|
2023
2282
|
let stdout = "";
|
|
2024
2283
|
let stderr = "";
|
|
@@ -2027,6 +2286,17 @@ export async function runCodexCommand(command, args, environment, input, signal)
|
|
|
2027
2286
|
child.stderr.setEncoding("utf8");
|
|
2028
2287
|
child.stdout.on("data", (chunk) => {
|
|
2029
2288
|
stdout += chunk;
|
|
2289
|
+
if (awaitingArchive && stdout.startsWith(ARCHIVE_READY)) {
|
|
2290
|
+
awaitingArchive = false;
|
|
2291
|
+
stdout = stdout.slice(ARCHIVE_READY.length);
|
|
2292
|
+
signal?.removeEventListener("abort", abort);
|
|
2293
|
+
// The helper cannot rename until this acknowledgement. Detach and check
|
|
2294
|
+
// cancellation before allowing the filesystem/database transaction.
|
|
2295
|
+
if (signal?.aborted)
|
|
2296
|
+
abort();
|
|
2297
|
+
else
|
|
2298
|
+
child.stdin.end("\n");
|
|
2299
|
+
}
|
|
2030
2300
|
});
|
|
2031
2301
|
child.stderr.on("data", (chunk) => {
|
|
2032
2302
|
stderr += chunk;
|
|
@@ -2043,8 +2313,24 @@ export async function runCodexCommand(command, args, environment, input, signal)
|
|
|
2043
2313
|
? resolve({ success: exitCode === 0, exitCode, stdout, stderr })
|
|
2044
2314
|
: reject(processError));
|
|
2045
2315
|
});
|
|
2046
|
-
|
|
2047
|
-
|
|
2316
|
+
if (archiveHandshake) {
|
|
2317
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
2318
|
+
if (signal?.aborted)
|
|
2319
|
+
abort();
|
|
2320
|
+
}
|
|
2321
|
+
try {
|
|
2322
|
+
if (stdinPrefix !== undefined)
|
|
2323
|
+
child.stdin.write(stdinPrefix);
|
|
2324
|
+
if (archiveHandshake)
|
|
2325
|
+
child.stdin.write(`${JSON.stringify(input ?? "")}\n`);
|
|
2326
|
+
else
|
|
2327
|
+
child.stdin.end(input);
|
|
2328
|
+
return await completion;
|
|
2329
|
+
}
|
|
2330
|
+
finally {
|
|
2331
|
+
if (archiveHandshake)
|
|
2332
|
+
signal?.removeEventListener("abort", abort);
|
|
2333
|
+
}
|
|
2048
2334
|
}
|
|
2049
2335
|
export async function probeCodexSandbox(command, environment, signal) {
|
|
2050
2336
|
// This preflight covers the Unix sandbox backends.
|
|
@@ -2163,7 +2449,7 @@ async function requirePython(candidate, source, environment, protectedRoot, sign
|
|
|
2163
2449
|
}
|
|
2164
2450
|
async function usablePython(candidate, environment = process.env, protectedRoot = process.cwd(), signal) {
|
|
2165
2451
|
const command = await resolveTrustedExecutable(isPythonPathCandidate(candidate)
|
|
2166
|
-
?
|
|
2452
|
+
? expandExecutableHome(candidate, environment)
|
|
2167
2453
|
: candidate, environment, protectedRoot);
|
|
2168
2454
|
if (command === null)
|
|
2169
2455
|
return null;
|
|
@@ -2190,14 +2476,13 @@ async function usablePython(candidate, environment = process.env, protectedRoot
|
|
|
2190
2476
|
}
|
|
2191
2477
|
}
|
|
2192
2478
|
export function isPythonPathCandidate(candidate) {
|
|
2193
|
-
return
|
|
2194
|
-
candidate.includes("\\") ||
|
|
2195
|
-
candidate.startsWith("."));
|
|
2479
|
+
return candidate.includes("/") || candidate.includes("\\");
|
|
2196
2480
|
}
|
|
2197
2481
|
async function hasPluginManifest(root) {
|
|
2198
2482
|
return await lstat(join(root, ".codex-plugin", "plugin.json")).then((metadata) => metadata.isFile(), () => false);
|
|
2199
2483
|
}
|
|
2200
|
-
|
|
2484
|
+
/** @internal Compare filesystem identity without depending on path spelling. */
|
|
2485
|
+
export function sameFile(left, right) {
|
|
2201
2486
|
// NTFS file IDs can exceed JavaScript's safe integer range.
|
|
2202
2487
|
return Promise.all([
|
|
2203
2488
|
stat(left, { bigint: true }),
|
|
@@ -2205,6 +2490,13 @@ function sameFile(left, right) {
|
|
|
2205
2490
|
]).then(([leftMetadata, rightMetadata]) => leftMetadata.dev === rightMetadata.dev &&
|
|
2206
2491
|
leftMetadata.ino === rightMetadata.ino, () => false);
|
|
2207
2492
|
}
|
|
2493
|
+
function expandExecutableHome(value, environment) {
|
|
2494
|
+
const path = value.startsWith("~\\") ? value.replaceAll("\\", "/") : value;
|
|
2495
|
+
// Expand only the home prefix; joining the suffix would collapse symlink/.. paths.
|
|
2496
|
+
return path.startsWith("~/")
|
|
2497
|
+
? `${expandHome("~", environment)}${sep}${path.slice(2)}`
|
|
2498
|
+
: expandHome(path, environment);
|
|
2499
|
+
}
|
|
2208
2500
|
export function expandHome(value, environment = process.env) {
|
|
2209
2501
|
const home = (process.platform === "win32"
|
|
2210
2502
|
? (environmentValue(environment, "USERPROFILE") ??
|