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.
@@ -0,0 +1,221 @@
1
+ /**
2
+ * [2.3.9][T3] LLM 家族检测与推理等级约束——执行工具层。
3
+ *
4
+ * 单一事实源在 src/plan.ts(REASONING_EFFORTS 五档存储全集旁:classifyModelFamily /
5
+ * allowedEffortsForModel / COMPLEXITY_EFFORT_BY_FAMILY,含用户要求 1/2 原文与
6
+ * 「不得删档/模型未知不约束」的完整语义注释)。本模块只做两件事:
7
+ * 1) 转发真源符号(保持 runtime/replan/tests 的引用面稳定,兼容别名
8
+ * detectLlmType ≡ classifyModelFamily);
9
+ * 2) 提供「事前约束」需要的两个执行函数:validateReasoningEffort(集合校验,
10
+ * 给明确错误信息=A3 报错轨)与 correctEffortForModel(越界自动降级修正
11
+ * =A3 修正轨,绝不抛错中断派发)。
12
+ *
13
+ * 与 [2.2.7] 宿主能力钳制(clampEffortToSupported/resolveSupportedEfforts)的
14
+ * 时序关系:检测(入口) → 静态集合收窄(本模块) → 宿主能力交集钳制 → 发送;
15
+ * 两道闸各自留痕(U7 裁决:静态表权威 + 能力面交集钳制留痕)。
16
+ */
17
+ import { allowedEffortsForModel, classifyModelFamily, defuseSessionReferenceText, effortForComplexity, EVIDENCE_MARKER_BEGIN, EVIDENCE_MARKER_END, effortsForModelFamily, highestEffortOf, OTHER_MODEL_EFFORTS, QWEN_MODEL_EFFORTS, REASONING_EFFORTS, truncate, } from './plan.js';
18
+ import { threePhasePromptLines } from './three-phase.js';
19
+ export { allowedEffortsForModel, classifyModelFamily, effortForComplexity, effortsForModelFamily, highestEffortOf, OTHER_MODEL_EFFORTS, QWEN_MODEL_EFFORTS, };
20
+ /** 兼容别名:T3 计划文本中的 detectLlmType ≡ 真源 classifyModelFamily。 */
21
+ export const detectLlmType = classifyModelFamily;
22
+ /** 兼容别名:T3 计划文本中的 getAllowedEffortLevels(llmType) ≡ 真源 effortsForModelFamily。 */
23
+ export const getAllowedEffortLevels = effortsForModelFamily;
24
+ /**
25
+ * 集合校验(用户要求 1/2 的硬白名单判定)。
26
+ * @param effort 待校验档位
27
+ * @param allowed 等级集合(null=模型未知,不施加约束,任何值都 ok)
28
+ */
29
+ export function validateReasoningEffort(effort, allowed) {
30
+ if (allowed === null)
31
+ return { ok: true };
32
+ if (typeof effort !== 'string' || !allowed.includes(effort)) {
33
+ return {
34
+ ok: false,
35
+ error: `reasoningEffort "${String(effort)}" 不在当前模型家族的推理等级集合 {${allowed.join(', ')}} 内(qwen 系仅 low/medium/xhigh;非 qwen 系仅 low/high/max)——请改用集合内档位`,
36
+ };
37
+ }
38
+ return { ok: true };
39
+ }
40
+ /** 静态强度序(与 runtime.ts EFFORT_STRENGTH_ORDER 同源语义)。 */
41
+ const STATIC_STRENGTH_ORDER = Object.freeze(['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max']);
42
+ /**
43
+ * 越界自动降级修正(A3 修正轨):请求档不在家族集合内时,钳到集合内「不高于
44
+ * 请求档」的最近档(按强度序逐级下探:qwen 下 max→xhigh、high→medium;非 qwen
45
+ * 下 xhigh→high、medium→low),全部更弱则取最弱档;集合未知(模型名缺失)
46
+ * ⇒ 原样透传。派发绝不因档位问题中断。
47
+ */
48
+ export function correctEffortForModel(effort, modelId) {
49
+ const allowed = allowedEffortsForModel(modelId);
50
+ if (allowed === null)
51
+ return { effort, adjusted: false, requested: effort };
52
+ if (allowed.includes(effort))
53
+ return { effort, adjusted: false, requested: effort };
54
+ const rank = (id) => STATIC_STRENGTH_ORDER.indexOf(id);
55
+ const ranked = [...allowed].sort((a, b) => rank(a) - rank(b));
56
+ const target = rank(effort);
57
+ const corrected = target < 0
58
+ ? ranked[0]
59
+ : (() => {
60
+ const atOrBelow = ranked.filter((id) => rank(id) >= 0 && rank(id) <= target);
61
+ return atOrBelow.length > 0 ? atOrBelow[atOrBelow.length - 1] : ranked[0];
62
+ })();
63
+ const family = classifyModelFamily(modelId);
64
+ return {
65
+ effort: corrected,
66
+ adjusted: true,
67
+ requested: effort,
68
+ reason: `${family === 'qwen' ? 'qwen-rule' : 'non-qwen-rule'}:${effort}→${corrected}(模型家族等级集合为 {${allowed.join(', ')}},越界档按强度序自动降级)`,
69
+ };
70
+ }
71
+ /**
72
+ * 要求 1/2 的规则全文(供 T4/T4b 部门告知注入引用同一事实源,避免文案漂移)。
73
+ */
74
+ export const LLM_REASONING_RULES_TEXT = [
75
+ '1. 分配任务前先判断用户此刻使用的大模型:字母 qwen 开头的模型,推理等级只包括 low、medium、xhigh——轻度任务使用 low,比较复杂的任务使用 medium,非常复杂的任务使用 xhigh。',
76
+ '2. 非 qwen 开头的其他大模型,推理等级只包括 low、high、max——轻度任务使用 low,比较复杂的任务使用 high,非常复杂的任务使用 max。',
77
+ ].join('\n');
78
+ export function buildLlmRulesBrief(info = {}) {
79
+ const family = info.family ?? classifyModelFamily(info.model ?? null);
80
+ const allowed = info.allowed ?? allowedEffortsForModel(info.model ?? null);
81
+ const lines = [
82
+ '[2.3.9][LLM 推理等级强制规则——用户要求 1/2 全文(部门、专家、组员全员告知,必须遵守)]',
83
+ LLM_REASONING_RULES_TEXT,
84
+ `- 本会话模型:${info.model || '(未知,不施加静态等级约束)'}`
85
+ + (info.model ? `(家族:${family === 'qwen' ? 'qwen 系' : '非 qwen 系'})` : '')
86
+ + (allowed ? `;可用推理等级集合:{${allowed.join(', ')}}` : ''),
87
+ ];
88
+ if (info.effort) {
89
+ const adjusted = Boolean(info.requested) && info.requested !== info.effort;
90
+ lines.push(`- 本任务的推理等级已按任务复杂度配置为 \`${info.effort}\`,必须全程应用(开工预告、执行、验证、复盘全生命周期生效)`
91
+ + (adjusted
92
+ ? `;请求档 \`${info.requested}\` 越出当前模型家族等级集合,已按规则自动钳制修正${info.correctionReason ? `(${info.correctionReason})` : ''}。`
93
+ : '。'));
94
+ }
95
+ if (info.tier === 'delegate') {
96
+ lines.push(`- 你是部门第三层执行者(${info.memberRole === 'expert' ? '本部门相关领域全球顶尖专家' : '本部门组员'}${info.memberName ? `:${info.memberName}` : ''})。你的等级由部门负责人按你分到任务的复杂度配置并经平台按上述等级集合强制约束;越界档会被钳制并留痕。必须确保自身任务完成品质非常高的前提下,完美、超高效率地执行。`);
97
+ }
98
+ else {
99
+ lines.push('- 部门负责人(本任务书的直接接收者)强制流程(用户要求 4/5):接到任务后必须先全面、全盘、深入梳理与研究,再用 dsh_workplan_delegate(action="review") 提交梳理产物(问题梳理 + 分工表 + 每位专家/组员的推理等级配置);梳理产物未提交前,dsh_workplan_delegate(action="dispatch") 会被平台拒绝(硬门禁)。梳理完成后再把任务合理分配给本部门相关领域全球顶尖专家与本部门组员;每位下级必须按自己分到任务的复杂度配置相应推理等级(轻度=low;qwen 中等=medium、非 qwen 中等=high;qwen 非常复杂=xhigh、非 qwen 非常复杂=max),全程应用;平台会按上述等级集合自动钳制越界档并留痕,等级在其任务全生命周期生效且不可被覆盖。第三层为叶子层:任何第四层派发一律被拒绝。');
100
+ }
101
+ return lines.join('\n');
102
+ }
103
+ const MAX_DELEGATE_MEMBERS = 6;
104
+ function readTrimmedStrings(value, limit) {
105
+ return (Array.isArray(value) ? value : [])
106
+ .map((item) => String(item ?? '').trim())
107
+ .filter(Boolean)
108
+ .slice(0, limit);
109
+ }
110
+ /**
111
+ * 梳理产物校验 + 分工表校验 + 等级钳制,三合一(一次调用给出全部拒因)。
112
+ * @param input.consolidation 部门负责人提交的梳理产物(review 阶段写入行,
113
+ * dispatch 阶段从行读回;两处都走这里,门禁与派发同一判据)
114
+ * @param input.model 当前会话模型 id(未知 ⇒ allowed=null ⇒ 不施加静态收窄,
115
+ * 但仍必须落在五档存储全集内——枚举校验永不放松)
116
+ */
117
+ export function planDelegations(input) {
118
+ const empty = { ok: false, code: 'DELEGATE_CONSOLIDATION_MISSING', members: [], clamped: [] };
119
+ const consolidation = input?.consolidation;
120
+ if (!consolidation || typeof consolidation !== 'object') {
121
+ return { ...empty, error: '尚未提交「全面梳理」产物:先用 dsh_workplan_delegate(action="review") 提交问题梳理与分工表,派发才会放行(用户要求 4 的硬门禁)。' };
122
+ }
123
+ const problemAnalysis = readTrimmedStrings(consolidation.problemAnalysis, 12);
124
+ if (problemAnalysis.length === 0) {
125
+ return { ...empty, code: 'DELEGATE_CONSOLIDATION_INCOMPLETE', error: '梳理产物不完整:problemAnalysis 至少 1 条(现状/事实/约束/未知/主要矛盾逐条写清),未梳理完不得进入再分配。' };
126
+ }
127
+ const assignments = (Array.isArray(consolidation.assignments) ? consolidation.assignments : []).slice(0, MAX_DELEGATE_MEMBERS);
128
+ if (assignments.length === 0) {
129
+ return { ...empty, code: 'DELEGATE_CONSOLIDATION_INCOMPLETE', error: '梳理产物不完整:分工表 assignments 至少 1 条(member/role/task/reasoningEffort 四项齐全)。' };
130
+ }
131
+ const allowed = allowedEffortsForModel(input.model ?? null);
132
+ const members = [];
133
+ const clamped = [];
134
+ let experts = 0;
135
+ let regular = 0;
136
+ for (let index = 0; index < assignments.length; index += 1) {
137
+ const item = assignments[index] ?? {};
138
+ const member = truncate(String(item.member ?? '').trim(), 80);
139
+ const role = item.role === 'expert' ? 'expert' : item.role === 'member' ? 'member' : '';
140
+ const task = truncate(String(item.task ?? '').trim(), 1500);
141
+ if (!member || !role || !task) {
142
+ return {
143
+ ok: false,
144
+ code: 'DELEGATE_ASSIGNMENT_INVALID',
145
+ members: [],
146
+ clamped: [],
147
+ error: `分工表第 ${index + 1} 条不完整:member(姓名/代号)、role(expert|member)、task(分到的任务)三者都必须非空。`,
148
+ };
149
+ }
150
+ const requested = REASONING_EFFORTS.includes(item.reasoningEffort)
151
+ ? String(item.reasoningEffort)
152
+ : (allowed === null ? 'low' : (highestEffortOf(allowed) ?? 'low'));
153
+ const outOfSet = allowed !== null && !allowed.includes(requested);
154
+ const correction = outOfSet ? correctEffortForModel(requested, input.model ?? null) : null;
155
+ const effort = correction ? correction.effort : requested;
156
+ if (correction) {
157
+ clamped.push({ member, requested, corrected: correction.effort, reason: correction.reason ?? '' });
158
+ }
159
+ if (role === 'expert')
160
+ experts += 1;
161
+ else
162
+ regular += 1;
163
+ members.push({
164
+ member,
165
+ role,
166
+ task,
167
+ effort,
168
+ ...(outOfSet ? { requested, correctionReason: correction?.reason } : {}),
169
+ });
170
+ }
171
+ if (experts === 0 || regular === 0) {
172
+ return {
173
+ ok: false,
174
+ code: 'DELEGATE_ROLE_MIX_REQUIRED',
175
+ members: [],
176
+ clamped: [],
177
+ error: '分工表必须同时覆盖「本部门相关领域全球顶尖专家」与「本部门组员」(各至少 1 名,用户要求 4):当前 expert=' + experts + '、member=' + regular + '。',
178
+ };
179
+ }
180
+ return {
181
+ ok: true,
182
+ members,
183
+ clamped,
184
+ consolidation: {
185
+ problemAnalysis,
186
+ constraints: readTrimmedStrings(consolidation.constraints, 12),
187
+ unknowns: readTrimmedStrings(consolidation.unknowns, 12),
188
+ approach: readTrimmedStrings(consolidation.approach, 12),
189
+ assignments: members.length,
190
+ },
191
+ };
192
+ }
193
+ /**
194
+ * [2.3.9][T4b] 第三层任务书:部门负责人 → 顶尖专家/组员子会话。
195
+ *
196
+ * 与二级任务书(buildChildPrompt)共享同一注入事实源 buildLlmRulesBrief
197
+ * (tier='delegate'),要求 1/2 全文与「等级全程应用、越界钳制留痕」的
198
+ * 口径不可能在两处漂移;叶子层禁令(不得再派生第四层)直接写进任务书,
199
+ * 服务端 delegateTool 另有一道硬拒——提示词说服模型,代码守住边界。
200
+ */
201
+ export function buildDelegateePrompt(input) {
202
+ const roleLabel = input.member.role === 'expert' ? '本部门相关领域全球顶尖专家' : '本部门组员';
203
+ return defuseSessionReferenceText([
204
+ `你是「${input.departmentLabel ?? '部门'}」的${roleLabel}(${input.member.member}),由部门负责人直接分配,只负责下面这一项分配到的工作。`,
205
+ `负责人任务:${input.leaderSubtaskId ?? ''} ${input.leaderSubtaskTitle ?? ''}`,
206
+ `你的任务:${input.member.task}`,
207
+ `工作目录:${input.cwd || '(未知)'}`,
208
+ ...(input.extraContext ? ['', input.extraContext] : []),
209
+ '',
210
+ input.rulesBrief,
211
+ '',
212
+ '执行要求(用户强制要求 5 原文口径):',
213
+ '- 你分到的推理等级已按任务复杂度配置并由平台按当前模型等级集合钳制生效:必须全程应用(规划、执行、验证、复盘全生命周期),不得自行换档。',
214
+ '- 必须在确保自身任务完成品质非常高的前提下,完美、超高效率地执行;严禁低效执行与浪费 token。',
215
+ '- 你是第三层叶子执行者:不得派生任何第四层 Agent/子会话;无法完成时在结论首行写 BLOCKED: 原因 并说明缺什么,不要空转。',
216
+ '- 完成后把结论与逐项证据(命令输出/文件/引用)用简洁中文回报给部门负责人会话;同时把同一份结构化结论写入 reports/wp-member-<你的成员名>-<任务代号>.json(相对工作目录,目录不存在就创建)作为结算兜底。',
217
+ `- 结果块契约:以 ${EVIDENCE_MARKER_BEGIN} 开头、${EVIDENCE_MARKER_END} 结尾,内含合法 JSON(status ∈ done/blocked/partial、phases 三阶段、acceptance 逐条带证据)。`,
218
+ '',
219
+ ...threePhasePromptLines(),
220
+ ].filter(Boolean).join('\n'));
221
+ }
package/lib/plan.js CHANGED
@@ -179,6 +179,49 @@ export const LIKELIHOODS = Object.freeze(['low', 'medium', 'high']);
179
179
  */
180
180
  export const REASONING_EFFORTS = Object.freeze(['low', 'medium', 'high', 'xhigh', 'max']);
181
181
  export const DEFAULT_REASONING_EFFORT = 'high';
182
+ export const QWEN_MODEL_EFFORTS = Object.freeze(['low', 'medium', 'xhigh']);
183
+ export const OTHER_MODEL_EFFORTS = Object.freeze(['low', 'high', 'max']);
184
+ /** 判定模型家族:qwen 开头(trim+小写)→ 'qwen';其余非空 → 'other';空/缺失 → null(不约束)。 */
185
+ export function classifyModelFamily(modelId) {
186
+ const normalized = String(modelId ?? '').trim().toLowerCase();
187
+ if (!normalized)
188
+ return null;
189
+ return normalized.startsWith('qwen') ? 'qwen' : 'other';
190
+ }
191
+ /** 家族 → 允许等级集合(用户要求 1/2 硬白名单);未知家族 → null = 不施加约束。 */
192
+ export function effortsForModelFamily(family) {
193
+ if (family === 'qwen')
194
+ return QWEN_MODEL_EFFORTS;
195
+ if (family === 'other')
196
+ return OTHER_MODEL_EFFORTS;
197
+ return null;
198
+ }
199
+ /** 一步式:按模型 id 得到等级集合;模型名缺失返回 null(不约束)。 */
200
+ export function allowedEffortsForModel(modelId) {
201
+ return effortsForModelFamily(classifyModelFamily(modelId));
202
+ }
203
+ export const COMPLEXITY_EFFORT_BY_FAMILY = Object.freeze({
204
+ qwen: Object.freeze({ light: 'low', moderate: 'medium', heavy: 'xhigh' }),
205
+ other: Object.freeze({ light: 'low', moderate: 'high', heavy: 'max' }),
206
+ });
207
+ /** 按家族+复杂度取应使用档位;家族未知返回 null。 */
208
+ export function effortForComplexity(family, complexity) {
209
+ if (!family)
210
+ return null;
211
+ return COMPLEXITY_EFFORT_BY_FAMILY[family][complexity];
212
+ }
213
+ /** 集合内最高档(强度序与 runtime EFFORT_STRENGTH_ORDER 同源);空集合返回 null。 */
214
+ export function highestEffortOf(levels) {
215
+ if (!levels || levels.length === 0)
216
+ return null;
217
+ const order = ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
218
+ let best = null;
219
+ for (const id of levels) {
220
+ if (best === null || order.indexOf(id) > order.indexOf(best))
221
+ best = id;
222
+ }
223
+ return best;
224
+ }
182
225
  export const DEPARTMENTS = Object.freeze({
183
226
  engineering: { zh: '工程研发', en: 'Engineering' },
184
227
  research: { zh: '研究分析', en: 'Research' },
@@ -952,10 +995,13 @@ function checkPlanGraph(plan, errors) {
952
995
  /**
953
996
  * Validate an untrusted planner object. Never throws for malformed input.
954
997
  *
955
- * @param {unknown} raw
956
- * @returns {{ok: true, plan: object} | {ok: false, errors: string[]}}
998
+ * [2.3.9][T3] options.allowedEfforts:当前模型家族的等级集合(真源
999
+ * allowedEffortsForModel)。传入时,规划器**显式写出**的集合外档位直接拒绝并
1000
+ * 点名(事前约束,要求 1/2;缺失/回落的 high 不在此列——派发侧静态收窄会带
1001
+ * qwen-rule 留痕降级,向后兼容旧回放零迁移)。null/未传 ⇒ 不施加(回放、旧
1002
+ * 调用零行为变化)。REASONING_EFFORTS 五档仍是存储全集,不得删档。
957
1003
  */
958
- export function validatePlan(raw) {
1004
+ export function validatePlan(raw, options) {
959
1005
  if (!isRecord(raw)) {
960
1006
  return { ok: false, errors: ['计划必须是 JSON 对象'] };
961
1007
  }
@@ -973,6 +1019,32 @@ export function validatePlan(raw) {
973
1019
  verification: readVerification(raw.verification, errors),
974
1020
  practiceLoop: readPracticeLoop(raw.practiceLoop, errors),
975
1021
  };
1022
+ const allowedEfforts = options && options.allowedEfforts ? options.allowedEfforts : null;
1023
+ if (allowedEfforts !== null && Array.isArray(raw.stages)) {
1024
+ /*
1025
+ * [2.3.9][T3/llm-rules] 模型感知的校验收窄(用户要求 1/2,主 Agent 口径):
1026
+ * 五档仍是存储全集(不得删档),但调用方传入当前模型家族等级集合时,
1027
+ * 规划器**显式写出**的集合外档位拒绝并点名字段——错误经重试回路回喂
1028
+ * 规划器自纠,属于事前约束而非派发后静默钳制。缺失档位不在此拦(由
1029
+ * readSubtasks 回落 high、派发侧静态收窄带 qwen-rule 留痕降级);未传
1030
+ * options 的调用(回放/旧路径)零行为变化。
1031
+ */
1032
+ for (let stageIndex = 0; stageIndex < raw.stages.length; stageIndex += 1) {
1033
+ const stage = raw.stages[stageIndex];
1034
+ if (!isRecord(stage) || !Array.isArray(stage.subtasks))
1035
+ continue;
1036
+ for (let subtaskIndex = 0; subtaskIndex < stage.subtasks.length; subtaskIndex += 1) {
1037
+ const subtask = stage.subtasks[subtaskIndex];
1038
+ if (!isRecord(subtask))
1039
+ continue;
1040
+ const effort = subtask.reasoningEffort;
1041
+ if (effort !== undefined && effort !== null
1042
+ && !(typeof effort === 'string' && allowedEfforts.includes(effort))) {
1043
+ push(errors, `stages[${stageIndex}].subtasks[${subtaskIndex}].reasoningEffort`, `"${String(effort)}" 不在当前模型家族的推理等级集合 {${allowedEfforts.join(' / ')}} 内(qwen 系仅 low / medium / xhigh;非 qwen 系仅 low / high / max),必须改用集合内档位或删除该字段`);
1044
+ }
1045
+ }
1046
+ }
1047
+ }
976
1048
  checkPlanGraph(plan, errors);
977
1049
  if (errors.length > 0)
978
1050
  return { ok: false, errors };
@@ -3253,6 +3325,14 @@ export function buildUpdateMessage(update) {
3253
3325
  * deriveSubtaskTimeoutMs。
3254
3326
  */
3255
3327
  ...(update.timeoutMs === undefined ? {} : { timeoutMs: update.timeoutMs }),
3328
+ /*
3329
+ * [2.3.9][T4b] 梳理门禁与第三层分工必须随 durable workplan-update 回放:
3330
+ * 刷新后门禁判据(consolidation)若只剩内存一份,重启的负责人可以不经
3331
+ * 梳理直接 dispatch,硬门禁就只是「本进程内的礼貌」。delegates 是看板
3332
+ * 第三层的数据源,同理。
3333
+ */
3334
+ ...(update.consolidation === undefined ? {} : { consolidation: update.consolidation }),
3335
+ ...(update.delegates === undefined ? {} : { delegates: update.delegates }),
3256
3336
  ...(update.revision === undefined ? {} : { revision: update.revision }),
3257
3337
  at: update.at ?? Date.now(),
3258
3338
  };
@@ -3766,6 +3846,63 @@ export function applyStatus(statuses, subtaskId, patch) {
3766
3846
  .filter((item) => isRecord(item) && typeof item.id === 'string')
3767
3847
  .map((item) => ({ id: item.id, reason: truncate(String(item.reason ?? ''), 300) }));
3768
3848
  }
3849
+ /*
3850
+ * [2.3.9][T4b] 第三层派发的留档字段(用户要求 4/5:负责人「先全面梳理、
3851
+ * 再分配」的硬门禁产物 + 顶尖专家/组员的分工与实时状态)。
3852
+ *
3853
+ * `consolidation` 是梳理门禁的唯一判据:没有它,delegateTool 的 dispatch
3854
+ * 动作必须被拒(A4)。`delegates` 是看板第三层的渲染数据源(A3),其
3855
+ * requested/corrected 对就是等级钳制的留痕(A5)。两者只写同一条状态行、
3856
+ * 走同一个 durable workplan-update 回放,刷新/重启后门禁与看板不失效。
3857
+ */
3858
+ if (patch.consolidation !== undefined) {
3859
+ if (patch.consolidation === null)
3860
+ next.consolidation = null;
3861
+ else if (isRecord(patch.consolidation)) {
3862
+ const briefStrings = (value, limit, itemMax) => (Array.isArray(value) ? value : [])
3863
+ .map((entry) => truncate(String(entry ?? '').trim(), itemMax))
3864
+ .filter(Boolean)
3865
+ .slice(0, limit);
3866
+ next.consolidation = {
3867
+ problemAnalysis: briefStrings(patch.consolidation.problemAnalysis, 12, 500),
3868
+ constraints: briefStrings(patch.consolidation.constraints, 12, 300),
3869
+ unknowns: briefStrings(patch.consolidation.unknowns, 12, 300),
3870
+ approach: briefStrings(patch.consolidation.approach, 12, 500),
3871
+ assignments: (Array.isArray(patch.consolidation.assignments) ? patch.consolidation.assignments : [])
3872
+ .slice(0, 6)
3873
+ .map((item) => ({
3874
+ member: truncate(String(item?.member ?? ''), 80),
3875
+ role: item?.role === 'expert' ? 'expert' : 'member',
3876
+ task: truncate(String(item?.task ?? ''), 800),
3877
+ reasoningEffort: REASONING_EFFORTS.includes(item?.reasoningEffort) ? item.reasoningEffort : 'low',
3878
+ ...(item?.requested && item.requested !== item.reasoningEffort
3879
+ ? { requested: String(item.requested) }
3880
+ : {}),
3881
+ })),
3882
+ submittedAt: numberOrNull(patch.consolidation.submittedAt) ?? Date.now(),
3883
+ };
3884
+ }
3885
+ else {
3886
+ throw new PlanError('consolidation 必须是对象或 null', 'INVALID_CONSOLIDATION');
3887
+ }
3888
+ }
3889
+ if (patch.delegates !== undefined) {
3890
+ next.delegates = (Array.isArray(patch.delegates) ? patch.delegates : [])
3891
+ .slice(0, 6)
3892
+ .map((item) => ({
3893
+ member: truncate(String(item?.member ?? ''), 80),
3894
+ role: item?.role === 'expert' ? 'expert' : 'member',
3895
+ task: truncate(String(item?.task ?? ''), 300),
3896
+ effort: REASONING_EFFORTS.includes(item?.effort) ? item.effort : 'low',
3897
+ ...(item?.requested && item.requested !== item.effort ? { requested: String(item.requested) } : {}),
3898
+ childId: typeof item?.childId === 'string' ? truncate(item.childId, 200) : null,
3899
+ status: ['running', 'done', 'failed', 'timeout', 'rejected'].includes(item?.status) ? item.status : 'running',
3900
+ summary: typeof item?.summary === 'string' ? truncate(item.summary, 300) : '',
3901
+ error: typeof item?.error === 'string' ? truncate(item.error, 300) : null,
3902
+ startedAt: numberOrNull(item?.startedAt),
3903
+ finishedAt: numberOrNull(item?.finishedAt),
3904
+ }));
3905
+ }
3769
3906
  /*
3770
3907
  * [1.7.0] Monotonic revision + author.
3771
3908
  *
@@ -3915,6 +4052,15 @@ export function applyStatus(statuses, subtaskId, patch) {
3915
4052
  // [1.10.6] A conflict belongs to one attempt; a reset starts a new one.
3916
4053
  if (patch.artifactConflict === undefined)
3917
4054
  next.artifactConflict = undefined;
4055
+ /*
4056
+ * [2.3.9][T4b] 第三层痕迹属于上一次尝试:重置后新负责人必须重新梳理、
4057
+ * 旧专家/组员的子会话也已随上一attempt终止——留着它们会让新行「看起来
4058
+ * 已梳理/已在派」,门禁(consolidation)与看板(delegates)双双失真。
4059
+ */
4060
+ if (patch.consolidation === undefined)
4061
+ next.consolidation = undefined;
4062
+ if (patch.delegates === undefined)
4063
+ next.delegates = undefined;
3918
4064
  }
3919
4065
  if (patch.status === 'in_progress') {
3920
4066
  if (next.startedAt === null)
@@ -4835,7 +4981,14 @@ export function buildChildPrompt({ plan, subtask, stage, dependencyResults, cwd,
4835
4981
  * 不注入时的旧行为是让子 Agent 去喊 `"lead"`——那不是任何会话的 id,
4836
4982
  * 真实派发中只会得到 `subagent "lead" is unavailable`。
4837
4983
  */
4838
- leadAgentId = '', leadAgentIdSource = 'none', }) {
4984
+ leadAgentId = '', leadAgentIdSource = 'none',
4985
+ /*
4986
+ * [2.3.9][T4b] 用户强制要求 3:分配任务时必须把要求 1/2 全文告知相关部门。
4987
+ * 注入唯一事实源在 llm-rules.ts(buildLlmRulesBrief,tier='department');
4988
+ * 由派发调用点传入(plan.ts 不能反向 import llm-rules.ts,会造成循环依赖)。
4989
+ * 空串 = 旧调用方(旧测试/旧路径)零变化;新派发链恒传非空。
4990
+ */
4991
+ llmRulesBrief = '', }) {
4839
4992
  const noticeTarget = readLeadAgentId(leadAgentId);
4840
4993
  const noticeCall = leadNoticeCallForm(noticeTarget);
4841
4994
  const noticeTargetLine = noticeTarget
@@ -4978,6 +5131,7 @@ leadAgentId = '', leadAgentIdSource = 'none', }) {
4978
5131
  `全局任务:${understanding.originalRequest ?? '(未记录)'}`,
4979
5132
  `最终交付物:${understanding.deliverable ?? '(未记录)'}`,
4980
5133
  ...anchorBlock,
5134
+ ...(llmRulesBrief ? ['', String(llmRulesBrief), ''] : []),
4981
5135
  `主要矛盾:${contradiction}`,
4982
5136
  `当前阶段:${stageName}(${stageGoal})`,
4983
5137
  `工作目录:${cwd || '(未知)'}`,
package/lib/replan.js CHANGED
@@ -188,7 +188,7 @@ function mergeReplacement(old, replacement, id, reason) {
188
188
  * (T4 D-T4-03)。修复前 add 接受 14 条依赖、200 条 inputs 与 16 万字符
189
189
  * 载荷,这些计划再也回灌不了 validatePlan,却能被真实派发。
190
190
  */
191
- function replanFieldError(raw) {
191
+ function replanFieldError(raw, allowedEfforts) {
192
192
  const list = (key, max, itemMax, required = false) => {
193
193
  const value = raw?.[key];
194
194
  if (value === undefined)
@@ -221,6 +221,10 @@ function replanFieldError(raw) {
221
221
  };
222
222
  /*
223
223
  * [2.2.7][T4/五档+G1] reasoningEffort 入口白名单(replace/add 两路共用本函数):
224
+ * [2.3.9][T3/同步点] 此处按 REASONING_EFFORTS **存储全集五档**校验是刻意决策:
225
+ * 重规划的输入可能来自回放/他模型计划,删档会破坏零迁移契约;模型家族收窄
226
+ * 统一发生在派发入口(runtime.ts 静态收窄 + qwen-rule/non-qwen-rule 留痕)与
227
+ * 规划校验(validatePlan options.allowedEfforts),口径见 plan.ts L214-231 注释。
224
228
  * 与 plan.ts readSubtasks 语义对齐——缺失/显式 null 合法(replace 继承旧行、
225
229
  * add 留给派发期回落 high),非缺失值必须是 REASONING_EFFORTS 五档之一
226
230
  * (low / medium / high / xhigh / max),非法值拒绝、不改写。补上此校验前,
@@ -230,8 +234,15 @@ function replanFieldError(raw) {
230
234
  const effortError = effort === undefined || effort === null
231
235
  ? null
232
236
  : typeof effort !== 'string' || !REASONING_EFFORTS.includes(effort)
233
- ? 'reasoningEffort 必须是 low / medium / high / xhigh / max 之一(缺失合法:replace 继承旧行、add 派发期回落;非法值拒绝,不改写)'
234
- : null;
237
+ ? 'reasoningEffort 必须是 low / medium / high / xhigh / max 之一(缺失合法:replace 继承旧行、add 派发期回落;非法值拒绝,不改写;传入模型家族集合时进一步收窄为该集合)'
238
+ /*
239
+ * [2.3.9][T3] 模型感知收窄口径(用户要求 1/2;与 plan.ts validatePlan、
240
+ * runtime 派发侧同一真源):调用方传入当前模型家族等级集合时,五档合规
241
+ * 但家族越界的档位(如 qwen 系的 high/max)同样拒绝并点名集合,不改写。
242
+ */
243
+ : Array.isArray(allowedEfforts) && allowedEfforts.length > 0 && !allowedEfforts.includes(effort)
244
+ ? `reasoningEffort "${effort}" 不在当前模型家族的推理等级集合 {${allowedEfforts.join(' / ')}} 内(qwen 系仅 low / medium / xhigh;非 qwen 系仅 low / high / max),必须改用集合内档位`
245
+ : null;
235
246
  return list('dependsOn', 12, 16)
236
247
  ?? list('method', 12, 800)
237
248
  ?? list('inputs', 12, 800)
@@ -323,7 +334,7 @@ export function planReplan(plan, changes, options = {}) {
323
334
  if (replacement.department !== undefined && replanDepartment(replacement.department) === null) {
324
335
  return fail(REPLAN_CODES.INVALID_REPLACEMENT, `replacement.department 不是合法部门:${String(replacement.department)}`);
325
336
  }
326
- const replacementError = replanFieldError(replacement);
337
+ const replacementError = replanFieldError(replacement, options?.allowedEfforts);
327
338
  if (replacementError)
328
339
  return fail(REPLAN_CODES.INVALID_REPLACEMENT, `replacement 字段不合规:${replacementError}`);
329
340
  const requestedId = typeof replacement.id === 'string' ? replacement.id.trim() : '';
@@ -382,7 +393,7 @@ export function planReplan(plan, changes, options = {}) {
382
393
  if (department === null) {
383
394
  return fail(REPLAN_CODES.INVALID_SUBTASK, `newSubtask.department 不是合法部门:${String(raw.department)}`);
384
395
  }
385
- const fieldError = replanFieldError(raw);
396
+ const fieldError = replanFieldError(raw, options?.allowedEfforts);
386
397
  if (fieldError)
387
398
  return fail(REPLAN_CODES.INVALID_SUBTASK, `newSubtask 字段不合规:${fieldError}`);
388
399
  const goal = typeof raw.objective === 'string' ? raw.objective.trim() : '';