Back to home@lzxcs

edit-diff-pro

Claude Code 风格的 edit/write diff 卡片:±3 行上下文、绝对行号、可配置默认展开(默认折叠)。

Stars
0
Language
JavaScript
Created
Aug 26, 2026
Updated
Aug 26, 2026

Introduction

edit-diff-pro

安装(Install)

需要 DSH(DeepSeek Harness)与 web profile(dsh web):

# 1. 安装插件(pnpm git 依赖)
dsh plugin --profile web add github:lzxcs/edit-diff-pro
# 2. 在 ~/.dsh/profiles/web/cordis.patch.yml 末尾追加注入块:
- insert:
    - id: edit-diff-pro
      name: 'edit-diff-pro'
# 3. 重启 DSH Web(托盘菜单 → DSH Web 重启),浏览器 Ctrl+F5 刷新页面

卸载:dsh plugin --profile web remove edit-diff-pro,并删掉 cordis.patch.yml 中的注入块。

Web GUI 插件:把 edit / write 工具调用的 diff 卡片替换为 Claude Code 风格视图。

功能

  • 可配置默认展开:新卡片默认折叠(与内置卡片一致),设置页(设置 → 插件 → "Diff 卡片")可切换为默认展开;点击卡片头部随时手动折叠/展开。
  • 上下文 + 行号:结果 hunk 本身携带 ±3 行上下文;本插件按行对齐渲染(LCS),上下文行中性色、删除行红色 -、新增行绿色 +,每行显示文件中的绝对行号(新增行显示新行号,其余显示旧行号)。
  • 可定制颜色:设置页(设置 → 插件 → "Diff 卡片")提供删除/新增行的背景色与文字色四个取色器;保存后所有 diff 卡片即时更新,重置默认 恢复主题淡色样式、默认折叠阈值与默认折叠。颜色经 settings 服务持久化到 $DSH_HOME/settings.yamledit-diff-pro: 段(留空 = 未自定义)。
  • 自动折叠:hunk 行数超过折叠阈值(设置页可调,默认 100 行)时自动折叠中间内容,保留头尾各一半行数;点击分界行"⋯ 已折叠 N 行 · 点击展开本段"只展开当前 hunk,卡片底部"全部展开 N 处折叠"一键展开全部。至少隐藏 10 行才折叠,避免一两个行的无意义折叠。阈值持久化在 edit-diff-pro: 段的 foldThreshold(20–5000,默认 100)。
  • 优雅降级:文件已删除、被后续修改、超过 4MB 或读取失败时,退化为不带行号的对齐视图;运行中的调用按参数视图渲染。

结构

  • lib/index.js — Node half:通过 ctx.inject 注册回环路由与 settings 命名空间。
    • GET /__edit-diff-pro/read?path=<path>[&cwd=<root>]{ content }(LF 归一化);
    • GET/POST /__edit-diff-pro/settings → 读取/写入 { colors, foldThreshold, defaultExpanded },经 settings 服务落到 $DSH_HOME/settings.yamledit-diff-pro: 段;
    • settings.register('edit-diff-pro', passThrough, { base }):让设置页能分发我们的卡片 (modlens 同款 pass-through schema)。
  • lib/client.js — Browser half:window.__ModuleLoader__.load 惰性 CJS 工厂, require('react'),注册 tool.call.toolviewedit / write 两个 key (priority: -1 影遮内置行),及 settings.plugin.itemedit-diff-pro 设置卡片; 颜色经共享 store 广播给所有 diff 卡片,以 CSS 变量 --dshdc-* 落到卡片根节点。

安装(本 profile)

  • package.json dependencies 加 "edit-diff-pro": "file:./edit-diff-pro"
  • cordis.patch.yml insert 行 { id: edit-diff-pro, name: 'edit-diff-pro' }
  • pnpm-workspace.yaml packages 加入 edit-diff-pro
  • pnpm install 后重启 dsh web

维护提示:pnpm 的 hoisted 链接器对 file: 依赖会拷贝进 store 而不是软链, 且不会自动重建被删除的链接。本 profile 中 node_modules\edit-diff-pro 是指向 源码目录的 junctionNew-Item -ItemType Junction),因此改 lib/client.js 后刷新页面即生效(服务端按请求读文件)。若某次 pnpm install 把它清掉了, 重新执行:

New-Item -ItemType Junction -Path "node_modules\edit-diff-pro" -Target "~/.dsh\profiles\web\edit-diff-pro"

安全说明

读取路由绑定在 dsh 自带的回环 web 服务器上(默认 127.0.0.1),无鉴权;它只读文件, 大小上限 4MB。与内置 fs 工具同一权限面(本机用户可读路径),不额外放开写权限。