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/index.ts
CHANGED
|
@@ -4,9 +4,15 @@ import { captureToolResult } from './capture.js'
|
|
|
4
4
|
import { installCapture } from './officialCapture.js'
|
|
5
5
|
import { installEvidence } from './reviewCapture.js'
|
|
6
6
|
import { installPending } from './pending/capture.js'
|
|
7
|
+
import type { PendingWrite } from './pending/capture.js'
|
|
8
|
+
import { installExternalCapture, VCS_WRITE_METHODS, VCS_WRITE_TOOLS } from './pending/externalCapture.js'
|
|
9
|
+
import { windows } from './pending/provenance.js'
|
|
7
10
|
import { recordWrite } from './pending/store.js'
|
|
11
|
+
import { cwdOfSession } from './store.js'
|
|
12
|
+
import { resolveScope } from './registry.js'
|
|
8
13
|
import { trackPendingCover } from './pendingCompat.js'
|
|
9
14
|
import { closeArchiveDbs } from './archiveDb.js'
|
|
15
|
+
import { startArchiveSweep } from './archivePurge.js'
|
|
10
16
|
import { handleRpc, integrationBaseUrlOf } from './rpc.js'
|
|
11
17
|
import { newSearcher } from './search/orchestrator.js'
|
|
12
18
|
import { newContentSearcher } from './search/content.js'
|
|
@@ -64,7 +70,7 @@ function createRuntime(ctx: Ctx, config: unknown) {
|
|
|
64
70
|
const svnRpc = createSvnRpc({ ctx, settings })
|
|
65
71
|
const dapRpc = createDapRpc(ctx)
|
|
66
72
|
const fileVersions = createFileVersions(ctx)
|
|
67
|
-
return { registry, searcher, contentSearcher, lspManager, lspRpc, aiRpc, svnRpc, dapRpc, fileVersions }
|
|
73
|
+
return { registry, searcher, contentSearcher, lspManager, lspRpc, aiRpc, svnRpc, dapRpc, fileVersions, settings }
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
/**
|
|
@@ -73,14 +79,49 @@ function createRuntime(ctx: Ctx, config: unknown) {
|
|
|
73
79
|
* @param ctx Host context.
|
|
74
80
|
* @param runtime Managers created by this instance.
|
|
75
81
|
*/
|
|
76
|
-
function attachRuntime(ctx: Ctx, runtime: Runtime):
|
|
82
|
+
function attachRuntime(ctx: Ctx, runtime: Runtime): { external: ReturnType<typeof installExternalCapture> } {
|
|
77
83
|
const evidence = installEvidence(ctx)
|
|
78
84
|
const stopCapture = installCapture(ctx, (cwd, snapshot) => { evidence.persist(cwd, snapshot); return true })
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
/** @author ddj 2026年11月24号 @param write 已确认的一次写入 @returns 无;落库失败不打断用户工具调用 */
|
|
86
|
+
function recordPendingWrite(write: PendingWrite): void {
|
|
81
87
|
try { trackPendingCover(write.cwd, write.path, true, write.sessionId) } catch { /* 内存登记失败不阻断采集 */ }
|
|
82
88
|
try { recordWrite(write) } catch (error) { log.warn('待审差异落库失败:' + String(error)) }
|
|
89
|
+
}
|
|
90
|
+
// 待审累计基线:只有写后内容确实变化才落库,异常一律不打断用户工具调用
|
|
91
|
+
const pending = installPending(ctx, recordPendingWrite)
|
|
92
|
+
// 外部改动采集:非 DSH 文件工具(bash 里的 node -e、脚本、生成器)写盘也进审查面板
|
|
93
|
+
const external = installExternalCapture({
|
|
94
|
+
ctx,
|
|
95
|
+
settings: () => runtime.settings.external(),
|
|
96
|
+
record: recordPendingWrite,
|
|
83
97
|
})
|
|
98
|
+
// 归档库每日清理:保留期 + 每文件上限,独立于会话存续
|
|
99
|
+
const sweep = startArchiveSweep()
|
|
100
|
+
/**
|
|
101
|
+
* @author ddj 2026年11月24号
|
|
102
|
+
* @description: 任一工具调用期间都是 agent 写入窗口:bash / python 写盘落在窗口内时归属 agent。
|
|
103
|
+
* 版本库写工具结束后再补扫一次,把命令造成的成片变化对齐进待审投影。
|
|
104
|
+
* @param exec 工具执行描述
|
|
105
|
+
* @param next 原始分发
|
|
106
|
+
* @returns 原始结果
|
|
107
|
+
*/
|
|
108
|
+
function aroundToolWindow(exec: { name?: unknown; agent?: { session?: unknown } }, next: () => Promise<unknown>): Promise<unknown> {
|
|
109
|
+
windows.enterTool()
|
|
110
|
+
return Promise.resolve()
|
|
111
|
+
.then(next)
|
|
112
|
+
.finally(() => {
|
|
113
|
+
windows.exitTool()
|
|
114
|
+
if (!VCS_WRITE_TOOLS.has(String(exec.name ?? ''))) return
|
|
115
|
+
const cwd = cwdOfSession(ctx, exec.agent?.session)
|
|
116
|
+
if (cwd) external.requestAlign(cwd)
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
/** @author ddj 2026年11月24号 @param session 新建会话 @returns 无;工作区可用即开始监听 */
|
|
120
|
+
function onCreated(session: { id?: unknown }): void {
|
|
121
|
+
if (typeof session.id !== 'string') return
|
|
122
|
+
const cwd = cwdOfSession(ctx, session)
|
|
123
|
+
if (cwd) external.ensure(cwd, session.id)
|
|
124
|
+
}
|
|
84
125
|
/** @author ddj 2026年09月28号 @param exec Tool execution. @param result Tool result. */
|
|
85
126
|
function onResult(exec: unknown, result: unknown): void {
|
|
86
127
|
void captureToolResult(ctx, runtime.registry, exec, result)
|
|
@@ -89,6 +130,7 @@ function attachRuntime(ctx: Ctx, runtime: Runtime): void {
|
|
|
89
130
|
function onDisposed(session: { id?: unknown }): void {
|
|
90
131
|
const cwd = cwdOf(session)
|
|
91
132
|
if (cwd) {
|
|
133
|
+
external.dismiss(cwd)
|
|
92
134
|
runtime.registry.delete(cwd)
|
|
93
135
|
runtime.searcher.dispose(cwd)
|
|
94
136
|
runtime.contentSearcher.dispose(cwd)
|
|
@@ -101,6 +143,9 @@ function attachRuntime(ctx: Ctx, runtime: Runtime): void {
|
|
|
101
143
|
await stopCapture()
|
|
102
144
|
evidence.dispose()
|
|
103
145
|
pending.dispose()
|
|
146
|
+
external.dispose()
|
|
147
|
+
sweep.dispose()
|
|
148
|
+
windows.dispose()
|
|
104
149
|
runtime.fileVersions.dispose()
|
|
105
150
|
closeArchiveDbs()
|
|
106
151
|
disposeAllServers()
|
|
@@ -108,9 +153,14 @@ function attachRuntime(ctx: Ctx, runtime: Runtime): void {
|
|
|
108
153
|
await Promise.allSettled(tasks.map((run) => Promise.resolve().then(run)))
|
|
109
154
|
}
|
|
110
155
|
ctx.on('tools/result', onResult)
|
|
156
|
+
ctx.on('tools/execute', aroundToolWindow)
|
|
157
|
+
ctx.on('session/created', onCreated)
|
|
111
158
|
ctx.on('session/disposed', onDisposed)
|
|
159
|
+
// 启动时给已有会话的工作区各开一份监听(会话内 cd 后由 session/created 与 ensure 幂等补齐)
|
|
160
|
+
for (const session of ctx.get('sessions').list()) onCreated(session)
|
|
112
161
|
ctx.effect(() => cleanup, 'vscode-mode:runtime')
|
|
113
162
|
hookExitReclaim()
|
|
163
|
+
return { external }
|
|
114
164
|
}
|
|
115
165
|
|
|
116
166
|
/**
|
|
@@ -136,13 +186,35 @@ export async function apply(ctx: Ctx, config?: unknown): Promise<void> {
|
|
|
136
186
|
bindHostLog(ctx)
|
|
137
187
|
const runtime = createRuntime(ctx, config)
|
|
138
188
|
const warnings: string[] = []
|
|
139
|
-
attachRuntime(ctx, runtime)
|
|
189
|
+
const capture = attachRuntime(ctx, runtime)
|
|
140
190
|
installContent(ctx)
|
|
191
|
+
/** 版本库写操作后的补扫串行链:并发 RPC 也不会叠出多次补扫。 */
|
|
192
|
+
let alignChain: Promise<void> = Promise.resolve()
|
|
141
193
|
/** @author ddj 2026年09月28号 @param method RPC name. @param args Typed request. @returns RPC result. */
|
|
142
194
|
function dispatch<M extends RpcMethod>(method: M, args: RpcRequestMap[M]) {
|
|
143
195
|
const { registry, searcher, contentSearcher, lspRpc, aiRpc, fileVersions, svnRpc, dapRpc } = runtime
|
|
144
|
-
|
|
196
|
+
const pendingResult = handleRpc(ctx, registry, method, args, searcher, contentSearcher, lspRpc.handlers,
|
|
145
197
|
aiRpc.handlers, fileVersions, svnRpc.handlers as Partial<RpcHandlerMap>, dapRpc.handlers)
|
|
198
|
+
// 版本库写操作(提交/更新/还原/清理…)之后补扫一次:命令造成的成片变化要能进待审投影
|
|
199
|
+
if (!VCS_WRITE_METHODS.has(method)) return pendingResult
|
|
200
|
+
alignChain = alignChain.then(async () => {
|
|
201
|
+
const cwd = await workspaceOfSession((args as { sessionId?: string } | undefined)?.sessionId)
|
|
202
|
+
if (cwd) capture.external.requestAlign(cwd)
|
|
203
|
+
}).catch(() => {})
|
|
204
|
+
return pendingResult
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* @author ddj 2026年11月24号
|
|
208
|
+
* @description: 取 RPC 参数里的会话工作区;取不到就跳过补扫,绝不影响 RPC 本身。
|
|
209
|
+
* @param sessionId 请求会话
|
|
210
|
+
* @returns 工作区路径或 null
|
|
211
|
+
*/
|
|
212
|
+
async function workspaceOfSession(sessionId: string | undefined): Promise<string | null> {
|
|
213
|
+
try {
|
|
214
|
+
if (!sessionId) return null
|
|
215
|
+
const scope = await resolveScope(ctx, sessionId)
|
|
216
|
+
return 'err' in scope ? null : scope.cwd
|
|
217
|
+
} catch { return null }
|
|
146
218
|
}
|
|
147
219
|
/** @author ddj 2026年09月28号 @param warning Startup compatibility diagnostic. */
|
|
148
220
|
function noteWarning(warning: string): void { warnings.push(warning) }
|
package/src/mcpManaged.ts
CHANGED
|
@@ -25,6 +25,10 @@ export interface ManagedState {
|
|
|
25
25
|
error?: string
|
|
26
26
|
/** 官方报告的 OAuth 授权阶段。 */
|
|
27
27
|
phase?: string
|
|
28
|
+
/** 官方报告的真连上时刻(epoch 毫秒,仅 connected 状态有)。 */
|
|
29
|
+
connectedAt?: number
|
|
30
|
+
/** 本条注册的挂载时刻(epoch 毫秒),供会话卡片算耗时。 */
|
|
31
|
+
since?: number
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
/** 一条托管注册的账目。 */
|
|
@@ -39,6 +43,8 @@ interface Held {
|
|
|
39
43
|
key: string
|
|
40
44
|
/** 需求计数:归零才真正注销。 */
|
|
41
45
|
refs: number
|
|
46
|
+
/** 注册时刻:会话卡片按它算本服务器的耗时。 */
|
|
47
|
+
mountedAt: number
|
|
42
48
|
/** 注销函数;注册失败时缺省。 */
|
|
43
49
|
dispose?: () => void
|
|
44
50
|
}
|
|
@@ -197,7 +203,7 @@ export class ManagedProject {
|
|
|
197
203
|
*/
|
|
198
204
|
private mount(path: string, server: string, def: ManagedDef, refs: number): void {
|
|
199
205
|
const name = managedName(path, server)
|
|
200
|
-
const record: Held = { name, path, server, key: keyOf(def), refs }
|
|
206
|
+
const record: Held = { name, path, server, key: keyOf(def), refs, mountedAt: Date.now() }
|
|
201
207
|
this.held.set(name, record)
|
|
202
208
|
const reason = this.conflictOf(name)
|
|
203
209
|
if (reason) {
|
|
@@ -269,7 +275,7 @@ export class ManagedProject {
|
|
|
269
275
|
}
|
|
270
276
|
|
|
271
277
|
/**
|
|
272
|
-
*
|
|
278
|
+
* 读一条托管的当前状态;挂载时刻与官方连上时刻一并带出。
|
|
273
279
|
* @public @author ddj 2026年11月23号
|
|
274
280
|
* @param path 工作区路径
|
|
275
281
|
* @param server 服务器名
|
|
@@ -277,12 +283,15 @@ export class ManagedProject {
|
|
|
277
283
|
*/
|
|
278
284
|
stateOf(path: string, server: string): ManagedState {
|
|
279
285
|
const name = managedName(path, server)
|
|
286
|
+
const held = this.held.get(name)
|
|
280
287
|
const view = this.views.get(name)
|
|
281
288
|
// 没注册过就不是 disabled:那是「按需、还没人用」,面板按 configured 显示。
|
|
282
|
-
if (!view) return { state:
|
|
289
|
+
if (!view) return held ? { state: 'unknown', since: held.mountedAt } : { state: 'idle' }
|
|
283
290
|
const state: ManagedState = { state: view.state }
|
|
291
|
+
if (held) state.since = held.mountedAt
|
|
284
292
|
if (view.error) state.error = view.error
|
|
285
293
|
if (view.phase) state.phase = view.phase
|
|
294
|
+
if (view.connectedAt !== undefined) state.connectedAt = view.connectedAt
|
|
286
295
|
return state
|
|
287
296
|
}
|
|
288
297
|
|
package/src/mcpManagerBridge.ts
CHANGED
|
@@ -33,6 +33,8 @@ export interface ManagerView {
|
|
|
33
33
|
state: string
|
|
34
34
|
error?: string
|
|
35
35
|
phase?: string
|
|
36
|
+
/** 官方报告的真连上时刻(epoch 毫秒,仅 connected 状态有)。 */
|
|
37
|
+
connectedAt?: number
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
/** 官方 manager 的最小能力面;服务缺失即 available() === false。 */
|
|
@@ -56,7 +58,7 @@ interface HostLike { get: (name: string) => unknown }
|
|
|
56
58
|
interface RawView {
|
|
57
59
|
name?: unknown
|
|
58
60
|
configured?: unknown
|
|
59
|
-
status?: { state?: unknown; reason?: unknown; lastError?: unknown; result?: { message?: unknown } }
|
|
61
|
+
status?: { state?: unknown; reason?: unknown; lastError?: unknown; connectedAt?: unknown; result?: { message?: unknown } }
|
|
60
62
|
authorization?: { phase?: unknown }
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -165,6 +167,8 @@ export function toView(raw: unknown): ManagerView {
|
|
|
165
167
|
const result: ManagerView = { name, configured: view.configured === true, state }
|
|
166
168
|
if (message) result.error = message
|
|
167
169
|
if (phase) result.phase = phase
|
|
170
|
+
// 只有真连上才带这个时刻,会话卡片据此算本服务器的真实初始化耗时。
|
|
171
|
+
if (typeof status.connectedAt === 'number') result.connectedAt = status.connectedAt
|
|
168
172
|
return result
|
|
169
173
|
}
|
|
170
174
|
|
package/src/mcpRuntime.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { loadHostModule } from './hostImport.js'
|
|
|
3
3
|
import { entriesOf, MCP_PACKAGE, publicConfig, toolsOf } from './mcp.js'
|
|
4
4
|
import { isProjectEntryId } from './compat.js'
|
|
5
5
|
import { matchWorkspace } from './mcpIsolation.js'
|
|
6
|
-
import { ManagedProject, managedName } from './mcpManaged.js'
|
|
6
|
+
import { ManagedProject, managedName, type ManagedState } from './mcpManaged.js'
|
|
7
7
|
import { managerPort } from './mcpManagerBridge.js'
|
|
8
8
|
import { listProjects, projectEntryId, reconcileProject } from './mcpProject.js'
|
|
9
9
|
import { parseMcpPolicy, type McpPolicy, type McpPhase, type McpSessionServer, type McpSessionStatus, type MpcConfig, type MpcServer, type MpcStatus } from './shared/mcp.js'
|
|
@@ -257,6 +257,8 @@ export class McpRuntime {
|
|
|
257
257
|
if (!def.enabled || record.holds.has(name) || !path) continue
|
|
258
258
|
record.holds.set(name, managed.hold(path, name))
|
|
259
259
|
}
|
|
260
|
+
// 托管后端不经过 syncAgent,配置就绪时刻要在这里落账,否则会话状态永远停在 preparing。
|
|
261
|
+
record.finishedAt ??= Date.now()
|
|
260
262
|
this.changed()
|
|
261
263
|
}
|
|
262
264
|
|
|
@@ -453,9 +455,12 @@ export class McpRuntime {
|
|
|
453
455
|
|
|
454
456
|
/** @private @author ddj 2026年10月20号 @param agent Owner. @param record Ledger. @returns Server phases with caller-local timing, not pooled connection age. */
|
|
455
457
|
private sessionServers(agent: any, record: AgentRecord): McpSessionServer[] {
|
|
458
|
+
const managed = this.probeBackend() === 'manager' ? this.managedOf() : undefined
|
|
459
|
+
const path = managed ? this.workspace(agent) ?? '' : ''
|
|
456
460
|
return this.catalogue(agent).map(({ serverName, phase }) => {
|
|
457
461
|
const instance = record.instances.get(serverName)
|
|
458
|
-
|
|
462
|
+
// 托管后端不建本会话的连接账目,阶段与时间只能取官方报告,不能再按「没实例就是 idle」处理。
|
|
463
|
+
if (!instance) return this.managedServer(record, serverName, phase, managed?.stateOf(path, serverName))
|
|
459
464
|
const entry = instance.lease.entry
|
|
460
465
|
return { serverName, phase, startedAt: instance.startedAt, phaseAt: Math.max(instance.startedAt, entry.phaseAt),
|
|
461
466
|
finishedAt: entry.finishedAt && Math.max(instance.startedAt, entry.finishedAt), error: entry.error, reused: instance.reused,
|
|
@@ -464,6 +469,27 @@ export class McpRuntime {
|
|
|
464
469
|
})
|
|
465
470
|
}
|
|
466
471
|
|
|
472
|
+
/**
|
|
473
|
+
* 托管后端的一条服务器状态:阶段取 catalogue 的官方映射,时间取挂载时刻与官方连上时刻。
|
|
474
|
+
* @private @author ddj 2026年11月24号
|
|
475
|
+
* @param record 会话账目
|
|
476
|
+
* @param serverName 服务器名
|
|
477
|
+
* @param phase 官方状态映射后的阶段
|
|
478
|
+
* @param state 官方托管状态;连接池后端不传
|
|
479
|
+
* @returns 会话里的一条服务器状态
|
|
480
|
+
*/
|
|
481
|
+
private managedServer(record: AgentRecord, serverName: string, phase: McpPhase, state?: ManagedState): McpSessionServer {
|
|
482
|
+
const startedAt = state?.since ?? record.finishedAt ?? record.startedAt
|
|
483
|
+
// 只有落定的阶段才收尾,正在起来的阶段留空,前端按秒继续走。
|
|
484
|
+
let finishedAt: number | undefined
|
|
485
|
+
if (phase === 'ready') finishedAt = state?.connectedAt ?? startedAt
|
|
486
|
+
else if (phase === 'error') finishedAt = startedAt
|
|
487
|
+
|
|
488
|
+
const server: McpSessionServer = { serverName, phase, startedAt, phaseAt: finishedAt ?? startedAt, finishedAt }
|
|
489
|
+
if (state?.error) server.error = state.error
|
|
490
|
+
return server
|
|
491
|
+
}
|
|
492
|
+
|
|
467
493
|
/** @public @author ddj 2026年09月28号 @param path Workspace. @returns Masked configuration and pool/lease counts; initialization is not health. */
|
|
468
494
|
views(path: string): MpcServer[] {
|
|
469
495
|
if (this.probeBackend() === 'manager') return this.viewsManaged(path)
|
|
@@ -547,6 +573,9 @@ export function leftoverOf(ctx: Ctx): string[] {
|
|
|
547
573
|
.map((entry) => String(entry.id))
|
|
548
574
|
}
|
|
549
575
|
|
|
576
|
+
/** 官方状态里算「还在起来」的那几个:连接中、重连退避、等凭据、等授权。 */
|
|
577
|
+
const STARTING_STATES = new Set(['connecting', 'reconnecting', 'waiting-credentials', 'waiting-authorization'])
|
|
578
|
+
|
|
550
579
|
/**
|
|
551
580
|
* 官方状态 → 插件阶段:未知一律 idle,不假装连上。
|
|
552
581
|
* @private @author ddj 2026年11月23号
|
|
@@ -555,7 +584,7 @@ export function leftoverOf(ctx: Ctx): string[] {
|
|
|
555
584
|
*/
|
|
556
585
|
function managedPhase(state: string): McpPhase {
|
|
557
586
|
if (state === 'connected') return 'ready'
|
|
558
|
-
if (state
|
|
587
|
+
if (STARTING_STATES.has(state)) return 'starting'
|
|
559
588
|
if (state === 'failed') return 'error'
|
|
560
589
|
return 'idle'
|
|
561
590
|
}
|
|
@@ -570,7 +599,7 @@ function managedPhase(state: string): McpPhase {
|
|
|
570
599
|
function managedStatusOf(enabled: boolean, state: string): MpcStatus {
|
|
571
600
|
if (!enabled) return 'disabled'
|
|
572
601
|
if (state === 'connected') return 'connected'
|
|
573
|
-
if (state
|
|
602
|
+
if (STARTING_STATES.has(state)) return 'connecting'
|
|
574
603
|
if (state === 'failed') return 'error'
|
|
575
604
|
return 'configured'
|
|
576
605
|
}
|
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
|
|