truelove-dreamer/dsh-plugin-hooks
DeepSeek Harness 插件:为 DSH 提供 Claude-Code 风格的生命周期钩子。配置在模型工具调用前后自动运行的 shell 命令(工具前/工具后),通过 stdin 传入 JSON 数据;工具前命令非零退出将阻止调用。
项目介绍Project Overview
dsh-plugin-hooks 为 DeepSeek Harness 引入 Claude Code 风格的工具生命周期钩子,通过 JSON 或 YAML 配置注册 pre-tool 与 post-tool 命令,在模型工具调用前后自动执行。pre-tool 钩子以非零退出码可阻断工具调用,post-tool 仅记录运行结果,适合添加 lint、护栏与审计等自动化步骤。钩子经 ctx.shell 走沙箱,收 stdin payload,支持热加载与 /hooks 命令查看历史。需注意:命令属可信 host 配置,仅在可信 profile 启用,且 v1 不支持 Stop 等会话事件。
dsh-plugin-hooks adds Claude Code style tool lifecycle hooks to DeepSeek Harness, running pre-tool and post-tool shell commands defined in JSON or YAML around model tool calls. pre-tool hooks can block calls via non-zero exit codes; post-tool hooks only log results. Useful for adding linters, guards, or audits. Commands run through ctx.shell with sandbox policy, receive stdin payloads, and support hot reload plus a /hooks history command. Caveat: hook commands are trusted host configuration, so enable only in trusted profiles, and v1 does not yet support session events like Stop.
请帮我了解并安装插件:【dsh-plugin-hooks】【https://github.com/truelove-dreamer/dsh-plugin-hooks】
把上面这条消息直接发给当前会话里的 DSH,让它帮你了解并安装。安装命令不一定准确,发给 DSH 更稳。Send this message to DSH in your current session. CLI install commands may not be accurate across systems — DSH will figure it out for you.
或使用命令行安装(适合开发者)Or use CLI install (for developers)
命令行安装CLI Install
dsh plugin --profile web add dsh-plugin-hooks
把 truelove-dreamer/dsh-plugin-hooks 加入你的 DSH 配置(web profile)即可启用。
READMEREADME
dsh-plugin-hooks
DeepSeek Harness 插件:把 Claude Code 风格的 lifecycle hooks 带到 DSH —— 配置驱动的 shell 命令,在模型工具调用前后自动执行。
背景
DSH 0.1.0-rc.6 没有 hooks 能力,但架构已经预留了接缝:tools/pre-execute / tools/post-execute 两个有序 waterfall,以及 shell 服务"通过 stdin 给命令喂 JSON payload"的词汇表(见 @deepseek-ai/dsh-shell)。这个插件以纯外部插件形式补上这块空白,设计对齐官方预留接口:
pre-toolhook:匹配的工具执行前运行;命令非零退出 → 阻止该工具调用(等价 Claude Code PreToolUse 返回 error);post-toolhook:工具结果落地后运行;退出码只记录,不改变工具结果。
配置
JSON 配置,来源二选一或叠加:
- 文件(默认
$DSH_HOME/hooks.json):
{
"hooks": [
{
"id": "lint-after-edit",
"event": "post-tool",
"tools": ["edit", "write"],
"command": "npm run lint -- --quiet",
"timeoutMs": 30000
},
{
"id": "guard-prod",
"event": "pre-tool",
"tools": ["bash", "pwsh"],
"command": "node guard.js"
}
]
}
- 内联(挂载 config,追加在文件 hooks 之后):
- id: hooks
name: dsh-plugin-hooks
config:
configFile: C:/path/to/hooks.json # 可选
hooks:
- id: always-deny-db
event: pre-tool
tools: [bash]
command: "node deny-db.js"
字段:id(必填、唯一)、event(pre-tool | post-tool)、tools(可选,默认全部)、command(必填)、timeoutMs(可选)、enabled(默认 true)。
安装
dsh plugin --profile web add dsh-plugin-hooks
挂载:
- insert:
- id: hooks
name: dsh-plugin-hooks
Hook 命令收到的数据
命令通过 stdin 收到一行 JSON payload:
{ "event": "PostToolUse", "hookId": "lint-after-edit", "toolName": "edit",
"args": { "path": "a.js" }, "sessionId": "s_xxx", "cwd": "C:/repo",
"result": { "isError": false, "exitCode": 0, "error": null }, "durationMs": 123 }
环境变量:CLAUDE_PROJECT_DIR(会话 cwd)、DSH_HOOK_EVENT、DSH_HOOK_ID、DSH_SESSION_ID。pre-tool payload 无 result/durationMs 字段。
命令
/hooks— 列出已配置 hooks + 最近 20 次运行记录(含退出码/错误摘要)/hooks-reload— 重新读配置文件,热加载,无需重启
设计说明
- 通过
ctx.on("tools/pre-execute"|"tools/post-execute")接入 Cordis waterfall;pre-tool非零退出时返回{ kind:"deny", reason }阻断调用(与 dsh-tools 的 deny 决策契约一致,见prepareExecution)。 - 钩子命令经
ctx.shell.run执行(自动套用沙箱策略与超时),payload 走 stdin、cwd 走 env —— 与 DSH 为 hooks bridges 预留的 shell 词汇表一致。 - 配置解析/匹配/payload 构建全部在
lib/config.js纯函数里,npm test零依赖。 - hook 运行不会递归触发工具事件(shell 是服务调用,不是工具调用)。
诚实边界
- hook 命令是受信任的 host 配置(等同 Claude Code hooks):能读写任何 host 能访问的东西,只在可信 profile 启用。
pre-tool命令会阻塞工具执行(超时/退出码决定放行与否);post-tool命令失败只记录,不影响结果。- v1 只支持工具生命周期事件;Stop / SessionEnd 类 hook 需要会话事件订阅,官方尚未暴露,留待后续。
- 若
ctx.shell未挂载,插件照常加载但 hook 不会运行(启动时在/hooks里提示)。
本地开发
cd plugins/dsh-plugin-hooks
npm test # node --test,零依赖
接线集成测试(真实 Cordis + mock shell,验证 allow/deny 语义与 payload):见仓库根 test-wiring.mjs。
ruvnet/ruflo
amruthpillai/reactive-resume
esengine/DeepSeek-Reasonix
volcengine/OpenViking
Molunerfinn/PicGo
titanwings/colleague-skill
nocobase/nocobase
Tencent/WeKnora