bugx-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +55 -0
- package/README.md +280 -2
- package/core/CATALOG.json +141 -0
- package/core/README.md +254 -0
- package/core/adapters/README.md +35 -0
- package/core/adapters/android-interaction.json +81 -0
- package/core/adapters/android.json +24 -0
- package/core/adapters/desktop-macos.json +20 -0
- package/core/adapters/ios-interaction.json +34 -0
- package/core/adapters/ios.json +23 -0
- package/core/adapters/memory-macos.json +24 -0
- package/core/agent/README.md +50 -0
- package/core/agent/__init__.py +146 -0
- package/core/agent/agent_artifacts.py +764 -0
- package/core/agent/agent_eval.py +1073 -0
- package/core/agent/agent_execution.py +552 -0
- package/core/agent/agent_orchestrator.py +1345 -0
- package/core/agent/agent_targets.py +871 -0
- package/core/agent/agent_workspace.py +770 -0
- package/core/assets/README.md +24 -0
- package/core/assets/bugx-avatar-1024.png +0 -0
- package/core/assets/bugx-avatar-512.png +0 -0
- package/core/assets/bugx-avatar-tight.svg +23 -0
- package/core/assets/bugx-avatar.svg +28 -0
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
- package/core/assets/project-layout.md +42 -0
- package/core/audit_packs/README.md +37 -0
- package/core/audit_packs/data-audit/manifest.json +94 -0
- package/core/audit_packs/data-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/data-audit/stages/10-schema-inventory.md +14 -0
- package/core/audit_packs/data-audit/stages/20-query-and-integrity.md +14 -0
- package/core/audit_packs/data-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/desktop-audit/manifest.json +123 -0
- package/core/audit_packs/desktop-audit/stages/00-scope.md +15 -0
- package/core/audit_packs/desktop-audit/stages/10-process-model.md +14 -0
- package/core/audit_packs/desktop-audit/stages/20-package-integrity.md +15 -0
- package/core/audit_packs/desktop-audit/stages/30-ui-behavior.md +14 -0
- package/core/audit_packs/desktop-audit/stages/80-evidence-regression.md +15 -0
- package/core/audit_packs/memory-testing.md +227 -0
- package/core/audit_packs/mobile-audit/manifest.json +155 -0
- package/core/audit_packs/mobile-audit/modules/android.md +19 -0
- package/core/audit_packs/mobile-audit/modules/h5.md +18 -0
- package/core/audit_packs/mobile-audit/modules/ios.md +25 -0
- package/core/audit_packs/mobile-audit/modules/miniprogram.md +26 -0
- package/core/audit_packs/mobile-audit/modules/webview.md +18 -0
- package/core/audit_packs/mobile-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/mobile-audit/stages/10-platform-inventory.md +14 -0
- package/core/audit_packs/mobile-audit/stages/20-masvs-static.md +20 -0
- package/core/audit_packs/mobile-audit/stages/30-component-exposure.md +14 -0
- package/core/audit_packs/mobile-audit/stages/40-device-behavior.md +14 -0
- package/core/audit_packs/mobile-audit/stages/80-evidence-regression.md +13 -0
- package/core/audit_packs/native-audit/manifest.json +127 -0
- package/core/audit_packs/native-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/native-audit/stages/10-static-white-box.md +14 -0
- package/core/audit_packs/native-audit/stages/20-memory-concurrency.md +15 -0
- package/core/audit_packs/native-audit/stages/30-behavior-black-box.md +39 -0
- package/core/audit_packs/native-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/platform-testing.md +174 -0
- package/core/audit_packs/web-audit/manifest.json +191 -0
- package/core/audit_packs/web-audit/modules/graphql.md +5 -0
- package/core/audit_packs/web-audit/modules/h5.md +18 -0
- package/core/audit_packs/web-audit/modules/multi-tenant.md +4 -0
- package/core/audit_packs/web-audit/modules/oauth.md +4 -0
- package/core/audit_packs/web-audit/modules/upload.md +4 -0
- package/core/audit_packs/web-audit/modules/websocket.md +4 -0
- package/core/audit_packs/web-audit/stages/00-scope.md +13 -0
- package/core/audit_packs/web-audit/stages/10-discovery.md +13 -0
- package/core/audit_packs/web-audit/stages/20-auth-session.md +13 -0
- package/core/audit_packs/web-audit/stages/30-authz-business.md +13 -0
- package/core/audit_packs/web-audit/stages/40-input-output.md +13 -0
- package/core/audit_packs/web-audit/stages/50-state-async.md +13 -0
- package/core/audit_packs/web-audit/stages/60-file-ssrf-deser.md +12 -0
- package/core/audit_packs/web-audit/stages/70-config-dependency.md +12 -0
- package/core/audit_packs/web-audit/stages/80-evidence-regression.md +12 -0
- package/core/autonomous_cve/INTERFACE.md +61 -0
- package/core/autonomous_cve/README.md +58 -0
- package/core/autonomous_cve/SPEC.md +25 -0
- package/core/autonomous_cve/__init__.py +109 -0
- package/core/autonomous_cve/attack_graph.py +1096 -0
- package/core/autonomous_cve/attack_graph_store.py +1822 -0
- package/core/autonomous_cve/audit_campaign.py +1232 -0
- package/core/autonomous_cve/behavior_graph.py +459 -0
- package/core/autonomous_cve/ghsa_advisories.py +174 -0
- package/core/autonomous_cve/models.py +93 -0
- package/core/autonomous_cve/mutator.py +87 -0
- package/core/autonomous_cve/patcher.py +126 -0
- package/core/autonomous_cve/scout.py +278 -0
- package/core/autonomous_cve/synthesizer.py +207 -0
- package/core/autonomous_cve/verifier.py +100 -0
- package/core/bugx.md +1299 -0
- package/core/bugx_paths.py +1846 -0
- package/core/cloud_sync/INTERFACE.md +32 -0
- package/core/cloud_sync/README.md +62 -0
- package/core/cloud_sync/SPEC.md +25 -0
- package/core/cloud_sync/__init__.py +23 -0
- package/core/cloud_sync/auto_sync.py +398 -0
- package/core/cloud_sync/cloud_client.py +1199 -0
- package/core/cloud_sync/cloud_onboard.py +702 -0
- package/core/cloud_sync/cloud_schema.py +648 -0
- package/core/cloud_sync/consent.py +81 -0
- package/core/cloud_sync/device_identity.py +307 -0
- package/core/cloud_sync/endpoint_router.py +415 -0
- package/core/cloud_sync/flywheel_client.py +760 -0
- package/core/cloud_sync/network_transport.py +275 -0
- package/core/cloud_sync/onboard_wizard.py +493 -0
- package/core/cloud_sync/sensitive_filter.py +285 -0
- package/core/cloud_sync/sync_pull.py +695 -0
- package/core/cloud_sync/sync_push.py +721 -0
- package/core/contracts/AGENT_GUIDE.md +362 -0
- package/core/contracts/README.md +34 -0
- package/core/contracts/bugx-blackbox.md +541 -0
- package/core/contracts/bugx-opencode.md +469 -0
- package/core/contracts/bugx-quick.md +44 -0
- package/core/contracts/bugx-runtime-contract.md +353 -0
- package/core/contracts/bugx-worker.md +470 -0
- package/core/contracts/engine_gap_contracts.py +390 -0
- package/core/coverage/README.md +70 -0
- package/core/coverage/__init__.py +106 -0
- package/core/coverage/coverage_ai_review.py +185 -0
- package/core/coverage/coverage_backfill.py +54 -0
- package/core/coverage/coverage_bootstrap.py +713 -0
- package/core/coverage/coverage_business.py +36 -0
- package/core/coverage/coverage_cli.py +715 -0
- package/core/coverage/coverage_discovery.py +859 -0
- package/core/coverage/coverage_evidence.py +977 -0
- package/core/coverage/coverage_forensics.py +115 -0
- package/core/coverage/coverage_gate.py +277 -0
- package/core/coverage/coverage_intelligence.py +734 -0
- package/core/coverage/coverage_manifest.py +396 -0
- package/core/coverage/coverage_platform.py +77 -0
- package/core/coverage/coverage_validate.py +236 -0
- package/core/coverage/module_coverage.py +157 -0
- package/core/dev_harness/INTERFACE.md +20 -0
- package/core/dev_harness/README.md +21 -0
- package/core/dev_harness/SPEC.md +25 -0
- package/core/dev_harness/__init__.py +5 -0
- package/core/dev_harness/interaction_preset.py +408 -0
- package/core/engine-integrity.json +2625 -0
- package/core/fuzzing/README.md +49 -0
- package/core/fuzzing/__init__.py +82 -0
- package/core/fuzzing/concurrency_fuzzer.py +382 -0
- package/core/fuzzing/differential_oracle.py +629 -0
- package/core/fuzzing/fuzz_input.py +1188 -0
- package/core/fuzzing/stateful_fuzzer.py +332 -0
- package/core/governance/README.md +61 -0
- package/core/governance/__init__.py +130 -0
- package/core/governance/capacity_planner.py +124 -0
- package/core/governance/dependency_lock.py +317 -0
- package/core/governance/goal_governor.py +754 -0
- package/core/governance/guide_budget.py +458 -0
- package/core/governance/lockdown.sh +50 -0
- package/core/governance/readonly_enforcer.py +154 -0
- package/core/governance/runtime_tool_gate.py +373 -0
- package/core/governance/secret_redactor.py +772 -0
- package/core/governance/token_budget.py +38 -0
- package/core/host_acp/INTERFACE.md +36 -0
- package/core/host_acp/README.md +51 -0
- package/core/host_acp/SPEC.md +25 -0
- package/core/host_acp/__init__.py +121 -0
- package/core/host_acp/base.py +111 -0
- package/core/host_acp/claude.py +41 -0
- package/core/host_acp/cline.py +235 -0
- package/core/host_acp/codex.py +245 -0
- package/core/host_acp/dsh.py +48 -0
- package/core/host_acp/opencode.py +154 -0
- package/core/host_acp/pi.py +36 -0
- package/core/host_acp/zcode.py +41 -0
- package/core/host_runtime/INTERFACE.md +24 -0
- package/core/host_runtime/README.md +62 -0
- package/core/host_runtime/SPEC.md +25 -0
- package/core/host_runtime/__init__.py +21 -0
- package/core/host_runtime/adapters.py +412 -0
- package/core/host_runtime/autonomous_runner.py +1152 -0
- package/core/host_runtime/cline.py +435 -0
- package/core/host_runtime/common.py +103 -0
- package/core/host_runtime/free_models.py +786 -0
- package/core/host_runtime/host_bootstrap.py +389 -0
- package/core/host_runtime/host_evaluators.py +721 -0
- package/core/host_runtime/host_probe.py +41 -0
- package/core/host_runtime/host_provider_arbitrator.py +777 -0
- package/core/host_runtime/host_registry.py +655 -0
- package/core/host_runtime/host_usage.py +127 -0
- package/core/host_runtime/mcp_process_tracker.py +509 -0
- package/core/host_runtime/mcp_registry_gate.py +368 -0
- package/core/hosts/INTERFACE.md +51 -0
- package/core/hosts/README.md +67 -0
- package/core/hosts/SPEC.md +25 -0
- package/core/hosts/__init__.py +136 -0
- package/core/hosts/_base_usage.py +152 -0
- package/core/hosts/_codex_usage.py +297 -0
- package/core/hosts/_dsh_usage.py +184 -0
- package/core/hosts/_mcp_toml.py +365 -0
- package/core/hosts/_zcode_usage.py +269 -0
- package/core/hosts/base.py +451 -0
- package/core/hosts/claude.py +157 -0
- package/core/hosts/cline.py +225 -0
- package/core/hosts/codex.py +948 -0
- package/core/hosts/dsh.py +518 -0
- package/core/hosts/opencode.py +358 -0
- package/core/hosts/pi.py +151 -0
- package/core/hosts/zcode.py +219 -0
- package/core/i18n.py +252 -0
- package/core/infra/README.md +39 -0
- package/core/infra/__init__.py +15 -0
- package/core/infra/build_info.py +86 -0
- package/core/infra/client_metadata.py +185 -0
- package/core/infra/python_runtime.py +540 -0
- package/core/infra/safe_xml.py +221 -0
- package/core/launch_bugx.py +118 -0
- package/core/launch_phases/INTERFACE.md +31 -0
- package/core/launch_phases/README.md +106 -0
- package/core/launch_phases/SPEC.md +25 -0
- package/core/launch_phases/__init__.py +29 -0
- package/core/launch_phases/candidate_revalidation.py +484 -0
- package/core/launch_phases/common.py +1041 -0
- package/core/launch_phases/finding_confirm_phase.py +387 -0
- package/core/launch_phases/finding_settlement.py +1245 -0
- package/core/launch_phases/findings_adjudication.py +666 -0
- package/core/launch_phases/findings_snapshot.py +357 -0
- package/core/launch_phases/judge_phase.py +791 -0
- package/core/launch_phases/lesson_context.py +536 -0
- package/core/launch_phases/lifecycle_reporter.py +627 -0
- package/core/launch_phases/orchestrator_controls.py +682 -0
- package/core/launch_phases/post_commit.py +567 -0
- package/core/launch_phases/post_coverage_sync.py +591 -0
- package/core/launch_phases/post_dry_run.py +817 -0
- package/core/launch_phases/post_observability.py +367 -0
- package/core/launch_phases/post_phase.py +1087 -0
- package/core/launch_phases/post_receipt.py +362 -0
- package/core/launch_phases/post_round_lifecycle.py +786 -0
- package/core/launch_phases/pre_phase.py +1029 -0
- package/core/launch_phases/pre_recon_scout.py +862 -0
- package/core/launch_phases/pre_state_builder.py +1286 -0
- package/core/launch_phases/report_sharing.py +414 -0
- package/core/launch_phases/round_orchestrator.py +1133 -0
- package/core/launch_phases/session_runtime.py +1623 -0
- package/core/launch_phases/startup_gates.py +1022 -0
- package/core/launch_phases/startup_interaction.py +947 -0
- package/core/launch_phases/startup_version_gate.py +873 -0
- package/core/launch_phases/supervisor_bridge.py +1224 -0
- package/core/launch_phases/supervisor_coverage.py +417 -0
- package/core/launch_phases/supervisor_degraded.py +1219 -0
- package/core/launch_phases/worker_barriers.py +414 -0
- package/core/launch_phases/worker_orchestrator.py +1166 -0
- package/core/launch_phases/worker_prior.py +749 -0
- package/core/ledger/INTERFACE.md +35 -0
- package/core/ledger/README.md +160 -0
- package/core/ledger/SPEC.md +25 -0
- package/core/ledger/__init__.py +67 -0
- package/core/ledger/_facade.py +226 -0
- package/core/ledger/archive_ops.py +572 -0
- package/core/ledger/auto_materialization.py +459 -0
- package/core/ledger/bug-log.md +22 -0
- package/core/ledger/cli.py +270 -0
- package/core/ledger/export_ops.py +549 -0
- package/core/ledger/finding_confirmation.py +1274 -0
- package/core/ledger/finding_io.py +299 -0
- package/core/ledger/finding_lifecycle.py +307 -0
- package/core/ledger/finding_verification.py +369 -0
- package/core/ledger/incidents.py +999 -0
- package/core/ledger/lesson-replay-cases.json +20 -0
- package/core/ledger/lesson_ledger.py +241 -0
- package/core/ledger/lesson_replay.py +272 -0
- package/core/ledger/life_ledger.py +668 -0
- package/core/ledger/mistake-book.md +130 -0
- package/core/ledger/patterns.py +681 -0
- package/core/ledger/receipt_contract.py +253 -0
- package/core/ledger/schema.py +1192 -0
- package/core/ledger/sync_ops.py +935 -0
- package/core/ledger/tool_experience.py +682 -0
- package/core/ledger/verify_life.py +1526 -0
- package/core/lesson-ledger.json +275 -0
- package/core/locales/README.md +19 -0
- package/core/locales/en-US.json +462 -0
- package/core/locales/zh-CN.json +462 -0
- package/core/mcp_handlers/INTERFACE.md +75 -0
- package/core/mcp_handlers/README.md +62 -0
- package/core/mcp_handlers/SPEC.md +25 -0
- package/core/mcp_handlers/__init__.py +128 -0
- package/core/mcp_handlers/base.py +697 -0
- package/core/mcp_handlers/channel_lifecycle.py +696 -0
- package/core/mcp_handlers/graph_handlers.py +222 -0
- package/core/mcp_handlers/knowledge_handlers.py +536 -0
- package/core/mcp_handlers/mining_handlers.py +586 -0
- package/core/mcp_handlers/resource_prompt_table.py +116 -0
- package/core/mcp_handlers/retrieval_handlers.py +239 -0
- package/core/mcp_handlers/rpc_server.py +465 -0
- package/core/mcp_handlers/supervisor_handlers.py +1435 -0
- package/core/mcp_handlers/telemetry_handlers.py +227 -0
- package/core/mcp_handlers/tool_table.py +1015 -0
- package/core/mcp_runtime_support/README.md +21 -0
- package/core/mcp_runtime_support/__init__.py +1 -0
- package/core/mcp_runtime_support/common.py +363 -0
- package/core/mcp_runtime_support/environment.py +605 -0
- package/core/mcp_runtime_support/verifier.py +810 -0
- package/core/metadata.txt +5 -0
- package/core/planning/README.md +157 -0
- package/core/planning/__init__.py +242 -0
- package/core/planning/capability_plan.py +187 -0
- package/core/planning/capability_planner.py +195 -0
- package/core/planning/domain_archetype.py +542 -0
- package/core/planning/domain_router.py +267 -0
- package/core/planning/dynamic_flow_analyzer.py +328 -0
- package/core/planning/impact_pruner.py +435 -0
- package/core/planning/intent_adjudicator.py +175 -0
- package/core/planning/judge_pipeline.py +1163 -0
- package/core/planning/logic_analysis.py +419 -0
- package/core/planning/prompt_harness.py +1702 -0
- package/core/planning/source_inspector.py +267 -0
- package/core/planning/spec_harvester.py +449 -0
- package/core/planning/target_sandbox_manager.py +573 -0
- package/core/planning/test_capability_verifier.py +1364 -0
- package/core/planning/tools-kb.md +38 -0
- package/core/planning/unit_kind.py +122 -0
- package/core/probes/INTERFACE.md +73 -0
- package/core/probes/README.md +51 -0
- package/core/probes/SPEC.md +26 -0
- package/core/probes/__init__.py +70 -0
- package/core/probes/android_probe.py +384 -0
- package/core/probes/base.py +147 -0
- package/core/probes/codebase_memory_probe.py +590 -0
- package/core/probes/desktop_probe.py +238 -0
- package/core/probes/differential_probe.py +356 -0
- package/core/probes/efficiency_probe.py +168 -0
- package/core/probes/ios_binary_probe.py +368 -0
- package/core/probes/memory_probe.py +326 -0
- package/core/probes/miniprogram_probe.py +323 -0
- package/core/probes/mobile_probe.py +281 -0
- package/core/probes/native_probe.py +214 -0
- package/core/probes/openwiki_probe.py +193 -0
- package/core/probes/pattern_probe.py +347 -0
- package/core/probes/platform_probe.py +343 -0
- package/core/probes/probe_registry.py +1669 -0
- package/core/probes/sast_probe.py +1009 -0
- package/core/probes/sast_rules.py +841 -0
- package/core/probes/sca_scanner.py +731 -0
- package/core/probes/web_probe.py +359 -0
- package/core/project_profiler/INTERFACE.md +62 -0
- package/core/project_profiler/README.md +53 -0
- package/core/project_profiler/SPEC.md +28 -0
- package/core/project_profiler/__init__.py +201 -0
- package/core/project_profiler/arbitrator.py +311 -0
- package/core/project_profiler/constants.py +247 -0
- package/core/project_profiler/detector.py +392 -0
- package/core/project_profiler/extractors.py +836 -0
- package/core/project_profiler/fingerprint.py +116 -0
- package/core/project_profiler/storage.py +258 -0
- package/core/project_profiler/strategy.py +265 -0
- package/core/prompts/README.md +35 -0
- package/core/prompts/codex_dialog_dispatch.md +9 -0
- package/core/prompts/command_routing_en.md +42 -0
- package/core/prompts/command_routing_zh.md +42 -0
- package/core/prompts/l0_router.md +47 -0
- package/core/prompts/rules/anti_patterns.md +16 -0
- package/core/prompts/rules/concurrency_rules.md +14 -0
- package/core/prompts/rules/memory_leak_rules.md +13 -0
- package/core/prompts/rules/prompt_injection_defense.md +13 -0
- package/core/prompts/stages/stage_explore.md +31 -0
- package/core/prompts/stages/stage_gate.md +43 -0
- package/core/prompts/stages/stage_mutate.md +42 -0
- package/core/prompts/stages/stage_repair.md +85 -0
- package/core/repair/README.md +74 -0
- package/core/repair/__init__.py +169 -0
- package/core/repair/fix_watchlist.py +391 -0
- package/core/repair/l7_dynamic.py +418 -0
- package/core/repair/l7_repair_loop.py +465 -0
- package/core/repair/l7_selfcheck.py +862 -0
- package/core/repair/minimize_repro.py +466 -0
- package/core/repair/patch_synthesizer.py +617 -0
- package/core/repair/regression_pack.py +379 -0
- package/core/repair/rsi_fixer.py +910 -0
- package/core/repair/rsi_loop.py +313 -0
- package/core/repair/rsi_repair.py +348 -0
- package/core/repair/rsi_rounds.py +212 -0
- package/core/repair/rsi_scope.py +262 -0
- package/core/repair/self_heal.py +604 -0
- package/core/repair/test_generator.py +1108 -0
- package/core/repair/test_quality_auditor.py +410 -0
- package/core/repair/test_strategy.py +511 -0
- package/core/report_engine/INTERFACE.md +59 -0
- package/core/report_engine/README.md +69 -0
- package/core/report_engine/SPEC.md +28 -0
- package/core/report_engine/__init__.py +47 -0
- package/core/report_engine/attestation.py +224 -0
- package/core/report_engine/authority.py +255 -0
- package/core/report_engine/finding_report.py +417 -0
- package/core/report_engine/formal_report_builder.py +924 -0
- package/core/report_engine/html_renderers.py +696 -0
- package/core/report_engine/models.py +761 -0
- package/core/report_engine/pdf_exporter.py +231 -0
- package/core/report_engine/projects_assets.py +730 -0
- package/core/report_engine/report_client.py +743 -0
- package/core/report_engine/report_data_builder.py +388 -0
- package/core/report_engine/report_share.py +459 -0
- package/core/report_engine/sast_bridge.py +116 -0
- package/core/report_engine/server.py +822 -0
- package/core/report_engine/visual_report_builder.py +796 -0
- package/core/report_engine/web-conformance.md +63 -0
- package/core/report_engine/web_conformance.py +459 -0
- package/core/report_engine/workbench_assets.py +484 -0
- package/core/retrieval/INTERFACE.md +20 -0
- package/core/retrieval/README.md +161 -0
- package/core/retrieval/SPEC.md +25 -0
- package/core/retrieval/__init__.py +3 -0
- package/core/retrieval/code_analyzer.py +1684 -0
- package/core/retrieval/codebase_memory_bridge.py +337 -0
- package/core/retrieval/context_assembler.py +234 -0
- package/core/retrieval/corpus_fetch.py +369 -0
- package/core/retrieval/graph_ego.py +597 -0
- package/core/retrieval/knowledge_auto.py +662 -0
- package/core/retrieval/knowledge_sources.py +168 -0
- package/core/retrieval/knowledge_sync.py +909 -0
- package/core/retrieval/memory_store.py +480 -0
- package/core/retrieval/query_planner.py +1020 -0
- package/core/retrieval/rrf_engine.py +137 -0
- package/core/retrieval/slice_extractor.py +1209 -0
- package/core/retrieval/slice_normalizer.py +373 -0
- package/core/retrieval/slice_spec.py +357 -0
- package/core/retrieval/symbol_index.py +1132 -0
- package/core/retrieval/universal_code_matcher.py +437 -0
- package/core/retrieval/xerj_bridge.py +476 -0
- package/core/retrieval/xerj_supervisor.py +362 -0
- package/core/rules/README.md +33 -0
- package/core/rules/ios/PROVENANCE.json +30 -0
- package/core/rules/ios/crypto.yaml +36 -0
- package/core/rules/ios/network.yaml +20 -0
- package/core/rules/ios/resilience.yaml +47 -0
- package/core/rules/ios/storage.yaml +48 -0
- package/core/rules/mastg/LICENSE +173 -0
- package/core/rules/mastg/PROVENANCE.json +270 -0
- package/core/rules/mastg/mastg-android-asymmetric-key-pair-used-for-multiple-purposes.yml +13 -0
- package/core/rules/mastg/mastg-android-backup-manifest.yml +24 -0
- package/core/rules/mastg/mastg-android-biometric-event-bound.yml +49 -0
- package/core/rules/mastg/mastg-android-biometric-invalidated-enrollment.yml +11 -0
- package/core/rules/mastg/mastg-android-biometric-no-confirmation-required.yml +10 -0
- package/core/rules/mastg/mastg-android-biometric-validity-duration.yml +24 -0
- package/core/rules/mastg/mastg-android-broken-encryption-algorithms.yaml +9 -0
- package/core/rules/mastg/mastg-android-broken-encryption-modes.yaml +13 -0
- package/core/rules/mastg/mastg-android-content-provider-exported.yml +35 -0
- package/core/rules/mastg/mastg-android-custom-deeplink-scheme.yml +29 -0
- package/core/rules/mastg/mastg-android-dangerous-app-permissions.yaml +65 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-apis.yml +36 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-manifest.yml +15 -0
- package/core/rules/mastg/mastg-android-debuggable-flag.yml +10 -0
- package/core/rules/mastg/mastg-android-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-deeplink-autoverify-missing.yml +33 -0
- package/core/rules/mastg/mastg-android-deeplink-unvalidated-parameter.yml +11 -0
- package/core/rules/mastg/mastg-android-device-passcode-present.yml +17 -0
- package/core/rules/mastg/mastg-android-fileprovider-broad-scope.yml +46 -0
- package/core/rules/mastg/mastg-android-hardcoded-crypto-keys-usage.yml +14 -0
- package/core/rules/mastg/mastg-android-hardcoded-security-provider.yaml +18 -0
- package/core/rules/mastg/mastg-android-implicit-intent-internal-communication.yml +30 -0
- package/core/rules/mastg/mastg-android-implicit-intent-leaking-extras.yml +29 -0
- package/core/rules/mastg/mastg-android-input-field-usage.yml +11 -0
- package/core/rules/mastg/mastg-android-key-generation-with-insufficient-key-length.yml +21 -0
- package/core/rules/mastg/mastg-android-keyboard-cache-input-types.yml +10 -0
- package/core/rules/mastg/mastg-android-local-storage-input-validation.yml +48 -0
- package/core/rules/mastg/mastg-android-native-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-network-checkservertrusted.yml +12 -0
- package/core/rules/mastg/mastg-android-network-hostname-verification.yml +11 -0
- package/core/rules/mastg/mastg-android-network-insecure-trust-anchors.yml +11 -0
- package/core/rules/mastg/mastg-android-network-onreceivedsslerror.yml +12 -0
- package/core/rules/mastg/mastg-android-non-random-use.yml +16 -0
- package/core/rules/mastg/mastg-android-object-deserialization.yml +14 -0
- package/core/rules/mastg/mastg-android-overlay-protection.yml +68 -0
- package/core/rules/mastg/mastg-android-pendingintent-mutable.yml +39 -0
- package/core/rules/mastg/mastg-android-random-apis-insufficient-entropy.yml +17 -0
- package/core/rules/mastg/mastg-android-root-detection.yaml +59 -0
- package/core/rules/mastg/mastg-android-sdk-version.yml +10 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications-manifest.yml +17 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications.yml +11 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-screenshot.yml +18 -0
- package/core/rules/mastg/mastg-android-sql-injection-contentprovider.yml +17 -0
- package/core/rules/mastg/mastg-android-ssl-socket-hostnameverifier.yml +15 -0
- package/core/rules/mastg/mastg-android-strictmode.yml +10 -0
- package/core/rules/mastg/mastg-android-system-alert-window.yml +9 -0
- package/core/rules/mastg/mastg-android-webview-allow-local-access.yml +15 -0
- package/core/rules/mastg/mastg-android-webview-bridges.yml +28 -0
- package/core/rules/mastg/mastg-android-webview-safebrowsing.yml +20 -0
- package/core/rules/mastg/mastg-android-webview-url-handlers.yml +41 -0
- package/core/rules/miniprogram/PROVENANCE.json +26 -0
- package/core/rules/miniprogram/network.yaml +37 -0
- package/core/rules/miniprogram/platform.yaml +36 -0
- package/core/rules/miniprogram/storage.yaml +48 -0
- package/core/rules/mobsfscan-swift/LICENSE +165 -0
- package/core/rules/mobsfscan-swift/PROVENANCE.json +58 -0
- package/core/rules/mobsfscan-swift/auth.yaml +59 -0
- package/core/rules/mobsfscan-swift/crypto.yaml +66 -0
- package/core/rules/mobsfscan-swift/jailbreak.yaml +14 -0
- package/core/rules/mobsfscan-swift/keyboard.yaml +34 -0
- package/core/rules/mobsfscan-swift/logging.yaml +23 -0
- package/core/rules/mobsfscan-swift/network.yaml +55 -0
- package/core/rules/mobsfscan-swift/resilience.yaml +29 -0
- package/core/rules/mobsfscan-swift/secrets.yaml +33 -0
- package/core/rules/mobsfscan-swift/storage.yaml +29 -0
- package/core/rules/mobsfscan-swift/webview.yaml +32 -0
- package/core/runtime/README.md +198 -0
- package/core/runtime/__init__.py +3 -0
- package/core/runtime/bugx_logging.py +1393 -0
- package/core/runtime/daemon_runner.py +623 -0
- package/core/runtime/fixture_solidify.py +449 -0
- package/core/runtime/global_telemetry.py +549 -0
- package/core/runtime/incident_eval.py +148 -0
- package/core/runtime/interaction.py +605 -0
- package/core/runtime/interaction_store.py +435 -0
- package/core/runtime/interactive_menu.py +95 -0
- package/core/runtime/log_analytics.py +922 -0
- package/core/runtime/mining_quality_framework.py +1387 -0
- package/core/runtime/model_runner.py +769 -0
- package/core/runtime/platform_adapter.py +579 -0
- package/core/runtime/prep_validate.py +476 -0
- package/core/runtime/project_graph.py +827 -0
- package/core/runtime/project_init.py +481 -0
- package/core/runtime/project_profile.py +224 -0
- package/core/runtime/project_settings.py +963 -0
- package/core/runtime/provider_window.py +97 -0
- package/core/runtime/resume_ticket.py +115 -0
- package/core/runtime/scenario_eval.py +814 -0
- package/core/runtime/seed_drill.py +549 -0
- package/core/runtime/self_audit.py +550 -0
- package/core/runtime/session_profile.py +205 -0
- package/core/runtime/setup_ui_env.py +229 -0
- package/core/runtime/startup_environment.py +859 -0
- package/core/runtime/sync_store.py +1421 -0
- package/core/runtime/tool_install_targets.py +18 -0
- package/core/schemas/README.md +35 -0
- package/core/schemas/agent-graph.schema.json +368 -0
- package/core/schemas/attack-graph.schema.json +88 -0
- package/core/schemas/evidence-bundle.schema.json +33 -0
- package/core/schemas/skill-pack.schema.json +230 -0
- package/core/schemas/worker-checkpoint.schema.json +119 -0
- package/core/secure_atomic.py +289 -0
- package/core/seed_corpus/README.md +55 -0
- package/core/seed_corpus/c.txt +29 -0
- package/core/seed_corpus/cpp.txt +32 -0
- package/core/seed_corpus/css.txt +70 -0
- package/core/seed_corpus/go.txt +46 -0
- package/core/seed_corpus/java.txt +30 -0
- package/core/seed_corpus/javascript.txt +55 -0
- package/core/seed_corpus/kotlin.txt +28 -0
- package/core/seed_corpus/python.txt +71 -0
- package/core/seed_corpus/rust.txt +53 -0
- package/core/seed_corpus/swift.txt +29 -0
- package/core/seed_corpus/typescript.txt +29 -0
- package/core/skills/README.md +53 -0
- package/core/skills/__init__.py +189 -0
- package/core/skills/bugx_docs_mcp_server.py +416 -0
- package/core/skills/bugx_mcp_server.py +1134 -0
- package/core/skills/mcp_runtime.py +968 -0
- package/core/skills/mcp_session_proof.py +605 -0
- package/core/skills/mobile_ui_inspector.py +405 -0
- package/core/skills/skill_pack.py +1214 -0
- package/core/skills/skill_synthesizer.py +1153 -0
- package/core/skills/tools_kb.py +313 -0
- package/core/supervisor/INTERFACE.md +121 -0
- package/core/supervisor/README.md +209 -0
- package/core/supervisor/SPEC.md +25 -0
- package/core/supervisor/__init__.py +175 -0
- package/core/supervisor/audit_supervisor.py +1015 -0
- package/core/supervisor/budget_governor.py +760 -0
- package/core/supervisor/checkpoint_handler.py +368 -0
- package/core/supervisor/checkpoint_pipeline.py +1322 -0
- package/core/supervisor/checkpoint_sync.py +640 -0
- package/core/supervisor/claim_events.py +74 -0
- package/core/supervisor/claim_sync.py +590 -0
- package/core/supervisor/cli.py +812 -0
- package/core/supervisor/context_sync.py +55 -0
- package/core/supervisor/coverage_sync.py +115 -0
- package/core/supervisor/finding_commit.py +470 -0
- package/core/supervisor/finding_sync.py +688 -0
- package/core/supervisor/finding_workflow.py +659 -0
- package/core/supervisor/finish_policy.py +224 -0
- package/core/supervisor/finish_sync.py +185 -0
- package/core/supervisor/graph_sync.py +669 -0
- package/core/supervisor/lease_manager.py +788 -0
- package/core/supervisor/lifecycle_blocks.py +124 -0
- package/core/supervisor/next_round_sync.py +126 -0
- package/core/supervisor/observability.py +140 -0
- package/core/supervisor/recovery_sync.py +165 -0
- package/core/supervisor/rejection_remedies.py +308 -0
- package/core/supervisor/round_governor.py +306 -0
- package/core/supervisor/serial_authorization.py +500 -0
- package/core/supervisor/start_sync.py +87 -0
- package/core/supervisor/state_store.py +249 -0
- package/core/supervisor/supervisor_host.py +511 -0
- package/core/supervisor/supervisor_models.py +1143 -0
- package/core/supervisor/systemic_failure.py +104 -0
- package/core/supervisor/task_scheduler.py +1640 -0
- package/core/supervisor/worker_checkpoint.py +223 -0
- package/core/supervisor/worker_execution.py +265 -0
- package/core/supervisor/worker_handoff.py +192 -0
- package/core/supervisor/worker_lifecycle.py +396 -0
- package/core/supervisor/worker_runtime.py +999 -0
- package/core/supervisor/worker_sync.py +89 -0
- package/core/supervisor_types/README.md +36 -0
- package/core/supervisor_types/__init__.py +0 -0
- package/core/supervisor_types/exceptions.py +52 -0
- package/core/supervisor_types/graph_models.py +357 -0
- package/core/supervisor_types/path_containment.py +151 -0
- package/core/supervisor_types/target_fingerprint.py +310 -0
- package/core/supervisor_types/worker_claim.py +402 -0
- package/core/webui/INTERFACE.md +50 -0
- package/core/webui/README.md +57 -0
- package/core/webui/SPEC.md +25 -0
- package/core/webui/__init__.py +11 -0
- package/core/webui/adapters/__init__.py +27 -0
- package/core/webui/adapters/base.py +87 -0
- package/core/webui/adapters/bugx.py +102 -0
- package/core/webui/adapters/claude.py +218 -0
- package/core/webui/adapters/cline.py +399 -0
- package/core/webui/adapters/codex.py +256 -0
- package/core/webui/adapters/dsh.py +173 -0
- package/core/webui/adapters/opencode.py +218 -0
- package/core/webui/adapters/pi.py +272 -0
- package/core/webui/adapters/registry.py +100 -0
- package/core/webui/adapters/zcode.py +312 -0
- package/core/webui/api_routes_post.py +668 -0
- package/core/webui/dispatcher.py +1376 -0
- package/core/webui/docs_session_service.py +473 -0
- package/core/webui/handler.py +674 -0
- package/core/webui/ide_cloud_service.py +526 -0
- package/core/webui/mcp_inspector.py +1743 -0
- package/core/webui/static/assets/index-CXAsl8mr.js +333 -0
- package/core/webui/static/assets/index-DHQUtWtx.css +1 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-B8Z6Jvzv.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-C44pakCn.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-Bb4u56_6.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-BdVUvljg.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-CWV284fw.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-DLkyKLvH.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-8-8HP2PF.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-DaDZE_Na.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-BccYJ-vZ.woff +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-Cw5-AHNN.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-By8GFJzz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-z-Q6FFuG.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-DJ5YJwmz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-Dn3IlU-Z.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-CUHe9xxf.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-DVVamBqs.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-CEpydyUl.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-Cp7z-ARB.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-BYjRCDVy.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-D-qasQTj.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-BbG3LG1A.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-DR1UuFon.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-8N8MYVKB.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-Bi3OSTTW.woff2 +0 -0
- package/core/webui/static/favicon.png +0 -0
- package/core/webui/static/icon-192.png +0 -0
- package/core/webui/static/index.html +42 -0
- package/core/webui/static/manifest.webmanifest +19 -0
- package/core/webui/static/project-settings.css +6458 -0
- package/core/webui/static/project-settings.js +9602 -0
- package/core/webui/static/sw.js +8 -0
- package/core/webui/workspace_service.py +218 -0
- package/docs/07_distribution/01_README_NPM.md +281 -0
- package/docs/07_distribution/README.md +16 -0
- package/docs/README.md +121 -0
- package/ecosystem/README.md +129 -0
- package/ecosystem/integrations/README.md +38 -0
- package/ecosystem/integrations/cline/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/dsh/agents/bugx.md +27 -0
- package/ecosystem/integrations/dsh/dsh-patch.yml +18 -0
- package/ecosystem/integrations/dsh/mcp/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/mcp/index.js +219 -0
- package/ecosystem/integrations/dsh/mcp/package.json +28 -0
- package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +70 -0
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/integrations/dsh/ui/client.js +87 -0
- package/ecosystem/integrations/dsh/ui/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/ui/index.js +7 -0
- package/ecosystem/integrations/dsh/ui/package.json +27 -0
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +53 -0
- package/ecosystem/integrations/opencode/mcp-lock.json +3067 -0
- package/ecosystem/integrations/opencode/opencode.json +118 -0
- package/ecosystem/integrations/pi/extensions/bugx/README.md +12 -0
- package/ecosystem/integrations/pi/extensions/bugx/index.ts +299 -0
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +11 -0
- package/ecosystem/integrations/pi/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/qoder/CONNECTORS.md +54 -0
- package/ecosystem/integrations/qoder/connector-meta.json +21 -0
- package/ecosystem/integrations/workbuddy/connector-meta.json +19 -0
- package/ecosystem/integrations/workbuddy/icon.png +0 -0
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +70 -0
- package/ecosystem/plugins/README.md +37 -0
- package/ecosystem/plugins/bugx/.claude-plugin/marketplace.json +17 -0
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +16 -0
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +41 -0
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +19 -0
- package/ecosystem/plugins/bugx/agents/bugx-judge.md +71 -0
- package/ecosystem/plugins/bugx/agents/bugx-worker.md +31 -0
- package/ecosystem/plugins/bugx/agents/bugx.md +74 -0
- package/ecosystem/plugins/bugx/assets/bugx-avatar-512.png +0 -0
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +118 -0
- package/ecosystem/plugins/bugx/skills/bugx-claude/SKILL.md +326 -0
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +129 -0
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +459 -0
- package/interfaces/README.md +143 -0
- package/interfaces/bin/README.md +35 -0
- package/interfaces/bin/bugx.js +80 -0
- package/interfaces/cli/README.md +90 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -0
- package/interfaces/cli/bugx_cli/cli.py +1678 -0
- package/interfaces/cli/bugx_cli/commands/__init__.py +1 -0
- package/interfaces/cli/bugx_cli/commands/advisory.py +94 -0
- package/interfaces/cli/bugx_cli/commands/agent.py +3944 -0
- package/interfaces/cli/bugx_cli/commands/audit.py +632 -0
- package/interfaces/cli/bugx_cli/commands/autonomous.py +260 -0
- package/interfaces/cli/bugx_cli/commands/cloud.py +1370 -0
- package/interfaces/cli/bugx_cli/commands/daemon.py +50 -0
- package/interfaces/cli/bugx_cli/commands/doctor.py +1345 -0
- package/interfaces/cli/bugx_cli/commands/goal.py +107 -0
- package/interfaces/cli/bugx_cli/commands/interaction.py +244 -0
- package/interfaces/cli/bugx_cli/commands/knowledge.py +617 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +2763 -0
- package/interfaces/cli/bugx_cli/commands/patch.py +1014 -0
- package/interfaces/cli/bugx_cli/commands/plugin.py +2714 -0
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +1446 -0
- package/interfaces/cli/bugx_cli/commands/plugin_cline.py +269 -0
- package/interfaces/cli/bugx_cli/commands/plugin_codex.py +74 -0
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +728 -0
- package/interfaces/cli/bugx_cli/commands/plugin_qoder.py +216 -0
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +710 -0
- package/interfaces/cli/bugx_cli/commands/project.py +670 -0
- package/interfaces/cli/bugx_cli/commands/report.py +260 -0
- package/interfaces/cli/bugx_cli/commands/skill.py +251 -0
- package/interfaces/cli/bugx_cli/commands/stats.py +133 -0
- package/interfaces/cli/bugx_cli/commands/system.py +2567 -0
- package/interfaces/cli/bugx_cli/common.py +898 -0
- package/interfaces/cli/bugx_cli/host_adapters.py +1917 -0
- package/interfaces/cli/bugx_cli/hosts/__init__.py +80 -0
- package/interfaces/cli/bugx_cli/hosts/base.py +99 -0
- package/interfaces/cli/bugx_cli/hosts/registry.py +571 -0
- package/interfaces/cli/bugx_cli/hosts/template_engine.py +188 -0
- package/interfaces/cli/bugx_cli/infra/__init__.py +209 -0
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +721 -0
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +1937 -0
- package/interfaces/cli/bugx_cli/infra/host_sync.py +545 -0
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +755 -0
- package/interfaces/cli/bugx_cli/infra/security.py +332 -0
- package/package.json +98 -4
- package/pyproject.toml +246 -0
- package/scripts/README.md +118 -0
- package/scripts/ensure-python.mjs +97 -0
- package/scripts/isolate-npm-readme.mjs +40 -0
- package/scripts/runtime.lock.json +31 -0
- package/scripts/sync-version.mjs +37 -0
- package/scripts/test-npm-wrapper.mjs +265 -0
|
@@ -0,0 +1,898 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""BugX 统一命令行入口。"""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
from contextlib import contextmanager
|
|
8
|
+
import copy
|
|
9
|
+
from email.parser import Parser
|
|
10
|
+
import hashlib
|
|
11
|
+
import importlib.metadata
|
|
12
|
+
import importlib.util
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
import re
|
|
16
|
+
import shutil
|
|
17
|
+
import subprocess
|
|
18
|
+
import sys
|
|
19
|
+
import sysconfig
|
|
20
|
+
import tarfile
|
|
21
|
+
import tempfile
|
|
22
|
+
import time
|
|
23
|
+
try:
|
|
24
|
+
import tomllib
|
|
25
|
+
except ImportError:
|
|
26
|
+
tomllib = None
|
|
27
|
+
import zipfile
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
from typing import Any
|
|
30
|
+
|
|
31
|
+
import bugx_cli
|
|
32
|
+
from . import __version__
|
|
33
|
+
from bugx_cli.infra import (
|
|
34
|
+
CONFIG_NAME,
|
|
35
|
+
CORE_API_RE,
|
|
36
|
+
CliError,
|
|
37
|
+
ENGINE_INTEGRITY_NAME,
|
|
38
|
+
ENGINE_INTEGRITY_SCHEMA,
|
|
39
|
+
LOCK_NAME,
|
|
40
|
+
MCP_RUNTIME_COMMAND,
|
|
41
|
+
OPENCODE_MCP_PACKAGES,
|
|
42
|
+
OPENCODE_PINNED_MCP_COMMANDS,
|
|
43
|
+
PLUGIN_VERSION_RE,
|
|
44
|
+
PROJECT_OWNED_CORE_NAMES,
|
|
45
|
+
REQUIRED_I18N_ASSETS,
|
|
46
|
+
REQUIRED_MCP_RECOMMENDATIONS,
|
|
47
|
+
RUNTIME_NAMES,
|
|
48
|
+
VERSION_RE,
|
|
49
|
+
_assert_no_symlink_components,
|
|
50
|
+
_asset_candidates,
|
|
51
|
+
_atomic_write_global_file,
|
|
52
|
+
_backup_host_resource,
|
|
53
|
+
_config_candidates,
|
|
54
|
+
_controlled_core_resource,
|
|
55
|
+
_copy_pi_extension,
|
|
56
|
+
_copy_plugin,
|
|
57
|
+
_detach_project_owned_core_links,
|
|
58
|
+
_detach_project_runtime_core_entries,
|
|
59
|
+
_engine_file_manifest,
|
|
60
|
+
_engine_install_lock,
|
|
61
|
+
_engine_integrity_status,
|
|
62
|
+
_ensure_global_cli_symlinks,
|
|
63
|
+
_find_current_cli_executable,
|
|
64
|
+
_find_repo_root,
|
|
65
|
+
_engine_manifest_payload,
|
|
66
|
+
_file_record,
|
|
67
|
+
_fsync_engine_tree,
|
|
68
|
+
_guard_plugin_write_target,
|
|
69
|
+
_host_bundle_checks,
|
|
70
|
+
_installed_plugin_agent,
|
|
71
|
+
_install_engine,
|
|
72
|
+
_integration_dir,
|
|
73
|
+
_is_reparse_point,
|
|
74
|
+
_is_runtime_artifact_name,
|
|
75
|
+
_legacy_project_core_present,
|
|
76
|
+
_json_version_marker,
|
|
77
|
+
_layout_module,
|
|
78
|
+
_legacy_core_runtime_entries,
|
|
79
|
+
_link_legacy_project_core,
|
|
80
|
+
_lock_candidates,
|
|
81
|
+
_lock_disabled_servers,
|
|
82
|
+
_mcp_entry_state,
|
|
83
|
+
_mcp_recommendations,
|
|
84
|
+
_mcp_runtime_check,
|
|
85
|
+
_mcp_runtime_doctor_payload,
|
|
86
|
+
_project_mcp_processes,
|
|
87
|
+
_abandoned_mcp_processes,
|
|
88
|
+
_mcp_session_hygiene_check,
|
|
89
|
+
installed_runtime_servers,
|
|
90
|
+
provision_targeted_mcp_runtime,
|
|
91
|
+
targeted_mcp_names,
|
|
92
|
+
_plugin_manifest,
|
|
93
|
+
_plugin_store,
|
|
94
|
+
_print_mcp_recommendations,
|
|
95
|
+
_records_for_paths,
|
|
96
|
+
_recover_engine_swap,
|
|
97
|
+
_relative_project_file,
|
|
98
|
+
_require_global_only_layout,
|
|
99
|
+
_remove_empty_parents,
|
|
100
|
+
_remove_engine_path,
|
|
101
|
+
_safe_record_target,
|
|
102
|
+
_engine_basename_index,
|
|
103
|
+
_script,
|
|
104
|
+
_sha256_file,
|
|
105
|
+
_shared_asset_records,
|
|
106
|
+
_stage_engine,
|
|
107
|
+
verify_builtin_mcp_manifest,
|
|
108
|
+
_version_contract_status,
|
|
109
|
+
_version_marker,
|
|
110
|
+
_write_engine_integrity,
|
|
111
|
+
_write_host_resource,
|
|
112
|
+
_write_private_json,
|
|
113
|
+
asset_root,
|
|
114
|
+
bundled_config,
|
|
115
|
+
bundled_lock,
|
|
116
|
+
default_mcp_runtime_root,
|
|
117
|
+
global_engine_root,
|
|
118
|
+
pi_extension_root,
|
|
119
|
+
pi_skill_root,
|
|
120
|
+
project_core,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
MIN_PYTHON = (3, 11)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _require_supported_python() -> None:
|
|
129
|
+
"""Fail before importing feature modules on an unsupported interpreter.
|
|
130
|
+
|
|
131
|
+
BugX deliberately targets Python 3.11+ (see ``pyproject.toml``). Several
|
|
132
|
+
core modules use 3.11-era dataclass/type features, so waiting until a
|
|
133
|
+
command imports them turns an environment problem into an opaque traceback.
|
|
134
|
+
Keep the guard at the CLI import boundary and return a stable, actionable
|
|
135
|
+
message instead.
|
|
136
|
+
"""
|
|
137
|
+
if sys.version_info < MIN_PYTHON:
|
|
138
|
+
actual = ".".join(str(part) for part in sys.version_info[:3])
|
|
139
|
+
required = ".".join(str(part) for part in MIN_PYTHON)
|
|
140
|
+
print(
|
|
141
|
+
f"[BugX] 当前 Python {actual} 不受支持;需要 Python >= {required}。"
|
|
142
|
+
"请切换到受支持的 Python 后重试。",
|
|
143
|
+
file=sys.stderr,
|
|
144
|
+
)
|
|
145
|
+
raise SystemExit(2)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
_require_supported_python()
|
|
149
|
+
|
|
150
|
+
from .host_adapters import (
|
|
151
|
+
add_locale_marker,
|
|
152
|
+
BUGX_WORKER_DESCRIPTION,
|
|
153
|
+
HOST_ADAPTERS,
|
|
154
|
+
WORKBUDDY_PROJECT_PATHS,
|
|
155
|
+
_workbuddy_config_roots,
|
|
156
|
+
discover_hosts,
|
|
157
|
+
get_adapter,
|
|
158
|
+
render_zcode_worker_entry,
|
|
159
|
+
strip_locale_marker,
|
|
160
|
+
read_locale_marker,
|
|
161
|
+
workbuddy_user_skill_root,
|
|
162
|
+
ZCODE_WORKER_INSTALL_PATH,
|
|
163
|
+
)
|
|
164
|
+
from .hosts.registry import sweepable_skill_adapter_names
|
|
165
|
+
|
|
166
|
+
#: 按 Skill 语义清扫的适配器基线(仅**未迁移**宿主;已迁移宿主由插件
|
|
167
|
+
#: ``install.sweepable`` 声明)。逐宿主切片时删除对应项。
|
|
168
|
+
_LEGACY_SWEEPABLE_SKILL_ADAPTERS = ("claude", "zcode", "workbuddy")
|
|
169
|
+
_SWEEPABLE_SKILL_ADAPTERS = sweepable_skill_adapter_names(_LEGACY_SWEEPABLE_SKILL_ADAPTERS)
|
|
170
|
+
|
|
171
|
+
RUNTIME_NAMES = {
|
|
172
|
+
"bugx-life.json", "bugx-life.json.snapshot", "bugx-life.json.lock",
|
|
173
|
+
"bugx-runtime.json", "bugx-runtime.lock", "findings.json",
|
|
174
|
+
"audit-supervisor.json", "audit-supervisor.lock", "coverage-evidence.json",
|
|
175
|
+
"coverage-evidence.lock", "finding-ledger.json", "finding-ledger.lock",
|
|
176
|
+
"audit-supervisor.json.lock", "coverage-evidence.json.lock",
|
|
177
|
+
"finding-ledger.json.lock",
|
|
178
|
+
"lesson-ledger.sqlite3", "lesson-ledger.sqlite3-shm", "lesson-ledger.sqlite3-wal",
|
|
179
|
+
"lesson-ledger.db", "lesson-ledger.db-shm", "lesson-ledger.db-wal",
|
|
180
|
+
"lesson-ledger.json.lock", ".lesson-ledger.json.lock",
|
|
181
|
+
"audit-campaign.json", "finding-lifecycle.json", "repair-audit.log",
|
|
182
|
+
"bugx-runtime.json.bak", "audit-supervisor.json.bak",
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
OPENCODE_REQUIRED_MCP = ("playwright", "postmcp", "dbhub", "redis", "semgrep", "mobile")
|
|
189
|
+
OPENCODE_LOCAL_MCP = ("bugx-supervisor", "bugx-supervisor-worker", "bugx-docs")
|
|
190
|
+
OPENCODE_ALL_REQUIRED_MCP = OPENCODE_REQUIRED_MCP + OPENCODE_LOCAL_MCP
|
|
191
|
+
OPENCODE_BUGX_MANAGED_MCP = OPENCODE_ALL_REQUIRED_MCP
|
|
192
|
+
# Native host MCP channels for local automatic review and knowledge lookup.
|
|
193
|
+
HOST_SUPERVISOR_MCP = ("bugx-supervisor", "bugx-supervisor-worker")
|
|
194
|
+
HOST_ALL_MCP = ("bugx-supervisor", "bugx-supervisor-worker", "bugx-docs")
|
|
195
|
+
HOST_SUPERVISOR_MCP_ROLES = {"bugx-supervisor": "host", "bugx-supervisor-worker": "worker"}
|
|
196
|
+
PROBE_SCRIPTS = {
|
|
197
|
+
"efficiency": "efficiency_probe.py",
|
|
198
|
+
"sast": "sast_probe.py",
|
|
199
|
+
"mobile": "mobile_probe.py",
|
|
200
|
+
"ios_binary": "ios_binary_probe.py",
|
|
201
|
+
"codebase-memory": "codebase_memory_probe.py",
|
|
202
|
+
"platform": "platform_probe.py",
|
|
203
|
+
"memory": "memory_probe.py",
|
|
204
|
+
"pattern": "pattern_probe.py",
|
|
205
|
+
"differential": "differential_probe.py",
|
|
206
|
+
"openwiki": "openwiki_probe.py",
|
|
207
|
+
}
|
|
208
|
+
PROBES_WITHOUT_ROOT_ARGUMENT = {"memory", "differential"}
|
|
209
|
+
CHATGPT_PLUGIN_NAME = "bugx"
|
|
210
|
+
CHATGPT_PLUGIN_SOURCE = "./plugins/bugx"
|
|
211
|
+
CHATGPT_GLOBAL_MARKETPLACE_NAME = "bugx-global"
|
|
212
|
+
CHATGPT_GLOBAL_PLUGIN_DIR_NAME = "chatgpt-plugin"
|
|
213
|
+
CHATGPT_LEGACY_MARKETPLACE_PREFIX = "bugx-local-"
|
|
214
|
+
_ACTIVE_TRACE_ID: str | None = None
|
|
215
|
+
|
|
216
|
+
RESET_PROJECT_DIRECTORIES = (
|
|
217
|
+
"pollings", "state", "logs", "artifacts", "index", "backups", "locks",
|
|
218
|
+
"evidence", "findings",
|
|
219
|
+
)
|
|
220
|
+
RESET_PROJECT_FILES = (
|
|
221
|
+
"current.json", "audit-supervisor.json",
|
|
222
|
+
"audit-supervisor.json.bak", "audit-supervisor.json.lock",
|
|
223
|
+
"lifecycle.lock", "bugx-life.json",
|
|
224
|
+
"bugx-life.json.snapshot", "bugx-life.json.lock", "bugx-runtime.json",
|
|
225
|
+
"bugx-runtime.lock", "coverage-evidence.json", "coverage-evidence.lock",
|
|
226
|
+
"finding-ledger.json", "finding-ledger.lock", ".finding-ledger.json.lock",
|
|
227
|
+
"audit-campaign.json", "finding-lifecycle.json", "repair-audit.log",
|
|
228
|
+
"startup-todo.md", "resume_ticket.json", "init.lock", ".init_progress.json",
|
|
229
|
+
"prep-record.md", "module-coverage.md", "strategy.json",
|
|
230
|
+
"attack-graph-snapshot.json", "coverage-ledger.json", "findings.json",
|
|
231
|
+
"life.json", "cloud-onboard.json",
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _ensure_core_importable() -> None:
|
|
242
|
+
"""把核心引擎目录(全局引擎/asset_root)加入 sys.path,保证 core 模块可 import。"""
|
|
243
|
+
asset_override = os.environ.get("BUGX_ASSET_ROOT")
|
|
244
|
+
if asset_override is not None:
|
|
245
|
+
candidate = Path(asset_override).expanduser()
|
|
246
|
+
try:
|
|
247
|
+
valid_asset = candidate.resolve(strict=True) in _asset_candidates()
|
|
248
|
+
except (OSError, RuntimeError, ValueError):
|
|
249
|
+
valid_asset = False
|
|
250
|
+
if not valid_asset:
|
|
251
|
+
raise CliError(f"BUGX_ASSET_ROOT 指向无效或不安全的资源目录: {asset_override}")
|
|
252
|
+
engine_override = os.environ.get("BUGX_GLOBAL_ENGINE_ROOT")
|
|
253
|
+
if engine_override is not None:
|
|
254
|
+
candidate = Path(engine_override).expanduser()
|
|
255
|
+
if not engine_override or not candidate.is_dir():
|
|
256
|
+
raise CliError(f"BUGX_GLOBAL_ENGINE_ROOT 指向不存在的引擎目录: {engine_override}")
|
|
257
|
+
asset = asset_root()
|
|
258
|
+
global_engine = global_engine_root()
|
|
259
|
+
if global_engine.is_dir() and not (global_engine / "launch_bugx.py").is_file():
|
|
260
|
+
print(
|
|
261
|
+
f"[bugx] 全局引擎目录 {global_engine} 缺失 launch_bugx.py,"
|
|
262
|
+
f"回落至 asset_root: {asset}",
|
|
263
|
+
file=sys.stderr,
|
|
264
|
+
)
|
|
265
|
+
candidates = []
|
|
266
|
+
for cand in (asset, global_engine):
|
|
267
|
+
if cand.is_dir() and (cand / "launch_bugx.py").is_file():
|
|
268
|
+
candidates.append(cand)
|
|
269
|
+
# 后插入者位于 sys.path[0],故按 (asset, global_engine) 顺序插入 ⇒
|
|
270
|
+
# 最终 global_engine 优先。契约见 `docs/03_ai/AI_REFERENCE.md`「副本升级门禁」:
|
|
271
|
+
# Python 导入必须优先 `global_engine_root()`(共享引擎是运行时真源),
|
|
272
|
+
# 仅在全局引擎缺失 launch_bugx.py 时才回落到 asset_root。
|
|
273
|
+
for cand in candidates:
|
|
274
|
+
s = str(cand)
|
|
275
|
+
while s in sys.path:
|
|
276
|
+
sys.path.remove(s)
|
|
277
|
+
sys.path.insert(0, s)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
# 宿主启动子进程时会通过环境变量指明工作区。MCP / 引擎入口若拿不到显式
|
|
281
|
+
# ``--root``,必须读它,而不是盲取 ``cwd``:桌面宿主的 cwd 往往是 ``/``,
|
|
282
|
+
# 盲取会把项目根解析成 ``/``、找不到 ``/.bugx``,于是 MCP 主通道每次在
|
|
283
|
+
# 0.2 秒内 ``exit=2``(日志还会落进 `sha256("/")[:16]` 那个目录)。
|
|
284
|
+
HOST_PROJECT_DIR_ENV_VARS: tuple[str, ...] = (
|
|
285
|
+
"BUGX_PROJECT_ROOT",
|
|
286
|
+
"CODEBUDDY_PROJECT_DIR",
|
|
287
|
+
"CLAUDE_PROJECT_DIR",
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def resolve_project_root(explicit: Path | None = None) -> Path:
|
|
292
|
+
"""解析项目根,绝不把"没给"静默等同于"就是 cwd"。
|
|
293
|
+
|
|
294
|
+
优先级:显式 ``--root`` → ``BUGX_PROJECT_ROOT`` → 宿主工作区环境变量 → ``cwd``。
|
|
295
|
+
环境变量仅在指向**真实存在的目录**时才被采纳,避免把幽灵路径当成项目根。
|
|
296
|
+
"""
|
|
297
|
+
if explicit is not None:
|
|
298
|
+
return Path(explicit)
|
|
299
|
+
for name in HOST_PROJECT_DIR_ENV_VARS:
|
|
300
|
+
if name not in os.environ:
|
|
301
|
+
continue
|
|
302
|
+
raw = os.environ[name]
|
|
303
|
+
if not raw.strip():
|
|
304
|
+
raise CliError(f"{name} 不能是空路径")
|
|
305
|
+
try:
|
|
306
|
+
candidate = Path(raw).expanduser()
|
|
307
|
+
except (OSError, RuntimeError, ValueError) as exc:
|
|
308
|
+
raise CliError(f"{name} 不是有效的项目目录路径: {raw}") from exc
|
|
309
|
+
if not candidate.is_dir():
|
|
310
|
+
raise CliError(f"{name} 指向不存在或非目录路径: {raw}")
|
|
311
|
+
return candidate
|
|
312
|
+
return Path.cwd()
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def _i18n_exc(key: str, fallback: str, locale: str | None = None, **kwargs: Any) -> str:
|
|
316
|
+
try:
|
|
317
|
+
_ensure_core_importable()
|
|
318
|
+
import core.i18n as i18n
|
|
319
|
+
return i18n.exception_text(key, locale=locale, fallback=fallback, **kwargs)
|
|
320
|
+
except Exception:
|
|
321
|
+
if not kwargs:
|
|
322
|
+
return fallback
|
|
323
|
+
try:
|
|
324
|
+
return fallback.format(**kwargs)
|
|
325
|
+
except Exception:
|
|
326
|
+
return fallback
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def _i18n_prompt(key: str, fallback: str, locale: str | None = None, **kwargs: Any) -> str:
|
|
330
|
+
try:
|
|
331
|
+
_ensure_core_importable()
|
|
332
|
+
import core.i18n as i18n
|
|
333
|
+
return i18n.prompt_text(key, locale=locale, fallback=fallback, **kwargs)
|
|
334
|
+
except Exception:
|
|
335
|
+
if not kwargs:
|
|
336
|
+
return fallback
|
|
337
|
+
try:
|
|
338
|
+
return fallback.format(**kwargs)
|
|
339
|
+
except Exception:
|
|
340
|
+
return fallback
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def _resolve_locale_name(locale: str | None = None) -> str:
|
|
344
|
+
if locale:
|
|
345
|
+
return locale
|
|
346
|
+
try:
|
|
347
|
+
_ensure_core_importable()
|
|
348
|
+
import core.i18n as i18n
|
|
349
|
+
return i18n.resolve_locale().resolved_locale
|
|
350
|
+
except Exception:
|
|
351
|
+
return "zh"
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def _rooted(root: Path, path: Path, *, allow_controlled_core: bool = False) -> Path:
|
|
357
|
+
"""Resolve and enforce that path is within the project root."""
|
|
358
|
+
root = root.resolve()
|
|
359
|
+
candidate = path if path.is_absolute() else root / path
|
|
360
|
+
resolved = candidate.resolve(strict=False)
|
|
361
|
+
try:
|
|
362
|
+
resolved.relative_to(root)
|
|
363
|
+
except ValueError as exc:
|
|
364
|
+
if allow_controlled_core and _controlled_core_resource(root, candidate, resolved):
|
|
365
|
+
return resolved
|
|
366
|
+
raise CliError(_i18n_exc("common.path_must_be_inside_root", f"路径必须位于项目根目录内: {path}", path=path)) from exc
|
|
367
|
+
return resolved
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def _seed_asset_in(source: Path, name: str) -> Path | None:
|
|
433
|
+
"""在引擎载荷内按**文件名**定位种子模板,找不到返回 ``None``。
|
|
434
|
+
|
|
435
|
+
种子模板已归档到 ``core/ledger/``(``bug-log.md`` / ``mistake-book.md``),
|
|
436
|
+
而这里曾经写的是 ``source / name``:文件搬进子包后该路径恒不存在,
|
|
437
|
+
``is_file()`` 恒假于是**静默跳过**——新项目永远没有
|
|
438
|
+
``.bugx/knowledge/bug-log.md``,而 ``init`` 依旧退出 0。
|
|
439
|
+
这是「文件归档进子包、消费方仍用扁平路径」缺陷族的又一例,改为按文件名
|
|
440
|
+
在载荷树内唯一解析,后续再搬目录也不需要改这里。同名多份时 fail-closed。
|
|
441
|
+
"""
|
|
442
|
+
direct = source / name
|
|
443
|
+
if direct.is_file() and not direct.is_symlink():
|
|
444
|
+
return direct
|
|
445
|
+
matches = [
|
|
446
|
+
path for path in _engine_basename_index(source).get(name, [])
|
|
447
|
+
if not path.is_symlink()
|
|
448
|
+
]
|
|
449
|
+
if len(matches) == 1:
|
|
450
|
+
return matches[0]
|
|
451
|
+
if len(matches) > 1:
|
|
452
|
+
listed = "、".join(str(path) for path in matches)
|
|
453
|
+
raise CliError(_i18n_exc(
|
|
454
|
+
"common.knowledge_seed_ambiguous",
|
|
455
|
+
f"引擎载荷中存在多个同名知识种子,拒绝猜测:{listed}", listed=listed,
|
|
456
|
+
))
|
|
457
|
+
return None
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
def _initialize_project_knowledge_snapshots(root: Path, source: Path) -> None:
|
|
461
|
+
"""Create project-owned human-readable knowledge snapshots once."""
|
|
462
|
+
layout = _layout_module(root).require(root)
|
|
463
|
+
for name, target in (
|
|
464
|
+
("bug-log.md", layout.bug_log),
|
|
465
|
+
("mistake-book.md", layout.mistake_book),
|
|
466
|
+
):
|
|
467
|
+
if target.is_symlink():
|
|
468
|
+
raise CliError(_i18n_exc("common.knowledge_snapshot_symlink_refused", f"项目知识快照不能是符号链接: {target}", target=target))
|
|
469
|
+
source_snapshot = _seed_asset_in(source, name)
|
|
470
|
+
if not target.exists() and source_snapshot is not None:
|
|
471
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
472
|
+
shutil.copy2(source_snapshot, target)
|
|
473
|
+
target.chmod(0o600)
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
def _logging_module(root: Path):
|
|
477
|
+
"""Load the versioned logger from the same asset source as the runtime."""
|
|
478
|
+
path = _script(root, "bugx_logging.py")
|
|
479
|
+
spec = importlib.util.spec_from_file_location("bugx_runtime_logging", path)
|
|
480
|
+
if spec is None or spec.loader is None:
|
|
481
|
+
raise CliError(_i18n_exc("common.logging_module_load_failed", f"无法加载 BugX 日日志模块: {path}", path=path))
|
|
482
|
+
module = importlib.util.module_from_spec(spec)
|
|
483
|
+
sys.modules[spec.name] = module
|
|
484
|
+
try:
|
|
485
|
+
spec.loader.exec_module(module)
|
|
486
|
+
except BaseException:
|
|
487
|
+
sys.modules.pop(spec.name, None)
|
|
488
|
+
raise
|
|
489
|
+
return module
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
def _configure_logging(root: Path, command: str, level: str | None = None,
|
|
493
|
+
trace_id: str | None = None):
|
|
494
|
+
try:
|
|
495
|
+
return _logging_module(root).configure(
|
|
496
|
+
root, command=command, level=level, trace_id=trace_id,
|
|
497
|
+
)
|
|
498
|
+
except (OSError, ValueError, CliError) as exc:
|
|
499
|
+
# Logging must never hide the command's real error or block a read-only
|
|
500
|
+
# discovery operation. The command still reports its normal result.
|
|
501
|
+
if (level or os.environ.get("BUGX_LOG_LEVEL", "")).upper() == "DEBUG":
|
|
502
|
+
print(f"[bugx] ! 诊断日志未启用: {exc}", file=sys.stderr)
|
|
503
|
+
return None
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
def diagnostic_log_path(root: Path) -> Path:
|
|
507
|
+
"""Return the diagnostic log path that logging actually writes to.
|
|
508
|
+
|
|
509
|
+
Writers and readers must agree: an initialized project keeps
|
|
510
|
+
``<root>/.bugx/logs/bugx.jsonl``, while an uninitialized directory is
|
|
511
|
+
logged to the per-user fallback (see ``bugx_logging.log_path``). Callers
|
|
512
|
+
that package or display the log must not re-derive the project path.
|
|
513
|
+
"""
|
|
514
|
+
return _logging_module(root).log_path(root)
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
def _log_update_event(root: Path, event: str, message: str = "", **fields: object) -> None:
|
|
518
|
+
"""Best-effort structured update diagnostics without logging full responses."""
|
|
519
|
+
import logging
|
|
520
|
+
|
|
521
|
+
logger = logging.getLogger("bugx")
|
|
522
|
+
if not any(getattr(handler, "_bugx_handler", False) for handler in logger.handlers):
|
|
523
|
+
return
|
|
524
|
+
try:
|
|
525
|
+
_logging_module(root).log_event(logger, event, message, **fields)
|
|
526
|
+
except (OSError, ValueError, CliError):
|
|
527
|
+
# Update diagnostics must never turn a network failure into a logging failure.
|
|
528
|
+
return
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
def _update_failure_fields(result: object) -> dict[str, object]:
|
|
532
|
+
"""Extract bounded, non-secret version-check failure metadata."""
|
|
533
|
+
data = getattr(result, "data", None)
|
|
534
|
+
if not isinstance(data, dict):
|
|
535
|
+
data = {}
|
|
536
|
+
nested = data.get("data") if isinstance(data.get("data"), dict) else {}
|
|
537
|
+
error = data.get("error") if isinstance(data.get("error"), dict) else {}
|
|
538
|
+
error_code = (
|
|
539
|
+
error.get("code") or data.get("error_code") or nested.get("error_code")
|
|
540
|
+
or data.get("code")
|
|
541
|
+
)
|
|
542
|
+
request_id = (
|
|
543
|
+
data.get("request_id") or data.get("requestId") or nested.get("request_id")
|
|
544
|
+
or nested.get("requestId")
|
|
545
|
+
)
|
|
546
|
+
message = getattr(result, "error", None) or data.get("message") or error.get("message")
|
|
547
|
+
return {
|
|
548
|
+
"http_status": getattr(result, "status", None),
|
|
549
|
+
"error_code": str(error_code)[:128] if error_code is not None else None,
|
|
550
|
+
"request_id": str(request_id)[:128] if request_id is not None else None,
|
|
551
|
+
"error_summary": str(message or "unknown error")[:512],
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
# 引擎把 ``help``/``-h``/``--help`` 一律当只读帮助视图
|
|
556
|
+
# (core/launch_phases/round_orchestrator.py「--help/help/-h 只读」契约)。
|
|
557
|
+
# CLI 与引擎共用这一份枚举,避免「帮助可读但日志已落盘」的静默漂移。
|
|
558
|
+
ENGINE_HELP_TOKENS = frozenset({"help", "-h", "--help"})
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
def _defer_command_logging_until_authorized(args: argparse.Namespace) -> bool:
|
|
562
|
+
"""Keep preview and rejected confirmation paths free of file writes.
|
|
563
|
+
|
|
564
|
+
The normal CLI logger writes ``command_started`` before dispatch. That is
|
|
565
|
+
useful for commands which are going to run, but it violates the contract
|
|
566
|
+
for a dry-run or an operation rejected solely because the user has not
|
|
567
|
+
confirmed it yet. Those paths must be observationally read-only, so do
|
|
568
|
+
not create/open the project log until authorization has succeeded.
|
|
569
|
+
"""
|
|
570
|
+
command = getattr(args, "command", None)
|
|
571
|
+
if command == "completion":
|
|
572
|
+
# Shell setup must be observationally read-only: emitting a script must
|
|
573
|
+
# not create a project log merely because it was run from a repository.
|
|
574
|
+
return True
|
|
575
|
+
if command == "reset":
|
|
576
|
+
return bool(getattr(args, "dry_run", False) or not getattr(args, "yes", False))
|
|
577
|
+
if command == "uninstall":
|
|
578
|
+
if getattr(args, "dry_run", False):
|
|
579
|
+
# Both project-level and --self previews are observational only;
|
|
580
|
+
# do not append command_started/command_finished to .bugx/logs.
|
|
581
|
+
return True
|
|
582
|
+
if getattr(args, "self", False):
|
|
583
|
+
# --self 处理的是用户级资源,不得因为 cwd 恰好是普通项目而
|
|
584
|
+
# 顺手创建项目级 .bugx/logs。卸载结果由 stdout/JSON 和外部
|
|
585
|
+
# 备份记录,不能把当前项目变成新的残留来源。
|
|
586
|
+
return True
|
|
587
|
+
if not getattr(args, "all", False) and not getattr(args, "agent"):
|
|
588
|
+
# 裸 uninstall 是引导/清单路径:必须观测只读(日志初始化会创建 .bugx)。
|
|
589
|
+
return True
|
|
590
|
+
dangerous = bool(
|
|
591
|
+
getattr(args, "purge_data", False)
|
|
592
|
+
or getattr(args, "purge_global_data", False)
|
|
593
|
+
)
|
|
594
|
+
return dangerous and not getattr(args, "yes", False)
|
|
595
|
+
if command == "plugin":
|
|
596
|
+
return (
|
|
597
|
+
getattr(args, "plugin_command", None) == "uninstall"
|
|
598
|
+
and not getattr(args, "yes", False)
|
|
599
|
+
)
|
|
600
|
+
if command == "engine":
|
|
601
|
+
forwarded = list(getattr(args, "engine_args", []) or [])
|
|
602
|
+
if forwarded and forwarded[0] == "--":
|
|
603
|
+
forwarded = forwarded[1:]
|
|
604
|
+
# 裸 ``bugx engine`` 会被 command_engine 默认成 status,是真实调度,
|
|
605
|
+
# 必须留日志;只有转发里出现帮助词时引擎才只打印帮助、不碰运行态。
|
|
606
|
+
return bool(forwarded) and any(
|
|
607
|
+
token in ENGINE_HELP_TOKENS for token in forwarded
|
|
608
|
+
)
|
|
609
|
+
return False
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
def _close_bugx_logging() -> None:
|
|
613
|
+
"""Close the active diagnostic file before a reset moves ``.bugx/logs``."""
|
|
614
|
+
import logging
|
|
615
|
+
|
|
616
|
+
logger = logging.getLogger("bugx")
|
|
617
|
+
for handler in list(logger.handlers):
|
|
618
|
+
try:
|
|
619
|
+
handler.close()
|
|
620
|
+
finally:
|
|
621
|
+
logger.removeHandler(handler)
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
def _ensure_project_readme(root: Path, source: Path) -> None:
|
|
625
|
+
target = root / ".bugx" / "README.md"
|
|
626
|
+
template = source / "project-layout.md"
|
|
627
|
+
if target.exists() or not template.is_file():
|
|
628
|
+
return
|
|
629
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
630
|
+
shutil.copy2(template, target)
|
|
631
|
+
target.chmod(0o600)
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
def _run_script(root: Path, name: str, arguments: list[str], timeout: float | None = None) -> int:
|
|
635
|
+
"""运行 core 脚本并透传退出码。
|
|
636
|
+
|
|
637
|
+
``timeout``(P3a):lesson/knowledge/probe/self-audit 类调用传 300 秒,
|
|
638
|
+
防止失控脚本永久挂起;mcp serve 与 mcp-runtime start 需要长驻/直通
|
|
639
|
+
stdio,保持 None(不设超时)。
|
|
640
|
+
"""
|
|
641
|
+
_ensure_core_importable()
|
|
642
|
+
try:
|
|
643
|
+
import core.bugx_paths as bugx_paths
|
|
644
|
+
for arg in arguments:
|
|
645
|
+
if isinstance(arg, str):
|
|
646
|
+
bugx_paths.assert_safe_command(arg, root=root)
|
|
647
|
+
except Exception as exc:
|
|
648
|
+
if "[FATAL_BLOCKED]" in str(exc):
|
|
649
|
+
raise CliError(str(exc)) from exc
|
|
650
|
+
command = [sys.executable, str(_script(root, name)), *arguments]
|
|
651
|
+
logger = _configure_logging(root, name, trace_id=_ACTIVE_TRACE_ID)
|
|
652
|
+
logging_module = _logging_module(root) if logger is not None else None
|
|
653
|
+
if logger is not None and logging_module is not None:
|
|
654
|
+
logging_module.log_event(logger, "core_script_started", script=name)
|
|
655
|
+
try:
|
|
656
|
+
environment = _python_environment()
|
|
657
|
+
if logger is not None and logging_module is not None:
|
|
658
|
+
context = logging_module.get_context(logger)
|
|
659
|
+
environment.update({
|
|
660
|
+
"BUGX_TRACE_ID": str(context["trace_id"]),
|
|
661
|
+
**({"BUGX_RUN_ID": str(context["run_id"])}
|
|
662
|
+
if context.get("run_id") else {}),
|
|
663
|
+
**({"BUGX_LIFECYCLE_ID": str(context["lifecycle_id"])}
|
|
664
|
+
if context.get("lifecycle_id") else {}),
|
|
665
|
+
**({"BUGX_ROUND": str(context["round"])}
|
|
666
|
+
if context.get("round") is not None else {}),
|
|
667
|
+
**({"BUGX_WORKER_ID": str(context["worker_id"])}
|
|
668
|
+
if context.get("worker_id") else {}),
|
|
669
|
+
})
|
|
670
|
+
result = subprocess.call(
|
|
671
|
+
command, cwd=root.resolve(), env=environment, timeout=timeout,
|
|
672
|
+
)
|
|
673
|
+
if logger is not None and logging_module is not None:
|
|
674
|
+
logging_module.log_event(logger, "core_script_finished", script=name,
|
|
675
|
+
exit_code=result)
|
|
676
|
+
return result
|
|
677
|
+
except subprocess.TimeoutExpired as exc:
|
|
678
|
+
if logger is not None and logging_module is not None:
|
|
679
|
+
logging_module.log_event(logger, "core_script_failed", str(exc),
|
|
680
|
+
level=40, script=name, exc_info=True)
|
|
681
|
+
raise CliError(_i18n_exc("common.script_execution_timeout", f"脚本执行超时(>{timeout}s): {name}", timeout=timeout, name=name)) from exc
|
|
682
|
+
except OSError as exc:
|
|
683
|
+
if logger is not None and logging_module is not None:
|
|
684
|
+
logging_module.log_event(logger, "core_script_failed", str(exc),
|
|
685
|
+
level=40, script=name, exc_info=True)
|
|
686
|
+
raise CliError(_i18n_exc("common.script_run_failed", f"无法运行 {name}: {exc}", name=name, exc=exc)) from exc
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
def _run_script_json(
|
|
690
|
+
root: Path, name: str, arguments: list[str], timeout: float | None = 300.0,
|
|
691
|
+
) -> dict | None:
|
|
692
|
+
"""运行 core 脚本并解析其 stdout 的 JSON(不流式输出)。
|
|
693
|
+
|
|
694
|
+
与 ``_run_script`` 共用安全校验与 Python 环境;脚本崩溃、超时或输出非 JSON 时
|
|
695
|
+
返回 ``None``(由调用方决定降级还是报错),保证子进程噪声不混进 UI。
|
|
696
|
+
"""
|
|
697
|
+
_ensure_core_importable()
|
|
698
|
+
try:
|
|
699
|
+
import core.bugx_paths as bugx_paths
|
|
700
|
+
for arg in arguments:
|
|
701
|
+
if isinstance(arg, str):
|
|
702
|
+
bugx_paths.assert_safe_command(arg, root=root)
|
|
703
|
+
except Exception as exc: # noqa: BLE001
|
|
704
|
+
if "[FATAL_BLOCKED]" in str(exc):
|
|
705
|
+
raise CliError(str(exc)) from exc
|
|
706
|
+
command = [sys.executable, str(_script(root, name)), *arguments]
|
|
707
|
+
try:
|
|
708
|
+
result = subprocess.run(
|
|
709
|
+
command, cwd=root.resolve(), env=_python_environment(),
|
|
710
|
+
capture_output=True, text=True, timeout=timeout, check=False,
|
|
711
|
+
)
|
|
712
|
+
except (OSError, subprocess.SubprocessError):
|
|
713
|
+
return None
|
|
714
|
+
if result.returncode != 0:
|
|
715
|
+
return None
|
|
716
|
+
payload = (result.stdout or "").strip()
|
|
717
|
+
if not payload:
|
|
718
|
+
return None
|
|
719
|
+
try:
|
|
720
|
+
parsed = json.loads(payload)
|
|
721
|
+
except ValueError:
|
|
722
|
+
return None
|
|
723
|
+
return parsed if isinstance(parsed, dict) else None
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
def _python_environment(overrides: dict[str, str] | None = None) -> dict[str, str]:
|
|
727
|
+
"""Return the CLI environment for Python core scripts.
|
|
728
|
+
|
|
729
|
+
Core scripts are executed from the global engine (or the bundled checkout
|
|
730
|
+
asset during development). The project contains state only, so Python's
|
|
731
|
+
bytecode cache must never be used as an implicit project code layer.
|
|
732
|
+
|
|
733
|
+
``overrides`` lets callers pin project-scoped env vars (e.g.
|
|
734
|
+
``BUGX_PROJECT_ROOT``) that the core scripts resolve relative to ``cwd``.
|
|
735
|
+
"""
|
|
736
|
+
environment = os.environ.copy()
|
|
737
|
+
entries = [item for item in environment.get("PATH", "").split(os.pathsep) if item]
|
|
738
|
+
candidates = [environment.get("BUGX_TOOL_PATH", "")]
|
|
739
|
+
if os.name != "nt":
|
|
740
|
+
candidates.extend((
|
|
741
|
+
"/opt/homebrew/bin", "/usr/local/bin",
|
|
742
|
+
"/home/linuxbrew/.linuxbrew/bin",
|
|
743
|
+
str(Path.home() / ".local" / "bin"),
|
|
744
|
+
str(Path.home() / ".cargo" / "bin"),
|
|
745
|
+
))
|
|
746
|
+
for candidate in candidates:
|
|
747
|
+
if candidate and candidate not in entries:
|
|
748
|
+
try:
|
|
749
|
+
if Path(candidate).is_dir():
|
|
750
|
+
entries.append(candidate)
|
|
751
|
+
except OSError:
|
|
752
|
+
continue
|
|
753
|
+
environment["PATH"] = os.pathsep.join(entries)
|
|
754
|
+
environment["PYTHONDONTWRITEBYTECODE"] = "1"
|
|
755
|
+
if "BUGX_PYTHON" not in environment and sys.executable:
|
|
756
|
+
environment["BUGX_PYTHON"] = sys.executable
|
|
757
|
+
if overrides:
|
|
758
|
+
environment.update(overrides)
|
|
759
|
+
return environment
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
@contextmanager
|
|
763
|
+
def _cli_version_environment():
|
|
764
|
+
"""Expose this source CLI version to child processes without leaking it to callers."""
|
|
765
|
+
previous = os.environ.get("BUGX_CLI_VERSION")
|
|
766
|
+
os.environ.setdefault("BUGX_CLI_VERSION", __version__)
|
|
767
|
+
try:
|
|
768
|
+
yield
|
|
769
|
+
finally:
|
|
770
|
+
if previous is None:
|
|
771
|
+
os.environ.pop("BUGX_CLI_VERSION", None)
|
|
772
|
+
else:
|
|
773
|
+
os.environ["BUGX_CLI_VERSION"] = previous
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
def _is_bugx_source_repo(root: Path) -> bool:
|
|
825
|
+
"""Check if the given root directory is the BugX development source repository.
|
|
826
|
+
|
|
827
|
+
委托给 ``core.bugx_paths`` 的权威实现:判定同时被全局项目注册表守卫使用,
|
|
828
|
+
两处各写一份必然漂移(本仓反复出现的缺陷族)。
|
|
829
|
+
"""
|
|
830
|
+
from core.bugx_paths import is_bugx_source_repo
|
|
831
|
+
return is_bugx_source_repo(root)
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
def _resolve_plugin_version(root: Path, default_version: str = __version__) -> str:
|
|
835
|
+
"""Resolve plugin version: in BugX dev repo, use repo baseline to avoid declaration drift."""
|
|
836
|
+
if _is_bugx_source_repo(root):
|
|
837
|
+
version_file = root / "VERSION"
|
|
838
|
+
if version_file.is_file():
|
|
839
|
+
try:
|
|
840
|
+
v = version_file.read_text(encoding="utf-8").strip()
|
|
841
|
+
if v:
|
|
842
|
+
return v
|
|
843
|
+
except OSError:
|
|
844
|
+
pass
|
|
845
|
+
return default_version
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
def get_build_id() -> int | None:
|
|
849
|
+
"""获取当前 Build ID(整型正整数,DOC-169)。"""
|
|
850
|
+
env_id = os.environ.get("BUGX_BUILD_ID")
|
|
851
|
+
if env_id is not None and re.fullmatch(r"[0-9]+", env_id) is None:
|
|
852
|
+
raise CliError("BUGX_BUILD_ID 必须仅包含十进制数字")
|
|
853
|
+
env_value: int | None = None
|
|
854
|
+
if env_id is not None:
|
|
855
|
+
try:
|
|
856
|
+
env_value = int(env_id)
|
|
857
|
+
except ValueError as exc:
|
|
858
|
+
raise CliError("BUGX_BUILD_ID 超出支持的整数范围") from exc
|
|
859
|
+
if env_value < 1:
|
|
860
|
+
raise CliError("BUGX_BUILD_ID 必须是正整数")
|
|
861
|
+
build_id = getattr(bugx_cli, "__build_id__", None)
|
|
862
|
+
if isinstance(build_id, int) and not isinstance(build_id, bool) and build_id >= 1:
|
|
863
|
+
return build_id
|
|
864
|
+
if env_value is not None:
|
|
865
|
+
return env_value
|
|
866
|
+
try:
|
|
867
|
+
from bugx_cli.infra.engine_installer import asset_root
|
|
868
|
+
meta = asset_root() / "metadata.txt"
|
|
869
|
+
if meta.is_file():
|
|
870
|
+
content = meta.read_text(encoding="utf-8")
|
|
871
|
+
match = re.search(r"^build_id:\s*(\d+)", content, re.M)
|
|
872
|
+
if match:
|
|
873
|
+
return int(match.group(1))
|
|
874
|
+
except Exception:
|
|
875
|
+
pass
|
|
876
|
+
try:
|
|
877
|
+
from bugx_cli.infra.engine_installer import global_engine_root
|
|
878
|
+
meta = global_engine_root() / "metadata.txt"
|
|
879
|
+
if meta.is_file():
|
|
880
|
+
content = meta.read_text(encoding="utf-8")
|
|
881
|
+
match = re.search(r"^build_id:\s*(\d+)", content, re.M)
|
|
882
|
+
if match:
|
|
883
|
+
return int(match.group(1))
|
|
884
|
+
except Exception:
|
|
885
|
+
pass
|
|
886
|
+
return None
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
def get_full_version() -> str:
|
|
890
|
+
"""返回标准版本与 Build ID 组合字符串,例如 1.0.0+build.4。"""
|
|
891
|
+
bid = get_build_id()
|
|
892
|
+
if bid is not None:
|
|
893
|
+
return f"{__version__}+build.{bid}"
|
|
894
|
+
return __version__
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
# 显式导出全部公有与内部辅助符号,支持模块化子命令透明引用
|
|
898
|
+
__all__ = [name for name in list(globals().keys()) if not (name.startswith("__") and name.endswith("__"))]
|