truelove-dreamer/dsh-plugin-hooks

DeepSeek Harness 插件:为 DSH 提供 Claude-Code 风格的生命周期钩子。配置在模型工具调用前后自动运行的 shell 命令(工具前/工具后),通过 stdin 传入 JSON 数据;工具前命令非零退出将阻止调用。

Project Overview项目介绍

dsh-plugin-hooks is a native plugin built exclusively for DeepSeek Harness (DSH) that brings Claude Code-style lifecycle hooks to the DSH platform. It was created to add hook functionality that was missing in DSH 0.1.0-rc.6, leveraging the official pre-execute and post-execute seams already reserved in DSH’s architecture. It supports two hook types: pre-tool hooks that run before matching tools are executed, and post-tool hooks that run after a tool finishes. If a pre-tool hook exits with a non-zero code, it blocks the corresponding tool call entirely, matching Claude Code’s behavior. This aligns with the design intent of the original Claude Code hook system.

Users install the plugin via the DSH CLI with the command dsh plugin --profile web add dsh-plugin-hooks, then add a mount entry in their DSH config to activate it. Hooks can be configured either via a JSON file (default path is $DSH_HOME/hooks.json) or as inline config in the DSH mount entry, and multiple configurations can be stacked together. After setup, users can list all configured hooks and the last 20 run logs with the /hooks command, or reload the config with /hooks-reload for hot updates without restarting DSH. It is targeted at DSH plugin developers and advanced users who want to customize their local development workflow.

The plugin integrates with DSH via Cordis waterfall events, and relies on the built-in ctx.shell service to run hook commands. If ctx.shell is not mounted, the plugin loads normally but hooks will not run, and a clear warning will be shown in the output of the /hooks command when DSH launches. Currently, it only supports tool lifecycle events; session-level events like Stop or SessionEnd are not supported yet because DSH has not exposed the required interfaces for those extensions. Hook commands run with full access to the host system, so the plugin should only be enabled on trusted DSH profiles.

这是一个专为DeepSeek Harness开发的原生插件,用于将Claude Code风格的生命周期钩子引入DSH,填补了DSH 0.1.0-rc.6缺少钩子能力的空白。它基于DSH架构预留的官方接口开发,支持pre-tool和post-tool两类钩子:pre-tool钩子在匹配工具执行前运行,非零退出码会阻止该工具调用,post-tool则在工具执行完后运行。

开发者可以通过JSON配置文件或内联挂载配置来定义钩子,配置支持指定钩子触发的工具范围、超时时间和启用状态。安装完成后,可通过DSH内置的/hooks命令查看已配置钩子和最近20次运行记录,用/hooks-reload命令热重载配置,无需重启DSH。该工具面向需要自定义DSH开发工作流的插件开发者和高级用户。

该插件遵循DSH的Cordis插件架构开发,依赖DSH内置的ctx.shell服务,如果该服务未挂载,插件会正常加载但钩子无法运行,启动时会在/hooks命令中给出提示。目前仅支持工具生命周期事件,会话类事件钩子暂不支持。钩子命令以受信任的主机配置运行,仅建议在可信配置文件中启用。

Pre-install check安装前体检Compatibility · Security兼容性 · 安全性 2 warnings2 项注意
  • No license declared - all rights reserved by default; ask the author before commercial use or redistribution未声明开源许可证 —— 默认「保留所有权利」,商用或再分发前先问作者
  • Only 2 stars - very few users, little community feedback星标只有 2,几乎没人在用,遇到问题缺少社区反馈
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 --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-tool hook:匹配的工具执行前运行;命令非零退出 → 阻止该工具调用(等价 Claude Code PreToolUse 返回 error);
  • post-tool hook:工具结果落地后运行;退出码只记录,不改变工具结果。

配置

JSON 配置,来源二选一或叠加:

  1. 文件(默认 $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"
    }
  ]
}
  1. 内联(挂载 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。

← 上一个 Prev dsh-undo 下一个 Next dsh-tool-pwsh-safe →