dsh-workplan 2.3.9 → 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/src/replan.ts CHANGED
@@ -282,8 +282,8 @@ function replanFieldError(raw: any, allowedEfforts?: readonly string[] | null):
282
282
  : Array.isArray(allowedEfforts) && allowedEfforts.length > 0 && !allowedEfforts.includes(effort)
283
283
  ? `reasoningEffort "${effort}" 不在当前模型家族的推理等级集合 {${allowedEfforts.join(' / ')}} 内(qwen 系仅 low / medium / xhigh;非 qwen 系仅 low / high / max),必须改用集合内档位`
284
284
  : null
285
- return list('dependsOn', 12, 16)
286
- ?? list('method', 12, 800)
285
+ return list('dependsOn', 12, MAX_SUBTASKS - 1)
286
+ ?? list('method', 8, 800)
287
287
  ?? list('inputs', 12, 800)
288
288
  ?? list('outputs', 12, 800)
289
289
  ?? list('acceptance', 8, 800)
@@ -627,24 +627,25 @@ export function applyReplanStatuses(statuses: any, payload: ReplanPayload): any[
627
627
  return next
628
628
  }
629
629
 
630
- /** durable `workplan-replan` 消息:正文 + 一行 JSON 载荷。 */
630
+ /** durable `workplan-replan` 消息:[T7] 可见文本置空(过程事件,C2),全量信封随 source.durable 落盘(选项 A)。 */
631
631
  export function buildReplanMessage(payload: ReplanPayload) {
632
632
  const changed = payload.marks.map((mark) => `${mark.subtaskId}→${mark.replacedBy.length ? mark.replacedBy.join('、') : '撤销'}`)
633
633
  const summary = truncate(`【重规划 r${payload.revision}】${changed.join(',') || '新增子任务'}`, 300)
634
- const lines = [
635
- summary,
636
- '',
637
- `原因:${payload.reason}`,
638
- '旧行保留为已重规划(不计入剩余项、不再调度);新行按 pending 进入下一轮。',
639
- '',
640
- REPLAN_MARKER_BEGIN,
641
- JSON.stringify(payload),
642
- REPLAN_MARKER_END,
643
- ]
644
- return makeUserMessage(lines.join('\n'), { kind: 'workplan-replan', form: 'notice', summary })
634
+ /*
635
+ * [T7] 重规划是过程事件:主 Agent 从 dsh_workplan_replan 的工具返回(按需
636
+ * 通道,不裁剪)已知晓新行与后续动作;注入正文置空,信封仍随事件落盘,
637
+ * parseReplanMessage 先读元数据回退旧文本标记(旧消息零迁移,C4)。
638
+ */
639
+ return makeUserMessage('', { kind: 'workplan-replan', form: 'notice', summary, durable: payload })
645
640
  }
646
641
 
647
642
  export function parseReplanMessage(message: any): ReplanPayload | null {
643
+ /* [T7] 先读元数据信封(source.durable,选项 A),回退旧文本标记。 */
644
+ const durable = message?.source?.durable
645
+ if (isRecord(durable) && durable.kind === 'workplan-replan'
646
+ && durable.plan && Array.isArray(durable.marks) && Array.isArray(durable.added)) {
647
+ return durable as ReplanPayload
648
+ }
648
649
  const text = messageText(message)
649
650
  const begin = text.indexOf(REPLAN_MARKER_BEGIN)
650
651
  const end = text.indexOf(REPLAN_MARKER_END)
@@ -709,42 +710,52 @@ export function buildChangeRequestMessage(payload: ChangeRequestPayload, context
709
710
  '1. 变更影响范围:调用 dsh_workplan_replan,用 cancel/replace/add 逐项说明受影响的子任务;旧行会保留为「已重规划」并可追溯。',
710
711
  '2. 只是补充说明、不改范围:调用 dsh_workplan_update 把说明写进对应子任务的 note。',
711
712
  '3. 变更尚未明确:先向用户确认,再重规划;不要用旧计划直接交付。',
712
- '',
713
- CHANGE_MARKER_BEGIN,
714
- JSON.stringify(payload),
715
- CHANGE_MARKER_END,
716
713
  ]
714
+ /*
715
+ * [T7] 变更原文是用户输入而非插件噪音:正文保留(闸门对 workplan-change
716
+ * 豁免上限),仅把 JSON 信封从正文移入 source.durable(选项 A);
717
+ * parseChangeRequestMessage 先读元数据回退旧文本标记(旧消息零迁移)。
718
+ */
717
719
  return makeUserMessage(lines.join('\n'), {
718
720
  kind: 'workplan-change',
719
721
  form: 'notice',
720
722
  summary: truncate(`需求变更已记录 #${payload.seq}`, 200),
723
+ durable: payload,
721
724
  })
722
725
  }
723
726
 
724
727
  export function parseChangeRequestMessage(message: any): ChangeRequestPayload | null {
725
- const text = messageText(message)
726
- const begin = text.indexOf(CHANGE_MARKER_BEGIN)
727
- const end = text.indexOf(CHANGE_MARKER_END)
728
- if (begin < 0 || end <= begin) return null
729
- try {
730
- const payload = JSON.parse(text.slice(begin + CHANGE_MARKER_BEGIN.length, end).trim())
731
- if (!isRecord(payload) || payload.kind !== 'workplan-change') return null
732
- if (typeof payload.text !== 'string' || !payload.text.trim()) return null
733
- return {
734
- kind: 'workplan-change',
735
- planId: String(payload.planId ?? ''),
736
- seq: Number.isInteger(Number(payload.seq)) ? Number(payload.seq) : 1,
737
- at: Number(payload.at) || Date.now(),
738
- turn: Number.isInteger(Number(payload.turn)) ? Number(payload.turn) : null,
739
- text: truncate(payload.text, 4000),
728
+ /* [T7] 先读元数据信封(source.durable,选项 A),回退旧文本标记。 */
729
+ let payload: any = message?.source?.durable
730
+ if (!isRecord(payload) || payload.kind !== 'workplan-change') {
731
+ const text = messageText(message)
732
+ const begin = text.indexOf(CHANGE_MARKER_BEGIN)
733
+ const end = text.indexOf(CHANGE_MARKER_END)
734
+ if (begin < 0 || end <= begin) return null
735
+ try {
736
+ payload = JSON.parse(text.slice(begin + CHANGE_MARKER_BEGIN.length, end).trim())
737
+ } catch {
738
+ return null
740
739
  }
741
- } catch {
742
- return null
740
+ }
741
+ if (!isRecord(payload) || payload.kind !== 'workplan-change') return null
742
+ if (typeof payload.text !== 'string' || !payload.text.trim()) return null
743
+ return {
744
+ kind: 'workplan-change',
745
+ planId: String(payload.planId ?? ''),
746
+ seq: Number.isInteger(Number(payload.seq)) ? Number(payload.seq) : 1,
747
+ at: Number(payload.at) || Date.now(),
748
+ turn: Number.isInteger(Number(payload.turn)) ? Number(payload.turn) : null,
749
+ text: truncate(payload.text, 4000),
743
750
  }
744
751
  }
745
752
 
746
- /** 从计划定义里读重规划修订号(写入时放在 plan.revision)。 */
753
+ /**
754
+ * 从计划定义里读重规划修订号(写入时放在 plan.planRevision,见本文件
755
+ * planReplan() 的 next.planRevision = revision;runtime 消费侧同样读
756
+ * plan.planRevision,见 runtime.ts 的 Number(plan?.planRevision ?? 0))。
757
+ */
747
758
  export function planRevisionOf(plan: any): number {
748
- const revision = Number(plan?.revision ?? 0)
759
+ const revision = Number(plan?.planRevision ?? 0)
749
760
  return Number.isFinite(revision) && revision > 0 ? revision : 0
750
761
  }