dsh-workplan 3.0.0 → 3.0.2
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 +51 -0
- package/README.en.md +20 -18
- package/README.md +33 -19
- package/README.zh.md +15 -19
- package/client.js +36 -67
- package/docs/cc/ADV-FSP-FUNCTIONAL-SPEC.md +16 -3
- package/docs/cc/ADV-TDS-TOE-DESIGN.md +3 -3
- package/docs/cc/AGD-OPS-SECURE-OPERATION.md +3 -7
- package/docs/cc/AVA-VULNERABILITY-ANALYSIS.md +19 -0
- package/docs/cc/SECURITY-TARGET.md +6 -6
- package/docs/collaboration.md +17 -16
- package/lib/approval-gate.js +144 -0
- package/lib/client.js +36 -67
- package/lib/criterion.js +22 -27
- package/lib/host.js +178 -40
- package/lib/llm-rules.js +2 -2
- package/lib/plan.js +176 -85
- package/lib/runtime.js +756 -829
- package/lib/watchdog.js +3 -0
- package/package.json +3 -2
- package/src/approval-gate.ts +168 -0
- package/src/client.ts +36 -67
- package/src/criterion.ts +22 -23
- package/src/host.ts +185 -40
- package/src/llm-rules.ts +2 -2
- package/src/plan.ts +166 -83
- package/src/runtime.ts +643 -693
- package/src/watchdog.ts +7 -0
package/src/plan.ts
CHANGED
|
@@ -10,10 +10,8 @@
|
|
|
10
10
|
import { createHash, randomUUID } from 'node:crypto'
|
|
11
11
|
|
|
12
12
|
import { DEPARTMENT_CAPABILITIES, DEPARTMENT_EXPERT_STANDARD, departmentCapability } from './departments.js'
|
|
13
|
-
//
|
|
14
|
-
// 只引入判据层常量/消毒/派生,运行层常量与公式不在本模块改动(Q7-B 红线)。
|
|
13
|
+
// 历史判据字段只做读取消毒;不再派生或传播时间完成门槛。
|
|
15
14
|
import {
|
|
16
|
-
CRITERION_TARGET_MINUTES,
|
|
17
15
|
CRITERION_RESULTS,
|
|
18
16
|
attemptWallClockMsOf,
|
|
19
17
|
sanitizeCriterionException,
|
|
@@ -874,7 +872,7 @@ function readSubtasks(value: any, stageIndex: any, errors: any) {
|
|
|
874
872
|
* estimateNeedsJustification 仅在触发时下发,旧计划载荷逐字不变)。
|
|
875
873
|
*/
|
|
876
874
|
if (source.splitReason !== undefined && source.splitReason !== null && typeof source.splitReason !== 'string') {
|
|
877
|
-
push(errors, `${base}.splitReason`, '
|
|
875
|
+
push(errors, `${base}.splitReason`, '必须是字符串(可选的历史拆分说明,缺失合法;与执行时限无关)')
|
|
878
876
|
}
|
|
879
877
|
const splitReasonText = typeof source.splitReason === 'string' ? source.splitReason.trim() : ''
|
|
880
878
|
let estimateConfirm: { confirmed: boolean; by?: string; at?: number; reason?: string } | null = null
|
|
@@ -895,10 +893,6 @@ function readSubtasks(value: any, stageIndex: any, errors: any) {
|
|
|
895
893
|
}
|
|
896
894
|
}
|
|
897
895
|
}
|
|
898
|
-
const estimateOverCriterion = estimateOk && estimateValue > CRITERION_TARGET_MINUTES
|
|
899
|
-
const estimateNeedsJustification = estimateOverCriterion
|
|
900
|
-
&& splitReasonText === ''
|
|
901
|
-
&& !(estimateConfirm && estimateConfirm.confirmed === true)
|
|
902
896
|
/*
|
|
903
897
|
* [2.2.0][T3/O-3a] per-subtask 协商上限(timeoutMs,毫秒)可选透传。
|
|
904
898
|
*
|
|
@@ -915,7 +909,7 @@ function readSubtasks(value: any, stageIndex: any, errors: any) {
|
|
|
915
909
|
&& Number.isFinite(timeoutValue)
|
|
916
910
|
&& timeoutValue > 0
|
|
917
911
|
if (hasTimeout && !timeoutOk) {
|
|
918
|
-
push(errors, `${base}.timeoutMs`, '
|
|
912
|
+
push(errors, `${base}.timeoutMs`, '必须是正数毫秒(旧计划的历史字段,可选;不会形成执行截止)')
|
|
919
913
|
}
|
|
920
914
|
/*
|
|
921
915
|
* [2.2.0][T13/推理等级] 子任务自带的推理等级(可选,仅 low / medium / high / xhigh / max)。
|
|
@@ -985,9 +979,7 @@ function readSubtasks(value: any, stageIndex: any, errors: any) {
|
|
|
985
979
|
* [1.7.0] 历史记录。
|
|
986
980
|
*/
|
|
987
981
|
...(estimateOk ? { estimateMinutes: estimateValue } : {}),
|
|
988
|
-
//
|
|
989
|
-
...(estimateOverCriterion ? { estimateOverCriterion: true } : {}),
|
|
990
|
-
...(estimateNeedsJustification ? { estimateNeedsJustification: true } : {}),
|
|
982
|
+
// splitReason / estimateConfirm 仅作历史兼容,不再派生任何时间判据或软门禁。
|
|
991
983
|
...(splitReasonText !== '' ? { splitReason: truncate(splitReasonText, 800) } : {}),
|
|
992
984
|
...(estimateConfirm ? { estimateConfirm } : {}),
|
|
993
985
|
...(timeoutOk ? { timeoutMs: timeoutValue } : {}),
|
|
@@ -1655,11 +1647,6 @@ export function buildPlannerPrompt(taskText: any, cwd: any, conversationContext:
|
|
|
1655
1647
|
const departments = DEPARTMENT_CAPABILITIES
|
|
1656
1648
|
.map((entry) => `- ${entry.id}(${entry.zh} / ${entry.en}):职责 ${entry.responsibilities.join(';')};典型产物 ${entry.outputs.join(';')}`)
|
|
1657
1649
|
.join('\n')
|
|
1658
|
-
const rawTotalMinutes = Number(budget?.totalMinutes)
|
|
1659
|
-
const totalMinutes = Number.isFinite(rawTotalMinutes) && rawTotalMinutes > 0
|
|
1660
|
-
? Math.max(1, Math.round(rawTotalMinutes))
|
|
1661
|
-
: 0
|
|
1662
|
-
const childMinutes = Math.max(1, Math.round(Number(budget?.childMinutes) || 15))
|
|
1663
1650
|
const concurrency = Math.max(1, Number(budget?.concurrency) || MAX_CONCURRENT)
|
|
1664
1651
|
const resumes = Number.isFinite(Number(budget?.maxResumes)) ? Number(budget.maxResumes) : MAX_PLAN_RESUMES
|
|
1665
1652
|
const task = truncate(taskText, 16000)
|
|
@@ -1693,28 +1680,24 @@ export function buildPlannerPrompt(taskText: any, cwd: any, conversationContext:
|
|
|
1693
1680
|
'- department 必须从下面的部门中选择一个;必须同时写 departmentRationale(1-2 句,引用该部门职责与任务要素),department 与 rationale 不一致的计划视为不合格。',
|
|
1694
1681
|
'- method、outputs、acceptance 必须是非空数组;inputs 可以为空,未知写“待确认”。',
|
|
1695
1682
|
'- unknowns 和 assumptions 必须如实列出;没有就写空数组,不能把假设写成事实。',
|
|
1696
|
-
'-
|
|
1683
|
+
'- 子任务必须可独立执行、可验收;按单一目标、单一主产物和清晰验收边界拆分,不得按分钟数强行切分,也不得为了凑数拆无意义任务。',
|
|
1697
1684
|
// [2.5.0] 用户要求 3:分解必须更简单。部门负责人拥有本部门内再分配权限
|
|
1698
1685
|
// (dsh_workplan_delegate),会把子任务再拆给多名顶尖专家与组员,因此
|
|
1699
1686
|
// 主计划层保持单一目标/单一主产物的简单子任务,执行细节下沉到部门内分工。
|
|
1700
|
-
'- 分解必须更简单(用户强制要求):每个子任务只写单一目标、单一主产物、可独立验收的一件事;不要把多个交付物压进同一个子任务。部门负责人接到子任务后,会用 dsh_workplan_delegate 把它再拆成更简单的单项工作,分配给本部门多名相关领域全球顶尖专家共同承担(部门组员角色已按用户要求 9
|
|
1687
|
+
'- 分解必须更简单(用户强制要求):每个子任务只写单一目标、单一主产物、可独立验收的一件事;不要把多个交付物压进同一个子任务。部门负责人接到子任务后,会用 dsh_workplan_delegate 把它再拆成更简单的单项工作,分配给本部门多名相关领域全球顶尖专家共同承担(部门组员角色已按用户要求 9 取消)——所以主计划子任务保持简单清晰即可,执行细节由部门内分工细化,不要越俎代庖替部门预拆全部细节。再分配只按工作边界与验收拆分;预估可汇总用于协调,但不设分钟上限,也不影响达标判定。',
|
|
1701
1688
|
'- 子任务由部门负责人子 Agent 牵头执行:负责人拥有本部门内的再分配权限(dsh_workplan_delegate,先 review 提交两轮深度思考产物后 dispatch 派给本部门专家(只保留 expert 角色)),但没有主计划派发权限、不能重启服务、不能安装或升级依赖。禁止把「调用 dsh_workplan_dispatch」「重启/停止 dsh web」「安装或升级插件」这类只有主 Agent 才能执行的动作写进子任务;确实需要时,写成“给出结论或建议,由主 Agent 执行”。',
|
|
1702
|
-
'-
|
|
1703
|
-
'- 运行层安全兜底(不是固定交付期限、不构成对外承诺,也不构成「允许慢」的许可):单次执行时限=clamp(estimateMinutes×2.0, 1 秒, 120 分钟),到点走安全兜底结算保证不丢产物;确需超过 10 分钟的唯一合法例外是用户明确批准并留痕(任务 ID、批准原文/来源、批准时间、放宽后分钟数、适用范围;无留痕=未批准);未获批准的超时不得以 done 收尾,记「判据违规(criterion-overrun)」并转新子任务续做。',
|
|
1704
|
-
'- 生效时点(不回溯):本判据自用户 2026-11-13 裁决(B/B/B/B/A/A/B)生效;运行态判定自补丁部署+用户重启+复核通过后新创建的计划起执行;此前已验收为 done 的历史任务与在途计划按旧规则,不重判、不重跑、不改验收结论。',
|
|
1689
|
+
'- 执行无时限:部门负责人和全球顶尖专家没有总时长、单次时长、空闲或回执硬截止;不要设置 timeoutMs,不要按分钟数拆任务,也不要把预估或实际耗时作为 done 的验收条件。用户显式取消、真实错误与证据/质量门禁仍须保留。',
|
|
1705
1690
|
// [2.3.2][D2-P2] 半角/逗号/括号自检硬约束:与解析层兜底(P0)互为防线,中文模型全角标点高发。
|
|
1706
1691
|
'- JSON 只允许半角标点(, : " { } [ ]);对象与数组的相邻成员之间必须有逗号;输出前自检括号成对、每个字符串以半角"闭合。',
|
|
1707
1692
|
'- 不要输出 Markdown 代码围栏、解释或前后缀;只输出一个 JSON 对象。',
|
|
1708
1693
|
'',
|
|
1709
|
-
'
|
|
1710
|
-
|
|
1711
|
-
? `- 一轮总预算约 ${totalMinutes} 分钟(运行层安全兜底,不是交付期限);判据层完成目标 ≤10 分钟;运行层规模参考 ${childMinutes} 分钟量级(仅供参考、非承诺,实际时长由执行专家开工预告协商决定),两个数字分属两层、不得混读;同时最多 ${concurrency} 个子任务并行。`
|
|
1712
|
-
: `- 本轮不设固定总预算;单个子任务按自身 estimateMinutes 与协商截止/延期执行;同时最多 ${concurrency} 个子任务并行。`,
|
|
1694
|
+
'本轮资源与执行方式:',
|
|
1695
|
+
`- 不设置整轮或单个子任务执行截止;estimateMinutes 只用于协调,不能派生 timeoutMs 或延期机制;同时最多 ${concurrency} 个子任务并行。`,
|
|
1713
1696
|
resumes > 0
|
|
1714
1697
|
? `- 受阻后自动续跑额度 ${resumes} 次;需要时计划会暂停并在下一轮继续。`
|
|
1715
1698
|
: '- 自动续跑额度为 0;计划不会因轮次预算被暂停。',
|
|
1716
1699
|
'- [3.0.0][用户要求 3/5] 每个子任务必须写 qualityRequirements(1-8 条字符串):这是主 Agent 派给部门负责人时随任务书一起下达的「结果质量要求」,写清成果必须达到什么要求、什么算合格。缺失质量要求的子任务在派发时会被系统直接拒发(DISPATCH_QUALITY_REQUIREMENTS_MISSING,不启动部门 Agent),必须 replan 补齐后重新派发。同时子任务必须是简单到 1+1=2 的单项工作:一个目标、一个主产物、一项可独立验收;不要在一个子任务里塞并列的多件事(出现「并且/同时/另外/还要/以及/分别/顺便」或多句并列时应拆成多个子任务)。',
|
|
1717
|
-
'- 每个子任务必须写 estimateMinutes(整数 1-240
|
|
1700
|
+
'- 每个子任务必须写 estimateMinutes(整数 1-240,如实预估):只用于安排协调与告知用户,仅供参考、非承诺;不会派生执行截止,不会因超过预估算超时,也不影响 done 验收。取值整数与范围校验仅防止离谱输入,缺失不报错。',
|
|
1718
1701
|
/*
|
|
1719
1702
|
* [2.2.0][T13/推理等级] 子 Agent 必须自决推理等级,禁止继承主 Agent。
|
|
1720
1703
|
* 用户规则原文见 plan.ts 顶部 REASONING_EFFORTS 注释;五档映射与五个示例
|
|
@@ -1900,7 +1883,7 @@ function flushPreHeadNotices(session: any) {
|
|
|
1900
1883
|
// 头未就绪绝不补发(否则又把通知写到 head 之前);等 head 落地后的下一次写入再补。
|
|
1901
1884
|
if (!surfaceHeadExists(session)) return
|
|
1902
1885
|
preHeadNoticeQueue.delete(session)
|
|
1903
|
-
for (const message of queue) session.append('user/message', message, { surfaceOp: 'append' })
|
|
1886
|
+
for (const message of queue) session.append('user/message', toJsonSafe(message), { surfaceOp: 'append' })
|
|
1904
1887
|
}
|
|
1905
1888
|
|
|
1906
1889
|
/*
|
|
@@ -2025,6 +2008,10 @@ const DURABLE_ENVELOPE_KINDS = new Set([
|
|
|
2025
2008
|
* - 本轮结算 finishRound 之前。
|
|
2026
2009
|
* 回放侧 parseUpdateMessages 把汇总消息里的 updates 数组按序逐条返回,语义与
|
|
2027
2010
|
* 逐条落盘完全等价(reconstructFromSession 仍是唯一的应用者)。
|
|
2011
|
+
*
|
|
2012
|
+
* [T3 写入失败限流] 合并落盘失败的重试策略:同批缓冲首次失败只记一次错误
|
|
2013
|
+
* (failed 闩锁),此后所有周期重试时机一律跳过该批,避免错误刷屏与无效重试;
|
|
2014
|
+
* 该批缓冲收到新台账更新时闩锁自动复位,重试恢复(缓冲本体始终保留,不丢台账)。
|
|
2028
2015
|
*/
|
|
2029
2016
|
export const PENDING_UPDATE_COUNT_LIMIT = 100
|
|
2030
2017
|
export const PENDING_UPDATE_SIZE_LIMIT = 200_000
|
|
@@ -2035,6 +2022,12 @@ interface PendingUpdateBuffer {
|
|
|
2035
2022
|
updates: any[]
|
|
2036
2023
|
size: number
|
|
2037
2024
|
dropped: number
|
|
2025
|
+
/**
|
|
2026
|
+
* [T3 写入失败限流] 同批缓冲首次落盘失败后置 true:此后周期重试(定时补发 /
|
|
2027
|
+
* pre-step 合并 / 结算合并)一律跳过该批,只记一次错误;缓冲收到新台账更新时
|
|
2028
|
+
* 自动复位为 false,恢复重试。
|
|
2029
|
+
*/
|
|
2030
|
+
failed?: boolean
|
|
2038
2031
|
}
|
|
2039
2032
|
|
|
2040
2033
|
const pendingUpdateBuffers = new WeakMap<object, PendingUpdateBuffer>()
|
|
@@ -2083,6 +2076,9 @@ function tryBufferWorkplanUpdate(session: any, message: any) {
|
|
|
2083
2076
|
const buffer = pendingBufferOf(session)
|
|
2084
2077
|
if (!buffer.planId && typeof durable.planId === 'string') buffer.planId = durable.planId
|
|
2085
2078
|
buffer.updates.push(durable)
|
|
2079
|
+
/* [T3 写入失败限流] 新台账更新到来即恢复该批的重试资格(此前可能因首次落盘
|
|
2080
|
+
* 失败而被限流停掉)。 */
|
|
2081
|
+
buffer.failed = false
|
|
2086
2082
|
try {
|
|
2087
2083
|
buffer.size += JSON.stringify(durable).length
|
|
2088
2084
|
} catch {
|
|
@@ -2108,6 +2104,9 @@ export function flushPendingWorkplanUpdates(session: any) {
|
|
|
2108
2104
|
if (!session || typeof session !== 'object') return undefined
|
|
2109
2105
|
const buffer = pendingUpdateBuffers.get(session)
|
|
2110
2106
|
if (!buffer || buffer.updates.length === 0) return undefined
|
|
2107
|
+
/* [T3 写入失败限流] 同批缓冲首次落盘失败后已记录一次错误并停止周期重试:
|
|
2108
|
+
* 这里直接跳过,下一次 tryBufferWorkplanUpdate 收到新更新会复位 failed。 */
|
|
2109
|
+
if (buffer.failed) return undefined
|
|
2111
2110
|
const updates = buffer.updates
|
|
2112
2111
|
const planId = buffer.planId || (typeof updates[updates.length - 1]?.planId === 'string' ? updates[updates.length - 1].planId : '')
|
|
2113
2112
|
const tail = updates
|
|
@@ -2128,7 +2127,7 @@ export function flushPendingWorkplanUpdates(session: any) {
|
|
|
2128
2127
|
flushingUpdateSessions.add(session)
|
|
2129
2128
|
try {
|
|
2130
2129
|
const appended = appendUserMessage(session, message)
|
|
2131
|
-
/* 只有真正落盘才清空缓冲:append
|
|
2130
|
+
/* 只有真正落盘才清空缓冲:append 抛错时保留缓冲,台账不静默消失。 */
|
|
2132
2131
|
if (pendingUpdateBuffers.get(session) === buffer) pendingUpdateBuffers.delete(session)
|
|
2133
2132
|
const timer = pendingUpdateTimers.get(session)
|
|
2134
2133
|
if (timer) {
|
|
@@ -2136,11 +2135,77 @@ export function flushPendingWorkplanUpdates(session: any) {
|
|
|
2136
2135
|
pendingUpdateTimers.delete(session)
|
|
2137
2136
|
}
|
|
2138
2137
|
return appended
|
|
2138
|
+
} catch (error) {
|
|
2139
|
+
/* [T3 写入失败限流] 同批缓冲首次失败:只记一次错误并置 failed 闩锁,此后
|
|
2140
|
+
* 周期重试(定时补发 / pre-step 合并 / 结算合并)一律跳过该批;缓冲收到新
|
|
2141
|
+
* 台账更新时 failed 复位,重试自动恢复。缓冲本体保留,不丢台账。 */
|
|
2142
|
+
buffer.failed = true
|
|
2143
|
+
console.warn(`[dsh-workplan] 进度归档合并落盘失败(该批 ${updates.length} 条台账已停止周期重试,新台账更新到来时自动恢复):${error instanceof Error ? error.message : String(error)}`)
|
|
2144
|
+
return undefined
|
|
2139
2145
|
} finally {
|
|
2140
2146
|
flushingUpdateSessions.delete(session)
|
|
2141
2147
|
}
|
|
2142
2148
|
}
|
|
2143
2149
|
|
|
2150
|
+
/**
|
|
2151
|
+
* [T2][治本·JSON 净化] 把任意进度数据递归净化为纯 JSON(可通过宿主
|
|
2152
|
+
* snapshotAppend / snapshotJsonValue 的 JSON.stringify+parse 往返校验)。
|
|
2153
|
+
* 语义约定(全部边界类型均有确定行为):
|
|
2154
|
+
* - 循环引用(WeakSet 检测)→ 占位字符串 "[Circular]"
|
|
2155
|
+
* - undefined / 函数 / symbol → 对象属性剔除该键;数组元素置 null
|
|
2156
|
+
* - NaN / ±Infinity → null
|
|
2157
|
+
* - Date → ISO 字符串
|
|
2158
|
+
* - Map → 普通对象(键转字符串);Set → 数组
|
|
2159
|
+
* - 其它对象递归净化自有可枚举属性
|
|
2160
|
+
* 纯 JSON 输入(仅 null/boolean/number有限值/string/array/object)经净化后语义不变。
|
|
2161
|
+
*/
|
|
2162
|
+
export function toJsonSafe(value: any, seen?: WeakSet<object>): any {
|
|
2163
|
+
if (value === null) return null
|
|
2164
|
+
const t = typeof value
|
|
2165
|
+
if (t === 'string' || t === 'boolean') return value
|
|
2166
|
+
if (t === 'number') return Number.isFinite(value) ? value : null
|
|
2167
|
+
if (t === 'undefined' || t === 'function' || t === 'symbol') return undefined
|
|
2168
|
+
if (t === 'bigint') return String(value)
|
|
2169
|
+
if (value instanceof Date) return value.toISOString()
|
|
2170
|
+
const set: WeakSet<object> = seen ?? new WeakSet<object>()
|
|
2171
|
+
if (set.has(value)) return '[Circular]'
|
|
2172
|
+
set.add(value)
|
|
2173
|
+
try {
|
|
2174
|
+
if (value instanceof Map) {
|
|
2175
|
+
const out: Record<string, any> = {}
|
|
2176
|
+
for (const [k, v] of value) {
|
|
2177
|
+
const sv = toJsonSafe(v, set)
|
|
2178
|
+
if (sv !== undefined) out[String(k)] = sv
|
|
2179
|
+
}
|
|
2180
|
+
return out
|
|
2181
|
+
}
|
|
2182
|
+
if (value instanceof Set) {
|
|
2183
|
+
const out: any[] = []
|
|
2184
|
+
for (const v of value) {
|
|
2185
|
+
const sv = toJsonSafe(v, set)
|
|
2186
|
+
out.push(sv === undefined ? null : sv)
|
|
2187
|
+
}
|
|
2188
|
+
return out
|
|
2189
|
+
}
|
|
2190
|
+
if (Array.isArray(value)) {
|
|
2191
|
+
const out: any[] = []
|
|
2192
|
+
for (const v of value) {
|
|
2193
|
+
const sv = toJsonSafe(v, set)
|
|
2194
|
+
out.push(sv === undefined ? null : sv)
|
|
2195
|
+
}
|
|
2196
|
+
return out
|
|
2197
|
+
}
|
|
2198
|
+
const out: Record<string, any> = {}
|
|
2199
|
+
for (const k of Object.keys(value)) {
|
|
2200
|
+
const sv = toJsonSafe(value[k], set)
|
|
2201
|
+
if (sv !== undefined) out[k] = sv
|
|
2202
|
+
}
|
|
2203
|
+
return out
|
|
2204
|
+
} finally {
|
|
2205
|
+
set.delete(value)
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2144
2209
|
export function appendUserMessage(session: any, payload: any, source?: any, opts?: { deferUntilHead?: boolean; allowBanned?: boolean }) {
|
|
2145
2210
|
if (!session || typeof session.append !== 'function') return undefined
|
|
2146
2211
|
let message = payload
|
|
@@ -2214,7 +2279,9 @@ export function appendUserMessage(session: any, payload: any, source?: any, opts
|
|
|
2214
2279
|
return undefined
|
|
2215
2280
|
}
|
|
2216
2281
|
flushPreHeadNotices(session)
|
|
2217
|
-
|
|
2282
|
+
/* [T2][治本] 写入前净化为纯 JSON:NaN/undefined/Date/Map/Set/循环引用等
|
|
2283
|
+
* 一律转为可序列化值,杜绝宿主 snapshotJsonValue 校验抛错导致的重试刷屏。 */
|
|
2284
|
+
return session.append('user/message', toJsonSafe(message), { surfaceOp: 'append' })
|
|
2218
2285
|
}
|
|
2219
2286
|
|
|
2220
2287
|
/*
|
|
@@ -2443,7 +2510,7 @@ export function buildDispatchPreAnnouncement(plan: any) {
|
|
|
2443
2510
|
const total = flattenSubtasks(plan).length
|
|
2444
2511
|
if (total === 0) return ''
|
|
2445
2512
|
const minutes = Math.max(1, estimatePlanMinutes(plan))
|
|
2446
|
-
return `【派发预告】本次分配 ${total} 个子任务,预计执行约 ${minutes} 分钟(口径:按各子任务 estimateMinutes
|
|
2513
|
+
return `【派发预告】本次分配 ${total} 个子任务,预计执行约 ${minutes} 分钟(口径:按各子任务 estimateMinutes 与并发度的下界估算。预估仅供参考,非承诺;实际时长以真实执行为准,不形成执行截止或完成验收门槛)。`
|
|
2447
2514
|
}
|
|
2448
2515
|
|
|
2449
2516
|
/**
|
|
@@ -2471,31 +2538,10 @@ export function buildPhaseZeroContinuationHint(effort: string, phaseZeroOutput:
|
|
|
2471
2538
|
}
|
|
2472
2539
|
|
|
2473
2540
|
export function buildBudgetWarning(plan: any, totalBudgetMinutes = 0, maxResumes = MAX_PLAN_RESUMES) {
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
* [2.2.0][T3/O-5b] 固定预算措辞改为「预估仅供参考,非承诺;实际时长协商
|
|
2479
|
-
* 决定」(方案 §2.6 #5 的目标措辞;O-5b 三处承诺禁令之一):预算提示只讲
|
|
2480
|
-
* 估算与轮次,不构成任何固定交付承诺。
|
|
2481
|
-
*
|
|
2482
|
-
* 标注行是输出的固定组成部分——预算内也返回(验收 E2「预算预告/计划消息
|
|
2483
|
-
* 把预估标注为仅供参考/非承诺」:凡 buildBudgetWarning 有输出必带该标注,
|
|
2484
|
-
* 计划消息经 warning 路径同享,不再按超预算与否吞掉)。
|
|
2485
|
-
*/
|
|
2486
|
-
const advisory = '(子任务 estimateMinutes 预估仅供参考,非承诺;判据层完成目标 ≤10 分钟,默认必须达成、超出须用户明确批准并留痕;运行层安全兜底由执行专家开工预告协商决定,不设固定交付期限、不构成对外承诺。)'
|
|
2487
|
-
// [2.2.5] 0 = 本轮不设固定总预算:只保留“预估仅供参考”的标注,不再输出
|
|
2488
|
-
// “超过本轮预算/需要 N 轮”的提示,避免与“不强制限制”的目标矛盾。
|
|
2489
|
-
if (budget === 0 || minutes <= budget) return advisory
|
|
2490
|
-
const rounds = Math.max(1, Math.ceil(minutes / budget))
|
|
2491
|
-
const missing = flattenSubtasks(plan).some((entry: any) => !Number.isFinite(Number(entry.subtask?.estimateMinutes)))
|
|
2492
|
-
return [
|
|
2493
|
-
`⚠ 预算提示:本计划 ${flattenSubtasks(plan).length} 项,按其估计约需 ${minutes} 分钟 > 本轮 ${budget} 分钟,`
|
|
2494
|
-
+ `预计需要约 ${rounds} 轮(续跑额度 ${maxResumes} 次)。`,
|
|
2495
|
-
advisory,
|
|
2496
|
-
'建议:拆成多轮,或减少同时进行的子任务。',
|
|
2497
|
-
...(missing ? ['(部分子任务缺少 estimateMinutes,已按运行层预算默认值每项 15 分钟估算。)'] : []),
|
|
2498
|
-
].join('\n')
|
|
2541
|
+
void plan
|
|
2542
|
+
void totalBudgetMinutes
|
|
2543
|
+
void maxResumes
|
|
2544
|
+
return '(子任务 estimateMinutes 预估仅供参考、非承诺,只用于协调与告知;部门负责人和全球顶尖专家执行没有时限,预估或实际耗时均不影响完成验收。)'
|
|
2499
2545
|
}
|
|
2500
2546
|
|
|
2501
2547
|
export function buildPlanMessage(plan: any, options: any = {}) {
|
|
@@ -2547,9 +2593,11 @@ export function buildPlanMessage(plan: any, options: any = {}) {
|
|
|
2547
2593
|
*/
|
|
2548
2594
|
options.planMode === true
|
|
2549
2595
|
? '下一步:当前处于 plan 模式,先把计划交给用户审阅;用户退出 plan 模式后,再调用 dsh_workplan_dispatch 执行。'
|
|
2550
|
-
: options.
|
|
2551
|
-
? '
|
|
2552
|
-
:
|
|
2596
|
+
: options.approvalHeld === true
|
|
2597
|
+
? '下一步:本计划处于「认可闸门」之下——任务要求先经用户认可再执行。在用户明确认可前不要派发(调用 dsh_workplan_dispatch 会被拒绝,也不会自动开跑);用户认可后,调用 dsh_workplan_release 解除闸门并开跑。'
|
|
2598
|
+
: options.autoDispatched === true
|
|
2599
|
+
? '下一步:计划已自动派发,部门 Agent 正在执行。不要重复调用 dsh_workplan_dispatch;用 dsh_workplan_status 查看进度,结果会在本轮结束时自动写入。'
|
|
2600
|
+
: '下一步:必须调用 dsh_workplan_dispatch 派发本计划;只展示计划而不派发,部门 Agent 不会启动。',
|
|
2553
2601
|
'',
|
|
2554
2602
|
PLAN_MARKER_BEGIN,
|
|
2555
2603
|
JSON.stringify(payload),
|
|
@@ -4124,6 +4172,11 @@ export function buildUpdateMessage(update: any) {
|
|
|
4124
4172
|
...(update.escalationSeq === undefined ? {} : { escalationSeq: update.escalationSeq }),
|
|
4125
4173
|
...(update.instruction === undefined ? {} : { instruction: update.instruction }),
|
|
4126
4174
|
...(update.instructionSeq === undefined ? {} : { instructionSeq: update.instructionSeq }),
|
|
4175
|
+
/*
|
|
4176
|
+
* [3.0.1] 死锁自愈:复活指示随 durable workplan-update 回放——重启后行上
|
|
4177
|
+
* 的 reviveInstruction 不丢,重建的子会话仍能收到这条指示。
|
|
4178
|
+
*/
|
|
4179
|
+
...(update.reviveInstruction === undefined ? {} : { reviveInstruction: update.reviveInstruction }),
|
|
4127
4180
|
/*
|
|
4128
4181
|
* [1.11.0] 指示回执提醒也要能回放(T10 N4)。
|
|
4129
4182
|
*
|
|
@@ -4156,6 +4209,13 @@ export function buildUpdateMessage(update: any) {
|
|
|
4156
4209
|
// 消毒抬升,刷新/重启后续跑读档放行(G1:写入与消费双侧接线)。
|
|
4157
4210
|
...(update.mainDeepThink === undefined ? {} : { mainDeepThink: update.mainDeepThink }),
|
|
4158
4211
|
...(update.mainDeepThinkPlanId === undefined ? {} : { mainDeepThinkPlanId: update.mainDeepThinkPlanId }),
|
|
4212
|
+
/*
|
|
4213
|
+
* [3.0.1] 认可闸门(计划级)随 durable workplan-update 回放:刷新/重启后
|
|
4214
|
+
* 「计划被按住、等用户认可」这条事实不丢,dispatch 门禁读档仍然生效;
|
|
4215
|
+
* gateHistory 是只增审计(release 追加),同一回放口径。
|
|
4216
|
+
*/
|
|
4217
|
+
...(update.dispatchHold === undefined ? {} : { dispatchHold: update.dispatchHold }),
|
|
4218
|
+
...(update.gateHistory === undefined ? {} : { gateHistory: update.gateHistory }),
|
|
4159
4219
|
...(update.delegates === undefined ? {} : { delegates: update.delegates }),
|
|
4160
4220
|
// [2.5.4][T3R1] 分派前深度梳理门禁审计(A3)随 durable workplan-update 回放:
|
|
4161
4221
|
// 拒绝/放行记录刷新/重启后仍可复核,与 consolidation 同一回放口径。
|
|
@@ -4523,6 +4583,26 @@ export function applyStatus(statuses: any, subtaskId: any, patch: any) {
|
|
|
4523
4583
|
if (patch.instructionSeq !== undefined) {
|
|
4524
4584
|
next.instructionSeq = Number.isInteger(Number(patch.instructionSeq)) ? Number(patch.instructionSeq) : null
|
|
4525
4585
|
}
|
|
4586
|
+
/*
|
|
4587
|
+
* [3.0.1] 死锁自愈留档:instruct 发现子会话失联时,指示不丢——登记为
|
|
4588
|
+
* reviveInstruction 随行持久化,下一次 dispatch 重建子会话时由
|
|
4589
|
+
* buildChildPrompt 带进新子提示词(与 instruction 同口径消毒;null 清除)。
|
|
4590
|
+
*/
|
|
4591
|
+
if (patch.reviveInstruction !== undefined) {
|
|
4592
|
+
if (patch.reviveInstruction === null) next.reviveInstruction = null
|
|
4593
|
+
else if (isRecord(patch.reviveInstruction)) {
|
|
4594
|
+
const text = truncate(String(patch.reviveInstruction.text ?? ''), MAX_INSTRUCTION_CHARS)
|
|
4595
|
+
if (!text) throw new PlanError('reviveInstruction.text 不能为空', 'INVALID_INSTRUCTION')
|
|
4596
|
+
next.reviveInstruction = {
|
|
4597
|
+
text,
|
|
4598
|
+
at: numberOrNull(patch.reviveInstruction.at) ?? Date.now(),
|
|
4599
|
+
by: ['agent', 'system', 'child'].includes(patch.reviveInstruction.by) ? patch.reviveInstruction.by : 'agent',
|
|
4600
|
+
reason: truncate(String(patch.reviveInstruction.reason ?? ''), 200) || null,
|
|
4601
|
+
}
|
|
4602
|
+
} else {
|
|
4603
|
+
throw new PlanError('reviveInstruction 必须是对象或 null', 'INVALID_INSTRUCTION')
|
|
4604
|
+
}
|
|
4605
|
+
}
|
|
4526
4606
|
if (patch.reportedAt !== undefined) next.reportedAt = numberOrNull(patch.reportedAt)
|
|
4527
4607
|
/*
|
|
4528
4608
|
* [2.2.0][T3/O-2c/O-3c] 柔性时长协商的留档字段(方案 §2.2/§2.4/§2.5)。
|
|
@@ -4545,7 +4625,7 @@ export function applyStatus(statuses: any, subtaskId: any, patch: any) {
|
|
|
4545
4625
|
else {
|
|
4546
4626
|
const value = Number(patch.timeoutMs)
|
|
4547
4627
|
if (!Number.isFinite(value) || value <= 0) {
|
|
4548
|
-
throw new PlanError('timeoutMs
|
|
4628
|
+
throw new PlanError('timeoutMs 必须是正数毫秒(历史字段;不会形成执行截止)', 'INVALID_TIMEOUT_MS')
|
|
4549
4629
|
}
|
|
4550
4630
|
next.timeoutMs = value
|
|
4551
4631
|
}
|
|
@@ -5502,12 +5582,6 @@ export function normaliseStatusEntry(entry: any): StatusEntry {
|
|
|
5502
5582
|
const criterionViolations = Array.isArray(source.criterionViolations)
|
|
5503
5583
|
? source.criterionViolations.filter((item: any) => item !== null && typeof item === 'object' && !Array.isArray(item)).slice(-20)
|
|
5504
5584
|
: null
|
|
5505
|
-
const exAnteForOver = leaderEstimate
|
|
5506
|
-
? { minutes: leaderEstimate.totalMinutes }
|
|
5507
|
-
: (source.timeNotice && Number.isFinite(Number(source.timeNotice.declaredMinutes))
|
|
5508
|
-
? { minutes: Number(source.timeNotice.declaredMinutes) }
|
|
5509
|
-
: null)
|
|
5510
|
-
const leaderEstimateOverCriterion = exAnteForOver !== null && exAnteForOver.minutes > CRITERION_TARGET_MINUTES
|
|
5511
5585
|
return {
|
|
5512
5586
|
...source,
|
|
5513
5587
|
subtaskId: stringOr(source.subtaskId, ''),
|
|
@@ -5535,7 +5609,8 @@ export function normaliseStatusEntry(entry: any): StatusEntry {
|
|
|
5535
5609
|
...(source.criterionException !== undefined ? { criterionException } : {}),
|
|
5536
5610
|
...(source.criterionViolations !== undefined ? { criterionViolations } : {}),
|
|
5537
5611
|
...(attemptWallClockMs !== null ? { attemptWallClockMs } : {}),
|
|
5538
|
-
|
|
5612
|
+
// 历史超判据标记不再作为当前事实传播;预估仅供协调。
|
|
5613
|
+
leaderEstimateOverCriterion: false,
|
|
5539
5614
|
}
|
|
5540
5615
|
}
|
|
5541
5616
|
|
|
@@ -6325,6 +6400,12 @@ export function buildChildPrompt({
|
|
|
6325
6400
|
conversationContext = '',
|
|
6326
6401
|
statuses = null,
|
|
6327
6402
|
previousFailure = null,
|
|
6403
|
+
/*
|
|
6404
|
+
* [3.0.1] 死锁自愈:该行此前升级待指示、子会话失联后由主 Agent 登记了
|
|
6405
|
+
* 复活指示(reviveInstruction)。重建子会话时必须把这条指示带进提示词,
|
|
6406
|
+
* 否则新子会话不知道主 Agent 已经拍板的决定,又会把同一个问题再请示一遍。
|
|
6407
|
+
*/
|
|
6408
|
+
reviveInstruction = null,
|
|
6328
6409
|
lessonsBrief = '',
|
|
6329
6410
|
/*
|
|
6330
6411
|
* [2.2.0][T3/O-2a] 子→主预告通道的目标。
|
|
@@ -6427,6 +6508,18 @@ export function buildChildPrompt({
|
|
|
6427
6508
|
'请针对上面这个原因调整做法,不要重复相同的失败路径;如果仍然无法完成,第一行输出 `BLOCKED: 原因` 并说明缺少什么。',
|
|
6428
6509
|
].join('\n')
|
|
6429
6510
|
: ''
|
|
6511
|
+
/*
|
|
6512
|
+
* [3.0.1] 复活指示块:先于一切任务描述给出主 Agent 已拍板的决定。
|
|
6513
|
+
* 这段来自主 Agent 对升级请示的答复(dsh_workplan_instruct),不是可选背景。
|
|
6514
|
+
*/
|
|
6515
|
+
const reviveBlock = reviveInstruction && typeof reviveInstruction === 'object' && reviveInstruction.text
|
|
6516
|
+
? [
|
|
6517
|
+
'',
|
|
6518
|
+
'【主 Agent 指示(针对你此前的请示,已拍板,直接照做)】',
|
|
6519
|
+
truncate(String(reviveInstruction.text), 2000),
|
|
6520
|
+
'你此前因该问题升级待指示;子会话重建后以上述指示为准,不要重复请示同一问题。',
|
|
6521
|
+
].join('\n')
|
|
6522
|
+
: ''
|
|
6430
6523
|
/*
|
|
6431
6524
|
* [1.8.19] A retried subtask must not pretend the prior attempt never existed.
|
|
6432
6525
|
*
|
|
@@ -6529,6 +6622,7 @@ export function buildChildPrompt({
|
|
|
6529
6622
|
...(resumeHint ? [resumeHint] : []),
|
|
6530
6623
|
...(phaseZeroContinuation ? [phaseZeroContinuation] : []),
|
|
6531
6624
|
...(pendingInstruction ? [pendingInstruction] : []),
|
|
6625
|
+
...(reviveBlock ? [reviveBlock] : []),
|
|
6532
6626
|
'',
|
|
6533
6627
|
...threePhasePromptLines(),
|
|
6534
6628
|
...(typeof lessonsBrief === 'string' && lessonsBrief.trim() !== ''
|
|
@@ -6573,28 +6667,17 @@ export function buildChildPrompt({
|
|
|
6573
6667
|
* 预告在目标解析阶段必然失败。现在改为:注入真实父会话 id + 用宿主
|
|
6574
6668
|
* 契约里的字段名 + 明确失败后的确定性重试与留痕,不再有「猜目标」的余地。
|
|
6575
6669
|
*/
|
|
6576
|
-
'
|
|
6670
|
+
'执行时间与进度沟通(部门负责人和全球顶尖专家均无执行硬截止):',
|
|
6577
6671
|
noticeTargetLine,
|
|
6578
|
-
`-
|
|
6579
|
-
|
|
6580
|
-
|
|
6672
|
+
`- 开工前先报预估时长:用 \`${noticeCall}\` 报预估完成时长,新预估覆盖旧预估;预估仅供参考、非承诺,只用于协调和告知,不累加为任何时间判据,也不影响验收。`,
|
|
6673
|
+
'- 发现预估明显变化时,用同一个目标更新预估并说明原因;无需申请延期,extendMs 已停用。平台不会仅因耗时、暂时无新事件或未及时回执而中止、判 blocked 或换人接手。',
|
|
6674
|
+
'- 完成即回报:用同一个目标报核心结论(做了什么、证据/文件、验收结果),不要等整轮结束;长任务应及时落盘并列出已完成路径。',
|
|
6581
6675
|
...(noticeTarget
|
|
6582
6676
|
? [
|
|
6583
6677
|
'- 失败后的确定性处理(禁止静默丢弃):`send_message` 若返回错误(`is unavailable` / `UNAUTHORIZED` / 工具不存在),先在汇报首行原样记录 `noticeChannel: {"target":"' + noticeTarget + '","at":<毫秒时间戳>,"error":"<错误原文>"}`,再用**同一个** agent_id 重试一次;仍失败就继续把子任务做完,把这条记录留在结果里(供主 Agent 阅读;插件不解析这一行,通道结论以状态行观测为准)。**不得改用其它目标,也不得向任何非本轮父会话发送**——那是越权发送,会触发宿主 lineage 拒绝。',
|
|
6584
6678
|
]
|
|
6585
6679
|
: []),
|
|
6586
|
-
|
|
6587
|
-
// [2.2.0][T6/O-1a] 完成即时通知条款(插件兜底通道):完成即报是第一通道(见上方「完成即回报」);插件另设兜底——子任务结算成功后立即向主会话推送一条含子任务 ID、摘要、验收计数与用时的即时通知,不等待整轮结束。兜底不替代主动回报。
|
|
6588
|
-
/*
|
|
6589
|
-
* [2.3.0][T1] 超时放宽告知与二次超时接手条款(用户 2026-11-10 要求 1/2):
|
|
6590
|
-
* 预告会由插件自动转告主 Agent「请把预期时间告知用户」;超时后主 Agent
|
|
6591
|
-
* 放宽时插件会把最新执行时限推送给你;连续两次超时改由主 Agent 接手,
|
|
6592
|
-
* 因此专家任何时候都要把已完成内容及时落盘并在回报中列路径——已完成部分
|
|
6593
|
-
* 会被登记为只读保护,禁止被丢弃。以下既有条款零删改。
|
|
6594
|
-
*/
|
|
6595
|
-
'- 预估上报会被插件即时转告主 Agent(含「请把此预期执行时间告知用户」提示),主 Agent 会把你报的预估时间告知用户,让双方都有准备。',
|
|
6596
|
-
'- 超时后主 Agent 放宽时,插件会向你的会话推送【延期告知】:内含最新执行时间与剩余余量,并要求你在保证工作质量的前提下高效率执行——收到通知继续当前工作,不要重新开始;已完成内容及时落盘。',
|
|
6597
|
-
'- 连续两次超时后本行转为「主 Agent 接手」(takeoverRequired):你已完成的产物会被登记为只读保护(禁止丢弃),主 Agent 只继续未完成部分;所以每个阶段都要及时落盘并在回报中列出已完成路径。',
|
|
6680
|
+
'- 预估上报会被插件即时转告主 Agent(含「请把此预期执行时间告知用户」提示),主 Agent 会把你报的预估时间告知用户,让双方都有准备;实际完成与否只由真实结果和验收证据决定。',
|
|
6598
6681
|
'',
|
|
6599
6682
|
'遇阻上报(强制,先于继续动作):',
|
|
6600
6683
|
'- 出现以下任一情况,第一动作是上报,不是猜测、绕过或静默继续:缺少权限/输入/依赖产物;需求自相矛盾;无法验证;同一命令连续两次失败;需要主 Agent 决定方向。',
|