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
@@ -16,7 +16,7 @@ from typing import Any
16
16
 
17
17
  from .. import __version__
18
18
  from ..common import *
19
- from ..infra.engine_installer import refresh_i18n_after_engine_swap
19
+ from ..infra.engine_installer import _is_global_home_scope, refresh_i18n_after_engine_swap
20
20
  from ..host_adapters import ENTRY_MULTI_PATH, HOST_ADAPTERS
21
21
  from ..hosts.registry import (
22
22
  engine_host_cli_hook,
@@ -49,7 +49,6 @@ from .plugin import (
49
49
  _remove_host_mcp_entry,
50
50
  _remove_opencode_mcp_entry,
51
51
  _remove_owned_record,
52
- _remove_qoder_mcp_entry,
53
52
  _reset_active_blockers,
54
53
  _reset_confirmation,
55
54
  _reset_entries,
@@ -602,49 +601,14 @@ def _purge_private_plugin_stores(root: Path, removed: list[str], preserved: list
602
601
  continue
603
602
  if manifest.get("private") is not True or manifest.get("autoload") is not False:
604
603
  continue
605
- shutil.rmtree(plugin_path)
604
+ _rmtree_force(plugin_path)
606
605
  removed.append(str(plugin_path.relative_to(root)))
607
606
  _remove_empty_parents(root, removed)
608
607
 
609
608
 
610
609
  def _rmtree_force(path: Path) -> None:
611
- """删除可能为**只读**的目录树(引擎载荷按不可变分发物安装)。
612
-
613
- 实测缺陷:`uninstall --self` 原先直接 ``shutil.rmtree(~/.bugx)``;当引擎目录
614
- 是 0o555/0o444 的只读载荷时抛 ``PermissionError: .bugx/core``,导致整个
615
- 自卸载失败(测试与真实用户同路径)。
616
-
617
- 关键点:删除条目需要**父目录**写权限,因此先自顶向下放开整棵树,再交给
618
- ``rmtree``;仅对失败条目 chmod 是不够的(实测仍 EACCES)。
619
- """
620
- if path.is_symlink() or path.is_file():
621
- path.unlink(missing_ok=True)
622
- return
623
- for root, _dirs, files in os.walk(path, topdown=True):
624
- try:
625
- os.chmod(root, 0o700)
626
- except OSError:
627
- pass
628
- for name in files:
629
- target = Path(root) / name
630
- if target.is_symlink():
631
- continue
632
- try:
633
- os.chmod(target, 0o600)
634
- except OSError:
635
- pass
636
-
637
- def _on_error(func, target, _exc): # noqa: ANN001 - stdlib 回调签名
638
- try:
639
- os.chmod(Path(target).parent, 0o700)
640
- except OSError:
641
- pass
642
- func(target)
643
-
644
- try:
645
- shutil.rmtree(path, onexc=_on_error)
646
- except TypeError: # Python < 3.12
647
- shutil.rmtree(path, onerror=_on_error)
610
+ """删除已完成安全校验、但可能包含只读条目的目录树。"""
611
+ _remove_tree_force(path)
648
612
 
649
613
 
650
614
  def _self_home_dir(*parts: str) -> Path:
@@ -967,7 +931,7 @@ def _self_remove_qoder_user_assets(
967
931
  cache_dir = _qoder_user_plugin_cache_dir()
968
932
  if cache_dir.is_dir() and not cache_dir.is_symlink():
969
933
  try:
970
- shutil.rmtree(cache_dir)
934
+ _rmtree_force(cache_dir)
971
935
  removed.append(f"{cache_dir}(已移除插件缓存)")
972
936
  except OSError as exc:
973
937
  preserved.append(f"{cache_dir}(删除失败:{exc})")
@@ -1216,7 +1180,7 @@ def _self_uninstall_pi_skill(
1216
1180
  if owned_copy:
1217
1181
  if backup_root is not None:
1218
1182
  _backup_tree_external(p_dir, backup_root / p_dir.name)
1219
- shutil.rmtree(p_dir)
1183
+ _rmtree_force(p_dir)
1220
1184
  removed.append(f"{label}(全局 skill 副本)")
1221
1185
  else:
1222
1186
  preserved.append(f"{label}(不是 BugX 副本或内容已变化,保留)")
@@ -1227,7 +1191,7 @@ def _self_uninstall_pi_skill(
1227
1191
  if agents_skill_dir.is_dir():
1228
1192
  if backup_root is not None:
1229
1193
  _backup_tree_external(agents_skill_dir, backup_root / "pi-global-skill")
1230
- shutil.rmtree(agents_skill_dir)
1194
+ _rmtree_force(agents_skill_dir)
1231
1195
  removed.append("~/.agents/skills/bugx(全局 skill 实体)")
1232
1196
  elif agents_skill_dir.exists():
1233
1197
  preserved.append("~/.agents/skills/bugx(不是安全目录,保留)")
@@ -1241,7 +1205,7 @@ def _self_uninstall_dsh_preset(
1241
1205
  return
1242
1206
  if backup_root is not None:
1243
1207
  _backup_tree_external(preset_dir, backup_root / "dsh-agent-presets")
1244
- shutil.rmtree(preset_dir)
1208
+ _rmtree_force(preset_dir)
1245
1209
  removed.append("~/.dsh/.agent-presets/bugx(全局预设)")
1246
1210
 
1247
1211
 
@@ -1274,7 +1238,7 @@ def _self_uninstall_dsh_ui_plugin(
1274
1238
  return
1275
1239
  if backup_root is not None:
1276
1240
  _backup_tree_external(plugin_root, backup_root / "dsh-ui-plugin")
1277
- shutil.rmtree(plugin_root)
1241
+ _rmtree_force(plugin_root)
1278
1242
  removed.append(f"{plugin_root}(DSH UI 插件)")
1279
1243
 
1280
1244
 
@@ -1344,7 +1308,7 @@ def _self_uninstall_workbuddy_skill(
1344
1308
  backup_root / "workbuddy-custom-expert" / config_root.name / "bugx",
1345
1309
  )
1346
1310
  try:
1347
- shutil.rmtree(expert_dir)
1311
+ _rmtree_force(expert_dir)
1348
1312
  removed.append(f"{expert_dir}(WorkBuddy 自定义专家)")
1349
1313
  except OSError as exc:
1350
1314
  preserved.append(f"{expert_dir}(删除失败:{exc})")
@@ -1879,6 +1843,9 @@ def _uninstall_guidance_flow(args: argparse.Namespace, root: Path) -> int:
1879
1843
  return command_uninstall(args)
1880
1844
 
1881
1845
 
1846
+ _SHARED_ROOT_MCP_HOSTS = frozenset({"claude", "funide", "qoder"})
1847
+
1848
+
1882
1849
  def _uninstall_dry_run_preview(
1883
1850
  root: Path,
1884
1851
  installed: list[object],
@@ -1888,6 +1855,7 @@ def _uninstall_dry_run_preview(
1888
1855
  purge_data: bool,
1889
1856
  purge_global_data: bool,
1890
1857
  force: bool = False,
1858
+ remaining_mcp_hosts: set[str],
1891
1859
  ) -> tuple[list[str], list[str]]:
1892
1860
  """Build an uninstall preview without invoking any mutating helper.
1893
1861
 
@@ -1978,6 +1946,9 @@ def _uninstall_dry_run_preview(
1978
1946
  continue
1979
1947
  target_path, _ = target_info
1980
1948
  if target_path.is_file() and not target_path.is_symlink():
1949
+ if mcp_host in _SHARED_ROOT_MCP_HOSTS and remaining_mcp_hosts:
1950
+ preserved.append(".mcp.json(仍有其他宿主使用 BugX MCP)")
1951
+ continue
1981
1952
  try:
1982
1953
  rel = str(target_path.relative_to(root))
1983
1954
  except ValueError:
@@ -2025,17 +1996,11 @@ def _remove_host_mcp_entries_for(
2025
1996
  preserved: list[str],
2026
1997
  *,
2027
1998
  backup_dir: Path | None = None,
1999
+ remaining_mcp_hosts: set[str],
2028
2000
  ) -> None:
2029
2001
  """清理宿主项目级 MCP 登记,含多路径宿主的 `.codebuddy` 兼容副本。"""
2030
- # Claude Code and FunIDE intentionally share the project-root `.mcp.json`
2031
- # shape. Removing FunIDE must not tear down a Claude installation that is
2032
- # still present in the same project; both hosts consume the same BugX
2033
- # servers. A FunIDE-only project has no `.claude` marker and is cleaned as
2034
- # usual.
2035
- if name == "funide" and (root / ".claude").exists():
2036
- preserved.append(
2037
- ".mcp.json(与 Claude Code 共用,卸载 FunIDE 时保留 BugX MCP)"
2038
- )
2002
+ if name in _SHARED_ROOT_MCP_HOSTS and remaining_mcp_hosts:
2003
+ preserved.append(".mcp.json(仍有其他宿主使用 BugX MCP)")
2039
2004
  else:
2040
2005
  _remove_host_mcp_entry(root, name, removed, preserved, backup_dir=backup_dir)
2041
2006
  for mcp_host in _mcp_config_host_names(name):
@@ -2084,6 +2049,11 @@ def command_uninstall(args: argparse.Namespace) -> int:
2084
2049
  choices = ", ".join(adapter.name for adapter in HOST_ADAPTERS)
2085
2050
  raise CliError(_i18n_exc("lifecycle.unknown_ai_agent", f"未知 AI Agent: {name};可选:{choices}", name=name, known=choices))
2086
2051
  selected_names = list(dict.fromkeys(known[name].name for name in raw_names))
2052
+ remaining_mcp_hosts = {
2053
+ str(item.get("name")) for item in installed if isinstance(item, dict)
2054
+ } & (_SHARED_ROOT_MCP_HOSTS - set(selected_names))
2055
+ if "funide" in selected_names and "claude" not in selected_names and (root / ".claude").exists():
2056
+ remaining_mcp_hosts.add("claude")
2087
2057
 
2088
2058
  if args.dry_run:
2089
2059
  planned, preserved = _uninstall_dry_run_preview(
@@ -2094,6 +2064,7 @@ def command_uninstall(args: argparse.Namespace) -> int:
2094
2064
  purge_data=bool(args.purge_data),
2095
2065
  purge_global_data=bool(args.purge_global_data),
2096
2066
  force=force,
2067
+ remaining_mcp_hosts=remaining_mcp_hosts,
2097
2068
  )
2098
2069
  payload = {
2099
2070
  "status": "DRY_RUN",
@@ -2183,7 +2154,10 @@ def command_uninstall(args: argparse.Namespace) -> int:
2183
2154
  ]
2184
2155
  for record in records:
2185
2156
  _remove_owned_record(root, record, name, removed, preserved, uninstall_backup_dir, force=force)
2186
- _remove_host_mcp_entries_for(root, name, removed, preserved, backup_dir=uninstall_backup_dir)
2157
+ _remove_host_mcp_entries_for(
2158
+ root, name, removed, preserved, backup_dir=uninstall_backup_dir,
2159
+ remaining_mcp_hosts=remaining_mcp_hosts,
2160
+ )
2187
2161
  if name == "chatgpt":
2188
2162
  _remove_chatgpt_marketplace_entry(root, removed, preserved, backup_dir=uninstall_backup_dir)
2189
2163
  _deregister_codex_plugin(root, removed, preserved)
@@ -2295,7 +2269,10 @@ def command_uninstall(args: argparse.Namespace) -> int:
2295
2269
  for name in selected_names:
2296
2270
  if name in recorded_names:
2297
2271
  continue
2298
- _remove_host_mcp_entries_for(root, name, removed, preserved, backup_dir=uninstall_backup_dir)
2272
+ _remove_host_mcp_entries_for(
2273
+ root, name, removed, preserved, backup_dir=uninstall_backup_dir,
2274
+ remaining_mcp_hosts=remaining_mcp_hosts,
2275
+ )
2299
2276
  if name == "chatgpt":
2300
2277
  _remove_chatgpt_marketplace_entry(root, removed, preserved, backup_dir=uninstall_backup_dir)
2301
2278
  _deregister_codex_plugin(root, removed, preserved)
@@ -2323,7 +2300,10 @@ def command_uninstall(args: argparse.Namespace) -> int:
2323
2300
  }
2324
2301
  for adapter in HOST_ADAPTERS:
2325
2302
  if adapter.name not in recorded:
2326
- _remove_host_mcp_entries_for(root, adapter.name, removed, preserved, backup_dir=uninstall_backup_dir)
2303
+ _remove_host_mcp_entries_for(
2304
+ root, adapter.name, removed, preserved, backup_dir=uninstall_backup_dir,
2305
+ remaining_mcp_hosts=remaining_mcp_hosts,
2306
+ )
2327
2307
  if (global_engine_root() / "bugx.md").is_file():
2328
2308
  _sweep_unrecorded_host_entry(root, adapter, removed, preserved, uninstall_backup_dir, force=force)
2329
2309
 
@@ -2377,14 +2357,14 @@ def command_uninstall(args: argparse.Namespace) -> int:
2377
2357
  for handler in list(logger.handlers):
2378
2358
  handler.close()
2379
2359
  logger.removeHandler(handler)
2380
- shutil.rmtree(bugx_root)
2360
+ _rmtree_force(bugx_root)
2381
2361
  # 与 --dry-run 预览保持一致:项目运行态被清掉必须在 removed 里可查,
2382
2362
  # 否则用户只能靠 ls 猜(removed 为空时会误以为没清干净)。
2383
2363
  removed.append(".bugx/(项目运行态、报告、证据与共享资源)")
2384
2364
  if args.purge_global_data and global_root.exists():
2385
2365
  if global_root.is_symlink():
2386
2366
  raise CliError(_i18n_exc("lifecycle.clean_global_knowledge_symlink_refused", "拒绝清理符号链接全局错题集目录"))
2387
- shutil.rmtree(global_root)
2367
+ _rmtree_force(global_root)
2388
2368
  removed.append("~/.bugx/knowledge/(全局错题集与经验集)")
2389
2369
  _remove_empty_parents(root, removed)
2390
2370
  payload = {
@@ -2427,6 +2407,54 @@ def _assert_writable(directory: Path, label: str) -> None:
2427
2407
  raise CliError(f"{label}不可写:{directory}: {exc}") from exc
2428
2408
 
2429
2409
 
2410
+ _PROJECT_SKILL = Path(".agents/skills/bugx/SKILL.md")
2411
+ _PROJECT_USER_SKILL = _PROJECT_SKILL
2412
+
2413
+
2414
+ def _read_project_user_skill(root: Path, source: Path) -> bytes:
2415
+ """Validate the required bundled Skill and its project destination before init writes."""
2416
+ target = root / _PROJECT_SKILL
2417
+ _assert_no_symlink_components(target)
2418
+ for parent in target.parents:
2419
+ if parent == root:
2420
+ break
2421
+ if parent.exists() and not parent.is_dir():
2422
+ raise CliError(f"项目 Skill 父路径不是目录:{parent}")
2423
+ if target.exists() and not target.is_file():
2424
+ raise CliError(f"项目 Skill 目标不是普通文件:{target}")
2425
+
2426
+ template = source.parent / "skills" / "platform" / "bugx" / "SKILL.md"
2427
+ _assert_no_symlink_components(template)
2428
+ if not template.is_file():
2429
+ raise CliError(f"安装包缺少 BugX Skill:{template}。请重新安装完整的 bugx-cli。")
2430
+ try:
2431
+ content = template.read_bytes()
2432
+ except OSError as exc:
2433
+ raise CliError(f"无法读取 BugX Skill:{template}: {exc}") from exc
2434
+ if not content.strip():
2435
+ raise CliError(f"安装包中的 BugX Skill 为空:{template}。请重新安装完整的 bugx-cli。")
2436
+ return content
2437
+
2438
+
2439
+ def _install_project_user_skill(root: Path, content: bytes, *, force: bool) -> Path | None:
2440
+ # 迁移/清理旧版 bugx-user
2441
+ legacy_user_skill = root / ".agents" / "skills" / "bugx-user" / "SKILL.md"
2442
+ if legacy_user_skill.is_file():
2443
+ try:
2444
+ legacy_user_skill.unlink()
2445
+ if legacy_user_skill.parent.is_dir():
2446
+ legacy_user_skill.parent.rmdir()
2447
+ except OSError:
2448
+ pass
2449
+
2450
+ target = root / _PROJECT_SKILL
2451
+ _assert_no_symlink_components(target)
2452
+ if target.is_file() and not force:
2453
+ return None
2454
+ _, _, backup = _write_host_resource(root, target, content, "bugx")
2455
+ return backup
2456
+
2457
+
2430
2458
  def _precheck_initialization(root: Path, source: Path) -> None:
2431
2459
  """F-L0-04 B 预检阶段:把可预知的失败全部前移到写盘之前(零落盘)。"""
2432
2460
  if not source.is_dir():
@@ -2464,7 +2492,7 @@ def _plan_cloud_onboarding(
2464
2492
  # been initialized. Probing sync here can otherwise make first-time
2465
2493
  # ``init --cloud-sync sync`` fail before it creates the very ledger that
2466
2494
  # sync requires.
2467
- if not had_onboarding and cloud_sync_explicit and cloud_sync_choice in {"local", "sync"}:
2495
+ if cloud_sync_explicit and cloud_sync_choice in {"local", "sync"}:
2468
2496
  action = "enable_sync" if cloud_sync_choice == "sync" else "set_local"
2469
2497
  return {"action": action}, 0
2470
2498
  if not had_onboarding:
@@ -2549,6 +2577,10 @@ def _commit_with_self_heal(commit, *, retries: int = 1):
2549
2577
 
2550
2578
  def command_init(args: argparse.Namespace) -> int:
2551
2579
  root = args.root.resolve()
2580
+ if _is_global_home_scope(root):
2581
+ raise CliError(
2582
+ "不能将用户主目录 (~) 作为被测项目初始化;请在具体项目目录执行 `bugx init --root <PROJECT>`,或运行 `bugx install` 执行用户全局安装。"
2583
+ )
2552
2584
  preset_data = {}
2553
2585
  try:
2554
2586
  _ensure_core_importable()
@@ -2581,6 +2613,7 @@ def command_init(args: argparse.Namespace) -> int:
2581
2613
  # F-L0-04 整改(commit-or-nothing):所有**已知**失败路径都必须在写盘前阻断。
2582
2614
  # ---- B 预检阶段(零落盘)------------------------------------------------
2583
2615
  _precheck_initialization(root, source)
2616
+ user_skill = _read_project_user_skill(root, source)
2584
2617
 
2585
2618
  # ---- A 决策阶段(零落盘):云端同步决策必须在任何写盘之前解析完成 --------
2586
2619
  onboarding_path = root / ".bugx" / "cloud-onboard.json"
@@ -2628,12 +2661,13 @@ def command_init(args: argparse.Namespace) -> int:
2628
2661
  _ensure_core_importable()
2629
2662
  from core.runtime.session_profile import save_commit_policy
2630
2663
  profile_file_ = save_commit_policy(commit_policy_, root=root)
2664
+ skill_backup_ = _install_project_user_skill(root, user_skill, force=args.force)
2631
2665
  _apply_cloud_onboarding_plan(root, onboarding_plan, preset_data)
2632
2666
  return {
2633
2667
  "removed": removed, "copied": copied_, "skipped": skipped_,
2634
2668
  "layout": layout_, "inherited": inherited_,
2635
2669
  "life_created": life_created_, "profile_file": profile_file_,
2636
- "commit_policy": commit_policy_,
2670
+ "commit_policy": commit_policy_, "skill_backup": skill_backup_,
2637
2671
  }
2638
2672
 
2639
2673
  committed = _commit_with_self_heal(_commit_project_state)
@@ -2682,6 +2716,9 @@ def command_init(args: argparse.Namespace) -> int:
2682
2716
  if removed_legacy_core:
2683
2717
  print(f" 已直接删除旧项目引擎入口:{removed_legacy_core}")
2684
2718
  print(f" 运行目录:{layout.root}")
2719
+ print(f" 标准 Skill:{_PROJECT_SKILL.as_posix()}")
2720
+ if committed["skill_backup"] is not None:
2721
+ print(f" 标准 Skill 备份:{committed['skill_backup']}")
2685
2722
  print(f" 写入 {copied} 个文件,保留 {skipped} 个已有文件")
2686
2723
  if life_created:
2687
2724
  print(" 已创建 .bugx 当前生命周期生命状态(1 条初始寿命)")