@restregular/dsh-powerup 0.3.1 → 0.4.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
@@ -1,7 +1,8 @@
1
1
  # Power-Up
2
2
 
3
3
  Small, opt-in upgrades for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness).
4
- The first upgrade is a **right-click action menu in the Trajectory view**.
4
+ The upgrades include a **right-click action menu in the Trajectory view**, an
5
+ optional **stop reason for background jobs**, and an in-place **plugin updater**.
5
6
 
6
7
  ## Install
7
8
 
@@ -31,6 +32,20 @@ Right-click empty space in the ledger:
31
32
  The sidebar **Power-Up** page turns the menu on or off and lists the available
32
33
  actions. The setting is stored in the browser.
33
34
 
35
+ ### Stop a background job with a reason
36
+
37
+ The session header's background jobs panel keeps the host's list, live output,
38
+ and stop button. Clicking a running job's stop button opens a small Power-Up
39
+ dialog instead of the host's two-press stop:
40
+
41
+ - The reason field is optional; an empty field keeps the host's default
42
+ `cancelled by the user` reason.
43
+ - Confirming stops the job through the Host route, which records
44
+ `cancelled by the user: <reason>`. The completion notice injected into the
45
+ session and the shell tool's result therefore carry the reason.
46
+ - If the button cannot be resolved to a live job, the click is left alone and
47
+ the host's original stop flow runs unchanged.
48
+
34
49
  ### Menu keys
35
50
 
36
51
  `↑` / `↓` move, `Home` / `End` jump, `Enter` runs, `Esc` closes.
@@ -89,6 +104,13 @@ refresh the page when the install finishes.
89
104
  observes the trajectory package's own `data-*` contracts. If those attributes
90
105
  change, row-specific actions degrade gracefully; session-level actions in the
91
106
  empty ledger area keep working.
107
+ - **The stop reason rides the host's own job registry.** The panel belongs to
108
+ `@deepseek-ai/dsh-client-ui-jobs`, so Power-Up does not replace it: a capture
109
+ listener recognizes its `button[data-kill-state]`, maps the button to the live
110
+ row (DOM order plus the row's `title` label), and opens the reason dialog.
111
+ The typed reason goes to `POST /dsh-powerup/api/job-kill`, which calls the
112
+ registry's `kill(id, session, reason)` — the same admission the built-in
113
+ Remote uses, with the reason settlement merges into the job's `detail` line.
92
114
  - **The update entry uses the built-in page's contracts.** The Plugins page has
93
115
  no per-card slot, so the overlay injects one button into every
94
116
  `[data-plugin-group="bundles"] [data-plugin-package]` card and re-asserts it
@@ -129,7 +151,7 @@ node test/smoke.mjs
129
151
 
130
152
  The smoke test loads the real Client module with React/browser doubles, applies
131
153
  it to a fake slot context, and checks registrations, icons, helpers, theme
132
- tokens, and the manifest.
154
+ tokens, the stop-reason mapping and Host route, and the manifest.
133
155
 
134
156
  ## License
135
157
 
package/client.js CHANGED
@@ -44,7 +44,7 @@
44
44
 
45
45
  const NS = 'dsh-powerup';
46
46
  const SETTINGS_KEY = 'dsh-powerup:settings:v1';
47
- const VERSION = '0.3.1';
47
+ const VERSION = '0.4.0';
48
48
  const MENU_GAP = 8;
49
49
  const MENU_WIDTH = 248;
50
50
 
@@ -68,6 +68,9 @@
68
68
  'page.updateTitle': '插件自更新',
69
69
  'page.updateDesc': '在插件页为每个第三方已安装插件提供更新入口:从安装源选版本、卸载旧版、按「添加插件」流程重装,并可立即启用与重启 DSH。',
70
70
  'page.updateHow': '打开侧边栏的「插件」页,在「已安装插件」分组中点击卡片右侧的更新图标。',
71
+ 'page.jobStopTitle': '后台任务停止原因',
72
+ 'page.jobStopDesc': '在会话顶部的后台任务面板里点停止按钮时,可以顺手填写停止原因;原因会附加在任务结束后注入会话的提示里。',
73
+ 'page.jobStopHow': '打开任意会话,点顶部的「后台任务」面板,在运行中的任务右侧点停止,填写原因(可留空)后确认。',
71
74
  'page.footer': 'Power-Up {version} · 设置在浏览器本地保存',
72
75
  'page.localOnly': '仅影响当前浏览器',
73
76
  'action.copy': '复制内容',
@@ -112,6 +115,14 @@
112
115
  'toast.sessionCopied': '会话 ID 已复制',
113
116
  'toast.forkUnavailable': '当前宿主没有提供 Fork 接口',
114
117
  'toast.noSession': '还没有打开会话',
118
+ 'jobStop.title': '停止后台任务',
119
+ 'jobStop.reasonLabel': '停止原因(可选)',
120
+ 'jobStop.reasonPlaceholder': '例如:已经不需要这个结果了',
121
+ 'jobStop.reasonNote': '原因会附加在任务结束后注入会话的提示里。',
122
+ 'jobStop.cancel': '取消',
123
+ 'jobStop.confirm': '停止任务',
124
+ 'jobStop.stopping': '正在停止…',
125
+ 'jobStop.failed': '停止失败:{message}',
115
126
  'update.button': '更新版本',
116
127
  'update.title': '更新插件',
117
128
  'update.subtitle': '选择版本后自动卸载旧版并安装新版本。',
@@ -205,6 +216,9 @@
205
216
  'page.updateTitle': 'Update plugins',
206
217
  'page.updateDesc': 'Every third-party plugin on the Plugins page gains an update entry: pick a version from a registry, remove the old copy, reinstall through the Add plugin path, then enable and restart DSH.',
207
218
  'page.updateHow': 'Open Plugins in the sidebar and click the update icon at the right of a card under Installed plugins.',
219
+ 'page.jobStopTitle': 'Background job stop reason',
220
+ 'page.jobStopDesc': 'When you stop a running job from the background jobs panel in the session header, you can leave a reason; the reason is appended to the notice injected into the session when the job settles.',
221
+ 'page.jobStopHow': 'Open a session, expand the background jobs panel, press stop on a running job, type a reason (optional), then confirm.',
208
222
  'page.footer': 'Power-Up {version} · Settings are stored in this browser',
209
223
  'page.localOnly': 'This browser only',
210
224
  'action.copy': 'Copy content',
@@ -249,6 +263,14 @@
249
263
  'toast.sessionCopied': 'Session ID copied',
250
264
  'toast.forkUnavailable': 'This host does not expose the fork API',
251
265
  'toast.noSession': 'No session is open',
266
+ 'jobStop.title': 'Stop background job',
267
+ 'jobStop.reasonLabel': 'Stop reason (optional)',
268
+ 'jobStop.reasonPlaceholder': 'e.g. the result is no longer needed',
269
+ 'jobStop.reasonNote': 'The reason is appended to the notice injected into the session when the job settles.',
270
+ 'jobStop.cancel': 'Cancel',
271
+ 'jobStop.confirm': 'Stop job',
272
+ 'jobStop.stopping': 'Stopping…',
273
+ 'jobStop.failed': 'Could not stop the job: {message}',
252
274
  'update.button': 'Update version',
253
275
  'update.title': 'Update plugin',
254
276
  'update.subtitle': 'Choose a version; the old one is removed and the new one installed.',
@@ -607,6 +629,15 @@
607
629
  );
608
630
  }
609
631
 
632
+ function StopIcon({ size = 16 }) {
633
+ return h(Icon, { size },
634
+ h('rect', {
635
+ x: '3.2', y: '3.2', width: '9.6', height: '9.6', rx: '1.7',
636
+ fill: 'none', stroke: 'currentColor', strokeWidth: '1.3',
637
+ }),
638
+ );
639
+ }
640
+
610
641
  function CheckIcon({ size = 16 }) {
611
642
  return h(Icon, { size },
612
643
  h('path', {
@@ -704,6 +735,27 @@
704
735
  .dsh-powerup-menu-foot-id{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:var(--dsw-font-family-code,ui-monospace,SFMono-Regular,Consolas,monospace)}
705
736
  .dsh-powerup-toast{position:fixed;left:50%;bottom:30px;transform:translateX(-50%);z-index:1001;max-width:min(440px,calc(100vw - 32px));padding:7px 12px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-overlay,var(--dsw-alias-bg-layer-1));color:var(--dsw-alias-label-primary);box-shadow:var(--dsw-elevation-lv2,0 8px 24px rgba(15,23,42,.18));font-size:12px;line-height:1.45;pointer-events:none;animation:dsh-powerup-toast-in .14s ease-out}
706
737
  @keyframes dsh-powerup-toast-in{from{opacity:0;transform:translate(-50%,5px)}to{opacity:1;transform:translate(-50%,0)}}
738
+ .dsh-powerup-jobstop{position:fixed;z-index:1002;box-sizing:border-box;display:flex;flex-direction:column;gap:10px;padding:12px;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-overlay,var(--dsw-alias-bg-layer-1));box-shadow:var(--dsw-elevation-prominent,0 16px 40px rgba(15,23,42,.24),0 2px 8px rgba(15,23,42,.1));color:var(--dsw-alias-label-primary);font-size:12.5px;line-height:1.45;pointer-events:auto;animation:dsh-powerup-jobstop-in .14s ease-out}
739
+ @keyframes dsh-powerup-jobstop-in{from{opacity:0;transform:translateY(3px)}to{opacity:1;transform:none}}
740
+ .dsh-powerup-jobstop-head{display:flex;align-items:center;gap:6px;color:var(--dsw-alias-label-tertiary);font-size:10.5px;font-weight:600;letter-spacing:.03em}
741
+ .dsh-powerup-jobstop-head svg{flex:none;color:var(--dsw-alias-state-error-primary)}
742
+ .dsh-powerup-jobstop-label{display:flex;align-items:center;gap:6px;min-width:0;color:var(--dsw-alias-label-secondary);font-family:var(--dsw-font-family-code,ui-monospace,SFMono-Regular,Consolas,monospace);font-size:11.5px}
743
+ .dsh-powerup-jobstop-label span{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
744
+ .dsh-powerup-jobstop-field{display:flex;flex-direction:column;gap:4px;min-width:0}
745
+ .dsh-powerup-jobstop-field-label{color:var(--dsw-alias-label-secondary);font-size:11.5px;line-height:17px}
746
+ .dsh-powerup-jobstop-input{box-sizing:border-box;width:100%;height:32px;padding:0 9px;border:.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);font:inherit;font-size:12.5px;line-height:18px;outline:none;transition:border-color .14s ease,box-shadow .14s ease}
747
+ .dsh-powerup-jobstop-input::placeholder{color:var(--dsw-alias-label-caption)}
748
+ .dsh-powerup-jobstop-input:focus{border-color:var(--dsw-alias-state-business-primary);box-shadow:inset 0 0 0 .5px var(--dsw-alias-state-business-primary)}
749
+ .dsh-powerup-jobstop-note{margin:0;color:var(--dsw-alias-label-tertiary);font-size:10.5px;line-height:15px}
750
+ .dsh-powerup-jobstop-error{margin:0;color:var(--dsw-alias-state-error-primary);font-size:11.5px;line-height:16px;overflow-wrap:anywhere}
751
+ .dsh-powerup-jobstop-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px}
752
+ .dsh-powerup-jobstop-cancel{height:28px;padding:0 10px;border:0;border-radius:var(--dsw-radius-sm,6px);background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;line-height:18px;cursor:pointer}
753
+ .dsh-powerup-jobstop-cancel:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2));color:var(--dsw-alias-label-primary)}
754
+ .dsh-powerup-jobstop-confirm{height:28px;padding:0 11px;border:0;border-radius:var(--dsw-radius-sm,6px);background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 12%,transparent);color:var(--dsw-alias-state-error-primary);font:inherit;font-size:12px;line-height:18px;cursor:pointer;transition:background .14s ease}
755
+ .dsh-powerup-jobstop-confirm:hover:not(:disabled){background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 20%,transparent)}
756
+ .dsh-powerup-jobstop-confirm:disabled,.dsh-powerup-jobstop-cancel:disabled{opacity:.55;cursor:default}
757
+ .dsh-powerup-jobstop-cancel:focus-visible,.dsh-powerup-jobstop-confirm:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}
758
+ @media (prefers-reduced-motion:reduce){.dsh-powerup-jobstop{animation:none}}
707
759
  .dsh-powerup-update-button{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;padding:0;border:0;border-radius:var(--dsw-radius-sm,6px);background:transparent;color:var(--dsw-alias-label-caption);cursor:pointer}
708
760
  .dsh-powerup-update-button:hover{background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2));color:var(--dsw-alias-label-secondary)}
709
761
  .dsh-powerup-restart-tag{flex:none;display:inline-flex;align-items:center;height:18px;padding:0 6px;border:.5px solid color-mix(in srgb,var(--dsw-alias-state-warn-primary) 32%,transparent);border-radius:999px;background:var(--dsw-alias-state-warn-tertiary);color:var(--dsw-alias-state-warn-label);font-size:10px;line-height:16px;white-space:nowrap}
@@ -748,12 +800,12 @@
748
800
  .dsh-powerup-update-toggle[aria-expanded=true]{border-color:var(--dsw-alias-state-business-primary);background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary)}
749
801
  .dsh-powerup-update-toggle .chevron{display:inline-flex;color:var(--dsw-alias-label-tertiary);transition:transform .16s ease}
750
802
  .dsh-powerup-update-toggle[aria-expanded=true] .chevron{transform:rotate(180deg);color:var(--dsw-alias-label-secondary)}
751
- .dsh-powerup-update-list{display:flex;flex-direction:column;max-height:240px;overflow-y:auto;border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg,10px);background:var(--dsw-alias-bg-layer-1);--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2)}
752
- .dsh-powerup-update-popover{position:fixed;z-index:1300;box-sizing:border-box;overflow-y:auto;pointer-events:auto;border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg,10px);background:var(--dsw-alias-bg-layer-2);box-shadow:var(--dsw-elevation-prominent);--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2)}
803
+ .dsh-powerup-update-list{box-sizing:border-box;display:flex;flex-direction:column;max-height:240px;overflow-x:hidden;overflow-y:auto;border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg,10px);background:var(--dsw-alias-bg-layer-1);--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2)}
804
+ .dsh-powerup-update-popover{position:fixed;z-index:1300;box-sizing:border-box;overflow-x:hidden;overflow-y:auto;pointer-events:auto;border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg,10px);background:var(--dsw-alias-bg-layer-2);box-shadow:var(--dsw-elevation-prominent);--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2)}
753
805
  .dsh-powerup-update-popover.dsh-powerup-update-list{border-radius:var(--dsw-radius-lg,10px)}
754
806
  .dsh-powerup-update-popover.dsh-powerup-update-select-menu{display:flex;flex-direction:column;padding:4px}
755
- .dsh-powerup-update-list-head{position:sticky;top:0;z-index:1;display:flex;align-items:center;justify-content:space-between;gap:8px;padding:7px 12px;border-bottom:.5px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px}
756
- .dsh-powerup-update-version{display:flex;align-items:center;gap:8px;width:100%;min-height:34px;padding:0 12px;border:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:12.5px;line-height:18px;text-align:left;cursor:pointer;font-variant-numeric:tabular-nums}
807
+ .dsh-powerup-update-list-head{box-sizing:border-box;position:sticky;top:0;z-index:1;display:flex;align-items:center;justify-content:space-between;gap:8px;padding:7px 12px;border-bottom:.5px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px}
808
+ .dsh-powerup-update-version{box-sizing:border-box;display:flex;align-items:center;gap:8px;width:100%;min-height:34px;padding:0 12px;border:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:12.5px;line-height:18px;text-align:left;cursor:pointer;font-variant-numeric:tabular-nums}
757
809
  .dsh-powerup-update-version>span:first-child{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
758
810
  .dsh-powerup-update-version:hover{background:var(--dsw-alias-interactive-bg-hover)}
759
811
  .dsh-powerup-update-version[aria-selected=true]{background:var(--dsw-alias-interactive-bg-active)}
@@ -780,15 +832,15 @@
780
832
  .dsh-powerup-update-notice.success svg{color:var(--dsw-alias-state-success-primary)}
781
833
  .dsh-powerup-update-registry{display:flex;flex-direction:column;gap:8px}
782
834
  .dsh-powerup-update-select{position:relative}
783
- .dsh-powerup-update-select-trigger{display:flex;align-items:center;gap:10px;width:100%;height:38px;padding:0 12px;border:.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:20px;text-align:left;cursor:pointer;transition:border-color .14s ease,box-shadow .14s ease}
835
+ .dsh-powerup-update-select-trigger{box-sizing:border-box;display:flex;align-items:center;gap:10px;width:100%;height:38px;padding:0 12px;border:.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:20px;text-align:left;cursor:pointer;transition:border-color .14s ease,box-shadow .14s ease}
784
836
  .dsh-powerup-update-select-trigger:hover{background:var(--dsw-alias-bg-layer-2)}
785
837
  .dsh-powerup-update-select-trigger[aria-expanded=true]{border-color:var(--dsw-alias-state-business-primary);box-shadow:inset 0 0 0 .5px var(--dsw-alias-state-business-primary)}
786
838
  .dsh-powerup-update-select-value{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
787
839
  .dsh-powerup-update-select-host{flex:none;color:var(--dsw-alias-label-tertiary);font-size:11.5px}
788
840
  .dsh-powerup-update-select-trigger .chevron{flex:none;display:inline-flex;color:var(--dsw-alias-label-tertiary);transition:transform .16s ease}
789
841
  .dsh-powerup-update-select-trigger[aria-expanded=true] .chevron{transform:rotate(180deg)}
790
- .dsh-powerup-update-select-menu{display:flex;flex-direction:column;padding:4px;border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg,10px);background:var(--dsw-alias-bg-layer-2);box-shadow:var(--dsw-elevation-prominent)}
791
- .dsh-powerup-update-option{display:flex;align-items:flex-start;gap:10px;width:100%;padding:8px 10px;border:0;border-radius:var(--dsw-radius-md,8px);background:transparent;color:var(--dsw-alias-label-primary);font:inherit;text-align:left;cursor:pointer}
842
+ .dsh-powerup-update-select-menu{box-sizing:border-box;display:flex;flex-direction:column;padding:4px;overflow-x:hidden;border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg,10px);background:var(--dsw-alias-bg-layer-2);box-shadow:var(--dsw-elevation-prominent)}
843
+ .dsh-powerup-update-option{box-sizing:border-box;display:flex;align-items:flex-start;gap:10px;width:100%;min-width:0;padding:8px 10px;border:0;border-radius:var(--dsw-radius-md,8px);background:transparent;color:var(--dsw-alias-label-primary);font:inherit;text-align:left;cursor:pointer}
792
844
  .dsh-powerup-update-option:hover{background:var(--dsw-alias-interactive-bg-hover)}
793
845
  .dsh-powerup-update-option[aria-selected=true]{background:var(--dsw-alias-interactive-bg-active)}
794
846
  .dsh-powerup-update-option-copy{display:flex;flex:1 1 auto;flex-direction:column;gap:1px;min-width:0}
@@ -1195,6 +1247,9 @@
1195
1247
  const UPDATE_API = '/dsh-powerup/api/restart';
1196
1248
  const AUDIT_API = '/dsh-powerup/api/audit';
1197
1249
  const SELF_UPDATE_API = '/dsh-powerup/api/self-update';
1250
+ const JOB_KILL_API = '/dsh-powerup/api/job-kill';
1251
+ /** Character cap shared by the stop dialog and the Host normalizer. */
1252
+ const JOB_STOP_REASON_MAX = 200;
1198
1253
  const OFFICIAL_REGISTRY = 'https://registry.npmjs.org/';
1199
1254
  const REGISTRY_HOSTS = new Map([
1200
1255
  ['registry.npmjs.org', 'update.registryDefault'],
@@ -1784,6 +1839,262 @@
1784
1839
  };
1785
1840
  }
1786
1841
 
1842
+ /**
1843
+ * The row label as the host renders it. Live job rows carry one element
1844
+ * whose text and `title` are both the job label; the stop button's own
1845
+ * `title` is the localized action name, so it is skipped. Reading the DOM
1846
+ * instead of stripping the localized `aria-label` keeps this working in
1847
+ * every host language.
1848
+ * @param {Element | null | undefined} button
1849
+ * @returns {string | undefined}
1850
+ */
1851
+ function stopButtonLabel(button) {
1852
+ if (button === null || button === undefined || typeof button.closest !== 'function') return undefined;
1853
+ const item = button.closest('li');
1854
+ if (item === null || typeof item.querySelectorAll !== 'function') return undefined;
1855
+ for (const node of item.querySelectorAll('[title]')) {
1856
+ if (node === button) continue;
1857
+ const title = node.getAttribute('title');
1858
+ if (typeof title !== 'string' || title === '') continue;
1859
+ if (node.textContent === title) return title;
1860
+ }
1861
+ return undefined;
1862
+ }
1863
+
1864
+ /**
1865
+ * The session the open jobs panel belongs to. The bridge publishes the
1866
+ * active session; when it is unavailable yet, a single watched session
1867
+ * with live jobs is unambiguous.
1868
+ * @param {{ rows?: Record<string, Array<{ status: string }>> }} snapshot
1869
+ * @param {string | undefined} sessionId
1870
+ * @returns {string | undefined}
1871
+ */
1872
+ function stopTargetSession(snapshot, sessionId) {
1873
+ const rows = snapshot?.rows ?? {};
1874
+ if (typeof sessionId === 'string' && sessionId !== '') return sessionId;
1875
+ const candidates = Object.keys(rows).filter((key) => (rows[key] ?? []).some((job) => job.status === 'running'));
1876
+ return candidates.length === 1 ? candidates[0] : undefined;
1877
+ }
1878
+
1879
+ /**
1880
+ * Resolve the job behind a host stop button without importing the jobs
1881
+ * plugin: the open panel renders its live rows in start order, so the
1882
+ * n-th stop button in the document belongs to the n-th running job. The
1883
+ * row label cross-checks that pairing. Returning undefined leaves the
1884
+ * host's own stop flow untouched.
1885
+ * @param {{ state?: { getSnapshot?: () => { rows?: Record<string, Array<object>> } } } | undefined} jobsService
1886
+ * @param {Element | null | undefined} button
1887
+ * @param {string | undefined} sessionId
1888
+ * @returns {{ sessionId: string, job: { id: string, label: string } } | undefined}
1889
+ */
1890
+ function resolveStopTarget(jobsService, button, sessionId) {
1891
+ if (jobsService === null || jobsService === undefined || button === null || button === undefined) return undefined;
1892
+ const state = jobsService.state;
1893
+ if (state === undefined || typeof state.getSnapshot !== 'function') return undefined;
1894
+ const snapshot = state.getSnapshot();
1895
+ const owner = stopTargetSession(snapshot, sessionId);
1896
+ if (owner === undefined) return undefined;
1897
+ const live = (snapshot?.rows?.[String(owner)] ?? [])
1898
+ .filter((job) => job.status === 'running')
1899
+ .sort((left, right) => left.startedAt - right.startedAt);
1900
+ if (live.length === 0) return undefined;
1901
+ const buttons = [...document.querySelectorAll('button[data-kill-state]')];
1902
+ const index = buttons.indexOf(button);
1903
+ if (index < 0) return undefined;
1904
+ const label = stopButtonLabel(button);
1905
+ let job = index < live.length ? live[index] : undefined;
1906
+ if (job !== undefined && label !== undefined && job.label !== label) job = undefined;
1907
+ if (job === undefined && label !== undefined) job = live.find((candidate) => candidate.label === label);
1908
+ if (job === undefined) return undefined;
1909
+ return { sessionId: owner, job };
1910
+ }
1911
+
1912
+ /**
1913
+ * The stop-reason popover. The host jobs panel owns an irreversible
1914
+ * two-press stop and always records `cancelled by the user`; this overlay
1915
+ * intercepts the first press, asks for an optional reason, and posts it to
1916
+ * the Host route that kills through the registry with that reason, so the
1917
+ * injected completion notice and the model's tool result carry it. If the
1918
+ * button cannot be resolved to a job, the event is left alone and the
1919
+ * host's original stop flow runs unchanged.
1920
+ */
1921
+ function JobStopOverlay({ jobs, ctx }) {
1922
+ const [target, setTarget] = useState(null);
1923
+ const [reason, setReason] = useState('');
1924
+ const [pending, setPending] = useState(false);
1925
+ const [error, setError] = useState(null);
1926
+ const panelRef = useRef(null);
1927
+ const inputRef = useRef(null);
1928
+ const sequenceRef = useRef(0);
1929
+ const t = useCallback((key, params) => translateCurrent(key, params), []);
1930
+
1931
+ const close = useCallback(() => {
1932
+ sequenceRef.current += 1;
1933
+ setTarget(null);
1934
+ setPending(false);
1935
+ setError(null);
1936
+ }, []);
1937
+
1938
+ useEffect(() => {
1939
+ const onClick = (event) => {
1940
+ if (event.defaultPrevented) return;
1941
+ const node = event.target;
1942
+ if (!(node instanceof Element)) return;
1943
+ const button = node.closest('button[data-kill-state]');
1944
+ if (button === null) return;
1945
+ const resolved = resolveStopTarget(jobs, button, bridge.sessionId);
1946
+ if (resolved === undefined) return;
1947
+ event.preventDefault();
1948
+ event.stopPropagation();
1949
+ sequenceRef.current += 1;
1950
+ setReason('');
1951
+ setError(null);
1952
+ setPending(false);
1953
+ setTarget({ ...resolved, rect: button.getBoundingClientRect() });
1954
+ };
1955
+ document.addEventListener('click', onClick, true);
1956
+ return () => document.removeEventListener('click', onClick, true);
1957
+ }, [jobs]);
1958
+
1959
+ useEffect(() => {
1960
+ if (target === null) return undefined;
1961
+ const onPointerDown = (event) => {
1962
+ const panel = panelRef.current;
1963
+ if (panel !== null && event.target instanceof Node && panel.contains(event.target)) return;
1964
+ close();
1965
+ };
1966
+ const onScroll = (event) => {
1967
+ const panel = panelRef.current;
1968
+ if (panel !== null && event.target instanceof Node && panel.contains(event.target)) return;
1969
+ close();
1970
+ };
1971
+ const onResize = () => close();
1972
+ document.addEventListener('pointerdown', onPointerDown, true);
1973
+ document.addEventListener('scroll', onScroll, true);
1974
+ window.addEventListener('resize', onResize);
1975
+ return () => {
1976
+ document.removeEventListener('pointerdown', onPointerDown, true);
1977
+ document.removeEventListener('scroll', onScroll, true);
1978
+ window.removeEventListener('resize', onResize);
1979
+ };
1980
+ }, [target, close]);
1981
+
1982
+ // A settled job needs no stop dialog; close it when the roster says it
1983
+ // finished (another stop path, a producer exit, or our own request).
1984
+ useEffect(() => {
1985
+ if (target === null || jobs?.state === undefined) return undefined;
1986
+ const state = jobs.state;
1987
+ if (typeof state.getSnapshot !== 'function' || typeof state.subscribe !== 'function') return undefined;
1988
+ const check = () => {
1989
+ const rows = state.getSnapshot()?.rows?.[String(target.sessionId)] ?? [];
1990
+ const row = rows.find((job) => String(job.id) === String(target.job.id));
1991
+ if (row === undefined || row.status !== 'running') close();
1992
+ };
1993
+ return state.subscribe(check);
1994
+ }, [target, jobs, close]);
1995
+
1996
+ useEffect(() => {
1997
+ if (target === null) return undefined;
1998
+ const timer = window.setTimeout(() => inputRef.current?.focus(), 0);
1999
+ return () => window.clearTimeout(timer);
2000
+ }, [target]);
2001
+
2002
+ const submit = async () => {
2003
+ if (target === null || pending) return;
2004
+ const token = sequenceRef.current;
2005
+ setPending(true);
2006
+ setError(null);
2007
+ try {
2008
+ const response = await fetch(JOB_KILL_API, {
2009
+ method: 'POST',
2010
+ headers: { 'content-type': 'application/json' },
2011
+ body: JSON.stringify({
2012
+ sessionId: target.sessionId,
2013
+ jobId: String(target.job.id),
2014
+ reason: reason.trim(),
2015
+ }),
2016
+ });
2017
+ let payload = null;
2018
+ try {
2019
+ payload = await response.json();
2020
+ } catch {
2021
+ payload = null;
2022
+ }
2023
+ if (!response.ok || payload?.ok !== true) throw new Error(payload?.error ?? `HTTP ${response.status}`);
2024
+ if (sequenceRef.current !== token) return;
2025
+ setTarget(null);
2026
+ setPending(false);
2027
+ setReason('');
2028
+ setError(null);
2029
+ } catch (failure) {
2030
+ if (sequenceRef.current !== token) return;
2031
+ setPending(false);
2032
+ setError(format(t('jobStop.failed'), { message: failure?.message ?? String(failure) }));
2033
+ }
2034
+ };
2035
+
2036
+ if (target === null) return null;
2037
+ const placement = popoverPlacement({ getBoundingClientRect: () => target.rect }, 300, 180);
2038
+ return h('div', {
2039
+ ref: panelRef,
2040
+ className: 'dsh-powerup-jobstop',
2041
+ role: 'dialog',
2042
+ 'aria-label': t('jobStop.title'),
2043
+ style: {
2044
+ left: `${placement.left}px`,
2045
+ width: `${placement.width}px`,
2046
+ ...(placement.top !== undefined ? { top: `${placement.top}px` } : { bottom: `${placement.bottom}px` }),
2047
+ maxHeight: `${placement.maxHeight}px`,
2048
+ },
2049
+ // Keep the host jobs menu open while the user interacts: its
2050
+ // outside-pointer handler listens on document and would close it.
2051
+ onPointerDown: (event) => event.stopPropagation(),
2052
+ onKeyDown: (event) => {
2053
+ if (event.key === 'Escape') {
2054
+ event.preventDefault();
2055
+ close();
2056
+ return;
2057
+ }
2058
+ if (event.key !== 'Enter' || event.isComposing === true) return;
2059
+ const tag = event.target?.tagName;
2060
+ if (tag !== 'INPUT' && tag !== 'TEXTAREA') return;
2061
+ event.preventDefault();
2062
+ void submit();
2063
+ },
2064
+ },
2065
+ h('div', { className: 'dsh-powerup-jobstop-head' }, h(StopIcon, { size: 12 }), t('jobStop.title')),
2066
+ h('div', { className: 'dsh-powerup-jobstop-label', title: target.job.label }, h('span', null, target.job.label)),
2067
+ h('label', { className: 'dsh-powerup-jobstop-field' },
2068
+ h('span', { className: 'dsh-powerup-jobstop-field-label' }, t('jobStop.reasonLabel')),
2069
+ h('input', {
2070
+ ref: inputRef,
2071
+ className: 'dsh-powerup-jobstop-input',
2072
+ type: 'text',
2073
+ value: reason,
2074
+ maxLength: JOB_STOP_REASON_MAX,
2075
+ placeholder: t('jobStop.reasonPlaceholder'),
2076
+ disabled: pending,
2077
+ onChange: (event) => setReason(event.target.value),
2078
+ }),
2079
+ ),
2080
+ h('p', { className: 'dsh-powerup-jobstop-note' }, t('jobStop.reasonNote')),
2081
+ error === null ? null : h('p', { className: 'dsh-powerup-jobstop-error', role: 'alert' }, error),
2082
+ h('div', { className: 'dsh-powerup-jobstop-actions' },
2083
+ h('button', {
2084
+ type: 'button',
2085
+ className: 'dsh-powerup-jobstop-cancel',
2086
+ disabled: pending,
2087
+ onClick: close,
2088
+ }, t('jobStop.cancel')),
2089
+ h('button', {
2090
+ type: 'button',
2091
+ className: 'dsh-powerup-jobstop-confirm',
2092
+ disabled: pending,
2093
+ onClick: () => { void submit(); },
2094
+ }, pending ? t('jobStop.stopping') : t('jobStop.confirm')),
2095
+ ));
2096
+ }
2097
+
1787
2098
  /**
1788
2099
  * The Plugins-page update control. It injects one icon button into each
1789
2100
  * third-party card of the built-in "Installed plugins" group, then owns
@@ -3101,6 +3412,16 @@
3101
3412
  ),
3102
3413
  h('p', { className: 'dsh-powerup-update-note', style: { marginTop: '12px' } }, t('page.updateHow')),
3103
3414
  ),
3415
+ h('section', { className: 'dsh-powerup-card' },
3416
+ h('div', { className: 'dsh-powerup-card-head' },
3417
+ h('div', { className: 'dsh-powerup-card-icon' }, h(StopIcon, { size: 18 })),
3418
+ h('div', { className: 'dsh-powerup-card-copy' },
3419
+ h('h2', null, t('page.jobStopTitle')),
3420
+ h('p', null, t('page.jobStopDesc')),
3421
+ ),
3422
+ ),
3423
+ h('p', { className: 'dsh-powerup-update-note', style: { marginTop: '12px' } }, t('page.jobStopHow')),
3424
+ ),
3104
3425
  h('section', { className: 'dsh-powerup-card' },
3105
3426
  h('h2', { className: 'dsh-powerup-section-title', style: { marginBottom: '10px' } }, t('page.howTitle')),
3106
3427
  h('ol', { className: 'dsh-powerup-steps' },
@@ -3216,6 +3537,29 @@
3216
3537
  console.warn('[dsh-powerup] plugin update registration failed:', error?.message ?? error);
3217
3538
  }
3218
3539
  }
3540
+
3541
+ // The stop-reason popover reads the Client jobs snapshot while the
3542
+ // built-in jobs panel owns the stop buttons. Wait for the jobs service
3543
+ // in a nested inject scope so a late-provided service still registers.
3544
+ if (typeof ctx.inject === 'function') {
3545
+ try {
3546
+ ctx.inject(['jobs'], (scope) => {
3547
+ const jobs = scope.get('jobs');
3548
+ const childSlots = scope.get('slots');
3549
+ if (jobs === undefined || childSlots === undefined || typeof childSlots.register !== 'function') return;
3550
+ scope.effect(
3551
+ () => childSlots.inject('shell.overlay', () => childSlots.register({
3552
+ name: 'shell.overlay',
3553
+ id: 'powerup-job-stop',
3554
+ order: 57,
3555
+ }, () => h(JobStopOverlay, { jobs, ctx: scope }))),
3556
+ 'dsh-powerup: job stop reason',
3557
+ );
3558
+ });
3559
+ } catch (error) {
3560
+ console.warn('[dsh-powerup] job stop registration failed:', error?.message ?? error);
3561
+ }
3562
+ }
3219
3563
  }
3220
3564
 
3221
3565
  return {
@@ -3231,6 +3575,9 @@
3231
3575
  PowerUpPage,
3232
3576
  PowerUpOverlay,
3233
3577
  PluginUpdateOverlay,
3578
+ JobStopOverlay,
3579
+ stopButtonLabel,
3580
+ resolveStopTarget,
3234
3581
  ensureUpdateButtons,
3235
3582
  ensureRestartBar,
3236
3583
  updateButtonLabel,
package/index.js CHANGED
@@ -10,10 +10,14 @@
10
10
  * POST /dsh-powerup/api/self-update → removes and reinstalls this plugin
11
11
  * in the background, surviving the
12
12
  * plugin's own unload
13
+ * POST /dsh-powerup/api/job-kill → stops one background job with an
14
+ * optional human reason
13
15
  *
14
16
  * The Client half drives other plugins' installation through the built-in
15
- * `pluginManager` Remote. Only the process restart and the self-update handoff
16
- * need Host code.
17
+ * `pluginManager` Remote. Only the process restart, the self-update handoff,
18
+ * and the stop-with-reason kill need Host code: the built-in `job.kill` Remote
19
+ * hard-codes `cancelled by the user`, while the registry's own `kill` accepts
20
+ * a reason that settlement merges into the job's `detail` line.
17
21
  */
18
22
 
19
23
  import { randomUUID } from 'node:crypto';
@@ -167,6 +171,40 @@ function appendSelfUpdateLog(line) {
167
171
  }
168
172
  }
169
173
 
174
+ /** The reason core records for a human kill; a custom reason is appended. */
175
+ const HUMAN_KILL_REASON = 'cancelled by the user';
176
+
177
+ /** Upper bound for the optional reason, in characters. */
178
+ const STOP_REASON_LIMIT = 200;
179
+
180
+ /**
181
+ * Normalize the optional reason typed in the stop dialog. Control characters
182
+ * and line breaks collapse into spaces so the reason stays one line inside the
183
+ * completion notice.
184
+ * @param {unknown} value
185
+ * @returns {string} the cleaned reason ('' when nothing was typed)
186
+ */
187
+ function normalizeStopReason(value) {
188
+ if (typeof value !== 'string') return '';
189
+ return value
190
+ .replace(/[\u0000-\u001f\u007f]+/gu, ' ')
191
+ .replace(/\s+/gu, ' ')
192
+ .trim()
193
+ .slice(0, STOP_REASON_LIMIT);
194
+ }
195
+
196
+ /**
197
+ * The reason recorded with a human kill. An empty custom reason keeps the
198
+ * core phrase; a typed one appends to it, so the injected completion notice
199
+ * reads `cancelled by the user: <reason>`.
200
+ * @param {unknown} value
201
+ * @returns {string}
202
+ */
203
+ function killReasonFor(value) {
204
+ const reason = normalizeStopReason(value);
205
+ return reason === '' ? HUMAN_KILL_REASON : `${HUMAN_KILL_REASON}: ${reason}`;
206
+ }
207
+
170
208
  /**
171
209
  * The concrete versions the update dialog accepts. The Client applies the same
172
210
  * shape before it removes anything; this is the Host-side guard.
@@ -243,11 +281,45 @@ async function handle(req, res, ctx) {
243
281
 
244
282
  const url = new URL(req.url ?? ROUTE, 'http://localhost');
245
283
  const op = url.pathname.slice(ROUTE.length).replace(/^\/+/u, '') || url.searchParams.get('op') || '';
246
- if (op !== '' && op !== 'restart' && op !== 'self-update' && op !== 'audit') {
284
+ if (op !== '' && op !== 'restart' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill') {
247
285
  sendJson(res, { ok: false, error: 'not-found' }, 404);
248
286
  return;
249
287
  }
250
288
 
289
+ if (op === 'job-kill') {
290
+ if (req.method !== 'POST') {
291
+ sendJson(res, { ok: false, error: 'method-not-allowed' }, 405);
292
+ return;
293
+ }
294
+ let body;
295
+ try {
296
+ body = await readJsonBody(req);
297
+ } catch (error) {
298
+ sendJson(res, { ok: false, error: String(error?.message ?? error) }, 400);
299
+ return;
300
+ }
301
+ const jobId = typeof body?.jobId === 'string' ? body.jobId.trim() : '';
302
+ const sessionId = typeof body?.sessionId === 'string' ? body.sessionId.trim() : '';
303
+ if (jobId === '' || sessionId === '') {
304
+ sendJson(res, { ok: false, code: 'invalid-request', error: 'jobId and sessionId are required' }, 400);
305
+ return;
306
+ }
307
+ const jobs = ctx?.get?.('jobs');
308
+ if (jobs === undefined || typeof jobs.kill !== 'function') {
309
+ sendJson(res, { ok: false, code: 'jobs-unavailable', error: 'jobs service is unavailable' }, 503);
310
+ return;
311
+ }
312
+ try {
313
+ // The registry's owner fence checks that this session can see the job,
314
+ // and records the reason so settlement merges it into `detail`.
315
+ const outcome = jobs.kill(jobId, sessionId, killReasonFor(body?.reason));
316
+ sendJson(res, { ok: true, outcome });
317
+ } catch (error) {
318
+ sendJson(res, { ok: false, code: 'kill-failed', error: String(error?.message ?? error) }, 404);
319
+ }
320
+ return;
321
+ }
322
+
251
323
  if (op === 'audit') {
252
324
  if (req.method !== 'GET') {
253
325
  sendJson(res, { ok: false, error: 'method-not-allowed' }, 405);
@@ -334,4 +406,17 @@ export function apply(ctx) {
334
406
  }
335
407
 
336
408
  /** Exported for tests only; the Host never reads this. */
337
- export const __test = { handle, isLoopback, sameOrigin, performSelfUpdate, normalizeVersion, auditProfileBundles, profileDirectory, HOST_STARTED_AT, ROUTE, MODULE_ID };
409
+ export const __test = {
410
+ handle,
411
+ isLoopback,
412
+ sameOrigin,
413
+ performSelfUpdate,
414
+ normalizeVersion,
415
+ normalizeStopReason,
416
+ killReasonFor,
417
+ auditProfileBundles,
418
+ profileDirectory,
419
+ HOST_STARTED_AT,
420
+ ROUTE,
421
+ MODULE_ID,
422
+ };
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Power-Up",
4
- "description": "Adds a right-click action menu to the Trajectory ledger: copy a record, copy a Markdown quote, quote it into the composer, open the record inspector, fork the session at that record, export the trajectory snapshot, and copy the session ID. The Plugins page gains an update control on every third-party installed plugin: choose a version from the registry, uninstall the old copy, reinstall through the Add plugin path, then enable and optionally restart DSH."
4
+ "description": "Adds a right-click action menu to the Trajectory ledger: copy a record, copy a Markdown quote, quote it into the composer, open the record inspector, fork the session at that record, export the trajectory snapshot, and copy the session ID. The session header's background jobs panel gains an optional stop reason when a job is stopped by hand; the reason is appended to the completion notice injected into the session. The Plugins page gains an update control on every third-party installed plugin: choose a version from the registry, uninstall the old copy, reinstall through the Add plugin path, then enable and optionally restart DSH."
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": "在轨迹页面为记录增加右键操作菜单:复制内容、复制 Markdown 引用、引用到输入框、查看记录详情、从该记录 Fork 会话、导出轨迹快照、复制会话 ID。插件页为每个第三方已安装插件增加更新按钮:从安装源选择版本,先卸载旧版再按「添加插件」流程安装,完成后可立即启用并选择是否重启 DSH。"
4
+ "description": "在轨迹页面为记录增加右键操作菜单:复制内容、复制 Markdown 引用、引用到输入框、查看记录详情、从该记录 Fork 会话、导出轨迹快照、复制会话 ID。在会话顶部的后台任务面板手动停止任务时可以填写停止原因,原因会附加在任务结束后注入会话的提示里。插件页为每个第三方已安装插件增加更新按钮:从安装源选择版本,先卸载旧版再按「添加插件」流程安装,完成后可立即启用并选择是否重启 DSH。"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@restregular/dsh-powerup",
3
- "version": "0.3.1",
4
- "description": "Power-Up — small, opt-in upgrades for DeepSeek Harness. Adds a right-click action menu to the Trajectory ledger and an update control for third-party plugins installed from the Plugins page, with version lookup from the configured registries, a starred default source, uninstall-and-reinstall through the Add plugin path, restart-needed markers, a background self-update, and an optional DSH restart. · 为 DeepSeek Harness 提供小型增强:在轨迹页面右键记录即可复制、引用、查看详情或从该记录 Fork;并在插件页为已安装插件提供带版本查询的更新按钮,安装源可设默认,沿用「添加插件」的安装流程,支持待重启标记、后台自更新与一键重启。",
3
+ "version": "0.4.0",
4
+ "description": "Power-Up — small, opt-in upgrades for DeepSeek Harness. Adds a right-click action menu to the Trajectory ledger, an optional stop reason in the session header's background jobs panel (appended to the injected completion notice), and an update control for third-party plugins installed from the Plugins page, with version lookup from the configured registries, a starred default source, uninstall-and-reinstall through the Add plugin path, restart-needed markers, a background self-update, and an optional DSH restart. · 为 DeepSeek Harness 提供小型增强:在轨迹页面右键记录即可复制、引用、查看详情或从该记录 Fork;在会话顶部的后台任务面板手动停止任务时可填写停止原因,原因会附加到任务结束后的会话提示;并在插件页为已安装插件提供带版本查询的更新按钮,安装源可设默认,沿用「添加插件」的安装流程,支持待重启标记、后台自更新与一键重启。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",
7
7
  "main": "index.js",
@@ -55,6 +55,8 @@
55
55
  "deepseek",
56
56
  "trajectory",
57
57
  "context-menu",
58
+ "background-jobs",
59
+ "job-control",
58
60
  "power-up"
59
61
  ],
60
62
  "publishConfig": {