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.
Files changed (66) hide show
  1. package/README.md +38 -33
  2. package/lib/client.js +87 -68
  3. package/lib/client.js.map +1 -1
  4. package/lib/index.js +11406 -4920
  5. package/lib/index.js.map +1 -1
  6. package/package.json +3 -2
  7. package/skills/dsh-vscodemode-html-plan/SKILL.md +44 -42
  8. package/skills/dsh-vscodemode-test-check/SKILL.md +82 -0
  9. package/src/archiveDb.ts +24 -0
  10. package/src/attachmentBytes.ts +84 -0
  11. package/src/client/htmlPlan/HtmlPlanModeChip.ts +181 -0
  12. package/src/client/htmlPlan/HtmlPlanPanel.ts +230 -61
  13. package/src/client/htmlPlan/planActions.ts +38 -8
  14. package/src/client/htmlPlan/planPage.ts +111 -9
  15. package/src/client/index.ts +9 -0
  16. package/src/client/openReceipt.ts +5 -2
  17. package/src/client/planBridge.ts +27 -2
  18. package/src/client/planState.ts +51 -4
  19. package/src/client/sidebar/panels/TestCheckPanel.ts +485 -0
  20. package/src/client/sidebar/panels/useTestCheckData.ts +414 -0
  21. package/src/client/sidebar/types.ts +2 -0
  22. package/src/client/state/diffSummary.ts +3 -0
  23. package/src/client/styles/editor.css +91 -0
  24. package/src/client/testCheck/TestCheckChip.ts +181 -0
  25. package/src/client/testCheck/TestCheckPanel.ts +339 -0
  26. package/src/client/testCheckPanelState.ts +173 -0
  27. package/src/client/ui/EditorView.ts +77 -7
  28. package/src/client/ui/McpSettings.ts +2 -2
  29. package/src/client/ui/OfficialReview.ts +6 -4
  30. package/src/htmlPlanAttachments.ts +4 -1
  31. package/src/htmlPlanCommand.ts +87 -235
  32. package/src/htmlPlanGuidance.ts +67 -0
  33. package/src/htmlPlanMode.ts +547 -0
  34. package/src/index.ts +28 -55
  35. package/src/officialCapture.ts +58 -9
  36. package/src/pending/externalCapture.ts +195 -401
  37. package/src/pending/kernel.ts +24 -1
  38. package/src/pending/persist.ts +109 -22
  39. package/src/pending/provenance.ts +5 -28
  40. package/src/pending/store.ts +109 -100
  41. package/src/pending/tracking.ts +81 -0
  42. package/src/pendingCompat.ts +26 -1
  43. package/src/pendingRpc.ts +8 -56
  44. package/src/planAutoPage.ts +306 -0
  45. package/src/planPagePack.ts +148 -0
  46. package/src/registry.ts +7 -2
  47. package/src/reviewDb.ts +1 -1
  48. package/src/reviewRpc.ts +14 -6
  49. package/src/rpc.ts +34 -0
  50. package/src/shared/htmlPlanMode.ts +26 -0
  51. package/src/shared/pendingReview.ts +15 -7
  52. package/src/shared/review.ts +5 -0
  53. package/src/shared/rpc.ts +53 -7
  54. package/src/shared/testCheck.ts +759 -0
  55. package/src/shared/testCheckHtml.ts +276 -0
  56. package/src/shared/testCheckPolicyDefault.ts +37 -0
  57. package/src/shared/testCheckSnippets.ts +197 -0
  58. package/src/store.ts +17 -1
  59. package/src/testCheckCommand.ts +287 -0
  60. package/src/testCheckGuidance.ts +79 -0
  61. package/src/testCheckMode.ts +654 -0
  62. package/src/testCheckPolicy.ts +141 -0
  63. package/src/testCheckRpc.ts +196 -0
  64. package/src/testCheckStore.ts +822 -0
  65. package/src/pending/externalAlign.ts +0 -297
  66. package/src/pending/vcs.ts +0 -584
@@ -1,51 +1,32 @@
1
1
  /**
2
- * dsh-vscode-mode host — /html-plan 命令:一键进入计划模式,并用 HTML 计划页交付。
2
+ * dsh-vscode-mode host — `/html-plan` 命令:进入/离开 HTML 计划模式。
3
3
  *
4
- * 机制(不复制官方逻辑):
5
- * - 宿主命令声明 input,rawInput 就是用户的「任务」;
6
- * - 处理器调用官方 /plan 命令并带上本插件的技能指令,官方 plan 处理器会
7
- * 进入计划模式并用 agent.steer 把这段指令作为用户消息送出;
8
- * - 因此这里不自行构造 UserMessage、不碰 plan 模式内部状态,官方不可用时直接报错(fail closed)。
4
+ * 与旧实现的区别:不再把一段长指令塞给官方 `/plan`,也不再要求模型写页面或跑 node;
5
+ * 命令只负责「选模式 + 把任务作为普通用户消息送进会话」,规则由 `html-plan:policy`
6
+ * 系统提示段落每请求提供(见 `htmlPlanMode.ts` / `htmlPlanGuidance.ts`)。
9
7
  *
10
- * 附件:命令声明 input.attachments,官方执行器把 composer 的图片/文件入库后再交给本处理器。
11
- * 处理器把字节复制到 plans/<slug>/assets/(agent 与打包脚本都读得到的工作区内路径),
12
- * 并把路径写进指令;失败只降级为说明文字,绝不阻断进入计划模式。
13
- * @author ddj 2026年11月21号
8
+ * 附件:命令声明 `input.attachments`,官方执行器把 composer 的图片/文件入库后再交给本处理器;
9
+ * 处理器把字节复制到 `plans/<slug>/assets/`(作者页可引用),并把路径写进送给模型的任务消息。
10
+ * @author ddj 2026年11月25号
14
11
  */
15
- import { mkdir, rmdir, unlink, writeFile } from 'node:fs/promises'
12
+ import { mkdir, writeFile } from 'node:fs/promises'
16
13
  import { dirname, join } from 'node:path'
17
- import { log } from './log.js'
18
14
  import { cwdOfSession, type Ctx } from './store.js'
19
- import {
20
- attachmentLines,
21
- slugFromTask,
22
- stageAttachments,
23
- type AttachmentStage,
24
- } from './htmlPlanAttachments.js'
15
+ import { attachmentLines, slugFromTask, stageAttachments } from './htmlPlanAttachments.js'
16
+ import { readChunks, rollbackFiles, toBytes } from './attachmentBytes.js'
17
+ import { HTML_PLAN_COMMAND } from './shared/htmlPlanMode.js'
18
+
19
+ //region 命令元信息
25
20
 
26
21
  /** 命令名(官方语法:小写字母开头,允许数字/_/-)。 */
27
- export const HTML_PLAN_COMMAND = 'html-plan'
22
+ export { HTML_PLAN_COMMAND }
28
23
 
29
24
  /** 命令描述(出现在 / 菜单与命令目录)。 */
30
- export const HTML_PLAN_DESCRIPTION = '用 HTML 计划页进入计划模式:/html-plan <任务>(可附图片或文件)'
31
-
32
- /** 计划指令模板版本(改文案时便于测试断言)。 */
33
- export const HTML_PLAN_INSTRUCTION_HEAD = '请使用技能 dsh-vscodemode-html-plan 规划下面的任务,并按 DSH 计划模式提交:'
34
-
35
- /** 裸 /html-plan 的指令:先问清任务,再产出 HTML 计划页。 */
36
- export const HTML_PLAN_BARE_INSTRUCTION = '请使用技能 dsh-vscodemode-html-plan 规划接下来的任务:先用一句话询问我要规划什么,再按技能规则产出 HTML 计划页,并在 exit_plan_mode 正文写一行「HTML 计划页:<path>」。'
37
-
38
- /** 委派开关:写在任务前,用户显式输入即视为本任务已授权委派。 */
39
- export const HTML_PLAN_DELEGATE_FLAG = '--delegate'
25
+ export const HTML_PLAN_DESCRIPTION = '进入或离开 HTML 计划模式:/html-plan [off|任务](可附图片或文件)'
40
26
 
41
- /** 关闭委派:即使达到阈值也不委派。 */
42
- export const HTML_PLAN_NO_DELEGATE_FLAG = '--no-delegate'
27
+ //endregion
43
28
 
44
- /** 委派写页的指令段(用户在 --delegate 下已授权)。 */
45
- export const HTML_PLAN_DELEGATE_INSTRUCTION = '写页方式:本次已获用户授权,写页阶段用一个 subagent_fork 专门写 plans/<slug>/plan.html 并打包。调研与主张树由你定稿后,给子级一份摘要(目标、主张列表、图示要点、决策、页路径与 plan.mjs 命令),要求它只写页与打包、返回 packed 路径与 lint 结果;父级只验 lint、计数与三处抽查,不读全文。子级失败则自己写。'
46
-
47
- /** 明确不委派的指令段(--no-delegate)。 */
48
- export const HTML_PLAN_SINGLE_AGENT_INSTRUCTION = '写页方式:本次不要委派子 agent,由你自己写计划页并用 plan.mjs 打包。'
29
+ //region 结构面
49
30
 
50
31
  /** 官方命令运行时最小结构面(宿主服务,鸭子类型)。 */
51
32
  interface CommandsLike {
@@ -63,7 +44,7 @@ interface CommandCtxLike {
63
44
  /** 官方命令调用(只声明本命令用到的字段)。 */
64
45
  export interface HtmlPlanInvocation {
65
46
  /** 接收命令的 agent。 */
66
- agent?: unknown
47
+ agent?: { steer?: (message: unknown) => unknown }
67
48
  /** 命令名之后的原始输入。 */
68
49
  rawInput?: unknown
69
50
  /** 取消信号。 */
@@ -74,22 +55,22 @@ export interface HtmlPlanInvocation {
74
55
 
75
56
  /** 附件准备结果(默认实现是落盘;测试可注入假的)。 */
76
57
  export interface AttachmentPrep {
77
- /** 固定 slug;没附件时 null(沿用 agent 自选)。 */
58
+ /** 固定 slug;没附件时 null。 */
78
59
  slug: string | null
79
60
  /** 落盘成功的附件数量。 */
80
61
  count: number
81
- /** 追加到指令里的附件段。 */
62
+ /** 追加到任务消息里的附件段。 */
82
63
  lines: string[]
83
- /** /plan 失败时回滚本次写入的附件。 */
64
+ /** 命令失败时回滚本次写入的附件。 */
84
65
  rollback: () => Promise<void>
85
66
  }
86
67
 
87
- /** 指令模板附加信息(固定 slug 与附件段)。 */
88
- export interface HtmlPlanInstructionExtras {
89
- /** 固定 slug(有附件时由命令决定)。 */
90
- slug?: string | null
91
- /** 附件说明行。 */
92
- attachmentLines?: readonly string[]
68
+ /** 命令输入解析结果。 */
69
+ export interface HtmlPlanInput {
70
+ /** off = 离开模式;enter = 进入模式(可带任务)。 */
71
+ action: 'off' | 'enter'
72
+ /** 剥离开关后的任务文本。 */
73
+ task: string
93
74
  }
94
75
 
95
76
  /** 附件存储服务最小结构面。 */
@@ -98,88 +79,39 @@ interface AttachmentStoreLike {
98
79
  readFileStream?: (ref: unknown, signal?: AbortSignal) => AsyncIterable<Uint8Array>
99
80
  }
100
81
 
101
- /** 安装选项(测试可替换指令模板与附件准备)。 */
82
+ /** 安装选项(测试可替换消息构造与附件准备)。 */
102
83
  export interface HtmlPlanCommandOptions {
103
- /** 自定义指令模板(入参为任务文本、委派开关与附加信息)。 */
104
- instructionOf?: (task: string, delegate?: boolean | null, extras?: HtmlPlanInstructionExtras) => string
84
+ /** 把纯文本包成宿主用户消息(由模式装配层注入 createUserMessage)。 */
85
+ buildUserMessage?: (text: string) => unknown
105
86
  /** 附件准备(默认落盘到 plans/<slug>/assets/);测试可替换。 */
106
87
  prepareAttachments?: (invocation: HtmlPlanInvocation, task: string) => Promise<AttachmentPrep>
107
88
  /** 宿主上下文:取 attachments 服务与会话工作区。 */
108
89
  hostCtx?: unknown
109
90
  }
110
91
 
111
- /** 命令输入解析结果。 */
112
- export interface HtmlPlanInput {
113
- /** true = --delegate,false = --no-delegate,null = 未指定。 */
114
- delegate: boolean | null
115
- /** 剥离开关后的任务文本。 */
116
- task: string
117
- }
92
+ //endregion
93
+
94
+ //region 输入解析
118
95
 
119
96
  /**
120
- * 解析 /html-plan 的输入:前导 --delegate / --no-delegate 开关(大小写不敏感,最后一个生效),
121
- * 其余文本作为任务。开关之外的文本原样保留(含内部空格与换行)。
122
- * @author ddj 2026年11月21号
97
+ * 解析 `/html-plan` 的输入:`off` 表示离开模式;其余文本作为任务(原样保留内部换行)。
98
+ * @author ddj 2026年11月25号
123
99
  * @param rawInput 官方命令的 rawInput
124
- * @returns 委派开关与任务文本
100
+ * @returns 动作与任务文本
125
101
  */
126
102
  export function parseHtmlPlanInput(rawInput: unknown): HtmlPlanInput {
127
- let rest = String(rawInput ?? '').trim()
128
- let delegate: boolean | null = null
129
- for (;;) {
130
- const match = /^(--delegate|--no-delegate)(?=\s|$)\s*/i.exec(rest)
131
- if (!match) break
132
- delegate = match[1].toLowerCase() === HTML_PLAN_DELEGATE_FLAG
133
- rest = rest.slice(match[0].length)
134
- }
135
- return { delegate, task: rest.trim() }
103
+ const text = String(rawInput ?? '').trim()
104
+ if (/^off$/i.test(text)) return { action: 'off', task: '' }
105
+ return { action: 'enter', task: text }
136
106
  }
137
107
 
138
- /**
139
- * 构造交给 agent 的计划指令:点名技能、产出路径、打包、标记行与审批方式。
140
- * 有附件时用命令固定下来的 slug,并把附件段插在步骤之后。
141
- * @author ddj 2026年11月21号
142
- * @param task 用户任务文本
143
- * @param delegate 委派开关(null = 未指定)
144
- * @param extras 固定 slug 与附件说明
145
- * @returns 完整用户消息正文
146
- */
147
- export function buildHtmlPlanInstruction(
148
- task: string,
149
- delegate: boolean | null = null,
150
- extras: HtmlPlanInstructionExtras = {},
151
- ): string {
152
- const objective = String(task ?? '').trim()
153
- const slug = typeof extras.slug === 'string' && /^[a-z0-9][a-z0-9-]*$/i.test(extras.slug) ? extras.slug : ''
154
- const pagePath = slug ? 'plans/' + slug + '/plan.html' : 'plans/<slug>/plan.html'
155
- const packedPath = slug ? 'plans/' + slug + '/plan.packed.html' : 'plans/<slug>/plan.packed.html'
156
- const command = slug
157
- ? 'node <技能目录>/runtime/plan.mjs ' + slug + ' --root <工作区>'
158
- : 'node <技能目录>/runtime/plan.mjs <slug> --root <工作区>'
159
- const check = slug ? 'plan.mjs ' + slug + ' --check' : 'plan.mjs <slug> --check'
160
- const steps = [
161
- '1. 先读相关代码与文件,按技能规则写 ' + pagePath + (slug ? '(slug 已固定,不要另起目录)。' : '(slug 用 kebab-case)。'),
162
- '2. 用一条命令打包:' + command + ',它会复制运行时、pack、清理;再跑 ' + check + ' 确认 plan.packed.html 在位。',
163
- '3. 计划模式允许写 plans/ 下的计划文件:不要因为「在计划模式」跳过写页面,更不要让我退出计划模式来生成。',
164
- '4. 页面确认生成后,才调用 exit_plan_mode:正文第一行必须是「# 计划:<标题>」,并单独一行「HTML 计划页:' + packedPath + '」;没生成成功就别写这一行,改交 Markdown 计划并说明原因。',
165
- '5. 计划正文同时给出 3~6 行摘要与待决策清单;不要绕过计划模式直接开工。',
166
- ]
167
- const attachment = (extras.attachmentLines ?? []).filter((line) => typeof line === 'string' && line.trim() !== '')
168
- const extra = delegate === null ? '' : (delegate ? HTML_PLAN_DELEGATE_INSTRUCTION : HTML_PLAN_SINGLE_AGENT_INSTRUCTION)
169
- const lines = [
170
- HTML_PLAN_INSTRUCTION_HEAD,
171
- ...steps,
172
- ...(attachment.length ? ['', ...attachment] : []),
173
- ...(extra ? [String(steps.length + 1) + '. ' + extra] : []),
174
- '',
175
- '任务:' + objective,
176
- ]
177
- return lines.join('\n')
178
- }
108
+ //endregion
109
+
110
+ //region 附件落盘
179
111
 
180
112
  /**
181
113
  * 取异常的展示文案。
182
- * @author ddj 2026年11月21号
114
+ * @author ddj 2026年11月25号
183
115
  * @param error 捕获值
184
116
  * @returns 可读文案
185
117
  */
@@ -188,71 +120,13 @@ function messageOf(error: unknown): string {
188
120
  return String(error ?? '未知错误')
189
121
  }
190
122
 
191
- /**
192
- * 把流式字节拼成一个 Uint8Array(附件可能是任意长度,不假设单块)。
193
- * @author ddj 2026年11月24号
194
- * @param source 按顺序产出的字节块
195
- * @returns 拼接后的字节
196
- */
197
- async function readChunks(source: AsyncIterable<Uint8Array>): Promise<Uint8Array> {
198
- const parts: Uint8Array[] = []
199
- let total = 0
200
- for await (const part of source) {
201
- parts.push(part)
202
- total += part.byteLength
203
- }
204
-
205
- const merged = new Uint8Array(total)
206
- let offset = 0
207
- for (const part of parts) {
208
- merged.set(part, offset)
209
- offset += part.byteLength
210
- }
211
- return merged
212
- }
213
-
214
- /**
215
- * 归一化附件存储返回的字节。
216
- * @author ddj 2026年11月24号
217
- * @param value 服务返回值
218
- * @returns 字节视图
219
- * @throws 无法识别时抛错(由上层记入 skipped)
220
- */
221
- function toBytes(value: unknown): Uint8Array {
222
- if (value instanceof Uint8Array) return value
223
- if (value instanceof ArrayBuffer) return new Uint8Array(value)
224
- if (ArrayBuffer.isView(value)) return new Uint8Array(value.buffer, value.byteOffset, value.byteLength)
225
- throw new Error('附件存储返回了无法识别的字节')
226
- }
227
-
228
- /**
229
- * 回滚本次写入的附件:逐个删除文件,再尝试移除空目录。
230
- * @author ddj 2026年11月24号
231
- * @param workspace 工作区绝对路径
232
- * @param stage 落盘结果
233
- * @returns 完成后的 Promise(单步失败只忽略)
234
- */
235
- async function rollbackStage(workspace: string, stage: AttachmentStage): Promise<void> {
236
- for (const file of stage.files) {
237
- try {
238
- await unlink(join(workspace, file.relativePath))
239
- } catch {
240
- /* 文件可能已被删除 */
241
- }
242
- }
243
- try {
244
- await rmdir(join(workspace, stage.dir))
245
- } catch {
246
- /* 目录非空或已不存在 */
247
- }
248
- }
249
123
 
250
124
  /**
251
125
  * 默认附件准备:把 composer 的图片/文件复制到 plans/<slug>/assets/。
252
126
  *
253
- * 任何失败(服务缺失、读字节失败、写盘失败)都降级成说明行,不阻断进入计划模式;
254
- * 只有 /plan 调用失败时才会回滚本次写入。
255
- * @author ddj 2026年11月24号
127
+ * 任何失败(服务缺失、读字节失败、写盘失败)都降级成说明行,不阻断进入模式;
128
+ * 只有命令最终失败时才会回滚本次写入。
129
+ * @author ddj 2026年11月25号
256
130
  * @param hostCtx 宿主上下文
257
131
  * @param invocation 官方命令调用
258
132
  * @param task 任务文本(派生 slug)
@@ -300,7 +174,7 @@ export async function stagePlanFiles(
300
174
  slug,
301
175
  count: stage.files.length,
302
176
  lines: attachmentLines(stage),
303
- rollback: () => rollbackStage(workspace, stage),
177
+ rollback: () => rollbackFiles(workspace, stage),
304
178
  }
305
179
  } catch (error) {
306
180
  return { slug: null, count: 0, lines: ['附件读取失败:' + messageOf(error) + ';本次按无附件规划。'], rollback: async () => {} }
@@ -309,7 +183,7 @@ export async function stagePlanFiles(
309
183
 
310
184
  /**
311
185
  * 回滚但不覆盖原始错误。
312
- * @author ddj 2026年11月24号
186
+ * @author ddj 2026年11月25号
313
187
  * @param prep 附件准备结果(可能为空)
314
188
  * @returns 完成后的 Promise
315
189
  */
@@ -322,94 +196,72 @@ async function rollbackOf(prep: AttachmentPrep | null): Promise<void> {
322
196
  }
323
197
  }
324
198
 
199
+ //endregion
200
+
201
+ //region 命令定义
202
+
325
203
  /**
326
- * 构造 /html-plan 命令定义(导出便于单测直接调用 handler)。
327
- * @author ddj 2026年11月21号
204
+ * 构造 `/html-plan` 命令定义(导出便于单测直接调用 handler)。
205
+ * @author ddj 2026年11月25号
328
206
  * @param commands 官方命令运行时
329
207
  * @param options 安装选项
330
208
  * @returns 官方 CommandDefinition 形状对象
331
209
  */
332
210
  export function htmlPlanCommandDefinition(commands: CommandsLike, options: HtmlPlanCommandOptions = {}): unknown {
333
- const instructionOf = typeof options.instructionOf === 'function' ? options.instructionOf : buildHtmlPlanInstruction
334
211
  const prepareAttachments = typeof options.prepareAttachments === 'function'
335
212
  ? options.prepareAttachments
336
213
  : (invocation: HtmlPlanInvocation, task: string) => stagePlanFiles(options.hostCtx, invocation, task)
337
214
  return {
338
215
  name: HTML_PLAN_COMMAND,
339
216
  description: HTML_PLAN_DESCRIPTION,
340
- input: { hint: '<任务描述>(可附图片或文件)', attachments: true },
341
- /** @private @author ddj 2026年11月21号 @param invocation 官方命令调用。 @returns 成功/错误结算。 */
217
+ input: { hint: '[off|任务](可附图片或文件)', attachments: true },
218
+ /** @private @author ddj 2026年11月25号 @param invocation 官方命令调用。 @returns 成功/错误结算。 */
342
219
  handler: async (invocation: HtmlPlanInvocation) => {
343
220
  const parsed = parseHtmlPlanInput(invocation?.rawInput)
344
- const task = parsed.task
345
- if (typeof commands.execute !== 'function') return { kind: 'error', text: '无法进入计划模式:官方 /plan 命令不可用' }
346
- const signal = invocation?.signal instanceof AbortSignal ? invocation.signal : new AbortController().signal
221
+ const blocks = Array.isArray(invocation?.attachments) ? invocation.attachments.filter(Boolean) : []
222
+
223
+ if (parsed.action === 'off') {
224
+ if (blocks.length) return { kind: 'error', text: '离开 HTML 计划模式不能附带图片或文件' }
225
+ return { kind: 'success', text: 'HTML 计划模式已关闭。' }
226
+ }
347
227
 
348
228
  let prep: AttachmentPrep | null = null
349
229
  try {
350
- prep = await prepareAttachments(invocation, task)
230
+ prep = await prepareAttachments(invocation, parsed.task)
351
231
  } catch (error) {
352
232
  prep = { slug: null, count: 0, lines: ['附件读取失败:' + messageOf(error)], rollback: async () => {} }
353
233
  }
354
234
 
355
- try {
356
- const delegateNote = parsed.delegate === null ? '' : '\n' + (parsed.delegate ? HTML_PLAN_DELEGATE_INSTRUCTION : HTML_PLAN_SINGLE_AGENT_INSTRUCTION)
357
- const extras: HtmlPlanInstructionExtras = { slug: prep?.slug ?? null, attachmentLines: prep?.lines ?? [] }
358
- const message = task
359
- ? instructionOf(task, parsed.delegate, extras)
360
- : HTML_PLAN_BARE_INSTRUCTION + delegateNote + (prep?.lines.length ? '\n\n' + prep.lines.join('\n') : '')
361
- const execution = await commands.execute(invocation?.agent, '/plan ' + message, [], signal)
362
- if (!execution) {
235
+ const lines: string[] = []
236
+ if (parsed.task) lines.push(parsed.task)
237
+ if (prep?.lines.length) {
238
+ if (lines.length) lines.push('')
239
+ lines.push(...prep.lines)
240
+ }
241
+
242
+ const text = lines.join('\n')
243
+ if (text) {
244
+ const steer = invocation?.agent?.steer
245
+ const build = options.buildUserMessage
246
+ if (typeof steer !== 'function' || typeof build !== 'function') {
363
247
  await rollbackOf(prep)
364
- return { kind: 'error', text: '无法进入计划模式:官方 /plan 命令不可用' }
248
+ return { kind: 'error', text: '无法把任务送进会话:宿主缺少消息构造或 steer 能力' }
365
249
  }
366
- if (execution.result?.kind !== 'success') {
250
+ try {
251
+ steer.call(invocation.agent, build(text))
252
+ } catch (error) {
367
253
  await rollbackOf(prep)
368
- return { kind: 'error', text: '无法进入计划模式:' + String(execution.result?.text ?? '未知原因') }
254
+ return { kind: 'error', text: '无法把任务送进会话:' + messageOf(error) }
369
255
  }
370
- const saved = prep && prep.count > 0 && prep.slug ? '(' + String(prep.count) + ' 个附件在 plans/' + prep.slug + '/assets/)' : ''
371
- return { kind: 'success', text: (task ? 'HTML 计划模式已开启:正在生成 HTML 计划页…' : 'HTML 计划模式已开启:请描述要规划的任务') + saved }
372
- } catch (error) {
373
- await rollbackOf(prep)
374
- return { kind: 'error', text: '无法进入计划模式:' + messageOf(error) }
375
256
  }
257
+
258
+ const saved = prep && prep.count > 0 && prep.slug ? '(' + String(prep.count) + ' 个附件在 plans/' + prep.slug + '/assets/)' : ''
259
+ const opened = parsed.task
260
+ ? 'HTML 计划模式已开启(离开用 /html-plan off)。'
261
+ : 'HTML 计划模式已开启:请描述要规划的任务(离开用 /html-plan off)。'
262
+ return { kind: 'success', text: opened + saved }
376
263
  },
377
264
  }
378
265
  }
379
266
 
380
- /**
381
- * 装配 /html-plan 宿主命令(commands 服务惰性获取;缺失时降级记日志,不抛错)。
382
- * @author ddj 2026年11月21号
383
- * @param ctx DSH host 上下文
384
- * @param options 安装选项
385
- * @returns 是否已调度注册(inject 回调异步执行)
386
- */
387
- export function installHtmlPlanCommand(ctx: Ctx, options: HtmlPlanCommandOptions = {}): boolean {
388
- const inject = (ctx as { inject?: unknown } | undefined)?.inject
389
- if (typeof inject !== 'function') {
390
- log.warn('/html-plan 未注册:DSH 未提供 ctx.inject')
391
- return false
392
- }
393
- try {
394
- ;(inject as (services: string[], callback: (sctx: unknown) => void) => unknown).call(ctx, ['commands'], (sctx) => {
395
- const commandCtx = sctx as CommandCtxLike
396
- const commands = commandCtx?.commands
397
- if (!commands || typeof commands.register !== 'function') {
398
- log.warn('/html-plan 未注册:commands 服务不支持 register')
399
- return
400
- }
401
- const mount = (): unknown => commands.register!(htmlPlanCommandDefinition(commands, { ...options, hostCtx: sctx }))
402
- try {
403
- if (typeof commandCtx.effect === 'function') commandCtx.effect(mount, 'vscode-mode: html-plan command')
404
- else mount()
405
- log.info('/html-plan 已注册:进入计划模式并用 HTML 计划页交付')
406
- } catch (error) {
407
- log.warn('/html-plan 注册失败:' + messageOf(error))
408
- }
409
- })
410
- } catch (error) {
411
- log.warn('/html-plan 注册调度失败:' + messageOf(error))
412
- return false
413
- }
414
- return true
415
- }
267
+ //endregion
@@ -0,0 +1,67 @@
1
+ /**
2
+ * dsh-vscode-mode host — HTML 计划模式的规则文本(纯函数,无 IO)。
3
+ *
4
+ * 对齐官方 `dsh-plan-mode` 的 `plan:policy` / `plan:status`:规则段落首次进入后常驻,
5
+ * 开头一句限定「只在模式活跃时适用」;状态段落每个请求按活跃状态给一句话。
6
+ * 文案拆成纯函数,便于单测三种状态(未进入 / 活跃 / 已退出)。
7
+ * @author ddj 2026年11月25号
8
+ */
9
+
10
+ //region 常量
11
+
12
+ /** 规则段落首句:与官方 plan:policy 同款的范围限定。 */
13
+ export const HTML_PLAN_POLICY_SCOPE = 'The following instructions apply only while HTML plan mode is active.'
14
+
15
+ /** 模式活跃时的状态句(对齐官方 plan:status)。 */
16
+ export const HTML_PLAN_STATUS_ACTIVE = 'HTML plan mode is active. Follow the html-plan instructions.'
17
+
18
+ /** 模式退出后的状态句(对齐官方 plan:status)。 */
19
+ export const HTML_PLAN_STATUS_INACTIVE = 'HTML plan mode is inactive. The html-plan instructions no longer apply.'
20
+
21
+ //endregion
22
+
23
+ //region 规则正文
24
+
25
+ /**
26
+ * HTML 计划模式的规则正文(不含首句范围限定)。
27
+ * @author ddj 2026年11月25号
28
+ * @returns 多行规则文本
29
+ */
30
+ export function htmlPlanRulesText(): string {
31
+ return [
32
+ 'HTML 计划模式已开启(与官方计划模式同级)。',
33
+ '',
34
+ '限制:只探索、只规划;不改源码,不运行会修改文件的命令。',
35
+ '交付物:一页 HTML 计划页。页面由插件负责:',
36
+ ' - 可选:把页面写到 plans/<slug>/plan.html(这是本模式唯一允许的写操作),',
37
+ ' 并在提交正文里加一行「HTML 计划页:plans/<slug>/plan.html」;插件会自动打包。',
38
+ ' - 不写也可以:插件会用你提交的计划正文渲染一页。',
39
+ '提交:调用 exit_html_plan_mode;plan 正文第一行必须是「# 计划:<标题>」,',
40
+ '并给出 3~6 行摘要与待决策清单。',
41
+ '不要运行打包命令,不要为页面退出模式,不要调用 exit_plan_mode(那是另一个模式的工具)。',
42
+ '如果用户还没有给出任务,先用一句话问清要规划什么,再开始。',
43
+ ].join('\n')
44
+ }
45
+
46
+ /**
47
+ * 规则段落正文:首次进入后常驻,用首句限定适用范围。
48
+ * @author ddj 2026年11月25号
49
+ * @returns 可直接作为 systemPrompt section 文本的多行字符串
50
+ */
51
+ export function htmlPlanPolicyText(): string {
52
+ return HTML_PLAN_POLICY_SCOPE + '\n\n' + htmlPlanRulesText()
53
+ }
54
+
55
+ /**
56
+ * 状态段落正文:未进入过模式时为空;进入过则按活跃状态二选一。
57
+ * @author ddj 2026年11月25号
58
+ * @param entered 是否进入过 HTML 计划模式
59
+ * @param active 当前是否活跃
60
+ * @returns 一行状态文本;未进入时为空串
61
+ */
62
+ export function htmlPlanStatusText(entered: boolean, active: boolean): string {
63
+ if (!entered) return ''
64
+ return active ? HTML_PLAN_STATUS_ACTIVE : HTML_PLAN_STATUS_INACTIVE
65
+ }
66
+
67
+ //endregion