ethanwong-hk/dsh-thinking-guard

Plugin插件 Native原生 ⭐ 3 MIT Approval & Security审批与安全

Circuit breaker for pure-thinking idle loops in DSH agent turns — triple fusing on timeout, reasoning volume, and degenerate repetition.

Project Overview项目介绍

dsh-thinking-guard is a Cordis-style native circuit-breaker plugin built exclusively for DSH (DeepSeek Harness) that watches the agent/assistant-stream event and stops turns where the model emits only reasoning deltas with zero text and zero tool-call output. It complements rather than replaces the existing dsh-llm-deepseek idle watchdog, because that watchdog only measures SSE connection liveness and resets its 5-minute timer on every chunk, so a model that streams reasoning faster than the timer window can run indefinitely against the 256000-token default ceiling. Installation accepts three forms: dsh plugin add @ethanwong-hk/dsh-thinking-guard from npm, dsh plugin add github:ethanwong-hk/dsh-thinking-guard from GitHub, or a manual mount by dropping the repository into ~/.dsh/plugins/dsh-thinking-guard/ and pasting the provided insert block into ~/.dsh/cordis.patch.yml. A DSH restart is required for activation, and the user can verify it is loaded with grep -n "thinking-guard" ~/.dsh/cordis.patch.yml.

When triggered, the plugin fires agent.cancel({ kind:'thinking-guard', reason, detail }) and then attempts to push a human-readable notice via agent.followup(). The defaults are thinkingOnlyMs: 45000, maxThinkingChars: 80000, and repeatThreshold: 3, plus tunables sentenceRepeatRatio: 0.6, gramDensity: 0.22, autoContinue: true, notify: true, and verbose: false, all set under the thinking-guard.config key of ~/.dsh/cordis.patch.yml. Environment overrides DSH_THINKING_GUARD_DISABLED, DSH_THINKING_ONLY_MS, DSH_MAX_THINKING_CHARS, DSH_THINKING_REPEAT_THRESHOLD, and DSH_THINKING_GUARD_VERBOSE allow temporary adjustments without editing YAML. The "stuck-since" anchor is the last actual progress event, not the attempt start, so legitimate slow-warmup turns are not misclassified as idle.

The plugin has no npm dependencies and only consumes harness-provided events and APIs; the notice factory resolves @deepseek-ai/dsh-llm through a candidate-path probe and falls back to a log-only path if resolution fails, so cancellation is never blocked by message construction. The bundled test/guard.test.mjs exercises eleven scenarios including pure-thinking timeout, sparse-repeat regression, capacity cap with output, and long-normal-turn pass-through, and the README documents a previously shipped bug where a module-scope cfg reference caused the breaker itself to silently no-op on every hit. It is licensed MIT and targets DSH specifically, with no compatibility claims for Claude Code, Codex, Cursor, or other agent runtimes.

dsh-thinking-guard 是一个面向 DSH(DeepSeek Harness)的 Cordis 原生熔断插件,专门拦截 agent 在「只输出 reasoning、无任何 text 或 tool-call」时的空转退化。它挂在 harness 暴露的 agent/assistant-stream 事件上,与 agent/llm-deepseek 的连接活性看门狗形成互补,因为后者只检测 SSE 心跳而无法识别思考进度停滞。安装方式有三种:dsh plugin add @ethanwong-hk/dsh-thinking-guard、从 GitHub 安装,或手工将仓库放到 ~/.dsh/plugins/dsh-thinking-guard/ 后在 ~/.dsh/cordis.patch.yml 中插入 manifest 片段,安装后需重启 DSH。

插件默认开启三重熔断:thinking-only-timeout(默认 45000 毫秒,零产出且距最后一次进展超时触发)、thinking-volume(默认 80000 字符,单次 reasoning 总量上限,不依赖是否已吐文本)、degenerate-loop(默认 3 次重复,尾部窗口内精确重复、句级模板、稀疏复读与 N-gram 高密度检测)。命中后会调用 agent.cancel({ kind:'thinking-guard', reason, detail }) 并尽力用 agent.followup() 注入可见说明。阈值、重复窗口系数、自动续写开关均通过 ~/.dsh/cordis.patch.yml 的 thinking-guard.config 项调整,环境变量 DSH_THINKING_* 系列可临时覆盖。

插件无外部依赖,仅消费 harness 的 agent/assistant-stream、agent/disposed 事件与 agent.cancel、agent.followup 接口;消息工厂按候选路径解析 @deepseek-ai/dsh-llm,失败时降级为日志而不影响熔断。仓库自带 test/guard.test.mjs,11 个用例覆盖纯思考超时、退化复读、稀疏复读回归与正常回合放行等场景,源码采用 MIT 协议,并已修复一处熔断器自身因 ReferenceError: cfg is not defined 而整体静默失效的缺陷。

Pre-install check安装前体检Compatibility · Security兼容性 · 安全性 1 warning1 项注意
  • Only 3 stars - very few users, little community feedback星标只有 3,几乎没人在用,遇到问题缺少社区反馈
DSH walks through these 9 checksDSH 会逐条核对这 9 项

Compatibility兼容性

  • DSH, Node, OS and profile requirementsDSH 版本 / Node 版本 / 操作系统 / profile 是否满足要求
  • External dependencies and runtimes (Electron / Python / Docker, ...)外部依赖与运行时(Electron / Python / Docker 等)是否齐备
  • Conflicts with installed plugins: command names, skill / tool names, ports, duplicate MCP registration与已装插件是否冲突:命令名、skill / tool 重名、端口占用、重复 MCP 注册

Security安全性

  • Repo matches the facts registered here; archived or abandoned?仓库是否与页面登记一致,是否归档或长期停更
  • Safety of preinstall / install / postinstall and install.sh / setup.ps1preinstall / install / postinstall 与 install.sh、setup.ps1 是否安全
  • curl|bash, download-then-execute, obfuscation, unrelated domains → stop immediatelycurl|bash、下载即执行、混淆代码、无关域名 → 立刻停止
  • Typosquatting or unmaintained packages among the new dependencies新增依赖里有没有 typosquatting 或无人维护的包
  • Requested permissions vs. what the feature actually needs申请了哪些权限、是否超出功能所需(filesystem / network / shell / clipboard)
  • Any sudo / admin requirement, plus uninstall and rollback是否要求 sudo / 管理员权限,以及卸载与回滚方式

Anything uncertain must be marked unknown with a note on how to confirm it. This site's signal screen is a static snapshot, not a security audit.拿不准的必须标「未知」并说明要我怎么确认。本站的信号筛查是静态快照,不能替代安全审计。

Or use CLI install (for developers)或使用命令行安装(适合开发者)

CLI Install命令行安装

dsh plugin add @ethanwong-hk/dsh-thinking-guard

把 ethanwong-hk/dsh-thinking-guard 加入你的 DSH 配置(web profile)即可启用。

READMEREADME

dsh-thinking-guard

纯思考空转熔断器。挂在 agent/assistant-stream 事件上,对「只思考、零产出」的退化回合实施三重熔断。

安装

方式一:从 npm 安装(推荐)

dsh plugin add @ethanwong-hk/dsh-thinking-guard

方式二:从 GitHub 安装

dsh plugin add github:ethanwong-hk/dsh-thinking-guard

方式三:手工挂载

把本仓库放到 ~/.dsh/plugins/dsh-thinking-guard/,然后在 ~/.dsh/cordis.patch.yml 中加入 cordis.patch.yml 里的 insert 片段(见下方「配置」)。

安装后重启 DSH 生效。验证是否加载:

grep -n "thinking-guard" ~/.dsh/cordis.patch.yml

为什么需要它

dsh-agent-loop 的 step() 只在流结束后才做终止判定(lib/index.js:1115-1119)。流不结束,turn/end 就永不写入。

dsh-llm-deepseek 的 idleWatchdog(lib/index.js:1627)测的是连接活性而非任务进展 —— 它在每个 SSE 事件上 pulse() 重置 5 分钟计时器(:1816 经 parseSse 喂食)。模型持续吐 reasoning-delta 时,看门狗每 chunk 重置,永不触发。

结果是:模型以比 5 分钟更密的节奏输出 thinking token 时,回合可以无限持续,只能由用户手动中止。默认 max_tokens = 256000(DEFAULT_MAX_TOKENS)量级过大,不构成实际兜底。

三重熔断

熔断 默认值 触发条件
thinking-only-timeout 45000 ms 零 text、零 tool-call,且距最后一次进展已超时
thinking-volume 80000 字符 单次尝试 reasoning 总量超限,不依赖是否有 text 产出
degenerate-loop 3 次重复 尾部窗口命中:精确重复单元 / 句子级模板重复 / 稀疏复读 / N-gram 高密度

命中即 agent.cancel({ kind:'thinking-guard', reason, detail }),并尽力用 agent.followup() 注入一条可见说明。

「停滞时长」锚定最后一次进展(text 或 tool-call 到达的时刻),而非 attempt 起点 —— 避免慢启动的正常回合被误判。

配置

在 ~/.dsh/cordis.patch.yml 的 thinking-guard 条目 config 下调整,重启 DSH 生效:

- insert:
    - id: thinking-guard
      name: "dsh-thinking-guard"
      config:
        enabled: true
        # 只思考、零 text/tool-call 的持续时长上限(毫秒)
        thinkingOnlyMs: 45000
        # 单次尝试 reasoning 字符总量上限
        maxThinkingChars: 80000
        # 退化循环:重复次数阈值
        repeatThreshold: 3
        # 熔断后自动注入「继续当前任务」指令
        autoContinue: true
        notify: true
        verbose: false

环境变量可临时覆盖(无需改配置):

变量 作用
DSH_THINKING_GUARD_DISABLED=1 停用
DSH_THINKING_ONLY_MS 纯思考停滞阈值
DSH_MAX_THINKING_CHARS 思考容量阈值
DSH_THINKING_REPEAT_THRESHOLD 重复次数阈值
DSH_THINKING_GUARD_VERBOSE=1 打日志

误报调优

现象 调整
正常长文本被误熔断 调高 sentenceRepeatRatio(默认 0.6)、gramDensity(默认 0.22)
退化循环漏检 调低 repeatThreshold(默认 8)
慢模型被误判停滞 调高 thinkingOnlyMs

Showing the opening section of the README — the full document lives in the repository以上为 README 开头摘要,完整文档在仓库内 · View the full README on GitHub →在 GitHub 查看完整 README →

← 上一个 Prev dsh-chat-toc 下一个 Next dsh-opencode-go-usage →