dsh-vscode-mode 0.38.0 → 0.40.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 (66) hide show
  1. package/README.md +38 -33
  2. package/lib/client.js +87 -68
  3. package/lib/client.js.map +1 -1
  4. package/lib/index.js +11406 -4920
  5. package/lib/index.js.map +1 -1
  6. package/package.json +3 -2
  7. package/skills/dsh-vscodemode-html-plan/SKILL.md +44 -42
  8. package/skills/dsh-vscodemode-test-check/SKILL.md +82 -0
  9. package/src/archiveDb.ts +24 -0
  10. package/src/attachmentBytes.ts +84 -0
  11. package/src/client/htmlPlan/HtmlPlanModeChip.ts +181 -0
  12. package/src/client/htmlPlan/HtmlPlanPanel.ts +230 -61
  13. package/src/client/htmlPlan/planActions.ts +38 -8
  14. package/src/client/htmlPlan/planPage.ts +111 -9
  15. package/src/client/index.ts +9 -0
  16. package/src/client/openReceipt.ts +5 -2
  17. package/src/client/planBridge.ts +27 -2
  18. package/src/client/planState.ts +51 -4
  19. package/src/client/sidebar/panels/TestCheckPanel.ts +485 -0
  20. package/src/client/sidebar/panels/useTestCheckData.ts +414 -0
  21. package/src/client/sidebar/types.ts +2 -0
  22. package/src/client/state/diffSummary.ts +3 -0
  23. package/src/client/styles/editor.css +91 -0
  24. package/src/client/testCheck/TestCheckChip.ts +181 -0
  25. package/src/client/testCheck/TestCheckPanel.ts +339 -0
  26. package/src/client/testCheckPanelState.ts +173 -0
  27. package/src/client/ui/EditorView.ts +77 -7
  28. package/src/client/ui/McpSettings.ts +2 -2
  29. package/src/client/ui/OfficialReview.ts +6 -4
  30. package/src/htmlPlanAttachments.ts +4 -1
  31. package/src/htmlPlanCommand.ts +87 -235
  32. package/src/htmlPlanGuidance.ts +67 -0
  33. package/src/htmlPlanMode.ts +547 -0
  34. package/src/index.ts +28 -55
  35. package/src/officialCapture.ts +58 -9
  36. package/src/pending/externalCapture.ts +195 -401
  37. package/src/pending/kernel.ts +24 -1
  38. package/src/pending/persist.ts +109 -22
  39. package/src/pending/provenance.ts +5 -28
  40. package/src/pending/store.ts +109 -100
  41. package/src/pending/tracking.ts +81 -0
  42. package/src/pendingCompat.ts +26 -1
  43. package/src/pendingRpc.ts +8 -56
  44. package/src/planAutoPage.ts +306 -0
  45. package/src/planPagePack.ts +148 -0
  46. package/src/registry.ts +7 -2
  47. package/src/reviewDb.ts +1 -1
  48. package/src/reviewRpc.ts +14 -6
  49. package/src/rpc.ts +34 -0
  50. package/src/shared/htmlPlanMode.ts +26 -0
  51. package/src/shared/pendingReview.ts +15 -7
  52. package/src/shared/review.ts +5 -0
  53. package/src/shared/rpc.ts +53 -7
  54. package/src/shared/testCheck.ts +759 -0
  55. package/src/shared/testCheckHtml.ts +276 -0
  56. package/src/shared/testCheckPolicyDefault.ts +37 -0
  57. package/src/shared/testCheckSnippets.ts +197 -0
  58. package/src/store.ts +17 -1
  59. package/src/testCheckCommand.ts +287 -0
  60. package/src/testCheckGuidance.ts +79 -0
  61. package/src/testCheckMode.ts +654 -0
  62. package/src/testCheckPolicy.ts +141 -0
  63. package/src/testCheckRpc.ts +196 -0
  64. package/src/testCheckStore.ts +822 -0
  65. package/src/pending/externalAlign.ts +0 -297
  66. package/src/pending/vcs.ts +0 -584
@@ -0,0 +1,287 @@
1
+ /**
2
+ * dsh-vscode-mode host — `/test-check [off|任务]` 命令:进入/离开测试验收模式。
3
+ *
4
+ * 命令只负责三件事:切模式(投影折叠命令事件)、建好单子目录、把任务与上报说明送进会话;
5
+ * 规则由 `test-check:policy` 系统提示段落每请求提供(见 `testCheckGuidance.ts`)。
6
+ *
7
+ * 附件与 `/html-plan` 同一套落盘方式,只是目标目录换成 `.dsh/test-check/<id>/assets/`:
8
+ * 验收单里引用截图/日志时,路径是相对项目根写的,所以 AI 能直接把证据挂到条目上。
9
+ * @author ddj 2026年11月25号
10
+ */
11
+ import { existsSync } from 'node:fs'
12
+ import { mkdir, writeFile } from 'node:fs/promises'
13
+ import { dirname, join } from 'node:path'
14
+ import { cwdOfSession, type Ctx } from './store.js'
15
+ import { ensureSheet } from './testCheckStore.js'
16
+ import { stageAttachments, type AttachmentStage } from './htmlPlanAttachments.js'
17
+ import { readChunks, rollbackFiles, toBytes } from './attachmentBytes.js'
18
+ import {
19
+ TEST_CHECK_BASE_DIR,
20
+ TEST_CHECK_COMMAND,
21
+ TEST_CHECK_EVENTS,
22
+ TEST_CHECK_ITEMS,
23
+ parseCheckInput,
24
+ testCheckIdOf,
25
+ } from './shared/testCheck.js'
26
+
27
+ //region 结构面
28
+
29
+ /** 命令描述(出现在 / 菜单与命令目录)。 */
30
+ export const TEST_CHECK_DESCRIPTION = '进入或离开测试验收模式:/test-check [off|任务](可附图片或文件)'
31
+
32
+ /** 官方命令调用(只声明本命令用到的字段)。 */
33
+ export interface CheckInvocation {
34
+ /** 接收命令的 agent。 */
35
+ agent?: { steer?: (message: unknown) => unknown; session?: unknown }
36
+ /** 命令名之后的原始输入。 */
37
+ rawInput?: unknown
38
+ /** 取消信号。 */
39
+ signal?: AbortSignal
40
+ /** 已入库的图片/文件块(未声明 attachments 时为空)。 */
41
+ attachments?: readonly unknown[]
42
+ }
43
+
44
+ /** 附件准备结果。 */
45
+ export interface CheckStage {
46
+ /** 追加到任务消息里的说明段。 */
47
+ lines: string[]
48
+ /** 命令失败时回滚本次写入的附件。 */
49
+ rollback: () => Promise<void>
50
+ }
51
+
52
+ /** 安装选项(测试可替换消息构造与附件准备)。 */
53
+ export interface CheckCommandOptions {
54
+ /** 把纯文本包成宿主用户消息(由模式装配层注入 createUserMessage)。 */
55
+ buildUserMessage?: (text: string) => unknown
56
+ /** 附件准备(默认落盘到 `.dsh/test-check/<id>/assets/`);测试可替换。 */
57
+ prepareAttachments?: (invocation: CheckInvocation, id: string) => Promise<CheckStage>
58
+ /** 宿主上下文:取 attachments 服务与会话工作区。 */
59
+ hostCtx?: unknown
60
+ }
61
+
62
+ /** 附件存储服务最小结构面。 */
63
+ interface AttachmentStoreLike {
64
+ readImage?: (ref: unknown, signal?: AbortSignal) => Promise<{ data?: unknown }>
65
+ readFileStream?: (ref: unknown, signal?: AbortSignal) => AsyncIterable<Uint8Array>
66
+ }
67
+
68
+ //endregion
69
+
70
+ //region 工具
71
+
72
+ /**
73
+ * 取异常的展示文案。
74
+ * @author ddj 2026年11月25号
75
+ * @param error 捕获值
76
+ * @returns 可读文案
77
+ */
78
+ function messageOf(error: unknown): string {
79
+ if (error instanceof Error) return error.message
80
+ return String(error ?? '未知错误')
81
+ }
82
+
83
+ /**
84
+ * 取会话工作区(宿主未注入会话时返回 null)。
85
+ * @author ddj 2026年11月25号
86
+ * @param hostCtx 宿主上下文
87
+ * @param session 会话
88
+ * @returns 工作区绝对路径或 null
89
+ */
90
+ function cwdOf(hostCtx: unknown, session: unknown): string | null {
91
+ const ctx = hostCtx as { get?: (name: string) => unknown } | undefined
92
+ if (!ctx || typeof ctx.get !== 'function' || !session) return null
93
+ try {
94
+ return cwdOfSession(ctx as Ctx, session as never)
95
+ } catch {
96
+ return null
97
+ }
98
+ }
99
+
100
+ /**
101
+ * 生成附件说明段(验收单是数据驱动的,附件只作为证据路径引用)。
102
+ * @author ddj 2026年11月25号
103
+ * @param stage 落盘结果
104
+ * @param id 单子 id
105
+ * @returns 逐行文本
106
+ */
107
+ function attachLines(stage: AttachmentStage, id: string): string[] {
108
+ const lines: string[] = []
109
+ if (stage.files.length) {
110
+ lines.push('附件已保存到 ' + TEST_CHECK_BASE_DIR + '/' + id + '/assets/(验收时可直接引用路径当证据):')
111
+ for (const file of stage.files) lines.push('- ' + file.relativePath + '(' + (file.kind === 'image' ? '图片' : '文件') + ')')
112
+ }
113
+ if (stage.skipped.length) {
114
+ lines.push('以下附件没能落盘,本次不要引用:')
115
+ for (const item of stage.skipped) lines.push('- ' + item.name + ':' + item.reason)
116
+ }
117
+ return lines
118
+ }
119
+
120
+ //endregion
121
+
122
+ //region 附件落盘
123
+
124
+ /**
125
+ * 默认附件准备:把 composer 的图片/文件复制到 `.dsh/test-check/<id>/assets/`。
126
+ *
127
+ * 任何失败都降级成说明行,不阻断进入模式;只有命令最终失败时才回滚本次写入。
128
+ * @author ddj 2026年11月25号
129
+ * @param hostCtx 宿主上下文
130
+ * @param invocation 官方命令调用
131
+ * @param id 单子 id
132
+ * @returns 附件准备结果
133
+ */
134
+ export async function stageCheckFiles(hostCtx: unknown, invocation: CheckInvocation, id: string): Promise<CheckStage> {
135
+ const empty: CheckStage = { lines: [], rollback: async () => {} }
136
+ const blocks = Array.isArray(invocation?.attachments) ? invocation.attachments.filter(Boolean) : []
137
+ if (!blocks.length) return empty
138
+
139
+ const ctx = hostCtx as { get?: (name: string) => unknown } | undefined
140
+ const workspace = cwdOf(hostCtx, invocation?.agent?.session)
141
+ const store = ctx && typeof ctx.get === 'function' ? ctx.get('attachments') as AttachmentStoreLike | undefined : undefined
142
+ const readImage = store?.readImage
143
+ const readFileStream = store?.readFileStream
144
+ if (!workspace || typeof readImage !== 'function' || typeof readFileStream !== 'function') {
145
+ return {
146
+ lines: ['附件读取失败:当前会话没有可用工作区或附件存储;本次按无附件验收。'],
147
+ rollback: async () => {},
148
+ }
149
+ }
150
+
151
+ try {
152
+ const stage = await stageAttachments({
153
+ blocks,
154
+ slug: id,
155
+ root: TEST_CHECK_BASE_DIR + '/' + id,
156
+ signal: invocation.signal,
157
+ readImage: async (ref, signal) => toBytes((await readImage(ref, signal)).data),
158
+ readFile: async (ref, signal) => readChunks(readFileStream(ref, signal)),
159
+ write: async (relativePath, bytes) => {
160
+ const absolute = join(workspace, relativePath)
161
+ await mkdir(dirname(absolute), { recursive: true })
162
+ await writeFile(absolute, bytes)
163
+ },
164
+ })
165
+ return { lines: attachLines(stage, id), rollback: () => rollbackFiles(workspace, stage) }
166
+ } catch (error) {
167
+ return { lines: ['附件读取失败:' + messageOf(error) + ';本次按无附件验收。'], rollback: async () => {} }
168
+ }
169
+ }
170
+
171
+ /**
172
+ * 回滚但不覆盖原始错误。
173
+ * @author ddj 2026年11月25号
174
+ * @param stage 附件准备结果(可能为空)
175
+ * @returns 完成后的 Promise
176
+ */
177
+ async function rollbackOf(stage: CheckStage | null): Promise<void> {
178
+ if (!stage) return
179
+ try {
180
+ await stage.rollback()
181
+ } catch {
182
+ /* 收尾失败不影响错误上报 */
183
+ }
184
+ }
185
+
186
+ //endregion
187
+
188
+ //region 消息
189
+
190
+ /**
191
+ * 拼送给模型的任务消息:任务原文 + 单子路径 + 上报约定 + 附件说明。
192
+ * @author ddj 2026年11月25号
193
+ * @param task 任务文本
194
+ * @param id 单子 id
195
+ * @param stage 附件准备结果
196
+ * @returns 用户消息文本
197
+ */
198
+ export function checkMessage(task: string, id: string, stage: CheckStage | null): string {
199
+ const lines: string[] = []
200
+ if (task) lines.push(task)
201
+ if (lines.length) lines.push('')
202
+ lines.push('验收单 id:' + id)
203
+ lines.push('定义:' + TEST_CHECK_BASE_DIR + '/' + id + '/' + TEST_CHECK_ITEMS + '(不存在就先建单;ID 形如 settings.claude-style.004)')
204
+ lines.push('上报:test_check_report(item / status / summary 必填,summary 就是证据;status 用 pass / fail / blocked / skip)')
205
+ lines.push('项目规则:' + TEST_CHECK_BASE_DIR + '/policy.md(可选,用户可自己写;写进规则段,改完当次请求生效)')
206
+ lines.push('结果目录:' + TEST_CHECK_BASE_DIR + '/' + id + '/' + TEST_CHECK_EVENTS + '/(每条一个 JSON 文件)')
207
+ lines.push('收尾:test_check_finish,把验收单导出到 docs/acceptance-' + id + '.html')
208
+ lines.push('离开模式:/test-check off')
209
+ if (stage?.lines.length) {
210
+ lines.push('')
211
+ lines.push(...stage.lines)
212
+ }
213
+ return lines.join('\n')
214
+ }
215
+
216
+ //endregion
217
+
218
+ //region 命令定义
219
+
220
+ /**
221
+ * 构造 `/test-check` 命令定义(导出便于单测直接调用 handler)。
222
+ * @author ddj 2026年11月25号
223
+ * @param options 安装选项
224
+ * @returns 官方 CommandDefinition 形状对象
225
+ */
226
+ export function checkCommand(options: CheckCommandOptions = {}): unknown {
227
+ const prepare = typeof options.prepareAttachments === 'function'
228
+ ? options.prepareAttachments
229
+ : (invocation: CheckInvocation, id: string) => stageCheckFiles(options.hostCtx, invocation, id)
230
+ return {
231
+ name: TEST_CHECK_COMMAND,
232
+ description: TEST_CHECK_DESCRIPTION,
233
+ input: { hint: '[off|任务](可附图片或文件)', attachments: true },
234
+ /** @private @author ddj 2026年11月25号 @param invocation 官方命令调用。 @returns 成功/错误结算。 */
235
+ handler: async (invocation: CheckInvocation) => {
236
+ const parsed = parseCheckInput(invocation?.rawInput)
237
+ const blocks = Array.isArray(invocation?.attachments) ? invocation.attachments.filter(Boolean) : []
238
+
239
+ if (parsed.action === 'off') {
240
+ if (blocks.length) return { kind: 'error', text: '离开测试验收模式不能附带图片或文件' }
241
+ return { kind: 'success', text: '测试验收模式已关闭。' }
242
+ }
243
+
244
+ const workspace = cwdOf(options.hostCtx, invocation?.agent?.session)
245
+ if (!workspace) return { kind: 'error', text: '无法进入测试验收模式:当前会话没有可用工作区' }
246
+
247
+ const id = testCheckIdOf(parsed.task)
248
+ let created: boolean
249
+ try {
250
+ const ensured = await ensureSheet({ cwd: workspace, id })
251
+ created = ensured.created
252
+ } catch (error) {
253
+ return { kind: 'error', text: '无法创建验收单目录:' + messageOf(error) }
254
+ }
255
+
256
+ let stage: CheckStage | null = null
257
+ try {
258
+ stage = await prepare(invocation, id)
259
+ } catch (error) {
260
+ stage = { lines: ['附件读取失败:' + messageOf(error)], rollback: async () => {} }
261
+ }
262
+
263
+ const text = checkMessage(parsed.task, id, stage)
264
+ const steer = invocation?.agent?.steer
265
+ const build = options.buildUserMessage
266
+ if (typeof steer !== 'function' || typeof build !== 'function') {
267
+ await rollbackOf(stage)
268
+ return { kind: 'error', text: '无法把任务送进会话:宿主缺少消息构造或 steer 能力' }
269
+ }
270
+ try {
271
+ steer.call(invocation.agent, build(text))
272
+ } catch (error) {
273
+ await rollbackOf(stage)
274
+ return { kind: 'error', text: '无法把任务送进会话:' + messageOf(error) }
275
+ }
276
+
277
+ const hasItems = existsSync(join(workspace, TEST_CHECK_BASE_DIR, id, TEST_CHECK_ITEMS))
278
+ const saved = stage && stage.lines.length && stage.lines[0].startsWith('附件已保存') ? '(附件已落盘)' : ''
279
+ const head = created || !hasItems
280
+ ? '测试验收模式已开启:验收单 ' + id + ' 还没建单,按提示先写 items.json。'
281
+ : '测试验收模式已开启:验收单 ' + id + '。'
282
+ return { kind: 'success', text: head + saved + ' 离开用 /test-check off。' }
283
+ },
284
+ }
285
+ }
286
+
287
+ //endregion
@@ -0,0 +1,79 @@
1
+ /**
2
+ * dsh-vscode-mode host — 测试验收模式的规则文本(纯函数,无 IO)。
3
+ *
4
+ * 结构照 `htmlPlanGuidance.ts`:规则段落首次进入后常驻,首句限定「只在模式活跃时适用」;
5
+ * 状态段落每个请求按活跃状态给一句话。规则里写死「必须带证据上报」——这是这个模式存在的理由。
6
+ * @author ddj 2026年11月25号
7
+ */
8
+
9
+ //region 常量
10
+
11
+ /** 规则段落首句:与其他模式的 policy 段同款范围限定。 */
12
+ export const TEST_CHECK_SCOPE = 'The following instructions apply only while test-check mode is active.'
13
+
14
+ /** 模式活跃时的状态句。 */
15
+ export const TEST_CHECK_STATUS_ACTIVE = 'Test-check mode is active. Every item must be reported with evidence.'
16
+
17
+ /** 模式退出后的状态句。 */
18
+ export const TEST_CHECK_STATUS_INACTIVE = 'Test-check mode is inactive. The test-check instructions no longer apply.'
19
+
20
+ //endregion
21
+
22
+ //region 规则正文
23
+
24
+ /**
25
+ * 规则正文(不含首句范围限定)。
26
+ * @author ddj 2026年11月25号
27
+ * @returns 多行规则文本
28
+ */
29
+ export function testCheckRulesText(): string {
30
+ return [
31
+ '测试验收模式已开启(独立模式,与 /plan、/html-plan 并列,互不覆盖)。',
32
+ '',
33
+ '目标:把这次任务的验收点逐条验掉,结果落在验收单里,人和 AI 看到的是同一份状态。',
34
+ '',
35
+ '规则:',
36
+ '1. 先看验收单:<项目根>/.dsh/test-check/<id>/items.json;没有就用 write 按模板建单,',
37
+ ' 测试点 ID 形如 settings.claude-style.004(<scope>.<area>.<3 位序号>),全局唯一、只增不改号。',
38
+ '2. 每验一项必须调用 test_check_report 上报,且必须带证据:summary 至少写清测试名、命令或日志路径。',
39
+ '3. 不许口头通过:没跑过就不许报 pass;跑不起来就报 blocked 并在 summary 里写清卡在哪。',
40
+ '4. 全部验完调用 test_check_finish:导出 docs/acceptance-<id>.html,模式随之退出。',
41
+ ' 还要留在模式里补验就带 stay: true;手动退出用 /test-check off(底部栏 chip 等价)。',
42
+ '5. 模式退出后不要再上报;下次同一任务再进来会回到同一张单(id 由任务文本派生)。',
43
+ '不要调用 exit_plan_mode / exit_html_plan_mode:那是另外两个模式的工具。',
44
+ ].join('\n')
45
+ }
46
+
47
+ /**
48
+ * 规则段落正文:首次进入后常驻,用首句限定适用范围。
49
+ *
50
+ * 项目级规则拼在内建规则后面,标一个来源标题:来自文件时写文件路径,
51
+ * 来自默认规则时说明「左侧面板可改」,让模型知道这段要求是谁定的。
52
+ * @author ddj 2026年11月25号 / 2026年11月26号
53
+ * @param overlay 生效的项目级规则正文(默认规则或文件内容)
54
+ * @param fromFile 是否来自 `.dsh/test-check/policy.md`(false = 默认规则)
55
+ * @returns 可直接作为 systemPrompt section 文本的多行字符串
56
+ */
57
+ export function testCheckPolicyText(overlay = '', fromFile = true): string {
58
+ const base = TEST_CHECK_SCOPE + '\n\n' + testCheckRulesText()
59
+ const extra = String(overlay ?? '').trim()
60
+ if (!extra) return base
61
+ const heading = fromFile
62
+ ? '### 项目自己的验收规则(来自 .dsh/test-check/policy.md)'
63
+ : '### 项目测试规范(默认规则;左侧「测试验收」面板可改)'
64
+ return base + '\n\n' + heading + '\n\n' + extra
65
+ }
66
+
67
+ /**
68
+ * 状态段落正文:未进入过模式时为空;进入过则按活跃状态二选一。
69
+ * @author ddj 2026年11月25号
70
+ * @param entered 是否进入过测试验收模式
71
+ * @param active 当前是否活跃
72
+ * @returns 一行状态文本;未进入时为空串
73
+ */
74
+ export function testCheckStatusText(entered: boolean, active: boolean): string {
75
+ if (!entered) return ''
76
+ return active ? TEST_CHECK_STATUS_ACTIVE : TEST_CHECK_STATUS_INACTIVE
77
+ }
78
+
79
+ //endregion