vod-devkit 0.5.9 → 0.5.11

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 (152) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/QUICKSTART.md +6 -2
  3. package/README.en.md +23 -2
  4. package/README.md +204 -16
  5. package/{contract → assets/contract}/tools.schema.json +127 -1
  6. package/{skills → assets/skills}/vod-core/SKILL.md +32 -1
  7. package/bin/vod-devkit +21 -1
  8. package/integrations/hermes/hooks/vod_guard.py +127 -0
  9. package/integrations/hermes/hooks/vod_router.py +89 -0
  10. package/integrations/hermes/host.json +4 -1
  11. package/npm/cli.js +6 -1
  12. package/package.json +37 -34
  13. package/packages/dsh/README.md +60 -0
  14. package/packages/dsh/package.json +52 -0
  15. package/plugins/vod-devkit/.codex-plugin/plugin.json +1 -1
  16. package/plugins/vod-devkit/.mcp.json +2 -0
  17. package/plugins/vod-devkit/build-info.json +3 -3
  18. package/plugins/vod-devkit/contract/tools.schema.json +127 -1
  19. package/plugins/vod-devkit/hooks/vod_guard.py +127 -0
  20. package/plugins/vod-devkit/hooks/vod_router.py +89 -0
  21. package/plugins/vod-devkit/skills/vod-core/SKILL.md +32 -1
  22. package/plugins/vod-devkit/vod_mcp/__init__.py +1 -1
  23. package/plugins/vod-devkit/vod_mcp/attribution.py +21 -2
  24. package/plugins/vod-devkit/vod_mcp/config_forms.py +22 -6
  25. package/plugins/vod-devkit/vod_mcp/diagnose.py +4 -2
  26. package/plugins/vod-devkit/vod_mcp/host_adapters/base.py +4 -1
  27. package/plugins/vod-devkit/vod_mcp/host_adapters/codex.py +154 -34
  28. package/plugins/vod-devkit/vod_mcp/host_adapters/dsh.py +133 -22
  29. package/plugins/vod-devkit/vod_mcp/host_adapters/hermes.py +216 -59
  30. package/plugins/vod-devkit/vod_mcp/host_adapters/opencode.py +10 -4
  31. package/plugins/vod-devkit/vod_mcp/hosts.py +4 -0
  32. package/plugins/vod-devkit/vod_mcp/net.py +78 -18
  33. package/plugins/vod-devkit/vod_mcp/packs/__init__.py +97 -22
  34. package/plugins/vod-devkit/vod_mcp/packs/collect.py +50 -42
  35. package/plugins/vod-devkit/vod_mcp/packs/core.py +138 -2
  36. package/plugins/vod-devkit/vod_mcp/paths.py +200 -30
  37. package/plugins/vod-devkit/vod_mcp/payload.py +10 -5
  38. package/plugins/vod-devkit/vod_mcp/provenance.py +1 -1
  39. package/plugins/vod-devkit/vod_mcp/remote_app.py +4 -4
  40. package/plugins/vod-devkit/vod_mcp/runtime_state.py +151 -28
  41. package/plugins/vod-devkit/vod_mcp/server.py +52 -7
  42. package/plugins/vod-devkit/vod_mcp/skills_registry.py +29 -8
  43. package/plugins/vod-devkit/vod_mcp/tools.py +21 -3
  44. package/plugins/vod-devkit/vod_mcp/transport_remote.py +22 -3
  45. package/{vod_mcp → src/vod_mcp}/__init__.py +1 -1
  46. package/{vod_mcp → src/vod_mcp}/attribution.py +21 -2
  47. package/{vod_mcp → src/vod_mcp}/config_forms.py +22 -6
  48. package/{vod_mcp → src/vod_mcp}/diagnose.py +4 -2
  49. package/{vod_mcp → src/vod_mcp}/host_adapters/base.py +4 -1
  50. package/{vod_mcp → src/vod_mcp}/host_adapters/codex.py +154 -34
  51. package/{vod_mcp → src/vod_mcp}/host_adapters/dsh.py +133 -22
  52. package/src/vod_mcp/host_adapters/hermes.py +361 -0
  53. package/{vod_mcp → src/vod_mcp}/host_adapters/opencode.py +10 -4
  54. package/{vod_mcp → src/vod_mcp}/hosts.py +4 -0
  55. package/{vod_mcp → src/vod_mcp}/net.py +78 -18
  56. package/src/vod_mcp/packs/__init__.py +142 -0
  57. package/{vod_mcp → src/vod_mcp}/packs/collect.py +50 -42
  58. package/src/vod_mcp/packs/core.py +216 -0
  59. package/src/vod_mcp/paths.py +208 -0
  60. package/{vod_mcp → src/vod_mcp}/payload.py +10 -5
  61. package/{vod_mcp → src/vod_mcp}/provenance.py +1 -1
  62. package/{vod_mcp → src/vod_mcp}/remote_app.py +4 -4
  63. package/{vod_mcp → src/vod_mcp}/runtime_state.py +151 -28
  64. package/{vod_mcp → src/vod_mcp}/server.py +52 -7
  65. package/{vod_mcp → src/vod_mcp}/skills_registry.py +29 -8
  66. package/{vod_mcp → src/vod_mcp}/tools.py +21 -3
  67. package/{vod_mcp → src/vod_mcp}/transport_remote.py +22 -3
  68. package/src/vodkit_cli/auth_cmd.py +81 -0
  69. package/{vodkit_cli → src/vodkit_cli}/cli.py +38 -8
  70. package/{vodkit_cli → src/vodkit_cli}/common.py +14 -3
  71. package/{vodkit_cli → src/vodkit_cli}/doctor.py +147 -9
  72. package/{vodkit_cli → src/vodkit_cli}/install.py +148 -33
  73. package/src/vodkit_cli/packs_cmd.py +329 -0
  74. package/{vodkit_cli → src/vodkit_cli}/remote.py +3 -3
  75. package/src/vodkit_cli/uninstall.py +315 -0
  76. package/vod_mcp/host_adapters/__pycache__/__init__.cpython-314.pyc +0 -0
  77. package/vod_mcp/host_adapters/__pycache__/__init__.cpython-39.pyc +0 -0
  78. package/vod_mcp/host_adapters/__pycache__/atomcode.cpython-314.pyc +0 -0
  79. package/vod_mcp/host_adapters/__pycache__/atomcode.cpython-39.pyc +0 -0
  80. package/vod_mcp/host_adapters/__pycache__/base.cpython-314.pyc +0 -0
  81. package/vod_mcp/host_adapters/__pycache__/base.cpython-39.pyc +0 -0
  82. package/vod_mcp/host_adapters/__pycache__/codearts.cpython-314.pyc +0 -0
  83. package/vod_mcp/host_adapters/__pycache__/codearts.cpython-39.pyc +0 -0
  84. package/vod_mcp/host_adapters/__pycache__/codeartswork.cpython-314.pyc +0 -0
  85. package/vod_mcp/host_adapters/__pycache__/codeartswork.cpython-39.pyc +0 -0
  86. package/vod_mcp/host_adapters/__pycache__/codex.cpython-314.pyc +0 -0
  87. package/vod_mcp/host_adapters/__pycache__/codex.cpython-39.pyc +0 -0
  88. package/vod_mcp/host_adapters/__pycache__/codex_desktop.cpython-314.pyc +0 -0
  89. package/vod_mcp/host_adapters/__pycache__/codex_desktop.cpython-39.pyc +0 -0
  90. package/vod_mcp/host_adapters/__pycache__/dsh.cpython-314.pyc +0 -0
  91. package/vod_mcp/host_adapters/__pycache__/dsh.cpython-39.pyc +0 -0
  92. package/vod_mcp/host_adapters/__pycache__/generic.cpython-314.pyc +0 -0
  93. package/vod_mcp/host_adapters/__pycache__/generic.cpython-39.pyc +0 -0
  94. package/vod_mcp/host_adapters/__pycache__/hermes.cpython-314.pyc +0 -0
  95. package/vod_mcp/host_adapters/__pycache__/hermes.cpython-39.pyc +0 -0
  96. package/vod_mcp/host_adapters/__pycache__/opencode.cpython-314.pyc +0 -0
  97. package/vod_mcp/host_adapters/__pycache__/opencode.cpython-39.pyc +0 -0
  98. package/vod_mcp/host_adapters/__pycache__/workbuddy.cpython-314.pyc +0 -0
  99. package/vod_mcp/host_adapters/__pycache__/workbuddy.cpython-39.pyc +0 -0
  100. package/vod_mcp/host_adapters/hermes.py +0 -204
  101. package/vod_mcp/packs/__init__.py +0 -67
  102. package/vod_mcp/packs/__pycache__/__init__.cpython-314.pyc +0 -0
  103. package/vod_mcp/packs/__pycache__/__init__.cpython-39.pyc +0 -0
  104. package/vod_mcp/packs/__pycache__/collect.cpython-314.pyc +0 -0
  105. package/vod_mcp/packs/__pycache__/collect.cpython-39.pyc +0 -0
  106. package/vod_mcp/packs/__pycache__/core.cpython-314.pyc +0 -0
  107. package/vod_mcp/packs/__pycache__/core.cpython-39.pyc +0 -0
  108. package/vod_mcp/packs/__pycache__/knowledge.cpython-314.pyc +0 -0
  109. package/vod_mcp/packs/__pycache__/knowledge.cpython-39.pyc +0 -0
  110. package/vod_mcp/packs/core.py +0 -80
  111. package/vod_mcp/paths.py +0 -38
  112. package/vodkit_cli/__pycache__/__init__.cpython-314.pyc +0 -0
  113. package/vodkit_cli/__pycache__/__init__.cpython-39.pyc +0 -0
  114. package/vodkit_cli/__pycache__/cli.cpython-314.pyc +0 -0
  115. package/vodkit_cli/__pycache__/cli.cpython-39.pyc +0 -0
  116. package/vodkit_cli/__pycache__/common.cpython-314.pyc +0 -0
  117. package/vodkit_cli/__pycache__/common.cpython-39.pyc +0 -0
  118. package/vodkit_cli/__pycache__/doctor.cpython-314.pyc +0 -0
  119. package/vodkit_cli/__pycache__/doctor.cpython-39.pyc +0 -0
  120. package/vodkit_cli/__pycache__/install.cpython-314.pyc +0 -0
  121. package/vodkit_cli/__pycache__/install.cpython-39.pyc +0 -0
  122. package/vodkit_cli/__pycache__/remote.cpython-314.pyc +0 -0
  123. package/vodkit_cli/__pycache__/remote.cpython-39.pyc +0 -0
  124. package/vodkit_cli/__pycache__/uninstall.cpython-314.pyc +0 -0
  125. package/vodkit_cli/__pycache__/uninstall.cpython-39.pyc +0 -0
  126. package/vodkit_cli/__pycache__/update.cpython-314.pyc +0 -0
  127. package/vodkit_cli/__pycache__/update.cpython-39.pyc +0 -0
  128. package/vodkit_cli/uninstall.py +0 -161
  129. /package/{safety → assets/safety}/policy.json +0 -0
  130. /package/{skills → assets/skills}/vod-core/references/acceptance-criteria.md +0 -0
  131. /package/{skills → assets/skills}/vod-core/references/verification-method.md +0 -0
  132. /package/{skills → assets/skills}/vod-feedback-collect/SKILL.md +0 -0
  133. /package/{skills → assets/skills}/vod-feedback-collect/references/acceptance-criteria.md +0 -0
  134. /package/{skills → assets/skills}/vod-feedback-collect/references/verification-method.md +0 -0
  135. /package/{skills → assets/skills}/vod-problem-classification-rules/SKILL.md +0 -0
  136. /package/{skills → assets/skills}/vod-scoring-rules/SKILL.md +0 -0
  137. /package/{vod_mcp → src/vod_mcp}/detect_framework.py +0 -0
  138. /package/{vod_mcp → src/vod_mcp}/guardrails.py +0 -0
  139. /package/{vod_mcp → src/vod_mcp}/host_adapters/__init__.py +0 -0
  140. /package/{vod_mcp → src/vod_mcp}/host_adapters/atomcode.py +0 -0
  141. /package/{vod_mcp → src/vod_mcp}/host_adapters/codearts.py +0 -0
  142. /package/{vod_mcp → src/vod_mcp}/host_adapters/codeartswork.py +0 -0
  143. /package/{vod_mcp → src/vod_mcp}/host_adapters/codex_desktop.py +0 -0
  144. /package/{vod_mcp → src/vod_mcp}/host_adapters/generic.py +0 -0
  145. /package/{vod_mcp → src/vod_mcp}/host_adapters/workbuddy.py +0 -0
  146. /package/{vod_mcp → src/vod_mcp}/packs/knowledge.py +0 -0
  147. /package/{vod_mcp → src/vod_mcp}/pending.py +0 -0
  148. /package/{vod_mcp → src/vod_mcp}/policy.py +0 -0
  149. /package/{vod_mcp → src/vod_mcp}/runtime.example.json +0 -0
  150. /package/{vod_mcp → src/vod_mcp}/update_check.py +0 -0
  151. /package/{vodkit_cli → src/vodkit_cli}/__init__.py +0 -0
  152. /package/{vodkit_cli → src/vodkit_cli}/update.py +0 -0
@@ -10,7 +10,8 @@ import sys
10
10
  from pathlib import Path
11
11
 
12
12
  from vod_mcp import hosts as host_specs
13
- from vod_mcp.host_adapters.base import ROOT, server_env, server_entry
13
+ from vod_mcp import paths
14
+ from vod_mcp.host_adapters.base import server_env, server_entry
14
15
 
15
16
  HOST = "hermes"
16
17
  SUPPORTS_REMOTE = True
@@ -28,53 +29,208 @@ def skills_dir(args):
28
29
  return Path(_spec()["skillsDir"])
29
30
 
30
31
 
31
- PLUGIN_NAME = "vod-feedback-router"
32
+ LEGACY_PLUGIN = "vod-feedback-router" # 旧形态(插件包),只用于清理
33
+ HOOK_MARK = "vod_router.py" # 我们这条 shell hook 的识别标志(幂等/摘除共用)
34
+ EVENT = "pre_llm_call"
35
+ HOOK_TIMEOUT = 10
36
+ # 安全面第二条:pre_tool_call(Hermes 把它当**阻塞事件**,stdout 回
37
+ # {"decision":"block"} 或 exit 2 即拦截)。只拦"把 key 读进对话"的动作,
38
+ # 其余一律放行——详见 integrations/hermes/hooks/vod_guard.py。
39
+ GUARD_EVENT = "pre_tool_call"
40
+ GUARD_MARK = "vod_guard.py"
41
+ GUARD_TIMEOUT = 5
32
42
 
33
43
 
34
- def _enabled_plugins() -> list:
35
- """读 hermes 配置里的 plugins.enabled(CLI 输出是 "- name" 行)。
44
+ def _profile_config() -> Path:
45
+ return Path(_spec()["profileConfig"])
36
46
 
37
- 无 CLI 直接返回空:裸 subprocess 会抛 FileNotFoundError 打崩整个 install
38
- (CI/无宿主机器上实测)——缺 CLI 是"降级"不是"失败"。
47
+
48
+ def _hook_script() -> Path:
49
+ return paths.hook_script()
50
+
51
+
52
+ def _hook_command() -> str:
53
+ import shlex
54
+ return f"{shlex.quote(sys.executable)} {shlex.quote(str(_hook_script()))}"
55
+
56
+
57
+ def upsert_hook(text: str, event: str, command: str, timeout: int, mark: str) -> tuple:
58
+ """把一个 shell hook 写进 config.yaml **文本**的指定事件,返回 (new_text, state)。
59
+
60
+ 为什么手改 YAML 文本而不 load/dump:运行时零第三方依赖(无 pyyaml),而
61
+ round-trip dump 会把用户的注释、锚点、顺序全洗掉——那是拿用户的整份配置
62
+ 换我们的方便。所以只做"最小结构插入",并且**形态不认识就抛错**(调用方
63
+ 打印可粘贴片段,绝不猜着改)。
64
+
65
+ mark 是"这条 hook 属于我们"的识别标志(脚本名),幂等与摘除共用同一条判据。
66
+
67
+ state: unchanged(已有本条)/ added(插进已有事件段)/ created(新建 hooks 段)
39
68
  """
40
- if not shutil.which("hermes"):
41
- return []
42
- r = subprocess.run(["hermes", "config", "get", "plugins.enabled"],
43
- capture_output=True, text=True, timeout=60)
44
- if r.returncode != 0:
45
- return []
46
- out = []
47
- for line in (r.stdout or "").splitlines():
48
- line = line.strip()
49
- if line.startswith("- "):
50
- out.append(line[2:].strip())
51
- elif line.startswith("-"):
52
- out.append(line[1:].strip())
53
- return [x for x in out if x]
54
-
55
-
56
- def enable_plugin(name: str = PLUGIN_NAME) -> str:
57
- """把路由插件加进 plugins.enabled(幂等)。返回 created / unchanged / skipped。
58
-
59
- 只追加一个名字:读现有名单 → 追加 → `hermes config set plugins.enabled '[...]'`。
60
- 不整文件改 config.yaml(用户可能手改过格式/注释),失败只提示不动。
69
+ if command in text and mark in text:
70
+ return (text, "unchanged")
71
+ lines = text.splitlines()
72
+ entries = [f'- command: "{command}"', f' timeout: {timeout}']
73
+
74
+ def _is_ours(line: str) -> bool:
75
+ return mark in line and "command" in line
76
+
77
+ idx_hooks = next((i for i, ln in enumerate(lines) if ln.rstrip() == "hooks:"), None)
78
+ if idx_hooks is None:
79
+ if any(ln.startswith("hooks:") for ln in lines):
80
+ raise RuntimeError("config.yaml 的 hooks 段不是块形态(hooks: 后有值),"
81
+ "拒绝自动插入")
82
+ out = list(lines)
83
+ if out and out[-1].strip():
84
+ out.append("")
85
+ out += ["hooks:", f" {event}:", " " + entries[0], " " + entries[1]]
86
+ return ("\n".join(out) + "\n", "created")
87
+
88
+ if any(_is_ours(ln) for ln in lines):
89
+ return (text, "unchanged")
90
+
91
+ # hooks 段结束位置:下一个缩进为 0 的非空行
92
+ end_hooks = len(lines)
93
+ for j in range(idx_hooks + 1, len(lines)):
94
+ if lines[j].strip() and not lines[j][0].isspace():
95
+ end_hooks = j
96
+ break
97
+ idx_event = next((i for i in range(idx_hooks + 1, end_hooks)
98
+ if lines[i].strip() == f"{event}:"), None)
99
+ if idx_event is None:
100
+ insert_at = idx_hooks + 1
101
+ new_lines = [f" {event}:", " " + entries[0], " " + entries[1]]
102
+ state = "added"
103
+ else:
104
+ # 插到该事件列表末尾:下一个缩进 <= 2 的非空行,或 hooks 段结束
105
+ insert_at = idx_event + 1
106
+ for j in range(idx_event + 1, end_hooks):
107
+ ln = lines[j]
108
+ if not ln.strip():
109
+ continue
110
+ indent = len(ln) - len(ln.lstrip())
111
+ if indent <= 2:
112
+ insert_at = j
113
+ break
114
+ insert_at = j + 1
115
+ new_lines = [" " + entries[0], " " + entries[1]]
116
+ state = "added"
117
+ out = lines[:insert_at] + new_lines + lines[insert_at:]
118
+ return ("\n".join(out) + "\n", state)
119
+
120
+
121
+ def upsert_llm_hook(text: str, command: str, timeout: int = HOOK_TIMEOUT) -> tuple:
122
+ """预采集路由(pre_llm_call)——薄壳,保留历史签名给已有用例。"""
123
+ return upsert_hook(text, EVENT, command, timeout, HOOK_MARK)
124
+
125
+
126
+ def upsert_guard_hook(text: str, command: str, timeout: int = GUARD_TIMEOUT) -> tuple:
127
+ """读 Key 拦截(pre_tool_call,阻塞事件)——薄壳。"""
128
+ return upsert_hook(text, GUARD_EVENT, command, timeout, GUARD_MARK)
129
+
130
+
131
+ def remove_hook(text: str, mark: str) -> tuple:
132
+ """从 config.yaml 文本里摘掉含 mark 的 hook 项(幂等)。返回 (new_text, removed?)。
133
+
134
+ 只删含 mark 的 `- command:` 行及其紧随的 `timeout:` 行;其余条目(别人的
135
+ hook、用户的注释、事件段本身若是空的也留着)一律不动——空事件段无害,删别人的
136
+ 配置才是有害的。
137
+ """
138
+ lines = text.splitlines()
139
+ out, removed, i = [], False, 0
140
+ while i < len(lines):
141
+ ln = lines[i]
142
+ if "- command:" in ln and mark in ln:
143
+ removed = True
144
+ i += 1
145
+ if i < len(lines) and lines[i].strip().startswith("timeout:"):
146
+ i += 1
147
+ continue
148
+ out.append(ln)
149
+ i += 1
150
+ return ("\n".join(out) + ("\n" if text.endswith("\n") else ""), removed)
151
+
152
+
153
+ def remove_llm_hook(text: str) -> tuple:
154
+ return remove_hook(text, HOOK_MARK)
155
+
156
+
157
+ def remove_guard_hook(text: str) -> tuple:
158
+ return remove_hook(text, GUARD_MARK)
159
+
160
+
161
+ def _guard_command() -> str:
162
+ import shlex
163
+ return f"{shlex.quote(sys.executable)} {shlex.quote(str(paths.guard_script()))}"
164
+
165
+
166
+ def _register_hooks(cfg_path: Path) -> None:
167
+ """装两条 shell hook(同一套脚本机制,各自事件注册)。
168
+
169
+ - `pre_llm_call`:预采集意图路由(注入采集纪律),非阻塞;
170
+ - `pre_tool_call`:只拦"读 runtime.json / 导出 VOD_*KEY"的动作,Hermes 的**阻塞**事件。
171
+
172
+ 两条都幂等;config.yaml 形态不认识时只打可粘贴片段,绝不猜着重写用户配置。
173
+ 单条失败不阻塞另一条(hook 与 MCP 配置是两条独立链)。
174
+ """
175
+ try:
176
+ text = cfg_path.read_text(encoding="utf-8") if cfg_path.exists() else ""
177
+ except OSError as e:
178
+ print(f"[vod-devkit] warn: 读不到 {cfg_path}({e}),两条 hook 均未注册",
179
+ file=sys.stderr)
180
+ return
181
+ plans = (
182
+ ("预采集 hook", EVENT, _hook_command(), HOOK_TIMEOUT, upsert_llm_hook),
183
+ ("读 Key 拦截 hook", GUARD_EVENT, _guard_command(), GUARD_TIMEOUT, upsert_guard_hook),
184
+ )
185
+ for label, event, cmd, timeout, upsert in plans:
186
+ try:
187
+ new_text, state = upsert(text, cmd)
188
+ except RuntimeError as e:
189
+ print(f"[vod-devkit] warn: {label}未注册({e})。请手动把下面两行加进 "
190
+ f"{cfg_path} 的 hooks.{event}:\n"
191
+ f" - command: \"{cmd}\"\n timeout: {timeout}", file=sys.stderr)
192
+ continue
193
+ if state != "unchanged":
194
+ try:
195
+ cfg_path.parent.mkdir(parents=True, exist_ok=True)
196
+ cfg_path.write_text(new_text, encoding="utf-8")
197
+ except OSError as e:
198
+ print(f"[vod-devkit] warn: {label}写入失败({e})", file=sys.stderr)
199
+ continue
200
+ text = new_text
201
+ verb = {"created": "已新建 hooks 段", "added": f"已加入 hooks.{event}",
202
+ "unchanged": "已存在"}[state]
203
+ print(f"已注册{label}({cfg_path},{verb};首次使用 hermes 会弹一次同意)")
204
+
205
+
206
+ def remove_legacy_plugin() -> str:
207
+ """摘旧插件形态(幂等):删目录 + 从 plugins.enabled 去名。
208
+
209
+ 为什么必须做:老装机里插件与新的 shell hook 会**同时生效**,每轮注入两段
210
+ 指令(模型看到重复要求,行为不可预测)。迁移必须单向收敛到 hook。
61
211
  """
62
- import json as _json
63
- if not shutil.which("hermes"):
64
- print("提示:未找到 hermes CLI,路由插件需手动在 plugins.enabled 中加入 "
65
- f"{name} 后生效")
66
- return "skipped"
67
- cur = _enabled_plugins()
68
- if name in cur:
69
- return "unchanged"
70
- merged = cur + [name]
71
- r = subprocess.run(["hermes", "config", "set", "plugins.enabled",
72
- _json.dumps(merged)], capture_output=True, text=True, timeout=60)
73
- if r.returncode != 0:
74
- print("提示:自动启用路由插件失败(" + (r.stderr or r.stdout).strip()[:120]
75
- + ");请手动把 " + name + " 加入 plugins.enabled")
76
- return "skipped"
77
- return "created"
212
+ removed = []
213
+ d = Path.home() / ".hermes" / "plugins" / LEGACY_PLUGIN
214
+ if d.exists():
215
+ shutil.rmtree(d, ignore_errors=True)
216
+ removed.append(f"目录 {d}")
217
+ if shutil.which("hermes"):
218
+ r = subprocess.run(["hermes", "config", "get", "plugins.enabled"],
219
+ capture_output=True, text=True, timeout=60)
220
+ names = []
221
+ for line in (r.stdout or "").splitlines():
222
+ line = line.strip()
223
+ if line.startswith("- "):
224
+ names.append(line[2:].strip())
225
+ elif line.startswith("-"):
226
+ names.append(line[1:].strip())
227
+ if LEGACY_PLUGIN in names:
228
+ keep = [n for n in names if n and n != LEGACY_PLUGIN]
229
+ rr = subprocess.run(["hermes", "config", "set", "plugins.enabled",
230
+ json.dumps(keep)], capture_output=True, text=True, timeout=60)
231
+ if rr.returncode == 0:
232
+ removed.append("plugins.enabled 条目")
233
+ return ";".join(removed)
78
234
 
79
235
 
80
236
  def install(args, packs: str) -> Path:
@@ -100,18 +256,15 @@ def install(args, packs: str) -> Path:
100
256
  print(f"提示:未找到 hermes CLI(PATH),已写出配置片段:{conf}\n"
101
257
  " 将其并入 ~/.hermes/config.yaml 的 mcp_servers 后重启会话生效",
102
258
  file=sys.stderr)
103
- # D-hook-1:强制评估路由插件(pre_llm_call 确定性意图路由,业界 forced-eval 模式)
104
- plug_src = ROOT / "hermes-plugin" / "vod-feedback-router"
105
- plug_dst = Path.home() / ".hermes" / "plugins" / PLUGIN_NAME
106
- if plug_src.is_dir():
107
- if plug_dst.exists():
108
- shutil.rmtree(plug_dst)
109
- shutil.copytree(plug_src, plug_dst)
110
- state = enable_plugin()
111
- verb = {"created": "已自动加入 plugins.enabled",
112
- "unchanged": "已在 plugins.enabled 中",
113
- "skipped": "未自动启用(见上方提示)"}[state]
114
- print(f"已安装 {PLUGIN_NAME} 路由插件(~/.hermes/plugins/,{verb};重启会话生效)")
259
+ # D-hook-unify-1:预采集路由走 config.yaml 的 hooks.pre_llm_call(shell hook)。
260
+ # 不再装 Python 插件:同一个"stdin JSON → stdout context"脚本可被任何宿主
261
+ # 用各自的机制注册,宿主进程内不需要 import 我们的代码。
262
+ # D-key-guard-4:同一套脚本机制再注册一条 hooks.pre_tool_call(阻塞事件),
263
+ # 只拦"读 runtime.json / 导出 VOD_*KEY"的动作——机制化技能里的"只引指纹"。
264
+ _register_hooks(_profile_config())
265
+ legacy = remove_legacy_plugin()
266
+ if legacy:
267
+ print(f"已清理旧插件形态(避免与新 hook 双份注入):{legacy}")
115
268
  if r is None:
116
269
  pass # 无 CLI:上面已经给过指引
117
270
  elif r.returncode == 0:
@@ -137,7 +290,10 @@ def install_remote(args, url, token):
137
290
  """
138
291
  import os
139
292
  env = os.environ.copy()
140
- env["MCP_VOD_DEVKIT_API_KEY"] = token
293
+ # token 可选(D-token-machine-1):没有就不注入——请求不带 Bearer,
294
+ # 由远程 server 用机器级匿名令牌提交(同机部署默认形态)。
295
+ if token:
296
+ env["MCP_VOD_DEVKIT_API_KEY"] = token
141
297
 
142
298
  def _yes_forever():
143
299
  # 交互问数随 hermes 版本变化(首次装=2 问,覆盖装=3 问),流式供给不数数
@@ -160,9 +316,10 @@ def install_remote(args, url, token):
160
316
  sys.exit(1)
161
317
  conf = Path(_spec()["configPath"]).parent / "vod-devkit.json"
162
318
  conf.parent.mkdir(parents=True, exist_ok=True)
163
- conf.write_text(json.dumps({"name": "vod-devkit", "url": url,
164
- "headers": {"Authorization": "Bearer ${MCP_VOD_DEVKIT_API_KEY}"}},
165
- ensure_ascii=False, indent=2), encoding="utf-8")
319
+ payload = {"name": "vod-devkit", "url": url}
320
+ if token: # 无 token 时不写 headers:请求不带 Bearer,走服务端匿名令牌
321
+ payload["headers"] = {"Authorization": "Bearer ${MCP_VOD_DEVKIT_API_KEY}"}
322
+ conf.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
166
323
  print(f"已注册 Hermes 远程 MCP({url};token 存 ~/.hermes/.env,配置内只留引用)")
167
324
  return conf
168
325
 
@@ -43,10 +43,16 @@ def install(args, packs: str) -> Path:
43
43
 
44
44
 
45
45
  def install_remote(args, url, token):
46
- """mcp.vod-devkit = {type:remote, url, enabled, headers}(headers 明文,提示权限)。"""
46
+ """mcp.vod-devkit = {type:remote, url, enabled, headers?}(headers 明文,提示权限)。
47
+
48
+ token 可选(D-token-machine-1):给了就写 Authorization(调用方自带身份);
49
+ 没给就不写 headers——请求无 Bearer,由远程 server 用机器级匿名令牌提交。
50
+ """
47
51
  conf = Path(_SPEC["configPath"])
48
- entry = {"type": "remote", "url": url, "enabled": True,
49
- "headers": {"Authorization": f"Bearer {token}"}}
52
+ entry = {"type": "remote", "url": url, "enabled": True}
53
+ if token:
54
+ entry["headers"] = {"Authorization": f"Bearer {token}"}
50
55
  action = merge_json_mcp(conf, entry)
51
- print(f"已写入 OpenCode 远程 MCP 配置({action}):{conf}(token 随配置存放,注意文件权限)")
56
+ suffix = "(token 随配置存放,注意文件权限)" if token else "(未带 token:走服务端匿名令牌)"
57
+ print(f"已写入 OpenCode 远程 MCP 配置({action}):{conf}{suffix}")
52
58
  return conf
@@ -99,4 +99,8 @@ def load(host: str, profile: str | None = None) -> dict:
99
99
  for x in raw.get("managedPaths") or []],
100
100
  "notes": raw.get("notes") or "",
101
101
  }
102
+ # 可选键:宿主的"配置文件本体"落点(如 hermes 的 config.yaml)——
103
+ # 只在一部分宿主上有意义,没写就不出现(不塞 None 让调用方猜)
104
+ if raw.get("profileConfig"):
105
+ spec["profileConfig"] = _resolve(_pick(raw["profileConfig"]), profile)
102
106
  return spec
@@ -19,18 +19,72 @@ _REQ_KEY = contextvars.ContextVar("vod_req_key", default=None)
19
19
 
20
20
  _SERVER_FACE = contextvars.ContextVar("vod_server_face", default=False)
21
21
 
22
+ # 匿名令牌代领总开关(D-token-machine-1 安全护栏):进程级布尔,启动期由
23
+ # transport_remote 按绑定地址决定——非回环绑定(可能被反代/公网触达)默认关闭
24
+ # 代领,避免"任何能连端口的进程都能用这台机的身份提交、消耗额度"。
25
+ # 回环绑定(同机部署的默认形态)保持开启,与本地 stdio 完全一致。
26
+ ANON_MINT_DISABLED = False
22
27
 
23
- def _eff_key(explicit=None) -> str:
24
- """当前生效的 key:显式参数 > 请求头(HTTP 面)> env/runtime(stdio 面)。"""
25
- if explicit is not None:
26
- return explicit
27
- return _REQ_KEY.get() or JAVA_KEY
28
28
 
29
+ def _live(field: str, default: str = "") -> str:
30
+ """身份类值的**调用期**解析:env(平台注入)> runtime.json 现读 > 默认。
29
31
 
30
- JAVA_BASE = os.environ.get("VOD_JAVA_API_BASE") or rt._RT.get("java_base") or DEFAULT_JAVA_BASE
32
+ 为什么不能在 import 期定常量(D-state-read-1):MCP server 是长驻进程,
33
+ `auth init --apply` 换 key、自动领取匿名令牌、安装器改 apiBase 都会改
34
+ runtime.json;常量把进程启动那一刻的值冻结住,表现是"明明配了/换了 key,
35
+ 工具仍用旧的"(401 或打到旧环境)。读失败回落默认,不阻断出口。
36
+ """
37
+ env_key = "VOD_JAVA_API_KEY" if field == "java_key" else "VOD_JAVA_API_BASE"
38
+ env = os.environ.get(env_key, "")
39
+ if env:
40
+ return env
41
+ try:
42
+ val = rt._runtime_cfg().get(field)
43
+ except Exception: # noqa: BLE001 状态文件坏/不可读时不阻断出口
44
+ val = None
45
+ if val:
46
+ return str(val)
47
+ # 镜像回落:本进程刚写的值(_runtime_update 同步镜像)与测试桩都走这条路;
48
+ # 文件优先保证"外部(auth init / 重装)改过的值"立刻生效。
49
+ return str(rt._RT.get(field) or default)
50
+
51
+
52
+ def _java_key() -> str:
53
+ # 显式 set 过的模块属性优先(monkeypatch / 历史赋值):这是仓内已有的 patch 面契约
54
+ # ("共享符号用模块属性访问"),现读只在**没人 set** 时生效。
55
+ override = globals().get("JAVA_KEY")
56
+ if override:
57
+ return str(override)
58
+ return _live("java_key", "")
59
+
60
+
61
+ def _java_base() -> str:
62
+ override = globals().get("JAVA_BASE")
63
+ if override:
64
+ return str(override)
65
+ return _live("java_base", DEFAULT_JAVA_BASE)
66
+
67
+
68
+ def __getattr__(name: str):
69
+ """`net.JAVA_KEY` / `net.JAVA_BASE` 一律**现读**(PEP 562 模块级 __getattr__)。
70
+
71
+ 保留这两个名字只为不动既有调用点与测试的 patch 面:属性被显式 set 过
72
+ (monkeypatch / 历史赋值)时优先用 set 的值,否则每次现读 runtime。
73
+ 模块**内部**必须直接调 `_java_key()` / `_java_base()`——模块内部的全局名查找
74
+ 不会触发 __getattr__,写成 `JAVA_KEY` 会 NameError 或读到旧值。
75
+ """
76
+ if name == "JAVA_KEY":
77
+ return _java_key()
78
+ if name == "JAVA_BASE":
79
+ return _java_base()
80
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
31
81
 
32
82
 
33
- JAVA_KEY = os.environ.get("VOD_JAVA_API_KEY", "") or rt._RT.get("java_key", "") # ExternalApiKeyFilter Bearer
83
+ def _eff_key(explicit=None) -> str:
84
+ """当前生效的 key:显式参数 > 请求头(HTTP 面)> env/runtime(stdio 面)。"""
85
+ if explicit is not None:
86
+ return explicit
87
+ return _REQ_KEY.get() or _java_key()
34
88
 
35
89
 
36
90
  _META_PATH = "/rest/developer/manager/hdvodmngservice/v1/external/meta"
@@ -65,7 +119,7 @@ def _load_meta(force: bool = False) -> dict:
65
119
  "dictVersion": cache["data"].get("dictVersion"),
66
120
  "stale": False, "source": "cache"}
67
121
  try:
68
- out = _http("GET", _META_PATH, None, base=JAVA_BASE, key=_eff_key(), timeout=10)
122
+ out = _http("GET", _META_PATH, None, base=_java_base(), key=_eff_key(), timeout=10)
69
123
  data = out.get("data") or {}
70
124
  if isinstance(data.get("products"), list) and data["products"]:
71
125
  rt._runtime_update({"meta_cache": {"fetchedAt": int(now), "data": data}})
@@ -95,8 +149,8 @@ def _http(method: str, path: str, body: dict | None = None,
95
149
  base/key 缺省在调用时解析模块级配置(不能用函数默认值——定义时即冻结,
96
150
  环境变更/测试 monkeypatch 均无法生效)。
97
151
  """
98
- base = base if base is not None else JAVA_BASE
99
- key = key if key is not None else JAVA_KEY
152
+ base = base if base is not None else _java_base()
153
+ key = key if key is not None else _java_key()
100
154
  # 传输协议守卫:非本机回环一律要求 https(Bearer 不得明文过公网)
101
155
  _host = base.split("//", 1)[-1].split("/", 1)[0].split(":")[0]
102
156
  if not base.startswith("https://") and _host not in ("127.0.0.1", "localhost", "::1"):
@@ -145,7 +199,7 @@ def probe_key(key: str | None = None, timeout: int = 8) -> dict:
145
199
  不判定——网络问题不是 key 问题,报"无法验证"而非"无效"
146
200
  """
147
201
  explicit = key is not None # 显式传参(服务面=请求头 Bearer)按显式口径判
148
- key = key if key is not None else JAVA_KEY
202
+ key = key if key is not None else _java_key()
149
203
  fp = _fingerprint(key)
150
204
  if not key:
151
205
  return {"ok": None, "reason": "no-key", "fingerprint": None}
@@ -168,7 +222,7 @@ def probe_key(key: str | None = None, timeout: int = 8) -> dict:
168
222
  return {"ok": False, "reason": "device-mismatch", "fingerprint": fp,
169
223
  "note": "匿名令牌与本设备不匹配:令牌本身有效,"
170
224
  "在本设备重新申请令牌后可继续(POST /external/token,"
171
- "首次提交自动完成)"}
225
+ "首次提交或 vod_auth_ensure 时自动完成)"}
172
226
  if not (explicit or _explicit_key()):
173
227
  # 匿名令牌 401 ≠ 配置错误:报"过期待重领"而非"rejected",
174
228
  # 避免 runtime 残留过期匿名令牌时被误读为正式 key 失效
@@ -180,9 +234,9 @@ def probe_key(key: str | None = None, timeout: int = 8) -> dict:
180
234
 
181
235
 
182
236
  def _key_state() -> dict:
183
- return {"configured": bool(JAVA_KEY), "fingerprint": _fingerprint(JAVA_KEY),
184
- "base": JAVA_BASE,
185
- "note": "已配置" if JAVA_KEY else "未配置(首次提交自动取匿名令牌)"}
237
+ return {"configured": bool(_java_key()), "fingerprint": _fingerprint(_java_key()),
238
+ "base": _java_base(),
239
+ "note": "已配置" if _java_key() else "未配置(首次提交或 vod_auth_ensure 时自动取匿名令牌)"}
186
240
 
187
241
 
188
242
  def _explicit_key() -> bool:
@@ -195,7 +249,9 @@ def _explicit_key() -> bool:
195
249
  """
196
250
  if bool(os.environ.get("VOD_JAVA_API_KEY")):
197
251
  return True
198
- return bool(JAVA_KEY) and str(rt._RT.get("token_tier") or "") != "anonymous"
252
+ tier = str(rt._runtime_cfg().get("token_tier")
253
+ or rt._RT.get("token_tier") or "")
254
+ return bool(_java_key()) and tier != "anonymous"
199
255
 
200
256
 
201
257
  def _legacy_key_hint() -> str:
@@ -235,7 +291,9 @@ def _fetch_anon_token() -> str | None:
235
291
  D-anon-verify(2026-11-05 真机实锤):引擎返回 ApiResponse 信封,
236
292
  顶层取 token 恒 None → 无 key 首提必 -32012,信封解析为必经路径。"""
237
293
  try:
238
- out = _http("POST", _TOKEN_PATH, {}, base=JAVA_BASE, key="", timeout=15)
294
+ if ANON_MINT_DISABLED:
295
+ return None # 非回环远程面:不代领(调用方须自带 Bearer)
296
+ out = _http("POST", _TOKEN_PATH, {}, base=_java_base(), key="", timeout=15)
239
297
  return _extract_anon_token(out)
240
298
  except ToolError:
241
299
  return None
@@ -245,7 +303,9 @@ def _acquire_anon_token_or_raise() -> str:
245
303
  """缺 key/匿名令牌失效 → 领零字段匿名令牌;端点不可用则如实报错。"""
246
304
  token = _fetch_anon_token()
247
305
  if not token:
306
+ hint = (";远程面若绑定非回环地址,代领默认关闭——请带 Authorization: Bearer <key>,"
307
+ "或服务端以 --allow-anon-mint 显式开启" if ANON_MINT_DISABLED else "")
248
308
  raise ToolError(
249
309
  "未配置接入 key 且匿名令牌端点不可用。引导:"
250
- + ";".join(str(g["label"]) for g in _KEY_GUIDANCE), code=-32012)
310
+ + ";".join(str(g["label"]) for g in _KEY_GUIDANCE) + hint, code=-32012)
251
311
  return token