Host-side guard that lets the write tool only create new files: when the target already exists it denies the call before execution and tells the model to use edit instead, applied to all sessions.
Install
# from npm (prebuilt)
dsh plugin --profile web add dsh-write-create-only
# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)
dsh plugin --profile web add github:better-er/dsh-write-create-only
Any plugin you install runs third-party code with your own permissions — it can read your files, use your credentials, and reach the network, and tool approvals don’t sandbox it. GitHub-sourced plugins also run build scripts at install time — pnpm blocks those until you allow them, so an install can stop with ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED or ERR_PNPM_IGNORED_BUILDS; dsh prints the exact key to add under allowBuilds in your profile’s pnpm-workspace.yaml, and the install works on the next run. Allowing a build is a trust decision: only install sources you trust, and pin a commit (github:owner/repo#sha).
README
This plugin publishes its README in Chinese only.
禁止 write 覆盖已存在的文件:write 只允许创建新文件,目标已存在时在工具执行前直接拒绝并提示改用 edit,全局所有会话生效,防止模型用 write 把已有文件整体冲掉。纯 host 端插件,不碰 DSH 源码。
为什么
write 是全文件覆写。模型一旦误用 write 去改一个已有文件,原内容会被整段覆盖,而 dsh 默认的 fs-observation-policy 只要求「先读过」,并不禁止覆写。与其事后靠模型自觉,不如把「write = 仅创建」立成硬约束。
覆写还有第二个后果:文件没有旧内容可比,dsh-edit-diff 抓不到差异,只能把整份文件当成新增,差异显示退化成满屏绿色。目标已存在时直接拒绝,既留住旧内容,也留住差异显示。这不是本插件与那一件约定的,而是覆写这件事本身决定的。
功能
- 只拦
write:edit、read等其余工具完全不受影响。 - 目标已存在 → 拒绝:在
tools/pre-execute瀑布里对write调用先fs.stat目标,已存在则返回deny,错误信息明确提示「请改用edit做定向修改;只有创建新文件时才使用write」,模型看到后会改走edit。 - 目标不存在 → 放行:新建文件一切照常。
- 保守放行:路径无效、stat 抛错等不确定情形一律放行,绝不误伤合法调用。
- 全局生效:所有 agent 与会话统一适用。
宣传片
四件一起讲的宣传片,中文与日语配音两版同在一个投稿里:
| 文件四件套宣传片 · 一个核心,三个辅助 |
|---|
安装
从 GitHub 安装:源码在 src/,lib/ 不入仓库,安装时 npm 会触发 prepare 脚本现场构建。
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 web 后启用,无需手工编辑任何文件。
卸载
dsh plugin --profile web remove dsh-write-create-only
彻底移除,重启 DSH web 后不再加载。
原理
dsh 的每个工具在执行前都会走 tools/pre-execute 这个异步瀑布,每个监听器按序决定 allow / ask / deny。本插件注册一个全局监听器:
- 只对
exec.name === 'write'生效; - 取出
exec.arguments.file_path,用会话工作目录ctx.fs.resolve成绝对目标,再ctx.fs.stat; - stat 返回非空即目标已存在,返回
{ kind: 'deny', reason }拒绝本次调用; - 其余情况一律
return next()放行到瀑布下一环。
选择 tools/pre-execute 而不是 fs/write-intent,是因为后者是单槽瀑布且已被默认的 fs-observation-policy 占用;而 tools/pre-execute 是多监听器瀑布,位置在工具执行最前面,既不影响 write 的 schema,也不与现有策略抢位。
开发与验证
pnpm install
pnpm build # 产出 lib/index.js
node scripts/smoke.mjs # 无运行时冒烟验证:5 项断言覆盖拦截/放行/容错
License
Links
More in this category
yjh051108/dsh-routing-suite★ 6997
One repository, three parts: a runtime injector for DSH plugin packages (inject, hot-reload, unload, promote a dev staging tool to the front, route self-heal, plus a settings-page plugin manager that lists, unloads and drags folders in to internalize), a task-aware reasoning-mode router agent preset (router-standard / router-spec / router-react), and a graded two-level task protocol whose six tools (commit_star, lock_stage, revise_do, edit_plan, mark_task, redteam_verdict) pin task state to disk. The injector implementation ships in-tree, so the install carries its own behaviour rather than a dependency list.
strukto-ai/mirage#dsh★ 3696
Swaps the filesystem and bash providers for a mirage virtual workspace: file tools and shell commands run over mounted resources (RAM, S3, Redis, Slack, Gmail, Notion, Postgres) instead of the host disk, with per-mount read/write/exec modes, per-command sandbox routing (monty, pyodide, quickjs in process; docker, e2b, daytona remote), and installed CLIs (git, gh, slack, linear, ntn, gws, or one you register) as head words in the virtual terminal.
first-fluke/oh-my-agent#dsh★ 1344
Runs project OMA checks before and after tool execution and when a turn tries to finish. Installs its OMA CLI dependency and initializes unconfigured projects on first use. Requires Node.js 22+; initial setup needs network access and project write access.
hust-open-atom-club/oh-dsh★ 322
Community distribution: TUI, desktop, and Web UI as one bundle with layered installation.
weijiafu14/pi2dsh★ 217
Pi Host ABI compatibility engine: after one install, unmodified Pi extensions from npm mount as native DSH plugins with `dsh plugin add <pi-package>`. Verified end to end on stock DSH with pi-mcp-adapter (full MCP manager: OAuth, resources, prompts, MCP Apps, elicitation, sampling), @tintinweb/pi-subagents, pi-code, pi-hermes-memory and pi-background-tasks; `pi2dsh inspect` reports a package's compatibility before installing.
Fishquito7/dsh-skill-mcp-panel★ 207
Manages DSH skills and MCP servers from the web settings: skill cards with hot enable/disable, workspace scopes, groups, batch migration and drag-and-drop import, plus stdio/HTTP MCP CRUD with connection tests, secret redaction and the unified dsh-panel CLI.
Community comments
Comments are public GitHub Discussions. Loading them connects to GitHub and Giscus; a GitHub account is required to post.