dsh-workplan 2.3.9 → 3.0.1

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
@@ -243,8 +243,8 @@ function replanFieldError(raw, allowedEfforts) {
243
243
  : Array.isArray(allowedEfforts) && allowedEfforts.length > 0 && !allowedEfforts.includes(effort)
244
244
  ? `reasoningEffort "${effort}" 不在当前模型家族的推理等级集合 {${allowedEfforts.join(' / ')}} 内(qwen 系仅 low / medium / xhigh;非 qwen 系仅 low / high / max),必须改用集合内档位`
245
245
  : null;
246
- return list('dependsOn', 12, 16)
247
- ?? list('method', 12, 800)
246
+ return list('dependsOn', 12, MAX_SUBTASKS - 1)
247
+ ?? list('method', 8, 800)
248
248
  ?? list('inputs', 12, 800)
249
249
  ?? list('outputs', 12, 800)
250
250
  ?? list('acceptance', 8, 800)
@@ -604,23 +604,24 @@ export function applyReplanStatuses(statuses, payload) {
604
604
  }
605
605
  return next;
606
606
  }
607
- /** durable `workplan-replan` 消息:正文 + 一行 JSON 载荷。 */
607
+ /** durable `workplan-replan` 消息:[T7] 可见文本置空(过程事件,C2),全量信封随 source.durable 落盘(选项 A)。 */
608
608
  export function buildReplanMessage(payload) {
609
609
  const changed = payload.marks.map((mark) => `${mark.subtaskId}→${mark.replacedBy.length ? mark.replacedBy.join('、') : '撤销'}`);
610
610
  const summary = truncate(`【重规划 r${payload.revision}】${changed.join(',') || '新增子任务'}`, 300);
611
- const lines = [
612
- summary,
613
- '',
614
- `原因:${payload.reason}`,
615
- '旧行保留为已重规划(不计入剩余项、不再调度);新行按 pending 进入下一轮。',
616
- '',
617
- REPLAN_MARKER_BEGIN,
618
- JSON.stringify(payload),
619
- REPLAN_MARKER_END,
620
- ];
621
- 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 });
622
617
  }
623
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
+ }
624
625
  const text = messageText(message);
625
626
  const begin = text.indexOf(REPLAN_MARKER_BEGIN);
626
627
  const end = text.indexOf(REPLAN_MARKER_END);
@@ -677,44 +678,54 @@ export function buildChangeRequestMessage(payload, context = {}) {
677
678
  '1. 变更影响范围:调用 dsh_workplan_replan,用 cancel/replace/add 逐项说明受影响的子任务;旧行会保留为「已重规划」并可追溯。',
678
679
  '2. 只是补充说明、不改范围:调用 dsh_workplan_update 把说明写进对应子任务的 note。',
679
680
  '3. 变更尚未明确:先向用户确认,再重规划;不要用旧计划直接交付。',
680
- '',
681
- CHANGE_MARKER_BEGIN,
682
- JSON.stringify(payload),
683
- CHANGE_MARKER_END,
684
681
  ];
682
+ /*
683
+ * [T7] 变更原文是用户输入而非插件噪音:正文保留(闸门对 workplan-change
684
+ * 豁免上限),仅把 JSON 信封从正文移入 source.durable(选项 A);
685
+ * parseChangeRequestMessage 先读元数据回退旧文本标记(旧消息零迁移)。
686
+ */
685
687
  return makeUserMessage(lines.join('\n'), {
686
688
  kind: 'workplan-change',
687
689
  form: 'notice',
688
690
  summary: truncate(`需求变更已记录 #${payload.seq}`, 200),
691
+ durable: payload,
689
692
  });
690
693
  }
691
694
  export function parseChangeRequestMessage(message) {
692
- const text = messageText(message);
693
- const begin = text.indexOf(CHANGE_MARKER_BEGIN);
694
- const end = text.indexOf(CHANGE_MARKER_END);
695
- if (begin < 0 || end <= begin)
696
- return null;
697
- try {
698
- const payload = JSON.parse(text.slice(begin + CHANGE_MARKER_BEGIN.length, end).trim());
699
- 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)
700
702
  return null;
701
- 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 {
702
707
  return null;
703
- return {
704
- kind: 'workplan-change',
705
- planId: String(payload.planId ?? ''),
706
- seq: Number.isInteger(Number(payload.seq)) ? Number(payload.seq) : 1,
707
- at: Number(payload.at) || Date.now(),
708
- turn: Number.isInteger(Number(payload.turn)) ? Number(payload.turn) : null,
709
- text: truncate(payload.text, 4000),
710
- };
708
+ }
711
709
  }
712
- catch {
710
+ if (!isRecord(payload) || payload.kind !== 'workplan-change')
713
711
  return null;
714
- }
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
+ };
715
722
  }
716
- /** 从计划定义里读重规划修订号(写入时放在 plan.revision)。 */
723
+ /**
724
+ * 从计划定义里读重规划修订号(写入时放在 plan.planRevision,见本文件
725
+ * planReplan() 的 next.planRevision = revision;runtime 消费侧同样读
726
+ * plan.planRevision,见 runtime.ts 的 Number(plan?.planRevision ?? 0))。
727
+ */
717
728
  export function planRevisionOf(plan) {
718
- const revision = Number(plan?.revision ?? 0);
729
+ const revision = Number(plan?.planRevision ?? 0);
719
730
  return Number.isFinite(revision) && revision > 0 ? revision : 0;
720
731
  }