dsh-block-placeholder-edits:拦截占位注释与整文件缩水写入

前言

在 DeepSeek Harness(DSH)里让模型改代码时,常见一种隐蔽失败:模型在 write 或 edit 的新内容里写上 // ... existing code ... 一类占位注释,编辑工具按字面替换后,原先几十行真实代码被一行注释顶掉。构建报错时才发现,更糟的是构建仍能通过、逻辑却已残缺。

手工审查每次工具调用成本高,事后 diff 也拦不住「已经落盘」的写入。下面介绍社区插件 dsh-block-placeholder-edits(维护者 acus9345),在每次 write / edit 落地前做校验,命中规则则拒绝调用并保留原文件,同时把问题行与修复建议返回给模型。

这是什么

dsh-block-placeholder-edits 是面向 DeepSeek Harness 的插件,在 Cordis 侧挂钩文件写入路径。README 中的定位是:拒绝会把真实代码替换成占位注释的编辑,以及会静默丢掉大文件大部分内容的整文件写入。许可证为 MIT;npm 包当前版本为 0.2.3(见仓库 package.json)。社区目录分类为「模型推理」,GitHub 仓库约 2 stars。

插件以当前 DSH 进程的权限运行;安装前建议自行查看源码与许可证,确认行为符合你的安全与合规要求。

核心功能

占位注释检测

插件检查新文本是否包含「谈论代码而非代码本身」的注释,常见注释风格均覆盖://、#、/* */、<!-- -->、--、;、JSX {/* */} 等。

示例(摘自 README):

// ... existing code ...
# rest of the file unchanged
/* ... */
// keep the rest as is
// ... other methods
{/* ... */}

单独一行的 ... 也会被视为占位,但在 Python、Markdown 等语言里 ... 有语义的文件中会排除。普通注释(包括提到 existing code 的说明性注释)会通过;若占位注释已存在于旧文本中,不会因此对模型重复告警。

大文件「缩水」整写检测

对整文件 write:若原文件不少于 40 行(默认 minLinesForShrink),而新内容行数少于原文的 一半(默认 shrinkRatio: 0.5),则拒绝写入。README 说明该模式通常表示模型凭记忆重写并丢掉大块内容。针对性 edit(old_string / new_string)不受此规则影响,新建文件也不受影响。

拒绝后的反馈与重试

拒绝时,模型会收到类似下面的说明(含问题行号与修复建议):

dsh-block-placeholder-edits blocked this edit to src/app.ts: the new text contains
placeholder comments that stand in for code instead of the code itself. Writing them
would delete whatever they replace.
  line 2: // ... rest of the function unchanged
Fix: write out the full code in place of each placeholder, or use a smaller `edit`
that replaces only the lines you are changing (old_string/new_string) so untouched
code stays as it is.

README 提到,实践中模型往往会改用更窄的 edit 或补全完整代码。若确需删除大段内容,模型可对完全相同的调用再执行一次以确认意图,第二次会通过(可由配置关闭)。若希望由人拍板,可将 mode 设为 ask。

安装与启用

常用 web profile(dsh web 对应的浏览器 UI)。若用 headless(脚本/CI)或 acp(编辑器集成),需对各自 profile 单独安装插件列表。

dsh plugin --profile web add dsh-block-placeholder-edits

安装后即生效,无需额外开关。卸载:

dsh plugin --profile web remove dsh-block-placeholder-edits

本地试改插件时,README 给出从克隆构建 tarball 再安装的路径(版本号以 npm pack 产物为准,示例中为 dsh-block-placeholder-edits-0.2.0.tgz):

git clone https://github.com/acus9345/dsh-block-placeholder-edits
cd dsh-block-placeholder-edits
npm install
npm pack
dsh plugin --profile web add ./dsh-block-placeholder-edits-0.2.0.tgz

配置

可在 DSH 侧栏 Plugins 中点开 dsh-block-placeholder-edits 修改并 Save,下一次工具调用即生效,无需重启。

也可在 ~/.dsh/profiles/<profile>/cordis.patch.yml,或全局 ~/.dsh/cordis.patch.yml 中追加(未写的键保持默认):

- id: block-placeholder-edits
  config:
    mode: deny                 # or `ask` for an approval prompt
    shrinkRatio: 0.5           # 0 turns the large-deletion check off
    minLinesForShrink: 40      # files shorter than this are never shrink-checked
    allowIdenticalRetry: true  # false: a refusal is final
    extraPatterns: []          # extra regexes for your own placeholder phrasing
    ignore: ['docs/**']        # globs to skip entirely

shrinkRatio 设为 0 可关闭大文件缩水检测;ignore 可对指定 glob 完全跳过插件检查。

适用场景与注意

适合在 DSH 中频繁让模型改仓库、且遇到过占位注释或「整文件重写变短」问题的开发者。它不替代代码评审,而是在工具层减少一类可预期的数据丢失。

注意:

  1. 每个 profile 插件列表独立,实际使用的 profile 都要 add 一次。
  2. 插件与 DSH 同进程权限,对 ignore 与自定义 extraPatterns 的配置应明确范围,避免误放行敏感路径。
  3. 社区插件目录(如 SkillHub)为独立站点,与 DeepSeek / 幻方无官方从属关系;安装来源以目录页与 GitHub 仓库为准。

开发与验证

维护者在仓库中提供单元测试与端到端测试(e2e 使用脚本化本地模型,无需 API key):

npm install
npm test           # detector unit tests
npm run test:e2e   # real dsh runs against a scripted local model, no API key needed

安装相关测试会执行 dsh plugin add,README 注明需要 PATH 上有 pnpm。问题与想法可通过 GitHub Issues 反馈。

结尾

dsh-block-placeholder-edits 在写入前拦住占位注释与可疑的大文件缩水整写,把具体行号与修复建议还给模型,降低「静默删代码」的概率。需要时可配合 mode: ask 或关闭缩水检测,在安全与灵活性之间按项目调整。

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜