dsh-edit-diff 0.1.1 → 0.2.0
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/LICENSE +1 -1
- package/README.md +10 -8
- package/lib/client.js +37 -21
- package/lib/index.js +8 -9
- package/package.json +2 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -16,14 +16,15 @@ DeepSeek Harness 内置的 DiffBlock 展示工具改动时有个毛病:它拿
|
|
|
16
16
|
|
|
17
17
|
## 功能
|
|
18
18
|
|
|
19
|
-
-
|
|
19
|
+
- **仅差异行**:完全相同行直接不渲染,只显示真实变化的删除行红 `-` 与新增行绿 `+`,消除重复。
|
|
20
20
|
- **行内字符高亮**:删/增行数相等的替换对,再做字符级 diff,用下划线在行内标出真正改动的字符,而不是整行糊在一起。
|
|
21
|
-
-
|
|
21
|
+
- **近线性算法**:先做公共前缀/后缀收缩线性,仅对中间小差异带运行 Myers diff,复杂度与差异量成正比而非平方,超大文件也流畅。
|
|
22
22
|
- **默认收起**:卡片默认一行摘要,点开才显示 diff 体,不刷屏。
|
|
23
23
|
- **长 diff 二次折叠**:展开后若差异行超 14 行,折成头 +「⋯ 展开其余 N 行差异」+ 尾,点开才全量。
|
|
24
24
|
- **对齐原生观感**:字号、圆角、配色复用内置 DiffBlock/ToolRow 同一批 `--dsw-*` 主题变量,视觉上就是原生卡片。
|
|
25
|
-
-
|
|
26
|
-
- **单文件与多文件**:`edit` / `write`
|
|
25
|
+
- **复制与统计**:复制只含差异行,`- `/`+ ` 前缀;底部 `└ +A -R · N file(s)` 变更统计。
|
|
26
|
+
- **单文件与多文件**:`edit` / `write` 双双接管,覆盖新建只显示绿色新增,纯删、多 hunk 等场景。
|
|
27
|
+
- **PTC 模式兼容**:`run_code` 子调用中的 `edit` / `write` 同样显示去重 diff,通过 `callId` 中的 `:code:` 标记识别子调用。注意 `write` 是全文件覆写,无旧内容,只能显示全新增;想看精确 diff 应使用 `edit`。
|
|
27
28
|
|
|
28
29
|
## 它长什么样
|
|
29
30
|
|
|
@@ -32,7 +33,7 @@ DeepSeek Harness 内置的 DiffBlock 展示工具改动时有个毛病:它拿
|
|
|
32
33
|

|
|
33
34
|
|
|
34
35
|
- **顶部行**:`✎ Edit · dsh-cache-billing\src\client.ts`,右侧 chevron 可点开收起。
|
|
35
|
-
- **diff
|
|
36
|
+
- **diff 体**:只显示真实变化的删除行红色 `-` 与新增行绿色 `+`,完全相同行不重复渲染。
|
|
36
37
|
- **行内高亮**:把 `峰谷价标注` 改成 `峰谷价标注附模型名`,改动到的字符 `附模型名` 以下划线加粗标出;右下角为复制按钮。
|
|
37
38
|
- **底部统计**:`└ +1 -1 · 1 file`,列明净增删行数与文件数。
|
|
38
39
|
|
|
@@ -58,11 +59,12 @@ dsh plugin --profile web remove dsh-edit-diff
|
|
|
58
59
|
|
|
59
60
|
- 是**标准形态的 dsh client 插件**,声明 `dsh.client`,导出 `./client`。
|
|
60
61
|
- 同时声明了 `dsh.bundle`,因此也是一个**自挂载的 bundle 层插件**:用 `dsh plugin --profile <name> add` 从 GitHub 安装后,会被自动识别为 profile layer 并挂载,无需手工写组合 entry。
|
|
61
|
-
- 纯浏览器半身,无 host 行为;`lib/index.js` 是无操作的 no-op
|
|
62
|
+
- 纯浏览器半身,无 host 行为;`lib/index.js` 是无操作的 no-op 主机插件标准双面包约定。
|
|
62
63
|
- **UI 挂载点**:接管 keyed 槽位 `tool.call.toolview` 的 `edit` 与 `write` 两个 key。
|
|
63
|
-
- **遮蔽而非冲突**:注册时显式传 `priority: -1
|
|
64
|
+
- **遮蔽而非冲突**:注册时显式传 `priority: -1`低于内置 `file-mutation-toolview` 的默认 0,用更低优先级遮蔽默认渲染,而不是在同一优先级上 clash。
|
|
65
|
+
- **PTC 模式**:通过 `callId` 包含 `:code:` 判断是否为 `run_code` 子调用,从 `argsRaw` 中提取 `old_string`/`new_string` 即 edit 或 `content` 即 write 动态构建 diff。
|
|
64
66
|
- **无构建**:`lib/client.js` 是按 DSH client bundle 产出的注册式模块,源码即产物,改完即用。
|
|
65
|
-
- 纯 JavaScript 单文件,不引入任何额外 npm
|
|
67
|
+
- 纯 JavaScript 单文件,不引入任何额外 npm 依赖diff 算法就地内联。
|
|
66
68
|
|
|
67
69
|
## License
|
|
68
70
|
|
package/lib/client.js
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
//
|
|
1
|
+
// dsh-edit-diff 浏览器端,标准 dsh client bundle 形态。
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// resolves its externals through the loader's injected require, which for
|
|
6
|
-
// `react` returns the platform module-table instance kept alive by the shell
|
|
7
|
-
// seed. The default export is the Cordis plugin object the browser kernel
|
|
8
|
-
// adopts and mounts.
|
|
3
|
+
// 通过 window.__ModuleLoader__.load 注册模块表条目,factory 从注入的 require
|
|
4
|
+
// 解析 react 等外部依赖。默认导出 Cordis 插件对象,由浏览器内核挂载。
|
|
9
5
|
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
// skipping identical lines entirely and highlighting real intra-line character
|
|
17
|
-
// changes. Visuals mirror the shipped DiffBlock/ToolRow so the card reads as
|
|
18
|
-
// native. Cards collapse to a single summary row by default; opening shows the
|
|
19
|
-
// body, and a very long diff folds its middle behind a "⋯ 展开其余 N 行差异"
|
|
20
|
-
// button instead of flooding the flow.
|
|
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。
|
|
21
12
|
|
|
22
13
|
window.__ModuleLoader__.load({
|
|
23
14
|
id: 'dsh-edit-diff',
|
|
@@ -96,7 +87,7 @@ window.__ModuleLoader__.load({
|
|
|
96
87
|
return ops
|
|
97
88
|
}
|
|
98
89
|
|
|
99
|
-
/** 把字符级 op
|
|
90
|
+
/** 把字符级 op 汇总成高亮区间 [start, end)。 */
|
|
100
91
|
function charRanges(ops) {
|
|
101
92
|
const delR = [], addR = []
|
|
102
93
|
for (const op of ops) {
|
|
@@ -125,7 +116,7 @@ window.__ModuleLoader__.load({
|
|
|
125
116
|
return (text.endsWith('\n') ? text.slice(0, -1) : text).split('\n')
|
|
126
117
|
}
|
|
127
118
|
|
|
128
|
-
/** 从 ops
|
|
119
|
+
/** 从 ops 构建渲染行,仅含真实差异;替换对删/增行数相等做行内字符高亮。 */
|
|
129
120
|
function buildDiffLines(oldLines, newLines) {
|
|
130
121
|
const ops = lineDiff(oldLines, newLines)
|
|
131
122
|
const out = []
|
|
@@ -169,6 +160,31 @@ window.__ModuleLoader__.load({
|
|
|
169
160
|
}
|
|
170
161
|
|
|
171
162
|
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
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
} catch {}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 标准模式:从 callView 或 resultView 提取 diffs
|
|
172
188
|
if (!('kind' in block)) {
|
|
173
189
|
const call = block.callView && block.callView.card === 'diff' ? block.callView : null
|
|
174
190
|
return call ? narrowDiffs(call.diffs) : null
|
|
@@ -405,7 +421,7 @@ window.__ModuleLoader__.load({
|
|
|
405
421
|
})
|
|
406
422
|
|
|
407
423
|
slots.inject('tool.call.toolview', () => {
|
|
408
|
-
// priority 要低于默认 0,遮蔽 file-mutation-toolview 的 edit/write
|
|
424
|
+
// priority 要低于默认 0,遮蔽 file-mutation-toolview 的 edit/write,最低者渲染;
|
|
409
425
|
// 若也传 0 会在同一 key 上 clash,而非替换。
|
|
410
426
|
slots.register({ name: 'tool.call.toolview', key: 'edit', priority: -1 }, DiffCard)
|
|
411
427
|
slots.register({ name: 'tool.call.toolview', key: 'write', priority: -1 }, DiffCard)
|
package/lib/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* single `dsh plugin --profile web add …` fully activates it.
|
|
2
|
+
* 主机端:空操作 Cordis 插件。所有行为在浏览器端 lib/client.js,
|
|
3
|
+
* 通过 package.json dsh.client 声明被 web 客户端模块系统发现。
|
|
4
|
+
* 本半身存在是为了让插件根目录成为完整的双面包,在宿主 Loader 中
|
|
5
|
+
* 显示为一个条目;通过 dsh.bundle 成为自挂载 bundle 层,
|
|
6
|
+
* 一条 dsh plugin --profile web add 即可完整激活。
|
|
8
7
|
*/
|
|
9
|
-
/**
|
|
8
|
+
/** 插件名,即配置条目 id。 */
|
|
10
9
|
const name = "dsh-edit-diff";
|
|
11
|
-
/**
|
|
10
|
+
/** 不使用任何主机端服务。 */
|
|
12
11
|
const inject = [];
|
|
13
|
-
/**
|
|
12
|
+
/** 本浏览器端插件无主机端行为。 */
|
|
14
13
|
function apply() {}
|
|
15
14
|
export { apply, inject, name };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-edit-diff",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "质量 diff:接管 edit/write
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "质量 diff:接管 edit/write 工具卡片,行级去重与行内高亮,消除相同内容在删除与新增两区的重复;兼容 PTC 模式,标准可安装的 dsh 客户端插件",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
7
7
|
"dsh",
|