dsh-workplan 1.5.2 → 1.7.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-workplan",
3
- "version": "1.5.2",
3
+ "version": "1.7.0",
4
4
  "description": "Automatic task decomposition, real department subagents, and a responsive workplan dashboard for DeepSeek Harness.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/client.ts CHANGED
@@ -20,21 +20,26 @@ window.__ModuleLoader__.load({
20
20
  "panel": "任务进度",
21
21
  "groupLive": "进行中",
22
22
  "groupDone": "已完成",
23
+ "groupEnded": "已结束",
23
24
  "groupLiveHint": "还没结束,正在或即将推进",
24
25
  "groupDoneHint": "已全部完成并收尾",
26
+ "groupEndedHint": "这一轮已经停了,没有东西在跑;说「续跑」可继续推进",
25
27
  "groupCollapse": "收起",
26
28
  "groupExpand": "展开",
27
29
  "groupNeeds": "需处理",
28
30
  "groupLiveEmpty": "没有进行中的任务",
29
31
  "groupDoneEmpty": "还没有完成的任务",
32
+ "groupEndedEmpty": "没有已结束但未完成的任务",
30
33
  "groupSummary": "未完成 {open} / 已完成 {done}(完成率 {pct}%)",
31
34
  "groupSummaryNoRate": "未完成 {open} / 已完成 {done}(完成率暂无数据)",
32
35
  "groupAria": "{title}组,{plans} 个计划,共 {total} 件具体工作,已完成 {done} 件,完成率 {pct}%。其中正在做 {active} 件、卡住 {blocked} 件、还没开始 {pending} 件。",
33
36
  "groupAriaEmpty": "{title}组,{plans} 个计划,暂无具体工作项。",
34
37
  "groupPlansLabel": "个计划",
35
- "chartGroups": "两类计划数量占比",
36
- "chartLive": "进行中计划完成度(按工作项)",
37
- "chartMore": "另有 {n} 个进行中计划未画入图表",
38
+ "chartGroups": "计划数量与完成情况",
39
+ "chartOpen": "未结束",
40
+ "chartDone": "已完成",
41
+ "chartLive": "未完成计划的完成度(按工作项)",
42
+ "chartMore": "另有 {n} 个未完成计划未画入图表",
38
43
 
39
44
  "title": "任务进度:一眼看懂",
40
45
  "subtitle": "用大白话说明:现在要做什么、谁在做、做到哪一步、接下来做什么。",
@@ -69,7 +74,8 @@ window.__ModuleLoader__.load({
69
74
  "blocked": "卡住了",
70
75
  "paused": "预算用完,可续跑",
71
76
  "degraded": "安排失败",
72
- "cancelled": "已取消"
77
+ "cancelled": "已取消",
78
+ "ended": "已结束,可续跑"
73
79
  },
74
80
  "status": {
75
81
  "pending": "还没开始",
@@ -174,6 +180,7 @@ window.__ModuleLoader__.load({
174
180
  "overview": "进度总览",
175
181
  "statusChart": "状态分布",
176
182
  "taskChart": "每个任务的进度",
183
+ "backToTop": "回到顶部",
177
184
  "jumpToTask": "跳转到任务明细",
178
185
  "scopeAll": "当前各会话最新计划汇总",
179
186
  "scopeThis": "本计划",
@@ -185,6 +192,7 @@ window.__ModuleLoader__.load({
185
192
  "en": {
186
193
  "groupLive": "In progress",
187
194
  "groupDone": "Completed",
195
+ "groupEnded": "Ended",
188
196
  "groupLiveHint": "Not finished yet — running or about to run",
189
197
  "groupDoneHint": "All work finished and wrapped up",
190
198
  "groupCollapse": "Collapse",
@@ -192,14 +200,17 @@ window.__ModuleLoader__.load({
192
200
  "groupNeeds": "needs attention",
193
201
  "groupLiveEmpty": "No work in progress",
194
202
  "groupDoneEmpty": "Nothing completed yet",
203
+ "groupEndedEmpty": "No ended-but-unfinished plans",
195
204
  "groupSummary": "Open {open} / done {done} ({pct}% complete)",
196
205
  "groupSummaryNoRate": "Open {open} / done {done} (completion rate unavailable)",
197
206
  "groupAria": "{title} group: {plans} plan(s), {total} work item(s), {done} done, {pct}% complete. Right now {active} in progress, {blocked} blocked, {pending} not started.",
198
207
  "groupAriaEmpty": "{title} group: {plans} plan(s), no work items yet.",
199
208
  "groupPlansLabel": "plan(s)",
200
- "chartGroups": "Plan count by group",
201
- "chartLive": "In-progress plans by work item",
202
- "chartMore": "{n} more in-progress plans not drawn",
209
+ "chartGroups": "Plan count and completion",
210
+ "chartOpen": "Open",
211
+ "chartDone": "Completed",
212
+ "chartLive": "Open plans by work item",
213
+ "chartMore": "{n} more open plans not drawn",
203
214
  "panel": "Task progress",
204
215
  "title": "Task progress at a glance",
205
216
  "subtitle": "Plain language: what this is, who is doing it, how far along it is, and what happens next.",
@@ -234,7 +245,8 @@ window.__ModuleLoader__.load({
234
245
  "blocked": "Stuck",
235
246
  "paused": "Paused (budget spent)",
236
247
  "degraded": "Planning failed",
237
- "cancelled": "Cancelled"
248
+ "cancelled": "Cancelled",
249
+ "ended": "Ended (resumable)"
238
250
  },
239
251
  "status": {
240
252
  "pending": "Not started",
@@ -339,6 +351,7 @@ window.__ModuleLoader__.load({
339
351
  "overview": "Progress overview",
340
352
  "statusChart": "Status mix",
341
353
  "taskChart": "Progress by task",
354
+ "backToTop": "Back to top",
342
355
  "jumpToTask": "Jump to task details",
343
356
  "scopeAll": "Latest plan per live session",
344
357
  "scopeThis": "This plan",
@@ -405,6 +418,7 @@ window.__ModuleLoader__.load({
405
418
  .dsh-wp-group::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; }
406
419
  .dsh-wp-group--live::before { background: linear-gradient(180deg, #fb923c, #f97316); }
407
420
  .dsh-wp-group--done::before { background: linear-gradient(180deg, #38bdf8, #0284c7); }
421
+ .dsh-wp-group--ended::before { background: linear-gradient(180deg, #94a3b8, #64748b); }
408
422
  /* T6 — 组头多出一行完成度摘要,底部内边距 10px → 6px,两组仍在同一屏内读完。 */
409
423
  .dsh-wp-group-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 0 4px 6px; }
410
424
  .dsh-wp-group-head--btn { width: 100%; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 8px; }
@@ -431,6 +445,8 @@ window.__ModuleLoader__.load({
431
445
  .dsh-wp-group-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
432
446
  .dsh-wp-group--live .dsh-wp-group-dot { background: #f97316; box-shadow: 0 0 0 4px rgba(249,115,22,.16); animation: dsh-wp-pulse 1.8s ease-in-out infinite; }
433
447
  .dsh-wp-group--done .dsh-wp-group-dot { background: #0ea5e9; box-shadow: 0 0 0 4px rgba(14,165,233,.14); }
448
+ /* [1.6.0] 已结束:灰点、不脉冲——"没有东西在跑"这件事不允许用动画表达。 */
449
+ .dsh-wp-group--ended .dsh-wp-group-dot { background: #94a3b8; box-shadow: 0 0 0 4px rgba(148,163,184,.16); }
434
450
  .dsh-wp-group-title { font-size: 15px; font-weight: 700; letter-spacing: .2px; color: var(--dsw-alias-label-primary, #0f172a); }
435
451
  /* 设计稿 §6.1:橙 #f97316 / 白 ≈2.8:1、蓝 #0ea5e9 / 白 ≈2.77:1,均不足 4.5:1,
436
452
  15px 粗体也不算法定「大字号」,所以组头一律用主文本色;品牌色只做「面」——
@@ -439,6 +455,7 @@ window.__ModuleLoader__.load({
439
455
  .dsh-wp-group-count { min-width: 22px; padding: 0 7px; height: 20px; border-radius: 999px; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; color: var(--dsw-alias-label-primary, #0f172a); font-variant-numeric: tabular-nums; }
440
456
  .dsh-wp-group--live .dsh-wp-group-count { background: rgba(249,115,22,.14); box-shadow: inset 0 0 0 1px rgba(249,115,22,.34); }
441
457
  .dsh-wp-group--done .dsh-wp-group-count { background: rgba(14,165,233,.14); box-shadow: inset 0 0 0 1px rgba(14,165,233,.34); }
458
+ .dsh-wp-group--ended .dsh-wp-group-count { background: rgba(148,163,184,.16); box-shadow: inset 0 0 0 1px rgba(148,163,184,.36); }
442
459
  /* WCAG AA:错误色叠 12% 红底后,浅色 #ec1313 只有 3.70:1;与主文本色混合 20%
443
460
  让浅色变深、深色变浅,两套主题都 ≥4.5:1(实测 5.16:1 / 5.67:1)。 */
444
461
  .dsh-wp-group-alert { font-size: 12px; font-weight: 650; color: var(--dsw-alias-state-error-primary, #ef4444); color: color-mix(in srgb, var(--dsw-alias-state-error-primary, #ef4444) 80%, var(--dsw-alias-label-primary, #0f172a) 20%); background: rgba(239,68,68,.12); padding: 1px 8px; border-radius: 999px; }
@@ -521,6 +538,35 @@ window.__ModuleLoader__.load({
521
538
  }
522
539
  .dsh-wp-button:hover { background: var(--dsw-alias-bg-layer-2); }
523
540
  .dsh-wp-button:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }
541
+ /* [T4] 回到顶部:sticky 的包含块与粘附视口就是 .dsh-wp 的 padding box,
542
+ 钉住的是面板可视区右下角。禁止 fixed(钉到浏览器视口)与 absolute
543
+ (随内容滚走)。始终挂载、用 visibility 藏显,避免显隐改变 scrollHeight。 */
544
+ .dsh-wp-backtop {
545
+ position: sticky;
546
+ bottom: 16px;
547
+ z-index: 30;
548
+ display: flex;
549
+ align-items: center;
550
+ justify-content: center;
551
+ width: 44px;
552
+ height: 44px;
553
+ margin: 12px 0 0 auto;
554
+ padding: 0;
555
+ border-radius: 50%;
556
+ border: 1px solid var(--dsw-alias-border-l1);
557
+ background: var(--dsw-alias-bg-layer-1);
558
+ color: var(--dsw-alias-label-primary);
559
+ font: inherit;
560
+ font-size: 18px;
561
+ line-height: 1;
562
+ cursor: pointer;
563
+ touch-action: manipulation;
564
+ visibility: hidden;
565
+ box-shadow: 0 2px 8px rgba(15,23,42,.18);
566
+ }
567
+ .dsh-wp-backtop[data-visible="true"], .dsh-wp-backtop:focus-within { visibility: visible; }
568
+ .dsh-wp-backtop:hover { background: var(--dsw-alias-bg-layer-2); }
569
+ .dsh-wp-backtop:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }
524
570
  .dsh-wp-banner {
525
571
  border: 1px solid var(--dsw-alias-border-l1);
526
572
  background: var(--dsw-alias-bg-layer-1);
@@ -751,6 +797,7 @@ window.__ModuleLoader__.load({
751
797
  .dsh-wp-group::before { content: ''; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; opacity: .9; }
752
798
  .dsh-wp-group--live::before { background: linear-gradient(180deg, #fbbf24, #ea580c); }
753
799
  .dsh-wp-group--done::before { background: linear-gradient(180deg, #7dd3fc, #0369a1); }
800
+ .dsh-wp-group--ended::before { background: linear-gradient(180deg, #cbd5e1, #94a3b8); }
754
801
  .dsh-wp-group--done { opacity: .97; }
755
802
  .dsh-wp-group-head--btn { transition: background-color .16s ease; }
756
803
  .dsh-wp-group-head--btn:hover { background: rgba(148,163,184,.10); }
@@ -982,12 +1029,33 @@ window.__ModuleLoader__.load({
982
1029
 
983
1030
  function phaseTone(phase: any) {
984
1031
  if (phase === 'blocked') return 'blocked'
1032
+ /*
1033
+ * [1.6.0] `ended` = 这一轮停了,但计划没做完。它既不是成功(done),也不能
1034
+ * 冒充正在干活(active);用中性 idle 色,卡在哪由二级徽标 suspendedPhase 说明。
1035
+ */
1036
+ if (phase === 'ended') return 'idle'
985
1037
  if (phase === 'degraded' || phase === 'cancelled' || phase === 'paused') return 'warn'
986
1038
  if (phase === 'integrating' || phase === 'done') return 'done'
987
1039
  if (phase === 'executing' || phase === 'planning') return 'active'
988
1040
  return 'idle'
989
1041
  }
990
1042
 
1043
+ /*
1044
+ * [1.6.0] 「已结束」徽标要把「停在哪儿」一起说出来。
1045
+ *
1046
+ * 只说「已结束,可续跑」,用户不知道是预算用完、卡住了、还是压根没开始;
1047
+ * 只说原阶段(「正在做」),又会像事故截图那样暗示还在跑。两段式表达:
1048
+ * 终态 + 原阶段,一次说清两个事实。
1049
+ */
1050
+ function phaseLabel(phase: any, session: any, t: any) {
1051
+ const base = t(`phase.${phase}`)
1052
+ if (phase !== 'ended') return base
1053
+ const suspended = String(session?.suspendedPhase ?? '')
1054
+ if (!suspended) return base
1055
+ const detail = t(`phase.${suspended}`)
1056
+ return detail && detail !== base ? `${base} · ${detail}` : base
1057
+ }
1058
+
991
1059
  function allEntries(session: any) {
992
1060
  const byId = new Map((Array.isArray(session?.statuses) ? session.statuses : []).map((item: any) => [item.subtaskId, item]))
993
1061
  const entries: any[] = []
@@ -1863,7 +1931,7 @@ window.__ModuleLoader__.load({
1863
1931
  panelClassName: 'dsh-wp-session-body',
1864
1932
  title: session.title || t('panel'),
1865
1933
  meta: h(PlanViz, { t, counts, now, rows: stageRows }),
1866
- badge: h(Pill, { tone }, t(`phase.${phase}`)),
1934
+ badge: h(Pill, { tone }, phaseLabel(phase, session, t)),
1867
1935
  },
1868
1936
  session.updatedAt
1869
1937
  ? h('div', { className: 'dsh-wp-meta dsh-wp-session-updated' }, `${t('updatedAt')} ${formatTime(session.updatedAt)}`)
@@ -1967,7 +2035,7 @@ window.__ModuleLoader__.load({
1967
2035
  charts.push(new lib(canvasA, {
1968
2036
  type: 'doughnut',
1969
2037
  data: {
1970
- labels: [t('groupLive'), t('groupDone')],
2038
+ labels: [t('chartOpen'), t('chartDone')],
1971
2039
  datasets: [{ data: [liveCount, doneCount], backgroundColor: [liveFill, doneFill], borderWidth: 0, hoverOffset: 5 }],
1972
2040
  },
1973
2041
  options: {
@@ -2022,16 +2090,16 @@ window.__ModuleLoader__.load({
2022
2090
  // 「无 canvas → 不建图 → 不 ready → 无 canvas」的死循环(T3 实测
2023
2091
  // 探针输出 canvasNodes:0 / fallbackBars:1)。改为并存:
2024
2092
  // fallback 在 ready 前可见,ready 后由 CSS 隐藏,canvas 反向隐藏。
2025
- h('div', { className: 'dsh-wp-chart-canvas' }, h('canvas', { 'data-chart': 'groups', role: 'img', 'aria-label': `${t('groupLive')} ${liveCount} / ${t('groupDone')} ${doneCount}` })),
2093
+ h('div', { className: 'dsh-wp-chart-canvas' }, h('canvas', { 'data-chart': 'groups', role: 'img', 'aria-label': `${t('chartOpen')} ${liveCount} / ${t('chartDone')} ${doneCount}` })),
2026
2094
  chartState !== 'ready'
2027
2095
  ? h('div', { className: 'dsh-wp-fallback' },
2028
- h('div', { className: 'dsh-wp-fallback-bar', role: 'img', 'aria-label': `${t('groupLive')} ${liveCount} / ${t('groupDone')} ${doneCount}` },
2096
+ h('div', { className: 'dsh-wp-fallback-bar', role: 'img', 'aria-label': `${t('chartOpen')} ${liveCount} / ${t('chartDone')} ${doneCount}` },
2029
2097
  h('span', { className: 'dsh-wp-fallback-live', style: { width: `${livePct}%` } }),
2030
2098
  h('span', { className: 'dsh-wp-fallback-done', style: { width: `${donePct}%` } }),
2031
2099
  ),
2032
2100
  h('div', { className: 'dsh-wp-fallback-legend' },
2033
- h('span', null, h('i', { className: 'dsh-wp-fallback-key dsh-wp-fallback-key--live' }), `${t('groupLive')} ${liveCount}`),
2034
- h('span', null, h('i', { className: 'dsh-wp-fallback-key dsh-wp-fallback-key--done' }), `${t('groupDone')} ${doneCount}`),
2101
+ h('span', null, h('i', { className: 'dsh-wp-fallback-key dsh-wp-fallback-key--live' }), `${t('chartOpen')} ${liveCount}`),
2102
+ h('span', null, h('i', { className: 'dsh-wp-fallback-key dsh-wp-fallback-key--done' }), `${t('chartDone')} ${doneCount}`),
2035
2103
  ),
2036
2104
  )
2037
2105
  : null,
@@ -2148,18 +2216,25 @@ window.__ModuleLoader__.load({
2148
2216
  }
2149
2217
 
2150
2218
  function SessionGroup({ group, list, hasLive, urgent, t, openSessionId, setOpenSessionId }: any) {
2219
+ /*
2220
+ * [1.6.0] 三个分组共用一套组件:live(真的在跑)、ended(这一轮停了但没做完)、
2221
+ * done(全部完成)。`ended` 是本次事故的修复核心——它必须是一个**独立分组**,
2222
+ * 而不是被塞回「进行中」:会话已经结束的事实不允许用「进行中」这三个字表达。
2223
+ */
2151
2224
  const isDone = group === 'done'
2225
+ const isEnded = group === 'ended'
2226
+ const keySuffix = isDone ? 'Done' : isEnded ? 'Ended' : 'Live'
2152
2227
  // 设计稿 §6.4 #1/#6:已完成组在有进行中任务时默认折叠,避免历史任务抢走
2153
2228
  // 「进行中」的视觉权重;没有进行中任务时默认展开,空的进度栏仍是空的。
2154
- // 折叠态由本组件自己持有(不给 users 存偏好),刷新后回到默认,符合 §7.3「不打扰」。
2155
- const [open, setOpen] = useState(!(isDone && hasLive))
2229
+ // [1.6.0] 「已结束」组同理:还有东西在跑时收起来,只留组头一行结论。
2230
+ const [open, setOpen] = useState(!((isDone || isEnded) && hasLive))
2156
2231
  // §7.3「不打扰」的自动展开:只在这两种情形打开一次,不做反复弹开——
2157
2232
  // ① 进行中清零(最后一个任务完成);② 用户正展开着的卡片被移进本组。
2158
2233
  // 依赖都是布尔值,轮询刷新不会重复触发。
2159
2234
  const holdsOpenCard = list.some((session: any) => session.sessionId === openSessionId)
2160
2235
  useEffect(() => { if (!hasLive) setOpen(true) }, [hasLive])
2161
2236
  useEffect(() => { if (holdsOpenCard) setOpen(true) }, [holdsOpenCard])
2162
- const collapsible = isDone && list.length > 0
2237
+ const collapsible = (isDone || isEnded) && list.length > 0
2163
2238
  // 折叠只隐藏、不卸载:`hidden` 必须是布尔 true,不能传空字符串——
2164
2239
  // React 对 `hidden` 走 DOM 布尔属性赋值,`el.hidden = ''` 会得到 false,
2165
2240
  // 只剩 CSS 类在遮挡;那样「折叠态 DOM 保留 + 无障碍语义」就不成立。
@@ -2170,8 +2245,8 @@ window.__ModuleLoader__.load({
2170
2245
  // T6:组头完成度摘要 + 零依赖进度环。数值只来自 groupTotals(list),
2171
2246
  // 先用纯文本给出「进行中 N / 已完成 M(完成率 x%)」,不点开、不看颜色也能读出进度。
2172
2247
  const totals = useMemo(() => groupTotals(list), [list])
2173
- const groupTitle = t(isDone ? 'groupDone' : 'groupLive')
2174
- const hintText = t(isDone ? 'groupDoneHint' : 'groupLiveHint')
2248
+ const groupTitle = t(`group${keySuffix}`)
2249
+ const hintText = t(`group${keySuffix}Hint`)
2175
2250
  // 用户 Q3:0/0 时不再显示「未完成 0 / 已完成 0(完成率暂无数据)」——
2176
2251
  // 环上已经是「—」,组内空态也已说明没有工作项;再重复一遍 0/0 只是噪声。
2177
2252
  // 全部做完(100%)仍保留整句,因为那时「未完成 0」正是用户要找的结论。
@@ -2238,7 +2313,7 @@ window.__ModuleLoader__.load({
2238
2313
  open: openSessionId === session.sessionId,
2239
2314
  onToggle: (next: boolean) => setOpenSessionId(next ? session.sessionId : null),
2240
2315
  })))
2241
- : h('div', { className: 'dsh-wp-group-empty' }, t(isDone ? 'groupDoneEmpty' : 'groupLiveEmpty')),
2316
+ : h('div', { className: 'dsh-wp-group-empty' }, t(`group${keySuffix}Empty`)),
2242
2317
  )
2243
2318
  }
2244
2319
 
@@ -2331,7 +2406,7 @@ window.__ModuleLoader__.load({
2331
2406
  h('div', { className: `dsh-wp-bar-fill dsh-wp-bar-fill--${tone}`, style: { width: `${percent}%` } }),
2332
2407
  ),
2333
2408
  h('div', { className: 'dsh-wp-bar-meta' },
2334
- h('span', null, t(`phase.${phase}`)),
2409
+ h('span', null, phaseLabel(phase, session, t)),
2335
2410
  h('span', null, `${percent}%`),
2336
2411
  ),
2337
2412
  )
@@ -2339,6 +2414,9 @@ window.__ModuleLoader__.load({
2339
2414
  )
2340
2415
  }
2341
2416
 
2417
+ /* [T4] 回到顶部的显示阈值(px):scrollTop 严格大于该值才显示。 */
2418
+ const BACK_TOP_THRESHOLD = 200
2419
+
2342
2420
  function Dashboard({ t }: any) {
2343
2421
  const { sessions, error, loading, updatedAt, reload } = usePlans()
2344
2422
  const [openSessionId, setOpenSessionId] = useState(null)
@@ -2383,6 +2461,7 @@ window.__ModuleLoader__.load({
2383
2461
  }, [activeSessions])
2384
2462
  const groups = useMemo(() => {
2385
2463
  const live: any[] = []
2464
+ const ended: any[] = []
2386
2465
  const finished: any[] = []
2387
2466
  const urgentPhases = ['blocked', 'degraded', 'paused']
2388
2467
  /*
@@ -2392,9 +2471,15 @@ window.__ModuleLoader__.load({
2392
2471
  * 14/14、100% 的计划带着 integrating 被塞进 live 组,组头于是出现
2393
2472
  * 「未完成 0 / 已完成 14(完成率 100%)」却仍标着「进行中」。
2394
2473
  * `planPhaseOf` 让分组、组头计数、卡片胶囊共用同一个结论。
2474
+ *
2475
+ * [1.6.0] 新增 ended 分组:宿主已经 `turn/end`(会话这一轮结束、没有任何
2476
+ * 东西在跑),而计划还没做完的,一律进「已结束」,绝不进「进行中」。
2477
+ * 这正是本次事故的现象:会话结束 4 小时后仍显示「进行中」。
2395
2478
  */
2396
2479
  for (const session of activeSessions) {
2397
- if (planPhaseOf(session.phase, planCounts(session.stats)) === 'done') finished.push(session)
2480
+ const phase = planPhaseOf(session.phase, planCounts(session.stats))
2481
+ if (phase === 'done') finished.push(session)
2482
+ else if (phase === 'ended') ended.push(session)
2398
2483
  else live.push(session)
2399
2484
  }
2400
2485
  /*
@@ -2411,11 +2496,19 @@ window.__ModuleLoader__.load({
2411
2496
  integrating: 3,
2412
2497
  planning: 4,
2413
2498
  pending: 5,
2499
+ ended: 6,
2414
2500
  }
2415
2501
  const rank = (session: any) => phaseRank[planPhaseOf(session.phase, planCounts(session.stats))] ?? 5
2416
2502
  live.sort((a: any, b: any) => (rank(a) - rank(b))
2417
2503
  || ((Number(b.createdAt) || 0) - (Number(a.createdAt) || 0))
2418
2504
  || String(a.sessionId).localeCompare(String(b.sessionId)))
2505
+ /*
2506
+ * [1.6.0] 已结束组按「最近结束在前」:`endedAt` 是宿主 turn/end 的时间戳
2507
+ * (后端下发),比 updatedAt 更准确地表达「什么时候停的」。
2508
+ */
2509
+ const endedAt = (session: any) => Number(session.endedAt) || Number(session.updatedAt) || Number(session.createdAt) || 0
2510
+ ended.sort((a: any, b: any) => (endedAt(b) - endedAt(a))
2511
+ || ((Number(b.createdAt) || 0) - (Number(a.createdAt) || 0)))
2419
2512
  /*
2420
2513
  * 已完成组按「最近完成在前」(§3.3 / C8):优先取子任务
2421
2514
  * statuses[].finishedAt 的最大值(忽略 null / 非数字),缺失则退回
@@ -2438,9 +2531,20 @@ window.__ModuleLoader__.load({
2438
2531
  }
2439
2532
  finished.sort((a: any, b: any) => (finishedAt(b) - finishedAt(a))
2440
2533
  || ((Number(b.createdAt) || 0) - (Number(a.createdAt) || 0)))
2441
- return { live, finished, urgent: live.filter((session: any) => urgentPhases.includes(session.phase)).length }
2534
+ return {
2535
+ live,
2536
+ ended,
2537
+ finished,
2538
+ urgent: live.filter((session: any) => urgentPhases.includes(session.phase)).length,
2539
+ /*
2540
+ * [1.6.0] 「已结束」组也需要「需处理」角标:卡住的计划停了仍然是卡住的,
2541
+ * 判定用后端下发的 suspendedPhase(原派发阶段),而不是被收敛后的 ended。
2542
+ */
2543
+ urgentEnded: ended.filter((session: any) => urgentPhases.includes(String(session.suspendedPhase ?? ''))).length,
2544
+ }
2442
2545
  }, [activeSessions])
2443
- const liveBars = useMemo(() => groups.live.slice(0, 6).map((session: any) => {
2546
+ // [1.6.0] 图表口径 = 未结束计划(进行中 + 已结束未完成),与环图标签一致。
2547
+ const liveBars = useMemo(() => [...groups.live, ...groups.ended].slice(0, 6).map((session: any) => {
2444
2548
  const raw = String(session.title || t('panel'))
2445
2549
  return {
2446
2550
  label: raw.length > 14 ? `${raw.slice(0, 14)}…` : raw,
@@ -2448,7 +2552,44 @@ window.__ModuleLoader__.load({
2448
2552
  value: planPercent(planCount(session.stats?.done), planCount(session.stats?.total)) ?? 0,
2449
2553
  }
2450
2554
  }), [groups, t])
2451
- return h('div', { className: 'dsh-wp' },
2555
+ /*
2556
+ * [T4] 回到顶部:用「状态当 ref」拿面板根节点(宿主兼容层不保证 useRef,
2557
+ * 见 GroupCharts 的同一处理),滚动目标只能是 .dsh-wp 这个 overflow 容器。
2558
+ */
2559
+ const [panelEl, setPanelEl] = useState(null)
2560
+ const [showBackTop, setShowBackTop] = useState(false)
2561
+ useEffect(() => {
2562
+ const panel: any = panelEl
2563
+ if (!panel || typeof panel.addEventListener !== 'function') return
2564
+ const onScroll = () => setShowBackTop(Number(panel.scrollTop) > BACK_TOP_THRESHOLD)
2565
+ // 挂载与内容变化时先求一次初值:刷新后停在中间也必须显示按钮。
2566
+ onScroll()
2567
+ panel.addEventListener('scroll', onScroll, { passive: true })
2568
+ return () => panel.removeEventListener('scroll', onScroll)
2569
+ }, [panelEl, activeSessions.length])
2570
+ const backToTop = useCallback((event?: any) => {
2571
+ // 双保险:ref 尚未回填时,从事件目标向上找唯一的滚动容器。
2572
+ let panel: any = panelEl
2573
+ if (!panel && event && event.currentTarget && typeof event.currentTarget.closest === 'function') {
2574
+ panel = event.currentTarget.closest('.dsh-wp')
2575
+ }
2576
+ if (!panel) return
2577
+ const reduced = typeof window !== 'undefined' && typeof window.matchMedia === 'function'
2578
+ && window.matchMedia('(prefers-reduced-motion: reduce)').matches
2579
+ if (typeof panel.scrollTo === 'function') {
2580
+ try {
2581
+ panel.scrollTo({ top: 0, behavior: reduced ? 'auto' : 'smooth' })
2582
+ return
2583
+ } catch (error) {
2584
+ /* 旧宿主不支持带参数的 scrollTo:落到下面的直接赋值。 */
2585
+ }
2586
+ }
2587
+ panel.scrollTop = 0
2588
+ }, [panelEl])
2589
+ return h('div', {
2590
+ className: 'dsh-wp',
2591
+ ref: (node: any) => { if (node !== panelEl) setPanelEl(node) },
2592
+ },
2452
2593
  h('header', { className: 'dsh-wp-header' },
2453
2594
  h('div', null,
2454
2595
  h('h1', { className: 'dsh-wp-title' }, t('title')),
@@ -2472,19 +2613,39 @@ window.__ModuleLoader__.load({
2472
2613
  activeSessions.length === 0
2473
2614
  ? h('div', { className: 'dsh-wp-empty' }, h('div', { style: { fontWeight: 650, marginBottom: '4px' } }, t('empty')), h('div', null, t('emptyHint')))
2474
2615
  : h('div', { className: 'dsh-wp-groups' },
2475
- h(SessionGroup, { group: 'live', list: groups.live, urgent: groups.urgent, t, openSessionId, setOpenSessionId }),
2476
- h(SessionGroup, { group: 'done', list: groups.finished, hasLive: groups.live.length > 0, urgent: 0, t, openSessionId, setOpenSessionId }),
2477
- // 用户选择 B:总览块(完成率环 + 每个计划的进度条)同样下移到两组之后,
2478
- // 让开屏第一屏直接是「进行中」组的任务卡(此前统计条 → 总览 → 说明行 →
2479
- // 任务卡,第一张卡要下滑约一屏)。顶部只保留 5 格数字统计条与一行口径说明。
2616
+ // [用户要求] 总览块(完成率环 + 每个任务的进度)上移到分组之前:
2617
+ // 用户要求红圈的「每个任务的进度」必须显示在「进行中」组之上。
2480
2618
  activeSessions.length > 0 ? h('div', { className: 'dsh-wp-overview' },
2481
2619
  h(Donut, { totals, t }),
2482
2620
  h(TaskBars, { sessions: activeSessions, t, onSelect: selectSession }),
2483
2621
  ) : null,
2622
+ /*
2623
+ * [1.6.0] 三组顺序:真的在跑 → 已结束(停在半路) → 已完成。
2624
+ * 「已结束」夹在中间是有意为之:它是用户最需要立刻知道的那一档
2625
+ * (刚停、还没做完),不能滑到历史组的下面去。
2626
+ */
2627
+ h(SessionGroup, { key: 'live', group: 'live', list: groups.live, urgent: groups.urgent, t, openSessionId, setOpenSessionId }),
2628
+ groups.ended.length > 0
2629
+ ? h(SessionGroup, { key: 'ended', group: 'ended', list: groups.ended, hasLive: groups.live.length > 0, urgent: groups.urgentEnded, t, openSessionId, setOpenSessionId })
2630
+ : null,
2631
+ h(SessionGroup, { key: 'done', group: 'done', list: groups.finished, hasLive: groups.live.length > 0 || groups.ended.length > 0, urgent: 0, t, openSessionId, setOpenSessionId }),
2484
2632
  // 图表放两组之后:两张卡各 ≈246px,排在组前会让首屏看不到任何一张任务卡
2485
2633
  // (设计稿 §8 第 12 条,T8 复核时复现在 1.4.2 源码里)。
2486
- h(GroupCharts, { liveCount: groups.live.length, doneCount: groups.finished.length, liveBars, hiddenBars: Math.max(0, groups.live.length - 6), t }),
2634
+ // [1.6.0] 「未结束」= 进行中 + 已结束但未完成:两者都还没做完,都是用户要盯的对象。
2635
+ h(GroupCharts, { liveCount: groups.live.length + groups.ended.length, doneCount: groups.finished.length, liveBars, hiddenBars: Math.max(0, groups.live.length + groups.ended.length - 6), t }),
2487
2636
  ),
2637
+ /*
2638
+ * [T4] 始终挂载的回到顶部按钮:作为 .dsh-wp 的最后一个直接子元素,
2639
+ * sticky 在面板滚动视口右下角;显隐只切换 data-visible,不增删节点。
2640
+ */
2641
+ h('button', {
2642
+ type: 'button',
2643
+ className: 'dsh-wp-backtop',
2644
+ 'data-visible': showBackTop ? 'true' : 'false',
2645
+ 'aria-label': t('backToTop'),
2646
+ title: t('backToTop'),
2647
+ onClick: backToTop,
2648
+ }, h('span', { 'aria-hidden': 'true' }, '↑')),
2488
2649
  )
2489
2650
  }
2490
2651
 
@@ -2511,7 +2672,7 @@ window.__ModuleLoader__.load({
2511
2672
  return h('div', { className: `dsh-wp-turn dsh-wp-tone-${tone}` },
2512
2673
  h('div', { className: 'dsh-wp-turn-title' },
2513
2674
  h('span', null, session.title || t('panel')),
2514
- h(Pill, { tone }, t(`phase.${phase}`)),
2675
+ h(Pill, { tone }, phaseLabel(phase, session, t)),
2515
2676
  ),
2516
2677
  h('div', { className: 'dsh-wp-muted', style: { marginTop: '6px' } },
2517
2678
  `${t('helpWho')}:${workerText(session, t)}`),
package/src/host.ts CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  createWorkplanRuntime,
14
14
  dispatchToolOutputSchema,
15
15
  plannerOutputSchema,
16
+ statusToolOutputSchema,
16
17
  updateToolOutputSchema,
17
18
  } from './runtime.js'
18
19
  import { isRecord } from './plan.js'
@@ -35,7 +36,7 @@ export const inject = ['tools', 'systemPrompt', 'llm', 'subagents', 'sessions']
35
36
  export const PROMPT_ORDER = 40
36
37
 
37
38
  const PROMPT_SECTION = [
38
- '本会话已启用自动任务分解。系统会在每个新用户任务的第一个模型步骤前生成计划,并先把计划显示在对话里;收到【任务分解】后,必须先调用 dsh_workplan_dispatch,等它返回部门执行结果,再做任何其他工具调用或回答。',
39
+ '本会话已启用自动任务分解。系统会在每个新用户任务的第一个模型步骤前生成计划,并先把计划显示在对话里;收到【任务分解】后,必须先调用 dsh_workplan_dispatch(默认 wait 等结果;预计较久时用 mode:"async" 先开跑),再做任何其他工具调用或回答。',
39
40
  '如果当前是 plan 模式:不要调用 dsh_workplan_dispatch;先把计划展示给用户,等待用户审阅并退出 plan 模式后,再调用 dsh_workplan_dispatch 执行。',
40
41
  '纯问候、寒暄、致谢、告别、简单确认(如「你好」「谢谢」「好的」「再见」)不生成计划,也不启动子 Agent;直接自然、简短地回答。只有包含实际目标、问题或交付物的消息才进行分解。',
41
42
  '单独的「继续」「接着」「然后呢」「下一步」等没有新增任务内容的追问,不生成计划;由主 Agent 结合会话上下文继续,或先询问用户要延续哪件事。',
@@ -45,9 +46,26 @@ const PROMPT_SECTION = [
45
46
  '2. 核对每个完成子任务的证据与验收标准,不合格的要用 dsh_workplan_update 标记为 blocked 或 in_progress;',
46
47
  '3. 对受阻项向用户说明,必要时先询问再继续;',
47
48
  '4. 不要声称未经验证的完成,不要重复派发已完成的子任务。',
49
+ '结果消息里每个完成项都带 verification 与 acceptance:`structured` 是子 Agent 逐条自检通过,`unverified` 是自述但未逐条确认,`failed` 是自检失败(已按受阻处理),`legacy` 是旧格式回传。只把 structured 当作可直接采信,其余必须你自己核对产物。',
50
+ '子 Agent 通过 `needs` 提出的跨部门需求会列在结果消息的「跨部门待转达」里:由你逐条处理(补派、向用户确认或直接完成),不要忽略。',
51
+ '长任务可以用 `dsh_workplan_dispatch({ mode: "async" })` 先开跑并立即答复用户,再用 `dsh_workplan_status` 查看进度;async 返回的是“已开跑”,不是“已完成”。',
48
52
  '如果自动分解降级,先向用户说明失败原因并询问是否重试,在用户确认前不要开始执行任务。',
49
53
  ].join('\n')
50
54
 
55
+ /**
56
+ * Seconds a dispatch has been running, from the payload only.
57
+ *
58
+ * `elapsedMs` is authoritative; `startedAt` is the fallback for a payload that
59
+ * carries no elapsed value. Computing this inside the template mixed `??` with
60
+ * a conditional and could silently print the wrong number.
61
+ */
62
+ function elapsedSeconds(result: any) {
63
+ const elapsed = Number(result?.elapsedMs)
64
+ if (Number.isFinite(elapsed) && elapsed >= 0) return elapsed
65
+ const startedAt = Number(result?.startedAt)
66
+ return Number.isFinite(startedAt) && startedAt > 0 ? Date.now() - startedAt : 0
67
+ }
68
+
51
69
  function textContent(text: any) {
52
70
  return [{ type: 'text', text }]
53
71
  }
@@ -106,6 +124,14 @@ function createUpdateTool(runtime: any) {
106
124
  items: { type: 'string' },
107
125
  description: '支持该状态的证据(文件、命令输出、验收结果)。',
108
126
  },
127
+ expectedRevision: {
128
+ type: 'integer',
129
+ description: '你读取到的 revision。传入后若该子任务已被更新,会返回 STALE_WRITE 而不是覆盖新证据。',
130
+ },
131
+ force: {
132
+ type: 'boolean',
133
+ description: '计划执行中强行改判(默认拒绝并返回 TASK_RUNNING)。会记录为人工改判。',
134
+ },
109
135
  note: {
110
136
  type: 'string',
111
137
  description: '补充说明;会显示在任务卡片中。',
@@ -122,7 +148,7 @@ function createUpdateTool(runtime: any) {
122
148
  const text = result.ok
123
149
  ? `已更新子任务 ${String(result.subtaskId ?? '')}:${String(result.status ?? '')}`
124
150
  + `(完成 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)},受阻 ${Number(stats.blocked ?? 0)})`
125
- : `更新失败:${String(result.error ?? '未知错误')}`
151
+ : `更新失败${result.code ? `(${String(result.code)})` : ''}:${String(result.error ?? result.hint ?? '未知错误')}`
126
152
  return textContent(text)
127
153
  },
128
154
  },
@@ -184,6 +210,46 @@ function createCancelTool(runtime: any) {
184
210
  }
185
211
  }
186
212
 
213
+ function createStatusTool(runtime: any) {
214
+ return {
215
+ name: 'dsh_workplan_status',
216
+ description:
217
+ '只读查看当前计划各子任务的实时状态与进度,不启动任何 Agent、不改任何状态。'
218
+ + '在 async 派发之后、或用户问“做到哪了”时使用;它是进度问题的唯一可信来源。',
219
+ parameters: {
220
+ type: 'object',
221
+ properties: {
222
+ planId: {
223
+ type: 'string',
224
+ description: '计划 ID;省略时使用当前会话最新计划。',
225
+ },
226
+ },
227
+ additionalProperties: false,
228
+ },
229
+ output: {
230
+ schema: statusToolOutputSchema(),
231
+ render(_args: any, value: any) {
232
+ const result = isRecord(value) ? value : {}
233
+ const stats = isRecord(result.stats) ? result.stats : {}
234
+ if (!result.ok) return textContent(`查询失败:${String(result.error ?? '未知错误')}`)
235
+ const running = result.running === true
236
+ return textContent(
237
+ `计划 ${String(result.planId ?? '')}|${running ? '执行中' : '未在执行'}`
238
+ + `|阶段:${phaseLabel(result.phase)}`
239
+ + `|完成 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)},受阻 ${Number(stats.blocked ?? 0)}`
240
+ + (running && Number(result.elapsedMs ?? 0) > 0
241
+ ? `|已 ${Math.round(Number(result.elapsedMs) / 1000)}s`
242
+ : ''),
243
+ )
244
+ },
245
+ },
246
+ async execute(args: any, exec: any) {
247
+ const parsed = asObject(args) ?? {}
248
+ return runtime.statusTool(exec.agent, parsed)
249
+ },
250
+ }
251
+ }
252
+
187
253
  function createDispatchTool(runtime: any) {
188
254
  return {
189
255
  name: 'dsh_workplan_dispatch',
@@ -197,6 +263,12 @@ function createDispatchTool(runtime: any) {
197
263
  type: 'string',
198
264
  description: '计划 ID;省略时使用当前会话最新计划。',
199
265
  },
266
+ mode: {
267
+ type: 'string',
268
+ enum: ['wait', 'async'],
269
+ description: '默认 wait:等本轮结束后返回完整结果。async:立即返回 running,'
270
+ + '本轮结束时自动写入结果消息;期间用 dsh_workplan_status 查看进度。',
271
+ },
200
272
  },
201
273
  additionalProperties: false,
202
274
  },
@@ -209,7 +281,10 @@ function createDispatchTool(runtime: any) {
209
281
  result.ok
210
282
  ? `计划 ${String(result.planId ?? '')} 当前阶段:${phaseLabel(result.phase)}`
211
283
  + `(完成 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)},受阻 ${Number(stats.blocked ?? 0)})`
212
- + (result.alreadyRunning ? `|仍在执行(已 ${Math.round(Number(result.elapsedMs ?? 0) / 1000)}s)` : '')
284
+ + (result.alreadyRunning || result.mode === 'async'
285
+ ? `|已在执行(${Math.round(elapsedSeconds(result) / 1000)}s)`
286
+ : '')
287
+ + (result.joined ? '|已加入进行中的派发并等到结果' : '')
213
288
  // The hint carries the recovery instruction (resume, or take the work
214
289
  // over directly); showing it in the rendered line keeps it visible
215
290
  // even when only the summary is read.
@@ -267,6 +342,7 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
267
342
 
268
343
  ctx.effect(() => ctx.tools.register(createUpdateTool(runtime)))
269
344
  ctx.effect(() => ctx.tools.register(createCancelTool(runtime)))
345
+ ctx.effect(() => ctx.tools.register(createStatusTool(runtime)))
270
346
  ctx.effect(() => ctx.tools.register(createDispatchTool(runtime)))
271
347
 
272
348
  /*
@@ -325,9 +401,9 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
325
401
 
326
402
  export const meta = {
327
403
  name,
328
- version: '1.5.2',
404
+ version: '1.7.0',
329
405
  promptOrder: PROMPT_ORDER,
330
406
  routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
331
407
  }
332
408
 
333
- export { PROMPT_SECTION, createCancelTool, createDispatchTool, createUpdateTool, plannerOutputSchema }
409
+ export { PROMPT_SECTION, createCancelTool, createDispatchTool, createStatusTool, createUpdateTool, plannerOutputSchema }