vod-devkit 0.5.2 → 0.5.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 (38) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +53 -1
  3. package/bin/vod-devkit +72 -11
  4. package/contract/tools.schema.json +1 -1
  5. package/integrations/atomcode/host.json +8 -0
  6. package/integrations/codeartswork/host.json +8 -0
  7. package/integrations/codex-desktop/host.json +8 -0
  8. package/integrations/workbuddy/host.json +8 -0
  9. package/package.json +3 -1
  10. package/plugins/vod-devkit/.codex-plugin/plugin.json +1 -1
  11. package/plugins/vod-devkit/build-info.json +3 -3
  12. package/plugins/vod-devkit/vod_mcp/__init__.py +1 -1
  13. package/plugins/vod-devkit/vod_mcp/detect_framework.py +160 -0
  14. package/plugins/vod-devkit/vod_mcp/diagnose.py +102 -0
  15. package/plugins/vod-devkit/vod_mcp/host_adapters/__init__.py +7 -1
  16. package/plugins/vod-devkit/vod_mcp/host_adapters/atomcode.py +53 -0
  17. package/plugins/vod-devkit/vod_mcp/host_adapters/codeartswork.py +53 -0
  18. package/plugins/vod-devkit/vod_mcp/host_adapters/codex.py +11 -2
  19. package/plugins/vod-devkit/vod_mcp/host_adapters/codex_desktop.py +153 -0
  20. package/plugins/vod-devkit/vod_mcp/host_adapters/hermes.py +52 -7
  21. package/plugins/vod-devkit/vod_mcp/host_adapters/workbuddy.py +47 -0
  22. package/vod_mcp/__init__.py +1 -1
  23. package/vod_mcp/detect_framework.py +160 -0
  24. package/vod_mcp/diagnose.py +102 -0
  25. package/vod_mcp/host_adapters/__init__.py +7 -1
  26. package/vod_mcp/host_adapters/__pycache__/__init__.cpython-314.pyc +0 -0
  27. package/vod_mcp/host_adapters/__pycache__/atomcode.cpython-314.pyc +0 -0
  28. package/vod_mcp/host_adapters/__pycache__/codeartswork.cpython-314.pyc +0 -0
  29. package/vod_mcp/host_adapters/__pycache__/codex.cpython-314.pyc +0 -0
  30. package/vod_mcp/host_adapters/__pycache__/codex_desktop.cpython-314.pyc +0 -0
  31. package/vod_mcp/host_adapters/__pycache__/hermes.cpython-314.pyc +0 -0
  32. package/vod_mcp/host_adapters/__pycache__/workbuddy.cpython-314.pyc +0 -0
  33. package/vod_mcp/host_adapters/atomcode.py +53 -0
  34. package/vod_mcp/host_adapters/codeartswork.py +53 -0
  35. package/vod_mcp/host_adapters/codex.py +11 -2
  36. package/vod_mcp/host_adapters/codex_desktop.py +153 -0
  37. package/vod_mcp/host_adapters/hermes.py +52 -7
  38. package/vod_mcp/host_adapters/workbuddy.py +47 -0
@@ -0,0 +1,102 @@
1
+ """诊断分层与错误解释(doctor 报告 + `explain` 子命令共用一张表)。
2
+
3
+ 动机(对表 huaweicloud-devkit 的 doctor-report / explain-error):我们原来的
4
+ doctor 是一条条 FAIL 平铺打印,"哪里坏了"和"下一步做什么"全靠读文案猜;
5
+ 运维在现场只会记住一句话——"doctor 报错了"。这里把**分类**和**动作**外置成数据:
6
+
7
+ - 每条检查/错误按关键词归到一个层(环境/载荷/配置/技能/网络/插件),
8
+ 输出时按层分组,一眼看出是"机器环境问题"还是"我们自己的安装问题";
9
+ - 同一张表提供 explain():给错误码或错误片段,返回 层 / 原因 / 动作。
10
+
11
+ 纪律:
12
+ - 表只描述"已知失败形态",不猜未知错误(未知就如实报"未收录"并给出排查入口)。
13
+ - 归层只按关键词匹配(确定性),不做语义推断——误归层会把运维带偏。
14
+ """
15
+ import fnmatch
16
+ import re
17
+
18
+ LAYERS = ["环境", "载荷", "配置", "技能", "网络", "插件"]
19
+
20
+ # (关键词/正则, 层, 原因, 动作)
21
+ RULES = [
22
+ (r"无 install-manifest|未 install",
23
+ "环境", "还没装(或 manifest 被删)", "运行 install --target <宿主>"),
24
+ (r"commitSHA 不一致|commitSha",
25
+ "载荷", "安装记录与当前包不是同一份构建(升版后未重装)", "重跑 install"),
26
+ (r"载荷目录缺失|载荷被改动|载荷残留",
27
+ "载荷", "MCP 入口指向的副本不在/被改", "重跑 install 重建副本"),
28
+ (r"MCP 配置文件缺失|mcpConfig",
29
+ "配置", "宿主配置文件被删或挪了位置", "重跑 install --target <宿主>"),
30
+ (r"未列出 vod-devkit|mcp list",
31
+ "配置", "宿主没读到我们的 MCP 条目", "检查宿主配置文件里的 mcp 段后重装"),
32
+ (r"skills 目录缺失|技能文件缺失|技能文件漂移|技能原生副本缺失|技能拷贝件",
33
+ "技能", "技能副本缺失或与安装指纹不符", "重跑 install 恢复"),
34
+ (r"路由插件副本落后|vod-feedback-router",
35
+ "插件", "仓内话术已更新但装机副本是旧的", "重跑 install --target hermes"),
36
+ (r"AGENTS\.md 仍含旧一代注入|vod-submit-one-liner",
37
+ "插件", "旧注入教模型跳过征询(红线失效)", "重跑 install --target codex 自动清理"),
38
+ (r"远程面|远程 MCP|探活|不可达|401",
39
+ "网络", "远程端点不可达或工具面不符", "检查网络/端点版本;设 VOD_MCP_TOKEN 再验"),
40
+ (r"key 无效|401 拒绝|指纹",
41
+ "网络", "引擎拒绝了 key", "核对/续期 key,或移除 key 走匿名档"),
42
+ (r"引擎不可达|ProbeError|timed out|Connection",
43
+ "网络", "引擎/网络不可达(不是 key 问题)", "查网络出口与引擎健康;离线可继续工作"),
44
+ (r"-32010|产品", "配置", "缺产品归属,拒绝提交", "先问用户是哪个产品,再带 product 提交"),
45
+ (r"python|node|版本", "环境", "运行时版本不满足", "按 README 的版本要求升级"),
46
+ ]
47
+
48
+ _EXPLAIN_EXTRA = {
49
+ "-32010": ("配置",
50
+ "缺少产品归属(用户没说、也追问不到),服务端拒绝写引擎",
51
+ "先用 vod_search_products 给候选问用户;用户说不清楚就不提交"),
52
+ "-32011": ("配置", "产品不在名录里", "按名录候选再确认一次;仍对不上则不提交"),
53
+ }
54
+
55
+
56
+ def classify(message: str) -> tuple:
57
+ """把一条失败/警告文案归到 (层, 原因, 动作)。未收录 → ("未分类", "", "")。"""
58
+ for pat, layer, cause, action in RULES:
59
+ if re.search(pat, message):
60
+ return layer, cause, action
61
+ return "未分类", "", ""
62
+
63
+
64
+ def explain(text: str) -> dict:
65
+ """给错误码或错误片段,返回 {layer, cause, action, known}。"""
66
+ for code, (layer, cause, action) in _EXPLAIN_EXTRA.items():
67
+ if code in text:
68
+ return {"layer": layer, "cause": cause, "action": action, "known": True}
69
+ layer, cause, action = classify(text)
70
+ return {"layer": layer, "cause": cause, "action": action,
71
+ "known": layer != "未分类"}
72
+
73
+
74
+ def group(problems: list) -> dict:
75
+ """按层分组(保持 LAYERS 顺序,未分类排最后)。"""
76
+ buckets = {l: [] for l in LAYERS}
77
+ buckets["未分类"] = []
78
+ for msg in problems:
79
+ layer, cause, action = classify(msg)
80
+ buckets[layer].append((msg, cause, action))
81
+ return {k: v for k, v in buckets.items() if v}
82
+
83
+
84
+ def render_problems(problems: list) -> str:
85
+ """把失败清单渲染成分层报告(供 doctor 输出)。"""
86
+ if not problems:
87
+ return ""
88
+ out = []
89
+ for layer, items in group(problems).items():
90
+ out.append(f"[{layer}]")
91
+ for msg, cause, action in items:
92
+ out.append(f"FAIL: {msg}")
93
+ if cause:
94
+ out.append(f" 原因:{cause}")
95
+ if action:
96
+ out.append(f" 动作:{action}")
97
+ return "\n".join(out)
98
+
99
+
100
+ def matches(message: str, pattern: str) -> bool:
101
+ """给运维手输片段做粗匹配(大小写不敏感,支持 * 通配)。"""
102
+ return fnmatch.fnmatch(message.lower(), pattern.lower())
@@ -5,14 +5,20 @@
5
5
 
6
6
  REGISTRY 里的模块必须实现 protocol 的三件事:install / install_remote / skills_dir。
7
7
  """
8
- from vod_mcp.host_adapters import codearts, codex, dsh, generic, hermes, opencode
8
+ from vod_mcp.host_adapters import (atomcode, codearts, codeartswork, codex,
9
+ codex_desktop, dsh, generic, hermes, opencode,
10
+ workbuddy)
9
11
 
10
12
  REGISTRY = {
11
13
  "hermes": hermes,
12
14
  "opencode": opencode,
13
15
  "codeartsdoer": codearts,
16
+ "codeartswork": codeartswork,
14
17
  "codex": codex,
18
+ "codex-desktop": codex_desktop,
15
19
  "dsh": dsh,
20
+ "workbuddy": workbuddy,
21
+ "atomcode": atomcode,
16
22
  "generic": generic,
17
23
  }
18
24
 
@@ -0,0 +1,53 @@
1
+ """AtomCode 宿主适配(mcpServers.<name> 形态,配置根可由 ATOMCODE_HOME 覆盖)。
2
+
3
+ 形态来源:huaweicloud-devkit targets.ts atomcodeHome/atomcodeMcpConfigFile ——
4
+ `${ATOMCODE_HOME:-~/.atomcode}/mcp.json` 的 mcpServers,技能落 <home>/skills。
5
+
6
+ 刻意不装宿主 hooks.json 的 pre_tool_use 遥测 hook(上游那样做是为了自己的埋点);
7
+ 本插件不引入遥测。
8
+ """
9
+ import os
10
+ import sys
11
+ from pathlib import Path
12
+
13
+ from vod_mcp.host_adapters.base import server_env, server_entry
14
+ from vod_mcp.host_adapters.generic import merge_mcp_servers
15
+
16
+ HOST = "atomcode"
17
+ SUPPORTS_REMOTE = True
18
+
19
+ _VERB = {"created": "写入", "updated": "更新", "unchanged": "跳过(已一致)"}
20
+
21
+
22
+ def _home() -> Path:
23
+ """调用期读 env(测试/多宿主环境可重定向,禁止 import 期求值)。"""
24
+ raw = (os.environ.get("ATOMCODE_HOME") or "").strip()
25
+ return Path(raw).expanduser() if raw else Path.home() / ".atomcode"
26
+
27
+
28
+ def _spec() -> dict:
29
+ return {
30
+ "configPath": _home() / "mcp.json",
31
+ "skillsDir": _home() / "skills",
32
+ }
33
+
34
+
35
+ def skills_dir(args):
36
+ return _spec()["skillsDir"]
37
+
38
+
39
+ def install(args, packs):
40
+ spec = _spec()
41
+ entry = {"command": sys.executable, "args": [server_entry()],
42
+ "env": server_env(args, packs)}
43
+ action = merge_mcp_servers(spec["configPath"], entry)
44
+ print(f"已{_VERB[action]} AtomCode 配置:{spec['configPath']}(重启 AtomCode 会话生效)")
45
+ return spec["configPath"]
46
+
47
+
48
+ def install_remote(args, url, token):
49
+ conf = _spec()["configPath"]
50
+ entry = {"url": url, "headers": {"Authorization": f"Bearer {token}"}}
51
+ action = merge_mcp_servers(conf, entry)
52
+ print(f"已{_VERB[action]} AtomCode 远程 MCP:{conf}(token 明文,注意文件权限)")
53
+ return conf
@@ -0,0 +1,53 @@
1
+ """CodeArts Work(CodeArts Space)宿主适配。
2
+
3
+ 形态来源:huaweicloud-devkit targets.ts codeartsWorkMcpSettingsFile + agents/codearts-work.ts:
4
+ - 只有用户级配置;平台迁移后新址 `~/.codearts/mcp/mcp_settings.json`,旧址
5
+ `~/.codeartswork/mcp/mcp_settings.json` 作为回退(新址目录存在就用新址)。
6
+ - 条目是 `mcp.<name> = {command: [exe, ...], environment: {...}}`——注意环境键名
7
+ 是 `environment`(与 opencode 的 `environment` 同名、与 mcpServers 的 `env` 不同)。
8
+ - 技能落 `~/.codeartswork/skills`。
9
+ """
10
+ import sys
11
+ from pathlib import Path
12
+
13
+ from vod_mcp import hosts as host_specs
14
+ from vod_mcp.host_adapters.base import merge_json_mcp, server_env, server_entry
15
+
16
+ HOST = "codeartswork"
17
+ SUPPORTS_REMOTE = True
18
+
19
+ _VERB = {"created": "写入", "updated": "更新", "unchanged": "跳过(已一致)"}
20
+
21
+
22
+ def _spec() -> dict:
23
+ return host_specs.load(HOST)
24
+
25
+
26
+ def _config_path() -> Path:
27
+ new_dir = Path.home() / ".codearts" / "mcp"
28
+ if new_dir.is_dir():
29
+ return new_dir / "mcp_settings.json"
30
+ return Path(_spec()["configPath"])
31
+
32
+
33
+ def skills_dir(args):
34
+ d = _spec().get("skillsDir")
35
+ return Path(d) if d else None
36
+
37
+
38
+ def install(args, packs):
39
+ conf = _config_path()
40
+ entry = {"command": [sys.executable, server_entry()],
41
+ "environment": server_env(args, packs)}
42
+ action = merge_json_mcp(conf, entry, section="mcp")
43
+ print(f"已{_VERB[action]} CodeArts Work 配置:{conf}(重启 CodeArts Work 会话生效)")
44
+ return conf
45
+
46
+
47
+ def install_remote(args, url, token):
48
+ conf = _config_path()
49
+ entry = {"url": url,
50
+ "environment": {"Authorization": f"Bearer {token}"}}
51
+ action = merge_json_mcp(conf, entry, section="mcp")
52
+ print(f"已{_VERB[action]} CodeArts Work 远程 MCP:{conf}(token 明文,注意文件权限)")
53
+ return conf
@@ -6,7 +6,7 @@ import sys
6
6
  from pathlib import Path
7
7
 
8
8
  from vod_mcp import hosts as host_specs
9
- from vod_mcp.host_adapters.base import ROOT
9
+ from vod_mcp.host_adapters.base import ROOT, server_env, server_entry
10
10
 
11
11
  HOST = "codex"
12
12
  SUPPORTS_REMOTE = True
@@ -170,7 +170,16 @@ def install(args, packs: str) -> Path:
170
170
  mj = json.loads(Path(mcp_jsons[0]).read_text(encoding="utf-8"))
171
171
  srv = mj.get("mcpServers", {}).get("vod-devkit")
172
172
  if srv is not None:
173
- srv.setdefault("env", {})["VOD_PACKS"] = packs
173
+ # 关键修正(2026-11-12 矩阵实锤):插件自带的 .mcp.json 写的是
174
+ # command="vod-devkit" + args=["serve"] —— 依赖 PATH 上那个全局包。
175
+ # 机器上装着旧版(实测 0.4.2)时,codex 会静默跑旧副本:配置、
176
+ # 技能都是新的,工具面却是旧的。改成绝对解释器 + 载荷副本,与其它
177
+ # 宿主同一条铁律(入口不依赖 PATH / npx 缓存)。
178
+ srv["command"] = sys.executable
179
+ srv["args"] = [server_entry()]
180
+ merged = dict(srv.get("env") or {})
181
+ merged.update(server_env(args, packs))
182
+ srv["env"] = merged
174
183
  Path(mcp_jsons[0]).write_text(
175
184
  json.dumps(mj, ensure_ascii=False, indent=2) + "\n",
176
185
  encoding="utf-8")
@@ -0,0 +1,153 @@
1
+ """Codex Desktop 宿主适配:个人市场(marketplace.json)+ 插件目录。
2
+
3
+ 形态来源:huaweicloud-devkit src/targets.ts(codexDesktopPluginsDir/codexMarketplacePath)
4
+ 与 agents/codex-desktop.ts:
5
+ - 插件目录 `~/plugins/<name>`,内含 `.mcp.json`(mcpServers)与
6
+ `.codex-plugin/plugin.json`(插件清单);技能在插件目录的 skills/ 下。
7
+ - Codex Desktop 通过 `~/.agents/plugins/marketplace.json` 发现插件:
8
+ `plugins[]` 里登记 `{name, source: {source: "local", path: "./plugins/<name>"}}`。
9
+
10
+ 纪律:
11
+ - marketplace.json 是共享文件:只摘/加自己的那一条,其它插件原样保留;首改落 .bak。
12
+ - 卸载 = 摘条目 + 删插件目录;不碰 `~/.agents/skills`、`~/.agents/commands` 等原生目录。
13
+ - 本机未装该宿主:形态按对表实现,doctor 标「未真机验证」。
14
+ """
15
+ import json
16
+ import shutil
17
+ import sys
18
+ from pathlib import Path
19
+
20
+ from vod_mcp import hosts as host_specs
21
+ from vod_mcp.host_adapters.base import server_env, server_entry
22
+
23
+ HOST = "codex-desktop"
24
+ SUPPORTS_REMOTE = True
25
+ NAME = "vod-devkit"
26
+
27
+
28
+ def _version() -> str:
29
+ try:
30
+ from vod_mcp import __version__
31
+ return str(__version__)
32
+ except Exception:
33
+ return "0.0.0"
34
+
35
+
36
+ def _spec() -> dict:
37
+ return host_specs.load(HOST)
38
+
39
+
40
+ def plugin_dir() -> Path:
41
+ return Path(_spec()["skillsDir"]).parent
42
+
43
+
44
+ def marketplace_path() -> Path:
45
+ return Path(_spec()["configPath"])
46
+
47
+
48
+ def _read_json(path: Path) -> dict:
49
+ if not path.exists():
50
+ return {}
51
+ raw = path.read_text(encoding="utf-8")
52
+ if not raw.strip():
53
+ return {}
54
+ try:
55
+ parsed = json.loads(raw)
56
+ except json.JSONDecodeError as e:
57
+ raise RuntimeError(f"{path} 不是合法 JSON({e.msg}),拒绝改动") from e
58
+ if not isinstance(parsed, dict):
59
+ raise RuntimeError(f"{path} 顶层不是对象,拒绝改动")
60
+ return parsed
61
+
62
+
63
+ def _write_json(path: Path, data: dict) -> None:
64
+ if path.exists():
65
+ shutil.copyfile(path, str(path) + ".bak")
66
+ path.parent.mkdir(parents=True, exist_ok=True)
67
+ path.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
68
+
69
+
70
+ def skills_dir(args):
71
+ return Path(_spec()["skillsDir"])
72
+
73
+
74
+ def _write_mcp_entry(entry: dict) -> Path:
75
+ pdir = plugin_dir()
76
+ pdir.mkdir(parents=True, exist_ok=True)
77
+ mcp_file = pdir / ".mcp.json"
78
+ mcp = _read_json(mcp_file)
79
+ servers = mcp.get("mcpServers")
80
+ if not isinstance(servers, dict):
81
+ servers = {}
82
+ servers[NAME] = entry
83
+ mcp["mcpServers"] = servers
84
+ _write_json(mcp_file, mcp)
85
+ return mcp_file
86
+
87
+
88
+ def _register_plugin(pdir: Path) -> None:
89
+ manifest = pdir / ".codex-plugin" / "plugin.json"
90
+ manifest.parent.mkdir(parents=True, exist_ok=True)
91
+ manifest.write_text(json.dumps({
92
+ "name": NAME, "version": _version(),
93
+ "description": "VOD 用户声音采集插件(MCP + 技能)",
94
+ "skills": ["skills"],
95
+ }, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
96
+
97
+ mp_path = marketplace_path()
98
+ mp = _read_json(mp_path)
99
+ if not mp.get("name"):
100
+ mp["name"] = "personal"
101
+ plugins = mp.get("plugins")
102
+ if not isinstance(plugins, list):
103
+ plugins = []
104
+ record = {"name": NAME, "source": {"source": "local", "path": f"./plugins/{NAME}"}}
105
+ replaced = False
106
+ for i, p in enumerate(plugins):
107
+ if isinstance(p, dict) and p.get("name") == NAME:
108
+ plugins[i] = record
109
+ replaced = True
110
+ break
111
+ if not replaced:
112
+ plugins.append(record)
113
+ mp["plugins"] = plugins
114
+ _write_json(mp_path, mp)
115
+ print(f"已写入 Codex Desktop 插件目录:{pdir}")
116
+ print(f"已在个人市场登记({('更新' if replaced else '新增')}):{mp_path}(重启 Codex Desktop 生效)")
117
+
118
+
119
+ def install(args, packs):
120
+ pdir = plugin_dir()
121
+ _write_mcp_entry({"command": sys.executable, "args": [server_entry()],
122
+ "env": server_env(args, packs)})
123
+ _register_plugin(pdir)
124
+ return marketplace_path()
125
+
126
+
127
+ def install_remote(args, url, token):
128
+ pdir = plugin_dir()
129
+ mcp_file = _write_mcp_entry({"url": url,
130
+ "headers": {"Authorization": f"Bearer {token}"}})
131
+ _register_plugin(pdir)
132
+ print(f"已写入 Codex Desktop 远程 MCP:{mcp_file}(token 明文,注意文件权限)")
133
+ return mcp_file
134
+
135
+
136
+ def uninstall() -> None:
137
+ """摘市场条目 + 删插件目录(只动自己的,不删宿主原生目录)。"""
138
+ mp_path = marketplace_path()
139
+ if mp_path.exists():
140
+ try:
141
+ mp = _read_json(mp_path)
142
+ except RuntimeError as e:
143
+ print(f"skip({e})")
144
+ return
145
+ plugins = [p for p in (mp.get("plugins") or [])
146
+ if not (isinstance(p, dict) and p.get("name") == NAME)]
147
+ mp["plugins"] = plugins
148
+ _write_json(mp_path, mp)
149
+ print(f"removed marketplace entry: {mp_path}")
150
+ pdir = plugin_dir()
151
+ if pdir.exists():
152
+ shutil.rmtree(pdir)
153
+ print("removed:", pdir)
@@ -4,6 +4,7 @@
4
4
  路径字面量);新增 Hermes 特定逻辑只改本模块。
5
5
  """
6
6
  import json
7
+ import shutil
7
8
  import subprocess
8
9
  import sys
9
10
  from pathlib import Path
@@ -21,6 +22,49 @@ def skills_dir(args):
21
22
  return Path(_SPEC["skillsDir"])
22
23
 
23
24
 
25
+ PLUGIN_NAME = "vod-feedback-router"
26
+
27
+
28
+ def _enabled_plugins() -> list:
29
+ """读 hermes 配置里的 plugins.enabled(CLI 输出是 "- name" 行)。"""
30
+ r = subprocess.run(["hermes", "config", "get", "plugins.enabled"],
31
+ capture_output=True, text=True, timeout=60)
32
+ if r.returncode != 0:
33
+ return []
34
+ out = []
35
+ for line in (r.stdout or "").splitlines():
36
+ line = line.strip()
37
+ if line.startswith("- "):
38
+ out.append(line[2:].strip())
39
+ elif line.startswith("-"):
40
+ out.append(line[1:].strip())
41
+ return [x for x in out if x]
42
+
43
+
44
+ def enable_plugin(name: str = PLUGIN_NAME) -> str:
45
+ """把路由插件加进 plugins.enabled(幂等)。返回 created / unchanged / skipped。
46
+
47
+ 只追加一个名字:读现有名单 → 追加 → `hermes config set plugins.enabled '[...]'`。
48
+ 不整文件改 config.yaml(用户可能手改过格式/注释),失败只提示不动。
49
+ """
50
+ import json as _json
51
+ if not shutil.which("hermes"):
52
+ print("提示:未找到 hermes CLI,路由插件需手动在 plugins.enabled 中加入 "
53
+ f"{name} 后生效")
54
+ return "skipped"
55
+ cur = _enabled_plugins()
56
+ if name in cur:
57
+ return "unchanged"
58
+ merged = cur + [name]
59
+ r = subprocess.run(["hermes", "config", "set", "plugins.enabled",
60
+ _json.dumps(merged)], capture_output=True, text=True, timeout=60)
61
+ if r.returncode != 0:
62
+ print("提示:自动启用路由插件失败(" + (r.stderr or r.stdout).strip()[:120]
63
+ + ");请手动把 " + name + " 加入 plugins.enabled")
64
+ return "skipped"
65
+ return "created"
66
+
67
+
24
68
  def install(args, packs: str) -> Path:
25
69
  """Hermes:官方途径 hermes mcp add(config.yaml mcp_servers)。"""
26
70
  conf = _MCP_DIR / "vod-devkit.json"
@@ -37,16 +81,17 @@ def install(args, packs: str) -> Path:
37
81
  *["--env"] + env_args, "--args", server_entry()],
38
82
  input="y\ny\n", capture_output=True, text=True)
39
83
  # D-hook-1:强制评估路由插件(pre_llm_call 确定性意图路由,业界 forced-eval 模式)
40
- import shutil as _sh
41
84
  plug_src = ROOT / "hermes-plugin" / "vod-feedback-router"
42
- plug_dst = Path.home() / ".hermes" / "plugins" / "vod-feedback-router"
85
+ plug_dst = Path.home() / ".hermes" / "plugins" / PLUGIN_NAME
43
86
  if plug_src.is_dir():
44
87
  if plug_dst.exists():
45
- _sh.rmtree(plug_dst)
46
- _sh.copytree(plug_src, plug_dst)
47
- print("已安装 vod-feedback-router 路由插件(~/.hermes/plugins/);"
48
- "需在 plugins.enabled 加入该名单后生效"
49
- "(hermes config set plugins.enabled ...,重启会话生效)")
88
+ shutil.rmtree(plug_dst)
89
+ shutil.copytree(plug_src, plug_dst)
90
+ state = enable_plugin()
91
+ verb = {"created": "已自动加入 plugins.enabled",
92
+ "unchanged": "已在 plugins.enabled 中",
93
+ "skipped": "未自动启用(见上方提示)"}[state]
94
+ print(f"已安装 {PLUGIN_NAME} 路由插件(~/.hermes/plugins/,{verb};重启会话生效)")
50
95
  if r.returncode == 0:
51
96
  print("已注册 Hermes MCP(hermes mcp list 可见;重启会话生效)")
52
97
  else:
@@ -0,0 +1,47 @@
1
+ """WorkBuddy 宿主适配(mcpServers.<name> 形态)。
2
+
3
+ 形态来源:huaweicloud-devkit targets.ts / agents/workbuddy.ts —— 用户级
4
+ `~/.workbuddy/mcp.json` 的 mcpServers 里一条,技能落 `~/.workbuddy/skills`。
5
+
6
+ 纪律:
7
+ - 只写 mcpServers.vod-devkit 一个键,宿主其它 server/用户键原样保留,首改落 .bak。
8
+ - 配置文件不是合法 JSON → 报错退出、字节不动(宁可不装不可装错)。
9
+ - 本机未装该宿主:配置形态按对表实现,doctor 会标「未真机验证」。
10
+ """
11
+ import sys
12
+ from pathlib import Path
13
+
14
+ from vod_mcp import hosts as host_specs
15
+ from vod_mcp.host_adapters.base import server_env, server_entry
16
+ from vod_mcp.host_adapters.generic import merge_mcp_servers
17
+
18
+ HOST = "workbuddy"
19
+ SUPPORTS_REMOTE = True
20
+
21
+ _VERB = {"created": "写入", "updated": "更新", "unchanged": "跳过(已一致)"}
22
+
23
+
24
+ def _spec() -> dict:
25
+ return host_specs.load(HOST)
26
+
27
+
28
+ def skills_dir(args):
29
+ d = _spec().get("skillsDir")
30
+ return Path(d) if d else None
31
+
32
+
33
+ def install(args, packs):
34
+ conf = Path(_spec()["configPath"])
35
+ entry = {"command": sys.executable, "args": [server_entry()],
36
+ "env": server_env(args, packs)}
37
+ action = merge_mcp_servers(conf, entry)
38
+ print(f"已{_VERB[action]} WorkBuddy 配置:{conf}(重启 WorkBuddy 会话生效)")
39
+ return conf
40
+
41
+
42
+ def install_remote(args, url, token):
43
+ conf = Path(_spec()["configPath"])
44
+ entry = {"url": url, "headers": {"Authorization": f"Bearer {token}"}}
45
+ action = merge_mcp_servers(conf, entry)
46
+ print(f"已{_VERB[action]} WorkBuddy 远程 MCP:{conf}(token 明文,注意文件权限)")
47
+ return conf