dsh-workplan 1.9.1 → 1.11.0
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 +317 -0
- package/README.en.md +8 -3
- package/README.md +9 -4
- package/client.js +195 -8
- package/docs/collaboration.md +16 -5
- package/docs/departments.md +2 -2
- package/docs/release-record-1.10.6-20261101.md +78 -0
- package/lib/auto-resume.js +175 -0
- package/lib/client.js +2742 -0
- package/lib/host.js +451 -4
- package/lib/plan.js +1011 -46
- package/lib/replan.js +602 -0
- package/lib/runtime.js +1826 -61
- package/package.json +2 -2
- package/src/auto-resume.ts +246 -0
- package/src/client.ts +212 -7
- package/src/host.ts +492 -3
- package/src/plan.ts +967 -41
- package/src/replan.ts +642 -0
- package/src/runtime.ts +1819 -57
package/src/host.ts
CHANGED
|
@@ -18,10 +18,12 @@ import {
|
|
|
18
18
|
createWorkplanRuntime,
|
|
19
19
|
dispatchToolOutputSchema,
|
|
20
20
|
plannerOutputSchema,
|
|
21
|
+
replanToolOutputSchema,
|
|
21
22
|
statusToolOutputSchema,
|
|
22
23
|
updateToolOutputSchema,
|
|
23
24
|
} from './runtime.js'
|
|
24
25
|
import { isRecord } from './plan.js'
|
|
26
|
+
import { autoResumeEnabledFrom } from './auto-resume.js'
|
|
25
27
|
|
|
26
28
|
/*
|
|
27
29
|
* [1.8.14] Identity of the modules this process actually loaded (N1).
|
|
@@ -110,8 +112,18 @@ const PROMPT_SECTION = [
|
|
|
110
112
|
'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
113
|
'6. 如果续跑被拒绝、受阻项无法恢复、证据补不齐、计划已取消但未完成,或用户要求先看中间结果:答复开头必须写「未完成:剩余 N 项(列出 ID)与原因」,正文只能按中间结果表述,不得包装成成品。取消不会给你交付许可。',
|
|
112
114
|
'7. 子任务有硬执行上限(默认 15 分钟/步)与整轮预算(默认 20 分钟):子 Agent 接近上限时应先把已完成内容落盘并在结论里列出路径。任何「达到执行上限」「本轮预算用尽」都不等于「什么都没做」:状态里的 error 会列出「声明产物已在盘上」,必须先用文件核对;若产物已覆盖验收标准,用 dsh_workplan_update 复核改判,只补缺失部分再续跑,禁止无视盘上产物把整步重跑。',
|
|
115
|
+
'8. 出现「待指示」项(closure=escalated,左侧栏显示「待指示」并附问题摘录)时,必须在当轮处理:用 dsh_workplan_instruct 下发决定(投递到子会话并把该行恢复为执行中),或确认放弃后用 dsh_workplan_update 置 blocked。不要沉默略过,也不要把待指示当成普通失败——它是一条还没被回答的请示,会一直占着交付门禁。',
|
|
116
|
+
'9. 出现「已下发未响应」(ackOverdue)时,不要重复派发:先用 dsh_workplan_status 看该行 childId 与已等待时长,必要时用 dsh_workplan_followup 投递一次说明;超过硬超时仍未响应会记为 blocked(blockedKind=no-ack),可以再下发指示复活。',
|
|
117
|
+
/*
|
|
118
|
+
* [1.11.0] T7:需求变更的重规划不能只靠模型自觉。
|
|
119
|
+
*
|
|
120
|
+
* 变更通知(workplan-change)与 replan 工具都在,但如果提示词不写“必须判定”,
|
|
121
|
+
* 模型仍可能用旧计划直接交付。这里把它写成第 10 条硬规则:判定动作只有
|
|
122
|
+
* replan / dispatch / cancel 三个,旧行保留可追溯,新行必须再 dispatch。
|
|
123
|
+
*/
|
|
124
|
+
'10. 执行中用户提出新要求,或原安排的前提被推翻时,必须用 `dsh_workplan_replan` 明确判定:`cancel`/`replace` 受影响的旧子任务、`add` 新工作,并在 `reason` 写清原因;旧行保留为「已重规划」(可追溯、不计入剩余项、不再调度),随后调用 `dsh_workplan_dispatch` 执行新行。只是补充说明、不改范围时用 `dsh_workplan_update` 的 `note`;不允许用旧计划直接交付。',
|
|
113
125
|
'结果消息里每个完成项都带 verification 与 acceptance:`structured` 是子 Agent 逐条自检通过,`unverified` 是自述但未逐条确认,`failed` 是自检失败(已按受阻处理),`legacy` 是旧格式回传。只有 structured 且 acceptance 每项 pass 才算可交付;其余必须你自己核对产物,并用 dsh_workplan_update 的 verification/acceptance/artifacts 字段把核对结果写回(这些字段会持久化、刷新后仍生效),不要把“看着没问题”当成证据。',
|
|
114
|
-
'子 Agent 通过 `needs`
|
|
126
|
+
'子 Agent 通过 `needs` 提出的跨部门需求会列在结果消息的「跨部门待转达」里,并自动登记为待处理需求、计入交付门禁:用 `dsh_workplan_handoff` 逐条处置(list 查看、assign 登记责任部门、resolve 写入答复或产物引用、close 判定无需动作),不要忽略。注意:assign 不产生工作(没有常驻部门代理),需要产出就用 `dsh_workplan_replan(action=add)` 建该部门的子任务或自己完成;对「待指示」的行 resolve 会直接把答复投递给子会话。每条需求都必须有处置结论,否则 present 会被拒绝。',
|
|
115
127
|
'长任务可以用 `dsh_workplan_dispatch({ mode: "async" })` 先开跑并立即答复用户,再用 `dsh_workplan_status` 查看进度;async 返回的是“已开跑”,不是“已完成”。',
|
|
116
128
|
'如果自动分解降级,先向用户说明失败原因并询问是否重试,在用户确认前不要开始执行任务。',
|
|
117
129
|
].join('\n')
|
|
@@ -153,6 +165,25 @@ export type WorkplanConfig = {
|
|
|
153
165
|
idleTimeoutMs?: number
|
|
154
166
|
totalTimeoutMs?: number
|
|
155
167
|
maxResumes?: number
|
|
168
|
+
/**
|
|
169
|
+
* [1.10.4] 整轮预算到点后自动开始下一轮。默认 **false**。
|
|
170
|
+
*
|
|
171
|
+
* 打开方式(部署时二选一):profile 配置 `autoResume: true`,或环境变量
|
|
172
|
+
* `DSH_WORKPLAN_AUTO_RESUME=1`。默认关闭是刻意的:自动续跑会自己消耗
|
|
173
|
+
* 模型额度,必须先在小流量 profile 上验证过状态机与证据门禁再开。
|
|
174
|
+
*/
|
|
175
|
+
autoResume?: boolean
|
|
176
|
+
/** 自动续跑轮次上限(0–4,默认 2);环境变量 `DSH_WORKPLAN_AUTO_RESUME_MAX`。 */
|
|
177
|
+
autoResumeMaxAttempts?: number
|
|
178
|
+
/**
|
|
179
|
+
* [1.11.0] 完成必回报(C-05 / M3 / M11)。默认 **true**。
|
|
180
|
+
*
|
|
181
|
+
* `true`:子任务结束必须附结构化证据块;只有散文、没有证据块且没写
|
|
182
|
+
* `BLOCKED:` 时判为 `blocked/unverified`,不再记成「已完成」。
|
|
183
|
+
* `false`:保留 1.10.6 行为(无证据块按 `done/legacy` 收),用于回放旧会话、
|
|
184
|
+
* 或部署方明确只想看松散结果。环境变量 `DSH_WORKPLAN_STRICT_COMPLETION=0`。
|
|
185
|
+
*/
|
|
186
|
+
strictCompletion?: boolean
|
|
156
187
|
}
|
|
157
188
|
|
|
158
189
|
function createUpdateTool(runtime: any) {
|
|
@@ -266,6 +297,145 @@ function createUpdateTool(runtime: any) {
|
|
|
266
297
|
}
|
|
267
298
|
}
|
|
268
299
|
|
|
300
|
+
/**
|
|
301
|
+
* [1.11.0] 需求变更 → 重规划的唯一入口(T4 C-11 / T7)。
|
|
302
|
+
*
|
|
303
|
+
* 触发条件写在工具描述里,因为「什么时候该重规划」是语义判断,代码不猜:
|
|
304
|
+
* - 执行中用户提出新要求、原安排不再成立;
|
|
305
|
+
* - 验收标准/交付物变化,旧子任务的完成不再等于用户要的结果;
|
|
306
|
+
* - 上游结论推翻了后续步骤的前提。
|
|
307
|
+
* 只补说明、不改范围时不要用本工具(那会白白留下一批“已重规划”旧行),
|
|
308
|
+
* 改用 `dsh_workplan_update` 的 note。
|
|
309
|
+
*
|
|
310
|
+
* 旧状态不删除:`planReplan()` 在计划定义上写 `supersededAt/replacedBy`,
|
|
311
|
+
* `applyReplanStatuses()` 在状态条上写 `closure:'replanned'` + `replannedFrom`,
|
|
312
|
+
* 两者是同一次写入的两个镜像;旧行保留可追溯、不计入剩余项、不再调度。
|
|
313
|
+
* 重规划本身不执行新行——必须再调用 `dsh_workplan_dispatch`。
|
|
314
|
+
*/
|
|
315
|
+
function createReplanTool(runtime: any) {
|
|
316
|
+
return {
|
|
317
|
+
name: 'dsh_workplan_replan',
|
|
318
|
+
description:
|
|
319
|
+
'按需求变更重规划当前计划:把受影响的旧子任务标为「已重规划」(保留可追溯,不再调度、不计入剩余项),'
|
|
320
|
+
+ '并为每个被替换项生成一个接替子任务、为新增工作生成新子任务。'
|
|
321
|
+
+ '触发条件:执行中用户提出新要求、验收标准或交付物变化、原安排的前提被推翻。'
|
|
322
|
+
+ '只补充说明而不改范围时不要调用本工具,改用 dsh_workplan_update 的 note。'
|
|
323
|
+
+ '重规划不会中途改写正在跑的本轮:执行中调用返回 REPLAN_PLAN_RUNNING 并把变更原文记为 changeRequest,'
|
|
324
|
+
+ '等本轮结束后用同一组 changes 重试即可(变更不会丢)。'
|
|
325
|
+
+ '重规划成功后必须再调用 dsh_workplan_dispatch 执行新行;旧行不会复活。',
|
|
326
|
+
parameters: {
|
|
327
|
+
type: 'object',
|
|
328
|
+
properties: {
|
|
329
|
+
planId: {
|
|
330
|
+
type: 'string',
|
|
331
|
+
description: '计划 ID;省略时使用当前会话最新计划。',
|
|
332
|
+
},
|
|
333
|
+
reason: {
|
|
334
|
+
type: 'string',
|
|
335
|
+
description: '为什么原安排失效(必填,会写进持久化记录与旧行留档)。',
|
|
336
|
+
},
|
|
337
|
+
changeText: {
|
|
338
|
+
type: 'string',
|
|
339
|
+
description: '可选:用户变更原文。本轮派发仍在执行时,本工具不会改计划,只会把它记为 changeRequest。',
|
|
340
|
+
},
|
|
341
|
+
changes: {
|
|
342
|
+
type: 'array',
|
|
343
|
+
minItems: 1,
|
|
344
|
+
maxItems: 12,
|
|
345
|
+
description: '逐项说明受影响的子任务:cancel=撤销,replace=用新行接替,add=追加新工作。',
|
|
346
|
+
items: {
|
|
347
|
+
type: 'object',
|
|
348
|
+
properties: {
|
|
349
|
+
subtaskId: {
|
|
350
|
+
type: 'string',
|
|
351
|
+
description: '受影响的旧子任务 ID(add 时可填任意未被占用的新 ID)。',
|
|
352
|
+
},
|
|
353
|
+
action: {
|
|
354
|
+
type: 'string',
|
|
355
|
+
enum: ['cancel', 'replace', 'add'],
|
|
356
|
+
description: 'cancel=只撤销;replace=撤销旧行并插入接替行;add=不动旧行,追加新行。',
|
|
357
|
+
},
|
|
358
|
+
reason: { type: 'string', description: '该子任务受影响的原因;省略时继承顶层 reason。' },
|
|
359
|
+
replacement: {
|
|
360
|
+
type: 'object',
|
|
361
|
+
description: 'replace 必填:改后的字段(未给的字段继承旧行)。',
|
|
362
|
+
properties: {
|
|
363
|
+
id: { type: 'string', description: '接替行 ID(默认在旧 ID 后加 b);最长 16 字符,不能与现有 ID 重复。' },
|
|
364
|
+
title: { type: 'string' },
|
|
365
|
+
department: { type: 'string' },
|
|
366
|
+
role: { type: 'string' },
|
|
367
|
+
objective: { type: 'string' },
|
|
368
|
+
method: { type: 'array', items: { type: 'string' } },
|
|
369
|
+
inputs: { type: 'array', items: { type: 'string' } },
|
|
370
|
+
outputs: { type: 'array', items: { type: 'string' } },
|
|
371
|
+
acceptance: { type: 'array', items: { type: 'string' } },
|
|
372
|
+
risk: { type: 'string' },
|
|
373
|
+
},
|
|
374
|
+
additionalProperties: false,
|
|
375
|
+
},
|
|
376
|
+
newSubtask: {
|
|
377
|
+
type: 'object',
|
|
378
|
+
description: 'add 必填:新增子任务,title 与 objective 必填。',
|
|
379
|
+
properties: {
|
|
380
|
+
id: { type: 'string', description: '新行 ID;省略时自动生成 R<修订号>-<序号>。' },
|
|
381
|
+
title: { type: 'string' },
|
|
382
|
+
objective: { type: 'string' },
|
|
383
|
+
department: { type: 'string' },
|
|
384
|
+
role: { type: 'string' },
|
|
385
|
+
method: { type: 'array', items: { type: 'string' } },
|
|
386
|
+
inputs: { type: 'array', items: { type: 'string' } },
|
|
387
|
+
outputs: { type: 'array', items: { type: 'string' } },
|
|
388
|
+
acceptance: { type: 'array', items: { type: 'string' } },
|
|
389
|
+
dependsOn: { type: 'array', items: { type: 'string' } },
|
|
390
|
+
risk: { type: 'string' },
|
|
391
|
+
reason: { type: 'string' },
|
|
392
|
+
},
|
|
393
|
+
required: ['title', 'objective'],
|
|
394
|
+
additionalProperties: false,
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
required: ['subtaskId', 'action'],
|
|
398
|
+
additionalProperties: false,
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
required: ['reason', 'changes'],
|
|
403
|
+
additionalProperties: false,
|
|
404
|
+
},
|
|
405
|
+
output: {
|
|
406
|
+
schema: replanToolOutputSchema(),
|
|
407
|
+
render(_args: any, value: any) {
|
|
408
|
+
const result = isRecord(value) ? value : {}
|
|
409
|
+
if (!result.ok) {
|
|
410
|
+
return textContent(
|
|
411
|
+
`重规划失败${result.code ? `(${String(result.code)})` : ''}:${String(result.error ?? result.hint ?? '未知错误')}`
|
|
412
|
+
+ (result.code === 'REPLAN_PLAN_RUNNING'
|
|
413
|
+
? '|变更已记录,等本轮结束(dispatch 返回后)再用同一组 changes 重试。'
|
|
414
|
+
: ''),
|
|
415
|
+
)
|
|
416
|
+
}
|
|
417
|
+
const marks = Array.isArray(result.marks) ? result.marks : []
|
|
418
|
+
const added = Array.isArray(result.added) ? result.added : []
|
|
419
|
+
const changed = marks
|
|
420
|
+
.map((mark: any) => `${String(mark?.subtaskId ?? '')}→${Array.isArray(mark?.replacedBy) && mark.replacedBy.length > 0 ? mark.replacedBy.join('、') : '撤销'}`)
|
|
421
|
+
.join(',')
|
|
422
|
+
const fresh = added.map((item: any) => String(item?.subtaskId ?? '')).filter(Boolean).join('、')
|
|
423
|
+
return textContent(
|
|
424
|
+
`计划 ${String(result.planId ?? '')} 已重规划为修订 r${Number(result.planRevision ?? 0)}`
|
|
425
|
+
+ (changed ? `|受影响:${changed}` : '')
|
|
426
|
+
+ (fresh ? `|新增:${fresh}` : '')
|
|
427
|
+
+ '|旧行保留为「已重规划」(可追溯、不计入剩余项、不再调度)'
|
|
428
|
+
+ '|下一步:调用 dsh_workplan_dispatch 执行新行。',
|
|
429
|
+
)
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
async execute(args: any, exec: any) {
|
|
433
|
+
const parsed = asObject(args) ?? {}
|
|
434
|
+
return runtime.replanPlan(exec.agent, parsed)
|
|
435
|
+
},
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
269
439
|
function createCancelTool(runtime: any) {
|
|
270
440
|
return {
|
|
271
441
|
name: 'dsh_workplan_cancel',
|
|
@@ -419,6 +589,254 @@ function createFollowupTool(runtime: any) {
|
|
|
419
589
|
}
|
|
420
590
|
}
|
|
421
591
|
|
|
592
|
+
/**
|
|
593
|
+
* [1.11.0] 子 → 父的唯一反向通道(T4 C-09 / T6 M5)。
|
|
594
|
+
*
|
|
595
|
+
* 为什么要有独立工具而不是让子 Agent 在结果块里写 `question`:结果块只在
|
|
596
|
+
* 子会话结束时才被父会话看到,那时子会话已经停了,请示与「已结束」无法区分,
|
|
597
|
+
* 主 Agent 只会在下一次 dispatch 之后才发现有人在等回答。这个工具把请示
|
|
598
|
+
* 提前到「还在跑」的时刻,并在状态条上留下 `closure:'escalated'`。
|
|
599
|
+
*/
|
|
600
|
+
function createEscalateTool(runtime: any) {
|
|
601
|
+
return {
|
|
602
|
+
name: 'dsh_workplan_escalate',
|
|
603
|
+
description:
|
|
604
|
+
'子 Agent 遇阻时向父会话上报请示,并把该子任务置为「待指示」。'
|
|
605
|
+
+ '遇阻(缺权限/缺输入/依赖产物缺失/需求自相矛盾/无法验证/同一命令连续两次失败/需要主 Agent 决定方向)时,'
|
|
606
|
+
+ '第一动作是调用本工具,然后停止推进、只做只读核对,等待主 Agent 指示。'
|
|
607
|
+
+ '不需要外部决定时不要调用;调用后不要自行选定一个选项继续。',
|
|
608
|
+
parameters: {
|
|
609
|
+
type: 'object',
|
|
610
|
+
properties: {
|
|
611
|
+
subtaskId: {
|
|
612
|
+
type: 'string',
|
|
613
|
+
description: '你的子任务 ID(仅用于回显核对;服务端按父子会话关系反查,自报值不作为定位依据)。',
|
|
614
|
+
},
|
|
615
|
+
question: {
|
|
616
|
+
type: 'string',
|
|
617
|
+
description: '需要主 Agent 回答的单个问题:写清卡在哪一步、已经尝试过什么、需要谁做什么决定。必填。',
|
|
618
|
+
},
|
|
619
|
+
options: {
|
|
620
|
+
type: 'array',
|
|
621
|
+
items: { type: 'string' },
|
|
622
|
+
description: '可选的处理方向(建议 2–4 个)。只是建议,不会被自动执行,也不会替你选择。',
|
|
623
|
+
},
|
|
624
|
+
needs: {
|
|
625
|
+
type: 'array',
|
|
626
|
+
items: { type: 'string' },
|
|
627
|
+
description: '需要其他部门/人员提供什么(每条一句话),由主 Agent 转达。',
|
|
628
|
+
},
|
|
629
|
+
},
|
|
630
|
+
required: ['question'],
|
|
631
|
+
additionalProperties: false,
|
|
632
|
+
},
|
|
633
|
+
output: {
|
|
634
|
+
schema: {
|
|
635
|
+
type: 'object',
|
|
636
|
+
properties: {
|
|
637
|
+
ok: { type: 'boolean' },
|
|
638
|
+
planId: { type: 'string' },
|
|
639
|
+
subtaskId: { type: 'string' },
|
|
640
|
+
status: { type: 'string' },
|
|
641
|
+
closure: { type: 'string' },
|
|
642
|
+
question: { type: 'string' },
|
|
643
|
+
code: { type: 'string' },
|
|
644
|
+
error: { type: 'string' },
|
|
645
|
+
message: { type: 'string' },
|
|
646
|
+
},
|
|
647
|
+
required: ['ok'],
|
|
648
|
+
additionalProperties: true,
|
|
649
|
+
},
|
|
650
|
+
render(_args: any, value: any) {
|
|
651
|
+
const result = isRecord(value) ? value : {}
|
|
652
|
+
if (!result.ok) {
|
|
653
|
+
return textContent(
|
|
654
|
+
`上报未登记:${String(result.error ?? result.code ?? '未知错误')}`
|
|
655
|
+
+ '|改为在结果块里写 "status":"blocked" 并附 "question",仍然算作请示。',
|
|
656
|
+
)
|
|
657
|
+
}
|
|
658
|
+
return textContent(
|
|
659
|
+
`${String(result.subtaskId ?? '')} 已登记为「待指示」`
|
|
660
|
+
+ (result.alreadyEscalated ? '(此前已登记,未重复提交)' : '')
|
|
661
|
+
+ `:${String(result.question ?? '')}`
|
|
662
|
+
+ '|现在停止推进,只做只读核对;等待主 Agent 指示后再继续。',
|
|
663
|
+
)
|
|
664
|
+
},
|
|
665
|
+
},
|
|
666
|
+
async execute(args: any, exec: any) {
|
|
667
|
+
const parsed = asObject(args) ?? {}
|
|
668
|
+
return runtime.escalateTool(exec.agent, parsed)
|
|
669
|
+
},
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* [1.11.0] 主 → 子的指示通道(T4 C-10 / T6 M6)。
|
|
675
|
+
*
|
|
676
|
+
* 服务端硬校验:根会话、该行 `closure:'escalated'`、`childId` 是本会话直接
|
|
677
|
+
* 子会话、instruction 非空且 ≤4000 字符。投递失败时不改状态 —— 「我发了」
|
|
678
|
+
* 与「它收到了」必须是两件事,否则界面会显示一个没人执行的指示。
|
|
679
|
+
*/
|
|
680
|
+
function createInstructTool(runtime: any) {
|
|
681
|
+
return {
|
|
682
|
+
name: 'dsh_workplan_instruct',
|
|
683
|
+
description:
|
|
684
|
+
'向一条「待指示」子任务下发主 Agent 的决定:投递给对应子会话,并把该行恢复为执行中(closure=instructed)。'
|
|
685
|
+
+ '只有根会话可调用;只接受 closure=escalated 的行。'
|
|
686
|
+
+ '投递失败时状态不变(仍是待指示),按返回的 hint 重试或改用 dsh_workplan_update 明确放弃。',
|
|
687
|
+
parameters: {
|
|
688
|
+
type: 'object',
|
|
689
|
+
properties: {
|
|
690
|
+
planId: {
|
|
691
|
+
type: 'string',
|
|
692
|
+
description: '计划 ID;省略时使用当前会话最新计划。',
|
|
693
|
+
},
|
|
694
|
+
subtaskId: {
|
|
695
|
+
type: 'string',
|
|
696
|
+
description: '待指示的子任务 ID,例如 T3。',
|
|
697
|
+
},
|
|
698
|
+
instruction: {
|
|
699
|
+
type: 'string',
|
|
700
|
+
description: '要子 Agent 执行的决定:写清结论、约束与仍需保留的边界;不要只说“继续”。最多 4000 字符。',
|
|
701
|
+
},
|
|
702
|
+
},
|
|
703
|
+
required: ['subtaskId', 'instruction'],
|
|
704
|
+
additionalProperties: false,
|
|
705
|
+
},
|
|
706
|
+
output: {
|
|
707
|
+
schema: {
|
|
708
|
+
type: 'object',
|
|
709
|
+
properties: {
|
|
710
|
+
ok: { type: 'boolean' },
|
|
711
|
+
planId: { type: 'string' },
|
|
712
|
+
subtaskId: { type: 'string' },
|
|
713
|
+
status: { type: 'string' },
|
|
714
|
+
closure: { type: 'string' },
|
|
715
|
+
revision: { type: 'number' },
|
|
716
|
+
messageId: { type: 'string' },
|
|
717
|
+
deliveryReady: { type: 'boolean' },
|
|
718
|
+
code: { type: 'string' },
|
|
719
|
+
error: { type: 'string' },
|
|
720
|
+
hint: { type: 'string' },
|
|
721
|
+
},
|
|
722
|
+
required: ['ok'],
|
|
723
|
+
additionalProperties: true,
|
|
724
|
+
},
|
|
725
|
+
render(_args: any, value: any) {
|
|
726
|
+
const result = isRecord(value) ? value : {}
|
|
727
|
+
if (!result.ok) {
|
|
728
|
+
return textContent(
|
|
729
|
+
`指示未下发:${String(result.error ?? result.code ?? '未知错误')}`
|
|
730
|
+
+ (result.hint ? `|下一步:${String(result.hint)}` : ''),
|
|
731
|
+
)
|
|
732
|
+
}
|
|
733
|
+
return textContent(
|
|
734
|
+
`${String(result.subtaskId ?? '')} 已收到指示并恢复执行(revision ${String(result.revision ?? '')})`
|
|
735
|
+
+ (result.messageId ? `,messageId ${String(result.messageId)}` : '')
|
|
736
|
+
+ '|该行现在显示「已收到指示」;完成前仍不得交付,需等它回报结果。',
|
|
737
|
+
)
|
|
738
|
+
},
|
|
739
|
+
},
|
|
740
|
+
async execute(args: any, exec: any) {
|
|
741
|
+
const parsed = asObject(args) ?? {}
|
|
742
|
+
return runtime.instructTool(exec.agent, parsed, exec.signal)
|
|
743
|
+
},
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* [1.11.0] 跨部门需求的处置入口(用户 m00687)。
|
|
749
|
+
*
|
|
750
|
+
* 子 Agent 提出的 `needs` 会自动变成一条 open handoff,并进入交付门禁;
|
|
751
|
+
* 只有根会话能用本工具把需求指派给部门、写入答复或判定无需动作。这是
|
|
752
|
+
* 「跨部门协作必须有始有终」的唯一人工出口,避免需求只停留在提示词文本里。
|
|
753
|
+
*/
|
|
754
|
+
function createHandoffTool(runtime: any) {
|
|
755
|
+
return {
|
|
756
|
+
name: 'dsh_workplan_handoff',
|
|
757
|
+
description:
|
|
758
|
+
'处置跨部门需求(needs)。子 Agent 每条 needs 都会登记为待处理需求,未处置会拦住交付。插件没有常驻部门代理:assign 只登记责任,实际产出要用 dsh_workplan_replan(action=add) 建子任务或由你完成;被答复的行若在「待指示」,resolve 会把答复直接投递给子会话。'
|
|
759
|
+
+ '动作:list 列出全部待处理需求;assign 指派给某个部门(department);'
|
|
760
|
+
+ 'resolve 写入书面答复或产物引用(response),表示需求已满足;close 判定无需动作。'
|
|
761
|
+
+ '只有根会话可调用。',
|
|
762
|
+
parameters: {
|
|
763
|
+
type: 'object',
|
|
764
|
+
properties: {
|
|
765
|
+
action: {
|
|
766
|
+
type: 'string',
|
|
767
|
+
enum: ['list', 'assign', 'resolve', 'close'],
|
|
768
|
+
description: 'list=查看;assign=指派部门;resolve=写入答复并解除阻塞;close=判定无需动作。',
|
|
769
|
+
},
|
|
770
|
+
planId: {
|
|
771
|
+
type: 'string',
|
|
772
|
+
description: '计划 ID;省略时使用当前会话最新计划。',
|
|
773
|
+
},
|
|
774
|
+
subtaskId: {
|
|
775
|
+
type: 'string',
|
|
776
|
+
description: '提出该需求的子任务 ID。除 list 外必填。',
|
|
777
|
+
},
|
|
778
|
+
handoffId: {
|
|
779
|
+
type: 'string',
|
|
780
|
+
description: '需求编号(如 H1);省略时处理该行第一条 open/routed 需求。',
|
|
781
|
+
},
|
|
782
|
+
department: {
|
|
783
|
+
type: 'string',
|
|
784
|
+
description: 'assign 必填:负责满足该需求的部门 ID。',
|
|
785
|
+
},
|
|
786
|
+
response: {
|
|
787
|
+
type: 'string',
|
|
788
|
+
description: 'resolve 必填:写清答复,或指出已由哪项产物/子任务满足该需求。最多 4000 字符。',
|
|
789
|
+
},
|
|
790
|
+
},
|
|
791
|
+
required: ['action'],
|
|
792
|
+
additionalProperties: false,
|
|
793
|
+
},
|
|
794
|
+
output: {
|
|
795
|
+
schema: {
|
|
796
|
+
type: 'object',
|
|
797
|
+
properties: {
|
|
798
|
+
ok: { type: 'boolean' },
|
|
799
|
+
planId: { type: 'string' },
|
|
800
|
+
subtaskId: { type: 'string' },
|
|
801
|
+
handoff: { type: 'object' },
|
|
802
|
+
count: { type: 'number' },
|
|
803
|
+
handoffs: { type: 'array' },
|
|
804
|
+
deliveryReady: { type: 'boolean' },
|
|
805
|
+
code: { type: 'string' },
|
|
806
|
+
error: { type: 'string' },
|
|
807
|
+
hint: { type: 'string' },
|
|
808
|
+
},
|
|
809
|
+
required: ['ok'],
|
|
810
|
+
additionalProperties: true,
|
|
811
|
+
},
|
|
812
|
+
render(_args: any, value: any) {
|
|
813
|
+
const result = isRecord(value) ? value : {}
|
|
814
|
+
if (!result.ok) {
|
|
815
|
+
return textContent(`处置未生效:${String(result.error ?? result.code ?? '未知错误')}`)
|
|
816
|
+
}
|
|
817
|
+
if (Array.isArray(result.handoffs)) {
|
|
818
|
+
if (result.handoffs.length === 0) return textContent('没有待处理的跨部门需求。')
|
|
819
|
+
return textContent(
|
|
820
|
+
`待处理跨部门需求 ${result.handoffs.length} 条:\n`
|
|
821
|
+
+ result.handoffs.slice(0, 10).map((item: any) =>
|
|
822
|
+
`- ${String(item.subtaskId)} ${String(item.id)}|${String(item.status)}`
|
|
823
|
+
+ `${item.department ? ` → ${String(item.department)}` : ''}|${String(item.request)}`).join('\n'),
|
|
824
|
+
)
|
|
825
|
+
}
|
|
826
|
+
return textContent(
|
|
827
|
+
`${String(result.subtaskId ?? '')} ${String(result.handoff?.id ?? '')} 已更新为 ${String(result.handoff?.status ?? '')}`
|
|
828
|
+
+ `|${result.deliveryReady === true ? '交付门禁已通过' : '交付门禁仍未通过'}`
|
|
829
|
+
+ `|${String(result.hint ?? '')}`,
|
|
830
|
+
)
|
|
831
|
+
},
|
|
832
|
+
},
|
|
833
|
+
async execute(args: any, exec: any) {
|
|
834
|
+
const parsed = asObject(args) ?? {}
|
|
835
|
+
return runtime.handoffTool(exec.agent, parsed, exec.signal)
|
|
836
|
+
},
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
422
840
|
function createStatusTool(runtime: any) {
|
|
423
841
|
return {
|
|
424
842
|
name: 'dsh_workplan_status',
|
|
@@ -586,6 +1004,43 @@ function createDispatchTool(runtime: any) {
|
|
|
586
1004
|
* short of editing the source, so any machine with slower subagents hit the
|
|
587
1005
|
* wall on every plan. These knobs let operations tune it without a rebuild.
|
|
588
1006
|
*/
|
|
1007
|
+
/**
|
|
1008
|
+
* [1.10.4] 布尔开关:配置项优先,其次环境变量。
|
|
1009
|
+
*
|
|
1010
|
+
* 与 `numericSetting` 不同,显式 `false` 必须能被表达,所以先判 boolean;
|
|
1011
|
+
* 环境变量只接受 1/true/yes/on,大小写不敏感。未配置时返回 `false`。
|
|
1012
|
+
*
|
|
1013
|
+
* [1.10.6] 注意:`autoResume` 已改用 `autoResumeEnabledFrom`(默认开启,
|
|
1014
|
+
* 且 `0/false/no/off` 可以显式关闭)。本函数保留给「默认关闭」语义的开关。
|
|
1015
|
+
*/
|
|
1016
|
+
/**
|
|
1017
|
+
* [1.11.0] `strictCompletion` 的三态解析:显式配置 > 显式环境变量 > 默认 true。
|
|
1018
|
+
*
|
|
1019
|
+
* 不能复用 `booleanSetting`:那个函数「未配置即 false」,会把默认开启的
|
|
1020
|
+
* 完成门禁反过来关掉(1.10.6 的 autoResume 就栽在这上面)。
|
|
1021
|
+
*/
|
|
1022
|
+
function strictCompletionEnabledFrom(configValue: any, envValue: any) {
|
|
1023
|
+
if (typeof configValue === 'boolean') return configValue
|
|
1024
|
+
const raw = envValue === undefined || envValue === null ? '' : String(envValue).trim()
|
|
1025
|
+
if (raw !== '') {
|
|
1026
|
+
if (/^(1|true|yes|on)$/i.test(raw)) return true
|
|
1027
|
+
if (/^(0|false|no|off)$/i.test(raw)) return false
|
|
1028
|
+
}
|
|
1029
|
+
return true
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
function booleanSetting(configValue: any, envName: string) {
|
|
1033
|
+
if (typeof configValue === 'boolean') return configValue
|
|
1034
|
+
const raw = typeof process !== 'undefined' ? process.env?.[envName] : undefined
|
|
1035
|
+
if (raw === undefined || raw === '') return false
|
|
1036
|
+
return /^(1|true|yes|on)$/i.test(String(raw).trim())
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
/** [1.10.6] 原样读取环境变量,供三态解析使用(未设置返回 undefined)。 */
|
|
1040
|
+
function settingEnv(envName: string) {
|
|
1041
|
+
return typeof process !== 'undefined' ? process.env?.[envName] : undefined
|
|
1042
|
+
}
|
|
1043
|
+
|
|
589
1044
|
function numericSetting(configValue: any, envName: string) {
|
|
590
1045
|
if (configValue !== undefined && configValue !== null && configValue !== '') {
|
|
591
1046
|
const numeric = Number(configValue)
|
|
@@ -636,6 +1091,18 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
|
636
1091
|
idleTimeoutMs: numericSetting(config.idleTimeoutMs, 'DSH_WORKPLAN_IDLE_TIMEOUT_MS'),
|
|
637
1092
|
totalTimeoutMs: numericSetting(config.totalTimeoutMs, 'DSH_WORKPLAN_TOTAL_TIMEOUT_MS'),
|
|
638
1093
|
maxResumes: numericSetting(config.maxResumes, 'DSH_WORKPLAN_MAX_RESUMES'),
|
|
1094
|
+
/*
|
|
1095
|
+
* [1.10.6] 三态解析:显式配置 > 显式环境变量 > 默认开启。
|
|
1096
|
+
* 旧实现用 `booleanSetting(..., false)`,未配置即等于关闭,于是「预算到点
|
|
1097
|
+
* 自动续跑」这个能力在用户机器上从来没打开过(1h57m 空窗的直接原因)。
|
|
1098
|
+
*/
|
|
1099
|
+
autoResume: autoResumeEnabledFrom(config.autoResume, settingEnv('DSH_WORKPLAN_AUTO_RESUME')),
|
|
1100
|
+
autoResumeMaxAttempts: numericSetting(config.autoResumeMaxAttempts, 'DSH_WORKPLAN_AUTO_RESUME_MAX'),
|
|
1101
|
+
/*
|
|
1102
|
+
* [1.11.0] 三态解析(显式配置 > 显式环境变量 > 默认 true)。
|
|
1103
|
+
* 与 autoResume 用同一种写法:未配置时走默认值,而不是悄悄等于 false。
|
|
1104
|
+
*/
|
|
1105
|
+
strictEvidence: strictCompletionEnabledFrom(config.strictCompletion, settingEnv('DSH_WORKPLAN_STRICT_COMPLETION')),
|
|
639
1106
|
})
|
|
640
1107
|
|
|
641
1108
|
ctx.effect(() =>
|
|
@@ -650,6 +1117,28 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
|
650
1117
|
ctx.effect(() => ctx.tools.register(createCancelTool(runtime)))
|
|
651
1118
|
ctx.effect(() => ctx.tools.register(createStatusTool(runtime)))
|
|
652
1119
|
ctx.effect(() => ctx.tools.register(createFollowupTool(runtime)))
|
|
1120
|
+
/*
|
|
1121
|
+
* [1.11.0] 闭环的两条工具通道(T4 C-09 / C-10)。
|
|
1122
|
+
*
|
|
1123
|
+
* `escalate` 必须对子会话可见(子 Agent 是它的唯一调用者),`instruct`
|
|
1124
|
+
* 必须只有根会话可用(服务端 `isRootSession` 硬校验,不依赖提示词)。
|
|
1125
|
+
* 注册在插件根与其它工具一致:宿主按会话注入哪些工具由平台决定,插件
|
|
1126
|
+
* 侧不做过滤;权限判断一律落在 execute 内部。
|
|
1127
|
+
*/
|
|
1128
|
+
ctx.effect(() => ctx.tools.register(createEscalateTool(runtime)))
|
|
1129
|
+
ctx.effect(() => ctx.tools.register(createInstructTool(runtime)))
|
|
1130
|
+
/*
|
|
1131
|
+
* [1.11.0] 需求变更的重规划入口(T4 C-11 / T7)。
|
|
1132
|
+
*
|
|
1133
|
+
* 根会话工具:子 Agent 不能改写主计划(execute 内部 `isRootSession` 硬校验)。
|
|
1134
|
+
* 它只在“计划定义需要改”时使用;执行中调用会拒绝改计划但保留变更原文。
|
|
1135
|
+
*/
|
|
1136
|
+
ctx.effect(() => ctx.tools.register(createReplanTool(runtime)))
|
|
1137
|
+
/*
|
|
1138
|
+
* [1.11.0] 跨部门需求处置(用户 m00687):注册在根插件上,`execute` 内部
|
|
1139
|
+
* 用 `isRootSession` 硬校验,子会话即使拿到工具表也无法处置需求。
|
|
1140
|
+
*/
|
|
1141
|
+
ctx.effect(() => ctx.tools.register(createHandoffTool(runtime)))
|
|
653
1142
|
ctx.effect(() => ctx.tools.register(createDispatchTool(runtime)))
|
|
654
1143
|
|
|
655
1144
|
/*
|
|
@@ -730,12 +1219,12 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
|
730
1219
|
|
|
731
1220
|
export const meta = {
|
|
732
1221
|
name,
|
|
733
|
-
version: '1.
|
|
1222
|
+
version: '1.11.0',
|
|
734
1223
|
promptOrder: PROMPT_ORDER,
|
|
735
1224
|
routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
|
|
736
1225
|
}
|
|
737
1226
|
|
|
738
|
-
export { PROMPT_SECTION, createCancelTool, createDispatchTool, createStatusTool, createUpdateTool, plannerOutputSchema }
|
|
1227
|
+
export { PROMPT_SECTION, createCancelTool, createDispatchTool, createEscalateTool, createHandoffTool, createInstructTool, createReplanTool, createStatusTool, createUpdateTool, plannerOutputSchema }
|
|
739
1228
|
|
|
740
1229
|
/**
|
|
741
1230
|
* [1.8.18] 写工具的路径级闸门(T7-N2),与 `toolGuardReason` 分开注册。
|