dsh-vscode-mode 0.38.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -33
- package/lib/client.js +87 -68
- package/lib/client.js.map +1 -1
- package/lib/index.js +11406 -4920
- package/lib/index.js.map +1 -1
- package/package.json +3 -2
- package/skills/dsh-vscodemode-html-plan/SKILL.md +44 -42
- package/skills/dsh-vscodemode-test-check/SKILL.md +82 -0
- package/src/archiveDb.ts +24 -0
- package/src/attachmentBytes.ts +84 -0
- package/src/client/htmlPlan/HtmlPlanModeChip.ts +181 -0
- package/src/client/htmlPlan/HtmlPlanPanel.ts +230 -61
- package/src/client/htmlPlan/planActions.ts +38 -8
- package/src/client/htmlPlan/planPage.ts +111 -9
- package/src/client/index.ts +9 -0
- package/src/client/openReceipt.ts +5 -2
- package/src/client/planBridge.ts +27 -2
- package/src/client/planState.ts +51 -4
- package/src/client/sidebar/panels/TestCheckPanel.ts +485 -0
- package/src/client/sidebar/panels/useTestCheckData.ts +414 -0
- package/src/client/sidebar/types.ts +2 -0
- package/src/client/state/diffSummary.ts +3 -0
- package/src/client/styles/editor.css +91 -0
- package/src/client/testCheck/TestCheckChip.ts +181 -0
- package/src/client/testCheck/TestCheckPanel.ts +339 -0
- package/src/client/testCheckPanelState.ts +173 -0
- package/src/client/ui/EditorView.ts +77 -7
- package/src/client/ui/McpSettings.ts +2 -2
- package/src/client/ui/OfficialReview.ts +6 -4
- package/src/htmlPlanAttachments.ts +4 -1
- package/src/htmlPlanCommand.ts +87 -235
- package/src/htmlPlanGuidance.ts +67 -0
- package/src/htmlPlanMode.ts +547 -0
- package/src/index.ts +28 -55
- package/src/officialCapture.ts +58 -9
- package/src/pending/externalCapture.ts +195 -401
- package/src/pending/kernel.ts +24 -1
- package/src/pending/persist.ts +109 -22
- package/src/pending/provenance.ts +5 -28
- package/src/pending/store.ts +109 -100
- package/src/pending/tracking.ts +81 -0
- package/src/pendingCompat.ts +26 -1
- package/src/pendingRpc.ts +8 -56
- package/src/planAutoPage.ts +306 -0
- package/src/planPagePack.ts +148 -0
- package/src/registry.ts +7 -2
- package/src/reviewDb.ts +1 -1
- package/src/reviewRpc.ts +14 -6
- package/src/rpc.ts +34 -0
- package/src/shared/htmlPlanMode.ts +26 -0
- package/src/shared/pendingReview.ts +15 -7
- package/src/shared/review.ts +5 -0
- package/src/shared/rpc.ts +53 -7
- package/src/shared/testCheck.ts +759 -0
- package/src/shared/testCheckHtml.ts +276 -0
- package/src/shared/testCheckPolicyDefault.ts +37 -0
- package/src/shared/testCheckSnippets.ts +197 -0
- package/src/store.ts +17 -1
- package/src/testCheckCommand.ts +287 -0
- package/src/testCheckGuidance.ts +79 -0
- package/src/testCheckMode.ts +654 -0
- package/src/testCheckPolicy.ts +141 -0
- package/src/testCheckRpc.ts +196 -0
- package/src/testCheckStore.ts +822 -0
- package/src/pending/externalAlign.ts +0 -297
- package/src/pending/vcs.ts +0 -584
|
@@ -250,23 +250,91 @@ export function planSlugOf(declared: unknown): string {
|
|
|
250
250
|
return /^[a-z0-9][a-z0-9-]*$/i.test(raw) ? raw : 'html-plan'
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
+
//region 页面来源决策(HTML 计划模式)
|
|
254
|
+
|
|
255
|
+
/** 计划页读取结果的三态(读不到 / 不存在 / 读到)。 */
|
|
256
|
+
export type PlanPageRead = 'ok' | 'missing' | 'error'
|
|
257
|
+
|
|
258
|
+
/** 计划签打开页面时要执行的动作。 */
|
|
259
|
+
export type PlanPageAction = 'show' | 'pack' | 'auto' | 'error'
|
|
260
|
+
|
|
261
|
+
/** 页面动作决策入参。 */
|
|
262
|
+
export interface PlanPageDecisionInput {
|
|
263
|
+
/** 计划正文声明的页面路径(可能为空)。 */
|
|
264
|
+
declared: string
|
|
265
|
+
/** 是否在 HTML 计划模式里提交(允许插件兜底页)。 */
|
|
266
|
+
htmlPlanMode: boolean
|
|
267
|
+
/** 声明路径的读取结果。 */
|
|
268
|
+
read: PlanPageRead
|
|
269
|
+
/** 读到的页面是否还引用未内联的运行时(需要重新打包)。 */
|
|
270
|
+
needsPack: boolean
|
|
271
|
+
/** 备用路径(`.packed.html` ↔ `.html`)是否存在。 */
|
|
272
|
+
alternateExists: boolean
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** 页面动作决策结果。 */
|
|
276
|
+
export interface PlanPageDecision {
|
|
277
|
+
/** 动作。 */
|
|
278
|
+
action: PlanPageAction
|
|
279
|
+
/** pack 动作的目标路径(绝对或相对,由调用方归位)。 */
|
|
280
|
+
target?: string
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* 决定计划签怎样拿到一页 HTML。
|
|
285
|
+
*
|
|
286
|
+
* 顺序:作者页可直接显示 → 作者页需要打包 → 备用路径打包 → HTML 计划模式下用正文渲染 → 报错。
|
|
287
|
+
* `htmlPlanMode` 为真时,声明页缺失/读不到也允许兜底渲染,保证模式内不出现「只剩报错」。
|
|
288
|
+
* @author ddj 2026年11月25号
|
|
289
|
+
* @param input 决策入参
|
|
290
|
+
* @returns 动作与打包目标
|
|
291
|
+
*/
|
|
292
|
+
export function planPageDecisionOf(input: PlanPageDecisionInput): PlanPageDecision {
|
|
293
|
+
const declared = String(input.declared ?? '').trim()
|
|
294
|
+
if (declared && input.read === 'ok') {
|
|
295
|
+
return input.needsPack ? { action: 'pack', target: declared } : { action: 'show' }
|
|
296
|
+
}
|
|
297
|
+
const alternate = declared ? planPageAltPath(declared) : null
|
|
298
|
+
if (alternate && input.alternateExists) return { action: 'pack', target: alternate }
|
|
299
|
+
if (input.htmlPlanMode) return { action: 'auto' }
|
|
300
|
+
return { action: 'error' }
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 推导作者页的备用路径:`plan.packed.html` ↔ `plan.html`。
|
|
305
|
+
* 没有这两种后缀时返回 null(不做无意义重试)。
|
|
306
|
+
* @author ddj 2026年11月25号
|
|
307
|
+
* @param path 声明路径
|
|
308
|
+
* @returns 备用路径;推导不出时 null
|
|
309
|
+
*/
|
|
310
|
+
export function planPageAltPath(path: unknown): string | null {
|
|
311
|
+
const value = String(path ?? '').trim().replace(/\\/g, '/')
|
|
312
|
+
if (!value) return null
|
|
313
|
+
if (/\.packed\.html?$/i.test(value)) return value.replace(/\.packed\.html?$/i, '.html')
|
|
314
|
+
if (/\.html?$/i.test(value)) return value.replace(/\.html?$/i, '.packed.html')
|
|
315
|
+
return null
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
//endregion
|
|
319
|
+
|
|
253
320
|
/**
|
|
254
|
-
* 让 agent
|
|
255
|
-
*
|
|
321
|
+
* 让 agent 重写作者页的修复指令(计划页签「生成 HTML 计划页」按钮发给 agent)。
|
|
322
|
+
* 插件会自动打包,所以不再要求模型跑 plan.mjs(那条命令会删中间文件,不能用于用户文件)。
|
|
256
323
|
* @author ddj 2026年11月23号
|
|
324
|
+
* @author ddj 2026年11月25号(改为「只写页、插件打包」,去掉运行 plan.mjs 的要求)
|
|
257
325
|
* @param declared 计划正文声明的页面路径(可为空)
|
|
258
326
|
* @returns 发给 agent 的用户消息
|
|
259
327
|
*/
|
|
260
328
|
export function planRepairInstruction(declared: unknown): string {
|
|
261
329
|
const slug = planSlugOf(declared)
|
|
262
330
|
return [
|
|
263
|
-
'请按 dsh-vscodemode-html-plan
|
|
331
|
+
'请按 dsh-vscodemode-html-plan 技能生成 HTML 计划页,然后重新提交计划:',
|
|
264
332
|
'1. 计划模式里允许写 plans/ 下的计划交付物:直接在计划模式里写页面,不要让我退出计划模式。',
|
|
265
|
-
`2.
|
|
266
|
-
`3. 页面若引用附件(<doc-file src="assets/…">),确认文件在 plans/${slug}/assets
|
|
267
|
-
'
|
|
268
|
-
`4.
|
|
269
|
-
'不要只写路径不生成文件;页面确实生成失败就说清原因,并交付纯 Markdown
|
|
333
|
+
`2. 只写 plans/${slug}/plan.html 即可:计划签打开时插件会自动打包,不要运行 plan.mjs 或任何 node 命令。`,
|
|
334
|
+
`3. 页面若引用附件(<doc-file src="assets/…">),确认文件在 plans/${slug}/assets/;插件打包时会把它们内联。`,
|
|
335
|
+
' 附件目录不会被插件删除;文件缺失时让我重新附一次,不要凭空造图。',
|
|
336
|
+
`4. 页面写好后调用 exit_plan_mode:正文第一行「# 计划:<标题>」,并单独一行「HTML 计划页:plans/${slug}/plan.html」。`,
|
|
337
|
+
'不要只写路径不生成文件;页面确实生成失败就说清原因,并交付纯 Markdown 计划(插件会用正文兜底渲染)。',
|
|
270
338
|
].join('\n')
|
|
271
339
|
}
|
|
272
340
|
|
|
@@ -300,7 +368,41 @@ export function derivePlanUiState(
|
|
|
300
368
|
return { mode: 'off', label: '计划模式未开启', active, pending }
|
|
301
369
|
}
|
|
302
370
|
|
|
303
|
-
/**
|
|
371
|
+
/**
|
|
372
|
+
* HTML 计划模式的状态推导(独立模式不走官方 plan 投影)。
|
|
373
|
+
*
|
|
374
|
+
* 投影缺失时按「提交即活跃」乐观处理:计划能走到计划签,说明提交时模式是活跃的;
|
|
375
|
+
* 批准/退出动作后按本地动作收口,避免按钮一直可点。
|
|
376
|
+
* @author ddj 2026年11月25号
|
|
377
|
+
* @param mode html-plan 投影快照({ active } 或 undefined)
|
|
378
|
+
* @param reviewPending 是否有待审批的 plan-review
|
|
379
|
+
* @param acted 本地刚完成动作
|
|
380
|
+
* @returns 计划页签状态
|
|
381
|
+
*/
|
|
382
|
+
export function deriveHtmlPlanUiState(
|
|
383
|
+
mode: unknown,
|
|
384
|
+
reviewPending: boolean,
|
|
385
|
+
acted?: 'approved' | 'revising' | 'exited' | null,
|
|
386
|
+
): PlanUiState {
|
|
387
|
+
const row = mode !== null && typeof mode === 'object' ? mode as { active?: unknown } : undefined
|
|
388
|
+
const active = row ? row.active === true : acted !== 'approved' && acted !== 'exited'
|
|
389
|
+
const pending = false
|
|
390
|
+
if (acted === 'approved') {
|
|
391
|
+
return { mode: 'approved', label: active ? '已批准 · 等待退出 HTML 计划模式' : '已批准 · 已退出 HTML 计划模式', active, pending }
|
|
392
|
+
}
|
|
393
|
+
if (acted === 'exited' && !active) return { mode: 'exited', label: '已退出 HTML 计划模式', active, pending }
|
|
394
|
+
if (acted === 'revising' && active) return { mode: 'revising', label: '继续规划中', active, pending }
|
|
395
|
+
if (active && reviewPending) return { mode: 'reviewing', label: '待审批', active, pending }
|
|
396
|
+
if (active) return { mode: 'planning', label: 'HTML 计划模式中', active, pending }
|
|
397
|
+
return { mode: 'off', label: 'HTML 计划模式未开启', active, pending }
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* 选项标签归一:字符串或 { label } 数组。
|
|
402
|
+
* @author ddj 2026年11月21号
|
|
403
|
+
* @param options 选项列表
|
|
404
|
+
* @returns 非空标签
|
|
405
|
+
*/
|
|
304
406
|
function labelsOf(options: unknown): string[] {
|
|
305
407
|
if (!Array.isArray(options)) return []
|
|
306
408
|
const out: string[] = []
|
package/src/client/index.ts
CHANGED
|
@@ -46,6 +46,8 @@ import { detectOfficial, installOfficial, registerOfficialFileClaim, OFFICIAL_TA
|
|
|
46
46
|
import { setNativeCsv, setNativeOpenHandler, resetNativeOpen } from './nativeOpenStore.js'
|
|
47
47
|
import { hasOfficialHtmlPreview, installHtmlPreviewProbe, isHtmlPath } from './htmlPreview.js'
|
|
48
48
|
import { installHtmlPlanActions } from './htmlPlan/planActions.js'
|
|
49
|
+
import { installHtmlPlanModeChip } from './htmlPlan/HtmlPlanModeChip.js'
|
|
50
|
+
import { installCheckChip } from './testCheck/TestCheckChip.js'
|
|
49
51
|
import { setFeaturePrefs } from './featurePrefs.js'
|
|
50
52
|
import { SideEditorTab } from './ui/SideEditorTab.js'
|
|
51
53
|
import { OfficialSideTab } from './ui/OfficialSideTab.js'
|
|
@@ -63,6 +65,7 @@ import { createSearchPanel } from './sidebar/panels/index.js'
|
|
|
63
65
|
import { createRulesPanel } from './sidebar/panels/index.js'
|
|
64
66
|
import { createSvnPanel } from './sidebar/panels/index.js'
|
|
65
67
|
import { createDebugPanel } from './sidebar/panels/index.js'
|
|
68
|
+
import { createTestCheckPanel } from './sidebar/panels/TestCheckPanel.js'
|
|
66
69
|
import { createTreeMenuRegistry } from './sidebar/contextMenu.js'
|
|
67
70
|
import { createDefaultFileMenuItems } from './sidebar/menuItems.js'
|
|
68
71
|
import { createOutlinePanel } from './outline/index.js'
|
|
@@ -333,6 +336,10 @@ export async function apply(ctx: any): Promise<void> {
|
|
|
333
336
|
ctx.effect(() => installHtmlPreviewProbe(ctx, { schedule }), 'vscode-mode: html preview probe')
|
|
334
337
|
// HTML 计划页动作桥:状态读取 / 官方审批作答 / /plan off / 回填输入框(全部可选服务)。
|
|
335
338
|
ctx.effect(() => installHtmlPlanActions(ctx), 'vscode-mode: html plan actions')
|
|
339
|
+
// HTML 计划模式 chip:输入框工具行的 list 槽,模式活跃时出现,点击执行 /html-plan off。
|
|
340
|
+
ctx.effect(() => installHtmlPlanModeChip(ctx), 'vscode-mode: html plan mode chip')
|
|
341
|
+
// 测试验收模式 chip:同一槽位,显示「验收 x/y」,点开文件编辑里的验收单页签。
|
|
342
|
+
ctx.effect(() => installCheckChip(ctx), 'vscode-mode: test-check chip')
|
|
336
343
|
// 官方代码审阅扩展位(0.2.3+):变更视图工具条与文件菜单加两条动作。
|
|
337
344
|
// 服务/slot 缺失时零注册,不影响自有 diff 面板。
|
|
338
345
|
ctx.effect(() => installOfficialReview(ctx, {
|
|
@@ -522,6 +529,8 @@ export async function apply(ctx: any): Promise<void> {
|
|
|
522
529
|
ctx.effect(() => sidebarPanels.register(createSvnPanel()), 'vscode-mode: sidebar panel svn')
|
|
523
530
|
// 调试面板:活动栏「调试」页签(VS Code 调试视图四段布局 + REPL;DAP 桥接)
|
|
524
531
|
ctx.effect(() => sidebarPanels.register(createDebugPanel()), 'vscode-mode: sidebar panel debug')
|
|
532
|
+
// 测试验收面板:活动栏「测试验收」页签(使用说明 + 专属技能 + 项目规范 + 两张验收单列表)
|
|
533
|
+
ctx.effect(() => sidebarPanels.register(createTestCheckPanel()), 'vscode-mode: sidebar panel testcheck')
|
|
525
534
|
// 客户端(重)装配对账:host 的 DapSession 常驻,而本模块状态随刷新/HMR 归零,
|
|
526
535
|
// 不对账则调试面板与暂停态 hover 静默失效(见 dapStore.resync)。
|
|
527
536
|
void dapStore.resync()
|
|
@@ -3,8 +3,10 @@ import { createRequestId } from './requestId.js'
|
|
|
3
3
|
|
|
4
4
|
import type { PlanDocument } from './planState.js'
|
|
5
5
|
|
|
6
|
-
export interface EditorRequest { requestId: string; sessionId: string; path: string | null; line?: number; column?: number; preview?: boolean; plan?: PlanDocument }
|
|
7
|
-
|
|
6
|
+
export interface EditorRequest { requestId: string; sessionId: string; path: string | null; line?: number; column?: number; preview?: boolean; plan?: PlanDocument; sheet?: SheetRef }
|
|
7
|
+
/** 测试验收单页签身份(虚拟页签,不落磁盘)。 */
|
|
8
|
+
export interface SheetRef { id: string; title: string }
|
|
9
|
+
export interface OpenOptions { preview?: boolean; plan?: PlanDocument; sheet?: SheetRef; signal?: AbortSignal; timeoutMs?: number }
|
|
8
10
|
interface Waiter { request: EditorRequest; finish: (success: boolean) => void; claimed?: boolean }
|
|
9
11
|
const waiters = new Map<string, Waiter>()
|
|
10
12
|
|
|
@@ -47,6 +49,7 @@ export function requestOpen(path: string | null, line?: number, column?: number,
|
|
|
47
49
|
const request: EditorRequest = { requestId, sessionId, path, line, column }
|
|
48
50
|
if (options.preview !== undefined) request.preview = options.preview
|
|
49
51
|
if (options.plan) request.plan = options.plan
|
|
52
|
+
if (options.sheet) request.sheet = options.sheet
|
|
50
53
|
return new Promise((resolve) => {
|
|
51
54
|
let timer: ReturnType<typeof setTimeout>
|
|
52
55
|
/** @private @author ddj 2026年09月28号 Complete once and release the deadline. */
|
package/src/client/planBridge.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Optional DSH plan integration; no provider or approval UI replacement. @author ddj 2026年10月08号 */
|
|
2
2
|
import React from 'react'
|
|
3
3
|
import { requestOpen } from './openReceipt.js'
|
|
4
|
-
import { createPlanFeed, clearPlanState, isPlanAddress, planDocument, type PlanWindow, type PlanOpen } from './planState.js'
|
|
4
|
+
import { cachedPlan, createPlanFeed, clearPlanState, isPlanAddress, planDocument, planFromEntries, type PlanWindow, type PlanOpen } from './planState.js'
|
|
5
5
|
import { installPlanDirect, optionalService, type PlanOpenOptions } from './planDirect.js'
|
|
6
6
|
import { detectOfficial, OFFICIAL_SLOT_NAME, type OfficialSidebar } from './officialSidebar.js'
|
|
7
7
|
import { readSessionScope, subscribeScope } from './sessionScope.js'
|
|
@@ -41,6 +41,31 @@ function planRouter(ctx: PlanContext, official: OfficialSidebar, native: (addres
|
|
|
41
41
|
/** @private @author ddj 2026年10月08号 React to owning-session changes without cancelling on unrelated list updates. */
|
|
42
42
|
function scopeChanged(): void { cancel() }
|
|
43
43
|
const offScope = subscribeScope(ctx, scopeChanged)
|
|
44
|
+
/**
|
|
45
|
+
* 解析计划地址对应的正文:官方资源 → 本插件缓存 → 会话窗口扫一遍。
|
|
46
|
+
*
|
|
47
|
+
* 官方 `dsh-client-ui-plan` 的资源提供方只认 `exit_plan_mode`,HTML 计划模式提交的
|
|
48
|
+
* `exit_html_plan_mode` 在它那里是「not-found」;不补这两级,计划页签只会显示读取失败。
|
|
49
|
+
* @author ddj 2026年11月25号
|
|
50
|
+
* @param sessionId 归属会话
|
|
51
|
+
* @param address 计划地址
|
|
52
|
+
* @param value 官方资源或审批参数里的计划正文
|
|
53
|
+
* @returns 计划文档;都不命中时 undefined
|
|
54
|
+
*/
|
|
55
|
+
function resolvePlan(sessionId: string, address: string, value: unknown): ReturnType<typeof planDocument> {
|
|
56
|
+
const official = planDocument(address, value)
|
|
57
|
+
if (official) return official
|
|
58
|
+
const cached = cachedPlan(address)
|
|
59
|
+
if (cached) return cached
|
|
60
|
+
try {
|
|
61
|
+
const sessions = optionalService(ctx, 'sessions') as Sessions | undefined
|
|
62
|
+
const feed = sessionId && typeof sessions?.binding === 'function' ? sessions.binding(sessionId)?.eventSource : undefined
|
|
63
|
+
const window = feed?.getSnapshot?.() as PlanWindow | undefined
|
|
64
|
+
if (window && Array.isArray(window.entries)) return planFromEntries(sessionId, address, window.entries)
|
|
65
|
+
} catch { /* 事件窗口不可用:按未找到处理 */ }
|
|
66
|
+
return undefined
|
|
67
|
+
}
|
|
68
|
+
|
|
44
69
|
/** @private @author ddj 2026年10月08号 @param props Official slot props. @returns Transfer status; only closes after preview readiness. */
|
|
45
70
|
function PlanRouter(props: PlanProps) {
|
|
46
71
|
const tab = props.useTabInfo?.()?.tab
|
|
@@ -48,7 +73,7 @@ function planRouter(ctx: PlanContext, official: OfficialSidebar, native: (addres
|
|
|
48
73
|
const address = nav?.address ?? ''
|
|
49
74
|
const resource = props.useResource?.(address) ?? EMPTY_RESOURCE
|
|
50
75
|
const review = nav?.params?.planReview
|
|
51
|
-
const plan =
|
|
76
|
+
const plan = resolvePlan(props.sessionId ?? '', address, review ?? ('value' in resource ? resource.value : undefined))
|
|
52
77
|
const [failed, setFailed] = React.useState(false)
|
|
53
78
|
const done = React.useRef('')
|
|
54
79
|
const key = address + ':' + nav?.revision
|
package/src/client/planState.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/** Plan identities and live-only event reduction. @author ddj 2026年10月08号 */
|
|
2
2
|
import { planPagePathOf } from './htmlPlan/planPage.js'
|
|
3
|
+
import { HTML_PLAN_EXIT_TOOL, OFFICIAL_PLAN_EXIT_TOOL } from '../shared/htmlPlanMode.js'
|
|
3
4
|
|
|
4
|
-
export interface PlanDocument { address: string; markdown: string; title: string; htmlPath?: string }
|
|
5
|
+
export interface PlanDocument { address: string; markdown: string; title: string; htmlPath?: string; htmlPlanMode?: boolean }
|
|
5
6
|
export interface PlanOpen { path?: string; plan?: PlanDocument }
|
|
6
7
|
export interface PlanEntry { type?: string; event: { type: string; seq?: number; data: unknown } }
|
|
7
8
|
export interface PlanWindow { revision: number; entries: readonly PlanEntry[]; change: { kind: string; entries?: readonly PlanEntry[] } }
|
|
@@ -47,6 +48,48 @@ export function isPlanAddress(address: unknown): address is string {
|
|
|
47
48
|
&& ['one-shot', 'continuable', 'unknown'].includes(segments[3]))
|
|
48
49
|
} catch { return false }
|
|
49
50
|
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 取计划地址里的工具调用 id(agent 地址与 subagent 地址都取最后一段)。
|
|
54
|
+
* @author ddj 2026年11月25号
|
|
55
|
+
* @param address 官方计划地址
|
|
56
|
+
* @returns 调用 id;无法解析时 null
|
|
57
|
+
*/
|
|
58
|
+
export function planCallIdOf(address: unknown): string | null {
|
|
59
|
+
if (!isPlanAddress(address)) return null
|
|
60
|
+
try {
|
|
61
|
+
const segments = address.split('/').slice(3).map(decodeURIComponent)
|
|
62
|
+
return segments[segments.length - 1] ?? null
|
|
63
|
+
} catch { return null }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 在会话窗口里按调用 id 找已提交的计划(官方资源提供方只认 `exit_plan_mode`,
|
|
68
|
+
* 不认 HTML 计划模式的 `exit_html_plan_mode`;刷新后缓存为空时靠这里兜底)。
|
|
69
|
+
* @author ddj 2026年11月25号
|
|
70
|
+
* @param sessionId 归属会话
|
|
71
|
+
* @param address 计划地址
|
|
72
|
+
* @param entries 会话窗口条目
|
|
73
|
+
* @returns 计划文档;没找到时 undefined
|
|
74
|
+
*/
|
|
75
|
+
export function planFromEntries(sessionId: string, address: unknown, entries: readonly PlanEntry[]): PlanDocument | undefined {
|
|
76
|
+
const callId = planCallIdOf(address)
|
|
77
|
+
if (!callId || !Array.isArray(entries)) return undefined
|
|
78
|
+
for (const entry of entries) {
|
|
79
|
+
const event = entry?.event
|
|
80
|
+
if (!event || (event.type !== 'tool/call' && event.type !== 'tool/ptc-dispatch-start')) continue
|
|
81
|
+
const data = record(event.data)
|
|
82
|
+
if (data.name !== HTML_PLAN_EXIT_TOOL && data.name !== OFFICIAL_PLAN_EXIT_TOOL) continue
|
|
83
|
+
const id = typeof data.callId === 'string' ? data.callId : (typeof data.subCallId === 'string' ? data.subCallId : '')
|
|
84
|
+
if (id !== callId) continue
|
|
85
|
+
const plan = planDocument(address as string, {
|
|
86
|
+
markdown: argsOf(data.arguments).plan,
|
|
87
|
+
htmlPlanMode: data.name === HTML_PLAN_EXIT_TOOL,
|
|
88
|
+
})
|
|
89
|
+
if (plan) return plan
|
|
90
|
+
}
|
|
91
|
+
return undefined
|
|
92
|
+
}
|
|
50
93
|
/** @public @author ddj 2026年10月08号 @param address Official address. @param value Provider or review payload. @returns Valid complete read-only plan, if available. */
|
|
51
94
|
export function planDocument(address: string, value: unknown): PlanDocument | undefined {
|
|
52
95
|
const data = record(value)
|
|
@@ -55,9 +98,13 @@ export function planDocument(address: string, value: unknown): PlanDocument | un
|
|
|
55
98
|
if (!title) return undefined
|
|
56
99
|
// HTML 计划页:正文标记行命中时随文档携带路径,计划页签据此切到 iframe 渲染。
|
|
57
100
|
const htmlPath = planPagePathOf(data.markdown)
|
|
58
|
-
|
|
101
|
+
// HTML 计划模式提交的计划:客户端据此渲染自动页,并允许无标记行的计划页签走插件渲染。
|
|
102
|
+
const htmlPlanMode = data.htmlPlanMode === true
|
|
103
|
+
const document: PlanDocument = htmlPath
|
|
59
104
|
? { address, markdown: data.markdown, title, htmlPath }
|
|
60
105
|
: { address, markdown: data.markdown, title }
|
|
106
|
+
if (htmlPlanMode) document.htmlPlanMode = true
|
|
107
|
+
return document
|
|
61
108
|
}
|
|
62
109
|
/** @private @author ddj 2026年10月08号 @param sessionId Current session. @param path Explicit plan path. @param cwd Workspace. Stores bounded associations, not file contents. */
|
|
63
110
|
function associate(sessionId: string, path: string, cwd: string): void {
|
|
@@ -111,10 +158,10 @@ export function createPlanFeed(sessionId: string, cwd = '') {
|
|
|
111
158
|
const call = event.type === 'tool/result' ? pending.get(id) : { name: String(data.name), args }
|
|
112
159
|
if (settled) pending.delete(id)
|
|
113
160
|
if (!call || !live || seen.has(id) || result.isError === true || data.error) return undefined
|
|
114
|
-
if (call.name ===
|
|
161
|
+
if (call.name === OFFICIAL_PLAN_EXIT_TOOL || call.name === HTML_PLAN_EXIT_TOOL) {
|
|
115
162
|
if (event.type === 'tool/result') return undefined
|
|
116
163
|
const address = 'dsh-resource://plan/' + encodeURIComponent(sessionId) + '/' + encodeURIComponent(id)
|
|
117
|
-
const plan = planDocument(address, { markdown: call.args.plan })
|
|
164
|
+
const plan = planDocument(address, { markdown: call.args.plan, htmlPlanMode: call.name === HTML_PLAN_EXIT_TOOL })
|
|
118
165
|
if (plan) { rememberPlan(plan); remember(id); return { plan } }
|
|
119
166
|
return undefined
|
|
120
167
|
}
|