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
@@ -9,8 +9,8 @@ ALL_PACKS = ("core", "collect", "knowledge")
9
9
 
10
10
  PACK_TOOLS = {
11
11
  # vod_search_products:问用户"是哪个产品"前给候选(只读,D-product-ask-1)
12
- "core": ["vod_devkit_info", "vod_auth_status", "vod_check_update",
13
- "vod_search_products"],
12
+ "core": ["vod_devkit_info", "vod_auth_status", "vod_auth_ensure", "vod_check_update",
13
+ "vod_search_products", "vod_packs_configure"],
14
14
  # 两段式(D-token-approval-2 极简形态)随 collect 下发;codex 话术走 draft→commit
15
15
  "collect": ["vod_submit_voices", "vod_draft_voices", "vod_commit_voices", "vod_list_submitted"],
16
16
  # 领域规则技能披露(第二轨):知道有哪几本规则、按需取全文。
@@ -19,25 +19,53 @@ PACK_TOOLS = {
19
19
  }
20
20
 
21
21
 
22
- BREAKER_MARKERS = (
23
- # 熔断标记(D-codex-circuit-breaker-1):install 门禁可被
24
- # `VOD_PACKS=core,collect serve` 绕过——运行期同查标记强制降级
25
- os.path.expanduser("~/.codex/vod-collect-suspended.json"),
26
- )
22
+ BREAKER_MARKERS = ()
23
+ # 熔断标记(D-codex-circuit-breaker-1):install 门禁可被 `VOD_PACKS=core,collect serve`
24
+ # 绕过——运行期同查标记强制降级。默认值**调用期解析**(不用 import 期 expanduser:
25
+ # 测试 monkeypatch HOME 时模块常量会钉在真机 HOME 上,标记就查错了机器);
26
+ # 非空即视为测试注入的显式清单(monkeypatch.setattr(packs, "BREAKER_MARKERS", ...))。
27
+ def breaker_markers() -> tuple:
28
+ if BREAKER_MARKERS:
29
+ return tuple(BREAKER_MARKERS)
30
+ return (os.path.expanduser("~/.codex/vod-collect-suspended.json"),)
27
31
 
28
32
 
29
33
  def enabled_packs() -> tuple:
30
- raw = os.environ.get("VOD_PACKS", "").strip()
34
+ return _resolve(os.environ.get("VOD_PACKS", "").strip())
35
+
36
+
37
+ class UnknownPack(ValueError):
38
+ """VOD_PACKS 里出现未知包 id。
39
+
40
+ 对齐 devkit 口径:**启动即报错**,不静默过滤。静默过滤=操作者以为关掉的还开着、
41
+ 以为打开的其实没装——"看起来配了没生效"是比崩溃更难查的一类故障。
42
+ """
43
+
44
+
45
+ def parse_packs(raw: str) -> tuple:
46
+ """解析 VOD_PACKS 字面值(逗号分隔,kb=knowledge 旧称)。未知 id 抛 UnknownPack。"""
31
47
  if not raw:
32
48
  return ALL_PACKS
33
- # kb=knowledge 旧称别名(历史文档/用户习惯;深审 P0-2 配套:安装口
34
- # 旧值不因运行口改名而静默失效)
35
- packs = tuple(p.strip() for p in raw.split(","))
36
- packs = tuple("knowledge" if p == "kb" else p for p in packs)
37
- packs = tuple(p for p in packs if p in ALL_PACKS)
49
+ ids = []
50
+ for part in raw.split(","):
51
+ p = part.strip()
52
+ if not p:
53
+ continue
54
+ ids.append("knowledge" if p == "kb" else p)
55
+ unknown = [p for p in ids if p not in ALL_PACKS]
56
+ if unknown:
57
+ raise UnknownPack(
58
+ f"VOD_PACKS 含未知包 id: {','.join(unknown)};可用: {','.join(ALL_PACKS)}")
59
+ return tuple(ids) or ALL_PACKS
60
+
61
+
62
+ def _resolve(raw: str) -> tuple:
63
+ if not raw:
64
+ return ALL_PACKS
65
+ packs = parse_packs(raw)
38
66
  if "core" not in packs:
39
67
  packs = ("core",) + packs
40
- if "collect" in packs and any(os.path.isfile(m) for m in BREAKER_MARKERS):
68
+ if "collect" in packs and any(os.path.isfile(m) for m in breaker_markers()):
41
69
  # 运行期熔断门禁:collect 强制摘除(非静默——stderr 告警)。
42
70
  # 解除=删熔断标记(install --ack-suspension 即此语义)
43
71
  packs = tuple(p for p in packs if p != "collect")
@@ -48,20 +76,67 @@ def enabled_packs() -> tuple:
48
76
  return packs
49
77
 
50
78
 
51
- # 服务面(HTTP 传输)摘除的"写本机状态"工具——对齐 huaweicloud-devkit 的
52
- # remoteSurface 门控语义:远程面没有"本机"这个概念。
53
- # draft/commit:草稿暂存在本机 runtime.json,HTTP 面由多客户端共享一个进程,
54
- # "本机草稿"既不隔离也不可审计;
55
- # list_submitted:本地账本是装机维度的记录,服务面读它不是客户端想要的答案
56
- # (跨机对账走引擎端点)。
79
+ # 服务面(HTTP 传输)摘除的工具。(2026-11-16 D-token-machine-1 修订:远程面收窄为
80
+ # 只剩这一项——远程部署的实际形态是"同一台机器上独立跑一个 MCP server 进程,
81
+ # 多个 agent 通过 HTTP 连它",和本地同一套身份/账本语义,所以 draft/commit/ledger 都放开。)
82
+ # packs_configure:会话内开关是**进程内状态**,HTTP 面每请求现造 server、无会话,
83
+ # 开关会在下一个请求消失("以为改了其实没改");且多 agent 共用进程时会互相影响。
84
+ # draft/commit 放开的前置是**草稿归属隔离**:草稿落 owner(宿主名+身份 hash),commit 校验归属,
85
+ # 避免同机两个 agent 之间"A 的草稿被 B 提交"(collect.draft_voices / commit_voices)。
57
86
  # 注意:submit 不摘——它对 VOD 的唯一动作是调用引擎 HTTP API,落库是服务端的事。
58
- REMOTE_WITHHELD = ("vod_draft_voices", "vod_commit_voices", "vod_list_submitted")
87
+ REMOTE_WITHHELD = ("vod_packs_configure",)
59
88
 
60
89
 
61
90
  def enabled_tools(remote: bool = False) -> list:
62
91
  tools = []
63
- for pack in enabled_packs():
92
+ for pack in effective_packs():
64
93
  tools.extend(PACK_TOOLS[pack])
65
94
  if remote:
66
95
  tools = [t for t in tools if t not in REMOTE_WITHHELD]
67
96
  return tools
97
+
98
+
99
+ # ── 会话内开关(D-packs-configure-1) ─────────────────────
100
+ #
101
+ # 与 CLI `packs enable|disable --apply` 分工:CLI 写宿主配置(持久,重启用),
102
+ # 这里只改进程内状态(立即生效,重启即清)。**不写 env、不写配置**——MCP 工具
103
+ # 去改宿主配置文件会把"谁改的"变成猜谜,而持久化面已经有一个可解释入口。
104
+
105
+ _RUNTIME: tuple | None = None
106
+
107
+
108
+ class PackRefused(PermissionError):
109
+ """运行期拒绝(安全门禁,如采集熔断)。与 UnknownPack(拼写错)分开报。"""
110
+
111
+
112
+ def effective_packs() -> tuple:
113
+ """当前生效的包:会话内开关优先,否则按 VOD_PACKS(含 core 强制与熔断)。"""
114
+ return _RUNTIME if _RUNTIME is not None else enabled_packs()
115
+
116
+
117
+ def normalize_packs(ids) -> tuple:
118
+ """归一请求的包列表:去重、kb 别名、core 强制、未知 id 报错、熔断拦截。"""
119
+ want = []
120
+ for p in ids:
121
+ p = (p or "").strip()
122
+ if not p:
123
+ continue
124
+ p = "knowledge" if p == "kb" else p
125
+ if p not in ALL_PACKS:
126
+ raise UnknownPack(
127
+ f"未知包 id: {p};可用: {','.join(ALL_PACKS)}")
128
+ if p not in want:
129
+ want.append(p)
130
+ if "collect" in want and any(os.path.isfile(m) for m in breaker_markers()):
131
+ # 熔断是安全门禁:显式开启也不能绕过。静默摘掉等于"配了没生效"。
132
+ raise PackRefused(
133
+ "采集熔断生效(codex 未确认提交 ≥2 次,D-codex-circuit-breaker-1):"
134
+ "会话内不能开启 collect;解除须删熔断标记")
135
+ return tuple(dict.fromkeys(["core"] + want))
136
+
137
+
138
+ def set_runtime_packs(ids) -> tuple:
139
+ """设置会话内生效包;ids 为 None 时恢复按 VOD_PACKS。返回新生效 tuple。"""
140
+ global _RUNTIME
141
+ _RUNTIME = None if ids is None else normalize_packs(ids)
142
+ return effective_packs()
@@ -39,7 +39,7 @@ def _attribute_product(items: list, params: dict, client_info: dict | None = Non
39
39
  ① 用户明确回答/确认(params.product,仅问过用户后由模型填)
40
40
  ② 原话唯一且高置信提及(多产品/歧义=低置信,转去问)
41
41
  ③ 会话记忆(30 分钟滑动,进程内;跨会话不继承)
42
- ④ 安装先验
42
+ ④ 安装先验(**仅在原话出现自指时生效**:D-product-ask-1 修订 A,2026-11-16)
43
43
  四级都拿不到(含用户明确说"不知道/随便"= params.productNotSpecified)→
44
44
  返回 source=unknown + confidence=low,由调用方抛可执行错误要求追问。
45
45
  **不做 host_default 兜底**(2026-11-12 复评删除:宿主产品也是一次推断,
@@ -415,13 +415,9 @@ def submit_voices(params: dict, client_info: dict | None = None,
415
415
  out = net._http("POST", _EXISTING_SUBMIT, body, base=net.JAVA_BASE, key=net._eff_key())
416
416
  return vid, (out.get("data") or {}).get("taskId")
417
417
 
418
- # 服务面(HTTP):身份只能来自请求头。缺 key 时 fail fast——不先打引擎再
419
- # 靠 401 兜底(那会多一次无意义外呼,且引擎若宽容 200 就绕过了守卫)。
420
- if net._SERVER_FACE.get() and not net._eff_key():
421
- raise net.ToolError(
422
- "服务面(HTTP 传输)不代签身份:请在本请求带上 Authorization: Bearer "
423
- "<VOD key>(插件只搬运身份,不产生身份;落库与配额都在服务端)",
424
- code=-32012)
418
+ # 服务面(HTTP):身份优先取请求头 Bearer;没有就同本地一样走机器级匿名令牌
419
+ # (D-token-machine-1 定稿:本地/远程同一套身份语义。远程多租户若需按调用方隔离,
420
+ # 由调用方带 Bearer 显式给出身份;匿名是"整机一份"的低信任档)
425
421
 
426
422
  # 缺产品且用户没说不知道 → 可执行错误(先问一次),不许裸提交 UNKNOWN
427
423
  _require_product_or_ask(attr, items, client_info)
@@ -451,20 +447,13 @@ def submit_voices(params: dict, client_info: dict | None = None,
451
447
  if ex.code == 404:
452
448
  fallback = True # 囤积端点未部署 → 落到下方 legacy 回落
453
449
  elif not net._eff_key() or ex.code == -32012:
454
- if net._SERVER_FACE.get():
455
- # 服务面(HTTP):不代签身份。匿名令牌按设备锚点签发,一进程
456
- # 一锚点会把配额/声量/归因全搅在一起(服务端多用户形态的
457
- # 已拍板口径:formal/host key + 按请求透传)。
458
- raise net.ToolError(
459
- "服务面(HTTP 传输)不代签身份:请在本请求带上 "
460
- "Authorization: Bearer <VOD key>,或改用 stdio 形态的匿名链",
461
- code=-32012)
462
450
  if net._explicit_key():
463
451
  _raise_explicit_key_rejected(net._eff_key())
464
452
  # 缺 key/匿名令牌失效 → 零字段匿名令牌 → 落 runtime.json → 重试一次
465
453
  token = net._acquire_anon_token_or_raise()
466
- net.JAVA_KEY = token
467
- rt._save_runtime({"java_key": token, "token_tier": "anonymous"})
454
+ # 统一状态入口(落盘 + 镜像);net 的 key 是调用期现读,不再写模块属性——
455
+ # 写属性会让 __getattr__ 失效、这份 token 又被冻结在进程里(D-state-read-1)
456
+ rt._runtime_update({"java_key": token, "token_tier": "anonymous"})
468
457
  out = net._http("POST", _SUBMIT_HOARDING, body, base=net.JAVA_BASE, key=net._eff_key())
469
458
  else:
470
459
  raise # 网络/413 等如实上抛
@@ -516,16 +505,11 @@ def submit_voices(params: dict, client_info: dict | None = None,
516
505
  voice_ids.append(vid)
517
506
  task_ids.append(None)
518
507
  elif (not net._eff_key() or e.code == -32012) and not voice_ids:
519
- if net._SERVER_FACE.get():
520
- rejected.append({"index": i, "reason":
521
- "服务面(HTTP 传输)不代签身份:请带 Authorization: Bearer <VOD key>"})
522
- continue
523
508
  if net._explicit_key():
524
509
  _raise_explicit_key_rejected(net._eff_key())
525
510
  # 零字段匿名令牌:缺 key/401 → 自动取令牌 → 落 runtime.json → 重试一次
526
511
  token = net._acquire_anon_token_or_raise()
527
- net.JAVA_KEY = token
528
- rt._save_runtime({"java_key": token, "token_tier": "anonymous"})
512
+ rt._runtime_update({"java_key": token, "token_tier": "anonymous"})
529
513
  vid, tid = _legacy_submit(i, v, content)
530
514
  accepted += 1
531
515
  voice_ids.append(vid)
@@ -614,11 +598,16 @@ def draft_voices(params: dict, client_info: dict | None = None) -> dict:
614
598
  payload_sha = hashlib.sha256(
615
599
  json.dumps(payload, sort_keys=True, ensure_ascii=False).encode()).hexdigest()
616
600
 
617
- with rt._RT_LOCK: # 读改写整段持锁:并发 draft 不互相丢草稿
618
- store = rt._drafts_load()
601
+ def _mutate(cfg: dict):
602
+ store = rt._drafts_purge(cfg.get(rt._DRAFT_KEY) or {})
619
603
  store[draft_id] = {
620
604
  "payload": payload, "payloadSha256": payload_sha,
621
605
  "tokenHash": rt._sha256(token),
606
+ # 草稿归属(D-token-machine-1 远程面放开两段式的前置):
607
+ # 同机多个 agent 共用一个远程 server 时草稿池是共享的,
608
+ # 记录创建者、commit 时校验,避免"A 的草稿被 B 提交"。
609
+ # 旧草稿无 owner 字段 → commit 兼容放行(升级不断回合)。
610
+ "owner": rt._session_key(client_info),
622
611
  # D-resume-commit-1:token 明文随草稿落盘(runtime.json 0600,与 java_key
623
612
  # 同级保护)。token 的威胁模型是"防载荷改写"而非"同意凭证"——落盘不放大
624
613
  # 风险,换断回合可续:agent 回合中断后凭 draftId 即可恢复提交(此前
@@ -631,7 +620,9 @@ def draft_voices(params: dict, client_info: dict | None = None) -> dict:
631
620
  }
632
621
  while len(store) > rt._DRAFT_CAP: # 环形:最旧先淘汰
633
622
  store.pop(next(iter(store)))
634
- rt._save_runtime({rt._DRAFT_KEY: store})
623
+ cfg[rt._DRAFT_KEY] = store
624
+
625
+ rt._runtime_atomic(_mutate) # 读整键→改→写整键必须整段在锁内(跨进程)
635
626
 
636
627
  out = {
637
628
  "draftId": draft_id,
@@ -660,22 +651,39 @@ def commit_voices(params: dict, client_info: dict | None = None) -> dict:
660
651
  if not draft_id:
661
652
  raise net.ToolError("draftId 为必填(取自 vod_draft_voices 返回原样透传)", code=-32602)
662
653
 
663
- store = rt._drafts_load()
664
- draft = store.get(draft_id)
665
- if draft is None:
666
- raise net.ToolError("草稿不存在或已过期(10 分钟 TTL),请重新 vod_draft_voices", code=-32011)
667
- token = str(params.get("approvalToken", "")) or str(draft.get("token", ""))
668
- payload_sha = str(params.get("payloadSha256", "")) or str(draft["payloadSha256"])
669
- if draft["tokenHash"] != rt._sha256(token):
670
- raise net.ToolError("审批令牌不匹配(draft 返回的 approvalToken 原样透传)", code=-32011)
671
- if draft["payloadSha256"] != payload_sha:
672
- raise net.ToolError("载荷校验不符(payloadSha256 与 draft 签发值不一致,禁止改写已确认内容)",
673
- code=-32011)
674
- # 单次消费:先摘除再提交——提交中途崩溃也不会二次提交(宁可丢一单重走流程)
675
- # 整段持锁:并发 commit 同一 draftId 时只有一方能消费成功
676
- with rt._RT_LOCK:
654
+ holder: dict = {}
655
+
656
+ def _consume(cfg: dict) -> None:
657
+ """校验 + 单次消费**同一事务内**完成。
658
+
659
+ 为什么不能在锁外读 store 再进锁里 pop:读到的是一份快照,覆盖回去会把别的
660
+ draft 甚至已消费的草稿复活(跨进程时尤其明显)。
661
+ """
662
+ store = rt._drafts_purge(cfg.get(rt._DRAFT_KEY) or {})
663
+ draft = store.get(draft_id)
664
+ if draft is None:
665
+ raise net.ToolError("草稿不存在或已过期(10 分钟 TTL),请重新 vod_draft_voices",
666
+ code=-32011)
667
+ owner = draft.get("owner")
668
+ if owner and owner != rt._session_key(client_info):
669
+ raise net.ToolError(
670
+ "这份草稿不属于当前客户端(草稿按宿主/会话隔离:只能由创建它的那个 agent 提交)",
671
+ code=-32011)
672
+ token = str(params.get("approvalToken", "")) or str(draft.get("token", ""))
673
+ payload_sha = str(params.get("payloadSha256", "")) or str(draft["payloadSha256"])
674
+ if draft["tokenHash"] != rt._sha256(token):
675
+ raise net.ToolError("审批令牌不匹配(draft 返回的 approvalToken 原样透传)",
676
+ code=-32011)
677
+ if draft["payloadSha256"] != payload_sha:
678
+ raise net.ToolError("载荷校验不符(payloadSha256 与 draft 签发值不一致,禁止改写已确认内容)",
679
+ code=-32011)
680
+ # 单次消费:提交中途崩溃也不会二次提交(宁可丢一单重走流程)
677
681
  store.pop(draft_id)
678
- rt._save_runtime({rt._DRAFT_KEY: store})
682
+ cfg[rt._DRAFT_KEY] = store
683
+ holder["draft"] = draft
684
+
685
+ rt._runtime_atomic(_consume)
686
+ draft = holder["draft"]
679
687
 
680
688
  out = submit_voices(dict(draft["payload"]), client_info,
681
689
  ledger_extra={"stage": "committed", "draftId": draft_id})
@@ -1,4 +1,10 @@
1
- """core pack:自述、认证自检、版本提醒、产品候选检索(只读,零写盘副作用)。"""
1
+ """core pack:自述、认证自检、版本提醒、产品候选检索(只读,零写盘副作用)。
2
+
3
+ 例外:`auth_ensure` 是唯一有写盘副作用的认证工具(领匿名令牌后落 state),
4
+ 显式 key 一律不覆盖、远程面不领取(见 D-token-machine-1)。
5
+ """
6
+ import os
7
+
2
8
  from vod_mcp import attribution as _attrib
3
9
  from vod_mcp import net, provenance
4
10
 
@@ -43,6 +49,53 @@ def devkit_info(params: dict, client_info: dict | None = None) -> dict:
43
49
  return provenance.info_payload(client_info)
44
50
 
45
51
 
52
+ def _pack_ids(v) -> list:
53
+ if isinstance(v, str):
54
+ return [x.strip() for x in v.split(",") if x.strip()]
55
+ if isinstance(v, (list, tuple)):
56
+ return [str(x) for x in v]
57
+ return []
58
+
59
+
60
+ def packs_configure(params: dict, client_info: dict | None = None) -> dict:
61
+ """会话内开关能力包(stdio 面;远程面在 REMOTE_WITHHELD 里被摘除)。
62
+
63
+ 只改进程内状态:不写 env、不写宿主配置(持久化面是 CLI `packs
64
+ enable|disable --apply`,一个概念只留一个写入口)。返回新生效面 + 工具清单,
65
+ 由 server 侧推 tools/list_changed。
66
+ """
67
+ from vod_mcp import packs as _packs
68
+ reset = bool(params.get("reset"))
69
+ enable = _pack_ids(params.get("enable") or [])
70
+ disable = _pack_ids(params.get("disable") or [])
71
+ if not reset and not enable and not disable:
72
+ raise net.ToolError("参数为空:给 enable / disable(包 id)或 reset=true", code=-32602)
73
+ current = _packs.effective_packs()
74
+ try:
75
+ if reset:
76
+ new = _packs.set_runtime_packs(None)
77
+ else:
78
+ want = [p for p in current if p not in set(disable)] + enable
79
+ new = _packs.set_runtime_packs(want)
80
+ except _packs.UnknownPack as e:
81
+ raise net.ToolError(str(e), code=-32602) from e
82
+ except _packs.PackRefused as e:
83
+ # 安全门禁拒绝(熔断):不是参数错,别让模型以为改个拼写就能开
84
+ raise net.ToolError(str(e), code=-32015) from e
85
+ added = [p for p in new if p not in current]
86
+ removed = [p for p in current if p not in new]
87
+ return {
88
+ "packs": list(new),
89
+ "added": added,
90
+ "removed": removed,
91
+ "tools": _packs.enabled_tools(),
92
+ "changed": bool(added or removed),
93
+ "persisted": False,
94
+ "note": ("会话内生效、重启即清;持久化用 CLI:"
95
+ "vod-devkit packs enable|disable <id> --apply"),
96
+ }
97
+
98
+
46
99
  def auth_status(params: dict, client_info: dict | None = None) -> dict:
47
100
  """认证自检:指纹化输出(明文永不出现),无 key 也跑并给引导。
48
101
 
@@ -55,7 +108,7 @@ def auth_status(params: dict, client_info: dict | None = None) -> dict:
55
108
  req_key = net._eff_key() if net._SERVER_FACE.get() else None
56
109
  out = {
57
110
  "javaKey": net._key_state(),
58
- "packs": sorted(__import__("vod_mcp.packs", fromlist=["enabled_packs"]).enabled_packs()),
111
+ "packs": sorted(__import__("vod_mcp.packs", fromlist=["effective_packs"]).effective_packs()),
59
112
  }
60
113
  if req_key:
61
114
  out["requestKey"] = {"fingerprint": net._fingerprint(req_key),
@@ -78,3 +131,86 @@ def auth_status(params: dict, client_info: dict | None = None) -> dict:
78
131
  def check_update(params: dict, client_info: dict | None = None) -> dict:
79
132
  from vod_mcp import update_check as uc
80
133
  return uc.check(params)
134
+
135
+
136
+ def auth_ensure(params: dict, client_info: dict | None = None) -> dict:
137
+ """判 + 领(D-token-machine-1):幂等,显式 key 一律不覆盖。
138
+
139
+ 与 auth_status 的分工:status 只读,ensure 是唯一的"需要时替你领一枚"入口。
140
+ 判定表(返回值 source 指明身份从哪来,方便事后审计):
141
+ · VOD_JAVA_API_KEY 显式存在 → 只探针,source=env,绝不覆盖
142
+ · runtime 有令牌且 verified → source=runtime,changed=false(不重复领)
143
+ · no-key / expired-anonymous /
144
+ device-mismatch → 领零字段匿名令牌 → 落 state → 复探
145
+ · rejected(显式 key 被引擎拒) → **不领**,fail fast(不静默降档)
146
+ · unreachable → **不领**,verified=null(网络问题不是身份问题)
147
+
148
+ 远程面同样是这套语义(D-token-machine-1 定稿:本地/远程同一个效果):
149
+ 请求头 Bearer 优先(调用方自带身份就用它);没有就由服务端领/复用机器级匿名令牌。
150
+ 多租户部署要按调用方隔离时,各调用方带自己的 Bearer;匿名档就是"整机一份"的低信任档。
151
+ """
152
+ from vod_mcp import runtime_state as rt
153
+
154
+ req_key = net._eff_key() if net._SERVER_FACE.get() else None
155
+ has_key = bool(req_key) or bool(net._java_key())
156
+ # source 要能回答问题"这身份是哪来的":运行时显式 key(auth init 写入)、
157
+ # 请求头身份、自动领的匿名令牌不是一回事——被拒后的处置也不同。
158
+ if req_key:
159
+ source = "request"
160
+ elif os.environ.get("VOD_JAVA_API_KEY"):
161
+ source = "env"
162
+ elif has_key and net._explicit_key():
163
+ source = "runtime-key"
164
+ elif has_key:
165
+ source = "runtime-anonymous"
166
+ else:
167
+ source = "none"
168
+
169
+ if source in ("runtime-anonymous", "new-anonymous"):
170
+ tier = "anonymous"
171
+ elif source == "none":
172
+ tier = "none"
173
+ else:
174
+ tier = "formal"
175
+
176
+ probe = (net.probe_key(req_key) if req_key
177
+ else (net.probe_key() if has_key else
178
+ {"ok": None, "reason": "no-key", "fingerprint": None}))
179
+ if probe.get("ok") is True:
180
+ return {"tier": tier, "source": source, "verified": True,
181
+ "reason": probe.get("reason"), "fingerprint": probe.get("fingerprint"),
182
+ "changed": False, "base": net._java_base()}
183
+
184
+ reason = probe.get("reason")
185
+ # 显式身份被拒:配置错误必须冒出来,静默换匿名 = 归因/额度双错位。
186
+ # 显式=请求头 Bearer / env key / runtime 里的正式 key(tier≠anonymous)。
187
+ if reason == "rejected" and (req_key or os.environ.get("VOD_JAVA_API_KEY")
188
+ or net._explicit_key()):
189
+ return {"tier": tier, "source": source, "verified": False, "reason": "rejected",
190
+ "fingerprint": probe.get("fingerprint"), "changed": False,
191
+ "base": net._java_base(),
192
+ "guidance": [{"action": "fix-key", "label": "显式 key 被引擎拒绝:换一把有效 key"
193
+ "(auth init --key … --apply),不要落到匿名档"}]}
194
+ if reason == "unreachable":
195
+ return {"tier": tier, "source": source, "verified": None,
196
+ "reason": "unreachable", "fingerprint": probe.get("fingerprint"),
197
+ "changed": False, "base": net._java_base(),
198
+ "note": "引擎不可达:未领取、未判定——网络问题不等于令牌问题"}
199
+
200
+ # 需要领:no-key / expired-anonymous / device-mismatch(以及过期但探针没给原文)
201
+ token = net._fetch_anon_token()
202
+ if not token:
203
+ hint = (";远程面若绑定非回环地址,代领默认关闭——请带 Authorization: Bearer <key>,"
204
+ "或服务端以 --allow-anon-mint 显式开启" if net.ANON_MINT_DISABLED else "")
205
+ raise net.ToolError(
206
+ "未配置接入 key 且匿名令牌端点不可用。引导:"
207
+ + ";".join(str(g["label"]) for g in net._KEY_GUIDANCE) + hint, code=-32012)
208
+ rt._runtime_update({"java_key": token, "token_tier": "anonymous"})
209
+ probe2 = net.probe_key()
210
+ return {"tier": "anonymous", "source": "new-anonymous",
211
+ "verified": probe2.get("ok"), "reason": probe2.get("reason") or reason,
212
+ "fingerprint": probe2.get("fingerprint"), "changed": True,
213
+ "base": net._java_base()}
214
+
215
+
216
+