dsh-workplan 1.8.3 → 1.8.18
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 +581 -0
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/client.js +64 -20
- package/docs/postmortem-1.8.4-20261030.md +51 -0
- package/docs/postmortem-1.8.7-20261031.md +385 -0
- package/docs/release-notes-1.8.4.md +65 -0
- package/docs/release-record-1.8.4-20261030.md +70 -0
- package/lib/host.js +244 -30
- package/lib/plan.js +355 -16
- package/lib/runtime.js +1516 -124
- package/package.json +1 -1
- package/src/client.ts +63 -19
- package/src/host.ts +260 -32
- package/src/plan.ts +383 -16
- package/src/runtime.ts +1487 -118
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# v1.8.4 — 「已结束」不再和「正在做」同屏
|
|
2
|
+
|
|
3
|
+
## 一句话
|
|
4
|
+
|
|
5
|
+
左侧栏「任务进度」曾把同一张卡片同时写成「已结束,可续跑 · 正在做」,而同一次运行还在真实推进脚本。
|
|
6
|
+
这一版让「结束」只按**真实的存活事实**判定:只要派发还在跑,卡片就不会宣布结束。
|
|
7
|
+
|
|
8
|
+
## 你会看到什么变化
|
|
9
|
+
|
|
10
|
+
| 之前 | 现在 |
|
|
11
|
+
|---|---|
|
|
12
|
+
| 徽标「已结束,可续跑 · 正在做」 | 派发在跑时显示真实阶段(如「正在做」);真的结束才显示「已结束」 |
|
|
13
|
+
| 「任务进度」卡一边宣告结束,展开后第 4 步仍写「正在做」 | 结束时会写明「本轮结束时这一步仍未完成,可以续跑」,不再残留「正在做」 |
|
|
14
|
+
| 同一张卡两个完成度:计数 73% / 加权 80% | 只有一个完成度,分组、环、展开页取同一个数 |
|
|
15
|
+
| 徽标承诺「可续跑」,卡片却不给方法 | 凡是说「可续跑」的地方,都给出「对主 Agent 说『续跑这个计划』…」以及剩余次数 |
|
|
16
|
+
|
|
17
|
+
## 根因(给需要复核的人)
|
|
18
|
+
|
|
19
|
+
计划结果由异步派发结算,而**派发可以跨过宿主回合结束**:事故会话里 `turn/end` 发生在
|
|
20
|
+
19:58:39,派发继续运行到 20:22:50 才写入结果。`serialisePlan` 只读取最后一个
|
|
21
|
+
`turn/start|turn/end` 事件判断「本轮是否结束」,从不读插件自己的存活信号
|
|
22
|
+
`record.dispatchPromise`,于是把「回合结束」误当成「没有东西在跑」,把阶段改写成
|
|
23
|
+
`ended`,而子任务状态仍是 `in_progress`——同屏的两句话从此互相打脸。
|
|
24
|
+
|
|
25
|
+
客户端还有三处加剧了矛盾:`planPhaseOf` 会用计数覆盖服务端阶段;`resumeHint` 只在
|
|
26
|
+
`phase === 'blocked'` 时给续跑指令,而徽标对 `ended` 也承诺「可续跑」;展开页用加权
|
|
27
|
+
百分比、分组与环用计数百分比。
|
|
28
|
+
|
|
29
|
+
## 修复内容
|
|
30
|
+
|
|
31
|
+
- `src/runtime.ts`:`serialisePlan` 先读 `record.dispatchPromise`;有活派发时不进入
|
|
32
|
+
`ended`,并把 `running` 随载荷下发。
|
|
33
|
+
- `src/runtime.ts`:回合真的结束且无活派发时,用 `settleStaleInflight` 把残留的
|
|
34
|
+
`in_progress` 改判 `blocked` 并附说明;**只改下发的副本**,内存记录不动,续跑仍从原地继续。
|
|
35
|
+
- `src/client.ts`:新增 `sessionPhaseOf`,`running === true` 时回退到原阶段,展示层不再
|
|
36
|
+
仅凭 `phase` 说「已结束」。
|
|
37
|
+
- `src/client.ts`:`resumeHint` 覆盖 `blocked` / `paused` / 可续跑的 `ended`;展开页与
|
|
38
|
+
分组统一使用计数百分比(删除 `planWeightedPercent`)。
|
|
39
|
+
- `src/plan.ts`:新增不变量 I11 —— `phase=ended` 且仍有 `in_progress` 时自检判红。
|
|
40
|
+
- 测试:新增 `tests/ended-live-dispatch.test.ts`(6 例,含回放路径、只改副本),
|
|
41
|
+
`tests/client-resume-hint.test.ts` 增 2 例(徽标与续跑说明必须同时成立;载荷说「还在跑」
|
|
42
|
+
时界面不得出现「已结束」)。全部 **196 项测试通过**。
|
|
43
|
+
|
|
44
|
+
## 升级
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
dsh plugin --profile web add dsh-workplan@1.8.4
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
插件在 `dsh web` 启动时加载,**升级后需重启一次 `dsh web` 才生效**(重启会中断正在运行的会话)。
|
|
51
|
+
历史计划不需要数据订正:面板按新规则重算,旧记录里「已结束 + 正在做」的组合不会再被渲染。
|
|
52
|
+
|
|
53
|
+
## 已知限制
|
|
54
|
+
|
|
55
|
+
- 「已结束」只代表**没有活派发**,不代表计划完成。没做完的计划仍会进入「已结束」分组并
|
|
56
|
+
标出受阻数——这是刻意的,用户需要看到「这一轮结束了,但事情没做完」。
|
|
57
|
+
- 存活信号只在同一进程内有效。若进程在派发中途被杀,记录里不会留下 `dispatchPromise`,
|
|
58
|
+
此时按「回合结束 + 残留 `in_progress`」收敛为受阻。
|
|
59
|
+
|
|
60
|
+
## 复核
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm run check && npm test # 196 项测试
|
|
64
|
+
npm run build && git diff --exit-code -- lib client.js # 生成物可复现
|
|
65
|
+
```
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# 发布记录 — 1.8.4(2026-10-30)
|
|
2
|
+
|
|
3
|
+
> 每一次发布留一条可复核的时间线:tag、commit、制品哈希、渠道复验命令与输出。
|
|
4
|
+
|
|
5
|
+
## 制品身份
|
|
6
|
+
|
|
7
|
+
| 项 | 值 |
|
|
8
|
+
|---|---|
|
|
9
|
+
| 版本 | 1.8.4 |
|
|
10
|
+
| commit | `0c8564c`(`Fix 已结束 shown while dispatch still running (1.8.4)`) |
|
|
11
|
+
| tag | `v1.8.4` |
|
|
12
|
+
| 本地制品 | `dsh-workplan-1.8.4.tgz`,590051 B |
|
|
13
|
+
| sha256 | `3b180810336030740560a8bfb249eb44b809a4fda608bc43ce28a7190e10af1b` |
|
|
14
|
+
| GitHub Release | https://github.com/abbaababa/dsh-workplan/releases/tag/v1.8.4 |
|
|
15
|
+
| npm | `dsh-workplan@1.8.4`,integrity `sha512-UnFQJPX76vgcx3dMe3/5x1BDTp22mrJd1cEndDP/wKiwOUDZBAu7V3rkACHs5nC6lwMwjixZ4Yx5qMDtVUEWbQ==` |
|
|
16
|
+
|
|
17
|
+
## 发布前检查(全部通过)
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
$ npm run check # tsc --noEmit,无输出即通过
|
|
21
|
+
$ npm test # ℹ tests 196 ℹ pass 196 ℹ fail 0
|
|
22
|
+
$ npm run build && git diff --exit-code -- lib client.js
|
|
23
|
+
REPRODUCIBLE: clean
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 渠道复验(实际输出)
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
$ npm view dsh-workplan dist-tags --json
|
|
30
|
+
[ { "latest": "1.8.4" } ]
|
|
31
|
+
|
|
32
|
+
$ npm view dsh-workplan@1.8.4 version dist.tarball
|
|
33
|
+
version = '1.8.4'
|
|
34
|
+
dist.tarball = 'https://registry.npmjs.org/dsh-workplan/-/dsh-workplan-1.8.4.tgz'
|
|
35
|
+
|
|
36
|
+
$ gh api repos/abbaababa/dsh-workplan/releases/tags/v1.8.4 \
|
|
37
|
+
--jq '.tag_name, (.assets[] | {name, state, size})'
|
|
38
|
+
v1.8.4
|
|
39
|
+
{"content_type":"application/x-gtar","name":"dsh-workplan-1.8.4.tgz","size":590051,"state":"uploaded"}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**未在本机复验的一项**:`curl -sIL` 直连 `release-assets.githubusercontent.com` 在本机
|
|
43
|
+
TLS 握手超时(`http=000`),因此「浏览器/包管理器直链下载返回 200」这条只能在网络可达的
|
|
44
|
+
机器上确认。Release 侧的资产状态已由 GitHub API 证明为 `uploaded`,大小与本地制品一致
|
|
45
|
+
(590051 B)。
|
|
46
|
+
|
|
47
|
+
## 生效方式
|
|
48
|
+
|
|
49
|
+
本机 profile 里 `~/.dsh/profiles/web/node_modules/dsh-workplan` 是指向本仓库的软链接,
|
|
50
|
+
源码与 `lib/`、`client.js` 已在发布前更新;**运行中的 `dsh web`(PID 27767,18:42:45 启动)
|
|
51
|
+
仍在用启动时加载的旧模块**,重启一次才生效:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# 先停掉当前的 dsh web,再用同一条精确命令拉起(会中断正在运行的会话)
|
|
55
|
+
node /Users/open/.npm/_npx/bd325e168b7188a4/node_modules/.bin/dsh \
|
|
56
|
+
--profile web --host 127.0.0.1 --port 3080 \
|
|
57
|
+
--trusted-host openmacbook-pro-1.ts.net --no-open
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 发布后离线复验(用事故会话真实日志重算)
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
$ T3_EXPAND=session-b83e4a75-225a-4e78-9bb2-d8cb90078278 \
|
|
64
|
+
node docs/status-audit/t3-render_sidebar_state.mjs \
|
|
65
|
+
~/.dsh/sessions/--Users-open-Documents-Stocks--/session-b83e4a75-.../session.v4.jsonl.zstd
|
|
66
|
+
payload: {"phase":"ended","suspendedPhase":"blocked","inProgress":0,"violations":[]}
|
|
67
|
+
expanded: 分步进度 11/15 做好了 总体进度 73% 0 正在做 · 0 还没开始 4 卡住了
|
|
68
|
+
badge: 已结束,可续跑 · 卡住了
|
|
69
|
+
hint: 对主 Agent 说「续跑这个计划」,会从受阻处继续(已完成的不重跑)(还可续跑 4 次)
|
|
70
|
+
```
|
package/lib/host.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
2
5
|
/**
|
|
3
6
|
* Host half of dsh-workplan.
|
|
4
7
|
*
|
|
@@ -10,6 +13,46 @@ import { readFileSync } from 'node:fs';
|
|
|
10
13
|
*/
|
|
11
14
|
import { applyHardeningHeaders, cancelToolOutputSchema, createWorkplanRuntime, dispatchToolOutputSchema, plannerOutputSchema, statusToolOutputSchema, updateToolOutputSchema, } from './runtime.js';
|
|
12
15
|
import { isRecord } from './plan.js';
|
|
16
|
+
/*
|
|
17
|
+
* [1.8.14] Identity of the modules this process actually loaded (N1).
|
|
18
|
+
*
|
|
19
|
+
* `version` alone cannot answer "is the running process the build I just
|
|
20
|
+
* shipped": the same version can be rebuilt, and a profile recomposition can
|
|
21
|
+
* leave stale modules in memory while the files on disk are new. Hashing the
|
|
22
|
+
* compiled entry files that make up the plugin at activation time gives a
|
|
23
|
+
* value that changes whenever the loaded bytes change. It is computed once, so
|
|
24
|
+
* it cannot drift during the process's life.
|
|
25
|
+
*
|
|
26
|
+
* [1.8.15] `watchdog.js` was missing from the list even though runtime.ts
|
|
27
|
+
* imports it and the build copies it next to the other entries. Appending a
|
|
28
|
+
* line to it left the fingerprint unchanged (T5c §6.1) — a build identity that
|
|
29
|
+
* ignores a loaded module is a false negative, exactly what it exists to catch.
|
|
30
|
+
*/
|
|
31
|
+
const LOADED_BUILD = (() => {
|
|
32
|
+
try {
|
|
33
|
+
const entryPath = fileURLToPath(import.meta.url);
|
|
34
|
+
const dir = dirname(entryPath);
|
|
35
|
+
const hash = createHash('sha256');
|
|
36
|
+
for (const file of ['host.js', 'runtime.js', 'plan.js', 'watchdog.js']) {
|
|
37
|
+
hash.update(readFileSync(join(dir, file)));
|
|
38
|
+
}
|
|
39
|
+
return { entryPath, buildHash: hash.digest('hex').slice(0, 16) };
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
/*
|
|
43
|
+
* Never fail activation for a diagnostic. An unknown fingerprint is still a
|
|
44
|
+
* truthful answer ("I cannot prove which bytes I am"), and `status` will
|
|
45
|
+
* show `unknown` instead of a fabricated hash.
|
|
46
|
+
*/
|
|
47
|
+
return { entryPath: '', buildHash: 'unknown' };
|
|
48
|
+
}
|
|
49
|
+
})();
|
|
50
|
+
/*
|
|
51
|
+
* Process start time derived from `process.uptime()`, so it is the actual OS
|
|
52
|
+
* process start, not the moment the plugin was constructed. Used to tell
|
|
53
|
+
* "restarted after the fix" from "same process, rebuilt files on disk".
|
|
54
|
+
*/
|
|
55
|
+
const PROCESS_STARTED_AT = Date.now() - Math.round(process.uptime() * 1000);
|
|
13
56
|
function phaseLabel(phase) {
|
|
14
57
|
if (phase === 'paused')
|
|
15
58
|
return '本轮预算用尽,可续跑';
|
|
@@ -41,7 +84,24 @@ const PROMPT_SECTION = [
|
|
|
41
84
|
'2. 核对每个完成子任务的证据与验收标准,不合格的要用 dsh_workplan_update 标记为 blocked 或 in_progress;',
|
|
42
85
|
'3. 对受阻项向用户说明,必要时先询问再继续;',
|
|
43
86
|
'4. 不要声称未经验证的完成,不要重复派发已完成的子任务。',
|
|
44
|
-
|
|
87
|
+
/*
|
|
88
|
+
* [1.8.7] 硬规则:ok:true 不等于完成。
|
|
89
|
+
*
|
|
90
|
+
* 事故(session-99984ebd…)里模型把「本轮预算用尽,可续跑(10/13)」当成
|
|
91
|
+
* 成功,直接 present 并收尾。提示词必须把「complete 字段才是完成」写到
|
|
92
|
+
* 不可误解,并且与 runtime 的回合收尾闸门(agent/turn-stopping)形成双保险。
|
|
93
|
+
*/
|
|
94
|
+
/*
|
|
95
|
+
* [1.8.13] 用户明确取消不是完成。
|
|
96
|
+
*
|
|
97
|
+
* 1.8.7 的原文是「全部 done(或用户明确取消)」,T5-C 就是拿这句话把
|
|
98
|
+
* “取消 1/3 再 present”走通的:提示词把它写成完成等价物,present 的
|
|
99
|
+
* planIncomplete 又对 cancelled 短路。现在完成只有一个判据:全部 done
|
|
100
|
+
* 且 deliveryReady=true。
|
|
101
|
+
*/
|
|
102
|
+
'5. 「完成」只有一个判据:计划里全部子任务都是 done,**且** deliveryReady=true(每个 done 项 verification="structured"、acceptance 非空且逐项 result="pass"、无缺失产物)。用户取消 ≠ 完成:取消只停止执行,未完成项仍然是未完成。`dsh_workplan_dispatch` 返回 ok:true / complete:true 只表示调用成功或状态全 done,必须再看 deliveryReady 与 完成 X/Y;只要 deliveryReady=false 或还有 pending/blocked,就禁止 present 交付物、禁止写“已完成/最终版/已交付”、禁止给收尾性最终答复,必须先再次调用 dsh_workplan_dispatch 续跑剩余项。',
|
|
103
|
+
'6. 如果续跑被拒绝、受阻项无法恢复、证据补不齐、计划已取消但未完成,或用户要求先看中间结果:答复开头必须写「未完成:剩余 N 项(列出 ID)与原因」,正文只能按中间结果表述,不得包装成成品。取消不会给你交付许可。',
|
|
104
|
+
'结果消息里每个完成项都带 verification 与 acceptance:`structured` 是子 Agent 逐条自检通过,`unverified` 是自述但未逐条确认,`failed` 是自检失败(已按受阻处理),`legacy` 是旧格式回传。只有 structured 且 acceptance 每项 pass 才算可交付;其余必须你自己核对产物,并用 dsh_workplan_update 的 verification/acceptance/artifacts 字段把核对结果写回(这些字段会持久化、刷新后仍生效),不要把“看着没问题”当成证据。',
|
|
45
105
|
'子 Agent 通过 `needs` 提出的跨部门需求会列在结果消息的「跨部门待转达」里:由你逐条处理(补派、向用户确认或直接完成),不要忽略。',
|
|
46
106
|
'长任务可以用 `dsh_workplan_dispatch({ mode: "async" })` 先开跑并立即答复用户,再用 `dsh_workplan_status` 查看进度;async 返回的是“已开跑”,不是“已完成”。',
|
|
47
107
|
'如果自动分解降级,先向用户说明失败原因并询问是否重试,在用户确认前不要开始执行任务。',
|
|
@@ -81,7 +141,10 @@ function createUpdateTool(runtime) {
|
|
|
81
141
|
return {
|
|
82
142
|
name: 'dsh_workplan_update',
|
|
83
143
|
description: '更新当前任务分解计划中一个子任务的状态与证据。仅用于本会话已生成的主计划;子 Agent 不可调用。'
|
|
84
|
-
+ '当主 Agent 核对子任务结果、发现完成不实或需要修正时使用。'
|
|
144
|
+
+ '当主 Agent 核对子任务结果、发现完成不实或需要修正时使用。'
|
|
145
|
+
+ '把子任务标成 done 时,必须同时给出真实的 verification 与 acceptance(每项 result="pass"),'
|
|
146
|
+
+ '否则计划不会变成可交付状态(deliveryReady=false,present 会被拒绝)。'
|
|
147
|
+
+ '这些字段会写入会话日志,刷新/重启后仍然生效。',
|
|
85
148
|
parameters: {
|
|
86
149
|
type: 'object',
|
|
87
150
|
properties: {
|
|
@@ -105,7 +168,47 @@ function createUpdateTool(runtime) {
|
|
|
105
168
|
evidence: {
|
|
106
169
|
type: 'array',
|
|
107
170
|
items: { type: 'string' },
|
|
108
|
-
description: '
|
|
171
|
+
description: '支持该状态的证据(文件、命令输出、验收结果)。只用于说明,不参与可交付判定。',
|
|
172
|
+
},
|
|
173
|
+
verification: {
|
|
174
|
+
type: 'string',
|
|
175
|
+
enum: ['structured', 'legacy', 'unverified', 'failed'],
|
|
176
|
+
description: '证据等级:structured=逐条自检通过;unverified=自述未逐条确认;'
|
|
177
|
+
+ 'legacy=旧格式回传(没有结构化证据);failed=自检失败。'
|
|
178
|
+
+ '可交付要求 structured。',
|
|
179
|
+
},
|
|
180
|
+
acceptance: {
|
|
181
|
+
type: 'array',
|
|
182
|
+
description: '验收项及逐项结果;可交付要求非空且每项 result="pass"。',
|
|
183
|
+
items: {
|
|
184
|
+
type: 'object',
|
|
185
|
+
properties: {
|
|
186
|
+
criterion: { type: 'string', description: '验收标准。' },
|
|
187
|
+
result: { type: 'string', enum: ['pass', 'fail', 'unverified'], description: '该项结果。' },
|
|
188
|
+
evidence: { type: 'string', description: '支持该结果的证据(文件、命令输出、测试结果)。' },
|
|
189
|
+
},
|
|
190
|
+
required: ['criterion', 'result'],
|
|
191
|
+
additionalProperties: false,
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
artifacts: {
|
|
195
|
+
type: 'array',
|
|
196
|
+
description: '声明产物;kind=file/url/note,exists=false 表示产物缺失。',
|
|
197
|
+
items: {
|
|
198
|
+
type: 'object',
|
|
199
|
+
properties: {
|
|
200
|
+
kind: { type: 'string', enum: ['file', 'url', 'note'] },
|
|
201
|
+
ref: { type: 'string' },
|
|
202
|
+
exists: { type: 'boolean' },
|
|
203
|
+
},
|
|
204
|
+
required: ['kind', 'ref'],
|
|
205
|
+
additionalProperties: false,
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
missingArtifacts: {
|
|
209
|
+
type: 'array',
|
|
210
|
+
items: { type: 'string' },
|
|
211
|
+
description: '已知缺失的产物路径;非空时计划不可交付。',
|
|
109
212
|
},
|
|
110
213
|
expectedRevision: {
|
|
111
214
|
type: 'integer',
|
|
@@ -148,7 +251,9 @@ function createCancelTool(runtime) {
|
|
|
148
251
|
return {
|
|
149
252
|
name: 'dsh_workplan_cancel',
|
|
150
253
|
description: '取消当前会话尚未派发/正在等待派发的任务分解计划。仅取消计划记录,不伪造任何完成;'
|
|
151
|
-
+ '取消后计划在面板中显示为“已取消”,不会启动任何部门 Agent。'
|
|
254
|
+
+ '取消后计划在面板中显示为“已取消”,不会启动任何部门 Agent。'
|
|
255
|
+
+ '注意:取消不等于完成。取消后如仍有未完成项或证据缺口,present 仍会被拒绝,'
|
|
256
|
+
+ '答复必须按「未完成:剩余 N 项与原因」说明。',
|
|
152
257
|
parameters: {
|
|
153
258
|
type: 'object',
|
|
154
259
|
properties: {
|
|
@@ -167,9 +272,15 @@ function createCancelTool(runtime) {
|
|
|
167
272
|
schema: cancelToolOutputSchema(),
|
|
168
273
|
render(_args, value) {
|
|
169
274
|
const result = isRecord(value) ? value : {};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
275
|
+
if (!result.ok)
|
|
276
|
+
return textContent(`取消失败:${String(result.error ?? '未知错误')}`);
|
|
277
|
+
const stats = isRecord(result.stats) ? result.stats : {};
|
|
278
|
+
const cancelledIncomplete = result.phase !== 'done';
|
|
279
|
+
return textContent(`已取消计划 ${String(result.planId ?? '')}:${String(result.reason ?? '用户取消')}`
|
|
280
|
+
+ `(完成 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)})`
|
|
281
|
+
+ (cancelledIncomplete
|
|
282
|
+
? '|计划仍未完成:不要 present,不要写“已完成”;答复按「未完成:剩余 N 项与原因」开头。'
|
|
283
|
+
: '|计划此前已全部 done。'));
|
|
173
284
|
},
|
|
174
285
|
},
|
|
175
286
|
async execute(args, exec) {
|
|
@@ -200,15 +311,35 @@ function createStatusTool(runtime) {
|
|
|
200
311
|
render(_args, value) {
|
|
201
312
|
const result = isRecord(value) ? value : {};
|
|
202
313
|
const stats = isRecord(result.stats) ? result.stats : {};
|
|
203
|
-
|
|
204
|
-
|
|
314
|
+
const runtimeInfo = isRecord(result.runtime) ? result.runtime : {};
|
|
315
|
+
/*
|
|
316
|
+
* [1.8.14] Every answer names the loaded build, including the failure
|
|
317
|
+
* path. The restart verification in the incident report (§14.6 step 2)
|
|
318
|
+
* called `status` before any plan existed and got bare `NO_PLAN`, so it
|
|
319
|
+
* could not confirm which build was answering.
|
|
320
|
+
*/
|
|
321
|
+
const startedAt = Number(runtimeInfo.startedAt) || 0;
|
|
322
|
+
const identity = [
|
|
323
|
+
typeof result.version === 'string' ? `v${result.version}` : '',
|
|
324
|
+
typeof runtimeInfo.buildHash === 'string' ? `build ${runtimeInfo.buildHash}` : '',
|
|
325
|
+
Number(runtimeInfo.pid) > 0 ? `pid ${Number(runtimeInfo.pid)}` : '',
|
|
326
|
+
startedAt > 0
|
|
327
|
+
? `启动 ${new Date(startedAt).toLocaleString('zh-CN', { hour12: false })}`
|
|
328
|
+
: '',
|
|
329
|
+
].filter(Boolean).join('|');
|
|
330
|
+
if (!result.ok) {
|
|
331
|
+
return textContent(`查询失败:${String(result.error ?? '未知错误')}`
|
|
332
|
+
+ (identity ? `(${identity})` : ''));
|
|
333
|
+
}
|
|
205
334
|
const running = result.running === true;
|
|
206
335
|
return textContent(`计划 ${String(result.planId ?? '')}|${running ? '执行中' : '未在执行'}`
|
|
207
336
|
+ `|阶段:${phaseLabel(result.phase)}`
|
|
208
337
|
+ `|完成 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)},受阻 ${Number(stats.blocked ?? 0)}`
|
|
338
|
+
+ `|${result.deliveryReady === true ? '可交付' : '未就绪'}`
|
|
209
339
|
+ (running && Number(result.elapsedMs ?? 0) > 0
|
|
210
340
|
? `|已 ${Math.round(Number(result.elapsedMs) / 1000)}s`
|
|
211
|
-
: '')
|
|
341
|
+
: '')
|
|
342
|
+
+ (identity ? `|${identity}` : ''));
|
|
212
343
|
},
|
|
213
344
|
},
|
|
214
345
|
async execute(args, exec) {
|
|
@@ -220,8 +351,10 @@ function createStatusTool(runtime) {
|
|
|
220
351
|
function createDispatchTool(runtime) {
|
|
221
352
|
return {
|
|
222
353
|
name: 'dsh_workplan_dispatch',
|
|
223
|
-
description: '
|
|
224
|
-
+ '把 durable
|
|
354
|
+
description: '派发当前会话尚未执行的任务分解计划。计划显示后必须先调用本工具;wait 会等到本轮结束,'
|
|
355
|
+
+ '把 durable 结果写入会话并返回每个子任务的状态/摘要。'
|
|
356
|
+
+ '返回值里的 complete=false 表示计划还没做完(可能只是本轮预算用尽),此时必须再次派发续跑,'
|
|
357
|
+
+ '不得把当前产物当作最终结果。重复调用是幂等的。',
|
|
225
358
|
parameters: {
|
|
226
359
|
type: 'object',
|
|
227
360
|
properties: {
|
|
@@ -243,17 +376,53 @@ function createDispatchTool(runtime) {
|
|
|
243
376
|
render(_args, value) {
|
|
244
377
|
const result = isRecord(value) ? value : {};
|
|
245
378
|
const stats = isRecord(result.stats) ? result.stats : {};
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
+ (result.joined ? '|已加入进行中的派发并等到结果' : '')
|
|
379
|
+
const done = Number(stats.done ?? 0);
|
|
380
|
+
const total = Number(stats.total ?? 0);
|
|
381
|
+
const blocked = Number(stats.blocked ?? 0);
|
|
382
|
+
const remaining = Math.max(0, total - done);
|
|
383
|
+
const name = `计划 ${String(result.planId ?? '')}`;
|
|
384
|
+
if (!result.ok) {
|
|
253
385
|
// The hint carries the recovery instruction (resume, or take the work
|
|
254
386
|
// over directly); showing it in the rendered line keeps it visible
|
|
255
387
|
// even when only the summary is read.
|
|
256
|
-
|
|
388
|
+
return textContent(`派发失败:${String(result.error ?? '未知错误')}${result.hint ? `|下一步:${String(result.hint)}` : ''}`);
|
|
389
|
+
}
|
|
390
|
+
/*
|
|
391
|
+
* [1.8.7] The first word decides how the model reads the round.
|
|
392
|
+
*
|
|
393
|
+
* Incident: `ok:true` + "已加入进行中的派发并等到结果(完成 10/13)"
|
|
394
|
+
* read as "done", so the model presented a half-finished report. Now an
|
|
395
|
+
* unfinished round starts with 未完成 and states the only legal next
|
|
396
|
+
* move; a finished one is the only place the word 已完成 appears.
|
|
397
|
+
*/
|
|
398
|
+
if (result.mode === 'async' || (result.running === true && result.joined !== true)) {
|
|
399
|
+
return textContent(`${name} 已开跑,尚未完成:当前完成 ${done}/${total},剩余 ${remaining} 项由本轮执行`
|
|
400
|
+
+ `(${Math.round(elapsedSeconds(result) / 1000)}s)`
|
|
401
|
+
+ '|不要重复派发;结果消息会在本轮结束时自动写入。在结果消息到达并确认 complete=true 之前,不要给最终答复。');
|
|
402
|
+
}
|
|
403
|
+
/*
|
|
404
|
+
* [1.8.13] All rows done is not the finish line.
|
|
405
|
+
*
|
|
406
|
+
* T5-B/D: every row said done, no structured evidence, and this branch
|
|
407
|
+
* printed 已完成 — the model then presented. Only deliveryReady=true
|
|
408
|
+
* reaches the completion sentence; every other state names the gaps and
|
|
409
|
+
* the legal next move (dispatch, fix evidence, or report unfinished).
|
|
410
|
+
*/
|
|
411
|
+
if (result.deliveryReady === true) {
|
|
412
|
+
return textContent(`${name} 已完成且可交付:完成 ${done}/${total},证据通过`
|
|
413
|
+
+ (result.joined ? '|已加入进行中的派发并等到结果' : ''));
|
|
414
|
+
}
|
|
415
|
+
const blockers = Array.isArray(result.deliveryBlockers) ? result.deliveryBlockers.slice(0, 6).join(';') : '';
|
|
416
|
+
const cancelled = result.phase === 'cancelled';
|
|
417
|
+
const next = cancelled
|
|
418
|
+
? '计划已取消且未完成:不要再次 dispatch,不要 present;答复按「未完成:剩余 N 项与原因」开头。'
|
|
419
|
+
: remaining > 0
|
|
420
|
+
? '下一步:再次调用 dsh_workplan_dispatch 续跑剩余项;全部 done 之前不要 present。'
|
|
421
|
+
: "全部子任务虽已 done,但证据未通过:用 dsh_workplan_update 补 verification='structured' 与 acceptance(每项 result='pass'),或把对应项改回 blocked;不要 present。";
|
|
422
|
+
return textContent(`${name} 未就绪:完成 ${done}/${total},剩余 ${remaining} 项,受阻 ${blocked}(${phaseLabel(result.phase)})`
|
|
423
|
+
+ (blockers ? `|证据缺口:${blockers}` : '')
|
|
424
|
+
+ (result.joined ? '|本轮已返回,但计划没有达到可交付状态' : '')
|
|
425
|
+
+ `|${next}|不要写“已完成/最终版/已交付”,不要给收尾性最终答复。`);
|
|
257
426
|
},
|
|
258
427
|
},
|
|
259
428
|
/*
|
|
@@ -287,8 +456,37 @@ function numericSetting(configValue, envName) {
|
|
|
287
456
|
const numeric = Number(raw);
|
|
288
457
|
return Number.isFinite(numeric) && numeric > 0 ? numeric : undefined;
|
|
289
458
|
}
|
|
459
|
+
/**
|
|
460
|
+
* Hard, tool-level guards. Kept as a pure function so the contracts can be
|
|
461
|
+
* pinned without mounting the whole plugin:
|
|
462
|
+
* - plan mode:只拦住 dispatch,其他工具保持可用(避免死锁);
|
|
463
|
+
* - `present`:计划未完成时由 runtime 拒绝(事故中模型在收尾闸门之前
|
|
464
|
+
* present,卡片一旦出现就无法撤回)。
|
|
465
|
+
*/
|
|
466
|
+
export function toolGuardReason(exec, runtime) {
|
|
467
|
+
if (exec?.name === 'dsh_workplan_dispatch') {
|
|
468
|
+
const session = exec?.agent?.session;
|
|
469
|
+
if (session && runtime.planModeActive(session)) {
|
|
470
|
+
return '当前是 plan 模式:计划已生成,请先让用户审阅/退出 plan 模式,再调用 dsh_workplan_dispatch。';
|
|
471
|
+
}
|
|
472
|
+
return undefined;
|
|
473
|
+
}
|
|
474
|
+
if (exec?.name === 'present')
|
|
475
|
+
return runtime.presentDenialReason(exec?.agent);
|
|
476
|
+
return undefined;
|
|
477
|
+
}
|
|
290
478
|
export function apply(ctx, config = {}) {
|
|
291
479
|
const runtime = createWorkplanRuntime(ctx, {
|
|
480
|
+
// [1.8.13] The answering version must be visible in status/dispatch output,
|
|
481
|
+
// not inferred from the PID.
|
|
482
|
+
version: meta.version,
|
|
483
|
+
// [1.8.14] ...and so must the exact loaded build (see LOADED_BUILD above).
|
|
484
|
+
build: {
|
|
485
|
+
pid: process.pid,
|
|
486
|
+
startedAt: PROCESS_STARTED_AT,
|
|
487
|
+
entryPath: LOADED_BUILD.entryPath,
|
|
488
|
+
buildHash: LOADED_BUILD.buildHash,
|
|
489
|
+
},
|
|
292
490
|
cwd: typeof config.cwd === 'string' ? config.cwd : undefined,
|
|
293
491
|
childTimeoutMs: numericSetting(config.childTimeoutMs, 'DSH_WORKPLAN_CHILD_TIMEOUT_MS'),
|
|
294
492
|
idleTimeoutMs: numericSetting(config.idleTimeoutMs, 'DSH_WORKPLAN_IDLE_TIMEOUT_MS'),
|
|
@@ -308,17 +506,21 @@ export function apply(ctx, config = {}) {
|
|
|
308
506
|
* Plan mode produces a plan for review, not department execution. Denying
|
|
309
507
|
* only the dispatch tool keeps every other tool available (no deadlock)
|
|
310
508
|
* and gives the model a precise reason instead of a silent no-op.
|
|
509
|
+
*
|
|
510
|
+
* [1.8.8] `present` 也在执行前拦截:事故里模型在回合中途就把未完成
|
|
511
|
+
* 的产物 present 出去,回合收尾闸门再拦已经撤不回卡片。计划未完成时
|
|
512
|
+
* 拒绝交付,模型必须先续跑或显式取消计划。
|
|
311
513
|
*/
|
|
312
|
-
ctx.effect(() => ctx.tools.guard((exec) =>
|
|
313
|
-
if (exec?.name !== 'dsh_workplan_dispatch')
|
|
314
|
-
return undefined;
|
|
315
|
-
const session = exec?.agent?.session;
|
|
316
|
-
if (session && runtime.planModeActive(session)) {
|
|
317
|
-
return '当前是 plan 模式:计划已生成,请先让用户审阅/退出 plan 模式,再调用 dsh_workplan_dispatch。';
|
|
318
|
-
}
|
|
319
|
-
return undefined;
|
|
320
|
-
}));
|
|
514
|
+
ctx.effect(() => ctx.tools.guard((exec) => toolGuardReason(exec, runtime)));
|
|
321
515
|
ctx.effect(() => ctx.on('agent/pre-step', runtime.onPreStep));
|
|
516
|
+
/*
|
|
517
|
+
* [1.8.7] 回合收尾前的闸门。官方 `agent/turn-stopping` 是 serial 事件、
|
|
518
|
+
* 在边界提交前被 await;监听器 `agent.steer()` 后机器会重读 inbox,于是
|
|
519
|
+
* 「计划没做完」时回合不会被关闭。这是「未完成即输出」的唯一强制点:
|
|
520
|
+
* 提示词和工具文案只能说服模型,这个事件能拦住收尾本身。
|
|
521
|
+
*/
|
|
522
|
+
ctx.effect(() => ctx.on('agent/turn-stopping', runtime.onTurnStopping));
|
|
523
|
+
ctx.effect(() => ctx.tools.guard((exec) => fileWriteGuardReason(exec, runtime)));
|
|
322
524
|
ctx.inject(['webServer', 'connection'], (scope) => {
|
|
323
525
|
scope.effect(() => scope.webServer.register({
|
|
324
526
|
kind: 'exact',
|
|
@@ -371,8 +573,20 @@ export function apply(ctx, config = {}) {
|
|
|
371
573
|
}
|
|
372
574
|
export const meta = {
|
|
373
575
|
name,
|
|
374
|
-
version: '1.8.
|
|
576
|
+
version: '1.8.18',
|
|
375
577
|
promptOrder: PROMPT_ORDER,
|
|
376
578
|
routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
|
|
377
579
|
};
|
|
378
580
|
export { PROMPT_SECTION, createCancelTool, createDispatchTool, createStatusTool, createUpdateTool, plannerOutputSchema };
|
|
581
|
+
/**
|
|
582
|
+
* [1.8.18] 写工具的路径级闸门(T7-N2),与 `toolGuardReason` 分开注册。
|
|
583
|
+
*
|
|
584
|
+
* present/dispatch 的语义是「计划未就绪不能交付」;这里管的是「已交付的
|
|
585
|
+
* 文件不能在计划未就绪时被原地改写」。两条守卫都返回拒绝原因,harness
|
|
586
|
+
* 取第一个非空原因,互不覆盖。
|
|
587
|
+
*/
|
|
588
|
+
export function fileWriteGuardReason(exec, runtime) {
|
|
589
|
+
if (exec?.name !== 'write' && exec?.name !== 'edit' && exec?.name !== 'str_replace_editor')
|
|
590
|
+
return undefined;
|
|
591
|
+
return runtime.presentedWriteDenialReason(exec?.agent, exec?.arguments);
|
|
592
|
+
}
|