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,2763 @@
|
|
|
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 ..infra.engine_installer import refresh_i18n_after_engine_swap
|
|
20
|
+
from ..host_adapters import ENTRY_MULTI_PATH, HOST_ADAPTERS
|
|
21
|
+
from ..hosts.registry import (
|
|
22
|
+
engine_host_cli_hook,
|
|
23
|
+
engine_host_user_agent_surfaces,
|
|
24
|
+
)
|
|
25
|
+
from .agent import (
|
|
26
|
+
_dsh_home,
|
|
27
|
+
_global_opencode_agents_dir,
|
|
28
|
+
_inherit_project_knowledge,
|
|
29
|
+
_initialize_lesson_ledger,
|
|
30
|
+
_initialize_life_state,
|
|
31
|
+
_unlink_global_pi_skill,
|
|
32
|
+
)
|
|
33
|
+
from .plugin import (
|
|
34
|
+
_bootstrap_global_knowledge,
|
|
35
|
+
_chatgpt_global_plugin_root,
|
|
36
|
+
_chatgpt_marketplace_name,
|
|
37
|
+
_clean_reset_entries,
|
|
38
|
+
_external_reset_backup_root,
|
|
39
|
+
_external_uninstall_backup_root,
|
|
40
|
+
_host_project_mcp_config_target,
|
|
41
|
+
_is_bugx_marketplace_source,
|
|
42
|
+
_move_reset_entries,
|
|
43
|
+
_read_hosts_record,
|
|
44
|
+
_remove_chatgpt_marketplace_entry,
|
|
45
|
+
_remove_claude_mcp_entry,
|
|
46
|
+
_remove_dsh_project_files,
|
|
47
|
+
_remove_dsh_user_preset,
|
|
48
|
+
_remove_empty_parents,
|
|
49
|
+
_remove_host_mcp_entry,
|
|
50
|
+
_remove_opencode_mcp_entry,
|
|
51
|
+
_remove_owned_record,
|
|
52
|
+
_remove_qoder_mcp_entry,
|
|
53
|
+
_reset_active_blockers,
|
|
54
|
+
_reset_confirmation,
|
|
55
|
+
_reset_entries,
|
|
56
|
+
_restore_reset_entries,
|
|
57
|
+
_sweep_unrecorded_host_entry,
|
|
58
|
+
_SWEEPABLE_SKILL_ADAPTERS,
|
|
59
|
+
_zcode_config_path,
|
|
60
|
+
_zcode_user_agents_dir,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _assemble_project_materials(root: Path, source: Path, layout: Any) -> None:
|
|
65
|
+
"""统一装配项目开工材料:开工准备记录与覆盖清单引导。"""
|
|
66
|
+
for name, target in (
|
|
67
|
+
("prep-record.md", layout.prep_record if hasattr(layout, "prep_record") else layout.require(root).prep_record),
|
|
68
|
+
("module-coverage.md", (layout.state_root if hasattr(layout, "state_root") else layout.require(root).state_root) / "module-coverage.md"),
|
|
69
|
+
):
|
|
70
|
+
source_record = source / name
|
|
71
|
+
if source_record.is_file() and not target.exists():
|
|
72
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
73
|
+
shutil.copy2(source_record, target)
|
|
74
|
+
target.chmod(0o600)
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
_ensure_core_importable()
|
|
78
|
+
from core.runtime import prep_validate
|
|
79
|
+
prep_validate.ensure_prep_record(root)
|
|
80
|
+
except Exception:
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
try:
|
|
84
|
+
_ensure_core_importable()
|
|
85
|
+
from core.coverage import coverage_bootstrap
|
|
86
|
+
coverage = coverage_bootstrap.inspect(root)
|
|
87
|
+
if not coverage.get("ready") and not coverage.get("blocked"):
|
|
88
|
+
coverage_bootstrap.bootstrap(root, confirmed=True)
|
|
89
|
+
except Exception:
|
|
90
|
+
pass
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _ensure_project_startup_todo(root: Path) -> Path:
|
|
94
|
+
"""生成或确保项目级开工总览 .bugx/startup-todo.md 存在且符合契约。"""
|
|
95
|
+
target = root / ".bugx" / "startup-todo.md"
|
|
96
|
+
if target.is_symlink():
|
|
97
|
+
raise OSError(f"拒绝写入软链接目标:{target}")
|
|
98
|
+
if not target.is_file() or target.stat().st_size == 0:
|
|
99
|
+
iso_now = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
|
|
100
|
+
content = (
|
|
101
|
+
"# BugX 启动总览 TODO\n\n"
|
|
102
|
+
f"- 项目:`{root}`\n"
|
|
103
|
+
"- 宿主/界面:`unknown` / `cli` / `idle`\n"
|
|
104
|
+
"- 当前阶段:`environment`\n"
|
|
105
|
+
"- 当前门禁:`none`\n"
|
|
106
|
+
f"- 最后校准:`{iso_now}`\n\n"
|
|
107
|
+
"- [x] 1. 环境检测与前置校验\n"
|
|
108
|
+
" - 校验 Python 版本、核心静态文件完整性与项目运行布局\n"
|
|
109
|
+
"- [~] 2. 启动配置与策略确认\n"
|
|
110
|
+
" - 确认云端同步、审查方式、轮询策略、修复模式与提交策略\n"
|
|
111
|
+
"- [ ] 3. 工具与执行能力准备\n"
|
|
112
|
+
" - 确认 MCP/探针连通性与项目上下文加载\n"
|
|
113
|
+
"- [ ] 4. 覆盖勘察与漏洞挖掘\n"
|
|
114
|
+
" - 生成覆盖清单并调度 Worker 并发挖掘验证\n"
|
|
115
|
+
"- [ ] 5. 同步与知识复盘\n"
|
|
116
|
+
" - 沉淀错题集、更新经验账本与云端同步\n"
|
|
117
|
+
"- [ ] 6. 报告与结论共享\n"
|
|
118
|
+
" - 生成 Round 审计报告与证据闭环\n"
|
|
119
|
+
"- [ ] 7. 安全收尾与生命周期结算\n"
|
|
120
|
+
" - 执行受控提交并结算运行状态\n\n"
|
|
121
|
+
"> 本文件是给用户和 Agent 查看全局进度的派生视图,不是账本、覆盖清单、Finding 来源或完成判定器。\n"
|
|
122
|
+
"> 正式 Round 开始后,详细进度位于当前生命周期 `state/audit-todo.md`。\n"
|
|
123
|
+
"> 阶段专精提示词(Harness):可通过 `bugx engine --root . prompt --stage <gate|explore|mutate|repair>` 或 MCP `bugx_get_stage_harness` 动态获取。\n"
|
|
124
|
+
)
|
|
125
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
126
|
+
descriptor, temporary = tempfile.mkstemp(
|
|
127
|
+
dir=str(target.parent), prefix=f".{target.name}.", suffix=".tmp",
|
|
128
|
+
)
|
|
129
|
+
try:
|
|
130
|
+
with os.fdopen(descriptor, "w", encoding="utf-8") as handle:
|
|
131
|
+
handle.write(content)
|
|
132
|
+
os.chmod(temporary, 0o600)
|
|
133
|
+
os.replace(temporary, target)
|
|
134
|
+
except BaseException:
|
|
135
|
+
try:
|
|
136
|
+
os.unlink(temporary)
|
|
137
|
+
except OSError:
|
|
138
|
+
pass
|
|
139
|
+
raise
|
|
140
|
+
return target
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _has_bugx_project_markers(bugx: Path) -> bool:
|
|
145
|
+
"""Check if .bugx directory contains recognizable BugX runtime artifacts."""
|
|
146
|
+
known_markers = (
|
|
147
|
+
"manifest.json", "current.json", "config.json", "hosts.json",
|
|
148
|
+
"pollings", "state", "logs", "artifacts", "index", "knowledge",
|
|
149
|
+
"backups", "locks", "resume_ticket.json", "prep-record.md",
|
|
150
|
+
"module-coverage.md", "init.lock", "audit-supervisor.json",
|
|
151
|
+
"bugx-life.json", "finding-ledger.json",
|
|
152
|
+
)
|
|
153
|
+
for name in known_markers:
|
|
154
|
+
p = bugx / name
|
|
155
|
+
if p.exists() or p.is_symlink():
|
|
156
|
+
return True
|
|
157
|
+
return False
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _snapshot_reset_paths(root: Path) -> set[Path]:
|
|
161
|
+
"""Record lexical paths below the project runtime without following links."""
|
|
162
|
+
paths: set[Path] = set()
|
|
163
|
+
if not root.exists() or root.is_symlink():
|
|
164
|
+
return paths
|
|
165
|
+
for current, directories, files in os.walk(root, followlinks=False):
|
|
166
|
+
parent = Path(current)
|
|
167
|
+
paths.add(parent)
|
|
168
|
+
for name in (*directories, *files):
|
|
169
|
+
paths.add(parent / name)
|
|
170
|
+
directories[:] = [name for name in directories if not (parent / name).is_symlink()]
|
|
171
|
+
return paths
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _remove_reset_created_paths(root: Path, existing: set[Path]) -> None:
|
|
175
|
+
"""Remove only paths created by a failed reset; refuse to traverse links."""
|
|
176
|
+
created = _snapshot_reset_paths(root) - existing
|
|
177
|
+
for path in sorted(created, key=lambda item: len(item.parts), reverse=True):
|
|
178
|
+
if path.is_symlink() or path.is_file():
|
|
179
|
+
path.unlink(missing_ok=True)
|
|
180
|
+
elif path.is_dir():
|
|
181
|
+
path.rmdir()
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _auto_abort_residual_runtime(root: Path, blockers: list[str]) -> bool:
|
|
185
|
+
"""残留运行态自愈:先走引擎安全中止,让状态回到可重置的确定态。
|
|
186
|
+
|
|
187
|
+
为什么必须有这一步(2026-11-02 实测):``pre`` 成功后 ``runtime.json`` 会留下
|
|
188
|
+
``active=true / state=running / pid=null``。此时进程早已退出,但 blocker 判定
|
|
189
|
+
会因「pid 字段缺失且 mtime 很新」把它当活任务,要求用户自己保存 ``blob``、
|
|
190
|
+
抄下 ``bugx engine ... abort`` 再重试——而这正是工具应当自己做完的确定性收口。
|
|
191
|
+
中止是引擎的**受支持入口**(在安全边界结算并释放租约),因此这里只做编排:
|
|
192
|
+
|
|
193
|
+
* 只对 ``runtime.json`` 类 blocker 触发,锁被占用(真有进程持有)不碰,
|
|
194
|
+
否则会与正在写入的会话互相破坏;
|
|
195
|
+
* 中止失败/超时只是「自愈未成功」,由调用方回落到带命令提示的报错,
|
|
196
|
+
绝不让 reset 静默继续。
|
|
197
|
+
"""
|
|
198
|
+
if not blockers:
|
|
199
|
+
return False
|
|
200
|
+
# 锁被占用说明确实有活进程在写:交给用户/--force,不自动中止。
|
|
201
|
+
if any("锁被占用" in item for item in blockers):
|
|
202
|
+
return False
|
|
203
|
+
script = root.resolve() / ".bugx"
|
|
204
|
+
if not script.is_dir():
|
|
205
|
+
return False
|
|
206
|
+
try:
|
|
207
|
+
launcher = global_engine_root() / "launch_bugx.py"
|
|
208
|
+
if not launcher.is_file():
|
|
209
|
+
return False
|
|
210
|
+
print("[bugx] 检测到残留运行态,正在自动安全中止(abort)后重置…")
|
|
211
|
+
completed = subprocess.run(
|
|
212
|
+
[sys.executable, str(launcher), "abort", "--reason", "auto: reset"],
|
|
213
|
+
cwd=str(root),
|
|
214
|
+
capture_output=True,
|
|
215
|
+
text=True,
|
|
216
|
+
timeout=120,
|
|
217
|
+
env=_reset_abort_env(root),
|
|
218
|
+
)
|
|
219
|
+
except (OSError, subprocess.SubprocessError, ValueError):
|
|
220
|
+
return False
|
|
221
|
+
if completed.returncode != 0:
|
|
222
|
+
return False
|
|
223
|
+
# 中止写入是异步安全的;给状态一次落盘机会再复查 blocker。
|
|
224
|
+
time.sleep(0.2)
|
|
225
|
+
return True
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def _reset_abort_env(root: Path) -> dict[str, str]:
|
|
229
|
+
"""中止子进程的环境:绑定当前项目根与全局引擎,避免解析到别的项目。"""
|
|
230
|
+
env = dict(os.environ)
|
|
231
|
+
env["BUGX_PROJECT_ROOT"] = str(root.resolve())
|
|
232
|
+
try:
|
|
233
|
+
env["BUGX_GLOBAL_ENGINE_ROOT"] = str(global_engine_root())
|
|
234
|
+
except (OSError, ValueError):
|
|
235
|
+
pass
|
|
236
|
+
env["BUGX_CLI_VERSION"] = __version__
|
|
237
|
+
return env
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def command_reset(args: argparse.Namespace) -> int:
|
|
241
|
+
"""Archive and recreate project runtime or global knowledge in one action."""
|
|
242
|
+
root = args.root.resolve()
|
|
243
|
+
global_options = (
|
|
244
|
+
args.reset_identity, args.reset_credentials,
|
|
245
|
+
args.reset_mcp_runtime, args.reset_backups,
|
|
246
|
+
)
|
|
247
|
+
if args.scope == "project" and any(global_options):
|
|
248
|
+
raise CliError(_i18n_exc("lifecycle.reset_flags_scope_global_only", "--reset-identity/--reset-credentials/--reset-mcp-runtime/--reset-backups 仅适用于 --scope global"))
|
|
249
|
+
if args.scope == "global" and args.reset_knowledge:
|
|
250
|
+
raise CliError(_i18n_exc("lifecycle.reset_knowledge_scope_project_only", "--reset-knowledge 仅适用于 --scope project;global 默认重置全局知识库"))
|
|
251
|
+
if args.scope == "project":
|
|
252
|
+
bugx = root / ".bugx"
|
|
253
|
+
if bugx.is_symlink() or not bugx.is_dir():
|
|
254
|
+
raise CliError(_i18n_exc("lifecycle.project_not_initialized", "项目未初始化或 .bugx 不安全;请先运行 bugx init"))
|
|
255
|
+
manifest = bugx / "manifest.json"
|
|
256
|
+
force = getattr(args, "force", False)
|
|
257
|
+
if manifest.is_symlink() or (manifest.exists() and not manifest.is_file()):
|
|
258
|
+
raise CliError(_i18n_exc("lifecycle.manifest_missing_for_reset", "项目缺少安全的 .bugx/manifest.json,拒绝猜测重置范围"))
|
|
259
|
+
if not manifest.exists() and not force and not _has_bugx_project_markers(bugx):
|
|
260
|
+
raise CliError(_i18n_exc("lifecycle.manifest_missing_for_reset", "项目缺少安全的 .bugx/manifest.json,拒绝猜测重置范围"))
|
|
261
|
+
if _legacy_project_core_present(root):
|
|
262
|
+
raise CliError(
|
|
263
|
+
"当前项目仍有旧的 .bugx/core 可执行入口;请先运行 "
|
|
264
|
+
"`bugx init --root .`,旧入口会被直接删除"
|
|
265
|
+
)
|
|
266
|
+
blockers = _reset_active_blockers(root)
|
|
267
|
+
if blockers and not force:
|
|
268
|
+
# 自愈:残留运行态是**可确定性收口**的状态,不该让用户手抄下一句命令。
|
|
269
|
+
# 有活进程时先走引擎的安全中止(它会在安全边界结算),再复查一次;
|
|
270
|
+
# 仍然存在才报错,并把可直接执行的命令写进提示。
|
|
271
|
+
if _auto_abort_residual_runtime(root, blockers):
|
|
272
|
+
blockers = _reset_active_blockers(root)
|
|
273
|
+
if blockers and not force:
|
|
274
|
+
raise CliError(
|
|
275
|
+
_i18n_exc(
|
|
276
|
+
"lifecycle.running_tasks_block_reset",
|
|
277
|
+
"检测到仍在写入的运行中任务,已尝试自动安全中止但未成功:"
|
|
278
|
+
+ ";".join(blockers)
|
|
279
|
+
+ "。请手动执行 `bugx engine --root . abort --reason reset` 后重试,"
|
|
280
|
+
"或加 --force 强制重置",
|
|
281
|
+
blockers=";".join(blockers),
|
|
282
|
+
)
|
|
283
|
+
)
|
|
284
|
+
include_knowledge = bool(args.reset_knowledge)
|
|
285
|
+
targets = _reset_entries(root, include_project_knowledge=include_knowledge)
|
|
286
|
+
if manifest.is_file() and force:
|
|
287
|
+
try:
|
|
288
|
+
manifest_data = json.loads(manifest.read_text(encoding="utf-8"))
|
|
289
|
+
layout_module = _layout_module(root)
|
|
290
|
+
expected_project_id = getattr(layout_module, "_project_id", lambda r: "")(root)
|
|
291
|
+
if (not isinstance(manifest_data, dict)
|
|
292
|
+
or manifest_data.get("schema_version") != getattr(layout_module, "SCHEMA_VERSION", 1)
|
|
293
|
+
or (expected_project_id and manifest_data.get("project_id") != expected_project_id)):
|
|
294
|
+
targets.append((manifest, "project/manifest.json"))
|
|
295
|
+
except (OSError, json.JSONDecodeError, ValueError):
|
|
296
|
+
targets.append((manifest, "project/manifest.json"))
|
|
297
|
+
no_backup = bool(getattr(args, "no_backup", False))
|
|
298
|
+
archive = None if no_backup else _external_reset_backup_root(root, "project")
|
|
299
|
+
summary = (
|
|
300
|
+
"项目级重置将清理并重建轮询、生命周期、状态、日志、证据、索引和备份(跳过备份);"
|
|
301
|
+
if no_backup else
|
|
302
|
+
"项目级重置将归档并重建轮询、生命周期、状态、日志、证据、索引和备份;"
|
|
303
|
+
) + (
|
|
304
|
+
"同时重置项目错题集/经验集。" if include_knowledge
|
|
305
|
+
else "项目错题集/经验集将保留。"
|
|
306
|
+
) + (
|
|
307
|
+
f"备份位置:{archive}" if archive else ""
|
|
308
|
+
)
|
|
309
|
+
_reset_confirmation(summary, yes=args.yes, dry_run=args.dry_run, root=root)
|
|
310
|
+
if args.dry_run:
|
|
311
|
+
payload = {
|
|
312
|
+
"status": "DRY_RUN", "scope": "project", "root": str(root),
|
|
313
|
+
"reset_knowledge": include_knowledge,
|
|
314
|
+
"targets": [relative for _, relative in targets],
|
|
315
|
+
"backup": str(archive) if archive else None,
|
|
316
|
+
}
|
|
317
|
+
else:
|
|
318
|
+
_close_bugx_logging()
|
|
319
|
+
transaction_archive = archive or Path(
|
|
320
|
+
tempfile.mkdtemp(prefix="bugx-reset-rollback-")
|
|
321
|
+
).resolve()
|
|
322
|
+
if archive is not None:
|
|
323
|
+
transaction_archive.mkdir(parents=True, exist_ok=False)
|
|
324
|
+
moved: list[tuple[Path, Path]] = []
|
|
325
|
+
preexisting: set[Path] | None = None
|
|
326
|
+
try:
|
|
327
|
+
moved = _move_reset_entries(targets, transaction_archive)
|
|
328
|
+
preexisting = _snapshot_reset_paths(root / ".bugx")
|
|
329
|
+
layout = _layout_module(root)
|
|
330
|
+
layout.initialize(root, bugx_version=__version__)
|
|
331
|
+
source = asset_root()
|
|
332
|
+
_assemble_project_materials(root, source, layout)
|
|
333
|
+
if include_knowledge:
|
|
334
|
+
_initialize_lesson_ledger(root, source)
|
|
335
|
+
_inherit_project_knowledge(root)
|
|
336
|
+
_initialize_life_state(root)
|
|
337
|
+
if archive is not None:
|
|
338
|
+
_write_private_json(archive / "reset-manifest.json", {
|
|
339
|
+
"scope": "project", "root": str(root),
|
|
340
|
+
"reset_knowledge": include_knowledge,
|
|
341
|
+
"created_at": time.time(),
|
|
342
|
+
"entries": [str(destination.relative_to(archive))
|
|
343
|
+
for _, destination in moved],
|
|
344
|
+
})
|
|
345
|
+
payload = {
|
|
346
|
+
"status": "RESET", "scope": "project", "root": str(root),
|
|
347
|
+
"reset_knowledge": include_knowledge,
|
|
348
|
+
"backup": str(archive) if archive else None,
|
|
349
|
+
"archived": [str(destination.relative_to(transaction_archive))
|
|
350
|
+
for _, destination in moved] if archive else [],
|
|
351
|
+
"recreated": ["polling-000001", "lifecycle-000001", "life.json"],
|
|
352
|
+
}
|
|
353
|
+
except BaseException as reset_error:
|
|
354
|
+
try:
|
|
355
|
+
if preexisting is not None:
|
|
356
|
+
_assert_no_symlink_components(root / ".bugx")
|
|
357
|
+
_remove_reset_created_paths(root / ".bugx", preexisting)
|
|
358
|
+
_assert_no_symlink_components(root / ".bugx")
|
|
359
|
+
_restore_reset_entries(moved)
|
|
360
|
+
except BaseException as rollback_error:
|
|
361
|
+
raise CliError(
|
|
362
|
+
f"项目重置失败且回滚不完整;原始数据保留于 {transaction_archive}: "
|
|
363
|
+
f"{rollback_error}"
|
|
364
|
+
) from reset_error
|
|
365
|
+
if preexisting is None and any(transaction_archive.iterdir()):
|
|
366
|
+
raise CliError(
|
|
367
|
+
f"项目条目移动失败且未能确认回滚状态;staging 保留于 {transaction_archive}"
|
|
368
|
+
) from reset_error
|
|
369
|
+
shutil.rmtree(transaction_archive, ignore_errors=True)
|
|
370
|
+
raise
|
|
371
|
+
if archive is None:
|
|
372
|
+
shutil.rmtree(transaction_archive, ignore_errors=True)
|
|
373
|
+
else:
|
|
374
|
+
bugx_home_lexical = Path.home() / ".bugx"
|
|
375
|
+
bugx_home = bugx_home_lexical
|
|
376
|
+
global_root = bugx_home_lexical / "knowledge"
|
|
377
|
+
if "BUGX_GLOBAL_KNOWLEDGE_ROOT" in os.environ:
|
|
378
|
+
override = os.environ["BUGX_GLOBAL_KNOWLEDGE_ROOT"]
|
|
379
|
+
if not override.strip():
|
|
380
|
+
raise CliError("BUGX_GLOBAL_KNOWLEDGE_ROOT 不能是空路径")
|
|
381
|
+
global_root = Path(override).expanduser()
|
|
382
|
+
_assert_no_symlink_components(global_root)
|
|
383
|
+
global_root = Path(os.path.abspath(str(global_root)))
|
|
384
|
+
try:
|
|
385
|
+
global_root.relative_to(bugx_home_lexical)
|
|
386
|
+
except ValueError as exc:
|
|
387
|
+
raise CliError("全局知识重置目标必须位于 ~/.bugx 内") from exc
|
|
388
|
+
_assert_no_symlink_components(global_root)
|
|
389
|
+
optional: list[tuple[Path, str]] = []
|
|
390
|
+
if args.reset_identity:
|
|
391
|
+
optional.extend(((bugx_home / "cloud-device-id", "global/cloud-device-id"),
|
|
392
|
+
(bugx_home / "identity" / "installation-secret",
|
|
393
|
+
"global/identity/installation-secret")))
|
|
394
|
+
if args.reset_credentials:
|
|
395
|
+
optional.append((bugx_home / "cloud-credentials.json", "global/cloud-credentials.json"))
|
|
396
|
+
if args.reset_mcp_runtime:
|
|
397
|
+
runtime_root = default_mcp_runtime_root()
|
|
398
|
+
optional.append((runtime_root, "global/mcp-runtime"))
|
|
399
|
+
if args.reset_backups:
|
|
400
|
+
optional.append((bugx_home / "backups", "global/backups"))
|
|
401
|
+
targets = [(global_root, "global/knowledge"),
|
|
402
|
+
(bugx_home_lexical / "cloud-sync", "global/cloud-sync"),
|
|
403
|
+
*optional]
|
|
404
|
+
for target, _ in targets:
|
|
405
|
+
_assert_no_symlink_components(target)
|
|
406
|
+
try:
|
|
407
|
+
target.relative_to(bugx_home_lexical)
|
|
408
|
+
except ValueError as exc:
|
|
409
|
+
raise CliError(f"全局重置目标必须位于 ~/.bugx 内: {target}") from exc
|
|
410
|
+
no_backup = bool(getattr(args, "no_backup", False))
|
|
411
|
+
archive = None if no_backup else _external_reset_backup_root(root, "global")
|
|
412
|
+
additions = []
|
|
413
|
+
if args.reset_identity:
|
|
414
|
+
additions.append("设备身份")
|
|
415
|
+
if args.reset_credentials:
|
|
416
|
+
additions.append("云端凭证")
|
|
417
|
+
if args.reset_mcp_runtime:
|
|
418
|
+
additions.append("MCP 运行时缓存")
|
|
419
|
+
if args.reset_backups:
|
|
420
|
+
additions.append("历史备份")
|
|
421
|
+
summary = "全局级重置将清空并重建全局错题集/经验集"
|
|
422
|
+
if additions:
|
|
423
|
+
summary += ",并处理:" + "、".join(additions)
|
|
424
|
+
if archive:
|
|
425
|
+
summary += f";全局引擎目录永不随项目重置删除。备份位置:{archive}"
|
|
426
|
+
else:
|
|
427
|
+
summary += ";全局引擎目录永不随项目重置删除(跳过备份)。"
|
|
428
|
+
_reset_confirmation(summary, yes=args.yes, dry_run=args.dry_run, root=root)
|
|
429
|
+
if args.dry_run:
|
|
430
|
+
payload = {
|
|
431
|
+
"status": "DRY_RUN", "scope": "global",
|
|
432
|
+
"reset_knowledge": True,
|
|
433
|
+
"targets": [relative for _, relative in targets],
|
|
434
|
+
"backup": str(archive) if archive else None,
|
|
435
|
+
}
|
|
436
|
+
else:
|
|
437
|
+
if archive is not None:
|
|
438
|
+
archive.mkdir(parents=True, exist_ok=False)
|
|
439
|
+
moved = []
|
|
440
|
+
created_dirs: list[Path] = []
|
|
441
|
+
knowledge_moved = False
|
|
442
|
+
try:
|
|
443
|
+
moved = _move_reset_entries(targets, archive)
|
|
444
|
+
knowledge_moved = True
|
|
445
|
+
source = asset_root()
|
|
446
|
+
_bootstrap_global_knowledge(root, source)
|
|
447
|
+
if args.reset_mcp_runtime:
|
|
448
|
+
runtime_root = default_mcp_runtime_root()
|
|
449
|
+
if not runtime_root.exists():
|
|
450
|
+
runtime_root.mkdir(parents=True, mode=0o700)
|
|
451
|
+
created_dirs.append(runtime_root)
|
|
452
|
+
if args.reset_backups:
|
|
453
|
+
backup_root = bugx_home / "backups"
|
|
454
|
+
if not backup_root.exists():
|
|
455
|
+
backup_root.mkdir(parents=True, mode=0o700)
|
|
456
|
+
created_dirs.append(backup_root)
|
|
457
|
+
_write_private_json(archive / "reset-manifest.json", {
|
|
458
|
+
"scope": "global", "reset_knowledge": True,
|
|
459
|
+
"reset_identity": bool(args.reset_identity),
|
|
460
|
+
"reset_credentials": bool(args.reset_credentials),
|
|
461
|
+
"reset_mcp_runtime": bool(args.reset_mcp_runtime),
|
|
462
|
+
"reset_backups": bool(args.reset_backups),
|
|
463
|
+
"created_at": time.time(),
|
|
464
|
+
"entries": [str(destination.relative_to(archive))
|
|
465
|
+
for _, destination in moved],
|
|
466
|
+
})
|
|
467
|
+
payload = {
|
|
468
|
+
"status": "RESET", "scope": "global", "reset_knowledge": True,
|
|
469
|
+
"reset_identity": bool(args.reset_identity),
|
|
470
|
+
"reset_credentials": bool(args.reset_credentials),
|
|
471
|
+
"reset_mcp_runtime": bool(args.reset_mcp_runtime),
|
|
472
|
+
"reset_backups": bool(args.reset_backups),
|
|
473
|
+
"backup": str(archive),
|
|
474
|
+
"archived": [str(destination.relative_to(archive))
|
|
475
|
+
for _, destination in moved],
|
|
476
|
+
"preserved": ["global engine"],
|
|
477
|
+
}
|
|
478
|
+
except BaseException:
|
|
479
|
+
for directory in reversed(created_dirs):
|
|
480
|
+
if directory.is_dir() and not directory.is_symlink():
|
|
481
|
+
shutil.rmtree(directory, ignore_errors=True)
|
|
482
|
+
try:
|
|
483
|
+
if knowledge_moved:
|
|
484
|
+
shutil.rmtree(global_root, ignore_errors=True)
|
|
485
|
+
finally:
|
|
486
|
+
_restore_reset_entries(moved)
|
|
487
|
+
shutil.rmtree(archive, ignore_errors=True)
|
|
488
|
+
raise
|
|
489
|
+
else:
|
|
490
|
+
_clean_reset_entries(targets)
|
|
491
|
+
source = asset_root()
|
|
492
|
+
_bootstrap_global_knowledge(root, source)
|
|
493
|
+
if args.reset_mcp_runtime:
|
|
494
|
+
runtime_root = default_mcp_runtime_root().resolve()
|
|
495
|
+
if not runtime_root.exists():
|
|
496
|
+
runtime_root.mkdir(parents=True, mode=0o700)
|
|
497
|
+
if args.reset_backups:
|
|
498
|
+
backup_root = bugx_home / "backups"
|
|
499
|
+
if not backup_root.exists():
|
|
500
|
+
backup_root.mkdir(parents=True, mode=0o700)
|
|
501
|
+
payload = {
|
|
502
|
+
"status": "RESET", "scope": "global", "reset_knowledge": True,
|
|
503
|
+
"reset_identity": bool(args.reset_identity),
|
|
504
|
+
"reset_credentials": bool(args.reset_credentials),
|
|
505
|
+
"reset_mcp_runtime": bool(args.reset_mcp_runtime),
|
|
506
|
+
"reset_backups": bool(args.reset_backups),
|
|
507
|
+
"backup": None,
|
|
508
|
+
"archived": [],
|
|
509
|
+
"preserved": ["global engine"],
|
|
510
|
+
}
|
|
511
|
+
if getattr(args, "json", False):
|
|
512
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
513
|
+
else:
|
|
514
|
+
print(f"[bugx] {payload['status']}:{payload['scope']} 重置完成")
|
|
515
|
+
if payload.get("backup"):
|
|
516
|
+
print(f" 可恢复备份:{payload['backup']}")
|
|
517
|
+
return 0
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
def _backup_tree_external(
|
|
521
|
+
source: Path,
|
|
522
|
+
destination: Path,
|
|
523
|
+
*,
|
|
524
|
+
ignore: Any = None,
|
|
525
|
+
) -> Path:
|
|
526
|
+
if source.is_symlink():
|
|
527
|
+
# 如果根目录本身是符号链接,备份解析后的真实目标。
|
|
528
|
+
source = source.resolve()
|
|
529
|
+
if not source.exists():
|
|
530
|
+
return destination
|
|
531
|
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
532
|
+
if source.is_file():
|
|
533
|
+
shutil.copy2(source, destination)
|
|
534
|
+
destination.chmod(0o600)
|
|
535
|
+
return destination
|
|
536
|
+
# copytree 使用 symlinks=True 保留符号链接结构,不再因包含软链接报错;
|
|
537
|
+
# dirs_exist_ok 允许与 P2-1 重定向的逐文件卸载备份合并到同一外部归档。
|
|
538
|
+
shutil.copytree(
|
|
539
|
+
source, destination, symlinks=True, dirs_exist_ok=True, ignore=ignore,
|
|
540
|
+
)
|
|
541
|
+
for directory in (destination, *destination.rglob("*")):
|
|
542
|
+
if directory.is_dir() and not directory.is_symlink():
|
|
543
|
+
directory.chmod(0o700)
|
|
544
|
+
elif directory.is_file() and not directory.is_symlink():
|
|
545
|
+
directory.chmod(0o600)
|
|
546
|
+
return destination
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def _backup_uninstall_delta(root: Path, backup_root: Path) -> None:
|
|
550
|
+
"""保存卸载阶段追加到项目运行态的可恢复数据。
|
|
551
|
+
|
|
552
|
+
项目级 purge 会先备份原始 ``.bugx``,之后宿主文件删除逻辑才会把
|
|
553
|
+
被删除文件的副本写入 ``.bugx/backups``,日志也可能在这段时间追加。
|
|
554
|
+
这些内容不在初始快照里,必须在删除 ``.bugx`` 前补充到外部归档。
|
|
555
|
+
只归档这两个由卸载阶段追加的目录,避免再次复制可能很大的报告和证据。
|
|
556
|
+
"""
|
|
557
|
+
bugx_root = root.resolve() / ".bugx"
|
|
558
|
+
for name, destination_name in (
|
|
559
|
+
("backups", "project-uninstall-backups"),
|
|
560
|
+
("logs", "project-final-logs"),
|
|
561
|
+
):
|
|
562
|
+
source = bugx_root / name
|
|
563
|
+
if source.exists() and not source.is_symlink():
|
|
564
|
+
_backup_tree_external(source, backup_root / destination_name)
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
def _write_uninstall_receipt(
|
|
568
|
+
backup_root: Path,
|
|
569
|
+
*,
|
|
570
|
+
root: Path,
|
|
571
|
+
hosts: list[str],
|
|
572
|
+
removed: list[str],
|
|
573
|
+
preserved: list[str],
|
|
574
|
+
purge_global_data: bool,
|
|
575
|
+
) -> None:
|
|
576
|
+
"""Persist the completed purge result beside its recovery archive."""
|
|
577
|
+
_write_private_json(backup_root / "uninstall-receipt.json", {
|
|
578
|
+
"schema_version": 1,
|
|
579
|
+
"status": "UNINSTALLED",
|
|
580
|
+
"root": str(root.resolve()),
|
|
581
|
+
"hosts": hosts,
|
|
582
|
+
"removed": removed,
|
|
583
|
+
"preserved": preserved,
|
|
584
|
+
"purged_project_data": True,
|
|
585
|
+
"purged_global_data": bool(purge_global_data),
|
|
586
|
+
"created_at": time.time(),
|
|
587
|
+
})
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
def _purge_private_plugin_stores(root: Path, removed: list[str], preserved: list[str]) -> None:
|
|
591
|
+
store = _plugin_store(root)
|
|
592
|
+
if not store.is_dir() or store.is_symlink():
|
|
593
|
+
return
|
|
594
|
+
for plugin_path in sorted(store.iterdir()):
|
|
595
|
+
manifest_path = plugin_path / "plugin.json"
|
|
596
|
+
if not manifest_path.is_file() or manifest_path.is_symlink():
|
|
597
|
+
continue
|
|
598
|
+
try:
|
|
599
|
+
_, manifest = _plugin_manifest(plugin_path, validate_payload=False)
|
|
600
|
+
except CliError:
|
|
601
|
+
preserved.append(f"{manifest_path.relative_to(root)}(清单无效,未删除)")
|
|
602
|
+
continue
|
|
603
|
+
if manifest.get("private") is not True or manifest.get("autoload") is not False:
|
|
604
|
+
continue
|
|
605
|
+
shutil.rmtree(plugin_path)
|
|
606
|
+
removed.append(str(plugin_path.relative_to(root)))
|
|
607
|
+
_remove_empty_parents(root, removed)
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
def _rmtree_force(path: Path) -> None:
|
|
611
|
+
"""删除可能为**只读**的目录树(引擎载荷按不可变分发物安装)。
|
|
612
|
+
|
|
613
|
+
实测缺陷:`uninstall --self` 原先直接 ``shutil.rmtree(~/.bugx)``;当引擎目录
|
|
614
|
+
是 0o555/0o444 的只读载荷时抛 ``PermissionError: .bugx/core``,导致整个
|
|
615
|
+
自卸载失败(测试与真实用户同路径)。
|
|
616
|
+
|
|
617
|
+
关键点:删除条目需要**父目录**写权限,因此先自顶向下放开整棵树,再交给
|
|
618
|
+
``rmtree``;仅对失败条目 chmod 是不够的(实测仍 EACCES)。
|
|
619
|
+
"""
|
|
620
|
+
if path.is_symlink() or path.is_file():
|
|
621
|
+
path.unlink(missing_ok=True)
|
|
622
|
+
return
|
|
623
|
+
for root, _dirs, files in os.walk(path, topdown=True):
|
|
624
|
+
try:
|
|
625
|
+
os.chmod(root, 0o700)
|
|
626
|
+
except OSError:
|
|
627
|
+
pass
|
|
628
|
+
for name in files:
|
|
629
|
+
target = Path(root) / name
|
|
630
|
+
if target.is_symlink():
|
|
631
|
+
continue
|
|
632
|
+
try:
|
|
633
|
+
os.chmod(target, 0o600)
|
|
634
|
+
except OSError:
|
|
635
|
+
pass
|
|
636
|
+
|
|
637
|
+
def _on_error(func, target, _exc): # noqa: ANN001 - stdlib 回调签名
|
|
638
|
+
try:
|
|
639
|
+
os.chmod(Path(target).parent, 0o700)
|
|
640
|
+
except OSError:
|
|
641
|
+
pass
|
|
642
|
+
func(target)
|
|
643
|
+
|
|
644
|
+
try:
|
|
645
|
+
shutil.rmtree(path, onexc=_on_error)
|
|
646
|
+
except TypeError: # Python < 3.12
|
|
647
|
+
shutil.rmtree(path, onerror=_on_error)
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
def _self_home_dir(*parts: str) -> Path:
|
|
651
|
+
"""Return user-profile paths without creating them.
|
|
652
|
+
|
|
653
|
+
BugX data/engine overrides must not relocate host configuration: install
|
|
654
|
+
and self-uninstall use the same actual user profile discovery directory.
|
|
655
|
+
"""
|
|
656
|
+
base = Path.home().resolve()
|
|
657
|
+
return base.joinpath(*parts) if parts else base
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
def _self_backup_root() -> Path:
|
|
661
|
+
# Windows legacy path handling can reject a valid backup tree once the
|
|
662
|
+
# global archive already contains ``~/.bugx/backups/uninstall`` entries:
|
|
663
|
+
# nesting that tree below ``home-bugx`` can exceed MAX_PATH. Keep the
|
|
664
|
+
# durable user-home location when it is safe, but select the user temp
|
|
665
|
+
# directory for long-home test profiles and similarly deep Windows homes.
|
|
666
|
+
preferred = Path.home() / f".bugx-self-uninstall-backup-{time.time_ns()}"
|
|
667
|
+
if os.name == "nt" and len(str(preferred)) + 220 >= 240:
|
|
668
|
+
preferred = Path(tempfile.gettempdir()) / preferred.name
|
|
669
|
+
base = preferred.resolve()
|
|
670
|
+
_assert_no_symlink_components(base)
|
|
671
|
+
return base
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
def _backup_global_home_for_self_uninstall(
|
|
675
|
+
bugx_home: Path, backup_root: Path,
|
|
676
|
+
) -> None:
|
|
677
|
+
"""Snapshot global data without nesting historical archives indefinitely.
|
|
678
|
+
|
|
679
|
+
Project purge archives already live under ``~/.bugx/backups/uninstall``.
|
|
680
|
+
Copying that tree below ``home-bugx/backups/uninstall`` during a later
|
|
681
|
+
self-uninstall needlessly adds path segments and exceeds Windows MAX_PATH.
|
|
682
|
+
Keep the archive contents, but publish them beside the main snapshot.
|
|
683
|
+
"""
|
|
684
|
+
uninstall_archives = (bugx_home / "backups" / "uninstall").resolve()
|
|
685
|
+
|
|
686
|
+
def ignore_nested_archives(source: str, names: list[str]) -> list[str]:
|
|
687
|
+
try:
|
|
688
|
+
if Path(source).resolve() == bugx_home.resolve() / "backups":
|
|
689
|
+
return ["uninstall"] if "uninstall" in names else []
|
|
690
|
+
except OSError:
|
|
691
|
+
return []
|
|
692
|
+
return []
|
|
693
|
+
|
|
694
|
+
_backup_tree_external(
|
|
695
|
+
bugx_home,
|
|
696
|
+
backup_root / "home-bugx",
|
|
697
|
+
ignore=ignore_nested_archives,
|
|
698
|
+
)
|
|
699
|
+
if uninstall_archives.is_dir() and not uninstall_archives.is_symlink():
|
|
700
|
+
_backup_tree_external(
|
|
701
|
+
uninstall_archives,
|
|
702
|
+
backup_root / "uninstall-archives",
|
|
703
|
+
)
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
def _self_zcode_bugx_dirs(config_path: Path) -> list[str]:
|
|
707
|
+
"""读取 ZCode 用户配置中指向 BugX 插件目录的 plugins.dirs 条目。"""
|
|
708
|
+
if config_path.is_symlink() or not config_path.is_file():
|
|
709
|
+
return []
|
|
710
|
+
try:
|
|
711
|
+
loaded = json.loads(config_path.read_text(encoding="utf-8"))
|
|
712
|
+
except (OSError, json.JSONDecodeError):
|
|
713
|
+
return []
|
|
714
|
+
plugins_cfg = loaded.get("plugins") if isinstance(loaded, dict) else None
|
|
715
|
+
dirs_raw = plugins_cfg.get("dirs") if isinstance(plugins_cfg, dict) else None
|
|
716
|
+
if not isinstance(dirs_raw, list):
|
|
717
|
+
return []
|
|
718
|
+
return [
|
|
719
|
+
str(item) for item in dirs_raw
|
|
720
|
+
if isinstance(item, str)
|
|
721
|
+
and item.replace("\\", "/").rstrip("/").endswith("plugins/bugx")
|
|
722
|
+
]
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
def _self_remove_zcode_registrations(
|
|
726
|
+
backup_root: Path | None, removed: list[str], preserved: list[str],
|
|
727
|
+
) -> None:
|
|
728
|
+
config_path = _zcode_config_path()
|
|
729
|
+
entries = _self_zcode_bugx_dirs(config_path)
|
|
730
|
+
if not entries:
|
|
731
|
+
return
|
|
732
|
+
if config_path.is_symlink() or not config_path.is_file():
|
|
733
|
+
preserved.append("~/.zcode/cli/config.json(不是安全的普通文件,未清理)")
|
|
734
|
+
return
|
|
735
|
+
try:
|
|
736
|
+
loaded = json.loads(config_path.read_text(encoding="utf-8"))
|
|
737
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
738
|
+
preserved.append(f"~/.zcode/cli/config.json(无法解析:{exc})")
|
|
739
|
+
return
|
|
740
|
+
plugins_cfg = dict(loaded.get("plugins") or {})
|
|
741
|
+
dirs_raw = plugins_cfg.get("dirs") if isinstance(plugins_cfg, dict) else []
|
|
742
|
+
kept = [
|
|
743
|
+
str(item) for item in (dirs_raw or [])
|
|
744
|
+
if not (
|
|
745
|
+
isinstance(item, str)
|
|
746
|
+
and item.replace("\\", "/").rstrip("/").endswith("plugins/bugx")
|
|
747
|
+
)
|
|
748
|
+
]
|
|
749
|
+
plugins_cfg["dirs"] = kept
|
|
750
|
+
loaded["plugins"] = plugins_cfg
|
|
751
|
+
mcp_cfg = loaded.get("mcp")
|
|
752
|
+
if isinstance(mcp_cfg, dict) and isinstance(mcp_cfg.get("servers"), dict):
|
|
753
|
+
servers = mcp_cfg["servers"]
|
|
754
|
+
for key in list(servers.keys()):
|
|
755
|
+
if "bugx" in key.lower():
|
|
756
|
+
del servers[key]
|
|
757
|
+
if backup_root is not None:
|
|
758
|
+
_backup_tree_external(config_path, backup_root / "zcode-config.json")
|
|
759
|
+
_atomic_write_global_file(config_path, json.dumps(
|
|
760
|
+
loaded, ensure_ascii=False, indent=2,
|
|
761
|
+
).encode("utf-8") + b"\n")
|
|
762
|
+
removed.append(
|
|
763
|
+
f"~/.zcode/cli/config.json(移除 {len(entries)} 条 BugX plugins.dirs 登记)"
|
|
764
|
+
)
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
_ZCODE_USER_AGENT_OWNERSHIP_MARKS = (
|
|
768
|
+
"## 用户级子智能体边界", "## 用户级插件边界", "bugx engine path --name bugx-runtime-contract.md",
|
|
769
|
+
)
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
def _self_remove_zcode_user_agents(
|
|
773
|
+
backup_root: Path | None, removed: list[str], preserved: list[str],
|
|
774
|
+
) -> None:
|
|
775
|
+
"""清理用户级 BugX 子智能体(storage.dir/agents 下的 bugx*.md)。
|
|
776
|
+
|
|
777
|
+
ZCode 的 user 作用域扫描根是 storageRoot/agents;这里只删除能证明是
|
|
778
|
+
BugX 用户级入口的文件(内容含 BugX 边界标记或协议指认),其余保留。
|
|
779
|
+
"""
|
|
780
|
+
agents_dir = _zcode_user_agents_dir()
|
|
781
|
+
display_dir = f"{agents_dir}/"
|
|
782
|
+
if agents_dir.is_symlink() or not agents_dir.is_dir():
|
|
783
|
+
return
|
|
784
|
+
for filename in ("bugx.md", "bugx-worker.md"):
|
|
785
|
+
entry = agents_dir / filename
|
|
786
|
+
if not entry.exists() and not entry.is_symlink():
|
|
787
|
+
continue
|
|
788
|
+
if entry.is_symlink() or not entry.is_file():
|
|
789
|
+
preserved.append(f"{display_dir}{filename}(不是安全的普通文件,未清理)")
|
|
790
|
+
continue
|
|
791
|
+
try:
|
|
792
|
+
current = entry.read_text(encoding="utf-8")
|
|
793
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
794
|
+
preserved.append(f"{display_dir}{filename}(无法读取:{exc},未清理)")
|
|
795
|
+
continue
|
|
796
|
+
if not any(mark in current for mark in _ZCODE_USER_AGENT_OWNERSHIP_MARKS):
|
|
797
|
+
preserved.append(
|
|
798
|
+
f"{display_dir}{filename}(内容不是 BugX 用户级入口,保留)"
|
|
799
|
+
)
|
|
800
|
+
continue
|
|
801
|
+
if backup_root is not None:
|
|
802
|
+
_backup_tree_external(entry, backup_root / f"zcode-user-agent-{filename}")
|
|
803
|
+
try:
|
|
804
|
+
entry.unlink()
|
|
805
|
+
except OSError as exc:
|
|
806
|
+
preserved.append(f"{display_dir}{filename}(删除失败:{exc})")
|
|
807
|
+
continue
|
|
808
|
+
removed.append(f"{display_dir}{filename}(BugX 用户级子智能体已移除)")
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
_CLAUDE_USER_AGENT_OWNERSHIP_MARKS = (
|
|
812
|
+
"## 用户级智能体边界", "## User-level Agent Boundary",
|
|
813
|
+
"bugx engine path --name bugx-runtime-contract.md",
|
|
814
|
+
"BugX Worker — Claude Code",
|
|
815
|
+
)
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
def _self_remove_claude_user_agents(
|
|
819
|
+
backup_root: Path | None, removed: list[str], preserved: list[str],
|
|
820
|
+
) -> None:
|
|
821
|
+
"""清理用户级 BugX 智能体(~/.claude/agents 下的 bugx*.md、技能与插件登记)。"""
|
|
822
|
+
from .plugin_claude import (
|
|
823
|
+
_claude_user_agents_dir,
|
|
824
|
+
_remove_claude_user_skills,
|
|
825
|
+
_remove_claude_plugin_registry,
|
|
826
|
+
)
|
|
827
|
+
|
|
828
|
+
_remove_claude_user_skills(removed, preserved, backup_root=backup_root)
|
|
829
|
+
_remove_claude_plugin_registry(removed, preserved, backup_root=backup_root)
|
|
830
|
+
agents_dir = _claude_user_agents_dir()
|
|
831
|
+
display_dir = f"{agents_dir}/"
|
|
832
|
+
if agents_dir.is_symlink() or not agents_dir.is_dir():
|
|
833
|
+
return
|
|
834
|
+
for filename in ("bugx.md", "bugx-worker.md"):
|
|
835
|
+
entry = agents_dir / filename
|
|
836
|
+
if not entry.exists() and not entry.is_symlink():
|
|
837
|
+
continue
|
|
838
|
+
if entry.is_symlink() or not entry.is_file():
|
|
839
|
+
preserved.append(f"{display_dir}{filename}(不是安全的普通文件,未清理)")
|
|
840
|
+
continue
|
|
841
|
+
try:
|
|
842
|
+
current = entry.read_text(encoding="utf-8")
|
|
843
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
844
|
+
preserved.append(f"{display_dir}{filename}(无法读取:{exc},未清理)")
|
|
845
|
+
continue
|
|
846
|
+
if not any(mark in current for mark in _CLAUDE_USER_AGENT_OWNERSHIP_MARKS):
|
|
847
|
+
preserved.append(
|
|
848
|
+
f"{display_dir}{filename}(内容不是 BugX 用户级入口,保留)"
|
|
849
|
+
)
|
|
850
|
+
continue
|
|
851
|
+
if backup_root is not None:
|
|
852
|
+
_backup_tree_external(entry, backup_root / f"claude-user-agent-{filename}")
|
|
853
|
+
try:
|
|
854
|
+
entry.unlink()
|
|
855
|
+
except OSError as exc:
|
|
856
|
+
preserved.append(f"{display_dir}{filename}(删除失败:{exc})")
|
|
857
|
+
continue
|
|
858
|
+
removed.append(f"{display_dir}{filename}(BugX 用户级智能体已移除)")
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
_QODER_USER_ASSET_OWNERSHIP_MARKS = (
|
|
862
|
+
"## 用户级智能体与插件边界", "bugx engine path --name bugx-runtime-contract.md",
|
|
863
|
+
)
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
def _self_remove_qoder_user_assets(
|
|
867
|
+
backup_root: Path | None, removed: list[str], preserved: list[str],
|
|
868
|
+
) -> None:
|
|
869
|
+
"""清理 Qoder 用户级 BugX 资产(~/.qoder/agents, ~/.qoder/skills, 插件注册)。"""
|
|
870
|
+
from .plugin_qoder import (
|
|
871
|
+
_qoder_user_agents_dir,
|
|
872
|
+
_qoder_user_plugins_dir,
|
|
873
|
+
_qoder_user_skills_dir,
|
|
874
|
+
)
|
|
875
|
+
|
|
876
|
+
agents_dir = _qoder_user_agents_dir()
|
|
877
|
+
if agents_dir.is_dir() and not agents_dir.is_symlink():
|
|
878
|
+
display_dir = f"{agents_dir}/"
|
|
879
|
+
for filename in ("bugx.md", "bugx-worker.md"):
|
|
880
|
+
entry = agents_dir / filename
|
|
881
|
+
if not entry.exists() and not entry.is_symlink():
|
|
882
|
+
continue
|
|
883
|
+
if entry.is_symlink() or not entry.is_file():
|
|
884
|
+
preserved.append(f"{display_dir}{filename}(不是安全的普通文件,未清理)")
|
|
885
|
+
continue
|
|
886
|
+
try:
|
|
887
|
+
current = entry.read_text(encoding="utf-8")
|
|
888
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
889
|
+
preserved.append(f"{display_dir}{filename}(无法读取:{exc},未清理)")
|
|
890
|
+
continue
|
|
891
|
+
if not any(mark in current for mark in _QODER_USER_ASSET_OWNERSHIP_MARKS):
|
|
892
|
+
preserved.append(f"{display_dir}{filename}(内容不是 BugX 用户级入口,保留)")
|
|
893
|
+
continue
|
|
894
|
+
if backup_root is not None:
|
|
895
|
+
_backup_tree_external(entry, backup_root / f"qoder-user-agent-{filename}")
|
|
896
|
+
try:
|
|
897
|
+
entry.unlink()
|
|
898
|
+
except OSError as exc:
|
|
899
|
+
preserved.append(f"{display_dir}{filename}(删除失败:{exc})")
|
|
900
|
+
continue
|
|
901
|
+
removed.append(f"{display_dir}{filename}(BugX 用户级智能体已移除)")
|
|
902
|
+
|
|
903
|
+
skills_dir = _qoder_user_skills_dir() / "bugx"
|
|
904
|
+
if skills_dir.is_dir() and not skills_dir.is_symlink():
|
|
905
|
+
skill_file = skills_dir / "SKILL.md"
|
|
906
|
+
if skill_file.is_file() and not skill_file.is_symlink():
|
|
907
|
+
if backup_root is not None:
|
|
908
|
+
_backup_tree_external(skill_file, backup_root / "qoder-user-skill-SKILL.md")
|
|
909
|
+
try:
|
|
910
|
+
skill_file.unlink()
|
|
911
|
+
removed.append(f"{skills_dir}/SKILL.md(BugX 用户级技能已移除)")
|
|
912
|
+
skills_dir.rmdir()
|
|
913
|
+
except OSError as exc:
|
|
914
|
+
preserved.append(f"{skills_dir}(删除失败:{exc})")
|
|
915
|
+
|
|
916
|
+
plugins_dir = _qoder_user_plugins_dir()
|
|
917
|
+
v2_path = plugins_dir / "installed_plugins_v2.json"
|
|
918
|
+
if v2_path.is_file() and not v2_path.is_symlink():
|
|
919
|
+
try:
|
|
920
|
+
data = json.loads(v2_path.read_text(encoding="utf-8"))
|
|
921
|
+
if isinstance(data, dict) and isinstance(data.get("plugins"), dict):
|
|
922
|
+
plugins_map = data["plugins"]
|
|
923
|
+
if "bugx@bugx-agent" in plugins_map:
|
|
924
|
+
plugins_map.pop("bugx@bugx-agent", None)
|
|
925
|
+
v2_path.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
926
|
+
removed.append(f"{v2_path}(已注销 bugx 插件 v2)")
|
|
927
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
928
|
+
preserved.append(f"{v2_path}(插件注销失败:{exc})")
|
|
929
|
+
|
|
930
|
+
v1_path = plugins_dir / "installed_plugins.json"
|
|
931
|
+
if v1_path.is_file() and not v1_path.is_symlink():
|
|
932
|
+
try:
|
|
933
|
+
data = json.loads(v1_path.read_text(encoding="utf-8"))
|
|
934
|
+
if isinstance(data, dict) and isinstance(data.get("plugins"), dict):
|
|
935
|
+
plugins_map = data["plugins"]
|
|
936
|
+
if "bugx@bugx-agent" in plugins_map:
|
|
937
|
+
plugins_map.pop("bugx@bugx-agent", None)
|
|
938
|
+
v1_path.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
939
|
+
removed.append(f"{v1_path}(已注销 bugx 插件 v1)")
|
|
940
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
941
|
+
preserved.append(f"{v1_path}(插件注销失败:{exc})")
|
|
942
|
+
|
|
943
|
+
from .plugin_qoder import (
|
|
944
|
+
_qoder_user_plugin_cache_dir,
|
|
945
|
+
_qoder_user_settings_path,
|
|
946
|
+
)
|
|
947
|
+
import shutil
|
|
948
|
+
|
|
949
|
+
# 清理 settings.json 中 BugX 插件注册;MCP 仅由项目级配置管理。
|
|
950
|
+
settings_path = _qoder_user_settings_path()
|
|
951
|
+
if settings_path.is_file() and not settings_path.is_symlink():
|
|
952
|
+
try:
|
|
953
|
+
settings_data = json.loads(settings_path.read_text(encoding="utf-8"))
|
|
954
|
+
settings_modified = False
|
|
955
|
+
if isinstance(settings_data, dict):
|
|
956
|
+
enabled = settings_data.get("enabledPlugins")
|
|
957
|
+
if isinstance(enabled, dict) and "bugx@bugx-agent" in enabled:
|
|
958
|
+
enabled.pop("bugx@bugx-agent", None)
|
|
959
|
+
settings_modified = True
|
|
960
|
+
if settings_modified:
|
|
961
|
+
settings_path.write_text(json.dumps(settings_data, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
962
|
+
removed.append(f"{settings_path}(已移除 bugx 插件注册)")
|
|
963
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
964
|
+
preserved.append(f"{settings_path}(清理失败:{exc})")
|
|
965
|
+
|
|
966
|
+
# 清理 ~/.qoder/plugins/cache/bugx-agent/bugx
|
|
967
|
+
cache_dir = _qoder_user_plugin_cache_dir()
|
|
968
|
+
if cache_dir.is_dir() and not cache_dir.is_symlink():
|
|
969
|
+
try:
|
|
970
|
+
shutil.rmtree(cache_dir)
|
|
971
|
+
removed.append(f"{cache_dir}(已移除插件缓存)")
|
|
972
|
+
except OSError as exc:
|
|
973
|
+
preserved.append(f"{cache_dir}(删除失败:{exc})")
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
_FUNIDE_USER_AGENT_OWNERSHIP_MARKS = (
|
|
977
|
+
"## FunIDE 用户级智能体边界",
|
|
978
|
+
"bugx engine path --name bugx-runtime-contract.md",
|
|
979
|
+
)
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
def _self_remove_funide_user_agent(
|
|
983
|
+
backup_root: Path | None, removed: list[str], preserved: list[str],
|
|
984
|
+
) -> None:
|
|
985
|
+
"""清理 FunIDE/Copilot 用户级 BugX Agent,保留用户自有文件。"""
|
|
986
|
+
from .plugin_funide import _funide_user_agents_dir
|
|
987
|
+
|
|
988
|
+
agents_dir = _funide_user_agents_dir()
|
|
989
|
+
entry = agents_dir / "bugx.agent.md"
|
|
990
|
+
if not entry.exists() and not entry.is_symlink():
|
|
991
|
+
return
|
|
992
|
+
display = str(entry)
|
|
993
|
+
if entry.is_symlink() or not entry.is_file():
|
|
994
|
+
preserved.append(f"{display}(不是安全的普通文件,未清理)")
|
|
995
|
+
return
|
|
996
|
+
try:
|
|
997
|
+
current = entry.read_text(encoding="utf-8")
|
|
998
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
999
|
+
preserved.append(f"{display}(无法读取:{exc},未清理)")
|
|
1000
|
+
return
|
|
1001
|
+
if not all(mark in current for mark in _FUNIDE_USER_AGENT_OWNERSHIP_MARKS):
|
|
1002
|
+
preserved.append(f"{display}(内容不是 BugX 用户级入口,保留)")
|
|
1003
|
+
return
|
|
1004
|
+
if backup_root is not None:
|
|
1005
|
+
_backup_tree_external(entry, backup_root / "funide-user-agent-bugx.agent.md")
|
|
1006
|
+
try:
|
|
1007
|
+
entry.unlink()
|
|
1008
|
+
except OSError as exc:
|
|
1009
|
+
preserved.append(f"{display}(删除失败:{exc})")
|
|
1010
|
+
return
|
|
1011
|
+
removed.append(f"{display}(FunIDE 用户级智能体已移除)")
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
def _self_remove_funide_native_agent(
|
|
1015
|
+
backup_root: Path | None, removed: list[str], preserved: list[str],
|
|
1016
|
+
) -> None:
|
|
1017
|
+
"""Remove only BugX's FunIDE Settings → 智能体 registry entry."""
|
|
1018
|
+
from .plugin_funide import _NATIVE_AGENT_OWNERSHIP_MARK, _funide_data_dir
|
|
1019
|
+
|
|
1020
|
+
target = _funide_data_dir() / "agents.json"
|
|
1021
|
+
if not target.exists() and not target.is_symlink():
|
|
1022
|
+
return
|
|
1023
|
+
display = str(target)
|
|
1024
|
+
if target.is_symlink() or not target.is_file():
|
|
1025
|
+
preserved.append(f"{display}(不是安全的普通文件,未清理)")
|
|
1026
|
+
return
|
|
1027
|
+
try:
|
|
1028
|
+
data = json.loads(target.read_text(encoding="utf-8"))
|
|
1029
|
+
except (OSError, UnicodeDecodeError, json.JSONDecodeError) as exc:
|
|
1030
|
+
preserved.append(f"{display}(无法读取:{exc},未清理)")
|
|
1031
|
+
return
|
|
1032
|
+
if not isinstance(data, dict) or not isinstance(data.get("agents"), list):
|
|
1033
|
+
preserved.append(f"{display}(格式异常,未清理)")
|
|
1034
|
+
return
|
|
1035
|
+
agents = data["agents"]
|
|
1036
|
+
index = next(
|
|
1037
|
+
(i for i, item in enumerate(agents)
|
|
1038
|
+
if isinstance(item, dict) and item.get("id") == "bugx"),
|
|
1039
|
+
None,
|
|
1040
|
+
)
|
|
1041
|
+
if index is None:
|
|
1042
|
+
return
|
|
1043
|
+
item = agents[index]
|
|
1044
|
+
if not isinstance(item, dict) or _NATIVE_AGENT_OWNERSHIP_MARK not in str(item.get("systemPrompt", "")):
|
|
1045
|
+
preserved.append(f"{display}(id=bugx 不是 BugX 注册项,保留)")
|
|
1046
|
+
return
|
|
1047
|
+
if backup_root is not None:
|
|
1048
|
+
_backup_tree_external(target, backup_root / "funide-native-agents.json")
|
|
1049
|
+
agents.pop(index)
|
|
1050
|
+
try:
|
|
1051
|
+
_atomic_write_global_file(
|
|
1052
|
+
target,
|
|
1053
|
+
(json.dumps(data, ensure_ascii=False, indent="\t") + "\n").encode("utf-8"),
|
|
1054
|
+
)
|
|
1055
|
+
except Exception as exc:
|
|
1056
|
+
preserved.append(f"{display}(写回失败:{exc},未清理)")
|
|
1057
|
+
return
|
|
1058
|
+
removed.append(f"{display}(FunIDE 原生智能体注册已移除)")
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
def _self_remove_funide_native_skill(
|
|
1062
|
+
backup_root: Path | None, removed: list[str], preserved: list[str],
|
|
1063
|
+
) -> None:
|
|
1064
|
+
"""Remove only BugX's FunIDE Settings → 技能 entry."""
|
|
1065
|
+
from .plugin_funide import _NATIVE_SKILL_OWNERSHIP_MARK, _funide_user_skills_dir
|
|
1066
|
+
|
|
1067
|
+
target = _funide_user_skills_dir() / "bugx" / "SKILL.md"
|
|
1068
|
+
if not target.exists() and not target.is_symlink():
|
|
1069
|
+
return
|
|
1070
|
+
display = str(target)
|
|
1071
|
+
if target.is_symlink() or not target.is_file():
|
|
1072
|
+
preserved.append(f"{display}(不是安全的普通文件,未清理)")
|
|
1073
|
+
return
|
|
1074
|
+
try:
|
|
1075
|
+
content = target.read_text(encoding="utf-8")
|
|
1076
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
1077
|
+
preserved.append(f"{display}(无法读取:{exc},未清理)")
|
|
1078
|
+
return
|
|
1079
|
+
if _NATIVE_SKILL_OWNERSHIP_MARK not in content:
|
|
1080
|
+
preserved.append(f"{display}(内容不是 BugX 用户级技能,保留)")
|
|
1081
|
+
return
|
|
1082
|
+
if backup_root is not None:
|
|
1083
|
+
_backup_tree_external(target, backup_root / "funide-native-skill-bugx.SKILL.md")
|
|
1084
|
+
try:
|
|
1085
|
+
target.unlink()
|
|
1086
|
+
target.parent.rmdir()
|
|
1087
|
+
except OSError as exc:
|
|
1088
|
+
preserved.append(f"{display}(删除失败:{exc})")
|
|
1089
|
+
return
|
|
1090
|
+
removed.append(f"{display}(FunIDE 原生技能已移除)")
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
def _self_remove_funide_profile_mcp(
|
|
1094
|
+
backup_root: Path | None, removed: list[str], preserved: list[str],
|
|
1095
|
+
) -> None:
|
|
1096
|
+
"""Remove BugX-owned entries from FunIDE's user-level MCP profile."""
|
|
1097
|
+
from .plugin_funide import (
|
|
1098
|
+
_funide_native_mcp_names,
|
|
1099
|
+
_funide_profile_mcp_entry_owned,
|
|
1100
|
+
_funide_profile_mcp_path,
|
|
1101
|
+
)
|
|
1102
|
+
|
|
1103
|
+
target = _funide_profile_mcp_path()
|
|
1104
|
+
if not target.exists() and not target.is_symlink():
|
|
1105
|
+
return
|
|
1106
|
+
display = str(target)
|
|
1107
|
+
if target.is_symlink() or not target.is_file():
|
|
1108
|
+
preserved.append(f"{display}(不是安全的普通文件,未清理)")
|
|
1109
|
+
return
|
|
1110
|
+
try:
|
|
1111
|
+
payload = json.loads(target.read_text(encoding="utf-8"))
|
|
1112
|
+
except (OSError, UnicodeDecodeError, json.JSONDecodeError) as exc:
|
|
1113
|
+
preserved.append(f"{display}(无法解析:{exc},未清理)")
|
|
1114
|
+
return
|
|
1115
|
+
if not isinstance(payload, dict) or not isinstance(payload.get("servers"), dict):
|
|
1116
|
+
preserved.append(f"{display}(缺少 servers 对象,未清理)")
|
|
1117
|
+
return
|
|
1118
|
+
servers = payload["servers"]
|
|
1119
|
+
names = [
|
|
1120
|
+
name for name in _funide_native_mcp_names()
|
|
1121
|
+
if name in servers and _funide_profile_mcp_entry_owned(name, servers[name])
|
|
1122
|
+
]
|
|
1123
|
+
if not names:
|
|
1124
|
+
return
|
|
1125
|
+
if backup_root is not None:
|
|
1126
|
+
_backup_tree_external(target, backup_root / "funide-user-mcp.json")
|
|
1127
|
+
for name in names:
|
|
1128
|
+
servers.pop(name, None)
|
|
1129
|
+
try:
|
|
1130
|
+
_atomic_write_global_file(
|
|
1131
|
+
target,
|
|
1132
|
+
(json.dumps(payload, ensure_ascii=False, indent="\t") + "\n").encode("utf-8"),
|
|
1133
|
+
)
|
|
1134
|
+
except OSError as exc:
|
|
1135
|
+
preserved.append(f"{display}(写回失败:{exc},未清理)")
|
|
1136
|
+
return
|
|
1137
|
+
removed.append(f"{display}(FunIDE 用户级 MCP:已移除 {', '.join(names)})")
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
def _self_uninstall_opencode_links(
|
|
1141
|
+
backup_root: Path | None,
|
|
1142
|
+
removed: list[str], preserved: list[str],
|
|
1143
|
+
) -> None:
|
|
1144
|
+
agents_dir = _self_home_dir(".config", "opencode", "agents")
|
|
1145
|
+
engine_root = global_engine_root()
|
|
1146
|
+
for filename in ("bugx.md", "bugx-worker.md"):
|
|
1147
|
+
entry = agents_dir / filename
|
|
1148
|
+
if not entry.is_symlink() and not entry.exists():
|
|
1149
|
+
continue
|
|
1150
|
+
alt_name = "bugx-opencode.md" if filename == "bugx.md" else filename
|
|
1151
|
+
cand = engine_root / "contracts" / alt_name
|
|
1152
|
+
expected = cand if cand.is_file() else (engine_root / alt_name)
|
|
1153
|
+
if not entry.is_symlink():
|
|
1154
|
+
# Windows may not grant SeCreateSymbolicLinkPrivilege. The
|
|
1155
|
+
# installer then publishes a byte-for-byte copy; recognize only
|
|
1156
|
+
# that exact copy as BugX-owned and preserve user edits.
|
|
1157
|
+
try:
|
|
1158
|
+
owned_copy = entry.is_file() and expected.is_file() \
|
|
1159
|
+
and _sha256_file(entry) == _sha256_file(expected)
|
|
1160
|
+
except OSError:
|
|
1161
|
+
owned_copy = False
|
|
1162
|
+
if not owned_copy:
|
|
1163
|
+
preserved.append(
|
|
1164
|
+
f"~/.config/opencode/agents/{filename}(不是 BugX 副本入口或内容已变化,保留)"
|
|
1165
|
+
)
|
|
1166
|
+
continue
|
|
1167
|
+
if backup_root is not None:
|
|
1168
|
+
_backup_tree_external(entry, backup_root / f"opencode-copy-{filename}")
|
|
1169
|
+
try:
|
|
1170
|
+
entry.unlink()
|
|
1171
|
+
except OSError as exc:
|
|
1172
|
+
preserved.append(f"~/.config/opencode/agents/{filename}(删除失败:{exc})")
|
|
1173
|
+
continue
|
|
1174
|
+
removed.append(f"~/.config/opencode/agents/{filename}(全局入口副本)")
|
|
1175
|
+
continue
|
|
1176
|
+
try:
|
|
1177
|
+
target = entry.resolve(strict=False)
|
|
1178
|
+
except OSError as exc:
|
|
1179
|
+
preserved.append(f"~/.config/opencode/agents/{filename}(无法解析:{exc})")
|
|
1180
|
+
continue
|
|
1181
|
+
if target in (expected.resolve(strict=False), (engine_root / filename).resolve(strict=False)):
|
|
1182
|
+
try:
|
|
1183
|
+
entry.unlink()
|
|
1184
|
+
except OSError as exc:
|
|
1185
|
+
preserved.append(f"~/.config/opencode/agents/{filename}(删除失败:{exc})")
|
|
1186
|
+
continue
|
|
1187
|
+
removed.append(f"~/.config/opencode/agents/{filename}(全局入口链接)")
|
|
1188
|
+
else:
|
|
1189
|
+
preserved.append(
|
|
1190
|
+
f"~/.config/opencode/agents/{filename}(未指向 BugX 全局引擎,保留)"
|
|
1191
|
+
)
|
|
1192
|
+
|
|
1193
|
+
|
|
1194
|
+
def _self_uninstall_pi_skill(
|
|
1195
|
+
backup_root: Path | None, removed: list[str], preserved: list[str],
|
|
1196
|
+
) -> None:
|
|
1197
|
+
agents_skill_dir = _self_home_dir(".agents", "skills", "bugx")
|
|
1198
|
+
pi_skill_dir = _self_home_dir(".pi", "skills", "bugx")
|
|
1199
|
+
pi_agent_skill_dir = _self_home_dir(".pi", "agent", "skills", "bugx")
|
|
1200
|
+
for label, p_dir in (("~/.pi/skills/bugx", pi_skill_dir), ("~/.pi/agent/skills/bugx", pi_agent_skill_dir)):
|
|
1201
|
+
if p_dir.is_symlink():
|
|
1202
|
+
p_dir.unlink()
|
|
1203
|
+
removed.append(f"{label}(全局 skill 链接)")
|
|
1204
|
+
elif p_dir.exists():
|
|
1205
|
+
# On Windows the installer may publish a directory copy when
|
|
1206
|
+
# symlink creation is unavailable. Remove only an exact copy of the
|
|
1207
|
+
# BugX-owned global skill; never remove a user-edited directory.
|
|
1208
|
+
global_skill = agents_skill_dir / "SKILL.md"
|
|
1209
|
+
candidate = p_dir / "SKILL.md"
|
|
1210
|
+
try:
|
|
1211
|
+
owned_copy = (p_dir.is_dir() and candidate.is_file()
|
|
1212
|
+
and global_skill.is_file()
|
|
1213
|
+
and _sha256_file(candidate) == _sha256_file(global_skill))
|
|
1214
|
+
except OSError:
|
|
1215
|
+
owned_copy = False
|
|
1216
|
+
if owned_copy:
|
|
1217
|
+
if backup_root is not None:
|
|
1218
|
+
_backup_tree_external(p_dir, backup_root / p_dir.name)
|
|
1219
|
+
shutil.rmtree(p_dir)
|
|
1220
|
+
removed.append(f"{label}(全局 skill 副本)")
|
|
1221
|
+
else:
|
|
1222
|
+
preserved.append(f"{label}(不是 BugX 副本或内容已变化,保留)")
|
|
1223
|
+
if agents_skill_dir.is_symlink():
|
|
1224
|
+
agents_skill_dir.unlink()
|
|
1225
|
+
removed.append("~/.agents/skills/bugx(符号链接)")
|
|
1226
|
+
return
|
|
1227
|
+
if agents_skill_dir.is_dir():
|
|
1228
|
+
if backup_root is not None:
|
|
1229
|
+
_backup_tree_external(agents_skill_dir, backup_root / "pi-global-skill")
|
|
1230
|
+
shutil.rmtree(agents_skill_dir)
|
|
1231
|
+
removed.append("~/.agents/skills/bugx(全局 skill 实体)")
|
|
1232
|
+
elif agents_skill_dir.exists():
|
|
1233
|
+
preserved.append("~/.agents/skills/bugx(不是安全目录,保留)")
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
def _self_uninstall_dsh_preset(
|
|
1237
|
+
backup_root: Path | None, removed: list[str], preserved: list[str],
|
|
1238
|
+
) -> None:
|
|
1239
|
+
preset_dir = _self_home_dir(".dsh", ".agent-presets", "bugx")
|
|
1240
|
+
if preset_dir.is_symlink() or not preset_dir.is_dir():
|
|
1241
|
+
return
|
|
1242
|
+
if backup_root is not None:
|
|
1243
|
+
_backup_tree_external(preset_dir, backup_root / "dsh-agent-presets")
|
|
1244
|
+
shutil.rmtree(preset_dir)
|
|
1245
|
+
removed.append("~/.dsh/.agent-presets/bugx(全局预设)")
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
def _self_uninstall_dsh_ui_plugin(
|
|
1249
|
+
backup_root: Path | None, removed: list[str], preserved: list[str],
|
|
1250
|
+
) -> None:
|
|
1251
|
+
"""Remove the BugX DSH web bundle and its profile registration."""
|
|
1252
|
+
dsh_home = _dsh_home()
|
|
1253
|
+
plugin_root = dsh_home / "plugins" / "bugx-ui"
|
|
1254
|
+
profile_root = dsh_home / "profiles" / "web"
|
|
1255
|
+
if not plugin_root.exists():
|
|
1256
|
+
return
|
|
1257
|
+
dsh = shutil.which("dsh")
|
|
1258
|
+
if dsh and (profile_root / "package.json").is_file():
|
|
1259
|
+
try:
|
|
1260
|
+
result = subprocess.run(
|
|
1261
|
+
[dsh, "plugin", "--profile", "web", "remove", "@bencibro/bugx-dsh-ui"],
|
|
1262
|
+
cwd=profile_root, capture_output=True, text=True, check=False,
|
|
1263
|
+
timeout=120,
|
|
1264
|
+
)
|
|
1265
|
+
except (OSError, subprocess.TimeoutExpired) as exc:
|
|
1266
|
+
preserved.append(f"{plugin_root}(web profile 注销失败:{exc})")
|
|
1267
|
+
return
|
|
1268
|
+
if result.returncode != 0:
|
|
1269
|
+
detail = (result.stderr or result.stdout or "dsh plugin remove 失败").strip()
|
|
1270
|
+
preserved.append(f"{plugin_root}(web profile 注销失败:{detail[-300:]})")
|
|
1271
|
+
return
|
|
1272
|
+
if plugin_root.is_symlink() or not plugin_root.is_dir():
|
|
1273
|
+
preserved.append(f"{plugin_root}(不是安全目录,未清理)")
|
|
1274
|
+
return
|
|
1275
|
+
if backup_root is not None:
|
|
1276
|
+
_backup_tree_external(plugin_root, backup_root / "dsh-ui-plugin")
|
|
1277
|
+
shutil.rmtree(plugin_root)
|
|
1278
|
+
removed.append(f"{plugin_root}(DSH UI 插件)")
|
|
1279
|
+
|
|
1280
|
+
|
|
1281
|
+
def _self_uninstall_workbuddy_skill(
|
|
1282
|
+
root: Path, backup_root: Path | None, removed: list[str], preserved: list[str],
|
|
1283
|
+
) -> None:
|
|
1284
|
+
"""清理用户级 WorkBuddy Skill;仅当与当前模板一致时删除。
|
|
1285
|
+
|
|
1286
|
+
用户级 Skill 是全局层工件(与 zcode 用户级 agents 同语义),
|
|
1287
|
+
项目级卸载永远保留;只有 ``uninstall --self`` 才处理。所有权判定
|
|
1288
|
+
采用内容比对:与当前渲染模板(``strip_locale_marker`` 后)逐字
|
|
1289
|
+
一致才视为 BugX 自有;用户改过一行即保留并如实报告。
|
|
1290
|
+
"""
|
|
1291
|
+
valid_templates: set[str] = set()
|
|
1292
|
+
candidate = global_engine_root() / "bugx.md"
|
|
1293
|
+
if not candidate.is_file():
|
|
1294
|
+
candidate = asset_root() / "bugx.md"
|
|
1295
|
+
if candidate.is_file():
|
|
1296
|
+
for loc in ("zh-CN", "en-US", None):
|
|
1297
|
+
try:
|
|
1298
|
+
valid_templates.add(
|
|
1299
|
+
strip_locale_marker(
|
|
1300
|
+
get_adapter("workbuddy").render(candidate, locale=loc)
|
|
1301
|
+
).strip()
|
|
1302
|
+
)
|
|
1303
|
+
except (CliError, OSError):
|
|
1304
|
+
pass
|
|
1305
|
+
for config_root in _workbuddy_config_roots():
|
|
1306
|
+
skill = config_root / "skills" / "bugx" / "SKILL.md"
|
|
1307
|
+
if not skill.is_file() or skill.is_symlink():
|
|
1308
|
+
continue
|
|
1309
|
+
display = str(skill)
|
|
1310
|
+
if not valid_templates:
|
|
1311
|
+
preserved.append(f"{display}(无法读取当前模板,保留)")
|
|
1312
|
+
continue
|
|
1313
|
+
try:
|
|
1314
|
+
current = strip_locale_marker(
|
|
1315
|
+
skill.read_text(encoding="utf-8")
|
|
1316
|
+
).strip()
|
|
1317
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
1318
|
+
preserved.append(f"{display}(读取失败:{exc},保留)")
|
|
1319
|
+
continue
|
|
1320
|
+
if current not in valid_templates:
|
|
1321
|
+
preserved.append(f"{display}(内容与 BugX 模板不一致,保留)")
|
|
1322
|
+
continue
|
|
1323
|
+
if backup_root is not None:
|
|
1324
|
+
_backup_tree_external(
|
|
1325
|
+
skill,
|
|
1326
|
+
backup_root / "workbuddy-user-skill" / config_root.name / skill.name,
|
|
1327
|
+
)
|
|
1328
|
+
try:
|
|
1329
|
+
skill.unlink()
|
|
1330
|
+
except OSError as exc:
|
|
1331
|
+
preserved.append(f"{display}(删除失败:{exc})")
|
|
1332
|
+
continue
|
|
1333
|
+
removed.append(f"{display}(WorkBuddy 用户级 Skill)")
|
|
1334
|
+
for parent in (skill.parent, skill.parent.parent):
|
|
1335
|
+
try:
|
|
1336
|
+
parent.rmdir()
|
|
1337
|
+
except OSError:
|
|
1338
|
+
break
|
|
1339
|
+
expert_dir = config_root / "plugins" / "marketplaces" / "my-experts" / "plugins" / "bugx"
|
|
1340
|
+
if expert_dir.is_dir() and not expert_dir.is_symlink():
|
|
1341
|
+
if backup_root is not None:
|
|
1342
|
+
_backup_tree_external(
|
|
1343
|
+
expert_dir,
|
|
1344
|
+
backup_root / "workbuddy-custom-expert" / config_root.name / "bugx",
|
|
1345
|
+
)
|
|
1346
|
+
try:
|
|
1347
|
+
shutil.rmtree(expert_dir)
|
|
1348
|
+
removed.append(f"{expert_dir}(WorkBuddy 自定义专家)")
|
|
1349
|
+
except OSError as exc:
|
|
1350
|
+
preserved.append(f"{expert_dir}(删除失败:{exc})")
|
|
1351
|
+
market_manifest_path = config_root / "plugins" / "marketplaces" / "my-experts" / ".codebuddy-plugin" / "marketplace.json"
|
|
1352
|
+
if market_manifest_path.is_file():
|
|
1353
|
+
try:
|
|
1354
|
+
m_data = json.loads(market_manifest_path.read_text(encoding="utf-8"))
|
|
1355
|
+
if isinstance(m_data, dict) and isinstance(m_data.get("plugins"), list):
|
|
1356
|
+
m_data["plugins"] = [p for p in m_data["plugins"] if isinstance(p, dict) and p.get("name") != "bugx"]
|
|
1357
|
+
market_manifest_path.write_text(json.dumps(m_data, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
1358
|
+
except (OSError, json.JSONDecodeError):
|
|
1359
|
+
pass
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
def _self_codex_registrations() -> tuple[Path, list[str], list[str]]:
|
|
1363
|
+
"""读取 ~/.codex/config.toml 中 BugX 本地 marketplace 与插件登记。"""
|
|
1364
|
+
config_path = _self_home_dir(".codex", "config.toml")
|
|
1365
|
+
marketplaces: list[str] = []
|
|
1366
|
+
plugins: list[str] = []
|
|
1367
|
+
if config_path.is_symlink() or not config_path.is_file():
|
|
1368
|
+
return config_path, marketplaces, plugins
|
|
1369
|
+
try:
|
|
1370
|
+
payload = tomllib.loads(config_path.read_text(encoding="utf-8"))
|
|
1371
|
+
except (OSError, ValueError) as exc:
|
|
1372
|
+
raise CliError(_i18n_exc("lifecycle.codex_config_unparseable", f"~/.codex/config.toml 无法解析:{exc}", exc=exc)) from exc
|
|
1373
|
+
section = payload.get("marketplaces")
|
|
1374
|
+
if isinstance(section, dict):
|
|
1375
|
+
marketplaces = sorted(
|
|
1376
|
+
str(key) for key in section
|
|
1377
|
+
if str(key).startswith("bugx-local-")
|
|
1378
|
+
or str(key) == CHATGPT_GLOBAL_MARKETPLACE_NAME
|
|
1379
|
+
)
|
|
1380
|
+
plugin_section = payload.get("plugins")
|
|
1381
|
+
if isinstance(plugin_section, dict):
|
|
1382
|
+
plugins = sorted(
|
|
1383
|
+
str(key) for key in plugin_section
|
|
1384
|
+
if str(key).startswith(f"{CHATGPT_PLUGIN_NAME}@bugx-local-")
|
|
1385
|
+
or str(key) == f"{CHATGPT_PLUGIN_NAME}@{CHATGPT_GLOBAL_MARKETPLACE_NAME}"
|
|
1386
|
+
)
|
|
1387
|
+
return config_path, marketplaces, plugins
|
|
1388
|
+
|
|
1389
|
+
|
|
1390
|
+
def _codex_binary() -> str | None:
|
|
1391
|
+
return shutil.which("codex")
|
|
1392
|
+
|
|
1393
|
+
|
|
1394
|
+
def _run_codex_plugin_command(
|
|
1395
|
+
command: list[str],
|
|
1396
|
+
) -> tuple[bool, str]:
|
|
1397
|
+
try:
|
|
1398
|
+
process = subprocess.run(
|
|
1399
|
+
command, capture_output=True, text=True, check=False, timeout=120,
|
|
1400
|
+
)
|
|
1401
|
+
except (OSError, subprocess.TimeoutExpired) as exc:
|
|
1402
|
+
return False, str(exc)
|
|
1403
|
+
detail = (process.stderr or process.stdout or "").strip()[-200:]
|
|
1404
|
+
return process.returncode == 0, detail
|
|
1405
|
+
|
|
1406
|
+
|
|
1407
|
+
def _self_uninstall_codex_plugins(
|
|
1408
|
+
backup_root: Path | None, removed: list[str], preserved: list[str],
|
|
1409
|
+
) -> None:
|
|
1410
|
+
try:
|
|
1411
|
+
config_path, marketplaces, plugins = _self_codex_registrations()
|
|
1412
|
+
except CliError as exc:
|
|
1413
|
+
preserved.append(str(exc))
|
|
1414
|
+
return
|
|
1415
|
+
if not marketplaces and not plugins:
|
|
1416
|
+
return
|
|
1417
|
+
codex = _codex_binary()
|
|
1418
|
+
if not codex:
|
|
1419
|
+
preserved.append(
|
|
1420
|
+
"~/.codex/config.toml(未找到 codex 命令,无法自动注销;请手工执行 "
|
|
1421
|
+
"codex plugin remove / codex plugin marketplace remove:"
|
|
1422
|
+
+ ", ".join(sorted(set(marketplaces))) + ")"
|
|
1423
|
+
)
|
|
1424
|
+
return
|
|
1425
|
+
if backup_root is not None and config_path.is_file():
|
|
1426
|
+
_backup_tree_external(config_path, backup_root / "codex-config.toml")
|
|
1427
|
+
for plugin_key in plugins:
|
|
1428
|
+
ok, detail = _run_codex_plugin_command(
|
|
1429
|
+
[codex, "plugin", "remove", plugin_key, "--json"])
|
|
1430
|
+
if ok:
|
|
1431
|
+
removed.append(f"~/.codex/config.toml(注销 codex 插件 {plugin_key})")
|
|
1432
|
+
else:
|
|
1433
|
+
preserved.append(f"~/.codex/config.toml(注销 {plugin_key} 失败:{detail})")
|
|
1434
|
+
for name in marketplaces:
|
|
1435
|
+
ok, detail = _run_codex_plugin_command(
|
|
1436
|
+
[codex, "plugin", "marketplace", "remove", name])
|
|
1437
|
+
if ok:
|
|
1438
|
+
removed.append(f"~/.codex/config.toml(移除 codex marketplace {name})")
|
|
1439
|
+
else:
|
|
1440
|
+
preserved.append(f"~/.codex/config.toml(移除 marketplace {name} 失败:{detail})")
|
|
1441
|
+
cache_root = _self_home_dir(".codex", "plugins", "cache")
|
|
1442
|
+
if cache_root.is_dir():
|
|
1443
|
+
for child in sorted(cache_root.iterdir()):
|
|
1444
|
+
if (child.name.startswith("bugx-local-")
|
|
1445
|
+
or child.name == CHATGPT_GLOBAL_MARKETPLACE_NAME) \
|
|
1446
|
+
and child.is_dir() and not child.is_symlink():
|
|
1447
|
+
shutil.rmtree(child, ignore_errors=True)
|
|
1448
|
+
removed.append(f"~/.codex/plugins/cache/{child.name}(codex 插件缓存)")
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
def _deregister_codex_plugin(
|
|
1452
|
+
root: Path, removed: list[str], preserved: list[str],
|
|
1453
|
+
) -> None:
|
|
1454
|
+
"""项目级 chatgpt 卸载:清理项目域历史登记,并**显式声明**全局单例保留。
|
|
1455
|
+
|
|
1456
|
+
本代 ``install`` 只注册机器级单例 ``bugx@bugx-global``(``plugin.py`` 的
|
|
1457
|
+
``codex plugin marketplace add ~/.bugx/chatgpt-plugin`` + ``codex plugin
|
|
1458
|
+
add bugx@bugx-global``),从不写项目域 marketplace 名。旧实现只匹配
|
|
1459
|
+
``bugx-local-<hash>``,因此恒为空操作却声称"反向注销全局登记"(2026-11-09
|
|
1460
|
+
审计 P2)。修复采用**共享资源语义**:一个项目卸载不得撤销其它项目仍在
|
|
1461
|
+
使用的机器级注册,全局清理由 ``bugx uninstall --self`` 负责;这里在按
|
|
1462
|
+
所有权核验后显式记录"保留"原因,杜绝静默空转。
|
|
1463
|
+
"""
|
|
1464
|
+
try:
|
|
1465
|
+
_config_path, marketplaces, plugins = _self_codex_registrations()
|
|
1466
|
+
except CliError as exc:
|
|
1467
|
+
preserved.append(str(exc))
|
|
1468
|
+
return
|
|
1469
|
+
name = _chatgpt_marketplace_name(root)
|
|
1470
|
+
legacy_plugins = [item for item in plugins if item.endswith(f"@{name}")]
|
|
1471
|
+
legacy_marketplaces = [name] if name in marketplaces else []
|
|
1472
|
+
codex = _codex_binary()
|
|
1473
|
+
if legacy_plugins or legacy_marketplaces:
|
|
1474
|
+
if not codex:
|
|
1475
|
+
preserved.append(
|
|
1476
|
+
f"codex 插件登记 {name}(未找到 codex 命令;请手工 codex plugin remove / "
|
|
1477
|
+
"codex plugin marketplace remove)"
|
|
1478
|
+
)
|
|
1479
|
+
else:
|
|
1480
|
+
for plugin_key in legacy_plugins:
|
|
1481
|
+
ok, detail = _run_codex_plugin_command(
|
|
1482
|
+
[codex, "plugin", "remove", plugin_key, "--json"])
|
|
1483
|
+
if ok:
|
|
1484
|
+
removed.append(f"codex 插件 {plugin_key}(已注销)")
|
|
1485
|
+
else:
|
|
1486
|
+
preserved.append(f"codex 插件 {plugin_key}(注销失败:{detail})")
|
|
1487
|
+
for legacy_name in legacy_marketplaces:
|
|
1488
|
+
ok, detail = _run_codex_plugin_command(
|
|
1489
|
+
[codex, "plugin", "marketplace", "remove", legacy_name])
|
|
1490
|
+
if ok:
|
|
1491
|
+
removed.append(f"codex marketplace {legacy_name}(已移除)")
|
|
1492
|
+
else:
|
|
1493
|
+
preserved.append(f"codex marketplace {legacy_name}(移除失败:{detail})")
|
|
1494
|
+
|
|
1495
|
+
global_plugin = f"{CHATGPT_PLUGIN_NAME}@{CHATGPT_GLOBAL_MARKETPLACE_NAME}"
|
|
1496
|
+
global_registered = (
|
|
1497
|
+
global_plugin in plugins or CHATGPT_GLOBAL_MARKETPLACE_NAME in marketplaces
|
|
1498
|
+
)
|
|
1499
|
+
if not global_registered:
|
|
1500
|
+
return
|
|
1501
|
+
owned = False
|
|
1502
|
+
try:
|
|
1503
|
+
owned = _is_bugx_marketplace_source(_chatgpt_global_plugin_root())
|
|
1504
|
+
except (OSError, ValueError):
|
|
1505
|
+
owned = False
|
|
1506
|
+
if owned:
|
|
1507
|
+
preserved.append(
|
|
1508
|
+
f"~/.codex/config.toml(全局 ChatGPT 插件 {global_plugin} 保留:"
|
|
1509
|
+
"机器级共享资源,清理请执行 bugx uninstall --self)"
|
|
1510
|
+
)
|
|
1511
|
+
else:
|
|
1512
|
+
preserved.append(
|
|
1513
|
+
f"~/.codex/config.toml({global_plugin} 不是 BugX 所有的来源,未修改)"
|
|
1514
|
+
)
|
|
1515
|
+
|
|
1516
|
+
|
|
1517
|
+
def _self_uninstall_inventory() -> list[str]:
|
|
1518
|
+
"""--dry-run 的全机残留清单:只读,不动任何文件。"""
|
|
1519
|
+
lines: list[str] = []
|
|
1520
|
+
zcode_entries = _self_zcode_bugx_dirs(_zcode_config_path())
|
|
1521
|
+
if zcode_entries:
|
|
1522
|
+
lines.append("将清理 ZCode plugins.dirs 登记:")
|
|
1523
|
+
lines.extend(f" - {entry}" for entry in zcode_entries)
|
|
1524
|
+
else:
|
|
1525
|
+
lines.append("ZCode plugins.dirs:无 BugX 登记")
|
|
1526
|
+
user_agents_dir = _zcode_user_agents_dir()
|
|
1527
|
+
user_agent_entries = [
|
|
1528
|
+
filename for filename in ("bugx.md", "bugx-worker.md")
|
|
1529
|
+
if (user_agents_dir / filename).is_file()
|
|
1530
|
+
]
|
|
1531
|
+
if user_agent_entries:
|
|
1532
|
+
lines.append(f"将清理 ZCode 用户级子智能体:{user_agents_dir}")
|
|
1533
|
+
lines.extend(f" - {filename}" for filename in user_agent_entries)
|
|
1534
|
+
else:
|
|
1535
|
+
lines.append("ZCode 用户级子智能体:无 BugX 登记")
|
|
1536
|
+
# 用户级智能体目录来自宿主自己的 ``user_agent_surfaces`` 钩子
|
|
1537
|
+
# (``commands/plugin_<host>.py``);通用层不写宿主名,也不猜目录名。
|
|
1538
|
+
for host_adapter in HOST_ADAPTERS:
|
|
1539
|
+
surfaces = engine_host_user_agent_surfaces(host_adapter.name)
|
|
1540
|
+
if not surfaces:
|
|
1541
|
+
continue
|
|
1542
|
+
primary = surfaces[0]
|
|
1543
|
+
agent_entries = [
|
|
1544
|
+
filename for filename in primary["entries"]
|
|
1545
|
+
if (primary["path"] / filename).is_file()
|
|
1546
|
+
]
|
|
1547
|
+
if agent_entries:
|
|
1548
|
+
lines.append(f"将清理 {primary['label']} 用户级智能体:{primary['path']}")
|
|
1549
|
+
lines.extend(f" - {filename}" for filename in agent_entries)
|
|
1550
|
+
else:
|
|
1551
|
+
lines.append(f"{primary['label']} 用户级智能体:无 BugX 登记")
|
|
1552
|
+
from .plugin_claude import _claude_user_agents_dir
|
|
1553
|
+
claude_agents_dir = _claude_user_agents_dir()
|
|
1554
|
+
claude_agent_entries = [
|
|
1555
|
+
filename for filename in ("bugx.md", "bugx-worker.md")
|
|
1556
|
+
if (claude_agents_dir / filename).is_file()
|
|
1557
|
+
]
|
|
1558
|
+
if claude_agent_entries:
|
|
1559
|
+
lines.append(f"将清理 Claude 用户级智能体:{claude_agents_dir}")
|
|
1560
|
+
lines.extend(f" - {filename}" for filename in claude_agent_entries)
|
|
1561
|
+
else:
|
|
1562
|
+
lines.append("Claude 用户级智能体:无 BugX 登记")
|
|
1563
|
+
from .plugin_qoder import _qoder_user_agents_dir
|
|
1564
|
+
qoder_agents_dir = _qoder_user_agents_dir()
|
|
1565
|
+
qoder_agent_entries = [
|
|
1566
|
+
filename for filename in ("bugx.md", "bugx-worker.md")
|
|
1567
|
+
if (qoder_agents_dir / filename).is_file()
|
|
1568
|
+
]
|
|
1569
|
+
if qoder_agent_entries:
|
|
1570
|
+
lines.append(f"将清理 Qoder 用户级智能体:{qoder_agents_dir}")
|
|
1571
|
+
lines.extend(f" - {filename}" for filename in qoder_agent_entries)
|
|
1572
|
+
else:
|
|
1573
|
+
lines.append("Qoder 用户级智能体:无 BugX 登记")
|
|
1574
|
+
from .plugin_funide import _funide_user_agents_dir
|
|
1575
|
+
funide_agent = _funide_user_agents_dir() / "bugx.agent.md"
|
|
1576
|
+
if funide_agent.is_file():
|
|
1577
|
+
lines.append(f"将清理 FunIDE 用户级智能体:{funide_agent}")
|
|
1578
|
+
else:
|
|
1579
|
+
lines.append("FunIDE 用户级智能体:无 BugX 登记")
|
|
1580
|
+
from .plugin_funide import _funide_data_dir
|
|
1581
|
+
funide_native = _funide_data_dir() / "agents.json"
|
|
1582
|
+
if funide_native.is_file():
|
|
1583
|
+
lines.append(f"将清理 FunIDE 原生智能体注册:{funide_native}")
|
|
1584
|
+
else:
|
|
1585
|
+
lines.append("FunIDE 原生智能体注册:无 BugX 登记")
|
|
1586
|
+
agents_dir = _self_home_dir(".config", "opencode", "agents")
|
|
1587
|
+
engine_root = global_engine_root()
|
|
1588
|
+
for filename in ("bugx.md", "bugx-worker.md"):
|
|
1589
|
+
entry = agents_dir / filename
|
|
1590
|
+
alt_name = "bugx-opencode.md" if filename == "bugx.md" else filename
|
|
1591
|
+
cand = engine_root / "contracts" / alt_name
|
|
1592
|
+
expected = cand if cand.is_file() else (engine_root / alt_name)
|
|
1593
|
+
if entry.is_symlink():
|
|
1594
|
+
target = entry.resolve(strict=False)
|
|
1595
|
+
if target in (expected.resolve(strict=False), (engine_root / filename).resolve(strict=False)):
|
|
1596
|
+
lines.append(f"将清理 ~/.config/opencode/agents/{filename}(指向全局引擎)")
|
|
1597
|
+
else:
|
|
1598
|
+
lines.append(f"保留 ~/.config/opencode/agents/{filename}(未指向全局引擎)")
|
|
1599
|
+
elif entry.exists():
|
|
1600
|
+
try:
|
|
1601
|
+
owned_copy = entry.is_file() and expected.is_file() \
|
|
1602
|
+
and _sha256_file(entry) == _sha256_file(expected)
|
|
1603
|
+
except OSError:
|
|
1604
|
+
owned_copy = False
|
|
1605
|
+
if owned_copy:
|
|
1606
|
+
lines.append(f"将清理 ~/.config/opencode/agents/{filename}(全局引擎副本入口)")
|
|
1607
|
+
else:
|
|
1608
|
+
lines.append(f"保留 ~/.config/opencode/agents/{filename}(非 BugX 副本或内容已变化)")
|
|
1609
|
+
pi_skill_dir = _self_home_dir(".pi", "skills", "bugx")
|
|
1610
|
+
agents_skill_dir = _self_home_dir(".agents", "skills", "bugx")
|
|
1611
|
+
for label, path in (("~/.pi/skills/bugx", pi_skill_dir),
|
|
1612
|
+
("~/.agents/skills/bugx", agents_skill_dir)):
|
|
1613
|
+
if path.is_symlink() or path.exists():
|
|
1614
|
+
lines.append(f"将清理 {label}")
|
|
1615
|
+
else:
|
|
1616
|
+
lines.append(f"{label}:不存在")
|
|
1617
|
+
dsh_preset = _self_home_dir(".dsh", ".agent-presets", "bugx")
|
|
1618
|
+
lines.append(
|
|
1619
|
+
f"将清理 ~/.dsh/.agent-presets/bugx(全局预设)"
|
|
1620
|
+
if dsh_preset.is_dir() and not dsh_preset.is_symlink()
|
|
1621
|
+
else "~/.dsh/.agent-presets/bugx:不存在"
|
|
1622
|
+
)
|
|
1623
|
+
dsh_ui = _dsh_home() / "plugins" / "bugx-ui"
|
|
1624
|
+
lines.append(
|
|
1625
|
+
f"将清理 {dsh_ui}(DSH web UI 插件)"
|
|
1626
|
+
if dsh_ui.is_dir() and not dsh_ui.is_symlink()
|
|
1627
|
+
else f"{dsh_ui}:不存在"
|
|
1628
|
+
)
|
|
1629
|
+
workbuddy_skills = [
|
|
1630
|
+
root / "skills" / "bugx" / "SKILL.md"
|
|
1631
|
+
for root in _workbuddy_config_roots()
|
|
1632
|
+
if (root / "skills" / "bugx" / "SKILL.md").is_file()
|
|
1633
|
+
]
|
|
1634
|
+
if workbuddy_skills:
|
|
1635
|
+
lines.append("将按模板比对清理 WorkBuddy 用户级 Skill:")
|
|
1636
|
+
lines.extend(f" - {path}" for path in workbuddy_skills)
|
|
1637
|
+
lines.append(" (内容与 BugX 模板不一致的一律保留)")
|
|
1638
|
+
else:
|
|
1639
|
+
lines.append("WorkBuddy 用户级 Skill:不存在")
|
|
1640
|
+
try:
|
|
1641
|
+
_codex_config, marketplaces, plugins = _self_codex_registrations()
|
|
1642
|
+
except CliError as exc:
|
|
1643
|
+
lines.append(f"~/.codex/config.toml(无法解析:{exc})")
|
|
1644
|
+
else:
|
|
1645
|
+
if marketplaces or plugins:
|
|
1646
|
+
lines.append(
|
|
1647
|
+
"将注销 codex 登记:" + ", ".join(plugins + marketplaces))
|
|
1648
|
+
else:
|
|
1649
|
+
lines.append("~/.codex/config.toml:无 BugX 本地 marketplace 登记")
|
|
1650
|
+
bugx_home = _self_home_dir(".bugx")
|
|
1651
|
+
if bugx_home.is_symlink():
|
|
1652
|
+
lines.append("~/.bugx 是符号链接:拒绝清理,请人工检查")
|
|
1653
|
+
elif bugx_home.is_dir():
|
|
1654
|
+
lines.append("将清理 ~/.bugx/(全局引擎、知识库、云数据;先整体外部备份)")
|
|
1655
|
+
else:
|
|
1656
|
+
lines.append("~/.bugx/:不存在")
|
|
1657
|
+
return lines
|
|
1658
|
+
|
|
1659
|
+
|
|
1660
|
+
def _self_uninstall_flow(args: argparse.Namespace, root: Path) -> int:
|
|
1661
|
+
"""卸载 BugX 全机自有工件:全局引擎、宿主全局登记与 ~/.bugx 数据。
|
|
1662
|
+
|
|
1663
|
+
项目级卸载(--all/--agent)只清理单个项目;本流程处理其余所有全局层
|
|
1664
|
+
残留。永远不触碰 pip 包本身(运行中的 CLI 不自删),只给出提示命令。
|
|
1665
|
+
"""
|
|
1666
|
+
if args.all or args.agent or args.purge_data or args.purge_global_data:
|
|
1667
|
+
raise CliError(_i18n_exc("lifecycle.self_mutually_exclusive", "--self 不能与 --all/--agent/--purge-data/--purge-global-data 同时使用"))
|
|
1668
|
+
if (root / ".bugx" / "manifest.json").exists() and not args.dry_run:
|
|
1669
|
+
raise CliError(_i18n_exc("lifecycle.self_project_still_attached", "当前项目仍接入 BugX(存在 .bugx/manifest.json);请先执行 bugx uninstall --root <项目> --all --yes --purge-data,再运行 --self"))
|
|
1670
|
+
if not args.yes and not args.dry_run:
|
|
1671
|
+
raise CliError(_i18n_exc("lifecycle.self_confirmation_required", "--self 会删除全局引擎与全局数据;确认请追加 --yes,或先用 --dry-run 查看清单"))
|
|
1672
|
+
|
|
1673
|
+
if args.dry_run:
|
|
1674
|
+
payload = {
|
|
1675
|
+
"status": "DRY_RUN",
|
|
1676
|
+
"self": True,
|
|
1677
|
+
"inventory": _self_uninstall_inventory(),
|
|
1678
|
+
}
|
|
1679
|
+
if getattr(args, "json", False):
|
|
1680
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
1681
|
+
else:
|
|
1682
|
+
print(f"BugX {__version__} · 全局自卸载预览(--dry-run,未修改任何文件)")
|
|
1683
|
+
for line in payload["inventory"]:
|
|
1684
|
+
print(f" {line}")
|
|
1685
|
+
return 0
|
|
1686
|
+
|
|
1687
|
+
removed: list[str] = []
|
|
1688
|
+
preserved: list[str] = []
|
|
1689
|
+
external_backup: Path | None = None
|
|
1690
|
+
no_backup = bool(getattr(args, "no_backup", False))
|
|
1691
|
+
bugx_home = _self_home_dir(".bugx")
|
|
1692
|
+
if bugx_home.is_symlink():
|
|
1693
|
+
raise CliError(_i18n_exc("lifecycle.clean_global_symlink_refused", "拒绝清理符号链接 ~/.bugx"))
|
|
1694
|
+
backup_root: Path | None = None
|
|
1695
|
+
if bugx_home.is_dir() and not no_backup:
|
|
1696
|
+
backup_root = _self_backup_root()
|
|
1697
|
+
try:
|
|
1698
|
+
backup_root.relative_to(bugx_home)
|
|
1699
|
+
except ValueError:
|
|
1700
|
+
pass
|
|
1701
|
+
else:
|
|
1702
|
+
raise CliError(_i18n_exc("lifecycle.self_backup_outside_global_required", "自卸载备份目录必须位于 ~/.bugx 之外"))
|
|
1703
|
+
_backup_global_home_for_self_uninstall(bugx_home, backup_root)
|
|
1704
|
+
external_backup = backup_root
|
|
1705
|
+
|
|
1706
|
+
_self_remove_zcode_registrations(backup_root, removed, preserved)
|
|
1707
|
+
_self_remove_zcode_user_agents(backup_root, removed, preserved)
|
|
1708
|
+
_self_remove_claude_user_agents(backup_root, removed, preserved)
|
|
1709
|
+
# 宿主专属的自卸载动作按约定模块名调用 ``self_remove_user_agents`` 钩子:
|
|
1710
|
+
# 通用层不再出现「某宿主的用户级智能体在哪、长什么样」。
|
|
1711
|
+
for host_adapter in HOST_ADAPTERS:
|
|
1712
|
+
self_remove = engine_host_cli_hook(host_adapter.name, "self_remove_user_agents")
|
|
1713
|
+
if self_remove is not None:
|
|
1714
|
+
self_remove(backup_root, removed, preserved)
|
|
1715
|
+
_self_remove_qoder_user_assets(backup_root, removed, preserved)
|
|
1716
|
+
_self_remove_funide_user_agent(backup_root, removed, preserved)
|
|
1717
|
+
_self_remove_funide_native_agent(backup_root, removed, preserved)
|
|
1718
|
+
_self_remove_funide_native_skill(backup_root, removed, preserved)
|
|
1719
|
+
_self_remove_funide_profile_mcp(backup_root, removed, preserved)
|
|
1720
|
+
_self_uninstall_opencode_links(external_backup, removed, preserved)
|
|
1721
|
+
_self_uninstall_pi_skill(backup_root, removed, preserved)
|
|
1722
|
+
_self_uninstall_dsh_preset(backup_root, removed, preserved)
|
|
1723
|
+
_self_uninstall_dsh_ui_plugin(backup_root, removed, preserved)
|
|
1724
|
+
_self_uninstall_workbuddy_skill(root, backup_root, removed, preserved)
|
|
1725
|
+
_self_uninstall_codex_plugins(backup_root, removed, preserved)
|
|
1726
|
+
if bugx_home.is_dir():
|
|
1727
|
+
# 引擎载荷可能是只读分发物(0o555/0o444):必须强制删除,否则自卸载
|
|
1728
|
+
# 会在 .bugx/core 上抛 PermissionError(实测)。
|
|
1729
|
+
_rmtree_force(bugx_home)
|
|
1730
|
+
removed.append(
|
|
1731
|
+
"~/.bugx/(全局引擎、知识库与云数据;已外部备份)"
|
|
1732
|
+
if external_backup else "~/.bugx/(全局引擎、知识库与云数据)"
|
|
1733
|
+
)
|
|
1734
|
+
|
|
1735
|
+
cli_source = os.environ.get("BUGX_CLI_SOURCE", "")
|
|
1736
|
+
if cli_source == "npm" or "bin/bugx.js" in sys.argv[0]:
|
|
1737
|
+
next_step = "如需移除 CLI 本体:npm uninstall -g bugx-cli"
|
|
1738
|
+
elif "uv/tools" in sys.executable or "uv/tools" in sys.argv[0] or ".local/share/uv" in sys.executable:
|
|
1739
|
+
next_step = "如需移除 CLI 本体:uv tool uninstall bugx-cli"
|
|
1740
|
+
else:
|
|
1741
|
+
next_step = "如需移除 CLI 本体:pip uninstall bugx-cli(若使用 npm,运行 npm uninstall -g bugx-cli)"
|
|
1742
|
+
|
|
1743
|
+
payload = {
|
|
1744
|
+
"status": "UNINSTALLED",
|
|
1745
|
+
"self": True,
|
|
1746
|
+
"removed": removed,
|
|
1747
|
+
"preserved": preserved,
|
|
1748
|
+
"backup": str(external_backup) if external_backup else None,
|
|
1749
|
+
"next_step": next_step,
|
|
1750
|
+
}
|
|
1751
|
+
if getattr(args, "json", False):
|
|
1752
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
1753
|
+
else:
|
|
1754
|
+
print(f"[bugx] 全局自卸载完成:移除 {len(removed)} 项,保留 {len(preserved)} 项")
|
|
1755
|
+
for item in removed:
|
|
1756
|
+
print(f" - {item}")
|
|
1757
|
+
for item in preserved:
|
|
1758
|
+
print(f" = {item}")
|
|
1759
|
+
if external_backup:
|
|
1760
|
+
print(f"[bugx] 备份:{external_backup}")
|
|
1761
|
+
print(f"[bugx] 下一步:{payload['next_step']}")
|
|
1762
|
+
return 0
|
|
1763
|
+
|
|
1764
|
+
|
|
1765
|
+
def _uninstall_guidance_flow(args: argparse.Namespace, root: Path) -> int:
|
|
1766
|
+
"""裸 uninstall 的引导路径:让用户在两级意图间二选一。
|
|
1767
|
+
|
|
1768
|
+
1) 仅卸载当前项目:删除项目下的 .bugx/ 与各 AI 工具入口,本项目回到
|
|
1769
|
+
未接入状态(删除前自动备份到项目外)。
|
|
1770
|
+
2) 全局卸载:移除 BugX 本体,所有 AI 工具都无法再使用 BugX
|
|
1771
|
+
(若当前项目仍接入,先执行 1 再移除全局层)。
|
|
1772
|
+
|
|
1773
|
+
TTY 走统一交互组件;非 TTY 输出两级选项与建议命令并返回 2。显式
|
|
1774
|
+
flag 路径(--agent/--all/--purge-*)不经过本函数,自动化行为不变。
|
|
1775
|
+
"""
|
|
1776
|
+
hosts_payload = _read_hosts_record(root / ".bugx" / "hosts.json")
|
|
1777
|
+
installed = hosts_payload.get("installed", [])
|
|
1778
|
+
host_names: list[str] = []
|
|
1779
|
+
for item in installed:
|
|
1780
|
+
if isinstance(item, dict) and isinstance(item.get("name"), str):
|
|
1781
|
+
name = str(item["name"])
|
|
1782
|
+
if name not in host_names:
|
|
1783
|
+
host_names.append(name)
|
|
1784
|
+
data_dir = root / ".bugx"
|
|
1785
|
+
has_project = bool(host_names) or (data_dir.exists() and not data_dir.is_symlink())
|
|
1786
|
+
|
|
1787
|
+
if not sys.stdin.isatty():
|
|
1788
|
+
payload = {
|
|
1789
|
+
"status": "NEEDS_SCOPE",
|
|
1790
|
+
"installed": host_names,
|
|
1791
|
+
"has_project_data": data_dir.exists(),
|
|
1792
|
+
"options": {
|
|
1793
|
+
"project": "仅卸载当前项目(删除本项目 .bugx/ 与各 AI 工具入口,"
|
|
1794
|
+
"先外部备份): bugx uninstall --root . --all --purge-data --yes",
|
|
1795
|
+
"global": "全局卸载(所有 AI 工具都不可用;先卸载当前项目): "
|
|
1796
|
+
"bugx uninstall --all --purge-data --yes && bugx uninstall --self --yes",
|
|
1797
|
+
},
|
|
1798
|
+
}
|
|
1799
|
+
if getattr(args, "json", False):
|
|
1800
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
1801
|
+
else:
|
|
1802
|
+
print("[bugx] 卸载分两级,请选择(当前项目"
|
|
1803
|
+
f"{'已接入 BugX' if has_project else '未接入 BugX'}):")
|
|
1804
|
+
print(" 1) 仅卸载当前项目:删除本项目下的 .bugx/ 与各 AI 工具入口,"
|
|
1805
|
+
"本项目回到未接入状态;其他项目不受影响(删除前自动备份到项目外)")
|
|
1806
|
+
print(" bugx uninstall --root . --all --purge-data --yes")
|
|
1807
|
+
print(" 2) 全局卸载:删除 BugX 本体(全局引擎与所有 AI 工具的登记),"
|
|
1808
|
+
"所有 AI 工具都无法再使用 BugX")
|
|
1809
|
+
print(" bugx uninstall --all --purge-data --yes && bugx uninstall --self --yes")
|
|
1810
|
+
return 2
|
|
1811
|
+
|
|
1812
|
+
_ensure_core_importable()
|
|
1813
|
+
from core.runtime import interaction
|
|
1814
|
+
from core.runtime import startup_environment
|
|
1815
|
+
|
|
1816
|
+
options = []
|
|
1817
|
+
if has_project:
|
|
1818
|
+
options.append(interaction.InteractionOption(
|
|
1819
|
+
"project", "仅卸载当前项目",
|
|
1820
|
+
"删除本项目下的 .bugx/ 与各 AI 工具入口,本项目回到未接入状态;"
|
|
1821
|
+
"其他项目不受影响(删除前自动备份到项目外)"))
|
|
1822
|
+
options.append(interaction.InteractionOption(
|
|
1823
|
+
"global", "全局卸载(所有 AI 工具都不可用)",
|
|
1824
|
+
"删除 BugX 本体:全局引擎、全局数据与所有 AI 工具的登记"
|
|
1825
|
+
+ (";会先卸载当前项目" if has_project else "")))
|
|
1826
|
+
options.append(interaction.InteractionOption(
|
|
1827
|
+
"cancel", "取消", "不修改任何文件"))
|
|
1828
|
+
question = interaction.InteractionQuestion(
|
|
1829
|
+
question_id="uninstall_scope",
|
|
1830
|
+
phase="uninstall",
|
|
1831
|
+
kind="select",
|
|
1832
|
+
title="选择卸载范围",
|
|
1833
|
+
question=(
|
|
1834
|
+
"仅卸载当前项目 = 本项目回到未接入状态,其他项目不受影响;"
|
|
1835
|
+
"全局卸载 = 所有 AI 工具都无法再使用 BugX。请选择"
|
|
1836
|
+
),
|
|
1837
|
+
options=tuple(options),
|
|
1838
|
+
multiple=False,
|
|
1839
|
+
default=len(options) - 1,
|
|
1840
|
+
)
|
|
1841
|
+
environment = startup_environment.detect(root)
|
|
1842
|
+
result = interaction.ask(question, environment)
|
|
1843
|
+
if result.status != interaction.ANSWERED or result.value == "cancel":
|
|
1844
|
+
print("[bugx] 已取消卸载,未修改任何文件")
|
|
1845
|
+
return 0
|
|
1846
|
+
if result.value not in {"project", "global"}:
|
|
1847
|
+
raise CliError(_i18n_exc("lifecycle.unknown_uninstall_scope", f"未知卸载范围选项: {result.value}", value=result.value))
|
|
1848
|
+
|
|
1849
|
+
if result.value == "global" and has_project:
|
|
1850
|
+
# 全局卸载前先把当前项目摘干净,避免留下悬空的项目运行态。
|
|
1851
|
+
args.all = True
|
|
1852
|
+
args.agent = []
|
|
1853
|
+
args.purge_data = True
|
|
1854
|
+
args.purge_global_data = False
|
|
1855
|
+
args.yes = True
|
|
1856
|
+
args.json = False
|
|
1857
|
+
code = command_uninstall(args)
|
|
1858
|
+
if code != 0:
|
|
1859
|
+
return code
|
|
1860
|
+
|
|
1861
|
+
if result.value == "global":
|
|
1862
|
+
# 注意:不能以 Namespace(**vars(args)) 重建——"self" 键与构造器形参
|
|
1863
|
+
# 冲突;直接原地改写后交给全局自卸载流程。
|
|
1864
|
+
args.self = True
|
|
1865
|
+
args.all = False
|
|
1866
|
+
args.agent = []
|
|
1867
|
+
args.purge_data = False
|
|
1868
|
+
args.purge_global_data = False
|
|
1869
|
+
args.dry_run = False
|
|
1870
|
+
args.yes = True
|
|
1871
|
+
args.json = False
|
|
1872
|
+
return _self_uninstall_flow(args, root)
|
|
1873
|
+
|
|
1874
|
+
args.all = True
|
|
1875
|
+
args.agent = []
|
|
1876
|
+
args.purge_data = True
|
|
1877
|
+
args.purge_global_data = False
|
|
1878
|
+
args.yes = True
|
|
1879
|
+
return command_uninstall(args)
|
|
1880
|
+
|
|
1881
|
+
|
|
1882
|
+
def _uninstall_dry_run_preview(
|
|
1883
|
+
root: Path,
|
|
1884
|
+
installed: list[object],
|
|
1885
|
+
selected_names: list[str],
|
|
1886
|
+
hosts_path: Path,
|
|
1887
|
+
*,
|
|
1888
|
+
purge_data: bool,
|
|
1889
|
+
purge_global_data: bool,
|
|
1890
|
+
force: bool = False,
|
|
1891
|
+
) -> tuple[list[str], list[str]]:
|
|
1892
|
+
"""Build an uninstall preview without invoking any mutating helper.
|
|
1893
|
+
|
|
1894
|
+
The normal uninstall path has several side effects besides the final
|
|
1895
|
+
deletion: per-file backups, host-record updates, structured logging, and
|
|
1896
|
+
host-specific configuration cleanup. A dry-run must not call those
|
|
1897
|
+
helpers even when ``--yes`` is present, so this function only inspects
|
|
1898
|
+
ownership records and current filesystem state.
|
|
1899
|
+
"""
|
|
1900
|
+
planned: list[str] = []
|
|
1901
|
+
preserved: list[str] = []
|
|
1902
|
+
recorded_names = {
|
|
1903
|
+
str(item.get("name")) for item in installed if isinstance(item, dict)
|
|
1904
|
+
}
|
|
1905
|
+
seen: set[str] = set()
|
|
1906
|
+
|
|
1907
|
+
def add_planned(label: str) -> None:
|
|
1908
|
+
if label not in seen:
|
|
1909
|
+
seen.add(label)
|
|
1910
|
+
planned.append(label)
|
|
1911
|
+
|
|
1912
|
+
for item in installed:
|
|
1913
|
+
if not isinstance(item, dict) or item.get("name") not in selected_names:
|
|
1914
|
+
continue
|
|
1915
|
+
name = str(item["name"])
|
|
1916
|
+
records = item.get("files")
|
|
1917
|
+
if not isinstance(records, list):
|
|
1918
|
+
records = []
|
|
1919
|
+
for record in records:
|
|
1920
|
+
if not isinstance(record, dict):
|
|
1921
|
+
continue
|
|
1922
|
+
relative = record.get("path")
|
|
1923
|
+
expected = record.get("sha256")
|
|
1924
|
+
if not isinstance(relative, str) or not isinstance(expected, str):
|
|
1925
|
+
preserved.append(f"{relative or '<unknown>'}(清单缺少哈希)")
|
|
1926
|
+
continue
|
|
1927
|
+
target = _safe_record_target(root, relative)
|
|
1928
|
+
if target.is_symlink():
|
|
1929
|
+
preserved.append(f"{relative}(符号链接)")
|
|
1930
|
+
continue
|
|
1931
|
+
if not target.exists():
|
|
1932
|
+
continue
|
|
1933
|
+
if not target.is_file():
|
|
1934
|
+
preserved.append(f"{relative}(不是普通文件)")
|
|
1935
|
+
continue
|
|
1936
|
+
try:
|
|
1937
|
+
current_hash = _sha256_file(target)
|
|
1938
|
+
except OSError as exc:
|
|
1939
|
+
preserved.append(f"{relative}(无法读取:{exc})")
|
|
1940
|
+
continue
|
|
1941
|
+
if current_hash != expected:
|
|
1942
|
+
if not force:
|
|
1943
|
+
preserved.append(f"{relative}(内容已被用户修改)")
|
|
1944
|
+
continue
|
|
1945
|
+
else:
|
|
1946
|
+
add_planned(f"{relative}(内容已修改,将强制清理并备份)")
|
|
1947
|
+
continue
|
|
1948
|
+
add_planned(relative)
|
|
1949
|
+
|
|
1950
|
+
# These entries are intentionally not represented as ordinary hashed
|
|
1951
|
+
# files: OpenCode uses project symlinks/config merging, and ChatGPT
|
|
1952
|
+
# uses a shared marketplace entry. List the affected surfaces without
|
|
1953
|
+
# calling their mutating uninstall implementations.
|
|
1954
|
+
if name == "opencode":
|
|
1955
|
+
for relative in (
|
|
1956
|
+
".opencode/agents/bugx.md",
|
|
1957
|
+
".opencode/agents/bugx-worker.md",
|
|
1958
|
+
CONFIG_NAME,
|
|
1959
|
+
):
|
|
1960
|
+
if (root / relative).exists() or (root / relative).is_symlink():
|
|
1961
|
+
add_planned(relative + "(按 BugX 归属检查)")
|
|
1962
|
+
elif name == "chatgpt":
|
|
1963
|
+
marketplace = root / ".agents" / "plugins" / "marketplace.json"
|
|
1964
|
+
if marketplace.exists() or marketplace.is_symlink():
|
|
1965
|
+
add_planned(str(marketplace.relative_to(root)) + "(移除 BugX 条目)")
|
|
1966
|
+
elif name == "dsh":
|
|
1967
|
+
for relative in (
|
|
1968
|
+
".dsh/patch.yml",
|
|
1969
|
+
".dsh/skills/bugx/SKILL.md",
|
|
1970
|
+
".dsh/agents/bugx.md",
|
|
1971
|
+
):
|
|
1972
|
+
if (root / relative).exists() or (root / relative).is_symlink():
|
|
1973
|
+
add_planned(relative + "(按 BugX 归属检查)")
|
|
1974
|
+
|
|
1975
|
+
for mcp_host in _mcp_config_host_names(name):
|
|
1976
|
+
target_info = _host_project_mcp_config_target(root, mcp_host)
|
|
1977
|
+
if not target_info:
|
|
1978
|
+
continue
|
|
1979
|
+
target_path, _ = target_info
|
|
1980
|
+
if target_path.is_file() and not target_path.is_symlink():
|
|
1981
|
+
try:
|
|
1982
|
+
rel = str(target_path.relative_to(root))
|
|
1983
|
+
except ValueError:
|
|
1984
|
+
rel = str(target_path)
|
|
1985
|
+
add_planned(f"{rel}(检查并清理 BugX MCP 注册)")
|
|
1986
|
+
|
|
1987
|
+
for name in selected_names:
|
|
1988
|
+
if name not in recorded_names:
|
|
1989
|
+
preserved.append(f"{name}(当前项目没有本版本安装记录,未删除未知文件)")
|
|
1990
|
+
|
|
1991
|
+
if purge_data:
|
|
1992
|
+
bugx_root = root / ".bugx"
|
|
1993
|
+
if bugx_root.exists() or bugx_root.is_symlink():
|
|
1994
|
+
add_planned(".bugx/(项目运行态、报告、证据与共享资源)")
|
|
1995
|
+
global_root = (Path.home() / ".bugx" / "knowledge").resolve()
|
|
1996
|
+
if purge_global_data and global_root.exists():
|
|
1997
|
+
add_planned("~/.bugx/knowledge/(全局错题集与经验集)")
|
|
1998
|
+
add_planned("项目级宿主登记与 BugX 配置(随 .bugx/ 一并清理)")
|
|
1999
|
+
elif hosts_path.exists():
|
|
2000
|
+
add_planned(".bugx/hosts.json(更新宿主登记)")
|
|
2001
|
+
|
|
2002
|
+
return planned, preserved
|
|
2003
|
+
|
|
2004
|
+
|
|
2005
|
+
def _mcp_config_host_names(name: str) -> tuple[str, ...]:
|
|
2006
|
+
"""宿主的项目级 MCP 登记路径名(含多路径宿主的兼容副本)。
|
|
2007
|
+
|
|
2008
|
+
安装侧(agent.py)对 ``entry_mode == ENTRY_MULTI_PATH`` 的宿主会把同一份 MCP
|
|
2009
|
+
登记**同时**写进 `.workbuddy/mcp.json` 与兼容的 `.codebuddy/mcp.json`。
|
|
2010
|
+
卸载必须成对清理,否则兼容副本里的 bugx-supervisor / worker / docs 会残留,
|
|
2011
|
+
宿主仍会去拉起已卸载项目的 BugX MCP。
|
|
2012
|
+
"""
|
|
2013
|
+
for adapter in HOST_ADAPTERS:
|
|
2014
|
+
if adapter.name == name:
|
|
2015
|
+
if getattr(adapter, "entry_mode", None) == ENTRY_MULTI_PATH:
|
|
2016
|
+
return (name, "codebuddy")
|
|
2017
|
+
return (name,)
|
|
2018
|
+
return (name,)
|
|
2019
|
+
|
|
2020
|
+
|
|
2021
|
+
def _remove_host_mcp_entries_for(
|
|
2022
|
+
root: Path,
|
|
2023
|
+
name: str,
|
|
2024
|
+
removed: list[str],
|
|
2025
|
+
preserved: list[str],
|
|
2026
|
+
*,
|
|
2027
|
+
backup_dir: Path | None = None,
|
|
2028
|
+
) -> None:
|
|
2029
|
+
"""清理宿主项目级 MCP 登记,含多路径宿主的 `.codebuddy` 兼容副本。"""
|
|
2030
|
+
# Claude Code and FunIDE intentionally share the project-root `.mcp.json`
|
|
2031
|
+
# shape. Removing FunIDE must not tear down a Claude installation that is
|
|
2032
|
+
# still present in the same project; both hosts consume the same BugX
|
|
2033
|
+
# servers. A FunIDE-only project has no `.claude` marker and is cleaned as
|
|
2034
|
+
# usual.
|
|
2035
|
+
if name == "funide" and (root / ".claude").exists():
|
|
2036
|
+
preserved.append(
|
|
2037
|
+
".mcp.json(与 Claude Code 共用,卸载 FunIDE 时保留 BugX MCP)"
|
|
2038
|
+
)
|
|
2039
|
+
else:
|
|
2040
|
+
_remove_host_mcp_entry(root, name, removed, preserved, backup_dir=backup_dir)
|
|
2041
|
+
for mcp_host in _mcp_config_host_names(name):
|
|
2042
|
+
if mcp_host == name:
|
|
2043
|
+
continue
|
|
2044
|
+
_remove_host_mcp_entry(
|
|
2045
|
+
root, mcp_host, removed, preserved,
|
|
2046
|
+
backup_host=name, backup_dir=backup_dir,
|
|
2047
|
+
)
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
def command_uninstall(args: argparse.Namespace) -> int:
|
|
2051
|
+
"""Safely remove BugX host entries while preserving user-owned assets."""
|
|
2052
|
+
root = args.root.resolve()
|
|
2053
|
+
if getattr(args, "self", False):
|
|
2054
|
+
return _self_uninstall_flow(args, root)
|
|
2055
|
+
if (root / ".bugx").is_symlink():
|
|
2056
|
+
raise CliError(_i18n_exc("lifecycle.operate_project_symlink_refused", "拒绝操作符号链接 .bugx"))
|
|
2057
|
+
if args.all and args.agent:
|
|
2058
|
+
raise CliError(_i18n_exc("lifecycle.all_and_agent_exclusive", "--all 不能与 --agent 同时使用"))
|
|
2059
|
+
if not args.all and not args.agent:
|
|
2060
|
+
return _uninstall_guidance_flow(args, root)
|
|
2061
|
+
if args.purge_data and not args.all:
|
|
2062
|
+
raise CliError(_i18n_exc("lifecycle.purge_data_all_only", "--purge-data 只能与 --all 一起使用"))
|
|
2063
|
+
if args.purge_global_data and not args.purge_data:
|
|
2064
|
+
raise CliError(_i18n_exc("lifecycle.purge_global_requires_purge_data", "--purge-global-data 必须与 --purge-data 一起使用"))
|
|
2065
|
+
if (args.purge_data or args.purge_global_data) and not args.yes and not args.dry_run:
|
|
2066
|
+
raise CliError(_i18n_exc("lifecycle.purge_data_yes_required", "清理数据需要显式提供 --yes;执行前会创建外部备份"))
|
|
2067
|
+
|
|
2068
|
+
force = bool(getattr(args, "force", False))
|
|
2069
|
+
hosts_path = root / ".bugx" / "hosts.json"
|
|
2070
|
+
hosts_payload = _read_hosts_record(hosts_path)
|
|
2071
|
+
installed = hosts_payload.get("installed", [])
|
|
2072
|
+
if not isinstance(installed, list):
|
|
2073
|
+
raise CliError(_i18n_exc("lifecycle.hosts_installed_not_array", "宿主清单 installed 必须是数组"))
|
|
2074
|
+
known: dict[str, HostAdapter] = {adapter.name: adapter for adapter in HOST_ADAPTERS}
|
|
2075
|
+
for adapter in HOST_ADAPTERS:
|
|
2076
|
+
for alias in adapter.aliases:
|
|
2077
|
+
known[alias] = adapter
|
|
2078
|
+
raw_names = (
|
|
2079
|
+
[str(item.get("name")) for item in installed if isinstance(item, dict)]
|
|
2080
|
+
if args.all else list(dict.fromkeys(args.agent))
|
|
2081
|
+
)
|
|
2082
|
+
for name in raw_names:
|
|
2083
|
+
if name not in known:
|
|
2084
|
+
choices = ", ".join(adapter.name for adapter in HOST_ADAPTERS)
|
|
2085
|
+
raise CliError(_i18n_exc("lifecycle.unknown_ai_agent", f"未知 AI Agent: {name};可选:{choices}", name=name, known=choices))
|
|
2086
|
+
selected_names = list(dict.fromkeys(known[name].name for name in raw_names))
|
|
2087
|
+
|
|
2088
|
+
if args.dry_run:
|
|
2089
|
+
planned, preserved = _uninstall_dry_run_preview(
|
|
2090
|
+
root,
|
|
2091
|
+
installed,
|
|
2092
|
+
selected_names,
|
|
2093
|
+
hosts_path,
|
|
2094
|
+
purge_data=bool(args.purge_data),
|
|
2095
|
+
purge_global_data=bool(args.purge_global_data),
|
|
2096
|
+
force=force,
|
|
2097
|
+
)
|
|
2098
|
+
payload = {
|
|
2099
|
+
"status": "DRY_RUN",
|
|
2100
|
+
"root": str(root),
|
|
2101
|
+
"hosts": selected_names,
|
|
2102
|
+
"removed": planned,
|
|
2103
|
+
"preserved": preserved,
|
|
2104
|
+
"purged_project_data": bool(args.purge_data),
|
|
2105
|
+
"purged_global_data": bool(args.purge_global_data),
|
|
2106
|
+
"backup": None,
|
|
2107
|
+
"backup_planned": bool(args.purge_data) and not getattr(args, "no_backup", False),
|
|
2108
|
+
"dry_run": True,
|
|
2109
|
+
}
|
|
2110
|
+
if getattr(args, "json", False):
|
|
2111
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
2112
|
+
else:
|
|
2113
|
+
print("[bugx] 卸载预览(--dry-run,未修改任何文件)")
|
|
2114
|
+
for item in planned:
|
|
2115
|
+
print(f" - {item}")
|
|
2116
|
+
for item in preserved:
|
|
2117
|
+
print(f" = {item}")
|
|
2118
|
+
if args.purge_data:
|
|
2119
|
+
if not getattr(args, "no_backup", False):
|
|
2120
|
+
print(" 备份:正式执行时会创建项目外部备份;本次未创建")
|
|
2121
|
+
else:
|
|
2122
|
+
print(" 备份:跳过备份(--no-backup)")
|
|
2123
|
+
return 0
|
|
2124
|
+
|
|
2125
|
+
external_backup: Path | None = None
|
|
2126
|
+
uninstall_backup_dir: Path | None = None
|
|
2127
|
+
# Global knowledge is a user-owned singleton. Never let an environment
|
|
2128
|
+
# variable turn ``uninstall --purge-global-data`` into an arbitrary-path
|
|
2129
|
+
# deletion primitive; test/development overrides are intentionally ignored
|
|
2130
|
+
# by destructive cleanup.
|
|
2131
|
+
bugx_home_lexical = Path.home() / ".bugx"
|
|
2132
|
+
global_root = bugx_home_lexical / "knowledge"
|
|
2133
|
+
try:
|
|
2134
|
+
global_root.relative_to(bugx_home_lexical)
|
|
2135
|
+
except ValueError as exc: # pragma: no cover - fixed child path invariant
|
|
2136
|
+
raise CliError("全局知识卸载目标必须位于 ~/.bugx 内") from exc
|
|
2137
|
+
if args.purge_global_data:
|
|
2138
|
+
_assert_no_symlink_components(global_root)
|
|
2139
|
+
no_backup = bool(getattr(args, "no_backup", False))
|
|
2140
|
+
if args.purge_data and not no_backup:
|
|
2141
|
+
backup_root = _external_uninstall_backup_root(root)
|
|
2142
|
+
try:
|
|
2143
|
+
backup_root.relative_to(root)
|
|
2144
|
+
except ValueError:
|
|
2145
|
+
pass
|
|
2146
|
+
else:
|
|
2147
|
+
raise CliError(_i18n_exc("lifecycle.uninstall_backup_outside_root", "卸载备份目录必须位于项目根目录之外"))
|
|
2148
|
+
if (root / ".bugx").exists():
|
|
2149
|
+
_backup_tree_external(root / ".bugx", backup_root / "project-bugx")
|
|
2150
|
+
if args.purge_global_data and global_root.exists():
|
|
2151
|
+
_backup_tree_external(global_root, backup_root / "global-knowledge")
|
|
2152
|
+
external_backup = backup_root
|
|
2153
|
+
# P2-1:宿主文件逐个备份直接重定向到项目外部归档;purge 删除
|
|
2154
|
+
# .bugx(连同其中的 .bugx/backups)后这些备份仍然可恢复。
|
|
2155
|
+
uninstall_backup_dir = backup_root / "project-uninstall-backups"
|
|
2156
|
+
|
|
2157
|
+
removed: list[str] = []
|
|
2158
|
+
preserved: list[str] = []
|
|
2159
|
+
remaining: list[object] = []
|
|
2160
|
+
for item in installed:
|
|
2161
|
+
if not isinstance(item, dict) or item.get("name") not in selected_names:
|
|
2162
|
+
remaining.append(item)
|
|
2163
|
+
continue
|
|
2164
|
+
name = str(item["name"])
|
|
2165
|
+
records = item.get("files")
|
|
2166
|
+
if not isinstance(records, list) or not records:
|
|
2167
|
+
# OpenCode 入口按设计是符号链接,files 清单恒为空;只要记录还带
|
|
2168
|
+
# entry_symlink 字段,下方专分支就会清理入口与全局注册,无需误报。
|
|
2169
|
+
has_opencode_entry = name == "opencode" and isinstance(
|
|
2170
|
+
item.get("entry_symlink"), str
|
|
2171
|
+
)
|
|
2172
|
+
if not has_opencode_entry:
|
|
2173
|
+
preserved.append(f"{name}(缺少本版本安装清单,未删除宿主文件)")
|
|
2174
|
+
records = []
|
|
2175
|
+
if name == "chatgpt":
|
|
2176
|
+
# Marketplace is a shared user catalog. It is edited structurally
|
|
2177
|
+
# below so unrelated plugins are retained; never delete the whole
|
|
2178
|
+
# JSON file through the ordinary hash-owned-file path.
|
|
2179
|
+
records = [
|
|
2180
|
+
record for record in records
|
|
2181
|
+
if not isinstance(record, dict)
|
|
2182
|
+
or record.get("path") != ".agents/plugins/marketplace.json"
|
|
2183
|
+
]
|
|
2184
|
+
for record in records:
|
|
2185
|
+
_remove_owned_record(root, record, name, removed, preserved, uninstall_backup_dir, force=force)
|
|
2186
|
+
_remove_host_mcp_entries_for(root, name, removed, preserved, backup_dir=uninstall_backup_dir)
|
|
2187
|
+
if name == "chatgpt":
|
|
2188
|
+
_remove_chatgpt_marketplace_entry(root, removed, preserved, backup_dir=uninstall_backup_dir)
|
|
2189
|
+
_deregister_codex_plugin(root, removed, preserved)
|
|
2190
|
+
if name == "dsh":
|
|
2191
|
+
_remove_dsh_user_preset(root, removed, preserved, purge_global=args.purge_global_data, backup_dir=uninstall_backup_dir)
|
|
2192
|
+
_remove_dsh_project_files(root, removed, preserved, records, backup_dir=uninstall_backup_dir, force=force)
|
|
2193
|
+
if name == "opencode":
|
|
2194
|
+
pass
|
|
2195
|
+
if name == "claude":
|
|
2196
|
+
from .plugin_claude import (
|
|
2197
|
+
_claude_user_agents_dir,
|
|
2198
|
+
_remove_claude_project_skills_and_dist,
|
|
2199
|
+
)
|
|
2200
|
+
_remove_claude_project_skills_and_dist(root, removed, preserved, backup_dir=uninstall_backup_dir)
|
|
2201
|
+
user_agents_dir = _claude_user_agents_dir()
|
|
2202
|
+
kept_agents = [
|
|
2203
|
+
filename for filename in ("bugx.md", "bugx-worker.md")
|
|
2204
|
+
if (user_agents_dir / filename).is_file()
|
|
2205
|
+
]
|
|
2206
|
+
if kept_agents:
|
|
2207
|
+
preserved.append(
|
|
2208
|
+
f"{user_agents_dir}/{'、'.join(kept_agents)}"
|
|
2209
|
+
"(Claude Code 用户级智能体保留,供其他项目使用;全局清理需 uninstall --self)"
|
|
2210
|
+
)
|
|
2211
|
+
for surface in engine_host_user_agent_surfaces(name):
|
|
2212
|
+
kept_agents = [
|
|
2213
|
+
filename for filename in surface["entries"]
|
|
2214
|
+
if (surface["path"] / filename).is_file()
|
|
2215
|
+
]
|
|
2216
|
+
if kept_agents:
|
|
2217
|
+
preserved.append(
|
|
2218
|
+
f"{surface['path']}/{'、'.join(kept_agents)}"
|
|
2219
|
+
f"({surface['label']} 用户级智能体保留,供其他项目使用;"
|
|
2220
|
+
"全局清理需 uninstall --self)"
|
|
2221
|
+
)
|
|
2222
|
+
if name == "pi":
|
|
2223
|
+
_unlink_global_pi_skill(root, removed, preserved)
|
|
2224
|
+
if name == "zcode":
|
|
2225
|
+
# 用户级子智能体跨项目共享;MCP 配置只保留在各自项目中;
|
|
2226
|
+
# 项目级卸载不删,只如实报告,全局清理走 uninstall --self。
|
|
2227
|
+
user_agents_dir = _zcode_user_agents_dir()
|
|
2228
|
+
kept_agents = [
|
|
2229
|
+
filename for filename in ("bugx.md", "bugx-worker.md")
|
|
2230
|
+
if (user_agents_dir / filename).is_file()
|
|
2231
|
+
]
|
|
2232
|
+
if kept_agents:
|
|
2233
|
+
preserved.append(
|
|
2234
|
+
f"{user_agents_dir}/{'、'.join(kept_agents)}"
|
|
2235
|
+
"(用户级子智能体保留,供其他项目使用;全局清理需 uninstall --self)"
|
|
2236
|
+
)
|
|
2237
|
+
if name == "workbuddy":
|
|
2238
|
+
# 用户级 Skill 与 zcode 用户级 agents 同层:跨项目共享,
|
|
2239
|
+
# 项目级卸载只报告保留,全局清理统一走 uninstall --self。
|
|
2240
|
+
user_skill = workbuddy_user_skill_root() / "skills" / "bugx" / "SKILL.md"
|
|
2241
|
+
if user_skill.is_file():
|
|
2242
|
+
preserved.append(
|
|
2243
|
+
f"{user_skill}"
|
|
2244
|
+
"(WorkBuddy 用户级 Skill 保留,供其他项目使用;全局清理需 uninstall --self)"
|
|
2245
|
+
)
|
|
2246
|
+
if name == "qoder":
|
|
2247
|
+
from .plugin_qoder import _qoder_user_agents_dir
|
|
2248
|
+
user_agents_dir = _qoder_user_agents_dir()
|
|
2249
|
+
kept_agents = [
|
|
2250
|
+
filename for filename in ("bugx.md", "bugx-worker.md")
|
|
2251
|
+
if (user_agents_dir / filename).is_file()
|
|
2252
|
+
]
|
|
2253
|
+
if kept_agents:
|
|
2254
|
+
preserved.append(
|
|
2255
|
+
f"{user_agents_dir}/{'、'.join(kept_agents)}"
|
|
2256
|
+
"(Qoder 用户级智能体保留,供其他项目使用;全局清理需 uninstall --self)"
|
|
2257
|
+
)
|
|
2258
|
+
if name == "funide":
|
|
2259
|
+
from .plugin_funide import (
|
|
2260
|
+
_funide_data_dir,
|
|
2261
|
+
_funide_profile_mcp_path,
|
|
2262
|
+
_funide_user_agents_dir,
|
|
2263
|
+
_funide_user_skills_dir,
|
|
2264
|
+
)
|
|
2265
|
+
user_agent = _funide_user_agents_dir() / "bugx.agent.md"
|
|
2266
|
+
if user_agent.is_file():
|
|
2267
|
+
preserved.append(
|
|
2268
|
+
f"{user_agent}"
|
|
2269
|
+
"(FunIDE 用户级智能体保留,供其他项目使用;全局清理需 uninstall --self)"
|
|
2270
|
+
)
|
|
2271
|
+
native_agent = _funide_data_dir() / "agents.json"
|
|
2272
|
+
if native_agent.is_file():
|
|
2273
|
+
preserved.append(
|
|
2274
|
+
f"{native_agent}"
|
|
2275
|
+
"(FunIDE 设置页原生智能体注册保留;全局清理需 uninstall --self)"
|
|
2276
|
+
)
|
|
2277
|
+
native_skill = _funide_user_skills_dir() / "bugx" / "SKILL.md"
|
|
2278
|
+
if native_skill.is_file():
|
|
2279
|
+
preserved.append(
|
|
2280
|
+
f"{native_skill}"
|
|
2281
|
+
"(FunIDE 设置页原生技能保留;全局清理需 uninstall --self)"
|
|
2282
|
+
)
|
|
2283
|
+
native_mcp = _funide_profile_mcp_path()
|
|
2284
|
+
if native_mcp.is_file():
|
|
2285
|
+
preserved.append(
|
|
2286
|
+
f"{native_mcp}"
|
|
2287
|
+
"(FunIDE 设置页用户级 MCP 保留;全局清理需 uninstall --self)"
|
|
2288
|
+
)
|
|
2289
|
+
|
|
2290
|
+
# A requested host not present in hosts.json has no ownership proof. The
|
|
2291
|
+
# clean-break release never guesses ownership or removes old-layout files.
|
|
2292
|
+
recorded_names = {
|
|
2293
|
+
str(item.get("name")) for item in installed if isinstance(item, dict)
|
|
2294
|
+
}
|
|
2295
|
+
for name in selected_names:
|
|
2296
|
+
if name in recorded_names:
|
|
2297
|
+
continue
|
|
2298
|
+
_remove_host_mcp_entries_for(root, name, removed, preserved, backup_dir=uninstall_backup_dir)
|
|
2299
|
+
if name == "chatgpt":
|
|
2300
|
+
_remove_chatgpt_marketplace_entry(root, removed, preserved, backup_dir=uninstall_backup_dir)
|
|
2301
|
+
_deregister_codex_plugin(root, removed, preserved)
|
|
2302
|
+
elif name == "dsh":
|
|
2303
|
+
# No hosts.json record means there is no ownership proof. In
|
|
2304
|
+
# particular, an empty record list triggers the legacy cleanup
|
|
2305
|
+
# fallback in _remove_dsh_project_files, so preserve all DSH files.
|
|
2306
|
+
_remove_dsh_project_files(root, removed, preserved, [], backup_dir=uninstall_backup_dir, force=force)
|
|
2307
|
+
elif name == "opencode":
|
|
2308
|
+
pass
|
|
2309
|
+
elif name == "pi":
|
|
2310
|
+
_unlink_global_pi_skill(root, removed, preserved)
|
|
2311
|
+
else:
|
|
2312
|
+
adapter = known.get(name)
|
|
2313
|
+
if (adapter is not None and adapter.name in _SWEEPABLE_SKILL_ADAPTERS
|
|
2314
|
+
and (global_engine_root() / "bugx.md").is_file()):
|
|
2315
|
+
_sweep_unrecorded_host_entry(root, adapter, removed, preserved, uninstall_backup_dir, force=force)
|
|
2316
|
+
else:
|
|
2317
|
+
preserved.append(f"{name}(当前项目没有本版本安装记录,未删除宿主文件)")
|
|
2318
|
+
|
|
2319
|
+
if args.all:
|
|
2320
|
+
# "像新项目一样":对没有任何安装记录的宿主入口与项目级 MCP 做清扫。
|
|
2321
|
+
recorded = {
|
|
2322
|
+
str(item.get("name")) for item in installed if isinstance(item, dict)
|
|
2323
|
+
}
|
|
2324
|
+
for adapter in HOST_ADAPTERS:
|
|
2325
|
+
if adapter.name not in recorded:
|
|
2326
|
+
_remove_host_mcp_entries_for(root, adapter.name, removed, preserved, backup_dir=uninstall_backup_dir)
|
|
2327
|
+
if (global_engine_root() / "bugx.md").is_file():
|
|
2328
|
+
_sweep_unrecorded_host_entry(root, adapter, removed, preserved, uninstall_backup_dir, force=force)
|
|
2329
|
+
|
|
2330
|
+
if not args.purge_data and hosts_path.exists():
|
|
2331
|
+
_write_private_json(hosts_path, {
|
|
2332
|
+
**{key: value for key, value in hosts_payload.items() if key != "installed"},
|
|
2333
|
+
"installed": remaining,
|
|
2334
|
+
})
|
|
2335
|
+
else:
|
|
2336
|
+
# Layout 2 has no project copy of the executable engine. Never
|
|
2337
|
+
# reconstruct a legacy ``.bugx/core`` inventory during uninstall.
|
|
2338
|
+
shared_records = hosts_payload.get("shared_files", [])
|
|
2339
|
+
if not isinstance(shared_records, list):
|
|
2340
|
+
shared_records = []
|
|
2341
|
+
for record in shared_records:
|
|
2342
|
+
_remove_owned_record(root, record, "shared-runtime", removed, preserved, uninstall_backup_dir)
|
|
2343
|
+
_purge_private_plugin_stores(root, removed, preserved)
|
|
2344
|
+
bugx_root = root / ".bugx"
|
|
2345
|
+
if bugx_root.is_symlink():
|
|
2346
|
+
raise CliError(_i18n_exc("lifecycle.clean_project_symlink_refused", "拒绝清理符号链接 .bugx"))
|
|
2347
|
+
if bugx_root.is_dir():
|
|
2348
|
+
if args.purge_data and external_backup is not None:
|
|
2349
|
+
# The initial external snapshot predates host-file deletion.
|
|
2350
|
+
# Persist the uninstall backups and the final diagnostic log
|
|
2351
|
+
# before removing the project runtime, otherwise the reported
|
|
2352
|
+
# recovery archive would silently miss the files just removed.
|
|
2353
|
+
_log_update_event(
|
|
2354
|
+
root,
|
|
2355
|
+
"uninstall_completed",
|
|
2356
|
+
"BugX 项目卸载即将完成",
|
|
2357
|
+
removed_count=len(removed),
|
|
2358
|
+
preserved_count=len(preserved),
|
|
2359
|
+
purge_data=True,
|
|
2360
|
+
backup=str(external_backup),
|
|
2361
|
+
)
|
|
2362
|
+
try:
|
|
2363
|
+
_backup_uninstall_delta(root, external_backup)
|
|
2364
|
+
_write_uninstall_receipt(
|
|
2365
|
+
external_backup,
|
|
2366
|
+
root=root,
|
|
2367
|
+
hosts=selected_names,
|
|
2368
|
+
removed=removed,
|
|
2369
|
+
preserved=preserved,
|
|
2370
|
+
purge_global_data=bool(args.purge_global_data),
|
|
2371
|
+
)
|
|
2372
|
+
except (OSError, ValueError, CliError) as exc:
|
|
2373
|
+
raise CliError(_i18n_exc("lifecycle.uninstall_backup_failed", f"卸载补充备份失败,已停止删除项目运行态:{exc}", exc=exc)) from exc
|
|
2374
|
+
# Close active logging handlers before purging the log directory
|
|
2375
|
+
import logging
|
|
2376
|
+
logger = logging.getLogger("bugx")
|
|
2377
|
+
for handler in list(logger.handlers):
|
|
2378
|
+
handler.close()
|
|
2379
|
+
logger.removeHandler(handler)
|
|
2380
|
+
shutil.rmtree(bugx_root)
|
|
2381
|
+
# 与 --dry-run 预览保持一致:项目运行态被清掉必须在 removed 里可查,
|
|
2382
|
+
# 否则用户只能靠 ls 猜(removed 为空时会误以为没清干净)。
|
|
2383
|
+
removed.append(".bugx/(项目运行态、报告、证据与共享资源)")
|
|
2384
|
+
if args.purge_global_data and global_root.exists():
|
|
2385
|
+
if global_root.is_symlink():
|
|
2386
|
+
raise CliError(_i18n_exc("lifecycle.clean_global_knowledge_symlink_refused", "拒绝清理符号链接全局错题集目录"))
|
|
2387
|
+
shutil.rmtree(global_root)
|
|
2388
|
+
removed.append("~/.bugx/knowledge/(全局错题集与经验集)")
|
|
2389
|
+
_remove_empty_parents(root, removed)
|
|
2390
|
+
payload = {
|
|
2391
|
+
"status": "UNINSTALLED",
|
|
2392
|
+
"root": str(root),
|
|
2393
|
+
"hosts": selected_names,
|
|
2394
|
+
"removed": removed,
|
|
2395
|
+
"preserved": preserved,
|
|
2396
|
+
"purged_project_data": bool(args.purge_data),
|
|
2397
|
+
"purged_global_data": bool(args.purge_global_data),
|
|
2398
|
+
"backup": str(external_backup) if external_backup else None,
|
|
2399
|
+
}
|
|
2400
|
+
if args.json:
|
|
2401
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
2402
|
+
else:
|
|
2403
|
+
print(f"[bugx] 卸载完成:删除 {len(removed)} 个 BugX 文件,保留 {len(preserved)} 个用户文件")
|
|
2404
|
+
if preserved:
|
|
2405
|
+
print(" 未删除(内容已变化或归属不明):" + ";".join(preserved))
|
|
2406
|
+
if external_backup:
|
|
2407
|
+
print(f" 数据备份:{external_backup}")
|
|
2408
|
+
backup_note = (
|
|
2409
|
+
f"外部归档 {external_backup}/project-uninstall-backups"
|
|
2410
|
+
if external_backup else ".bugx/backups"
|
|
2411
|
+
)
|
|
2412
|
+
print(
|
|
2413
|
+
" 测试报告、证据和错题集默认保留;被移除的宿主配置已备份到 "
|
|
2414
|
+
f"{backup_note},OpenCode 中 BugX 添加的 MCP 已移除(用户自有配置保留)"
|
|
2415
|
+
)
|
|
2416
|
+
return 0
|
|
2417
|
+
|
|
2418
|
+
|
|
2419
|
+
def _assert_writable(directory: Path, label: str) -> None:
|
|
2420
|
+
"""写探针:目录不可写时立即以 CliError 阻断(探针文件随即删除,零残留)。"""
|
|
2421
|
+
try:
|
|
2422
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
2423
|
+
probe = directory / f".bugx-write-probe-{os.getpid()}"
|
|
2424
|
+
probe.write_text("", encoding="utf-8")
|
|
2425
|
+
probe.unlink()
|
|
2426
|
+
except OSError as exc:
|
|
2427
|
+
raise CliError(f"{label}不可写:{directory}: {exc}") from exc
|
|
2428
|
+
|
|
2429
|
+
|
|
2430
|
+
def _precheck_initialization(root: Path, source: Path) -> None:
|
|
2431
|
+
"""F-L0-04 B 预检阶段:把可预知的失败全部前移到写盘之前(零落盘)。"""
|
|
2432
|
+
if not source.is_dir():
|
|
2433
|
+
raise CliError(_i18n_exc(
|
|
2434
|
+
"common.asset_root_unavailable",
|
|
2435
|
+
f"安装资源不可用,初始化已停止:{source}", source=source,
|
|
2436
|
+
))
|
|
2437
|
+
_assert_writable(root, "项目根目录")
|
|
2438
|
+
_assert_no_symlink_components(root / ".bugx")
|
|
2439
|
+
# 引擎目的地的权威校验留在 ``_install_engine``(避免两处解析口径漂移导致误报);
|
|
2440
|
+
# 此处只预检父目录可写性,把「目的地不可写」这类失败提前到写盘之前。
|
|
2441
|
+
_assert_writable(global_engine_root().parent, "全局引擎父目录")
|
|
2442
|
+
|
|
2443
|
+
|
|
2444
|
+
def _plan_cloud_onboarding(
|
|
2445
|
+
root: Path, *, cloud_sync_choice: str, had_onboarding: bool,
|
|
2446
|
+
cloud_sync_explicit: bool = False,
|
|
2447
|
+
) -> tuple[dict[str, Any] | None, int]:
|
|
2448
|
+
"""F-L0-04 A 决策阶段:判定云端 onboarding 目标动作(**项目状态零写入**)。
|
|
2449
|
+
|
|
2450
|
+
返回 ``(plan, exit_code)``:
|
|
2451
|
+
|
|
2452
|
+
* ``plan is not None`` → 决策已确定,交由 D 阶段落地(``exit_code`` 无意义);
|
|
2453
|
+
* ``plan is None`` → 决策未完成,调用方必须**在写盘前**以 ``exit_code`` 阻断
|
|
2454
|
+
(``2`` = 决策未完成;``1`` = onboarding 检查异常)。
|
|
2455
|
+
|
|
2456
|
+
既有语义(必须保留):
|
|
2457
|
+
* ``local`` / ``sync`` 是**已完成的用户决策**,同步未执行也放行;
|
|
2458
|
+
* ``done``(已开启同步)但本次同步未完成 → **必须阻断**(不得静默放行);
|
|
2459
|
+
* 状态非法或异常 → 阻断。
|
|
2460
|
+
"""
|
|
2461
|
+
# An explicit CLI choice is authoritative even when a previous attempt
|
|
2462
|
+
# left an onboarding file in ``pending``. Defer its side effects until
|
|
2463
|
+
# the commit phase, after project state (including the lesson ledger) has
|
|
2464
|
+
# been initialized. Probing sync here can otherwise make first-time
|
|
2465
|
+
# ``init --cloud-sync sync`` fail before it creates the very ledger that
|
|
2466
|
+
# sync requires.
|
|
2467
|
+
if not had_onboarding and cloud_sync_explicit and cloud_sync_choice in {"local", "sync"}:
|
|
2468
|
+
action = "enable_sync" if cloud_sync_choice == "sync" else "set_local"
|
|
2469
|
+
return {"action": action}, 0
|
|
2470
|
+
if not had_onboarding:
|
|
2471
|
+
if cloud_sync_choice == "sync":
|
|
2472
|
+
return {"action": "enable_sync"}, 0
|
|
2473
|
+
return {"action": "set_local"}, 0
|
|
2474
|
+
try:
|
|
2475
|
+
_ensure_core_importable()
|
|
2476
|
+
from core.cloud_sync.cloud_onboard import get_state
|
|
2477
|
+
from core.cloud_sync.onboard_wizard import maybe_onboard
|
|
2478
|
+
onboarding_ok = maybe_onboard(root, perform_sync=True)
|
|
2479
|
+
state = get_state(root)
|
|
2480
|
+
except Exception as exc: # noqa: BLE001
|
|
2481
|
+
print(f"[bugx] 云端 onboarding 检查失败,初始化已停止:{exc}")
|
|
2482
|
+
return None, 1
|
|
2483
|
+
if state not in {"done", "local", "sync"} or (
|
|
2484
|
+
state not in {"local", "sync"} and not onboarding_ok
|
|
2485
|
+
):
|
|
2486
|
+
return None, 2
|
|
2487
|
+
return {"action": "already_decided", "state": state}, 0
|
|
2488
|
+
|
|
2489
|
+
|
|
2490
|
+
def _apply_cloud_onboarding_plan(
|
|
2491
|
+
root: Path, plan: dict[str, Any], preset_data: dict[str, Any],
|
|
2492
|
+
) -> str:
|
|
2493
|
+
"""F-L0-04 D 阶段:落地云端 onboarding 决策。
|
|
2494
|
+
|
|
2495
|
+
与既有语义保持一致(本地/同步分支只记录意图,已有状态才执行同步);
|
|
2496
|
+
同步失败按既有设计降级为 ``sync_pending``,**不阻断初始化**。
|
|
2497
|
+
"""
|
|
2498
|
+
_ensure_core_importable()
|
|
2499
|
+
from core.cloud_sync.cloud_onboard import CloudOnboardDecisionRequired, get_state, set_state
|
|
2500
|
+
from core.cloud_sync.onboard_wizard import maybe_onboard
|
|
2501
|
+
|
|
2502
|
+
action = plan["action"]
|
|
2503
|
+
if action == "set_local":
|
|
2504
|
+
set_state(root, "local")
|
|
2505
|
+
return "local"
|
|
2506
|
+
if action == "enable_sync":
|
|
2507
|
+
set_state(root, "sync")
|
|
2508
|
+
# 用户已在命令行显式选择同步(意图明确),因此项目身份与登记必须在
|
|
2509
|
+
# init 阶段实际落盘,由 ensure_project_identity 确定性生成标准 v2 身份文件。
|
|
2510
|
+
try:
|
|
2511
|
+
from core.cloud_sync.onboard_wizard import ensure_project_identity
|
|
2512
|
+
ensure_project_identity(root)
|
|
2513
|
+
maybe_onboard(
|
|
2514
|
+
root, perform_sync=True, allow_identity_create=False,
|
|
2515
|
+
require_interaction=False,
|
|
2516
|
+
)
|
|
2517
|
+
except CloudOnboardDecisionRequired as exc:
|
|
2518
|
+
print(f" (项目登记延后到首次同步:{exc})")
|
|
2519
|
+
except Exception as exc: # noqa: BLE001
|
|
2520
|
+
# 登记失败不得回滚用户已做出的同步决策;状态保持 `sync`,
|
|
2521
|
+
# 由首次同步重试,并在输出里暴露真实失败原因。
|
|
2522
|
+
print(f" (项目登记未完成:{exc};首次同步将重试)")
|
|
2523
|
+
return "sync"
|
|
2524
|
+
# action == "already_decided":A 阶段已完成同步验证,D 阶段无需重复动作
|
|
2525
|
+
return str(plan.get("state") or get_state(root))
|
|
2526
|
+
|
|
2527
|
+
|
|
2528
|
+
def _commit_with_self_heal(commit, *, retries: int = 1):
|
|
2529
|
+
"""F-L0-04 D 阶段包装:写入失败先自愈重试;仍失败则返回 None(绝不谎报成功)。
|
|
2530
|
+
|
|
2531
|
+
``CliError`` 属决策类失败(已由 B 预检覆盖),直接抛出交由 CLI 统一处理。
|
|
2532
|
+
"""
|
|
2533
|
+
last: BaseException | None = None
|
|
2534
|
+
for attempt in range(retries + 1):
|
|
2535
|
+
try:
|
|
2536
|
+
return commit()
|
|
2537
|
+
except CliError:
|
|
2538
|
+
raise
|
|
2539
|
+
except Exception as exc: # noqa: BLE001
|
|
2540
|
+
last = exc
|
|
2541
|
+
if attempt < retries:
|
|
2542
|
+
print(
|
|
2543
|
+
f" ⚠ 初始化写入失败,正在自愈重试({type(exc).__name__}: {exc})",
|
|
2544
|
+
file=sys.stderr,
|
|
2545
|
+
)
|
|
2546
|
+
print(f"[bugx] 初始化失败:{type(last).__name__}: {last}", file=sys.stderr)
|
|
2547
|
+
return None
|
|
2548
|
+
|
|
2549
|
+
|
|
2550
|
+
def command_init(args: argparse.Namespace) -> int:
|
|
2551
|
+
root = args.root.resolve()
|
|
2552
|
+
preset_data = {}
|
|
2553
|
+
try:
|
|
2554
|
+
_ensure_core_importable()
|
|
2555
|
+
from core.dev_harness.interaction_preset import _read_preset_raw_payload
|
|
2556
|
+
preset_data = _read_preset_raw_payload(root)
|
|
2557
|
+
except Exception:
|
|
2558
|
+
preset_data = {}
|
|
2559
|
+
|
|
2560
|
+
cloud_sync_explicit = bool(getattr(args, "cloud_sync_explicit", False))
|
|
2561
|
+
if not cloud_sync_explicit and "cloud_sync" in preset_data:
|
|
2562
|
+
setattr(args, "cloud_sync", preset_data["cloud_sync"])
|
|
2563
|
+
cloud_sync_explicit = True
|
|
2564
|
+
setattr(args, "cloud_sync_explicit", True)
|
|
2565
|
+
|
|
2566
|
+
if not getattr(args, "commit_policy", None) and "commit_policy" in preset_data:
|
|
2567
|
+
setattr(args, "commit_policy", preset_data["commit_policy"])
|
|
2568
|
+
|
|
2569
|
+
# argparse suppresses the cloud-sync default so headless callers cannot
|
|
2570
|
+
# silently turn an omitted user decision into local mode.
|
|
2571
|
+
if not cloud_sync_explicit and not sys.stdin.isatty():
|
|
2572
|
+
print(
|
|
2573
|
+
"[bugx] 非交互模式禁止静默选择云端同步策略;请显式传入 "
|
|
2574
|
+
"--cloud-sync local 或 --cloud-sync sync。",
|
|
2575
|
+
file=sys.stderr,
|
|
2576
|
+
)
|
|
2577
|
+
return 2
|
|
2578
|
+
root.mkdir(parents=True, exist_ok=True)
|
|
2579
|
+
source = asset_root()
|
|
2580
|
+
|
|
2581
|
+
# F-L0-04 整改(commit-or-nothing):所有**已知**失败路径都必须在写盘前阻断。
|
|
2582
|
+
# ---- B 预检阶段(零落盘)------------------------------------------------
|
|
2583
|
+
_precheck_initialization(root, source)
|
|
2584
|
+
|
|
2585
|
+
# ---- A 决策阶段(零落盘):云端同步决策必须在任何写盘之前解析完成 --------
|
|
2586
|
+
onboarding_path = root / ".bugx" / "cloud-onboard.json"
|
|
2587
|
+
had_onboarding = onboarding_path.is_file()
|
|
2588
|
+
cloud_sync_choice = getattr(args, "cloud_sync", "local")
|
|
2589
|
+
onboarding_plan, onboarding_gate_code = _plan_cloud_onboarding(
|
|
2590
|
+
root, cloud_sync_choice=cloud_sync_choice, had_onboarding=had_onboarding,
|
|
2591
|
+
cloud_sync_explicit=cloud_sync_explicit,
|
|
2592
|
+
)
|
|
2593
|
+
if onboarding_plan is None:
|
|
2594
|
+
if onboarding_gate_code != 1:
|
|
2595
|
+
print(
|
|
2596
|
+
"[bugx] 云端 onboarding 未完成;初始化/重置不会跳过登录门禁,"
|
|
2597
|
+
"请完成云端授权或明确选择本地模式。"
|
|
2598
|
+
)
|
|
2599
|
+
return onboarding_gate_code
|
|
2600
|
+
|
|
2601
|
+
was_initialized = (root / ".bugx" / "manifest.json").is_file()
|
|
2602
|
+
|
|
2603
|
+
# ---- D 原子提交阶段:唯一写盘窗口(含自愈重试)--------------------------
|
|
2604
|
+
# 说明(O3 未落地):项目状态**不能**整体在 staging 内构建——
|
|
2605
|
+
# ``_assemble_project_materials`` / ``prep_validate`` / ``coverage_bootstrap``
|
|
2606
|
+
# 必须扫描**真实项目树**才能生成覆盖清单(实测:指向 staging 会得到
|
|
2607
|
+
# 「清单漏列全部最小单元」),且既有 ``.bugx`` 下的用户自定义目录必须原样保留。
|
|
2608
|
+
# 因此本阶段仍直接写真实项目根;零落盘由 A/B 阶段保证。
|
|
2609
|
+
def _commit_project_state() -> dict[str, Any]:
|
|
2610
|
+
# DOC-004 Layout 2:初始化只创建项目状态,不创建项目可执行引擎。
|
|
2611
|
+
# 旧项目的可执行入口按方案三默认直接删除,避免继续暴露双运行时。
|
|
2612
|
+
removed = _require_global_only_layout(root)
|
|
2613
|
+
copied_, skipped_ = _install_engine(source, args.force)
|
|
2614
|
+
refresh_i18n_after_engine_swap()
|
|
2615
|
+
_ensure_global_cli_symlinks()
|
|
2616
|
+
layout_ = _layout_module(root).initialize(root, bugx_version=__version__)
|
|
2617
|
+
_ensure_project_readme(root, source)
|
|
2618
|
+
_assemble_project_materials(root, source, layout_)
|
|
2619
|
+
_initialize_lesson_ledger(root, source)
|
|
2620
|
+
inherited_ = {"imported": 0, "skipped": 0}
|
|
2621
|
+
if not was_initialized:
|
|
2622
|
+
inherited_ = _inherit_project_knowledge(root)
|
|
2623
|
+
_initialize_project_knowledge_snapshots(root, source)
|
|
2624
|
+
life_created_ = _initialize_life_state(root)
|
|
2625
|
+
commit_policy_ = getattr(args, "commit_policy", None)
|
|
2626
|
+
profile_file_ = None
|
|
2627
|
+
if commit_policy_:
|
|
2628
|
+
_ensure_core_importable()
|
|
2629
|
+
from core.runtime.session_profile import save_commit_policy
|
|
2630
|
+
profile_file_ = save_commit_policy(commit_policy_, root=root)
|
|
2631
|
+
_apply_cloud_onboarding_plan(root, onboarding_plan, preset_data)
|
|
2632
|
+
return {
|
|
2633
|
+
"removed": removed, "copied": copied_, "skipped": skipped_,
|
|
2634
|
+
"layout": layout_, "inherited": inherited_,
|
|
2635
|
+
"life_created": life_created_, "profile_file": profile_file_,
|
|
2636
|
+
"commit_policy": commit_policy_,
|
|
2637
|
+
}
|
|
2638
|
+
|
|
2639
|
+
committed = _commit_with_self_heal(_commit_project_state)
|
|
2640
|
+
if committed is None:
|
|
2641
|
+
return 1
|
|
2642
|
+
removed_legacy_core = committed["removed"]
|
|
2643
|
+
copied = committed["copied"]
|
|
2644
|
+
skipped = committed["skipped"]
|
|
2645
|
+
layout = committed["layout"]
|
|
2646
|
+
inherited = committed["inherited"]
|
|
2647
|
+
life_created = committed["life_created"]
|
|
2648
|
+
profile_file = committed["profile_file"]
|
|
2649
|
+
commit_policy = committed["commit_policy"]
|
|
2650
|
+
# ---- E 收尾阶段(降级不阻断)-------------------------------------------
|
|
2651
|
+
try:
|
|
2652
|
+
# Ensure the project diagnostic log file exists so that subsequent
|
|
2653
|
+
# commands (and tests that read a baseline) see a readable path.
|
|
2654
|
+
log_file = root / ".bugx" / "logs" / "bugx.jsonl"
|
|
2655
|
+
log_file.parent.mkdir(parents=True, exist_ok=True)
|
|
2656
|
+
log_file.touch(exist_ok=True)
|
|
2657
|
+
log_file.chmod(0o600)
|
|
2658
|
+
_ensure_project_startup_todo(root)
|
|
2659
|
+
except OSError as exc:
|
|
2660
|
+
print(f" ⚠ 收尾步骤未完成(不影响初始化结果):{exc}", file=sys.stderr)
|
|
2661
|
+
try:
|
|
2662
|
+
_ensure_core_importable()
|
|
2663
|
+
from core.runtime import bugx_logging
|
|
2664
|
+
logger = bugx_logging.configure(root, command="init")
|
|
2665
|
+
bugx_logging.log_event(
|
|
2666
|
+
logger,
|
|
2667
|
+
"lifecycle_initialized",
|
|
2668
|
+
f"项目初始化完成: {root}",
|
|
2669
|
+
extra={
|
|
2670
|
+
"project_root": str(root),
|
|
2671
|
+
"cloud_sync": cloud_sync_choice,
|
|
2672
|
+
"commit_policy": commit_policy or "unset",
|
|
2673
|
+
"layout_version": getattr(layout, "manifest", {}).get("layout_version", "2.0.0") if hasattr(layout, "manifest") else "2.0.0",
|
|
2674
|
+
},
|
|
2675
|
+
)
|
|
2676
|
+
except Exception:
|
|
2677
|
+
pass
|
|
2678
|
+
|
|
2679
|
+
# ---- F 输出阶段:仅在关键写入全部成功后打印 ----------------------------
|
|
2680
|
+
print(f"[bugx] 初始化完成: 全局引擎 {global_engine_root()}")
|
|
2681
|
+
print(" 项目布局:仅保存 .bugx 状态/配置;可执行引擎统一来自全局目录")
|
|
2682
|
+
if removed_legacy_core:
|
|
2683
|
+
print(f" 已直接删除旧项目引擎入口:{removed_legacy_core}")
|
|
2684
|
+
print(f" 运行目录:{layout.root}")
|
|
2685
|
+
print(f" 写入 {copied} 个文件,保留 {skipped} 个已有文件")
|
|
2686
|
+
if life_created:
|
|
2687
|
+
print(" 已创建 .bugx 当前生命周期生命状态(1 条初始寿命)")
|
|
2688
|
+
else:
|
|
2689
|
+
print(" 保留已有 .bugx 当前生命周期生命状态;未重置运行状态")
|
|
2690
|
+
print(" 错题集:项目 SQLite 已建立;全局通用库按用户目录初始化/复用(Agent 只读)")
|
|
2691
|
+
if profile_file:
|
|
2692
|
+
print(f" 提交策略:{commit_policy}(配置已写入 {profile_file})")
|
|
2693
|
+
if not was_initialized:
|
|
2694
|
+
print(f" 已从全局通用库继承 active 模式:{inherited.get('imported', 0)} 条")
|
|
2695
|
+
print(" 宿主:未绑定;请使用 `bugx install --agent <宿主>` 安装原生入口")
|
|
2696
|
+
if skipped:
|
|
2697
|
+
print(" 使用 --force 可更新静态 Agent 文件;运行时状态不会被覆盖")
|
|
2698
|
+
try:
|
|
2699
|
+
from .cloud import confirm_data_sharing
|
|
2700
|
+
confirm_data_sharing(args)
|
|
2701
|
+
except Exception:
|
|
2702
|
+
pass
|
|
2703
|
+
return 0
|
|
2704
|
+
|
|
2705
|
+
|
|
2706
|
+
def _global_opencode_integrity_check() -> tuple[bool, str]:
|
|
2707
|
+
agents_dir = _global_opencode_agents_dir()
|
|
2708
|
+
engine = global_engine_root()
|
|
2709
|
+
missing: list[str] = []
|
|
2710
|
+
for filename in ("bugx.md", "bugx-worker.md"):
|
|
2711
|
+
link = agents_dir / filename
|
|
2712
|
+
alt_name = "bugx-opencode.md" if filename == "bugx.md" else filename
|
|
2713
|
+
cand = engine / "contracts" / alt_name
|
|
2714
|
+
expected = cand if cand.is_file() else (engine / alt_name)
|
|
2715
|
+
try:
|
|
2716
|
+
linked = (link.is_symlink()
|
|
2717
|
+
and link.resolve(strict=True) == expected.resolve(strict=True))
|
|
2718
|
+
# 无符号链接特权(Windows 非管理员/非开发者模式)时安装会发布
|
|
2719
|
+
# 字节一致的副本;哈希一致同样视为有效入口。
|
|
2720
|
+
copied = (not link.is_symlink() and link.is_file()
|
|
2721
|
+
and _sha256_file(link) == _sha256_file(expected))
|
|
2722
|
+
if not (linked or copied):
|
|
2723
|
+
missing.append(filename)
|
|
2724
|
+
except OSError:
|
|
2725
|
+
missing.append(filename)
|
|
2726
|
+
if missing:
|
|
2727
|
+
return False, "全局入口缺失或未指向当前引擎:" + ", ".join(missing)
|
|
2728
|
+
return True, "全局 bugx/bugx-worker 入口均指向当前引擎"
|
|
2729
|
+
|
|
2730
|
+
|
|
2731
|
+
def _global_pi_integrity_check(root: Path) -> tuple[bool, str]:
|
|
2732
|
+
project_skill = root / ".pi" / "skills" / "bugx" / "SKILL.md"
|
|
2733
|
+
home = Path.home().resolve()
|
|
2734
|
+
global_skill = home / ".agents" / "skills" / "bugx" / "SKILL.md"
|
|
2735
|
+
pi_link = home / ".pi" / "skills" / "bugx"
|
|
2736
|
+
pi_agent_link = home / ".pi" / "agent" / "skills" / "bugx"
|
|
2737
|
+
try:
|
|
2738
|
+
if not project_skill.is_file() or project_skill.is_symlink():
|
|
2739
|
+
return False, "项目 Pi Skill 缺失或不安全"
|
|
2740
|
+
if not global_skill.is_file() or global_skill.is_symlink():
|
|
2741
|
+
return False, "全局 Pi Skill 缺失或不安全"
|
|
2742
|
+
if _sha256_file(project_skill) != _sha256_file(global_skill):
|
|
2743
|
+
try:
|
|
2744
|
+
global_text = global_skill.read_text(encoding="utf-8")
|
|
2745
|
+
if "BugX for ChatGPT" in global_text or "BugX L0 路由入口" in global_text:
|
|
2746
|
+
return True, "全局 Skill 由 ChatGPT/L0 路由占用,Pi 兼容共存"
|
|
2747
|
+
except OSError:
|
|
2748
|
+
pass
|
|
2749
|
+
return False, "全局 Pi Skill 与项目版本哈希不一致"
|
|
2750
|
+
|
|
2751
|
+
def _check_link(link: Path) -> bool:
|
|
2752
|
+
linked = (link.is_symlink()
|
|
2753
|
+
and link.resolve(strict=True) == global_skill.parent.resolve())
|
|
2754
|
+
copied_dir = (not link.is_symlink() and link.is_dir()
|
|
2755
|
+
and (link / "SKILL.md").is_file()
|
|
2756
|
+
and _sha256_file(link / "SKILL.md") == _sha256_file(global_skill))
|
|
2757
|
+
return linked or copied_dir
|
|
2758
|
+
|
|
2759
|
+
if not (_check_link(pi_link) or _check_link(pi_agent_link)):
|
|
2760
|
+
return False, "~/.pi/skills/bugx 或 ~/.pi/agent/skills/bugx 未指向全局 Pi Skill"
|
|
2761
|
+
except OSError as exc:
|
|
2762
|
+
return False, f"全局 Pi Skill 无法校验: {exc}"
|
|
2763
|
+
return True, "项目、全局 Pi Skill 与发现入口哈希一致"
|