bugx-cli 0.1.1 → 0.1.3

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 (131) hide show
  1. package/README.md +36 -35
  2. package/core/README.md +1 -1
  3. package/core/agent/agent_orchestrator.py +3 -0
  4. package/core/agent/agent_workspace.py +14 -2
  5. package/core/assets/README.md +3 -2
  6. package/core/assets/bugx-social-preview.svg +71 -0
  7. package/core/assets/bugx-wechat-group.png +0 -0
  8. package/core/assets/twitter_promo_art.jpg +0 -0
  9. package/core/assets/twitter_promo_card.svg +166 -0
  10. package/core/assets/twitter_promo_clean.jpg +0 -0
  11. package/core/assets/twitter_terminal_real.png +0 -0
  12. package/core/audit_packs/README.md +2 -0
  13. package/core/audit_packs/pitfalls/auth_crypto.json +64 -0
  14. package/core/audit_packs/pitfalls/file_ssrf_cmd.json +64 -0
  15. package/core/audit_packs/pitfalls/go_backend.json +66 -0
  16. package/core/audit_packs/pitfalls/java_spring.json +64 -0
  17. package/core/audit_packs/pitfalls/js_ts_web.json +67 -0
  18. package/core/audit_packs/pitfalls/python_web.json +82 -0
  19. package/core/bugx.md +2 -2
  20. package/core/bugx_paths.py +2 -2
  21. package/core/cli-help.txt +1 -1
  22. package/core/cloud_sync/cloud_client.py +56 -5
  23. package/core/cloud_sync/consent.py +33 -3
  24. package/core/cloud_sync/flywheel_client.py +186 -24
  25. package/core/contracts/README.md +1 -1
  26. package/core/contracts/bugx-opencode.md +1 -1
  27. package/core/contracts/bugx-runtime-contract.md +1 -1
  28. package/core/contracts/bugx-worker.md +1 -1
  29. package/core/engine-integrity.json +191 -95
  30. package/core/host_acp/kimi.py +175 -0
  31. package/core/host_acp/minimax.py +28 -0
  32. package/core/host_runtime/host_registry.py +23 -3
  33. package/core/hosts/dsh.py +1 -1
  34. package/core/hosts/kimi.py +293 -0
  35. package/core/hosts/minimax.py +248 -0
  36. package/core/hosts/zcode.py +5 -0
  37. package/core/infra/README.md +1 -1
  38. package/core/infra/build_info.py +30 -5
  39. package/core/launch_phases/README.md +6 -3
  40. package/core/launch_phases/finding_confirm_phase.py +168 -7
  41. package/core/launch_phases/post_phase.py +5 -5
  42. package/core/launch_phases/pre_recon_scout.py +13 -0
  43. package/core/launch_phases/report_sharing.py +3 -7
  44. package/core/launch_phases/round_orchestrator.py +114 -26
  45. package/core/launch_phases/semantic_recon.py +545 -0
  46. package/core/launch_phases/startup_version_gate.py +6 -2
  47. package/core/launch_phases/supervisor_bridge.py +14 -23
  48. package/core/launch_phases/verify_loop.py +767 -0
  49. package/core/launch_phases/worker_prior.py +115 -0
  50. package/core/ledger/README.md +2 -1
  51. package/core/ledger/finding_verification.py +511 -2
  52. package/core/ledger/fp_ledger.py +255 -0
  53. package/core/metadata.txt +2 -2
  54. package/core/planning/README.md +2 -1
  55. package/core/planning/prompt_harness.py +50 -10
  56. package/core/planning/prompt_policy_engine.py +386 -0
  57. package/core/prompts/README.md +4 -2
  58. package/core/prompts/policies/prompt_policies.json +101 -0
  59. package/core/prompts/stages/stage_verify.defensive.md +42 -0
  60. package/core/prompts/stages/stage_verify.md +44 -0
  61. package/core/report_engine/report_share.py +0 -8
  62. package/core/retrieval/README.md +2 -1
  63. package/core/retrieval/pitfall_packs.py +277 -0
  64. package/core/runtime/README.md +1 -1
  65. package/core/runtime/global_telemetry.py +20 -0
  66. package/core/runtime/scenario_eval.py +1 -1
  67. package/core/runtime/setup_ui_env.py +4 -7
  68. package/core/supervisor/README.md +1 -1
  69. package/core/supervisor/cli.py +2 -2
  70. package/core/webui/mcp_inspector.py +6 -0
  71. package/core/webui/static/index.html +51 -3
  72. package/core/webui/static/manifest.webmanifest +1 -1
  73. package/core/webui/static/project-settings.js +18 -3
  74. package/core/webui/static/robots.txt +36 -0
  75. package/core/webui/static/sitemap.xml +15 -0
  76. package/docs/07_distribution/01_README_NPM.md +36 -35
  77. package/ecosystem/integrations/cline/skills/bugx/SKILL.md +1 -1
  78. package/ecosystem/integrations/dsh/agents/bugx.md +1 -1
  79. package/ecosystem/integrations/dsh/dsh-patch.yml +2 -2
  80. package/ecosystem/integrations/dsh/mcp/package.json +1 -1
  81. package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +1 -1
  82. package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
  83. package/ecosystem/integrations/dsh/ui/package.json +1 -1
  84. package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +1 -1
  85. package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
  86. package/ecosystem/integrations/pi/skills/bugx/SKILL.md +1 -1
  87. package/ecosystem/integrations/qoder/connector-meta.json +9 -9
  88. package/ecosystem/integrations/workbuddy/connector-meta.json +9 -9
  89. package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +2 -2
  90. package/ecosystem/plugins/bugx/.claude-plugin/marketplace.json +2 -2
  91. package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +2 -2
  92. package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +4 -4
  93. package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +2 -2
  94. package/ecosystem/plugins/bugx/agents/bugx-worker.md +1 -1
  95. package/ecosystem/plugins/bugx/agents/bugx.md +1 -1
  96. package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +3 -3
  97. package/ecosystem/plugins/bugx/skills/bugx-claude/SKILL.md +1 -1
  98. package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
  99. package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
  100. package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +1 -1
  101. package/interfaces/bin/bugx.js +9 -7
  102. package/interfaces/cli/bugx_cli/__init__.py +2 -2
  103. package/interfaces/cli/bugx_cli/cli.py +178 -67
  104. package/interfaces/cli/bugx_cli/commands/agent.py +313 -127
  105. package/interfaces/cli/bugx_cli/commands/audit.py +8 -7
  106. package/interfaces/cli/bugx_cli/commands/cloud.py +27 -19
  107. package/interfaces/cli/bugx_cli/commands/doctor.py +18 -0
  108. package/interfaces/cli/bugx_cli/commands/knowledge.py +3 -4
  109. package/interfaces/cli/bugx_cli/commands/lifecycle.py +54 -47
  110. package/interfaces/cli/bugx_cli/commands/plugin.py +9 -9
  111. package/interfaces/cli/bugx_cli/commands/plugin_claude.py +27 -13
  112. package/interfaces/cli/bugx_cli/commands/plugin_kimi.py +348 -0
  113. package/interfaces/cli/bugx_cli/commands/plugin_minimax.py +322 -0
  114. package/interfaces/cli/bugx_cli/commands/plugin_qoder.py +3 -4
  115. package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +4 -5
  116. package/interfaces/cli/bugx_cli/commands/project.py +6 -13
  117. package/interfaces/cli/bugx_cli/commands/system.py +577 -162
  118. package/interfaces/cli/bugx_cli/common.py +102 -15
  119. package/interfaces/cli/bugx_cli/host_adapters.py +150 -4
  120. package/interfaces/cli/bugx_cli/hosts/registry.py +4 -2
  121. package/interfaces/cli/bugx_cli/hosts/template_engine.py +10 -9
  122. package/interfaces/cli/bugx_cli/infra/engine_installer.py +21 -10
  123. package/interfaces/cli/bugx_cli/infra/host_sync.py +1 -1
  124. package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +2 -2
  125. package/package.json +54 -16
  126. package/pyproject.toml +64 -1
  127. package/scripts/sync-version.mjs +1 -1
  128. package/skills/README.md +25 -0
  129. package/skills/platform/bugx-user/SKILL.md +92 -0
  130. package/core/assets/bugx-hero-cn.png +0 -0
  131. package/core/assets/bugx-hero-en.png +0 -0
@@ -0,0 +1,175 @@
1
+ #!/usr/bin/env python3
2
+ """core/host_acp/kimi.py - Kimi Code CLI 的 ACP 适配插件。
3
+
4
+ 实机口径(``kimi 2.1.1``,2026-11-23 实测):
5
+
6
+ * ACP 入口为 ``kimi acp``,通过 stdio 运行标准 JSON-RPC 2.0 Agent Client Protocol
7
+ (``initialize`` 返回 ``protocolVersion: 1``、``agentInfo.name: "Kimi Code CLI"``)。
8
+ * ``kimi acp --help`` 仅接受 ``--login`` 与 ``--region``,无 ``--dir`` / ``--model`` /
9
+ ``--data-dir`` flag;工作区绑定由探针子进程 ``cwd=<probe_root>`` 与 ``session/new``
10
+ 参数提供。
11
+ * 项目级 MCP 配置位于 ``.kimi-code/mcp.json``,容器键为标准 ``mcpServers``
12
+ (``{"command": "...", "args": [...]}``),优先级高于用户级
13
+ ``<KIMI_CODE_HOME>/mcp.json``(默认 ``~/.kimi-code/mcp.json``)。
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import json
19
+ import os
20
+ import shutil
21
+ from pathlib import Path
22
+ from typing import Any
23
+
24
+ from .base import AcpPlugin
25
+
26
+ __all__ = ["KimiAcpPlugin", "PLUGIN", "is_available", "run_static_degraded"]
27
+
28
+ _HOST_NAME = __name__.rsplit(".", 1)[-1]
29
+
30
+
31
+ def _kimi_code_home() -> Path:
32
+ configured = os.environ.get("KIMI_CODE_HOME")
33
+ if configured and configured.strip():
34
+ return Path(configured).expanduser()
35
+ return Path.home() / ".kimi-code"
36
+
37
+
38
+ def _resolve_kimi_executable() -> str | None:
39
+ found = shutil.which("kimi")
40
+ if found:
41
+ return found
42
+ bin_dir = _kimi_code_home() / "bin"
43
+ names = ("kimi.exe", "kimi.cmd", "kimi.bat", "kimi") if os.name == "nt" else ("kimi",)
44
+ for name in names:
45
+ fallback = bin_dir / name
46
+ if fallback.is_file():
47
+ return str(fallback)
48
+ return None
49
+
50
+
51
+ class KimiAcpPlugin(AcpPlugin):
52
+ """Kimi Code CLI ACP 插件。"""
53
+
54
+ name = _HOST_NAME
55
+ executable = "kimi"
56
+ status = "ready"
57
+ supports_project_permissions = False
58
+
59
+ def acp_argv(
60
+ self,
61
+ *,
62
+ model: str | None = None,
63
+ data_dir: Path | str | None = None,
64
+ ) -> list[str]:
65
+ del model, data_dir
66
+ return [_resolve_kimi_executable() or self.executable, "acp"]
67
+
68
+ def launch_policy(self) -> dict[str, Any]:
69
+ """返回 Kimi Code CLI 的 ACP 启动策略。"""
70
+ return {
71
+ "auto_approve": False,
72
+ "auto_approve_flag": None,
73
+ "model_flag": None,
74
+ "reason": "kimi acp 无 --model/--dir flag;工作区由 cwd 绑定,通过 ACP 协议交互",
75
+ }
76
+
77
+ def ensure_probe_servers(
78
+ self,
79
+ project_root: Path,
80
+ config_paths: tuple[Path, ...],
81
+ servers: dict[str, dict[str, Any]],
82
+ ) -> list[str]:
83
+ """将 BugX 通道写入探活项目内部的 ``.kimi-code/mcp.json``(标准 ``mcpServers`` 形状)。"""
84
+ updated: list[str] = []
85
+ root_resolved = project_root.resolve()
86
+ targets = list(config_paths) or [root_resolved / ".kimi-code" / "mcp.json"]
87
+ for path in targets:
88
+ try:
89
+ resolved = path.resolve()
90
+ except OSError:
91
+ continue
92
+ if root_resolved not in resolved.parents and resolved.parent != root_resolved:
93
+ continue # 严格限定只写探活项目内部
94
+ payload: dict[str, Any] = {}
95
+ if resolved.is_file() and not resolved.is_symlink():
96
+ try:
97
+ loaded = json.loads(resolved.read_text(encoding="utf-8"))
98
+ if isinstance(loaded, dict):
99
+ payload = loaded
100
+ except (OSError, UnicodeError, ValueError):
101
+ payload = {}
102
+ mcp_servers = payload.get("mcpServers")
103
+ if not isinstance(mcp_servers, dict):
104
+ mcp_servers = {}
105
+ payload["mcpServers"] = mcp_servers
106
+ changed = False
107
+ for name, spec in servers.items():
108
+ command = spec.get("command")
109
+ args = spec.get("args") or []
110
+ if not isinstance(command, str) or not command:
111
+ raise ValueError(f"无效的探活 MCP 命令: {name}")
112
+ if not isinstance(args, (list, tuple)):
113
+ raise ValueError(f"无效的探活 MCP 参数: {name}")
114
+ expected: dict[str, Any] = {
115
+ "command": command,
116
+ "args": [str(item) for item in args],
117
+ }
118
+ env = spec.get("env")
119
+ if isinstance(env, dict) and env:
120
+ expected["env"] = {str(k): str(v) for k, v in env.items()}
121
+ if mcp_servers.get(name) != expected:
122
+ mcp_servers[name] = expected
123
+ changed = True
124
+ if changed or not resolved.exists():
125
+ resolved.parent.mkdir(parents=True, exist_ok=True)
126
+ resolved.write_text(
127
+ json.dumps(payload, indent=2, ensure_ascii=False) + "\n",
128
+ encoding="utf-8",
129
+ )
130
+ updated.append(str(resolved))
131
+ return updated
132
+
133
+
134
+ PLUGIN = KimiAcpPlugin
135
+
136
+
137
+ def is_available() -> tuple[bool, str]:
138
+ """降级契约:机械探活 Kimi Code CLI 是否安装(零子进程)。"""
139
+ path = _resolve_kimi_executable()
140
+ if path is None:
141
+ return False, "kimi 可执行文件未安装;ACP 适配器无法拉起真实会话"
142
+ return True, path
143
+
144
+
145
+ def run_static_degraded(root: Path | None = None) -> dict:
146
+ """宿主 CLI 缺失/降级时的静态输出:只声明适配器事实,绝不伪装 ACP 会话。"""
147
+ available, availability_detail = is_available()
148
+ plugin = PLUGIN()
149
+ return {
150
+ "adapter": f"core/host_acp/{plugin.name}.py",
151
+ "plugin": plugin.name,
152
+ "schema_version": 1,
153
+ "success": available,
154
+ "status": "degraded",
155
+ "degraded": True,
156
+ "degraded_reason": (
157
+ "static_facts_only" if available else f"{plugin.name}_cli_not_installed"
158
+ ),
159
+ "probe_mode": "static_degraded",
160
+ "acp_status": plugin.status,
161
+ "acp_supported": plugin.supports_acp(),
162
+ "acp_reason": plugin.reason or None,
163
+ "executable": plugin.executable,
164
+ "mcp_health": "unknown",
165
+ "findings": [],
166
+ "evidence": {
167
+ "availability_detail": availability_detail,
168
+ "project_root": str(root) if root else None,
169
+ },
170
+ "metadata": {
171
+ "degraded_mode": "static_adapter_facts_only",
172
+ "mcp_probing": "deferred_to_host_probe_chain",
173
+ "fallback": "宿主 CLI 缺失时由外层宿主/用户决策接管;BugX 不代装宿主 CLI",
174
+ },
175
+ }
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env python3
2
+ """core/host_acp/minimax.py - MiniMax Code ACP capability declaration.
3
+
4
+ MiniMax Code's installed desktop package exposes Plugin V1, MCP and Agent
5
+ manifests. A standard ACP entry point was not found in the inspected package,
6
+ so this is an explicit upstream-capability declaration, not an unfinished local
7
+ adapter.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from .base import AcpPlugin
13
+
14
+ __all__ = ["MiniMaxAcpPlugin", "PLUGIN"]
15
+
16
+
17
+ class MiniMaxAcpPlugin(AcpPlugin):
18
+ name = "minimax"
19
+ executable = "mcode"
20
+ status = "unavailable"
21
+ reason = (
22
+ "MiniMax Code 3.1.0 桌面包已取证 Plugin V1、MCP 与 Agent 能力,"
23
+ "但未取证到标准 ACP 入口;ACP 探活不伪造命令行参数。"
24
+ )
25
+ supports_project_permissions = False
26
+
27
+
28
+ PLUGIN = MiniMaxAcpPlugin
@@ -38,6 +38,8 @@ SUPPORTED_HOSTS: tuple[str, ...] = (
38
38
  "cline",
39
39
  "zcode",
40
40
  "dsh",
41
+ "kimi",
42
+ "minimax",
41
43
  "chatgpt",
42
44
  "workbuddy",
43
45
  "qoder",
@@ -87,15 +89,33 @@ _apply_plugin_markers(HOST_MARKERS)
87
89
  #: 已迁移插件(只读视图):宿主事实的唯一来源。
88
90
  _HOST_PLUGINS = MappingProxyType(dict(host_plugins.PLUGINS))
89
91
 
90
- # FunIDE 当前确认的是桌面 Copilot Agent UI,尚未确认独立的
91
- # AskUserQuestion 原生工具;保持安全默认,交互交给外层控制器或 TTY。
92
- NATIVE_QUESTION_HOSTS: frozenset[str] = frozenset(SUPPORTED_HOSTS) - {"funide"}
92
+ # 未迁移宿主的交互事实仍由旧基线维护;已迁移宿主直接读取插件身份面。
93
+ _LEGACY_NON_NATIVE_QUESTION_HOSTS: frozenset[str] = frozenset({"funide"})
94
+ NATIVE_QUESTION_HOSTS: frozenset[str] = frozenset(
95
+ name for name in SUPPORTED_HOSTS
96
+ if (
97
+ (
98
+ name in _HOST_PLUGINS
99
+ and _HOST_PLUGINS[name].identity.native_question
100
+ )
101
+ or (
102
+ name not in _HOST_PLUGINS
103
+ and name not in _LEGACY_NON_NATIVE_QUESTION_HOSTS
104
+ )
105
+ )
106
+ )
93
107
 
94
108
  # 宿主可执行名别名 → 规范宿主名。进程树识别必须经此归一化,避免
95
109
  # 「同一宿主多个可执行名」散落在各调用点。
96
110
  HOST_EXECUTABLE_ALIASES: dict[str, str] = {
97
111
  "claude-code": "claude",
98
112
  "deepseek": "dsh",
113
+ "kimi-code": "kimi",
114
+ "kimicode": "kimi",
115
+ "minimax-code": "minimax",
116
+ "minimaxcode": "minimax",
117
+ "minimax code": "minimax",
118
+ "mcode": "minimax",
99
119
  "codebuddy": "workbuddy",
100
120
  "codebuddy-lite-wb": "workbuddy",
101
121
  "qoder-cli": "qoder",
package/core/hosts/dsh.py CHANGED
@@ -96,7 +96,7 @@ def _dsh_home() -> Path:
96
96
  import os
97
97
 
98
98
  configured = os.environ.get("DSH_HOME", "").strip()
99
- return Path(configured) if configured else Path.home() / ".dsh"
99
+ return Path(configured).expanduser() if configured else Path.home() / ".dsh"
100
100
 
101
101
 
102
102
  def _profile_patch_path() -> Path:
@@ -0,0 +1,293 @@
1
+ #!/usr/bin/env python3
2
+ """core/hosts/kimi.py - Kimi Code CLI 插件(DOC-239 六面架构完整适配)。
3
+
4
+ 事实来源(2026-11-23 实测,Kimi Code 1.4.2 / ``KIMI_CODE_HOME``):
5
+
6
+ * identity ← ``kimi --help``:可执行文件名为 ``kimi``,别名 ``kimi-code`` / ``kimicode``;
7
+ 项目标记为 ``.kimi-code/mcp.json`` 与 ``.kimi-code``。
8
+ * install ← ``subagent`` 入口:``.kimi-code/agents/bugx.md`` 与
9
+ ``.kimi-code/agents/bugx-worker.md``;支持项目级与用户级
10
+ ``~/.kimi-code/skills/`` 及原生 ``mcpServers`` 配置。
11
+ * engine_run ← 无头通道为 ``kimi -p <prompt>``,自治执行为
12
+ ``kimi -p <prompt> --output-format stream-json --auto``;
13
+ 支持自定义 subagent 定义(``--agent`` / ``--agent-file``)。
14
+ * worker_runtime← ``mode="multi"``,支持 CLI 并发调度。
15
+ * mcp_write ← 配置容器键为 ``mcpServers``,项目级作用域为 ``.kimi-code/mcp.json``,
16
+ 全局作用域为 ``<KIMI_CODE_HOME>/mcp.json``(默认 ``~/.kimi-code/mcp.json``)。
17
+ * distribution ← 桌面端插件目录为 ``<KIMI_CODE_HOME>/plugins/managed/<id>``,
18
+ 启用注册表为 ``<KIMI_CODE_HOME>/plugins/installed.json``。
19
+ * acp ← ``kimi acp`` 原生支持标准 JSON-RPC 2.0 ACP 协议,由
20
+ ``core/host_acp/kimi.py`` 以 ``status="ready"`` 声明。
21
+ """
22
+
23
+ from __future__ import annotations
24
+
25
+ import os
26
+ import platform
27
+ import shutil
28
+ from pathlib import Path
29
+
30
+ from .base import (
31
+ AcpFacet,
32
+ EngineRunFacet,
33
+ HostPlugin,
34
+ IdentityFacet,
35
+ InstallFacet,
36
+ McpWriteFacet,
37
+ RunContext,
38
+ STATUS_READY,
39
+ WorkerRuntimeFacet,
40
+ )
41
+
42
+ __all__ = ["PLUGIN", "is_available", "run_static_degraded"]
43
+
44
+ _NAME = "kimi"
45
+
46
+ _PROJECT_PATHS: tuple[str, ...] = (
47
+ ".kimi-code/agents/bugx.md",
48
+ ".kimi-code/agents/bugx-worker.md",
49
+ )
50
+
51
+ _CUSTOM_TITLE = "# BugX\n\n这是 BugX 的 Kimi Code 审计智能体入口。"
52
+
53
+ _CUSTOM_PREAMBLE = (
54
+ "先读取全局引擎协议:\n"
55
+ "通过 `bugx engine path --name bugx-runtime-contract.md` 读取全局协议,\n"
56
+ "并遵守其中的寿命、Supervisor、证据和报告协议。\n\n"
57
+ "该入口只把任务交给当前 Kimi Code 会话;BugX CLI 只安装资源,不启动 Kimi Code、不执行审计。\n"
58
+ )
59
+
60
+
61
+ def _kimi_code_home() -> Path:
62
+ configured = os.environ.get("KIMI_CODE_HOME")
63
+ if configured and configured.strip():
64
+ return Path(configured).expanduser()
65
+ return Path.home() / ".kimi-code"
66
+
67
+
68
+ def _resolve_kimi_executable() -> str | None:
69
+ found = shutil.which("kimi")
70
+ if found:
71
+ return found
72
+ bin_dir = _kimi_code_home() / "bin"
73
+ names = ("kimi.exe", "kimi.cmd", "kimi.bat", "kimi") if os.name == "nt" else ("kimi",)
74
+ for name in names:
75
+ fallback = bin_dir / name
76
+ if fallback.is_file():
77
+ return str(fallback)
78
+ return None
79
+
80
+
81
+ def _windows_drive_roots() -> tuple[Path, ...]:
82
+ """返回 Windows 当前可用的逻辑驱动器根目录。"""
83
+ if platform.system() != "Windows":
84
+ return ()
85
+ try:
86
+ import ctypes
87
+
88
+ mask = int(ctypes.windll.kernel32.GetLogicalDrives())
89
+ except (AttributeError, OSError, TypeError, ValueError):
90
+ return ()
91
+ return tuple(
92
+ Path(f"{chr(ord('A') + index)}:/")
93
+ for index in range(26)
94
+ if mask & (1 << index)
95
+ )
96
+
97
+
98
+ def _headless_argv(ctx: RunContext) -> list[str]:
99
+ command = [_resolve_kimi_executable() or "kimi", "-p", ctx.prompt]
100
+ if ctx.session:
101
+ command[1:1] = ["--session", ctx.session]
102
+ if ctx.model:
103
+ command += ["-m", ctx.model]
104
+ return command
105
+
106
+
107
+ def _autonomous_argv(ctx: RunContext) -> list[str]:
108
+ command = [_resolve_kimi_executable() or "kimi"]
109
+ if ctx.session:
110
+ command += ["--session", ctx.session]
111
+ if ctx.model:
112
+ command += ["-m", ctx.model]
113
+ command += [
114
+ "-p",
115
+ ctx.prompt,
116
+ "--output-format",
117
+ "stream-json",
118
+ "--auto",
119
+ ]
120
+ return command
121
+
122
+
123
+ def _mcp_config_paths(root: Path) -> tuple[Path, ...]:
124
+ return (root / ".kimi-code" / "mcp.json",)
125
+
126
+
127
+ def _kimi_app_markers() -> tuple[Path, ...]:
128
+ """Kimi 桌面端已知安装位置。"""
129
+ home = Path.home()
130
+ markers: list[Path] = []
131
+ if platform.system() == "Darwin":
132
+ markers.extend((
133
+ Path("/Applications/Kimi.app"),
134
+ Path("/Applications/Kimi Code.app"),
135
+ home / "Applications" / "Kimi.app",
136
+ home / "Applications" / "Kimi Code.app",
137
+ home / "Library" / "Application Support" / "kimi-desktop",
138
+ home / "Library" / "Application Support" / "Kimi Code",
139
+ ))
140
+ elif os.name != "nt":
141
+ markers.extend((
142
+ home / ".local" / "share" / "applications" / "kimi.desktop",
143
+ home / ".local" / "share" / "applications" / "kimi-code.desktop",
144
+ Path("/usr/bin/kimi-desktop"),
145
+ Path("/usr/bin/kimi-code"),
146
+ Path("/opt/Kimi/kimi"),
147
+ Path("/opt/Kimi Code/kimi-code"),
148
+ ))
149
+
150
+ bases: list[Path] = []
151
+ for variable in (
152
+ "LOCALAPPDATA", "APPDATA", "PROGRAMFILES", "PROGRAMFILES(X86)",
153
+ ):
154
+ value = os.environ.get(variable)
155
+ if value:
156
+ bases.append(Path(value))
157
+ bases.extend(_windows_drive_roots())
158
+ for base in bases:
159
+ markers.extend((
160
+ base / "Kimi" / "Kimi.exe",
161
+ base / "kimi-desktop" / "Kimi.exe",
162
+ base / "Kimi Code" / "Kimi Code.exe",
163
+ base / "Programs" / "Kimi" / "Kimi.exe",
164
+ base / "Programs" / "kimi-desktop" / "Kimi.exe",
165
+ base / "Programs" / "Kimi Code" / "Kimi Code.exe",
166
+ base / "Program Files" / "Kimi Code" / "Kimi Code.exe",
167
+ base / "Program Files (x86)" / "Kimi Code" / "Kimi Code.exe",
168
+ ))
169
+ return tuple(markers)
170
+
171
+
172
+ def _agent_config_path(root: Path) -> Path:
173
+ return root / ".kimi-code"
174
+
175
+
176
+ PLUGIN = HostPlugin(
177
+ identity=IdentityFacet(
178
+ name=_NAME,
179
+ label="Kimi Code",
180
+ order=14,
181
+ executable="kimi",
182
+ markers=(".kimi-code/mcp.json", ".kimi-code"),
183
+ aliases=("kimi-code", "kimicode"),
184
+ app_markers=_kimi_app_markers,
185
+ native_question=True,
186
+ ),
187
+ status=STATUS_READY,
188
+ install=InstallFacet(
189
+ kind="subagent",
190
+ path=".kimi-code/agents/bugx.md",
191
+ marker=".kimi-code",
192
+ required_paths=_PROJECT_PATHS,
193
+ capabilities=frozenset(
194
+ {
195
+ "native-mcp-config",
196
+ "extra-tracked-paths",
197
+ "skills",
198
+ "user-agent-registration",
199
+ }
200
+ ),
201
+ interaction={
202
+ "tool": "AskUserQuestion",
203
+ "single_select": "multiSelect=false",
204
+ "multi_select": "tooling:batch 时使用 multiSelect=true",
205
+ },
206
+ tools_line="Bash, Read, Grep, Glob, Edit, Write",
207
+ mcp_relpaths=(".kimi-code/mcp.json",),
208
+ worker_subagent=True,
209
+ worker_entry_path=".kimi-code/agents/bugx-worker.md",
210
+ custom_title=_CUSTOM_TITLE,
211
+ custom_preamble=_CUSTOM_PREAMBLE,
212
+ generated_dirs=(".kimi-code",),
213
+ sweepable=True,
214
+ ),
215
+ engine_run=EngineRunFacet(
216
+ supports_headless=True,
217
+ headless_argv=_headless_argv,
218
+ autonomous_argv=_autonomous_argv,
219
+ mcp_config_paths=_mcp_config_paths,
220
+ agent_config_path=_agent_config_path,
221
+ mcp_health=None,
222
+ host_surface="tui",
223
+ recon_scout_argv=lambda _root, text, _prompt_file, _inventory=None: [
224
+ _resolve_kimi_executable() or "kimi",
225
+ "-p",
226
+ text,
227
+ "--output-format",
228
+ "text",
229
+ "--auto",
230
+ ],
231
+ native_task=True,
232
+ ),
233
+ worker_runtime=WorkerRuntimeFacet(
234
+ mode="multi",
235
+ max_concurrency=None,
236
+ requires_process_mode=False,
237
+ sandbox_sync=(),
238
+ ),
239
+ mcp_write=McpWriteFacet(
240
+ container_key="mcpServers",
241
+ writer_key=_NAME,
242
+ project_relpath=".kimi-code/mcp.json",
243
+ global_scope="~/.kimi-code/mcp.json",
244
+ mirror_relpaths=(),
245
+ requires_absolutize=True,
246
+ entry_extra={},
247
+ ),
248
+ acp=AcpFacet(plugin=_NAME),
249
+ )
250
+
251
+
252
+ def is_available() -> tuple[bool, str]:
253
+ """降级契约:机械探活 Kimi Code CLI 是否安装(零子进程)。"""
254
+ path = _resolve_kimi_executable()
255
+ if path is None:
256
+ return False, "kimi 可执行文件未安装;headless(kimi -p)与 ACP(kimi acp)通道不可用"
257
+ return True, path
258
+
259
+
260
+ def run_static_degraded(root: Path | None = None) -> dict:
261
+ """Kimi Code CLI 缺失时的静态降级输出:只声明插件事实,绝不伪装宿主健康。"""
262
+ available, availability_detail = is_available()
263
+ return {
264
+ "plugin": _NAME,
265
+ "schema_version": 1,
266
+ "success": available,
267
+ "status": "degraded",
268
+ "degraded": True,
269
+ "degraded_reason": (
270
+ "static_facts_only" if available else "kimi_cli_not_installed"
271
+ ),
272
+ "probe_mode": "static_degraded",
273
+ "headless_available": available,
274
+ "native_task_available": bool(available and PLUGIN.engine_run.native_task),
275
+ "identity": {
276
+ "executable": PLUGIN.identity.executable,
277
+ "aliases": list(PLUGIN.identity.aliases),
278
+ "markers": list(PLUGIN.identity.markers),
279
+ },
280
+ "agent_entry": PLUGIN.install.path,
281
+ "mcp_project_relpath": PLUGIN.mcp_write.project_relpath,
282
+ "mcp_global_scope": PLUGIN.mcp_write.global_scope,
283
+ "findings": [],
284
+ "evidence": {
285
+ "availability_detail": availability_detail,
286
+ "project_root": str(root) if root else None,
287
+ },
288
+ "metadata": {
289
+ "degraded_mode": "static_plugin_facts_only",
290
+ "acp": "ready(kimi acp 原生支持标准 ACP,见 core/host_acp/kimi.py)",
291
+ "fallback": "宿主 CLI 缺失时由外层宿主/用户决策接管;BugX 不代装宿主 CLI",
292
+ },
293
+ }