@restregular/dsh-powerup 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -3
- package/client.js +446 -4
- package/index.js +163 -11
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +4 -2
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
|
|
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.
|
|
@@ -51,6 +66,10 @@ update dialog:
|
|
|
51
66
|
a version that is both uses one **Current · latest** tag.
|
|
52
67
|
3. Confirming removes the installed copy, checks the new spec the way **Add
|
|
53
68
|
plugin** does, and installs the selected version without enabling it.
|
|
69
|
+
Because the old copy is already gone at that point, a refused check or a
|
|
70
|
+
failed install automatically re-installs the removed version with its
|
|
71
|
+
previous enabled state; the dialog reports both the failure and the rollback
|
|
72
|
+
result.
|
|
54
73
|
4. The dialog then asks whether to enable the new version.
|
|
55
74
|
5. After enabling, it asks whether to restart DSH. On the desktop app the
|
|
56
75
|
`lib/restart-helper.cjs` helper relaunches the exact executable after the old
|
|
@@ -89,6 +108,13 @@ refresh the page when the install finishes.
|
|
|
89
108
|
observes the trajectory package's own `data-*` contracts. If those attributes
|
|
90
109
|
change, row-specific actions degrade gracefully; session-level actions in the
|
|
91
110
|
empty ledger area keep working.
|
|
111
|
+
- **The stop reason rides the host's own job registry.** The panel belongs to
|
|
112
|
+
`@deepseek-ai/dsh-client-ui-jobs`, so Power-Up does not replace it: a capture
|
|
113
|
+
listener recognizes its `button[data-kill-state]`, maps the button to the live
|
|
114
|
+
row (DOM order plus the row's `title` label), and opens the reason dialog.
|
|
115
|
+
The typed reason goes to `POST /dsh-powerup/api/job-kill`, which calls the
|
|
116
|
+
registry's `kill(id, session, reason)` — the same admission the built-in
|
|
117
|
+
Remote uses, with the reason settlement merges into the job's `detail` line.
|
|
92
118
|
- **The update entry uses the built-in page's contracts.** The Plugins page has
|
|
93
119
|
no per-card slot, so the overlay injects one button into every
|
|
94
120
|
`[data-plugin-group="bundles"] [data-plugin-package]` card and re-asserts it
|
|
@@ -102,7 +128,9 @@ refresh the page when the install finishes.
|
|
|
102
128
|
through the built-in manager service. Removing the bundle unloads Power-Up's
|
|
103
129
|
own Host fiber, but the manager service and the pending promise stay in the
|
|
104
130
|
Host process, so the reinstall finishes; failures are appended to
|
|
105
|
-
`~/.dsh/powerup/self-update.log`.
|
|
131
|
+
`~/.dsh/powerup/self-update.log`. The Host captures the version it was loaded
|
|
132
|
+
from before removal and re-installs that version if the check or install
|
|
133
|
+
fails, so a failed self-update does not leave Power-Up missing.
|
|
106
134
|
- **Restart status lives in this browser session.** A management result that
|
|
107
135
|
says `restart-required` is written to `sessionStorage`; the card gets a
|
|
108
136
|
**Restart needed** tag and the group heading gets a count plus a restart
|
|
@@ -129,7 +157,7 @@ node test/smoke.mjs
|
|
|
129
157
|
|
|
130
158
|
The smoke test loads the real Client module with React/browser doubles, applies
|
|
131
159
|
it to a fake slot context, and checks registrations, icons, helpers, theme
|
|
132
|
-
tokens, and the manifest.
|
|
160
|
+
tokens, the stop-reason mapping and Host route, and the manifest.
|
|
133
161
|
|
|
134
162
|
## License
|
|
135
163
|
|
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.
|
|
47
|
+
const VERSION = '0.4.1';
|
|
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': '选择版本后自动卸载旧版并安装新版本。',
|
|
@@ -140,6 +151,7 @@
|
|
|
140
151
|
'update.step.checking': '正在校验版本…',
|
|
141
152
|
'update.step.removing': '正在卸载旧版…',
|
|
142
153
|
'update.step.installing': '正在安装 {version}…',
|
|
154
|
+
'update.step.rollback': '正在恢复旧版本 {version}…',
|
|
143
155
|
'update.step.enabling': '正在启用…',
|
|
144
156
|
'update.log': '安装输出',
|
|
145
157
|
'update.enableTitle': '安装完成,是否立即启用?',
|
|
@@ -176,6 +188,11 @@
|
|
|
176
188
|
'update.doneRestart': '部分更改需要重启 DSH 后生效。',
|
|
177
189
|
'update.doneButton': '完成',
|
|
178
190
|
'update.errorTitle': '更新失败',
|
|
191
|
+
'update.rollbackOkTitle': '已恢复旧版本',
|
|
192
|
+
'update.rollbackOkDesc': '更新失败,{name} 已自动回滚到 {version},仍可继续使用。',
|
|
193
|
+
'update.rollbackFailedTitle': '旧版本恢复失败',
|
|
194
|
+
'update.rollbackFailedDesc': '自动回滚失败:{message}。请到「插件」页用「添加插件」重新安装。',
|
|
195
|
+
'update.rollbackUnavailable': '无法确定旧版本号,未能自动回滚。请到「插件」页重新安装。',
|
|
179
196
|
'update.selfTitle': '请用「添加插件」更新 Power-Up 自身',
|
|
180
197
|
'update.selfDesc': '更新 Power-Up 会先卸载本插件,更新流程会随之中断。',
|
|
181
198
|
'update.notRemovable': '该插件受 DSH 管理,不能在这里更新。',
|
|
@@ -205,6 +222,9 @@
|
|
|
205
222
|
'page.updateTitle': 'Update plugins',
|
|
206
223
|
'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
224
|
'page.updateHow': 'Open Plugins in the sidebar and click the update icon at the right of a card under Installed plugins.',
|
|
225
|
+
'page.jobStopTitle': 'Background job stop reason',
|
|
226
|
+
'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.',
|
|
227
|
+
'page.jobStopHow': 'Open a session, expand the background jobs panel, press stop on a running job, type a reason (optional), then confirm.',
|
|
208
228
|
'page.footer': 'Power-Up {version} · Settings are stored in this browser',
|
|
209
229
|
'page.localOnly': 'This browser only',
|
|
210
230
|
'action.copy': 'Copy content',
|
|
@@ -249,6 +269,14 @@
|
|
|
249
269
|
'toast.sessionCopied': 'Session ID copied',
|
|
250
270
|
'toast.forkUnavailable': 'This host does not expose the fork API',
|
|
251
271
|
'toast.noSession': 'No session is open',
|
|
272
|
+
'jobStop.title': 'Stop background job',
|
|
273
|
+
'jobStop.reasonLabel': 'Stop reason (optional)',
|
|
274
|
+
'jobStop.reasonPlaceholder': 'e.g. the result is no longer needed',
|
|
275
|
+
'jobStop.reasonNote': 'The reason is appended to the notice injected into the session when the job settles.',
|
|
276
|
+
'jobStop.cancel': 'Cancel',
|
|
277
|
+
'jobStop.confirm': 'Stop job',
|
|
278
|
+
'jobStop.stopping': 'Stopping…',
|
|
279
|
+
'jobStop.failed': 'Could not stop the job: {message}',
|
|
252
280
|
'update.button': 'Update version',
|
|
253
281
|
'update.title': 'Update plugin',
|
|
254
282
|
'update.subtitle': 'Choose a version; the old one is removed and the new one installed.',
|
|
@@ -277,6 +305,7 @@
|
|
|
277
305
|
'update.step.checking': 'Checking the version…',
|
|
278
306
|
'update.step.removing': 'Removing the old version…',
|
|
279
307
|
'update.step.installing': 'Installing {version}…',
|
|
308
|
+
'update.step.rollback': 'Restoring {version}…',
|
|
280
309
|
'update.step.enabling': 'Enabling…',
|
|
281
310
|
'update.log': 'Install output',
|
|
282
311
|
'update.enableTitle': 'Installed. Enable it now?',
|
|
@@ -313,6 +342,11 @@
|
|
|
313
342
|
'update.doneRestart': 'Some changes apply only after DSH restarts.',
|
|
314
343
|
'update.doneButton': 'Done',
|
|
315
344
|
'update.errorTitle': 'Update failed',
|
|
345
|
+
'update.rollbackOkTitle': 'Previous version restored',
|
|
346
|
+
'update.rollbackOkDesc': 'The update failed, so {name} was rolled back to {version} and is ready to use.',
|
|
347
|
+
'update.rollbackFailedTitle': 'Could not restore the previous version',
|
|
348
|
+
'update.rollbackFailedDesc': 'Automatic rollback failed: {message}. Reinstall it from the Plugins page with “Add plugin”.',
|
|
349
|
+
'update.rollbackUnavailable': 'The previous version is unknown, so no automatic rollback was possible. Reinstall it from the Plugins page.',
|
|
316
350
|
'update.selfTitle': 'Update Power-Up with Add plugin',
|
|
317
351
|
'update.selfDesc': 'Updating Power-Up removes this plugin first, which interrupts this flow.',
|
|
318
352
|
'update.notRemovable': 'DSH manages this plugin; it cannot be updated here.',
|
|
@@ -607,6 +641,15 @@
|
|
|
607
641
|
);
|
|
608
642
|
}
|
|
609
643
|
|
|
644
|
+
function StopIcon({ size = 16 }) {
|
|
645
|
+
return h(Icon, { size },
|
|
646
|
+
h('rect', {
|
|
647
|
+
x: '3.2', y: '3.2', width: '9.6', height: '9.6', rx: '1.7',
|
|
648
|
+
fill: 'none', stroke: 'currentColor', strokeWidth: '1.3',
|
|
649
|
+
}),
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
|
|
610
653
|
function CheckIcon({ size = 16 }) {
|
|
611
654
|
return h(Icon, { size },
|
|
612
655
|
h('path', {
|
|
@@ -704,6 +747,27 @@
|
|
|
704
747
|
.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
748
|
.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
749
|
@keyframes dsh-powerup-toast-in{from{opacity:0;transform:translate(-50%,5px)}to{opacity:1;transform:translate(-50%,0)}}
|
|
750
|
+
.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}
|
|
751
|
+
@keyframes dsh-powerup-jobstop-in{from{opacity:0;transform:translateY(3px)}to{opacity:1;transform:none}}
|
|
752
|
+
.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}
|
|
753
|
+
.dsh-powerup-jobstop-head svg{flex:none;color:var(--dsw-alias-state-error-primary)}
|
|
754
|
+
.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}
|
|
755
|
+
.dsh-powerup-jobstop-label span{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
756
|
+
.dsh-powerup-jobstop-field{display:flex;flex-direction:column;gap:4px;min-width:0}
|
|
757
|
+
.dsh-powerup-jobstop-field-label{color:var(--dsw-alias-label-secondary);font-size:11.5px;line-height:17px}
|
|
758
|
+
.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}
|
|
759
|
+
.dsh-powerup-jobstop-input::placeholder{color:var(--dsw-alias-label-caption)}
|
|
760
|
+
.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)}
|
|
761
|
+
.dsh-powerup-jobstop-note{margin:0;color:var(--dsw-alias-label-tertiary);font-size:10.5px;line-height:15px}
|
|
762
|
+
.dsh-powerup-jobstop-error{margin:0;color:var(--dsw-alias-state-error-primary);font-size:11.5px;line-height:16px;overflow-wrap:anywhere}
|
|
763
|
+
.dsh-powerup-jobstop-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px}
|
|
764
|
+
.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}
|
|
765
|
+
.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)}
|
|
766
|
+
.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}
|
|
767
|
+
.dsh-powerup-jobstop-confirm:hover:not(:disabled){background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 20%,transparent)}
|
|
768
|
+
.dsh-powerup-jobstop-confirm:disabled,.dsh-powerup-jobstop-cancel:disabled{opacity:.55;cursor:default}
|
|
769
|
+
.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}
|
|
770
|
+
@media (prefers-reduced-motion:reduce){.dsh-powerup-jobstop{animation:none}}
|
|
707
771
|
.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
772
|
.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
773
|
.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}
|
|
@@ -1195,6 +1259,9 @@
|
|
|
1195
1259
|
const UPDATE_API = '/dsh-powerup/api/restart';
|
|
1196
1260
|
const AUDIT_API = '/dsh-powerup/api/audit';
|
|
1197
1261
|
const SELF_UPDATE_API = '/dsh-powerup/api/self-update';
|
|
1262
|
+
const JOB_KILL_API = '/dsh-powerup/api/job-kill';
|
|
1263
|
+
/** Character cap shared by the stop dialog and the Host normalizer. */
|
|
1264
|
+
const JOB_STOP_REASON_MAX = 200;
|
|
1198
1265
|
const OFFICIAL_REGISTRY = 'https://registry.npmjs.org/';
|
|
1199
1266
|
const REGISTRY_HOSTS = new Map([
|
|
1200
1267
|
['registry.npmjs.org', 'update.registryDefault'],
|
|
@@ -1606,6 +1673,35 @@
|
|
|
1606
1673
|
return `powerup-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
1607
1674
|
}
|
|
1608
1675
|
|
|
1676
|
+
/**
|
|
1677
|
+
* Reinstall the version an update removed. The update removes the old
|
|
1678
|
+
* copy before the new spec is inspected, so a refused inspection or a
|
|
1679
|
+
* failed install leaves the plugin missing; this puts the old version
|
|
1680
|
+
* back with the enabled state it had before the update.
|
|
1681
|
+
* @param {{ installBundle: Function }} manager
|
|
1682
|
+
* @param {{ name: string, version: string | null | undefined, enabled?: boolean, registry?: string | null }} target
|
|
1683
|
+
* @param {(key: string, params?: object) => string} t
|
|
1684
|
+
* @returns {Promise<{ version: string }>}
|
|
1685
|
+
*/
|
|
1686
|
+
async function restorePreviousBundle(manager, target, t) {
|
|
1687
|
+
const version = typeof target.version === 'string' ? target.version.trim() : '';
|
|
1688
|
+
if (version === '') throw new Error(t('update.rollbackUnavailable'));
|
|
1689
|
+
const installed = await manager.installBundle(`${target.name}@${version}`, {
|
|
1690
|
+
enabled: target.enabled !== false,
|
|
1691
|
+
requestId: newRequestId(),
|
|
1692
|
+
registry: target.registry ?? null,
|
|
1693
|
+
});
|
|
1694
|
+
if (!installed.ok) throw new Error(installed.error?.message ?? t('update.unknown'));
|
|
1695
|
+
const value = installed.value ?? {};
|
|
1696
|
+
if (value.error !== undefined || value.application === 'failed') throw new Error(operationReason(value, t));
|
|
1697
|
+
if (value.application === 'cancelled') throw new Error(t('update.cancelled'));
|
|
1698
|
+
return {
|
|
1699
|
+
version: typeof value.version === 'string' && value.version !== '' ? value.version : version,
|
|
1700
|
+
restartRequired: value.application === 'restart-required',
|
|
1701
|
+
restartReason: typeof value.restartReason === 'string' ? value.restartReason : '',
|
|
1702
|
+
};
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1609
1705
|
/**
|
|
1610
1706
|
* The package name of a registry install spec. Git, tarball, and local
|
|
1611
1707
|
* paths return null; their installed name comes from the Host result.
|
|
@@ -1784,6 +1880,262 @@
|
|
|
1784
1880
|
};
|
|
1785
1881
|
}
|
|
1786
1882
|
|
|
1883
|
+
/**
|
|
1884
|
+
* The row label as the host renders it. Live job rows carry one element
|
|
1885
|
+
* whose text and `title` are both the job label; the stop button's own
|
|
1886
|
+
* `title` is the localized action name, so it is skipped. Reading the DOM
|
|
1887
|
+
* instead of stripping the localized `aria-label` keeps this working in
|
|
1888
|
+
* every host language.
|
|
1889
|
+
* @param {Element | null | undefined} button
|
|
1890
|
+
* @returns {string | undefined}
|
|
1891
|
+
*/
|
|
1892
|
+
function stopButtonLabel(button) {
|
|
1893
|
+
if (button === null || button === undefined || typeof button.closest !== 'function') return undefined;
|
|
1894
|
+
const item = button.closest('li');
|
|
1895
|
+
if (item === null || typeof item.querySelectorAll !== 'function') return undefined;
|
|
1896
|
+
for (const node of item.querySelectorAll('[title]')) {
|
|
1897
|
+
if (node === button) continue;
|
|
1898
|
+
const title = node.getAttribute('title');
|
|
1899
|
+
if (typeof title !== 'string' || title === '') continue;
|
|
1900
|
+
if (node.textContent === title) return title;
|
|
1901
|
+
}
|
|
1902
|
+
return undefined;
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
/**
|
|
1906
|
+
* The session the open jobs panel belongs to. The bridge publishes the
|
|
1907
|
+
* active session; when it is unavailable yet, a single watched session
|
|
1908
|
+
* with live jobs is unambiguous.
|
|
1909
|
+
* @param {{ rows?: Record<string, Array<{ status: string }>> }} snapshot
|
|
1910
|
+
* @param {string | undefined} sessionId
|
|
1911
|
+
* @returns {string | undefined}
|
|
1912
|
+
*/
|
|
1913
|
+
function stopTargetSession(snapshot, sessionId) {
|
|
1914
|
+
const rows = snapshot?.rows ?? {};
|
|
1915
|
+
if (typeof sessionId === 'string' && sessionId !== '') return sessionId;
|
|
1916
|
+
const candidates = Object.keys(rows).filter((key) => (rows[key] ?? []).some((job) => job.status === 'running'));
|
|
1917
|
+
return candidates.length === 1 ? candidates[0] : undefined;
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
/**
|
|
1921
|
+
* Resolve the job behind a host stop button without importing the jobs
|
|
1922
|
+
* plugin: the open panel renders its live rows in start order, so the
|
|
1923
|
+
* n-th stop button in the document belongs to the n-th running job. The
|
|
1924
|
+
* row label cross-checks that pairing. Returning undefined leaves the
|
|
1925
|
+
* host's own stop flow untouched.
|
|
1926
|
+
* @param {{ state?: { getSnapshot?: () => { rows?: Record<string, Array<object>> } } } | undefined} jobsService
|
|
1927
|
+
* @param {Element | null | undefined} button
|
|
1928
|
+
* @param {string | undefined} sessionId
|
|
1929
|
+
* @returns {{ sessionId: string, job: { id: string, label: string } } | undefined}
|
|
1930
|
+
*/
|
|
1931
|
+
function resolveStopTarget(jobsService, button, sessionId) {
|
|
1932
|
+
if (jobsService === null || jobsService === undefined || button === null || button === undefined) return undefined;
|
|
1933
|
+
const state = jobsService.state;
|
|
1934
|
+
if (state === undefined || typeof state.getSnapshot !== 'function') return undefined;
|
|
1935
|
+
const snapshot = state.getSnapshot();
|
|
1936
|
+
const owner = stopTargetSession(snapshot, sessionId);
|
|
1937
|
+
if (owner === undefined) return undefined;
|
|
1938
|
+
const live = (snapshot?.rows?.[String(owner)] ?? [])
|
|
1939
|
+
.filter((job) => job.status === 'running')
|
|
1940
|
+
.sort((left, right) => left.startedAt - right.startedAt);
|
|
1941
|
+
if (live.length === 0) return undefined;
|
|
1942
|
+
const buttons = [...document.querySelectorAll('button[data-kill-state]')];
|
|
1943
|
+
const index = buttons.indexOf(button);
|
|
1944
|
+
if (index < 0) return undefined;
|
|
1945
|
+
const label = stopButtonLabel(button);
|
|
1946
|
+
let job = index < live.length ? live[index] : undefined;
|
|
1947
|
+
if (job !== undefined && label !== undefined && job.label !== label) job = undefined;
|
|
1948
|
+
if (job === undefined && label !== undefined) job = live.find((candidate) => candidate.label === label);
|
|
1949
|
+
if (job === undefined) return undefined;
|
|
1950
|
+
return { sessionId: owner, job };
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
/**
|
|
1954
|
+
* The stop-reason popover. The host jobs panel owns an irreversible
|
|
1955
|
+
* two-press stop and always records `cancelled by the user`; this overlay
|
|
1956
|
+
* intercepts the first press, asks for an optional reason, and posts it to
|
|
1957
|
+
* the Host route that kills through the registry with that reason, so the
|
|
1958
|
+
* injected completion notice and the model's tool result carry it. If the
|
|
1959
|
+
* button cannot be resolved to a job, the event is left alone and the
|
|
1960
|
+
* host's original stop flow runs unchanged.
|
|
1961
|
+
*/
|
|
1962
|
+
function JobStopOverlay({ jobs, ctx }) {
|
|
1963
|
+
const [target, setTarget] = useState(null);
|
|
1964
|
+
const [reason, setReason] = useState('');
|
|
1965
|
+
const [pending, setPending] = useState(false);
|
|
1966
|
+
const [error, setError] = useState(null);
|
|
1967
|
+
const panelRef = useRef(null);
|
|
1968
|
+
const inputRef = useRef(null);
|
|
1969
|
+
const sequenceRef = useRef(0);
|
|
1970
|
+
const t = useCallback((key, params) => translateCurrent(key, params), []);
|
|
1971
|
+
|
|
1972
|
+
const close = useCallback(() => {
|
|
1973
|
+
sequenceRef.current += 1;
|
|
1974
|
+
setTarget(null);
|
|
1975
|
+
setPending(false);
|
|
1976
|
+
setError(null);
|
|
1977
|
+
}, []);
|
|
1978
|
+
|
|
1979
|
+
useEffect(() => {
|
|
1980
|
+
const onClick = (event) => {
|
|
1981
|
+
if (event.defaultPrevented) return;
|
|
1982
|
+
const node = event.target;
|
|
1983
|
+
if (!(node instanceof Element)) return;
|
|
1984
|
+
const button = node.closest('button[data-kill-state]');
|
|
1985
|
+
if (button === null) return;
|
|
1986
|
+
const resolved = resolveStopTarget(jobs, button, bridge.sessionId);
|
|
1987
|
+
if (resolved === undefined) return;
|
|
1988
|
+
event.preventDefault();
|
|
1989
|
+
event.stopPropagation();
|
|
1990
|
+
sequenceRef.current += 1;
|
|
1991
|
+
setReason('');
|
|
1992
|
+
setError(null);
|
|
1993
|
+
setPending(false);
|
|
1994
|
+
setTarget({ ...resolved, rect: button.getBoundingClientRect() });
|
|
1995
|
+
};
|
|
1996
|
+
document.addEventListener('click', onClick, true);
|
|
1997
|
+
return () => document.removeEventListener('click', onClick, true);
|
|
1998
|
+
}, [jobs]);
|
|
1999
|
+
|
|
2000
|
+
useEffect(() => {
|
|
2001
|
+
if (target === null) return undefined;
|
|
2002
|
+
const onPointerDown = (event) => {
|
|
2003
|
+
const panel = panelRef.current;
|
|
2004
|
+
if (panel !== null && event.target instanceof Node && panel.contains(event.target)) return;
|
|
2005
|
+
close();
|
|
2006
|
+
};
|
|
2007
|
+
const onScroll = (event) => {
|
|
2008
|
+
const panel = panelRef.current;
|
|
2009
|
+
if (panel !== null && event.target instanceof Node && panel.contains(event.target)) return;
|
|
2010
|
+
close();
|
|
2011
|
+
};
|
|
2012
|
+
const onResize = () => close();
|
|
2013
|
+
document.addEventListener('pointerdown', onPointerDown, true);
|
|
2014
|
+
document.addEventListener('scroll', onScroll, true);
|
|
2015
|
+
window.addEventListener('resize', onResize);
|
|
2016
|
+
return () => {
|
|
2017
|
+
document.removeEventListener('pointerdown', onPointerDown, true);
|
|
2018
|
+
document.removeEventListener('scroll', onScroll, true);
|
|
2019
|
+
window.removeEventListener('resize', onResize);
|
|
2020
|
+
};
|
|
2021
|
+
}, [target, close]);
|
|
2022
|
+
|
|
2023
|
+
// A settled job needs no stop dialog; close it when the roster says it
|
|
2024
|
+
// finished (another stop path, a producer exit, or our own request).
|
|
2025
|
+
useEffect(() => {
|
|
2026
|
+
if (target === null || jobs?.state === undefined) return undefined;
|
|
2027
|
+
const state = jobs.state;
|
|
2028
|
+
if (typeof state.getSnapshot !== 'function' || typeof state.subscribe !== 'function') return undefined;
|
|
2029
|
+
const check = () => {
|
|
2030
|
+
const rows = state.getSnapshot()?.rows?.[String(target.sessionId)] ?? [];
|
|
2031
|
+
const row = rows.find((job) => String(job.id) === String(target.job.id));
|
|
2032
|
+
if (row === undefined || row.status !== 'running') close();
|
|
2033
|
+
};
|
|
2034
|
+
return state.subscribe(check);
|
|
2035
|
+
}, [target, jobs, close]);
|
|
2036
|
+
|
|
2037
|
+
useEffect(() => {
|
|
2038
|
+
if (target === null) return undefined;
|
|
2039
|
+
const timer = window.setTimeout(() => inputRef.current?.focus(), 0);
|
|
2040
|
+
return () => window.clearTimeout(timer);
|
|
2041
|
+
}, [target]);
|
|
2042
|
+
|
|
2043
|
+
const submit = async () => {
|
|
2044
|
+
if (target === null || pending) return;
|
|
2045
|
+
const token = sequenceRef.current;
|
|
2046
|
+
setPending(true);
|
|
2047
|
+
setError(null);
|
|
2048
|
+
try {
|
|
2049
|
+
const response = await fetch(JOB_KILL_API, {
|
|
2050
|
+
method: 'POST',
|
|
2051
|
+
headers: { 'content-type': 'application/json' },
|
|
2052
|
+
body: JSON.stringify({
|
|
2053
|
+
sessionId: target.sessionId,
|
|
2054
|
+
jobId: String(target.job.id),
|
|
2055
|
+
reason: reason.trim(),
|
|
2056
|
+
}),
|
|
2057
|
+
});
|
|
2058
|
+
let payload = null;
|
|
2059
|
+
try {
|
|
2060
|
+
payload = await response.json();
|
|
2061
|
+
} catch {
|
|
2062
|
+
payload = null;
|
|
2063
|
+
}
|
|
2064
|
+
if (!response.ok || payload?.ok !== true) throw new Error(payload?.error ?? `HTTP ${response.status}`);
|
|
2065
|
+
if (sequenceRef.current !== token) return;
|
|
2066
|
+
setTarget(null);
|
|
2067
|
+
setPending(false);
|
|
2068
|
+
setReason('');
|
|
2069
|
+
setError(null);
|
|
2070
|
+
} catch (failure) {
|
|
2071
|
+
if (sequenceRef.current !== token) return;
|
|
2072
|
+
setPending(false);
|
|
2073
|
+
setError(format(t('jobStop.failed'), { message: failure?.message ?? String(failure) }));
|
|
2074
|
+
}
|
|
2075
|
+
};
|
|
2076
|
+
|
|
2077
|
+
if (target === null) return null;
|
|
2078
|
+
const placement = popoverPlacement({ getBoundingClientRect: () => target.rect }, 300, 180);
|
|
2079
|
+
return h('div', {
|
|
2080
|
+
ref: panelRef,
|
|
2081
|
+
className: 'dsh-powerup-jobstop',
|
|
2082
|
+
role: 'dialog',
|
|
2083
|
+
'aria-label': t('jobStop.title'),
|
|
2084
|
+
style: {
|
|
2085
|
+
left: `${placement.left}px`,
|
|
2086
|
+
width: `${placement.width}px`,
|
|
2087
|
+
...(placement.top !== undefined ? { top: `${placement.top}px` } : { bottom: `${placement.bottom}px` }),
|
|
2088
|
+
maxHeight: `${placement.maxHeight}px`,
|
|
2089
|
+
},
|
|
2090
|
+
// Keep the host jobs menu open while the user interacts: its
|
|
2091
|
+
// outside-pointer handler listens on document and would close it.
|
|
2092
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
2093
|
+
onKeyDown: (event) => {
|
|
2094
|
+
if (event.key === 'Escape') {
|
|
2095
|
+
event.preventDefault();
|
|
2096
|
+
close();
|
|
2097
|
+
return;
|
|
2098
|
+
}
|
|
2099
|
+
if (event.key !== 'Enter' || event.isComposing === true) return;
|
|
2100
|
+
const tag = event.target?.tagName;
|
|
2101
|
+
if (tag !== 'INPUT' && tag !== 'TEXTAREA') return;
|
|
2102
|
+
event.preventDefault();
|
|
2103
|
+
void submit();
|
|
2104
|
+
},
|
|
2105
|
+
},
|
|
2106
|
+
h('div', { className: 'dsh-powerup-jobstop-head' }, h(StopIcon, { size: 12 }), t('jobStop.title')),
|
|
2107
|
+
h('div', { className: 'dsh-powerup-jobstop-label', title: target.job.label }, h('span', null, target.job.label)),
|
|
2108
|
+
h('label', { className: 'dsh-powerup-jobstop-field' },
|
|
2109
|
+
h('span', { className: 'dsh-powerup-jobstop-field-label' }, t('jobStop.reasonLabel')),
|
|
2110
|
+
h('input', {
|
|
2111
|
+
ref: inputRef,
|
|
2112
|
+
className: 'dsh-powerup-jobstop-input',
|
|
2113
|
+
type: 'text',
|
|
2114
|
+
value: reason,
|
|
2115
|
+
maxLength: JOB_STOP_REASON_MAX,
|
|
2116
|
+
placeholder: t('jobStop.reasonPlaceholder'),
|
|
2117
|
+
disabled: pending,
|
|
2118
|
+
onChange: (event) => setReason(event.target.value),
|
|
2119
|
+
}),
|
|
2120
|
+
),
|
|
2121
|
+
h('p', { className: 'dsh-powerup-jobstop-note' }, t('jobStop.reasonNote')),
|
|
2122
|
+
error === null ? null : h('p', { className: 'dsh-powerup-jobstop-error', role: 'alert' }, error),
|
|
2123
|
+
h('div', { className: 'dsh-powerup-jobstop-actions' },
|
|
2124
|
+
h('button', {
|
|
2125
|
+
type: 'button',
|
|
2126
|
+
className: 'dsh-powerup-jobstop-cancel',
|
|
2127
|
+
disabled: pending,
|
|
2128
|
+
onClick: close,
|
|
2129
|
+
}, t('jobStop.cancel')),
|
|
2130
|
+
h('button', {
|
|
2131
|
+
type: 'button',
|
|
2132
|
+
className: 'dsh-powerup-jobstop-confirm',
|
|
2133
|
+
disabled: pending,
|
|
2134
|
+
onClick: () => { void submit(); },
|
|
2135
|
+
}, pending ? t('jobStop.stopping') : t('jobStop.confirm')),
|
|
2136
|
+
));
|
|
2137
|
+
}
|
|
2138
|
+
|
|
1787
2139
|
/**
|
|
1788
2140
|
* The Plugins-page update control. It injects one icon button into each
|
|
1789
2141
|
* third-party card of the built-in "Installed plugins" group, then owns
|
|
@@ -2068,6 +2420,7 @@
|
|
|
2068
2420
|
title: packageDisplayTitle(pkg),
|
|
2069
2421
|
currentVersion: pkg.version ?? null,
|
|
2070
2422
|
installed: pkg.installed === true,
|
|
2423
|
+
enabled: pkg.enabled !== false,
|
|
2071
2424
|
phase: 'choose',
|
|
2072
2425
|
choices,
|
|
2073
2426
|
registryKey: choice.key,
|
|
@@ -2303,6 +2656,9 @@
|
|
|
2303
2656
|
const registry = registryValue(choice);
|
|
2304
2657
|
const spec = `${current.name}@${version}`;
|
|
2305
2658
|
const requestId = newRequestId();
|
|
2659
|
+
const previousVersion = typeof current.currentVersion === 'string' && current.currentVersion !== '' ? current.currentVersion : null;
|
|
2660
|
+
const previousEnabled = current.enabled !== false;
|
|
2661
|
+
let removedOld = false;
|
|
2306
2662
|
patch(token, { phase: 'working', step: current.self === true ? 'installing' : 'removing', error: null, formError: null, log: '', logLabel: spec });
|
|
2307
2663
|
if (current.self === true) {
|
|
2308
2664
|
// Power-Up cannot reinstall itself from its own client: removing
|
|
@@ -2334,7 +2690,9 @@
|
|
|
2334
2690
|
const removed = await manager.removeBundle(current.name);
|
|
2335
2691
|
if (tokenRef.current !== token) return;
|
|
2336
2692
|
if (!removed.ok) throw new Error(removed.error?.message ?? t('update.unknown'));
|
|
2337
|
-
if (removed.value.error !== undefined) throw new Error(operationReason(removed.value, t));
|
|
2693
|
+
if (removed.value.error !== undefined || removed.value.application === 'failed') throw new Error(operationReason(removed.value, t));
|
|
2694
|
+
if (removed.value.application === 'cancelled') throw new Error(t('update.cancelled'));
|
|
2695
|
+
removedOld = true;
|
|
2338
2696
|
patch(token, { step: 'checking' });
|
|
2339
2697
|
const checked = await manager.inspect(spec, { registry });
|
|
2340
2698
|
if (tokenRef.current !== token) return;
|
|
@@ -2364,7 +2722,40 @@
|
|
|
2364
2722
|
enabling: false,
|
|
2365
2723
|
});
|
|
2366
2724
|
} catch (error) {
|
|
2367
|
-
|
|
2725
|
+
const original = errorText(error) || t('update.unknown');
|
|
2726
|
+
// Before the first successful step the old copy is still installed;
|
|
2727
|
+
// after it, a failed inspect/install must put the old version back.
|
|
2728
|
+
if (!removedOld) {
|
|
2729
|
+
patch(token, { phase: 'error', step: null, error: original });
|
|
2730
|
+
return;
|
|
2731
|
+
}
|
|
2732
|
+
if (previousVersion === null) {
|
|
2733
|
+
patch(token, { phase: 'error', step: null, error: original, rollbackUnavailable: true });
|
|
2734
|
+
return;
|
|
2735
|
+
}
|
|
2736
|
+
patch(token, { phase: 'working', step: 'rollback', rollbackVersion: previousVersion, error: null, formError: null });
|
|
2737
|
+
try {
|
|
2738
|
+
const restored = await restorePreviousBundle(manager, {
|
|
2739
|
+
name: current.name,
|
|
2740
|
+
version: previousVersion,
|
|
2741
|
+
enabled: previousEnabled,
|
|
2742
|
+
registry,
|
|
2743
|
+
}, t);
|
|
2744
|
+
if (tokenRef.current !== token) return;
|
|
2745
|
+
if (restored.restartRequired === true) {
|
|
2746
|
+
recordPending({ name: current.name, version: restored.version, reason: restored.restartReason });
|
|
2747
|
+
}
|
|
2748
|
+
patch(token, { phase: 'error', step: null, error: original, rolledBack: true, rollbackVersion: restored.version });
|
|
2749
|
+
} catch (rollbackFailure) {
|
|
2750
|
+
if (tokenRef.current !== token) return;
|
|
2751
|
+
patch(token, {
|
|
2752
|
+
phase: 'error',
|
|
2753
|
+
step: null,
|
|
2754
|
+
error: original,
|
|
2755
|
+
rollbackVersion: previousVersion,
|
|
2756
|
+
rollbackError: errorText(rollbackFailure) || t('update.unknown'),
|
|
2757
|
+
});
|
|
2758
|
+
}
|
|
2368
2759
|
}
|
|
2369
2760
|
};
|
|
2370
2761
|
|
|
@@ -2709,7 +3100,9 @@
|
|
|
2709
3100
|
? t('update.step.removing')
|
|
2710
3101
|
: view.step === 'installing'
|
|
2711
3102
|
? t('update.step.installing', { version: view.logLabel ?? '' })
|
|
2712
|
-
:
|
|
3103
|
+
: view.step === 'rollback'
|
|
3104
|
+
? t('update.step.rollback', { version: view.rollbackVersion ?? view.currentVersion ?? '' })
|
|
3105
|
+
: t('update.step.checking');
|
|
2713
3106
|
return [
|
|
2714
3107
|
h('div', { key: 'status', className: 'dsh-powerup-update-status' },
|
|
2715
3108
|
h('span', { className: 'dsh-powerup-update-spinner', 'aria-hidden': 'true' }),
|
|
@@ -2773,6 +3166,18 @@
|
|
|
2773
3166
|
if (view.phase === 'error') {
|
|
2774
3167
|
return [
|
|
2775
3168
|
notice('error', h(WarnIcon, { size: 15 }), t('update.errorTitle'), view.error ?? t('update.unknown')),
|
|
3169
|
+
view.rolledBack === true
|
|
3170
|
+
? notice('success', h(CheckIcon, { size: 15 }), t('update.rollbackOkTitle'), t('update.rollbackOkDesc', {
|
|
3171
|
+
name: view.name,
|
|
3172
|
+
version: view.rollbackVersion ?? view.currentVersion ?? '',
|
|
3173
|
+
}))
|
|
3174
|
+
: null,
|
|
3175
|
+
view.rollbackError !== undefined && view.rollbackError !== null
|
|
3176
|
+
? notice('warn', h(WarnIcon, { size: 15 }), t('update.rollbackFailedTitle'), t('update.rollbackFailedDesc', { message: view.rollbackError }))
|
|
3177
|
+
: null,
|
|
3178
|
+
view.rollbackUnavailable === true
|
|
3179
|
+
? notice('warn', h(WarnIcon, { size: 15 }), t('update.rollbackFailedTitle'), t('update.rollbackUnavailable'))
|
|
3180
|
+
: null,
|
|
2776
3181
|
h('span', { key: 'name', className: 'dsh-powerup-update-name' }, view.name),
|
|
2777
3182
|
];
|
|
2778
3183
|
}
|
|
@@ -3101,6 +3506,16 @@
|
|
|
3101
3506
|
),
|
|
3102
3507
|
h('p', { className: 'dsh-powerup-update-note', style: { marginTop: '12px' } }, t('page.updateHow')),
|
|
3103
3508
|
),
|
|
3509
|
+
h('section', { className: 'dsh-powerup-card' },
|
|
3510
|
+
h('div', { className: 'dsh-powerup-card-head' },
|
|
3511
|
+
h('div', { className: 'dsh-powerup-card-icon' }, h(StopIcon, { size: 18 })),
|
|
3512
|
+
h('div', { className: 'dsh-powerup-card-copy' },
|
|
3513
|
+
h('h2', null, t('page.jobStopTitle')),
|
|
3514
|
+
h('p', null, t('page.jobStopDesc')),
|
|
3515
|
+
),
|
|
3516
|
+
),
|
|
3517
|
+
h('p', { className: 'dsh-powerup-update-note', style: { marginTop: '12px' } }, t('page.jobStopHow')),
|
|
3518
|
+
),
|
|
3104
3519
|
h('section', { className: 'dsh-powerup-card' },
|
|
3105
3520
|
h('h2', { className: 'dsh-powerup-section-title', style: { marginBottom: '10px' } }, t('page.howTitle')),
|
|
3106
3521
|
h('ol', { className: 'dsh-powerup-steps' },
|
|
@@ -3216,6 +3631,29 @@
|
|
|
3216
3631
|
console.warn('[dsh-powerup] plugin update registration failed:', error?.message ?? error);
|
|
3217
3632
|
}
|
|
3218
3633
|
}
|
|
3634
|
+
|
|
3635
|
+
// The stop-reason popover reads the Client jobs snapshot while the
|
|
3636
|
+
// built-in jobs panel owns the stop buttons. Wait for the jobs service
|
|
3637
|
+
// in a nested inject scope so a late-provided service still registers.
|
|
3638
|
+
if (typeof ctx.inject === 'function') {
|
|
3639
|
+
try {
|
|
3640
|
+
ctx.inject(['jobs'], (scope) => {
|
|
3641
|
+
const jobs = scope.get('jobs');
|
|
3642
|
+
const childSlots = scope.get('slots');
|
|
3643
|
+
if (jobs === undefined || childSlots === undefined || typeof childSlots.register !== 'function') return;
|
|
3644
|
+
scope.effect(
|
|
3645
|
+
() => childSlots.inject('shell.overlay', () => childSlots.register({
|
|
3646
|
+
name: 'shell.overlay',
|
|
3647
|
+
id: 'powerup-job-stop',
|
|
3648
|
+
order: 57,
|
|
3649
|
+
}, () => h(JobStopOverlay, { jobs, ctx: scope }))),
|
|
3650
|
+
'dsh-powerup: job stop reason',
|
|
3651
|
+
);
|
|
3652
|
+
});
|
|
3653
|
+
} catch (error) {
|
|
3654
|
+
console.warn('[dsh-powerup] job stop registration failed:', error?.message ?? error);
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3219
3657
|
}
|
|
3220
3658
|
|
|
3221
3659
|
return {
|
|
@@ -3231,6 +3669,9 @@
|
|
|
3231
3669
|
PowerUpPage,
|
|
3232
3670
|
PowerUpOverlay,
|
|
3233
3671
|
PluginUpdateOverlay,
|
|
3672
|
+
JobStopOverlay,
|
|
3673
|
+
stopButtonLabel,
|
|
3674
|
+
resolveStopTarget,
|
|
3234
3675
|
ensureUpdateButtons,
|
|
3235
3676
|
ensureRestartBar,
|
|
3236
3677
|
updateButtonLabel,
|
|
@@ -3259,6 +3700,7 @@
|
|
|
3259
3700
|
normalizeVersionInput,
|
|
3260
3701
|
inspectReason,
|
|
3261
3702
|
operationReason,
|
|
3703
|
+
restorePreviousBundle,
|
|
3262
3704
|
},
|
|
3263
3705
|
};
|
|
3264
3706
|
},
|
package/index.js
CHANGED
|
@@ -9,15 +9,21 @@
|
|
|
9
9
|
* GET /dsh-powerup/api/audit → profile bundles newer than this Host
|
|
10
10
|
* POST /dsh-powerup/api/self-update → removes and reinstalls this plugin
|
|
11
11
|
* in the background, surviving the
|
|
12
|
-
* plugin's own unload
|
|
12
|
+
* plugin's own unload; a failed step
|
|
13
|
+
* reinstalls the version that was
|
|
14
|
+
* removed
|
|
15
|
+
* POST /dsh-powerup/api/job-kill → stops one background job with an
|
|
16
|
+
* optional human reason
|
|
13
17
|
*
|
|
14
18
|
* The Client half drives other plugins' installation through the built-in
|
|
15
|
-
* `pluginManager` Remote. Only the process restart
|
|
16
|
-
* need Host code.
|
|
19
|
+
* `pluginManager` Remote. Only the process restart, the self-update handoff,
|
|
20
|
+
* and the stop-with-reason kill need Host code: the built-in `job.kill` Remote
|
|
21
|
+
* hard-codes `cancelled by the user`, while the registry's own `kill` accepts
|
|
22
|
+
* a reason that settlement merges into the job's `detail` line.
|
|
17
23
|
*/
|
|
18
24
|
|
|
19
25
|
import { randomUUID } from 'node:crypto';
|
|
20
|
-
import { appendFileSync, mkdirSync, statSync } from 'node:fs';
|
|
26
|
+
import { appendFileSync, mkdirSync, readFileSync, statSync } from 'node:fs';
|
|
21
27
|
import { dirname, join } from 'node:path';
|
|
22
28
|
import { homedir } from 'node:os';
|
|
23
29
|
import { describeRestart, requestRestart } from './lib/restart.js';
|
|
@@ -37,6 +43,24 @@ const BODY_LIMIT = 16 * 1024;
|
|
|
37
43
|
/** The moment this Host process started; a profile file newer than it may await a restart. */
|
|
38
44
|
const HOST_STARTED_AT = Date.now() - process.uptime() * 1000;
|
|
39
45
|
|
|
46
|
+
/**
|
|
47
|
+
* The version this Host module was loaded from. A self-update removes the only
|
|
48
|
+
* installed copy before inspecting the target, so a failure must reinstall this
|
|
49
|
+
* exact version instead of leaving Power-Up missing.
|
|
50
|
+
* @returns {string}
|
|
51
|
+
*/
|
|
52
|
+
function selfVersion() {
|
|
53
|
+
try {
|
|
54
|
+
const manifest = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
|
|
55
|
+
return typeof manifest?.version === 'string' ? manifest.version : '';
|
|
56
|
+
} catch {
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Captured at load time, before self-update touches the package directory. */
|
|
62
|
+
const SELF_VERSION = selfVersion();
|
|
63
|
+
|
|
40
64
|
/**
|
|
41
65
|
* The desktop profile directory, resolved without depending on the shell tool.
|
|
42
66
|
* @returns {string}
|
|
@@ -167,6 +191,40 @@ function appendSelfUpdateLog(line) {
|
|
|
167
191
|
}
|
|
168
192
|
}
|
|
169
193
|
|
|
194
|
+
/** The reason core records for a human kill; a custom reason is appended. */
|
|
195
|
+
const HUMAN_KILL_REASON = 'cancelled by the user';
|
|
196
|
+
|
|
197
|
+
/** Upper bound for the optional reason, in characters. */
|
|
198
|
+
const STOP_REASON_LIMIT = 200;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Normalize the optional reason typed in the stop dialog. Control characters
|
|
202
|
+
* and line breaks collapse into spaces so the reason stays one line inside the
|
|
203
|
+
* completion notice.
|
|
204
|
+
* @param {unknown} value
|
|
205
|
+
* @returns {string} the cleaned reason ('' when nothing was typed)
|
|
206
|
+
*/
|
|
207
|
+
function normalizeStopReason(value) {
|
|
208
|
+
if (typeof value !== 'string') return '';
|
|
209
|
+
return value
|
|
210
|
+
.replace(/[\u0000-\u001f\u007f]+/gu, ' ')
|
|
211
|
+
.replace(/\s+/gu, ' ')
|
|
212
|
+
.trim()
|
|
213
|
+
.slice(0, STOP_REASON_LIMIT);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* The reason recorded with a human kill. An empty custom reason keeps the
|
|
218
|
+
* core phrase; a typed one appends to it, so the injected completion notice
|
|
219
|
+
* reads `cancelled by the user: <reason>`.
|
|
220
|
+
* @param {unknown} value
|
|
221
|
+
* @returns {string}
|
|
222
|
+
*/
|
|
223
|
+
function killReasonFor(value) {
|
|
224
|
+
const reason = normalizeStopReason(value);
|
|
225
|
+
return reason === '' ? HUMAN_KILL_REASON : `${HUMAN_KILL_REASON}: ${reason}`;
|
|
226
|
+
}
|
|
227
|
+
|
|
170
228
|
/**
|
|
171
229
|
* The concrete versions the update dialog accepts. The Client applies the same
|
|
172
230
|
* shape before it removes anything; this is the Host-side guard.
|
|
@@ -187,12 +245,13 @@ function normalizeVersion(value) {
|
|
|
187
245
|
* @param {import('@deepseek-ai/cordis').Context} ctx
|
|
188
246
|
* @param {string} version
|
|
189
247
|
* @param {string | null} registry
|
|
190
|
-
* @param {{ manager?: unknown, log?: (line: string) => void }} [options]
|
|
191
|
-
* @returns {Promise<{ ok: boolean, stage?: string, error?: string }>}
|
|
248
|
+
* @param {{ manager?: unknown, log?: (line: string) => void, previousVersion?: string }} [options]
|
|
249
|
+
* @returns {Promise<{ ok: boolean, stage?: string, error?: string, rolledBack?: boolean, rollbackError?: string }>}
|
|
192
250
|
*/
|
|
193
251
|
export async function performSelfUpdate(ctx, version, registry, options = {}) {
|
|
194
252
|
const log = options.log ?? appendSelfUpdateLog;
|
|
195
253
|
const manager = options.manager ?? ctx?.get?.('pluginManager');
|
|
254
|
+
const previousVersion = typeof options.previousVersion === 'string' ? options.previousVersion : SELF_VERSION;
|
|
196
255
|
if (manager === undefined || typeof manager.installBundle !== 'function') {
|
|
197
256
|
log('self-update: pluginManager service is unavailable');
|
|
198
257
|
return { ok: false, stage: 'manager', error: 'pluginManager service is unavailable' };
|
|
@@ -200,11 +259,16 @@ export async function performSelfUpdate(ctx, version, registry, options = {}) {
|
|
|
200
259
|
const spec = `${MODULE_ID}@${version}`;
|
|
201
260
|
log(`self-update: start ${spec} registry=${String(registry)}`);
|
|
202
261
|
let stage = 'remove';
|
|
262
|
+
let removedOld = false;
|
|
203
263
|
try {
|
|
204
264
|
const removed = await manager.removeBundle(MODULE_ID);
|
|
205
265
|
if (removed?.error !== undefined) {
|
|
206
266
|
throw new Error(`remove failed: ${removed.error.code ?? 'error'} ${removed.error.diagnostic ?? ''}`.trim());
|
|
207
267
|
}
|
|
268
|
+
if (removed?.application === 'cancelled' || removed?.application === 'failed') {
|
|
269
|
+
throw new Error(`remove ${removed.application}`);
|
|
270
|
+
}
|
|
271
|
+
removedOld = true;
|
|
208
272
|
log(`self-update: removed (application=${removed?.application ?? 'unknown'})`);
|
|
209
273
|
stage = 'inspect';
|
|
210
274
|
const checked = await manager.inspect(spec, { registry });
|
|
@@ -218,15 +282,54 @@ export async function performSelfUpdate(ctx, version, registry, options = {}) {
|
|
|
218
282
|
registry,
|
|
219
283
|
requestId: randomUUID(),
|
|
220
284
|
});
|
|
221
|
-
if (installed?.error !== undefined) {
|
|
222
|
-
|
|
285
|
+
if (installed?.error !== undefined || installed?.application === 'failed') {
|
|
286
|
+
const detail = installed?.error === undefined
|
|
287
|
+
? ''
|
|
288
|
+
: `${installed.error.code ?? 'error'} ${installed.error.diagnostic ?? ''}`.trim();
|
|
289
|
+
throw new Error(`install failed${detail === '' ? '' : `: ${detail}`}`);
|
|
223
290
|
}
|
|
224
291
|
log(`self-update: installed (application=${installed?.application ?? 'unknown'}, version=${installed?.version ?? 'unknown'})`);
|
|
225
292
|
return { ok: true, stage: 'install' };
|
|
226
293
|
} catch (error) {
|
|
227
294
|
const message = String(error?.message ?? error);
|
|
228
295
|
log(`self-update: failed at ${stage}: ${message}${error?.stack === undefined ? '' : `\n${error.stack}`}`);
|
|
229
|
-
|
|
296
|
+
// Removing the old copy is the first step, so any later failure leaves
|
|
297
|
+
// Power-Up uninstalled. Put the running version back instead.
|
|
298
|
+
let rolledBack = false;
|
|
299
|
+
let rollbackError;
|
|
300
|
+
if (removedOld) {
|
|
301
|
+
if (previousVersion === '') {
|
|
302
|
+
rollbackError = 'the previous version is unknown';
|
|
303
|
+
log('self-update: cannot roll back: previous version unknown');
|
|
304
|
+
} else {
|
|
305
|
+
log(`self-update: rolling back to ${MODULE_ID}@${previousVersion}`);
|
|
306
|
+
try {
|
|
307
|
+
const restored = await manager.installBundle(`${MODULE_ID}@${previousVersion}`, {
|
|
308
|
+
enabled: true,
|
|
309
|
+
registry,
|
|
310
|
+
requestId: randomUUID(),
|
|
311
|
+
});
|
|
312
|
+
if (restored?.error !== undefined || restored?.application === 'failed') {
|
|
313
|
+
const detail = restored?.error === undefined
|
|
314
|
+
? ''
|
|
315
|
+
: `${restored.error.code ?? 'error'} ${restored.error.diagnostic ?? ''}`.trim();
|
|
316
|
+
throw new Error(`rollback install failed${detail === '' ? '' : `: ${detail}`}`);
|
|
317
|
+
}
|
|
318
|
+
rolledBack = true;
|
|
319
|
+
log(`self-update: rolled back to ${previousVersion} (application=${restored?.application ?? 'unknown'})`);
|
|
320
|
+
} catch (rollbackFailure) {
|
|
321
|
+
rollbackError = String(rollbackFailure?.message ?? rollbackFailure);
|
|
322
|
+
log(`self-update: rollback failed: ${rollbackError}`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return {
|
|
327
|
+
ok: false,
|
|
328
|
+
stage,
|
|
329
|
+
error: message,
|
|
330
|
+
rolledBack,
|
|
331
|
+
...(rollbackError === undefined ? {} : { rollbackError }),
|
|
332
|
+
};
|
|
230
333
|
}
|
|
231
334
|
}
|
|
232
335
|
|
|
@@ -243,11 +346,45 @@ async function handle(req, res, ctx) {
|
|
|
243
346
|
|
|
244
347
|
const url = new URL(req.url ?? ROUTE, 'http://localhost');
|
|
245
348
|
const op = url.pathname.slice(ROUTE.length).replace(/^\/+/u, '') || url.searchParams.get('op') || '';
|
|
246
|
-
if (op !== '' && op !== 'restart' && op !== 'self-update' && op !== 'audit') {
|
|
349
|
+
if (op !== '' && op !== 'restart' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill') {
|
|
247
350
|
sendJson(res, { ok: false, error: 'not-found' }, 404);
|
|
248
351
|
return;
|
|
249
352
|
}
|
|
250
353
|
|
|
354
|
+
if (op === 'job-kill') {
|
|
355
|
+
if (req.method !== 'POST') {
|
|
356
|
+
sendJson(res, { ok: false, error: 'method-not-allowed' }, 405);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
let body;
|
|
360
|
+
try {
|
|
361
|
+
body = await readJsonBody(req);
|
|
362
|
+
} catch (error) {
|
|
363
|
+
sendJson(res, { ok: false, error: String(error?.message ?? error) }, 400);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const jobId = typeof body?.jobId === 'string' ? body.jobId.trim() : '';
|
|
367
|
+
const sessionId = typeof body?.sessionId === 'string' ? body.sessionId.trim() : '';
|
|
368
|
+
if (jobId === '' || sessionId === '') {
|
|
369
|
+
sendJson(res, { ok: false, code: 'invalid-request', error: 'jobId and sessionId are required' }, 400);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const jobs = ctx?.get?.('jobs');
|
|
373
|
+
if (jobs === undefined || typeof jobs.kill !== 'function') {
|
|
374
|
+
sendJson(res, { ok: false, code: 'jobs-unavailable', error: 'jobs service is unavailable' }, 503);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
try {
|
|
378
|
+
// The registry's owner fence checks that this session can see the job,
|
|
379
|
+
// and records the reason so settlement merges it into `detail`.
|
|
380
|
+
const outcome = jobs.kill(jobId, sessionId, killReasonFor(body?.reason));
|
|
381
|
+
sendJson(res, { ok: true, outcome });
|
|
382
|
+
} catch (error) {
|
|
383
|
+
sendJson(res, { ok: false, code: 'kill-failed', error: String(error?.message ?? error) }, 404);
|
|
384
|
+
}
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
|
|
251
388
|
if (op === 'audit') {
|
|
252
389
|
if (req.method !== 'GET') {
|
|
253
390
|
sendJson(res, { ok: false, error: 'method-not-allowed' }, 405);
|
|
@@ -334,4 +471,19 @@ export function apply(ctx) {
|
|
|
334
471
|
}
|
|
335
472
|
|
|
336
473
|
/** Exported for tests only; the Host never reads this. */
|
|
337
|
-
export const __test = {
|
|
474
|
+
export const __test = {
|
|
475
|
+
handle,
|
|
476
|
+
isLoopback,
|
|
477
|
+
sameOrigin,
|
|
478
|
+
performSelfUpdate,
|
|
479
|
+
normalizeVersion,
|
|
480
|
+
normalizeStopReason,
|
|
481
|
+
killReasonFor,
|
|
482
|
+
selfVersion,
|
|
483
|
+
auditProfileBundles,
|
|
484
|
+
profileDirectory,
|
|
485
|
+
HOST_STARTED_AT,
|
|
486
|
+
SELF_VERSION,
|
|
487
|
+
ROUTE,
|
|
488
|
+
MODULE_ID,
|
|
489
|
+
};
|
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
|
|
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.
|
|
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.1",
|
|
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": {
|