dsh-vscode-mode 0.35.0 → 0.37.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 +28 -5
- package/lib/client.js +63 -63
- package/lib/client.js.map +1 -1
- package/lib/index.js +1885 -54
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/dsh-vscodemode-html-plan/SKILL.md +1 -1
- package/src/archivePurge.ts +319 -0
- package/src/capture.ts +3 -0
- package/src/client/addToConversation.ts +77 -18
- package/src/client/htmlPlan/HtmlPlanPanel.ts +9 -13
- package/src/client/htmlPlan/planActions.ts +97 -23
- package/src/client/htmlPlan/planPage.ts +2 -2
- package/src/client/reviewBatch.ts +8 -0
- package/src/client/state/diffSummary.ts +6 -1
- package/src/client/state/reviewFeed.ts +35 -4
- package/src/client/ui/EditorView.ts +7 -0
- package/src/client/ui/McpSettings.ts +21 -0
- package/src/client/ui/OfficialReview.ts +20 -2
- package/src/fileOpenSettings.ts +29 -0
- package/src/index.ts +78 -6
- package/src/mcpManaged.ts +12 -3
- package/src/mcpManagerBridge.ts +5 -1
- package/src/mcpRuntime.ts +33 -4
- package/src/pending/capture.ts +32 -4
- package/src/pending/decide.ts +12 -3
- package/src/pending/externalAlign.ts +297 -0
- package/src/pending/externalCapture.ts +677 -0
- package/src/pending/kernel.ts +19 -1
- package/src/pending/persist.ts +201 -12
- package/src/pending/provenance.ts +239 -0
- package/src/pending/store.ts +67 -6
- package/src/pending/vcs.ts +140 -0
- package/src/pendingCompat.ts +13 -6
- package/src/pendingRpc.ts +37 -2
- package/src/rpc.ts +30 -2
- package/src/shared/pendingReview.ts +19 -1
- package/src/shared/review.ts +3 -1
- package/src/shared/rpc.ts +8 -0
package/src/pending/store.ts
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* 待审投影的工作区存储:把采集到的写入折进单条累计条目,并承接 Keep/Revert 与外部改动的吸收。
|
|
3
3
|
* @author ddj 2026年10月29号
|
|
4
4
|
*/
|
|
5
|
-
import type { PendingDecide, PendingDetail, PendingHistoryMove, PendingItem, PendingPage } from '../shared/pendingReview.js'
|
|
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
8
|
import { addedFiles } from '../reviewDb.js'
|
|
9
|
+
import { pathKeyOf, sourceOfTool, windows } from './provenance.js'
|
|
9
10
|
import type { PendingWrite } from './capture.js'
|
|
10
11
|
import { readText, pendingGaps } from './capture.js'
|
|
11
12
|
import type { ShellLike, VcsImportOptions } from './vcs.js'
|
|
@@ -17,9 +18,10 @@ import type { PendingEntry } from './kernel.js'
|
|
|
17
18
|
import type { PendingFlags, StoredEntry } from './persist.js'
|
|
18
19
|
import type { KeepRecord } from './persist.js'
|
|
19
20
|
import {
|
|
20
|
-
dropEntry, earliestUndone, latestApplied, loadBlocks, loadEntries, pendingDb, pushHistory,
|
|
21
|
-
readOp, saveBlocks, saveDecisions, saveEntry, setHistoryState, writeOp,
|
|
21
|
+
dropEntry, earliestUndone, latestApplied, loadBlocks, loadEntries, pendingDb, purgeEntries, pushHistory,
|
|
22
|
+
readOp, saveBlocks, saveDecisions, saveEntry, setHistoryState, vacuumEntries, writeOp,
|
|
22
23
|
} from './persist.js'
|
|
24
|
+
import type { PurgeFilter, PurgeOutcome } from './persist.js'
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* @author ddj 2026年10月29号
|
|
@@ -70,6 +72,9 @@ export function foldWrite(stored: StoredEntry | undefined, write: PendingWrite):
|
|
|
70
72
|
oldText: write.before ?? '',
|
|
71
73
|
newText: write.after ?? '',
|
|
72
74
|
updatedAt: write.now,
|
|
75
|
+
source: sourceOfTool(write.tool),
|
|
76
|
+
origin: originOf(write),
|
|
77
|
+
baseKind: write.before === null ? 'absent' : (write.baseKind ?? 'known'),
|
|
73
78
|
})
|
|
74
79
|
if (!stored) {
|
|
75
80
|
return {
|
|
@@ -90,6 +95,21 @@ export function foldWrite(stored: StoredEntry | undefined, write: PendingWrite):
|
|
|
90
95
|
}
|
|
91
96
|
}
|
|
92
97
|
|
|
98
|
+
/**
|
|
99
|
+
* @private
|
|
100
|
+
* @author ddj 2026-11-24
|
|
101
|
+
* @description: 本次写入的归属:显式指定优先,否则按窗口判定(工具链路默认 agent)。
|
|
102
|
+
* @param write 采集到的写入
|
|
103
|
+
* @returns 归属
|
|
104
|
+
*/
|
|
105
|
+
function originOf(write: PendingWrite): PendingOrigin {
|
|
106
|
+
if (write.origin) return write.origin
|
|
107
|
+
const window = windows.windowOf(pathKeyOf(write.identity))
|
|
108
|
+
if (window === 'self') return 'agent'
|
|
109
|
+
if (window === 'editor') return 'editor'
|
|
110
|
+
return 'agent'
|
|
111
|
+
}
|
|
112
|
+
|
|
93
113
|
/**
|
|
94
114
|
* @author ddj 2026年10月29号
|
|
95
115
|
* @description: 条目转列表投影,已解决条目仍保留但不可再决定。
|
|
@@ -115,6 +135,9 @@ export function itemOf(stored: StoredEntry, baselineEmpty = false): PendingItem
|
|
|
115
135
|
updatedAt: entry.updatedAt,
|
|
116
136
|
sessionId: entry.sessionId,
|
|
117
137
|
sessionIds: entry.sessionIds,
|
|
138
|
+
source: entry.source ?? 'tool',
|
|
139
|
+
origin: entry.origin ?? 'agent',
|
|
140
|
+
baseKind: entry.baseKind ?? 'known',
|
|
118
141
|
}
|
|
119
142
|
if (entry.lineage !== undefined) item.lineage = entry.lineage
|
|
120
143
|
return item
|
|
@@ -204,9 +227,11 @@ export function recordWrite(write: PendingWrite): void {
|
|
|
204
227
|
* @param now 时间
|
|
205
228
|
* @returns 新条目与标记
|
|
206
229
|
*/
|
|
207
|
-
export function absorbed(stored: StoredEntry, content: string, now: number): StoredEntry {
|
|
230
|
+
export function absorbed(stored: StoredEntry, content: string, now: number, origin?: PendingOrigin): StoredEntry {
|
|
231
|
+
const entry: PendingEntry = { ...stored.entry, newText: content, updatedAt: now, unseen: true }
|
|
232
|
+
if (origin) entry.origin = origin
|
|
208
233
|
return {
|
|
209
|
-
entry
|
|
234
|
+
entry,
|
|
210
235
|
flags: { ...stored.flags, diverged: true, missing: false, revision: stored.flags.revision + 1 },
|
|
211
236
|
}
|
|
212
237
|
}
|
|
@@ -299,7 +324,9 @@ export async function applyDecide(
|
|
|
299
324
|
now: Date.now(),
|
|
300
325
|
write: (content) => {
|
|
301
326
|
if (content === null) return deleteTarget(fs, cwd, stored.entry.id, stored.entry.newText, signal, policy)
|
|
302
|
-
|
|
327
|
+
// 允许重建:文件已被删除时撤销的语义就是「恢复修改前内容」。createIfAbsent 原子创建,
|
|
328
|
+
// 期间有人抢先写了同名文件会失败并回到 diverged,不会覆盖别人的新内容。
|
|
329
|
+
return writerFor(fs, cwd, stored.entry.id, stored.entry.newText, signal, policy, true)(content)
|
|
303
330
|
},
|
|
304
331
|
})
|
|
305
332
|
if (!outcome.ok) return { ok: false, reason: outcome.reason }
|
|
@@ -577,6 +604,40 @@ export function removeEntry(cwd: string, id: string, revision: number): boolean
|
|
|
577
604
|
return true
|
|
578
605
|
}
|
|
579
606
|
|
|
607
|
+
/** 清库回执:命中、删除、保留条数,以及可选的 VACUUM 耗时。 */
|
|
608
|
+
export interface PendingPurgeOutcome extends PurgeOutcome {
|
|
609
|
+
/** VACUUM 耗时毫秒;dryRun 或未清理时为 undefined。 */
|
|
610
|
+
vacuumMs?: number
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/** 清库默认口径:只清 watch 通道、空基线的条目——幽灵记录就长这样。 */
|
|
614
|
+
export const PURGE_DEFAULT_SOURCES = ['watch']
|
|
615
|
+
/** 清库默认基线口径:空基线(改前内容缺失)。 */
|
|
616
|
+
export const PURGE_DEFAULT_BASE_KINDS = ['absent']
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* @public
|
|
620
|
+
* @author ddj 2026-11-24
|
|
621
|
+
* @description: 清掉指定通道的待审条目(幽灵记录治理入口)。dryRun 只报数;
|
|
622
|
+
* 真删之后按需 VACUUM,把已删行占的页还给磁盘。
|
|
623
|
+
* @param cwd 工作区
|
|
624
|
+
* @param filter 筛选条件(缺省 watch + absent)
|
|
625
|
+
* @param options dryRun 只数不删;vacuum 删除后是否回收
|
|
626
|
+
* @returns 命中、删除、保留条数与 VACUUM 耗时
|
|
627
|
+
*/
|
|
628
|
+
export function purgePending(
|
|
629
|
+
cwd: string, filter: PurgeFilter = {}, options: { dryRun?: boolean; vacuum?: boolean } = {},
|
|
630
|
+
): PendingPurgeOutcome {
|
|
631
|
+
const scoped: PurgeFilter = {
|
|
632
|
+
sources: filter.sources && filter.sources.length ? filter.sources : PURGE_DEFAULT_SOURCES,
|
|
633
|
+
baseKinds: filter.baseKinds && filter.baseKinds.length ? filter.baseKinds : PURGE_DEFAULT_BASE_KINDS,
|
|
634
|
+
before: filter.before,
|
|
635
|
+
}
|
|
636
|
+
const outcome = purgeEntries(cwd, scoped, options.dryRun === true)
|
|
637
|
+
if (options.dryRun || !outcome.removed || !options.vacuum) return outcome
|
|
638
|
+
return { ...outcome, vacuumMs: vacuumEntries(cwd) }
|
|
639
|
+
}
|
|
640
|
+
|
|
580
641
|
/**
|
|
581
642
|
* @author ddj 2026年10月29号
|
|
582
643
|
* @description: 取错误码用于拒绝原因,没有则回落到消息文本。
|
package/src/pending/vcs.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { readFile, stat } from 'node:fs/promises'
|
|
7
7
|
import { dirname, join, resolve, sep } from 'node:path'
|
|
8
|
+
import { pathKeyOf } from './provenance.js'
|
|
8
9
|
|
|
9
10
|
/** 支持的版本库种类。 */
|
|
10
11
|
export type VcsKind = 'git' | 'svn' | 'p4'
|
|
@@ -23,6 +24,23 @@ export interface VcsChange {
|
|
|
23
24
|
newText: string | null
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
/** 工作副本相对基线的一条状态(补扫只关心这三类)。 */
|
|
28
|
+
export type VcsEntryStatus = 'modified' | 'added' | 'deleted'
|
|
29
|
+
|
|
30
|
+
/** 一条状态条目:绝对路径与归一状态。 */
|
|
31
|
+
export interface VcsEntry {
|
|
32
|
+
path: string
|
|
33
|
+
status: VcsEntryStatus
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 一次状态探测结果:根目录、种类与「相对基线有改动」的路径集合。 */
|
|
37
|
+
export interface VcsStatus {
|
|
38
|
+
kind: VcsKind
|
|
39
|
+
root: string
|
|
40
|
+
/** 绝对路径比较键 → 状态条目(键由 pathKeyFor 生成,调用方直接比对)。 */
|
|
41
|
+
entries: Map<string, VcsEntry>
|
|
42
|
+
}
|
|
43
|
+
|
|
26
44
|
/** 导入选项。 */
|
|
27
45
|
export interface VcsImportOptions {
|
|
28
46
|
includeUntracked?: boolean
|
|
@@ -365,6 +383,128 @@ async function runCommand(
|
|
|
365
383
|
}
|
|
366
384
|
}
|
|
367
385
|
|
|
386
|
+
/**
|
|
387
|
+
* @author ddj 2026-11-24
|
|
388
|
+
* @description: 只读一条状态命令,取「工作副本相对基线有改动」的路径集合。补扫用它当候选与
|
|
389
|
+
* 「干净」判据:不在集合里的路径,其内容变化只能来自版本库同步,不该记成 agent 改动。
|
|
390
|
+
* 非 git/svn(含 Perforce 与无版本库)一律返回 null,由调用方降级为「只对齐已记录条目」。
|
|
391
|
+
* @param shell shell 能力
|
|
392
|
+
* @param cwd 工作区
|
|
393
|
+
* @param onFailure 失败原因回调(可选):调用方用它把「为什么没有状态」写进采集缺口
|
|
394
|
+
* @returns 状态集合或 null
|
|
395
|
+
*/
|
|
396
|
+
export async function vcsStatus(
|
|
397
|
+
shell: ShellLike, cwd: string, onFailure?: (reason: string) => void,
|
|
398
|
+
): Promise<VcsStatus | null> {
|
|
399
|
+
const detected = await detectVcsRoot(cwd)
|
|
400
|
+
if (!detected) {
|
|
401
|
+
onFailure?.('不是 git/svn 工作副本')
|
|
402
|
+
return null
|
|
403
|
+
}
|
|
404
|
+
if (detected.kind === 'p4') {
|
|
405
|
+
onFailure?.('Perforce 工作副本不支持状态探测')
|
|
406
|
+
return null
|
|
407
|
+
}
|
|
408
|
+
return detected.kind === 'git' ? gitStatus(shell, detected.root, onFailure) : svnStatus(shell, detected.root, onFailure)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* @private
|
|
413
|
+
* @author ddj 2026-11-24
|
|
414
|
+
* @description: git 状态:一条 status 命令解析出改动集合。
|
|
415
|
+
* @param shell shell 能力
|
|
416
|
+
* @param root 仓库根
|
|
417
|
+
* @param onFailure 失败原因回调(可选)
|
|
418
|
+
* @returns 状态集合或 null(命令失败)
|
|
419
|
+
*/
|
|
420
|
+
async function gitStatus(shell: ShellLike, root: string, onFailure?: (reason: string) => void): Promise<VcsStatus | null> {
|
|
421
|
+
const status = await runCommand(shell, 'git -c status.renames=false status --porcelain=v1 -z --untracked-files=all', root)
|
|
422
|
+
if (!status.ok) {
|
|
423
|
+
onFailure?.('git status 失败:' + status.stderr.slice(0, 200))
|
|
424
|
+
return null
|
|
425
|
+
}
|
|
426
|
+
const entries = new Map<string, VcsEntry>()
|
|
427
|
+
for (const entry of parseGitStatus(status.stdout)) {
|
|
428
|
+
const absolute = join(root, ...entry.path.split(GIT_SEPARATOR))
|
|
429
|
+
if (!insideRoot(root, absolute)) continue
|
|
430
|
+
entries.set(pathKeyOf(absolute), { path: absolute, status: gitStatusOf(entry.status) })
|
|
431
|
+
}
|
|
432
|
+
return { kind: 'git', root, entries }
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* @private
|
|
437
|
+
* @author ddj 2026-11-24
|
|
438
|
+
* @description: svn 状态:一条 status --xml 解析出改动集合。
|
|
439
|
+
* @param shell shell 能力
|
|
440
|
+
* @param root 工作副本根
|
|
441
|
+
* @param onFailure 失败原因回调(可选)
|
|
442
|
+
* @returns 状态集合或 null(命令失败)
|
|
443
|
+
*/
|
|
444
|
+
async function svnStatus(shell: ShellLike, root: string, onFailure?: (reason: string) => void): Promise<VcsStatus | null> {
|
|
445
|
+
const status = await runCommand(shell, 'svn status --xml', root)
|
|
446
|
+
if (!status.ok) {
|
|
447
|
+
onFailure?.('svn status 失败:' + status.stderr.slice(0, 200))
|
|
448
|
+
return null
|
|
449
|
+
}
|
|
450
|
+
const entries = new Map<string, VcsEntry>()
|
|
451
|
+
for (const entry of parseSvnStatus(status.stdout)) {
|
|
452
|
+
const absolute = resolve(root, entry.path)
|
|
453
|
+
if (!insideRoot(root, absolute)) continue
|
|
454
|
+
entries.set(pathKeyOf(absolute), { path: absolute, status: svnStatusOf(entry.status) })
|
|
455
|
+
}
|
|
456
|
+
return { kind: 'svn', root, entries }
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* @private
|
|
461
|
+
* @author ddj 2026-11-24
|
|
462
|
+
* @description: git 状态码归一:删除优先,其次新增/未跟踪,其余按修改。
|
|
463
|
+
* @param status 两位状态码
|
|
464
|
+
* @returns 归一状态
|
|
465
|
+
*/
|
|
466
|
+
function gitStatusOf(status: string): VcsEntryStatus {
|
|
467
|
+
if (status.includes('D')) return 'deleted'
|
|
468
|
+
if (status === '??' || status.includes('A')) return 'added'
|
|
469
|
+
return 'modified'
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* @private
|
|
474
|
+
* @author ddj 2026-11-24
|
|
475
|
+
* @description: svn 条目状态归一。
|
|
476
|
+
* @param status wc-status 的 item 值
|
|
477
|
+
* @returns 归一状态
|
|
478
|
+
*/
|
|
479
|
+
function svnStatusOf(status: string): VcsEntryStatus {
|
|
480
|
+
if (status === 'deleted' || status === 'missing') return 'deleted'
|
|
481
|
+
if (status === 'added' || status === 'unversioned' || status === 'replaced') return 'added'
|
|
482
|
+
return 'modified'
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* @author ddj 2026-11-24
|
|
487
|
+
* @description: 读某路径的版本库基线内容;只用于补录记录的修改前内容。
|
|
488
|
+
* @param shell shell 能力
|
|
489
|
+
* @param status 已探测的状态(给根目录与种类)
|
|
490
|
+
* @param absolute 绝对路径
|
|
491
|
+
* @returns 基线内容;读不到返回 null
|
|
492
|
+
*/
|
|
493
|
+
export async function vcsBaselineOf(
|
|
494
|
+
shell: ShellLike, status: Pick<VcsStatus, 'kind' | 'root'>, absolute: string,
|
|
495
|
+
): Promise<string | null> {
|
|
496
|
+
const root = status.root
|
|
497
|
+
const relative = absolute.slice(root.length).replace(/^[\\/]+/, '').split(sep).join(GIT_SEPARATOR)
|
|
498
|
+
if (!relative) return null
|
|
499
|
+
try {
|
|
500
|
+
if (status.kind === 'git') return await gitBaseline(shell, root, relative)
|
|
501
|
+
const shown = await runCommand(shell, `svn cat -r BASE ${quote(absolute)}`, root)
|
|
502
|
+
return shown.ok ? shown.stdout : null
|
|
503
|
+
} catch {
|
|
504
|
+
return null
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
368
508
|
/**
|
|
369
509
|
* @author ddj 2026年10月30号
|
|
370
510
|
* @description: 读单元格文本,不存在时返回 null。
|
package/src/pendingCompat.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import type { ReviewDetail, ReviewItem, ReviewPage } from './shared/review.js'
|
|
7
7
|
import type { PendingDetail, PendingItem, PendingPage } from './shared/pendingReview.js'
|
|
8
8
|
import { pathKeyFor } from './shared/pathKey.js'
|
|
9
|
+
import { sourceLabelOf } from './pending/provenance.js'
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* 进程内"已被待审接管"的路径集合;旧写入口守卫只读它,绝不碰数据库。
|
|
@@ -102,7 +103,7 @@ export function pendingDisplay(cwd: string, path: string): string {
|
|
|
102
103
|
* @returns 面板列表项
|
|
103
104
|
*/
|
|
104
105
|
export function pendingItemOf(item: PendingItem, cwd?: string): ReviewItem {
|
|
105
|
-
|
|
106
|
+
const row: ReviewItem = {
|
|
106
107
|
id: PENDING_PREFIX + item.id,
|
|
107
108
|
sessionId: item.sessionId,
|
|
108
109
|
turn: 0,
|
|
@@ -117,6 +118,9 @@ export function pendingItemOf(item: PendingItem, cwd?: string): ReviewItem {
|
|
|
117
118
|
revision: item.revision,
|
|
118
119
|
current: true,
|
|
119
120
|
}
|
|
121
|
+
// 来源徽标只对待审条目有意义:官方行没有采集通道。
|
|
122
|
+
if (item.settled !== true) row.sourceLabel = sourceLabelOf(item)
|
|
123
|
+
return row
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
/**
|
|
@@ -127,16 +131,19 @@ export function pendingItemOf(item: PendingItem, cwd?: string): ReviewItem {
|
|
|
127
131
|
* @returns 面板详情
|
|
128
132
|
*/
|
|
129
133
|
export function pendingDetailOf(detail: PendingDetail, capturedAt: string, cwd?: string): ReviewDetail {
|
|
134
|
+
const capability: ReviewDetail['capability'] = {
|
|
135
|
+
keep: detail.capability.keep,
|
|
136
|
+
undo: detail.capability.revert,
|
|
137
|
+
reason: detail.capability.reason,
|
|
138
|
+
}
|
|
139
|
+
// 非 agent 来源的撤销需要客户端先确认:能力位原样透出,由界面弹一次确认。
|
|
140
|
+
if (detail.capability.confirmRevert === true) capability.confirmUndo = true
|
|
130
141
|
return {
|
|
131
142
|
item: pendingItemOf(detail.item, cwd),
|
|
132
143
|
diff: detail.diff,
|
|
133
144
|
capturedAt,
|
|
134
145
|
blocks: detail.blocks,
|
|
135
|
-
capability
|
|
136
|
-
keep: detail.capability.keep,
|
|
137
|
-
undo: detail.capability.revert,
|
|
138
|
-
reason: detail.capability.reason,
|
|
139
|
-
},
|
|
146
|
+
capability,
|
|
140
147
|
}
|
|
141
148
|
}
|
|
142
149
|
|
package/src/pendingRpc.ts
CHANGED
|
@@ -6,8 +6,9 @@ import type { Registry } from './registry.js'
|
|
|
6
6
|
import { bucketOf } from './registry.js'
|
|
7
7
|
import { readText } from './pending/capture.js'
|
|
8
8
|
import { pendingRawId, setPendingCovers, trackPendingCover } from './pendingCompat.js'
|
|
9
|
-
import { loadEntries, saveEntry } from './pending/persist.js'
|
|
10
|
-
import { applyDecide, importFromVcs, itemOf, loadDetail, loadPage, refreshed, removeEntry, undoDecide } from './pending/store.js'
|
|
9
|
+
import { loadEntries, pendingVersion, saveEntry } from './pending/persist.js'
|
|
10
|
+
import { applyDecide, importFromVcs, itemOf, loadDetail, loadPage, purgePending, recordWrite, refreshed, removeEntry, undoDecide } from './pending/store.js'
|
|
11
|
+
import { alignInWorkspace } from './pending/externalAlign.js'
|
|
11
12
|
import type { ShellLike } from './pending/vcs.js'
|
|
12
13
|
import type { Ctx } from './store.js'
|
|
13
14
|
import { policyOf } from './store.js'
|
|
@@ -94,6 +95,11 @@ function readHandlers(kit: ScopeKit): Partial<RpcHandlerMap> {
|
|
|
94
95
|
const detail = loadDetail(cwd, rawId)
|
|
95
96
|
return detail ? { ok: true, detail } : { ok: false, error: '待审条目不存在' }
|
|
96
97
|
},
|
|
98
|
+
'edrv.pending.version': async (args: PendingRequest) => {
|
|
99
|
+
// 只读内存计数:供客户端用 1s 轻量轮询替代把整页列表拉到 5s 一次
|
|
100
|
+
const cwd = await kit.read(args.sessionId)
|
|
101
|
+
return { ok: true, version: pendingVersion(cwd) }
|
|
102
|
+
},
|
|
97
103
|
}
|
|
98
104
|
}
|
|
99
105
|
|
|
@@ -188,6 +194,35 @@ function refreshHandlers(kit: ScopeKit): Partial<RpcHandlerMap> {
|
|
|
188
194
|
if (next) saveEntry(cwd, next)
|
|
189
195
|
return { ok: true, item: itemOf(next ?? stored) }
|
|
190
196
|
},
|
|
197
|
+
'edrv.pending.align': async (args) => {
|
|
198
|
+
// 手动补扫:与启动对齐同一条路径,只是明确要求本端活跃会话
|
|
199
|
+
const cwd = await kit.write(args.sessionId)
|
|
200
|
+
const outcome = await alignInWorkspace(kit.ctx, cwd, args.sessionId, (write) => {
|
|
201
|
+
try { trackPendingCover(write.cwd, write.path, true, write.sessionId) } catch { /* 登记失败不影响落库 */ }
|
|
202
|
+
recordWrite(write)
|
|
203
|
+
})
|
|
204
|
+
const page = loadPage(cwd, args.sessionId)
|
|
205
|
+
setPendingCovers(cwd, args.sessionId, page.items.map((item) => item.path))
|
|
206
|
+
return { ok: true, imported: outcome.imported, changed: outcome.changed, gaps: outcome.gaps }
|
|
207
|
+
},
|
|
208
|
+
/**
|
|
209
|
+
* @author ddj 2026-11-24
|
|
210
|
+
* @description: 清掉指定通道的幽灵记录。dryRun 只报数;真删后按需 VACUUM,
|
|
211
|
+
* 并重建「待审接管」集合,避免旧路径继续顶掉官方行。
|
|
212
|
+
* @param args 清理请求
|
|
213
|
+
* @returns 命中、删除、保留条数与 VACUUM 耗时
|
|
214
|
+
*/
|
|
215
|
+
'edrv.pending.purge': async (args) => {
|
|
216
|
+
const cwd = await kit.write(args.sessionId)
|
|
217
|
+
const outcome = purgePending(cwd, {
|
|
218
|
+
sources: args.sources,
|
|
219
|
+
baseKinds: args.baseKinds,
|
|
220
|
+
before: args.before,
|
|
221
|
+
}, { dryRun: args.dryRun === true, vacuum: true })
|
|
222
|
+
const page = loadPage(cwd, args.sessionId)
|
|
223
|
+
setPendingCovers(cwd, args.sessionId, page.items.map((item) => item.path))
|
|
224
|
+
return { ok: true, matched: outcome.matched, removed: outcome.removed, kept: outcome.kept, vacuumMs: outcome.vacuumMs }
|
|
225
|
+
},
|
|
191
226
|
}
|
|
192
227
|
}
|
|
193
228
|
|
package/src/rpc.ts
CHANGED
|
@@ -25,6 +25,7 @@ import { cp, mkdir, readFile, rename, rm, stat, writeFile, readdir } from 'node:
|
|
|
25
25
|
import { basename, dirname, join } from 'node:path'
|
|
26
26
|
import { archiveEntryFor, markDecision, recordResolved, reconstructOriginal } from './model.js'
|
|
27
27
|
import { clearRevertState, listArchives, pageArchives, readArchives, revertState, setRevertState, startReverts } from './archiveDb.js'
|
|
28
|
+
import { purgeArchiveDb } from './archivePurge.js'
|
|
28
29
|
import { hasOfficial } from './reviewDb.js'
|
|
29
30
|
import { log } from './log.js'
|
|
30
31
|
import type { Registry, SessionScope } from './registry.js'
|
|
@@ -55,6 +56,7 @@ import type { EncodingVerdict } from './textEncoding.js'
|
|
|
55
56
|
import { backupPathOf, classifyEncoding, decodePreview, isEncodingError, lossyCountOf, repairBytes } from './textEncoding.js'
|
|
56
57
|
import { baseNameOf, checkNewName, checkRenameName, isSubPath, joinRelPath, parentRelOf } from './shared/fsNames.js'
|
|
57
58
|
import { invalidateIndex, listDirCached } from './treeIndex.js'
|
|
59
|
+
import { pathKeyOf, windows } from './pending/provenance.js'
|
|
58
60
|
import { findRemoteWs, remoteDisplayOf, type RemoteWs } from './remoteWorkspace.js'
|
|
59
61
|
import { revealInExplorer } from './reveal.js'
|
|
60
62
|
import { dshHome, debugLogFile, pluginLogRoot, uiGlobalsFile, uiStateFile } from './paths.js'
|
|
@@ -377,9 +379,13 @@ async function afterManualSave(
|
|
|
377
379
|
registry: Registry,
|
|
378
380
|
sc: { session: Session; cwd: string },
|
|
379
381
|
path: string,
|
|
382
|
+
identity?: string,
|
|
380
383
|
): Promise<void> {
|
|
381
384
|
// 手动保存后目录树可能变化(新建/删除文件):父目录+祖先进失效,后台自愈。
|
|
382
385
|
invalidateIndex(ctx, sc.cwd, path)
|
|
386
|
+
// 这是用户自己在编辑器里保存:打标记让外部改动采集只推进基线,不新建待审行。
|
|
387
|
+
// 标记必须用解析后的绝对身份,否则与 watch 事件的比较键对不上。
|
|
388
|
+
windows.markEditor(pathKeyOf(identity ?? path))
|
|
383
389
|
// Editing disk is not a review decision. Keep all historical pending records;
|
|
384
390
|
// location checks may report conflict but must not silently accept or archive them.
|
|
385
391
|
}
|
|
@@ -1082,7 +1088,7 @@ export function buildHandlers(
|
|
|
1082
1088
|
const rev = typeof args.rev === 'string' && args.rev ? args.rev : null
|
|
1083
1089
|
const intent = rev ? { kind: 'replaceIfVersion', version: rev } : undefined
|
|
1084
1090
|
const outcome = await fs.writeText(target, args.content, intent, void 0, policyOf(ctx, sc.session))
|
|
1085
|
-
await afterManualSave(ctx, registry, sc, args.path)
|
|
1091
|
+
await afterManualSave(ctx, registry, sc, args.path, fs.processPath(target))
|
|
1086
1092
|
return { ok: true, rev: outcome?.version ? String(outcome.version) : rev ?? undefined }
|
|
1087
1093
|
} catch (error) {
|
|
1088
1094
|
if (isStaleVersion(error)) {
|
|
@@ -1111,7 +1117,7 @@ export function buildHandlers(
|
|
|
1111
1117
|
if (bytes.byteLength === 0) return { ok: false, error: '内容为空,拒绝写回' }
|
|
1112
1118
|
if (bytes.byteLength > BINARY_READ_CAP) return { ok: false, error: '内容过大(>32MB),拒绝写回' }
|
|
1113
1119
|
await writeFile(fs.processPath(target), bytes)
|
|
1114
|
-
await afterManualSave(ctx, registry, sc, args.path)
|
|
1120
|
+
await afterManualSave(ctx, registry, sc, args.path, fs.processPath(target))
|
|
1115
1121
|
return { ok: true }
|
|
1116
1122
|
} catch (error) {
|
|
1117
1123
|
return { ok: false, error: '二进制保存失败:' + String(error) }
|
|
@@ -1130,6 +1136,28 @@ export function buildHandlers(
|
|
|
1130
1136
|
return { ok: false, error: '归档列表读取失败:' + String(error) }
|
|
1131
1137
|
}
|
|
1132
1138
|
},
|
|
1139
|
+
/**
|
|
1140
|
+
* @author ddj 2026-11-24
|
|
1141
|
+
* @description: 归档库清理:保留期 + 每文件上限 + 撤销栈截断。缺省 dryRun,显式传 false 才删。
|
|
1142
|
+
* @param args 清理参数
|
|
1143
|
+
* @returns 三个统计口径与删除行数
|
|
1144
|
+
*/
|
|
1145
|
+
'edrv.archive.purge': async (args) => {
|
|
1146
|
+
const sc = await resolveScope(ctx, args.sessionId)
|
|
1147
|
+
if ('err' in sc) return { ok: false, error: sc.err }
|
|
1148
|
+
try {
|
|
1149
|
+
const outcome = purgeArchiveDb(sc.cwd, {
|
|
1150
|
+
dryRun: args.dryRun !== false,
|
|
1151
|
+
retentionDays: args.retentionDays,
|
|
1152
|
+
keepBatches: args.keepBatches,
|
|
1153
|
+
keepHistory: args.keepHistory,
|
|
1154
|
+
vacuum: args.vacuum,
|
|
1155
|
+
})
|
|
1156
|
+
return { ok: true, ...outcome }
|
|
1157
|
+
} catch (error) {
|
|
1158
|
+
return { ok: false, error: '归档清理失败:' + String(error) }
|
|
1159
|
+
}
|
|
1160
|
+
},
|
|
1133
1161
|
'edrv.archivePage': async (args) => {
|
|
1134
1162
|
const sc = await resolveScope(ctx, args.sessionId)
|
|
1135
1163
|
if ('err' in sc) return { ok: false, error: sc.err }
|
|
@@ -9,6 +9,18 @@ import type { ReviewBlockState } from './reviewRegions.js'
|
|
|
9
9
|
/** 基线形态:`file` 写回内容,`none` 说明基线没有该路径(Revert 语义是删除文件)。 */
|
|
10
10
|
export type PendingEarlier = 'file' | 'none'
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* 采集通道:谁把这次变化变成了一条记录。
|
|
14
|
+
* `tool` 是旧记录与未知写工具的默认值;`remote_ssh_write` 目前只走旧链路,为桥接保留。
|
|
15
|
+
*/
|
|
16
|
+
export type PendingSource = 'edit' | 'write' | 'remote_ssh_write' | 'tool' | 'watch' | 'scan' | 'vcs'
|
|
17
|
+
|
|
18
|
+
/** 归属:谁动的文件。撤销白名单只看它。 */
|
|
19
|
+
export type PendingOrigin = 'agent' | 'editor' | 'vcs' | 'external'
|
|
20
|
+
|
|
21
|
+
/** 修改前内容的可信度:known 已知内容,absent 当时不存在,vcs 版本库基线,unknown 拿不到。 */
|
|
22
|
+
export type PendingBaseKind = 'known' | 'absent' | 'vcs' | 'unknown'
|
|
23
|
+
|
|
12
24
|
/** 会话血缘,用于子代理/派生会话归属到同一待审视图。 */
|
|
13
25
|
export interface PendingLineage {
|
|
14
26
|
parentSessionId?: string
|
|
@@ -41,6 +53,12 @@ export interface PendingItem {
|
|
|
41
53
|
sessionId: string
|
|
42
54
|
sessionIds: string[]
|
|
43
55
|
lineage?: PendingLineage
|
|
56
|
+
/** 采集通道;旧条目没有该字段,按 `tool` 处理。 */
|
|
57
|
+
source?: PendingSource
|
|
58
|
+
/** 归属;旧条目没有该字段,按 `agent` 处理。 */
|
|
59
|
+
origin?: PendingOrigin
|
|
60
|
+
/** 修改前内容的可信度;旧条目没有该字段,按 `known` 处理。 */
|
|
61
|
+
baseKind?: PendingBaseKind
|
|
44
62
|
}
|
|
45
63
|
|
|
46
64
|
/** 一页待审条目。 */
|
|
@@ -57,7 +75,7 @@ export interface PendingDetail {
|
|
|
57
75
|
item: PendingItem
|
|
58
76
|
diff: OfficialDiff
|
|
59
77
|
blocks: ReviewBlockState[]
|
|
60
|
-
capability: { keep: boolean; revert: boolean; reason: string }
|
|
78
|
+
capability: { keep: boolean; revert: boolean; reason: string; confirmRevert?: boolean }
|
|
61
79
|
}
|
|
62
80
|
|
|
63
81
|
/** 全部请求都带会话作用域,工作区由 host 解析,永不采信客户端 cwd。 */
|
package/src/shared/review.ts
CHANGED
|
@@ -55,6 +55,8 @@ export interface ReviewItem {
|
|
|
55
55
|
decision: ReviewFileDecision
|
|
56
56
|
revision: number
|
|
57
57
|
current: boolean
|
|
58
|
+
/** 待审条目的来源徽标(如「watch · agent」);官方行为空。 */
|
|
59
|
+
sourceLabel?: string
|
|
58
60
|
}
|
|
59
61
|
export interface ReviewDetail {
|
|
60
62
|
item: ReviewItem
|
|
@@ -62,7 +64,7 @@ export interface ReviewDetail {
|
|
|
62
64
|
capturedAt: string
|
|
63
65
|
blocks: import('./reviewRegions.js').ReviewBlockState[]
|
|
64
66
|
/** live 缺省视为未知:只有 host 明确给出 false 时才代表会话不在本端活跃。 */
|
|
65
|
-
capability: { keep: boolean; undo: boolean; reason: string; live?: boolean }
|
|
67
|
+
capability: { keep: boolean; undo: boolean; reason: string; live?: boolean; confirmUndo?: boolean }
|
|
66
68
|
}
|
|
67
69
|
export interface CaptureGap {
|
|
68
70
|
sessionId: string
|
package/src/shared/rpc.ts
CHANGED
|
@@ -392,6 +392,9 @@ export interface RpcRequestMap {
|
|
|
392
392
|
'edrv.pending.refresh': PendingRequest & { id: string }
|
|
393
393
|
'edrv.pending.history': PendingHistoryMove
|
|
394
394
|
'edrv.pending.import': PendingImport
|
|
395
|
+
'edrv.pending.align': PendingRequest & { includeUntracked?: boolean }
|
|
396
|
+
'edrv.pending.purge': PendingRequest & { dryRun?: boolean; sources?: string[]; baseKinds?: string[]; before?: number }
|
|
397
|
+
'edrv.pending.version': PendingRequest
|
|
395
398
|
'edrv.list': { sessionId?: string; callIds?: string[]; skipStale?: boolean }
|
|
396
399
|
'edrv.accept': { sessionId?: string; callId: string; scope?: RpcScope; hunkIndex?: number }
|
|
397
400
|
'edrv.reject': { sessionId?: string; callId: string; scope?: RpcScope; hunkIndex?: number }
|
|
@@ -409,6 +412,7 @@ export interface RpcRequestMap {
|
|
|
409
412
|
'edrv.archiveList': { sessionId?: string }
|
|
410
413
|
'edrv.archivePage': { sessionId?: string; cursor?: string; limit?: number }
|
|
411
414
|
'edrv.archiveRead': { sessionId?: string; path?: string; batch?: number | null }
|
|
415
|
+
'edrv.archive.purge': { sessionId?: string; dryRun?: boolean; retentionDays?: number; keepBatches?: number; keepHistory?: number; vacuum?: boolean }
|
|
412
416
|
'edrv.rollback': { sessionId?: string; path: string; batch?: number }
|
|
413
417
|
'edrv.debug': { sessionId?: string; text: string; level?: LoggerLevel }
|
|
414
418
|
'edrv.dlog.list': { sessionId?: string }
|
|
@@ -600,6 +604,9 @@ export interface RpcOkMap {
|
|
|
600
604
|
'edrv.pending.refresh': { item: PendingItem }
|
|
601
605
|
'edrv.pending.history': { item: PendingItem; wrote: boolean }
|
|
602
606
|
'edrv.pending.import': { imported: number; changes: number }
|
|
607
|
+
'edrv.pending.align': { imported: number; changed: number; gaps: string[] }
|
|
608
|
+
'edrv.pending.purge': { matched: number; removed: number; kept: number; vacuumMs?: number }
|
|
609
|
+
'edrv.pending.version': { version: number }
|
|
603
610
|
'edrv.list': { records: RecordView[] }
|
|
604
611
|
'edrv.accept': { record: RecordView }
|
|
605
612
|
'edrv.reject': { record: RecordView }
|
|
@@ -617,6 +624,7 @@ export interface RpcOkMap {
|
|
|
617
624
|
'edrv.archiveList': { entries: ArchiveEntry[] }
|
|
618
625
|
'edrv.archivePage': { entries: ArchiveEntry[]; nextCursor: string | null }
|
|
619
626
|
'edrv.archiveRead': { batches: ArchiveBatch[] }
|
|
627
|
+
'edrv.archive.purge': { expired: number; overCap: number; keptPending: number; removed: { records: number; batches: number; history: number }; vacuumMs?: number }
|
|
620
628
|
'edrv.rollback': { path: string; batch: number | null }
|
|
621
629
|
'edrv.debug': object
|
|
622
630
|
'edrv.dlog.list': { root: string; files: DebugLogFileInfo[]; current: string | null }
|