@restregular/dsh-powerup 0.8.6 → 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,19 +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.
120
- - **A synthetic "Restart DSH" tile.** A second Power-Up tile (circular-arrow
121
- restart glyph + `重启` / `Restart`) opens the same restart confirmation the pending-restart
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
+ - **A synthetic "Restart DSH" tile.** A second Power-Up tile (a ring with the
121
+ arrowhead tangent to the top, i.e. the arrow lines up with the arc) plus
122
+ `重启` / `Restart` opens the same restart confirmation the pending-restart
122
123
  bar uses: the tile only calls into that React prompt, so there is one dialog,
123
124
  one capability read (`GET /dsh-powerup/api/restart`) and one set of copy. The
124
125
  confirmation explains that running tasks are interrupted; only a runtime that
125
- can relaunch itself (the desktop app) enables the confirm button. The tile
126
- drags like any other, never joins a folder, and is hidden with the rest of
127
- 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.
128
137
  - **Ungroup expands in place.** Dissolving a folder puts its icons back on the
129
138
  grid exactly where the folder sat, in the folder's own order — nothing jumps
130
139
  to the end of the grid.
@@ -230,21 +239,22 @@ fiber is unloaded. The panel closes; refresh the page when the install finishes.
230
239
  rows are resolved by shape — a direct `<button>`, or a wrapper (the More
231
240
  launcher's `Menu` root `<span>`) whose direct child is that button — because
232
241
  the wrapper element differs between the panel rows and the more menu.
233
- - **The DOM launcher borrows the React restart prompt.** The launcher is plain
234
- DOM and cannot render React, so the Plugins overlay publishes its
235
- `openRestart` in a module-level bridge while it is mounted; the synthetic
236
- restart tile calls that, and gets the exact confirmation, capability check and
237
- localized copy the pending-restart bar uses — nothing is duplicated. If the
238
- overlay is not mounted at all (a host without `remote.pluginManager`), the
239
- 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.
240
250
  - **Every sync write is idempotent.** The launcher observes its own `<nav>`
241
251
  with a `MutationObserver`, so a write that changes a watched subtree on every
242
252
  sync turns into an infinite loop — and a loop rebuilds the folder flyout
243
253
  continuously, which makes normal clicks miss (the node under the pointer is
244
254
  replaced between `pointerdown` and `click`). Setting `textContent` to the same
245
- string still emits a `childList` mutation, so the synthetic chat/restart tiles
246
- only write their labels when they actually changed, folder tiles rebuild only
247
- 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
248
258
  their signature changed, and the flyout re-renders only when its roster or
249
259
  name changed. A
250
260
  `MutationObserver` re-applies that after every host render, and the module
@@ -259,9 +269,9 @@ fiber is unloaded. The panel closes; refresh the page when the install finishes.
259
269
  `[data-plugin-group="bundles"] [data-plugin-package]` card and re-asserts it
260
270
  after React renders. Version listing is a plain registry `GET`; removal and
261
271
  installation use the same `remote.pluginManager` calls as **Add plugin**. The
262
- Host adds two loopback-only routes: `/dsh-powerup/api/restart` for the
263
- process restart, and `/dsh-powerup/api/self-update` for the self-install
264
- 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.
265
275
  - **Power-Up's own install outlives its unload.** The Host route sends its
266
276
  answer, then a timer starts `removeBundle` → `inspect` →
267
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.6';
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,10 +574,18 @@
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
- /** 16-grid restart glyph (Material restart_alt) for the "restart DSH" tile. */
562
- const LAUNCHER_RESTART_ICON = '<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" focusable="false"><path d="M12 5V2L7 7l5 5V9c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z"/></svg>';
581
+ /**
582
+ * 16-grid restart glyph: a ring with the arrowhead sitting exactly on the
583
+ * top tangent, so the wedge and the arc line up instead of floating off
584
+ * the opening (the previous Material glyph read as detached).
585
+ */
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>';
563
589
  /**
564
590
  * Bridge to the Plugins overlay's React restart prompt. The launcher is
565
591
  * plain DOM and cannot render React, so the overlay publishes its opener
@@ -567,35 +593,61 @@
567
593
  * the same confirmation, capability check and locale-aware copy.
568
594
  */
569
595
  const restartPromptBridge = { open: null };
596
+ /** Same bridge for the "close DSH" confirmation. */
597
+ const closePromptBridge = { open: null };
570
598
 
571
599
  /**
572
600
  * Last resort for a host where the Plugins overlay (and with it the
573
- * React restart prompt) is not mounted: confirm with the browser and ask
574
- * the Host restart route directly. Unreachable on a normal desktop/web
575
- * 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
576
606
  */
577
- async function restartWithoutPrompt() {
607
+ async function appActionWithoutPrompt(options) {
578
608
  const t = (key, params) => translateCurrent(key, params);
579
609
  try {
580
- const capability = await fetch('/dsh-powerup/api/restart', { headers: { accept: 'application/json' } })
610
+ const capability = await fetch(options.api, { headers: { accept: 'application/json' } })
581
611
  .then((response) => response.json());
582
612
  if (capability?.supported !== true) {
583
- window.alert(t('update.restartUnsupported', { reason: capability?.reason ?? '' }));
613
+ window.alert(t(options.unsupportedKey, { reason: capability?.reason ?? '' }));
584
614
  return;
585
615
  }
586
- if (window.confirm(t('restart.title') + ' ' + t('restart.desc')) !== true) return;
587
- 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, {
588
618
  method: 'POST',
589
619
  headers: { 'content-type': 'application/json' },
590
- body: JSON.stringify({ action: 'restart' }),
620
+ body: JSON.stringify({ action: options.action }),
591
621
  });
592
622
  const data = await response.json().catch(() => null);
593
623
  if (!response.ok || data?.ok !== true) throw new Error(data?.error ?? 'HTTP ' + response.status);
594
624
  } catch (error) {
595
- window.alert(t('update.restartFailed', { message: error?.message ?? String(error) }));
625
+ window.alert(t(options.failedKey, { message: error?.message ?? String(error) }));
596
626
  }
597
627
  }
598
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
+
599
651
  function launcherGroupEntry(groupId) {
600
652
  return LAUNCHER_GROUP_PREFIX + groupId;
601
653
  }
@@ -610,16 +662,6 @@
610
662
  return 'g' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
611
663
  }
612
664
 
613
- /**
614
- * Synthetic tiles (back to conversation, restart DSH, the host's "more"
615
- * launcher) always live directly on the grid and can never join a folder.
616
- * @param {string} key tile key
617
- * @returns {boolean}
618
- */
619
- function isLauncherSpecialKey(key) {
620
- return key === LAUNCHER_CHAT_KEY || key === LAUNCHER_RESTART_KEY || key === LAUNCHER_MORE_KEY;
621
- }
622
-
623
665
  /**
624
666
  * Reconcile the saved launcher state with the panels that exist right now.
625
667
  * Unknown panel keys (unregistered, unpinned) are dropped; panels without
@@ -641,7 +683,6 @@
641
683
  const list = Array.isArray(value.items) ? value.items : [];
642
684
  for (const key of list) {
643
685
  if (typeof key !== 'string' || !known.has(key) || assigned.has(key)) continue;
644
- if (key.startsWith('__')) continue;
645
686
  assigned.add(key);
646
687
  items.push(key);
647
688
  }
@@ -698,7 +739,7 @@
698
739
  const index = source.indexOf(folderEntry);
699
740
  const members = [];
700
741
  for (const key of Array.isArray(items) ? items : []) {
701
- if (typeof key !== 'string' || key === '' || key.startsWith('__')) continue;
742
+ if (typeof key !== 'string' || key === '') continue;
702
743
  if (list.includes(key) || members.includes(key)) continue;
703
744
  members.push(key);
704
745
  }
@@ -733,6 +774,7 @@
733
774
  const listPanels = typeof options.listPanels === 'function' ? options.listPanels : () => [];
734
775
  const selectConversation = typeof options.selectConversation === 'function' ? options.selectConversation : () => {};
735
776
  const openRestart = typeof options.openRestart === 'function' ? options.openRestart : () => false;
777
+ const openClose = typeof options.openClose === 'function' ? options.openClose : () => false;
736
778
 
737
779
  let nav = null;
738
780
  let docObserver = null;
@@ -747,6 +789,7 @@
747
789
  let folderButtons = new Map();
748
790
  let chatButton = null;
749
791
  let restartButton = null;
792
+ let closeButton = null;
750
793
  let dropLine = null;
751
794
  let drag = null;
752
795
  let popup = null;
@@ -856,7 +899,8 @@
856
899
  for (const child of [...container.children]) {
857
900
  if (child.hasAttribute('data-powerup-folder')
858
901
  || child.hasAttribute('data-powerup-chat')
859
- || child.hasAttribute('data-powerup-restart')) continue;
902
+ || child.hasAttribute('data-powerup-restart')
903
+ || child.hasAttribute('data-powerup-close')) continue;
860
904
  if (typeof child.classList === 'object' && child.classList !== null && child.classList.contains('dsh-powerup-drop-line')) continue;
861
905
  let gridEl = child;
862
906
  let buttonEl = null;
@@ -1015,6 +1059,80 @@
1015
1059
  return button;
1016
1060
  }
1017
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
+
1018
1136
  function hideDropLine() {
1019
1137
  if (dropLine !== null) dropLine.style.display = 'none';
1020
1138
  if (nav !== null && typeof nav.querySelectorAll === 'function') {
@@ -1030,6 +1148,7 @@
1030
1148
  folderButtons = new Map();
1031
1149
  if (chatButton !== null) chatButton.style.display = 'none';
1032
1150
  if (restartButton !== null) restartButton.style.display = 'none';
1151
+ if (closeButton !== null) closeButton.style.display = 'none';
1033
1152
  if (dropLine !== null) {
1034
1153
  dropLine.remove();
1035
1154
  dropLine = null;
@@ -1076,14 +1195,13 @@
1076
1195
  hostTiles = collectHostTiles(nav);
1077
1196
  const wide = detectWide(hostTiles);
1078
1197
  nav.classList.toggle('dsh-powerup-launcher-wide', wide);
1079
- 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)];
1080
1199
  if (pendingLoad) {
1081
1200
  pendingLoad = false;
1082
1201
  state = normalizeLauncherState(readPersisted(), panelKeys);
1083
1202
  } else {
1084
1203
  state = normalizeLauncherState(state, panelKeys);
1085
1204
  }
1086
- const tiles = tileByKeyMap();
1087
1205
  const memberOf = new Map();
1088
1206
  for (const group of Object.values(state.groups)) {
1089
1207
  for (const key of group.items) memberOf.set(key, group.id);
@@ -1099,16 +1217,13 @@
1099
1217
  tile.gridEl.style.order = position === undefined ? '' : String(position);
1100
1218
  }
1101
1219
  const chat = ensureChatButton();
1102
- setSyntheticLabel(chat, t('launcher.backToConversation'));
1103
- chat.style.display = wide ? '' : 'none';
1104
- const chatPosition = orderIndex.get(LAUNCHER_CHAT_KEY);
1105
- chat.style.order = chatPosition === undefined ? '' : String(chatPosition);
1220
+ syncSyntheticTile(chat, LAUNCHER_CHAT_KEY, t('launcher.backToConversation'), undefined, wide, memberOf, orderIndex);
1106
1221
  chat.classList.toggle('is-active', hostTiles.every((tile) => tile.active !== true));
1107
1222
  const restart = ensureRestartButton();
1108
- setSyntheticLabel(restart, t('launcher.restart'), t('launcher.restartHint'));
1109
- restart.style.display = wide ? '' : 'none';
1110
- const restartPosition = orderIndex.get(LAUNCHER_RESTART_KEY);
1111
- 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();
1112
1227
  const live = new Set();
1113
1228
  for (const [groupId, group] of Object.entries(state.groups)) {
1114
1229
  live.add(groupId);
@@ -1284,8 +1399,7 @@
1284
1399
  const element = popup.element;
1285
1400
  element.textContent = '';
1286
1401
  const head = document.createElement('div');
1287
- head.className = 'dsh-powerup-folder-pop-head';
1288
- const title = document.createElement('button');
1402
+ head.className = 'dsh-powerup-folder-pop-head'; const title = document.createElement('button');
1289
1403
  title.type = 'button';
1290
1404
  title.className = 'dsh-powerup-folder-pop-title';
1291
1405
  title.textContent = group.name === '' ? t('launcher.groupDefault') : group.name;
@@ -1302,7 +1416,7 @@
1302
1416
  head.append(title, count, dissolve);
1303
1417
  const grid = document.createElement('div');
1304
1418
  grid.className = 'dsh-powerup-folder-grid';
1305
- const tiles = tileByKeyMap();
1419
+ const tiles = tileMap();
1306
1420
  for (const key of group.items) {
1307
1421
  const tile = tiles.get(key);
1308
1422
  if (tile === undefined) continue;
@@ -1530,9 +1644,36 @@
1530
1644
  }
1531
1645
  }
1532
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
+ */
1533
1653
  function selectPanel(tile) {
1534
1654
  try {
1535
- 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
+ }
1536
1677
  } catch (error) {
1537
1678
  warn('panel could not be selected:', error);
1538
1679
  }
@@ -1591,12 +1732,13 @@
1591
1732
  // ----------------------------------------------------------------
1592
1733
  function topLevelCandidates(excludeKey) {
1593
1734
  const candidates = [];
1735
+ const synthetic = syntheticTileButtons();
1594
1736
  for (const entry of state.order) {
1595
1737
  if (entry === excludeKey) continue;
1596
- if (entry === LAUNCHER_CHAT_KEY || entry === LAUNCHER_RESTART_KEY) {
1597
- const button = entry === LAUNCHER_CHAT_KEY ? chatButton : restartButton;
1598
- if (button !== null && button.isConnected === true) {
1599
- 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' });
1600
1742
  }
1601
1743
  continue;
1602
1744
  }
@@ -1624,6 +1766,9 @@
1624
1766
  if (button.hasAttribute('data-powerup-restart')) {
1625
1767
  return { kind: 'restart', key: LAUNCHER_RESTART_KEY, gridEl: button, label: t('launcher.restart') };
1626
1768
  }
1769
+ if (button.hasAttribute('data-powerup-close')) {
1770
+ return { kind: 'close', key: LAUNCHER_CLOSE_KEY, gridEl: button, label: t('launcher.close') };
1771
+ }
1627
1772
  const folderId = button.getAttribute('data-powerup-folder');
1628
1773
  if (folderId !== null) {
1629
1774
  const group = state.groups[folderId];
@@ -1725,8 +1870,7 @@
1725
1870
  const centerX = rect.left + rect.width / 2;
1726
1871
  const centerY = rect.top + rect.height / 2;
1727
1872
  const nearCenter = Math.abs(x - centerX) <= rect.width * 0.28 && Math.abs(y - centerY) <= rect.height * 0.32;
1728
- const special = isLauncherSpecialKey(candidate.key) || isLauncherSpecialKey(drag.descriptor.key);
1729
- if (nearCenter && !special) {
1873
+ if (nearCenter) {
1730
1874
  drop = { kind: 'merge', target: candidate };
1731
1875
  } else {
1732
1876
  drop = { kind: 'insert', index: candidates.indexOf(candidate) + (x < centerX ? 0 : 1), anchor: rect, after: x >= centerX };
@@ -1854,7 +1998,6 @@
1854
1998
 
1855
1999
  function performMerge(sourceKey, targetKey) {
1856
2000
  if (sourceKey === targetKey) return;
1857
- if (isLauncherSpecialKey(sourceKey) || isLauncherSpecialKey(targetKey)) return;
1858
2001
  const sourceGroupId = launcherEntryGroupId(sourceKey);
1859
2002
  const targetGroupId = launcherEntryGroupId(targetKey);
1860
2003
  if (sourceGroupId !== null && sourceGroupId === targetGroupId) return;
@@ -1951,6 +2094,10 @@
1951
2094
  restartButton.remove();
1952
2095
  restartButton = null;
1953
2096
  }
2097
+ if (closeButton !== null) {
2098
+ closeButton.remove();
2099
+ closeButton = null;
2100
+ }
1954
2101
  state = { order: [], groups: {} };
1955
2102
  pendingLoad = true;
1956
2103
  nav = null;
@@ -2030,6 +2177,14 @@
2030
2177
  void restartWithoutPrompt();
2031
2178
  return true;
2032
2179
  },
2180
+ openClose: () => {
2181
+ if (closePromptBridge.open !== null) {
2182
+ closePromptBridge.open();
2183
+ return true;
2184
+ }
2185
+ void closeWithoutPrompt();
2186
+ return true;
2187
+ },
2033
2188
  });
2034
2189
  ctx.effect(() => {
2035
2190
  core.start();
@@ -3050,6 +3205,8 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
3050
3205
  const POWERUP_REGISTRY_KEY = 'dsh-powerup:update-registry:v1';
3051
3206
  const PENDING_RESTART_KEY = 'dsh-powerup:pending-restart:v1';
3052
3207
  const UPDATE_API = '/dsh-powerup/api/restart';
3208
+ /** Host route that closes the whole application. */
3209
+ const CLOSE_API = '/dsh-powerup/api/close';
3053
3210
  const AUDIT_API = '/dsh-powerup/api/audit';
3054
3211
  const SELF_UPDATE_API = '/dsh-powerup/api/self-update';
3055
3212
  const JOB_KILL_API = '/dsh-powerup/api/job-kill';
@@ -4073,10 +4230,11 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
4073
4230
  const [view, setView] = useState(null);
4074
4231
  const [localeTick, forceLocale] = useState(0);
4075
4232
  const [pending, setPending] = useState(() => readPendingRestarts());
4076
- const [restartAsk, setRestartAsk] = useState(false);
4077
- const [restartCapability, setRestartCapability] = useState(null);
4078
- const [restartBusy, setRestartBusy] = useState(false);
4079
- 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);
4080
4238
  const tokenRef = useRef(null);
4081
4239
  const abortRef = useRef(null);
4082
4240
  const buttonsRef = useRef(new Set());
@@ -4491,18 +4649,18 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
4491
4649
  };
4492
4650
  }, [remote]);
4493
4651
 
4494
- // Escape dismisses the list-header restart confirmation unless a
4495
- // restart request is already in flight.
4652
+ // Escape dismisses the app-level confirmation unless its request is
4653
+ // already in flight.
4496
4654
  useEffect(() => {
4497
- if (!restartAsk) return undefined;
4655
+ if (appAsk === null) return undefined;
4498
4656
  const onKeyDown = (event) => {
4499
- if (event.key !== 'Escape' || restartBusy) return;
4657
+ if (event.key !== 'Escape' || appBusy) return;
4500
4658
  event.stopPropagation();
4501
- setRestartAsk(false);
4659
+ setAppAsk(null);
4502
4660
  };
4503
4661
  document.addEventListener('keydown', onKeyDown, true);
4504
4662
  return () => document.removeEventListener('keydown', onKeyDown, true);
4505
- }, [restartAsk, restartBusy]);
4663
+ }, [appAsk, appBusy]);
4506
4664
 
4507
4665
  // A one-click update that does not restart leaves a completion panel;
4508
4666
  // close it on its own so it never lingers over the Plugins page.
@@ -4743,10 +4901,10 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
4743
4901
  }
4744
4902
  };
4745
4903
 
4746
- /** Ask the Host route whether this runtime can restart itself. */
4747
- const readRestartCapability = async () => {
4904
+ /** Ask one Host app-control route whether this runtime supports it. */
4905
+ const readAppCapability = async (api) => {
4748
4906
  try {
4749
- const response = await fetch(UPDATE_API, { headers: { accept: 'application/json' } });
4907
+ const response = await fetch(api, { headers: { accept: 'application/json' } });
4750
4908
  const data = await response.json();
4751
4909
  return {
4752
4910
  supported: response.ok && data?.ok === true && data.supported === true,
@@ -4757,48 +4915,60 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
4757
4915
  }
4758
4916
  };
4759
4917
 
4760
- /** POST the restart command; throws when the Host refuses. */
4761
- const requestAppRestart = async () => {
4762
- 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, {
4763
4925
  method: 'POST',
4764
4926
  headers: { 'content-type': 'application/json' },
4765
- body: JSON.stringify({ action: 'restart' }),
4927
+ body: JSON.stringify({ action }),
4766
4928
  });
4767
4929
  const data = await response.json().catch(() => null);
4768
4930
  if (!response.ok || data?.ok !== true) throw new Error(data?.error ?? `HTTP ${response.status}`);
4769
4931
  };
4770
4932
 
4771
- /** Open the list-header restart confirmation and read the capability. */
4772
- const openRestart = () => {
4773
- setRestartAsk(true);
4774
- setRestartCapability(null);
4775
- setRestartError(null);
4776
- setRestartBusy(false);
4777
- 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));
4778
4944
  };
4779
- openRestartRef.current = openRestart;
4945
+ const openAppActionRef = useRef(() => {});
4946
+ openAppActionRef.current = openAppAction;
4947
+ openRestartRef.current = () => openAppActionRef.current('restart');
4780
4948
 
4781
4949
  // The sidebar launcher is plain DOM and cannot render React, so it
4782
- // calls this opener for its synthetic "restart DSH" tile. Keeping the
4783
- // 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
4784
4952
  // confirmation dialog, one capability read and one set of copy.
4785
4953
  useEffect(() => {
4786
- restartPromptBridge.open = () => openRestartRef.current();
4954
+ restartPromptBridge.open = () => openAppActionRef.current('restart');
4955
+ closePromptBridge.open = () => openAppActionRef.current('close');
4787
4956
  return () => {
4788
4957
  if (restartPromptBridge.open !== null) restartPromptBridge.open = null;
4958
+ if (closePromptBridge.open !== null) closePromptBridge.open = null;
4789
4959
  };
4790
4960
  }, []);
4791
4961
 
4792
- /** Confirm the list-header restart. */
4793
- const confirmRestart = async () => {
4794
- if (restartBusy) return;
4795
- setRestartBusy(true);
4796
- 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);
4797
4967
  try {
4798
- await requestAppRestart();
4968
+ await requestAppAction(appAsk === 'close' ? 'close' : 'restart');
4799
4969
  } catch (error) {
4800
- setRestartBusy(false);
4801
- setRestartError(errorText(error) || tRef.current('update.unknown'));
4970
+ setAppBusy(false);
4971
+ setAppError(errorText(error) || tRef.current('update.unknown'));
4802
4972
  }
4803
4973
  };
4804
4974
 
@@ -4863,10 +5033,11 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
4863
5033
  ),
4864
5034
  );
4865
5035
 
4866
- const restartPrompt = restartAsk ? h('div', {
5036
+ const appAction = appAsk === 'close' ? 'close' : 'restart';
5037
+ const appPrompt = appAsk === null ? null : h('div', {
4867
5038
  className: 'dsh-powerup-update-mask',
4868
5039
  onMouseDown: (event) => {
4869
- if (event.target === event.currentTarget && !restartBusy) setRestartAsk(false);
5040
+ if (event.target === event.currentTarget && !appBusy) setAppAsk(null);
4870
5041
  },
4871
5042
  },
4872
5043
  h('div', {
@@ -4874,43 +5045,43 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
4874
5045
  style: { width: 'min(420px,100%)' },
4875
5046
  role: 'dialog',
4876
5047
  'aria-modal': 'true',
4877
- 'aria-labelledby': 'dsh-powerup-restart-title',
5048
+ 'aria-labelledby': 'dsh-powerup-app-action-title',
4878
5049
  },
4879
5050
  h('div', { className: 'dsh-powerup-update-head' },
4880
5051
  h('div', { className: 'dsh-powerup-update-heading' },
4881
- 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')),
4882
5053
  /* A sidebar-initiated restart usually has no pending plugins, so the
4883
5054
  subtitle only appears when there is something to report. */
4884
- 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,
4885
5056
  ),
4886
- 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) }, '×'),
4887
5058
  ),
4888
5059
  h('div', { className: 'dsh-powerup-update-body' },
4889
- h('p', { className: 'dsh-powerup-update-note' }, t('restart.desc')),
4890
- restartCapability !== null && restartCapability.supported !== true
4891
- ? 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 ?? '' }))
4892
5063
  : null,
4893
- restartError === null ? null : notice('error', h(WarnIcon, { size: 14 }), null, restartError),
4894
- restartBusy
5064
+ appError === null ? null : notice('error', h(WarnIcon, { size: 14 }), null, appError),
5065
+ appBusy
4895
5066
  ? h('div', { className: 'dsh-powerup-update-status' },
4896
5067
  h('span', { className: 'dsh-powerup-update-spinner', 'aria-hidden': 'true' }),
4897
- t('update.restarting'),
5068
+ t(appAction === 'close' ? 'close.closing' : 'update.restarting'),
4898
5069
  )
4899
5070
  : null,
4900
5071
  ),
4901
5072
  h('div', { className: 'dsh-powerup-update-foot' },
4902
- 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')),
4903
5074
  h('button', {
4904
5075
  type: 'button',
4905
5076
  className: 'dsh-powerup-update-primary',
4906
- disabled: restartBusy || restartCapability?.supported !== true,
4907
- onClick: confirmRestart,
4908
- }, 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')),
4909
5080
  ),
4910
5081
  ),
4911
- ) : null;
5082
+ );
4912
5083
 
4913
- if (view === null) return restartPrompt;
5084
+ if (view === null) return appPrompt;
4914
5085
  const busy = view.phase === 'working' || view.phase === 'self-updating' || view.phase === 'restarting' || view.enabling === true;
4915
5086
  const canClose = !busy;
4916
5087
  const title = view.title === undefined || view.title === '' ? view.name : view.title;
@@ -5778,6 +5949,8 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
5778
5949
  LAUNCHER_CHAT_KEY,
5779
5950
  LAUNCHER_RESTART_KEY,
5780
5951
  LAUNCHER_RESTART_ICON,
5952
+ LAUNCHER_CLOSE_KEY,
5953
+ LAUNCHER_CLOSE_ICON,
5781
5954
  normalizeLauncherState,
5782
5955
  dissolveGroupOrder,
5783
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.6",
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",