@restregular/dsh-powerup 0.8.8 → 0.8.9

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
@@ -6,7 +6,7 @@ The upgrades include a **right-click action menu in the Trajectory view**, a
6
6
  data, an optional **stop reason for background jobs**, an in-place
7
7
  **plugin installer**, and a **sidebar launcher** that turns the left sidebar's
8
8
  panel list into an adaptive icon grid with drag sorting, folders, a
9
- back-to-conversation tile and a restart-DSH tile.
9
+ back-to-conversation tile, and restart/close tiles.
10
10
 
11
11
  ## Install
12
12
 
@@ -112,20 +112,28 @@ entries other plugins add) become an icon grid instead of a one-per-row list:
112
112
  menu in a `Menu` root `<span>` around the row button (not a div), so the
113
113
  launcher resolves any non-button child that owns a direct button as that
114
114
  entry; it gets the same stacked icon/label tile and can be dragged like any
115
- other panel. It never folds into a folder.
115
+ other panel, including into a folder.
116
116
  - **A synthetic "Back to conversation" tile.** Power-Up adds one extra tile of
117
117
  its own (chat glyph + label) that calls `layout.selectPanel(null)` to return
118
- to the Conversation; it highlights when no global panel is selected, can be
119
- placed anywhere by dragging, and never joins a folder either.
118
+ to the Conversation; it highlights when no global panel is selected and can be
119
+ placed anywhere by dragging, including into a folder.
120
120
  - **A synthetic "Restart DSH" tile.** A second Power-Up tile (a ring with the
121
121
  arrowhead tangent to the top, i.e. the arrow lines up with the arc) plus
122
122
  `重启` / `Restart` opens the same restart confirmation the pending-restart
123
123
  bar uses: the tile only calls into that React prompt, so there is one dialog,
124
124
  one capability read (`GET /dsh-powerup/api/restart`) and one set of copy. The
125
125
  confirmation explains that running tasks are interrupted; only a runtime that
126
- can relaunch itself (the desktop app) enables the confirm button. The tile
127
- drags like any other, never joins a folder, and is hidden with the rest of
128
- the grid in the collapsed rail.
126
+ can relaunch itself (the desktop app) enables the confirm button.
127
+ - **A synthetic "Close DSH" tile.** A power-symbol tile plus `关闭` / `Close`
128
+ opens a close confirmation (same dialog and copy conventions as restart) and
129
+ posts to `GET/POST /dsh-powerup/api/close`, which ends the Electron app without
130
+ relaunching it. Like the other synthetic tiles it drags anywhere, including
131
+ into a folder.
132
+ - **Folders take every tile.** Host panels, the host's "More" entry and
133
+ Power-Up's own tiles all merge the same way: drop one onto the middle of
134
+ another, or onto a folder, and it becomes a member; drag it out of the flyout
135
+ to put it back on the grid. The three synthetic tiles are hidden with the rest
136
+ of the grid in the collapsed rail.
129
137
  - **Ungroup expands in place.** Dissolving a folder puts its icons back on the
130
138
  grid exactly where the folder sat, in the folder's own order — nothing jumps
131
139
  to the end of the grid.
@@ -231,21 +239,22 @@ fiber is unloaded. The panel closes; refresh the page when the install finishes.
231
239
  rows are resolved by shape — a direct `<button>`, or a wrapper (the More
232
240
  launcher's `Menu` root `<span>`) whose direct child is that button — because
233
241
  the wrapper element differs between the panel rows and the more menu.
234
- - **The DOM launcher borrows the React restart prompt.** The launcher is plain
235
- DOM and cannot render React, so the Plugins overlay publishes its
236
- `openRestart` in a module-level bridge while it is mounted; the synthetic
237
- restart tile calls that, and gets the exact confirmation, capability check and
238
- localized copy the pending-restart bar uses — nothing is duplicated. If the
239
- overlay is not mounted at all (a host without `remote.pluginManager`), the
240
- tile falls back to a browser confirm over the same Host route.
242
+ - **The DOM launcher borrows the React app-action prompts.** The launcher is
243
+ plain DOM and cannot render React, so the Plugins overlay publishes
244
+ `openRestart` and `openClose` in module-level bridges while it is mounted; the
245
+ synthetic restart/close tiles call them, and get the exact confirmations,
246
+ capability checks and localized copy the pending-restart bar uses — nothing is
247
+ duplicated. If the overlay is not mounted at all (a host without
248
+ `remote.pluginManager`), each tile falls back to a browser confirm over the
249
+ same Host route.
241
250
  - **Every sync write is idempotent.** The launcher observes its own `<nav>`
242
251
  with a `MutationObserver`, so a write that changes a watched subtree on every
243
252
  sync turns into an infinite loop — and a loop rebuilds the folder flyout
244
253
  continuously, which makes normal clicks miss (the node under the pointer is
245
254
  replaced between `pointerdown` and `click`). Setting `textContent` to the same
246
- string still emits a `childList` mutation, so the synthetic chat/restart tiles
247
- only write their labels when they actually changed, folder tiles rebuild only
248
- when
255
+ string still emits a `childList` mutation, so the synthetic chat/restart/close
256
+ tiles only write their labels when they actually changed, folder tiles rebuild
257
+ only when
249
258
  their signature changed, and the flyout re-renders only when its roster or
250
259
  name changed. A
251
260
  `MutationObserver` re-applies that after every host render, and the module
@@ -260,9 +269,9 @@ fiber is unloaded. The panel closes; refresh the page when the install finishes.
260
269
  `[data-plugin-group="bundles"] [data-plugin-package]` card and re-asserts it
261
270
  after React renders. Version listing is a plain registry `GET`; removal and
262
271
  installation use the same `remote.pluginManager` calls as **Add plugin**. The
263
- Host adds two loopback-only routes: `/dsh-powerup/api/restart` for the
264
- process restart, and `/dsh-powerup/api/self-update` for the self-install
265
- handoff.
272
+ Host adds three loopback-only routes: `/dsh-powerup/api/restart` for the
273
+ process restart, `/dsh-powerup/api/close` for closing the app without a
274
+ relaunch, and `/dsh-powerup/api/self-update` for the self-install handoff.
266
275
  - **Power-Up's own install outlives its unload.** The Host route sends its
267
276
  answer, then a timer starts `removeBundle` → `inspect` →
268
277
  `installBundle(enabled: true)` through the built-in manager service. Removing
package/client.js CHANGED
@@ -69,7 +69,7 @@
69
69
 
70
70
  const NS = 'dsh-powerup';
71
71
  const SETTINGS_KEY = 'dsh-powerup:settings:v1';
72
- const VERSION = '0.8.8';
72
+ const VERSION = '0.8.9';
73
73
  const MENU_GAP = 8;
74
74
  const MENU_WIDTH = 248;
75
75
  /** Reference scheme understood by the Host's `powerup_step_read` tool. */
@@ -107,7 +107,7 @@
107
107
  'page.jobStopDesc': '在会话顶部的后台任务面板里点停止按钮时,可以顺手填写停止原因;原因会附加在任务结束后注入会话的提示里。',
108
108
  'page.jobStopHow': '打开任意会话,点顶部的「后台任务」面板,在运行中的任务右侧点停止,填写原因(可留空)后确认。',
109
109
  'page.launcherTitle': '侧边栏启动器',
110
- 'page.launcherDesc': '把左侧边栏的面板按钮变成自适应图标网格:列数跟着侧边栏宽度走,图标在上、文字在下;拖动图标可以排序,把一个图标拖到另一个图标的中间就会合成一个分组(像 Windows 开始菜单的文件夹),点分组会以浮层弹出里面的图标。网格里自带「返回会话」和「重启 DSH」两个按钮。',
110
+ 'page.launcherDesc': '把左侧边栏的面板按钮变成自适应图标网格:列数跟着侧边栏宽度走,图标在上、文字在下;拖动图标可以排序,把一个图标拖到另一个图标的中间就会合成一个分组(像 Windows 开始菜单的文件夹),点分组会以浮层弹出里面的图标。网格里自带「返回会话」「重启 DSH」「关闭 DSH」三个按钮,它们和「更多」一样也能拖进分组。',
111
111
  'page.launcherToggle': '启用图标网格',
112
112
  'page.launcherToggleHint': '关闭后侧边栏恢复宿主原本的列表样式;排序与分组仍会保留。',
113
113
  'launcher.groupDefault': '分组',
@@ -118,6 +118,15 @@
118
118
  'launcher.backToConversation': '返回会话',
119
119
  'launcher.restart': '重启',
120
120
  'launcher.restartHint': '重启 DSH(正在运行的任务会中断)',
121
+ 'launcher.close': '关闭',
122
+ 'launcher.closeHint': '关闭 DSH(正在运行的任务会中断)',
123
+ 'close.title': '关闭 DSH?',
124
+ 'close.desc': '关闭会退出 DSH,正在运行的任务会中断。',
125
+ 'close.cancel': '取消',
126
+ 'close.confirm': '关闭 DSH',
127
+ 'close.closing': 'DSH 正在关闭…',
128
+ 'close.failed': '关闭请求失败:{message}',
129
+ 'close.unsupported': '当前运行方式无法自动关闭:{reason}',
121
130
  'page.footer': 'Power-Up {version} · 设置在浏览器本地保存',
122
131
  'page.localOnly': '仅影响当前浏览器',
123
132
  'action.copy': '复制内容',
@@ -296,7 +305,7 @@
296
305
  '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.',
297
306
  'page.jobStopHow': 'Open a session, expand the background jobs panel, press stop on a running job, type a reason (optional), then confirm.',
298
307
  'page.launcherTitle': 'Sidebar launcher',
299
- 'page.launcherDesc': 'Turns the left sidebar panel buttons into an adaptive icon grid: the column count follows the sidebar width, icons sit above their labels, icons can be dragged to reorder, dropping one icon onto the middle of another forms a folder (like a Windows Start menu folder), and clicking a folder opens its contents in a flyout. The grid also carries two built-in buttons: back to conversation and restart DSH.',
308
+ 'page.launcherDesc': 'Turns the left sidebar panel buttons into an adaptive icon grid: the column count follows the sidebar width, icons sit above their labels, icons can be dragged to reorder, dropping one icon onto the middle of another forms a folder (like a Windows Start menu folder), and clicking a folder opens its contents in a flyout. The grid also carries three built-in buttons — back to conversation, restart DSH and close DSH — and they, like the host\'s "more" entry, can be dragged into a folder too.',
300
309
  'page.launcherToggle': 'Enable the icon grid',
301
310
  'page.launcherToggleHint': 'When off, the sidebar keeps the host list; order and folders are remembered.',
302
311
  'launcher.groupDefault': 'Group',
@@ -307,6 +316,15 @@
307
316
  'launcher.backToConversation': 'Back to conversation',
308
317
  'launcher.restart': 'Restart',
309
318
  'launcher.restartHint': 'Restart DSH (running tasks are interrupted)',
319
+ 'launcher.close': 'Close',
320
+ 'launcher.closeHint': 'Close DSH (running tasks are interrupted)',
321
+ 'close.title': 'Close DSH?',
322
+ 'close.desc': 'Closing quits DSH; running tasks are interrupted.',
323
+ 'close.cancel': 'Cancel',
324
+ 'close.confirm': 'Close DSH',
325
+ 'close.closing': 'DSH is closing…',
326
+ 'close.failed': 'Close request failed: {message}',
327
+ 'close.unsupported': 'This runtime cannot close itself: {reason}',
310
328
  'page.footer': 'Power-Up {version} · Settings are stored in this browser',
311
329
  'page.localOnly': 'This browser only',
312
330
  'action.copy': 'Copy content',
@@ -556,6 +574,8 @@
556
574
  const LAUNCHER_CHAT_KEY = '__chat';
557
575
  /** Tile key of the Power-Up "restart DSH" tile. */
558
576
  const LAUNCHER_RESTART_KEY = '__restart';
577
+ /** Tile key of the Power-Up "close DSH" tile. */
578
+ const LAUNCHER_CLOSE_KEY = '__close';
559
579
  /** 16-grid chat glyph for the synthetic "back to conversation" tile. */
560
580
  const LAUNCHER_CHAT_ICON = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false"><path d="M2.8 3.4h10.4v6.8H7.4L4.4 12.8v-2.6H2.8V3.4Z" stroke="currentColor" stroke-width="1.3" stroke-linejoin="round"/></svg>';
561
581
  /**
@@ -564,6 +584,8 @@
564
584
  * the opening (the previous Material glyph read as detached).
565
585
  */
566
586
  const LAUNCHER_RESTART_ICON = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false"><path d="M11.94 5.34A4.75 4.75 0 1 1 8 3.25" stroke="currentColor" stroke-width="1.55" stroke-linecap="round"/><path d="M7.85 1.45 11 3.25 7.85 5.05Z" fill="currentColor"/></svg>';
587
+ /** 16-grid power glyph for the synthetic "close DSH" tile. */
588
+ const LAUNCHER_CLOSE_ICON = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false"><path d="M8 2.9v5.2" stroke="currentColor" stroke-width="1.55" stroke-linecap="round"/><path d="M5.77 3.81A4.75 4.75 0 1 0 10.23 3.81" stroke="currentColor" stroke-width="1.55" stroke-linecap="round"/></svg>';
567
589
  /**
568
590
  * Bridge to the Plugins overlay's React restart prompt. The launcher is
569
591
  * plain DOM and cannot render React, so the overlay publishes its opener
@@ -571,35 +593,61 @@
571
593
  * the same confirmation, capability check and locale-aware copy.
572
594
  */
573
595
  const restartPromptBridge = { open: null };
596
+ /** Same bridge for the "close DSH" confirmation. */
597
+ const closePromptBridge = { open: null };
574
598
 
575
599
  /**
576
600
  * Last resort for a host where the Plugins overlay (and with it the
577
- * React restart prompt) is not mounted: confirm with the browser and ask
578
- * the Host restart route directly. Unreachable on a normal desktop/web
579
- * host, where `remote.pluginManager` mounts the overlay.
601
+ * React app-action prompt) is not mounted: confirm with the browser and
602
+ * ask the Host route directly. Unreachable on a normal desktop/web host,
603
+ * where `remote.pluginManager` mounts the overlay.
604
+ *
605
+ * @param {{ api: string, action: 'restart' | 'close', titleKey: string, descKey: string, unsupportedKey: string, failedKey: string }} options
580
606
  */
581
- async function restartWithoutPrompt() {
607
+ async function appActionWithoutPrompt(options) {
582
608
  const t = (key, params) => translateCurrent(key, params);
583
609
  try {
584
- const capability = await fetch('/dsh-powerup/api/restart', { headers: { accept: 'application/json' } })
610
+ const capability = await fetch(options.api, { headers: { accept: 'application/json' } })
585
611
  .then((response) => response.json());
586
612
  if (capability?.supported !== true) {
587
- window.alert(t('update.restartUnsupported', { reason: capability?.reason ?? '' }));
613
+ window.alert(t(options.unsupportedKey, { reason: capability?.reason ?? '' }));
588
614
  return;
589
615
  }
590
- if (window.confirm(t('restart.title') + ' ' + t('restart.desc')) !== true) return;
591
- const response = await fetch('/dsh-powerup/api/restart', {
616
+ if (window.confirm(t(options.titleKey) + ' ' + t(options.descKey)) !== true) return;
617
+ const response = await fetch(options.api, {
592
618
  method: 'POST',
593
619
  headers: { 'content-type': 'application/json' },
594
- body: JSON.stringify({ action: 'restart' }),
620
+ body: JSON.stringify({ action: options.action }),
595
621
  });
596
622
  const data = await response.json().catch(() => null);
597
623
  if (!response.ok || data?.ok !== true) throw new Error(data?.error ?? 'HTTP ' + response.status);
598
624
  } catch (error) {
599
- window.alert(t('update.restartFailed', { message: error?.message ?? String(error) }));
625
+ window.alert(t(options.failedKey, { message: error?.message ?? String(error) }));
600
626
  }
601
627
  }
602
628
 
629
+ function restartWithoutPrompt() {
630
+ return appActionWithoutPrompt({
631
+ api: UPDATE_API,
632
+ action: 'restart',
633
+ titleKey: 'restart.title',
634
+ descKey: 'restart.desc',
635
+ unsupportedKey: 'update.restartUnsupported',
636
+ failedKey: 'update.restartFailed',
637
+ });
638
+ }
639
+
640
+ function closeWithoutPrompt() {
641
+ return appActionWithoutPrompt({
642
+ api: CLOSE_API,
643
+ action: 'close',
644
+ titleKey: 'close.title',
645
+ descKey: 'close.desc',
646
+ unsupportedKey: 'close.unsupported',
647
+ failedKey: 'close.failed',
648
+ });
649
+ }
650
+
603
651
  function launcherGroupEntry(groupId) {
604
652
  return LAUNCHER_GROUP_PREFIX + groupId;
605
653
  }
@@ -614,16 +662,6 @@
614
662
  return 'g' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
615
663
  }
616
664
 
617
- /**
618
- * Synthetic tiles (back to conversation, restart DSH, the host's "more"
619
- * launcher) always live directly on the grid and can never join a folder.
620
- * @param {string} key tile key
621
- * @returns {boolean}
622
- */
623
- function isLauncherSpecialKey(key) {
624
- return key === LAUNCHER_CHAT_KEY || key === LAUNCHER_RESTART_KEY || key === LAUNCHER_MORE_KEY;
625
- }
626
-
627
665
  /**
628
666
  * Reconcile the saved launcher state with the panels that exist right now.
629
667
  * Unknown panel keys (unregistered, unpinned) are dropped; panels without
@@ -645,7 +683,6 @@
645
683
  const list = Array.isArray(value.items) ? value.items : [];
646
684
  for (const key of list) {
647
685
  if (typeof key !== 'string' || !known.has(key) || assigned.has(key)) continue;
648
- if (key.startsWith('__')) continue;
649
686
  assigned.add(key);
650
687
  items.push(key);
651
688
  }
@@ -702,7 +739,7 @@
702
739
  const index = source.indexOf(folderEntry);
703
740
  const members = [];
704
741
  for (const key of Array.isArray(items) ? items : []) {
705
- if (typeof key !== 'string' || key === '' || key.startsWith('__')) continue;
742
+ if (typeof key !== 'string' || key === '') continue;
706
743
  if (list.includes(key) || members.includes(key)) continue;
707
744
  members.push(key);
708
745
  }
@@ -737,6 +774,7 @@
737
774
  const listPanels = typeof options.listPanels === 'function' ? options.listPanels : () => [];
738
775
  const selectConversation = typeof options.selectConversation === 'function' ? options.selectConversation : () => {};
739
776
  const openRestart = typeof options.openRestart === 'function' ? options.openRestart : () => false;
777
+ const openClose = typeof options.openClose === 'function' ? options.openClose : () => false;
740
778
 
741
779
  let nav = null;
742
780
  let docObserver = null;
@@ -751,6 +789,7 @@
751
789
  let folderButtons = new Map();
752
790
  let chatButton = null;
753
791
  let restartButton = null;
792
+ let closeButton = null;
754
793
  let dropLine = null;
755
794
  let drag = null;
756
795
  let popup = null;
@@ -860,7 +899,8 @@
860
899
  for (const child of [...container.children]) {
861
900
  if (child.hasAttribute('data-powerup-folder')
862
901
  || child.hasAttribute('data-powerup-chat')
863
- || child.hasAttribute('data-powerup-restart')) continue;
902
+ || child.hasAttribute('data-powerup-restart')
903
+ || child.hasAttribute('data-powerup-close')) continue;
864
904
  if (typeof child.classList === 'object' && child.classList !== null && child.classList.contains('dsh-powerup-drop-line')) continue;
865
905
  let gridEl = child;
866
906
  let buttonEl = null;
@@ -1019,6 +1059,80 @@
1019
1059
  return button;
1020
1060
  }
1021
1061
 
1062
+ /**
1063
+ * The synthetic "close DSH" tile. Like the restart tile it opens the
1064
+ * React confirmation owned by the Plugins overlay (same dialog, its own
1065
+ * route), so closing asks before ending the app.
1066
+ */
1067
+ function ensureCloseButton() {
1068
+ if (closeButton !== null && closeButton.isConnected === true) return closeButton;
1069
+ const button = createSyntheticTile('dsh-powerup-close', 'data-powerup-close', LAUNCHER_CLOSE_ICON);
1070
+ button.addEventListener('click', (event) => {
1071
+ event.preventDefault();
1072
+ event.stopPropagation();
1073
+ if (drag !== null && drag.active) return;
1074
+ closePopup();
1075
+ try {
1076
+ if (openClose() === false) warn('the close prompt is not available in this host');
1077
+ } catch (error) {
1078
+ warn('close prompt could not be opened:', error);
1079
+ }
1080
+ });
1081
+ nav.appendChild(button);
1082
+ closeButton = button;
1083
+ return button;
1084
+ }
1085
+
1086
+ /** The synthetic tile buttons, for drag candidates and hit-testing. */
1087
+ function syntheticTileButtons() {
1088
+ return new Map([
1089
+ [LAUNCHER_CHAT_KEY, chatButton],
1090
+ [LAUNCHER_RESTART_KEY, restartButton],
1091
+ [LAUNCHER_CLOSE_KEY, closeButton],
1092
+ ]);
1093
+ }
1094
+
1095
+ /**
1096
+ * Full tile records for the synthetic tiles, so a folder can list,
1097
+ * stack and open them exactly like a host panel row.
1098
+ */
1099
+ function syntheticTileRecords() {
1100
+ const records = new Map();
1101
+ const add = (key, button, label, glyph, active) => {
1102
+ if (button === null || button.isConnected !== true) return;
1103
+ records.set(key, {
1104
+ key,
1105
+ label,
1106
+ glyphHtml: glyph,
1107
+ buttonEl: button,
1108
+ gridEl: button,
1109
+ isMore: false,
1110
+ active: active === true,
1111
+ });
1112
+ };
1113
+ add(LAUNCHER_CHAT_KEY, chatButton, t('launcher.backToConversation'), LAUNCHER_CHAT_ICON,
1114
+ hostTiles.every((tile) => tile.active !== true));
1115
+ add(LAUNCHER_RESTART_KEY, restartButton, t('launcher.restart'), LAUNCHER_RESTART_ICON);
1116
+ add(LAUNCHER_CLOSE_KEY, closeButton, t('launcher.close'), LAUNCHER_CLOSE_ICON);
1117
+ return records;
1118
+ }
1119
+
1120
+ /** Host rows plus synthetic tiles; folders can hold either kind. */
1121
+ function tileMap() {
1122
+ return new Map([...syntheticTileRecords(), ...tileByKeyMap()]);
1123
+ }
1124
+
1125
+ /**
1126
+ * Apply the shared state (label, visibility, grid position) to one
1127
+ * synthetic tile. A tile that a folder hides disappears from the grid.
1128
+ */
1129
+ function syncSyntheticTile(button, key, label, hint, wide, memberOf, orderIndex) {
1130
+ setSyntheticLabel(button, label, hint);
1131
+ button.style.display = wide && !memberOf.has(key) ? '' : 'none';
1132
+ const position = orderIndex.get(key);
1133
+ button.style.order = position === undefined ? '' : String(position);
1134
+ }
1135
+
1022
1136
  function hideDropLine() {
1023
1137
  if (dropLine !== null) dropLine.style.display = 'none';
1024
1138
  if (nav !== null && typeof nav.querySelectorAll === 'function') {
@@ -1034,6 +1148,7 @@
1034
1148
  folderButtons = new Map();
1035
1149
  if (chatButton !== null) chatButton.style.display = 'none';
1036
1150
  if (restartButton !== null) restartButton.style.display = 'none';
1151
+ if (closeButton !== null) closeButton.style.display = 'none';
1037
1152
  if (dropLine !== null) {
1038
1153
  dropLine.remove();
1039
1154
  dropLine = null;
@@ -1080,14 +1195,13 @@
1080
1195
  hostTiles = collectHostTiles(nav);
1081
1196
  const wide = detectWide(hostTiles);
1082
1197
  nav.classList.toggle('dsh-powerup-launcher-wide', wide);
1083
- const panelKeys = [LAUNCHER_CHAT_KEY, LAUNCHER_RESTART_KEY, ...hostTiles.map((tile) => tile.key)];
1198
+ const panelKeys = [LAUNCHER_CHAT_KEY, LAUNCHER_RESTART_KEY, LAUNCHER_CLOSE_KEY, ...hostTiles.map((tile) => tile.key)];
1084
1199
  if (pendingLoad) {
1085
1200
  pendingLoad = false;
1086
1201
  state = normalizeLauncherState(readPersisted(), panelKeys);
1087
1202
  } else {
1088
1203
  state = normalizeLauncherState(state, panelKeys);
1089
1204
  }
1090
- const tiles = tileByKeyMap();
1091
1205
  const memberOf = new Map();
1092
1206
  for (const group of Object.values(state.groups)) {
1093
1207
  for (const key of group.items) memberOf.set(key, group.id);
@@ -1103,16 +1217,13 @@
1103
1217
  tile.gridEl.style.order = position === undefined ? '' : String(position);
1104
1218
  }
1105
1219
  const chat = ensureChatButton();
1106
- setSyntheticLabel(chat, t('launcher.backToConversation'));
1107
- chat.style.display = wide ? '' : 'none';
1108
- const chatPosition = orderIndex.get(LAUNCHER_CHAT_KEY);
1109
- chat.style.order = chatPosition === undefined ? '' : String(chatPosition);
1220
+ syncSyntheticTile(chat, LAUNCHER_CHAT_KEY, t('launcher.backToConversation'), undefined, wide, memberOf, orderIndex);
1110
1221
  chat.classList.toggle('is-active', hostTiles.every((tile) => tile.active !== true));
1111
1222
  const restart = ensureRestartButton();
1112
- setSyntheticLabel(restart, t('launcher.restart'), t('launcher.restartHint'));
1113
- restart.style.display = wide ? '' : 'none';
1114
- const restartPosition = orderIndex.get(LAUNCHER_RESTART_KEY);
1115
- restart.style.order = restartPosition === undefined ? '' : String(restartPosition);
1223
+ syncSyntheticTile(restart, LAUNCHER_RESTART_KEY, t('launcher.restart'), t('launcher.restartHint'), wide, memberOf, orderIndex);
1224
+ const close = ensureCloseButton();
1225
+ syncSyntheticTile(close, LAUNCHER_CLOSE_KEY, t('launcher.close'), t('launcher.closeHint'), wide, memberOf, orderIndex);
1226
+ const tiles = tileMap();
1116
1227
  const live = new Set();
1117
1228
  for (const [groupId, group] of Object.entries(state.groups)) {
1118
1229
  live.add(groupId);
@@ -1288,8 +1399,7 @@
1288
1399
  const element = popup.element;
1289
1400
  element.textContent = '';
1290
1401
  const head = document.createElement('div');
1291
- head.className = 'dsh-powerup-folder-pop-head';
1292
- const title = document.createElement('button');
1402
+ head.className = 'dsh-powerup-folder-pop-head'; const title = document.createElement('button');
1293
1403
  title.type = 'button';
1294
1404
  title.className = 'dsh-powerup-folder-pop-title';
1295
1405
  title.textContent = group.name === '' ? t('launcher.groupDefault') : group.name;
@@ -1306,7 +1416,7 @@
1306
1416
  head.append(title, count, dissolve);
1307
1417
  const grid = document.createElement('div');
1308
1418
  grid.className = 'dsh-powerup-folder-grid';
1309
- const tiles = tileByKeyMap();
1419
+ const tiles = tileMap();
1310
1420
  for (const key of group.items) {
1311
1421
  const tile = tiles.get(key);
1312
1422
  if (tile === undefined) continue;
@@ -1534,9 +1644,36 @@
1534
1644
  }
1535
1645
  }
1536
1646
 
1647
+ /**
1648
+ * Activate one grid or folder flyout tile. The host's "more" row is
1649
+ * wrapped in a Menu root; when a folder hides it, the menu would anchor
1650
+ * to a zero-sized element, so briefly restore its box (transparent) and
1651
+ * let the host open the menu near the grid, then hide it again.
1652
+ */
1537
1653
  function selectPanel(tile) {
1538
1654
  try {
1539
- tile.buttonEl.click();
1655
+ const hiddenMore = tile.isMore === true
1656
+ && tile.gridEl !== undefined
1657
+ && typeof tile.gridEl.style === 'object'
1658
+ && tile.gridEl.style.display === 'none';
1659
+ if (hiddenMore) {
1660
+ const element = tile.gridEl;
1661
+ const restore = { display: element.style.display, opacity: element.style.opacity, pointerEvents: element.style.pointerEvents };
1662
+ element.style.display = '';
1663
+ element.style.opacity = '0';
1664
+ element.style.pointerEvents = 'none';
1665
+ if (typeof element.getBoundingClientRect === 'function') void element.getBoundingClientRect();
1666
+ tile.buttonEl.click();
1667
+ const reset = () => {
1668
+ element.style.display = restore.display;
1669
+ element.style.opacity = restore.opacity;
1670
+ element.style.pointerEvents = restore.pointerEvents;
1671
+ };
1672
+ if (typeof window !== 'undefined' && window !== null && typeof window.setTimeout === 'function') window.setTimeout(reset, 400);
1673
+ else reset();
1674
+ } else {
1675
+ tile.buttonEl.click();
1676
+ }
1540
1677
  } catch (error) {
1541
1678
  warn('panel could not be selected:', error);
1542
1679
  }
@@ -1595,12 +1732,13 @@
1595
1732
  // ----------------------------------------------------------------
1596
1733
  function topLevelCandidates(excludeKey) {
1597
1734
  const candidates = [];
1735
+ const synthetic = syntheticTileButtons();
1598
1736
  for (const entry of state.order) {
1599
1737
  if (entry === excludeKey) continue;
1600
- if (entry === LAUNCHER_CHAT_KEY || entry === LAUNCHER_RESTART_KEY) {
1601
- const button = entry === LAUNCHER_CHAT_KEY ? chatButton : restartButton;
1602
- if (button !== null && button.isConnected === true) {
1603
- candidates.push({ key: entry, el: button, kind: entry === LAUNCHER_CHAT_KEY ? 'chat' : 'restart' });
1738
+ const synth = synthetic.get(entry);
1739
+ if (synth !== undefined) {
1740
+ if (synth !== null && synth.isConnected === true && synth.style.display !== 'none') {
1741
+ candidates.push({ key: entry, el: synth, kind: 'synthetic' });
1604
1742
  }
1605
1743
  continue;
1606
1744
  }
@@ -1628,6 +1766,9 @@
1628
1766
  if (button.hasAttribute('data-powerup-restart')) {
1629
1767
  return { kind: 'restart', key: LAUNCHER_RESTART_KEY, gridEl: button, label: t('launcher.restart') };
1630
1768
  }
1769
+ if (button.hasAttribute('data-powerup-close')) {
1770
+ return { kind: 'close', key: LAUNCHER_CLOSE_KEY, gridEl: button, label: t('launcher.close') };
1771
+ }
1631
1772
  const folderId = button.getAttribute('data-powerup-folder');
1632
1773
  if (folderId !== null) {
1633
1774
  const group = state.groups[folderId];
@@ -1729,8 +1870,7 @@
1729
1870
  const centerX = rect.left + rect.width / 2;
1730
1871
  const centerY = rect.top + rect.height / 2;
1731
1872
  const nearCenter = Math.abs(x - centerX) <= rect.width * 0.28 && Math.abs(y - centerY) <= rect.height * 0.32;
1732
- const special = isLauncherSpecialKey(candidate.key) || isLauncherSpecialKey(drag.descriptor.key);
1733
- if (nearCenter && !special) {
1873
+ if (nearCenter) {
1734
1874
  drop = { kind: 'merge', target: candidate };
1735
1875
  } else {
1736
1876
  drop = { kind: 'insert', index: candidates.indexOf(candidate) + (x < centerX ? 0 : 1), anchor: rect, after: x >= centerX };
@@ -1858,7 +1998,6 @@
1858
1998
 
1859
1999
  function performMerge(sourceKey, targetKey) {
1860
2000
  if (sourceKey === targetKey) return;
1861
- if (isLauncherSpecialKey(sourceKey) || isLauncherSpecialKey(targetKey)) return;
1862
2001
  const sourceGroupId = launcherEntryGroupId(sourceKey);
1863
2002
  const targetGroupId = launcherEntryGroupId(targetKey);
1864
2003
  if (sourceGroupId !== null && sourceGroupId === targetGroupId) return;
@@ -1955,6 +2094,10 @@
1955
2094
  restartButton.remove();
1956
2095
  restartButton = null;
1957
2096
  }
2097
+ if (closeButton !== null) {
2098
+ closeButton.remove();
2099
+ closeButton = null;
2100
+ }
1958
2101
  state = { order: [], groups: {} };
1959
2102
  pendingLoad = true;
1960
2103
  nav = null;
@@ -2034,6 +2177,14 @@
2034
2177
  void restartWithoutPrompt();
2035
2178
  return true;
2036
2179
  },
2180
+ openClose: () => {
2181
+ if (closePromptBridge.open !== null) {
2182
+ closePromptBridge.open();
2183
+ return true;
2184
+ }
2185
+ void closeWithoutPrompt();
2186
+ return true;
2187
+ },
2037
2188
  });
2038
2189
  ctx.effect(() => {
2039
2190
  core.start();
@@ -3054,6 +3205,8 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
3054
3205
  const POWERUP_REGISTRY_KEY = 'dsh-powerup:update-registry:v1';
3055
3206
  const PENDING_RESTART_KEY = 'dsh-powerup:pending-restart:v1';
3056
3207
  const UPDATE_API = '/dsh-powerup/api/restart';
3208
+ /** Host route that closes the whole application. */
3209
+ const CLOSE_API = '/dsh-powerup/api/close';
3057
3210
  const AUDIT_API = '/dsh-powerup/api/audit';
3058
3211
  const SELF_UPDATE_API = '/dsh-powerup/api/self-update';
3059
3212
  const JOB_KILL_API = '/dsh-powerup/api/job-kill';
@@ -4077,10 +4230,11 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
4077
4230
  const [view, setView] = useState(null);
4078
4231
  const [localeTick, forceLocale] = useState(0);
4079
4232
  const [pending, setPending] = useState(() => readPendingRestarts());
4080
- const [restartAsk, setRestartAsk] = useState(false);
4081
- const [restartCapability, setRestartCapability] = useState(null);
4082
- const [restartBusy, setRestartBusy] = useState(false);
4083
- const [restartError, setRestartError] = useState(null);
4233
+ /** Open app-level confirmation: null, 'restart' or 'close'. */
4234
+ const [appAsk, setAppAsk] = useState(null);
4235
+ const [appCapability, setAppCapability] = useState(null);
4236
+ const [appBusy, setAppBusy] = useState(false);
4237
+ const [appError, setAppError] = useState(null);
4084
4238
  const tokenRef = useRef(null);
4085
4239
  const abortRef = useRef(null);
4086
4240
  const buttonsRef = useRef(new Set());
@@ -4495,18 +4649,18 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
4495
4649
  };
4496
4650
  }, [remote]);
4497
4651
 
4498
- // Escape dismisses the list-header restart confirmation unless a
4499
- // restart request is already in flight.
4652
+ // Escape dismisses the app-level confirmation unless its request is
4653
+ // already in flight.
4500
4654
  useEffect(() => {
4501
- if (!restartAsk) return undefined;
4655
+ if (appAsk === null) return undefined;
4502
4656
  const onKeyDown = (event) => {
4503
- if (event.key !== 'Escape' || restartBusy) return;
4657
+ if (event.key !== 'Escape' || appBusy) return;
4504
4658
  event.stopPropagation();
4505
- setRestartAsk(false);
4659
+ setAppAsk(null);
4506
4660
  };
4507
4661
  document.addEventListener('keydown', onKeyDown, true);
4508
4662
  return () => document.removeEventListener('keydown', onKeyDown, true);
4509
- }, [restartAsk, restartBusy]);
4663
+ }, [appAsk, appBusy]);
4510
4664
 
4511
4665
  // A one-click update that does not restart leaves a completion panel;
4512
4666
  // close it on its own so it never lingers over the Plugins page.
@@ -4747,10 +4901,10 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
4747
4901
  }
4748
4902
  };
4749
4903
 
4750
- /** Ask the Host route whether this runtime can restart itself. */
4751
- const readRestartCapability = async () => {
4904
+ /** Ask one Host app-control route whether this runtime supports it. */
4905
+ const readAppCapability = async (api) => {
4752
4906
  try {
4753
- const response = await fetch(UPDATE_API, { headers: { accept: 'application/json' } });
4907
+ const response = await fetch(api, { headers: { accept: 'application/json' } });
4754
4908
  const data = await response.json();
4755
4909
  return {
4756
4910
  supported: response.ok && data?.ok === true && data.supported === true,
@@ -4761,48 +4915,60 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
4761
4915
  }
4762
4916
  };
4763
4917
 
4764
- /** POST the restart command; throws when the Host refuses. */
4765
- const requestAppRestart = async () => {
4766
- const response = await fetch(UPDATE_API, {
4918
+ /** The restart capability, used by the install flow as well. */
4919
+ const readRestartCapability = () => readAppCapability(UPDATE_API);
4920
+
4921
+ /** POST one app-control command; throws when the Host refuses. */
4922
+ const requestAppAction = async (action) => {
4923
+ const api = action === 'close' ? CLOSE_API : UPDATE_API;
4924
+ const response = await fetch(api, {
4767
4925
  method: 'POST',
4768
4926
  headers: { 'content-type': 'application/json' },
4769
- body: JSON.stringify({ action: 'restart' }),
4927
+ body: JSON.stringify({ action }),
4770
4928
  });
4771
4929
  const data = await response.json().catch(() => null);
4772
4930
  if (!response.ok || data?.ok !== true) throw new Error(data?.error ?? `HTTP ${response.status}`);
4773
4931
  };
4774
4932
 
4775
- /** Open the list-header restart confirmation and read the capability. */
4776
- const openRestart = () => {
4777
- setRestartAsk(true);
4778
- setRestartCapability(null);
4779
- setRestartError(null);
4780
- setRestartBusy(false);
4781
- void readRestartCapability().then((capability) => setRestartCapability(capability));
4933
+ /** The restart command, as the install flow spells it. */
4934
+ const requestAppRestart = () => requestAppAction('restart');
4935
+
4936
+ /** Open the app-level confirmation for one action and read its capability. */
4937
+ const openAppAction = (action) => {
4938
+ setAppAsk(action);
4939
+ setAppCapability(null);
4940
+ setAppError(null);
4941
+ setAppBusy(false);
4942
+ void readAppCapability(action === 'close' ? CLOSE_API : UPDATE_API)
4943
+ .then((capability) => setAppCapability(capability));
4782
4944
  };
4783
- openRestartRef.current = openRestart;
4945
+ const openAppActionRef = useRef(() => {});
4946
+ openAppActionRef.current = openAppAction;
4947
+ openRestartRef.current = () => openAppActionRef.current('restart');
4784
4948
 
4785
4949
  // The sidebar launcher is plain DOM and cannot render React, so it
4786
- // calls this opener for its synthetic "restart DSH" tile. Keeping the
4787
- // opener here means the sidebar and the pending-restart bar share one
4950
+ // calls these openers for its synthetic restart/close tiles. Keeping
4951
+ // them here means the sidebar and the pending-restart bar share one
4788
4952
  // confirmation dialog, one capability read and one set of copy.
4789
4953
  useEffect(() => {
4790
- restartPromptBridge.open = () => openRestartRef.current();
4954
+ restartPromptBridge.open = () => openAppActionRef.current('restart');
4955
+ closePromptBridge.open = () => openAppActionRef.current('close');
4791
4956
  return () => {
4792
4957
  if (restartPromptBridge.open !== null) restartPromptBridge.open = null;
4958
+ if (closePromptBridge.open !== null) closePromptBridge.open = null;
4793
4959
  };
4794
4960
  }, []);
4795
4961
 
4796
- /** Confirm the list-header restart. */
4797
- const confirmRestart = async () => {
4798
- if (restartBusy) return;
4799
- setRestartBusy(true);
4800
- setRestartError(null);
4962
+ /** Confirm the app-level action (restart or close). */
4963
+ const confirmAppAction = async () => {
4964
+ if (appBusy) return;
4965
+ setAppBusy(true);
4966
+ setAppError(null);
4801
4967
  try {
4802
- await requestAppRestart();
4968
+ await requestAppAction(appAsk === 'close' ? 'close' : 'restart');
4803
4969
  } catch (error) {
4804
- setRestartBusy(false);
4805
- setRestartError(errorText(error) || tRef.current('update.unknown'));
4970
+ setAppBusy(false);
4971
+ setAppError(errorText(error) || tRef.current('update.unknown'));
4806
4972
  }
4807
4973
  };
4808
4974
 
@@ -4867,10 +5033,11 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
4867
5033
  ),
4868
5034
  );
4869
5035
 
4870
- const restartPrompt = restartAsk ? h('div', {
5036
+ const appAction = appAsk === 'close' ? 'close' : 'restart';
5037
+ const appPrompt = appAsk === null ? null : h('div', {
4871
5038
  className: 'dsh-powerup-update-mask',
4872
5039
  onMouseDown: (event) => {
4873
- if (event.target === event.currentTarget && !restartBusy) setRestartAsk(false);
5040
+ if (event.target === event.currentTarget && !appBusy) setAppAsk(null);
4874
5041
  },
4875
5042
  },
4876
5043
  h('div', {
@@ -4878,43 +5045,43 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
4878
5045
  style: { width: 'min(420px,100%)' },
4879
5046
  role: 'dialog',
4880
5047
  'aria-modal': 'true',
4881
- 'aria-labelledby': 'dsh-powerup-restart-title',
5048
+ 'aria-labelledby': 'dsh-powerup-app-action-title',
4882
5049
  },
4883
5050
  h('div', { className: 'dsh-powerup-update-head' },
4884
5051
  h('div', { className: 'dsh-powerup-update-heading' },
4885
- h('h2', { id: 'dsh-powerup-restart-title' }, t('restart.title')),
5052
+ h('h2', { id: 'dsh-powerup-app-action-title' }, t(appAction === 'close' ? 'close.title' : 'restart.title')),
4886
5053
  /* A sidebar-initiated restart usually has no pending plugins, so the
4887
5054
  subtitle only appears when there is something to report. */
4888
- pending.length === 0 ? null : h('p', null, t('restart.pending', { count: pending.length })),
5055
+ appAction === 'restart' && pending.length > 0 ? h('p', null, t('restart.pending', { count: pending.length })) : null,
4889
5056
  ),
4890
- restartBusy ? null : h('button', { type: 'button', className: 'dsh-powerup-update-close', 'aria-label': t('update.close'), onClick: () => setRestartAsk(false) }, '×'),
5057
+ appBusy ? null : h('button', { type: 'button', className: 'dsh-powerup-update-close', 'aria-label': t('update.close'), onClick: () => setAppAsk(null) }, '×'),
4891
5058
  ),
4892
5059
  h('div', { className: 'dsh-powerup-update-body' },
4893
- h('p', { className: 'dsh-powerup-update-note' }, t('restart.desc')),
4894
- restartCapability !== null && restartCapability.supported !== true
4895
- ? notice('warn', h(WarnIcon, { size: 14 }), null, t('update.restartUnsupported', { reason: restartCapability.reason ?? '' }))
5060
+ h('p', { className: 'dsh-powerup-update-note' }, t(appAction === 'close' ? 'close.desc' : 'restart.desc')),
5061
+ appCapability !== null && appCapability.supported !== true
5062
+ ? notice('warn', h(WarnIcon, { size: 14 }), null, t(appAction === 'close' ? 'close.unsupported' : 'update.restartUnsupported', { reason: appCapability.reason ?? '' }))
4896
5063
  : null,
4897
- restartError === null ? null : notice('error', h(WarnIcon, { size: 14 }), null, restartError),
4898
- restartBusy
5064
+ appError === null ? null : notice('error', h(WarnIcon, { size: 14 }), null, appError),
5065
+ appBusy
4899
5066
  ? h('div', { className: 'dsh-powerup-update-status' },
4900
5067
  h('span', { className: 'dsh-powerup-update-spinner', 'aria-hidden': 'true' }),
4901
- t('update.restarting'),
5068
+ t(appAction === 'close' ? 'close.closing' : 'update.restarting'),
4902
5069
  )
4903
5070
  : null,
4904
5071
  ),
4905
5072
  h('div', { className: 'dsh-powerup-update-foot' },
4906
- h('button', { type: 'button', className: 'dsh-powerup-update-ghost', disabled: restartBusy, onClick: () => setRestartAsk(false) }, t('restart.cancel')),
5073
+ h('button', { type: 'button', className: 'dsh-powerup-update-ghost', disabled: appBusy, onClick: () => setAppAsk(null) }, t(appAction === 'close' ? 'close.cancel' : 'restart.cancel')),
4907
5074
  h('button', {
4908
5075
  type: 'button',
4909
5076
  className: 'dsh-powerup-update-primary',
4910
- disabled: restartBusy || restartCapability?.supported !== true,
4911
- onClick: confirmRestart,
4912
- }, restartBusy ? t('update.restarting') : t('restart.confirm')),
5077
+ disabled: appBusy || appCapability?.supported !== true,
5078
+ onClick: confirmAppAction,
5079
+ }, appBusy ? t(appAction === 'close' ? 'close.closing' : 'update.restarting') : t(appAction === 'close' ? 'close.confirm' : 'restart.confirm')),
4913
5080
  ),
4914
5081
  ),
4915
- ) : null;
5082
+ );
4916
5083
 
4917
- if (view === null) return restartPrompt;
5084
+ if (view === null) return appPrompt;
4918
5085
  const busy = view.phase === 'working' || view.phase === 'self-updating' || view.phase === 'restarting' || view.enabling === true;
4919
5086
  const canClose = !busy;
4920
5087
  const title = view.title === undefined || view.title === '' ? view.name : view.title;
@@ -5782,6 +5949,8 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
5782
5949
  LAUNCHER_CHAT_KEY,
5783
5950
  LAUNCHER_RESTART_KEY,
5784
5951
  LAUNCHER_RESTART_ICON,
5952
+ LAUNCHER_CLOSE_KEY,
5953
+ LAUNCHER_CLOSE_ICON,
5785
5954
  normalizeLauncherState,
5786
5955
  dissolveGroupOrder,
5787
5956
  createLauncherCore,
package/index.js CHANGED
@@ -6,6 +6,8 @@
6
6
  *
7
7
  * GET /dsh-powerup/api/restart → { ok, supported, reason? }
8
8
  * POST /dsh-powerup/api/restart → schedules a whole-app restart
9
+ * GET /dsh-powerup/api/close → { ok, supported, reason? }
10
+ * POST /dsh-powerup/api/close → closes the whole app (no relaunch)
9
11
  * GET /dsh-powerup/api/audit → profile bundles newer than this Host
10
12
  * POST /dsh-powerup/api/self-update → removes and reinstalls this plugin
11
13
  * in the background, surviving the
@@ -33,7 +35,7 @@ import { appendFileSync, mkdirSync, readFileSync, statSync } from 'node:fs';
33
35
  import { dirname, join } from 'node:path';
34
36
  import { homedir } from 'node:os';
35
37
  import { defineTool } from '@deepseek-ai/dsh-tools';
36
- import { describeRestart, requestRestart } from './lib/restart.js';
38
+ import { describeClose, describeRestart, requestRestart, requestShutdown } from './lib/restart.js';
37
39
  import { createStepReadTool } from './lib/step-tool.js';
38
40
 
39
41
  /** Prefix owned by this plugin. */
@@ -354,7 +356,7 @@ async function handle(req, res, ctx) {
354
356
 
355
357
  const url = new URL(req.url ?? ROUTE, 'http://localhost');
356
358
  const op = url.pathname.slice(ROUTE.length).replace(/^\/+/u, '') || url.searchParams.get('op') || '';
357
- if (op !== '' && op !== 'restart' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill') {
359
+ if (op !== '' && op !== 'restart' && op !== 'close' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill') {
358
360
  sendJson(res, { ok: false, error: 'not-found' }, 404);
359
361
  return;
360
362
  }
@@ -440,22 +442,26 @@ async function handle(req, res, ctx) {
440
442
  return;
441
443
  }
442
444
 
443
- if (req.method === 'GET') {
444
- sendJson(res, { ok: true, action: 'restart', ...describeRestart() });
445
- return;
446
- }
447
-
448
- if (req.method === 'POST') {
449
- try {
450
- const scheduled = requestRestart();
451
- sendJson(res, { ok: true, restarting: true, ...scheduled });
452
- } catch (error) {
453
- sendJson(res, { ok: false, code: error?.code, error: String(error?.message ?? error) }, 409);
445
+ if (op === '' || op === 'restart' || op === 'close') {
446
+ const action = op === 'close' ? 'close' : 'restart';
447
+ if (req.method === 'GET') {
448
+ sendJson(res, { ok: true, action, ...(action === 'close' ? describeClose() : describeRestart()) });
449
+ return;
450
+ }
451
+ if (req.method === 'POST') {
452
+ try {
453
+ const scheduled = action === 'close' ? requestShutdown() : requestRestart();
454
+ sendJson(res, { ok: true, [action === 'close' ? 'closing' : 'restarting']: true, ...scheduled });
455
+ } catch (error) {
456
+ sendJson(res, { ok: false, code: error?.code, error: String(error?.message ?? error) }, 409);
457
+ }
458
+ return;
454
459
  }
460
+ sendJson(res, { ok: false, error: 'method-not-allowed' }, 405);
455
461
  return;
456
462
  }
457
463
 
458
- sendJson(res, { ok: false, error: 'method-not-allowed' }, 405);
464
+ sendJson(res, { ok: false, error: 'not-found' }, 404);
459
465
  }
460
466
 
461
467
  /**
package/lib/restart.js CHANGED
@@ -1,12 +1,13 @@
1
1
  /**
2
- * dsh-powerup — restart the whole DSH desktop app.
2
+ * dsh-powerup — restart or close the whole DSH desktop app.
3
3
  *
4
4
  * The Host half runs inside the `dsh-desktop-host` child process, whose parent
5
5
  * is the Electron main process. The desktop shell exposes shutdown and update
6
6
  * controls over IPC but no "restart application" request, so this module
7
7
  * starts a detached helper (`restart-helper.cjs`), lets the HTTP response
8
8
  * settle, then ends the Electron main process. The helper waits for this Host
9
- * to exit and relaunches the same executable.
9
+ * to exit and relaunches the same executable — or, in `shutdown` mode, just
10
+ * lets the app close.
10
11
  *
11
12
  * Only the Electron desktop build supports this. A plain `dsh web` process
12
13
  * reports the reason instead, and the UI hides the action.
@@ -43,14 +44,15 @@ function dshHome() {
43
44
  }
44
45
 
45
46
  /**
46
- * Whether this runtime can restart the whole application.
47
+ * Whether this runtime can control the whole application.
48
+ * @param {'restart' | 'close'} action
47
49
  * @returns {{ supported: boolean, reason?: string }}
48
50
  */
49
- export function describeRestart() {
51
+ function describeAction(action) {
50
52
  if (process.versions.electron === undefined) {
51
53
  return {
52
54
  supported: false,
53
- reason: 'DSH is running as a command-line web process (dsh web); restart it from the terminal.',
55
+ reason: `DSH is running as a command-line web process (dsh web); ${action} it from the terminal.`,
54
56
  };
55
57
  }
56
58
  if (typeof process.execPath !== 'string' || process.execPath.length === 0 || !existsSync(process.execPath)) {
@@ -63,6 +65,22 @@ export function describeRestart() {
63
65
  return { supported: true };
64
66
  }
65
67
 
68
+ /**
69
+ * Whether this runtime can restart the whole application.
70
+ * @returns {{ supported: boolean, reason?: string }}
71
+ */
72
+ export function describeRestart() {
73
+ return describeAction('restart');
74
+ }
75
+
76
+ /**
77
+ * Whether this runtime can close the whole application.
78
+ * @returns {{ supported: boolean, reason?: string }}
79
+ */
80
+ export function describeClose() {
81
+ return describeAction('close');
82
+ }
83
+
66
84
  /**
67
85
  * Schedule a full application restart. The caller must finish its HTTP
68
86
  * response; the helper waits {@link ACTION_DELAY_MS} before acting.
@@ -71,13 +89,33 @@ export function describeRestart() {
71
89
  * @throws {Error} with `code = 'restart-unsupported'` outside the desktop app.
72
90
  */
73
91
  export function requestRestart() {
74
- const capability = describeRestart();
92
+ return scheduleAction('restart');
93
+ }
94
+
95
+ /**
96
+ * Schedule closing the whole application (the detached helper ends the
97
+ * Electron main process and does not relaunch it).
98
+ *
99
+ * @returns {{ supported: true, action: 'shutdown', pid: number | undefined, pending: boolean }}
100
+ * @throws {Error} with `code = 'shutdown-unsupported'` outside the desktop app.
101
+ */
102
+ export function requestShutdown() {
103
+ return scheduleAction('shutdown');
104
+ }
105
+
106
+ /**
107
+ * Start the detached helper for one application-level action.
108
+ * @param {'restart' | 'shutdown'} action
109
+ * @returns {{ supported: true, action: string, pid: number | undefined, pending: boolean }}
110
+ */
111
+ function scheduleAction(action) {
112
+ const capability = describeAction(action === 'shutdown' ? 'close' : 'restart');
75
113
  if (!capability.supported) {
76
- const error = new Error(capability.reason ?? 'This runtime cannot restart DSH.');
77
- error.code = 'restart-unsupported';
114
+ const error = new Error(capability.reason ?? 'This runtime cannot control DSH.');
115
+ error.code = (action === 'shutdown' ? 'shutdown' : 'restart') + '-unsupported';
78
116
  throw error;
79
117
  }
80
- if (scheduled) return { supported: true, action: 'restart', pid: undefined, pending: true };
118
+ if (scheduled) return { supported: true, action, pid: undefined, pending: true };
81
119
  scheduled = true;
82
120
 
83
121
  const executable = process.execPath;
@@ -97,7 +135,7 @@ export function requestRestart() {
97
135
  String(process.pid),
98
136
  dirname(executable),
99
137
  '[]',
100
- 'restart',
138
+ action === 'shutdown' ? 'shutdown' : 'restart',
101
139
  String(ACTION_DELAY_MS),
102
140
  ], {
103
141
  cwd: dirname(executable),
@@ -124,7 +162,7 @@ export function requestRestart() {
124
162
  child.on('error', () => {
125
163
  scheduled = false;
126
164
  });
127
- return { supported: true, action: 'restart', pid: child.pid, pending: false };
165
+ return { supported: true, action, pid: child.pid, pending: false };
128
166
  }
129
167
 
130
168
  /**
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, copy a step reference (session id + step id) that the read-only powerup_step_read tool resolves back into the raw session data, export the trajectory snapshot, and copy the session ID. The session header 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 install control on every third-party installed plugin: read versions from the registry, install the version in the input through the Add plugin path (removing the old copy first), then enable and optionally restart DSH. The install panel also offers a one-click install that installs the input version without the enable and restart questions, enabling and restarting automatically by default; both defaults are configurable on the Power-Up page. A sidebar launcher turns the left sidebar panel buttons into an adaptive icon grid (icon above label) with drag sorting and folders: drop an icon onto the middle of another to fold them into a folder like a Windows Start menu folder, click a folder to open its icons in a flyout, and switch the whole grid off on the Power-Up page. The grid also carries two built-in buttons: back to conversation, and restart DSH (which reuses the install flow's restart confirmation)."
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, copy a step reference (session id + step id) that the read-only powerup_step_read tool resolves back into the raw session data, export the trajectory snapshot, and copy the session ID. The session header 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 install control on every third-party installed plugin: read versions from the registry, install the version in the input through the Add plugin path (removing the old copy first), then enable and optionally restart DSH. The install panel also offers a one-click install that installs the input version without the enable and restart questions, enabling and restarting automatically by default; both defaults are configurable on the Power-Up page. A sidebar launcher turns the left sidebar panel buttons into an adaptive icon grid (icon above label) with drag sorting and folders: drop an icon onto the middle of another to fold them into a folder like a Windows Start menu folder, click a folder to open its icons in a flyout, and switch the whole grid off on the Power-Up page. The grid also carries three built-in buttons — back to conversation, restart DSH and close DSH — and they, like the host more entry, can be dragged into a folder; restart and close reuse the install flow's confirmation dialog."
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 + 步骤 ID」的步骤引用(Agent 用只读工具 powerup_step_read 取回该步骤完整数据)、导出轨迹快照、复制会话 ID。在会话顶部的后台任务面板手动停止任务时可以填写停止原因,原因会附加在任务结束后注入会话的提示里。插件页为每个第三方已安装插件增加安装按钮:从安装源读取版本,按输入框中的版本先卸载旧版再按「添加插件」流程安装,完成后可立即启用并选择是否重启 DSH。安装面板还提供「一键安装」:按输入框版本安装并跳过启用与重启的询问,默认自动启用并重启,可在 Power-Up 页面调整默认行为。侧边栏启动器把左侧边栏的面板按钮变成随宽度自适应的图标网格(图标在上、文字在下),支持拖拽排序与分组:把一个图标拖到另一个图标的中间即可合并成分组(像 Windows 开始菜单的文件夹),点击分组会以浮层弹出其中的图标;可在 Power-Up 页面整体关闭。网格里自带「返回会话」与「重启 DSH」两个按钮,重启沿用插件安装流程的确认对话框。"
4
+ "description": "在轨迹页面为记录增加右键操作菜单:复制内容、复制 Markdown 引用、引用到输入框、查看记录详情、从该记录 Fork 会话、复制「会话 ID + 步骤 ID」的步骤引用(Agent 用只读工具 powerup_step_read 取回该步骤完整数据)、导出轨迹快照、复制会话 ID。在会话顶部的后台任务面板手动停止任务时可以填写停止原因,原因会附加在任务结束后注入会话的提示里。插件页为每个第三方已安装插件增加安装按钮:从安装源读取版本,按输入框中的版本先卸载旧版再按「添加插件」流程安装,完成后可立即启用并选择是否重启 DSH。安装面板还提供「一键安装」:按输入框版本安装并跳过启用与重启的询问,默认自动启用并重启,可在 Power-Up 页面调整默认行为。侧边栏启动器把左侧边栏的面板按钮变成随宽度自适应的图标网格(图标在上、文字在下),支持拖拽排序与分组:把一个图标拖到另一个图标的中间即可合并成分组(像 Windows 开始菜单的文件夹),点击分组会以浮层弹出其中的图标;可在 Power-Up 页面整体关闭。网格里自带「返回会话」「重启 DSH」「关闭 DSH」三个按钮,它们和「更多」一样可以拖进分组;重启与关闭沿用插件安装流程的确认对话框。"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@restregular/dsh-powerup",
3
- "version": "0.8.8",
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 install control for third-party plugins from the Plugins page: read versions from the configured registries, install the version in the input through the Add plugin path (removing the old copy first), mark restart-needed installs, hand Power-Up's own install to the background, and optionally restart DSH. One-click install skips the enable and restart questions and can apply those actions automatically with configurable defaults. The ledger menu also copies a step reference (session id + step id) that the read-only powerup_step_read tool resolves back into the raw session data. · 为 DeepSeek Harness 提供小型增强:在轨迹页面右键记录即可复制、引用、查看详情或从该记录 Fork;右键「复制步骤引用」得到「会话 ID + 步骤 ID」,Agent 用只读工具 powerup_step_read 即可取回该步骤的完整原始数据;在会话顶部的后台任务面板手动停止任务时可填写停止原因,原因会附加到任务结束后的会话提示;并在插件页为第三方已安装插件提供安装按钮,从安装源读取版本,按输入框中的版本沿用「添加插件」流程安装(先卸载旧版),支持待重启标记、Power-Up 自身后台安装与可选重启;安装面板提供「一键安装」,按输入框版本安装并跳过启用/重启询问,默认自动启用并重启,可在 Power-Up 页面调整默认行为。 · 侧边栏启动器:把左侧边栏的面板按钮变成随宽度自适应的图标网格(图标在上、文字在下),支持拖拽排序与分组(拖到另一个图标中间即合并为分组,点击分组弹出浮层展示内部图标),可随时整体关闭;网格里自带「返回会话」与「重启 DSH」两个按钮,重启沿用插件安装流程的确认对话框。",
3
+ "version": "0.8.9",
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 install control for third-party plugins from the Plugins page: read versions from the configured registries, install the version in the input through the Add plugin path (removing the old copy first), mark restart-needed installs, hand Power-Up's own install to the background, and optionally restart DSH. One-click install skips the enable and restart questions and can apply those actions automatically with configurable defaults. The ledger menu also copies a step reference (session id + step id) that the read-only powerup_step_read tool resolves back into the raw session data. · 为 DeepSeek Harness 提供小型增强:在轨迹页面右键记录即可复制、引用、查看详情或从该记录 Fork;右键「复制步骤引用」得到「会话 ID + 步骤 ID」,Agent 用只读工具 powerup_step_read 即可取回该步骤的完整原始数据;在会话顶部的后台任务面板手动停止任务时可填写停止原因,原因会附加到任务结束后的会话提示;并在插件页为第三方已安装插件提供安装按钮,从安装源读取版本,按输入框中的版本沿用「添加插件」流程安装(先卸载旧版),支持待重启标记、Power-Up 自身后台安装与可选重启;安装面板提供「一键安装」,按输入框版本安装并跳过启用/重启询问,默认自动启用并重启,可在 Power-Up 页面调整默认行为。 · 侧边栏启动器:把左侧边栏的面板按钮变成随宽度自适应的图标网格(图标在上、文字在下),支持拖拽排序与分组(拖到另一个图标中间即合并为分组,点击分组弹出浮层展示内部图标),可随时整体关闭;网格里自带「返回会话」「重启 DSH」「关闭 DSH」三个按钮,它们和「更多」一样可以拖进分组,重启/关闭沿用插件安装流程的确认对话框。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",
7
7
  "main": "index.js",
@@ -77,7 +77,8 @@
77
77
  "launcher",
78
78
  "drag-sort",
79
79
  "folder",
80
- "restart"
80
+ "restart",
81
+ "close"
81
82
  ],
82
83
  "publishConfig": {
83
84
  "access": "public",