bugx-cli 0.0.0-stage → 0.1.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/LICENSE +55 -0
- package/README.md +280 -2
- package/core/CATALOG.json +141 -0
- package/core/README.md +254 -0
- package/core/adapters/README.md +35 -0
- package/core/adapters/android-interaction.json +81 -0
- package/core/adapters/android.json +24 -0
- package/core/adapters/desktop-macos.json +20 -0
- package/core/adapters/ios-interaction.json +34 -0
- package/core/adapters/ios.json +23 -0
- package/core/adapters/memory-macos.json +24 -0
- package/core/agent/README.md +50 -0
- package/core/agent/__init__.py +146 -0
- package/core/agent/agent_artifacts.py +764 -0
- package/core/agent/agent_eval.py +1073 -0
- package/core/agent/agent_execution.py +552 -0
- package/core/agent/agent_orchestrator.py +1345 -0
- package/core/agent/agent_targets.py +871 -0
- package/core/agent/agent_workspace.py +770 -0
- package/core/assets/README.md +24 -0
- package/core/assets/bugx-avatar-1024.png +0 -0
- package/core/assets/bugx-avatar-512.png +0 -0
- package/core/assets/bugx-avatar-tight.svg +23 -0
- package/core/assets/bugx-avatar.svg +28 -0
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
- package/core/assets/project-layout.md +42 -0
- package/core/audit_packs/README.md +37 -0
- package/core/audit_packs/data-audit/manifest.json +94 -0
- package/core/audit_packs/data-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/data-audit/stages/10-schema-inventory.md +14 -0
- package/core/audit_packs/data-audit/stages/20-query-and-integrity.md +14 -0
- package/core/audit_packs/data-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/desktop-audit/manifest.json +123 -0
- package/core/audit_packs/desktop-audit/stages/00-scope.md +15 -0
- package/core/audit_packs/desktop-audit/stages/10-process-model.md +14 -0
- package/core/audit_packs/desktop-audit/stages/20-package-integrity.md +15 -0
- package/core/audit_packs/desktop-audit/stages/30-ui-behavior.md +14 -0
- package/core/audit_packs/desktop-audit/stages/80-evidence-regression.md +15 -0
- package/core/audit_packs/memory-testing.md +227 -0
- package/core/audit_packs/mobile-audit/manifest.json +155 -0
- package/core/audit_packs/mobile-audit/modules/android.md +19 -0
- package/core/audit_packs/mobile-audit/modules/h5.md +18 -0
- package/core/audit_packs/mobile-audit/modules/ios.md +25 -0
- package/core/audit_packs/mobile-audit/modules/miniprogram.md +26 -0
- package/core/audit_packs/mobile-audit/modules/webview.md +18 -0
- package/core/audit_packs/mobile-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/mobile-audit/stages/10-platform-inventory.md +14 -0
- package/core/audit_packs/mobile-audit/stages/20-masvs-static.md +20 -0
- package/core/audit_packs/mobile-audit/stages/30-component-exposure.md +14 -0
- package/core/audit_packs/mobile-audit/stages/40-device-behavior.md +14 -0
- package/core/audit_packs/mobile-audit/stages/80-evidence-regression.md +13 -0
- package/core/audit_packs/native-audit/manifest.json +127 -0
- package/core/audit_packs/native-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/native-audit/stages/10-static-white-box.md +14 -0
- package/core/audit_packs/native-audit/stages/20-memory-concurrency.md +15 -0
- package/core/audit_packs/native-audit/stages/30-behavior-black-box.md +39 -0
- package/core/audit_packs/native-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/platform-testing.md +174 -0
- package/core/audit_packs/web-audit/manifest.json +191 -0
- package/core/audit_packs/web-audit/modules/graphql.md +5 -0
- package/core/audit_packs/web-audit/modules/h5.md +18 -0
- package/core/audit_packs/web-audit/modules/multi-tenant.md +4 -0
- package/core/audit_packs/web-audit/modules/oauth.md +4 -0
- package/core/audit_packs/web-audit/modules/upload.md +4 -0
- package/core/audit_packs/web-audit/modules/websocket.md +4 -0
- package/core/audit_packs/web-audit/stages/00-scope.md +13 -0
- package/core/audit_packs/web-audit/stages/10-discovery.md +13 -0
- package/core/audit_packs/web-audit/stages/20-auth-session.md +13 -0
- package/core/audit_packs/web-audit/stages/30-authz-business.md +13 -0
- package/core/audit_packs/web-audit/stages/40-input-output.md +13 -0
- package/core/audit_packs/web-audit/stages/50-state-async.md +13 -0
- package/core/audit_packs/web-audit/stages/60-file-ssrf-deser.md +12 -0
- package/core/audit_packs/web-audit/stages/70-config-dependency.md +12 -0
- package/core/audit_packs/web-audit/stages/80-evidence-regression.md +12 -0
- package/core/autonomous_cve/INTERFACE.md +61 -0
- package/core/autonomous_cve/README.md +58 -0
- package/core/autonomous_cve/SPEC.md +25 -0
- package/core/autonomous_cve/__init__.py +109 -0
- package/core/autonomous_cve/attack_graph.py +1096 -0
- package/core/autonomous_cve/attack_graph_store.py +1822 -0
- package/core/autonomous_cve/audit_campaign.py +1232 -0
- package/core/autonomous_cve/behavior_graph.py +459 -0
- package/core/autonomous_cve/ghsa_advisories.py +174 -0
- package/core/autonomous_cve/models.py +93 -0
- package/core/autonomous_cve/mutator.py +87 -0
- package/core/autonomous_cve/patcher.py +126 -0
- package/core/autonomous_cve/scout.py +278 -0
- package/core/autonomous_cve/synthesizer.py +207 -0
- package/core/autonomous_cve/verifier.py +100 -0
- package/core/bugx.md +1299 -0
- package/core/bugx_paths.py +1846 -0
- package/core/cloud_sync/INTERFACE.md +32 -0
- package/core/cloud_sync/README.md +62 -0
- package/core/cloud_sync/SPEC.md +25 -0
- package/core/cloud_sync/__init__.py +23 -0
- package/core/cloud_sync/auto_sync.py +398 -0
- package/core/cloud_sync/cloud_client.py +1199 -0
- package/core/cloud_sync/cloud_onboard.py +702 -0
- package/core/cloud_sync/cloud_schema.py +648 -0
- package/core/cloud_sync/consent.py +81 -0
- package/core/cloud_sync/device_identity.py +307 -0
- package/core/cloud_sync/endpoint_router.py +415 -0
- package/core/cloud_sync/flywheel_client.py +760 -0
- package/core/cloud_sync/network_transport.py +275 -0
- package/core/cloud_sync/onboard_wizard.py +493 -0
- package/core/cloud_sync/sensitive_filter.py +285 -0
- package/core/cloud_sync/sync_pull.py +695 -0
- package/core/cloud_sync/sync_push.py +721 -0
- package/core/contracts/AGENT_GUIDE.md +362 -0
- package/core/contracts/README.md +34 -0
- package/core/contracts/bugx-blackbox.md +541 -0
- package/core/contracts/bugx-opencode.md +469 -0
- package/core/contracts/bugx-quick.md +44 -0
- package/core/contracts/bugx-runtime-contract.md +353 -0
- package/core/contracts/bugx-worker.md +470 -0
- package/core/contracts/engine_gap_contracts.py +390 -0
- package/core/coverage/README.md +70 -0
- package/core/coverage/__init__.py +106 -0
- package/core/coverage/coverage_ai_review.py +185 -0
- package/core/coverage/coverage_backfill.py +54 -0
- package/core/coverage/coverage_bootstrap.py +713 -0
- package/core/coverage/coverage_business.py +36 -0
- package/core/coverage/coverage_cli.py +715 -0
- package/core/coverage/coverage_discovery.py +859 -0
- package/core/coverage/coverage_evidence.py +977 -0
- package/core/coverage/coverage_forensics.py +115 -0
- package/core/coverage/coverage_gate.py +277 -0
- package/core/coverage/coverage_intelligence.py +734 -0
- package/core/coverage/coverage_manifest.py +396 -0
- package/core/coverage/coverage_platform.py +77 -0
- package/core/coverage/coverage_validate.py +236 -0
- package/core/coverage/module_coverage.py +157 -0
- package/core/dev_harness/INTERFACE.md +20 -0
- package/core/dev_harness/README.md +21 -0
- package/core/dev_harness/SPEC.md +25 -0
- package/core/dev_harness/__init__.py +5 -0
- package/core/dev_harness/interaction_preset.py +408 -0
- package/core/engine-integrity.json +2625 -0
- package/core/fuzzing/README.md +49 -0
- package/core/fuzzing/__init__.py +82 -0
- package/core/fuzzing/concurrency_fuzzer.py +382 -0
- package/core/fuzzing/differential_oracle.py +629 -0
- package/core/fuzzing/fuzz_input.py +1188 -0
- package/core/fuzzing/stateful_fuzzer.py +332 -0
- package/core/governance/README.md +61 -0
- package/core/governance/__init__.py +130 -0
- package/core/governance/capacity_planner.py +124 -0
- package/core/governance/dependency_lock.py +317 -0
- package/core/governance/goal_governor.py +754 -0
- package/core/governance/guide_budget.py +458 -0
- package/core/governance/lockdown.sh +50 -0
- package/core/governance/readonly_enforcer.py +154 -0
- package/core/governance/runtime_tool_gate.py +373 -0
- package/core/governance/secret_redactor.py +772 -0
- package/core/governance/token_budget.py +38 -0
- package/core/host_acp/INTERFACE.md +36 -0
- package/core/host_acp/README.md +51 -0
- package/core/host_acp/SPEC.md +25 -0
- package/core/host_acp/__init__.py +121 -0
- package/core/host_acp/base.py +111 -0
- package/core/host_acp/claude.py +41 -0
- package/core/host_acp/cline.py +235 -0
- package/core/host_acp/codex.py +245 -0
- package/core/host_acp/dsh.py +48 -0
- package/core/host_acp/opencode.py +154 -0
- package/core/host_acp/pi.py +36 -0
- package/core/host_acp/zcode.py +41 -0
- package/core/host_runtime/INTERFACE.md +24 -0
- package/core/host_runtime/README.md +62 -0
- package/core/host_runtime/SPEC.md +25 -0
- package/core/host_runtime/__init__.py +21 -0
- package/core/host_runtime/adapters.py +412 -0
- package/core/host_runtime/autonomous_runner.py +1152 -0
- package/core/host_runtime/cline.py +435 -0
- package/core/host_runtime/common.py +103 -0
- package/core/host_runtime/free_models.py +786 -0
- package/core/host_runtime/host_bootstrap.py +389 -0
- package/core/host_runtime/host_evaluators.py +721 -0
- package/core/host_runtime/host_probe.py +41 -0
- package/core/host_runtime/host_provider_arbitrator.py +777 -0
- package/core/host_runtime/host_registry.py +655 -0
- package/core/host_runtime/host_usage.py +127 -0
- package/core/host_runtime/mcp_process_tracker.py +509 -0
- package/core/host_runtime/mcp_registry_gate.py +368 -0
- package/core/hosts/INTERFACE.md +51 -0
- package/core/hosts/README.md +67 -0
- package/core/hosts/SPEC.md +25 -0
- package/core/hosts/__init__.py +136 -0
- package/core/hosts/_base_usage.py +152 -0
- package/core/hosts/_codex_usage.py +297 -0
- package/core/hosts/_dsh_usage.py +184 -0
- package/core/hosts/_mcp_toml.py +365 -0
- package/core/hosts/_zcode_usage.py +269 -0
- package/core/hosts/base.py +451 -0
- package/core/hosts/claude.py +157 -0
- package/core/hosts/cline.py +225 -0
- package/core/hosts/codex.py +948 -0
- package/core/hosts/dsh.py +518 -0
- package/core/hosts/opencode.py +358 -0
- package/core/hosts/pi.py +151 -0
- package/core/hosts/zcode.py +219 -0
- package/core/i18n.py +252 -0
- package/core/infra/README.md +39 -0
- package/core/infra/__init__.py +15 -0
- package/core/infra/build_info.py +86 -0
- package/core/infra/client_metadata.py +185 -0
- package/core/infra/python_runtime.py +540 -0
- package/core/infra/safe_xml.py +221 -0
- package/core/launch_bugx.py +118 -0
- package/core/launch_phases/INTERFACE.md +31 -0
- package/core/launch_phases/README.md +106 -0
- package/core/launch_phases/SPEC.md +25 -0
- package/core/launch_phases/__init__.py +29 -0
- package/core/launch_phases/candidate_revalidation.py +484 -0
- package/core/launch_phases/common.py +1041 -0
- package/core/launch_phases/finding_confirm_phase.py +387 -0
- package/core/launch_phases/finding_settlement.py +1245 -0
- package/core/launch_phases/findings_adjudication.py +666 -0
- package/core/launch_phases/findings_snapshot.py +357 -0
- package/core/launch_phases/judge_phase.py +791 -0
- package/core/launch_phases/lesson_context.py +536 -0
- package/core/launch_phases/lifecycle_reporter.py +627 -0
- package/core/launch_phases/orchestrator_controls.py +682 -0
- package/core/launch_phases/post_commit.py +567 -0
- package/core/launch_phases/post_coverage_sync.py +591 -0
- package/core/launch_phases/post_dry_run.py +817 -0
- package/core/launch_phases/post_observability.py +367 -0
- package/core/launch_phases/post_phase.py +1087 -0
- package/core/launch_phases/post_receipt.py +362 -0
- package/core/launch_phases/post_round_lifecycle.py +786 -0
- package/core/launch_phases/pre_phase.py +1029 -0
- package/core/launch_phases/pre_recon_scout.py +862 -0
- package/core/launch_phases/pre_state_builder.py +1286 -0
- package/core/launch_phases/report_sharing.py +414 -0
- package/core/launch_phases/round_orchestrator.py +1133 -0
- package/core/launch_phases/session_runtime.py +1623 -0
- package/core/launch_phases/startup_gates.py +1022 -0
- package/core/launch_phases/startup_interaction.py +947 -0
- package/core/launch_phases/startup_version_gate.py +873 -0
- package/core/launch_phases/supervisor_bridge.py +1224 -0
- package/core/launch_phases/supervisor_coverage.py +417 -0
- package/core/launch_phases/supervisor_degraded.py +1219 -0
- package/core/launch_phases/worker_barriers.py +414 -0
- package/core/launch_phases/worker_orchestrator.py +1166 -0
- package/core/launch_phases/worker_prior.py +749 -0
- package/core/ledger/INTERFACE.md +35 -0
- package/core/ledger/README.md +160 -0
- package/core/ledger/SPEC.md +25 -0
- package/core/ledger/__init__.py +67 -0
- package/core/ledger/_facade.py +226 -0
- package/core/ledger/archive_ops.py +572 -0
- package/core/ledger/auto_materialization.py +459 -0
- package/core/ledger/bug-log.md +22 -0
- package/core/ledger/cli.py +270 -0
- package/core/ledger/export_ops.py +549 -0
- package/core/ledger/finding_confirmation.py +1274 -0
- package/core/ledger/finding_io.py +299 -0
- package/core/ledger/finding_lifecycle.py +307 -0
- package/core/ledger/finding_verification.py +369 -0
- package/core/ledger/incidents.py +999 -0
- package/core/ledger/lesson-replay-cases.json +20 -0
- package/core/ledger/lesson_ledger.py +241 -0
- package/core/ledger/lesson_replay.py +272 -0
- package/core/ledger/life_ledger.py +668 -0
- package/core/ledger/mistake-book.md +130 -0
- package/core/ledger/patterns.py +681 -0
- package/core/ledger/receipt_contract.py +253 -0
- package/core/ledger/schema.py +1192 -0
- package/core/ledger/sync_ops.py +935 -0
- package/core/ledger/tool_experience.py +682 -0
- package/core/ledger/verify_life.py +1526 -0
- package/core/lesson-ledger.json +275 -0
- package/core/locales/README.md +19 -0
- package/core/locales/en-US.json +462 -0
- package/core/locales/zh-CN.json +462 -0
- package/core/mcp_handlers/INTERFACE.md +75 -0
- package/core/mcp_handlers/README.md +62 -0
- package/core/mcp_handlers/SPEC.md +25 -0
- package/core/mcp_handlers/__init__.py +128 -0
- package/core/mcp_handlers/base.py +697 -0
- package/core/mcp_handlers/channel_lifecycle.py +696 -0
- package/core/mcp_handlers/graph_handlers.py +222 -0
- package/core/mcp_handlers/knowledge_handlers.py +536 -0
- package/core/mcp_handlers/mining_handlers.py +586 -0
- package/core/mcp_handlers/resource_prompt_table.py +116 -0
- package/core/mcp_handlers/retrieval_handlers.py +239 -0
- package/core/mcp_handlers/rpc_server.py +465 -0
- package/core/mcp_handlers/supervisor_handlers.py +1435 -0
- package/core/mcp_handlers/telemetry_handlers.py +227 -0
- package/core/mcp_handlers/tool_table.py +1015 -0
- package/core/mcp_runtime_support/README.md +21 -0
- package/core/mcp_runtime_support/__init__.py +1 -0
- package/core/mcp_runtime_support/common.py +363 -0
- package/core/mcp_runtime_support/environment.py +605 -0
- package/core/mcp_runtime_support/verifier.py +810 -0
- package/core/metadata.txt +5 -0
- package/core/planning/README.md +157 -0
- package/core/planning/__init__.py +242 -0
- package/core/planning/capability_plan.py +187 -0
- package/core/planning/capability_planner.py +195 -0
- package/core/planning/domain_archetype.py +542 -0
- package/core/planning/domain_router.py +267 -0
- package/core/planning/dynamic_flow_analyzer.py +328 -0
- package/core/planning/impact_pruner.py +435 -0
- package/core/planning/intent_adjudicator.py +175 -0
- package/core/planning/judge_pipeline.py +1163 -0
- package/core/planning/logic_analysis.py +419 -0
- package/core/planning/prompt_harness.py +1702 -0
- package/core/planning/source_inspector.py +267 -0
- package/core/planning/spec_harvester.py +449 -0
- package/core/planning/target_sandbox_manager.py +573 -0
- package/core/planning/test_capability_verifier.py +1364 -0
- package/core/planning/tools-kb.md +38 -0
- package/core/planning/unit_kind.py +122 -0
- package/core/probes/INTERFACE.md +73 -0
- package/core/probes/README.md +51 -0
- package/core/probes/SPEC.md +26 -0
- package/core/probes/__init__.py +70 -0
- package/core/probes/android_probe.py +384 -0
- package/core/probes/base.py +147 -0
- package/core/probes/codebase_memory_probe.py +590 -0
- package/core/probes/desktop_probe.py +238 -0
- package/core/probes/differential_probe.py +356 -0
- package/core/probes/efficiency_probe.py +168 -0
- package/core/probes/ios_binary_probe.py +368 -0
- package/core/probes/memory_probe.py +326 -0
- package/core/probes/miniprogram_probe.py +323 -0
- package/core/probes/mobile_probe.py +281 -0
- package/core/probes/native_probe.py +214 -0
- package/core/probes/openwiki_probe.py +193 -0
- package/core/probes/pattern_probe.py +347 -0
- package/core/probes/platform_probe.py +343 -0
- package/core/probes/probe_registry.py +1669 -0
- package/core/probes/sast_probe.py +1009 -0
- package/core/probes/sast_rules.py +841 -0
- package/core/probes/sca_scanner.py +731 -0
- package/core/probes/web_probe.py +359 -0
- package/core/project_profiler/INTERFACE.md +62 -0
- package/core/project_profiler/README.md +53 -0
- package/core/project_profiler/SPEC.md +28 -0
- package/core/project_profiler/__init__.py +201 -0
- package/core/project_profiler/arbitrator.py +311 -0
- package/core/project_profiler/constants.py +247 -0
- package/core/project_profiler/detector.py +392 -0
- package/core/project_profiler/extractors.py +836 -0
- package/core/project_profiler/fingerprint.py +116 -0
- package/core/project_profiler/storage.py +258 -0
- package/core/project_profiler/strategy.py +265 -0
- package/core/prompts/README.md +35 -0
- package/core/prompts/codex_dialog_dispatch.md +9 -0
- package/core/prompts/command_routing_en.md +42 -0
- package/core/prompts/command_routing_zh.md +42 -0
- package/core/prompts/l0_router.md +47 -0
- package/core/prompts/rules/anti_patterns.md +16 -0
- package/core/prompts/rules/concurrency_rules.md +14 -0
- package/core/prompts/rules/memory_leak_rules.md +13 -0
- package/core/prompts/rules/prompt_injection_defense.md +13 -0
- package/core/prompts/stages/stage_explore.md +31 -0
- package/core/prompts/stages/stage_gate.md +43 -0
- package/core/prompts/stages/stage_mutate.md +42 -0
- package/core/prompts/stages/stage_repair.md +85 -0
- package/core/repair/README.md +74 -0
- package/core/repair/__init__.py +169 -0
- package/core/repair/fix_watchlist.py +391 -0
- package/core/repair/l7_dynamic.py +418 -0
- package/core/repair/l7_repair_loop.py +465 -0
- package/core/repair/l7_selfcheck.py +862 -0
- package/core/repair/minimize_repro.py +466 -0
- package/core/repair/patch_synthesizer.py +617 -0
- package/core/repair/regression_pack.py +379 -0
- package/core/repair/rsi_fixer.py +910 -0
- package/core/repair/rsi_loop.py +313 -0
- package/core/repair/rsi_repair.py +348 -0
- package/core/repair/rsi_rounds.py +212 -0
- package/core/repair/rsi_scope.py +262 -0
- package/core/repair/self_heal.py +604 -0
- package/core/repair/test_generator.py +1108 -0
- package/core/repair/test_quality_auditor.py +410 -0
- package/core/repair/test_strategy.py +511 -0
- package/core/report_engine/INTERFACE.md +59 -0
- package/core/report_engine/README.md +69 -0
- package/core/report_engine/SPEC.md +28 -0
- package/core/report_engine/__init__.py +47 -0
- package/core/report_engine/attestation.py +224 -0
- package/core/report_engine/authority.py +255 -0
- package/core/report_engine/finding_report.py +417 -0
- package/core/report_engine/formal_report_builder.py +924 -0
- package/core/report_engine/html_renderers.py +696 -0
- package/core/report_engine/models.py +761 -0
- package/core/report_engine/pdf_exporter.py +231 -0
- package/core/report_engine/projects_assets.py +730 -0
- package/core/report_engine/report_client.py +743 -0
- package/core/report_engine/report_data_builder.py +388 -0
- package/core/report_engine/report_share.py +459 -0
- package/core/report_engine/sast_bridge.py +116 -0
- package/core/report_engine/server.py +822 -0
- package/core/report_engine/visual_report_builder.py +796 -0
- package/core/report_engine/web-conformance.md +63 -0
- package/core/report_engine/web_conformance.py +459 -0
- package/core/report_engine/workbench_assets.py +484 -0
- package/core/retrieval/INTERFACE.md +20 -0
- package/core/retrieval/README.md +161 -0
- package/core/retrieval/SPEC.md +25 -0
- package/core/retrieval/__init__.py +3 -0
- package/core/retrieval/code_analyzer.py +1684 -0
- package/core/retrieval/codebase_memory_bridge.py +337 -0
- package/core/retrieval/context_assembler.py +234 -0
- package/core/retrieval/corpus_fetch.py +369 -0
- package/core/retrieval/graph_ego.py +597 -0
- package/core/retrieval/knowledge_auto.py +662 -0
- package/core/retrieval/knowledge_sources.py +168 -0
- package/core/retrieval/knowledge_sync.py +909 -0
- package/core/retrieval/memory_store.py +480 -0
- package/core/retrieval/query_planner.py +1020 -0
- package/core/retrieval/rrf_engine.py +137 -0
- package/core/retrieval/slice_extractor.py +1209 -0
- package/core/retrieval/slice_normalizer.py +373 -0
- package/core/retrieval/slice_spec.py +357 -0
- package/core/retrieval/symbol_index.py +1132 -0
- package/core/retrieval/universal_code_matcher.py +437 -0
- package/core/retrieval/xerj_bridge.py +476 -0
- package/core/retrieval/xerj_supervisor.py +362 -0
- package/core/rules/README.md +33 -0
- package/core/rules/ios/PROVENANCE.json +30 -0
- package/core/rules/ios/crypto.yaml +36 -0
- package/core/rules/ios/network.yaml +20 -0
- package/core/rules/ios/resilience.yaml +47 -0
- package/core/rules/ios/storage.yaml +48 -0
- package/core/rules/mastg/LICENSE +173 -0
- package/core/rules/mastg/PROVENANCE.json +270 -0
- package/core/rules/mastg/mastg-android-asymmetric-key-pair-used-for-multiple-purposes.yml +13 -0
- package/core/rules/mastg/mastg-android-backup-manifest.yml +24 -0
- package/core/rules/mastg/mastg-android-biometric-event-bound.yml +49 -0
- package/core/rules/mastg/mastg-android-biometric-invalidated-enrollment.yml +11 -0
- package/core/rules/mastg/mastg-android-biometric-no-confirmation-required.yml +10 -0
- package/core/rules/mastg/mastg-android-biometric-validity-duration.yml +24 -0
- package/core/rules/mastg/mastg-android-broken-encryption-algorithms.yaml +9 -0
- package/core/rules/mastg/mastg-android-broken-encryption-modes.yaml +13 -0
- package/core/rules/mastg/mastg-android-content-provider-exported.yml +35 -0
- package/core/rules/mastg/mastg-android-custom-deeplink-scheme.yml +29 -0
- package/core/rules/mastg/mastg-android-dangerous-app-permissions.yaml +65 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-apis.yml +36 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-manifest.yml +15 -0
- package/core/rules/mastg/mastg-android-debuggable-flag.yml +10 -0
- package/core/rules/mastg/mastg-android-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-deeplink-autoverify-missing.yml +33 -0
- package/core/rules/mastg/mastg-android-deeplink-unvalidated-parameter.yml +11 -0
- package/core/rules/mastg/mastg-android-device-passcode-present.yml +17 -0
- package/core/rules/mastg/mastg-android-fileprovider-broad-scope.yml +46 -0
- package/core/rules/mastg/mastg-android-hardcoded-crypto-keys-usage.yml +14 -0
- package/core/rules/mastg/mastg-android-hardcoded-security-provider.yaml +18 -0
- package/core/rules/mastg/mastg-android-implicit-intent-internal-communication.yml +30 -0
- package/core/rules/mastg/mastg-android-implicit-intent-leaking-extras.yml +29 -0
- package/core/rules/mastg/mastg-android-input-field-usage.yml +11 -0
- package/core/rules/mastg/mastg-android-key-generation-with-insufficient-key-length.yml +21 -0
- package/core/rules/mastg/mastg-android-keyboard-cache-input-types.yml +10 -0
- package/core/rules/mastg/mastg-android-local-storage-input-validation.yml +48 -0
- package/core/rules/mastg/mastg-android-native-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-network-checkservertrusted.yml +12 -0
- package/core/rules/mastg/mastg-android-network-hostname-verification.yml +11 -0
- package/core/rules/mastg/mastg-android-network-insecure-trust-anchors.yml +11 -0
- package/core/rules/mastg/mastg-android-network-onreceivedsslerror.yml +12 -0
- package/core/rules/mastg/mastg-android-non-random-use.yml +16 -0
- package/core/rules/mastg/mastg-android-object-deserialization.yml +14 -0
- package/core/rules/mastg/mastg-android-overlay-protection.yml +68 -0
- package/core/rules/mastg/mastg-android-pendingintent-mutable.yml +39 -0
- package/core/rules/mastg/mastg-android-random-apis-insufficient-entropy.yml +17 -0
- package/core/rules/mastg/mastg-android-root-detection.yaml +59 -0
- package/core/rules/mastg/mastg-android-sdk-version.yml +10 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications-manifest.yml +17 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications.yml +11 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-screenshot.yml +18 -0
- package/core/rules/mastg/mastg-android-sql-injection-contentprovider.yml +17 -0
- package/core/rules/mastg/mastg-android-ssl-socket-hostnameverifier.yml +15 -0
- package/core/rules/mastg/mastg-android-strictmode.yml +10 -0
- package/core/rules/mastg/mastg-android-system-alert-window.yml +9 -0
- package/core/rules/mastg/mastg-android-webview-allow-local-access.yml +15 -0
- package/core/rules/mastg/mastg-android-webview-bridges.yml +28 -0
- package/core/rules/mastg/mastg-android-webview-safebrowsing.yml +20 -0
- package/core/rules/mastg/mastg-android-webview-url-handlers.yml +41 -0
- package/core/rules/miniprogram/PROVENANCE.json +26 -0
- package/core/rules/miniprogram/network.yaml +37 -0
- package/core/rules/miniprogram/platform.yaml +36 -0
- package/core/rules/miniprogram/storage.yaml +48 -0
- package/core/rules/mobsfscan-swift/LICENSE +165 -0
- package/core/rules/mobsfscan-swift/PROVENANCE.json +58 -0
- package/core/rules/mobsfscan-swift/auth.yaml +59 -0
- package/core/rules/mobsfscan-swift/crypto.yaml +66 -0
- package/core/rules/mobsfscan-swift/jailbreak.yaml +14 -0
- package/core/rules/mobsfscan-swift/keyboard.yaml +34 -0
- package/core/rules/mobsfscan-swift/logging.yaml +23 -0
- package/core/rules/mobsfscan-swift/network.yaml +55 -0
- package/core/rules/mobsfscan-swift/resilience.yaml +29 -0
- package/core/rules/mobsfscan-swift/secrets.yaml +33 -0
- package/core/rules/mobsfscan-swift/storage.yaml +29 -0
- package/core/rules/mobsfscan-swift/webview.yaml +32 -0
- package/core/runtime/README.md +198 -0
- package/core/runtime/__init__.py +3 -0
- package/core/runtime/bugx_logging.py +1393 -0
- package/core/runtime/daemon_runner.py +623 -0
- package/core/runtime/fixture_solidify.py +449 -0
- package/core/runtime/global_telemetry.py +549 -0
- package/core/runtime/incident_eval.py +148 -0
- package/core/runtime/interaction.py +605 -0
- package/core/runtime/interaction_store.py +435 -0
- package/core/runtime/interactive_menu.py +95 -0
- package/core/runtime/log_analytics.py +922 -0
- package/core/runtime/mining_quality_framework.py +1387 -0
- package/core/runtime/model_runner.py +769 -0
- package/core/runtime/platform_adapter.py +579 -0
- package/core/runtime/prep_validate.py +476 -0
- package/core/runtime/project_graph.py +827 -0
- package/core/runtime/project_init.py +481 -0
- package/core/runtime/project_profile.py +224 -0
- package/core/runtime/project_settings.py +963 -0
- package/core/runtime/provider_window.py +97 -0
- package/core/runtime/resume_ticket.py +115 -0
- package/core/runtime/scenario_eval.py +814 -0
- package/core/runtime/seed_drill.py +549 -0
- package/core/runtime/self_audit.py +550 -0
- package/core/runtime/session_profile.py +205 -0
- package/core/runtime/setup_ui_env.py +229 -0
- package/core/runtime/startup_environment.py +859 -0
- package/core/runtime/sync_store.py +1421 -0
- package/core/runtime/tool_install_targets.py +18 -0
- package/core/schemas/README.md +35 -0
- package/core/schemas/agent-graph.schema.json +368 -0
- package/core/schemas/attack-graph.schema.json +88 -0
- package/core/schemas/evidence-bundle.schema.json +33 -0
- package/core/schemas/skill-pack.schema.json +230 -0
- package/core/schemas/worker-checkpoint.schema.json +119 -0
- package/core/secure_atomic.py +289 -0
- package/core/seed_corpus/README.md +55 -0
- package/core/seed_corpus/c.txt +29 -0
- package/core/seed_corpus/cpp.txt +32 -0
- package/core/seed_corpus/css.txt +70 -0
- package/core/seed_corpus/go.txt +46 -0
- package/core/seed_corpus/java.txt +30 -0
- package/core/seed_corpus/javascript.txt +55 -0
- package/core/seed_corpus/kotlin.txt +28 -0
- package/core/seed_corpus/python.txt +71 -0
- package/core/seed_corpus/rust.txt +53 -0
- package/core/seed_corpus/swift.txt +29 -0
- package/core/seed_corpus/typescript.txt +29 -0
- package/core/skills/README.md +53 -0
- package/core/skills/__init__.py +189 -0
- package/core/skills/bugx_docs_mcp_server.py +416 -0
- package/core/skills/bugx_mcp_server.py +1134 -0
- package/core/skills/mcp_runtime.py +968 -0
- package/core/skills/mcp_session_proof.py +605 -0
- package/core/skills/mobile_ui_inspector.py +405 -0
- package/core/skills/skill_pack.py +1214 -0
- package/core/skills/skill_synthesizer.py +1153 -0
- package/core/skills/tools_kb.py +313 -0
- package/core/supervisor/INTERFACE.md +121 -0
- package/core/supervisor/README.md +209 -0
- package/core/supervisor/SPEC.md +25 -0
- package/core/supervisor/__init__.py +175 -0
- package/core/supervisor/audit_supervisor.py +1015 -0
- package/core/supervisor/budget_governor.py +760 -0
- package/core/supervisor/checkpoint_handler.py +368 -0
- package/core/supervisor/checkpoint_pipeline.py +1322 -0
- package/core/supervisor/checkpoint_sync.py +640 -0
- package/core/supervisor/claim_events.py +74 -0
- package/core/supervisor/claim_sync.py +590 -0
- package/core/supervisor/cli.py +812 -0
- package/core/supervisor/context_sync.py +55 -0
- package/core/supervisor/coverage_sync.py +115 -0
- package/core/supervisor/finding_commit.py +470 -0
- package/core/supervisor/finding_sync.py +688 -0
- package/core/supervisor/finding_workflow.py +659 -0
- package/core/supervisor/finish_policy.py +224 -0
- package/core/supervisor/finish_sync.py +185 -0
- package/core/supervisor/graph_sync.py +669 -0
- package/core/supervisor/lease_manager.py +788 -0
- package/core/supervisor/lifecycle_blocks.py +124 -0
- package/core/supervisor/next_round_sync.py +126 -0
- package/core/supervisor/observability.py +140 -0
- package/core/supervisor/recovery_sync.py +165 -0
- package/core/supervisor/rejection_remedies.py +308 -0
- package/core/supervisor/round_governor.py +306 -0
- package/core/supervisor/serial_authorization.py +500 -0
- package/core/supervisor/start_sync.py +87 -0
- package/core/supervisor/state_store.py +249 -0
- package/core/supervisor/supervisor_host.py +511 -0
- package/core/supervisor/supervisor_models.py +1143 -0
- package/core/supervisor/systemic_failure.py +104 -0
- package/core/supervisor/task_scheduler.py +1640 -0
- package/core/supervisor/worker_checkpoint.py +223 -0
- package/core/supervisor/worker_execution.py +265 -0
- package/core/supervisor/worker_handoff.py +192 -0
- package/core/supervisor/worker_lifecycle.py +396 -0
- package/core/supervisor/worker_runtime.py +999 -0
- package/core/supervisor/worker_sync.py +89 -0
- package/core/supervisor_types/README.md +36 -0
- package/core/supervisor_types/__init__.py +0 -0
- package/core/supervisor_types/exceptions.py +52 -0
- package/core/supervisor_types/graph_models.py +357 -0
- package/core/supervisor_types/path_containment.py +151 -0
- package/core/supervisor_types/target_fingerprint.py +310 -0
- package/core/supervisor_types/worker_claim.py +402 -0
- package/core/webui/INTERFACE.md +50 -0
- package/core/webui/README.md +57 -0
- package/core/webui/SPEC.md +25 -0
- package/core/webui/__init__.py +11 -0
- package/core/webui/adapters/__init__.py +27 -0
- package/core/webui/adapters/base.py +87 -0
- package/core/webui/adapters/bugx.py +102 -0
- package/core/webui/adapters/claude.py +218 -0
- package/core/webui/adapters/cline.py +399 -0
- package/core/webui/adapters/codex.py +256 -0
- package/core/webui/adapters/dsh.py +173 -0
- package/core/webui/adapters/opencode.py +218 -0
- package/core/webui/adapters/pi.py +272 -0
- package/core/webui/adapters/registry.py +100 -0
- package/core/webui/adapters/zcode.py +312 -0
- package/core/webui/api_routes_post.py +668 -0
- package/core/webui/dispatcher.py +1376 -0
- package/core/webui/docs_session_service.py +473 -0
- package/core/webui/handler.py +674 -0
- package/core/webui/ide_cloud_service.py +526 -0
- package/core/webui/mcp_inspector.py +1743 -0
- package/core/webui/static/assets/index-CXAsl8mr.js +333 -0
- package/core/webui/static/assets/index-DHQUtWtx.css +1 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-B8Z6Jvzv.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-C44pakCn.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-Bb4u56_6.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-BdVUvljg.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-CWV284fw.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-DLkyKLvH.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-8-8HP2PF.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-DaDZE_Na.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-BccYJ-vZ.woff +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-Cw5-AHNN.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-By8GFJzz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-z-Q6FFuG.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-DJ5YJwmz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-Dn3IlU-Z.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-CUHe9xxf.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-DVVamBqs.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-CEpydyUl.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-Cp7z-ARB.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-BYjRCDVy.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-D-qasQTj.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-BbG3LG1A.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-DR1UuFon.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-8N8MYVKB.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-Bi3OSTTW.woff2 +0 -0
- package/core/webui/static/favicon.png +0 -0
- package/core/webui/static/icon-192.png +0 -0
- package/core/webui/static/index.html +42 -0
- package/core/webui/static/manifest.webmanifest +19 -0
- package/core/webui/static/project-settings.css +6458 -0
- package/core/webui/static/project-settings.js +9602 -0
- package/core/webui/static/sw.js +8 -0
- package/core/webui/workspace_service.py +218 -0
- package/docs/07_distribution/01_README_NPM.md +281 -0
- package/docs/07_distribution/README.md +16 -0
- package/docs/README.md +121 -0
- package/ecosystem/README.md +129 -0
- package/ecosystem/integrations/README.md +38 -0
- package/ecosystem/integrations/cline/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/dsh/agents/bugx.md +27 -0
- package/ecosystem/integrations/dsh/dsh-patch.yml +18 -0
- package/ecosystem/integrations/dsh/mcp/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/mcp/index.js +219 -0
- package/ecosystem/integrations/dsh/mcp/package.json +28 -0
- package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +70 -0
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/integrations/dsh/ui/client.js +87 -0
- package/ecosystem/integrations/dsh/ui/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/ui/index.js +7 -0
- package/ecosystem/integrations/dsh/ui/package.json +27 -0
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +53 -0
- package/ecosystem/integrations/opencode/mcp-lock.json +3067 -0
- package/ecosystem/integrations/opencode/opencode.json +118 -0
- package/ecosystem/integrations/pi/extensions/bugx/README.md +12 -0
- package/ecosystem/integrations/pi/extensions/bugx/index.ts +299 -0
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +11 -0
- package/ecosystem/integrations/pi/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/qoder/CONNECTORS.md +54 -0
- package/ecosystem/integrations/qoder/connector-meta.json +21 -0
- package/ecosystem/integrations/workbuddy/connector-meta.json +19 -0
- package/ecosystem/integrations/workbuddy/icon.png +0 -0
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +70 -0
- package/ecosystem/plugins/README.md +37 -0
- package/ecosystem/plugins/bugx/.claude-plugin/marketplace.json +17 -0
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +16 -0
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +41 -0
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +19 -0
- package/ecosystem/plugins/bugx/agents/bugx-judge.md +71 -0
- package/ecosystem/plugins/bugx/agents/bugx-worker.md +31 -0
- package/ecosystem/plugins/bugx/agents/bugx.md +74 -0
- package/ecosystem/plugins/bugx/assets/bugx-avatar-512.png +0 -0
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +118 -0
- package/ecosystem/plugins/bugx/skills/bugx-claude/SKILL.md +326 -0
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +129 -0
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +459 -0
- package/interfaces/README.md +143 -0
- package/interfaces/bin/README.md +35 -0
- package/interfaces/bin/bugx.js +80 -0
- package/interfaces/cli/README.md +90 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -0
- package/interfaces/cli/bugx_cli/cli.py +1678 -0
- package/interfaces/cli/bugx_cli/commands/__init__.py +1 -0
- package/interfaces/cli/bugx_cli/commands/advisory.py +94 -0
- package/interfaces/cli/bugx_cli/commands/agent.py +3944 -0
- package/interfaces/cli/bugx_cli/commands/audit.py +632 -0
- package/interfaces/cli/bugx_cli/commands/autonomous.py +260 -0
- package/interfaces/cli/bugx_cli/commands/cloud.py +1370 -0
- package/interfaces/cli/bugx_cli/commands/daemon.py +50 -0
- package/interfaces/cli/bugx_cli/commands/doctor.py +1345 -0
- package/interfaces/cli/bugx_cli/commands/goal.py +107 -0
- package/interfaces/cli/bugx_cli/commands/interaction.py +244 -0
- package/interfaces/cli/bugx_cli/commands/knowledge.py +617 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +2763 -0
- package/interfaces/cli/bugx_cli/commands/patch.py +1014 -0
- package/interfaces/cli/bugx_cli/commands/plugin.py +2714 -0
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +1446 -0
- package/interfaces/cli/bugx_cli/commands/plugin_cline.py +269 -0
- package/interfaces/cli/bugx_cli/commands/plugin_codex.py +74 -0
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +728 -0
- package/interfaces/cli/bugx_cli/commands/plugin_qoder.py +216 -0
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +710 -0
- package/interfaces/cli/bugx_cli/commands/project.py +670 -0
- package/interfaces/cli/bugx_cli/commands/report.py +260 -0
- package/interfaces/cli/bugx_cli/commands/skill.py +251 -0
- package/interfaces/cli/bugx_cli/commands/stats.py +133 -0
- package/interfaces/cli/bugx_cli/commands/system.py +2567 -0
- package/interfaces/cli/bugx_cli/common.py +898 -0
- package/interfaces/cli/bugx_cli/host_adapters.py +1917 -0
- package/interfaces/cli/bugx_cli/hosts/__init__.py +80 -0
- package/interfaces/cli/bugx_cli/hosts/base.py +99 -0
- package/interfaces/cli/bugx_cli/hosts/registry.py +571 -0
- package/interfaces/cli/bugx_cli/hosts/template_engine.py +188 -0
- package/interfaces/cli/bugx_cli/infra/__init__.py +209 -0
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +721 -0
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +1937 -0
- package/interfaces/cli/bugx_cli/infra/host_sync.py +545 -0
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +755 -0
- package/interfaces/cli/bugx_cli/infra/security.py +332 -0
- package/package.json +98 -4
- package/pyproject.toml +246 -0
- package/scripts/README.md +118 -0
- package/scripts/ensure-python.mjs +97 -0
- package/scripts/isolate-npm-readme.mjs +40 -0
- package/scripts/runtime.lock.json +31 -0
- package/scripts/sync-version.mjs +37 -0
- package/scripts/test-npm-wrapper.mjs +265 -0
|
@@ -0,0 +1,948 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""core/hosts/codex.py - Codex 插件(DOC-239 S3:纵切,事实只在这里声明)。
|
|
3
|
+
|
|
4
|
+
事实来源(逐字搬入,不重新解释):
|
|
5
|
+
|
|
6
|
+
* identity ← ``host_registry.HOST_MARKERS["codex"]``(``.codex/config.toml`` 等)
|
|
7
|
+
* install ← ``src/bugx_cli/hosts/registry.HOST_COMPONENTS`` +
|
|
8
|
+
``host_adapters.HOST_ADAPTERS``(``.agents/skills/bugx/SKILL.md``)
|
|
9
|
+
* engine ← ``supervisor_host.CodexAdapter``(无头 ``codex exec <prompt>``;自治
|
|
10
|
+
``--approve-for-me`` + ``resume``/``--json``/``--enable multi_agent_v2``
|
|
11
|
+
+ ``-c mcp_servers.*`` 覆盖)
|
|
12
|
+
* mcp_write ← 项目级 ``.codex/config.toml`` 的 ``[mcp_servers.<name>]`` 表 +
|
|
13
|
+
``.bugx/state/host-mcp/codex.json`` 运行期回执。**Codex 只读 TOML**:
|
|
14
|
+
``codex-cli 0.163.0`` 实测 ``.codex/config.json`` 永不被加载(旧 JSON
|
|
15
|
+
写入器产生的是死配置),因此本插件声明 ``config_format="toml"``,
|
|
16
|
+
写入/清理/诊断三件由 :mod:`hosts.mcp_toml` 承担,CLI 通用 JSON 骨架
|
|
17
|
+
不得接管。
|
|
18
|
+
* trust ← ``$CODEX_HOME/config.toml`` 的 ``[projects."<绝对路径>"]``。官方文档
|
|
19
|
+
明示 “Untrusted projects skip project-scoped ``.codex/`` layers,
|
|
20
|
+
including project-local config”,即项目未受信任时上面写的 TOML 会被
|
|
21
|
+
**整层跳过**。启动期自愈为 ``trust_level = "trusted"``;用户显式写
|
|
22
|
+
``untrusted`` 时 fail-closed,绝不按死配置继续跑。
|
|
23
|
+
* acp ← **无 ACP 入口**:``codex-cli 0.163.0`` 的 ``--help`` 没有 ``acp``
|
|
24
|
+
子命令、也没有 ``--acp`` flag(2026-10-22 真机审计,见
|
|
25
|
+
``docs/08_internal/11_research/HOST_LAUNCH_CONTRACT_AUDIT_2026-10-22.md``)。
|
|
26
|
+
该事实由 ``core/host_acp/codex.py`` 以 ``status = "unavailable"``
|
|
27
|
+
**机读声明**,探针如实报 ``BLOCKED(adapter_status=unavailable)``——
|
|
28
|
+
它不是「未迁移」,而是宿主产品本身没有该协议面;把它写进 TODO 会让
|
|
29
|
+
审计把「等上游」误读成本仓拖欠。
|
|
30
|
+
因此 Codex 的受支持通道是**无头 ``codex exec``**(``engine_run`` 面),
|
|
31
|
+
调用契约按实测钉死:prompt 走 argv 时 stdin 必须关闭、会话 id 取
|
|
32
|
+
``thread.started.thread_id``、``resume`` 子命令不接受
|
|
33
|
+
``--approve-for-me`` / ``--add-dir``。
|
|
34
|
+
|
|
35
|
+
* git ← **不归本插件负责,也不许本插件绕过**:项目根是 Git 仓库是 ``pre``
|
|
36
|
+
前置门禁(``core/launch_phases/startup_gates.py::git_startup_gate``,
|
|
37
|
+
状态取自 ``core/startup_environment.py::detect_git``:``missing`` →
|
|
38
|
+
``install_git``、``not-repository`` → ``git_init``、``unborn`` 等 →
|
|
39
|
+
``repair_git``;未通过直接 ``POLLING_DECISION_REQUIRED``,**不创建
|
|
40
|
+
Session**)。契约合规的项目到这里一定已有 ``.git``(目录或 worktree
|
|
41
|
+
gitfile),所以 argv **绝不**带 ``--skip-git-repo-check``:该 flag 既
|
|
42
|
+
多余,又会顺手放开宿主自己的目录信任边界,把「前置门禁失效」伪装成
|
|
43
|
+
「跑得通」。真缺 ``.git`` 就让 Codex 自己报
|
|
44
|
+
``Not inside a trusted directory ...``,由上游 ``git_environment``
|
|
45
|
+
门禁修复,不做静默降级。
|
|
46
|
+
|
|
47
|
+
为什么 ``CodexAdapter`` 的 argv 逻辑必须搬进插件:它此前与 CLI 的
|
|
48
|
+
``HostComponent`` / ``HOST_ADAPTERS`` 各自声明同一批量(名字、入口、能力),
|
|
49
|
+
漏改一处就静默降级(DES-01 的成因)。纵切后引擎/CLI 通用层零 Codex 字面量。
|
|
50
|
+
|
|
51
|
+
仍然在插件外的 Codex 事实(``tests/test_host_plugins.py`` 的
|
|
52
|
+
``OUTSIDE_PLUGIN_CODEX`` 按文件逐一核对):
|
|
53
|
+
|
|
54
|
+
* ``src/bugx_cli/commands/plugin.py`` / ``lifecycle.py``:ChatGPT 分发流程经
|
|
55
|
+
``codex plugin`` 命令注册 marketplace 并读 ``~/.codex/config.toml`` ——那是
|
|
56
|
+
**chatgpt 宿主的安装实现**(S4 负责迁移),不是 Codex 宿主接线;
|
|
57
|
+
* ``src/bugx_cli/host_adapters.CodexAdapter``:只剩 Windows 安装位探测这一 CLI
|
|
58
|
+
行为覆写(``%LOCALAPPDATA%\\OpenAI\\Codex`` 与 MSIX),声明字段全部来自本模块。
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
from __future__ import annotations
|
|
62
|
+
|
|
63
|
+
import json
|
|
64
|
+
import os
|
|
65
|
+
import time
|
|
66
|
+
import tomllib
|
|
67
|
+
from pathlib import Path
|
|
68
|
+
from typing import Any, Mapping
|
|
69
|
+
|
|
70
|
+
# 同包私有模块一律走相对导入:平铺绝对回退会触发架构棘轮的跨模块私有符号
|
|
71
|
+
# 泄露计数(private_leaks 棘轮基线 0),且 core.* 命名空间由引擎自举保证。
|
|
72
|
+
from . import _mcp_toml as mcp_toml
|
|
73
|
+
from .base import (
|
|
74
|
+
AcpFacet,
|
|
75
|
+
EngineRunFacet,
|
|
76
|
+
HostPlugin,
|
|
77
|
+
IdentityFacet,
|
|
78
|
+
InstallFacet,
|
|
79
|
+
McpWriteFacet,
|
|
80
|
+
RunContext,
|
|
81
|
+
STATUS_READY,
|
|
82
|
+
WorkerRuntimeFacet,
|
|
83
|
+
UsageFacet,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
__all__ = ["PLUGIN", "bootstrap_mcp", "ensure_project_trust", "inspect_project", "remove_mcp"]
|
|
87
|
+
|
|
88
|
+
_NAME = "codex"
|
|
89
|
+
|
|
90
|
+
#: Codex 项目级配置目录(``identity.markers`` 的同源推导,不重复写路径)。
|
|
91
|
+
_CONFIG_DIR = ".codex"
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _config_paths(root: Path) -> tuple[Path, ...]:
|
|
95
|
+
"""Codex 唯一会被加载的项目级配置(``config.json`` 不是 Codex 的格式)。"""
|
|
96
|
+
|
|
97
|
+
return (root / _CONFIG_DIR / "config.toml",)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _agent_config_path(root: Path) -> Path:
|
|
101
|
+
"""``agent_config_path`` 的 Codex 口径:真实文件优先,其次目录本身。"""
|
|
102
|
+
|
|
103
|
+
for candidate in _config_paths(root):
|
|
104
|
+
if candidate.is_file():
|
|
105
|
+
return candidate
|
|
106
|
+
return root / _CONFIG_DIR
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _writable_state_dirs() -> list[Path]:
|
|
110
|
+
"""BugX 运行期必须可写的宿主外状态/缓存目录(``workspace-write`` 之外)。
|
|
111
|
+
|
|
112
|
+
真机事实(``codex-cli 0.163.0``,``--approve-for-me`` 的 managed 权限档):沙箱
|
|
113
|
+
只允许写工作区,``$HOME`` 一律 ``EPERM``。未授权时会连锁失败:
|
|
114
|
+
|
|
115
|
+
* ``~/.bugx/mcp-runtime/**`` 写不进 ⇒ 可选 MCP(如 semgrep)供给必然失败,而该
|
|
116
|
+
条目是 critical,``pre`` 直接阻断(实测:``本轮启动已停止:semgrep``);
|
|
117
|
+
* ``~/.semgrep/semgrep.log`` / ``~/.cache/semgrep`` 写不进 ⇒ 即使扫描器已装好,
|
|
118
|
+
``semgrep --version`` 也直接抛 ``PermissionError``(实测原文)。
|
|
119
|
+
|
|
120
|
+
因此只授权这些**运行期状态/缓存**子目录,**绝不**授权 ``~/.bugx`` 本身:
|
|
121
|
+
``~/.bugx/core`` 是引擎本体,授权写等于允许被审代码改写审计工具。
|
|
122
|
+
目录不存在时不下发(不主动创建用户主目录里的新路径)。
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
home = Path.home()
|
|
126
|
+
candidates = (
|
|
127
|
+
home / ".bugx" / "mcp-runtime",
|
|
128
|
+
home / ".bugx" / "logs",
|
|
129
|
+
home / ".semgrep",
|
|
130
|
+
home / ".cache" / "semgrep",
|
|
131
|
+
)
|
|
132
|
+
return [path for path in candidates if path.is_dir() and not path.is_symlink()]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _state_grants() -> list[str]:
|
|
136
|
+
"""``--add-dir`` 参数对(运行期可写状态目录)。"""
|
|
137
|
+
|
|
138
|
+
grants: list[str] = []
|
|
139
|
+
for state_dir in _writable_state_dirs():
|
|
140
|
+
grants += ["--add-dir", str(state_dir)]
|
|
141
|
+
return grants
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _headless_argv(ctx: RunContext) -> list[str]:
|
|
145
|
+
# Codex ``exec`` 没有 OpenCode 风格的 ``--agent``:``ctx.agent`` / ``ctx.session``
|
|
146
|
+
# 被刻意忽略(会话续跑用 ``resume``,见 ``_autonomous_argv``)。
|
|
147
|
+
#
|
|
148
|
+
# 调用契约(0.163.0 实测,别按「看起来合理」改):
|
|
149
|
+
# * prompt 走 argv 时 stdin 里**不能有可读数据**:stdin 非 TTY 时 Codex 仍会打印
|
|
150
|
+
# ``Reading additional input from stdin...``(``stdin=DEVNULL`` 实测也照打,
|
|
151
|
+
# 见 ``scripts/smoke_host_headless.py`` 的 ``informational.stdin_notice``),
|
|
152
|
+
# 但它读到 EOF 就继续;真正的风险是把管道里的内容追加成 ``<stdin>`` 块污染
|
|
153
|
+
# prompt。因此判据是「事件流里没有 ``<stdin>`` 块 + Agent 文本未被污染」,
|
|
154
|
+
# 而不是「stderr 没有这行提示」——后者永远做不到,把它当契约只会制造假阴性。
|
|
155
|
+
# * **不加** ``--skip-git-repo-check``:Git 仓库是 ``pre`` 的 ``git_environment``
|
|
156
|
+
# 门禁(``startup_gates.git_startup_gate`` → ``git_init``/``repair_git``),
|
|
157
|
+
# 合规项目必然已有 ``.git``;在这里放行等于绕过宿主目录信任边界,掩盖前置
|
|
158
|
+
# 门禁失效(见模块 docstring 的 ``git`` 面)。
|
|
159
|
+
# * **必须加** ``--approve-for-me``(2026-10-24 真机反证,0.163.0):不带该 flag 时
|
|
160
|
+
# ``codex exec`` 的 approval policy 是 ``never``,**任何** MCP 工具调用都被拒绝——
|
|
161
|
+
# 事件流里 ``item.started``/``item.completed`` 的 ``mcp_tool_call`` 依次出现
|
|
162
|
+
# ``{"server":"bugx-supervisor","tool":"bugx_supervisor_status"}`` 与
|
|
163
|
+
# ``{"status":"failed","error":{"message":"MCP tool call requires approval, but
|
|
164
|
+
# approval policy is never"}}``;即「宿主发现了项目级 MCP 与工具名,却调用不了」。
|
|
165
|
+
# 这种形态极易被误读成「MCP 没加载」或「模型不听话」,实际是 approval 通路缺失。
|
|
166
|
+
# 带上之后同一命令返回 ``status=completed`` +
|
|
167
|
+
# ``structured_content={"status":"NO_RUN","root":"<项目根>"}``,证明项目级
|
|
168
|
+
# ``.codex/config.toml`` 的 MCP 表真的被加载并按项目根服务(反例实验见
|
|
169
|
+
# ``scripts/smoke_host_headless.py --mode mcp``)。
|
|
170
|
+
# ``--approve-for-me`` 的官方语义是「approval 请求走自动复核,沙箱固定
|
|
171
|
+
# workspace-write」(``codex exec --help``),与 ``_autonomous_argv`` 保持同一
|
|
172
|
+
# approval 语义:无头通道没有人类可以点「允许」,缺它等于让每个 Worker 的
|
|
173
|
+
# 控制面调用恒失败。
|
|
174
|
+
return [
|
|
175
|
+
"codex", "exec", "--approve-for-me",
|
|
176
|
+
*_state_grants(),
|
|
177
|
+
ctx.prompt,
|
|
178
|
+
]
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
_SCOUT_FEATURE_OPTIONS = (
|
|
182
|
+
"-c", "features.plugins=false", "-c", "features.apps=false",
|
|
183
|
+
"-c", "features.multi_agent=false",
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _scout_inventory_command(root: Path) -> tuple[list[str], str]:
|
|
188
|
+
"""声明侦察前要执行的清单查询:``(argv, 结果键)``,由引擎执行。
|
|
189
|
+
|
|
190
|
+
插件只声明命令与结果位置,不在本模块启动子进程——``subprocess`` 属于被
|
|
191
|
+
依赖方向门禁禁止的模块(插件事实只能单向流出,不得自己驱动外部进程)。
|
|
192
|
+
"""
|
|
193
|
+
_ = root
|
|
194
|
+
# 实测:`codex mcp list --json` 返回**顶级数组**,不是 {"servers": [...]}。
|
|
195
|
+
# 结果键留空表示「整个负载就是清单」,避免把包装键写死成错误事实。
|
|
196
|
+
return ["codex", "mcp", "list", "--json", *_SCOUT_FEATURE_OPTIONS], ""
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _disable_mcp_options(servers: object) -> list[str]:
|
|
200
|
+
"""把 CLI 的有效 MCP 清单转成 ``-c mcp_servers.<name>.enabled=false``。
|
|
201
|
+
|
|
202
|
+
纯函数:输入是引擎读回的 JSON 结果,不接触进程、文件或全局配置,因此
|
|
203
|
+
可以独立断言「哪些服务器会被关掉」。名字无法用 CLI 键表达时显式告警并
|
|
204
|
+
跳过,绝不猜测或吞掉。
|
|
205
|
+
"""
|
|
206
|
+
import re
|
|
207
|
+
import warnings
|
|
208
|
+
|
|
209
|
+
if not isinstance(servers, list):
|
|
210
|
+
raise ValueError("Codex MCP inventory must be an array")
|
|
211
|
+
options: list[str] = []
|
|
212
|
+
for server in servers:
|
|
213
|
+
name = server.get("name") if isinstance(server, dict) else None
|
|
214
|
+
if not isinstance(name, str) or not server.get("enabled"):
|
|
215
|
+
continue
|
|
216
|
+
if not re.fullmatch(r"[A-Za-z0-9_-]+", name):
|
|
217
|
+
warnings.warn(f"Scout retained MCP with unaddressable CLI key: {name!r}", RuntimeWarning)
|
|
218
|
+
continue
|
|
219
|
+
options.extend(["-c", f"mcp_servers.{name}.enabled=false"])
|
|
220
|
+
return options
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def recon_scout_command(
|
|
224
|
+
root: Path, prompt: str, inventory: object | None = None,
|
|
225
|
+
) -> list[str]:
|
|
226
|
+
"""Context-only Scout; no global config writes, model/effort remain intact.
|
|
227
|
+
|
|
228
|
+
``inventory`` 由引擎按 ``_scout_inventory_command`` 读取后传入;未提供时
|
|
229
|
+
(例如清单查询失败)不追加禁用项,侦察仍在 read-only 沙箱内执行。
|
|
230
|
+
"""
|
|
231
|
+
return [
|
|
232
|
+
"codex", "exec", "--json", "--ephemeral", "--sandbox", "read-only",
|
|
233
|
+
*_SCOUT_FEATURE_OPTIONS, *_disable_mcp_options(inventory), "-C", str(root),
|
|
234
|
+
("This is a semantic-review subroutine called by the active audit Agent, not a request to launch that Agent. "
|
|
235
|
+
"The caller owns every user gate, lifecycle transition and Worker dispatch. "
|
|
236
|
+
"Perform the original semantic-review task below without recursively starting the parent workflow or loading its full manuals. "
|
|
237
|
+
"You may inspect relevant source read-only when needed; report missing evidence as unverified. "
|
|
238
|
+
"Return the requested JSON object only.\n\n" + prompt),
|
|
239
|
+
]
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def _autonomous_mcp_options() -> list[str]:
|
|
243
|
+
"""BugX 内置 MCP 的命令行覆盖(子 Agent 也要能拿到,故同时写项目配置)。"""
|
|
244
|
+
|
|
245
|
+
options: list[str] = []
|
|
246
|
+
for name, role in (
|
|
247
|
+
("bugx-supervisor", "host"),
|
|
248
|
+
("bugx-supervisor-worker", "worker"),
|
|
249
|
+
):
|
|
250
|
+
prefix = f"mcp_servers.{name}"
|
|
251
|
+
options.extend([
|
|
252
|
+
"-c", f'{prefix}.command="bugx"',
|
|
253
|
+
"-c", f'{prefix}.args=["mcp","serve","--root",".","--role","{role}"]',
|
|
254
|
+
])
|
|
255
|
+
options.extend([
|
|
256
|
+
"-c", 'mcp_servers.bugx-docs.command="bugx"',
|
|
257
|
+
"-c", 'mcp_servers.bugx-docs.args=["mcp","docs","serve","--root",".","--db",".bugx/knowledge/docs.sqlite3"]',
|
|
258
|
+
])
|
|
259
|
+
return options
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def _git_metadata_dirs(root: Path) -> list[Path]:
|
|
263
|
+
"""本仓库需要授权给 Codex 的 Git 元数据目录(普通克隆 1 个,worktree/submodule 2 个)。
|
|
264
|
+
|
|
265
|
+
``.git`` 是目录 → 就是它自己;``.git`` 是 **gitfile**(``gitdir: <path>``,``git
|
|
266
|
+
worktree`` 与 submodule 都这样)→ 授权 ``gitdir`` **和**它的 ``commondir``:worktree
|
|
267
|
+
私有目录只有 ``HEAD``/``index``,``objects``/``refs``/``config`` 落在共同目录里,
|
|
268
|
+
只授权前者仍然写不进对象库。
|
|
269
|
+
|
|
270
|
+
无法解析的 gitfile(缺指针 / 指针指向已清理的目录)返回空列表,**不在 argv 层抛错**:
|
|
271
|
+
``startup_environment.detect_git`` 对这两种形态实测都是 ``not-repository`` +
|
|
272
|
+
``ready=False``,``pre`` 的 ``git_environment`` 门禁会先阻断(被动修复或中断),
|
|
273
|
+
argv 只是投影,不该变成第二套门禁——build 191 的教训就是插件别替宿主门禁做决定。
|
|
274
|
+
完全没有 ``.git`` 同理属门禁职责。
|
|
275
|
+
"""
|
|
276
|
+
|
|
277
|
+
git_path = Path(root).expanduser().resolve() / ".git"
|
|
278
|
+
if git_path.is_dir() and not git_path.is_symlink():
|
|
279
|
+
return [git_path]
|
|
280
|
+
if not git_path.is_file():
|
|
281
|
+
# 符号链接的 ``.git`` 也走这里:不跟随,避免把沙箱授权扩到仓库外的任意路径。
|
|
282
|
+
return []
|
|
283
|
+
try:
|
|
284
|
+
text = git_path.read_text(encoding="utf-8")
|
|
285
|
+
except OSError:
|
|
286
|
+
return []
|
|
287
|
+
pointer = next(
|
|
288
|
+
(line.strip() for line in text.splitlines() if line.strip().startswith("gitdir:")),
|
|
289
|
+
"",
|
|
290
|
+
)
|
|
291
|
+
raw = pointer[len("gitdir:"):].strip()
|
|
292
|
+
if not raw:
|
|
293
|
+
return []
|
|
294
|
+
gitdir = Path(raw).expanduser()
|
|
295
|
+
if not gitdir.is_absolute():
|
|
296
|
+
gitdir = git_path.parent / gitdir
|
|
297
|
+
gitdir = gitdir.resolve()
|
|
298
|
+
if not gitdir.is_dir():
|
|
299
|
+
return []
|
|
300
|
+
dirs = [gitdir]
|
|
301
|
+
commondir_file = gitdir / "commondir"
|
|
302
|
+
if commondir_file.is_file():
|
|
303
|
+
try:
|
|
304
|
+
raw_common = commondir_file.read_text(encoding="utf-8").strip()
|
|
305
|
+
except OSError:
|
|
306
|
+
raw_common = ""
|
|
307
|
+
if raw_common:
|
|
308
|
+
common = Path(raw_common).expanduser()
|
|
309
|
+
if not common.is_absolute():
|
|
310
|
+
common = gitdir / common
|
|
311
|
+
common = common.resolve()
|
|
312
|
+
if common != gitdir and common.is_dir():
|
|
313
|
+
dirs.append(common)
|
|
314
|
+
return dirs
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def _autonomous_argv(ctx: RunContext) -> list[str]:
|
|
318
|
+
# 不加 ``--skip-git-repo-check``:Git 仓库由 ``pre`` 的 ``git_environment`` 门禁
|
|
319
|
+
# 保证(见 ``_headless_argv`` 注释与模块 docstring 的 ``git`` 面)。
|
|
320
|
+
command = ["codex", "exec", "--approve-for-me"]
|
|
321
|
+
# --approve-for-me keeps workspace-write; grant only this clone's Git metadata so
|
|
322
|
+
# its startup write probe and local commits work. worktree/submodule 的 ``.git``
|
|
323
|
+
# 是 gitfile,需要同时授权 gitdir 与 commondir(见 ``_git_metadata_dirs``)。
|
|
324
|
+
for metadata_dir in _git_metadata_dirs(Path(ctx.root)):
|
|
325
|
+
command += ["--add-dir", str(metadata_dir)]
|
|
326
|
+
# 运行期状态/缓存目录同样必须在 resume 之前下发(同上:resume 不接受 --add-dir)。
|
|
327
|
+
command += _state_grants()
|
|
328
|
+
if ctx.session:
|
|
329
|
+
# ``resume`` 是 ``exec`` 的子命令,且**只**接受自己那套选项:实测
|
|
330
|
+
# ``codex exec resume --help`` 没有 ``--approve-for-me`` / ``--add-dir``,
|
|
331
|
+
# 因此这两个 flag 必须放在子命令**之前**(exec 级),放进 resume 之后会
|
|
332
|
+
# 变成「未知参数」直接退出。
|
|
333
|
+
command += ["resume", ctx.session]
|
|
334
|
+
command += [
|
|
335
|
+
"--json", "--enable", "multi_agent_v2",
|
|
336
|
+
*_autonomous_mcp_options(), ctx.prompt,
|
|
337
|
+
]
|
|
338
|
+
return command
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def _mcp_health(name: str, cfg: dict, root: Path | None = None) -> bool:
|
|
342
|
+
del name, cfg, root # bugx-supervisor 是宿主加载的 stdio MCP,恒健康
|
|
343
|
+
return True
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
#: BugX 受管条目的命名/命令前缀:既是冲突判定(能否覆盖)的所有权依据,也是
|
|
347
|
+
#: 卸载清理依据。
|
|
348
|
+
_BUGX_NAME_PREFIX = "bugx"
|
|
349
|
+
|
|
350
|
+
#: 追加表块前的横幅:用户据此识别哪一段由安装/启动流程维护。
|
|
351
|
+
_MCP_BANNER = "# BugX-managed MCP servers; generated for autonomous child Agents."
|
|
352
|
+
|
|
353
|
+
#: 旧实现把 MCP 写进 ``.codex/config.json``(Codex 从不加载该文件);只有在
|
|
354
|
+
#: 「整份内容都是 BugX 条目」时清扫,用户自写内容一律保留。
|
|
355
|
+
_LEGACY_JSON = "config.json"
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def _codex_home() -> Path:
|
|
359
|
+
"""``$CODEX_HOME`` 或 ``~/.codex``:Codex 用户级配置根(trust 与全局配置同处)。"""
|
|
360
|
+
|
|
361
|
+
override = os.environ.get("CODEX_HOME")
|
|
362
|
+
if override:
|
|
363
|
+
return Path(override).expanduser().resolve(strict=False)
|
|
364
|
+
return Path.home() / _CONFIG_DIR
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def _is_bugx_entry(name: str, spec: Mapping[str, Any]) -> bool:
|
|
368
|
+
"""条目是否由 BugX 维护:只看 command/args 是否指向 ``bugx``。
|
|
369
|
+
|
|
370
|
+
刻意**不看名字**:``bugx-supervisor`` 这个名字虽由本工具保留,但若用户把它
|
|
371
|
+
指向别的程序,那属于用户配置,必须冲突可见(拒绝覆盖),而不是被安装流程
|
|
372
|
+
当成「旧版 BugX 条目」静默改写。
|
|
373
|
+
"""
|
|
374
|
+
|
|
375
|
+
del name
|
|
376
|
+
tokens = [str(spec.get("command") or "")]
|
|
377
|
+
tokens.extend(str(arg) for arg in (spec.get("args") or ()))
|
|
378
|
+
return any(_BUGX_NAME_PREFIX in token.lower() for token in tokens)
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def _read_text(path: Path) -> str:
|
|
382
|
+
try:
|
|
383
|
+
return path.read_text(encoding="utf-8")
|
|
384
|
+
except (FileNotFoundError, PermissionError, OSError):
|
|
385
|
+
return ""
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
def _strip_banner(text: str) -> str:
|
|
389
|
+
"""去掉孤立的受管横幅注释(条目清空后它不再指向任何表块)。"""
|
|
390
|
+
|
|
391
|
+
lines = [line for line in text.splitlines() if line.strip() != _MCP_BANNER]
|
|
392
|
+
while lines and not lines[0].strip():
|
|
393
|
+
lines.pop(0)
|
|
394
|
+
while lines and not lines[-1].strip():
|
|
395
|
+
lines.pop()
|
|
396
|
+
if not lines:
|
|
397
|
+
return ""
|
|
398
|
+
return "\n".join(lines) + "\n"
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def _backup_config(root: Path, target: Path, suffix: str) -> Path | None:
|
|
402
|
+
"""备份到项目 ``.bugx/backups/host-mcp/``(0600);非普通文件不备份。"""
|
|
403
|
+
|
|
404
|
+
if not target.is_file() or target.is_symlink():
|
|
405
|
+
return None
|
|
406
|
+
backup_dir = root / ".bugx" / "backups" / "host-mcp"
|
|
407
|
+
backup_dir.mkdir(parents=True, exist_ok=True)
|
|
408
|
+
backup = backup_dir / f"codex-{time.time_ns()}{suffix}"
|
|
409
|
+
backup.write_bytes(target.read_bytes())
|
|
410
|
+
backup.chmod(0o600)
|
|
411
|
+
return backup
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def _trust_state(root: Path) -> str:
|
|
415
|
+
"""只读判定项目信任态:``trusted`` / ``untrusted`` / ``absent`` / ``unknown``。"""
|
|
416
|
+
|
|
417
|
+
home = _codex_home()
|
|
418
|
+
target = home / "config.toml"
|
|
419
|
+
if not home.is_dir():
|
|
420
|
+
return "absent"
|
|
421
|
+
try:
|
|
422
|
+
parsed = tomllib.loads(_read_text(target))
|
|
423
|
+
except (ValueError, UnicodeError):
|
|
424
|
+
return "unknown"
|
|
425
|
+
projects = parsed.get("projects")
|
|
426
|
+
entry = projects.get(str(root)) if isinstance(projects, dict) else None
|
|
427
|
+
if isinstance(entry, dict) and entry.get("trust_level") == "trusted":
|
|
428
|
+
return "trusted"
|
|
429
|
+
return "untrusted"
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def ensure_project_trust(root: Path) -> dict[str, object]:
|
|
433
|
+
"""确保项目在 ``$CODEX_HOME/config.toml`` 中受信任。
|
|
434
|
+
|
|
435
|
+
官方文档:*Untrusted projects skip project-scoped ``.codex/`` layers,
|
|
436
|
+
including project-local config*。即项目未受信任时,本插件写的
|
|
437
|
+
``[mcp_servers.*]`` 会被整层跳过——原生子 Agent 拿不到 MCP,且没有任何报错。
|
|
438
|
+
|
|
439
|
+
* 已 trusted → ``unchanged``(零写入);
|
|
440
|
+
* 无条目 → 追加 ``[projects."<绝对路径>"] trust_level = "trusted"``;
|
|
441
|
+
* 用户显式写 ``untrusted`` → **fail-closed** 抛错,绝不静默降级;
|
|
442
|
+
* 写入后**复读校验**:磁盘态若不是 ``trusted``(例如另一进程并发改写覆盖了
|
|
443
|
+
本次写入),同样 fail-closed——信任丢失时 Codex 会整层跳过项目级
|
|
444
|
+
``.codex/`` 配置且**不报错**,静默继续等于让子 Agent 无 MCP 裸跑;
|
|
445
|
+
* 本机无 ``$CODEX_HOME`` 目录 → ``absent``(宿主未安装,不凭空创建用户目录)。
|
|
446
|
+
|
|
447
|
+
``root`` 入口即归一化为**解析后的绝对路径**:Codex 用进程 ``cwd``(已解析,
|
|
448
|
+
macOS 上是 ``/private/...``)作为 ``[projects."<path>"]`` 的键。传入未解析路径
|
|
449
|
+
(``/tmp/...``、相对路径)会**并为同一项目写第二个条目**,真正的项目仍是
|
|
450
|
+
``untrusted``,且与上面所有判定共用同一个错键 ⇒ 全程「看起来成功」。
|
|
451
|
+
"""
|
|
452
|
+
|
|
453
|
+
root = Path(root).resolve()
|
|
454
|
+
import core.secure_atomic as secure_atomic
|
|
455
|
+
|
|
456
|
+
home = _codex_home()
|
|
457
|
+
target = home / "config.toml"
|
|
458
|
+
if not home.is_dir():
|
|
459
|
+
return {"status": "absent", "path": str(target), "created": False}
|
|
460
|
+
if target.is_symlink():
|
|
461
|
+
raise OSError(f"拒绝通过符号链接写入 Codex 用户级配置: {target}")
|
|
462
|
+
text = _read_text(target)
|
|
463
|
+
state = _trust_state(root)
|
|
464
|
+
if state == "trusted":
|
|
465
|
+
return {"status": "unchanged", "path": str(target), "created": False}
|
|
466
|
+
if state != "absent" and f'[projects."{root}"]' in text:
|
|
467
|
+
raise OSError(
|
|
468
|
+
f"{root} 已在 {target} 中被显式标记为非 trusted,"
|
|
469
|
+
"Codex 会整层跳过项目级 .codex/ 配置(含 BugX MCP)。"
|
|
470
|
+
'如需自治运行,请把该项目改为 trust_level = "trusted",或改用其它宿主。'
|
|
471
|
+
)
|
|
472
|
+
# 归属事实必须在写入前采样:卸载时只有「本工具新增的条目」才允许回收,
|
|
473
|
+
# 用户自己加过的信任条目属于用户配置(见 ``_forget_project_trust``)。
|
|
474
|
+
created = not _trust_entry_present(root)
|
|
475
|
+
try:
|
|
476
|
+
new_text, status = mcp_toml.set_table_key(
|
|
477
|
+
text, ("projects", str(root)), "trust_level", '"trusted"',
|
|
478
|
+
)
|
|
479
|
+
except ValueError as exc:
|
|
480
|
+
raise OSError(f"Codex 用户级配置无法登记项目信任({target}): {exc}") from exc
|
|
481
|
+
if status == "unchanged":
|
|
482
|
+
return {"status": "unchanged", "path": str(target), "created": False}
|
|
483
|
+
backup = _backup_config(root, target, ".toml")
|
|
484
|
+
mode = target.stat().st_mode & 0o777 if target.exists() else 0o600
|
|
485
|
+
secure_atomic.atomic_write_text(target, new_text, mode=mode, parent_mode=0o700)
|
|
486
|
+
# 写后复读:原子替换只保证"不会读到半截文件",不保证"本次写入仍是最新一次"。
|
|
487
|
+
# 并发改写(另一个 BugX 运行 / 用户编辑器保存)会让信任丢失,而 Codex 对未受
|
|
488
|
+
# 信任项目是**静默跳过**项目级配置——此时继续跑等于 Worker 无 MCP 裸跑。
|
|
489
|
+
verified = _trust_state(root)
|
|
490
|
+
if verified != "trusted":
|
|
491
|
+
raise OSError(
|
|
492
|
+
f"Codex 用户级信任写入后未生效({target} 复读为 {verified}):"
|
|
493
|
+
"可能有其它进程并发改写该文件。未受信任的项目会被 Codex 整层跳过项目级 "
|
|
494
|
+
".codex/ 配置(含 BugX MCP)且不报错,拒绝按降级态继续。"
|
|
495
|
+
)
|
|
496
|
+
return {
|
|
497
|
+
"status": "trusted",
|
|
498
|
+
"path": str(target),
|
|
499
|
+
"backup": str(backup) if backup else None,
|
|
500
|
+
"created": created,
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
#: 全局 MCP 条目(用户级 ``$CODEX_HOME/config.toml``):``--root .`` 相对绑定
|
|
505
|
+
#: ——Codex 以项目 cwd 派发 stdio MCP,任意项目内启动即绑定该项目;引擎侧
|
|
506
|
+
#: root 自愈(``_resolve_serve_root``)兜底 cwd 非 BugX 项目的场景(结构化
|
|
507
|
+
#: INITIALIZATION_REQUIRED,提示按需安装)。``bugx-docs`` 的 ``--db`` 同理按
|
|
508
|
+
#: 项目相对路径解析。
|
|
509
|
+
_GLOBAL_MCP_SERVERS: dict[str, dict[str, object]] = {
|
|
510
|
+
"bugx-supervisor": {
|
|
511
|
+
"command": "bugx",
|
|
512
|
+
"args": ["mcp", "serve", "--root", ".", "--role", "host"],
|
|
513
|
+
},
|
|
514
|
+
"bugx-supervisor-worker": {
|
|
515
|
+
"command": "bugx",
|
|
516
|
+
"args": ["mcp", "serve", "--root", ".", "--role", "worker"],
|
|
517
|
+
},
|
|
518
|
+
"bugx-docs": {
|
|
519
|
+
"command": "bugx",
|
|
520
|
+
"args": [
|
|
521
|
+
"mcp", "docs", "serve", "--root", ".",
|
|
522
|
+
"--db", ".bugx/knowledge/docs.sqlite3",
|
|
523
|
+
],
|
|
524
|
+
},
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def ensure_global_mcp(root: Path) -> dict[str, object]:
|
|
529
|
+
"""把 BugX MCP 三通道安装到**用户级** ``$CODEX_HOME/config.toml``。
|
|
530
|
+
|
|
531
|
+
与项目级 ``bootstrap_mcp`` 互补:项目级让 Worker 子代理稳定拿到 MCP
|
|
532
|
+
(含 trust 语义),全局级让宿主在**任意目录**都能直接审计当前项目,
|
|
533
|
+
无需每项目跑一次 ``bugx install --agent codex``。两者同名同定义时
|
|
534
|
+
Codex 按就近覆盖合并,互不冲突;项目未安装时全局条目是唯一来源。
|
|
535
|
+
|
|
536
|
+
纪律与 :func:`ensure_project_trust` 同源:备份(0600)、用户自有同名
|
|
537
|
+
条目拒绝覆盖(``_is_bugx_entry`` 归属判定)、原子写入 + 写后复读校验、
|
|
538
|
+
幂等(二跑 unchanged)。**绝不触碰** ``[projects]`` 信任表——全局 MCP
|
|
539
|
+
不依赖项目信任语义,也绝不静默扩大信任授权。
|
|
540
|
+
"""
|
|
541
|
+
import core.secure_atomic as secure_atomic
|
|
542
|
+
|
|
543
|
+
home = _codex_home()
|
|
544
|
+
if not home.is_dir():
|
|
545
|
+
raise OSError(
|
|
546
|
+
f"未找到 Codex 用户级配置目录({home}):宿主未安装,"
|
|
547
|
+
"拒绝凭空创建用户目录。请先安装 Codex CLI 后重试。"
|
|
548
|
+
)
|
|
549
|
+
target = home / "config.toml"
|
|
550
|
+
if target.is_symlink():
|
|
551
|
+
raise OSError(f"拒绝通过符号链接写入 Codex 全局 MCP 配置: {target}")
|
|
552
|
+
text = _read_text(target)
|
|
553
|
+
try:
|
|
554
|
+
new_text, added, updated = mcp_toml.upsert_servers(
|
|
555
|
+
text, _GLOBAL_MCP_SERVERS, owned=_is_bugx_entry, banner=_MCP_BANNER,
|
|
556
|
+
)
|
|
557
|
+
except ValueError as exc:
|
|
558
|
+
raise OSError(f"Codex 全局 MCP 配置写入被拒绝({target}): {exc}") from exc
|
|
559
|
+
changed = bool(added or updated)
|
|
560
|
+
backup: Path | None = None
|
|
561
|
+
if changed:
|
|
562
|
+
backup = _backup_config(root, target, ".toml")
|
|
563
|
+
mode = target.stat().st_mode & 0o777 if target.exists() else 0o600
|
|
564
|
+
secure_atomic.atomic_write_text(target, new_text, mode=mode, parent_mode=0o700)
|
|
565
|
+
# 写后复读:与信任写入同一防线——并发改写会让本次条目丢失且无报错。
|
|
566
|
+
final = mcp_toml.read_servers(_read_text(target))
|
|
567
|
+
missing = [n for n in _GLOBAL_MCP_SERVERS if n not in final]
|
|
568
|
+
if missing:
|
|
569
|
+
raise OSError(
|
|
570
|
+
f"Codex 全局 MCP 写入后未生效({target} 复读缺失: {', '.join(missing)}):"
|
|
571
|
+
"可能有其它进程并发改写该文件,拒绝按降级态继续。"
|
|
572
|
+
)
|
|
573
|
+
return {
|
|
574
|
+
"status": "unchanged" if not changed else "written",
|
|
575
|
+
"path": str(target),
|
|
576
|
+
"added": added,
|
|
577
|
+
"updated": updated,
|
|
578
|
+
"backup": str(backup) if backup else None,
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
def _trust_entry_present(root: Path) -> bool:
|
|
583
|
+
"""``$CODEX_HOME/config.toml`` 里是否**已存在** ``[projects."<root>"]`` 条目。
|
|
584
|
+
|
|
585
|
+
与 :func:`_trust_state` 的分工:后者回答「现在是不是 trusted」,本函数回答
|
|
586
|
+
「这个条目是不是本工具新增的」。卸载时只有本工具新增的条目才允许回收——用户
|
|
587
|
+
自己写过的条目(哪怕值同为 ``trusted``)属于用户配置。
|
|
588
|
+
"""
|
|
589
|
+
|
|
590
|
+
home = _codex_home()
|
|
591
|
+
try:
|
|
592
|
+
parsed = tomllib.loads(_read_text(home / "config.toml"))
|
|
593
|
+
except (OSError, ValueError):
|
|
594
|
+
return False
|
|
595
|
+
projects = parsed.get("projects")
|
|
596
|
+
return isinstance(projects, dict) and str(root) in projects
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
def _forget_project_trust(root: Path, receipt_path: Path) -> dict[str, object]:
|
|
600
|
+
"""回收**本工具新增**的用户级信任条目(卸载闭环的一部分)。
|
|
601
|
+
|
|
602
|
+
为什么必须回收:``[projects."<绝对路径>"] trust_level = "trusted"`` 是一条**永久**
|
|
603
|
+
信任授权。项目被删除或临时目录被重建(``/tmp`` 复用)后,Codex 仍会静默加载该
|
|
604
|
+
路径下的项目级 ``.codex/config.toml``(其中可声明任意 MCP 命令),等于把「谁先
|
|
605
|
+
在那个路径写文件」升级成「谁能让宿主执行命令」。安装期写了用户级配置,卸载期就
|
|
606
|
+
必须物理回收,否则「安装成功」自带一条越权后门。
|
|
607
|
+
|
|
608
|
+
三条同时满足才删(任一条不满足都保留并说明原因,不猜归属):
|
|
609
|
+
|
|
610
|
+
1. 运行期回执 ``.bugx/state/host-mcp/codex.json`` 记录 ``trust.created == true``;
|
|
611
|
+
2. 当前信任态仍是 ``trusted``(用户改成 ``untrusted`` 是显式表达,不得抹除);
|
|
612
|
+
3. 切除后 ``tomllib`` 复核通过且复读不再是 ``trusted``;成功即删回执,避免陈旧
|
|
613
|
+
回执二次触发删除。
|
|
614
|
+
"""
|
|
615
|
+
|
|
616
|
+
try:
|
|
617
|
+
payload = json.loads(receipt_path.read_text(encoding="utf-8"))
|
|
618
|
+
except (OSError, UnicodeError, ValueError):
|
|
619
|
+
return {"status": "preserved", "reason": "无运行期回执:无法证明信任条目归属"}
|
|
620
|
+
trust = payload.get("trust") if isinstance(payload, dict) else None
|
|
621
|
+
if not isinstance(trust, dict) or not trust.get("created"):
|
|
622
|
+
return {"status": "preserved", "reason": "信任条目不是本工具新增(用户原有配置)"}
|
|
623
|
+
if _trust_state(root) != "trusted":
|
|
624
|
+
return {"status": "preserved", "reason": "当前信任态非 trusted(用户显式表达),不回收"}
|
|
625
|
+
|
|
626
|
+
import core.secure_atomic as secure_atomic
|
|
627
|
+
|
|
628
|
+
target = _codex_home() / "config.toml"
|
|
629
|
+
if target.is_symlink():
|
|
630
|
+
return {"status": "preserved", "reason": f"{target} 是符号链接,拒绝改写"}
|
|
631
|
+
try:
|
|
632
|
+
new_text, removed = mcp_toml.remove_table(
|
|
633
|
+
_read_text(target), ("projects", str(root)),
|
|
634
|
+
)
|
|
635
|
+
except (OSError, ValueError) as exc:
|
|
636
|
+
return {"status": "preserved", "reason": f"用户级配置无法解析:{exc}"}
|
|
637
|
+
if not removed:
|
|
638
|
+
return {"status": "preserved", "reason": "未找到可切除的信任表块"}
|
|
639
|
+
backup = _backup_config(root, target, ".trust.toml")
|
|
640
|
+
mode = target.stat().st_mode & 0o777 if target.exists() else 0o600
|
|
641
|
+
secure_atomic.atomic_write_text(target, new_text, mode=mode, parent_mode=0o700)
|
|
642
|
+
if _trust_state(root) == "trusted":
|
|
643
|
+
return {"status": "failed", "reason": "切除后复读仍为 trusted(疑似并发改写)"}
|
|
644
|
+
try:
|
|
645
|
+
receipt_path.unlink()
|
|
646
|
+
except OSError:
|
|
647
|
+
pass
|
|
648
|
+
return {
|
|
649
|
+
"status": "removed",
|
|
650
|
+
"path": str(target),
|
|
651
|
+
"backup": str(backup) if backup else None,
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
def _sweep_legacy_json(root: Path) -> list[str]:
|
|
656
|
+
"""清扫旧的 ``.codex/config.json`` 死配置(Codex 从不加载它)。
|
|
657
|
+
|
|
658
|
+
仅在「整份内容都是 BugX 条目」时删除;任何用户自写字段/条目都保留原文件,
|
|
659
|
+
不猜归属。
|
|
660
|
+
"""
|
|
661
|
+
|
|
662
|
+
path = root / _CONFIG_DIR / _LEGACY_JSON
|
|
663
|
+
if path.is_symlink() or not path.is_file():
|
|
664
|
+
return []
|
|
665
|
+
try:
|
|
666
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
667
|
+
except (OSError, UnicodeError, ValueError):
|
|
668
|
+
return []
|
|
669
|
+
if not isinstance(payload, dict) or set(payload) - {"mcp_servers"}:
|
|
670
|
+
return []
|
|
671
|
+
servers = payload.get("mcp_servers")
|
|
672
|
+
if not isinstance(servers, dict) or not servers:
|
|
673
|
+
return []
|
|
674
|
+
if any(
|
|
675
|
+
not isinstance(spec, dict) or not _is_bugx_entry(name, spec)
|
|
676
|
+
for name, spec in servers.items()
|
|
677
|
+
):
|
|
678
|
+
return []
|
|
679
|
+
try:
|
|
680
|
+
path.unlink()
|
|
681
|
+
except OSError:
|
|
682
|
+
return []
|
|
683
|
+
return [f"{_CONFIG_DIR}/{_LEGACY_JSON}"]
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
def bootstrap_mcp(root: Path, servers: Mapping[str, Mapping[str, Any]]) -> dict[str, object]:
|
|
687
|
+
"""安装 BugX 固定的 MCP 条目(项目作用域,绝不改用户全局 MCP 表)。
|
|
688
|
+
|
|
689
|
+
三层缺一不可:
|
|
690
|
+
|
|
691
|
+
* ``$CODEX_HOME/config.toml`` 的 ``[projects."<root>"]``:**项目未受信任时
|
|
692
|
+
项目级配置整层被跳过**(见 :func:`ensure_project_trust`);
|
|
693
|
+
* ``.codex/config.toml``:**原生子 Agent 不继承父进程的 ``-c`` 覆盖**,项目级
|
|
694
|
+
配置才让 Worker 拿到 MCP;BugX 自有条目按最新定义原地更新,用户自有条目
|
|
695
|
+
冲突时拒绝覆盖;
|
|
696
|
+
* ``.bugx/state/host-mcp/codex.json``:运行期回执,供门禁复核「本次启动到底
|
|
697
|
+
写了什么」,不被宿主读取。
|
|
698
|
+
|
|
699
|
+
备份落 ``.bugx/backups/host-mcp/``(0600),写入走 ``secure_atomic``(同目录
|
|
700
|
+
临时文件 + ``os.replace``);解析失败/冲突一律抛错,不静默降级。
|
|
701
|
+
"""
|
|
702
|
+
|
|
703
|
+
import core.secure_atomic as secure_atomic
|
|
704
|
+
|
|
705
|
+
root = Path(root).resolve()
|
|
706
|
+
config_target = root / _CONFIG_DIR / "config.toml"
|
|
707
|
+
if config_target.is_symlink():
|
|
708
|
+
raise OSError(f"拒绝通过符号链接写入 Codex MCP 配置: {config_target}")
|
|
709
|
+
trust = ensure_project_trust(root)
|
|
710
|
+
config_text = _read_text(config_target)
|
|
711
|
+
try:
|
|
712
|
+
new_text, added, updated = mcp_toml.upsert_servers(
|
|
713
|
+
config_text, servers, owned=_is_bugx_entry, banner=_MCP_BANNER,
|
|
714
|
+
)
|
|
715
|
+
except ValueError as exc:
|
|
716
|
+
raise OSError(f"Codex MCP 配置写入被拒绝({config_target}): {exc}") from exc
|
|
717
|
+
config_changed = bool(added or updated)
|
|
718
|
+
config_backup: Path | None = None
|
|
719
|
+
created = not config_target.exists()
|
|
720
|
+
if config_changed:
|
|
721
|
+
config_backup = _backup_config(root, config_target, ".toml")
|
|
722
|
+
mode = config_target.stat().st_mode & 0o777 if config_target.exists() else 0o600
|
|
723
|
+
secure_atomic.atomic_write_text(
|
|
724
|
+
config_target, new_text, mode=mode, parent_mode=0o700,
|
|
725
|
+
)
|
|
726
|
+
legacy_removed = _sweep_legacy_json(root)
|
|
727
|
+
# 回执记录**生效态**(而不是本次是否发生写入),否则二跑会因「首次写了信任、
|
|
728
|
+
# 二次是 unchanged」而误报 changed,幂等断言形同虚设。
|
|
729
|
+
effective_trust = _trust_state(root)
|
|
730
|
+
|
|
731
|
+
receipt = root / ".bugx" / "state" / "host-mcp" / "codex.json"
|
|
732
|
+
try:
|
|
733
|
+
current: object = json.loads(receipt.read_text(encoding="utf-8"))
|
|
734
|
+
except (OSError, UnicodeError, ValueError):
|
|
735
|
+
current = None
|
|
736
|
+
# 归属证据必须**跨跑稳定**:首次写入时 created=True,二跑拿到的是 unchanged,
|
|
737
|
+
# 若照抄本次结果就会把归属洗成 False(卸载随即拒绝回收,信任条目永久残留)。
|
|
738
|
+
previous_created = False
|
|
739
|
+
if isinstance(current, dict):
|
|
740
|
+
previous_trust = current.get("trust")
|
|
741
|
+
previous_created = bool(
|
|
742
|
+
isinstance(previous_trust, dict) and previous_trust.get("created")
|
|
743
|
+
)
|
|
744
|
+
trust_created = bool(trust.get("created")) or (
|
|
745
|
+
previous_created and effective_trust == "trusted"
|
|
746
|
+
)
|
|
747
|
+
payload = {
|
|
748
|
+
"mcpServers": {name: dict(spec) for name, spec in servers.items()},
|
|
749
|
+
"scope": "project",
|
|
750
|
+
"managed": True,
|
|
751
|
+
# 只记**稳定事实**(路径 + 条目名)。本次的新增/更新属于一次性事件,写进
|
|
752
|
+
# 回执会让「二跑零写入」永远为假。
|
|
753
|
+
"config": {"path": str(config_target), "servers": sorted(servers)},
|
|
754
|
+
# ``created`` 是**归属证据**:卸载时只有它记录的条目才允许回收(见
|
|
755
|
+
# ``_forget_project_trust``)。它是稳定事实(一次写入后不再变化),不会
|
|
756
|
+
# 破坏「二跑零写入」。
|
|
757
|
+
"trust": {
|
|
758
|
+
"status": effective_trust,
|
|
759
|
+
"path": trust["path"],
|
|
760
|
+
"created": trust_created,
|
|
761
|
+
},
|
|
762
|
+
"legacy_removed": legacy_removed,
|
|
763
|
+
}
|
|
764
|
+
changed = current != payload
|
|
765
|
+
if changed:
|
|
766
|
+
secure_atomic.atomic_write_json(receipt, payload, mode=0o600)
|
|
767
|
+
return {
|
|
768
|
+
"host": _NAME,
|
|
769
|
+
"path": str(receipt),
|
|
770
|
+
"changed": changed,
|
|
771
|
+
"backup": str(config_backup) if config_backup else None,
|
|
772
|
+
"config_path": str(config_target),
|
|
773
|
+
"config_changed": config_changed,
|
|
774
|
+
"created": created,
|
|
775
|
+
"trust": trust["status"],
|
|
776
|
+
"trust_changed": trust["status"] == "trusted",
|
|
777
|
+
"trust_created": trust_created,
|
|
778
|
+
"trust_path": trust["path"],
|
|
779
|
+
"legacy_removed": legacy_removed,
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
def remove_mcp(root: Path) -> dict[str, object]:
|
|
784
|
+
"""卸载清理:项目 ``.codex/config.toml`` 条目 + **本工具新增**的用户级信任条目。
|
|
785
|
+
|
|
786
|
+
项目文件只由表块和横幅组成时整文件删除(避免留下空壳 ``.codex/config.toml``);
|
|
787
|
+
仍有用户配置时按表块精准切除,绝不重排用户内容。用户级信任条目按
|
|
788
|
+
:func:`_forget_project_trust` 的归属规则回收——只删本工具新增的那条,用户原有
|
|
789
|
+
偏好与显式 ``untrusted`` 一律保留(原因写进 ``preserved``,不静默跳过)。
|
|
790
|
+
"""
|
|
791
|
+
|
|
792
|
+
root = Path(root).resolve()
|
|
793
|
+
target = root / _CONFIG_DIR / "config.toml"
|
|
794
|
+
receipt_path = root / ".bugx" / "state" / "host-mcp" / "codex.json"
|
|
795
|
+
removed: list[str] = []
|
|
796
|
+
preserved: list[str] = []
|
|
797
|
+
rel = f"{_CONFIG_DIR}/config.toml"
|
|
798
|
+
if target.is_symlink() or not target.is_file():
|
|
799
|
+
preserved.append(f"{rel}(不存在或为符号链接:无项目级条目可清理)")
|
|
800
|
+
else:
|
|
801
|
+
text = _read_text(target)
|
|
802
|
+
names: list[str] = []
|
|
803
|
+
new_text = text
|
|
804
|
+
try:
|
|
805
|
+
new_text, names = mcp_toml.remove_servers(text, _is_bugx_entry)
|
|
806
|
+
except (ValueError, UnicodeError) as exc:
|
|
807
|
+
preserved.append(f"{rel}(无法解析:{exc})")
|
|
808
|
+
if not names:
|
|
809
|
+
preserved.append(f"{rel}(未发现 BugX 受管条目)")
|
|
810
|
+
else:
|
|
811
|
+
# 横幅只服务于「下面还有受管表块」;条目清空后它成了孤儿注释,一并清掉。
|
|
812
|
+
new_text = _strip_banner(new_text)
|
|
813
|
+
remaining = mcp_toml.validate(new_text) if new_text.strip() else {}
|
|
814
|
+
if not remaining:
|
|
815
|
+
try:
|
|
816
|
+
target.unlink()
|
|
817
|
+
except OSError as exc:
|
|
818
|
+
preserved.append(f"{rel}(删除失败:{exc})")
|
|
819
|
+
else:
|
|
820
|
+
removed.append(f"{rel}(已安全完全删除)")
|
|
821
|
+
else:
|
|
822
|
+
try:
|
|
823
|
+
target.write_text(new_text, encoding="utf-8")
|
|
824
|
+
except OSError as exc:
|
|
825
|
+
preserved.append(f"{rel}(写入失败:{exc})")
|
|
826
|
+
else:
|
|
827
|
+
removed.append(f"{rel}(移除 BugX MCP 服务器:{', '.join(sorted(names))})")
|
|
828
|
+
|
|
829
|
+
trust = _forget_project_trust(root, receipt_path)
|
|
830
|
+
if trust["status"] == "removed":
|
|
831
|
+
removed.append(f"{trust['path']}(回收本工具新增的项目信任条目:{root})")
|
|
832
|
+
elif trust["status"] == "failed":
|
|
833
|
+
preserved.append(f"Codex 用户级信任条目未回收:{trust['reason']}")
|
|
834
|
+
return {"removed": removed, "preserved": preserved, "trust": trust}
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
def inspect_project(root: Path, expected: tuple[str, ...] = ()) -> dict[str, object]:
|
|
838
|
+
"""只读诊断:项目 TOML 里的 BugX 条目 + 信任态(供 CLI ``validate_install``)。"""
|
|
839
|
+
|
|
840
|
+
root = Path(root).resolve()
|
|
841
|
+
target = root / _CONFIG_DIR / "config.toml"
|
|
842
|
+
trust = _trust_state(root)
|
|
843
|
+
try:
|
|
844
|
+
servers = mcp_toml.read_servers(_read_text(target))
|
|
845
|
+
except (ValueError, UnicodeError) as exc:
|
|
846
|
+
return {
|
|
847
|
+
"path": str(target),
|
|
848
|
+
"error": str(exc),
|
|
849
|
+
"servers": [],
|
|
850
|
+
"missing": list(expected),
|
|
851
|
+
"trust": trust,
|
|
852
|
+
}
|
|
853
|
+
present = [name for name, spec in servers.items() if _is_bugx_entry(name, spec)]
|
|
854
|
+
return {
|
|
855
|
+
"path": str(target),
|
|
856
|
+
"error": None,
|
|
857
|
+
"servers": present,
|
|
858
|
+
"missing": [name for name in expected if name not in servers],
|
|
859
|
+
"trust": trust,
|
|
860
|
+
"trust_path": str(_codex_home() / "config.toml"),
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
PLUGIN = HostPlugin(
|
|
865
|
+
identity=IdentityFacet(
|
|
866
|
+
name=_NAME,
|
|
867
|
+
label="Codex",
|
|
868
|
+
# 顺序即 ``host_registry.SUPPORTED_HOSTS`` 的展示顺序(opencode/claude/codex)。
|
|
869
|
+
order=2,
|
|
870
|
+
executable=_NAME,
|
|
871
|
+
markers=(
|
|
872
|
+
".codex/config.toml",
|
|
873
|
+
".agents/skills/bugx/SKILL.md",
|
|
874
|
+
_CONFIG_DIR,
|
|
875
|
+
),
|
|
876
|
+
aliases=(),
|
|
877
|
+
app_markers=None,
|
|
878
|
+
native_question=True,
|
|
879
|
+
),
|
|
880
|
+
status=STATUS_READY,
|
|
881
|
+
install=InstallFacet(
|
|
882
|
+
kind="skill",
|
|
883
|
+
# DOC-169:Codex 官方项目发现路径是 $CWD/.agents/skills。
|
|
884
|
+
path=".agents/skills/bugx/SKILL.md",
|
|
885
|
+
marker=_CONFIG_DIR,
|
|
886
|
+
# 旧 .codex/skills 为遗留清扫面:模板一致才删,用户改动保留。
|
|
887
|
+
legacy_paths=(".codex/skills/bugx/SKILL.md",),
|
|
888
|
+
capabilities=frozenset({"native-mcp-config"}),
|
|
889
|
+
interaction={
|
|
890
|
+
"tool": "request_user_input(Codex 交互宿主原生控件)",
|
|
891
|
+
"single_select": "questions 仅 1 个;原生控件单选;按 question id + 精确 label 映射稳定 value",
|
|
892
|
+
"availability": "通常为 Plan;Default 需显式启用对应实验特性且工具出现在当前工具列表",
|
|
893
|
+
"fallback": "BUGX_INTERACTION_REQUEST → Codex/ACP 外层;无承接者则阻断",
|
|
894
|
+
"failure": "控件失败时重问当前 gate;无控件且无 TTY 时阻断",
|
|
895
|
+
},
|
|
896
|
+
worker_subagent=False,
|
|
897
|
+
# 原 ``common._SWEEPABLE_SKILL_ADAPTERS`` 成员:入口按 Skill 语义整体清扫。
|
|
898
|
+
sweepable=True,
|
|
899
|
+
),
|
|
900
|
+
engine_run=EngineRunFacet(
|
|
901
|
+
supports_headless=True,
|
|
902
|
+
headless_argv=_headless_argv,
|
|
903
|
+
autonomous_argv=_autonomous_argv,
|
|
904
|
+
mcp_config_paths=_config_paths,
|
|
905
|
+
agent_config_path=_agent_config_path,
|
|
906
|
+
mcp_health=_mcp_health,
|
|
907
|
+
host_surface="tui",
|
|
908
|
+
# Recon Scout:一次性只读语义复核(见 ``recon_scout_command``)。
|
|
909
|
+
recon_scout_argv=lambda root, prompt_text, _prompt_file, inventory=None: (
|
|
910
|
+
recon_scout_command(root, prompt_text, inventory)
|
|
911
|
+
),
|
|
912
|
+
# 侦察前先向 CLI 查有效 MCP 清单,逐个 -c enabled=false;执行留在引擎侧
|
|
913
|
+
# (插件不得 import subprocess),这里只声明命令与结果键。
|
|
914
|
+
recon_scout_inventory=_scout_inventory_command,
|
|
915
|
+
# Codex 有原生 ``collaboration.spawn_agent``(multi_agent_v2):Worker 由
|
|
916
|
+
# 宿主派发,禁止 ``workers --execute`` 进程池代跑。
|
|
917
|
+
native_task=True,
|
|
918
|
+
),
|
|
919
|
+
worker_runtime=WorkerRuntimeFacet(
|
|
920
|
+
mode="multi",
|
|
921
|
+
max_concurrency=None,
|
|
922
|
+
requires_process_mode=False,
|
|
923
|
+
sandbox_sync=(),
|
|
924
|
+
),
|
|
925
|
+
mcp_write=McpWriteFacet(
|
|
926
|
+
container_key="mcp_servers",
|
|
927
|
+
writer_key=_NAME,
|
|
928
|
+
# Codex 只加载 ``.codex/config.toml``(0.163 实测 ``config.json`` 永不被读)。
|
|
929
|
+
project_relpath=".codex/config.toml",
|
|
930
|
+
# 全局作用域:``$CODEX_HOME/config.toml``(ensure_global_mcp,相对
|
|
931
|
+
# ``--root .`` 绑定项目 cwd;engine root 自愈兜底)。
|
|
932
|
+
global_scope="~/.codex/config.toml",
|
|
933
|
+
mirror_relpaths=(),
|
|
934
|
+
requires_absolutize=True,
|
|
935
|
+
config_format="toml",
|
|
936
|
+
bootstrap=bootstrap_mcp,
|
|
937
|
+
remove=remove_mcp,
|
|
938
|
+
inspect=inspect_project,
|
|
939
|
+
),
|
|
940
|
+
acp=AcpFacet(plugin=_NAME),
|
|
941
|
+
usage=UsageFacet(
|
|
942
|
+
plugin=_NAME,
|
|
943
|
+
module="_codex_usage",
|
|
944
|
+
state_filename="codex-usage.json",
|
|
945
|
+
notes="Read-only local thread index and identity-filtered JSONL usage; unknown values remain null.",
|
|
946
|
+
),
|
|
947
|
+
)
|
|
948
|
+
|