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/lib/plan.js
CHANGED
|
@@ -8,9 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { createHash, randomUUID } from 'node:crypto';
|
|
10
10
|
import { DEPARTMENT_CAPABILITIES, DEPARTMENT_EXPERT_STANDARD, departmentCapability } from './departments.js';
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
import { CRITERION_TARGET_MINUTES, CRITERION_RESULTS, attemptWallClockMsOf, sanitizeCriterionException, } from './criterion.js';
|
|
11
|
+
// 历史判据字段只做读取消毒;不再派生或传播时间完成门槛。
|
|
12
|
+
import { CRITERION_RESULTS, attemptWallClockMsOf, sanitizeCriterionException, } from './criterion.js';
|
|
14
13
|
import { MAX_TASK_ANCHOR_CHARS } from './understanding.js';
|
|
15
14
|
import { isMappingDigest, verifyMappingDigest } from './supersede-digest.js';
|
|
16
15
|
import { phaseSummaryLine, sanitizeMainDeepThink, threePhasePromptLines, validatePhaseEvidence } from './three-phase.js';
|
|
@@ -758,7 +757,7 @@ function readSubtasks(value, stageIndex, errors) {
|
|
|
758
757
|
* estimateNeedsJustification 仅在触发时下发,旧计划载荷逐字不变)。
|
|
759
758
|
*/
|
|
760
759
|
if (source.splitReason !== undefined && source.splitReason !== null && typeof source.splitReason !== 'string') {
|
|
761
|
-
push(errors, `${base}.splitReason`, '
|
|
760
|
+
push(errors, `${base}.splitReason`, '必须是字符串(可选的历史拆分说明,缺失合法;与执行时限无关)');
|
|
762
761
|
}
|
|
763
762
|
const splitReasonText = typeof source.splitReason === 'string' ? source.splitReason.trim() : '';
|
|
764
763
|
let estimateConfirm = null;
|
|
@@ -780,10 +779,6 @@ function readSubtasks(value, stageIndex, errors) {
|
|
|
780
779
|
};
|
|
781
780
|
}
|
|
782
781
|
}
|
|
783
|
-
const estimateOverCriterion = estimateOk && estimateValue > CRITERION_TARGET_MINUTES;
|
|
784
|
-
const estimateNeedsJustification = estimateOverCriterion
|
|
785
|
-
&& splitReasonText === ''
|
|
786
|
-
&& !(estimateConfirm && estimateConfirm.confirmed === true);
|
|
787
782
|
/*
|
|
788
783
|
* [2.2.0][T3/O-3a] per-subtask 协商上限(timeoutMs,毫秒)可选透传。
|
|
789
784
|
*
|
|
@@ -800,7 +795,7 @@ function readSubtasks(value, stageIndex, errors) {
|
|
|
800
795
|
&& Number.isFinite(timeoutValue)
|
|
801
796
|
&& timeoutValue > 0;
|
|
802
797
|
if (hasTimeout && !timeoutOk) {
|
|
803
|
-
push(errors, `${base}.timeoutMs`, '
|
|
798
|
+
push(errors, `${base}.timeoutMs`, '必须是正数毫秒(旧计划的历史字段,可选;不会形成执行截止)');
|
|
804
799
|
}
|
|
805
800
|
/*
|
|
806
801
|
* [2.2.0][T13/推理等级] 子任务自带的推理等级(可选,仅 low / medium / high / xhigh / max)。
|
|
@@ -870,9 +865,7 @@ function readSubtasks(value, stageIndex, errors) {
|
|
|
870
865
|
* [1.7.0] 历史记录。
|
|
871
866
|
*/
|
|
872
867
|
...(estimateOk ? { estimateMinutes: estimateValue } : {}),
|
|
873
|
-
//
|
|
874
|
-
...(estimateOverCriterion ? { estimateOverCriterion: true } : {}),
|
|
875
|
-
...(estimateNeedsJustification ? { estimateNeedsJustification: true } : {}),
|
|
868
|
+
// splitReason / estimateConfirm 仅作历史兼容,不再派生任何时间判据或软门禁。
|
|
876
869
|
...(splitReasonText !== '' ? { splitReason: truncate(splitReasonText, 800) } : {}),
|
|
877
870
|
...(estimateConfirm ? { estimateConfirm } : {}),
|
|
878
871
|
...(timeoutOk ? { timeoutMs: timeoutValue } : {}),
|
|
@@ -1569,11 +1562,6 @@ export function buildPlannerPrompt(taskText, cwd, conversationContext = '', budg
|
|
|
1569
1562
|
const departments = DEPARTMENT_CAPABILITIES
|
|
1570
1563
|
.map((entry) => `- ${entry.id}(${entry.zh} / ${entry.en}):职责 ${entry.responsibilities.join(';')};典型产物 ${entry.outputs.join(';')}`)
|
|
1571
1564
|
.join('\n');
|
|
1572
|
-
const rawTotalMinutes = Number(budget?.totalMinutes);
|
|
1573
|
-
const totalMinutes = Number.isFinite(rawTotalMinutes) && rawTotalMinutes > 0
|
|
1574
|
-
? Math.max(1, Math.round(rawTotalMinutes))
|
|
1575
|
-
: 0;
|
|
1576
|
-
const childMinutes = Math.max(1, Math.round(Number(budget?.childMinutes) || 15));
|
|
1577
1565
|
const concurrency = Math.max(1, Number(budget?.concurrency) || MAX_CONCURRENT);
|
|
1578
1566
|
const resumes = Number.isFinite(Number(budget?.maxResumes)) ? Number(budget.maxResumes) : MAX_PLAN_RESUMES;
|
|
1579
1567
|
const task = truncate(taskText, 16000);
|
|
@@ -1607,28 +1595,24 @@ export function buildPlannerPrompt(taskText, cwd, conversationContext = '', budg
|
|
|
1607
1595
|
'- department 必须从下面的部门中选择一个;必须同时写 departmentRationale(1-2 句,引用该部门职责与任务要素),department 与 rationale 不一致的计划视为不合格。',
|
|
1608
1596
|
'- method、outputs、acceptance 必须是非空数组;inputs 可以为空,未知写“待确认”。',
|
|
1609
1597
|
'- unknowns 和 assumptions 必须如实列出;没有就写空数组,不能把假设写成事实。',
|
|
1610
|
-
'-
|
|
1598
|
+
'- 子任务必须可独立执行、可验收;按单一目标、单一主产物和清晰验收边界拆分,不得按分钟数强行切分,也不得为了凑数拆无意义任务。',
|
|
1611
1599
|
// [2.5.0] 用户要求 3:分解必须更简单。部门负责人拥有本部门内再分配权限
|
|
1612
1600
|
// (dsh_workplan_delegate),会把子任务再拆给多名顶尖专家与组员,因此
|
|
1613
1601
|
// 主计划层保持单一目标/单一主产物的简单子任务,执行细节下沉到部门内分工。
|
|
1614
|
-
'- 分解必须更简单(用户强制要求):每个子任务只写单一目标、单一主产物、可独立验收的一件事;不要把多个交付物压进同一个子任务。部门负责人接到子任务后,会用 dsh_workplan_delegate 把它再拆成更简单的单项工作,分配给本部门多名相关领域全球顶尖专家共同承担(部门组员角色已按用户要求 9
|
|
1602
|
+
'- 分解必须更简单(用户强制要求):每个子任务只写单一目标、单一主产物、可独立验收的一件事;不要把多个交付物压进同一个子任务。部门负责人接到子任务后,会用 dsh_workplan_delegate 把它再拆成更简单的单项工作,分配给本部门多名相关领域全球顶尖专家共同承担(部门组员角色已按用户要求 9 取消)——所以主计划子任务保持简单清晰即可,执行细节由部门内分工细化,不要越俎代庖替部门预拆全部细节。再分配只按工作边界与验收拆分;预估可汇总用于协调,但不设分钟上限,也不影响达标判定。',
|
|
1615
1603
|
'- 子任务由部门负责人子 Agent 牵头执行:负责人拥有本部门内的再分配权限(dsh_workplan_delegate,先 review 提交两轮深度思考产物后 dispatch 派给本部门专家(只保留 expert 角色)),但没有主计划派发权限、不能重启服务、不能安装或升级依赖。禁止把「调用 dsh_workplan_dispatch」「重启/停止 dsh web」「安装或升级插件」这类只有主 Agent 才能执行的动作写进子任务;确实需要时,写成“给出结论或建议,由主 Agent 执行”。',
|
|
1616
|
-
'-
|
|
1617
|
-
'- 运行层安全兜底(不是固定交付期限、不构成对外承诺,也不构成「允许慢」的许可):单次执行时限=clamp(estimateMinutes×2.0, 1 秒, 120 分钟),到点走安全兜底结算保证不丢产物;确需超过 10 分钟的唯一合法例外是用户明确批准并留痕(任务 ID、批准原文/来源、批准时间、放宽后分钟数、适用范围;无留痕=未批准);未获批准的超时不得以 done 收尾,记「判据违规(criterion-overrun)」并转新子任务续做。',
|
|
1618
|
-
'- 生效时点(不回溯):本判据自用户 2026-11-13 裁决(B/B/B/B/A/A/B)生效;运行态判定自补丁部署+用户重启+复核通过后新创建的计划起执行;此前已验收为 done 的历史任务与在途计划按旧规则,不重判、不重跑、不改验收结论。',
|
|
1604
|
+
'- 执行无时限:部门负责人和全球顶尖专家没有总时长、单次时长、空闲或回执硬截止;不要设置 timeoutMs,不要按分钟数拆任务,也不要把预估或实际耗时作为 done 的验收条件。用户显式取消、真实错误与证据/质量门禁仍须保留。',
|
|
1619
1605
|
// [2.3.2][D2-P2] 半角/逗号/括号自检硬约束:与解析层兜底(P0)互为防线,中文模型全角标点高发。
|
|
1620
1606
|
'- JSON 只允许半角标点(, : " { } [ ]);对象与数组的相邻成员之间必须有逗号;输出前自检括号成对、每个字符串以半角"闭合。',
|
|
1621
1607
|
'- 不要输出 Markdown 代码围栏、解释或前后缀;只输出一个 JSON 对象。',
|
|
1622
1608
|
'',
|
|
1623
|
-
'
|
|
1624
|
-
|
|
1625
|
-
? `- 一轮总预算约 ${totalMinutes} 分钟(运行层安全兜底,不是交付期限);判据层完成目标 ≤10 分钟;运行层规模参考 ${childMinutes} 分钟量级(仅供参考、非承诺,实际时长由执行专家开工预告协商决定),两个数字分属两层、不得混读;同时最多 ${concurrency} 个子任务并行。`
|
|
1626
|
-
: `- 本轮不设固定总预算;单个子任务按自身 estimateMinutes 与协商截止/延期执行;同时最多 ${concurrency} 个子任务并行。`,
|
|
1609
|
+
'本轮资源与执行方式:',
|
|
1610
|
+
`- 不设置整轮或单个子任务执行截止;estimateMinutes 只用于协调,不能派生 timeoutMs 或延期机制;同时最多 ${concurrency} 个子任务并行。`,
|
|
1627
1611
|
resumes > 0
|
|
1628
1612
|
? `- 受阻后自动续跑额度 ${resumes} 次;需要时计划会暂停并在下一轮继续。`
|
|
1629
1613
|
: '- 自动续跑额度为 0;计划不会因轮次预算被暂停。',
|
|
1630
1614
|
'- [3.0.0][用户要求 3/5] 每个子任务必须写 qualityRequirements(1-8 条字符串):这是主 Agent 派给部门负责人时随任务书一起下达的「结果质量要求」,写清成果必须达到什么要求、什么算合格。缺失质量要求的子任务在派发时会被系统直接拒发(DISPATCH_QUALITY_REQUIREMENTS_MISSING,不启动部门 Agent),必须 replan 补齐后重新派发。同时子任务必须是简单到 1+1=2 的单项工作:一个目标、一个主产物、一项可独立验收;不要在一个子任务里塞并列的多件事(出现「并且/同时/另外/还要/以及/分别/顺便」或多句并列时应拆成多个子任务)。',
|
|
1631
|
-
'- 每个子任务必须写 estimateMinutes(整数 1-240
|
|
1615
|
+
'- 每个子任务必须写 estimateMinutes(整数 1-240,如实预估):只用于安排协调与告知用户,仅供参考、非承诺;不会派生执行截止,不会因超过预估算超时,也不影响 done 验收。取值整数与范围校验仅防止离谱输入,缺失不报错。',
|
|
1632
1616
|
/*
|
|
1633
1617
|
* [2.2.0][T13/推理等级] 子 Agent 必须自决推理等级,禁止继承主 Agent。
|
|
1634
1618
|
* 用户规则原文见 plan.ts 顶部 REASONING_EFFORTS 注释;五档映射与五个示例
|
|
@@ -1821,7 +1805,7 @@ function flushPreHeadNotices(session) {
|
|
|
1821
1805
|
return;
|
|
1822
1806
|
preHeadNoticeQueue.delete(session);
|
|
1823
1807
|
for (const message of queue)
|
|
1824
|
-
session.append('user/message', message, { surfaceOp: 'append' });
|
|
1808
|
+
session.append('user/message', toJsonSafe(message), { surfaceOp: 'append' });
|
|
1825
1809
|
}
|
|
1826
1810
|
/*
|
|
1827
1811
|
* [2.5.5][治本] 头落地自动补发保险丝:旧实现只在「下一次 appendUserMessage」
|
|
@@ -1941,6 +1925,10 @@ const DURABLE_ENVELOPE_KINDS = new Set([
|
|
|
1941
1925
|
* - 本轮结算 finishRound 之前。
|
|
1942
1926
|
* 回放侧 parseUpdateMessages 把汇总消息里的 updates 数组按序逐条返回,语义与
|
|
1943
1927
|
* 逐条落盘完全等价(reconstructFromSession 仍是唯一的应用者)。
|
|
1928
|
+
*
|
|
1929
|
+
* [T3 写入失败限流] 合并落盘失败的重试策略:同批缓冲首次失败只记一次错误
|
|
1930
|
+
* (failed 闩锁),此后所有周期重试时机一律跳过该批,避免错误刷屏与无效重试;
|
|
1931
|
+
* 该批缓冲收到新台账更新时闩锁自动复位,重试恢复(缓冲本体始终保留,不丢台账)。
|
|
1944
1932
|
*/
|
|
1945
1933
|
export const PENDING_UPDATE_COUNT_LIMIT = 100;
|
|
1946
1934
|
export const PENDING_UPDATE_SIZE_LIMIT = 200_000;
|
|
@@ -1995,6 +1983,9 @@ function tryBufferWorkplanUpdate(session, message) {
|
|
|
1995
1983
|
if (!buffer.planId && typeof durable.planId === 'string')
|
|
1996
1984
|
buffer.planId = durable.planId;
|
|
1997
1985
|
buffer.updates.push(durable);
|
|
1986
|
+
/* [T3 写入失败限流] 新台账更新到来即恢复该批的重试资格(此前可能因首次落盘
|
|
1987
|
+
* 失败而被限流停掉)。 */
|
|
1988
|
+
buffer.failed = false;
|
|
1998
1989
|
try {
|
|
1999
1990
|
buffer.size += JSON.stringify(durable).length;
|
|
2000
1991
|
}
|
|
@@ -2023,6 +2014,10 @@ export function flushPendingWorkplanUpdates(session) {
|
|
|
2023
2014
|
const buffer = pendingUpdateBuffers.get(session);
|
|
2024
2015
|
if (!buffer || buffer.updates.length === 0)
|
|
2025
2016
|
return undefined;
|
|
2017
|
+
/* [T3 写入失败限流] 同批缓冲首次落盘失败后已记录一次错误并停止周期重试:
|
|
2018
|
+
* 这里直接跳过,下一次 tryBufferWorkplanUpdate 收到新更新会复位 failed。 */
|
|
2019
|
+
if (buffer.failed)
|
|
2020
|
+
return undefined;
|
|
2026
2021
|
const updates = buffer.updates;
|
|
2027
2022
|
const planId = buffer.planId || (typeof updates[updates.length - 1]?.planId === 'string' ? updates[updates.length - 1].planId : '');
|
|
2028
2023
|
const tail = updates
|
|
@@ -2044,7 +2039,7 @@ export function flushPendingWorkplanUpdates(session) {
|
|
|
2044
2039
|
flushingUpdateSessions.add(session);
|
|
2045
2040
|
try {
|
|
2046
2041
|
const appended = appendUserMessage(session, message);
|
|
2047
|
-
/* 只有真正落盘才清空缓冲:append
|
|
2042
|
+
/* 只有真正落盘才清空缓冲:append 抛错时保留缓冲,台账不静默消失。 */
|
|
2048
2043
|
if (pendingUpdateBuffers.get(session) === buffer)
|
|
2049
2044
|
pendingUpdateBuffers.delete(session);
|
|
2050
2045
|
const timer = pendingUpdateTimers.get(session);
|
|
@@ -2054,10 +2049,86 @@ export function flushPendingWorkplanUpdates(session) {
|
|
|
2054
2049
|
}
|
|
2055
2050
|
return appended;
|
|
2056
2051
|
}
|
|
2052
|
+
catch (error) {
|
|
2053
|
+
/* [T3 写入失败限流] 同批缓冲首次失败:只记一次错误并置 failed 闩锁,此后
|
|
2054
|
+
* 周期重试(定时补发 / pre-step 合并 / 结算合并)一律跳过该批;缓冲收到新
|
|
2055
|
+
* 台账更新时 failed 复位,重试自动恢复。缓冲本体保留,不丢台账。 */
|
|
2056
|
+
buffer.failed = true;
|
|
2057
|
+
console.warn(`[dsh-workplan] 进度归档合并落盘失败(该批 ${updates.length} 条台账已停止周期重试,新台账更新到来时自动恢复):${error instanceof Error ? error.message : String(error)}`);
|
|
2058
|
+
return undefined;
|
|
2059
|
+
}
|
|
2057
2060
|
finally {
|
|
2058
2061
|
flushingUpdateSessions.delete(session);
|
|
2059
2062
|
}
|
|
2060
2063
|
}
|
|
2064
|
+
/**
|
|
2065
|
+
* [T2][治本·JSON 净化] 把任意进度数据递归净化为纯 JSON(可通过宿主
|
|
2066
|
+
* snapshotAppend / snapshotJsonValue 的 JSON.stringify+parse 往返校验)。
|
|
2067
|
+
* 语义约定(全部边界类型均有确定行为):
|
|
2068
|
+
* - 循环引用(WeakSet 检测)→ 占位字符串 "[Circular]"
|
|
2069
|
+
* - undefined / 函数 / symbol → 对象属性剔除该键;数组元素置 null
|
|
2070
|
+
* - NaN / ±Infinity → null
|
|
2071
|
+
* - Date → ISO 字符串
|
|
2072
|
+
* - Map → 普通对象(键转字符串);Set → 数组
|
|
2073
|
+
* - 其它对象递归净化自有可枚举属性
|
|
2074
|
+
* 纯 JSON 输入(仅 null/boolean/number有限值/string/array/object)经净化后语义不变。
|
|
2075
|
+
*/
|
|
2076
|
+
export function toJsonSafe(value, seen) {
|
|
2077
|
+
if (value === null)
|
|
2078
|
+
return null;
|
|
2079
|
+
const t = typeof value;
|
|
2080
|
+
if (t === 'string' || t === 'boolean')
|
|
2081
|
+
return value;
|
|
2082
|
+
if (t === 'number')
|
|
2083
|
+
return Number.isFinite(value) ? value : null;
|
|
2084
|
+
if (t === 'undefined' || t === 'function' || t === 'symbol')
|
|
2085
|
+
return undefined;
|
|
2086
|
+
if (t === 'bigint')
|
|
2087
|
+
return String(value);
|
|
2088
|
+
if (value instanceof Date)
|
|
2089
|
+
return value.toISOString();
|
|
2090
|
+
const set = seen ?? new WeakSet();
|
|
2091
|
+
if (set.has(value))
|
|
2092
|
+
return '[Circular]';
|
|
2093
|
+
set.add(value);
|
|
2094
|
+
try {
|
|
2095
|
+
if (value instanceof Map) {
|
|
2096
|
+
const out = {};
|
|
2097
|
+
for (const [k, v] of value) {
|
|
2098
|
+
const sv = toJsonSafe(v, set);
|
|
2099
|
+
if (sv !== undefined)
|
|
2100
|
+
out[String(k)] = sv;
|
|
2101
|
+
}
|
|
2102
|
+
return out;
|
|
2103
|
+
}
|
|
2104
|
+
if (value instanceof Set) {
|
|
2105
|
+
const out = [];
|
|
2106
|
+
for (const v of value) {
|
|
2107
|
+
const sv = toJsonSafe(v, set);
|
|
2108
|
+
out.push(sv === undefined ? null : sv);
|
|
2109
|
+
}
|
|
2110
|
+
return out;
|
|
2111
|
+
}
|
|
2112
|
+
if (Array.isArray(value)) {
|
|
2113
|
+
const out = [];
|
|
2114
|
+
for (const v of value) {
|
|
2115
|
+
const sv = toJsonSafe(v, set);
|
|
2116
|
+
out.push(sv === undefined ? null : sv);
|
|
2117
|
+
}
|
|
2118
|
+
return out;
|
|
2119
|
+
}
|
|
2120
|
+
const out = {};
|
|
2121
|
+
for (const k of Object.keys(value)) {
|
|
2122
|
+
const sv = toJsonSafe(value[k], set);
|
|
2123
|
+
if (sv !== undefined)
|
|
2124
|
+
out[k] = sv;
|
|
2125
|
+
}
|
|
2126
|
+
return out;
|
|
2127
|
+
}
|
|
2128
|
+
finally {
|
|
2129
|
+
set.delete(value);
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2061
2132
|
export function appendUserMessage(session, payload, source, opts) {
|
|
2062
2133
|
if (!session || typeof session.append !== 'function')
|
|
2063
2134
|
return undefined;
|
|
@@ -2138,7 +2209,9 @@ export function appendUserMessage(session, payload, source, opts) {
|
|
|
2138
2209
|
return undefined;
|
|
2139
2210
|
}
|
|
2140
2211
|
flushPreHeadNotices(session);
|
|
2141
|
-
|
|
2212
|
+
/* [T2][治本] 写入前净化为纯 JSON:NaN/undefined/Date/Map/Set/循环引用等
|
|
2213
|
+
* 一律转为可序列化值,杜绝宿主 snapshotJsonValue 校验抛错导致的重试刷屏。 */
|
|
2214
|
+
return session.append('user/message', toJsonSafe(message), { surfaceOp: 'append' });
|
|
2142
2215
|
}
|
|
2143
2216
|
/*
|
|
2144
2217
|
* [2.2.5][T5] 分解期间进度文案与回报器(T3 交互规范 §3 C2/C3、§4 频率规则)。
|
|
@@ -2346,7 +2419,7 @@ export function buildDispatchPreAnnouncement(plan) {
|
|
|
2346
2419
|
if (total === 0)
|
|
2347
2420
|
return '';
|
|
2348
2421
|
const minutes = Math.max(1, estimatePlanMinutes(plan));
|
|
2349
|
-
return `【派发预告】本次分配 ${total} 个子任务,预计执行约 ${minutes} 分钟(口径:按各子任务 estimateMinutes
|
|
2422
|
+
return `【派发预告】本次分配 ${total} 个子任务,预计执行约 ${minutes} 分钟(口径:按各子任务 estimateMinutes 与并发度的下界估算。预估仅供参考,非承诺;实际时长以真实执行为准,不形成执行截止或完成验收门槛)。`;
|
|
2350
2423
|
}
|
|
2351
2424
|
/**
|
|
2352
2425
|
* [2.5.0][自配档] phase-0 任务书(负责人):唯一职责=评估复杂度+提交自配。
|
|
@@ -2371,32 +2444,10 @@ export function buildPhaseZeroContinuationHint(effort, phaseZeroOutput, lowDirec
|
|
|
2371
2444
|
return `【phase-0→phase-1 接续——继续勿重做】你已在 phase-0 完成复杂度评估并配置整体推理等级 \`${effort}\`(effortOverride 已登记,重试/续跑全程生效)。平台已按你的自配档接续本会话;phase-0 输出:${truncate(String(phaseZeroOutput ?? ''), 600) || '(无)'}。${nextStep},不要重新评估复杂度,不要重做 phase-0 已完成的工作。`;
|
|
2372
2445
|
}
|
|
2373
2446
|
export function buildBudgetWarning(plan, totalBudgetMinutes = 0, maxResumes = MAX_PLAN_RESUMES) {
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
* [2.2.0][T3/O-5b] 固定预算措辞改为「预估仅供参考,非承诺;实际时长协商
|
|
2379
|
-
* 决定」(方案 §2.6 #5 的目标措辞;O-5b 三处承诺禁令之一):预算提示只讲
|
|
2380
|
-
* 估算与轮次,不构成任何固定交付承诺。
|
|
2381
|
-
*
|
|
2382
|
-
* 标注行是输出的固定组成部分——预算内也返回(验收 E2「预算预告/计划消息
|
|
2383
|
-
* 把预估标注为仅供参考/非承诺」:凡 buildBudgetWarning 有输出必带该标注,
|
|
2384
|
-
* 计划消息经 warning 路径同享,不再按超预算与否吞掉)。
|
|
2385
|
-
*/
|
|
2386
|
-
const advisory = '(子任务 estimateMinutes 预估仅供参考,非承诺;判据层完成目标 ≤10 分钟,默认必须达成、超出须用户明确批准并留痕;运行层安全兜底由执行专家开工预告协商决定,不设固定交付期限、不构成对外承诺。)';
|
|
2387
|
-
// [2.2.5] 0 = 本轮不设固定总预算:只保留“预估仅供参考”的标注,不再输出
|
|
2388
|
-
// “超过本轮预算/需要 N 轮”的提示,避免与“不强制限制”的目标矛盾。
|
|
2389
|
-
if (budget === 0 || minutes <= budget)
|
|
2390
|
-
return advisory;
|
|
2391
|
-
const rounds = Math.max(1, Math.ceil(minutes / budget));
|
|
2392
|
-
const missing = flattenSubtasks(plan).some((entry) => !Number.isFinite(Number(entry.subtask?.estimateMinutes)));
|
|
2393
|
-
return [
|
|
2394
|
-
`⚠ 预算提示:本计划 ${flattenSubtasks(plan).length} 项,按其估计约需 ${minutes} 分钟 > 本轮 ${budget} 分钟,`
|
|
2395
|
-
+ `预计需要约 ${rounds} 轮(续跑额度 ${maxResumes} 次)。`,
|
|
2396
|
-
advisory,
|
|
2397
|
-
'建议:拆成多轮,或减少同时进行的子任务。',
|
|
2398
|
-
...(missing ? ['(部分子任务缺少 estimateMinutes,已按运行层预算默认值每项 15 分钟估算。)'] : []),
|
|
2399
|
-
].join('\n');
|
|
2447
|
+
void plan;
|
|
2448
|
+
void totalBudgetMinutes;
|
|
2449
|
+
void maxResumes;
|
|
2450
|
+
return '(子任务 estimateMinutes 预估仅供参考、非承诺,只用于协调与告知;部门负责人和全球顶尖专家执行没有时限,预估或实际耗时均不影响完成验收。)';
|
|
2400
2451
|
}
|
|
2401
2452
|
export function buildPlanMessage(plan, options = {}) {
|
|
2402
2453
|
const summary = buildPlanSummary(plan);
|
|
@@ -2443,9 +2494,11 @@ export function buildPlanMessage(plan, options = {}) {
|
|
|
2443
2494
|
*/
|
|
2444
2495
|
options.planMode === true
|
|
2445
2496
|
? '下一步:当前处于 plan 模式,先把计划交给用户审阅;用户退出 plan 模式后,再调用 dsh_workplan_dispatch 执行。'
|
|
2446
|
-
: options.
|
|
2447
|
-
? '
|
|
2448
|
-
:
|
|
2497
|
+
: options.approvalHeld === true
|
|
2498
|
+
? '下一步:本计划处于「认可闸门」之下——任务要求先经用户认可再执行。在用户明确认可前不要派发(调用 dsh_workplan_dispatch 会被拒绝,也不会自动开跑);用户认可后,调用 dsh_workplan_release 解除闸门并开跑。'
|
|
2499
|
+
: options.autoDispatched === true
|
|
2500
|
+
? '下一步:计划已自动派发,部门 Agent 正在执行。不要重复调用 dsh_workplan_dispatch;用 dsh_workplan_status 查看进度,结果会在本轮结束时自动写入。'
|
|
2501
|
+
: '下一步:必须调用 dsh_workplan_dispatch 派发本计划;只展示计划而不派发,部门 Agent 不会启动。',
|
|
2449
2502
|
'',
|
|
2450
2503
|
PLAN_MARKER_BEGIN,
|
|
2451
2504
|
JSON.stringify(payload),
|
|
@@ -3999,6 +4052,11 @@ export function buildUpdateMessage(update) {
|
|
|
3999
4052
|
...(update.escalationSeq === undefined ? {} : { escalationSeq: update.escalationSeq }),
|
|
4000
4053
|
...(update.instruction === undefined ? {} : { instruction: update.instruction }),
|
|
4001
4054
|
...(update.instructionSeq === undefined ? {} : { instructionSeq: update.instructionSeq }),
|
|
4055
|
+
/*
|
|
4056
|
+
* [3.0.1] 死锁自愈:复活指示随 durable workplan-update 回放——重启后行上
|
|
4057
|
+
* 的 reviveInstruction 不丢,重建的子会话仍能收到这条指示。
|
|
4058
|
+
*/
|
|
4059
|
+
...(update.reviveInstruction === undefined ? {} : { reviveInstruction: update.reviveInstruction }),
|
|
4002
4060
|
/*
|
|
4003
4061
|
* [1.11.0] 指示回执提醒也要能回放(T10 N4)。
|
|
4004
4062
|
*
|
|
@@ -4031,6 +4089,13 @@ export function buildUpdateMessage(update) {
|
|
|
4031
4089
|
// 消毒抬升,刷新/重启后续跑读档放行(G1:写入与消费双侧接线)。
|
|
4032
4090
|
...(update.mainDeepThink === undefined ? {} : { mainDeepThink: update.mainDeepThink }),
|
|
4033
4091
|
...(update.mainDeepThinkPlanId === undefined ? {} : { mainDeepThinkPlanId: update.mainDeepThinkPlanId }),
|
|
4092
|
+
/*
|
|
4093
|
+
* [3.0.1] 认可闸门(计划级)随 durable workplan-update 回放:刷新/重启后
|
|
4094
|
+
* 「计划被按住、等用户认可」这条事实不丢,dispatch 门禁读档仍然生效;
|
|
4095
|
+
* gateHistory 是只增审计(release 追加),同一回放口径。
|
|
4096
|
+
*/
|
|
4097
|
+
...(update.dispatchHold === undefined ? {} : { dispatchHold: update.dispatchHold }),
|
|
4098
|
+
...(update.gateHistory === undefined ? {} : { gateHistory: update.gateHistory }),
|
|
4034
4099
|
...(update.delegates === undefined ? {} : { delegates: update.delegates }),
|
|
4035
4100
|
// [2.5.4][T3R1] 分派前深度梳理门禁审计(A3)随 durable workplan-update 回放:
|
|
4036
4101
|
// 拒绝/放行记录刷新/重启后仍可复核,与 consolidation 同一回放口径。
|
|
@@ -4418,6 +4483,29 @@ export function applyStatus(statuses, subtaskId, patch) {
|
|
|
4418
4483
|
if (patch.instructionSeq !== undefined) {
|
|
4419
4484
|
next.instructionSeq = Number.isInteger(Number(patch.instructionSeq)) ? Number(patch.instructionSeq) : null;
|
|
4420
4485
|
}
|
|
4486
|
+
/*
|
|
4487
|
+
* [3.0.1] 死锁自愈留档:instruct 发现子会话失联时,指示不丢——登记为
|
|
4488
|
+
* reviveInstruction 随行持久化,下一次 dispatch 重建子会话时由
|
|
4489
|
+
* buildChildPrompt 带进新子提示词(与 instruction 同口径消毒;null 清除)。
|
|
4490
|
+
*/
|
|
4491
|
+
if (patch.reviveInstruction !== undefined) {
|
|
4492
|
+
if (patch.reviveInstruction === null)
|
|
4493
|
+
next.reviveInstruction = null;
|
|
4494
|
+
else if (isRecord(patch.reviveInstruction)) {
|
|
4495
|
+
const text = truncate(String(patch.reviveInstruction.text ?? ''), MAX_INSTRUCTION_CHARS);
|
|
4496
|
+
if (!text)
|
|
4497
|
+
throw new PlanError('reviveInstruction.text 不能为空', 'INVALID_INSTRUCTION');
|
|
4498
|
+
next.reviveInstruction = {
|
|
4499
|
+
text,
|
|
4500
|
+
at: numberOrNull(patch.reviveInstruction.at) ?? Date.now(),
|
|
4501
|
+
by: ['agent', 'system', 'child'].includes(patch.reviveInstruction.by) ? patch.reviveInstruction.by : 'agent',
|
|
4502
|
+
reason: truncate(String(patch.reviveInstruction.reason ?? ''), 200) || null,
|
|
4503
|
+
};
|
|
4504
|
+
}
|
|
4505
|
+
else {
|
|
4506
|
+
throw new PlanError('reviveInstruction 必须是对象或 null', 'INVALID_INSTRUCTION');
|
|
4507
|
+
}
|
|
4508
|
+
}
|
|
4421
4509
|
if (patch.reportedAt !== undefined)
|
|
4422
4510
|
next.reportedAt = numberOrNull(patch.reportedAt);
|
|
4423
4511
|
/*
|
|
@@ -4442,7 +4530,7 @@ export function applyStatus(statuses, subtaskId, patch) {
|
|
|
4442
4530
|
else {
|
|
4443
4531
|
const value = Number(patch.timeoutMs);
|
|
4444
4532
|
if (!Number.isFinite(value) || value <= 0) {
|
|
4445
|
-
throw new PlanError('timeoutMs
|
|
4533
|
+
throw new PlanError('timeoutMs 必须是正数毫秒(历史字段;不会形成执行截止)', 'INVALID_TIMEOUT_MS');
|
|
4446
4534
|
}
|
|
4447
4535
|
next.timeoutMs = value;
|
|
4448
4536
|
}
|
|
@@ -5370,12 +5458,6 @@ export function normaliseStatusEntry(entry) {
|
|
|
5370
5458
|
const criterionViolations = Array.isArray(source.criterionViolations)
|
|
5371
5459
|
? source.criterionViolations.filter((item) => item !== null && typeof item === 'object' && !Array.isArray(item)).slice(-20)
|
|
5372
5460
|
: null;
|
|
5373
|
-
const exAnteForOver = leaderEstimate
|
|
5374
|
-
? { minutes: leaderEstimate.totalMinutes }
|
|
5375
|
-
: (source.timeNotice && Number.isFinite(Number(source.timeNotice.declaredMinutes))
|
|
5376
|
-
? { minutes: Number(source.timeNotice.declaredMinutes) }
|
|
5377
|
-
: null);
|
|
5378
|
-
const leaderEstimateOverCriterion = exAnteForOver !== null && exAnteForOver.minutes > CRITERION_TARGET_MINUTES;
|
|
5379
5461
|
return {
|
|
5380
5462
|
...source,
|
|
5381
5463
|
subtaskId: stringOr(source.subtaskId, ''),
|
|
@@ -5403,7 +5485,8 @@ export function normaliseStatusEntry(entry) {
|
|
|
5403
5485
|
...(source.criterionException !== undefined ? { criterionException } : {}),
|
|
5404
5486
|
...(source.criterionViolations !== undefined ? { criterionViolations } : {}),
|
|
5405
5487
|
...(attemptWallClockMs !== null ? { attemptWallClockMs } : {}),
|
|
5406
|
-
|
|
5488
|
+
// 历史超判据标记不再作为当前事实传播;预估仅供协调。
|
|
5489
|
+
leaderEstimateOverCriterion: false,
|
|
5407
5490
|
};
|
|
5408
5491
|
}
|
|
5409
5492
|
/**
|
|
@@ -6185,7 +6268,13 @@ export function findSubtask(plan, subtaskId) {
|
|
|
6185
6268
|
}
|
|
6186
6269
|
return null;
|
|
6187
6270
|
}
|
|
6188
|
-
export function buildChildPrompt({ plan, subtask, stage, dependencyResults, cwd, conversationContext = '', statuses = null, previousFailure = null,
|
|
6271
|
+
export function buildChildPrompt({ plan, subtask, stage, dependencyResults, cwd, conversationContext = '', statuses = null, previousFailure = null,
|
|
6272
|
+
/*
|
|
6273
|
+
* [3.0.1] 死锁自愈:该行此前升级待指示、子会话失联后由主 Agent 登记了
|
|
6274
|
+
* 复活指示(reviveInstruction)。重建子会话时必须把这条指示带进提示词,
|
|
6275
|
+
* 否则新子会话不知道主 Agent 已经拍板的决定,又会把同一个问题再请示一遍。
|
|
6276
|
+
*/
|
|
6277
|
+
reviveInstruction = null, lessonsBrief = '',
|
|
6189
6278
|
/*
|
|
6190
6279
|
* [2.2.0][T3/O-2a] 子→主预告通道的目标。
|
|
6191
6280
|
*
|
|
@@ -6282,6 +6371,18 @@ phaseZeroContinuation = '', }) {
|
|
|
6282
6371
|
'请针对上面这个原因调整做法,不要重复相同的失败路径;如果仍然无法完成,第一行输出 `BLOCKED: 原因` 并说明缺少什么。',
|
|
6283
6372
|
].join('\n')
|
|
6284
6373
|
: '';
|
|
6374
|
+
/*
|
|
6375
|
+
* [3.0.1] 复活指示块:先于一切任务描述给出主 Agent 已拍板的决定。
|
|
6376
|
+
* 这段来自主 Agent 对升级请示的答复(dsh_workplan_instruct),不是可选背景。
|
|
6377
|
+
*/
|
|
6378
|
+
const reviveBlock = reviveInstruction && typeof reviveInstruction === 'object' && reviveInstruction.text
|
|
6379
|
+
? [
|
|
6380
|
+
'',
|
|
6381
|
+
'【主 Agent 指示(针对你此前的请示,已拍板,直接照做)】',
|
|
6382
|
+
truncate(String(reviveInstruction.text), 2000),
|
|
6383
|
+
'你此前因该问题升级待指示;子会话重建后以上述指示为准,不要重复请示同一问题。',
|
|
6384
|
+
].join('\n')
|
|
6385
|
+
: '';
|
|
6285
6386
|
/*
|
|
6286
6387
|
* [1.8.19] A retried subtask must not pretend the prior attempt never existed.
|
|
6287
6388
|
*
|
|
@@ -6382,6 +6483,7 @@ phaseZeroContinuation = '', }) {
|
|
|
6382
6483
|
...(resumeHint ? [resumeHint] : []),
|
|
6383
6484
|
...(phaseZeroContinuation ? [phaseZeroContinuation] : []),
|
|
6384
6485
|
...(pendingInstruction ? [pendingInstruction] : []),
|
|
6486
|
+
...(reviveBlock ? [reviveBlock] : []),
|
|
6385
6487
|
'',
|
|
6386
6488
|
...threePhasePromptLines(),
|
|
6387
6489
|
...(typeof lessonsBrief === 'string' && lessonsBrief.trim() !== ''
|
|
@@ -6426,28 +6528,17 @@ phaseZeroContinuation = '', }) {
|
|
|
6426
6528
|
* 预告在目标解析阶段必然失败。现在改为:注入真实父会话 id + 用宿主
|
|
6427
6529
|
* 契约里的字段名 + 明确失败后的确定性重试与留痕,不再有「猜目标」的余地。
|
|
6428
6530
|
*/
|
|
6429
|
-
'
|
|
6531
|
+
'执行时间与进度沟通(部门负责人和全球顶尖专家均无执行硬截止):',
|
|
6430
6532
|
noticeTargetLine,
|
|
6431
|
-
`-
|
|
6432
|
-
|
|
6433
|
-
|
|
6533
|
+
`- 开工前先报预估时长:用 \`${noticeCall}\` 报预估完成时长,新预估覆盖旧预估;预估仅供参考、非承诺,只用于协调和告知,不累加为任何时间判据,也不影响验收。`,
|
|
6534
|
+
'- 发现预估明显变化时,用同一个目标更新预估并说明原因;无需申请延期,extendMs 已停用。平台不会仅因耗时、暂时无新事件或未及时回执而中止、判 blocked 或换人接手。',
|
|
6535
|
+
'- 完成即回报:用同一个目标报核心结论(做了什么、证据/文件、验收结果),不要等整轮结束;长任务应及时落盘并列出已完成路径。',
|
|
6434
6536
|
...(noticeTarget
|
|
6435
6537
|
? [
|
|
6436
6538
|
'- 失败后的确定性处理(禁止静默丢弃):`send_message` 若返回错误(`is unavailable` / `UNAUTHORIZED` / 工具不存在),先在汇报首行原样记录 `noticeChannel: {"target":"' + noticeTarget + '","at":<毫秒时间戳>,"error":"<错误原文>"}`,再用**同一个** agent_id 重试一次;仍失败就继续把子任务做完,把这条记录留在结果里(供主 Agent 阅读;插件不解析这一行,通道结论以状态行观测为准)。**不得改用其它目标,也不得向任何非本轮父会话发送**——那是越权发送,会触发宿主 lineage 拒绝。',
|
|
6437
6539
|
]
|
|
6438
6540
|
: []),
|
|
6439
|
-
|
|
6440
|
-
// [2.2.0][T6/O-1a] 完成即时通知条款(插件兜底通道):完成即报是第一通道(见上方「完成即回报」);插件另设兜底——子任务结算成功后立即向主会话推送一条含子任务 ID、摘要、验收计数与用时的即时通知,不等待整轮结束。兜底不替代主动回报。
|
|
6441
|
-
/*
|
|
6442
|
-
* [2.3.0][T1] 超时放宽告知与二次超时接手条款(用户 2026-11-10 要求 1/2):
|
|
6443
|
-
* 预告会由插件自动转告主 Agent「请把预期时间告知用户」;超时后主 Agent
|
|
6444
|
-
* 放宽时插件会把最新执行时限推送给你;连续两次超时改由主 Agent 接手,
|
|
6445
|
-
* 因此专家任何时候都要把已完成内容及时落盘并在回报中列路径——已完成部分
|
|
6446
|
-
* 会被登记为只读保护,禁止被丢弃。以下既有条款零删改。
|
|
6447
|
-
*/
|
|
6448
|
-
'- 预估上报会被插件即时转告主 Agent(含「请把此预期执行时间告知用户」提示),主 Agent 会把你报的预估时间告知用户,让双方都有准备。',
|
|
6449
|
-
'- 超时后主 Agent 放宽时,插件会向你的会话推送【延期告知】:内含最新执行时间与剩余余量,并要求你在保证工作质量的前提下高效率执行——收到通知继续当前工作,不要重新开始;已完成内容及时落盘。',
|
|
6450
|
-
'- 连续两次超时后本行转为「主 Agent 接手」(takeoverRequired):你已完成的产物会被登记为只读保护(禁止丢弃),主 Agent 只继续未完成部分;所以每个阶段都要及时落盘并在回报中列出已完成路径。',
|
|
6541
|
+
'- 预估上报会被插件即时转告主 Agent(含「请把此预期执行时间告知用户」提示),主 Agent 会把你报的预估时间告知用户,让双方都有准备;实际完成与否只由真实结果和验收证据决定。',
|
|
6451
6542
|
'',
|
|
6452
6543
|
'遇阻上报(强制,先于继续动作):',
|
|
6453
6544
|
'- 出现以下任一情况,第一动作是上报,不是猜测、绕过或静默继续:缺少权限/输入/依赖产物;需求自相矛盾;无法验证;同一命令连续两次失败;需要主 Agent 决定方向。',
|