vod-devkit 0.5.4 → 0.5.8
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 +43 -0
- package/QUICKSTART.md +47 -23
- package/README.en.md +7 -2
- package/README.md +6 -2
- package/bin/vod-devkit +12 -1166
- package/contract/tools.schema.json +1 -1
- package/integrations/atomcode/host.json +5 -3
- package/integrations/codeartsdoer/host.json +1 -2
- package/package.json +8 -2
- package/plugins/vod-devkit/.codex-plugin/plugin.json +1 -1
- package/plugins/vod-devkit/build-info.json +3 -3
- package/plugins/vod-devkit/contract/tools.schema.json +446 -0
- package/plugins/vod-devkit/safety/policy.json +48 -0
- package/plugins/vod-devkit/skills/vod-feedback-collect/SKILL.md +13 -4
- package/plugins/vod-devkit/skills/vod-problem-classification-rules/SKILL.md +2 -1
- package/plugins/vod-devkit/skills/vod-scoring-rules/SKILL.md +2 -1
- package/plugins/vod-devkit/vod_mcp/__init__.py +1 -1
- package/plugins/vod-devkit/vod_mcp/__pycache__/__init__.cpython-314.pyc +0 -0
- package/plugins/vod-devkit/vod_mcp/__pycache__/attribution.cpython-314.pyc +0 -0
- package/plugins/vod-devkit/vod_mcp/__pycache__/net.cpython-314.pyc +0 -0
- package/plugins/vod-devkit/vod_mcp/__pycache__/paths.cpython-314.pyc +0 -0
- package/plugins/vod-devkit/vod_mcp/__pycache__/policy.cpython-314.pyc +0 -0
- package/plugins/vod-devkit/vod_mcp/__pycache__/provenance.cpython-314.pyc +0 -0
- package/plugins/vod-devkit/vod_mcp/__pycache__/runtime_state.cpython-314.pyc +0 -0
- package/plugins/vod-devkit/vod_mcp/__pycache__/skills_registry.cpython-314.pyc +0 -0
- package/plugins/vod-devkit/vod_mcp/__pycache__/tools.cpython-314.pyc +0 -0
- package/plugins/vod-devkit/vod_mcp/attribution.py +8 -8
- package/plugins/vod-devkit/vod_mcp/host_adapters/base.py +3 -1
- package/plugins/vod-devkit/vod_mcp/host_adapters/codex.py +16 -3
- package/plugins/vod-devkit/vod_mcp/host_adapters/hermes.py +99 -16
- package/plugins/vod-devkit/vod_mcp/hosts.py +3 -1
- package/plugins/vod-devkit/vod_mcp/net.py +251 -0
- package/plugins/vod-devkit/vod_mcp/packs/__pycache__/__init__.cpython-314.pyc +0 -0
- package/plugins/vod-devkit/vod_mcp/packs/__pycache__/collect.cpython-314.pyc +0 -0
- package/plugins/vod-devkit/vod_mcp/packs/__pycache__/core.cpython-314.pyc +0 -0
- package/plugins/vod-devkit/vod_mcp/packs/__pycache__/knowledge.cpython-314.pyc +0 -0
- package/plugins/vod-devkit/vod_mcp/packs/collect.py +684 -0
- package/plugins/vod-devkit/vod_mcp/packs/core.py +80 -0
- package/plugins/vod-devkit/vod_mcp/packs/knowledge.py +17 -0
- package/plugins/vod-devkit/vod_mcp/paths.py +38 -0
- package/plugins/vod-devkit/vod_mcp/payload.py +3 -1
- package/plugins/vod-devkit/vod_mcp/policy.py +3 -2
- package/plugins/vod-devkit/vod_mcp/provenance.py +3 -2
- package/plugins/vod-devkit/vod_mcp/remote_app.py +25 -0
- package/plugins/vod-devkit/vod_mcp/runtime_state.py +324 -0
- package/plugins/vod-devkit/vod_mcp/server.py +10 -7
- package/plugins/vod-devkit/vod_mcp/skills_registry.py +11 -9
- package/plugins/vod-devkit/vod_mcp/tools.py +23 -1300
- package/plugins/vod-devkit/vod_mcp/transport_remote.py +68 -8
- package/plugins/vod-devkit/vod_mcp/update_check.py +1 -1
- package/skills/vod-feedback-collect/SKILL.md +13 -4
- package/skills/vod-problem-classification-rules/SKILL.md +2 -1
- package/skills/vod-scoring-rules/SKILL.md +2 -1
- package/vod_mcp/__init__.py +1 -1
- package/vod_mcp/attribution.py +8 -8
- package/vod_mcp/host_adapters/__pycache__/__init__.cpython-39.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/atomcode.cpython-39.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/base.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/base.cpython-39.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/codearts.cpython-39.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/codeartswork.cpython-39.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/codex.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/codex.cpython-39.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/codex_desktop.cpython-39.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/dsh.cpython-39.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/generic.cpython-39.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/hermes.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/hermes.cpython-39.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/opencode.cpython-39.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/workbuddy.cpython-39.pyc +0 -0
- package/vod_mcp/host_adapters/base.py +3 -1
- package/vod_mcp/host_adapters/codex.py +16 -3
- package/vod_mcp/host_adapters/hermes.py +99 -16
- package/vod_mcp/hosts.py +3 -1
- package/vod_mcp/net.py +251 -0
- package/vod_mcp/packs/__pycache__/__init__.cpython-314.pyc +0 -0
- package/vod_mcp/packs/__pycache__/__init__.cpython-39.pyc +0 -0
- package/vod_mcp/packs/__pycache__/collect.cpython-314.pyc +0 -0
- package/vod_mcp/packs/__pycache__/collect.cpython-39.pyc +0 -0
- package/vod_mcp/packs/__pycache__/core.cpython-314.pyc +0 -0
- package/vod_mcp/packs/__pycache__/core.cpython-39.pyc +0 -0
- package/vod_mcp/packs/__pycache__/knowledge.cpython-314.pyc +0 -0
- package/vod_mcp/packs/__pycache__/knowledge.cpython-39.pyc +0 -0
- package/vod_mcp/packs/collect.py +684 -0
- package/vod_mcp/packs/core.py +80 -0
- package/vod_mcp/packs/knowledge.py +17 -0
- package/vod_mcp/paths.py +38 -0
- package/vod_mcp/payload.py +3 -1
- package/vod_mcp/policy.py +3 -2
- package/vod_mcp/provenance.py +3 -2
- package/vod_mcp/remote_app.py +25 -0
- package/vod_mcp/runtime_state.py +324 -0
- package/vod_mcp/server.py +10 -7
- package/vod_mcp/skills_registry.py +11 -9
- package/vod_mcp/tools.py +23 -1300
- package/vod_mcp/transport_remote.py +68 -8
- package/vod_mcp/update_check.py +1 -1
- package/vodkit_cli/__init__.py +10 -0
- package/vodkit_cli/__pycache__/__init__.cpython-314.pyc +0 -0
- package/vodkit_cli/__pycache__/__init__.cpython-39.pyc +0 -0
- package/vodkit_cli/__pycache__/cli.cpython-314.pyc +0 -0
- package/vodkit_cli/__pycache__/cli.cpython-39.pyc +0 -0
- package/vodkit_cli/__pycache__/common.cpython-314.pyc +0 -0
- package/vodkit_cli/__pycache__/common.cpython-39.pyc +0 -0
- package/vodkit_cli/__pycache__/doctor.cpython-314.pyc +0 -0
- package/vodkit_cli/__pycache__/doctor.cpython-39.pyc +0 -0
- package/vodkit_cli/__pycache__/install.cpython-314.pyc +0 -0
- package/vodkit_cli/__pycache__/install.cpython-39.pyc +0 -0
- package/vodkit_cli/__pycache__/remote.cpython-314.pyc +0 -0
- package/vodkit_cli/__pycache__/remote.cpython-39.pyc +0 -0
- package/vodkit_cli/__pycache__/uninstall.cpython-314.pyc +0 -0
- package/vodkit_cli/__pycache__/uninstall.cpython-39.pyc +0 -0
- package/vodkit_cli/__pycache__/update.cpython-314.pyc +0 -0
- package/vodkit_cli/__pycache__/update.cpython-39.pyc +0 -0
- package/vodkit_cli/cli.py +86 -0
- package/vodkit_cli/common.py +254 -0
- package/vodkit_cli/doctor.py +269 -0
- package/vodkit_cli/install.py +260 -0
- package/vodkit_cli/remote.py +200 -0
- package/vodkit_cli/uninstall.py +161 -0
- package/vodkit_cli/update.py +45 -0
- /package/plugins/vod-devkit/vod_mcp/{packs.py → packs/__init__.py} +0 -0
- /package/vod_mcp/{packs.py → packs/__init__.py} +0 -0
package/bin/vod-devkit
CHANGED
|
@@ -1,1177 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""vod-devkit
|
|
2
|
+
"""vod-devkit 安装器入口(薄壳)。
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
实现在 vodkit_cli/ 包内(F8:1245 行单体按命令域拆分)。这里只做两件事:
|
|
5
|
+
① 把包根塞进 sys.path(脚本直跑时可得);② 引出 main 与对外稳定面
|
|
6
|
+
(PRESETS / detect_targets / build_info / write_build_info —— 测试与文档依赖)。
|
|
7
|
+
|
|
8
|
+
首个参数是 `serve` 时整体透传给 MCP server(不读任何安装配置)。
|
|
6
9
|
"""
|
|
7
|
-
import argparse
|
|
8
|
-
import json
|
|
9
|
-
import os
|
|
10
|
-
import re
|
|
11
|
-
import shutil
|
|
12
|
-
import subprocess
|
|
13
10
|
import sys
|
|
14
|
-
import datetime
|
|
15
11
|
from pathlib import Path
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
sys.path.insert(0, str(ROOT))
|
|
19
|
-
|
|
20
|
-
from vod_mcp import hosts as host_specs # noqa: E402 宿主适配层(数据驱动:路径/探测/生成物)
|
|
21
|
-
from vod_mcp.host_adapters import REGISTRY as HOST_ADAPTERS # noqa: E402 宿主安装逻辑(每宿主一模块)
|
|
22
|
-
from vod_mcp.host_adapters import generic as generic_host # noqa: E402
|
|
23
|
-
|
|
24
|
-
# 路径常量一律来自 integrations/<host>/host.json(单一来源):新增宿主=加
|
|
25
|
-
# 目录,不改这里;平台差异也在数据里(opencode 的 windows 分叉)。
|
|
26
|
-
_HERMES_SPEC = host_specs.load("hermes")
|
|
27
|
-
HERMES_MCP_DIR = Path(_HERMES_SPEC["configPath"]).parent # 约定:写入前打印供确认
|
|
28
|
-
HERMES_SKILLS_DIR = Path(_HERMES_SPEC["skillsDir"])
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def git_sha(strict: bool) -> str | None:
|
|
32
|
-
dirty = bool(subprocess.run(["git", "status", "--porcelain"], cwd=ROOT,
|
|
33
|
-
capture_output=True).stdout.strip())
|
|
34
|
-
if strict and dirty:
|
|
35
|
-
print("工作区不干净,拒绝构建(构建纪律)", file=sys.stderr)
|
|
36
|
-
sys.exit(1)
|
|
37
|
-
sha = subprocess.run(["git", "rev-parse", "HEAD"], cwd=ROOT,
|
|
38
|
-
capture_output=True, text=True).stdout.strip()
|
|
39
|
-
return sha or None
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def _safe_remote(url: str) -> str:
|
|
43
|
-
"""凭据脱敏:oauth2:xxx@ / https://user:pass@ 一律剥离。"""
|
|
44
|
-
import re as _re
|
|
45
|
-
return _re.sub(r"(https?://)([^@/]+@)", r"\1", url)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def build_info(strict: bool = False) -> dict:
|
|
49
|
-
from vod_mcp import __version__
|
|
50
|
-
remote = subprocess.run(["git", "remote", "get-url", "origin"], cwd=ROOT,
|
|
51
|
-
capture_output=True, text=True).stdout.strip()
|
|
52
|
-
return {
|
|
53
|
-
"version": __version__,
|
|
54
|
-
"commitSha": git_sha(strict),
|
|
55
|
-
"builtAt": datetime.datetime.now().isoformat(timespec="seconds"),
|
|
56
|
-
"sourceRemote": _safe_remote(remote) if remote else None,
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
def write_build_info(strict: bool):
|
|
61
|
-
info = build_info(strict)
|
|
62
|
-
# 隔离跑法(宿主矩阵/CI 用例)不许改真实仓的 build-info:它会被重烧成当前
|
|
63
|
-
# HEAD,而包内副本停在发版提交 → 结构门禁"根/包内不一致"假红(本轮实锤)。
|
|
64
|
-
if os.environ.get("VOD_DEVKIT_NO_BUILD_INFO"):
|
|
65
|
-
print("build-info.json: 跳过写入(VOD_DEVKIT_NO_BUILD_INFO)")
|
|
66
|
-
return
|
|
67
|
-
(ROOT / "build-info.json").write_text(
|
|
68
|
-
json.dumps(info, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
69
|
-
print("build-info.json:", json.dumps(info, ensure_ascii=False))
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def manifest_path() -> Path:
|
|
73
|
-
"""安装名册位置:默认仓根;VOD_DEVKIT_MANIFEST 可覆盖(多安装根/隔离测试)。
|
|
74
|
-
|
|
75
|
-
契约上 manifest 落在"安装器所在的仓根"——npx 缓存下的仓被清掉时名册一起消失,
|
|
76
|
-
所以 doctor/uninstall 只在同一个仓上下文里自洽;需要另置一份或多份时用该 env。
|
|
77
|
-
"""
|
|
78
|
-
override = (os.environ.get("VOD_DEVKIT_MANIFEST") or "").strip()
|
|
79
|
-
return Path(override) if override else ROOT / "install-manifest.json"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
PRESETS = {
|
|
83
|
-
# 对外默认:开发者=反馈采集者(workflow 不进对外默认集)
|
|
84
|
-
"collect": "core,collect",
|
|
85
|
-
# 内部:运营/可信第三方全量。2026-11-06 修正(深审 P0-2):原值
|
|
86
|
-
# "core,workflow,kb,collect" 与运行期 ALL_PACKS=(core,collect,knowledge)
|
|
87
|
-
# 命名漂移——workflow 包已随"运营归 vod-system 前端"净删、kb 是
|
|
88
|
-
# knowledge 的旧称,按原值安装 workflow/kb 被静默丢弃(安装口说装了
|
|
89
|
-
# 运行口不认=挪到别处而非消除)
|
|
90
|
-
"full": "core,collect,knowledge",
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
def _skill_installs(manifest_path: Path, extra_dirs) -> list:
|
|
95
|
-
"""多宿主技能落点并集(名册对账):manifest 按「最近一次安装」覆盖会
|
|
96
|
-
互相冲掉落点(实锤:codex 装完 opencode 落点消失),按 host+dir
|
|
97
|
-
去重保留历史落点。"""
|
|
98
|
-
import json as _json
|
|
99
|
-
import os
|
|
100
|
-
home = str(Path.home()) + os.sep
|
|
101
|
-
prev = {}
|
|
102
|
-
if manifest_path.exists():
|
|
103
|
-
try:
|
|
104
|
-
for si in _json.loads(manifest_path.read_text(encoding="utf-8")).get("skillInstalls") or []:
|
|
105
|
-
d = si.get("dir") or ""
|
|
106
|
-
# 只保留「当前 HOME 之下且目录真实存在」的落点——隔离环境
|
|
107
|
-
# (fake-home 测试)不吞真实 HOME 的历史落点,卸载残留自动剪枝
|
|
108
|
-
if d.startswith(home) and Path(d).is_dir():
|
|
109
|
-
prev[(si["host"], d)] = si
|
|
110
|
-
except Exception:
|
|
111
|
-
pass
|
|
112
|
-
for h, d in [("hermes", HERMES_SKILLS_DIR)] + list(extra_dirs or []):
|
|
113
|
-
if d is not None:
|
|
114
|
-
prev[(h, str(d))] = {"host": h, "dir": str(d)}
|
|
115
|
-
return sorted(prev.values(), key=lambda x: (x["host"], x["dir"]))
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
def _dir_hashes(base: Path) -> dict:
|
|
119
|
-
"""对既有目录树计算相对 sha256 指纹(roster 对账用)。"""
|
|
120
|
-
import hashlib
|
|
121
|
-
out = {}
|
|
122
|
-
for skill in sorted(Path(base).iterdir()):
|
|
123
|
-
if skill.is_dir():
|
|
124
|
-
for f in sorted(skill.rglob("*")):
|
|
125
|
-
if f.is_file():
|
|
126
|
-
out[f"{skill.name}/{f.relative_to(skill)}"] = (
|
|
127
|
-
hashlib.sha256(f.read_bytes()).hexdigest())
|
|
128
|
-
return out
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
def _skill_hashes() -> dict:
|
|
132
|
-
"""技能拷贝件指纹(D-drift-lock):安装时记录 sha256,verify/doctor 比对
|
|
133
|
-
——拷贝件与安装产物漂移可检(vendor 规则漂移实锤的针对性防线)。"""
|
|
134
|
-
import hashlib
|
|
135
|
-
out = {}
|
|
136
|
-
for entry in sorted((ROOT / "skills").iterdir()):
|
|
137
|
-
if entry.is_dir():
|
|
138
|
-
for f in sorted(entry.rglob("*")):
|
|
139
|
-
if f.is_file():
|
|
140
|
-
rel = f"{entry.name}/{f.relative_to(entry)}"
|
|
141
|
-
out[rel] = hashlib.sha256(f.read_bytes()).hexdigest()
|
|
142
|
-
return out
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
def _drifted_skills(manifest: dict) -> list:
|
|
146
|
-
"""比对 skillsDir 拷贝件与 manifest.skillHashes,返回漂移文件清单。"""
|
|
147
|
-
import hashlib
|
|
148
|
-
base = Path(manifest["skillsDir"])
|
|
149
|
-
drifted = []
|
|
150
|
-
for rel, sha in (manifest.get("skillHashes") or {}).items():
|
|
151
|
-
f = base / rel
|
|
152
|
-
if not f.exists():
|
|
153
|
-
drifted.append(f"{rel}(缺失)")
|
|
154
|
-
elif hashlib.sha256(f.read_bytes()).hexdigest() != sha:
|
|
155
|
-
drifted.append(f"{rel}(内容被改)")
|
|
156
|
-
return drifted
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
_AGENTS_MARKER_BEGIN = "<!-- vod-devkit:feedback-skill BEGIN -->"
|
|
160
|
-
_AGENTS_MARKER_END = "<!-- vod-devkit:feedback-skill END -->"
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
def _expected_remote_tools() -> set:
|
|
164
|
-
"""远程面应当暴露的工具集 = 契约全集 - REMOTE_WITHHELD(写面本机工具不进远程)。"""
|
|
165
|
-
from vod_mcp import packs as _packs
|
|
166
|
-
contract = json.loads((ROOT / "contract" / "tools.schema.json").read_text(encoding="utf-8"))
|
|
167
|
-
return set(contract["tools"]) - set(_packs.REMOTE_WITHHELD)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def _probe_remote(url: str, token: str, timeout: int = 15) -> list:
|
|
171
|
-
"""远程 MCP 端点探活:initialize + tools/list,返回工具名清单(失败抛 RuntimeError)。
|
|
172
|
-
|
|
173
|
-
走 stdlib urllib(安装器零第三方依赖红线);Accept 双类型,兼容 SSE 单事件响应。
|
|
174
|
-
探活在**写入任何配置之前**执行——装不上就不留半成品。
|
|
175
|
-
"""
|
|
176
|
-
import urllib.request
|
|
177
|
-
|
|
178
|
-
def _post(payload: dict) -> dict:
|
|
179
|
-
req = urllib.request.Request(
|
|
180
|
-
url, data=json.dumps(payload).encode(), method="POST",
|
|
181
|
-
headers={"content-type": "application/json",
|
|
182
|
-
"accept": "application/json, text/event-stream",
|
|
183
|
-
**({"Authorization": f"Bearer {token}"} if token else {})})
|
|
184
|
-
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
185
|
-
body = resp.read().decode("utf-8", "replace")
|
|
186
|
-
if body.startswith("event:") or body.startswith("data:"):
|
|
187
|
-
for line in body.splitlines():
|
|
188
|
-
if line.startswith("data:"):
|
|
189
|
-
body = line[5:].strip()
|
|
190
|
-
break
|
|
191
|
-
data = json.loads(body or "{}")
|
|
192
|
-
if isinstance(data, dict) and data.get("error"):
|
|
193
|
-
raise RuntimeError(f"JSON-RPC 错误:{data['error']}")
|
|
194
|
-
return data
|
|
195
|
-
|
|
196
|
-
_post({"jsonrpc": "2.0", "id": 1, "method": "initialize",
|
|
197
|
-
"params": {"protocolVersion": "2025-06-18",
|
|
198
|
-
"clientInfo": {"name": "vod-devkit-installer", "version": "1"},
|
|
199
|
-
"capabilities": {}}})
|
|
200
|
-
listed = _post({"jsonrpc": "2.0", "id": 2, "method": "tools/list"})
|
|
201
|
-
names = [t.get("name") for t in (listed.get("result") or {}).get("tools") or []]
|
|
202
|
-
if not names:
|
|
203
|
-
raise RuntimeError("tools/list 返回空——端点可能不是 Streamable HTTP MCP")
|
|
204
|
-
return names
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
def _remote_reachable(url: str, timeout: int = 6) -> bool:
|
|
208
|
-
"""端点是否可达:GET 得到任何 HTTP 响应(405 是远程面契约的正常应答)即算通。"""
|
|
209
|
-
import urllib.error
|
|
210
|
-
import urllib.request
|
|
211
|
-
try:
|
|
212
|
-
with urllib.request.urlopen(url, timeout=timeout):
|
|
213
|
-
return True
|
|
214
|
-
except urllib.error.HTTPError:
|
|
215
|
-
return True # 405/401/406 都证明端点活着
|
|
216
|
-
except Exception:
|
|
217
|
-
return False
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
def detect_targets() -> list:
|
|
223
|
-
"""0/1/N 探测:按 host.json 的 detect 段判断宿主是否在场(CLI 或配置目录)。"""
|
|
224
|
-
found = []
|
|
225
|
-
for host in host_specs.hosts():
|
|
226
|
-
spec = host_specs.raw(host) # 探测不解析路径(dsh 的 {profile} 占位符必填)
|
|
227
|
-
if spec.get("detectCLI") and shutil.which(spec["detectCLI"]):
|
|
228
|
-
found.append(host)
|
|
229
|
-
elif spec.get("detectPath") and Path(spec["detectPath"]).exists():
|
|
230
|
-
found.append(host)
|
|
231
|
-
return found
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
def _validate_product_or_exit(product: str, base: str) -> bool:
|
|
235
|
-
"""D-product-id-2:安装期产品硬校验(B 案,2026-11-05 拍板)。
|
|
236
|
-
--product 命中 meta productCatalog(名字大小写不敏感或 id 精确)才放行;
|
|
237
|
-
未命中/目录不可达一律拒绝安装并给可执行引导(宁可不装不可装错)。"""
|
|
238
|
-
import urllib.request
|
|
239
|
-
import urllib.error
|
|
240
|
-
import uuid
|
|
241
|
-
api_prefix = "/rest/developer/manager/hdvodmngservice/v1"
|
|
242
|
-
key = os.environ.get("VOD_JAVA_API_KEY", "")
|
|
243
|
-
token = ""
|
|
244
|
-
# 全程一致的设备锚点(S1 设备绑定:token 与后续请求必须同 device/UA,
|
|
245
|
-
# 否则 meta 401 设备不匹配;每次装机一个新锚点,一次校验只耗一枚令牌)
|
|
246
|
-
device = uuid.uuid4().hex[:32]
|
|
247
|
-
ua = "vod-devkit-installer/1"
|
|
248
|
-
|
|
249
|
-
def _get(url: str):
|
|
250
|
-
auth = key or token
|
|
251
|
-
req = urllib.request.Request(url, headers={
|
|
252
|
-
"content-type": "application/json",
|
|
253
|
-
"X-Vod-Device-Id": device,
|
|
254
|
-
"User-Agent": ua,
|
|
255
|
-
**({"authorization": f"Bearer {auth}"} if auth else {}),
|
|
256
|
-
})
|
|
257
|
-
with urllib.request.urlopen(req, timeout=10) as resp:
|
|
258
|
-
return resp.status, resp.read().decode("utf-8", "replace")
|
|
259
|
-
|
|
260
|
-
try:
|
|
261
|
-
if not key:
|
|
262
|
-
req = urllib.request.Request( # 零字段匿名令牌(方案 C 同链)
|
|
263
|
-
f"{base}{api_prefix}/external/token", data=b"{}",
|
|
264
|
-
headers={"content-type": "application/json", "X-Vod-Device-Id": device,
|
|
265
|
-
"User-Agent": ua}, method="POST")
|
|
266
|
-
with urllib.request.urlopen(req, timeout=10) as resp:
|
|
267
|
-
body = json.loads(resp.read().decode("utf-8", "replace") or "{}")
|
|
268
|
-
token = (body.get("data") or {}).get("token") or body.get("token") or ""
|
|
269
|
-
catalog = None
|
|
270
|
-
status, text = _get(f"{base}{api_prefix}/external/meta")
|
|
271
|
-
data = (json.loads(text) or {}).get("data") or {}
|
|
272
|
-
catalog = data.get("productCatalog")
|
|
273
|
-
if not catalog and token: # 老引擎 meta 无目录 → 退 /external/products
|
|
274
|
-
status, text = _get(f"{base}{api_prefix}/external/products") if not key else (None, None)
|
|
275
|
-
if text:
|
|
276
|
-
data = (json.loads(text) or {}).get("data") or []
|
|
277
|
-
catalog = data
|
|
278
|
-
if not catalog:
|
|
279
|
-
print("[vod-devkit] 产品校验失败:引擎 meta 无 productCatalog 且 /external/products 不可用。\n"
|
|
280
|
-
" 不执行安装(宁可不装不可装错)。请核对 --java-api-base 指向的引擎是否已部署 T7i 版本。",
|
|
281
|
-
file=sys.stderr)
|
|
282
|
-
sys.exit(2)
|
|
283
|
-
p = product.strip()
|
|
284
|
-
hit = any(
|
|
285
|
-
(str(x.get("name") or "").lower() == p.lower())
|
|
286
|
-
or (str(x.get("id")) == p)
|
|
287
|
-
for x in catalog if isinstance(x, dict))
|
|
288
|
-
if not hit:
|
|
289
|
-
sample = " / ".join(str(x.get("name")) for x in catalog[:8] if isinstance(x, dict))
|
|
290
|
-
print(f"[vod-devkit] --product '{product}' 不在产品名录(t_vod_product),拒绝安装。\n"
|
|
291
|
-
" 归因前提无效=内置采集技能/分类/透传全部空转且用户无感知(归因错误比报错更糟)。\n"
|
|
292
|
-
f" 权威名单:GET {api_prefix}/external/products(共 {len(catalog)} 项),示例:{sample} …",
|
|
293
|
-
file=sys.stderr)
|
|
294
|
-
sys.exit(2)
|
|
295
|
-
return True
|
|
296
|
-
except SystemExit:
|
|
297
|
-
raise
|
|
298
|
-
except Exception as e:
|
|
299
|
-
print(f"[vod-devkit] 产品校验不可达({e.__class__.__name__}),拒绝安装(宁可不装不可装错)。\n"
|
|
300
|
-
" 请核对网络与 --java-api-base;确需离线安装请联系 VOD 运营。",
|
|
301
|
-
file=sys.stderr)
|
|
302
|
-
sys.exit(2)
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
def cmd_install(args):
|
|
306
|
-
from vod_mcp import DEFAULT_JAVA_BASE
|
|
307
|
-
if not args.java_api_base:
|
|
308
|
-
# 优先级:--java-api-base > env VOD_JAVA_API_BASE > DEFAULT_JAVA_BASE
|
|
309
|
-
#(env 与插件运行时同键,安装器跟随同链;测试/CI 用 env 指桩引擎零外呼)
|
|
310
|
-
args.java_api_base = os.environ.get("VOD_JAVA_API_BASE") or DEFAULT_JAVA_BASE
|
|
311
|
-
write_build_info(strict=False)
|
|
312
|
-
target = args.target
|
|
313
|
-
if target == "auto":
|
|
314
|
-
found = detect_targets()
|
|
315
|
-
generic_found = generic_host.detect_known()
|
|
316
|
-
if len(found) == 1:
|
|
317
|
-
target = found[0]
|
|
318
|
-
elif not found and len(generic_found) == 1:
|
|
319
|
-
# A 层兜底:没有专属模块但有已知通用 MCP 宿主 → 走通用写入
|
|
320
|
-
#(探到唯一一个才自动写,多个/零个都要人选定,不许猜)
|
|
321
|
-
target = "generic"
|
|
322
|
-
if not getattr(args, "mcp_config", ""):
|
|
323
|
-
args.mcp_config = str(generic_host._expand(generic_found[0]["config"]))
|
|
324
|
-
print(f"探测到通用 MCP 宿主: {generic_found[0]['label']} → 通用写入 "
|
|
325
|
-
f"({args.mcp_config})")
|
|
326
|
-
elif not found:
|
|
327
|
-
known = "、".join(h["label"] + "(" + h["config"] + ")" for h in generic_found)
|
|
328
|
-
print("未探测到可自动安装的宿主;用 --target hermes|opencode|codeartsdoer|codeartswork|codex|codex-desktop|dsh|workbuddy|atomcode 显式指定"
|
|
329
|
-
+ (f",或通用写入:--target generic --mcp-config <配置>(探测到 {known})"
|
|
330
|
-
if generic_found else ""), file=sys.stderr)
|
|
331
|
-
sys.exit(2)
|
|
332
|
-
else:
|
|
333
|
-
print(f"探测到多个宿主: {found + [h['id'] for h in generic_found]};"
|
|
334
|
-
"请 --target 显式指定其一", file=sys.stderr)
|
|
335
|
-
sys.exit(2)
|
|
336
|
-
print(f"探测到宿主: {target}")
|
|
337
|
-
adapter = HOST_ADAPTERS.get(target)
|
|
338
|
-
if adapter is None:
|
|
339
|
-
g = [(h["id"], h["config"]) for h in generic_host.detect_known()]
|
|
340
|
-
hint = ("\n 探测到通用 MCP 宿主:" + ";".join(f"{i}({c})" for i, c in g)
|
|
341
|
-
if g else "")
|
|
342
|
-
print(f"不支持目标: {target}(可选 hermes|opencode|codeartsdoer|codeartswork|codex|codex-desktop|dsh|workbuddy|atomcode|generic|auto){hint}\n"
|
|
343
|
-
" 通用宿主:install --target generic --mcp-config <配置文件>",
|
|
344
|
-
file=sys.stderr)
|
|
345
|
-
sys.exit(2)
|
|
346
|
-
packs = args.packs or PRESETS.get(args.preset, "")
|
|
347
|
-
# 恢复门禁(D-codex-circuit-breaker-1,2026-11-06 负责人确认):
|
|
348
|
-
# 熔断标记存在(~/.codex/vod-collect-suspended.json)时,codex 装 collect
|
|
349
|
-
# 被拒——恢复采集的前置=token 化上线并过回归,不是改回 packs 一个动作;
|
|
350
|
-
# --ack-suspension=显式解除(P1-4 修正:解除动作后置到安装成功之后——
|
|
351
|
-
# 若产品校验/安装中途失败,熔断不得已被解除)。
|
|
352
|
-
pending_ack = False
|
|
353
|
-
if target == "codex" and "collect" in (packs or "").replace(" ", "").split(","):
|
|
354
|
-
marker = Path.home() / ".codex" / "vod-collect-suspended.json"
|
|
355
|
-
if marker.is_file() and getattr(args, "ack_suspension", False):
|
|
356
|
-
pending_ack = True # 解除后置:安装成功才落
|
|
357
|
-
elif marker.is_file():
|
|
358
|
-
print("[vod-devkit] 恢复门禁:codex 采集处于熔断状态"
|
|
359
|
-
"(未确认提交 ≥2 次,详见 docs/decisions.md"
|
|
360
|
-
" D-codex-circuit-breaker-1)。"
|
|
361
|
-
"恢复前置=token 化两段式上线并通过回归"
|
|
362
|
-
"(draft→commit 审计链/重复 commit 被拒/未确认可检测)。",
|
|
363
|
-
file=sys.stderr)
|
|
364
|
-
sys.exit(2)
|
|
365
|
-
# 归因绑定降级(D-attrib-B,2026-11-11 负责人拍板 P1-P4 全 A):--product
|
|
366
|
-
# 由必填改为**可选先验**——归因主路径改成运行期从用户原话解析(证据唯一
|
|
367
|
-
# 命中才采信),安装绑定只在「无字面证据且无记忆」时兜底。保留「给了就
|
|
368
|
-
# 必须对」:显式提供时仍做名录硬校验(拼错照样 exit 2),不给不拦装。
|
|
369
|
-
# D-dsh-install-1:--profile 必填在进入任何安装动作前校验(先校验后写入)
|
|
370
|
-
if target == "dsh" and not (args.dsh_profile or "").strip():
|
|
371
|
-
print("[vod-devkit] --profile 必填:dsh 按 profile 组织插件与配置。\n"
|
|
372
|
-
" 例:npx vod-devkit install --target dsh --profile web --product CodeArts",
|
|
373
|
-
file=sys.stderr)
|
|
374
|
-
sys.exit(2)
|
|
375
|
-
bound_product = args.product
|
|
376
|
-
# D-product-id-2(2026-11-05 用户拍板 B,推翻"宿主名是显式合法值"宽容口径):
|
|
377
|
-
# 安装期产品硬校验——--product 必须命中 meta productCatalog(名字大小写不敏感
|
|
378
|
-
# 或平台主键 id 精确)。理由:--product 是整条采集链(内置采集技能/分类/透传)
|
|
379
|
-
# 的归因前提,装错=全套 skill 逻辑空转且用户无感知;归因错误比报错更糟。
|
|
380
|
-
# 目录不可达(离线/引擎异常)同样拒绝——宁可不装不可装错(postinstall 拒绝
|
|
381
|
-
# 猜测同源纪律)。插件提交链的 name 兼容通道不受影响(那是老版本插件兼容,
|
|
382
|
-
# 不是安装期放行理由)。
|
|
383
|
-
if args.product: # 可选先验:给了就校验,不给不拦装(D-attrib-B)
|
|
384
|
-
_validate_product_or_exit(args.product, args.java_api_base)
|
|
385
|
-
# D-key-guard-2 红线:preset(产品分发)形态下 key 禁止随包——环境变量里的
|
|
386
|
-
# key 不透传给宿主配置(客户机一律走匿名令牌自领),并当场告警
|
|
387
|
-
distribution = args.distribution
|
|
388
|
-
if distribution == "preset" and os.environ.pop("VOD_JAVA_API_KEY", None):
|
|
389
|
-
print("[vod-devkit] warn: preset 形态下 VOD_JAVA_API_KEY 已忽略且不写入宿主配置"
|
|
390
|
-
"(key 落在哪台机器哪台就是信任边界;客户机走匿名令牌)", file=sys.stderr)
|
|
391
|
-
rt = ROOT / "vod_mcp" / "runtime.json"
|
|
392
|
-
cfg = {}
|
|
393
|
-
if rt.exists():
|
|
394
|
-
try:
|
|
395
|
-
cfg = json.loads(rt.read_text(encoding="utf-8"))
|
|
396
|
-
except Exception:
|
|
397
|
-
cfg = {}
|
|
398
|
-
cfg["product"] = bound_product
|
|
399
|
-
if getattr(args, "no_local_ledger", False):
|
|
400
|
-
# D-key-guard-3④:企业数据驻留要求可关本地账本(代价 vod_list_submitted 不可用)
|
|
401
|
-
cfg["local_ledger"] = False
|
|
402
|
-
# base 同步落 runtime.json:宿主 env 透传不稳是实测坑,透传挂了静默落回
|
|
403
|
-
# 127.0.0.1:8090;文件兑底与 env 同值不构成双真源(优先级链 env>文件)
|
|
404
|
-
# 宿主产品(host_default 兜底用,D-product-ask-1):只有 integrations 声明了才写
|
|
405
|
-
spec_raw = host_specs.raw(target) if target in host_specs.hosts() else {}
|
|
406
|
-
if spec_raw.get("productDefault"):
|
|
407
|
-
cfg["host_product"] = spec_raw["productDefault"]
|
|
408
|
-
cfg["java_base"] = args.java_api_base
|
|
409
|
-
rt.write_text(json.dumps(cfg, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
410
|
-
|
|
411
|
-
# ── 远程 attach / skills-only(D-attach-1)───────────────────────────
|
|
412
|
-
# 形态:MCP 单独部署一个远程端点,宿主只把 MCP 配置指向它(+ 本地技能)。
|
|
413
|
-
# 约束:远程面无匿名链(缺 key fail fast)→ token 必填;探活先于写入,
|
|
414
|
-
# 失败零副作用。dsh 壳不走 MCP,这两种模式对 dsh 无意义(显式拒绝)。
|
|
415
|
-
remote_url = (getattr(args, "mcp_url", "") or "").strip()
|
|
416
|
-
skills_only = bool(getattr(args, "skills_only", False))
|
|
417
|
-
if remote_url or skills_only:
|
|
418
|
-
if not getattr(adapter, "SUPPORTS_REMOTE", False):
|
|
419
|
-
what = "dsh 壳不走 MCP" if target == "dsh" else f"{target} 不走 MCP"
|
|
420
|
-
print(f"[vod-devkit] {what},不支持 --mcp-url / --skills-only\n"
|
|
421
|
-
f" {target} 请用本地形态:install --target {target} "
|
|
422
|
-
+ ("--profile <name>" if target == "dsh" else ""),
|
|
423
|
-
file=sys.stderr)
|
|
424
|
-
sys.exit(2)
|
|
425
|
-
token = (getattr(args, "mcp_token", "") or os.environ.get("VOD_MCP_TOKEN") or "").strip()
|
|
426
|
-
if remote_url:
|
|
427
|
-
if not token:
|
|
428
|
-
print("[vod-devkit] 远程 attach 必须提供 --mcp-token 或 env VOD_MCP_TOKEN:\n"
|
|
429
|
-
" 远程面不代签匿名令牌(身份只从请求头来),无 token 装上也提交不了",
|
|
430
|
-
file=sys.stderr)
|
|
431
|
-
sys.exit(2)
|
|
432
|
-
try:
|
|
433
|
-
names = _probe_remote(remote_url, token)
|
|
434
|
-
except Exception as e: # noqa: BLE001
|
|
435
|
-
print(f"[vod-devkit] 远程 MCP 探活失败(未写入任何配置):{e}", file=sys.stderr)
|
|
436
|
-
sys.exit(2)
|
|
437
|
-
expected = _expected_remote_tools()
|
|
438
|
-
missing = expected - set(names)
|
|
439
|
-
if missing:
|
|
440
|
-
print(f"[vod-devkit] 远程面工具面不符:缺 {sorted(missing)}\n"
|
|
441
|
-
f" 实际 = {sorted(names)}\n"
|
|
442
|
-
" 该端点可能不是 vod-devkit 远程面,或版本/角色不匹配;拒绝安装",
|
|
443
|
-
file=sys.stderr)
|
|
444
|
-
sys.exit(2)
|
|
445
|
-
print(f"远程面探活通过:{len(names)} 个工具({', '.join(sorted(names))})")
|
|
446
|
-
mcp_conf = None if skills_only else adapter.install_remote(args, remote_url, token)
|
|
447
|
-
extra_dirs = _install_skills(target, packs, args,
|
|
448
|
-
(getattr(args, "dsh_profile", "") or "").strip() or None)
|
|
449
|
-
_write_install_manifest(args, target, packs, bound_product, mcp_conf, extra_dirs,
|
|
450
|
-
transport=("skills-only" if skills_only else "remote"),
|
|
451
|
-
mcp_url=remote_url)
|
|
452
|
-
return
|
|
453
|
-
|
|
454
|
-
payload_dir = _stage_payload() # 载荷固化:入口指向这份副本,不再指向 npx 缓存
|
|
455
|
-
mcp_conf = adapter.install(args, packs)
|
|
456
|
-
|
|
457
|
-
# P1-4 修正:ack 解除后置——安装全部成功才落(解除先于安装=失败安装
|
|
458
|
-
# 也绕过了恢复门禁语义)
|
|
459
|
-
if pending_ack:
|
|
460
|
-
marker = Path.home() / ".codex" / "vod-collect-suspended.json"
|
|
461
|
-
if marker.is_file():
|
|
462
|
-
marker.unlink()
|
|
463
|
-
audit = Path.home() / ".codex" / "vod-collect-suspension-audit.log"
|
|
464
|
-
with audit.open("a", encoding="utf-8") as f:
|
|
465
|
-
f.write(f"{datetime.datetime.now().isoformat(timespec='seconds')}\t"
|
|
466
|
-
f"ack_suspension\tpacks={packs}\n")
|
|
467
|
-
print(f"[vod-devkit] 已显式解除 codex 采集熔断(安装成功),审计已记录:{audit}")
|
|
468
|
-
|
|
469
|
-
# G1 修复:技能全量拷贝(目录型技能+平铺规则文档),按 packs 过滤
|
|
470
|
-
extra_dirs = _install_skills(target, packs, args,
|
|
471
|
-
(getattr(args, "dsh_profile", "") or "").strip() or None)
|
|
472
|
-
|
|
473
|
-
_write_install_manifest(args, target, packs, bound_product, mcp_conf,
|
|
474
|
-
extra_dirs, payload_dir=payload_dir)
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
def _stage_payload():
|
|
478
|
-
"""把 server/contract/safety/skills 拷进 ~/.vod-devkit/payloads/<ver>/ 并指过去。
|
|
479
|
-
|
|
480
|
-
对标 devkit 的 copyServerPayload(D-payload-1):npx 安装时仓在
|
|
481
|
-
~/.npm/_npx/<hash>/,npm 清缓存/换版本后入口指向已删除路径 → 宿主 MCP 静默掉线。
|
|
482
|
-
"""
|
|
483
|
-
from vod_mcp import payload as _payload
|
|
484
|
-
from vod_mcp.host_adapters import base as _base
|
|
485
|
-
dest = _payload.stage()
|
|
486
|
-
# 把安装期运行配置种进载荷(载荷 runtime 与仓内 runtime 是两份文件):
|
|
487
|
-
# 否则 host_product/product/java_base 只写在仓内,真正跑起来的副本看不到
|
|
488
|
-
seeded = {k: v for k, v in _runtime_cfg_read().items()
|
|
489
|
-
if k in ("product", "host_product", "java_base", "local_ledger")}
|
|
490
|
-
if seeded:
|
|
491
|
-
rt = dest / "vod_mcp" / "runtime.json"
|
|
492
|
-
cur = {}
|
|
493
|
-
if rt.exists():
|
|
494
|
-
try:
|
|
495
|
-
cur = json.loads(rt.read_text(encoding="utf-8"))
|
|
496
|
-
except Exception:
|
|
497
|
-
cur = {}
|
|
498
|
-
cur.update(seeded)
|
|
499
|
-
rt.write_text(json.dumps(cur, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
500
|
-
_base.set_payload_dir(dest)
|
|
501
|
-
return dest
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
def _install_skills(target: str, packs: str, args, profile: str | None = None):
|
|
505
|
-
"""技能段:按 packs 过滤后拷到 hermes 主目录 + 目标宿主的技能发现目录。
|
|
506
|
-
|
|
507
|
-
目标宿主列表由 integrations/<host>/host.json 的 skillsDir 决定——2026-11-11
|
|
508
|
-
实锤:dsh 此前不在拷贝分支里,npx 装 dsh 只拿到工具、拿不到任何技能文
|
|
509
|
-
件(同意前置/逐字回显/追问判定这些话术纪律整层缺失),而 ~/.dsh/skills
|
|
510
|
-
下的副本是 /opt/vod-install 脚本手工刷的,不是安装器产物。
|
|
511
|
-
返回 [(host, Path)] 落点清单(供 manifest 名册对账)。"""
|
|
512
|
-
HERMES_SKILLS_DIR.mkdir(parents=True, exist_ok=True)
|
|
513
|
-
# opencode 原生技能目录(2026-11-06 实测:opencode 自动发现
|
|
514
|
-
# ~/.config/opencode/skills/ 并经 skill 工具按需加载——此前安装器漏拷,
|
|
515
|
-
# opencode 只有工具描述一条约束通道,话术类约束全部失效)
|
|
516
|
-
extra_dirs = [] # [(host, Path)]
|
|
517
|
-
adapter = HOST_ADAPTERS.get(target)
|
|
518
|
-
dst = adapter.skills_dir(args) if adapter and target != "hermes" else None
|
|
519
|
-
if dst is not None:
|
|
520
|
-
dst.mkdir(parents=True, exist_ok=True)
|
|
521
|
-
extra_dirs.append((target, dst))
|
|
522
|
-
pack_set = set(p for p in packs.split(",") if p)
|
|
523
|
-
for entry in sorted((ROOT / "skills").iterdir()):
|
|
524
|
-
if entry.is_dir(): # vod-core / vod-feedback-collect
|
|
525
|
-
skill = entry.name
|
|
526
|
-
if skill == "vod-core" and "core" not in pack_set:
|
|
527
|
-
continue
|
|
528
|
-
if skill == "vod-feedback-collect" and "collect" not in pack_set:
|
|
529
|
-
continue
|
|
530
|
-
dst = HERMES_SKILLS_DIR / skill
|
|
531
|
-
if dst.exists():
|
|
532
|
-
shutil.rmtree(dst)
|
|
533
|
-
shutil.copytree(entry, dst)
|
|
534
|
-
for _host, oc_dst in extra_dirs:
|
|
535
|
-
dst2 = oc_dst / skill
|
|
536
|
-
if dst2.exists():
|
|
537
|
-
shutil.rmtree(dst2)
|
|
538
|
-
shutil.copytree(entry, dst2)
|
|
539
|
-
# 领域规则技能为静态副本,与引擎真源的对账见 scripts/rules_provenance.py
|
|
540
|
-
return extra_dirs
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
def _read_manifest() -> dict:
|
|
544
|
-
p = manifest_path()
|
|
545
|
-
if not p.exists():
|
|
546
|
-
return {}
|
|
547
|
-
try:
|
|
548
|
-
return json.loads(p.read_text(encoding="utf-8"))
|
|
549
|
-
except Exception:
|
|
550
|
-
return {}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
def _install_rows(prev: dict, row: dict) -> list:
|
|
554
|
-
"""按 target 去重的安装行(D-installs-1):一个 manifest 记全部宿主安装。
|
|
555
|
-
|
|
556
|
-
起因(结构债):顶电平字段只记「最近一次安装」,装 hermes 再装 codearts 后
|
|
557
|
-
uninstall 只清最后一个宿主的 MCP 条目,另一台宿主的配置永远留在那。
|
|
558
|
-
"""
|
|
559
|
-
rows = [r for r in (prev.get("installs") or []) if r.get("target") != row["target"]]
|
|
560
|
-
rows.append(row)
|
|
561
|
-
return sorted(rows, key=lambda r: r.get("installedAt") or "")
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
def _write_install_manifest(args, target, packs, bound_product, mcp_conf,
|
|
565
|
-
extra_dirs, transport: str = "stdio",
|
|
566
|
-
mcp_url: str = "", payload_dir=None) -> None:
|
|
567
|
-
"""manifest 段:落安装名册(版本/来源/归因/落点指纹),并给出 key
|
|
568
|
-
配置提示。名册对账口径见各字段注释(原 cmd_install 尾段,整段平移)。"""
|
|
569
|
-
bi = json.loads((ROOT / "build-info.json").read_text(encoding="utf-8"))
|
|
570
|
-
manifest = {
|
|
571
|
-
"version": bi["version"],
|
|
572
|
-
"source": {"type": "git", "remote": bi["sourceRemote"],
|
|
573
|
-
"ref": subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"],
|
|
574
|
-
cwd=ROOT, capture_output=True, text=True).stdout.strip(),
|
|
575
|
-
"commitSha": bi["commitSha"]},
|
|
576
|
-
"target": target,
|
|
577
|
-
# 传输形态(D-attach-1):stdio=宿主本机拉起进程;remote=指向单独部署的
|
|
578
|
-
# 远程端点;skills-only=只装技能(MCP 由别处注册)
|
|
579
|
-
"transport": transport,
|
|
580
|
-
"mcpUrl": mcp_url or None,
|
|
581
|
-
"installedAt": datetime.datetime.now().isoformat(timespec="seconds"),
|
|
582
|
-
"preset": args.preset,
|
|
583
|
-
"distribution": getattr(args, "distribution", "devkit"),
|
|
584
|
-
"product": bound_product,
|
|
585
|
-
"packs": packs,
|
|
586
|
-
"dshProfile": (getattr(args, "dsh_profile", "") or "").strip() or None,
|
|
587
|
-
# dsh 修复用(S60/A 止血):patch 块被 dsh 运行时序列化冲掉后,
|
|
588
|
-
# doctor 可凭 product/apiBase 重建(块内容=安装期静态部署值)
|
|
589
|
-
"apiBase": (getattr(args, "java_api_base", "") or "") or None,
|
|
590
|
-
"mcpConfig": (str(mcp_conf) if mcp_conf else None),
|
|
591
|
-
"skillsDir": str(HERMES_SKILLS_DIR),
|
|
592
|
-
# 名册对账(huaweicloud-devkit doctor 模式借鉴,2026-11-06):
|
|
593
|
-
# 每个原生技能落点的独立指纹——漏装/漂移可被 doctor 逐落点抓出,
|
|
594
|
-
# 不再只盯 hermes 单目录(opencode 漏拷静默失效的针对性防线)。
|
|
595
|
-
# 多宿主并集合并:manifest 按「最近一次安装」覆盖会互相冲掉落点
|
|
596
|
-
# (实锤:codex 装完 opencode 落点消失),按 host+dir 去重保留历史
|
|
597
|
-
"skillInstalls": _skill_installs(manifest_path(), extra_dirs),
|
|
598
|
-
"skillHashes": _skill_hashes(),
|
|
599
|
-
# 载荷副本(D-payload-1):宿主入口指向这里,而不是仓/npx 缓存路径
|
|
600
|
-
"payloadDir": str(payload_dir) if payload_dir else None,
|
|
601
|
-
}
|
|
602
|
-
row = {k: manifest[k] for k in
|
|
603
|
-
("target", "transport", "mcpUrl", "installedAt", "product", "packs",
|
|
604
|
-
"dshProfile", "apiBase", "mcpConfig", "skillsDir", "payloadDir")}
|
|
605
|
-
row["version"] = manifest["version"]
|
|
606
|
-
row["commitSha"] = manifest["source"]["commitSha"]
|
|
607
|
-
row["skillInstalls"] = [si for si in manifest["skillInstalls"]
|
|
608
|
-
if si["host"] == target]
|
|
609
|
-
prev = _read_manifest()
|
|
610
|
-
manifest["installs"] = _install_rows(prev, row)
|
|
611
|
-
manifest_path().write_text(json.dumps(manifest, ensure_ascii=False, indent=2),
|
|
612
|
-
encoding="utf-8")
|
|
613
|
-
print("installed:", json.dumps(manifest, ensure_ascii=False, indent=2))
|
|
614
|
-
missing = [k for k in ("VOD_JAVA_API_KEY",) if
|
|
615
|
-
not os.environ.get(k) and not _runtime_cfg_read().get("java_key")]
|
|
616
|
-
if missing and transport == "stdio":
|
|
617
|
-
print(f"提示:{missing} 未配置——首次提交将自动申请零字段匿名令牌(无需配置)")
|
|
618
|
-
elif transport == "remote":
|
|
619
|
-
print("远程形态提示:身份随请求头走(token 已由宿主配置承载);"
|
|
620
|
-
"本机 runtime.json 的匿名链不参与远程提交")
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
def _runtime_cfg_read() -> dict:
|
|
624
|
-
p = ROOT / "vod_mcp" / "runtime.json"
|
|
625
|
-
if p.exists():
|
|
626
|
-
try:
|
|
627
|
-
return json.loads(p.read_text(encoding="utf-8"))
|
|
628
|
-
except Exception:
|
|
629
|
-
return {}
|
|
630
|
-
return {}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
def cmd_status(_args):
|
|
635
|
-
p = manifest_path()
|
|
636
|
-
if not p.exists():
|
|
637
|
-
print("未安装(无 install-manifest)")
|
|
638
|
-
sys.exit(1)
|
|
639
|
-
# golden 稳定性:apiBase 含安装期动态值(本地验证实例端口),归一化后输出
|
|
640
|
-
text = p.read_text(encoding="utf-8")
|
|
641
|
-
text = re.sub(r'"apiBase": "http://127\.0\.0\.1:\d+"',
|
|
642
|
-
'"apiBase": "http://127.0.0.1:<PORT>"', text)
|
|
643
|
-
# 载荷路径含 HOME/版本,按 <PAYLOAD> 归一(golden 不随环境漂)
|
|
644
|
-
text = re.sub(r'"payloadDir": ".*?/payloads/[^"]+"',
|
|
645
|
-
'"payloadDir": "<PAYLOAD>"', text)
|
|
646
|
-
print(text)
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
def _repair_dsh_patch_block(mf: dict) -> str | None:
|
|
650
|
-
"""doctor 自愈(S58/A):profile cordis.patch.yml 的 vod-devkit 块缺失或
|
|
651
|
-
打平(未缩进在 - insert: 之下)时,按 manifest 的 product/apiBase 重建
|
|
652
|
-
正确嵌套块。返回修复的文件路径;块完好返回 None。
|
|
653
|
-
|
|
654
|
-
嵌套铁律(真机实锤):id/name/config 必须缩进在 `- insert:` 之下——
|
|
655
|
-
dsh 的配置序列化只保留它能识别的块,手工游离块会被下次写盘冲掉。
|
|
656
|
-
"""
|
|
657
|
-
prof = mf["dshProfile"]
|
|
658
|
-
patch = Path(host_specs.load("dsh", prof)["configPath"])
|
|
659
|
-
if not patch.exists():
|
|
660
|
-
return None
|
|
661
|
-
from vod_mcp import config_forms as cf
|
|
662
|
-
lines = patch.read_text(encoding="utf-8").splitlines()
|
|
663
|
-
try:
|
|
664
|
-
verdict, reason = cf.classify_dsh_patch(lines)
|
|
665
|
-
except cf.Refused as e:
|
|
666
|
-
verdict, reason = "refuse", str(e)
|
|
667
|
-
if verdict == "refuse":
|
|
668
|
-
# 自愈也不越界:文件形态未知时只报告,不动字节
|
|
669
|
-
print(f"[doctor] skip(cordis.patch.yml 形态不受支持,未自愈):{reason}",
|
|
670
|
-
file=sys.stderr)
|
|
671
|
-
return None
|
|
672
|
-
vod_idx = next((i for i, ln in enumerate(lines)
|
|
673
|
-
if ln.strip().startswith("- id: vod-devkit")), None)
|
|
674
|
-
if vod_idx is not None and lines[vod_idx].startswith((" ", "\t")):
|
|
675
|
-
# 已嵌套且在 insert 组内(简化判定:缩进+前文存在 - insert: 行)→ 完好
|
|
676
|
-
has_insert = any(ln.strip() == "- insert:" for ln in lines[:vod_idx])
|
|
677
|
-
has_name = any("name: dsh-vod-devkit" in ln
|
|
678
|
-
for ln in lines[vod_idx:vod_idx + 3])
|
|
679
|
-
if has_insert and has_name:
|
|
680
|
-
return None
|
|
681
|
-
# 需要重建:先摘除旧块(块边界=下一个 `- ` 群组项,任何缩进),再追加正确嵌套组
|
|
682
|
-
if vod_idx is not None:
|
|
683
|
-
end = next((j for j in range(vod_idx + 1, len(lines))
|
|
684
|
-
if lines[j].strip().startswith("- ")), len(lines))
|
|
685
|
-
del lines[vod_idx:end]
|
|
686
|
-
if lines and lines[-1].strip():
|
|
687
|
-
lines.append("")
|
|
688
|
-
product = mf.get("product") or ""
|
|
689
|
-
api_base = mf.get("apiBase") or ""
|
|
690
|
-
lines += [
|
|
691
|
-
"- insert:",
|
|
692
|
-
" - id: vod-devkit",
|
|
693
|
-
" name: dsh-vod-devkit",
|
|
694
|
-
" config:",
|
|
695
|
-
f" product: {product}",
|
|
696
|
-
f" apiBase: {api_base}",
|
|
697
|
-
f" uiBase: {api_base}", # D-uiBase-direct:浏览器半直连,与 install 同口径
|
|
698
|
-
]
|
|
699
|
-
patch.write_text("\n".join(lines).rstrip("\n") + "\n", encoding="utf-8")
|
|
700
|
-
return str(patch)
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
def _render_problems(problems) -> str:
|
|
704
|
-
"""分层报告(对表 devkit 的 doctor-report):按 环境/载荷/配置/技能/网络/插件 分组,
|
|
705
|
-
每条失败给「原因」与「动作」,避免运维只看到一堆 FAIL 文案。"""
|
|
706
|
-
from vod_mcp import diagnose
|
|
707
|
-
return diagnose.render_problems(problems)
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
def cmd_explain(args):
|
|
711
|
-
"""解释一条失败文案/错误码(-32010 等):给层 + 原因 + 动作。"""
|
|
712
|
-
from vod_mcp import diagnose
|
|
713
|
-
text = " ".join(args.text).strip()
|
|
714
|
-
if not text:
|
|
715
|
-
print("用法:vod-devkit explain '<错误文案或错误码>'", file=sys.stderr)
|
|
716
|
-
sys.exit(2)
|
|
717
|
-
info = diagnose.explain(text)
|
|
718
|
-
if not info["known"]:
|
|
719
|
-
print(f"未收录该问题:{text[:120]}", file=sys.stderr)
|
|
720
|
-
print(" 排查入口:doctor 看分层报告;仍无头绪就把这段文案连同 doctor 输出一起贴出来",
|
|
721
|
-
file=sys.stderr)
|
|
722
|
-
sys.exit(2)
|
|
723
|
-
print(f"层:{info['layer']}")
|
|
724
|
-
print(f"原因:{info['cause']}")
|
|
725
|
-
print(f"动作:{info['action']}")
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
def cmd_detect(args):
|
|
729
|
-
"""只读识别项目语言/框架/构建(给采集端补上下文;不写任何文件)。"""
|
|
730
|
-
from vod_mcp import detect_framework
|
|
731
|
-
try:
|
|
732
|
-
info = detect_framework.detect(args.path or os.getcwd())
|
|
733
|
-
except ValueError as e:
|
|
734
|
-
print(str(e), file=sys.stderr)
|
|
735
|
-
sys.exit(2)
|
|
736
|
-
print(json.dumps(info, ensure_ascii=False, indent=2))
|
|
737
|
-
print("摘要:" + detect_framework.summary_line(info))
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
def cmd_doctor(_args):
|
|
741
|
-
problems = []
|
|
742
|
-
p = manifest_path()
|
|
743
|
-
if not p.exists():
|
|
744
|
-
problems.append("无 install-manifest.json(未 install?)")
|
|
745
|
-
else:
|
|
746
|
-
mf = json.loads(p.read_text(encoding="utf-8"))
|
|
747
|
-
# dsh patch 块自愈(S58/A 止血,2026-11-06 真机实锤):dsh 运行时
|
|
748
|
-
# 序列化会冲掉 profile patch 里的 vod 块(配置树不含手工块)——
|
|
749
|
-
# doctor 检测缺失/打平后按 manifest 的 product/apiBase 重建嵌套块
|
|
750
|
-
if mf.get("target") == "dsh" and mf.get("dshProfile"):
|
|
751
|
-
patched = _repair_dsh_patch_block(mf)
|
|
752
|
-
if patched:
|
|
753
|
-
print(f"[doctor] 已重建 dsh patch 的 vod-devkit 块:{patched}"
|
|
754
|
-
"(重启 dsh 生效)")
|
|
755
|
-
bi = json.loads((ROOT / "build-info.json").read_text(encoding="utf-8"))
|
|
756
|
-
if mf["source"]["commitSha"] != bi.get("commitSha"):
|
|
757
|
-
problems.append("install-manifest 与 build-info 的 commitSHA 不一致")
|
|
758
|
-
if mf.get("mcpConfig") and not Path(mf["mcpConfig"]).exists():
|
|
759
|
-
problems.append("MCP 配置文件缺失")
|
|
760
|
-
if mf.get("transport") == "remote" and mf.get("mcpUrl"):
|
|
761
|
-
url = mf["mcpUrl"]
|
|
762
|
-
token = (os.environ.get("VOD_MCP_TOKEN")
|
|
763
|
-
or os.environ.get("MCP_VOD_DEVKIT_API_KEY") or "").strip()
|
|
764
|
-
try:
|
|
765
|
-
names = _probe_remote(url, token, timeout=8)
|
|
766
|
-
missing = _expected_remote_tools() - set(names)
|
|
767
|
-
if missing:
|
|
768
|
-
problems.append(f"远程面工具面不符(缺 {sorted(missing)}):{url}")
|
|
769
|
-
else:
|
|
770
|
-
print(f"[doctor] 远程面可达:{url}({len(names)} 工具)")
|
|
771
|
-
except Exception as e: # noqa: BLE001
|
|
772
|
-
if not _remote_reachable(url):
|
|
773
|
-
problems.append(f"远程 MCP 端点不可达:{url}")
|
|
774
|
-
elif not token:
|
|
775
|
-
print("[doctor] 远程端点可达,但未提供 token(401 属预期):"
|
|
776
|
-
"设 VOD_MCP_TOKEN 可验工具面")
|
|
777
|
-
else:
|
|
778
|
-
problems.append(f"远程面探活失败(带 token):{e}")
|
|
779
|
-
if not Path(mf["skillsDir"]).exists():
|
|
780
|
-
problems.append("skills 目录缺失")
|
|
781
|
-
drifted = _drifted_skills(mf)
|
|
782
|
-
if drifted:
|
|
783
|
-
problems.append("技能拷贝件与安装产物漂移(D-drift-lock):"
|
|
784
|
-
+ "、".join(drifted) + "——重跑 install 恢复")
|
|
785
|
-
# 名册对账(逐原生落点):漏装/漂移按宿主点名(借鉴 devkit doctor)
|
|
786
|
-
for si in mf.get("skillInstalls") or []:
|
|
787
|
-
d = Path(si["dir"])
|
|
788
|
-
if not d.exists():
|
|
789
|
-
problems.append(f"技能原生副本缺失({si['host']}):{d} 不存在"
|
|
790
|
-
"——重跑 install 恢复")
|
|
791
|
-
continue
|
|
792
|
-
import hashlib
|
|
793
|
-
expect = mf.get("skillHashes") or {}
|
|
794
|
-
for rel, sha in expect.items():
|
|
795
|
-
f = d / rel
|
|
796
|
-
if not f.exists():
|
|
797
|
-
problems.append(f"技能文件缺失({si['host']}):{rel}")
|
|
798
|
-
elif hashlib.sha256(f.read_bytes()).hexdigest() != sha:
|
|
799
|
-
problems.append(f"技能文件漂移({si['host']}):{rel}")
|
|
800
|
-
# 载荷(D-payload-1):MCP 入口指向副本 → 副本必须在且未被改
|
|
801
|
-
from vod_mcp import payload as _payload
|
|
802
|
-
pd = mf.get("payloadDir")
|
|
803
|
-
if pd:
|
|
804
|
-
if not Path(pd).is_dir():
|
|
805
|
-
problems.append(f"载荷目录缺失:{pd}(MCP 入口指向它,宿主起不来)——重跑 install")
|
|
806
|
-
else:
|
|
807
|
-
bad = _payload.verify(Path(pd))
|
|
808
|
-
if bad:
|
|
809
|
-
problems.append("载荷被改动:" + ";".join(bad[:5]))
|
|
810
|
-
if _payload.marker_path().exists():
|
|
811
|
-
print(f"[doctor] 载荷已换({pd})——重启宿主会话生效")
|
|
812
|
-
else:
|
|
813
|
-
print("[doctor] 提示:本次安装无载荷副本(旧版),入口指向仓内路径;重跑 install 可固化")
|
|
814
|
-
for res in _payload.residue():
|
|
815
|
-
print(f"[doctor] 载荷残留(无 payload.json):{res}——可手动删除")
|
|
816
|
-
# 旧一代 AGENTS.md 注入(2026-11-05 之前的 one-liner):教模型跳过同意 +
|
|
817
|
-
# 归因由安装绑定。实测 1705 个 codex 会话带着它 → 不动它就等于红线失效。
|
|
818
|
-
legacy_agents = Path.home() / ".codex" / "AGENTS.md"
|
|
819
|
-
if legacy_agents.exists() and "vod-submit-one-liner" in legacy_agents.read_text(
|
|
820
|
-
encoding="utf-8"):
|
|
821
|
-
problems.append(f"AGENTS.md 仍含旧一代注入(教模型跳过同意):{legacy_agents}"
|
|
822
|
-
"——重跑 install --target codex 自动清理")
|
|
823
|
-
# 路由插件副本(hermes):仓内话术改了但装机副本没刷新 → 宿主还在注入旧口径
|
|
824
|
-
# (2026-11-11 实锤:仓里已把"归因由安装绑定决定"改成"原话解析",装机副本仍是旧的)
|
|
825
|
-
rp_dst = Path.home() / ".hermes" / "plugins" / "vod-feedback-router" / "router.py"
|
|
826
|
-
rp_src = ROOT / "hermes-plugin" / "vod-feedback-router" / "router.py"
|
|
827
|
-
if rp_dst.exists() and rp_src.exists() and rp_dst.read_text(encoding="utf-8") != \
|
|
828
|
-
rp_src.read_text(encoding="utf-8"):
|
|
829
|
-
problems.append(f"路由插件副本落后于仓内:{rp_dst}(重跑 install --target hermes)")
|
|
830
|
-
# CodeArts Agent 冒烟:官方 CLI 在就 list 一次(实测通道=codearts_cli.json 的 mcp 段)
|
|
831
|
-
if mf.get("target") == "codeartsdoer" and shutil.which("codearts"):
|
|
832
|
-
r = subprocess.run(["codearts", "mcp", "list"], capture_output=True,
|
|
833
|
-
text=True, timeout=60)
|
|
834
|
-
if "vod-devkit" in (r.stdout or ""):
|
|
835
|
-
print("[doctor] CodeArts Agent 已识别 vod-devkit(codearts mcp list)")
|
|
836
|
-
else:
|
|
837
|
-
problems.append("CodeArts Agent 未列出 vod-devkit"
|
|
838
|
-
"(codearts mcp list)——检查 codearts_cli.json 的 mcp 段")
|
|
839
|
-
if problems:
|
|
840
|
-
print(_render_problems(problems))
|
|
841
|
-
sys.exit(1)
|
|
842
|
-
# key 探针(最佳努力):配置了 key 就问一次引擎,无效当场报;网络不可达只提示不 FAIL
|
|
843
|
-
#(离线环境 doctor 必须可用——网络问题不是 key 问题)
|
|
844
|
-
from vod_mcp.tools import _runtime_cfg
|
|
845
|
-
key = os.environ.get("VOD_JAVA_API_KEY") or _runtime_cfg().get("java_key")
|
|
846
|
-
if key:
|
|
847
|
-
from vod_mcp.tools import probe_key
|
|
848
|
-
chk = probe_key(key)
|
|
849
|
-
if chk["ok"] is False:
|
|
850
|
-
problems.append(f"key 无效(指纹 {chk['fingerprint']},引擎 401 拒绝)——"
|
|
851
|
-
"请核对/续期,或移除 key 走匿名档")
|
|
852
|
-
elif chk["ok"] is None:
|
|
853
|
-
print(f"warn: key 未验证(引擎不可达,指纹 {chk['fingerprint']})")
|
|
854
|
-
else:
|
|
855
|
-
print(f"key: 有效(指纹 {chk['fingerprint']})")
|
|
856
|
-
if problems:
|
|
857
|
-
print(_render_problems(problems))
|
|
858
|
-
sys.exit(1)
|
|
859
|
-
print("doctor: OK")
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
def _distribution() -> str:
|
|
863
|
-
"""分发形态位(D-key-guard-3):install --distribution 写入,构建期定死。
|
|
864
|
-
devkit=开发/运维形态(自装自管);preset=产品随 agent 分发(客户机只读)。"""
|
|
865
|
-
p = manifest_path()
|
|
866
|
-
if not p.exists():
|
|
867
|
-
return "devkit"
|
|
868
|
-
try:
|
|
869
|
-
return json.loads(p.read_text(encoding="utf-8")).get("distribution", "devkit")
|
|
870
|
-
except Exception:
|
|
871
|
-
return "devkit"
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
def cmd_verify(_args):
|
|
875
|
-
p = manifest_path()
|
|
876
|
-
if not p.exists():
|
|
877
|
-
print("未安装")
|
|
878
|
-
sys.exit(1)
|
|
879
|
-
sha = json.loads(p.read_text(encoding="utf-8"))["source"]["commitSha"]
|
|
880
|
-
if not sha:
|
|
881
|
-
print("manifest 无 commitSha(dev 构建无法核验)")
|
|
882
|
-
sys.exit(1)
|
|
883
|
-
if _distribution() == "preset":
|
|
884
|
-
# D-key-guard-3②:产品分发形态客户机无 git 源——只做本地完整性校验,
|
|
885
|
-
# 源端比对降级为 unchecked 不 FAIL(离线 verify 必须可用)
|
|
886
|
-
bi = json.loads((ROOT / "build-info.json").read_text(encoding="utf-8"))
|
|
887
|
-
if sha != bi.get("commitSha"):
|
|
888
|
-
print("FAIL: manifest 与 build-info commitSHA 不一致(安装产物被篡改/混装)")
|
|
889
|
-
sys.exit(1)
|
|
890
|
-
print("verify: OK(preset 本地完整性;源端比对 unchecked)")
|
|
891
|
-
return
|
|
892
|
-
r = subprocess.run(["git", "cat-file", "-e", f"{sha}^{{commit}}"],
|
|
893
|
-
cwd=ROOT, capture_output=True)
|
|
894
|
-
if r.returncode != 0:
|
|
895
|
-
subprocess.run(["git", "fetch", "origin"], cwd=ROOT)
|
|
896
|
-
r = subprocess.run(["git", "cat-file", "-e", f"{sha}^{{commit}}"],
|
|
897
|
-
cwd=ROOT, capture_output=True)
|
|
898
|
-
if r.returncode != 0:
|
|
899
|
-
print(f"FAIL: commit {sha} 不存在于 origin(被改写或非本仓产物)")
|
|
900
|
-
sys.exit(1)
|
|
901
|
-
print(f"verify: OK(commit {sha[:12]} 存在于本仓/origin)")
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
def cmd_update(args=None):
|
|
905
|
-
"""更新:git fetch 比较 origin/main,落后则 ff 拉取并重烧 build-info。
|
|
906
|
-
|
|
907
|
-
--skip / --clear-skip(D-devtoolchain-7,对齐 devkit update-skip 裁剪版):
|
|
908
|
-
只维护「跳过某个版本提醒」的运行时状态,不动代码——所以放在 git 拉取之前返回。
|
|
909
|
-
"""
|
|
910
|
-
if getattr(args, "skip", False) or getattr(args, "clear_skip", False):
|
|
911
|
-
from vod_mcp import update_check as uc
|
|
912
|
-
out = uc.check({"clearSkip": True} if getattr(args, "clear_skip", False)
|
|
913
|
-
else {"skip": True})
|
|
914
|
-
print(out.get("note") or "")
|
|
915
|
-
if out.get("latestVersion"):
|
|
916
|
-
print(f"latest = {out['latestVersion']}(clearSkip=true 可撤销)")
|
|
917
|
-
return
|
|
918
|
-
if _distribution() == "preset":
|
|
919
|
-
# D-key-guard-3②:产品分发形态插件版本随 agent 发版管理,客户机禁止自更新
|
|
920
|
-
#(绕过产品版本管理=未测试代码进客户现场)
|
|
921
|
-
print("产品分发形态(preset)不支持自更新:插件版本随 agent 发版管理。"
|
|
922
|
-
"如需升级请联系产品提供方发布新版本。")
|
|
923
|
-
return
|
|
924
|
-
subprocess.run(["git", "fetch", "origin", "--tags"], cwd=ROOT, capture_output=True)
|
|
925
|
-
local = subprocess.run(["git", "rev-parse", "HEAD"], cwd=ROOT,
|
|
926
|
-
capture_output=True, text=True).stdout.strip()
|
|
927
|
-
remote = subprocess.run(["git", "rev-parse", "origin/main"], cwd=ROOT,
|
|
928
|
-
capture_output=True, text=True).stdout.strip()
|
|
929
|
-
if local == remote:
|
|
930
|
-
print(f"已是最新({local[:12]})")
|
|
931
|
-
return
|
|
932
|
-
r = subprocess.run(["git", "pull", "--ff-only"], cwd=ROOT,
|
|
933
|
-
capture_output=True, text=True)
|
|
934
|
-
if r.returncode != 0:
|
|
935
|
-
print("更新失败(有本地改动阻挡 ff?):", r.stderr.strip()[:200])
|
|
936
|
-
sys.exit(1)
|
|
937
|
-
print(f"已更新 {local[:12]} → {remote[:12]}")
|
|
938
|
-
write_build_info(strict=False)
|
|
939
|
-
print("build-info 已重烧;如需重新安装执行:")
|
|
940
|
-
print(f" {sys.argv[0]} install --target hermes --preset collect --product <产品名>")
|
|
941
|
-
print(" 并重启 agent 会话")
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
# 共享用户配置文件:uninstall 只摘「我们的托管条目」,绝不删除文件
|
|
945
|
-
#(深审 P0-3 只挡了 config.toml;opencode.json 同类且更危险——里面有用户整份
|
|
946
|
-
# provider 配置。2026-11-11 远程 attach 落地时一并收口。)
|
|
947
|
-
_SHARED_CONFIG_NAMES = {"config.toml", "config.yaml", "config.yml",
|
|
948
|
-
"opencode.json", "opencode.jsonc"}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
def _remove_managed_mcp_entry(target: str, path: Path) -> None:
|
|
952
|
-
"""从宿主共享配置里摘掉 vod-devkit 条目(保留其它键/其它 server)。"""
|
|
953
|
-
section = {"opencode": "mcp", "codeartsdoer": "mcp", "codeartswork": "mcp",
|
|
954
|
-
"generic": "mcpServers", "workbuddy": "mcpServers",
|
|
955
|
-
"atomcode": "mcpServers"}.get(target)
|
|
956
|
-
if section:
|
|
957
|
-
if not path.exists():
|
|
958
|
-
return
|
|
959
|
-
try:
|
|
960
|
-
cfg = json.loads(path.read_text(encoding="utf-8"))
|
|
961
|
-
except Exception:
|
|
962
|
-
print(f"skip({path} 不是合法 JSON,未改动)")
|
|
963
|
-
return
|
|
964
|
-
block = cfg.get(section) or {}
|
|
965
|
-
if "vod-devkit" not in block:
|
|
966
|
-
return
|
|
967
|
-
block.pop("vod-devkit")
|
|
968
|
-
if not block:
|
|
969
|
-
cfg.pop(section, None)
|
|
970
|
-
else:
|
|
971
|
-
cfg[section] = block
|
|
972
|
-
path.write_text(json.dumps(cfg, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
973
|
-
print(f"removed {section}.vod-devkit: {path}")
|
|
974
|
-
return
|
|
975
|
-
cli, args = None, None
|
|
976
|
-
if target == "hermes" and shutil.which("hermes"):
|
|
977
|
-
cli, args = "hermes", ["mcp", "remove", "vod-devkit"]
|
|
978
|
-
elif target == "codex" and shutil.which("codex"):
|
|
979
|
-
cli, args = "codex", ["mcp", "remove", "vod-devkit"]
|
|
980
|
-
if cli:
|
|
981
|
-
r = subprocess.run([cli, *args], capture_output=True, text=True, timeout=120)
|
|
982
|
-
print(f"{cli} mcp remove:", "OK" if r.returncode == 0
|
|
983
|
-
else (r.stderr or r.stdout).strip()[-120:])
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
def _remove_managed_skills(mf: dict, path: Path, target: str) -> None:
|
|
987
|
-
"""技能摘除:hermes 目录是专属的(整目录删);其它宿主技能目录是**共享**的
|
|
988
|
-
(opencode ~/.config/opencode/skills 等),只摘本插件改名下的技能。
|
|
989
|
-
2026-11-11 与 uninstall 共享配置收口同批修:整目录删会连带删掉用户的其它技能。"""
|
|
990
|
-
if target == "hermes":
|
|
991
|
-
if path.exists():
|
|
992
|
-
shutil.rmtree(path)
|
|
993
|
-
print("removed:", path)
|
|
994
|
-
return
|
|
995
|
-
names = {rel.split("/")[0] for rel in (mf.get("skillHashes") or {})}
|
|
996
|
-
removed = []
|
|
997
|
-
for n in sorted(names):
|
|
998
|
-
d = path / n
|
|
999
|
-
if d.is_dir():
|
|
1000
|
-
shutil.rmtree(d)
|
|
1001
|
-
removed.append(n)
|
|
1002
|
-
print(f"removed skills: {removed}(共享目录保留):{path}") if removed \
|
|
1003
|
-
else print(f"skip(无需摘除的技能):{path}")
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
def _cleanup_install_row(row: dict, skill_hashes: dict | None = None) -> None:
|
|
1007
|
-
"""按一条安装记录清理:MCP 条目 / 技能落点 / 宿主专属产物。
|
|
1008
|
-
|
|
1009
|
-
技能名清单来自 manifest 顶层 skillHashes(各安装行共用同一份技能集合)。
|
|
1010
|
-
"""
|
|
1011
|
-
target = row.get("target")
|
|
1012
|
-
# codex-desktop:mcpConfig 指向共享的 marketplace.json,绝不能走"整文件删"分支
|
|
1013
|
-
# (那会删掉用户/其它插件的市场登记)。交给适配器只摘自己那一条 + 删插件目录。
|
|
1014
|
-
if target == "codex-desktop":
|
|
1015
|
-
from vod_mcp.host_adapters import codex_desktop as _cd
|
|
1016
|
-
_cd.uninstall()
|
|
1017
|
-
return
|
|
1018
|
-
mf = dict(row)
|
|
1019
|
-
mf["skillHashes"] = skill_hashes or {}
|
|
1020
|
-
for key in ("mcpConfig", "skillsDir"):
|
|
1021
|
-
path_s = row.get(key)
|
|
1022
|
-
if not path_s:
|
|
1023
|
-
continue # codex 等宿主 mcpConfig 可为 None(P0-3:无托管配置文件)
|
|
1024
|
-
if key == "skillsDir":
|
|
1025
|
-
_remove_managed_skills(mf, Path(path_s), target)
|
|
1026
|
-
continue
|
|
1027
|
-
path = Path(path_s)
|
|
1028
|
-
# 深审 P0-3(破坏性路径一票否决):共享用户配置永不整文件删除
|
|
1029
|
-
#(config.toml/opencode.json/codearts_cli.json/.claude.json 里有用户自己的
|
|
1030
|
-
# provider、其它 server)。JSON 合并型宿主一律走"摘条目",与文件名无关——
|
|
1031
|
-
# codearts_cli.json 第一版没进 _SHARED_CONFIG_NAMES,卸载把整份配置删了(实锤)。
|
|
1032
|
-
if target in ("opencode", "codeartsdoer", "codeartswork", "generic",
|
|
1033
|
-
"workbuddy", "atomcode") or path.name in _SHARED_CONFIG_NAMES:
|
|
1034
|
-
print(f"skip(用户配置文件,uninstall 只摘托管条目):{path}")
|
|
1035
|
-
_remove_managed_mcp_entry(target, path)
|
|
1036
|
-
continue
|
|
1037
|
-
if path.exists():
|
|
1038
|
-
shutil.rmtree(path) if path.is_dir() else path.unlink()
|
|
1039
|
-
print("removed:", path)
|
|
1040
|
-
# codex 摘除:remote 形态摘 MCP 条目;stdio 形态摘原生插件(best-effort)
|
|
1041
|
-
if target == "codex":
|
|
1042
|
-
codex = shutil.which("codex")
|
|
1043
|
-
if codex and (row.get("transport") or "stdio") == "remote":
|
|
1044
|
-
_remove_managed_mcp_entry("codex", Path.home() / ".codex" / "config.toml")
|
|
1045
|
-
elif codex:
|
|
1046
|
-
r = subprocess.run([codex, "plugin", "remove", "vod-devkit@vod-local"],
|
|
1047
|
-
capture_output=True, text=True, timeout=120)
|
|
1048
|
-
print("codex plugin remove:",
|
|
1049
|
-
"OK" if r.returncode == 0 else (r.stderr or r.stdout).strip()[-120:])
|
|
1050
|
-
# opencode 随装生成物(/vod-doctor 命令)
|
|
1051
|
-
if target == "opencode":
|
|
1052
|
-
for g in host_specs.load("opencode")["generated"]:
|
|
1053
|
-
gen = Path(g["dest"])
|
|
1054
|
-
if gen.exists():
|
|
1055
|
-
gen.unlink()
|
|
1056
|
-
print("removed:", gen)
|
|
1057
|
-
# dsh 壳(D-dsh-install-1):摘插件 + 从 profile patch 移除 config 段
|
|
1058
|
-
if target == "dsh":
|
|
1059
|
-
dsh = shutil.which("dsh")
|
|
1060
|
-
prof = (row.get("dshProfile") or "").strip()
|
|
1061
|
-
if dsh and prof:
|
|
1062
|
-
subprocess.run([dsh, "plugin", "--profile", prof, "remove",
|
|
1063
|
-
"dsh-vod-devkit"], capture_output=True, text=True)
|
|
1064
|
-
if prof: # 无 profile 记录=没写过 patch,无需(也无法)摘除
|
|
1065
|
-
patch_path = Path(host_specs.load("dsh", prof)["configPath"])
|
|
1066
|
-
from vod_mcp.host_adapters import dsh as dsh_adapter
|
|
1067
|
-
if dsh_adapter.remove_patch_block(patch_path):
|
|
1068
|
-
print("removed vod-devkit config block:", patch_path)
|
|
1069
|
-
# codeartsdoer / opencode / generic 共用 JSON 配置:条目已在上面按 mcpConfig 摘除
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
def cmd_uninstall(_args):
|
|
1073
|
-
p = manifest_path()
|
|
1074
|
-
if not p.exists():
|
|
1075
|
-
print("未安装")
|
|
1076
|
-
return
|
|
1077
|
-
mf = json.loads(p.read_text(encoding="utf-8"))
|
|
1078
|
-
rows = mf.get("installs") or [mf] # 老 manifest(无 installs[])退化为单条
|
|
1079
|
-
for row in rows:
|
|
1080
|
-
_cleanup_install_row(row, mf.get("skillHashes"))
|
|
1081
|
-
# 载荷清理(D-payload-1):所有安装记录共用的副本,逐目录去重后删,再删 marker
|
|
1082
|
-
from vod_mcp import payload as _payload
|
|
1083
|
-
seen = set()
|
|
1084
|
-
for row in rows:
|
|
1085
|
-
pd = row.get("payloadDir")
|
|
1086
|
-
if not pd or pd in seen:
|
|
1087
|
-
continue
|
|
1088
|
-
seen.add(pd)
|
|
1089
|
-
if Path(pd).is_dir():
|
|
1090
|
-
shutil.rmtree(pd, ignore_errors=True)
|
|
1091
|
-
print("removed payload:", pd)
|
|
1092
|
-
try:
|
|
1093
|
-
_payload.marker_path().unlink(missing_ok=True)
|
|
1094
|
-
except Exception:
|
|
1095
|
-
pass
|
|
1096
|
-
p.unlink()
|
|
1097
|
-
print("removed:", p)
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
def main():
|
|
1101
|
-
# `serve` 后的参数整体透传给 MCP server(argparse 的 REMAINDER 会把
|
|
1102
|
-
# --transport 当成未知参数拦下,devkit 的二进制本身就是 server,同形处理)
|
|
1103
|
-
if len(sys.argv) > 1 and sys.argv[1] == "serve":
|
|
1104
|
-
os.execv(sys.executable,
|
|
1105
|
-
[sys.executable, str(ROOT / "vod_mcp" / "server.py"), *sys.argv[2:]])
|
|
1106
|
-
ap = argparse.ArgumentParser(prog="vod-devkit")
|
|
1107
|
-
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
1108
|
-
sp = sub.add_parser("install")
|
|
1109
|
-
sp.add_argument("--target", default="auto",
|
|
1110
|
-
help="hermes|opencode|codeartsdoer|codeartswork|codex|codex-desktop|dsh|workbuddy|atomcode|generic|auto(默认探测)")
|
|
1111
|
-
sp.add_argument("--preset", default="collect", choices=list(PRESETS),
|
|
1112
|
-
help="collect=对外默认(采集者);full=内部全量")
|
|
1113
|
-
sp.add_argument("--api-base", default="http://127.0.0.1:8000")
|
|
1114
|
-
sp.add_argument("--java-api-base", default=None,
|
|
1115
|
-
help="VOD 平台地址(缺省=https://vod-dev.topxtopx.com,勿用回环默认)")
|
|
1116
|
-
sp.add_argument("--packs", default="", help="显式覆盖 preset(逗号分隔)")
|
|
1117
|
-
sp.add_argument("--ack-suspension", action="store_true",
|
|
1118
|
-
help="确认解除 codex 采集熔断(恢复门禁逃生口,D-codex-circuit-breaker-1)")
|
|
1119
|
-
sp.add_argument("--product", default="",
|
|
1120
|
-
help="归因绑定:本 agent 服务的产品(codearts/aishell 等;采集反馈默认归属)")
|
|
1121
|
-
sp.add_argument("--distribution", default="devkit", choices=["devkit", "preset"],
|
|
1122
|
-
help="devkit=开发/运维自装(默认);preset=产品随 agent 分发(禁 key 随包/"
|
|
1123
|
-
"禁自更新/客户机首启重生成状态)")
|
|
1124
|
-
sp.add_argument("--profile", dest="dsh_profile", default="",
|
|
1125
|
-
help="dsh 专用:profile 名(--target dsh 时必填)")
|
|
1126
|
-
sp.add_argument("--mcp-url", default="",
|
|
1127
|
-
help="远程 attach 模式:宿主 MCP 配置指向该 Streamable HTTP 端点"
|
|
1128
|
-
"(hermes/opencode/codex 支持;dsh 不走 MCP)")
|
|
1129
|
-
sp.add_argument("--mcp-token", default="",
|
|
1130
|
-
help="远程 attach 的身份(也可用 env VOD_MCP_TOKEN):远程面不代签身份,"
|
|
1131
|
-
"缺 token 拒绝安装")
|
|
1132
|
-
sp.add_argument("--mcp-config", default="",
|
|
1133
|
-
help="通用宿主(--target generic)的 MCP 配置文件路径;不给则只打印可粘贴片段")
|
|
1134
|
-
sp.add_argument("--skills-only", action="store_true",
|
|
1135
|
-
help="只装技能,不动宿主 MCP 配置(MCP 已由别处/手工注册时用)")
|
|
1136
|
-
sp.add_argument("--no-local-ledger", action="store_true",
|
|
1137
|
-
help="关闭本地提交账本(企业数据驻留要求;vod_list_submitted 将不可用)")
|
|
1138
|
-
sp.set_defaults(fn=cmd_install)
|
|
1139
|
-
for name, fn in (("status", cmd_status), ("doctor", cmd_doctor),
|
|
1140
|
-
("verify", cmd_verify), ("update", cmd_update),
|
|
1141
|
-
("uninstall", cmd_uninstall),
|
|
1142
|
-
("explain", cmd_explain),
|
|
1143
|
-
("detect", cmd_detect)):
|
|
1144
|
-
s = sub.add_parser(name)
|
|
1145
|
-
if name == "explain":
|
|
1146
|
-
s.add_argument("text", nargs="+", help="错误文案或错误码(-32010 等)")
|
|
1147
|
-
if name == "detect":
|
|
1148
|
-
s.add_argument("--path", default="", help="要识别的项目目录(默认当前目录)")
|
|
1149
|
-
if name == "update":
|
|
1150
|
-
s.add_argument("--skip", action="store_true",
|
|
1151
|
-
help="跳过当前 registry latest 的提醒(只压这一个版本,"
|
|
1152
|
-
"下个版本仍提醒;不提供永久静音)")
|
|
1153
|
-
s.add_argument("--clear-skip", action="store_true",
|
|
1154
|
-
help="撤销版本跳过设置,恢复正常提醒")
|
|
1155
|
-
s.set_defaults(fn=fn)
|
|
1156
|
-
sub.add_parser("build-info").set_defaults(fn=lambda a: write_build_info(strict=False))
|
|
1157
|
-
|
|
1158
|
-
def _serve(a):
|
|
1159
|
-
"""MCP server 入口(codex 插件 .mcp.json 与远程面共用)。
|
|
13
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
1160
14
|
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
extra = list(getattr(a, "server_args", []) or [])
|
|
1165
|
-
os.execv(sys.executable,
|
|
1166
|
-
[sys.executable, str(ROOT / "vod_mcp" / "server.py"), *extra])
|
|
1167
|
-
sp_serve = sub.add_parser("serve", help="启动 MCP server(默认 stdio;"
|
|
1168
|
-
"--transport remote 起 Streamable HTTP)")
|
|
1169
|
-
sp_serve.add_argument("server_args", nargs=argparse.REMAINDER,
|
|
1170
|
-
help="透传给 vod_mcp.server(如 --transport remote --port 9528)")
|
|
1171
|
-
sp_serve.set_defaults(fn=_serve)
|
|
1172
|
-
args = ap.parse_args()
|
|
1173
|
-
args.fn(args)
|
|
15
|
+
from vodkit_cli import main # noqa: E402
|
|
16
|
+
from vodkit_cli.common import PRESETS, build_info, write_build_info # noqa: E402
|
|
17
|
+
from vodkit_cli.install import detect_targets # noqa: E402
|
|
1174
18
|
|
|
19
|
+
# 对外稳定面(测试按路径加载本文件后直接取这几个名字;pyflakes 认 __all__)
|
|
20
|
+
__all__ = ["main", "PRESETS", "detect_targets", "build_info", "write_build_info"]
|
|
1175
21
|
|
|
1176
22
|
if __name__ == "__main__":
|
|
1177
23
|
main()
|