dsh-workplan 3.0.3 → 3.0.9

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/client.js CHANGED
@@ -224,6 +224,7 @@ window.__ModuleLoader__.load({
224
224
  "vizStageTitle": "分步进度",
225
225
  "vizOverall": "总体进度",
226
226
  "allPlansHint": "上面是当前各会话最新计划的合计;历史计划不在此汇总,下面每张卡片只统计本计划。",
227
+ "trimNotice": "计划数据过大,部分会话或明细已在服务端省略,当前仅展示子集;缩小范围或会话后再看完整数据。",
227
228
  "openHint": "打开左侧「任务进度」看完整安排。",
228
229
  "timeNegotiation": "执行时间(无时限)",
229
230
  "noTimeLimit": "部门负责人和全球顶尖专家执行无时限;预估仅供参考,不影响完成验收",
@@ -459,6 +460,7 @@ window.__ModuleLoader__.load({
459
460
  "vizStageTitle": "Step progress",
460
461
  "vizOverall": "Overall progress",
461
462
  "allPlansHint": "These totals cover the latest plan in each live session; older plans are not included. Each card below counts only its own plan.",
463
+ "trimNotice": "The plan data was too large, so some sessions or details were omitted on the server; only a subset is shown. Narrow the scope to see the full data.",
462
464
  "openHint": "Open “Task progress” on the left for the full plan.",
463
465
  "timeNegotiation": "Execution time (no limit)",
464
466
  "noTimeLimit": "Department leads and domain experts have no execution time limit; estimates are informational and do not affect acceptance",
@@ -1539,37 +1541,178 @@ window.__ModuleLoader__.load({
1539
1541
  if (!payload || payload.ok !== true) {
1540
1542
  throw new Error(asText(payload?.error) || '计划接口返回异常');
1541
1543
  }
1542
- return Array.isArray(payload.sessions) ? payload.sessions : [];
1544
+ /*
1545
+ * [复审修复] 返回完整载荷,不再只回 sessions:服务端 2.5MB 上限
1546
+ * (runtime.ts MAX_PLANS_RESPONSE_BYTES + trimPlansPayload)裁剪时会置
1547
+ * truncated / omittedSessions / omittedDetail,旧实现把它们丢掉,看板
1548
+ * 静默少显示数据。向后兼容:调用方仍取 .sessions(数组)。
1549
+ *
1550
+ * omittedDetail 在服务端是挂在每个 session 项上的(trimPlansPayload
1551
+ * 里 sessions[].omittedDetail = true),顶层也可能有;两者都要看。
1552
+ */
1553
+ const sessions = Array.isArray(payload.sessions) ? payload.sessions : [];
1554
+ const omittedSessions = typeof payload.omittedSessions === 'number'
1555
+ && Number.isFinite(payload.omittedSessions) ? payload.omittedSessions : 0;
1556
+ const omittedDetail = payload.omittedDetail === true
1557
+ || sessions.some((item) => item && item.omittedDetail === true);
1558
+ return { sessions, truncated: payload.truncated === true, omittedSessions, omittedDetail };
1559
+ }
1560
+ /*
1561
+ * [3.0.6][第 2 批] 看板轮询按会话共享。
1562
+ *
1563
+ * 旧实现里每个 TurnCard 都调用 usePlans(sessionId),各自 4 秒一次请求:
1564
+ * 一个会话有 30 张卡就是 30 请求/4s,服务端每次还要重建无内存记录的计划。
1565
+ * 现在同一 key(''=全部会话,或具体 sessionId)只有一个轮询器 + 一组订阅者,
1566
+ * 最后一个订阅者卸载时才停止;新订阅者立即拿到当前快照,不重复请求。
1567
+ */
1568
+ const planPolls = new Map();
1569
+ /* [复审修复] 单次轮询的挂死上限:到点按超时错误路径处理,绝不让 running 永真。 */
1570
+ const PLAN_POLL_TIMEOUT_MS = 15000;
1571
+ function emptyPlansState() {
1572
+ return {
1573
+ loading: true,
1574
+ sessions: [],
1575
+ truncated: false,
1576
+ omittedSessions: 0,
1577
+ omittedDetail: false,
1578
+ error: null,
1579
+ updatedAt: null,
1580
+ };
1543
1581
  }
1544
1582
  function usePlans(sessionId) {
1545
- const [state, setState] = useState({ loading: true, sessions: [], error: null, updatedAt: null });
1546
- const load = useCallback(async (signal) => {
1547
- try {
1548
- const sessions = await fetchPlans(sessionId, signal);
1549
- if (signal?.aborted)
1550
- return;
1551
- setState({ loading: false, sessions, error: null, updatedAt: Date.now() });
1583
+ const key = sessionId || '';
1584
+ const [state, setState] = useState(() => planPolls.get(key)?.state ?? emptyPlansState());
1585
+ useEffect(() => {
1586
+ let entry = planPolls.get(key);
1587
+ if (!entry) {
1588
+ entry = {
1589
+ state: emptyPlansState(),
1590
+ listeners: new Set(),
1591
+ timer: null,
1592
+ controller: null,
1593
+ running: false,
1594
+ run: null,
1595
+ timedOut: false,
1596
+ onVisible: null,
1597
+ };
1598
+ planPolls.set(key, entry);
1552
1599
  }
1553
- catch (error) {
1554
- if (signal?.aborted)
1555
- return;
1556
- setState((previous) => ({
1557
- ...previous,
1558
- loading: false,
1559
- error: error instanceof Error ? error.message : String(error),
1560
- }));
1600
+ const listener = (next) => setState(next);
1601
+ entry.listeners.add(listener);
1602
+ setState(entry.state);
1603
+ if (!entry.run) {
1604
+ entry.run = async () => {
1605
+ if (entry.running)
1606
+ return;
1607
+ /*
1608
+ * [复审修复] 后台标签页跳过本次轮询:interval 保留,回到前台后
1609
+ * 自然恢复;另有 visibilitychange 监听立即补一轮(见下方注册)。
1610
+ */
1611
+ if (typeof document !== 'undefined' && document.visibilityState === 'hidden')
1612
+ return;
1613
+ entry.running = true;
1614
+ entry.timedOut = false;
1615
+ const controller = new AbortController();
1616
+ entry.controller = controller;
1617
+ /*
1618
+ * [复审修复] 15s 超时:一次挂死的请求不再让 entry.running 永真、
1619
+ * 看板永久冻结。卸载中止保持静默;超时中止走错误路径:
1620
+ * console.warn + 结束本次 running,interval 继续。
1621
+ *
1622
+ * 优先 AbortSignal.timeout + AbortSignal.any(无 JS 侧计时器句柄,
1623
+ * 不存在悬挂/句柄卫生问题);宿主运行时不支持 any() 时退回手动
1624
+ * setTimeout 控制器(等效实现),句柄挂在 entry 上,finally 与
1625
+ * 卸载 cleanup 双路清理——注意这里禁止 unref:这是收束类计时器
1626
+ * (tests/handle-policy.test.ts 契约),unref 会让 node 事件循环
1627
+ * 提前排空、看板错误路径永远到不了。
1628
+ */
1629
+ const anySignal = typeof AbortSignal.any === 'function'
1630
+ && typeof AbortSignal.timeout === 'function';
1631
+ let timeoutTimer = null;
1632
+ const signal = anySignal
1633
+ ? AbortSignal.any([controller.signal, AbortSignal.timeout(PLAN_POLL_TIMEOUT_MS)])
1634
+ : (() => {
1635
+ timeoutTimer = setTimeout(() => {
1636
+ entry.timedOut = true;
1637
+ controller.abort();
1638
+ }, PLAN_POLL_TIMEOUT_MS);
1639
+ return controller.signal;
1640
+ })();
1641
+ entry.timeoutTimer = timeoutTimer;
1642
+ try {
1643
+ const plansPayload = await fetchPlans(sessionId, signal);
1644
+ if (signal.aborted)
1645
+ return;
1646
+ entry.state = {
1647
+ loading: false,
1648
+ sessions: plansPayload.sessions,
1649
+ truncated: plansPayload.truncated === true,
1650
+ omittedSessions: plansPayload.omittedSessions,
1651
+ omittedDetail: plansPayload.omittedDetail === true,
1652
+ error: null,
1653
+ updatedAt: Date.now(),
1654
+ };
1655
+ }
1656
+ catch (error) {
1657
+ /*
1658
+ * 静默条件:仅「主动中止(卸载/重入)」。超时的判定两路都要覆盖——
1659
+ * 手动兜底路径置了 entry.timedOut;AbortSignal.any 路径里超时只体现为
1660
+ * 组合 signal 被中止而 controller 没有(卸载恰好相反:controller 先中止)。
1661
+ */
1662
+ const timedOut = entry.timedOut === true
1663
+ || (signal.aborted === true && controller.signal.aborted === false);
1664
+ if (signal.aborted && !timedOut)
1665
+ return;
1666
+ if (timedOut) {
1667
+ console.warn('[dsh-workplan] plans 轮询超时(15000ms),已结束本轮,下一轮继续', error);
1668
+ }
1669
+ entry.state = {
1670
+ ...entry.state,
1671
+ loading: false,
1672
+ error: error instanceof Error ? error.message : String(error),
1673
+ };
1674
+ }
1675
+ finally {
1676
+ if (timeoutTimer !== null)
1677
+ clearTimeout(timeoutTimer);
1678
+ entry.timeoutTimer = null;
1679
+ entry.running = false;
1680
+ entry.timedOut = false;
1681
+ entry.controller = null;
1682
+ entry.listeners.forEach((notify) => notify(entry.state));
1683
+ }
1684
+ };
1685
+ entry.run();
1686
+ entry.timer = setInterval(() => entry.run(), 4000);
1687
+ /*
1688
+ * [复审修复] 回到前台立即补一轮:后台期间 interval 触发的轮询
1689
+ * 全部被跳过,不补的话用户切回来最多干等一个周期。
1690
+ */
1691
+ entry.onVisible = () => {
1692
+ if (typeof document !== 'undefined' && document.visibilityState === 'visible') {
1693
+ entry.run?.();
1694
+ }
1695
+ };
1696
+ if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
1697
+ document.addEventListener('visibilitychange', entry.onVisible);
1698
+ }
1561
1699
  }
1562
- }, [sessionId]);
1563
- useEffect(() => {
1564
- const controller = new AbortController();
1565
- load(controller.signal);
1566
- const timer = setInterval(() => load(controller.signal), 4000);
1567
1700
  return () => {
1568
- controller.abort();
1569
- clearInterval(timer);
1701
+ entry.listeners.delete(listener);
1702
+ if (entry.listeners.size === 0) {
1703
+ if (entry.timer)
1704
+ clearInterval(entry.timer);
1705
+ if (entry.timeoutTimer)
1706
+ clearTimeout(entry.timeoutTimer);
1707
+ entry.controller?.abort();
1708
+ if (typeof document !== 'undefined' && typeof document.removeEventListener === 'function') {
1709
+ document.removeEventListener('visibilitychange', entry.onVisible);
1710
+ }
1711
+ planPolls.delete(key);
1712
+ }
1570
1713
  };
1571
- }, [load]);
1572
- return { ...state, reload: () => load() };
1714
+ }, [key, sessionId]);
1715
+ return { ...state, reload: () => planPolls.get(key)?.run?.() };
1573
1716
  }
1574
1717
  function ErrorBanner({ message, onRetry, t }) {
1575
1718
  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')));
@@ -2762,7 +2905,7 @@ window.__ModuleLoader__.load({
2762
2905
  /* [T4] 回到顶部的显示阈值(px):scrollTop 严格大于该值才显示。 */
2763
2906
  const BACK_TOP_THRESHOLD = 200;
2764
2907
  function Dashboard({ t }) {
2765
- const { sessions, error, loading, updatedAt, reload } = usePlans();
2908
+ const { sessions, error, loading, updatedAt, reload, truncated, omittedSessions, omittedDetail, } = usePlans();
2766
2909
  const [openSessionId, setOpenSessionId] = useState(null);
2767
2910
  const selectSession = useCallback((sessionId) => {
2768
2911
  if (!sessionId)
@@ -2944,7 +3087,18 @@ window.__ModuleLoader__.load({
2944
3087
  className: 'dsh-wp',
2945
3088
  ref: (node) => { if (node !== panelEl)
2946
3089
  setPanelEl(node); },
2947
- }, h('header', { className: 'dsh-wp-header' }, h('div', null, h('h1', { className: 'dsh-wp-title' }, t('title')), h('p', { className: 'dsh-wp-subtitle' }, t('subtitle')), h('div', { className: 'dsh-wp-meta' }, updatedAt ? h('span', null, `${t('updatedAt')} ${formatTime(updatedAt)}`) : null, h('span', null, `${t('scopeAll')}:${activeSessions.length} ${t('sessionCount')},${t('taskBreakdown')} ${totals.total} ${t('subtaskCount')}`))), h('button', { type: 'button', className: 'dsh-wp-button', onClick: reload, disabled: loading }, t('refresh'))), error ? h(ErrorBanner, { message: error, onRetry: reload, t }) : null, activeSessions.length > 0 ? h('div', { className: 'dsh-wp-statbar', role: 'list' }, h('div', { className: 'dsh-wp-stat dsh-wp-stat--tasks', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, activeSessions.length), h('div', { className: 'dsh-wp-stat-label' }, t('sessionCount'))), h('div', { className: 'dsh-wp-stat', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.total), h('div', { className: 'dsh-wp-stat-label' }, t('workItems'))), h('div', { className: 'dsh-wp-stat dsh-wp-stat--done', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.done), h('div', { className: 'dsh-wp-stat-label' }, t('stats.done'))), h('div', { className: 'dsh-wp-stat dsh-wp-stat--active', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.inProgress), h('div', { className: 'dsh-wp-stat-label' }, t('stats.inProgress'))), h('div', { className: 'dsh-wp-stat dsh-wp-stat--blocked', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.blocked), h('div', { className: 'dsh-wp-stat-label' }, t('stats.blocked')))) : null, activeSessions.length > 0 ? h('div', { className: 'dsh-wp-scope-note' }, t('allPlansHint')) : null, activeSessions.length === 0
3090
+ }, h('header', { className: 'dsh-wp-header' }, h('div', null, h('h1', { className: 'dsh-wp-title' }, t('title')), h('p', { className: 'dsh-wp-subtitle' }, t('subtitle')), h('div', { className: 'dsh-wp-meta' }, updatedAt ? h('span', null, `${t('updatedAt')} ${formatTime(updatedAt)}`) : null, h('span', null, `${t('scopeAll')}:${activeSessions.length} ${t('sessionCount')},${t('taskBreakdown')} ${totals.total} ${t('subtaskCount')}`))), h('button', { type: 'button', className: 'dsh-wp-button', onClick: reload, disabled: loading }, t('refresh'))), error ? h(ErrorBanner, { message: error, onRetry: reload, t }) : null,
3091
+ /*
3092
+ * [复审修复] 服务端裁剪提示:载荷被 2.5MB 上限裁剪(truncated /
3093
+ * omittedSessions / omittedDetail 任一成立)时明确告知「展示为子集」,
3094
+ * 不再静默少显示数据。复用现有 degraded 横幅样式,不新增 CSS/依赖。
3095
+ */
3096
+ (truncated === true || Number(omittedSessions) > 0 || omittedDetail === true)
3097
+ ? h('div', {
3098
+ className: 'dsh-wp-banner dsh-wp-banner--degraded dsh-wp-trim-notice',
3099
+ role: 'status',
3100
+ }, t('trimNotice'))
3101
+ : null, activeSessions.length > 0 ? h('div', { className: 'dsh-wp-statbar', role: 'list' }, h('div', { className: 'dsh-wp-stat dsh-wp-stat--tasks', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, activeSessions.length), h('div', { className: 'dsh-wp-stat-label' }, t('sessionCount'))), h('div', { className: 'dsh-wp-stat', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.total), h('div', { className: 'dsh-wp-stat-label' }, t('workItems'))), h('div', { className: 'dsh-wp-stat dsh-wp-stat--done', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.done), h('div', { className: 'dsh-wp-stat-label' }, t('stats.done'))), h('div', { className: 'dsh-wp-stat dsh-wp-stat--active', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.inProgress), h('div', { className: 'dsh-wp-stat-label' }, t('stats.inProgress'))), h('div', { className: 'dsh-wp-stat dsh-wp-stat--blocked', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.blocked), h('div', { className: 'dsh-wp-stat-label' }, t('stats.blocked')))) : null, activeSessions.length > 0 ? h('div', { className: 'dsh-wp-scope-note' }, t('allPlansHint')) : null, activeSessions.length === 0
2948
3102
  ? h('div', { className: 'dsh-wp-empty' }, h('div', { style: { fontWeight: 650, marginBottom: '4px' } }, t('empty')), h('div', null, t('emptyHint')))
2949
3103
  : h('div', { className: 'dsh-wp-groups' },
2950
3104
  // [用户要求] 总览块(完成率环 + 每个任务的进度)上移到分组之前:
@@ -0,0 +1,7 @@
1
+ # v3.0.3
2
+
3
+ release v3.0.3: latest source + version publish
4
+
5
+ - tag: v3.0.3
6
+ - date: 2026-11-17
7
+ - npm: https://www.npmjs.com/package/dsh-workplan/v/3.0.3
@@ -0,0 +1,7 @@
1
+ # v3.0.9
2
+
3
+ 3.0.9:五步工作法全量审计修复——结果块模板补 approachBasis 字段、全部结算阈值渲染进提示词(消除「40/40/20」简写遮蔽 resources/tools/prepared/evidence 四项下限)、五步证据不完整接入有界回喂(EVIDENCE_INCOMPLETE 闸)、负责人汇总 F11 校验接线生效、缺块/退回改结构化标志(不再依赖错误文案正则);专家汇报回调强制结构化 JSON 结算(非法 JSON 绝不计 done);取消 engines.dsh 版本门槛,各版本 DSH 均可安装使用
4
+
5
+ - tag: v3.0.9
6
+ - date: 2026-11-19
7
+ - npm: https://www.npmjs.com/package/dsh-workplan/v/3.0.9
@@ -54,6 +54,68 @@ const APPROVAL_PATTERNS = [
54
54
  label: '「认可后开始执行」',
55
55
  },
56
56
  ];
57
+ /*
58
+ * [3.0.2] 命中候选的语境排除:否定 / 引用 / 规章制度转述。
59
+ *
60
+ * 正则只看字面,两种常见文本会被误按:
61
+ * 1. 否定句——「不用经用户认可再执行,直接干」:用户恰恰在**取消**门槛,
62
+ * 字面却完整命中「经…认可再…」;
63
+ * 2. 引用/转述——用户粘贴规章制度原文(「制度规定:须经用户批准后再执行」)
64
+ * 或把门槛语当引文讨论,不是在给自己的任务设门槛。
65
+ *
66
+ * 排除判据(命中位置之前约 40 字符窗口内,命中任一则该条候选不触发):
67
+ * - 否定词:不用/无需/不必/不需要/禁止/谈不上;单字 勿/别 须紧贴命中
68
+ * (6 字内且无句断),避免「识别/分别/级别」里的「别」误伤;
69
+ * - 引号包裹:「」“”‘’以及直引号成对出现、且命中片段位于引号内;
70
+ * - 转述字样:原文/制度/规定/条款。
71
+ * 窗口只回看、不越过句读推断语义——拿不准时维持原判定(宁漏勿冤的
72
+ * 方向对漏判更有利:漏判只是回到默认自动派发,误判才会把普通任务按住)。
73
+ */
74
+ const NEGATION_WORDS = Object.freeze(['不用', '无需', '不必', '不需要', '禁止', '谈不上']);
75
+ /** 单字否定必须紧贴命中(其后 ≤6 字即命中、中间无句末符),否则视为普通用字。 */
76
+ const SINGLE_CHAR_NEGATION = /[勿别][^。;!?\n]{0,6}$/;
77
+ /** 用户转述规章制度时的常见字样(40 字窗口内出现即视为引用而非本任务门槛)。 */
78
+ const RULES_QUOTE_WORDS = Object.freeze(['原文', '制度', '规定', '条款']);
79
+ /** 成对引号:「」“”‘’为不对称对;直引号 " 与 ' 按出现次数奇偶判定。 */
80
+ const QUOTE_PAIRS = Object.freeze([
81
+ ['「', '」'], ['“', '”'], ['‘', '’'], ['"', '"'], ["'", "'"],
82
+ ]);
83
+ function hasNegationBefore(window) {
84
+ for (const word of NEGATION_WORDS) {
85
+ if (window.includes(word))
86
+ return true;
87
+ }
88
+ return SINGLE_CHAR_NEGATION.test(window);
89
+ }
90
+ function isInsideQuotes(text, index) {
91
+ const before = text.slice(0, index);
92
+ for (const [open, close] of QUOTE_PAIRS) {
93
+ if (open === close) {
94
+ let count = 0;
95
+ for (let position = 0; position < before.length; position += 1) {
96
+ if (before[position] === open)
97
+ count += 1;
98
+ }
99
+ if (count % 2 === 1)
100
+ return true;
101
+ }
102
+ else if (before.lastIndexOf(open) > before.lastIndexOf(close)) {
103
+ return true;
104
+ }
105
+ }
106
+ return false;
107
+ }
108
+ /** 命中位置之前约 40 字符窗口内是否存在否定/引用/转述标记。 */
109
+ function hasExemptContext(text, index) {
110
+ const window = text.slice(Math.max(0, index - 40), index);
111
+ if (hasNegationBefore(window))
112
+ return true;
113
+ for (const word of RULES_QUOTE_WORDS) {
114
+ if (window.includes(word))
115
+ return true;
116
+ }
117
+ return isInsideQuotes(text, index);
118
+ }
57
119
  function excerptOf(text, match, max = 60) {
58
120
  const start = Math.max(0, match.index - 6);
59
121
  const end = Math.min(text.length, match.index + match[0].length + 10);
@@ -70,9 +132,23 @@ export function detectApprovalGate(taskText) {
70
132
  return { held: false, matched: [], reason: '' };
71
133
  const matched = [];
72
134
  for (const { re, label } of APPROVAL_PATTERNS) {
73
- const found = re.exec(text);
74
- if (found) {
75
- matched.push({ label, excerpt: excerptOf(text, found) });
135
+ // [3.0.2] 逐处匹配并跳过带否定/引用语境的候选;同一条规则后一处干净命中
136
+ // 仍可触发(如先转述制度、再给自己的任务立门槛)。
137
+ const scanner = new RegExp(re.source, re.flags.includes('g') ? re.flags : `${re.flags}g`);
138
+ let found;
139
+ let hit = null;
140
+ while ((found = scanner.exec(text)) !== null) {
141
+ if (found[0] === '') {
142
+ scanner.lastIndex += 1;
143
+ continue;
144
+ }
145
+ if (!hasExemptContext(text, found.index)) {
146
+ hit = found;
147
+ break;
148
+ }
149
+ }
150
+ if (hit) {
151
+ matched.push({ label, excerpt: excerptOf(text, hit) });
76
152
  // 一条规则命中即可;继续跑完所有规则只为汇总证据,不去重(同义重复无害)。
77
153
  }
78
154
  }
package/lib/client.js CHANGED
@@ -224,6 +224,7 @@ window.__ModuleLoader__.load({
224
224
  "vizStageTitle": "分步进度",
225
225
  "vizOverall": "总体进度",
226
226
  "allPlansHint": "上面是当前各会话最新计划的合计;历史计划不在此汇总,下面每张卡片只统计本计划。",
227
+ "trimNotice": "计划数据过大,部分会话或明细已在服务端省略,当前仅展示子集;缩小范围或会话后再看完整数据。",
227
228
  "openHint": "打开左侧「任务进度」看完整安排。",
228
229
  "timeNegotiation": "执行时间(无时限)",
229
230
  "noTimeLimit": "部门负责人和全球顶尖专家执行无时限;预估仅供参考,不影响完成验收",
@@ -459,6 +460,7 @@ window.__ModuleLoader__.load({
459
460
  "vizStageTitle": "Step progress",
460
461
  "vizOverall": "Overall progress",
461
462
  "allPlansHint": "These totals cover the latest plan in each live session; older plans are not included. Each card below counts only its own plan.",
463
+ "trimNotice": "The plan data was too large, so some sessions or details were omitted on the server; only a subset is shown. Narrow the scope to see the full data.",
462
464
  "openHint": "Open “Task progress” on the left for the full plan.",
463
465
  "timeNegotiation": "Execution time (no limit)",
464
466
  "noTimeLimit": "Department leads and domain experts have no execution time limit; estimates are informational and do not affect acceptance",
@@ -1539,37 +1541,178 @@ window.__ModuleLoader__.load({
1539
1541
  if (!payload || payload.ok !== true) {
1540
1542
  throw new Error(asText(payload?.error) || '计划接口返回异常');
1541
1543
  }
1542
- return Array.isArray(payload.sessions) ? payload.sessions : [];
1544
+ /*
1545
+ * [复审修复] 返回完整载荷,不再只回 sessions:服务端 2.5MB 上限
1546
+ * (runtime.ts MAX_PLANS_RESPONSE_BYTES + trimPlansPayload)裁剪时会置
1547
+ * truncated / omittedSessions / omittedDetail,旧实现把它们丢掉,看板
1548
+ * 静默少显示数据。向后兼容:调用方仍取 .sessions(数组)。
1549
+ *
1550
+ * omittedDetail 在服务端是挂在每个 session 项上的(trimPlansPayload
1551
+ * 里 sessions[].omittedDetail = true),顶层也可能有;两者都要看。
1552
+ */
1553
+ const sessions = Array.isArray(payload.sessions) ? payload.sessions : [];
1554
+ const omittedSessions = typeof payload.omittedSessions === 'number'
1555
+ && Number.isFinite(payload.omittedSessions) ? payload.omittedSessions : 0;
1556
+ const omittedDetail = payload.omittedDetail === true
1557
+ || sessions.some((item) => item && item.omittedDetail === true);
1558
+ return { sessions, truncated: payload.truncated === true, omittedSessions, omittedDetail };
1559
+ }
1560
+ /*
1561
+ * [3.0.6][第 2 批] 看板轮询按会话共享。
1562
+ *
1563
+ * 旧实现里每个 TurnCard 都调用 usePlans(sessionId),各自 4 秒一次请求:
1564
+ * 一个会话有 30 张卡就是 30 请求/4s,服务端每次还要重建无内存记录的计划。
1565
+ * 现在同一 key(''=全部会话,或具体 sessionId)只有一个轮询器 + 一组订阅者,
1566
+ * 最后一个订阅者卸载时才停止;新订阅者立即拿到当前快照,不重复请求。
1567
+ */
1568
+ const planPolls = new Map();
1569
+ /* [复审修复] 单次轮询的挂死上限:到点按超时错误路径处理,绝不让 running 永真。 */
1570
+ const PLAN_POLL_TIMEOUT_MS = 15000;
1571
+ function emptyPlansState() {
1572
+ return {
1573
+ loading: true,
1574
+ sessions: [],
1575
+ truncated: false,
1576
+ omittedSessions: 0,
1577
+ omittedDetail: false,
1578
+ error: null,
1579
+ updatedAt: null,
1580
+ };
1543
1581
  }
1544
1582
  function usePlans(sessionId) {
1545
- const [state, setState] = useState({ loading: true, sessions: [], error: null, updatedAt: null });
1546
- const load = useCallback(async (signal) => {
1547
- try {
1548
- const sessions = await fetchPlans(sessionId, signal);
1549
- if (signal?.aborted)
1550
- return;
1551
- setState({ loading: false, sessions, error: null, updatedAt: Date.now() });
1583
+ const key = sessionId || '';
1584
+ const [state, setState] = useState(() => planPolls.get(key)?.state ?? emptyPlansState());
1585
+ useEffect(() => {
1586
+ let entry = planPolls.get(key);
1587
+ if (!entry) {
1588
+ entry = {
1589
+ state: emptyPlansState(),
1590
+ listeners: new Set(),
1591
+ timer: null,
1592
+ controller: null,
1593
+ running: false,
1594
+ run: null,
1595
+ timedOut: false,
1596
+ onVisible: null,
1597
+ };
1598
+ planPolls.set(key, entry);
1552
1599
  }
1553
- catch (error) {
1554
- if (signal?.aborted)
1555
- return;
1556
- setState((previous) => ({
1557
- ...previous,
1558
- loading: false,
1559
- error: error instanceof Error ? error.message : String(error),
1560
- }));
1600
+ const listener = (next) => setState(next);
1601
+ entry.listeners.add(listener);
1602
+ setState(entry.state);
1603
+ if (!entry.run) {
1604
+ entry.run = async () => {
1605
+ if (entry.running)
1606
+ return;
1607
+ /*
1608
+ * [复审修复] 后台标签页跳过本次轮询:interval 保留,回到前台后
1609
+ * 自然恢复;另有 visibilitychange 监听立即补一轮(见下方注册)。
1610
+ */
1611
+ if (typeof document !== 'undefined' && document.visibilityState === 'hidden')
1612
+ return;
1613
+ entry.running = true;
1614
+ entry.timedOut = false;
1615
+ const controller = new AbortController();
1616
+ entry.controller = controller;
1617
+ /*
1618
+ * [复审修复] 15s 超时:一次挂死的请求不再让 entry.running 永真、
1619
+ * 看板永久冻结。卸载中止保持静默;超时中止走错误路径:
1620
+ * console.warn + 结束本次 running,interval 继续。
1621
+ *
1622
+ * 优先 AbortSignal.timeout + AbortSignal.any(无 JS 侧计时器句柄,
1623
+ * 不存在悬挂/句柄卫生问题);宿主运行时不支持 any() 时退回手动
1624
+ * setTimeout 控制器(等效实现),句柄挂在 entry 上,finally 与
1625
+ * 卸载 cleanup 双路清理——注意这里禁止 unref:这是收束类计时器
1626
+ * (tests/handle-policy.test.ts 契约),unref 会让 node 事件循环
1627
+ * 提前排空、看板错误路径永远到不了。
1628
+ */
1629
+ const anySignal = typeof AbortSignal.any === 'function'
1630
+ && typeof AbortSignal.timeout === 'function';
1631
+ let timeoutTimer = null;
1632
+ const signal = anySignal
1633
+ ? AbortSignal.any([controller.signal, AbortSignal.timeout(PLAN_POLL_TIMEOUT_MS)])
1634
+ : (() => {
1635
+ timeoutTimer = setTimeout(() => {
1636
+ entry.timedOut = true;
1637
+ controller.abort();
1638
+ }, PLAN_POLL_TIMEOUT_MS);
1639
+ return controller.signal;
1640
+ })();
1641
+ entry.timeoutTimer = timeoutTimer;
1642
+ try {
1643
+ const plansPayload = await fetchPlans(sessionId, signal);
1644
+ if (signal.aborted)
1645
+ return;
1646
+ entry.state = {
1647
+ loading: false,
1648
+ sessions: plansPayload.sessions,
1649
+ truncated: plansPayload.truncated === true,
1650
+ omittedSessions: plansPayload.omittedSessions,
1651
+ omittedDetail: plansPayload.omittedDetail === true,
1652
+ error: null,
1653
+ updatedAt: Date.now(),
1654
+ };
1655
+ }
1656
+ catch (error) {
1657
+ /*
1658
+ * 静默条件:仅「主动中止(卸载/重入)」。超时的判定两路都要覆盖——
1659
+ * 手动兜底路径置了 entry.timedOut;AbortSignal.any 路径里超时只体现为
1660
+ * 组合 signal 被中止而 controller 没有(卸载恰好相反:controller 先中止)。
1661
+ */
1662
+ const timedOut = entry.timedOut === true
1663
+ || (signal.aborted === true && controller.signal.aborted === false);
1664
+ if (signal.aborted && !timedOut)
1665
+ return;
1666
+ if (timedOut) {
1667
+ console.warn('[dsh-workplan] plans 轮询超时(15000ms),已结束本轮,下一轮继续', error);
1668
+ }
1669
+ entry.state = {
1670
+ ...entry.state,
1671
+ loading: false,
1672
+ error: error instanceof Error ? error.message : String(error),
1673
+ };
1674
+ }
1675
+ finally {
1676
+ if (timeoutTimer !== null)
1677
+ clearTimeout(timeoutTimer);
1678
+ entry.timeoutTimer = null;
1679
+ entry.running = false;
1680
+ entry.timedOut = false;
1681
+ entry.controller = null;
1682
+ entry.listeners.forEach((notify) => notify(entry.state));
1683
+ }
1684
+ };
1685
+ entry.run();
1686
+ entry.timer = setInterval(() => entry.run(), 4000);
1687
+ /*
1688
+ * [复审修复] 回到前台立即补一轮:后台期间 interval 触发的轮询
1689
+ * 全部被跳过,不补的话用户切回来最多干等一个周期。
1690
+ */
1691
+ entry.onVisible = () => {
1692
+ if (typeof document !== 'undefined' && document.visibilityState === 'visible') {
1693
+ entry.run?.();
1694
+ }
1695
+ };
1696
+ if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
1697
+ document.addEventListener('visibilitychange', entry.onVisible);
1698
+ }
1561
1699
  }
1562
- }, [sessionId]);
1563
- useEffect(() => {
1564
- const controller = new AbortController();
1565
- load(controller.signal);
1566
- const timer = setInterval(() => load(controller.signal), 4000);
1567
1700
  return () => {
1568
- controller.abort();
1569
- clearInterval(timer);
1701
+ entry.listeners.delete(listener);
1702
+ if (entry.listeners.size === 0) {
1703
+ if (entry.timer)
1704
+ clearInterval(entry.timer);
1705
+ if (entry.timeoutTimer)
1706
+ clearTimeout(entry.timeoutTimer);
1707
+ entry.controller?.abort();
1708
+ if (typeof document !== 'undefined' && typeof document.removeEventListener === 'function') {
1709
+ document.removeEventListener('visibilitychange', entry.onVisible);
1710
+ }
1711
+ planPolls.delete(key);
1712
+ }
1570
1713
  };
1571
- }, [load]);
1572
- return { ...state, reload: () => load() };
1714
+ }, [key, sessionId]);
1715
+ return { ...state, reload: () => planPolls.get(key)?.run?.() };
1573
1716
  }
1574
1717
  function ErrorBanner({ message, onRetry, t }) {
1575
1718
  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')));
@@ -2762,7 +2905,7 @@ window.__ModuleLoader__.load({
2762
2905
  /* [T4] 回到顶部的显示阈值(px):scrollTop 严格大于该值才显示。 */
2763
2906
  const BACK_TOP_THRESHOLD = 200;
2764
2907
  function Dashboard({ t }) {
2765
- const { sessions, error, loading, updatedAt, reload } = usePlans();
2908
+ const { sessions, error, loading, updatedAt, reload, truncated, omittedSessions, omittedDetail, } = usePlans();
2766
2909
  const [openSessionId, setOpenSessionId] = useState(null);
2767
2910
  const selectSession = useCallback((sessionId) => {
2768
2911
  if (!sessionId)
@@ -2944,7 +3087,18 @@ window.__ModuleLoader__.load({
2944
3087
  className: 'dsh-wp',
2945
3088
  ref: (node) => { if (node !== panelEl)
2946
3089
  setPanelEl(node); },
2947
- }, h('header', { className: 'dsh-wp-header' }, h('div', null, h('h1', { className: 'dsh-wp-title' }, t('title')), h('p', { className: 'dsh-wp-subtitle' }, t('subtitle')), h('div', { className: 'dsh-wp-meta' }, updatedAt ? h('span', null, `${t('updatedAt')} ${formatTime(updatedAt)}`) : null, h('span', null, `${t('scopeAll')}:${activeSessions.length} ${t('sessionCount')},${t('taskBreakdown')} ${totals.total} ${t('subtaskCount')}`))), h('button', { type: 'button', className: 'dsh-wp-button', onClick: reload, disabled: loading }, t('refresh'))), error ? h(ErrorBanner, { message: error, onRetry: reload, t }) : null, activeSessions.length > 0 ? h('div', { className: 'dsh-wp-statbar', role: 'list' }, h('div', { className: 'dsh-wp-stat dsh-wp-stat--tasks', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, activeSessions.length), h('div', { className: 'dsh-wp-stat-label' }, t('sessionCount'))), h('div', { className: 'dsh-wp-stat', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.total), h('div', { className: 'dsh-wp-stat-label' }, t('workItems'))), h('div', { className: 'dsh-wp-stat dsh-wp-stat--done', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.done), h('div', { className: 'dsh-wp-stat-label' }, t('stats.done'))), h('div', { className: 'dsh-wp-stat dsh-wp-stat--active', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.inProgress), h('div', { className: 'dsh-wp-stat-label' }, t('stats.inProgress'))), h('div', { className: 'dsh-wp-stat dsh-wp-stat--blocked', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.blocked), h('div', { className: 'dsh-wp-stat-label' }, t('stats.blocked')))) : null, activeSessions.length > 0 ? h('div', { className: 'dsh-wp-scope-note' }, t('allPlansHint')) : null, activeSessions.length === 0
3090
+ }, h('header', { className: 'dsh-wp-header' }, h('div', null, h('h1', { className: 'dsh-wp-title' }, t('title')), h('p', { className: 'dsh-wp-subtitle' }, t('subtitle')), h('div', { className: 'dsh-wp-meta' }, updatedAt ? h('span', null, `${t('updatedAt')} ${formatTime(updatedAt)}`) : null, h('span', null, `${t('scopeAll')}:${activeSessions.length} ${t('sessionCount')},${t('taskBreakdown')} ${totals.total} ${t('subtaskCount')}`))), h('button', { type: 'button', className: 'dsh-wp-button', onClick: reload, disabled: loading }, t('refresh'))), error ? h(ErrorBanner, { message: error, onRetry: reload, t }) : null,
3091
+ /*
3092
+ * [复审修复] 服务端裁剪提示:载荷被 2.5MB 上限裁剪(truncated /
3093
+ * omittedSessions / omittedDetail 任一成立)时明确告知「展示为子集」,
3094
+ * 不再静默少显示数据。复用现有 degraded 横幅样式,不新增 CSS/依赖。
3095
+ */
3096
+ (truncated === true || Number(omittedSessions) > 0 || omittedDetail === true)
3097
+ ? h('div', {
3098
+ className: 'dsh-wp-banner dsh-wp-banner--degraded dsh-wp-trim-notice',
3099
+ role: 'status',
3100
+ }, t('trimNotice'))
3101
+ : null, activeSessions.length > 0 ? h('div', { className: 'dsh-wp-statbar', role: 'list' }, h('div', { className: 'dsh-wp-stat dsh-wp-stat--tasks', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, activeSessions.length), h('div', { className: 'dsh-wp-stat-label' }, t('sessionCount'))), h('div', { className: 'dsh-wp-stat', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.total), h('div', { className: 'dsh-wp-stat-label' }, t('workItems'))), h('div', { className: 'dsh-wp-stat dsh-wp-stat--done', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.done), h('div', { className: 'dsh-wp-stat-label' }, t('stats.done'))), h('div', { className: 'dsh-wp-stat dsh-wp-stat--active', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.inProgress), h('div', { className: 'dsh-wp-stat-label' }, t('stats.inProgress'))), h('div', { className: 'dsh-wp-stat dsh-wp-stat--blocked', role: 'listitem' }, h('div', { className: 'dsh-wp-stat-value' }, totals.blocked), h('div', { className: 'dsh-wp-stat-label' }, t('stats.blocked')))) : null, activeSessions.length > 0 ? h('div', { className: 'dsh-wp-scope-note' }, t('allPlansHint')) : null, activeSessions.length === 0
2948
3102
  ? h('div', { className: 'dsh-wp-empty' }, h('div', { style: { fontWeight: 650, marginBottom: '4px' } }, t('empty')), h('div', null, t('emptyHint')))
2949
3103
  : h('div', { className: 'dsh-wp-groups' },
2950
3104
  // [用户要求] 总览块(完成率环 + 每个任务的进度)上移到分组之前: