dsh-edit-diff 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # dsh·去重复 diff 展示插件
1
+ # dsh·修改显示优化插件
2
2
 
3
3
  接管 DSH 浏览器的 `edit` / `write` 工具卡片,用近线性行级 diff 做真正的差异展示,消除内置 DiffBlock 把「未变化的相同行」在删除区红 `-` 行和新增区绿 `+` 行各渲染一遍的重复。
4
4
 
@@ -6,13 +6,11 @@
6
6
 
7
7
  ## 引言
8
8
 
9
- DeepSeek Harness 内置的 DiffBlock 展示工具改动时有个毛病:它拿到旧文件全文和新文件全文,就把旧的全染成红色 `-` 行、新的全染成绿色 `+` 行——**完全不做行级匹配**。
9
+ 原版 diff 的显示相当离谱:一次只修改一行,它却把这行连同上下各三行一起带进 diff,共十四行,其中七行被折叠,正好红区和绿区完全不重叠。不点开二级展开根本看不出到底改了什么——点开了也照样看花眼。
10
10
 
11
- 结果呢?一次只改了一小段的 edit,一堆根本没变的注释、空行、样板代码,在红绿两区各出现一遍,仿佛同一句话被说了两次。大文件改起来更是重复加刷屏,想扫一眼真正改了什么,得靠肉眼在一大摊重复里找不同。
11
+ 这个插件把无关的相同行全部去除。只修改一行时,就只显示一行红一行绿,真正的修改加粗划线,一眼就能看清改在哪里。
12
12
 
13
- 这哪行。改个文件就该像看 git diff 一样:**只亮出真正的差异,相同行不该凑热闹**。
14
-
15
- 于是这个插件接管了 `edit` 和 `write` 两个工具卡片,用近线性算法算出真实差异,相同行一行不渲染,替换行还把改动到的具体字符用下划线标出来。一眼就知道到底改了什么。
13
+ 另外,PTC 模式下默认只显示调用成功与否,本插件也做了适配,能正常显示修改内容。
16
14
 
17
15
  ## 功能
18
16
 
@@ -24,18 +22,14 @@ DeepSeek Harness 内置的 DiffBlock 展示工具改动时有个毛病:它拿
24
22
  - **对齐原生观感**:字号、圆角、配色复用内置 DiffBlock/ToolRow 同一批 `--dsw-*` 主题变量,视觉上就是原生卡片。
25
23
  - **复制与统计**:复制只含差异行,`- `/`+ ` 前缀;底部 `└ +A -R · N file(s)` 变更统计。
26
24
  - **单文件与多文件**:`edit` / `write` 双双接管,覆盖新建只显示绿色新增,纯删、多 hunk 等场景。
27
- - **PTC 模式兼容**:`run_code` 子调用中的 `edit` / `write` 同样显示去重 diff,通过 `callId` 中的 `:code:` 标记识别子调用。注意 `write` 是全文件覆写,无旧内容,只能显示全新增;想看精确 diff 应使用 `edit`。
25
+ - **PTC 模式兼容**:`run_code` 子调用中的 `edit` / `write` 同样显示优化后的修改 diff,通过 `callId` 中的 `:code:` 标记识别子调用。注意 `write` 是全文件覆写,无旧内容,只能显示全新增;想看精确 diff 应使用 `edit`。
28
26
 
29
27
  ## 它长什么样
30
28
 
31
- `edit` 只改动一小段后的实际效果:
32
-
33
- ![去重复 diff 效果](docs/去重复diff.webp)
34
-
35
- - **顶部行**:`✎ Edit · dsh-cache-billing\src\client.ts`,右侧 chevron 可点开收起。
36
- - **diff 体**:只显示真实变化的删除行红色 `-` 与新增行绿色 `+`,完全相同行不重复渲染。
37
- - **行内高亮**:把 `峰谷价标注` 改成 `峰谷价标注附模型名`,改动到的字符 `附模型名` 以下划线加粗标出;右下角为复制按钮。
38
- - **底部统计**:`└ +1 -1 · 1 file`,列明净增删行数与文件数。
29
+ | | 效果图 |
30
+ | --- | --- |
31
+ | 原版 diff | ![原版离谱显示](docs/原版diff.webp) |
32
+ | 本插件 | ![插件优化显示](docs/优化diff.webp) |
39
33
 
40
34
  ## 安装
41
35
 
package/lib/client.js CHANGED
@@ -1,14 +1,13 @@
1
1
  // dsh-edit-diff 浏览器端,标准 dsh client bundle 形态。
2
2
  //
3
- // 通过 window.__ModuleLoader__.load 注册模块表条目,factory 从注入的 require
4
- // 解析 react 等外部依赖。默认导出 Cordis 插件对象,由浏览器内核挂载。
3
+ // 通过 window.__ModuleLoader__.load 注册模块表条目,factory 从注入的 require 解析 react 等外部依赖。
4
+ // 默认导出 Cordis 插件对象,由浏览器内核挂载。
5
5
  //
6
- // 接管 edit/write 工具卡片:内置 DiffBlock 对新旧全文逐行染色,不做行级匹配,
7
- // 相同行在红绿两区各渲染一遍。本插件接管 tool.call.toolview 的 edit/write key
8
- // 用近线性行级 diff 公共前缀/后缀收缩 + Myers 跳过相同行,替换行做字符级
9
- // 下划线高亮。视觉对齐内置 DiffBlock/ToolRow。卡片默认收起,长 diff 二次折叠。
10
- // PTC 模式下 run_code 子调用中的 edit/write 同样显示去重 diff
11
- // 通过 callId 中的 :code: 标记识别子调用,从 argsRaw 动态构建 diff。
6
+ // 接管 edit/write 工具卡片:内置 DiffBlock 对新旧全文逐行染色且不做行级匹配,相同行在红绿两区各渲染一遍。
7
+ // 本插件接管 tool.call.toolview 的 edit/write key,用近线性行级 diff 跳过相同行,替换行做字符级下划线高亮。
8
+ // 视觉对齐内置 DiffBlock/ToolRow。卡片默认收起,长 diff 二次折叠。
9
+ //
10
+ // PTC 模式下 run_code 子调用中的 edit/write 同样显示去重 diff,按 callId 的 :code: 标记识别,从 argsRaw 动态构建。
12
11
 
13
12
  window.__ModuleLoader__.load({
14
13
  id: 'dsh-edit-diff',
@@ -160,32 +159,49 @@ window.__ModuleLoader__.load({
160
159
  }
161
160
 
162
161
  function extractDiffs(block) {
163
- // PTC 模式:从 argsRaw 动态构建 diffs
164
- // callId 包含 ':code:' 表示这是 run_code 的子调用
165
- if (typeof block.callId === 'string' && block.callId.includes(':code:')) {
166
- // RunningToolCall 的 argsRaw 在 block 上,ToolResultNode argsRaw block.call 上
167
- const argsRaw = block.call ? block.call.argsRaw : block.argsRaw
168
- const name = block.call ? block.call.name : block.name
169
- if (name === 'edit' || name === 'write') {
170
- try {
171
- const args = JSON.parse(argsRaw)
172
- if (args && typeof args === 'object') {
173
- const filePath = args.file_path
174
- if (typeof filePath === 'string' && filePath !== '') {
175
- if (name === 'write' && typeof args.content === 'string') {
176
- return narrowDiffs([{ path: filePath, oldText: null, newText: args.content }])
177
- }
178
- if (name === 'edit' && typeof args.old_string === 'string' && typeof args.new_string === 'string') {
179
- return narrowDiffs([{ path: filePath, oldText: args.old_string || null, newText: args.new_string }])
180
- }
162
+ const done = 'kind' in block
163
+ // PTC 子调用标记:新版 DSH 用 parentCallId;旧版 callId ':code:',双兼容
164
+ const subCall = block.parentCallId !== void 0 ||
165
+ (typeof block.callId === 'string' && block.callId.includes(':code:'))
166
+
167
+ // settled 且非错误:取真实应用的 diff,新版 DSH 存放在 block.meta.diffs。
168
+ // 结构与内置 diffCardModel/appliedDiffs 同构,支持多 hunk。
169
+ if (done && !subCall && !block.isError) {
170
+ const meta = block.meta
171
+ if (meta !== null && typeof meta === 'object' && !Array.isArray(meta)) {
172
+ const diffs = meta.diffs
173
+ if (Array.isArray(diffs) && diffs.length > 0) {
174
+ const n = narrowDiffs(diffs)
175
+ if (n !== null) return n
176
+ }
177
+ }
178
+ }
179
+
180
+ // 子调用 / running / 兜底:没有真实 diff,改为从参数意图推断。
181
+ // running 的 argsRaw/name 在 block 顶层,settled 的挪到 block.call 上,两处兼容。
182
+ // settled 失败同样不显示意图 diff,与内置 diffCardModel 一致。
183
+ if (done && !subCall && block.isError) return null
184
+ const argsRaw = (block.call ? block.call.argsRaw : block.argsRaw) ?? ''
185
+ const name = block.call ? block.call.name : block.name
186
+ if (name === 'edit' || name === 'write') {
187
+ try {
188
+ const args = JSON.parse(argsRaw)
189
+ if (args && typeof args === 'object') {
190
+ const filePath = args.file_path
191
+ if (typeof filePath === 'string' && filePath !== '') {
192
+ if (name === 'write' && typeof args.content === 'string') {
193
+ return narrowDiffs([{ path: filePath, oldText: null, newText: args.content }])
194
+ }
195
+ if (name === 'edit' && typeof args.old_string === 'string' && typeof args.new_string === 'string') {
196
+ return narrowDiffs([{ path: filePath, oldText: args.old_string || null, newText: args.new_string }])
181
197
  }
182
198
  }
183
- } catch {}
184
- }
199
+ }
200
+ } catch {}
185
201
  }
186
-
187
- // 标准模式:从 callView resultView 提取 diffs
188
- if (!('kind' in block)) {
202
+
203
+ // 旧版 DSH 0.1.x 重构前没有以上字段,回退从 callView/resultView diff。
204
+ if (!done) {
189
205
  const call = block.callView && block.callView.card === 'diff' ? block.callView : null
190
206
  return call ? narrowDiffs(call.diffs) : null
191
207
  }
@@ -421,7 +437,7 @@ window.__ModuleLoader__.load({
421
437
  })
422
438
 
423
439
  slots.inject('tool.call.toolview', () => {
424
- // priority 要低于默认 0,遮蔽 file-mutation-toolview 的 edit/write,最低者渲染;
440
+ // priority 要低于默认 0,遮蔽 file-mutation-toolview 的 edit/write,最低者渲染。
425
441
  // 若也传 0 会在同一 key 上 clash,而非替换。
426
442
  slots.register({ name: 'tool.call.toolview', key: 'edit', priority: -1 }, DiffCard)
427
443
  slots.register({ name: 'tool.call.toolview', key: 'write', priority: -1 }, DiffCard)
package/lib/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  /**
2
- * 主机端:空操作 Cordis 插件。所有行为在浏览器端 lib/client.js,
3
- * 通过 package.json dsh.client 声明被 web 客户端模块系统发现。
4
- * 本半身存在是为了让插件根目录成为完整的双面包,在宿主 Loader
5
- * 显示为一个条目;通过 dsh.bundle 成为自挂载 bundle 层,
6
- * 一条 dsh plugin --profile web add 即可完整激活。
2
+ * 主机端:空操作 Cordis 插件。
3
+ * 所有行为在浏览器端 lib/client.js,通过 package.json dsh.client 声明被 web 客户端模块系统发现。
4
+ * 本半身存在是为了让插件根目录成为完整的双面包,在宿主 Loader 中显示为一个条目。
5
+ * 通过 dsh.bundle 成为自挂载 bundle 层,一条 dsh plugin --profile web add 即可完整激活。
7
6
  */
8
7
  /** 插件名,即配置条目 id。 */
9
8
  const name = "dsh-edit-diff";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-edit-diff",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "质量 diff:接管 edit/write 工具卡片,行级去重与行内高亮,消除相同内容在删除与新增两区的重复;兼容 PTC 模式,标准可安装的 dsh 客户端插件",
5
5
  "keywords": [
6
6
  "deepseek-harness",