dsh-gatekeeper
闸总 / Gatekeeper — holds model refusal replies before they enter the session context, and stops tool commands that would destroy a disk.
설치
$
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:huajikano/dsh-gatekeeper配置
- id: gatekeeper
config:
diskGuardEnabled: true # 总开关,独立于回复拦截
diskGuardCritical: block # 致命档:block / ask / warn / off
diskGuardRisky: warn # 大批量档
diskGuardTools: [pwsh, bash, shell, sh, zsh, powershell, cmd, terminal_send]
diskGuardAllowDirs: [node_modules, .git, dist, build, target, obj, tmp, temp]
diskGuardDisabledRules: [] # 想关掉的单条规则名
diskGuardTools 是白名单:只有列出来的工具才会被当作 shell 读取。默认包含 pwsh / bash 这类执行工具和 terminal_send(它能把命令打进已有终端)——这两个都得有,否则从终端里敲进去的命令不经过检查。
sessionsExclude / sessions 对两半插件同样生效:被静音的会话连工具调用也不查。
推荐配置
日常使用(只拦真正说出口的拒绝):
- id: gatekeeper
config:
onDetect: block
scanReasoning: false
scanToolArgs: false
要连思考一起管(误伤明显升高,配合 dryRun 先看):
- id: gatekeeper
config:
onDetect: block
scanReasoning: true
dryRun: true
auditPath: C:\temp\refusal-audit.jsonl
开发/调试这个插件本身:把当前会话 id 加进排除,否则它会拦你自己的测试输出。
sessionsExclude:
- session-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
配置
在 profile 的 cordis.patch.yml 里按 id 覆盖:
- id: gatekeeper
config:
scanChars: 600
dryRun: false
replacementText: '[gatekeeper] 已拦截一段拒绝性回复,原文未进入会话。'
| 字段 | 默认 | 说明 |
|---|---|---|
enabled | true | 总开关 |
onDetect | 'block' | block 自动丢弃;ask 检查命中后等待人工决定 |
askTimeoutMs | 120000 | ask 模式下等你多久,超时按丢弃 |
dryRun | false | 只记录不拦截,用来先调检测 |
scanReasoning | false | 思考内容也参与判定(误伤高,按需打开) |
scanToolArgs | false | 工具参数也参与判定(写文件/发消息会误伤) |
scanChars | 600 | 检测多少字符 |
minChars | 8 | 短于这个长度不判 |
openerWindowChars | 120 | 拒绝语必须出现在开头多少字符内 |
replacementText | '' | 丢弃后写进会话的文本。空字符串 = 什么都不写 |
patterns | [] | 自定义正则,命中即拦(大小写不敏感) |
blocklist | [] | 自定义词库:纯文本、一行一条、不区分大小写,命中任一条即拦 |
sessions | [] | 只守这些 session id;空表示全部 |
sessionsExclude | [] | 这些 session 永不拦截 |
purposes | [] | 额外要守的 purpose;空表示只守主对话 |
blockToolCalls | false | 连带工具调用的回复也拦 |
auditPath | '' | 非空则把每次命中追加成 JSONL |
磁盘保护自己的字段(diskGuardEnabled / diskGuardCritical / diskGuardRisky / diskGuardTools / diskGuardAllowDirs / diskGuardDisabledRules)见上面的〈磁盘保护〉一节。两半插件把命中写进同一个 auditPath,用记录的 kind 区分。
建议先开 dryRun: true 跑一段时间,看 auditPath 里的记录确认没有误杀,再关掉。