dsh-write-create-only:禁止 write 覆盖已存在文件

前言

在 DeepSeek Harness(DSH)中,write 工具的默认行为是全文件覆写。模型一旦误用 write 去修改已有文件,原内容会被整段覆盖。DSH 默认的 fs-observation-policy 只要求先读过文件,并不禁止覆写操作。与其事后靠模型自觉,不如把“write = 仅创建”立成硬约束。

核心能力

本插件提供以下功能:
1. 只拦 write:edit、read 等其他工具完全不受影响。
2. 目标已存在 → 拒绝:在工具执行前直接拒绝,提示改用 edit。
3. 目标不存在 → 放行:新建文件操作照常。
4. 保守放行:路径无效、stat 抛错等不确定情形一律放行,绝不误伤合法调用。
5. 全局生效:所有 agent 与会话统一适用。

安装与启用

插件安装后自动挂载,重启 DSH web 后生效。

从 GitHub 安装(源码在 src/,安装时自动构建):

dsh plugin --profile web add github:better-er/dsh-write-create-only

从 npm 安装(包内含构建产物 lib/index.js):

dsh plugin --profile web add dsh-write-create-only

工作原理

dsh 的每个工具在执行前都会走 tools/pre-execute 异步瀑布。本插件在此瀑布中注册一个全局监听器:
1. 只对 exec.name === 'write' 生效。
2. 取出 exec.arguments.file_path,用 ctx.fs.resolve 成绝对目标,再调用 ctx.fs.stat。
3. stat 返回非空即目标已存在,返回 { kind: 'deny', reason } 拒绝本次调用。
4. 其余情况一律 return next() 放行。

选择 tools/pre-execute 而非 fs/write-intent,是因为后者是单槽瀑布且已被默认策略占用;tools/pre-execute 是多监听器瀑布,不影响 write 的 schema。

卸载

彻底移除插件:

dsh plugin --profile web remove dsh-write-create-only

开发与验证

插件提供运行时冒烟验证,覆盖拦截/放行/容错等断言:

npm install
npm run build
node scripts/smoke.mjs

License

MIT

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

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

小夜