bugx-cli 0.1.3 → 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 (129) hide show
  1. package/core/README.md +5 -3
  2. package/core/assets/bugx-wechat-group.png +0 -0
  3. package/core/bugx.md +2 -2
  4. package/core/bugx_paths.py +10 -2
  5. package/core/bundled_docs/OVERVIEW.md +310 -0
  6. package/core/bundled_docs/README.md +10 -0
  7. package/core/bundled_docs/README_EN.md +278 -0
  8. package/core/bundled_docs/ai/01_AI_REFERENCE.md +833 -0
  9. package/core/bundled_docs/ai/02_AI_USAGE.md +161 -0
  10. package/core/bundled_docs/ai/03_AI_COMMANDS.md +322 -0
  11. package/core/bundled_docs/guides/01_USER_GUIDE.md +887 -0
  12. package/core/bundled_docs/guides/02_COMMANDS.md +935 -0
  13. package/core/bundled_docs/guides/03_TROUBLESHOOTING.md +763 -0
  14. package/core/bundled_docs/guides/04_CLOUD_AUTH_AND_SYNC_COOKBOOK.md +48 -0
  15. package/core/bundled_docs/guides/05_HOST_MATRIX_AND_DISPATCH.md +23 -0
  16. package/core/bundled_docs/guides/06_PROBES_AND_POC_COOKBOOK.md +49 -0
  17. package/core/bundled_docs/guides/07_LIFECYCLE_AND_RECOVERY_STATES.md +46 -0
  18. package/core/bundled_docs/guides/08_LESSONS_AND_PRIVACY_BOUNDARY.md +35 -0
  19. package/core/bundled_docs/hosts/bugx-claude_SKILL.md +326 -0
  20. package/core/bundled_docs/hosts/bugx-dsh_SKILL.md +229 -0
  21. package/core/bundled_docs/hosts/bugx-opencode_SKILL.md +129 -0
  22. package/core/bundled_docs/hosts/bugx-zcode_SKILL.md +459 -0
  23. package/core/bundled_docs/hosts/bugx_SKILL.md +118 -0
  24. package/core/bundled_docs/hosts/cline_bugx_SKILL.md +69 -0
  25. package/core/bundled_docs/hosts/platform_bugx_SKILL.md +50 -0
  26. package/core/bundled_docs/manifest.json +140 -0
  27. package/core/bundled_docs/reference/01_ENVIRONMENT_VARIABLES.md +421 -0
  28. package/core/bundled_docs/reference/04_REPOSITORY_TOPOLOGY.md +180 -0
  29. package/core/cli-help.txt +7 -3
  30. package/core/cloud_sync/cloud_client.py +81 -2
  31. package/core/cloud_sync/endpoint_router.py +22 -9
  32. package/core/cloud_sync/issue_uploader.py +297 -0
  33. package/core/cloud_sync/sensitive_filter.py +77 -7
  34. package/core/contracts/AGENT_GUIDE.md +3 -9
  35. package/core/contracts/README.md +1 -1
  36. package/core/contracts/bugx-runtime-contract.md +10 -20
  37. package/core/contracts/bugx-worker.md +1 -1
  38. package/core/engine-integrity.json +209 -93
  39. package/core/host_acp/antigravity.py +153 -0
  40. package/core/host_runtime/adapters.py +5 -1
  41. package/core/host_runtime/antigravity.py +162 -0
  42. package/core/host_runtime/host_bootstrap.py +18 -7
  43. package/core/host_runtime/host_evaluators.py +4 -4
  44. package/core/host_runtime/host_registry.py +2 -1
  45. package/core/host_runtime/mcp_process_tracker.py +30 -3
  46. package/core/host_runtime/mcp_registry_gate.py +34 -11
  47. package/core/hosts/antigravity.py +115 -0
  48. package/core/hosts/codex.py +3 -0
  49. package/core/hosts/dsh.py +42 -23
  50. package/core/hosts/minimax.py +5 -4
  51. package/core/i18n.py +94 -5
  52. package/core/infra/README.md +1 -1
  53. package/core/infra/build_info.py +2 -2
  54. package/core/launch_phases/README.md +2 -2
  55. package/core/launch_phases/startup_version_gate.py +2 -2
  56. package/core/launch_phases/supervisor_bridge.py +2 -0
  57. package/core/launch_phases/supervisor_degraded.py +7 -5
  58. package/core/ledger/README.md +1 -1
  59. package/core/locales/en-US.json +3 -3
  60. package/core/locales/zh-CN.json +3 -3
  61. package/core/mcp_runtime_support/environment.py +6 -1
  62. package/core/metadata.txt +1 -1
  63. package/core/planning/README.md +1 -1
  64. package/core/planning/prompt_harness.py +2 -2
  65. package/core/probes/codebase_memory_probe.py +43 -24
  66. package/core/probes/probe_registry.py +10 -7
  67. package/core/prompts/command_routing_en.md +6 -5
  68. package/core/prompts/command_routing_zh.md +6 -5
  69. package/core/repair/rsi_rounds.py +3 -0
  70. package/core/repair/self_heal.py +160 -6
  71. package/core/retrieval/README.md +1 -1
  72. package/core/runtime/README.md +1 -1
  73. package/core/runtime/scenario_eval.py +5 -1
  74. package/core/runtime/tool_install_targets.py +12 -2
  75. package/core/skills/README.md +4 -2
  76. package/core/skills/bugx_docs_cloud_sync.py +658 -0
  77. package/core/skills/bugx_docs_mcp_server.py +966 -140
  78. package/core/supervisor/README.md +1 -1
  79. package/core/supervisor/worker_execution.py +16 -3
  80. package/core/webui/docs_session_service.py +40 -2
  81. package/core/webui/mcp_inspector.py +6 -6
  82. package/ecosystem/integrations/cline/skills/bugx/SKILL.md +46 -46
  83. package/ecosystem/integrations/dsh/agents/bugx.md +2 -1
  84. package/ecosystem/integrations/dsh/mcp/package.json +1 -1
  85. package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +5 -5
  86. package/ecosystem/integrations/dsh/ui/package.json +1 -1
  87. package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +2 -2
  88. package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
  89. package/ecosystem/integrations/pi/skills/bugx/SKILL.md +5 -5
  90. package/ecosystem/integrations/qoder/CONNECTORS.md +11 -23
  91. package/ecosystem/integrations/qoder/connector-meta.json +1 -1
  92. package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
  93. package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +8 -7
  94. package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
  95. package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
  96. package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
  97. package/ecosystem/plugins/bugx/agents/bugx-worker.md +14 -18
  98. package/ecosystem/plugins/bugx/agents/bugx.md +45 -49
  99. package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +7 -7
  100. package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +2 -2
  101. package/interfaces/cli/bugx_cli/__init__.py +1 -1
  102. package/interfaces/cli/bugx_cli/cli.py +138 -8
  103. package/interfaces/cli/bugx_cli/commands/agent.py +376 -69
  104. package/interfaces/cli/bugx_cli/commands/cloud.py +42 -1
  105. package/interfaces/cli/bugx_cli/commands/doctor.py +650 -223
  106. package/interfaces/cli/bugx_cli/commands/guide.py +143 -0
  107. package/interfaces/cli/bugx_cli/commands/issue.py +262 -0
  108. package/interfaces/cli/bugx_cli/commands/lifecycle.py +55 -25
  109. package/interfaces/cli/bugx_cli/commands/plugin.py +295 -54
  110. package/interfaces/cli/bugx_cli/commands/plugin_antigravity.py +350 -0
  111. package/interfaces/cli/bugx_cli/commands/plugin_claude.py +2 -2
  112. package/interfaces/cli/bugx_cli/commands/plugin_kimi.py +154 -62
  113. package/interfaces/cli/bugx_cli/commands/plugin_minimax.py +308 -108
  114. package/interfaces/cli/bugx_cli/commands/system.py +11 -1
  115. package/interfaces/cli/bugx_cli/common.py +39 -8
  116. package/interfaces/cli/bugx_cli/host_adapters.py +40 -3
  117. package/interfaces/cli/bugx_cli/hosts/registry.py +3 -2
  118. package/interfaces/cli/bugx_cli/hosts/template_engine.py +21 -2
  119. package/interfaces/cli/bugx_cli/infra/__init__.py +4 -0
  120. package/interfaces/cli/bugx_cli/infra/ai_advisor.py +14 -12
  121. package/interfaces/cli/bugx_cli/infra/engine_installer.py +76 -10
  122. package/interfaces/cli/bugx_cli/infra/host_sync.py +66 -1
  123. package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +240 -50
  124. package/package.json +3 -2
  125. package/pyproject.toml +22 -2
  126. package/scripts/sync-version.mjs +1 -1
  127. package/skills/README.md +1 -2
  128. package/skills/platform/bugx/SKILL.md +50 -0
  129. package/skills/platform/bugx-user/SKILL.md +0 -92
@@ -22,6 +22,7 @@ from ..common import _close_bugx_logging
22
22
  from ..infra.engine_installer import refresh_i18n_after_engine_swap
23
23
  from ..common import *
24
24
  from ..hosts.registry import (
25
+ QODER_PROJECT_MCP_PATHS,
25
26
  engine_host_cli_hook,
26
27
  engine_host_label,
27
28
  engine_host_plugins,
@@ -61,6 +62,7 @@ from .plugin import (
61
62
  _chatgpt_marketplace,
62
63
  _ensure_chatgpt_plugin,
63
64
  _ensure_zcode_plugin,
65
+ _qoder_mcp_entry_is_current,
64
66
  _sweep_legacy_skill_entry,
65
67
  _sweep_legacy_zcode_project_entries,
66
68
  _prompt_for_hosts,
@@ -104,13 +106,18 @@ class _CliProgress:
104
106
  percent = max(0, min(100, percent))
105
107
  filled = self._WIDTH * percent // 100
106
108
  line = f"[bugx] 进度 [{('=' * filled).ljust(self._WIDTH, '-')}] {percent:3d}% {label}"
107
- sys.stderr.write("\r" + line)
109
+ cols = sum(2 if ord(ch) > 127 else 1 for ch in line)
110
+ prev = int(getattr(self, "_last_cols", 0))
111
+ pad = " " * max(0, prev - cols)
112
+ self._last_cols = cols
113
+ sys.stderr.write("\r" + line + pad)
108
114
  sys.stderr.flush()
109
115
 
110
116
  def finish(self, label: str = "完成") -> None:
111
117
  if not self.enabled:
112
118
  return
113
119
  self.update(100, label)
120
+ self._last_cols = 0
114
121
  sys.stderr.write("\n")
115
122
  sys.stderr.flush()
116
123
 
@@ -218,7 +225,6 @@ _AGENT_INSTALL_SNAPSHOT_FILES = (
218
225
  ".agents/plugins/marketplace.json",
219
226
  ".qoder/agents/bugx.md",
220
227
  ".qoder/agents/bugx-worker.md",
221
- ".qoder/mcp.json",
222
228
  ".github/agents/bugx.agent.md",
223
229
  ".trea/agents/bugx.md",
224
230
  ".trea/mcp.json",
@@ -437,6 +443,8 @@ def _agent_install_snapshot(
437
443
  """
438
444
  staging = Path(tempfile.mkdtemp(prefix="bugx-install-transaction-")).resolve()
439
445
  existed: dict[str, bool] = {}
446
+ if _is_global_home_scope(root):
447
+ return staging, existed
440
448
  try:
441
449
  for relative in _agent_install_surfaces(selected_adapters):
442
450
  target = root / relative
@@ -689,6 +697,8 @@ def _remove_install_snapshot_tree(path: Path) -> None:
689
697
  def _restore_agent_install_snapshot(
690
698
  root: Path, staging: Path, existed: dict[str, bool],
691
699
  ) -> None:
700
+ if _is_global_home_scope(root) or not existed:
701
+ return
692
702
  manifest_path = staging / _AGENT_INSTALL_SNAPSHOT_MANIFEST
693
703
  if manifest_path.is_file():
694
704
  payload = json.loads(manifest_path.read_text(encoding="utf-8"))
@@ -838,6 +848,180 @@ def _select_install_adapters(
838
848
  return tuple(selected)
839
849
 
840
850
 
851
+ def _sync_global_pi_skill_global_mode(root: Path, *, locale: str | None = None) -> None:
852
+ """Install user-level ~/.agents/skills/bugx and ~/.pi skill links without touching root/.pi."""
853
+ skill_src = pi_skill_root() / "SKILL.md"
854
+ if not skill_src.is_file():
855
+ return
856
+ content = add_locale_marker(skill_src.read_text(encoding="utf-8"), locale)
857
+ home = Path.home().resolve()
858
+ agents_skill_parent = (home / ".agents" / "skills").resolve(strict=False)
859
+ if not agents_skill_parent.is_relative_to(home):
860
+ raise CliError(_i18n_exc("agent.pi_global_skill_escaped_user", f"Pi 全局 Skill 目录越出用户目录:{agents_skill_parent}", path=agents_skill_parent))
861
+ _assert_no_symlink_components(agents_skill_parent)
862
+ agents_skill_dir = agents_skill_parent / "bugx"
863
+ _assert_no_symlink_components(agents_skill_dir)
864
+ agents_skill_dir.mkdir(parents=True, exist_ok=True)
865
+ target = agents_skill_dir / "SKILL.md"
866
+ _tx_stage_global(target)
867
+ _atomic_write_global_file_tx(target, content.encode("utf-8"))
868
+ for p_dir in (home / ".pi" / "skills" / "bugx", home / ".pi" / "agent" / "skills" / "bugx"):
869
+ _assert_no_symlink_components(p_dir.parent)
870
+ p_dir.parent.mkdir(parents=True, exist_ok=True)
871
+ if p_dir.is_symlink() or p_dir.exists():
872
+ if not p_dir.is_symlink():
873
+ # Only update inside already-owned file/dir if needed; skip foreign user directories
874
+ existing = p_dir / "SKILL.md"
875
+ if existing.is_file():
876
+ try:
877
+ _atomic_write_global_file_tx(existing, content.encode("utf-8"))
878
+ except OSError:
879
+ pass
880
+ continue
881
+ _atomic_link_or_copy(agents_skill_dir, p_dir, directory=True)
882
+
883
+
884
+ def _finish_global_home_install(
885
+ args: argparse.Namespace,
886
+ *,
887
+ root: Path,
888
+ source: Path,
889
+ selected: tuple[object, ...],
890
+ engine_copied: int,
891
+ engine_skipped: int,
892
+ deployment_locale: str,
893
+ cbm_detail: str,
894
+ ts_detail: str,
895
+ progress: _CliProgress | None = None,
896
+ ) -> int:
897
+ """Complete a User-Global Home Mode (`~`) install without polluting home with project files."""
898
+ del args.force
899
+ global_k = (_global_bugx_dir() / "knowledge").resolve()
900
+ override = os.environ.get("BUGX_GLOBAL_KNOWLEDGE_ROOT")
901
+ if override:
902
+ global_k = Path(override).expanduser().resolve()
903
+ if not (global_k / "global.sqlite3").is_file():
904
+ from .plugin import _bootstrap_global_knowledge
905
+
906
+ _bootstrap_global_knowledge(root, source)
907
+
908
+ selected_names = {str(getattr(adapter, "name", "")) for adapter in selected}
909
+ user_hosts_done: list[str] = []
910
+ project_only_hosts: list[str] = []
911
+ dsh_ui_plugin: dict[str, object] | None = None
912
+ dsh_patch_status: str | None = None
913
+ user_agents_by_host: dict[str, dict[str, object]] = {}
914
+ host_mcp_configs: dict[str, dict[str, object]] = {}
915
+ opencode_user_skill: dict[str, object] | None = None
916
+ workbuddy_user_skill: dict[str, object] | None = None
917
+ workbuddy_custom_expert: dict[str, object] | None = None
918
+
919
+ if progress is not None:
920
+ progress.update(70, "正在装配用户级宿主资产")
921
+
922
+ for adapter in selected:
923
+ name = str(adapter.name)
924
+ if adapter.supports(CAP_PROJECT_PATCH_OVERLAY):
925
+ dsh_patch_status, dsh_ui_plugin = _ensure_dsh_patch(root)
926
+ user_hosts_done.append(name)
927
+ if adapter.supports(CAP_NATIVE_MCP_CONFIG) and name == HOST_NAME_ZCODE:
928
+ item_status, path, _backup, _created = write_host_mcp_config(root, name)
929
+ host_mcp_configs[name] = {
930
+ "path": str(path),
931
+ "status": item_status,
932
+ "session_restart_required": item_status != "unchanged",
933
+ }
934
+ if adapter.supports(CAP_USER_AGENT_REGISTRATION):
935
+ res = adapter.ensure_user_agents(root, source, locale=deployment_locale)
936
+ if isinstance(res, dict):
937
+ user_agents_by_host[name] = res
938
+ if name == HOST_NAME_ZCODE:
939
+ from .plugin_zcode import (
940
+ _upsert_zcode_plugin_dirs,
941
+ _write_zcode_global_plugin,
942
+ )
943
+ _write_zcode_global_plugin(root, source, locale=deployment_locale)
944
+ _upsert_zcode_plugin_dirs(register=None, remove=False)
945
+ user_skill = _ensure_zcode_user_skill(root, source)
946
+ if name in user_agents_by_host:
947
+ user_agents_by_host[name]["user_skill"] = user_skill
948
+ if name not in user_hosts_done:
949
+ user_hosts_done.append(name)
950
+ if adapter.supports(CAP_GLOBAL_AGENT_LINK):
951
+ _register_global_opencode_agent(root)
952
+ opencode_user_skill = _ensure_opencode_user_skill(
953
+ root, source, backup_label=name,
954
+ )
955
+ if name not in user_hosts_done:
956
+ user_hosts_done.append(name)
957
+ if adapter.supports(CAP_GLOBAL_SKILL_LINK):
958
+ _sync_global_pi_skill_global_mode(root, locale=deployment_locale)
959
+ if name not in user_hosts_done:
960
+ user_hosts_done.append(name)
961
+ if adapter.supports(CAP_USER_LEVEL_ARTIFACT):
962
+ wb_content = adapter.render(global_engine_root() / "bugx.md", locale=deployment_locale)
963
+ workbuddy_user_skill = _ensure_workbuddy_user_skill(root, wb_content)
964
+ workbuddy_custom_expert = _ensure_workbuddy_custom_expert(root, wb_content)
965
+ for cfg_root in _workbuddy_config_roots():
966
+ if cfg_root != workbuddy_user_skill_root():
967
+ _ensure_workbuddy_custom_expert(root, wb_content, config_root=cfg_root)
968
+ if name not in user_hosts_done:
969
+ user_hosts_done.append(name)
970
+
971
+ if adapter.supports(CAP_PROJECT_MCP_CONFIG) or (
972
+ adapter.supports(CAP_NATIVE_MCP_CONFIG) and name not in {HOST_NAME_ZCODE}
973
+ ) or adapter.entry_mode == ENTRY_PLUGIN_CATALOG or name in {"codex", "cline", "trea", "claude", "qoder", "funide", "workbuddy", "pi"}:
974
+ project_only_hosts.append(name)
975
+
976
+ if progress is not None:
977
+ progress.finish("用户全局安装完成")
978
+ mcp_recommendations = _mcp_recommendations(root, installed_hosts=selected_names)
979
+ payload = {
980
+ "mode": "global",
981
+ "global_scope": True,
982
+ "root": str(root),
983
+ "shared_engine": str(global_engine_root()),
984
+ "shared_copied": engine_copied,
985
+ "shared_skipped": engine_skipped,
986
+ "required_tools": {
987
+ "codebase-memory-mcp": cbm_detail,
988
+ "tree-sitter-language-pack": ts_detail,
989
+ },
990
+ "user_level_hosts": sorted(set(user_hosts_done)),
991
+ "project_only_hosts": sorted(set(project_only_hosts)),
992
+ "dsh_patch": dsh_patch_status,
993
+ "dsh_ui_plugin": dsh_ui_plugin,
994
+ "user_agents_by_host": user_agents_by_host,
995
+ "host_mcp_configs": host_mcp_configs,
996
+ "opencode_user_skill": opencode_user_skill,
997
+ "workbuddy_user_skill": workbuddy_user_skill,
998
+ "workbuddy_custom_expert": workbuddy_custom_expert,
999
+ "mcp_recommendations": mcp_recommendations,
1000
+ "status": "installed",
1001
+ "ready": True,
1002
+ }
1003
+ if getattr(args, "json", False):
1004
+ print(json.dumps(payload, ensure_ascii=False, indent=2, default=_json_default))
1005
+ else:
1006
+ print("[bugx] ✓ 用户全局模式安装完成(未在主目录 ~ 创建项目 .bugx/manifest.json 或项目入口)")
1007
+ print(f" 共享引擎:{global_engine_root()}(复制 {engine_copied},未变更跳过 {engine_skipped})")
1008
+ print(f" 全局知识库:{global_k}")
1009
+ print(f" 必需核心工具:codebase-memory-mcp ({cbm_detail});tree-sitter ({ts_detail})")
1010
+ if user_hosts_done:
1011
+ print(f" 用户级宿主资产:{', '.join(sorted(set(user_hosts_done)))}")
1012
+ if dsh_ui_plugin is not None:
1013
+ detail_ui = str(dsh_ui_plugin.get("detail") or dsh_ui_plugin.get("status") or "")
1014
+ print(f" DSH UI 插件:{dsh_ui_plugin.get('root')}({detail_ui})")
1015
+ if project_only_hosts:
1016
+ print(
1017
+ " 提示:以下宿主需绑定具体工作区配置(当前仅完成全局层装配,未写入主目录 ~):"
1018
+ + ", ".join(sorted(set(project_only_hosts)))
1019
+ )
1020
+ print(" 进入具体项目目录后运行 `bugx install`(或 `bugx install --root <PROJECT>`)完成项目绑定。")
1021
+ _print_mcp_recommendations(mcp_recommendations)
1022
+ return 0
1023
+
1024
+
841
1025
  def _command_agent_impl(
842
1026
  args: argparse.Namespace,
843
1027
  *,
@@ -879,15 +1063,17 @@ def _command_agent_impl(
879
1063
  # Validate an existing host manifest before any resource or runtime writes;
880
1064
  # a corrupt manifest must never cause a partial installation and then fail.
881
1065
  existing_record = root / ".bugx" / "hosts.json"
882
- if existing_record.exists() or existing_record.is_symlink():
1066
+ is_home_scope = _is_global_home_scope(root)
1067
+ if not is_home_scope and (existing_record.exists() or existing_record.is_symlink()):
883
1068
  _merge_host_records(existing_record, [])
884
1069
 
885
1070
  # Validate host catalogs or prerequisites before shared runtime writes so
886
1071
  # an invalid or conflicting catalog cannot leave a partial install.
887
- for adapter in selected:
888
- adapter.pre_validate(root)
889
- if any(adapter.supports(CAP_PROJECT_MCP_CONFIG) for adapter in selected):
890
- _preflight_opencode_mcp_config(root)
1072
+ if not is_home_scope:
1073
+ for adapter in selected:
1074
+ adapter.pre_validate(root)
1075
+ if any(adapter.supports(CAP_PROJECT_MCP_CONFIG) for adapter in selected):
1076
+ _preflight_opencode_mcp_config(root)
891
1077
  if progress is not None:
892
1078
  progress.update(15, "已完成配置校验")
893
1079
 
@@ -895,7 +1081,10 @@ def _command_agent_impl(
895
1081
  source = asset_root()
896
1082
  # DOC-004 Layout 2:项目不再承载可执行 core。旧项目必须显式选择
897
1083
  # 破坏性迁移;迁移会先转移运行态/项目数据,再把旧 core 移出活动布局。
898
- removed_legacy_core = _require_global_only_layout(root)
1084
+ if not is_home_scope:
1085
+ removed_legacy_core = _require_global_only_layout(root)
1086
+ else:
1087
+ removed_legacy_core = False
899
1088
  if progress is not None:
900
1089
  progress.update(20, "正在安装共享引擎")
901
1090
  engine = global_engine_root()
@@ -925,6 +1114,38 @@ def _command_agent_impl(
925
1114
  )
926
1115
  _ensure_global_cli_symlinks()
927
1116
 
1117
+ if progress is not None:
1118
+ progress.update(45, "校验并装配必需核心依赖(codebase-memory / tree-sitter)")
1119
+ _ensure_core_importable()
1120
+ from core.repair.self_heal import (
1121
+ ensure_codebase_memory_ready,
1122
+ ensure_tree_sitter_ready,
1123
+ )
1124
+ cbm_ok, cbm_detail = ensure_codebase_memory_ready(root)
1125
+ if not cbm_ok:
1126
+ raise CliError(
1127
+ f"必需核心依赖 codebase-memory-mcp 安装或校验失败(不可降级放行):{cbm_detail}"
1128
+ )
1129
+ ts_ok, ts_detail = ensure_tree_sitter_ready()
1130
+ if not ts_ok:
1131
+ raise CliError(
1132
+ f"必需核心依赖 tree-sitter-language-pack 安装或校验失败(不可降级放行):{ts_detail}"
1133
+ )
1134
+
1135
+ if is_home_scope:
1136
+ return _finish_global_home_install(
1137
+ args,
1138
+ root=root,
1139
+ source=source,
1140
+ selected=selected,
1141
+ engine_copied=copied,
1142
+ engine_skipped=skipped,
1143
+ deployment_locale=deployment_locale,
1144
+ cbm_detail=cbm_detail,
1145
+ ts_detail=ts_detail,
1146
+ progress=progress,
1147
+ )
1148
+
928
1149
  _layout_module(root).initialize(root, bugx_version=__version__)
929
1150
  _ensure_project_readme(root, source)
930
1151
  # The common runtime is intentionally installed once even when the selected
@@ -932,21 +1153,29 @@ def _command_agent_impl(
932
1153
  _initialize_lesson_ledger(root, source)
933
1154
  _initialize_project_knowledge_snapshots(root, source)
934
1155
  _initialize_life_state(root)
1156
+ from .lifecycle import _ensure_project_startup_todo
1157
+ _ensure_project_startup_todo(root)
935
1158
  if progress is not None:
936
1159
  progress.update(60, "项目运行态初始化完成")
937
1160
  if removed_legacy_core:
938
1161
  print(f"[bugx] 已直接删除旧项目引擎入口:{removed_legacy_core}")
939
1162
  selected_mcp_names = targeted_mcp_names(root)
940
- optional_mcp_names = selected_mcp_names & {"playwright", "postmcp"}
941
- provisioned_optional_mcps = provision_targeted_mcp_runtime(root, optional_mcp_names)
1163
+ # 可选 MCP 能力(playwright/postmcp 等)延迟至实际项目审计 pre 阶段由 AI 与用户决定启用,
1164
+ # 不在 install 阶段触发耗时联网装配。
1165
+ provisioned_optional_mcps: set[str] = set()
942
1166
  opencode_config_status: str | None = None
943
1167
  opencode_config_backup: Path | None = None
944
1168
  host_mcp_configs: dict[str, dict[str, object]] = {}
945
1169
  dsh_patch_status: str | None = None
946
1170
  dsh_ui_plugin: dict[str, object] | None = None
1171
+ docs_transport = getattr(args, "docs_transport", None)
1172
+ docs_remote_url = getattr(args, "docs_remote_url", None)
947
1173
  if any(adapter.supports(CAP_PROJECT_MCP_CONFIG) for adapter in selected):
948
1174
  opencode_config_status, opencode_config_backup = _ensure_opencode_config(
949
- root, selected=selected_mcp_names,
1175
+ root,
1176
+ selected=selected_mcp_names,
1177
+ docs_transport=docs_transport,
1178
+ docs_remote_url=docs_remote_url,
950
1179
  )
951
1180
  if any(adapter.supports(CAP_PROJECT_PATCH_OVERLAY) for adapter in selected):
952
1181
  dsh_patch_status, dsh_ui_plugin = _ensure_dsh_patch(root)
@@ -1199,7 +1428,11 @@ def _command_agent_impl(
1199
1428
  )
1200
1429
  for config_host in config_hosts:
1201
1430
  item_status, path, backup, created = write_host_mcp_config(
1202
- root, config_host, optional_names=provisioned_optional_mcps,
1431
+ root,
1432
+ config_host,
1433
+ optional_names=provisioned_optional_mcps,
1434
+ docs_transport=docs_transport,
1435
+ docs_remote_url=docs_remote_url,
1203
1436
  )
1204
1437
  config_paths.append(str(path))
1205
1438
  if item_status != "unchanged":
@@ -1402,7 +1635,7 @@ def _command_agent_impl(
1402
1635
  if progress is not None:
1403
1636
  progress.update(98, "安装记录已写入")
1404
1637
  progress.finish()
1405
- mcp_recommendations = _mcp_recommendations(root)
1638
+ mcp_recommendations = _mcp_recommendations(root, installed_hosts=selected_names)
1406
1639
  payload = {
1407
1640
  "status": "INSTALLED", "root": str(root),
1408
1641
  "hosts": installed, "shared_copied": copied, "shared_skipped": skipped,
@@ -2015,46 +2248,49 @@ def _ensure_dsh_patch(root: Path) -> tuple[str, dict[str, object] | None]:
2015
2248
  The browser UI package is installed separately into the DSH web profile;
2016
2249
  agent presets do not load ``dsh.client`` modules.
2017
2250
  """
2018
- dsh_dir = root.resolve() / ".dsh"
2019
- dsh_dir.mkdir(parents=True, exist_ok=True)
2020
-
2021
- patch_path = dsh_dir / "patch.yml"
2022
- skill_path = dsh_dir / "skills" / "bugx" / "SKILL.md"
2023
- dsh_skill_path = dsh_dir / "skills" / "bugx-dsh" / "SKILL.md"
2024
- agent_path = dsh_dir / "agents" / "bugx.md"
2251
+ is_home_scope = _is_global_home_scope(root)
2025
2252
  patched = False
2026
- any_existing = any(path.exists() for path in (patch_path, skill_path, dsh_skill_path, agent_path))
2027
-
2028
- # Read bundled templates from integrations/dsh/
2029
- integration_dir = _integration_dir()
2030
- bundled_patch = integration_dir / "dsh" / "dsh-patch.yml"
2031
- bundled_skill = integration_dir / "dsh" / "skills" / "bugx" / "SKILL.md"
2032
- bundled_dsh_skill = integration_dir / "dsh" / "skills" / "bugx-dsh" / "SKILL.md"
2033
- bundled_agent = integration_dir / "dsh" / "agents" / "bugx.md"
2034
-
2035
- for bundled, target in (
2036
- (bundled_patch, patch_path),
2037
- (bundled_skill, skill_path),
2038
- (bundled_dsh_skill, dsh_skill_path),
2039
- (bundled_agent, agent_path),
2040
- ):
2041
- if not bundled.is_file():
2042
- raise CliError(_i18n_exc("agent.dsh_resource_missing", f"缺少 dsh 适配资源:{bundled}", bundled=bundled))
2043
- copied, _skipped, _backup = _write_host_resource(
2044
- root, target, bundled.read_bytes(), "dsh",
2045
- )
2046
- patched = patched or bool(copied)
2047
-
2048
- # 项目 patch 也要带官方 MCP overlay:`bugx doctor` 的「DeepSeek Harness
2049
- # MCP 配置」扫的是项目 `.dsh/patch.yml` 与全局预设,不是 profile patch。
2050
- # 只在 profile 层写入会让 install 之后 doctor 仍报「缺少 bugx-supervisor
2051
- # MCP」——修好调用却报告缺失,是更难排查的破窗。
2052
- if patch_path.is_file():
2053
- project_patch = patch_path.read_text(encoding="utf-8")
2054
- with_overlay = _ensure_official_mcp_overlay(project_patch, root)
2055
- if with_overlay != project_patch:
2056
- _atomic_write_global_file_tx(patch_path, with_overlay.encode("utf-8"))
2057
- patched = True
2253
+ any_existing = False
2254
+ if not is_home_scope:
2255
+ dsh_dir = root.resolve() / ".dsh"
2256
+ dsh_dir.mkdir(parents=True, exist_ok=True)
2257
+
2258
+ patch_path = dsh_dir / "patch.yml"
2259
+ skill_path = dsh_dir / "skills" / "bugx" / "SKILL.md"
2260
+ dsh_skill_path = dsh_dir / "skills" / "bugx-dsh" / "SKILL.md"
2261
+ agent_path = dsh_dir / "agents" / "bugx.md"
2262
+ any_existing = any(path.exists() for path in (patch_path, skill_path, dsh_skill_path, agent_path))
2263
+
2264
+ # Read bundled templates from integrations/dsh/
2265
+ integration_dir = _integration_dir()
2266
+ bundled_patch = integration_dir / "dsh" / "dsh-patch.yml"
2267
+ bundled_skill = integration_dir / "dsh" / "skills" / "bugx" / "SKILL.md"
2268
+ bundled_dsh_skill = integration_dir / "dsh" / "skills" / "bugx-dsh" / "SKILL.md"
2269
+ bundled_agent = integration_dir / "dsh" / "agents" / "bugx.md"
2270
+
2271
+ for bundled, target in (
2272
+ (bundled_patch, patch_path),
2273
+ (bundled_skill, skill_path),
2274
+ (bundled_dsh_skill, dsh_skill_path),
2275
+ (bundled_agent, agent_path),
2276
+ ):
2277
+ if not bundled.is_file():
2278
+ raise CliError(_i18n_exc("agent.dsh_resource_missing", f"缺少 dsh 适配资源:{bundled}", bundled=bundled))
2279
+ copied, _skipped, _backup = _write_host_resource(
2280
+ root, target, bundled.read_bytes(), "dsh",
2281
+ )
2282
+ patched = patched or bool(copied)
2283
+
2284
+ # 项目 patch 也要带官方 MCP overlay:`bugx doctor` 的「DeepSeek Harness
2285
+ # MCP 配置」扫的是项目 `.dsh/patch.yml` 与全局预设,不是 profile patch。
2286
+ # 只在 profile 层写入会让 install 之后 doctor 仍报「缺少 bugx-supervisor
2287
+ # MCP」——修好调用却报告缺失,是更难排查的破窗。
2288
+ if patch_path.is_file():
2289
+ project_patch = patch_path.read_text(encoding="utf-8")
2290
+ with_overlay = _ensure_official_mcp_overlay(project_patch, root)
2291
+ if with_overlay != project_patch:
2292
+ _atomic_write_global_file_tx(patch_path, with_overlay.encode("utf-8"))
2293
+ patched = True
2058
2294
 
2059
2295
  # Deploy BugX's agent preset and the browser UI bundle to their native
2060
2296
  # DSH user-level locations.
@@ -2064,6 +2300,8 @@ def _ensure_dsh_patch(root: Path) -> tuple[str, dict[str, object] | None]:
2064
2300
  except (CliError, OSError) as exc:
2065
2301
  raise CliError(_i18n_exc("agent.dsh_preset_write_failed", f"写入 dsh 全局预设失败:{exc}", exc=exc)) from exc
2066
2302
 
2303
+ if is_home_scope:
2304
+ return ("global_only", ui_plugin)
2067
2305
  if patched:
2068
2306
  return ("patched", ui_plugin) if any_existing else ("created", ui_plugin)
2069
2307
  return ("unchanged", ui_plugin)
@@ -2586,9 +2824,10 @@ def _sync_one_profile_patch(
2586
2824
  else:
2587
2825
  updated = f"{content.rstrip()}\n\n{patch_block}\n"
2588
2826
 
2589
- if root is None:
2590
- raise CliError("_sync_one_profile_patch 需要 root 以绝对化 MCP --root/--db(F-RSI-20261119-015)")
2591
- updated = _ensure_official_mcp_overlay(updated, root)
2827
+ if root is None or _is_global_home_scope(root):
2828
+ updated = _ensure_official_mcp_overlay(updated, root or Path.home())
2829
+ else:
2830
+ updated = _ensure_official_mcp_overlay(updated, root)
2592
2831
 
2593
2832
  if updated != content:
2594
2833
  _atomic_write_global_file_tx(patch_path, updated.encode("utf-8"))
@@ -2629,9 +2868,43 @@ def _ensure_official_mcp_overlay(content: str, root: Path) -> str:
2629
2868
  不再承载 MCP,若 install 也不写,doctor 就会判定「缺少 bugx-supervisor
2630
2869
  MCP」,形成「修好调用却报告缺失」的新破窗。
2631
2870
  """
2632
- root_text = str(Path(root).resolve())
2871
+ global_scope = _is_global_home_scope(root)
2872
+ if global_scope:
2873
+ existing_match = re.search(
2874
+ r"^\s*-\s*['\"]?--root['\"]?\s*\n\s*-\s*['\"]?([^'\"\n]+)['\"]?",
2875
+ content,
2876
+ re.MULTILINE,
2877
+ )
2878
+ preserved_root: str | None = None
2879
+ if existing_match:
2880
+ candidate_text = existing_match.group(1).strip()
2881
+ if candidate_text and candidate_text not in {".", "{ROOT}"}:
2882
+ try:
2883
+ candidate_path = Path(candidate_text).expanduser().resolve()
2884
+ if candidate_path.is_dir() and not _is_global_home_scope(candidate_path):
2885
+ preserved_root = str(candidate_path)
2886
+ except OSError:
2887
+ preserved_root = None
2888
+ if preserved_root is not None:
2889
+ servers_to_write = tuple(
2890
+ (name, [arg.replace("{ROOT}", preserved_root) for arg in argv])
2891
+ for name, argv in _OFFICIAL_MCP_SERVERS
2892
+ )
2893
+ else:
2894
+ servers_to_write = (
2895
+ ("bugx-supervisor", ["mcp", "serve", "--role", "host"]),
2896
+ ("bugx-supervisor-worker", ["mcp", "serve", "--role", "worker"]),
2897
+ ("bugx-docs", ["mcp", "docs", "serve"]),
2898
+ )
2899
+ else:
2900
+ root_text = str(Path(root).resolve())
2901
+ servers_to_write = tuple(
2902
+ (name, [arg.replace("{ROOT}", root_text) for arg in argv])
2903
+ for name, argv in _OFFICIAL_MCP_SERVERS
2904
+ )
2905
+
2633
2906
  lines = [_OFFICIAL_MCP_MARKER, "- insert:"]
2634
- for server_name, argv in _OFFICIAL_MCP_SERVERS:
2907
+ for server_name, argv in servers_to_write:
2635
2908
  lines.extend([
2636
2909
  f" - id: {server_name}",
2637
2910
  f" name: '{_OFFICIAL_MCP_CLIENT}'",
@@ -2642,7 +2915,7 @@ def _ensure_official_mcp_overlay(content: str, root: Path) -> str:
2642
2915
  " args:",
2643
2916
  ])
2644
2917
  lines.extend(
2645
- f" - '{arg.replace('{ROOT}', root_text)}'" for arg in argv
2918
+ f" - '{arg}'" for arg in argv
2646
2919
  )
2647
2920
  block = "\n".join(lines) + "\n"
2648
2921
 
@@ -3583,7 +3856,11 @@ def _preflight_opencode_mcp_config(root: Path) -> None:
3583
3856
 
3584
3857
 
3585
3858
  def _ensure_opencode_config(
3586
- root: Path, *, selected: set[str] | None = None,
3859
+ root: Path,
3860
+ *,
3861
+ selected: set[str] | None = None,
3862
+ docs_transport: str | None = None,
3863
+ docs_remote_url: str | None = None,
3587
3864
  ) -> tuple[str, Path | None]:
3588
3865
  """Create or safely merge the bundled OpenCode MCP configuration.
3589
3866
 
@@ -3628,6 +3905,15 @@ def _ensure_opencode_config(
3628
3905
  for name in list(bundled_servers):
3629
3906
  if name not in keep:
3630
3907
  bundled_servers.pop(name, None)
3908
+ from .plugin import resolve_effective_docs_transport
3909
+ effective_docs_transport = resolve_effective_docs_transport(docs_transport, docs_remote_url)
3910
+ if effective_docs_transport == "remote" and "bugx-docs" in bundled_servers:
3911
+ from .plugin import _resolve_docs_remote_url
3912
+ bundled_servers["bugx-docs"] = {
3913
+ "type": "remote",
3914
+ "url": _resolve_docs_remote_url(docs_remote_url),
3915
+ "codemode": False,
3916
+ }
3631
3917
  if target.exists():
3632
3918
  if not target.is_file():
3633
3919
  raise CliError(_i18n_exc("agent.opencode_config_not_regular_file", f"OpenCode 配置不是普通文件: {target}", target=target))
@@ -3674,13 +3960,26 @@ def _ensure_opencode_config(
3674
3960
  name for name in managed_names
3675
3961
  if not isinstance(servers.get(name), dict)
3676
3962
  ]
3677
- if not missing and not remove_unavailable_optional and not configuration_changed:
3963
+ docs_entry = servers.get("bugx-docs")
3964
+ desired_docs = bundled_servers.get("bugx-docs")
3965
+ docs_transport_mismatch = (
3966
+ isinstance(docs_entry, dict)
3967
+ and isinstance(desired_docs, dict)
3968
+ and _mcp_entry_state("bugx-docs", docs_entry) == "configured"
3969
+ and (
3970
+ (effective_docs_transport == "remote" and docs_entry.get("url") != desired_docs.get("url"))
3971
+ or (effective_docs_transport == "stdio" and isinstance(docs_entry.get("url"), str))
3972
+ )
3973
+ )
3974
+ if not missing and not remove_unavailable_optional and not docs_transport_mismatch and not configuration_changed:
3678
3975
  return "unchanged", None
3679
3976
  backup = _backup_opencode_config(root, target)
3680
3977
  for name in remove_unavailable_optional:
3681
3978
  servers.pop(name, None)
3682
3979
  for name in missing:
3683
3980
  servers[name] = copy.deepcopy(bundled_servers[name])
3981
+ if docs_transport_mismatch and desired_docs is not None:
3982
+ servers["bugx-docs"] = copy.deepcopy(desired_docs)
3684
3983
  updated = json.dumps(payload, ensure_ascii=False, indent=2) + "\n"
3685
3984
  descriptor, temporary = tempfile.mkstemp(
3686
3985
  dir=str(target.parent), prefix=f".{target.name}.", suffix=".tmp",
@@ -3776,17 +4075,24 @@ def _check_host_mcp_config(root: Path, host_name: str, *, repair: bool = False)
3776
4075
  if not dsh_client or not isinstance(ui_name, str):
3777
4076
  ui_detail = ";DSH UI 包 manifest 缺少 dsh.client 或 ./client 导出"
3778
4077
  elif profile.is_file() and (ui_name not in bundles or ui_name not in dependencies):
3779
- ui_detail = ";DSH UI 包未注册到 web profile,请重新运行 bugx install --agent dsh"
4078
+ ui_detail = ";DSH UI 包已暂存就绪(CLI/Desktop 通道可用;可选 web profile 注册未激活)"
3780
4079
  elif not profile.is_file():
3781
4080
  ui_detail = ";已暂存 DSH UI 包(当前未发现 web profile)"
3782
4081
  else:
3783
4082
  ui_detail = ";DSH UI 图标包已注册到 web profile"
3784
- if patch_file.is_file() or user_preset.is_file():
4083
+ profile_patches = [
4084
+ _dsh_home() / "profiles" / profile_name / "cordis.patch.yml"
4085
+ for profile_name in ("web", "desktop")
4086
+ ]
4087
+ if patch_file.is_file() or user_preset.is_file() or any(p.is_file() for p in profile_patches):
3785
4088
  content = ""
3786
4089
  if patch_file.is_file():
3787
4090
  content += patch_file.read_text(encoding="utf-8", errors="ignore")
3788
4091
  if user_preset.is_file():
3789
4092
  content += user_preset.read_text(encoding="utf-8", errors="ignore")
4093
+ for p_patch in profile_patches:
4094
+ if p_patch.is_file():
4095
+ content += p_patch.read_text(encoding="utf-8", errors="ignore")
3790
4096
  has_supervisor = "bugx-supervisor" in content or "mcp-client" in content
3791
4097
  has_native_question = "@deepseek-ai/dsh-tool-ask-user" in content
3792
4098
  if has_supervisor and has_native_question:
@@ -4005,11 +4311,8 @@ def _check_host_mcp_config(root: Path, host_name: str, *, repair: bool = False)
4005
4311
  return True, "WorkBuddy `.workbuddy` 与 CodeBuddy 兼容 Skill 入口、Connector 图标包均已就绪;" + user_detail + venv_detail
4006
4312
 
4007
4313
  if host_name == HOST_NAME_QODER:
4008
- qoder_mcp = root / ".qoder" / "mcp.json"
4009
- project_mcp = root / ".mcp.json"
4010
- candidates = (
4011
- (qoder_mcp, "flat"),
4012
- (project_mcp, "flat"),
4314
+ candidates = tuple(
4315
+ (root / relative, "flat") for relative in reversed(QODER_PROJECT_MCP_PATHS)
4013
4316
  )
4014
4317
  from .plugin_qoder import _clean_legacy_qoder_plugin_and_skills, _qoder_user_agents_dir
4015
4318
 
@@ -4054,7 +4357,9 @@ def _check_host_mcp_config(root: Path, host_name: str, *, repair: bool = False)
4054
4357
  if has_legacy:
4055
4358
  legacy_warning = ";发现用户级 Qoder 遗留配置,可运行 `bugx doctor --repair` 清理"
4056
4359
 
4057
- ok, detail = _validate_host_supervisor_mcp(candidates, root)
4360
+ ok, detail = _validate_host_supervisor_mcp(
4361
+ candidates, root, merge_servers=True, entry_is_current=_qoder_mcp_entry_is_current,
4362
+ )
4058
4363
  user_agents_dir = _qoder_user_agents_dir()
4059
4364
  user_main = user_agents_dir / "bugx.md"
4060
4365
  user_worker = user_agents_dir / "bugx-worker.md"
@@ -4071,7 +4376,9 @@ def _check_host_mcp_config(root: Path, host_name: str, *, repair: bool = False)
4071
4376
  _ensure_qoder_user_agents(root, source=asset_root())
4072
4377
  if not ok:
4073
4378
  write_host_mcp_config(root, host_name)
4074
- ok, detail = _validate_host_supervisor_mcp(candidates, root)
4379
+ ok, detail = _validate_host_supervisor_mcp(
4380
+ candidates, root, merge_servers=True, entry_is_current=_qoder_mcp_entry_is_current,
4381
+ )
4075
4382
  missing_user = [
4076
4383
  name for name, path in (("bugx", user_main), ("bugx-worker", user_worker))
4077
4384
  if not path.is_file()