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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-vscode-mode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "DSH 上的类 VSCode 编码体验:Monaco 编辑器(文件页签/QuickOpen/状态栏,可驻 DSH 0.1.5+ 官方右侧 Sidebar 与对话同屏)+ 命令栏(Ctrl+Shift+P)与可扩展指令系统 + VS Code 兼容代码片段(.code-snippets 全局/项目,IntelliSense 展开)+ Agent 编辑差异审查(整文件差异/采纳/拒绝/归档/回滚)+ SVN 集成(侧栏变更面板/日志弹窗/并排差异)+ 语言服务器(LSP)智能(跳转定义/引用/hover/大纲 + VSIX 扩展市场安装),状态持久化到工作区旁车,界面状态(页签/光标/侧栏/编辑 Tab/导航历史)镜像到 DSH home 跨重启恢复",
|
|
5
5
|
"icon": "assets/icon.svg",
|
|
6
6
|
"keywords": [
|
|
@@ -157,7 +157,7 @@ HTML 骨架(可复制后改写):
|
|
|
157
157
|
- 页面底部按钮「N 个待回答」跳到下一个未展开的决策;每个决策有编号(如「决策 2 / 4」)。
|
|
158
158
|
- 用户点 Respond 后出现一份 markdown 答复;点「回复」直接发送给 agent(等同把答复发回对话)。
|
|
159
159
|
- 发送失败时插件会恢复按钮并提示原因;此时可用 Copy response 或计划页签顶部「填入对话输入框」。
|
|
160
|
-
- 有待审批卡片时,「回复」=
|
|
160
|
+
- 有待审批卡片时,「回复」= 先把答复送进 agent 当前回合(steer),再结算为「同意执行」:批准结果和答复落在同一次模型请求里,agent 带着答复开始执行;要改计划请先点页签「继续规划」,再回复反馈。
|
|
161
161
|
- 带单选或复选的决策末尾自带「自己写一条」输入框(运行时注入,不用自己写 `<textarea>`):写了文字就清掉上面的单选,答复里是 `_(no selection)_` 加 `custom:` 行,这个决策也算已变更。
|
|
162
162
|
- 只有文本框、刻度或排序的决策不加这个输入框。
|
|
163
163
|
- 收到带 `custom:` 的答复时,把自定义内容当作读者的实际选择,按它重规划;要在某条决策上关掉输入框,给 `<doc-ask custom="off">`。
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 归档库清理:保留期 + 每文件上限 + 撤销栈截断。
|
|
3
|
+
*
|
|
4
|
+
* 设计取舍:
|
|
5
|
+
* - 只删「已判定」的内容:`batches.pending > 0` 或批次内任一条 `records.pending > 0` 的整批跳过,
|
|
6
|
+
* 绝不因为时间久就丢掉还没判的 hunk。
|
|
7
|
+
* - 删除顺序写死:先按 call_id 清 `revert_intents`,再删 `records`,最后删 `batches`。
|
|
8
|
+
* 表里的 REFERENCES 只是声明,SQLite 默认不开外键,靠这条顺序避免孤儿行。
|
|
9
|
+
* - 时间比较用 `Date.parse`,解析失败的时间一律当「不超期」,宁可少删。
|
|
10
|
+
* - 真删之前先留一份同名备份(`<db>.before-purge.bak`,覆盖写),每个工作区只占一份。
|
|
11
|
+
* 作者 ddj 2026-11-24
|
|
12
|
+
*/
|
|
13
|
+
import { readdirSync, rmSync } from 'node:fs'
|
|
14
|
+
import { join } from 'node:path'
|
|
15
|
+
import { DatabaseSync } from 'node:sqlite'
|
|
16
|
+
import { archiveDbFile, dshHome, PLUGIN_ID } from './paths.js'
|
|
17
|
+
import { dbFor, activeReady } from './archiveDb.js'
|
|
18
|
+
import { log } from './log.js'
|
|
19
|
+
|
|
20
|
+
/** 已判定历史默认保留天数。 */
|
|
21
|
+
export const RETENTION_DAYS = 30
|
|
22
|
+
/** 同一路径默认保留多少个归档批次。 */
|
|
23
|
+
export const KEEP_BATCHES = 20
|
|
24
|
+
/** 同一待审条目默认保留多少步撤销栈。 */
|
|
25
|
+
export const KEEP_HISTORY = 10
|
|
26
|
+
/** 幂等操作表默认保留多少条(该表无时间列,按 rowid 保留最近的)。 */
|
|
27
|
+
export const KEEP_OPS = 500
|
|
28
|
+
/** 真删前备份文件名后缀。 */
|
|
29
|
+
const BACKUP_SUFFIX = '.before-purge.bak'
|
|
30
|
+
|
|
31
|
+
/** 清理选项;缺省值即产品默认。 */
|
|
32
|
+
export interface ArchivePurgeOptions {
|
|
33
|
+
/** 保留天数(缺省 {@link RETENTION_DAYS})。 */
|
|
34
|
+
retentionDays?: number
|
|
35
|
+
/** 每路径保留批次数(缺省 {@link KEEP_BATCHES})。 */
|
|
36
|
+
keepBatches?: number
|
|
37
|
+
/** 每条目保留的撤销步数(缺省 {@link KEEP_HISTORY})。 */
|
|
38
|
+
keepHistory?: number
|
|
39
|
+
/** true 只报数不删。 */
|
|
40
|
+
dryRun?: boolean
|
|
41
|
+
/** 删除后 VACUUM(缺省 true)。 */
|
|
42
|
+
vacuum?: boolean
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 一次清理的结果。 */
|
|
46
|
+
export interface ArchivePurgeOutcome {
|
|
47
|
+
/** 超期候选批次数(与 overCap 可能重叠)。 */
|
|
48
|
+
expired: number
|
|
49
|
+
/** 超每文件上限的候选批次数。 */
|
|
50
|
+
overCap: number
|
|
51
|
+
/** 因为还有未判定内容而跳过的批次数。 */
|
|
52
|
+
keptPending: number
|
|
53
|
+
/** 实际删除的行数。 */
|
|
54
|
+
removed: { records: number; batches: number; history: number }
|
|
55
|
+
/** VACUUM 耗时毫秒;未执行时为 undefined。 */
|
|
56
|
+
vacuumMs?: number
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 数据库行。 */
|
|
60
|
+
type Row = Record<string, string | number | null>
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @author ddj 2026-11-24
|
|
64
|
+
* @description: 挑出要删的批次:先按保留期,再按每路径上限,未判完的整批跳过。
|
|
65
|
+
* @param db 工作区归档库连接
|
|
66
|
+
* @param options 清理选项
|
|
67
|
+
* @returns 候选批次 id 与两个统计口径
|
|
68
|
+
*/
|
|
69
|
+
function pickCandidates(db: ReturnType<typeof dbFor>, options: ArchivePurgeOptions): {
|
|
70
|
+
ids: number[]; expired: number; overCap: number; keptPending: number
|
|
71
|
+
} {
|
|
72
|
+
const retentionDays = options.retentionDays ?? RETENTION_DAYS
|
|
73
|
+
const keepBatches = options.keepBatches ?? KEEP_BATCHES
|
|
74
|
+
const cutoff = Date.now() - retentionDays * 24 * 60 * 60 * 1000
|
|
75
|
+
// 批次按路径分组、组内按时间倒序:靠前的就是留下的
|
|
76
|
+
const rows = db.prepare(`SELECT b.id, b.path, b.at, b.pending,
|
|
77
|
+
(SELECT COUNT(*) FROM records r WHERE r.batch_id = b.id AND r.pending > 0) AS open_records
|
|
78
|
+
FROM batches b ORDER BY b.path, b.at DESC, b.id DESC`).all() as Row[]
|
|
79
|
+
const seen = new Map<string, number>()
|
|
80
|
+
const picked = new Set<number>()
|
|
81
|
+
let expired = 0
|
|
82
|
+
let overCap = 0
|
|
83
|
+
let keptPending = 0
|
|
84
|
+
for (const row of rows) {
|
|
85
|
+
const id = Number(row.id)
|
|
86
|
+
const path = String(row.path)
|
|
87
|
+
const order = (seen.get(path) ?? 0) + 1
|
|
88
|
+
seen.set(path, order)
|
|
89
|
+
const at = Date.parse(String(row.at))
|
|
90
|
+
const isExpired = Number.isFinite(at) && at < cutoff
|
|
91
|
+
const isOverCap = order > keepBatches
|
|
92
|
+
if (!isExpired && !isOverCap) continue
|
|
93
|
+
if (isExpired) expired += 1
|
|
94
|
+
if (isOverCap) overCap += 1
|
|
95
|
+
// 还有未判定内容的批次一律保留:删了就再也判不了
|
|
96
|
+
if (Number(row.pending) > 0 || Number(row.open_records) > 0) {
|
|
97
|
+
keptPending += 1
|
|
98
|
+
continue
|
|
99
|
+
}
|
|
100
|
+
picked.add(id)
|
|
101
|
+
}
|
|
102
|
+
return { ids: [...picked], expired, overCap, keptPending }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @author ddj 2026-11-24
|
|
107
|
+
* @description: 截断撤销栈与幂等表:每个条目只留最近若干步,避免这两张表跟着天长日久。
|
|
108
|
+
* @param db 工作区归档库连接
|
|
109
|
+
* @param keepHistory 每条目保留步数
|
|
110
|
+
* @returns 删除的历史行数
|
|
111
|
+
*/
|
|
112
|
+
function trimPendingTables(db: ReturnType<typeof dbFor>, keepHistory: number): number {
|
|
113
|
+
const trimmed = db.prepare(`DELETE FROM pending_history WHERE id NOT IN (
|
|
114
|
+
SELECT id FROM (
|
|
115
|
+
SELECT id, ROW_NUMBER() OVER (PARTITION BY entry_id ORDER BY id DESC) AS rn FROM pending_history
|
|
116
|
+
) WHERE rn <= ?)`).run(keepHistory)
|
|
117
|
+
db.prepare(`DELETE FROM pending_ops WHERE rowid NOT IN (
|
|
118
|
+
SELECT rowid FROM pending_ops ORDER BY rowid DESC LIMIT ?)`).run(KEEP_OPS)
|
|
119
|
+
return Number(trimmed.changes)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @author ddj 2026-11-24
|
|
124
|
+
* @description: 真删:单事务内按「撤销意图 → 记录 → 批次」顺序清,备份在事务之前做。
|
|
125
|
+
* @param db 工作区归档库连接
|
|
126
|
+
* @param ids 候选批次 id
|
|
127
|
+
* @returns 删除的记录数与批次数
|
|
128
|
+
*/
|
|
129
|
+
function removeBatches(db: ReturnType<typeof dbFor>, ids: number[]): { records: number; batches: number } {
|
|
130
|
+
const callIds = db.prepare('SELECT call_id FROM records WHERE batch_id = ?')
|
|
131
|
+
const dropIntent = db.prepare('DELETE FROM revert_intents WHERE call_id = ?')
|
|
132
|
+
const dropRecords = db.prepare('DELETE FROM records WHERE batch_id = ?')
|
|
133
|
+
const dropBatch = db.prepare('DELETE FROM batches WHERE id = ?')
|
|
134
|
+
let records = 0
|
|
135
|
+
let batches = 0
|
|
136
|
+
db.exec('BEGIN IMMEDIATE')
|
|
137
|
+
try {
|
|
138
|
+
for (const id of ids) {
|
|
139
|
+
for (const row of callIds.all(id) as Row[]) dropIntent.run(String(row.call_id))
|
|
140
|
+
records += Number(dropRecords.run(id).changes)
|
|
141
|
+
batches += Number(dropBatch.run(id).changes)
|
|
142
|
+
}
|
|
143
|
+
db.exec('COMMIT')
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (db.isTransaction) db.exec('ROLLBACK')
|
|
146
|
+
throw error
|
|
147
|
+
}
|
|
148
|
+
return { records, batches }
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @public
|
|
153
|
+
* @author ddj 2026-11-24
|
|
154
|
+
* @description: 归档库清理入口:保留期 + 每文件上限 + 撤销栈截断,可选 VACUUM。
|
|
155
|
+
* @param cwd 工作区
|
|
156
|
+
* @param options 清理选项
|
|
157
|
+
* @returns 三个统计口径与实际删除行数
|
|
158
|
+
* @throws 归档库不可用或事务失败
|
|
159
|
+
*/
|
|
160
|
+
export function purgeArchiveDb(cwd: string, options: ArchivePurgeOptions = {}): ArchivePurgeOutcome {
|
|
161
|
+
const db = dbFor(cwd)
|
|
162
|
+
const { ids, expired, overCap, keptPending } = pickCandidates(db, options)
|
|
163
|
+
const dryRun = options.dryRun !== false
|
|
164
|
+
const keepHistory = options.keepHistory ?? KEEP_HISTORY
|
|
165
|
+
if (dryRun) {
|
|
166
|
+
return { expired, overCap, keptPending, removed: { records: 0, batches: 0, history: 0 } }
|
|
167
|
+
}
|
|
168
|
+
// 没有要删的批次就不备份、不动库:每日扫描绝大多数时候是空跑
|
|
169
|
+
if (ids.length) backupBeforePurge(db, cwd)
|
|
170
|
+
const removedBatches = removeBatches(db, ids)
|
|
171
|
+
const history = activeReady(cwd) ? trimPendingTables(db, keepHistory) : 0
|
|
172
|
+
const outcome: ArchivePurgeOutcome = {
|
|
173
|
+
expired, overCap, keptPending,
|
|
174
|
+
removed: { ...removedBatches, history },
|
|
175
|
+
}
|
|
176
|
+
if (options.vacuum !== false && (removedBatches.batches || history)) {
|
|
177
|
+
outcome.vacuumMs = vacuumOf(db)
|
|
178
|
+
}
|
|
179
|
+
return outcome
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @private
|
|
184
|
+
* @author ddj 2026-11-24
|
|
185
|
+
* @description: 回收已删行占用的页;失败只记日志,不影响已完成的删除。
|
|
186
|
+
* @param db 工作区归档库连接
|
|
187
|
+
* @returns 耗时毫秒
|
|
188
|
+
*/
|
|
189
|
+
function vacuumOf(db: ReturnType<typeof dbFor>): number {
|
|
190
|
+
const started = Date.now()
|
|
191
|
+
try {
|
|
192
|
+
db.exec('VACUUM')
|
|
193
|
+
} catch (error) {
|
|
194
|
+
log.warn('归档库 VACUUM 失败:' + String(error))
|
|
195
|
+
}
|
|
196
|
+
return Date.now() - started
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @private
|
|
201
|
+
* @author ddj 2026-11-24
|
|
202
|
+
* @description: 真删前留一份备份;同名覆盖,每个工作区只占一份。
|
|
203
|
+
* @param db 工作区归档库连接
|
|
204
|
+
* @param cwd 工作区
|
|
205
|
+
* @returns 无
|
|
206
|
+
*/
|
|
207
|
+
function backupBeforePurge(db: ReturnType<typeof dbFor>, cwd: string): void {
|
|
208
|
+
const target = archiveDbFile(cwd) + BACKUP_SUFFIX
|
|
209
|
+
try {
|
|
210
|
+
rmSync(target, { force: true })
|
|
211
|
+
db.exec(`VACUUM INTO '${target.replace(/'/g, "''")}'`)
|
|
212
|
+
} catch (error) {
|
|
213
|
+
log.warn('归档库清理前备份失败(继续执行):' + String(error))
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// --region 每日扫描
|
|
218
|
+
|
|
219
|
+
/** 启动后首次扫描的延迟:避开启动高峰。 */
|
|
220
|
+
export const SWEEP_FIRST_DELAY_MS = 90_000
|
|
221
|
+
/** 扫描间隔:每天一次。 */
|
|
222
|
+
export const SWEEP_INTERVAL_MS = 24 * 60 * 60 * 1000
|
|
223
|
+
|
|
224
|
+
/** 扫描选项(测试可注入节奏、执行体与 home)。 */
|
|
225
|
+
export interface ArchiveSweepOptions {
|
|
226
|
+
/** 首次扫描延迟毫秒。 */
|
|
227
|
+
delayMs?: number
|
|
228
|
+
/** 重复扫描间隔毫秒。 */
|
|
229
|
+
intervalMs?: number
|
|
230
|
+
/** 单个工作区的执行体(缺省 {@link purgeArchiveDb})。 */
|
|
231
|
+
run?: (cwd: string, options: ArchivePurgeOptions) => ArchivePurgeOutcome
|
|
232
|
+
/** 覆盖 DSH home(测试注入)。 */
|
|
233
|
+
home?: string
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @public
|
|
238
|
+
* @author ddj 2026-11-24
|
|
239
|
+
* @description: 列出本机所有归档库对应的工作区:读每个库里的 metadata.cwd,
|
|
240
|
+
* 不依赖有没有活跃会话。读不出来的库跳过并记日志。
|
|
241
|
+
* @param home DSH home
|
|
242
|
+
* @returns 工作区绝对路径清单
|
|
243
|
+
*/
|
|
244
|
+
export function listArchiveWorkspaces(home = dshHome()): string[] {
|
|
245
|
+
let names: string[] = []
|
|
246
|
+
try {
|
|
247
|
+
names = readdirSync(join(home, PLUGIN_ID, 'data', 'archive')).filter((name) => name.endsWith('.sqlite'))
|
|
248
|
+
} catch {
|
|
249
|
+
return []
|
|
250
|
+
}
|
|
251
|
+
const found: string[] = []
|
|
252
|
+
for (const name of names) {
|
|
253
|
+
const file = join(home, PLUGIN_ID, 'data', 'archive', name)
|
|
254
|
+
let db: DatabaseSync | undefined
|
|
255
|
+
try {
|
|
256
|
+
db = new DatabaseSync(file, { readOnly: true })
|
|
257
|
+
const row = db.prepare("SELECT value FROM metadata WHERE name='cwd'").get() as { value?: unknown } | undefined
|
|
258
|
+
if (row?.value) found.push(String(row.value))
|
|
259
|
+
} catch (error) {
|
|
260
|
+
log.debug('跳过不可读归档库:' + file + ' ' + String(error))
|
|
261
|
+
} finally {
|
|
262
|
+
try { db?.close() } catch { /* 关闭失败不影响扫描 */ }
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return found
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @public
|
|
270
|
+
* @author ddj 2026-11-24
|
|
271
|
+
* @description: 对所有工作区归档库跑一遍清理;单个库失败只记日志,不影响其他库。
|
|
272
|
+
* @param options 扫描选项
|
|
273
|
+
* @returns 扫描到的库数与删除的行数合计
|
|
274
|
+
*/
|
|
275
|
+
export function sweepArchives(options: ArchiveSweepOptions = {}): { workspaces: number; removed: number } {
|
|
276
|
+
const run = options.run ?? purgeArchiveDb
|
|
277
|
+
const workspaces = listArchiveWorkspaces(options.home)
|
|
278
|
+
let removed = 0
|
|
279
|
+
for (const cwd of workspaces) {
|
|
280
|
+
try {
|
|
281
|
+
const outcome = run(cwd, { dryRun: false })
|
|
282
|
+
removed += outcome.removed.batches + outcome.removed.history
|
|
283
|
+
if (outcome.removed.batches || outcome.removed.history) {
|
|
284
|
+
log.debug(`归档库清理:${cwd} 批次 ${outcome.removed.batches},历史 ${outcome.removed.history},VACUUM ${outcome.vacuumMs ?? 0}ms`)
|
|
285
|
+
}
|
|
286
|
+
} catch (error) {
|
|
287
|
+
log.debug('归档库清理跳过:' + cwd + ' ' + String(error))
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return { workspaces: workspaces.length, removed }
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* @public
|
|
295
|
+
* @author ddj 2026-11-24
|
|
296
|
+
* @description: 每日自动清理:启动后延迟跑一次,之后每 24 小时一次;返回可释放的句柄。
|
|
297
|
+
* @param options 扫描选项
|
|
298
|
+
* @returns 可释放句柄
|
|
299
|
+
*/
|
|
300
|
+
export function startArchiveSweep(options: ArchiveSweepOptions = {}): { dispose(): void } {
|
|
301
|
+
let stopped = false
|
|
302
|
+
const run = (): void => {
|
|
303
|
+
if (stopped) return
|
|
304
|
+
try { sweepArchives(options) } catch (error) { log.warn('归档库每日清理失败:' + String(error)) }
|
|
305
|
+
}
|
|
306
|
+
const first = setTimeout(run, options.delayMs ?? SWEEP_FIRST_DELAY_MS)
|
|
307
|
+
const timer = setInterval(run, options.intervalMs ?? SWEEP_INTERVAL_MS)
|
|
308
|
+
if (typeof first.unref === 'function') first.unref()
|
|
309
|
+
if (typeof timer.unref === 'function') timer.unref()
|
|
310
|
+
return {
|
|
311
|
+
dispose(): void {
|
|
312
|
+
stopped = true
|
|
313
|
+
clearTimeout(first)
|
|
314
|
+
clearInterval(timer)
|
|
315
|
+
},
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// --endregion
|
package/src/capture.ts
CHANGED
|
@@ -19,6 +19,7 @@ import type { Registry } from './registry.js'
|
|
|
19
19
|
import { cwdOfSession } from './registry.js'
|
|
20
20
|
import { findRemoteWs, mirrorTargetOf } from './remoteWorkspace.js'
|
|
21
21
|
import { invalidateIndex } from './treeIndex.js'
|
|
22
|
+
import { pathKeyOf, windows } from './pending/provenance.js'
|
|
22
23
|
import { log } from './log.js'
|
|
23
24
|
|
|
24
25
|
/** 捕获所需的工具执行最小形状(DSH ToolExecution 的结构子集)。 */
|
|
@@ -154,6 +155,8 @@ async function syncMirrorFile(absPath: string, content: string): Promise<string
|
|
|
154
155
|
try {
|
|
155
156
|
await mkdir(dirname(absPath), { recursive: true })
|
|
156
157
|
await writeFile(absPath, content, 'utf8')
|
|
158
|
+
// 镜像写穿是本插件自己的写盘:打标记让 watch 采集别把它记成外部改动
|
|
159
|
+
windows.markSelf(pathKeyOf(absPath))
|
|
157
160
|
return null
|
|
158
161
|
} catch (error) {
|
|
159
162
|
return String(error)
|
|
@@ -271,10 +271,17 @@ export interface CtxLike {
|
|
|
271
271
|
effect?: (setup: () => () => void, label?: string) => (() => void)
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
+
/**
|
|
275
|
+
* 投递方式:`queue` 排到当前回合之后(下一回合才读),`steer` 送进当前回合的下一步
|
|
276
|
+
* (agent 下一次请求就能看到)。区别由 Host 侧 `session/prompt` 的 mode 决定。
|
|
277
|
+
* @author ddj 2026年11月24号
|
|
278
|
+
*/
|
|
279
|
+
export type TaskSendMode = 'queue' | 'steer'
|
|
280
|
+
|
|
274
281
|
/** Public Controller subset; old Hosts need not provide retain/binding. */
|
|
275
282
|
interface SessionBridge {
|
|
276
283
|
retain?: (id: string, options: { source: 'controllerOperation'; signal: AbortSignal }) => {
|
|
277
|
-
ready: Promise<{ session: { prompt(content: { type: 'text'; text: string }[], mode:
|
|
284
|
+
ready: Promise<{ session: { prompt(content: { type: 'text'; text: string }[], mode: TaskSendMode, signal: AbortSignal): Promise<{ ok: boolean }> } }>
|
|
278
285
|
release(): void
|
|
279
286
|
}
|
|
280
287
|
binding?: (id: string) => { ctx: unknown } | undefined
|
|
@@ -296,8 +303,25 @@ function taskReceipt(receipt: unknown): TaskSendResult {
|
|
|
296
303
|
return { status: 'unknown', legacyOk: false }
|
|
297
304
|
}
|
|
298
305
|
|
|
299
|
-
/**
|
|
300
|
-
|
|
306
|
+
/**
|
|
307
|
+
* 经公共 Controller 投递一条文本(独占一次会话代际,投完即释放)。
|
|
308
|
+
* @author ddj 2026年10月29号
|
|
309
|
+
* @author ddj 2026年11月24号(新增 mode:steer 送进当前回合)
|
|
310
|
+
* @param ctx 生命周期持有者
|
|
311
|
+
* @param sessions 公共 Controller
|
|
312
|
+
* @param id 固定目标会话
|
|
313
|
+
* @param text 任务正文
|
|
314
|
+
* @param mode 投递方式,默认 queue
|
|
315
|
+
* @returns 受理证据;全程不换通道
|
|
316
|
+
* @sideEffects 持有并释放恰好一次会话引用
|
|
317
|
+
*/
|
|
318
|
+
async function sendOwned(
|
|
319
|
+
ctx: CtxLike,
|
|
320
|
+
sessions: SessionBridge,
|
|
321
|
+
id: string,
|
|
322
|
+
text: string,
|
|
323
|
+
mode: TaskSendMode = 'queue',
|
|
324
|
+
): Promise<TaskSendResult> {
|
|
301
325
|
const controller = new AbortController()
|
|
302
326
|
const reference = sessions.retain!(id, { source: 'controllerOperation', signal: controller.signal })
|
|
303
327
|
let released = false
|
|
@@ -318,7 +342,7 @@ async function sendOwned(ctx: CtxLike, sessions: SessionBridge, id: string, text
|
|
|
318
342
|
if (controller.signal.aborted) result = { status: 'cancelled', legacyOk: false }
|
|
319
343
|
else {
|
|
320
344
|
started = true
|
|
321
|
-
result = taskReceipt(await binding.session.prompt([{ type: 'text', text }],
|
|
345
|
+
result = taskReceipt(await binding.session.prompt([{ type: 'text', text }], mode, controller.signal))
|
|
322
346
|
}
|
|
323
347
|
} catch {
|
|
324
348
|
result = { status: started ? 'unknown' : 'unavailable', legacyOk: false }
|
|
@@ -333,10 +357,22 @@ async function sendOwned(ctx: CtxLike, sessions: SessionBridge, id: string, text
|
|
|
333
357
|
return result
|
|
334
358
|
}
|
|
335
359
|
|
|
336
|
-
/**
|
|
337
|
-
|
|
360
|
+
/**
|
|
361
|
+
* 旧 Host 的单次投递:按能力选一条通道,不跨通道重试。
|
|
362
|
+
*
|
|
363
|
+
* `steer` 只能用带 mode 的通道(remote.session / wire);输入框 `submit()` 只能排队,
|
|
364
|
+
* 拿它顶 steer 会把「同一步送达」悄悄降级成下一回合,所以 steer 直接跳过该通道。
|
|
365
|
+
* @author ddj 2026年10月29号
|
|
366
|
+
* @author ddj 2026年11月24号(新增 mode)
|
|
367
|
+
* @param ctx 服务持有者
|
|
368
|
+
* @param id 固定目标会话
|
|
369
|
+
* @param text 任务正文
|
|
370
|
+
* @param mode 投递方式,默认 queue
|
|
371
|
+
* @returns 本次唯一通道的受理证据
|
|
372
|
+
*/
|
|
373
|
+
async function sendLegacy(ctx: CtxLike, id: string, text: string, mode: TaskSendMode = 'queue'): Promise<TaskSendResult> {
|
|
338
374
|
const input = inputFor(ctx, id) as { setDraft?: (task: string) => void; submit?: () => void } | undefined
|
|
339
|
-
if (typeof input?.setDraft === 'function' && typeof input.submit === 'function') {
|
|
375
|
+
if (mode === 'queue' && typeof input?.setDraft === 'function' && typeof input.submit === 'function') {
|
|
340
376
|
let submitted = false
|
|
341
377
|
try {
|
|
342
378
|
input.setDraft(text)
|
|
@@ -347,9 +383,9 @@ async function sendLegacy(ctx: CtxLike, id: string, text: string): Promise<TaskS
|
|
|
347
383
|
}
|
|
348
384
|
|
|
349
385
|
const remote = ctx.get('remote.session') as { prompt?: (req: unknown) => Promise<unknown> } | undefined
|
|
350
|
-
if (typeof remote?.prompt !== 'function') return httpTaskResult(id, text)
|
|
386
|
+
if (typeof remote?.prompt !== 'function') return mode === 'steer' ? { status: 'unavailable', legacyOk: false } : httpTaskResult(id, text)
|
|
351
387
|
try {
|
|
352
|
-
const payload = { sessionId: id, mode
|
|
388
|
+
const payload = { sessionId: id, mode, content: [{ type: 'text', text }] }
|
|
353
389
|
const receipt = await remote.prompt(slotArg(payload))
|
|
354
390
|
return taskReceipt((receipt as { result?: unknown } | null)?.result ?? receipt)
|
|
355
391
|
} catch { return { status: 'unknown', legacyOk: false } }
|
|
@@ -439,10 +475,18 @@ export async function apiSessionPrompt(sessionId: string, text: string): Promise
|
|
|
439
475
|
return (await httpTaskResult(sessionId, text)).legacyOk
|
|
440
476
|
}
|
|
441
477
|
|
|
442
|
-
/**
|
|
443
|
-
|
|
478
|
+
/**
|
|
479
|
+
* wire 直发 session/prompt 的受理证据(未持有 Controller 时用)。
|
|
480
|
+
* @author ddj 2026年10月29号
|
|
481
|
+
* @author ddj 2026年11月24号(新增 mode)
|
|
482
|
+
* @param sessionId 固定目标会话
|
|
483
|
+
* @param text 任务正文
|
|
484
|
+
* @param mode 投递方式,默认 queue
|
|
485
|
+
* @returns HTTP 回执证据;进入请求后的异常一律不算安全拒绝
|
|
486
|
+
*/
|
|
487
|
+
async function httpTaskResult(sessionId: string, text: string, mode: TaskSendMode = 'queue'): Promise<TaskSendResult> {
|
|
444
488
|
try {
|
|
445
|
-
const payload = { sessionId, mode
|
|
489
|
+
const payload = { sessionId, mode, content: [{ type: 'text', text }] }
|
|
446
490
|
const res = await fetch(appUrl(SESSION_PROMPT_PATH), {
|
|
447
491
|
method: 'POST',
|
|
448
492
|
headers: { 'content-type': 'application/json' },
|
|
@@ -523,8 +567,11 @@ export interface AddToConversation {
|
|
|
523
567
|
startDraftSession(cwd?: string): Promise<DraftSessionResult>
|
|
524
568
|
/** Historical compatibility result, not proof that a task was accepted. */
|
|
525
569
|
sendTask(sessionId: string | undefined, text: string): Promise<boolean>
|
|
526
|
-
/**
|
|
527
|
-
|
|
570
|
+
/**
|
|
571
|
+
* Optional on older injected facades; detailed callers must not infer acceptance from sendTask.
|
|
572
|
+
* `mode` 默认 queue;`steer` 送进当前回合(会话在跑时 agent 下一次请求就能看到)。
|
|
573
|
+
*/
|
|
574
|
+
sendTaskResult?(sessionId: string | undefined, text: string, mode?: TaskSendMode): Promise<TaskSendResult>
|
|
528
575
|
}
|
|
529
576
|
|
|
530
577
|
/**
|
|
@@ -704,13 +751,25 @@ export function createAddToConversation(ctx: CtxLike): AddToConversation {
|
|
|
704
751
|
*/
|
|
705
752
|
const sendTask: AddToConversation['sendTask'] = async (sessionId, text) => (await sendTaskResult(sessionId, text)).legacyOk
|
|
706
753
|
|
|
707
|
-
/**
|
|
708
|
-
|
|
754
|
+
/**
|
|
755
|
+
* 投递一条文本并返回详细受理证据(只选一条通道,不跨通道重发)。
|
|
756
|
+
* @author ddj 2026年10月29号
|
|
757
|
+
* @author ddj 2026年11月24号(新增 mode:steer 送进当前回合)
|
|
758
|
+
* @param sessionId 固定目标会话
|
|
759
|
+
* @param text 任务正文
|
|
760
|
+
* @param mode 投递方式,默认 queue
|
|
761
|
+
* @returns 受理证据
|
|
762
|
+
*/
|
|
763
|
+
async function sendTaskResult(
|
|
764
|
+
sessionId: string | undefined,
|
|
765
|
+
text: string,
|
|
766
|
+
mode: TaskSendMode = 'queue',
|
|
767
|
+
): Promise<TaskSendResult> {
|
|
709
768
|
if (!sessionId) return { status: 'unavailable', legacyOk: false }
|
|
710
769
|
try {
|
|
711
770
|
const sessions = ctx.get('sessions') as SessionBridge | undefined
|
|
712
|
-
if (typeof sessions?.retain === 'function') return await sendOwned(ctx, sessions, sessionId, text)
|
|
713
|
-
return await sendLegacy(ctx, sessionId, text)
|
|
771
|
+
if (typeof sessions?.retain === 'function') return await sendOwned(ctx, sessions, sessionId, text, mode)
|
|
772
|
+
return await sendLegacy(ctx, sessionId, text, mode)
|
|
714
773
|
} catch { return { status: 'unavailable', legacyOk: false } }
|
|
715
774
|
}
|
|
716
775
|
|
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
readPendingReview,
|
|
27
27
|
readPlanProjection,
|
|
28
28
|
revealPlanReview,
|
|
29
|
-
sendPlanMessage,
|
|
30
29
|
submitPlanResponse,
|
|
31
30
|
subscribePlanFaces,
|
|
32
31
|
} from './planActions.js'
|
|
@@ -166,7 +165,9 @@ export function HtmlPlanPanel(props: HtmlPlanPanelProps) {
|
|
|
166
165
|
|
|
167
166
|
/**
|
|
168
167
|
* 把页面答复直接发给 agent:成功清空并回传成功,失败回传原因且保留文本。
|
|
168
|
+
* 有待审批时答复会先送进 agent 当前回合、再结算批准,两者落在同一次请求里。
|
|
169
169
|
* @author ddj 2026年11月21号
|
|
170
|
+
* @author ddj 2026年11月24号(文案改为「答复与批准同一步送达」)
|
|
170
171
|
* @param text 答复 markdown
|
|
171
172
|
*/
|
|
172
173
|
async function sendResponse(text: string): Promise<void> {
|
|
@@ -178,7 +179,7 @@ export function HtmlPlanPanel(props: HtmlPlanPanelProps) {
|
|
|
178
179
|
const result = await submitPlanResponse(sessionId, body)
|
|
179
180
|
setBusy(false)
|
|
180
181
|
setNotice(result.ok
|
|
181
|
-
? hadReview ? '
|
|
182
|
+
? hadReview ? '答复已随批准送进当前回合,agent 会带着答复开始执行' : '已回复并发送给 agent'
|
|
182
183
|
: String(result.error ?? '发送失败'))
|
|
183
184
|
try {
|
|
184
185
|
frameRef.current?.contentWindow?.postMessage({
|
|
@@ -252,29 +253,24 @@ export function HtmlPlanPanel(props: HtmlPlanPanelProps) {
|
|
|
252
253
|
|
|
253
254
|
/**
|
|
254
255
|
* 让 agent 现场生成计划页:先发修复指令,再每 2 秒读一次,最多等 90 秒。
|
|
255
|
-
*
|
|
256
|
+
*
|
|
257
|
+
* 有待审批卡片时把「继续规划」和修复指令一起交给 agent(先 steer 指令再结算),
|
|
258
|
+
* 否则 agent 会先按「继续规划」开始修订、指令等到下一回合才被读到。
|
|
256
259
|
* 计划模式允许写计划交付物,所以这里不要求用户退出计划模式。
|
|
257
260
|
* @author ddj 2026年11月23号
|
|
261
|
+
* @author ddj 2026年11月24号(与「继续规划」一起提交,保证同一步送达)
|
|
258
262
|
*/
|
|
259
263
|
async function regenerate(): Promise<void> {
|
|
260
264
|
if (repairing) return
|
|
261
265
|
setRepairing(true)
|
|
262
266
|
const hadReview = reviewRef.current
|
|
263
|
-
|
|
264
|
-
const kept = await answerPlanReview(sessionId, false)
|
|
265
|
-
if (!kept.ok) {
|
|
266
|
-
setRepairing(false)
|
|
267
|
-
setNotice('先提交「继续规划」失败:' + String(kept.error ?? ''))
|
|
268
|
-
return
|
|
269
|
-
}
|
|
270
|
-
refresh()
|
|
271
|
-
}
|
|
272
|
-
const result = await sendPlanMessage(sessionId, planRepairInstruction(declared))
|
|
267
|
+
const result = await submitPlanResponse(sessionId, planRepairInstruction(declared), false)
|
|
273
268
|
setRepairing(false)
|
|
274
269
|
if (!result.ok) {
|
|
275
270
|
setNotice(String(result.error ?? '发送失败'))
|
|
276
271
|
return
|
|
277
272
|
}
|
|
273
|
+
refresh()
|
|
278
274
|
setNotice(hadReview
|
|
279
275
|
? '已提交「继续规划」并让 agent 生成计划页,等文件出现(最多 90 秒)…'
|
|
280
276
|
: '已让 agent 生成计划页,等文件出现(最多 90 秒)…')
|