dsh-workplan 1.10.6 → 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 +122 -0
- package/README.en.md +8 -3
- package/README.md +9 -4
- package/client.js +142 -5
- 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/client.js +142 -5
- package/lib/host.js +422 -4
- package/lib/plan.js +869 -37
- package/lib/replan.js +602 -0
- package/lib/runtime.js +1316 -27
- package/package.json +1 -1
- package/src/client.ts +154 -4
- package/src/host.ts +453 -3
- package/src/plan.ts +827 -32
- package/src/replan.ts +642 -0
- package/src/runtime.ts +1305 -26
package/lib/host.js
CHANGED
|
@@ -11,7 +11,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
11
11
|
* - dsh_workplan_update and dsh_workplan_dispatch model tools;
|
|
12
12
|
* - the read-only dashboard route.
|
|
13
13
|
*/
|
|
14
|
-
import { applyHardeningHeaders, cancelToolOutputSchema, createWorkplanRuntime, dispatchToolOutputSchema, plannerOutputSchema, statusToolOutputSchema, updateToolOutputSchema, } from './runtime.js';
|
|
14
|
+
import { applyHardeningHeaders, cancelToolOutputSchema, createWorkplanRuntime, dispatchToolOutputSchema, plannerOutputSchema, replanToolOutputSchema, statusToolOutputSchema, updateToolOutputSchema, } from './runtime.js';
|
|
15
15
|
import { isRecord } from './plan.js';
|
|
16
16
|
import { autoResumeEnabledFrom } from './auto-resume.js';
|
|
17
17
|
/*
|
|
@@ -103,8 +103,18 @@ const PROMPT_SECTION = [
|
|
|
103
103
|
'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 续跑剩余项。',
|
|
104
104
|
'6. 如果续跑被拒绝、受阻项无法恢复、证据补不齐、计划已取消但未完成,或用户要求先看中间结果:答复开头必须写「未完成:剩余 N 项(列出 ID)与原因」,正文只能按中间结果表述,不得包装成成品。取消不会给你交付许可。',
|
|
105
105
|
'7. 子任务有硬执行上限(默认 15 分钟/步)与整轮预算(默认 20 分钟):子 Agent 接近上限时应先把已完成内容落盘并在结论里列出路径。任何「达到执行上限」「本轮预算用尽」都不等于「什么都没做」:状态里的 error 会列出「声明产物已在盘上」,必须先用文件核对;若产物已覆盖验收标准,用 dsh_workplan_update 复核改判,只补缺失部分再续跑,禁止无视盘上产物把整步重跑。',
|
|
106
|
+
'8. 出现「待指示」项(closure=escalated,左侧栏显示「待指示」并附问题摘录)时,必须在当轮处理:用 dsh_workplan_instruct 下发决定(投递到子会话并把该行恢复为执行中),或确认放弃后用 dsh_workplan_update 置 blocked。不要沉默略过,也不要把待指示当成普通失败——它是一条还没被回答的请示,会一直占着交付门禁。',
|
|
107
|
+
'9. 出现「已下发未响应」(ackOverdue)时,不要重复派发:先用 dsh_workplan_status 看该行 childId 与已等待时长,必要时用 dsh_workplan_followup 投递一次说明;超过硬超时仍未响应会记为 blocked(blockedKind=no-ack),可以再下发指示复活。',
|
|
108
|
+
/*
|
|
109
|
+
* [1.11.0] T7:需求变更的重规划不能只靠模型自觉。
|
|
110
|
+
*
|
|
111
|
+
* 变更通知(workplan-change)与 replan 工具都在,但如果提示词不写“必须判定”,
|
|
112
|
+
* 模型仍可能用旧计划直接交付。这里把它写成第 10 条硬规则:判定动作只有
|
|
113
|
+
* replan / dispatch / cancel 三个,旧行保留可追溯,新行必须再 dispatch。
|
|
114
|
+
*/
|
|
115
|
+
'10. 执行中用户提出新要求,或原安排的前提被推翻时,必须用 `dsh_workplan_replan` 明确判定:`cancel`/`replace` 受影响的旧子任务、`add` 新工作,并在 `reason` 写清原因;旧行保留为「已重规划」(可追溯、不计入剩余项、不再调度),随后调用 `dsh_workplan_dispatch` 执行新行。只是补充说明、不改范围时用 `dsh_workplan_update` 的 `note`;不允许用旧计划直接交付。',
|
|
106
116
|
'结果消息里每个完成项都带 verification 与 acceptance:`structured` 是子 Agent 逐条自检通过,`unverified` 是自述但未逐条确认,`failed` 是自检失败(已按受阻处理),`legacy` 是旧格式回传。只有 structured 且 acceptance 每项 pass 才算可交付;其余必须你自己核对产物,并用 dsh_workplan_update 的 verification/acceptance/artifacts 字段把核对结果写回(这些字段会持久化、刷新后仍生效),不要把“看着没问题”当成证据。',
|
|
107
|
-
'子 Agent 通过 `needs`
|
|
117
|
+
'子 Agent 通过 `needs` 提出的跨部门需求会列在结果消息的「跨部门待转达」里,并自动登记为待处理需求、计入交付门禁:用 `dsh_workplan_handoff` 逐条处置(list 查看、assign 登记责任部门、resolve 写入答复或产物引用、close 判定无需动作),不要忽略。注意:assign 不产生工作(没有常驻部门代理),需要产出就用 `dsh_workplan_replan(action=add)` 建该部门的子任务或自己完成;对「待指示」的行 resolve 会直接把答复投递给子会话。每条需求都必须有处置结论,否则 present 会被拒绝。',
|
|
108
118
|
'长任务可以用 `dsh_workplan_dispatch({ mode: "async" })` 先开跑并立即答复用户,再用 `dsh_workplan_status` 查看进度;async 返回的是“已开跑”,不是“已完成”。',
|
|
109
119
|
'如果自动分解降级,先向用户说明失败原因并询问是否重试,在用户确认前不要开始执行任务。',
|
|
110
120
|
].join('\n');
|
|
@@ -249,6 +259,139 @@ function createUpdateTool(runtime) {
|
|
|
249
259
|
},
|
|
250
260
|
};
|
|
251
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* [1.11.0] 需求变更 → 重规划的唯一入口(T4 C-11 / T7)。
|
|
264
|
+
*
|
|
265
|
+
* 触发条件写在工具描述里,因为「什么时候该重规划」是语义判断,代码不猜:
|
|
266
|
+
* - 执行中用户提出新要求、原安排不再成立;
|
|
267
|
+
* - 验收标准/交付物变化,旧子任务的完成不再等于用户要的结果;
|
|
268
|
+
* - 上游结论推翻了后续步骤的前提。
|
|
269
|
+
* 只补说明、不改范围时不要用本工具(那会白白留下一批“已重规划”旧行),
|
|
270
|
+
* 改用 `dsh_workplan_update` 的 note。
|
|
271
|
+
*
|
|
272
|
+
* 旧状态不删除:`planReplan()` 在计划定义上写 `supersededAt/replacedBy`,
|
|
273
|
+
* `applyReplanStatuses()` 在状态条上写 `closure:'replanned'` + `replannedFrom`,
|
|
274
|
+
* 两者是同一次写入的两个镜像;旧行保留可追溯、不计入剩余项、不再调度。
|
|
275
|
+
* 重规划本身不执行新行——必须再调用 `dsh_workplan_dispatch`。
|
|
276
|
+
*/
|
|
277
|
+
function createReplanTool(runtime) {
|
|
278
|
+
return {
|
|
279
|
+
name: 'dsh_workplan_replan',
|
|
280
|
+
description: '按需求变更重规划当前计划:把受影响的旧子任务标为「已重规划」(保留可追溯,不再调度、不计入剩余项),'
|
|
281
|
+
+ '并为每个被替换项生成一个接替子任务、为新增工作生成新子任务。'
|
|
282
|
+
+ '触发条件:执行中用户提出新要求、验收标准或交付物变化、原安排的前提被推翻。'
|
|
283
|
+
+ '只补充说明而不改范围时不要调用本工具,改用 dsh_workplan_update 的 note。'
|
|
284
|
+
+ '重规划不会中途改写正在跑的本轮:执行中调用返回 REPLAN_PLAN_RUNNING 并把变更原文记为 changeRequest,'
|
|
285
|
+
+ '等本轮结束后用同一组 changes 重试即可(变更不会丢)。'
|
|
286
|
+
+ '重规划成功后必须再调用 dsh_workplan_dispatch 执行新行;旧行不会复活。',
|
|
287
|
+
parameters: {
|
|
288
|
+
type: 'object',
|
|
289
|
+
properties: {
|
|
290
|
+
planId: {
|
|
291
|
+
type: 'string',
|
|
292
|
+
description: '计划 ID;省略时使用当前会话最新计划。',
|
|
293
|
+
},
|
|
294
|
+
reason: {
|
|
295
|
+
type: 'string',
|
|
296
|
+
description: '为什么原安排失效(必填,会写进持久化记录与旧行留档)。',
|
|
297
|
+
},
|
|
298
|
+
changeText: {
|
|
299
|
+
type: 'string',
|
|
300
|
+
description: '可选:用户变更原文。本轮派发仍在执行时,本工具不会改计划,只会把它记为 changeRequest。',
|
|
301
|
+
},
|
|
302
|
+
changes: {
|
|
303
|
+
type: 'array',
|
|
304
|
+
minItems: 1,
|
|
305
|
+
maxItems: 12,
|
|
306
|
+
description: '逐项说明受影响的子任务:cancel=撤销,replace=用新行接替,add=追加新工作。',
|
|
307
|
+
items: {
|
|
308
|
+
type: 'object',
|
|
309
|
+
properties: {
|
|
310
|
+
subtaskId: {
|
|
311
|
+
type: 'string',
|
|
312
|
+
description: '受影响的旧子任务 ID(add 时可填任意未被占用的新 ID)。',
|
|
313
|
+
},
|
|
314
|
+
action: {
|
|
315
|
+
type: 'string',
|
|
316
|
+
enum: ['cancel', 'replace', 'add'],
|
|
317
|
+
description: 'cancel=只撤销;replace=撤销旧行并插入接替行;add=不动旧行,追加新行。',
|
|
318
|
+
},
|
|
319
|
+
reason: { type: 'string', description: '该子任务受影响的原因;省略时继承顶层 reason。' },
|
|
320
|
+
replacement: {
|
|
321
|
+
type: 'object',
|
|
322
|
+
description: 'replace 必填:改后的字段(未给的字段继承旧行)。',
|
|
323
|
+
properties: {
|
|
324
|
+
id: { type: 'string', description: '接替行 ID(默认在旧 ID 后加 b);最长 16 字符,不能与现有 ID 重复。' },
|
|
325
|
+
title: { type: 'string' },
|
|
326
|
+
department: { type: 'string' },
|
|
327
|
+
role: { type: 'string' },
|
|
328
|
+
objective: { type: 'string' },
|
|
329
|
+
method: { type: 'array', items: { type: 'string' } },
|
|
330
|
+
inputs: { type: 'array', items: { type: 'string' } },
|
|
331
|
+
outputs: { type: 'array', items: { type: 'string' } },
|
|
332
|
+
acceptance: { type: 'array', items: { type: 'string' } },
|
|
333
|
+
risk: { type: 'string' },
|
|
334
|
+
},
|
|
335
|
+
additionalProperties: false,
|
|
336
|
+
},
|
|
337
|
+
newSubtask: {
|
|
338
|
+
type: 'object',
|
|
339
|
+
description: 'add 必填:新增子任务,title 与 objective 必填。',
|
|
340
|
+
properties: {
|
|
341
|
+
id: { type: 'string', description: '新行 ID;省略时自动生成 R<修订号>-<序号>。' },
|
|
342
|
+
title: { type: 'string' },
|
|
343
|
+
objective: { type: 'string' },
|
|
344
|
+
department: { type: 'string' },
|
|
345
|
+
role: { type: 'string' },
|
|
346
|
+
method: { type: 'array', items: { type: 'string' } },
|
|
347
|
+
inputs: { type: 'array', items: { type: 'string' } },
|
|
348
|
+
outputs: { type: 'array', items: { type: 'string' } },
|
|
349
|
+
acceptance: { type: 'array', items: { type: 'string' } },
|
|
350
|
+
dependsOn: { type: 'array', items: { type: 'string' } },
|
|
351
|
+
risk: { type: 'string' },
|
|
352
|
+
reason: { type: 'string' },
|
|
353
|
+
},
|
|
354
|
+
required: ['title', 'objective'],
|
|
355
|
+
additionalProperties: false,
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
required: ['subtaskId', 'action'],
|
|
359
|
+
additionalProperties: false,
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
required: ['reason', 'changes'],
|
|
364
|
+
additionalProperties: false,
|
|
365
|
+
},
|
|
366
|
+
output: {
|
|
367
|
+
schema: replanToolOutputSchema(),
|
|
368
|
+
render(_args, value) {
|
|
369
|
+
const result = isRecord(value) ? value : {};
|
|
370
|
+
if (!result.ok) {
|
|
371
|
+
return textContent(`重规划失败${result.code ? `(${String(result.code)})` : ''}:${String(result.error ?? result.hint ?? '未知错误')}`
|
|
372
|
+
+ (result.code === 'REPLAN_PLAN_RUNNING'
|
|
373
|
+
? '|变更已记录,等本轮结束(dispatch 返回后)再用同一组 changes 重试。'
|
|
374
|
+
: ''));
|
|
375
|
+
}
|
|
376
|
+
const marks = Array.isArray(result.marks) ? result.marks : [];
|
|
377
|
+
const added = Array.isArray(result.added) ? result.added : [];
|
|
378
|
+
const changed = marks
|
|
379
|
+
.map((mark) => `${String(mark?.subtaskId ?? '')}→${Array.isArray(mark?.replacedBy) && mark.replacedBy.length > 0 ? mark.replacedBy.join('、') : '撤销'}`)
|
|
380
|
+
.join(',');
|
|
381
|
+
const fresh = added.map((item) => String(item?.subtaskId ?? '')).filter(Boolean).join('、');
|
|
382
|
+
return textContent(`计划 ${String(result.planId ?? '')} 已重规划为修订 r${Number(result.planRevision ?? 0)}`
|
|
383
|
+
+ (changed ? `|受影响:${changed}` : '')
|
|
384
|
+
+ (fresh ? `|新增:${fresh}` : '')
|
|
385
|
+
+ '|旧行保留为「已重规划」(可追溯、不计入剩余项、不再调度)'
|
|
386
|
+
+ '|下一步:调用 dsh_workplan_dispatch 执行新行。');
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
async execute(args, exec) {
|
|
390
|
+
const parsed = asObject(args) ?? {};
|
|
391
|
+
return runtime.replanPlan(exec.agent, parsed);
|
|
392
|
+
},
|
|
393
|
+
};
|
|
394
|
+
}
|
|
252
395
|
function createCancelTool(runtime) {
|
|
253
396
|
return {
|
|
254
397
|
name: 'dsh_workplan_cancel',
|
|
@@ -391,6 +534,236 @@ function createFollowupTool(runtime) {
|
|
|
391
534
|
},
|
|
392
535
|
};
|
|
393
536
|
}
|
|
537
|
+
/**
|
|
538
|
+
* [1.11.0] 子 → 父的唯一反向通道(T4 C-09 / T6 M5)。
|
|
539
|
+
*
|
|
540
|
+
* 为什么要有独立工具而不是让子 Agent 在结果块里写 `question`:结果块只在
|
|
541
|
+
* 子会话结束时才被父会话看到,那时子会话已经停了,请示与「已结束」无法区分,
|
|
542
|
+
* 主 Agent 只会在下一次 dispatch 之后才发现有人在等回答。这个工具把请示
|
|
543
|
+
* 提前到「还在跑」的时刻,并在状态条上留下 `closure:'escalated'`。
|
|
544
|
+
*/
|
|
545
|
+
function createEscalateTool(runtime) {
|
|
546
|
+
return {
|
|
547
|
+
name: 'dsh_workplan_escalate',
|
|
548
|
+
description: '子 Agent 遇阻时向父会话上报请示,并把该子任务置为「待指示」。'
|
|
549
|
+
+ '遇阻(缺权限/缺输入/依赖产物缺失/需求自相矛盾/无法验证/同一命令连续两次失败/需要主 Agent 决定方向)时,'
|
|
550
|
+
+ '第一动作是调用本工具,然后停止推进、只做只读核对,等待主 Agent 指示。'
|
|
551
|
+
+ '不需要外部决定时不要调用;调用后不要自行选定一个选项继续。',
|
|
552
|
+
parameters: {
|
|
553
|
+
type: 'object',
|
|
554
|
+
properties: {
|
|
555
|
+
subtaskId: {
|
|
556
|
+
type: 'string',
|
|
557
|
+
description: '你的子任务 ID(仅用于回显核对;服务端按父子会话关系反查,自报值不作为定位依据)。',
|
|
558
|
+
},
|
|
559
|
+
question: {
|
|
560
|
+
type: 'string',
|
|
561
|
+
description: '需要主 Agent 回答的单个问题:写清卡在哪一步、已经尝试过什么、需要谁做什么决定。必填。',
|
|
562
|
+
},
|
|
563
|
+
options: {
|
|
564
|
+
type: 'array',
|
|
565
|
+
items: { type: 'string' },
|
|
566
|
+
description: '可选的处理方向(建议 2–4 个)。只是建议,不会被自动执行,也不会替你选择。',
|
|
567
|
+
},
|
|
568
|
+
needs: {
|
|
569
|
+
type: 'array',
|
|
570
|
+
items: { type: 'string' },
|
|
571
|
+
description: '需要其他部门/人员提供什么(每条一句话),由主 Agent 转达。',
|
|
572
|
+
},
|
|
573
|
+
},
|
|
574
|
+
required: ['question'],
|
|
575
|
+
additionalProperties: false,
|
|
576
|
+
},
|
|
577
|
+
output: {
|
|
578
|
+
schema: {
|
|
579
|
+
type: 'object',
|
|
580
|
+
properties: {
|
|
581
|
+
ok: { type: 'boolean' },
|
|
582
|
+
planId: { type: 'string' },
|
|
583
|
+
subtaskId: { type: 'string' },
|
|
584
|
+
status: { type: 'string' },
|
|
585
|
+
closure: { type: 'string' },
|
|
586
|
+
question: { type: 'string' },
|
|
587
|
+
code: { type: 'string' },
|
|
588
|
+
error: { type: 'string' },
|
|
589
|
+
message: { type: 'string' },
|
|
590
|
+
},
|
|
591
|
+
required: ['ok'],
|
|
592
|
+
additionalProperties: true,
|
|
593
|
+
},
|
|
594
|
+
render(_args, value) {
|
|
595
|
+
const result = isRecord(value) ? value : {};
|
|
596
|
+
if (!result.ok) {
|
|
597
|
+
return textContent(`上报未登记:${String(result.error ?? result.code ?? '未知错误')}`
|
|
598
|
+
+ '|改为在结果块里写 "status":"blocked" 并附 "question",仍然算作请示。');
|
|
599
|
+
}
|
|
600
|
+
return textContent(`${String(result.subtaskId ?? '')} 已登记为「待指示」`
|
|
601
|
+
+ (result.alreadyEscalated ? '(此前已登记,未重复提交)' : '')
|
|
602
|
+
+ `:${String(result.question ?? '')}`
|
|
603
|
+
+ '|现在停止推进,只做只读核对;等待主 Agent 指示后再继续。');
|
|
604
|
+
},
|
|
605
|
+
},
|
|
606
|
+
async execute(args, exec) {
|
|
607
|
+
const parsed = asObject(args) ?? {};
|
|
608
|
+
return runtime.escalateTool(exec.agent, parsed);
|
|
609
|
+
},
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* [1.11.0] 主 → 子的指示通道(T4 C-10 / T6 M6)。
|
|
614
|
+
*
|
|
615
|
+
* 服务端硬校验:根会话、该行 `closure:'escalated'`、`childId` 是本会话直接
|
|
616
|
+
* 子会话、instruction 非空且 ≤4000 字符。投递失败时不改状态 —— 「我发了」
|
|
617
|
+
* 与「它收到了」必须是两件事,否则界面会显示一个没人执行的指示。
|
|
618
|
+
*/
|
|
619
|
+
function createInstructTool(runtime) {
|
|
620
|
+
return {
|
|
621
|
+
name: 'dsh_workplan_instruct',
|
|
622
|
+
description: '向一条「待指示」子任务下发主 Agent 的决定:投递给对应子会话,并把该行恢复为执行中(closure=instructed)。'
|
|
623
|
+
+ '只有根会话可调用;只接受 closure=escalated 的行。'
|
|
624
|
+
+ '投递失败时状态不变(仍是待指示),按返回的 hint 重试或改用 dsh_workplan_update 明确放弃。',
|
|
625
|
+
parameters: {
|
|
626
|
+
type: 'object',
|
|
627
|
+
properties: {
|
|
628
|
+
planId: {
|
|
629
|
+
type: 'string',
|
|
630
|
+
description: '计划 ID;省略时使用当前会话最新计划。',
|
|
631
|
+
},
|
|
632
|
+
subtaskId: {
|
|
633
|
+
type: 'string',
|
|
634
|
+
description: '待指示的子任务 ID,例如 T3。',
|
|
635
|
+
},
|
|
636
|
+
instruction: {
|
|
637
|
+
type: 'string',
|
|
638
|
+
description: '要子 Agent 执行的决定:写清结论、约束与仍需保留的边界;不要只说“继续”。最多 4000 字符。',
|
|
639
|
+
},
|
|
640
|
+
},
|
|
641
|
+
required: ['subtaskId', 'instruction'],
|
|
642
|
+
additionalProperties: false,
|
|
643
|
+
},
|
|
644
|
+
output: {
|
|
645
|
+
schema: {
|
|
646
|
+
type: 'object',
|
|
647
|
+
properties: {
|
|
648
|
+
ok: { type: 'boolean' },
|
|
649
|
+
planId: { type: 'string' },
|
|
650
|
+
subtaskId: { type: 'string' },
|
|
651
|
+
status: { type: 'string' },
|
|
652
|
+
closure: { type: 'string' },
|
|
653
|
+
revision: { type: 'number' },
|
|
654
|
+
messageId: { type: 'string' },
|
|
655
|
+
deliveryReady: { type: 'boolean' },
|
|
656
|
+
code: { type: 'string' },
|
|
657
|
+
error: { type: 'string' },
|
|
658
|
+
hint: { type: 'string' },
|
|
659
|
+
},
|
|
660
|
+
required: ['ok'],
|
|
661
|
+
additionalProperties: true,
|
|
662
|
+
},
|
|
663
|
+
render(_args, value) {
|
|
664
|
+
const result = isRecord(value) ? value : {};
|
|
665
|
+
if (!result.ok) {
|
|
666
|
+
return textContent(`指示未下发:${String(result.error ?? result.code ?? '未知错误')}`
|
|
667
|
+
+ (result.hint ? `|下一步:${String(result.hint)}` : ''));
|
|
668
|
+
}
|
|
669
|
+
return textContent(`${String(result.subtaskId ?? '')} 已收到指示并恢复执行(revision ${String(result.revision ?? '')})`
|
|
670
|
+
+ (result.messageId ? `,messageId ${String(result.messageId)}` : '')
|
|
671
|
+
+ '|该行现在显示「已收到指示」;完成前仍不得交付,需等它回报结果。');
|
|
672
|
+
},
|
|
673
|
+
},
|
|
674
|
+
async execute(args, exec) {
|
|
675
|
+
const parsed = asObject(args) ?? {};
|
|
676
|
+
return runtime.instructTool(exec.agent, parsed, exec.signal);
|
|
677
|
+
},
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* [1.11.0] 跨部门需求的处置入口(用户 m00687)。
|
|
682
|
+
*
|
|
683
|
+
* 子 Agent 提出的 `needs` 会自动变成一条 open handoff,并进入交付门禁;
|
|
684
|
+
* 只有根会话能用本工具把需求指派给部门、写入答复或判定无需动作。这是
|
|
685
|
+
* 「跨部门协作必须有始有终」的唯一人工出口,避免需求只停留在提示词文本里。
|
|
686
|
+
*/
|
|
687
|
+
function createHandoffTool(runtime) {
|
|
688
|
+
return {
|
|
689
|
+
name: 'dsh_workplan_handoff',
|
|
690
|
+
description: '处置跨部门需求(needs)。子 Agent 每条 needs 都会登记为待处理需求,未处置会拦住交付。插件没有常驻部门代理:assign 只登记责任,实际产出要用 dsh_workplan_replan(action=add) 建子任务或由你完成;被答复的行若在「待指示」,resolve 会把答复直接投递给子会话。'
|
|
691
|
+
+ '动作:list 列出全部待处理需求;assign 指派给某个部门(department);'
|
|
692
|
+
+ 'resolve 写入书面答复或产物引用(response),表示需求已满足;close 判定无需动作。'
|
|
693
|
+
+ '只有根会话可调用。',
|
|
694
|
+
parameters: {
|
|
695
|
+
type: 'object',
|
|
696
|
+
properties: {
|
|
697
|
+
action: {
|
|
698
|
+
type: 'string',
|
|
699
|
+
enum: ['list', 'assign', 'resolve', 'close'],
|
|
700
|
+
description: 'list=查看;assign=指派部门;resolve=写入答复并解除阻塞;close=判定无需动作。',
|
|
701
|
+
},
|
|
702
|
+
planId: {
|
|
703
|
+
type: 'string',
|
|
704
|
+
description: '计划 ID;省略时使用当前会话最新计划。',
|
|
705
|
+
},
|
|
706
|
+
subtaskId: {
|
|
707
|
+
type: 'string',
|
|
708
|
+
description: '提出该需求的子任务 ID。除 list 外必填。',
|
|
709
|
+
},
|
|
710
|
+
handoffId: {
|
|
711
|
+
type: 'string',
|
|
712
|
+
description: '需求编号(如 H1);省略时处理该行第一条 open/routed 需求。',
|
|
713
|
+
},
|
|
714
|
+
department: {
|
|
715
|
+
type: 'string',
|
|
716
|
+
description: 'assign 必填:负责满足该需求的部门 ID。',
|
|
717
|
+
},
|
|
718
|
+
response: {
|
|
719
|
+
type: 'string',
|
|
720
|
+
description: 'resolve 必填:写清答复,或指出已由哪项产物/子任务满足该需求。最多 4000 字符。',
|
|
721
|
+
},
|
|
722
|
+
},
|
|
723
|
+
required: ['action'],
|
|
724
|
+
additionalProperties: false,
|
|
725
|
+
},
|
|
726
|
+
output: {
|
|
727
|
+
schema: {
|
|
728
|
+
type: 'object',
|
|
729
|
+
properties: {
|
|
730
|
+
ok: { type: 'boolean' },
|
|
731
|
+
planId: { type: 'string' },
|
|
732
|
+
subtaskId: { type: 'string' },
|
|
733
|
+
handoff: { type: 'object' },
|
|
734
|
+
count: { type: 'number' },
|
|
735
|
+
handoffs: { type: 'array' },
|
|
736
|
+
deliveryReady: { type: 'boolean' },
|
|
737
|
+
code: { type: 'string' },
|
|
738
|
+
error: { type: 'string' },
|
|
739
|
+
hint: { type: 'string' },
|
|
740
|
+
},
|
|
741
|
+
required: ['ok'],
|
|
742
|
+
additionalProperties: true,
|
|
743
|
+
},
|
|
744
|
+
render(_args, value) {
|
|
745
|
+
const result = isRecord(value) ? value : {};
|
|
746
|
+
if (!result.ok) {
|
|
747
|
+
return textContent(`处置未生效:${String(result.error ?? result.code ?? '未知错误')}`);
|
|
748
|
+
}
|
|
749
|
+
if (Array.isArray(result.handoffs)) {
|
|
750
|
+
if (result.handoffs.length === 0)
|
|
751
|
+
return textContent('没有待处理的跨部门需求。');
|
|
752
|
+
return textContent(`待处理跨部门需求 ${result.handoffs.length} 条:\n`
|
|
753
|
+
+ result.handoffs.slice(0, 10).map((item) => `- ${String(item.subtaskId)} ${String(item.id)}|${String(item.status)}`
|
|
754
|
+
+ `${item.department ? ` → ${String(item.department)}` : ''}|${String(item.request)}`).join('\n'));
|
|
755
|
+
}
|
|
756
|
+
return textContent(`${String(result.subtaskId ?? '')} ${String(result.handoff?.id ?? '')} 已更新为 ${String(result.handoff?.status ?? '')}`
|
|
757
|
+
+ `|${result.deliveryReady === true ? '交付门禁已通过' : '交付门禁仍未通过'}`
|
|
758
|
+
+ `|${String(result.hint ?? '')}`);
|
|
759
|
+
},
|
|
760
|
+
},
|
|
761
|
+
async execute(args, exec) {
|
|
762
|
+
const parsed = asObject(args) ?? {};
|
|
763
|
+
return runtime.handoffTool(exec.agent, parsed, exec.signal);
|
|
764
|
+
},
|
|
765
|
+
};
|
|
766
|
+
}
|
|
394
767
|
function createStatusTool(runtime) {
|
|
395
768
|
return {
|
|
396
769
|
name: 'dsh_workplan_status',
|
|
@@ -553,6 +926,24 @@ function createDispatchTool(runtime) {
|
|
|
553
926
|
* [1.10.6] 注意:`autoResume` 已改用 `autoResumeEnabledFrom`(默认开启,
|
|
554
927
|
* 且 `0/false/no/off` 可以显式关闭)。本函数保留给「默认关闭」语义的开关。
|
|
555
928
|
*/
|
|
929
|
+
/**
|
|
930
|
+
* [1.11.0] `strictCompletion` 的三态解析:显式配置 > 显式环境变量 > 默认 true。
|
|
931
|
+
*
|
|
932
|
+
* 不能复用 `booleanSetting`:那个函数「未配置即 false」,会把默认开启的
|
|
933
|
+
* 完成门禁反过来关掉(1.10.6 的 autoResume 就栽在这上面)。
|
|
934
|
+
*/
|
|
935
|
+
function strictCompletionEnabledFrom(configValue, envValue) {
|
|
936
|
+
if (typeof configValue === 'boolean')
|
|
937
|
+
return configValue;
|
|
938
|
+
const raw = envValue === undefined || envValue === null ? '' : String(envValue).trim();
|
|
939
|
+
if (raw !== '') {
|
|
940
|
+
if (/^(1|true|yes|on)$/i.test(raw))
|
|
941
|
+
return true;
|
|
942
|
+
if (/^(0|false|no|off)$/i.test(raw))
|
|
943
|
+
return false;
|
|
944
|
+
}
|
|
945
|
+
return true;
|
|
946
|
+
}
|
|
556
947
|
function booleanSetting(configValue, envName) {
|
|
557
948
|
if (typeof configValue === 'boolean')
|
|
558
949
|
return configValue;
|
|
@@ -620,6 +1011,11 @@ export function apply(ctx, config = {}) {
|
|
|
620
1011
|
*/
|
|
621
1012
|
autoResume: autoResumeEnabledFrom(config.autoResume, settingEnv('DSH_WORKPLAN_AUTO_RESUME')),
|
|
622
1013
|
autoResumeMaxAttempts: numericSetting(config.autoResumeMaxAttempts, 'DSH_WORKPLAN_AUTO_RESUME_MAX'),
|
|
1014
|
+
/*
|
|
1015
|
+
* [1.11.0] 三态解析(显式配置 > 显式环境变量 > 默认 true)。
|
|
1016
|
+
* 与 autoResume 用同一种写法:未配置时走默认值,而不是悄悄等于 false。
|
|
1017
|
+
*/
|
|
1018
|
+
strictEvidence: strictCompletionEnabledFrom(config.strictCompletion, settingEnv('DSH_WORKPLAN_STRICT_COMPLETION')),
|
|
623
1019
|
});
|
|
624
1020
|
ctx.effect(() => ctx.systemPrompt.section({
|
|
625
1021
|
name: 'dsh-workplan',
|
|
@@ -630,6 +1026,28 @@ export function apply(ctx, config = {}) {
|
|
|
630
1026
|
ctx.effect(() => ctx.tools.register(createCancelTool(runtime)));
|
|
631
1027
|
ctx.effect(() => ctx.tools.register(createStatusTool(runtime)));
|
|
632
1028
|
ctx.effect(() => ctx.tools.register(createFollowupTool(runtime)));
|
|
1029
|
+
/*
|
|
1030
|
+
* [1.11.0] 闭环的两条工具通道(T4 C-09 / C-10)。
|
|
1031
|
+
*
|
|
1032
|
+
* `escalate` 必须对子会话可见(子 Agent 是它的唯一调用者),`instruct`
|
|
1033
|
+
* 必须只有根会话可用(服务端 `isRootSession` 硬校验,不依赖提示词)。
|
|
1034
|
+
* 注册在插件根与其它工具一致:宿主按会话注入哪些工具由平台决定,插件
|
|
1035
|
+
* 侧不做过滤;权限判断一律落在 execute 内部。
|
|
1036
|
+
*/
|
|
1037
|
+
ctx.effect(() => ctx.tools.register(createEscalateTool(runtime)));
|
|
1038
|
+
ctx.effect(() => ctx.tools.register(createInstructTool(runtime)));
|
|
1039
|
+
/*
|
|
1040
|
+
* [1.11.0] 需求变更的重规划入口(T4 C-11 / T7)。
|
|
1041
|
+
*
|
|
1042
|
+
* 根会话工具:子 Agent 不能改写主计划(execute 内部 `isRootSession` 硬校验)。
|
|
1043
|
+
* 它只在“计划定义需要改”时使用;执行中调用会拒绝改计划但保留变更原文。
|
|
1044
|
+
*/
|
|
1045
|
+
ctx.effect(() => ctx.tools.register(createReplanTool(runtime)));
|
|
1046
|
+
/*
|
|
1047
|
+
* [1.11.0] 跨部门需求处置(用户 m00687):注册在根插件上,`execute` 内部
|
|
1048
|
+
* 用 `isRootSession` 硬校验,子会话即使拿到工具表也无法处置需求。
|
|
1049
|
+
*/
|
|
1050
|
+
ctx.effect(() => ctx.tools.register(createHandoffTool(runtime)));
|
|
633
1051
|
ctx.effect(() => ctx.tools.register(createDispatchTool(runtime)));
|
|
634
1052
|
/*
|
|
635
1053
|
* Plan mode produces a plan for review, not department execution. Denying
|
|
@@ -702,11 +1120,11 @@ export function apply(ctx, config = {}) {
|
|
|
702
1120
|
}
|
|
703
1121
|
export const meta = {
|
|
704
1122
|
name,
|
|
705
|
-
version: '1.
|
|
1123
|
+
version: '1.11.0',
|
|
706
1124
|
promptOrder: PROMPT_ORDER,
|
|
707
1125
|
routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
|
|
708
1126
|
};
|
|
709
|
-
export { PROMPT_SECTION, createCancelTool, createDispatchTool, createStatusTool, createUpdateTool, plannerOutputSchema };
|
|
1127
|
+
export { PROMPT_SECTION, createCancelTool, createDispatchTool, createEscalateTool, createHandoffTool, createInstructTool, createReplanTool, createStatusTool, createUpdateTool, plannerOutputSchema };
|
|
710
1128
|
/**
|
|
711
1129
|
* [1.8.18] 写工具的路径级闸门(T7-N2),与 `toolGuardReason` 分开注册。
|
|
712
1130
|
*
|