dsh-workplan 1.6.0 → 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.6.0",
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
@@ -180,6 +180,7 @@ window.__ModuleLoader__.load({
180
180
  "overview": "进度总览",
181
181
  "statusChart": "状态分布",
182
182
  "taskChart": "每个任务的进度",
183
+ "backToTop": "回到顶部",
183
184
  "jumpToTask": "跳转到任务明细",
184
185
  "scopeAll": "当前各会话最新计划汇总",
185
186
  "scopeThis": "本计划",
@@ -350,6 +351,7 @@ window.__ModuleLoader__.load({
350
351
  "overview": "Progress overview",
351
352
  "statusChart": "Status mix",
352
353
  "taskChart": "Progress by task",
354
+ "backToTop": "Back to top",
353
355
  "jumpToTask": "Jump to task details",
354
356
  "scopeAll": "Latest plan per live session",
355
357
  "scopeThis": "This plan",
@@ -536,6 +538,35 @@ window.__ModuleLoader__.load({
536
538
  }
537
539
  .dsh-wp-button:hover { background: var(--dsw-alias-bg-layer-2); }
538
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; }
539
570
  .dsh-wp-banner {
540
571
  border: 1px solid var(--dsw-alias-border-l1);
541
572
  background: var(--dsw-alias-bg-layer-1);
@@ -2383,6 +2414,9 @@ window.__ModuleLoader__.load({
2383
2414
  )
2384
2415
  }
2385
2416
 
2417
+ /* [T4] 回到顶部的显示阈值(px):scrollTop 严格大于该值才显示。 */
2418
+ const BACK_TOP_THRESHOLD = 200
2419
+
2386
2420
  function Dashboard({ t }: any) {
2387
2421
  const { sessions, error, loading, updatedAt, reload } = usePlans()
2388
2422
  const [openSessionId, setOpenSessionId] = useState(null)
@@ -2518,7 +2552,44 @@ window.__ModuleLoader__.load({
2518
2552
  value: planPercent(planCount(session.stats?.done), planCount(session.stats?.total)) ?? 0,
2519
2553
  }
2520
2554
  }), [groups, t])
2521
- 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
+ },
2522
2593
  h('header', { className: 'dsh-wp-header' },
2523
2594
  h('div', null,
2524
2595
  h('h1', { className: 'dsh-wp-title' }, t('title')),
@@ -2542,6 +2613,12 @@ window.__ModuleLoader__.load({
2542
2613
  activeSessions.length === 0
2543
2614
  ? h('div', { className: 'dsh-wp-empty' }, h('div', { style: { fontWeight: 650, marginBottom: '4px' } }, t('empty')), h('div', null, t('emptyHint')))
2544
2615
  : h('div', { className: 'dsh-wp-groups' },
2616
+ // [用户要求] 总览块(完成率环 + 每个任务的进度)上移到分组之前:
2617
+ // 用户要求红圈的「每个任务的进度」必须显示在「进行中」组之上。
2618
+ activeSessions.length > 0 ? h('div', { className: 'dsh-wp-overview' },
2619
+ h(Donut, { totals, t }),
2620
+ h(TaskBars, { sessions: activeSessions, t, onSelect: selectSession }),
2621
+ ) : null,
2545
2622
  /*
2546
2623
  * [1.6.0] 三组顺序:真的在跑 → 已结束(停在半路) → 已完成。
2547
2624
  * 「已结束」夹在中间是有意为之:它是用户最需要立刻知道的那一档
@@ -2552,18 +2629,23 @@ window.__ModuleLoader__.load({
2552
2629
  ? h(SessionGroup, { key: 'ended', group: 'ended', list: groups.ended, hasLive: groups.live.length > 0, urgent: groups.urgentEnded, t, openSessionId, setOpenSessionId })
2553
2630
  : null,
2554
2631
  h(SessionGroup, { key: 'done', group: 'done', list: groups.finished, hasLive: groups.live.length > 0 || groups.ended.length > 0, urgent: 0, t, openSessionId, setOpenSessionId }),
2555
- // 用户选择 B:总览块(完成率环 + 每个计划的进度条)同样下移到两组之后,
2556
- // 让开屏第一屏直接是「进行中」组的任务卡(此前统计条 → 总览 → 说明行 →
2557
- // 任务卡,第一张卡要下滑约一屏)。顶部只保留 5 格数字统计条与一行口径说明。
2558
- activeSessions.length > 0 ? h('div', { className: 'dsh-wp-overview' },
2559
- h(Donut, { totals, t }),
2560
- h(TaskBars, { sessions: activeSessions, t, onSelect: selectSession }),
2561
- ) : null,
2562
2632
  // 图表放两组之后:两张卡各 ≈246px,排在组前会让首屏看不到任何一张任务卡
2563
2633
  // (设计稿 §8 第 12 条,T8 复核时复现在 1.4.2 源码里)。
2564
2634
  // [1.6.0] 「未结束」= 进行中 + 已结束但未完成:两者都还没做完,都是用户要盯的对象。
2565
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 }),
2566
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' }, '↑')),
2567
2649
  )
2568
2650
  }
2569
2651
 
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.6.0',
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 }