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.
- package/README.md +26 -29
- package/core/README.md +5 -3
- package/core/agent/agent_orchestrator.py +3 -0
- package/core/agent/agent_workspace.py +14 -2
- package/core/assets/bugx-wechat-group.png +0 -0
- package/core/assets/twitter_promo_art.jpg +0 -0
- package/core/assets/twitter_promo_card.svg +166 -0
- package/core/assets/twitter_promo_clean.jpg +0 -0
- package/core/assets/twitter_terminal_real.png +0 -0
- package/core/bugx.md +3 -3
- package/core/bugx_paths.py +10 -2
- package/core/bundled_docs/OVERVIEW.md +310 -0
- package/core/bundled_docs/README.md +10 -0
- package/core/bundled_docs/README_EN.md +278 -0
- package/core/bundled_docs/ai/01_AI_REFERENCE.md +833 -0
- package/core/bundled_docs/ai/02_AI_USAGE.md +161 -0
- package/core/bundled_docs/ai/03_AI_COMMANDS.md +322 -0
- package/core/bundled_docs/guides/01_USER_GUIDE.md +887 -0
- package/core/bundled_docs/guides/02_COMMANDS.md +935 -0
- package/core/bundled_docs/guides/03_TROUBLESHOOTING.md +763 -0
- package/core/bundled_docs/guides/04_CLOUD_AUTH_AND_SYNC_COOKBOOK.md +48 -0
- package/core/bundled_docs/guides/05_HOST_MATRIX_AND_DISPATCH.md +23 -0
- package/core/bundled_docs/guides/06_PROBES_AND_POC_COOKBOOK.md +49 -0
- package/core/bundled_docs/guides/07_LIFECYCLE_AND_RECOVERY_STATES.md +46 -0
- package/core/bundled_docs/guides/08_LESSONS_AND_PRIVACY_BOUNDARY.md +35 -0
- package/core/bundled_docs/hosts/bugx-claude_SKILL.md +326 -0
- package/core/bundled_docs/hosts/bugx-dsh_SKILL.md +229 -0
- package/core/bundled_docs/hosts/bugx-opencode_SKILL.md +129 -0
- package/core/bundled_docs/hosts/bugx-zcode_SKILL.md +459 -0
- package/core/bundled_docs/hosts/bugx_SKILL.md +118 -0
- package/core/bundled_docs/hosts/cline_bugx_SKILL.md +69 -0
- package/core/bundled_docs/hosts/platform_bugx_SKILL.md +50 -0
- package/core/bundled_docs/manifest.json +140 -0
- package/core/bundled_docs/reference/01_ENVIRONMENT_VARIABLES.md +421 -0
- package/core/bundled_docs/reference/04_REPOSITORY_TOPOLOGY.md +180 -0
- package/core/cli-help.txt +7 -3
- package/core/cloud_sync/cloud_client.py +81 -2
- package/core/cloud_sync/endpoint_router.py +22 -9
- package/core/cloud_sync/issue_uploader.py +297 -0
- package/core/cloud_sync/sensitive_filter.py +77 -7
- package/core/contracts/AGENT_GUIDE.md +3 -9
- package/core/contracts/README.md +1 -1
- package/core/contracts/bugx-opencode.md +1 -1
- package/core/contracts/bugx-runtime-contract.md +10 -20
- package/core/contracts/bugx-worker.md +1 -1
- package/core/engine-integrity.json +267 -111
- package/core/host_acp/antigravity.py +153 -0
- package/core/host_acp/kimi.py +175 -0
- package/core/host_acp/minimax.py +28 -0
- package/core/host_runtime/adapters.py +5 -1
- package/core/host_runtime/antigravity.py +162 -0
- package/core/host_runtime/host_bootstrap.py +18 -7
- package/core/host_runtime/host_evaluators.py +4 -4
- package/core/host_runtime/host_registry.py +25 -4
- package/core/host_runtime/mcp_process_tracker.py +30 -3
- package/core/host_runtime/mcp_registry_gate.py +34 -11
- package/core/hosts/antigravity.py +115 -0
- package/core/hosts/codex.py +3 -0
- package/core/hosts/dsh.py +43 -24
- package/core/hosts/kimi.py +293 -0
- package/core/hosts/minimax.py +249 -0
- package/core/hosts/zcode.py +5 -0
- package/core/i18n.py +94 -5
- package/core/infra/README.md +1 -1
- package/core/infra/build_info.py +30 -5
- package/core/launch_phases/README.md +2 -2
- package/core/launch_phases/startup_version_gate.py +2 -2
- package/core/launch_phases/supervisor_bridge.py +16 -23
- package/core/launch_phases/supervisor_degraded.py +7 -5
- package/core/ledger/README.md +1 -1
- package/core/locales/en-US.json +3 -3
- package/core/locales/zh-CN.json +3 -3
- package/core/mcp_runtime_support/environment.py +6 -1
- package/core/metadata.txt +2 -2
- package/core/planning/README.md +1 -1
- package/core/planning/prompt_harness.py +2 -2
- package/core/probes/codebase_memory_probe.py +43 -24
- package/core/probes/probe_registry.py +10 -7
- package/core/prompts/command_routing_en.md +6 -5
- package/core/prompts/command_routing_zh.md +6 -5
- package/core/repair/rsi_rounds.py +3 -0
- package/core/repair/self_heal.py +160 -6
- package/core/retrieval/README.md +1 -1
- package/core/runtime/README.md +1 -1
- package/core/runtime/scenario_eval.py +5 -1
- package/core/runtime/setup_ui_env.py +4 -7
- package/core/runtime/tool_install_targets.py +12 -2
- package/core/skills/README.md +4 -2
- package/core/skills/bugx_docs_cloud_sync.py +658 -0
- package/core/skills/bugx_docs_mcp_server.py +966 -140
- package/core/supervisor/README.md +1 -1
- package/core/supervisor/cli.py +2 -2
- package/core/supervisor/worker_execution.py +16 -3
- package/core/webui/docs_session_service.py +40 -2
- package/core/webui/mcp_inspector.py +12 -6
- package/core/webui/static/index.html +51 -3
- package/core/webui/static/manifest.webmanifest +1 -1
- package/core/webui/static/project-settings.js +18 -3
- package/core/webui/static/robots.txt +36 -0
- package/core/webui/static/sitemap.xml +15 -0
- package/docs/07_distribution/01_README_NPM.md +26 -29
- package/ecosystem/integrations/cline/skills/bugx/SKILL.md +46 -46
- package/ecosystem/integrations/dsh/agents/bugx.md +2 -1
- package/ecosystem/integrations/dsh/dsh-patch.yml +2 -2
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +6 -6
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +2 -2
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/pi/skills/bugx/SKILL.md +6 -6
- package/ecosystem/integrations/qoder/CONNECTORS.md +11 -23
- package/ecosystem/integrations/qoder/connector-meta.json +9 -9
- package/ecosystem/integrations/workbuddy/connector-meta.json +9 -9
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +8 -7
- package/ecosystem/plugins/bugx/.claude-plugin/marketplace.json +2 -2
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +2 -2
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +4 -4
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +2 -2
- package/ecosystem/plugins/bugx/agents/bugx-worker.md +14 -18
- package/ecosystem/plugins/bugx/agents/bugx.md +45 -49
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +8 -8
- package/ecosystem/plugins/bugx/skills/bugx-claude/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +3 -3
- package/interfaces/bin/bugx.js +2 -0
- package/interfaces/cli/bugx_cli/__init__.py +2 -2
- package/interfaces/cli/bugx_cli/cli.py +153 -8
- package/interfaces/cli/bugx_cli/commands/agent.py +568 -136
- package/interfaces/cli/bugx_cli/commands/cloud.py +42 -1
- package/interfaces/cli/bugx_cli/commands/doctor.py +668 -223
- package/interfaces/cli/bugx_cli/commands/guide.py +143 -0
- package/interfaces/cli/bugx_cli/commands/issue.py +262 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +99 -62
- package/interfaces/cli/bugx_cli/commands/plugin.py +301 -60
- package/interfaces/cli/bugx_cli/commands/plugin_antigravity.py +350 -0
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +27 -13
- package/interfaces/cli/bugx_cli/commands/plugin_kimi.py +440 -0
- package/interfaces/cli/bugx_cli/commands/plugin_minimax.py +522 -0
- package/interfaces/cli/bugx_cli/commands/plugin_qoder.py +3 -4
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +4 -5
- package/interfaces/cli/bugx_cli/commands/system.py +75 -5
- package/interfaces/cli/bugx_cli/common.py +135 -15
- package/interfaces/cli/bugx_cli/host_adapters.py +190 -7
- package/interfaces/cli/bugx_cli/hosts/registry.py +6 -3
- package/interfaces/cli/bugx_cli/hosts/template_engine.py +31 -11
- package/interfaces/cli/bugx_cli/infra/__init__.py +4 -0
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +14 -12
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +76 -10
- package/interfaces/cli/bugx_cli/infra/host_sync.py +66 -1
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +242 -52
- package/package.json +38 -13
- package/pyproject.toml +57 -13
- package/scripts/sync-version.mjs +1 -1
- package/skills/README.md +24 -0
- package/skills/platform/bugx/SKILL.md +50 -0
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""interfaces/cli/bugx_cli/commands/plugin_kimi.py - Kimi Code CLI 与桌面端插件适配。"""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import datetime
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
import shutil
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from ..common import (
|
|
14
|
+
CliError,
|
|
15
|
+
_resolve_locale_name,
|
|
16
|
+
asset_root,
|
|
17
|
+
global_engine_root,
|
|
18
|
+
)
|
|
19
|
+
from ..hosts.template_engine import (
|
|
20
|
+
add_locale_marker,
|
|
21
|
+
get_agent_description,
|
|
22
|
+
get_worker_description,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
KIMI_PLUGIN_ICON_URL = "https://bugx.dev/brand-mark.svg"
|
|
27
|
+
KIMI_PLUGIN_BRAND_COLOR = "#0284c7"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _kimi_code_home() -> Path:
|
|
31
|
+
"""返回 Kimi Code 当前跨平台数据根目录。
|
|
32
|
+
|
|
33
|
+
Kimi Code 1.4.x 的桌面端与 CLI 都通过 ``KIMI_CODE_HOME``(未设置时
|
|
34
|
+
``~/.kimi-code``)解析插件目录;旧版 ``daimon-share`` 不是当前插件
|
|
35
|
+
注册协议,不能作为回退路径。
|
|
36
|
+
"""
|
|
37
|
+
configured = os.environ.get("KIMI_CODE_HOME")
|
|
38
|
+
if configured is not None:
|
|
39
|
+
if not configured.strip():
|
|
40
|
+
raise CliError("KIMI_CODE_HOME 不能为空。")
|
|
41
|
+
return Path(configured).expanduser().resolve()
|
|
42
|
+
return (Path.home() / ".kimi-code").resolve()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _find_bugx_skill_source(root: Path, source: Path) -> Path | None:
|
|
46
|
+
"""定位可复用的 BugX SKILL.md 源文件。"""
|
|
47
|
+
from ..infra.host_sync import find_bugx_skill_source
|
|
48
|
+
|
|
49
|
+
return find_bugx_skill_source(root, source)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _find_bugx_avatar_source() -> Path | None:
|
|
53
|
+
"""定位官方 BugX 图标源文件。"""
|
|
54
|
+
candidates = (
|
|
55
|
+
asset_root() / "bugx-avatar-512.png",
|
|
56
|
+
asset_root() / "assets" / "bugx-avatar-512.png",
|
|
57
|
+
global_engine_root() / "assets" / "bugx-avatar-512.png",
|
|
58
|
+
Path(__file__).resolve().parents[4] / "core" / "assets" / "bugx-avatar-512.png",
|
|
59
|
+
)
|
|
60
|
+
for candidate in candidates:
|
|
61
|
+
if not candidate.is_symlink() and candidate.is_file():
|
|
62
|
+
return candidate
|
|
63
|
+
return None
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _build_agent_bugx(locale: str | None = None) -> str:
|
|
67
|
+
loc = _resolve_locale_name(locale)
|
|
68
|
+
desc = get_agent_description(loc)
|
|
69
|
+
is_zh = loc.startswith("zh")
|
|
70
|
+
body = (
|
|
71
|
+
"# BugX\n\n"
|
|
72
|
+
"这是 BugX 的 Kimi Code 入口。\n\n"
|
|
73
|
+
"先读取全局引擎协议:\n"
|
|
74
|
+
"通过 `bugx engine path --name bugx-runtime-contract.md` 和\n"
|
|
75
|
+
"`bugx engine path --name bugx-quick.md` 读取全局协议,并遵守其中的寿命、Supervisor、\n"
|
|
76
|
+
"证据和报告协议。\n\n"
|
|
77
|
+
"该入口只把任务交给当前 Kimi Code 会话;BugX CLI 只安装资源,不直接执行审计。\n\n"
|
|
78
|
+
"## 交互适配\n"
|
|
79
|
+
"- 使用结构化提示呈现交互决策。\n"
|
|
80
|
+
"- 确保可访问 `bugx-supervisor` 与 `bugx-supervisor-worker` MCP 工具。\n"
|
|
81
|
+
) if is_zh else (
|
|
82
|
+
"# BugX\n\n"
|
|
83
|
+
"This is BugX's Kimi Code entry.\n\n"
|
|
84
|
+
"Read the global engine protocol first:\n"
|
|
85
|
+
"load the global protocol via `bugx engine path --name bugx-runtime-contract.md` and\n"
|
|
86
|
+
"`bugx engine path --name bugx-quick.md`, and follow the lifetime, Supervisor,\n"
|
|
87
|
+
"evidence, and reporting protocols in them.\n\n"
|
|
88
|
+
"This entry only hands the task to the current Kimi Code session; BugX CLI installs\n"
|
|
89
|
+
"resources and does not run audits directly.\n\n"
|
|
90
|
+
"## Interaction Adaptation\n"
|
|
91
|
+
"- Present interaction decisions with structured prompts.\n"
|
|
92
|
+
"- Ensure `bugx-supervisor` and `bugx-supervisor-worker` MCP tools are accessible.\n"
|
|
93
|
+
)
|
|
94
|
+
rendered = (
|
|
95
|
+
"---\n"
|
|
96
|
+
"name: bugx\n"
|
|
97
|
+
f"description: {desc}\n"
|
|
98
|
+
"tools: Bash, Read, Grep, Glob, Edit, Write, AskUserQuestion\n"
|
|
99
|
+
"color: cyan\n"
|
|
100
|
+
"---\n\n"
|
|
101
|
+
+ body
|
|
102
|
+
)
|
|
103
|
+
return add_locale_marker(rendered, loc)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _build_agent_worker(locale: str | None = None) -> str:
|
|
107
|
+
loc = _resolve_locale_name(locale)
|
|
108
|
+
desc = get_worker_description(loc)
|
|
109
|
+
is_zh = loc.startswith("zh")
|
|
110
|
+
body = (
|
|
111
|
+
"# BugX Worker\n\n"
|
|
112
|
+
"这是 BugX Worker 执行子智能体。\n\n"
|
|
113
|
+
"## 执行规则\n"
|
|
114
|
+
"- 遵守任务分配与租约限制。\n"
|
|
115
|
+
"- 向 `bugx-supervisor-worker` 上报心跳与检查点。\n"
|
|
116
|
+
"- 为确认的缺陷提供可独立执行的验证脚本(PoC)。\n"
|
|
117
|
+
) if is_zh else (
|
|
118
|
+
"# BugX Worker\n\n"
|
|
119
|
+
"This is the BugX Worker execution sub-agent.\n\n"
|
|
120
|
+
"## Execution Rules\n"
|
|
121
|
+
"- Obey task assignment and lease constraints.\n"
|
|
122
|
+
"- Report heartbeats and checkpoints to `bugx-supervisor-worker`.\n"
|
|
123
|
+
"- Provide standalone proof-of-concept (PoC) scripts for confirmed defects.\n"
|
|
124
|
+
)
|
|
125
|
+
rendered = (
|
|
126
|
+
"---\n"
|
|
127
|
+
"name: bugx-worker\n"
|
|
128
|
+
f"description: {desc}\n"
|
|
129
|
+
"tools: Bash, Read, Grep, Glob, Edit, Write\n"
|
|
130
|
+
"color: green\n"
|
|
131
|
+
"---\n\n"
|
|
132
|
+
+ body
|
|
133
|
+
)
|
|
134
|
+
return add_locale_marker(rendered, loc)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _build_desktop_plugin_manifest(version: str = "0.1.3", locale: str | None = None) -> dict[str, Any]:
|
|
138
|
+
"""生成具备完整桌面端 UI / 徽标与 MCP 通道配置的 kimi.plugin.json。"""
|
|
139
|
+
loc = _resolve_locale_name(locale)
|
|
140
|
+
desc = get_agent_description(loc)
|
|
141
|
+
return {
|
|
142
|
+
"name": "bugx",
|
|
143
|
+
"version": version,
|
|
144
|
+
"description": desc,
|
|
145
|
+
"homepage": "https://bugx.dev",
|
|
146
|
+
"author": {
|
|
147
|
+
"name": "BugX",
|
|
148
|
+
"url": "https://bugx.dev",
|
|
149
|
+
},
|
|
150
|
+
"license": "MIT",
|
|
151
|
+
"keywords": [
|
|
152
|
+
"security",
|
|
153
|
+
"code-audit",
|
|
154
|
+
"code-review",
|
|
155
|
+
"vulnerability",
|
|
156
|
+
"mcp",
|
|
157
|
+
"bugx",
|
|
158
|
+
],
|
|
159
|
+
"agents": "./agents",
|
|
160
|
+
"skills": "./skills",
|
|
161
|
+
"interface": {
|
|
162
|
+
"defaultLocale": "zh-CN",
|
|
163
|
+
"displayName": "BugX",
|
|
164
|
+
"shortDescription": "自主代码审查与自主测试智能体",
|
|
165
|
+
"longDescription": "BugX 是一个具备自主代码审查与测试能力的智能体,严把代码交付关:它帮助开发人员在写完代码后自动排查隐藏的深层 Bug,减少反复排错与返工;帮助测试人员自动化运行黑盒测试、功能验证与性能测试,自动覆盖手工盲测难以覆盖的极端场景;确保代码功能符合要求、具备良好的健壮性和稳定性。让开发和测试在繁琐的工作中解放双手,大幅提高工作效率、全面提升代码质量、显著降低后期维护成本,实现科技服务于人。",
|
|
166
|
+
"developerName": "BugX",
|
|
167
|
+
"websiteURL": "https://bugx.dev",
|
|
168
|
+
"category": "PRODUCTIVITY",
|
|
169
|
+
"hostKind": "local",
|
|
170
|
+
"tryPrompts": [
|
|
171
|
+
"对当前项目执行自主代码审查,找出深层 Bug",
|
|
172
|
+
"为当前项目执行自动化测试,验证功能与稳定性",
|
|
173
|
+
],
|
|
174
|
+
"brandColor": {
|
|
175
|
+
"light": KIMI_PLUGIN_BRAND_COLOR,
|
|
176
|
+
"dark": KIMI_PLUGIN_BRAND_COLOR,
|
|
177
|
+
},
|
|
178
|
+
"iconUrl": KIMI_PLUGIN_ICON_URL,
|
|
179
|
+
},
|
|
180
|
+
"mcpServers": {
|
|
181
|
+
"bugx-supervisor": {
|
|
182
|
+
"command": "bugx",
|
|
183
|
+
"args": [
|
|
184
|
+
"mcp",
|
|
185
|
+
"serve",
|
|
186
|
+
"--root",
|
|
187
|
+
".",
|
|
188
|
+
"--role",
|
|
189
|
+
"host",
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
"bugx-supervisor-worker": {
|
|
193
|
+
"command": "bugx",
|
|
194
|
+
"args": [
|
|
195
|
+
"mcp",
|
|
196
|
+
"serve",
|
|
197
|
+
"--root",
|
|
198
|
+
".",
|
|
199
|
+
"--role",
|
|
200
|
+
"worker",
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
"bugx-docs": {
|
|
204
|
+
"command": "bugx",
|
|
205
|
+
"args": [
|
|
206
|
+
"mcp",
|
|
207
|
+
"docs",
|
|
208
|
+
"serve",
|
|
209
|
+
"--root",
|
|
210
|
+
".",
|
|
211
|
+
"--db",
|
|
212
|
+
".bugx/knowledge/docs.sqlite3",
|
|
213
|
+
],
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _ensure_kimi_plugin(
|
|
220
|
+
root: Path,
|
|
221
|
+
source: Path,
|
|
222
|
+
*,
|
|
223
|
+
locale: str | None = None,
|
|
224
|
+
) -> dict[str, Any]:
|
|
225
|
+
"""安装并激活 Kimi Code 当前插件协议中的 BugX 插件。
|
|
226
|
+
|
|
227
|
+
Kimi Code 1.4.x 的真实注册面是 ``<KIMI_CODE_HOME>/plugins``:插件
|
|
228
|
+
文件放在 ``managed/bugx``,启用状态登记在 ``installed.json``。这里
|
|
229
|
+
只写入这一套当前契约;若宿主数据根不存在则立即失败,避免安装命令
|
|
230
|
+
返回成功但插件实际没有注册。
|
|
231
|
+
"""
|
|
232
|
+
loc = _resolve_locale_name(locale)
|
|
233
|
+
kimi_home = _kimi_code_home()
|
|
234
|
+
if not kimi_home.is_dir():
|
|
235
|
+
raise CliError(
|
|
236
|
+
"未找到 Kimi Code 数据目录: "
|
|
237
|
+
f"{kimi_home}。请先启动一次 Kimi Code,或设置有效的 KIMI_CODE_HOME。"
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
plugins_root = kimi_home / "plugins"
|
|
241
|
+
installed_file = plugins_root / "installed.json"
|
|
242
|
+
if installed_file.is_file():
|
|
243
|
+
try:
|
|
244
|
+
installed_data = json.loads(installed_file.read_text(encoding="utf-8"))
|
|
245
|
+
except (OSError, UnicodeError, json.JSONDecodeError) as exc:
|
|
246
|
+
raise CliError(
|
|
247
|
+
f"Kimi Code 插件注册表无法解析,已阻断写入: {installed_file}"
|
|
248
|
+
) from exc
|
|
249
|
+
else:
|
|
250
|
+
installed_data = {"version": 1, "plugins": []}
|
|
251
|
+
|
|
252
|
+
if not isinstance(installed_data, dict):
|
|
253
|
+
raise CliError(f"Kimi Code 插件注册表顶层必须是对象: {installed_file}")
|
|
254
|
+
plugins_value = installed_data.get("plugins")
|
|
255
|
+
if plugins_value is None:
|
|
256
|
+
plugins_list: list[dict[str, Any]] = []
|
|
257
|
+
installed_data["plugins"] = plugins_list
|
|
258
|
+
elif isinstance(plugins_value, list):
|
|
259
|
+
plugins_list = plugins_value
|
|
260
|
+
else:
|
|
261
|
+
raise CliError(f"Kimi Code 插件注册表 plugins 必须是数组: {installed_file}")
|
|
262
|
+
|
|
263
|
+
dest = plugins_root / "managed" / "bugx"
|
|
264
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
265
|
+
|
|
266
|
+
written: list[dict[str, Any]] = []
|
|
267
|
+
|
|
268
|
+
# 2. 写入 kimi.plugin.json 与 .kimi-plugin/plugin.json
|
|
269
|
+
manifest_obj = _build_desktop_plugin_manifest(locale=loc)
|
|
270
|
+
manifest_bytes = (
|
|
271
|
+
json.dumps(manifest_obj, indent=2, ensure_ascii=False) + "\n"
|
|
272
|
+
).encode("utf-8")
|
|
273
|
+
|
|
274
|
+
manifest_file = dest / "kimi.plugin.json"
|
|
275
|
+
manifest_file.write_bytes(manifest_bytes)
|
|
276
|
+
written.append({
|
|
277
|
+
"path": str(manifest_file),
|
|
278
|
+
"status": "created",
|
|
279
|
+
"backup": None,
|
|
280
|
+
"created": True,
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
dot_plugin_dir = dest / ".kimi-plugin"
|
|
284
|
+
dot_plugin_dir.mkdir(parents=True, exist_ok=True)
|
|
285
|
+
(dot_plugin_dir / "plugin.json").write_bytes(manifest_bytes)
|
|
286
|
+
|
|
287
|
+
# 3. 部署官方 Logo 图标 (icon.png / assets/icon.png)
|
|
288
|
+
avatar_src = _find_bugx_avatar_source()
|
|
289
|
+
if avatar_src and avatar_src.is_file():
|
|
290
|
+
avatar_bytes = avatar_src.read_bytes()
|
|
291
|
+
icon_dest = dest / "icon.png"
|
|
292
|
+
icon_dest.write_bytes(avatar_bytes)
|
|
293
|
+
written.append({
|
|
294
|
+
"path": str(icon_dest),
|
|
295
|
+
"status": "created",
|
|
296
|
+
"backup": None,
|
|
297
|
+
"created": True,
|
|
298
|
+
})
|
|
299
|
+
assets_dir = dest / "assets"
|
|
300
|
+
assets_dir.mkdir(parents=True, exist_ok=True)
|
|
301
|
+
(assets_dir / "icon.png").write_bytes(avatar_bytes)
|
|
302
|
+
|
|
303
|
+
# 4. 部署 skills/ 与 agents/
|
|
304
|
+
agents_dir = dest / "agents"
|
|
305
|
+
agents_dir.mkdir(parents=True, exist_ok=True)
|
|
306
|
+
agent_main = agents_dir / "bugx.md"
|
|
307
|
+
agent_main.write_text(_build_agent_bugx(locale=loc), encoding="utf-8")
|
|
308
|
+
written.append({
|
|
309
|
+
"path": str(agent_main),
|
|
310
|
+
"status": "created",
|
|
311
|
+
"backup": None,
|
|
312
|
+
"created": True,
|
|
313
|
+
})
|
|
314
|
+
agent_worker = agents_dir / "bugx-worker.md"
|
|
315
|
+
agent_worker.write_text(_build_agent_worker(locale=loc), encoding="utf-8")
|
|
316
|
+
written.append({
|
|
317
|
+
"path": str(agent_worker),
|
|
318
|
+
"status": "created",
|
|
319
|
+
"backup": None,
|
|
320
|
+
"created": True,
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
skills_dir = dest / "skills" / "bugx"
|
|
324
|
+
skills_dir.mkdir(parents=True, exist_ok=True)
|
|
325
|
+
skill_src = _find_bugx_skill_source(root, source)
|
|
326
|
+
if skill_src and skill_src.is_file():
|
|
327
|
+
target_skill = skills_dir / "SKILL.md"
|
|
328
|
+
target_skill.write_bytes(skill_src.read_bytes())
|
|
329
|
+
written.append({
|
|
330
|
+
"path": str(target_skill),
|
|
331
|
+
"status": "created",
|
|
332
|
+
"backup": None,
|
|
333
|
+
"created": True,
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
# 5. 直接写入并激活到当前 Kimi Code 的 installed.json(免用户点击安装)
|
|
337
|
+
now_iso = datetime.datetime.now(datetime.timezone.utc).isoformat().replace("+00:00", "Z")
|
|
338
|
+
entry = next(
|
|
339
|
+
(p for p in plugins_list if isinstance(p, dict) and p.get("id") == "bugx"),
|
|
340
|
+
None,
|
|
341
|
+
)
|
|
342
|
+
if entry is None:
|
|
343
|
+
entry = {
|
|
344
|
+
"id": "bugx",
|
|
345
|
+
"root": str(dest),
|
|
346
|
+
"source": "local-path",
|
|
347
|
+
"origin": "custom",
|
|
348
|
+
"enabled": True,
|
|
349
|
+
"installedAt": now_iso,
|
|
350
|
+
"updatedAt": now_iso,
|
|
351
|
+
"originalSource": str(dest),
|
|
352
|
+
}
|
|
353
|
+
plugins_list.append(entry)
|
|
354
|
+
else:
|
|
355
|
+
entry["root"] = str(dest)
|
|
356
|
+
entry["enabled"] = True
|
|
357
|
+
entry["updatedAt"] = now_iso
|
|
358
|
+
|
|
359
|
+
installed_file.parent.mkdir(parents=True, exist_ok=True)
|
|
360
|
+
installed_file.write_text(
|
|
361
|
+
json.dumps(installed_data, indent=2, ensure_ascii=False) + "\n",
|
|
362
|
+
encoding="utf-8",
|
|
363
|
+
)
|
|
364
|
+
written.append({
|
|
365
|
+
"path": str(installed_file),
|
|
366
|
+
"status": "updated",
|
|
367
|
+
"backup": None,
|
|
368
|
+
"created": False,
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
return {
|
|
372
|
+
"dir": str(dest),
|
|
373
|
+
"home": str(kimi_home),
|
|
374
|
+
"registry": str(installed_file),
|
|
375
|
+
"written": written,
|
|
376
|
+
"backups": [],
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def validate_install(root: Path) -> tuple[bool, str]:
|
|
381
|
+
"""Verify Kimi Code plugin registration, files, and MCP server channels."""
|
|
382
|
+
del root
|
|
383
|
+
try:
|
|
384
|
+
kimi_home = _kimi_code_home()
|
|
385
|
+
except CliError as exc:
|
|
386
|
+
return False, str(exc)
|
|
387
|
+
plugins_root = kimi_home / "plugins"
|
|
388
|
+
installed_file = plugins_root / "installed.json"
|
|
389
|
+
dest = plugins_root / "managed" / "bugx"
|
|
390
|
+
manifest = dest / "kimi.plugin.json"
|
|
391
|
+
dot_manifest = dest / ".kimi-plugin" / "plugin.json"
|
|
392
|
+
agent_main = dest / "agents" / "bugx.md"
|
|
393
|
+
agent_worker = dest / "agents" / "bugx-worker.md"
|
|
394
|
+
skill_file = dest / "skills" / "bugx" / "SKILL.md"
|
|
395
|
+
missing = [
|
|
396
|
+
label for label, path in (
|
|
397
|
+
("installed.json", installed_file),
|
|
398
|
+
("kimi.plugin.json", manifest),
|
|
399
|
+
(".kimi-plugin/plugin.json", dot_manifest),
|
|
400
|
+
("主智能体", agent_main),
|
|
401
|
+
("Worker 智能体", agent_worker),
|
|
402
|
+
("Skill", skill_file),
|
|
403
|
+
)
|
|
404
|
+
if path.is_symlink() or not path.is_file()
|
|
405
|
+
]
|
|
406
|
+
if missing:
|
|
407
|
+
return (
|
|
408
|
+
False,
|
|
409
|
+
f"Kimi Code 插件不完整({dest} 缺少 {'、'.join(missing)});"
|
|
410
|
+
"请运行 `bugx install --agent kimi`",
|
|
411
|
+
)
|
|
412
|
+
try:
|
|
413
|
+
installed_data = json.loads(installed_file.read_text(encoding="utf-8"))
|
|
414
|
+
except (OSError, UnicodeError, json.JSONDecodeError) as exc:
|
|
415
|
+
return False, f"Kimi Code installed.json 无法解析({installed_file}):{exc}"
|
|
416
|
+
plugins_list = installed_data.get("plugins") if isinstance(installed_data, dict) else None
|
|
417
|
+
entry = (
|
|
418
|
+
next((p for p in plugins_list if isinstance(p, dict) and p.get("id") == "bugx"), None)
|
|
419
|
+
if isinstance(plugins_list, list) else None
|
|
420
|
+
)
|
|
421
|
+
if not entry or not entry.get("enabled"):
|
|
422
|
+
return False, f"Kimi Code installed.json 未启用 bugx 插件({installed_file});请运行 `bugx install --agent kimi`"
|
|
423
|
+
try:
|
|
424
|
+
manifest_data = json.loads(manifest.read_text(encoding="utf-8"))
|
|
425
|
+
except (OSError, UnicodeError, json.JSONDecodeError) as exc:
|
|
426
|
+
return False, f"Kimi Code kimi.plugin.json 无法解析({manifest}):{exc}"
|
|
427
|
+
servers = manifest_data.get("mcpServers") if isinstance(manifest_data, dict) else None
|
|
428
|
+
if not isinstance(servers, dict):
|
|
429
|
+
return False, f"Kimi Code kimi.plugin.json 缺少 mcpServers({manifest})"
|
|
430
|
+
missing_channels = [
|
|
431
|
+
ch for ch in ("bugx-supervisor", "bugx-supervisor-worker", "bugx-docs")
|
|
432
|
+
if not isinstance(servers.get(ch), dict)
|
|
433
|
+
]
|
|
434
|
+
if missing_channels:
|
|
435
|
+
return (
|
|
436
|
+
False,
|
|
437
|
+
f"Kimi Code kimi.plugin.json 缺少 {', '.join(missing_channels)}({manifest});"
|
|
438
|
+
"请运行 `bugx install --agent kimi`",
|
|
439
|
+
)
|
|
440
|
+
return True, f"Kimi Code 插件与三通道 MCP 已就绪并启用({dest})"
|