KYinCode/dsh-hooks-plugin ↗★ 1
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).
安装
$
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:KYinCode/dsh-hooks-plugin说明文档
阅读完整 README ↗配置示例
/.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 实现 command 与 http;prompt/agent 依赖外部 LLM/子代理,v1 不做(parseHookConfig 会拒绝未知类型) |
if | string | 无 | 权限规则语法过滤器(如 Bash(git *)、Read(*.ts)),仅工具类事件生效;在 spawn 之前匹配 tool_name + tool_input,不匹配则不启动进程 |
timeout | number(>0) | 60 | 本命令/请求的超时秒数 |
statusMessage | string | 无 | 纯展示文案:hook 运行时在 spinner/列表里显示的自定义状态消息;有则取代 command/url/prompt 作为 hook 显示名,不参与去重键、不改变执行与决策 |
once | boolean | false | 为 true 时执行一次后从运行期集合移除 |
type: "command" 专用
| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
command | string(必填) | — | 要执行的 shell 命令 |
shell | "bash" | "powershell" | bash | shell 解释器;bash 用 $SHELL(bash/zsh/sh),powershell 用 pwsh。是去重键的一部分 |
async | boolean | false | 为 true 时后台运行、不阻塞主流程 |
asyncRewake | boolean | false | 后台运行,且退出码为 2 时唤醒模型并注入阻塞错误;隐含 async |
type: "http" 专用
| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
url | string(必填,URL) | — | 向其 POST hook 输入 JSON 的地址 |
headers | object | 无 | 附加请求头;值可用 $VAR_NAME / ${VAR_NAME} 引用环境变量 |
allowedEnvVars | string[] | 无 | 允许在 header 值里插值的环境变量名白名单;只列出的变量会被解析,其余 $VAR 引用留空 |
type: "prompt" / type: "agent" 专用(v1 不做,schema 对齐 CC)
| 字段 | 类型 | 说明 |
|---|---|---|
prompt | string(必填) | 用 LLM 评估的 prompt / 要验证的内容;$ARGUMENTS 占位 = hook 输入 JSON |
model | string | 指定模型(如 claude-sonnet-4-6);缺省用小模型 / Haiku |
matcher 结构
{
"": [
{ "matcher": "", "hooks": [ , ... ] },
...
]
}
| 字段 | 类型 | 说明 |
|---|---|---|
matcher | string | 事件匹配模式:*(或空)全匹配;A|B 管道精确匹配;其余按正则。DSH 工具名小写,精确匹配大小写不敏感 |
hooks | hook[] | 该 matcher 命中时串行执行的 hook 列表 |
事件 key 限 CC 27 事件名;v1 实际接线:PreToolUse / PostToolUse / PostToolUseFailure / UserPromptSubmit / SessionStart / SessionEnd / Stop / SubagentEnd。