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
@@ -1,297 +0,0 @@
1
- /**
2
- * 外部改动补扫:拿版本库当基线,把「插件还没记录过」的工作副本改动用 `source='scan'` 补录,
3
- * 同时提供 watch 采集需要的两个只读能力(改动集合与基线内容)。
4
- *
5
- * 设计取舍:
6
- * - 候选只来自一条 `git status` / `svn status` 命令,不遍历目录树;因此 200 MB 仓库的启动对齐
7
- * 与定时补扫都只花「一条命令 + 少量读盘」。
8
- * - 不在版本库改动集合里的路径一律不建记录:内容变化只能来自版本库同步,记成 agent 改动会
9
- * 污染审查队列并让撤销误伤(见任务书验收 4)。
10
- * - 基线与读盘都有硬上限(条数、字节、截止时间),超限写 `gaps`,绝不静默截断。
11
- * 作者 ddj 2026-11-24
12
- */
13
- import { sessionOf } from '../registry.js'
14
- import type { Ctx } from '../store.js'
15
- import { policyOf } from '../store.js'
16
- import type { PendingWrite } from './capture.js'
17
- import { noteCaptureGap, readText } from './capture.js'
18
- import type { ShellLike, VcsStatus } from './vcs.js'
19
- import { vcsBaselineOf, vcsStatus } from './vcs.js'
20
- import { pathKeyOf } from './provenance.js'
21
- import { loadEntries } from './persist.js'
22
- import type { StoredEntry } from './persist.js'
23
- import { log } from '../log.js'
24
-
25
- // --region 预算
26
-
27
- /** 单次补扫的预算:候选条数、总读取字节、总耗时、基线读取条数。 */
28
- export interface AlignBudget {
29
- paths: number
30
- bytes: number
31
- deadlineMs: number
32
- baselines: number
33
- }
34
-
35
- /** 默认预算:大仓下也只是一条 status 命令加几十次读盘。 */
36
- export const ALIGN_BUDGET: AlignBudget = { paths: 2000, bytes: 16 << 20, deadlineMs: 5000, baselines: 32 }
37
-
38
- /** 单文件读取上限:与待审采集一致,超出只标 oversized 不读全文。 */
39
- export const ALIGN_FILE_MAX = 1024 * 1024
40
-
41
- // --endregion
42
-
43
- // --region 只读能力
44
-
45
- /** 补扫可用的版本库作用域:shell 已绑定会话沙箱策略。 */
46
- export interface VcsScope {
47
- shell: ShellLike
48
- cwd: string
49
- sessionId: string
50
- }
51
-
52
- /**
53
- * @author ddj 2026-11-24
54
- * @description: 取本会话可用的版本库能力;没有 shell 服务或会话不存在时返回 null。
55
- * @param ctx Host 上下文
56
- * @param cwd 工作区
57
- * @param sessionId 会话
58
- * @returns 作用域或 null
59
- */
60
- export function vcsScopeOf(ctx: Ctx, cwd: string, sessionId: string): VcsScope | null {
61
- const raw = ctx.get('shell') as ShellLike | undefined
62
- if (!raw || typeof raw.resolve !== 'function') return null
63
- const policy = policyOf(ctx, sessionOf(ctx, sessionId))
64
- return {
65
- cwd: String(cwd),
66
- sessionId,
67
- shell: {
68
- resolve: (request) => raw.resolve(policy ? { ...request, sandboxPolicy: policy } : request),
69
- execute: (spec) => raw.execute(spec),
70
- },
71
- }
72
- }
73
-
74
- // --endregion
75
-
76
- // --region 补扫
77
-
78
- /** 一次补扫的结果。 */
79
- export interface AlignOutcome {
80
- /** 新建或更新的条目数。 */
81
- imported: number
82
- /** 版本库报告的改动条数(含已记录、已跳过的)。 */
83
- changed: number
84
- /** 因预算、编码、读取失败等原因没处理的说明。 */
85
- gaps: string[]
86
- }
87
-
88
- /** 补扫需要的外部依赖(便于单测注入)。 */
89
- export interface AlignDeps {
90
- /** 读磁盘内容(严格 UTF-8 往返);缺失返回 null,不可读抛错。 */
91
- read(absolute: string): Promise<string | null>
92
- /** 落库;由调用方提供(复用待审采集 sink)。 */
93
- record(write: PendingWrite): void
94
- /** 已落库条目(按比较键索引)。 */
95
- entries(): Map<string, StoredEntry>
96
- now?(): number
97
- }
98
-
99
- /**
100
- * @author ddj 2026-11-24
101
- * @description: 一次补扫:版本库候选 → 逐条对比已知内容 → 未记录的补录(source='scan')。
102
- * 无版本库或状态命令不可用时降级为「只对齐已记录条目」,并把原因写进 gaps。
103
- * @param scope 版本库作用域(可为空:无 shell 时走降级)
104
- * @param deps 读盘与落库能力
105
- * @param budget 预算
106
- * @returns 结果
107
- */
108
- export async function alignExternal(scope: VcsScope | null, deps: AlignDeps, budget: AlignBudget = ALIGN_BUDGET): Promise<AlignOutcome> {
109
- const started = Date.now()
110
- const now = deps.now ?? Date.now
111
- const gaps: string[] = []
112
- const known = deps.entries()
113
-
114
- const status = scope ? await vcsStatus(scope.shell, scope.cwd) : null
115
- if (!status) {
116
- const reason = scope ? '版本库状态不可用(非 git/svn 或命令失败):补扫只对齐已记录条目' : '当前环境没有 shell 能力:补扫只对齐已记录条目'
117
- gaps.push(reason)
118
- const imported = await reconcileKnown(scope, deps, known, budget, started, now, gaps)
119
- return { imported, changed: 0, gaps }
120
- }
121
-
122
- const candidates = [...status.entries]
123
- if (candidates.length > budget.paths) {
124
- gaps.push(`版本库报告 ${candidates.length} 个改动,本次只处理前 ${budget.paths} 个`)
125
- }
126
- let imported = 0
127
- let bytes = 0
128
- let baselines = 0
129
-
130
- for (const [key, entry] of candidates.slice(0, budget.paths)) {
131
- if (Date.now() - started > budget.deadlineMs) {
132
- gaps.push(`补扫超过 ${budget.deadlineMs}ms,剩余改动留到下一轮`)
133
- break
134
- }
135
- const stored = known.get(key)
136
- const absolute = entry.path
137
- try {
138
- if (entry.status === 'deleted') {
139
- // 版本库里已删:已知内容照旧当基线才能恢复;没有条目时按「基线未知」留档
140
- if (stored && stored.flags.missing) continue
141
- deps.record(writeOf(scope, absolute, stored ? stored.entry.newText : null, null, now(), 'external',
142
- stored ? 'known' : 'unknown'))
143
- imported += 1
144
- continue
145
- }
146
- const content = await deps.read(absolute)
147
- if (content === null) continue
148
- if (content.length > ALIGN_FILE_MAX) { gaps.push(absolute + ': 超过单文件上限,未补扫'); continue }
149
- if (stored && stored.entry.newText === content) continue
150
- if (bytes + content.length > budget.bytes) { gaps.push(absolute + ': 补扫读取预算已用尽,未补扫'); continue }
151
- bytes += content.length
152
- if (stored) {
153
- deps.record(writeOf(scope, absolute, stored.entry.newText, content, now(), 'external', 'known'))
154
- imported += 1
155
- continue
156
- }
157
- // 版本库说新增(未跟踪/added):修改前内容就是"不存在",撤销语义是删除文件
158
- if (entry.status === 'added') {
159
- deps.record(writeOf(scope, absolute, null, content, now(), 'external', 'absent'))
160
- imported += 1
161
- continue
162
- }
163
- // 已跟踪的修改但没有既有条目:修改前内容只能取版本库基线,读不到就标未知(撤销置灰)
164
- let base: string | null = null
165
- if (baselines < budget.baselines) {
166
- baselines += 1
167
- base = await vcsBaselineOf(scope!.shell, status, absolute)
168
- } else {
169
- gaps.push(absolute + ': 基线读取预算已用尽,记为基线未知')
170
- }
171
- deps.record(writeOf(scope, absolute, base, content, now(), 'external', base === null ? 'unknown' : 'vcs'))
172
- imported += 1
173
- } catch (error) {
174
- gaps.push(absolute + ': ' + String(error))
175
- }
176
- }
177
- return { imported, changed: candidates.length, gaps }
178
- }
179
-
180
- /**
181
- * @private
182
- * @author ddj 2026-11-24
183
- * @description: 降级路径:只把已记录条目与磁盘对齐(条目数很小,不会遍历仓库)。
184
- * @param scope 版本库作用域
185
- * @param deps 读盘与落库能力
186
- * @param known 已落库条目
187
- * @param budget 预算
188
- * @param started 起始时间
189
- * @param now 时钟
190
- * @param gaps 缺口输出
191
- * @returns 无
192
- */
193
- async function reconcileKnown(
194
- scope: VcsScope | null, deps: AlignDeps, known: Map<string, StoredEntry>,
195
- budget: AlignBudget, started: number, now: () => number, gaps: string[],
196
- ): Promise<number> {
197
- let bytes = 0
198
- let imported = 0
199
- for (const stored of known.values()) {
200
- if (Date.now() - started > budget.deadlineMs) { gaps.push('降级补扫超过截止时间,剩余条目留到下一轮'); break }
201
- try {
202
- // 必须用条目里的真实路径读盘:比较键在 Windows 上折叠过大小写,不能当路径用。
203
- const content = await deps.read(stored.entry.id)
204
- if (content === null) {
205
- if (stored.flags.missing) continue
206
- deps.record(writeOf(scope, stored.entry.path, stored.entry.newText, null, now(), 'external', 'known'))
207
- imported += 1
208
- continue
209
- }
210
- if (content === stored.entry.newText) continue
211
- if (bytes + content.length > budget.bytes) { gaps.push(stored.entry.path + ': 补扫读取预算已用尽,未补扫'); break }
212
- bytes += content.length
213
- deps.record(writeOf(scope, stored.entry.path, stored.entry.newText, content, now(), 'external', 'known'))
214
- imported += 1
215
- } catch (error) {
216
- gaps.push(stored.entry.path + ': ' + String(error))
217
- }
218
- }
219
- return imported
220
- }
221
-
222
- /**
223
- * @private
224
- * @author ddj 2026-11-24
225
- * @description: 组装一条待审写入;补扫只产出 `source='scan'` 的记录。
226
- * @param scope 版本库作用域
227
- * @param absolute 绝对路径
228
- * @param before 修改前内容(null = 当时不存在或未知,由 baseKind 区分)
229
- * @param after 当前内容(null = 已删除)
230
- * @param at 时间
231
- * @param origin 归属
232
- * @param baseKind 基线可信度
233
- * @returns 待审写入
234
- */
235
- function writeOf(
236
- scope: VcsScope | null, absolute: string, before: string | null, after: string | null,
237
- at: number, origin: 'external' | 'agent', baseKind: 'known' | 'vcs' | 'absent' | 'unknown',
238
- ): PendingWrite {
239
- return {
240
- cwd: scope?.cwd ?? '',
241
- sessionId: scope?.sessionId ?? '',
242
- path: absolute,
243
- identity: absolute,
244
- before,
245
- after,
246
- now: at,
247
- tool: 'scan',
248
- origin,
249
- baseKind,
250
- }
251
- }
252
-
253
- // --endregion
254
-
255
- // --region Host 装配
256
-
257
- /**
258
- * @author ddj 2026-11-24
259
- * @description: 用 Host 能力跑一次补扫:版本库候选 + 待审库条目 + ctx.fs 读盘。
260
- * @param ctx Host 上下文
261
- * @param cwd 工作区
262
- * @param sessionId 会话
263
- * @param record 落库回调(复用待审采集 sink)
264
- * @param budget 预算
265
- * @returns 结果
266
- */
267
- export async function alignInWorkspace(
268
- ctx: Ctx, cwd: string, sessionId: string, record: (write: PendingWrite) => void, budget: AlignBudget = ALIGN_BUDGET,
269
- ): Promise<AlignOutcome> {
270
- const fs = ctx.get('fs')
271
- if (!fs) return { imported: 0, changed: 0, gaps: ['缺少 fs 服务:补扫未执行'] }
272
- const entries = new Map<string, StoredEntry>()
273
- for (const stored of loadEntries(cwd)) entries.set(pathKeyOf(stored.entry.id), stored)
274
- const deps: AlignDeps = {
275
- read: async (absolute) => {
276
- try {
277
- const target = await fs.resolve(absolute, { cwd })
278
- return await readText(fs, target)
279
- } catch (error) {
280
- noteCaptureGap(cwd, sessionId, absolute, error)
281
- throw error
282
- }
283
- },
284
- record,
285
- entries: () => entries,
286
- }
287
- try {
288
- const outcome = await alignExternal(vcsScopeOf(ctx, cwd, sessionId), deps, budget)
289
- for (const gap of outcome.gaps) log.debug('补扫:' + gap)
290
- return outcome
291
- } catch (error) {
292
- log.warn('补扫失败:' + String(error))
293
- return { imported: 0, changed: 0, gaps: ['补扫失败:' + String(error)] }
294
- }
295
- }
296
-
297
- // --endregion