bugx-cli 0.1.1__py3-none-any.whl
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.
- bugx_cli/__init__.py +6 -0
- bugx_cli/cli.py +1685 -0
- bugx_cli/commands/__init__.py +1 -0
- bugx_cli/commands/advisory.py +94 -0
- bugx_cli/commands/agent.py +4210 -0
- bugx_cli/commands/audit.py +632 -0
- bugx_cli/commands/autonomous.py +260 -0
- bugx_cli/commands/cloud.py +1371 -0
- bugx_cli/commands/daemon.py +50 -0
- bugx_cli/commands/doctor.py +1590 -0
- bugx_cli/commands/goal.py +107 -0
- bugx_cli/commands/interaction.py +248 -0
- bugx_cli/commands/knowledge.py +619 -0
- bugx_cli/commands/lifecycle.py +2763 -0
- bugx_cli/commands/patch.py +1014 -0
- bugx_cli/commands/plugin.py +2749 -0
- bugx_cli/commands/plugin_claude.py +1446 -0
- bugx_cli/commands/plugin_cline.py +269 -0
- bugx_cli/commands/plugin_codex.py +74 -0
- bugx_cli/commands/plugin_funide.py +729 -0
- bugx_cli/commands/plugin_qoder.py +216 -0
- bugx_cli/commands/plugin_zcode.py +710 -0
- bugx_cli/commands/project.py +670 -0
- bugx_cli/commands/report.py +256 -0
- bugx_cli/commands/skill.py +251 -0
- bugx_cli/commands/stats.py +133 -0
- bugx_cli/commands/system.py +2567 -0
- bugx_cli/common.py +906 -0
- bugx_cli/host_adapters.py +1892 -0
- bugx_cli/hosts/__init__.py +80 -0
- bugx_cli/hosts/base.py +99 -0
- bugx_cli/hosts/registry.py +573 -0
- bugx_cli/hosts/template_engine.py +188 -0
- bugx_cli/infra/__init__.py +209 -0
- bugx_cli/infra/ai_advisor.py +851 -0
- bugx_cli/infra/engine_installer.py +1945 -0
- bugx_cli/infra/host_sync.py +548 -0
- bugx_cli/infra/mcp_advisor.py +826 -0
- bugx_cli/infra/security.py +339 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/bugx-mcp-manifest.json +53 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/CATALOG.json +141 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/README.md +254 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/README.md +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/android-interaction.json +81 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/android.json +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/desktop-macos.json +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/ios-interaction.json +34 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/ios.json +23 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/memory-macos.json +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/README.md +51 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/__init__.py +146 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_artifacts.py +766 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_eval.py +1155 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_execution.py +718 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_orchestrator.py +1351 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_targets.py +877 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_workspace.py +770 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/feature_baseline.py +150 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/README.md +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/LICENSE.txt +362 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/UPSTREAM.md +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/axe.min.js +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar-1024.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar-512.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar-tight.svg +23 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar.svg +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-cn.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-en.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-en.svg +74 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-zh.svg +74 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/codex.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/dsh.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/project-layout.md +42 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/zcode.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/README.md +37 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/manifest.json +94 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/00-scope.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/10-schema-inventory.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/20-query-and-integrity.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/80-evidence-regression.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/manifest.json +123 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/00-scope.md +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/10-process-model.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/20-package-integrity.md +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/30-ui-behavior.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/80-evidence-regression.md +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/memory-testing.md +227 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/manifest.json +155 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/android.md +19 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/h5.md +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/ios.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/miniprogram.md +26 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/webview.md +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/00-scope.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/10-platform-inventory.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/20-masvs-static.md +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/30-component-exposure.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/40-device-behavior.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/80-evidence-regression.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/manifest.json +127 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/00-scope.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/10-static-white-box.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/20-memory-concurrency.md +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/30-behavior-black-box.md +39 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/80-evidence-regression.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/platform-testing.md +174 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/manifest.json +191 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/graphql.md +5 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/h5.md +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/multi-tenant.md +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/oauth.md +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/upload.md +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/websocket.md +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/00-scope.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/10-discovery.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/20-auth-session.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/30-authz-business.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/40-input-output.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/50-state-async.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/60-file-ssrf-deser.md +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/70-config-dependency.md +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/80-evidence-regression.md +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/INTERFACE.md +61 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/README.md +58 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/__init__.py +109 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/attack_graph.py +1096 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/attack_graph_store.py +1868 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/audit_campaign.py +1232 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/behavior_graph.py +465 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/ghsa_advisories.py +174 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/models.py +93 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/mutator.py +87 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/patcher.py +126 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/scout.py +278 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/synthesizer.py +207 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/verifier.py +103 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/bugx.md +1299 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/bugx_paths.py +1881 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cli-help.txt +66 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/INTERFACE.md +32 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/README.md +62 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/__init__.py +23 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/auto_sync.py +398 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/cloud_client.py +1218 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/cloud_onboard.py +743 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/cloud_schema.py +648 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/consent.py +81 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/device_identity.py +307 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/endpoint_router.py +415 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/flywheel_client.py +769 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/network_transport.py +296 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/onboard_wizard.py +493 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/sensitive_filter.py +285 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/sync_pull.py +695 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/sync_push.py +723 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/AGENT_GUIDE.md +359 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/README.md +34 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-blackbox.md +541 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-opencode.md +469 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-quick.md +44 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-runtime-contract.md +353 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-worker.md +470 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/engine_gap_contracts.py +473 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/README.md +70 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/__init__.py +106 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_ai_review.py +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_backfill.py +54 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_bootstrap.py +713 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_business.py +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_cli.py +715 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_discovery.py +1429 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_evidence.py +1024 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_forensics.py +124 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_gate.py +277 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_intelligence.py +734 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_manifest.py +396 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_platform.py +77 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_validate.py +241 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/module_coverage.py +157 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/INTERFACE.md +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/README.md +21 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/__init__.py +5 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/interaction_preset.py +408 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/engine-integrity.json +2797 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/README.md +49 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/__init__.py +82 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/concurrency_fuzzer.py +435 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/differential_oracle.py +1164 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/fuzz_input.py +1291 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/stateful_fuzzer.py +404 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/README.md +61 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/__init__.py +130 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/capacity_planner.py +124 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/dependency_lock.py +317 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/goal_governor.py +754 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/guide_budget.py +458 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/lockdown.sh +50 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/readonly_enforcer.py +154 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/runtime_tool_gate.py +373 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/secret_redactor.py +784 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/token_budget.py +38 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/INTERFACE.md +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/README.md +51 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/__init__.py +121 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/base.py +111 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/claude.py +99 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/cline.py +298 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/codex.py +300 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/dsh.py +106 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/opencode.py +209 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/pi.py +94 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/zcode.py +99 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/INTERFACE.md +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/README.md +62 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/__init__.py +21 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/adapters.py +412 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/autonomous_runner.py +1152 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/cline.py +448 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/common.py +103 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/free_models.py +786 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_bootstrap.py +389 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_evaluators.py +761 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_probe.py +41 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_provider_arbitrator.py +831 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_registry.py +662 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_usage.py +127 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/mcp_process_tracker.py +509 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/mcp_registry_gate.py +379 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/pi.py +102 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/provider_facts.py +66 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/INTERFACE.md +51 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/README.md +67 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/__init__.py +140 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_base_usage.py +152 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_codex_usage.py +297 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_dsh_usage.py +184 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_mcp_toml.py +365 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_zcode_usage.py +269 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/base.py +479 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/claude.py +212 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/cline.py +229 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/codex.py +1006 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/dsh.py +526 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/opencode.py +358 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/pi.py +308 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/zcode.py +219 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/i18n.py +252 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/README.md +41 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/__init__.py +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/build_info.py +105 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/client_metadata.py +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/json_utils.py +22 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/python_runtime.py +540 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/safe_xml.py +221 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_bugx.py +118 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/INTERFACE.md +31 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/README.md +106 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/__init__.py +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/candidate_revalidation.py +484 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/common.py +1060 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/finding_confirm_phase.py +391 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/finding_settlement.py +1432 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/findings_adjudication.py +666 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/findings_snapshot.py +357 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/judge_phase.py +848 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/lesson_context.py +536 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/lifecycle_reporter.py +627 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/orchestrator_controls.py +686 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_commit.py +567 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_coverage_sync.py +598 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_dry_run.py +817 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_observability.py +367 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_phase.py +1223 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_receipt.py +373 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_round_lifecycle.py +786 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/pre_phase.py +1029 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/pre_recon_scout.py +879 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/pre_state_builder.py +1133 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/report_sharing.py +414 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/round_orchestrator.py +1116 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/session_runtime.py +1670 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/startup_gates.py +1050 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/startup_interaction.py +1003 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/startup_version_gate.py +879 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/supervisor_bridge.py +1253 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/supervisor_coverage.py +423 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/supervisor_degraded.py +1211 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/worker_barriers.py +424 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/worker_orchestrator.py +1246 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/worker_prior.py +749 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/INTERFACE.md +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/README.md +160 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/__init__.py +67 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/_facade.py +227 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/archive_ops.py +630 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/auto_materialization.py +459 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/bug-log.md +22 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/cli.py +275 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/export_ops.py +554 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_confirmation.py +1316 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_io.py +299 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_lifecycle.py +730 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_verification.py +405 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/incidents.py +1005 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/lesson-replay-cases.json +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/lesson_ledger.py +241 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/lesson_replay.py +272 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/life_ledger.py +668 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/mistake-book.md +130 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/patterns.py +684 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/receipt_contract.py +269 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/schema.py +1192 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/sync_ops.py +940 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/tool_experience.py +683 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/verify_life.py +1597 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/lesson-ledger.json +275 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/locales/README.md +19 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/locales/en-US.json +462 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/locales/zh-CN.json +462 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/INTERFACE.md +75 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/README.md +62 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/__init__.py +128 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/base.py +717 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/channel_lifecycle.py +751 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/graph_handlers.py +222 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/knowledge_handlers.py +536 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/mining_handlers.py +586 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/resource_prompt_table.py +116 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/retrieval_handlers.py +249 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/rpc_server.py +470 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/supervisor_handlers.py +1461 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/telemetry_handlers.py +227 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/tool_table.py +1030 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/README.md +21 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/__init__.py +1 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/common.py +363 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/environment.py +567 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/verifier.py +758 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/metadata.txt +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/README.md +157 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/__init__.py +242 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/capability_plan.py +187 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/capability_planner.py +195 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/domain_archetype.py +542 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/domain_router.py +269 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/dynamic_flow_analyzer.py +533 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/impact_pruner.py +435 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/intent_adjudicator.py +175 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/judge_pipeline.py +1246 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/logic_analysis.py +419 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/prompt_harness.py +1704 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/source_inspector.py +267 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/spec_harvester.py +449 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/target_sandbox_manager.py +573 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/test_capability_verifier.py +1364 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/tools-kb.md +38 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/unit_kind.py +122 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/INTERFACE.md +83 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/README.md +51 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/SPEC.md +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/__init__.py +76 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/android_probe.py +552 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/base.py +147 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/codebase_memory_probe.py +647 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/desktop_probe.py +342 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/differential_probe.py +434 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/efficiency_probe.py +232 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ios_binary_probe.py +472 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/memory_probe.py +392 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/miniprogram_probe.py +385 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/mobile_probe.py +466 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/native_probe.py +302 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/openwiki_probe.py +263 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/pattern_probe.py +453 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/platform_probe.py +424 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/probe_registry.py +1770 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sast_fixture_corpus.py +340 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sast_probe.py +1510 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sast_rules.py +1481 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sca_scanner.py +779 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_accessibility.py +149 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_audit.py +513 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_contract.py +273 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_evidence.py +212 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_measurements.py +314 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_repair.py +250 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_review.py +133 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_storybook.py +107 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_tokens.py +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_visual_diff.py +131 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/web_probe.py +714 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/INTERFACE.md +62 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/README.md +53 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/SPEC.md +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/__init__.py +201 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/arbitrator.py +316 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/constants.py +247 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/detector.py +399 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/extractors.py +836 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/fingerprint.py +116 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/storage.py +258 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/strategy.py +301 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/README.md +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/codex_dialog_dispatch.md +9 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/command_routing_en.md +42 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/command_routing_zh.md +42 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/l0_router.md +47 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/anti_patterns.md +16 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/concurrency_rules.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/memory_leak_rules.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/prompt_injection_defense.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_explore.md +31 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_gate.md +43 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_mutate.md +42 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_repair.md +85 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/README.md +74 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/__init__.py +169 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/fix_watchlist.py +391 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/l7_dynamic.py +418 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/l7_repair_loop.py +462 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/l7_selfcheck.py +862 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/minimize_repro.py +466 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/patch_synthesizer.py +617 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/regression_pack.py +379 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_fixer.py +910 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_loop.py +311 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_repair.py +348 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_rounds.py +212 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_scope.py +281 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/self_heal.py +604 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/test_generator.py +1108 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/test_quality_auditor.py +410 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/test_strategy.py +511 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/INTERFACE.md +59 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/README.md +69 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/SPEC.md +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/__init__.py +47 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/attestation.py +228 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/authority.py +255 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/finding_report.py +418 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/formal_report_builder.py +924 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/html_renderers.py +696 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/models.py +759 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/pdf_exporter.py +231 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/projects_assets.py +730 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/report_client.py +743 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/report_data_builder.py +388 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/report_share.py +459 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/sast_bridge.py +116 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/server.py +832 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/visual_report_builder.py +796 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/web-conformance.md +168 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/web_conformance.py +428 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/workbench_assets.py +484 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/INTERFACE.md +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/README.md +161 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/__init__.py +3 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/code_analyzer.py +1720 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/codebase_memory_bridge.py +337 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/context_assembler.py +240 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/corpus_fetch.py +369 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/graph_ego.py +597 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/knowledge_auto.py +662 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/knowledge_sources.py +168 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/knowledge_sync.py +1003 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/memory_store.py +480 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/query_planner.py +1020 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/rrf_engine.py +137 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/slice_extractor.py +1209 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/slice_normalizer.py +373 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/slice_spec.py +357 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/symbol_index.py +1151 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/universal_code_matcher.py +622 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/xerj_bridge.py +476 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/xerj_supervisor.py +362 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/README.md +33 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/PROVENANCE.json +30 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/crypto.yaml +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/network.yaml +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/resilience.yaml +47 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/storage.yaml +48 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/LICENSE +173 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/PROVENANCE.json +270 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-asymmetric-key-pair-used-for-multiple-purposes.yml +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-backup-manifest.yml +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-event-bound.yml +49 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-invalidated-enrollment.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-no-confirmation-required.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-validity-duration.yml +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-broken-encryption-algorithms.yaml +9 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-broken-encryption-modes.yaml +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-content-provider-exported.yml +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-custom-deeplink-scheme.yml +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-dangerous-app-permissions.yaml +65 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-apis.yml +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-manifest.yml +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-debuggable-flag.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-debugger-checks.yml +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-deeplink-autoverify-missing.yml +33 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-deeplink-unvalidated-parameter.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-device-passcode-present.yml +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-fileprovider-broad-scope.yml +46 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-hardcoded-crypto-keys-usage.yml +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-hardcoded-security-provider.yaml +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-implicit-intent-internal-communication.yml +30 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-implicit-intent-leaking-extras.yml +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-input-field-usage.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-key-generation-with-insufficient-key-length.yml +21 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-keyboard-cache-input-types.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-local-storage-input-validation.yml +48 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-native-debugger-checks.yml +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-checkservertrusted.yml +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-hostname-verification.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-insecure-trust-anchors.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-onreceivedsslerror.yml +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-non-random-use.yml +16 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-object-deserialization.yml +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-overlay-protection.yml +68 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-pendingintent-mutable.yml +39 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-random-apis-insufficient-entropy.yml +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-root-detection.yaml +59 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sdk-version.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sensitive-data-in-notifications-manifest.yml +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sensitive-data-in-notifications.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sensitive-data-in-screenshot.yml +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sql-injection-contentprovider.yml +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-ssl-socket-hostnameverifier.yml +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-strictmode.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-system-alert-window.yml +9 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-allow-local-access.yml +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-bridges.yml +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-safebrowsing.yml +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-url-handlers.yml +41 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/PROVENANCE.json +26 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/network.yaml +37 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/platform.yaml +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/storage.yaml +48 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/LICENSE +165 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/PROVENANCE.json +58 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/auth.yaml +59 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/crypto.yaml +66 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/jailbreak.yaml +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/keyboard.yaml +34 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/logging.yaml +23 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/network.yaml +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/resilience.yaml +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/secrets.yaml +33 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/storage.yaml +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/webview.yaml +32 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/README.md +198 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/__init__.py +3 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/bugx_logging.py +1464 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/daemon_runner.py +623 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/fixture_solidify.py +444 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/global_telemetry.py +549 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/incident_eval.py +148 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/interaction.py +605 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/interaction_store.py +435 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/interactive_menu.py +95 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/log_analytics.py +922 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/mining_quality_framework.py +1387 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/model_runner.py +732 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/platform_adapter.py +579 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/prep_validate.py +478 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_graph.py +827 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_init.py +481 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_profile.py +224 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_settings.py +964 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/provider_window.py +97 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/resume_ticket.py +115 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/scenario_eval.py +856 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/seed_drill.py +549 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/self_audit.py +550 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/session_profile.py +205 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/setup_ui_env.py +229 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/startup_environment.py +859 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/sync_store.py +1421 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/tool_install_targets.py +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/README.md +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/agent-graph.schema.json +368 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/attack-graph.schema.json +88 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/evidence-bundle.schema.json +33 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/skill-pack.schema.json +230 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/worker-checkpoint.schema.json +119 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/secure_atomic.py +289 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/README.md +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/c.txt +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/cpp.txt +32 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/css.txt +70 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/go.txt +46 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/java.txt +30 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/javascript.txt +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/kotlin.txt +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/python.txt +71 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/rust.txt +53 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/swift.txt +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/typescript.txt +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/README.md +53 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/__init__.py +189 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/bugx_docs_mcp_server.py +418 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/bugx_mcp_server.py +1161 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/mcp_runtime.py +968 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/mcp_session_proof.py +605 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/mobile_ui_inspector.py +405 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/skill_pack.py +1214 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/skill_synthesizer.py +1153 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/tools_kb.py +313 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/INTERFACE.md +121 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/README.md +209 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/__init__.py +175 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/audit_supervisor.py +1015 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/budget_governor.py +1254 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/checkpoint_handler.py +368 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/checkpoint_pipeline.py +1564 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/checkpoint_sync.py +653 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/claim_events.py +74 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/claim_sync.py +590 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/cli.py +812 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/context_sync.py +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/coverage_sync.py +115 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finding_commit.py +470 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finding_sync.py +688 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finding_workflow.py +676 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finish_policy.py +224 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finish_sync.py +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/graph_sync.py +669 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/lease_manager.py +788 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/lifecycle_blocks.py +129 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/next_round_sync.py +126 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/observability.py +140 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/recovery_sync.py +165 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/rejection_remedies.py +355 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/round_governor.py +306 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/serial_authorization.py +544 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/start_sync.py +87 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/state_store.py +249 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/supervisor_host.py +511 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/supervisor_models.py +1143 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/systemic_failure.py +104 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/task_scheduler.py +1640 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_checkpoint.py +230 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_execution.py +265 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_handoff.py +192 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_lifecycle.py +396 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_runtime.py +1005 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_sync.py +89 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/README.md +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/__init__.py +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/exceptions.py +52 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/graph_models.py +357 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/path_containment.py +151 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/target_fingerprint.py +310 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/worker_claim.py +411 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/INTERFACE.md +50 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/README.md +57 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/SPEC.md +26 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/__init__.py +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/__init__.py +27 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/base.py +87 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/bugx.py +102 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/claude.py +222 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/cline.py +407 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/codex.py +260 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/dsh.py +177 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/opencode.py +218 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/pi.py +272 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/registry.py +100 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/zcode.py +312 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/api_routes_post.py +668 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/dispatcher.py +1376 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/docs_session_service.py +473 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/handler.py +674 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/ide_cloud_service.py +526 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/mcp_inspector.py +1747 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/00-base.css +1060 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/01-monitoring.css +802 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/02-header-actions.css +321 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/03-trigger-popover.css +697 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/04-composer.css +628 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/05-skills-center.css +878 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/06-mcp-center.css +623 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/07-skill-detail.css +265 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/08-files-management.css +167 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/09-files-center.css +386 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/10-icons.css +105 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/11-project-options.css +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/12-profile-tab.css +383 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/index-CXAsl8mr.js +333 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/index-DHQUtWtx.css +1 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-400-normal-B8Z6Jvzv.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-400-normal-C44pakCn.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-500-normal-Bb4u56_6.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-500-normal-BdVUvljg.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-CWV284fw.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-DLkyKLvH.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-8-8HP2PF.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-DaDZE_Na.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-400-normal-BccYJ-vZ.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-400-normal-Cw5-AHNN.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-500-normal-By8GFJzz.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-500-normal-z-Q6FFuG.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-400-normal-DJ5YJwmz.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-400-normal-Dn3IlU-Z.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-500-normal-CUHe9xxf.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-500-normal-DVVamBqs.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-400-normal-CEpydyUl.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-400-normal-Cp7z-ARB.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-500-normal-BYjRCDVy.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-500-normal-D-qasQTj.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-400-normal-BbG3LG1A.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-400-normal-DR1UuFon.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-500-normal-8N8MYVKB.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-500-normal-Bi3OSTTW.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/design-tokens.css +113 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/favicon.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/icon-192.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/index.html +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/manifest.webmanifest +19 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/project-settings.js +9602 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/sw.js +8 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/workspace_service.py +218 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/agents/bugx.md +27 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/dsh-patch.yml +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/mcp/cordis.patch.yml +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/mcp/index.js +219 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/mcp/package.json +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/skills/bugx/SKILL.md +70 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/skills/bugx-dsh/SKILL.md +229 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/client.js +87 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/cordis.patch.yml +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/index.js +7 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/package.json +27 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/mcp-lock.json +3075 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/opencode.json +129 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/pi/extensions/bugx/README.md +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/pi/extensions/bugx/index.ts +299 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/pi/extensions/bugx/manifest.json +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/pi/skills/bugx/SKILL.md +69 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/plugins/bugx/skills/bugx-claude/SKILL.md +326 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/plugins/bugx/skills/bugx-opencode/SKILL.md +129 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/plugins/bugx/skills/bugx-zcode/SKILL.md +459 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/workbuddy/connector-meta.json +19 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/workbuddy/icon.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/workbuddy/skills/bugx/SKILL.md +70 -0
- bugx_cli-0.1.1.dist-info/METADATA +335 -0
- bugx_cli-0.1.1.dist-info/RECORD +762 -0
- bugx_cli-0.1.1.dist-info/WHEEL +5 -0
- bugx_cli-0.1.1.dist-info/entry_points.txt +2 -0
- bugx_cli-0.1.1.dist-info/licenses/LICENSE +55 -0
- bugx_cli-0.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,2749 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import copy
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import re
|
|
9
|
+
import shutil
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
import tempfile
|
|
13
|
+
import time
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from .. import __version__
|
|
18
|
+
from ..common import *
|
|
19
|
+
from ..host_adapters import HOST_ADAPTERS
|
|
20
|
+
from ..hosts.registry import (
|
|
21
|
+
engine_host_label,
|
|
22
|
+
engine_host_mcp_config_paths,
|
|
23
|
+
engine_host_mcp_write,
|
|
24
|
+
engine_host_plugins,
|
|
25
|
+
sweepable_skill_adapter_names,
|
|
26
|
+
)
|
|
27
|
+
from ..hosts.template_engine import interaction_protocol
|
|
28
|
+
from .plugin_zcode import (
|
|
29
|
+
_ensure_zcode_plugin,
|
|
30
|
+
_ensure_zcode_user_agents,
|
|
31
|
+
_sweep_legacy_zcode_project_entries,
|
|
32
|
+
_zcode_config_path,
|
|
33
|
+
_zcode_workspace_mcp_config_path,
|
|
34
|
+
_zcode_plugin_agent_content,
|
|
35
|
+
_zcode_plugin_boundary_section,
|
|
36
|
+
_zcode_plugin_manifest,
|
|
37
|
+
_zcode_plugin_worker_content,
|
|
38
|
+
_zcode_storage_dir_override,
|
|
39
|
+
_zcode_user_agent_boundary,
|
|
40
|
+
_zcode_user_agent_content_main,
|
|
41
|
+
_zcode_user_agent_content_worker,
|
|
42
|
+
_zcode_user_agents_dir,
|
|
43
|
+
command_plugin_zcode,
|
|
44
|
+
_ensure_zcode_user_skill,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _i18n_exc(key: str, fallback: str, locale: str | None = None, **kwargs: Any) -> str:
|
|
49
|
+
try:
|
|
50
|
+
_ensure_core_importable()
|
|
51
|
+
import core.i18n as i18n
|
|
52
|
+
return i18n.exception_text(key, locale=locale, fallback=fallback, **kwargs)
|
|
53
|
+
except Exception:
|
|
54
|
+
if not kwargs:
|
|
55
|
+
return fallback
|
|
56
|
+
try:
|
|
57
|
+
return fallback.format(**kwargs)
|
|
58
|
+
except Exception:
|
|
59
|
+
return fallback
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _i18n_prompt(key: str, fallback: str, locale: str | None = None, **kwargs: Any) -> str:
|
|
63
|
+
try:
|
|
64
|
+
_ensure_core_importable()
|
|
65
|
+
import core.i18n as i18n
|
|
66
|
+
return i18n.prompt_text(key, locale=locale, fallback=fallback, **kwargs)
|
|
67
|
+
except Exception:
|
|
68
|
+
if not kwargs:
|
|
69
|
+
return fallback
|
|
70
|
+
try:
|
|
71
|
+
return fallback.format(**kwargs)
|
|
72
|
+
except Exception:
|
|
73
|
+
return fallback
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _resolve_locale_name(locale: str | None = None) -> str:
|
|
77
|
+
if locale:
|
|
78
|
+
return locale
|
|
79
|
+
try:
|
|
80
|
+
_ensure_core_importable()
|
|
81
|
+
import core.i18n as i18n
|
|
82
|
+
return i18n.resolve_locale().resolved_locale
|
|
83
|
+
except Exception:
|
|
84
|
+
return "zh-CN"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def command_plugin(args: argparse.Namespace) -> int:
|
|
88
|
+
"""Discover or explicitly install a private BugX plugin."""
|
|
89
|
+
root = args.root.resolve()
|
|
90
|
+
if args.plugin_command == "zcode":
|
|
91
|
+
return command_plugin_zcode(args)
|
|
92
|
+
if args.plugin_command == "list":
|
|
93
|
+
store = _plugin_store(root)
|
|
94
|
+
payload = []
|
|
95
|
+
for manifest_path in sorted(store.glob("*/plugin.json")):
|
|
96
|
+
try:
|
|
97
|
+
_, manifest = _plugin_manifest(manifest_path.parent, validate_payload=False)
|
|
98
|
+
except CliError:
|
|
99
|
+
continue
|
|
100
|
+
installed_agent = _installed_plugin_agent(root, manifest)
|
|
101
|
+
loaded = bool(installed_agent and installed_agent.is_file())
|
|
102
|
+
payload.append({"name": manifest["name"], "version": manifest["version"],
|
|
103
|
+
"autoload": manifest["autoload"], "private": manifest["private"],
|
|
104
|
+
"loaded": loaded})
|
|
105
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2) if args.json else
|
|
106
|
+
"\n".join(f"{item['name']}\tloaded={item['loaded']}\tautoload={item['autoload']}"
|
|
107
|
+
for item in payload))
|
|
108
|
+
return 0
|
|
109
|
+
if args.plugin_command == "status":
|
|
110
|
+
if not args.plugin_name:
|
|
111
|
+
raise CliError(_i18n_exc("plugin.status_missing_name", "plugin status 必须提供插件名称"))
|
|
112
|
+
plugin_path = _plugin_store(root) / args.plugin_name
|
|
113
|
+
if not (plugin_path / "plugin.json").is_file():
|
|
114
|
+
payload = {"name": args.plugin_name, "loaded": False, "root": str(root)}
|
|
115
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2) if args.json else
|
|
116
|
+
f"{args.plugin_name}: NOT_LOADED")
|
|
117
|
+
return 0
|
|
118
|
+
_, manifest = _plugin_manifest(
|
|
119
|
+
plugin_path, args.plugin_name, validate_payload=False,
|
|
120
|
+
)
|
|
121
|
+
installed_agent = _installed_plugin_agent(root, manifest)
|
|
122
|
+
loaded = bool(installed_agent and installed_agent.is_file())
|
|
123
|
+
payload = {
|
|
124
|
+
"name": manifest["name"], "version": manifest["version"],
|
|
125
|
+
"loaded": loaded, "autoload": manifest["autoload"],
|
|
126
|
+
"private": manifest["private"], "root": str(root),
|
|
127
|
+
}
|
|
128
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2) if args.json else
|
|
129
|
+
f"{manifest['name']}: {'LOADED' if loaded else 'INCOMPLETE'}")
|
|
130
|
+
return 0
|
|
131
|
+
if args.plugin_command == "uninstall":
|
|
132
|
+
if not args.plugin_name:
|
|
133
|
+
raise CliError(_i18n_exc("plugin.uninstall_missing_name", "plugin uninstall 必须提供插件名称"))
|
|
134
|
+
if not args.yes:
|
|
135
|
+
raise CliError(_i18n_exc("plugin.uninstall_requires_yes", "plugin uninstall 需要显式提供 --yes;卸载前会备份 BugX 文件"))
|
|
136
|
+
plugin_path = _plugin_store(root) / args.plugin_name
|
|
137
|
+
manifest_path = plugin_path / "plugin.json"
|
|
138
|
+
if not manifest_path.is_file() or manifest_path.is_symlink():
|
|
139
|
+
payload = {"status": "NOT_FOUND", "name": args.plugin_name, "removed": []}
|
|
140
|
+
not_found_msg = _i18n_prompt("plugin.not_found", f"[bugx] 未找到插件 {args.plugin_name}", name=args.plugin_name)
|
|
141
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2) if args.json else not_found_msg)
|
|
142
|
+
return 0
|
|
143
|
+
|
|
144
|
+
_, manifest = _plugin_manifest(plugin_path, args.plugin_name, validate_payload=False)
|
|
145
|
+
removed: list[str] = []
|
|
146
|
+
preserved: list[str] = []
|
|
147
|
+
marker = plugin_path / ".bugx-install.json"
|
|
148
|
+
marker_payload: dict[str, object] = {}
|
|
149
|
+
if marker.is_file() and not marker.is_symlink():
|
|
150
|
+
try:
|
|
151
|
+
loaded = json.loads(marker.read_text(encoding="utf-8"))
|
|
152
|
+
if isinstance(loaded, dict):
|
|
153
|
+
marker_payload = loaded
|
|
154
|
+
except (OSError, json.JSONDecodeError):
|
|
155
|
+
preserved.append(str(marker.relative_to(root)) + "(安装记录无法解析)")
|
|
156
|
+
for record in marker_payload.get("files", []):
|
|
157
|
+
_remove_owned_record(root, record, f"plugin-{args.plugin_name}", removed, preserved)
|
|
158
|
+
manifest_record = marker_payload.get("manifest")
|
|
159
|
+
if manifest_record is None:
|
|
160
|
+
preserved.append(str(manifest_path.relative_to(root)) + "(旧版安装缺少哈希记录)")
|
|
161
|
+
else:
|
|
162
|
+
_remove_owned_record(
|
|
163
|
+
root, manifest_record, f"plugin-{args.plugin_name}", removed, preserved,
|
|
164
|
+
)
|
|
165
|
+
if marker.is_file() and not marker.is_symlink():
|
|
166
|
+
_remove_owned_record(
|
|
167
|
+
root,
|
|
168
|
+
{"path": _relative_project_file(root, marker), "sha256": _sha256_file(marker)},
|
|
169
|
+
f"plugin-{args.plugin_name}", removed, preserved,
|
|
170
|
+
)
|
|
171
|
+
_remove_empty_parents(root, removed)
|
|
172
|
+
payload = {
|
|
173
|
+
"status": "UNINSTALLED", "name": manifest["name"],
|
|
174
|
+
"removed": removed, "preserved": preserved,
|
|
175
|
+
}
|
|
176
|
+
msg = _i18n_prompt(
|
|
177
|
+
"plugin.uninstalled",
|
|
178
|
+
f"[bugx] 已卸载插件 {manifest['name']};删除 {len(removed)} 个文件,保留 {len(preserved)} 个文件",
|
|
179
|
+
name=manifest["name"], removed=len(removed), preserved=len(preserved),
|
|
180
|
+
)
|
|
181
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2) if args.json else msg)
|
|
182
|
+
return 0
|
|
183
|
+
if args.plugin_command not in {"install", "load"}:
|
|
184
|
+
raise CliError(_i18n_exc("plugin.unknown_command", f"未知插件命令: {args.plugin_command}", command=args.plugin_command))
|
|
185
|
+
if not args.source:
|
|
186
|
+
raise CliError(_i18n_exc("plugin.install_missing_source", "plugin install 必须提供 --source <插件目录>"))
|
|
187
|
+
source = Path(args.source).expanduser().resolve()
|
|
188
|
+
if not source.is_dir():
|
|
189
|
+
raise CliError(_i18n_exc("plugin.source_not_found", f"插件目录不存在: {source}", source=source))
|
|
190
|
+
_, manifest = _plugin_manifest(source, args.plugin_name)
|
|
191
|
+
copied, skipped, manifest = _copy_plugin(
|
|
192
|
+
source, root / ".bugx" / "plugins" / str(manifest["name"]) / "payload",
|
|
193
|
+
args.force, project_root=root,
|
|
194
|
+
)
|
|
195
|
+
installed_files = _records_for_paths(
|
|
196
|
+
root, [path for path in manifest.pop("_installed_targets", []) if isinstance(path, Path)]
|
|
197
|
+
)
|
|
198
|
+
stored_manifest = _plugin_store(root) / str(manifest["name"]) / "plugin.json"
|
|
199
|
+
marker_path = stored_manifest.parent / ".bugx-install.json"
|
|
200
|
+
marker_payload = {
|
|
201
|
+
"schema_version": 1,
|
|
202
|
+
"plugin": manifest["name"],
|
|
203
|
+
"files": installed_files,
|
|
204
|
+
}
|
|
205
|
+
manifest_record = _file_record(root, stored_manifest)
|
|
206
|
+
if manifest_record is not None:
|
|
207
|
+
marker_payload["manifest"] = manifest_record
|
|
208
|
+
_write_private_json(marker_path, marker_payload)
|
|
209
|
+
payload = {
|
|
210
|
+
"status": "LOADED", "name": manifest["name"],
|
|
211
|
+
"version": manifest["version"], "copied": copied, "skipped": skipped,
|
|
212
|
+
"autoload": False, "private": True,
|
|
213
|
+
}
|
|
214
|
+
msg = _i18n_prompt(
|
|
215
|
+
"plugin.installed_on_demand",
|
|
216
|
+
f"[bugx] 已按需安装插件 {manifest['name']}(写入 {copied},保留 {skipped})",
|
|
217
|
+
name=manifest["name"], copied=copied, skipped=skipped,
|
|
218
|
+
)
|
|
219
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2) if args.json else msg)
|
|
220
|
+
return 0
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _prompt_for_hosts(hosts: list[dict[str, object]], root: Path) -> list[str]:
|
|
224
|
+
available = [item for item in hosts if item["installed"]]
|
|
225
|
+
if not available:
|
|
226
|
+
raise CliError(
|
|
227
|
+
_i18n_exc(
|
|
228
|
+
"plugin.no_agent_detected",
|
|
229
|
+
"没有检测到已安装的 AI Agent;请安装 OpenCode/Codex/Claude/ZCode/Pi/ChatGPT,"
|
|
230
|
+
"或显式指定 --agent",
|
|
231
|
+
)
|
|
232
|
+
)
|
|
233
|
+
_ensure_core_importable()
|
|
234
|
+
from core.runtime import interaction
|
|
235
|
+
from core.runtime import startup_environment
|
|
236
|
+
|
|
237
|
+
project_configured = _i18n_prompt("plugin.host_project_configured", "项目已有配置")
|
|
238
|
+
cmd_installed = _i18n_prompt("plugin.host_command_installed", "命令已安装")
|
|
239
|
+
options = [
|
|
240
|
+
(
|
|
241
|
+
str(item["name"]),
|
|
242
|
+
f"{item['label']}({project_configured if item['project_marker'] else cmd_installed})",
|
|
243
|
+
)
|
|
244
|
+
for item in available
|
|
245
|
+
]
|
|
246
|
+
options.append(("all", _i18n_prompt("plugin.host_all_detected", "安装到全部已检测 Agent")))
|
|
247
|
+
title = _i18n_prompt("plugin.choose_install_target_title", "选择 BugX Agent 安装目标")
|
|
248
|
+
question_text = _i18n_prompt("plugin.choose_install_target_question", "可多选需要安装或更新的宿主 Agent")
|
|
249
|
+
question = interaction.InteractionQuestion(
|
|
250
|
+
question_id="agent_install_targets",
|
|
251
|
+
phase="install",
|
|
252
|
+
kind="select",
|
|
253
|
+
title=title,
|
|
254
|
+
question=question_text,
|
|
255
|
+
options=tuple(
|
|
256
|
+
interaction.InteractionOption(value=value, label=value, description=description)
|
|
257
|
+
for value, description in options
|
|
258
|
+
),
|
|
259
|
+
multiple=True,
|
|
260
|
+
default=0,
|
|
261
|
+
)
|
|
262
|
+
environment = startup_environment.detect(root)
|
|
263
|
+
result = interaction.ask(question, environment)
|
|
264
|
+
if result.status != interaction.ANSWERED or not isinstance(result.value, tuple):
|
|
265
|
+
raise CliError(_i18n_exc("plugin.agent_selection_not_completed", "未完成 Agent 安装目标选择;请重新运行并完成当前菜单"))
|
|
266
|
+
selected = list(result.value)
|
|
267
|
+
if "all" in selected:
|
|
268
|
+
return [str(item["name"]) for item in available]
|
|
269
|
+
return [name for name in selected if name in {str(item["name"]) for item in available}]
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def _write_host_entry(
|
|
273
|
+
root: Path, target: Path, content: str, force: bool, host_name: str,
|
|
274
|
+
) -> tuple[int, int, Path | None]:
|
|
275
|
+
del force # Existing content is updated through the recoverable backup path.
|
|
276
|
+
return _write_host_resource(root, target, content.encode("utf-8"), host_name)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def _backup_uninstall_file(
|
|
282
|
+
root: Path, host_name: str, target: Path, backup_dir: Path | None = None,
|
|
283
|
+
) -> Path:
|
|
284
|
+
"""Backup a file removed by uninstall; backups remain recoverable in .bugx."""
|
|
285
|
+
return _backup_host_resource(root, f"uninstall-{host_name}", target, backup_dir=backup_dir)
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def _remove_owned_record(
|
|
289
|
+
root: Path,
|
|
290
|
+
record: object,
|
|
291
|
+
host_name: str,
|
|
292
|
+
removed: list[str],
|
|
293
|
+
preserved: list[str],
|
|
294
|
+
backup_dir: Path | None = None,
|
|
295
|
+
force: bool = False,
|
|
296
|
+
) -> None:
|
|
297
|
+
"""Remove a file only when its current bytes match BugX's recorded bytes (or force=True)."""
|
|
298
|
+
if not isinstance(record, dict):
|
|
299
|
+
return
|
|
300
|
+
relative = record.get("path")
|
|
301
|
+
expected = record.get("sha256")
|
|
302
|
+
if not isinstance(relative, str) or not isinstance(expected, str):
|
|
303
|
+
preserved.append(f"{relative or '<unknown>'}(清单缺少哈希)")
|
|
304
|
+
return
|
|
305
|
+
target = _safe_record_target(root, relative)
|
|
306
|
+
if target.is_symlink():
|
|
307
|
+
preserved.append(f"{relative}(符号链接)")
|
|
308
|
+
return
|
|
309
|
+
if not target.exists():
|
|
310
|
+
# 入口文件已被外部删除:仍然修剪安装时产生的空目录,避免
|
|
311
|
+
# .workbuddy/skills/bugx 这类空壳在卸载后残留(removed 为空、
|
|
312
|
+
# status 却报 UNINSTALLED,看起来像卸干净了)。
|
|
313
|
+
_remove_empty_parents(root, [relative])
|
|
314
|
+
return
|
|
315
|
+
if not target.is_file():
|
|
316
|
+
preserved.append(f"{relative}(不是普通文件)")
|
|
317
|
+
return
|
|
318
|
+
try:
|
|
319
|
+
current_hash = _sha256_file(target)
|
|
320
|
+
except OSError as exc:
|
|
321
|
+
preserved.append(f"{relative}(无法读取:{exc})")
|
|
322
|
+
return
|
|
323
|
+
if current_hash != expected and not force:
|
|
324
|
+
preserved.append(f"{relative}(内容已被用户修改)")
|
|
325
|
+
return
|
|
326
|
+
backup = _backup_uninstall_file(root, host_name, target, backup_dir)
|
|
327
|
+
try:
|
|
328
|
+
target.unlink()
|
|
329
|
+
except OSError as exc:
|
|
330
|
+
preserved.append(f"{relative}(删除失败:{exc};备份:{backup})")
|
|
331
|
+
return
|
|
332
|
+
if current_hash != expected:
|
|
333
|
+
removed.append(f"{relative}(强制清理已备份)")
|
|
334
|
+
else:
|
|
335
|
+
removed.append(relative)
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
#: 按 Skill 语义清扫的适配器基线(仅**未迁移**宿主;已迁移宿主由插件
|
|
339
|
+
#: ``install.sweepable`` 声明)。逐宿主切片时删除对应项。
|
|
340
|
+
_LEGACY_SWEEPABLE_SKILL_ADAPTERS = ("claude", "workbuddy", "qoder", "trea")
|
|
341
|
+
_SWEEPABLE_SKILL_ADAPTERS = sweepable_skill_adapter_names(_LEGACY_SWEEPABLE_SKILL_ADAPTERS)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def _sweep_legacy_skill_entry(
|
|
345
|
+
root: Path, relative: str, rendered: str, host_name: str,
|
|
346
|
+
) -> bool:
|
|
347
|
+
"""安装时清理宿主遗留安装路径(DOC-169,声明式 ``legacy_paths``)。
|
|
348
|
+
|
|
349
|
+
仅当内容与当前模板渲染逐字一致(忽略 locale 标记)才认定为 BugX 自有:
|
|
350
|
+
先备份到项目卸载备份目录再删除;用户改过的文件一律保留。
|
|
351
|
+
"""
|
|
352
|
+
target = root / relative
|
|
353
|
+
if target.is_symlink() or not target.is_file():
|
|
354
|
+
return False
|
|
355
|
+
try:
|
|
356
|
+
current = target.read_text(encoding="utf-8")
|
|
357
|
+
except (OSError, UnicodeDecodeError):
|
|
358
|
+
return False
|
|
359
|
+
if strip_locale_marker(current) != strip_locale_marker(rendered):
|
|
360
|
+
return False
|
|
361
|
+
_backup_uninstall_file(root, host_name, target, None)
|
|
362
|
+
try:
|
|
363
|
+
target.unlink()
|
|
364
|
+
except OSError:
|
|
365
|
+
return False
|
|
366
|
+
_remove_empty_parents(root, [relative])
|
|
367
|
+
return True
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def _sweep_unrecorded_host_entry(
|
|
371
|
+
root: Path, adapter, removed: list[str], preserved: list[str],
|
|
372
|
+
backup_dir: Path | None = None,
|
|
373
|
+
force: bool = False,
|
|
374
|
+
) -> None:
|
|
375
|
+
"""无安装记录的宿主入口:按当前渲染模板比对清理(0.6.79)。
|
|
376
|
+
|
|
377
|
+
项目卸载的语义是"任何受支持的 IDE 进来都像新项目"。对 hosts.json
|
|
378
|
+
没有记录的宿主(旧版本安装或登记丢失),入口文件内容与当前模板渲染
|
|
379
|
+
逐字一致才认定为 BugX 自有并删除;有出入一律保留并报告,不冒充归属。
|
|
380
|
+
若 force=True,则对已识别的目标进行强制备份并删除。
|
|
381
|
+
"""
|
|
382
|
+
if adapter.name not in _SWEEPABLE_SKILL_ADAPTERS:
|
|
383
|
+
return
|
|
384
|
+
|
|
385
|
+
def _sweep_rendered(relative: str, rendered: str) -> None:
|
|
386
|
+
target = root / relative
|
|
387
|
+
if target.is_symlink() or not target.is_file():
|
|
388
|
+
return
|
|
389
|
+
try:
|
|
390
|
+
current = target.read_text(encoding="utf-8")
|
|
391
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
392
|
+
preserved.append(f"{relative}(比对失败:{exc},保留)")
|
|
393
|
+
return
|
|
394
|
+
if strip_locale_marker(current) != strip_locale_marker(rendered) and not force:
|
|
395
|
+
preserved.append(f"{relative}(内容与 BugX 模板不一致,保留)")
|
|
396
|
+
return
|
|
397
|
+
_backup_uninstall_file(root, adapter.name, target, backup_dir)
|
|
398
|
+
try:
|
|
399
|
+
target.unlink()
|
|
400
|
+
except OSError as exc:
|
|
401
|
+
preserved.append(f"{relative}(删除失败:{exc})")
|
|
402
|
+
return
|
|
403
|
+
if strip_locale_marker(current) != strip_locale_marker(rendered):
|
|
404
|
+
removed.append(f"{relative}(无登记遗留,强制清理已备份)")
|
|
405
|
+
else:
|
|
406
|
+
removed.append(f"{relative}(无登记遗留,按当前模板比对后删除)")
|
|
407
|
+
_remove_empty_parents(root, [relative])
|
|
408
|
+
|
|
409
|
+
source = global_engine_root() / "bugx.md"
|
|
410
|
+
if not source.is_file():
|
|
411
|
+
preserved.append(f"{adapter.install_path}(无法读取当前模板,保留)")
|
|
412
|
+
return
|
|
413
|
+
try:
|
|
414
|
+
# 安装端用解析后的部署 locale 渲染入口(i18n.resolve_locale()
|
|
415
|
+
# .resolved_locale,可被 --locale 覆盖);无登记清扫必须用同一
|
|
416
|
+
# locale 才能逐字比对,否则非英语环境下入口会被误判为“内容与
|
|
417
|
+
# BugX 模板不一致”而永远无法清理(2026-09-28 修复)。
|
|
418
|
+
sweep_locale = _resolve_locale_name(None)
|
|
419
|
+
rendered = adapter.render(source, locale=sweep_locale)
|
|
420
|
+
if adapter.name == "workbuddy":
|
|
421
|
+
for relative in adapter.required_paths:
|
|
422
|
+
_sweep_rendered(relative, rendered)
|
|
423
|
+
else:
|
|
424
|
+
_sweep_rendered(adapter.install_path, rendered)
|
|
425
|
+
for req_rel in getattr(adapter, "required_paths", ()) or ():
|
|
426
|
+
req_rendered = adapter.render_required_entry(req_rel, source, locale=sweep_locale)
|
|
427
|
+
if req_rendered:
|
|
428
|
+
_sweep_rendered(req_rel, req_rendered)
|
|
429
|
+
if adapter.name == "claude":
|
|
430
|
+
from .plugin_claude import _remove_claude_project_skills_and_dist
|
|
431
|
+
_remove_claude_project_skills_and_dist(root, removed, preserved, backup_dir=backup_dir)
|
|
432
|
+
_remove_empty_parents(root, [adapter.install_path])
|
|
433
|
+
# DOC-169:声明式遗留路径(如 codex 旧 .codex/skills)无登记遗留
|
|
434
|
+
# 按对应入口模板比对清理。worker 等遗留路径必须先使用宿主提供的
|
|
435
|
+
# 路径级 renderer,不能拿主 agent 模板误判为用户改写。
|
|
436
|
+
for legacy_rel in getattr(adapter, "legacy_paths", ()) or ():
|
|
437
|
+
legacy_rendered = adapter.render_required_entry(
|
|
438
|
+
legacy_rel, source, locale=sweep_locale,
|
|
439
|
+
) or rendered
|
|
440
|
+
_sweep_rendered(legacy_rel, legacy_rendered)
|
|
441
|
+
except CliError as exc:
|
|
442
|
+
preserved.append(f"{adapter.install_path}(比对失败:{exc},保留)")
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
def _read_hosts_record(path: Path) -> dict[str, object]:
|
|
446
|
+
if path.is_symlink() or not path.is_file():
|
|
447
|
+
return {"schema_version": 1, "installed": [], "shared_files": []}
|
|
448
|
+
try:
|
|
449
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
450
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
451
|
+
raise CliError(_i18n_exc("plugin.hosts_manifest_unreadable", f"宿主清单无法读取,拒绝卸载: {path}: {exc}", path=path, exc=exc)) from exc
|
|
452
|
+
if not isinstance(payload, dict) or not isinstance(payload.get("installed"), list):
|
|
453
|
+
raise CliError(_i18n_exc("plugin.hosts_manifest_missing_installed", f"宿主清单缺少 installed 数组,拒绝卸载: {path}", path=path))
|
|
454
|
+
if not isinstance(payload.get("shared_files", []), list):
|
|
455
|
+
raise CliError(_i18n_exc("plugin.hosts_manifest_shared_files_not_list", f"宿主清单的 shared_files 必须是数组: {path}", path=path))
|
|
456
|
+
return payload
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def _chatgpt_marketplace_name(root: Path) -> str:
|
|
460
|
+
"""Return a stable, collision-resistant name for this project's marketplace."""
|
|
461
|
+
digest = hashlib.sha256(str(root.resolve()).encode("utf-8")).hexdigest()[:10]
|
|
462
|
+
return f"bugx-local-{digest}"
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
def _chatgpt_skill_content(
|
|
466
|
+
source: Path, *, locale: str | None = None, version: str = __version__,
|
|
467
|
+
) -> str:
|
|
468
|
+
"""Mirror the canonical BugX protocol into the OpenAI Skill format.
|
|
469
|
+
|
|
470
|
+
Uses the progressive L0 router prompt as the lightweight root definition,
|
|
471
|
+
avoiding monolithic context bloat in host environments.
|
|
472
|
+
"""
|
|
473
|
+
l0_file = source / "prompts" / "l0_router.md"
|
|
474
|
+
if l0_file.is_file():
|
|
475
|
+
body = l0_file.read_text(encoding="utf-8").strip()
|
|
476
|
+
else:
|
|
477
|
+
body = (source / "bugx-quick.md").read_text(encoding="utf-8").strip()
|
|
478
|
+
|
|
479
|
+
loc = _resolve_locale_name(locale)
|
|
480
|
+
banner = _i18n_prompt(
|
|
481
|
+
"plugin.chatgpt_skill_banner",
|
|
482
|
+
"这是 BugX 的 ChatGPT Skill 镜像。执行前通过 `bugx engine path --name "
|
|
483
|
+
"AGENT_GUIDE.md` 和 `bugx engine path --name bugx.md` 读取全局协议;"
|
|
484
|
+
"全局引擎是协议和运行时的唯一权威来源。\n\n"
|
|
485
|
+
f"协议镜像版本:{version}\n",
|
|
486
|
+
locale=loc,
|
|
487
|
+
version=version,
|
|
488
|
+
)
|
|
489
|
+
from ..host_adapters import get_agent_description
|
|
490
|
+
desc = get_agent_description(loc)
|
|
491
|
+
|
|
492
|
+
content = (
|
|
493
|
+
"---\n"
|
|
494
|
+
"name: bugx\n"
|
|
495
|
+
f"description: {desc}\n"
|
|
496
|
+
f"metadata:\n bugx_version: \"{version}\"\n"
|
|
497
|
+
"---\n\n"
|
|
498
|
+
"# BugX for ChatGPT\n\n"
|
|
499
|
+
f"{banner.rstrip()}\n\n"
|
|
500
|
+
f"{interaction_protocol('chatgpt', loc).lstrip()}\n\n"
|
|
501
|
+
f"{body.rstrip()}\n"
|
|
502
|
+
)
|
|
503
|
+
return add_locale_marker(content, locale)
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
def _chatgpt_plugin_manifest(version: str = __version__) -> dict[str, object]:
|
|
507
|
+
return {
|
|
508
|
+
"name": CHATGPT_PLUGIN_NAME,
|
|
509
|
+
"version": version,
|
|
510
|
+
"description": "Autonomous code review and vulnerability hunting agent that uncovers, reproduces, and fixes deep bugs.",
|
|
511
|
+
"skills": "./skills/",
|
|
512
|
+
"homepage": "https://bugx.dev",
|
|
513
|
+
"author": {
|
|
514
|
+
"name": "BugX",
|
|
515
|
+
"url": "https://bugx.dev",
|
|
516
|
+
},
|
|
517
|
+
"license": "BSL-1.1",
|
|
518
|
+
"keywords": ["bugx", "audit", "security", "testing"],
|
|
519
|
+
"interface": {
|
|
520
|
+
"displayName": "BugX",
|
|
521
|
+
"shortDescription": "Autonomous code review and vulnerability hunting agent that uncovers, reproduces, and fixes deep bugs.",
|
|
522
|
+
"longDescription": "An autonomous agent dedicated to code review, vulnerability hunting, and automated bug fixing. Built for deep investigations, BugX steps in when you are wrapping up a feature, opening a pull request, or hunting down an elusive bug. It analyzes code logic, automatically writes test cases to uncover and reproduce hidden flaws, and delivers verified patches that resolve root causes. Always safeguarding your code quality and security.",
|
|
523
|
+
"developerName": "BugX",
|
|
524
|
+
"category": "Developer tools",
|
|
525
|
+
# ChatGPT only exposes its native choice/confirmation surface to
|
|
526
|
+
# plugins that explicitly opt into the Interactive capability.
|
|
527
|
+
# The Skill text alone cannot enable that surface.
|
|
528
|
+
"capabilities": ["Interactive", "Read", "Write"],
|
|
529
|
+
"websiteURL": "https://bugx.dev",
|
|
530
|
+
"privacyPolicyURL": "https://bugx.dev",
|
|
531
|
+
"termsOfServiceURL": "https://bugx.dev",
|
|
532
|
+
"composerIcon": "./assets/bugx-avatar-512.png",
|
|
533
|
+
"logo": "./assets/bugx-avatar-512.png",
|
|
534
|
+
"logoDark": "./assets/bugx-avatar-512.png",
|
|
535
|
+
"defaultPrompt": [
|
|
536
|
+
"Use BugX to find, reproduce, verify, and report bugs in this app or codebase.",
|
|
537
|
+
],
|
|
538
|
+
"brandColor": "#0284c7",
|
|
539
|
+
"screenshots": [],
|
|
540
|
+
},
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
def _chatgpt_plugin_icon_payload() -> bytes:
|
|
545
|
+
"""Load the bundled icon used by project and global ChatGPT plugins."""
|
|
546
|
+
path = asset_root() / "assets" / "bugx-avatar-512.png"
|
|
547
|
+
try:
|
|
548
|
+
return path.read_bytes()
|
|
549
|
+
except OSError as exc:
|
|
550
|
+
raise CliError(
|
|
551
|
+
_i18n_exc(
|
|
552
|
+
"plugin.chatgpt_icon_missing",
|
|
553
|
+
f"BugX Plugin 图标资源缺失: {path}",
|
|
554
|
+
path=path,
|
|
555
|
+
)
|
|
556
|
+
) from exc
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
def _host_mcp_mirror_targets(host_name: str, root: Path) -> list[tuple[str, Path]]:
|
|
560
|
+
"""宿主声明的 MCP 镜像目标(插件 ``mcp_write.mirror_relpaths``)。
|
|
561
|
+
|
|
562
|
+
只有镜像根目录(或目标文件)真实存在时才返回——不替用户凭空创建宿主目录。
|
|
563
|
+
"""
|
|
564
|
+
|
|
565
|
+
facet = engine_host_mcp_write(host_name)
|
|
566
|
+
if facet is None or not facet.mirror_relpaths:
|
|
567
|
+
return []
|
|
568
|
+
label = engine_host_label(host_name)
|
|
569
|
+
targets: list[tuple[str, Path]] = []
|
|
570
|
+
for relpath in facet.mirror_relpaths:
|
|
571
|
+
target = root.resolve() / relpath
|
|
572
|
+
marker_dir = target.parent
|
|
573
|
+
if marker_dir.is_dir() or target.is_file():
|
|
574
|
+
targets.append((label, target))
|
|
575
|
+
return targets
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
def _sync_mcp_mirror(
|
|
579
|
+
host_name: str,
|
|
580
|
+
mirror_label: str,
|
|
581
|
+
mirror_target: Path,
|
|
582
|
+
desired: dict[str, dict[str, object]],
|
|
583
|
+
*,
|
|
584
|
+
optional_names: set[str] | None = None,
|
|
585
|
+
) -> None:
|
|
586
|
+
"""把宿主的 MCP 注册同步镜像到兼容宿主的配置文件(如 Roo Code 的 ``.roo/mcp.json``)。"""
|
|
587
|
+
|
|
588
|
+
facet = engine_host_mcp_write(host_name)
|
|
589
|
+
servers_key = facet.container_key if facet is not None else "mcpServers"
|
|
590
|
+
if host_name == "opencode":
|
|
591
|
+
payload = _load_json_object(mirror_target, mirror_label)
|
|
592
|
+
else:
|
|
593
|
+
try:
|
|
594
|
+
payload = _load_json_object(mirror_target, mirror_label)
|
|
595
|
+
except Exception:
|
|
596
|
+
payload = {}
|
|
597
|
+
container = payload
|
|
598
|
+
keys = servers_key.split(".")
|
|
599
|
+
for key in keys[:-1]:
|
|
600
|
+
child = container.get(key)
|
|
601
|
+
if child is None:
|
|
602
|
+
child = {}
|
|
603
|
+
container[key] = child
|
|
604
|
+
elif not isinstance(child, dict):
|
|
605
|
+
raise CliError(f"{mirror_label} 配置 {servers_key} 不是对象,拒绝写入: {mirror_target}")
|
|
606
|
+
if host_name == "opencode" and key == "mcp" and child and "servers" not in child:
|
|
607
|
+
raise CliError(
|
|
608
|
+
f"OpenCode 配置使用旧的扁平 mcp 结构,拒绝镜像迁移: {mirror_target}"
|
|
609
|
+
)
|
|
610
|
+
container = child
|
|
611
|
+
leaf_key = keys[-1]
|
|
612
|
+
servers = container.get(leaf_key)
|
|
613
|
+
if servers is None:
|
|
614
|
+
servers = {}
|
|
615
|
+
container[leaf_key] = servers
|
|
616
|
+
elif not isinstance(servers, dict):
|
|
617
|
+
raise CliError(f"{mirror_label} 配置 {servers_key} 不是对象,拒绝写入: {mirror_target}")
|
|
618
|
+
|
|
619
|
+
for name in {"playwright", "postmcp"} - set(optional_names or set()):
|
|
620
|
+
if _host_mcp_entry_is_current(name, servers.get(name)):
|
|
621
|
+
servers.pop(name, None)
|
|
622
|
+
|
|
623
|
+
for name, expected in desired.items():
|
|
624
|
+
current = servers.get(name)
|
|
625
|
+
if not isinstance(current, dict):
|
|
626
|
+
servers[name] = copy.deepcopy(expected)
|
|
627
|
+
elif not _host_mcp_entry_is_current(name, current):
|
|
628
|
+
merged = copy.deepcopy(current)
|
|
629
|
+
merged.update(copy.deepcopy(expected))
|
|
630
|
+
servers[name] = merged
|
|
631
|
+
|
|
632
|
+
mirror_target.parent.mkdir(parents=True, exist_ok=True)
|
|
633
|
+
_atomic_write_global_file(
|
|
634
|
+
mirror_target,
|
|
635
|
+
json.dumps(payload, ensure_ascii=False, indent=2).encode("utf-8") + b"\n",
|
|
636
|
+
)
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
def _sync_trae_mcp_mirror(
|
|
640
|
+
root: Path,
|
|
641
|
+
desired: dict[str, dict[str, object]],
|
|
642
|
+
*,
|
|
643
|
+
optional_names: set[str] | None = None,
|
|
644
|
+
) -> None:
|
|
645
|
+
"""当工作区存在 .trae 或 .trae-cn 目录时,将 Trea MCP 注册同步镜像写入相应目录的 mcp.json。"""
|
|
646
|
+
for marker_name in (".trae", ".trae-cn"):
|
|
647
|
+
marker_dir = root.resolve() / marker_name
|
|
648
|
+
if not marker_dir.is_dir() and not (marker_dir / "mcp.json").is_file():
|
|
649
|
+
continue
|
|
650
|
+
marker_target = marker_dir / "mcp.json"
|
|
651
|
+
try:
|
|
652
|
+
payload = _load_json_object(marker_target, f"Trae ({marker_name})")
|
|
653
|
+
except Exception:
|
|
654
|
+
payload = {}
|
|
655
|
+
servers_key = "mcpServers"
|
|
656
|
+
servers = payload.get(servers_key)
|
|
657
|
+
if servers is None or not isinstance(servers, dict):
|
|
658
|
+
servers = {}
|
|
659
|
+
payload[servers_key] = servers
|
|
660
|
+
|
|
661
|
+
for name in {"playwright", "postmcp"} - set(optional_names or set()):
|
|
662
|
+
if _host_mcp_entry_is_current(name, servers.get(name)):
|
|
663
|
+
servers.pop(name, None)
|
|
664
|
+
|
|
665
|
+
for name, expected in desired.items():
|
|
666
|
+
current = servers.get(name)
|
|
667
|
+
if not isinstance(current, dict):
|
|
668
|
+
servers[name] = copy.deepcopy(expected)
|
|
669
|
+
elif not _host_mcp_entry_is_current(name, current):
|
|
670
|
+
merged = copy.deepcopy(current)
|
|
671
|
+
merged.update(copy.deepcopy(expected))
|
|
672
|
+
servers[name] = merged
|
|
673
|
+
|
|
674
|
+
marker_dir.mkdir(parents=True, exist_ok=True)
|
|
675
|
+
_atomic_write_global_file(
|
|
676
|
+
marker_target,
|
|
677
|
+
json.dumps(payload, ensure_ascii=False, indent=2).encode("utf-8") + b"\n",
|
|
678
|
+
)
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
#: **未迁移**宿主的 MCP 条目附加字段基线(逐宿主切片时删除对应项)。
|
|
682
|
+
#: 已迁移宿主由插件 ``mcp_write.entry_extra`` 声明。
|
|
683
|
+
_LEGACY_MCP_ENTRY_EXTRA: dict[str, dict[str, object]] = {
|
|
684
|
+
"zcode": {"enabled": True},
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
def _mcp_shape_names() -> set[str]:
|
|
689
|
+
"""合法 MCP 配置形态:CLI 适配器宿主 + 插件宿主 + 基线别名(``codebuddy``)。"""
|
|
690
|
+
|
|
691
|
+
names = {adapter.name for adapter in HOST_ADAPTERS}
|
|
692
|
+
names.update(plugin.name for plugin in engine_host_plugins())
|
|
693
|
+
names.add("codebuddy")
|
|
694
|
+
return names
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
def _host_mcp_entry_extra(host_name: str) -> dict[str, object]:
|
|
698
|
+
"""宿主 server 条目的专有字段:插件 ``mcp_write.entry_extra`` 优先,否则走基线表。"""
|
|
699
|
+
|
|
700
|
+
facet = engine_host_mcp_write(host_name)
|
|
701
|
+
if facet is not None and facet.entry_extra:
|
|
702
|
+
return dict(facet.entry_extra)
|
|
703
|
+
return dict(_LEGACY_MCP_ENTRY_EXTRA.get(str(host_name).strip().casefold(), {}))
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
def _global_only_mcp_host(host_name: str) -> bool:
|
|
707
|
+
"""宿主是否只有**用户级/全局** MCP 作用域(插件 ``mcp_write.project_relpath is None``)。"""
|
|
708
|
+
|
|
709
|
+
facet = engine_host_mcp_write(host_name)
|
|
710
|
+
return bool(facet is not None and facet.project_relpath is None)
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
def _host_global_mcp_target(host_name: str, root: Path) -> Path | None:
|
|
714
|
+
"""全局作用域宿主的真实配置文件路径(来自插件 ``engine_run.mcp_config_paths``)。"""
|
|
715
|
+
|
|
716
|
+
paths = engine_host_mcp_config_paths(host_name, root.resolve())
|
|
717
|
+
return paths[0] if paths else None
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
def _host_supervisor_server_definitions(
|
|
721
|
+
*, shape: str, optional_names: set[str] | None = None,
|
|
722
|
+
) -> dict[str, dict[str, object]]:
|
|
723
|
+
"""构建 Cline / Claude Code / ZCode / Qoder / Trea / FunIDE 的最小 BugX MCP 注册。
|
|
724
|
+
|
|
725
|
+
命令刻意使用 ``--root .``:宿主以当前工作区为 cwd 启动 stdio MCP
|
|
726
|
+
server,``.`` 因此解析到用户当前打开的项目,而不是某个用户级进程目录。
|
|
727
|
+
|
|
728
|
+
每个宿主的配置只写在当前项目中,server 命令统一以 ``--root .``
|
|
729
|
+
绑定宿主打开的工作区。
|
|
730
|
+
|
|
731
|
+
例外:宿主插件声明 ``mcp_write.requires_absolutize=True`` 时(pi/claude 等,
|
|
732
|
+
写入分支见 :func:`write_host_mcp_config`),落盘前由
|
|
733
|
+
:func:`_absolutize_server_definitions` 把 ``--root``/``--db``/command 绝对化——
|
|
734
|
+
这类宿主由宿主进程 spawn MCP,cwd 不可依赖。
|
|
735
|
+
"""
|
|
736
|
+
if shape not in _mcp_shape_names():
|
|
737
|
+
raise CliError(_i18n_exc("plugin.unknown_mcp_shape", f"未知宿主 MCP 配置形态: {shape}", shape=shape))
|
|
738
|
+
entry_extra = _host_mcp_entry_extra(shape)
|
|
739
|
+
result: dict[str, dict[str, object]] = {}
|
|
740
|
+
for name in HOST_SUPERVISOR_MCP:
|
|
741
|
+
role = HOST_SUPERVISOR_MCP_ROLES[name]
|
|
742
|
+
entry: dict[str, object] = {
|
|
743
|
+
# 显式声明传输类型:所有宿主注册的都是本地 stdio server。
|
|
744
|
+
# 旧实现省略该字段,与 test_cli_hosts 的 MCP 契约断言
|
|
745
|
+
# (type == "stdio")不一致,属实现漏写而非测试过时。
|
|
746
|
+
"type": "stdio",
|
|
747
|
+
"command": "bugx",
|
|
748
|
+
"args": ["mcp", "serve", "--root", ".", "--role", role],
|
|
749
|
+
}
|
|
750
|
+
if entry_extra:
|
|
751
|
+
entry.update(copy.deepcopy(entry_extra))
|
|
752
|
+
result[name] = entry
|
|
753
|
+
docs_entry: dict[str, object] = {
|
|
754
|
+
"type": "stdio",
|
|
755
|
+
"command": "bugx",
|
|
756
|
+
"args": [
|
|
757
|
+
"mcp", "docs", "serve", "--root", ".",
|
|
758
|
+
"--db", ".bugx/knowledge/docs.sqlite3",
|
|
759
|
+
],
|
|
760
|
+
}
|
|
761
|
+
if entry_extra:
|
|
762
|
+
docs_entry.update(copy.deepcopy(entry_extra))
|
|
763
|
+
result["bugx-docs"] = docs_entry
|
|
764
|
+
for name in sorted(optional_names or set()):
|
|
765
|
+
if name not in {"playwright", "postmcp"}:
|
|
766
|
+
continue
|
|
767
|
+
result[name] = {
|
|
768
|
+
"type": "stdio",
|
|
769
|
+
"command": "bugx",
|
|
770
|
+
"args": ["mcp-runtime", "start", "--server", name],
|
|
771
|
+
}
|
|
772
|
+
return result
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
def _host_mcp_command_tokens(entry: object) -> list[str] | None:
|
|
776
|
+
"""Normalize a host MCP entry to argv without executing it."""
|
|
777
|
+
if not isinstance(entry, dict):
|
|
778
|
+
return None
|
|
779
|
+
command = entry.get("command")
|
|
780
|
+
args = entry.get("args", [])
|
|
781
|
+
if isinstance(command, list):
|
|
782
|
+
tokens = [item for item in command if isinstance(item, str)]
|
|
783
|
+
if len(tokens) != len(command):
|
|
784
|
+
return None
|
|
785
|
+
if args not in (None, []):
|
|
786
|
+
if not isinstance(args, list) or any(not isinstance(item, str) for item in args):
|
|
787
|
+
return None
|
|
788
|
+
tokens.extend(args)
|
|
789
|
+
return tokens
|
|
790
|
+
if not isinstance(command, str) or not command.strip():
|
|
791
|
+
return None
|
|
792
|
+
if args is None:
|
|
793
|
+
args = []
|
|
794
|
+
if not isinstance(args, list) or any(not isinstance(item, str) for item in args):
|
|
795
|
+
return None
|
|
796
|
+
return [command, *args]
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
_PYTHON_MODULE_LAUNCHER_PREFIX = ["-m", "bugx_cli.cli"]
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
def _absolute_bugx_launcher() -> tuple[str, list[str]]:
|
|
803
|
+
"""解析 bugx 启动入口,返回 ``(command, 前缀参数)``。
|
|
804
|
+
|
|
805
|
+
候选按可信度排序,**绝不落盘伪造路径**(旧实现无条件取 ``sys.argv[0]``,
|
|
806
|
+
在 ``python -m`` 下会写出 ``/abs/project/-m`` 这类无法启动的 command):
|
|
807
|
+
|
|
808
|
+
1. ``shutil.which("bugx")`` —— 标准安装;
|
|
809
|
+
2. ``sys.argv[0]`` 是真实可执行文件 —— 直接调用探测脚本的场景;
|
|
810
|
+
3. 与当前解释器同目录的 ``bugx`` —— venv / pip 安装;
|
|
811
|
+
4. 兜底:``<当前解释器> -m bugx_cli.cli`` —— 绝对、可执行、不伪造路径。
|
|
812
|
+
"""
|
|
813
|
+
|
|
814
|
+
override = shutil.which("bugx")
|
|
815
|
+
if override:
|
|
816
|
+
return str(Path(override).resolve()), []
|
|
817
|
+
try:
|
|
818
|
+
candidate = Path(sys.argv[0]).resolve()
|
|
819
|
+
except OSError:
|
|
820
|
+
candidate = None
|
|
821
|
+
if (
|
|
822
|
+
candidate is not None
|
|
823
|
+
and candidate.is_file()
|
|
824
|
+
and os.access(candidate, os.X_OK)
|
|
825
|
+
and candidate.name not in {"-m", "-c", "-"}
|
|
826
|
+
):
|
|
827
|
+
return str(candidate), []
|
|
828
|
+
sibling = Path(sys.executable).parent / "bugx"
|
|
829
|
+
if sibling.is_file():
|
|
830
|
+
return str(sibling), []
|
|
831
|
+
return str(Path(sys.executable).resolve()), list(_PYTHON_MODULE_LAUNCHER_PREFIX)
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
def _absolutize_server_definitions(
|
|
835
|
+
desired: dict[str, dict[str, object]], root: Path,
|
|
836
|
+
) -> dict[str, dict[str, object]]:
|
|
837
|
+
"""把用户级注册的期望定义绝对化:command、``--root`` 与项目内 ``--db``。
|
|
838
|
+
|
|
839
|
+
用户级配置(ZCode 全局、Cline 数据目录)不在工作区内,MCP server 由宿主进程
|
|
840
|
+
spawn——常驻 Hub Daemon 的 cwd 不是工作区,``--root .`` 会解析到宿主 cwd
|
|
841
|
+
而不是本项目,因此必须写绝对项目根。
|
|
842
|
+
"""
|
|
843
|
+
command, prefix = _absolute_bugx_launcher()
|
|
844
|
+
root_str = str(root)
|
|
845
|
+
for entry in desired.values():
|
|
846
|
+
args = entry.get("args")
|
|
847
|
+
if entry.get("command") == "bugx":
|
|
848
|
+
entry["command"] = command
|
|
849
|
+
if prefix and isinstance(args, list):
|
|
850
|
+
# 兜底形态:解释器 + 模块入口,前缀必须与 pinned 参数一起落盘。
|
|
851
|
+
entry["args"] = args = [*prefix, *args]
|
|
852
|
+
if not isinstance(args, list):
|
|
853
|
+
continue
|
|
854
|
+
for index, token in enumerate(args):
|
|
855
|
+
if token == "--root" and index + 1 < len(args):
|
|
856
|
+
args[index + 1] = root_str
|
|
857
|
+
elif token == "--db" and index + 1 < len(args) \
|
|
858
|
+
and str(args[index + 1]).startswith(".bugx/"):
|
|
859
|
+
args[index + 1] = str(root / str(args[index + 1]))
|
|
860
|
+
return desired
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
def _mcp_entry_has_relative_paths(entry: object) -> bool:
|
|
864
|
+
"""宿主 MCP 条目 argv 是否仍携带相对 ``--root`` / ``--db`` 路径 token。
|
|
865
|
+
|
|
866
|
+
``mcp_write.requires_absolutize=True`` 宿主的**声明性过期**判据:这类宿主的
|
|
867
|
+
stdio MCP server 由宿主进程 spawn,cwd 不是工作区,相对 ``--root .`` 会解析
|
|
868
|
+
到宿主自己的目录而不是本项目(dsh/pi 实测同一陷阱,D3 遗留修复的过期语义)。
|
|
869
|
+
磁盘条目只要还是相对形态就判过期,触发重写为绝对根;绝对形态交给
|
|
870
|
+
``_host_mcp_entry_is_current`` 按 root 感知的 pinned 语义比对(幂等判定)。
|
|
871
|
+
"""
|
|
872
|
+
if not isinstance(entry, dict):
|
|
873
|
+
return False
|
|
874
|
+
args = entry.get("args")
|
|
875
|
+
if not isinstance(args, list):
|
|
876
|
+
return False
|
|
877
|
+
for index, token in enumerate(args):
|
|
878
|
+
if index + 1 >= len(args):
|
|
879
|
+
continue
|
|
880
|
+
value = args[index + 1]
|
|
881
|
+
if not isinstance(value, str):
|
|
882
|
+
continue
|
|
883
|
+
if token == "--root" and not Path(value).is_absolute():
|
|
884
|
+
return True
|
|
885
|
+
if token == "--db" and value.startswith(".bugx/"):
|
|
886
|
+
return True
|
|
887
|
+
return False
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
def _zcode_mcp_container_key() -> str:
|
|
891
|
+
"""ZCode MCP 容器的点分键;来自插件 ``mcp_write.container_key``(唯一事实)。"""
|
|
892
|
+
|
|
893
|
+
facet = engine_host_mcp_write("zcode")
|
|
894
|
+
if facet is None: # pragma: no cover - 插件缺失时 engine_host_mcp_write 已 fail-closed
|
|
895
|
+
raise CliError(
|
|
896
|
+
_i18n_exc("plugin.unknown_mcp_shape", "未知宿主 MCP 配置形态: zcode", shape="zcode")
|
|
897
|
+
)
|
|
898
|
+
return facet.container_key
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
def _zcode_global_server_definitions(
|
|
902
|
+
root: Path, *, optional_names: set[str] | None = None,
|
|
903
|
+
) -> dict[str, dict[str, object]]:
|
|
904
|
+
"""ZCode 用户级全局注册的期望定义:command/--root/--db 全部绝对化。"""
|
|
905
|
+
desired = _host_supervisor_server_definitions(
|
|
906
|
+
shape="zcode", optional_names=optional_names,
|
|
907
|
+
)
|
|
908
|
+
return _absolutize_server_definitions(desired, root)
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
def _global_server_definitions(
|
|
912
|
+
host_name: str, root: Path, *, optional_names: set[str] | None = None,
|
|
913
|
+
) -> dict[str, dict[str, object]]:
|
|
914
|
+
"""全局作用域宿主的期望定义:command/``--root``/``--db`` 全部绝对化。
|
|
915
|
+
|
|
916
|
+
全局注册(如 ``<DATA_DIR>/settings/<host>_mcp_settings.json``)里的 stdio server
|
|
917
|
+
可能由常驻守护进程(cwd 为 ``/``)spawn ⇒ ``--root .`` 不可用,必须绝对化。
|
|
918
|
+
"""
|
|
919
|
+
desired = _host_supervisor_server_definitions(
|
|
920
|
+
shape=str(host_name).strip().casefold(), optional_names=optional_names,
|
|
921
|
+
)
|
|
922
|
+
return _absolutize_server_definitions(desired, root)
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
def _same_mcp_arg(got: object, want: object, root: Path | None = None) -> bool:
|
|
926
|
+
"""单个参数是否等价:同字面,或同一条绝对路径的两种写法(支持相对 root 解析)。"""
|
|
927
|
+
if got == want:
|
|
928
|
+
return True
|
|
929
|
+
if not isinstance(got, str) or not isinstance(want, str):
|
|
930
|
+
return False
|
|
931
|
+
try:
|
|
932
|
+
got_path = (root / got) if (root and not Path(got).is_absolute()) else Path(got)
|
|
933
|
+
want_path = (root / want) if (root and not Path(want).is_absolute()) else Path(want)
|
|
934
|
+
return got_path.resolve() == want_path.resolve()
|
|
935
|
+
except OSError:
|
|
936
|
+
return False
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
def _launcher_kind(command: str) -> str:
|
|
940
|
+
"""启动器类别:``bugx``(原生启动器)/ ``python``(解释器)/ ``other:<name>``。"""
|
|
941
|
+
name = Path(command).name
|
|
942
|
+
if name in {"bugx", "bugx.js"}:
|
|
943
|
+
return "bugx"
|
|
944
|
+
if name.startswith("python") or name.startswith("pypy"):
|
|
945
|
+
return "python"
|
|
946
|
+
return f"other:{name}"
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
def _launchers_equivalent(got_cmd: str, got_args: list, want_cmd: str, want_args: list) -> bool:
|
|
950
|
+
"""两个启动器写法是否等价(原生启动器 ⇔ 解释器 + ``-m bugx_cli.cli``)。"""
|
|
951
|
+
got_kind, want_kind = _launcher_kind(got_cmd), _launcher_kind(want_cmd)
|
|
952
|
+
if got_kind == want_kind == "bugx":
|
|
953
|
+
return True
|
|
954
|
+
if got_kind == want_kind:
|
|
955
|
+
return got_cmd == want_cmd
|
|
956
|
+
if {got_kind, want_kind} != {"bugx", "python"}:
|
|
957
|
+
return False
|
|
958
|
+
prefix = _PYTHON_MODULE_LAUNCHER_PREFIX
|
|
959
|
+
if got_kind == "python" and list(got_args[: len(prefix)]) != prefix:
|
|
960
|
+
return False
|
|
961
|
+
if want_kind == "python" and list(want_args[: len(prefix)]) != prefix:
|
|
962
|
+
return False
|
|
963
|
+
return True
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
def _strip_launcher_prefix(args: list) -> list:
|
|
967
|
+
prefix = _PYTHON_MODULE_LAUNCHER_PREFIX
|
|
968
|
+
if list(args[: len(prefix)]) == prefix:
|
|
969
|
+
return list(args[len(prefix):])
|
|
970
|
+
return list(args)
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
def _tokens_equivalent(actual: list[str], expected: list[str], root: Path | None = None) -> bool:
|
|
974
|
+
"""两条完整命令(含启动器)是否语义等价——**唯一**的等价判定实现。
|
|
975
|
+
|
|
976
|
+
先比启动器类别(允许 ``python -m bugx_cli.cli`` 与原生 ``bugx`` 互为等价),
|
|
977
|
+
再剥掉模块入口前缀后逐参比对,因此两种写法的 token 数量可以不同。
|
|
978
|
+
"""
|
|
979
|
+
if not actual or not expected:
|
|
980
|
+
return False
|
|
981
|
+
if not _launchers_equivalent(actual[0], actual[1:], expected[0], expected[1:]):
|
|
982
|
+
return False
|
|
983
|
+
got_rest = _strip_launcher_prefix(actual[1:])
|
|
984
|
+
want_rest = _strip_launcher_prefix(expected[1:])
|
|
985
|
+
if len(got_rest) != len(want_rest):
|
|
986
|
+
return False
|
|
987
|
+
return all(_same_mcp_arg(got, want, root) for got, want in zip(got_rest, want_rest))
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
def _absolute_entry_is_current(
|
|
991
|
+
name: str, entry: object, desired: dict[str, dict[str, object]],
|
|
992
|
+
) -> bool:
|
|
993
|
+
"""用户级条目的时效判定:与本次期望定义**语义**相等,禁用即过期。
|
|
994
|
+
|
|
995
|
+
不在期望集内的名字(如未选装的 playwright/postmcp)回退到 pinned
|
|
996
|
+
相对 token 判定,保留"旧 bugx 装的托管条目要被清理"的既有语义。
|
|
997
|
+
|
|
998
|
+
``command`` 按启动器类别比较:``/abs/bin/bugx``、PATH 名 ``bugx`` 与
|
|
999
|
+
``<python> -m bugx_cli.cli`` 是同一件事的三种写法。角色、子命令、``--root``、
|
|
1000
|
+
``--db`` 仍逐项比对(路径按解析结果比较),因此「指向别的项目」依旧判过期。
|
|
1001
|
+
"""
|
|
1002
|
+
if not isinstance(entry, dict):
|
|
1003
|
+
return False
|
|
1004
|
+
if entry.get("disabled") is True or entry.get("enabled") is False:
|
|
1005
|
+
return False
|
|
1006
|
+
expected = desired.get(name)
|
|
1007
|
+
if expected is None:
|
|
1008
|
+
return _host_mcp_entry_is_current(name, entry)
|
|
1009
|
+
got_cmd = entry.get("command")
|
|
1010
|
+
want_cmd = expected.get("command")
|
|
1011
|
+
if not isinstance(got_cmd, str) or not isinstance(want_cmd, str):
|
|
1012
|
+
return False
|
|
1013
|
+
got_args = entry.get("args")
|
|
1014
|
+
want_args = expected.get("args")
|
|
1015
|
+
if not isinstance(got_args, list) or not isinstance(want_args, list):
|
|
1016
|
+
return False
|
|
1017
|
+
return _tokens_equivalent([got_cmd, *got_args], [want_cmd, *want_args])
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
def _prune_global_mcp_servers(servers: dict[str, object], current_root: Path, max_projects: int = 3) -> bool:
|
|
1021
|
+
"""终局加固补丁 13:全局配置孤儿修剪与 LRU 上限控制 (LRU Pruning & Active Ping)。
|
|
1022
|
+
|
|
1023
|
+
1. 物理存在性校验:扫描全局配置历史条目,若对应 --root 目录在磁盘上已不存在,物理删除该条目;
|
|
1024
|
+
2. LRU 数量硬上限:跨项目条目数限制为最多 max_projects(3) 个项目。
|
|
1025
|
+
"""
|
|
1026
|
+
changed = False
|
|
1027
|
+
project_entries: dict[str, list[str]] = {}
|
|
1028
|
+
for server_name, server_cfg in list(servers.items()):
|
|
1029
|
+
if not str(server_name).startswith("bugx-supervisor") and not str(server_name).startswith("bugx-docs"):
|
|
1030
|
+
continue
|
|
1031
|
+
if not isinstance(server_cfg, dict):
|
|
1032
|
+
continue
|
|
1033
|
+
args = server_cfg.get("args")
|
|
1034
|
+
root_path = None
|
|
1035
|
+
if isinstance(args, list):
|
|
1036
|
+
for i, arg in enumerate(args):
|
|
1037
|
+
if arg == "--root" and i + 1 < len(args):
|
|
1038
|
+
root_path = str(args[i + 1])
|
|
1039
|
+
break
|
|
1040
|
+
if root_path:
|
|
1041
|
+
p = Path(root_path)
|
|
1042
|
+
# 物理存在性校验:若磁盘目录已不存在,立即物理剔除
|
|
1043
|
+
if not p.is_dir():
|
|
1044
|
+
servers.pop(server_name, None)
|
|
1045
|
+
changed = True
|
|
1046
|
+
continue
|
|
1047
|
+
norm_root = str(p.resolve())
|
|
1048
|
+
project_entries.setdefault(norm_root, []).append(server_name)
|
|
1049
|
+
|
|
1050
|
+
current_root_norm = str(current_root.resolve())
|
|
1051
|
+
# 若项目数超出上限(保留当前项目 + 其他项目最多 3 个)
|
|
1052
|
+
if len(project_entries) > max_projects:
|
|
1053
|
+
removable_roots = [r for r in project_entries if r != current_root_norm]
|
|
1054
|
+
overflow_count = len(project_entries) - max_projects
|
|
1055
|
+
for root_to_drop in removable_roots[:overflow_count]:
|
|
1056
|
+
for entry_name in project_entries[root_to_drop]:
|
|
1057
|
+
servers.pop(entry_name, None)
|
|
1058
|
+
changed = True
|
|
1059
|
+
|
|
1060
|
+
return changed
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
def _validate_global_supervisor_mcp(host_name: str, root: Path) -> tuple[bool, str]:
|
|
1064
|
+
"""校验全局作用域宿主配置内的 BugX MCP 注册(指向本项目的绝对路径)。"""
|
|
1065
|
+
target = _host_global_mcp_target(host_name, root)
|
|
1066
|
+
if target is None:
|
|
1067
|
+
return False, _i18n_prompt(
|
|
1068
|
+
"plugin.global_mcp_path_unknown",
|
|
1069
|
+
f"宿主 {host_name} 未声明全局 MCP 配置路径,无法校验",
|
|
1070
|
+
host_name=host_name,
|
|
1071
|
+
)
|
|
1072
|
+
path = target
|
|
1073
|
+
servers = _read_host_json_servers(path, "flat")
|
|
1074
|
+
if not servers:
|
|
1075
|
+
return False, _i18n_prompt(
|
|
1076
|
+
"plugin.mcp_not_found",
|
|
1077
|
+
"未找到 bugx-supervisor host/worker 双通道 MCP 配置;请运行 bugx install --agent",
|
|
1078
|
+
)
|
|
1079
|
+
desired = _global_server_definitions(host_name, root)
|
|
1080
|
+
missing_or_stale = [
|
|
1081
|
+
name for name in HOST_ALL_MCP
|
|
1082
|
+
if not _absolute_entry_is_current(name, servers.get(name), desired)
|
|
1083
|
+
]
|
|
1084
|
+
if not missing_or_stale:
|
|
1085
|
+
return True, _i18n_prompt(
|
|
1086
|
+
"plugin.mcp_registered",
|
|
1087
|
+
f"已在 {path} 注册并启用 bugx-supervisor host/worker 双通道与 docs 服务",
|
|
1088
|
+
path=path,
|
|
1089
|
+
)
|
|
1090
|
+
detail = _i18n_prompt(
|
|
1091
|
+
"plugin.mcp_missing_or_stale",
|
|
1092
|
+
f"{path}(缺失或过期:{', '.join(missing_or_stale)})",
|
|
1093
|
+
path=path, items=", ".join(missing_or_stale),
|
|
1094
|
+
)
|
|
1095
|
+
return False, _i18n_prompt(
|
|
1096
|
+
"plugin.mcp_incomplete",
|
|
1097
|
+
f"MCP 配置不完整:{detail};请运行 bugx install --agent",
|
|
1098
|
+
details=detail,
|
|
1099
|
+
)
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
def _validate_zcode_global_supervisor_mcp(root: Path) -> tuple[bool, str]:
|
|
1103
|
+
"""校验 ZCode 用户级全局配置中的 BugX MCP 注册(指向本项目的绝对路径)。"""
|
|
1104
|
+
servers = _read_host_json_servers(_zcode_config_path(), _zcode_mcp_container_key())
|
|
1105
|
+
if not servers:
|
|
1106
|
+
return False, _i18n_prompt(
|
|
1107
|
+
"plugin.mcp_not_found",
|
|
1108
|
+
"未找到 bugx-supervisor host/worker 双通道 MCP 配置;请运行 bugx install --agent",
|
|
1109
|
+
)
|
|
1110
|
+
desired = _zcode_global_server_definitions(root)
|
|
1111
|
+
missing_or_stale = [
|
|
1112
|
+
name for name in HOST_ALL_MCP
|
|
1113
|
+
if not _absolute_entry_is_current(name, servers.get(name), desired)
|
|
1114
|
+
]
|
|
1115
|
+
if not missing_or_stale:
|
|
1116
|
+
return True, _i18n_prompt(
|
|
1117
|
+
"plugin.mcp_registered",
|
|
1118
|
+
f"已在 {_zcode_config_path()} 注册并启用 bugx-supervisor host/worker 双通道与 docs 服务",
|
|
1119
|
+
path=_zcode_config_path(),
|
|
1120
|
+
)
|
|
1121
|
+
detail = _i18n_prompt(
|
|
1122
|
+
"plugin.mcp_missing_or_stale",
|
|
1123
|
+
f"{_zcode_config_path()}(缺失或过期:{', '.join(missing_or_stale)})",
|
|
1124
|
+
path=_zcode_config_path(), items=", ".join(missing_or_stale),
|
|
1125
|
+
)
|
|
1126
|
+
return False, _i18n_prompt(
|
|
1127
|
+
"plugin.mcp_incomplete",
|
|
1128
|
+
f"MCP 配置不完整:{detail};请运行 bugx install --agent",
|
|
1129
|
+
details=detail,
|
|
1130
|
+
)
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
def _zcode_bound_project_root() -> Path | None:
|
|
1134
|
+
"""读取用户级全局配置中 BugX 三通道当前绑定的 ``--root``(归一化绝对路径)。
|
|
1135
|
+
|
|
1136
|
+
ZCode 的 MCP 注册是用户级全局单例:三通道 ``--root`` 指向最后一次
|
|
1137
|
+
``bugx install --agent zcode`` 的项目。install 需要在重写前拿到这个
|
|
1138
|
+
既有绑定,才能判定"切换了挖掘项目"并输出明确提示。返回 ``None``
|
|
1139
|
+
表示没有可比较的既有绑定(未注册、无法解析或各通道根不一致)。
|
|
1140
|
+
"""
|
|
1141
|
+
servers = _read_host_json_servers(_zcode_config_path(), _zcode_mcp_container_key())
|
|
1142
|
+
roots: set[str] = set()
|
|
1143
|
+
for name in HOST_ALL_MCP:
|
|
1144
|
+
entry = servers.get(name)
|
|
1145
|
+
if not isinstance(entry, dict):
|
|
1146
|
+
continue
|
|
1147
|
+
args = entry.get("args")
|
|
1148
|
+
if not isinstance(args, list):
|
|
1149
|
+
continue
|
|
1150
|
+
for index, token in enumerate(args):
|
|
1151
|
+
if token == "--root" and index + 1 < len(args) \
|
|
1152
|
+
and isinstance(args[index + 1], str):
|
|
1153
|
+
roots.add(args[index + 1])
|
|
1154
|
+
break
|
|
1155
|
+
if len(roots) != 1:
|
|
1156
|
+
return None
|
|
1157
|
+
(only,) = roots
|
|
1158
|
+
return Path(only).resolve()
|
|
1159
|
+
|
|
1160
|
+
|
|
1161
|
+
def _expand_pinned_expected(expected: list[str], root: Path | None) -> list[str]:
|
|
1162
|
+
"""把 pinned 模板里的 ``--root .`` / ``--db .bugx/...`` 展开为绝对路径。"""
|
|
1163
|
+
expanded = list(expected)
|
|
1164
|
+
if root is None:
|
|
1165
|
+
return expanded
|
|
1166
|
+
for index, token in enumerate(expanded):
|
|
1167
|
+
if index + 1 >= len(expanded):
|
|
1168
|
+
continue
|
|
1169
|
+
if token == "--root" and expanded[index + 1] == ".":
|
|
1170
|
+
expanded[index + 1] = str(root)
|
|
1171
|
+
elif token == "--db" and str(expanded[index + 1]).startswith(".bugx/"):
|
|
1172
|
+
expanded[index + 1] = str(root / str(expanded[index + 1]))
|
|
1173
|
+
return expanded
|
|
1174
|
+
|
|
1175
|
+
|
|
1176
|
+
def _mcp_tokens_match(
|
|
1177
|
+
actual: list[str], expected: list[str], root: Path | None = None,
|
|
1178
|
+
) -> bool:
|
|
1179
|
+
"""比较宿主 MCP 条目 tokens 与 pinned 模板,按**语义**而非字面。
|
|
1180
|
+
|
|
1181
|
+
合法安装有等价写法:项目级 ``bugx mcp serve --root . --role host``(pinned)与
|
|
1182
|
+
用户级 ``/abs/bin/bugx mcp serve --root /abs/project --role host``。旧实现做字面
|
|
1183
|
+
token 相等 ⇒ 任何绝对安装永远被判「missing or stale」(实测 cline/zcode 长期红项)。
|
|
1184
|
+
|
|
1185
|
+
收敛后只有一条比较流水线:pinned 模板先按本次根展开,再交给
|
|
1186
|
+
``_tokens_equivalent``(启动器类别 + 逐参路径等价)。角色/子命令/顺序仍严格
|
|
1187
|
+
相等,所以「指向别的项目」「角色写错」「db 写错」依旧判过期。
|
|
1188
|
+
"""
|
|
1189
|
+
return _tokens_equivalent(actual, _expand_pinned_expected(expected, root), root)
|
|
1190
|
+
|
|
1191
|
+
|
|
1192
|
+
def _host_mcp_entry_is_current(
|
|
1193
|
+
name: str, entry: object, root: Path | None = None,
|
|
1194
|
+
) -> bool:
|
|
1195
|
+
"""Check one BugX host/worker entry without treating mere key presence as ready."""
|
|
1196
|
+
if not isinstance(entry, dict):
|
|
1197
|
+
return False
|
|
1198
|
+
if entry.get("disabled") is True or entry.get("enabled") is False:
|
|
1199
|
+
return False
|
|
1200
|
+
expected = OPENCODE_PINNED_MCP_COMMANDS.get(name)
|
|
1201
|
+
if not expected:
|
|
1202
|
+
return False
|
|
1203
|
+
actual = _host_mcp_command_tokens(entry)
|
|
1204
|
+
return _mcp_tokens_match(actual, expected, root)
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
def _load_json_object(path: Path, label: str) -> dict[str, object]:
|
|
1208
|
+
if path.is_symlink():
|
|
1209
|
+
raise CliError(_i18n_exc("plugin.mcp_symlink_config_refused", f"拒绝写入符号链接 {label} 配置: {path}", label=label, path=path))
|
|
1210
|
+
if not path.exists():
|
|
1211
|
+
return {}
|
|
1212
|
+
if not path.is_file():
|
|
1213
|
+
raise CliError(_i18n_exc("plugin.mcp_config_not_regular_file", f"{label} 配置不是普通文件,拒绝写入: {path}", label=label, path=path))
|
|
1214
|
+
try:
|
|
1215
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
1216
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
1217
|
+
raise CliError(_i18n_exc("plugin.mcp_config_unparseable", f"{label} 配置无法解析,拒绝写入: {path}: {exc}", label=label, path=path, exc=exc)) from exc
|
|
1218
|
+
if not isinstance(payload, dict):
|
|
1219
|
+
raise CliError(_i18n_exc("plugin.mcp_config_not_json_object", f"{label} 配置顶层必须是 JSON 对象,拒绝写入: {path}", label=label, path=path))
|
|
1220
|
+
return payload
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
def write_host_mcp_config(
|
|
1224
|
+
root: Path, host_name: str, *, optional_names: set[str] | None = None,
|
|
1225
|
+
) -> tuple[str, Path, Path | None, bool]:
|
|
1226
|
+
"""Idempotently register both BugX MCP channels in a host-native file.
|
|
1227
|
+
|
|
1228
|
+
Return ``(status, path, backup, created)``. Only BugX's two reserved
|
|
1229
|
+
names are changed; unrelated host settings and MCP servers remain intact.
|
|
1230
|
+
"""
|
|
1231
|
+
root = root.resolve()
|
|
1232
|
+
if _global_only_mcp_host(host_name):
|
|
1233
|
+
# 只有用户级/全局作用域:项目内没有会被加载的 MCP 文件(插件
|
|
1234
|
+
# ``mcp_write.project_relpath is None`` 即此语义)。
|
|
1235
|
+
host_plugin = engine_host_mcp_write(host_name)
|
|
1236
|
+
if host_plugin is not None and host_plugin.bootstrap is not None:
|
|
1237
|
+
# 写入实现由插件 ``mcp_write.bootstrap`` 拥有:宿主配置不是
|
|
1238
|
+
# 「JSON 容器键」形态(dsh 的 cordis patch 是 YAML **list**,通用
|
|
1239
|
+
# 骨架既解析不了也会把 ``[]`` 判成「顶层不是对象」直接拒绝写入)。
|
|
1240
|
+
result = host_plugin.bootstrap(
|
|
1241
|
+
root,
|
|
1242
|
+
_global_server_definitions(
|
|
1243
|
+
host_name, root, optional_names=optional_names,
|
|
1244
|
+
),
|
|
1245
|
+
)
|
|
1246
|
+
written = result.get("path")
|
|
1247
|
+
return (
|
|
1248
|
+
"merged" if result.get("changed") else "unchanged",
|
|
1249
|
+
Path(str(written)) if written else Path(""),
|
|
1250
|
+
None,
|
|
1251
|
+
False,
|
|
1252
|
+
)
|
|
1253
|
+
target = _host_global_mcp_target(host_name, root)
|
|
1254
|
+
if target is None:
|
|
1255
|
+
raise CliError(
|
|
1256
|
+
_i18n_exc(
|
|
1257
|
+
"plugin.global_mcp_path_unknown",
|
|
1258
|
+
f"宿主 {host_name} 未声明全局 MCP 配置路径,拒绝写入",
|
|
1259
|
+
host_name=host_name,
|
|
1260
|
+
)
|
|
1261
|
+
)
|
|
1262
|
+
payload = _load_json_object(target, engine_host_label(host_name))
|
|
1263
|
+
servers_key = host_plugin.container_key
|
|
1264
|
+
container = payload
|
|
1265
|
+
keys = servers_key.split(".")
|
|
1266
|
+
for k in keys[:-1]:
|
|
1267
|
+
child = container.get(k)
|
|
1268
|
+
if not isinstance(child, dict):
|
|
1269
|
+
child = {}
|
|
1270
|
+
container[k] = child
|
|
1271
|
+
container = child
|
|
1272
|
+
leaf_key = keys[-1]
|
|
1273
|
+
servers = container.get(leaf_key)
|
|
1274
|
+
if servers is None:
|
|
1275
|
+
servers = {}
|
|
1276
|
+
container[leaf_key] = servers
|
|
1277
|
+
if not isinstance(servers, dict):
|
|
1278
|
+
raise CliError(
|
|
1279
|
+
_i18n_exc(
|
|
1280
|
+
"plugin.host_servers_not_object",
|
|
1281
|
+
f"{engine_host_label(host_name)} 配置 {servers_key} 不是对象,拒绝写入: {target}",
|
|
1282
|
+
servers_key=servers_key,
|
|
1283
|
+
target=target,
|
|
1284
|
+
)
|
|
1285
|
+
)
|
|
1286
|
+
desired = _global_server_definitions(host_name, root, optional_names=optional_names)
|
|
1287
|
+
elif (
|
|
1288
|
+
(migrated := engine_host_mcp_write(host_name)) is not None
|
|
1289
|
+
and migrated.config_format == "toml"
|
|
1290
|
+
and migrated.bootstrap is not None
|
|
1291
|
+
):
|
|
1292
|
+
# TOML 宿主:写入 / 项目信任 / 回执全部由插件拥有。通用 JSON 骨架在这里只会
|
|
1293
|
+
# 产出死配置(Codex 从不加载 ``.codex/config.json``),因此直接委托插件,
|
|
1294
|
+
# 不再复制一份宿主实现。
|
|
1295
|
+
desired = _host_supervisor_server_definitions(
|
|
1296
|
+
shape=str(host_name).strip().casefold(), optional_names=optional_names,
|
|
1297
|
+
)
|
|
1298
|
+
result = migrated.bootstrap(root, desired)
|
|
1299
|
+
relpath = migrated.project_relpath or ""
|
|
1300
|
+
target = Path(str(result.get("config_path") or (root / relpath)))
|
|
1301
|
+
raw_backup = result.get("backup")
|
|
1302
|
+
backup = Path(str(raw_backup)) if raw_backup else None
|
|
1303
|
+
changed = bool(
|
|
1304
|
+
result.get("config_changed")
|
|
1305
|
+
or result.get("trust_changed")
|
|
1306
|
+
or result.get("legacy_removed")
|
|
1307
|
+
)
|
|
1308
|
+
if not changed:
|
|
1309
|
+
return "unchanged", target, None, False
|
|
1310
|
+
return ("merged" if backup is not None else "created"), target, backup, bool(
|
|
1311
|
+
result.get("created")
|
|
1312
|
+
)
|
|
1313
|
+
elif (
|
|
1314
|
+
(migrated := engine_host_mcp_write(host_name)) is not None
|
|
1315
|
+
and migrated.project_relpath
|
|
1316
|
+
and not migrated.custom_writer
|
|
1317
|
+
):
|
|
1318
|
+
# 已迁移宿主:目标路径/容器键/条目附加字段全部来自插件 ``mcp_write``。
|
|
1319
|
+
target = root / migrated.project_relpath
|
|
1320
|
+
payload = _load_json_object(target, engine_host_label(host_name))
|
|
1321
|
+
servers_key = migrated.container_key
|
|
1322
|
+
servers = payload.get(servers_key)
|
|
1323
|
+
if servers is None:
|
|
1324
|
+
servers = {}
|
|
1325
|
+
payload[servers_key] = servers
|
|
1326
|
+
if not isinstance(servers, dict):
|
|
1327
|
+
raise CliError(
|
|
1328
|
+
_i18n_exc(
|
|
1329
|
+
"plugin.host_servers_not_object",
|
|
1330
|
+
f"{engine_host_label(host_name)} 配置 {servers_key} 不是对象,拒绝写入: {target}",
|
|
1331
|
+
servers_key=servers_key,
|
|
1332
|
+
target=target,
|
|
1333
|
+
)
|
|
1334
|
+
)
|
|
1335
|
+
desired = _host_supervisor_server_definitions(
|
|
1336
|
+
shape=str(host_name).strip().casefold(), optional_names=optional_names,
|
|
1337
|
+
)
|
|
1338
|
+
if migrated.requires_absolutize:
|
|
1339
|
+
# 宿主声明 ``requires_absolutize=True`` 时按契约落盘**绝对**根(D3
|
|
1340
|
+
# 遗留修复:通用骨架此前无视该声明写相对 ``--root .``)。这类宿主的
|
|
1341
|
+
# stdio MCP server 由宿主进程 spawn,cwd 不是工作区,相对根会解析到
|
|
1342
|
+
# 宿主目录。语义与 dsh/pi bootstrap 一致:绝对化后同根重跑逐字段
|
|
1343
|
+
# 相等 ⇒ changed=False;换根则按本次根重写。
|
|
1344
|
+
_absolutize_server_definitions(desired, root)
|
|
1345
|
+
elif host_name == "funide":
|
|
1346
|
+
target = root / ".mcp.json"
|
|
1347
|
+
payload = _load_json_object(target, "FunIDE")
|
|
1348
|
+
servers_key = "mcpServers"
|
|
1349
|
+
servers = payload.get(servers_key)
|
|
1350
|
+
if servers is None:
|
|
1351
|
+
servers = {}
|
|
1352
|
+
payload[servers_key] = servers
|
|
1353
|
+
if not isinstance(servers, dict):
|
|
1354
|
+
raise CliError(_i18n_exc("plugin.funide_servers_not_object", f"FunIDE 配置 {servers_key} 不是对象,拒绝写入: {target}", servers_key=servers_key, target=target))
|
|
1355
|
+
desired = _host_supervisor_server_definitions(shape="funide", optional_names=optional_names)
|
|
1356
|
+
elif host_name in {"chatgpt", "workbuddy", "codebuddy"}:
|
|
1357
|
+
# pi / dsh 已迁移为插件:分别走上方通用 JSON 骨架分支(requires_absolutize
|
|
1358
|
+
# 声明绝对化)与全局分支(project_relpath=None),这里的遗留路径已不可达。
|
|
1359
|
+
target = root / {
|
|
1360
|
+
"chatgpt": ".agents/mcp.json",
|
|
1361
|
+
"workbuddy": ".workbuddy/mcp.json",
|
|
1362
|
+
"codebuddy": ".codebuddy/mcp.json",
|
|
1363
|
+
}[host_name]
|
|
1364
|
+
payload = _load_json_object(target, host_name)
|
|
1365
|
+
servers_key = "mcpServers"
|
|
1366
|
+
servers = payload.setdefault(servers_key, {})
|
|
1367
|
+
if not isinstance(servers, dict):
|
|
1368
|
+
raise CliError(f"{host_name} 配置 {servers_key} 不是对象,拒绝写入: {target}")
|
|
1369
|
+
desired = _host_supervisor_server_definitions(
|
|
1370
|
+
shape="workbuddy" if host_name == "codebuddy" else host_name,
|
|
1371
|
+
optional_names=optional_names,
|
|
1372
|
+
)
|
|
1373
|
+
elif host_name == "qoder":
|
|
1374
|
+
target = root / ".qoder" / "mcp.json"
|
|
1375
|
+
payload = _load_json_object(target, "Qoder")
|
|
1376
|
+
servers_key = "mcpServers"
|
|
1377
|
+
servers = payload.get(servers_key)
|
|
1378
|
+
if servers is None:
|
|
1379
|
+
servers = {}
|
|
1380
|
+
payload[servers_key] = servers
|
|
1381
|
+
if not isinstance(servers, dict):
|
|
1382
|
+
raise CliError(_i18n_exc("plugin.qoder_servers_not_object", f"Qoder 配置 {servers_key} 不是对象,拒绝写入: {target}", servers_key=servers_key, target=target))
|
|
1383
|
+
desired = _host_supervisor_server_definitions(shape="qoder", optional_names=optional_names)
|
|
1384
|
+
elif host_name == "trea":
|
|
1385
|
+
# DOC-169:补全 Trea 的项目级 MCP 写入(flat 形态,与 qoder 同构)。
|
|
1386
|
+
target = root / ".trea" / "mcp.json"
|
|
1387
|
+
payload = _load_json_object(target, "Trea")
|
|
1388
|
+
servers_key = "mcpServers"
|
|
1389
|
+
servers = payload.get(servers_key)
|
|
1390
|
+
if servers is None:
|
|
1391
|
+
servers = {}
|
|
1392
|
+
payload[servers_key] = servers
|
|
1393
|
+
if not isinstance(servers, dict):
|
|
1394
|
+
raise CliError(_i18n_exc("plugin.trea_servers_not_object", f"Trea 配置 {servers_key} 不是对象,拒绝写入: {target}", servers_key=servers_key, target=target))
|
|
1395
|
+
desired = _host_supervisor_server_definitions(shape="trea", optional_names=optional_names)
|
|
1396
|
+
else:
|
|
1397
|
+
raise CliError(_i18n_exc("plugin.unsupported_mcp_host", f"不支持写入 MCP 的宿主: {host_name}", host_name=host_name))
|
|
1398
|
+
|
|
1399
|
+
changed = False
|
|
1400
|
+
upgraded = False
|
|
1401
|
+
# ZCode 全局注册使用绝对 command/--root,不能拿 OPENCODE_PINNED_MCP_COMMANDS
|
|
1402
|
+
# 的相对 token 判定时效;按本次构造的期望定义逐字段相等比对。
|
|
1403
|
+
if host_name == "zcode" or _global_only_mcp_host(host_name):
|
|
1404
|
+
if _prune_global_mcp_servers(servers, root):
|
|
1405
|
+
changed = True
|
|
1406
|
+
# 全局作用域宿主按「与本次绝对化期望逐字段相等」判定时效,不能用相对 token。
|
|
1407
|
+
def _entry_is_current(name: str, current: object) -> bool:
|
|
1408
|
+
return _absolute_entry_is_current(name, current, desired)
|
|
1409
|
+
else:
|
|
1410
|
+
_absolutize_facet = engine_host_mcp_write(host_name)
|
|
1411
|
+
if _absolutize_facet is not None and _absolutize_facet.requires_absolutize:
|
|
1412
|
+
def _entry_is_current(name: str, current: object) -> bool:
|
|
1413
|
+
# 声明绝对化的宿主(pi/claude…):相对 --root/--db 是声明性过期,
|
|
1414
|
+
# 必须重写为绝对根;绝对形态按 root 感知的 pinned 语义比对——
|
|
1415
|
+
# 同根重跑逐字段相等 ⇒ unchanged(幂等,不依赖 CLI 进程 cwd)。
|
|
1416
|
+
if _mcp_entry_has_relative_paths(current):
|
|
1417
|
+
return False
|
|
1418
|
+
return _host_mcp_entry_is_current(name, current, root)
|
|
1419
|
+
else:
|
|
1420
|
+
_entry_is_current = _host_mcp_entry_is_current
|
|
1421
|
+
optional_managed = {"playwright", "postmcp"}
|
|
1422
|
+
for name in optional_managed - set(optional_names or set()):
|
|
1423
|
+
current = servers.get(name)
|
|
1424
|
+
if _entry_is_current(name, current):
|
|
1425
|
+
servers.pop(name, None)
|
|
1426
|
+
changed = True
|
|
1427
|
+
for name, expected in desired.items():
|
|
1428
|
+
current = servers.get(name)
|
|
1429
|
+
if not isinstance(current, dict):
|
|
1430
|
+
servers[name] = copy.deepcopy(expected)
|
|
1431
|
+
changed = True
|
|
1432
|
+
continue
|
|
1433
|
+
if not _entry_is_current(name, current):
|
|
1434
|
+
merged = copy.deepcopy(current)
|
|
1435
|
+
merged.update(copy.deepcopy(expected))
|
|
1436
|
+
servers[name] = merged
|
|
1437
|
+
changed = True
|
|
1438
|
+
upgraded = True
|
|
1439
|
+
mirror_targets = _host_mcp_mirror_targets(host_name, root)
|
|
1440
|
+
for mirror_host, mirror_target in mirror_targets:
|
|
1441
|
+
_sync_mcp_mirror(host_name, mirror_host, mirror_target, desired,
|
|
1442
|
+
optional_names=optional_names)
|
|
1443
|
+
if host_name == "trea":
|
|
1444
|
+
_sync_trae_mcp_mirror(root, desired, optional_names=optional_names)
|
|
1445
|
+
if not changed:
|
|
1446
|
+
return "unchanged", target, None, False
|
|
1447
|
+
|
|
1448
|
+
backup = _backup_host_resource(root, host_name, target) if target.exists() else None
|
|
1449
|
+
_atomic_write_global_file(
|
|
1450
|
+
target,
|
|
1451
|
+
json.dumps(payload, ensure_ascii=False, indent=2).encode("utf-8") + b"\n",
|
|
1452
|
+
)
|
|
1453
|
+
result = ("upgraded" if upgraded else "merged" if backup else "created"), target, backup, backup is None
|
|
1454
|
+
return result
|
|
1455
|
+
|
|
1456
|
+
|
|
1457
|
+
def _restore_host_mcp_config_change(
|
|
1458
|
+
target: Path, backup: Path | None, created: bool,
|
|
1459
|
+
) -> None:
|
|
1460
|
+
"""Best-effort rollback for a project host MCP write in the install transaction."""
|
|
1461
|
+
try:
|
|
1462
|
+
if backup is not None and backup.is_file():
|
|
1463
|
+
_atomic_write_global_file(target, backup.read_bytes())
|
|
1464
|
+
elif created and target.is_file() and not target.is_symlink():
|
|
1465
|
+
target.unlink()
|
|
1466
|
+
except OSError:
|
|
1467
|
+
# The original install error is more useful than a secondary rollback
|
|
1468
|
+
# error; the backup remains available under the project .bugx tree.
|
|
1469
|
+
pass
|
|
1470
|
+
|
|
1471
|
+
|
|
1472
|
+
def _read_host_json_servers(path: Path, shape: str) -> dict[str, object]:
|
|
1473
|
+
"""Read one native host MCP map for doctor without treating key presence as ready."""
|
|
1474
|
+
if path.is_symlink() or not path.is_file():
|
|
1475
|
+
return {}
|
|
1476
|
+
try:
|
|
1477
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
1478
|
+
except (OSError, json.JSONDecodeError):
|
|
1479
|
+
return {}
|
|
1480
|
+
if not isinstance(payload, dict):
|
|
1481
|
+
return {}
|
|
1482
|
+
if "." in shape:
|
|
1483
|
+
container = payload
|
|
1484
|
+
keys = shape.split(".")
|
|
1485
|
+
for key in keys[:-1]:
|
|
1486
|
+
child = container.get(key)
|
|
1487
|
+
if not isinstance(child, dict):
|
|
1488
|
+
container = {}
|
|
1489
|
+
break
|
|
1490
|
+
container = child
|
|
1491
|
+
servers = container.get(keys[-1])
|
|
1492
|
+
elif shape == "funide":
|
|
1493
|
+
# FunIDE's profile-level MCP resource is the VS Code-compatible
|
|
1494
|
+
# ``<User>/mcp.json`` shape: ``{"servers": {...}}``.
|
|
1495
|
+
servers = payload.get("servers")
|
|
1496
|
+
else:
|
|
1497
|
+
servers = payload.get("mcpServers")
|
|
1498
|
+
return servers if isinstance(servers, dict) else {}
|
|
1499
|
+
|
|
1500
|
+
|
|
1501
|
+
def _validate_host_supervisor_mcp(
|
|
1502
|
+
candidates: tuple[tuple[Path, str], ...],
|
|
1503
|
+
root: Path | None = None,
|
|
1504
|
+
) -> tuple[bool, str]:
|
|
1505
|
+
"""Require current, enabled host and worker entries in one native config.
|
|
1506
|
+
|
|
1507
|
+
``root`` 用于判定用户级绝对 ``--root`` 是否指向**本项目**(语义等价比对),
|
|
1508
|
+
缺省时只接受 pinned 相对形式。
|
|
1509
|
+
"""
|
|
1510
|
+
partial: list[str] = []
|
|
1511
|
+
for path, shape in candidates:
|
|
1512
|
+
servers = _read_host_json_servers(path, shape)
|
|
1513
|
+
if not servers:
|
|
1514
|
+
continue
|
|
1515
|
+
missing_or_stale = [
|
|
1516
|
+
name for name in HOST_ALL_MCP
|
|
1517
|
+
if not _host_mcp_entry_is_current(name, servers.get(name), root)
|
|
1518
|
+
]
|
|
1519
|
+
if not missing_or_stale:
|
|
1520
|
+
return True, _i18n_prompt("plugin.mcp_registered", f"已在 {path} 注册并启用 bugx-supervisor host/worker 双通道与 docs 服务", path=path)
|
|
1521
|
+
partial.append(_i18n_prompt("plugin.mcp_missing_or_stale", f"{path}(缺失或过期:{', '.join(missing_or_stale)})", path=path, items=', '.join(missing_or_stale)))
|
|
1522
|
+
if partial:
|
|
1523
|
+
return False, _i18n_prompt("plugin.mcp_incomplete", "MCP 配置不完整:" + ";".join(partial) + ";请运行 bugx install --agent", details=';'.join(partial))
|
|
1524
|
+
return False, _i18n_prompt("plugin.mcp_not_found", "未找到 bugx-supervisor host/worker 双通道 MCP 配置;请运行 bugx install --agent")
|
|
1525
|
+
|
|
1526
|
+
|
|
1527
|
+
def _chatgpt_global_plugin_root() -> Path:
|
|
1528
|
+
"""Return the one BugX-owned ChatGPT Plugin source for this machine.
|
|
1529
|
+
|
|
1530
|
+
ChatGPT/Codex marketplace registration is global, while the BugX project
|
|
1531
|
+
protocol is intentionally project-neutral and resolves ``.bugx`` from the
|
|
1532
|
+
active workspace. A stable global source therefore avoids one identical
|
|
1533
|
+
``bugx`` Skill being indexed once per project.
|
|
1534
|
+
"""
|
|
1535
|
+
override = os.environ.get("BUGX_CHATGPT_PLUGIN_ROOT")
|
|
1536
|
+
if override:
|
|
1537
|
+
return Path(override).expanduser()
|
|
1538
|
+
# macOS exposes the home directory through aliases such as /var; resolve
|
|
1539
|
+
# only this trusted system-provided prefix, while keeping user overrides
|
|
1540
|
+
# lexical so their symlink boundary can still be rejected.
|
|
1541
|
+
return Path.home().resolve(strict=False) / ".bugx" / CHATGPT_GLOBAL_PLUGIN_DIR_NAME
|
|
1542
|
+
|
|
1543
|
+
|
|
1544
|
+
def _codex_config_path() -> Path:
|
|
1545
|
+
"""Return Codex's registry path, with an isolation override for tests."""
|
|
1546
|
+
override = os.environ.get("BUGX_CODEX_CONFIG")
|
|
1547
|
+
if override:
|
|
1548
|
+
return Path(override).expanduser().resolve()
|
|
1549
|
+
return (Path.home() / ".codex" / "config.toml").resolve()
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
def _is_bugx_marketplace_source(root: Path) -> bool:
|
|
1553
|
+
"""Check whether a legacy local marketplace is a BugX project source.
|
|
1554
|
+
|
|
1555
|
+
Missing roots are considered stale BugX registrations because the name is
|
|
1556
|
+
reserved by this installer. Existing roots must still contain the
|
|
1557
|
+
expected BugX manifest before their registry entry may be migrated; this
|
|
1558
|
+
prevents a user-owned marketplace that merely resembles the name from
|
|
1559
|
+
being removed.
|
|
1560
|
+
"""
|
|
1561
|
+
if not root.exists():
|
|
1562
|
+
return True
|
|
1563
|
+
manifest = root / "plugins" / CHATGPT_PLUGIN_NAME / ".codex-plugin" / "plugin.json"
|
|
1564
|
+
if not manifest.is_file() or manifest.is_symlink():
|
|
1565
|
+
return False
|
|
1566
|
+
try:
|
|
1567
|
+
payload = json.loads(manifest.read_text(encoding="utf-8"))
|
|
1568
|
+
except (OSError, json.JSONDecodeError):
|
|
1569
|
+
return False
|
|
1570
|
+
return isinstance(payload, dict) and payload.get("name") == CHATGPT_PLUGIN_NAME
|
|
1571
|
+
|
|
1572
|
+
|
|
1573
|
+
def _legacy_chatgpt_marketplaces() -> tuple[list[str], list[str]]:
|
|
1574
|
+
"""Find BugX-generated marketplace registrations that can be migrated.
|
|
1575
|
+
|
|
1576
|
+
The result contains registry names and non-fatal diagnostics. Parsing is
|
|
1577
|
+
intentionally read-only; registry mutations are delegated to the
|
|
1578
|
+
supported ``codex plugin`` commands below.
|
|
1579
|
+
"""
|
|
1580
|
+
path = _codex_config_path()
|
|
1581
|
+
if not path.is_file() or path.is_symlink():
|
|
1582
|
+
return [], []
|
|
1583
|
+
try:
|
|
1584
|
+
payload = tomllib.loads(path.read_text(encoding="utf-8"))
|
|
1585
|
+
except (OSError, tomllib.TOMLDecodeError) as exc:
|
|
1586
|
+
return [], [_i18n_prompt("plugin.codex_registry_unreadable", f"无法读取 Codex 插件注册表,未迁移旧索引:{exc}", exc=exc)]
|
|
1587
|
+
marketplaces = payload.get("marketplaces", {})
|
|
1588
|
+
if not isinstance(marketplaces, dict):
|
|
1589
|
+
return [], []
|
|
1590
|
+
names: list[str] = []
|
|
1591
|
+
warnings: list[str] = []
|
|
1592
|
+
for name, metadata in marketplaces.items():
|
|
1593
|
+
if not isinstance(name, str) or not name.startswith(CHATGPT_LEGACY_MARKETPLACE_PREFIX):
|
|
1594
|
+
continue
|
|
1595
|
+
if not isinstance(metadata, dict) or metadata.get("source_type") != "local":
|
|
1596
|
+
continue
|
|
1597
|
+
source = metadata.get("source")
|
|
1598
|
+
if not isinstance(source, str) or not source.strip():
|
|
1599
|
+
warnings.append(_i18n_prompt("plugin.codex_migration_missing_source", f"{name}:缺少本地来源,未迁移", name=name))
|
|
1600
|
+
continue
|
|
1601
|
+
source_root = Path(source).expanduser()
|
|
1602
|
+
if not source_root.is_absolute():
|
|
1603
|
+
source_root = path.parent / source_root
|
|
1604
|
+
source_root = source_root.resolve(strict=False)
|
|
1605
|
+
if _is_bugx_marketplace_source(source_root):
|
|
1606
|
+
names.append(name)
|
|
1607
|
+
else:
|
|
1608
|
+
warnings.append(_i18n_prompt("plugin.codex_migration_foreign_source", f"{name}:来源不是可确认的 BugX Marketplace,保留", name=name))
|
|
1609
|
+
return names, warnings
|
|
1610
|
+
|
|
1611
|
+
|
|
1612
|
+
def _write_chatgpt_global_plugin(
|
|
1613
|
+
source: Path, *, locale: str | None = None,
|
|
1614
|
+
) -> tuple[Path, dict[str, object]]:
|
|
1615
|
+
"""Publish the canonical global ChatGPT Plugin atomically.
|
|
1616
|
+
|
|
1617
|
+
Returns ``(marketplace_path, shared_skill_status)``. ``~/.agents/skills/
|
|
1618
|
+
bugx/SKILL.md`` is the shared global skill surface (Pi consumes the same
|
|
1619
|
+
path); its write is best-effort but must be **observable** — 2026-11-09
|
|
1620
|
+
审计 P3:旧实现 ``except Exception: pass`` 会把符号链接/权限拒绝静默吞掉。
|
|
1621
|
+
"""
|
|
1622
|
+
root = _chatgpt_global_plugin_root()
|
|
1623
|
+
_assert_no_symlink_components(root)
|
|
1624
|
+
manifest_path = root / "plugins" / CHATGPT_PLUGIN_NAME / ".codex-plugin" / "plugin.json"
|
|
1625
|
+
marketplace_path = root / ".agents" / "plugins" / "marketplace.json"
|
|
1626
|
+
existing_manifest = manifest_path
|
|
1627
|
+
if existing_manifest.exists():
|
|
1628
|
+
if existing_manifest.is_symlink() or not existing_manifest.is_file():
|
|
1629
|
+
raise CliError(_i18n_exc("plugin.chatgpt_manifest_not_regular_file", f"拒绝覆盖非普通的全局 ChatGPT Plugin 清单: {existing_manifest}", path=existing_manifest))
|
|
1630
|
+
try:
|
|
1631
|
+
current = json.loads(existing_manifest.read_text(encoding="utf-8"))
|
|
1632
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
1633
|
+
raise CliError(_i18n_exc("plugin.chatgpt_manifest_unparseable", f"全局 ChatGPT Plugin 清单无法解析: {existing_manifest}: {exc}", path=existing_manifest, exc=exc)) from exc
|
|
1634
|
+
if not isinstance(current, dict) or current.get("name") != CHATGPT_PLUGIN_NAME:
|
|
1635
|
+
raise CliError(_i18n_exc("plugin.chatgpt_manifest_not_bugx", f"全局 ChatGPT Plugin 清单不是 BugX,拒绝覆盖: {existing_manifest}", path=existing_manifest))
|
|
1636
|
+
canonical_entry = {
|
|
1637
|
+
"name": CHATGPT_PLUGIN_NAME,
|
|
1638
|
+
"source": {"source": "local", "path": "./plugins/bugx"},
|
|
1639
|
+
"policy": {"installation": "AVAILABLE", "authentication": "ON_INSTALL"},
|
|
1640
|
+
"category": "Developer tools",
|
|
1641
|
+
}
|
|
1642
|
+
marketplace = {
|
|
1643
|
+
"name": CHATGPT_GLOBAL_MARKETPLACE_NAME,
|
|
1644
|
+
"interface": {"displayName": "BugX"},
|
|
1645
|
+
"plugins": [canonical_entry],
|
|
1646
|
+
}
|
|
1647
|
+
if marketplace_path.exists():
|
|
1648
|
+
if marketplace_path.is_symlink() or not marketplace_path.is_file():
|
|
1649
|
+
raise CliError(_i18n_exc("plugin.chatgpt_marketplace_not_regular_file", f"拒绝覆盖非普通的全局 Marketplace 清单: {marketplace_path}", path=marketplace_path))
|
|
1650
|
+
try:
|
|
1651
|
+
current_marketplace = json.loads(marketplace_path.read_text(encoding="utf-8"))
|
|
1652
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
1653
|
+
raise CliError(
|
|
1654
|
+
_i18n_exc("plugin.chatgpt_marketplace_unparseable", f"全局 Marketplace 清单无法解析,拒绝覆盖: {marketplace_path}: {exc}", path=marketplace_path, exc=exc)
|
|
1655
|
+
) from exc
|
|
1656
|
+
if not isinstance(current_marketplace, dict) \
|
|
1657
|
+
or current_marketplace.get("name") != CHATGPT_GLOBAL_MARKETPLACE_NAME \
|
|
1658
|
+
or not isinstance(current_marketplace.get("plugins"), list):
|
|
1659
|
+
raise CliError(
|
|
1660
|
+
_i18n_exc("plugin.chatgpt_marketplace_not_bugx", f"全局 Marketplace 清单不是 BugX 所有,拒绝覆盖: {marketplace_path}", path=marketplace_path)
|
|
1661
|
+
)
|
|
1662
|
+
preserved = [
|
|
1663
|
+
item for item in current_marketplace["plugins"]
|
|
1664
|
+
if not isinstance(item, dict) or item.get("name") != CHATGPT_PLUGIN_NAME
|
|
1665
|
+
]
|
|
1666
|
+
marketplace = dict(current_marketplace)
|
|
1667
|
+
marketplace["plugins"] = [canonical_entry, *preserved]
|
|
1668
|
+
generated = {
|
|
1669
|
+
root / "plugins" / CHATGPT_PLUGIN_NAME / ".codex-plugin" / "plugin.json": (
|
|
1670
|
+
json.dumps(_chatgpt_plugin_manifest(), ensure_ascii=False, indent=2) + "\n"
|
|
1671
|
+
).encode("utf-8"),
|
|
1672
|
+
root / "plugins" / CHATGPT_PLUGIN_NAME / "assets" / "bugx-avatar-512.png": (
|
|
1673
|
+
_chatgpt_plugin_icon_payload()
|
|
1674
|
+
),
|
|
1675
|
+
root / "plugins" / CHATGPT_PLUGIN_NAME / "skills" / "bugx" / "SKILL.md": (
|
|
1676
|
+
_chatgpt_skill_content(source, locale=locale).encode("utf-8")
|
|
1677
|
+
),
|
|
1678
|
+
marketplace_path: (json.dumps(marketplace, ensure_ascii=False, indent=2) + "\n").encode("utf-8"),
|
|
1679
|
+
}
|
|
1680
|
+
for target, content in generated.items():
|
|
1681
|
+
_atomic_write_global_file(target, content)
|
|
1682
|
+
home = Path.home().resolve()
|
|
1683
|
+
agents_skill_parent = (home / ".agents" / "skills").resolve(strict=False)
|
|
1684
|
+
shared_skill: dict[str, object] = {
|
|
1685
|
+
"status": "skipped",
|
|
1686
|
+
"path": str((home / ".agents" / "skills" / "bugx" / "SKILL.md")),
|
|
1687
|
+
"error": "shared skill dir escapes user home",
|
|
1688
|
+
}
|
|
1689
|
+
if agents_skill_parent.is_relative_to(home):
|
|
1690
|
+
target_skill = agents_skill_parent / "bugx" / "SKILL.md"
|
|
1691
|
+
try:
|
|
1692
|
+
_assert_no_symlink_components(agents_skill_parent)
|
|
1693
|
+
user_agents_skill_dir = agents_skill_parent / "bugx"
|
|
1694
|
+
_assert_no_symlink_components(user_agents_skill_dir)
|
|
1695
|
+
user_agents_skill_dir.mkdir(parents=True, exist_ok=True)
|
|
1696
|
+
_atomic_write_global_file(
|
|
1697
|
+
target_skill,
|
|
1698
|
+
_chatgpt_skill_content(source, locale=locale).encode("utf-8"),
|
|
1699
|
+
)
|
|
1700
|
+
shared_skill = {"status": "written", "path": str(target_skill), "error": None}
|
|
1701
|
+
except Exception as exc: # noqa: BLE001 - 共享面写入失败必须可观察,但不阻断主安装
|
|
1702
|
+
shared_skill = {
|
|
1703
|
+
"status": "failed",
|
|
1704
|
+
"path": str(target_skill),
|
|
1705
|
+
"error": f"{type(exc).__name__}: {str(exc)[:300]}",
|
|
1706
|
+
}
|
|
1707
|
+
return marketplace_path, shared_skill
|
|
1708
|
+
|
|
1709
|
+
|
|
1710
|
+
def _run_codex_cli(codex: str, command: list[str]) -> tuple[bool, str]:
|
|
1711
|
+
"""Run one bounded Codex registry command without exposing full output."""
|
|
1712
|
+
try:
|
|
1713
|
+
process = subprocess.run(
|
|
1714
|
+
[codex, *command], capture_output=True, text=True, check=False, timeout=30,
|
|
1715
|
+
)
|
|
1716
|
+
except (OSError, subprocess.TimeoutExpired) as exc:
|
|
1717
|
+
return False, str(exc)
|
|
1718
|
+
output = (process.stdout or process.stderr or "").strip()
|
|
1719
|
+
return process.returncode == 0, output[-500:]
|
|
1720
|
+
|
|
1721
|
+
|
|
1722
|
+
def _migrate_legacy_chatgpt_registrations(codex: str) -> dict[str, object]:
|
|
1723
|
+
"""Remove only BugX-owned legacy indexes before registering the singleton."""
|
|
1724
|
+
names, warnings = _legacy_chatgpt_marketplaces()
|
|
1725
|
+
removed: list[str] = []
|
|
1726
|
+
failures: list[str] = []
|
|
1727
|
+
for name in names:
|
|
1728
|
+
# Removing the marketplace is the essential operation. Plugin cache
|
|
1729
|
+
# removal is best effort because a broken source can prevent the CLI
|
|
1730
|
+
# from resolving the old plugin, while the registry entry is still
|
|
1731
|
+
# removable.
|
|
1732
|
+
plugin_ok, plugin_output = _run_codex_cli(
|
|
1733
|
+
codex, ["plugin", "remove", f"{CHATGPT_PLUGIN_NAME}@{name}", "--json"],
|
|
1734
|
+
)
|
|
1735
|
+
marketplace_ok, marketplace_output = _run_codex_cli(
|
|
1736
|
+
codex, ["plugin", "marketplace", "remove", name, "--json"],
|
|
1737
|
+
)
|
|
1738
|
+
if marketplace_ok:
|
|
1739
|
+
removed.append(name)
|
|
1740
|
+
else:
|
|
1741
|
+
detail = marketplace_output or plugin_output or _i18n_prompt("plugin.no_output", "无输出")
|
|
1742
|
+
failures.append(_i18n_prompt("plugin.codex_remove_marketplace_failed", f"{name}:无法移除 Marketplace({detail})", name=name, detail=detail))
|
|
1743
|
+
if not plugin_ok and plugin_output:
|
|
1744
|
+
warnings.append(_i18n_prompt("plugin.codex_cache_not_cleaned", f"{name}:旧插件缓存未清理(不影响索引迁移):{plugin_output}", name=name, output=plugin_output))
|
|
1745
|
+
return {"removed": removed, "warnings": warnings, "failures": failures}
|
|
1746
|
+
|
|
1747
|
+
|
|
1748
|
+
def _chatgpt_marketplace_paths(root: Path) -> tuple[Path, Path]:
|
|
1749
|
+
"""Return the logical and safe physical paths for the project catalog."""
|
|
1750
|
+
logical = root / ".agents" / "plugins" / "marketplace.json"
|
|
1751
|
+
agents_root = root / ".agents"
|
|
1752
|
+
if _is_reparse_point(agents_root):
|
|
1753
|
+
try:
|
|
1754
|
+
resolved_agents = agents_root.resolve(strict=True)
|
|
1755
|
+
except OSError as exc:
|
|
1756
|
+
raise CliError(_i18n_exc(
|
|
1757
|
+
"plugin.chatgpt_agents_target_unreadable",
|
|
1758
|
+
f"ChatGPT .agents 宿主目录链接无法解析,拒绝写入: {agents_root}: {exc}",
|
|
1759
|
+
path=agents_root, exc=exc,
|
|
1760
|
+
)) from exc
|
|
1761
|
+
if not resolved_agents.is_dir():
|
|
1762
|
+
raise CliError(_i18n_exc(
|
|
1763
|
+
"plugin.chatgpt_agents_target_not_directory",
|
|
1764
|
+
f"ChatGPT .agents 宿主目录链接目标不是目录,拒绝写入: {agents_root}",
|
|
1765
|
+
path=agents_root,
|
|
1766
|
+
))
|
|
1767
|
+
physical = resolved_agents / "plugins" / "marketplace.json"
|
|
1768
|
+
else:
|
|
1769
|
+
physical = logical
|
|
1770
|
+
_assert_no_symlink_components(physical)
|
|
1771
|
+
return logical, physical
|
|
1772
|
+
|
|
1773
|
+
|
|
1774
|
+
def _chatgpt_marketplace(root: Path) -> tuple[Path, Path, dict[str, object]]:
|
|
1775
|
+
"""Load and validate the repo marketplace before any writes."""
|
|
1776
|
+
logical_path, path = _chatgpt_marketplace_paths(root)
|
|
1777
|
+
if path.is_symlink():
|
|
1778
|
+
raise CliError(_i18n_exc("plugin.chatgpt_marketplace_symlink_refused", f"拒绝写入符号链接 ChatGPT Marketplace: {logical_path}", path=logical_path))
|
|
1779
|
+
if not path.exists():
|
|
1780
|
+
payload: dict[str, object] = {
|
|
1781
|
+
"name": _chatgpt_marketplace_name(root),
|
|
1782
|
+
"interface": {"displayName": "BugX Local Plugins"},
|
|
1783
|
+
"plugins": [],
|
|
1784
|
+
}
|
|
1785
|
+
return logical_path, path, payload
|
|
1786
|
+
try:
|
|
1787
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
1788
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
1789
|
+
raise CliError(_i18n_exc("plugin.chatgpt_local_marketplace_unreadable", f"ChatGPT Marketplace 无法读取,拒绝覆盖: {logical_path}: {exc}", path=logical_path, exc=exc)) from exc
|
|
1790
|
+
if not isinstance(payload, dict) or not isinstance(payload.get("plugins"), list):
|
|
1791
|
+
raise CliError(_i18n_exc("plugin.chatgpt_local_marketplace_missing_plugins", f"ChatGPT Marketplace 缺少有效 plugins 数组,拒绝覆盖: {logical_path}", path=logical_path))
|
|
1792
|
+
if not isinstance(payload.get("name"), str) or not payload["name"]:
|
|
1793
|
+
payload["name"] = _chatgpt_marketplace_name(root)
|
|
1794
|
+
if not isinstance(payload.get("interface"), dict):
|
|
1795
|
+
payload["interface"] = {"displayName": "BugX Local Plugins"}
|
|
1796
|
+
for item in payload["plugins"]:
|
|
1797
|
+
if not isinstance(item, dict) or not isinstance(item.get("name"), str):
|
|
1798
|
+
raise CliError(_i18n_exc("plugin.chatgpt_local_marketplace_invalid_plugin", f"ChatGPT Marketplace 含有无效插件条目,拒绝覆盖: {logical_path}", path=logical_path))
|
|
1799
|
+
if item.get("name") == CHATGPT_PLUGIN_NAME:
|
|
1800
|
+
existing_source = item.get("source")
|
|
1801
|
+
if existing_source not in (None, {
|
|
1802
|
+
"source": "local", "path": CHATGPT_PLUGIN_SOURCE,
|
|
1803
|
+
}):
|
|
1804
|
+
raise CliError(
|
|
1805
|
+
_i18n_exc("plugin.chatgpt_local_marketplace_foreign_bugx", "ChatGPT Marketplace 已存在非 BugX 本地来源的 bugx 插件,拒绝替换")
|
|
1806
|
+
)
|
|
1807
|
+
return logical_path, path, payload
|
|
1808
|
+
|
|
1809
|
+
|
|
1810
|
+
def _ensure_chatgpt_plugin(
|
|
1811
|
+
root: Path, source: Path, *, locale: str | None = None,
|
|
1812
|
+
) -> dict[str, object]:
|
|
1813
|
+
"""Create a full repo Plugin and optionally install it through Codex CLI.
|
|
1814
|
+
|
|
1815
|
+
The ChatGPT application does not expose a supported silent account-side
|
|
1816
|
+
install API. We therefore prepare the project marker, publish one stable
|
|
1817
|
+
machine-wide BugX marketplace, and use the supported Codex plugin commands
|
|
1818
|
+
when available. Legacy per-project BugX marketplaces are migrated before
|
|
1819
|
+
registration so ChatGPT cannot index the same Skill multiple times.
|
|
1820
|
+
"""
|
|
1821
|
+
root = root.resolve()
|
|
1822
|
+
marketplace_path, marketplace_target, marketplace = _chatgpt_marketplace(root)
|
|
1823
|
+
plugin_root = root / "plugins" / CHATGPT_PLUGIN_NAME
|
|
1824
|
+
manifest_path = plugin_root / ".codex-plugin" / "plugin.json"
|
|
1825
|
+
skill_path = plugin_root / "skills" / "bugx" / "SKILL.md"
|
|
1826
|
+
for path in (
|
|
1827
|
+
plugin_root, root / "plugins",
|
|
1828
|
+
):
|
|
1829
|
+
if path.is_symlink():
|
|
1830
|
+
raise CliError(_i18n_exc("plugin.chatgpt_symlink_plugin_path", f"拒绝写入符号链接 ChatGPT Plugin 路径: {path}", path=path))
|
|
1831
|
+
|
|
1832
|
+
entry = {
|
|
1833
|
+
"name": CHATGPT_PLUGIN_NAME,
|
|
1834
|
+
"source": {"source": "local", "path": CHATGPT_PLUGIN_SOURCE},
|
|
1835
|
+
"policy": {"installation": "AVAILABLE", "authentication": "ON_INSTALL"},
|
|
1836
|
+
"category": "Developer tools",
|
|
1837
|
+
"isCustom": True,
|
|
1838
|
+
"isUserCreated": True,
|
|
1839
|
+
}
|
|
1840
|
+
entries = marketplace["plugins"]
|
|
1841
|
+
assert isinstance(entries, list)
|
|
1842
|
+
replaced = False
|
|
1843
|
+
merged_entries: list[object] = []
|
|
1844
|
+
for item in entries:
|
|
1845
|
+
if item.get("name") == CHATGPT_PLUGIN_NAME:
|
|
1846
|
+
if replaced:
|
|
1847
|
+
continue
|
|
1848
|
+
merged_entries.append(entry)
|
|
1849
|
+
replaced = True
|
|
1850
|
+
else:
|
|
1851
|
+
merged_entries.append(item)
|
|
1852
|
+
if not replaced:
|
|
1853
|
+
merged_entries.append(entry)
|
|
1854
|
+
marketplace["plugins"] = merged_entries
|
|
1855
|
+
|
|
1856
|
+
plugin_version = _resolve_plugin_version(root, __version__)
|
|
1857
|
+
generated = {
|
|
1858
|
+
manifest_path: json.dumps(_chatgpt_plugin_manifest(version=plugin_version), ensure_ascii=False, indent=2) + "\n",
|
|
1859
|
+
plugin_root / "assets" / "bugx-avatar-512.png": _chatgpt_plugin_icon_payload(),
|
|
1860
|
+
skill_path: _chatgpt_skill_content(source, locale=locale, version=plugin_version),
|
|
1861
|
+
marketplace_target: json.dumps(marketplace, ensure_ascii=False, indent=2) + "\n",
|
|
1862
|
+
}
|
|
1863
|
+
copied = skipped = 0
|
|
1864
|
+
backups: list[Path] = []
|
|
1865
|
+
for target, content in generated.items():
|
|
1866
|
+
copied_count, skipped_count, backup = _write_host_resource(
|
|
1867
|
+
root,
|
|
1868
|
+
target,
|
|
1869
|
+
content if isinstance(content, bytes) else content.encode("utf-8"),
|
|
1870
|
+
"chatgpt",
|
|
1871
|
+
)
|
|
1872
|
+
copied += copied_count
|
|
1873
|
+
skipped += skipped_count
|
|
1874
|
+
if backup is not None:
|
|
1875
|
+
backups.append(backup)
|
|
1876
|
+
|
|
1877
|
+
# PATH 上找不到时不放弃:Codex Windows 安装器常不写 PATH,
|
|
1878
|
+
# 复用适配器探测的标准安装位置解析真实二进制。
|
|
1879
|
+
codex = shutil.which("codex")
|
|
1880
|
+
if not codex:
|
|
1881
|
+
try:
|
|
1882
|
+
codex = get_adapter("codex").detect(root)["executable"] or None
|
|
1883
|
+
except (OSError, ValueError):
|
|
1884
|
+
codex = None
|
|
1885
|
+
global_marketplace_path, shared_skill = _write_chatgpt_global_plugin(source, locale=locale)
|
|
1886
|
+
result: dict[str, object] = {
|
|
1887
|
+
"status": "prepared",
|
|
1888
|
+
"marketplace": str(marketplace["name"]),
|
|
1889
|
+
"global_marketplace": CHATGPT_GLOBAL_MARKETPLACE_NAME,
|
|
1890
|
+
"global_marketplace_path": str(global_marketplace_path),
|
|
1891
|
+
"plugin": CHATGPT_PLUGIN_NAME,
|
|
1892
|
+
"marketplace_path": str(marketplace_path.relative_to(root)),
|
|
1893
|
+
"plugin_path": str(plugin_root.relative_to(root)),
|
|
1894
|
+
"copied": copied,
|
|
1895
|
+
"skipped": skipped,
|
|
1896
|
+
"backups": [str(path.relative_to(root)) for path in backups],
|
|
1897
|
+
"shared_skill": shared_skill,
|
|
1898
|
+
"next_step": _i18n_prompt("plugin.chatgpt_next_step", "重启 ChatGPT 桌面应用,在 Plugins 中启用 BugX;新聊天中使用 @bugx"),
|
|
1899
|
+
}
|
|
1900
|
+
if isinstance(shared_skill, dict) and shared_skill.get("status") == "failed":
|
|
1901
|
+
result["shared_skill_warning"] = _i18n_prompt(
|
|
1902
|
+
"plugin.chatgpt_shared_skill_write_failed",
|
|
1903
|
+
f"共享全局 Skill 写入失败(不影响插件注册):{shared_skill.get('error')}",
|
|
1904
|
+
error=shared_skill.get("error", ""),
|
|
1905
|
+
)
|
|
1906
|
+
if not codex:
|
|
1907
|
+
result["legacy_cleanup"] = {
|
|
1908
|
+
"status": "pending", "removed": [], "warnings": [], "failures": [],
|
|
1909
|
+
}
|
|
1910
|
+
return result
|
|
1911
|
+
|
|
1912
|
+
legacy_cleanup = _migrate_legacy_chatgpt_registrations(codex)
|
|
1913
|
+
result["legacy_cleanup"] = legacy_cleanup
|
|
1914
|
+
|
|
1915
|
+
commands = [
|
|
1916
|
+
[codex, "plugin", "marketplace", "add", str(_chatgpt_global_plugin_root()), "--json"],
|
|
1917
|
+
[codex, "plugin", "add",
|
|
1918
|
+
f"{CHATGPT_PLUGIN_NAME}@{CHATGPT_GLOBAL_MARKETPLACE_NAME}", "--json"],
|
|
1919
|
+
]
|
|
1920
|
+
command_outputs: list[str] = []
|
|
1921
|
+
for command in commands:
|
|
1922
|
+
try:
|
|
1923
|
+
process = subprocess.run(
|
|
1924
|
+
command, cwd=root, capture_output=True, text=True,
|
|
1925
|
+
check=False, timeout=30,
|
|
1926
|
+
)
|
|
1927
|
+
except (OSError, subprocess.TimeoutExpired) as exc:
|
|
1928
|
+
result["registration_warning"] = _i18n_prompt("plugin.codex_command_call_failed", f"无法调用 Codex Plugin 安装命令: {exc}", exc=exc)
|
|
1929
|
+
return result
|
|
1930
|
+
output = (process.stdout or process.stderr or "").strip()
|
|
1931
|
+
command_outputs.append(output[-500:])
|
|
1932
|
+
if process.returncode != 0:
|
|
1933
|
+
no_out = _i18n_prompt("plugin.no_output", "无输出")
|
|
1934
|
+
result["registration_warning"] = (
|
|
1935
|
+
_i18n_prompt("plugin.codex_command_failed", f"Codex Plugin 命令失败({process.returncode}):{output[-500:] or no_out}", code=process.returncode, output=output[-500:] or no_out)
|
|
1936
|
+
)
|
|
1937
|
+
result["command_outputs"] = command_outputs
|
|
1938
|
+
return result
|
|
1939
|
+
result.update({
|
|
1940
|
+
"status": "installed-via-codex",
|
|
1941
|
+
"method": "codex plugin marketplace add + codex plugin add",
|
|
1942
|
+
"command_outputs": command_outputs,
|
|
1943
|
+
"next_step": _i18n_prompt("plugin.chatgpt_next_step_codex", "重启 ChatGPT 桌面应用;如未显示,请在 Plugins → Personal 中确认 BugX"),
|
|
1944
|
+
})
|
|
1945
|
+
if legacy_cleanup.get("failures"):
|
|
1946
|
+
result["registration_warning"] = (
|
|
1947
|
+
_i18n_prompt("plugin.legacy_marketplace_partial_failure", "部分旧 BugX Marketplace 未能迁移;当前插件已注册,但仍可能存在重复索引。")
|
|
1948
|
+
)
|
|
1949
|
+
return result
|
|
1950
|
+
|
|
1951
|
+
|
|
1952
|
+
def _remove_opencode_mcp_entry(
|
|
1953
|
+
root: Path, removed: list[str], preserved: list[str], *, backup_host: str = "opencode",
|
|
1954
|
+
backup_dir: Path | None = None,
|
|
1955
|
+
) -> None:
|
|
1956
|
+
"""Remove BugX-managed OpenCode registrations on uninstall.
|
|
1957
|
+
|
|
1958
|
+
Rules:
|
|
1959
|
+
- The project entry .opencode/agents/bugx.md is removed when it is a
|
|
1960
|
+
symlink resolving to the global engine payload; foreign or user-owned
|
|
1961
|
+
links are preserved.
|
|
1962
|
+
- The global agent registration (link into ~/.config/opencode/agents)
|
|
1963
|
+
is removed only when it points into this project.
|
|
1964
|
+
- If opencode.json was fully created by BugX (its mcp.servers section contains
|
|
1965
|
+
only managed BugX entries and no user-owned custom keys), the whole
|
|
1966
|
+
file is removed after a backup.
|
|
1967
|
+
- If pre-existing user configuration is present, only the BugX-managed
|
|
1968
|
+
MCP entries are structurally removed; every user-owned MCP is preserved.
|
|
1969
|
+
"""
|
|
1970
|
+
from .agent import _unlink_global_opencode_agent
|
|
1971
|
+
|
|
1972
|
+
_unlink_global_opencode_agent(root)
|
|
1973
|
+
for filename, label in (
|
|
1974
|
+
("bugx.md", ".opencode/agents/bugx.md(入口符号链接)"),
|
|
1975
|
+
("bugx-worker.md", ".opencode/agents/bugx-worker.md(worker 入口符号链接)"),
|
|
1976
|
+
):
|
|
1977
|
+
entry = root / ".opencode" / "agents" / filename
|
|
1978
|
+
payload = global_engine_root() / filename
|
|
1979
|
+
if not payload.is_file():
|
|
1980
|
+
payload = global_engine_root() / "contracts" / filename
|
|
1981
|
+
alt_payload = global_engine_root() / "contracts" / "bugx-opencode.md" if filename == "bugx.md" else payload
|
|
1982
|
+
if not alt_payload.is_file():
|
|
1983
|
+
alt_payload = global_engine_root() / "bugx-opencode.md" if filename == "bugx.md" else payload
|
|
1984
|
+
if entry.is_symlink():
|
|
1985
|
+
try:
|
|
1986
|
+
resolved = entry.resolve()
|
|
1987
|
+
if resolved in (payload.resolve(), alt_payload.resolve()):
|
|
1988
|
+
entry.unlink()
|
|
1989
|
+
removed.append(label)
|
|
1990
|
+
except OSError:
|
|
1991
|
+
pass
|
|
1992
|
+
path = root / CONFIG_NAME
|
|
1993
|
+
if not path.exists():
|
|
1994
|
+
return
|
|
1995
|
+
if path.is_symlink() or not path.is_file():
|
|
1996
|
+
preserved.append(f"{CONFIG_NAME}(不是安全的普通文件,未清理)")
|
|
1997
|
+
return
|
|
1998
|
+
try:
|
|
1999
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
2000
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
2001
|
+
preserved.append(f"{CONFIG_NAME}(无法解析:{exc})")
|
|
2002
|
+
return
|
|
2003
|
+
if not isinstance(payload, dict):
|
|
2004
|
+
preserved.append(f"{CONFIG_NAME}(顶层不是对象,未清理)")
|
|
2005
|
+
return
|
|
2006
|
+
|
|
2007
|
+
mcp = payload.get("mcp")
|
|
2008
|
+
servers: dict[str, object] = {}
|
|
2009
|
+
if mcp is not None:
|
|
2010
|
+
if not isinstance(mcp, dict):
|
|
2011
|
+
preserved.append(f"{CONFIG_NAME}(mcp 不是对象,未清理)")
|
|
2012
|
+
return
|
|
2013
|
+
raw_servers = mcp.get("servers")
|
|
2014
|
+
if raw_servers is None and mcp:
|
|
2015
|
+
preserved.append(f"{CONFIG_NAME}(旧版扁平 mcp 配置未迁移、未清理)")
|
|
2016
|
+
return
|
|
2017
|
+
if raw_servers is not None and not isinstance(raw_servers, dict):
|
|
2018
|
+
preserved.append(f"{CONFIG_NAME}(mcp.servers 不是对象,未清理)")
|
|
2019
|
+
return
|
|
2020
|
+
if isinstance(raw_servers, dict):
|
|
2021
|
+
servers = raw_servers
|
|
2022
|
+
|
|
2023
|
+
managed_servers: list[str] = []
|
|
2024
|
+
for name in OPENCODE_BUGX_MANAGED_MCP:
|
|
2025
|
+
entry = servers.get(name)
|
|
2026
|
+
expected = OPENCODE_PINNED_MCP_COMMANDS.get(name)
|
|
2027
|
+
actual = _host_mcp_command_tokens(entry)
|
|
2028
|
+
if expected and actual and _mcp_tokens_match(actual, expected, root):
|
|
2029
|
+
managed_servers.append(name)
|
|
2030
|
+
|
|
2031
|
+
plugins = payload.get("plugins")
|
|
2032
|
+
managed_plugins = (
|
|
2033
|
+
[item for item in plugins if item == "@dietrichgebert/ponytail"]
|
|
2034
|
+
if isinstance(plugins, list) else []
|
|
2035
|
+
)
|
|
2036
|
+
if not managed_servers and not managed_plugins:
|
|
2037
|
+
return
|
|
2038
|
+
|
|
2039
|
+
_backup_uninstall_file(root, backup_host, path, backup_dir)
|
|
2040
|
+
for name in managed_servers:
|
|
2041
|
+
servers.pop(name, None)
|
|
2042
|
+
if isinstance(mcp, dict) and isinstance(mcp.get("servers"), dict):
|
|
2043
|
+
if not servers:
|
|
2044
|
+
mcp.pop("servers", None)
|
|
2045
|
+
if not mcp:
|
|
2046
|
+
payload.pop("mcp", None)
|
|
2047
|
+
|
|
2048
|
+
if managed_plugins:
|
|
2049
|
+
remaining_plugins = [
|
|
2050
|
+
item for item in plugins if item != "@dietrichgebert/ponytail"
|
|
2051
|
+
]
|
|
2052
|
+
if remaining_plugins:
|
|
2053
|
+
payload["plugins"] = remaining_plugins
|
|
2054
|
+
else:
|
|
2055
|
+
payload.pop("plugins", None)
|
|
2056
|
+
|
|
2057
|
+
user_keys = set(payload) - {"$schema"}
|
|
2058
|
+
if not user_keys:
|
|
2059
|
+
try:
|
|
2060
|
+
path.unlink()
|
|
2061
|
+
removed.append(f"{CONFIG_NAME}(已安全完全删除)")
|
|
2062
|
+
except OSError as exc:
|
|
2063
|
+
preserved.append(f"{CONFIG_NAME}(删除失败:{exc})")
|
|
2064
|
+
return
|
|
2065
|
+
|
|
2066
|
+
content = json.dumps(payload, ensure_ascii=False, indent=2) + "\n"
|
|
2067
|
+
_write_host_resource(root, path, content.encode("utf-8"), backup_host)
|
|
2068
|
+
details = []
|
|
2069
|
+
if managed_servers:
|
|
2070
|
+
details.append(f"MCP:{', '.join(sorted(managed_servers))}")
|
|
2071
|
+
if managed_plugins:
|
|
2072
|
+
details.append("plugins:@dietrichgebert/ponytail")
|
|
2073
|
+
removed.append(f"{CONFIG_NAME}(移除 BugX 添加的 {';'.join(details)})")
|
|
2074
|
+
|
|
2075
|
+
|
|
2076
|
+
def _host_project_mcp_config_target(root: Path, host_name: str) -> tuple[Path, str] | None:
|
|
2077
|
+
"""Return (config_path, servers_key) for the host's project-level MCP registration."""
|
|
2078
|
+
root = root.resolve()
|
|
2079
|
+
if _global_only_mcp_host(host_name):
|
|
2080
|
+
# 用户级/全局作用域:项目内没有会被加载的 MCP 文件(插件事实)。
|
|
2081
|
+
facet = engine_host_mcp_write(host_name)
|
|
2082
|
+
global_target = _host_global_mcp_target(host_name, root)
|
|
2083
|
+
if global_target is None or facet is None:
|
|
2084
|
+
return None
|
|
2085
|
+
return global_target, facet.container_key
|
|
2086
|
+
# 已迁移宿主:项目级路径与容器键都来自插件 ``mcp_write``(不再按名字分支)。
|
|
2087
|
+
# ``custom_writer`` 为真的宿主(opencode.json)由专用写入器负责,避免通用
|
|
2088
|
+
# JSON 骨架接管它的 permission/plugin 合并语义。
|
|
2089
|
+
migrated = engine_host_mcp_write(host_name)
|
|
2090
|
+
if migrated is not None and migrated.project_relpath and not migrated.custom_writer:
|
|
2091
|
+
return root / migrated.project_relpath, migrated.container_key
|
|
2092
|
+
if host_name == "funide":
|
|
2093
|
+
return root / ".mcp.json", "mcpServers"
|
|
2094
|
+
if host_name in {"chatgpt", "workbuddy", "codebuddy"}:
|
|
2095
|
+
# pi / dsh 已迁移(上方插件分支接管),遗留映射仅剩未迁移宿主。
|
|
2096
|
+
rel_map = {
|
|
2097
|
+
"chatgpt": ".agents/mcp.json",
|
|
2098
|
+
"workbuddy": ".workbuddy/mcp.json",
|
|
2099
|
+
"codebuddy": ".codebuddy/mcp.json",
|
|
2100
|
+
}
|
|
2101
|
+
return root / rel_map[host_name], "mcpServers"
|
|
2102
|
+
if host_name == "qoder":
|
|
2103
|
+
return root / ".qoder" / "mcp.json", "mcpServers"
|
|
2104
|
+
if host_name == "trea":
|
|
2105
|
+
return root / ".trea" / "mcp.json", "mcpServers"
|
|
2106
|
+
if host_name == "opencode":
|
|
2107
|
+
return root / "opencode.json", "mcp.servers"
|
|
2108
|
+
return None
|
|
2109
|
+
|
|
2110
|
+
|
|
2111
|
+
def _host_project_mcp_config_targets(root: Path, host_name: str) -> list[tuple[Path, str]]:
|
|
2112
|
+
"""Return all candidate (config_path, servers_key) tuples for the host's project-level MCP registration."""
|
|
2113
|
+
root = root.resolve()
|
|
2114
|
+
targets: list[tuple[Path, str]] = []
|
|
2115
|
+
primary = _host_project_mcp_config_target(root, host_name)
|
|
2116
|
+
if primary:
|
|
2117
|
+
targets.append(primary)
|
|
2118
|
+
facet = engine_host_mcp_write(host_name)
|
|
2119
|
+
if facet is not None:
|
|
2120
|
+
for mirror_label, mirror_target in _host_mcp_mirror_targets(host_name, root):
|
|
2121
|
+
servers_key = facet.container_key
|
|
2122
|
+
targets.append((mirror_target, servers_key))
|
|
2123
|
+
return targets
|
|
2124
|
+
|
|
2125
|
+
|
|
2126
|
+
def _remove_host_mcp_entry(
|
|
2127
|
+
root: Path,
|
|
2128
|
+
host_name: str,
|
|
2129
|
+
removed: list[str],
|
|
2130
|
+
preserved: list[str],
|
|
2131
|
+
*,
|
|
2132
|
+
backup_host: str | None = None,
|
|
2133
|
+
backup_dir: Path | None = None,
|
|
2134
|
+
) -> None:
|
|
2135
|
+
"""从宿主项目级配置文件中清理 BugX MCP 服务器注册(覆盖全部受支持宿主)。
|
|
2136
|
+
|
|
2137
|
+
若清理后该配置文件再无其他用户配置,整文件安全删除并修剪空父目录;
|
|
2138
|
+
若包含用户其他配置,则仅剔除 BugX 注册条目并保留其余配置。
|
|
2139
|
+
"""
|
|
2140
|
+
if host_name == "opencode":
|
|
2141
|
+
_remove_opencode_mcp_entry(
|
|
2142
|
+
root, removed, preserved,
|
|
2143
|
+
backup_host=backup_host or "opencode", backup_dir=backup_dir,
|
|
2144
|
+
)
|
|
2145
|
+
return
|
|
2146
|
+
|
|
2147
|
+
facet = engine_host_mcp_write(host_name)
|
|
2148
|
+
if facet is not None and facet.remove is not None:
|
|
2149
|
+
# 非 JSON 形态(TOML)由插件按表块精准切除;通用 JSON 解析在这里会静默
|
|
2150
|
+
# 跳过整个文件,卸载报告却显示「已清理」——那是最贵的假绿。
|
|
2151
|
+
candidate = root / facet.project_relpath if facet.project_relpath else None
|
|
2152
|
+
if candidate is not None and candidate.is_file() and not candidate.is_symlink():
|
|
2153
|
+
_backup_uninstall_file(root, backup_host or host_name, candidate, backup_dir)
|
|
2154
|
+
outcome = facet.remove(root)
|
|
2155
|
+
removed.extend(str(item) for item in (outcome.get("removed") or ()))
|
|
2156
|
+
preserved.extend(str(item) for item in (outcome.get("preserved") or ()))
|
|
2157
|
+
return
|
|
2158
|
+
|
|
2159
|
+
def _is_bugx_mcp_entry(name: str, entry: object) -> bool:
|
|
2160
|
+
if name in HOST_ALL_MCP or "bugx" in name.lower():
|
|
2161
|
+
return True
|
|
2162
|
+
tokens = _host_mcp_command_tokens(entry)
|
|
2163
|
+
if tokens and any("bugx" in str(tok).lower() for tok in tokens):
|
|
2164
|
+
return True
|
|
2165
|
+
return False
|
|
2166
|
+
|
|
2167
|
+
targets = _host_project_mcp_config_targets(root, host_name)
|
|
2168
|
+
for path, servers_key in targets:
|
|
2169
|
+
if not path.exists():
|
|
2170
|
+
continue
|
|
2171
|
+
try:
|
|
2172
|
+
rel = path.relative_to(root).as_posix()
|
|
2173
|
+
except ValueError:
|
|
2174
|
+
rel = str(path)
|
|
2175
|
+
if path.is_symlink() or not path.is_file():
|
|
2176
|
+
preserved.append(f"{rel}(不是安全的普通文件,未清理)")
|
|
2177
|
+
continue
|
|
2178
|
+
try:
|
|
2179
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
2180
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
2181
|
+
preserved.append(f"{rel}(无法解析:{exc})")
|
|
2182
|
+
continue
|
|
2183
|
+
if not isinstance(payload, dict):
|
|
2184
|
+
continue
|
|
2185
|
+
mcp_section: dict | None = None
|
|
2186
|
+
leaf_key = servers_key
|
|
2187
|
+
if "." in servers_key:
|
|
2188
|
+
# 嵌套容器键(如 ZCode 的 "mcp.servers")
|
|
2189
|
+
keys = servers_key.split(".")
|
|
2190
|
+
container = payload
|
|
2191
|
+
for k in keys[:-1]:
|
|
2192
|
+
child = container.get(k)
|
|
2193
|
+
if not isinstance(child, dict):
|
|
2194
|
+
container = None
|
|
2195
|
+
break
|
|
2196
|
+
container = child
|
|
2197
|
+
leaf_key = keys[-1]
|
|
2198
|
+
servers = container.get(leaf_key) if isinstance(container, dict) else None
|
|
2199
|
+
if isinstance(container, dict):
|
|
2200
|
+
mcp_section = container
|
|
2201
|
+
else:
|
|
2202
|
+
servers = payload.get(servers_key)
|
|
2203
|
+
if not isinstance(servers, dict):
|
|
2204
|
+
continue
|
|
2205
|
+
|
|
2206
|
+
bugx_keys = [k for k, v in servers.items() if _is_bugx_mcp_entry(k, v)]
|
|
2207
|
+
if not bugx_keys:
|
|
2208
|
+
continue
|
|
2209
|
+
|
|
2210
|
+
_backup_uninstall_file(root, backup_host or host_name, path, backup_dir)
|
|
2211
|
+
try:
|
|
2212
|
+
# 用**词法**绝对路径判断,不做 symlink 解析:项目内宿主符号链接
|
|
2213
|
+
# (如 `.agents -> 托管目录`)仍属于项目作用域,按原有清理语义处理。
|
|
2214
|
+
outside_project = not Path(os.path.abspath(str(path))).is_relative_to(
|
|
2215
|
+
Path(os.path.abspath(str(root)))
|
|
2216
|
+
)
|
|
2217
|
+
except (OSError, ValueError):
|
|
2218
|
+
outside_project = True
|
|
2219
|
+
if outside_project:
|
|
2220
|
+
# 用户级全局配置永不整删(jenkins/gitea 等无关 server 与插件登记同文件,
|
|
2221
|
+
# Cline 的 settings 还存放非 MCP 设置):只精准剔除 BugX 条目,
|
|
2222
|
+
# 空 servers 段顺手收掉。
|
|
2223
|
+
for k in bugx_keys:
|
|
2224
|
+
servers.pop(k, None)
|
|
2225
|
+
if mcp_section is not None and not mcp_section.get(leaf_key):
|
|
2226
|
+
mcp_section.pop(leaf_key, None)
|
|
2227
|
+
content = json.dumps(payload, ensure_ascii=False, indent=2) + "\n"
|
|
2228
|
+
_write_host_resource(root, path, content.encode("utf-8"), backup_host or host_name)
|
|
2229
|
+
removed.append(f"{rel}(移除 BugX MCP 服务器:{', '.join(sorted(bugx_keys))})")
|
|
2230
|
+
continue
|
|
2231
|
+
user_keys = [k for k in servers if k not in bugx_keys]
|
|
2232
|
+
top_level_user_keys = set(payload.keys()) - {servers_key}
|
|
2233
|
+
if not user_keys and not top_level_user_keys:
|
|
2234
|
+
try:
|
|
2235
|
+
path.unlink()
|
|
2236
|
+
removed.append(f"{rel}(已安全完全删除)")
|
|
2237
|
+
_remove_empty_parents(root, [rel])
|
|
2238
|
+
except OSError as exc:
|
|
2239
|
+
preserved.append(f"{rel}(删除失败:{exc})")
|
|
2240
|
+
continue
|
|
2241
|
+
|
|
2242
|
+
for k in bugx_keys:
|
|
2243
|
+
servers.pop(k, None)
|
|
2244
|
+
content = json.dumps(payload, ensure_ascii=False, indent=2) + "\n"
|
|
2245
|
+
_write_host_resource(root, path, content.encode("utf-8"), backup_host or host_name)
|
|
2246
|
+
removed.append(f"{rel}(移除 BugX MCP 服务器:{', '.join(sorted(bugx_keys))})")
|
|
2247
|
+
|
|
2248
|
+
|
|
2249
|
+
def _remove_claude_mcp_entry(
|
|
2250
|
+
root: Path, removed: list[str], preserved: list[str], *, backup_host: str = "claude",
|
|
2251
|
+
backup_dir: Path | None = None,
|
|
2252
|
+
) -> None:
|
|
2253
|
+
"""Remove BugX supervisor MCP channels from .mcp.json on claude uninstall."""
|
|
2254
|
+
_remove_host_mcp_entry(
|
|
2255
|
+
root, "claude", removed, preserved,
|
|
2256
|
+
backup_host=backup_host, backup_dir=backup_dir,
|
|
2257
|
+
)
|
|
2258
|
+
|
|
2259
|
+
|
|
2260
|
+
def _remove_qoder_mcp_entry(
|
|
2261
|
+
root: Path, removed: list[str], preserved: list[str], *, backup_host: str = "qoder",
|
|
2262
|
+
backup_dir: Path | None = None,
|
|
2263
|
+
) -> None:
|
|
2264
|
+
"""Remove BugX supervisor MCP channels from .qoder/mcp.json on qoder uninstall."""
|
|
2265
|
+
_remove_host_mcp_entry(
|
|
2266
|
+
root, "qoder", removed, preserved,
|
|
2267
|
+
backup_host=backup_host, backup_dir=backup_dir,
|
|
2268
|
+
)
|
|
2269
|
+
|
|
2270
|
+
|
|
2271
|
+
def _remove_dsh_project_files(
|
|
2272
|
+
root: Path, removed: list[str], preserved: list[str],
|
|
2273
|
+
records: list[object] | None = None, *, backup_host: str = "dsh",
|
|
2274
|
+
backup_dir: Path | None = None,
|
|
2275
|
+
force: bool = False,
|
|
2276
|
+
) -> None:
|
|
2277
|
+
"""清理 DSH 在项目根下的写入产物。
|
|
2278
|
+
|
|
2279
|
+
P2-3(哈希归属检查):
|
|
2280
|
+
- 有记录且哈希未变:正常清理并记入 removed;
|
|
2281
|
+
- 有记录但内容已被用户修改:保留文件并记入 preserved,不强行覆盖/删除;
|
|
2282
|
+
- 无记录:没有所有权证明,保留文件并记入 preserved;调用方若要清理必须
|
|
2283
|
+
先提供当前安装记录,禁止按文件名猜测归属。
|
|
2284
|
+
- force=True:强制清理已备份的文件。
|
|
2285
|
+
"""
|
|
2286
|
+
if not records and not force:
|
|
2287
|
+
for candidate in (
|
|
2288
|
+
root / ".dsh" / "patch.yml",
|
|
2289
|
+
root / ".dsh" / "agents" / "bugx.md",
|
|
2290
|
+
root / ".dsh" / "skills" / "bugx" / "SKILL.md",
|
|
2291
|
+
):
|
|
2292
|
+
if candidate.exists() and not candidate.is_symlink() and candidate.is_file():
|
|
2293
|
+
relative = candidate.relative_to(root).as_posix()
|
|
2294
|
+
preserved.append(f"{relative}(没有安装记录,无法证明文件归属;未删除)")
|
|
2295
|
+
return
|
|
2296
|
+
records_by_path: dict[str, str] = {}
|
|
2297
|
+
for record in records or []:
|
|
2298
|
+
if isinstance(record, dict) and isinstance(record.get("path"), str) \
|
|
2299
|
+
and isinstance(record.get("sha256"), str):
|
|
2300
|
+
records_by_path[record["path"]] = record["sha256"]
|
|
2301
|
+
candidates = [
|
|
2302
|
+
root / ".dsh" / "patch.yml",
|
|
2303
|
+
root / ".dsh" / "agents" / "bugx.md",
|
|
2304
|
+
root / ".dsh" / "skills" / "bugx" / "SKILL.md",
|
|
2305
|
+
]
|
|
2306
|
+
for candidate in candidates:
|
|
2307
|
+
if not candidate.exists() or candidate.is_symlink() or not candidate.is_file():
|
|
2308
|
+
continue
|
|
2309
|
+
relative = candidate.relative_to(root).as_posix()
|
|
2310
|
+
expected_hash = records_by_path.get(relative)
|
|
2311
|
+
if expected_hash is not None:
|
|
2312
|
+
try:
|
|
2313
|
+
current_hash = _sha256_file(candidate)
|
|
2314
|
+
except OSError as exc:
|
|
2315
|
+
preserved.append(f"{relative}(无法读取:{exc})")
|
|
2316
|
+
continue
|
|
2317
|
+
if current_hash != expected_hash and not force:
|
|
2318
|
+
note = f"{relative}(内容已被用户修改)"
|
|
2319
|
+
if note not in preserved:
|
|
2320
|
+
preserved.append(note)
|
|
2321
|
+
continue
|
|
2322
|
+
try:
|
|
2323
|
+
backup = _backup_uninstall_file(root, backup_host, candidate, backup_dir)
|
|
2324
|
+
except OSError as exc:
|
|
2325
|
+
preserved.append(f"{relative}(备份失败:{exc})")
|
|
2326
|
+
continue
|
|
2327
|
+
try:
|
|
2328
|
+
candidate.unlink()
|
|
2329
|
+
if (expected_hash is not None and current_hash != expected_hash) or not records:
|
|
2330
|
+
removed.append(f"{relative}(强制清理已备份)")
|
|
2331
|
+
else:
|
|
2332
|
+
removed.append(
|
|
2333
|
+
relative if expected_hash is not None
|
|
2334
|
+
else f"{relative}(无记录遗留,按 BugX 渲染归属清理)"
|
|
2335
|
+
)
|
|
2336
|
+
except OSError as exc:
|
|
2337
|
+
preserved.append(f"{relative}(删除失败:{exc};备份:{backup})")
|
|
2338
|
+
|
|
2339
|
+
|
|
2340
|
+
def _remove_dsh_user_preset(
|
|
2341
|
+
root: Path, removed: list[str], preserved: list[str], *, purge_global: bool = False,
|
|
2342
|
+
backup_host: str = "dsh", backup_dir: Path | None = None,
|
|
2343
|
+
) -> None:
|
|
2344
|
+
"""Remove the global user preset ~/.dsh/.agent-presets/bugx/ ONLY when purge_global is set.
|
|
2345
|
+
|
|
2346
|
+
In a multi-project setup, other projects may rely on the shared user preset.
|
|
2347
|
+
Ordinary project uninstalls clean up only project-local .dsh files to prevent
|
|
2348
|
+
breaking other projects. Global user preset removal is performed only during
|
|
2349
|
+
explicit --purge-global-data --yes operations.
|
|
2350
|
+
"""
|
|
2351
|
+
if not purge_global:
|
|
2352
|
+
preserved.append("~/.dsh/.agent-presets/bugx(全局预设保留,供其他项目复用;全局清理需 --purge-global-data)")
|
|
2353
|
+
return
|
|
2354
|
+
preset_dir = Path.home() / ".dsh" / ".agent-presets" / "bugx"
|
|
2355
|
+
if not preset_dir.exists():
|
|
2356
|
+
return
|
|
2357
|
+
if preset_dir.is_symlink() or not preset_dir.is_dir():
|
|
2358
|
+
preserved.append("~/.dsh/.agent-presets/bugx(不是安全的目录,未清理)")
|
|
2359
|
+
return
|
|
2360
|
+
try:
|
|
2361
|
+
# Backup user preset directory before unlinking
|
|
2362
|
+
for child in preset_dir.iterdir():
|
|
2363
|
+
if child.is_file() and not child.is_symlink():
|
|
2364
|
+
_backup_uninstall_file(root, backup_host, child, backup_dir)
|
|
2365
|
+
shutil.rmtree(preset_dir)
|
|
2366
|
+
removed.append("~/.dsh/.agent-presets/bugx(已显式清理全局 DSH 预设)")
|
|
2367
|
+
except OSError as exc:
|
|
2368
|
+
preserved.append(f"~/.dsh/.agent-presets/bugx(清理失败:{exc})")
|
|
2369
|
+
|
|
2370
|
+
|
|
2371
|
+
def _remove_chatgpt_marketplace_entry(
|
|
2372
|
+
root: Path, removed: list[str], preserved: list[str], *, backup_host: str = "chatgpt",
|
|
2373
|
+
backup_dir: Path | None = None,
|
|
2374
|
+
) -> None:
|
|
2375
|
+
"""Remove only BugX's local marketplace entry and retain every other entry."""
|
|
2376
|
+
try:
|
|
2377
|
+
logical_path, path = _chatgpt_marketplace_paths(root)
|
|
2378
|
+
except CliError as exc:
|
|
2379
|
+
preserved.append(f".agents/plugins/marketplace.json({exc})")
|
|
2380
|
+
return
|
|
2381
|
+
if not path.exists():
|
|
2382
|
+
return
|
|
2383
|
+
if path.is_symlink() or not path.is_file():
|
|
2384
|
+
preserved.append(f"{logical_path.relative_to(root)}(不是安全的普通文件)")
|
|
2385
|
+
return
|
|
2386
|
+
try:
|
|
2387
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
2388
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
2389
|
+
preserved.append(f"{logical_path.relative_to(root)}(无法解析:{exc})")
|
|
2390
|
+
return
|
|
2391
|
+
if not isinstance(payload, dict) or not isinstance(payload.get("plugins"), list):
|
|
2392
|
+
preserved.append(f"{logical_path.relative_to(root)}(缺少有效 plugins 数组)")
|
|
2393
|
+
return
|
|
2394
|
+
bugx_entries = [
|
|
2395
|
+
item for item in payload["plugins"]
|
|
2396
|
+
if isinstance(item, dict) and item.get("name") == CHATGPT_PLUGIN_NAME
|
|
2397
|
+
]
|
|
2398
|
+
owned = [
|
|
2399
|
+
item for item in bugx_entries
|
|
2400
|
+
if item.get("source") in (None, {"source": "local", "path": CHATGPT_PLUGIN_SOURCE})
|
|
2401
|
+
]
|
|
2402
|
+
if not bugx_entries:
|
|
2403
|
+
return
|
|
2404
|
+
if len(owned) != len(bugx_entries):
|
|
2405
|
+
preserved.append(f"{logical_path.relative_to(root)}(存在非 BugX 的同名插件,未修改)")
|
|
2406
|
+
return
|
|
2407
|
+
updated = dict(payload)
|
|
2408
|
+
updated["plugins"] = [item for item in payload["plugins"] if item not in owned]
|
|
2409
|
+
if not updated["plugins"]:
|
|
2410
|
+
# BugX 是唯一条目:marketplace 只为 BugX 存在,按"新项目"语义
|
|
2411
|
+
# 备份后删除文件并修剪 .agents 空壳目录。
|
|
2412
|
+
_backup_uninstall_file(root, backup_host, path, backup_dir)
|
|
2413
|
+
path.unlink()
|
|
2414
|
+
removed.append(str(logical_path.relative_to(root)) + "(BugX 为唯一条目,文件已删除)")
|
|
2415
|
+
for shell in (path.parent, path.parent.parent):
|
|
2416
|
+
try:
|
|
2417
|
+
shell.rmdir()
|
|
2418
|
+
except OSError:
|
|
2419
|
+
break
|
|
2420
|
+
return
|
|
2421
|
+
content = json.dumps(updated, ensure_ascii=False, indent=2) + "\n"
|
|
2422
|
+
_write_host_resource(root, path, content.encode("utf-8"), backup_host)
|
|
2423
|
+
removed.append(str(logical_path.relative_to(root)) + "(移除 BugX 条目)")
|
|
2424
|
+
|
|
2425
|
+
|
|
2426
|
+
def _external_uninstall_backup_root(root: Path) -> Path:
|
|
2427
|
+
override = os.environ.get("BUGX_UNINSTALL_BACKUP_ROOT")
|
|
2428
|
+
base = Path(override).expanduser() if override else Path.home() / ".bugx" / "backups" / "uninstall"
|
|
2429
|
+
project_id = hashlib.sha256(str(root.resolve()).encode("utf-8")).hexdigest()[:16]
|
|
2430
|
+
return base.resolve() / project_id / str(time.time_ns())
|
|
2431
|
+
|
|
2432
|
+
|
|
2433
|
+
def _reset_forbidden_targets(root: Path, scope: str) -> list[Path]:
|
|
2434
|
+
"""Return every path the requested reset may actually clear.
|
|
2435
|
+
|
|
2436
|
+
The backup archive only has to stay outside *these* targets. Treating
|
|
2437
|
+
the whole reset root as forbidden was over-conservative: on Windows the
|
|
2438
|
+
system tempdir lives inside the user's home, so a global reset invoked
|
|
2439
|
+
from the home directory could never find a valid archive location.
|
|
2440
|
+
"""
|
|
2441
|
+
root = root.resolve()
|
|
2442
|
+
if scope == "project":
|
|
2443
|
+
# A project reset only moves entries under <root>/.bugx.
|
|
2444
|
+
return [(root / ".bugx").resolve()]
|
|
2445
|
+
bugx_home = (Path.home() / ".bugx").resolve()
|
|
2446
|
+
knowledge_root = bugx_home / "knowledge"
|
|
2447
|
+
knowledge_override = os.environ.get("BUGX_GLOBAL_KNOWLEDGE_ROOT")
|
|
2448
|
+
if knowledge_override:
|
|
2449
|
+
knowledge_root = Path(knowledge_override).expanduser().resolve()
|
|
2450
|
+
forbidden = [
|
|
2451
|
+
knowledge_root,
|
|
2452
|
+
(bugx_home / "cloud-sync").resolve(),
|
|
2453
|
+
(bugx_home / "identity").resolve(),
|
|
2454
|
+
(bugx_home / "backups").resolve(),
|
|
2455
|
+
]
|
|
2456
|
+
try:
|
|
2457
|
+
forbidden.append(default_mcp_runtime_root().resolve())
|
|
2458
|
+
except Exception:
|
|
2459
|
+
pass
|
|
2460
|
+
# File targets (cloud-device-id, cloud-credentials.json) cannot contain a
|
|
2461
|
+
# directory, so only existing directories matter here.
|
|
2462
|
+
return [path for path in forbidden if path.is_dir()]
|
|
2463
|
+
|
|
2464
|
+
|
|
2465
|
+
def _external_reset_backup_root(root: Path, scope: str) -> Path:
|
|
2466
|
+
"""Return a reset archive outside every path that may be reset."""
|
|
2467
|
+
override = os.environ.get("BUGX_RESET_BACKUP_ROOT")
|
|
2468
|
+
base = Path(override).expanduser() if override else Path.home() / ".bugx" / "reset-backups"
|
|
2469
|
+
project_id = hashlib.sha256(str(root.resolve()).encode("utf-8")).hexdigest()[:16]
|
|
2470
|
+
|
|
2471
|
+
def _candidate(base_dir: Path) -> Path:
|
|
2472
|
+
return base_dir.resolve() / scope / project_id / str(time.time_ns())
|
|
2473
|
+
|
|
2474
|
+
def _blocked(candidate: Path) -> bool:
|
|
2475
|
+
return any(candidate == path or candidate.is_relative_to(path)
|
|
2476
|
+
for path in _reset_forbidden_targets(root, scope))
|
|
2477
|
+
|
|
2478
|
+
candidate = _candidate(base)
|
|
2479
|
+
if _blocked(candidate):
|
|
2480
|
+
if override:
|
|
2481
|
+
raise CliError(_i18n_exc("plugin.reset_backup_invalid", f"重置备份目录不能位于待清理目录内: {candidate}", candidate=candidate))
|
|
2482
|
+
# The default archive lives under ~/.bugx; a project reset of the home
|
|
2483
|
+
# directory itself would clear it, so fall back to the system tempdir.
|
|
2484
|
+
# Forbidden targets are named directories under ~/.bugx, and the
|
|
2485
|
+
# platform tempdir is outside all of them on Windows, macOS and Linux,
|
|
2486
|
+
# so this fallback can no longer defeat itself (N1).
|
|
2487
|
+
candidate = _candidate(Path(tempfile.gettempdir()) / "bugx-reset-backups")
|
|
2488
|
+
if _blocked(candidate):
|
|
2489
|
+
raise CliError(_i18n_exc("plugin.reset_backup_invalid", f"重置备份目录不能位于待清理目录内: {candidate}", candidate=candidate))
|
|
2490
|
+
_assert_no_symlink_components(candidate.parent)
|
|
2491
|
+
|
|
2492
|
+
return candidate
|
|
2493
|
+
|
|
2494
|
+
|
|
2495
|
+
def _reset_lock_is_held(path: Path) -> bool:
|
|
2496
|
+
"""Check a persisted lock without treating stale lock files as active."""
|
|
2497
|
+
if not path.exists() or path.is_symlink():
|
|
2498
|
+
return False
|
|
2499
|
+
try:
|
|
2500
|
+
import fcntl
|
|
2501
|
+
backend = fcntl
|
|
2502
|
+
except ImportError:
|
|
2503
|
+
try:
|
|
2504
|
+
import msvcrt
|
|
2505
|
+
backend = msvcrt
|
|
2506
|
+
except ImportError as exc: # pragma: no cover - unsupported platform
|
|
2507
|
+
raise CliError("当前平台无法检查 BugX 运行锁,已拒绝重置") from exc
|
|
2508
|
+
try:
|
|
2509
|
+
handle = path.open("a+b")
|
|
2510
|
+
except OSError:
|
|
2511
|
+
return True
|
|
2512
|
+
try:
|
|
2513
|
+
try:
|
|
2514
|
+
if backend.__name__ == "msvcrt":
|
|
2515
|
+
handle.seek(0)
|
|
2516
|
+
if handle.tell() == 0 and handle.read(1) == b"":
|
|
2517
|
+
handle.write(b"\0")
|
|
2518
|
+
handle.flush()
|
|
2519
|
+
handle.seek(0)
|
|
2520
|
+
backend.locking(handle.fileno(), backend.LK_NBLCK, 1)
|
|
2521
|
+
else:
|
|
2522
|
+
backend.flock(handle.fileno(), backend.LOCK_EX | backend.LOCK_NB)
|
|
2523
|
+
except OSError:
|
|
2524
|
+
return True
|
|
2525
|
+
if backend.__name__ == "msvcrt":
|
|
2526
|
+
handle.seek(0)
|
|
2527
|
+
backend.locking(handle.fileno(), backend.LK_UNLCK, 1)
|
|
2528
|
+
else:
|
|
2529
|
+
backend.flock(handle.fileno(), backend.LOCK_UN)
|
|
2530
|
+
return False
|
|
2531
|
+
finally:
|
|
2532
|
+
handle.close()
|
|
2533
|
+
|
|
2534
|
+
|
|
2535
|
+
def _is_pid_alive_cli(pid: object) -> bool:
|
|
2536
|
+
if pid is None or not isinstance(pid, int) or isinstance(pid, bool) or pid <= 0:
|
|
2537
|
+
return False
|
|
2538
|
+
try:
|
|
2539
|
+
os.kill(pid, 0)
|
|
2540
|
+
return True
|
|
2541
|
+
except ProcessLookupError:
|
|
2542
|
+
return False
|
|
2543
|
+
except PermissionError:
|
|
2544
|
+
return True
|
|
2545
|
+
except OSError as err:
|
|
2546
|
+
import errno
|
|
2547
|
+
return getattr(err, "errno", None) == errno.EPERM
|
|
2548
|
+
|
|
2549
|
+
|
|
2550
|
+
def _reset_active_blockers(root: Path) -> list[str]:
|
|
2551
|
+
"""Reject reset while a lifecycle can still write project state."""
|
|
2552
|
+
bugx = root.resolve() / ".bugx"
|
|
2553
|
+
if not bugx.is_dir() or bugx.is_symlink():
|
|
2554
|
+
return []
|
|
2555
|
+
blockers: list[str] = []
|
|
2556
|
+
state_files = list(bugx.rglob("runtime.json"))
|
|
2557
|
+
for path in state_files:
|
|
2558
|
+
if path.is_symlink() or not path.is_file():
|
|
2559
|
+
continue
|
|
2560
|
+
try:
|
|
2561
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
2562
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
2563
|
+
blockers.append(f"{path.relative_to(root)}(无法确认状态:{exc})")
|
|
2564
|
+
continue
|
|
2565
|
+
active = payload.get("active") is True
|
|
2566
|
+
state = str(payload.get("state", ""))
|
|
2567
|
+
if active or state in {"running", "paused", "PRE", "BASELINE_CAPTURED",
|
|
2568
|
+
"AGENT_RUNNING", "POST", "DECIDE"}:
|
|
2569
|
+
pid = payload.get("pid")
|
|
2570
|
+
lock_path = path.with_name("runtime.lock")
|
|
2571
|
+
lock_held = _reset_lock_is_held(lock_path)
|
|
2572
|
+
if pid is not None and isinstance(pid, int) and not isinstance(pid, bool):
|
|
2573
|
+
if _is_pid_alive_cli(pid) or lock_held:
|
|
2574
|
+
blockers.append(f"{path.relative_to(root)}({state or 'active'})")
|
|
2575
|
+
elif lock_held:
|
|
2576
|
+
blockers.append(f"{path.relative_to(root)}({state or 'active'})")
|
|
2577
|
+
else:
|
|
2578
|
+
try:
|
|
2579
|
+
mtime_age = time.time() - path.stat().st_mtime
|
|
2580
|
+
except OSError:
|
|
2581
|
+
mtime_age = 0
|
|
2582
|
+
if mtime_age < 600:
|
|
2583
|
+
blockers.append(f"{path.relative_to(root)}({state or 'active'})")
|
|
2584
|
+
for path in (
|
|
2585
|
+
bugx / "lifecycle.lock",
|
|
2586
|
+
bugx / "init.lock",
|
|
2587
|
+
bugx / "locks" / "project.lock",
|
|
2588
|
+
*bugx.glob("pollings/*/lifecycles/*/state/runtime.lock"),
|
|
2589
|
+
*bugx.glob("pollings/*/lifecycles/*/state/audit-supervisor.lock"),
|
|
2590
|
+
*bugx.glob("pollings/*/lifecycles/*/state/locks/*.lock"),
|
|
2591
|
+
):
|
|
2592
|
+
if _reset_lock_is_held(path):
|
|
2593
|
+
blockers.append(f"{path.relative_to(root)}(锁被占用)")
|
|
2594
|
+
return blockers
|
|
2595
|
+
|
|
2596
|
+
|
|
2597
|
+
def _reset_entries(root: Path, *, include_project_knowledge: bool) -> list[tuple[Path, str]]:
|
|
2598
|
+
bugx = root.resolve() / ".bugx"
|
|
2599
|
+
entries: list[tuple[Path, str]] = []
|
|
2600
|
+
for name in RESET_PROJECT_DIRECTORIES:
|
|
2601
|
+
entries.append((bugx / name, f"project/{name}"))
|
|
2602
|
+
for name in RESET_PROJECT_FILES:
|
|
2603
|
+
entries.append((bugx / name, f"project/{name}"))
|
|
2604
|
+
# Old releases could place mutable runtime files in the compatibility
|
|
2605
|
+
# core directory. They are part of a project reset even though current
|
|
2606
|
+
# runtime files live under pollings/*/state.
|
|
2607
|
+
entries.extend(_legacy_core_runtime_entries(root))
|
|
2608
|
+
# Sync cursors, inbox and outbox are transport/runtime state, not the
|
|
2609
|
+
# project knowledge ledger. A normal project reset must clear them too;
|
|
2610
|
+
# otherwise the recreated runtime can skip remote changes or replay stale
|
|
2611
|
+
# operations against a new Session.
|
|
2612
|
+
entries.append((bugx / "cloud-sync", "project/cloud-sync"))
|
|
2613
|
+
if include_project_knowledge:
|
|
2614
|
+
entries.append((bugx / "knowledge", "project/knowledge"))
|
|
2615
|
+
return entries
|
|
2616
|
+
|
|
2617
|
+
|
|
2618
|
+
def _move_reset_entries(entries: list[tuple[Path, str]], archive: Path) -> list[tuple[Path, Path]]:
|
|
2619
|
+
"""Move reset targets into an external archive and roll back on failure."""
|
|
2620
|
+
moved: list[tuple[Path, Path]] = []
|
|
2621
|
+
try:
|
|
2622
|
+
for source, relative in entries:
|
|
2623
|
+
if not source.exists() and not source.is_symlink():
|
|
2624
|
+
continue
|
|
2625
|
+
archived_link_target: Path | None = None
|
|
2626
|
+
if source.is_symlink():
|
|
2627
|
+
# Only reserved legacy runtime entries are allowed here. We
|
|
2628
|
+
# move the link itself into the external archive and never
|
|
2629
|
+
# follow or delete its target (which may be the shared engine).
|
|
2630
|
+
if not (relative.startswith("project/core/")
|
|
2631
|
+
and _is_runtime_artifact_name(source.name)):
|
|
2632
|
+
raise CliError(_i18n_exc("plugin.reset_symlink_refused", f"拒绝重置符号链接运行产物: {source}", source=source))
|
|
2633
|
+
archived_link_target = source.resolve(strict=False)
|
|
2634
|
+
else:
|
|
2635
|
+
_assert_no_symlink_components(source)
|
|
2636
|
+
destination = archive / relative
|
|
2637
|
+
_assert_no_symlink_components(destination.parent)
|
|
2638
|
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
2639
|
+
shutil.move(str(source), str(destination))
|
|
2640
|
+
if archived_link_target is not None:
|
|
2641
|
+
# A relative link keeps its old relative base after a move and
|
|
2642
|
+
# becomes a misleading/dangling archive entry. Recreate only
|
|
2643
|
+
# the link itself with its absolute resolved target; the
|
|
2644
|
+
# target is never read, copied, or deleted.
|
|
2645
|
+
destination.unlink()
|
|
2646
|
+
destination.symlink_to(str(archived_link_target))
|
|
2647
|
+
moved.append((source, destination))
|
|
2648
|
+
except BaseException:
|
|
2649
|
+
_restore_reset_entries(moved)
|
|
2650
|
+
raise
|
|
2651
|
+
return moved
|
|
2652
|
+
|
|
2653
|
+
|
|
2654
|
+
def _restore_reset_entries(moved: list[tuple[Path, Path]]) -> None:
|
|
2655
|
+
for source, destination in reversed(moved):
|
|
2656
|
+
if destination.exists() or destination.is_symlink():
|
|
2657
|
+
source.parent.mkdir(parents=True, exist_ok=True)
|
|
2658
|
+
if source.is_symlink() or source.is_file():
|
|
2659
|
+
source.unlink(missing_ok=True)
|
|
2660
|
+
elif source.is_dir():
|
|
2661
|
+
shutil.rmtree(source, ignore_errors=True)
|
|
2662
|
+
shutil.move(str(destination), str(source))
|
|
2663
|
+
|
|
2664
|
+
|
|
2665
|
+
def _clean_reset_entries(entries: list[tuple[Path, str]]) -> None:
|
|
2666
|
+
"""Directly remove reset targets when backup is skipped."""
|
|
2667
|
+
for source, relative in entries:
|
|
2668
|
+
if not source.exists() and not source.is_symlink():
|
|
2669
|
+
continue
|
|
2670
|
+
if source.is_symlink():
|
|
2671
|
+
if not (relative.startswith("project/core/")
|
|
2672
|
+
and _is_runtime_artifact_name(source.name)):
|
|
2673
|
+
raise CliError(_i18n_exc("plugin.reset_symlink_refused", f"拒绝重置符号链接运行产物: {source}", source=source))
|
|
2674
|
+
source.unlink(missing_ok=True)
|
|
2675
|
+
elif source.is_file():
|
|
2676
|
+
_assert_no_symlink_components(source)
|
|
2677
|
+
source.unlink(missing_ok=True)
|
|
2678
|
+
elif source.is_dir():
|
|
2679
|
+
_assert_no_symlink_components(source)
|
|
2680
|
+
shutil.rmtree(source, ignore_errors=True)
|
|
2681
|
+
|
|
2682
|
+
|
|
2683
|
+
def _bootstrap_global_knowledge(root: Path, source: Path) -> None:
|
|
2684
|
+
"""Create a clean global ledger after an explicit global reset."""
|
|
2685
|
+
global_root = (Path.home() / ".bugx" / "knowledge").resolve()
|
|
2686
|
+
override = os.environ.get("BUGX_GLOBAL_KNOWLEDGE_ROOT")
|
|
2687
|
+
if override:
|
|
2688
|
+
global_root = Path(override).expanduser().resolve()
|
|
2689
|
+
_assert_no_symlink_components(global_root)
|
|
2690
|
+
global_root.mkdir(parents=True, exist_ok=True)
|
|
2691
|
+
seed = global_root / "global.json"
|
|
2692
|
+
db = global_root / "global.sqlite3"
|
|
2693
|
+
marker = global_root / "manifest.json"
|
|
2694
|
+
source_seed = source / "lesson-ledger.json"
|
|
2695
|
+
if not source_seed.is_file() or source_seed.is_symlink():
|
|
2696
|
+
raise CliError(_i18n_exc("plugin.lesson_rebuild_seed_missing", "重建全局错题集失败:缺少内置 lesson-ledger.json 种子"))
|
|
2697
|
+
shutil.copy2(source_seed, seed)
|
|
2698
|
+
script = _script(root, "lesson_ledger.py")
|
|
2699
|
+
process = subprocess.run(
|
|
2700
|
+
[sys.executable, str(script), "init", "--ledger", str(seed), "--json"],
|
|
2701
|
+
cwd=root.resolve(), capture_output=True, text=True, check=False, timeout=30,
|
|
2702
|
+
env=_python_environment(),
|
|
2703
|
+
)
|
|
2704
|
+
if process.returncode != 0 or not db.is_file():
|
|
2705
|
+
detail = (process.stderr or process.stdout).strip()[:800]
|
|
2706
|
+
raise CliError(_i18n_exc("plugin.lesson_rebuild_failed", f"重建全局错题集失败:{detail or 'lesson_ledger init 返回非 0'}", detail=detail or 'lesson_ledger init 返回非 0'))
|
|
2707
|
+
|
|
2708
|
+
seed.chmod(0o600)
|
|
2709
|
+
db.chmod(0o600)
|
|
2710
|
+
_write_private_json(marker, {
|
|
2711
|
+
"schema_version": 1,
|
|
2712
|
+
"scope": "global",
|
|
2713
|
+
"authority": "sqlite",
|
|
2714
|
+
"read_only_for_agents": True,
|
|
2715
|
+
"seed": seed.name,
|
|
2716
|
+
"database": db.name,
|
|
2717
|
+
"initialized_at": time.time(),
|
|
2718
|
+
"reset": True,
|
|
2719
|
+
})
|
|
2720
|
+
|
|
2721
|
+
|
|
2722
|
+
def _reset_confirmation(summary: str, *, yes: bool, dry_run: bool, root: Path | None = None) -> None:
|
|
2723
|
+
if yes or dry_run:
|
|
2724
|
+
return
|
|
2725
|
+
print(summary)
|
|
2726
|
+
_ensure_core_importable()
|
|
2727
|
+
from core.runtime import interaction
|
|
2728
|
+
from core.runtime import startup_environment
|
|
2729
|
+
|
|
2730
|
+
question = interaction.InteractionQuestion(
|
|
2731
|
+
question_id="reset_confirmation",
|
|
2732
|
+
phase="reset",
|
|
2733
|
+
kind="confirm",
|
|
2734
|
+
title="确认执行 BugX 重置",
|
|
2735
|
+
question="重置操作将按上方范围归档并重建运行产物,是否继续?",
|
|
2736
|
+
options=(
|
|
2737
|
+
interaction.InteractionOption("yes", "确认执行", "按已展示的范围执行重置"),
|
|
2738
|
+
interaction.InteractionOption("no", "取消", "不修改任何数据"),
|
|
2739
|
+
),
|
|
2740
|
+
default=1,
|
|
2741
|
+
)
|
|
2742
|
+
environment = startup_environment.detect(root or Path.cwd())
|
|
2743
|
+
result = interaction.ask(question, environment)
|
|
2744
|
+
if result.status != interaction.ANSWERED:
|
|
2745
|
+
raise CliError(_i18n_exc("reset.not_confirmed", "未完成重置确认,未修改任何数据"))
|
|
2746
|
+
if result.value != "yes":
|
|
2747
|
+
raise CliError(_i18n_exc("reset.cancelled", "已取消重置,未修改任何数据"))
|
|
2748
|
+
|
|
2749
|
+
return
|