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/CHANGELOG.md +161 -0
- package/README.en.md +20 -18
- package/README.md +33 -19
- package/README.zh.md +15 -19
- package/client.js +88 -59
- package/docs/cc/ADV-FSP-FUNCTIONAL-SPEC.md +19 -6
- 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 +22 -3
- 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 +88 -59
- package/lib/comm-format.js +58 -6
- package/lib/criterion.js +210 -0
- package/lib/dept-journal.js +319 -0
- package/lib/host.js +333 -63
- package/lib/llm-rules.js +281 -24
- package/lib/plan.js +1468 -219
- package/lib/replan.js +50 -39
- package/lib/runtime.js +3474 -1088
- package/lib/three-phase.js +106 -20
- package/lib/understanding.js +18 -3
- package/lib/v3-contract.js +431 -0
- package/lib/watchdog.js +9 -1
- package/package.json +4 -3
- package/src/approval-gate.ts +168 -0
- package/src/client.ts +88 -59
- package/src/comm-format.ts +63 -5
- package/src/criterion.ts +261 -0
- package/src/dept-journal.ts +373 -0
- package/src/host.ts +341 -64
- package/src/llm-rules.ts +349 -27
- package/src/plan.ts +1464 -210
- package/src/replan.ts +48 -37
- package/src/runtime.ts +3028 -699
- package/src/three-phase.ts +147 -20
- package/src/understanding.ts +20 -3
- package/src/v3-contract.ts +470 -0
- package/src/watchdog.ts +13 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [3.0.1] 认可闸门(approval gate)——「未经用户认可不得派发」的底层机制修复。
|
|
3
|
+
*
|
|
4
|
+
* 事故复盘(2026-11-15,wp-e745a477):用户明确要求「有疑问先问用户、经认可后
|
|
5
|
+
* 再开始执行」,主 Agent 也确在提问;但计划一生成,autoDispatch 默认 true 仍
|
|
6
|
+
* 把第一个子任务派了出去。子 Agent 缺产品背景、够不到用户,只能升级待指示,
|
|
7
|
+
* 子会话随后失联(NO_CHILD),instruct/update/dispatch 三条出口全部堵死,
|
|
8
|
+
* 整盘计划只能人工取消。
|
|
9
|
+
*
|
|
10
|
+
* 本模块钉住第一根因:任务锚点文本里凡是「先经用户认可/批准/确认再执行」的
|
|
11
|
+
* 明确门槛语,计划照出、但按住不派(等价于该计划的 plan-first),直到用户
|
|
12
|
+
* 明确认可、主 Agent 调用 dsh_workplan_release 解除闸门。
|
|
13
|
+
*
|
|
14
|
+
* 关闭方式(保留给自动化场景):DSH_WORKPLAN_APPROVAL_GATE=0/false/off
|
|
15
|
+
* 只关「关键词识别」这一半;主 Agent 显式闸门(dsh_workplan_hold)不受影响。
|
|
16
|
+
*/
|
|
17
|
+
import { PlanError } from './plan.js';
|
|
18
|
+
/**
|
|
19
|
+
* 认可门槛语规则表。每条都是「批准类动词 + (再|才)+ 开始执行类动词」的
|
|
20
|
+
* 明确组合,宁可漏判(回落到默认自动派发)也不误判(把普通任务按住),
|
|
21
|
+
* 因为误判的成本是每次执行多一次手动放行,漏判的成本才是事故复发。
|
|
22
|
+
*/
|
|
23
|
+
const APPROVAL_PATTERNS = [
|
|
24
|
+
{
|
|
25
|
+
re: /经[^。;!?\n]{0,10}?认可[^。;!?\n]{0,10}?(再|才)/,
|
|
26
|
+
label: '「经(您/用户)认可后再……」',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
re: /(得到|获得|征得|收到|拿到)[^。;!?\n]{0,10}?(您|用户)?[^。;!?\n]{0,6}?(认可|批准|同意|确认|答复|回复|首肯)[^。;!?\n]{0,10}?(后|再|才)/,
|
|
30
|
+
label: '「得到您认可后再……」',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
re: /(确认|批准|同意|拍板|审阅|答复|回复|首肯)好?(之后|以后|后)[^。;!?\n]{0,6}?(再|才|然后)(开始|执行|动手|做)/,
|
|
34
|
+
label: '「确认后再开始执行」',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
re: /(先|务必先|必须先)[^。;!?\n]{0,8}?(问|询问|请示|向您确认|向您请示|和您确认|跟您确认)[^。;!?\n]{0,4}?(用户|您|我)/,
|
|
38
|
+
label: '「(有疑)先问用户/您」',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
re: /(有疑问|任何疑问|存在疑问|不确定|不清楚)[^。;!?\n]{0,12}?(问|询问|请示|确认)[^。;!?\n]{0,6}?(用户|您)/,
|
|
42
|
+
label: '「有疑问先问用户」',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
re: /(等待|待)[^。;!?\n]{0,4}?(用户|您)[^。;!?\n]{0,10}?(确认|批准|认可|答复|回复|审阅|同意|拍板)/,
|
|
46
|
+
label: '「等待用户确认/批准」',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
re: /(未经|未获得|未得到|没有得到|缺少)[^。;!?\n]{0,8}?(您|用户)?[^。;!?\n]{0,4}?(认可|批准|同意|确认)[^。;!?\n]{0,10}?(不要|不得|禁止|不能|勿|别|不可)/,
|
|
50
|
+
label: '「未经认可不得开始执行」',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
re: /(认可|批准|同意|确认|审阅)[^。;!?\n]{0,4}?后[^。;!?\n]{0,8}?(开始执行|再执行|才执行|开始正式执行|再开始|才开始)/,
|
|
54
|
+
label: '「认可后开始执行」',
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
function excerptOf(text, match, max = 60) {
|
|
58
|
+
const start = Math.max(0, match.index - 6);
|
|
59
|
+
const end = Math.min(text.length, match.index + match[0].length + 10);
|
|
60
|
+
const slice = text.slice(start, end).replace(/\s+/g, ' ').trim();
|
|
61
|
+
return slice.length > max ? `${slice.slice(0, max)}…` : slice;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 识别任务锚点文本里的「先经认可再执行」门槛语。
|
|
65
|
+
* 纯函数、无副作用;空文本/纯寒暄在上游已被过滤,这里再兜底一次。
|
|
66
|
+
*/
|
|
67
|
+
export function detectApprovalGate(taskText) {
|
|
68
|
+
const text = typeof taskText === 'string' ? taskText.trim() : '';
|
|
69
|
+
if (!text)
|
|
70
|
+
return { held: false, matched: [], reason: '' };
|
|
71
|
+
const matched = [];
|
|
72
|
+
for (const { re, label } of APPROVAL_PATTERNS) {
|
|
73
|
+
const found = re.exec(text);
|
|
74
|
+
if (found) {
|
|
75
|
+
matched.push({ label, excerpt: excerptOf(text, found) });
|
|
76
|
+
// 一条规则命中即可;继续跑完所有规则只为汇总证据,不去重(同义重复无害)。
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const held = matched.length > 0;
|
|
80
|
+
return {
|
|
81
|
+
held,
|
|
82
|
+
matched,
|
|
83
|
+
reason: held
|
|
84
|
+
? `任务锚点命中认可门槛语:${matched.map((item) => item.label).join('、')}`
|
|
85
|
+
: '',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** [3.0.1] 关键词识别闸门的总开关:DSH_WORKPLAN_APPROVAL_GATE=0/false/off 关闭。 */
|
|
89
|
+
export function approvalGateDetectionDisabled() {
|
|
90
|
+
const raw = String(process.env.DSH_WORKPLAN_APPROVAL_GATE ?? '').trim().toLowerCase();
|
|
91
|
+
return raw === '0' || raw === 'false' || raw === 'off';
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 计划是否被认可闸门按住、不得派发。
|
|
95
|
+
* 闸门一旦被 release 清空(dispatchHold=null),这里立即放行——
|
|
96
|
+
* 释放动作本身由 dsh_workplan_release 登记 gateHistory 留痕,不赖在本字段上。
|
|
97
|
+
*/
|
|
98
|
+
export function isDispatchHeld(record) {
|
|
99
|
+
const hold = record?.dispatchHold;
|
|
100
|
+
return Boolean(hold && typeof hold === 'object' && (hold.kind === 'keyword' || hold.kind === 'manual'));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* [3.0.1] 死锁自愈:escalated 行子会话失联时的复活补丁。
|
|
104
|
+
*
|
|
105
|
+
* 旧行为:instruct 发现 childId 缺失或子会话已不在 spawnedChildIds 里,直接报
|
|
106
|
+
* NO_CHILD / 投递失败——而 ESCALATION_OPEN 又禁止改判、dispatch 又被待指示行
|
|
107
|
+
* 挡住,三条出口全堵,整盘计划只能人工取消(wp-e745a477 T1 实证)。
|
|
108
|
+
*
|
|
109
|
+
* 新行为:把该行从 escalated 复位为 pending,并把指示登记为 reviveInstruction;
|
|
110
|
+
* 下一次 dispatch 走常规的 executeSubtask 路径重建全新子会话,提示词会把指示
|
|
111
|
+
* 带给新子会话。状态迁移 escalated→pending 在 TRANSITIONS 里是合法边。
|
|
112
|
+
*
|
|
113
|
+
* 纯函数:只产出 applyStatus 补丁,不写任何状态,便于单测。
|
|
114
|
+
*/
|
|
115
|
+
export function buildChildRevivePatch(current, instruction, now) {
|
|
116
|
+
const trimmed = String(instruction ?? '').trim();
|
|
117
|
+
if (!trimmed)
|
|
118
|
+
throw new PlanError('复活指示不能为空:请把要下发给子会话的决定原文传入 instruction。', 'INVALID_INSTRUCTION');
|
|
119
|
+
const revision = Number(current?.revision ?? 0) + 1;
|
|
120
|
+
return {
|
|
121
|
+
patch: {
|
|
122
|
+
status: 'pending',
|
|
123
|
+
closure: 'pending',
|
|
124
|
+
reviveInstruction: {
|
|
125
|
+
text: trimmed,
|
|
126
|
+
at: now,
|
|
127
|
+
by: 'agent',
|
|
128
|
+
reason: 'child-revive',
|
|
129
|
+
},
|
|
130
|
+
question: null,
|
|
131
|
+
options: [],
|
|
132
|
+
error: null,
|
|
133
|
+
blockedKind: null,
|
|
134
|
+
finishedAt: null,
|
|
135
|
+
ackOverdue: false,
|
|
136
|
+
ackedAt: null,
|
|
137
|
+
// 旧失联子会话解绑;新子会话由 executeSubtask 激活时写回新的 childId。
|
|
138
|
+
childId: null,
|
|
139
|
+
revision,
|
|
140
|
+
updatedBy: 'agent',
|
|
141
|
+
},
|
|
142
|
+
revision,
|
|
143
|
+
};
|
|
144
|
+
}
|
package/lib/client.js
CHANGED
|
@@ -23,7 +23,6 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
"groupEnded": "已结束",
|
|
24
24
|
"groupLiveHint": "还没结束,正在或即将推进",
|
|
25
25
|
"groupDoneHint": "已全部完成并收尾",
|
|
26
|
-
"groupEndedHint": "这一轮已经停了,没有东西在跑;说「续跑」可继续推进",
|
|
27
26
|
"groupCollapse": "收起",
|
|
28
27
|
"groupExpand": "展开",
|
|
29
28
|
"groupNeeds": "需处理",
|
|
@@ -93,15 +92,16 @@ window.__ModuleLoader__.load({
|
|
|
93
92
|
"closed": "无需动作"
|
|
94
93
|
},
|
|
95
94
|
"handoffs": "跨部门需求",
|
|
96
|
-
"delegates": "
|
|
95
|
+
"delegates": "第三层(全球顶尖专家)",
|
|
97
96
|
"delegateExpert": "专家",
|
|
98
|
-
"delegateMember": "
|
|
97
|
+
"delegateMember": "专家",
|
|
99
98
|
"delegateStatus": {
|
|
100
99
|
"running": "执行中",
|
|
101
100
|
"done": "已完成",
|
|
102
101
|
"failed": "失败",
|
|
103
102
|
"timeout": "超时",
|
|
104
|
-
"rejected": "派发被拒"
|
|
103
|
+
"rejected": "派发被拒",
|
|
104
|
+
"blocked": "受阻"
|
|
105
105
|
},
|
|
106
106
|
"dept": {
|
|
107
107
|
"engineering": "工程研发",
|
|
@@ -225,26 +225,32 @@ window.__ModuleLoader__.load({
|
|
|
225
225
|
"vizOverall": "总体进度",
|
|
226
226
|
"allPlansHint": "上面是当前各会话最新计划的合计;历史计划不在此汇总,下面每张卡片只统计本计划。",
|
|
227
227
|
"openHint": "打开左侧「任务进度」看完整安排。",
|
|
228
|
-
"timeNegotiation": "
|
|
228
|
+
"timeNegotiation": "执行时间(无时限)",
|
|
229
|
+
"noTimeLimit": "部门负责人和全球顶尖专家执行无时限;预估仅供参考,不影响完成验收",
|
|
229
230
|
"reasoningEffort": "推理等级",
|
|
230
|
-
"estimateMinutes": "
|
|
231
|
-
"negotiatedCeiling": "
|
|
232
|
-
"derived": "
|
|
233
|
-
"negotiatedDeadline": "
|
|
231
|
+
"estimateMinutes": "预估时长(仅信息)",
|
|
232
|
+
"negotiatedCeiling": "历史上限(已失效)",
|
|
233
|
+
"derived": "历史派生",
|
|
234
|
+
"negotiatedDeadline": "历史截止(已失效)",
|
|
234
235
|
"startedAtLabel": "开始时间",
|
|
235
236
|
"remaining": "剩余",
|
|
236
237
|
"minutes": "分钟",
|
|
237
238
|
"seconds": "秒",
|
|
238
|
-
"timeExtensions": "
|
|
239
|
-
"startNotice": "
|
|
240
|
-
"timeWarning": "
|
|
241
|
-
"pendingAdjudication": "
|
|
242
|
-
"pendingAdjudicationHint": "
|
|
239
|
+
"timeExtensions": "历史延期记录(不再生效)",
|
|
240
|
+
"startNotice": "开工预估(仅信息)",
|
|
241
|
+
"timeWarning": "历史时间提示",
|
|
242
|
+
"pendingAdjudication": "历史待裁决标记",
|
|
243
|
+
"pendingAdjudicationHint": "这是旧记录;当前没有执行截止,以真实结果、验收证据或用户取消为准。",
|
|
243
244
|
"noticeChannel": "预告通道",
|
|
244
245
|
"noticeChannelObserved": "已观测到送达",
|
|
245
246
|
"noticeChannelAwaiting": "等待观测",
|
|
246
247
|
"noticeChannelNotObserved": "未观测到送达",
|
|
247
248
|
"reason": "原因",
|
|
249
|
+
"leaderEstimateFull": "全部下属开工预估之和:{minutes} 分钟({reported}/{expected} 已上报)|仅用于协调,不构成时间判据",
|
|
250
|
+
"leaderEstimatePartial": "下属开工预估部分和:{minutes} 分钟({reported}/{expected} 已上报{gaps})|未报齐时如实显示部分和,不影响完成验收",
|
|
251
|
+
"leaderEstimateOver": "预估合计 {minutes} 分钟(仅信息,无超时或完成限制)",
|
|
252
|
+
"leaderEstimateMissing": ",缺:{names}",
|
|
253
|
+
"leaderEstimateFailed": ",报送失败:{names}",
|
|
248
254
|
},
|
|
249
255
|
"en": {
|
|
250
256
|
"groupLive": "In progress",
|
|
@@ -305,6 +311,7 @@ window.__ModuleLoader__.load({
|
|
|
305
311
|
"paused": "Paused (budget spent)",
|
|
306
312
|
"degraded": "Planning failed",
|
|
307
313
|
"cancelled": "Cancelled",
|
|
314
|
+
"superseded": "Taken over by another plan",
|
|
308
315
|
"ended": "Ended (resumable)"
|
|
309
316
|
},
|
|
310
317
|
"status": {
|
|
@@ -328,7 +335,8 @@ window.__ModuleLoader__.load({
|
|
|
328
335
|
"done": "done",
|
|
329
336
|
"failed": "failed",
|
|
330
337
|
"timeout": "timeout",
|
|
331
|
-
"rejected": "rejected"
|
|
338
|
+
"rejected": "rejected",
|
|
339
|
+
"blocked": "blocked"
|
|
332
340
|
},
|
|
333
341
|
"dept": {
|
|
334
342
|
"engineering": "Engineering",
|
|
@@ -452,26 +460,32 @@ window.__ModuleLoader__.load({
|
|
|
452
460
|
"vizOverall": "Overall progress",
|
|
453
461
|
"allPlansHint": "These totals cover the latest plan in each live session; older plans are not included. Each card below counts only its own plan.",
|
|
454
462
|
"openHint": "Open “Task progress” on the left for the full plan.",
|
|
455
|
-
"timeNegotiation": "
|
|
463
|
+
"timeNegotiation": "Execution time (no limit)",
|
|
464
|
+
"noTimeLimit": "Department leads and domain experts have no execution time limit; estimates are informational and do not affect acceptance",
|
|
456
465
|
"reasoningEffort": "Reasoning effort",
|
|
457
|
-
"estimateMinutes": "Estimate",
|
|
458
|
-
"negotiatedCeiling": "
|
|
459
|
-
"derived": "derived",
|
|
460
|
-
"negotiatedDeadline": "
|
|
466
|
+
"estimateMinutes": "Estimate (informational)",
|
|
467
|
+
"negotiatedCeiling": "Historical ceiling (inactive)",
|
|
468
|
+
"derived": "historical derived value",
|
|
469
|
+
"negotiatedDeadline": "Historical deadline (inactive)",
|
|
461
470
|
"startedAtLabel": "Started at",
|
|
462
471
|
"remaining": "remaining",
|
|
463
472
|
"minutes": "min",
|
|
464
473
|
"seconds": "s",
|
|
465
|
-
"timeExtensions": "
|
|
466
|
-
"startNotice": "Start
|
|
467
|
-
"timeWarning": "
|
|
468
|
-
"pendingAdjudication": "
|
|
469
|
-
"pendingAdjudicationHint": "
|
|
474
|
+
"timeExtensions": "Historical extensions (inactive)",
|
|
475
|
+
"startNotice": "Start estimate (informational)",
|
|
476
|
+
"timeWarning": "Historical time notice",
|
|
477
|
+
"pendingAdjudication": "Historical pending-decision marker",
|
|
478
|
+
"pendingAdjudicationHint": "Legacy record only; there is no execution deadline. Results, acceptance evidence, or explicit user cancellation determine completion.",
|
|
470
479
|
"noticeChannel": "Notice channel",
|
|
471
480
|
"noticeChannelObserved": "Delivery observed",
|
|
472
481
|
"noticeChannelAwaiting": "Awaiting observation",
|
|
473
482
|
"noticeChannelNotObserved": "Delivery not observed",
|
|
474
483
|
"reason": "reason",
|
|
484
|
+
"leaderEstimateFull": "Sum of all delegate start estimates: {minutes} min ({reported}/{expected} reported) | Coordination only, not a time criterion",
|
|
485
|
+
"leaderEstimatePartial": "Partial sum of delegate start estimates: {minutes} min ({reported}/{expected} reported{gaps}) | Informational only; incomplete estimates do not affect acceptance",
|
|
486
|
+
"leaderEstimateOver": "Estimate total: {minutes} min (informational; no timeout or completion limit)",
|
|
487
|
+
"leaderEstimateMissing": ", missing: {names}",
|
|
488
|
+
"leaderEstimateFailed": ", delivery failed: {names}",
|
|
475
489
|
}
|
|
476
490
|
};
|
|
477
491
|
function flattenLocale(source, prefix = '', out = {}) {
|
|
@@ -1561,56 +1575,45 @@ window.__ModuleLoader__.load({
|
|
|
1561
1575
|
return h('div', { className: 'dsh-wp-banner dsh-wp-banner--error', role: 'alert' }, h('div', { className: 'dsh-wp-section-title' }, t('error')), h('div', { className: 'dsh-wp-error-text' }, message || t('noResult')), h('button', { type: 'button', className: 'dsh-wp-button', style: { marginTop: '8px' }, onClick: onRetry }, t('retry')));
|
|
1562
1576
|
}
|
|
1563
1577
|
/*
|
|
1564
|
-
* [
|
|
1578
|
+
* [3.0.1] 看板:执行时间信息与历史回放。
|
|
1565
1579
|
*
|
|
1566
|
-
*
|
|
1567
|
-
* - 计划定义:estimateMinutes
|
|
1568
|
-
* - 状态行:startedAt/
|
|
1569
|
-
* timeNotice
|
|
1570
|
-
*
|
|
1580
|
+
* 负责人和专家执行无时限,客户端不得显示倒计时、协商上限或“到点会怎样”:
|
|
1581
|
+
* - 计划定义:estimateMinutes 仅参考;timeoutMs 是历史字段,不形成截止;
|
|
1582
|
+
* - 状态行:startedAt 仅用于已执行时长;deadlineAt/timeJournal/timeWarning/
|
|
1583
|
+
* pendingAdjudication 只作历史标记;timeNotice 是开工信息;
|
|
1584
|
+
* noticeChannel 是子→主送达观测;
|
|
1585
|
+
* [T7] leaderEstimate(负责人时长聚合,服务端读时派生:全员 sent 表述完整等式,
|
|
1586
|
+
* 否则部分和+缺口名单;null/缺失整块不渲染,客户端严禁求和)。
|
|
1571
1587
|
*
|
|
1572
1588
|
* 客户端不推导状态机、不补造字段:任何字段缺失就少显示一行;全部缺失整块不渲染,
|
|
1573
1589
|
* 绝不出现 undefined / [object Object]。
|
|
1574
1590
|
*/
|
|
1575
1591
|
function TimeNegotiation({ item, subtask, t }) {
|
|
1576
1592
|
const estimate = positiveNumber(subtask?.estimateMinutes);
|
|
1577
|
-
const deadlineAt = positiveNumber(item?.deadlineAt);
|
|
1578
|
-
const startedAt = positiveNumber(item?.startedAt);
|
|
1579
1593
|
const journal = Array.isArray(item?.timeJournal) ? item.timeJournal : [];
|
|
1580
1594
|
const extensions = journal
|
|
1581
1595
|
.filter((entry) => entry?.action === 'extend' && positiveNumber(entry?.extendMs))
|
|
1582
1596
|
.slice(-3);
|
|
1583
|
-
/*
|
|
1584
|
-
* [2.2.3][N2] D2「协商上限」结构性不可达:计划里没有 timeoutMs 时,
|
|
1585
|
-
* 用 deadlineAt - startedAt - 已延期 派生一个只读上限,明确标注“派生”,
|
|
1586
|
-
* 不写回计划、不把派生值冒充用户授权值。
|
|
1587
|
-
*/
|
|
1588
|
-
const extensionTotal = extensions.reduce((sum, entry) => sum + Number(positiveNumber(entry?.extendMs) ?? 0), 0);
|
|
1589
|
-
const declaredCeiling = positiveNumber(subtask?.timeoutMs);
|
|
1590
|
-
const derivedCeiling = !declaredCeiling && startedAt && deadlineAt
|
|
1591
|
-
? Math.max(0, deadlineAt - startedAt - extensionTotal)
|
|
1592
|
-
: null;
|
|
1593
|
-
const ceiling = declaredCeiling ?? derivedCeiling;
|
|
1594
|
-
const ceilingLabel = declaredCeiling ? t('negotiatedCeiling') : `${t('negotiatedCeiling')}(${t('derived')})`;
|
|
1595
1597
|
const notice = item?.timeNotice && typeof item.timeNotice === 'object' ? item.timeNotice : null;
|
|
1596
1598
|
const warning = item?.timeWarning && typeof item.timeWarning === 'object' ? item.timeWarning : null;
|
|
1597
1599
|
const channel = item?.noticeChannel && typeof item.noticeChannel === 'object' ? item.noticeChannel : null;
|
|
1598
1600
|
const pending = item?.pendingAdjudication === true;
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1601
|
+
/*
|
|
1602
|
+
* [T7][J2/J6] 负责人任务时长聚合:只渲染服务端下发的 leaderEstimate
|
|
1603
|
+
* (plan.ts deriveLeaderEstimate 读时派生,经 serialisePlan→derivePlanSnapshot
|
|
1604
|
+
* 同源下发)。客户端严禁求和、不推导状态机:reported===expected 仅作
|
|
1605
|
+
* 措辞选择(J1:全员 sent 才表述完整等式)。totalMinutes=0 合法(F3
|
|
1606
|
+
* 部分和 0),故用 ≥0 守卫而非 positiveNumber;字段缺失/null(J8 空
|
|
1607
|
+
* roster/replanned 旧行/越界 fail-closed)⇒ 不渲染本块。
|
|
1608
|
+
*/
|
|
1609
|
+
const leaderEstimate = item?.leaderEstimate && typeof item.leaderEstimate === 'object' ? item.leaderEstimate : null;
|
|
1610
|
+
const leaderExpected = leaderEstimate && Number.isInteger(leaderEstimate.expected) && leaderEstimate.expected > 0 ? leaderEstimate.expected : null;
|
|
1611
|
+
const leaderReported = leaderEstimate && Number.isInteger(leaderEstimate.reported) && leaderEstimate.reported >= 0 ? leaderEstimate.reported : null;
|
|
1612
|
+
const leaderMinutes = leaderEstimate && Number.isFinite(Number(leaderEstimate.totalMinutes)) && Number(leaderEstimate.totalMinutes) >= 0 ? Number(leaderEstimate.totalMinutes) : null;
|
|
1613
|
+
const leaderShown = leaderEstimate !== null && leaderExpected !== null && leaderReported !== null && leaderMinutes !== null;
|
|
1614
|
+
const facts = [t('noTimeLimit')];
|
|
1604
1615
|
if (estimate)
|
|
1605
1616
|
facts.push(`${t('estimateMinutes')}:${estimate} ${t('minutes')}`);
|
|
1606
|
-
if (ceiling)
|
|
1607
|
-
facts.push(`${ceilingLabel}:${Math.round(ceiling / 60000)} ${t('minutes')}`);
|
|
1608
|
-
if (deadlineAt) {
|
|
1609
|
-
const left = remainingMs && remainingMs > 0
|
|
1610
|
-
? `(${t('remaining')} ${Math.max(1, Math.round(remainingMs / 60000))} ${t('minutes')})`
|
|
1611
|
-
: '';
|
|
1612
|
-
facts.push(`${t('negotiatedDeadline')}:${formatTime(deadlineAt)}${left}`);
|
|
1613
|
-
}
|
|
1614
1617
|
const notes = [];
|
|
1615
1618
|
if (notice) {
|
|
1616
1619
|
const declared = positiveNumber(notice.declaredMinutes);
|
|
@@ -1640,6 +1643,22 @@ window.__ModuleLoader__.load({
|
|
|
1640
1643
|
}
|
|
1641
1644
|
if (pending)
|
|
1642
1645
|
notes.push(`${t('pendingAdjudication')}:${t('pendingAdjudicationHint')}`);
|
|
1646
|
+
/*
|
|
1647
|
+
* [T7][J1 方案 A] 全员 sent(reported===expected)才表述完整等式
|
|
1648
|
+
* 「负责人任务时长=全部下属开工预估之和」;否则必须按「部分和(X/Y)」
|
|
1649
|
+
* 标注并如实列出缺口名单。名单 join 只是展示拼接,不是求和;数值全部
|
|
1650
|
+
* 来自服务端下发的 leaderEstimate,客户端不做任何算术。
|
|
1651
|
+
*/
|
|
1652
|
+
if (leaderShown) {
|
|
1653
|
+
const missingNames = Array.isArray(leaderEstimate.missing) ? leaderEstimate.missing.filter((name) => typeof name === 'string' && name !== '') : [];
|
|
1654
|
+
const failedNames = Array.isArray(leaderEstimate.failed) ? leaderEstimate.failed.filter((name) => typeof name === 'string' && name !== '') : [];
|
|
1655
|
+
const gaps = (missingNames.length > 0 ? fill(t('leaderEstimateMissing'), { names: missingNames.join('、') }) : '')
|
|
1656
|
+
+ (failedNames.length > 0 ? fill(t('leaderEstimateFailed'), { names: failedNames.join('、') }) : '');
|
|
1657
|
+
notes.push(leaderReported === leaderExpected
|
|
1658
|
+
? fill(t('leaderEstimateFull'), { minutes: leaderMinutes, reported: leaderReported, expected: leaderExpected })
|
|
1659
|
+
: fill(t('leaderEstimatePartial'), { minutes: leaderMinutes, reported: leaderReported, expected: leaderExpected, gaps }));
|
|
1660
|
+
// 历史 leaderEstimateOverCriterion 字段不再渲染为告警;预估不构成时间判据。
|
|
1661
|
+
}
|
|
1643
1662
|
return h('div', { className: 'dsh-wp-time' }, h('div', { className: 'dsh-wp-time-title' }, t('timeNegotiation')), facts.length > 0
|
|
1644
1663
|
? h('div', { className: 'dsh-wp-time-row' }, facts.map((fact, factIndex) => h('span', { key: String(factIndex) }, fact)))
|
|
1645
1664
|
: null, notes.map((note, noteIndex) => h('p', { key: String(noteIndex), className: 'dsh-wp-time-note' }, note)));
|
|
@@ -1721,7 +1740,7 @@ window.__ModuleLoader__.load({
|
|
|
1721
1740
|
: null,
|
|
1722
1741
|
/*
|
|
1723
1742
|
* [2.3.9][T4b] 第三层派发看板(用户要求 4/5):部门负责人分配给
|
|
1724
|
-
*
|
|
1743
|
+
* 全球顶尖专家的每位下级、其推理等级(含越界钳制留痕)与实时状态
|
|
1725
1744
|
* 必须对用户与主 Agent 可见,否则「第三层派给了谁、跑没跑完」只存在
|
|
1726
1745
|
* 负责人子会话里。数据源 = 状态行 delegates(applyStatus 消毒 +
|
|
1727
1746
|
* durable workplan-update 回放,刷新/重启不丢),客户端不推导状态。
|
|
@@ -1731,7 +1750,17 @@ window.__ModuleLoader__.load({
|
|
|
1731
1750
|
+ `(${member?.role === 'expert' ? t('delegateExpert') : t('delegateMember')})`
|
|
1732
1751
|
+ `|${t('reasoningEffort')}:${String(member?.effort ?? '?')}`
|
|
1733
1752
|
+ (member?.requested && member.requested !== member.effort ? `(越界钳制自 ${String(member.requested)})` : '')
|
|
1753
|
+
+ (member?.selfEffort ? `|自配档 ${String(member.selfEffort)}${member?.selfEffortRequested && member.selfEffortRequested !== member.selfEffort ? `(钳制自 ${String(member.selfEffortRequested)})` : ''}` : '|自配档 待自配')
|
|
1734
1754
|
+ `|${t(`delegateStatus.${String(member?.status ?? 'running')}`)}`
|
|
1755
|
+
/*
|
|
1756
|
+
* [2.5.6] 第三层闭环可见性:叶子的「待指示/已给指示/已回应」
|
|
1757
|
+
* 与第一层同一套 closure 文案(服务端下发,客户端不推导),
|
|
1758
|
+
* 请示问题随待指示标记一并展示,负责人/用户一眼看到谁在等谁。
|
|
1759
|
+
*/
|
|
1760
|
+
+ (member?.escalation ? `|${t('closureEscalated')}${member.escalation.question ? `:${String(member.escalation.question)}` : ''}` : '')
|
|
1761
|
+
+ (member?.lastInstruction ? `|${t('closureInstructed')}` : '')
|
|
1762
|
+
+ (member?.closure === 'acknowledged' ? `|${t('closureAcknowledged')}` : '')
|
|
1763
|
+
+ (member?.instructionOverdue ? `|${t('closureNoAck')}` : '')
|
|
1735
1764
|
+ (member?.summary ? `:${String(member.summary)}` : '')))))
|
|
1736
1765
|
: null, status !== 'blocked' && item?.summary ? h('p', { className: 'dsh-wp-muted' }, `${t('summary')}:${plainError(item.summary)}`) : null,
|
|
1737
1766
|
/*
|
package/lib/comm-format.js
CHANGED
|
@@ -17,8 +17,17 @@
|
|
|
17
17
|
* - 与既有门禁正交:解析失败、验收缺口、三阶段缺失仍由原门禁先拦,
|
|
18
18
|
* 本门禁只负责把「其它门禁都过了、但格式仍不合规」的 done 退回。
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
import { checkDepartmentSummary, checkExpertReport, renderDepartmentSummarySpec, renderExpertReportSpec, } from './v3-contract.js';
|
|
21
|
+
/**
|
|
22
|
+
* 格式规范版本,随规范内容变更递增。
|
|
23
|
+
*
|
|
24
|
+
* [3.0.0] 1 → 2:用户 2026-11-14 第 7、10 条要求为结果格式增加了两条
|
|
25
|
+
* 结构化精简契约(F10 专家 JSON 汇报、F11 部门 JSON 汇总)。F1–F9 的
|
|
26
|
+
* 文本与判据一字未改(只增不改),新增条目由调用方按接收者层级开关:
|
|
27
|
+
* 专家结果查 F10,部门负责人结果查 F11,未声明层级时两条都不查
|
|
28
|
+
* (历史回放与其它调用点零回归)。
|
|
29
|
+
*/
|
|
30
|
+
export const COMM_FORMAT_VERSION = 2;
|
|
22
31
|
/**
|
|
23
32
|
* 统一沟通交流格式规范定义(F1-F9,冻结不可变)。
|
|
24
33
|
*/
|
|
@@ -33,7 +42,7 @@ export const COMM_FORMAT_SPEC = Object.freeze({
|
|
|
33
42
|
description: '证据块必须是合法 JSON 对象,顶层必须含 status 字段,取值只能是 done / blocked / partial',
|
|
34
43
|
rationale: 'status 是交付门禁的入口条件,缺失或非法则无法判定完成与否' }),
|
|
35
44
|
Object.freeze({ id: 'F3', category: 'phases',
|
|
36
|
-
description: '必须包含三阶段证据:phases.planning
|
|
45
|
+
description: '必须包含三阶段证据:phases.planning(两轮深度思考:第一轮任务深研 problemAnalysis + 第二轮方法流程步骤 approach + 第二轮依据 approachBasis)、phases.execution(实际执行步骤)、phases.verification(逐项验证)',
|
|
37
46
|
rationale: '三阶段是质量闭环的基础,缺任一阶段等于跳过对应质控环节' }),
|
|
38
47
|
Object.freeze({ id: 'F4', category: 'acceptance',
|
|
39
48
|
description: '验收结果必须逐条回应计划的验收标准(A1、A2…),且每条 result=pass 必须附带具体证据(命令输出/文件路径/引用),禁止空证据 pass',
|
|
@@ -53,6 +62,16 @@ export const COMM_FORMAT_SPEC = Object.freeze({
|
|
|
53
62
|
Object.freeze({ id: 'F9', category: 'integrity',
|
|
54
63
|
description: '不得编造、虚构或伪造任何证据、文件路径、命令输出或验收结果;无法确认的项目必须写 unverified',
|
|
55
64
|
rationale: '虚假证据一旦通过交付门禁,用户拿到的就是不可信的成品' }),
|
|
65
|
+
/*
|
|
66
|
+
* [3.0.0] F10/F11:用户 2026-11-14 第 7、10 条要求。F1–F9 是 2.1.0 起的
|
|
67
|
+
* 冻结条目,本次只增不改;两条新条目按接收者层级启用(见 check 的 tier)。
|
|
68
|
+
*/
|
|
69
|
+
Object.freeze({ id: 'F10', category: 'report',
|
|
70
|
+
description: '专家(第三层执行者)结果必须包含 report 对象,只允许 keyResults/keyInfo/importantInfo/leadRequirements 四个字符串数组字段,至少各有 1 条非空内容(keyInfo/important 可为空数组但须存在),每数组最多 6 条、每条最多 200 字符,内部与跨字段不得出现重复表述',
|
|
71
|
+
rationale: '用户要求 7:专家成果必须非常精简地汇报给部门负责人,只要关键信息、关键成果、重要信息和负责人要求的东西,并以 JSON mode 结构化输出' }),
|
|
72
|
+
Object.freeze({ id: 'F11', category: 'report',
|
|
73
|
+
description: '部门负责人结果必须包含 departmentSummary 对象,只允许 keyResults/keyInfo/importantInfo/sources 四个字符串数组字段,keyResults 至少 1 条非空、sources 必须覆盖本部门全部已派发专家,每数组最多 6 条、每条最多 200 字符,内部与跨字段不得出现重复表述',
|
|
74
|
+
rationale: '用户要求 8/10/11:部门负责人必须全面汇总全部专家汇报,汇总报告必须精简、禁止累赘重复,并以 JSON mode 结构化直接交回主 Agent' }),
|
|
56
75
|
]),
|
|
57
76
|
/*
|
|
58
77
|
* [2.2.0][T3/O-2c] 结果块可选字段(方案 §2.4:「模板增加 timeSpentMinutes、
|
|
@@ -78,8 +97,12 @@ export const COMM_FORMAT_SPEC = Object.freeze({
|
|
|
78
97
|
* @param parsed - 已解析的证据块 payload(parseEvidenceBlock 的 payload,可为 null)
|
|
79
98
|
* @param rawOutput - 子 Agent 原始输出全文
|
|
80
99
|
* @param expectedAcceptanceCount - 计划定义的验收标准条数
|
|
100
|
+
* @param options.tier - 接收者层级:'expert' 追加 F10(专家 JSON 汇报),
|
|
101
|
+
* 'leader' 追加 F11(部门 JSON 汇总);省略则两条都不查(历史回放、
|
|
102
|
+
* 旧调用点零回归)
|
|
103
|
+
* @param options.expectedExperts - 本部门已派发的专家名单(F11 覆盖度核对用)
|
|
81
104
|
*/
|
|
82
|
-
export function checkCommFormatCompliance(parsed, rawOutput, expectedAcceptanceCount) {
|
|
105
|
+
export function checkCommFormatCompliance(parsed, rawOutput, expectedAcceptanceCount, options = {}) {
|
|
83
106
|
const violations = [];
|
|
84
107
|
const text = typeof rawOutput === 'string' ? rawOutput : '';
|
|
85
108
|
// F1: 证据块标记必须成对出现(rescueEvidence 捞到的豁免——主 Agent 已能解析)
|
|
@@ -168,19 +191,48 @@ export function checkCommFormatCompliance(parsed, rawOutput, expectedAcceptanceC
|
|
|
168
191
|
violations.push({ ruleId: 'F8', category: 'blocked',
|
|
169
192
|
message: 'status 为 blocked 但 question 为空:须写清卡在哪一步、已尝试什么、需要谁做什么决定' });
|
|
170
193
|
}
|
|
194
|
+
/*
|
|
195
|
+
* F10/F11(用户 2026-11-14 第 7、10、11 条):按接收者层级启用。
|
|
196
|
+
* 只拦 done 路径——受阻结果已有更针对性的诊断(F8/三阶段),
|
|
197
|
+
* 不再叠加精简性条目,避免一条 blocked 被反复退回在格式上。
|
|
198
|
+
*/
|
|
199
|
+
if (options.tier === 'expert' && parsed.status === 'done') {
|
|
200
|
+
const report = checkExpertReport(parsed.report);
|
|
201
|
+
for (const item of report.violations) {
|
|
202
|
+
violations.push({ ruleId: 'F10', category: 'report', message: item });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (options.tier === 'leader' && parsed.status === 'done') {
|
|
206
|
+
const summary = checkDepartmentSummary(parsed.departmentSummary, options.expectedExperts ?? []);
|
|
207
|
+
for (const item of summary.violations) {
|
|
208
|
+
violations.push({ ruleId: 'F11', category: 'report', message: item });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
171
211
|
return { compliant: violations.length === 0, violations, version: COMM_FORMAT_VERSION };
|
|
172
212
|
}
|
|
173
213
|
/**
|
|
174
214
|
* 把格式规范渲染为嵌入子 Agent 提示词的文本。
|
|
175
215
|
* 这是「派发工作时附带统一沟通交流格式要求」的具体实现。
|
|
216
|
+
*
|
|
217
|
+
* @param tier - 接收者层级:'expert' 附带专家 JSON 汇报契约(F10),
|
|
218
|
+
* 'leader' 附带部门 JSON 汇总契约(F11);省略时两条都不带。
|
|
176
219
|
*/
|
|
177
|
-
export function renderCommFormatSpec() {
|
|
220
|
+
export function renderCommFormatSpec(tier) {
|
|
178
221
|
const lines = [
|
|
179
222
|
'沟通交流格式规范(v' + String(COMM_FORMAT_VERSION) + ',主 Agent 与部门人员双方认可的结果格式契约):',
|
|
180
223
|
];
|
|
181
|
-
|
|
224
|
+
const scoped = tier === 'expert'
|
|
225
|
+
? COMM_FORMAT_SPEC.requirements.filter((req) => req.id !== 'F11')
|
|
226
|
+
: tier === 'leader'
|
|
227
|
+
? COMM_FORMAT_SPEC.requirements.filter((req) => req.id !== 'F10')
|
|
228
|
+
: COMM_FORMAT_SPEC.requirements;
|
|
229
|
+
for (const req of scoped) {
|
|
182
230
|
lines.push(`- 【${req.id}】${req.description}`);
|
|
183
231
|
}
|
|
232
|
+
if (tier === 'expert')
|
|
233
|
+
lines.push('', renderExpertReportSpec());
|
|
234
|
+
if (tier === 'leader')
|
|
235
|
+
lines.push('', renderDepartmentSummarySpec());
|
|
184
236
|
lines.push('不合规的后果:主 Agent 收到结果后按本规范逐条核验;任一不合规,结果立刻退回,你将收到列明不合规条目的退回通知,须全部修正后重新提交完整结果。');
|
|
185
237
|
return lines.join('\n');
|
|
186
238
|
}
|