DeepSeek Harness 插件

skyskyskyl/dsh-question-shield

Star 数 ★ 1 分类 安全与权限 收录于 2026-12-01

让探讨型提问保持只读并拦截未经授权的新建文件,同时不破坏 Prompt Cache。

安装

# Release 预构建包

dsh plugin --profile web add -w "https://github.com/skyskyskyl/dsh-question-shield/releases/download/v0.1.0/dsh-question-shield-0.1.0.tgz"

# GitHub 源码(首次需按提示配置 allowBuilds 构建授权后重试)

dsh plugin --profile web add github:skyskyskyl/dsh-question-shield

装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络,工具审批管不到它。GitHub 来源的插件还会在安装时执行构建脚本——pnpm 默认拦截,所以安装可能停在 ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED 或 ERR_PNPM_IGNORED_BUILDS;dsh 会打印出需要添加的确切键名,把它加进该 profile 的 pnpm-workspace.yaml 的 allowBuilds 下,重跑一次即可装上。放行构建本身就是一次信任判断:请只安装可信来源,并尽量锁定 commit(github:owner/repo#sha)。

README

English | 简体中文

别再因为随口问了一句,代码库就被直接重构;也别再让 Agent 擅自生成一堆你没要过的辅助脚本和文档。


Before vs. After

1. 随口探讨 -> 代码直接被改

# Before
you> 是不是把 handleRequest 改成异步会更好?

agent> 好主意!我现在就帮你改成异步...
  [edit] src/server.ts (+48 -31)
  [edit] src/router.ts (+22 -14)
  [edit] tests/server.test.ts (+39 -19)
# 你只是想聊聊利弊,结果被迫 `git checkout .`。
# After (with dsh-question-shield)
you> 是不是把 handleRequest 改成异步会更好?

agent> 改动前可以先权衡这几点:
  - 优势:高并发下不阻塞 I/O,错误链路更清晰。
  - 代价:router.ts 里 3 处调用方都会传染成 async。
  如果你确认要改,我可以马上动手。
# 在你明确拍板前,零文件改动。

2. 修个 Bug -> 突然多出一堆莫名其妙的新文件

# Before
you> 帮我修复一下 src/client.ts 里的超时 bug

agent> 修好了!另外顺手帮你建了几个辅助文件:
  [edit] src/client.ts (+4 -2)
  [write] scripts/verify_timeout_tmp.mjs (NEW)
  [write] TIMEOUT_FIX_NOTES.md (NEW)
# After
you> 帮我修复一下 src/client.ts 里的超时 bug

agent>
  [edit] src/client.ts (+4 -2)
  [blocked] write scripts/verify_timeout_tmp.mjs
    [Question Shield] Blocked unsolicited file creation: "scripts/verify_timeout_tmp.mjs".
    The user did not ask to create a new file. Please edit existing files instead, or ask first.

Why it happens

从言语行为理论(Speech Act Theory)来看,“是不是改成异步会更好?”和 “Would it be better to refactor this?” 属于信息征询 / 是非疑问句(Information-seeking / Polar Questions),而不是行动指令(Directives)。但在编码 Agent 场景下,模型很容易触发讨好型倾向,把探讨性发问直接当成“立刻动手改代码”的命令。

dsh-question-shield 用本地中英文正则 + 当轮只读状态锁 + 工具执行前的文件存在性校验,把这条边界重新立起来。没有额外 LLM 调用,也不动 System Prompt 前缀,不会破坏 Prompt Cache。

(我的语言学知识居然有用了 lmao)


安装

通过 GitHub 直接安装到 DSH Profile

dsh plugin --profile default add github:skyskyskyl/dsh-question-shield

提示(pnpm >= 10): 从 Git 安装时会执行 prepare 脚本编译 TypeScript。若首次安装时 pnpm 拦截了构建脚本,按提示在对应 profile 的 pnpm-workspace.yaml 中加入 allowBuilds: { dsh-question-shield: true } 后重新执行 dsh plugin add 即可。

或本地克隆并通过 --patch 加载

git clone https://github.com/skyskyskyl/dsh-question-shield.git
cd dsh-question-shield
pnpm install && pnpm run build

创建 question-shield.patch.yml:

- insert:
    - id: question-shield
      name: /absolute/path/to/dsh-question-shield/lib/index.js

启动 DeepSeek Harness:

dsh --patch ./question-shield.patch.yml

配置项

所有配置均为可选,开箱即用。可在 profile 的 cordis.patch.yml 中按需覆盖:

- insert:
    - id: question-shield
      name: dsh-question-shield
      config:
        enableQuestionShield: true
        strictReadOnlyOnQuestion: true
        guardUnsolicitedFileCreate: true
        allowCreatePatterns:
          - "**/*.test.ts"
          - "tmp/**"
        customQuestionPatterns:
          - "\\bbrainstorm\\b"
        customDirectivePatterns:
          - "直接上线"
配置项 类型 默认值 说明
enableQuestionShield boolean true 开启中英文探讨型提问识别与约束提示注入。
strictReadOnlyOnQuestion boolean true 提问回合硬拦截所有文件写入/编辑/补丁工具。
guardUnsolicitedFileCreate boolean true 拦截未经明确要求或点名的“新建文件”操作。
allowCreatePatterns string[] [] 允许自由新建文件的路径 glob 白名单(支持 *、**、?)。
customQuestionPatterns string[] [] 自定义扩展探讨型提问正则(不区分大小写)。
customDirectivePatterns string[] [] 自定义扩展明确指令排除正则(命中时不触发护栏)。

工作原理

  1. agent/pre-step 钩子:
    • 检查本轮 source.kind === 'user' 的用户输入,支持纯中文、纯英文及中英混排。
    • 区分探讨型提问(如“是不是改成异步会更好?”)与礼貌型指令(如“能不能现在帮我把这个函数改成异步?”),避免误伤。
    • 仅在当轮 messages 末尾追加一句 [Question Shield] 约束提示,不修改 System Prompt 前缀,不影响 Prompt Cache。
    • 通过 WeakMap<Agent, TurnState> 按 Agent 隔离状态:同一回合后续 step 保持锁定,下一轮新指令自动解锁。
  2. tools/pre-execute 钩子:
    • 拦截 DSH 内置文件变更工具(write、edit、apply_patch 以及 str_replace_editor 的非 view 操作)。
    • 若处于提问回合且 strictReadOnlyOnQuestion: true,直接返回 deny 提示模型先说明方案并等待确认。
    • 若处于普通回合且 guardUnsolicitedFileCreate: true,检查目标路径在本地文件系统是否尚不存在;若用户既未表达新建意图、也未点名该文件名、且不在 allowCreatePatterns 白名单中,则直接拦截。

本地开发与测试

pnpm install
pnpm run typecheck
pnpm run build
pnpm test

开源协议

MIT

内容来自项目 README(GitHub)↗

链接

同类插件

查看整个分类 →

社区评论

评论公开保存在 GitHub Discussions。加载评论会连接 GitHub 和 Giscus;发表内容需要 GitHub 账号。