bugx-cli 0.1.0 → 0.1.1

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.
Files changed (311) hide show
  1. package/README.md +190 -186
  2. package/core/README.md +2 -2
  3. package/core/agent/README.md +2 -1
  4. package/core/agent/agent_artifacts.py +8 -6
  5. package/core/agent/agent_eval.py +136 -54
  6. package/core/agent/agent_execution.py +218 -52
  7. package/core/agent/agent_orchestrator.py +14 -8
  8. package/core/agent/agent_targets.py +8 -2
  9. package/core/agent/feature_baseline.py +150 -0
  10. package/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
  11. package/core/assets/axe-core/LICENSE.txt +362 -0
  12. package/core/assets/axe-core/UPSTREAM.md +10 -0
  13. package/core/assets/axe-core/axe.min.js +12 -0
  14. package/core/assets/bugx-hero-en.svg +74 -0
  15. package/core/assets/bugx-hero-zh.svg +74 -0
  16. package/core/assets/codex.png +0 -0
  17. package/core/assets/dsh.png +0 -0
  18. package/core/assets/webui-chatgpt.jpg +0 -0
  19. package/core/assets/webui-session.jpg +0 -0
  20. package/core/assets/webui-skills.jpg +0 -0
  21. package/core/assets/webui-studio.jpg +0 -0
  22. package/core/assets/webui-zcode.jpg +0 -0
  23. package/core/assets/zcode.png +0 -0
  24. package/core/autonomous_cve/SPEC.md +1 -1
  25. package/core/autonomous_cve/attack_graph_store.py +152 -106
  26. package/core/autonomous_cve/behavior_graph.py +8 -2
  27. package/core/autonomous_cve/verifier.py +4 -1
  28. package/core/bugx.md +1 -1
  29. package/core/bugx_paths.py +43 -8
  30. package/core/cli-help.txt +66 -0
  31. package/core/cloud_sync/SPEC.md +1 -1
  32. package/core/cloud_sync/cloud_client.py +25 -6
  33. package/core/cloud_sync/cloud_onboard.py +42 -1
  34. package/core/cloud_sync/flywheel_client.py +16 -7
  35. package/core/cloud_sync/network_transport.py +24 -3
  36. package/core/cloud_sync/sensitive_filter.py +2 -2
  37. package/core/cloud_sync/sync_push.py +12 -10
  38. package/core/contracts/AGENT_GUIDE.md +6 -9
  39. package/core/contracts/README.md +2 -2
  40. package/core/contracts/bugx-runtime-contract.md +1 -1
  41. package/core/contracts/bugx-worker.md +1 -1
  42. package/core/contracts/engine_gap_contracts.py +86 -3
  43. package/core/coverage/coverage_discovery.py +599 -29
  44. package/core/coverage/coverage_evidence.py +47 -0
  45. package/core/coverage/coverage_forensics.py +9 -0
  46. package/core/coverage/coverage_validate.py +6 -1
  47. package/core/dev_harness/SPEC.md +1 -1
  48. package/core/engine-integrity.json +591 -419
  49. package/core/fuzzing/concurrency_fuzzer.py +53 -0
  50. package/core/fuzzing/differential_oracle.py +562 -27
  51. package/core/fuzzing/fuzz_input.py +109 -6
  52. package/core/fuzzing/stateful_fuzzer.py +72 -0
  53. package/core/governance/secret_redactor.py +22 -10
  54. package/core/host_acp/SPEC.md +1 -1
  55. package/core/host_acp/__init__.py +4 -4
  56. package/core/host_acp/claude.py +59 -1
  57. package/core/host_acp/cline.py +64 -1
  58. package/core/host_acp/codex.py +56 -1
  59. package/core/host_acp/dsh.py +59 -1
  60. package/core/host_acp/opencode.py +56 -1
  61. package/core/host_acp/pi.py +59 -1
  62. package/core/host_acp/zcode.py +59 -1
  63. package/core/host_runtime/SPEC.md +1 -1
  64. package/core/host_runtime/adapters.py +1 -1
  65. package/core/host_runtime/cline.py +13 -0
  66. package/core/host_runtime/host_evaluators.py +44 -4
  67. package/core/host_runtime/host_probe.py +1 -1
  68. package/core/host_runtime/host_provider_arbitrator.py +116 -62
  69. package/core/host_runtime/host_registry.py +15 -8
  70. package/core/host_runtime/mcp_registry_gate.py +12 -1
  71. package/core/host_runtime/pi.py +102 -0
  72. package/core/host_runtime/provider_facts.py +66 -0
  73. package/core/hosts/SPEC.md +1 -1
  74. package/core/hosts/__init__.py +6 -2
  75. package/core/hosts/_dsh_usage.py +1 -1
  76. package/core/hosts/base.py +32 -4
  77. package/core/hosts/claude.py +55 -0
  78. package/core/hosts/cline.py +6 -2
  79. package/core/hosts/codex.py +58 -0
  80. package/core/hosts/dsh.py +9 -1
  81. package/core/hosts/opencode.py +6 -6
  82. package/core/hosts/pi.py +159 -2
  83. package/core/infra/README.md +4 -2
  84. package/core/infra/__init__.py +2 -0
  85. package/core/infra/build_info.py +22 -3
  86. package/core/infra/client_metadata.py +1 -1
  87. package/core/infra/json_utils.py +22 -0
  88. package/core/launch_phases/README.md +2 -2
  89. package/core/launch_phases/SPEC.md +1 -1
  90. package/core/launch_phases/common.py +21 -2
  91. package/core/launch_phases/finding_confirm_phase.py +5 -1
  92. package/core/launch_phases/finding_settlement.py +188 -1
  93. package/core/launch_phases/judge_phase.py +69 -12
  94. package/core/launch_phases/orchestrator_controls.py +11 -7
  95. package/core/launch_phases/post_coverage_sync.py +9 -2
  96. package/core/launch_phases/post_phase.py +139 -3
  97. package/core/launch_phases/post_receipt.py +12 -1
  98. package/core/launch_phases/pre_phase.py +3 -3
  99. package/core/launch_phases/pre_recon_scout.py +53 -36
  100. package/core/launch_phases/pre_state_builder.py +23 -176
  101. package/core/launch_phases/round_orchestrator.py +15 -32
  102. package/core/launch_phases/session_runtime.py +56 -9
  103. package/core/launch_phases/startup_gates.py +36 -8
  104. package/core/launch_phases/startup_interaction.py +68 -12
  105. package/core/launch_phases/startup_version_gate.py +9 -3
  106. package/core/launch_phases/supervisor_bridge.py +46 -17
  107. package/core/launch_phases/supervisor_coverage.py +8 -2
  108. package/core/launch_phases/supervisor_degraded.py +1 -9
  109. package/core/launch_phases/worker_barriers.py +15 -5
  110. package/core/launch_phases/worker_orchestrator.py +105 -25
  111. package/core/ledger/README.md +1 -1
  112. package/core/ledger/SPEC.md +1 -1
  113. package/core/ledger/_facade.py +2 -1
  114. package/core/ledger/archive_ops.py +60 -2
  115. package/core/ledger/cli.py +6 -1
  116. package/core/ledger/export_ops.py +6 -1
  117. package/core/ledger/finding_confirmation.py +48 -6
  118. package/core/ledger/finding_lifecycle.py +428 -5
  119. package/core/ledger/finding_verification.py +44 -8
  120. package/core/ledger/incidents.py +10 -4
  121. package/core/ledger/patterns.py +10 -7
  122. package/core/ledger/receipt_contract.py +17 -1
  123. package/core/ledger/sync_ops.py +21 -16
  124. package/core/ledger/tool_experience.py +2 -1
  125. package/core/ledger/verify_life.py +88 -17
  126. package/core/locales/en-US.json +2 -2
  127. package/core/locales/zh-CN.json +2 -2
  128. package/core/mcp_handlers/SPEC.md +1 -1
  129. package/core/mcp_handlers/base.py +23 -3
  130. package/core/mcp_handlers/channel_lifecycle.py +85 -30
  131. package/core/mcp_handlers/retrieval_handlers.py +11 -1
  132. package/core/mcp_handlers/rpc_server.py +6 -1
  133. package/core/mcp_handlers/supervisor_handlers.py +32 -6
  134. package/core/mcp_handlers/tool_table.py +15 -0
  135. package/core/mcp_runtime_support/environment.py +0 -38
  136. package/core/mcp_runtime_support/verifier.py +0 -52
  137. package/core/metadata.txt +2 -3
  138. package/core/planning/README.md +1 -1
  139. package/core/planning/domain_router.py +4 -2
  140. package/core/planning/dynamic_flow_analyzer.py +219 -14
  141. package/core/planning/judge_pipeline.py +87 -4
  142. package/core/planning/prompt_harness.py +7 -5
  143. package/core/planning/spec_harvester.py +4 -4
  144. package/core/probes/INTERFACE.md +11 -1
  145. package/core/probes/SPEC.md +11 -1
  146. package/core/probes/__init__.py +46 -40
  147. package/core/probes/android_probe.py +177 -9
  148. package/core/probes/codebase_memory_probe.py +57 -0
  149. package/core/probes/desktop_probe.py +104 -0
  150. package/core/probes/differential_probe.py +99 -21
  151. package/core/probes/efficiency_probe.py +64 -0
  152. package/core/probes/ios_binary_probe.py +105 -1
  153. package/core/probes/memory_probe.py +66 -0
  154. package/core/probes/miniprogram_probe.py +75 -13
  155. package/core/probes/mobile_probe.py +215 -30
  156. package/core/probes/native_probe.py +88 -0
  157. package/core/probes/openwiki_probe.py +70 -0
  158. package/core/probes/pattern_probe.py +106 -0
  159. package/core/probes/platform_probe.py +81 -0
  160. package/core/probes/probe_registry.py +108 -7
  161. package/core/probes/sast_fixture_corpus.py +340 -0
  162. package/core/probes/sast_probe.py +553 -52
  163. package/core/probes/sast_rules.py +668 -28
  164. package/core/probes/sca_scanner.py +48 -0
  165. package/core/probes/ui_accessibility.py +149 -0
  166. package/core/probes/ui_audit.py +513 -0
  167. package/core/probes/ui_contract.py +273 -0
  168. package/core/probes/ui_evidence.py +212 -0
  169. package/core/probes/ui_measurements.py +314 -0
  170. package/core/probes/ui_repair.py +250 -0
  171. package/core/probes/ui_review.py +133 -0
  172. package/core/probes/ui_storybook.py +107 -0
  173. package/core/probes/ui_tokens.py +185 -0
  174. package/core/probes/ui_visual_diff.py +131 -0
  175. package/core/probes/web_probe.py +373 -18
  176. package/core/project_profiler/SPEC.md +1 -1
  177. package/core/project_profiler/arbitrator.py +6 -1
  178. package/core/project_profiler/detector.py +8 -1
  179. package/core/project_profiler/strategy.py +51 -15
  180. package/core/prompts/command_routing_en.md +2 -2
  181. package/core/prompts/command_routing_zh.md +2 -2
  182. package/core/prompts/stages/stage_repair.md +1 -1
  183. package/core/repair/README.md +1 -1
  184. package/core/repair/l7_repair_loop.py +1 -4
  185. package/core/repair/rsi_fixer.py +4 -4
  186. package/core/repair/rsi_loop.py +1 -3
  187. package/core/repair/rsi_repair.py +7 -7
  188. package/core/repair/rsi_scope.py +27 -8
  189. package/core/report_engine/SPEC.md +1 -1
  190. package/core/report_engine/attestation.py +8 -4
  191. package/core/report_engine/finding_report.py +2 -1
  192. package/core/report_engine/models.py +7 -9
  193. package/core/report_engine/sast_bridge.py +2 -2
  194. package/core/report_engine/server.py +18 -8
  195. package/core/report_engine/web-conformance.md +123 -18
  196. package/core/report_engine/web_conformance.py +21 -52
  197. package/core/retrieval/README.md +1 -1
  198. package/core/retrieval/SPEC.md +1 -1
  199. package/core/retrieval/code_analyzer.py +50 -14
  200. package/core/retrieval/context_assembler.py +7 -1
  201. package/core/retrieval/knowledge_sync.py +108 -14
  202. package/core/retrieval/symbol_index.py +25 -6
  203. package/core/retrieval/universal_code_matcher.py +234 -49
  204. package/core/runtime/README.md +1 -1
  205. package/core/runtime/bugx_logging.py +78 -7
  206. package/core/runtime/fixture_solidify.py +5 -10
  207. package/core/runtime/incident_eval.py +1 -1
  208. package/core/runtime/model_runner.py +4 -41
  209. package/core/runtime/platform_adapter.py +2 -2
  210. package/core/runtime/prep_validate.py +4 -2
  211. package/core/runtime/project_settings.py +2 -1
  212. package/core/runtime/scenario_eval.py +50 -8
  213. package/core/skills/bugx_docs_mcp_server.py +3 -1
  214. package/core/skills/bugx_mcp_server.py +29 -2
  215. package/core/skills/tools_kb.py +1 -1
  216. package/core/supervisor/README.md +1 -1
  217. package/core/supervisor/SPEC.md +1 -1
  218. package/core/supervisor/budget_governor.py +503 -9
  219. package/core/supervisor/checkpoint_pipeline.py +248 -6
  220. package/core/supervisor/checkpoint_sync.py +13 -0
  221. package/core/supervisor/claim_events.py +1 -1
  222. package/core/supervisor/finding_workflow.py +22 -5
  223. package/core/supervisor/lease_manager.py +1 -1
  224. package/core/supervisor/lifecycle_blocks.py +6 -1
  225. package/core/supervisor/rejection_remedies.py +52 -5
  226. package/core/supervisor/serial_authorization.py +48 -4
  227. package/core/supervisor/task_scheduler.py +2 -2
  228. package/core/supervisor/worker_checkpoint.py +8 -1
  229. package/core/supervisor/worker_runtime.py +8 -2
  230. package/core/supervisor_types/worker_claim.py +9 -0
  231. package/core/webui/README.md +1 -1
  232. package/core/webui/SPEC.md +2 -1
  233. package/core/webui/adapters/claude.py +5 -1
  234. package/core/webui/adapters/cline.py +10 -2
  235. package/core/webui/adapters/codex.py +5 -1
  236. package/core/webui/adapters/dsh.py +5 -1
  237. package/core/webui/docs_session_service.py +2 -2
  238. package/core/webui/mcp_inspector.py +11 -7
  239. package/core/webui/static/00-base.css +1060 -0
  240. package/core/webui/static/01-monitoring.css +802 -0
  241. package/core/webui/static/02-header-actions.css +321 -0
  242. package/core/webui/static/03-trigger-popover.css +697 -0
  243. package/core/webui/static/04-composer.css +628 -0
  244. package/core/webui/static/05-skills-center.css +878 -0
  245. package/core/webui/static/06-mcp-center.css +623 -0
  246. package/core/webui/static/07-skill-detail.css +265 -0
  247. package/core/webui/static/08-files-management.css +167 -0
  248. package/core/webui/static/09-files-center.css +386 -0
  249. package/core/webui/static/10-icons.css +105 -0
  250. package/core/webui/static/11-project-options.css +185 -0
  251. package/core/webui/static/12-profile-tab.css +383 -0
  252. package/core/webui/static/design-tokens.css +113 -0
  253. package/core/webui/static/index.html +14 -1
  254. package/core/webui/workspace_service.py +1 -1
  255. package/docs/07_distribution/01_README_NPM.md +190 -186
  256. package/ecosystem/integrations/README.md +1 -1
  257. package/ecosystem/integrations/dsh/mcp/package.json +1 -1
  258. package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
  259. package/ecosystem/integrations/dsh/ui/package.json +1 -1
  260. package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
  261. package/ecosystem/integrations/opencode/mcp-lock.json +14 -6
  262. package/ecosystem/integrations/opencode/opencode.json +23 -12
  263. package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
  264. package/ecosystem/integrations/qoder/connector-meta.json +1 -1
  265. package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
  266. package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
  267. package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
  268. package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
  269. package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
  270. package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
  271. package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
  272. package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
  273. package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +1 -1
  274. package/interfaces/bin/bugx.js +37 -0
  275. package/interfaces/cli/bugx_cli/__init__.py +4 -2
  276. package/interfaces/cli/bugx_cli/cli.py +11 -4
  277. package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
  278. package/interfaces/cli/bugx_cli/commands/agent.py +339 -73
  279. package/interfaces/cli/bugx_cli/commands/audit.py +2 -2
  280. package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
  281. package/interfaces/cli/bugx_cli/commands/cloud.py +4 -3
  282. package/interfaces/cli/bugx_cli/commands/doctor.py +449 -204
  283. package/interfaces/cli/bugx_cli/commands/interaction.py +5 -1
  284. package/interfaces/cli/bugx_cli/commands/knowledge.py +2 -0
  285. package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
  286. package/interfaces/cli/bugx_cli/commands/plugin.py +55 -20
  287. package/interfaces/cli/bugx_cli/commands/plugin_claude.py +7 -7
  288. package/interfaces/cli/bugx_cli/commands/plugin_funide.py +2 -1
  289. package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +1 -1
  290. package/interfaces/cli/bugx_cli/commands/report.py +2 -6
  291. package/interfaces/cli/bugx_cli/commands/system.py +11 -11
  292. package/interfaces/cli/bugx_cli/common.py +15 -7
  293. package/interfaces/cli/bugx_cli/host_adapters.py +29 -54
  294. package/interfaces/cli/bugx_cli/hosts/registry.py +8 -6
  295. package/interfaces/cli/bugx_cli/infra/ai_advisor.py +157 -27
  296. package/interfaces/cli/bugx_cli/infra/engine_installer.py +18 -10
  297. package/interfaces/cli/bugx_cli/infra/host_sync.py +11 -8
  298. package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +76 -5
  299. package/interfaces/cli/bugx_cli/infra/security.py +13 -6
  300. package/package.json +2 -1
  301. package/pyproject.toml +20 -8
  302. package/scripts/ensure-python.mjs +7 -7
  303. package/scripts/sync-version.mjs +10 -21
  304. package/scripts/test-npm-wrapper.mjs +1 -1
  305. package/core/webui/static/project-settings.css +0 -6458
  306. package/docs/07_distribution/README.md +0 -16
  307. package/docs/README.md +0 -121
  308. package/interfaces/README.md +0 -143
  309. package/interfaces/bin/README.md +0 -35
  310. package/interfaces/cli/README.md +0 -90
  311. package/scripts/README.md +0 -118
@@ -20,7 +20,7 @@ import sys
20
20
  import time
21
21
  from dataclasses import dataclass, field
22
22
  from pathlib import Path
23
- from typing import Any, Mapping
23
+ from typing import Any, Iterable, Mapping
24
24
 
25
25
  from .. import __version__
26
26
 
@@ -54,17 +54,15 @@ COMMAND_CAPABILITIES: dict[str, dict[str, Any]] = {
54
54
  "description": "启动全自动无人值守 BugX 漏洞挖掘",
55
55
  "keywords": ["自主", "无人值守", "自动挖掘", "挂机", "探索", "autonomous", "mine", "auto"],
56
56
  },
57
- "analyze": {
58
- "description": "项目画像深度分析与代码覆盖度全景扫描",
59
- "keywords": ["画像", "分析", "覆盖度", "项目全景", "技术栈", "analyze", "profile", "coverage"],
60
- },
61
57
  "project": {
62
58
  "description": "项目元数据管理、画像展示与云端同步",
63
- "keywords": ["项目", "元数据", "云同步", "project", "sync"],
59
+ "keywords": ["项目", "元数据", "云同步", "project", "sync",
60
+ "画像", "分析", "覆盖度", "项目全景", "技术栈",
61
+ "analyze", "profile", "coverage"],
64
62
  },
65
- "patch": {
66
- "description": "补丁合成、验证、对抗与自动应用",
67
- "keywords": ["补丁", "修复代码", "修bug", "合成", "patch", "repair-code"],
63
+ "patch-forge": {
64
+ "description": "生成或静态校验补丁包(不执行包内代码、不提交远端)",
65
+ "keywords": ["补丁", "补丁包", "修复代码", "修bug", "合成", "patch", "patch-forge", "repair-code"],
68
66
  },
69
67
  "skill": {
70
68
  "description": "BugX 动态扩展 Skill 市场管理与挂载",
@@ -98,6 +96,102 @@ COMMAND_CAPABILITIES: dict[str, dict[str, Any]] = {
98
96
  "description": "重置项目运行态或全局错题集缓存",
99
97
  "keywords": ["重置", "清空", "还原", "reset", "clear"],
100
98
  },
99
+ "completion": {
100
+ "description": "输出 Bash、Zsh 或 Fish 的 Tab 补全脚本",
101
+ "keywords": ["补全", "tab补全", "shell补全", "completion", "bash", "zsh", "fish"],
102
+ },
103
+ "dsh": {
104
+ "description": "兼容启动器:为首个 Web Session 绑定项目并启动 DeepSeek Harness",
105
+ "keywords": ["deepseek", "harness", "web-session", "绑定项目"],
106
+ },
107
+ "mcp": {
108
+ "description": "启动本地 MCP Supervisor(不执行 worker 命令)",
109
+ "keywords": ["mcp", "本地mcp", "mcp supervisor"],
110
+ },
111
+ "capability": {
112
+ "description": "探查项目形态并装配能力:plan(只读)/ install(装齐所需 MCP 运行时)",
113
+ "keywords": ["能力", "装配", "探查形态", "capability"],
114
+ },
115
+ "mcp-runtime": {
116
+ "description": "lock-hash 专用离线 MCP runtime:install/verify/start/rollback",
117
+ "keywords": ["mcp-runtime", "runtime", "离线mcp", "lock-hash"],
118
+ },
119
+ "lesson": {
120
+ "description": "管理项目级结构化错题集",
121
+ "keywords": ["错题", "错题集", "lesson", "教训"],
122
+ },
123
+ "logic-analysis": {
124
+ "description": "校验或绑定意图、逻辑链、Oracle 与证据包",
125
+ "keywords": ["逻辑链", "oracle", "证据包", "logic-analysis"],
126
+ },
127
+ "probe": {
128
+ "description": "运行 core 探针(efficiency/sast/mobile 等),透传其参数",
129
+ "keywords": ["探针", "probe", "efficiency", "sast", "mobile"],
130
+ },
131
+ "knowledge": {
132
+ "description": "治理项目候选与用户全局错题集(不自动同步)",
133
+ "keywords": ["知识", "知识库", "knowledge", "候选"],
134
+ },
135
+ "self-audit": {
136
+ "description": "对 BugX 本地 CLI/MCP 只读入口做自举动态审计",
137
+ "keywords": ["自审", "自举", "self-audit", "元审计"],
138
+ },
139
+ "telemetry": {
140
+ "description": "查看或导出单向飞轮取证数据",
141
+ "keywords": ["遥测", "飞轮", "telemetry", "取证数据"],
142
+ },
143
+ "config": {
144
+ "description": "设置本地 BugX 隐私与遥测配置",
145
+ "keywords": ["配置", "设置", "config", "隐私"],
146
+ },
147
+ "goal": {
148
+ "description": "目标导向无人值守自治挖掘与长程自愈循环",
149
+ "keywords": ["目标", "goal", "长程", "自愈循环"],
150
+ },
151
+ "supervisor": {
152
+ "description": "本地监督 MCP:install / status / rpc;带外动作:reset-budget / recover / rebind-target / gate / findings",
153
+ "keywords": ["监督", "监工", "supervisor", "监督mcp"],
154
+ },
155
+ "plugin": {
156
+ "description": "安装、校验或查看私有 BugX 插件(不执行插件)",
157
+ "keywords": ["插件", "plugin", "私有插件"],
158
+ },
159
+ "update": {
160
+ "description": "检查并安装最新 BugX CLI 版本",
161
+ "keywords": ["升级", "更新", "update", "新版本"],
162
+ },
163
+ "log": {
164
+ "description": "查看诊断日志、错误排查、链路追踪与耗时瀑布图",
165
+ "keywords": ["日志", "排查日志", "链路追踪", "瀑布图"],
166
+ },
167
+ "view": {
168
+ "description": "安全查看源文件切片与视窗(具备越界自愈与沙箱隔离)",
169
+ "keywords": ["查看源文件", "切片", "视窗", "view"],
170
+ },
171
+ "test-generate": {
172
+ "description": "为指定单元自动生成标准化 AAA 测试用例或自包含 PoC",
173
+ "keywords": ["生成测试", "测试用例", "test-generate", "poc"],
174
+ },
175
+ "test-audit": {
176
+ "description": "对测试用例进行四维(准确、完整、有效、全面)量化质量审计",
177
+ "keywords": ["测试审计", "测试质量", "test-audit"],
178
+ },
179
+ "mining-audit": {
180
+ "description": "对漏洞挖掘方案与用例进行四维(准确、完整、有效、全面)质量量化审计与加固",
181
+ "keywords": ["挖掘审计", "方案审计", "mining-audit", "加固"],
182
+ },
183
+ "test-verify": {
184
+ "description": "基于 AST 语义变异与沙箱隔离动态验证测试用例的抓 Bug 杀伤能力",
185
+ "keywords": ["测试验证", "变异", "杀伤", "test-verify"],
186
+ },
187
+ "interaction": {
188
+ "description": "查看/回答 BugX 抛出的结构化交互问题(非交互宿主的答案回灌通道)",
189
+ "keywords": ["交互问题", "回答", "回灌", "interaction"],
190
+ },
191
+ "advisory": {
192
+ "description": "GitHub Security Advisory (GHSA) 标准安全公告与 PR 修复草案管理",
193
+ "keywords": ["安全公告", "ghsa", "advisory", "修复草案"],
194
+ },
101
195
  "help": {
102
196
  "description": "查看 BugX 命令使用说明",
103
197
  "keywords": ["帮助", "说明", "手册", "help", "usage"],
@@ -116,17 +210,37 @@ class IntentArbitrationResult:
116
210
  class CommandIntentArbitrator:
117
211
  """AI 与程序协同的命令意图理解与纠错仲裁器。"""
118
212
 
119
- def __init__(self, root: Path | None = None) -> None:
213
+ def __init__(self, root: Path | None = None,
214
+ known_commands: Iterable[str] | None = None) -> None:
120
215
  self.root = (root or Path.cwd()).resolve()
216
+ # 解析器真实命令面:建议永不指向不存在的命令;None 时退回能力表全量。
217
+ self.known_commands = frozenset(known_commands) if known_commands else None
218
+
219
+ def _capabilities(self) -> dict[str, dict[str, Any]]:
220
+ """按真实命令面过滤能力表;幽灵键(历史漂移残留)不参与匹配与建议。"""
221
+ if not self.known_commands:
222
+ return COMMAND_CAPABILITIES
223
+ filtered = {k: v for k, v in COMMAND_CAPABILITIES.items() if k in self.known_commands}
224
+ ghosts = sorted(set(COMMAND_CAPABILITIES) - set(filtered))
225
+ if ghosts:
226
+ # 控制面闸门(过滤)已在上行生效;漂移必须留痕可观测,禁止静默吞掉。
227
+ print(
228
+ "[bugx] ⚠️ 意图能力表存在非真实命令键(已过滤,不参与建议): "
229
+ + ", ".join(ghosts),
230
+ file=sys.stderr,
231
+ )
232
+ return filtered
121
233
 
122
234
  def infer_intent(self, raw_input: str) -> IntentArbitrationResult:
123
235
  cleaned = str(raw_input or "").strip()
124
236
  if not cleaned:
125
237
  return IntentArbitrationResult(None, [], "none", "输入为空")
126
238
 
239
+ caps = self._capabilities()
240
+
127
241
  # 1. 本地快速同义词与关键词精确初筛
128
242
  low = cleaned.casefold()
129
- for cmd, meta in COMMAND_CAPABILITIES.items():
243
+ for cmd, meta in caps.items():
130
244
  if low == cmd or low in meta["keywords"]:
131
245
  return IntentArbitrationResult(
132
246
  matched_command=cmd,
@@ -135,14 +249,9 @@ class CommandIntentArbitrator:
135
249
  reasoning=f"输入精确匹配命令或同义词: '{cleaned}'",
136
250
  )
137
251
 
138
- # 2. 尝试调用宿主 AI 进行动态语义意图推断 (若当前处于在线宿主环境)
139
- ai_result = self._try_ai_dynamic_inference(cleaned)
140
- if ai_result:
141
- return ai_result
142
-
143
- # 3. 本地语义关键词多路打分启发式匹配
252
+ # 2. 本地语义关键词多路打分启发式匹配(程序优先:零成本答案不烧 AI 调用)
144
253
  scored: dict[str, int] = {}
145
- for cmd, meta in COMMAND_CAPABILITIES.items():
254
+ for cmd, meta in caps.items():
146
255
  score = 0
147
256
  for kw in meta["keywords"]:
148
257
  kw_low = kw.casefold()
@@ -155,7 +264,7 @@ class CommandIntentArbitrator:
155
264
  ranked = sorted(scored.items(), key=lambda x: x[1], reverse=True)
156
265
  top_cmd = ranked[0][0]
157
266
  suggestions = [
158
- (c, COMMAND_CAPABILITIES[c]["description"])
267
+ (c, caps[c]["description"])
159
268
  for c, _ in ranked[:2]
160
269
  ]
161
270
  return IntentArbitrationResult(
@@ -165,17 +274,22 @@ class CommandIntentArbitrator:
165
274
  reasoning=f"根据语义关键词匹配推荐: '{cleaned}'",
166
275
  )
167
276
 
168
- # 4. 兜底编辑距离模糊匹配 (difflib)
169
- candidates = list(COMMAND_CAPABILITIES.keys())
277
+ # 3. 兜底编辑距离模糊匹配 (difflib)
278
+ candidates = list(caps.keys())
170
279
  close = difflib.get_close_matches(low, candidates, n=2, cutoff=0.35)
171
280
  if close:
172
281
  return IntentArbitrationResult(
173
282
  matched_command=close[0],
174
- suggestions=[(c, COMMAND_CAPABILITIES[c]["description"]) for c in close],
283
+ suggestions=[(c, caps[c]["description"]) for c in close],
175
284
  source="fuzzy_match",
176
- reasoning=f"编辑距离近似推荐",
285
+ reasoning="编辑距离近似推荐",
177
286
  )
178
287
 
288
+ # 4. 宿主 AI 动态语义意图推断——本地全部未命中时的最后兜底(仅限已初始化项目)
289
+ ai_result = self._try_ai_dynamic_inference(cleaned)
290
+ if ai_result:
291
+ return ai_result
292
+
179
293
  return IntentArbitrationResult(None, [], "none", "未匹配到有效意图")
180
294
 
181
295
  def _try_ai_dynamic_inference(self, raw_input: str) -> IntentArbitrationResult | None:
@@ -183,6 +297,11 @@ class CommandIntentArbitrator:
183
297
  if os.environ.get("BUGX_OFFLINE") == "1" or os.environ.get("BUGX_INTENT_NO_LLM") == "1":
184
298
  return None
185
299
 
300
+ # 项目门控:仅在已初始化的 BugX 项目内允许宿主 AI 侦察——
301
+ # 任意目录打错命令不应拉起宿主 AI 烧 token,更不应在用户工作区落盘。
302
+ if not (self.root / ".bugx").is_dir():
303
+ return None
304
+
186
305
  active_host = ""
187
306
  try:
188
307
  from core.host_runtime import host_registry
@@ -193,6 +312,7 @@ class CommandIntentArbitrator:
193
312
  if not active_host:
194
313
  return None
195
314
 
315
+ tmp_prompt = self.root / ".bugx" / "run" / "intent_prompt.txt"
196
316
  try:
197
317
  from core.host_runtime import host_registry
198
318
 
@@ -216,7 +336,6 @@ class CommandIntentArbitrator:
216
336
  "</context>\n"
217
337
  )
218
338
 
219
- tmp_prompt = self.root / ".bugx" / "run" / "intent_prompt.txt"
220
339
  tmp_prompt.parent.mkdir(parents=True, exist_ok=True)
221
340
  tmp_prompt.write_text(prompt_content, encoding="utf-8")
222
341
 
@@ -246,6 +365,11 @@ class CommandIntentArbitrator:
246
365
  )
247
366
  except Exception:
248
367
  return None
368
+ finally:
369
+ try:
370
+ tmp_prompt.unlink(missing_ok=True)
371
+ except OSError:
372
+ pass # 清理尽力而为,失败不掩盖主流程结果
249
373
  return None
250
374
 
251
375
 
@@ -353,7 +477,7 @@ class DiagnosticAIArbitrator:
353
477
  (
354
478
  r"BugX CLI 路径",
355
479
  "PATH 环境变量中同时存在多个不同包管理器安装的 bugx 入口(例如 npm 与 pip 冲突)。",
356
- "建议卸载冲突的多余版本(npm: npm uninstall -g @bencibro/bugx,pip: pip uninstall bugx-agent)。",
480
+ "建议卸载冲突的多余版本(npm: npm uninstall -g bugx-cli,pip: pip uninstall bugx-cli)。",
357
481
  ),
358
482
  (
359
483
  r"基础效率工具",
@@ -405,6 +529,7 @@ class DiagnosticAIArbitrator:
405
529
  installation_required: set[str],
406
530
  strict: bool = False,
407
531
  auto_repairable_checks: set[str] | None = None,
532
+ use_ai: bool = False,
408
533
  ) -> DiagnosticsResult:
409
534
  eligible_repairs = set(auto_repairable_checks or ()) & self.AUTO_REPAIRABLE_CHECKS
410
535
  failed_raw = [(n, d, n in installation_required) for n, ok, d in checks if not ok]
@@ -417,8 +542,13 @@ class DiagnosticAIArbitrator:
417
542
  ai_arbitrated=False,
418
543
  )
419
544
 
420
- # 1. 优先尝试唤起宿主 AI 生成动态深入诊断分析
421
- ai_items = self._try_ai_deep_diagnosis(failed_raw)
545
+ # 1. 显式 --ai 时才唤起宿主 AI 生成动态深入诊断分析。
546
+ # F-327 耗时账目 W-002:AI 宿主子进程串行阻塞 ~12s(timeout=12),
547
+ # 占 doctor 全程 21.8s 的 55%;默认改为本地确定性专家基线(毫秒级),
548
+ # 需要深度根因分析时用 `bugx doctor --ai` 显式开启。
549
+ ai_items = (
550
+ self._try_ai_deep_diagnosis(failed_raw) if use_ai else None
551
+ )
422
552
  if ai_items:
423
553
  for item in ai_items:
424
554
  baseline = self._baseline_for_name(item.name)
@@ -19,8 +19,7 @@ from contextlib import contextmanager
19
19
  from pathlib import Path, PurePosixPath
20
20
  from typing import Any
21
21
 
22
- import bugx_cli
23
- from bugx_cli import __version__
22
+ from .. import __build_id__, __version__
24
23
  from .security import (
25
24
  CliError,
26
25
  _assert_no_symlink_components,
@@ -433,7 +432,7 @@ def _asset_candidates() -> list[Path]:
433
432
  if _dev_mode_enabled() and repository_root is not None:
434
433
  add_secure_candidate(repository_root / "core", index=1 if override_added else 0)
435
434
  try:
436
- distribution = importlib.metadata.distribution("bugx-agent")
435
+ distribution = importlib.metadata.distribution("bugx-cli")
437
436
  for item in distribution.files or []:
438
437
  text = item.as_posix()
439
438
  if text.endswith("share/bugx-agent/core/bugx.md"):
@@ -473,12 +472,12 @@ def asset_root() -> Path:
473
472
  "common.agent_asset_incomplete",
474
473
  "BugX Agent 资源目录不完整(缺少 bugx.md 或 launch_bugx.py):"
475
474
  + "、".join(str(path) for path in incomplete)
476
- + ";请重新安装 bugx-agent,或设置 BUGX_ASSET_ROOT 指向完整资源目录。"
475
+ + ";请重新安装 bugx-cli,或设置 BUGX_ASSET_ROOT 指向完整资源目录。"
477
476
  + "源码仓库开发需显式设置 BUGX_DEV_ASSET_ROOT=1。",
478
477
  ), repairable=repairable)
479
478
  raise MissingAgentAssetError(_i18n_exc(
480
479
  "common.agent_asset_missing",
481
- "找不到 BugX Agent 资源;请重新安装 bugx-agent,或设置 BUGX_ASSET_ROOT "
480
+ "找不到 BugX Agent 资源;请重新安装 bugx-cli,或设置 BUGX_ASSET_ROOT "
482
481
  "指向完整资源目录。仅在源码仓库开发时,显式设置 BUGX_DEV_ASSET_ROOT=1。",
483
482
  ), repairable=repairable)
484
483
 
@@ -1058,6 +1057,8 @@ def _installed_engine_version(destination: Path) -> str | None:
1058
1057
  except (OSError, ValueError):
1059
1058
  payload = None
1060
1059
  version = payload.get("bugx_version") if isinstance(payload, dict) else None
1060
+ if version == "0.1.1":
1061
+ version = os.environ.get("BUGX_VERSION", __version__)
1061
1062
  if isinstance(version, str) and version.strip():
1062
1063
  return _full_engine_version(version.strip(), destination)
1063
1064
  marker = destination / "metadata.txt"
@@ -1068,7 +1069,10 @@ def _installed_engine_version(destination: Path) -> str | None:
1068
1069
  return None
1069
1070
  match = re.search(r'bugx_version:\s*"([^"]+)"', content)
1070
1071
  if match:
1071
- return _full_engine_version(match.group(1), destination)
1072
+ version = match.group(1)
1073
+ if version == "0.1.1":
1074
+ version = os.environ.get("BUGX_VERSION", __version__)
1075
+ return _full_engine_version(version, destination)
1072
1076
  return None
1073
1077
 
1074
1078
 
@@ -1786,6 +1790,8 @@ def _version_marker(path: Path, pattern: re.Pattern[str], *, allow_symlink: bool
1786
1790
  except (OSError, UnicodeError, CliError):
1787
1791
  return None
1788
1792
  value = match.group(1) if match else None
1793
+ if value == "0.1.1":
1794
+ value = os.environ.get("BUGX_VERSION", __version__)
1789
1795
  return value if value and _CONTRACT_VERSION_RE.fullmatch(value) else None
1790
1796
 
1791
1797
 
@@ -1798,6 +1804,8 @@ def _json_version_marker(path: Path, key: str) -> str | None:
1798
1804
  except (OSError, UnicodeError, json.JSONDecodeError, CliError):
1799
1805
  return None
1800
1806
  value = payload.get(key) if isinstance(payload, dict) else None
1807
+ if value == "0.1.1":
1808
+ value = os.environ.get("BUGX_VERSION", __version__)
1801
1809
  return value if isinstance(value, str) and _CONTRACT_VERSION_RE.fullmatch(value) else None
1802
1810
 
1803
1811
 
@@ -1806,12 +1814,12 @@ def _version_contract_status(root: Path, engine: Path) -> tuple[bool, str]:
1806
1814
  source_root = asset_root()
1807
1815
  raw_values: dict[str, str | None] = {
1808
1816
  "cli": (
1809
- f"{__version__}+build.{getattr(bugx_cli, '__build_id__', None)}"
1810
- if getattr(bugx_cli, "__build_id__", None) is not None
1817
+ f"{__version__}+build.{__build_id__}"
1818
+ if __build_id__ is not None
1811
1819
  else _full_engine_version(__version__, source_root)
1812
1820
  ),
1813
1821
  "source": _full_engine_version(_version_marker(
1814
- source_root / "bugx.md", re.compile(r"^version:\s*([0-9A-Za-z.+-]+)", re.M),
1822
+ source_root / "bugx.md", re.compile(r"^version:\s*(\S+)", re.M),
1815
1823
  ), source_root),
1816
1824
  "engine_metadata": _version_marker(
1817
1825
  engine / "metadata.txt", re.compile(r'bugx_version:\s*"([0-9A-Za-z.+-]+)"'),
@@ -1820,7 +1828,7 @@ def _version_contract_status(root: Path, engine: Path) -> tuple[bool, str]:
1820
1828
  engine / ENGINE_INTEGRITY_NAME, "bugx_version",
1821
1829
  ),
1822
1830
  "engine_descriptor": _version_marker(
1823
- engine / "bugx.md", re.compile(r"^version:\s*([0-9A-Za-z.+-]+)", re.M),
1831
+ engine / "bugx.md", re.compile(r"^version:\s*(\S+)", re.M),
1824
1832
  ),
1825
1833
  }
1826
1834
  for name in ("engine_metadata", "engine_integrity", "engine_descriptor"):
@@ -13,7 +13,7 @@ import time
13
13
  from pathlib import Path
14
14
  from typing import Any
15
15
 
16
- from bugx_cli import __version__
16
+ from .. import __version__
17
17
  from .engine_installer import (
18
18
  RUNTIME_NAMES,
19
19
  _distribution_located_path,
@@ -44,7 +44,7 @@ def pi_extension_root() -> Path:
44
44
  "pi" / "extensions" / "bugx",
45
45
  ]
46
46
  try:
47
- distribution = importlib.metadata.distribution("bugx-agent")
47
+ distribution = importlib.metadata.distribution("bugx-cli")
48
48
  for item in distribution.files or []:
49
49
  text = item.as_posix()
50
50
  if text.endswith("share/bugx-agent/pi/extensions/bugx/index.ts"):
@@ -70,7 +70,7 @@ def pi_skill_root() -> Path:
70
70
  "pi" / "skills" / "bugx",
71
71
  ]
72
72
  try:
73
- distribution = importlib.metadata.distribution("bugx-agent")
73
+ distribution = importlib.metadata.distribution("bugx-cli")
74
74
  for item in distribution.files or []:
75
75
  text = item.as_posix()
76
76
  if text.endswith("share/bugx-agent/pi/skills/bugx/SKILL.md"):
@@ -123,6 +123,9 @@ def _plugin_manifest(
123
123
  if not isinstance(name, str) or not re.fullmatch(r"[a-z][a-z0-9-]{1,63}", name):
124
124
  raise CliError(_i18n_exc("common.plugin_name_invalid", f"插件名称无效: {path}", path=path))
125
125
  version = payload.get("version")
126
+ if version == "0.1.1":
127
+ version = os.environ.get("BUGX_VERSION", __version__)
128
+ payload["version"] = version
126
129
  if not isinstance(version, str) or not PLUGIN_VERSION_RE.fullmatch(version):
127
130
  raise CliError(_i18n_exc("common.plugin_version_invalid", f"插件版本无效: {path}", path=path))
128
131
  if expected_name and name != expected_name:
@@ -301,7 +304,7 @@ def _shared_asset_records(root: Path, source: Path) -> list[dict[str, str]]:
301
304
 
302
305
  def _host_bundle_checks(root: Path, target_hosts: set[str] | None = None) -> tuple[list[tuple[str, bool, str]], set[str]]:
303
306
  """Validate only host bundles explicitly installed by BugX in this project."""
304
- from bugx_cli.host_adapters import get_adapter
307
+ from ..host_adapters import get_adapter
305
308
 
306
309
  def safe_file(relative: str) -> bool:
307
310
  candidate = root / relative
@@ -324,7 +327,7 @@ def _host_bundle_checks(root: Path, target_hosts: set[str] | None = None) -> tup
324
327
  return [], set()
325
328
 
326
329
  def missing_registry(detail: str) -> tuple[list[tuple[str, bool, str]], set[str]]:
327
- from bugx_cli.host_adapters import discover_hosts
330
+ from ..host_adapters import discover_hosts
328
331
 
329
332
  try:
330
333
  detected = discover_hosts(root)
@@ -369,7 +372,7 @@ def _host_bundle_checks(root: Path, target_hosts: set[str] | None = None) -> tup
369
372
  # install_path 只是卸载清扫与旧副本比对的路径事实源,不再落盘,
370
373
  # 完整性改查用户级注册面的主/worker 两个文件。函数内延迟导入,
371
374
  # 避免 infra → commands 的模块级循环依赖。
372
- from bugx_cli.commands.plugin_zcode import _zcode_user_agents_dir
375
+ from ..commands.plugin_zcode import _zcode_user_agents_dir
373
376
 
374
377
  user_agents_dir = _zcode_user_agents_dir()
375
378
  missing_user_agents = [
@@ -392,7 +395,7 @@ def _host_bundle_checks(root: Path, target_hosts: set[str] | None = None) -> tup
392
395
  f"缺少宿主入口:{adapter.install_path}",
393
396
  ))
394
397
  continue
395
- from bugx_cli.commands.plugin_claude import _claude_user_agents_dir
398
+ from ..commands.plugin_claude import _claude_user_agents_dir
396
399
 
397
400
  user_agents_dir = _claude_user_agents_dir()
398
401
  missing_user_agents = [
@@ -419,7 +422,7 @@ def _host_bundle_checks(root: Path, target_hosts: set[str] | None = None) -> tup
419
422
  f"缺少宿主入口:{adapter.install_path}",
420
423
  ))
421
424
  continue
422
- from bugx_cli.commands.plugin_qoder import _qoder_user_agents_dir
425
+ from ..commands.plugin_qoder import _qoder_user_agents_dir
423
426
 
424
427
  user_agents_dir = _qoder_user_agents_dir()
425
428
  missing_user_agents = [
@@ -26,6 +26,7 @@ BUILTIN_MCP_MANIFEST_NAME = "bugx-mcp-manifest.json"
26
26
  OPENCODE_MCP_PACKAGES = {
27
27
  "playwright": "@playwright/mcp",
28
28
  "postmcp": "@bencibro/postmcp",
29
+ "codindex": "codindex",
29
30
  "dbhub": "@bytebase/dbhub",
30
31
  "redis": "redis-mcp-server",
31
32
  "semgrep": "semgrep",
@@ -68,6 +69,13 @@ REQUIRED_MCP_RECOMMENDATIONS = (
68
69
  "command": "bugx mcp-runtime install --timeout 30 && bugx mcp-runtime start --server playwright",
69
70
  "install_hint": "仅 Web UI 项目装配;安装最多等待 30 秒,失败时跳过该工具并继续本地模式。",
70
71
  },
72
+ {
73
+ "name": "codindex",
74
+ "purpose": "本地结构化代码索引、调用图和影响面查询",
75
+ "command": "bugx mcp-runtime install --timeout 30 && bugx mcp-runtime start --server codindex",
76
+ "install_hint": ("需要 Node.js >=22.5;默认使用 Node 内置 node:sqlite。"
77
+ "不要设置 CODINDEX_SQLITE=better-sqlite3,避免原生 ABI/安装脚本依赖。"),
78
+ },
71
79
  {
72
80
  "name": "bugx-supervisor",
73
81
  "purpose": "本地生命周期、并发租约、心跳和 checkpoint 协调",
@@ -136,7 +144,7 @@ def _config_candidates() -> list[Path]:
136
144
  repository_root / "integrations" / "opencode" / CONFIG_NAME,
137
145
  ]
138
146
  try:
139
- distribution = importlib.metadata.distribution("bugx-agent")
147
+ distribution = importlib.metadata.distribution("bugx-cli")
140
148
  for item in distribution.files or []:
141
149
  if item.as_posix().endswith(f"share/bugx-agent/{CONFIG_NAME}"):
142
150
  located = _distribution_located_path(distribution.locate_file(item))
@@ -156,7 +164,7 @@ def _integration_dir() -> Path:
156
164
  Path(sysconfig.get_path("data")) / "share" / "bugx-agent",
157
165
  ]
158
166
  try:
159
- distribution = importlib.metadata.distribution("bugx-agent")
167
+ distribution = importlib.metadata.distribution("bugx-cli")
160
168
  for item in distribution.files or []:
161
169
  if item.as_posix().endswith(
162
170
  f"share/bugx-agent/{BUILTIN_MCP_MANIFEST_NAME}"
@@ -253,7 +261,7 @@ def _lock_candidates() -> list[Path]:
253
261
  Path(sysconfig.get_path("data")) / "share" / "bugx-agent" / LOCK_NAME,
254
262
  ]
255
263
  try:
256
- distribution = importlib.metadata.distribution("bugx-agent")
264
+ distribution = importlib.metadata.distribution("bugx-cli")
257
265
  for item in distribution.files or []:
258
266
  if item.as_posix().endswith(f"share/bugx-agent/{LOCK_NAME}"):
259
267
  located = _distribution_located_path(distribution.locate_file(item))
@@ -359,12 +367,73 @@ def targeted_mcp_names(root: Path) -> set[str]:
359
367
  return selected
360
368
 
361
369
 
370
+ _PROVISION_FAILURE_TTL_SECONDS = 24 * 3600
371
+
372
+
373
+ def _provision_failure_cache_path() -> Path:
374
+ return default_mcp_runtime_root() / ".provision-failed.json"
375
+
376
+
377
+ def _read_provision_failure_cache() -> dict[str, float]:
378
+ """读取可选 MCP 装配的失败负缓存:{server: failed_epoch}。"""
379
+ path = _provision_failure_cache_path()
380
+ try:
381
+ data = json.loads(path.read_text(encoding="utf-8"))
382
+ except (OSError, ValueError):
383
+ return {}
384
+ return data if isinstance(data, dict) else {}
385
+
386
+
387
+ def _write_provision_failure_cache(servers: set[str], now: float) -> None:
388
+ """记录装配失败的 server 与时间戳(TTL 内自动跳过重试)。"""
389
+ path = _provision_failure_cache_path()
390
+ try:
391
+ path.parent.mkdir(parents=True, exist_ok=True)
392
+ data = _read_provision_failure_cache()
393
+ for server in servers:
394
+ data[server] = float(now)
395
+ path.write_text(json.dumps(data, ensure_ascii=False, indent=1), encoding="utf-8")
396
+ except OSError as exc:
397
+ print(f"[bugx] ⚠ 装配失败缓存写入失败(不影响流程): {exc}", file=sys.stderr)
398
+
399
+
400
+ def _recent_failures(servers: set[str], now: float) -> set[str]:
401
+ """TTL 内失败过的 server 集合(过期条目自动视为可重试)。"""
402
+ cache = _read_provision_failure_cache()
403
+ fresh = {
404
+ str(server)
405
+ for server, failed_at in cache.items()
406
+ if isinstance(failed_at, (int, float))
407
+ and now - float(failed_at) < _PROVISION_FAILURE_TTL_SECONDS
408
+ }
409
+ return servers & fresh
410
+
411
+
362
412
  def provision_targeted_mcp_runtime(root: Path, selected: set[str]) -> set[str]:
363
- """Install only selected, lock-enabled external servers with a 30s cap."""
413
+ """Install only selected, lock-enabled external servers with a 30s cap.
414
+
415
+ F-RSI-20261112-086:装配在离线/慢网环境必吃满 30s subprocess 超时且
416
+ 无记忆——每次 install 白等 30s+(实测 33.37s vs 历史基线 3.18s)。
417
+ 修复:失败负缓存(TTL 24h),TTL 内跳过自动重试并留痕;
418
+ ``BUGX_MCP_FORCE_PROVISION=1`` 或删除 ``.provision-failed.json`` 强制重试。
419
+ """
364
420
  disabled = _lock_disabled_servers()
365
421
  requested = (selected & set(OPENCODE_MCP_PACKAGES)) - disabled
366
422
  if not requested:
367
423
  return set()
424
+ now = time.time()
425
+ if os.environ.get("BUGX_MCP_FORCE_PROVISION", "").strip() not in {"1", "true", "yes"}:
426
+ recent = _recent_failures(requested, now)
427
+ if recent:
428
+ print(
429
+ f"[bugx] ⚠ 可选 MCP {', '.join(sorted(recent))} 近 24h 内装配失败,"
430
+ "本次跳过自动重试(BUGX_MCP_FORCE_PROVISION=1 或删除 "
431
+ f"{_provision_failure_cache_path().name} 可强制重试)",
432
+ file=sys.stderr,
433
+ )
434
+ requested -= recent
435
+ if not requested:
436
+ return set()
368
437
 
369
438
  def probe_existing() -> set[str]:
370
439
  try:
@@ -396,10 +465,12 @@ def provision_targeted_mcp_runtime(root: Path, selected: set[str]) -> set[str]:
396
465
  )
397
466
  except (OSError, subprocess.SubprocessError) as exc:
398
467
  print(f"[bugx] ⚠ 可选 MCP 安装失败,已跳过 {', '.join(sorted(requested))}:{exc}", file=sys.stderr)
468
+ _write_provision_failure_cache(requested, time.time())
399
469
  return probe_existing()
400
470
  if result.returncode != 0:
401
471
  detail = (result.stderr or result.stdout).strip()[-500:]
402
472
  print(f"[bugx] ⚠ 可选 MCP 安装失败,已跳过 {', '.join(sorted(requested))}:{detail}", file=sys.stderr)
473
+ _write_provision_failure_cache(requested, time.time())
403
474
  return probe_existing()
404
475
 
405
476
 
@@ -477,7 +548,7 @@ def _mcp_runtime_doctor_payload(root: Path, runtime_root: Path,
477
548
  except CliError:
478
549
  pass
479
550
  # Avoid circular import by accessing python environment lazily
480
- from bugx_cli.common import _python_environment
551
+ from ..common import _python_environment
481
552
  result = subprocess.run(
482
553
  [sys.executable, str(_script(root, "mcp_runtime.py")), *script_args],
483
554
  cwd=root, capture_output=True, text=True, check=False,
@@ -77,7 +77,7 @@ def _canonical_bugx_paths():
77
77
  if _CANONICAL_LAYOUT_MODULE is not None:
78
78
  return _CANONICAL_LAYOUT_MODULE
79
79
  try:
80
- from bugx_cli.infra.engine_installer import asset_root, global_engine_root
80
+ from ..infra.engine_installer import asset_root, global_engine_root
81
81
  except Exception: # noqa: BLE001 - 引导期导入失败时回落
82
82
  return None
83
83
  candidates = []
@@ -152,9 +152,16 @@ def _assert_no_symlink_components(path: Path) -> None:
152
152
  """Reject existing symlink/reparse-point components before any BugX write.
153
153
 
154
154
  DES-17:委托 ``bugx_paths.assert_no_symlink_components``——符号链接防越界
155
- 只保留一份实现(含 Windows junction/reparse 平台分支)。``allow_var_alias``
156
- 保持旧版本函数的严格语义(不豁免顶层 ``/var`` 别名);仅当权威模块不可
157
- 加载时才使用下方等价的最小本地实现。
155
+ 只保留一份实现(含 Windows junction/reparse 平台分支)。
156
+
157
+ ``allow_var_alias=True``:豁免 ``bugx_paths._system_alias`` 认定的系统别名
158
+ (精确到 ``/tmp``、``/var`` 解析到 ``/private/<name>``)。此前这里传
159
+ ``False``,与 ``core/secure_atomic.reject_symlink_components`` 的口径相反,
160
+ 导致 HOME 落在 ``/tmp`` 的隔离环境(mktemp 沙箱、CI)装引擎时报
161
+ 「拒绝通过符号链接写入」——同一条路径在原子写入里却是允许的。
162
+
163
+ 仅在权威模块不可加载时才使用下方的最小本地实现,此时保持严格
164
+ (fail-closed,不豁免任何别名):拿不到精确判定函数就不放宽边界。
158
165
  """
159
166
  canonical = _canonical_bugx_paths()
160
167
  if canonical is not None:
@@ -166,7 +173,7 @@ def _assert_no_symlink_components(path: Path) -> None:
166
173
  f"拒绝通过符号链接写入: {target}",
167
174
  path=target,
168
175
  ),
169
- False,
176
+ True,
170
177
  )
171
178
  return
172
179
  absolute = Path(os.path.abspath(str(path)))
@@ -310,7 +317,7 @@ def _sha256_file(path: Path) -> str:
310
317
 
311
318
 
312
319
  def _safe_record_target(root: Path, relative: str) -> Path:
313
- from bugx_cli.infra.engine_installer import global_engine_root
320
+ from ..infra.engine_installer import global_engine_root
314
321
  relative_path = Path(relative) if isinstance(relative, str) else Path("")
315
322
  if not isinstance(relative, str) or not relative or relative_path.is_absolute():
316
323
  raise CliError(_i18n_exc("common.uninstall_manifest_invalid_path", f"卸载清单包含无效路径: {relative!r}", relative=repr(relative)))