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.
Files changed (123) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/QUICKSTART.md +47 -23
  3. package/README.en.md +7 -2
  4. package/README.md +6 -2
  5. package/bin/vod-devkit +12 -1166
  6. package/contract/tools.schema.json +1 -1
  7. package/integrations/atomcode/host.json +5 -3
  8. package/integrations/codeartsdoer/host.json +1 -2
  9. package/package.json +8 -2
  10. package/plugins/vod-devkit/.codex-plugin/plugin.json +1 -1
  11. package/plugins/vod-devkit/build-info.json +3 -3
  12. package/plugins/vod-devkit/contract/tools.schema.json +446 -0
  13. package/plugins/vod-devkit/safety/policy.json +48 -0
  14. package/plugins/vod-devkit/skills/vod-feedback-collect/SKILL.md +13 -4
  15. package/plugins/vod-devkit/skills/vod-problem-classification-rules/SKILL.md +2 -1
  16. package/plugins/vod-devkit/skills/vod-scoring-rules/SKILL.md +2 -1
  17. package/plugins/vod-devkit/vod_mcp/__init__.py +1 -1
  18. package/plugins/vod-devkit/vod_mcp/__pycache__/__init__.cpython-314.pyc +0 -0
  19. package/plugins/vod-devkit/vod_mcp/__pycache__/attribution.cpython-314.pyc +0 -0
  20. package/plugins/vod-devkit/vod_mcp/__pycache__/net.cpython-314.pyc +0 -0
  21. package/plugins/vod-devkit/vod_mcp/__pycache__/paths.cpython-314.pyc +0 -0
  22. package/plugins/vod-devkit/vod_mcp/__pycache__/policy.cpython-314.pyc +0 -0
  23. package/plugins/vod-devkit/vod_mcp/__pycache__/provenance.cpython-314.pyc +0 -0
  24. package/plugins/vod-devkit/vod_mcp/__pycache__/runtime_state.cpython-314.pyc +0 -0
  25. package/plugins/vod-devkit/vod_mcp/__pycache__/skills_registry.cpython-314.pyc +0 -0
  26. package/plugins/vod-devkit/vod_mcp/__pycache__/tools.cpython-314.pyc +0 -0
  27. package/plugins/vod-devkit/vod_mcp/attribution.py +8 -8
  28. package/plugins/vod-devkit/vod_mcp/host_adapters/base.py +3 -1
  29. package/plugins/vod-devkit/vod_mcp/host_adapters/codex.py +16 -3
  30. package/plugins/vod-devkit/vod_mcp/host_adapters/hermes.py +99 -16
  31. package/plugins/vod-devkit/vod_mcp/hosts.py +3 -1
  32. package/plugins/vod-devkit/vod_mcp/net.py +251 -0
  33. package/plugins/vod-devkit/vod_mcp/packs/__pycache__/__init__.cpython-314.pyc +0 -0
  34. package/plugins/vod-devkit/vod_mcp/packs/__pycache__/collect.cpython-314.pyc +0 -0
  35. package/plugins/vod-devkit/vod_mcp/packs/__pycache__/core.cpython-314.pyc +0 -0
  36. package/plugins/vod-devkit/vod_mcp/packs/__pycache__/knowledge.cpython-314.pyc +0 -0
  37. package/plugins/vod-devkit/vod_mcp/packs/collect.py +684 -0
  38. package/plugins/vod-devkit/vod_mcp/packs/core.py +80 -0
  39. package/plugins/vod-devkit/vod_mcp/packs/knowledge.py +17 -0
  40. package/plugins/vod-devkit/vod_mcp/paths.py +38 -0
  41. package/plugins/vod-devkit/vod_mcp/payload.py +3 -1
  42. package/plugins/vod-devkit/vod_mcp/policy.py +3 -2
  43. package/plugins/vod-devkit/vod_mcp/provenance.py +3 -2
  44. package/plugins/vod-devkit/vod_mcp/remote_app.py +25 -0
  45. package/plugins/vod-devkit/vod_mcp/runtime_state.py +324 -0
  46. package/plugins/vod-devkit/vod_mcp/server.py +10 -7
  47. package/plugins/vod-devkit/vod_mcp/skills_registry.py +11 -9
  48. package/plugins/vod-devkit/vod_mcp/tools.py +23 -1300
  49. package/plugins/vod-devkit/vod_mcp/transport_remote.py +68 -8
  50. package/plugins/vod-devkit/vod_mcp/update_check.py +1 -1
  51. package/skills/vod-feedback-collect/SKILL.md +13 -4
  52. package/skills/vod-problem-classification-rules/SKILL.md +2 -1
  53. package/skills/vod-scoring-rules/SKILL.md +2 -1
  54. package/vod_mcp/__init__.py +1 -1
  55. package/vod_mcp/attribution.py +8 -8
  56. package/vod_mcp/host_adapters/__pycache__/__init__.cpython-39.pyc +0 -0
  57. package/vod_mcp/host_adapters/__pycache__/atomcode.cpython-39.pyc +0 -0
  58. package/vod_mcp/host_adapters/__pycache__/base.cpython-314.pyc +0 -0
  59. package/vod_mcp/host_adapters/__pycache__/base.cpython-39.pyc +0 -0
  60. package/vod_mcp/host_adapters/__pycache__/codearts.cpython-39.pyc +0 -0
  61. package/vod_mcp/host_adapters/__pycache__/codeartswork.cpython-39.pyc +0 -0
  62. package/vod_mcp/host_adapters/__pycache__/codex.cpython-314.pyc +0 -0
  63. package/vod_mcp/host_adapters/__pycache__/codex.cpython-39.pyc +0 -0
  64. package/vod_mcp/host_adapters/__pycache__/codex_desktop.cpython-39.pyc +0 -0
  65. package/vod_mcp/host_adapters/__pycache__/dsh.cpython-39.pyc +0 -0
  66. package/vod_mcp/host_adapters/__pycache__/generic.cpython-39.pyc +0 -0
  67. package/vod_mcp/host_adapters/__pycache__/hermes.cpython-314.pyc +0 -0
  68. package/vod_mcp/host_adapters/__pycache__/hermes.cpython-39.pyc +0 -0
  69. package/vod_mcp/host_adapters/__pycache__/opencode.cpython-39.pyc +0 -0
  70. package/vod_mcp/host_adapters/__pycache__/workbuddy.cpython-39.pyc +0 -0
  71. package/vod_mcp/host_adapters/base.py +3 -1
  72. package/vod_mcp/host_adapters/codex.py +16 -3
  73. package/vod_mcp/host_adapters/hermes.py +99 -16
  74. package/vod_mcp/hosts.py +3 -1
  75. package/vod_mcp/net.py +251 -0
  76. package/vod_mcp/packs/__pycache__/__init__.cpython-314.pyc +0 -0
  77. package/vod_mcp/packs/__pycache__/__init__.cpython-39.pyc +0 -0
  78. package/vod_mcp/packs/__pycache__/collect.cpython-314.pyc +0 -0
  79. package/vod_mcp/packs/__pycache__/collect.cpython-39.pyc +0 -0
  80. package/vod_mcp/packs/__pycache__/core.cpython-314.pyc +0 -0
  81. package/vod_mcp/packs/__pycache__/core.cpython-39.pyc +0 -0
  82. package/vod_mcp/packs/__pycache__/knowledge.cpython-314.pyc +0 -0
  83. package/vod_mcp/packs/__pycache__/knowledge.cpython-39.pyc +0 -0
  84. package/vod_mcp/packs/collect.py +684 -0
  85. package/vod_mcp/packs/core.py +80 -0
  86. package/vod_mcp/packs/knowledge.py +17 -0
  87. package/vod_mcp/paths.py +38 -0
  88. package/vod_mcp/payload.py +3 -1
  89. package/vod_mcp/policy.py +3 -2
  90. package/vod_mcp/provenance.py +3 -2
  91. package/vod_mcp/remote_app.py +25 -0
  92. package/vod_mcp/runtime_state.py +324 -0
  93. package/vod_mcp/server.py +10 -7
  94. package/vod_mcp/skills_registry.py +11 -9
  95. package/vod_mcp/tools.py +23 -1300
  96. package/vod_mcp/transport_remote.py +68 -8
  97. package/vod_mcp/update_check.py +1 -1
  98. package/vodkit_cli/__init__.py +10 -0
  99. package/vodkit_cli/__pycache__/__init__.cpython-314.pyc +0 -0
  100. package/vodkit_cli/__pycache__/__init__.cpython-39.pyc +0 -0
  101. package/vodkit_cli/__pycache__/cli.cpython-314.pyc +0 -0
  102. package/vodkit_cli/__pycache__/cli.cpython-39.pyc +0 -0
  103. package/vodkit_cli/__pycache__/common.cpython-314.pyc +0 -0
  104. package/vodkit_cli/__pycache__/common.cpython-39.pyc +0 -0
  105. package/vodkit_cli/__pycache__/doctor.cpython-314.pyc +0 -0
  106. package/vodkit_cli/__pycache__/doctor.cpython-39.pyc +0 -0
  107. package/vodkit_cli/__pycache__/install.cpython-314.pyc +0 -0
  108. package/vodkit_cli/__pycache__/install.cpython-39.pyc +0 -0
  109. package/vodkit_cli/__pycache__/remote.cpython-314.pyc +0 -0
  110. package/vodkit_cli/__pycache__/remote.cpython-39.pyc +0 -0
  111. package/vodkit_cli/__pycache__/uninstall.cpython-314.pyc +0 -0
  112. package/vodkit_cli/__pycache__/uninstall.cpython-39.pyc +0 -0
  113. package/vodkit_cli/__pycache__/update.cpython-314.pyc +0 -0
  114. package/vodkit_cli/__pycache__/update.cpython-39.pyc +0 -0
  115. package/vodkit_cli/cli.py +86 -0
  116. package/vodkit_cli/common.py +254 -0
  117. package/vodkit_cli/doctor.py +269 -0
  118. package/vodkit_cli/install.py +260 -0
  119. package/vodkit_cli/remote.py +200 -0
  120. package/vodkit_cli/uninstall.py +161 -0
  121. package/vodkit_cli/update.py +45 -0
  122. /package/plugins/vod-devkit/vod_mcp/{packs.py → packs/__init__.py} +0 -0
  123. /package/vod_mcp/{packs.py → packs/__init__.py} +0 -0
@@ -0,0 +1,269 @@
1
+ """诊断类子命令:status / doctor / verify / explain / detect。"""
2
+ import json
3
+ import os
4
+ import re
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
+ from vodkit_cli import common, remote
12
+
13
+
14
+ def cmd_status(_args):
15
+ p = common.manifest_path()
16
+ if not p.exists():
17
+ print("未安装(无 install-manifest)")
18
+ sys.exit(1)
19
+ # golden 稳定性:apiBase 含安装期动态值(本地验证实例端口),归一化后输出
20
+ text = p.read_text(encoding="utf-8")
21
+ text = re.sub(r'"apiBase": "http://127\.0\.0\.1:\d+"',
22
+ '"apiBase": "http://127.0.0.1:<PORT>"', text)
23
+ # 载荷路径含 HOME/版本,按 <PAYLOAD> 归一(golden 不随环境漂)
24
+ text = re.sub(r'"payloadDir": ".*?/payloads/[^"]+"',
25
+ '"payloadDir": "<PAYLOAD>"', text)
26
+ print(text)
27
+
28
+
29
+ def _repair_dsh_patch_block(mf: dict) -> str | None:
30
+ """doctor 自愈(S58/A):profile cordis.patch.yml 的 vod-devkit 块缺失或
31
+ 打平(未缩进在 - insert: 之下)时,按 manifest 的 product/apiBase 重建
32
+ 正确嵌套块。返回修复的文件路径;块完好返回 None。
33
+
34
+ 嵌套铁律(真机实锤):id/name/config 必须缩进在 `- insert:` 之下——
35
+ dsh 的配置序列化只保留它能识别的块,手工游离块会被下次写盘冲掉。
36
+ """
37
+ prof = mf["dshProfile"]
38
+ patch = Path(host_specs.load("dsh", prof)["configPath"])
39
+ if not patch.exists():
40
+ return None
41
+ from vod_mcp import config_forms as cf
42
+ lines = patch.read_text(encoding="utf-8").splitlines()
43
+ try:
44
+ verdict, reason = cf.classify_dsh_patch(lines)
45
+ except cf.Refused as e:
46
+ verdict, reason = "refuse", str(e)
47
+ if verdict == "refuse":
48
+ # 自愈也不越界:文件形态未知时只报告,不动字节
49
+ print(f"[doctor] skip(cordis.patch.yml 形态不受支持,未自愈):{reason}",
50
+ file=sys.stderr)
51
+ return None
52
+ vod_idx = next((i for i, ln in enumerate(lines)
53
+ if ln.strip().startswith("- id: vod-devkit")), None)
54
+ if vod_idx is not None and lines[vod_idx].startswith((" ", "\t")):
55
+ # 已嵌套且在 insert 组内(简化判定:缩进+前文存在 - insert: 行)→ 完好
56
+ has_insert = any(ln.strip() == "- insert:" for ln in lines[:vod_idx])
57
+ has_name = any("name: dsh-vod-devkit" in ln
58
+ for ln in lines[vod_idx:vod_idx + 3])
59
+ if has_insert and has_name:
60
+ return None
61
+ # 需要重建:先摘除旧块(块边界=下一个 `- ` 群组项,任何缩进),再追加正确嵌套组
62
+ if vod_idx is not None:
63
+ end = next((j for j in range(vod_idx + 1, len(lines))
64
+ if lines[j].strip().startswith("- ")), len(lines))
65
+ del lines[vod_idx:end]
66
+ if lines and lines[-1].strip():
67
+ lines.append("")
68
+ product = mf.get("product") or ""
69
+ api_base = mf.get("apiBase") or ""
70
+ lines += [
71
+ "- insert:",
72
+ " - id: vod-devkit",
73
+ " name: dsh-vod-devkit",
74
+ " config:",
75
+ f" product: {product}",
76
+ f" apiBase: {api_base}",
77
+ f" uiBase: {api_base}", # D-uiBase-direct:浏览器半直连,与 install 同口径
78
+ ]
79
+ patch.write_text("\n".join(lines).rstrip("\n") + "\n", encoding="utf-8")
80
+ return str(patch)
81
+
82
+
83
+ def _render_problems(problems) -> str:
84
+ """分层报告(对表 devkit 的 doctor-report):按 环境/载荷/配置/技能/网络/插件 分组,
85
+ 每条失败给「原因」与「动作」,避免运维只看到一堆 FAIL 文案。"""
86
+ from vod_mcp import diagnose
87
+ return diagnose.render_problems(problems)
88
+
89
+
90
+ def cmd_explain(args):
91
+ """解释一条失败文案/错误码(-32010 等):给层 + 原因 + 动作。"""
92
+ from vod_mcp import diagnose
93
+ text = " ".join(args.text).strip()
94
+ if not text:
95
+ print("用法:vod-devkit explain '<错误文案或错误码>'", file=sys.stderr)
96
+ sys.exit(2)
97
+ info = diagnose.explain(text)
98
+ if not info["known"]:
99
+ print(f"未收录该问题:{text[:120]}", file=sys.stderr)
100
+ print(" 排查入口:doctor 看分层报告;仍无头绪就把这段文案连同 doctor 输出一起贴出来",
101
+ file=sys.stderr)
102
+ sys.exit(2)
103
+ print(f"层:{info['layer']}")
104
+ print(f"原因:{info['cause']}")
105
+ print(f"动作:{info['action']}")
106
+
107
+
108
+ def cmd_detect(args):
109
+ """只读识别项目语言/框架/构建(给采集端补上下文;不写任何文件)。"""
110
+ from vod_mcp import detect_framework
111
+ try:
112
+ info = detect_framework.detect(args.path or os.getcwd())
113
+ except ValueError as e:
114
+ print(str(e), file=sys.stderr)
115
+ sys.exit(2)
116
+ print(json.dumps(info, ensure_ascii=False, indent=2))
117
+ print("摘要:" + detect_framework.summary_line(info))
118
+
119
+
120
+ def cmd_doctor(_args):
121
+ problems = []
122
+ p = common.manifest_path()
123
+ if not p.exists():
124
+ problems.append("无 install-manifest.json(未 install?)")
125
+ else:
126
+ mf = json.loads(p.read_text(encoding="utf-8"))
127
+ # dsh patch 块自愈(S58/A 止血,2026-11-06 真机实锤):dsh 运行时
128
+ # 序列化会冲掉 profile patch 里的 vod 块(配置树不含手工块)——
129
+ # doctor 检测缺失/打平后按 manifest 的 product/apiBase 重建嵌套块
130
+ if mf.get("target") == "dsh" and mf.get("dshProfile"):
131
+ patched = _repair_dsh_patch_block(mf)
132
+ if patched:
133
+ print(f"[doctor] 已重建 dsh patch 的 vod-devkit 块:{patched}"
134
+ "(重启 dsh 生效)")
135
+ bi = json.loads((common.ROOT / "build-info.json").read_text(encoding="utf-8"))
136
+ if mf["source"]["commitSha"] != bi.get("commitSha"):
137
+ problems.append("install-manifest 与 build-info 的 commitSHA 不一致")
138
+ if mf.get("mcpConfig") and not Path(mf["mcpConfig"]).exists():
139
+ problems.append("MCP 配置文件缺失")
140
+ if mf.get("transport") == "remote" and mf.get("mcpUrl"):
141
+ url = mf["mcpUrl"]
142
+ token = (os.environ.get("VOD_MCP_TOKEN")
143
+ or os.environ.get("MCP_VOD_DEVKIT_API_KEY") or "").strip()
144
+ try:
145
+ names = remote._probe_remote(url, token, timeout=8)
146
+ missing = remote._expected_remote_tools() - set(names)
147
+ if missing:
148
+ problems.append(f"远程面工具面不符(缺 {sorted(missing)}):{url}")
149
+ else:
150
+ print(f"[doctor] 远程面可达:{url}({len(names)} 工具)")
151
+ except Exception as e: # noqa: BLE001
152
+ if not remote._remote_reachable(url):
153
+ problems.append(f"远程 MCP 端点不可达:{url}")
154
+ elif not token:
155
+ print("[doctor] 远程端点可达,但未提供 token(401 属预期):"
156
+ "设 VOD_MCP_TOKEN 可验工具面")
157
+ else:
158
+ problems.append(f"远程面探活失败(带 token):{e}")
159
+ if not Path(mf["skillsDir"]).exists():
160
+ problems.append("skills 目录缺失")
161
+ drifted = common._drifted_skills(mf)
162
+ if drifted:
163
+ problems.append("技能拷贝件与安装产物漂移(D-drift-lock):"
164
+ + "、".join(drifted) + "——重跑 install 恢复")
165
+ # 名册对账(逐原生落点):漏装/漂移按宿主点名(借鉴 devkit doctor)
166
+ for si in mf.get("skillInstalls") or []:
167
+ d = Path(si["dir"])
168
+ if not d.exists():
169
+ problems.append(f"技能原生副本缺失({si['host']}):{d} 不存在"
170
+ "——重跑 install 恢复")
171
+ continue
172
+ import hashlib
173
+ expect = mf.get("skillHashes") or {}
174
+ for rel, sha in expect.items():
175
+ f = d / rel
176
+ if not f.exists():
177
+ problems.append(f"技能文件缺失({si['host']}):{rel}")
178
+ elif hashlib.sha256(f.read_bytes()).hexdigest() != sha:
179
+ problems.append(f"技能文件漂移({si['host']}):{rel}")
180
+ # 载荷(D-payload-1):MCP 入口指向副本 → 副本必须在且未被改
181
+ from vod_mcp import payload as _payload
182
+ pd = mf.get("payloadDir")
183
+ if pd:
184
+ if not Path(pd).is_dir():
185
+ problems.append(f"载荷目录缺失:{pd}(MCP 入口指向它,宿主起不来)——重跑 install")
186
+ else:
187
+ bad = _payload.verify(Path(pd))
188
+ if bad:
189
+ problems.append("载荷被改动:" + ";".join(bad[:5]))
190
+ if _payload.marker_path().exists():
191
+ print(f"[doctor] 载荷已换({pd})——重启宿主会话生效")
192
+ else:
193
+ print("[doctor] 提示:本次安装无载荷副本(旧版),入口指向仓内路径;重跑 install 可固化")
194
+ for res in _payload.residue():
195
+ print(f"[doctor] 载荷残留(无 payload.json):{res}——可手动删除")
196
+ # 旧一代 AGENTS.md 注入(2026-11-05 之前的 one-liner):教模型跳过同意 +
197
+ # 归因由安装绑定。实测 1705 个 codex 会话带着它 → 不动它就等于红线失效。
198
+ legacy_agents = Path.home() / ".codex" / "AGENTS.md"
199
+ if legacy_agents.exists() and "vod-submit-one-liner" in legacy_agents.read_text(
200
+ encoding="utf-8"):
201
+ problems.append(f"AGENTS.md 仍含旧一代注入(教模型跳过同意):{legacy_agents}"
202
+ "——重跑 install --target codex 自动清理")
203
+ # 路由插件副本(hermes):仓内话术改了但装机副本没刷新 → 宿主还在注入旧口径
204
+ # (2026-11-11 实锤:仓里已把"归因由安装绑定决定"改成"原话解析",装机副本仍是旧的)
205
+ rp_dst = Path.home() / ".hermes" / "plugins" / "vod-feedback-router" / "router.py"
206
+ rp_src = common.ROOT / "hermes-plugin" / "vod-feedback-router" / "router.py"
207
+ if rp_dst.exists() and rp_src.exists() and rp_dst.read_text(encoding="utf-8") != \
208
+ rp_src.read_text(encoding="utf-8"):
209
+ problems.append(f"路由插件副本落后于仓内:{rp_dst}(重跑 install --target hermes)")
210
+ # CodeArts Agent 冒烟:官方 CLI 在就 list 一次(实测通道=codearts_cli.json 的 mcp 段)
211
+ if mf.get("target") == "codeartsdoer" and shutil.which("codearts"):
212
+ r = subprocess.run(["codearts", "mcp", "list"], capture_output=True,
213
+ text=True, timeout=60)
214
+ if "vod-devkit" in (r.stdout or ""):
215
+ print("[doctor] CodeArts Agent 已识别 vod-devkit(codearts mcp list)")
216
+ else:
217
+ problems.append("CodeArts Agent 未列出 vod-devkit"
218
+ "(codearts mcp list)——检查 codearts_cli.json 的 mcp 段")
219
+ if problems:
220
+ print(_render_problems(problems))
221
+ sys.exit(1)
222
+ # key 探针(最佳努力):配置了 key 就问一次引擎,无效当场报;网络不可达只提示不 FAIL
223
+ #(离线环境 doctor 必须可用——网络问题不是 key 问题)
224
+ from vod_mcp.runtime_state import _runtime_cfg
225
+ key = os.environ.get("VOD_JAVA_API_KEY") or _runtime_cfg().get("java_key")
226
+ if key:
227
+ from vod_mcp.net import probe_key
228
+ chk = probe_key(key)
229
+ if chk["ok"] is False:
230
+ problems.append(f"key 无效(指纹 {chk['fingerprint']},引擎 401 拒绝)——"
231
+ "请核对/续期,或移除 key 走匿名档")
232
+ elif chk["ok"] is None:
233
+ print(f"warn: key 未验证(引擎不可达,指纹 {chk['fingerprint']})")
234
+ else:
235
+ print(f"key: 有效(指纹 {chk['fingerprint']})")
236
+ if problems:
237
+ print(_render_problems(problems))
238
+ sys.exit(1)
239
+ print("doctor: OK")
240
+
241
+
242
+ def cmd_verify(_args):
243
+ p = common.manifest_path()
244
+ if not p.exists():
245
+ print("未安装")
246
+ sys.exit(1)
247
+ sha = json.loads(p.read_text(encoding="utf-8"))["source"]["commitSha"]
248
+ if not sha:
249
+ print("manifest 无 commitSha(dev 构建无法核验)")
250
+ sys.exit(1)
251
+ if common._distribution() == "preset":
252
+ # D-key-guard-3②:产品分发形态客户机无 git 源——只做本地完整性校验,
253
+ # 源端比对降级为 unchecked 不 FAIL(离线 verify 必须可用)
254
+ bi = json.loads((common.ROOT / "build-info.json").read_text(encoding="utf-8"))
255
+ if sha != bi.get("commitSha"):
256
+ print("FAIL: manifest 与 build-info commitSHA 不一致(安装产物被篡改/混装)")
257
+ sys.exit(1)
258
+ print("verify: OK(preset 本地完整性;源端比对 unchecked)")
259
+ return
260
+ r = subprocess.run(["git", "cat-file", "-e", f"{sha}^{{commit}}"],
261
+ cwd=common.ROOT, capture_output=True)
262
+ if r.returncode != 0:
263
+ subprocess.run(["git", "fetch", "origin"], cwd=common.ROOT)
264
+ r = subprocess.run(["git", "cat-file", "-e", f"{sha}^{{commit}}"],
265
+ cwd=common.ROOT, capture_output=True)
266
+ if r.returncode != 0:
267
+ print(f"FAIL: commit {sha} 不存在于 origin(被改写或非本仓产物)")
268
+ sys.exit(1)
269
+ print(f"verify: OK(commit {sha[:12]} 存在于本仓/origin)")
@@ -0,0 +1,260 @@
1
+ """install 子命令:探测 → 门禁 → 载荷固化 → 宿主写入 → 技能拷贝 → manifest。"""
2
+ import datetime
3
+ import json
4
+ import os
5
+ import shutil
6
+ import sys
7
+ from pathlib import Path
8
+
9
+ from vod_mcp import hosts as host_specs
10
+ from vod_mcp.host_adapters import REGISTRY as HOST_ADAPTERS
11
+ from vod_mcp.host_adapters import generic as generic_host
12
+ from vodkit_cli import common, remote
13
+
14
+
15
+ def detect_targets() -> list:
16
+ """0/1/N 探测:按 host.json 的 detect 段判断宿主是否在场(CLI 或配置目录)。"""
17
+ found = []
18
+ for host in host_specs.hosts():
19
+ spec = host_specs.raw(host) # 探测不解析路径(dsh 的 {profile} 占位符必填)
20
+ if spec.get("detectCLI") and shutil.which(spec["detectCLI"]):
21
+ found.append(host)
22
+ elif spec.get("detectPath") and Path(spec["detectPath"]).exists():
23
+ found.append(host)
24
+ return found
25
+
26
+
27
+ def cmd_install(args):
28
+ from vod_mcp import DEFAULT_JAVA_BASE
29
+ if not args.java_api_base:
30
+ # 优先级:--java-api-base > env VOD_JAVA_API_BASE > DEFAULT_JAVA_BASE
31
+ #(env 与插件运行时同键,安装器跟随同链;测试/CI 用 env 指桩引擎零外呼)
32
+ args.java_api_base = os.environ.get("VOD_JAVA_API_BASE") or DEFAULT_JAVA_BASE
33
+ common.write_build_info(strict=False)
34
+ target = args.target
35
+ if target == "auto":
36
+ found = detect_targets()
37
+ generic_found = generic_host.detect_known()
38
+ if len(found) == 1:
39
+ target = found[0]
40
+ elif not found and len(generic_found) == 1:
41
+ # A 层兜底:没有专属模块但有已知通用 MCP 宿主 → 走通用写入
42
+ #(探到唯一一个才自动写,多个/零个都要人选定,不许猜)
43
+ target = "generic"
44
+ if not getattr(args, "mcp_config", ""):
45
+ args.mcp_config = str(generic_host._expand(generic_found[0]["config"]))
46
+ print(f"探测到通用 MCP 宿主: {generic_found[0]['label']} → 通用写入 "
47
+ f"({args.mcp_config})")
48
+ elif not found:
49
+ known = "、".join(h["label"] + "(" + h["config"] + ")" for h in generic_found)
50
+ print("未探测到可自动安装的宿主;用 --target hermes|opencode|codeartsdoer|codeartswork|codex|codex-desktop|dsh|workbuddy|atomcode 显式指定"
51
+ + (f",或通用写入:--target generic --mcp-config <配置>(探测到 {known})"
52
+ if generic_found else ""), file=sys.stderr)
53
+ sys.exit(2)
54
+ else:
55
+ print(f"探测到多个宿主: {found + [h['id'] for h in generic_found]};"
56
+ "请 --target 显式指定其一", file=sys.stderr)
57
+ sys.exit(2)
58
+ print(f"探测到宿主: {target}")
59
+ adapter = HOST_ADAPTERS.get(target)
60
+ if adapter is None:
61
+ g = [(h["id"], h["config"]) for h in generic_host.detect_known()]
62
+ hint = ("\n 探测到通用 MCP 宿主:" + ";".join(f"{i}({c})" for i, c in g)
63
+ if g else "")
64
+ print(f"不支持目标: {target}(可选 hermes|opencode|codeartsdoer|codeartswork|codex|codex-desktop|dsh|workbuddy|atomcode|generic|auto){hint}\n"
65
+ " 通用宿主:install --target generic --mcp-config <配置文件>",
66
+ file=sys.stderr)
67
+ sys.exit(2)
68
+ packs = args.packs or common.PRESETS.get(args.preset, "")
69
+ # 恢复门禁(D-codex-circuit-breaker-1,2026-11-06 负责人确认):
70
+ # 熔断标记存在(~/.codex/vod-collect-suspended.json)时,codex 装 collect
71
+ # 被拒——恢复采集的前置=token 化上线并过回归,不是改回 packs 一个动作;
72
+ # --ack-suspension=显式解除(P1-4 修正:解除动作后置到安装成功之后——
73
+ # 若产品校验/安装中途失败,熔断不得已被解除)。
74
+ pending_ack = False
75
+ if target == "codex" and "collect" in (packs or "").replace(" ", "").split(","):
76
+ marker = Path.home() / ".codex" / "vod-collect-suspended.json"
77
+ if marker.is_file() and getattr(args, "ack_suspension", False):
78
+ pending_ack = True # 解除后置:安装成功才落
79
+ elif marker.is_file():
80
+ print("[vod-devkit] 恢复门禁:codex 采集处于熔断状态"
81
+ "(未确认提交 ≥2 次,详见 docs/decisions.md"
82
+ " D-codex-circuit-breaker-1)。"
83
+ "恢复前置=token 化两段式上线并通过回归"
84
+ "(draft→commit 审计链/重复 commit 被拒/未确认可检测)。",
85
+ file=sys.stderr)
86
+ sys.exit(2)
87
+ # 归因绑定降级(D-attrib-B,2026-11-11 负责人拍板 P1-P4 全 A):--product
88
+ # 由必填改为**可选先验**——归因主路径改成运行期从用户原话解析(证据唯一
89
+ # 命中才采信),安装绑定只在「无字面证据且无记忆」时兜底。保留「给了就
90
+ # 必须对」:显式提供时仍做名录硬校验(拼错照样 exit 2),不给不拦装。
91
+ # D-dsh-install-1:--profile 必填在进入任何安装动作前校验(先校验后写入)
92
+ if target == "dsh" and not (args.dsh_profile or "").strip():
93
+ print("[vod-devkit] --profile 必填:dsh 按 profile 组织插件与配置。\n"
94
+ " 例:npx vod-devkit install --target dsh --profile web --product CodeArts",
95
+ file=sys.stderr)
96
+ sys.exit(2)
97
+ bound_product = args.product
98
+ # D-product-id-2(2026-11-05 用户拍板 B,推翻"宿主名是显式合法值"宽容口径):
99
+ # 安装期产品硬校验——--product 必须命中 meta productCatalog(名字大小写不敏感
100
+ # 或平台主键 id 精确)。理由:--product 是整条采集链(内置采集技能/分类/透传)
101
+ # 的归因前提,装错=全套 skill 逻辑空转且用户无感知;归因错误比报错更糟。
102
+ # 目录不可达(离线/引擎异常)同样拒绝——宁可不装不可装错(postinstall 拒绝
103
+ # 猜测同源纪律)。插件提交链的 name 兼容通道不受影响(那是老版本插件兼容,
104
+ # 不是安装期放行理由)。
105
+ if args.product: # 可选先验:给了就校验,不给不拦装(D-attrib-B)
106
+ remote._validate_product_or_exit(args.product, args.java_api_base)
107
+ # D-key-guard-2 红线:preset(产品分发)形态下 key 禁止随包——环境变量里的
108
+ # key 不透传给宿主配置(客户机一律走匿名令牌自领),并当场告警
109
+ distribution = args.distribution
110
+ if distribution == "preset" and os.environ.pop("VOD_JAVA_API_KEY", None):
111
+ print("[vod-devkit] warn: preset 形态下 VOD_JAVA_API_KEY 已忽略且不写入宿主配置"
112
+ "(key 落在哪台机器哪台就是信任边界;客户机走匿名令牌)", file=sys.stderr)
113
+ rt = common.ROOT / "vod_mcp" / "runtime.json"
114
+ cfg = {}
115
+ if rt.exists():
116
+ try:
117
+ cfg = json.loads(rt.read_text(encoding="utf-8"))
118
+ except Exception:
119
+ cfg = {}
120
+ cfg["product"] = bound_product
121
+ if getattr(args, "no_local_ledger", False):
122
+ # D-key-guard-3④:企业数据驻留要求可关本地账本(代价 vod_list_submitted 不可用)
123
+ cfg["local_ledger"] = False
124
+ # base 同步落 runtime.json:宿主 env 透传不稳是实测坑,透传挂了静默落回
125
+ # 127.0.0.1:8090;文件兑底与 env 同值不构成双真源(优先级链 env>文件)
126
+ # 宿主产品(host_default)已删除(2026-11-12 复评):宿主产品也是一次推断,
127
+ # 错归会进引擎幂等/判重域。候选只走 vod_search_products,这里不再写 host_product。
128
+ cfg["java_base"] = args.java_api_base
129
+ rt.write_text(json.dumps(cfg, ensure_ascii=False, indent=2), encoding="utf-8")
130
+
131
+ # ── 远程 attach / skills-only(D-attach-1)───────────────────────────
132
+ # 形态:MCP 单独部署一个远程端点,宿主只把 MCP 配置指向它(+ 本地技能)。
133
+ # 约束:远程面无匿名链(缺 key fail fast)→ token 必填;探活先于写入,
134
+ # 失败零副作用。dsh 壳不走 MCP,这两种模式对 dsh 无意义(显式拒绝)。
135
+ remote_url = (getattr(args, "mcp_url", "") or "").strip()
136
+ skills_only = bool(getattr(args, "skills_only", False))
137
+ if remote_url or skills_only:
138
+ if not getattr(adapter, "SUPPORTS_REMOTE", False):
139
+ what = "dsh 壳不走 MCP" if target == "dsh" else f"{target} 不走 MCP"
140
+ print(f"[vod-devkit] {what},不支持 --mcp-url / --skills-only\n"
141
+ f" {target} 请用本地形态:install --target {target} "
142
+ + ("--profile <name>" if target == "dsh" else ""),
143
+ file=sys.stderr)
144
+ sys.exit(2)
145
+ token = (getattr(args, "mcp_token", "") or os.environ.get("VOD_MCP_TOKEN") or "").strip()
146
+ if remote_url:
147
+ if not token:
148
+ print("[vod-devkit] 远程 attach 必须提供 --mcp-token 或 env VOD_MCP_TOKEN:\n"
149
+ " 远程面不代签匿名令牌(身份只从请求头来),无 token 装上也提交不了",
150
+ file=sys.stderr)
151
+ sys.exit(2)
152
+ try:
153
+ names = remote._probe_remote(remote_url, token)
154
+ except Exception as e: # noqa: BLE001
155
+ print(f"[vod-devkit] 远程 MCP 探活失败(未写入任何配置):{e}", file=sys.stderr)
156
+ sys.exit(2)
157
+ expected = remote._expected_remote_tools()
158
+ missing = expected - set(names)
159
+ if missing:
160
+ print(f"[vod-devkit] 远程面工具面不符:缺 {sorted(missing)}\n"
161
+ f" 实际 = {sorted(names)}\n"
162
+ " 该端点可能不是 vod-devkit 远程面,或版本/角色不匹配;拒绝安装",
163
+ file=sys.stderr)
164
+ sys.exit(2)
165
+ print(f"远程面探活通过:{len(names)} 个工具({', '.join(sorted(names))})")
166
+ mcp_conf = None if skills_only else adapter.install_remote(args, remote_url, token)
167
+ extra_dirs = _install_skills(target, packs, args,
168
+ (getattr(args, "dsh_profile", "") or "").strip() or None)
169
+ common._write_install_manifest(args, target, packs, bound_product, mcp_conf, extra_dirs,
170
+ transport=("skills-only" if skills_only else "remote"),
171
+ mcp_url=remote_url)
172
+ return
173
+
174
+ payload_dir = _stage_payload() # 载荷固化:入口指向这份副本,不再指向 npx 缓存
175
+ mcp_conf = adapter.install(args, packs)
176
+
177
+ # P1-4 修正:ack 解除后置——安装全部成功才落(解除先于安装=失败安装
178
+ # 也绕过了恢复门禁语义)
179
+ if pending_ack:
180
+ marker = Path.home() / ".codex" / "vod-collect-suspended.json"
181
+ if marker.is_file():
182
+ marker.unlink()
183
+ audit = Path.home() / ".codex" / "vod-collect-suspension-audit.log"
184
+ with audit.open("a", encoding="utf-8") as f:
185
+ f.write(f"{datetime.datetime.now().isoformat(timespec='seconds')}\t"
186
+ f"ack_suspension\tpacks={packs}\n")
187
+ print(f"[vod-devkit] 已显式解除 codex 采集熔断(安装成功),审计已记录:{audit}")
188
+
189
+ # G1 修复:技能全量拷贝(目录型技能+平铺规则文档),按 packs 过滤
190
+ extra_dirs = _install_skills(target, packs, args,
191
+ (getattr(args, "dsh_profile", "") or "").strip() or None)
192
+
193
+ common._write_install_manifest(args, target, packs, bound_product, mcp_conf,
194
+ extra_dirs, payload_dir=payload_dir)
195
+
196
+
197
+ def _stage_payload():
198
+ """把 server/contract/safety/skills 拷进 ~/.vod-devkit/payloads/<ver>/ 并指过去。
199
+
200
+ 对标 devkit 的 copyServerPayload(D-payload-1):npx 安装时仓在
201
+ ~/.npm/_npx/<hash>/,npm 清缓存/换版本后入口指向已删除路径 → 宿主 MCP 静默掉线。
202
+ """
203
+ from vod_mcp import payload as _payload
204
+ from vod_mcp.host_adapters import base as _base
205
+ dest = _payload.stage()
206
+ # 把安装期运行配置种进载荷(载荷 runtime 与仓内 runtime 是两份文件):
207
+ # 否则 host_product/product/java_base 只写在仓内,真正跑起来的副本看不到
208
+ seeded = {k: v for k, v in common._runtime_cfg_read().items()
209
+ if k in ("product", "host_product", "java_base", "local_ledger")}
210
+ if seeded:
211
+ rt = dest / "vod_mcp" / "runtime.json"
212
+ cur = {}
213
+ if rt.exists():
214
+ try:
215
+ cur = json.loads(rt.read_text(encoding="utf-8"))
216
+ except Exception:
217
+ cur = {}
218
+ cur.update(seeded)
219
+ rt.write_text(json.dumps(cur, ensure_ascii=False, indent=2), encoding="utf-8")
220
+ _base.set_payload_dir(dest)
221
+ return dest
222
+
223
+
224
+ def _install_skills(target: str, packs: str, args, profile: str | None = None):
225
+ """技能段:按 packs 过滤后拷到 hermes 主目录 + 目标宿主的技能发现目录。
226
+
227
+ 目标宿主列表由 integrations/<host>/host.json 的 skillsDir 决定——2026-11-11
228
+ 实锤:dsh 此前不在拷贝分支里,npx 装 dsh 只拿到工具、拿不到任何技能文
229
+ 件(同意前置/逐字回显/追问判定这些话术纪律整层缺失),而 ~/.dsh/skills
230
+ 下的副本是 /opt/vod-install 脚本手工刷的,不是安装器产物。
231
+ 返回 [(host, Path)] 落点清单(供 manifest 名册对账)。"""
232
+ common.HERMES_SKILLS_DIR.mkdir(parents=True, exist_ok=True)
233
+ # opencode 原生技能目录(2026-11-06 实测:opencode 自动发现
234
+ # ~/.config/opencode/skills/ 并经 skill 工具按需加载——此前安装器漏拷,
235
+ # opencode 只有工具描述一条约束通道,话术类约束全部失效)
236
+ extra_dirs = [] # [(host, Path)]
237
+ adapter = HOST_ADAPTERS.get(target)
238
+ dst = adapter.skills_dir(args) if adapter and target != "hermes" else None
239
+ if dst is not None:
240
+ dst.mkdir(parents=True, exist_ok=True)
241
+ extra_dirs.append((target, dst))
242
+ pack_set = set(p for p in packs.split(",") if p)
243
+ for entry in sorted((common.ROOT / "skills").iterdir()):
244
+ if entry.is_dir(): # vod-core / vod-feedback-collect
245
+ skill = entry.name
246
+ if skill == "vod-core" and "core" not in pack_set:
247
+ continue
248
+ if skill == "vod-feedback-collect" and "collect" not in pack_set:
249
+ continue
250
+ dst = common.HERMES_SKILLS_DIR / skill
251
+ if dst.exists():
252
+ shutil.rmtree(dst)
253
+ shutil.copytree(entry, dst)
254
+ for _host, oc_dst in extra_dirs:
255
+ dst2 = oc_dst / skill
256
+ if dst2.exists():
257
+ shutil.rmtree(dst2)
258
+ shutil.copytree(entry, dst2)
259
+ # 领域规则技能为静态副本,与引擎真源的对账见 scripts/rules_provenance.py
260
+ return extra_dirs