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,306 @@
1
+ /**
2
+ * dsh-vscode-mode host — HTML 计划模式的「兜底页」渲染。
3
+ *
4
+ * 模型不写作者页(或写失败)时,用提交给 `exit_html_plan_mode` 的计划 Markdown 生成一页
5
+ * htmlplan 风格的独立 HTML:内联技能运行时样式与脚本,支持标题/段落/列表/代码/引用/表格。
6
+ * 只求「有页可读」,不产出主张树与决策控件。
7
+ *
8
+ * 运行时资产(`htmlplan.css` / `htmlplan.js`)从随包技能目录读取并缓存;本模块不写盘。
9
+ * @author ddj 2026年11月25号
10
+ */
11
+ import { readFile } from 'node:fs/promises'
12
+ import { join } from 'node:path'
13
+ import { skillsDirOf } from './paths.js'
14
+
15
+ //region 结构面
16
+
17
+ /** 计划运行时资产。 */
18
+ export interface PlanRuntimeAssets {
19
+ /** htmlplan.css 原文。 */
20
+ css: string
21
+ /** htmlplan.js 原文。 */
22
+ js: string
23
+ }
24
+
25
+ //endregion
26
+
27
+ //region 常量
28
+
29
+ /** 计划正文上限:超过直接报错,避免把超大文本塞进 iframe。 */
30
+ export const AUTO_PAGE_MARKDOWN_CAP = 256 * 1024
31
+
32
+ /** 技能名(随包目录)。 */
33
+ const SKILL_DIR = 'dsh-vscodemode-html-plan'
34
+
35
+ /** 计划页标记行(作者页声明),自动页里必须剥掉。 */
36
+ const PAGE_MARK_LINE = /^[ \t]*HTML[ \t]*计划页[ \t]*[::].*$/gim
37
+
38
+ //endregion
39
+
40
+ //region 运行时资产
41
+
42
+ let assetsCache: Promise<PlanRuntimeAssets> | null = null
43
+
44
+ /**
45
+ * 读取技能自带的 htmlplan 运行时(进程内缓存;失败不缓存,便于重试)。
46
+ * @author ddj 2026年11月25号
47
+ * @returns 样式与脚本原文
48
+ */
49
+ export function planRuntimeAssets(): Promise<PlanRuntimeAssets> {
50
+ if (!assetsCache) {
51
+ const dir = join(skillsDirOf(import.meta.url), SKILL_DIR, 'runtime')
52
+ assetsCache = Promise.all([
53
+ readFile(join(dir, 'htmlplan.css'), 'utf8'),
54
+ readFile(join(dir, 'htmlplan.js'), 'utf8'),
55
+ ]).then(([css, js]) => ({ css, js })).catch((error: unknown) => {
56
+ assetsCache = null
57
+ throw error
58
+ })
59
+ }
60
+ return assetsCache
61
+ }
62
+
63
+ //endregion
64
+
65
+ //region Markdown 子集渲染
66
+
67
+ /** Markdown 子集里会用到的转义。 */
68
+ const ESCAPES: Record<string, string> = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }
69
+
70
+ /**
71
+ * HTML 转义。
72
+ * @author ddj 2026年11月25号
73
+ * @param text 原文本
74
+ * @returns 可安全放进 HTML 的文本
75
+ */
76
+ function escapeHtml(text: string): string {
77
+ return text.replace(/[&<>"]/g, (char) => ESCAPES[char] ?? char)
78
+ }
79
+
80
+ /**
81
+ * 把行内 Markdown(代码、粗体、斜体、链接)转成 HTML;其余文本先转义。
82
+ * @author ddj 2026年11月25号
83
+ * @param text 行内文本
84
+ * @returns HTML 片段
85
+ */
86
+ export function renderInline(text: string): string {
87
+ const parts = String(text ?? '').split(/(`[^`]*`)/)
88
+ return parts.map((part) => {
89
+ if (part.startsWith('`') && part.endsWith('`') && part.length >= 2) {
90
+ return '<code>' + escapeHtml(part.slice(1, -1)) + '</code>'
91
+ }
92
+ let html = escapeHtml(part)
93
+ html = html.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
94
+ html = html.replace(/(^|[^*])\*([^*]+)\*/g, '$1<em>$2</em>')
95
+ html = html.replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, '<a href="$2" rel="noreferrer noopener">$1</a>')
96
+ return html
97
+ }).join('')
98
+ }
99
+
100
+ /**
101
+ * 取一行里的纯文本(去行内标记),用于标题。
102
+ * @author ddj 2026年11月25号
103
+ * @param text 行内文本
104
+ * @returns 纯文本
105
+ */
106
+ function plainTextOf(text: string): string {
107
+ return String(text ?? '')
108
+ .replace(/`([^`]*)`/g, '$1')
109
+ .replace(/\*\*([^*]+)\*\*/g, '$1')
110
+ .replace(/(^|[^*])\*([^*]+)\*/g, '$1$2')
111
+ .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1')
112
+ .trim()
113
+ }
114
+
115
+ /**
116
+ * 判断行是否表格分隔行(|---|---|)。
117
+ * @author ddj 2026年11月25号
118
+ * @param line 行文本
119
+ * @returns 是否分隔行
120
+ */
121
+ function isTableDivider(line: string): boolean {
122
+ return /^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(line)
123
+ }
124
+
125
+ /**
126
+ * 把一行表格拆成单元格。
127
+ * @author ddj 2026年11月25号
128
+ * @param line 行文本
129
+ * @returns 单元格文本
130
+ */
131
+ function tableCells(line: string): string[] {
132
+ return line.trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map((cell) => cell.trim())
133
+ }
134
+
135
+ /**
136
+ * 把计划 Markdown 渲染成页面主体 HTML(不含外壳)。
137
+ * @author ddj 2026年11月25号
138
+ * @param markdown 计划正文
139
+ * @returns `{ title, body }`
140
+ */
141
+ export function renderPlanMarkdown(markdown: string): { title: string; body: string } {
142
+ const lines = String(markdown ?? '').replace(PAGE_MARK_LINE, '').split('\n')
143
+ const out: string[] = []
144
+ let title = ''
145
+ let index = 0
146
+
147
+ while (index < lines.length) {
148
+ const line = lines[index] ?? ''
149
+ const trimmed = line.trim()
150
+
151
+ if (!trimmed) {
152
+ index += 1
153
+ continue
154
+ }
155
+
156
+ // 围栏代码块
157
+ const fence = /^```([\w-]*)\s*$/.exec(trimmed)
158
+ if (fence) {
159
+ const code: string[] = []
160
+ index += 1
161
+ while (index < lines.length && !/^```\s*$/.test((lines[index] ?? '').trim())) {
162
+ code.push(lines[index] ?? '')
163
+ index += 1
164
+ }
165
+ index += 1
166
+ const lang = fence[1] ? ' class="language-' + escapeHtml(fence[1]) + '"' : ''
167
+ out.push('<pre><code' + lang + '>' + escapeHtml(code.join('\n')) + '</code></pre>')
168
+ continue
169
+ }
170
+
171
+ // 标题
172
+ const heading = /^(#{1,6})\s+(.*)$/.exec(trimmed)
173
+ if (heading) {
174
+ const level = heading[1].length
175
+ const text = heading[2].trim()
176
+ if (!title) {
177
+ title = plainTextOf(text)
178
+ index += 1
179
+ continue
180
+ }
181
+ const tag = level >= 4 ? 'h4' : level === 3 ? 'h3' : 'h2'
182
+ out.push('<' + tag + '>' + renderInline(text) + '</' + tag + '>')
183
+ index += 1
184
+ continue
185
+ }
186
+
187
+ // 分隔线
188
+ if (/^(?:-{3,}|\*{3,}|_{3,})$/.test(trimmed)) {
189
+ out.push('<hr>')
190
+ index += 1
191
+ continue
192
+ }
193
+
194
+ // 引用
195
+ if (trimmed.startsWith('>')) {
196
+ const quote: string[] = []
197
+ while (index < lines.length && (lines[index] ?? '').trim().startsWith('>')) {
198
+ quote.push((lines[index] ?? '').trim().replace(/^>\s?/, ''))
199
+ index += 1
200
+ }
201
+ out.push('<blockquote>' + renderInline(quote.join(' ')) + '</blockquote>')
202
+ continue
203
+ }
204
+
205
+ // 表格
206
+ const next = (lines[index + 1] ?? '').trim()
207
+ if (trimmed.includes('|') && isTableDivider(next)) {
208
+ const header = tableCells(trimmed)
209
+ index += 2
210
+ const rows: string[][] = []
211
+ while (index < lines.length && (lines[index] ?? '').trim().includes('|')) {
212
+ rows.push(tableCells(lines[index] ?? ''))
213
+ index += 1
214
+ }
215
+ out.push('<table><thead><tr>' + header.map((cell) => '<th>' + renderInline(cell) + '</th>').join('') + '</tr></thead><tbody>'
216
+ + rows.map((row) => '<tr>' + row.map((cell) => '<td>' + renderInline(cell) + '</td>').join('') + '</tr>').join('')
217
+ + '</tbody></table>')
218
+ continue
219
+ }
220
+
221
+ // 列表(有序/无序,单层)
222
+ const listMatch = /^([-*+]|\d+[.)])\s+(.*)$/.exec(trimmed)
223
+ if (listMatch) {
224
+ const ordered = /^\d/.test(listMatch[1])
225
+ const items: string[] = []
226
+ while (index < lines.length) {
227
+ const item = /^([-*+]|\d+[.)])\s+(.*)$/.exec((lines[index] ?? '').trim())
228
+ if (!item || /^\d/.test(item[1]) !== ordered) break
229
+ items.push(item[2])
230
+ index += 1
231
+ // 续行(缩进的非列表行)并入当前项。
232
+ while (index < lines.length) {
233
+ const cont = lines[index] ?? ''
234
+ if (!cont.trim() || /^([-*+]|\d+[.)])\s+/.test(cont.trim()) || /^#{1,6}\s/.test(cont.trim())) break
235
+ items[items.length - 1] += ' ' + cont.trim()
236
+ index += 1
237
+ }
238
+ }
239
+ const tag = ordered ? 'ol' : 'ul'
240
+ out.push('<' + tag + '>' + items.map((item) => '<li>' + renderInline(item) + '</li>').join('') + '</' + tag + '>')
241
+ continue
242
+ }
243
+
244
+ // 段落:收集到空行或下一个块级记号
245
+ const paragraph: string[] = [trimmed]
246
+ index += 1
247
+ while (index < lines.length) {
248
+ const raw = (lines[index] ?? '').trim()
249
+ if (!raw) break
250
+ if (/^```/.test(raw) || /^#{1,6}\s/.test(raw) || /^(?:-{3,}|\*{3,}|_{3,})$/.test(raw) || /^>/.test(raw)) break
251
+ if (/^([-*+]|\d+[.)])\s+/.test(raw)) break
252
+ if (raw.includes('|') && isTableDivider((lines[index + 1] ?? '').trim())) break
253
+ paragraph.push(raw)
254
+ index += 1
255
+ }
256
+ out.push('<p>' + renderInline(paragraph.join(' ')) + '</p>')
257
+ }
258
+
259
+ return { title: title || '计划', body: out.join('\n') }
260
+ }
261
+
262
+ //endregion
263
+
264
+ //region 页面组装
265
+
266
+ /**
267
+ * 生成一页独立的 HTML 计划页(运行时内联,可直接塞进 sandbox iframe)。
268
+ *
269
+ * `data-feedback="off"` 关掉运行时自带的 Respond 条:页面没有决策控件,回复走计划签的官方按钮。
270
+ * @author ddj 2026年11月25号
271
+ * @param markdown 计划正文
272
+ * @param assets 运行时样式与脚本
273
+ * @returns 完整 HTML 文本
274
+ */
275
+ export function renderAutoPlanPage(markdown: string, assets: PlanRuntimeAssets): string {
276
+ const text = String(markdown ?? '')
277
+ if (text.length > AUTO_PAGE_MARKDOWN_CAP) {
278
+ throw new Error('计划正文过大(上限 ' + String(AUTO_PAGE_MARKDOWN_CAP) + ' 字符)')
279
+ }
280
+ const { title, body } = renderPlanMarkdown(text)
281
+ const script = String(assets?.js ?? '').replace(/<\/script/gi, '<\\/script')
282
+ const style = String(assets?.css ?? '')
283
+ return [
284
+ '<!doctype html>',
285
+ '<html lang="zh-CN" data-htmlplan-packed>',
286
+ '<meta charset="utf-8">',
287
+ '<meta name="viewport" content="width=device-width, initial-scale=1">',
288
+ '<title>' + escapeHtml(title) + '</title>',
289
+ '<style data-htmlplan>',
290
+ style,
291
+ '</style>',
292
+ '<body data-feedback="off">',
293
+ '<header><h1>' + renderInline(title) + '</h1></header>',
294
+ '<main>',
295
+ body,
296
+ '</main>',
297
+ '<script data-htmlplan>',
298
+ script,
299
+ '</script>',
300
+ '</body>',
301
+ '</html>',
302
+ '',
303
+ ].join('\n')
304
+ }
305
+
306
+ //endregion
@@ -0,0 +1,148 @@
1
+ /**
2
+ * dsh-vscode-mode host — 作者页自动打包(调技能自带 `pack.mjs`)。
3
+ *
4
+ * 模型只写 `plans/<slug>/plan.html` 时,计划签打开前在这里跑一次官方打包脚本:
5
+ * 输出到系统临时文件,读回后删除,绝不删改作者页与 `assets/`(与技能里 `plan.mjs`
6
+ * 的一键流程不同——那条会清理中间产物,不能拿来处理用户文件)。
7
+ *
8
+ * 只读工作区:页面必须落在会话工作区内、扩展名是 `.html/.htm`、确实是文件;
9
+ * 打包脚本本身还有自己的 `--root` 围栏与密钥过滤。
10
+ * @author ddj 2026年11月25号
11
+ */
12
+ import { execFile } from 'node:child_process'
13
+ import { readFile, rm, stat } from 'node:fs/promises'
14
+ import { tmpdir } from 'node:os'
15
+ import { isAbsolute, join, relative, resolve } from 'node:path'
16
+ import { childEnv } from './childEnv.js'
17
+ import { skillsDirOf } from './paths.js'
18
+
19
+ //region 常量
20
+
21
+ /** 打包子进程超时(毫秒)。 */
22
+ export const PLAN_PACK_TIMEOUT_MS = 20_000
23
+
24
+ /** 打包输出上限(读回内存的字节数)。 */
25
+ export const PLAN_PACK_MAX_BYTES = 16 * 1024 * 1024
26
+
27
+ /** 结果缓存条数(按 path + mtime + size)。 */
28
+ const CACHE_MAX = 8
29
+
30
+ //endregion
31
+
32
+ //region 结构面
33
+
34
+ /** 打包执行结果。 */
35
+ interface PackRun {
36
+ stdout: string
37
+ stderr: string
38
+ }
39
+
40
+ //endregion
41
+
42
+ //region 缓存
43
+
44
+ /** 已打包结果:key = 绝对路径 + mtime + size。 */
45
+ const cache = new Map<string, string>()
46
+
47
+ //endregion
48
+
49
+ //region 执行
50
+
51
+ /**
52
+ * 取异常的展示文案。
53
+ * @author ddj 2026年11月25号
54
+ * @param error 捕获值
55
+ * @returns 可读文本
56
+ */
57
+ function messageOf(error: unknown): string {
58
+ if (error instanceof Error) return error.message
59
+ return String(error ?? '未知错误')
60
+ }
61
+
62
+ /**
63
+ * 跑一次打包脚本(child_process.execFile 的 Promise 包装,保留 stdout/stderr)。
64
+ * @author ddj 2026年11月25号
65
+ * @param args 参数列表
66
+ * @param cwd 工作区
67
+ * @returns stdout / stderr
68
+ */
69
+ function runPack(args: string[], cwd: string): Promise<PackRun> {
70
+ return new Promise((resolvePromise, reject) => {
71
+ execFile(process.execPath, args, {
72
+ cwd,
73
+ timeout: PLAN_PACK_TIMEOUT_MS,
74
+ windowsHide: true,
75
+ env: childEnv(),
76
+ maxBuffer: PLAN_PACK_MAX_BYTES,
77
+ }, (error, stdout, stderr) => {
78
+ const out = String(stdout ?? '')
79
+ const err = String(stderr ?? '')
80
+ if (error) {
81
+ reject(Object.assign(error, { packStdout: out, packStderr: err }))
82
+ return
83
+ }
84
+ resolvePromise({ stdout: out, stderr: err })
85
+ })
86
+ })
87
+ }
88
+
89
+ /**
90
+ * 把作者页打包成单文件 HTML(结果进内存,不落工作区)。
91
+ * @author ddj 2026年11月25号
92
+ * @param cwd 会话工作区绝对路径
93
+ * @param pagePath 页面路径(绝对或相对工作区)
94
+ * @returns 打包后的 HTML 文本
95
+ * @throws 路径越界、文件不存在、打包失败时抛出可读错误
96
+ */
97
+ export async function packPlanPage(cwd: string, pagePath: string): Promise<string> {
98
+ const workspace = resolve(String(cwd ?? ''))
99
+ const raw = String(pagePath ?? '').trim()
100
+ if (!raw) throw new Error('缺少页面路径')
101
+
102
+ const absolute = isAbsolute(raw) ? resolve(raw) : resolve(workspace, raw)
103
+ const inside = relative(workspace, absolute)
104
+ if (!inside || inside.startsWith('..') || isAbsolute(inside)) {
105
+ throw new Error('计划页必须位于会话工作区内:' + raw)
106
+ }
107
+ if (!/\.html?$/i.test(absolute)) throw new Error('只打包 .html / .htm 页面:' + raw)
108
+
109
+ const info = await stat(absolute).catch(() => null)
110
+ if (!info || !info.isFile()) throw new Error('计划页文件不存在:' + raw)
111
+
112
+ const key = absolute + '|' + String(info.mtimeMs) + '|' + String(info.size)
113
+ const hit = cache.get(key)
114
+ if (hit !== undefined) return hit
115
+
116
+ const packScript = join(skillsDirOf(import.meta.url), 'dsh-vscodemode-html-plan', 'runtime', 'pack.mjs')
117
+ const output = join(tmpdir(), 'dsh-htmlplan-' + String(process.pid) + '-' + String(Date.now())
118
+ + '-' + Math.random().toString(36).slice(2, 8) + '.packed.html')
119
+
120
+ try {
121
+ await runPack([packScript, absolute, '-o', output, '--root', workspace, '--quiet'], workspace)
122
+ const html = await readFile(output, 'utf8')
123
+ cache.set(key, html)
124
+ if (cache.size > CACHE_MAX) {
125
+ const oldest = cache.keys().next().value
126
+ if (oldest !== undefined) cache.delete(oldest)
127
+ }
128
+ return html
129
+ } catch (error) {
130
+ const stdout = String((error as { packStdout?: unknown } | null)?.packStdout ?? '')
131
+ const stderr = String((error as { packStderr?: unknown } | null)?.packStderr ?? '')
132
+ const detail = (stdout.trim() || stderr.trim()).slice(-400)
133
+ throw new Error('打包计划页失败:' + (detail || messageOf(error)))
134
+ } finally {
135
+ await rm(output, { force: true }).catch(() => {})
136
+ }
137
+ }
138
+
139
+ /**
140
+ * 清空打包结果缓存(测试与工作区切换用)。
141
+ * @author ddj 2026年11月25号
142
+ * @returns 无
143
+ */
144
+ export function clearPlanPagePackCache(): void {
145
+ cache.clear()
146
+ }
147
+
148
+ //endregion
package/src/registry.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import type { DiffRecord } from './shared/types.js'
7
7
  import type { Ctx, Session } from './store.js'
8
- import { cwdOfSession, loadBucket } from './store.js'
8
+ import { cwdOfSession, loadBucket, reclaimActive } from './store.js'
9
9
  import { SESSION_MISSING_ERROR, SESSION_NO_WORKSPACE_ERROR } from './shared/rpc.js'
10
10
 
11
11
  /** cwd → 记录桶(内存缓存;随会话销毁清理)。 */
@@ -59,9 +59,14 @@ export function cwdOf(session: Session | undefined): string | null {
59
59
  /** 取(或加载)某工作区记录桶。 */
60
60
  export function bucketOf(registry: Registry, ctx: Ctx, cwd: string): Promise<Map<string, DiffRecord>> {
61
61
  const existing = registry.get(cwd)
62
- if (existing) return Promise.resolve(existing)
62
+ if (existing) {
63
+ try { reclaimActive(cwd, existing) } catch { /* 重置标记读取失败不影响列表 */ }
64
+ return Promise.resolve(existing)
65
+ }
63
66
  return loadBucket(ctx, cwd).then((map) => {
64
67
  registry.set(cwd, map)
68
+ // 待审 v7 迁移留下的「旧活跃记录待重置」标记:库内已清空,内存桶也必须一起清
69
+ try { reclaimActive(cwd, map) } catch { /* 重置标记读取失败不影响列表 */ }
65
70
  return map
66
71
  })
67
72
  }
package/src/reviewDb.ts CHANGED
@@ -224,7 +224,7 @@ function dropFile(db: DatabaseSync, fileId: string): void {
224
224
  }
225
225
 
226
226
  /** @public @author ddj 2026年10月26号 @param cwd Workspace. @param gap Announced event identity. @param state Durable inbox or explicit failure. */
227
- export function captureState(cwd: string, gap: CaptureGap, state: 'queued' | 'gap'): void {
227
+ export function captureState(cwd: string, gap: CaptureGap, state: 'queued' | 'gap' | 'complete'): void {
228
228
  reviewDb(cwd).prepare(`INSERT INTO review_capture VALUES(?,?,?,?,?) ON CONFLICT(session_id,turn,seq)
229
229
  DO UPDATE SET state=excluded.state,error=excluded.error WHERE review_capture.state<>'complete'`).run(gap.sessionId, gap.turn, gap.seq, state, gap.error)
230
230
  }
package/src/reviewRpc.ts CHANGED
@@ -46,13 +46,20 @@ function batchSnapshot(cwd: string, pending: PendingPage): { ok: true; page: Rev
46
46
  // 分页期间有记录被判定掉:数量对不上就不给客户端一份半截快照
47
47
  if (official.length !== first.pending) return { ok: false, error: '待审记录数量不完整,未执行批量操作' }
48
48
 
49
- // 待审投影已接管的路径,官方旧行必须让位,否则同一文件会被批量写两次
49
+ // 待审投影已接管的路径,官方旧行必须让位,否则同一文件会被批量写两次;
50
+ // 已关窗的路径也算接管:用户处理完了,旧行不该再回到待办里。
51
+ const covered = pending.coveredPaths ?? []
50
52
  const live = pending.items.filter((item) => !item.settled)
51
- const kept = official.filter((row) => !live.some((entry) => pendingSamePath(entry.path, row.currentPath) || pendingSamePath(entry.path, row.path)))
53
+ const kept = official.filter((row) => !covered.some((entry) => pendingSamePath(entry, row.currentPath) || pendingSamePath(entry, row.path))
54
+ && !live.some((entry) => pendingSamePath(entry.path, row.currentPath) || pendingSamePath(entry.path, row.path)))
52
55
  const items = [...live.map((entry) => pendingItemOf(entry, cwd)), ...kept]
53
56
  return {
54
57
  ok: true,
55
- page: { items, pending: items.length, nextCursor: null, gaps: first.gaps, ...(first.overview ? { overview: first.overview } : {}) },
58
+ page: {
59
+ items, pending: items.length, nextCursor: null, gaps: first.gaps,
60
+ pendingCoveredPaths: pending.coveredPaths ?? [],
61
+ ...(first.overview ? { overview: first.overview } : {}),
62
+ },
56
63
  }
57
64
  }
58
65
 
@@ -262,9 +269,10 @@ export function reviewHandlers(ctx: Ctx, registry: Registry): Partial<RpcHandler
262
269
  // 否则待审详情(块判定 + 批注 + 让 AI 应答)在这条入口上永远点不到。
263
270
  const key = args.path
264
271
  const own = pending.items.filter((item) => pendingSamePath(item.path, key)).map((item) => pendingItemOf(item, cwd))
265
- // 待审接管后同路径的官方轮次行只是旧口径残影:留着会让人点进只读详情,以为没有判定入口。
266
- const history = own.length ? official.items.filter((item) => !pendingSamePath(item.path, key)) : official.items
267
- return { ok: true, page: { ...official, items: [...own, ...history] } }
272
+ // 待审接管后同路径的官方轮次行只是旧口径残影:留档能看到,但不进当前待审入口。
273
+ const covered = (pending.coveredPaths ?? []).some((path) => pendingSamePath(path, key))
274
+ const history = own.length || covered ? official.items.filter((item) => !pendingSamePath(item.path, key)) : official.items
275
+ return { ok: true, page: { ...official, items: [...own, ...history], pendingCoveredPaths: pending.coveredPaths ?? [] } }
268
276
  }
269
277
  // 待审投影就位后由它承接被覆盖路径,官方旧行让位,同一路径只保留一个权威
270
278
  const merged = mergedPage(official, pending, cwd)
package/src/rpc.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  archiveRecords,
16
16
  archiveCanceled,
17
17
  autoArchiveStale,
18
+ reclaimActive,
18
19
  retireCovered,
19
20
  policyOf,
20
21
  resolveTarget,
@@ -28,6 +29,8 @@ import { clearRevertState, listArchives, pageArchives, readArchives, revertState
28
29
  import { purgeArchiveDb, scheduleArchiveRewrite } from './archivePurge.js'
29
30
  import { hasOfficial } from './reviewDb.js'
30
31
  import { log } from './log.js'
32
+ import { planRuntimeAssets, renderAutoPlanPage } from './planAutoPage.js'
33
+ import { packPlanPage } from './planPagePack.js'
31
34
  import { beginOperation } from './slowLog.js'
32
35
  import type { Registry, SessionScope } from './registry.js'
33
36
  import { bucketOf, cwdOfSession, resolveScope, sessionOf } from './registry.js'
@@ -71,6 +74,7 @@ import { createTextPages } from './textPages.js'
71
74
  import { reviewHandlers } from './reviewRpc.js'
72
75
  import { pendingHandlers } from './pendingRpc.js'
73
76
  import { univerHandlers } from './univerRpc.js'
77
+ import { checkHandlers } from './testCheckRpc.js'
74
78
  import { fileAbsent, missingReview, missingDecide, missingPath, refusalCodeOf } from './missingReview.js'
75
79
  import { pendingCovers } from './pendingCompat.js'
76
80
  import { runReplace } from './search/replaceRun.js'
@@ -747,6 +751,8 @@ export function buildHandlers(
747
751
  ...(reviewHandlers(ctx, registry) as RpcHandlerMap),
748
752
  ...(pendingHandlers(ctx, registry) as RpcHandlerMap),
749
753
  ...(univerHandlers(ctx) as RpcHandlerMap),
754
+ // edrv.testCheck.* 由 checkHandlers 提供(验收单视图/上报/导出),这里并入。
755
+ ...(checkHandlers(ctx) as RpcHandlerMap),
750
756
  'edrv.list': async (args) => {
751
757
  // #region debug log
752
758
  const start = performance.now()
@@ -776,6 +782,8 @@ export function buildHandlers(
776
782
  await archiveCanceled(ctx, sc.session, sc.cwd, bucket)
777
783
  // 已被待审累计基线接管的路径:旧记录直接结案归档,旧通道的 Keep/Undo 随之从界面消失
778
784
  await retireCovered(ctx, sc.session, sc.cwd, bucket)
785
+ // 待审 v7 迁移可能刚清空库内旧记录:同一个请求里的内存桶也要同步清掉
786
+ reclaimActive(sc.cwd, bucket)
779
787
  // #region debug log
780
788
  staleMs = performance.now() - staleStart
781
789
  // #endregion
@@ -833,6 +841,32 @@ export function buildHandlers(
833
841
  }
834
842
  return { ok: true }
835
843
  },
844
+ /**
845
+ * HTML 计划模式兜底页:把提交给 exit_html_plan_mode 的计划正文渲染成独立 HTML。
846
+ * 不读工作区文件,只读随包技能运行时;失败返回可读错误,客户端回落 Markdown。
847
+ * @author ddj 2026年11月25号
848
+ */
849
+ 'edrv.planPage.render': async (args) => {
850
+ try {
851
+ const assets = await planRuntimeAssets()
852
+ return { ok: true, html: renderAutoPlanPage(String(args.markdown ?? ''), assets) }
853
+ } catch (error) {
854
+ return { ok: false, error: error instanceof Error ? error.message : String(error) }
855
+ }
856
+ },
857
+ /**
858
+ * HTML 计划模式作者页打包:只允许会话工作区内的 .html/.htm,结果进内存、不落工作区。
859
+ * @author ddj 2026年11月25号
860
+ */
861
+ 'edrv.planPage.pack': async (args) => {
862
+ const sc = await resolveScope(ctx, args.sessionId)
863
+ if ('err' in sc) return { ok: false, error: sc.err }
864
+ try {
865
+ return { ok: true, html: await packPlanPage(sc.cwd, String(args.path ?? '')) }
866
+ } catch (error) {
867
+ return { ok: false, error: error instanceof Error ? error.message : String(error) }
868
+ }
869
+ },
836
870
  'edrv.accept': async (args) => {
837
871
  const sc = await requireSession(ctx, args.sessionId)
838
872
  if ('err' in sc) return { ok: false, error: sc.err }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * dsh-vscode-mode shared — HTML 计划模式的跨平面常量。
3
+ *
4
+ * 宿主注册投影、命令与退出工具,客户端 chip 与计划签都要认同一套名字;
5
+ * 放 shared 里避免 host/client 两侧各写一份字面量后悄悄漂移。
6
+ * @author ddj 2026年11月25号
7
+ */
8
+
9
+ //region 常量
10
+
11
+ /** 会话投影 key(`sessionProjections.register` 的 key,也是客户端 `useProjection` 的入参)。 */
12
+ export const HTML_PLAN_MODE_KEY = 'html-plan'
13
+
14
+ /** 进入/离开模式的命令名(官方命令语法:小写字母开头)。 */
15
+ export const HTML_PLAN_COMMAND = 'html-plan'
16
+
17
+ /** 离开模式的完整命令行(chip 与退出工具共用)。 */
18
+ export const HTML_PLAN_OFF_LINE = '/html-plan off'
19
+
20
+ /** 客户端捕获计划提交时要识别的工具名。 */
21
+ export const HTML_PLAN_EXIT_TOOL = 'exit_html_plan_mode'
22
+
23
+ /** 官方计划模式的退出工具名(保持识别,普通计划不受影响)。 */
24
+ export const OFFICIAL_PLAN_EXIT_TOOL = 'exit_plan_mode'
25
+
26
+ //endregion
@@ -33,6 +33,12 @@ export type PendingEvidence = 'authoritative' | 'receipt' | 'snapshot' | 'none'
33
33
  /** 一次写入调用的结局:只有 changed 会进待审列表。 */
34
34
  export type PendingVerdict = 'changed' | 'noop' | 'failed' | 'unverified'
35
35
 
36
+ /**
37
+ * 差异追踪窗口状态:`open` 表示 AI 动过、用户还没处理完,期间所有改动都折进同一条差异;
38
+ * `closed` 表示已处理完,之后的改动不再生成记录。
39
+ */
40
+ export type PendingTracking = 'open' | 'closed'
41
+
36
42
  /** 会话血缘,用于子代理/派生会话归属到同一待审视图。 */
37
43
  export interface PendingLineage {
38
44
  parentSessionId?: string
@@ -75,6 +81,10 @@ export interface PendingItem {
75
81
  evidence?: PendingEvidence
76
82
  /** 这次调用的结局;旧条目没有该字段,按 `changed` 处理。 */
77
83
  verdict?: PendingVerdict
84
+ /** 差异追踪窗口状态;缺省按 `open` 解释。 */
85
+ tracking?: PendingTracking
86
+ /** 开窗时刻(毫秒时间戳);0 表示旧条目或未知。 */
87
+ openedAt?: number
78
88
  /** 只读编辑说明(模型声明,仅展示,不参与判定);没有时不出现。 */
79
89
  note?: string
80
90
  }
@@ -86,6 +96,11 @@ export interface PendingPage {
86
96
  nextCursor: number | null
87
97
  /** 采集/重建过程中的缺口说明,绝不静默吞掉。 */
88
98
  gaps: string[]
99
+ /**
100
+ * 已被待审窗口接管过的路径(含已关窗条目,路径与身份两种写法):
101
+ * 用来压住同路径的官方旧行与旧工具记录,避免关窗后它们复活。
102
+ */
103
+ coveredPaths?: string[]
89
104
  }
90
105
 
91
106
  /** 单条待审详情。 */
@@ -130,12 +145,5 @@ export interface PendingHistoryMove extends PendingRequest {
130
145
  operationId: string
131
146
  }
132
147
 
133
- /** 从版本控制导入本地改动。 */
134
- export interface PendingImport extends PendingRequest {
135
- includeUntracked?: boolean
136
- /** 只刷新一个文件,便于大仓单文件重扫。 */
137
- path?: string
138
- }
139
-
140
148
  /** 待审条目在面板列表里的 id 前缀;客户端与 Host 共用这一份口径。 */
141
149
  export const PENDING_PREFIX = 'pending:'