vod-devkit 0.4.4 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/QUICKSTART.md +1 -1
  3. package/README.en.md +190 -56
  4. package/README.md +210 -56
  5. package/bin/vod-devkit +502 -460
  6. package/contract/tools.schema.json +114 -7
  7. package/integrations/codeartsdoer/host.json +11 -0
  8. package/integrations/codex/host.json +20 -0
  9. package/integrations/dsh/host.json +15 -0
  10. package/integrations/hermes/host.json +20 -0
  11. package/integrations/opencode/command/vod-doctor.md +10 -0
  12. package/integrations/opencode/host.json +28 -0
  13. package/package.json +13 -10
  14. package/plugins/vod-devkit/.codex-plugin/plugin.json +1 -1
  15. package/plugins/vod-devkit/build-info.json +3 -3
  16. package/plugins/vod-devkit/skills/vod-core/SKILL.md +43 -15
  17. package/plugins/vod-devkit/skills/vod-core/references/acceptance-criteria.md +9 -0
  18. package/plugins/vod-devkit/skills/vod-core/references/verification-method.md +29 -0
  19. package/plugins/vod-devkit/skills/vod-feedback-collect/SKILL.md +57 -11
  20. package/plugins/vod-devkit/skills/vod-feedback-collect/references/acceptance-criteria.md +28 -0
  21. package/plugins/vod-devkit/skills/vod-feedback-collect/references/verification-method.md +31 -0
  22. package/plugins/vod-devkit/skills/vod-problem-classification-rules/SKILL.md +3 -1
  23. package/plugins/vod-devkit/skills/vod-scoring-rules/SKILL.md +22 -1
  24. package/plugins/vod-devkit/vod_mcp/__init__.py +1 -1
  25. package/plugins/vod-devkit/vod_mcp/attribution.py +378 -0
  26. package/plugins/vod-devkit/vod_mcp/config_forms.py +154 -0
  27. package/plugins/vod-devkit/vod_mcp/guardrails.py +25 -0
  28. package/plugins/vod-devkit/vod_mcp/host_adapters/__init__.py +26 -0
  29. package/plugins/vod-devkit/vod_mcp/host_adapters/base.py +73 -0
  30. package/plugins/vod-devkit/vod_mcp/host_adapters/codearts.py +57 -0
  31. package/plugins/vod-devkit/vod_mcp/host_adapters/codex.py +209 -0
  32. package/plugins/vod-devkit/vod_mcp/host_adapters/dsh.py +176 -0
  33. package/plugins/vod-devkit/vod_mcp/host_adapters/generic.py +132 -0
  34. package/plugins/vod-devkit/vod_mcp/host_adapters/hermes.py +76 -0
  35. package/plugins/vod-devkit/vod_mcp/host_adapters/opencode.py +52 -0
  36. package/plugins/vod-devkit/vod_mcp/hosts.py +100 -0
  37. package/plugins/vod-devkit/vod_mcp/packs.py +19 -3
  38. package/plugins/vod-devkit/vod_mcp/payload.py +174 -0
  39. package/plugins/vod-devkit/vod_mcp/remote_app.py +100 -0
  40. package/plugins/vod-devkit/vod_mcp/server.py +43 -16
  41. package/plugins/vod-devkit/vod_mcp/skills_registry.py +124 -0
  42. package/plugins/vod-devkit/vod_mcp/tools.py +455 -55
  43. package/plugins/vod-devkit/vod_mcp/transport_remote.py +289 -0
  44. package/plugins/vod-devkit/vod_mcp/update_check.py +133 -0
  45. package/skills/vod-core/SKILL.md +43 -15
  46. package/skills/vod-core/references/acceptance-criteria.md +9 -0
  47. package/skills/vod-core/references/verification-method.md +29 -0
  48. package/skills/vod-feedback-collect/SKILL.md +57 -11
  49. package/skills/vod-feedback-collect/references/acceptance-criteria.md +28 -0
  50. package/skills/vod-feedback-collect/references/verification-method.md +31 -0
  51. package/skills/vod-problem-classification-rules/SKILL.md +3 -1
  52. package/skills/vod-scoring-rules/SKILL.md +22 -1
  53. package/vod_mcp/__init__.py +1 -1
  54. package/vod_mcp/attribution.py +378 -0
  55. package/vod_mcp/config_forms.py +154 -0
  56. package/vod_mcp/guardrails.py +25 -0
  57. package/vod_mcp/host_adapters/__init__.py +26 -0
  58. package/vod_mcp/host_adapters/__pycache__/__init__.cpython-314.pyc +0 -0
  59. package/vod_mcp/host_adapters/__pycache__/base.cpython-314.pyc +0 -0
  60. package/vod_mcp/host_adapters/__pycache__/codearts.cpython-314.pyc +0 -0
  61. package/vod_mcp/host_adapters/__pycache__/codex.cpython-314.pyc +0 -0
  62. package/vod_mcp/host_adapters/__pycache__/dsh.cpython-314.pyc +0 -0
  63. package/vod_mcp/host_adapters/__pycache__/generic.cpython-314.pyc +0 -0
  64. package/vod_mcp/host_adapters/__pycache__/hermes.cpython-314.pyc +0 -0
  65. package/vod_mcp/host_adapters/__pycache__/opencode.cpython-314.pyc +0 -0
  66. package/vod_mcp/host_adapters/base.py +73 -0
  67. package/vod_mcp/host_adapters/codearts.py +57 -0
  68. package/vod_mcp/host_adapters/codex.py +209 -0
  69. package/vod_mcp/host_adapters/dsh.py +176 -0
  70. package/vod_mcp/host_adapters/generic.py +132 -0
  71. package/vod_mcp/host_adapters/hermes.py +76 -0
  72. package/vod_mcp/host_adapters/opencode.py +52 -0
  73. package/vod_mcp/hosts.py +100 -0
  74. package/vod_mcp/packs.py +19 -3
  75. package/vod_mcp/payload.py +174 -0
  76. package/vod_mcp/remote_app.py +100 -0
  77. package/vod_mcp/server.py +43 -16
  78. package/vod_mcp/skills_registry.py +124 -0
  79. package/vod_mcp/tools.py +455 -55
  80. package/vod_mcp/transport_remote.py +289 -0
  81. package/vod_mcp/update_check.py +133 -0
@@ -0,0 +1,26 @@
1
+ """宿主适配注册表(数据驱动分派)。
2
+
3
+ 加宿主 = 一个模块 + REGISTRY 一行;bin/vod-devkit 不再出现宿主分支
4
+ (对标 huaweicloud-devkit 的 agents/<id>.ts + switch 分派形态)。
5
+
6
+ REGISTRY 里的模块必须实现 protocol 的三件事:install / install_remote / skills_dir。
7
+ """
8
+ from vod_mcp.host_adapters import codearts, codex, dsh, generic, hermes, opencode
9
+
10
+ REGISTRY = {
11
+ "hermes": hermes,
12
+ "opencode": opencode,
13
+ "codeartsdoer": codearts,
14
+ "codex": codex,
15
+ "dsh": dsh,
16
+ "generic": generic,
17
+ }
18
+
19
+
20
+ def get(target: str):
21
+ """未知宿主抛 KeyError(调用方给"不支持目标"提示,不许静默降级)。"""
22
+ return REGISTRY[target]
23
+
24
+
25
+ def modules() -> dict:
26
+ return dict(REGISTRY)
@@ -0,0 +1,73 @@
1
+ """宿主适配公共件:MCP server 入口、环境与 JSON 配置合并(各宿主共用)。"""
2
+ import json
3
+ import os
4
+ import shutil
5
+ from pathlib import Path
6
+
7
+ ROOT = Path(__file__).resolve().parent.parent.parent
8
+
9
+ # 载荷目录(bin 在 install 前用 payload.stage() 落好并 set_payload_dir 指过来)
10
+ _PAYLOAD_DIR = None
11
+
12
+
13
+ def set_payload_dir(path) -> None:
14
+ global _PAYLOAD_DIR
15
+ _PAYLOAD_DIR = Path(path) if path else None
16
+
17
+
18
+ def payload_dir():
19
+ return _PAYLOAD_DIR
20
+
21
+
22
+ def server_entry() -> str:
23
+ """MCP server 绝对路径:优先载荷副本(npx 缓存被清也不会掉线),否则仓内。"""
24
+ base = _PAYLOAD_DIR or ROOT
25
+ return str(Path(base) / "vod_mcp" / "server.py")
26
+
27
+
28
+ def server_env(args, packs: str) -> dict:
29
+ # 无 key 不写空串(空串会让探针/严格解析器误当字面值;运行时空=未设置,
30
+ # 自动兜底 runtime.json java_key 或首提申请匿名令牌)
31
+ env = {"VOD_PACKS": packs,
32
+ "VOD_JAVA_API_BASE": args.java_api_base}
33
+ key = os.environ.get("VOD_JAVA_API_KEY", "")
34
+ if key:
35
+ env["VOD_JAVA_API_KEY"] = key
36
+ return env
37
+
38
+
39
+ def merge_json_mcp(path: Path, entry: dict, section: str = "mcp",
40
+ name: str = "vod-devkit", backup: bool = True) -> str:
41
+ """读写共享 JSON 配置里的 <section>.<name> 条目(保留其它键/其它 server)。
42
+
43
+ 返回 created / updated / unchanged;文件不是合法 JSON 时抛 RuntimeError
44
+ (调用方拒绝安装,字节不动)。共享配置文件首改落 .bak。
45
+ """
46
+ cfg = {}
47
+ existed = path.exists()
48
+ if existed:
49
+ raw = path.read_text(encoding="utf-8")
50
+ if raw.strip():
51
+ try:
52
+ parsed = json.loads(raw)
53
+ except json.JSONDecodeError as e:
54
+ raise RuntimeError(f"{path} 不是合法 JSON({e.msg}),拒绝改动") from e
55
+ if not isinstance(parsed, dict):
56
+ raise RuntimeError(f"{path} 顶层不是对象,拒绝改动")
57
+ cfg = parsed
58
+ block = cfg.get(section)
59
+ if block is None:
60
+ block = {}
61
+ elif not isinstance(block, dict):
62
+ raise RuntimeError(f"{path} 的 {section} 不是对象,拒绝改动")
63
+ if block.get(name) == entry:
64
+ return "unchanged"
65
+ action = "updated" if block.get(name) else "created"
66
+ if existed and backup:
67
+ shutil.copyfile(path, str(path) + ".bak")
68
+ block[name] = entry
69
+ cfg[section] = block
70
+ path.parent.mkdir(parents=True, exist_ok=True)
71
+ path.write_text(json.dumps(cfg, ensure_ascii=False, indent=2) + "\n",
72
+ encoding="utf-8")
73
+ return action
@@ -0,0 +1,57 @@
1
+ """CodeArts Agent 宿主适配(实测 2026-11-11)。
2
+
3
+ CodeArts Agent 是 OpenCode 的分支(安装壳导出 SCENARIO=codeartsdoer、
4
+ OPENCODE_CONFIG=~/.codeartsdoer/codearts_cli.json、KERNEL_CONFIG_DIR=~/.codeartsdoer),
5
+ 所以配置形态与 opencode 同 schema:`mcp.<name> = {type:"local", command:[...], enabled}`。
6
+
7
+ 现场实测(本机 codearts 已装,286MB 二进制):
8
+ - 往 ~/.codeartsdoer/codearts_cli.json 写 mcp.vod-probe → `codearts mcp list`
9
+ 输出 "● ○ vod-probe disabled / python3 -c pass" → 通道有效,已还原。
10
+ - `codearts mcp add` 没有任何参数(交互式向导)→ 程序化只能写 JSON,再用
11
+ `codearts mcp list` 冒烟。
12
+ - mcp_settings.json 只对**项目级** `<project>/.codeartsdoer/mcp/mcp_settings.json`
13
+ 生效(二进制:`.${SCENARIO}/mcp/mcp_settings.json`);用户级读
14
+ `~/.config/opencode/mcp/mcp_settings.json` —— 写 ~/.codeartsdoer/mcp/ 无效。
15
+ - 技能目录 ~/.codeartsdoer/skills(二进制字符串 "codeartsdoer/skills/")。
16
+ """
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 merge_json_mcp, server_env, server_entry
22
+
23
+ HOST = "codeartsdoer"
24
+ SUPPORTS_REMOTE = True
25
+
26
+
27
+ def _spec() -> dict:
28
+ """每次现读:host.json 的 ~ 相对 HOME 解析必须在调用期做(测试可重定向 HOME)。"""
29
+ return host_specs.load("codeartsdoer")
30
+
31
+
32
+ def skills_dir(args):
33
+ d = _spec().get("skillsDir")
34
+ return Path(d) if d else None
35
+
36
+
37
+ def install(args, packs):
38
+ """写 codearts_cli.json 的 mcp.vod-devkit(无损合并,保留 provider/model 等键)。"""
39
+ conf = Path(_spec()["configPath"])
40
+ entry = {
41
+ "type": "local",
42
+ "command": [sys.executable, server_entry()],
43
+ "enabled": True,
44
+ "environment": server_env(args, packs),
45
+ }
46
+ action = merge_json_mcp(conf, entry)
47
+ print(f"已写入 CodeArts Agent 配置({action}):{conf}(重启 codearts 会话生效)")
48
+ return conf
49
+
50
+
51
+ def install_remote(args, url, token):
52
+ conf = Path(_spec()["configPath"])
53
+ entry = {"type": "remote", "url": url, "enabled": True,
54
+ "headers": {"Authorization": f"Bearer {token}"}}
55
+ action = merge_json_mcp(conf, entry)
56
+ print(f"已写入 CodeArts Agent 远程 MCP({action}):{conf}(token 明文,注意文件权限)")
57
+ return conf
@@ -0,0 +1,209 @@
1
+ """Codex 宿主适配(D-codex-agents-1 终态):原生插件路径 + 历史遗留清理。"""
2
+ import json
3
+ import shutil
4
+ import subprocess
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ from vod_mcp import hosts as host_specs
9
+ from vod_mcp.host_adapters.base import ROOT
10
+
11
+ HOST = "codex"
12
+ SUPPORTS_REMOTE = True
13
+ _AGENTS_MARKER_BEGIN = "<!-- vod-devkit:feedback-skill BEGIN -->"
14
+ # 更早一代注入(2026-11-05 之前):AGENTS.md 里教模型"立即提交 confirmed=true、
15
+ # 不要追问、归因由安装绑定"——与现行红线(先征得同意、归因从原话解析)矛盾,
16
+ # 且 1705 个历史会话带着它跑(实测)。清理逻辑必须认这个标记,否则残留继续生效。
17
+ _LEGACY_ONE_LINER = "<!-- vod-submit-one-liner -->"
18
+ _AGENTS_MARKER_END = "<!-- vod-devkit:feedback-skill END -->"
19
+ _SPEC = host_specs.load("codex")
20
+
21
+
22
+ def skills_dir(args):
23
+ d = _SPEC.get("skillsDir")
24
+ return Path(d) if d else None
25
+
26
+
27
+ def strip_codex_vod_blocks(text: str) -> str:
28
+ """幂等剥离:删除 [mcp_servers.vod-devkit] **及其全部子表**。
29
+
30
+ 不能用行内正则截断式剥离——args = ["…"] 行内的 '[' 会让正则提前断块。
31
+ 也不能只删父表(旧实现):留下 [mcp_servers.vod-devkit.env] 在 TOML
32
+ 语义里会重建父表,装出一个没有 command 的假 server。扫描/删除语义
33
+ 统一在 vod_mcp/config_forms.py(单一实现),形态不受支持时抛
34
+ RuntimeError——调用方必须原样放弃修改。
35
+ """
36
+ from vod_mcp import config_forms as cf
37
+ try:
38
+ verdict, reason = cf.classify_codex_toml(text)
39
+ except cf.Refused as e:
40
+ raise RuntimeError(f"codex config.toml 形态不受支持:{e}") from e
41
+ if verdict == "refuse":
42
+ raise RuntimeError(f"codex config.toml 形态不受支持:{reason}")
43
+ cleaned, _removed = cf.strip_managed_toml(text)
44
+ return cleaned
45
+
46
+
47
+ def strip_legacy_one_liner(text: str) -> tuple:
48
+ """剥离旧一代 one-liner 注入块 → (new_text, changed)。
49
+
50
+ 边界取法(宁可少删不可误删):从标记行删到下一个 `<!--` 标记 / 一级标题 `# ` /
51
+ `---` 分隔线;都没有则删到 EOF。绝不动用户的其它 markdown 段。
52
+ """
53
+ lines = text.splitlines()
54
+ idx = next((i for i, ln in enumerate(lines) if ln.strip() == _LEGACY_ONE_LINER), None)
55
+ if idx is None:
56
+ return text, False
57
+ end = len(lines)
58
+ for j in range(idx + 1, len(lines)):
59
+ s = lines[j].strip()
60
+ if s.startswith("<!--") or s.startswith("# ") or s == "---":
61
+ end = j
62
+ break
63
+ out = lines[:idx] + lines[end:]
64
+ return "\n".join(out).rstrip() + ("\n" if out else ""), True
65
+
66
+
67
+ def strip_agents_vod_block(text: str) -> str:
68
+ """幂等剥离 AGENTS.md 中带标记的 vod-devkit 技能块(历史方案清理)。
69
+
70
+ P2(深审 2026-11-06):只有 BEGIN 没有 END 时不得静默吞掉文件剩余
71
+ 全部内容——抛错拒绝(调用方 exit 2 不落盘),宁可装不上不可删用户文件。
72
+ """
73
+ lines, skipping, out = text.splitlines(), False, []
74
+ for line in lines:
75
+ if line.strip() == _AGENTS_MARKER_BEGIN:
76
+ skipping = True
77
+ continue
78
+ if line.strip() == _AGENTS_MARKER_END:
79
+ skipping = False
80
+ continue
81
+ if not skipping:
82
+ out.append(line)
83
+ if skipping:
84
+ raise RuntimeError(
85
+ "AGENTS.md 存在 vod-devkit BEGIN 标记但缺失 END 标记"
86
+ "(文件可能被手动截断)——拒绝自动清理,请手动检查该文件")
87
+ return "\n".join(out).rstrip()
88
+
89
+
90
+ def install(args, packs: str) -> Path:
91
+ """Codex(D-codex-agents-1 终态):原生插件路径——
92
+ codex plugin marketplace add <仓>/plugins + plugin add vod-devkit@vod-local,
93
+ 打包 skills(渐进式按需加载的采集工作流)+ .mcp.json(vod-devkit serve)。
94
+ 历史遗留清理:旧 config.toml [mcp_servers.vod-devkit] 段与 AGENTS.md 技能块
95
+ 一并移除(与原生插件同名会双注册;AGENTS.md 方案被原生 skill 取代)。
96
+ 前置:codex CLI 与 vod-devkit 命令在 PATH(npm i -g vod-devkit ≥0.1.12)。"""
97
+ codex = shutil.which("codex")
98
+ if not codex:
99
+ print("[vod-devkit] 未找到 codex CLI,无法走原生插件安装", file=sys.stderr)
100
+ sys.exit(2)
101
+ spec = host_specs.load("codex")
102
+ conf = Path(spec["configPath"])
103
+ if conf.exists(): # 历史遗留:config.toml MCP 段与插件同名=双注册,移除
104
+ text = conf.read_text(encoding="utf-8")
105
+ try:
106
+ cleaned = strip_codex_vod_blocks(text)
107
+ except RuntimeError as e:
108
+ # 形态守卫:非已知形态宁可不装——改坏用户整份 codex 配置的代价
109
+ # 远高于装不上(字节未动)
110
+ print(f"[vod-devkit] {e}。安装中止,未改动该文件。", file=sys.stderr)
111
+ sys.exit(2)
112
+ if cleaned != text.rstrip():
113
+ conf.write_text(cleaned + "\n", encoding="utf-8")
114
+ print(f"已移除旧 config.toml MCP 段(原生插件取代):{conf}")
115
+ agents = Path.home() / ".codex" / "AGENTS.md"
116
+ if agents.exists(): # 历史遗留:AGENTS.md 技能块已被原生 skill 取代
117
+ text = agents.read_text(encoding="utf-8")
118
+ cleaned = text
119
+ if _LEGACY_ONE_LINER in cleaned:
120
+ # 旧一代 one-liner("立即提交/不要追问/归因由安装绑定")必须清掉:
121
+ # 它是 consent 红线的真实破口(实测 1705 个历史会话带着它跑)
122
+ import datetime as _dt
123
+ bak = agents.with_name(f"AGENTS.md.bak-{_dt.datetime.now():%Y%m%d%H%M%S}")
124
+ bak.write_text(text, encoding="utf-8")
125
+ cleaned, _ = strip_legacy_one_liner(cleaned)
126
+ print(f"已移除旧 AGENTS.md one-liner 注入(备份 {bak.name}):{agents}")
127
+ try:
128
+ cleaned = strip_agents_vod_block(cleaned)
129
+ except RuntimeError as e:
130
+ print(f"[vod-devkit] {e}", file=sys.stderr)
131
+ sys.exit(2)
132
+ if cleaned.strip() == "":
133
+ agents.unlink() # 整份都是我们的注入 → 文件本身也不留
134
+ print(f"已删除空的 AGENTS.md(内容全为旧注入):{agents}")
135
+ elif cleaned != text.rstrip():
136
+ agents.write_text(cleaned + "\n", encoding="utf-8")
137
+ print(f"已移除旧 AGENTS.md 技能块(原生 skill 取代):{agents}")
138
+ mp_root = ROOT / "plugins"
139
+
140
+ def _run(cmd):
141
+ r = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
142
+ if r.returncode != 0:
143
+ raise RuntimeError(f"{' '.join(cmd)} → {r.stderr.strip() or r.stdout.strip()}")
144
+ return r.stdout
145
+
146
+ mp_name = "vod-local"
147
+ # devkit 卫生实践:stale cache 先清——codex 插件缓存不自动失效,不清则
148
+ # 重装/升级后旧版本残留(marketplace 指向与 cache 内容漂移)
149
+ for stale in (Path.home() / ".codex" / "plugins" / "marketplaces" / mp_name,
150
+ Path.home() / ".codex" / "plugins" / "cache" / mp_name):
151
+ if stale.exists():
152
+ shutil.rmtree(stale)
153
+ print(f"已清理 stale 插件缓存:{stale}")
154
+ ml = subprocess.run([codex, "plugin", "marketplace", "list"], capture_output=True, text=True, timeout=120).stdout
155
+ if mp_name not in ml:
156
+ _run([codex, "plugin", "marketplace", "add", str(mp_root)])
157
+ print(f"已注册本地 marketplace:{mp_root}")
158
+ _run([codex, "plugin", "add", f"vod-devkit@{mp_name}"])
159
+ print("已安装 codex 原生插件 vod-devkit(skills + MCP,重启 Codex 会话生效)")
160
+ # P1-5(深审 2026-11-06):插件自带的 .mcp.json 硬编码 env.VOD_PACKS=
161
+ # core,collect——--packs 对 codex 半失效(运行期仍注册 collect 工具)。
162
+ # plugin add 后把缓存内 .mcp.json 的 packs 对齐本次安装值。
163
+ import glob as _glob
164
+ mcp_jsons = sorted(
165
+ _glob.glob(str(Path.home() / ".codex" / "plugins" / "cache"
166
+ / mp_name / "vod-devkit" / "*" / ".mcp.json")),
167
+ key=lambda p: Path(p).stat().st_mtime, reverse=True)
168
+ if mcp_jsons:
169
+ try:
170
+ mj = json.loads(Path(mcp_jsons[0]).read_text(encoding="utf-8"))
171
+ srv = mj.get("mcpServers", {}).get("vod-devkit")
172
+ if srv is not None:
173
+ srv.setdefault("env", {})["VOD_PACKS"] = packs
174
+ Path(mcp_jsons[0]).write_text(
175
+ json.dumps(mj, ensure_ascii=False, indent=2) + "\n",
176
+ encoding="utf-8")
177
+ print(f"已对齐插件 MCP packs:{mcp_jsons[0]}(VOD_PACKS={packs})")
178
+ except Exception as e:
179
+ print(f"[vod-devkit] warn: 插件 .mcp.json packs 对齐失败({e})——"
180
+ "运行期熔断门禁仍会兜底", file=sys.stderr)
181
+ return Path(mcp_jsons[0])
182
+ # 深审 P0-3:绝不再返回 ~/.codex/config.toml——它是用户整份 codex 配置,
183
+ # uninstall 对 mcpConfig 是删除语义,指向它=卸载删光用户配置(破坏性)
184
+ print("[vod-devkit] warn: 未定位到插件 .mcp.json(uninstall 将跳过 MCP 清理,"
185
+ "可手动删除插件缓存目录)", file=sys.stderr)
186
+ return None
187
+
188
+
189
+ def install_remote(args, url, token):
190
+ """codex mcp add --url + --bearer-token-env-var(token 由用户环境提供)。"""
191
+ codex = shutil.which("codex")
192
+ if not codex:
193
+ print("[vod-devkit] 未找到 codex CLI,无法走远程注册", file=sys.stderr)
194
+ sys.exit(2)
195
+ r = subprocess.run([codex, "mcp", "add", "vod-devkit", "--url", url,
196
+ "--bearer-token-env-var", "VOD_MCP_TOKEN"],
197
+ capture_output=True, text=True, timeout=180)
198
+ if r.returncode != 0:
199
+ print(f"[vod-devkit] codex mcp add(remote)失败:{(r.stderr or r.stdout).strip()[-200:]}",
200
+ file=sys.stderr)
201
+ sys.exit(1)
202
+ stale = Path.home() / ".codex" / "plugins"
203
+ if stale.exists():
204
+ print("提示:codex 若曾用插件形态安装过 vod-devkit,请先 "
205
+ "`codex plugin remove vod-devkit@vod-local` 避免双注册(stdio 插件 .mcp.json "
206
+ "与本次 remote 配置同名)", file=sys.stderr)
207
+ print(f"已注册 Codex 远程 MCP({url})。token 由环境变量 VOD_MCP_TOKEN 提供:\n"
208
+ f" export VOD_MCP_TOKEN=<你的 key>(写入 shell 配置或宿主 env)")
209
+ return None
@@ -0,0 +1,176 @@
1
+ """DeepSeek Harness (dsh) 宿主适配:壳包 dsh-vod-devkit + profile patch upsert。
2
+
3
+ dsh 壳不走 MCP(工具/UI 都由壳进程提供)→ SUPPORTS_REMOTE=False。
4
+ """
5
+ import shutil
6
+ import subprocess
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ from vod_mcp import hosts as host_specs
11
+
12
+
13
+ HOST = "dsh"
14
+ SUPPORTS_REMOTE = False
15
+
16
+
17
+ def skills_dir(args):
18
+ prof = (getattr(args, "dsh_profile", "") or "").strip()
19
+ if not prof:
20
+ return None
21
+ d = host_specs.load("dsh", prof).get("skillsDir")
22
+ return Path(d) if d else None
23
+
24
+
25
+ def install(args, packs: str) -> Path:
26
+ """dsh 工具壳(D-dsh-install-1,2026-11-06 用户拍板 A):三壳口径统一——
27
+ --product 安装期硬校验(cmd_install 已先行,到达此处必已过)+ 校验先于
28
+ add + 幂等写 profile cordis.patch.yml config override。
29
+ 生效通道真机实测(2026-11-06,dsh 0.2.1-rc.5):profile cordis.patch.yml
30
+ 的 id-targeted config override 是工具壳读取 product/apiBase/uiBase/
31
+ confirmWrites 的唯一运行时通道(启动 banner + 桩引擎提交链实证)。
32
+ uiBase(D-uiBase-direct):浏览器半(反馈按钮)直连引擎——apiBase 是
33
+ server 半(Node)自用,浏览器同源策略下用不上;缺 uiBase 时 UI 提交
34
+ 发往 dsh 同源(404→本地暂存),嵌入方真机实锤。dsh plugin add 会自建
35
+ profile,无需前置。"""
36
+ dsh = shutil.which("dsh")
37
+ profile = (getattr(args, "dsh_profile", "") or "").strip()
38
+ if not profile:
39
+ # argparse 进入安装前校验(cmd_install 已兜底,直调防御)
40
+ print("[vod-devkit] --profile 必填:dsh 按 profile 组织插件与配置"
41
+ "(--profile <name>)", file=sys.stderr)
42
+ sys.exit(2)
43
+ if not dsh:
44
+ print("[vod-devkit] 未找到 dsh CLI(PATH),拒绝安装(宁可不装不可装错)。"
45
+ "前置:npm i -g @deepseek-ai/dsh(需 pnpm)", file=sys.stderr)
46
+ sys.exit(2)
47
+ r = subprocess.run([dsh, "plugin", "--profile", profile,
48
+ "add", "dsh-vod-devkit"],
49
+ capture_output=True, text=True, timeout=300)
50
+ if r.returncode != 0:
51
+ print(f"[vod-devkit] dsh plugin add 失败:{(r.stderr or r.stdout).strip()[-300:]}",
52
+ file=sys.stderr)
53
+ sys.exit(1)
54
+ print(f"已安装 dsh 插件 dsh-vod-devkit(profile={profile},dsh plugin list 可见)")
55
+
56
+ patch = Path(host_specs.load("dsh", profile)["configPath"])
57
+ # name 行必须保留:cordis.patch.yml 的 insert 块靠 name 绑定 client 半
58
+ # (反馈按钮)——只写 id+config 会在重装幂等替换时把 name 吞掉,UI 静默
59
+ # 失激活(2026-11-06 真机实锤:重装后入口消失)
60
+ # 嵌套铁律(2026-11-10 真机实锤):块必须缩进在 `- insert:` 之下——平铺
61
+ # 形态被 dsh 组合层丢弃,插件掉出组合树(banner/工具/UI 全消失)。
62
+ # 归因先验(D-attrib-B):--product 可选;空值时写 '' 而非空值
63
+ # (dsh 壳 config schema 是 z.string().default(''),YAML null 会校验失败)
64
+ prod_yaml = args.product or "''"
65
+ block = ("- insert:\n"
66
+ " - id: vod-devkit\n"
67
+ " name: dsh-vod-devkit\n"
68
+ " config:\n"
69
+ f" product: {prod_yaml}\n"
70
+ f" apiBase: {args.java_api_base}\n"
71
+ f" uiBase: {args.java_api_base}\n" # D-uiBase-direct:浏览器半直连引擎
72
+ " # headless 无审批通道:原生 ask 门禁会永久阻断写工具(四宿主实测实锤:\n"
73
+ " # requires approval, but no approval channel)。同意确认由 SKILL 话术层\n"
74
+ " # 承担(draft→用户确认→commit / 明确指令直发),web 端如需硬门禁按\n"
75
+ " # profile 覆盖回 true。\n"
76
+ " confirmWrites: false\n")
77
+ try:
78
+ written = upsert_patch(patch, block)
79
+ except Exception as e:
80
+ # 回滚/修复指引:插件已装但配置未写 = 半成品,给明确的手动修复格式。
81
+ # 区分两类失败:形态守卫拒绝(文件合法但不在已知形态内,字节未动)
82
+ # 与真实 IO 失败——两者的处置动作不同,文案必须能分辨。
83
+ print(f"[vod-devkit] 插件已装入 profile={profile},但配置写入失败"
84
+ f"({e.__class__.__name__}: {e};该文件未被改动)。请手动把下段并入 {patch}"
85
+ f"(顶层 YAML 数组元素,已有 - id: vod-devkit 段则原位替换):\n"
86
+ f"{block}", file=sys.stderr)
87
+ sys.exit(1)
88
+ if written:
89
+ print(f"已写入归因/引擎配置(幂等 upsert):{patch}")
90
+ else:
91
+ print(f"配置未变化(幂等跳过):{patch}")
92
+ return patch
93
+
94
+
95
+ def find_dsh_block(lines):
96
+ """定位 cordis.patch.yml 中 vod-devkit 块的 (start, end)。
97
+
98
+ 扫描/边界语义统一在 vod_mcp/config_forms.find_dsh_block(单一实现,
99
+ install 的幂等 upsert、uninstall 摘除、doctor 自愈三处共用——两处扫描
100
+ 规则漂移在本仓 dsh 壳上实锤过)。本函数只保留名字兼容调用点。
101
+ """
102
+ from vod_mcp import config_forms as cf
103
+ return cf.find_dsh_block(lines)
104
+
105
+
106
+ def upsert_patch(patch: Path, block: str) -> bool:
107
+ """幂等写 profile cordis.patch.yml:已存在 `- id: vod-devkit` 段则原位整块
108
+ 替换(不重复插入);无则追加。按行扫描块边界(下一行 `- ` 顶层元素或 EOF),
109
+ 不引 YAML 依赖(本仓零第三方依赖红线)。返回是否有写入。"""
110
+ from vod_mcp import config_forms as cf
111
+ lines = patch.read_text(encoding="utf-8").splitlines() if patch.exists() else []
112
+ # 形态守卫(先分类后改字节):非已知形态一律拒绝——这个文件坏掉等于
113
+ # 整个 dsh profile 起不来(`[]` 占位实锤),比装不上代价高得多
114
+ try:
115
+ verdict, reason = cf.classify_dsh_patch(lines)
116
+ except cf.Refused as e:
117
+ raise RuntimeError(f"cordis.patch.yml 形态不受支持:{e}") from e
118
+ if verdict == "refuse":
119
+ raise RuntimeError(f"cordis.patch.yml 形态不受支持:{reason}")
120
+ start, end = find_dsh_block(lines)
121
+ if start is None:
122
+ # 空数组占位清除(四宿主实测实锤:dsh plugin add 自建的模板含字面量
123
+ # `[]` 顶层行,直接追加块 = `[]` 后跟 `- id:` 顶层元素 = 非法 YAML,
124
+ # 整个 profile 启动崩溃)。`[]` 语义=空数组,被块 entries 取代即删。
125
+ lines = [ln for ln in lines if ln.strip() != "[]"]
126
+ new = lines + ([""] if lines and lines[-1].strip() else []) + block.splitlines()
127
+ else:
128
+ new = lines[:start] + block.splitlines() + lines[end:]
129
+ new_text = "\n".join(new).rstrip("\n") + "\n"
130
+ # 空 `- insert:` 组头清理(损坏态自愈):孤儿组头(下一个顶层元素前无
131
+ # 子项)来自历史平铺替换的残留——留它在 dsh 组合层是空组,可能拖垮
132
+ # 整个 patch 解析。upsert 后顺手摘除(幂等,不碰正常组)。
133
+ cleaned = []
134
+ for idx, ln in enumerate(new):
135
+ if ln.strip() == "- insert:":
136
+ nxt = new[idx + 1] if idx + 1 < len(new) else ""
137
+ if nxt.startswith("- ") or (not nxt.strip() and idx + 2 >= len(new)):
138
+ continue # 孤儿组头:下一行已是新顶层元素(无子项)→ 摘除
139
+ cleaned.append(ln)
140
+ new_text = "\n".join(cleaned).rstrip("\n") + "\n"
141
+ old_text = patch.read_text(encoding="utf-8") if patch.exists() else ""
142
+ if new_text == old_text:
143
+ return False
144
+ patch.parent.mkdir(parents=True, exist_ok=True)
145
+ patch.write_text(new_text, encoding="utf-8")
146
+ return True
147
+
148
+
149
+ def remove_patch_block(patch: Path) -> bool:
150
+ """从 cordis.patch.yml 摘除 vod-devkit 块(uninstall 用)。返回是否摘除。"""
151
+ if not patch.exists():
152
+ return False
153
+ from vod_mcp import config_forms as cf
154
+ lines = patch.read_text(encoding="utf-8").splitlines()
155
+ try:
156
+ verdict, reason = cf.classify_dsh_patch(lines)
157
+ except cf.Refused as e:
158
+ verdict, reason = "refuse", str(e)
159
+ if verdict == "refuse":
160
+ # 卸载路径同样不动字节:文件已经坏了,再"尽力删"只会让故障更难定位
161
+ print(f"[vod-devkit] skip(cordis.patch.yml 形态不受支持,未改动):{reason}",
162
+ file=sys.stderr)
163
+ return False
164
+ start, end = find_dsh_block(lines)
165
+ if start is None:
166
+ return False
167
+ patch.write_text(
168
+ "\n".join(lines[:start] + lines[end:]).rstrip("\n") + "\n",
169
+ encoding="utf-8")
170
+ return True
171
+
172
+
173
+ def install_remote(args, url, token):
174
+ print("[vod-devkit] dsh 壳不走 MCP,不支持远程 attach;请用本地形态:"
175
+ "install --target dsh --profile <name>", file=sys.stderr)
176
+ sys.exit(2)