dsh-vscode-mode 0.30.0 → 0.31.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.
Files changed (53) hide show
  1. package/README.md +54 -10
  2. package/lib/client.js +143 -52
  3. package/lib/client.js.map +1 -1
  4. package/lib/index.js +3549 -1465
  5. package/lib/index.js.map +1 -1
  6. package/package.json +1 -1
  7. package/skills/dsh-vscodemode-html-plan/LICENSE +202 -0
  8. package/skills/dsh-vscodemode-html-plan/SKILL.md +147 -0
  9. package/skills/dsh-vscodemode-html-plan/examples/scheduled-send.html +298 -0
  10. package/skills/dsh-vscodemode-html-plan/references/blocks.md +227 -0
  11. package/skills/dsh-vscodemode-html-plan/references/subagent-brief.md +17 -0
  12. package/skills/dsh-vscodemode-html-plan/references/upstream-SKILL.md +174 -0
  13. package/skills/dsh-vscodemode-html-plan/runtime/htmlplan.css +564 -0
  14. package/skills/dsh-vscodemode-html-plan/runtime/htmlplan.js +1299 -0
  15. package/skills/dsh-vscodemode-html-plan/runtime/pack.mjs +300 -0
  16. package/src/ai/llmTask.ts +178 -0
  17. package/src/ai/llmTypes.ts +6 -0
  18. package/src/ai/svnCommitMsg.ts +107 -0
  19. package/src/ai/svnTriage.ts +34 -85
  20. package/src/client/aiCommit.ts +57 -0
  21. package/src/client/htmlPlan/HtmlPlanPanel.ts +261 -0
  22. package/src/client/htmlPlan/planActions.ts +347 -0
  23. package/src/client/htmlPlan/planPage.ts +333 -0
  24. package/src/client/htmlPreview.ts +218 -0
  25. package/src/client/index.ts +8 -0
  26. package/src/client/officialSidebar.ts +11 -3
  27. package/src/client/planState.ts +8 -2
  28. package/src/client/sidebar/menuItems.ts +1 -0
  29. package/src/client/sidebar/panels/SvnPanel.ts +17 -0
  30. package/src/client/sidebar/types.ts +2 -0
  31. package/src/client/styles/editor.css +77 -0
  32. package/src/client/svnActions.ts +7 -0
  33. package/src/client/svnCommit.ts +109 -0
  34. package/src/client/svnNotice.ts +1 -1
  35. package/src/client/svnStatus.ts +5 -2
  36. package/src/client/ui/EditorView.ts +85 -7
  37. package/src/client/ui/McpSettings.ts +59 -0
  38. package/src/client/ui/SvnAiPlanDialog.ts +24 -4
  39. package/src/client/ui/SvnCommitDialog.ts +458 -0
  40. package/src/client/ui/commandCatalog.ts +11 -0
  41. package/src/client/ui/svnCommitModel.ts +204 -0
  42. package/src/fileOpenSettings.ts +113 -5
  43. package/src/htmlPlanCommand.ts +176 -0
  44. package/src/index.ts +4 -0
  45. package/src/shared/keybindings.ts +11 -0
  46. package/src/shared/rpc.ts +13 -4
  47. package/src/shared/svn.ts +191 -10
  48. package/src/shared/svnActions.ts +16 -0
  49. package/src/svn.ts +205 -47
  50. package/src/svnCommit.ts +348 -0
  51. package/src/svnCore.ts +254 -0
  52. package/src/svnToolJson.ts +73 -0
  53. package/src/svnTools.ts +566 -0
@@ -0,0 +1,566 @@
1
+ /**
2
+ * dsh-vscode-mode host — 19 个 §svn_*§ agent 工具(22-agent-tools-and-commit)。
3
+ *
4
+ * 为什么要有工具层:此前模型只能在大 Bash 里裸跑 §svn§——没有只读/只写边界、
5
+ * 没有输出归一(0.2.x 会因 §undefined§/NaN 整次失败),也没有路径白名单。
6
+ * 这里把「会话绑定 + 路径归一 + 执行 + 无损输出」收敛成一份适配层,
7
+ * 执行本身仍走 svn.ts 的既有 handler / 统一执行器(单一执行路径)。
8
+ *
9
+ * 纪律:写工具受只读设置拦截(执行器层);只读工具声明 §isConcurrencySafe§ 以允许并行;
10
+ * 位置参数(属性名/changelist/URL)拒 §-§ 开头;路径操作数一律在 §--§ 之后。
11
+ * @author ddj 2026年11月15号
12
+ */
13
+ import type { Ctx } from './store.js'
14
+ import { loadHostModule } from './hostImport.js'
15
+ import { toLosslessJson, toolJsonText } from './svnToolJson.js'
16
+ import { classifySvnError, svnErrorOf, svnOperandErrorOf } from './svnCore.js'
17
+ import { COMMIT_PATHS_CAP } from './shared/svn.js'
18
+
19
+ /** 只读子命令超时。 */
20
+ const READ_GRACE_MS = 30_000
21
+ /** 写子命令超时。 */
22
+ const MUTATE_GRACE_MS = 120_000
23
+ /** 状态类超时。 */
24
+ const STATUS_GRACE_MS = 120_000
25
+ /** 输出收集上限(工具载荷,8MB 足够看一个目录的 diff)。 */
26
+ const OUTPUT_CAP = 8 * 1024 * 1024
27
+
28
+ /** 工具作用域(会话工作区 + 工作副本根)。 */
29
+ export interface SvnToolScope {
30
+ /** 会话工作区目录。 */
31
+ cwd: string
32
+ /** 工作副本根绝对路径。 */
33
+ root: string
34
+ }
35
+
36
+ /** 工具执行 API(由 svn.ts 的 createSvnRpc 提供)。 */
37
+ export interface SvnToolApi {
38
+ /** 既有 RPC handler(写操作复用同一执行路径)。 */
39
+ handlers: Record<string, (args: Record<string, unknown>) => Promise<{ ok: boolean } & Record<string, unknown>>>
40
+ /** 统一执行器(只读门禁/超时倍数在 svnCore)。 */
41
+ run: (cwd: string, argv: string[], graceMs: number, stdoutCap?: number, allowFallback?: boolean) => Promise<{ code: number | null; stdout: string; stderr: string }>
42
+ /** 会话 → 作用域。 */
43
+ scopeOf: (sessionId?: string) => Promise<SvnToolScope | { err: string }>
44
+ /** 工作区相对路径 → svn 目标(越界返回 null)。 */
45
+ targetOf: (cwd: string, root: string, rel: string) => string | null
46
+ /** 路径归一(越界返回 null)。 */
47
+ relOf: (raw: unknown) => string | null
48
+ }
49
+
50
+ /** 工具执行上下文(只取所需字段)。 */
51
+ interface ToolExec {
52
+ agent?: { session?: { id?: string } }
53
+ signal?: AbortSignal
54
+ }
55
+
56
+ /** 工具定义(渲染 + 执行)。 */
57
+ interface ToolSpec {
58
+ /** 工具名(§svn_*§)。 */
59
+ name: string
60
+ /** 给模型的说明(英文为主,含边界)。 */
61
+ description: string
62
+ /** 参数 schema(dsh-tools 的属性表)。 */
63
+ parameters: Record<string, unknown>
64
+ /** 是否只读(true = 允许并行)。 */
65
+ safe: boolean
66
+ /** 执行体(args 已由框架校验,仍是 unknown 语义)。 */
67
+ execute: (args: Record<string, unknown>, exec: ToolExec, api: SvnToolApi) => Promise<unknown>
68
+ }
69
+
70
+ /**
71
+ * 取执行会话 id(工具必须绑定会话:所有操作都限定在该会话工作区)。
72
+ * @author ddj 2026年11月15号
73
+ * @param exec 执行上下文
74
+ * @returns 会话 id
75
+ */
76
+ function sessionIdOf(exec: ToolExec): string {
77
+ const id = exec.agent?.session?.id
78
+ if (!id) throw new Error('SVN 工具需要所属会话')
79
+ return id
80
+ }
81
+
82
+ /**
83
+ * 读数:整数参数收敛。
84
+ * @author ddj 2026年11月15号
85
+ * @param value 原始值
86
+ * @returns 整数或 undefined
87
+ */
88
+ function intOf(value: unknown): number | undefined {
89
+ const num = typeof value === 'number' ? value : Number(value)
90
+ return Number.isInteger(num) ? num : undefined
91
+ }
92
+
93
+ /**
94
+ * 读数:字符串数组参数收敛(去空白/去重)。
95
+ * @author ddj 2026年11月15号
96
+ * @param value 原始值
97
+ * @returns 路径数组
98
+ */
99
+ function stringsOf(value: unknown): string[] {
100
+ if (!Array.isArray(value)) return []
101
+ return [...new Set(value.map((item) => String(item ?? '').trim()).filter(Boolean))]
102
+ }
103
+
104
+ /**
105
+ * 解析目标路径:URL 原样透传(防被当文件路径),其余按工作区相对路径归一。
106
+ * @author ddj 2026年11月15号
107
+ * @param api 工具 API @param scope 作用域 @param raw 原始路径
108
+ * @returns svn 目标操作数
109
+ */
110
+ async function targetOfPath(api: SvnToolApi, scope: SvnToolScope, raw: unknown): Promise<string> {
111
+ const text = typeof raw === 'string' ? raw.trim() : ''
112
+ const isUrl = /^(?:svn|[a-z][a-z0-9+.-]*):\/\//i.test(text) || text.startsWith('^/')
113
+ if (isUrl) {
114
+ const error = svnOperandErrorOf(text)
115
+ if (error) throw new Error(error)
116
+ return text
117
+ }
118
+ const rel = api.relOf(text)
119
+ if (rel === null) throw new Error('路径不合法(越界或非法字符)')
120
+ const target = api.targetOf(scope.cwd, scope.root, rel)
121
+ if (!target) throw new Error('目标不在 SVN 工作副本内')
122
+ return target
123
+ }
124
+
125
+ /**
126
+ * 跑一条只读命令并返回文本(失败转可读错误)。
127
+ * @author ddj 2026年11月15号
128
+ * @param api 工具 API @param scope 作用域 @param argv 参数 @param cap 输出上限
129
+ * @returns stdout
130
+ */
131
+ async function readText(api: SvnToolApi, scope: SvnToolScope, argv: string[], cap = OUTPUT_CAP): Promise<{ text: string; truncated: boolean }> {
132
+ const outcome = await api.run(scope.root, argv, READ_GRACE_MS, cap)
133
+ if (outcome.code !== 0) {
134
+ const info = classifySvnError([outcome.stderr, outcome.stdout].filter(Boolean).join('\n'))
135
+ throw new Error(info.message)
136
+ }
137
+ return { text: outcome.stdout, truncated: outcome.stdout.length >= cap }
138
+ }
139
+
140
+ /**
141
+ * 跑一条写命令(批量 add/delete 等无专用 handler 的场景)。
142
+ * @author ddj 2026年11月15号
143
+ * @param api 工具 API @param scope 作用域 @param argv 参数
144
+ * @returns 退出码与合并输出
145
+ */
146
+ async function runWrite(api: SvnToolApi, scope: SvnToolScope, argv: string[]): Promise<{ code: number | null; text: string }> {
147
+ const outcome = await api.run(scope.root, argv, MUTATE_GRACE_MS)
148
+ const text = [outcome.stdout, outcome.stderr].filter(Boolean).join('\n').trim()
149
+ if (outcome.code !== 0) {
150
+ const info = classifySvnError(text)
151
+ throw new Error(info.message)
152
+ }
153
+ return { code: outcome.code, text }
154
+ }
155
+
156
+ /**
157
+ * 包一层统一错误处理:只读拒绝带 code,其余透传可读文案。
158
+ * @author ddj 2026年11月15号
159
+ * @param exec 执行上下文 @param api 工具 API @param body 实现
160
+ * @returns 归一化结果
161
+ */
162
+ async function guarded(exec: ToolExec, api: SvnToolApi, body: (scope: SvnToolScope, sessionId: string) => Promise<unknown>): Promise<unknown> {
163
+ try {
164
+ if (exec.signal?.aborted) return { ok: false, error: '调用已取消' }
165
+ const sessionId = sessionIdOf(exec)
166
+ const scope = await api.scopeOf(sessionId)
167
+ if ('err' in scope) return { ok: false, error: scope.err }
168
+ return toLosslessJson(await body(scope, sessionId))
169
+ } catch (error) {
170
+ const info = svnErrorOf(error)
171
+ return toLosslessJson({ ok: false, ...(info.code ? { code: info.code } : {}), error: info.error })
172
+ }
173
+ }
174
+
175
+ /**
176
+ * 复用既有 RPC handler(写操作的唯一执行路径)。
177
+ * @author ddj 2026年11月15号
178
+ * @param api 工具 API @param method handler 名 @param args 参数
179
+ * @returns handler 结果
180
+ */
181
+ async function callHandler(api: SvnToolApi, method: string, args: Record<string, unknown>): Promise<{ ok: boolean } & Record<string, unknown>> {
182
+ const handler = api.handlers[method]
183
+ if (!handler) return { ok: false, error: '该能力在当前宿主不可用:' + method }
184
+ return handler(args)
185
+ }
186
+
187
+ /** 路径数组参数(1 个以上)。 */
188
+ const PATHS_PARAM = { type: 'array', items: { type: 'string' }, required: true, description: '工作区相对路径列表(最多 ' + COMMIT_PATHS_CAP + ' 个)' }
189
+ /** 可选路径参数。 */
190
+ const PATH_PARAM = { type: 'string', description: '工作区相对路径(缺省 = 工作副本根);允许 svn:// 或 https:// 仓库 URL' }
191
+
192
+ /** 19 个工具定义(顺序仅影响列表展示)。 */
193
+ const TOOL_SPECS: readonly ToolSpec[] = [
194
+ {
195
+ name: 'svn_status',
196
+ description: 'List working-copy changes (status). Read-only. Returns entries with path/status/changelist/revision plus changelist grouping.',
197
+ parameters: { force: { type: 'boolean', description: 'Skip the 5s cache and re-read' } },
198
+ safe: true,
199
+ execute: (args, exec, api) => guarded(exec, api, async (_scope, sessionId) => {
200
+ const result = await callHandler(api, 'svn.changes', { sessionId, force: args.force === true })
201
+ return result
202
+ }),
203
+ },
204
+ {
205
+ name: 'svn_info',
206
+ description: 'Show repository information for the workspace or a path (revision, URL, repository root). Read-only.',
207
+ parameters: { path: PATH_PARAM },
208
+ safe: true,
209
+ execute: (args, exec, api) => guarded(exec, api, async (scope) => {
210
+ const target = await targetOfPath(api, scope, args.path)
211
+ const { text } = await readText(api, scope, ['info', '--xml', '--', target])
212
+ const revision = /<entry[^>]*\brevision="(\d+)"/.exec(text)?.[1]
213
+ const url = /<url>([^<]*)<\/url>/.exec(text)?.[1]
214
+ const rootUrl = /<root>([^<]*)<\/root>/.exec(text)?.[1]
215
+ return {
216
+ ok: true,
217
+ path: target,
218
+ revision: revision ? Number(revision) : undefined,
219
+ url,
220
+ repositoryRoot: rootUrl,
221
+ }
222
+ }),
223
+ },
224
+ {
225
+ name: 'svn_diff',
226
+ description: 'Show a unified diff. Read-only. Without revisions it diffs BASE against the working copy; with revision/revA/revB it diffs repository revisions.',
227
+ parameters: {
228
+ path: PATH_PARAM,
229
+ revision: { type: 'integer', description: 'Diff this revision against its previous revision' },
230
+ revA: { type: 'integer', description: 'Left revision (with revB)' },
231
+ revB: { type: 'integer', description: 'Right revision (with revA)' },
232
+ ignoreWhitespace: { type: 'boolean', description: 'Ignore whitespace-only changes' },
233
+ },
234
+ safe: true,
235
+ execute: (args, exec, api) => guarded(exec, api, async (scope) => {
236
+ const target = await targetOfPath(api, scope, args.path)
237
+ const argv = ['diff']
238
+ const revA = intOf(args.revA)
239
+ const revB = intOf(args.revB)
240
+ const revision = intOf(args.revision)
241
+ if (revA !== undefined && revB !== undefined) argv.push('-r', revA + ':' + revB)
242
+ else if (revision !== undefined) argv.push('-c', String(revision))
243
+ if (args.ignoreWhitespace === true) argv.push('-x', '-w')
244
+ argv.push('--', target)
245
+ const { text, truncated } = await readText(api, scope, argv)
246
+ return { ok: true, path: target, text, truncated }
247
+ }),
248
+ },
249
+ {
250
+ name: 'svn_log',
251
+ description: 'Read commit history (log) for the workspace or a path. Read-only. Returns entries with revision/author/date/message/paths.',
252
+ parameters: {
253
+ path: PATH_PARAM,
254
+ limit: { type: 'integer', description: 'Maximum entries (default 50, cap 500)' },
255
+ startRev: { type: 'integer', description: 'Range start revision (with endRev)' },
256
+ endRev: { type: 'integer', description: 'Range end revision' },
257
+ stopOnCopy: { type: 'boolean', description: 'Stop at the copy point' },
258
+ showMerged: { type: 'boolean', description: 'Include merged revisions (-g)' },
259
+ },
260
+ safe: true,
261
+ execute: (args, exec, api) => guarded(exec, api, async (scope, sessionId) => {
262
+ const rel = api.relOf(args.path)
263
+ if (rel === null) throw new Error('路径不合法')
264
+ const startRev = intOf(args.startRev)
265
+ const endRev = intOf(args.endRev)
266
+ const result = await callHandler(api, 'svn.log', {
267
+ sessionId,
268
+ ...(rel ? { path: rel } : {}),
269
+ limit: intOf(args.limit),
270
+ stopOnCopy: args.stopOnCopy === true,
271
+ showMerged: args.showMerged === true,
272
+ ...(startRev !== undefined ? { startRev } : {}),
273
+ ...(endRev !== undefined ? { endRev } : {}),
274
+ })
275
+ return result
276
+ }),
277
+ },
278
+ {
279
+ name: 'svn_blame',
280
+ description: 'Show line-by-line last-change attribution (blame) for one file. Read-only.',
281
+ parameters: {
282
+ path: { type: 'string', required: true, description: 'File path relative to the workspace' },
283
+ revision: { type: 'integer', description: 'Blame at this revision (default HEAD)' },
284
+ },
285
+ safe: true,
286
+ execute: (args, exec, api) => guarded(exec, api, async (scope) => {
287
+ const target = await targetOfPath(api, scope, args.path)
288
+ const argv = ['blame']
289
+ const revision = intOf(args.revision)
290
+ if (revision !== undefined) argv.push('-r', String(revision))
291
+ argv.push('--', target)
292
+ const { text, truncated } = await readText(api, scope, argv)
293
+ return { ok: true, path: target, text, truncated }
294
+ }),
295
+ },
296
+ {
297
+ name: 'svn_list',
298
+ description: 'List directory entries in a working copy or repository URL (svn list). Read-only.',
299
+ parameters: { path: PATH_PARAM },
300
+ safe: true,
301
+ execute: (args, exec, api) => guarded(exec, api, async (scope) => {
302
+ const target = await targetOfPath(api, scope, args.path)
303
+ const { text, truncated } = await readText(api, scope, ['list', '--', target])
304
+ const entries = text.split(/\r?\n/).map((line) => line.trim()).filter(Boolean)
305
+ return { ok: true, path: target, entries, truncated }
306
+ }),
307
+ },
308
+ {
309
+ name: 'svn_cat',
310
+ description: 'Read file content from the working copy BASE or a repository revision (svn cat). Read-only.',
311
+ parameters: {
312
+ path: { type: 'string', required: true, description: 'File path (workspace-relative) or repository URL' },
313
+ revision: { type: 'string', description: 'Revision, BASE or HEAD (default working copy BASE)' },
314
+ },
315
+ safe: true,
316
+ execute: (args, exec, api) => guarded(exec, api, async (scope) => {
317
+ const target = await targetOfPath(api, scope, args.path)
318
+ const revision = typeof args.revision === 'string' && args.revision.trim() ? args.revision.trim() : 'BASE'
319
+ const revError = svnOperandErrorOf(revision)
320
+ if (revError) throw new Error(revError)
321
+ const { text, truncated } = await readText(api, scope, ['cat', '-r', revision, '--', target])
322
+ return { ok: true, path: target, revision, text, truncated }
323
+ }),
324
+ },
325
+ {
326
+ name: 'svn_propget',
327
+ description: 'Read one versioned property (e.g. svn:ignore, svn:eol-style). Read-only.',
328
+ parameters: {
329
+ path: PATH_PARAM,
330
+ name: { type: 'string', required: true, description: 'Property name such as svn:ignore' },
331
+ },
332
+ safe: true,
333
+ execute: (args, exec, api) => guarded(exec, api, async (scope) => {
334
+ const name = String(args.name ?? '').trim()
335
+ const nameError = svnOperandErrorOf(name)
336
+ if (nameError) throw new Error(nameError)
337
+ const target = await targetOfPath(api, scope, args.path)
338
+ const { text } = await readText(api, scope, ['propget', name, '--', target])
339
+ return { ok: true, path: target, name, value: text.replace(/\r?\n$/, '') }
340
+ }),
341
+ },
342
+ {
343
+ name: 'svn_proplist',
344
+ description: 'List all versioned properties of a path. Read-only.',
345
+ parameters: { path: PATH_PARAM },
346
+ safe: true,
347
+ execute: (args, exec, api) => guarded(exec, api, async (scope) => {
348
+ const target = await targetOfPath(api, scope, args.path)
349
+ const { text, truncated } = await readText(api, scope, ['proplist', '-v', '--', target])
350
+ return { ok: true, path: target, text, truncated }
351
+ }),
352
+ },
353
+ {
354
+ name: 'svn_add',
355
+ description: 'Schedule unversioned paths for addition (svn add). Write operation; blocked in read-only mode.',
356
+ parameters: { paths: PATHS_PARAM },
357
+ safe: false,
358
+ execute: (args, exec, api) => guarded(exec, api, async (_scope, sessionId) => {
359
+ const paths = stringsOf(args.paths)
360
+ if (!paths.length) throw new Error('未提供任何路径')
361
+ return callHandler(api, 'svn.add', { sessionId, paths })
362
+ }),
363
+ },
364
+ {
365
+ name: 'svn_delete',
366
+ description: 'Schedule versioned paths for deletion (svn delete). Write operation; blocked in read-only mode.',
367
+ parameters: { paths: PATHS_PARAM },
368
+ safe: false,
369
+ execute: (args, exec, api) => guarded(exec, api, async (scope) => {
370
+ const paths = stringsOf(args.paths)
371
+ if (!paths.length) throw new Error('未提供任何路径')
372
+ const targets: string[] = []
373
+ for (const path of paths) {
374
+ const rel = api.relOf(path)
375
+ if (rel === null || rel === '') throw new Error('路径不合法:' + path)
376
+ const target = api.targetOf(scope.cwd, scope.root, rel)
377
+ if (!target) throw new Error('目标不在 SVN 工作副本内:' + path)
378
+ targets.push(target)
379
+ }
380
+ const { text } = await runWrite(api, scope, ['delete', '--', ...targets])
381
+ const count = (text.match(/^(?:D|Deleting|正在删除)\b/gm) ?? []).length
382
+ return { ok: true, count, summary: '已计划删除 ' + (count || targets.length) + ' 项', output: text }
383
+ }),
384
+ },
385
+ {
386
+ name: 'svn_revert',
387
+ description: 'Revert local changes of the given paths (svn revert). Destructive; blocked in read-only mode.',
388
+ parameters: {
389
+ paths: PATHS_PARAM,
390
+ depth: { type: 'string', enum: ['empty'], description: 'Revert only the given entries (no recursion)' },
391
+ },
392
+ safe: false,
393
+ execute: (args, exec, api) => guarded(exec, api, async (_scope, sessionId) => {
394
+ const paths = stringsOf(args.paths)
395
+ if (!paths.length) throw new Error('未提供任何路径')
396
+ return callHandler(api, 'svn.revert', { sessionId, paths, ...(args.depth === 'empty' ? { depth: 'empty' } : {}) })
397
+ }),
398
+ },
399
+ {
400
+ name: 'svn_commit',
401
+ description: 'Commit the given paths with a message (native commit: host re-checks status first, optionally auto-adds unversioned and auto-deletes missing files). Write operation; blocked in read-only mode. Never resolves conflicts automatically.',
402
+ parameters: {
403
+ paths: PATHS_PARAM,
404
+ message: { type: 'string', required: true, description: 'Commit message (first line becomes the subject)' },
405
+ changelist: { type: 'string', description: 'Only commit entries of this changelist' },
406
+ keepLocks: { type: 'boolean', description: 'Keep locks after commit (--no-unlock)' },
407
+ autoAdd: { type: 'boolean', description: 'Auto svn add selected unversioned paths (default from settings)' },
408
+ autoDelete: { type: 'boolean', description: 'Auto svn delete selected missing paths (default from settings)' },
409
+ },
410
+ safe: false,
411
+ execute: (args, exec, api) => guarded(exec, api, async (_scope, sessionId) => {
412
+ const paths = stringsOf(args.paths)
413
+ if (!paths.length) throw new Error('未提供任何路径')
414
+ const message = typeof args.message === 'string' ? args.message : ''
415
+ if (!message.trim()) throw new Error('提交信息不能为空')
416
+ return callHandler(api, 'svn.commit', {
417
+ sessionId,
418
+ paths,
419
+ message,
420
+ ...(typeof args.changelist === 'string' && args.changelist.trim() ? { changelist: args.changelist.trim() } : {}),
421
+ keepLocks: args.keepLocks === true,
422
+ ...(typeof args.autoAdd === 'boolean' ? { autoAdd: args.autoAdd } : {}),
423
+ ...(typeof args.autoDelete === 'boolean' ? { autoDelete: args.autoDelete } : {}),
424
+ })
425
+ }),
426
+ },
427
+ {
428
+ name: 'svn_update',
429
+ description: 'Update the working copy (svn update). Write operation; blocked in read-only mode.',
430
+ parameters: { path: PATH_PARAM },
431
+ safe: false,
432
+ execute: (args, exec, api) => guarded(exec, api, async (_scope, sessionId) => {
433
+ const rel = api.relOf(args.path)
434
+ if (rel === null) throw new Error('路径不合法')
435
+ return callHandler(api, 'svn.update', { sessionId, ...(rel ? { path: rel } : {}) })
436
+ }),
437
+ },
438
+ {
439
+ name: 'svn_resolve',
440
+ description: 'Mark a conflicted path resolved with the given strategy (svn resolve). Write operation; blocked in read-only mode.',
441
+ parameters: {
442
+ path: { type: 'string', required: true, description: 'Conflicted path relative to the workspace' },
443
+ accept: { type: 'string', required: true, enum: ['working', 'mine-full', 'theirs-full'], description: 'Conflict strategy' },
444
+ },
445
+ safe: false,
446
+ execute: (args, exec, api) => guarded(exec, api, async (_scope, sessionId) => {
447
+ const accept = String(args.accept ?? '')
448
+ if (!['working', 'mine-full', 'theirs-full'].includes(accept)) throw new Error('解决策略不合法')
449
+ const rel = api.relOf(args.path)
450
+ if (rel === null || rel === '') throw new Error('路径不合法')
451
+ return callHandler(api, 'svn.resolve', { sessionId, path: rel, accept })
452
+ }),
453
+ },
454
+ {
455
+ name: 'svn_cleanup',
456
+ description: 'Clean up the working copy locks (svn cleanup); optionally remove unversioned/ignored files. Write operation; blocked in read-only mode.',
457
+ parameters: {
458
+ removeUnversioned: { type: 'boolean', description: 'Also delete unversioned files' },
459
+ removeIgnored: { type: 'boolean', description: 'Also delete ignored files' },
460
+ },
461
+ safe: false,
462
+ execute: (args, exec, api) => guarded(exec, api, async (_scope, sessionId) => callHandler(api, 'svn.cleanup', {
463
+ sessionId,
464
+ removeUnversioned: args.removeUnversioned === true,
465
+ removeIgnored: args.removeIgnored === true,
466
+ })),
467
+ },
468
+ {
469
+ name: 'svn_propset',
470
+ description: 'Set one versioned property value (svn propset), e.g. svn:ignore or svn:eol-style. Write operation; blocked in read-only mode.',
471
+ parameters: {
472
+ path: PATH_PARAM,
473
+ name: { type: 'string', required: true, description: 'Property name' },
474
+ value: { type: 'string', required: true, description: 'Property value (use \n for multi-line values)' },
475
+ },
476
+ safe: false,
477
+ execute: (args, exec, api) => guarded(exec, api, async (scope) => {
478
+ const name = String(args.name ?? '').trim()
479
+ const nameError = svnOperandErrorOf(name)
480
+ if (nameError) throw new Error(nameError)
481
+ const value = typeof args.value === 'string' ? args.value : ''
482
+ const target = await targetOfPath(api, scope, args.path)
483
+ await runWrite(api, scope, ['propset', name, value, '--', target])
484
+ return { ok: true, path: target, name, summary: '已写入属性 ' + name }
485
+ }),
486
+ },
487
+ {
488
+ name: 'svn_propdel',
489
+ description: 'Delete one versioned property (svn propdel). Write operation; blocked in read-only mode.',
490
+ parameters: {
491
+ path: PATH_PARAM,
492
+ name: { type: 'string', required: true, description: 'Property name' },
493
+ },
494
+ safe: false,
495
+ execute: (args, exec, api) => guarded(exec, api, async (scope) => {
496
+ const name = String(args.name ?? '').trim()
497
+ const nameError = svnOperandErrorOf(name)
498
+ if (nameError) throw new Error(nameError)
499
+ const target = await targetOfPath(api, scope, args.path)
500
+ await runWrite(api, scope, ['propdel', name, '--', target])
501
+ return { ok: true, path: target, name, summary: '已删除属性 ' + name }
502
+ }),
503
+ },
504
+ {
505
+ name: 'svn_changelist',
506
+ description: 'Assign or remove changelist membership for paths (svn changelist). Write operation; blocked in read-only mode.',
507
+ parameters: {
508
+ paths: PATHS_PARAM,
509
+ name: { type: 'string', description: 'Changelist name (required unless remove=true)' },
510
+ remove: { type: 'boolean', description: 'Remove the paths from their changelist' },
511
+ },
512
+ safe: false,
513
+ execute: (args, exec, api) => guarded(exec, api, async (_scope, sessionId) => {
514
+ const paths = stringsOf(args.paths)
515
+ if (!paths.length) throw new Error('未提供任何路径')
516
+ const remove = args.remove === true
517
+ const name = typeof args.name === 'string' ? args.name.trim() : ''
518
+ if (!remove && !name) throw new Error('未提供分区分名')
519
+ return callHandler(api, 'svn.changelist', { sessionId, paths, ...(name ? { name } : {}), remove })
520
+ }),
521
+ },
522
+ ]
523
+
524
+ /**
525
+ * 构造一个工具的 defineTool 选项(参数/输出/render/执行)。
526
+ * @author ddj 2026年11月15号
527
+ * @param spec 工具定义
528
+ * @param api 工具 API
529
+ * @returns defineTool 选项
530
+ */
531
+ function optionsOf(spec: ToolSpec, api: SvnToolApi) {
532
+ return {
533
+ name: spec.name,
534
+ description: spec.description,
535
+ parameters: spec.parameters,
536
+ output: {
537
+ schema: { type: 'json' },
538
+ /** @author ddj 2026年11月15号 @param _args 参数 @param value 结果 @returns 模型可见内容 */
539
+ render(_args: unknown, value: unknown) {
540
+ return [{ type: 'text', text: toolJsonText(value) }]
541
+ },
542
+ },
543
+ isConcurrencySafe: () => spec.safe,
544
+ /** @author ddj 2026年11月15号 @param args 参数 @param exec 执行上下文 @returns 工具结果 */
545
+ execute: (args: unknown, exec: ToolExec) => spec.execute((args ?? {}) as Record<string, unknown>, exec, api),
546
+ }
547
+ }
548
+
549
+ /**
550
+ * 注册全部 SVN 工具(每个工具独立 disposer,随插件卸载回收)。
551
+ * @author ddj 2026年11月15号
552
+ * @param ctx host 插件上下文
553
+ * @param api 工具执行 API
554
+ */
555
+ export async function installSvnTools(ctx: Ctx, api: SvnToolApi): Promise<void> {
556
+ const module = await loadHostModule('@deepseek-ai/dsh-tools') as { defineTool: (options: unknown) => unknown }
557
+ const tools = ctx.get('tools') as { register: (definition: unknown) => () => void } | null | undefined
558
+ if (!tools || typeof tools.register !== 'function') return
559
+ for (const spec of TOOL_SPECS) {
560
+ const definition = module.defineTool(optionsOf(spec, api))
561
+ ctx.effect(() => tools.register(definition), 'vscode-mode:svn-tool-' + spec.name)
562
+ }
563
+ }
564
+
565
+ /** 已注册的工具名清单(测试/诊断用)。 */
566
+ export const SVN_TOOL_NAMES: readonly string[] = TOOL_SPECS.map((spec) => spec.name)