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
@@ -8,6 +8,7 @@ import hashlib
8
8
  import importlib.metadata
9
9
  import io
10
10
  import json
11
+ import math
11
12
  import os
12
13
  import re
13
14
  import shutil
@@ -49,6 +50,9 @@ _STABLE_AGENT_FILES_HOST = "files.pythonhosted.org"
49
50
  _MAX_PYPI_METADATA_BYTES = 4 * 1024 * 1024
50
51
  _MAX_PYPI_WHEEL_BYTES = 128 * 1024 * 1024
51
52
 
53
+ DEFAULT_PROBE_TIMEOUT_SECONDS = 120.0
54
+ MAX_PROBE_TIMEOUT_SECONDS = 1800.0
55
+
52
56
 
53
57
  def completion_tree(parser: argparse.ArgumentParser) -> dict[str, tuple[str, ...]]:
54
58
  """Derive nested commands, enum selectors and options from the CLI parser."""
@@ -2364,18 +2368,74 @@ def command_engine(args: argparse.Namespace) -> int:
2364
2368
  )
2365
2369
 
2366
2370
 
2371
+ def _parse_probe_timeout(raw: object) -> float:
2372
+ """Parse the bounded outer watchdog used by ``bugx probe``."""
2373
+ try:
2374
+ value = float(raw)
2375
+ except (TypeError, ValueError) as exc:
2376
+ raise argparse.ArgumentTypeError("--timeout-seconds 必须是数字") from exc
2377
+ if not math.isfinite(value) or value <= 0 or value > MAX_PROBE_TIMEOUT_SECONDS:
2378
+ raise argparse.ArgumentTypeError(
2379
+ f"--timeout-seconds 必须在 0 和 {MAX_PROBE_TIMEOUT_SECONDS:g} 秒之间"
2380
+ )
2381
+ return value
2382
+
2383
+
2384
+ def _extract_probe_timeout(
2385
+ args: argparse.Namespace, actual_extra: list[str],
2386
+ ) -> tuple[list[str], float]:
2387
+ """Extract the outer timeout without forwarding it to the probe script.
2388
+
2389
+ ``probe_args`` uses ``argparse.REMAINDER``, so users may put the option
2390
+ after the probe kind as well as before it. Keeping the extraction here
2391
+ makes both forms equivalent and prevents ``ui_audit.py`` from seeing a
2392
+ BugX wrapper option it does not own.
2393
+ """
2394
+ configured = getattr(args, "timeout_seconds", None)
2395
+ forwarded: list[str] = []
2396
+ forwarded_timeout: float | None = None
2397
+ index = 0
2398
+ while index < len(actual_extra):
2399
+ token = actual_extra[index]
2400
+ if token == "--timeout-seconds":
2401
+ if forwarded_timeout is not None or index + 1 >= len(actual_extra):
2402
+ raise CliError("--timeout-seconds 只能指定一次并且必须带值")
2403
+ try:
2404
+ forwarded_timeout = _parse_probe_timeout(actual_extra[index + 1])
2405
+ except argparse.ArgumentTypeError as exc:
2406
+ raise CliError(str(exc)) from exc
2407
+ index += 2
2408
+ continue
2409
+ if token.startswith("--timeout-seconds="):
2410
+ if forwarded_timeout is not None:
2411
+ raise CliError("--timeout-seconds 只能指定一次")
2412
+ try:
2413
+ forwarded_timeout = _parse_probe_timeout(token.split("=", 1)[1])
2414
+ except argparse.ArgumentTypeError as exc:
2415
+ raise CliError(str(exc)) from exc
2416
+ index += 1
2417
+ continue
2418
+ forwarded.append(token)
2419
+ index += 1
2420
+
2421
+ if configured is not None and forwarded_timeout is not None:
2422
+ raise CliError("--timeout-seconds 只能指定一次")
2423
+ timeout = configured if configured is not None else forwarded_timeout
2424
+ return forwarded, _parse_probe_timeout(
2425
+ DEFAULT_PROBE_TIMEOUT_SECONDS if timeout is None else timeout
2426
+ )
2427
+
2428
+
2367
2429
  def command_probe(args: argparse.Namespace, extra_args: list[str] | None = None) -> int:
2368
2430
  """运行探针包装命令,透传选定 probe 的参数。"""
2369
2431
  root = args.root.resolve()
2370
2432
  script_name = PROBE_SCRIPTS[args.probe_kind]
2371
- forward_args: list[str] = []
2372
2433
  actual_extra = extra_args if extra_args is not None else getattr(args, "probe_args", [])
2373
- if actual_extra:
2374
- forward_args.extend(actual_extra)
2434
+ forward_args, timeout = _extract_probe_timeout(args, list(actual_extra))
2375
2435
  if args.probe_kind not in PROBES_WITHOUT_ROOT_ARGUMENT \
2376
2436
  and "--root" not in forward_args and "-r" not in forward_args:
2377
2437
  forward_args.extend(["--root", str(root)])
2378
- return _run_script(root, script_name, forward_args, timeout=300)
2438
+ return _run_script(root, script_name, forward_args, timeout=timeout)
2379
2439
 
2380
2440
 
2381
2441
  def command_mcp_prune(args: argparse.Namespace) -> int:
@@ -2427,7 +2487,7 @@ def command_mcp(args: argparse.Namespace) -> int:
2427
2487
 
2428
2488
 
2429
2489
  def command_mcp_docs(args: argparse.Namespace) -> int:
2430
- """索引或启动本地项目文档 MCP,不访问第三方文档服务。"""
2490
+ """索引、同步或启动双域文档 MCP,隔离业务项目与官方知识库。"""
2431
2491
  root = resolve_project_root(args.root).resolve()
2432
2492
  forwarded = [args.mcp_docs_command, "--root", str(root), "--db", str(args.db)]
2433
2493
  if args.project_id:
@@ -2436,6 +2496,16 @@ def command_mcp_docs(args: argparse.Namespace) -> int:
2436
2496
  forwarded.extend(["--version", args.version])
2437
2497
  if getattr(args, "no_auto_index", False):
2438
2498
  forwarded.append("--no-auto-index")
2499
+ mode = getattr(args, "mode", None)
2500
+ if mode:
2501
+ forwarded.extend(["--mode", str(mode)])
2502
+ remote_url = getattr(args, "remote_url", None)
2503
+ if remote_url:
2504
+ forwarded.extend(["--remote-url", str(remote_url)])
2505
+ if getattr(args, "force", False):
2506
+ forwarded.append("--force")
2507
+ if getattr(args, "offline", False):
2508
+ forwarded.append("--offline")
2439
2509
  return _run_script(
2440
2510
  root, "bugx_docs_mcp_server.py", forwarded,
2441
2511
  timeout=None if args.mcp_docs_command == "serve" else 300,
@@ -14,6 +14,7 @@ import json
14
14
  import os
15
15
  import re
16
16
  import shutil
17
+ import stat
17
18
  import subprocess
18
19
  import sys
19
20
  import sysconfig
@@ -61,6 +62,8 @@ from .infra import (
61
62
  _ensure_global_cli_symlinks,
62
63
  _find_current_cli_executable,
63
64
  _find_repo_root,
65
+ _global_bugx_dir,
66
+ _is_global_home_scope,
64
67
  _engine_manifest_payload,
65
68
  _file_record,
66
69
  _fsync_engine_tree,
@@ -255,18 +258,41 @@ def _ensure_core_importable() -> None:
255
258
  candidate = Path(engine_override).expanduser()
256
259
  if not engine_override or not candidate.is_dir():
257
260
  raise CliError(f"BUGX_GLOBAL_ENGINE_ROOT 指向不存在的引擎目录: {engine_override}")
258
- asset = asset_root()
259
261
  global_engine = global_engine_root()
260
- if global_engine.is_dir() and not (global_engine / "launch_bugx.py").is_file():
261
- print(
262
- f"[bugx] 全局引擎目录 {global_engine} 缺失 launch_bugx.py,"
263
- f"回落至 asset_root: {asset}",
264
- file=sys.stderr,
265
- )
262
+ asset: Path | None = None
263
+ try:
264
+ asset = asset_root()
265
+ except CliError:
266
+ asset = None
267
+
268
+ if asset is None:
269
+ try:
270
+ repo_root = _source_checkout_root()
271
+ repo_core = repo_root / "core"
272
+ if repo_core.is_dir() and (repo_core / "launch_bugx.py").is_file():
273
+ asset = repo_core
274
+ except Exception:
275
+ pass
276
+
266
277
  candidates = []
267
278
  for cand in (asset, global_engine):
268
- if cand.is_dir() and (cand / "launch_bugx.py").is_file():
279
+ if cand is not None and cand.is_dir() and (cand / "launch_bugx.py").is_file():
269
280
  candidates.append(cand)
281
+
282
+ if not candidates:
283
+ raise MissingAgentAssetError(_i18n_exc(
284
+ "common.agent_asset_missing",
285
+ "找不到 BugX Agent 资源;请重新安装 bugx-cli,或设置 BUGX_ASSET_ROOT "
286
+ "指向完整资源目录。仅在源码仓库开发时,显式设置 BUGX_DEV_ASSET_ROOT=1。",
287
+ ), repairable=True)
288
+
289
+ if global_engine.is_dir() and not (global_engine / "launch_bugx.py").is_file():
290
+ if asset is not None:
291
+ print(
292
+ f"[bugx] 全局引擎目录 {global_engine} 缺失 launch_bugx.py,"
293
+ f"回落至 asset_root: {asset}",
294
+ file=sys.stderr,
295
+ )
270
296
  # 后插入者位于 sys.path[0],故按 (asset, global_engine) 顺序插入 ⇒
271
297
  # 最终 global_engine 优先。契约见 `docs/03_ai/01_AI_REFERENCE.md`「副本升级门禁」:
272
298
  # Python 导入必须优先 `global_engine_root()`(共享引擎是运行时真源),
@@ -276,6 +302,12 @@ def _ensure_core_importable() -> None:
276
302
  while s in sys.path:
277
303
  sys.path.remove(s)
278
304
  sys.path.insert(0, s)
305
+ try:
306
+ from core.repair.self_heal import mount_bugx_pydeps
307
+
308
+ mount_bugx_pydeps()
309
+ except Exception:
310
+ pass
279
311
 
280
312
 
281
313
  # 宿主启动子进程时会通过环境变量指明工作区。MCP / 引擎入口若拿不到显式
@@ -633,9 +665,9 @@ def _ensure_project_readme(root: Path, source: Path) -> None:
633
665
  def _run_script(root: Path, name: str, arguments: list[str], timeout: float | None = None) -> int:
634
666
  """运行 core 脚本并透传退出码。
635
667
 
636
- ``timeout``(P3a):lesson/knowledge/probe/self-audit 类调用传 300 秒,
637
- 防止失控脚本永久挂起;mcp serve 与 mcp-runtime start 需要长驻/直通
638
- stdio,保持 None(不设超时)。
668
+ ``timeout`` 由调用方提供。``bugx probe`` 使用有界的 120 秒默认看护
669
+ (CLI 可显式调整到 1800 秒以内),以防失控脚本永久挂起;mcp serve
670
+ 与 mcp-runtime start 需要长驻/直通 stdio,保持 None(不设超时)。
639
671
  """
640
672
  _ensure_core_importable()
641
673
  try:
@@ -685,6 +717,69 @@ def _run_script(root: Path, name: str, arguments: list[str], timeout: float | No
685
717
  raise CliError(_i18n_exc("common.script_run_failed", f"无法运行 {name}: {exc}", name=name, exc=exc)) from exc
686
718
 
687
719
 
720
+ def _remove_tree_force(path: Path) -> None:
721
+ """Remove an already-validated BugX-owned path despite read-only bits.
722
+
723
+ Windows refuses to unlink read-only files even when their parent directory
724
+ is writable. The helper validates the parent path components before
725
+ changing permissions and never follows symlinks while doing so. Callers
726
+ still remain responsible for the higher-level ownership decision.
727
+ """
728
+ path = Path(path)
729
+ _assert_no_symlink_components(path.parent)
730
+ if path.is_symlink():
731
+ path.unlink(missing_ok=True)
732
+ return
733
+ if path.is_file():
734
+ try:
735
+ path.unlink()
736
+ except PermissionError:
737
+ parent = path.parent
738
+ if not parent.is_symlink():
739
+ os.chmod(parent, stat.S_IMODE(parent.stat().st_mode) | 0o700)
740
+ os.chmod(path, stat.S_IMODE(path.stat().st_mode) | stat.S_IWUSR)
741
+ path.unlink()
742
+ return
743
+ if not path.exists():
744
+ return
745
+
746
+ for current, _directories, files in os.walk(path, topdown=True, followlinks=False):
747
+ current_path = Path(current)
748
+ try:
749
+ os.chmod(current_path, stat.S_IMODE(current_path.stat().st_mode) | 0o700)
750
+ except OSError:
751
+ pass
752
+ for name in files:
753
+ target = current_path / name
754
+ if target.is_symlink():
755
+ continue
756
+ try:
757
+ os.chmod(target, stat.S_IMODE(target.stat().st_mode) | stat.S_IWUSR)
758
+ except OSError:
759
+ pass
760
+
761
+ def _on_error(func, target, _exc): # noqa: ANN001 - stdlib callback signature
762
+ target_path = Path(target)
763
+ try:
764
+ if not target_path.is_symlink():
765
+ os.chmod(
766
+ target_path,
767
+ stat.S_IMODE(target_path.stat().st_mode)
768
+ | (stat.S_IWUSR if target_path.is_file() else 0o700),
769
+ )
770
+ parent = target_path.parent
771
+ if parent != target_path and not parent.is_symlink():
772
+ os.chmod(parent, stat.S_IMODE(parent.stat().st_mode) | 0o700)
773
+ except OSError:
774
+ pass
775
+ func(target)
776
+
777
+ try:
778
+ shutil.rmtree(path, onexc=_on_error)
779
+ except TypeError: # Python < 3.12
780
+ shutil.rmtree(path, onerror=_on_error)
781
+
782
+
688
783
  def _run_script_json(
689
784
  root: Path, name: str, arguments: list[str], timeout: float | None = 300.0,
690
785
  ) -> dict | None:
@@ -751,6 +846,8 @@ def _python_environment(overrides: dict[str, str] | None = None) -> dict[str, st
751
846
  continue
752
847
  environment["PATH"] = os.pathsep.join(entries)
753
848
  environment["PYTHONDONTWRITEBYTECODE"] = "1"
849
+ environment["PYTHONUTF8"] = "1"
850
+ environment["PYTHONIOENCODING"] = "utf-8"
754
851
  if "BUGX_PYTHON" not in environment and sys.executable:
755
852
  environment["BUGX_PYTHON"] = sys.executable
756
853
  if overrides:
@@ -892,11 +989,34 @@ def get_build_id() -> int | None:
892
989
  return None
893
990
 
894
991
 
992
+ def is_dev_mode() -> bool:
993
+ """是否处于 dev / alpha 开发模式。正式版(Stable)返回 False。"""
994
+ if os.environ.get("BUGX_DEV") in ("1", "true", "yes", "on"):
995
+ return True
996
+ env = os.environ.get("BUGX_ENV", "").strip().lower()
997
+ if env in ("dev", "development", "local", "test"):
998
+ return True
999
+ try:
1000
+ from core.infra.client_metadata import release_channel, client_marker
1001
+ channel = release_channel()
1002
+ marker = client_marker()
1003
+ if channel != "stable" or marker in ("dev", "alpha"):
1004
+ return True
1005
+ except Exception:
1006
+ pass
1007
+ return False
1008
+
1009
+
895
1010
  def get_full_version() -> str:
896
- """返回标准版本与 Build ID 组合字符串,例如 0.1.1+build.627。"""
897
- bid = get_build_id()
898
- if bid is not None:
899
- return f"{__version__}+build.{bid}"
1011
+ """返回标准版本展示字符串。
1012
+
1013
+ 正式版(Stable / Release)输出纯语义版本(如 0.1.3,不带 Build ID);
1014
+ 只有 dev / alpha 模式才携带(如 0.1.3+build.1)。
1015
+ """
1016
+ if is_dev_mode():
1017
+ bid = get_build_id()
1018
+ if bid is not None:
1019
+ return f"{__version__}+build.{bid}"
900
1020
  return __version__
901
1021
 
902
1022
 
@@ -16,7 +16,7 @@ import re
16
16
  import shutil
17
17
  import subprocess
18
18
 
19
- from .hosts.registry import engine_host_plugin
19
+ from .hosts.registry import QODER_PROJECT_MCP_PATHS, engine_host_plugin
20
20
  from .hosts.template_engine import (
21
21
  AGENT_DESCRIPTION,
22
22
  AGENT_DESCRIPTION_EN,
@@ -221,10 +221,17 @@ def add_locale_marker(content: str, locale: str | None) -> str:
221
221
  file. The marker is intentionally placed after that metadata block so it
222
222
  remains an inert HTML comment while preserving host discovery semantics.
223
223
  """
224
- if not locale:
224
+ loc = (locale or "").strip()
225
+ if not loc:
226
+ try:
227
+ import core.i18n as i18n
228
+ loc = i18n.resolve_locale().resolved_locale
229
+ except Exception:
230
+ pass
231
+ if not loc:
225
232
  return content
226
233
  content = strip_locale_marker(content)
227
- normalized = str(locale).strip() or "en-US"
234
+ normalized = loc or "en-US"
228
235
  marker = f"<!-- bugx-locale: {normalized} -->\n"
229
236
  if content.startswith("---\n"):
230
237
  closing = content.find("\n---", 4)
@@ -521,6 +528,8 @@ def _claude_app_markers() -> tuple[Path, ...]:
521
528
  relative_paths = (
522
529
  "Claude/Claude.exe",
523
530
  "Programs/Claude/Claude.exe",
531
+ "Program Files/Claude/Claude.exe",
532
+ "Program Files (x86)/Claude/Claude.exe",
524
533
  )
525
534
  for base in bases:
526
535
  markers.extend(base / rel for rel in relative_paths)
@@ -533,6 +542,50 @@ def _claude_app_markers() -> tuple[Path, ...]:
533
542
  return tuple(dict.fromkeys(markers))
534
543
 
535
544
 
545
+ def _kimi_app_markers() -> tuple[Path, ...]:
546
+ """Return well-known Kimi desktop application locations."""
547
+ home = Path.home()
548
+ markers: list[Path] = []
549
+ if platform.system() == "Darwin":
550
+ markers.extend((
551
+ Path("/Applications/Kimi.app"),
552
+ Path("/Applications/Kimi Code.app"),
553
+ home / "Applications" / "Kimi.app",
554
+ home / "Applications" / "Kimi Code.app",
555
+ home / "Library" / "Application Support" / "kimi-desktop",
556
+ home / "Library" / "Application Support" / "Kimi Code",
557
+ ))
558
+ elif platform.system() == "Windows":
559
+ bases = [
560
+ Path(value) for variable in
561
+ ("LOCALAPPDATA", "APPDATA", "PROGRAMFILES", "PROGRAMFILES(X86)")
562
+ if (value := os.environ.get(variable))
563
+ ]
564
+ bases.extend(_windows_drive_roots())
565
+ relative_paths = (
566
+ "Kimi/Kimi.exe",
567
+ "kimi-desktop/Kimi.exe",
568
+ "Kimi Code/Kimi Code.exe",
569
+ "Programs/Kimi/Kimi.exe",
570
+ "Programs/kimi-desktop/Kimi.exe",
571
+ "Programs/Kimi Code/Kimi Code.exe",
572
+ "Program Files/Kimi Code/Kimi Code.exe",
573
+ "Program Files (x86)/Kimi Code/Kimi Code.exe",
574
+ )
575
+ for base in bases:
576
+ markers.extend(base / rel for rel in relative_paths)
577
+ else:
578
+ markers.extend((
579
+ home / ".local" / "share" / "applications" / "kimi.desktop",
580
+ home / ".local" / "share" / "applications" / "kimi-code.desktop",
581
+ Path("/usr/bin/kimi-desktop"),
582
+ Path("/usr/bin/kimi-code"),
583
+ Path("/opt/Kimi/kimi"),
584
+ Path("/opt/Kimi Code/kimi-code"),
585
+ ))
586
+ return tuple(dict.fromkeys(markers))
587
+
588
+
536
589
  def _qoder_app_markers() -> tuple[Path, ...]:
537
590
  """Return well-known Qoder desktop application locations."""
538
591
  home = Path.home()
@@ -619,12 +672,22 @@ def _trea_app_markers() -> tuple[Path, ...]:
619
672
  "Programs/trae/Trae.exe",
620
673
  "Trae/Trae.exe",
621
674
  "trae/Trae.exe",
675
+ "Program Files/Trae/Trae.exe",
676
+ "Program Files (x86)/Trae/Trae.exe",
677
+ "Program Files/trae/Trae.exe",
678
+ "Program Files (x86)/trae/Trae.exe",
622
679
  "Programs/Trae CN/Trae CN.exe",
623
680
  "Programs/Trae CN/trae-cn.exe",
624
681
  "Programs/Trae CN/Trae.exe",
625
682
  "Trae CN/Trae CN.exe",
626
683
  "Trae CN/trae-cn.exe",
627
684
  "Trae CN/Trae.exe",
685
+ "Program Files/Trae CN/Trae CN.exe",
686
+ "Program Files (x86)/Trae CN/Trae CN.exe",
687
+ "Program Files/Trae CN/trae-cn.exe",
688
+ "Program Files (x86)/Trae CN/trae-cn.exe",
689
+ "Program Files/Trae CN/Trae.exe",
690
+ "Program Files (x86)/Trae CN/Trae.exe",
628
691
  )
629
692
  for base in bases:
630
693
  markers.extend(base / rel for rel in relative_paths)
@@ -1202,6 +1265,7 @@ CAP_GLOBAL_AGENT_LINK = "global-agent-link" # 注册用户级全局 age
1202
1265
  CAP_GLOBAL_SKILL_LINK = "global-skill-link" # 注册用户级全局 skill 链接
1203
1266
  CAP_NATIVE_MCP_CONFIG = "native-mcp-config" # 需要写宿主原生项目/工作区 MCP 容器
1204
1267
  CAP_USER_AGENT_REGISTRATION = "user-agent-registration" # 需要用户级子智能体注册
1268
+ CAP_USER_LEVEL_PLUGIN = "user-level-plugin" # 需要写用户级 Plugin V1 包
1205
1269
  CAP_USER_LEVEL_ARTIFACT = "user-level-artifact" # 需要写用户级 Skill / Connector 产物
1206
1270
  CAP_WORKSPACE_MIRROR = "workspace-mirror" # 支持工作区同构镜像(如 Roo Code .roo)
1207
1271
  #: 需要把入口额外镜像到本宿主的**变体目录**(如 Trae 的 .trae / .trae-cn)。
@@ -1213,6 +1277,8 @@ HOST_NAME_ZCODE = "zcode"
1213
1277
  HOST_NAME_CLAUDE = "claude"
1214
1278
  HOST_NAME_QODER = "qoder"
1215
1279
  HOST_NAME_FUNIDE = "funide"
1280
+ HOST_NAME_KIMI = "kimi"
1281
+ HOST_NAME_MINIMAX = "minimax"
1216
1282
 
1217
1283
 
1218
1284
  @dataclass(frozen=True)
@@ -1284,6 +1350,8 @@ class HostAdapter:
1284
1350
  return ["skill", "extension"]
1285
1351
  if self.supports(CAP_DISTRIBUTION_PLUGIN):
1286
1352
  return ["plugin"]
1353
+ if self.supports(CAP_USER_LEVEL_PLUGIN):
1354
+ return ["plugin"]
1287
1355
  return ["entry"]
1288
1356
 
1289
1357
  def detect(self, root: Path) -> dict[str, object]:
@@ -1442,6 +1510,96 @@ class ClaudeAdapter(HostAdapter):
1442
1510
  return _ensure_claude_user_agents(root, source, locale=locale)
1443
1511
 
1444
1512
 
1513
+ class KimiAdapter(HostAdapter):
1514
+ """Kimi Code CLI & Desktop adapter."""
1515
+
1516
+ def _app_markers(self) -> tuple[Path, ...]:
1517
+ return _kimi_app_markers()
1518
+
1519
+ def _user_marker(self) -> bool:
1520
+ configured = os.environ.get("KIMI_CODE_HOME")
1521
+ kimi_home = (
1522
+ Path(configured).expanduser()
1523
+ if configured and configured.strip()
1524
+ else Path.home() / ".kimi-code"
1525
+ )
1526
+ return kimi_home.is_dir()
1527
+
1528
+ def render_required_entry(
1529
+ self, relative: str, source: Path, *, locale: str | None = None,
1530
+ ) -> str | None:
1531
+ if relative.endswith("bugx-worker.md"):
1532
+ return render_claude_worker_entry(locale=locale)
1533
+ return None
1534
+
1535
+ def ensure_user_agents(
1536
+ self, root: Path, source: Path, *, locale: str | None = None,
1537
+ ) -> dict[str, object] | None:
1538
+ from .commands.plugin_kimi import _ensure_kimi_plugin
1539
+ return _ensure_kimi_plugin(root, source, locale=locale)
1540
+
1541
+
1542
+ class MiniMaxAdapter(HostAdapter):
1543
+ """MiniMax Code desktop Plugin V1 adapter."""
1544
+
1545
+ def _app_markers(self) -> tuple[Path, ...]:
1546
+ plugin = engine_host_plugin(self.name)
1547
+ marker_factory = plugin.identity.app_markers
1548
+ return tuple(marker_factory()) if marker_factory is not None else ()
1549
+
1550
+ def _user_marker(self) -> bool:
1551
+ configured = os.environ.get("MINIMAX_DATA_DIR")
1552
+ data_dir = (
1553
+ Path(configured).expanduser()
1554
+ if configured and configured.strip()
1555
+ else Path.home() / ".minimax"
1556
+ )
1557
+ return (
1558
+ data_dir / "plugins" / "bugx" / ".minimax-plugin" / "plugin.json"
1559
+ ).is_file()
1560
+
1561
+ def _project_marker(self, root: Path) -> bool:
1562
+ if self._user_marker():
1563
+ return True
1564
+ return super()._project_marker(root)
1565
+
1566
+ @property
1567
+ def installed_components(self) -> list[str]:
1568
+ return ["plugin", "agent", "worker", "skill", "mcp"]
1569
+
1570
+ def pre_validate(self, root: Path) -> None:
1571
+ from .commands.plugin_minimax import _minimax_custom_agent_path, _validate_custom_agent
1572
+
1573
+ _validate_custom_agent(_minimax_custom_agent_path())
1574
+
1575
+ def ensure_user_agents(
1576
+ self, root: Path, source: Path, *, locale: str | None = None,
1577
+ ) -> dict[str, object] | None:
1578
+ from .commands.plugin_minimax import _ensure_minimax_plugin
1579
+ return _ensure_minimax_plugin(root, source, locale=locale)
1580
+
1581
+
1582
+ class AntigravityAdapter(HostAdapter):
1583
+ def _user_marker(self) -> bool:
1584
+ return (Path.home() / self.install_path).is_file()
1585
+
1586
+ def pre_validate(self, root: Path) -> None:
1587
+ from .commands.plugin_antigravity import pre_validate
1588
+
1589
+ pre_validate()
1590
+
1591
+ def ensure_user_agents(
1592
+ self, root: Path, source: Path, *, locale: str | None = None,
1593
+ ) -> dict[str, object]:
1594
+ from .commands.plugin_antigravity import install_review_plugin
1595
+
1596
+ return install_review_plugin()
1597
+
1598
+ @property
1599
+ def installed_components(self) -> list[str]:
1600
+ return ["plugin", "agent", "worker", "skill", "workspace-mcp"]
1601
+
1602
+
1445
1603
  class ZCodeAdapter(HostAdapter):
1446
1604
  """ZCode IDE adapter."""
1447
1605
 
@@ -1567,6 +1725,9 @@ class ChatGptAdapter(HostAdapter):
1567
1725
  class QoderAdapter(HostAdapter):
1568
1726
  """Qoder AI adapter."""
1569
1727
 
1728
+ def managed_surfaces(self) -> tuple[str, ...]:
1729
+ return (*super().managed_surfaces(), QODER_PROJECT_MCP_PATHS[0])
1730
+
1570
1731
  def _app_markers(self) -> tuple[Path, ...]:
1571
1732
  return _qoder_app_markers()
1572
1733
 
@@ -1624,6 +1785,14 @@ class TreaAdapter(HostAdapter):
1624
1785
  info = super().detect(root)
1625
1786
  home = Path.home()
1626
1787
  variants: list[str] = []
1788
+ app_markers = self._app_markers()
1789
+ cn_app_markers = tuple(
1790
+ marker for marker in app_markers
1791
+ if any(token in str(marker).casefold() for token in ("trae cn", "trae-cn"))
1792
+ )
1793
+ global_app_markers = tuple(
1794
+ marker for marker in app_markers if marker not in cn_app_markers
1795
+ )
1627
1796
 
1628
1797
  cn_paths = [
1629
1798
  Path("/Applications/Trae CN.app"),
@@ -1632,7 +1801,11 @@ class TreaAdapter(HostAdapter):
1632
1801
  home / "Library" / "Application Support" / "Trae CN",
1633
1802
  root / ".trae-cn",
1634
1803
  ]
1635
- if shutil.which("trae-cn") or any(p.exists() for p in cn_paths):
1804
+ if (
1805
+ shutil.which("trae-cn")
1806
+ or any(p.exists() for p in cn_paths)
1807
+ or any(p.exists() for p in cn_app_markers)
1808
+ ):
1636
1809
  variants.append("trae-cn")
1637
1810
 
1638
1811
  global_paths = [
@@ -1643,7 +1816,11 @@ class TreaAdapter(HostAdapter):
1643
1816
  root / ".trae",
1644
1817
  root / ".trea",
1645
1818
  ]
1646
- if shutil.which("trae") or any(p.exists() for p in global_paths):
1819
+ if (
1820
+ shutil.which("trae")
1821
+ or any(p.exists() for p in global_paths)
1822
+ or any(p.exists() for p in global_app_markers)
1823
+ ):
1647
1824
  variants.append("trae")
1648
1825
 
1649
1826
  info["detected_variants"] = variants
@@ -1654,8 +1831,9 @@ class TreaAdapter(HostAdapter):
1654
1831
  if cn_exe:
1655
1832
  info["executable"] = cn_exe
1656
1833
  else:
1657
- for marker in self._app_markers():
1658
- if "trae-cn" in marker.name and marker.is_file():
1834
+ for marker in app_markers:
1835
+ marker_name = marker.name.casefold()
1836
+ if ("trae-cn" in marker_name or "trae cn" in marker_name) and marker.is_file():
1659
1837
  info["executable"] = str(marker)
1660
1838
  break
1661
1839
  return info
@@ -1824,6 +2002,11 @@ HOST_ADAPTERS: tuple[HostAdapter, ...] = (
1824
2002
  # ZCodeAdapter 只保留 CLI 侧行为覆写。引擎快照不可用时跳过(见
1825
2003
  # _plugin_backed_adapters:全新机器上必须先能启动 bugx init)。
1826
2004
  *_plugin_backed_adapters(ZCodeAdapter),
2005
+ # DOC-239:声明字段全部来自引擎插件(core/hosts/kimi.py)。
2006
+ *_plugin_backed_adapters(KimiAdapter),
2007
+ # MiniMax Code 桌面端通过 Plugin V1 注册 Agent、Skill 与 MCP。
2008
+ *_plugin_backed_adapters(MiniMaxAdapter),
2009
+ *_plugin_backed_adapters(AntigravityAdapter),
1827
2010
  WorkBuddyAdapter(
1828
2011
  "workbuddy", "WorkBuddy AI", "workbuddy", ".workbuddy",
1829
2012
  WORKBUDDY_PROJECT_PATHS[0], "skill", WORKBUDDY_PROJECT_PATHS,
@@ -43,6 +43,7 @@ WORKBUDDY_PROJECT_PATHS = (
43
43
  ".workbuddy/skills/bugx/SKILL.md",
44
44
  ".codebuddy/skills/bugx/SKILL.md",
45
45
  )
46
+ QODER_PROJECT_MCP_PATHS = (".mcp.json", ".qoder/settings.json")
46
47
 
47
48
 
48
49
  def _packaged_asset_cores() -> tuple[Path, ...]:
@@ -288,7 +289,7 @@ def engine_worker_entry_dir(name: str) -> str:
288
289
  #: 进程池执行器)自动追加,不进本表。这不是第二份宿主事实:宿主身份仍在
289
290
  #: 插件/``SUPPORTED_HOSTS``,本表只说「CLI 的 host 选项按什么顺序出现」。
290
291
  AUTONOMOUS_HOST_BASELINE: tuple[str, ...] = (
291
- "claude", "codex", "opencode", "dsh", "pi",
292
+ "claude", "codex", "opencode", "dsh", "pi", "kimi",
292
293
  )
293
294
 
294
295
 
@@ -375,7 +376,9 @@ def _component_from_plugin(name: str) -> HostComponent:
375
376
  #: 本清单只用于**定位/枚举插件**,不含任何宿主事实(不复制 label、路径、能力)。
376
377
  #: 它随纵切推进增长;全部宿主迁移完成后本清单与 ``HOST_COMPONENTS`` 的本地字面量
377
378
  #: 会一起消失。
378
- PLUGIN_BACKED_HOSTS: tuple[str, ...] = ("cline", "codex", "claude", "pi", "zcode")
379
+ PLUGIN_BACKED_HOSTS: tuple[str, ...] = (
380
+ "cline", "codex", "claude", "pi", "zcode", "kimi", "minimax", "antigravity",
381
+ )
379
382
 
380
383
 
381
384
  def plugin_backed_components() -> tuple[HostComponent, ...]:
@@ -501,7 +504,7 @@ HOST_COMPONENTS: tuple[HostComponent, ...] = (
501
504
  single_select="等价于 multiple=false",
502
505
  failure="控件失败时停在当前 gate",
503
506
  ),
504
- mcp=McpContract(config_relpaths=(".qoder/mcp.json", ".mcp.json")),
507
+ mcp=McpContract(config_relpaths=QODER_PROJECT_MCP_PATHS),
505
508
  execution=ExecutionContract(supports_headless=True, host_surface="tui"),
506
509
  aliases=("qoder-cli", "ali-qoder"),
507
510
  capabilities=frozenset({