dsh-vscode-mode 0.27.2 → 0.28.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/README.md +12 -4
- package/lib/index.js +2939 -2725
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/pending/bulkTargets.ts +125 -0
- package/src/pending/capture.ts +144 -18
- package/src/toolTargets.ts +34 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-vscode-mode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "DSH 上的类 VSCode 编码体验:Monaco 编辑器(文件页签/QuickOpen/状态栏,可驻 DSH 0.1.5+ 官方右侧 Sidebar 与对话同屏)+ 命令栏(Ctrl+Shift+P)与可扩展指令系统 + VS Code 兼容代码片段(.code-snippets 全局/项目,IntelliSense 展开)+ Agent 编辑差异审查(整文件差异/采纳/拒绝/归档/回滚)+ SVN 集成(侧栏变更面板/日志弹窗/并排差异)+ 语言服务器(LSP)智能(跳转定义/引用/hover/大纲 + VSIX 扩展市场安装),状态持久化到工作区旁车,界面状态(页签/光标/侧栏/编辑 Tab/导航历史)镜像到 DSH home 跨重启恢复",
|
|
5
5
|
"icon": "assets/icon.svg",
|
|
6
6
|
"keywords": [
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 批量替换目标预读:执行前按字面量求候选文件,供待审采集冻结写前基线。
|
|
3
|
+
* @author ddj 2026年11月09号
|
|
4
|
+
*/
|
|
5
|
+
import type { Ctx, Session } from '../store.js'
|
|
6
|
+
import { searchRipgrepContent } from '../search/content.js'
|
|
7
|
+
import type { ContentSearchInput, ContentSearchResult } from '../search/types.js'
|
|
8
|
+
|
|
9
|
+
/** 单次批量替换最多预读的候选文件数,与待审采集预算一致。 */
|
|
10
|
+
export const BULK_LIMIT = 16
|
|
11
|
+
/** 内容搜索命中上限:只需文件集合,取够即可。 */
|
|
12
|
+
const SEARCH_RESULTS = 200
|
|
13
|
+
|
|
14
|
+
/** 批量替换工具参数里本模块关心的字段。 */
|
|
15
|
+
export interface BulkArgs {
|
|
16
|
+
path?: unknown
|
|
17
|
+
pattern?: unknown
|
|
18
|
+
glob?: unknown
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 一次候选求值所需的宿主信息与工具参数。 */
|
|
22
|
+
export interface BulkScope {
|
|
23
|
+
ctx: Ctx
|
|
24
|
+
session: Session
|
|
25
|
+
cwd: string
|
|
26
|
+
args: BulkArgs
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 预读候选:绝对路径集合与去重后的候选总数。 */
|
|
30
|
+
export interface BulkCandidates {
|
|
31
|
+
paths: string[]
|
|
32
|
+
total: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 内容搜索注入点;测试可替换,生产使用打包 ripgrep。 */
|
|
36
|
+
export type BulkSearcher = (input: ContentSearchInput) => Promise<ContentSearchResult>
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @private
|
|
40
|
+
* @author ddj 2026年11月09号
|
|
41
|
+
* @description: 取字符串参数,非字符串或空串退回缺省值。
|
|
42
|
+
* @param value 原始参数值
|
|
43
|
+
* @param fallback 缺省值
|
|
44
|
+
* @returns 非空字符串
|
|
45
|
+
*/
|
|
46
|
+
function textOf(value: unknown, fallback: string): string {
|
|
47
|
+
return typeof value === 'string' && value.trim() ? value : fallback
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @private
|
|
52
|
+
* @author ddj 2026年11月09号
|
|
53
|
+
* @description: 取 glob 过滤数组;空数组表示不限制,交由 rg 默认忽略规则。
|
|
54
|
+
* @param value 原始参数值
|
|
55
|
+
* @returns 去空后的 glob 列表;无有效项时为 undefined
|
|
56
|
+
*/
|
|
57
|
+
function globsOf(value: unknown): string[] | undefined {
|
|
58
|
+
if (!Array.isArray(value)) return undefined
|
|
59
|
+
const globs = value.map((item) => String(item).trim()).filter(Boolean)
|
|
60
|
+
return globs.length ? globs : undefined
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @private
|
|
65
|
+
* @author ddj 2026年11月09号
|
|
66
|
+
* @description: 解析替换作用域为绝对路径;缺省为工作区根。
|
|
67
|
+
* @param scope 宿主信息与工具参数
|
|
68
|
+
* @returns 作用域绝对路径
|
|
69
|
+
* @throws 文件系统不可用或解析失败
|
|
70
|
+
*/
|
|
71
|
+
async function scopeRoot(scope: BulkScope): Promise<string> {
|
|
72
|
+
const fs = scope.ctx.get('fs') as { resolve?: (path: string, opts: { cwd: string }) => Promise<unknown> } | undefined
|
|
73
|
+
if (!fs || typeof fs.resolve !== 'function') throw new Error('文件系统不可用')
|
|
74
|
+
const requested = textOf(scope.args.path, '.')
|
|
75
|
+
return String(await fs.resolve(requested, { cwd: scope.cwd }))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @private
|
|
80
|
+
* @author ddj 2026年11月09号
|
|
81
|
+
* @description: 搜索命中路径转绝对路径;rg 命中的路径相对搜索根。
|
|
82
|
+
* @param root 搜索根(作用域绝对路径)
|
|
83
|
+
* @param path 命中路径
|
|
84
|
+
* @returns 绝对路径
|
|
85
|
+
*/
|
|
86
|
+
function targetOf(root: string, path: string): string {
|
|
87
|
+
if (!path || path === '.') return root
|
|
88
|
+
if (path.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(path)) return path
|
|
89
|
+
return root.replace(/[\\/]+$/, '') + '/' + path
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @public
|
|
94
|
+
* @author ddj 2026年11月09号
|
|
95
|
+
* @description: 以替换作用域为搜索根按字面量求候选文件;作用域外的同名命中不进入候选。
|
|
96
|
+
* @param scope 宿主信息、工作区与工具参数
|
|
97
|
+
* @param search 可注入的内容搜索实现
|
|
98
|
+
* @returns 候选绝对路径(最多 BULK_LIMIT 个)与去重后的候选总数
|
|
99
|
+
* @throws 参数缺 pattern、文件系统不可用或搜索失败(由调用方转采集 gap)
|
|
100
|
+
*/
|
|
101
|
+
export async function replaceCandidates(scope: BulkScope, search: BulkSearcher = searchRipgrepContent): Promise<BulkCandidates> {
|
|
102
|
+
const query = textOf(scope.args.pattern, '')
|
|
103
|
+
if (!query) return { paths: [], total: 0 }
|
|
104
|
+
|
|
105
|
+
const root = await scopeRoot(scope)
|
|
106
|
+
const result = await search({
|
|
107
|
+
ctx: scope.ctx,
|
|
108
|
+
session: scope.session,
|
|
109
|
+
cwd: scope.cwd,
|
|
110
|
+
root,
|
|
111
|
+
query,
|
|
112
|
+
matchCase: true,
|
|
113
|
+
regex: false,
|
|
114
|
+
maxResults: SEARCH_RESULTS,
|
|
115
|
+
include: globsOf(scope.args.glob),
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
const seen = new Set<string>()
|
|
119
|
+
for (const match of result.matches) {
|
|
120
|
+
seen.add(targetOf(root, match.path))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const paths = [...seen].sort()
|
|
124
|
+
return { paths: paths.slice(0, BULK_LIMIT), total: paths.length }
|
|
125
|
+
}
|
package/src/pending/capture.ts
CHANGED
|
@@ -5,11 +5,18 @@
|
|
|
5
5
|
import { cwdOfSession } from '../store.js'
|
|
6
6
|
import type { Ctx } from '../store.js'
|
|
7
7
|
import { log } from '../log.js'
|
|
8
|
-
import { toolTargets, patchDiagnostics } from '../toolTargets.js'
|
|
8
|
+
import { toolTargets, patchDiagnostics, OPS_PREFIX } from '../toolTargets.js'
|
|
9
|
+
import { replaceCandidates, BULK_LIMIT } from './bulkTargets.js'
|
|
10
|
+
import type { BulkSearcher } from './bulkTargets.js'
|
|
9
11
|
import { rawText, rawReviewFile } from '../reviewEvidence.js'
|
|
10
12
|
|
|
11
|
-
/**
|
|
12
|
-
const WRITE_TOOLS = [
|
|
13
|
+
/** 可被采信为待审来源的写文件工具(含 dsh-ops 的单目标写工具)。 */
|
|
14
|
+
const WRITE_TOOLS = [
|
|
15
|
+
'edit', 'write', 'str_replace_editor', 'apply_patch',
|
|
16
|
+
OPS_PREFIX + 'edit_file', OPS_PREFIX + 'write_file', OPS_PREFIX + 'remove', OPS_PREFIX + 'copy', OPS_PREFIX + 'move',
|
|
17
|
+
]
|
|
18
|
+
/** 批量替换:目标执行前未知,走候选预读 + 回执对齐。 */
|
|
19
|
+
const BULK_TOOL = OPS_PREFIX + 'replace'
|
|
13
20
|
/** 单文件文本上限:超过即标注 oversized,不静默截断。 */
|
|
14
21
|
const MAX_TEXT = 1024 * 1024
|
|
15
22
|
const captureGaps = new Map<string, { cwd: string; sessionId: string; message: string }>()
|
|
@@ -51,13 +58,15 @@ interface CaptureState {
|
|
|
51
58
|
busy: Set<string>
|
|
52
59
|
stopped: boolean
|
|
53
60
|
disposed: Set<string>
|
|
61
|
+
/** 批量替换候选搜索注入点;缺省使用打包 ripgrep。 */
|
|
62
|
+
search?: BulkSearcher
|
|
54
63
|
}
|
|
55
64
|
|
|
56
65
|
/** 工具的写工具参数形状;只取本采集关心的字段。 */
|
|
57
66
|
interface WriteExec {
|
|
58
67
|
id?: string
|
|
59
68
|
name?: string
|
|
60
|
-
arguments?: { file_path?: unknown; path?: unknown; input?: unknown }
|
|
69
|
+
arguments?: { file_path?: unknown; path?: unknown; to?: unknown; input?: unknown; dryRun?: unknown; pattern?: unknown; glob?: unknown }
|
|
61
70
|
agent?: { session?: { id?: string; cwd?: string } }
|
|
62
71
|
}
|
|
63
72
|
|
|
@@ -68,8 +77,10 @@ interface WriteExec {
|
|
|
68
77
|
* @param sink 已确认写入的接收方
|
|
69
78
|
* @returns 可释放的采集器
|
|
70
79
|
*/
|
|
71
|
-
export function installPending(
|
|
72
|
-
|
|
80
|
+
export function installPending(
|
|
81
|
+
ctx: Ctx, sink: (write: PendingWrite) => void, options?: { search?: BulkSearcher },
|
|
82
|
+
): PendingCapture {
|
|
83
|
+
const state: CaptureState = { busy: new Set<string>(), stopped: false, disposed: new Set<string>(), search: options?.search }
|
|
73
84
|
ctx.on('tools/execute', (exec: WriteExec, next: () => Promise<unknown>) => aroundTool(ctx, state, sink, exec, next))
|
|
74
85
|
ctx.on('session/disposed', (session: { id: string }) => {
|
|
75
86
|
state.disposed.add(session.id)
|
|
@@ -125,6 +136,113 @@ interface CapturePlan {
|
|
|
125
136
|
fs: any
|
|
126
137
|
}
|
|
127
138
|
|
|
139
|
+
/** 替换回执里的一条文件结果;只关心目标与完成状态。 */
|
|
140
|
+
interface BulkItem { path: string; status?: string }
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @private
|
|
144
|
+
* @author ddj 2026年11月09号
|
|
145
|
+
* @description: dryRun 只预览不落盘,既不预读基线也不产生待审条目。
|
|
146
|
+
* @param exec 工具分发上下文
|
|
147
|
+
* @returns 是否预览调用
|
|
148
|
+
*/
|
|
149
|
+
function isDryRun(exec: WriteExec): boolean {
|
|
150
|
+
return exec.arguments?.dryRun === true
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @private
|
|
155
|
+
* @author ddj 2026年11月09号
|
|
156
|
+
* @description: 解析批量替换回执里的文件条目;形状不符返回空,交给官方快照兜底。
|
|
157
|
+
* @param result 工具返回值
|
|
158
|
+
* @returns 带路径的回执条目
|
|
159
|
+
*/
|
|
160
|
+
function bulkItems(result: unknown): BulkItem[] {
|
|
161
|
+
const envelope = result as { value?: unknown } | null
|
|
162
|
+
const payload = (envelope?.value ?? result) as { items?: unknown } | null
|
|
163
|
+
if (!Array.isArray(payload?.items)) return []
|
|
164
|
+
|
|
165
|
+
const items: BulkItem[] = []
|
|
166
|
+
for (const raw of payload.items as unknown[]) {
|
|
167
|
+
const item = raw as { path?: unknown; status?: unknown } | null
|
|
168
|
+
if (!item || typeof item.path !== 'string' || !item.path) continue
|
|
169
|
+
items.push({ path: item.path, status: typeof item.status === 'string' ? item.status : undefined })
|
|
170
|
+
}
|
|
171
|
+
return items
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @private
|
|
176
|
+
* @author ddj 2026年11月09号
|
|
177
|
+
* @description: 求本次调用的采集目标;批量替换先按字面量预读候选,其余按工具参数取路径。
|
|
178
|
+
* @param ctx Host 生命周期
|
|
179
|
+
* @param cwd 工作区
|
|
180
|
+
* @param exec 工具分发上下文
|
|
181
|
+
* @param bulk 是否批量替换
|
|
182
|
+
* @returns 目标路径与批量替换的候选总数
|
|
183
|
+
* @throws 候选求值失败或工具参数不可用
|
|
184
|
+
*/
|
|
185
|
+
async function captureTargets(
|
|
186
|
+
ctx: Ctx, cwd: string, exec: WriteExec, bulk: boolean, search?: BulkSearcher,
|
|
187
|
+
): Promise<{ paths: string[]; total: number }> {
|
|
188
|
+
if (!bulk) return { paths: await toolTargets(exec), total: 0 }
|
|
189
|
+
const session = exec.agent?.session ?? { id: '' }
|
|
190
|
+
return replaceCandidates({ ctx, session: session as never, cwd, args: exec.arguments ?? {} }, search)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @private
|
|
195
|
+
* @author ddj 2026年11月09号
|
|
196
|
+
* @description: 用替换回执对齐预读候选;回执完成但没预读到的文件只记 gap,不伪造基线。
|
|
197
|
+
* @param scope 工作区作用域
|
|
198
|
+
* @param exec 工具分发上下文
|
|
199
|
+
* @param result 工具返回值
|
|
200
|
+
* @param plans 已完成写前冻结的采集计划
|
|
201
|
+
* @returns 无;路径解析失败只记 gap
|
|
202
|
+
*/
|
|
203
|
+
async function reconcileBulk(
|
|
204
|
+
scope: { cwd: string; sessionId: string; fs: any }, exec: WriteExec, result: unknown, plans: CapturePlan[],
|
|
205
|
+
): Promise<void> {
|
|
206
|
+
const known = new Set(plans.map((plan) => plan.identity))
|
|
207
|
+
for (const item of bulkItems(result)) {
|
|
208
|
+
if (item.status !== 'completed') continue
|
|
209
|
+
try {
|
|
210
|
+
const target = await scope.fs.resolve(item.path, { cwd: scope.cwd })
|
|
211
|
+
if (known.has(scope.fs.processPath(target))) continue
|
|
212
|
+
recordGap(scope, exec, item.path, '未预读基线,未采集该文件前后差异')
|
|
213
|
+
} catch (error) {
|
|
214
|
+
recordGap(scope, exec, item.path, error)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @private
|
|
221
|
+
* @author ddj 2026年11月09号
|
|
222
|
+
* @description: 逐目标冻结写前基线;预算超限、路径不可用或读取失败只影响对应目标。
|
|
223
|
+
* @param scope 工作区作用域
|
|
224
|
+
* @param state 采集生命周期状态
|
|
225
|
+
* @param exec 工具分发上下文
|
|
226
|
+
* @param paths 本次调用的目标路径
|
|
227
|
+
* @returns 已冻结的采集计划
|
|
228
|
+
*/
|
|
229
|
+
async function buildPlans(
|
|
230
|
+
scope: { cwd: string; sessionId: string; fs: any }, state: CaptureState, exec: WriteExec, paths: string[],
|
|
231
|
+
): Promise<CapturePlan[]> {
|
|
232
|
+
const plans: CapturePlan[] = []
|
|
233
|
+
for (const path of paths) {
|
|
234
|
+
try {
|
|
235
|
+
if (plans.length >= BULK_LIMIT) throw new Error('capture target budget exceeded')
|
|
236
|
+
const plan = await planOf(scope, state, path)
|
|
237
|
+
if (plan) plans.push(plan)
|
|
238
|
+
} catch (error) {
|
|
239
|
+
if (!state.stopped && !state.disposed.has(scope.sessionId)) recordGap(scope, exec, path, error)
|
|
240
|
+
log.debug('待审采集跳过:' + path + ': ' + String(error))
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return plans
|
|
244
|
+
}
|
|
245
|
+
|
|
128
246
|
/**
|
|
129
247
|
* @author ddj 2026年10月30号
|
|
130
248
|
* @description: 写工具执行前后各读一次,内容变化才上报;任何采集异常都不改变工具结果。
|
|
@@ -139,26 +257,34 @@ async function aroundTool(
|
|
|
139
257
|
ctx: Ctx, state: CaptureState, sink: (write: PendingWrite) => void,
|
|
140
258
|
exec: WriteExec, next: () => Promise<unknown>,
|
|
141
259
|
): Promise<unknown> {
|
|
142
|
-
|
|
260
|
+
const name = String(exec.name)
|
|
261
|
+
const bulk = name === BULK_TOOL
|
|
262
|
+
if (state.stopped || (!bulk && !WRITE_TOOLS.includes(name)) || isDryRun(exec)) return next()
|
|
263
|
+
|
|
143
264
|
const session = exec.agent?.session
|
|
144
265
|
const cwd = session ? cwdOfSession(ctx, session as never) : null
|
|
145
266
|
if (!session?.id || !cwd) return next()
|
|
267
|
+
|
|
146
268
|
const scope = { cwd, sessionId: session.id, fs: ctx.get('fs') }
|
|
147
|
-
|
|
269
|
+
let targets: { paths: string[]; total: number }
|
|
148
270
|
try {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
271
|
+
targets = await captureTargets(ctx, scope.cwd, exec, bulk, state.search)
|
|
272
|
+
} catch (error) {
|
|
273
|
+
recordGap(scope, exec, bulk ? BULK_TOOL : name, error)
|
|
274
|
+
log.debug('待审目标不可用:' + String(error))
|
|
275
|
+
return next()
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// 候选超出预算时只保证前 BULK_LIMIT 个文件有真实基线,其余在回执对齐阶段补 gap。
|
|
279
|
+
if (bulk && targets.total > targets.paths.length) {
|
|
280
|
+
recordGap(scope, exec, BULK_TOOL, '批量替换候选 ' + targets.total + ' 个文件,仅采集前 ' + targets.paths.length + ' 个')
|
|
281
|
+
}
|
|
282
|
+
const plans = await buildPlans(scope, state, exec, targets.paths)
|
|
158
283
|
|
|
159
284
|
try {
|
|
160
285
|
const result = await next()
|
|
161
|
-
if (
|
|
286
|
+
if (bulk && !state.stopped && !state.disposed.has(scope.sessionId)) await reconcileBulk(scope, exec, result, plans)
|
|
287
|
+
if (name === 'apply_patch' && !state.stopped && !state.disposed.has(scope.sessionId)) {
|
|
162
288
|
for (const diagnostic of patchDiagnostics(result)) recordGap(scope, exec, 'apply_patch', diagnostic)
|
|
163
289
|
}
|
|
164
290
|
return result
|
package/src/toolTargets.ts
CHANGED
|
@@ -4,10 +4,13 @@ import { loadHostModule } from './hostImport.js'
|
|
|
4
4
|
export interface ToolCall {
|
|
5
5
|
name?: string
|
|
6
6
|
id?: string
|
|
7
|
-
arguments?: { file_path?: unknown; path?: unknown; input?: unknown }
|
|
7
|
+
arguments?: { file_path?: unknown; path?: unknown; to?: unknown; input?: unknown }
|
|
8
8
|
}
|
|
9
9
|
interface PatchTarget { path: string; moveTo?: string }
|
|
10
10
|
|
|
11
|
+
/** dsh-ops 工具名前缀(对应 dsh-ops 的 TOOL_PREFIX)。 */
|
|
12
|
+
export const OPS_PREFIX = 'ops_'
|
|
13
|
+
|
|
11
14
|
/** @public @author ddj 2026年11月04号 @param result Untrusted tool envelope. @returns Diagnostic-only status; never writable preimages. */
|
|
12
15
|
export function patchDiagnostics(result: unknown): string[] {
|
|
13
16
|
const envelope = result as { value?: unknown } | null
|
|
@@ -43,8 +46,38 @@ export async function patchParser(): Promise<PatchParser | null> {
|
|
|
43
46
|
return parser
|
|
44
47
|
}
|
|
45
48
|
|
|
49
|
+
/** dsh-ops 单目标写工具后缀:目标只来自 arguments.path。 */
|
|
50
|
+
const OPS_SINGLE = new Set(['edit_file', 'write_file', 'remove'])
|
|
51
|
+
/** dsh-ops 成对写工具后缀:源为 arguments.path,目标为 arguments.to。 */
|
|
52
|
+
const OPS_PAIR = new Set(['copy', 'move'])
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @private
|
|
56
|
+
* @author ddj 2026年11月09号
|
|
57
|
+
* @description: dsh-ops 写工具的真实落盘目标;未知 ops 工具保守返回空,不猜测路径。
|
|
58
|
+
* @param call 工具身份与调用参数
|
|
59
|
+
* @returns 去重后的目标路径;无目标时为空数组
|
|
60
|
+
*/
|
|
61
|
+
function opsTargets(call: ToolCall): string[] {
|
|
62
|
+
const suffix = String(call.name).slice(OPS_PREFIX.length)
|
|
63
|
+
const single = OPS_SINGLE.has(suffix) || OPS_PAIR.has(suffix)
|
|
64
|
+
const source = single ? call.arguments?.path : undefined
|
|
65
|
+
const destination = OPS_PAIR.has(suffix) ? call.arguments?.to : undefined
|
|
66
|
+
const paths: string[] = []
|
|
67
|
+
if (typeof source === 'string' && source) {
|
|
68
|
+
paths.push(source)
|
|
69
|
+
}
|
|
70
|
+
if (typeof destination === 'string' && destination && destination !== source) {
|
|
71
|
+
paths.push(destination)
|
|
72
|
+
}
|
|
73
|
+
return paths
|
|
74
|
+
}
|
|
75
|
+
|
|
46
76
|
/** @public @author ddj 2026年11月04号 @param call Tool identity and arguments. @param parser Optional injectable official parser. @returns Unique unresolved source/destination paths. @throws Unsupported parser or malformed patch. */
|
|
47
77
|
export async function toolTargets(call: ToolCall, parser?: PatchParser | null): Promise<string[]> {
|
|
78
|
+
if (String(call.name).startsWith(OPS_PREFIX)) {
|
|
79
|
+
return opsTargets(call)
|
|
80
|
+
}
|
|
48
81
|
if (['edit', 'write', 'str_replace_editor'].includes(String(call.name))) {
|
|
49
82
|
const path = call.arguments?.file_path ?? call.arguments?.path
|
|
50
83
|
return typeof path === 'string' && path ? [path] : []
|