bugx-cli 0.1.0 → 0.1.2

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 (338) hide show
  1. package/README.md +193 -185
  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/README.md +3 -2
  11. package/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
  12. package/core/assets/axe-core/LICENSE.txt +362 -0
  13. package/core/assets/axe-core/UPSTREAM.md +10 -0
  14. package/core/assets/axe-core/axe.min.js +12 -0
  15. package/core/assets/bugx-hero-en.svg +74 -0
  16. package/core/assets/bugx-hero-zh.svg +74 -0
  17. package/core/assets/bugx-social-preview.svg +71 -0
  18. package/core/assets/bugx-wechat-group.png +0 -0
  19. package/core/assets/codex.png +0 -0
  20. package/core/assets/dsh.png +0 -0
  21. package/core/assets/webui-chatgpt.jpg +0 -0
  22. package/core/assets/webui-session.jpg +0 -0
  23. package/core/assets/webui-skills.jpg +0 -0
  24. package/core/assets/webui-studio.jpg +0 -0
  25. package/core/assets/webui-zcode.jpg +0 -0
  26. package/core/assets/zcode.png +0 -0
  27. package/core/audit_packs/README.md +2 -0
  28. package/core/audit_packs/pitfalls/auth_crypto.json +64 -0
  29. package/core/audit_packs/pitfalls/file_ssrf_cmd.json +64 -0
  30. package/core/audit_packs/pitfalls/go_backend.json +66 -0
  31. package/core/audit_packs/pitfalls/java_spring.json +64 -0
  32. package/core/audit_packs/pitfalls/js_ts_web.json +67 -0
  33. package/core/audit_packs/pitfalls/python_web.json +82 -0
  34. package/core/autonomous_cve/SPEC.md +1 -1
  35. package/core/autonomous_cve/attack_graph_store.py +152 -106
  36. package/core/autonomous_cve/behavior_graph.py +8 -2
  37. package/core/autonomous_cve/verifier.py +4 -1
  38. package/core/bugx.md +1 -1
  39. package/core/bugx_paths.py +43 -8
  40. package/core/cli-help.txt +66 -0
  41. package/core/cloud_sync/SPEC.md +1 -1
  42. package/core/cloud_sync/cloud_client.py +81 -11
  43. package/core/cloud_sync/cloud_onboard.py +42 -1
  44. package/core/cloud_sync/consent.py +33 -3
  45. package/core/cloud_sync/flywheel_client.py +186 -15
  46. package/core/cloud_sync/network_transport.py +24 -3
  47. package/core/cloud_sync/sensitive_filter.py +2 -2
  48. package/core/cloud_sync/sync_push.py +12 -10
  49. package/core/contracts/AGENT_GUIDE.md +6 -9
  50. package/core/contracts/README.md +2 -2
  51. package/core/contracts/bugx-runtime-contract.md +1 -1
  52. package/core/contracts/bugx-worker.md +1 -1
  53. package/core/contracts/engine_gap_contracts.py +86 -3
  54. package/core/coverage/coverage_discovery.py +599 -29
  55. package/core/coverage/coverage_evidence.py +47 -0
  56. package/core/coverage/coverage_forensics.py +9 -0
  57. package/core/coverage/coverage_validate.py +6 -1
  58. package/core/dev_harness/SPEC.md +1 -1
  59. package/core/engine-integrity.json +670 -442
  60. package/core/fuzzing/concurrency_fuzzer.py +53 -0
  61. package/core/fuzzing/differential_oracle.py +562 -27
  62. package/core/fuzzing/fuzz_input.py +109 -6
  63. package/core/fuzzing/stateful_fuzzer.py +72 -0
  64. package/core/governance/secret_redactor.py +22 -10
  65. package/core/host_acp/SPEC.md +1 -1
  66. package/core/host_acp/__init__.py +4 -4
  67. package/core/host_acp/claude.py +59 -1
  68. package/core/host_acp/cline.py +64 -1
  69. package/core/host_acp/codex.py +56 -1
  70. package/core/host_acp/dsh.py +59 -1
  71. package/core/host_acp/opencode.py +56 -1
  72. package/core/host_acp/pi.py +59 -1
  73. package/core/host_acp/zcode.py +59 -1
  74. package/core/host_runtime/SPEC.md +1 -1
  75. package/core/host_runtime/adapters.py +1 -1
  76. package/core/host_runtime/cline.py +13 -0
  77. package/core/host_runtime/host_evaluators.py +44 -4
  78. package/core/host_runtime/host_probe.py +1 -1
  79. package/core/host_runtime/host_provider_arbitrator.py +116 -62
  80. package/core/host_runtime/host_registry.py +15 -8
  81. package/core/host_runtime/mcp_registry_gate.py +12 -1
  82. package/core/host_runtime/pi.py +102 -0
  83. package/core/host_runtime/provider_facts.py +66 -0
  84. package/core/hosts/SPEC.md +1 -1
  85. package/core/hosts/__init__.py +6 -2
  86. package/core/hosts/_dsh_usage.py +1 -1
  87. package/core/hosts/base.py +32 -4
  88. package/core/hosts/claude.py +55 -0
  89. package/core/hosts/cline.py +6 -2
  90. package/core/hosts/codex.py +58 -0
  91. package/core/hosts/dsh.py +9 -1
  92. package/core/hosts/opencode.py +6 -6
  93. package/core/hosts/pi.py +159 -2
  94. package/core/infra/README.md +4 -2
  95. package/core/infra/__init__.py +2 -0
  96. package/core/infra/build_info.py +22 -3
  97. package/core/infra/client_metadata.py +1 -1
  98. package/core/infra/json_utils.py +22 -0
  99. package/core/launch_phases/README.md +6 -3
  100. package/core/launch_phases/SPEC.md +1 -1
  101. package/core/launch_phases/common.py +21 -2
  102. package/core/launch_phases/finding_confirm_phase.py +170 -5
  103. package/core/launch_phases/finding_settlement.py +188 -1
  104. package/core/launch_phases/judge_phase.py +69 -12
  105. package/core/launch_phases/orchestrator_controls.py +11 -7
  106. package/core/launch_phases/post_coverage_sync.py +9 -2
  107. package/core/launch_phases/post_phase.py +144 -8
  108. package/core/launch_phases/post_receipt.py +12 -1
  109. package/core/launch_phases/pre_phase.py +3 -3
  110. package/core/launch_phases/pre_recon_scout.py +66 -36
  111. package/core/launch_phases/pre_state_builder.py +23 -176
  112. package/core/launch_phases/report_sharing.py +3 -7
  113. package/core/launch_phases/round_orchestrator.py +129 -58
  114. package/core/launch_phases/semantic_recon.py +545 -0
  115. package/core/launch_phases/session_runtime.py +56 -9
  116. package/core/launch_phases/startup_gates.py +36 -8
  117. package/core/launch_phases/startup_interaction.py +68 -12
  118. package/core/launch_phases/startup_version_gate.py +13 -3
  119. package/core/launch_phases/supervisor_bridge.py +46 -17
  120. package/core/launch_phases/supervisor_coverage.py +8 -2
  121. package/core/launch_phases/supervisor_degraded.py +1 -9
  122. package/core/launch_phases/verify_loop.py +767 -0
  123. package/core/launch_phases/worker_barriers.py +15 -5
  124. package/core/launch_phases/worker_orchestrator.py +105 -25
  125. package/core/launch_phases/worker_prior.py +115 -0
  126. package/core/ledger/README.md +2 -1
  127. package/core/ledger/SPEC.md +1 -1
  128. package/core/ledger/_facade.py +2 -1
  129. package/core/ledger/archive_ops.py +60 -2
  130. package/core/ledger/cli.py +6 -1
  131. package/core/ledger/export_ops.py +6 -1
  132. package/core/ledger/finding_confirmation.py +48 -6
  133. package/core/ledger/finding_lifecycle.py +428 -5
  134. package/core/ledger/finding_verification.py +555 -10
  135. package/core/ledger/fp_ledger.py +255 -0
  136. package/core/ledger/incidents.py +10 -4
  137. package/core/ledger/patterns.py +10 -7
  138. package/core/ledger/receipt_contract.py +17 -1
  139. package/core/ledger/sync_ops.py +21 -16
  140. package/core/ledger/tool_experience.py +2 -1
  141. package/core/ledger/verify_life.py +88 -17
  142. package/core/locales/en-US.json +2 -2
  143. package/core/locales/zh-CN.json +2 -2
  144. package/core/mcp_handlers/SPEC.md +1 -1
  145. package/core/mcp_handlers/base.py +23 -3
  146. package/core/mcp_handlers/channel_lifecycle.py +85 -30
  147. package/core/mcp_handlers/retrieval_handlers.py +11 -1
  148. package/core/mcp_handlers/rpc_server.py +6 -1
  149. package/core/mcp_handlers/supervisor_handlers.py +32 -6
  150. package/core/mcp_handlers/tool_table.py +15 -0
  151. package/core/mcp_runtime_support/environment.py +0 -38
  152. package/core/mcp_runtime_support/verifier.py +0 -52
  153. package/core/metadata.txt +2 -3
  154. package/core/planning/README.md +2 -1
  155. package/core/planning/domain_router.py +4 -2
  156. package/core/planning/dynamic_flow_analyzer.py +219 -14
  157. package/core/planning/judge_pipeline.py +87 -4
  158. package/core/planning/prompt_harness.py +57 -15
  159. package/core/planning/prompt_policy_engine.py +386 -0
  160. package/core/planning/spec_harvester.py +4 -4
  161. package/core/probes/INTERFACE.md +11 -1
  162. package/core/probes/SPEC.md +11 -1
  163. package/core/probes/__init__.py +46 -40
  164. package/core/probes/android_probe.py +177 -9
  165. package/core/probes/codebase_memory_probe.py +57 -0
  166. package/core/probes/desktop_probe.py +104 -0
  167. package/core/probes/differential_probe.py +99 -21
  168. package/core/probes/efficiency_probe.py +64 -0
  169. package/core/probes/ios_binary_probe.py +105 -1
  170. package/core/probes/memory_probe.py +66 -0
  171. package/core/probes/miniprogram_probe.py +75 -13
  172. package/core/probes/mobile_probe.py +215 -30
  173. package/core/probes/native_probe.py +88 -0
  174. package/core/probes/openwiki_probe.py +70 -0
  175. package/core/probes/pattern_probe.py +106 -0
  176. package/core/probes/platform_probe.py +81 -0
  177. package/core/probes/probe_registry.py +108 -7
  178. package/core/probes/sast_fixture_corpus.py +340 -0
  179. package/core/probes/sast_probe.py +553 -52
  180. package/core/probes/sast_rules.py +668 -28
  181. package/core/probes/sca_scanner.py +48 -0
  182. package/core/probes/ui_accessibility.py +149 -0
  183. package/core/probes/ui_audit.py +513 -0
  184. package/core/probes/ui_contract.py +273 -0
  185. package/core/probes/ui_evidence.py +212 -0
  186. package/core/probes/ui_measurements.py +314 -0
  187. package/core/probes/ui_repair.py +250 -0
  188. package/core/probes/ui_review.py +133 -0
  189. package/core/probes/ui_storybook.py +107 -0
  190. package/core/probes/ui_tokens.py +185 -0
  191. package/core/probes/ui_visual_diff.py +131 -0
  192. package/core/probes/web_probe.py +373 -18
  193. package/core/project_profiler/SPEC.md +1 -1
  194. package/core/project_profiler/arbitrator.py +6 -1
  195. package/core/project_profiler/detector.py +8 -1
  196. package/core/project_profiler/strategy.py +51 -15
  197. package/core/prompts/README.md +4 -2
  198. package/core/prompts/command_routing_en.md +2 -2
  199. package/core/prompts/command_routing_zh.md +2 -2
  200. package/core/prompts/policies/prompt_policies.json +101 -0
  201. package/core/prompts/stages/stage_repair.md +1 -1
  202. package/core/prompts/stages/stage_verify.defensive.md +42 -0
  203. package/core/prompts/stages/stage_verify.md +44 -0
  204. package/core/repair/README.md +1 -1
  205. package/core/repair/l7_repair_loop.py +1 -4
  206. package/core/repair/rsi_fixer.py +4 -4
  207. package/core/repair/rsi_loop.py +1 -3
  208. package/core/repair/rsi_repair.py +7 -7
  209. package/core/repair/rsi_scope.py +27 -8
  210. package/core/report_engine/SPEC.md +1 -1
  211. package/core/report_engine/attestation.py +8 -4
  212. package/core/report_engine/finding_report.py +2 -1
  213. package/core/report_engine/models.py +7 -9
  214. package/core/report_engine/report_share.py +0 -8
  215. package/core/report_engine/sast_bridge.py +2 -2
  216. package/core/report_engine/server.py +18 -8
  217. package/core/report_engine/web-conformance.md +123 -18
  218. package/core/report_engine/web_conformance.py +21 -52
  219. package/core/retrieval/README.md +2 -1
  220. package/core/retrieval/SPEC.md +1 -1
  221. package/core/retrieval/code_analyzer.py +50 -14
  222. package/core/retrieval/context_assembler.py +7 -1
  223. package/core/retrieval/knowledge_sync.py +108 -14
  224. package/core/retrieval/pitfall_packs.py +277 -0
  225. package/core/retrieval/symbol_index.py +25 -6
  226. package/core/retrieval/universal_code_matcher.py +234 -49
  227. package/core/runtime/README.md +1 -1
  228. package/core/runtime/bugx_logging.py +78 -7
  229. package/core/runtime/fixture_solidify.py +5 -10
  230. package/core/runtime/global_telemetry.py +20 -0
  231. package/core/runtime/incident_eval.py +1 -1
  232. package/core/runtime/model_runner.py +4 -41
  233. package/core/runtime/platform_adapter.py +2 -2
  234. package/core/runtime/prep_validate.py +4 -2
  235. package/core/runtime/project_settings.py +2 -1
  236. package/core/runtime/scenario_eval.py +50 -8
  237. package/core/skills/bugx_docs_mcp_server.py +3 -1
  238. package/core/skills/bugx_mcp_server.py +29 -2
  239. package/core/skills/tools_kb.py +1 -1
  240. package/core/supervisor/README.md +1 -1
  241. package/core/supervisor/SPEC.md +1 -1
  242. package/core/supervisor/budget_governor.py +503 -9
  243. package/core/supervisor/checkpoint_pipeline.py +248 -6
  244. package/core/supervisor/checkpoint_sync.py +13 -0
  245. package/core/supervisor/claim_events.py +1 -1
  246. package/core/supervisor/finding_workflow.py +22 -5
  247. package/core/supervisor/lease_manager.py +1 -1
  248. package/core/supervisor/lifecycle_blocks.py +6 -1
  249. package/core/supervisor/rejection_remedies.py +52 -5
  250. package/core/supervisor/serial_authorization.py +48 -4
  251. package/core/supervisor/task_scheduler.py +2 -2
  252. package/core/supervisor/worker_checkpoint.py +8 -1
  253. package/core/supervisor/worker_runtime.py +8 -2
  254. package/core/supervisor_types/worker_claim.py +9 -0
  255. package/core/webui/README.md +1 -1
  256. package/core/webui/SPEC.md +2 -1
  257. package/core/webui/adapters/claude.py +5 -1
  258. package/core/webui/adapters/cline.py +10 -2
  259. package/core/webui/adapters/codex.py +5 -1
  260. package/core/webui/adapters/dsh.py +5 -1
  261. package/core/webui/docs_session_service.py +2 -2
  262. package/core/webui/mcp_inspector.py +11 -7
  263. package/core/webui/static/00-base.css +1060 -0
  264. package/core/webui/static/01-monitoring.css +802 -0
  265. package/core/webui/static/02-header-actions.css +321 -0
  266. package/core/webui/static/03-trigger-popover.css +697 -0
  267. package/core/webui/static/04-composer.css +628 -0
  268. package/core/webui/static/05-skills-center.css +878 -0
  269. package/core/webui/static/06-mcp-center.css +623 -0
  270. package/core/webui/static/07-skill-detail.css +265 -0
  271. package/core/webui/static/08-files-management.css +167 -0
  272. package/core/webui/static/09-files-center.css +386 -0
  273. package/core/webui/static/10-icons.css +105 -0
  274. package/core/webui/static/11-project-options.css +185 -0
  275. package/core/webui/static/12-profile-tab.css +383 -0
  276. package/core/webui/static/design-tokens.css +113 -0
  277. package/core/webui/static/index.html +14 -1
  278. package/core/webui/workspace_service.py +1 -1
  279. package/docs/07_distribution/01_README_NPM.md +193 -185
  280. package/ecosystem/integrations/README.md +1 -1
  281. package/ecosystem/integrations/dsh/mcp/package.json +1 -1
  282. package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
  283. package/ecosystem/integrations/dsh/ui/package.json +1 -1
  284. package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
  285. package/ecosystem/integrations/opencode/mcp-lock.json +14 -6
  286. package/ecosystem/integrations/opencode/opencode.json +23 -12
  287. package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
  288. package/ecosystem/integrations/qoder/connector-meta.json +1 -1
  289. package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
  290. package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
  291. package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
  292. package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
  293. package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
  294. package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
  295. package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
  296. package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
  297. package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +1 -1
  298. package/interfaces/bin/bugx.js +37 -0
  299. package/interfaces/cli/bugx_cli/__init__.py +4 -2
  300. package/interfaces/cli/bugx_cli/cli.py +172 -69
  301. package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
  302. package/interfaces/cli/bugx_cli/commands/agent.py +461 -134
  303. package/interfaces/cli/bugx_cli/commands/audit.py +10 -9
  304. package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
  305. package/interfaces/cli/bugx_cli/commands/cloud.py +31 -22
  306. package/interfaces/cli/bugx_cli/commands/doctor.py +449 -204
  307. package/interfaces/cli/bugx_cli/commands/interaction.py +5 -1
  308. package/interfaces/cli/bugx_cli/commands/knowledge.py +5 -4
  309. package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
  310. package/interfaces/cli/bugx_cli/commands/plugin.py +58 -23
  311. package/interfaces/cli/bugx_cli/commands/plugin_claude.py +7 -7
  312. package/interfaces/cli/bugx_cli/commands/plugin_funide.py +2 -1
  313. package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +1 -1
  314. package/interfaces/cli/bugx_cli/commands/project.py +6 -13
  315. package/interfaces/cli/bugx_cli/commands/report.py +2 -6
  316. package/interfaces/cli/bugx_cli/commands/system.py +524 -169
  317. package/interfaces/cli/bugx_cli/common.py +21 -15
  318. package/interfaces/cli/bugx_cli/host_adapters.py +29 -54
  319. package/interfaces/cli/bugx_cli/hosts/registry.py +8 -6
  320. package/interfaces/cli/bugx_cli/infra/ai_advisor.py +157 -27
  321. package/interfaces/cli/bugx_cli/infra/engine_installer.py +35 -16
  322. package/interfaces/cli/bugx_cli/infra/host_sync.py +11 -8
  323. package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +76 -5
  324. package/interfaces/cli/bugx_cli/infra/security.py +13 -6
  325. package/package.json +30 -15
  326. package/pyproject.toml +60 -9
  327. package/scripts/ensure-python.mjs +7 -7
  328. package/scripts/sync-version.mjs +10 -21
  329. package/scripts/test-npm-wrapper.mjs +1 -1
  330. package/core/assets/bugx-hero-cn.png +0 -0
  331. package/core/assets/bugx-hero-en.png +0 -0
  332. package/core/webui/static/project-settings.css +0 -6458
  333. package/docs/07_distribution/README.md +0 -16
  334. package/docs/README.md +0 -121
  335. package/interfaces/README.md +0 -143
  336. package/interfaces/bin/README.md +0 -35
  337. package/interfaces/cli/README.md +0 -90
  338. package/scripts/README.md +0 -118
@@ -28,9 +28,8 @@ import zipfile
28
28
  from pathlib import Path
29
29
  from typing import Any
30
30
 
31
- import bugx_cli
32
31
  from . import __version__
33
- from bugx_cli.infra import (
32
+ from .infra import (
34
33
  CONFIG_NAME,
35
34
  CORE_API_RE,
36
35
  CliError,
@@ -197,6 +196,8 @@ PROBE_SCRIPTS = {
197
196
  "efficiency": "efficiency_probe.py",
198
197
  "sast": "sast_probe.py",
199
198
  "mobile": "mobile_probe.py",
199
+ "ui": "ui_audit.py",
200
+ "android": "android_probe.py",
200
201
  "ios_binary": "ios_binary_probe.py",
201
202
  "codebase-memory": "codebase_memory_probe.py",
202
203
  "platform": "platform_probe.py",
@@ -267,7 +268,7 @@ def _ensure_core_importable() -> None:
267
268
  if cand.is_dir() and (cand / "launch_bugx.py").is_file():
268
269
  candidates.append(cand)
269
270
  # 后插入者位于 sys.path[0],故按 (asset, global_engine) 顺序插入 ⇒
270
- # 最终 global_engine 优先。契约见 `docs/03_ai/AI_REFERENCE.md`「副本升级门禁」:
271
+ # 最终 global_engine 优先。契约见 `docs/03_ai/01_AI_REFERENCE.md`「副本升级门禁」:
271
272
  # Python 导入必须优先 `global_engine_root()`(共享引擎是运行时真源),
272
273
  # 仅在全局引擎缺失 launch_bugx.py 时才回落到 asset_root。
273
274
  for cand in candidates:
@@ -568,6 +569,10 @@ def _defer_command_logging_until_authorized(args: argparse.Namespace) -> bool:
568
569
  not create/open the project log until authorization has succeeded.
569
570
  """
570
571
  command = getattr(args, "command", None)
572
+ if getattr(args, "dry_run", False) or command == "hosts":
573
+ return True
574
+ if command == "project" and getattr(args, "project_action", None) == "show":
575
+ return True
571
576
  if command == "completion":
572
577
  # Shell setup must be observationally read-only: emitting a script must
573
578
  # not create a project log merely because it was run from a repository.
@@ -598,14 +603,8 @@ def _defer_command_logging_until_authorized(args: argparse.Namespace) -> bool:
598
603
  and not getattr(args, "yes", False)
599
604
  )
600
605
  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
- )
606
+ # Engine actions own their own logging after argument validation.
607
+ return True
609
608
  return False
610
609
 
611
610
 
@@ -858,13 +857,20 @@ def get_build_id() -> int | None:
858
857
  raise CliError("BUGX_BUILD_ID 超出支持的整数范围") from exc
859
858
  if env_value < 1:
860
859
  raise CliError("BUGX_BUILD_ID 必须是正整数")
861
- build_id = getattr(bugx_cli, "__build_id__", None)
860
+ # F-RSI-20261110-045:包标识改相对读取——原 `getattr(bugx_cli, "__build_id__")`
861
+ # 依赖顶层模块名 `bugx_cli`,仓库开发布局下该名字解析到 site-packages
862
+ # 安装副本(bugx-agent 1.0.0 快照),__build_id__ 短路劫持到陈旧快照。
863
+ try:
864
+ from . import __build_id__ as _pkg_build_id
865
+ except ImportError:
866
+ _pkg_build_id = None
867
+ build_id = _pkg_build_id if isinstance(_pkg_build_id, int) and not isinstance(_pkg_build_id, bool) and _pkg_build_id >= 1 else None
862
868
  if isinstance(build_id, int) and not isinstance(build_id, bool) and build_id >= 1:
863
869
  return build_id
864
870
  if env_value is not None:
865
871
  return env_value
866
872
  try:
867
- from bugx_cli.infra.engine_installer import asset_root
873
+ from .infra.engine_installer import asset_root
868
874
  meta = asset_root() / "metadata.txt"
869
875
  if meta.is_file():
870
876
  content = meta.read_text(encoding="utf-8")
@@ -874,7 +880,7 @@ def get_build_id() -> int | None:
874
880
  except Exception:
875
881
  pass
876
882
  try:
877
- from bugx_cli.infra.engine_installer import global_engine_root
883
+ from .infra.engine_installer import global_engine_root
878
884
  meta = global_engine_root() / "metadata.txt"
879
885
  if meta.is_file():
880
886
  content = meta.read_text(encoding="utf-8")
@@ -887,7 +893,7 @@ def get_build_id() -> int | None:
887
893
 
888
894
 
889
895
  def get_full_version() -> str:
890
- """返回标准版本与 Build ID 组合字符串,例如 1.0.0+build.4。"""
896
+ """返回标准版本与 Build ID 组合字符串,例如 0.1.1+build.627。"""
891
897
  bid = get_build_id()
892
898
  if bid is not None:
893
899
  return f"{__version__}+build.{bid}"
@@ -17,6 +17,16 @@ import shutil
17
17
  import subprocess
18
18
 
19
19
  from .hosts.registry import engine_host_plugin
20
+ from .hosts.template_engine import (
21
+ AGENT_DESCRIPTION,
22
+ AGENT_DESCRIPTION_EN,
23
+ AGENT_DESCRIPTION_ZH,
24
+ BUGX_WORKER_DESCRIPTION,
25
+ BUGX_WORKER_DESCRIPTION_EN,
26
+ BUGX_WORKER_DESCRIPTION_ZH,
27
+ get_agent_description,
28
+ get_worker_description,
29
+ )
20
30
 
21
31
 
22
32
  def _windows_drive_roots() -> tuple[Path, ...]:
@@ -83,55 +93,6 @@ def _running_zcode_markers() -> tuple[Path, ...]:
83
93
  return tuple(markers)
84
94
 
85
95
 
86
- # 宿主入口 frontmatter 的触发文案。description 是各宿主决定"何时自动
87
- # 启用 BugX agent"的路由依据,必须跨宿主保持一致。支持中英双语自适应,
88
- # 非 zh 语言一律回退为规范英文。
89
- AGENT_DESCRIPTION_EN = (
90
- "An autonomous agent dedicated to code review, vulnerability hunting, and automated bug fixing. "
91
- "Built for deep investigations, BugX steps in when you are wrapping up a feature, opening a pull request, or hunting down an elusive bug. "
92
- "It analyzes code logic, automatically writes test cases to uncover and reproduce hidden flaws, and delivers verified patches that resolve root causes. "
93
- "Always safeguarding your code quality and security."
94
- )
95
-
96
- AGENT_DESCRIPTION_ZH = (
97
- "专注于代码质量与安全的自主审查智能体。专为深层缺陷排查而生——在功能写完、提 PR 或排查疑难 Bug 时,"
98
- "它能深入分析代码逻辑,自动编写测试用例,挖掘、复现Bug和漏洞,生成经过验证的修复补丁。随时为您的代码质量和代码安全把关。"
99
- )
100
-
101
- # 并发 worker 子智能体的路由描述。OpenCode v2 通过 ``subagent`` 的 agent ID
102
- # ``bugx-worker`` 派发;描述用于让主 Agent 在子智能体目录中识别其职责;文案与
103
- # core/bugx-worker.md 的 frontmatter 保持一致,支持中英双语自适应。
104
- BUGX_WORKER_DESCRIPTION_ZH = (
105
- "BugX 并发审查 Worker。由 BugX 主智能体并发调度,负责具体代码模块的深度审查、缺陷挖掘与可复现用例验证;"
106
- "仅作为子智能体工作节点协同运行。"
107
- )
108
-
109
- BUGX_WORKER_DESCRIPTION_EN = (
110
- "A concurrent audit worker dispatched in parallel by the primary BugX agent to inspect assigned modules, "
111
- "hunt vulnerabilities, and verify defect reproduction as a collaborative subagent."
112
- )
113
-
114
- # 默认导出别名(维持向后兼容性,默认中文)
115
- AGENT_DESCRIPTION = AGENT_DESCRIPTION_ZH
116
- BUGX_WORKER_DESCRIPTION = BUGX_WORKER_DESCRIPTION_ZH
117
-
118
-
119
- def get_agent_description(locale: str | None = None) -> str:
120
- """Return the localized host agent description (fallback to en-US)."""
121
- loc = (locale or "").strip()
122
- if loc.startswith("zh"):
123
- return AGENT_DESCRIPTION_ZH
124
- return AGENT_DESCRIPTION_EN
125
-
126
-
127
- def get_worker_description(locale: str | None = None) -> str:
128
- """Return the localized concurrent worker description (fallback to en-US)."""
129
- loc = (locale or "").strip()
130
- if loc.startswith("zh"):
131
- return BUGX_WORKER_DESCRIPTION_ZH
132
- return BUGX_WORKER_DESCRIPTION_EN
133
-
134
-
135
96
  # ZCode 并发 worker 子智能体的模板路径与历史项目级安装位置。
136
97
  # 0.7.18 起 worker 不再写项目级入口,只做用户级注册(storageRoot/agents)
137
98
  # 与插件镜像;该路径保留给无登记遗留清扫(清理旧版本写入的项目级副本)。
@@ -805,19 +766,19 @@ def workbuddy_cli_venv() -> Path | None:
805
766
 
806
767
 
807
768
  def workbuddy_cli_venv_version(venv_path: Path | None = None) -> str | None:
808
- """快速探测 WorkBuddy 私有环境中的 bugx-agent 版本,优先读 dist-info 免进程开销。"""
769
+ """快速探测 WorkBuddy 私有环境中的 bugx-cli 版本,优先读 dist-info 免进程开销。"""
809
770
  venv = venv_path or workbuddy_cli_venv()
810
771
  if not venv:
811
772
  return None
812
773
  lib_dir = venv / ("Lib" if os.name == "nt" else "lib")
813
774
  if lib_dir.is_dir():
814
775
  for sp in lib_dir.glob("python*/site-packages"):
815
- for dist in sp.glob("bugx_agent-*.dist-info"):
816
- match = re.search(r"bugx_agent-([\d.]+)\.dist-info", dist.name)
776
+ for dist in sp.glob("bugx_cli-*.dist-info"):
777
+ match = re.search(r"bugx_cli-([\d.]+)\.dist-info", dist.name)
817
778
  if match:
818
779
  return match.group(1)
819
- for dist in (lib_dir / "site-packages").glob("bugx_agent-*.dist-info"):
820
- match = re.search(r"bugx_agent-([\d.]+)\.dist-info", dist.name)
780
+ for dist in (lib_dir / "site-packages").glob("bugx_cli-*.dist-info"):
781
+ match = re.search(r"bugx_cli-([\d.]+)\.dist-info", dist.name)
821
782
  if match:
822
783
  return match.group(1)
823
784
  bin_dir = venv / ("Scripts" if os.name == "nt" else "bin")
@@ -1487,6 +1448,20 @@ class ZCodeAdapter(HostAdapter):
1487
1448
  def _app_markers(self) -> tuple[Path, ...]:
1488
1449
  return _zcode_app_markers()
1489
1450
 
1451
+ def _user_marker(self) -> bool:
1452
+ # F-RSI-20261118-009:ZCode Desktop 的 agent 注册是用户级全局的
1453
+ # (~/.zcode/agents/bugx.md),不是项目级 .zcode 目录——所有项目都
1454
+ # 能用。project_marker 检查 root/.zcode 对用户注册宿主永远 False。
1455
+ agents_dir = Path.home() / ".zcode" / "agents"
1456
+ return (agents_dir / "bugx.md").is_file()
1457
+
1458
+ def _project_marker(self, root: Path) -> bool:
1459
+ # ZCode 是用户级注册宿主:用户级 agents 已注册即视为宿主可用,
1460
+ # 项目级 .zcode 目录不是必要条件(ZCode Desktop 不按项目写入 .zcode)。
1461
+ if self._user_marker():
1462
+ return True
1463
+ return super()._project_marker(root)
1464
+
1490
1465
  def render_required_entry(
1491
1466
  self, relative_path: str, source: Path, *, locale: str | None = None,
1492
1467
  ) -> str | None:
@@ -3,7 +3,7 @@
3
3
  统一管理所有受支持宿主组件声明,对外导出 HOST_COMPONENTS 清单与查找方法。
4
4
  """
5
5
 
6
- from bugx_cli.infra.security import _find_repo_root
6
+ from ..infra.security import _find_repo_root
7
7
 
8
8
  from pathlib import Path
9
9
  from typing import Any
@@ -281,12 +281,14 @@ def engine_worker_entry_dir(name: str) -> str:
281
281
 
282
282
 
283
283
  #: ``bugx autonomous`` / ``bugx goal`` 的 ``--host`` 展示基线(顺序即 help 顺序)。
284
- #: 三项都是**原生 Task 派发**宿主(无 CLI 进程池执行器);已迁移插件的取值由
285
- #: ``worker_runtime.autonomous_cli`` 自动追加,未迁移宿主(claude)只能靠本表。
286
- #: 这不是第二份宿主事实:宿主身份仍在插件/``SUPPORTED_HOSTS``,本表只说「CLI
287
- #: 的 host 选项按什么顺序出现」。
284
+ #: 成员都是**无 CLI 进程池执行器**的宿主:claude/codex/opencode/dsh 走原生 Task
285
+ #: 派发;pi 无原生 Task(``native_task=False``)但插件已声明
286
+ #: ``engine_run.autonomous_argv`` 无头自治通道(``pi --approve -p --mode json``),
287
+ #: 前台自治循环直接驱动。声明 ``worker_runtime.autonomous_cli`` 的插件(CLI
288
+ #: 进程池执行器)自动追加,不进本表。这不是第二份宿主事实:宿主身份仍在
289
+ #: 插件/``SUPPORTED_HOSTS``,本表只说「CLI 的 host 选项按什么顺序出现」。
288
290
  AUTONOMOUS_HOST_BASELINE: tuple[str, ...] = (
289
- "claude", "codex", "opencode", "dsh",
291
+ "claude", "codex", "opencode", "dsh", "pi",
290
292
  )
291
293
 
292
294
 
@@ -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)