dsh-workplan 1.8.18 → 1.10.6
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 +354 -0
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/client.js +55 -4
- package/docs/postmortem-1.8.7-20261031.md +113 -0
- package/docs/release-notes-1.9.1.md +67 -0
- package/lib/auto-resume.js +175 -0
- package/lib/client.js +2605 -0
- package/lib/host.js +134 -5
- package/lib/plan.js +295 -12
- package/lib/runtime.js +892 -63
- package/lib/supersede-digest.js +115 -0
- package/lib/supersede.js +378 -0
- package/package.json +2 -2
- package/src/auto-resume.ts +246 -0
- package/src/client.ts +59 -3
- package/src/host.ts +152 -4
- package/src/plan.ts +308 -12
- package/src/runtime.ts +925 -61
- package/src/supersede-digest.ts +116 -0
- package/src/supersede.ts +429 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [1.10.4][auto-resume] Automatic continuation of a plan whose round budget ran out.
|
|
3
|
+
*
|
|
4
|
+
* Why this module exists
|
|
5
|
+
* ----------------------
|
|
6
|
+
* The 2026-11-01 incident: subtask T12 was killed by the whole-round budget
|
|
7
|
+
* (`TOTAL_TIMEOUT`, 20 min) at 15:31:26, reset to `pending`, and then **never
|
|
8
|
+
* ran again** — the plan stayed `paused` until a human dispatched it 24 minutes
|
|
9
|
+
* later. `shouldRetryAttempt()` is right to refuse `ABORTED`/`TOTAL_TIMEOUT`
|
|
10
|
+
* *inside* a round: that round has no budget left, so a retry would be cut by
|
|
11
|
+
* the same blade. The missing layer is not "retry the child"; it is
|
|
12
|
+
* "start the next round" — a new deadline, the same plan, and `done` work
|
|
13
|
+
* never re-run.
|
|
14
|
+
*
|
|
15
|
+
* This module owns only the decision table (`should we continue?`). It is a
|
|
16
|
+
* pure function with no timer, no I/O and no record mutation, so every branch
|
|
17
|
+
* can be pinned by a unit test without mounting the host. The runtime supplies
|
|
18
|
+
* the bookkeeping; `src/runtime.ts` owns the timer.
|
|
19
|
+
*
|
|
20
|
+
* Safety stance (the reason it is more than a loop)
|
|
21
|
+
* -------------------------------------------------
|
|
22
|
+
* Automatic recovery must never manufacture a green result. Therefore:
|
|
23
|
+
* - it only ever continues a `paused` plan; `blocked` means a real failure and
|
|
24
|
+
* is repaired by a human adjudication or the resume budget, never silently;
|
|
25
|
+
* - `done` rows are never re-run (the resumer calls `resetBlockedStatuses`,
|
|
26
|
+
* which only clears blocked/in_progress, and a paused round leaves them
|
|
27
|
+
* `pending`);
|
|
28
|
+
* - it never adjudicates evidence: every continuation goes through the normal
|
|
29
|
+
* child path (`settleFromOutput` → `deliveryReadiness`), so "all done" is
|
|
30
|
+
* still decided by structured evidence;
|
|
31
|
+
* - "all done but evidence gaps" stops here on purpose (`NOTHING_PENDING`):
|
|
32
|
+
* re-running a done subtask cannot fix a missing acceptance item, it only
|
|
33
|
+
* produces duplicate work and a chance to overwrite the evidence.
|
|
34
|
+
*
|
|
35
|
+
* Default: **off**. See `AUTO_RESUME_DEFAULTS.enabled`.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/** Tunables that are policy, not deployment config. */
|
|
39
|
+
export const AUTO_RESUME_DEFAULTS = Object.freeze({
|
|
40
|
+
/**
|
|
41
|
+
* [1.10.6] On by default.
|
|
42
|
+
*
|
|
43
|
+
* The 2026-11-01 user verdict on the previous "off by default" stance was
|
|
44
|
+
* unambiguous: a subtask killed by the round budget sat untouched for 1h57m
|
|
45
|
+
* and the only reason was a flag nobody had been told to flip. A recovery
|
|
46
|
+
* feature that ships silent is indistinguishable from a missing one.
|
|
47
|
+
*
|
|
48
|
+
* Every safety branch below still applies when this is on (cancel, plan mode,
|
|
49
|
+
* blocked rows, no-progress, attempt cap), and `autoResume: false` in the
|
|
50
|
+
* profile or `DSH_WORKPLAN_AUTO_RESUME=0` turns it off for one deployment.
|
|
51
|
+
*/
|
|
52
|
+
enabled: true,
|
|
53
|
+
/** How many continuation rounds one plan may start without a human. */
|
|
54
|
+
maxAttempts: 2,
|
|
55
|
+
/** Delay before the first continuation round. */
|
|
56
|
+
baseDelayMs: 30_000,
|
|
57
|
+
/** Upper bound of the exponential backoff. */
|
|
58
|
+
maxDelayMs: 300_000,
|
|
59
|
+
/** Consecutive continuation rounds that completed no new subtask before stopping. */
|
|
60
|
+
stallLimit: 1,
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
/** Hard cap for a configured attempt budget (0 disables the chain). */
|
|
64
|
+
export const AUTO_RESUME_MAX_ATTEMPTS_CAP = 4
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Clamp a configured attempt budget.
|
|
68
|
+
*
|
|
69
|
+
* Non-numeric input falls back to the default instead of disabling the feature
|
|
70
|
+
* silently; only an explicit in-range number is honoured.
|
|
71
|
+
*
|
|
72
|
+
* @param value - configured value, if any.
|
|
73
|
+
* @returns an integer within `[0, AUTO_RESUME_MAX_ATTEMPTS_CAP]`.
|
|
74
|
+
*/
|
|
75
|
+
export function autoResumeAttemptCap(value: any) {
|
|
76
|
+
const numeric = Number(value)
|
|
77
|
+
if (!Number.isFinite(numeric)) return AUTO_RESUME_DEFAULTS.maxAttempts
|
|
78
|
+
return Math.min(AUTO_RESUME_MAX_ATTEMPTS_CAP, Math.max(0, Math.floor(numeric)))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* [1.10.6] Resolve the feature flag from profile config + environment.
|
|
83
|
+
*
|
|
84
|
+
* Explicit config wins; an explicit environment value wins over the default;
|
|
85
|
+
* anything unset falls back to `AUTO_RESUME_DEFAULTS.enabled` (now true).
|
|
86
|
+
* Values are read the same way for both sources so `0/false/no/off` turn it off
|
|
87
|
+
* instead of being treated as "present, therefore on".
|
|
88
|
+
*
|
|
89
|
+
* @param configValue - `autoResume` from the profile config, if any.
|
|
90
|
+
* @param envValue - `DSH_WORKPLAN_AUTO_RESUME`, if set.
|
|
91
|
+
* @returns whether automatic continuation rounds are allowed.
|
|
92
|
+
*/
|
|
93
|
+
export function autoResumeEnabledFrom(configValue: any, envValue: any) {
|
|
94
|
+
if (typeof configValue === 'boolean') return configValue
|
|
95
|
+
const raw = envValue === undefined || envValue === null ? '' : String(envValue).trim()
|
|
96
|
+
if (raw !== '') {
|
|
97
|
+
if (/^(1|true|yes|on)$/i.test(raw)) return true
|
|
98
|
+
if (/^(0|false|no|off)$/i.test(raw)) return false
|
|
99
|
+
}
|
|
100
|
+
return AUTO_RESUME_DEFAULTS.enabled === true
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** `schedule` = arm the next round; `stop` = leave the plan to a human. */
|
|
104
|
+
export type AutoResumeAction = 'schedule' | 'stop'
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Why the machine stopped. Stable strings: the status tool exposes them and
|
|
108
|
+
* tests assert on the literal values.
|
|
109
|
+
*/
|
|
110
|
+
export type AutoResumeCode =
|
|
111
|
+
| 'SCHEDULED'
|
|
112
|
+
| 'AUTO_RESUME_DISABLED'
|
|
113
|
+
| 'NO_PLAN'
|
|
114
|
+
| 'CANCELLED'
|
|
115
|
+
| 'SUPERSEDED'
|
|
116
|
+
| 'ALREADY_RUNNING'
|
|
117
|
+
| 'PLAN_MODE'
|
|
118
|
+
| 'PHASE_NOT_PAUSED'
|
|
119
|
+
| 'NOTHING_PENDING'
|
|
120
|
+
| 'HAS_BLOCKED'
|
|
121
|
+
| 'BUDGET_EXHAUSTED'
|
|
122
|
+
| 'NO_PROGRESS'
|
|
123
|
+
|
|
124
|
+
/** Everything the decision needs; all fields are primitives by design. */
|
|
125
|
+
export interface AutoResumeInput {
|
|
126
|
+
/** Feature flag. */
|
|
127
|
+
enabled: boolean
|
|
128
|
+
/** `record.phase` at the moment the round ended. */
|
|
129
|
+
phase: string
|
|
130
|
+
/** The user stopped this plan. */
|
|
131
|
+
cancelled: boolean
|
|
132
|
+
/** Automatic decomposition degraded; there is no usable plan. */
|
|
133
|
+
degraded: boolean
|
|
134
|
+
/** The session is in plan mode (a plan is for review, not execution). */
|
|
135
|
+
planMode: boolean
|
|
136
|
+
/** A dispatch is still in flight. */
|
|
137
|
+
running: boolean
|
|
138
|
+
/** Defined subtasks. */
|
|
139
|
+
total: number
|
|
140
|
+
/** Subtasks currently `done`. */
|
|
141
|
+
done: number
|
|
142
|
+
/** Subtasks currently `pending`. */
|
|
143
|
+
pending: number
|
|
144
|
+
/** Subtasks currently `blocked`. */
|
|
145
|
+
blocked: number
|
|
146
|
+
/** Continuation rounds already started by this machine. */
|
|
147
|
+
attempt: number
|
|
148
|
+
/** Configured continuation budget. */
|
|
149
|
+
maxAttempts: number
|
|
150
|
+
/** Consecutive continuation rounds that added no `done` row. */
|
|
151
|
+
noProgressRounds: number
|
|
152
|
+
/** Stop after this many stalled rounds. */
|
|
153
|
+
stallLimit: number
|
|
154
|
+
/** Backoff base. */
|
|
155
|
+
baseDelayMs: number
|
|
156
|
+
/** Backoff ceiling. */
|
|
157
|
+
maxDelayMs: number
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface AutoResumeDecision {
|
|
161
|
+
action: AutoResumeAction
|
|
162
|
+
code: AutoResumeCode
|
|
163
|
+
/** Human/model readable; goes into `record.errors` and the status tool. */
|
|
164
|
+
reason: string
|
|
165
|
+
/** Attempt index of the round that would start (unchanged when stopping). */
|
|
166
|
+
attempt: number
|
|
167
|
+
/** Delay before that round; `0` when stopping. */
|
|
168
|
+
delayMs: number
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Decide whether one more round may start, and when.
|
|
173
|
+
*
|
|
174
|
+
* Branch order is the contract (first match wins):
|
|
175
|
+
* 1. feature flag / no plan
|
|
176
|
+
* 2. user stop (`cancelled`, `superseded`) — never resurrect a decision
|
|
177
|
+
* 3. already running / plan mode
|
|
178
|
+
* 4. only a `paused` phase is auto-continuable
|
|
179
|
+
* 5. nothing pending (includes "all done, evidence gap" — human work)
|
|
180
|
+
* 6. any `blocked` row — a real failure, not a budget artifact
|
|
181
|
+
* 7. attempt / progress budgets
|
|
182
|
+
*
|
|
183
|
+
* @param input - the frozen facts of the round that just ended.
|
|
184
|
+
* @returns the decision plus a model-readable reason.
|
|
185
|
+
*/
|
|
186
|
+
export function decideAutoResume(input: AutoResumeInput): AutoResumeDecision {
|
|
187
|
+
const attempt = Math.max(0, Math.floor(Number(input.attempt) || 0))
|
|
188
|
+
const maxAttempts = Math.max(0, Math.floor(Number(input.maxAttempts) || 0))
|
|
189
|
+
const stop = (code: AutoResumeCode, reason: string): AutoResumeDecision => ({
|
|
190
|
+
action: 'stop',
|
|
191
|
+
code,
|
|
192
|
+
reason,
|
|
193
|
+
attempt,
|
|
194
|
+
delayMs: 0,
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
if (input.enabled !== true) {
|
|
198
|
+
return stop('AUTO_RESUME_DISABLED', '自动续跑开关未开启(默认关闭)')
|
|
199
|
+
}
|
|
200
|
+
if (input.degraded === true || Number(input.total) <= 0) {
|
|
201
|
+
return stop('NO_PLAN', '没有可续跑的计划(自动分解降级或子任务数为 0)')
|
|
202
|
+
}
|
|
203
|
+
if (input.cancelled === true || input.phase === 'cancelled') {
|
|
204
|
+
return stop('CANCELLED', '用户已取消:自动重来等于违背停下的决定')
|
|
205
|
+
}
|
|
206
|
+
if (input.phase === 'superseded') {
|
|
207
|
+
return stop('SUPERSEDED', '责任已转移到承接计划,本计划不得自动续跑')
|
|
208
|
+
}
|
|
209
|
+
if (input.running === true) {
|
|
210
|
+
return stop('ALREADY_RUNNING', '已有一轮在跑,不能并发再开一轮')
|
|
211
|
+
}
|
|
212
|
+
if (input.planMode === true) {
|
|
213
|
+
return stop('PLAN_MODE', 'plan 模式下计划只供审阅,不自动执行')
|
|
214
|
+
}
|
|
215
|
+
if (input.phase !== 'paused') {
|
|
216
|
+
return stop('PHASE_NOT_PAUSED', `计划阶段是 ${String(input.phase ?? 'unknown')},只有 paused(预算到点)才自动续跑`)
|
|
217
|
+
}
|
|
218
|
+
if (Number(input.pending) <= 0) {
|
|
219
|
+
/*
|
|
220
|
+
* Also the evidence-gap case: all rows done but deliveryReady=false.
|
|
221
|
+
* Re-running done work is forbidden by the delivery contract; the gap can
|
|
222
|
+
* only be closed by a human re-adjudication, so stop and say so.
|
|
223
|
+
*/
|
|
224
|
+
return stop('NOTHING_PENDING', '没有 pending 项:若仍未就绪,那是证据缺口,需主 Agent 复核,不能靠重跑 done 项解决')
|
|
225
|
+
}
|
|
226
|
+
if (Number(input.blocked) > 0) {
|
|
227
|
+
return stop('HAS_BLOCKED', `存在 ${input.blocked} 个 blocked 子任务:那是真实失败,需人工改判或显式续跑,不自动修复`)
|
|
228
|
+
}
|
|
229
|
+
if (attempt >= maxAttempts) {
|
|
230
|
+
return stop('BUDGET_EXHAUSTED', `自动续跑已用满 ${maxAttempts} 轮,交给主 Agent 决定`)
|
|
231
|
+
}
|
|
232
|
+
if (Number(input.noProgressRounds) >= Math.max(1, Number(input.stallLimit) || 1)) {
|
|
233
|
+
return stop('NO_PROGRESS', `连续 ${input.noProgressRounds} 轮没有新增完成项,停止空转`)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const base = Math.max(0, Number(input.baseDelayMs) || 0)
|
|
237
|
+
const cap = Math.max(base, Number(input.maxDelayMs) || base)
|
|
238
|
+
const delayMs = Math.min(cap, base * Math.pow(2, attempt))
|
|
239
|
+
return {
|
|
240
|
+
action: 'schedule',
|
|
241
|
+
code: 'SCHEDULED',
|
|
242
|
+
reason: `第 ${attempt + 1}/${maxAttempts} 轮自动续跑将在 ${Math.round(delayMs / 1000)}s 后开始`,
|
|
243
|
+
attempt: attempt + 1,
|
|
244
|
+
delayMs,
|
|
245
|
+
}
|
|
246
|
+
}
|
package/src/client.ts
CHANGED
|
@@ -77,6 +77,7 @@ window.__ModuleLoader__.load({
|
|
|
77
77
|
"paused": "预算用完,可续跑",
|
|
78
78
|
"degraded": "安排失败",
|
|
79
79
|
"cancelled": "已取消",
|
|
80
|
+
"superseded": "已由他计划承接",
|
|
80
81
|
"ended": "已结束,可续跑"
|
|
81
82
|
},
|
|
82
83
|
"status": {
|
|
@@ -118,6 +119,10 @@ window.__ModuleLoader__.load({
|
|
|
118
119
|
"willDeliver": "做完交付",
|
|
119
120
|
"waitFor": "要等",
|
|
120
121
|
"blockedReason": "卡住原因",
|
|
122
|
+
"pendingReason": "还没做完的原因",
|
|
123
|
+
"lastErrorNote": "上一轮的失败记录(已完成,仅留档)",
|
|
124
|
+
"notDeliverable": "还不能交付",
|
|
125
|
+
"notDeliverableHint": "「全部做完」不等于「可以交付」:交付还需要每一行都有可核对的证据。下面是没有通过的部分。",
|
|
121
126
|
"progressLabel": "进度",
|
|
122
127
|
"more": "更多细节(不看也不影响理解)",
|
|
123
128
|
"why": "为什么这样安排",
|
|
@@ -290,6 +295,10 @@ window.__ModuleLoader__.load({
|
|
|
290
295
|
"willDeliver": "What it delivers",
|
|
291
296
|
"waitFor": "Waits for",
|
|
292
297
|
"blockedReason": "Why it is stuck",
|
|
298
|
+
"pendingReason": "Why it is not finished yet",
|
|
299
|
+
"lastErrorNote": "Previous attempt's failure (done, kept for the record)",
|
|
300
|
+
"notDeliverable": "Not deliverable yet",
|
|
301
|
+
"notDeliverableHint": "All rows done does not mean deliverable: every row needs checkable evidence. The gaps are listed below.",
|
|
293
302
|
"progressLabel": "Progress",
|
|
294
303
|
"more": "More detail (optional)",
|
|
295
304
|
"why": "Why it is arranged this way",
|
|
@@ -1441,7 +1450,21 @@ window.__ModuleLoader__.load({
|
|
|
1441
1450
|
status === 'in_progress' ? h(Progress, { value: pct, tone }) : null,
|
|
1442
1451
|
status === 'in_progress' ? h('div', { className: 'dsh-wp-progress-meta' }, h('span', null, `${t('progressLabel')} ${pct}%`)) : null,
|
|
1443
1452
|
status !== 'blocked' && item?.summary ? h('p', { className: 'dsh-wp-muted' }, `${t('summary')}:${plainError(item.summary)}`) : null,
|
|
1444
|
-
|
|
1453
|
+
/*
|
|
1454
|
+
* [1.10.0] R-02:「卡住原因」只属于没做完的行。
|
|
1455
|
+
*
|
|
1456
|
+
* 1.9.1 无条件渲染 `item.error`,只要历史记录里残留一句失败文本,就会在
|
|
1457
|
+
* 一行 status=done 的卡片下面写「卡住原因:本轮预算用尽…」——「已完成」
|
|
1458
|
+
* 与「卡住了」同屏,正是用户截图里的矛盾。数据层已经保证 done 行没有
|
|
1459
|
+
* error(I12),这里再做一次呈现守卫:任何历史载荷、旧缓存都不会重现。
|
|
1460
|
+
*/
|
|
1461
|
+
item?.error && status !== 'done'
|
|
1462
|
+
? h('p', { className: 'dsh-wp-error-text' },
|
|
1463
|
+
`${t(status === 'blocked' ? 'blockedReason' : 'pendingReason')}:${plainError(item.error)}`)
|
|
1464
|
+
: null,
|
|
1465
|
+
status === 'done' && item?.lastError
|
|
1466
|
+
? h('p', { className: 'dsh-wp-muted' }, `${t('lastErrorNote')}:${plainError(item.lastError)}`)
|
|
1467
|
+
: null,
|
|
1445
1468
|
h('details', { className: 'dsh-wp-details' },
|
|
1446
1469
|
h('summary', null, t('more')),
|
|
1447
1470
|
h('div', { className: 'dsh-wp-grid', style: { marginTop: '8px' } },
|
|
@@ -1600,6 +1623,22 @@ window.__ModuleLoader__.load({
|
|
|
1600
1623
|
return total > 0 ? Math.round((done / total) * 100) : null
|
|
1601
1624
|
}
|
|
1602
1625
|
|
|
1626
|
+
/*
|
|
1627
|
+
* [1.10.0] C-11:100% 只有一个来源。
|
|
1628
|
+
*
|
|
1629
|
+
* `done/total` 是「行数」,服务端的 `stats.progress` 是「加权完成度」,
|
|
1630
|
+
* 二者在 12 done + 1 blocked@95 时分别是 92 与 95(T3 实测)。界面只展示
|
|
1631
|
+
* 一个数:行数百分比;但只要加权口径还差一点(或全部行 done 却不可交付),
|
|
1632
|
+
* 就不允许显示成 100——"100%" 在这一页上必须同时意味着「每行都做完」。
|
|
1633
|
+
*/
|
|
1634
|
+
function cappedPercent(raw: number | null, stats: any): number | null {
|
|
1635
|
+
if (raw === null) return null
|
|
1636
|
+
const weighted = Number(stats?.progress)
|
|
1637
|
+
if (raw >= 100 && Number.isFinite(weighted) && weighted < 100) return 99
|
|
1638
|
+
if (raw > 100) return 100
|
|
1639
|
+
return raw
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1603
1642
|
// 与 groupTotals 同一套口径:先夹到 [0,total],再让「正在做/还没开始」
|
|
1604
1643
|
// 吃掉剩余量,四段之和恒等于总数(构成条不会溢出或出现负宽度)。
|
|
1605
1644
|
function planCounts(stats: any): PlanCounts {
|
|
@@ -1609,7 +1648,7 @@ window.__ModuleLoader__.load({
|
|
|
1609
1648
|
const blocked = Math.min(planCount(source.blocked), total - done)
|
|
1610
1649
|
const active = Math.min(planCount(source.inProgress), total - done - blocked)
|
|
1611
1650
|
const pending = Math.max(0, total - done - blocked - active)
|
|
1612
|
-
return { total, done, active, blocked, pending, percent: planPercent(done, total) }
|
|
1651
|
+
return { total, done, active, blocked, pending, percent: cappedPercent(planPercent(done, total), source) }
|
|
1613
1652
|
}
|
|
1614
1653
|
|
|
1615
1654
|
/*
|
|
@@ -1986,6 +2025,23 @@ window.__ModuleLoader__.load({
|
|
|
1986
2025
|
h('div', null, plainError(session.error || '')),
|
|
1987
2026
|
h('div', { className: 'dsh-wp-muted' }, t('degradedHint')),
|
|
1988
2027
|
) : null,
|
|
2028
|
+
/*
|
|
2029
|
+
* [1.10.0] C-09:把服务端已经下发、却从来没人读的交付门禁搬上界面。
|
|
2030
|
+
*
|
|
2031
|
+
* 1.9.1 的载荷里一直带着 `deliveryReady / deliveryBlockers`(present 用的
|
|
2032
|
+
* 就是同一份判定),但 `client.ts` 一处都没消费。于是「13/13、100%、绿」,
|
|
2033
|
+
* 而 present 被拒——「进度 100% ≠ 可交付」这条事实在界面上完全不可见。
|
|
2034
|
+
*/
|
|
2035
|
+
session.deliveryReady === false
|
|
2036
|
+
? h('div', { className: 'dsh-wp-banner dsh-wp-banner--degraded' },
|
|
2037
|
+
h('strong', null, t('notDeliverable')),
|
|
2038
|
+
h('div', { className: 'dsh-wp-muted' }, t('notDeliverableHint')),
|
|
2039
|
+
Array.isArray(session.deliveryBlockers) && session.deliveryBlockers.length
|
|
2040
|
+
? h('ul', { className: 'dsh-wp-muted' },
|
|
2041
|
+
session.deliveryBlockers.slice(0, 6).map((blocker: any, index: any) =>
|
|
2042
|
+
h('li', { key: index }, plainError(String(blocker)))))
|
|
2043
|
+
: null,
|
|
2044
|
+
) : null,
|
|
1989
2045
|
h(Guide, { session, t }),
|
|
1990
2046
|
departments.length ? h('div', { className: 'dsh-wp-section' },
|
|
1991
2047
|
h('div', { className: 'dsh-wp-section-title' }, t('who')),
|
|
@@ -2593,7 +2649,7 @@ window.__ModuleLoader__.load({
|
|
|
2593
2649
|
return {
|
|
2594
2650
|
label: raw.length > 14 ? `${raw.slice(0, 14)}…` : raw,
|
|
2595
2651
|
// [1.5.2] 与卡片/组头同一个百分比函数,杜绝第二套口径。
|
|
2596
|
-
value: planPercent(planCount(session.stats?.done), planCount(session.stats?.total)) ?? 0,
|
|
2652
|
+
value: cappedPercent(planPercent(planCount(session.stats?.done), planCount(session.stats?.total)), session.stats) ?? 0,
|
|
2597
2653
|
}
|
|
2598
2654
|
}), [groups, t])
|
|
2599
2655
|
/*
|
package/src/host.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
updateToolOutputSchema,
|
|
23
23
|
} from './runtime.js'
|
|
24
24
|
import { isRecord } from './plan.js'
|
|
25
|
+
import { autoResumeEnabledFrom } from './auto-resume.js'
|
|
25
26
|
|
|
26
27
|
/*
|
|
27
28
|
* [1.8.14] Identity of the modules this process actually loaded (N1).
|
|
@@ -109,6 +110,7 @@ const PROMPT_SECTION = [
|
|
|
109
110
|
*/
|
|
110
111
|
'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
112
|
'6. 如果续跑被拒绝、受阻项无法恢复、证据补不齐、计划已取消但未完成,或用户要求先看中间结果:答复开头必须写「未完成:剩余 N 项(列出 ID)与原因」,正文只能按中间结果表述,不得包装成成品。取消不会给你交付许可。',
|
|
113
|
+
'7. 子任务有硬执行上限(默认 15 分钟/步)与整轮预算(默认 20 分钟):子 Agent 接近上限时应先把已完成内容落盘并在结论里列出路径。任何「达到执行上限」「本轮预算用尽」都不等于「什么都没做」:状态里的 error 会列出「声明产物已在盘上」,必须先用文件核对;若产物已覆盖验收标准,用 dsh_workplan_update 复核改判,只补缺失部分再续跑,禁止无视盘上产物把整步重跑。',
|
|
112
114
|
'结果消息里每个完成项都带 verification 与 acceptance:`structured` 是子 Agent 逐条自检通过,`unverified` 是自述但未逐条确认,`failed` 是自检失败(已按受阻处理),`legacy` 是旧格式回传。只有 structured 且 acceptance 每项 pass 才算可交付;其余必须你自己核对产物,并用 dsh_workplan_update 的 verification/acceptance/artifacts 字段把核对结果写回(这些字段会持久化、刷新后仍生效),不要把“看着没问题”当成证据。',
|
|
113
115
|
'子 Agent 通过 `needs` 提出的跨部门需求会列在结果消息的「跨部门待转达」里:由你逐条处理(补派、向用户确认或直接完成),不要忽略。',
|
|
114
116
|
'长任务可以用 `dsh_workplan_dispatch({ mode: "async" })` 先开跑并立即答复用户,再用 `dsh_workplan_status` 查看进度;async 返回的是“已开跑”,不是“已完成”。',
|
|
@@ -152,6 +154,16 @@ export type WorkplanConfig = {
|
|
|
152
154
|
idleTimeoutMs?: number
|
|
153
155
|
totalTimeoutMs?: number
|
|
154
156
|
maxResumes?: number
|
|
157
|
+
/**
|
|
158
|
+
* [1.10.4] 整轮预算到点后自动开始下一轮。默认 **false**。
|
|
159
|
+
*
|
|
160
|
+
* 打开方式(部署时二选一):profile 配置 `autoResume: true`,或环境变量
|
|
161
|
+
* `DSH_WORKPLAN_AUTO_RESUME=1`。默认关闭是刻意的:自动续跑会自己消耗
|
|
162
|
+
* 模型额度,必须先在小流量 profile 上验证过状态机与证据门禁再开。
|
|
163
|
+
*/
|
|
164
|
+
autoResume?: boolean
|
|
165
|
+
/** 自动续跑轮次上限(0–4,默认 2);环境变量 `DSH_WORKPLAN_AUTO_RESUME_MAX`。 */
|
|
166
|
+
autoResumeMaxAttempts?: number
|
|
155
167
|
}
|
|
156
168
|
|
|
157
169
|
function createUpdateTool(runtime: any) {
|
|
@@ -272,7 +284,12 @@ function createCancelTool(runtime: any) {
|
|
|
272
284
|
'取消当前会话尚未派发/正在等待派发的任务分解计划。仅取消计划记录,不伪造任何完成;'
|
|
273
285
|
+ '取消后计划在面板中显示为“已取消”,不会启动任何部门 Agent。'
|
|
274
286
|
+ '注意:取消不等于完成。取消后如仍有未完成项或证据缺口,present 仍会被拒绝,'
|
|
275
|
-
+ '答复必须按「未完成:剩余 N 项与原因」说明。'
|
|
287
|
+
+ '答复必须按「未完成:剩余 N 项与原因」说明。'
|
|
288
|
+
+ 'disposition="superseded" 是另一种处置:把交付责任转移给一个可验证的承接计划。'
|
|
289
|
+
+ '运行时逐条复算(V1–V8):源计划必须已取消且未全 done、承接计划必须定义更晚且非终态、'
|
|
290
|
+
+ '映射必须覆盖源计划全部子任务、每个映射目标必须有 done+structured 证据与全通过的验收、'
|
|
291
|
+
+ '且本会话存在同时含两个 planId 的用户确认消息。任一不满足即拒绝并返回 SUPERSEDE_* 码,'
|
|
292
|
+
+ '状态不变;被取代不等于完成。',
|
|
276
293
|
parameters: {
|
|
277
294
|
type: 'object',
|
|
278
295
|
properties: {
|
|
@@ -282,7 +299,39 @@ function createCancelTool(runtime: any) {
|
|
|
282
299
|
},
|
|
283
300
|
reason: {
|
|
284
301
|
type: 'string',
|
|
285
|
-
description: '
|
|
302
|
+
description: '取消/取代原因,会写入会话记录。',
|
|
303
|
+
},
|
|
304
|
+
disposition: {
|
|
305
|
+
type: 'string',
|
|
306
|
+
enum: ['cancelled', 'superseded'],
|
|
307
|
+
description: '处置方式:cancelled=用户撤销(默认);superseded=责任已转移给承接计划。',
|
|
308
|
+
},
|
|
309
|
+
supersededBy: {
|
|
310
|
+
type: 'object',
|
|
311
|
+
description: 'disposition=superseded 时必填:承接计划与逐项覆盖映射。'
|
|
312
|
+
+ '只给映射意图,requiredCount/coveredCount/coverage/digest 由运行时复算,不接受自报。',
|
|
313
|
+
properties: {
|
|
314
|
+
planId: {
|
|
315
|
+
type: 'string',
|
|
316
|
+
description: '承接计划的 planId(必须定义得过且未终止)。',
|
|
317
|
+
},
|
|
318
|
+
mapping: {
|
|
319
|
+
type: 'array',
|
|
320
|
+
description: '源计划每个定义子任务一条映射;from 必须恰好覆盖全部源项(各一次)。',
|
|
321
|
+
items: {
|
|
322
|
+
type: 'object',
|
|
323
|
+
properties: {
|
|
324
|
+
from: { type: 'string', description: '源计划子任务 ID。' },
|
|
325
|
+
to: { type: 'string', description: '承接计划子任务 ID。' },
|
|
326
|
+
basis: { type: 'string', description: '覆盖依据(为什么这两项是同一责任)。' },
|
|
327
|
+
},
|
|
328
|
+
required: ['from', 'to', 'basis'],
|
|
329
|
+
additionalProperties: false,
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
required: ['planId', 'mapping'],
|
|
334
|
+
additionalProperties: false,
|
|
286
335
|
},
|
|
287
336
|
},
|
|
288
337
|
additionalProperties: false,
|
|
@@ -291,8 +340,20 @@ function createCancelTool(runtime: any) {
|
|
|
291
340
|
schema: cancelToolOutputSchema(),
|
|
292
341
|
render(_args: any, value: any) {
|
|
293
342
|
const result = isRecord(value) ? value : {}
|
|
294
|
-
if (!result.ok)
|
|
343
|
+
if (!result.ok) {
|
|
344
|
+
return textContent(`处置失败${result.code ? `(${String(result.code)})` : ''}:`
|
|
345
|
+
+ `${String(result.error ?? '未知错误')}`)
|
|
346
|
+
}
|
|
295
347
|
const stats = isRecord(result.stats) ? result.stats : {}
|
|
348
|
+
if (result.phase === 'superseded') {
|
|
349
|
+
const by = isRecord(result.supersededBy) ? result.supersededBy : {}
|
|
350
|
+
return textContent(
|
|
351
|
+
`计划 ${String(result.planId ?? '')} 已被取代:承接计划 ${String(by.planId ?? '')}`
|
|
352
|
+
+ `(映射 ${Number(by.coveredCount ?? 0)}/${Number(by.requiredCount ?? 0)},digest 已复算)`
|
|
353
|
+
+ `|源计划仍是 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)}:被取代不等于完成,`
|
|
354
|
+
+ '不得 present 源计划,只能使用承接计划通过交付就绪检查的产物。',
|
|
355
|
+
)
|
|
356
|
+
}
|
|
296
357
|
const cancelledIncomplete = result.phase !== 'done'
|
|
297
358
|
return textContent(
|
|
298
359
|
`已取消计划 ${String(result.planId ?? '')}:${String(result.reason ?? '用户取消')}`
|
|
@@ -311,6 +372,64 @@ function createCancelTool(runtime: any) {
|
|
|
311
372
|
}
|
|
312
373
|
}
|
|
313
374
|
|
|
375
|
+
function createFollowupTool(runtime: any) {
|
|
376
|
+
return {
|
|
377
|
+
name: 'dsh_workplan_followup',
|
|
378
|
+
description:
|
|
379
|
+
'把一条说明投递给本会话的某个**直接子会话**,让它继续跑一个正常回合。'
|
|
380
|
+
+ '用途仅限:子任务被预算/超时中止、但产物已在盘上,且用户明确同意补发 follow-up 时,'
|
|
381
|
+
+ '让子会话自己收尾,从而让它自己的 turn/end 变成 completed。'
|
|
382
|
+
+ '它不写计划状态、不触发交付、也不改变界面判定;投递本身不等于完成。'
|
|
383
|
+
+ '不是直接子会话(父会话 catalog 未登记)一律拒绝。',
|
|
384
|
+
parameters: {
|
|
385
|
+
type: 'object',
|
|
386
|
+
properties: {
|
|
387
|
+
sessionId: {
|
|
388
|
+
type: 'string',
|
|
389
|
+
description: '直接子会话 ID(父会话 subagent/catalog 中登记的那一个)。',
|
|
390
|
+
},
|
|
391
|
+
message: {
|
|
392
|
+
type: 'string',
|
|
393
|
+
description: '发给子会话的说明:确认已有产物、只补缺口、不要整步重跑;不要要求它伪造完成。',
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
required: ['sessionId', 'message'],
|
|
397
|
+
additionalProperties: false,
|
|
398
|
+
},
|
|
399
|
+
output: {
|
|
400
|
+
schema: {
|
|
401
|
+
type: 'object',
|
|
402
|
+
properties: {
|
|
403
|
+
ok: { type: 'boolean' },
|
|
404
|
+
sessionId: { type: 'string' },
|
|
405
|
+
messageId: { type: 'string' },
|
|
406
|
+
code: { type: 'string' },
|
|
407
|
+
error: { type: 'string' },
|
|
408
|
+
},
|
|
409
|
+
required: ['ok'],
|
|
410
|
+
additionalProperties: true,
|
|
411
|
+
},
|
|
412
|
+
render(_args: any, value: any) {
|
|
413
|
+
const result = isRecord(value) ? value : {}
|
|
414
|
+
if (!result.ok) {
|
|
415
|
+
return textContent(
|
|
416
|
+
`follow-up 未投递:${String(result.error ?? result.code ?? '未知错误')}`,
|
|
417
|
+
)
|
|
418
|
+
}
|
|
419
|
+
return textContent(
|
|
420
|
+
`已向子会话 ${String(result.sessionId ?? '')} 投递 follow-up`
|
|
421
|
+
+ (result.messageId ? `(messageId ${String(result.messageId)})` : '')
|
|
422
|
+
+ '。投递只代表消息被接收;界面状态要等该子会话自己的回合正常结束才会变化。',
|
|
423
|
+
)
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
async execute(args: any, exec: any) {
|
|
427
|
+
const parsed = asObject(args) ?? {}
|
|
428
|
+
return runtime.followupTool(exec.agent, parsed, exec.signal)
|
|
429
|
+
},
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
314
433
|
function createStatusTool(runtime: any) {
|
|
315
434
|
return {
|
|
316
435
|
name: 'dsh_workplan_status',
|
|
@@ -478,6 +597,27 @@ function createDispatchTool(runtime: any) {
|
|
|
478
597
|
* short of editing the source, so any machine with slower subagents hit the
|
|
479
598
|
* wall on every plan. These knobs let operations tune it without a rebuild.
|
|
480
599
|
*/
|
|
600
|
+
/**
|
|
601
|
+
* [1.10.4] 布尔开关:配置项优先,其次环境变量。
|
|
602
|
+
*
|
|
603
|
+
* 与 `numericSetting` 不同,显式 `false` 必须能被表达,所以先判 boolean;
|
|
604
|
+
* 环境变量只接受 1/true/yes/on,大小写不敏感。未配置时返回 `false`。
|
|
605
|
+
*
|
|
606
|
+
* [1.10.6] 注意:`autoResume` 已改用 `autoResumeEnabledFrom`(默认开启,
|
|
607
|
+
* 且 `0/false/no/off` 可以显式关闭)。本函数保留给「默认关闭」语义的开关。
|
|
608
|
+
*/
|
|
609
|
+
function booleanSetting(configValue: any, envName: string) {
|
|
610
|
+
if (typeof configValue === 'boolean') return configValue
|
|
611
|
+
const raw = typeof process !== 'undefined' ? process.env?.[envName] : undefined
|
|
612
|
+
if (raw === undefined || raw === '') return false
|
|
613
|
+
return /^(1|true|yes|on)$/i.test(String(raw).trim())
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/** [1.10.6] 原样读取环境变量,供三态解析使用(未设置返回 undefined)。 */
|
|
617
|
+
function settingEnv(envName: string) {
|
|
618
|
+
return typeof process !== 'undefined' ? process.env?.[envName] : undefined
|
|
619
|
+
}
|
|
620
|
+
|
|
481
621
|
function numericSetting(configValue: any, envName: string) {
|
|
482
622
|
if (configValue !== undefined && configValue !== null && configValue !== '') {
|
|
483
623
|
const numeric = Number(configValue)
|
|
@@ -528,6 +668,13 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
|
528
668
|
idleTimeoutMs: numericSetting(config.idleTimeoutMs, 'DSH_WORKPLAN_IDLE_TIMEOUT_MS'),
|
|
529
669
|
totalTimeoutMs: numericSetting(config.totalTimeoutMs, 'DSH_WORKPLAN_TOTAL_TIMEOUT_MS'),
|
|
530
670
|
maxResumes: numericSetting(config.maxResumes, 'DSH_WORKPLAN_MAX_RESUMES'),
|
|
671
|
+
/*
|
|
672
|
+
* [1.10.6] 三态解析:显式配置 > 显式环境变量 > 默认开启。
|
|
673
|
+
* 旧实现用 `booleanSetting(..., false)`,未配置即等于关闭,于是「预算到点
|
|
674
|
+
* 自动续跑」这个能力在用户机器上从来没打开过(1h57m 空窗的直接原因)。
|
|
675
|
+
*/
|
|
676
|
+
autoResume: autoResumeEnabledFrom(config.autoResume, settingEnv('DSH_WORKPLAN_AUTO_RESUME')),
|
|
677
|
+
autoResumeMaxAttempts: numericSetting(config.autoResumeMaxAttempts, 'DSH_WORKPLAN_AUTO_RESUME_MAX'),
|
|
531
678
|
})
|
|
532
679
|
|
|
533
680
|
ctx.effect(() =>
|
|
@@ -541,6 +688,7 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
|
541
688
|
ctx.effect(() => ctx.tools.register(createUpdateTool(runtime)))
|
|
542
689
|
ctx.effect(() => ctx.tools.register(createCancelTool(runtime)))
|
|
543
690
|
ctx.effect(() => ctx.tools.register(createStatusTool(runtime)))
|
|
691
|
+
ctx.effect(() => ctx.tools.register(createFollowupTool(runtime)))
|
|
544
692
|
ctx.effect(() => ctx.tools.register(createDispatchTool(runtime)))
|
|
545
693
|
|
|
546
694
|
/*
|
|
@@ -621,7 +769,7 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
|
621
769
|
|
|
622
770
|
export const meta = {
|
|
623
771
|
name,
|
|
624
|
-
version: '1.
|
|
772
|
+
version: '1.10.6',
|
|
625
773
|
promptOrder: PROMPT_ORDER,
|
|
626
774
|
routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
|
|
627
775
|
}
|