Skip to content

dsh-anchored

Verified

dsh-anchored · v1.0.1 · MIT

Anchor-verified file editing for DeepSeek Harness: four-letter line anchors, stale-proof edits, and a guard that keeps shell/code from modifying files directly.

Install

dsh plugin add dsh-anchored

Confirm the layer applied with dsh --profile default --dump-config — see the install guide.

Source

Published to npm without a public repository. Inspect the package contents before installing.

Tags

Creators

Readme

Anchored · dsh-anchored

每一次编辑都钉在你读到的那一行。锚点不对,编辑就被拒绝。

把 Feather 的 anchor / hashline 编辑模型移植到 DeepSeek Harness: 读取文件时每一行带一个四字母锚点,编辑只认锚点、不认行号,也不做模糊匹配; 同时用一个 tools/pre-execute 策略闸门禁止命令行与内联代码直接改文件。

aQmz│fn main() {
Rk4v│    println!("hello");
bN7t│}

它替换了什么

bundle patch 分三层替换内置文件工具:

  1. 非 Web 的单 agent 部署:把宿主平面 @deepseek-ai/dsh-tool-fs 的 read / write / edit 关掉,只保留 read_image。
  2. Web 默认的 preset-standard 与 subagent 使用的 preset-cordis:在各自的完整 preset 插件表里关掉这三个工具,并把 dsh-anchored 挂进该 preset,按 agent 作用域注册锚点工具。
  3. 一个全局 dsh-anchored 兜底行:给仍停留在旧 preset 修订上的会话提供写入闸门,以及不与旧 scoped 名称冲突的锚点工具。

然后注册本插件的工具:

工具 作用
read 按 anchor│content 返回文件;offset / limit 分页
replace 用一个锚点范围替换成新文本;空文本即删除
replace_within 只替换行内一段;replace_old 必须在范围内恰好出现一次
insert 在某一行前/后插入多行
copy / move 按锚点跨行、跨文件复制/移动
write 新建或整体重写文件,返回新锚点
undo_last_change 撤销该文件上一次编辑;文件已变化时拒绝
anchor_grep 正则搜索,命中行直接带锚点,可不再 read 就编辑

锚点的性质与 Feather 一致:

  • 4 个字母、区分大小写,没有数字和符号,便于模型按 token 处理;
  • 未改动的行在编辑后保留原锚点;删除行的锚点 LIFO 复用,新行从每文件确定性的 随机流中取新锚点;
  • 每次编辑前都重新核对磁盘内容,内容变了就重建映射并让旧锚点失效;
  • 编辑失败会带 [E_ANCHOR_STALE] / [E_UNKNOWN_ANCHOR] / [E_MATCH_COUNT] 和当前行一起返回,模型可原地重试;
  • 保留 CRLF / LF 与文件末尾换行约定;空文件始终保留一个可寻址的空行。

写入策略

tools/pre-execute 闸门会拒绝以下“直接改文件”的行为,命令不会被执行:

  • shell 重定向、tee、dd of=、touch、truncate;
  • rm / rmdir / mv / cp / install / ln、sed -i、perl -i、 awk inplace、patch、vim/nano 等编辑器;
  • 会改写工作区的 git 子命令(checkout、restore、reset、clean、 apply、merge、rebase、pull 等);
  • 会改 manifest 的包管理器子命令(pnpm add、npm install <pkg>、 cargo add、go get、dotnet add 等);
  • PowerShell 的 Set-Content、Out-File、New-Item、Remove-Item、 Move-Item、Copy-Item 等写文件 cmdlet;
  • python -c / node -e / heredoc / bash -c 等内联代码里出现写文件 API;
  • 其他会写文件的工具名:edit、ops_write_file、ops_edit_file、 ops_replace(dryRun 除外)、ops_copy、ops_move、ops_remove、 ops_batch(plan 除外)、apply_patch、str_replace_editor(view 除外)。

读取、构建、测试、pnpm install、cargo build、git status/commit 等仍然允许; 构建工具写出的生成物(target/、dist/ 等)不在此策略的审查范围内。

这是策略闸门,不是 OS 级隔离。它识别的是常见的直接写文件形式;被按名字调用的 项目脚本(如 python build.py)不会被逐行审计。真正的边界仍由 DSH 的 sandboxPolicy(read-only / workspace-write / danger-full-access)负责。

安装

公开包已发布:dsh-anchored。

在 DSH Desktop:Settings → Plugins → 安装插件,输入 dsh-anchored;或用 CLI:

dsh plugin --profile desktop add dsh-anchored

本地开发时也可以用绝对路径安装本目录:

plugin_manager install_bundle target=D:\Work\dsh-hashline

安装或更新后请重启 DeepSeek Harness:宿主插件模块需要新的 JavaScript 代次,而已经打开的 会话会保留启动时的 preset 修订。重启后新建会话(或恢复会话)会重新挂载最新 preset。 判断是否生效:read 的返回行应形如 aQmz│...,且工具表里没有 edit。

目录

cordis.patch.yml   关闭工具行,覆盖 preset-standard / preset-cordis,插入 dsh-anchored
lib/engine.js      锚点引擎(replace/insert/copy/move/undo、stale 校验、diff)
lib/store.js       ctx.fs 适配、锚点解析、文件刷新、anchor_grep
lib/tools.js       9 个模型工具的定义
lib/guard.js       tools/pre-execute 写文件闸门
test/run.mjs       离线假 ctx.fs 测试(node test/run.mjs)

限制

  • 锚点映射保存在 Host 进程内。未改动的文件重启后会得到相同锚点(种子由规范路径 + 内容哈希决定);编辑过的文件重启后需要重新 read。
  • 同一锚点出现在多个已映射文件时,按最近 touch 的文件优先(与 Feather 一致)。
  • anchor_grep 跳过 .git、node_modules、target、dist 等目录,单文件上限 2 MiB,单次最多扫描 5000 个文件。
  • 文件必须能整体按 UTF-8 文本读取;二进制、UTF-16、非 UTF-8 会被拒绝。
  • 新建文件的父目录由插件在 workspace 根内补建;read-only 模式下不会补建。

验证

node test/run.mjs

覆盖:锚点稳定性、replace/insert/undo、stale 拒绝、空文件、CRLF、跨文件 copy/move、 anchor_grep、以及 shell/内联代码/写文件工具的拦截。

已在本机验证:node test/run.mjs 全部通过;当前 Host 里全局 replace / insert / anchor_grep 与写入闸门可用(shell 重定向被拒绝)。 read / write 的 preset 级替换需要重启后新建会话才能观察,因为运行中的会话固定使用启动时的 preset 修订。

License

MIT © 2026 pagey