KYinCode/dsh-hooks-plugin1

dsh-hooks-plugin

Claude Code style hooks for DeepSeek Harness: run shell commands on agent/tool lifecycle events from .dsh/hooks.json (CC-compatible JSON shape).

包名
dsh-hooks-plugin
版本
0.2.3
许可证
MIT
最近更新
2026年8月18日

安装

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:KYinCode/dsh-hooks-plugin

配置示例

/.dsh/hooks.json

{
  "PreToolUse": [
    {
      "matcher": "Read|Write|Edit",
      "hooks": [
        {
          "type": "command",
          "command": "echo hook triggered",
          "timeout": 5
        }
      ]
    },
    {
      "matcher": "Read",
      "hooks": [
        {
          "type": "command",
          "command": "node -e \"process.stdout.write(JSON.stringify({hookSpecificOutput:{hookEventName:'PreToolUse',permissionDecision:'deny',permissionDecisionReason:'blocked'}}))\"",
          "if": "Read(*private*)",
          "timeout": 5
        }
      ]
    }
  ]
}

hook 字段 schema

每条 hook 是一个对象,type 决定判别联合(对齐 CC 2.1.88 schemas/hooks.ts)。

command / prompt / agent / http 公共字段

字段类型默认说明
type"command" | "http" | "prompt" | "agent"hook 类型。v1 实现 commandhttpprompt/agent 依赖外部 LLM/子代理,v1 不做(parseHookConfig 会拒绝未知类型)
ifstring权限规则语法过滤器(如 Bash(git *)Read(*.ts)),仅工具类事件生效;在 spawn 之前匹配 tool_name + tool_input,不匹配则不启动进程
timeoutnumber(>0)60本命令/请求的超时秒数
statusMessagestring纯展示文案:hook 运行时在 spinner/列表里显示的自定义状态消息;有则取代 command/url/prompt 作为 hook 显示名,不参与去重键、不改变执行与决策
oncebooleanfalsetrue 时执行一次后从运行期集合移除

type: "command" 专用

字段类型默认说明
commandstring(必填)要执行的 shell 命令
shell"bash" | "powershell"bashshell 解释器;bash$SHELL(bash/zsh/sh),powershell 用 pwsh。是去重键的一部分
asyncbooleanfalsetrue 时后台运行、不阻塞主流程
asyncRewakebooleanfalse后台运行,且退出码为 2 时唤醒模型并注入阻塞错误;隐含 async

type: "http" 专用

字段类型默认说明
urlstring(必填,URL)向其 POST hook 输入 JSON 的地址
headersobject附加请求头;值可用 $VAR_NAME / ${VAR_NAME} 引用环境变量
allowedEnvVarsstring[]允许在 header 值里插值的环境变量名白名单;只列出的变量会被解析,其余 $VAR 引用留空

type: "prompt" / type: "agent" 专用(v1 不做,schema 对齐 CC)

字段类型说明
promptstring(必填)用 LLM 评估的 prompt / 要验证的内容;$ARGUMENTS 占位 = hook 输入 JSON
modelstring指定模型(如 claude-sonnet-4-6);缺省用小模型 / Haiku

matcher 结构

{
  "": [
    { "matcher": "", "hooks": [ , ... ] },
    ...
  ]
}
字段类型说明
matcherstring事件匹配模式:*(或空)全匹配;A|B 管道精确匹配;其余按正则。DSH 工具名小写,精确匹配大小写不敏感
hookshook[]该 matcher 命中时串行执行的 hook 列表

事件 key 限 CC 27 事件名;v1 实际接线:PreToolUse / PostToolUse / PostToolUseFailure / UserPromptSubmit / SessionStart / SessionEnd / Stop / SubagentEnd