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
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -46,6 +46,8 @@ window.__ModuleLoader__.load({
|
|
|
46
46
|
"helpTitle": "先看这三句",
|
|
47
47
|
"helpWhat": "这件事",
|
|
48
48
|
"helpWho": "现在谁在做",
|
|
49
|
+
/* [1.8.5] 「已结束」的计划下面不许再写「现在谁在做」。 */
|
|
50
|
+
"helpWhere": "停在哪一步",
|
|
49
51
|
"helpNext": "接下来做什么",
|
|
50
52
|
"helpNobody": "还没开始",
|
|
51
53
|
"helpDone": "都做完了",
|
|
@@ -185,7 +187,7 @@ window.__ModuleLoader__.load({
|
|
|
185
187
|
"scopeAll": "当前各会话最新计划汇总",
|
|
186
188
|
"scopeThis": "本计划",
|
|
187
189
|
"vizStageTitle": "分步进度",
|
|
188
|
-
"
|
|
190
|
+
"vizOverall": "总体进度",
|
|
189
191
|
"allPlansHint": "上面是当前各会话最新计划的合计;历史计划不在此汇总,下面每张卡片只统计本计划。",
|
|
190
192
|
"openHint": "打开左侧「任务进度」看完整安排。"
|
|
191
193
|
},
|
|
@@ -217,6 +219,7 @@ window.__ModuleLoader__.load({
|
|
|
217
219
|
"helpTitle": "Start with these three",
|
|
218
220
|
"helpWhat": "This task",
|
|
219
221
|
"helpWho": "Who is doing it now",
|
|
222
|
+
"helpWhere": "Where it stopped",
|
|
220
223
|
"helpNext": "What happens next",
|
|
221
224
|
"helpNobody": "Not started yet",
|
|
222
225
|
"helpDone": "Everything is done",
|
|
@@ -356,7 +359,7 @@ window.__ModuleLoader__.load({
|
|
|
356
359
|
"scopeAll": "Latest plan per live session",
|
|
357
360
|
"scopeThis": "This plan",
|
|
358
361
|
"vizStageTitle": "Step progress",
|
|
359
|
-
"
|
|
362
|
+
"vizOverall": "Overall progress",
|
|
360
363
|
"allPlansHint": "These totals cover the latest plan in each live session; older plans are not included. Each card below counts only its own plan.",
|
|
361
364
|
"openHint": "Open “Task progress” on the left for the full plan."
|
|
362
365
|
}
|
|
@@ -1122,13 +1125,39 @@ window.__ModuleLoader__.load({
|
|
|
1122
1125
|
return t('helpNobody')
|
|
1123
1126
|
}
|
|
1124
1127
|
|
|
1128
|
+
/*
|
|
1129
|
+
* [1.8.5] 「谁在做」这三个字只能用在真的有东西在跑的时候。
|
|
1130
|
+
*
|
|
1131
|
+
* 事故(2026-10-30 21:38):计划已经「已结束,可续跑 · 卡住了」,卡片却仍写着
|
|
1132
|
+
* 「现在谁在做:研究分析 · 人性自私与利益博弈推演(卡住了)」,用户据此认为
|
|
1133
|
+
* 子智能体还在跑、报告和状态互相矛盾。同一句话在「没人跑」时应改口径为
|
|
1134
|
+
* 「停在哪一步」,把「现在进行时」换成「过去时」,不留误读空间。
|
|
1135
|
+
*/
|
|
1136
|
+
function workerLabel(session: any, t: any) {
|
|
1137
|
+
const active = findEntry(session, 'in_progress')
|
|
1138
|
+
return active ? t('helpWho') : t('helpWhere')
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1125
1141
|
/*
|
|
1126
1142
|
* A blocked card used to read "卡住了" and stop there: no hint that the plan
|
|
1127
1143
|
* is recoverable, so the only visible option was to restate the request and
|
|
1128
1144
|
* build a fresh plan. Say out loud how to resume instead.
|
|
1129
1145
|
*/
|
|
1130
1146
|
function resumeHint(session: any, t: any) {
|
|
1131
|
-
|
|
1147
|
+
/*
|
|
1148
|
+
* [1.8.4] 谁承诺「可续跑」,谁就必须给出续跑方法。
|
|
1149
|
+
*
|
|
1150
|
+
* 旧实现只在 `phase === 'blocked'` 时给指令,而徽标在 ended 状态下拼的是
|
|
1151
|
+
* 「已结束,可续跑 · 卡住了」——同一张卡一边承诺能续跑,一边返回空字符串
|
|
1152
|
+
* 不给任何操作,这是事故截图里的第三处自相矛盾(T3 的互斥证据)。
|
|
1153
|
+
* 现在凡是徽标会说出「可续跑」的阶段(blocked / paused / ended 且原阶段
|
|
1154
|
+
* 是这类可续跑状态),一律给出同样的续跑指令。
|
|
1155
|
+
*/
|
|
1156
|
+
if (!session) return ''
|
|
1157
|
+
const phase = String(session.phase ?? '')
|
|
1158
|
+
const suspended = String(session.suspendedPhase ?? '')
|
|
1159
|
+
const resumable = phase === 'blocked' || phase === 'paused' || (phase === 'ended' && (suspended === '' || suspended === 'blocked' || suspended === 'paused' || suspended === 'executing' || suspended === 'planning'))
|
|
1160
|
+
if (!resumable) return ''
|
|
1132
1161
|
if (session.resumeAvailable) {
|
|
1133
1162
|
const limit = Number(session.resumeLimit ?? 0)
|
|
1134
1163
|
const used = Number(session.resumeCount ?? 0)
|
|
@@ -1185,7 +1214,7 @@ window.__ModuleLoader__.load({
|
|
|
1185
1214
|
h('div', { className: 'dsh-wp-guide-value' }, what),
|
|
1186
1215
|
),
|
|
1187
1216
|
h('div', { className: 'dsh-wp-guide-row' },
|
|
1188
|
-
h('div', { className: 'dsh-wp-guide-label' }, t
|
|
1217
|
+
h('div', { className: 'dsh-wp-guide-label' }, workerLabel(session, t)),
|
|
1189
1218
|
h('div', { className: 'dsh-wp-guide-value' }, workerText(session, t)),
|
|
1190
1219
|
),
|
|
1191
1220
|
h('div', { className: 'dsh-wp-guide-row' },
|
|
@@ -1609,15 +1638,22 @@ window.__ModuleLoader__.load({
|
|
|
1609
1638
|
}
|
|
1610
1639
|
|
|
1611
1640
|
/*
|
|
1612
|
-
* [1.
|
|
1641
|
+
* [1.8.4] 一张卡片的阶段只能有一个结论,且必须让「存活事实」拥有否决权。
|
|
1613
1642
|
*
|
|
1614
|
-
*
|
|
1615
|
-
*
|
|
1643
|
+
* 事故截图(2026-10-30 20:06:33)里同一张卡在「已结束」组,第 4 步却写着
|
|
1644
|
+
* 「正在做」。根因在后端(`turn/end` 早于异步派发结束),但展示层同样要能
|
|
1645
|
+
* 自保:服务端现在把 `running` 一起下发,这里据此兜一层——载荷同时说
|
|
1646
|
+
* 「已结束」和「派发仍在跑」时,以存活事实为准,绝不渲染「已结束」。
|
|
1647
|
+
* 老载荷没有 `running` 字段(undefined),行为保持原样。
|
|
1616
1648
|
*/
|
|
1617
|
-
function
|
|
1618
|
-
const
|
|
1619
|
-
|
|
1620
|
-
|
|
1649
|
+
function sessionPhaseOf(session: any, counts?: PlanCounts): string {
|
|
1650
|
+
const resolved = counts ?? planCounts(session?.stats || {})
|
|
1651
|
+
const phase = planPhaseOf(session?.phase || 'pending', resolved)
|
|
1652
|
+
if (phase === 'ended' && session?.running === true) {
|
|
1653
|
+
const suspended = String(session?.suspendedPhase ?? '')
|
|
1654
|
+
return suspended !== '' && suspended !== 'ended' ? suspended : 'executing'
|
|
1655
|
+
}
|
|
1656
|
+
return phase
|
|
1621
1657
|
}
|
|
1622
1658
|
|
|
1623
1659
|
function planStatusMap(statuses: any): Map<string, any> {
|
|
@@ -1858,7 +1894,7 @@ window.__ModuleLoader__.load({
|
|
|
1858
1894
|
)
|
|
1859
1895
|
}
|
|
1860
1896
|
|
|
1861
|
-
// 展开后的「分步进度」:逐阶段行 +
|
|
1897
|
+
// 展开后的「分步进度」:逐阶段行 + 总体进度(与环/组头同一个计数口径)。
|
|
1862
1898
|
function PlanOverview({ t, stats, counts, rows }: { t: (key: string) => string; stats: any; counts: PlanCounts; rows: PlanStageRow[] }) {
|
|
1863
1899
|
const stateOf = (tone: PlanTone): string => (tone === 'done'
|
|
1864
1900
|
? t('stats.done')
|
|
@@ -1873,7 +1909,15 @@ window.__ModuleLoader__.load({
|
|
|
1873
1909
|
h('span', null, `${counts.done}/${counts.total} ${t('stats.done')}`),
|
|
1874
1910
|
),
|
|
1875
1911
|
h('div', { className: 'dsh-wp-planoverview-stats' },
|
|
1876
|
-
|
|
1912
|
+
/*
|
|
1913
|
+
* [1.8.4] 一张卡只允许一个百分比口径。
|
|
1914
|
+
*
|
|
1915
|
+
* 这里以前显示加权进度,卡片其余位置显示计数百分比,于是同一张卡同时
|
|
1916
|
+
* 出现「73%」(环、组头、本计划 11/15)和「总体进度(加权)80%」——
|
|
1917
|
+
* 两者都算得对,但用户看到的是自相矛盾(T3 实测)。展示口径统一为
|
|
1918
|
+
* 计数百分比:它就是环、组头、图例共用的那个数,也是用户能数出来的数。
|
|
1919
|
+
*/
|
|
1920
|
+
h('span', null, `${t('vizOverall')} ${counts.percent === null ? '—' : `${counts.percent}%`}`),
|
|
1877
1921
|
h('span', null, `${counts.active} ${t('stats.inProgress')} · ${counts.pending} ${t('stats.pending')}`),
|
|
1878
1922
|
counts.blocked > 0 ? h('span', null, `${counts.blocked} ${t('stats.blocked')}`) : null,
|
|
1879
1923
|
),
|
|
@@ -1916,7 +1960,7 @@ window.__ModuleLoader__.load({
|
|
|
1916
1960
|
* 胶囊就必须是「已完成」,视觉档位也必须是 done。截图里那张卡之所以
|
|
1917
1961
|
* 「100% + 正在收尾 + 留在进行中组」,就是因为这三个读者各读各的字段。
|
|
1918
1962
|
*/
|
|
1919
|
-
const phase =
|
|
1963
|
+
const phase = sessionPhaseOf(session, counts)
|
|
1920
1964
|
const tone = phaseTone(phase)
|
|
1921
1965
|
const departments = Array.isArray(session.departments) ? session.departments : []
|
|
1922
1966
|
const statuses = Array.isArray(session.statuses) ? session.statuses : []
|
|
@@ -2389,7 +2433,7 @@ window.__ModuleLoader__.load({
|
|
|
2389
2433
|
const counts = planCounts(stats)
|
|
2390
2434
|
// 同一套计数与对账:柱状图的百分比、文案、色调都不得自成一套。
|
|
2391
2435
|
const percent = counts.percent ?? 0
|
|
2392
|
-
const phase =
|
|
2436
|
+
const phase = sessionPhaseOf(session, counts)
|
|
2393
2437
|
const tone = phaseTone(phase)
|
|
2394
2438
|
return h('button', {
|
|
2395
2439
|
key: session.sessionId,
|
|
@@ -2477,7 +2521,7 @@ window.__ModuleLoader__.load({
|
|
|
2477
2521
|
* 这正是本次事故的现象:会话结束 4 小时后仍显示「进行中」。
|
|
2478
2522
|
*/
|
|
2479
2523
|
for (const session of activeSessions) {
|
|
2480
|
-
const phase =
|
|
2524
|
+
const phase = sessionPhaseOf(session)
|
|
2481
2525
|
if (phase === 'done') finished.push(session)
|
|
2482
2526
|
else if (phase === 'ended') ended.push(session)
|
|
2483
2527
|
else live.push(session)
|
|
@@ -2498,7 +2542,7 @@ window.__ModuleLoader__.load({
|
|
|
2498
2542
|
pending: 5,
|
|
2499
2543
|
ended: 6,
|
|
2500
2544
|
}
|
|
2501
|
-
const rank = (session: any) => phaseRank[
|
|
2545
|
+
const rank = (session: any) => phaseRank[sessionPhaseOf(session)] ?? 5
|
|
2502
2546
|
live.sort((a: any, b: any) => (rank(a) - rank(b))
|
|
2503
2547
|
|| ((Number(b.createdAt) || 0) - (Number(a.createdAt) || 0))
|
|
2504
2548
|
|| String(a.sessionId).localeCompare(String(b.sessionId)))
|
|
@@ -2667,7 +2711,7 @@ window.__ModuleLoader__.load({
|
|
|
2667
2711
|
* 「侧栏已完成 / 对话里正在收尾」之间再次自相矛盾。
|
|
2668
2712
|
*/
|
|
2669
2713
|
const stats = session.stats || {}
|
|
2670
|
-
const phase =
|
|
2714
|
+
const phase = sessionPhaseOf(session)
|
|
2671
2715
|
const tone = phaseTone(phase)
|
|
2672
2716
|
return h('div', { className: `dsh-wp-turn dsh-wp-tone-${tone}` },
|
|
2673
2717
|
h('div', { className: 'dsh-wp-turn-title' },
|
|
@@ -2675,7 +2719,7 @@ window.__ModuleLoader__.load({
|
|
|
2675
2719
|
h(Pill, { tone }, phaseLabel(phase, session, t)),
|
|
2676
2720
|
),
|
|
2677
2721
|
h('div', { className: 'dsh-wp-muted', style: { marginTop: '6px' } },
|
|
2678
|
-
`${t
|
|
2722
|
+
`${workerLabel(session, t)}:${workerText(session, t)}`),
|
|
2679
2723
|
h('div', { className: 'dsh-wp-muted', style: { marginTop: '2px' } },
|
|
2680
2724
|
`${t('helpNext')}:${nextText(session, t)}`),
|
|
2681
2725
|
h('div', { className: 'dsh-wp-progress-meta' },
|
package/src/host.ts
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
|
*
|
|
@@ -20,6 +23,47 @@ import {
|
|
|
20
23
|
} from './runtime.js'
|
|
21
24
|
import { isRecord } from './plan.js'
|
|
22
25
|
|
|
26
|
+
/*
|
|
27
|
+
* [1.8.14] Identity of the modules this process actually loaded (N1).
|
|
28
|
+
*
|
|
29
|
+
* `version` alone cannot answer "is the running process the build I just
|
|
30
|
+
* shipped": the same version can be rebuilt, and a profile recomposition can
|
|
31
|
+
* leave stale modules in memory while the files on disk are new. Hashing the
|
|
32
|
+
* compiled entry files that make up the plugin at activation time gives a
|
|
33
|
+
* value that changes whenever the loaded bytes change. It is computed once, so
|
|
34
|
+
* it cannot drift during the process's life.
|
|
35
|
+
*
|
|
36
|
+
* [1.8.15] `watchdog.js` was missing from the list even though runtime.ts
|
|
37
|
+
* imports it and the build copies it next to the other entries. Appending a
|
|
38
|
+
* line to it left the fingerprint unchanged (T5c §6.1) — a build identity that
|
|
39
|
+
* ignores a loaded module is a false negative, exactly what it exists to catch.
|
|
40
|
+
*/
|
|
41
|
+
const LOADED_BUILD = (() => {
|
|
42
|
+
try {
|
|
43
|
+
const entryPath = fileURLToPath(import.meta.url)
|
|
44
|
+
const dir = dirname(entryPath)
|
|
45
|
+
const hash = createHash('sha256')
|
|
46
|
+
for (const file of ['host.js', 'runtime.js', 'plan.js', 'watchdog.js']) {
|
|
47
|
+
hash.update(readFileSync(join(dir, file)))
|
|
48
|
+
}
|
|
49
|
+
return { entryPath, buildHash: hash.digest('hex').slice(0, 16) }
|
|
50
|
+
} catch {
|
|
51
|
+
/*
|
|
52
|
+
* Never fail activation for a diagnostic. An unknown fingerprint is still a
|
|
53
|
+
* truthful answer ("I cannot prove which bytes I am"), and `status` will
|
|
54
|
+
* show `unknown` instead of a fabricated hash.
|
|
55
|
+
*/
|
|
56
|
+
return { entryPath: '', buildHash: 'unknown' }
|
|
57
|
+
}
|
|
58
|
+
})()
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
* Process start time derived from `process.uptime()`, so it is the actual OS
|
|
62
|
+
* process start, not the moment the plugin was constructed. Used to tell
|
|
63
|
+
* "restarted after the fix" from "same process, rebuilt files on disk".
|
|
64
|
+
*/
|
|
65
|
+
const PROCESS_STARTED_AT = Date.now() - Math.round(process.uptime() * 1000)
|
|
66
|
+
|
|
23
67
|
function phaseLabel(phase: any) {
|
|
24
68
|
if (phase === 'paused') return '本轮预算用尽,可续跑'
|
|
25
69
|
if (phase === 'blocked') return '卡住了'
|
|
@@ -48,7 +92,24 @@ const PROMPT_SECTION = [
|
|
|
48
92
|
'2. 核对每个完成子任务的证据与验收标准,不合格的要用 dsh_workplan_update 标记为 blocked 或 in_progress;',
|
|
49
93
|
'3. 对受阻项向用户说明,必要时先询问再继续;',
|
|
50
94
|
'4. 不要声称未经验证的完成,不要重复派发已完成的子任务。',
|
|
51
|
-
|
|
95
|
+
/*
|
|
96
|
+
* [1.8.7] 硬规则:ok:true 不等于完成。
|
|
97
|
+
*
|
|
98
|
+
* 事故(session-99984ebd…)里模型把「本轮预算用尽,可续跑(10/13)」当成
|
|
99
|
+
* 成功,直接 present 并收尾。提示词必须把「complete 字段才是完成」写到
|
|
100
|
+
* 不可误解,并且与 runtime 的回合收尾闸门(agent/turn-stopping)形成双保险。
|
|
101
|
+
*/
|
|
102
|
+
/*
|
|
103
|
+
* [1.8.13] 用户明确取消不是完成。
|
|
104
|
+
*
|
|
105
|
+
* 1.8.7 的原文是「全部 done(或用户明确取消)」,T5-C 就是拿这句话把
|
|
106
|
+
* “取消 1/3 再 present”走通的:提示词把它写成完成等价物,present 的
|
|
107
|
+
* planIncomplete 又对 cancelled 短路。现在完成只有一个判据:全部 done
|
|
108
|
+
* 且 deliveryReady=true。
|
|
109
|
+
*/
|
|
110
|
+
'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 续跑剩余项。',
|
|
111
|
+
'6. 如果续跑被拒绝、受阻项无法恢复、证据补不齐、计划已取消但未完成,或用户要求先看中间结果:答复开头必须写「未完成:剩余 N 项(列出 ID)与原因」,正文只能按中间结果表述,不得包装成成品。取消不会给你交付许可。',
|
|
112
|
+
'结果消息里每个完成项都带 verification 与 acceptance:`structured` 是子 Agent 逐条自检通过,`unverified` 是自述但未逐条确认,`failed` 是自检失败(已按受阻处理),`legacy` 是旧格式回传。只有 structured 且 acceptance 每项 pass 才算可交付;其余必须你自己核对产物,并用 dsh_workplan_update 的 verification/acceptance/artifacts 字段把核对结果写回(这些字段会持久化、刷新后仍生效),不要把“看着没问题”当成证据。',
|
|
52
113
|
'子 Agent 通过 `needs` 提出的跨部门需求会列在结果消息的「跨部门待转达」里:由你逐条处理(补派、向用户确认或直接完成),不要忽略。',
|
|
53
114
|
'长任务可以用 `dsh_workplan_dispatch({ mode: "async" })` 先开跑并立即答复用户,再用 `dsh_workplan_status` 查看进度;async 返回的是“已开跑”,不是“已完成”。',
|
|
54
115
|
'如果自动分解降级,先向用户说明失败原因并询问是否重试,在用户确认前不要开始执行任务。',
|
|
@@ -98,7 +159,10 @@ function createUpdateTool(runtime: any) {
|
|
|
98
159
|
name: 'dsh_workplan_update',
|
|
99
160
|
description:
|
|
100
161
|
'更新当前任务分解计划中一个子任务的状态与证据。仅用于本会话已生成的主计划;子 Agent 不可调用。'
|
|
101
|
-
+ '当主 Agent 核对子任务结果、发现完成不实或需要修正时使用。'
|
|
162
|
+
+ '当主 Agent 核对子任务结果、发现完成不实或需要修正时使用。'
|
|
163
|
+
+ '把子任务标成 done 时,必须同时给出真实的 verification 与 acceptance(每项 result="pass"),'
|
|
164
|
+
+ '否则计划不会变成可交付状态(deliveryReady=false,present 会被拒绝)。'
|
|
165
|
+
+ '这些字段会写入会话日志,刷新/重启后仍然生效。',
|
|
102
166
|
parameters: {
|
|
103
167
|
type: 'object',
|
|
104
168
|
properties: {
|
|
@@ -122,7 +186,47 @@ function createUpdateTool(runtime: any) {
|
|
|
122
186
|
evidence: {
|
|
123
187
|
type: 'array',
|
|
124
188
|
items: { type: 'string' },
|
|
125
|
-
description: '
|
|
189
|
+
description: '支持该状态的证据(文件、命令输出、验收结果)。只用于说明,不参与可交付判定。',
|
|
190
|
+
},
|
|
191
|
+
verification: {
|
|
192
|
+
type: 'string',
|
|
193
|
+
enum: ['structured', 'legacy', 'unverified', 'failed'],
|
|
194
|
+
description: '证据等级:structured=逐条自检通过;unverified=自述未逐条确认;'
|
|
195
|
+
+ 'legacy=旧格式回传(没有结构化证据);failed=自检失败。'
|
|
196
|
+
+ '可交付要求 structured。',
|
|
197
|
+
},
|
|
198
|
+
acceptance: {
|
|
199
|
+
type: 'array',
|
|
200
|
+
description: '验收项及逐项结果;可交付要求非空且每项 result="pass"。',
|
|
201
|
+
items: {
|
|
202
|
+
type: 'object',
|
|
203
|
+
properties: {
|
|
204
|
+
criterion: { type: 'string', description: '验收标准。' },
|
|
205
|
+
result: { type: 'string', enum: ['pass', 'fail', 'unverified'], description: '该项结果。' },
|
|
206
|
+
evidence: { type: 'string', description: '支持该结果的证据(文件、命令输出、测试结果)。' },
|
|
207
|
+
},
|
|
208
|
+
required: ['criterion', 'result'],
|
|
209
|
+
additionalProperties: false,
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
artifacts: {
|
|
213
|
+
type: 'array',
|
|
214
|
+
description: '声明产物;kind=file/url/note,exists=false 表示产物缺失。',
|
|
215
|
+
items: {
|
|
216
|
+
type: 'object',
|
|
217
|
+
properties: {
|
|
218
|
+
kind: { type: 'string', enum: ['file', 'url', 'note'] },
|
|
219
|
+
ref: { type: 'string' },
|
|
220
|
+
exists: { type: 'boolean' },
|
|
221
|
+
},
|
|
222
|
+
required: ['kind', 'ref'],
|
|
223
|
+
additionalProperties: false,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
missingArtifacts: {
|
|
227
|
+
type: 'array',
|
|
228
|
+
items: { type: 'string' },
|
|
229
|
+
description: '已知缺失的产物路径;非空时计划不可交付。',
|
|
126
230
|
},
|
|
127
231
|
expectedRevision: {
|
|
128
232
|
type: 'integer',
|
|
@@ -166,7 +270,9 @@ function createCancelTool(runtime: any) {
|
|
|
166
270
|
name: 'dsh_workplan_cancel',
|
|
167
271
|
description:
|
|
168
272
|
'取消当前会话尚未派发/正在等待派发的任务分解计划。仅取消计划记录,不伪造任何完成;'
|
|
169
|
-
+ '取消后计划在面板中显示为“已取消”,不会启动任何部门 Agent。'
|
|
273
|
+
+ '取消后计划在面板中显示为“已取消”,不会启动任何部门 Agent。'
|
|
274
|
+
+ '注意:取消不等于完成。取消后如仍有未完成项或证据缺口,present 仍会被拒绝,'
|
|
275
|
+
+ '答复必须按「未完成:剩余 N 项与原因」说明。',
|
|
170
276
|
parameters: {
|
|
171
277
|
type: 'object',
|
|
172
278
|
properties: {
|
|
@@ -185,10 +291,15 @@ function createCancelTool(runtime: any) {
|
|
|
185
291
|
schema: cancelToolOutputSchema(),
|
|
186
292
|
render(_args: any, value: any) {
|
|
187
293
|
const result = isRecord(value) ? value : {}
|
|
294
|
+
if (!result.ok) return textContent(`取消失败:${String(result.error ?? '未知错误')}`)
|
|
295
|
+
const stats = isRecord(result.stats) ? result.stats : {}
|
|
296
|
+
const cancelledIncomplete = result.phase !== 'done'
|
|
188
297
|
return textContent(
|
|
189
|
-
result.
|
|
190
|
-
|
|
191
|
-
|
|
298
|
+
`已取消计划 ${String(result.planId ?? '')}:${String(result.reason ?? '用户取消')}`
|
|
299
|
+
+ `(完成 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)})`
|
|
300
|
+
+ (cancelledIncomplete
|
|
301
|
+
? '|计划仍未完成:不要 present,不要写“已完成”;答复按「未完成:剩余 N 项与原因」开头。'
|
|
302
|
+
: '|计划此前已全部 done。'),
|
|
192
303
|
)
|
|
193
304
|
},
|
|
194
305
|
},
|
|
@@ -221,15 +332,38 @@ function createStatusTool(runtime: any) {
|
|
|
221
332
|
render(_args: any, value: any) {
|
|
222
333
|
const result = isRecord(value) ? value : {}
|
|
223
334
|
const stats = isRecord(result.stats) ? result.stats : {}
|
|
224
|
-
|
|
335
|
+
const runtimeInfo = isRecord(result.runtime) ? result.runtime : {}
|
|
336
|
+
/*
|
|
337
|
+
* [1.8.14] Every answer names the loaded build, including the failure
|
|
338
|
+
* path. The restart verification in the incident report (§14.6 step 2)
|
|
339
|
+
* called `status` before any plan existed and got bare `NO_PLAN`, so it
|
|
340
|
+
* could not confirm which build was answering.
|
|
341
|
+
*/
|
|
342
|
+
const startedAt = Number(runtimeInfo.startedAt) || 0
|
|
343
|
+
const identity = [
|
|
344
|
+
typeof result.version === 'string' ? `v${result.version}` : '',
|
|
345
|
+
typeof runtimeInfo.buildHash === 'string' ? `build ${runtimeInfo.buildHash}` : '',
|
|
346
|
+
Number(runtimeInfo.pid) > 0 ? `pid ${Number(runtimeInfo.pid)}` : '',
|
|
347
|
+
startedAt > 0
|
|
348
|
+
? `启动 ${new Date(startedAt).toLocaleString('zh-CN', { hour12: false })}`
|
|
349
|
+
: '',
|
|
350
|
+
].filter(Boolean).join('|')
|
|
351
|
+
if (!result.ok) {
|
|
352
|
+
return textContent(
|
|
353
|
+
`查询失败:${String(result.error ?? '未知错误')}`
|
|
354
|
+
+ (identity ? `(${identity})` : ''),
|
|
355
|
+
)
|
|
356
|
+
}
|
|
225
357
|
const running = result.running === true
|
|
226
358
|
return textContent(
|
|
227
|
-
`计划 ${String(result.planId ?? '')}|${running ? '执行中' : '未在执行'}`
|
|
359
|
+
`计划 ${String(result.planId ?? '')}|${running ? '执行中' : '未在执行'}`
|
|
228
360
|
+ `|阶段:${phaseLabel(result.phase)}`
|
|
229
361
|
+ `|完成 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)},受阻 ${Number(stats.blocked ?? 0)}`
|
|
362
|
+
+ `|${result.deliveryReady === true ? '可交付' : '未就绪'}`
|
|
230
363
|
+ (running && Number(result.elapsedMs ?? 0) > 0
|
|
231
364
|
? `|已 ${Math.round(Number(result.elapsedMs) / 1000)}s`
|
|
232
|
-
: '')
|
|
365
|
+
: '')
|
|
366
|
+
+ (identity ? `|${identity}` : ''),
|
|
233
367
|
)
|
|
234
368
|
},
|
|
235
369
|
},
|
|
@@ -244,8 +378,10 @@ function createDispatchTool(runtime: any) {
|
|
|
244
378
|
return {
|
|
245
379
|
name: 'dsh_workplan_dispatch',
|
|
246
380
|
description:
|
|
247
|
-
'
|
|
248
|
-
+ '把 durable
|
|
381
|
+
'派发当前会话尚未执行的任务分解计划。计划显示后必须先调用本工具;wait 会等到本轮结束,'
|
|
382
|
+
+ '把 durable 结果写入会话并返回每个子任务的状态/摘要。'
|
|
383
|
+
+ '返回值里的 complete=false 表示计划还没做完(可能只是本轮预算用尽),此时必须再次派发续跑,'
|
|
384
|
+
+ '不得把当前产物当作最终结果。重复调用是幂等的。',
|
|
249
385
|
parameters: {
|
|
250
386
|
type: 'object',
|
|
251
387
|
properties: {
|
|
@@ -267,18 +403,58 @@ function createDispatchTool(runtime: any) {
|
|
|
267
403
|
render(_args: any, value: any) {
|
|
268
404
|
const result = isRecord(value) ? value : {}
|
|
269
405
|
const stats = isRecord(result.stats) ? result.stats : {}
|
|
406
|
+
const done = Number(stats.done ?? 0)
|
|
407
|
+
const total = Number(stats.total ?? 0)
|
|
408
|
+
const blocked = Number(stats.blocked ?? 0)
|
|
409
|
+
const remaining = Math.max(0, total - done)
|
|
410
|
+
const name = `计划 ${String(result.planId ?? '')}`
|
|
411
|
+
if (!result.ok) {
|
|
412
|
+
// The hint carries the recovery instruction (resume, or take the work
|
|
413
|
+
// over directly); showing it in the rendered line keeps it visible
|
|
414
|
+
// even when only the summary is read.
|
|
415
|
+
return textContent(`派发失败:${String(result.error ?? '未知错误')}${result.hint ? `|下一步:${String(result.hint)}` : ''}`)
|
|
416
|
+
}
|
|
417
|
+
/*
|
|
418
|
+
* [1.8.7] The first word decides how the model reads the round.
|
|
419
|
+
*
|
|
420
|
+
* Incident: `ok:true` + "已加入进行中的派发并等到结果(完成 10/13)"
|
|
421
|
+
* read as "done", so the model presented a half-finished report. Now an
|
|
422
|
+
* unfinished round starts with 未完成 and states the only legal next
|
|
423
|
+
* move; a finished one is the only place the word 已完成 appears.
|
|
424
|
+
*/
|
|
425
|
+
if (result.mode === 'async' || (result.running === true && result.joined !== true)) {
|
|
426
|
+
return textContent(
|
|
427
|
+
`${name} 已开跑,尚未完成:当前完成 ${done}/${total},剩余 ${remaining} 项由本轮执行`
|
|
428
|
+
+ `(${Math.round(elapsedSeconds(result) / 1000)}s)`
|
|
429
|
+
+ '|不要重复派发;结果消息会在本轮结束时自动写入。在结果消息到达并确认 complete=true 之前,不要给最终答复。',
|
|
430
|
+
)
|
|
431
|
+
}
|
|
432
|
+
/*
|
|
433
|
+
* [1.8.13] All rows done is not the finish line.
|
|
434
|
+
*
|
|
435
|
+
* T5-B/D: every row said done, no structured evidence, and this branch
|
|
436
|
+
* printed 已完成 — the model then presented. Only deliveryReady=true
|
|
437
|
+
* reaches the completion sentence; every other state names the gaps and
|
|
438
|
+
* the legal next move (dispatch, fix evidence, or report unfinished).
|
|
439
|
+
*/
|
|
440
|
+
if (result.deliveryReady === true) {
|
|
441
|
+
return textContent(
|
|
442
|
+
`${name} 已完成且可交付:完成 ${done}/${total},证据通过`
|
|
443
|
+
+ (result.joined ? '|已加入进行中的派发并等到结果' : ''),
|
|
444
|
+
)
|
|
445
|
+
}
|
|
446
|
+
const blockers = Array.isArray(result.deliveryBlockers) ? result.deliveryBlockers.slice(0, 6).join(';') : ''
|
|
447
|
+
const cancelled = result.phase === 'cancelled'
|
|
448
|
+
const next = cancelled
|
|
449
|
+
? '计划已取消且未完成:不要再次 dispatch,不要 present;答复按「未完成:剩余 N 项与原因」开头。'
|
|
450
|
+
: remaining > 0
|
|
451
|
+
? '下一步:再次调用 dsh_workplan_dispatch 续跑剩余项;全部 done 之前不要 present。'
|
|
452
|
+
: "全部子任务虽已 done,但证据未通过:用 dsh_workplan_update 补 verification='structured' 与 acceptance(每项 result='pass'),或把对应项改回 blocked;不要 present。"
|
|
270
453
|
return textContent(
|
|
271
|
-
result.
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
? `|已在执行(${Math.round(elapsedSeconds(result) / 1000)}s)`
|
|
276
|
-
: '')
|
|
277
|
-
+ (result.joined ? '|已加入进行中的派发并等到结果' : '')
|
|
278
|
-
// The hint carries the recovery instruction (resume, or take the work
|
|
279
|
-
// over directly); showing it in the rendered line keeps it visible
|
|
280
|
-
// even when only the summary is read.
|
|
281
|
-
: `派发失败:${String(result.error ?? '未知错误')}${result.hint ? `|下一步:${String(result.hint)}` : ''}`,
|
|
454
|
+
`${name} 未就绪:完成 ${done}/${total},剩余 ${remaining} 项,受阻 ${blocked}(${phaseLabel(result.phase)})`
|
|
455
|
+
+ (blockers ? `|证据缺口:${blockers}` : '')
|
|
456
|
+
+ (result.joined ? '|本轮已返回,但计划没有达到可交付状态' : '')
|
|
457
|
+
+ `|${next}|不要写“已完成/最终版/已交付”,不要给收尾性最终答复。`,
|
|
282
458
|
)
|
|
283
459
|
},
|
|
284
460
|
},
|
|
@@ -313,8 +489,40 @@ function numericSetting(configValue: any, envName: string) {
|
|
|
313
489
|
return Number.isFinite(numeric) && numeric > 0 ? numeric : undefined
|
|
314
490
|
}
|
|
315
491
|
|
|
492
|
+
/**
|
|
493
|
+
* Hard, tool-level guards. Kept as a pure function so the contracts can be
|
|
494
|
+
* pinned without mounting the whole plugin:
|
|
495
|
+
* - plan mode:只拦住 dispatch,其他工具保持可用(避免死锁);
|
|
496
|
+
* - `present`:计划未完成时由 runtime 拒绝(事故中模型在收尾闸门之前
|
|
497
|
+
* present,卡片一旦出现就无法撤回)。
|
|
498
|
+
*/
|
|
499
|
+
export function toolGuardReason(
|
|
500
|
+
exec: any,
|
|
501
|
+
runtime: { planModeActive(session: any): boolean; presentDenialReason(agent: any): string | undefined },
|
|
502
|
+
) {
|
|
503
|
+
if (exec?.name === 'dsh_workplan_dispatch') {
|
|
504
|
+
const session = exec?.agent?.session
|
|
505
|
+
if (session && runtime.planModeActive(session)) {
|
|
506
|
+
return '当前是 plan 模式:计划已生成,请先让用户审阅/退出 plan 模式,再调用 dsh_workplan_dispatch。'
|
|
507
|
+
}
|
|
508
|
+
return undefined
|
|
509
|
+
}
|
|
510
|
+
if (exec?.name === 'present') return runtime.presentDenialReason(exec?.agent)
|
|
511
|
+
return undefined
|
|
512
|
+
}
|
|
513
|
+
|
|
316
514
|
export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
317
515
|
const runtime = createWorkplanRuntime(ctx, {
|
|
516
|
+
// [1.8.13] The answering version must be visible in status/dispatch output,
|
|
517
|
+
// not inferred from the PID.
|
|
518
|
+
version: meta.version,
|
|
519
|
+
// [1.8.14] ...and so must the exact loaded build (see LOADED_BUILD above).
|
|
520
|
+
build: {
|
|
521
|
+
pid: process.pid,
|
|
522
|
+
startedAt: PROCESS_STARTED_AT,
|
|
523
|
+
entryPath: LOADED_BUILD.entryPath,
|
|
524
|
+
buildHash: LOADED_BUILD.buildHash,
|
|
525
|
+
},
|
|
318
526
|
cwd: typeof config.cwd === 'string' ? config.cwd : undefined,
|
|
319
527
|
childTimeoutMs: numericSetting(config.childTimeoutMs, 'DSH_WORKPLAN_CHILD_TIMEOUT_MS'),
|
|
320
528
|
idleTimeoutMs: numericSetting(config.idleTimeoutMs, 'DSH_WORKPLAN_IDLE_TIMEOUT_MS'),
|
|
@@ -339,17 +547,22 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
|
339
547
|
* Plan mode produces a plan for review, not department execution. Denying
|
|
340
548
|
* only the dispatch tool keeps every other tool available (no deadlock)
|
|
341
549
|
* and gives the model a precise reason instead of a silent no-op.
|
|
550
|
+
*
|
|
551
|
+
* [1.8.8] `present` 也在执行前拦截:事故里模型在回合中途就把未完成
|
|
552
|
+
* 的产物 present 出去,回合收尾闸门再拦已经撤不回卡片。计划未完成时
|
|
553
|
+
* 拒绝交付,模型必须先续跑或显式取消计划。
|
|
342
554
|
*/
|
|
343
|
-
ctx.effect(() => ctx.tools.guard((exec: any) =>
|
|
344
|
-
if (exec?.name !== 'dsh_workplan_dispatch') return undefined
|
|
345
|
-
const session = exec?.agent?.session
|
|
346
|
-
if (session && runtime.planModeActive(session)) {
|
|
347
|
-
return '当前是 plan 模式:计划已生成,请先让用户审阅/退出 plan 模式,再调用 dsh_workplan_dispatch。'
|
|
348
|
-
}
|
|
349
|
-
return undefined
|
|
350
|
-
}))
|
|
555
|
+
ctx.effect(() => ctx.tools.guard((exec: any) => toolGuardReason(exec, runtime)))
|
|
351
556
|
|
|
352
557
|
ctx.effect(() => ctx.on('agent/pre-step', runtime.onPreStep))
|
|
558
|
+
/*
|
|
559
|
+
* [1.8.7] 回合收尾前的闸门。官方 `agent/turn-stopping` 是 serial 事件、
|
|
560
|
+
* 在边界提交前被 await;监听器 `agent.steer()` 后机器会重读 inbox,于是
|
|
561
|
+
* 「计划没做完」时回合不会被关闭。这是「未完成即输出」的唯一强制点:
|
|
562
|
+
* 提示词和工具文案只能说服模型,这个事件能拦住收尾本身。
|
|
563
|
+
*/
|
|
564
|
+
ctx.effect(() => ctx.on('agent/turn-stopping', runtime.onTurnStopping))
|
|
565
|
+
ctx.effect(() => ctx.tools.guard((exec: any) => fileWriteGuardReason(exec, runtime)))
|
|
353
566
|
|
|
354
567
|
ctx.inject(['webServer', 'connection'], (scope: any) => {
|
|
355
568
|
scope.effect(() =>
|
|
@@ -408,9 +621,24 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
|
408
621
|
|
|
409
622
|
export const meta = {
|
|
410
623
|
name,
|
|
411
|
-
version: '1.8.
|
|
624
|
+
version: '1.8.18',
|
|
412
625
|
promptOrder: PROMPT_ORDER,
|
|
413
626
|
routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
|
|
414
627
|
}
|
|
415
628
|
|
|
416
629
|
export { PROMPT_SECTION, createCancelTool, createDispatchTool, createStatusTool, createUpdateTool, plannerOutputSchema }
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* [1.8.18] 写工具的路径级闸门(T7-N2),与 `toolGuardReason` 分开注册。
|
|
633
|
+
*
|
|
634
|
+
* present/dispatch 的语义是「计划未就绪不能交付」;这里管的是「已交付的
|
|
635
|
+
* 文件不能在计划未就绪时被原地改写」。两条守卫都返回拒绝原因,harness
|
|
636
|
+
* 取第一个非空原因,互不覆盖。
|
|
637
|
+
*/
|
|
638
|
+
export function fileWriteGuardReason(
|
|
639
|
+
exec: any,
|
|
640
|
+
runtime: { presentedWriteDenialReason(agent: any, args: any): string | undefined },
|
|
641
|
+
) {
|
|
642
|
+
if (exec?.name !== 'write' && exec?.name !== 'edit' && exec?.name !== 'str_replace_editor') return undefined
|
|
643
|
+
return runtime.presentedWriteDenialReason(exec?.agent, exec?.arguments)
|
|
644
|
+
}
|