dsh-vscode-mode 0.34.0 → 0.36.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 +25 -4
- package/lib/client.js +63 -63
- package/lib/client.js.map +1 -1
- package/lib/index.js +1841 -73
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/dsh-vscodemode-html-plan/SKILL.md +23 -0
- package/skills/dsh-vscodemode-html-plan/references/blocks.md +14 -0
- package/skills/dsh-vscodemode-html-plan/runtime/htmlplan.css +20 -0
- package/skills/dsh-vscodemode-html-plan/runtime/htmlplan.js +36 -1
- package/skills/dsh-vscodemode-html-plan/runtime/pack.mjs +35 -4
- package/skills/dsh-vscodemode-html-plan/runtime/plan.mjs +17 -6
- package/src/capture.ts +3 -0
- package/src/client/htmlPlan/HtmlPlanPanel.ts +8 -3
- package/src/client/htmlPlan/planPage.ts +31 -1
- 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/htmlPlanAttachments.ts +362 -0
- package/src/htmlPlanCommand.ts +257 -18
- package/src/index.ts +74 -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 +581 -0
- package/src/pending/kernel.ts +19 -1
- package/src/pending/persist.ts +114 -12
- package/src/pending/provenance.ts +239 -0
- package/src/pending/store.ts +30 -4
- package/src/pending/vcs.ts +122 -0
- package/src/pendingCompat.ts +13 -6
- package/src/pendingRpc.ts +19 -2
- package/src/rpc.ts +7 -2
- package/src/shared/pendingReview.ts +19 -1
- package/src/shared/review.ts +3 -1
- package/src/shared/rpc.ts +4 -0
package/src/pending/capture.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { toolTargets, patchDiagnostics, OPS_PREFIX } from '../toolTargets.js'
|
|
|
9
9
|
import { replaceCandidates, BULK_LIMIT } from './bulkTargets.js'
|
|
10
10
|
import type { BulkSearcher } from './bulkTargets.js'
|
|
11
11
|
import { rawText, rawReviewFile } from '../reviewEvidence.js'
|
|
12
|
+
import type { PendingBaseKind, PendingOrigin } from '../shared/pendingReview.js'
|
|
12
13
|
|
|
13
14
|
/** 可被采信为待审来源的写文件工具(含 dsh-ops 的单目标写工具)。 */
|
|
14
15
|
const WRITE_TOOLS = [
|
|
@@ -36,6 +37,21 @@ function recordGap(scope: { cwd: string; sessionId: string }, exec: WriteExec, p
|
|
|
36
37
|
while (captureGaps.size > 500) captureGaps.delete(captureGaps.keys().next().value!)
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
/**
|
|
41
|
+
* @public
|
|
42
|
+
* @author ddj 2026-11-24
|
|
43
|
+
* @description: 外部采集(watch / 补扫)的缺口上报:非文本、超大、读取失败都记进同一份列表,
|
|
44
|
+
* 让面板能把「没记下来」说清楚,而不是静默丢条目。
|
|
45
|
+
* @param cwd 工作区
|
|
46
|
+
* @param sessionId 会话
|
|
47
|
+
* @param path 出问题的路径
|
|
48
|
+
* @param error 原因
|
|
49
|
+
* @returns 无
|
|
50
|
+
*/
|
|
51
|
+
export function noteCaptureGap(cwd: string, sessionId: string, path: string, error: unknown): void {
|
|
52
|
+
recordGap({ cwd, sessionId }, { id: 'external' }, path, error)
|
|
53
|
+
}
|
|
54
|
+
|
|
39
55
|
/** 一次已确认的写入。 */
|
|
40
56
|
export interface PendingWrite {
|
|
41
57
|
cwd: string
|
|
@@ -45,6 +61,12 @@ export interface PendingWrite {
|
|
|
45
61
|
before: string | null
|
|
46
62
|
after: string | null
|
|
47
63
|
now: number
|
|
64
|
+
/** 触发本次写入的工具名;缺省按未知写工具(`tool`)记录。 */
|
|
65
|
+
tool?: string
|
|
66
|
+
/** 显式归属(外部采集用);缺省按时间窗判定。 */
|
|
67
|
+
origin?: PendingOrigin
|
|
68
|
+
/** 修改前内容的可信度(外部采集用);缺省按 before 是否为空推断。 */
|
|
69
|
+
baseKind?: PendingBaseKind
|
|
48
70
|
}
|
|
49
71
|
|
|
50
72
|
/** 采集器。 */
|
|
@@ -105,7 +127,7 @@ export function installPending(
|
|
|
105
127
|
* @param exec 工具分发上下文
|
|
106
128
|
* @returns 采集计划或 null
|
|
107
129
|
*/
|
|
108
|
-
async function planOf(scope: { cwd: string; sessionId: string; fs: any }, state: CaptureState, requested: string): Promise<CapturePlan | null> {
|
|
130
|
+
async function planOf(scope: { cwd: string; sessionId: string; fs: any }, state: CaptureState, requested: string, tool: string): Promise<CapturePlan | null> {
|
|
109
131
|
const { cwd, sessionId, fs } = scope
|
|
110
132
|
if (state.stopped || state.disposed.has(sessionId)) return null
|
|
111
133
|
const target = await fs.resolve(requested, { cwd })
|
|
@@ -118,7 +140,7 @@ async function planOf(scope: { cwd: string; sessionId: string; fs: any }, state:
|
|
|
118
140
|
state.busy.delete(identity)
|
|
119
141
|
return null
|
|
120
142
|
}
|
|
121
|
-
return { cwd: String(cwd), sessionId, path: requested, identity, before, target, fs }
|
|
143
|
+
return { cwd: String(cwd), sessionId, path: requested, identity, before, target, fs, tool }
|
|
122
144
|
} catch (error) {
|
|
123
145
|
state.busy.delete(identity)
|
|
124
146
|
throw error
|
|
@@ -134,6 +156,8 @@ interface CapturePlan {
|
|
|
134
156
|
before: string | null
|
|
135
157
|
target: unknown
|
|
136
158
|
fs: any
|
|
159
|
+
/** 触发本次写入的工具名,用于记录采集通道。 */
|
|
160
|
+
tool: string
|
|
137
161
|
}
|
|
138
162
|
|
|
139
163
|
/** 替换回执里的一条文件结果;只关心目标与完成状态。 */
|
|
@@ -230,10 +254,11 @@ async function buildPlans(
|
|
|
230
254
|
scope: { cwd: string; sessionId: string; fs: any }, state: CaptureState, exec: WriteExec, paths: string[],
|
|
231
255
|
): Promise<CapturePlan[]> {
|
|
232
256
|
const plans: CapturePlan[] = []
|
|
257
|
+
const tool = String(exec.name ?? '')
|
|
233
258
|
for (const path of paths) {
|
|
234
259
|
try {
|
|
235
260
|
if (plans.length >= BULK_LIMIT) throw new Error('capture target budget exceeded')
|
|
236
|
-
const plan = await planOf(scope, state, path)
|
|
261
|
+
const plan = await planOf(scope, state, path, tool)
|
|
237
262
|
if (plan) plans.push(plan)
|
|
238
263
|
} catch (error) {
|
|
239
264
|
if (!state.stopped && !state.disposed.has(scope.sessionId)) recordGap(scope, exec, path, error)
|
|
@@ -316,7 +341,10 @@ async function reportWrite(state: CaptureState, sink: (write: PendingWrite) => v
|
|
|
316
341
|
if (gap.cwd === plan.cwd && gap.sessionId === plan.sessionId && identity[3] === plan.path) captureGaps.delete(key)
|
|
317
342
|
}
|
|
318
343
|
if (plan.before === after) return
|
|
319
|
-
sink({
|
|
344
|
+
sink({
|
|
345
|
+
cwd: plan.cwd, sessionId: plan.sessionId, path: plan.path, identity: plan.identity,
|
|
346
|
+
before: plan.before, after, now: Date.now(), tool: plan.tool,
|
|
347
|
+
})
|
|
320
348
|
}
|
|
321
349
|
|
|
322
350
|
/**
|
package/src/pending/decide.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { keepBlock, revertBlock, textDiff } from './hunks.js'
|
|
|
10
10
|
import type { PendingEntry } from './kernel.js'
|
|
11
11
|
import { applyUpdate, isSettled } from './kernel.js'
|
|
12
12
|
import type { PendingFlags } from './persist.js'
|
|
13
|
+
import { revertPolicyOf, sourceLabelOf } from './provenance.js'
|
|
13
14
|
|
|
14
15
|
/** 写盘结果:`content` 是读回校验通过后的最终内容,null 表示删除。 */
|
|
15
16
|
export type WriteResult = { ok: true; content: string | null } | { ok: false; reason: string }
|
|
@@ -187,18 +188,26 @@ function markAll(states: ReviewBlockState[], targets: ReviewBlock[], decision: '
|
|
|
187
188
|
}
|
|
188
189
|
|
|
189
190
|
/**
|
|
190
|
-
* @author ddj 2026年10月29号
|
|
191
|
-
* @description: 能力口径:Keep 恒可;Revert
|
|
191
|
+
* @author ddj 2026年10月29号 / 2026年11月24号
|
|
192
|
+
* @description: 能力口径:Keep 恒可;Revert 受超大/缺失/已解决/来源限制,拒绝原因要能展示。
|
|
193
|
+
* 撤销白名单:只有 agent 来源且基线可信时直接可撤销,其它来源要求客户端显式确认。
|
|
192
194
|
* @param entry 待审条目
|
|
193
195
|
* @param flags 持久标记
|
|
194
196
|
* @returns 能力与原因
|
|
195
197
|
*/
|
|
196
|
-
export function capabilityOf(entry: PendingEntry, flags: PendingFlags): { keep: boolean; revert: boolean; reason: string } {
|
|
198
|
+
export function capabilityOf(entry: PendingEntry, flags: PendingFlags): { keep: boolean; revert: boolean; reason: string; confirmRevert?: boolean } {
|
|
197
199
|
if (isSettled(entry)) return { keep: false, revert: false, reason: 'settled' }
|
|
198
200
|
if (flags.oversized) return { keep: false, revert: false, reason: 'oversized' }
|
|
201
|
+
if (entry.baseKind === 'unknown') {
|
|
202
|
+
return { keep: true, revert: false, reason: '未捕获修改前内容(外部写入):留档可见,但不能撤销,否则会删掉现有代码' }
|
|
203
|
+
}
|
|
199
204
|
if (entry.earlierVersion === 'none' && entry.newText.length === 0) {
|
|
200
205
|
return { keep: true, revert: false, reason: 'empty-create' }
|
|
201
206
|
}
|
|
207
|
+
const policy = revertPolicyOf(entry.origin, entry.baseKind)
|
|
208
|
+
if (policy === 'confirm') {
|
|
209
|
+
return { keep: true, revert: true, confirmRevert: true, reason: '该改动不是本会话工具写的(' + sourceLabelOf(entry) + '):撤销前请确认' }
|
|
210
|
+
}
|
|
202
211
|
return { keep: true, revert: true, reason: '' }
|
|
203
212
|
}
|
|
204
213
|
|
|
@@ -0,0 +1,297 @@
|
|
|
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
|