@openai/codex-security 0.1.31 → 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 +442 -2434
- package/_bundled_plugin/.app.json +5 -1
- package/_bundled_plugin/.codex-plugin/plugin.json +9 -5
- package/_bundled_plugin/.mcp.json +3 -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 +7 -214
- 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 +5 -5
- package/_bundled_plugin/references/config-preflight.md +1 -5
- package/_bundled_plugin/references/core-scan.md +34 -10
- package/_bundled_plugin/references/final-report.md +13 -13
- package/_bundled_plugin/references/finding-detail-fields.md +90 -80
- package/_bundled_plugin/references/sarif-adapter.md +1 -1
- package/_bundled_plugin/references/scan-artifacts.md +3 -4
- package/_bundled_plugin/references/scan-contract.md +11 -6
- 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 +2 -2
- package/_bundled_plugin/schemas/coverage.schema.json +23 -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 +83 -95
- 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 +245 -356
- 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 +29 -69
- package/_bundled_plugin/scripts/deep_scan_config.py +9 -11
- package/_bundled_plugin/scripts/deep_scan_workbench.py +208 -363
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -5
- package/_bundled_plugin/scripts/finalize_scan_contract.py +733 -375
- package/_bundled_plugin/scripts/finding_preview.py +81 -91
- package/_bundled_plugin/scripts/generate_in_scope_files.py +48 -102
- package/_bundled_plugin/scripts/generate_rank_input.py +117 -888
- package/_bundled_plugin/scripts/launch_codex_security_mcp +35 -6
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +5 -5
- package/_bundled_plugin/scripts/rank_preview.py +43 -902
- package/_bundled_plugin/scripts/report_projection.py +143 -219
- package/_bundled_plugin/scripts/snapshot_sqlite.py +6 -1
- package/_bundled_plugin/scripts/threat_model_projection.py +161 -0
- 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 +59 -9
- 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 +21 -6
- package/_bundled_plugin/scripts/workbench_cli.py +99 -190
- package/_bundled_plugin/scripts/workbench_constants.py +6 -14
- package/_bundled_plugin/scripts/workbench_db.py +524 -672
- package/_bundled_plugin/scripts/workbench_feedback.py +6 -3
- package/_bundled_plugin/scripts/workbench_finding_index.py +20 -7
- 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 +28 -18
- package/_bundled_plugin/scripts/workbench_progress.py +26 -92
- package/_bundled_plugin/scripts/workbench_publication.py +77 -116
- package/_bundled_plugin/scripts/workbench_remediation.py +14 -20
- package/_bundled_plugin/scripts/workbench_saved_results.py +1402 -263
- package/_bundled_plugin/scripts/workbench_scan_history.py +57 -57
- package/_bundled_plugin/scripts/workbench_scan_start.py +109 -52
- package/_bundled_plugin/scripts/workbench_scan_usage.py +30 -49
- package/_bundled_plugin/scripts/workbench_schema.py +71 -1370
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +16 -7
- package/_bundled_plugin/scripts/workbench_target.py +526 -150
- package/_bundled_plugin/scripts/workbench_target_state.py +1 -5
- package/_bundled_plugin/scripts/workbench_validation.py +19 -44
- 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 +6 -6
- 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 +2 -2
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +13 -1
- package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
- 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 +63 -15
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +970 -553
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +70 -0
- package/dist/artifact-export.d.ts.map +1 -0
- package/dist/artifact-export.js +292 -0
- package/dist/artifact-export.js.map +1 -0
- package/dist/auth.d.ts +2 -6
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +27 -12
- package/dist/auth.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +9 -9
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-scan-severity.d.ts.map +1 -1
- package/dist/classify-scan-severity.js +2 -5
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity.d.ts +28 -17
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +16 -35
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts +3 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +285 -0
- package/dist/cli-help.js.map +1 -0
- 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 +22 -24
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1660 -1556
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +11 -17
- 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-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +1 -2
- package/dist/codex-prompt.js.map +1 -1
- package/dist/codex-sdk-environment.d.ts +3 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -0
- package/dist/codex-sdk-environment.js +68 -0
- package/dist/codex-sdk-environment.js.map +1 -0
- package/dist/component-plan.d.ts +2 -5
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +38 -34
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +7 -5
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +54 -44
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +93 -104
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +15 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +124 -348
- 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 +75 -34
- 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 +116 -134
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +7 -6
- 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 +23 -16
- 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 +33 -20
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +9 -1
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +129 -20
- 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 +59 -47
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.d.ts.map +1 -1
- package/dist/deduplication/deduplication.js +59 -113
- 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 +12 -28
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +188 -12
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +34 -24
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/review.d.ts +7 -0
- package/dist/deduplication/review.d.ts.map +1 -1
- package/dist/deduplication/review.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 +159 -44
- 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 +7 -23
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-progress.d.ts +2 -1
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +32 -47
- 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 +5 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -7
- 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 +26 -30
- 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 +18 -13
- 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 +16 -44
- package/dist/findings-import.js.map +1 -1
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +9 -4
- package/dist/github.js.map +1 -1
- package/dist/import-scan.d.ts.map +1 -1
- package/dist/import-scan.js +49 -39
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +11 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts +7 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +115 -47
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js +4 -10
- 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 +24 -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 +225 -153
- 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 +69 -14
- package/dist/owner-evidence.js.map +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +5 -6
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config-schema.d.ts +10 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +5 -3
- package/dist/project-config.js.map +1 -1
- package/dist/prompt-files.d.ts +0 -1
- package/dist/prompt-files.d.ts.map +1 -1
- package/dist/prompt-files.js +2 -4
- package/dist/prompt-files.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 +40 -79
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +48 -76
- 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 +7 -16
- 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 +138 -199
- package/dist/publish.js.map +1 -1
- package/dist/record.d.ts +2 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +4 -0
- package/dist/record.js.map +1 -0
- 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/result.d.ts +4 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +7 -0
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +25 -17
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +619 -255
- 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 +16 -32
- package/dist/saved-scan.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +19 -30
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +31 -18
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +307 -347
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +3 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +351 -92
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +55 -15
- 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 +14 -12
- 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 +18 -3
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +5 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +4 -0
- package/dist/scan-settings.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 +15 -33
- package/dist/security-policy-cli.js.map +1 -1
- package/dist/security-policy.d.ts +17 -9
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +131 -98
- 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 +11 -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 +55 -55
- 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 +20 -32
- 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 +6 -5
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +15 -10
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +12 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +124 -62
- package/dist/targets.js.map +1 -1
- package/dist/trusted-executable.d.ts +6 -1
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +28 -9
- package/dist/trusted-executable.js.map +1 -1
- package/dist/value.d.ts +2 -0
- package/dist/value.d.ts.map +1 -0
- package/dist/value.js +27 -0
- package/dist/value.js.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +3 -6
- package/dist/version.js.map +1 -1
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -2
- package/dist/windows-path.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 +2 -0
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +40 -46
- package/dist/worker-progress.js.map +1 -1
- package/docs/cli.md +1778 -0
- package/docs/dedupe-records.md +24 -0
- package/docs/findings-service.md +402 -0
- package/package.json +23 -23
- package/schemas/project-config.schema.json +5 -0
- package/_bundled_plugin/schemas/tools/worker-threat-model.schema.json +0 -18
- package/_bundled_plugin/scripts/normalize_candidates.py +0 -338
- 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 -119
- 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/findings-service.d.ts +0 -20
- package/dist/server/findings-service.d.ts.map +0 -1
- package/dist/server/findings-service.js +0 -31
- package/dist/server/findings-service.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 -6
- package/dist/server/routes.d.ts.map +0 -1
- package/dist/server/routes.js +0 -86
- 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 -17
- package/dist/server/server.js.map +0 -1
- package/dist/server/validation.d.ts +0 -17
- package/dist/server/validation.d.ts.map +0 -1
- package/dist/server/validation.js +0 -53
- package/dist/server/validation.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud-publish.d.ts","sourceRoot":"","sources":["../src/cloud-publish.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cloud-publish.d.ts","sourceRoot":"","sources":["../src/cloud-publish.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAC;AAoCzD,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;CACtB;AAED,UAAU,4BAA4B;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACjE,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,kBAAkB,CACtC,aAAa,EAAE,MAAM,EACrB,YAAY,GAAE,4BAA4B,GAAG;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;CACpB,GACL,OAAO,CAAC,sBAAsB,CAAC,CAYjC;AAED,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,MAAM,EACf,YAAY,GAAE,4BAAiC,GAC9C,OAAO,CAAC,sBAAsB,CAAC,CA6FjC"}
|
package/dist/cloud-publish.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import { existsSync } from "node:fs";
|
|
3
2
|
import { readFile } from "node:fs/promises";
|
|
4
3
|
import { join } from "node:path";
|
|
5
4
|
import { z } from "incur";
|
|
6
5
|
import { parse as parseToml } from "smol-toml";
|
|
7
|
-
import { loadContract } from "./contract.js";
|
|
8
|
-
import { AuthenticationRequiredError, CodexSecurityError } from "./errors.js";
|
|
9
|
-
import { CSV_TARGET_ID, csvRowFinding, parseFindingsCsv, } from "./findings-import.js";
|
|
6
|
+
import { loadContract, sha256Text as sha256 } from "./contract.js";
|
|
7
|
+
import { AuthenticationRequiredError, CodexSecurityError, errorMessage, } from "./errors.js";
|
|
8
|
+
import { CSV_TARGET_ID, bindImportedFindings, csvRowFinding, parseFindingsCsv, } from "./findings-import.js";
|
|
10
9
|
import { bundledPluginRoot, codexSecurityCredentialAllowsAmbientImport, codexSecurityCredentialHome, codexSecurityHasStoredFileCredentials, expandHome, } from "./runtime.js";
|
|
11
10
|
import { VERSION } from "./version.js";
|
|
12
11
|
const CLOUD_PUBLISH_URL = "https://chatgpt.com/backend-api/aardvark/cli/findings";
|
|
@@ -39,18 +38,19 @@ export async function publishFindingsCsvToCloud(csvPath, dependencies = {}) {
|
|
|
39
38
|
dependencies.signal?.throwIfAborted();
|
|
40
39
|
let source;
|
|
41
40
|
try {
|
|
42
|
-
source = await readFile(csvPath
|
|
41
|
+
source = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(await readFile(csvPath));
|
|
43
42
|
}
|
|
44
43
|
catch (error) {
|
|
45
|
-
throw new CodexSecurityError(
|
|
46
|
-
cause: error,
|
|
47
|
-
});
|
|
44
|
+
throw new CodexSecurityError(`Could not read findings CSV. ${errorMessage(error)}`, { cause: error });
|
|
48
45
|
}
|
|
49
46
|
dependencies.signal?.throwIfAborted();
|
|
50
47
|
const rows = parseFindingsCsv(source);
|
|
48
|
+
if (rows.length === 0) {
|
|
49
|
+
throw new CodexSecurityError("Findings CSV must contain at least one finding.");
|
|
50
|
+
}
|
|
51
51
|
const digest = sha256(source);
|
|
52
52
|
const scanId = `scan_csv_${sha256(["codex-security-csv-import/v1", VERSION, source].join("\0")).slice(0, 24)}`;
|
|
53
|
-
const findings = rows.map(
|
|
53
|
+
const findings = bindImportedFindings(rows.map(csvRowFinding), "csv", scanId, CSV_TARGET_ID);
|
|
54
54
|
const timestamp = "1970-01-01T00:00:00.000Z";
|
|
55
55
|
const findingsDocument = JSON.stringify({
|
|
56
56
|
documentType: "codex-security.findings",
|
|
@@ -63,7 +63,6 @@ export async function publishFindingsCsvToCloud(csvPath, dependencies = {}) {
|
|
|
63
63
|
schemaVersion: "1.0",
|
|
64
64
|
scanId,
|
|
65
65
|
mode: "repository",
|
|
66
|
-
completeness: "unknown",
|
|
67
66
|
inventoryStrategy: "custom",
|
|
68
67
|
includePaths: ["."],
|
|
69
68
|
excludePaths: [],
|
|
@@ -116,13 +115,7 @@ export async function publishFindingsCsvToCloud(csvPath, dependencies = {}) {
|
|
|
116
115
|
};
|
|
117
116
|
return publishCloudPayload(scan, findings, dependencies);
|
|
118
117
|
}
|
|
119
|
-
function sha256(value) {
|
|
120
|
-
return createHash("sha256").update(value, "utf8").digest("hex");
|
|
121
|
-
}
|
|
122
118
|
async function publishCloudPayload(scan, findings, dependencies) {
|
|
123
|
-
if (findings.length === 0) {
|
|
124
|
-
throw new CodexSecurityError("There are no findings to publish.");
|
|
125
|
-
}
|
|
126
119
|
dependencies.signal?.throwIfAborted();
|
|
127
120
|
if (dependencies.dryRun) {
|
|
128
121
|
return {
|
|
@@ -196,7 +189,8 @@ async function publishCloudPayload(scan, findings, dependencies) {
|
|
|
196
189
|
};
|
|
197
190
|
}
|
|
198
191
|
async function readCloudCredentials(environment) {
|
|
199
|
-
|
|
192
|
+
const configuredHome = environment["CODEX_HOME"];
|
|
193
|
+
let home = expandHome(configuredHome?.trim() ? configuredHome : "~/.codex", environment);
|
|
200
194
|
let requireFileStorage = true;
|
|
201
195
|
const dedicatedHome = codexSecurityCredentialHome(environment);
|
|
202
196
|
if (existsSync(dedicatedHome)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud-publish.js","sourceRoot":"","sources":["../src/cloud-publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE9E,OAAO,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,iBAAiB,EACjB,0CAA0C,EAC1C,2BAA2B,EAC3B,qCAAqC,EACrC,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,iBAAiB,GACrB,uDAAuD,CAAC;AAC1D,MAAM,sBAAsB,GAC1B,qKAAqK,CAAC;AAExK,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE;IAC1C,cAAc,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;IACnC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf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AC;QACvB,IAAI,iBAA0B,CAAC;QAC/B,IAAI,CAAC;YACH,iBAAiB,GAAG,SAAS,CAC3B,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,EAAE,MAAM,CAAC,CAClD,CAAC,4BAA4B,CAAC,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,2BAA2B,CAAC,sBAAsB,CAAC,CAAC;QAChE,CAAC;QACD,kEAAkE;QAClE,wEAAwE;QACxE,IAAI,iBAAiB,KAAK,MAAM,EAAE,CAAC;YACjC,MAAM,IAAI,2BAA2B,CAAC,sBAAsB,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IACD,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,iBAAiB,CAAC,SAAS,CAC7C,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC,CAC5D,CAAC;QACF,IAAI,WAAW,CAAC,OAAO;YAAE,OAAO,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,2EAA2E;IAC7E,CAAC;IACD,MAAM,IAAI,2BAA2B,CAAC,sBAAsB,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { z } from \"incur\";\nimport { parse as parseToml } from \"smol-toml\";\nimport { loadContract } from \"./contract.js\";\nimport { AuthenticationRequiredError, CodexSecurityError } from \"./errors.js\";\nimport type { Finding, ScanManifest } from \"./models.js\";\nimport {\n CSV_TARGET_ID,\n csvRowFinding,\n parseFindingsCsv,\n} from \"./findings-import.js\";\nimport {\n bundledPluginRoot,\n codexSecurityCredentialAllowsAmbientImport,\n codexSecurityCredentialHome,\n codexSecurityHasStoredFileCredentials,\n expandHome,\n} from \"./runtime.js\";\nimport { VERSION } from \"./version.js\";\n\nconst CLOUD_PUBLISH_URL =\n \"https://chatgpt.com/backend-api/aardvark/cli/findings\";\nconst CHATGPT_LOGIN_REQUIRED =\n \"Cloud publication requires a ChatGPT login already available to Codex Security. Run a scan or sign in with ChatGPT using Codex file credential storage, then retry.\";\n\nconst credentialsSchema = z.object({\n auth_mode: z.literal(\"chatgpt\").optional(),\n OPENAI_API_KEY: z.null().optional(),\n tokens: z.object({\n access_token: z.string().trim().min(1),\n account_id: z.string().trim().min(1),\n }),\n});\n\nconst receiptSchema = z.object({\n status: z.literal(\"accepted\"),\n finding_ids: z.array(z.string().min(1)),\n finding_count: z.number().int().positive(),\n});\n\nexport interface CloudPublicationResult {\n scanId: string;\n findingIds: string[];\n findingCount: number;\n dryRun?: true;\n findings?: Finding[];\n}\n\ninterface CloudPublicationDependencies {\n environment?: NodeJS.ProcessEnv;\n fetch?: (url: string, options: RequestInit) => Promise<Response>;\n signal?: AbortSignal;\n dryRun?: boolean;\n}\n\nexport async function publishScanToCloud(\n scanDirectory: string,\n dependencies: CloudPublicationDependencies & {\n expectedScanId?: string;\n } = {},\n): Promise<CloudPublicationResult> {\n const { manifest, findings } = await loadContract(scanDirectory, {\n pluginRoot: await bundledPluginRoot(),\n signal: dependencies.signal,\n expectedScanId: dependencies.expectedScanId,\n });\n if (findings.findings.length === 0) {\n throw new CodexSecurityError(\n \"The completed scan has no findings to publish.\",\n );\n }\n return publishCloudPayload(manifest.scan, findings.findings, dependencies);\n}\n\nexport async function publishFindingsCsvToCloud(\n csvPath: string,\n dependencies: CloudPublicationDependencies = {},\n): Promise<CloudPublicationResult> {\n dependencies.signal?.throwIfAborted();\n let source: string;\n try {\n source = await readFile(csvPath, \"utf8\");\n } catch (error) {\n throw new CodexSecurityError(\"Could not read findings CSV.\", {\n cause: error,\n });\n }\n dependencies.signal?.throwIfAborted();\n const rows = parseFindingsCsv(source);\n const digest = sha256(source);\n const scanId = `scan_csv_${sha256(\n [\"codex-security-csv-import/v1\", VERSION, source].join(\"\\0\"),\n ).slice(0, 24)}`;\n const findings = rows.map((row) => csvRowFinding(row, scanId));\n const timestamp = \"1970-01-01T00:00:00.000Z\";\n const findingsDocument = JSON.stringify({\n documentType: \"codex-security.findings\",\n schemaVersion: \"1.0\",\n scanId,\n findings,\n });\n const coverageDocument = JSON.stringify({\n documentType: \"codex-security.coverage\",\n schemaVersion: \"1.0\",\n scanId,\n mode: \"repository\",\n completeness: \"unknown\",\n inventoryStrategy: \"custom\",\n includePaths: [\".\"],\n excludePaths: [],\n surfaces: findings.map((finding) => ({\n id: finding.occurrenceId,\n label: finding.title,\n disposition: \"reported\",\n receiptRefs: [],\n })),\n explicitExclusions: [],\n deferred: [],\n });\n const scan: ScanManifest[\"scan\"] = {\n id: scanId,\n producer: { name: \"codex-security-cli\", version: VERSION },\n status: \"completed\",\n startedAt: timestamp,\n completedAt: timestamp,\n sealedAt: timestamp,\n target: {\n kind: \"directory_snapshot\",\n targetId: CSV_TARGET_ID,\n displayName: \"findings.csv\",\n snapshotDigest: `codex-security-snapshot/v1:sha256:${digest}`,\n },\n scope: {\n includePaths: [\".\"],\n excludePaths: [],\n summary: \"Findings imported from a Codex Security CSV export.\",\n },\n coverageRef: \"coverage.json\",\n findingsRef: \"findings.json\",\n artifacts: [\n {\n path: \"findings.json\",\n sha256: sha256(findingsDocument),\n mediaType: \"application/json\",\n },\n {\n path: \"coverage.json\",\n sha256: sha256(coverageDocument),\n mediaType: \"application/json\",\n },\n {\n path: \"findings.csv\",\n sha256: digest,\n mediaType: \"text/csv\",\n },\n ],\n };\n return publishCloudPayload(scan, findings, dependencies);\n}\n\nfunction sha256(value: string): string {\n return createHash(\"sha256\").update(value, \"utf8\").digest(\"hex\");\n}\n\nasync function publishCloudPayload(\n scan: ScanManifest[\"scan\"],\n findings: Finding[],\n dependencies: CloudPublicationDependencies,\n): Promise<CloudPublicationResult> {\n if (findings.length === 0) {\n throw new CodexSecurityError(\"There are no findings to publish.\");\n }\n dependencies.signal?.throwIfAborted();\n if (dependencies.dryRun) {\n return {\n scanId: scan.id,\n findingIds: [],\n findingCount: findings.length,\n dryRun: true,\n findings,\n };\n }\n const credentials = await readCloudCredentials(\n dependencies.environment ?? process.env,\n );\n const publishUrl =\n dependencies.environment?.[\"CODEX_SECURITY_CLOUD_PUBLISH_URL\"]?.trim() ||\n CLOUD_PUBLISH_URL;\n const timeout = AbortSignal.timeout(30_000);\n const signal = dependencies.signal\n ? AbortSignal.any([dependencies.signal, timeout])\n : timeout;\n let response: Response;\n try {\n response = await (dependencies.fetch ?? globalThis.fetch)(publishUrl, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${credentials.access_token}`,\n \"ChatGPT-Account-ID\": credentials.account_id,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n },\n body: JSON.stringify({\n schemaVersion: \"1.0\",\n scan,\n findings,\n }),\n redirect: \"error\",\n signal,\n });\n } catch {\n dependencies.signal?.throwIfAborted();\n // A lost response does not establish whether the server accepted the POST.\n throw new CodexSecurityError(\n \"Cloud publication was not confirmed. The request was not retried; check whether it was accepted before submitting again.\",\n );\n }\n if (!response.ok) {\n await response.body?.cancel().catch(() => undefined);\n const detail =\n response.status === 401\n ? \"Sign in with ChatGPT again before retrying.\"\n : response.status === 403\n ? \"The signed-in account is not authorized to publish to Cloud.\"\n : response.status === 404\n ? \"Cloud publication is not available for this account or deployment.\"\n : \"The request was not retried.\";\n throw new CodexSecurityError(\n `Cloud publication failed (HTTP ${response.status}). ${detail}`,\n );\n }\n const receipt = receiptSchema.safeParse(\n await response.json().catch(() => {\n dependencies.signal?.throwIfAborted();\n return undefined;\n }),\n );\n // Cloud assigns opaque IDs in request order, so they cannot be compared to\n // local finding IDs. The authenticated response must still preserve the\n // submitted count and return one distinct observation for each finding.\n if (\n (response.status !== 200 && response.status !== 201) ||\n !receipt.success ||\n receipt.data.finding_count !== findings.length ||\n receipt.data.finding_ids.length !== findings.length ||\n new Set(receipt.data.finding_ids).size !== receipt.data.finding_ids.length\n ) {\n throw new CodexSecurityError(\n \"Cloud publication returned an invalid acceptance receipt. Check whether the request was accepted before submitting again.\",\n );\n }\n return {\n scanId: scan.id,\n findingIds: receipt.data.finding_ids,\n findingCount: receipt.data.finding_count,\n };\n}\n\nasync function readCloudCredentials(environment: NodeJS.ProcessEnv) {\n let home = expandHome(\n environment[\"CODEX_HOME\"]?.trim() || \"~/.codex\",\n environment,\n );\n let requireFileStorage = true;\n const dedicatedHome = codexSecurityCredentialHome(environment);\n if (existsSync(dedicatedHome)) {\n if (!(await codexSecurityCredentialAllowsAmbientImport(dedicatedHome))) {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n if (await codexSecurityHasStoredFileCredentials(dedicatedHome)) {\n home = dedicatedHome;\n requireFileStorage = false;\n } else if (existsSync(join(dedicatedHome, \"config.toml\"))) {\n // Do not silently switch accounts when the dedicated login may be in a keyring.\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n }\n if (requireFileStorage) {\n let credentialStorage: unknown;\n try {\n credentialStorage = parseToml(\n await readFile(join(home, \"config.toml\"), \"utf8\"),\n )[\"cli_auth_credentials_store\"];\n } catch {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n // File presence is not proof that it is the active ambient login:\n // automatic or keyring storage can leave auth.json for another account.\n if (credentialStorage !== \"file\") {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n }\n try {\n const credentials = credentialsSchema.safeParse(\n JSON.parse(await readFile(join(home, \"auth.json\"), \"utf8\")),\n );\n if (credentials.success) return credentials.data.tokens;\n } catch {\n // Parsing and filesystem diagnostics must not reflect credential contents.\n }\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cloud-publish.js","sourceRoot":"","sources":["../src/cloud-publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SA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AkE;QAClE,wEAAwE;QACxE,IAAI,iBAAiB,KAAK,MAAM,EAAE,CAAC;YACjC,MAAM,IAAI,2BAA2B,CAAC,sBAAsB,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IACD,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,iBAAiB,CAAC,SAAS,CAC7C,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC,CAC5D,CAAC;QACF,IAAI,WAAW,CAAC,OAAO;YAAE,OAAO,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,2EAA2E;IAC7E,CAAC;IACD,MAAM,IAAI,2BAA2B,CAAC,sBAAsB,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { z } from \"incur\";\nimport { parse as parseToml } from \"smol-toml\";\nimport { loadContract, sha256Text as sha256 } from \"./contract.js\";\nimport {\n AuthenticationRequiredError,\n CodexSecurityError,\n errorMessage,\n} from \"./errors.js\";\nimport type { Finding, ScanManifest } from \"./models.js\";\nimport {\n CSV_TARGET_ID,\n bindImportedFindings,\n csvRowFinding,\n parseFindingsCsv,\n} from \"./findings-import.js\";\nimport {\n bundledPluginRoot,\n codexSecurityCredentialAllowsAmbientImport,\n codexSecurityCredentialHome,\n codexSecurityHasStoredFileCredentials,\n expandHome,\n} from \"./runtime.js\";\nimport { VERSION } from \"./version.js\";\n\nconst CLOUD_PUBLISH_URL =\n \"https://chatgpt.com/backend-api/aardvark/cli/findings\";\nconst CHATGPT_LOGIN_REQUIRED =\n \"Cloud publication requires a ChatGPT login already available to Codex Security. Run a scan or sign in with ChatGPT using Codex file credential storage, then retry.\";\n\nconst credentialsSchema = z.object({\n auth_mode: z.literal(\"chatgpt\").optional(),\n OPENAI_API_KEY: z.null().optional(),\n tokens: z.object({\n access_token: z.string().trim().min(1),\n account_id: z.string().trim().min(1),\n }),\n});\n\nconst receiptSchema = z.object({\n status: z.literal(\"accepted\"),\n finding_ids: z.array(z.string().min(1)),\n finding_count: z.number().int().positive(),\n});\n\nexport interface CloudPublicationResult {\n scanId: string;\n findingIds: string[];\n findingCount: number;\n dryRun?: true;\n findings?: Finding[];\n}\n\ninterface CloudPublicationDependencies {\n environment?: NodeJS.ProcessEnv;\n fetch?: (url: string, options: RequestInit) => Promise<Response>;\n signal?: AbortSignal;\n dryRun?: boolean;\n}\n\nexport async function publishScanToCloud(\n scanDirectory: string,\n dependencies: CloudPublicationDependencies & {\n expectedScanId?: string;\n } = {},\n): Promise<CloudPublicationResult> {\n const { manifest, findings } = await loadContract(scanDirectory, {\n pluginRoot: await bundledPluginRoot(),\n signal: dependencies.signal,\n expectedScanId: dependencies.expectedScanId,\n });\n if (findings.findings.length === 0) {\n throw new CodexSecurityError(\n \"The completed scan has no findings to publish.\",\n );\n }\n return publishCloudPayload(manifest.scan, findings.findings, dependencies);\n}\n\nexport async function publishFindingsCsvToCloud(\n csvPath: string,\n dependencies: CloudPublicationDependencies = {},\n): Promise<CloudPublicationResult> {\n dependencies.signal?.throwIfAborted();\n let source: string;\n try {\n source = new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true }).decode(\n await readFile(csvPath),\n );\n } catch (error) {\n throw new CodexSecurityError(\n `Could not read findings CSV. ${errorMessage(error)}`,\n { cause: error },\n );\n }\n dependencies.signal?.throwIfAborted();\n const rows = parseFindingsCsv(source);\n if (rows.length === 0) {\n throw new CodexSecurityError(\n \"Findings CSV must contain at least one finding.\",\n );\n }\n const digest = sha256(source);\n const scanId = `scan_csv_${sha256(\n [\"codex-security-csv-import/v1\", VERSION, source].join(\"\\0\"),\n ).slice(0, 24)}`;\n const findings = bindImportedFindings(\n rows.map(csvRowFinding),\n \"csv\",\n scanId,\n CSV_TARGET_ID,\n );\n const timestamp = \"1970-01-01T00:00:00.000Z\";\n const findingsDocument = JSON.stringify({\n documentType: \"codex-security.findings\",\n schemaVersion: \"1.0\",\n scanId,\n findings,\n });\n const coverageDocument = JSON.stringify({\n documentType: \"codex-security.coverage\",\n schemaVersion: \"1.0\",\n scanId,\n mode: \"repository\",\n inventoryStrategy: \"custom\",\n includePaths: [\".\"],\n excludePaths: [],\n surfaces: findings.map((finding) => ({\n id: finding.occurrenceId,\n label: finding.title,\n disposition: \"reported\",\n receiptRefs: [],\n })),\n explicitExclusions: [],\n deferred: [],\n });\n const scan: ScanManifest[\"scan\"] = {\n id: scanId,\n producer: { name: \"codex-security-cli\", version: VERSION },\n status: \"completed\",\n startedAt: timestamp,\n completedAt: timestamp,\n sealedAt: timestamp,\n target: {\n kind: \"directory_snapshot\",\n targetId: CSV_TARGET_ID,\n displayName: \"findings.csv\",\n snapshotDigest: `codex-security-snapshot/v1:sha256:${digest}`,\n },\n scope: {\n includePaths: [\".\"],\n excludePaths: [],\n summary: \"Findings imported from a Codex Security CSV export.\",\n },\n coverageRef: \"coverage.json\",\n findingsRef: \"findings.json\",\n artifacts: [\n {\n path: \"findings.json\",\n sha256: sha256(findingsDocument),\n mediaType: \"application/json\",\n },\n {\n path: \"coverage.json\",\n sha256: sha256(coverageDocument),\n mediaType: \"application/json\",\n },\n {\n path: \"findings.csv\",\n sha256: digest,\n mediaType: \"text/csv\",\n },\n ],\n };\n return publishCloudPayload(scan, findings, dependencies);\n}\n\nasync function publishCloudPayload(\n scan: ScanManifest[\"scan\"],\n findings: Finding[],\n dependencies: CloudPublicationDependencies,\n): Promise<CloudPublicationResult> {\n dependencies.signal?.throwIfAborted();\n if (dependencies.dryRun) {\n return {\n scanId: scan.id,\n findingIds: [],\n findingCount: findings.length,\n dryRun: true,\n findings,\n };\n }\n const credentials = await readCloudCredentials(\n dependencies.environment ?? process.env,\n );\n const publishUrl =\n dependencies.environment?.[\"CODEX_SECURITY_CLOUD_PUBLISH_URL\"]?.trim() ||\n CLOUD_PUBLISH_URL;\n const timeout = AbortSignal.timeout(30_000);\n const signal = dependencies.signal\n ? AbortSignal.any([dependencies.signal, timeout])\n : timeout;\n let response: Response;\n try {\n response = await (dependencies.fetch ?? globalThis.fetch)(publishUrl, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${credentials.access_token}`,\n \"ChatGPT-Account-ID\": credentials.account_id,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n },\n body: JSON.stringify({\n schemaVersion: \"1.0\",\n scan,\n findings,\n }),\n redirect: \"error\",\n signal,\n });\n } catch {\n dependencies.signal?.throwIfAborted();\n // A lost response does not establish whether the server accepted the POST.\n throw new CodexSecurityError(\n \"Cloud publication was not confirmed. The request was not retried; check whether it was accepted before submitting again.\",\n );\n }\n if (!response.ok) {\n await response.body?.cancel().catch(() => undefined);\n const detail =\n response.status === 401\n ? \"Sign in with ChatGPT again before retrying.\"\n : response.status === 403\n ? \"The signed-in account is not authorized to publish to Cloud.\"\n : response.status === 404\n ? \"Cloud publication is not available for this account or deployment.\"\n : \"The request was not retried.\";\n throw new CodexSecurityError(\n `Cloud publication failed (HTTP ${response.status}). ${detail}`,\n );\n }\n const receipt = receiptSchema.safeParse(\n await response.json().catch(() => {\n dependencies.signal?.throwIfAborted();\n return undefined;\n }),\n );\n // Cloud assigns opaque IDs in request order, so they cannot be compared to\n // local finding IDs. The authenticated response must still preserve the\n // submitted count and return one distinct observation for each finding.\n if (\n (response.status !== 200 && response.status !== 201) ||\n !receipt.success ||\n receipt.data.finding_count !== findings.length ||\n receipt.data.finding_ids.length !== findings.length ||\n new Set(receipt.data.finding_ids).size !== receipt.data.finding_ids.length\n ) {\n throw new CodexSecurityError(\n \"Cloud publication returned an invalid acceptance receipt. Check whether the request was accepted before submitting again.\",\n );\n }\n return {\n scanId: scan.id,\n findingIds: receipt.data.finding_ids,\n findingCount: receipt.data.finding_count,\n };\n}\n\nasync function readCloudCredentials(environment: NodeJS.ProcessEnv) {\n const configuredHome = environment[\"CODEX_HOME\"];\n let home = expandHome(\n configuredHome?.trim() ? configuredHome : \"~/.codex\",\n environment,\n );\n let requireFileStorage = true;\n const dedicatedHome = codexSecurityCredentialHome(environment);\n if (existsSync(dedicatedHome)) {\n if (!(await codexSecurityCredentialAllowsAmbientImport(dedicatedHome))) {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n if (await codexSecurityHasStoredFileCredentials(dedicatedHome)) {\n home = dedicatedHome;\n requireFileStorage = false;\n } else if (existsSync(join(dedicatedHome, \"config.toml\"))) {\n // Do not silently switch accounts when the dedicated login may be in a keyring.\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n }\n if (requireFileStorage) {\n let credentialStorage: unknown;\n try {\n credentialStorage = parseToml(\n await readFile(join(home, \"config.toml\"), \"utf8\"),\n )[\"cli_auth_credentials_store\"];\n } catch {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n // File presence is not proof that it is the active ambient login:\n // automatic or keyring storage can leave auth.json for another account.\n if (credentialStorage !== \"file\") {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n }\n try {\n const credentials = credentialsSchema.safeParse(\n JSON.parse(await readFile(join(home, \"auth.json\"), \"utf8\")),\n );\n if (credentials.success) return credentials.data.tokens;\n } catch {\n // Parsing and filesystem diagnostics must not reflect credential contents.\n }\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type CodeownerIdentity = {
|
|
2
|
+
kind: "person" | "group";
|
|
3
|
+
provider: "github";
|
|
4
|
+
handle: string;
|
|
5
|
+
} | {
|
|
6
|
+
kind: "person";
|
|
7
|
+
email: string;
|
|
8
|
+
};
|
|
9
|
+
export interface CodeownersRule {
|
|
10
|
+
pattern: string;
|
|
11
|
+
line: number;
|
|
12
|
+
rule: string;
|
|
13
|
+
owners: CodeownerIdentity[];
|
|
14
|
+
matches: (path: string) => boolean;
|
|
15
|
+
}
|
|
16
|
+
/** GitHub CODEOWNERS uses the last matching rule, including ownerless rules. */
|
|
17
|
+
export declare function parseCodeowners(source: string): CodeownersRule[];
|
|
18
|
+
export declare function codeownersForPath(rules: readonly CodeownersRule[], path: string): CodeownersRule | undefined;
|
|
19
|
+
//# sourceMappingURL=codeowners.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeowners.d.ts","sourceRoot":"","sources":["../src/codeowners.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,EAAE,CAAC;IAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACpC;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,EAAE,CAwChE;AAmFD,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,IAAI,EAAE,MAAM,GACX,cAAc,GAAG,SAAS,CAE5B"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/** GitHub CODEOWNERS uses the last matching rule, including ownerless rules. */
|
|
2
|
+
export function parseCodeowners(source) {
|
|
3
|
+
const rules = [];
|
|
4
|
+
for (const [index, line] of source.split(/\r?\n/u).entries()) {
|
|
5
|
+
const value = line.trim();
|
|
6
|
+
if (!value || value.startsWith("#"))
|
|
7
|
+
continue;
|
|
8
|
+
const token = /^(?:\\.|[^\s])+/u.exec(value)[0];
|
|
9
|
+
const matches = codeownersPattern(token);
|
|
10
|
+
if (matches === null)
|
|
11
|
+
continue;
|
|
12
|
+
const handles = value
|
|
13
|
+
.slice(token.length)
|
|
14
|
+
.split("#", 1)[0]
|
|
15
|
+
.trim()
|
|
16
|
+
.split(/\s+/u)
|
|
17
|
+
.filter(Boolean);
|
|
18
|
+
const owners = [];
|
|
19
|
+
let valid = true;
|
|
20
|
+
for (const handle of handles) {
|
|
21
|
+
if (/^@[a-z\d](?:[a-z\d_-]*[a-z\d])?(?:\/[a-z\d_.-]+)?$/iu.test(handle)) {
|
|
22
|
+
owners.push(handle.includes("/")
|
|
23
|
+
? { kind: "group", provider: "github", handle: handle.slice(1) }
|
|
24
|
+
: { kind: "person", provider: "github", handle: handle.slice(1) });
|
|
25
|
+
}
|
|
26
|
+
else if (/^[^@\s]+@[^@\s]+$/u.test(handle)) {
|
|
27
|
+
owners.push({ kind: "person", email: handle });
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
valid = false;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (valid)
|
|
35
|
+
rules.push({
|
|
36
|
+
pattern: token,
|
|
37
|
+
line: index + 1,
|
|
38
|
+
rule: line,
|
|
39
|
+
owners,
|
|
40
|
+
matches,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return rules;
|
|
44
|
+
}
|
|
45
|
+
function codeownersPattern(pattern) {
|
|
46
|
+
if (pattern.startsWith("!") || pattern.startsWith("\\#"))
|
|
47
|
+
return null;
|
|
48
|
+
const anchored = pattern.startsWith("/");
|
|
49
|
+
if (anchored)
|
|
50
|
+
pattern = pattern.slice(1);
|
|
51
|
+
const directory = pattern.endsWith("/");
|
|
52
|
+
if (directory)
|
|
53
|
+
pattern = pattern.slice(0, -1);
|
|
54
|
+
const rooted = anchored || pattern.includes("/");
|
|
55
|
+
const immediate = /(?:^|\/)[*?]$/u.test(pattern);
|
|
56
|
+
const characters = Array.from(pattern);
|
|
57
|
+
const tokens = [];
|
|
58
|
+
for (let index = 0; index < characters.length; index++) {
|
|
59
|
+
const character = characters[index];
|
|
60
|
+
if (character === "\\" && index + 1 < characters.length) {
|
|
61
|
+
tokens.push({ literal: characters[++index] });
|
|
62
|
+
}
|
|
63
|
+
else if (character === "[" ||
|
|
64
|
+
character === "]" ||
|
|
65
|
+
(character === "*" &&
|
|
66
|
+
characters[index + 1] === "*" &&
|
|
67
|
+
characters[index + 2] === "*")) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
else if (character === "*" &&
|
|
71
|
+
characters[index + 1] === "*" &&
|
|
72
|
+
(index === 0 || characters[index - 1] === "/") &&
|
|
73
|
+
(index + 2 === characters.length || characters[index + 2] === "/")) {
|
|
74
|
+
if (characters[index + 2] === "/") {
|
|
75
|
+
tokens.push("**/");
|
|
76
|
+
index += 2;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
tokens.push("**");
|
|
80
|
+
index++;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (character === "*" || character === "?")
|
|
84
|
+
tokens.push(character);
|
|
85
|
+
else
|
|
86
|
+
tokens.push({ literal: character });
|
|
87
|
+
}
|
|
88
|
+
return (path) => {
|
|
89
|
+
let active = new Set([0]);
|
|
90
|
+
let next = new Set();
|
|
91
|
+
// Deduplicate reachable positions: O(pattern * path) work and O(pattern)
|
|
92
|
+
// space, including when several wildcards can consume the same character.
|
|
93
|
+
for (let offset = 0;;) {
|
|
94
|
+
const boundary = offset === 0 || path[offset - 1] === "/";
|
|
95
|
+
if (!rooted && boundary)
|
|
96
|
+
active.add(0);
|
|
97
|
+
for (const index of active) {
|
|
98
|
+
const token = tokens[index];
|
|
99
|
+
if (token === "*" || token === "**" || (token === "**/" && boundary))
|
|
100
|
+
active.add(index + 1);
|
|
101
|
+
}
|
|
102
|
+
const end = offset === path.length;
|
|
103
|
+
// docs/* ends at the immediate child; service* may own a directory.
|
|
104
|
+
if (active.has(tokens.length) &&
|
|
105
|
+
(directory
|
|
106
|
+
? path[offset] === "/"
|
|
107
|
+
: end || (!immediate && path[offset] === "/")))
|
|
108
|
+
return true;
|
|
109
|
+
if (end)
|
|
110
|
+
return false;
|
|
111
|
+
const character = String.fromCodePoint(path.codePointAt(offset));
|
|
112
|
+
next.clear();
|
|
113
|
+
for (const index of active) {
|
|
114
|
+
const token = tokens[index];
|
|
115
|
+
if (token === undefined)
|
|
116
|
+
continue;
|
|
117
|
+
if (typeof token === "object") {
|
|
118
|
+
if (token.literal === character)
|
|
119
|
+
next.add(index + 1);
|
|
120
|
+
}
|
|
121
|
+
else if (token === "?") {
|
|
122
|
+
if (character !== "/")
|
|
123
|
+
next.add(index + 1);
|
|
124
|
+
}
|
|
125
|
+
else if (token !== "*" || character !== "/")
|
|
126
|
+
next.add(index);
|
|
127
|
+
}
|
|
128
|
+
if (rooted && next.size === 0)
|
|
129
|
+
return false;
|
|
130
|
+
[active, next] = [next, active];
|
|
131
|
+
offset += character.length;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export function codeownersForPath(rules, path) {
|
|
136
|
+
return rules.findLast(({ matches }) => matches(path));
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=codeowners.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeowners.js","sourceRoot":"","sources":["../src/codeowners.ts"],"names":[],"mappings":"AAYA,gFAAgF;AAChF,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,MAAM,KAAK,GAAqB,EAAE,CAAC;IACnC,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC1B,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,UAAU,CAAC,G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C9B,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS;wBAAE,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;gBACvD,CAAC;qBAAM,IAAI,KAAK,KAAK,GAAG,EAAE,CAAC;oBACzB,IAAI,SAAS,KAAK,GAAG;wBAAE,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;gBAC7C,CAAC;qBAAM,IAAI,KAAK,KAAK,GAAG,IAAI,SAAS,KAAK,GAAG;oBAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACjE,CAAC;YACD,IAAI,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;YAC5C,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAChC,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC;QAC7B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,KAAgC,EAChC,IAAY;IAEZ,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC","sourcesContent":["export type CodeownerIdentity =\n | { kind: \"person\" | \"group\"; provider: \"github\"; handle: string }\n | { kind: \"person\"; email: string };\n\nexport interface CodeownersRule {\n pattern: string;\n line: number;\n rule: string;\n owners: CodeownerIdentity[];\n matches: (path: string) => boolean;\n}\n\n/** GitHub CODEOWNERS uses the last matching rule, including ownerless rules. */\nexport function parseCodeowners(source: string): CodeownersRule[] {\n const rules: CodeownersRule[] = [];\n for (const [index, line] of source.split(/\\r?\\n/u).entries()) {\n const value = line.trim();\n if (!value || value.startsWith(\"#\")) continue;\n const token = /^(?:\\\\.|[^\\s])+/u.exec(value)![0];\n const matches = codeownersPattern(token);\n if (matches === null) continue;\n const handles = value\n .slice(token.length)\n .split(\"#\", 1)[0]!\n .trim()\n .split(/\\s+/u)\n .filter(Boolean);\n const owners: CodeownerIdentity[] = [];\n let valid = true;\n for (const handle of handles) {\n if (/^@[a-z\\d](?:[a-z\\d_-]*[a-z\\d])?(?:\\/[a-z\\d_.-]+)?$/iu.test(handle)) {\n owners.push(\n handle.includes(\"/\")\n ? { kind: \"group\", provider: \"github\", handle: handle.slice(1) }\n : { kind: \"person\", provider: \"github\", handle: handle.slice(1) },\n );\n } else if (/^[^@\\s]+@[^@\\s]+$/u.test(handle)) {\n owners.push({ kind: \"person\", email: handle });\n } else {\n valid = false;\n break;\n }\n }\n if (valid)\n rules.push({\n pattern: token,\n line: index + 1,\n rule: line,\n owners,\n matches,\n });\n }\n return rules;\n}\n\ntype PatternToken = { literal: string } | \"*\" | \"?\" | \"**\" | \"**/\";\n\nfunction codeownersPattern(pattern: string): CodeownersRule[\"matches\"] | null {\n if (pattern.startsWith(\"!\") || pattern.startsWith(\"\\\\#\")) return null;\n const anchored = pattern.startsWith(\"/\");\n if (anchored) pattern = pattern.slice(1);\n const directory = pattern.endsWith(\"/\");\n if (directory) pattern = pattern.slice(0, -1);\n const rooted = anchored || pattern.includes(\"/\");\n const immediate = /(?:^|\\/)[*?]$/u.test(pattern);\n const characters = Array.from(pattern);\n const tokens: PatternToken[] = [];\n for (let index = 0; index < characters.length; index++) {\n const character = characters[index]!;\n if (character === \"\\\\\" && index + 1 < characters.length) {\n tokens.push({ literal: characters[++index]! });\n } else if (\n character === \"[\" ||\n character === \"]\" ||\n (character === \"*\" &&\n characters[index + 1] === \"*\" &&\n characters[index + 2] === \"*\")\n ) {\n return null;\n } else if (\n character === \"*\" &&\n characters[index + 1] === \"*\" &&\n (index === 0 || characters[index - 1] === \"/\") &&\n (index + 2 === characters.length || characters[index + 2] === \"/\")\n ) {\n if (characters[index + 2] === \"/\") {\n tokens.push(\"**/\");\n index += 2;\n } else {\n tokens.push(\"**\");\n index++;\n }\n } else if (character === \"*\" || character === \"?\") tokens.push(character);\n else tokens.push({ literal: character });\n }\n return (path) => {\n let active = new Set([0]);\n let next = new Set<number>();\n // Deduplicate reachable positions: O(pattern * path) work and O(pattern)\n // space, including when several wildcards can consume the same character.\n for (let offset = 0; ;) {\n const boundary = offset === 0 || path[offset - 1] === \"/\";\n if (!rooted && boundary) active.add(0);\n for (const index of active) {\n const token = tokens[index];\n if (token === \"*\" || token === \"**\" || (token === \"**/\" && boundary))\n active.add(index + 1);\n }\n const end = offset === path.length;\n // docs/* ends at the immediate child; service* may own a directory.\n if (\n active.has(tokens.length) &&\n (directory\n ? path[offset] === \"/\"\n : end || (!immediate && path[offset] === \"/\"))\n )\n return true;\n if (end) return false;\n const character = String.fromCodePoint(path.codePointAt(offset)!);\n next.clear();\n for (const index of active) {\n const token = tokens[index];\n if (token === undefined) continue;\n if (typeof token === \"object\") {\n if (token.literal === character) next.add(index + 1);\n } else if (token === \"?\") {\n if (character !== \"/\") next.add(index + 1);\n } else if (token !== \"*\" || character !== \"/\") next.add(index);\n }\n if (rooted && next.size === 0) return false;\n [active, next] = [next, active];\n offset += character.length;\n }\n };\n}\n\nexport function codeownersForPath(\n rules: readonly CodeownersRule[],\n path: string,\n): CodeownersRule | undefined {\n return rules.findLast(({ matches }) => matches(path));\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-prompt.d.ts","sourceRoot":"","sources":["../src/codex-prompt.ts"],"names":[],"mappings":"AAAA,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAK,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"codex-prompt.d.ts","sourceRoot":"","sources":["../src/codex-prompt.ts"],"names":[],"mappings":"AAAA,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAK,GAAG,MAAM,CAE3E;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAKpD"}
|
package/dist/codex-prompt.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export function shellEnvironmentReference(name, suffix = "") {
|
|
2
|
-
|
|
3
|
-
return `"${prefix}${name}${suffix}"`;
|
|
2
|
+
return `"${process.platform === "win32" ? "$env:" : "$"}${name}${suffix}"`;
|
|
4
3
|
}
|
|
5
4
|
export function pluginPythonCommand() {
|
|
6
5
|
return `${process.platform === "win32" ? "& " : ""}${shellEnvironmentReference("PYTHON")}`;
|
package/dist/codex-prompt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-prompt.js","sourceRoot":"","sources":["../src/codex-prompt.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,yBAAyB,CAAC,IAAY,EAAE,MAAM,GAAG,EAAE;IACjE,
|
|
1
|
+
{"version":3,"file":"codex-prompt.js","sourceRoot":"","sources":["../src/codex-prompt.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,yBAAyB,CAAC,IAAY,EAAE,MAAM,GAAG,EAAE;IACjE,OAAO,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,GAAG,MAAM,GAAG,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,OAAO,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,yBAAyB,CAAC,QAAQ,CAAC,EAAE,CAAC;AAC7F,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;SACzB,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC;SAC/B,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC;SAC/B,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AACrC,CAAC","sourcesContent":["export function shellEnvironmentReference(name: string, suffix = \"\"): string {\n return `\"${process.platform === \"win32\" ? \"$env:\" : \"$\"}${name}${suffix}\"`;\n}\n\nexport function pluginPythonCommand(): string {\n return `${process.platform === \"win32\" ? \"& \" : \"\"}${shellEnvironmentReference(\"PYTHON\")}`;\n}\n\nexport function jsonForPrompt(value: unknown): string {\n return JSON.stringify(value)\n .replaceAll(\"\\u0085\", \"\\\\u0085\")\n .replaceAll(\"\\u2028\", \"\\\\u2028\")\n .replaceAll(\"\\u2029\", \"\\\\u2029\");\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-sdk-environment.d.ts","sourceRoot":"","sources":["../src/codex-sdk-environment.ts"],"names":[],"mappings":"AAKA,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA6BxB;AAED,wBAAgB,6BAA6B,CAC3C,gBAAgB,CAAC,EAAE,MAAM,GACxB,MAAM,CA0CR"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { existsSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { delimiter, dirname, join } from "node:path";
|
|
4
|
+
import { PluginBootstrapError } from "./errors.js";
|
|
5
|
+
export function bundledCodexSdkEnvironment(command, environment) {
|
|
6
|
+
// An SDK executable override disables its bundled-tool PATH setup.
|
|
7
|
+
let toolsDirectory;
|
|
8
|
+
try {
|
|
9
|
+
toolsDirectory = join(dirname(realpathSync.native(dirname(command))), "codex-path");
|
|
10
|
+
if (!statSync(toolsDirectory).isDirectory())
|
|
11
|
+
return environment;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return environment;
|
|
15
|
+
}
|
|
16
|
+
const result = { ...environment };
|
|
17
|
+
const pathKeys = Object.keys(result).filter((key) => process.platform === "win32"
|
|
18
|
+
? key.toLowerCase() === "path"
|
|
19
|
+
: key === "PATH");
|
|
20
|
+
const pathKey = pathKeys.includes("Path")
|
|
21
|
+
? "Path"
|
|
22
|
+
: (pathKeys.at(-1) ?? "PATH");
|
|
23
|
+
for (const key of pathKeys) {
|
|
24
|
+
if (key !== pathKey)
|
|
25
|
+
delete result[key];
|
|
26
|
+
}
|
|
27
|
+
const entries = (result[pathKey] ?? "")
|
|
28
|
+
.split(delimiter)
|
|
29
|
+
.filter((entry) => entry.length > 0 && entry !== toolsDirectory);
|
|
30
|
+
result[pathKey] = [toolsDirectory, ...entries].join(delimiter);
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
export function resolveBundledCodexExecutable(codexPackageJson) {
|
|
34
|
+
const platform = process.platform === "android" ? "linux" : process.platform;
|
|
35
|
+
const packageName = `@openai/codex-${platform}-${process.arch}`;
|
|
36
|
+
let packageJson;
|
|
37
|
+
let legacyVendor = false;
|
|
38
|
+
try {
|
|
39
|
+
const selectedPackageJson = codexPackageJson ??
|
|
40
|
+
createRequire(import.meta.url).resolve("@openai/codex/package.json");
|
|
41
|
+
try {
|
|
42
|
+
packageJson = createRequire(selectedPackageJson).resolve(`${packageName}/package.json`);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (codexPackageJson === undefined)
|
|
46
|
+
throw error;
|
|
47
|
+
packageJson = selectedPackageJson;
|
|
48
|
+
legacyVendor = true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw new PluginBootstrapError(`The bundled Codex executable could not be resolved from ${packageName}. Reinstall @openai/codex with optional dependencies enabled, or set CODEX_CLI_PATH to an installed Codex executable.`, { cause: error });
|
|
53
|
+
}
|
|
54
|
+
const vendor = join(dirname(packageJson), "vendor");
|
|
55
|
+
const architecture = process.arch === "arm64" ? "aarch64" : "x86_64";
|
|
56
|
+
const legacyTarget = `${architecture}-${platform === "darwin" ? "apple-darwin" : platform === "win32" ? "pc-windows-msvc" : "unknown-linux-musl"}`;
|
|
57
|
+
const target = readdirSync(vendor, { withFileTypes: true }).find((entry) => entry.isDirectory() && (!legacyVendor || entry.name === legacyTarget));
|
|
58
|
+
const targetRoot = join(vendor, target?.name ?? "");
|
|
59
|
+
const binaryName = process.platform === "win32" ? "codex.exe" : "codex";
|
|
60
|
+
let command = join(targetRoot, "bin", binaryName);
|
|
61
|
+
if (codexPackageJson !== undefined && !existsSync(command))
|
|
62
|
+
command = join(targetRoot, "codex", binaryName);
|
|
63
|
+
if (target === undefined || !existsSync(command)) {
|
|
64
|
+
throw new PluginBootstrapError(`The ${packageName} package does not contain the Codex executable. Reinstall @openai/codex with optional dependencies enabled, or set CODEX_CLI_PATH to an installed Codex executable.`);
|
|
65
|
+
}
|
|
66
|
+
return command;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=codex-sdk-environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-sdk-environment.js","sourceRoot":"","sources":["../src/codex-sdk-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,UAAU,0BAA0B,CACxC,OAAe,EACf,WAAmC;IAEnC,mEAAmE;IACnE,IAAI,cAAsB,CAAC;IAC3B,IAAI,CAAC;QACH,cAAc,GAAG,IAAI,CACnB,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAC9C,YAAY,CACb,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC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AAE,CACR,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC,CACxE,CAAC;IACF,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;IACpD,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC;IACxE,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;IAClD,IAAI,gBAAgB,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QACxD,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;IAClD,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,oBAAoB,CAC5B,OAAO,WAAW,qKAAqK,CACxL,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { existsSync, readdirSync, realpathSync, statSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { delimiter, dirname, join } from \"node:path\";\nimport { PluginBootstrapError } from \"./errors.js\";\n\nexport function bundledCodexSdkEnvironment(\n command: string,\n environment: Record<string, string>,\n): Record<string, string> {\n // An SDK executable override disables its bundled-tool PATH setup.\n let toolsDirectory: string;\n try {\n toolsDirectory = join(\n dirname(realpathSync.native(dirname(command))),\n \"codex-path\",\n );\n if (!statSync(toolsDirectory).isDirectory()) return environment;\n } catch {\n return environment;\n }\n const result = { ...environment };\n const pathKeys = Object.keys(result).filter((key) =>\n process.platform === \"win32\"\n ? key.toLowerCase() === \"path\"\n : key === \"PATH\",\n );\n const pathKey = pathKeys.includes(\"Path\")\n ? \"Path\"\n : (pathKeys.at(-1) ?? \"PATH\");\n for (const key of pathKeys) {\n if (key !== pathKey) delete result[key];\n }\n const entries = (result[pathKey] ?? \"\")\n .split(delimiter)\n .filter((entry) => entry.length > 0 && entry !== toolsDirectory);\n result[pathKey] = [toolsDirectory, ...entries].join(delimiter);\n return result;\n}\n\nexport function resolveBundledCodexExecutable(\n codexPackageJson?: string,\n): string {\n const platform = process.platform === \"android\" ? \"linux\" : process.platform;\n const packageName = `@openai/codex-${platform}-${process.arch}`;\n let packageJson: string;\n let legacyVendor = false;\n try {\n const selectedPackageJson =\n codexPackageJson ??\n createRequire(import.meta.url).resolve(\"@openai/codex/package.json\");\n try {\n packageJson = createRequire(selectedPackageJson).resolve(\n `${packageName}/package.json`,\n );\n } catch (error) {\n if (codexPackageJson === undefined) throw error;\n packageJson = selectedPackageJson;\n legacyVendor = true;\n }\n } catch (error) {\n throw new PluginBootstrapError(\n `The bundled Codex executable could not be resolved from ${packageName}. Reinstall @openai/codex with optional dependencies enabled, or set CODEX_CLI_PATH to an installed Codex executable.`,\n { cause: error },\n );\n }\n const vendor = join(dirname(packageJson), \"vendor\");\n const architecture = process.arch === \"arm64\" ? \"aarch64\" : \"x86_64\";\n const legacyTarget = `${architecture}-${platform === \"darwin\" ? \"apple-darwin\" : platform === \"win32\" ? \"pc-windows-msvc\" : \"unknown-linux-musl\"}`;\n const target = readdirSync(vendor, { withFileTypes: true }).find(\n (entry) =>\n entry.isDirectory() && (!legacyVendor || entry.name === legacyTarget),\n );\n const targetRoot = join(vendor, target?.name ?? \"\");\n const binaryName = process.platform === \"win32\" ? \"codex.exe\" : \"codex\";\n let command = join(targetRoot, \"bin\", binaryName);\n if (codexPackageJson !== undefined && !existsSync(command))\n command = join(targetRoot, \"codex\", binaryName);\n if (target === undefined || !existsSync(command)) {\n throw new PluginBootstrapError(\n `The ${packageName} package does not contain the Codex executable. Reinstall @openai/codex with optional dependencies enabled, or set CODEX_CLI_PATH to an installed Codex executable.`,\n );\n }\n return command;\n}\n"]}
|
package/dist/component-plan.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReadOnlyCodexOptions } from "./scan-comparison.js";
|
|
2
2
|
export interface ComponentPlan {
|
|
3
3
|
components: Array<{
|
|
4
4
|
name: string;
|
|
5
5
|
paths: string[];
|
|
6
6
|
}>;
|
|
7
7
|
}
|
|
8
|
-
export interface ComponentPlanningOptions {
|
|
9
|
-
config?: CodexSecurityConfig;
|
|
10
|
-
environment?: NodeJS.ProcessEnv;
|
|
11
|
-
signal?: AbortSignal;
|
|
8
|
+
export interface ComponentPlanningOptions extends Pick<ReadOnlyCodexOptions, "config" | "environment" | "signal"> {
|
|
12
9
|
}
|
|
13
10
|
export declare function normalizeComponentPlan(repository: string, value: unknown, signal?: AbortSignal): Promise<ComponentPlan>;
|
|
14
11
|
export declare function planComponents(repository: string, options?: ComponentPlanningOptions): Promise<ComponentPlan>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-plan.d.ts","sourceRoot":"","sources":["../src/component-plan.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"component-plan.d.ts","sourceRoot":"","sources":["../src/component-plan.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAC;AAuB9B,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CACpD,oBAAoB,EACpB,QAAQ,GAAG,aAAa,GAAG,QAAQ,CACpC;CASA;AAED,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC,CAOxB;AAED,wBAAsB,cAAc,CAClC,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,aAAa,CAAC,CA+DxB"}
|
package/dist/component-plan.js
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
import { execFile as execFileCallback } from "node:child_process";
|
|
2
1
|
import { lstat, readdir } from "node:fs/promises";
|
|
3
2
|
import { tmpdir } from "node:os";
|
|
4
3
|
import { join, posix } from "node:path";
|
|
5
|
-
import { promisify } from "node:util";
|
|
6
4
|
import { z } from "incur";
|
|
7
5
|
import { runReadOnlyCodex, } from "./scan-comparison.js";
|
|
8
6
|
import { CODEX_SECURITY_THREAD_SOURCES } from "./thread-source.js";
|
|
9
|
-
import { enclosingGitWorktreeRoot, normalizeRepository, normalizeTarget, validatedGitEnvironment, } from "./targets.js";
|
|
10
|
-
import { resolveTrustedExecutable } from "./trusted-executable.js";
|
|
11
|
-
const execFile = promisify(execFileCallback);
|
|
7
|
+
import { nullIfMissingFile, enclosingGitWorktreeRoot, gitOutput, normalizeRepository, normalizeTarget, validatedGitEnvironment, } from "./targets.js";
|
|
12
8
|
/** @internal */
|
|
13
|
-
export const componentPlanSchema = z
|
|
14
|
-
.object({
|
|
9
|
+
export const componentPlanSchema = z.strictObject({
|
|
15
10
|
components: z
|
|
16
|
-
.array(z
|
|
17
|
-
.object({
|
|
11
|
+
.array(z.strictObject({
|
|
18
12
|
name: z.string().trim().min(1),
|
|
19
13
|
paths: z.array(z.string().min(1)).min(1),
|
|
20
|
-
})
|
|
21
|
-
.strict())
|
|
14
|
+
}))
|
|
22
15
|
.min(1),
|
|
23
|
-
})
|
|
24
|
-
.strict();
|
|
16
|
+
});
|
|
25
17
|
export async function normalizeComponentPlan(repository, value, signal) {
|
|
26
18
|
const plan = componentPlanSchema.parse(value);
|
|
27
19
|
for (const component of plan.components) {
|
|
@@ -40,7 +32,8 @@ export async function planComponents(repository, options = {}) {
|
|
|
40
32
|
for (const batch of componentPlanningBatches(files, options.signal)) {
|
|
41
33
|
options.signal?.throwIfAborted();
|
|
42
34
|
const response = await runReadOnlyCodex(batch.prompt, z.toJSONSchema(componentPlanSchema, { target: "openapi-3.0" }), { ...options, config: options.config ?? {}, workingDirectory: tmpdir() }, {
|
|
43
|
-
surface: "
|
|
35
|
+
surface: options.surface ?? "sdk",
|
|
36
|
+
command: "scan-components",
|
|
44
37
|
threadSource: CODEX_SECURITY_THREAD_SOURCES.scan,
|
|
45
38
|
});
|
|
46
39
|
const proposed = await normalizeComponentPlan(repository, JSON.parse(response), options.signal);
|
|
@@ -181,14 +174,12 @@ function directoryCounts(files) {
|
|
|
181
174
|
}
|
|
182
175
|
async function inventoryFiles(repository, signal) {
|
|
183
176
|
signal?.throwIfAborted();
|
|
184
|
-
|
|
177
|
+
const utf8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
178
|
+
if (await enclosingGitWorktreeRoot(repository, signal, {
|
|
179
|
+
requireIfPresent: true,
|
|
180
|
+
})) {
|
|
185
181
|
validatedGitEnvironment();
|
|
186
|
-
const
|
|
187
|
-
if (git === null)
|
|
188
|
-
throw new Error("Git is required to inventory this repository.");
|
|
189
|
-
const { stdout } = await execFile(git.executable, [
|
|
190
|
-
"-C",
|
|
191
|
-
repository,
|
|
182
|
+
const stdout = await gitOutput(repository, [
|
|
192
183
|
"ls-files",
|
|
193
184
|
"--cached",
|
|
194
185
|
"--others",
|
|
@@ -197,17 +188,14 @@ async function inventoryFiles(repository, signal) {
|
|
|
197
188
|
"-z",
|
|
198
189
|
"--",
|
|
199
190
|
".",
|
|
200
|
-
],
|
|
191
|
+
], signal, undefined, undefined, "buffer");
|
|
201
192
|
const files = [];
|
|
202
|
-
for (const path of stdout.split("\0").filter(Boolean)) {
|
|
193
|
+
for (const path of stdout.toString("latin1").split("\0").filter(Boolean)) {
|
|
203
194
|
signal?.throwIfAborted();
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
return null;
|
|
207
|
-
throw error;
|
|
208
|
-
});
|
|
195
|
+
const bytes = Buffer.from(path, "latin1");
|
|
196
|
+
const metadata = await lstat(Buffer.from(join(Buffer.from(repository).toString("latin1"), path), "latin1")).catch(nullIfMissingFile);
|
|
209
197
|
if (metadata?.isFile())
|
|
210
|
-
files.push(join(repository,
|
|
198
|
+
files.push(join(repository, utf8.decode(bytes)));
|
|
211
199
|
}
|
|
212
200
|
return files.length === 0
|
|
213
201
|
? []
|
|
@@ -218,12 +206,28 @@ async function inventoryFiles(repository, signal) {
|
|
|
218
206
|
while (pending.length > 0) {
|
|
219
207
|
signal?.throwIfAborted();
|
|
220
208
|
const directory = pending.pop();
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
209
|
+
const directoryPath = join(repository, directory);
|
|
210
|
+
// Bun's buffer encoding omits Dirent metadata even with withFileTypes.
|
|
211
|
+
const entries = process.versions["bun"]
|
|
212
|
+
? await readdir(directoryPath, {
|
|
213
|
+
withFileTypes: true,
|
|
214
|
+
encoding: process.platform === "win32" ? "utf8" : "latin1",
|
|
215
|
+
})
|
|
216
|
+
: await readdir(directoryPath, {
|
|
217
|
+
withFileTypes: true,
|
|
218
|
+
encoding: "buffer",
|
|
219
|
+
});
|
|
220
|
+
for (const entry of entries) {
|
|
221
|
+
if (!entry.isDirectory() && !entry.isFile())
|
|
222
|
+
continue;
|
|
223
|
+
const name = typeof entry.name === "string"
|
|
224
|
+
? process.platform === "win32"
|
|
225
|
+
? entry.name
|
|
226
|
+
: utf8.decode(Buffer.from(entry.name, "latin1"))
|
|
227
|
+
: utf8.decode(entry.name);
|
|
228
|
+
if (name === ".git")
|
|
225
229
|
continue;
|
|
226
|
-
const path = directory ? `${directory}/${
|
|
230
|
+
const path = directory ? `${directory}/${name}` : name;
|
|
227
231
|
if (entry.isDirectory())
|
|
228
232
|
pending.push(path);
|
|
229
233
|
else if (entry.isFile())
|