dsh-workplan 2.3.2 → 2.3.9
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 +8 -0
- package/README.en.md +2 -2
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/client.js +40 -0
- package/docs/cc/ADV-FSP-FUNCTIONAL-SPEC.md +1 -0
- package/docs/cc/AVA-VULNERABILITY-ANALYSIS.md +10 -0
- package/docs/cc/SECURITY-TARGET.md +1 -0
- package/docs/release-record-2.3.2-20261110.md +25 -0
- package/lib/client.js +40 -0
- package/lib/host.js +134 -2
- package/lib/llm-rules.js +221 -0
- package/lib/plan.js +158 -4
- package/lib/replan.js +16 -5
- package/lib/runtime.js +384 -13
- package/package.json +1 -1
- package/src/client.ts +47 -0
- package/src/host.ts +142 -2
- package/src/llm-rules.ts +345 -0
- package/src/plan.ts +178 -3
- package/src/replan.ts +16 -5
- package/src/runtime.ts +392 -13
package/src/runtime.ts
CHANGED
|
@@ -91,6 +91,19 @@ import {
|
|
|
91
91
|
} from './plan.js'
|
|
92
92
|
import type { PresentDenialVerdict, PresentDenyCode } from './plan.js'
|
|
93
93
|
import { auditClarifyNeed, compactUnderstandingAudit, validatePlanContext } from './understanding.js'
|
|
94
|
+
// [2.3.9][T3] LLM 家族检测 + 推理等级静态约束(用户强制要求 1/2;详见 llm-rules.ts 头注释)。
|
|
95
|
+
// [2.3.9][T4b] 追加第三层派发纯逻辑核:buildLlmRulesBrief(要求 1/2 全文告知注入,
|
|
96
|
+
// 部门层与专家/组员层共用同一事实源)、planDelegations(负责人「先全面梳理再分配」
|
|
97
|
+
// 硬门禁 + 分工表校验 + 等级钳制)、buildDelegateePrompt(第三层任务书)。
|
|
98
|
+
import {
|
|
99
|
+
allowedEffortsForModel,
|
|
100
|
+
buildDelegateePrompt,
|
|
101
|
+
buildLlmRulesBrief,
|
|
102
|
+
classifyModelFamily,
|
|
103
|
+
correctEffortForModel,
|
|
104
|
+
highestEffortOf,
|
|
105
|
+
planDelegations,
|
|
106
|
+
} from './llm-rules.js'
|
|
94
107
|
import { phaseGateFromErrors, phaseSummaryLine, validatePhaseEvidence } from './three-phase.js'
|
|
95
108
|
import {
|
|
96
109
|
lessonStats,
|
|
@@ -804,11 +817,40 @@ export async function runPlanner(ctx: any, options: any) {
|
|
|
804
817
|
// 用户的成本预期,所以先归一化再进白名单。
|
|
805
818
|
const plannerEffortRaw = String(process.env.DSH_WORKPLAN_PLANNER_REASONING_EFFORT ?? '').trim().toLowerCase()
|
|
806
819
|
const plannerEffort = REASONING_EFFORTS.includes(plannerEffortRaw) ? plannerEffortRaw : ''
|
|
807
|
-
|
|
820
|
+
/*
|
|
821
|
+
* [2.3.9][T3/llm-rules] 用户强制要求 1/2(分配前先检测模型家族):qwen 开头
|
|
822
|
+
* 模型只允许 low / medium / xhigh,其余模型只允许 low / high / max。
|
|
823
|
+
* 默认档随家族取「合法集内最高档」(qwen⇒xhigh、非 qwen⇒max);env 显式
|
|
824
|
+
* 覆盖仍优先,覆盖值同样过静态收窄。静态约束先于宿主能力钳制执行(两道闸:
|
|
825
|
+
* 静态表权威,能力面在其上继续交集钳制,均留痕,与 U7 裁决一致)。模型名
|
|
826
|
+
* 缺失⇒不施加静态约束并用原默认档,保持 [2.2.7]「无从判定⇒不阻断」旧行为。
|
|
827
|
+
*/
|
|
828
|
+
const plannerStaticAllowed = allowedEffortsForModel(modelSelection?.model)
|
|
829
|
+
const plannerFamilyDefault = highestEffortOf(plannerStaticAllowed) ?? DEFAULT_PLANNER_REASONING_EFFORT
|
|
830
|
+
const requestedPlannerEffort = plannerEffort || plannerFamilyDefault
|
|
831
|
+
const plannerEffortOriginLabel = plannerEffort ? 'env' : `default-${plannerFamilyDefault}`
|
|
832
|
+
const plannerStaticCorrection = plannerStaticAllowed && !plannerStaticAllowed.includes(requestedPlannerEffort)
|
|
833
|
+
? correctEffortForModel(requestedPlannerEffort, modelSelection?.model)
|
|
834
|
+
: null
|
|
835
|
+
const staticRulePlannerEffort = plannerStaticCorrection ? plannerStaticCorrection.effort : requestedPlannerEffort
|
|
836
|
+
const plannerStaticTrace = plannerStaticCorrection
|
|
837
|
+
? `→${classifyModelFamily(modelSelection?.model) === 'qwen' ? 'qwen-rule' : 'non-qwen-rule'}:${plannerStaticCorrection.requested}→${plannerStaticCorrection.effort}`
|
|
838
|
+
: ''
|
|
839
|
+
if (plannerStaticCorrection) {
|
|
840
|
+
console.warn('[dsh-workplan] planner reasoning effort corrected by LLM family rules:', JSON.stringify({
|
|
841
|
+
provider: modelSelection?.provider,
|
|
842
|
+
model: modelSelection?.model,
|
|
843
|
+
family: classifyModelFamily(modelSelection?.model),
|
|
844
|
+
requested: requestedPlannerEffort,
|
|
845
|
+
corrected: plannerStaticCorrection.effort,
|
|
846
|
+
allowed: plannerStaticAllowed,
|
|
847
|
+
reason: plannerStaticCorrection.reason,
|
|
848
|
+
}))
|
|
849
|
+
}
|
|
808
850
|
/*
|
|
809
851
|
* [2.2.7] 发送前按模型能力钳制档位:宿主对不支持的档位会在网络调用前直接
|
|
810
852
|
* 抛 UNSUPPORTED_REASONING_EFFORT,重试不自愈(终态),整次规划因此降级。
|
|
811
|
-
*
|
|
853
|
+
* 查询不可用时保持旧行为;查询成功后请求档钳制到清单内等效档,空清单
|
|
812
854
|
* (模型无 reasoning 元数据)则不发送档位字段。'' 在这里表示「不发送」。
|
|
813
855
|
*/
|
|
814
856
|
const plannerEffortSupport = await resolveSupportedEfforts(
|
|
@@ -818,13 +860,13 @@ export async function runPlanner(ctx: any, options: any) {
|
|
|
818
860
|
signal,
|
|
819
861
|
)
|
|
820
862
|
const effectivePlannerEffort = plannerEffortSupport === null
|
|
821
|
-
?
|
|
822
|
-
: (clampEffortToSupported(
|
|
823
|
-
if (plannerEffortSupport !== null && effectivePlannerEffort !==
|
|
863
|
+
? staticRulePlannerEffort
|
|
864
|
+
: (clampEffortToSupported(staticRulePlannerEffort, plannerEffortSupport) ?? '')
|
|
865
|
+
if (plannerEffortSupport !== null && effectivePlannerEffort !== staticRulePlannerEffort) {
|
|
824
866
|
console.warn('[dsh-workplan] planner reasoning effort clamped for model compatibility:', JSON.stringify({
|
|
825
867
|
provider: modelSelection?.provider,
|
|
826
868
|
model: modelSelection?.model,
|
|
827
|
-
requested:
|
|
869
|
+
requested: staticRulePlannerEffort,
|
|
828
870
|
effective: effectivePlannerEffort || '(omitted)',
|
|
829
871
|
supported: plannerEffortSupport,
|
|
830
872
|
}))
|
|
@@ -943,7 +985,9 @@ export async function runPlanner(ctx: any, options: any) {
|
|
|
943
985
|
const text = await collectStream(stream, onChunk, sink)
|
|
944
986
|
lastText = text
|
|
945
987
|
const raw = extractJson(text)
|
|
946
|
-
|
|
988
|
+
// [2.3.9][T3] 事前约束:规划器显式写出集合外档位 → validatePlan 拒绝并点名,
|
|
989
|
+
// 经重试回路回喂自纠(用户要求 1/2;模型名缺失⇒null⇒不施加)。
|
|
990
|
+
const validated = validatePlan(raw, { allowedEfforts: allowedEffortsForModel(modelSelection.model) })
|
|
947
991
|
if (validated.ok) {
|
|
948
992
|
/*
|
|
949
993
|
* [1.12.0] Structure alone is not understanding. Run the three-stage
|
|
@@ -1109,9 +1153,10 @@ export async function runPlanner(ctx: any, options: any) {
|
|
|
1109
1153
|
// 复盘把「主 Agent=high」误读成「规划器=high」。
|
|
1110
1154
|
// [2.2.7] 钳制发生时同样记录实际发出值('' = 未发送)。
|
|
1111
1155
|
reasoningEffort: effectivePlannerEffort,
|
|
1112
|
-
reasoningEffortSource:
|
|
1113
|
-
+
|
|
1114
|
-
|
|
1156
|
+
reasoningEffortSource: plannerEffortOriginLabel
|
|
1157
|
+
+ plannerStaticTrace
|
|
1158
|
+
+ (plannerEffortSupport !== null && effectivePlannerEffort !== staticRulePlannerEffort
|
|
1159
|
+
? `→clamped(${staticRulePlannerEffort})` : ''),
|
|
1115
1160
|
attempt,
|
|
1116
1161
|
taskChars: typeof taskText === 'string' ? taskText.length : 0,
|
|
1117
1162
|
promptChars,
|
|
@@ -2003,6 +2048,30 @@ async function executeSubtask(ctx: any, record: any, stage: any, subtask: any, o
|
|
|
2003
2048
|
&& REASONING_EFFORTS.includes(subtask.reasoningEffort)
|
|
2004
2049
|
? subtask.reasoningEffort
|
|
2005
2050
|
: DEFAULT_REASONING_EFFORT
|
|
2051
|
+
/*
|
|
2052
|
+
* [2.3.9][T3/llm-rules] 用户强制要求 1/2 的执行点:派发前对每个子任务的
|
|
2053
|
+
* reasoningEffort 做模型家族等级集合校验。越界档不中断派发(A3 修正轨),
|
|
2054
|
+
* 按强度序自动降级并 console.warn 留痕;随后 [2.2.7] 宿主能力钳制作为
|
|
2055
|
+
* 第二道闸继续生效(静态表权威 + 能力面交集)。模型名缺失⇒不施加静态
|
|
2056
|
+
* 约束,保持旧行为。
|
|
2057
|
+
*/
|
|
2058
|
+
const childStaticAllowed = allowedEffortsForModel(modelSelection?.model)
|
|
2059
|
+
const childStaticCorrection = childStaticAllowed && !childStaticAllowed.includes(requestedChildEffort)
|
|
2060
|
+
? correctEffortForModel(requestedChildEffort, modelSelection?.model)
|
|
2061
|
+
: null
|
|
2062
|
+
const staticRuleChildEffort = childStaticCorrection ? childStaticCorrection.effort : requestedChildEffort
|
|
2063
|
+
if (childStaticCorrection) {
|
|
2064
|
+
console.warn('[dsh-workplan] child reasoning effort corrected by LLM family rules:', JSON.stringify({
|
|
2065
|
+
subtaskId: subtask.id,
|
|
2066
|
+
provider: modelSelection?.provider,
|
|
2067
|
+
model: modelSelection?.model,
|
|
2068
|
+
family: classifyModelFamily(modelSelection?.model),
|
|
2069
|
+
requested: requestedChildEffort,
|
|
2070
|
+
corrected: childStaticCorrection.effort,
|
|
2071
|
+
allowed: childStaticAllowed,
|
|
2072
|
+
reason: childStaticCorrection.reason,
|
|
2073
|
+
}))
|
|
2074
|
+
}
|
|
2006
2075
|
/*
|
|
2007
2076
|
* [2.2.7] 能力不可查询时保持同步路径:派发链上任何多余的 await 微任务都会
|
|
2008
2077
|
* 把 awaiting 通道写入推晚一个 tick(notice-channel 运行时集成用例即因此
|
|
@@ -2016,8 +2085,8 @@ async function executeSubtask(ctx: any, record: any, stage: any, subtask: any, o
|
|
|
2016
2085
|
? await resolveSupportedEfforts(ctx.llm, modelSelection.provider, modelSelection.model, parentSignal)
|
|
2017
2086
|
: null
|
|
2018
2087
|
const childEffort = childEffortSupport === null
|
|
2019
|
-
?
|
|
2020
|
-
: (clampEffortToSupported(
|
|
2088
|
+
? staticRuleChildEffort
|
|
2089
|
+
: (clampEffortToSupported(staticRuleChildEffort, childEffortSupport) ?? '')
|
|
2021
2090
|
activation = await ctx.subagents.startActivation({
|
|
2022
2091
|
provider: 'spawn',
|
|
2023
2092
|
label: `${subtask.department}:${subtask.id} ${subtask.title}`.slice(0, 120),
|
|
@@ -2063,6 +2132,21 @@ async function executeSubtask(ctx: any, record: any, stage: any, subtask: any, o
|
|
|
2063
2132
|
*/
|
|
2064
2133
|
previousFailure: lastFailure ?? null,
|
|
2065
2134
|
lessonsBrief,
|
|
2135
|
+
/*
|
|
2136
|
+
* [2.3.9][T4b] 用户强制要求 3:分配任务时必须把要求 1/2 的
|
|
2137
|
+
* **全部内容**告知相关部门。注入文本由 llm-rules.ts 的
|
|
2138
|
+
* buildLlmRulesBrief 单一事实源生成(tier='department'):
|
|
2139
|
+
* 要求 1/2 原文 + 本会话模型与家族判定 + 本子任务已配置/钳制后
|
|
2140
|
+
* 的推理等级 + 部门负责人「先全面梳理、再用 dsh_workplan_delegate
|
|
2141
|
+
* 分配给顶尖专家与组员」的强制流程告知。
|
|
2142
|
+
*/
|
|
2143
|
+
llmRulesBrief: buildLlmRulesBrief({
|
|
2144
|
+
model: modelSelection?.model ?? null,
|
|
2145
|
+
effort: staticRuleChildEffort || null,
|
|
2146
|
+
requested: childStaticCorrection ? requestedChildEffort : null,
|
|
2147
|
+
correctionReason: childStaticCorrection?.reason ?? null,
|
|
2148
|
+
tier: 'department',
|
|
2149
|
+
}),
|
|
2066
2150
|
}),
|
|
2067
2151
|
}],
|
|
2068
2152
|
parent: options.agent,
|
|
@@ -2086,7 +2170,16 @@ async function executeSubtask(ctx: any, record: any, stage: any, subtask: any, o
|
|
|
2086
2170
|
// [2.2.7] '' = 模型无 reasoning 元数据 ⇒ 不发送,避免派发期即中断。
|
|
2087
2171
|
...(childEffort ? { reasoningEffort: childEffort } : {}),
|
|
2088
2172
|
},
|
|
2089
|
-
|
|
2173
|
+
/*
|
|
2174
|
+
* [2.3.9][T4b] 三层派发深度(用户强制要求 4/5):主 Agent(0) →
|
|
2175
|
+
* 部门负责人子会话(1) → 顶尖专家/组员子会话(2)。maxDepth 是宿主
|
|
2176
|
+
* resolveChildDepth 的**绝对深度上限**(child-agent.d.ts:24-29),
|
|
2177
|
+
* 部门层放行到 2 才能让负责人经 dsh_workplan_delegate 派生第三层;
|
|
2178
|
+
* 第三层成员派生时同样传 2 ⇒ 任何第四层(深度 3)被宿主抛
|
|
2179
|
+
* SubagentDepthError 硬拒,delegateTool 服务端另有一道「只有部门
|
|
2180
|
+
* 负责人行可调用」的校验——提示词说服模型,代码守住边界。
|
|
2181
|
+
*/
|
|
2182
|
+
maxDepth: 2,
|
|
2090
2183
|
},
|
|
2091
2184
|
signal: child.controller.signal,
|
|
2092
2185
|
delivery: 'caller',
|
|
@@ -6884,6 +6977,290 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
6884
6977
|
}
|
|
6885
6978
|
}
|
|
6886
6979
|
|
|
6980
|
+
/**
|
|
6981
|
+
* [2.3.9][T4b] 第三层派发(用户强制要求 4/5):部门负责人专用工具。
|
|
6982
|
+
*
|
|
6983
|
+
* 层级模型:主 Agent(根会话, depth 0) → 部门负责人子会话(depth 1) →
|
|
6984
|
+
* 顶尖专家/组员子会话(depth 2, 叶子层)。三道硬边界:
|
|
6985
|
+
* 1. 调用者必须是计划内某行的部门负责人子会话(childId 反查行);
|
|
6986
|
+
* 根会话被拒(用 dsh_workplan_dispatch),第三层成员也被拒——
|
|
6987
|
+
* 其父会话是部门会话、没有计划记录,NO_PLAN/NO_SUBTASK 即叶子层禁令;
|
|
6988
|
+
* 2. 梳理门禁:dispatch 前必须先 review 提交「全面梳理产物 + 分工表」
|
|
6989
|
+
* (planDelegations 唯一判据,durable 回放后依然生效);
|
|
6990
|
+
* 3. 深度:成员 spawn 传 maxDepth:2,第四层(depth 3)由宿主
|
|
6991
|
+
* SubagentDepthError 硬拒(resolveChildDepth 绝对上限)。
|
|
6992
|
+
*
|
|
6993
|
+
* 每位下级的推理等级按其任务复杂度由负责人配置,经 planDelegations 按
|
|
6994
|
+
* 当前模型家族合法集合(qwen→low/medium/xhigh;非qwen→low/high/max)
|
|
6995
|
+
* 钳制并留痕(delegates[].requested/effort 对),随 spawn 的 agentOptions
|
|
6996
|
+
* 下发且全生命周期生效(要求 5)。
|
|
6997
|
+
*/
|
|
6998
|
+
async function delegateTool(agent: any, args: any, signal?: any) {
|
|
6999
|
+
const childSession = agent?.session
|
|
7000
|
+
if (!childSession?.id) {
|
|
7001
|
+
return { ok: false, code: 'NO_SESSION', error: '只能在会话内使用第三层派发' }
|
|
7002
|
+
}
|
|
7003
|
+
const parentId = childSession.header?.parentSession
|
|
7004
|
+
if (!parentId) {
|
|
7005
|
+
return {
|
|
7006
|
+
ok: false,
|
|
7007
|
+
code: 'NOT_LEADER_SESSION',
|
|
7008
|
+
error: '只有「部门负责人子会话」可以使用 dsh_workplan_delegate:根会话请用 dsh_workplan_dispatch 派发主计划;第三层专家/组员是叶子层,不得再派发(用户要求 4:只有一层下级)。',
|
|
7009
|
+
}
|
|
7010
|
+
}
|
|
7011
|
+
let record = state.records.get(parentId)
|
|
7012
|
+
if (!record?.plan) {
|
|
7013
|
+
const parent = (ctx as any).sessions?.get?.(parentId)
|
|
7014
|
+
if (parent) {
|
|
7015
|
+
try {
|
|
7016
|
+
record = reconstructFromSession(parent)
|
|
7017
|
+
} catch (error) {
|
|
7018
|
+
pushRecordError({ errors: [] } as any, error)
|
|
7019
|
+
}
|
|
7020
|
+
}
|
|
7021
|
+
}
|
|
7022
|
+
if (!record?.plan) {
|
|
7023
|
+
return {
|
|
7024
|
+
ok: false,
|
|
7025
|
+
code: 'NO_PLAN',
|
|
7026
|
+
error: '父会话没有可关联的计划。若你是第三层专家/组员(叶子层):不得再派发,完成自身任务后把结论回报部门负责人即可。',
|
|
7027
|
+
}
|
|
7028
|
+
}
|
|
7029
|
+
const row = (record.statuses ?? []).find((item: any) => item?.childId === childSession.id)
|
|
7030
|
+
if (!row) {
|
|
7031
|
+
return {
|
|
7032
|
+
ok: false,
|
|
7033
|
+
code: 'NO_SUBTASK',
|
|
7034
|
+
error: '计划里找不到与本子会话关联的子任务行(childId 未登记);第三层派发只能由计划内的部门负责人子会话发起。',
|
|
7035
|
+
}
|
|
7036
|
+
}
|
|
7037
|
+
if (row.status === 'done') {
|
|
7038
|
+
return { ok: false, code: 'ALREADY_DONE', subtaskId: row.subtaskId, error: '该子任务已完成,不能再派发第三层。' }
|
|
7039
|
+
}
|
|
7040
|
+
const action = ['review', 'dispatch', 'status'].includes(args?.action) ? String(args.action) : ''
|
|
7041
|
+
if (!action) {
|
|
7042
|
+
return { ok: false, code: 'INVALID_ACTION', error: 'action 必须是 review(提交全面梳理产物)/ dispatch(派发给顶尖专家与组员)/ status(查看梳理与下级进度)' }
|
|
7043
|
+
}
|
|
7044
|
+
const subtaskId = String(row.subtaskId)
|
|
7045
|
+
const modelSelection = resolveModelSelection(ctx, { agent })
|
|
7046
|
+
const model = typeof modelSelection?.model === 'string' && modelSelection.model.trim() ? modelSelection.model.trim() : null
|
|
7047
|
+
const parentSession = (ctx as any).sessions?.get?.(parentId)
|
|
7048
|
+
const persist = (patch: any) => {
|
|
7049
|
+
const revision = Number(row.revision ?? 0) + 1
|
|
7050
|
+
record.statuses = applyStatus(record.statuses, subtaskId, { ...patch, revision, updatedBy: 'child' })
|
|
7051
|
+
record.updatedAt = Date.now()
|
|
7052
|
+
try {
|
|
7053
|
+
const written = record.statuses.find((item: any) => item?.subtaskId === subtaskId)
|
|
7054
|
+
appendUserMessage(parentSession, buildUpdateMessage({
|
|
7055
|
+
planId: record.plan.planId,
|
|
7056
|
+
subtaskId,
|
|
7057
|
+
status: written?.status ?? row.status,
|
|
7058
|
+
...(patch.consolidation === undefined ? {} : { consolidation: written?.consolidation }),
|
|
7059
|
+
...(patch.delegates === undefined ? {} : { delegates: written?.delegates }),
|
|
7060
|
+
revision: written?.revision ?? revision,
|
|
7061
|
+
}))
|
|
7062
|
+
} catch (error) {
|
|
7063
|
+
pushRecordError(record, error)
|
|
7064
|
+
}
|
|
7065
|
+
return record.statuses.find((item: any) => item?.subtaskId === subtaskId)
|
|
7066
|
+
}
|
|
7067
|
+
|
|
7068
|
+
if (action === 'status') {
|
|
7069
|
+
const delegates = Array.isArray(row.delegates) ? row.delegates : []
|
|
7070
|
+
return {
|
|
7071
|
+
ok: true,
|
|
7072
|
+
planId: record.plan.planId,
|
|
7073
|
+
subtaskId,
|
|
7074
|
+
action,
|
|
7075
|
+
consolidation: row.consolidation ?? null,
|
|
7076
|
+
delegates,
|
|
7077
|
+
hint: !row.consolidation
|
|
7078
|
+
? '尚未提交梳理产物:先调用 action="review"(用户要求 4 的硬门禁)。'
|
|
7079
|
+
: delegates.length === 0
|
|
7080
|
+
? '梳理产物已登记,可调用 action="dispatch" 正式派发给顶尖专家与组员。'
|
|
7081
|
+
: '第三层已派发;各下级结论会送回本会话,收齐后汇总核验,再写最终结果块。',
|
|
7082
|
+
}
|
|
7083
|
+
}
|
|
7084
|
+
|
|
7085
|
+
if (action === 'review') {
|
|
7086
|
+
const input = isRecord(args?.consolidation) ? args.consolidation : null
|
|
7087
|
+
if (!input) {
|
|
7088
|
+
return {
|
|
7089
|
+
ok: false,
|
|
7090
|
+
code: 'MISSING_CONSOLIDATION',
|
|
7091
|
+
subtaskId,
|
|
7092
|
+
error: 'review 必须携带 consolidation:{ problemAnalysis[], constraints[]?, unknowns[]?, approach[]?, assignments[{member, role:"expert"|"member", task, reasoningEffort}] }——用户要求 4 的「全面、全盘、深入梳理」产物 + 分工表(至少 1 名顶尖专家 + 1 名组员)。',
|
|
7093
|
+
}
|
|
7094
|
+
}
|
|
7095
|
+
const preview = planDelegations({ consolidation: input, model })
|
|
7096
|
+
if (!preview.ok) {
|
|
7097
|
+
return {
|
|
7098
|
+
ok: false,
|
|
7099
|
+
code: preview.code ?? 'DELEGATE_CONSOLIDATION_INVALID',
|
|
7100
|
+
subtaskId,
|
|
7101
|
+
error: preview.error,
|
|
7102
|
+
hint: '修正梳理产物后重新 action="review";未登记前 action="dispatch" 会持续被硬门禁拒绝。',
|
|
7103
|
+
}
|
|
7104
|
+
}
|
|
7105
|
+
const written = persist({
|
|
7106
|
+
consolidation: {
|
|
7107
|
+
problemAnalysis: input.problemAnalysis,
|
|
7108
|
+
constraints: input.constraints,
|
|
7109
|
+
unknowns: input.unknowns,
|
|
7110
|
+
approach: input.approach,
|
|
7111
|
+
assignments: input.assignments,
|
|
7112
|
+
submittedAt: Date.now(),
|
|
7113
|
+
},
|
|
7114
|
+
})
|
|
7115
|
+
return {
|
|
7116
|
+
ok: true,
|
|
7117
|
+
planId: record.plan.planId,
|
|
7118
|
+
subtaskId,
|
|
7119
|
+
action,
|
|
7120
|
+
consolidation: written?.consolidation ?? null,
|
|
7121
|
+
members: preview.members,
|
|
7122
|
+
clamped: preview.clamped,
|
|
7123
|
+
model: model ?? '(未知,未施加静态等级约束)',
|
|
7124
|
+
hint: '梳理产物已登记(durable,刷新后门禁依然生效)。现在可调用 action="dispatch" 正式派发;每位下级的推理等级已按当前模型家族合法集合钳制(clamped 列出越界修正与原因,留痕可审计)。',
|
|
7125
|
+
}
|
|
7126
|
+
}
|
|
7127
|
+
|
|
7128
|
+
// action === 'dispatch'
|
|
7129
|
+
const consolidation = isRecord(row.consolidation) ? row.consolidation : null
|
|
7130
|
+
const delegationPlan = planDelegations({ consolidation, model })
|
|
7131
|
+
if (!delegationPlan.ok) {
|
|
7132
|
+
return {
|
|
7133
|
+
ok: false,
|
|
7134
|
+
code: delegationPlan.code ?? 'DELEGATE_CONSOLIDATION_MISSING',
|
|
7135
|
+
subtaskId,
|
|
7136
|
+
error: delegationPlan.error,
|
|
7137
|
+
}
|
|
7138
|
+
}
|
|
7139
|
+
if (Array.isArray(row.delegates) && row.delegates.some((item: any) => item?.status === 'running')) {
|
|
7140
|
+
return {
|
|
7141
|
+
ok: false,
|
|
7142
|
+
code: 'DELEGATE_ALREADY_RUNNING',
|
|
7143
|
+
subtaskId,
|
|
7144
|
+
error: '第三层已在派发中(仍有下级 running):不要重复派发。用 action="status" 查看进度;如需补派新成员,先等当前下级结算。',
|
|
7145
|
+
delegates: row.delegates,
|
|
7146
|
+
}
|
|
7147
|
+
}
|
|
7148
|
+
const departmentLabel = DEPARTMENTS[row.department as keyof typeof DEPARTMENTS]?.zh ?? String(row.department ?? '部门')
|
|
7149
|
+
// cwd 与 dispatchTool 同源(session.header.cwd,7465 行同款):优先负责人
|
|
7150
|
+
// 子会话自己的工作目录,缺失回退根会话;都没有则交给宿主按 parent 推导。
|
|
7151
|
+
const cwd = typeof childSession.header?.cwd === 'string' && childSession.header.cwd
|
|
7152
|
+
? childSession.header.cwd
|
|
7153
|
+
: (typeof parentSession?.header?.cwd === 'string' && parentSession.header.cwd
|
|
7154
|
+
? parentSession.header.cwd
|
|
7155
|
+
: undefined)
|
|
7156
|
+
const delegates: any[] = []
|
|
7157
|
+
for (const assignment of delegationPlan.members) {
|
|
7158
|
+
const rulesBrief = buildLlmRulesBrief({
|
|
7159
|
+
model,
|
|
7160
|
+
effort: assignment.effort,
|
|
7161
|
+
requested: assignment.requested ?? null,
|
|
7162
|
+
correctionReason: assignment.correctionReason ?? null,
|
|
7163
|
+
tier: 'delegate',
|
|
7164
|
+
memberName: assignment.member,
|
|
7165
|
+
memberRole: assignment.role,
|
|
7166
|
+
})
|
|
7167
|
+
const promptText = buildDelegateePrompt({
|
|
7168
|
+
departmentLabel,
|
|
7169
|
+
leaderSubtaskId: subtaskId,
|
|
7170
|
+
leaderSubtaskTitle: String(row.title ?? ''),
|
|
7171
|
+
member: assignment,
|
|
7172
|
+
rulesBrief,
|
|
7173
|
+
cwd: cwd ?? '',
|
|
7174
|
+
leadSessionId: childSession.id,
|
|
7175
|
+
})
|
|
7176
|
+
let childId: string | null = null
|
|
7177
|
+
let memberStatus = 'running'
|
|
7178
|
+
let memberError: string | null = null
|
|
7179
|
+
try {
|
|
7180
|
+
const activation = await ctx.subagents.startActivation({
|
|
7181
|
+
provider: 'spawn',
|
|
7182
|
+
label: `${row.department}:${subtaskId}→${assignment.member}`.slice(0, 120),
|
|
7183
|
+
request: {
|
|
7184
|
+
prompt: [{ type: 'text', text: promptText }],
|
|
7185
|
+
parent: agent,
|
|
7186
|
+
cwd,
|
|
7187
|
+
agentOptions: {
|
|
7188
|
+
...(modelSelection?.provider && modelSelection?.model
|
|
7189
|
+
? { provider: modelSelection.provider, model: modelSelection.model }
|
|
7190
|
+
: {}),
|
|
7191
|
+
// 要求 5:等级随任务复杂度配置并全程应用;'' = 模型无 reasoning 元数据 ⇒ 不发送。
|
|
7192
|
+
...(assignment.effort ? { reasoningEffort: assignment.effort } : {}),
|
|
7193
|
+
},
|
|
7194
|
+
// 成员在 depth 2;任何第四层(depth 3)被宿主绝对深度上限硬拒。
|
|
7195
|
+
maxDepth: 2,
|
|
7196
|
+
},
|
|
7197
|
+
signal,
|
|
7198
|
+
delivery: 'caller',
|
|
7199
|
+
})
|
|
7200
|
+
childId = typeof activation?.childId === 'string' ? activation.childId : null
|
|
7201
|
+
if (activation && typeof activation.result?.then === 'function') {
|
|
7202
|
+
const settledChildId = childId
|
|
7203
|
+
activation.result.then((outcome: any) => {
|
|
7204
|
+
try {
|
|
7205
|
+
const completed = outcome?.stopReason === 'completed'
|
|
7206
|
+
const current = (record.statuses ?? []).find((item: any) => item?.subtaskId === subtaskId)
|
|
7207
|
+
const list = (Array.isArray(current?.delegates) ? current.delegates : [])
|
|
7208
|
+
.map((item: any) => (item?.childId === settledChildId
|
|
7209
|
+
? {
|
|
7210
|
+
...item,
|
|
7211
|
+
status: completed ? 'done' : 'failed',
|
|
7212
|
+
summary: truncate(resultText(outcome), 300),
|
|
7213
|
+
error: completed ? null : truncate(String(outcome?.diagnostic ?? `子会话结束状态 ${outcome?.stopReason}`), 300),
|
|
7214
|
+
finishedAt: Date.now(),
|
|
7215
|
+
}
|
|
7216
|
+
: item))
|
|
7217
|
+
const revision = Number(current?.revision ?? 0) + 1
|
|
7218
|
+
record.statuses = applyStatus(record.statuses, subtaskId, { delegates: list, revision, updatedBy: 'child' })
|
|
7219
|
+
record.updatedAt = Date.now()
|
|
7220
|
+
appendUserMessage(parentSession, buildUpdateMessage({
|
|
7221
|
+
planId: record.plan.planId,
|
|
7222
|
+
subtaskId,
|
|
7223
|
+
status: current?.status ?? row.status,
|
|
7224
|
+
delegates: list,
|
|
7225
|
+
revision,
|
|
7226
|
+
}))
|
|
7227
|
+
} catch {
|
|
7228
|
+
// 结算留痕失败不影响主链路:看板下次刷新按内存行渲染。
|
|
7229
|
+
}
|
|
7230
|
+
}).catch(() => {})
|
|
7231
|
+
}
|
|
7232
|
+
} catch (error: any) {
|
|
7233
|
+
memberStatus = 'rejected'
|
|
7234
|
+
memberError = truncate(String(error?.message ?? error), 300)
|
|
7235
|
+
}
|
|
7236
|
+
delegates.push({
|
|
7237
|
+
member: assignment.member,
|
|
7238
|
+
role: assignment.role,
|
|
7239
|
+
task: assignment.task,
|
|
7240
|
+
effort: assignment.effort,
|
|
7241
|
+
...(assignment.requested && assignment.requested !== assignment.effort ? { requested: assignment.requested } : {}),
|
|
7242
|
+
childId,
|
|
7243
|
+
status: memberStatus,
|
|
7244
|
+
summary: '',
|
|
7245
|
+
error: memberError,
|
|
7246
|
+
startedAt: Date.now(),
|
|
7247
|
+
finishedAt: null,
|
|
7248
|
+
})
|
|
7249
|
+
}
|
|
7250
|
+
const written = persist({ delegates })
|
|
7251
|
+
const rejected = delegates.filter((item) => item.status === 'rejected')
|
|
7252
|
+
return {
|
|
7253
|
+
ok: rejected.length < delegates.length,
|
|
7254
|
+
planId: record.plan.planId,
|
|
7255
|
+
subtaskId,
|
|
7256
|
+
action,
|
|
7257
|
+
delegates: written?.delegates ?? delegates,
|
|
7258
|
+
clamped: delegationPlan.clamped,
|
|
7259
|
+
...(rejected.length ? { rejected: rejected.map((item) => ({ member: item.member, error: item.error })) } : {}),
|
|
7260
|
+
hint: '第三层已派发(一层下级、叶子层,第四层会被硬拒)。每位专家/组员的完成结论会送回本会话(delivery=caller);收齐后由你汇总核验,再写最终结果块。用 action="status" 查看进度。',
|
|
7261
|
+
}
|
|
7262
|
+
}
|
|
7263
|
+
|
|
6887
7264
|
async function dispatchTool(agent: any, args: any, signal: any) {
|
|
6888
7265
|
const session = agent?.session
|
|
6889
7266
|
if (!session) throw new PlanError('只能在会话内派发计划', 'NO_SESSION')
|
|
@@ -8163,6 +8540,8 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
8163
8540
|
statusTool,
|
|
8164
8541
|
followupTool,
|
|
8165
8542
|
escalateTool,
|
|
8543
|
+
// [2.3.9][T4b] 第三层派发(部门负责人专用):review 梳理门禁 → dispatch 专家/组员。
|
|
8544
|
+
delegateTool,
|
|
8166
8545
|
verifyTool: verifySubtask,
|
|
8167
8546
|
lessonsTool,
|
|
8168
8547
|
instructTool,
|