dsh-workplan 1.12.1 → 1.12.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,65 @@
1
+ ## 1.12.3 — 2026-11-04
2
+
3
+ **修好 MS2 20 条真实实跑暴露的四处缺陷:指代误拦(T05-08)、该问不问(T05-04/09/13/20)、未确认自行派发、法务召回缺失(T05-12)。默认行为变化:信息不足时不再生成计划、不再派发,改为向用户提问。**
4
+
5
+ ### 一、四处缺陷的修法
6
+
7
+ | 编号 | 缺陷(MS2 实测) | 1.12.3 的修法 | 代码位置 |
8
+ |---|---|---|---|
9
+ | **① 指代误拦** | T05-08「它每天具体走势」——「它」的先行词就在同一句的上半句,却被判成「找不到先行词」直接拦下 | 先在**任务原文**的同一句、再在上一句里找「实体型」先行词(引号跨度,或含数字/字母的中文实体片段);只有两处都找不到才拦 | `src/understanding.ts` `resolvePronounAntecedentInline` |
10
+ | **② 该问不问** | T05-04/09/13/20 四条本该澄清,却照做计划并派发 | 四条可判定规则:C1 裸表态、C2 悬空内部编号、C3 预测类无标的、C4 界面改动无对象;命中时**在规划之前**拦下,并给出一句可以原样问用户的话 | `src/understanding.ts` `auditClarifyNeed`;`src/plan.ts` `buildClarifyMessage`;`src/runtime.ts` 规划前闸门 |
11
+ | **③ 未确认自行派发** | 20 条里累计 46 次未经用户确认就启动部门 Agent | 按用户 2026-11-04 的决定:**自动派发语义不变**,只在「信息不足」这一类上拦截——缺信息时连计划都不生成,自然走不到派发 | `src/runtime.ts` `clarifyGateDisabled` / `maybePlan` |
12
+ | **④ 法务召回** | T05-12「会不会窃取用户文件和数据」判成无部门覆盖 | legal 词表增加 窃取 / 信息泄露 / 个人信息 / 数据安全 / 隐私风险 / 移动终端(刻意不用「泄露」:内存泄露属于工程问题) | `src/departments.ts` |
13
+
14
+ ### 二、每一条结论的证据(可复核)
15
+
16
+ - **离线回放(不调用模型)**:20 条真实原文 → clarify **4/4 命中**,16 条正常任务**误拦 0 条**;T05-12 legal 命中 2 词(窃取、移动终端);「修复内存泄露导致的崩溃」legal 命中 0 词;「参考国际标准做一下排版」仍为 1 词(低于 ≥2 门槛,不会把排版任务拉进法务)。
17
+ - **端到端(headless 真跑)**:用 T05-13 原文启动 headless → 事件流里 **0 个计划、0 次 `dsh_workplan_*` 工具调用**,模型改为向用户提问(证据见 `_t_clarify_20261104/`)。
18
+ - **自动化测试**:`npm test` **523 条全过、0 失败**(含新增 `tests/clarify-gate.test.ts`、`tests/antecedent-inline.test.ts`);`npm run check`(`tsc --noEmit`)退出码 0。
19
+ - **修正了一条旧断言**:legal 词表从 16 词增到 22 词,`tests/department-coverage.test.ts` 的数量断言同步更新并写明原因;C4 曾把「把红圈处改为默认收起」误判成「没说要改哪里」,用 `department-fit.test.ts` 抓出来后才补上「红圈/红框/圈出」三种说法。
20
+
21
+ ### 三、开关与行为影响
22
+
23
+ - 新增 `DSH_WORKPLAN_CLARIFY_GATE=0`:关闭澄清闸门,回到旧行为(信息不足也照做计划、照派发)。默认开启。
24
+ - `DSH_WORKPLAN_AUTO_DISPATCH` 语义**未变**:默认自动派发照旧,只是信息不足的任务不会再走到派发这一步。
25
+ - C3/C4 允许「缺的对象在最近对话里」:上一轮说过「截图红圈处的分步进度」,本轮「把它改成默认收起」就不算缺信息(否则会把正常追问也拦掉)。
26
+
27
+ ### 四、本版没有覆盖的(如实登记,不计入修复证据)
28
+
29
+ - 同一工作区里还有一个 headless「未完成不得成功收尾」闸门(`failClosedOnIncomplete` / `WORKPLAN_INCOMPLETE`),目前**只有实现、没有自动化用例**;发布前必须补测,本版不宣称它已验证。
30
+
31
+ ## 1.12.2 — 2026-11-04
32
+
33
+ **修好 G1/G2/G3 三个写保护漏洞(1.12.1 只记录了缺口)。这是一次有意的行为变更:已交付文件的写保护现在真正无死角,且不再区分「谁在写」。**
34
+
35
+ ### 一、修了什么(三个漏洞,逐条)
36
+
37
+ | 编号 | 1.12.1 的状态 | 1.12.2 的修法 | 代码位置 |
38
+ |---|---|---|---|
39
+ | **G1** 子 Agent 不受保护 | 非根会话直接放行:「门卫只认户主,保姆拿钥匙能进」 | 去掉角色判断。已交付文件在计划未就绪期间不得被原地改写,**与谁在写无关**。 | `src/runtime.ts` `presentedWriteDenialReason` |
40
+ | **G2** 只认三个工具名 | 只接管 write / edit / str_replace_editor,第四个写工具(如 `apply_patch`)根本不进闸门 | 改为**按参数形状识别**写操作:带 `file_path`/`path`,或 patch 文本含 `*** Update/Add/Delete File:`。一次调用含多个文件时,只要有任一命中就整单拒绝。读类工具显式白名单排除。 | `src/host.ts` `fileWriteGuardReason` / `isWriteShapedCall`;`src/runtime.ts` `writeTargets` |
41
+ | **G3** 符号链接绕过 | 只做 `path.resolve`,`/link/report.md` 与 `/real/report.md` 被当成两个文件 | 两侧都归一到**真实文件身份**(`realpath.native`)。交付链接、写真实路径(或反之)都能认出来。文件尚不存在时解析最近的存在祖先;完全解析不了时退回旧行为。 | `src/runtime.ts` `realPathIdentity` / `identityPath` |
42
+
43
+ ### 二、行为影响(会影响现有使用的部分,务必读完)
44
+
45
+ 1. **子 Agent 写已交付文件会被拒绝**(G1)。以前后台子 Agent 能改掉用户手上那份报告,现在与主 Agent 同等对待。**present 仍只有主会话可用**,所以「交付能力」没有扩大,只是「改写已交付文件」的口子被堵上。
46
+ 2. **更多工具名进入写保护**(G2)。过去改一个名字(如 `apply_patch`、`write_file`)就能绕过的写法,现在同样被拦;一次 patch 改动多个文件时,只要有一个是已交付文件就整单拒绝。
47
+ 3. **符号链接不再是第二种写法**(G3)。通过软链接路径改写已交付文件会被拦下,报错文案与直接路径完全一致。
48
+ 4. **照旧保留的出路**:计划交付就绪后放行;计划被 `dsh_workplan_cancel` 显式取消后放行;present 之后才新建的计划不受限制;plan 模式下写保护不生效。
49
+ 5. **没有削弱的权限**:其余 8 处 `NOT_ROOT` 校验(子 Agent 不能 update / replan / cancel / dispatch 主计划、不能下发指示、不能处置跨部门需求、不能补发 follow-up、不能 present)**一处未动**。那是「子 Agent 不能改计划」的权限,与「不能改文件」是两件事。
50
+
51
+ ### 三、验证(双向红绿,不是只跑一次绿)
52
+
53
+ - **修复前**(换回 1.12.1 的 `src/runtime.ts` + `src/host.ts`):`tests 498 / pass 491 / fail 7`,失败项正是 6 条 G1/G2/G3 新用例 + 1 条既有契约用例。
54
+ - **修复后**:`tests 498 / pass 498 / fail 0`,退出码 0;`npm run check`(tsc --noEmit)退出码 0。
55
+ - 用例数构成:基线 495 + G1 一条 + G2 一条 + G3 反向一条 = 498。
56
+ - 三条原本「钉住缺口」的用例已翻转成「钉住修复」:`p03-m1-write-guard-gaps.test.ts` 的 G3 条、`p03-m1-guard-gating-gaps.test.ts` 的 G1/G2 条、以及既有契约 `workplan-presented-write-guard.test.ts` 中「非根会话放行」的断言。
57
+
58
+ ### 四、事实边界(不得外推)
59
+
60
+ - 真实模型在 20 条任务上的通过率**未被本版刷新**,仍为 2026-11-03 的 `pass 4/20`。原因:模型密钥 4 个环境变量全空 + 工作区外写配置权限缺失,20 条真实模型验证无法在本轮重跑。
61
+ - 1.12.2 是**代码级修复 + 回归验证**的结论,不代表 20 条真实模型任务的表现有任何变化。
62
+
1
63
  ## 1.12.1 — 2026-11-04
2
64
 
3
65
  **补强任务理解的三处漏判:部门覆盖硬校验、指代先行词核实、写保护缺口固化测试。**
package/README.en.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > **Two selling points, one line: a full ISO/IEC 15408:2026 evidence pack you can verify with 5 commands, and a one-command install with zero runtime dependencies.**
4
4
 
5
5
  [![verify](https://github.com/abbaababa/dsh-workplan/actions/workflows/verify.yml/badge.svg)](https://github.com/abbaababa/dsh-workplan/actions/workflows/verify.yml)
6
- [![version](https://img.shields.io/badge/version-1.12.1-blue.svg)](https://github.com/abbaababa/dsh-workplan/releases/tag/v1.12.1)
6
+ [![version](https://img.shields.io/badge/version-1.12.3-blue.svg)](https://github.com/abbaababa/dsh-workplan/releases/tag/v1.12.3)
7
7
 
8
8
  Adds "plan first → dispatch real department subagents → watch progress in the sidebar" to **DeepSeek Harness (DSH)**. No app, no DSH source patch, no page replacement.
9
9
 
@@ -80,7 +80,7 @@ The full contract — roles, data shapes, state machine, recovery, and the three
80
80
  ## Install
81
81
 
82
82
  ```bash
83
- dsh plugin --profile web add dsh-workplan@1.12.1
83
+ dsh plugin --profile web add dsh-workplan@1.12.3
84
84
  ```
85
85
 
86
86
  Restart the DSH Web process (or reload the page) so the bundle is picked up.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > **两个卖点,一句话:ISO/IEC 15408:2026 全套安全证据,5 条命令自己验;安装一条命令、零第三方运行时依赖。**
4
4
 
5
5
  [![verify](https://github.com/abbaababa/dsh-workplan/actions/workflows/verify.yml/badge.svg)](https://github.com/abbaababa/dsh-workplan/actions/workflows/verify.yml)
6
- [![version](https://img.shields.io/badge/version-1.12.1-blue.svg)](https://github.com/abbaababa/dsh-workplan/releases/tag/v1.12.1)
6
+ [![version](https://img.shields.io/badge/version-1.12.3-blue.svg)](https://github.com/abbaababa/dsh-workplan/releases/tag/v1.12.3)
7
7
 
8
8
  给 **DeepSeek Harness(DSH)** 加一段「先拆计划 → 真派部门子 Agent 去做 → 左侧栏实时看进度」的能力。不装 App、不改 DSH 源码、不换页面。
9
9
 
@@ -69,7 +69,7 @@ grep -RInE "child_process|execSync|eval\(|writeFileSync" src || echo "0 命中
69
69
  ## 一键安装
70
70
 
71
71
  ```bash
72
- dsh plugin --profile web add dsh-workplan@1.12.1
72
+ dsh plugin --profile web add dsh-workplan@1.12.3
73
73
  ```
74
74
 
75
75
  装完**重启一次 DSH Web**(或重新载入当前页面)让插件生效。
package/README.zh.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > **两个卖点,一句话:ISO/IEC 15408:2026 全套安全证据,5 条命令自己验;安装一条命令、零第三方运行时依赖。**
4
4
 
5
5
  [![verify](https://github.com/abbaababa/dsh-workplan/actions/workflows/verify.yml/badge.svg)](https://github.com/abbaababa/dsh-workplan/actions/workflows/verify.yml)
6
- [![version](https://img.shields.io/badge/version-1.12.1-blue.svg)](https://github.com/abbaababa/dsh-workplan/releases/tag/v1.12.1)
6
+ [![version](https://img.shields.io/badge/version-1.12.3-blue.svg)](https://github.com/abbaababa/dsh-workplan/releases/tag/v1.12.3)
7
7
 
8
8
  给 **DeepSeek Harness(DSH)** 加一段「先拆计划 → 真派部门子 Agent 去做 → 左侧栏实时看进度」的能力。不装 App、不改 DSH 源码、不换页面。
9
9
 
@@ -69,7 +69,7 @@ grep -RInE "child_process|execSync|eval\(|writeFileSync" src || echo "0 命中
69
69
  ## 一键安装
70
70
 
71
71
  ```bash
72
- dsh plugin --profile web add dsh-workplan@1.12.1
72
+ dsh plugin --profile web add dsh-workplan@1.12.3
73
73
  ```
74
74
 
75
75
  装完**重启一次 DSH Web**(或重新载入当前页面)让插件生效。
@@ -0,0 +1,41 @@
1
+ # 决策:澄清闸门与自动派发的边界(2026-11-04)
2
+
3
+ ## 1. 用户拍板
4
+
5
+ > 「此外,DSH_WORKPLAN_AUTO_DISPATCH 改为在"信息不足"类上拦截,其它全部按你推荐的去做」
6
+ > —— 2026-11-04 20:53,用户原文
7
+
8
+ 含义(按原文,不引申):
9
+
10
+ 1. **自动派发本身不改**:计划生成后照旧自动开跑,不要求用户每次点确认。
11
+ 2. **只有一类要拦**:任务信息不足(缺关键输入、缺指代、缺标的、缺界面对象)时,不要拆计划、不要派发,改为向用户提问。
12
+ 3. 其余三项(①指代放宽 ②澄清提问 ④法务召回)按主 Agent 的建议执行。
13
+
14
+ ## 2. 为什么拦在「规划之前」而不是「派发之前」
15
+
16
+ MS2 的 20 条是整会话任务:被测 agent 收到原文后会自己决定「先派发计划」。
17
+ 如果拦在派发这一步,计划已经生成、计划列表里已经出现一个基于猜测的 planId,
18
+ 用户看到的仍是「已经开工,只是没开跑」。拦在规划之前则连计划都不产生——
19
+ 没有 planId,也就没有可被误派发的对象。
20
+
21
+ ## 3. 判定规则(可复算,不靠感觉)
22
+
23
+ | 规则 | 触发条件 | 对应的 MS2 用例 |
24
+ |---|---|---|
25
+ | C1 裸表态 | 句首是「同意/赞成/按你说的…」,且带一个任务里没定义的编号或整句 ≤24 字 | T05-04「…同意移入」 |
26
+ | C2 悬空内部编号 | 出现 `R-W5-01`/`W5`/`T4 草稿` 这类编号,且任务与最近对话里都没定义 | T05-09「按 T4 草稿开始续做」 |
27
+ | C3 预测类无标的 | 出现 预测/预判/走势/涨跌/行情,且原文与上下文都没有 6 位代码、字母+数字、引号名称 | T05-20「准确预测11月全月详细、具体走势」 |
28
+ | C4 界面改动无对象 | 出现 折叠/展开/按钮/显示/布局…,且原文与上下文都没有 左侧栏/面板/截图/红圈… | T05-13「显示内容希望可折叠」 |
29
+
30
+ 「上下文也算」是刻意的:上一轮说过「截图红圈处的分步进度」,本轮「把它改成默认收起」
31
+ 是正常追问,不该被拦(`tests/plan-anchor.test.ts` 的 strict 用例钉住了这一点)。
32
+
33
+ ## 4. 证据
34
+
35
+ - 离线回放(20 条真实原文,不调模型):clarify 4/4 命中,16 条正常任务误拦 0 条。
36
+ - 端到端 headless(T05-13 原文):0 个计划、0 次 `dsh_workplan_*` 调用,模型向用户提问。
37
+ - 自动化:`npm test` 523/523 通过;`npm run check` 退出码 0。
38
+
39
+ ## 5. 回退方式
40
+
41
+ `DSH_WORKPLAN_CLARIFY_GATE=0` 关闭闸门,回到 1.12.2 的行为。
@@ -163,6 +163,13 @@ export const DEPARTMENT_CAPABILITIES = Object.freeze([
163
163
  keywords: [
164
164
  '法务', '合同', '版权', '许可', '合规', '条款', '法律', '隐私', '授权', '侵权', '国际标准',
165
165
  'ISO/IEC 15408', '15408', 'ISO/IEC', 'ISO 标准', 'CC 标准',
166
+ // [P0-4 recall] T05-12 「会不会窃取用户电脑和移动终端里的文件和数据」 is a
167
+ // privacy/authorisation claim and matched nothing: the list had 隐私/授权 but
168
+ // not the verbs a user actually writes. These are plain words, so the
169
+ // intrusion guard keeps legal out of unrelated plans.
170
+ // 「泄露」 alone would also fire on 「内存泄露」 (a memory leak is engineering,
171
+ // not legal); 「信息泄露」 keeps the privacy sense and the keyword count at 22.
172
+ '窃取', '信息泄露', '个人信息', '数据安全', '隐私风险', '移动终端',
166
173
  ],
167
174
  },
168
175
  {
package/lib/host.js CHANGED
@@ -965,6 +965,25 @@ function strictCompletionEnabledFrom(configValue, envValue) {
965
965
  }
966
966
  return true;
967
967
  }
968
+ /**
969
+ * [1.12.3] `failClosedOnIncomplete` 的三态解析:显式配置 > 显式环境变量 > 'auto'。
970
+ *
971
+ * 与 `strictCompletionEnabledFrom` 的区别只在默认值:这里未配置时返回 `'auto'`,
972
+ * 语义是「headless 才硬失败」,不能退化成 `false`(那等于默认关闭,事故会复发),
973
+ * 也不能退化成 `true`(那会让交互式会话在收尾时抛错)。
974
+ */
975
+ function failClosedOnIncompleteFrom(configValue, envValue) {
976
+ if (typeof configValue === 'boolean')
977
+ return configValue;
978
+ const raw = envValue === undefined || envValue === null ? '' : String(envValue).trim();
979
+ if (raw !== '') {
980
+ if (/^(1|true|yes|on)$/i.test(raw))
981
+ return true;
982
+ if (/^(0|false|no|off)$/i.test(raw))
983
+ return false;
984
+ }
985
+ return 'auto';
986
+ }
968
987
  function booleanSetting(configValue, envName) {
969
988
  if (typeof configValue === 'boolean')
970
989
  return configValue;
@@ -1042,6 +1061,11 @@ export function apply(ctx, config = {}) {
1042
1061
  * 与 autoResume / strictCompletion 同一写法,避免「没配置就等于关闭」。
1043
1062
  */
1044
1063
  autoDispatch: strictCompletionEnabledFrom(config.autoDispatch, settingEnv('DSH_WORKPLAN_AUTO_DISPATCH')),
1064
+ /*
1065
+ * [1.12.3] headless「未完成不得成功收尾」。默认 'auto':只有 headless
1066
+ * 运行上下文(提供 `headlessStartup` 服务)才硬失败,交互式会话不受影响。
1067
+ */
1068
+ failClosedOnIncomplete: failClosedOnIncompleteFrom(config.failClosedOnIncomplete, settingEnv('DSH_WORKPLAN_FAIL_CLOSED_ON_INCOMPLETE')),
1045
1069
  });
1046
1070
  ctx.effect(() => ctx.systemPrompt.section({
1047
1071
  name: 'dsh-workplan',
@@ -1146,7 +1170,7 @@ export function apply(ctx, config = {}) {
1146
1170
  }
1147
1171
  export const meta = {
1148
1172
  name,
1149
- version: '1.12.1',
1173
+ version: '1.12.3',
1150
1174
  promptOrder: PROMPT_ORDER,
1151
1175
  routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
1152
1176
  };
@@ -1159,7 +1183,50 @@ export { PROMPT_SECTION, createCancelTool, createDispatchTool, createEscalateToo
1159
1183
  * 取第一个非空原因,互不覆盖。
1160
1184
  */
1161
1185
  export function fileWriteGuardReason(exec, runtime) {
1162
- if (exec?.name !== 'write' && exec?.name !== 'edit' && exec?.name !== 'str_replace_editor')
1186
+ if (!isWriteShapedCall(exec))
1163
1187
  return undefined;
1164
- return runtime.presentedWriteDenialReason(exec?.agent, exec?.arguments);
1188
+ // The three historical write tools pass their arguments through untouched, so
1189
+ // their behaviour stays exactly as before (argument-shape matching is only an
1190
+ // EXTENSION: a tool that used to be denied is still denied the same way).
1191
+ const direct = exec?.name === 'write' || exec?.name === 'edit' || exec?.name === 'str_replace_editor';
1192
+ const reason = direct ? runtime.presentedWriteDenialReason(exec?.agent, exec?.arguments) : undefined;
1193
+ if (typeof reason === 'string')
1194
+ return reason;
1195
+ // [1.12.2] G2: a single call can touch several files (apply_patch hunks).
1196
+ // Deny the call as a whole if any of its targets is a protected deliverable.
1197
+ for (const target of runtime.writeTargets(exec?.agent, exec?.arguments) ?? []) {
1198
+ const extra = runtime.presentedWriteDenialReason(exec?.agent, { file_path: target });
1199
+ if (typeof extra === 'string')
1200
+ return extra;
1201
+ }
1202
+ return undefined;
1203
+ }
1204
+ /**
1205
+ * [1.12.2] G2: recognise write calls by their argument shape, not by a tool-name
1206
+ * allow-list. The 1.8.18 version named write/edit/str_replace_editor only, so a
1207
+ * fourth write tool such as apply_patch never reached the guard at all.
1208
+ *
1209
+ * Shape rule: a path/first positional argument PLUS a content-bearing argument
1210
+ * (content, file_text, new_str, old_string, patch, input). read/read_image/
1211
+ * present/glob/grep carry no such pair, so they stay untouched.
1212
+ */
1213
+ const READ_ONLY_TOOLS = new Set([
1214
+ 'read', 'read_image', 'glob', 'grep', 'ls', 'list', 'list_dir',
1215
+ 'present', 'todo_write', 'ask_user_question',
1216
+ ]);
1217
+ function isWriteShapedCall(exec) {
1218
+ const name = exec?.name;
1219
+ if (typeof name !== 'string' || !name)
1220
+ return false;
1221
+ const args = exec?.arguments;
1222
+ if (!args || typeof args !== 'object')
1223
+ return false;
1224
+ // Read-only tools also carry file_path/path; the guard must never touch them.
1225
+ if (READ_ONLY_TOOLS.has(name))
1226
+ return false;
1227
+ // A patch tool names its target(s) inside the patch text, not in an argument.
1228
+ if (typeof args.input === 'string' && /\*\*\* (Update|Add|Delete|Move) File/.test(args.input))
1229
+ return true;
1230
+ // Every other write form names a single target: file_path or path.
1231
+ return typeof args.file_path === 'string' || typeof args.path === 'string';
1165
1232
  }
package/lib/plan.js CHANGED
@@ -1149,6 +1149,31 @@ export function buildDegradedMessage(options) {
1149
1149
  ].join('\n');
1150
1150
  return makeUserMessage(text, { kind: 'workplan', form: 'notice', summary });
1151
1151
  }
1152
+ /**
1153
+ * [1.12.3] 信息不足时先问,不做计划也不派发。
1154
+ *
1155
+ * 2026-11-04 MS2 的真实数据:T05-04/09/13/20 这四条本来需要澄清,插件却照样拆出
1156
+ * 计划并(自动)派发,部门 Agent 于是对着一个并不存在的目标开工。用户在同一天拍板:
1157
+ * 自动派发只在「信息不足」这一类上拦截,其余一律照旧。所以这里不是关掉自动派发,
1158
+ * 而是在规划**之前**把缺的东西变成一句能给用户看的话。
1159
+ *
1160
+ * 这条消息不带计划信封:没有计划就没有 planId,也不该出现在计划列表里。
1161
+ */
1162
+ export function buildClarifyMessage(options) {
1163
+ const rule = String(options.rule ?? '');
1164
+ const reason = truncate(options.reason ?? '', 600);
1165
+ const question = String(options.question ?? '').trim();
1166
+ const summary = truncate(`【先澄清,未生成计划】${reason}`, 300);
1167
+ const text = [
1168
+ `【先澄清,未生成计划】任务信息不足:${reason}(规则 ${rule})`,
1169
+ '',
1170
+ `请把这句话原样问用户:${question || '请补充这个任务缺的关键信息。'}`,
1171
+ '',
1172
+ '本条没有生成任务分解,也没有派发任何部门 Agent——缺信息时拆出来的计划只能靠猜。',
1173
+ '等用户回答后,用户的下一条消息会重新触发计划生成;在那之前不要调用 dsh_workplan_dispatch,也不要开始执行。',
1174
+ ].join('\n');
1175
+ return makeUserMessage(text, { kind: 'workplan', form: 'notice', summary });
1176
+ }
1152
1177
  export function buildResultSummary(result) {
1153
1178
  const stats = result.stats ?? { done: 0, total: 0, blocked: 0 };
1154
1179
  const done = Number(stats.done ?? 0);
package/lib/runtime.js CHANGED
@@ -12,10 +12,10 @@
12
12
  * in this file is allowed to escape as an unhandled rejection from a listener.
13
13
  */
14
14
  import { randomUUID } from 'node:crypto';
15
- import { existsSync, statSync } from 'node:fs';
16
- import { isAbsolute, resolve } from 'node:path';
17
- import { MAX_CONCURRENT, PlanError, aggregateInvariantViolations, applyStatus, attachPlanMeta, blockCancelledDependents, buildChildPrompt, buildCancelMessage, buildDegradedMessage, buildPlanMessage, buildPlannerPrompt, buildResultMessage, buildStopSteerText, createStatuses, deliveryReadiness, derivePlanSnapshot, extractJson, flattenSubtasks, isRecord, isSocialMessage, isTerminalPhase, isStatusQuestion, isVagueContinuation, makeUserMessage, markDependentsBlocked, messageText, readySubtasks, MAX_PLAN_RESUMES, PRESENT_DENY_CODES, canResumePlan, resetBlockedStatuses, parseCancelMessage, parseResultMessage, parseWorkplanMessage, planPhase, reconcilePhase, truncate, validatePlan, applyResultStatuses, adjudicateResult, activeDenyCode, MAX_CONVERSATION_CHARS, MAX_ESCALATION_OPTIONS, MAX_INSTRUCTION_CHARS, MAX_QUESTION_CHARS, parseUpdateMessage, buildUpdateMessage, normaliseHandoffs, openHandoffs, DEPARTMENTS, DEPARTMENT_IDS, MAX_HANDOFF_RESPONSE_CHARS, } from './plan.js';
18
- import { compactUnderstandingAudit, validatePlanContext } from './understanding.js';
15
+ import { existsSync, realpathSync, statSync } from 'node:fs';
16
+ import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
17
+ import { MAX_CONCURRENT, PlanError, aggregateInvariantViolations, applyStatus, attachPlanMeta, blockCancelledDependents, buildChildPrompt, buildCancelMessage, buildClarifyMessage, buildDegradedMessage, buildPlanMessage, buildPlannerPrompt, buildResultMessage, buildStopSteerText, createStatuses, deliveryReadiness, derivePlanSnapshot, extractJson, flattenSubtasks, isRecord, isSocialMessage, isTerminalPhase, isStatusQuestion, isVagueContinuation, makeUserMessage, markDependentsBlocked, messageText, readySubtasks, MAX_PLAN_RESUMES, PRESENT_DENY_CODES, canResumePlan, resetBlockedStatuses, parseCancelMessage, parseResultMessage, parseWorkplanMessage, planPhase, reconcilePhase, truncate, validatePlan, applyResultStatuses, adjudicateResult, activeDenyCode, MAX_CONVERSATION_CHARS, MAX_ESCALATION_OPTIONS, MAX_INSTRUCTION_CHARS, MAX_QUESTION_CHARS, parseUpdateMessage, buildUpdateMessage, normaliseHandoffs, openHandoffs, DEPARTMENTS, DEPARTMENT_IDS, MAX_HANDOFF_RESPONSE_CHARS, } from './plan.js';
18
+ import { auditClarifyNeed, compactUnderstandingAudit, validatePlanContext } from './understanding.js';
19
19
  import { computeMappingDigest, verifyMappingDigest } from './supersede-digest.js';
20
20
  import { supersedePlanRecord } from './supersede.js';
21
21
  import { createProgressWatchdog, describeError } from './watchdog.js';
@@ -2713,6 +2713,20 @@ export function createWorkplanRuntime(ctx, options = {}) {
2713
2713
  * resume, cancel, the host's tool timeout) agrees on the same numbers.
2714
2714
  */
2715
2715
  const pluginVersion = typeof options.version === 'string' && options.version ? options.version : 'unknown';
2716
+ /*
2717
+ * [1.12.3] fail-closed 解析:显式值优先;'auto' 只在 headless 运行中生效。
2718
+ * `ctx.get` 在普通对象(测试)上不存在,可选链保证降级为「非 headless」。
2719
+ */
2720
+ const failClosedMode = options.failClosedOnIncomplete ?? 'auto';
2721
+ const headlessRun = (() => {
2722
+ try {
2723
+ return ctx?.get?.('headlessStartup') !== undefined;
2724
+ }
2725
+ catch {
2726
+ return false;
2727
+ }
2728
+ })();
2729
+ const failClosedActive = failClosedMode === true || (failClosedMode === 'auto' && headlessRun);
2716
2730
  /*
2717
2731
  * [1.8.14] Build identity, captured once.
2718
2732
  *
@@ -5010,8 +5024,30 @@ export function createWorkplanRuntime(ctx, options = {}) {
5010
5024
  const book = record.stopSteers && record.stopSteers.turn === turn
5011
5025
  ? record.stopSteers
5012
5026
  : { turn, count: 0 };
5013
- if (book.count >= STOP_STEER_LIMIT)
5027
+ if (book.count >= STOP_STEER_LIMIT) {
5028
+ /*
5029
+ * [1.12.3] steer 用尽后不再沉默放行。
5030
+ *
5031
+ * 旧行为(1.8.7–1.12.2):达到上限就 `return`,回合正常收尾。对交互式
5032
+ * 会话这是「避免死循环」;对 headless 却是事故复现路径——官方 runner 只
5033
+ * 看 `turn/end reason.kind==='completed'`,它会把「计划未完成但回合正常
5034
+ * 结束」打印成结果并 exit 0(session-99984ebd… 的最终现场)。
5035
+ *
5036
+ * 现在:headless(或显式开启)时抛 WORKPLAN_INCOMPLETE。turn-stopping
5037
+ * 是 serial 事件,抛错 ⇒ 该回合以 error 收尾 ⇒ runner 走 fail():
5038
+ * 不打印正文、非零退出。交互式会话维持原样(只 steer,不抛错)。
5039
+ */
5040
+ if (failClosedActive) {
5041
+ const stuck = derivePlanSnapshot(record.statuses);
5042
+ const remaining = (stuck.statuses ?? [])
5043
+ .filter((item) => item.status !== 'done')
5044
+ .map((item) => String(item.subtaskId));
5045
+ throw new PlanError(`未完成:剩余 ${remaining.length} 项(${remaining.join(', ')})与原因——计划 ${record.plan.planId} `
5046
+ + `仅完成 ${stuck.stats.done}/${stuck.stats.total},本回合已连续 ${book.count} 次被要求续跑/补证,`
5047
+ + '仍未通过交付就绪检查。headless 以非零退出码结束,不输出「已完成」结果。', 'WORKPLAN_INCOMPLETE', { planId: record.plan.planId, stats: stuck.stats, remaining });
5048
+ }
5014
5049
  return;
5050
+ }
5015
5051
  book.count += 1;
5016
5052
  record.stopSteers = book;
5017
5053
  const snapshot = derivePlanSnapshot(record.statuses);
@@ -5032,6 +5068,12 @@ export function createWorkplanRuntime(ctx, options = {}) {
5032
5068
  + `已在回合收尾前要求继续/如实收尾(第 ${book.count} 次)`);
5033
5069
  }
5034
5070
  catch (error) {
5071
+ /*
5072
+ * [1.12.3] fail-closed 的硬失败必须穿过这层日志包装:
5073
+ * 这里原本把任何异常降级成一条 warn,等于把上面的抛错又吃掉。
5074
+ */
5075
+ if (error instanceof PlanError && error.code === 'WORKPLAN_INCOMPLETE')
5076
+ throw error;
5035
5077
  ctx.logger?.warn?.(`dsh-workplan: 回合收尾检查失败:${error instanceof Error ? error.message : String(error)}`);
5036
5078
  }
5037
5079
  }
@@ -5374,6 +5416,38 @@ export function createWorkplanRuntime(ctx, options = {}) {
5374
5416
  * 集合里,所以“用户要求改版 → 新计划”不会被写保护卡死;cancel 仍是显式出路。
5375
5417
  */
5376
5418
  const presentedPaths = new Map();
5419
+ /*
5420
+ * [1.12.2] G3 修复:符号链接必须归一到同一个文件。
5421
+ * 1.8.18 的 canonicalPath 只做 path.resolve,同一个文件因此有无限种写法——
5422
+ * 交付的是 /a/report.md,改 /link/report.md(link 指向 a)就被放过。
5423
+ * 这里再用 realpath.native 把路径解析成真实身份,两侧都解析才能比对。
5424
+ * 文件尚不存在时解析最近的存在祖先后拼回剩余段落;完全解析不了时
5425
+ * 返回 undefined,调用方回落到旧的 path.resolve 结果(不改变旧行为)。
5426
+ */
5427
+ function realPathIdentity(value) {
5428
+ try {
5429
+ return realpathSync.native(value);
5430
+ }
5431
+ catch {
5432
+ // 文件可能尚未创建,继续找最近的存在祖先。
5433
+ }
5434
+ let cursor = value;
5435
+ const tail = [];
5436
+ for (let depth = 0; depth < 64; depth += 1) {
5437
+ const parent = dirname(cursor);
5438
+ if (!parent || parent === cursor)
5439
+ return undefined;
5440
+ tail.unshift(basename(cursor));
5441
+ cursor = parent;
5442
+ try {
5443
+ return join(realpathSync.native(cursor), ...tail);
5444
+ }
5445
+ catch {
5446
+ // 继续向上。
5447
+ }
5448
+ }
5449
+ return undefined;
5450
+ }
5377
5451
  function canonicalPath(session, value) {
5378
5452
  if (typeof value !== 'string' || value.trim() === '')
5379
5453
  return undefined;
@@ -5382,6 +5456,12 @@ export function createWorkplanRuntime(ctx, options = {}) {
5382
5456
  const cwd = session?.header?.cwd ?? options.cwd;
5383
5457
  return typeof cwd === 'string' && cwd ? resolve(cwd, value) : undefined;
5384
5458
  }
5459
+ function identityPath(session, value) {
5460
+ const canonical = canonicalPath(session, value);
5461
+ if (canonical === undefined)
5462
+ return undefined;
5463
+ return realPathIdentity(canonical) ?? canonical;
5464
+ }
5385
5465
  function presentedEntries(session) {
5386
5466
  if (typeof session?.eventAt !== 'function' || !(Number(session.seq) >= 0))
5387
5467
  return [];
@@ -5412,7 +5492,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
5412
5492
  for (const file of event.data?.files ?? []) {
5413
5493
  if (typeof file?.path !== 'string' || file.path.trim() === '')
5414
5494
  continue;
5415
- entries.push({ raw: file.path, canonical: canonicalPath(session, file.path), planIds });
5495
+ entries.push({ raw: file.path, canonical: identityPath(session, file.path), planIds });
5416
5496
  }
5417
5497
  }
5418
5498
  presentedPaths.set(session.id, {
@@ -5430,7 +5510,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
5430
5510
  }
5431
5511
  function presentedWriteDenialReason(agent, args) {
5432
5512
  const session = agent?.session;
5433
- if (!session || !isRootSession(session))
5513
+ if (!session)
5434
5514
  return undefined;
5435
5515
  if (isPlanModeActive(ctx, session))
5436
5516
  return undefined;
@@ -5440,8 +5520,15 @@ export function createWorkplanRuntime(ctx, options = {}) {
5440
5520
  const requested = args?.file_path ?? args?.path;
5441
5521
  if (typeof requested !== 'string' || requested.trim() === '')
5442
5522
  return undefined;
5443
- const canonical = canonicalPath(session, requested);
5523
+ // [1.12.2] G3: compare by real file identity (symlinks resolved).
5524
+ const canonical = identityPath(session, requested);
5525
+ /*
5526
+ * [1.12.2] G3: compare like-for-like. The entry now holds the real identity
5527
+ * of the presented path, so a link delivered earlier and a write through
5528
+ * the real path (or vice versa) resolve to the same string.
5529
+ */
5444
5530
  const matched = entries.filter((entry) => entry.raw === requested
5531
+ || (entry.raw !== undefined && identityPath(session, entry.raw) === canonical)
5445
5532
  || (canonical !== undefined && entry.canonical !== undefined && entry.canonical === canonical));
5446
5533
  if (matched.length === 0)
5447
5534
  return undefined;
@@ -5465,6 +5552,29 @@ export function createWorkplanRuntime(ctx, options = {}) {
5465
5552
  + '完成后重新 present 新版本;确实不做的计划用 dsh_workplan_cancel 显式取消。'
5466
5553
  + '(present 之后新建的计划不受此限制。)';
5467
5554
  }
5555
+ /**
5556
+ * [1.12.2] G2: every path a single write call can touch.
5557
+ * apply_patch carries many files in one string; parsing the directives here
5558
+ * lets the guard deny the whole call instead of letting an unrelated path
5559
+ * in the arguments form a blind spot.
5560
+ */
5561
+ function writeTargets(_agent, args) {
5562
+ const targets = [];
5563
+ const single = args?.file_path ?? args?.path;
5564
+ if (typeof single === 'string' && single.trim() !== '')
5565
+ targets.push(single);
5566
+ const patch = typeof args?.input === 'string' ? args.input : (typeof args?.patch === 'string' ? args.patch : '');
5567
+ if (patch) {
5568
+ const directive = /^\*\*\* (?:Update File|Add File|Delete File|Move to): (.+)$/gm;
5569
+ let match;
5570
+ while ((match = directive.exec(patch)) !== null) {
5571
+ const path = match[1].trim();
5572
+ if (path !== '')
5573
+ targets.push(path);
5574
+ }
5575
+ }
5576
+ return targets;
5577
+ }
5468
5578
  function plansPayload(sessionId) {
5469
5579
  /*
5470
5580
  * [1.8.15] The feed must carry build identity too.
@@ -5558,6 +5668,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
5558
5668
  presentDenialVerdict,
5559
5669
  supersededDenialVerdict,
5560
5670
  presentedWriteDenialReason,
5671
+ writeTargets,
5561
5672
  updateStatus,
5562
5673
  cancelPlan,
5563
5674
  dispatchTool,
@@ -5573,6 +5684,14 @@ export function createWorkplanRuntime(ctx, options = {}) {
5573
5684
  planModeActive: (session) => isPlanModeActive(ctx, session),
5574
5685
  };
5575
5686
  }
5687
+ /**
5688
+ * [1.12.3] 澄清闸门的退出口。默认开启;只有显式设成 0/false/off 才回到旧行为
5689
+ * (信息不足也照做计划、照派发)。
5690
+ */
5691
+ function clarifyGateDisabled() {
5692
+ const raw = String(process.env.DSH_WORKPLAN_CLARIFY_GATE ?? '').trim().toLowerCase();
5693
+ return raw === '0' || raw === 'false' || raw === 'off';
5694
+ }
5576
5695
  function resolveModelSelection(ctx, payload) {
5577
5696
  const direct = payload.modelSelection;
5578
5697
  if (direct?.provider && direct?.model) {
@@ -5721,6 +5840,39 @@ async function maybePlan(ctx, state, payload, downstream, options) {
5721
5840
  }
5722
5841
  return downstream;
5723
5842
  }
5843
+ /*
5844
+ * [1.12.3] 信息不足就不做计划、不派发——只问一句。
5845
+ *
5846
+ * 用户在 2026-11-04 拍板:自动派发改成「只在信息不足这一类上拦截」,其余照旧。
5847
+ * 因此拦截点放在规划之前,而不是关掉自动派发:缺信息时连计划都不生成,
5848
+ * 免得部门 Agent 对着一个猜出来的目标开工。
5849
+ * 关闭方式:DSH_WORKPLAN_CLARIFY_GATE=0(保留给需要旧行为的自动化)。
5850
+ */
5851
+ if (!clarifyGateDisabled()) {
5852
+ const clarify = auditClarifyNeed(taskText, conversationContext);
5853
+ if (clarify.needed) {
5854
+ const createdAt = Date.now();
5855
+ state.records.set(session.id, {
5856
+ planId: null,
5857
+ plan: null,
5858
+ title: '任务信息不足(先澄清)',
5859
+ degraded: false,
5860
+ clarify: true,
5861
+ error: clarify.reason,
5862
+ statuses: [],
5863
+ phase: 'clarify',
5864
+ errors: [truncate(clarify.reason, 1000)],
5865
+ createdAt,
5866
+ updatedAt: createdAt,
5867
+ createdTurn: payload.turn,
5868
+ });
5869
+ return enterDecision(downstream, [buildClarifyMessage({
5870
+ rule: clarify.rule,
5871
+ reason: clarify.reason,
5872
+ question: clarify.question,
5873
+ })]);
5874
+ }
5875
+ }
5724
5876
  const modelSelection = resolveModelSelection(ctx, payload);
5725
5877
  if (!modelSelection?.provider || !modelSelection?.model) {
5726
5878
  const message = buildDegradedMessage({