vod-devkit 0.0.0-stage → 0.1.0
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 +13 -0
- package/LICENSE.txt +21 -0
- package/QUICKSTART.md +79 -0
- package/README.en.md +75 -0
- package/README.md +84 -2
- package/bin/vod-devkit +464 -0
- package/contract/tools.schema.json +187 -0
- package/npm/cli.js +39 -0
- package/package.json +28 -4
- package/safety/policy.json +48 -0
- package/skills/vod-core/SKILL.md +23 -0
- package/skills/vod-feedback-collect/SKILL.md +90 -0
- package/skills/vod-problem-classification-rules/SKILL.md +45 -0
- package/skills/vod-scoring-rules/SKILL.md +37 -0
- package/vod_mcp/__init__.py +11 -0
- package/vod_mcp/__pycache__/__init__.cpython-314.pyc +0 -0
- package/vod_mcp/__pycache__/packs.cpython-314.pyc +0 -0
- package/vod_mcp/__pycache__/policy.cpython-314.pyc +0 -0
- package/vod_mcp/__pycache__/provenance.cpython-314.pyc +0 -0
- package/vod_mcp/__pycache__/server.cpython-314.pyc +0 -0
- package/vod_mcp/__pycache__/tools.cpython-314.pyc +0 -0
- package/vod_mcp/packs.py +30 -0
- package/vod_mcp/policy.py +98 -0
- package/vod_mcp/provenance.py +43 -0
- package/vod_mcp/runtime.example.json +6 -0
- package/vod_mcp/runtime.json +1473 -0
- package/vod_mcp/server.py +105 -0
- package/vod_mcp/tools.py +620 -0
package/bin/vod-devkit
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""vod-devkit 安装器 CLI(骨架):install / status / doctor / verify / uninstall。
|
|
3
|
+
|
|
4
|
+
当前支持目标:hermes。install 做三件事:落 MCP 配置片段、拷 skills、
|
|
5
|
+
写 install-manifest(commitSHA 来源主键)。
|
|
6
|
+
"""
|
|
7
|
+
import argparse
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import shutil
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
import datetime
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
17
|
+
sys.path.insert(0, str(ROOT))
|
|
18
|
+
HERMES_MCP_DIR = Path.home() / ".hermes" / "mcp" # 约定:写入前打印供确认
|
|
19
|
+
HERMES_SKILLS_DIR = Path.home() / ".hermes" / "skills" / "devops" / "vod-devkit"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def git_sha(strict: bool) -> str | None:
|
|
23
|
+
dirty = bool(subprocess.run(["git", "status", "--porcelain"], cwd=ROOT,
|
|
24
|
+
capture_output=True).stdout.strip())
|
|
25
|
+
if strict and dirty:
|
|
26
|
+
print("工作区不干净,拒绝构建(构建纪律)", file=sys.stderr)
|
|
27
|
+
sys.exit(1)
|
|
28
|
+
sha = subprocess.run(["git", "rev-parse", "HEAD"], cwd=ROOT,
|
|
29
|
+
capture_output=True, text=True).stdout.strip()
|
|
30
|
+
return sha or None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _safe_remote(url: str) -> str:
|
|
34
|
+
"""凭据脱敏:oauth2:xxx@ / https://user:pass@ 一律剥离。"""
|
|
35
|
+
import re as _re
|
|
36
|
+
return _re.sub(r"(https?://)([^@/]+@)", r"\1", url)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def build_info(strict: bool = False) -> dict:
|
|
40
|
+
from vod_mcp import __version__
|
|
41
|
+
remote = subprocess.run(["git", "remote", "get-url", "origin"], cwd=ROOT,
|
|
42
|
+
capture_output=True, text=True).stdout.strip()
|
|
43
|
+
return {
|
|
44
|
+
"version": __version__,
|
|
45
|
+
"commitSha": git_sha(strict),
|
|
46
|
+
"builtAt": datetime.datetime.now().isoformat(timespec="seconds"),
|
|
47
|
+
"sourceRemote": _safe_remote(remote) if remote else None,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def write_build_info(strict: bool):
|
|
52
|
+
info = build_info(strict)
|
|
53
|
+
(ROOT / "build-info.json").write_text(
|
|
54
|
+
json.dumps(info, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
55
|
+
print("build-info.json:", json.dumps(info, ensure_ascii=False))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def manifest_path() -> Path:
|
|
59
|
+
return ROOT / "install-manifest.json"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
PRESETS = {
|
|
63
|
+
# 对外默认:开发者=反馈采集者(workflow 不进对外默认集)
|
|
64
|
+
"collect": "core,collect",
|
|
65
|
+
# 内部:运营/可信第三方全量(含分析发起)
|
|
66
|
+
"full": "core,workflow,kb,collect",
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _server_entry() -> str:
|
|
71
|
+
return str(ROOT / "vod_mcp" / "server.py")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _server_env(args, packs: str) -> dict:
|
|
75
|
+
# 无 key 不写空串(空串会让探针/严格解析器误当字面值;运行时空=未设置,
|
|
76
|
+
# 自动兜底 runtime.json java_key 或首提申请匿名令牌)
|
|
77
|
+
env = {"VOD_PACKS": packs,
|
|
78
|
+
"VOD_JAVA_API_BASE": args.java_api_base}
|
|
79
|
+
key = os.environ.get("VOD_JAVA_API_KEY", "")
|
|
80
|
+
if key:
|
|
81
|
+
env["VOD_JAVA_API_KEY"] = key
|
|
82
|
+
return env
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _install_hermes(args, packs: str) -> Path:
|
|
86
|
+
"""Hermes:官方途径 hermes mcp add(config.yaml mcp_servers)。"""
|
|
87
|
+
conf = HERMES_MCP_DIR / "vod-devkit.json"
|
|
88
|
+
conf.parent.mkdir(parents=True, exist_ok=True)
|
|
89
|
+
conf.write_text(json.dumps({
|
|
90
|
+
"name": "vod-devkit", "command": sys.executable,
|
|
91
|
+
"args": [_server_entry()], "env": _server_env(args, packs),
|
|
92
|
+
}, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
93
|
+
env_args = []
|
|
94
|
+
for k, v in _server_env(args, packs).items():
|
|
95
|
+
env_args.extend([k + "=" + v])
|
|
96
|
+
r = subprocess.run(
|
|
97
|
+
["hermes", "mcp", "add", "vod-devkit", "--command", sys.executable,
|
|
98
|
+
*["--env"] + env_args, "--args", _server_entry()],
|
|
99
|
+
input="y\ny\n", capture_output=True, text=True)
|
|
100
|
+
if r.returncode == 0:
|
|
101
|
+
print("已注册 Hermes MCP(hermes mcp list 可见;重启会话生效)")
|
|
102
|
+
else:
|
|
103
|
+
print(f"提示:hermes mcp add 未成功({r.stderr.strip()[:150]});"
|
|
104
|
+
f"可将 {conf} 内容并入 Hermes 配置")
|
|
105
|
+
return conf
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _install_opencode(args, packs: str) -> Path:
|
|
109
|
+
"""OpenCode:~/.config/opencode/opencode.json 的 mcp 段无损合并。
|
|
110
|
+
|
|
111
|
+
schema 实测要求:command=数组、enabled 必填;既有内容(provider 等)
|
|
112
|
+
原样保留(读改写,只动 mcp.vod-devkit 键)。
|
|
113
|
+
"""
|
|
114
|
+
import platform
|
|
115
|
+
base = Path.home() / (".config/opencode" if platform.system() != "Windows"
|
|
116
|
+
else "AppData/Local/opencode")
|
|
117
|
+
conf = base / "opencode.json"
|
|
118
|
+
conf.parent.mkdir(parents=True, exist_ok=True)
|
|
119
|
+
cfg = {}
|
|
120
|
+
if conf.exists():
|
|
121
|
+
try:
|
|
122
|
+
cfg = json.loads(conf.read_text(encoding="utf-8"))
|
|
123
|
+
except Exception:
|
|
124
|
+
cfg = {}
|
|
125
|
+
cfg.setdefault("mcp", {})["vod-devkit"] = {
|
|
126
|
+
"type": "local",
|
|
127
|
+
"command": [sys.executable, _server_entry()],
|
|
128
|
+
"enabled": True,
|
|
129
|
+
"environment": _server_env(args, packs),
|
|
130
|
+
}
|
|
131
|
+
conf.write_text(json.dumps(cfg, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
132
|
+
print(f"已写入 OpenCode 配置:{conf}(重启 OpenCode 会话生效)")
|
|
133
|
+
return conf
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _strip_codex_vod_blocks(text: str) -> str:
|
|
137
|
+
"""幂等剥离:按行删除 [mcp_servers.vod-devkit] 及 .env 子表整块。
|
|
138
|
+
|
|
139
|
+
不能用行内正则截断式剥离——args = ["…"] 行内的 '[' 会让正则提前断块,
|
|
140
|
+
旧 env 子表残留(实测:二次安装后 env 表×2、旧 VOD_PACKS 滞留,
|
|
141
|
+
换 preset 不生效)。按行扫描到下一个 '[' 开头的节头为止才是整块。
|
|
142
|
+
"""
|
|
143
|
+
out, skipping = [], False
|
|
144
|
+
for line in text.splitlines():
|
|
145
|
+
s = line.strip()
|
|
146
|
+
if s.startswith("[mcp_servers.vod-devkit"):
|
|
147
|
+
skipping = True
|
|
148
|
+
continue
|
|
149
|
+
if skipping and s.startswith("["):
|
|
150
|
+
skipping = False
|
|
151
|
+
if not skipping:
|
|
152
|
+
out.append(line)
|
|
153
|
+
return "\n".join(out).rstrip()
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _install_codex(args, packs: str) -> Path:
|
|
157
|
+
"""Codex:~/.codex/config.toml 的 [mcp_servers.vod-devkit] 表(幂等重写)。"""
|
|
158
|
+
conf = Path.home() / ".codex" / "config.toml"
|
|
159
|
+
conf.parent.mkdir(parents=True, exist_ok=True)
|
|
160
|
+
text = conf.read_text(encoding="utf-8") if conf.exists() else ""
|
|
161
|
+
text = _strip_codex_vod_blocks(text)
|
|
162
|
+
env = _server_env(args, packs)
|
|
163
|
+
env_lines = "\n".join(f'{k} = "{v}"' for k, v in env.items())
|
|
164
|
+
block = (f'\n[mcp_servers.vod-devkit]\n'
|
|
165
|
+
f'command = "{sys.executable}"\n'
|
|
166
|
+
f'args = ["{_server_entry()}"]\n'
|
|
167
|
+
f'\n[mcp_servers.vod-devkit.env]\n{env_lines}\n')
|
|
168
|
+
conf.write_text(text.rstrip() + "\n" + block, encoding="utf-8")
|
|
169
|
+
print(f"已写入 Codex 配置:{conf}(重启 Codex 会话生效)")
|
|
170
|
+
return conf
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
_INSTALLERS = {"hermes": _install_hermes, "opencode": _install_opencode,
|
|
174
|
+
"codex": _install_codex}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def detect_targets() -> list:
|
|
178
|
+
"""0/1/N 探测:按各家配置目录存在性判断已装宿主。"""
|
|
179
|
+
found = []
|
|
180
|
+
if shutil.which("hermes"):
|
|
181
|
+
found.append("hermes")
|
|
182
|
+
if (Path.home() / ".config/opencode").exists():
|
|
183
|
+
found.append("opencode")
|
|
184
|
+
if (Path.home() / ".codex").exists():
|
|
185
|
+
found.append("codex")
|
|
186
|
+
return found
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def cmd_install(args):
|
|
190
|
+
from vod_mcp import DEFAULT_JAVA_BASE
|
|
191
|
+
if not args.java_api_base:
|
|
192
|
+
args.java_api_base = DEFAULT_JAVA_BASE # 缺省=平台真实地址,不强制用户传
|
|
193
|
+
write_build_info(strict=False)
|
|
194
|
+
target = args.target
|
|
195
|
+
if target == "auto":
|
|
196
|
+
found = detect_targets()
|
|
197
|
+
if len(found) == 1:
|
|
198
|
+
target = found[0]
|
|
199
|
+
elif not found:
|
|
200
|
+
print("未探测到任何宿主;用 --target hermes|opencode|codex 显式指定",
|
|
201
|
+
file=sys.stderr)
|
|
202
|
+
sys.exit(2)
|
|
203
|
+
else:
|
|
204
|
+
print(f"探测到多个宿主: {found};请 --target 显式指定其一", file=sys.stderr)
|
|
205
|
+
sys.exit(2)
|
|
206
|
+
print(f"探测到宿主: {target}")
|
|
207
|
+
installer = _INSTALLERS.get(target)
|
|
208
|
+
if installer is None:
|
|
209
|
+
print(f"不支持目标: {target}(可选 hermes|opencode|codex|auto)", file=sys.stderr)
|
|
210
|
+
sys.exit(2)
|
|
211
|
+
packs = args.packs or PRESETS.get(args.preset, "")
|
|
212
|
+
# 归因绑定(T7d 统一:安装必配,与 dsh UI 加载必配同口径):--product 必填——
|
|
213
|
+
# 缺省宿主名在生态部署是错归陷阱(高校AI开发者平台 agent 底座=hermes,
|
|
214
|
+
# 不填则反馈全归 hermes)。宿主名仍是合法值(自反馈场景显式传
|
|
215
|
+
# --product hermes),但必须显式选择,不做静默默认(归因错误比没数据更糟)。
|
|
216
|
+
if not args.product:
|
|
217
|
+
print(
|
|
218
|
+
"[vod-devkit] --product 必填:产品归因是安装必配项(与 UI 嵌入注入同口径)。\n"
|
|
219
|
+
" 取值=生态看板产品名(可用 GET /external/products 查询权威名单),如:\n"
|
|
220
|
+
" --product \"高校AI开发者平台\" / --product \"GTD\" / --product \"Skills门户\"\n"
|
|
221
|
+
" 反馈关于宿主工具本身时显式传宿主名:--product hermes",
|
|
222
|
+
file=sys.stderr)
|
|
223
|
+
sys.exit(2)
|
|
224
|
+
bound_product = args.product
|
|
225
|
+
# D-key-guard-2 红线:preset(产品分发)形态下 key 禁止随包——环境变量里的
|
|
226
|
+
# key 不透传给宿主配置(客户机一律走匿名令牌自领),并当场告警
|
|
227
|
+
distribution = args.distribution
|
|
228
|
+
if distribution == "preset" and os.environ.pop("VOD_JAVA_API_KEY", None):
|
|
229
|
+
print("[vod-devkit] warn: preset 形态下 VOD_JAVA_API_KEY 已忽略且不写入宿主配置"
|
|
230
|
+
"(key 落在哪台机器哪台就是信任边界;客户机走匿名令牌)", file=sys.stderr)
|
|
231
|
+
rt = ROOT / "vod_mcp" / "runtime.json"
|
|
232
|
+
cfg = {}
|
|
233
|
+
if rt.exists():
|
|
234
|
+
try:
|
|
235
|
+
cfg = json.loads(rt.read_text(encoding="utf-8"))
|
|
236
|
+
except Exception:
|
|
237
|
+
cfg = {}
|
|
238
|
+
cfg["product"] = bound_product
|
|
239
|
+
if getattr(args, "no_local_ledger", False):
|
|
240
|
+
# D-key-guard-3④:企业数据驻留要求可关本地账本(代价 vod_list_submitted 不可用)
|
|
241
|
+
cfg["local_ledger"] = False
|
|
242
|
+
# base 同步落 runtime.json:宿主 env 透传不稳是实测坑,透传挂了静默落回
|
|
243
|
+
# 127.0.0.1:8090;文件兑底与 env 同值不构成双真源(优先级链 env>文件)
|
|
244
|
+
cfg["java_base"] = args.java_api_base
|
|
245
|
+
rt.write_text(json.dumps(cfg, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
246
|
+
|
|
247
|
+
mcp_conf = installer(args, packs)
|
|
248
|
+
|
|
249
|
+
# G1 修复:技能全量拷贝(目录型技能+平铺规则文档),按 packs 过滤
|
|
250
|
+
HERMES_SKILLS_DIR.mkdir(parents=True, exist_ok=True)
|
|
251
|
+
pack_set = set(p for p in packs.split(",") if p)
|
|
252
|
+
for entry in sorted((ROOT / "skills").iterdir()):
|
|
253
|
+
if entry.is_dir(): # vod-core / vod-feedback-collect
|
|
254
|
+
skill = entry.name
|
|
255
|
+
if skill == "vod-core" and "core" not in pack_set:
|
|
256
|
+
continue
|
|
257
|
+
if skill == "vod-feedback-collect" and "collect" not in pack_set:
|
|
258
|
+
continue
|
|
259
|
+
dst = HERMES_SKILLS_DIR / skill
|
|
260
|
+
if dst.exists():
|
|
261
|
+
shutil.rmtree(dst)
|
|
262
|
+
shutil.copytree(entry, dst)
|
|
263
|
+
# vendored 领域规则已由 vendor_rules.py 落成技能目录结构
|
|
264
|
+
|
|
265
|
+
bi = json.loads((ROOT / "build-info.json").read_text(encoding="utf-8"))
|
|
266
|
+
manifest = {
|
|
267
|
+
"product": "vod-devkit",
|
|
268
|
+
"version": bi["version"],
|
|
269
|
+
"source": {"type": "git", "remote": bi["sourceRemote"],
|
|
270
|
+
"ref": subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"],
|
|
271
|
+
cwd=ROOT, capture_output=True, text=True).stdout.strip(),
|
|
272
|
+
"commitSha": bi["commitSha"]},
|
|
273
|
+
"target": target,
|
|
274
|
+
"installedAt": datetime.datetime.now().isoformat(timespec="seconds"),
|
|
275
|
+
"preset": args.preset,
|
|
276
|
+
"distribution": getattr(args, "distribution", "devkit"),
|
|
277
|
+
"product": bound_product,
|
|
278
|
+
"packs": packs,
|
|
279
|
+
"mcpConfig": str(mcp_conf),
|
|
280
|
+
"skillsDir": str(HERMES_SKILLS_DIR),
|
|
281
|
+
}
|
|
282
|
+
manifest_path().write_text(json.dumps(manifest, ensure_ascii=False, indent=2),
|
|
283
|
+
encoding="utf-8")
|
|
284
|
+
print("installed:", json.dumps(manifest, ensure_ascii=False, indent=2))
|
|
285
|
+
missing = [k for k in ("VOD_JAVA_API_KEY",) if
|
|
286
|
+
not os.environ.get(k) and not _runtime_cfg_read().get("java_key")]
|
|
287
|
+
if missing:
|
|
288
|
+
print(f"提示:{missing} 未配置——首次提交将自动申请零字段匿名令牌(无需配置)")
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def _runtime_cfg_read() -> dict:
|
|
292
|
+
p = ROOT / "vod_mcp" / "runtime.json"
|
|
293
|
+
if p.exists():
|
|
294
|
+
try:
|
|
295
|
+
return json.loads(p.read_text(encoding="utf-8"))
|
|
296
|
+
except Exception:
|
|
297
|
+
return {}
|
|
298
|
+
return {}
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def cmd_status(_args):
|
|
303
|
+
p = manifest_path()
|
|
304
|
+
if not p.exists():
|
|
305
|
+
print("未安装(无 install-manifest)")
|
|
306
|
+
sys.exit(1)
|
|
307
|
+
print(p.read_text(encoding="utf-8"))
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def cmd_doctor(_args):
|
|
311
|
+
problems = []
|
|
312
|
+
p = manifest_path()
|
|
313
|
+
if not p.exists():
|
|
314
|
+
problems.append("无 install-manifest.json(未 install?)")
|
|
315
|
+
else:
|
|
316
|
+
mf = json.loads(p.read_text(encoding="utf-8"))
|
|
317
|
+
bi = json.loads((ROOT / "build-info.json").read_text(encoding="utf-8"))
|
|
318
|
+
if mf["source"]["commitSha"] != bi.get("commitSha"):
|
|
319
|
+
problems.append("install-manifest 与 build-info 的 commitSHA 不一致")
|
|
320
|
+
if not Path(mf["mcpConfig"]).exists():
|
|
321
|
+
problems.append("MCP 配置文件缺失")
|
|
322
|
+
if not Path(mf["skillsDir"]).exists():
|
|
323
|
+
problems.append("skills 目录缺失")
|
|
324
|
+
if problems:
|
|
325
|
+
for x in problems:
|
|
326
|
+
print("FAIL:", x)
|
|
327
|
+
sys.exit(1)
|
|
328
|
+
# key 探针(最佳努力):配置了 key 就问一次引擎,无效当场报;网络不可达只提示不 FAIL
|
|
329
|
+
#(离线环境 doctor 必须可用——网络问题不是 key 问题)
|
|
330
|
+
from vod_mcp.tools import _runtime_cfg
|
|
331
|
+
key = os.environ.get("VOD_JAVA_API_KEY") or _runtime_cfg().get("java_key")
|
|
332
|
+
if key:
|
|
333
|
+
from vod_mcp.tools import probe_key
|
|
334
|
+
chk = probe_key(key)
|
|
335
|
+
if chk["ok"] is False:
|
|
336
|
+
problems.append(f"key 无效(指纹 {chk['fingerprint']},引擎 401 拒绝)——"
|
|
337
|
+
"请核对/续期,或移除 key 走匿名档")
|
|
338
|
+
elif chk["ok"] is None:
|
|
339
|
+
print(f"warn: key 未验证(引擎不可达,指纹 {chk['fingerprint']})")
|
|
340
|
+
else:
|
|
341
|
+
print(f"key: 有效(指纹 {chk['fingerprint']})")
|
|
342
|
+
if problems:
|
|
343
|
+
for x in problems:
|
|
344
|
+
print("FAIL:", x)
|
|
345
|
+
sys.exit(1)
|
|
346
|
+
print("doctor: OK")
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def _distribution() -> str:
|
|
350
|
+
"""分发形态位(D-key-guard-3):install --distribution 写入,构建期定死。
|
|
351
|
+
devkit=开发/运维形态(自装自管);preset=产品随 agent 分发(客户机只读)。"""
|
|
352
|
+
p = manifest_path()
|
|
353
|
+
if not p.exists():
|
|
354
|
+
return "devkit"
|
|
355
|
+
try:
|
|
356
|
+
return json.loads(p.read_text(encoding="utf-8")).get("distribution", "devkit")
|
|
357
|
+
except Exception:
|
|
358
|
+
return "devkit"
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def cmd_verify(_args):
|
|
362
|
+
p = manifest_path()
|
|
363
|
+
if not p.exists():
|
|
364
|
+
print("未安装")
|
|
365
|
+
sys.exit(1)
|
|
366
|
+
sha = json.loads(p.read_text(encoding="utf-8"))["source"]["commitSha"]
|
|
367
|
+
if not sha:
|
|
368
|
+
print("manifest 无 commitSha(dev 构建无法核验)")
|
|
369
|
+
sys.exit(1)
|
|
370
|
+
if _distribution() == "preset":
|
|
371
|
+
# D-key-guard-3②:产品分发形态客户机无 git 源——只做本地完整性校验,
|
|
372
|
+
# 源端比对降级为 unchecked 不 FAIL(离线 verify 必须可用)
|
|
373
|
+
bi = json.loads((ROOT / "build-info.json").read_text(encoding="utf-8"))
|
|
374
|
+
if sha != bi.get("commitSha"):
|
|
375
|
+
print("FAIL: manifest 与 build-info commitSHA 不一致(安装产物被篡改/混装)")
|
|
376
|
+
sys.exit(1)
|
|
377
|
+
print("verify: OK(preset 本地完整性;源端比对 unchecked)")
|
|
378
|
+
return
|
|
379
|
+
r = subprocess.run(["git", "cat-file", "-e", f"{sha}^{{commit}}"],
|
|
380
|
+
cwd=ROOT, capture_output=True)
|
|
381
|
+
if r.returncode != 0:
|
|
382
|
+
subprocess.run(["git", "fetch", "origin"], cwd=ROOT)
|
|
383
|
+
r = subprocess.run(["git", "cat-file", "-e", f"{sha}^{{commit}}"],
|
|
384
|
+
cwd=ROOT, capture_output=True)
|
|
385
|
+
if r.returncode != 0:
|
|
386
|
+
print(f"FAIL: commit {sha} 不存在于 origin(被改写或非本仓产物)")
|
|
387
|
+
sys.exit(1)
|
|
388
|
+
print(f"verify: OK(commit {sha[:12]} 存在于本仓/origin)")
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def cmd_update(_args):
|
|
392
|
+
"""更新:git fetch 比较 origin/main,落后则 ff 拉取并重烧 build-info。"""
|
|
393
|
+
if _distribution() == "preset":
|
|
394
|
+
# D-key-guard-3②:产品分发形态插件版本随 agent 发版管理,客户机禁止自更新
|
|
395
|
+
#(绕过产品版本管理=未测试代码进客户现场)
|
|
396
|
+
print("产品分发形态(preset)不支持自更新:插件版本随 agent 发版管理。"
|
|
397
|
+
"如需升级请联系产品提供方发布新版本。")
|
|
398
|
+
return
|
|
399
|
+
subprocess.run(["git", "fetch", "origin", "--tags"], cwd=ROOT, capture_output=True)
|
|
400
|
+
local = subprocess.run(["git", "rev-parse", "HEAD"], cwd=ROOT,
|
|
401
|
+
capture_output=True, text=True).stdout.strip()
|
|
402
|
+
remote = subprocess.run(["git", "rev-parse", "origin/main"], cwd=ROOT,
|
|
403
|
+
capture_output=True, text=True).stdout.strip()
|
|
404
|
+
if local == remote:
|
|
405
|
+
print(f"已是最新({local[:12]})")
|
|
406
|
+
return
|
|
407
|
+
r = subprocess.run(["git", "pull", "--ff-only"], cwd=ROOT,
|
|
408
|
+
capture_output=True, text=True)
|
|
409
|
+
if r.returncode != 0:
|
|
410
|
+
print("更新失败(有本地改动阻挡 ff?):", r.stderr.strip()[:200])
|
|
411
|
+
sys.exit(1)
|
|
412
|
+
print(f"已更新 {local[:12]} → {remote[:12]}")
|
|
413
|
+
write_build_info(strict=False)
|
|
414
|
+
print("build-info 已重烧;如需重新安装执行:")
|
|
415
|
+
print(f" {sys.argv[0]} install --target hermes --preset collect --product <产品名>")
|
|
416
|
+
print(" 并重启 agent 会话")
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def cmd_uninstall(_args):
|
|
420
|
+
p = manifest_path()
|
|
421
|
+
if p.exists():
|
|
422
|
+
mf = json.loads(p.read_text(encoding="utf-8"))
|
|
423
|
+
for key in ("mcpConfig", "skillsDir"):
|
|
424
|
+
path = Path(mf[key])
|
|
425
|
+
if path.exists():
|
|
426
|
+
shutil.rmtree(path) if path.is_dir() else path.unlink()
|
|
427
|
+
print("removed:", path)
|
|
428
|
+
p.unlink()
|
|
429
|
+
print("removed:", p)
|
|
430
|
+
else:
|
|
431
|
+
print("未安装")
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
def main():
|
|
435
|
+
ap = argparse.ArgumentParser(prog="vod-devkit")
|
|
436
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
437
|
+
sp = sub.add_parser("install")
|
|
438
|
+
sp.add_argument("--target", default="auto", help="hermes|opencode|codex|auto(默认探测)")
|
|
439
|
+
sp.add_argument("--preset", default="collect", choices=list(PRESETS),
|
|
440
|
+
help="collect=对外默认(采集者);full=内部全量")
|
|
441
|
+
sp.add_argument("--api-base", default="http://127.0.0.1:8000")
|
|
442
|
+
sp.add_argument("--java-api-base", default=None,
|
|
443
|
+
help="VOD 平台地址(缺省=https://vod-dev.topxtopx.com,勿用回环默认)")
|
|
444
|
+
sp.add_argument("--packs", default="", help="显式覆盖 preset(逗号分隔)")
|
|
445
|
+
sp.add_argument("--product", default="",
|
|
446
|
+
help="归因绑定:本 agent 服务的产品(codearts/aishell 等;采集反馈默认归属)")
|
|
447
|
+
sp.add_argument("--distribution", default="devkit", choices=["devkit", "preset"],
|
|
448
|
+
help="devkit=开发/运维自装(默认);preset=产品随 agent 分发(禁 key 随包/"
|
|
449
|
+
"禁自更新/客户机首启重生成状态)")
|
|
450
|
+
sp.add_argument("--no-local-ledger", action="store_true",
|
|
451
|
+
help="关闭本地提交账本(企业数据驻留要求;vod_list_submitted 将不可用)")
|
|
452
|
+
sp.set_defaults(fn=cmd_install)
|
|
453
|
+
for name, fn in (("status", cmd_status), ("doctor", cmd_doctor),
|
|
454
|
+
("verify", cmd_verify), ("update", cmd_update),
|
|
455
|
+
("uninstall", cmd_uninstall)):
|
|
456
|
+
s = sub.add_parser(name)
|
|
457
|
+
s.set_defaults(fn=fn)
|
|
458
|
+
sub.add_parser("build-info").set_defaults(fn=lambda a: write_build_info(strict=False))
|
|
459
|
+
args = ap.parse_args()
|
|
460
|
+
args.fn(args)
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
if __name__ == "__main__":
|
|
464
|
+
main()
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "vod-devkit MCP 工具契约(唯一事实源)",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"tools": {
|
|
6
|
+
"vod_submit_voices": {
|
|
7
|
+
"description": "提交 agent 产品用户反馈声音(写,需确认)。对接囤积端点 POST /external/voices(V16 切换:批式、不触发分析,voiceId 由引擎确定性计算回执下发;引擎未部署 404 自动回落老链)。tags=采集层三分类(problem_type:值)。缺 key 时自动获取零字段匿名令牌。",
|
|
8
|
+
"input": {
|
|
9
|
+
"type": "object",
|
|
10
|
+
"properties": {
|
|
11
|
+
"voices": {
|
|
12
|
+
"type": "array",
|
|
13
|
+
"minItems": 1,
|
|
14
|
+
"maxItems": 50,
|
|
15
|
+
"items": {
|
|
16
|
+
"type": "object",
|
|
17
|
+
"properties": {
|
|
18
|
+
"content": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"minLength": 1,
|
|
21
|
+
"maxLength": 2000
|
|
22
|
+
},
|
|
23
|
+
"userType": {
|
|
24
|
+
"type": "string"
|
|
25
|
+
},
|
|
26
|
+
"tags": {
|
|
27
|
+
"type": "array",
|
|
28
|
+
"items": {
|
|
29
|
+
"type": "string"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"required": [
|
|
34
|
+
"content"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"description": "用户反馈声音列表(content 必填)"
|
|
38
|
+
},
|
|
39
|
+
"confirmed": {
|
|
40
|
+
"type": "boolean",
|
|
41
|
+
"default": false,
|
|
42
|
+
"description": "用户已确认为 true 才执行(confirm 护栏,逐次同意)"
|
|
43
|
+
},
|
|
44
|
+
"product": {
|
|
45
|
+
"type": "string",
|
|
46
|
+
"description": "反馈关于的产品(宿主即产品,不设白名单)。归因顺序:本参数显式指定 > 安装绑定默认(install --product,缺省=宿主名,装在 hermes 归 hermes/dsh 归 DSH)> 不带(引擎落 UNKNOWN 档人工归因)。宿主工具自报产品名原样上送,引擎宽松归一(折叠空白+别名收编)。"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"required": [
|
|
50
|
+
"voices"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
"output": {
|
|
54
|
+
"type": "object",
|
|
55
|
+
"properties": {
|
|
56
|
+
"accepted": {
|
|
57
|
+
"type": "integer"
|
|
58
|
+
},
|
|
59
|
+
"voiceIds": {
|
|
60
|
+
"type": "array",
|
|
61
|
+
"items": {
|
|
62
|
+
"type": "string"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"rejected": {
|
|
66
|
+
"type": "array"
|
|
67
|
+
},
|
|
68
|
+
"taskIds": {
|
|
69
|
+
"type": "array",
|
|
70
|
+
"items": {
|
|
71
|
+
"type": [
|
|
72
|
+
"integer",
|
|
73
|
+
"null"
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
"description": "引擎分析任务 ID(与 voiceIds 对位;幂等重发为 null)"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"required": [
|
|
80
|
+
"accepted",
|
|
81
|
+
"voiceIds"
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
"backend": "java(VOD_JAVA_API_BASE+VOD_JAVA_API_KEY);现有 /external/voice/submit"
|
|
85
|
+
},
|
|
86
|
+
"vod_devkit_info": {
|
|
87
|
+
"description": "插件自述(只读,core pack 常驻):版本/commitSHA/宿主身份/安装信息。",
|
|
88
|
+
"input": {
|
|
89
|
+
"type": "object",
|
|
90
|
+
"properties": {}
|
|
91
|
+
},
|
|
92
|
+
"output": {
|
|
93
|
+
"type": "object",
|
|
94
|
+
"properties": {
|
|
95
|
+
"version": {
|
|
96
|
+
"type": "string"
|
|
97
|
+
},
|
|
98
|
+
"commitSha": {
|
|
99
|
+
"type": "string"
|
|
100
|
+
},
|
|
101
|
+
"hostClient": {
|
|
102
|
+
"type": "object"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"required": [
|
|
106
|
+
"version",
|
|
107
|
+
"commitSha"
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
"backend": "local(无上游)"
|
|
111
|
+
},
|
|
112
|
+
"vod_auth_status": {
|
|
113
|
+
"description": "认证自检(只读,无 key 也能跑):报告双后端 key 配置态(指纹非明文)、连通性、环境指向、生效 packs。缺 key 时输出结构化引导(申请步骤)。",
|
|
114
|
+
"input": {
|
|
115
|
+
"type": "object",
|
|
116
|
+
"properties": {}
|
|
117
|
+
},
|
|
118
|
+
"output": {
|
|
119
|
+
"type": "object",
|
|
120
|
+
"properties": {
|
|
121
|
+
"javaKey": {
|
|
122
|
+
"type": "object"
|
|
123
|
+
},
|
|
124
|
+
"workflowKey": {
|
|
125
|
+
"type": "object"
|
|
126
|
+
},
|
|
127
|
+
"packs": {
|
|
128
|
+
"type": "array"
|
|
129
|
+
},
|
|
130
|
+
"guidance": {
|
|
131
|
+
"type": "array"
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
"required": [
|
|
135
|
+
"javaKey",
|
|
136
|
+
"workflowKey"
|
|
137
|
+
]
|
|
138
|
+
},
|
|
139
|
+
"backend": "local(无上游;探测时轻量 ping)"
|
|
140
|
+
},
|
|
141
|
+
"vod_list_submitted": {
|
|
142
|
+
"description": "查询本机已提交的声音(只读)。本地账本(cap 200),最新在前;跨机/权威查询随引擎端点(VOD-VOI)。终端用户进度追问由 agent 凭此对账回答。",
|
|
143
|
+
"input": {
|
|
144
|
+
"type": "object",
|
|
145
|
+
"properties": {
|
|
146
|
+
"limit": {
|
|
147
|
+
"type": "integer",
|
|
148
|
+
"minimum": 1,
|
|
149
|
+
"maximum": 100,
|
|
150
|
+
"default": 20
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"output": {
|
|
155
|
+
"type": "object",
|
|
156
|
+
"properties": {
|
|
157
|
+
"total": {
|
|
158
|
+
"type": "integer"
|
|
159
|
+
},
|
|
160
|
+
"submissions": {
|
|
161
|
+
"type": "array"
|
|
162
|
+
},
|
|
163
|
+
"scope": {
|
|
164
|
+
"type": "string"
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
"required": [
|
|
168
|
+
"total",
|
|
169
|
+
"submissions"
|
|
170
|
+
]
|
|
171
|
+
},
|
|
172
|
+
"backend": "local(无上游;读本机 runtime.json 账本)"
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
"backends": {
|
|
176
|
+
"java": {
|
|
177
|
+
"base": "VOD_JAVA_API_BASE",
|
|
178
|
+
"key": "VOD_JAVA_API_KEY",
|
|
179
|
+
"auth": "ExternalApiKeyFilter Bearer"
|
|
180
|
+
},
|
|
181
|
+
"local": {
|
|
182
|
+
"base": null,
|
|
183
|
+
"key": null,
|
|
184
|
+
"auth": null
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
package/npm/cli.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* vod-devkit npm 引导器(npx vod-devkit ... 的入口)。
|
|
4
|
+
*
|
|
5
|
+
* 职责:找到 python3(>=3.10)→ 把参数透传给仓内 bin/vod-devkit 安装器。
|
|
6
|
+
* Node 层只是引导(devkit 的 npx 体验同款形态);全部逻辑在 Python 侧。
|
|
7
|
+
*/
|
|
8
|
+
import { spawnSync } from 'node:child_process';
|
|
9
|
+
import { existsSync } from 'node:fs';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { dirname, join } from 'node:path';
|
|
12
|
+
|
|
13
|
+
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
14
|
+
const installer = join(ROOT, 'bin', 'vod-devkit');
|
|
15
|
+
|
|
16
|
+
const candidates = [process.env.VOD_PYTHON, 'python3', 'python3.12', 'python3.11', 'python3.10', 'python']
|
|
17
|
+
.filter(Boolean);
|
|
18
|
+
|
|
19
|
+
function findPython() {
|
|
20
|
+
for (const cmd of candidates) {
|
|
21
|
+
const probe = spawnSync(cmd, ['-c', 'import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)'], { stdio: 'ignore' });
|
|
22
|
+
if (probe.status === 0) return cmd;
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const py = findPython();
|
|
28
|
+
if (!py) {
|
|
29
|
+
console.error('[vod-devkit] 未找到 Python >= 3.10(尝试过: ' + candidates.join(', ') + ')。');
|
|
30
|
+
console.error(' 请安装 Python 3.10+ 或设置 VOD_PYTHON 指向解释器路径。');
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
if (!existsSync(installer)) {
|
|
34
|
+
console.error('[vod-devkit] 安装器缺失: ' + installer);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const result = spawnSync(py, [installer, ...process.argv.slice(2)], { stdio: 'inherit' });
|
|
39
|
+
process.exit(result.status ?? 1);
|