dsh-workplan 2.3.2 → 3.0.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/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,10 +234,17 @@ 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;
235
- return list('dependsOn', 12, 16)
236
- ?? list('method', 12, 800)
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;
246
+ return list('dependsOn', 12, MAX_SUBTASKS - 1)
247
+ ?? list('method', 8, 800)
237
248
  ?? list('inputs', 12, 800)
238
249
  ?? list('outputs', 12, 800)
239
250
  ?? list('acceptance', 8, 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() : '';
@@ -593,23 +604,24 @@ export function applyReplanStatuses(statuses, payload) {
593
604
  }
594
605
  return next;
595
606
  }
596
- /** durable `workplan-replan` 消息:正文 + 一行 JSON 载荷。 */
607
+ /** durable `workplan-replan` 消息:[T7] 可见文本置空(过程事件,C2),全量信封随 source.durable 落盘(选项 A)。 */
597
608
  export function buildReplanMessage(payload) {
598
609
  const changed = payload.marks.map((mark) => `${mark.subtaskId}→${mark.replacedBy.length ? mark.replacedBy.join('、') : '撤销'}`);
599
610
  const summary = truncate(`【重规划 r${payload.revision}】${changed.join(',') || '新增子任务'}`, 300);
600
- const lines = [
601
- summary,
602
- '',
603
- `原因:${payload.reason}`,
604
- '旧行保留为已重规划(不计入剩余项、不再调度);新行按 pending 进入下一轮。',
605
- '',
606
- REPLAN_MARKER_BEGIN,
607
- JSON.stringify(payload),
608
- REPLAN_MARKER_END,
609
- ];
610
- return makeUserMessage(lines.join('\n'), { kind: 'workplan-replan', form: 'notice', summary });
611
+ /*
612
+ * [T7] 重规划是过程事件:主 Agent 从 dsh_workplan_replan 的工具返回(按需
613
+ * 通道,不裁剪)已知晓新行与后续动作;注入正文置空,信封仍随事件落盘,
614
+ * parseReplanMessage 先读元数据回退旧文本标记(旧消息零迁移,C4)。
615
+ */
616
+ return makeUserMessage('', { kind: 'workplan-replan', form: 'notice', summary, durable: payload });
611
617
  }
612
618
  export function parseReplanMessage(message) {
619
+ /* [T7] 先读元数据信封(source.durable,选项 A),回退旧文本标记。 */
620
+ const durable = message?.source?.durable;
621
+ if (isRecord(durable) && durable.kind === 'workplan-replan'
622
+ && durable.plan && Array.isArray(durable.marks) && Array.isArray(durable.added)) {
623
+ return durable;
624
+ }
613
625
  const text = messageText(message);
614
626
  const begin = text.indexOf(REPLAN_MARKER_BEGIN);
615
627
  const end = text.indexOf(REPLAN_MARKER_END);
@@ -666,44 +678,54 @@ export function buildChangeRequestMessage(payload, context = {}) {
666
678
  '1. 变更影响范围:调用 dsh_workplan_replan,用 cancel/replace/add 逐项说明受影响的子任务;旧行会保留为「已重规划」并可追溯。',
667
679
  '2. 只是补充说明、不改范围:调用 dsh_workplan_update 把说明写进对应子任务的 note。',
668
680
  '3. 变更尚未明确:先向用户确认,再重规划;不要用旧计划直接交付。',
669
- '',
670
- CHANGE_MARKER_BEGIN,
671
- JSON.stringify(payload),
672
- CHANGE_MARKER_END,
673
681
  ];
682
+ /*
683
+ * [T7] 变更原文是用户输入而非插件噪音:正文保留(闸门对 workplan-change
684
+ * 豁免上限),仅把 JSON 信封从正文移入 source.durable(选项 A);
685
+ * parseChangeRequestMessage 先读元数据回退旧文本标记(旧消息零迁移)。
686
+ */
674
687
  return makeUserMessage(lines.join('\n'), {
675
688
  kind: 'workplan-change',
676
689
  form: 'notice',
677
690
  summary: truncate(`需求变更已记录 #${payload.seq}`, 200),
691
+ durable: payload,
678
692
  });
679
693
  }
680
694
  export function parseChangeRequestMessage(message) {
681
- const text = messageText(message);
682
- const begin = text.indexOf(CHANGE_MARKER_BEGIN);
683
- const end = text.indexOf(CHANGE_MARKER_END);
684
- if (begin < 0 || end <= begin)
685
- return null;
686
- try {
687
- const payload = JSON.parse(text.slice(begin + CHANGE_MARKER_BEGIN.length, end).trim());
688
- if (!isRecord(payload) || payload.kind !== 'workplan-change')
695
+ /* [T7] 先读元数据信封(source.durable,选项 A),回退旧文本标记。 */
696
+ let payload = message?.source?.durable;
697
+ if (!isRecord(payload) || payload.kind !== 'workplan-change') {
698
+ const text = messageText(message);
699
+ const begin = text.indexOf(CHANGE_MARKER_BEGIN);
700
+ const end = text.indexOf(CHANGE_MARKER_END);
701
+ if (begin < 0 || end <= begin)
689
702
  return null;
690
- if (typeof payload.text !== 'string' || !payload.text.trim())
703
+ try {
704
+ payload = JSON.parse(text.slice(begin + CHANGE_MARKER_BEGIN.length, end).trim());
705
+ }
706
+ catch {
691
707
  return null;
692
- return {
693
- kind: 'workplan-change',
694
- planId: String(payload.planId ?? ''),
695
- seq: Number.isInteger(Number(payload.seq)) ? Number(payload.seq) : 1,
696
- at: Number(payload.at) || Date.now(),
697
- turn: Number.isInteger(Number(payload.turn)) ? Number(payload.turn) : null,
698
- text: truncate(payload.text, 4000),
699
- };
708
+ }
700
709
  }
701
- catch {
710
+ if (!isRecord(payload) || payload.kind !== 'workplan-change')
702
711
  return null;
703
- }
712
+ if (typeof payload.text !== 'string' || !payload.text.trim())
713
+ return null;
714
+ return {
715
+ kind: 'workplan-change',
716
+ planId: String(payload.planId ?? ''),
717
+ seq: Number.isInteger(Number(payload.seq)) ? Number(payload.seq) : 1,
718
+ at: Number(payload.at) || Date.now(),
719
+ turn: Number.isInteger(Number(payload.turn)) ? Number(payload.turn) : null,
720
+ text: truncate(payload.text, 4000),
721
+ };
704
722
  }
705
- /** 从计划定义里读重规划修订号(写入时放在 plan.revision)。 */
723
+ /**
724
+ * 从计划定义里读重规划修订号(写入时放在 plan.planRevision,见本文件
725
+ * planReplan() 的 next.planRevision = revision;runtime 消费侧同样读
726
+ * plan.planRevision,见 runtime.ts 的 Number(plan?.planRevision ?? 0))。
727
+ */
706
728
  export function planRevisionOf(plan) {
707
- const revision = Number(plan?.revision ?? 0);
729
+ const revision = Number(plan?.planRevision ?? 0);
708
730
  return Number.isFinite(revision) && revision > 0 ? revision : 0;
709
731
  }