dsh-message-rewrite
Codex 风格消息原地编辑 DSH 插件:hover ✎ 编辑 → 同会话截断并重新生成回复(surface replacement)
- Stars
- 0
- Language
- JavaScript
- Created
- Sep 5, 2026
- Updated
- Sep 5, 2026
Introduction
dsh-message-rewrite
DeepSeek Harness(DSH)消息原地编辑插件 —— Codex 风格:hover 历史用户消息 → ✎ 编辑 → 同会话从编辑点截断旧回复并重新生成。
适用于 DeepSeek Harness 桌面 App / Web(DSH profile 插件体系,Cordis bundle 双半包:host index.js + client client.js)。
功能
- 消息原地编辑:鼠标 hover 自己发过的任意用户消息 → 出现「✎ 编辑」按钮。
- 精致浮层编辑器:点击后弹出居中玻璃拟态卡片,预填原内容,可反复编辑(编辑链),支持 Esc 取消 / ⌘Enter 发送 / 字数统计 / loading 状态。
- Codex 式截断重生成:发送后,被编辑消息及其后的旧回复从**消息表面(surface)**被替换(
surfaceOp: replace),同一会话从编辑点重新生成——不开新会话。 - 编辑链:编辑过的消息可以继续再编辑(A → B → C…),只显示最终版本。
- 中间消息自动 fork:编辑的若是中间消息(其后还有更新的用户消息),自动 fork 新会话改写,不误伤后续对话。
- 虚拟滚动兼容:按钮/气泡经 uuid 精确绑定,长会话、虚拟列表复用均不错位。
- 深色/浅色主题自适应。
安装
方式 A:profile bundle(推荐,与官方插件一致)
- 把本仓库
index.js、client.js、cordis.patch.yml放到你的 DSH profile 插件目录,例如:# 桌面 App profile 通常为 ~/.dsh/profiles/web PLUGIN_DIR=~/.dsh/profiles/web/plugins/dsh-message-rewrite mkdir -p "$PLUGIN_DIR" cp index.js client.js cordis.patch.yml package.json "$PLUGIN_DIR/" - 在
~/.dsh/profiles/web/package.json的dependencies加入:
在"dsh-message-rewrite": "file:./plugins/dsh-message-rewrite"dsh.profile.bundles数组加入:"dsh-message-rewrite" - 安装依赖并重启 DSH server(如
~/bin/dsh-server-restart),刷新页面。
方式 B:从 npm 安装(已发布)
cd ~/.dsh/profiles/web
pnpm add dsh-message-rewrite
# 并把 "dsh-message-rewrite" 加入 package.json 的 dsh.profile.bundles
bash ~/bin/dsh-server-restart # 重启后刷新页面
⚠️
cordis.patch.yml通过 bundle 通道自动加载;请勿再在主cordis.patch.yml重复 insert 本插件,否则 webserver 会因duplicate prefix route /dsh-rewrite启动崩溃。
使用
- 打开任意会话,把鼠标移到一条用户消息上(你自己的消息)。
- 点击行尾的 ✎ 编辑。
- 在浮层里修改文本,按 发送并重新生成(或 ⌘Enter)。
- 该消息之后被替换的旧回复会被隐藏,编辑后的内容气泡 + 新生成的回复出现在原位置。
- 编辑后的内容气泡 hover 会出现「✎ 再次编辑」,可继续形成编辑链。
Agent 运行中提交会提示「请先等待本轮结束」(不静默吞点击)。编辑中间消息会自动 fork 到新会话。
工作原理(适配 DSH 内核 0.1.2-rc.1)
- host(
index.js,CJS,injectconnection+agents)- RPC
/dsh-rewrite/list:列出会话 surface 上可编辑的用户消息(seq + 文本 + id + rewrite 元数据)。 - RPC
/dsh-rewrite/rewrite:校验 agent idle → 构造带source.rewrite的新 user message →agent.followup()入 inbox 唤醒 driver → 在agent/pre-step(prepend)拦截该消息的 append,包成surfaceOp:{op:"replace", start, end}+sourceEventSeqs,旧尾部从表面移除(审计日志保留)。
- RPC
- client(
client.js):__ModuleLoader__加载的 web 客户端;扫描官方消息列表(data-chat-flow-kind="user"+data-chat-anchor-key),用 uuid 与 host list 精确对齐挂 ✎ 按钮;自绘「✎ 已编辑」气泡(双锚点定位,兼容虚拟滚动);被 replace shadow 的旧行打data-message-rewrite-discarded隐藏。
关键内核 API(0.1.2-rc.1 实测)
ctx.on("agent/pre-step", ({agent, messages, signal}, next), {prepend:true})agent.session.append(type, data, {surfaceOp:{op:"replace",start,end}, sourceEventSeqs})agent.followup(msg)= inbox "next-turn" 插入 + wakeDriveragent.status(idle/running)、agent.session.surface.nodes、agent.session.eventscreateUserMessagefrom@deepseek-ai/dsh-llm(ESM,host 动态import)
卸载
- 从
~/.dsh/profiles/web/package.json移除依赖与dsh.profile.bundles条目。 - 删除
plugins/dsh-message-rewrite目录(如已软链进node_modules一并删除)。 - 重启 DSH server 并刷新页面。
已知边界
- 只对「用户消息」行挂编辑按钮;AI 回复行暂不支持编辑(可扩展「重新生成」)。
- 依赖 DSH 桌面 App / Web 的 profile 插件体系(Cordis +
__ModuleLoader__),非独立 CLI。 - 内核 API 随 DSH 版本演进可能变化(适配目标:0.1.2-rc.1)。
License
MIT