@restregular/dsh-powerup 0.8.2 → 0.8.4

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.
Files changed (3) hide show
  1. package/README.md +18 -1
  2. package/client.js +223 -15
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -116,6 +116,14 @@ entries other plugins add) become an icon grid instead of a one-per-row list:
116
116
  its own (chat glyph + label) that calls `layout.selectPanel(null)` to return
117
117
  to the Conversation; it highlights when no global panel is selected, can be
118
118
  placed anywhere by dragging, and never joins a folder either.
119
+ - **Ungroup expands in place.** Dissolving a folder puts its icons back on the
120
+ grid exactly where the folder sat, in the folder's own order — nothing jumps
121
+ to the end of the grid.
122
+ - **Drag inside a folder.** Tiles in the flyout are drag handles: drag one over
123
+ another to reorder the folder's contents, or drag it out of the flyout and
124
+ drop it anywhere else to put it back on the grid right after the folder
125
+ (the folder dissolves once it is empty). The folder flyout never re-renders
126
+ while it is being dragged.
119
127
  - **Collapsed sidebar stays native.** When the sidebar collapses to its 56px
120
128
  rail there are no labels to stack, so the launcher steps aside and the host's
121
129
  rail rendering takes over untouched.
@@ -212,7 +220,16 @@ fiber is unloaded. The panel closes; refresh the page when the install finishes.
212
220
  would drop an added class), and sorts with the grid's `order` property. Host
213
221
  rows are resolved by shape — a direct `<button>`, or a wrapper (the More
214
222
  launcher's `Menu` root `<span>`) whose direct child is that button — because
215
- the wrapper element differs between the panel rows and the more menu. A
223
+ the wrapper element differs between the panel rows and the more menu.
224
+ - **Every sync write is idempotent.** The launcher observes its own `<nav>`
225
+ with a `MutationObserver`, so a write that changes a watched subtree on every
226
+ sync turns into an infinite loop — and a loop rebuilds the folder flyout
227
+ continuously, which makes normal clicks miss (the node under the pointer is
228
+ replaced between `pointerdown` and `click`). Setting `textContent` to the same
229
+ string still emits a `childList` mutation, so the synthetic chat tile only
230
+ writes its label when it actually changed, folder tiles rebuild only when
231
+ their signature changed, and the flyout re-renders only when its roster or
232
+ name changed. A
216
233
  `MutationObserver` re-applies that after every host render, and the module
217
234
  falls back to the native rail whenever the wide layout disappears.
218
235
  - **Launcher state is tiny and self-healing.** `dsh-powerup:launcher:v1` stores
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.2';
72
+ const VERSION = '0.8.4';
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. */
@@ -630,6 +630,30 @@
630
630
  return { order, groups };
631
631
  }
632
632
 
633
+ /**
634
+ * Replace a folder entry with its members, in the folder's own order, at
635
+ * the exact position the folder occupied. Used by "ungroup" so dissolving
636
+ * a folder is a pure expansion and never scatters the icons to the end.
637
+ * @param {string[]} order current top-level order
638
+ * @param {string} folderEntry the `group:<id>` entry being dissolved
639
+ * @param {string[]} items member keys in folder order
640
+ * @returns {string[]} the new top-level order
641
+ */
642
+ function dissolveGroupOrder(order, folderEntry, items) {
643
+ const source = Array.isArray(order) ? order : [];
644
+ const list = source.filter((entry) => entry !== folderEntry);
645
+ const index = source.indexOf(folderEntry);
646
+ const members = [];
647
+ for (const key of Array.isArray(items) ? items : []) {
648
+ if (typeof key !== 'string' || key === '' || key.startsWith('__')) continue;
649
+ if (list.includes(key) || members.includes(key)) continue;
650
+ members.push(key);
651
+ }
652
+ const insertAt = index < 0 ? list.length : Math.min(index, list.length);
653
+ list.splice(insertAt, 0, ...members);
654
+ return list;
655
+ }
656
+
633
657
  /**
634
658
  * DOM-driven controller for the sidebar launcher.
635
659
  *
@@ -671,6 +695,7 @@
671
695
  let dropLine = null;
672
696
  let drag = null;
673
697
  let popup = null;
698
+ let popupDrag = null;
674
699
 
675
700
  function warn(message, error) {
676
701
  try {
@@ -982,7 +1007,7 @@
982
1007
  chat.setAttribute('aria-label', chatLabel);
983
1008
  chat.setAttribute('title', chatLabel);
984
1009
  const chatText = typeof chat.querySelector === 'function' ? chat.querySelector('.dsh-powerup-chat-label') : null;
985
- if (chatText !== null) chatText.textContent = chatLabel;
1010
+ if (chatText !== null && chatText.textContent !== chatLabel) chatText.textContent = chatLabel;
986
1011
  chat.style.display = wide ? '' : 'none';
987
1012
  const chatPosition = orderIndex.get(LAUNCHER_CHAT_KEY);
988
1013
  chat.style.order = chatPosition === undefined ? '' : String(chatPosition);
@@ -1002,9 +1027,9 @@
1002
1027
  button.remove();
1003
1028
  folderButtons.delete(groupId);
1004
1029
  }
1005
- if (popup !== null) {
1030
+ if (popup !== null && popupDrag === null) {
1006
1031
  if (state.groups[popup.groupId] === undefined) closePopup();
1007
- else renderPopup();
1032
+ else refreshPopup();
1008
1033
  }
1009
1034
  } catch (error) {
1010
1035
  warn('launcher sync failed:', error);
@@ -1059,6 +1084,7 @@
1059
1084
 
1060
1085
  function closePopup() {
1061
1086
  if (popup === null) return;
1087
+ endPopupDrag();
1062
1088
  const element = popup.element;
1063
1089
  popup = null;
1064
1090
  document.removeEventListener('pointerdown', onPopupOutside, true);
@@ -1131,6 +1157,25 @@
1131
1157
  element.style.transformOrigin = originX + ' 22%';
1132
1158
  }
1133
1159
 
1160
+ function popupSignature(group) {
1161
+ return group.name + '\u0000' + group.items.join('\u0000');
1162
+ }
1163
+
1164
+ /** Re-render the flyout only when its roster or name actually changed. */
1165
+ function refreshPopup() {
1166
+ if (popup === null) return;
1167
+ const group = state.groups[popup.groupId];
1168
+ if (group === undefined) {
1169
+ closePopup();
1170
+ return;
1171
+ }
1172
+ if (popup.signature === popupSignature(group)) {
1173
+ positionPopup();
1174
+ return;
1175
+ }
1176
+ renderPopup();
1177
+ }
1178
+
1134
1179
  function renderPopup() {
1135
1180
  if (popup === null) return;
1136
1181
  const group = state.groups[popup.groupId];
@@ -1138,6 +1183,7 @@
1138
1183
  closePopup();
1139
1184
  return;
1140
1185
  }
1186
+ popup.signature = popupSignature(group);
1141
1187
  const element = popup.element;
1142
1188
  element.textContent = '';
1143
1189
  const head = document.createElement('div');
@@ -1168,6 +1214,7 @@
1168
1214
  item.setAttribute('role', 'button');
1169
1215
  item.setAttribute('tabindex', '0');
1170
1216
  item.setAttribute('aria-label', tile.label);
1217
+ item.setAttribute('data-powerup-item', key);
1171
1218
  const glyph = document.createElement('span');
1172
1219
  glyph.className = 'dsh-powerup-folder-item-glyph';
1173
1220
  glyph.innerHTML = tile.glyphHtml;
@@ -1193,7 +1240,11 @@
1193
1240
  removeFromGroup(popup === null ? null : popup.groupId, key);
1194
1241
  });
1195
1242
  item.append(glyph, label, remove);
1196
- item.addEventListener('click', () => selectPanel(tile));
1243
+ item.addEventListener('pointerdown', onPopupItemPointerDown);
1244
+ item.addEventListener('click', () => {
1245
+ if (popupDrag !== null && popupDrag.moved === true) return;
1246
+ selectPanel(tile);
1247
+ });
1197
1248
  item.addEventListener('keydown', (event) => {
1198
1249
  if (event.key !== 'Enter' && event.key !== ' ') return;
1199
1250
  event.preventDefault();
@@ -1205,6 +1256,140 @@
1205
1256
  positionPopup();
1206
1257
  }
1207
1258
 
1259
+ // ----------------------------------------------------------------
1260
+ // Drag inside the flyout: reorder members, or drag one out to the grid
1261
+ // ----------------------------------------------------------------
1262
+ function popupItemElements() {
1263
+ if (popup === null) return [];
1264
+ return [...popup.element.querySelectorAll('.dsh-powerup-folder-item')];
1265
+ }
1266
+
1267
+ function onPopupItemPointerDown(event) {
1268
+ if (popup === null) return;
1269
+ if (event.button !== undefined && event.button !== 0) return;
1270
+ const target = event.target;
1271
+ if (target === null || target === undefined || typeof target.closest !== 'function') return;
1272
+ if (target.closest('.dsh-powerup-folder-item-remove') !== null) return;
1273
+ const item = target.closest('.dsh-powerup-folder-item');
1274
+ if (item === null) return;
1275
+ const key = item.getAttribute('data-powerup-item');
1276
+ if (key === null || key === '') return;
1277
+ popupDrag = {
1278
+ groupId: popup.groupId,
1279
+ key,
1280
+ item,
1281
+ startX: event.clientX,
1282
+ startY: event.clientY,
1283
+ active: false,
1284
+ moved: false,
1285
+ outside: false,
1286
+ ghost: null,
1287
+ offsetX: 0,
1288
+ offsetY: 0,
1289
+ };
1290
+ document.addEventListener('pointermove', onPopupItemMove, { capture: true, passive: false });
1291
+ document.addEventListener('pointerup', onPopupItemUp, true);
1292
+ document.addEventListener('pointercancel', onPopupItemUp, true);
1293
+ }
1294
+
1295
+ function beginPopupDrag() {
1296
+ if (popupDrag === null || popup === null) return;
1297
+ popupDrag.active = true;
1298
+ popupDrag.moved = true;
1299
+ const rect = popupDrag.item.getBoundingClientRect();
1300
+ const ghost = popupDrag.item.cloneNode(true);
1301
+ ghost.className = 'dsh-powerup-folder-item-ghost';
1302
+ ghost.removeAttribute('data-powerup-item');
1303
+ ghost.style.width = rect.width + 'px';
1304
+ ghost.style.height = rect.height + 'px';
1305
+ ghost.style.left = rect.left + 'px';
1306
+ ghost.style.top = rect.top + 'px';
1307
+ document.body.appendChild(ghost);
1308
+ popupDrag.ghost = ghost;
1309
+ popupDrag.offsetX = popupDrag.startX - rect.left;
1310
+ popupDrag.offsetY = popupDrag.startY - rect.top;
1311
+ popupDrag.item.classList.add('is-dragging');
1312
+ popup.element.classList.add('is-reordering');
1313
+ }
1314
+
1315
+ function onPopupItemMove(event) {
1316
+ if (popupDrag === null || popup === null) return;
1317
+ if (!popupDrag.active) {
1318
+ const dx = event.clientX - popupDrag.startX;
1319
+ const dy = event.clientY - popupDrag.startY;
1320
+ if (Math.sqrt(dx * dx + dy * dy) < 5) return;
1321
+ beginPopupDrag();
1322
+ }
1323
+ if (typeof event.preventDefault === 'function') event.preventDefault();
1324
+ if (popupDrag.ghost !== null) {
1325
+ popupDrag.ghost.style.left = Math.round(event.clientX - popupDrag.offsetX) + 'px';
1326
+ popupDrag.ghost.style.top = Math.round(event.clientY - popupDrag.offsetY) + 'px';
1327
+ }
1328
+ const rect = popup.element.getBoundingClientRect();
1329
+ const outside = event.clientX < rect.left - 12 || event.clientX > rect.right + 12
1330
+ || event.clientY < rect.top - 12 || event.clientY > rect.bottom + 12;
1331
+ if (outside !== popupDrag.outside) {
1332
+ popupDrag.outside = outside;
1333
+ popup.element.classList.toggle('is-dragging-out', outside);
1334
+ }
1335
+ if (outside) return;
1336
+ const hit = typeof document.elementFromPoint === 'function' ? document.elementFromPoint(event.clientX, event.clientY) : null;
1337
+ const targetItem = hit !== null && hit !== undefined && typeof hit.closest === 'function' ? hit.closest('.dsh-powerup-folder-item') : null;
1338
+ if (targetItem === null || targetItem === popupDrag.item || popup.element.contains(targetItem) !== true) return;
1339
+ const targetRect = targetItem.getBoundingClientRect();
1340
+ const centerX = targetRect.left + targetRect.width / 2;
1341
+ const centerY = targetRect.top + targetRect.height / 2;
1342
+ /* Same row → compare along the row; another row → compare vertically. */
1343
+ const sameRow = Math.abs(event.clientY - centerY) <= targetRect.height / 2;
1344
+ const before = sameRow ? event.clientX < centerX : event.clientY < centerY;
1345
+ const grid = targetItem.parentNode;
1346
+ if (grid === null) return;
1347
+ if (before) grid.insertBefore(popupDrag.item, targetItem);
1348
+ else grid.insertBefore(popupDrag.item, targetItem.nextSibling);
1349
+ }
1350
+
1351
+ function endPopupDrag() {
1352
+ document.removeEventListener('pointermove', onPopupItemMove, { capture: true, passive: false });
1353
+ document.removeEventListener('pointerup', onPopupItemUp, true);
1354
+ document.removeEventListener('pointercancel', onPopupItemUp, true);
1355
+ if (popupDrag !== null) {
1356
+ if (popupDrag.ghost !== null) popupDrag.ghost.remove();
1357
+ if (popupDrag.item !== undefined) popupDrag.item.classList.remove('is-dragging');
1358
+ if (popup !== null) popup.element.classList.remove('is-reordering', 'is-dragging-out');
1359
+ }
1360
+ popupDrag = null;
1361
+ }
1362
+
1363
+ function onPopupItemUp() {
1364
+ if (popupDrag === null) return;
1365
+ const data = popupDrag;
1366
+ const active = data.active;
1367
+ const outside = data.outside;
1368
+ endPopupDrag();
1369
+ if (!active) return;
1370
+ suppressNextClick();
1371
+ if (popup === null) return;
1372
+ if (outside) {
1373
+ if (detachFromGroup(data.groupId, data.key)) {
1374
+ closePopup();
1375
+ sync();
1376
+ }
1377
+ return;
1378
+ }
1379
+ const group = state.groups[data.groupId];
1380
+ if (group === undefined) return;
1381
+ const items = popupItemElements()
1382
+ .map((element) => element.getAttribute('data-powerup-item'))
1383
+ .filter((key) => typeof key === 'string' && key !== '');
1384
+ if (items.length !== group.items.length) {
1385
+ renderPopup();
1386
+ return;
1387
+ }
1388
+ state = { order: state.order, groups: { ...state.groups, [data.groupId]: { ...group, items } } };
1389
+ save();
1390
+ sync();
1391
+ }
1392
+
1208
1393
  function beginRename() {
1209
1394
  if (popup === null) return;
1210
1395
  const group = state.groups[popup.groupId];
@@ -1257,22 +1442,37 @@
1257
1442
  closePopup();
1258
1443
  }
1259
1444
 
1260
- function removeFromGroup(groupId, key) {
1261
- if (groupId === null || typeof groupId !== 'string' || typeof key !== 'string') return;
1445
+ /**
1446
+ * Take one member out of a folder and put it back on the grid right
1447
+ * after the folder (the folder dissolves when it becomes empty).
1448
+ * @returns {boolean} whether the member was removed.
1449
+ */
1450
+ function detachFromGroup(groupId, key) {
1451
+ if (groupId === null || typeof groupId !== 'string' || typeof key !== 'string') return false;
1262
1452
  const group = state.groups[groupId];
1263
- if (group === undefined) return;
1453
+ if (group === undefined) return false;
1264
1454
  const items = group.items.filter((entry) => entry !== key);
1265
- const order = state.order.filter((entry) => entry !== key);
1266
1455
  const groups = { ...state.groups };
1456
+ const folderEntry = launcherGroupEntry(groupId);
1457
+ let order = state.order.filter((entry) => entry !== key);
1458
+ const folderIndex = order.indexOf(folderEntry);
1267
1459
  if (items.length === 0) {
1268
1460
  delete groups[groupId];
1269
- state = { order: order.filter((entry) => entry !== launcherGroupEntry(groupId)), groups };
1461
+ order = order.filter((entry) => entry !== folderEntry);
1462
+ if (folderIndex >= 0) order.splice(folderIndex, 0, key);
1463
+ else order.push(key);
1270
1464
  } else {
1271
1465
  groups[groupId] = { ...group, items };
1272
- order.push(key);
1273
- state = { order, groups };
1466
+ const insertAt = folderIndex >= 0 ? folderIndex + 1 : order.length;
1467
+ order.splice(insertAt, 0, key);
1274
1468
  }
1469
+ state = { order: dedupeEntries(order), groups };
1275
1470
  save();
1471
+ return true;
1472
+ }
1473
+
1474
+ function removeFromGroup(groupId, key) {
1475
+ if (!detachFromGroup(groupId, key)) return;
1276
1476
  sync();
1277
1477
  }
1278
1478
 
@@ -1282,9 +1482,7 @@
1282
1482
  if (group === undefined) return;
1283
1483
  const groups = { ...state.groups };
1284
1484
  delete groups[groupId];
1285
- const order = state.order
1286
- .filter((entry) => entry !== launcherGroupEntry(groupId))
1287
- .concat(group.items.filter((key) => !state.order.includes(key)));
1485
+ const order = dissolveGroupOrder(state.order, launcherGroupEntry(groupId), group.items);
1288
1486
  state = { order, groups };
1289
1487
  save();
1290
1488
  closePopup();
@@ -2095,6 +2293,15 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
2095
2293
  .dsh-powerup-folder-item-remove{position:absolute;top:1px;right:2px;display:inline-flex;align-items:center;justify-content:center;width:15px;height:15px;padding:0;border:0;border-radius:50%;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-tertiary);font:inherit;font-size:11px;line-height:15px;cursor:pointer;opacity:0;transition:opacity .12s ease}
2096
2294
  .dsh-powerup-folder-item:hover .dsh-powerup-folder-item-remove,.dsh-powerup-folder-item-remove:focus-visible{opacity:1}
2097
2295
  .dsh-powerup-folder-item-remove:hover{color:var(--dsw-alias-label-primary)}
2296
+ .dsh-powerup-folder-item[data-powerup-item]{cursor:grab;touch-action:none;user-select:none;-webkit-user-select:none}
2297
+ .dsh-powerup-folder-item.is-dragging{opacity:.3}
2298
+ .dsh-powerup-folder-pop.is-reordering{overflow:visible}
2299
+ .dsh-powerup-folder-pop.is-dragging-out{opacity:.7;transform:scale(.97)}
2300
+ .dsh-powerup-folder-item-ghost{position:fixed;z-index:1900;box-sizing:border-box;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;padding:6px 2px 5px;border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-layer-2);box-shadow:var(--dsw-elevation-prominent);color:var(--dsw-alias-label-primary);font-size:11px;line-height:14px;pointer-events:none;opacity:.96;transform:scale(1.05)}
2301
+ .dsh-powerup-folder-item-ghost .dsh-powerup-folder-item-glyph{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;flex:none;color:var(--dsw-alias-label-secondary)}
2302
+ .dsh-powerup-folder-item-ghost .dsh-powerup-folder-item-glyph svg{width:20px;height:20px}
2303
+ .dsh-powerup-folder-item-ghost .dsh-powerup-folder-item-label{display:block;width:100%;max-width:100%;color:var(--dsw-alias-label-secondary);text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
2304
+ .dsh-powerup-folder-item-ghost .dsh-powerup-folder-item-remove{display:none}
2098
2305
  @media (prefers-reduced-motion:reduce){nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button,nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>[data-powerup-more]>button,.dsh-powerup-folder,.dsh-powerup-folder-pop,.dsh-powerup-drag-ghost,.dsh-powerup-drop-line{transition:none}}
2099
2306
  `;
2100
2307
 
@@ -5443,6 +5650,7 @@ nav.dsh-powerup-launcher.dsh-powerup-launcher-wide>button:hover [class*="panelTi
5443
5650
  LAUNCHER_CSS,
5444
5651
  LAUNCHER_STORAGE_KEY,
5445
5652
  normalizeLauncherState,
5653
+ dissolveGroupOrder,
5446
5654
  createLauncherCore,
5447
5655
  installLauncher,
5448
5656
  PowerUpLineIcon,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-powerup",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
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 页面调整默认行为。 · 侧边栏启动器:把左侧边栏的面板按钮变成随宽度自适应的图标网格(图标在上、文字在下),支持拖拽排序与分组(拖到另一个图标中间即合并为分组,点击分组弹出浮层展示内部图标),可随时整体关闭。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",