nuwa-skill
alchaincyf
你想蒸馏的下一个员工,何必是同事。蒸馏任何人的思维方式——心智模型、决策启发式、表达DNA。Distill how anyone thinks.
Paradox1278/dsh-empty-turn-guard
A DeepSeek Harness plugin that stops silent turn death: when the upstream ends with stop_reason=tool_use but emits no tool call or text, DSH closes the turn as completed and the agent stops without reporting. This plugin steers the turn back open.
PROJECT TOPICS
INSTALL REFERENCE
dsh plugin --profile web add github:Paradox1278/dsh-empty-turn-guard
该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。
PROJECT README
DSH 插件:拦截「上游声称有工具调用、却一个 tool-call 都没发」的残缺轮次,把「静默完成」改成「继续执行」。
DSH 里出现过这样的现象:一轮回复什么都没做,界面直接显示「已完成」,思考也停了。
根因链(已逐行核实):
也就是说:「结束原因是工具调用」这个信息在 agent-loop 里被丢弃了,没有 tool-call 也不报错。
| 形态 | 命中数 | 占比 |
|---|---|---|
| finish=tool-calls 但无 tool-call 块 | 57 | 7.0% |
| 其中 只有 reasoning 块 | 43 | 75% |
| 其中 完全空(除 usage/finish 外零块) | 11 | 19% |
| 其中 只有正文 text | 3 | 5% |
结论:判据不能只数「内容块数量」,那样会漏掉 75% 的 reasoning-only 情况。 必须问的是「上游说 tool-calls,但到底有没有发出 tool-call」。
不改 app.asar,只用官方公开扩展点:
| 扩展点 | 用途 |
|---|---|
| agent/assistant-stream | 观察每个 attempt 的 start / chunk / end 帧,统计内容块与 tool-call 块,记下 finish.reason.kind |
| agent/turn-stopping | 轮次即将关闭时介入(此时 loop 还没 break) |
| agent.steer(msg) | 往 inbox.next-step 塞一条消息,使 :797 的第二道判空失效,轮次继续 |
判定条件(见 index.js 的 classifyAttempt):
StreamChunk 七种类型依据 _asar2/@deepseek-ai/dsh-llm/lib/typert.host.js:596; FinishReason 五种依据同文件 :356(stop / tool-calls / max-tokens / aborted / error)。
- insert:
- id: dsh-empty-turn-guard
name: dsh-empty-turn-guard
config:
enabled: true
maxConsecutiveEmptySteps: 0
maxRemediesPerTurn: 0
maxRemediesPerAgent: 0
absoluteLimit: 10000
log: true
steerText: '[empty-turn-guard] 上一步没有任何有效输出……请立刻继续执行。'
| 字段 | 默认值 | 说明 |
|---|---|---|
| enabled | false | 总开关,必须显式 true |
| maxConsecutiveEmptySteps | 0 | 连续空轮次上限;0 = 不限。设 N 表示允许连续 N 次,第 N+1 次放行 |
| maxRemediesPerTurn | 0 | 同一 turn 内补救次数上限;0 = 不限 |
| maxRemediesPerAgent | 0 | 单个 agent 生命周期补救总数上限;0 = 不限 |
| absoluteLimit | 10000 | 程序性死循环保险丝;0 = 关闭 |
| log | true | 是否通过 ctx.logger.warn 记录介入与放行 |
| steerText | 内置中文提示 | 注入给模型的内容(0.4.0 起要求「立刻继续执行,不要回复本条消息」) |
# 打包(在开发机上执行一次)
powershell -NoProfile -ExecutionPolicy Bypass -File .\build-package.ps1
# -> .\dist\dsh-empty-turn-guard-v0.4.0.zip
把 zip 拷到目标机器,解压后有两条安装路径:
# Windows:双击 install.cmd,或
powershell -NoProfile -ExecutionPolicy Bypass -File .\install.ps1 -ProfileDir "<profile>"
# 任意平台(零依赖,Node 22+):Windows / Linux / macOS 都能用
node install.mjs
node install.mjs --profile ~/.dsh/profiles/desktop
然后重启 DSH。安装器会自动探测 profile(%DSH_HOME%\profiles\* 优先,其次
%USERPROFILE%\.dsh\profiles\*);有多个 profile 时会拒绝猜测并要求显式指定。
详见包内 INSTALL.md。
分发包做成离线 zip而不是 npm 包的三个原因:
file: 依赖 + dsh.profile.bundles 装配,本来就不需要 registry;install.cmd,双击即可,无需用户敲命令。Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
.\install.ps1 # 自动探测 profile($HOME\.dsh\profiles\desktop)
.\install.ps1 -ProfileDir "D:\x" # 显式指定
.\install.ps1 -Uninstall # 回滚(备份保留)
两个安装器(install.ps1 与 install.mjs)做的事完全一致,都是五步:
备份 package.json / cordis.patch.yml → 复制到
为什么需要 node_modules 那一步(旧版 install.ps1 漏了,会导致装了但不生效): DSH 启动时用
createRequire(<profile>/package.json).resolve.paths(包名)定位 bundle (dsh-app-boot/lib/index.js:1774resolveBundleDir→ :1755packageDirFromAnchor), 只在 package.json 里写dependencies并不会让包变得可解析 —— 文件必须真的落在<profile>/node_modules/下。安装器优先建 junction,失败自动降级为复制目录。
推荐:双击 run-sync.cmd(等价于 powershell -NoProfile -ExecutionPolicy Bypass -File sync-latest.ps1)。
脚本只做四件事,且全程 BOM-free:
%USERPROFILE%\.dsh\profiles\desktop\vendor\dsh-empty-turn-guard;- id: dsh-empty-turn-guard 块并整块替换成新配置(不限模式);node --check、BOM 检测、三项上限是否为 0、安装版本是否与源一致)。看到 VERDICT: OK -- empty-turn-guard 0.4.0 deployed (unlimited mode) 后重启 DeepSeek Harness。
手动等价做法:
Copy-Item .\index.js,.\package.json,.\README.md "$HOME\.dsh\profiles\desktop\vendor\dsh-empty-turn-guard\" -Force
node .\preflight.mjs --profile "$HOME\.dsh\profiles\desktop"
vendor 目录是 junction 的目标实体,复制即生效;改完仍需重启 DSH。 注意 patch 里的三个上限必须同时改成 0,否则仍是旧行为。
0.2.0 用 maxRemediesPerTurn=1 作为主闸门,实测在同一个 turn 里失效:
关键:这两次空轮之间隔了三步正常执行(step 11/12/13 都带 tool-call),并不是上游持续异常, 单纯按「每 turn 一次」限流属于误伤。
第一版 install.ps1 用了 Set-Content -Encoding UTF8 写 package.json。 Windows PowerShell 5.1 的 -Encoding UTF8 会写入 BOM,而 DSH 是这样读清单的:
raw = readFileSync(path, "utf8") // dsh-app-boot/lib/index.js:1688
const parsed = JSON.parse(raw) // :1692
BOM 让 JSON.parse 抛错,整个桌面宿主在启动阶段直接退出:
DesktopHostFatalError: Unexpected token '<BOM>', "<BOM>{" is not valid JSON
at readProfileManifest (dsh-app-boot/lib/index.js:1692:22)
at loadProfileDirectory (dsh-app-boot/lib/index.js:1796:42)
现在的写法:所有写入走 [System.Text.UTF8Encoding]::new($false) + File::WriteAllText / File::AppendAllText,永不产生 BOM。两个防复发工具:
.\repair-profile.ps1 # 逐字节检测并剥离 BOM;健康 profile 返回 "nothing to repair"
node preflight.mjs # 用纯 Node 复刻 dsh 启动读取路径(manifest/bundles/patch/import)
重启前请务必先跑 node preflight.mjs,exit 0 才重启。
node test.mjs # 单元测试:43 项断言
node preflight.mjs # 启动前置检查:profile 能否被 dsh 正确加载(9 项)
.\verify.ps1 # 安装完整性:8 项文件/配置/语法/加载检查
test.mjs 覆盖:classifyAttempt 判定表(7 项)、零块注入、仅 reasoning + tool-calls 补救、 仅 usage/finish 仍判零产出、有 tool-call 放行、finish=stop 的 reasoning 放行、 逐轮上限、跨 turn 全局熔断、abandoned 放行、turn 不匹配放行、默认关闭完全惰性、 steer 抛错不崩、多 agent 状态隔离、异常 payload 不崩、补救消息形状(id/role/source/唯一性), 以及 0.4.0 不限模式的回归:[3d] 同 turn 连 25 次空轮全部补救、 [3e] 跨 15 个 turn 全部补救、[3f] absoluteLimit=5 时救满 5 次停手、 [3g] signal.aborted 放行、[3h] 模型恢复产出后停止补救。
真实帧回放(用线上会话里 turn 39 的真实 step 序列重放):
node replay.mjs # 期望输出 REPLAY OK,补救 2 次
node replay-old.mjs # 对照:已安装的旧版只救 1 次
插件用 ctx.logger.warn 记录每次介入,日志行形如:
[empty-turn-guard] turn 12 step 3 命中(tool-calls-without-tool-call:finish=tool-calls,但没有出现任何 tool-call 块),已注入第 1 次补救(本 turn 第 1 次,连续第 1 次)
并且在命中时,会话里会立刻出现一条用户消息,内容就是 steerText (以 [empty-turn-guard] 开头)。看到这条消息 = 插件真的拦截并救回了一个残缺轮次。
CLASSIFICATION EVIDENCE
系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: ai-agent。