dsh-workplan 1.8.4 → 1.9.1

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.
@@ -0,0 +1,67 @@
1
+ # v1.9.1 — 圈注三行能自己变绿,1.9.0 的四项遗留全修完
2
+
3
+ ## 一句话
4
+
5
+ `dsh_workplan_followup` 让被中止的子会话在**用户授权后自己再跑完一个正常回合**,
6
+ 界面据此变绿;同时把 1.9.0 明确留到「下一批」的四项(superseded 写侧、P1 拒绝码、
7
+ W1 digest、W5 真实取消联测)全部落地。npm 上此前最新是 **1.8.18**,`1.9.0` 与
8
+ `1.9.1` 都从未发布,所以升到 1.9.1 会一次性拿到 1.9.0 与 1.9.1 的全部修复。
9
+
10
+ ## 你会看到什么变化
11
+
12
+ | 之前 | 现在 |
13
+ |---|---|
14
+ | 被整轮预算 / 900s 上限中止的子会话永远是灰点(`lastTurnCompleted=false`),改台账也不会变绿 | `dsh_workplan_followup` 把说明投递给父会话登记过的**直接**子会话;子会话自己跑完一轮后 `turn/end` 正常,界面自然变绿 |
15
+ | 想把一个已取消计划的交付责任转给另一个计划,只能手改记录 → 重启后 live 与 replay 分叉 | `dsh_workplan_cancel` 支持 `disposition:'superseded'` + `supersededBy`,V1–V8 核验全过才写、`coverage`/`digest` 由运行时复算,append 成功才翻内存状态 |
16
+ | 全部子任务 done 但证据有缺口时,`present` 的拒绝码是 `ACTIVE_NOT_READY`,用户分不清「没做完」和「证据不齐」 | 统一走 `activeDenyCode()`:`remaining` 空 + `blockers` 非空 ⇒ `EVIDENCE_GAP`,其余 ⇒ `ACTIVE_NOT_READY`;拒绝文案不变 |
17
+ | 覆盖映射存进日志后无法复核是否被改动 | `sha256(canonical(mapping))` 规范化摘要(sort_keys + 紧凑分隔符 + 非 ASCII 不转义),读侧只重算、不信任缓存值,重算不一致即 stale |
18
+ | 取消 / 取代的信封只在单测里用桩件验证 | W5 联测直接走真实 `buildCancelMessage` 信封 → durable 记录 → replay 读回,覆盖两种处置与终态互斥 |
19
+
20
+ ## 修复内容
21
+
22
+ ### 1. `dsh_workplan_followup`(1.9.1 主体)
23
+
24
+ - 只允许根会话调用;目标必须是父会话 `subagent/catalog` 里登记的**直接**子会话。
25
+ - 只投递、不改状态:不写台账、不触发 `present`、不改 `lastTurnCompleted`;
26
+ 是否变绿由子会话自己的下一轮 `turn/end` 决定。
27
+ - 拒绝码:`NOT_ROOT` / `NOT_DIRECT_CHILD` / `NO_SUBAGENT_SERVICE` / `DELIVERY_FAILED`;
28
+ 空 message 或超 4000 字符直接拒绝。
29
+
30
+ ### 2. superseded 写侧(唯一入口)
31
+
32
+ - `src/supersede.ts`:`supersedePlanRecord()` 是 `superseded` 的唯一写路径;
33
+ V1–V8 任一失败返回 `ok:false` + `SUPERSEDE_*` 码,**不改内存、不写日志**。
34
+ - `src/plan.ts`:`buildCancelMessage(..., { disposition:'superseded' })` 是全仓库唯一
35
+ 拼装 `workplan-cancel` 信封的出口;自动覆盖路径只允许写 `cancelled`。
36
+ - 用户确认(V8)必须是真实用户消息:同时包含两个 planId 且含
37
+ 「确认/同意/可以/按此执行」之一;模型自述不算确认。
38
+
39
+ ### 3. P1 拒绝码统一
40
+
41
+ - `PRESENT_DENY_CODES` + `activeDenyCode()` 收敛 `present` 的两个未完成分支;
42
+ 码值对外可断言,文案逐字保留;`EVIDENCE_GAP` 散落字符串 0 处。
43
+
44
+ ### 4. W1 digest
45
+
46
+ - `src/supersede-digest.ts`:`canonicalMappingJson()` / `computeMappingDigest()` /
47
+ `verifyMappingDigest()` / `withMappingDigest()`;摘要只证明「存下来的 mapping
48
+ 没被改动」,不证明两项工作在语义上等价。
49
+
50
+ ### 5. W5 真实取消信封联测
51
+
52
+ - `tests/workplan-w5-cancel-e2e.test.ts` 5 例:1.8.19 真实信封字段契约不变、
53
+ 事故同构场景、生产写路径 schema 一致、D2 未放宽、superseded 增量字段降级可读。
54
+
55
+ ## 升级与兼容
56
+
57
+ - 旧调用不受影响:`dsh_workplan_cancel` 的 `disposition` 缺省仍是 `cancelled`。
58
+ - 旧会话可回放:`superseded` 是增量字段,旧读侧按 `cancelled` 降级可读。
59
+ - 需要 Node ≥ 22(`engines.node` 未变)。
60
+
61
+ ## 证据(发布时复核)
62
+
63
+ - `npm run check` EXIT 0(无诊断)。
64
+ - `npm test` EXIT 0:**306 / 306**(1.9.0 基线 277,净增 29)。
65
+ - 两次构建 7 个产物(`lib/*.js` + `client.js`)sha256 完全一致。
66
+ - `npm pack`:产物清单、体积与 `shasum` 在发布记录 `docs/release-record-1.9.1-20261101.md` 中逐项登记
67
+ (本文件自身也在包内,因此不在此处写会随本文件变化的体积数字)。
@@ -0,0 +1,70 @@
1
+ # 发布记录 — 1.8.4(2026-10-30)
2
+
3
+ > 每一次发布留一条可复核的时间线:tag、commit、制品哈希、渠道复验命令与输出。
4
+
5
+ ## 制品身份
6
+
7
+ | 项 | 值 |
8
+ |---|---|
9
+ | 版本 | 1.8.4 |
10
+ | commit | `0c8564c`(`Fix 已结束 shown while dispatch still running (1.8.4)`) |
11
+ | tag | `v1.8.4` |
12
+ | 本地制品 | `dsh-workplan-1.8.4.tgz`,590051 B |
13
+ | sha256 | `3b180810336030740560a8bfb249eb44b809a4fda608bc43ce28a7190e10af1b` |
14
+ | GitHub Release | https://github.com/abbaababa/dsh-workplan/releases/tag/v1.8.4 |
15
+ | npm | `dsh-workplan@1.8.4`,integrity `sha512-UnFQJPX76vgcx3dMe3/5x1BDTp22mrJd1cEndDP/wKiwOUDZBAu7V3rkACHs5nC6lwMwjixZ4Yx5qMDtVUEWbQ==` |
16
+
17
+ ## 发布前检查(全部通过)
18
+
19
+ ```
20
+ $ npm run check # tsc --noEmit,无输出即通过
21
+ $ npm test # ℹ tests 196 ℹ pass 196 ℹ fail 0
22
+ $ npm run build && git diff --exit-code -- lib client.js
23
+ REPRODUCIBLE: clean
24
+ ```
25
+
26
+ ## 渠道复验(实际输出)
27
+
28
+ ```
29
+ $ npm view dsh-workplan dist-tags --json
30
+ [ { "latest": "1.8.4" } ]
31
+
32
+ $ npm view dsh-workplan@1.8.4 version dist.tarball
33
+ version = '1.8.4'
34
+ dist.tarball = 'https://registry.npmjs.org/dsh-workplan/-/dsh-workplan-1.8.4.tgz'
35
+
36
+ $ gh api repos/abbaababa/dsh-workplan/releases/tags/v1.8.4 \
37
+ --jq '.tag_name, (.assets[] | {name, state, size})'
38
+ v1.8.4
39
+ {"content_type":"application/x-gtar","name":"dsh-workplan-1.8.4.tgz","size":590051,"state":"uploaded"}
40
+ ```
41
+
42
+ **未在本机复验的一项**:`curl -sIL` 直连 `release-assets.githubusercontent.com` 在本机
43
+ TLS 握手超时(`http=000`),因此「浏览器/包管理器直链下载返回 200」这条只能在网络可达的
44
+ 机器上确认。Release 侧的资产状态已由 GitHub API 证明为 `uploaded`,大小与本地制品一致
45
+ (590051 B)。
46
+
47
+ ## 生效方式
48
+
49
+ 本机 profile 里 `~/.dsh/profiles/web/node_modules/dsh-workplan` 是指向本仓库的软链接,
50
+ 源码与 `lib/`、`client.js` 已在发布前更新;**运行中的 `dsh web`(PID 27767,18:42:45 启动)
51
+ 仍在用启动时加载的旧模块**,重启一次才生效:
52
+
53
+ ```bash
54
+ # 先停掉当前的 dsh web,再用同一条精确命令拉起(会中断正在运行的会话)
55
+ node /Users/open/.npm/_npx/bd325e168b7188a4/node_modules/.bin/dsh \
56
+ --profile web --host 127.0.0.1 --port 3080 \
57
+ --trusted-host openmacbook-pro-1.ts.net --no-open
58
+ ```
59
+
60
+ ## 发布后离线复验(用事故会话真实日志重算)
61
+
62
+ ```
63
+ $ T3_EXPAND=session-b83e4a75-225a-4e78-9bb2-d8cb90078278 \
64
+ node docs/status-audit/t3-render_sidebar_state.mjs \
65
+ ~/.dsh/sessions/--Users-open-Documents-Stocks--/session-b83e4a75-.../session.v4.jsonl.zstd
66
+ payload: {"phase":"ended","suspendedPhase":"blocked","inProgress":0,"violations":[]}
67
+ expanded: 分步进度 11/15 做好了 总体进度 73% 0 正在做 · 0 还没开始 4 卡住了
68
+ badge: 已结束,可续跑 · 卡住了
69
+ hint: 对主 Agent 说「续跑这个计划」,会从受阻处继续(已完成的不重跑)(还可续跑 4 次)
70
+ ```
package/lib/host.js CHANGED
@@ -1,4 +1,7 @@
1
+ import { createHash } from 'node:crypto';
1
2
  import { readFileSync } from 'node:fs';
3
+ import { dirname, join } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
2
5
  /**
3
6
  * Host half of dsh-workplan.
4
7
  *
@@ -10,6 +13,46 @@ import { readFileSync } from 'node:fs';
10
13
  */
11
14
  import { applyHardeningHeaders, cancelToolOutputSchema, createWorkplanRuntime, dispatchToolOutputSchema, plannerOutputSchema, statusToolOutputSchema, updateToolOutputSchema, } from './runtime.js';
12
15
  import { isRecord } from './plan.js';
16
+ /*
17
+ * [1.8.14] Identity of the modules this process actually loaded (N1).
18
+ *
19
+ * `version` alone cannot answer "is the running process the build I just
20
+ * shipped": the same version can be rebuilt, and a profile recomposition can
21
+ * leave stale modules in memory while the files on disk are new. Hashing the
22
+ * compiled entry files that make up the plugin at activation time gives a
23
+ * value that changes whenever the loaded bytes change. It is computed once, so
24
+ * it cannot drift during the process's life.
25
+ *
26
+ * [1.8.15] `watchdog.js` was missing from the list even though runtime.ts
27
+ * imports it and the build copies it next to the other entries. Appending a
28
+ * line to it left the fingerprint unchanged (T5c §6.1) — a build identity that
29
+ * ignores a loaded module is a false negative, exactly what it exists to catch.
30
+ */
31
+ const LOADED_BUILD = (() => {
32
+ try {
33
+ const entryPath = fileURLToPath(import.meta.url);
34
+ const dir = dirname(entryPath);
35
+ const hash = createHash('sha256');
36
+ for (const file of ['host.js', 'runtime.js', 'plan.js', 'watchdog.js']) {
37
+ hash.update(readFileSync(join(dir, file)));
38
+ }
39
+ return { entryPath, buildHash: hash.digest('hex').slice(0, 16) };
40
+ }
41
+ catch {
42
+ /*
43
+ * Never fail activation for a diagnostic. An unknown fingerprint is still a
44
+ * truthful answer ("I cannot prove which bytes I am"), and `status` will
45
+ * show `unknown` instead of a fabricated hash.
46
+ */
47
+ return { entryPath: '', buildHash: 'unknown' };
48
+ }
49
+ })();
50
+ /*
51
+ * Process start time derived from `process.uptime()`, so it is the actual OS
52
+ * process start, not the moment the plugin was constructed. Used to tell
53
+ * "restarted after the fix" from "same process, rebuilt files on disk".
54
+ */
55
+ const PROCESS_STARTED_AT = Date.now() - Math.round(process.uptime() * 1000);
13
56
  function phaseLabel(phase) {
14
57
  if (phase === 'paused')
15
58
  return '本轮预算用尽,可续跑';
@@ -41,7 +84,25 @@ const PROMPT_SECTION = [
41
84
  '2. 核对每个完成子任务的证据与验收标准,不合格的要用 dsh_workplan_update 标记为 blocked 或 in_progress;',
42
85
  '3. 对受阻项向用户说明,必要时先询问再继续;',
43
86
  '4. 不要声称未经验证的完成,不要重复派发已完成的子任务。',
44
- '结果消息里每个完成项都带 verification 与 acceptance:`structured` 是子 Agent 逐条自检通过,`unverified` 是自述但未逐条确认,`failed` 是自检失败(已按受阻处理),`legacy` 是旧格式回传。只把 structured 当作可直接采信,其余必须你自己核对产物。',
87
+ /*
88
+ * [1.8.7] 硬规则:ok:true 不等于完成。
89
+ *
90
+ * 事故(session-99984ebd…)里模型把「本轮预算用尽,可续跑(10/13)」当成
91
+ * 成功,直接 present 并收尾。提示词必须把「complete 字段才是完成」写到
92
+ * 不可误解,并且与 runtime 的回合收尾闸门(agent/turn-stopping)形成双保险。
93
+ */
94
+ /*
95
+ * [1.8.13] 用户明确取消不是完成。
96
+ *
97
+ * 1.8.7 的原文是「全部 done(或用户明确取消)」,T5-C 就是拿这句话把
98
+ * “取消 1/3 再 present”走通的:提示词把它写成完成等价物,present 的
99
+ * planIncomplete 又对 cancelled 短路。现在完成只有一个判据:全部 done
100
+ * 且 deliveryReady=true。
101
+ */
102
+ '5. 「完成」只有一个判据:计划里全部子任务都是 done,**且** deliveryReady=true(每个 done 项 verification="structured"、acceptance 非空且逐项 result="pass"、无缺失产物)。用户取消 ≠ 完成:取消只停止执行,未完成项仍然是未完成。`dsh_workplan_dispatch` 返回 ok:true / complete:true 只表示调用成功或状态全 done,必须再看 deliveryReady 与 完成 X/Y;只要 deliveryReady=false 或还有 pending/blocked,就禁止 present 交付物、禁止写“已完成/最终版/已交付”、禁止给收尾性最终答复,必须先再次调用 dsh_workplan_dispatch 续跑剩余项。',
103
+ '6. 如果续跑被拒绝、受阻项无法恢复、证据补不齐、计划已取消但未完成,或用户要求先看中间结果:答复开头必须写「未完成:剩余 N 项(列出 ID)与原因」,正文只能按中间结果表述,不得包装成成品。取消不会给你交付许可。',
104
+ '7. 子任务有硬执行上限(默认 15 分钟/步)与整轮预算(默认 20 分钟):子 Agent 接近上限时应先把已完成内容落盘并在结论里列出路径。任何「达到执行上限」「本轮预算用尽」都不等于「什么都没做」:状态里的 error 会列出「声明产物已在盘上」,必须先用文件核对;若产物已覆盖验收标准,用 dsh_workplan_update 复核改判,只补缺失部分再续跑,禁止无视盘上产物把整步重跑。',
105
+ '结果消息里每个完成项都带 verification 与 acceptance:`structured` 是子 Agent 逐条自检通过,`unverified` 是自述但未逐条确认,`failed` 是自检失败(已按受阻处理),`legacy` 是旧格式回传。只有 structured 且 acceptance 每项 pass 才算可交付;其余必须你自己核对产物,并用 dsh_workplan_update 的 verification/acceptance/artifacts 字段把核对结果写回(这些字段会持久化、刷新后仍生效),不要把“看着没问题”当成证据。',
45
106
  '子 Agent 通过 `needs` 提出的跨部门需求会列在结果消息的「跨部门待转达」里:由你逐条处理(补派、向用户确认或直接完成),不要忽略。',
46
107
  '长任务可以用 `dsh_workplan_dispatch({ mode: "async" })` 先开跑并立即答复用户,再用 `dsh_workplan_status` 查看进度;async 返回的是“已开跑”,不是“已完成”。',
47
108
  '如果自动分解降级,先向用户说明失败原因并询问是否重试,在用户确认前不要开始执行任务。',
@@ -81,7 +142,10 @@ function createUpdateTool(runtime) {
81
142
  return {
82
143
  name: 'dsh_workplan_update',
83
144
  description: '更新当前任务分解计划中一个子任务的状态与证据。仅用于本会话已生成的主计划;子 Agent 不可调用。'
84
- + '当主 Agent 核对子任务结果、发现完成不实或需要修正时使用。',
145
+ + '当主 Agent 核对子任务结果、发现完成不实或需要修正时使用。'
146
+ + '把子任务标成 done 时,必须同时给出真实的 verification 与 acceptance(每项 result="pass"),'
147
+ + '否则计划不会变成可交付状态(deliveryReady=false,present 会被拒绝)。'
148
+ + '这些字段会写入会话日志,刷新/重启后仍然生效。',
85
149
  parameters: {
86
150
  type: 'object',
87
151
  properties: {
@@ -105,7 +169,47 @@ function createUpdateTool(runtime) {
105
169
  evidence: {
106
170
  type: 'array',
107
171
  items: { type: 'string' },
108
- description: '支持该状态的证据(文件、命令输出、验收结果)。',
172
+ description: '支持该状态的证据(文件、命令输出、验收结果)。只用于说明,不参与可交付判定。',
173
+ },
174
+ verification: {
175
+ type: 'string',
176
+ enum: ['structured', 'legacy', 'unverified', 'failed'],
177
+ description: '证据等级:structured=逐条自检通过;unverified=自述未逐条确认;'
178
+ + 'legacy=旧格式回传(没有结构化证据);failed=自检失败。'
179
+ + '可交付要求 structured。',
180
+ },
181
+ acceptance: {
182
+ type: 'array',
183
+ description: '验收项及逐项结果;可交付要求非空且每项 result="pass"。',
184
+ items: {
185
+ type: 'object',
186
+ properties: {
187
+ criterion: { type: 'string', description: '验收标准。' },
188
+ result: { type: 'string', enum: ['pass', 'fail', 'unverified'], description: '该项结果。' },
189
+ evidence: { type: 'string', description: '支持该结果的证据(文件、命令输出、测试结果)。' },
190
+ },
191
+ required: ['criterion', 'result'],
192
+ additionalProperties: false,
193
+ },
194
+ },
195
+ artifacts: {
196
+ type: 'array',
197
+ description: '声明产物;kind=file/url/note,exists=false 表示产物缺失。',
198
+ items: {
199
+ type: 'object',
200
+ properties: {
201
+ kind: { type: 'string', enum: ['file', 'url', 'note'] },
202
+ ref: { type: 'string' },
203
+ exists: { type: 'boolean' },
204
+ },
205
+ required: ['kind', 'ref'],
206
+ additionalProperties: false,
207
+ },
208
+ },
209
+ missingArtifacts: {
210
+ type: 'array',
211
+ items: { type: 'string' },
212
+ description: '已知缺失的产物路径;非空时计划不可交付。',
109
213
  },
110
214
  expectedRevision: {
111
215
  type: 'integer',
@@ -148,7 +252,14 @@ function createCancelTool(runtime) {
148
252
  return {
149
253
  name: 'dsh_workplan_cancel',
150
254
  description: '取消当前会话尚未派发/正在等待派发的任务分解计划。仅取消计划记录,不伪造任何完成;'
151
- + '取消后计划在面板中显示为“已取消”,不会启动任何部门 Agent。',
255
+ + '取消后计划在面板中显示为“已取消”,不会启动任何部门 Agent。'
256
+ + '注意:取消不等于完成。取消后如仍有未完成项或证据缺口,present 仍会被拒绝,'
257
+ + '答复必须按「未完成:剩余 N 项与原因」说明。'
258
+ + 'disposition="superseded" 是另一种处置:把交付责任转移给一个可验证的承接计划。'
259
+ + '运行时逐条复算(V1–V8):源计划必须已取消且未全 done、承接计划必须定义更晚且非终态、'
260
+ + '映射必须覆盖源计划全部子任务、每个映射目标必须有 done+structured 证据与全通过的验收、'
261
+ + '且本会话存在同时含两个 planId 的用户确认消息。任一不满足即拒绝并返回 SUPERSEDE_* 码,'
262
+ + '状态不变;被取代不等于完成。',
152
263
  parameters: {
153
264
  type: 'object',
154
265
  properties: {
@@ -158,7 +269,39 @@ function createCancelTool(runtime) {
158
269
  },
159
270
  reason: {
160
271
  type: 'string',
161
- description: '取消原因,会写入会话记录。',
272
+ description: '取消/取代原因,会写入会话记录。',
273
+ },
274
+ disposition: {
275
+ type: 'string',
276
+ enum: ['cancelled', 'superseded'],
277
+ description: '处置方式:cancelled=用户撤销(默认);superseded=责任已转移给承接计划。',
278
+ },
279
+ supersededBy: {
280
+ type: 'object',
281
+ description: 'disposition=superseded 时必填:承接计划与逐项覆盖映射。'
282
+ + '只给映射意图,requiredCount/coveredCount/coverage/digest 由运行时复算,不接受自报。',
283
+ properties: {
284
+ planId: {
285
+ type: 'string',
286
+ description: '承接计划的 planId(必须定义得过且未终止)。',
287
+ },
288
+ mapping: {
289
+ type: 'array',
290
+ description: '源计划每个定义子任务一条映射;from 必须恰好覆盖全部源项(各一次)。',
291
+ items: {
292
+ type: 'object',
293
+ properties: {
294
+ from: { type: 'string', description: '源计划子任务 ID。' },
295
+ to: { type: 'string', description: '承接计划子任务 ID。' },
296
+ basis: { type: 'string', description: '覆盖依据(为什么这两项是同一责任)。' },
297
+ },
298
+ required: ['from', 'to', 'basis'],
299
+ additionalProperties: false,
300
+ },
301
+ },
302
+ },
303
+ required: ['planId', 'mapping'],
304
+ additionalProperties: false,
162
305
  },
163
306
  },
164
307
  additionalProperties: false,
@@ -167,9 +310,24 @@ function createCancelTool(runtime) {
167
310
  schema: cancelToolOutputSchema(),
168
311
  render(_args, value) {
169
312
  const result = isRecord(value) ? value : {};
170
- return textContent(result.ok
171
- ? `已取消计划 ${String(result.planId ?? '')}:${String(result.reason ?? '用户取消')}`
172
- : `取消失败:${String(result.error ?? '未知错误')}`);
313
+ if (!result.ok) {
314
+ return textContent(`处置失败${result.code ? `(${String(result.code)})` : ''}:`
315
+ + `${String(result.error ?? '未知错误')}`);
316
+ }
317
+ const stats = isRecord(result.stats) ? result.stats : {};
318
+ if (result.phase === 'superseded') {
319
+ const by = isRecord(result.supersededBy) ? result.supersededBy : {};
320
+ return textContent(`计划 ${String(result.planId ?? '')} 已被取代:承接计划 ${String(by.planId ?? '')}`
321
+ + `(映射 ${Number(by.coveredCount ?? 0)}/${Number(by.requiredCount ?? 0)},digest 已复算)`
322
+ + `|源计划仍是 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)}:被取代不等于完成,`
323
+ + '不得 present 源计划,只能使用承接计划通过交付就绪检查的产物。');
324
+ }
325
+ const cancelledIncomplete = result.phase !== 'done';
326
+ return textContent(`已取消计划 ${String(result.planId ?? '')}:${String(result.reason ?? '用户取消')}`
327
+ + `(完成 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)})`
328
+ + (cancelledIncomplete
329
+ ? '|计划仍未完成:不要 present,不要写“已完成”;答复按「未完成:剩余 N 项与原因」开头。'
330
+ : '|计划此前已全部 done。'));
173
331
  },
174
332
  },
175
333
  async execute(args, exec) {
@@ -180,6 +338,58 @@ function createCancelTool(runtime) {
180
338
  },
181
339
  };
182
340
  }
341
+ function createFollowupTool(runtime) {
342
+ return {
343
+ name: 'dsh_workplan_followup',
344
+ description: '把一条说明投递给本会话的某个**直接子会话**,让它继续跑一个正常回合。'
345
+ + '用途仅限:子任务被预算/超时中止、但产物已在盘上,且用户明确同意补发 follow-up 时,'
346
+ + '让子会话自己收尾,从而让它自己的 turn/end 变成 completed。'
347
+ + '它不写计划状态、不触发交付、也不改变界面判定;投递本身不等于完成。'
348
+ + '不是直接子会话(父会话 catalog 未登记)一律拒绝。',
349
+ parameters: {
350
+ type: 'object',
351
+ properties: {
352
+ sessionId: {
353
+ type: 'string',
354
+ description: '直接子会话 ID(父会话 subagent/catalog 中登记的那一个)。',
355
+ },
356
+ message: {
357
+ type: 'string',
358
+ description: '发给子会话的说明:确认已有产物、只补缺口、不要整步重跑;不要要求它伪造完成。',
359
+ },
360
+ },
361
+ required: ['sessionId', 'message'],
362
+ additionalProperties: false,
363
+ },
364
+ output: {
365
+ schema: {
366
+ type: 'object',
367
+ properties: {
368
+ ok: { type: 'boolean' },
369
+ sessionId: { type: 'string' },
370
+ messageId: { type: 'string' },
371
+ code: { type: 'string' },
372
+ error: { type: 'string' },
373
+ },
374
+ required: ['ok'],
375
+ additionalProperties: true,
376
+ },
377
+ render(_args, value) {
378
+ const result = isRecord(value) ? value : {};
379
+ if (!result.ok) {
380
+ return textContent(`follow-up 未投递:${String(result.error ?? result.code ?? '未知错误')}`);
381
+ }
382
+ return textContent(`已向子会话 ${String(result.sessionId ?? '')} 投递 follow-up`
383
+ + (result.messageId ? `(messageId ${String(result.messageId)})` : '')
384
+ + '。投递只代表消息被接收;界面状态要等该子会话自己的回合正常结束才会变化。');
385
+ },
386
+ },
387
+ async execute(args, exec) {
388
+ const parsed = asObject(args) ?? {};
389
+ return runtime.followupTool(exec.agent, parsed, exec.signal);
390
+ },
391
+ };
392
+ }
183
393
  function createStatusTool(runtime) {
184
394
  return {
185
395
  name: 'dsh_workplan_status',
@@ -200,15 +410,35 @@ function createStatusTool(runtime) {
200
410
  render(_args, value) {
201
411
  const result = isRecord(value) ? value : {};
202
412
  const stats = isRecord(result.stats) ? result.stats : {};
203
- if (!result.ok)
204
- return textContent(`查询失败:${String(result.error ?? '未知错误')}`);
413
+ const runtimeInfo = isRecord(result.runtime) ? result.runtime : {};
414
+ /*
415
+ * [1.8.14] Every answer names the loaded build, including the failure
416
+ * path. The restart verification in the incident report (§14.6 step 2)
417
+ * called `status` before any plan existed and got bare `NO_PLAN`, so it
418
+ * could not confirm which build was answering.
419
+ */
420
+ const startedAt = Number(runtimeInfo.startedAt) || 0;
421
+ const identity = [
422
+ typeof result.version === 'string' ? `v${result.version}` : '',
423
+ typeof runtimeInfo.buildHash === 'string' ? `build ${runtimeInfo.buildHash}` : '',
424
+ Number(runtimeInfo.pid) > 0 ? `pid ${Number(runtimeInfo.pid)}` : '',
425
+ startedAt > 0
426
+ ? `启动 ${new Date(startedAt).toLocaleString('zh-CN', { hour12: false })}`
427
+ : '',
428
+ ].filter(Boolean).join('|');
429
+ if (!result.ok) {
430
+ return textContent(`查询失败:${String(result.error ?? '未知错误')}`
431
+ + (identity ? `(${identity})` : ''));
432
+ }
205
433
  const running = result.running === true;
206
434
  return textContent(`计划 ${String(result.planId ?? '')}|${running ? '执行中' : '未在执行'}`
207
435
  + `|阶段:${phaseLabel(result.phase)}`
208
436
  + `|完成 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)},受阻 ${Number(stats.blocked ?? 0)}`
437
+ + `|${result.deliveryReady === true ? '可交付' : '未就绪'}`
209
438
  + (running && Number(result.elapsedMs ?? 0) > 0
210
439
  ? `|已 ${Math.round(Number(result.elapsedMs) / 1000)}s`
211
- : ''));
440
+ : '')
441
+ + (identity ? `|${identity}` : ''));
212
442
  },
213
443
  },
214
444
  async execute(args, exec) {
@@ -220,8 +450,10 @@ function createStatusTool(runtime) {
220
450
  function createDispatchTool(runtime) {
221
451
  return {
222
452
  name: 'dsh_workplan_dispatch',
223
- description: '派发当前会话尚未执行的任务分解计划。计划显示后必须先调用本工具;它会等待各部门 Agent 完成,'
224
- + '把 durable 结果写入会话并返回每个子任务的状态/摘要。重复调用是幂等的。',
453
+ description: '派发当前会话尚未执行的任务分解计划。计划显示后必须先调用本工具;wait 会等到本轮结束,'
454
+ + '把 durable 结果写入会话并返回每个子任务的状态/摘要。'
455
+ + '返回值里的 complete=false 表示计划还没做完(可能只是本轮预算用尽),此时必须再次派发续跑,'
456
+ + '不得把当前产物当作最终结果。重复调用是幂等的。',
225
457
  parameters: {
226
458
  type: 'object',
227
459
  properties: {
@@ -243,17 +475,53 @@ function createDispatchTool(runtime) {
243
475
  render(_args, value) {
244
476
  const result = isRecord(value) ? value : {};
245
477
  const stats = isRecord(result.stats) ? result.stats : {};
246
- return textContent(result.ok
247
- ? `计划 ${String(result.planId ?? '')} 当前阶段:${phaseLabel(result.phase)}`
248
- + `(完成 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)},受阻 ${Number(stats.blocked ?? 0)})`
249
- + (result.alreadyRunning || result.mode === 'async'
250
- ? `|已在执行(${Math.round(elapsedSeconds(result) / 1000)}s)`
251
- : '')
252
- + (result.joined ? '|已加入进行中的派发并等到结果' : '')
478
+ const done = Number(stats.done ?? 0);
479
+ const total = Number(stats.total ?? 0);
480
+ const blocked = Number(stats.blocked ?? 0);
481
+ const remaining = Math.max(0, total - done);
482
+ const name = `计划 ${String(result.planId ?? '')}`;
483
+ if (!result.ok) {
253
484
  // The hint carries the recovery instruction (resume, or take the work
254
485
  // over directly); showing it in the rendered line keeps it visible
255
486
  // even when only the summary is read.
256
- : `派发失败:${String(result.error ?? '未知错误')}${result.hint ? `|下一步:${String(result.hint)}` : ''}`);
487
+ return textContent(`派发失败:${String(result.error ?? '未知错误')}${result.hint ? `|下一步:${String(result.hint)}` : ''}`);
488
+ }
489
+ /*
490
+ * [1.8.7] The first word decides how the model reads the round.
491
+ *
492
+ * Incident: `ok:true` + "已加入进行中的派发并等到结果(完成 10/13)"
493
+ * read as "done", so the model presented a half-finished report. Now an
494
+ * unfinished round starts with 未完成 and states the only legal next
495
+ * move; a finished one is the only place the word 已完成 appears.
496
+ */
497
+ if (result.mode === 'async' || (result.running === true && result.joined !== true)) {
498
+ return textContent(`${name} 已开跑,尚未完成:当前完成 ${done}/${total},剩余 ${remaining} 项由本轮执行`
499
+ + `(${Math.round(elapsedSeconds(result) / 1000)}s)`
500
+ + '|不要重复派发;结果消息会在本轮结束时自动写入。在结果消息到达并确认 complete=true 之前,不要给最终答复。');
501
+ }
502
+ /*
503
+ * [1.8.13] All rows done is not the finish line.
504
+ *
505
+ * T5-B/D: every row said done, no structured evidence, and this branch
506
+ * printed 已完成 — the model then presented. Only deliveryReady=true
507
+ * reaches the completion sentence; every other state names the gaps and
508
+ * the legal next move (dispatch, fix evidence, or report unfinished).
509
+ */
510
+ if (result.deliveryReady === true) {
511
+ return textContent(`${name} 已完成且可交付:完成 ${done}/${total},证据通过`
512
+ + (result.joined ? '|已加入进行中的派发并等到结果' : ''));
513
+ }
514
+ const blockers = Array.isArray(result.deliveryBlockers) ? result.deliveryBlockers.slice(0, 6).join(';') : '';
515
+ const cancelled = result.phase === 'cancelled';
516
+ const next = cancelled
517
+ ? '计划已取消且未完成:不要再次 dispatch,不要 present;答复按「未完成:剩余 N 项与原因」开头。'
518
+ : remaining > 0
519
+ ? '下一步:再次调用 dsh_workplan_dispatch 续跑剩余项;全部 done 之前不要 present。'
520
+ : "全部子任务虽已 done,但证据未通过:用 dsh_workplan_update 补 verification='structured' 与 acceptance(每项 result='pass'),或把对应项改回 blocked;不要 present。";
521
+ return textContent(`${name} 未就绪:完成 ${done}/${total},剩余 ${remaining} 项,受阻 ${blocked}(${phaseLabel(result.phase)})`
522
+ + (blockers ? `|证据缺口:${blockers}` : '')
523
+ + (result.joined ? '|本轮已返回,但计划没有达到可交付状态' : '')
524
+ + `|${next}|不要写“已完成/最终版/已交付”,不要给收尾性最终答复。`);
257
525
  },
258
526
  },
259
527
  /*
@@ -287,8 +555,37 @@ function numericSetting(configValue, envName) {
287
555
  const numeric = Number(raw);
288
556
  return Number.isFinite(numeric) && numeric > 0 ? numeric : undefined;
289
557
  }
558
+ /**
559
+ * Hard, tool-level guards. Kept as a pure function so the contracts can be
560
+ * pinned without mounting the whole plugin:
561
+ * - plan mode:只拦住 dispatch,其他工具保持可用(避免死锁);
562
+ * - `present`:计划未完成时由 runtime 拒绝(事故中模型在收尾闸门之前
563
+ * present,卡片一旦出现就无法撤回)。
564
+ */
565
+ export function toolGuardReason(exec, runtime) {
566
+ if (exec?.name === 'dsh_workplan_dispatch') {
567
+ const session = exec?.agent?.session;
568
+ if (session && runtime.planModeActive(session)) {
569
+ return '当前是 plan 模式:计划已生成,请先让用户审阅/退出 plan 模式,再调用 dsh_workplan_dispatch。';
570
+ }
571
+ return undefined;
572
+ }
573
+ if (exec?.name === 'present')
574
+ return runtime.presentDenialReason(exec?.agent);
575
+ return undefined;
576
+ }
290
577
  export function apply(ctx, config = {}) {
291
578
  const runtime = createWorkplanRuntime(ctx, {
579
+ // [1.8.13] The answering version must be visible in status/dispatch output,
580
+ // not inferred from the PID.
581
+ version: meta.version,
582
+ // [1.8.14] ...and so must the exact loaded build (see LOADED_BUILD above).
583
+ build: {
584
+ pid: process.pid,
585
+ startedAt: PROCESS_STARTED_AT,
586
+ entryPath: LOADED_BUILD.entryPath,
587
+ buildHash: LOADED_BUILD.buildHash,
588
+ },
292
589
  cwd: typeof config.cwd === 'string' ? config.cwd : undefined,
293
590
  childTimeoutMs: numericSetting(config.childTimeoutMs, 'DSH_WORKPLAN_CHILD_TIMEOUT_MS'),
294
591
  idleTimeoutMs: numericSetting(config.idleTimeoutMs, 'DSH_WORKPLAN_IDLE_TIMEOUT_MS'),
@@ -303,22 +600,27 @@ export function apply(ctx, config = {}) {
303
600
  ctx.effect(() => ctx.tools.register(createUpdateTool(runtime)));
304
601
  ctx.effect(() => ctx.tools.register(createCancelTool(runtime)));
305
602
  ctx.effect(() => ctx.tools.register(createStatusTool(runtime)));
603
+ ctx.effect(() => ctx.tools.register(createFollowupTool(runtime)));
306
604
  ctx.effect(() => ctx.tools.register(createDispatchTool(runtime)));
307
605
  /*
308
606
  * Plan mode produces a plan for review, not department execution. Denying
309
607
  * only the dispatch tool keeps every other tool available (no deadlock)
310
608
  * and gives the model a precise reason instead of a silent no-op.
609
+ *
610
+ * [1.8.8] `present` 也在执行前拦截:事故里模型在回合中途就把未完成
611
+ * 的产物 present 出去,回合收尾闸门再拦已经撤不回卡片。计划未完成时
612
+ * 拒绝交付,模型必须先续跑或显式取消计划。
311
613
  */
312
- ctx.effect(() => ctx.tools.guard((exec) => {
313
- if (exec?.name !== 'dsh_workplan_dispatch')
314
- return undefined;
315
- const session = exec?.agent?.session;
316
- if (session && runtime.planModeActive(session)) {
317
- return '当前是 plan 模式:计划已生成,请先让用户审阅/退出 plan 模式,再调用 dsh_workplan_dispatch。';
318
- }
319
- return undefined;
320
- }));
614
+ ctx.effect(() => ctx.tools.guard((exec) => toolGuardReason(exec, runtime)));
321
615
  ctx.effect(() => ctx.on('agent/pre-step', runtime.onPreStep));
616
+ /*
617
+ * [1.8.7] 回合收尾前的闸门。官方 `agent/turn-stopping` 是 serial 事件、
618
+ * 在边界提交前被 await;监听器 `agent.steer()` 后机器会重读 inbox,于是
619
+ * 「计划没做完」时回合不会被关闭。这是「未完成即输出」的唯一强制点:
620
+ * 提示词和工具文案只能说服模型,这个事件能拦住收尾本身。
621
+ */
622
+ ctx.effect(() => ctx.on('agent/turn-stopping', runtime.onTurnStopping));
623
+ ctx.effect(() => ctx.tools.guard((exec) => fileWriteGuardReason(exec, runtime)));
322
624
  ctx.inject(['webServer', 'connection'], (scope) => {
323
625
  scope.effect(() => scope.webServer.register({
324
626
  kind: 'exact',
@@ -371,8 +673,20 @@ export function apply(ctx, config = {}) {
371
673
  }
372
674
  export const meta = {
373
675
  name,
374
- version: '1.8.4',
676
+ version: '1.9.1',
375
677
  promptOrder: PROMPT_ORDER,
376
678
  routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
377
679
  };
378
680
  export { PROMPT_SECTION, createCancelTool, createDispatchTool, createStatusTool, createUpdateTool, plannerOutputSchema };
681
+ /**
682
+ * [1.8.18] 写工具的路径级闸门(T7-N2),与 `toolGuardReason` 分开注册。
683
+ *
684
+ * present/dispatch 的语义是「计划未就绪不能交付」;这里管的是「已交付的
685
+ * 文件不能在计划未就绪时被原地改写」。两条守卫都返回拒绝原因,harness
686
+ * 取第一个非空原因,互不覆盖。
687
+ */
688
+ export function fileWriteGuardReason(exec, runtime) {
689
+ if (exec?.name !== 'write' && exec?.name !== 'edit' && exec?.name !== 'str_replace_editor')
690
+ return undefined;
691
+ return runtime.presentedWriteDenialReason(exec?.agent, exec?.arguments);
692
+ }