dsh-workplan 2.0.2 → 2.0.4

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,83 @@
1
+ ## 2.0.4 — 2026-11-05
2
+
3
+ **修复「子 Agent 干完活却交不了差」的四条判定缺陷,并给交互式会话收尾加上「放行但留痕」。**
4
+
5
+ ### 一、问题与证据链
6
+
7
+ 用户 2026-11-05 报告:计划里 5 个子 Agent 的产物都已在磁盘上,结果却被判「结果块无法解析」「未提供结构化证据块」,交付门禁反复重开;同一会话里还出现「子任务没完成就先给结论」。
8
+
9
+ 逐条核对子会话原始回执后确认,这不是模型没干活,而是四处判定把「格式瑕疵」当成了「没有证据」:
10
+
11
+ | # | 事实 | 证据 |
12
+ |---|---|---|
13
+ | 1 | 3 份回执**结尾各少一个 `}`**,补一个括号后 `JSON.parse` 立即通过 | 逐字符括号扫描;补后解析成功 |
14
+ | 2 | 2 份回执 JSON 合法,只是**漏写 `WORKPLAN_EVIDENCE` 标记**(放在代码块里) | 旧实现判「未提供证据块」,与事实相反 |
15
+ | 3 | 旧验收只做 `实际文本.includes(声明原文)`,同义改写一律判「没回应」 | `acceptanceCoverage()` |
16
+ | 4 | `reported` 状态没有 `done` 出边,复核已回报的行必撞「非法闭环迁移」 | 状态迁移表 |
17
+ | 5 | 交互式会话 steer 上限 2 次,用尽后静默放行,用户看不到「这次是没做完就收尾」 | `onTurnStopping` |
18
+
19
+ ### 二、改了什么
20
+
21
+ - **回执解析有界修复**:新增 `closeOpenJson` / `lastSafeCut` / `repairEvidenceJson`,只在结构层补括号与截断,不补内容;修不好的仍如实报错,并给出「只保留 status/summary/acceptance/artifacts/needs 后重发」的下一步。
22
+ - **无标记回执可认领**:新增 `rescueEvidenceFromFence()`,仅在缺规定标记时,从代码块中认领「有 `status` 且至少带一个证据字段」的对象;计划载荷、配置片段这类普通 JSON 不会被误认。
23
+ - **验收匹配放宽到语义层**:新增字符二元组 Dice 相似度与否定词一致性校验——同义改写、语序调整算同一条;**删掉「不得」这类否定词,或只抄前半句,仍然判不覆盖**。
24
+ - **状态机补齐**:已回报的行再次交付时保持 `reported`,不再强写 `done`,也不再报非法迁移。
25
+ - **交互式收尾「放行但留痕」(方案 B)**:steer 用尽时不再沉默 `return`,而是把 `releasedIncomplete`(轮次、进度、未完成项)记入计划状态、向会话追加一条 notice、并写一条 warn 日志;三处使用同一组数字。headless 场景维持原有 `WORKPLAN_INCOMPLETE` 硬失败语义。
26
+ - **错误文案分档**:截断、少闭合符、缺标记三种情况给出各自的修复指令,不再统一说「无法解析」。
27
+
28
+ ### 三、验证
29
+
30
+ - 新增 `tests/workplan-user-logic-204.test.ts`:13 条用例覆盖同义改写、部分回应、删否定词、只抄前半句、缺括号、缺标记、误认普通 JSON、已回报复核。其中「删否定词」「只抄前半句」两类假阳性由独立复核子 Agent 用 18 条真实差异对复现后补入。
31
+ - `npm test`:**562 条用例全过,0 失败**。
32
+ - `npm run build` 重新生成 `lib/`、`dist/`、`client.js`,与 `src/` 同步。
33
+ - `npm pack --dry-run` 文件清单核对:不含 `.backups`、`node_modules`、测试临时文件与任何凭证。
34
+
35
+ ### 四、范围说明(重要)
36
+
37
+ 本版本**不含**官方 `@deepseek-ai/dsh-client-ui-chat` 的界面文案改动。那条改动(「已完成,用时 」→「本轮过程已完成,用时 」)落在第三方包内部文件,属官方 DSH 安装目录,不随本包分发;需要的话请按仓库文档中的说明自行替换,或等待上游修复。
38
+
39
+ ### 五、发布
40
+
41
+ - npm:`dsh-workplan@2.0.4`
42
+ - GitHub Release:`v2.0.4`,附 `dsh-workplan-2.0.4.tgz` 制品与 SHA256
43
+ - 索引源(dsh-plugin-catalog 链路):条目 tarball 指向 `v2.0.4` Release,由上游 CI 生成 catalog
44
+
45
+ ## 2.0.3 — 2026-11-05
46
+
47
+ **修复「官方 `/goal` 目标指令会让 dsh-workplan 自动分解永远不触发」的真实缺陷:goal 第一轮现在作为合法任务入口参与自动分解;已有进行中计划时 goal 轮次绝不抢跑。**
48
+
49
+ ### 一、问题与证据链
50
+
51
+ 用户 2026-11-05 报告:使用官方 DeepSeek Harness 的「目标 goal」指令后,dsh-workplan 的自动任务分解似乎不会触发。核查代码后确认这不是猜测,而是一条可复现的契约缺口:
52
+
53
+ | # | 事实 | 证据位置 |
54
+ |---|---|---|
55
+ | 1 | `/goal <objective>` 命令只写 goal 领域状态,**不产生** `user/message` | `@deepseek-ai/dsh-command-goal` 的 `create` 分支 |
56
+ | 2 | goal 的自动续跑轮次由 round driver 以 `source.kind = "goal"` 的 user 消息送达,文本形如 `<goal_round>Objective: "…"</goal_round>` | `@deepseek-ai/dsh-goal-round-driver/lib/index.js` 的 `renderGoalRoundPrompt` 与 `createUserMessage` |
57
+ | 3 | 2.0.2 的 `humanMessages()` 只接受 `source.kind === 'user'` 或未标记的消息 | `src/runtime.ts#humanMessages` |
58
+ | 4 | `maybePlan()` 在 `human.length === 0` 时直接返回,不进入规划 | `src/runtime.ts#maybePlan` |
59
+
60
+ 1+2+3+4 合并后的结论:如果任务是通过 `/goal` 设置的,整条 goal 生命周期内都不存在「人类消息」,插件永远不会自动分解该任务。人工消息路径(普通输入框任务)不受影响。
61
+
62
+ ### 二、改了什么
63
+
64
+ - 新增 `goalRoundPlanningTask(ctx, payload, existing)`:只接受 `source.kind === 'goal'` 且 `round === 1` 的消息作为自动分解入口。
65
+ - `maybePlan()` 在没有任何人工消息时改走该入口;任务文本优先级为:`goals` 领域服务的结构化 `objective` → 从官方 `<goal_round>` 信封解析 JSON objective → 整条消息原文。
66
+ - 防抢跑:会话里存在进行中计划(`executing` / `paused` / `pending` / `verification` 等)时,goal 轮次直接放行不建计划;`done` / `ended` / `cancelled` / `superseded` / `degraded` / `clarify` 属于历史记录,不拦新任务。
67
+ - 人工消息路径、`humanMessages()` 的既有语义、执行中变更(changeRequest)与 replan 规则全部保持不变。
68
+
69
+ ### 三、验证
70
+
71
+ - 新增 `tests/goal-round-planning.test.ts`:7 条断言覆盖 round 1/round 2、goals 服务优先、信封解析、无 objective 兜底、进行中计划防抢跑、历史终态放行。
72
+ - `npm test`:553 条用例全过;`npm run check`(tsc --noEmit)退出码 0。
73
+ - `npm run build` 重新生成 `lib/`、`dist/`、`client.js`,与 `src/` 同步。
74
+
75
+ ### 四、发布
76
+
77
+ - npm:`dsh-workplan@2.0.3`
78
+ - GitHub Release:`v2.0.3`,附 `dsh-workplan-2.0.3.tgz` 制品
79
+ - 索引源(dsh-plugin-catalog 链路):条目 tarball 指向 `v2.0.3` Release,等待上游 CI 生成 catalog
80
+
1
81
  ## 2.0.2 — 2026-11-05
2
82
 
3
83
  **更正「第一、二阶段禁用 dsh-workplan 插件」的适用范围:这条只适用于 2026-11-05 本次优化会话,不是对所有后续会话的永久产品规则。2.0.2 起,提示词、工具描述、README 与协作文档不再声明全局禁用;三阶段工作法与「验证工具缺前两阶段证据返回 PHASE_GATE」的证据门禁保持不变。**
package/README.en.md CHANGED
@@ -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@2.0.2
83
+ dsh plugin --profile web add dsh-workplan@2.0.4
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-2.0.2-blue.svg)](https://github.com/abbaababa/dsh-workplan/releases/tag/v2.0.2)
6
+ [![version](https://img.shields.io/badge/version-2.0.3-blue.svg)](https://github.com/abbaababa/dsh-workplan/releases/tag/v2.0.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@2.0.2
72
+ dsh plugin --profile web add dsh-workplan@2.0.4
73
73
  ```
74
74
 
75
75
  装完**重启一次 DSH Web**(或重新载入当前页面)让插件生效。
@@ -0,0 +1,87 @@
1
+ # dsh-workplan 2.0.2 发布记录(可复核)
2
+
3
+ - 发布时间:2026-11-05 13:45–14:10(Asia/Shanghai)
4
+ - 版本:**2.0.2**(`package.json` / `package-lock.json` 两处 / `src/host.ts#meta.version` / CHANGELOG / README 两份安装命令,由 `tests/version-sync.test.ts` 断言一致)
5
+ - 主题:更正「第一、二阶段禁用 dsh-workplan 插件」的适用范围——只适用于 2026-11-05 本次优化会话,不是对所有后续会话的永久产品规则
6
+
7
+ ## 1. 为什么发 2.0.2
8
+
9
+ 用户在 2.0.1 发布后澄清:原要求 4「第一、二阶段禁用 dsh-workplan 插件」是**本次会话内**对优化过程的约束,不是要求插件对所有未来会话禁用。1.13.0 起该条被写成产品级规则(子 Agent 提示词、`dsh_workplan_verify` 描述、运行时报错、README、协作文档),属于对需求范围的误读;2.0.2 全面更正措辞与说明,三阶段契约与自我学习机制不变。
10
+
11
+ ## 2. 提交与 tag
12
+
13
+ | 项 | 值 |
14
+ |---|---|
15
+ | 发布提交 | `17707511cafe2a9772eb630d3d8ccce1c7a22ccd` |
16
+ | commit 标题 | `Release 2.0.2: 更正「第一、二阶段禁用插件」的适用范围(仅 2026-11-05 本次会话,非永久规则)` |
17
+ | tag | `v2.0.2`(annotated,tag 对象 `ae402a8441267983195257f35ecc30644a45d281`) |
18
+ | tag → 提交 | `git rev-list -n 1 v2.0.2` = `17707511cafe2a9772eb630d3d8ccce1c7a22ccd`(一致) |
19
+ | 远端 | `main` 已推送 `ccd362a..1770751`;`git ls-remote --tags origin v2.0.2` 返回 `refs/tags/v2.0.2` |
20
+
21
+ ## 3. 干净克隆门禁(tag 构建)
22
+
23
+ 在 `/tmp/dsh-workplan-release-2.0.2`(`git clone --depth 1 --branch v2.0.2`)执行:
24
+
25
+ | 命令 | 结果 |
26
+ |---|---|
27
+ | `npm ci` | 退出 0 |
28
+ | `npm run check` | 退出 0(`tsc -p tsconfig.json --noEmit`) |
29
+ | `npm test` | **tests 546 / pass 546 / fail 0**,退出 0 |
30
+ | `npm pack` | `dsh-workplan-2.0.2.tgz`,**1,088,610 B**,sha256 `5e9dcc26a0e1ed204073ac0a1bf9ebc71b43403a1cd50a9ef68925999020f7f2` |
31
+
32
+ 包清单 100 个文件;含 `lib/lessons.js`、`docs/release-notes-2.0.2.md`,`version` 为 2.0.2。
33
+
34
+ ## 4. GitHub Release
35
+
36
+ - URL:https://github.com/abbaababa/dsh-workplan/releases/tag/v2.0.2
37
+ - 资产:`dsh-workplan-2.0.2.tgz`,state `uploaded`,1,088,610 B
38
+ - 资产 digest(GitHub API 返回):`sha256:5e9dcc26a0e1ed204073ac0a1bf9ebc71b43403a1cd50a9ef68925999020f7f2`(与本地 `shasum -a 256` 一致)
39
+
40
+ ## 5. npm 发布
41
+
42
+ - 2026-11-05 14:02 在干净克隆执行 `npm publish`,输出 `+ dsh-workplan@2.0.2`;注册表提示进入处理队列。
43
+ - 复核口径:`npm view dsh-workplan dist-tags version` 与 `GET https://registry.npmjs.org/dsh-workplan/2.0.2` 双证据(2.0.1 的经验:处理需数分钟,期间重复投递会得到 E409)。
44
+ - 发布结果:**2026-11-05 14:08 注册表可见**——`npm view dsh-workplan dist-tags version` 返回 `{ latest: '2.0.2' }`,`GET https://registry.npmjs.org/dsh-workplan/2.0.2` 返回 200。
45
+ - 安装冒烟(npm 公开包):`/tmp/dsh-wp-install-2.0.2` 执行 `npm i dsh-workplan@2.0.2` 后核对——version 2.0.2、`lib/lessons.js` 存在、`lib/three-phase.js` 已不含「阶段一、二:dsh-workplan 插件禁用」、`PHASE_GATE` 与「缺少 planning / execution 证据时返回 PHASE_GATE」文案保留、注册工具 11 个。
46
+
47
+ ## 6. 索引源(awesome-dsh-plugin)
48
+
49
+ | 项 | 值 |
50
+ |---|---|
51
+ | PR | https://github.com/awesome-dsh-plugin/awesome-dsh-plugin/pull/12201 |
52
+ | 条目提交 | `377bb700b49b7eb447270132540ea02f77bc1555` |
53
+ | 分支 | `abbaababa:bump-dsh-workplan-2.0.1`(PR 内已更新为 2.0.2) |
54
+ | 变更 | `data/plugins/abbaababa__dsh-workplan.yml` 的 `tarball` 指向 `v2.0.2` Release 资产 |
55
+ | 校验 | 条目 YAML 通过 `js-yaml` 解析;`tarball` 为 GitHub Release 托管 URL;`package.json` 声明 `dsh.bundle` |
56
+
57
+ ## 7. 本次改了什么(可复核)
58
+
59
+ | 文件 | 变更 |
60
+ |---|---|
61
+ | `src/three-phase.ts` | 提示词删除「阶段一、二:dsh-workplan 插件禁用」,改为「阶段一、二写全证据;调用 verify 会因缺少前两阶段证据返回 PHASE_GATE(证据门禁,不是禁用插件)」;头部注释同步 |
62
+ | `src/host.ts` | `dsh_workplan_verify` 描述由「阶段一、二禁用本插件」改为「缺少 planning / execution 证据时返回 PHASE_GATE 与待补项」 |
63
+ | `src/runtime.ts` | `PHASE_GATE` 报错文案由「插件在阶段一、二禁用」改为「阶段三核验缺少前两阶段证据」 |
64
+ | `README.md` / `README.en.md` | 增加 2.0.2 更正说明:该约束仅适用于本次会话;主 Agent 任何阶段都可用计划/派发/查询/改判工具 |
65
+ | `docs/collaboration.md`、`docs/cc/AVA-VULNERABILITY-ANALYSIS.md` | 表格与措辞由「禁用」改为「证据门禁」,并加 2.0.2 更正说明 |
66
+ | `tests/three-phase.test.ts` | 断言提示词不再包含「插件禁用」;同时继续断言阶段三门禁与 `PHASE_GATE` |
67
+ | `CHANGELOG.md`、`docs/release-notes-2.0.2.md` | 新增 2.0.2 条目与发布说明;2.0.1 条目加勘误 |
68
+
69
+ ## 8. 未变的部分
70
+
71
+ - 三阶段「规划 → 执行 → 验证」仍是产品功能;完成判定仍要求 `phases` 齐全。
72
+ - `dsh_workplan_verify` 仍只接受三阶段齐全的证据;缺 planning/execution 仍返回 `PHASE_GATE`。
73
+ - 阶段三复盘与永久教训记忆机制完全不变;工具面仍是 11 个。
74
+
75
+ ## 9. 复核附录
76
+
77
+ ```bash
78
+ # 版本与 tag
79
+ cd plugins/dsh-workplan && git rev-parse HEAD && git rev-list -n 1 v2.0.2
80
+ # 干净克隆门禁
81
+ git clone --depth 1 --branch v2.0.2 git@github.com:abbaababa/dsh-workplan.git /tmp/dsh-workplan-release-2.0.2
82
+ cd /tmp/dsh-workplan-release-2.0.2 && npm ci && npm run check && npm test && npm pack
83
+ # 发布核对
84
+ npm view dsh-workplan dist-tags version
85
+ gh api repos/abbaababa/dsh-workplan/releases/tags/v2.0.2 --jq '.assets[] | {name, size, state, digest}'
86
+ gh pr view 12201 --repo awesome-dsh-plugin/awesome-dsh-plugin
87
+ ```
@@ -0,0 +1,47 @@
1
+ # Release record — dsh-workplan 2.0.3 (2026-11-05)
2
+
3
+ ## 1. 变更主题
4
+
5
+ 修复官方 DeepSeek Harness「`/goal` 目标指令」导致自动任务分解永不触发的缺陷。
6
+
7
+ 根因证据链:
8
+
9
+ 1. `/goal <objective>` 只写 goal 领域状态,不产生 `user/message`(`@deepseek-ai/dsh-command-goal` create 分支)。
10
+ 2. goal 自动续跑轮次由 `@deepseek-ai/dsh-goal-round-driver` 以 `source.kind = 'goal'`、`round >= 1` 的 user 消息送达(`renderGoalRoundPrompt` + `createUserMessage`)。
11
+ 3. 2.0.2 的 `src/runtime.ts#humanMessages` 只接受 `source.kind === 'user'` 或省略的消息。
12
+ 4. `src/runtime.ts#maybePlan` 在 `human.length === 0` 时直接返回。
13
+
14
+ 修复:`goalRoundPlanningTask()` 接受 goal 第一轮;进行中计划存在时不抢跑;任务文本优先取 `goals` 服务 objective,其次解析 `<goal_round>` 信封,最后用原文。
15
+
16
+ ## 2. 版本与提交
17
+
18
+ | 项目 | 值 |
19
+ |---|---|
20
+ | package.json version | 2.0.3 |
21
+ | meta.version(src/host.ts) | 2.0.3 |
22
+ | git commit | 7e25f07 |
23
+ | git tag | v2.0.3 |
24
+
25
+ ## 3. 验证
26
+
27
+ - `npm run check`:退出码 0(tsc --noEmit)。
28
+ - `npm test`:553 条用例全过(含新增 `tests/goal-round-planning.test.ts` 7 条)。
29
+ - `npm run build`:`lib/`、`dist/`、`client.js` 与 `src/` 同步;`lib/host.js` 内 version 为 2.0.3。
30
+
31
+ ## 4. 发布渠道
32
+
33
+ | 渠道 | 状态 | 证据 |
34
+ |---|---|---|
35
+ | npm | 已发布 | `npm view dsh-workplan@latest version` → 2.0.3 |
36
+ | GitHub Release | 已发布 | https://github.com/abbaababa/dsh-workplan/releases/tag/v2.0.3 |
37
+ | Release 制品 | 已上传 | `dsh-workplan-2.0.3.tgz` sha256 `e6bdb13f31fde51f7a370abea5f1f734f32d35fd4b8ed7431aae21468dda50df`(本地与下载一致) |
38
+ | 索引源(awesome-dsh-plugin → dsh-plugin-catalog) | PR 待合并 | https://github.com/awesome-dsh-plugin/awesome-dsh-plugin/pull/12316(tarball 已指向 v2.0.3;catalog npm 发版由上游 CI 触发) |
39
+
40
+ ## 5. 复验命令
41
+
42
+ ```bash
43
+ npm view dsh-workplan@latest version
44
+ curl -sIL -o /dev/null -w '%{http_code}\n' \
45
+ https://github.com/abbaababa/dsh-workplan/releases/download/v2.0.3/dsh-workplan-2.0.3.tgz
46
+ curl -s https://raw.githubusercontent.com/awesome-dsh-plugin/awesome-dsh-plugin/main/data/plugins/abbaababa__dsh-workplan.yml | grep tarball
47
+ ```
package/lib/host.js CHANGED
@@ -1363,7 +1363,7 @@ export function apply(ctx, config = {}) {
1363
1363
  }
1364
1364
  export const meta = {
1365
1365
  name,
1366
- version: '2.0.2',
1366
+ version: '2.0.4',
1367
1367
  promptOrder: PROMPT_ORDER,
1368
1368
  routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
1369
1369
  };
package/lib/plan.js CHANGED
@@ -1666,6 +1666,53 @@ export function normaliseCriterion(value) {
1666
1666
  .replace(/[\s,。;、,.;::!!??"'“”‘’()()\[\]【】《》<>]/g, '')
1667
1667
  .replace(/^(必须|需要|应当|应该|请|务必)/, '');
1668
1668
  }
1669
+ /**
1670
+ * [2.0.4] 两条验收描述的相似度(0–1)。
1671
+ *
1672
+ * 用字符二元组 Dice 系数而不是编辑距离:中文短句里「逐项」「一致性」这类
1673
+ * 词被增删时,二元组重合度比字符级编辑距离更接近人的判断,也不需要引入
1674
+ * 任何依赖。空串与单字返回 0,交给调用方的长度门槛处理。
1675
+ */
1676
+ export function criterionSimilarity(a, b) {
1677
+ if (!a || !b)
1678
+ return 0;
1679
+ if (a === b)
1680
+ return 1;
1681
+ const grams = (text) => {
1682
+ const chars = Array.from(text);
1683
+ const out = new Map();
1684
+ for (let i = 0; i + 1 < chars.length; i += 1) {
1685
+ const gram = chars[i] + chars[i + 1];
1686
+ out.set(gram, (out.get(gram) ?? 0) + 1);
1687
+ }
1688
+ return out;
1689
+ };
1690
+ const left = grams(a);
1691
+ const right = grams(b);
1692
+ let leftTotal = 0;
1693
+ let rightTotal = 0;
1694
+ for (const count of left.values())
1695
+ leftTotal += count;
1696
+ for (const count of right.values())
1697
+ rightTotal += count;
1698
+ if (leftTotal === 0 || rightTotal === 0)
1699
+ return 0;
1700
+ let overlap = 0;
1701
+ for (const [gram, count] of left) {
1702
+ overlap += Math.min(count, right.get(gram) ?? 0);
1703
+ }
1704
+ return (2 * overlap) / (leftTotal + rightTotal);
1705
+ }
1706
+ /**
1707
+ * [2.0.4] 验收文本里是否带否定/禁止语气。
1708
+ *
1709
+ * 「不得超过 5%」与「超过 5%」的二元组相似度可以很高,但语义相反。
1710
+ * 相似度只用来判「是不是同一条」,判不了「是不是同一个约束」,所以要单独
1711
+ * 把否定词拎出来比较:两边不一致就直接判不覆盖,不交给阈值碰运气。
1712
+ */
1713
+ export function hasNegation(text) {
1714
+ return /不得|禁止|严禁|不能|不可|不允许|不应|无需|避免|排除|不超过|不低于|不高于|不等于|未通过|未完成/.test(String(text ?? ''));
1715
+ }
1669
1716
  export function acceptanceCoverage(expected, actual) {
1670
1717
  const want = (Array.isArray(expected) ? expected : []).map(normaliseCriterion).filter(Boolean);
1671
1718
  const got = (Array.isArray(actual) ? actual : [])
@@ -1693,7 +1740,28 @@ export function acceptanceCoverage(expected, actual) {
1693
1740
  return true;
1694
1741
  if (Math.min(row.length, criterion.length) < 6)
1695
1742
  return false;
1696
- return row.includes(criterion);
1743
+ if (row.includes(criterion))
1744
+ return true;
1745
+ /*
1746
+ * [2.0.4] 同义改写必须算同一条验收(用户 m00302 / 2026-11-05)。
1747
+ *
1748
+ * 1.12.0 只认「证据原文包含计划原文」,于是主 Agent 把
1749
+ * 「数字与 T9 逐项一致」写成「数字与 T9 一致」就会被判成「没回应」,
1750
+ * 交付门禁反复重开。这不是证据不合格,是**字面匹配**在惩罚正常表述。
1751
+ *
1752
+ * [2.0.4] 补充规则(阈值与注释一致,不再出现 2/3 对 0.65、0.75 对 0.70):
1753
+ * 1. 证据几乎抄全了计划原文(≥85%)→ 覆盖;
1754
+ * 2. 字符二元组 Dice 相似度 ≥ 0.70,且两边否定词状态一致 → 覆盖。
1755
+ * 否定词必须单独看:T4 用真实差异对复现出「删掉『不得超过』」这种
1756
+ * 改写会被纯相似度放过,那是把约束反过来的假阳性,必须挡住。
1757
+ * 只回应一半的情况(如「登录测试」对「登录测试与越权测试」,Dice 0.667)
1758
+ * 仍然不覆盖,Q6/U-16 的本意不变。
1759
+ */
1760
+ if (criterion.includes(row) && row.length / criterion.length >= 0.85)
1761
+ return true;
1762
+ if (hasNegation(criterion) !== hasNegation(row))
1763
+ return false;
1764
+ return criterionSimilarity(row, criterion) >= 0.7;
1697
1765
  });
1698
1766
  if (!covered)
1699
1767
  missing.push(String((Array.isArray(expected) ? expected : [])[index] ?? criterion));
@@ -1844,25 +1912,178 @@ function readEvidenceOptions(value) {
1844
1912
  * A malformed block is reported as such instead of being silently ignored —
1845
1913
  * "cannot tell" must never default to "done".
1846
1914
  */
1915
+ /**
1916
+ * [2.0.4] 把一段被截断的 JSON 补成可解析的对象(用户 m00302)。
1917
+ *
1918
+ * 事故(T1 报告 §2.3 复核后的真实形态):5 个子 Agent 的产物都已落盘,
1919
+ * 其中 3 项(T4/T6/T10)的回执**结尾各少一个 `}`**,2 项(T5/T7)JSON 合法
1920
+ * 但漏写规定标记。旧实现把前者判成「无法解析」、后者判成「未提供证据块」,
1921
+ * 证据在盘上,判定却拿不到,只能人工兜底。
1922
+ *
1923
+ * 注意:早期口头归因写的「内容太长被截断」是错的——会话里 3000 字符是
1924
+ * 结果写回时的展示上限,不是解析输入;同样被判 done 的 T1/T2/T3 也被截到
1925
+ * 3000 字却解析正常。这里做的是**有界修复**,不是放宽验收:
1926
+ * - 只补结构(收尾引号、闭合括号),绝不补内容,也不改任何字段值;
1927
+ * - 修复后的对象仍然走完整的 status/acceptance/phases 门禁;
1928
+ * - 修不好就如实返回 null,绝不用「猜」的内容顶替。
1929
+ */
1930
+ function closeOpenJson(text) {
1931
+ const chars = Array.from(text);
1932
+ const stack = [];
1933
+ let inString = false;
1934
+ let escaped = false;
1935
+ for (const char of chars) {
1936
+ if (inString) {
1937
+ if (escaped)
1938
+ escaped = false;
1939
+ else if (char === '\\')
1940
+ escaped = true;
1941
+ else if (char === '"')
1942
+ inString = false;
1943
+ continue;
1944
+ }
1945
+ if (char === '"')
1946
+ inString = true;
1947
+ else if (char === '{')
1948
+ stack.push('}');
1949
+ else if (char === '[')
1950
+ stack.push(']');
1951
+ else if (char === '}' || char === ']') {
1952
+ if (stack.pop() !== char)
1953
+ return null;
1954
+ }
1955
+ }
1956
+ let closed = text;
1957
+ if (inString)
1958
+ closed += '"';
1959
+ while (stack.length > 0)
1960
+ closed += stack.pop();
1961
+ return closed;
1962
+ }
1963
+ /** 最后一个「切掉它之后仍可能闭合」的位置:字符串外的逗号或左括号。 */
1964
+ function lastSafeCut(text) {
1965
+ const chars = Array.from(text);
1966
+ let inString = false;
1967
+ let escaped = false;
1968
+ let cut = -1;
1969
+ for (let i = 0; i < chars.length; i += 1) {
1970
+ const char = chars[i];
1971
+ if (inString) {
1972
+ if (escaped)
1973
+ escaped = false;
1974
+ else if (char === '\\')
1975
+ escaped = true;
1976
+ else if (char === '"')
1977
+ inString = false;
1978
+ continue;
1979
+ }
1980
+ if (char === '"')
1981
+ inString = true;
1982
+ else if (char === ',' || char === '{' || char === '[')
1983
+ cut = inString ? cut : i;
1984
+ }
1985
+ return cut;
1986
+ }
1987
+ export function repairEvidenceJson(text) {
1988
+ let body = String(text ?? '').trim();
1989
+ for (let attempt = 0; attempt < 24 && body.length > 0; attempt += 1) {
1990
+ const closed = closeOpenJson(body);
1991
+ if (closed) {
1992
+ try {
1993
+ const value = JSON.parse(closed);
1994
+ if (isRecord(value))
1995
+ return value;
1996
+ }
1997
+ catch {
1998
+ /* 继续往前切 */
1999
+ }
2000
+ }
2001
+ const cut = lastSafeCut(body);
2002
+ if (cut <= 0)
2003
+ return null;
2004
+ body = body.slice(0, cut);
2005
+ }
2006
+ return null;
2007
+ }
2008
+ /**
2009
+ * [2.0.4] 没写规定标记、但内容其实交齐了的回执(用户 m00302)。
2010
+ *
2011
+ * 子会话原文核查(T1 报告 §2.3)显示:T5/T7 的证据块 **JSON 完全合法**,
2012
+ * status/phases/acceptance/artifacts 一样不缺,只是被放进了 Markdown 代码块,
2013
+ * 没有写 `WORKPLAN_EVIDENCE:START/END`。旧实现直接判「结果块缺失」,把
2014
+ * 「格式没按规定」说成「没交作业」。
2015
+ *
2016
+ * 这里做的是**有界认领**:只认带 `status` 且至少还有一个证据字段的 JSON
2017
+ * 对象,绝不把任意 JSON(比如计划载荷、配置片段)当成回执。
2018
+ */
2019
+ export function rescueEvidenceFromFence(output) {
2020
+ const text = typeof output === 'string' ? output : '';
2021
+ if (!text.includes('{'))
2022
+ return null;
2023
+ const candidates = [];
2024
+ const fence = /```(?:json|JSON)?\s*\n([\s\S]*?)```/g;
2025
+ let match;
2026
+ while ((match = fence.exec(text)) !== null)
2027
+ candidates.push(match[1]);
2028
+ const first = text.indexOf('{');
2029
+ const last = text.lastIndexOf('}');
2030
+ if (first >= 0 && last > first)
2031
+ candidates.push(text.slice(first, last + 1));
2032
+ for (const candidate of candidates) {
2033
+ let value = null;
2034
+ try {
2035
+ value = JSON.parse(String(candidate).trim());
2036
+ }
2037
+ catch {
2038
+ value = repairEvidenceJson(String(candidate).trim());
2039
+ }
2040
+ if (!isRecord(value))
2041
+ continue;
2042
+ if (!EVIDENCE_STATUSES.includes(value.status))
2043
+ continue;
2044
+ const hasEvidence = Array.isArray(value.acceptance) || Array.isArray(value.artifacts)
2045
+ || Array.isArray(value.needs) || isRecord(value.phases) || typeof value.summary === 'string';
2046
+ if (!hasEvidence)
2047
+ continue;
2048
+ return value;
2049
+ }
2050
+ return null;
2051
+ }
1847
2052
  export function parseEvidenceBlock(output) {
1848
2053
  const text = typeof output === 'string' ? output : '';
1849
2054
  const begin = text.lastIndexOf(EVIDENCE_MARKER_BEGIN);
1850
- if (begin < 0)
1851
- return { found: false, malformed: false, truncated: false, payload: null, raw: '' };
1852
- const end = text.indexOf(EVIDENCE_MARKER_END, begin + EVIDENCE_MARKER_BEGIN.length);
1853
- if (end < 0)
1854
- return { found: true, malformed: true, truncated: false, payload: null, raw: '' };
1855
- const raw = text.slice(begin + EVIDENCE_MARKER_BEGIN.length, end).trim();
1856
- const truncated = raw.length > MAX_EVIDENCE_BLOCK_CHARS;
1857
- try {
1858
- const payload = JSON.parse(raw);
2055
+ if (begin < 0) {
2056
+ const rescued = rescueEvidenceFromFence(text);
2057
+ if (rescued) {
2058
+ return { found: true, malformed: false, truncated: false, repaired: false, rescued: true, payload: rescued, raw: '' };
2059
+ }
2060
+ return { found: false, malformed: false, truncated: false, repaired: false, rescued: false, payload: null, raw: '' };
2061
+ }
2062
+ const bodyStart = begin + EVIDENCE_MARKER_BEGIN.length;
2063
+ const end = text.indexOf(EVIDENCE_MARKER_END, bodyStart);
2064
+ /*
2065
+ * [2.0.4] 结束标记缺失 = 输出被截断,不是「格式错误」。
2066
+ *
2067
+ * 旧实现遇到这种情况直接判 malformed,还把 `truncated` 写成 false,于是
2068
+ * 上层拿到的是「无法解析」,看不出真正原因。现在先把标记之后的全部内容
2069
+ * 当作候选块,交给有界修复;修得回来就是可用证据,修不回来才报截断。
2070
+ */
2071
+ const raw = (end < 0 ? text.slice(bodyStart) : text.slice(bodyStart, end)).trim();
2072
+ const truncated = end < 0 || raw.length > MAX_EVIDENCE_BLOCK_CHARS;
2073
+ const accept = (payload, repaired) => {
1859
2074
  if (!isRecord(payload) || !EVIDENCE_STATUSES.includes(payload.status)) {
1860
- return { found: true, malformed: true, truncated, payload: null, raw };
2075
+ return { found: true, malformed: true, truncated, repaired, rescued: false, payload: null, raw };
1861
2076
  }
1862
- return { found: true, malformed: false, truncated, payload, raw };
2077
+ return { found: true, malformed: false, truncated, repaired, rescued: false, payload, raw };
2078
+ };
2079
+ try {
2080
+ return accept(JSON.parse(raw), false);
1863
2081
  }
1864
2082
  catch {
1865
- return { found: true, malformed: true, truncated, payload: null, raw };
2083
+ const repaired = repairEvidenceJson(raw);
2084
+ if (repaired)
2085
+ return accept(repaired, true);
2086
+ return { found: true, malformed: true, truncated, repaired: false, payload: null, raw };
1866
2087
  }
1867
2088
  }
1868
2089
  const BLOCKED_LINE = /^\s*(BLOCKED|受阻|无法完成)\s*[::]\s*/i;
@@ -1896,7 +2117,17 @@ export function adjudicateResult({ output, strict = true, expectedAcceptance = [
1896
2117
  acceptance: [],
1897
2118
  artifacts: [],
1898
2119
  needs: [],
1899
- error: '结果块无法解析,请主 Agent 核对',
2120
+ /*
2121
+ * [2.0.4] 失败信息必须能指导下一步动作(用户 m00302)。
2122
+ *
2123
+ * 「无法解析,请主 Agent 核对」把诊断责任推回给人:既不说是不是截断,
2124
+ * 也不说该重发还是该改格式,于是只能靠读原始输出猜。现在按截断/非法
2125
+ * 分档给出可执行提示。
2126
+ */
2127
+ error: parsed.truncated
2128
+ ? '结果块被截断(缺少结束标记或超过长度上限):请让该子 Agent 重新回报,'
2129
+ + '只保留 status/summary/acceptance/artifacts/needs 字段,删掉大段执行日志后重发'
2130
+ : '结果块 JSON 非法(不是截断):请检查引号、逗号与括号是否成对,修正后重新回报',
1900
2131
  };
1901
2132
  }
1902
2133
  if (!parsed.found) {
@@ -2551,8 +2782,22 @@ export function applyStatus(statuses, subtaskId, patch) {
2551
2782
  next.updatedBy = ['child', 'agent', 'system'].includes(patch.updatedBy) ? patch.updatedBy : 'system';
2552
2783
  if (patch.status === 'done') {
2553
2784
  next.progress = 100;
2554
- if (patch.closure === undefined)
2555
- next.closure = 'done';
2785
+ /*
2786
+ * [2.0.4] 「已回报」是事实,不是阶段(用户 m00302 / 2026-11-05)。
2787
+ *
2788
+ * `closure:'reported'` 的意思是「这条完成结果已经通过结果消息回报过」,
2789
+ * 它是交付门禁 `reportPending` 读的事实。主 Agent 事后复核证据、把
2790
+ * verification/acceptance 补齐时,status 仍然是 done —— 旧代码却把
2791
+ * closure 默认改回 `done`,于是撞上「非法闭环迁移:reported → done」,
2792
+ * 逼着人先写一次假的 blocked 再写 done。审计链被污染,界面还会短暂
2793
+ * 显示「受阻」。
2794
+ *
2795
+ * 现在:没有显式指定 closure 的复核写入,保留已回报事实;只有调用方
2796
+ * 明确要把它退回未回报时,迁移表才继续拒绝并在文案里给出出路。
2797
+ */
2798
+ if (patch.closure === undefined) {
2799
+ next.closure = current.closure === 'reported' ? 'reported' : 'done';
2800
+ }
2556
2801
  /*
2557
2802
  * 一条已经完成的子任务不可能同时“在等指示”。旧的 question/options 是
2558
2803
  * 上一段受阻经历的证据,不能继续驱动模型把它当成未决请示;失败原因本身
@@ -2723,7 +2968,8 @@ export function applyStatus(statuses, subtaskId, patch) {
2723
2968
  && next.closure != null
2724
2969
  && next.closure !== previousClosure
2725
2970
  && !(CLOSURE_TRANSITIONS[String(previousClosure)] ?? []).includes(String(next.closure))) {
2726
- throw new PlanError(`非法闭环迁移:${String(previousClosure)} → ${String(next.closure)}`, 'INVALID_TRANSITION');
2971
+ throw new PlanError(`非法闭环迁移:${String(previousClosure)} → ${String(next.closure)};`
2972
+ + '「已回报」的行若要再次交付,请直接派发新一轮,不要把它退回未回报', 'INVALID_TRANSITION');
2727
2973
  }
2728
2974
  if (next.closure === 'escalated' && next.status !== 'blocked') {
2729
2975
  throw new PlanError('closure=escalated 必须同时是 status=blocked;恢复推进请写 closure=instructed', 'INVALID_CLOSURE_PROJECTION');
package/lib/runtime.js CHANGED
@@ -184,6 +184,82 @@ function taskTextFromMessages(messages) {
184
184
  }
185
185
  return truncate(texts.join('\n\n'), 16000);
186
186
  }
187
+ /**
188
+ * [2.0.3] `source.kind === 'goal'` 的轮次也是用户的真实任务。
189
+ *
190
+ * 官方 DeepSeek Harness 的 `/goal <objective>` 命令不会产生 `user/message`:
191
+ * 目标文本由 goal-round-driver 以 `source.kind = 'goal'`、`round >= 1` 的
192
+ * 用户消息送达(见 `@deepseek-ai/dsh-goal-round-driver` 的
193
+ * `renderGoalRoundPrompt` / `createUserMessage`)。旧版 `humanMessages()` 只认
194
+ * `source.kind` 为 `user` 或省略的消息,于是 `/goal` 任务在整条 goal 生命周期
195
+ * 内都拿不到任务文本,`maybePlan()` 永远不会触发自动分解。
196
+ *
197
+ * 这里只认每个 goal 的第一轮(`round === 1`),并且只在该会话没有进行中的
198
+ * 计划时放行:
199
+ * - `round === 1` 是目标进入本会话的唯一入口,后续轮次是同一目标的续跑,
200
+ * 不能重复建计划;
201
+ * - 已存在进行中/未派发计划时返回 undefined,避免 goal 轮次与人工计划互相
202
+ * 取消或误记成「执行中新增需求」。
203
+ *
204
+ * 任务文本优先取 goal 领域服务的结构化 objective(干净文本),取不到时再从
205
+ * `<goal_round>` 信封里解析 JSON objective,最后才退回整条消息文本。
206
+ */
207
+ export function goalRoundPlanningTask(ctx, payload, existing) {
208
+ if (planRecordIsLive(existing))
209
+ return undefined;
210
+ const messages = Array.isArray(payload?.messages) ? payload.messages : [];
211
+ for (const message of messages) {
212
+ if (!message || message.role !== 'user')
213
+ continue;
214
+ const source = message.source ?? {};
215
+ if (source.kind !== 'goal')
216
+ continue;
217
+ if (Number(source.round) !== 1)
218
+ continue;
219
+ const raw = messageText(message).trim();
220
+ const text = goalObjectiveOf(ctx, payload.agent) || goalObjectiveFromText(raw) || raw;
221
+ if (!text)
222
+ continue;
223
+ return { text: truncate(text, 16000), goalId: String(source.goalId ?? ''), round: 1 };
224
+ }
225
+ return undefined;
226
+ }
227
+ /**
228
+ * Whether an existing plan record still owns work in this session.
229
+ *
230
+ * `isTerminalPhase()` 只覆盖 cancelled/superseded(present 门禁的语义);
231
+ * 对 goal 轮次的入口判定,done/ended/degraded/clarify 同样是「这一轮可以
232
+ * 开始新计划」的历史记录,不能把 `/goal` 任务永久挡在自动分解之外。
233
+ */
234
+ function planRecordIsLive(existing) {
235
+ if (!existing?.plan)
236
+ return false;
237
+ const phase = String(existing.phase ?? '');
238
+ return !['done', 'ended', 'cancelled', 'superseded', 'clarify', 'degraded'].includes(phase);
239
+ }
240
+ /** Read the structured objective of the current goal view, when the service exists. */
241
+ function goalObjectiveOf(ctx, agent) {
242
+ try {
243
+ const view = ctx?.get?.('goals')?.get?.(agent);
244
+ return typeof view?.objective === 'string' ? view.objective.trim() : '';
245
+ }
246
+ catch {
247
+ return '';
248
+ }
249
+ }
250
+ /** Parse `Objective: "<json string>"` out of the official `<goal_round>` envelope. */
251
+ export function goalObjectiveFromText(text) {
252
+ const match = /<goal_round>[\s\S]*?Objective:\s*("(?:[^"\\]|\\.)*")/.exec(String(text ?? ''));
253
+ if (!match)
254
+ return '';
255
+ try {
256
+ const value = JSON.parse(match[1]);
257
+ return typeof value === 'string' ? value.trim() : '';
258
+ }
259
+ catch {
260
+ return '';
261
+ }
262
+ }
187
263
  /*
188
264
  * Children start with zero parent context. Without recent turns they cannot
189
265
  * resolve "B", "it", "the previous item", so they search blindly and time out.
@@ -5168,6 +5244,47 @@ export function createWorkplanRuntime(ctx, options = {}) {
5168
5244
  * 是 serial 事件,抛错 ⇒ 该回合以 error 收尾 ⇒ runner 走 fail():
5169
5245
  * 不打印正文、非零退出。交互式会话维持原样(只 steer,不抛错)。
5170
5246
  */
5247
+ /*
5248
+ * [2.0.5] U1=B:交互式会话放行,但必须留痕。
5249
+ *
5250
+ * 旧行为是 `return` 了事——用户看到回合正常结束,却没有任何地方写着
5251
+ * 「这个回合其实是没通过门禁被放出来的」。B 方案不动「不硬拦」这个
5252
+ * 决定,只把放行本身记成一件事:
5253
+ * 1. 记录收进 record.releasedIncomplete(durable,刷新后仍在);
5254
+ * 2. 往会话追加一条 notice,用户当场能看见;
5255
+ * 3. 日志留一行,便于事后对时间线。
5256
+ * 三处都写同一组数字,避免「面板说 8/8、通知说 5/8」这种二次矛盾。
5257
+ */
5258
+ if (!failClosedActive) {
5259
+ const stuck = derivePlanSnapshot(record.statuses);
5260
+ const released = (stuck.statuses ?? [])
5261
+ .filter((item) => item.status !== 'done')
5262
+ .map((item) => String(item.subtaskId));
5263
+ record.releasedIncomplete = {
5264
+ turn,
5265
+ at: Date.now(),
5266
+ done: stuck.stats.done,
5267
+ total: stuck.stats.total,
5268
+ remaining: released,
5269
+ };
5270
+ ctx.logger?.warn?.(`dsh-workplan: 回合 ${turn} 连续 ${book.count} 次未通过交付就绪,按 B 方案放行但留痕:`
5271
+ + `${stuck.stats.done}/${stuck.stats.total},未完成 ${released.join(', ') || '无'}`);
5272
+ try {
5273
+ session.append('user/message', makeUserMessage([
5274
+ `⚠️ 本轮未通过交付就绪检查,已按「放行但留痕」结束(计划 ${record.plan.planId})`,
5275
+ `进度 ${stuck.stats.done}/${stuck.stats.total};未完成:${released.join(', ') || '无'}`,
5276
+ '本回合的内容不是最终交付;产物若已在盘上,下一回合核验后仍可交付。',
5277
+ ].join('\n'), {
5278
+ kind: 'workplan-release',
5279
+ form: 'notice',
5280
+ summary: `未就绪放行 ${stuck.stats.done}/${stuck.stats.total}`,
5281
+ }), { surfaceOp: 'append' });
5282
+ }
5283
+ catch (error) {
5284
+ ctx.logger?.warn?.(`dsh-workplan: 放行留痕写入失败:${error instanceof Error ? error.message : String(error)}`);
5285
+ }
5286
+ return;
5287
+ }
5171
5288
  if (failClosedActive) {
5172
5289
  const stuck = derivePlanSnapshot(record.statuses);
5173
5290
  const remaining = (stuck.statuses ?? [])
@@ -5908,9 +6025,15 @@ async function maybePlan(ctx, state, payload, downstream, options) {
5908
6025
  return downstream;
5909
6026
  const planMode = isPlanModeActive(ctx, session);
5910
6027
  const human = humanMessages(payload.messages);
5911
- if (human.length === 0)
6028
+ const existing = state.records.get(session.id);
6029
+ /*
6030
+ * [2.0.3] `/goal` 任务没有 user/message,任务文本只以 `source.kind = 'goal'`
6031
+ * 的轮次消息出现。放宽入口,但只认第一轮且只在该会话没有进行中计划时放行。
6032
+ */
6033
+ const goalTask = human.length === 0 ? goalRoundPlanningTask(ctx, payload, existing) : undefined;
6034
+ if (human.length === 0 && goalTask === undefined)
5912
6035
  return downstream;
5913
- const taskText = taskTextFromMessages(payload.messages);
6036
+ const taskText = goalTask?.text ?? taskTextFromMessages(payload.messages);
5914
6037
  if (!taskText)
5915
6038
  return downstream;
5916
6039
  if (isSocialMessage(taskText))
@@ -5931,7 +6054,6 @@ async function maybePlan(ctx, state, payload, downstream, options) {
5931
6054
  state.activeTurns = new Map();
5932
6055
  state.activeTurns.set(session.id, Number(payload.turn ?? 0));
5933
6056
  const conversationContext = recentConversation(session);
5934
- const existing = state.records.get(session.id);
5935
6057
  if (existing?.plan?.createdTurn === payload.turn)
5936
6058
  return downstream;
5937
6059
  /*
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-workplan",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
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",
package/src/host.ts CHANGED
@@ -1490,7 +1490,7 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
1490
1490
 
1491
1491
  export const meta = {
1492
1492
  name,
1493
- version: '2.0.2',
1493
+ version: '2.0.4',
1494
1494
  promptOrder: PROMPT_ORDER,
1495
1495
  routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
1496
1496
  }
package/src/plan.ts CHANGED
@@ -1755,6 +1755,50 @@ export function normaliseCriterion(value: any) {
1755
1755
  .replace(/^(必须|需要|应当|应该|请|务必)/, '')
1756
1756
  }
1757
1757
 
1758
+ /**
1759
+ * [2.0.4] 两条验收描述的相似度(0–1)。
1760
+ *
1761
+ * 用字符二元组 Dice 系数而不是编辑距离:中文短句里「逐项」「一致性」这类
1762
+ * 词被增删时,二元组重合度比字符级编辑距离更接近人的判断,也不需要引入
1763
+ * 任何依赖。空串与单字返回 0,交给调用方的长度门槛处理。
1764
+ */
1765
+ export function criterionSimilarity(a: string, b: string) {
1766
+ if (!a || !b) return 0
1767
+ if (a === b) return 1
1768
+ const grams = (text: string) => {
1769
+ const chars = Array.from(text)
1770
+ const out = new Map<string, number>()
1771
+ for (let i = 0; i + 1 < chars.length; i += 1) {
1772
+ const gram = chars[i] + chars[i + 1]
1773
+ out.set(gram, (out.get(gram) ?? 0) + 1)
1774
+ }
1775
+ return out
1776
+ }
1777
+ const left = grams(a)
1778
+ const right = grams(b)
1779
+ let leftTotal = 0
1780
+ let rightTotal = 0
1781
+ for (const count of left.values()) leftTotal += count
1782
+ for (const count of right.values()) rightTotal += count
1783
+ if (leftTotal === 0 || rightTotal === 0) return 0
1784
+ let overlap = 0
1785
+ for (const [gram, count] of left) {
1786
+ overlap += Math.min(count, right.get(gram) ?? 0)
1787
+ }
1788
+ return (2 * overlap) / (leftTotal + rightTotal)
1789
+ }
1790
+
1791
+ /**
1792
+ * [2.0.4] 验收文本里是否带否定/禁止语气。
1793
+ *
1794
+ * 「不得超过 5%」与「超过 5%」的二元组相似度可以很高,但语义相反。
1795
+ * 相似度只用来判「是不是同一条」,判不了「是不是同一个约束」,所以要单独
1796
+ * 把否定词拎出来比较:两边不一致就直接判不覆盖,不交给阈值碰运气。
1797
+ */
1798
+ export function hasNegation(text: string) {
1799
+ return /不得|禁止|严禁|不能|不可|不允许|不应|无需|避免|排除|不超过|不低于|不高于|不等于|未通过|未完成/.test(String(text ?? ''))
1800
+ }
1801
+
1758
1802
  export function acceptanceCoverage(expected: any, actual: any) {
1759
1803
  const want = (Array.isArray(expected) ? expected : []).map(normaliseCriterion).filter(Boolean)
1760
1804
  const got = (Array.isArray(actual) ? actual : [])
@@ -1779,7 +1823,25 @@ export function acceptanceCoverage(expected: any, actual: any) {
1779
1823
  if (row === criterion) return true
1780
1824
  if (idPattern.test(row)) return true
1781
1825
  if (Math.min(row.length, criterion.length) < 6) return false
1782
- return row.includes(criterion)
1826
+ if (row.includes(criterion)) return true
1827
+ /*
1828
+ * [2.0.4] 同义改写必须算同一条验收(用户 m00302 / 2026-11-05)。
1829
+ *
1830
+ * 1.12.0 只认「证据原文包含计划原文」,于是主 Agent 把
1831
+ * 「数字与 T9 逐项一致」写成「数字与 T9 一致」就会被判成「没回应」,
1832
+ * 交付门禁反复重开。这不是证据不合格,是**字面匹配**在惩罚正常表述。
1833
+ *
1834
+ * [2.0.4] 补充规则(阈值与注释一致,不再出现 2/3 对 0.65、0.75 对 0.70):
1835
+ * 1. 证据几乎抄全了计划原文(≥85%)→ 覆盖;
1836
+ * 2. 字符二元组 Dice 相似度 ≥ 0.70,且两边否定词状态一致 → 覆盖。
1837
+ * 否定词必须单独看:T4 用真实差异对复现出「删掉『不得超过』」这种
1838
+ * 改写会被纯相似度放过,那是把约束反过来的假阳性,必须挡住。
1839
+ * 只回应一半的情况(如「登录测试」对「登录测试与越权测试」,Dice 0.667)
1840
+ * 仍然不覆盖,Q6/U-16 的本意不变。
1841
+ */
1842
+ if (criterion.includes(row) && row.length / criterion.length >= 0.85) return true
1843
+ if (hasNegation(criterion) !== hasNegation(row)) return false
1844
+ return criterionSimilarity(row, criterion) >= 0.7
1783
1845
  })
1784
1846
  if (!covered) missing.push(String((Array.isArray(expected) ? expected : [])[index] ?? criterion))
1785
1847
  }
@@ -1928,22 +1990,156 @@ function readEvidenceOptions(value: any) {
1928
1990
  * A malformed block is reported as such instead of being silently ignored —
1929
1991
  * "cannot tell" must never default to "done".
1930
1992
  */
1993
+ /**
1994
+ * [2.0.4] 把一段被截断的 JSON 补成可解析的对象(用户 m00302)。
1995
+ *
1996
+ * 事故(T1 报告 §2.3 复核后的真实形态):5 个子 Agent 的产物都已落盘,
1997
+ * 其中 3 项(T4/T6/T10)的回执**结尾各少一个 `}`**,2 项(T5/T7)JSON 合法
1998
+ * 但漏写规定标记。旧实现把前者判成「无法解析」、后者判成「未提供证据块」,
1999
+ * 证据在盘上,判定却拿不到,只能人工兜底。
2000
+ *
2001
+ * 注意:早期口头归因写的「内容太长被截断」是错的——会话里 3000 字符是
2002
+ * 结果写回时的展示上限,不是解析输入;同样被判 done 的 T1/T2/T3 也被截到
2003
+ * 3000 字却解析正常。这里做的是**有界修复**,不是放宽验收:
2004
+ * - 只补结构(收尾引号、闭合括号),绝不补内容,也不改任何字段值;
2005
+ * - 修复后的对象仍然走完整的 status/acceptance/phases 门禁;
2006
+ * - 修不好就如实返回 null,绝不用「猜」的内容顶替。
2007
+ */
2008
+ function closeOpenJson(text: string): string | null {
2009
+ const chars = Array.from(text)
2010
+ const stack: string[] = []
2011
+ let inString = false
2012
+ let escaped = false
2013
+ for (const char of chars) {
2014
+ if (inString) {
2015
+ if (escaped) escaped = false
2016
+ else if (char === '\\') escaped = true
2017
+ else if (char === '"') inString = false
2018
+ continue
2019
+ }
2020
+ if (char === '"') inString = true
2021
+ else if (char === '{') stack.push('}')
2022
+ else if (char === '[') stack.push(']')
2023
+ else if (char === '}' || char === ']') {
2024
+ if (stack.pop() !== char) return null
2025
+ }
2026
+ }
2027
+ let closed = text
2028
+ if (inString) closed += '"'
2029
+ while (stack.length > 0) closed += stack.pop()
2030
+ return closed
2031
+ }
2032
+
2033
+ /** 最后一个「切掉它之后仍可能闭合」的位置:字符串外的逗号或左括号。 */
2034
+ function lastSafeCut(text: string): number {
2035
+ const chars = Array.from(text)
2036
+ let inString = false
2037
+ let escaped = false
2038
+ let cut = -1
2039
+ for (let i = 0; i < chars.length; i += 1) {
2040
+ const char = chars[i]
2041
+ if (inString) {
2042
+ if (escaped) escaped = false
2043
+ else if (char === '\\') escaped = true
2044
+ else if (char === '"') inString = false
2045
+ continue
2046
+ }
2047
+ if (char === '"') inString = true
2048
+ else if (char === ',' || char === '{' || char === '[') cut = inString ? cut : i
2049
+ }
2050
+ return cut
2051
+ }
2052
+
2053
+ export function repairEvidenceJson(text: string): any {
2054
+ let body = String(text ?? '').trim()
2055
+ for (let attempt = 0; attempt < 24 && body.length > 0; attempt += 1) {
2056
+ const closed = closeOpenJson(body)
2057
+ if (closed) {
2058
+ try {
2059
+ const value = JSON.parse(closed)
2060
+ if (isRecord(value)) return value
2061
+ } catch {
2062
+ /* 继续往前切 */
2063
+ }
2064
+ }
2065
+ const cut = lastSafeCut(body)
2066
+ if (cut <= 0) return null
2067
+ body = body.slice(0, cut)
2068
+ }
2069
+ return null
2070
+ }
2071
+
2072
+ /**
2073
+ * [2.0.4] 没写规定标记、但内容其实交齐了的回执(用户 m00302)。
2074
+ *
2075
+ * 子会话原文核查(T1 报告 §2.3)显示:T5/T7 的证据块 **JSON 完全合法**,
2076
+ * status/phases/acceptance/artifacts 一样不缺,只是被放进了 Markdown 代码块,
2077
+ * 没有写 `WORKPLAN_EVIDENCE:START/END`。旧实现直接判「结果块缺失」,把
2078
+ * 「格式没按规定」说成「没交作业」。
2079
+ *
2080
+ * 这里做的是**有界认领**:只认带 `status` 且至少还有一个证据字段的 JSON
2081
+ * 对象,绝不把任意 JSON(比如计划载荷、配置片段)当成回执。
2082
+ */
2083
+ export function rescueEvidenceFromFence(output: any): any {
2084
+ const text = typeof output === 'string' ? output : ''
2085
+ if (!text.includes('{')) return null
2086
+ const candidates: string[] = []
2087
+ const fence = /```(?:json|JSON)?\s*\n([\s\S]*?)```/g
2088
+ let match: RegExpExecArray | null
2089
+ while ((match = fence.exec(text)) !== null) candidates.push(match[1])
2090
+ const first = text.indexOf('{')
2091
+ const last = text.lastIndexOf('}')
2092
+ if (first >= 0 && last > first) candidates.push(text.slice(first, last + 1))
2093
+ for (const candidate of candidates) {
2094
+ let value: any = null
2095
+ try {
2096
+ value = JSON.parse(String(candidate).trim())
2097
+ } catch {
2098
+ value = repairEvidenceJson(String(candidate).trim())
2099
+ }
2100
+ if (!isRecord(value)) continue
2101
+ if (!EVIDENCE_STATUSES.includes(value.status)) continue
2102
+ const hasEvidence = Array.isArray(value.acceptance) || Array.isArray(value.artifacts)
2103
+ || Array.isArray(value.needs) || isRecord(value.phases) || typeof value.summary === 'string'
2104
+ if (!hasEvidence) continue
2105
+ return value
2106
+ }
2107
+ return null
2108
+ }
2109
+
1931
2110
  export function parseEvidenceBlock(output: any) {
1932
2111
  const text = typeof output === 'string' ? output : ''
1933
2112
  const begin = text.lastIndexOf(EVIDENCE_MARKER_BEGIN)
1934
- if (begin < 0) return { found: false, malformed: false, truncated: false, payload: null, raw: '' }
1935
- const end = text.indexOf(EVIDENCE_MARKER_END, begin + EVIDENCE_MARKER_BEGIN.length)
1936
- if (end < 0) return { found: true, malformed: true, truncated: false, payload: null, raw: '' }
1937
- const raw = text.slice(begin + EVIDENCE_MARKER_BEGIN.length, end).trim()
1938
- const truncated = raw.length > MAX_EVIDENCE_BLOCK_CHARS
1939
- try {
1940
- const payload = JSON.parse(raw)
2113
+ if (begin < 0) {
2114
+ const rescued = rescueEvidenceFromFence(text)
2115
+ if (rescued) {
2116
+ return { found: true, malformed: false, truncated: false, repaired: false, rescued: true, payload: rescued, raw: '' }
2117
+ }
2118
+ return { found: false, malformed: false, truncated: false, repaired: false, rescued: false, payload: null, raw: '' }
2119
+ }
2120
+ const bodyStart = begin + EVIDENCE_MARKER_BEGIN.length
2121
+ const end = text.indexOf(EVIDENCE_MARKER_END, bodyStart)
2122
+ /*
2123
+ * [2.0.4] 结束标记缺失 = 输出被截断,不是「格式错误」。
2124
+ *
2125
+ * 旧实现遇到这种情况直接判 malformed,还把 `truncated` 写成 false,于是
2126
+ * 上层拿到的是「无法解析」,看不出真正原因。现在先把标记之后的全部内容
2127
+ * 当作候选块,交给有界修复;修得回来就是可用证据,修不回来才报截断。
2128
+ */
2129
+ const raw = (end < 0 ? text.slice(bodyStart) : text.slice(bodyStart, end)).trim()
2130
+ const truncated = end < 0 || raw.length > MAX_EVIDENCE_BLOCK_CHARS
2131
+ const accept = (payload: any, repaired: boolean) => {
1941
2132
  if (!isRecord(payload) || !EVIDENCE_STATUSES.includes(payload.status)) {
1942
- return { found: true, malformed: true, truncated, payload: null, raw }
2133
+ return { found: true, malformed: true, truncated, repaired, rescued: false, payload: null, raw }
1943
2134
  }
1944
- return { found: true, malformed: false, truncated, payload, raw }
2135
+ return { found: true, malformed: false, truncated, repaired, rescued: false, payload, raw }
2136
+ }
2137
+ try {
2138
+ return accept(JSON.parse(raw), false)
1945
2139
  } catch {
1946
- return { found: true, malformed: true, truncated, payload: null, raw }
2140
+ const repaired = repairEvidenceJson(raw)
2141
+ if (repaired) return accept(repaired, true)
2142
+ return { found: true, malformed: true, truncated, repaired: false, payload: null, raw }
1947
2143
  }
1948
2144
  }
1949
2145
 
@@ -1979,7 +2175,17 @@ export function adjudicateResult({ output, strict = true, expectedAcceptance = [
1979
2175
  acceptance: [],
1980
2176
  artifacts: [],
1981
2177
  needs: [],
1982
- error: '结果块无法解析,请主 Agent 核对',
2178
+ /*
2179
+ * [2.0.4] 失败信息必须能指导下一步动作(用户 m00302)。
2180
+ *
2181
+ * 「无法解析,请主 Agent 核对」把诊断责任推回给人:既不说是不是截断,
2182
+ * 也不说该重发还是该改格式,于是只能靠读原始输出猜。现在按截断/非法
2183
+ * 分档给出可执行提示。
2184
+ */
2185
+ error: parsed.truncated
2186
+ ? '结果块被截断(缺少结束标记或超过长度上限):请让该子 Agent 重新回报,'
2187
+ + '只保留 status/summary/acceptance/artifacts/needs 字段,删掉大段执行日志后重发'
2188
+ : '结果块 JSON 非法(不是截断):请检查引号、逗号与括号是否成对,修正后重新回报',
1983
2189
  }
1984
2190
  }
1985
2191
  if (!parsed.found) {
@@ -2603,7 +2809,22 @@ export function applyStatus(statuses: any, subtaskId: any, patch: any) {
2603
2809
  next.updatedBy = ['child', 'agent', 'system'].includes(patch.updatedBy) ? patch.updatedBy : 'system'
2604
2810
  if (patch.status === 'done') {
2605
2811
  next.progress = 100
2606
- if (patch.closure === undefined) next.closure = 'done'
2812
+ /*
2813
+ * [2.0.4] 「已回报」是事实,不是阶段(用户 m00302 / 2026-11-05)。
2814
+ *
2815
+ * `closure:'reported'` 的意思是「这条完成结果已经通过结果消息回报过」,
2816
+ * 它是交付门禁 `reportPending` 读的事实。主 Agent 事后复核证据、把
2817
+ * verification/acceptance 补齐时,status 仍然是 done —— 旧代码却把
2818
+ * closure 默认改回 `done`,于是撞上「非法闭环迁移:reported → done」,
2819
+ * 逼着人先写一次假的 blocked 再写 done。审计链被污染,界面还会短暂
2820
+ * 显示「受阻」。
2821
+ *
2822
+ * 现在:没有显式指定 closure 的复核写入,保留已回报事实;只有调用方
2823
+ * 明确要把它退回未回报时,迁移表才继续拒绝并在文案里给出出路。
2824
+ */
2825
+ if (patch.closure === undefined) {
2826
+ next.closure = current.closure === 'reported' ? 'reported' : 'done'
2827
+ }
2607
2828
  /*
2608
2829
  * 一条已经完成的子任务不可能同时“在等指示”。旧的 question/options 是
2609
2830
  * 上一段受阻经历的证据,不能继续驱动模型把它当成未决请示;失败原因本身
@@ -2743,7 +2964,8 @@ export function applyStatus(statuses: any, subtaskId: any, patch: any) {
2743
2964
  && !(CLOSURE_TRANSITIONS[String(previousClosure)] ?? []).includes(String(next.closure))
2744
2965
  ) {
2745
2966
  throw new PlanError(
2746
- `非法闭环迁移:${String(previousClosure)} → ${String(next.closure)}`,
2967
+ `非法闭环迁移:${String(previousClosure)} → ${String(next.closure)};`
2968
+ + '「已回报」的行若要再次交付,请直接派发新一轮,不要把它退回未回报',
2747
2969
  'INVALID_TRANSITION',
2748
2970
  )
2749
2971
  }
package/src/runtime.ts CHANGED
@@ -259,6 +259,77 @@ function taskTextFromMessages(messages: any) {
259
259
  return truncate(texts.join('\n\n'), 16000)
260
260
  }
261
261
 
262
+ /**
263
+ * [2.0.3] `source.kind === 'goal'` 的轮次也是用户的真实任务。
264
+ *
265
+ * 官方 DeepSeek Harness 的 `/goal <objective>` 命令不会产生 `user/message`:
266
+ * 目标文本由 goal-round-driver 以 `source.kind = 'goal'`、`round >= 1` 的
267
+ * 用户消息送达(见 `@deepseek-ai/dsh-goal-round-driver` 的
268
+ * `renderGoalRoundPrompt` / `createUserMessage`)。旧版 `humanMessages()` 只认
269
+ * `source.kind` 为 `user` 或省略的消息,于是 `/goal` 任务在整条 goal 生命周期
270
+ * 内都拿不到任务文本,`maybePlan()` 永远不会触发自动分解。
271
+ *
272
+ * 这里只认每个 goal 的第一轮(`round === 1`),并且只在该会话没有进行中的
273
+ * 计划时放行:
274
+ * - `round === 1` 是目标进入本会话的唯一入口,后续轮次是同一目标的续跑,
275
+ * 不能重复建计划;
276
+ * - 已存在进行中/未派发计划时返回 undefined,避免 goal 轮次与人工计划互相
277
+ * 取消或误记成「执行中新增需求」。
278
+ *
279
+ * 任务文本优先取 goal 领域服务的结构化 objective(干净文本),取不到时再从
280
+ * `<goal_round>` 信封里解析 JSON objective,最后才退回整条消息文本。
281
+ */
282
+ export function goalRoundPlanningTask(ctx: any, payload: any, existing: any) {
283
+ if (planRecordIsLive(existing)) return undefined
284
+ const messages = Array.isArray(payload?.messages) ? payload.messages : []
285
+ for (const message of messages) {
286
+ if (!message || message.role !== 'user') continue
287
+ const source = message.source ?? {}
288
+ if (source.kind !== 'goal') continue
289
+ if (Number(source.round) !== 1) continue
290
+ const raw = messageText(message).trim()
291
+ const text = goalObjectiveOf(ctx, payload.agent) || goalObjectiveFromText(raw) || raw
292
+ if (!text) continue
293
+ return { text: truncate(text, 16000), goalId: String(source.goalId ?? ''), round: 1 }
294
+ }
295
+ return undefined
296
+ }
297
+
298
+ /**
299
+ * Whether an existing plan record still owns work in this session.
300
+ *
301
+ * `isTerminalPhase()` 只覆盖 cancelled/superseded(present 门禁的语义);
302
+ * 对 goal 轮次的入口判定,done/ended/degraded/clarify 同样是「这一轮可以
303
+ * 开始新计划」的历史记录,不能把 `/goal` 任务永久挡在自动分解之外。
304
+ */
305
+ function planRecordIsLive(existing: any) {
306
+ if (!existing?.plan) return false
307
+ const phase = String(existing.phase ?? '')
308
+ return !['done', 'ended', 'cancelled', 'superseded', 'clarify', 'degraded'].includes(phase)
309
+ }
310
+
311
+ /** Read the structured objective of the current goal view, when the service exists. */
312
+ function goalObjectiveOf(ctx: any, agent: any) {
313
+ try {
314
+ const view = ctx?.get?.('goals')?.get?.(agent)
315
+ return typeof view?.objective === 'string' ? view.objective.trim() : ''
316
+ } catch {
317
+ return ''
318
+ }
319
+ }
320
+
321
+ /** Parse `Objective: "<json string>"` out of the official `<goal_round>` envelope. */
322
+ export function goalObjectiveFromText(text: any) {
323
+ const match = /<goal_round>[\s\S]*?Objective:\s*("(?:[^"\\]|\\.)*")/.exec(String(text ?? ''))
324
+ if (!match) return ''
325
+ try {
326
+ const value = JSON.parse(match[1] as string)
327
+ return typeof value === 'string' ? value.trim() : ''
328
+ } catch {
329
+ return ''
330
+ }
331
+ }
332
+
262
333
  /*
263
334
  * Children start with zero parent context. Without recent turns they cannot
264
335
  * resolve "B", "it", "the previous item", so they search blindly and time out.
@@ -5218,6 +5289,53 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
5218
5289
  * 是 serial 事件,抛错 ⇒ 该回合以 error 收尾 ⇒ runner 走 fail():
5219
5290
  * 不打印正文、非零退出。交互式会话维持原样(只 steer,不抛错)。
5220
5291
  */
5292
+ /*
5293
+ * [2.0.5] U1=B:交互式会话放行,但必须留痕。
5294
+ *
5295
+ * 旧行为是 `return` 了事——用户看到回合正常结束,却没有任何地方写着
5296
+ * 「这个回合其实是没通过门禁被放出来的」。B 方案不动「不硬拦」这个
5297
+ * 决定,只把放行本身记成一件事:
5298
+ * 1. 记录收进 record.releasedIncomplete(durable,刷新后仍在);
5299
+ * 2. 往会话追加一条 notice,用户当场能看见;
5300
+ * 3. 日志留一行,便于事后对时间线。
5301
+ * 三处都写同一组数字,避免「面板说 8/8、通知说 5/8」这种二次矛盾。
5302
+ */
5303
+ if (!failClosedActive) {
5304
+ const stuck = derivePlanSnapshot(record.statuses)
5305
+ const released = (stuck.statuses ?? [])
5306
+ .filter((item: any) => item.status !== 'done')
5307
+ .map((item: any) => String(item.subtaskId))
5308
+ record.releasedIncomplete = {
5309
+ turn,
5310
+ at: Date.now(),
5311
+ done: stuck.stats.done,
5312
+ total: stuck.stats.total,
5313
+ remaining: released,
5314
+ }
5315
+ ctx.logger?.warn?.(
5316
+ `dsh-workplan: 回合 ${turn} 连续 ${book.count} 次未通过交付就绪,按 B 方案放行但留痕:`
5317
+ + `${stuck.stats.done}/${stuck.stats.total},未完成 ${released.join(', ') || '无'}`,
5318
+ )
5319
+ try {
5320
+ session.append('user/message', makeUserMessage(
5321
+ [
5322
+ `⚠️ 本轮未通过交付就绪检查,已按「放行但留痕」结束(计划 ${record.plan.planId})`,
5323
+ `进度 ${stuck.stats.done}/${stuck.stats.total};未完成:${released.join(', ') || '无'}`,
5324
+ '本回合的内容不是最终交付;产物若已在盘上,下一回合核验后仍可交付。',
5325
+ ].join('\n'),
5326
+ {
5327
+ kind: 'workplan-release',
5328
+ form: 'notice',
5329
+ summary: `未就绪放行 ${stuck.stats.done}/${stuck.stats.total}`,
5330
+ },
5331
+ ), { surfaceOp: 'append' })
5332
+ } catch (error) {
5333
+ ctx.logger?.warn?.(
5334
+ `dsh-workplan: 放行留痕写入失败:${error instanceof Error ? error.message : String(error)}`,
5335
+ )
5336
+ }
5337
+ return
5338
+ }
5221
5339
  if (failClosedActive) {
5222
5340
  const stuck = derivePlanSnapshot(record.statuses)
5223
5341
  const remaining = (stuck.statuses ?? [])
@@ -5946,8 +6064,14 @@ async function maybePlan(ctx: any, state: any, payload: any, downstream: any, op
5946
6064
  if (payload.step !== 1) return downstream
5947
6065
  const planMode = isPlanModeActive(ctx, session)
5948
6066
  const human = humanMessages(payload.messages)
5949
- if (human.length === 0) return downstream
5950
- const taskText = taskTextFromMessages(payload.messages)
6067
+ const existing = state.records.get(session.id)
6068
+ /*
6069
+ * [2.0.3] `/goal` 任务没有 user/message,任务文本只以 `source.kind = 'goal'`
6070
+ * 的轮次消息出现。放宽入口,但只认第一轮且只在该会话没有进行中计划时放行。
6071
+ */
6072
+ const goalTask = human.length === 0 ? goalRoundPlanningTask(ctx, payload, existing) : undefined
6073
+ if (human.length === 0 && goalTask === undefined) return downstream
6074
+ const taskText = goalTask?.text ?? taskTextFromMessages(payload.messages)
5951
6075
  if (!taskText) return downstream
5952
6076
  if (isSocialMessage(taskText)) return downstream
5953
6077
  if (isVagueContinuation(taskText)) return downstream
@@ -5963,7 +6087,6 @@ async function maybePlan(ctx: any, state: any, payload: any, downstream: any, op
5963
6087
  if (!state.activeTurns) state.activeTurns = new Map()
5964
6088
  state.activeTurns.set(session.id, Number(payload.turn ?? 0))
5965
6089
  const conversationContext = recentConversation(session)
5966
- const existing = state.records.get(session.id)
5967
6090
  if (existing?.plan?.createdTurn === payload.turn) return downstream
5968
6091
  /*
5969
6092
  * [1.11.0] 执行中记录的变更,在本轮结束后仍然没有被 replan 落实时,必须