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.
- package/README.md +38 -33
- package/lib/client.js +87 -68
- package/lib/client.js.map +1 -1
- package/lib/index.js +11406 -4920
- package/lib/index.js.map +1 -1
- package/package.json +3 -2
- package/skills/dsh-vscodemode-html-plan/SKILL.md +44 -42
- package/skills/dsh-vscodemode-test-check/SKILL.md +82 -0
- package/src/archiveDb.ts +24 -0
- package/src/attachmentBytes.ts +84 -0
- package/src/client/htmlPlan/HtmlPlanModeChip.ts +181 -0
- package/src/client/htmlPlan/HtmlPlanPanel.ts +230 -61
- package/src/client/htmlPlan/planActions.ts +38 -8
- package/src/client/htmlPlan/planPage.ts +111 -9
- package/src/client/index.ts +9 -0
- package/src/client/openReceipt.ts +5 -2
- package/src/client/planBridge.ts +27 -2
- package/src/client/planState.ts +51 -4
- package/src/client/sidebar/panels/TestCheckPanel.ts +485 -0
- package/src/client/sidebar/panels/useTestCheckData.ts +414 -0
- package/src/client/sidebar/types.ts +2 -0
- package/src/client/state/diffSummary.ts +3 -0
- package/src/client/styles/editor.css +91 -0
- package/src/client/testCheck/TestCheckChip.ts +181 -0
- package/src/client/testCheck/TestCheckPanel.ts +339 -0
- package/src/client/testCheckPanelState.ts +173 -0
- package/src/client/ui/EditorView.ts +77 -7
- package/src/client/ui/McpSettings.ts +2 -2
- package/src/client/ui/OfficialReview.ts +6 -4
- package/src/htmlPlanAttachments.ts +4 -1
- package/src/htmlPlanCommand.ts +87 -235
- package/src/htmlPlanGuidance.ts +67 -0
- package/src/htmlPlanMode.ts +547 -0
- package/src/index.ts +28 -55
- package/src/officialCapture.ts +58 -9
- package/src/pending/externalCapture.ts +195 -401
- package/src/pending/kernel.ts +24 -1
- package/src/pending/persist.ts +109 -22
- package/src/pending/provenance.ts +5 -28
- package/src/pending/store.ts +109 -100
- package/src/pending/tracking.ts +81 -0
- package/src/pendingCompat.ts +26 -1
- package/src/pendingRpc.ts +8 -56
- package/src/planAutoPage.ts +306 -0
- package/src/planPagePack.ts +148 -0
- package/src/registry.ts +7 -2
- package/src/reviewDb.ts +1 -1
- package/src/reviewRpc.ts +14 -6
- package/src/rpc.ts +34 -0
- package/src/shared/htmlPlanMode.ts +26 -0
- package/src/shared/pendingReview.ts +15 -7
- package/src/shared/review.ts +5 -0
- package/src/shared/rpc.ts +53 -7
- package/src/shared/testCheck.ts +759 -0
- package/src/shared/testCheckHtml.ts +276 -0
- package/src/shared/testCheckPolicyDefault.ts +37 -0
- package/src/shared/testCheckSnippets.ts +197 -0
- package/src/store.ts +17 -1
- package/src/testCheckCommand.ts +287 -0
- package/src/testCheckGuidance.ts +79 -0
- package/src/testCheckMode.ts +654 -0
- package/src/testCheckPolicy.ts +141 -0
- package/src/testCheckRpc.ts +196 -0
- package/src/testCheckStore.ts +822 -0
- package/src/pending/externalAlign.ts +0 -297
- package/src/pending/vcs.ts +0 -584
package/src/pending/store.ts
CHANGED
|
@@ -5,22 +5,20 @@
|
|
|
5
5
|
import type { PendingDecide, PendingDetail, PendingHistoryMove, PendingItem, PendingOrigin, PendingPage } from '../shared/pendingReview.js'
|
|
6
6
|
import type { ReviewBlockState } from '../shared/reviewRegions.js'
|
|
7
7
|
import { reviewBlocks } from '../shared/reviewRegions.js'
|
|
8
|
-
import { addedFiles } from '../reviewDb.js'
|
|
9
8
|
import { pathKeyOf, sourceOfTool, windows } from './provenance.js'
|
|
10
9
|
import type { PendingWrite } from './capture.js'
|
|
11
10
|
import { readText, pendingGaps } from './capture.js'
|
|
12
11
|
import { noteOf } from './notes.js'
|
|
13
|
-
import type { ShellLike, VcsImportOptions } from './vcs.js'
|
|
14
|
-
import { importVcsChanges } from './vcs.js'
|
|
15
12
|
import type { DecideOutcome, WriteResult } from './decide.js'
|
|
16
13
|
import { capabilityOf, decide, diffOf } from './decide.js'
|
|
17
|
-
import { entryFromNew, isSettled, mergeEntries } from './kernel.js'
|
|
14
|
+
import { applyTracking, entryFromNew, isSettled, mergeEntries } from './kernel.js'
|
|
18
15
|
import type { PendingEntry } from './kernel.js'
|
|
16
|
+
import { coveredPathsOf, isOpenEntry, nextTracking, trackingOf } from './tracking.js'
|
|
19
17
|
import type { PendingFlags, StoredEntry } from './persist.js'
|
|
20
18
|
import type { KeepRecord } from './persist.js'
|
|
21
19
|
import {
|
|
22
|
-
dropEntry, earliestUndone, latestApplied, loadBlocks, loadEntries, loadEntry,
|
|
23
|
-
readOp, saveBlocks, saveDecisions, saveEntry, setHistoryState, vacuumEntries, writeOp,
|
|
20
|
+
dropBlocks, dropEntry, dropHistory, earliestUndone, latestApplied, loadBlocks, loadEntries, loadEntry,
|
|
21
|
+
purgeEntries, pushHistory, readOp, saveBlocks, saveDecisions, saveEntry, setHistoryState, vacuumEntries, writeOp,
|
|
24
22
|
} from './persist.js'
|
|
25
23
|
import type { HistoryRow, PurgeFilter, PurgeOutcome } from './persist.js'
|
|
26
24
|
|
|
@@ -89,14 +87,14 @@ function blockStatesOf(entry: PendingEntry, revision = -1): ReviewBlockState[] {
|
|
|
89
87
|
}
|
|
90
88
|
|
|
91
89
|
/**
|
|
92
|
-
* @
|
|
93
|
-
* @
|
|
94
|
-
* @
|
|
90
|
+
* @private
|
|
91
|
+
* @author ddj 2026年11月25号
|
|
92
|
+
* @description: 由一次采集写入构造新窗口条目;基线取写前内容,开窗时刻取本次写入时间。
|
|
95
93
|
* @param write 采集到的写入
|
|
96
|
-
* @returns
|
|
94
|
+
* @returns 新条目(窗口状态 open)
|
|
97
95
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
function freshEntryOf(write: PendingWrite, tracking: 'open' | 'closed' = 'open'): PendingEntry {
|
|
97
|
+
return entryFromNew({
|
|
100
98
|
id: write.identity,
|
|
101
99
|
path: write.path,
|
|
102
100
|
sessionId: write.sessionId,
|
|
@@ -109,13 +107,34 @@ export function foldWrite(stored: StoredEntry | undefined, write: PendingWrite):
|
|
|
109
107
|
baseKind: write.before === null ? 'absent' : (write.baseKind ?? 'known'),
|
|
110
108
|
evidence: write.evidence ?? 'snapshot',
|
|
111
109
|
verdict: write.verdict ?? 'changed',
|
|
110
|
+
tracking,
|
|
111
|
+
openedAt: write.now,
|
|
112
112
|
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @author ddj 2026年10月29号 / 2026年11月25号
|
|
117
|
+
* @description: 把一次工具写入折进窗口:窗口关闭时按本次写前内容重开新窗口,窗口打开时基线留最早、内容取最新。
|
|
118
|
+
* 重开属于新窗口,调用方负责清掉旧窗口的块决定与撤销行。
|
|
119
|
+
* @param stored 已有条目(可为空)
|
|
120
|
+
* @param write 采集到的写入
|
|
121
|
+
* @returns 折叠后的条目与标记
|
|
122
|
+
*/
|
|
123
|
+
export function foldWrite(stored: StoredEntry | undefined, write: PendingWrite): StoredEntry {
|
|
124
|
+
const fresh = freshEntryOf(write)
|
|
113
125
|
if (!stored) {
|
|
114
126
|
return {
|
|
115
127
|
entry: fresh,
|
|
116
128
|
flags: { missing: write.after === null, diverged: false, oversized: false, revision: 0 },
|
|
117
129
|
}
|
|
118
130
|
}
|
|
131
|
+
if (!isOpenEntry(stored.entry)) {
|
|
132
|
+
// 新窗口:基线是这次写前内容;旧窗口的判定、块与撤销都不跨窗。
|
|
133
|
+
return {
|
|
134
|
+
entry: fresh,
|
|
135
|
+
flags: { missing: write.after === null, diverged: false, oversized: stored.flags.oversized, revision: stored.flags.revision + 1 },
|
|
136
|
+
}
|
|
137
|
+
}
|
|
119
138
|
const merged = mergeEntries(stored.entry, fresh)
|
|
120
139
|
merged.path = write.path
|
|
121
140
|
return {
|
|
@@ -174,6 +193,8 @@ export function itemOf(stored: StoredEntry, baselineEmpty = false): PendingItem
|
|
|
174
193
|
baseKind: entry.baseKind ?? 'known',
|
|
175
194
|
evidence: entry.evidence ?? 'snapshot',
|
|
176
195
|
verdict: entry.verdict ?? 'changed',
|
|
196
|
+
tracking: trackingOf(entry),
|
|
197
|
+
openedAt: entry.openedAt ?? 0,
|
|
177
198
|
}
|
|
178
199
|
if (entry.lineage !== undefined) item.lineage = entry.lineage
|
|
179
200
|
return item
|
|
@@ -181,26 +202,14 @@ export function itemOf(stored: StoredEntry, baselineEmpty = false): PendingItem
|
|
|
181
202
|
|
|
182
203
|
/**
|
|
183
204
|
* @private
|
|
184
|
-
* @author ddj 2026年11月04号
|
|
185
|
-
* @description
|
|
186
|
-
*
|
|
205
|
+
* @author ddj 2026年11月04号 / 2026年11月25号
|
|
206
|
+
* @description: 从条目基线判断创建来源:只有窗口自己的基线是"文件不存在"时才按整文件新增渲染。
|
|
207
|
+
* 重开窗口的基线是磁盘真实内容,不再借官方快照把整个文件算成新增。
|
|
187
208
|
* @param stored 累计条目
|
|
188
|
-
* @param sourceAdds 单次读取内的来源创建集合缓存
|
|
189
209
|
* @returns 是否将展示基线置空
|
|
190
210
|
*/
|
|
191
|
-
function emptyBaseOf(
|
|
192
|
-
|
|
193
|
-
const decided = pendingDb(cwd).prepare('SELECT 1 FROM pending_history WHERE entry_id=? LIMIT 1').get(stored.entry.id)
|
|
194
|
-
if (decided) return false
|
|
195
|
-
for (const sourceId of stored.entry.sessionIds) {
|
|
196
|
-
let createdPaths = sourceAdds.get(sourceId)
|
|
197
|
-
if (!createdPaths) {
|
|
198
|
-
createdPaths = addedFiles(cwd, sourceId)
|
|
199
|
-
sourceAdds.set(sourceId, createdPaths)
|
|
200
|
-
}
|
|
201
|
-
if (createdPaths.has(stored.entry.id)) return true
|
|
202
|
-
}
|
|
203
|
-
return false
|
|
211
|
+
function emptyBaseOf(stored: StoredEntry): boolean {
|
|
212
|
+
return stored.entry.earlierVersion === 'none'
|
|
204
213
|
}
|
|
205
214
|
|
|
206
215
|
/**
|
|
@@ -212,14 +221,20 @@ function emptyBaseOf(cwd: string, stored: StoredEntry, sourceAdds = new Map<stri
|
|
|
212
221
|
*/
|
|
213
222
|
export function loadPage(cwd: string, _sessionId?: string): PendingPage {
|
|
214
223
|
const all = loadEntries(cwd)
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
const items = visible.map((stored) => withNote(cwd, itemOf(stored, emptyBaseOf(
|
|
224
|
+
// 列表只显示开窗中的文件:已关窗条目仍留在库里供撤销判定,但不再出现在面板。
|
|
225
|
+
const visible = all.filter((stored) => isOpenEntry(stored.entry))
|
|
226
|
+
const items = visible.map((stored) => withNote(cwd, itemOf(stored, emptyBaseOf(stored))))
|
|
218
227
|
const gaps: string[] = pendingGaps(cwd)
|
|
219
228
|
for (const stored of visible) {
|
|
220
229
|
if (stored.flags.oversized) gaps.push(`${stored.entry.path}: 文本超出上限,仅保留标记`)
|
|
221
230
|
}
|
|
222
|
-
return {
|
|
231
|
+
return {
|
|
232
|
+
items,
|
|
233
|
+
pending: items.filter((item) => !item.settled).length,
|
|
234
|
+
nextCursor: null,
|
|
235
|
+
gaps,
|
|
236
|
+
coveredPaths: coveredPathsOf(all),
|
|
237
|
+
}
|
|
223
238
|
}
|
|
224
239
|
|
|
225
240
|
/**
|
|
@@ -246,7 +261,7 @@ function withNote(cwd: string, item: PendingItem): PendingItem {
|
|
|
246
261
|
export function loadDetail(cwd: string, id: string, baselineEmpty = false): PendingDetail | null {
|
|
247
262
|
const stored = loadEntries(cwd).find((item) => item.entry.id === id)
|
|
248
263
|
if (!stored) return null
|
|
249
|
-
const emptyBase = baselineEmpty || emptyBaseOf(
|
|
264
|
+
const emptyBase = baselineEmpty || emptyBaseOf(stored)
|
|
250
265
|
const diff = diffOf(stored.entry, emptyBase)
|
|
251
266
|
return {
|
|
252
267
|
item: withNote(cwd, itemOf(stored, emptyBase)),
|
|
@@ -257,52 +272,62 @@ export function loadDetail(cwd: string, id: string, baselineEmpty = false): Pend
|
|
|
257
272
|
}
|
|
258
273
|
|
|
259
274
|
/**
|
|
260
|
-
* @author ddj 2026年10月29号
|
|
261
|
-
* @description:
|
|
275
|
+
* @author ddj 2026年10月29号 / 2026年11月25号
|
|
276
|
+
* @description: 工具写入入口:开窗或折进当前窗口;关窗后再次写入按新窗口处理。
|
|
262
277
|
* @param write 已确认写入
|
|
263
278
|
* @returns 无
|
|
264
279
|
*/
|
|
265
280
|
export function recordWrite(write: PendingWrite): void {
|
|
266
281
|
const stored = loadEntries(write.cwd).find((item) => item.entry.id === write.identity)
|
|
267
|
-
|
|
268
|
-
|
|
282
|
+
// 开窗中的重复上报且内容没变:不重复落库
|
|
283
|
+
if (stored && isOpenEntry(stored.entry) && stored.entry.oldText === stored.entry.newText
|
|
284
|
+
&& stored.entry.newText === (write.after ?? '')) return
|
|
285
|
+
const next = foldWrite(stored, write)
|
|
286
|
+
// 重开属于新窗口:旧窗口的块决定与撤销行不跨窗
|
|
287
|
+
if (stored && !isOpenEntry(stored.entry)) {
|
|
288
|
+
dropBlocks(write.cwd, write.identity)
|
|
289
|
+
dropHistory(write.cwd, write.identity)
|
|
290
|
+
}
|
|
291
|
+
saveEntry(write.cwd, withWindow(next))
|
|
269
292
|
}
|
|
270
293
|
|
|
271
294
|
/**
|
|
272
|
-
* @author ddj 2026年
|
|
273
|
-
* @description:
|
|
274
|
-
* @param
|
|
275
|
-
* @
|
|
276
|
-
* @param now 时间
|
|
277
|
-
* @returns 新条目与标记
|
|
295
|
+
* @author ddj 2026年11月25号
|
|
296
|
+
* @description: 外部/编辑器改动入口:只折进已开窗的文件,其余路径一律不建记录。
|
|
297
|
+
* @param write 采集到的外部改动
|
|
298
|
+
* @returns 是否折进了窗口
|
|
278
299
|
*/
|
|
279
|
-
export function
|
|
280
|
-
const
|
|
281
|
-
if (
|
|
282
|
-
|
|
300
|
+
export function foldTracked(write: PendingWrite): boolean {
|
|
301
|
+
const stored = loadEntries(write.cwd).find((item) => item.entry.id === write.identity)
|
|
302
|
+
if (!stored || !isOpenEntry(stored.entry)) return false
|
|
303
|
+
const merged = mergeEntries(stored.entry, freshEntryOf(write))
|
|
304
|
+
merged.path = write.path
|
|
305
|
+
const closed = nextTracking(merged) === 'closed'
|
|
306
|
+
const entry = applyTracking(merged, closed ? 'closed' : 'open')
|
|
307
|
+
// 外部改动默认标未读;已经回到基线的窗口没有可看内容,不标
|
|
308
|
+
if (!closed) entry.unseen = true
|
|
309
|
+
saveEntry(write.cwd, {
|
|
283
310
|
entry,
|
|
284
|
-
flags: {
|
|
285
|
-
|
|
311
|
+
flags: {
|
|
312
|
+
missing: write.after === null,
|
|
313
|
+
diverged: !closed,
|
|
314
|
+
oversized: stored.flags.oversized,
|
|
315
|
+
revision: stored.flags.revision + 1,
|
|
316
|
+
},
|
|
317
|
+
})
|
|
318
|
+
return true
|
|
286
319
|
}
|
|
287
320
|
|
|
288
321
|
/**
|
|
289
|
-
* @
|
|
290
|
-
* @
|
|
291
|
-
* @
|
|
292
|
-
* @param
|
|
293
|
-
* @
|
|
294
|
-
* @returns 需要落库的新状态,无需改动时为 null
|
|
322
|
+
* @private
|
|
323
|
+
* @author ddj 2026年11月25号
|
|
324
|
+
* @description: 按净差异收尾窗口状态:内容回到基线就关窗,否则保持打开。
|
|
325
|
+
* @param stored 条目与标记
|
|
326
|
+
* @returns 收尾后的条目与标记
|
|
295
327
|
*/
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
return { entry: stored.entry, flags: { ...stored.flags, missing: true, revision: stored.flags.revision + 1 } }
|
|
300
|
-
}
|
|
301
|
-
if (content === stored.entry.newText) {
|
|
302
|
-
if (!stored.flags.missing) return null
|
|
303
|
-
return { entry: stored.entry, flags: { ...stored.flags, missing: false, revision: stored.flags.revision + 1 } }
|
|
304
|
-
}
|
|
305
|
-
return absorbed(stored, content, now)
|
|
328
|
+
function withWindow(stored: StoredEntry): StoredEntry {
|
|
329
|
+
const state = nextTracking(stored.entry)
|
|
330
|
+
return { ...stored, entry: applyTracking(stored.entry, state) }
|
|
306
331
|
}
|
|
307
332
|
|
|
308
333
|
/**
|
|
@@ -364,6 +389,8 @@ export async function applyDecide(
|
|
|
364
389
|
): Promise<DecideOutcome | { ok: false; reason: string }> {
|
|
365
390
|
const stored = loadEntries(cwd).find((item) => item.entry.id === request.id)
|
|
366
391
|
if (!stored) return { ok: false, reason: 'unknown-item' }
|
|
392
|
+
// 撤销会写盘:先打自写标记,避免 watch 把插件自己的写回折成一次外部改动。
|
|
393
|
+
if (request.decision === 'rejected') windows.markSelf(pathKeyOf(stored.entry.id))
|
|
367
394
|
const beforeBlocks = blockStatesOf(stored.entry, stored.flags.revision)
|
|
368
395
|
const outcome = await decide({
|
|
369
396
|
request,
|
|
@@ -379,7 +406,9 @@ export async function applyDecide(
|
|
|
379
406
|
},
|
|
380
407
|
})
|
|
381
408
|
if (!outcome.ok) return { ok: false, reason: outcome.reason }
|
|
382
|
-
|
|
409
|
+
// 判定把两侧推平就关窗;还有剩余块就保持打开。
|
|
410
|
+
const entry = applyTracking(outcome.entry, nextTracking(outcome.entry))
|
|
411
|
+
saveEntry(cwd, { entry, flags: outcome.flags })
|
|
383
412
|
saveBlocks(cwd, request.id, outcome.blocks)
|
|
384
413
|
// 撤销行按路径覆盖写:同一路径永远只有一行,撤销回到判定前的基线或内容
|
|
385
414
|
pushHistory(cwd, {
|
|
@@ -391,7 +420,7 @@ export async function applyDecide(
|
|
|
391
420
|
content: stored.entry.newText,
|
|
392
421
|
wrote: outcome.wrote,
|
|
393
422
|
}, Date.now())
|
|
394
|
-
return outcome
|
|
423
|
+
return { ...outcome, entry }
|
|
395
424
|
}
|
|
396
425
|
|
|
397
426
|
/** 批量 Keep 的目标条目:display 只用于回报,operationId 由 host 按批次派生。 */
|
|
@@ -451,8 +480,12 @@ export async function keepAll(cwd: string, items: PendingKeepTarget[]): Promise<
|
|
|
451
480
|
continue
|
|
452
481
|
}
|
|
453
482
|
outcome.kept.push({ id: item.id, path: before.entry.path })
|
|
454
|
-
records.push({
|
|
455
|
-
|
|
483
|
+
records.push({
|
|
484
|
+
entryId: item.id,
|
|
485
|
+
stored: before,
|
|
486
|
+
next: { entry: applyTracking(outcomeOf.entry, nextTracking(outcomeOf.entry)), flags: outcomeOf.flags },
|
|
487
|
+
blocks: outcomeOf.blocks,
|
|
488
|
+
})
|
|
456
489
|
}
|
|
457
490
|
|
|
458
491
|
// 落库阶段被别的决定抢先推进的条目从 kept 挪到 skipped,如实反映磁盘状态
|
|
@@ -464,34 +497,6 @@ export async function keepAll(cwd: string, items: PendingKeepTarget[]): Promise<
|
|
|
464
497
|
return outcome
|
|
465
498
|
}
|
|
466
499
|
|
|
467
|
-
/**
|
|
468
|
-
* @author ddj 2026年10月30号
|
|
469
|
-
* @description: 版本库导入:把工作副本相对基线的改动折进待审条目,已存在条目按折叠规则并入。
|
|
470
|
-
* @param shell shell 能力
|
|
471
|
-
* @param cwd 工作区
|
|
472
|
-
* @param sessionId 触发导入的会话
|
|
473
|
-
* @param options 导入选项
|
|
474
|
-
* @returns 导入条数与探测到的改动数
|
|
475
|
-
*/
|
|
476
|
-
export async function importFromVcs(
|
|
477
|
-
shell: ShellLike, cwd: string, sessionId: string, options: VcsImportOptions = {},
|
|
478
|
-
): Promise<{ imported: number; changes: number }> {
|
|
479
|
-
const changes = await importVcsChanges(shell, cwd, options)
|
|
480
|
-
const now = Date.now()
|
|
481
|
-
for (const change of changes) {
|
|
482
|
-
recordWrite({
|
|
483
|
-
cwd,
|
|
484
|
-
sessionId,
|
|
485
|
-
path: change.path,
|
|
486
|
-
identity: change.path,
|
|
487
|
-
before: change.earlierVersion === 'none' ? null : change.oldText,
|
|
488
|
-
after: change.newText,
|
|
489
|
-
now,
|
|
490
|
-
})
|
|
491
|
-
}
|
|
492
|
-
return { imported: changes.length, changes: changes.length }
|
|
493
|
-
}
|
|
494
|
-
|
|
495
500
|
/**
|
|
496
501
|
* @author ddj 2026年10月30号
|
|
497
502
|
* @description: 撤销或重做最近一次判定。一条路径只有一行撤销记录:撤销回到判定前的两侧内容,
|
|
@@ -517,15 +522,19 @@ export async function undoDecide(
|
|
|
517
522
|
writeOp(cwd, move.operationId, JSON.stringify(move), 'prepared')
|
|
518
523
|
let wrote = false
|
|
519
524
|
if (target.write) {
|
|
525
|
+
// 插件写回会触发 watch:先打自写标记,避免折成一次外部改动。
|
|
526
|
+
windows.markSelf(pathKeyOf(stored.entry.id))
|
|
520
527
|
const result = await writeBack(fs, cwd, stored, target.state, signal, policy)
|
|
521
528
|
if (!result.ok) return { ok: false, reason: result.reason }
|
|
522
529
|
wrote = true
|
|
523
530
|
}
|
|
524
531
|
|
|
525
|
-
|
|
532
|
+
// 撤销/重做后按净差异收尾窗口:撤销 Keep 会重新出现差异 → 重开;重做 → 关窗。
|
|
533
|
+
const entry = applyTracking(target.state.entry, nextTracking(target.state.entry))
|
|
534
|
+
saveEntry(cwd, { entry, flags: target.state.flags })
|
|
526
535
|
saveBlocks(cwd, record.entryId, target.state.blocks)
|
|
527
536
|
setHistoryState(cwd, record.entryId, move.direction === 'undo' ? 'undone' : 'applied')
|
|
528
|
-
const outcome = { ok: true as const, item: itemOf({ entry
|
|
537
|
+
const outcome = { ok: true as const, item: itemOf({ entry, flags: target.state.flags }), wrote }
|
|
529
538
|
writeOp(cwd, move.operationId, JSON.stringify(move), 'committed', { result: JSON.stringify(outcome) })
|
|
530
539
|
return outcome
|
|
531
540
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 差异追踪窗口:判定一条条目是否仍在追踪、一次变化后应处的窗口状态,
|
|
3
|
+
* 以及为面板提供「已被窗口接管过的路径」覆盖集。
|
|
4
|
+
*
|
|
5
|
+
* 窗口规则:
|
|
6
|
+
* - AI 文件工具确认改了内容 → 开窗,基线 = 写前磁盘内容;
|
|
7
|
+
* - 窗口内任何改动都折进同一条差异,基线不动;
|
|
8
|
+
* - 用户处理完(无净差异)或内容回到基线 → 关窗;
|
|
9
|
+
* - 关窗后外部改动不再生成记录,直到 AI 再次改动该文件。
|
|
10
|
+
* @author ddj 2026年11月25号
|
|
11
|
+
*/
|
|
12
|
+
import type { StoredEntry } from './persist.js'
|
|
13
|
+
import { loadEntry } from './persist.js'
|
|
14
|
+
import type { PendingEntry } from './kernel.js'
|
|
15
|
+
import { isSettled } from './kernel.js'
|
|
16
|
+
import type { PendingTracking } from '../shared/pendingReview.js'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @author ddj 2026年11月25号
|
|
20
|
+
* @description: 读条目的窗口状态;缺省按 `open` 解释(旧数据与新建条目默认在追踪中)。
|
|
21
|
+
* @param entry 待审条目
|
|
22
|
+
* @returns 窗口状态
|
|
23
|
+
*/
|
|
24
|
+
export function trackingOf(entry: PendingEntry): PendingTracking {
|
|
25
|
+
// 旧宿主(0.38)不写 opened_at:这类行不是本模型开的窗口,按已关窗处理,
|
|
26
|
+
// 既不在面板显示,也不接收外部改动,避免旧宿主把 Unity 改动继续灌进来。
|
|
27
|
+
if (!entry.openedAt) return 'closed'
|
|
28
|
+
return entry.tracking === 'closed' ? 'closed' : 'open'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @author ddj 2026年11月25号
|
|
33
|
+
* @description: 条目是否仍在追踪窗口内(只有窗口内的文件才接收外部改动)。
|
|
34
|
+
* @param entry 待审条目
|
|
35
|
+
* @returns 在窗口内返回 true
|
|
36
|
+
*/
|
|
37
|
+
export function isOpenEntry(entry: PendingEntry): boolean {
|
|
38
|
+
return trackingOf(entry) === 'open'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @author ddj 2026年11月25号
|
|
43
|
+
* @description: 一次变化后应处的窗口状态:已无净差异就关窗,否则保持打开。
|
|
44
|
+
* @param entry 待审条目
|
|
45
|
+
* @returns 目标窗口状态
|
|
46
|
+
*/
|
|
47
|
+
export function nextTracking(entry: PendingEntry): PendingTracking {
|
|
48
|
+
return isSettled(entry) ? 'closed' : 'open'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @author ddj 2026年11月25号
|
|
53
|
+
* @description: 某个文件当前是否有开着的窗口;官方快照按它决定是否落库。
|
|
54
|
+
* @param cwd 工作区
|
|
55
|
+
* @param identity 后端进程路径(待审条目 id 同源)
|
|
56
|
+
* @returns 开窗中返回 true
|
|
57
|
+
*/
|
|
58
|
+
export function isTrackedPath(cwd: string, identity: string): boolean {
|
|
59
|
+
const stored = loadEntry(cwd, identity)
|
|
60
|
+
return stored !== undefined && isOpenEntry(stored.entry)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @author ddj 2026年11月25号
|
|
65
|
+
* @description: 已被窗口接管过的路径(含已关窗条目):路径与身份两种写法都给出,
|
|
66
|
+
* 用来压住同路径的官方旧行与旧工具记录,避免关窗后它们复活。
|
|
67
|
+
* @param entries 本工作区全部条目(含已关窗)
|
|
68
|
+
* @returns 去重后的路径列表
|
|
69
|
+
*/
|
|
70
|
+
export function coveredPathsOf(entries: readonly StoredEntry[]): string[] {
|
|
71
|
+
const seen = new Set<string>()
|
|
72
|
+
const paths: string[] = []
|
|
73
|
+
for (const stored of entries) {
|
|
74
|
+
for (const path of [stored.entry.path, stored.entry.id]) {
|
|
75
|
+
if (!path || seen.has(path)) continue
|
|
76
|
+
seen.add(path)
|
|
77
|
+
paths.push(path)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return paths
|
|
81
|
+
}
|
package/src/pendingCompat.ts
CHANGED
|
@@ -255,6 +255,8 @@ export function pendingCovers(cwd: string, path: string, sessionId?: string): bo
|
|
|
255
255
|
*/
|
|
256
256
|
export function mergedPage(official: ReviewPage, pending: PendingPage, cwd?: string): ReviewPage {
|
|
257
257
|
const covered = new Set<string>()
|
|
258
|
+
// 已关窗的路径也继续算覆盖:关窗代表用户处理完了,官方旧行不能再冒出来。
|
|
259
|
+
for (const path of pending.coveredPaths ?? []) covered.add(pathKey(path))
|
|
258
260
|
for (const item of pending.items) {
|
|
259
261
|
// 待审条目的 path 是写入时的原始写法(常为工作区相对路径),官方条目用绝对身份:
|
|
260
262
|
// 只按 path 建覆盖集时同一文件会同时留下待审行与官方行,差异栏把一份改动算成两条。
|
|
@@ -263,11 +265,34 @@ export function mergedPage(official: ReviewPage, pending: PendingPage, cwd?: str
|
|
|
263
265
|
}
|
|
264
266
|
const kept = official.items.filter((item) => !covered.has(pathKey(item.currentPath)) && !covered.has(pathKey(item.path)))
|
|
265
267
|
const items = [...pending.items.map((item) => pendingItemOf(item, cwd)), ...kept]
|
|
268
|
+
const overview = official.overview
|
|
269
|
+
? { ...official.overview, coveredPaths: mergePaths(official.overview.coveredPaths, pending.coveredPaths ?? []) }
|
|
270
|
+
: undefined
|
|
266
271
|
return {
|
|
267
272
|
items,
|
|
268
273
|
pending: pending.pending + kept.filter((item) => item.decision === 'pending').length,
|
|
269
274
|
nextCursor: official.nextCursor,
|
|
270
275
|
gaps: official.gaps,
|
|
271
|
-
|
|
276
|
+
pendingCoveredPaths: pending.coveredPaths ?? [],
|
|
277
|
+
...(overview ? { overview } : {}),
|
|
272
278
|
}
|
|
273
279
|
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @private
|
|
283
|
+
* @author ddj 2026年11月25号
|
|
284
|
+
* @description: 合并两组路径并去重;官方覆盖集保持原有顺序,待审覆盖追加在后。
|
|
285
|
+
* @param existing 官方覆盖路径
|
|
286
|
+
* @param added 待审覆盖路径
|
|
287
|
+
* @returns 去重后的路径列表
|
|
288
|
+
*/
|
|
289
|
+
function mergePaths(existing: readonly string[], added: readonly string[]): string[] {
|
|
290
|
+
const seen = new Set(existing)
|
|
291
|
+
const paths = [...existing]
|
|
292
|
+
for (const path of added) {
|
|
293
|
+
if (seen.has(path)) continue
|
|
294
|
+
seen.add(path)
|
|
295
|
+
paths.push(path)
|
|
296
|
+
}
|
|
297
|
+
return paths
|
|
298
|
+
}
|
package/src/pendingRpc.ts
CHANGED
|
@@ -4,12 +4,10 @@ import type { PendingRequest } from './shared/pendingReview.js'
|
|
|
4
4
|
import { resolveScope, sessionOf } from './registry.js'
|
|
5
5
|
import type { Registry } from './registry.js'
|
|
6
6
|
import { bucketOf } from './registry.js'
|
|
7
|
-
import { readText } from './pending/capture.js'
|
|
8
7
|
import { pendingRawId, setPendingCovers, trackPendingCover } from './pendingCompat.js'
|
|
9
|
-
import { loadEntries, pendingVersion
|
|
10
|
-
import { applyDecide,
|
|
11
|
-
import {
|
|
12
|
-
import type { ShellLike } from './pending/vcs.js'
|
|
8
|
+
import { loadEntries, pendingVersion } from './pending/persist.js'
|
|
9
|
+
import { applyDecide, loadDetail, loadPage, purgePending, removeEntry, undoDecide } from './pending/store.js'
|
|
10
|
+
import { captureSync } from './pending/externalCapture.js'
|
|
13
11
|
import type { Ctx } from './store.js'
|
|
14
12
|
import { policyOf } from './store.js'
|
|
15
13
|
|
|
@@ -59,20 +57,6 @@ function failureOf(error: unknown): string {
|
|
|
59
57
|
return error instanceof Error ? error.message : String(error)
|
|
60
58
|
}
|
|
61
59
|
|
|
62
|
-
/**
|
|
63
|
-
* @author ddj 2026年10月30号
|
|
64
|
-
* @description: 按会话策略包装 shell:执行器默认按 workspace-write 跑,本机无可用沙箱后端会直接拒绝。
|
|
65
|
-
* @param raw 原始 shell 能力
|
|
66
|
-
* @param policy 会话沙箱策略
|
|
67
|
-
* @returns 带策略的 shell 视图
|
|
68
|
-
*/
|
|
69
|
-
function shellOf(raw: ShellLike, policy: unknown): ShellLike {
|
|
70
|
-
return {
|
|
71
|
-
resolve: (request) => raw.resolve(policy ? { ...request, sandboxPolicy: policy } : request),
|
|
72
|
-
execute: (spec) => raw.execute(spec),
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
60
|
/**
|
|
77
61
|
* @author ddj 2026年10月30号
|
|
78
62
|
* @description: 读路径处理器:列表与详情,允许跨实例冷读。
|
|
@@ -158,52 +142,20 @@ function historyHandlers(kit: ScopeKit): Partial<RpcHandlerMap> {
|
|
|
158
142
|
}
|
|
159
143
|
|
|
160
144
|
/**
|
|
161
|
-
* @author ddj 2026年10月30号
|
|
162
|
-
* @description:
|
|
145
|
+
* @author ddj 2026年10月30号 / 2026年11月25号
|
|
146
|
+
* @description: 投影维护处理器:校准追踪窗口、清理旧通道条目。
|
|
163
147
|
* @param kit 作用域能力
|
|
164
148
|
* @returns 处理器表
|
|
165
149
|
*/
|
|
166
150
|
function refreshHandlers(kit: ScopeKit): Partial<RpcHandlerMap> {
|
|
167
151
|
return {
|
|
168
|
-
'edrv.pending.import': async (args) => {
|
|
169
|
-
const cwd = await kit.write(args.sessionId)
|
|
170
|
-
const raw = kit.ctx.get('shell') as unknown as ShellLike | undefined
|
|
171
|
-
if (!raw) return { ok: false, error: '当前环境没有 shell 能力,无法读取版本库基线' }
|
|
172
|
-
const policy = policyOf(kit.ctx, sessionOf(kit.ctx, args.sessionId))
|
|
173
|
-
try {
|
|
174
|
-
const shell = shellOf(raw, policy)
|
|
175
|
-
const result = await importFromVcs(shell, cwd, args.sessionId, { includeUntracked: args.includeUntracked, path: args.path })
|
|
176
|
-
const page = loadPage(cwd, args.sessionId)
|
|
177
|
-
setPendingCovers(cwd, args.sessionId, page.items.map((item) => item.path))
|
|
178
|
-
return { ok: true, imported: result.imported, changes: result.changes }
|
|
179
|
-
} catch (error) {
|
|
180
|
-
return { ok: false, error: failureOf(error) }
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
'edrv.pending.refresh': async (args: PendingRequest & { id: string }) => {
|
|
184
|
-
const cwd = await kit.write(args.sessionId)
|
|
185
|
-
const id = pendingRawId(args.id)
|
|
186
|
-
const stored = loadEntries(cwd).find((entry) => entry.entry.id === id)
|
|
187
|
-
if (!stored) return { ok: false, error: '待审条目不存在' }
|
|
188
|
-
const fs = kit.ctx.get('fs')
|
|
189
|
-
const session = sessionOf(kit.ctx, args.sessionId)
|
|
190
|
-
const target = await fs.resolve(id, { cwd, agent: session })
|
|
191
|
-
const content = await readText(fs, target).catch(() => undefined)
|
|
192
|
-
if (content === undefined) return { ok: false, error: '读取失败' }
|
|
193
|
-
const next = refreshed(stored, content, Date.now())
|
|
194
|
-
if (next) saveEntry(cwd, next)
|
|
195
|
-
return { ok: true, item: itemOf(next ?? stored) }
|
|
196
|
-
},
|
|
197
152
|
'edrv.pending.align': async (args) => {
|
|
198
|
-
//
|
|
153
|
+
// 手动校准:把开窗文件与磁盘对齐一次,补上漏掉的 watch 事件;不受 scan 开关限制
|
|
199
154
|
const cwd = await kit.write(args.sessionId)
|
|
200
|
-
const outcome = await
|
|
201
|
-
try { trackPendingCover(write.cwd, write.path, true, write.sessionId) } catch { /* 登记失败不影响落库 */ }
|
|
202
|
-
recordWrite(write)
|
|
203
|
-
})
|
|
155
|
+
const outcome = await captureSync(cwd)
|
|
204
156
|
const page = loadPage(cwd, args.sessionId)
|
|
205
157
|
setPendingCovers(cwd, args.sessionId, page.items.map((item) => item.path))
|
|
206
|
-
return { ok: true,
|
|
158
|
+
return { ok: true, checked: outcome.checked, folded: outcome.folded, gaps: outcome.gaps }
|
|
207
159
|
},
|
|
208
160
|
/**
|
|
209
161
|
* @author ddj 2026-11-24
|