@restregular/dsh-powerup 0.10.7 → 0.11.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/README.md CHANGED
@@ -408,6 +408,29 @@ record carrying its own workspace id, so the settings page can manage every
408
408
  workspace together. Older per-workspace files are migrated automatically on
409
409
  first access.
410
410
 
411
+ ### Task progress snapshot
412
+
413
+ A **Progress** button in the session header generates a structured view of
414
+ what the current task has accomplished so far, without blocking or disturbing
415
+ the running agent:
416
+
417
+ - **Off to the side.** Clicking the button asks the Host to start a separate
418
+ model call that reuses the session's own provider/model. That call reads a
419
+ compact copy of the recent conversation, runs under its own abort/timeout,
420
+ writes **nothing** to the session log, and never touches the agent's turn —
421
+ you can keep working while it runs. The panel polls until it settles.
422
+ - **Model picks the structure.** The report is one JSON object whose `mode`
423
+ the model chooses from `checklist`, `phases`, `milestones`, or `tree`, with
424
+ status badges, progress meter, blockers, and per-node details rendered for
425
+ that shape. The Host validates and normalizes the result before it reaches
426
+ the UI.
427
+ - **Model-rendered extras.** The report may include a `display` array of blocks
428
+ (`text`, `kv`, `callout`, `bars`, `code`) that the panel renders directly, so
429
+ the model can surface any additional user-facing content it finds useful
430
+ without the plugin needing to anticipate every format.
431
+ - The feature is on by default and can be switched off on the Power-Up page;
432
+ reports are cached per session in memory and marked stale after a minute.
433
+
411
434
  ### Dual send buttons
412
435
 
413
436
  When enabled on the Power-Up page, two compact controls appear at the right of
package/client.js CHANGED
@@ -83,7 +83,7 @@
83
83
  const promptCreateDraft = { workspaceId: null, title: '', text: '', scope: 'current' };
84
84
  /** Fallback bucket when the hero cannot resolve an owning workspace yet. */
85
85
  const UNSCOPED_WORKSPACE = '__unscoped__';
86
- const VERSION = '0.10.7';
86
+ const VERSION = '0.11.0';
87
87
  const MENU_GAP = 8;
88
88
  const MENU_WIDTH = 248;
89
89
  /** Reference scheme understood by the Host's `powerup_step_read` tool. */
@@ -344,6 +344,22 @@
344
344
  'update.invalidVersion': '请输入有效版本号(例如 1.2.3)',
345
345
  'update.stopProfile': '当前 profile 不能热卸载该插件,请重启 DSH 后再试。',
346
346
  'update.unsupportedTitle': '无法自动安装',
347
+ 'page.taskProgressTitle': '任务进度速览',
348
+ 'page.taskProgressDesc': '在会话顶部加一个「进度」按钮,点击后用当前会话的模型在后台分析会话记录,生成结构化的任务进度并用浮层展示。调用在旁路进行,不写入会话、不打断正在运行的任务;模型会按任务类型选择清单、阶段、里程碑或任务树,并可补充一段直接渲染给用户看的内容。',
349
+ 'page.taskProgressHow': '在任意会话顶部点击「进度」按钮,面板会显示最近一次结果;首次使用点「生成进度」。生成期间可继续正常操作会话。',
350
+ 'progress.title': '任务进度',
351
+ 'progress.label': '进度',
352
+ 'progress.subtitle': '由当前会话模型在后台生成',
353
+ 'progress.hint': '还没有进度报告,点「生成进度」开始分析。',
354
+ 'progress.empty': '还没有生成过进度报告。',
355
+ 'progress.generate': '生成进度',
356
+ 'progress.refresh': '重新生成',
357
+ 'progress.retry': '重试',
358
+ 'progress.loading': '正在后台分析会话进度…',
359
+ 'progress.close': '关闭',
360
+ 'progress.failed': '生成进度失败',
361
+ 'progress.stale': '报告已过期',
362
+ 'progress.updated': '更新于 {time}',
347
363
  'page.promptsTitle': '工作区提示词',
348
364
  'page.promptsDesc': '为每个工作区保存可复用的提示词。开启后,新会话行的 Agent 预设右侧会出现一个下拉列表,选择即可把提示词填入输入框(可继续编辑),或点提示词右侧的发送按钮直接发出。',
349
365
  'page.promptsHow': '先启用本功能,再切到「工作区提示词」标签页创建提示词;提示词按工作区隔离,没有标题时显示开头几个字。',
@@ -650,6 +666,22 @@
650
666
  'update.invalidVersion': 'Enter a valid version, for example 1.2.3.',
651
667
  'update.stopProfile': 'This profile cannot hot-remove the plugin; restart DSH and try again.',
652
668
  'update.unsupportedTitle': 'Cannot install automatically',
669
+ 'page.taskProgressTitle': 'Task progress snapshot',
670
+ 'page.taskProgressDesc': 'Adds a Progress button to the session header. Clicking it asks the current session model to analyze the session in the background and produce a structured progress report shown in a floating panel. The call is off to the side: nothing is written to the session and the running task is never interrupted. The model picks a checklist, phases, milestones, or task tree to fit the work, and may add content rendered directly in the panel.',
671
+ 'page.taskProgressHow': 'Click Progress in any session header to see the last report; on first use press Generate. You can keep working in the session while it runs.',
672
+ 'progress.title': 'Task progress',
673
+ 'progress.label': 'Progress',
674
+ 'progress.subtitle': 'Generated in the background by this session model',
675
+ 'progress.hint': 'No progress report yet. Press Generate to analyze the session.',
676
+ 'progress.empty': 'No progress report generated yet.',
677
+ 'progress.generate': 'Generate progress',
678
+ 'progress.refresh': 'Regenerate',
679
+ 'progress.retry': 'Retry',
680
+ 'progress.loading': 'Analyzing session progress in the background…',
681
+ 'progress.close': 'Close',
682
+ 'progress.failed': 'Could not generate progress',
683
+ 'progress.stale': 'Stale report',
684
+ 'progress.updated': 'Updated at {time}',
653
685
  'page.promptsTitle': 'Workspace prompts',
654
686
  'page.promptsDesc': 'Save reusable prompts per workspace. When enabled, a dropdown appears next to the Agent preset in the New Session row: pick a prompt to fill the composer (still editable), or click its send button to send it right away.',
655
687
  'page.promptsHow': 'Enable this feature, then open the "Workspace prompts" tab to create prompts. Prompts are scoped per workspace; without a title the first few characters are shown.',
@@ -747,6 +779,7 @@
747
779
  contentRendering: true,
748
780
  dualSend: false,
749
781
  workspacePrompts: true,
782
+ taskProgress: true,
750
783
  oneClickEnable: true,
751
784
  oneClickRestart: true,
752
785
  };
@@ -769,6 +802,7 @@
769
802
  contentRendering: parsed.contentRendering !== false,
770
803
  dualSend: parsed.dualSend === true,
771
804
  workspacePrompts: parsed.workspacePrompts !== false,
805
+ taskProgress: parsed.taskProgress !== false,
772
806
  oneClickEnable: parsed.oneClickEnable !== false,
773
807
  oneClickRestart: parsed.oneClickRestart !== false,
774
808
  };
@@ -3816,6 +3850,16 @@
3816
3850
  );
3817
3851
  }
3818
3852
 
3853
+ /** A radar/target glyph for the task-progress side call. */
3854
+ function ProgressIcon({ size = 16 }) {
3855
+ return h(Icon, { size },
3856
+ h('circle', { cx: '8', cy: '8', r: '5.8', fill: 'none', stroke: 'currentColor', strokeWidth: '1.2' }),
3857
+ h('circle', { cx: '8', cy: '8', r: '2.6', fill: 'none', stroke: 'currentColor', strokeWidth: '1.2' }),
3858
+ h('path', { d: 'M8 8 12.4 3.6', stroke: 'currentColor', strokeWidth: '1.2', strokeLinecap: 'round' }),
3859
+ h('circle', { cx: '8', cy: '8', r: '.9', fill: 'currentColor' }),
3860
+ );
3861
+ }
3862
+
3819
3863
  function ChevronDownIcon({ size = 12 }) {
3820
3864
  return h(Icon, { size },
3821
3865
  h('path', {
@@ -4342,6 +4386,69 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
4342
4386
  .dsh-powerup-prompt-modal-close:focus-visible,.dsh-powerup-prompt-modal-cancel:focus-visible,.dsh-powerup-prompt-modal-save:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}
4343
4387
  @media (max-width:560px){.dsh-powerup-prompt-modal-mask{padding:12px}.dsh-powerup-prompt-modal-head{padding:16px 12px 8px 16px}.dsh-powerup-prompt-modal-body{padding:0 16px 4px}.dsh-powerup-prompt-modal-foot{padding:12px 16px 16px}}
4344
4388
  @media (prefers-reduced-motion:reduce){.dsh-powerup-prompt-pop,.dsh-powerup-prompt-trigger-chevron,.dsh-powerup-prompt-modal-mask,.dsh-powerup-prompt-modal,.dsh-powerup-prompt-modal-mask.is-closing,.dsh-powerup-prompt-modal.is-closing{transition:none;animation:none}}
4389
+ `;
4390
+
4391
+ const PROGRESS_CSS = `
4392
+ /* Task-progress header button + floating panel. */
4393
+ .dsh-powerup-progress-btn{display:inline-flex;align-items:center;justify-content:center;gap:5px;min-width:26px;height:26px;padding:0 7px;border:.5px solid var(--dsw-alias-border-l2);border-radius:7px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);font:inherit;font-size:11.5px;line-height:1;cursor:pointer;transition:background .12s ease,color .12s ease,border-color .12s ease}
4394
+ .dsh-powerup-progress-btn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l3)}
4395
+ .dsh-powerup-progress-btn:focus-visible{outline:2px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}
4396
+ .dsh-powerup-progress-btn.is-running{color:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary)}
4397
+ .dsh-powerup-progress-btn.is-running svg{animation:dsh-powerup-progress-spin 1.4s linear infinite}
4398
+ @keyframes dsh-powerup-progress-spin{to{transform:rotate(360deg)}}
4399
+ .dsh-powerup-progress-btn-dot{flex:none;width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-state-success-primary)}
4400
+ .dsh-powerup-progress-panel{position:fixed;z-index:1500;box-sizing:border-box;display:flex;flex-direction:column;width:360px;max-width:calc(100vw - 24px);max-height:min(72vh,620px);border:0;border-radius:var(--dsw-radius-panel,14px);background:var(--dsw-alias-bg-layer-2);box-shadow:var(--dsw-elevation-prominent);--dsw-elevation-stroke-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-primary);font-size:12px;line-height:1.55;pointer-events:auto;overflow:hidden;--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2);animation:dsh-powerup-progress-in .15s ease-out}
4401
+ @keyframes dsh-powerup-progress-in{from{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:none}}
4402
+ .dsh-powerup-progress-head{display:flex;align-items:flex-start;gap:8px;padding:14px 14px 10px 16px;border-bottom:.5px solid var(--dsw-alias-border-l1)}
4403
+ .dsh-powerup-progress-heading{display:flex;flex:1 1 auto;flex-direction:column;gap:2px;min-width:0}
4404
+ .dsh-powerup-progress-title{font-size:14px;font-weight:600;line-height:1.35;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
4405
+ .dsh-powerup-progress-sub{color:var(--dsw-alias-label-tertiary);font-size:10.5px;line-height:1.4}
4406
+ .dsh-powerup-progress-close{flex:none;display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;margin:-2px -2px 0 0;padding:0;border:0;border-radius:var(--dsw-radius-sm);background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:17px;line-height:1;cursor:pointer}
4407
+ .dsh-powerup-progress-close:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
4408
+ .dsh-powerup-progress-body{flex:1 1 auto;min-height:0;overflow-y:auto;padding:12px 16px 16px}
4409
+ .dsh-powerup-progress-loading{display:flex;align-items:center;gap:9px;color:var(--dsw-alias-label-secondary);font-size:12px}
4410
+ .dsh-powerup-progress-error{margin:0;color:var(--dsw-alias-state-error-primary);font-size:11.5px;line-height:1.6;overflow-wrap:anywhere}
4411
+ .dsh-powerup-progress-empty{color:var(--dsw-alias-label-tertiary);font-size:11.5px;line-height:1.6}
4412
+ .dsh-powerup-progress-summary{margin:0 0 12px;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.6;overflow-wrap:anywhere}
4413
+ .dsh-powerup-progress-meter{display:flex;flex-direction:column;gap:5px;margin:0 0 14px}
4414
+ .dsh-powerup-progress-meter-head{display:flex;align-items:center;justify-content:space-between;color:var(--dsw-alias-label-tertiary);font-size:10.5px}
4415
+ .dsh-powerup-progress-meter-head strong{color:var(--dsw-alias-brand-primary);font-size:12px;font-variant-numeric:tabular-nums}
4416
+ .dsh-powerup-progress-track{height:6px;border-radius:999px;background:var(--dsw-alias-border-l2);overflow:hidden}
4417
+ .dsh-powerup-progress-fill{height:100%;border-radius:999px;background:var(--dsw-alias-brand-primary);transition:width .3s ease}
4418
+ .dsh-powerup-progress-section{margin:12px 0 6px;color:var(--dsw-alias-label-tertiary);font-size:10.5px;font-weight:600;letter-spacing:.04em;text-transform:uppercase}
4419
+ .dsh-powerup-progress-items{display:flex;flex-direction:column;gap:6px;margin:0;padding:0;list-style:none}
4420
+ .dsh-powerup-progress-item{display:flex;align-items:flex-start;gap:8px;padding:6px 8px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;background:var(--dsw-alias-bg-layer-1)}
4421
+ .dsh-powerup-progress-badge{flex:none;display:inline-flex;align-items:center;justify-content:center;min-width:16px;height:16px;padding:0 5px;border-radius:8px;font-size:9.5px;font-weight:700;letter-spacing:.02em}
4422
+ .dsh-powerup-progress-badge[data-status=pending]{background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-tertiary)}
4423
+ .dsh-powerup-progress-badge[data-status=in-progress]{background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 14%,transparent);color:var(--dsw-alias-state-business-primary)}
4424
+ .dsh-powerup-progress-badge[data-status=done]{background:color-mix(in srgb,var(--dsw-alias-state-success-primary) 14%,transparent);color:var(--dsw-alias-state-success-primary)}
4425
+ .dsh-powerup-progress-badge[data-status=blocked]{background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 14%,transparent);color:var(--dsw-alias-state-error-primary)}
4426
+ .dsh-powerup-progress-item-copy{display:flex;flex:1 1 auto;flex-direction:column;gap:2px;min-width:0}
4427
+ .dsh-powerup-progress-item-title{color:var(--dsw-alias-label-primary);font-size:11.5px;line-height:1.5;overflow-wrap:anywhere}
4428
+ .dsh-powerup-progress-item-detail{color:var(--dsw-alias-label-tertiary);font-size:10.5px;line-height:1.5;overflow-wrap:anywhere}
4429
+ .dsh-powerup-progress-children{margin:4px 0 0 6px;padding-left:10px;border-left:1px solid var(--dsw-alias-border-l2)}
4430
+ .dsh-powerup-progress-blockers{margin:12px 0 0;padding:8px 10px;border:1px solid color-mix(in srgb,var(--dsw-alias-state-error-primary) 30%,transparent);border-radius:8px;background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 7%,transparent);color:var(--dsw-alias-state-error-primary);font-size:11px;line-height:1.55}
4431
+ .dsh-powerup-progress-blockers ul{margin:4px 0 0;padding-left:16px}
4432
+ .dsh-powerup-progress-display{display:flex;flex-direction:column;gap:10px;margin-top:14px;padding-top:12px;border-top:.5px solid var(--dsw-alias-border-l1)}
4433
+ .dsh-powerup-progress-display-head{color:var(--dsw-alias-label-tertiary);font-size:10.5px;font-weight:600;letter-spacing:.04em;text-transform:uppercase}
4434
+ .dsh-powerup-progress-display-text{color:var(--dsw-alias-label-secondary);font-size:11.5px;line-height:1.65;overflow-wrap:anywhere;white-space:pre-wrap}
4435
+ .dsh-powerup-progress-kv{display:flex;flex-direction:column;gap:4px}
4436
+ .dsh-powerup-progress-kv-row{display:flex;align-items:baseline;justify-content:space-between;gap:12px}
4437
+ .dsh-powerup-progress-kv-row dt{flex:none;color:var(--dsw-alias-label-tertiary);font-size:11px}
4438
+ .dsh-powerup-progress-kv-row dd{margin:0;min-width:0;text-align:right;color:var(--dsw-alias-label-primary);font-size:11.5px;overflow-wrap:anywhere}
4439
+ .dsh-powerup-progress-callout{padding:8px 10px;border-radius:8px;font-size:11.5px;line-height:1.6;overflow-wrap:anywhere}
4440
+ .dsh-powerup-progress-callout[data-tone=info]{background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-secondary)}
4441
+ .dsh-powerup-progress-callout[data-tone=warn]{background:color-mix(in srgb,var(--dsw-alias-state-warning-primary,var(--dsw-alias-state-error-primary)) 10%,transparent);color:var(--dsw-alias-state-warning-primary,var(--dsw-alias-state-error-primary))}
4442
+ .dsh-powerup-progress-callout[data-tone=success]{background:color-mix(in srgb,var(--dsw-alias-state-success-primary) 10%,transparent);color:var(--dsw-alias-state-success-primary)}
4443
+ .dsh-powerup-progress-bar{display:flex;flex-direction:column;gap:3px;margin-bottom:6px}
4444
+ .dsh-powerup-progress-bar-head{display:flex;justify-content:space-between;color:var(--dsw-alias-label-secondary);font-size:10.5px}
4445
+ .dsh-powerup-progress-code{margin:0;padding:8px 10px;border-radius:8px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);font-family:var(--dsw-font-family-code,ui-monospace,SFMono-Regular,Consolas,monospace);font-size:11px;line-height:1.5;overflow-x:auto;white-space:pre-wrap;overflow-wrap:anywhere}
4446
+ .dsh-powerup-progress-foot{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:10px 16px;border-top:.5px solid var(--dsw-alias-border-l1)}
4447
+ .dsh-powerup-progress-refresh{height:28px;padding:0 12px;border:.5px solid var(--dsw-alias-border-l2);border-radius:7px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);font:inherit;font-size:11.5px;line-height:1.5;cursor:pointer}
4448
+ .dsh-powerup-progress-refresh:hover{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary)}
4449
+ .dsh-powerup-progress-refresh:disabled{opacity:.45;cursor:not-allowed}
4450
+ .dsh-powerup-progress-time{color:var(--dsw-alias-label-caption);font-size:10px}
4451
+ @media (prefers-reduced-motion:reduce){.dsh-powerup-progress-panel,.dsh-powerup-progress-btn.is-running svg,.dsh-powerup-progress-fill{animation:none;transition:none}}
4345
4452
  `;
4346
4453
 
4347
4454
  /** Max display length of a session option, in Unicode code points. */
@@ -5558,7 +5665,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
5558
5665
  try {
5559
5666
  const style = document.createElement('style');
5560
5667
  style.setAttribute('data-dsh-powerup', '');
5561
- style.textContent = CSS + '\n' + LAUNCHER_CSS + '\n' + SESSION_SWITCH_CSS + '\n' + LOCATE_CSS + '\n' + SCROLL_TOP_CSS + '\n' + RENDERING_CSS + '\n' + PROMPTS_CSS;
5668
+ style.textContent = CSS + '\n' + LAUNCHER_CSS + '\n' + SESSION_SWITCH_CSS + '\n' + LOCATE_CSS + '\n' + SCROLL_TOP_CSS + '\n' + RENDERING_CSS + '\n' + PROMPTS_CSS + '\n' + PROGRESS_CSS;
5562
5669
  document.head.appendChild(style);
5563
5670
  ctx.effect(() => () => style.remove(), 'dsh-powerup: styles');
5564
5671
  } catch (error) {
@@ -9470,6 +9577,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
9470
9577
  featureCard('scrollToTop', ScrollTopIcon, 'page.scrollToTopTitle', 'page.scrollToTopDesc', 'page.scrollToTopHow'),
9471
9578
  featureCard('contentRendering', PowerUpLineIcon, 'page.renderingTitle', 'page.renderingDesc', 'page.renderingHow'),
9472
9579
  featureCard('dualSend', LauncherIcon, 'page.dualSendTitle', 'page.dualSendDesc', 'page.dualSendHow'),
9580
+ featureCard('taskProgress', ProgressIcon, 'page.taskProgressTitle', 'page.taskProgressDesc', 'page.taskProgressHow'),
9473
9581
  featureCard('workspacePrompts', TagIcon, 'page.promptsTitle', 'page.promptsDesc', 'page.promptsHow'),
9474
9582
  featureCard('jobStop', StopIcon, 'page.jobStopTitle', 'page.jobStopDesc', 'page.jobStopHow'),
9475
9583
  featureCard('update', UpdateIcon, 'page.updateTitle', 'page.updateDesc', 'page.updateHow', oneClickDetail),
@@ -9523,6 +9631,343 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
9523
9631
  }
9524
9632
  }
9525
9633
 
9634
+ // ------------------------------------------------------------------
9635
+ // Task progress: header button + body-portal panel
9636
+ // ------------------------------------------------------------------
9637
+ const PROGRESS_API = '/dsh-powerup/api/progress';
9638
+
9639
+ /** POST to the progress route; returns the parsed body. */
9640
+ async function progressRequest(sessionId, action) {
9641
+ const response = await fetch(PROGRESS_API, {
9642
+ method: 'POST',
9643
+ headers: { 'content-type': 'application/json' },
9644
+ body: JSON.stringify({ sessionId, action }),
9645
+ });
9646
+ const body = await response.json();
9647
+ if (!body?.ok) throw new Error(body?.error ?? `HTTP ${response.status}`);
9648
+ return body;
9649
+ }
9650
+
9651
+ const STATUS_LABEL = {
9652
+ pending: '待办', 'in-progress': '进行中', done: '完成', blocked: '受阻',
9653
+ };
9654
+ const MODE_LABEL = {
9655
+ checklist: '任务清单', phases: '阶段', milestones: '里程碑', tree: '任务树',
9656
+ };
9657
+
9658
+ /** One status badge. */
9659
+ function ProgressBadge(status) {
9660
+ return h('span', {
9661
+ className: 'dsh-powerup-progress-badge',
9662
+ 'data-status': status,
9663
+ }, STATUS_LABEL[status] ?? status);
9664
+ }
9665
+
9666
+ /** Render one node (checklist step / phase / milestone / tree node). */
9667
+ function ProgressItem(title, status, detail, children, key) {
9668
+ return h('li', { key, className: 'dsh-powerup-progress-item' },
9669
+ ProgressBadge(status),
9670
+ h('div', { className: 'dsh-powerup-progress-item-copy' },
9671
+ h('span', { className: 'dsh-powerup-progress-item-title' }, title),
9672
+ detail ? h('span', { className: 'dsh-powerup-progress-item-detail' }, detail) : null,
9673
+ Array.isArray(children) && children.length > 0
9674
+ ? h('ul', { className: 'dsh-powerup-progress-children' }, children)
9675
+ : null,
9676
+ ),
9677
+ );
9678
+ }
9679
+
9680
+ /** Render the model-chosen structured body. */
9681
+ function ProgressStructure(report) {
9682
+ if (report === null || typeof report !== 'object') return null;
9683
+ const sections = [];
9684
+ const mode = report.mode ?? 'checklist';
9685
+ if (mode === 'phases' && Array.isArray(report.phases) && report.phases.length > 0) {
9686
+ sections.push(h('div', { key: 'phases' },
9687
+ h('div', { className: 'dsh-powerup-progress-section' }, MODE_LABEL.phases),
9688
+ h('ul', { className: 'dsh-powerup-progress-items' }, report.phases.map((phase, i) => ProgressItem(
9689
+ phase.name, phase.status, phase.detail,
9690
+ Array.isArray(phase.steps) && phase.steps.length > 0
9691
+ ? phase.steps.map((s, j) => ProgressItem(s.title, s.status, '', null, `p${i}-s${j}`))
9692
+ : null,
9693
+ `phase-${i}`,
9694
+ ))),
9695
+ ));
9696
+ } else if (mode === 'milestones' && Array.isArray(report.milestones) && report.milestones.length > 0) {
9697
+ sections.push(h('div', { key: 'milestones' },
9698
+ h('div', { className: 'dsh-powerup-progress-section' }, MODE_LABEL.milestones),
9699
+ h('ul', { className: 'dsh-powerup-progress-items' }, report.milestones.map((m, i) => ProgressItem(
9700
+ m.name, m.status, m.criteria ? `${m.detail ?? ''} · ${m.criteria}`.trim() : m.detail,
9701
+ null, `m-${i}`,
9702
+ ))),
9703
+ ));
9704
+ } else if (mode === 'tree' && report.tree !== null && report.tree !== undefined) {
9705
+ const node = (n, key) => ProgressItem(
9706
+ n.title, n.status, n.detail,
9707
+ Array.isArray(n.children) && n.children.length > 0 ? n.children.map((c, i) => node(c, `${key}-${i}`)) : null,
9708
+ key,
9709
+ );
9710
+ sections.push(h('div', { key: 'tree' },
9711
+ h('div', { className: 'dsh-powerup-progress-section' }, MODE_LABEL.tree),
9712
+ h('ul', { className: 'dsh-powerup-progress-items' }, [node(report.tree, 'root')]),
9713
+ ));
9714
+ } else if (Array.isArray(report.steps) && report.steps.length > 0) {
9715
+ sections.push(h('div', { key: 'steps' },
9716
+ h('div', { className: 'dsh-powerup-progress-section' }, MODE_LABEL.checklist),
9717
+ h('ul', { className: 'dsh-powerup-progress-items' }, report.steps.map((s, i) => ProgressItem(
9718
+ s.title, s.status, s.detail, null, `step-${i}`,
9719
+ ))),
9720
+ ));
9721
+ }
9722
+ if (Array.isArray(report.blockers) && report.blockers.length > 0) {
9723
+ sections.push(h('div', { key: 'blockers', className: 'dsh-powerup-progress-blockers' },
9724
+ h('strong', null, '阻碍'),
9725
+ h('ul', null, report.blockers.map((b, i) => h('li', { key: i }, b))),
9726
+ ));
9727
+ }
9728
+ return sections.length > 0 ? h('div', null, sections) : null;
9729
+ }
9730
+
9731
+ /** Render the model-authored free-form display blocks verbatim. */
9732
+ function ProgressDisplay(report) {
9733
+ const blocks = Array.isArray(report?.display) ? report.display : [];
9734
+ if (blocks.length === 0) return null;
9735
+ const rendered = blocks.map((block, i) => {
9736
+ if (block.kind === 'text') {
9737
+ return h('div', { key: i, className: 'dsh-powerup-progress-display-text' }, block.text);
9738
+ }
9739
+ if (block.kind === 'kv') {
9740
+ return h('dl', { key: i, className: 'dsh-powerup-progress-kv' },
9741
+ block.items.map((item, j) => h('div', { key: j, className: 'dsh-powerup-progress-kv-row' },
9742
+ h('dt', null, item.label),
9743
+ h('dd', null, item.value),
9744
+ )),
9745
+ );
9746
+ }
9747
+ if (block.kind === 'callout') {
9748
+ return h('div', { key: i, className: 'dsh-powerup-progress-callout', 'data-tone': block.tone }, block.text);
9749
+ }
9750
+ if (block.kind === 'bars') {
9751
+ return h('div', { key: i },
9752
+ block.items.map((item, j) => h('div', { key: j, className: 'dsh-powerup-progress-bar' },
9753
+ h('div', { className: 'dsh-powerup-progress-bar-head' },
9754
+ h('span', null, item.label),
9755
+ h('span', null, `${item.value}%`),
9756
+ ),
9757
+ h('div', { className: 'dsh-powerup-progress-track' },
9758
+ h('div', { className: 'dsh-powerup-progress-fill', style: { width: `${item.value}%` } }),
9759
+ ),
9760
+ )),
9761
+ );
9762
+ }
9763
+ if (block.kind === 'code') {
9764
+ return h('pre', { key: i, className: 'dsh-powerup-progress-code' }, block.text);
9765
+ }
9766
+ return null;
9767
+ }).filter(Boolean);
9768
+ if (rendered.length === 0) return null;
9769
+ return h('div', { className: 'dsh-powerup-progress-display' },
9770
+ h('div', { className: 'dsh-powerup-progress-display-head' }, '模型补充'),
9771
+ rendered,
9772
+ );
9773
+ }
9774
+
9775
+ /**
9776
+ * Header utility: a button that opens a body-portal panel. The panel polls
9777
+ * the Host route while a side call runs, and reuses the last report after
9778
+ * it finishes. All work is fire-and-forget on the Host, so the running
9779
+ * task is never blocked or interrupted.
9780
+ */
9781
+ function ProgressControl({ sessionId }) {
9782
+ const settings = useSettings();
9783
+ const [open, setOpen] = useState(false);
9784
+ const [view, setView] = useState(null);
9785
+ const [busy, setBusy] = useState(false);
9786
+ const panelRef = useRef(null);
9787
+ const buttonRef = useRef(null);
9788
+ const sessionRef = useRef(sessionId);
9789
+ sessionRef.current = sessionId;
9790
+ const t = useCallback((key, params) => translateCurrent(key, params), []);
9791
+
9792
+ const refresh = useCallback(async () => {
9793
+ const id = sessionRef.current;
9794
+ if (typeof id !== 'string' || id === '') return null;
9795
+ try {
9796
+ const body = await progressRequest(id, 'poll');
9797
+ setView(body);
9798
+ return body;
9799
+ } catch {
9800
+ return null;
9801
+ }
9802
+ }, []);
9803
+
9804
+ // While the panel is open, keep polling until the side call settles.
9805
+ useEffect(() => {
9806
+ if (!open) return undefined;
9807
+ let disposed = false;
9808
+ const tick = async () => {
9809
+ if (disposed) return;
9810
+ const body = await refresh();
9811
+ if (disposed) return;
9812
+ if (body?.status === 'running') {
9813
+ window.setTimeout(tick, 900);
9814
+ }
9815
+ };
9816
+ void tick();
9817
+ return () => { disposed = true; };
9818
+ }, [open, refresh]);
9819
+
9820
+ const run = useCallback(async () => {
9821
+ const id = sessionRef.current;
9822
+ if (typeof id !== 'string' || id === '') return;
9823
+ setBusy(true);
9824
+ try {
9825
+ const body = await progressRequest(id, 'start');
9826
+ setView(body);
9827
+ } catch (error) {
9828
+ setView({ status: 'error', error: error?.message ?? String(error) });
9829
+ } finally {
9830
+ setBusy(false);
9831
+ // Kick the polling loop even if it was already mounted.
9832
+ if (!open) setOpen(true);
9833
+ }
9834
+ }, [open]);
9835
+
9836
+ const close = useCallback(() => setOpen(false), []);
9837
+
9838
+ // Esc and outside click close the panel.
9839
+ useEffect(() => {
9840
+ if (!open) return undefined;
9841
+ const onKey = (event) => {
9842
+ if (event.key === 'Escape') { event.stopPropagation(); close(); }
9843
+ };
9844
+ const onPointer = (event) => {
9845
+ const panel = panelRef.current;
9846
+ const button = buttonRef.current;
9847
+ if (panel !== null && event.target instanceof Node && panel.contains(event.target)) return;
9848
+ if (button !== null && event.target instanceof Node && button.contains(event.target)) return;
9849
+ close();
9850
+ };
9851
+ document.addEventListener('keydown', onKey, true);
9852
+ document.addEventListener('pointerdown', onPointer, true);
9853
+ return () => {
9854
+ document.removeEventListener('keydown', onKey, true);
9855
+ document.removeEventListener('pointerdown', onPointer, true);
9856
+ };
9857
+ }, [open, close]);
9858
+
9859
+ if (settings.taskProgress === false) return null;
9860
+ const running = view?.status === 'running' || busy;
9861
+ const report = view?.report;
9862
+
9863
+ const button = h('button', {
9864
+ ref: buttonRef,
9865
+ type: 'button',
9866
+ className: 'dsh-powerup-progress-btn' + (running ? ' is-running' : ''),
9867
+ title: t('progress.title'),
9868
+ 'aria-label': t('progress.title'),
9869
+ onClick: () => {
9870
+ if (open) { close(); return; }
9871
+ setOpen(true);
9872
+ void refresh();
9873
+ },
9874
+ },
9875
+ h(ProgressIcon, { size: 15 }),
9876
+ h('span', null, t('progress.label')),
9877
+ running ? h('span', { className: 'dsh-powerup-progress-btn-dot' }) : null,
9878
+ );
9879
+
9880
+ const body = (() => {
9881
+ if (view === null) return h('div', { className: 'dsh-powerup-progress-empty' }, t('progress.hint'));
9882
+ if (view.status === 'error') return h('p', { className: 'dsh-powerup-progress-error' }, view.error ?? t('progress.failed'));
9883
+ if (view.status === 'idle' || view.status === 'expired') {
9884
+ return h('div', null,
9885
+ h('p', { className: 'dsh-powerup-progress-empty' }, t('progress.empty')),
9886
+ h('button', {
9887
+ type: 'button', className: 'dsh-powerup-progress-refresh',
9888
+ disabled: busy, onClick: () => void run(),
9889
+ }, t('progress.generate')),
9890
+ );
9891
+ }
9892
+ if (view.status === 'running') {
9893
+ return h('div', null,
9894
+ h('div', { className: 'dsh-powerup-progress-loading' }, t('progress.loading')),
9895
+ report ? h('div', null,
9896
+ h('p', { className: 'dsh-powerup-progress-summary' }, report.summary),
9897
+ ProgressStructure(report),
9898
+ ) : null,
9899
+ );
9900
+ }
9901
+ if (report === null || report === undefined) {
9902
+ return h('div', null,
9903
+ h('p', { className: 'dsh-powerup-progress-empty' }, t('progress.failed')),
9904
+ h('button', {
9905
+ type: 'button', className: 'dsh-powerup-progress-refresh',
9906
+ disabled: busy, onClick: () => void run(),
9907
+ }, t('progress.retry')),
9908
+ );
9909
+ }
9910
+ return h('div', null,
9911
+ h('p', { className: 'dsh-powerup-progress-summary' }, report.summary),
9912
+ h('div', { className: 'dsh-powerup-progress-meter' },
9913
+ h('div', { className: 'dsh-powerup-progress-meter-head' },
9914
+ h('span', null, MODE_LABEL[report.mode] ?? report.mode),
9915
+ h('strong', null, `${report.percent}%`),
9916
+ ),
9917
+ h('div', { className: 'dsh-powerup-progress-track' },
9918
+ h('div', { className: 'dsh-powerup-progress-fill', style: { width: `${report.percent}%` } }),
9919
+ ),
9920
+ ),
9921
+ ProgressStructure(report),
9922
+ ProgressDisplay(report),
9923
+ );
9924
+ })();
9925
+
9926
+ const panel = !open ? null : h('div', {
9927
+ ref: panelRef,
9928
+ className: 'dsh-powerup-progress-panel',
9929
+ style: {
9930
+ top: (() => {
9931
+ const rect = buttonRef.current?.getBoundingClientRect?.();
9932
+ return `${Math.round((rect?.bottom ?? 44) + 6)}px`;
9933
+ })(),
9934
+ right: (() => {
9935
+ const rect = buttonRef.current?.getBoundingClientRect?.();
9936
+ return `${Math.round(Math.max(12, window.innerWidth - (rect?.right ?? window.innerWidth - 12)))}px`;
9937
+ })(),
9938
+ },
9939
+ },
9940
+ h('div', { className: 'dsh-powerup-progress-head' },
9941
+ h('div', { className: 'dsh-powerup-progress-heading' },
9942
+ h('span', { className: 'dsh-powerup-progress-title' }, report?.title ?? t('progress.title')),
9943
+ h('span', { className: 'dsh-powerup-progress-sub' },
9944
+ view?.stale ? `${t('progress.stale')} · ` : '',
9945
+ t('progress.subtitle'),
9946
+ ),
9947
+ ),
9948
+ h('button', {
9949
+ type: 'button', className: 'dsh-powerup-progress-close',
9950
+ 'aria-label': t('progress.close'), onClick: close,
9951
+ }, '×'),
9952
+ ),
9953
+ h('div', { className: 'dsh-powerup-progress-body' }, body),
9954
+ h('div', { className: 'dsh-powerup-progress-foot' },
9955
+ h('span', { className: 'dsh-powerup-progress-time' },
9956
+ view?.updatedAt ? format(t('progress.updated'), { time: new Date(view.updatedAt).toLocaleTimeString() }) : '',
9957
+ ),
9958
+ h('button', {
9959
+ type: 'button', className: 'dsh-powerup-progress-refresh',
9960
+ disabled: busy || running, onClick: () => void run(),
9961
+ }, t('progress.refresh')),
9962
+ ),
9963
+ );
9964
+
9965
+ return h('span', { style: { display: 'inline-flex', alignItems: 'center' } },
9966
+ button,
9967
+ renderInBody(panel),
9968
+ );
9969
+ }
9970
+
9526
9971
  // ------------------------------------------------------------------
9527
9972
  // Plugin body
9528
9973
  // ------------------------------------------------------------------
@@ -9574,6 +10019,11 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
9574
10019
  order: 50,
9575
10020
  }, PowerUpBridge, 'dsh-powerup: session bridge');
9576
10021
 
10022
+ register('conversation.session.header.utilities', {
10023
+ id: 'powerup-progress',
10024
+ order: 52,
10025
+ }, (props) => h(ProgressControl, { sessionId: props?.sessionId }), 'dsh-powerup: task progress');
10026
+
9577
10027
  register('conversation.hero.options', {
9578
10028
  id: 'powerup-prompts',
9579
10029
  order: 60,
@@ -9671,6 +10121,11 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
9671
10121
  SCROLL_TOP_CSS,
9672
10122
  RENDERING_CSS,
9673
10123
  PROMPTS_CSS,
10124
+ PROGRESS_CSS,
10125
+ ProgressControl,
10126
+ ProgressStructure,
10127
+ ProgressDisplay,
10128
+ progressRequest,
9674
10129
  PROMPTS_LAST_KEY,
9675
10130
  promptCreateDraft,
9676
10131
  readPrompts,
package/index.js CHANGED
@@ -16,6 +16,9 @@
16
16
  * removed
17
17
  * POST /dsh-powerup/api/job-kill → stops one background job with an
18
18
  * optional human reason
19
+ * POST /dsh-powerup/api/progress → starts/polls/cancels a side-model
20
+ * task-progress summary (never writes
21
+ * to the session log or blocks the turn)
19
22
  * tool powerup_step_read → resolves a `dsh-step:` reference
20
23
  * copied from the Trajectory menu into
21
24
  * the raw session events it identifies
@@ -37,6 +40,7 @@ import { homedir } from 'node:os';
37
40
  import { defineTool } from '@deepseek-ai/dsh-tools';
38
41
  import { describeClose, describeRestart, requestRestart, requestShutdown } from './lib/restart.js';
39
42
  import { createStepReadTool } from './lib/step-tool.js';
43
+ import { createProgressManager } from './lib/progress-manager.js';
40
44
 
41
45
  /** Prefix owned by this plugin. */
42
46
  const ROUTE = '/dsh-powerup/api';
@@ -434,11 +438,47 @@ async function handle(req, res, ctx) {
434
438
 
435
439
  const url = new URL(req.url ?? ROUTE, 'http://localhost');
436
440
  const op = url.pathname.slice(ROUTE.length).replace(/^\/+/u, '') || url.searchParams.get('op') || '';
437
- if (op !== '' && op !== 'restart' && op !== 'close' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill' && op !== 'prompts' && op !== 'mask-rules') {
441
+ if (op !== '' && op !== 'restart' && op !== 'close' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill' && op !== 'prompts' && op !== 'mask-rules' && op !== 'progress') {
438
442
  sendJson(res, { ok: false, error: 'not-found' }, 404);
439
443
  return;
440
444
  }
441
445
 
446
+ if (op === 'progress') {
447
+ if (req.method !== 'POST') {
448
+ sendJson(res, { ok: false, error: 'method-not-allowed' }, 405);
449
+ return;
450
+ }
451
+ let body;
452
+ try {
453
+ body = await readJsonBody(req);
454
+ } catch (error) {
455
+ sendJson(res, { ok: false, error: String(error?.message ?? error) }, 400);
456
+ return;
457
+ }
458
+ const sessionId = typeof body?.sessionId === 'string' ? body.sessionId.trim() : '';
459
+ if (sessionId === '') {
460
+ sendJson(res, { ok: false, code: 'invalid-request', error: 'sessionId is required' }, 400);
461
+ return;
462
+ }
463
+ const action = ['start', 'poll', 'cancel'].includes(body?.action) ? body.action : 'poll';
464
+ const manager = ctx?.__powerupProgress;
465
+ if (manager === undefined) {
466
+ sendJson(res, { ok: false, code: 'unavailable', error: 'progress service is not ready' }, 503);
467
+ return;
468
+ }
469
+ try {
470
+ const view = action === 'start'
471
+ ? manager.start(sessionId)
472
+ : action === 'cancel'
473
+ ? manager.cancel(sessionId)
474
+ : manager.poll(sessionId);
475
+ sendJson(res, { ok: true, action, ...view });
476
+ } catch (error) {
477
+ sendJson(res, { ok: false, code: 'progress-failed', error: String(error?.message ?? error) }, 500);
478
+ }
479
+ return;
480
+ }
481
+
442
482
  if (op === 'mask-rules') {
443
483
  const filePath = storePath(MASK_RULES_FILE);
444
484
  if (req.method === 'POST') {
@@ -629,6 +669,26 @@ export function apply(ctx) {
629
669
  'dsh-powerup: step reference reader',
630
670
  );
631
671
  });
672
+ // The progress side call needs both `llm` and `sessionQuery`. Wait for them
673
+ // through inject so a late-provided service still creates the manager.
674
+ ctx.inject(['llm', 'sessionQuery'], (scope) => {
675
+ const manager = createProgressManager({
676
+ getLlm: () => scope.get('llm'),
677
+ getSessionQuery: () => scope.get('sessionQuery'),
678
+ resolveRoute: (sessionId) => {
679
+ // Fall back to the default model when a session has no captured header.
680
+ const defaults = scope.get('agentDefaultModel');
681
+ const selection = typeof defaults?.currentSelection === 'function' ? defaults.currentSelection() : undefined;
682
+ return selection !== undefined && typeof selection.provider === 'string'
683
+ ? selection
684
+ : undefined;
685
+ },
686
+ });
687
+ ctx.__powerupProgress = manager;
688
+ scope.effect(() => () => {
689
+ if (ctx.__powerupProgress === manager) ctx.__powerupProgress = undefined;
690
+ }, 'dsh-powerup: progress manager');
691
+ });
632
692
  }
633
693
 
634
694
  /** Exported for tests only; the Host never reads this. */
@@ -655,4 +715,5 @@ export const __test = {
655
715
  ROUTE,
656
716
  MODULE_ID,
657
717
  STORE_DIR_NAME,
718
+ createProgressManager,
658
719
  };
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Per-session state machine for Power-Up's task-progress side call.
3
+ *
4
+ * The manager is deliberately tiny and dependency-free: the Host injects the
5
+ * `llm`, `sessionQuery` and a route resolver, and the Client drives it through
6
+ * three verbs (start / poll / cancel). Nothing here writes to a session log.
7
+ */
8
+
9
+ import {
10
+ PROGRESS_CACHE_TTL_MS,
11
+ PROGRESS_STALE_MS,
12
+ ProgressError,
13
+ buildProgressContext,
14
+ generateProgress,
15
+ } from './progress-tool.js';
16
+
17
+ /** Cooperative deadline wrapper for one generation. */
18
+ function deadline(signal, ms) {
19
+ const controller = new AbortController();
20
+ const onAbort = () => controller.abort(signal?.reason);
21
+ if (signal?.aborted) controller.abort(signal.reason);
22
+ else signal?.addEventListener?.('abort', onAbort, { once: true });
23
+ const timer = setTimeout(() => controller.abort(new ProgressError('TIMEOUT', 'the progress call timed out')), ms);
24
+ timer.unref?.();
25
+ const dispose = () => {
26
+ clearTimeout(timer);
27
+ signal?.removeEventListener?.('abort', onAbort);
28
+ };
29
+ return { signal: controller.signal, dispose };
30
+ }
31
+
32
+ /**
33
+ * @param {{ getLlm: () => any, getSessionQuery: () => any, resolveRoute: (sessionId: string) => any, timeoutMs?: number }} options
34
+ */
35
+ export function createProgressManager(options) {
36
+ if (options === null || typeof options !== 'object') throw new TypeError('createProgressManager requires options');
37
+ const getLlm = options.getLlm;
38
+ const getSessionQuery = options.getSessionQuery;
39
+ const resolveRoute = options.resolveRoute;
40
+ if (typeof getLlm !== 'function' || typeof getSessionQuery !== 'function' || typeof resolveRoute !== 'function') {
41
+ throw new TypeError('createProgressManager needs getLlm, getSessionQuery and resolveRoute');
42
+ }
43
+ const timeoutMs = Number.isFinite(options.timeoutMs) ? options.timeoutMs : 45_000;
44
+
45
+ /** @type {Map<string, {status:string, startedAt:number, updatedAt:number, report?:object, error?:string, controller?:AbortController}>} */
46
+ const states = new Map();
47
+
48
+ function stateOf(sessionId) {
49
+ return states.get(sessionId) ?? { status: 'idle', startedAt: 0, updatedAt: Date.now() };
50
+ }
51
+
52
+ /** Return a client-safe view of a session's state. */
53
+ function view(sessionId) {
54
+ const state = stateOf(sessionId);
55
+ const result = {
56
+ status: state.status,
57
+ updatedAt: state.updatedAt,
58
+ startedAt: state.startedAt,
59
+ stale: false,
60
+ };
61
+ if (state.report !== undefined) result.report = state.report;
62
+ if (state.error !== undefined) result.error = state.error;
63
+ if (state.status === 'done') result.stale = Date.now() - state.updatedAt > PROGRESS_STALE_MS;
64
+ if (state.status === 'idle' && Date.now() - state.updatedAt > PROGRESS_CACHE_TTL_MS) {
65
+ result.status = 'expired';
66
+ }
67
+ return result;
68
+ }
69
+
70
+ function cancel(sessionId) {
71
+ const state = states.get(sessionId);
72
+ if (state?.controller !== undefined) {
73
+ try { state.controller.abort(new ProgressError('CANCELLED', 'the progress call was cancelled')); } catch { /* ignore */ }
74
+ }
75
+ states.set(sessionId, { ...state, status: 'idle', controller: undefined, updatedAt: Date.now() });
76
+ return view(sessionId);
77
+ }
78
+
79
+ function start(sessionId) {
80
+ // Cancel any previous in-flight call before starting a fresh one.
81
+ const previous = states.get(sessionId);
82
+ if (previous?.controller !== undefined) {
83
+ try { previous.controller.abort(new ProgressError('SUPERSEDED', 'a newer progress call replaced this one')); } catch { /* ignore */ }
84
+ }
85
+ const controller = new AbortController();
86
+ const startedAt = Date.now();
87
+ states.set(sessionId, { status: 'running', startedAt, updatedAt: startedAt, controller });
88
+
89
+ const scope = deadline(controller.signal, timeoutMs);
90
+ (async () => {
91
+ try {
92
+ const llm = getLlm();
93
+ const query = getSessionQuery();
94
+ const route = resolveRoute(sessionId);
95
+ if (query === null || typeof query !== 'object') {
96
+ throw new ProgressError('QUERY_UNAVAILABLE', 'the sessionQuery service is unavailable');
97
+ }
98
+ const [config, surface] = await Promise.all([
99
+ typeof query.inspectSession === 'function'
100
+ ? query.inspectSession(sessionId, (session) => session?.requestHeader?.()?.config ?? undefined, scope.signal)
101
+ : Promise.resolve(undefined),
102
+ typeof query.readSurface === 'function'
103
+ ? query.readSurface(sessionId)
104
+ : Promise.resolve({ events: [] }),
105
+ ]);
106
+ const resolved = (config !== undefined && typeof config?.provider === 'string' && typeof config?.model === 'string')
107
+ ? config
108
+ : (typeof route === 'object' && route !== null ? route : undefined);
109
+ if (resolved === undefined || typeof resolved.provider !== 'string' || typeof resolved.model !== 'string') {
110
+ throw new ProgressError('NO_ROUTE', 'could not resolve a provider/model for this session');
111
+ }
112
+ const context = buildProgressContext(surface, {});
113
+ const report = await generateProgress({ llm, route: resolved, context, signal: scope.signal });
114
+ const current = states.get(sessionId);
115
+ if (current?.controller !== controller) return; // superseded by a newer call
116
+ states.set(sessionId, {
117
+ status: 'done',
118
+ startedAt,
119
+ updatedAt: Date.now(),
120
+ report,
121
+ });
122
+ } catch (error) {
123
+ const current = states.get(sessionId);
124
+ if (current?.controller !== controller) return;
125
+ if (scope.signal.aborted && !(error instanceof ProgressError)) return; // cancelled silently
126
+ states.set(sessionId, {
127
+ status: 'error',
128
+ startedAt,
129
+ updatedAt: Date.now(),
130
+ error: String(error?.message ?? error),
131
+ });
132
+ } finally {
133
+ scope.dispose();
134
+ }
135
+ })().catch(() => { /* never let a side call crash the Host */ });
136
+
137
+ return view(sessionId);
138
+ }
139
+
140
+ return {
141
+ start,
142
+ poll: (sessionId) => view(sessionId),
143
+ cancel,
144
+ /** Exposed for tests only. */
145
+ __test: { states, deadline },
146
+ };
147
+ }
@@ -0,0 +1,308 @@
1
+ /**
2
+ * Power-Up task-progress side call.
3
+ *
4
+ * A session's progress is summarized by a SEPARATE model call that never enters
5
+ * the conversation log and never touches the running agent's turn or abort
6
+ * signal. The Host reads the session's recent surface messages, resolves the
7
+ * same provider/model the session last used, asks the model for a structured
8
+ * JSON progress report, and caches the latest report in memory for the Client
9
+ * panel to poll.
10
+ *
11
+ * Everything in this module is plain JS so it can be exercised by the offline
12
+ * tests without a DSH installation. It never imports `@deepseek-ai/*` at module
13
+ * load; the Host passes the `llm` service in at call time.
14
+ */
15
+
16
+ /** Default cooperative deadline for one side call. */
17
+ export const PROGRESS_TIMEOUT_MS = 45_000;
18
+
19
+ /** Upper bound on characters of session text fed into the side call. */
20
+ export const PROGRESS_CONTEXT_LIMIT = 24_000;
21
+
22
+ /** Max output tokens for the summary. */
23
+ export const PROGRESS_MAX_TOKENS = 900;
24
+
25
+ /** Number of recent surface messages considered. */
26
+ export const PROGRESS_MESSAGE_LIMIT = 60;
27
+
28
+ /** Cache TTL for a finished report, in milliseconds. */
29
+ export const PROGRESS_CACHE_TTL_MS = 5 * 60_000;
30
+
31
+ /** Report is considered stale for the overlay after this long. */
32
+ export const PROGRESS_STALE_MS = 60_000;
33
+
34
+ /** The JSON schema modes the model may choose from. */
35
+ export const PROGRESS_MODES = ['checklist', 'phases', 'milestones', 'tree'];
36
+
37
+ /**
38
+ * The single instruction sent to the side model. It deliberately lets the
39
+ * model choose a structure that fits the task instead of forcing one shape.
40
+ */
41
+ export const PROGRESS_SYSTEM_PROMPT = [
42
+ 'You are a task-progress reporter embedded in DeepSeek Harness.',
43
+ 'You will be given a compact transcript of a work session that is still in progress.',
44
+ 'Produce ONE JSON object and nothing else — no prose, no markdown fences.',
45
+ 'Pick the structure that best fits the task and set "mode" accordingly:',
46
+ ' - "checklist": a to-do list with discrete steps. Use "steps": [{"title","status","detail"}], status one of pending|in-progress|done|blocked.',
47
+ ' - "phases": ordered work phases. Use "phases": [{"name","status","detail","steps"?:[{"title","status"}]}].',
48
+ ' - "milestones": goal-oriented milestones. Use "milestones": [{"name","status","detail","criteria"?}].',
49
+ ' - "tree": hierarchical subtasks (e.g. subagents or nested work). Use "root": {"title","status","children"?:[...]}.',
50
+ 'Every mode also requires: "title" (short), "summary" (1-2 sentences), "percent" (integer 0-100), "blockers" (string array).',
51
+ 'You MAY add a "display" field to show extra information the user will see directly in the panel.',
52
+ '"display" is an array of blocks. Each block is either',
53
+ ' {"kind":"text","text":"..."} (plain text, line breaks preserved), or',
54
+ ' {"kind":"kv","items":[{"label":"...","value":"..."}]}, or',
55
+ ' {"kind":"callout","tone":"info"|"warn"|"success","text":"..."}, or',
56
+ ' {"kind":"bars","items":[{"label":"...","value":0-100}]}, or',
57
+ ' {"kind":"code","language":"...","text":"..."}.',
58
+ 'Keep "display" concise and genuinely useful; omit it when the structured fields already say everything.',
59
+ 'Be honest: if work has not started, say so; never invent progress. Base the report only on the transcript.',
60
+ ].join('\n');
61
+
62
+ /** Error with a stable machine code. */
63
+ export class ProgressError extends Error {
64
+ constructor(code, message, options = {}) {
65
+ super(`${code}: ${message}`);
66
+ this.name = 'ProgressError';
67
+ this.code = code;
68
+ if (options.cause !== undefined) this.cause = options.cause;
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Accept either a live Session or a SessionSurfaceSnapshot and return a compact
74
+ * transcript of recent user/assistant text (tool names noted, arguments dropped).
75
+ * @param {object} session
76
+ * @param {{provider: string, model: string, maxTokens?: number}} route
77
+ * @returns {string}
78
+ */
79
+ export function buildProgressContext(session, options = {}) {
80
+ const limit = Number.isFinite(options.limit) ? options.limit : PROGRESS_CONTEXT_LIMIT;
81
+ const messageLimit = Number.isFinite(options.messageLimit) ? options.messageLimit : PROGRESS_MESSAGE_LIMIT;
82
+ const events = Array.isArray(session?.events) ? session.events : [];
83
+ const chunks = [];
84
+ let used = 0;
85
+ const selected = events.length > messageLimit ? events.slice(-messageLimit) : events;
86
+ for (const event of selected) {
87
+ if (event === null || typeof event !== 'object') continue;
88
+ let role = '';
89
+ let message = null;
90
+ if (event.type === 'user/message') {
91
+ role = 'User';
92
+ message = event.data;
93
+ } else if (event.type === 'assistant/message') {
94
+ role = 'Assistant';
95
+ message = event.data?.message;
96
+ } else if (event.role === 'user' || event.role === 'assistant') {
97
+ role = event.role === 'user' ? 'User' : 'Assistant';
98
+ message = event;
99
+ }
100
+ if (message === null || typeof message !== 'object') continue;
101
+ const parts = [];
102
+ for (const block of Array.isArray(message.content) ? message.content : []) {
103
+ if (block === null || typeof block !== 'object') continue;
104
+ if (block.type === 'text' && typeof block.text === 'string') {
105
+ parts.push(block.text.trim());
106
+ } else if (block.type === 'tool-call') {
107
+ const name = typeof block.name === 'string' ? block.name : 'tool';
108
+ parts.push(`[called ${name}]`);
109
+ } else if (block.type === 'tool-result') {
110
+ parts.push('[tool result]');
111
+ }
112
+ }
113
+ const text = parts.filter(Boolean).join('\n').trim();
114
+ if (text === '') continue;
115
+ const line = `${role}: ${text}`;
116
+ if (used + line.length > limit) break;
117
+ chunks.push(line);
118
+ used += line.length;
119
+ }
120
+ return chunks.join('\n\n').slice(0, limit);
121
+ }
122
+
123
+ /**
124
+ * Strip accidental markdown fences and parse the model text as one JSON object.
125
+ * @param {string} text
126
+ * @returns {object}
127
+ */
128
+ export function parseProgressReport(text) {
129
+ if (typeof text !== 'string' || text.trim() === '') {
130
+ throw new ProgressError('EMPTY', 'the model returned an empty progress report');
131
+ }
132
+ let cleaned = text.trim();
133
+ const fence = cleaned.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/iu);
134
+ if (fence !== null) cleaned = fence[1].trim();
135
+ let value;
136
+ try {
137
+ value = JSON.parse(cleaned);
138
+ } catch (error) {
139
+ throw new ProgressError('INVALID_JSON', 'the model did not return valid JSON', { cause: error });
140
+ }
141
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
142
+ throw new ProgressError('INVALID_SHAPE', 'the progress report must be a JSON object');
143
+ }
144
+ return normalizeProgressReport(value);
145
+ }
146
+
147
+ /**
148
+ * Normalize/validate a parsed report into a stable shape for the UI. Unknown
149
+ * fields are dropped, missing fields get safe defaults, and the mode is checked
150
+ * against the declared set.
151
+ * @param {object} value
152
+ * @returns {object}
153
+ */
154
+ export function normalizeProgressReport(value) {
155
+ const mode = PROGRESS_MODES.includes(value?.mode) ? value.mode : 'checklist';
156
+ const statusOf = (x) => ['pending', 'in-progress', 'done', 'blocked'].includes(x) ? x : 'pending';
157
+ const text = (x, max = 4000) => typeof x === 'string' ? x.trim().slice(0, max) : '';
158
+ const list = (x) => Array.isArray(x) ? x.filter((v) => v !== null && typeof v === 'object') : [];
159
+ const listStrings = (x) => Array.isArray(x) ? x : [];
160
+
161
+ const steps = list(value.steps).map((s) => ({
162
+ title: text(s.title, 240),
163
+ status: statusOf(s.status),
164
+ detail: text(s.detail, 1200),
165
+ })).filter((s) => s.title !== '');
166
+ const phases = list(value.phases).map((p) => ({
167
+ name: text(p.name, 240),
168
+ status: statusOf(p.status),
169
+ detail: text(p.detail, 1200),
170
+ steps: list(p.steps).map((s) => ({
171
+ title: text(s.title, 240),
172
+ status: statusOf(s.status),
173
+ })).filter((s) => s.title !== ''),
174
+ })).filter((p) => p.name !== '');
175
+ const milestones = list(value.milestones).map((m) => ({
176
+ name: text(m.name, 240),
177
+ status: statusOf(m.status),
178
+ detail: text(m.detail, 1200),
179
+ criteria: text(m.criteria, 600),
180
+ })).filter((m) => m.name !== '');
181
+ const normalizeNode = (node, depth = 0) => {
182
+ if (depth > 6 || node === null || typeof node !== 'object') return null;
183
+ return {
184
+ title: text(node.title ?? node.name, 240),
185
+ status: statusOf(node.status),
186
+ detail: text(node.detail, 800),
187
+ children: list(node.children).map((c) => normalizeNode(c, depth + 1)).filter(Boolean),
188
+ };
189
+ };
190
+ const tree = normalizeNode(value.root) ?? normalizeNode(value.tree) ?? null;
191
+
192
+ const display = list(value.display).map((block) => {
193
+ if (block.kind === 'text') return { kind: 'text', text: text(block.text, 8000) };
194
+ if (block.kind === 'kv') {
195
+ return {
196
+ kind: 'kv',
197
+ items: list(block.items).map((item) => ({
198
+ label: text(item.label, 160),
199
+ value: text(item.value, 1200),
200
+ })).filter((item) => item.label !== ''),
201
+ };
202
+ }
203
+ if (block.kind === 'callout') {
204
+ return {
205
+ kind: 'callout',
206
+ tone: ['info', 'warn', 'success'].includes(block.tone) ? block.tone : 'info',
207
+ text: text(block.text, 2000),
208
+ };
209
+ }
210
+ if (block.kind === 'bars') {
211
+ return {
212
+ kind: 'bars',
213
+ items: list(block.items).map((item) => ({
214
+ label: text(item.label, 160),
215
+ value: Math.max(0, Math.min(100, Math.round(Number(item.value) || 0))),
216
+ })).filter((item) => item.label !== ''),
217
+ };
218
+ }
219
+ if (block.kind === 'code') {
220
+ return { kind: 'code', language: text(block.language, 40), text: text(block.text, 8000) };
221
+ }
222
+ return null;
223
+ }).filter(Boolean);
224
+
225
+ const percentRaw = Number(value.percent);
226
+ return {
227
+ mode,
228
+ title: text(value.title, 240) || 'Task progress',
229
+ summary: text(value.summary, 2400),
230
+ percent: Number.isFinite(percentRaw) ? Math.max(0, Math.min(100, Math.round(percentRaw))) : 0,
231
+ blockers: listStrings(value.blockers).map((b) => text(b, 600)).filter(Boolean),
232
+ steps,
233
+ phases,
234
+ milestones,
235
+ tree,
236
+ display,
237
+ updatedAt: Date.now(),
238
+ };
239
+ }
240
+
241
+ /**
242
+ * Assemble accumulated text chunks and check the terminal finish reason.
243
+ * @param {string} text
244
+ * @param {{kind: string} | undefined} finish
245
+ * @returns {string}
246
+ */
247
+ export function finishReport(text, finish) {
248
+ if (finish?.kind === 'error' || finish?.kind === 'aborted') {
249
+ throw new ProgressError('LLM_FAILED', `the side model call ${finish.kind ?? 'failed'}`);
250
+ }
251
+ if (finish?.kind === 'max-tokens') {
252
+ throw new ProgressError('TRUNCATED', 'the side model hit its token limit before finishing');
253
+ }
254
+ return text;
255
+ }
256
+
257
+ /**
258
+ * Perform the side call. The caller supplies the `llm` service, the route, the
259
+ * transcript and its own AbortSignal; this function writes nothing durable.
260
+ *
261
+ * @param {object} options
262
+ * @param {object} options.llm the Host `ctx.llm` service
263
+ * @param {{provider: string, model: string, reasoningEffort?: string, maxTokens?: number}} options.route
264
+ * @param {string} options.context compact transcript
265
+ * @param {AbortSignal} [options.signal]
266
+ * @returns {Promise<object>} a normalized progress report
267
+ */
268
+ export async function generateProgress({ llm, route, context, signal }) {
269
+ if (llm === null || typeof llm !== 'object' || typeof llm.prepareCall !== 'function') {
270
+ throw new ProgressError('LLM_UNAVAILABLE', 'the llm service is unavailable');
271
+ }
272
+ if (route === null || typeof route !== 'object' || typeof route.provider !== 'string' || typeof route.model !== 'string') {
273
+ throw new ProgressError('NO_ROUTE', 'no provider/model route is available for this session');
274
+ }
275
+ const config = {
276
+ provider: route.provider,
277
+ model: route.model,
278
+ ...(typeof route.reasoningEffort === 'string' ? { reasoningEffort: route.reasoningEffort } : {}),
279
+ maxTokens: Number.isFinite(route.maxTokens) ? route.maxTokens : PROGRESS_MAX_TOKENS,
280
+ };
281
+ const call = await llm.prepareCall(config, signal);
282
+ const prompt = [
283
+ 'Session transcript (may be truncated):',
284
+ '---',
285
+ context || '(no recent user or assistant text)',
286
+ '---',
287
+ 'Return only the JSON progress object described in your instructions.',
288
+ ].join('\n');
289
+ const options = {
290
+ ...call.config,
291
+ messages: [{ role: 'user', content: [{ type: 'text', text: prompt }] }],
292
+ system: PROGRESS_SYSTEM_PROMPT,
293
+ purpose: 'task-progress',
294
+ ...(signal === undefined ? {} : { signal }),
295
+ };
296
+ let text = '';
297
+ let finish;
298
+ for await (const chunk of call.stream(options)) {
299
+ if (signal?.aborted) throw new ProgressError('ABORTED', 'the progress call was cancelled');
300
+ if (chunk === null || typeof chunk !== 'object') continue;
301
+ if (chunk.type === 'text-delta' && typeof chunk.text === 'string') {
302
+ text += chunk.text;
303
+ } else if (chunk.type === 'finish') {
304
+ finish = chunk.reason;
305
+ }
306
+ }
307
+ return parseProgressReport(finishReport(text, finish));
308
+ }
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Power-Up",
4
- "description": "Independently toggleable upgrades for DeepSeek Harness on the Power-Up page: trajectory context menu and step references, job stop reasons, one-click plugin install, sidebar icon grid and back-to-top, session switching and locating, workspace prompts, plus conversation rendering enhancements (regex reply masking) and dual send buttons (queued/interrupt)."
4
+ "description": "Independently toggleable upgrades for DeepSeek Harness on the Power-Up page: trajectory context menu and step references, job stop reasons, one-click plugin install, sidebar icon grid and back-to-top, session switching and locating, workspace prompts, non-blocking model-generated structured task progress, plus conversation rendering enhancements (regex reply masking) and dual send buttons (queued/interrupt)."
5
5
  }
6
6
  }
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Power-Up",
4
- "description": "为 DeepSeek Harness 提供一组可在 Power-Up 页面独立开关的增强:轨迹右键菜单与步骤引用、后台任务停止原因、插件一键安装、侧边栏图标网格与回到顶部、会话切换与定位、工作区提示词,以及会话内容渲染增强(回复内容正则屏蔽)和双发送按钮(等待/插话)。"
4
+ "description": "为 DeepSeek Harness 提供一组可在 Power-Up 页面独立开关的增强:轨迹右键菜单与步骤引用、后台任务停止原因、插件一键安装、侧边栏图标网格与回到顶部、会话切换与定位、工作区提示词、旁路模型生成的结构化任务进度,以及会话内容渲染增强(回复内容正则屏蔽)和双发送按钮(等待/插话)。"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@restregular/dsh-powerup",
3
- "version": "0.10.7",
4
- "description": "为 DeepSeek Harness 提供一组可选的小型增强:轨迹右键菜单与步骤引用、后台任务停止原因、插件一键安装、侧边栏图标网格、会话切换、定位当前会话、工作区提示词;所有功能均可在 Power-Up 页面独立开关。 · Opt-in upgrades for DeepSeek Harness: Trajectory context menu and step references, job stop reasons, one-click plugin install, an adaptive sidebar launcher, session switching, locating the current session, and workspace prompts — each toggled independently on the Power-Up page.",
3
+ "version": "0.11.0",
4
+ "description": "为 DeepSeek Harness 提供一组可选的小型增强:轨迹右键菜单与步骤引用、后台任务停止原因、插件一键安装、侧边栏图标网格、会话切换、定位当前会话、工作区提示词、旁路模型生成的结构化任务进度;所有功能均可在 Power-Up 页面独立开关。 · Opt-in upgrades for DeepSeek Harness: Trajectory context menu and step references, job stop reasons, one-click plugin install, an adaptive sidebar launcher, session switching, locating the current session, workspace prompts, and non-blocking model-generated structured task progress — each toggled independently on the Power-Up page.",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",
7
7
  "main": "index.js",
@@ -21,6 +21,8 @@
21
21
  "lib/restart-helper.cjs",
22
22
  "lib/step-reference.js",
23
23
  "lib/step-tool.js",
24
+ "lib/progress-tool.js",
25
+ "lib/progress-manager.js",
24
26
  "locale/*.json",
25
27
  "icon.svg",
26
28
  "README.md",
@@ -81,7 +83,10 @@
81
83
  "close",
82
84
  "session-switch",
83
85
  "workspace",
84
- "locate"
86
+ "locate",
87
+ "task-progress",
88
+ "side-llm",
89
+ "visualization"
85
90
  ],
86
91
  "publishConfig": {
87
92
  "access": "public",
@@ -91,7 +96,7 @@
91
96
  "node": ">=22.13.0"
92
97
  },
93
98
  "scripts": {
94
- "test": "node test/smoke.mjs && node test/host.mjs"
99
+ "test": "node test/smoke.mjs && node test/host.mjs && node test/progress.mjs"
95
100
  },
96
101
  "license": "MIT",
97
102
  "author": "RestRegular"