vod-devkit 0.3.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/bin/vod-devkit +26 -1
- package/contract/tools.schema.json +25 -7
- package/package.json +3 -1
- package/plugins/vod-devkit/.codex-plugin/plugin.json +1 -1
- package/plugins/vod-devkit/build-info.json +3 -3
- package/plugins/vod-devkit/skills/vod-feedback-collect/SKILL.md +38 -1
- package/plugins/vod-devkit/vod_mcp/__init__.py +1 -1
- package/plugins/vod-devkit/vod_mcp/pending.py +139 -0
- package/plugins/vod-devkit/vod_mcp/policy.py +4 -4
- package/plugins/vod-devkit/vod_mcp/tools.py +221 -119
- package/skills/vod-feedback-collect/SKILL.md +38 -1
- package/vod_mcp/__init__.py +1 -1
- package/vod_mcp/pending.py +139 -0
- package/vod_mcp/policy.py +4 -4
- package/vod_mcp/tools.py +221 -119
|
@@ -30,12 +30,17 @@ _FOLLOWUP_DECLINES = frozenset({
|
|
|
30
30
|
|
|
31
31
|
def _followup_fields(voice: dict) -> dict:
|
|
32
32
|
"""D-followup-impl-2 单源提取(submit 主路径与 draft 暂存共用,禁双边漂移):
|
|
33
|
-
仅 trim 非空且非拒答词才含键;引擎同口径截 2000;内容永不回流 content。
|
|
33
|
+
仅 trim 非空且非拒答词才含键;引擎同口径截 2000;内容永不回流 content。
|
|
34
|
+
followupStatus(评审八点 #3 引擎侧承载的插件上报):三态白名单归一
|
|
35
|
+
(strip+lower),白名单外/缺失省键——引擎侧降 NULL 不拒收,插件侧同口径双保险。"""
|
|
34
36
|
out = {}
|
|
35
37
|
for _f in ("reproSteps", "expectedBehavior"):
|
|
36
38
|
_val = str(voice.get(_f) or "").strip()
|
|
37
39
|
if _val and _val.lower() not in _FOLLOWUP_DECLINES:
|
|
38
40
|
out[_f] = _val[:2000]
|
|
41
|
+
_st = str(voice.get("followupStatus") or "").strip().lower()
|
|
42
|
+
if _st in ("not_asked", "declined", "answered"):
|
|
43
|
+
out["followupStatus"] = _st
|
|
39
44
|
return out
|
|
40
45
|
|
|
41
46
|
_CONTRACT_PATH = Path(__file__).resolve().parent.parent / "contract" / "tools.schema.json"
|
|
@@ -221,6 +226,13 @@ def _install_nonce() -> str:
|
|
|
221
226
|
if not n:
|
|
222
227
|
import uuid
|
|
223
228
|
n = uuid.uuid4().hex[:8]
|
|
229
|
+
# 首装 nonce 必须同步回写内存态 _RT(D-dev-nonce-sync,2026-11-09 真机实锤):
|
|
230
|
+
# _RT 仅模块导入时加载一次,_save_runtime 只落盘——不同步则同进程内每次调用
|
|
231
|
+
# 生成新 nonce:领令牌(设备 A)与提交(设备 B)设备绑定校验失败,重试仍
|
|
232
|
+
# 新 nonce(设备 C)再 401——全新安装首次提交必失败冒给用户(存量安装
|
|
233
|
+
# runtime.json 已有 nonce 不受影响)。同步后领令牌/提交同设备,401→领令牌
|
|
234
|
+
# →重试全程进程内无感。
|
|
235
|
+
_RT["install_nonce"] = n
|
|
224
236
|
try:
|
|
225
237
|
_save_runtime({"install_nonce": n})
|
|
226
238
|
except Exception:
|
|
@@ -238,6 +250,15 @@ def _voice_id(source: str, content: str, nonce: str) -> str:
|
|
|
238
250
|
return f"ext_{source}_{hashlib.sha1((content + nonce).encode('utf-8')).hexdigest()[:12]}"
|
|
239
251
|
|
|
240
252
|
|
|
253
|
+
def _legacy_key_hint() -> str:
|
|
254
|
+
"""旧版残留凭据自愈提示(评审拍板项):出错时给可操作路径,不发公告靠用户撞。
|
|
255
|
+
含当前插件版本与重装命令——重装会刷新 runtime/清掉旧 key 残留。"""
|
|
256
|
+
version = getattr(__import__("vod_mcp"), "__version__", "unknown")
|
|
257
|
+
return ("若为旧版安装残留凭据:更新插件(当前 v" + version + ")并重装即可清除——"
|
|
258
|
+
"npx vod-devkit@latest install --target <宿主> --product <产品名>;"
|
|
259
|
+
"或移除 VOD_JAVA_API_KEY 环境变量走匿名档")
|
|
260
|
+
|
|
261
|
+
|
|
241
262
|
def _explicit_key() -> bool:
|
|
242
263
|
"""当前 JAVA_KEY 是否为显式配置(正式/宿主 key)而非本会话自动领取的匿名令牌。
|
|
243
264
|
|
|
@@ -251,6 +272,133 @@ def _explicit_key() -> bool:
|
|
|
251
272
|
return bool(JAVA_KEY) and str(_RT.get("token_tier") or "") != "anonymous"
|
|
252
273
|
|
|
253
274
|
|
|
275
|
+
# ── D-pending-1:无通道期 pending 反馈 flush(方案 A,2026-11-09)──
|
|
276
|
+
|
|
277
|
+
def _flush_pending(product):
|
|
278
|
+
"""补提交 ~/.vod-devkit/pending-feedback.jsonl 里 status=pending 的条目。
|
|
279
|
+
|
|
280
|
+
口径(D-pending-1 定稿):同步执行但失败只记日志、绝不回滚主提交;
|
|
281
|
+
幂等键=条目级(sha1(content+confirmAt+source)),内容级去重由引擎
|
|
282
|
+
uk_voice_id 承担(同内容重提=skipped);重写+原子 rename,失败条目
|
|
283
|
+
保留 pending;单次上限 100 条最早优先,超 30 天标记 expired 剔除。
|
|
284
|
+
双通道消息分离:本函数结果只进工具内部诊断(result.pendingFlush),
|
|
285
|
+
用户侧话术由 skill 层承担(已暂存/自动补交,禁止出现路径)。
|
|
286
|
+
"""
|
|
287
|
+
from vod_mcp import pending as _pq
|
|
288
|
+
path = _pq.default_path()
|
|
289
|
+
entries = _pq.load_entries(path)
|
|
290
|
+
if not entries:
|
|
291
|
+
return {"scanned": 0}
|
|
292
|
+
plan = _pq.plan_flush(entries)
|
|
293
|
+
kept = list(plan["kept"])
|
|
294
|
+
flushed, failed, corrected = 0, 0, 0
|
|
295
|
+
for e in plan["to_flush"]:
|
|
296
|
+
content = _pq.canonical_content(e) # D-pending-1 补强:originalLines 权威拼接,剥模型加的标点
|
|
297
|
+
if content != str(e.get("content", "")):
|
|
298
|
+
corrected += 1
|
|
299
|
+
_log("pending flush: content 与 originalLines 拼接不一致,以 originalLines 为准(剥除模型拼接改动)")
|
|
300
|
+
hv = {"title": str(content)[:60], "content": str(content)}
|
|
301
|
+
if e.get("tags"):
|
|
302
|
+
hv["tags"] = e["tags"]
|
|
303
|
+
body = {"voices": [hv]}
|
|
304
|
+
if product:
|
|
305
|
+
body["product"] = product
|
|
306
|
+
try:
|
|
307
|
+
out = _http("POST", _SUBMIT_HOARDING, body, base=JAVA_BASE, key=JAVA_KEY)
|
|
308
|
+
ids = (out or {}).get("voiceIds") or ((out or {}).get("data") or {}).get("voiceIds")
|
|
309
|
+
if ids is None:
|
|
310
|
+
failed += 1
|
|
311
|
+
kept.append(e)
|
|
312
|
+
_log("pending flush: 回执未含 voiceIds,条目保留")
|
|
313
|
+
else:
|
|
314
|
+
flushed += 1 # 含幂等 skipped(同内容重提=引擎 skipped,零重复)
|
|
315
|
+
except Exception as err:
|
|
316
|
+
failed += 1
|
|
317
|
+
kept.append(e)
|
|
318
|
+
_log(f"pending flush failed (kept pending): {err}")
|
|
319
|
+
_pq.save_entries(path, kept)
|
|
320
|
+
return {"scanned": len(entries), "flushed": flushed,
|
|
321
|
+
"failed": failed, "expired": len(plan["expired"]),
|
|
322
|
+
"corrected": corrected}
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def _collect_voice_items(params: dict) -> tuple[list, list]:
|
|
327
|
+
"""校验段:content 非空+≤2000 字(契约 maxLength,防超大 payload)。
|
|
328
|
+
返回 (items[(index, voice, content)], rejected 明细)。"""
|
|
329
|
+
items, rejected = [], []
|
|
330
|
+
for i, v in enumerate(params.get("voices", [])):
|
|
331
|
+
content = str(v.get("content", "")).strip()
|
|
332
|
+
if not content:
|
|
333
|
+
rejected.append({"index": i, "reason": "content 为空"})
|
|
334
|
+
elif len(content) > 2000:
|
|
335
|
+
rejected.append({"index": i, "reason": f"content 超 2000 字({len(content)})"})
|
|
336
|
+
else:
|
|
337
|
+
items.append((i, v, content))
|
|
338
|
+
return items, rejected
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def _echo_plan(items: list, vids: list) -> dict:
|
|
342
|
+
"""回显段(方案 A,2026-11-06 拍板):提交回执强制携带原话回显。
|
|
343
|
+
检测型防线——宿主模型改写用户原话(实锤:"体验不好"→"不友好")
|
|
344
|
+
在回执处当场可见;agent 必须原样转述,改写露馅。"""
|
|
345
|
+
ok = [(vid, items[min(i, len(items) - 1)][2])
|
|
346
|
+
for i, vid in enumerate(vids) if vid]
|
|
347
|
+
return {
|
|
348
|
+
"requiresUserEcho": bool(ok),
|
|
349
|
+
"instruction": ("请向用户原样转述已收录内容:每条以「已收录原话:」开头,"
|
|
350
|
+
"后接 content 全文。禁止改写、概括、增删字词。"),
|
|
351
|
+
"contents": [{"voiceId": vid, "content": c} for vid, c in ok],
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def _ledger_submit(items: list, vids: list, tids: list, product: str | None,
|
|
356
|
+
extra: dict | None = None) -> None:
|
|
357
|
+
"""账本段:回执 voiceIds/taskIds 逐条落本地账本(层级①查询的源)。"""
|
|
358
|
+
import time as _time
|
|
359
|
+
entries = [{"voiceId": vid, "taskId": tid,
|
|
360
|
+
"title": items[min(i, len(items) - 1)][2][:40],
|
|
361
|
+
"product": product, "at": _time.strftime("%Y-%m-%dT%H:%M:%S")}
|
|
362
|
+
for i, (vid, tid) in enumerate(zip(vids, tids))]
|
|
363
|
+
if extra:
|
|
364
|
+
for e in entries:
|
|
365
|
+
e.update(extra) # 两段式:stage=committed + draftId 关联(验收③)
|
|
366
|
+
_ledger_append(entries)
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def _hoard_voice(v: dict, content: str) -> dict:
|
|
370
|
+
"""载荷段:单条囤积端点 voice 载荷(title/content + tags/userType +
|
|
371
|
+
D-followup-impl-2 追问补充透传:单源 _followup_fields,拒答词集兜底)。"""
|
|
372
|
+
hv = {"title": content[:60], "content": content}
|
|
373
|
+
if v.get("tags"): # 采集层三分类(problem_type:值)→正式入库
|
|
374
|
+
hv["tags"] = v["tags"]
|
|
375
|
+
if v.get("userType"):
|
|
376
|
+
hv["userType"] = v["userType"]
|
|
377
|
+
hv.update(_followup_fields(v))
|
|
378
|
+
return hv
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def _raise_explicit_key_rejected(key: str) -> None:
|
|
382
|
+
"""显式 key(安装注入/正式档)被引擎 401 拒绝 → fail fast:
|
|
383
|
+
不取匿名令牌、不覆盖配置——静默降级匿名档=配置错误被吞
|
|
384
|
+
(归因错位比报错更糟,同 AIShell 错归病根)。囤积/legacy 两路径同口径。"""
|
|
385
|
+
raise ToolError(
|
|
386
|
+
f"注入的 key 被引擎拒绝(指纹 {_fingerprint(key)}):"
|
|
387
|
+
"请核对 key 是否过期/被吊销,或移除 key 走匿名档。"
|
|
388
|
+
+ _legacy_key_hint(),
|
|
389
|
+
code=-32012)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def _acquire_anon_token_or_raise() -> str:
|
|
393
|
+
"""缺 key/匿名令牌失效 → 领零字段匿名令牌;端点不可用则如实报错。"""
|
|
394
|
+
token = _fetch_anon_token()
|
|
395
|
+
if not token:
|
|
396
|
+
raise ToolError(
|
|
397
|
+
"未配置接入 key 且匿名令牌端点不可用。引导:"
|
|
398
|
+
+ ";".join(g["label"] for g in _KEY_GUIDANCE), code=-32012)
|
|
399
|
+
return token
|
|
400
|
+
|
|
401
|
+
|
|
254
402
|
def submit_voices(params: dict, client_info: dict | None = None,
|
|
255
403
|
ledger_extra: dict | None = None) -> dict:
|
|
256
404
|
"""V16 切换:主路径=囤积端点 POST /external/voices(Bearer,批式,不触发分析);
|
|
@@ -266,46 +414,12 @@ def submit_voices(params: dict, client_info: dict | None = None,
|
|
|
266
414
|
import uuid
|
|
267
415
|
host = (client_info or {}).get("name") or "unknown-host"
|
|
268
416
|
product, ignored_runtime = _resolve_product(params)
|
|
269
|
-
accepted, voice_ids, task_ids, rejected = 0, [], [], []
|
|
270
417
|
global JAVA_KEY
|
|
271
|
-
|
|
272
|
-
items =
|
|
273
|
-
for i, v in enumerate(voices_in):
|
|
274
|
-
content = str(v.get("content", "")).strip()
|
|
275
|
-
if not content:
|
|
276
|
-
rejected.append({"index": i, "reason": "content 为空"})
|
|
277
|
-
continue
|
|
278
|
-
if len(content) > 2000: # 契约 maxLength 2000:内容边界(防超大 payload)
|
|
279
|
-
rejected.append({"index": i, "reason": f"content 超 2000 字({len(content)})"})
|
|
280
|
-
continue
|
|
281
|
-
items.append((i, v, content))
|
|
418
|
+
accepted, voice_ids, task_ids = 0, [], []
|
|
419
|
+
items, rejected = _collect_voice_items(params)
|
|
282
420
|
if not items:
|
|
283
421
|
return {"accepted": 0, "voiceIds": [], "taskIds": [], "rejected": rejected}
|
|
284
422
|
|
|
285
|
-
def _echo(vids):
|
|
286
|
-
"""方案 A(2026-11-06 拍板):提交回执强制携带原话回显。
|
|
287
|
-
检测型防线——宿主模型改写用户原话(实锤:"体验不好"→"不友好")
|
|
288
|
-
在回执处当场可见;agent 必须原样转述,改写露馅。"""
|
|
289
|
-
ok = [(vid, items[min(i, len(items) - 1)][2])
|
|
290
|
-
for i, vid in enumerate(vids) if vid]
|
|
291
|
-
return {
|
|
292
|
-
"requiresUserEcho": bool(ok),
|
|
293
|
-
"instruction": ("请向用户原样转述已收录内容:每条以「已收录原话:」开头,"
|
|
294
|
-
"后接 content 全文。禁止改写、概括、增删字词。"),
|
|
295
|
-
"contents": [{"voiceId": vid, "content": c} for vid, c in ok],
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
def _ledger(vids, tids):
|
|
299
|
-
import time as _time
|
|
300
|
-
entries = [{"voiceId": vid, "taskId": tid,
|
|
301
|
-
"title": items[min(i, len(items) - 1)][2][:40],
|
|
302
|
-
"product": product, "at": _time.strftime("%Y-%m-%dT%H:%M:%S")}
|
|
303
|
-
for i, (vid, tid) in enumerate(zip(vids, tids))]
|
|
304
|
-
if ledger_extra:
|
|
305
|
-
for e in entries:
|
|
306
|
-
e.update(ledger_extra) # 两段式:stage=committed + draftId 关联(验收③)
|
|
307
|
-
_ledger_append(entries)
|
|
308
|
-
|
|
309
423
|
def _legacy_submit(i, v, content):
|
|
310
424
|
"""过渡回落:老链单条提交(提交即分析语义,仅 404 触发)。"""
|
|
311
425
|
nonce = uuid.uuid4().hex[:8] # 调用级:重试复用,跨调用不重复
|
|
@@ -324,20 +438,7 @@ def submit_voices(params: dict, client_info: dict | None = None,
|
|
|
324
438
|
return vid, (out.get("data") or {}).get("taskId")
|
|
325
439
|
|
|
326
440
|
# ---- 主路径:囤积端点批式提交 ----
|
|
327
|
-
|
|
328
|
-
for i, v, content in items:
|
|
329
|
-
hv = {"title": content[:60], "content": content}
|
|
330
|
-
tags = v.get("tags") # 采集层三分类(problem_type:值)→【类型名】标题前缀正式入库
|
|
331
|
-
if tags:
|
|
332
|
-
hv["tags"] = tags
|
|
333
|
-
ut = v.get("userType")
|
|
334
|
-
if ut:
|
|
335
|
-
hv["userType"] = ut
|
|
336
|
-
# D-followup-impl-2 追问补充透传:单源 _followup_fields(拒答词集兜底+
|
|
337
|
-
# 引擎同口径截 2000+禁回流 content;未追问/答"没有"=键集合零漂移)
|
|
338
|
-
hv.update(_followup_fields(v))
|
|
339
|
-
hoard_voices.append(hv)
|
|
340
|
-
body = {"voices": hoard_voices}
|
|
441
|
+
body = {"voices": [_hoard_voice(v, content) for _, v, content in items]}
|
|
341
442
|
if product: # 无归因不带 product(引擎 UNKNOWN 档),不本地拦截
|
|
342
443
|
body["product"] = product
|
|
343
444
|
out = None
|
|
@@ -349,20 +450,9 @@ def submit_voices(params: dict, client_info: dict | None = None,
|
|
|
349
450
|
fallback = True # 囤积端点未部署 → 落到下方 legacy 回落
|
|
350
451
|
elif not JAVA_KEY or ex.code == -32012:
|
|
351
452
|
if _explicit_key():
|
|
352
|
-
|
|
353
|
-
# 不取匿名令牌、不覆盖配置——静默降级匿名档=配置错误被吞
|
|
354
|
-
#(归因错位比报错更糟,同 AIShell 错归病根)
|
|
355
|
-
raise ToolError(
|
|
356
|
-
f"注入的 key 被引擎拒绝(指纹 {_fingerprint(JAVA_KEY)}):"
|
|
357
|
-
"请核对 key 是否过期/被吊销,或移除 key 走匿名档(删除 "
|
|
358
|
-
"VOD_JAVA_API_KEY 环境变量与 runtime.json java_key)",
|
|
359
|
-
code=-32012)
|
|
453
|
+
_raise_explicit_key_rejected(JAVA_KEY)
|
|
360
454
|
# 缺 key/匿名令牌失效 → 零字段匿名令牌 → 落 runtime.json → 重试一次
|
|
361
|
-
token =
|
|
362
|
-
if not token:
|
|
363
|
-
raise ToolError(
|
|
364
|
-
"未配置接入 key 且匿名令牌端点不可用。引导:" +
|
|
365
|
-
";".join(g["label"] for g in _KEY_GUIDANCE), code=-32012)
|
|
455
|
+
token = _acquire_anon_token_or_raise()
|
|
366
456
|
JAVA_KEY = token
|
|
367
457
|
_save_runtime({"java_key": token, "token_tier": "anonymous"})
|
|
368
458
|
out = _http("POST", _SUBMIT_HOARDING, body, base=JAVA_BASE, key=JAVA_KEY)
|
|
@@ -382,22 +472,23 @@ def submit_voices(params: dict, client_info: dict | None = None,
|
|
|
382
472
|
# 回执缺失/整批被拒 → 不得兜底计成功(实锤缺陷:空 voiceId 记成功
|
|
383
473
|
# 且宿主模型据此谎报"已提交")。accepted 以真实回执为准。
|
|
384
474
|
accepted = 0
|
|
385
|
-
voice_ids.extend([""] * len(
|
|
475
|
+
voice_ids.extend([""] * len(items))
|
|
386
476
|
if not engine_rejected:
|
|
387
477
|
engine_rejected = [{"reason": "引擎回执未含 voiceIds(提交结果未知),请勿视为已收录"}]
|
|
388
|
-
task_ids.extend([None] * len(
|
|
478
|
+
task_ids.extend([None] * len(items)) # 囤积语义:无即时任务
|
|
389
479
|
result = {"accepted": accepted, "voiceIds": voice_ids,
|
|
390
480
|
"taskIds": task_ids, "rejected": rejected + engine_rejected,
|
|
391
481
|
"analysis": "deferred", # 囤积语义明示(V6 运营批量消费)
|
|
392
482
|
"path": "hoarding",
|
|
393
|
-
"echo":
|
|
483
|
+
"echo": _echo_plan(items, voice_ids)}
|
|
394
484
|
if out.get("productRegistered") is not None:
|
|
395
485
|
result["productRegistered"] = out.get("productRegistered")
|
|
396
486
|
# D-attrib-A 可观测:模型试图改归因留痕,不静默吞
|
|
397
487
|
result["productSource"] = "install_binding"
|
|
398
488
|
if ignored_runtime:
|
|
399
489
|
result["ignoredRuntimeProduct"] = ignored_runtime
|
|
400
|
-
|
|
490
|
+
_ledger_submit(items, voice_ids, task_ids, product, ledger_extra)
|
|
491
|
+
result["pendingFlush"] = _flush_pending(product)
|
|
401
492
|
return result
|
|
402
493
|
# ---- 过渡回落:老链单条提交(仅囤积端点 404 触发) ----
|
|
403
494
|
for i, v, content in items:
|
|
@@ -414,46 +505,25 @@ def submit_voices(params: dict, client_info: dict | None = None,
|
|
|
414
505
|
task_ids.append(None)
|
|
415
506
|
elif (not JAVA_KEY or e.code == -32012) and not voice_ids:
|
|
416
507
|
if _explicit_key():
|
|
417
|
-
|
|
418
|
-
raise ToolError(
|
|
419
|
-
f"注入的 key 被引擎拒绝(指纹 {_fingerprint(JAVA_KEY)}):"
|
|
420
|
-
"请核对 key 是否过期/被吊销,或移除 key 走匿名档", code=-32012)
|
|
508
|
+
_raise_explicit_key_rejected(JAVA_KEY)
|
|
421
509
|
# 零字段匿名令牌:缺 key/401 → 自动取令牌 → 落 runtime.json → 重试一次
|
|
422
|
-
token =
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
task_ids.append(tid)
|
|
430
|
-
else:
|
|
431
|
-
raise ToolError(
|
|
432
|
-
"未配置接入 key 且匿名令牌端点不可用。引导:" +
|
|
433
|
-
";".join(g["label"] for g in _KEY_GUIDANCE), code=-32012)
|
|
510
|
+
token = _acquire_anon_token_or_raise()
|
|
511
|
+
JAVA_KEY = token
|
|
512
|
+
_save_runtime({"java_key": token, "token_tier": "anonymous"})
|
|
513
|
+
vid, tid = _legacy_submit(i, v, content)
|
|
514
|
+
accepted += 1
|
|
515
|
+
voice_ids.append(vid)
|
|
516
|
+
task_ids.append(tid)
|
|
434
517
|
else:
|
|
435
518
|
rejected.append({"index": i, "reason": msg[:120]})
|
|
436
519
|
result = {"accepted": accepted, "voiceIds": voice_ids,
|
|
437
520
|
"taskIds": task_ids, "rejected": rejected,
|
|
438
521
|
"path": "legacy-fallback",
|
|
439
|
-
"echo":
|
|
440
|
-
|
|
522
|
+
"echo": _echo_plan(items, voice_ids)}
|
|
523
|
+
_ledger_submit(items, voice_ids, task_ids, product, ledger_extra)
|
|
524
|
+
result["pendingFlush"] = _flush_pending(product)
|
|
441
525
|
return result
|
|
442
526
|
|
|
443
|
-
# 本地账本落账(层级①查询的源)
|
|
444
|
-
import time as _time
|
|
445
|
-
_contents = [str(v.get("content", ""))[:40]
|
|
446
|
-
for v in params.get("voices", []) if str(v.get("content", "")).strip()]
|
|
447
|
-
ledger_entries = [
|
|
448
|
-
{"voiceId": vid, "taskId": tid,
|
|
449
|
-
"title": (_contents[i] if i < len(_contents) else ""),
|
|
450
|
-
"product": product, "at": _time.strftime("%Y-%m-%dT%H:%M:%S")}
|
|
451
|
-
for i, (vid, tid) in enumerate(zip(voice_ids, task_ids))
|
|
452
|
-
]
|
|
453
|
-
_ledger_append(ledger_entries)
|
|
454
|
-
return {"accepted": accepted, "voiceIds": voice_ids,
|
|
455
|
-
"taskIds": task_ids, "rejected": rejected}
|
|
456
|
-
|
|
457
527
|
|
|
458
528
|
def _fingerprint(key: str) -> str | None:
|
|
459
529
|
import hashlib
|
|
@@ -479,6 +549,12 @@ def probe_key(key: str | None = None, timeout: int = 8) -> dict:
|
|
|
479
549
|
except ToolError as ex:
|
|
480
550
|
code = ex.code
|
|
481
551
|
if code == 401 or code == -32012:
|
|
552
|
+
# 匿名令牌 401 ≠ 配置错误:报"过期待重领"而非"rejected",
|
|
553
|
+
# 避免 runtime 残留过期匿名令牌时被误读为正式 key 失效
|
|
554
|
+
# (显式 key 被拒仍报 rejected——fail fast 口径不变)
|
|
555
|
+
if not _explicit_key():
|
|
556
|
+
return {"ok": False, "reason": "expired-anonymous", "fingerprint": fp,
|
|
557
|
+
"note": "匿名令牌已过期:下次提交自动重领,无需操作"}
|
|
482
558
|
return {"ok": False, "reason": "rejected", "fingerprint": fp}
|
|
483
559
|
return {"ok": None, "reason": "unreachable", "fingerprint": fp}
|
|
484
560
|
|
|
@@ -504,6 +580,10 @@ def auth_status(params: dict, client_info: dict | None = None) -> dict:
|
|
|
504
580
|
if JAVA_KEY:
|
|
505
581
|
# 主动探针(devkit auth init 真调 IAM 的廉价版):用户问"key 好没好"有确定答案
|
|
506
582
|
out["keyCheck"] = probe_key()
|
|
583
|
+
if _explicit_key():
|
|
584
|
+
# 旧版残留凭据检测位(评审拍板项):显式 key 存活即在位提示自愈路径,
|
|
585
|
+
# 不等提交撞 401 才发现(codex 0.2.3 残留 key 挡匿名链的实锤教训)
|
|
586
|
+
out["legacyKeyHint"] = _legacy_key_hint()
|
|
507
587
|
if not JAVA_KEY:
|
|
508
588
|
out["guidance"] = _KEY_GUIDANCE
|
|
509
589
|
out["tokenReady"] = "首次提交时将自动申请匿名令牌(零字段,日限额低)"
|
|
@@ -595,23 +675,33 @@ def _ensure_first_boot(rt_path: Path | None = None) -> dict:
|
|
|
595
675
|
return {"action": "stamped"}
|
|
596
676
|
|
|
597
677
|
|
|
678
|
+
def _uptime_seconds() -> float:
|
|
679
|
+
"""本机 uptime(秒)。独立函数:测试可 monkeypatch,消除对宿主机器的依赖
|
|
680
|
+
(实锤:test_clone_image_detection_warns 曾硬编码 boot_age=7 天与真机
|
|
681
|
+
/proc/uptime 实值比较,uptime>7 天的机器必红——环境相关测试缺陷)。"""
|
|
682
|
+
return float(open("/proc/uptime").read().split()[0])
|
|
683
|
+
|
|
684
|
+
|
|
598
685
|
def _warn_if_cloned(cfg: dict, p: Path) -> None:
|
|
599
686
|
"""preset 克隆镜像检测(D-key-guard-3①延伸,仅告警不阻断):
|
|
600
687
|
firstBootAt 距今显著超过本机 uptime(>1h 容差)→ 本机状态大概率来自
|
|
601
688
|
母机镜像克隆——所有克隆机共享同一 device 锚点/账本,声量与配额会收敛。
|
|
602
689
|
判据:firstBootAt 的"年龄" > uptime+容差 ⇒ 首启发生在"这台机器"存在之前。"""
|
|
603
690
|
import time as _t
|
|
691
|
+
if _distribution() != "preset":
|
|
692
|
+
return
|
|
604
693
|
try:
|
|
605
|
-
if _distribution() != "preset":
|
|
606
|
-
return
|
|
607
694
|
boot = _t.mktime(_t.strptime(cfg["firstBootAt"], "%Y-%m-%dT%H:%M:%S"))
|
|
608
|
-
uptime_s =
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
695
|
+
uptime_s = _uptime_seconds()
|
|
696
|
+
except (KeyError, ValueError, OSError) as ex:
|
|
697
|
+
# 收窄捕获(原 except Exception: pass 吞掉真实异常,告警失效不可见):
|
|
698
|
+
# 只吞解析类异常(缺字段/格式坏/读不到 /proc),其余如实上抛
|
|
699
|
+
_log(f"clone 检测跳过(无法解析 firstBootAt/uptime):{ex}")
|
|
700
|
+
return
|
|
701
|
+
if _t.time() - boot > uptime_s + 3600:
|
|
702
|
+
_warn("疑似镜像克隆机:firstBootAt 早于本机 uptime——克隆分发未清 "
|
|
703
|
+
"runtime.json,所有克隆机共享同一设备锚点/账本。请在镜像冻结前 "
|
|
704
|
+
"uninstall 或删除 runtime.json(装机 checklist ②)")
|
|
615
705
|
|
|
616
706
|
|
|
617
707
|
def _save_runtime(update: dict, replace: bool = False) -> None:
|
|
@@ -709,6 +799,11 @@ def _drafts_purge(store: dict) -> dict:
|
|
|
709
799
|
if v.get("expiresAt", 0) > now}
|
|
710
800
|
|
|
711
801
|
|
|
802
|
+
def _drafts_load() -> dict:
|
|
803
|
+
"""草稿库现读 + 过期惰性清除(draft/commit 单源共用,禁双边漂移)。"""
|
|
804
|
+
return _drafts_purge(_runtime_cfg().get(_DRAFT_KEY) or {})
|
|
805
|
+
|
|
806
|
+
|
|
712
807
|
def draft_voices(params: dict, client_info: dict | None = None) -> dict:
|
|
713
808
|
"""两段式第一步:校验+暂存草稿+签发一次性令牌(不提交任何数据)。"""
|
|
714
809
|
import time as _time
|
|
@@ -744,10 +839,14 @@ def draft_voices(params: dict, client_info: dict | None = None) -> dict:
|
|
|
744
839
|
payload_sha = hashlib.sha256(
|
|
745
840
|
json.dumps(payload, sort_keys=True, ensure_ascii=False).encode()).hexdigest()
|
|
746
841
|
|
|
747
|
-
|
|
748
|
-
store = _drafts_purge(fresh.get(_DRAFT_KEY) or {})
|
|
842
|
+
store = _drafts_load()
|
|
749
843
|
store[draft_id] = {
|
|
750
844
|
"payload": payload, "payloadSha256": payload_sha, "tokenHash": _sha256(token),
|
|
845
|
+
# D-resume-commit-1:token 明文随草稿落盘(runtime.json 0600,与 java_key
|
|
846
|
+
# 同级保护)。token 的威胁模型是"防载荷改写"而非"同意凭证"——落盘不放大
|
|
847
|
+
# 风险,换断回合可续:agent 回合中断后凭 draftId 即可恢复提交(此前
|
|
848
|
+
# approvalToken 只存在于 draft 响应文本,回合断即丢失,只能重开草稿)
|
|
849
|
+
"token": token,
|
|
751
850
|
"product": product, "createdAt": _time.strftime("%Y-%m-%dT%H:%M:%S"),
|
|
752
851
|
"expiresAt": _time.time() + _DRAFT_TTL,
|
|
753
852
|
}
|
|
@@ -770,19 +869,22 @@ def draft_voices(params: dict, client_info: dict | None = None) -> dict:
|
|
|
770
869
|
|
|
771
870
|
|
|
772
871
|
def commit_voices(params: dict, client_info: dict | None = None) -> dict:
|
|
773
|
-
"""两段式第二步:令牌校验→单次消费→复用 submit_voices 既有提交链。
|
|
872
|
+
"""两段式第二步:令牌校验→单次消费→复用 submit_voices 既有提交链。
|
|
873
|
+
|
|
874
|
+
D-resume-commit-1:approvalToken/payloadSha256 可省略——draftId 命中本地
|
|
875
|
+
未过期草稿时自动恢复(断回合续提交)。显式传入仍走原校验(传了假 sha
|
|
876
|
+
照样拒),恢复路径的完整性由签发时落盘的 sha/token 保证,语义不放宽。
|
|
877
|
+
"""
|
|
774
878
|
draft_id = str(params.get("draftId", ""))
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
if not draft_id or not token or not payload_sha:
|
|
778
|
-
raise ToolError("draftId/approvalToken/payloadSha256 为必填(取自 vod_draft_voices 返回原样透传)",
|
|
779
|
-
code=-32602)
|
|
879
|
+
if not draft_id:
|
|
880
|
+
raise ToolError("draftId 为必填(取自 vod_draft_voices 返回原样透传)", code=-32602)
|
|
780
881
|
|
|
781
|
-
|
|
782
|
-
store = _drafts_purge(fresh.get(_DRAFT_KEY) or {})
|
|
882
|
+
store = _drafts_load()
|
|
783
883
|
draft = store.get(draft_id)
|
|
784
884
|
if draft is None:
|
|
785
885
|
raise ToolError("草稿不存在或已过期(10 分钟 TTL),请重新 vod_draft_voices", code=-32011)
|
|
886
|
+
token = str(params.get("approvalToken", "")) or str(draft.get("token", ""))
|
|
887
|
+
payload_sha = str(params.get("payloadSha256", "")) or str(draft["payloadSha256"])
|
|
786
888
|
if draft["tokenHash"] != _sha256(token):
|
|
787
889
|
raise ToolError("审批令牌不匹配(draft 返回的 approvalToken 原样透传)", code=-32011)
|
|
788
890
|
if draft["payloadSha256"] != payload_sha:
|
|
@@ -112,6 +112,10 @@ version: 1
|
|
|
112
112
|
符合诚实回退。**
|
|
113
113
|
4. 引擎侧承载已就绪(t_vod_voice_inbox.repro_steps/expected_behavior,
|
|
114
114
|
issue 渲染带「用户追问补充」来源注记)——本话术非空头承诺(S51 自审过)。
|
|
115
|
+
5. 追问环节状态随行上送(followupStatus,引擎指标字段、issue 不渲染):
|
|
116
|
+
not_asked=未触发追问(已有实质回应/泛化未触发);declined=问了未答
|
|
117
|
+
或答"没有/不方便";answered=已答并随两字段上送。三态白名单,
|
|
118
|
+
不确定就不带键(引擎降 NULL)。
|
|
115
119
|
|
|
116
120
|
**反截断红线(2026-11-08 opencode 实锤)**:用户在引导补充后给出的
|
|
117
121
|
补充句是**完整提交物**,content=该句逐字全量上送,禁止摘取其中片段
|
|
@@ -154,8 +158,14 @@ version: 1
|
|
|
154
158
|
3. 调用 vod_draft_voices 暂存草稿(必须用户已初步同意)→ 把返回的
|
|
155
159
|
contents 逐条**原样**展示给用户核对(禁止改写概括)→ 明确问
|
|
156
160
|
「确认提交吗」→ 用户明确同意后才调 vod_commit_voices(draftId/
|
|
157
|
-
approvalToken/payloadSha256
|
|
161
|
+
approvalToken/payloadSha256 原样透传;断回合场景 token/sha 可省略,
|
|
162
|
+
插件从本地草稿恢复)。单发工具 vod_submit_voices
|
|
158
163
|
仅限无两段式工具的宿主使用。**一次一批**,攒多条一起交也行,但每批都要用户点头
|
|
164
|
+
**用户确认后必须当回合 commit(D-resume-commit-1 话术锁,禁自由裁量)**:
|
|
165
|
+
用户说了"提交/确认/提吧"之后,本回合必须调 vod_commit_voices 收口——
|
|
166
|
+
调用失败或草稿过期就重开草稿再 commit;任何原因提交不成,必须明确
|
|
167
|
+
告诉用户"还没有提交成功",禁止只回一句"好的"就结束(实锤:agent
|
|
168
|
+
draft 后收工,用户说了两次"提交"仍无下文,反馈 40 分钟没进引擎)
|
|
159
169
|
**一次抱怨=一条声音(2026-11-06 实锤红线)**:用户一次表述只提交一条,
|
|
160
170
|
content=原话逐字——禁止拆成多条、禁止生成多个改写变体(实锤:一次
|
|
161
171
|
"网页卡回复慢"被宿主改写成「网页打开,…」+「网页卡,…」两条入库建出
|
|
@@ -164,6 +174,23 @@ version: 1
|
|
|
164
174
|
4. 拿到回执 → 对用户说人话:"已收录,产品团队会看到这条反馈"——
|
|
165
175
|
**voiceId 不展示给终端用户**(编号噪音),仅供 agent 对账用;
|
|
166
176
|
用户追问"提交了吗"时 agent 用 voiceId/taskId 核对后回答状态
|
|
177
|
+
5. **无通道 fallback(D-pending-1,插件未安装/无 vod 工具时)**:
|
|
178
|
+
- 落盘:把反馈追加写入 `~/.vod-devkit/pending-feedback.jsonl`(JSONL 一行
|
|
179
|
+
一条,字段 idempotencyKey=sha1(content+confirmAt+source)/content/tags/
|
|
180
|
+
confirmAt/createdAt=当前时间/source=宿主名/echoShown/status="pending"/
|
|
181
|
+
originalLines=用户原话逐行数组(多轮/多行原话必填——flush 以它拼接为
|
|
182
|
+
权威 content,机械剥除模型拼接时新增的标点连接词,S73 改字技术锁;
|
|
183
|
+
模型自拟 content 仅供比对))。
|
|
184
|
+
**条目级幂等键,内容级去重归引擎**(同内容重提=skipped),禁止用本键
|
|
185
|
+
判"用户重复反馈"。
|
|
186
|
+
- echo 前移(两场景诚实区分):能拿到用户输入原文 → 落盘前与 content
|
|
187
|
+
比对,不一致以原文为准;拿不到 → 先向用户逐字回显将暂存的内容再落盘、
|
|
188
|
+
echoShown=true——这是概率性防线非确定性闸,不假装解决保真。
|
|
189
|
+
- 对用户只说人话:"反馈已暂存(内容:……)。当前环境暂不支持直接提交,
|
|
190
|
+
恢复后会自动补交。" **禁止出现文件路径/profile/工具名/幂等键**(内部
|
|
191
|
+
细节进日志不进用户提示;路径属 CWE-209 敏感信息)。
|
|
192
|
+
- 补交:插件恢复后任一次 vod_submit_voices 成功会自动 flush pending
|
|
193
|
+
(引擎幂等防重,用户无需操作);超 30 天未补交的条目会被标记过期。
|
|
167
194
|
|
|
168
195
|
## 纪律
|
|
169
196
|
|
|
@@ -200,3 +227,13 @@ version: 1
|
|
|
200
227
|
- 渠道/来源一律不提交、不向用户提及(引擎按链路固定赋值)
|
|
201
228
|
- 提单/工单类诉求:不需要"复现步骤/严重程度/优先级"等开发者工单字段——
|
|
202
229
|
用户原话即完整提交物,缺什么由运营侧补充
|
|
230
|
+
|
|
231
|
+
## 教训(D-pending-1 落地过程实锤)
|
|
232
|
+
|
|
233
|
+
- **skill 留白即兴实锤**:无通道场景旧版 skill 未规定任何格式,agent 即兴
|
|
234
|
+
发明 JSON「暂存记录」输出到对话(工具名/枚举外露+伪落盘=有记录的丢失)。
|
|
235
|
+
定律再次验证:凡留白处模型必自由裁量——fallback/异常路径必须在 skill 里
|
|
236
|
+
格式定死,能格式锁的绝不交给话术。
|
|
237
|
+
- **拼接改字第 N 次实锤与机械锁**:模型把两行无标点原话拼成「差劲。使用
|
|
238
|
+
…不流畅。」(S73 判定例在仍违)——originalLines 字段+flush 权威拼接=
|
|
239
|
+
确定性剥除,规则层锁不死的行为下沉技术层。
|
package/vod_mcp/__init__.py
CHANGED