dsh-edit-diff 0.2.0 → 0.3.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/lib/client.js CHANGED
@@ -1,440 +1,605 @@
1
- // dsh-edit-diff 浏览器端,标准 dsh client bundle 形态。
2
- //
3
- // 通过 window.__ModuleLoader__.load 注册模块表条目,factory 从注入的 require
4
- // 解析 react 等外部依赖。默认导出 Cordis 插件对象,由浏览器内核挂载。
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。
12
-
13
1
  window.__ModuleLoader__.load({
14
- id: 'dsh-edit-diff',
15
- factory: (require) => {
16
- const module = { exports: {} }
17
- const exports = module.exports
18
-
19
- const React = require('react')
20
- const DOC = typeof document !== 'undefined' ? document : null
21
-
22
- // ==================== 近线性 diff 核心 ====================
23
-
24
- /** 行级 Myers:前缀/后缀收缩后仅对中间核心区跑 diff,返回 op 数组。 */
25
- function myersDiff(aList, bList) {
26
- const N = aList.length, M = bList.length
27
- const max = N + M
28
- let prev = { 1: 0 }
29
- const trace = []
30
- let dMax = 0, found = false
31
- for (let d = 0; d <= max; d++) {
32
- trace.push({ ...prev })
33
- const cur = {}
34
- for (let k = -d; k <= d; k += 2) {
35
- let x
36
- if (k === -d || (k !== d && (prev[k - 1] ?? -Infinity) < (prev[k + 1] ?? -Infinity))) x = (prev[k + 1] ?? 0)
37
- else x = (prev[k - 1] ?? -1) + 1
38
- let y = x - k
39
- while (x < N && y < M && aList[x] === bList[y]) { x++; y++ }
40
- cur[k] = x
41
- if (x >= N && y >= M) { dMax = d; found = true; break }
42
- }
43
- prev = cur
44
- if (found) break
45
- }
46
- if (!found) {
47
- const ops = []
48
- for (let i = 0; i < N; i++) ops.push({ type: 'del', a: i, b: -1 })
49
- for (let j = 0; j < M; j++) ops.push({ type: 'add', a: -1, b: j })
50
- return ops
51
- }
52
- const ops = []
53
- let x = N, y = M
54
- for (let d = dMax; d > 0; d--) {
55
- const t = trace[d]
56
- const k = x - y
57
- let prevK
58
- if (k === -d || (k !== d && (t[k - 1] ?? -Infinity) < (t[k + 1] ?? -Infinity))) prevK = k + 1
59
- else prevK = k - 1
60
- const prevX = t[prevK] ?? 0
61
- const prevY = prevX - prevK
62
- while (x > prevX && y > prevY) { ops.push({ type: 'same', a: x - 1, b: y - 1 }); x--; y-- }
63
- if (x === prevX) { ops.push({ type: 'add', a: -1, b: y - 1 }); y-- }
64
- else { ops.push({ type: 'del', a: x - 1, b: -1 }); x-- }
65
- }
66
- while (x > 0 && y > 0) { ops.push({ type: 'same', a: x - 1, b: y - 1 }); x--; y-- }
67
- ops.reverse()
68
- return ops
69
- }
70
-
71
- /** 行级 diff:线性前缀/后缀收缩,仅对中间核心区跑 Myers。 */
72
- function lineDiff(aLines, bLines) {
73
- let p = 0
74
- const minLen = Math.min(aLines.length, bLines.length)
75
- while (p < minLen && aLines[p] === bLines[p]) p++
76
- let s = 0
77
- const al = aLines.length, bl = bLines.length
78
- while (s < minLen - p && aLines[al - 1 - s] === bLines[bl - 1 - s]) s++
79
- const ops = []
80
- for (let i = 0; i < p; i++) ops.push({ type: 'same', a: i, b: i })
81
- const aMid = aLines.slice(p, al - s)
82
- const bMid = bLines.slice(p, bl - s)
83
- for (const op of myersDiff(aMid, bMid)) {
84
- ops.push({ type: op.type, a: op.a === -1 ? -1 : op.a + p, b: op.b === -1 ? -1 : op.b + p })
85
- }
86
- for (let i = 0; i < s; i++) ops.push({ type: 'same', a: al - s + i, b: bl - s + i })
87
- return ops
88
- }
89
-
90
- /** 把字符级 op 汇总成高亮区间 [start, end)。 */
91
- function charRanges(ops) {
92
- const delR = [], addR = []
93
- for (const op of ops) {
94
- if (op.type === 'del') delR.push(op.a)
95
- else if (op.type === 'add') addR.push(op.b)
96
- }
97
- const mk = (idx) => {
98
- if (idx.length === 0) return []
99
- idx.sort((a, b) => a - b)
100
- const out = []; let s = idx[0], e = idx[0]
101
- for (let i = 1; i < idx.length; i++) {
102
- if (idx[i] === e + 1) e = idx[i]
103
- else { out.push([s, e + 1]); s = idx[i]; e = idx[i] }
104
- }
105
- out.push([s, e + 1])
106
- return out
107
- }
108
- return { del: mk(delR), add: mk(addR) }
109
- }
110
- function lineHighlight(oldStr, newStr) {
111
- return charRanges(myersDiff([...oldStr], [...newStr]))
112
- }
113
-
114
- function contentLines(text) {
115
- if (text === '') return []
116
- return (text.endsWith('\n') ? text.slice(0, -1) : text).split('\n')
117
- }
118
-
119
- /** 从 ops 构建渲染行,仅含真实差异;替换对删/增行数相等做行内字符高亮。 */
120
- function buildDiffLines(oldLines, newLines) {
121
- const ops = lineDiff(oldLines, newLines)
122
- const out = []
123
- let i = 0
124
- while (i < ops.length) {
125
- if (ops[i].type === 'same') { i++; continue }
126
- const dStart = i
127
- while (i < ops.length && ops[i].type === 'del') i++
128
- const addStart = i
129
- while (i < ops.length && ops[i].type === 'add') i++
130
- const delOps = ops.slice(dStart, addStart)
131
- const addOps = ops.slice(addStart, i)
132
- if (delOps.length === addOps.length && delOps.length > 0) {
133
- for (let k = 0; k < delOps.length; k++) {
134
- const hl = lineHighlight(oldLines[delOps[k].a], newLines[addOps[k].b])
135
- out.push({ kind: 'del', text: oldLines[delOps[k].a], hl: hl.del })
136
- out.push({ kind: 'add', text: newLines[addOps[k].b], hl: hl.add })
137
- }
138
- } else {
139
- for (const op of delOps) out.push({ kind: 'del', text: oldLines[op.a], hl: [] })
140
- for (const op of addOps) out.push({ kind: 'add', text: newLines[op.b], hl: [] })
141
- }
142
- }
143
- return out
144
- }
145
-
146
- // ==================== 卡片模型 ====================
147
-
148
- function narrowDiffs(diffs) {
149
- if (!Array.isArray(diffs) || diffs.length === 0) return null
150
- const out = []
151
- for (const h of diffs) {
152
- if (typeof h !== 'object' || h === null) return null
153
- const path = h.path, oldText = h.oldText, newText = h.newText
154
- if (typeof path !== 'string') return null
155
- if (oldText !== null && typeof oldText !== 'string') return null
156
- if (typeof newText !== 'string') return null
157
- out.push({ path, oldText, newText })
158
- }
159
- return out
160
- }
161
-
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
188
- if (!('kind' in block)) {
189
- const call = block.callView && block.callView.card === 'diff' ? block.callView : null
190
- return call ? narrowDiffs(call.diffs) : null
191
- }
192
- const result = block.resultView && block.resultView.card === 'diff' ? block.resultView : null
193
- return result ? narrowDiffs(result.diffs) : null
194
- }
195
-
196
- function resultText(block) {
197
- if (!('kind' in block)) return ''
198
- const parts = []
199
- for (const b of block.content) {
200
- parts.push(b.type === 'text' ? b.text : JSON.stringify(b))
201
- }
202
- if (parts.length === 0 && block.error !== undefined) parts.push(block.error.name + ': ' + block.error.code)
203
- return parts.join('\n')
204
- }
205
-
206
- function firstLine(t) { const n = t.indexOf('\n'); return n === -1 ? t : t.slice(0, n) }
207
-
208
- function buildCardModel(block, toolName, cwd) {
209
- const done = 'kind' in block
210
- const argsRaw = (done ? (block.call ? block.call.argsRaw : '') : (block.argsRaw ?? ''))
211
- const state = !done ? 'running' : (block.error && block.error.code === 'interrupted') ? 'stopped' : block.isError ? 'error' : 'ok'
212
- let filePath
213
- let summary = ''
214
- try {
215
- const parsed = JSON.parse(argsRaw)
216
- if (parsed && typeof parsed === 'object') {
217
- const p = parsed.file_path ?? parsed.path
218
- if (typeof p === 'string' && p !== '') filePath = firstLine(p)
219
- const vs = Object.values(parsed).filter(v => typeof v === 'string' && v !== '')
220
- summary = vs.length > 0 ? firstLine(vs[0]) : argsRaw
221
- } else summary = firstLine(argsRaw)
222
- } catch { summary = firstLine(argsRaw) }
223
- if (filePath !== undefined) summary = filePath
224
- if (filePath !== undefined && cwd) {
225
- const root = cwd.replace(/[/\\]+$/, '')
226
- if (filePath.startsWith(root + '/') || filePath.startsWith(root + '\\')) summary = filePath.slice(root.length + 1)
227
- }
228
- const title = toolName === 'edit' ? 'Edit' : toolName === 'write' ? 'Write' : (toolName || '')
229
- const diffs = extractDiffs(block)
230
- const output = done ? (resultText(block) || null) : null
231
- return { title, summary, filePath, state, diffs, output }
232
- }
233
-
234
- // ==================== 组件 ====================
235
-
236
- function DiffCard(props) {
237
- const block = props.block, cwd = props.cwd, openFile = props.openFile, inspect = props.inspect, toolName = props.toolName
238
- // open:点行头展开整个卡片;revealed:展开后点「展开其余」显示全部行
239
- const [open, setOpen] = React.useState(false)
240
- const [revealed, setRevealed] = React.useState(false)
241
- const [copied, setCopied] = React.useState(false)
242
- const m = buildCardModel(block, toolName, cwd)
243
- const fileLines = m.diffs === null ? null : m.diffs.map(d => ({ path: d.path, lines: buildDiffLines(contentLines(d.oldText ?? ''), contentLines(d.newText)) }))
244
- const hasAny = fileLines !== null && fileLines.some(f => f.lines.length > 0)
245
- const displayLines = hasAny ? fileLines : null
246
- const addCount = displayLines ? displayLines.reduce((s, f) => s + f.lines.filter(l => l.kind === 'add').length, 0) : 0
247
- const delCount = displayLines ? displayLines.reduce((s, f) => s + f.lines.filter(l => l.kind === 'del').length, 0) : 0
248
- const files = m.diffs ? m.diffs.length : 0
249
- const hasContent = displayLines !== null || m.output !== null
250
- const expandable = hasContent
251
- const status = m.state === 'running' ? '运行中' : m.state === 'error' ? '失败' : m.state === 'stopped' ? '已中断' : null
252
- const failureSummary = m.state === 'error' && m.output !== null ? firstLine(m.output) : null
253
- const summaryText = failureSummary !== null ? failureSummary : (m.summary || m.title)
254
- const fileLink = m.filePath !== undefined && openFile !== undefined && failureSummary === null
255
- const MAX = 14
256
- let flatLines = null
257
- let hidden = 0
258
- if (displayLines && open) {
259
- flatLines = []
260
- for (const f of displayLines) {
261
- flatLines.push({ kind: 'path', text: f.path, hl: [] })
262
- flatLines.push(...f.lines)
263
- }
264
- hidden = flatLines.length - MAX
265
- if (hidden < 0) hidden = 0
266
- if (hidden > 0 && !revealed) {
267
- const headN = Math.ceil(MAX / 2)
268
- flatLines = flatLines.slice(0, headN)
269
- .concat({ kind: 'mid', text: '⋯ 展开其余 ' + hidden + ' 行差异', hl: [] })
270
- .concat(flatLines.slice(flatLines.length - (MAX - headN)))
271
- }
272
- }
273
- const onToggle = () => { setOpen(v => !v); setRevealed(false) }
274
- const onOpenFile = (e) => { e.stopPropagation(); if (m.filePath !== undefined) openFile(m.filePath) }
275
- const onCopy = () => {
276
- if (copied || flatLines === null || flatLines.length === 0) return
277
- const txt = flatLines.map(l => l.kind === 'del' ? '- ' + l.text : l.kind === 'add' ? '+ ' + l.text : l.text).join('\n')
278
- copyTextIntoClipboard(txt)
279
- setCopied(true)
280
- timerRef.timeout(() => setCopied(false), 1200)
281
- }
282
- const rowType = m.title === 'Write' ? 'write' : m.title === 'Edit' ? 'edit' : 'file'
283
- return React.createElement('div', { className: 'edd-root', 'data-variant': rowType, 'data-state': m.state },
284
- status !== null && React.createElement('span', { className: 'edd-vh' }, status),
285
- React.createElement('div', { className: 'edd-row', onClick: onToggle, role: 'button', tabIndex: expandable ? 0 : -1, 'aria-expanded': open },
286
- React.createElement('span', { className: 'edd-icon' }, '✎'),
287
- React.createElement('span', { className: 'edd-title' }, m.title),
288
- summaryText !== '' && React.createElement(React.Fragment, null,
289
- React.createElement('span', { className: 'edd-sep', 'aria-hidden': true }),
290
- fileLink
291
- ? React.createElement('button', { type: 'button', className: 'edd-filelink', onClick: onOpenFile }, summaryText)
292
- : React.createElement('span', { className: 'edd-summary' + (failureSummary !== null ? ' edd-err' : '') }, summaryText)
293
- ),
294
- expandable && React.createElement('span', { className: 'edd-chev' + (open ? ' edd-chev-open' : '') }, '›')
295
- ),
296
- React.createElement('div', { className: 'edd-bodyWrap' },
297
- flatLines && React.createElement('div', { className: 'edd-body' },
298
- React.createElement('button', { type: 'button', className: 'edd-copy', onClick: onCopy }, copied ? '复制成功' : '复制'),
299
- flatLines.map((l, idx) => {
300
- if (l.kind === 'mid') return React.createElement('button', { key: idx, type: 'button', className: 'edd-expand', onClick: () => setRevealed(true) }, l.text)
301
- const prefix = l.kind === 'del' ? '-' : l.kind === 'add' ? '+' : ''
302
- const kids = []
303
- if (prefix) kids.push(React.createElement('span', { key: 'p', className: 'edd-marker' }, prefix))
304
- if (l.kind === 'del' || l.kind === 'add') {
305
- if (l.text.length === 0) {
306
- kids.push(React.createElement('span', { key: 'e', className: 'edd-empty' }, '␣'))
307
- } else if (l.hl.length > 0) {
308
- let last = 0
309
- for (const r of l.hl) {
310
- if (r[0] > last) kids.push(React.createElement('span', { key: 't' + last, className: 'edd-plain' }, l.text.slice(last, r[0])))
311
- kids.push(React.createElement('span', { key: 'h' + r[0], className: 'edd-hl' }, l.text.slice(r[0], r[1])))
312
- last = r[1]
313
- }
314
- if (last < l.text.length) kids.push(React.createElement('span', { key: 't' + last, className: 'edd-plain' }, l.text.slice(last)))
315
- } else {
316
- kids.push(React.createElement('span', { key: 't', className: 'edd-plain' }, l.text))
317
- }
318
- } else {
319
- kids.push(React.createElement('span', { key: 't', className: 'edd-plain' }, l.text))
320
- }
321
- return React.createElement('div', { key: idx, className: 'edd-line ' + (l.kind === 'del' ? 'edd-del' : l.kind === 'add' ? 'edd-add' : l.kind === 'path' ? 'edd-path' : 'edd-plain-line') }, kids)
322
- })
323
- ),
324
- open && m.output !== null && flatLines === null && React.createElement('div', { className: 'edd-io' },
325
- React.createElement('span', { className: 'edd-iolabel' }, 'OUT'),
326
- React.createElement('span', { className: 'edd-iotext' }, m.output)
327
- ),
328
- open && ((flatLines && flatLines.length > 0) || m.output !== null) && React.createElement('div', { className: 'edd-foot' }, '└ +' + addCount + ' -' + delCount + ' · ' + files + ' file' + (files === 1 ? '' : 's')),
329
- open && React.createElement('div', { className: 'edd-actions' },
330
- inspect !== undefined && ((flatLines && flatLines.length > 0) || m.output !== null) && React.createElement('button', { type: 'button', className: 'edd-inspect', onClick: inspect }, 'Inspect')
331
- )
332
- )
333
- )
334
- }
335
-
336
- // ==================== 剪贴板与样式 ====================
337
-
338
- let timerRef = { timeout: null }
339
-
340
- function copyTextIntoClipboard(txt) {
341
- if (typeof navigator !== 'undefined' && navigator.clipboard && navigator.clipboard.writeText) {
342
- navigator.clipboard.writeText(txt).catch(() => {})
343
- return
344
- }
345
- if (!DOC) return
346
- const ta = DOC.createElement('textarea')
347
- ta.value = txt
348
- ta.style.position = 'fixed'
349
- ta.style.opacity = '0'
350
- DOC.body.appendChild(ta)
351
- ta.select()
352
- try { DOC.execCommand('copy') } catch {}
353
- DOC.body.removeChild(ta)
354
- }
355
-
356
- // 视觉对齐内置 DiffBlock / ToolRow:复用同一批主题 token,字号/圆角/背景保持一致。
357
- const CSS = [
358
- '.edd-root{box-sizing:border-box;color:var(--dsw-alias-label-primary);}',
359
- '.edd-vh{position:absolute;width:1px;height:1px;clip:rect(0 0 0 0);overflow:hidden;white-space:nowrap;}',
360
- '.edd-row{display:flex;align-items:center;gap:6px;cursor:pointer;min-height:24px;padding:4px 0;font-size:14px;line-height:24px;}',
361
- '.edd-icon{color:var(--dsw-alias-label-secondary);flex:none;font-style:normal;}',
362
- '.edd-title{font-weight:400;flex:none;color:var(--dsw-alias-label-primary);}',
363
- '.edd-sep{flex:none;width:2px;height:2px;border-radius:1px;margin:0 8px;background:var(--dsw-alias-label-caption);}',
364
- '.edd-summary{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px;line-height:24px;color:var(--dsw-alias-label-tertiary);text-align:left;}',
365
- '.edd-err{color:var(--dsw-alias-state-error-primary);}',
366
- '.edd-filelink{flex:1 1 auto;min-width:0;margin:0;padding:0;border:none;background:none;font-family:inherit;font-size:14px;line-height:24px;color:var(--dsw-alias-label-secondary);text-decoration:underline;text-decoration-color:var(--dsw-alias-label-quaternary);text-underline-offset:3px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:left;cursor:pointer;}',
367
- '.edd-filelink:hover{color:var(--dsw-alias-label-primary);text-decoration-color:currentColor;}',
368
- '.edd-chev{margin-left:auto;color:var(--dsw-alias-label-secondary);flex:none;transition:transform .12s;display:inline-block;}',
369
- '.edd-chev-open{transform:rotate(90deg);}',
370
- '.edd-bodyWrap{overflow:hidden;}',
371
- '.edd-body{position:relative;margin:8px 0;background:var(--dsw-alias-markdown-code-block);border-radius:12px;font:var(--dsw-font-markdown-code-block);overflow-x:auto;overflow-y:hidden;padding:12px 14px 12px 14px;box-sizing:border-box;}',
372
- '.edd-copy{position:absolute;top:8px;right:12px;z-index:1;background-color:transparent;border:none;padding:0;margin:0;color:var(--dsw-alias-label-secondary);cursor:pointer;font:var(--dsw-font-xs-13);}',
373
- '.edd-copy:hover{color:var(--dsw-alias-label-primary);}',
374
- '.edd-path{color:var(--dsw-alias-label-primary);font-weight:600;padding-right:56px;}',
375
- '.edd-line{min-height:22px;white-space:pre;}',
376
- '.edd-del{color:var(--dsw-alias-state-error-primary);}',
377
- '.edd-add{color:var(--dsw-alias-state-success-primary);}',
378
- '.edd-marker{color:inherit;opacity:1;user-select:none;}',
379
- '.edd-plain{white-space:pre;}',
380
- '.edd-empty{opacity:.5;font-style:italic;}',
381
- '.edd-hl{text-decoration:underline;text-decoration-thickness:2px;text-decoration-color:currentColor;font-weight:600;}',
382
- '.edd-expand{display:inline-block;margin:2px 0;padding:1px 0;border:none;background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer;font:var(--dsw-font-markdown-code-block);text-align:left;}',
383
- '.edd-expand:hover{color:var(--dsw-alias-label-secondary);}',
384
- '.edd-foot{padding:0 14px 12px;font:var(--dsw-font-markdown-code-block);color:var(--dsw-alias-label-tertiary);}',
385
- '.edd-io{padding:8px 14px;}',
386
- '.edd-iolabel{margin-right:8px;color:var(--dsw-alias-label-caption);font-weight:600;}',
387
- '.edd-iotext{color:var(--dsw-alias-label-secondary);white-space:pre-wrap;word-break:break-word;}',
388
- '.edd-actions{padding:4px 0 2px 4px;}',
389
- '.edd-inspect{display:inline-flex;align-items:center;gap:4px;margin:0;padding:2px 8px;border:1px solid var(--dsw-alias-border-l2);border-radius:999px;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-secondary);font-size:11px;line-height:16px;cursor:pointer;opacity:0;transition:opacity .12s ease;}',
390
- '.edd-root:hover .edd-inspect,.edd-inspect:focus-visible{opacity:1;}',
391
- '.edd-inspect:hover{background:var(--dsw-alias-interactive-bg-hover-solid);color:var(--dsw-alias-label-primary);}',
392
- ].join('')
393
-
394
- function ensureStyle() {
395
- if (!DOC || styleTag) return
396
- const tag = DOC.createElement('style')
397
- tag.dataset.plugin = 'dsh-edit-diff'
398
- tag.textContent = CSS
399
- DOC.head.appendChild(tag)
400
- styleTag = tag
401
- }
402
- let styleTag = null
403
-
404
- // ==================== 插件 ====================
405
-
406
- const plugin = {
407
- name: 'dsh-edit-diff',
408
- inject: ['slots', 'timer'],
409
- apply(ctx) {
410
- const slots = ctx.get && ctx.get('slots')
411
- if (!slots) return
412
- const timer = ctx.get && ctx.get('timer')
413
- if (timer && timer.timeout) timerRef.timeout = (fn, ms) => timer.timeout(fn, ms)
414
-
415
- ctx.effect(function () {
416
- ensureStyle()
417
- return function () {
418
- if (styleTag && styleTag.parentNode) styleTag.parentNode.removeChild(styleTag)
419
- styleTag = null
420
- }
421
- })
422
-
423
- slots.inject('tool.call.toolview', () => {
424
- // priority 要低于默认 0,遮蔽 file-mutation-toolview 的 edit/write,最低者渲染;
425
- // 若也传 0 会在同一 key 上 clash,而非替换。
426
- slots.register({ name: 'tool.call.toolview', key: 'edit', priority: -1 }, DiffCard)
427
- slots.register({ name: 'tool.call.toolview', key: 'write', priority: -1 }, DiffCard)
428
- })
429
- },
430
- }
431
-
432
- exports.default = plugin
433
- exports.name = plugin.name
434
- exports.inject = plugin.inject
435
- exports.apply = plugin.apply
2
+ id: "dsh-edit-diff",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperties(exports, {
7
+ __esModule: { value: true },
8
+ [Symbol.toStringTag]: { value: "Module" }
9
+ });
10
+ //#region \0rolldown/runtime.js
11
+ var __create = Object.create;
12
+ var __defProp = Object.defineProperty;
13
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
14
+ var __getOwnPropNames = Object.getOwnPropertyNames;
15
+ var __getProtoOf = Object.getPrototypeOf;
16
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
19
+ key = keys[i];
20
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
21
+ get: ((k) => from[k]).bind(null, key),
22
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
23
+ });
24
+ }
25
+ return to;
26
+ };
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: true
30
+ }) : target, mod));
31
+ //#endregion
32
+ let react = require("react");
33
+ react = __toESM(react, 1);
34
+ //#region src/client.ts
35
+ /** 文档对象,非浏览器环境下为 null。 */
36
+ const DOC = typeof document !== "undefined" ? document : null;
37
+ /** 行级 Myers:前缀/后缀收缩后仅对中间核心区跑 diff,返回 op 数组。 */
38
+ function myersDiff(aList, bList) {
39
+ const N = aList.length;
40
+ const M = bList.length;
41
+ const max = N + M;
42
+ let prev = { 1: 0 };
43
+ const trace = [];
44
+ let dMax = 0;
45
+ let found = false;
46
+ for (let d = 0; d <= max; d++) {
47
+ trace.push({ ...prev });
48
+ const cur = {};
49
+ for (let k = -d; k <= d; k += 2) {
50
+ let x;
51
+ if (k === -d || k !== d && (prev[k - 1] ?? -Infinity) < (prev[k + 1] ?? -Infinity)) x = prev[k + 1] ?? 0;
52
+ else x = (prev[k - 1] ?? -1) + 1;
53
+ let y = x - k;
54
+ while (x < N && y < M && aList[x] === bList[y]) {
55
+ x++;
56
+ y++;
57
+ }
58
+ cur[k] = x;
59
+ if (x >= N && y >= M) {
60
+ dMax = d;
61
+ found = true;
62
+ break;
63
+ }
64
+ }
65
+ prev = cur;
66
+ if (found) break;
67
+ }
68
+ if (!found) {
69
+ const ops = [];
70
+ for (let i = 0; i < N; i++) ops.push({
71
+ type: "del",
72
+ a: i,
73
+ b: -1
74
+ });
75
+ for (let j = 0; j < M; j++) ops.push({
76
+ type: "add",
77
+ a: -1,
78
+ b: j
79
+ });
80
+ return ops;
81
+ }
82
+ const ops = [];
83
+ let x = N;
84
+ let y = M;
85
+ for (let d = dMax; d > 0; d--) {
86
+ const t = trace[d] ?? {};
87
+ const k = x - y;
88
+ let prevK;
89
+ if (k === -d || k !== d && (t[k - 1] ?? -Infinity) < (t[k + 1] ?? -Infinity)) prevK = k + 1;
90
+ else prevK = k - 1;
91
+ const prevX = t[prevK] ?? 0;
92
+ const prevY = prevX - prevK;
93
+ while (x > prevX && y > prevY) {
94
+ ops.push({
95
+ type: "same",
96
+ a: x - 1,
97
+ b: y - 1
98
+ });
99
+ x--;
100
+ y--;
101
+ }
102
+ if (x === prevX) {
103
+ ops.push({
104
+ type: "add",
105
+ a: -1,
106
+ b: y - 1
107
+ });
108
+ y--;
109
+ } else {
110
+ ops.push({
111
+ type: "del",
112
+ a: x - 1,
113
+ b: -1
114
+ });
115
+ x--;
116
+ }
117
+ }
118
+ while (x > 0 && y > 0) {
119
+ ops.push({
120
+ type: "same",
121
+ a: x - 1,
122
+ b: y - 1
123
+ });
124
+ x--;
125
+ y--;
126
+ }
127
+ ops.reverse();
128
+ return ops;
129
+ }
130
+ /** 行级 diff:线性前缀/后缀收缩,仅对中间核心区跑 Myers。 */
131
+ function lineDiff(aLines, bLines) {
132
+ let p = 0;
133
+ const minLen = Math.min(aLines.length, bLines.length);
134
+ while (p < minLen && aLines[p] === bLines[p]) p++;
135
+ let s = 0;
136
+ const al = aLines.length;
137
+ const bl = bLines.length;
138
+ while (s < minLen - p && aLines[al - 1 - s] === bLines[bl - 1 - s]) s++;
139
+ const ops = [];
140
+ for (let i = 0; i < p; i++) ops.push({
141
+ type: "same",
142
+ a: i,
143
+ b: i
144
+ });
145
+ const aMid = aLines.slice(p, al - s);
146
+ const bMid = bLines.slice(p, bl - s);
147
+ for (const op of myersDiff(aMid, bMid)) ops.push({
148
+ type: op.type,
149
+ a: op.a === -1 ? -1 : op.a + p,
150
+ b: op.b === -1 ? -1 : op.b + p
151
+ });
152
+ for (let i = 0; i < s; i++) ops.push({
153
+ type: "same",
154
+ a: al - s + i,
155
+ b: bl - s + i
156
+ });
157
+ return ops;
158
+ }
159
+ /** 把字符级 op 汇总成高亮区间 [start, end)。 */
160
+ function charRanges(ops) {
161
+ const delIdx = [];
162
+ const addIdx = [];
163
+ for (const op of ops) if (op.type === "del") delIdx.push(op.a);
164
+ else if (op.type === "add") addIdx.push(op.b);
165
+ const mk = (idx) => {
166
+ if (idx.length === 0) return [];
167
+ idx.sort((a, b) => a - b);
168
+ const out = [];
169
+ let start = idx[0];
170
+ let end = start;
171
+ for (let i = 1; i < idx.length; i++) {
172
+ const value = idx[i];
173
+ if (value === end + 1) end = value;
174
+ else {
175
+ out.push([start, end + 1]);
176
+ start = value;
177
+ end = value;
178
+ }
179
+ }
180
+ out.push([start, end + 1]);
181
+ return out;
182
+ };
183
+ return {
184
+ del: mk(delIdx),
185
+ add: mk(addIdx)
186
+ };
187
+ }
188
+ function lineHighlight(oldStr, newStr) {
189
+ return charRanges(myersDiff([...oldStr], [...newStr]));
190
+ }
191
+ function contentLines(text) {
192
+ if (text === "") return [];
193
+ return (text.endsWith("\n") ? text.slice(0, -1) : text).split("\n");
194
+ }
195
+ /** 从 ops 构建渲染行,仅含真实差异;替换对删/增行数相等做行内字符高亮。 */
196
+ function buildDiffLines(oldLines, newLines) {
197
+ const ops = lineDiff(oldLines, newLines);
198
+ const out = [];
199
+ let i = 0;
200
+ while (i < ops.length) {
201
+ if (ops[i]?.type === "same") {
202
+ i++;
203
+ continue;
204
+ }
205
+ const dStart = i;
206
+ while (i < ops.length && ops[i]?.type === "del") i++;
207
+ const addStart = i;
208
+ while (i < ops.length && ops[i]?.type === "add") i++;
209
+ const delOps = ops.slice(dStart, addStart);
210
+ const addOps = ops.slice(addStart, i);
211
+ if (delOps.length === addOps.length && delOps.length > 0) for (let k = 0; k < delOps.length; k++) {
212
+ const del = delOps[k];
213
+ const add = addOps[k];
214
+ if (del === void 0 || add === void 0) continue;
215
+ const oldText = oldLines[del.a] ?? "";
216
+ const newText = newLines[add.b] ?? "";
217
+ const hl = lineHighlight(oldText, newText);
218
+ out.push({
219
+ kind: "del",
220
+ text: oldText,
221
+ hl: hl.del
222
+ });
223
+ out.push({
224
+ kind: "add",
225
+ text: newText,
226
+ hl: hl.add
227
+ });
228
+ }
229
+ else {
230
+ for (const op of delOps) out.push({
231
+ kind: "del",
232
+ text: oldLines[op.a] ?? "",
233
+ hl: []
234
+ });
235
+ for (const op of addOps) out.push({
236
+ kind: "add",
237
+ text: newLines[op.b] ?? "",
238
+ hl: []
239
+ });
240
+ }
241
+ }
242
+ return out;
243
+ }
244
+ /** 收窄外部 diff 数据,字段不合法时返回 null。 */
245
+ function narrowDiffs(diffs) {
246
+ if (!Array.isArray(diffs) || diffs.length === 0) return null;
247
+ const out = [];
248
+ for (const item of diffs) {
249
+ if (item === null || typeof item !== "object") return null;
250
+ const record = item;
251
+ if (typeof record.path !== "string") return null;
252
+ if (record.oldText !== null && typeof record.oldText !== "string") return null;
253
+ if (typeof record.newText !== "string") return null;
254
+ out.push({
255
+ path: record.path,
256
+ oldText: record.oldText,
257
+ newText: record.newText
258
+ });
259
+ }
260
+ return out;
261
+ }
262
+ /** 从卡片数据块中取出 diff,取不到时回退到参数意图。 */
263
+ function extractDiffs(block) {
264
+ const done = "kind" in block;
265
+ const subCall = block.parentCallId !== void 0 || typeof block.callId === "string" && block.callId.includes(":code:");
266
+ if (done && !subCall && block.isError !== true) {
267
+ const meta = block.meta;
268
+ if (meta !== null && typeof meta === "object" && !Array.isArray(meta)) {
269
+ const diffs = meta.diffs;
270
+ if (Array.isArray(diffs) && diffs.length > 0) {
271
+ const narrowed = narrowDiffs(diffs);
272
+ if (narrowed !== null) return narrowed;
273
+ }
274
+ }
275
+ }
276
+ if (done && !subCall && block.isError === true) return null;
277
+ const rawArgs = (block.call !== void 0 ? block.call.argsRaw : block.argsRaw) ?? "";
278
+ const argsRaw = typeof rawArgs === "string" ? rawArgs : "";
279
+ const name = block.call !== void 0 ? block.call.name : block.name;
280
+ if (name === "edit" || name === "write") try {
281
+ const args = JSON.parse(argsRaw);
282
+ if (args !== null && typeof args === "object") {
283
+ const record = args;
284
+ const filePath = record.file_path;
285
+ if (typeof filePath === "string" && filePath !== "") {
286
+ if (name === "write" && typeof record.content === "string") return narrowDiffs([{
287
+ path: filePath,
288
+ oldText: null,
289
+ newText: record.content
290
+ }]);
291
+ if (name === "edit" && typeof record.old_string === "string" && typeof record.new_string === "string") return narrowDiffs([{
292
+ path: filePath,
293
+ oldText: record.old_string || null,
294
+ newText: record.new_string
295
+ }]);
296
+ }
297
+ }
298
+ } catch {}
299
+ if (!done) {
300
+ const callView = block.callView;
301
+ if (callView === null || typeof callView !== "object" || callView.card !== "diff") return null;
302
+ return narrowDiffs(callView.diffs);
303
+ }
304
+ const resultView = block.resultView;
305
+ if (resultView === null || typeof resultView !== "object" || resultView.card !== "diff") return null;
306
+ return narrowDiffs(resultView.diffs);
307
+ }
308
+ /** 汇总工具结果文本。 */
309
+ function resultText(block) {
310
+ if (!("kind" in block)) return "";
311
+ const parts = [];
312
+ const content = Array.isArray(block.content) ? block.content : [];
313
+ for (const item of content) {
314
+ const record = item !== null && typeof item === "object" ? item : null;
315
+ const isText = record !== null && record.type === "text" && typeof record.text === "string";
316
+ parts.push(isText ? record.text : JSON.stringify(item));
317
+ }
318
+ if (parts.length === 0 && block.error !== void 0) parts.push(String(block.error.name) + ": " + String(block.error.code));
319
+ return parts.join("\n");
320
+ }
321
+ function firstLine(t) {
322
+ const n = t.indexOf("\n");
323
+ return n === -1 ? t : t.slice(0, n);
324
+ }
325
+ /** 由数据块推导卡片模型。 */
326
+ function buildCardModel(block, toolName, cwd) {
327
+ const done = "kind" in block;
328
+ const rawArgs = done ? block.call?.argsRaw ?? "" : block.argsRaw ?? "";
329
+ const argsRaw = typeof rawArgs === "string" ? rawArgs : "";
330
+ const state = !done ? "running" : block.error?.code === "interrupted" ? "stopped" : block.isError === true ? "error" : "ok";
331
+ let filePath;
332
+ let summary = "";
333
+ try {
334
+ const parsed = JSON.parse(argsRaw);
335
+ if (parsed !== null && typeof parsed === "object") {
336
+ const record = parsed;
337
+ const p = record.file_path ?? record.path;
338
+ if (typeof p === "string" && p !== "") filePath = firstLine(p);
339
+ const values = Object.values(record).filter((v) => typeof v === "string" && v !== "");
340
+ summary = values.length > 0 ? firstLine(values[0]) : argsRaw;
341
+ } else summary = firstLine(argsRaw);
342
+ } catch {
343
+ summary = firstLine(argsRaw);
344
+ }
345
+ if (filePath !== void 0) summary = filePath;
346
+ if (filePath !== void 0 && cwd !== void 0) {
347
+ const root = cwd.replace(/[/\\]+$/, "");
348
+ if (filePath.startsWith(root + "/") || filePath.startsWith(root + "\\")) summary = filePath.slice(root.length + 1);
349
+ }
350
+ const title = toolName === "edit" ? "Edit" : toolName === "write" ? "Write" : toolName ?? "";
351
+ const diffs = extractDiffs(block);
352
+ const output = done ? resultText(block) || null : null;
353
+ return {
354
+ title,
355
+ summary,
356
+ filePath,
357
+ state,
358
+ diffs,
359
+ output
360
+ };
361
+ }
362
+ function DiffCard(props) {
363
+ const { block, cwd, openFile, inspect, toolName } = props;
364
+ const [open, setOpen] = react.useState(false);
365
+ const [revealed, setRevealed] = react.useState(false);
366
+ const [copied, setCopied] = react.useState(false);
367
+ const m = buildCardModel(block, toolName, cwd);
368
+ const fileLines = m.diffs === null ? null : m.diffs.map((d) => ({
369
+ path: d.path,
370
+ lines: buildDiffLines(contentLines(d.oldText ?? ""), contentLines(d.newText))
371
+ }));
372
+ const displayLines = fileLines !== null && fileLines.some((f) => f.lines.length > 0) ? fileLines : null;
373
+ const addCount = displayLines === null ? 0 : displayLines.reduce((sum, f) => sum + f.lines.filter((l) => l.kind === "add").length, 0);
374
+ const delCount = displayLines === null ? 0 : displayLines.reduce((sum, f) => sum + f.lines.filter((l) => l.kind === "del").length, 0);
375
+ const files = m.diffs === null ? 0 : m.diffs.length;
376
+ const expandable = displayLines !== null || m.output !== null;
377
+ const status = m.state === "running" ? "运行中" : m.state === "error" ? "失败" : m.state === "stopped" ? "已中断" : null;
378
+ const failureSummary = m.state === "error" && m.output !== null ? firstLine(m.output) : null;
379
+ const summaryText = failureSummary !== null ? failureSummary : m.summary || m.title;
380
+ const fileLink = m.filePath !== void 0 && openFile !== void 0 && failureSummary === null;
381
+ const MAX = 14;
382
+ let flatLines = null;
383
+ let hidden = 0;
384
+ if (displayLines !== null && open) {
385
+ const rows = [];
386
+ for (const f of displayLines) {
387
+ rows.push({
388
+ kind: "path",
389
+ text: f.path,
390
+ hl: []
391
+ });
392
+ rows.push(...f.lines);
393
+ }
394
+ hidden = rows.length - MAX;
395
+ if (hidden < 0) hidden = 0;
396
+ if (hidden > 0 && !revealed) {
397
+ const headN = Math.ceil(MAX / 2);
398
+ flatLines = [
399
+ ...rows.slice(0, headN),
400
+ {
401
+ kind: "mid",
402
+ text: "⋯ 展开其余 " + hidden + " 行差异",
403
+ hl: []
404
+ },
405
+ ...rows.slice(rows.length - 7)
406
+ ];
407
+ } else flatLines = rows;
408
+ }
409
+ const onToggle = () => {
410
+ setOpen((v) => !v);
411
+ setRevealed(false);
412
+ };
413
+ const onOpenFile = (event) => {
414
+ event.stopPropagation();
415
+ if (m.filePath !== void 0 && openFile !== void 0) openFile(m.filePath);
416
+ };
417
+ const onCopy = () => {
418
+ if (copied || flatLines === null || flatLines.length === 0) return;
419
+ copyTextIntoClipboard(flatLines.map((l) => l.kind === "del" ? "- " + l.text : l.kind === "add" ? "+ " + l.text : l.text).join("\n"));
420
+ setCopied(true);
421
+ const timeout = timerRef.timeout;
422
+ if (timeout !== null) timeout(() => setCopied(false), 1200);
423
+ };
424
+ const rowType = m.title === "Write" ? "write" : m.title === "Edit" ? "edit" : "file";
425
+ return react.createElement("div", {
426
+ className: "edd-root",
427
+ "data-variant": rowType,
428
+ "data-state": m.state
429
+ }, status !== null && react.createElement("span", { className: "edd-vh" }, status), react.createElement("div", {
430
+ className: "edd-row",
431
+ onClick: onToggle,
432
+ role: "button",
433
+ tabIndex: expandable ? 0 : -1,
434
+ "aria-expanded": open
435
+ }, react.createElement("span", { className: "edd-icon" }, "✎"), react.createElement("span", { className: "edd-title" }, m.title), summaryText !== "" && react.createElement(react.Fragment, null, react.createElement("span", {
436
+ className: "edd-sep",
437
+ "aria-hidden": true
438
+ }), fileLink ? react.createElement("button", {
439
+ type: "button",
440
+ className: "edd-filelink",
441
+ onClick: onOpenFile
442
+ }, summaryText) : react.createElement("span", { className: "edd-summary" + (failureSummary !== null ? " edd-err" : "") }, summaryText)), expandable && react.createElement("span", { className: "edd-chev" + (open ? " edd-chev-open" : "") }, "›")), react.createElement("div", { className: "edd-bodyWrap" }, flatLines === null ? null : react.createElement("div", { className: "edd-body" }, react.createElement("button", {
443
+ type: "button",
444
+ className: "edd-copy",
445
+ onClick: onCopy
446
+ }, copied ? "复制成功" : "复制"), flatLines.map((line, idx) => {
447
+ if (line.kind === "mid") return react.createElement("button", {
448
+ key: idx,
449
+ type: "button",
450
+ className: "edd-expand",
451
+ onClick: () => setRevealed(true)
452
+ }, line.text);
453
+ const prefix = line.kind === "del" ? "-" : line.kind === "add" ? "+" : "";
454
+ const kids = [];
455
+ if (prefix !== "") kids.push(react.createElement("span", {
456
+ key: "p",
457
+ className: "edd-marker"
458
+ }, prefix));
459
+ if (line.kind === "del" || line.kind === "add") {
460
+ if (line.text.length === 0) kids.push(react.createElement("span", {
461
+ key: "e",
462
+ className: "edd-empty"
463
+ }, "␣"));
464
+ else if (line.hl.length > 0) {
465
+ let last = 0;
466
+ for (const range of line.hl) {
467
+ if (range[0] > last) kids.push(react.createElement("span", {
468
+ key: "t" + last,
469
+ className: "edd-plain"
470
+ }, line.text.slice(last, range[0])));
471
+ kids.push(react.createElement("span", {
472
+ key: "h" + range[0],
473
+ className: "edd-hl"
474
+ }, line.text.slice(range[0], range[1])));
475
+ last = range[1];
476
+ }
477
+ if (last < line.text.length) kids.push(react.createElement("span", {
478
+ key: "t" + last,
479
+ className: "edd-plain"
480
+ }, line.text.slice(last)));
481
+ } else kids.push(react.createElement("span", {
482
+ key: "t",
483
+ className: "edd-plain"
484
+ }, line.text));
485
+ } else kids.push(react.createElement("span", {
486
+ key: "t",
487
+ className: "edd-plain"
488
+ }, line.text));
489
+ return react.createElement("div", {
490
+ key: idx,
491
+ className: "edd-line " + (line.kind === "del" ? "edd-del" : line.kind === "add" ? "edd-add" : line.kind === "path" ? "edd-path" : "edd-plain-line")
492
+ }, kids);
493
+ })), open && m.output !== null && flatLines === null && react.createElement("div", { className: "edd-io" }, react.createElement("span", { className: "edd-iolabel" }, "OUT"), react.createElement("span", { className: "edd-iotext" }, m.output)), open && (flatLines !== null && flatLines.length > 0 || m.output !== null) && react.createElement("div", { className: "edd-foot" }, "└ +" + addCount + " -" + delCount + " · " + files + " file" + (files === 1 ? "" : "s")), open && react.createElement("div", { className: "edd-actions" }, inspect !== void 0 && (flatLines !== null && flatLines.length > 0 || m.output !== null) && react.createElement("button", {
494
+ type: "button",
495
+ className: "edd-inspect",
496
+ onClick: inspect
497
+ }, "Inspect"))));
498
+ }
499
+ /** 宿主 timer 服务的时间回调,未注入时为 null。 */
500
+ const timerRef = { timeout: null };
501
+ function copyTextIntoClipboard(txt) {
502
+ if (typeof navigator !== "undefined" && navigator.clipboard !== void 0 && navigator.clipboard.writeText !== void 0) {
503
+ navigator.clipboard.writeText(txt).catch(() => {});
504
+ return;
505
+ }
506
+ if (DOC === null) return;
507
+ const ta = DOC.createElement("textarea");
508
+ ta.value = txt;
509
+ ta.style.position = "fixed";
510
+ ta.style.opacity = "0";
511
+ DOC.body.appendChild(ta);
512
+ ta.select();
513
+ try {
514
+ DOC.execCommand("copy");
515
+ } catch {}
516
+ DOC.body.removeChild(ta);
517
+ }
518
+ const CSS = [
519
+ ".edd-root{box-sizing:border-box;color:var(--dsw-alias-label-primary);}",
520
+ ".edd-vh{position:absolute;width:1px;height:1px;clip:rect(0 0 0 0);overflow:hidden;white-space:nowrap;}",
521
+ ".edd-row{display:flex;align-items:center;gap:6px;cursor:pointer;min-height:24px;padding:4px 0;font-size:14px;line-height:24px;}",
522
+ ".edd-icon{color:var(--dsw-alias-label-secondary);flex:none;font-style:normal;}",
523
+ ".edd-title{font-weight:400;flex:none;color:var(--dsw-alias-label-primary);}",
524
+ ".edd-sep{flex:none;width:2px;height:2px;border-radius:1px;margin:0 8px;background:var(--dsw-alias-label-caption);}",
525
+ ".edd-summary{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px;line-height:24px;color:var(--dsw-alias-label-tertiary);text-align:left;}",
526
+ ".edd-err{color:var(--dsw-alias-state-error-primary);}",
527
+ ".edd-filelink{flex:1 1 auto;min-width:0;margin:0;padding:0;border:none;background:none;font-family:inherit;font-size:14px;line-height:24px;color:var(--dsw-alias-label-secondary);text-decoration:underline;text-decoration-color:var(--dsw-alias-label-quaternary);text-underline-offset:3px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:left;cursor:pointer;}",
528
+ ".edd-filelink:hover{color:var(--dsw-alias-label-primary);text-decoration-color:currentColor;}",
529
+ ".edd-chev{margin-left:auto;color:var(--dsw-alias-label-secondary);flex:none;transition:transform .12s;display:inline-block;}",
530
+ ".edd-chev-open{transform:rotate(90deg);}",
531
+ ".edd-bodyWrap{overflow:hidden;}",
532
+ ".edd-body{position:relative;margin:8px 0;background:var(--dsw-alias-markdown-code-block);border-radius:12px;font:var(--dsw-font-markdown-code-block);overflow-x:auto;overflow-y:hidden;padding:12px 14px 12px 14px;box-sizing:border-box;}",
533
+ ".edd-copy{position:absolute;top:8px;right:12px;z-index:1;background-color:transparent;border:none;padding:0;margin:0;color:var(--dsw-alias-label-secondary);cursor:pointer;font:var(--dsw-font-xs-13);}",
534
+ ".edd-copy:hover{color:var(--dsw-alias-label-primary);}",
535
+ ".edd-path{color:var(--dsw-alias-label-primary);font-weight:600;padding-right:56px;}",
536
+ ".edd-line{min-height:22px;white-space:pre;}",
537
+ ".edd-del{color:var(--dsw-alias-state-error-primary);}",
538
+ ".edd-add{color:var(--dsw-alias-state-success-primary);}",
539
+ ".edd-marker{color:inherit;opacity:1;user-select:none;}",
540
+ ".edd-plain{white-space:pre;}",
541
+ ".edd-empty{opacity:.5;font-style:italic;}",
542
+ ".edd-hl{text-decoration:underline;text-decoration-thickness:2px;text-decoration-color:currentColor;font-weight:600;}",
543
+ ".edd-expand{display:inline-block;margin:2px 0;padding:1px 0;border:none;background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer;font:var(--dsw-font-markdown-code-block);text-align:left;}",
544
+ ".edd-expand:hover{color:var(--dsw-alias-label-secondary);}",
545
+ ".edd-foot{padding:0 14px 12px;font:var(--dsw-font-markdown-code-block);color:var(--dsw-alias-label-tertiary);}",
546
+ ".edd-io{padding:8px 14px;}",
547
+ ".edd-iolabel{margin-right:8px;color:var(--dsw-alias-label-caption);font-weight:600;}",
548
+ ".edd-iotext{color:var(--dsw-alias-label-secondary);white-space:pre-wrap;word-break:break-word;}",
549
+ ".edd-actions{padding:4px 0 2px 4px;}",
550
+ ".edd-inspect{display:inline-flex;align-items:center;gap:4px;margin:0;padding:2px 8px;border:1px solid var(--dsw-alias-border-l2);border-radius:999px;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-secondary);font-size:11px;line-height:16px;cursor:pointer;opacity:0;transition:opacity .12s ease;}",
551
+ ".edd-root:hover .edd-inspect,.edd-inspect:focus-visible{opacity:1;}",
552
+ ".edd-inspect:hover{background:var(--dsw-alias-interactive-bg-hover-solid);color:var(--dsw-alias-label-primary);}"
553
+ ].join("");
554
+ let styleTag = null;
555
+ function ensureStyle() {
556
+ if (DOC === null || styleTag !== null) return;
557
+ const tag = DOC.createElement("style");
558
+ tag.dataset.plugin = "dsh-edit-diff";
559
+ tag.textContent = CSS;
560
+ DOC.head.appendChild(tag);
561
+ styleTag = tag;
562
+ }
563
+ const plugin = {
564
+ name: "dsh-edit-diff",
565
+ inject: ["slots", "timer"],
566
+ apply(ctx) {
567
+ const slots = ctx.get?.("slots");
568
+ if (slots === void 0) return;
569
+ const timer = ctx.get?.("timer");
570
+ if (timer !== void 0 && typeof timer.timeout === "function") timerRef.timeout = (callback, ms) => {
571
+ timer.timeout(callback, ms);
572
+ };
573
+ ctx.effect(function() {
574
+ ensureStyle();
575
+ return function() {
576
+ if (styleTag !== null && styleTag.parentNode !== null) styleTag.parentNode.removeChild(styleTag);
577
+ styleTag = null;
578
+ };
579
+ });
580
+ slots.inject("tool.call.toolview", () => {
581
+ slots.register({
582
+ name: "tool.call.toolview",
583
+ key: "edit",
584
+ priority: -1
585
+ }, DiffCard);
586
+ slots.register({
587
+ name: "tool.call.toolview",
588
+ key: "write",
589
+ priority: -1
590
+ }, DiffCard);
591
+ });
592
+ }
593
+ };
594
+ const name = plugin.name;
595
+ const inject = plugin.inject;
596
+ //#endregion
597
+ exports.apply = plugin.apply;
598
+ exports.default = plugin;
599
+ exports.inject = inject;
600
+ exports.name = name;
601
+ return module.exports;
602
+ }
603
+ });
436
604
 
437
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
438
- return module.exports
439
- },
440
- })
605
+ //# sourceMappingURL=client.js.map