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.
- package/CHANGELOG.md +14 -0
- package/README.md +53 -1
- package/bin/vod-devkit +72 -11
- package/contract/tools.schema.json +1 -1
- package/integrations/atomcode/host.json +8 -0
- package/integrations/codeartswork/host.json +8 -0
- package/integrations/codex-desktop/host.json +8 -0
- package/integrations/workbuddy/host.json +8 -0
- package/package.json +3 -1
- package/plugins/vod-devkit/.codex-plugin/plugin.json +1 -1
- package/plugins/vod-devkit/build-info.json +3 -3
- package/plugins/vod-devkit/vod_mcp/__init__.py +1 -1
- package/plugins/vod-devkit/vod_mcp/detect_framework.py +160 -0
- package/plugins/vod-devkit/vod_mcp/diagnose.py +102 -0
- package/plugins/vod-devkit/vod_mcp/host_adapters/__init__.py +7 -1
- package/plugins/vod-devkit/vod_mcp/host_adapters/atomcode.py +53 -0
- package/plugins/vod-devkit/vod_mcp/host_adapters/codeartswork.py +53 -0
- package/plugins/vod-devkit/vod_mcp/host_adapters/codex.py +11 -2
- package/plugins/vod-devkit/vod_mcp/host_adapters/codex_desktop.py +153 -0
- package/plugins/vod-devkit/vod_mcp/host_adapters/hermes.py +52 -7
- package/plugins/vod-devkit/vod_mcp/host_adapters/workbuddy.py +47 -0
- package/vod_mcp/__init__.py +1 -1
- package/vod_mcp/detect_framework.py +160 -0
- package/vod_mcp/diagnose.py +102 -0
- package/vod_mcp/host_adapters/__init__.py +7 -1
- package/vod_mcp/host_adapters/__pycache__/__init__.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/atomcode.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/codeartswork.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/codex.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/codex_desktop.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/hermes.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/workbuddy.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/atomcode.py +53 -0
- package/vod_mcp/host_adapters/codeartswork.py +53 -0
- package/vod_mcp/host_adapters/codex.py +11 -2
- package/vod_mcp/host_adapters/codex_desktop.py +153 -0
- package/vod_mcp/host_adapters/hermes.py +52 -7
- package/vod_mcp/host_adapters/workbuddy.py +47 -0
|
@@ -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
|
-
|
|
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" /
|
|
85
|
+
plug_dst = Path.home() / ".hermes" / "plugins" / PLUGIN_NAME
|
|
43
86
|
if plug_src.is_dir():
|
|
44
87
|
if plug_dst.exists():
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
package/vod_mcp/__init__.py
CHANGED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""只读项目识别:语言构成 + 框架/构建工具线索。
|
|
2
|
+
|
|
3
|
+
对标 huaweicloud-devkit 的 detect-framework*(513 行):它做的推论比我们多
|
|
4
|
+
(框架 → 推荐能力),我们只需要"这是哪个语言/框架的项目"给采集端补上下文,
|
|
5
|
+
所以刻意只做**确定性证据**:
|
|
6
|
+
|
|
7
|
+
- 语言:按扩展名统计文件数(跳过 vendor 目录 / node_modules / .git / 大二进制),
|
|
8
|
+
取前 N 个;不做"猜测比例"。
|
|
9
|
+
- 框架/构建:只认标记文件与清单里的显式依赖(package.json 的 dependencies、
|
|
10
|
+
requirements.txt、pyproject.toml、pom.xml、go.mod、Cargo.toml、build.gradle),
|
|
11
|
+
不做字符串模糊匹配——误报比不报更糟(会把运维带偏)。
|
|
12
|
+
|
|
13
|
+
只读:本模块不写任何文件、不发网络请求。
|
|
14
|
+
"""
|
|
15
|
+
import json
|
|
16
|
+
import os
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
SKIP_DIRS = {".git", "node_modules", "vendor", "dist", "build", ".venv", "venv",
|
|
20
|
+
"__pycache__", ".mypy_cache", ".pytest_cache", "target", ".idea"}
|
|
21
|
+
MAX_FILES = 20000 # 扫描上限:大仓不做全量遍历(41s 索引卡死过 UI)
|
|
22
|
+
MAX_DEPTH = 12
|
|
23
|
+
|
|
24
|
+
LANG_EXT = {
|
|
25
|
+
".py": "Python", ".js": "JavaScript", ".mjs": "JavaScript", ".cjs": "JavaScript",
|
|
26
|
+
".ts": "TypeScript", ".tsx": "TypeScript", ".jsx": "JavaScript",
|
|
27
|
+
".java": "Java", ".kt": "Kotlin", ".go": "Go", ".rs": "Rust",
|
|
28
|
+
".rb": "Ruby", ".php": "PHP", ".cs": "C#", ".c": "C", ".cc": "C++",
|
|
29
|
+
".cpp": "C++", ".h": "C/C++ header", ".swift": "Swift", ".scala": "Scala",
|
|
30
|
+
".sh": "Shell", ".sql": "SQL", ".vue": "Vue", ".md": "Markdown",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# 标记文件 → (种类, 名称)
|
|
34
|
+
MARKERS = {
|
|
35
|
+
"package.json": ("node", "npm/node"),
|
|
36
|
+
"pnpm-lock.yaml": ("node", "pnpm"),
|
|
37
|
+
"yarn.lock": ("node", "yarn"),
|
|
38
|
+
"requirements.txt": ("python", "pip"),
|
|
39
|
+
"pyproject.toml": ("python", "pyproject"),
|
|
40
|
+
"setup.py": ("python", "setuptools"),
|
|
41
|
+
"Pipfile": ("python", "pipenv"),
|
|
42
|
+
"pom.xml": ("java", "Maven"),
|
|
43
|
+
"build.gradle": ("java", "Gradle"),
|
|
44
|
+
"build.gradle.kts": ("java", "Gradle"),
|
|
45
|
+
"go.mod": ("go", "Go modules"),
|
|
46
|
+
"Cargo.toml": ("rust", "Cargo"),
|
|
47
|
+
"Gemfile": ("ruby", "Bundler"),
|
|
48
|
+
"composer.json": ("php", "Composer"),
|
|
49
|
+
"Dockerfile": ("infra", "Docker"),
|
|
50
|
+
"docker-compose.yml": ("infra", "Docker Compose"),
|
|
51
|
+
"Makefile": ("infra", "Make"),
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
# 依赖名 → 框架名(只认清单里的显式依赖)
|
|
55
|
+
JS_FRAMEWORKS = {
|
|
56
|
+
"react": "React", "vue": "Vue", "next": "Next.js", "nuxt": "Nuxt",
|
|
57
|
+
"express": "Express", "fastify": "Fastify", "koa": "Koa", "@nestjs/core": "NestJS",
|
|
58
|
+
"vite": "Vite", "webpack": "Webpack", "electron": "Electron",
|
|
59
|
+
}
|
|
60
|
+
PY_FRAMEWORKS = {
|
|
61
|
+
"django": "Django", "flask": "Flask", "fastapi": "FastAPI",
|
|
62
|
+
"torch": "PyTorch", "tensorflow": "TensorFlow", "pytest": "pytest",
|
|
63
|
+
"sqlalchemy": "SQLAlchemy", "pydantic": "Pydantic",
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _iter_files(root: Path):
|
|
68
|
+
seen = 0
|
|
69
|
+
root_s = str(root)
|
|
70
|
+
for dirpath, dirnames, filenames in os.walk(root_s):
|
|
71
|
+
dirnames[:] = [d for d in dirnames if d not in SKIP_DIRS]
|
|
72
|
+
rel = os.path.relpath(dirpath, root_s)
|
|
73
|
+
depth = 0 if rel == "." else rel.count(os.sep) + 1
|
|
74
|
+
if depth > MAX_DEPTH:
|
|
75
|
+
dirnames[:] = []
|
|
76
|
+
continue
|
|
77
|
+
for name in filenames:
|
|
78
|
+
yield Path(dirpath) / name
|
|
79
|
+
seen += 1
|
|
80
|
+
if seen >= MAX_FILES:
|
|
81
|
+
return
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _read_json(path: Path) -> dict:
|
|
85
|
+
try:
|
|
86
|
+
return json.loads(path.read_text(encoding="utf-8", errors="replace"))
|
|
87
|
+
except Exception:
|
|
88
|
+
return {}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _js_frameworks(path: Path) -> list:
|
|
92
|
+
data = _read_json(path)
|
|
93
|
+
names = set()
|
|
94
|
+
for section in ("dependencies", "devDependencies", "peerDependencies"):
|
|
95
|
+
for dep in (data.get(section) or {}):
|
|
96
|
+
if dep in JS_FRAMEWORKS:
|
|
97
|
+
names.add(JS_FRAMEWORKS[dep])
|
|
98
|
+
return sorted(names)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _py_frameworks(root: Path) -> list:
|
|
102
|
+
names = set()
|
|
103
|
+
req = root / "requirements.txt"
|
|
104
|
+
if req.exists():
|
|
105
|
+
for line in req.read_text(encoding="utf-8", errors="replace").splitlines():
|
|
106
|
+
token = line.strip().split("==")[0].split(">=")[0].split("[")[0].lower()
|
|
107
|
+
if token in PY_FRAMEWORKS:
|
|
108
|
+
names.add(PY_FRAMEWORKS[token])
|
|
109
|
+
pyproj = root / "pyproject.toml"
|
|
110
|
+
if pyproj.exists():
|
|
111
|
+
text = pyproj.read_text(encoding="utf-8", errors="replace").lower()
|
|
112
|
+
for dep, label in PY_FRAMEWORKS.items():
|
|
113
|
+
if f'"{dep}"' in text or f"'{dep}'" in text:
|
|
114
|
+
names.add(label)
|
|
115
|
+
return sorted(names)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def detect(path=".") -> dict:
|
|
119
|
+
"""返回 {root, languages[{name,files,share}], markers, frameworks, truncated}。"""
|
|
120
|
+
root = Path(path).expanduser().resolve()
|
|
121
|
+
if not root.is_dir():
|
|
122
|
+
raise ValueError(f"{root} 不是目录")
|
|
123
|
+
counts = {}
|
|
124
|
+
truncated = False
|
|
125
|
+
scanned = 0
|
|
126
|
+
for f in _iter_files(root):
|
|
127
|
+
scanned += 1
|
|
128
|
+
ext = f.suffix.lower()
|
|
129
|
+
lang = LANG_EXT.get(ext)
|
|
130
|
+
if lang:
|
|
131
|
+
counts[lang] = counts.get(lang, 0) + 1
|
|
132
|
+
if scanned >= MAX_FILES:
|
|
133
|
+
truncated = True
|
|
134
|
+
break
|
|
135
|
+
total = sum(counts.values()) or 1
|
|
136
|
+
languages = [{"name": n, "files": c, "share": round(c / total, 3)}
|
|
137
|
+
for n, c in sorted(counts.items(), key=lambda x: (-x[1], x[0]))[:8]]
|
|
138
|
+
markers = []
|
|
139
|
+
for name, (kind, label) in MARKERS.items():
|
|
140
|
+
if (root / name).exists():
|
|
141
|
+
markers.append({"file": name, "kind": kind, "label": label})
|
|
142
|
+
frameworks = []
|
|
143
|
+
pkg = root / "package.json"
|
|
144
|
+
if pkg.exists():
|
|
145
|
+
frameworks += _js_frameworks(pkg)
|
|
146
|
+
frameworks += _py_frameworks(root)
|
|
147
|
+
return {"root": str(root), "scanned": scanned, "truncated": truncated,
|
|
148
|
+
"languages": languages,
|
|
149
|
+
"markers": sorted(markers, key=lambda m: m["file"]),
|
|
150
|
+
"frameworks": sorted(set(frameworks))}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def summary_line(info: dict) -> str:
|
|
154
|
+
top = "、".join(f"{l['name']} {int(l['share'] * 100)}%" for l in info["languages"][:3])
|
|
155
|
+
parts = [f"主语言 {top}"] if top else ["未识别到源码文件"]
|
|
156
|
+
if info["frameworks"]:
|
|
157
|
+
parts.append("框架 " + "、".join(info["frameworks"][:4]))
|
|
158
|
+
if info["markers"]:
|
|
159
|
+
parts.append("构建 " + "、".join(m["label"] for m in info["markers"][:3]))
|
|
160
|
+
return ";".join(parts)
|