dsh-guardian
DeepSeek Harness task-protection plugin: plugin preflight scanner (catches missing `inject` declarations that crash the host), loop detection (repeated identical tool calls -> steer to a new approach), recursion guard (nested subagent depth cap), and interruption awareness (status route with safeToRestart). Never terminates tasks — only steers via injected messages. Zero npm dependencies.
安装
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:akira399/dsh-guardian说明文档
阅读完整 README ↗dsh-guardian
DeepSeek Harness(DSH)任务防护插件:把真实故障中总结的教训变成主动防护,防止任务意外中断、防止任务把系统带入自我递归或崩溃状态。永不终止任务,只做检测、引导与上报。
防护机制(对应四条教训)
1. 插件预检:防止"坏插件把宿主搞崩"
历史事故:插件用了 ctx.setInterval(timer 服务)却漏声明 inject: ["timer"] → Cordis 启动抛 cannot get property "timer" without inject → 整棵插件树崩溃、宿主宕机、会话中断。
防护:部署任何新插件前运行预检扫描器,静态分析 lib/index.js 的 ctx. 用法与 inject 声明是否一致:
node /scripts/preflight.mjs
- ✅ 通过:
inject声明完整(含 timer 类:ctx.setInterval/setTimeout/...) - ❌ 失败:列出缺失的服务名(
timer/tools/settings...)并给出修复提示 - 智能识别:
ctx.get("X")/ctx.inject(["X"], cb)的嵌套获取不需要顶层声明;sctx./wctx.作用域上下文不会被误判
也可在代码里直接调用:import { scanSource } from "dsh-guardian/preflight"。
2. 循环检测:防止任务原地打转
同一工具调用(名称 + 参数指纹)在滑动窗口内重复 ≥ maxLoopRepeats 次 → 判定循环 → 注入换方向提示 + 记录 LOOP_DETECTED。
3. 递归防护:防止自我递归失控
子代理/工作流嵌套深度(tool-workflow/agent-start→agent-end 计数)超过 maxSubagentDepth → 注入收敛提示 + 记录 RECURSION_DETECTED。
4. 中断感知:防止任务执行中被打断
GET /api/dsh-guardian/status 返回:
- 各会话的
running/busy/ 嵌套深度 / 近期调用数 safeToRestart:只要还有会话在运行就为false——重启宿主前先查这里,避免把正在执行的任务连同宿主一起杀掉(本会话多次中断的根因)。
安全重启助手(强制机制):直接重启仍可能因疏忽打断任务,因此提供 scripts/safe-restart.ps1——它先查 safeToRestart,有会话在运行就拒绝重启(除非 -Force):
powershell -NoProfile -ExecutionPolicy Bypass -File \scripts\safe-restart.ps1
# 强制重启(仅在确实需要时):加 -Force
所有事件写入 $DSH_HOME/guardian/events.jsonl,状态路由可查最近 50 条。
安装
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:akira399/dsh-guardian