bugx-cli 0.1.2 → 0.1.4

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 (157) hide show
  1. package/README.md +26 -29
  2. package/core/README.md +5 -3
  3. package/core/agent/agent_orchestrator.py +3 -0
  4. package/core/agent/agent_workspace.py +14 -2
  5. package/core/assets/bugx-wechat-group.png +0 -0
  6. package/core/assets/twitter_promo_art.jpg +0 -0
  7. package/core/assets/twitter_promo_card.svg +166 -0
  8. package/core/assets/twitter_promo_clean.jpg +0 -0
  9. package/core/assets/twitter_terminal_real.png +0 -0
  10. package/core/bugx.md +3 -3
  11. package/core/bugx_paths.py +10 -2
  12. package/core/bundled_docs/OVERVIEW.md +310 -0
  13. package/core/bundled_docs/README.md +10 -0
  14. package/core/bundled_docs/README_EN.md +278 -0
  15. package/core/bundled_docs/ai/01_AI_REFERENCE.md +833 -0
  16. package/core/bundled_docs/ai/02_AI_USAGE.md +161 -0
  17. package/core/bundled_docs/ai/03_AI_COMMANDS.md +322 -0
  18. package/core/bundled_docs/guides/01_USER_GUIDE.md +887 -0
  19. package/core/bundled_docs/guides/02_COMMANDS.md +935 -0
  20. package/core/bundled_docs/guides/03_TROUBLESHOOTING.md +763 -0
  21. package/core/bundled_docs/guides/04_CLOUD_AUTH_AND_SYNC_COOKBOOK.md +48 -0
  22. package/core/bundled_docs/guides/05_HOST_MATRIX_AND_DISPATCH.md +23 -0
  23. package/core/bundled_docs/guides/06_PROBES_AND_POC_COOKBOOK.md +49 -0
  24. package/core/bundled_docs/guides/07_LIFECYCLE_AND_RECOVERY_STATES.md +46 -0
  25. package/core/bundled_docs/guides/08_LESSONS_AND_PRIVACY_BOUNDARY.md +35 -0
  26. package/core/bundled_docs/hosts/bugx-claude_SKILL.md +326 -0
  27. package/core/bundled_docs/hosts/bugx-dsh_SKILL.md +229 -0
  28. package/core/bundled_docs/hosts/bugx-opencode_SKILL.md +129 -0
  29. package/core/bundled_docs/hosts/bugx-zcode_SKILL.md +459 -0
  30. package/core/bundled_docs/hosts/bugx_SKILL.md +118 -0
  31. package/core/bundled_docs/hosts/cline_bugx_SKILL.md +69 -0
  32. package/core/bundled_docs/hosts/platform_bugx_SKILL.md +50 -0
  33. package/core/bundled_docs/manifest.json +140 -0
  34. package/core/bundled_docs/reference/01_ENVIRONMENT_VARIABLES.md +421 -0
  35. package/core/bundled_docs/reference/04_REPOSITORY_TOPOLOGY.md +180 -0
  36. package/core/cli-help.txt +7 -3
  37. package/core/cloud_sync/cloud_client.py +81 -2
  38. package/core/cloud_sync/endpoint_router.py +22 -9
  39. package/core/cloud_sync/issue_uploader.py +297 -0
  40. package/core/cloud_sync/sensitive_filter.py +77 -7
  41. package/core/contracts/AGENT_GUIDE.md +3 -9
  42. package/core/contracts/README.md +1 -1
  43. package/core/contracts/bugx-opencode.md +1 -1
  44. package/core/contracts/bugx-runtime-contract.md +10 -20
  45. package/core/contracts/bugx-worker.md +1 -1
  46. package/core/engine-integrity.json +267 -111
  47. package/core/host_acp/antigravity.py +153 -0
  48. package/core/host_acp/kimi.py +175 -0
  49. package/core/host_acp/minimax.py +28 -0
  50. package/core/host_runtime/adapters.py +5 -1
  51. package/core/host_runtime/antigravity.py +162 -0
  52. package/core/host_runtime/host_bootstrap.py +18 -7
  53. package/core/host_runtime/host_evaluators.py +4 -4
  54. package/core/host_runtime/host_registry.py +25 -4
  55. package/core/host_runtime/mcp_process_tracker.py +30 -3
  56. package/core/host_runtime/mcp_registry_gate.py +34 -11
  57. package/core/hosts/antigravity.py +115 -0
  58. package/core/hosts/codex.py +3 -0
  59. package/core/hosts/dsh.py +43 -24
  60. package/core/hosts/kimi.py +293 -0
  61. package/core/hosts/minimax.py +249 -0
  62. package/core/hosts/zcode.py +5 -0
  63. package/core/i18n.py +94 -5
  64. package/core/infra/README.md +1 -1
  65. package/core/infra/build_info.py +30 -5
  66. package/core/launch_phases/README.md +2 -2
  67. package/core/launch_phases/startup_version_gate.py +2 -2
  68. package/core/launch_phases/supervisor_bridge.py +16 -23
  69. package/core/launch_phases/supervisor_degraded.py +7 -5
  70. package/core/ledger/README.md +1 -1
  71. package/core/locales/en-US.json +3 -3
  72. package/core/locales/zh-CN.json +3 -3
  73. package/core/mcp_runtime_support/environment.py +6 -1
  74. package/core/metadata.txt +2 -2
  75. package/core/planning/README.md +1 -1
  76. package/core/planning/prompt_harness.py +2 -2
  77. package/core/probes/codebase_memory_probe.py +43 -24
  78. package/core/probes/probe_registry.py +10 -7
  79. package/core/prompts/command_routing_en.md +6 -5
  80. package/core/prompts/command_routing_zh.md +6 -5
  81. package/core/repair/rsi_rounds.py +3 -0
  82. package/core/repair/self_heal.py +160 -6
  83. package/core/retrieval/README.md +1 -1
  84. package/core/runtime/README.md +1 -1
  85. package/core/runtime/scenario_eval.py +5 -1
  86. package/core/runtime/setup_ui_env.py +4 -7
  87. package/core/runtime/tool_install_targets.py +12 -2
  88. package/core/skills/README.md +4 -2
  89. package/core/skills/bugx_docs_cloud_sync.py +658 -0
  90. package/core/skills/bugx_docs_mcp_server.py +966 -140
  91. package/core/supervisor/README.md +1 -1
  92. package/core/supervisor/cli.py +2 -2
  93. package/core/supervisor/worker_execution.py +16 -3
  94. package/core/webui/docs_session_service.py +40 -2
  95. package/core/webui/mcp_inspector.py +12 -6
  96. package/core/webui/static/index.html +51 -3
  97. package/core/webui/static/manifest.webmanifest +1 -1
  98. package/core/webui/static/project-settings.js +18 -3
  99. package/core/webui/static/robots.txt +36 -0
  100. package/core/webui/static/sitemap.xml +15 -0
  101. package/docs/07_distribution/01_README_NPM.md +26 -29
  102. package/ecosystem/integrations/cline/skills/bugx/SKILL.md +46 -46
  103. package/ecosystem/integrations/dsh/agents/bugx.md +2 -1
  104. package/ecosystem/integrations/dsh/dsh-patch.yml +2 -2
  105. package/ecosystem/integrations/dsh/mcp/package.json +1 -1
  106. package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +6 -6
  107. package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
  108. package/ecosystem/integrations/dsh/ui/package.json +1 -1
  109. package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +2 -2
  110. package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
  111. package/ecosystem/integrations/pi/skills/bugx/SKILL.md +6 -6
  112. package/ecosystem/integrations/qoder/CONNECTORS.md +11 -23
  113. package/ecosystem/integrations/qoder/connector-meta.json +9 -9
  114. package/ecosystem/integrations/workbuddy/connector-meta.json +9 -9
  115. package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +8 -7
  116. package/ecosystem/plugins/bugx/.claude-plugin/marketplace.json +2 -2
  117. package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +2 -2
  118. package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +4 -4
  119. package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +2 -2
  120. package/ecosystem/plugins/bugx/agents/bugx-worker.md +14 -18
  121. package/ecosystem/plugins/bugx/agents/bugx.md +45 -49
  122. package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +8 -8
  123. package/ecosystem/plugins/bugx/skills/bugx-claude/SKILL.md +1 -1
  124. package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
  125. package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
  126. package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +3 -3
  127. package/interfaces/bin/bugx.js +2 -0
  128. package/interfaces/cli/bugx_cli/__init__.py +2 -2
  129. package/interfaces/cli/bugx_cli/cli.py +153 -8
  130. package/interfaces/cli/bugx_cli/commands/agent.py +568 -136
  131. package/interfaces/cli/bugx_cli/commands/cloud.py +42 -1
  132. package/interfaces/cli/bugx_cli/commands/doctor.py +668 -223
  133. package/interfaces/cli/bugx_cli/commands/guide.py +143 -0
  134. package/interfaces/cli/bugx_cli/commands/issue.py +262 -0
  135. package/interfaces/cli/bugx_cli/commands/lifecycle.py +99 -62
  136. package/interfaces/cli/bugx_cli/commands/plugin.py +301 -60
  137. package/interfaces/cli/bugx_cli/commands/plugin_antigravity.py +350 -0
  138. package/interfaces/cli/bugx_cli/commands/plugin_claude.py +27 -13
  139. package/interfaces/cli/bugx_cli/commands/plugin_kimi.py +440 -0
  140. package/interfaces/cli/bugx_cli/commands/plugin_minimax.py +522 -0
  141. package/interfaces/cli/bugx_cli/commands/plugin_qoder.py +3 -4
  142. package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +4 -5
  143. package/interfaces/cli/bugx_cli/commands/system.py +75 -5
  144. package/interfaces/cli/bugx_cli/common.py +135 -15
  145. package/interfaces/cli/bugx_cli/host_adapters.py +190 -7
  146. package/interfaces/cli/bugx_cli/hosts/registry.py +6 -3
  147. package/interfaces/cli/bugx_cli/hosts/template_engine.py +31 -11
  148. package/interfaces/cli/bugx_cli/infra/__init__.py +4 -0
  149. package/interfaces/cli/bugx_cli/infra/ai_advisor.py +14 -12
  150. package/interfaces/cli/bugx_cli/infra/engine_installer.py +76 -10
  151. package/interfaces/cli/bugx_cli/infra/host_sync.py +66 -1
  152. package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +242 -52
  153. package/package.json +38 -13
  154. package/pyproject.toml +57 -13
  155. package/scripts/sync-version.mjs +1 -1
  156. package/skills/README.md +24 -0
  157. package/skills/platform/bugx/SKILL.md +50 -0
@@ -11,6 +11,7 @@ import subprocess
11
11
  import sys
12
12
  import tempfile
13
13
  import time
14
+ from collections.abc import Callable
14
15
  from pathlib import Path
15
16
  from typing import Any
16
17
 
@@ -18,6 +19,7 @@ from .. import __version__
18
19
  from ..common import *
19
20
  from ..host_adapters import HOST_ADAPTERS
20
21
  from ..hosts.registry import (
22
+ QODER_PROJECT_MCP_PATHS,
21
23
  engine_host_label,
22
24
  engine_host_mcp_config_paths,
23
25
  engine_host_mcp_write,
@@ -507,7 +509,7 @@ def _chatgpt_plugin_manifest(version: str = __version__) -> dict[str, object]:
507
509
  return {
508
510
  "name": CHATGPT_PLUGIN_NAME,
509
511
  "version": version,
510
- "description": "Autonomous code review and vulnerability hunting agent that uncovers, reproduces, and fixes deep bugs.",
512
+ "description": "Autonomous code review and testing agent. Catches hidden deep bugs for developers, automates black-box, functional, and performance testing for QA, and ensures rock-solid software delivery.",
511
513
  "skills": "./skills/",
512
514
  "homepage": "https://bugx.dev",
513
515
  "author": {
@@ -518,8 +520,8 @@ def _chatgpt_plugin_manifest(version: str = __version__) -> dict[str, object]:
518
520
  "keywords": ["bugx", "audit", "security", "testing"],
519
521
  "interface": {
520
522
  "displayName": "BugX",
521
- "shortDescription": "Autonomous code review and vulnerability hunting agent that uncovers, reproduces, and fixes deep bugs.",
522
- "longDescription": "An autonomous agent dedicated to code review, vulnerability hunting, and automated bug fixing. Built for deep investigations, BugX steps in when you are wrapping up a feature, opening a pull request, or hunting down an elusive bug. It analyzes code logic, automatically writes test cases to uncover and reproduce hidden flaws, and delivers verified patches that resolve root causes. Always safeguarding your code quality and security.",
523
+ "shortDescription": "Autonomous code review and testing agent. Catches hidden deep bugs for developers, automates black-box, functional, and performance testing for QA, and ensures rock-solid software delivery.",
524
+ "longDescription": "BugX is an autonomous code review and testing agent designed to safeguard software delivery: it surfaces hidden, deep bugs for developers right after writing code to eliminate painful debugging and rework; automates black-box, functional, and performance testing across complex edge cases for QA; and ensures software strictly meets functional requirements with rock-solid stability and resilience. By taking over tedious verification, BugX frees engineers from manual grunt work, boosts team velocity, elevates code quality, and significantly lowers long-term maintenance costs—putting technology to work for people.",
523
525
  "developerName": "BugX",
524
526
  "category": "Developer tools",
525
527
  # ChatGPT only exposes its native choice/confirmation surface to
@@ -717,8 +719,81 @@ def _host_global_mcp_target(host_name: str, root: Path) -> Path | None:
717
719
  return paths[0] if paths else None
718
720
 
719
721
 
722
+ def _resolve_docs_remote_url(explicit: str | None = None) -> str:
723
+ """解析并校验 bugx-docs remote HTTP MCP 端点 URL。"""
724
+ import re as _re
725
+ from ..common import __version__
726
+
727
+ try:
728
+ from core.cloud_sync.endpoint_router import load_cloud_config, validate_base_url
729
+ except Exception as exc: # noqa: BLE001
730
+ raise CliError(f"无法加载云端路由校验器以配置远程 bugx-docs:{exc}") from exc
731
+
732
+ ver_match = _re.match(r"([0-9]+\.[0-9]+\.[0-9]+)", str(__version__))
733
+ contract_ver = ver_match.group(1) if ver_match else str(__version__)
734
+ raw = str(explicit or "").strip()
735
+ if raw:
736
+ base_part, _, query = raw.partition("?")
737
+ try:
738
+ normalized = validate_base_url(base_part)
739
+ except ValueError as exc:
740
+ raise CliError(f"非法 --docs-remote-url: {exc}") from exc
741
+ if "/api/v1/mcp/docs" not in normalized:
742
+ normalized = f"{normalized}/api/v1/mcp/docs"
743
+ return f"{normalized}?{query}" if query else f"{normalized}?contract_version={contract_ver}"
744
+
745
+ cfg = load_cloud_config()
746
+ base = str(cfg.get("base_url") or "https://bugx.dev").strip()
747
+ try:
748
+ normalized_base = validate_base_url(base)
749
+ except ValueError as exc:
750
+ raise CliError(f"云端 base_url 无法用于远程 bugx-docs: {exc}") from exc
751
+ return f"{normalized_base}/api/v1/mcp/docs?contract_version={contract_ver}"
752
+
753
+
754
+ def _probe_docs_remote_connectivity(url: str, timeout: float = 1.0) -> bool:
755
+ """快速探测远程文档服务连通性(1s 有界超时)。"""
756
+ import urllib.error
757
+ import urllib.request
758
+ try:
759
+ req = urllib.request.Request(url, headers={"User-Agent": "bugx-install-probe"}, method="HEAD")
760
+ with urllib.request.urlopen(req, timeout=timeout) as resp:
761
+ return resp.status < 500
762
+ except urllib.error.HTTPError as exc:
763
+ return exc.code < 500
764
+ except (urllib.error.URLError, TimeoutError, OSError):
765
+ return False
766
+
767
+
768
+ def resolve_effective_docs_transport(
769
+ docs_transport: str | None,
770
+ docs_remote_url: str | None = None,
771
+ ) -> str:
772
+ """确定当前环境应采用的 bugx-docs 传输模式(远程优先,无法联网时自动降级本地)。"""
773
+ if docs_transport in {"stdio", "remote"}:
774
+ return docs_transport
775
+ try:
776
+ from core.skills.bugx_docs_cloud_sync import docs_offline_disabled
777
+ if docs_offline_disabled():
778
+ return "stdio"
779
+ except Exception:
780
+ pass
781
+
782
+ try:
783
+ target_url = _resolve_docs_remote_url(docs_remote_url)
784
+ if _probe_docs_remote_connectivity(target_url, timeout=1.0):
785
+ return "remote"
786
+ except Exception:
787
+ pass
788
+ return "stdio"
789
+
790
+
720
791
  def _host_supervisor_server_definitions(
721
- *, shape: str, optional_names: set[str] | None = None,
792
+ *,
793
+ shape: str,
794
+ optional_names: set[str] | None = None,
795
+ docs_transport: str | None = None,
796
+ docs_remote_url: str | None = None,
722
797
  ) -> dict[str, dict[str, object]]:
723
798
  """构建 Cline / Claude Code / ZCode / Qoder / Trea / FunIDE 的最小 BugX MCP 注册。
724
799
 
@@ -736,6 +811,7 @@ def _host_supervisor_server_definitions(
736
811
  if shape not in _mcp_shape_names():
737
812
  raise CliError(_i18n_exc("plugin.unknown_mcp_shape", f"未知宿主 MCP 配置形态: {shape}", shape=shape))
738
813
  entry_extra = _host_mcp_entry_extra(shape)
814
+ effective_transport = resolve_effective_docs_transport(docs_transport, docs_remote_url)
739
815
  result: dict[str, dict[str, object]] = {}
740
816
  for name in HOST_SUPERVISOR_MCP:
741
817
  role = HOST_SUPERVISOR_MCP_ROLES[name]
@@ -750,16 +826,24 @@ def _host_supervisor_server_definitions(
750
826
  if entry_extra:
751
827
  entry.update(copy.deepcopy(entry_extra))
752
828
  result[name] = entry
753
- docs_entry: dict[str, object] = {
754
- "type": "stdio",
755
- "command": "bugx",
756
- "args": [
757
- "mcp", "docs", "serve", "--root", ".",
758
- "--db", ".bugx/knowledge/docs.sqlite3",
759
- ],
760
- }
761
- if entry_extra:
762
- docs_entry.update(copy.deepcopy(entry_extra))
829
+ if effective_transport == "remote":
830
+ resolved_url = _resolve_docs_remote_url(docs_remote_url)
831
+ docs_entry = (
832
+ {"url": resolved_url}
833
+ if shape == "codex"
834
+ else {"type": "http", "url": resolved_url}
835
+ )
836
+ else:
837
+ docs_entry = {
838
+ "type": "stdio",
839
+ "command": "bugx",
840
+ "args": [
841
+ "mcp", "docs", "serve", "--root", ".",
842
+ "--db", ".bugx/knowledge/docs.sqlite3",
843
+ ],
844
+ }
845
+ if entry_extra:
846
+ docs_entry.update(copy.deepcopy(entry_extra))
763
847
  result["bugx-docs"] = docs_entry
764
848
  for name in sorted(optional_names or set()):
765
849
  if name not in {"playwright", "postmcp"}:
@@ -797,9 +881,29 @@ def _host_mcp_command_tokens(entry: object) -> list[str] | None:
797
881
 
798
882
 
799
883
  _PYTHON_MODULE_LAUNCHER_PREFIX = ["-m", "bugx_cli.cli"]
884
+ _SAFE_PYTHON_MODULE_LAUNCHER_PREFIX = ["-P", *_PYTHON_MODULE_LAUNCHER_PREFIX]
885
+ _QODER_NPM_ENV_KEYS = ("BUGX_CLI_SOURCE", "BUGX_ASSET_ROOT", "PYTHONPATH")
886
+
887
+
888
+ def _qoder_windows_mcp_launcher() -> tuple[str, dict[str, str]]:
889
+ """Keep Qoder's Windows stdio launch independent of PATH and npm shims."""
890
+ python = Path(sys.executable)
891
+ if not python.is_absolute() or python.suffix.casefold() != ".exe" or not python.is_file():
892
+ raise CliError(f"Qoder MCP 需要可直接启动的 Windows Python 解释器: {python}")
893
+ if os.environ.get("BUGX_CLI_SOURCE") != "npm":
894
+ return str(python), {}
895
+ # npm adds its Python module and engine paths to the installer's environment.
896
+ # Qoder runs in a different process and does not inherit either of them.
897
+ return str(python), {
898
+ "BUGX_CLI_SOURCE": "npm",
899
+ "BUGX_ASSET_ROOT": str(asset_root()),
900
+ "PYTHONPATH": str(Path(__file__).resolve().parents[2]),
901
+ }
800
902
 
801
903
 
802
- def _absolute_bugx_launcher() -> tuple[str, list[str]]:
904
+ def _absolute_bugx_launcher(
905
+ *, direct_engine: bool = False, script_name: str = "bugx_mcp_server.py",
906
+ ) -> tuple[str, list[str]]:
803
907
  """解析 bugx 启动入口,返回 ``(command, 前缀参数)``。
804
908
 
805
909
  候选按可信度排序,**绝不落盘伪造路径**(旧实现无条件取 ``sys.argv[0]``,
@@ -811,6 +915,21 @@ def _absolute_bugx_launcher() -> tuple[str, list[str]]:
811
915
  4. 兜底:``<当前解释器> -m bugx_cli.cli`` —— 绝对、可执行、不伪造路径。
812
916
  """
813
917
 
918
+ if direct_engine:
919
+ # Antigravity ACP has a short MCP pre-load window. Starting the full
920
+ # CLI first adds several seconds on Windows, while the engine script
921
+ # is self-bootstrapping and reaches the same ``serve`` implementation
922
+ # directly. Keep the interpreter and script absolute because the ACP
923
+ # process is not guaranteed to inherit the user's PATH or cwd.
924
+ engine_roots = (global_engine_root(), asset_root())
925
+ for engine_root in engine_roots:
926
+ script = engine_root / "skills" / script_name
927
+ if script.is_file():
928
+ return str(Path(sys.executable).resolve()), [str(script.resolve())]
929
+ raise CliError(
930
+ f"全局 BugX 引擎缺少 skills/{script_name},无法为 Antigravity ACP 写入快速 MCP 启动器"
931
+ )
932
+
814
933
  override = shutil.which("bugx")
815
934
  if override:
816
935
  return str(Path(override).resolve()), []
@@ -840,10 +959,23 @@ def _absolutize_server_definitions(
840
959
  spawn——常驻 Hub Daemon 的 cwd 不是工作区,``--root .`` 会解析到宿主 cwd
841
960
  而不是本项目,因此必须写绝对项目根。
842
961
  """
843
- command, prefix = _absolute_bugx_launcher()
844
962
  root_str = str(root)
845
963
  for entry in desired.values():
964
+ direct_engine = entry.pop("_bugx_direct_engine_script", False) is True
846
965
  args = entry.get("args")
966
+ script_name = "bugx_mcp_server.py"
967
+ if direct_engine and isinstance(args, list):
968
+ if args[:2] == ["mcp", "docs"]:
969
+ script_name = "bugx_docs_mcp_server.py"
970
+ args = args[2:]
971
+ elif args[:1] == ["mcp"]:
972
+ args = args[1:]
973
+ else:
974
+ raise CliError("Antigravity 直通 MCP 条目缺少受支持的 `mcp` 子命令")
975
+ entry["args"] = args
976
+ command, prefix = _absolute_bugx_launcher(
977
+ direct_engine=direct_engine, script_name=script_name,
978
+ )
847
979
  if entry.get("command") == "bugx":
848
980
  entry["command"] = command
849
981
  if prefix and isinstance(args, list):
@@ -860,7 +992,7 @@ def _absolutize_server_definitions(
860
992
  return desired
861
993
 
862
994
 
863
- def _mcp_entry_has_relative_paths(entry: object) -> bool:
995
+ def _mcp_entry_has_relative_paths(entry: object, *, include_db: bool = True) -> bool:
864
996
  """宿主 MCP 条目 argv 是否仍携带相对 ``--root`` / ``--db`` 路径 token。
865
997
 
866
998
  ``mcp_write.requires_absolutize=True`` 宿主的**声明性过期**判据:这类宿主的
@@ -882,7 +1014,7 @@ def _mcp_entry_has_relative_paths(entry: object) -> bool:
882
1014
  continue
883
1015
  if token == "--root" and not Path(value).is_absolute():
884
1016
  return True
885
- if token == "--db" and value.startswith(".bugx/"):
1017
+ if include_db and token == "--db" and value.startswith(".bugx/"):
886
1018
  return True
887
1019
  return False
888
1020
 
@@ -938,8 +1070,8 @@ def _same_mcp_arg(got: object, want: object, root: Path | None = None) -> bool:
938
1070
 
939
1071
  def _launcher_kind(command: str) -> str:
940
1072
  """启动器类别:``bugx``(原生启动器)/ ``python``(解释器)/ ``other:<name>``。"""
941
- name = Path(command).name
942
- if name in {"bugx", "bugx.js"}:
1073
+ name = os.path.normcase(Path(command).name)
1074
+ if name in {"bugx", "bugx.exe", "bugx.js"}:
943
1075
  return "bugx"
944
1076
  if name.startswith("python") or name.startswith("pypy"):
945
1077
  return "python"
@@ -955,18 +1087,17 @@ def _launchers_equivalent(got_cmd: str, got_args: list, want_cmd: str, want_args
955
1087
  return got_cmd == want_cmd
956
1088
  if {got_kind, want_kind} != {"bugx", "python"}:
957
1089
  return False
958
- prefix = _PYTHON_MODULE_LAUNCHER_PREFIX
959
- if got_kind == "python" and list(got_args[: len(prefix)]) != prefix:
1090
+ if got_kind == "python" and _strip_launcher_prefix(got_args) == list(got_args):
960
1091
  return False
961
- if want_kind == "python" and list(want_args[: len(prefix)]) != prefix:
1092
+ if want_kind == "python" and _strip_launcher_prefix(want_args) == list(want_args):
962
1093
  return False
963
1094
  return True
964
1095
 
965
1096
 
966
1097
  def _strip_launcher_prefix(args: list) -> list:
967
- prefix = _PYTHON_MODULE_LAUNCHER_PREFIX
968
- if list(args[: len(prefix)]) == prefix:
969
- return list(args[len(prefix):])
1098
+ for prefix in (_SAFE_PYTHON_MODULE_LAUNCHER_PREFIX, _PYTHON_MODULE_LAUNCHER_PREFIX):
1099
+ if list(args[: len(prefix)]) == prefix:
1100
+ return list(args[len(prefix):])
970
1101
  return list(args)
971
1102
 
972
1103
 
@@ -1174,7 +1305,7 @@ def _expand_pinned_expected(expected: list[str], root: Path | None) -> list[str]
1174
1305
 
1175
1306
 
1176
1307
  def _mcp_tokens_match(
1177
- actual: list[str], expected: list[str], root: Path | None = None,
1308
+ actual: list[str] | None, expected: list[str], root: Path | None = None,
1178
1309
  ) -> bool:
1179
1310
  """比较宿主 MCP 条目 tokens 与 pinned 模板,按**语义**而非字面。
1180
1311
 
@@ -1186,7 +1317,7 @@ def _mcp_tokens_match(
1186
1317
  ``_tokens_equivalent``(启动器类别 + 逐参路径等价)。角色/子命令/顺序仍严格
1187
1318
  相等,所以「指向别的项目」「角色写错」「db 写错」依旧判过期。
1188
1319
  """
1189
- return _tokens_equivalent(actual, _expand_pinned_expected(expected, root), root)
1320
+ return bool(actual) and _tokens_equivalent(actual, _expand_pinned_expected(expected, root), root)
1190
1321
 
1191
1322
 
1192
1323
  def _host_mcp_entry_is_current(
@@ -1197,6 +1328,12 @@ def _host_mcp_entry_is_current(
1197
1328
  return False
1198
1329
  if entry.get("disabled") is True or entry.get("enabled") is False:
1199
1330
  return False
1331
+ if name == "bugx-docs" and isinstance(entry.get("url"), str) and entry["url"].strip():
1332
+ try:
1333
+ from core.host_runtime.mcp_process_tracker import probe_remote_docs_mcp
1334
+ return bool(probe_remote_docs_mcp({"bugx-docs": entry}).get("healthy"))
1335
+ except Exception:
1336
+ return False
1200
1337
  expected = OPENCODE_PINNED_MCP_COMMANDS.get(name)
1201
1338
  if not expected:
1202
1339
  return False
@@ -1204,6 +1341,31 @@ def _host_mcp_entry_is_current(
1204
1341
  return _mcp_tokens_match(actual, expected, root)
1205
1342
 
1206
1343
 
1344
+ def _qoder_mcp_entry_is_current(name: str, entry: object, root: Path | None) -> bool:
1345
+ """Check project binding and the Windows launcher used by Qoder Desktop."""
1346
+ # The Docs server resolves a relative database path under its explicit root.
1347
+ if not (
1348
+ isinstance(entry, dict)
1349
+ and not _mcp_entry_has_relative_paths(entry, include_db=False)
1350
+ and _host_mcp_entry_is_current(name, entry, root)
1351
+ ):
1352
+ return False
1353
+ if os.name != "nt":
1354
+ return True
1355
+ command, environment = _qoder_windows_mcp_launcher()
1356
+ args = entry.get("args")
1357
+ current_env = entry.get("env", {})
1358
+ return (
1359
+ isinstance(entry.get("command"), str)
1360
+ and os.path.normcase(entry["command"]) == os.path.normcase(command)
1361
+ and isinstance(args, list)
1362
+ and args[:len(_SAFE_PYTHON_MODULE_LAUNCHER_PREFIX)] == _SAFE_PYTHON_MODULE_LAUNCHER_PREFIX
1363
+ and isinstance(current_env, dict)
1364
+ and all(current_env.get(key) == value for key, value in environment.items())
1365
+ and (bool(environment) or current_env.get("BUGX_CLI_SOURCE") != "npm")
1366
+ )
1367
+
1368
+
1207
1369
  def _load_json_object(path: Path, label: str) -> dict[str, object]:
1208
1370
  if path.is_symlink():
1209
1371
  raise CliError(_i18n_exc("plugin.mcp_symlink_config_refused", f"拒绝写入符号链接 {label} 配置: {path}", label=label, path=path))
@@ -1221,7 +1383,12 @@ def _load_json_object(path: Path, label: str) -> dict[str, object]:
1221
1383
 
1222
1384
 
1223
1385
  def write_host_mcp_config(
1224
- root: Path, host_name: str, *, optional_names: set[str] | None = None,
1386
+ root: Path,
1387
+ host_name: str,
1388
+ *,
1389
+ optional_names: set[str] | None = None,
1390
+ docs_transport: str | None = None,
1391
+ docs_remote_url: str | None = None,
1225
1392
  ) -> tuple[str, Path, Path | None, bool]:
1226
1393
  """Idempotently register both BugX MCP channels in a host-native file.
1227
1394
 
@@ -1293,7 +1460,10 @@ def write_host_mcp_config(
1293
1460
  # 产出死配置(Codex 从不加载 ``.codex/config.json``),因此直接委托插件,
1294
1461
  # 不再复制一份宿主实现。
1295
1462
  desired = _host_supervisor_server_definitions(
1296
- shape=str(host_name).strip().casefold(), optional_names=optional_names,
1463
+ shape=str(host_name).strip().casefold(),
1464
+ optional_names=optional_names,
1465
+ docs_transport=docs_transport,
1466
+ docs_remote_url=docs_remote_url,
1297
1467
  )
1298
1468
  result = migrated.bootstrap(root, desired)
1299
1469
  relpath = migrated.project_relpath or ""
@@ -1333,7 +1503,10 @@ def write_host_mcp_config(
1333
1503
  )
1334
1504
  )
1335
1505
  desired = _host_supervisor_server_definitions(
1336
- shape=str(host_name).strip().casefold(), optional_names=optional_names,
1506
+ shape=str(host_name).strip().casefold(),
1507
+ optional_names=optional_names,
1508
+ docs_transport=docs_transport,
1509
+ docs_remote_url=docs_remote_url,
1337
1510
  )
1338
1511
  if migrated.requires_absolutize:
1339
1512
  # 宿主声明 ``requires_absolutize=True`` 时按契约落盘**绝对**根(D3
@@ -1352,7 +1525,12 @@ def write_host_mcp_config(
1352
1525
  payload[servers_key] = servers
1353
1526
  if not isinstance(servers, dict):
1354
1527
  raise CliError(_i18n_exc("plugin.funide_servers_not_object", f"FunIDE 配置 {servers_key} 不是对象,拒绝写入: {target}", servers_key=servers_key, target=target))
1355
- desired = _host_supervisor_server_definitions(shape="funide", optional_names=optional_names)
1528
+ desired = _host_supervisor_server_definitions(
1529
+ shape="funide",
1530
+ optional_names=optional_names,
1531
+ docs_transport=docs_transport,
1532
+ docs_remote_url=docs_remote_url,
1533
+ )
1356
1534
  elif host_name in {"chatgpt", "workbuddy", "codebuddy"}:
1357
1535
  # pi / dsh 已迁移为插件:分别走上方通用 JSON 骨架分支(requires_absolutize
1358
1536
  # 声明绝对化)与全局分支(project_relpath=None),这里的遗留路径已不可达。
@@ -1369,18 +1547,32 @@ def write_host_mcp_config(
1369
1547
  desired = _host_supervisor_server_definitions(
1370
1548
  shape="workbuddy" if host_name == "codebuddy" else host_name,
1371
1549
  optional_names=optional_names,
1550
+ docs_transport=docs_transport,
1551
+ docs_remote_url=docs_remote_url,
1372
1552
  )
1373
1553
  elif host_name == "qoder":
1374
- target = root / ".qoder" / "mcp.json"
1554
+ target = root / QODER_PROJECT_MCP_PATHS[0]
1375
1555
  payload = _load_json_object(target, "Qoder")
1376
1556
  servers_key = "mcpServers"
1377
1557
  servers = payload.get(servers_key)
1378
- if servers is None:
1558
+ if servers_key not in payload:
1379
1559
  servers = {}
1380
1560
  payload[servers_key] = servers
1381
1561
  if not isinstance(servers, dict):
1382
1562
  raise CliError(_i18n_exc("plugin.qoder_servers_not_object", f"Qoder 配置 {servers_key} 不是对象,拒绝写入: {target}", servers_key=servers_key, target=target))
1383
1563
  desired = _host_supervisor_server_definitions(shape="qoder", optional_names=optional_names)
1564
+ windows_launcher = _qoder_windows_mcp_launcher() if os.name == "nt" else None
1565
+ # Qoder Desktop can spawn stdio from its application directory.
1566
+ for entry in desired.values():
1567
+ args = entry.get("args")
1568
+ if isinstance(args, list):
1569
+ entry["args"] = _expand_pinned_expected(args, root)
1570
+ if windows_launcher is not None:
1571
+ command, environment = windows_launcher
1572
+ entry["command"] = command
1573
+ entry["args"] = [*_SAFE_PYTHON_MODULE_LAUNCHER_PREFIX, *entry["args"]]
1574
+ if environment:
1575
+ entry["env"] = environment
1384
1576
  elif host_name == "trea":
1385
1577
  # DOC-169:补全 Trea 的项目级 MCP 写入(flat 形态,与 qoder 同构)。
1386
1578
  target = root / ".trea" / "mcp.json"
@@ -1406,6 +1598,9 @@ def write_host_mcp_config(
1406
1598
  # 全局作用域宿主按「与本次绝对化期望逐字段相等」判定时效,不能用相对 token。
1407
1599
  def _entry_is_current(name: str, current: object) -> bool:
1408
1600
  return _absolute_entry_is_current(name, current, desired)
1601
+ elif host_name == "qoder":
1602
+ def _entry_is_current(name: str, current: object) -> bool:
1603
+ return _qoder_mcp_entry_is_current(name, current, root)
1409
1604
  else:
1410
1605
  _absolutize_facet = engine_host_mcp_write(host_name)
1411
1606
  if _absolutize_facet is not None and _absolutize_facet.requires_absolutize:
@@ -1415,13 +1610,24 @@ def write_host_mcp_config(
1415
1610
  # 同根重跑逐字段相等 ⇒ unchanged(幂等,不依赖 CLI 进程 cwd)。
1416
1611
  if _mcp_entry_has_relative_paths(current):
1417
1612
  return False
1613
+ # 直通引擎脚本等宿主专属启动器也属于声明性契约的一部分;
1614
+ # 不能只拿通用 pinned ``bugx mcp`` 模板比较,否则旧启动器会
1615
+ # 被误判为 current,导致 ACP 冷启动超时的修复永远不落盘。
1616
+ return _absolute_entry_is_current(name, current, desired)
1617
+ elif target == root / QODER_PROJECT_MCP_PATHS[0]:
1618
+ # Other hosts sharing the root manifest can reuse Qoder's absolute binding.
1619
+ def _entry_is_current(name: str, current: object) -> bool:
1418
1620
  return _host_mcp_entry_is_current(name, current, root)
1419
1621
  else:
1420
1622
  _entry_is_current = _host_mcp_entry_is_current
1421
1623
  optional_managed = {"playwright", "postmcp"}
1422
1624
  for name in optional_managed - set(optional_names or set()):
1423
1625
  current = servers.get(name)
1424
- if _entry_is_current(name, current):
1626
+ is_managed = (
1627
+ _host_mcp_entry_is_current(name, current, root)
1628
+ if host_name == "qoder" else _entry_is_current(name, current)
1629
+ )
1630
+ if is_managed:
1425
1631
  servers.pop(name, None)
1426
1632
  changed = True
1427
1633
  for name, expected in desired.items():
@@ -1430,9 +1636,37 @@ def write_host_mcp_config(
1430
1636
  servers[name] = copy.deepcopy(expected)
1431
1637
  changed = True
1432
1638
  continue
1433
- if not _entry_is_current(name, current):
1639
+ drop_cwd = host_name == "qoder" and name in HOST_ALL_MCP and "cwd" in current
1640
+ entry_is_current = _entry_is_current(name, current)
1641
+ if name == "bugx-docs" and entry_is_current:
1642
+ effective_transport = resolve_effective_docs_transport(docs_transport, docs_remote_url)
1643
+ if effective_transport == "remote" and current.get("url") != expected.get("url"):
1644
+ entry_is_current = False
1645
+ elif effective_transport == "stdio" and isinstance(current.get("url"), str):
1646
+ entry_is_current = False
1647
+ if drop_cwd or not entry_is_current:
1434
1648
  merged = copy.deepcopy(current)
1435
- merged.update(copy.deepcopy(expected))
1649
+ if not entry_is_current:
1650
+ merged.update(copy.deepcopy(expected))
1651
+ if host_name == "qoder" and os.name == "nt":
1652
+ old_env = current.get("env")
1653
+ if isinstance(old_env, dict):
1654
+ environment = dict(old_env)
1655
+ if environment.get("BUGX_CLI_SOURCE") == "npm":
1656
+ for key in _QODER_NPM_ENV_KEYS:
1657
+ environment.pop(key, None)
1658
+ environment.update(expected.get("env", {}))
1659
+ merged["env"] = environment
1660
+ elif "env" not in expected:
1661
+ merged.pop("env", None)
1662
+ if name == "bugx-docs":
1663
+ if "url" in expected:
1664
+ merged.pop("command", None)
1665
+ merged.pop("args", None)
1666
+ elif "command" in expected:
1667
+ merged.pop("url", None)
1668
+ if drop_cwd:
1669
+ merged.pop("cwd")
1436
1670
  servers[name] = merged
1437
1671
  changed = True
1438
1672
  upgraded = True
@@ -1501,20 +1735,30 @@ def _read_host_json_servers(path: Path, shape: str) -> dict[str, object]:
1501
1735
  def _validate_host_supervisor_mcp(
1502
1736
  candidates: tuple[tuple[Path, str], ...],
1503
1737
  root: Path | None = None,
1738
+ *,
1739
+ merge_servers: bool = False,
1740
+ entry_is_current: Callable[[str, object, Path | None], bool] = _host_mcp_entry_is_current,
1504
1741
  ) -> tuple[bool, str]:
1505
- """Require current, enabled host and worker entries in one native config.
1742
+ """Require current, enabled BugX entries in the host's effective config.
1506
1743
 
1507
1744
  ``root`` 用于判定用户级绝对 ``--root`` 是否指向**本项目**(语义等价比对),
1508
1745
  缺省时只接受 pinned 相对形式。
1509
1746
  """
1747
+ configs = [
1748
+ (str(path), servers)
1749
+ for path, shape in candidates
1750
+ if (servers := _read_host_json_servers(path, shape))
1751
+ ]
1752
+ if merge_servers and configs:
1753
+ # Candidates are in load order. A higher-priority definition replaces
1754
+ # the whole server entry, including an explicitly disabled entry.
1755
+ merged = {name: entry for _, servers in configs for name, entry in servers.items()}
1756
+ configs = [(" + ".join(path for path, _ in configs), merged)]
1510
1757
  partial: list[str] = []
1511
- for path, shape in candidates:
1512
- servers = _read_host_json_servers(path, shape)
1513
- if not servers:
1514
- continue
1758
+ for path, servers in configs:
1515
1759
  missing_or_stale = [
1516
1760
  name for name in HOST_ALL_MCP
1517
- if not _host_mcp_entry_is_current(name, servers.get(name), root)
1761
+ if not entry_is_current(name, servers.get(name), root)
1518
1762
  ]
1519
1763
  if not missing_or_stale:
1520
1764
  return True, _i18n_prompt("plugin.mcp_registered", f"已在 {path} 注册并启用 bugx-supervisor host/worker 双通道与 docs 服务", path=path)
@@ -2100,7 +2344,7 @@ def _host_project_mcp_config_target(root: Path, host_name: str) -> tuple[Path, s
2100
2344
  }
2101
2345
  return root / rel_map[host_name], "mcpServers"
2102
2346
  if host_name == "qoder":
2103
- return root / ".qoder" / "mcp.json", "mcpServers"
2347
+ return root / QODER_PROJECT_MCP_PATHS[0], "mcpServers"
2104
2348
  if host_name == "trea":
2105
2349
  return root / ".trea" / "mcp.json", "mcpServers"
2106
2350
  if host_name == "opencode":
@@ -2156,7 +2400,14 @@ def _remove_host_mcp_entry(
2156
2400
  preserved.extend(str(item) for item in (outcome.get("preserved") or ()))
2157
2401
  return
2158
2402
 
2159
- def _is_bugx_mcp_entry(name: str, entry: object) -> bool:
2403
+ def _is_bugx_mcp_entry(name: str, entry: object, *, shared: bool) -> bool:
2404
+ if shared:
2405
+ return name in HOST_ALL_MCP or (
2406
+ name in {"playwright", "postmcp"}
2407
+ and _mcp_tokens_match(
2408
+ _host_mcp_command_tokens(entry), OPENCODE_PINNED_MCP_COMMANDS[name], root,
2409
+ )
2410
+ )
2160
2411
  if name in HOST_ALL_MCP or "bugx" in name.lower():
2161
2412
  return True
2162
2413
  tokens = _host_mcp_command_tokens(entry)
@@ -2203,7 +2454,8 @@ def _remove_host_mcp_entry(
2203
2454
  if not isinstance(servers, dict):
2204
2455
  continue
2205
2456
 
2206
- bugx_keys = [k for k, v in servers.items() if _is_bugx_mcp_entry(k, v)]
2457
+ shared = path == root / QODER_PROJECT_MCP_PATHS[0]
2458
+ bugx_keys = [k for k, v in servers.items() if _is_bugx_mcp_entry(k, v, shared=shared)]
2207
2459
  if not bugx_keys:
2208
2460
  continue
2209
2461
 
@@ -2257,17 +2509,6 @@ def _remove_claude_mcp_entry(
2257
2509
  )
2258
2510
 
2259
2511
 
2260
- def _remove_qoder_mcp_entry(
2261
- root: Path, removed: list[str], preserved: list[str], *, backup_host: str = "qoder",
2262
- backup_dir: Path | None = None,
2263
- ) -> None:
2264
- """Remove BugX supervisor MCP channels from .qoder/mcp.json on qoder uninstall."""
2265
- _remove_host_mcp_entry(
2266
- root, "qoder", removed, preserved,
2267
- backup_host=backup_host, backup_dir=backup_dir,
2268
- )
2269
-
2270
-
2271
2512
  def _remove_dsh_project_files(
2272
2513
  root: Path, removed: list[str], preserved: list[str],
2273
2514
  records: list[object] | None = None, *, backup_host: str = "dsh",
@@ -2362,7 +2603,7 @@ def _remove_dsh_user_preset(
2362
2603
  for child in preset_dir.iterdir():
2363
2604
  if child.is_file() and not child.is_symlink():
2364
2605
  _backup_uninstall_file(root, backup_host, child, backup_dir)
2365
- shutil.rmtree(preset_dir)
2606
+ _remove_tree_force(preset_dir)
2366
2607
  removed.append("~/.dsh/.agent-presets/bugx(已显式清理全局 DSH 预设)")
2367
2608
  except OSError as exc:
2368
2609
  preserved.append(f"~/.dsh/.agent-presets/bugx(清理失败:{exc})")
@@ -2658,7 +2899,7 @@ def _restore_reset_entries(moved: list[tuple[Path, Path]]) -> None:
2658
2899
  if source.is_symlink() or source.is_file():
2659
2900
  source.unlink(missing_ok=True)
2660
2901
  elif source.is_dir():
2661
- shutil.rmtree(source, ignore_errors=True)
2902
+ _remove_tree_force(source)
2662
2903
  shutil.move(str(destination), str(source))
2663
2904
 
2664
2905
 
@@ -2677,7 +2918,7 @@ def _clean_reset_entries(entries: list[tuple[Path, str]]) -> None:
2677
2918
  source.unlink(missing_ok=True)
2678
2919
  elif source.is_dir():
2679
2920
  _assert_no_symlink_components(source)
2680
- shutil.rmtree(source, ignore_errors=True)
2921
+ _remove_tree_force(source)
2681
2922
 
2682
2923
 
2683
2924
  def _bootstrap_global_knowledge(root: Path, source: Path) -> None: