dsh-workplan 1.12.2 → 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,33 @@
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
+
1
31
  ## 1.12.2 — 2026-11-04
2
32
 
3
33
  **修好 G1/G2/G3 三个写保护漏洞(1.12.1 只记录了缺口)。这是一次有意的行为变更:已交付文件的写保护现在真正无死角,且不再区分「谁在写」。**
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.2-blue.svg)](https://github.com/abbaababa/dsh-workplan/releases/tag/v1.12.2)
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.2
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.2-blue.svg)](https://github.com/abbaababa/dsh-workplan/releases/tag/v1.12.2)
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.2
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.2-blue.svg)](https://github.com/abbaababa/dsh-workplan/releases/tag/v1.12.2)
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.2
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.2',
1173
+ version: '1.12.3',
1150
1174
  promptOrder: PROMPT_ORDER,
1151
1175
  routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
1152
1176
  };
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
@@ -14,8 +14,8 @@
14
14
  import { randomUUID } from 'node:crypto';
15
15
  import { existsSync, realpathSync, statSync } from 'node:fs';
16
16
  import { basename, dirname, isAbsolute, join, 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';
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
  }
@@ -5642,6 +5684,14 @@ export function createWorkplanRuntime(ctx, options = {}) {
5642
5684
  planModeActive: (session) => isPlanModeActive(ctx, session),
5643
5685
  };
5644
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
+ }
5645
5695
  function resolveModelSelection(ctx, payload) {
5646
5696
  const direct = payload.modelSelection;
5647
5697
  if (direct?.provider && direct?.model) {
@@ -5790,6 +5840,39 @@ async function maybePlan(ctx, state, payload, downstream, options) {
5790
5840
  }
5791
5841
  return downstream;
5792
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
+ }
5793
5876
  const modelSelection = resolveModelSelection(ctx, payload);
5794
5877
  if (!modelSelection?.provider || !modelSelection?.model) {
5795
5878
  const message = buildDegradedMessage({
@@ -386,6 +386,245 @@ export function resolvePronounAntecedent(token, conversationContext) {
386
386
  }
387
387
  return null;
388
388
  }
389
+ /**
390
+ * [T3] Resolve a pronoun from the task text itself, in the sentence that holds
391
+ * it or the sentence immediately before it.
392
+ *
393
+ * MS2 T05-08 read 「…159667工业母机ETF国泰,下月全月…?准确预判后…告诉我,它每天…」
394
+ * — the name sits in the PREVIOUS sentence while the pronoun's own sentence is
395
+ * pure prose, so conversation-only resolution rejected the task as "no
396
+ * antecedent". A name the user wrote in the task is the strongest possible
397
+ * antecedent, so the task text is searched too:
398
+ *
399
+ * 1. the current sentence, before the pronoun;
400
+ * 2. only if that has no referent, the sentence right before it.
401
+ *
402
+ * Only explicit referents qualify: a quoted name, or an identifier-like span
403
+ * (「159667工业母机ETF国泰」/「159667」/「dsh-workplan」) — the boundaries a reader
404
+ * would use. Ordinary prose never qualifies, so a pronoun with no real referent
405
+ * still blocks (`needs-context`) instead of being resolved to filler.
406
+ *
407
+ * The scope is deliberately narrow: reaching further produced wrong antecedents
408
+ * in replay ("…昨天涨了" taken as a name). A blocked plan is recoverable; a plan
409
+ * dispatched on a guessed referent is not.
410
+ */
411
+ const INLINE_SENTENCE_BOUNDARY = /[。!?!?\n]/;
412
+ const INLINE_NAME_CHAR = /[\u4e00-\u9fffA-Za-z0-9._-]/;
413
+ const INLINE_ENTITY_STOP = new Set('的是了在有我你他她它们这那吗呢吧啊呀就都也还又很太更最把被让给从到与和及或而但却则其该此每各么怎如何走涨跌买卖加减看好'.split(''));
414
+ const LEADING_REQUEST = /^(?:看一下|看下|看看|帮我|帮忙|麻烦|给我|我们|必须|需要|想要|关注|推荐|分析|预判|预测|研究|介绍|说说|告诉|查一下|查查|对比|比较|关于|针对|请|我|你|想|要|把|将|对)\s*/;
415
+ function isInlineSentenceBoundary(char) {
416
+ return !!char && INLINE_SENTENCE_BOUNDARY.test(char);
417
+ }
418
+ function isInlineNameChar(char) {
419
+ return !!char && INLINE_NAME_CHAR.test(char);
420
+ }
421
+ /** Drop request lead-ins so "我关注159667…" reads as the name, not the sentence. */
422
+ function stripRequestPrefixes(fragment) {
423
+ let value = fragment;
424
+ for (let round = 0; round < 3; round += 1) {
425
+ const next = value.replace(LEADING_REQUEST, '');
426
+ if (next === value)
427
+ break;
428
+ value = next;
429
+ }
430
+ return value.trim();
431
+ }
432
+ /**
433
+ * Is this span an explicit referent rather than a piece of prose?
434
+ *
435
+ * An explicit referent carries an identifier signal (a 4+ digit code such as
436
+ * 159667, or a Latin run such as ETF / dsh-workplan) and contains no function
437
+ * word. That keeps 「159667工业母机ETF国泰」 and drops 「是我重点关注的基金」.
438
+ * Dates (「11月」/「2026年」) and bare numbers are not referents.
439
+ */
440
+ function isExplicitEntityToken(value) {
441
+ const token = value.trim();
442
+ if (token.length < 2 || token.length > 24)
443
+ return false;
444
+ if (/^(?:它|他|她|其)(?:们)?$/.test(token))
445
+ return false;
446
+ if (/^\d{1,4}(?:年|月|日|号)/.test(token))
447
+ return false;
448
+ if (/^\d{1,2}$/.test(token))
449
+ return false;
450
+ // A bare instrument category names a class, not one instrument.
451
+ if (/^(?:ETF|LOF|QDII|A股|港股|美股)$/.test(token))
452
+ return false;
453
+ const hasCode = /\d{4,}/.test(token);
454
+ const hasLatin = /[A-Za-z]{2,}/.test(token);
455
+ const mixedSignal = /[A-Za-z]\d|\d[A-Za-z]/.test(token);
456
+ if (!hasCode && !hasLatin && !mixedSignal)
457
+ return false;
458
+ for (const char of token) {
459
+ if (INLINE_ENTITY_STOP.has(char))
460
+ return false;
461
+ }
462
+ return !FUNCTION_WORD_ONLY.test(token);
463
+ }
464
+ /**
465
+ * Take the explicit referent out of one punctuation/space-delimited fragment.
466
+ *
467
+ * A clean fragment is kept whole; otherwise the identifier and the name
468
+ * characters attached to it are cut out, stopping at the first function word
469
+ * or verb ("159667工业母机ETF国泰是我重点…" -> "159667工业母机ETF国泰").
470
+ */
471
+ function inlineEntityCore(fragment) {
472
+ const raw = stripRequestPrefixes(fragment).replace(/[。!?!?…]+$/, '').trim();
473
+ if (!raw)
474
+ return null;
475
+ if (isExplicitEntityToken(raw))
476
+ return raw;
477
+ const anchor = /\d{2,}|[A-Za-z]{2,}/.exec(raw);
478
+ if (!anchor)
479
+ return null;
480
+ let start = anchor.index;
481
+ while (start > 0 && isInlineNameChar(raw[start - 1]) && !INLINE_ENTITY_STOP.has(raw[start - 1]))
482
+ start -= 1;
483
+ let end = anchor.index + anchor[0].length;
484
+ while (end < raw.length && isInlineNameChar(raw[end]) && !INLINE_ENTITY_STOP.has(raw[end]))
485
+ end += 1;
486
+ const value = raw.slice(start, end).replace(/[.\-_]+$/, '').trim();
487
+ return isExplicitEntityToken(value) ? value : null;
488
+ }
489
+ /** Find the last explicit referent inside one sentence span. */
490
+ function findExplicitEntity(span) {
491
+ const text = span.trim();
492
+ if (!text)
493
+ return null;
494
+ const quoted = [...text.matchAll(/[「『“"《]([^」』”"》\n]{2,24})[」』”"》]/g)];
495
+ for (let i = quoted.length - 1; i >= 0; i -= 1) {
496
+ const value = quoted[i][1].trim();
497
+ if (isExplicitEntityToken(value))
498
+ return { antecedent: value, source: text.slice(-80) };
499
+ }
500
+ const fragments = text.split(/[,,、;;::\s]+/);
501
+ for (let i = fragments.length - 1; i >= 0; i -= 1) {
502
+ const value = inlineEntityCore(fragments[i]);
503
+ if (value)
504
+ return { antecedent: value, source: text.slice(-80) };
505
+ }
506
+ return null;
507
+ }
508
+ /** Bounds of the sentence around `index`, plus the sentence immediately before. */
509
+ function inlineSentenceBounds(text, index) {
510
+ let start = 0;
511
+ for (let i = index - 1; i >= 0; i -= 1) {
512
+ if (isInlineSentenceBoundary(text[i])) {
513
+ start = i + 1;
514
+ break;
515
+ }
516
+ }
517
+ let prevEnd = start;
518
+ while (prevEnd > 0 && isInlineSentenceBoundary(text[prevEnd - 1]))
519
+ prevEnd -= 1;
520
+ let prevStart = 0;
521
+ for (let i = prevEnd - 1; i >= 0; i -= 1) {
522
+ if (isInlineSentenceBoundary(text[i])) {
523
+ prevStart = i + 1;
524
+ break;
525
+ }
526
+ }
527
+ return { start, prevStart, prevEnd };
528
+ }
529
+ /** 「其它」 is a word, not a pronoun: skip it and use the real occurrence. */
530
+ function lastInlineReferenceIndex(text, token) {
531
+ let index = text.lastIndexOf(token);
532
+ while (index > 0 && token === '它' && text[index - 1] === '其') {
533
+ index = text.lastIndexOf(token, index - 1);
534
+ }
535
+ return index;
536
+ }
537
+ export function resolvePronounAntecedentInline(token, taskText) {
538
+ const text = String(taskText ?? '');
539
+ if (!text || text.length > MAX_TASK_ANCHOR_CHARS)
540
+ return null;
541
+ const index = lastInlineReferenceIndex(text, token);
542
+ if (index <= 0)
543
+ return null;
544
+ const bounds = inlineSentenceBounds(text, index);
545
+ const current = findExplicitEntity(text.slice(bounds.start, index));
546
+ if (current)
547
+ return current;
548
+ if (bounds.prevEnd > bounds.prevStart) {
549
+ const previous = findExplicitEntity(text.slice(bounds.prevStart, bounds.prevEnd));
550
+ if (previous)
551
+ return previous;
552
+ }
553
+ return null;
554
+ }
555
+ /**
556
+ * [P0-2c] Decide whether a task is missing information the user must supply.
557
+ *
558
+ * MS2's four clarify cases (T05-04/09/13/20) were planned and dispatched anyway.
559
+ * Each failed for a *checkable* reason, so each gets a deterministic rule instead
560
+ * of a vibe:
561
+ *
562
+ * C1 bare agreement — the text is an answer to a question the model never saw
563
+ * (「同意移入」) and carries an identifier it never defines (R-W5-01).
564
+ * C2 dangling artifact — an internal reference (T4 草稿, W5) that is not defined
565
+ * in the task and not present in the conversation.
566
+ * C3 missing target — a forecast/trend request with no identifiable subject
567
+ * (「准确预测11月全月详细、具体走势」: which instrument? which year?).
568
+ * C4 missing UI object — a display change (折叠/展开/按钮…) that names no surface
569
+ * (左侧栏/截图/插件…), so any implementation would be a guess.
570
+ */
571
+ export function auditClarifyNeed(taskText, conversationContext = '') {
572
+ const text = String(taskText ?? '').trim();
573
+ const conversation = String(conversationContext ?? '');
574
+ if (!text)
575
+ return { needed: false, rule: '', reason: '', question: '' };
576
+ const both = text + '\n' + conversation;
577
+ const AGREEMENT = /(?:^|[。;;!!\n])\s*(?:同意|赞成|可以|好的|没问题|就按|按你说的|确认)/;
578
+ // No trailing \b: a CJK char is a non-word char, so 「T4 草稿」 has no word
579
+ // boundary after 稿 and the id would silently never match.
580
+ const DANGLING_ID = /(?:R-[A-Z]{1,4}-\d{1,4}|W\d{1,3}\b|T\d{1,3}\s*草稿)/;
581
+ if (AGREEMENT.test(text) && (DANGLING_ID.test(text) || text.length <= 24) && !DANGLING_ID.test(conversation)) {
582
+ return {
583
+ needed: true,
584
+ rule: 'C1',
585
+ reason: '任务只是对上文问题的表态,且引用了任务里没有定义的编号,缺上文',
586
+ question: '你这句话是在回答哪个问题?请把上文的问题、或你要「同意/移入」的具体对象说清楚。',
587
+ };
588
+ }
589
+ const dangling = text.match(DANGLING_ID);
590
+ if (dangling && !conversation.includes(dangling[0])) {
591
+ return {
592
+ needed: true,
593
+ rule: 'C2',
594
+ reason: '任务引用了「' + dangling[0] + '」这一内部编号/草稿,但任务原文没有定义它,也找不到上文',
595
+ question: '「' + dangling[0] + '」指的是什么?请给出文件路径、链接或把内容贴进来。',
596
+ };
597
+ }
598
+ const FORECAST = /(预测|预判|走势|涨跌|行情)/;
599
+ const SUBJECT = /(?:\d{6}|[A-Z]{2,}\d+|[「『“"《][^」』”"》]{2,20}[」』”"》])/;
600
+ // The missing subject may already be named in the conversation (「它走势如何」 after
601
+ // the user quoted a ticker). Only the task's own words make it a forecast request.
602
+ if (FORECAST.test(text) && !SUBJECT.test(both)) {
603
+ return {
604
+ needed: true,
605
+ rule: 'C3',
606
+ reason: '要求预测走势,但任务里没有可识别标的(股票代码/名称),也没有年份,缺关键输入',
607
+ question: '要预测哪只标的(股票代码或名称)?看哪个时间段?',
608
+ };
609
+ }
610
+ const UI_VERB = /(折叠|展开|按钮|显示|布局|样式|颜色|排序|置顶|收起)/;
611
+ // 红圈/红框/圈出 name a surface the same way 截图 does: the user has pointed at
612
+ // something concrete. Without them 「把红圈处改为默认收起」 was C4-blocked even
613
+ // though the sentence is unambiguous (caught by department-fit.test.ts).
614
+ const UI_OBJECT = /(左侧栏|右侧栏|侧边栏|侧栏|面板|对话框|弹窗|菜单|工具栏|页面|截图|画圈|红圈|红框|圈出|插件|顶栏|底栏|任务进度)/;
615
+ // Same rule as C3: 「把它改成默认收起」 is not missing a surface when the previous
616
+ // turn said 「截图红圈处的分步进度」. The verb must be in the task, the object may
617
+ // come from either side (plan-anchor.test.ts 'strict mode blocks…' covers this).
618
+ if (UI_VERB.test(text) && !UI_OBJECT.test(both)) {
619
+ return {
620
+ needed: true,
621
+ rule: 'C4',
622
+ reason: '要求改动界面显示,但没有说明改哪个界面/哪个板块,缺指代对象',
623
+ question: '要改的是哪个界面/哪个板块?(例如左侧栏、任务进度面板、某个按钮;有截图更好)',
624
+ };
625
+ }
626
+ return { needed: false, rule: '', reason: '', question: '' };
627
+ }
389
628
  /**
390
629
  * Split one clause into candidate noun phrases.
391
630
  *
@@ -836,15 +1075,24 @@ export function auditTaskUnderstanding(plan, context = {}) {
836
1075
  const resolvedByContext = extracted.references.map((reference) => {
837
1076
  if (reference.resolved)
838
1077
  return reference;
839
- const found = resolvePronounAntecedent(reference.token, conversation);
1078
+ const fromConversation = resolvePronounAntecedent(reference.token, conversation);
1079
+ const found = fromConversation ?? resolvePronounAntecedentInline(reference.token, taskText);
840
1080
  if (!found)
841
1081
  return reference;
842
1082
  // Option letters are resolved only when the conversation lists that option
843
1083
  // as a listed choice ("A 方案" / "B 选项"), not a bare letter in a word.
1084
+ // Task-text entities never satisfy this rule on their own: the option must
1085
+ // be defined where the user chose it, i.e. in the conversation.
844
1086
  const listedOption = new RegExp('(?:^|[^A-Za-z])' + reference.token + '\\s*(?:方案|选项)');
845
1087
  if (/^[A-D]$/.test(reference.token) && !listedOption.test(conversation))
846
1088
  return reference;
847
- return { ...reference, resolved: true, resolvedBy: 'context', antecedent: found.antecedent };
1089
+ /*
1090
+ * [T3] Record where the referent came from. Reusing 'context' for an
1091
+ * antecedent found inside the task text would misreport an empty
1092
+ * conversation as the source, so the audit keeps the two apart.
1093
+ */
1094
+ const resolvedBy = fromConversation ? 'context' : 'task-text';
1095
+ return { ...reference, resolved: true, resolvedBy, antecedent: found.antecedent };
848
1096
  });
849
1097
  const unresolved = resolvedByContext.filter((reference) => !reference.resolved);
850
1098
  const reasons = [];
@@ -938,6 +1186,14 @@ export function validatePlanContext(plan, context = {}) {
938
1186
  if (audit.stage3.verdict === 'needs-clarification') {
939
1187
  errors.push(`CLARIFY: ${audit.stage3.reasons.find((reason) => reason.includes('自相矛盾')) ?? '用户要求存在矛盾,必须先向用户确认'}`);
940
1188
  }
1189
+ /*
1190
+ * [P0-2c] Missing inputs must stop the plan before any department agent runs:
1191
+ * MS2 T05-04/09/13/20 were all planned and dispatched with the key input absent.
1192
+ */
1193
+ const clarify = auditClarifyNeed(context.taskText ?? audit.anchor?.text ?? '', context.conversationContext ?? '');
1194
+ if (clarify.needed) {
1195
+ errors.push('CLARIFY: ' + clarify.reason + '(规则 ' + clarify.rule + ')');
1196
+ }
941
1197
  if (audit.stage3.verdict === 'needs-context') {
942
1198
  errors.push(`CONTEXT: ${audit.stage3.reasons.find((reason) => reason.includes('指代')) ?? '任务含指代但在最近对话中找不到先行词,必须先向用户确认'}`);
943
1199
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-workplan",
3
- "version": "1.12.2",
3
+ "version": "1.12.3",
4
4
  "description": "Automatic task decomposition, real department subagents, and a responsive workplan dashboard for DeepSeek Harness.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -173,6 +173,13 @@ export const DEPARTMENT_CAPABILITIES: readonly DepartmentCapability[] = Object.f
173
173
  keywords: [
174
174
  '法务', '合同', '版权', '许可', '合规', '条款', '法律', '隐私', '授权', '侵权', '国际标准',
175
175
  'ISO/IEC 15408', '15408', 'ISO/IEC', 'ISO 标准', 'CC 标准',
176
+ // [P0-4 recall] T05-12 「会不会窃取用户电脑和移动终端里的文件和数据」 is a
177
+ // privacy/authorisation claim and matched nothing: the list had 隐私/授权 but
178
+ // not the verbs a user actually writes. These are plain words, so the
179
+ // intrusion guard keeps legal out of unrelated plans.
180
+ // 「泄露」 alone would also fire on 「内存泄露」 (a memory leak is engineering,
181
+ // not legal); 「信息泄露」 keeps the privacy sense and the keyword count at 22.
182
+ '窃取', '信息泄露', '个人信息', '数据安全', '隐私风险', '移动终端',
176
183
  ],
177
184
  },
178
185
  {
package/src/host.ts CHANGED
@@ -194,6 +194,16 @@ export type WorkplanConfig = {
194
194
  * 关闭方式:`autoDispatch: false` 或环境变量 `DSH_WORKPLAN_AUTO_DISPATCH=0`。
195
195
  */
196
196
  autoDispatch?: boolean
197
+ /**
198
+ * [1.12.3] headless「未完成不得成功收尾」硬闸门。
199
+ *
200
+ * `'auto'`(不配置时的默认):只在 headless 运行中启用,交互式 web/tui 会话
201
+ * 行为完全不变。`true` 强制开启(任何运行方式都硬失败),`false` 关闭并回到
202
+ * 1.12.2 的「steer 用尽即放行」。
203
+ *
204
+ * 环境变量:`DSH_WORKPLAN_FAIL_CLOSED_ON_INCOMPLETE=1|0`。
205
+ */
206
+ failClosedOnIncomplete?: boolean
197
207
  }
198
208
 
199
209
  function createUpdateTool(runtime: any) {
@@ -1060,6 +1070,23 @@ function strictCompletionEnabledFrom(configValue: any, envValue: any) {
1060
1070
  return true
1061
1071
  }
1062
1072
 
1073
+ /**
1074
+ * [1.12.3] `failClosedOnIncomplete` 的三态解析:显式配置 > 显式环境变量 > 'auto'。
1075
+ *
1076
+ * 与 `strictCompletionEnabledFrom` 的区别只在默认值:这里未配置时返回 `'auto'`,
1077
+ * 语义是「headless 才硬失败」,不能退化成 `false`(那等于默认关闭,事故会复发),
1078
+ * 也不能退化成 `true`(那会让交互式会话在收尾时抛错)。
1079
+ */
1080
+ function failClosedOnIncompleteFrom(configValue: any, envValue: any): boolean | 'auto' {
1081
+ if (typeof configValue === 'boolean') return configValue
1082
+ const raw = envValue === undefined || envValue === null ? '' : String(envValue).trim()
1083
+ if (raw !== '') {
1084
+ if (/^(1|true|yes|on)$/i.test(raw)) return true
1085
+ if (/^(0|false|no|off)$/i.test(raw)) return false
1086
+ }
1087
+ return 'auto'
1088
+ }
1089
+
1063
1090
  function booleanSetting(configValue: any, envName: string) {
1064
1091
  if (typeof configValue === 'boolean') return configValue
1065
1092
  const raw = typeof process !== 'undefined' ? process.env?.[envName] : undefined
@@ -1139,6 +1166,14 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
1139
1166
  * 与 autoResume / strictCompletion 同一写法,避免「没配置就等于关闭」。
1140
1167
  */
1141
1168
  autoDispatch: strictCompletionEnabledFrom(config.autoDispatch, settingEnv('DSH_WORKPLAN_AUTO_DISPATCH')),
1169
+ /*
1170
+ * [1.12.3] headless「未完成不得成功收尾」。默认 'auto':只有 headless
1171
+ * 运行上下文(提供 `headlessStartup` 服务)才硬失败,交互式会话不受影响。
1172
+ */
1173
+ failClosedOnIncomplete: failClosedOnIncompleteFrom(
1174
+ config.failClosedOnIncomplete,
1175
+ settingEnv('DSH_WORKPLAN_FAIL_CLOSED_ON_INCOMPLETE'),
1176
+ ),
1142
1177
  })
1143
1178
 
1144
1179
  ctx.effect(() =>
@@ -1255,7 +1290,7 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
1255
1290
 
1256
1291
  export const meta = {
1257
1292
  name,
1258
- version: '1.12.2',
1293
+ version: '1.12.3',
1259
1294
  promptOrder: PROMPT_ORDER,
1260
1295
  routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
1261
1296
  }
package/src/plan.ts CHANGED
@@ -1224,6 +1224,32 @@ export function buildDegradedMessage(options: any) {
1224
1224
  return makeUserMessage(text, { kind: 'workplan', form: 'notice', summary })
1225
1225
  }
1226
1226
 
1227
+ /**
1228
+ * [1.12.3] 信息不足时先问,不做计划也不派发。
1229
+ *
1230
+ * 2026-11-04 MS2 的真实数据:T05-04/09/13/20 这四条本来需要澄清,插件却照样拆出
1231
+ * 计划并(自动)派发,部门 Agent 于是对着一个并不存在的目标开工。用户在同一天拍板:
1232
+ * 自动派发只在「信息不足」这一类上拦截,其余一律照旧。所以这里不是关掉自动派发,
1233
+ * 而是在规划**之前**把缺的东西变成一句能给用户看的话。
1234
+ *
1235
+ * 这条消息不带计划信封:没有计划就没有 planId,也不该出现在计划列表里。
1236
+ */
1237
+ export function buildClarifyMessage(options: any) {
1238
+ const rule = String(options.rule ?? '')
1239
+ const reason = truncate(options.reason ?? '', 600)
1240
+ const question = String(options.question ?? '').trim()
1241
+ const summary = truncate(`【先澄清,未生成计划】${reason}`, 300)
1242
+ const text = [
1243
+ `【先澄清,未生成计划】任务信息不足:${reason}(规则 ${rule})`,
1244
+ '',
1245
+ `请把这句话原样问用户:${question || '请补充这个任务缺的关键信息。'}`,
1246
+ '',
1247
+ '本条没有生成任务分解,也没有派发任何部门 Agent——缺信息时拆出来的计划只能靠猜。',
1248
+ '等用户回答后,用户的下一条消息会重新触发计划生成;在那之前不要调用 dsh_workplan_dispatch,也不要开始执行。',
1249
+ ].join('\n')
1250
+ return makeUserMessage(text, { kind: 'workplan', form: 'notice', summary })
1251
+ }
1252
+
1227
1253
  export function buildResultSummary(result: any) {
1228
1254
  const stats = result.stats ?? { done: 0, total: 0, blocked: 0 }
1229
1255
  const done = Number(stats.done ?? 0)
package/src/runtime.ts CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  blockCancelledDependents,
26
26
  buildChildPrompt,
27
27
  buildCancelMessage,
28
+ buildClarifyMessage,
28
29
  buildDegradedMessage,
29
30
  buildPlanMessage,
30
31
  buildPlannerPrompt,
@@ -71,7 +72,7 @@ import {
71
72
  MAX_HANDOFF_RESPONSE_CHARS,
72
73
  } from './plan.js'
73
74
  import type { PresentDenialVerdict, PresentDenyCode } from './plan.js'
74
- import { compactUnderstandingAudit, validatePlanContext } from './understanding.js'
75
+ import { auditClarifyNeed, compactUnderstandingAudit, validatePlanContext } from './understanding.js'
75
76
  import { computeMappingDigest, verifyMappingDigest } from './supersede-digest.js'
76
77
  import { supersedePlanRecord } from './supersede.js'
77
78
  import { createProgressWatchdog, describeError } from './watchdog.js'
@@ -2770,6 +2771,27 @@ export type WorkplanRuntimeOptions = {
2770
2771
  * 派发)。plan 模式、已有计划执行中、预算/取消/幂等/交付门禁不受影响。
2771
2772
  */
2772
2773
  autoDispatch?: boolean
2774
+ /**
2775
+ * [1.12.3] headless「未完成不得成功收尾」硬闸门(fail-closed)。
2776
+ *
2777
+ * 事故(session-99984ebd…)暴露的最后一个缺口:`agent/turn-stopping` 的
2778
+ * steer 每个回合最多 2 次,用尽后闸门只能沉默放行;而官方 headless runner
2779
+ * 的完成判据是 `turn/end reason.kind === 'completed'`,它并不认识计划,
2780
+ * 于是「计划未完成但回合正常收尾」= 打印正文 + exit 0,自动化仍把它当成成功。
2781
+ *
2782
+ * 语义:
2783
+ * - `'auto'`(默认):只在 headless 运行中启用——判据是运行上下文提供了
2784
+ * 官方 headless 专属服务 `headlessStartup`(packages/bundle/headless/
2785
+ * src/startup.ts 提供,web/tui profile 不提供)。交互式会话行为不变。
2786
+ * - `true` / `false`:显式打开 / 关闭。
2787
+ *
2788
+ * 启用后:steer 次数用尽而计划仍未通过交付就绪检查时,闸门抛
2789
+ * `PlanError('WORKPLAN_INCOMPLETE')`。官方 `agent/turn-stopping` 是 serial
2790
+ * 事件(cordis `serial()` 逐个 await,监听器抛错会向上传播),因此该回合以
2791
+ * `error` 结束;headless runner 的 `failure` 非空 ⇒ 不打印「已完成」正文、
2792
+ * 以非零退出码结束(packages/bundle/headless/src/index.ts 的 fail())。
2793
+ */
2794
+ failClosedOnIncomplete?: boolean | 'auto'
2773
2795
  /**
2774
2796
  * [1.8.13] Package version, supplied by the host from its `meta.version`.
2775
2797
  *
@@ -2810,6 +2832,19 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
2810
2832
  * resume, cancel, the host's tool timeout) agrees on the same numbers.
2811
2833
  */
2812
2834
  const pluginVersion = typeof options.version === 'string' && options.version ? options.version : 'unknown'
2835
+ /*
2836
+ * [1.12.3] fail-closed 解析:显式值优先;'auto' 只在 headless 运行中生效。
2837
+ * `ctx.get` 在普通对象(测试)上不存在,可选链保证降级为「非 headless」。
2838
+ */
2839
+ const failClosedMode: boolean | 'auto' = options.failClosedOnIncomplete ?? 'auto'
2840
+ const headlessRun = (() => {
2841
+ try {
2842
+ return ctx?.get?.('headlessStartup') !== undefined
2843
+ } catch {
2844
+ return false
2845
+ }
2846
+ })()
2847
+ const failClosedActive = failClosedMode === true || (failClosedMode === 'auto' && headlessRun)
2813
2848
  /*
2814
2849
  * [1.8.14] Build identity, captured once.
2815
2850
  *
@@ -5033,7 +5068,34 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
5033
5068
  const book = record.stopSteers && record.stopSteers.turn === turn
5034
5069
  ? record.stopSteers
5035
5070
  : { turn, count: 0 }
5036
- if (book.count >= STOP_STEER_LIMIT) return
5071
+ if (book.count >= STOP_STEER_LIMIT) {
5072
+ /*
5073
+ * [1.12.3] steer 用尽后不再沉默放行。
5074
+ *
5075
+ * 旧行为(1.8.7–1.12.2):达到上限就 `return`,回合正常收尾。对交互式
5076
+ * 会话这是「避免死循环」;对 headless 却是事故复现路径——官方 runner 只
5077
+ * 看 `turn/end reason.kind==='completed'`,它会把「计划未完成但回合正常
5078
+ * 结束」打印成结果并 exit 0(session-99984ebd… 的最终现场)。
5079
+ *
5080
+ * 现在:headless(或显式开启)时抛 WORKPLAN_INCOMPLETE。turn-stopping
5081
+ * 是 serial 事件,抛错 ⇒ 该回合以 error 收尾 ⇒ runner 走 fail():
5082
+ * 不打印正文、非零退出。交互式会话维持原样(只 steer,不抛错)。
5083
+ */
5084
+ if (failClosedActive) {
5085
+ const stuck = derivePlanSnapshot(record.statuses)
5086
+ const remaining = (stuck.statuses ?? [])
5087
+ .filter((item: any) => item.status !== 'done')
5088
+ .map((item: any) => String(item.subtaskId))
5089
+ throw new PlanError(
5090
+ `未完成:剩余 ${remaining.length} 项(${remaining.join(', ')})与原因——计划 ${record.plan.planId} `
5091
+ + `仅完成 ${stuck.stats.done}/${stuck.stats.total},本回合已连续 ${book.count} 次被要求续跑/补证,`
5092
+ + '仍未通过交付就绪检查。headless 以非零退出码结束,不输出「已完成」结果。',
5093
+ 'WORKPLAN_INCOMPLETE',
5094
+ { planId: record.plan.planId, stats: stuck.stats, remaining },
5095
+ )
5096
+ }
5097
+ return
5098
+ }
5037
5099
  book.count += 1
5038
5100
  record.stopSteers = book
5039
5101
  const snapshot = derivePlanSnapshot(record.statuses)
@@ -5058,6 +5120,11 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
5058
5120
  + `已在回合收尾前要求继续/如实收尾(第 ${book.count} 次)`,
5059
5121
  )
5060
5122
  } catch (error) {
5123
+ /*
5124
+ * [1.12.3] fail-closed 的硬失败必须穿过这层日志包装:
5125
+ * 这里原本把任何异常降级成一条 warn,等于把上面的抛错又吃掉。
5126
+ */
5127
+ if (error instanceof PlanError && error.code === 'WORKPLAN_INCOMPLETE') throw error
5061
5128
  ctx.logger?.warn?.(`dsh-workplan: 回合收尾检查失败:${error instanceof Error ? error.message : String(error)}`)
5062
5129
  }
5063
5130
  }
@@ -5649,6 +5716,15 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
5649
5716
  }
5650
5717
  }
5651
5718
 
5719
+ /**
5720
+ * [1.12.3] 澄清闸门的退出口。默认开启;只有显式设成 0/false/off 才回到旧行为
5721
+ * (信息不足也照做计划、照派发)。
5722
+ */
5723
+ function clarifyGateDisabled() {
5724
+ const raw = String(process.env.DSH_WORKPLAN_CLARIFY_GATE ?? '').trim().toLowerCase()
5725
+ return raw === '0' || raw === 'false' || raw === 'off'
5726
+ }
5727
+
5652
5728
  function resolveModelSelection(ctx: any, payload: any) {
5653
5729
  const direct = payload.modelSelection
5654
5730
  if (direct?.provider && direct?.model) {
@@ -5786,6 +5862,39 @@ async function maybePlan(ctx: any, state: any, payload: any, downstream: any, op
5786
5862
  }
5787
5863
  return downstream
5788
5864
  }
5865
+ /*
5866
+ * [1.12.3] 信息不足就不做计划、不派发——只问一句。
5867
+ *
5868
+ * 用户在 2026-11-04 拍板:自动派发改成「只在信息不足这一类上拦截」,其余照旧。
5869
+ * 因此拦截点放在规划之前,而不是关掉自动派发:缺信息时连计划都不生成,
5870
+ * 免得部门 Agent 对着一个猜出来的目标开工。
5871
+ * 关闭方式:DSH_WORKPLAN_CLARIFY_GATE=0(保留给需要旧行为的自动化)。
5872
+ */
5873
+ if (!clarifyGateDisabled()) {
5874
+ const clarify = auditClarifyNeed(taskText, conversationContext)
5875
+ if (clarify.needed) {
5876
+ const createdAt = Date.now()
5877
+ state.records.set(session.id, {
5878
+ planId: null,
5879
+ plan: null,
5880
+ title: '任务信息不足(先澄清)',
5881
+ degraded: false,
5882
+ clarify: true,
5883
+ error: clarify.reason,
5884
+ statuses: [],
5885
+ phase: 'clarify',
5886
+ errors: [truncate(clarify.reason, 1000)],
5887
+ createdAt,
5888
+ updatedAt: createdAt,
5889
+ createdTurn: payload.turn,
5890
+ })
5891
+ return enterDecision(downstream, [buildClarifyMessage({
5892
+ rule: clarify.rule,
5893
+ reason: clarify.reason,
5894
+ question: clarify.question,
5895
+ })])
5896
+ }
5897
+ }
5789
5898
  const modelSelection = resolveModelSelection(ctx, payload)
5790
5899
  if (!modelSelection?.provider || !modelSelection?.model) {
5791
5900
  const message = buildDegradedMessage({
@@ -118,12 +118,13 @@ export interface TaskReference {
118
118
  token: string
119
119
  /**
120
120
  * `context` = an antecedent for this token was actually found in the recent
121
- * conversation and quoted in `antecedent`; `inline-noun` = e.g. 「这个插件」;
122
- * `none` = still ambiguous.
121
+ * conversation and quoted in `antecedent`; `task-text` = the referent was
122
+ * named in the user's own task text (the pronoun's sentence, or the sentence
123
+ * right before it); `inline-noun` = e.g. 「这个插件」; `none` = still ambiguous.
123
124
  */
124
- resolvedBy: 'context' | 'inline-noun' | 'none'
125
+ resolvedBy: 'context' | 'task-text' | 'inline-noun' | 'none'
125
126
  resolved: boolean
126
- /** The noun phrase taken from the conversation that this token points at. */
127
+ /** The noun phrase (from the conversation or the task text) the token points at. */
127
128
  antecedent?: string
128
129
  evidence: string
129
130
  }
@@ -559,6 +560,238 @@ export function resolvePronounAntecedent(token: string, conversationContext: str
559
560
  return null
560
561
  }
561
562
 
563
+ /**
564
+ * [T3] Resolve a pronoun from the task text itself, in the sentence that holds
565
+ * it or the sentence immediately before it.
566
+ *
567
+ * MS2 T05-08 read 「…159667工业母机ETF国泰,下月全月…?准确预判后…告诉我,它每天…」
568
+ * — the name sits in the PREVIOUS sentence while the pronoun's own sentence is
569
+ * pure prose, so conversation-only resolution rejected the task as "no
570
+ * antecedent". A name the user wrote in the task is the strongest possible
571
+ * antecedent, so the task text is searched too:
572
+ *
573
+ * 1. the current sentence, before the pronoun;
574
+ * 2. only if that has no referent, the sentence right before it.
575
+ *
576
+ * Only explicit referents qualify: a quoted name, or an identifier-like span
577
+ * (「159667工业母机ETF国泰」/「159667」/「dsh-workplan」) — the boundaries a reader
578
+ * would use. Ordinary prose never qualifies, so a pronoun with no real referent
579
+ * still blocks (`needs-context`) instead of being resolved to filler.
580
+ *
581
+ * The scope is deliberately narrow: reaching further produced wrong antecedents
582
+ * in replay ("…昨天涨了" taken as a name). A blocked plan is recoverable; a plan
583
+ * dispatched on a guessed referent is not.
584
+ */
585
+ const INLINE_SENTENCE_BOUNDARY = /[。!?!?\n]/
586
+ const INLINE_NAME_CHAR = /[\u4e00-\u9fffA-Za-z0-9._-]/
587
+ const INLINE_ENTITY_STOP = new Set('的是了在有我你他她它们这那吗呢吧啊呀就都也还又很太更最把被让给从到与和及或而但却则其该此每各么怎如何走涨跌买卖加减看好'.split(''))
588
+ const LEADING_REQUEST = /^(?:看一下|看下|看看|帮我|帮忙|麻烦|给我|我们|必须|需要|想要|关注|推荐|分析|预判|预测|研究|介绍|说说|告诉|查一下|查查|对比|比较|关于|针对|请|我|你|想|要|把|将|对)\s*/
589
+
590
+ function isInlineSentenceBoundary(char: string | undefined): boolean {
591
+ return !!char && INLINE_SENTENCE_BOUNDARY.test(char)
592
+ }
593
+
594
+ function isInlineNameChar(char: string | undefined): boolean {
595
+ return !!char && INLINE_NAME_CHAR.test(char)
596
+ }
597
+
598
+ /** Drop request lead-ins so "我关注159667…" reads as the name, not the sentence. */
599
+ function stripRequestPrefixes(fragment: string): string {
600
+ let value = fragment
601
+ for (let round = 0; round < 3; round += 1) {
602
+ const next = value.replace(LEADING_REQUEST, '')
603
+ if (next === value) break
604
+ value = next
605
+ }
606
+ return value.trim()
607
+ }
608
+
609
+ /**
610
+ * Is this span an explicit referent rather than a piece of prose?
611
+ *
612
+ * An explicit referent carries an identifier signal (a 4+ digit code such as
613
+ * 159667, or a Latin run such as ETF / dsh-workplan) and contains no function
614
+ * word. That keeps 「159667工业母机ETF国泰」 and drops 「是我重点关注的基金」.
615
+ * Dates (「11月」/「2026年」) and bare numbers are not referents.
616
+ */
617
+ function isExplicitEntityToken(value: string): boolean {
618
+ const token = value.trim()
619
+ if (token.length < 2 || token.length > 24) return false
620
+ if (/^(?:它|他|她|其)(?:们)?$/.test(token)) return false
621
+ if (/^\d{1,4}(?:年|月|日|号)/.test(token)) return false
622
+ if (/^\d{1,2}$/.test(token)) return false
623
+ // A bare instrument category names a class, not one instrument.
624
+ if (/^(?:ETF|LOF|QDII|A股|港股|美股)$/.test(token)) return false
625
+ const hasCode = /\d{4,}/.test(token)
626
+ const hasLatin = /[A-Za-z]{2,}/.test(token)
627
+ const mixedSignal = /[A-Za-z]\d|\d[A-Za-z]/.test(token)
628
+ if (!hasCode && !hasLatin && !mixedSignal) return false
629
+ for (const char of token) {
630
+ if (INLINE_ENTITY_STOP.has(char)) return false
631
+ }
632
+ return !FUNCTION_WORD_ONLY.test(token)
633
+ }
634
+
635
+ /**
636
+ * Take the explicit referent out of one punctuation/space-delimited fragment.
637
+ *
638
+ * A clean fragment is kept whole; otherwise the identifier and the name
639
+ * characters attached to it are cut out, stopping at the first function word
640
+ * or verb ("159667工业母机ETF国泰是我重点…" -> "159667工业母机ETF国泰").
641
+ */
642
+ function inlineEntityCore(fragment: string): string | null {
643
+ const raw = stripRequestPrefixes(fragment).replace(/[。!?!?…]+$/, '').trim()
644
+ if (!raw) return null
645
+ if (isExplicitEntityToken(raw)) return raw
646
+ const anchor = /\d{2,}|[A-Za-z]{2,}/.exec(raw)
647
+ if (!anchor) return null
648
+ let start = anchor.index
649
+ while (start > 0 && isInlineNameChar(raw[start - 1]) && !INLINE_ENTITY_STOP.has(raw[start - 1])) start -= 1
650
+ let end = anchor.index + anchor[0].length
651
+ while (end < raw.length && isInlineNameChar(raw[end]) && !INLINE_ENTITY_STOP.has(raw[end])) end += 1
652
+ const value = raw.slice(start, end).replace(/[.\-_]+$/, '').trim()
653
+ return isExplicitEntityToken(value) ? value : null
654
+ }
655
+
656
+ /** Find the last explicit referent inside one sentence span. */
657
+ function findExplicitEntity(span: string): AntecedentResult | null {
658
+ const text = span.trim()
659
+ if (!text) return null
660
+ const quoted = [...text.matchAll(/[「『“"《]([^」』”"》\n]{2,24})[」』”"》]/g)]
661
+ for (let i = quoted.length - 1; i >= 0; i -= 1) {
662
+ const value = quoted[i][1].trim()
663
+ if (isExplicitEntityToken(value)) return { antecedent: value, source: text.slice(-80) }
664
+ }
665
+ const fragments = text.split(/[,,、;;::\s]+/)
666
+ for (let i = fragments.length - 1; i >= 0; i -= 1) {
667
+ const value = inlineEntityCore(fragments[i])
668
+ if (value) return { antecedent: value, source: text.slice(-80) }
669
+ }
670
+ return null
671
+ }
672
+
673
+ /** Bounds of the sentence around `index`, plus the sentence immediately before. */
674
+ function inlineSentenceBounds(text: string, index: number): { start: number; prevStart: number; prevEnd: number } {
675
+ let start = 0
676
+ for (let i = index - 1; i >= 0; i -= 1) {
677
+ if (isInlineSentenceBoundary(text[i])) {
678
+ start = i + 1
679
+ break
680
+ }
681
+ }
682
+ let prevEnd = start
683
+ while (prevEnd > 0 && isInlineSentenceBoundary(text[prevEnd - 1])) prevEnd -= 1
684
+ let prevStart = 0
685
+ for (let i = prevEnd - 1; i >= 0; i -= 1) {
686
+ if (isInlineSentenceBoundary(text[i])) {
687
+ prevStart = i + 1
688
+ break
689
+ }
690
+ }
691
+ return { start, prevStart, prevEnd }
692
+ }
693
+
694
+ /** 「其它」 is a word, not a pronoun: skip it and use the real occurrence. */
695
+ function lastInlineReferenceIndex(text: string, token: string): number {
696
+ let index = text.lastIndexOf(token)
697
+ while (index > 0 && token === '它' && text[index - 1] === '其') {
698
+ index = text.lastIndexOf(token, index - 1)
699
+ }
700
+ return index
701
+ }
702
+
703
+ export function resolvePronounAntecedentInline(token: string, taskText: string): AntecedentResult | null {
704
+ const text = String(taskText ?? '')
705
+ if (!text || text.length > MAX_TASK_ANCHOR_CHARS) return null
706
+ const index = lastInlineReferenceIndex(text, token)
707
+ if (index <= 0) return null
708
+ const bounds = inlineSentenceBounds(text, index)
709
+ const current = findExplicitEntity(text.slice(bounds.start, index))
710
+ if (current) return current
711
+ if (bounds.prevEnd > bounds.prevStart) {
712
+ const previous = findExplicitEntity(text.slice(bounds.prevStart, bounds.prevEnd))
713
+ if (previous) return previous
714
+ }
715
+ return null
716
+ }
717
+
718
+ /**
719
+ * [P0-2c] Decide whether a task is missing information the user must supply.
720
+ *
721
+ * MS2's four clarify cases (T05-04/09/13/20) were planned and dispatched anyway.
722
+ * Each failed for a *checkable* reason, so each gets a deterministic rule instead
723
+ * of a vibe:
724
+ *
725
+ * C1 bare agreement — the text is an answer to a question the model never saw
726
+ * (「同意移入」) and carries an identifier it never defines (R-W5-01).
727
+ * C2 dangling artifact — an internal reference (T4 草稿, W5) that is not defined
728
+ * in the task and not present in the conversation.
729
+ * C3 missing target — a forecast/trend request with no identifiable subject
730
+ * (「准确预测11月全月详细、具体走势」: which instrument? which year?).
731
+ * C4 missing UI object — a display change (折叠/展开/按钮…) that names no surface
732
+ * (左侧栏/截图/插件…), so any implementation would be a guess.
733
+ */
734
+ export function auditClarifyNeed(
735
+ taskText: unknown,
736
+ conversationContext = '',
737
+ ): { needed: boolean; rule: string; reason: string; question: string } {
738
+ const text = String(taskText ?? '').trim()
739
+ const conversation = String(conversationContext ?? '')
740
+ if (!text) return { needed: false, rule: '', reason: '', question: '' }
741
+ const both = text + '\n' + conversation
742
+
743
+ const AGREEMENT = /(?:^|[。;;!!\n])\s*(?:同意|赞成|可以|好的|没问题|就按|按你说的|确认)/
744
+ // No trailing \b: a CJK char is a non-word char, so 「T4 草稿」 has no word
745
+ // boundary after 稿 and the id would silently never match.
746
+ const DANGLING_ID = /(?:R-[A-Z]{1,4}-\d{1,4}|W\d{1,3}\b|T\d{1,3}\s*草稿)/
747
+ if (AGREEMENT.test(text) && (DANGLING_ID.test(text) || text.length <= 24) && !DANGLING_ID.test(conversation)) {
748
+ return {
749
+ needed: true,
750
+ rule: 'C1',
751
+ reason: '任务只是对上文问题的表态,且引用了任务里没有定义的编号,缺上文',
752
+ question: '你这句话是在回答哪个问题?请把上文的问题、或你要「同意/移入」的具体对象说清楚。',
753
+ }
754
+ }
755
+ const dangling = text.match(DANGLING_ID)
756
+ if (dangling && !conversation.includes(dangling[0])) {
757
+ return {
758
+ needed: true,
759
+ rule: 'C2',
760
+ reason: '任务引用了「' + dangling[0] + '」这一内部编号/草稿,但任务原文没有定义它,也找不到上文',
761
+ question: '「' + dangling[0] + '」指的是什么?请给出文件路径、链接或把内容贴进来。',
762
+ }
763
+ }
764
+ const FORECAST = /(预测|预判|走势|涨跌|行情)/
765
+ const SUBJECT = /(?:\d{6}|[A-Z]{2,}\d+|[「『“"《][^」』”"》]{2,20}[」』”"》])/
766
+ // The missing subject may already be named in the conversation (「它走势如何」 after
767
+ // the user quoted a ticker). Only the task's own words make it a forecast request.
768
+ if (FORECAST.test(text) && !SUBJECT.test(both)) {
769
+ return {
770
+ needed: true,
771
+ rule: 'C3',
772
+ reason: '要求预测走势,但任务里没有可识别标的(股票代码/名称),也没有年份,缺关键输入',
773
+ question: '要预测哪只标的(股票代码或名称)?看哪个时间段?',
774
+ }
775
+ }
776
+ const UI_VERB = /(折叠|展开|按钮|显示|布局|样式|颜色|排序|置顶|收起)/
777
+ // 红圈/红框/圈出 name a surface the same way 截图 does: the user has pointed at
778
+ // something concrete. Without them 「把红圈处改为默认收起」 was C4-blocked even
779
+ // though the sentence is unambiguous (caught by department-fit.test.ts).
780
+ const UI_OBJECT = /(左侧栏|右侧栏|侧边栏|侧栏|面板|对话框|弹窗|菜单|工具栏|页面|截图|画圈|红圈|红框|圈出|插件|顶栏|底栏|任务进度)/
781
+ // Same rule as C3: 「把它改成默认收起」 is not missing a surface when the previous
782
+ // turn said 「截图红圈处的分步进度」. The verb must be in the task, the object may
783
+ // come from either side (plan-anchor.test.ts 'strict mode blocks…' covers this).
784
+ if (UI_VERB.test(text) && !UI_OBJECT.test(both)) {
785
+ return {
786
+ needed: true,
787
+ rule: 'C4',
788
+ reason: '要求改动界面显示,但没有说明改哪个界面/哪个板块,缺指代对象',
789
+ question: '要改的是哪个界面/哪个板块?(例如左侧栏、任务进度面板、某个按钮;有截图更好)',
790
+ }
791
+ }
792
+ return { needed: false, rule: '', reason: '', question: '' }
793
+ }
794
+
562
795
  /**
563
796
  * Split one clause into candidate noun phrases.
564
797
  *
@@ -1010,13 +1243,22 @@ export function auditTaskUnderstanding(plan: any, context: PlanAuditContext = {}
1010
1243
  const conversation = typeof context.conversationContext === 'string' ? context.conversationContext : ''
1011
1244
  const resolvedByContext = extracted.references.map((reference) => {
1012
1245
  if (reference.resolved) return reference
1013
- const found = resolvePronounAntecedent(reference.token, conversation)
1246
+ const fromConversation = resolvePronounAntecedent(reference.token, conversation)
1247
+ const found = fromConversation ?? resolvePronounAntecedentInline(reference.token, taskText)
1014
1248
  if (!found) return reference
1015
1249
  // Option letters are resolved only when the conversation lists that option
1016
1250
  // as a listed choice ("A 方案" / "B 选项"), not a bare letter in a word.
1251
+ // Task-text entities never satisfy this rule on their own: the option must
1252
+ // be defined where the user chose it, i.e. in the conversation.
1017
1253
  const listedOption = new RegExp('(?:^|[^A-Za-z])' + reference.token + '\\s*(?:方案|选项)')
1018
1254
  if (/^[A-D]$/.test(reference.token) && !listedOption.test(conversation)) return reference
1019
- return { ...reference, resolved: true, resolvedBy: 'context' as const, antecedent: found.antecedent }
1255
+ /*
1256
+ * [T3] Record where the referent came from. Reusing 'context' for an
1257
+ * antecedent found inside the task text would misreport an empty
1258
+ * conversation as the source, so the audit keeps the two apart.
1259
+ */
1260
+ const resolvedBy: TaskReference['resolvedBy'] = fromConversation ? 'context' : 'task-text'
1261
+ return { ...reference, resolved: true, resolvedBy, antecedent: found.antecedent }
1020
1262
  })
1021
1263
  const unresolved = resolvedByContext.filter((reference) => !reference.resolved)
1022
1264
 
@@ -1110,6 +1352,14 @@ export function validatePlanContext(plan: any, context: PlanAuditContext = {}):
1110
1352
  if (audit.stage3.verdict === 'needs-clarification') {
1111
1353
  errors.push(`CLARIFY: ${audit.stage3.reasons.find((reason) => reason.includes('自相矛盾')) ?? '用户要求存在矛盾,必须先向用户确认'}`)
1112
1354
  }
1355
+ /*
1356
+ * [P0-2c] Missing inputs must stop the plan before any department agent runs:
1357
+ * MS2 T05-04/09/13/20 were all planned and dispatched with the key input absent.
1358
+ */
1359
+ const clarify = auditClarifyNeed(context.taskText ?? audit.anchor?.text ?? '', context.conversationContext ?? '')
1360
+ if (clarify.needed) {
1361
+ errors.push('CLARIFY: ' + clarify.reason + '(规则 ' + clarify.rule + ')')
1362
+ }
1113
1363
  if (audit.stage3.verdict === 'needs-context') {
1114
1364
  errors.push(`CONTEXT: ${audit.stage3.reasons.find((reason) => reason.includes('指代')) ?? '任务含指代但在最近对话中找不到先行词,必须先向用户确认'}`)
1115
1365
  }