nuwa-skill
alchaincyf
你想蒸馏的下一个员工,何必是同事。蒸馏任何人的思维方式——心智模型、决策启发式、表达DNA。Distill how anyone thinks.
PROJECT TOPICS
INSTALL REFERENCE
dsh plugin --profile web add github:fatatalia/dsh-turn-guard
该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。
PROJECT README
dsh 的 turn 级单步超时插件:对 agent 会话的每一步(step)施加超时控制——当某一步运行超过配置时限,强制中断(agent.cancel),防止模型退化导致的无意义死循环。
dsh 的 turn(一次对话)由 agent-loop 的 while(true) 驱动,没有总时长/最大步数上限(设计上支持长编码任务)。模型退化时(陷入循环、持续生成无意义内容),turn 无限运行,无兜底。
真实事故:webhook 处理退款短信时,模型(deepseek-v4-flash:0731)陷入调查循环 → 推理退化输出 "nope" 无限重复 → 无任何兜底,用户手动中断。
本插件目标:防止模型退化导致的无意义死循环——每一步(step)若超过配置时限即强制中断,正常处理不受影响。
agent.cancel 公开方法)┌─ 各入口插件(imessage / webhook / heartbeat / dreaming)─────────────┐
│ settings 段加 stepTimeoutSec(设置页可编辑,单位:秒) │
│ 创建/恢复 agent 后: │
│ agent.__pluginConfig.turnGuard = { stepSec: <自己的值> } │
└──────────────────────────────────────────────────────────────────────┘
↓(agent 挂配置)
┌─ dsh-turn-guard 插件(零映射)────────────────────────────────────────┐
│ ctx.on("session/event") 监听 step/start、step/end、turn/end │
│ agents.get(session.id) → 读 agent.__pluginConfig?.turnGuard?.stepSec │
│ ├── 有值 → step/start 起定时器(stepSec × 1000 ms), │
│ │ step/end 清;超时 agent.cancel({kind:'hook'}) │
│ └── 无值 → 不干预(等同 web) │
└──────────────────────────────────────────────────────────────────────┘
| 插件 | settings 段 | 默认 |
|---|---|---|
| imessage | imessage.stepTimeoutSec |
0(不限制) |
| webhook | webhook.hooks.<id>.stepTimeoutSec(每个 hook 独立) |
0(不限制) |
| heartbeat | heartbeat.stepTimeoutSec |
0(不限制) |
| dreaming | dreaming.stepTimeoutSec |
0(不限制) |
0 / 未配置 = 不限制(等同 web 会话行为)。设置页(Settings → 各插件)均有「单步超时(秒)」输入框,getConfig 自动回填当前值,保存即热生效(无需重启)。
__pluginConfig{ turnGuard: { stepSec }, loopGuard: {...}, xxx: {...} }Object.defineProperty(agent, "__pluginConfig", { enumerable: false, writable: true, configurable: true })——不可枚举,避免被遍历/序列化干扰// session/event 里识别 step 边界(窄短路:assistant/chunk 等高频事件直接 return)
if (event.type === "step/start") {
const agent = agents.get(session.id);
const sec = agent?.__pluginConfig?.turnGuard?.stepSec;
if (!sec) return; // 无配置不干预
timers.set(session.id, setTimeout(() => {
agent.cancel({ kind: "hook", reason: `step timeout (${sec}s)` });
}, sec * 1000)); // 底层 setTimeout 需要毫秒,这里转换
} else if (event.type === "step/end" || event.type === "turn/end") {
clearTimeout(timers.get(session.id));
}
agent.cancel({kind:"hook", reason}) 是 AgentCancelCause 的合法值,中止整个 turn(abort signal → turnEnds={kind:"aborted"} → turn/end 落盘)keepInbox: false):模型已退化时 pending 消息留着只会继续跑step/end 在 agent-loop 的 finally 里必发(完成/失败/取消/max-tokens 都到)——定时器必然被清理,无泄漏| 会话类型 | 配置 | 行为 |
|---|---|---|
| gateway-*(imessage) | 有(如 300s) | 每步超 300 秒打断 |
| webhook-* | 有(每 hook 可配) | 同上 |
| heartbeat-* | 无(默认) | 不限制 |
| dreaming-* | 有(如 600s) | 每步超 600 秒打断 |
| session-*(web) | 永远不管 | 不限制(交互式) |
dsh-turn-guard/
├── index.js # host 插件:session/event 监听 + 定时器 + agent.cancel
├── cordis.patch.yml # 插入 host 插件行
└── package.json # dsh.bundle
纯 host 插件(无 client/设置页——配置入口在各入口插件的设置页)。
agents(通过 agents.get(session.id) 取 agent 读配置;session/event 事件由 sessions 服务经 ctx 广播)
step/start/step/end 事件真实存在且必然成对(dsh-agent-loop turn() 里 step/end 在 finally 发出,完成/失败/取消/max-tokens 都到)agent.cancel({kind:"hook", reason}) 是 AgentCancelCause 合法值,中止整个 turn(abort signal → turnEnds={kind:"aborted"} → turn/end 落盘)ctx.on("session/event", (session, event) => ...) 订阅姿势与官方 dsh-agent-instructions 同款assistant/chunk(每 token 一条),handler 窄短路只处理 step/start/step/end/turn/end主实例 profile 挂载(dependencies + bundles 两处):
dsh plugin --profile web add /Users/fatatalia/project/dsh-turn-guard
或手动加 package.json 的 dependencies("dsh-turn-guard": "link:...")+ dsh.profile.bundles。
stepTimeoutSec 设小(如 3),发一条需要长时间推理的指令,确认:turn/end reason={"kind":"aborted","reason":{"kind":"hook","reason":"step timeout (3s)"}}step/end 在 finally 正常发出(定时器无泄漏)__pluginConfig.turnGuard.maxSteps,step/start 计数超限 cancel(防多步无限循环)docs/turn-guard-plan.md(在代码东工作区)CLASSIFICATION EVIDENCE
系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: agent。