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,181 @@
1
+ /**
2
+ * dsh-vscode-mode client — 底部栏的「验收 x/y」chip。
3
+ *
4
+ * 与 HTML 计划模式 chip 共用 `conversation.input.left` 列表槽(官方计划 chip 占着
5
+ * `conversation.input.plan`,不去抢):模式活跃时出现,计数来自 `edrv.testCheck.get`
6
+ * 的派生视图,点开在「文件编辑」里打开验收单页签。
7
+ * @author ddj 2026年11月25号
8
+ */
9
+ import React from 'react'
10
+ import { log } from '../log.js'
11
+ import { rpc } from '../rpc.js'
12
+ import { requestOpen } from '../openReceipt.js'
13
+ import { TEST_CHECK_CHIP_MS, TEST_CHECK_MODE_KEY } from '../../shared/testCheck.js'
14
+
15
+ //region 结构面
16
+
17
+ /** chip 组件 props(slot 标准 props)。 */
18
+ export interface CheckChipProps {
19
+ /** 当前会话。 */
20
+ sessionId?: string
21
+ /** 官方标准 kit:按 key 读会话投影。 */
22
+ useProjection?: (key: string) => unknown
23
+ /** 输入框是否锁定。 */
24
+ locked?: boolean
25
+ }
26
+
27
+ /** slots 服务最小结构面。 */
28
+ interface SlotsLike {
29
+ inject: (name: string, register: () => unknown) => unknown
30
+ register: (spec: unknown, render: unknown) => unknown
31
+ }
32
+
33
+ /** 客户端上下文最小结构面。 */
34
+ interface ChipCtx {
35
+ slots?: SlotsLike
36
+ get?: (name: string) => unknown
37
+ }
38
+
39
+ //endregion
40
+
41
+ //region 工具
42
+
43
+ /**
44
+ * 取异常的展示文案。
45
+ * @author ddj 2026年11月25号
46
+ * @param error 捕获值
47
+ * @returns 可读文本
48
+ */
49
+ function messageOf(error: unknown): string {
50
+ return error instanceof Error ? error.message : String(error ?? '未知错误')
51
+ }
52
+
53
+ //endregion
54
+
55
+ //region 组件
56
+
57
+ /**
58
+ * 底部栏 chip:模式活跃时出现,显示通过数/总数,点击打开验收单页签。
59
+ * @author ddj 2026年11月25号
60
+ * @param props slot 运行时 props
61
+ * @returns chip 元素;模式不活跃时为 null
62
+ */
63
+ export function TestCheckChip(props: CheckChipProps) {
64
+ const sessionId = String(props.sessionId ?? '')
65
+ const mode = typeof props.useProjection === 'function'
66
+ ? props.useProjection(TEST_CHECK_MODE_KEY) as { active?: boolean; id?: string } | undefined
67
+ : undefined
68
+ const sheetId = typeof mode?.id === 'string' && mode.id ? mode.id : 'check'
69
+ const active = mode?.active === true
70
+
71
+ const [tally, setTally] = React.useState('')
72
+ const [opening, setOpening] = React.useState(false)
73
+ const [note, setNote] = React.useState('')
74
+
75
+ React.useEffect(() => {
76
+ if (!active || !sessionId) {
77
+ setTally('')
78
+ return undefined
79
+ }
80
+ let alive = true
81
+ /** 读一次计数(轮询,失败保留上一次的数字)。 */
82
+ async function loadTally(): Promise<void> {
83
+ try {
84
+ const raw = await rpc('edrv.testCheck.get', { sessionId, id: sheetId })
85
+ if (!alive || !raw.ok) return
86
+ const counts = raw.view.counts
87
+ setTally(String(counts.pass) + '/' + String(counts.total))
88
+ } catch (error) {
89
+ log.warn('验收单计数读取失败:' + messageOf(error))
90
+ }
91
+ }
92
+ void loadTally()
93
+ const timer = window.setInterval(() => { void loadTally() }, TEST_CHECK_CHIP_MS)
94
+ return () => {
95
+ alive = false
96
+ window.clearInterval(timer)
97
+ }
98
+ }, [active, sessionId, sheetId])
99
+
100
+ if (!active) return null
101
+
102
+ /**
103
+ * 打开验收单页签(文件编辑内的虚拟页签)。
104
+ *
105
+ * 宿主刚重载时编辑器可能还没挂上,第一次请求会超时(真机实测);超时后等一拍再试一次,
106
+ * 仍然失败才提示用户,避免「点了没反应」被误当成模式坏了。
107
+ * @author ddj 2026年11月25号
108
+ */
109
+ async function openSheet(): Promise<void> {
110
+ if (opening) return
111
+ if (!sessionId) { setNote('当前没有活动会话'); return }
112
+ setOpening(true)
113
+ setNote('')
114
+ try {
115
+ let ok = await requestOpen(null, undefined, undefined, sessionId, {
116
+ preview: true,
117
+ sheet: { id: sheetId, title: '验收单 · ' + sheetId },
118
+ timeoutMs: 4000,
119
+ })
120
+ if (!ok) {
121
+ await new Promise((resolve) => { setTimeout(resolve, 300) })
122
+ ok = await requestOpen(null, undefined, undefined, sessionId, {
123
+ preview: true,
124
+ sheet: { id: sheetId, title: '验收单 · ' + sheetId },
125
+ timeoutMs: 4000,
126
+ })
127
+ }
128
+ if (!ok) setNote('打开失败:编辑器没有回执,请重试')
129
+ } catch (error) {
130
+ setNote('打开失败:' + messageOf(error))
131
+ }
132
+ setOpening(false)
133
+ }
134
+
135
+ return React.createElement('span', { className: 'edrv-testcheck-chip-wrap' },
136
+ React.createElement('button', {
137
+ type: 'button',
138
+ className: 'edrv-testcheck-chip',
139
+ title: '测试验收模式已开启:点开验收单(离开用 /test-check off)',
140
+ 'aria-label': '打开测试验收单',
141
+ disabled: props.locked === true || opening,
142
+ onClick: () => { void openSheet() },
143
+ },
144
+ React.createElement('span', { className: 'edrv-testcheck-chip-glyph', 'aria-hidden': true }, '✓'),
145
+ '验收 ' + (tally || '—'),
146
+ React.createElement('span', { className: 'edrv-testcheck-chip-open', 'aria-hidden': true }, '›')),
147
+ (note ? React.createElement('span', { className: 'edrv-testcheck-chip-error', role: 'status', title: note }, note) : null))
148
+ }
149
+
150
+ //endregion
151
+
152
+ //region 装配
153
+
154
+ /**
155
+ * 把 chip 装到 `conversation.input.left` 列表槽。
156
+ * @author ddj 2026年11月25号
157
+ * @param ctx 客户端上下文
158
+ * @returns 卸载函数;槽位/服务不可用时 null
159
+ */
160
+ export function installCheckChip(ctx: unknown): (() => void) | null {
161
+ const client = ctx as ChipCtx | undefined
162
+ const slots = client?.slots
163
+ if (!slots || typeof slots.inject !== 'function' || typeof slots.register !== 'function') {
164
+ log.warn('验收单 chip 未注册:slots 服务不可用')
165
+ return null
166
+ }
167
+ try {
168
+ const disposer = slots.inject('conversation.input.left', () => slots.register({
169
+ name: 'conversation.input.left',
170
+ id: 'edrv-test-check',
171
+ order: 21,
172
+ label: '验收单',
173
+ }, TestCheckChip))
174
+ return typeof disposer === 'function' ? disposer as () => void : null
175
+ } catch (error) {
176
+ log.warn('验收单 chip 注册失败(' + messageOf(error) + '),已跳过')
177
+ return null
178
+ }
179
+ }
180
+
181
+ //endregion
@@ -0,0 +1,339 @@
1
+ /**
2
+ * dsh-vscode-mode client — 测试验收单页签:汇总条 + 工具栏 + 沙箱 iframe + 建单引导。
3
+ *
4
+ * 页面内容由插件用数据渲染(`shared/testCheckHtml.ts`),不要求模型写 HTML:
5
+ * 每次轮询拿到派生视图,只有数据指纹变了才换 iframe 的 `srcDoc`,避免每秒重绘闪烁。
6
+ * 没有 `items.json` 时这里给建单引导与五语言上报片段;工具栏还提供「手动上报」小表单。
7
+ * @author ddj 2026年11月25号
8
+ */
9
+ import React from 'react'
10
+ import { log } from '../log.js'
11
+ import { rpc } from '../rpc.js'
12
+ import { itemsTemplateOf, renderSheetHtml } from '../../shared/testCheckHtml.js'
13
+ import { reportSnippets, snippetsMarkdown } from '../../shared/testCheckSnippets.js'
14
+ import {
15
+ TEST_CHECK_POLL_MS,
16
+ TEST_CHECK_STATUSES,
17
+ type TestCheckItemView,
18
+ type TestCheckView,
19
+ } from '../../shared/testCheck.js'
20
+
21
+ //region 结构面
22
+
23
+ /** 面板输入(由 EditorView 从验收单页签装配)。 */
24
+ export interface TestCheckPanelProps {
25
+ /** 当前会话。 */
26
+ sessionId?: string
27
+ /** 工作区(只用于展示,实际路径由 host 解析)。 */
28
+ cwd?: string
29
+ /** 单子 id。 */
30
+ id?: string
31
+ /** 页签标题。 */
32
+ title?: string
33
+ }
34
+
35
+ /** 状态中文名(手动上报的下拉)。 */
36
+ const STATUS_LABEL: Record<string, string> = {
37
+ pass: '通过',
38
+ fail: '失败',
39
+ blocked: '阻塞',
40
+ skip: '跳过',
41
+ }
42
+
43
+ //endregion
44
+
45
+ //region 小工具
46
+
47
+ /**
48
+ * 取异常的展示文案。
49
+ * @author ddj 2026年11月25号
50
+ * @param error 捕获值
51
+ * @returns 可读文本
52
+ */
53
+ function messageOf(error: unknown): string {
54
+ return error instanceof Error ? error.message : String(error ?? '未知错误')
55
+ }
56
+
57
+ /**
58
+ * 把文本写进剪贴板(浏览器不支持时返回 false,由调用方提示)。
59
+ * @author ddj 2026年11月25号
60
+ * @param text 文本
61
+ * @returns 是否写入成功
62
+ */
63
+ async function copyText(text: string): Promise<boolean> {
64
+ try {
65
+ if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
66
+ await navigator.clipboard.writeText(text)
67
+ return true
68
+ }
69
+ } catch {
70
+ /* 剪贴板被拒:交给调用方提示 */
71
+ }
72
+ return false
73
+ }
74
+
75
+ /**
76
+ * 把分组摊平成条目清单(手动上报的下拉用)。
77
+ * @author ddj 2026年11月25号
78
+ * @param view 派生视图
79
+ * @returns 条目清单
80
+ */
81
+ function flatItems(view: TestCheckView | null): TestCheckItemView[] {
82
+ if (!view) return []
83
+ return view.groups.flatMap((group) => group.items)
84
+ }
85
+
86
+ //endregion
87
+
88
+ //region 页面块
89
+
90
+ /**
91
+ * 汇总一句(工具栏用)。
92
+ * @author ddj 2026年11月25号
93
+ * @param view 派生视图
94
+ * @returns 一行文案;没有视图时为空串
95
+ */
96
+ function tallyOf(view: TestCheckView | null): string {
97
+ if (!view) return ''
98
+ const c = view.counts
99
+ return '通过 ' + String(c.pass) + '/' + String(c.total)
100
+ + ' · 失败 ' + String(c.fail)
101
+ + ' · 阻塞 ' + String(c.blocked)
102
+ + ' · 需复验 ' + String(c.stale)
103
+ + ' · 未验 ' + String(c.todo)
104
+ }
105
+
106
+ /**
107
+ * 建单引导:模板 + 五语言片段 + 说明(缺定义或有错时显示)。
108
+ * @author ddj 2026年11月25号
109
+ * @param props 单子 id 与复制回调
110
+ * @returns 引导元素
111
+ */
112
+ function guideOf(props: { id: string; view: TestCheckView | null; onCopy: (text: string) => void }) {
113
+ const { id, view, onCopy } = props
114
+ const template = itemsTemplateOf(id)
115
+ const snippets = snippetsMarkdown(id, view?.title ?? '')
116
+ const missing = view === null || view.state === 'missing'
117
+ return React.createElement('div', { className: 'edrv-testcheck-guide' },
118
+ React.createElement('h3', null, missing ? '还没有验收单' : 'items.json 校验没通过'),
119
+ missing
120
+ ? React.createElement('p', null, '在 ', React.createElement('code', null, '.dsh/test-check/' + id + '/items.json'),
121
+ ' 写这份定义;也可以把下面这段发给 AI 让它建单。')
122
+ : React.createElement('ul', { className: 'edrv-testcheck-errors' },
123
+ String(view?.error ?? '').split('\n').filter(Boolean).map((line, index) =>
124
+ React.createElement('li', { key: String(index) }, line))),
125
+ React.createElement('p', null, 'ID 形如 ', React.createElement('code', null, 'settings.claude-style.004'),
126
+ '(<scope>.<area>.<3 位序号>),全局唯一、只增不改号;删条目把 ', React.createElement('code', null, 'retired'), ' 置 true。'),
127
+ React.createElement('pre', { className: 'edrv-testcheck-pre' }, template),
128
+ React.createElement('div', { className: 'edrv-testcheck-actions' },
129
+ React.createElement('button', { className: 'edrv-pill edrv-pill-ghost', onClick: () => onCopy(template) }, '复制 items.json 模板'),
130
+ React.createElement('button', { className: 'edrv-pill edrv-pill-ghost', onClick: () => onCopy(snippets) }, '复制上报片段')),
131
+ React.createElement('p', null, '结果不用写进定义:每次验证往 ',
132
+ React.createElement('code', null, '.dsh/test-check/' + id + '/events/'), ' 写一个 JSON 文件;必填只有 ',
133
+ React.createElement('code', null, 'item'), ' 与 ', React.createElement('code', null, 'status'),
134
+ ',没有 ', React.createElement('code', null, 'evidence'), ' 的 pass 不算通过。'),
135
+ React.createElement('details', { className: 'edrv-testcheck-details' },
136
+ React.createElement('summary', null, '各语言上报片段(C# / Lua / Python / bash / Node)'),
137
+ reportSnippets(id).map((snippet) => React.createElement('div', { key: snippet.id, className: 'edrv-testcheck-snippet' },
138
+ React.createElement('div', { className: 'edrv-testcheck-snippet-head' },
139
+ React.createElement('span', null, snippet.label),
140
+ React.createElement('button', {
141
+ className: 'edrv-pill edrv-pill-ghost',
142
+ onClick: () => onCopy(snippet.code),
143
+ }, '复制')),
144
+ React.createElement('pre', { className: 'edrv-testcheck-pre' }, snippet.code)))))
145
+ }
146
+
147
+ /**
148
+ * 手动上报小表单(页面不放决策控件,勾选在页签这一侧做)。
149
+ * @author ddj 2026年11月25号
150
+ * @param props 条目清单、忙碌状态与提交回调
151
+ * @returns 表单元素
152
+ */
153
+ function manualFormOf(props: {
154
+ items: TestCheckItemView[]
155
+ busy: boolean
156
+ onSubmit: (item: string, status: string, summary: string) => void
157
+ }) {
158
+ const [item, setItem] = React.useState('')
159
+ const [status, setStatus] = React.useState('pass')
160
+ const [summary, setSummary] = React.useState('')
161
+ const current = item || props.items[0]?.id || ''
162
+ return React.createElement('div', { className: 'edrv-testcheck-manual' },
163
+ React.createElement('select', { value: current, onChange: (event: React.ChangeEvent<HTMLSelectElement>) => setItem(event.target.value) },
164
+ props.items.map((row) => React.createElement('option', { key: row.id, value: row.id },
165
+ row.id + ' · ' + row.title))),
166
+ React.createElement('select', { value: status, onChange: (event: React.ChangeEvent<HTMLSelectElement>) => setStatus(event.target.value) },
167
+ TEST_CHECK_STATUSES.map((value) => React.createElement('option', { key: value, value }, STATUS_LABEL[value] ?? value))),
168
+ React.createElement('input', {
169
+ className: 'edrv-testcheck-input',
170
+ placeholder: '证据一句话:测试名 / 命令 / 日志路径',
171
+ value: summary,
172
+ onChange: (event: React.ChangeEvent<HTMLInputElement>) => setSummary(event.target.value),
173
+ }),
174
+ React.createElement('button', {
175
+ className: 'edrv-pill edrv-pill-accent',
176
+ disabled: props.busy || !current || !summary.trim(),
177
+ onClick: () => props.onSubmit(current, status, summary.trim()),
178
+ }, '上报'))
179
+ }
180
+
181
+ //endregion
182
+
183
+ //region 组件
184
+
185
+ /**
186
+ * 验收单页签。
187
+ * @author ddj 2026年11月25号
188
+ * @param props 会话、工作区、单子 id 与标题
189
+ * @returns 页签正文
190
+ */
191
+ export function TestCheckPanel(props: TestCheckPanelProps) {
192
+ const sessionId = String(props.sessionId ?? '')
193
+ const sheetId = String(props.id ?? 'check')
194
+ const [view, setView] = React.useState<TestCheckView | null>(null)
195
+ const [error, setError] = React.useState('')
196
+ const [notice, setNotice] = React.useState('')
197
+ const [busy, setBusy] = React.useState(false)
198
+ const [manual, setManual] = React.useState(false)
199
+ const alive = React.useRef(true)
200
+
201
+ /**
202
+ * 读一次视图(轮询与按钮共用)。
203
+ * @author ddj 2026年11月25号
204
+ * @param force 是否跳过 host 缓存
205
+ */
206
+ async function loadView(force = false): Promise<void> {
207
+ try {
208
+ const raw = await rpc('edrv.testCheck.get', { sessionId, id: sheetId, force })
209
+ if (!alive.current) return
210
+ if (raw.ok) {
211
+ setView(raw.view)
212
+ setError('')
213
+ } else {
214
+ setError(String(raw.error ?? '读取失败'))
215
+ }
216
+ } catch (cause) {
217
+ if (alive.current) setError(messageOf(cause))
218
+ log.warn('验收单读取失败:' + messageOf(cause))
219
+ }
220
+ }
221
+
222
+ React.useEffect(() => {
223
+ alive.current = true
224
+ void loadView(true)
225
+ const timer = window.setInterval(() => { void loadView(false) }, TEST_CHECK_POLL_MS)
226
+ return () => {
227
+ alive.current = false
228
+ window.clearInterval(timer)
229
+ }
230
+ // eslint-disable-next-line react-hooks/exhaustive-deps
231
+ }, [sessionId, sheetId])
232
+
233
+ /** 复制并提示(失败时说清原因,不静默)。 */
234
+ async function copyAndNotify(text: string): Promise<void> {
235
+ const ok = await copyText(text)
236
+ setNotice(ok ? '已复制到剪贴板' : '复制失败:浏览器拒绝了剪贴板写入,请手动选中复制')
237
+ }
238
+
239
+ /** 导出快照到 docs/acceptance-<id>.html。 */
240
+ async function exportSheet(): Promise<void> {
241
+ if (busy) return
242
+ setBusy(true)
243
+ try {
244
+ const raw = await rpc('edrv.testCheck.snapshot', { sessionId, id: sheetId })
245
+ setNotice(raw.ok ? '快照已导出:' + raw.path : '导出失败:' + String(raw.error ?? '未知原因'))
246
+ if (raw.ok) setView(raw.view)
247
+ } catch (cause) {
248
+ setNotice('导出失败:' + messageOf(cause))
249
+ }
250
+ setBusy(false)
251
+ }
252
+
253
+ /**
254
+ * 手动上报一条结果。
255
+ * @author ddj 2026年11月25号
256
+ * @param item 测试点 id
257
+ * @param status pass / fail / blocked / skip
258
+ * @param summary 证据
259
+ */
260
+ async function reportOne(item: string, status: string, summary: string): Promise<void> {
261
+ if (busy) return
262
+ setBusy(true)
263
+ try {
264
+ const raw = await rpc('edrv.testCheck.report', {
265
+ sessionId,
266
+ id: sheetId,
267
+ item,
268
+ status: status as 'pass' | 'fail' | 'blocked' | 'skip',
269
+ summary,
270
+ })
271
+ setNotice(raw.ok ? '已上报:' + item : '上报失败:' + String(raw.error ?? '未知原因'))
272
+ if (raw.ok) setView(raw.view)
273
+ } catch (cause) {
274
+ setNotice('上报失败:' + messageOf(cause))
275
+ }
276
+ setBusy(false)
277
+ }
278
+
279
+ const html = React.useMemo(
280
+ () => (view && view.state === 'ready' ? renderSheetHtml(view) : ''),
281
+ // 只按数据指纹重算:轮询拿到同内容的视图时,iframe 不重绘。
282
+ [view?.stamp, view?.state], // eslint-disable-line react-hooks/exhaustive-deps
283
+ )
284
+ const items = flatItems(view)
285
+ const ready = view?.state === 'ready'
286
+
287
+ const toolbar = React.createElement('div', { className: 'edrv-testcheck-bar' },
288
+ React.createElement('span', { className: 'edrv-testcheck-title', title: sheetId }, view?.title ?? props.title ?? sheetId),
289
+ React.createElement('span', { className: 'edrv-testcheck-tally' }, tallyOf(view)),
290
+ React.createElement('span', { style: { flex: 1 } }),
291
+ React.createElement('button', {
292
+ className: 'edrv-pill edrv-pill-ghost',
293
+ disabled: busy || !ready,
294
+ title: '打开手动上报:选条目、选状态、写一句证据',
295
+ onClick: () => setManual((value) => !value),
296
+ }, manual ? '收起上报' : '手动上报'),
297
+ React.createElement('button', {
298
+ className: 'edrv-pill edrv-pill-ghost',
299
+ disabled: busy || !ready,
300
+ title: '导出 docs/acceptance-' + sheetId + '.html(单文件,脱离 DSH 也能打开)',
301
+ onClick: () => { void exportSheet() },
302
+ }, busy ? '导出中…' : '导出快照'),
303
+ React.createElement('button', {
304
+ className: 'edrv-pill edrv-pill-ghost',
305
+ title: '立即重读(跳过 host 缓存)',
306
+ onClick: () => { void loadView(true) },
307
+ }, '⟳'))
308
+
309
+ const noticeLine = notice ? React.createElement('div', { className: 'edrv-testcheck-notice' }, notice) : null
310
+ const errorLine = error ? React.createElement('div', { className: 'edrv-testcheck-error', role: 'alert' }, error) : null
311
+
312
+ let stage
313
+ if (view === null || view.state !== 'ready') {
314
+ stage = guideOf({ id: sheetId, view, onCopy: (text) => { void copyAndNotify(text) } })
315
+ } else {
316
+ stage = React.createElement(React.Fragment, null,
317
+ view.ignored.length
318
+ ? React.createElement('div', { className: 'edrv-testcheck-notice' },
319
+ '已忽略 ' + String(view.ignored.length) + ' 个事件文件:' + view.ignored.slice(0, 3).map((row) => row.file + '(' + row.reason + ')').join(';'))
320
+ : null,
321
+ React.createElement('iframe', {
322
+ className: 'edrv-testcheck-frame',
323
+ title: view.title,
324
+ sandbox: '',
325
+ srcDoc: html,
326
+ }))
327
+ }
328
+
329
+ return React.createElement('div', { className: 'edrv-testcheck', 'data-sheet-id': sheetId },
330
+ toolbar,
331
+ (manual && ready)
332
+ ? manualFormOf({ items, busy, onSubmit: (item, status, summary) => { void reportOne(item, status, summary) } })
333
+ : null,
334
+ noticeLine,
335
+ errorLine,
336
+ stage)
337
+ }
338
+
339
+ //endregion
@@ -0,0 +1,173 @@
1
+ /**
2
+ * dsh-vscode-mode client — 侧栏「测试验收」面板的纯逻辑(无 React、无 IO,可直接单测)。
3
+ *
4
+ * 面板把「读到的数据」与本文件给出的「该怎么显示」分开:状态文案、按钮是否可点、
5
+ * 行上写什么,全在这里算;组件只负责摆位置。
6
+ * @author ddj 2026年11月26号
7
+ */
8
+ import { POLICY_MAX_BYTES } from '../shared/testCheckPolicyDefault.js'
9
+ import type { TestCheckCounts, TestCheckSheetSummary, TestCheckView } from '../shared/testCheck.js'
10
+
11
+ //region 类型
12
+
13
+ /** 规范披露状态(面板状态行与保存按钮共用)。 */
14
+ export interface PolicyView {
15
+ /** 规范文件绝对路径。 */
16
+ path: string
17
+ /** 当前生效正文。 */
18
+ text: string
19
+ /** true = 用的是默认规则。 */
20
+ isDefault: boolean
21
+ }
22
+
23
+ /** 保存按钮可用性判定入参。 */
24
+ export interface SavePolicyInput {
25
+ /** 会话工作区(没有工作区时一律不可保存)。 */
26
+ cwd?: string | null
27
+ /** 编辑框里的草稿。 */
28
+ draft: string
29
+ /** 当前生效正文(用来判断有没有改动)。 */
30
+ savedText: string
31
+ /** 当前是否在用默认规则。 */
32
+ isDefault: boolean
33
+ }
34
+
35
+ //endregion
36
+
37
+ //region 规范
38
+
39
+ /**
40
+ * 状态行文案:说清「现在用的是哪一份」和「保存会写到哪」。
41
+ * @author ddj 2026年11月26号
42
+ * @param view 规范状态
43
+ * @returns 一行文案
44
+ */
45
+ export function policyStatusText(view: PolicyView): string {
46
+ if (!view.path) return '当前使用默认规则(没有工作区,不能保存到项目)'
47
+ return view.isDefault
48
+ ? '当前使用默认规则;保存后写入 ' + view.path
49
+ : '已保存到 ' + view.path
50
+ }
51
+
52
+ /**
53
+ * 保存按钮文案:编辑框清空时语义是「删掉自定义规则,回到默认」,按钮要如实写出来。
54
+ * @author ddj 2026年11月26号
55
+ * @param draft 编辑框草稿
56
+ * @returns 按钮文案
57
+ */
58
+ export function policySaveLabel(draft: string): string {
59
+ return String(draft ?? '').trim() === '' ? '恢复默认' : '保存'
60
+ }
61
+
62
+ /**
63
+ * 保存按钮是否可点:需要工作区、需要有改动,且「已经是默认还清空」这种空操作不给点。
64
+ * @author ddj 2026年11月26号
65
+ * @param input 判定入参
66
+ * @returns 可点返回 true
67
+ */
68
+ export function canSavePolicy(input: SavePolicyInput): boolean {
69
+ if (!input.cwd) return false
70
+
71
+ const draft = String(input.draft ?? '').replace(/\r\n/g, '\n')
72
+ if (draft === String(input.savedText ?? '')) return false
73
+ if (draft.trim() === '' && input.isDefault) return false
74
+ return true
75
+ }
76
+
77
+ /**
78
+ * 规则正文的字节数(UTF-8;与宿主截断口径一致)。
79
+ * @author ddj 2026年11月26号
80
+ * @param text 规则正文
81
+ * @returns 字节数
82
+ */
83
+ export function policyBytesOf(text: string): number {
84
+ return new TextEncoder().encode(String(text ?? '')).length
85
+ }
86
+
87
+ /**
88
+ * 是否超过规则正文上限(超了会被截断,面板要提示)。
89
+ * @author ddj 2026年11月26号
90
+ * @param bytes 字节数
91
+ * @returns 超限返回 true
92
+ */
93
+ export function isPolicyOversize(bytes: number): boolean {
94
+ return Number(bytes) > POLICY_MAX_BYTES
95
+ }
96
+
97
+ /**
98
+ * 体积文案:`9.2 KB / 上限 8 KB`。
99
+ * @author ddj 2026年11月26号
100
+ * @param bytes 字节数
101
+ * @returns 一行文案
102
+ */
103
+ export function policySizeText(bytes: number): string {
104
+ const size = (Number(bytes) / 1024).toFixed(1)
105
+ return size + ' KB / 上限 ' + String(POLICY_MAX_BYTES / 1024) + ' KB'
106
+ }
107
+
108
+ //endregion
109
+
110
+ //region 验收单
111
+
112
+ /**
113
+ * 行上的计数文案(通过/总数;总数为 0 时显示「空单」)。
114
+ * @author ddj 2026年11月26号
115
+ * @param counts 汇总计数
116
+ * @returns 短文本
117
+ */
118
+ export function sheetTallyOf(counts: TestCheckCounts | null | undefined): string {
119
+ if (!counts || counts.total <= 0) return '空单'
120
+ return String(counts.pass) + '/' + String(counts.total)
121
+ }
122
+
123
+ /**
124
+ * 全部单列表行的副文案:快照缺失时提示走移除,正常时提示点开快照。
125
+ * @author ddj 2026年11月26号
126
+ * @param hasSnapshot 快照是否存在
127
+ * @returns 一行提示
128
+ */
129
+ export function sheetRowHint(hasSnapshot: boolean): string {
130
+ return hasSnapshot ? '点行打开 docs 里的快照' : '快照缺失:可先导出,或直接移除这一条'
131
+ }
132
+
133
+ /**
134
+ * 移除确认弹窗正文:把要删的两个路径写清楚,别让人点到后悔。
135
+ * @author ddj 2026年11月26号
136
+ * @param title 单子标题
137
+ * @param dir 单子目录
138
+ * @param snapshotPath 快照路径
139
+ * @returns 多行确认文案
140
+ */
141
+ export function removeConfirmText(title: string, dir: string, snapshotPath: string): string {
142
+ return '移除验收单「' + title + '」?\n\n会删除:\n' + dir + '\n' + snapshotPath + '\n\n删除后不能恢复。'
143
+ }
144
+
145
+ /**
146
+ * 把当前单的最新计数合并进「全部验收单」那一行(轮询后本地更新,不再请求列表)。
147
+ *
148
+ * 计数与标题都没变时返回原数组引用,避免每 2.5 秒无谓重渲染。
149
+ * @author ddj 2026年11月26号
150
+ * @param rows 当前列表行
151
+ * @param view 当前单的派生视图(null 表示没有)
152
+ * @returns 新的行数组(无变化时是原引用)
153
+ */
154
+ export function mergeSheetCounts(
155
+ rows: readonly TestCheckSheetSummary[],
156
+ view: TestCheckView | null,
157
+ ): readonly TestCheckSheetSummary[] {
158
+ if (!view) return rows
159
+ const target = rows.find((row) => row.id === view.id)
160
+ if (!target) return rows
161
+
162
+ const before = target.counts
163
+ const after = view.counts
164
+ const unchanged = target.title === view.title
165
+ && before.total === after.total && before.pass === after.pass
166
+ && before.fail === after.fail && before.blocked === after.blocked
167
+ && before.todo === after.todo && before.stale === after.stale
168
+ if (unchanged) return rows
169
+
170
+ return rows.map((row) => (row.id === view.id ? { ...row, counts: after, title: view.title } : row))
171
+ }
172
+
173
+ //endregion