dsh-workplan 1.6.0 → 1.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-workplan",
3
- "version": "1.6.0",
3
+ "version": "1.7.1",
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
@@ -10,9 +10,11 @@ import { readFileSync } from 'node:fs'
10
10
  */
11
11
 
12
12
  import {
13
+ cancelToolOutputSchema,
13
14
  createWorkplanRuntime,
14
15
  dispatchToolOutputSchema,
15
16
  plannerOutputSchema,
17
+ statusToolOutputSchema,
16
18
  updateToolOutputSchema,
17
19
  } from './runtime.js'
18
20
  import { isRecord } from './plan.js'
@@ -35,7 +37,7 @@ export const inject = ['tools', 'systemPrompt', 'llm', 'subagents', 'sessions']
35
37
  export const PROMPT_ORDER = 40
36
38
 
37
39
  const PROMPT_SECTION = [
38
- '本会话已启用自动任务分解。系统会在每个新用户任务的第一个模型步骤前生成计划,并先把计划显示在对话里;收到【任务分解】后,必须先调用 dsh_workplan_dispatch,等它返回部门执行结果,再做任何其他工具调用或回答。',
40
+ '本会话已启用自动任务分解。系统会在每个新用户任务的第一个模型步骤前生成计划,并先把计划显示在对话里;收到【任务分解】后,必须先调用 dsh_workplan_dispatch(默认 wait 等结果;预计较久时用 mode:"async" 先开跑),再做任何其他工具调用或回答。',
39
41
  '如果当前是 plan 模式:不要调用 dsh_workplan_dispatch;先把计划展示给用户,等待用户审阅并退出 plan 模式后,再调用 dsh_workplan_dispatch 执行。',
40
42
  '纯问候、寒暄、致谢、告别、简单确认(如「你好」「谢谢」「好的」「再见」)不生成计划,也不启动子 Agent;直接自然、简短地回答。只有包含实际目标、问题或交付物的消息才进行分解。',
41
43
  '单独的「继续」「接着」「然后呢」「下一步」等没有新增任务内容的追问,不生成计划;由主 Agent 结合会话上下文继续,或先询问用户要延续哪件事。',
@@ -45,9 +47,26 @@ const PROMPT_SECTION = [
45
47
  '2. 核对每个完成子任务的证据与验收标准,不合格的要用 dsh_workplan_update 标记为 blocked 或 in_progress;',
46
48
  '3. 对受阻项向用户说明,必要时先询问再继续;',
47
49
  '4. 不要声称未经验证的完成,不要重复派发已完成的子任务。',
50
+ '结果消息里每个完成项都带 verification 与 acceptance:`structured` 是子 Agent 逐条自检通过,`unverified` 是自述但未逐条确认,`failed` 是自检失败(已按受阻处理),`legacy` 是旧格式回传。只把 structured 当作可直接采信,其余必须你自己核对产物。',
51
+ '子 Agent 通过 `needs` 提出的跨部门需求会列在结果消息的「跨部门待转达」里:由你逐条处理(补派、向用户确认或直接完成),不要忽略。',
52
+ '长任务可以用 `dsh_workplan_dispatch({ mode: "async" })` 先开跑并立即答复用户,再用 `dsh_workplan_status` 查看进度;async 返回的是“已开跑”,不是“已完成”。',
48
53
  '如果自动分解降级,先向用户说明失败原因并询问是否重试,在用户确认前不要开始执行任务。',
49
54
  ].join('\n')
50
55
 
56
+ /**
57
+ * Seconds a dispatch has been running, from the payload only.
58
+ *
59
+ * `elapsedMs` is authoritative; `startedAt` is the fallback for a payload that
60
+ * carries no elapsed value. Computing this inside the template mixed `??` with
61
+ * a conditional and could silently print the wrong number.
62
+ */
63
+ function elapsedSeconds(result: any) {
64
+ const elapsed = Number(result?.elapsedMs)
65
+ if (Number.isFinite(elapsed) && elapsed >= 0) return elapsed
66
+ const startedAt = Number(result?.startedAt)
67
+ return Number.isFinite(startedAt) && startedAt > 0 ? Date.now() - startedAt : 0
68
+ }
69
+
51
70
  function textContent(text: any) {
52
71
  return [{ type: 'text', text }]
53
72
  }
@@ -97,15 +116,21 @@ function createUpdateTool(runtime: any) {
97
116
  },
98
117
  progress: {
99
118
  type: 'integer',
100
- minimum: 0,
101
- maximum: 100,
102
- description: '进度百分比;done 会自动置为 100。',
119
+ description: '进度百分比(0-100);done 会自动置为 100。',
103
120
  },
104
121
  evidence: {
105
122
  type: 'array',
106
123
  items: { type: 'string' },
107
124
  description: '支持该状态的证据(文件、命令输出、验收结果)。',
108
125
  },
126
+ expectedRevision: {
127
+ type: 'integer',
128
+ description: '你读取到的 revision。传入后若该子任务已被更新,会返回 STALE_WRITE 而不是覆盖新证据。',
129
+ },
130
+ force: {
131
+ type: 'boolean',
132
+ description: '计划执行中强行改判(默认拒绝并返回 TASK_RUNNING)。会记录为人工改判。',
133
+ },
109
134
  note: {
110
135
  type: 'string',
111
136
  description: '补充说明;会显示在任务卡片中。',
@@ -122,7 +147,7 @@ function createUpdateTool(runtime: any) {
122
147
  const text = result.ok
123
148
  ? `已更新子任务 ${String(result.subtaskId ?? '')}:${String(result.status ?? '')}`
124
149
  + `(完成 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)},受阻 ${Number(stats.blocked ?? 0)})`
125
- : `更新失败:${String(result.error ?? '未知错误')}`
150
+ : `更新失败${result.code ? `(${String(result.code)})` : ''}:${String(result.error ?? result.hint ?? '未知错误')}`
126
151
  return textContent(text)
127
152
  },
128
153
  },
@@ -156,17 +181,7 @@ function createCancelTool(runtime: any) {
156
181
  additionalProperties: false,
157
182
  },
158
183
  output: {
159
- schema: {
160
- type: 'object',
161
- properties: {
162
- ok: { type: 'boolean' },
163
- planId: { type: 'string' },
164
- phase: { type: 'string' },
165
- reason: { type: 'string' },
166
- },
167
- required: ['ok'],
168
- additionalProperties: true,
169
- },
184
+ schema: cancelToolOutputSchema(),
170
185
  render(_args: any, value: any) {
171
186
  const result = isRecord(value) ? value : {}
172
187
  return textContent(
@@ -184,6 +199,46 @@ function createCancelTool(runtime: any) {
184
199
  }
185
200
  }
186
201
 
202
+ function createStatusTool(runtime: any) {
203
+ return {
204
+ name: 'dsh_workplan_status',
205
+ description:
206
+ '只读查看当前计划各子任务的实时状态与进度,不启动任何 Agent、不改任何状态。'
207
+ + '在 async 派发之后、或用户问“做到哪了”时使用;它是进度问题的唯一可信来源。',
208
+ parameters: {
209
+ type: 'object',
210
+ properties: {
211
+ planId: {
212
+ type: 'string',
213
+ description: '计划 ID;省略时使用当前会话最新计划。',
214
+ },
215
+ },
216
+ additionalProperties: false,
217
+ },
218
+ output: {
219
+ schema: statusToolOutputSchema(),
220
+ render(_args: any, value: any) {
221
+ const result = isRecord(value) ? value : {}
222
+ const stats = isRecord(result.stats) ? result.stats : {}
223
+ if (!result.ok) return textContent(`查询失败:${String(result.error ?? '未知错误')}`)
224
+ const running = result.running === true
225
+ return textContent(
226
+ `计划 ${String(result.planId ?? '')}|${running ? '执行中' : '未在执行'}`
227
+ + `|阶段:${phaseLabel(result.phase)}`
228
+ + `|完成 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)},受阻 ${Number(stats.blocked ?? 0)}`
229
+ + (running && Number(result.elapsedMs ?? 0) > 0
230
+ ? `|已 ${Math.round(Number(result.elapsedMs) / 1000)}s`
231
+ : ''),
232
+ )
233
+ },
234
+ },
235
+ async execute(args: any, exec: any) {
236
+ const parsed = asObject(args) ?? {}
237
+ return runtime.statusTool(exec.agent, parsed)
238
+ },
239
+ }
240
+ }
241
+
187
242
  function createDispatchTool(runtime: any) {
188
243
  return {
189
244
  name: 'dsh_workplan_dispatch',
@@ -197,6 +252,12 @@ function createDispatchTool(runtime: any) {
197
252
  type: 'string',
198
253
  description: '计划 ID;省略时使用当前会话最新计划。',
199
254
  },
255
+ mode: {
256
+ type: 'string',
257
+ enum: ['wait', 'async'],
258
+ description: '默认 wait:等本轮结束后返回完整结果。async:立即返回 running,'
259
+ + '本轮结束时自动写入结果消息;期间用 dsh_workplan_status 查看进度。',
260
+ },
200
261
  },
201
262
  additionalProperties: false,
202
263
  },
@@ -209,7 +270,10 @@ function createDispatchTool(runtime: any) {
209
270
  result.ok
210
271
  ? `计划 ${String(result.planId ?? '')} 当前阶段:${phaseLabel(result.phase)}`
211
272
  + `(完成 ${Number(stats.done ?? 0)}/${Number(stats.total ?? 0)},受阻 ${Number(stats.blocked ?? 0)})`
212
- + (result.alreadyRunning ? `|仍在执行(已 ${Math.round(Number(result.elapsedMs ?? 0) / 1000)}s)` : '')
273
+ + (result.alreadyRunning || result.mode === 'async'
274
+ ? `|已在执行(${Math.round(elapsedSeconds(result) / 1000)}s)`
275
+ : '')
276
+ + (result.joined ? '|已加入进行中的派发并等到结果' : '')
213
277
  // The hint carries the recovery instruction (resume, or take the work
214
278
  // over directly); showing it in the rendered line keeps it visible
215
279
  // even when only the summary is read.
@@ -267,6 +331,7 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
267
331
 
268
332
  ctx.effect(() => ctx.tools.register(createUpdateTool(runtime)))
269
333
  ctx.effect(() => ctx.tools.register(createCancelTool(runtime)))
334
+ ctx.effect(() => ctx.tools.register(createStatusTool(runtime)))
270
335
  ctx.effect(() => ctx.tools.register(createDispatchTool(runtime)))
271
336
 
272
337
  /*
@@ -325,9 +390,9 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
325
390
 
326
391
  export const meta = {
327
392
  name,
328
- version: '1.6.0',
393
+ version: '1.7.1',
329
394
  promptOrder: PROMPT_ORDER,
330
395
  routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
331
396
  }
332
397
 
333
- export { PROMPT_SECTION, createCancelTool, createDispatchTool, createUpdateTool, plannerOutputSchema }
398
+ export { PROMPT_SECTION, createCancelTool, createDispatchTool, createStatusTool, createUpdateTool, plannerOutputSchema }