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
package/src/client.ts
CHANGED
|
@@ -24,7 +24,6 @@ window.__ModuleLoader__.load({
|
|
|
24
24
|
"groupEnded": "已结束",
|
|
25
25
|
"groupLiveHint": "还没结束,正在或即将推进",
|
|
26
26
|
"groupDoneHint": "已全部完成并收尾",
|
|
27
|
-
"groupEndedHint": "这一轮已经停了,没有东西在跑;说「续跑」可继续推进",
|
|
28
27
|
"groupCollapse": "收起",
|
|
29
28
|
"groupExpand": "展开",
|
|
30
29
|
"groupNeeds": "需处理",
|
|
@@ -95,15 +94,16 @@ window.__ModuleLoader__.load({
|
|
|
95
94
|
"closed": "无需动作"
|
|
96
95
|
},
|
|
97
96
|
"handoffs": "跨部门需求",
|
|
98
|
-
"delegates": "
|
|
97
|
+
"delegates": "第三层(全球顶尖专家)",
|
|
99
98
|
"delegateExpert": "专家",
|
|
100
|
-
"delegateMember": "
|
|
99
|
+
"delegateMember": "专家",
|
|
101
100
|
"delegateStatus": {
|
|
102
101
|
"running": "执行中",
|
|
103
102
|
"done": "已完成",
|
|
104
103
|
"failed": "失败",
|
|
105
104
|
"timeout": "超时",
|
|
106
|
-
"rejected": "派发被拒"
|
|
105
|
+
"rejected": "派发被拒",
|
|
106
|
+
"blocked": "受阻"
|
|
107
107
|
},
|
|
108
108
|
"dept": {
|
|
109
109
|
"engineering": "工程研发",
|
|
@@ -227,26 +227,32 @@ window.__ModuleLoader__.load({
|
|
|
227
227
|
"vizOverall": "总体进度",
|
|
228
228
|
"allPlansHint": "上面是当前各会话最新计划的合计;历史计划不在此汇总,下面每张卡片只统计本计划。",
|
|
229
229
|
"openHint": "打开左侧「任务进度」看完整安排。",
|
|
230
|
-
"timeNegotiation": "
|
|
230
|
+
"timeNegotiation": "执行时间(无时限)",
|
|
231
|
+
"noTimeLimit": "部门负责人和全球顶尖专家执行无时限;预估仅供参考,不影响完成验收",
|
|
231
232
|
"reasoningEffort": "推理等级",
|
|
232
|
-
"estimateMinutes": "
|
|
233
|
-
"negotiatedCeiling": "
|
|
234
|
-
"derived": "
|
|
235
|
-
"negotiatedDeadline": "
|
|
233
|
+
"estimateMinutes": "预估时长(仅信息)",
|
|
234
|
+
"negotiatedCeiling": "历史上限(已失效)",
|
|
235
|
+
"derived": "历史派生",
|
|
236
|
+
"negotiatedDeadline": "历史截止(已失效)",
|
|
236
237
|
"startedAtLabel": "开始时间",
|
|
237
238
|
"remaining": "剩余",
|
|
238
239
|
"minutes": "分钟",
|
|
239
240
|
"seconds": "秒",
|
|
240
|
-
"timeExtensions": "
|
|
241
|
-
"startNotice": "
|
|
242
|
-
"timeWarning": "
|
|
243
|
-
"pendingAdjudication": "
|
|
244
|
-
"pendingAdjudicationHint": "
|
|
241
|
+
"timeExtensions": "历史延期记录(不再生效)",
|
|
242
|
+
"startNotice": "开工预估(仅信息)",
|
|
243
|
+
"timeWarning": "历史时间提示",
|
|
244
|
+
"pendingAdjudication": "历史待裁决标记",
|
|
245
|
+
"pendingAdjudicationHint": "这是旧记录;当前没有执行截止,以真实结果、验收证据或用户取消为准。",
|
|
245
246
|
"noticeChannel": "预告通道",
|
|
246
247
|
"noticeChannelObserved": "已观测到送达",
|
|
247
248
|
"noticeChannelAwaiting": "等待观测",
|
|
248
249
|
"noticeChannelNotObserved": "未观测到送达",
|
|
249
250
|
"reason": "原因",
|
|
251
|
+
"leaderEstimateFull": "全部下属开工预估之和:{minutes} 分钟({reported}/{expected} 已上报)|仅用于协调,不构成时间判据",
|
|
252
|
+
"leaderEstimatePartial": "下属开工预估部分和:{minutes} 分钟({reported}/{expected} 已上报{gaps})|未报齐时如实显示部分和,不影响完成验收",
|
|
253
|
+
"leaderEstimateOver": "预估合计 {minutes} 分钟(仅信息,无超时或完成限制)",
|
|
254
|
+
"leaderEstimateMissing": ",缺:{names}",
|
|
255
|
+
"leaderEstimateFailed": ",报送失败:{names}",
|
|
250
256
|
},
|
|
251
257
|
"en": {
|
|
252
258
|
"groupLive": "In progress",
|
|
@@ -307,6 +313,7 @@ window.__ModuleLoader__.load({
|
|
|
307
313
|
"paused": "Paused (budget spent)",
|
|
308
314
|
"degraded": "Planning failed",
|
|
309
315
|
"cancelled": "Cancelled",
|
|
316
|
+
"superseded": "Taken over by another plan",
|
|
310
317
|
"ended": "Ended (resumable)"
|
|
311
318
|
},
|
|
312
319
|
"status": {
|
|
@@ -330,7 +337,8 @@ window.__ModuleLoader__.load({
|
|
|
330
337
|
"done": "done",
|
|
331
338
|
"failed": "failed",
|
|
332
339
|
"timeout": "timeout",
|
|
333
|
-
"rejected": "rejected"
|
|
340
|
+
"rejected": "rejected",
|
|
341
|
+
"blocked": "blocked"
|
|
334
342
|
},
|
|
335
343
|
"dept": {
|
|
336
344
|
"engineering": "Engineering",
|
|
@@ -454,26 +462,32 @@ window.__ModuleLoader__.load({
|
|
|
454
462
|
"vizOverall": "Overall progress",
|
|
455
463
|
"allPlansHint": "These totals cover the latest plan in each live session; older plans are not included. Each card below counts only its own plan.",
|
|
456
464
|
"openHint": "Open “Task progress” on the left for the full plan.",
|
|
457
|
-
"timeNegotiation": "
|
|
465
|
+
"timeNegotiation": "Execution time (no limit)",
|
|
466
|
+
"noTimeLimit": "Department leads and domain experts have no execution time limit; estimates are informational and do not affect acceptance",
|
|
458
467
|
"reasoningEffort": "Reasoning effort",
|
|
459
|
-
"estimateMinutes": "Estimate",
|
|
460
|
-
"negotiatedCeiling": "
|
|
461
|
-
"derived": "derived",
|
|
462
|
-
"negotiatedDeadline": "
|
|
468
|
+
"estimateMinutes": "Estimate (informational)",
|
|
469
|
+
"negotiatedCeiling": "Historical ceiling (inactive)",
|
|
470
|
+
"derived": "historical derived value",
|
|
471
|
+
"negotiatedDeadline": "Historical deadline (inactive)",
|
|
463
472
|
"startedAtLabel": "Started at",
|
|
464
473
|
"remaining": "remaining",
|
|
465
474
|
"minutes": "min",
|
|
466
475
|
"seconds": "s",
|
|
467
|
-
"timeExtensions": "
|
|
468
|
-
"startNotice": "Start
|
|
469
|
-
"timeWarning": "
|
|
470
|
-
"pendingAdjudication": "
|
|
471
|
-
"pendingAdjudicationHint": "
|
|
476
|
+
"timeExtensions": "Historical extensions (inactive)",
|
|
477
|
+
"startNotice": "Start estimate (informational)",
|
|
478
|
+
"timeWarning": "Historical time notice",
|
|
479
|
+
"pendingAdjudication": "Historical pending-decision marker",
|
|
480
|
+
"pendingAdjudicationHint": "Legacy record only; there is no execution deadline. Results, acceptance evidence, or explicit user cancellation determine completion.",
|
|
472
481
|
"noticeChannel": "Notice channel",
|
|
473
482
|
"noticeChannelObserved": "Delivery observed",
|
|
474
483
|
"noticeChannelAwaiting": "Awaiting observation",
|
|
475
484
|
"noticeChannelNotObserved": "Delivery not observed",
|
|
476
485
|
"reason": "reason",
|
|
486
|
+
"leaderEstimateFull": "Sum of all delegate start estimates: {minutes} min ({reported}/{expected} reported) | Coordination only, not a time criterion",
|
|
487
|
+
"leaderEstimatePartial": "Partial sum of delegate start estimates: {minutes} min ({reported}/{expected} reported{gaps}) | Informational only; incomplete estimates do not affect acceptance",
|
|
488
|
+
"leaderEstimateOver": "Estimate total: {minutes} min (informational; no timeout or completion limit)",
|
|
489
|
+
"leaderEstimateMissing": ", missing: {names}",
|
|
490
|
+
"leaderEstimateFailed": ", delivery failed: {names}",
|
|
477
491
|
}
|
|
478
492
|
}
|
|
479
493
|
|
|
@@ -1615,55 +1629,44 @@ window.__ModuleLoader__.load({
|
|
|
1615
1629
|
}
|
|
1616
1630
|
|
|
1617
1631
|
/*
|
|
1618
|
-
* [
|
|
1632
|
+
* [3.0.1] 看板:执行时间信息与历史回放。
|
|
1619
1633
|
*
|
|
1620
|
-
*
|
|
1621
|
-
* - 计划定义:estimateMinutes
|
|
1622
|
-
* - 状态行:startedAt/
|
|
1623
|
-
* timeNotice
|
|
1624
|
-
*
|
|
1634
|
+
* 负责人和专家执行无时限,客户端不得显示倒计时、协商上限或“到点会怎样”:
|
|
1635
|
+
* - 计划定义:estimateMinutes 仅参考;timeoutMs 是历史字段,不形成截止;
|
|
1636
|
+
* - 状态行:startedAt 仅用于已执行时长;deadlineAt/timeJournal/timeWarning/
|
|
1637
|
+
* pendingAdjudication 只作历史标记;timeNotice 是开工信息;
|
|
1638
|
+
* noticeChannel 是子→主送达观测;
|
|
1639
|
+
* [T7] leaderEstimate(负责人时长聚合,服务端读时派生:全员 sent 表述完整等式,
|
|
1640
|
+
* 否则部分和+缺口名单;null/缺失整块不渲染,客户端严禁求和)。
|
|
1625
1641
|
*
|
|
1626
1642
|
* 客户端不推导状态机、不补造字段:任何字段缺失就少显示一行;全部缺失整块不渲染,
|
|
1627
1643
|
* 绝不出现 undefined / [object Object]。
|
|
1628
1644
|
*/
|
|
1629
1645
|
function TimeNegotiation({ item, subtask, t }: any) {
|
|
1630
1646
|
const estimate = positiveNumber(subtask?.estimateMinutes)
|
|
1631
|
-
const deadlineAt = positiveNumber(item?.deadlineAt)
|
|
1632
|
-
const startedAt = positiveNumber(item?.startedAt)
|
|
1633
1647
|
const journal = Array.isArray(item?.timeJournal) ? item.timeJournal : []
|
|
1634
1648
|
const extensions = journal
|
|
1635
1649
|
.filter((entry: any) => entry?.action === 'extend' && positiveNumber(entry?.extendMs))
|
|
1636
1650
|
.slice(-3)
|
|
1637
|
-
/*
|
|
1638
|
-
* [2.2.3][N2] D2「协商上限」结构性不可达:计划里没有 timeoutMs 时,
|
|
1639
|
-
* 用 deadlineAt - startedAt - 已延期 派生一个只读上限,明确标注“派生”,
|
|
1640
|
-
* 不写回计划、不把派生值冒充用户授权值。
|
|
1641
|
-
*/
|
|
1642
|
-
const extensionTotal = extensions.reduce(
|
|
1643
|
-
(sum: number, entry: any) => sum + Number(positiveNumber(entry?.extendMs) ?? 0), 0)
|
|
1644
|
-
const declaredCeiling = positiveNumber(subtask?.timeoutMs)
|
|
1645
|
-
const derivedCeiling = !declaredCeiling && startedAt && deadlineAt
|
|
1646
|
-
? Math.max(0, deadlineAt - startedAt - extensionTotal)
|
|
1647
|
-
: null
|
|
1648
|
-
const ceiling = declaredCeiling ?? derivedCeiling
|
|
1649
|
-
const ceilingLabel = declaredCeiling ? t('negotiatedCeiling') : `${t('negotiatedCeiling')}(${t('derived')})`
|
|
1650
1651
|
const notice = item?.timeNotice && typeof item.timeNotice === 'object' ? item.timeNotice : null
|
|
1651
1652
|
const warning = item?.timeWarning && typeof item.timeWarning === 'object' ? item.timeWarning : null
|
|
1652
1653
|
const channel = item?.noticeChannel && typeof item.noticeChannel === 'object' ? item.noticeChannel : null
|
|
1653
1654
|
const pending = item?.pendingAdjudication === true
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1655
|
+
/*
|
|
1656
|
+
* [T7][J2/J6] 负责人任务时长聚合:只渲染服务端下发的 leaderEstimate
|
|
1657
|
+
* (plan.ts deriveLeaderEstimate 读时派生,经 serialisePlan→derivePlanSnapshot
|
|
1658
|
+
* 同源下发)。客户端严禁求和、不推导状态机:reported===expected 仅作
|
|
1659
|
+
* 措辞选择(J1:全员 sent 才表述完整等式)。totalMinutes=0 合法(F3
|
|
1660
|
+
* 部分和 0),故用 ≥0 守卫而非 positiveNumber;字段缺失/null(J8 空
|
|
1661
|
+
* roster/replanned 旧行/越界 fail-closed)⇒ 不渲染本块。
|
|
1662
|
+
*/
|
|
1663
|
+
const leaderEstimate = item?.leaderEstimate && typeof item.leaderEstimate === 'object' ? item.leaderEstimate : null
|
|
1664
|
+
const leaderExpected = leaderEstimate && Number.isInteger(leaderEstimate.expected) && leaderEstimate.expected > 0 ? leaderEstimate.expected : null
|
|
1665
|
+
const leaderReported = leaderEstimate && Number.isInteger(leaderEstimate.reported) && leaderEstimate.reported >= 0 ? leaderEstimate.reported : null
|
|
1666
|
+
const leaderMinutes = leaderEstimate && Number.isFinite(Number(leaderEstimate.totalMinutes)) && Number(leaderEstimate.totalMinutes) >= 0 ? Number(leaderEstimate.totalMinutes) : null
|
|
1667
|
+
const leaderShown = leaderEstimate !== null && leaderExpected !== null && leaderReported !== null && leaderMinutes !== null
|
|
1668
|
+
const facts: string[] = [t('noTimeLimit')]
|
|
1659
1669
|
if (estimate) facts.push(`${t('estimateMinutes')}:${estimate} ${t('minutes')}`)
|
|
1660
|
-
if (ceiling) facts.push(`${ceilingLabel}:${Math.round(ceiling / 60000)} ${t('minutes')}`)
|
|
1661
|
-
if (deadlineAt) {
|
|
1662
|
-
const left = remainingMs && remainingMs > 0
|
|
1663
|
-
? `(${t('remaining')} ${Math.max(1, Math.round(remainingMs / 60000))} ${t('minutes')})`
|
|
1664
|
-
: ''
|
|
1665
|
-
facts.push(`${t('negotiatedDeadline')}:${formatTime(deadlineAt)}${left}`)
|
|
1666
|
-
}
|
|
1667
1670
|
const notes: any[] = []
|
|
1668
1671
|
if (notice) {
|
|
1669
1672
|
const declared = positiveNumber(notice.declaredMinutes)
|
|
@@ -1693,6 +1696,22 @@ window.__ModuleLoader__.load({
|
|
|
1693
1696
|
notes.push(`${t('noticeChannel')}:${stateText}${reason}`)
|
|
1694
1697
|
}
|
|
1695
1698
|
if (pending) notes.push(`${t('pendingAdjudication')}:${t('pendingAdjudicationHint')}`)
|
|
1699
|
+
/*
|
|
1700
|
+
* [T7][J1 方案 A] 全员 sent(reported===expected)才表述完整等式
|
|
1701
|
+
* 「负责人任务时长=全部下属开工预估之和」;否则必须按「部分和(X/Y)」
|
|
1702
|
+
* 标注并如实列出缺口名单。名单 join 只是展示拼接,不是求和;数值全部
|
|
1703
|
+
* 来自服务端下发的 leaderEstimate,客户端不做任何算术。
|
|
1704
|
+
*/
|
|
1705
|
+
if (leaderShown) {
|
|
1706
|
+
const missingNames = Array.isArray(leaderEstimate.missing) ? leaderEstimate.missing.filter((name: any) => typeof name === 'string' && name !== '') : []
|
|
1707
|
+
const failedNames = Array.isArray(leaderEstimate.failed) ? leaderEstimate.failed.filter((name: any) => typeof name === 'string' && name !== '') : []
|
|
1708
|
+
const gaps = (missingNames.length > 0 ? fill(t('leaderEstimateMissing'), { names: missingNames.join('、') }) : '')
|
|
1709
|
+
+ (failedNames.length > 0 ? fill(t('leaderEstimateFailed'), { names: failedNames.join('、') }) : '')
|
|
1710
|
+
notes.push(leaderReported === leaderExpected
|
|
1711
|
+
? fill(t('leaderEstimateFull'), { minutes: leaderMinutes, reported: leaderReported, expected: leaderExpected })
|
|
1712
|
+
: fill(t('leaderEstimatePartial'), { minutes: leaderMinutes, reported: leaderReported, expected: leaderExpected, gaps }))
|
|
1713
|
+
// 历史 leaderEstimateOverCriterion 字段不再渲染为告警;预估不构成时间判据。
|
|
1714
|
+
}
|
|
1696
1715
|
return h('div', { className: 'dsh-wp-time' },
|
|
1697
1716
|
h('div', { className: 'dsh-wp-time-title' }, t('timeNegotiation')),
|
|
1698
1717
|
facts.length > 0
|
|
@@ -1807,7 +1826,7 @@ window.__ModuleLoader__.load({
|
|
|
1807
1826
|
: null,
|
|
1808
1827
|
/*
|
|
1809
1828
|
* [2.3.9][T4b] 第三层派发看板(用户要求 4/5):部门负责人分配给
|
|
1810
|
-
*
|
|
1829
|
+
* 全球顶尖专家的每位下级、其推理等级(含越界钳制留痕)与实时状态
|
|
1811
1830
|
* 必须对用户与主 Agent 可见,否则「第三层派给了谁、跑没跑完」只存在
|
|
1812
1831
|
* 负责人子会话里。数据源 = 状态行 delegates(applyStatus 消毒 +
|
|
1813
1832
|
* durable workplan-update 回放,刷新/重启不丢),客户端不推导状态。
|
|
@@ -1821,7 +1840,17 @@ window.__ModuleLoader__.load({
|
|
|
1821
1840
|
+ `(${member?.role === 'expert' ? t('delegateExpert') : t('delegateMember')})`
|
|
1822
1841
|
+ `|${t('reasoningEffort')}:${String(member?.effort ?? '?')}`
|
|
1823
1842
|
+ (member?.requested && member.requested !== member.effort ? `(越界钳制自 ${String(member.requested)})` : '')
|
|
1843
|
+
+ (member?.selfEffort ? `|自配档 ${String(member.selfEffort)}${member?.selfEffortRequested && member.selfEffortRequested !== member.selfEffort ? `(钳制自 ${String(member.selfEffortRequested)})` : ''}` : '|自配档 待自配')
|
|
1824
1844
|
+ `|${t(`delegateStatus.${String(member?.status ?? 'running')}`)}`
|
|
1845
|
+
/*
|
|
1846
|
+
* [2.5.6] 第三层闭环可见性:叶子的「待指示/已给指示/已回应」
|
|
1847
|
+
* 与第一层同一套 closure 文案(服务端下发,客户端不推导),
|
|
1848
|
+
* 请示问题随待指示标记一并展示,负责人/用户一眼看到谁在等谁。
|
|
1849
|
+
*/
|
|
1850
|
+
+ (member?.escalation ? `|${t('closureEscalated')}${member.escalation.question ? `:${String(member.escalation.question)}` : ''}` : '')
|
|
1851
|
+
+ (member?.lastInstruction ? `|${t('closureInstructed')}` : '')
|
|
1852
|
+
+ (member?.closure === 'acknowledged' ? `|${t('closureAcknowledged')}` : '')
|
|
1853
|
+
+ (member?.instructionOverdue ? `|${t('closureNoAck')}` : '')
|
|
1825
1854
|
+ (member?.summary ? `:${String(member.summary)}` : ''),
|
|
1826
1855
|
)),
|
|
1827
1856
|
),
|
package/src/comm-format.ts
CHANGED
|
@@ -18,8 +18,23 @@
|
|
|
18
18
|
* 本门禁只负责把「其它门禁都过了、但格式仍不合规」的 done 退回。
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
import {
|
|
22
|
+
checkDepartmentSummary,
|
|
23
|
+
checkExpertReport,
|
|
24
|
+
renderDepartmentSummarySpec,
|
|
25
|
+
renderExpertReportSpec,
|
|
26
|
+
} from './v3-contract.js'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 格式规范版本,随规范内容变更递增。
|
|
30
|
+
*
|
|
31
|
+
* [3.0.0] 1 → 2:用户 2026-11-14 第 7、10 条要求为结果格式增加了两条
|
|
32
|
+
* 结构化精简契约(F10 专家 JSON 汇报、F11 部门 JSON 汇总)。F1–F9 的
|
|
33
|
+
* 文本与判据一字未改(只增不改),新增条目由调用方按接收者层级开关:
|
|
34
|
+
* 专家结果查 F10,部门负责人结果查 F11,未声明层级时两条都不查
|
|
35
|
+
* (历史回放与其它调用点零回归)。
|
|
36
|
+
*/
|
|
37
|
+
export const COMM_FORMAT_VERSION = 2
|
|
23
38
|
|
|
24
39
|
/** 单条不合规项。 */
|
|
25
40
|
export interface CommFormatViolation {
|
|
@@ -55,7 +70,7 @@ export const COMM_FORMAT_SPEC = Object.freeze({
|
|
|
55
70
|
description: '证据块必须是合法 JSON 对象,顶层必须含 status 字段,取值只能是 done / blocked / partial',
|
|
56
71
|
rationale: 'status 是交付门禁的入口条件,缺失或非法则无法判定完成与否' }),
|
|
57
72
|
Object.freeze({ id: 'F3', category: 'phases',
|
|
58
|
-
description: '必须包含三阶段证据:phases.planning
|
|
73
|
+
description: '必须包含三阶段证据:phases.planning(两轮深度思考:第一轮任务深研 problemAnalysis + 第二轮方法流程步骤 approach + 第二轮依据 approachBasis)、phases.execution(实际执行步骤)、phases.verification(逐项验证)',
|
|
59
74
|
rationale: '三阶段是质量闭环的基础,缺任一阶段等于跳过对应质控环节' }),
|
|
60
75
|
Object.freeze({ id: 'F4', category: 'acceptance',
|
|
61
76
|
description: '验收结果必须逐条回应计划的验收标准(A1、A2…),且每条 result=pass 必须附带具体证据(命令输出/文件路径/引用),禁止空证据 pass',
|
|
@@ -75,6 +90,16 @@ export const COMM_FORMAT_SPEC = Object.freeze({
|
|
|
75
90
|
Object.freeze({ id: 'F9', category: 'integrity',
|
|
76
91
|
description: '不得编造、虚构或伪造任何证据、文件路径、命令输出或验收结果;无法确认的项目必须写 unverified',
|
|
77
92
|
rationale: '虚假证据一旦通过交付门禁,用户拿到的就是不可信的成品' }),
|
|
93
|
+
/*
|
|
94
|
+
* [3.0.0] F10/F11:用户 2026-11-14 第 7、10 条要求。F1–F9 是 2.1.0 起的
|
|
95
|
+
* 冻结条目,本次只增不改;两条新条目按接收者层级启用(见 check 的 tier)。
|
|
96
|
+
*/
|
|
97
|
+
Object.freeze({ id: 'F10', category: 'report',
|
|
98
|
+
description: '专家(第三层执行者)结果必须包含 report 对象,只允许 keyResults/keyInfo/importantInfo/leadRequirements 四个字符串数组字段,至少各有 1 条非空内容(keyInfo/important 可为空数组但须存在),每数组最多 6 条、每条最多 200 字符,内部与跨字段不得出现重复表述',
|
|
99
|
+
rationale: '用户要求 7:专家成果必须非常精简地汇报给部门负责人,只要关键信息、关键成果、重要信息和负责人要求的东西,并以 JSON mode 结构化输出' }),
|
|
100
|
+
Object.freeze({ id: 'F11', category: 'report',
|
|
101
|
+
description: '部门负责人结果必须包含 departmentSummary 对象,只允许 keyResults/keyInfo/importantInfo/sources 四个字符串数组字段,keyResults 至少 1 条非空、sources 必须覆盖本部门全部已派发专家,每数组最多 6 条、每条最多 200 字符,内部与跨字段不得出现重复表述',
|
|
102
|
+
rationale: '用户要求 8/10/11:部门负责人必须全面汇总全部专家汇报,汇总报告必须精简、禁止累赘重复,并以 JSON mode 结构化直接交回主 Agent' }),
|
|
78
103
|
]),
|
|
79
104
|
/*
|
|
80
105
|
* [2.2.0][T3/O-2c] 结果块可选字段(方案 §2.4:「模板增加 timeSpentMinutes、
|
|
@@ -101,11 +126,16 @@ export const COMM_FORMAT_SPEC = Object.freeze({
|
|
|
101
126
|
* @param parsed - 已解析的证据块 payload(parseEvidenceBlock 的 payload,可为 null)
|
|
102
127
|
* @param rawOutput - 子 Agent 原始输出全文
|
|
103
128
|
* @param expectedAcceptanceCount - 计划定义的验收标准条数
|
|
129
|
+
* @param options.tier - 接收者层级:'expert' 追加 F10(专家 JSON 汇报),
|
|
130
|
+
* 'leader' 追加 F11(部门 JSON 汇总);省略则两条都不查(历史回放、
|
|
131
|
+
* 旧调用点零回归)
|
|
132
|
+
* @param options.expectedExperts - 本部门已派发的专家名单(F11 覆盖度核对用)
|
|
104
133
|
*/
|
|
105
134
|
export function checkCommFormatCompliance(
|
|
106
135
|
parsed: any,
|
|
107
136
|
rawOutput: string,
|
|
108
137
|
expectedAcceptanceCount: number,
|
|
138
|
+
options: { tier?: 'leader' | 'expert'; expectedExperts?: readonly string[] } = {},
|
|
109
139
|
): CommFormatCheckResult {
|
|
110
140
|
const violations: CommFormatViolation[] = []
|
|
111
141
|
const text = typeof rawOutput === 'string' ? rawOutput : ''
|
|
@@ -198,20 +228,48 @@ export function checkCommFormatCompliance(
|
|
|
198
228
|
message: 'status 为 blocked 但 question 为空:须写清卡在哪一步、已尝试什么、需要谁做什么决定' })
|
|
199
229
|
}
|
|
200
230
|
|
|
231
|
+
/*
|
|
232
|
+
* F10/F11(用户 2026-11-14 第 7、10、11 条):按接收者层级启用。
|
|
233
|
+
* 只拦 done 路径——受阻结果已有更针对性的诊断(F8/三阶段),
|
|
234
|
+
* 不再叠加精简性条目,避免一条 blocked 被反复退回在格式上。
|
|
235
|
+
*/
|
|
236
|
+
if (options.tier === 'expert' && parsed.status === 'done') {
|
|
237
|
+
const report = checkExpertReport(parsed.report)
|
|
238
|
+
for (const item of report.violations) {
|
|
239
|
+
violations.push({ ruleId: 'F10', category: 'report', message: item })
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (options.tier === 'leader' && parsed.status === 'done') {
|
|
243
|
+
const summary = checkDepartmentSummary(parsed.departmentSummary, options.expectedExperts ?? [])
|
|
244
|
+
for (const item of summary.violations) {
|
|
245
|
+
violations.push({ ruleId: 'F11', category: 'report', message: item })
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
201
249
|
return { compliant: violations.length === 0, violations, version: COMM_FORMAT_VERSION }
|
|
202
250
|
}
|
|
203
251
|
|
|
204
252
|
/**
|
|
205
253
|
* 把格式规范渲染为嵌入子 Agent 提示词的文本。
|
|
206
254
|
* 这是「派发工作时附带统一沟通交流格式要求」的具体实现。
|
|
255
|
+
*
|
|
256
|
+
* @param tier - 接收者层级:'expert' 附带专家 JSON 汇报契约(F10),
|
|
257
|
+
* 'leader' 附带部门 JSON 汇总契约(F11);省略时两条都不带。
|
|
207
258
|
*/
|
|
208
|
-
export function renderCommFormatSpec(): string {
|
|
259
|
+
export function renderCommFormatSpec(tier?: 'leader' | 'expert'): string {
|
|
209
260
|
const lines: string[] = [
|
|
210
261
|
'沟通交流格式规范(v' + String(COMM_FORMAT_VERSION) + ',主 Agent 与部门人员双方认可的结果格式契约):',
|
|
211
262
|
]
|
|
212
|
-
|
|
263
|
+
const scoped = tier === 'expert'
|
|
264
|
+
? COMM_FORMAT_SPEC.requirements.filter((req: any) => req.id !== 'F11')
|
|
265
|
+
: tier === 'leader'
|
|
266
|
+
? COMM_FORMAT_SPEC.requirements.filter((req: any) => req.id !== 'F10')
|
|
267
|
+
: COMM_FORMAT_SPEC.requirements
|
|
268
|
+
for (const req of scoped) {
|
|
213
269
|
lines.push(`- 【${req.id}】${req.description}`)
|
|
214
270
|
}
|
|
271
|
+
if (tier === 'expert') lines.push('', renderExpertReportSpec())
|
|
272
|
+
if (tier === 'leader') lines.push('', renderDepartmentSummarySpec())
|
|
215
273
|
lines.push('不合规的后果:主 Agent 收到结果后按本规范逐条核验;任一不合规,结果立刻退回,你将收到列明不合规条目的退回通知,须全部修正后重新提交完整结果。')
|
|
216
274
|
return lines.join('\n')
|
|
217
275
|
}
|
package/src/criterion.ts
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [3.0.1][历史模块] 「简单」判据 v2 · 判据层(criterion layer)。
|
|
3
|
+
*
|
|
4
|
+
* **生产已停用**:用户已取消部门负责人及全球顶尖专家的执行时限,
|
|
5
|
+
* `criterionV2Active()` 现在无条件返回 false,任何环境变量、计划时间或旧字段
|
|
6
|
+
* 都不能重新开启 `≤10 分钟才能 done` 的间接时间门。本文件保留纯函数,仅供
|
|
7
|
+
* 旧记录回放、历史审计和既有单元测试解释当时规则,不参与新任务结算。
|
|
8
|
+
*
|
|
9
|
+
* 口径来源(历史,逐字保留以便追溯):
|
|
10
|
+
* - reports/simple-criterion-v2-spec.md(用户 2026-11-13 裁决 B/B/B/B/A/A/B):
|
|
11
|
+
* S-Q1-1..6 / S-Q2-1..4 / S-Q3-1..4 / S-Q4-1..5 / S-Q5-1..5 / S-Q6-1..5 / S-Q7-1..5,
|
|
12
|
+
* §3.5 唯一判定链(met / exception-approved / unmet 三选一)。
|
|
13
|
+
* - reports/simple-criterion-v2-touchpoints.md C05–C10 / C22 / C29(机制落点)。
|
|
14
|
+
* - reports/simple-criterion-v2-open-decisions.md D-1~D-4 推荐项(均选 A,
|
|
15
|
+
* **待用户裁定**;本模块按推荐实现,裁定前不得据以宣称达标)。
|
|
16
|
+
*
|
|
17
|
+
* 分层纪律(Q7-B,红线):
|
|
18
|
+
* - 本模块只承载**判据层**(完成目标 ≤10 分钟);**运行层**安全兜底
|
|
19
|
+
* (CHILD_TIMEOUT_MS=900000 / MAX_CHILD_TIMEOUT_MS=7200000 /
|
|
20
|
+
* deriveSubtaskTimeoutMs 公式 / L4 结算)数值与公式一律不改。
|
|
21
|
+
* - 判据层不改变运行层时限;运行层允许延长不等于判据层达标。
|
|
22
|
+
*
|
|
23
|
+
* 历史生效边界(Q5-A/D-1;当前已全部失效):
|
|
24
|
+
* - 旧版本曾用 DSH_WORKPLAN_CRITERION_V2 与 _SINCE 按计划创建时间开启;
|
|
25
|
+
* - [3.0.1] 该开关已被硬编码关闭,且不得恢复。即使环境变量齐全、计划新建,
|
|
26
|
+
* `criterionV2Active()` 仍为 false;时长不参与 done 判定。
|
|
27
|
+
* - `evaluateCriterion` 等纯函数仍可被历史测试/审计直接调用,但其结论不会
|
|
28
|
+
* 进入生产结算路径。
|
|
29
|
+
*
|
|
30
|
+
* 本模块不 import plan.ts / runtime.ts(避免循环依赖):聚合结果
|
|
31
|
+
* (LeaderEstimateSummary 形状)由调用方以参数传入。
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/** [历史] 旧判据层目标(分钟);仅供纯函数审计,不参与新任务验收。 */
|
|
35
|
+
export const CRITERION_TARGET_MINUTES = 10
|
|
36
|
+
|
|
37
|
+
/** 结算判据三选一(spec §3.5 第 4 步)。 */
|
|
38
|
+
export const CRITERION_RESULTS = ['met', 'unmet', 'exception-approved'] as const
|
|
39
|
+
export type CriterionResult = (typeof CRITERION_RESULTS)[number]
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* [SCv2-T4][Q1-B/S-Q1-2] 用户例外批准留痕(最终定名 criterionException)。
|
|
43
|
+
*
|
|
44
|
+
* 5 项口径(spec S-Q1-2):任务 ID(由所在状态行 subtaskId 承载)、批准原文/来源
|
|
45
|
+
* (reason + 可选 source)、批准时间(at,epoch 毫秒;展示按 Asia/Shanghai)、
|
|
46
|
+
* 放宽后的分钟数(extendedMinutes / extendedMs,延期场景由 runtime 回填)、
|
|
47
|
+
* 适用范围(scope:仅本任务 task / 本计划 plan)。无留痕=未批准。
|
|
48
|
+
*/
|
|
49
|
+
export interface CriterionException {
|
|
50
|
+
readonly approvedBy: 'user'
|
|
51
|
+
readonly at: number
|
|
52
|
+
readonly reason: string
|
|
53
|
+
readonly source?: string
|
|
54
|
+
readonly scope: 'task' | 'plan'
|
|
55
|
+
readonly extendedMs?: number
|
|
56
|
+
readonly extendedMinutes?: number
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isRecord(value: unknown): value is Record<string, any> {
|
|
60
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* fail-closed 消毒(与 sanitizeDelegateEstimate 同风格):任一必填项缺失/非法
|
|
65
|
+
* ⇒ 整个批准丢弃(返回 null),绝不入库脏值、绝不把「未批准」洗成「已批准」。
|
|
66
|
+
*/
|
|
67
|
+
export function sanitizeCriterionException(value: unknown): CriterionException | null {
|
|
68
|
+
if (!isRecord(value)) return null
|
|
69
|
+
if (value.approvedBy !== 'user') return null
|
|
70
|
+
const at = Number(value.at)
|
|
71
|
+
if (!Number.isFinite(at) || at <= 0) return null
|
|
72
|
+
const reason = typeof value.reason === 'string' ? value.reason.trim() : ''
|
|
73
|
+
if (reason === '') return null
|
|
74
|
+
if (value.scope !== 'task' && value.scope !== 'plan') return null
|
|
75
|
+
const extendedMs = Number(value.extendedMs)
|
|
76
|
+
const extendedMinutes = Number(value.extendedMinutes)
|
|
77
|
+
return {
|
|
78
|
+
approvedBy: 'user',
|
|
79
|
+
at,
|
|
80
|
+
reason: reason.slice(0, 2000),
|
|
81
|
+
...(typeof value.source === 'string' && value.source.trim() !== ''
|
|
82
|
+
? { source: value.source.trim().slice(0, 500) }
|
|
83
|
+
: {}),
|
|
84
|
+
scope: value.scope,
|
|
85
|
+
...(Number.isFinite(extendedMs) && extendedMs > 0 ? { extendedMs: Math.floor(extendedMs) } : {}),
|
|
86
|
+
...(Number.isFinite(extendedMinutes) && extendedMinutes > 0
|
|
87
|
+
? { extendedMinutes: Math.round(extendedMinutes * 100) / 100 }
|
|
88
|
+
: {}),
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* [3.0.1] 判据 v2 是否对该计划生效。
|
|
94
|
+
*
|
|
95
|
+
* 现在恒为 false:这是取消执行时限后的硬边界,不是默认值。保留参数是为了
|
|
96
|
+
* 兼容旧调用签名与历史测试;任何环境变量都不能让判据重新进入生产结算。
|
|
97
|
+
*/
|
|
98
|
+
export function criterionV2Active(
|
|
99
|
+
planCreatedAt: unknown,
|
|
100
|
+
env: Record<string, string | undefined> = process.env,
|
|
101
|
+
): boolean {
|
|
102
|
+
// 用户已取消部门负责人及全球顶尖专家的执行时限:历史环境变量不得重新启用
|
|
103
|
+
// “≤10 分钟才能 done”的间接时间门。evaluateCriterion 仍保留供历史记录/回放审计。
|
|
104
|
+
void planCreatedAt
|
|
105
|
+
void env
|
|
106
|
+
return false
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* [SCv2-T4][Q6-A/C28/C29] 单次尝试墙钟(毫秒)=结算时间 − 尝试起点。
|
|
111
|
+
*
|
|
112
|
+
* 数据源只认 journal 时间戳(startedAt/finishedAt),绝不采用模型自报分钟数
|
|
113
|
+
* (S-Q6-3)。已知陷阱(touchpoints C29 ⚠):预算重置会清空 startedAt/finishedAt
|
|
114
|
+
* ——缺失时返回 null(「未验证」),**绝不返回 0**(否则把「计时被清空」误判成
|
|
115
|
+
* 「0 分钟完成」)。每次尝试独立计量,不跨尝试累计(S-Q6-1/2)。
|
|
116
|
+
*/
|
|
117
|
+
export function attemptWallClockMsOf(row: unknown): number | null {
|
|
118
|
+
if (!isRecord(row)) return null
|
|
119
|
+
// null/undefined 必须显式拒绝:Number(null)===0 会把「计时被重置清空」
|
|
120
|
+
// 误判成「0 分钟完成」(Q6-A 唯一实现陷阱,touchpoints C29 ⚠)。
|
|
121
|
+
if (row.startedAt === null || row.startedAt === undefined) return null
|
|
122
|
+
if (row.finishedAt === null || row.finishedAt === undefined) return null
|
|
123
|
+
const started = Number(row.startedAt)
|
|
124
|
+
const finished = Number(row.finishedAt)
|
|
125
|
+
if (!Number.isFinite(started) || !Number.isFinite(finished)) return null
|
|
126
|
+
return Math.max(0, finished - started)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** 事前条件输入(分钟);complete=false 表示预估未齐/缺失(D-3 推荐 A 严格口径)。 */
|
|
130
|
+
export interface CriterionExAnte {
|
|
131
|
+
readonly minutes: number | null
|
|
132
|
+
readonly complete: boolean
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* [SCv2-T4][Q4-B/D-2 推荐 A/D-3 推荐 A] 部门行事前预估口径。
|
|
137
|
+
*
|
|
138
|
+
* - 有叶子(leaderEstimate 非 null):事前值=全部叶子最新 sent 预估之和;
|
|
139
|
+
* reported===expected 才算「齐」(部分和不得视为达标,S-Q4-5/D-3)。
|
|
140
|
+
* - 无叶子直做(leaderEstimate null):事前值=负责人自身开工预估
|
|
141
|
+
* (row.timeNotice.declaredMinutes,D-2 推荐 A,对称于叶子之和);缺失⇒不齐。
|
|
142
|
+
* 绝不因「没有叶子」而自动豁免(S-Q4-4)。
|
|
143
|
+
*
|
|
144
|
+
* leaderEstimate 由调用方传 plan.ts deriveLeaderEstimate 的结果(形状兼容),
|
|
145
|
+
* 本模块不重复求和、不反写台账(F6/J8 同纪律)。
|
|
146
|
+
*/
|
|
147
|
+
export function criterionExAnte(
|
|
148
|
+
row: unknown,
|
|
149
|
+
leaderEstimate: { totalMinutes: number; reported: number; expected: number } | null | undefined,
|
|
150
|
+
): CriterionExAnte {
|
|
151
|
+
if (leaderEstimate && Number.isFinite(Number(leaderEstimate.totalMinutes))) {
|
|
152
|
+
return {
|
|
153
|
+
minutes: Number(leaderEstimate.totalMinutes),
|
|
154
|
+
complete: leaderEstimate.reported === leaderEstimate.expected && leaderEstimate.expected > 0,
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const notice = isRecord(row) && isRecord(row.timeNotice) ? row.timeNotice : null
|
|
158
|
+
const declared = notice ? Number(notice.declaredMinutes) : NaN
|
|
159
|
+
if (Number.isFinite(declared) && declared > 0) return { minutes: declared, complete: true }
|
|
160
|
+
return { minutes: null, complete: false }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** 判据结算输出(与 T5 参考实现 referenceQ3Settlement 同形,供生产绑定)。 */
|
|
164
|
+
export interface CriterionEvaluation {
|
|
165
|
+
readonly criterionResult: CriterionResult
|
|
166
|
+
readonly canBeDone: boolean
|
|
167
|
+
readonly needsReplacement: boolean
|
|
168
|
+
readonly exceptionRecorded: boolean
|
|
169
|
+
readonly reasons: string[]
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* [SCv2-T4][spec §3.5 第 4 步 / S-Q6-5 / D-4 推荐 A] 判据层结算判定(纯函数)。
|
|
174
|
+
*
|
|
175
|
+
* 达标(met)=事前预估之和 ≤10 **且** 事后单次尝试墙钟 ≤10(双条件同时满足);
|
|
176
|
+
* 任一不满足且无有效用户批准 ⇒ unmet(不得 done、记违规、转接替行);
|
|
177
|
+
* 有有效用户批准 ⇒ exception-approved(可 done、留例外、不生成接替行)。
|
|
178
|
+
*
|
|
179
|
+
* 批准时机(C-4 推荐 A,待裁定):批准必须不晚于本次结算(at <= settledAt);
|
|
180
|
+
* 结算后追认一律无效(防「事后洗白」),只能批准接替行。
|
|
181
|
+
*
|
|
182
|
+
* 严格口径(D-3 推荐 A,待裁定):事前预估未齐 / 墙钟缺失(被重置清空)
|
|
183
|
+
* ⇒ 不得宣称达标,按 unmet 处理并如实给出 reasons;受平台缺陷影响的行
|
|
184
|
+
* 可经 Q1 例外审批留痕后豁免(exception-approved 分支)。
|
|
185
|
+
*/
|
|
186
|
+
export function evaluateCriterion(input: {
|
|
187
|
+
exAnteMinutes: number | null
|
|
188
|
+
exAnteComplete: boolean
|
|
189
|
+
wallClockMs: number | null
|
|
190
|
+
exception?: CriterionException | null
|
|
191
|
+
settledAt?: number
|
|
192
|
+
}): CriterionEvaluation {
|
|
193
|
+
const reasons: string[] = []
|
|
194
|
+
let over = false
|
|
195
|
+
if (!input.exAnteComplete) {
|
|
196
|
+
over = true
|
|
197
|
+
reasons.push('ex-ante-incomplete:事前预估未齐或缺失(D-3 严格口径,不得视为达标)')
|
|
198
|
+
} else if (input.exAnteMinutes !== null && input.exAnteMinutes > CRITERION_TARGET_MINUTES) {
|
|
199
|
+
over = true
|
|
200
|
+
reasons.push(`ex-ante-over:事前预估 ${input.exAnteMinutes} 分钟 > ${CRITERION_TARGET_MINUTES} 分钟目标`)
|
|
201
|
+
}
|
|
202
|
+
if (input.wallClockMs === null) {
|
|
203
|
+
over = true
|
|
204
|
+
reasons.push('wall-clock-unverified:单次尝试墙钟缺失(计时被重置或无时间戳),不得按 0 分钟判达标(Q6-A)')
|
|
205
|
+
} else if (input.wallClockMs > CRITERION_TARGET_MINUTES * 60_000) {
|
|
206
|
+
over = true
|
|
207
|
+
reasons.push(`wall-clock-over:本次尝试墙钟 ${(input.wallClockMs / 60_000).toFixed(2)} 分钟 > ${CRITERION_TARGET_MINUTES} 分钟目标`)
|
|
208
|
+
}
|
|
209
|
+
if (!over) {
|
|
210
|
+
return { criterionResult: 'met', canBeDone: true, needsReplacement: false, exceptionRecorded: false, reasons }
|
|
211
|
+
}
|
|
212
|
+
const exception = input.exception ?? null
|
|
213
|
+
if (exception) {
|
|
214
|
+
const settledAt = Number.isFinite(Number(input.settledAt)) ? Number(input.settledAt) : Date.now()
|
|
215
|
+
if (exception.at <= settledAt) {
|
|
216
|
+
return {
|
|
217
|
+
criterionResult: 'exception-approved',
|
|
218
|
+
canBeDone: true,
|
|
219
|
+
needsReplacement: false,
|
|
220
|
+
exceptionRecorded: true,
|
|
221
|
+
reasons: [...reasons, 'user-exception:用户明确批准并留痕(Q1-B 唯一例外通道)'],
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
reasons.push('approval-after-settlement:批准时间晚于本次结算,事后追认无效(C-4 推荐 A)')
|
|
225
|
+
}
|
|
226
|
+
return { criterionResult: 'unmet', canBeDone: false, needsReplacement: true, exceptionRecorded: false, reasons }
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* [SCv2-T4] T5 参考实现 referenceQ3Settlement 的同口径生产适配器(分钟入参)。
|
|
231
|
+
* 生产接线落盘后 T5 只需把 referenceQ3* 替换为本导出,断言口径保持不变。
|
|
232
|
+
*/
|
|
233
|
+
export function q3SettlementVerdict(input: {
|
|
234
|
+
declaredMinutes?: number
|
|
235
|
+
wallClockMinutes?: number
|
|
236
|
+
userApproved?: boolean
|
|
237
|
+
}): CriterionEvaluation {
|
|
238
|
+
const exception: CriterionException | null = input.userApproved === true
|
|
239
|
+
? { approvedBy: 'user', at: 1, reason: 'user-approved(参考夹具口径)', scope: 'task' }
|
|
240
|
+
: null
|
|
241
|
+
return evaluateCriterion({
|
|
242
|
+
exAnteMinutes: Number(input.declaredMinutes ?? 0),
|
|
243
|
+
exAnteComplete: true,
|
|
244
|
+
wallClockMs: Number(input.wallClockMinutes ?? 0) * 60_000,
|
|
245
|
+
exception,
|
|
246
|
+
settledAt: Date.now(),
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* [SCv2-T4][D-4 推荐 A] 判据违规审计条目(append-only,绝不抹除)。
|
|
252
|
+
* 行级最终结果取最后一次(接替)尝试;原始未批准超时保留在本数组供审计,
|
|
253
|
+
* 防「续跑洗白」。上限 20 条与 timeJournal 同纪律。
|
|
254
|
+
*/
|
|
255
|
+
export function appendCriterionViolation(
|
|
256
|
+
existing: unknown,
|
|
257
|
+
entry: { at: number; attempt: number; wallClockMs: number | null; exAnteMinutes: number | null; reasons: string[] },
|
|
258
|
+
): Array<Record<string, unknown>> {
|
|
259
|
+
const list = Array.isArray(existing) ? existing.filter(isRecord) : []
|
|
260
|
+
return [...list, { ...entry, kind: 'criterion-overrun' }].slice(-20)
|
|
261
|
+
}
|