dsh-sidebar-shelves 0.1.0 → 0.1.2

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
@@ -5,9 +5,11 @@ English | [中文](#中文)
5
5
  Two-line session cards for the [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) sidebar.
6
6
 
7
7
  - **Project tiles** — every Workspace gets a tile: a name-derived monogram and color, or the emoji, color, or square image file you pick. Icon Composer `.icon` packages work too.
8
- - **Pinning** — pinned sessions lead the list; pinning is independent of archiving.
9
- - **Archiving** — archive a session by hand, or let cards archive themselves after 3, 7, 14, or 30 days. Archived sessions drop to the Archived shelf at the bottom.
10
- - **Status markers** — running and waiting markers, plus a terminal marker on sessions that own one.
8
+ - **Pinning** — pinned sessions lead the list; pinning applies to active sessions, and archiving clears the pin.
9
+ - **Context menu** — right-click a card to pin, rename, fork, copy the Session ID, archive it, or remove its project; Shift+F10 opens the same menu from the keyboard.
10
+ - **Project menu** — right-click a card's project tile or name to change its icon or remove the project; removal only unregisters the workspace and keeps its folder and sessions.
11
+ - **Archiving** — archive a session by hand, or let cards archive themselves after 3, 7, 14, or 30 days. Archiving the session on screen opens the next card below (the one above when it was last) instead of the New Session page. Archived sessions drop to the Archived shelf at the bottom; expanding it scrolls within a capped area, and a click anywhere outside it folds it back.
12
+ - **Status markers** — running and waiting markers; a running session's time takes the brand accent, and a terminal marker flags sessions that own one.
11
13
  - **Activity counts** — running background jobs and subagents per session, folded on the Host from the Session's own job records.
12
14
  - **Recency sorting** — newest input first, and the composer's Workspace menu reuses the same tiles and the same order.
13
15
  - **Header tile** — the open session's Workspace tile sits just before its title in the conversation header.
@@ -53,9 +55,11 @@ MIT
53
55
  DeepSeek Harness 侧边栏的会话卡片:每个会话是一张两行卡片。
54
56
 
55
57
  - **项目图标** — 每个工作区一个图标:按名称生成的字母块与配色,或你选的 emoji、颜色、方形图片;也支持 Icon Composer 的 `.icon` 图标包。
56
- - **置顶** — 置顶会话排在最前,与归档互不影响。
57
- - **归档** — 手动归档,或按 3、7、14、30 天自动归档;归档的会话收进底部的「已归档」。
58
- - **状态标记** — 运行中、等待中标记,以及带终端会话的终端标记。
58
+ - **置顶** — 置顶会话排在最前,仅适用于活跃会话;归档时会自动取消置顶。
59
+ - **右键菜单** — 在会话卡片上右键可置顶、重命名、分叉、复制会话 ID、归档或移除所属项目;键盘上 Shift+F10 打开同一菜单。
60
+ - **项目菜单** — 在卡片的项目图标或项目名上右键,可更改项目图标或移除项目;移除只取消工作区注册,文件夹和会话都会保留。
61
+ - **归档** — 手动归档,或按 3、7、14、30 天自动归档;归档当前会话后自动打开列表中的下一张卡片(它是最后一张时打开上一张),不再停在新建会话页。归档的会话收进底部的「已归档」,展开后在限定高度内滚动,点击该区域以外的任何地方自动收起。
62
+ - **状态标记** — 运行中、等待中标记;运行中会话的时间改用品牌色高亮,带终端会话另显示终端标记。
59
63
  - **活动计数** — 每个会话运行中的后台任务与子代理数量,由 Host 端从会话自身的任务记录折叠得出。
60
64
  - **按最近输入排序** — 输入框的工作区菜单复用同一套图标和同一套顺序。
61
65
  - **标题前图标** — 打开的会话在标题前显示所属工作区的图标。
package/client.js CHANGED
@@ -13,6 +13,9 @@
13
13
  * session leaves the list only when the user archives it. Pinning is local and
14
14
  * independent of archiving.
15
15
  *
16
+ * A card's context menu mirrors the native Session menu where the running DSH
17
+ * offers the same verbs: pin, rename, fork, copy the Session id, and archive.
18
+ *
16
19
  * The composer's workspace menu is the second occupant: it draws each Workspace
17
20
  * with the same project tile and orders them by their newest session, so the
18
21
  * sidebar and the picker share one icon set and one recency rule. The third is
@@ -23,7 +26,7 @@ window.__ModuleLoader__.load({
23
26
  id: 'dsh-sidebar-shelves',
24
27
  factory(require) {
25
28
  const React = require('react');
26
- const { Button, IconPlusOutlineRegular, Menu, Modal } = require('@deepseek-ai/dsh-client-ui-primitives');
29
+ const { Button, IconPlusOutlineRegular, Menu, Modal, Toast, writeClipboard } = require('@deepseek-ai/dsh-client-ui-primitives');
27
30
  const h = React.createElement;
28
31
  const NS = 'dsh.sidebarShelves';
29
32
 
@@ -36,6 +39,9 @@ window.__ModuleLoader__.load({
36
39
  // Mirrors the Host half's projection key; the Host folds owned jobs there.
37
40
  const JOB_ACTIVITY_KEY = 'sidebarShelvesJobActivity';
38
41
  const AUTO_ARCHIVE_CHOICES = [3, 7, 14, 30];
42
+ // The settings panel floats over the column instead of joining its flow, so
43
+ // its box is placed from the gear's own rect.
44
+ const SETTINGS_POPOVER_WIDTH = 232;
39
45
 
40
46
  // t3code's project palette: the same name always lands on the same slot, so a
41
47
  // project keeps its color without anything being stored. Light mode uses the
@@ -100,6 +106,23 @@ window.__ModuleLoader__.load({
100
106
  'action.unarchive': '取消归档',
101
107
  'action.pin': '置顶会话',
102
108
  'action.unpin': '取消置顶',
109
+ 'action.rename': '重命名…',
110
+ 'action.fork': '分叉会话',
111
+ 'action.copyId': '复制会话 ID',
112
+ 'action.copyIdDone': '已复制会话 ID',
113
+ 'action.copyIdFailed': '复制会话 ID 失败',
114
+ 'action.forkFailed': '无法分叉会话',
115
+ 'action.removeProject': '移除项目',
116
+ 'remove.title': '移除项目',
117
+ 'remove.desc': '将把“{name}”从侧边栏的项目中移除。文件夹与会话记录会保留,其会话将显示为未分组。',
118
+ 'remove.pending': '正在移除项目…',
119
+ 'remove.confirm': '移除',
120
+ 'remove.cancel': '取消',
121
+ 'remove.done': '已移除项目',
122
+ 'rename.title': '重命名会话',
123
+ 'rename.confirm': '确定',
124
+ 'rename.cancel': '取消',
125
+ 'rename.empty': '标题不能为空',
103
126
  'menu.addWorkspace': '添加工作区…',
104
127
  'menu.addFailed': '无法添加工作区',
105
128
  'menu.addRetry': '重试',
@@ -145,6 +168,23 @@ window.__ModuleLoader__.load({
145
168
  'action.unarchive': 'Unarchive session',
146
169
  'action.pin': 'Pin session',
147
170
  'action.unpin': 'Unpin session',
171
+ 'action.rename': 'Rename…',
172
+ 'action.fork': 'Fork session',
173
+ 'action.copyId': 'Copy Session ID',
174
+ 'action.copyIdDone': 'Session ID copied',
175
+ 'action.copyIdFailed': 'Could not copy Session ID',
176
+ 'action.forkFailed': 'Could not fork session',
177
+ 'action.removeProject': 'Remove project',
178
+ 'remove.title': 'Remove project',
179
+ 'remove.desc': 'This removes “{name}” from the sidebar projects. The folder and its sessions are kept; its sessions become ungrouped.',
180
+ 'remove.pending': 'Removing project…',
181
+ 'remove.confirm': 'Remove',
182
+ 'remove.cancel': 'Cancel',
183
+ 'remove.done': 'Project removed',
184
+ 'rename.title': 'Rename session',
185
+ 'rename.confirm': 'Rename',
186
+ 'rename.cancel': 'Cancel',
187
+ 'rename.empty': 'Title cannot be empty',
148
188
  'menu.addWorkspace': 'Add workspace…',
149
189
  'menu.addFailed': 'Could not add workspace',
150
190
  'menu.addRetry': 'Try again',
@@ -182,7 +222,9 @@ window.__ModuleLoader__.load({
182
222
  '.dsh-shelves-scroll{display:flex;flex-direction:column;flex:1 1 auto;min-height:0;overflow-y:auto;scrollbar-width:none;-ms-overflow-style:none}',
183
223
  '.dsh-shelves-scroll::-webkit-scrollbar{display:none;width:0;height:0}',
184
224
  '.dsh-shelves-stack{display:flex;flex:1 1 auto;flex-direction:column;gap:2px;padding:6px 4px 10px}',
185
- '.dsh-shelves-bottom{display:flex;flex-direction:column;gap:2px;margin-top:auto}',
225
+ '.dsh-shelves-bottom{display:flex;flex-direction:column;gap:2px;margin-top:auto;padding-top:6px;border-top:1px solid var(--dsw-alias-border-l1)}',
226
+ '.dsh-shelves-archived-list{display:flex;flex-direction:column;gap:2px;max-height:min(360px,42vh);overflow-y:auto;overscroll-behavior:contain;scrollbar-width:none;-ms-overflow-style:none}',
227
+ '.dsh-shelves-archived-list::-webkit-scrollbar{display:none;width:0;height:0}',
186
228
  '.dsh-shelves-headrow{display:flex;align-items:center;gap:2px;margin-top:6px}',
187
229
  '.dsh-shelves-head{display:flex;flex:1 1 auto;align-items:center;gap:6px;box-sizing:border-box;height:32px;padding:0 6px;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;font-weight:500;text-align:left;cursor:pointer}',
188
230
  '.dsh-shelves-head:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2))}',
@@ -193,7 +235,7 @@ window.__ModuleLoader__.load({
193
235
  '.dsh-shelves-gear{display:inline-flex;flex:none;align-items:center;justify-content:center;box-sizing:border-box;width:26px;height:26px;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer;opacity:.6}',
194
236
  '.dsh-shelves-gear:hover,.dsh-shelves-gear[aria-expanded="true"]{opacity:1;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2))}',
195
237
  '.dsh-shelves-gear:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}',
196
- '.dsh-shelves-settings{margin:4px 0 6px;padding:8px 10px 10px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;background:var(--dsw-alias-bg-layer-1)}',
238
+ '.dsh-shelves-settings{position:fixed;z-index:60;display:flex;flex-direction:column;box-sizing:border-box;padding:8px 10px 10px;border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-overlay);box-shadow:0 10px 28px #00000033}',
197
239
  '.dsh-shelves-settings-title{margin-bottom:2px;font-size:11px;font-weight:500;letter-spacing:.03em;color:var(--dsw-alias-label-secondary)}',
198
240
  '.dsh-shelves-setting{display:flex;align-items:center;justify-content:space-between;gap:10px;min-height:28px;font-size:12px;color:var(--dsw-alias-label-primary)}',
199
241
  '.dsh-shelves-select{position:relative;display:inline-flex;align-items:center}',
@@ -203,7 +245,7 @@ window.__ModuleLoader__.load({
203
245
  '.dsh-shelves-row{position:relative;display:flex;box-sizing:border-box;flex-direction:column;justify-content:center;width:100%;min-height:56px;padding:5px 10px;border-radius:8px;color:var(--dsw-alias-label-primary);font-size:14px;text-align:left;cursor:pointer;user-select:none}',
204
246
  '.dsh-shelves-row:hover{background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2))}',
205
247
  '.dsh-shelves-row:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}',
206
- '.dsh-shelves-row-selected{background:var(--dsw-alias-bg-layer-2)}',
248
+ '.dsh-shelves-row-selected{background:var(--dsw-specific-sidebar-nav-item-active,var(--dsw-alias-bg-layer-2))}',
207
249
  '.dsh-shelves-titleline{display:flex;align-items:center;gap:6px;min-width:0;min-height:22px}',
208
250
  '.dsh-shelves-title{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:500}',
209
251
  '.dsh-shelves-title-done{font-weight:700}',
@@ -217,6 +259,9 @@ window.__ModuleLoader__.load({
217
259
  '.dsh-shelves-badge-n{color:var(--dsw-alias-label-secondary)}',
218
260
  '.dsh-shelves-term{display:inline-flex;flex:none;align-items:center;color:var(--dsw-alias-state-business-primary)}',
219
261
  '.dsh-shelves-time{margin-left:auto;flex:none;font-size:12px;font-variant-numeric:tabular-nums;opacity:.7;transition:opacity .12s ease}',
262
+ // A working session's time carries the same brand color as its spinner, so
263
+ // the row reads as live without a second kind of accent.
264
+ '.dsh-shelves-time-running{color:var(--dsw-alias-brand-primary);font-weight:500;opacity:1}',
220
265
  '.dsh-shelves-status{display:inline-flex;align-items:center;justify-content:center;transition:opacity .12s ease}',
221
266
  '.dsh-shelves-status-working{color:var(--dsw-alias-brand-primary)}',
222
267
  '.dsh-shelves-status-warn{color:var(--dsw-alias-state-warn-primary)}',
@@ -307,6 +352,14 @@ window.__ModuleLoader__.load({
307
352
  '.dsh-shelves-files-btn:disabled{opacity:.45;cursor:default}',
308
353
  '.dsh-shelves-files-btn-primary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-base)}',
309
354
  '.dsh-shelves-files-btn-primary:hover{background:color-mix(in srgb,var(--dsw-alias-label-primary) 86%,var(--dsw-alias-bg-base))}',
355
+ '.dsh-shelves-rename{display:flex;flex-direction:column;gap:6px}',
356
+ '.dsh-shelves-rename input{box-sizing:border-box;width:100%;height:34px;padding:0 10px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;outline:none}',
357
+ '.dsh-shelves-rename input:focus{border-color:var(--dsw-alias-brand-primary)}',
358
+ '.dsh-shelves-rename-error{font-size:12px;color:var(--dsw-alias-state-error-primary)}',
359
+ '.dsh-shelves-remove{display:flex;flex-direction:column;gap:8px;font-size:13px;line-height:1.5;color:var(--dsw-alias-label-primary)}',
360
+ '.dsh-shelves-remove-pending{font-size:12px;color:var(--dsw-alias-label-secondary)}',
361
+ '.dsh-shelves-remove-error{font-size:12px;color:var(--dsw-alias-state-error-primary)}',
362
+ '.dsh-shelves-danger{color:var(--dsw-alias-state-error-primary)}',
310
363
  '.dsh-shelves-row:hover .dsh-shelves-time,.dsh-shelves-row:focus-within .dsh-shelves-time{opacity:0}',
311
364
  '.dsh-shelves-empty{padding:16px 10px;color:var(--dsw-alias-label-secondary);font-size:12px}',
312
365
  '.dsh-shelves-rail{display:inline-flex;flex:none;align-items:center;justify-content:center;box-sizing:border-box;width:36px;height:36px;margin:0 auto;border:0;border-radius:10px;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:11px;font-variant-numeric:tabular-nums;cursor:pointer}',
@@ -335,8 +388,12 @@ window.__ModuleLoader__.load({
335
388
  gear: 'M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM19.4 15a1.7 1.7 0 0 0 .3 1.9l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-2.9 1.2v.2a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-2.9-1.2l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1A1.7 1.7 0 0 0 3 15H2.9a2 2 0 1 1 0-4H3a1.7 1.7 0 0 0 1.2-2.9l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1A1.7 1.7 0 0 0 10 4.1V4a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 2.9 1.2l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1A1.7 1.7 0 0 0 21 11h.1a2 2 0 1 1 0 4H21a1.7 1.7 0 0 0-1.6 1z',
336
389
  pin: 'M12 17v5M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z',
337
390
  unarchive: 'M3.5 5.5h17v3.5h-17zM5.5 9v9.5h13V9M12 15.5V10M9.5 12.5l2.5-2.5 2.5 2.5',
391
+ rename: 'M4 20h4l9.5-9.5a2.1 2.1 0 0 0-3-3L5 17v3zM13.5 6.5l4 4',
392
+ fork: 'M6 4v9M6 19a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5zM18 9a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5zM18 9c0 4.5-4 5-8 5.5',
393
+ copy: 'M9 9h10v10H9zM5 15V5h10',
338
394
  image: 'M3.5 5.5h17v13h-17zM7 14.5l3.5-3.5 3 3 2-2 2 2M8 9.5h.01',
339
395
  search: 'M10.5 17a6.5 6.5 0 1 0 0-13 6.5 6.5 0 0 0 0 13zM15.5 15.5L20 20',
396
+ trash: 'M4 7h16M9.5 7V5h5v2M6.5 7l.8 12.5h9.4L17.5 7M10 11v5M14 11v5',
340
397
  };
341
398
 
342
399
  function glyph(name, size) {
@@ -648,9 +705,11 @@ window.__ModuleLoader__.load({
648
705
  context.fillRect(0, 0, ICON_CANVAS, ICON_CANVAS);
649
706
  }
650
707
  const ratio = ICON_CANVAS / 1024;
651
- for (const group of spec.groups) {
708
+ // icon.json lists groups and their layers front to back, so the back-most
709
+ // paint first; walking them in file order would bury the art under its fill.
710
+ for (const group of [...spec.groups].reverse()) {
652
711
  if (group === null || typeof group !== 'object' || group.hidden === true) continue;
653
- for (const layer of group.layers ?? []) {
712
+ for (const layer of [...(group.layers ?? [])].reverse()) {
654
713
  if (layerHidden(layer, appearance)) continue;
655
714
  const assetName = layer?.['image-name'];
656
715
  if (typeof assetName !== 'string' || assetName === '') continue;
@@ -777,7 +836,7 @@ window.__ModuleLoader__.load({
777
836
  icon: workspace === undefined ? null : projectIcon(workspaceIconName(workspace), icons[workspace.workspaceId]),
778
837
  updatedAtMs,
779
838
  archived: archived.has(id),
780
- pinned: pinned[id] !== undefined,
839
+ pinned: pinned[id] !== undefined && !archived.has(id),
781
840
  pending,
782
841
  completed,
783
842
  running,
@@ -806,6 +865,37 @@ window.__ModuleLoader__.load({
806
865
  return undefined;
807
866
  }
808
867
 
868
+ // A floating panel closes on a click outside it, Escape, scroll or resize;
869
+ // Escape also returns focus to the control that opened it. `inside` names the
870
+ // panel and its trigger, so a click on either keeps the panel's own handler in
871
+ // charge of toggling it.
872
+ function useDismissFloating(open, setOpen, inside, openerRef) {
873
+ React.useEffect(() => {
874
+ if (!open) return undefined;
875
+ const close = () => setOpen(null);
876
+ const onPointerDown = (event) => {
877
+ const target = event.target;
878
+ if (target instanceof Element && target.closest(inside) !== null) return;
879
+ close();
880
+ };
881
+ const onKeyDown = (event) => {
882
+ if (event.key !== 'Escape') return;
883
+ close();
884
+ if (openerRef !== undefined) openerRef.current?.focus();
885
+ };
886
+ document.addEventListener('pointerdown', onPointerDown, true);
887
+ document.addEventListener('keydown', onKeyDown);
888
+ window.addEventListener('scroll', close, true);
889
+ window.addEventListener('resize', close);
890
+ return () => {
891
+ document.removeEventListener('pointerdown', onPointerDown, true);
892
+ document.removeEventListener('keydown', onKeyDown);
893
+ window.removeEventListener('scroll', close, true);
894
+ window.removeEventListener('resize', close);
895
+ };
896
+ }, [open, setOpen, inside, openerRef]);
897
+ }
898
+
809
899
  function useIconUrl(key, load) {
810
900
  const [url, setUrl] = React.useState(() => (key === null ? null : (ICON_URLS.get(key) ?? null)));
811
901
  React.useEffect(() => {
@@ -863,9 +953,10 @@ window.__ModuleLoader__.load({
863
953
  );
864
954
  }
865
955
 
866
- // One row's Workspace tile: the face above, with the picker opening from it.
956
+ // One row's Workspace tile: the face above, with the picker opening from it
957
+ // and the project menu on the context-menu gesture.
867
958
  function ProjectTile(props) {
868
- const { icon, label, onOpen } = props;
959
+ const { icon, label, onOpen, onMenu } = props;
869
960
  return h(
870
961
  'button',
871
962
  {
@@ -877,6 +968,17 @@ window.__ModuleLoader__.load({
877
968
  event.stopPropagation();
878
969
  onOpen(event);
879
970
  },
971
+ onContextMenu: (event) => {
972
+ event.preventDefault();
973
+ event.stopPropagation();
974
+ onMenu(event);
975
+ },
976
+ onKeyDown: (event) => {
977
+ if (event.key !== 'ContextMenu' && !(event.shiftKey && event.key === 'F10')) return;
978
+ event.preventDefault();
979
+ event.stopPropagation();
980
+ onMenu(event);
981
+ },
880
982
  },
881
983
  h(ProjectFace, props),
882
984
  );
@@ -1368,7 +1470,7 @@ window.__ModuleLoader__.load({
1368
1470
  }
1369
1471
 
1370
1472
  function Shelves(props) {
1371
- const { wide, expandSidebar, useSessions, useSessionStatus, useWorkspaces, usePanelInfo, openSession, archiveSession, unarchiveSession, getOpenTabs, listFiles, readFileBytes, t } = props;
1473
+ const { wide, expandSidebar, useSessions, useSessionStatus, useWorkspaces, usePanelInfo, useWorkspaceAccess, openSession, archiveSession, unarchiveSession, forkSession, renameSession, deleteWorkspace, getOpenTabs, listFiles, readFileBytes, t } = props;
1372
1474
  const list = useSessions((state) => state) ?? EMPTY_LIST;
1373
1475
  const statuses = useSessionStatus((state) => state);
1374
1476
  const items = useWorkspaces((state) => state.items);
@@ -1395,17 +1497,47 @@ window.__ModuleLoader__.load({
1395
1497
  const [settings, setSettings] = React.useState(() => normalizeSettings(readJson(SETTINGS_KEY, {})));
1396
1498
  const [pinned, setPinned] = React.useState(() => normalizeMap(readJson(PINNED_KEY, {})));
1397
1499
  const icons = React.useSyncExternalStore(iconsStore.subscribe, iconsStore.get);
1398
- const [settingsOpen, setSettingsOpen] = React.useState(false);
1500
+ // The settings panel floats over the column, so it keeps only its fixed
1501
+ // box; the gear is the control it is anchored to and returns focus to.
1502
+ const [settingsPopover, setSettingsPopover] = React.useState(null);
1503
+ const settingsGearRef = React.useRef(null);
1399
1504
  const [archivedOpen, setArchivedOpen] = React.useState(false);
1400
1505
  const [iconPicker, setIconPicker] = React.useState(null);
1401
1506
  const [filePicker, setFilePicker] = React.useState(null);
1507
+ // One card menu at a time, anchored at the gesture point. `row` is the
1508
+ // occurrence snapshot; the element restores focus after a keyboard open.
1509
+ // A project menu rides the same slot with `kind: 'project'`.
1510
+ const [cardMenu, setCardMenu] = React.useState(null);
1511
+ const cardMenuRef = React.useRef(null);
1512
+ cardMenuRef.current = cardMenu;
1513
+ // A rename request owns its draft so a rejected write keeps the dialog.
1514
+ const [rename, setRename] = React.useState(null);
1515
+ // Removal keeps its target and failure text so a rejected write stays visible.
1516
+ const [removeProject, setRemoveProject] = React.useState(null);
1517
+ const [toast, setToast] = React.useState(null);
1402
1518
  const [clock, bumpClock] = React.useReducer((n) => n + 1, 0);
1519
+ // The pointer point is a zero-size rect; the Menu primitive clamps it to
1520
+ // the viewport and follows scroll and resize while open.
1521
+ const cardMenuRect = React.useCallback(() => {
1522
+ const menu = cardMenuRef.current;
1523
+ if (menu === null) return null;
1524
+ return { left: menu.x, right: menu.x, top: menu.y, bottom: menu.y, width: 0, height: 0 };
1525
+ }, []);
1403
1526
 
1404
1527
  React.useEffect(() => {
1405
1528
  const id = window.setInterval(bumpClock, 60000);
1406
1529
  return () => window.clearInterval(id);
1407
1530
  }, []);
1408
1531
 
1532
+ // The rail renders no cards, so a pending menu or panel must not survive a
1533
+ // collapse.
1534
+ React.useEffect(() => {
1535
+ if (!wide) {
1536
+ setCardMenu(null);
1537
+ setSettingsPopover(null);
1538
+ }
1539
+ }, [wide]);
1540
+
1409
1541
  const updateSettings = (patch) =>
1410
1542
  setSettings((prev) => {
1411
1543
  const next = { ...prev, ...patch };
@@ -1426,8 +1558,8 @@ window.__ModuleLoader__.load({
1426
1558
  iconsStore.set(next);
1427
1559
  };
1428
1560
 
1429
- const openIconPicker = (row, event) => {
1430
- const rect = event.currentTarget.getBoundingClientRect();
1561
+ const openIconPicker = (row, element) => {
1562
+ const rect = element.getBoundingClientRect();
1431
1563
  const left = Math.max(8, Math.min(rect.left, window.innerWidth - 208));
1432
1564
  const height = 200;
1433
1565
  const top = rect.bottom + 6 + height > window.innerHeight ? Math.max(8, rect.top - height - 6) : rect.bottom + 6;
@@ -1453,28 +1585,39 @@ window.__ModuleLoader__.load({
1453
1585
  setIconPicker(null);
1454
1586
  };
1455
1587
 
1588
+ // The shelf sits at the bottom of the column, so the panel grows upward from
1589
+ // the gear: anchoring its bottom edge needs no height estimate.
1590
+ const openSettings = (element) => {
1591
+ const rect = element.getBoundingClientRect();
1592
+ const left = Math.max(
1593
+ 8,
1594
+ Math.min(rect.right - SETTINGS_POPOVER_WIDTH, window.innerWidth - SETTINGS_POPOVER_WIDTH - 8),
1595
+ );
1596
+ setSettingsPopover({ left, bottom: Math.max(8, window.innerHeight - rect.top + 6) });
1597
+ };
1598
+
1599
+ useDismissFloating(iconPicker !== null, setIconPicker, '.dsh-shelves-iconpicker, .dsh-shelves-proj');
1600
+ useDismissFloating(
1601
+ settingsPopover !== null,
1602
+ setSettingsPopover,
1603
+ '.dsh-shelves-settings, .dsh-shelves-gear',
1604
+ settingsGearRef,
1605
+ );
1606
+ // The expanded Archived shelf folds back on a click anywhere outside it, so
1607
+ // browsing the column never leaves it open. Its own header row and list keep
1608
+ // it open, and the header button still toggles it.
1456
1609
  React.useEffect(() => {
1457
- if (iconPicker === null) return undefined;
1458
- const close = () => setIconPicker(null);
1610
+ if (!archivedOpen) return undefined;
1459
1611
  const onPointerDown = (event) => {
1460
1612
  const target = event.target;
1461
- if (target instanceof Element && target.closest('.dsh-shelves-iconpicker, .dsh-shelves-proj') !== null) return;
1462
- close();
1463
- };
1464
- const onKeyDown = (event) => {
1465
- if (event.key === 'Escape') close();
1613
+ if (target instanceof Element && target.closest('.dsh-shelves-headrow, .dsh-shelves-archived-list') !== null) {
1614
+ return;
1615
+ }
1616
+ setArchivedOpen(false);
1466
1617
  };
1467
1618
  document.addEventListener('pointerdown', onPointerDown, true);
1468
- document.addEventListener('keydown', onKeyDown);
1469
- window.addEventListener('scroll', close, true);
1470
- window.addEventListener('resize', close);
1471
- return () => {
1472
- document.removeEventListener('pointerdown', onPointerDown, true);
1473
- document.removeEventListener('keydown', onKeyDown);
1474
- window.removeEventListener('scroll', close, true);
1475
- window.removeEventListener('resize', close);
1476
- };
1477
- }, [iconPicker]);
1619
+ return () => document.removeEventListener('pointerdown', onPointerDown, true);
1620
+ }, [archivedOpen]);
1478
1621
 
1479
1622
  const currentId = React.useMemo(() => {
1480
1623
  const byId = list.byId ?? {};
@@ -1489,6 +1632,27 @@ window.__ModuleLoader__.load({
1489
1632
  () => deriveRows(list, statuses, workspaceIndex(items), currentId, archived, pinned, icons),
1490
1633
  [list, statuses, items, currentId, archived, pinned, icons],
1491
1634
  );
1635
+ // The gear leaves with the last card, so its panel must not outlive it.
1636
+ React.useEffect(() => {
1637
+ if (rows.length === 0) setSettingsPopover(null);
1638
+ }, [rows.length]);
1639
+ // Archiving drops the pin with the session, so unarchiving never brings
1640
+ // back a pin that could not be seen or cleared while it was archived.
1641
+ React.useEffect(() => {
1642
+ setPinned((prev) => {
1643
+ const next = {};
1644
+ let dropped = false;
1645
+ for (const [id, at] of Object.entries(prev)) {
1646
+ if (archived.has(id)) dropped = true;
1647
+ else next[id] = at;
1648
+ }
1649
+ if (!dropped) return prev;
1650
+ writeJson(PINNED_KEY, next);
1651
+ return next;
1652
+ });
1653
+ }, [archived]);
1654
+ // Owner-only; a shared page never receives a project removal row.
1655
+ const canRemoveProject = useWorkspaceAccess(cardMenu?.row.workspaceId ?? '', 'workspace/delete');
1492
1656
 
1493
1657
  // A run that ends stays marked "Done" until the row is opened. DSH's own
1494
1658
  // `completionUnread` only fires for a session that is not the main view and
@@ -1621,9 +1785,29 @@ window.__ModuleLoader__.load({
1621
1785
  // Archive is the Host's own durable state, so it survives reloads and reaches
1622
1786
  // every client. A Session with running work refuses the plain archive; the
1623
1787
  // refusal is left as-is instead of driving a stop-and-archive flow.
1788
+ //
1789
+ // Archiving the card on screen clears the main view and shows the New
1790
+ // Session page, so that one opens the card below instead — or the one
1791
+ // above when it was last — once the archive is durable. A failure keeps
1792
+ // the current card, so a refused archive never moves the user.
1793
+ const nextAfterArchive = (row) => {
1794
+ if (row.id !== currentId) return undefined;
1795
+ const index = active.findIndex((candidate) => candidate.id === row.id);
1796
+ if (index === -1) return undefined;
1797
+ return active[index + 1] ?? active[index - 1];
1798
+ };
1799
+
1624
1800
  const toggleArchive = (row) => {
1625
- const run = row.archived ? unarchiveSession(row.id) : archiveSession(row.id);
1626
- Promise.resolve(run).catch(() => {});
1801
+ if (row.archived) {
1802
+ Promise.resolve(unarchiveSession(row.id)).catch(() => {});
1803
+ return;
1804
+ }
1805
+ const next = nextAfterArchive(row);
1806
+ Promise.resolve(archiveSession(row.id))
1807
+ .then(() => {
1808
+ if (next !== undefined) open(next);
1809
+ })
1810
+ .catch(() => {});
1627
1811
  };
1628
1812
 
1629
1813
  const togglePin = (row) => {
@@ -1633,6 +1817,142 @@ window.__ModuleLoader__.load({
1633
1817
  updatePinned(next);
1634
1818
  };
1635
1819
 
1820
+ const showToast = (text, tone) => setToast({ text, tone, key: Date.now() });
1821
+
1822
+ // The card menu mirrors the native Session menu: same verbs, same order.
1823
+ // It never opens the Session, so a background row keeps the selection.
1824
+ const openCardMenu = (row, point, keyboard, element) => {
1825
+ if (row.blank) return;
1826
+ setCardMenu({ kind: 'session', row, x: point.x, y: point.y, keyboard, element });
1827
+ };
1828
+
1829
+ // A project menu hangs off a Workspace tile or name: change its tile or
1830
+ // remove its registration. Sessions and files stay untouched.
1831
+ const openProjectMenu = (row, point, keyboard, element) => {
1832
+ if (row.workspaceId === undefined) return;
1833
+ setIconPicker(null);
1834
+ setCardMenu({ kind: 'project', row, x: point.x, y: point.y, keyboard, element });
1835
+ };
1836
+
1837
+ const closeCardMenu = () => {
1838
+ const menu = cardMenuRef.current;
1839
+ setCardMenu(null);
1840
+ // A keyboard menu owns focus while open; hand it back to its row.
1841
+ if (menu?.keyboard) {
1842
+ Promise.resolve().then(() => {
1843
+ if (menu.element?.isConnected) menu.element.focus();
1844
+ });
1845
+ }
1846
+ };
1847
+
1848
+ const cardMenuItems = (row) => {
1849
+ const items = [];
1850
+ if (!row.archived) {
1851
+ items.push({ id: 'pin', label: row.pinned ? t('action.unpin') : t('action.pin'), icon: glyph('pin', 16) });
1852
+ }
1853
+ items.push({ id: 'rename', label: t('action.rename'), icon: glyph('rename', 16) });
1854
+ items.push({ id: 'fork', label: t('action.fork'), icon: glyph('fork', 16) });
1855
+ items.push({ type: 'separator', id: 'card-menu-copy' });
1856
+ items.push({ id: 'copyId', label: t('action.copyId'), icon: glyph('copy', 16) });
1857
+ items.push({ type: 'separator', id: 'card-menu-archive' });
1858
+ items.push({
1859
+ id: 'archive',
1860
+ label: row.archived ? t('action.unarchive') : t('action.archive'),
1861
+ icon: glyph(row.archived ? 'unarchive' : 'archive', 16),
1862
+ });
1863
+ if (row.workspaceId !== undefined && canRemoveProject) {
1864
+ items.push({ type: 'separator', id: 'card-menu-project' });
1865
+ items.push({ id: 'removeProject', label: t('action.removeProject'), icon: glyph('trash', 16), danger: true });
1866
+ }
1867
+ return items;
1868
+ };
1869
+
1870
+ const projectMenuItems = () => {
1871
+ const items = [{ id: 'projectIcon', label: t('icon.edit'), icon: glyph('image', 16) }];
1872
+ if (canRemoveProject) {
1873
+ items.push({ type: 'separator', id: 'project-menu-remove' });
1874
+ items.push({ id: 'removeProject', label: t('action.removeProject'), icon: glyph('trash', 16), danger: true });
1875
+ }
1876
+ return items;
1877
+ };
1878
+
1879
+ const selectCardMenuItem = (id) => {
1880
+ const menu = cardMenuRef.current;
1881
+ if (menu === null) return;
1882
+ closeCardMenu();
1883
+ // Read the live row: pin and archive state may have moved since opening.
1884
+ const row = rows.find((candidate) => candidate.id === menu.row.id) ?? menu.row;
1885
+ if (menu.kind === 'project') {
1886
+ if (id === 'projectIcon') {
1887
+ if (menu.element?.isConnected) openIconPicker(row, menu.element);
1888
+ } else if (id === 'removeProject' && row.workspaceId !== undefined) {
1889
+ setRemoveProject({ workspaceId: row.workspaceId, name: row.workspace, busy: false, error: null });
1890
+ }
1891
+ return;
1892
+ }
1893
+ if (id === 'pin') togglePin(row);
1894
+ else if (id === 'rename') setRename({ id: row.id, draft: row.title || '', busy: false, error: null });
1895
+ else if (id === 'fork') {
1896
+ Promise.resolve()
1897
+ .then(() => forkSession(row.id))
1898
+ .catch((reason) => {
1899
+ console.warn('sidebar-shelves: fork failed', reason);
1900
+ showToast(t('action.forkFailed'), 'error');
1901
+ });
1902
+ } else if (id === 'copyId') {
1903
+ Promise.resolve()
1904
+ .then(() => writeClipboard(row.id))
1905
+ .then((ok) => showToast(ok ? t('action.copyIdDone') : t('action.copyIdFailed'), ok ? 'success' : 'error'))
1906
+ .catch(() => showToast(t('action.copyIdFailed'), 'error'));
1907
+ } else if (id === 'archive') toggleArchive(row);
1908
+ else if (id === 'removeProject' && row.workspaceId !== undefined) {
1909
+ setRemoveProject({ workspaceId: row.workspaceId, name: row.workspace, busy: false, error: null });
1910
+ }
1911
+ };
1912
+
1913
+ const submitRename = () => {
1914
+ const target = rename;
1915
+ if (target === null || target.busy) return;
1916
+ const title = target.draft.trim();
1917
+ if (title === '') {
1918
+ setRename({ ...target, error: t('rename.empty') });
1919
+ return;
1920
+ }
1921
+ setRename({ ...target, busy: true, error: null });
1922
+ Promise.resolve()
1923
+ .then(() => renameSession(target.id, title))
1924
+ .then(() => setRename(null))
1925
+ .catch((reason) => {
1926
+ const message = reason instanceof Error ? reason.message : String(reason);
1927
+ setRename((current) =>
1928
+ current !== null && current.id === target.id ? { ...current, busy: false, error: message } : current,
1929
+ );
1930
+ });
1931
+ };
1932
+
1933
+ // Removing a project only deletes the Workspace registration; the folder
1934
+ // and every Session stay. A successful delete also drops the local tile choice.
1935
+ const confirmRemoveProject = () => {
1936
+ const target = removeProject;
1937
+ if (target === null || target.busy) return;
1938
+ setRemoveProject({ ...target, busy: true, error: null });
1939
+ Promise.resolve()
1940
+ .then(() => deleteWorkspace(target.workspaceId))
1941
+ .then(() => {
1942
+ updateIcon(target.workspaceId, null);
1943
+ setRemoveProject(null);
1944
+ showToast(t('remove.done'), 'success');
1945
+ })
1946
+ .catch((reason) => {
1947
+ const message = reason instanceof Error ? reason.message : String(reason);
1948
+ setRemoveProject((current) =>
1949
+ current !== null && current.workspaceId === target.workspaceId
1950
+ ? { ...current, busy: false, error: message }
1951
+ : current,
1952
+ );
1953
+ });
1954
+ };
1955
+
1636
1956
  // The Workspace's tile: its chosen image, an emoji, or a two-letter monogram
1637
1957
  // in its own color. Clicking it opens the picker; an ungrouped Session has none.
1638
1958
  const renderProjectIcon = (row) => {
@@ -1645,7 +1965,17 @@ window.__ModuleLoader__.load({
1645
1965
  workspacePath: row.workspacePath,
1646
1966
  sessionId: row.id,
1647
1967
  readFileBytes,
1648
- onOpen: (event) => openIconPicker(row, event),
1968
+ onOpen: (event) => openIconPicker(row, event.currentTarget),
1969
+ onMenu: (event) => {
1970
+ const rect = event.currentTarget.getBoundingClientRect();
1971
+ const keyboard = event.type !== 'contextmenu';
1972
+ openProjectMenu(
1973
+ row,
1974
+ keyboard ? { x: rect.left + 10, y: rect.bottom - 6 } : { x: event.clientX, y: event.clientY },
1975
+ keyboard,
1976
+ event.currentTarget,
1977
+ );
1978
+ },
1649
1979
  });
1650
1980
  };
1651
1981
 
@@ -1679,6 +2009,7 @@ window.__ModuleLoader__.load({
1679
2009
  const title = row.blank ? t('session.new') : row.title || t('session.untitled');
1680
2010
  const status = row.archived ? undefined : statusOf(row, unseen.has(row.id), t);
1681
2011
  const time = relativeTime(row.updatedAtMs, Date.now(), t);
2012
+ const timeClass = status?.tone === 'working' ? 'dsh-shelves-time dsh-shelves-time-running' : 'dsh-shelves-time';
1682
2013
  const classes = ['dsh-shelves-row'];
1683
2014
  if (selected) classes.push('dsh-shelves-row-selected');
1684
2015
  if (row.archived) classes.push('dsh-shelves-row-archived');
@@ -1693,9 +2024,21 @@ window.__ModuleLoader__.load({
1693
2024
  'aria-disabled': row.archived ? 'true' : undefined,
1694
2025
  title,
1695
2026
  onClick: () => open(row),
2027
+ onContextMenu: (event) => {
2028
+ event.preventDefault();
2029
+ event.stopPropagation();
2030
+ openCardMenu(row, { x: event.clientX, y: event.clientY }, false, event.currentTarget);
2031
+ },
1696
2032
  onKeyDown: (event) => {
1697
2033
  // Keys pressed inside the row's own buttons belong to those buttons.
1698
2034
  if (event.target !== event.currentTarget) return;
2035
+ // The platform context-menu gesture opens the same menu as the pointer.
2036
+ if (event.key === 'ContextMenu' || (event.shiftKey && event.key === 'F10')) {
2037
+ event.preventDefault();
2038
+ const rect = event.currentTarget.getBoundingClientRect();
2039
+ openCardMenu(row, { x: rect.left + 10, y: rect.bottom - 6 }, true, event.currentTarget);
2040
+ return;
2041
+ }
1699
2042
  if (event.key !== 'Enter' && event.key !== ' ') return;
1700
2043
  event.preventDefault();
1701
2044
  open(row);
@@ -1718,7 +2061,7 @@ window.__ModuleLoader__.load({
1718
2061
  glyph(status.key, 13),
1719
2062
  ),
1720
2063
  h('span', { className: status?.key === 'done' ? 'dsh-shelves-title dsh-shelves-title-done' : 'dsh-shelves-title' }, title),
1721
- time === '' ? null : h('span', { className: 'dsh-shelves-time' }, time),
2064
+ time === '' ? null : h('span', { className: timeClass }, time),
1722
2065
  ),
1723
2066
  h(
1724
2067
  'span',
@@ -1731,7 +2074,22 @@ window.__ModuleLoader__.load({
1731
2074
  glyph('pin', 12),
1732
2075
  )
1733
2076
  : null,
1734
- h('span', { className: 'dsh-shelves-ws' }, row.workspace),
2077
+ h(
2078
+ 'span',
2079
+ {
2080
+ className: 'dsh-shelves-ws',
2081
+ title: row.workspace || undefined,
2082
+ onContextMenu:
2083
+ row.workspaceId === undefined
2084
+ ? undefined
2085
+ : (event) => {
2086
+ event.preventDefault();
2087
+ event.stopPropagation();
2088
+ openProjectMenu(row, { x: event.clientX, y: event.clientY }, false, event.currentTarget);
2089
+ },
2090
+ },
2091
+ row.workspace,
2092
+ ),
1735
2093
  renderActivityBadge('jobs', row.jobsRunning, row.jobsLabels),
1736
2094
  renderActivityBadge('subagents', row.subagentsRunning, row.subagentLabels),
1737
2095
  terminalSessions.has(row.id)
@@ -1745,20 +2103,22 @@ window.__ModuleLoader__.load({
1745
2103
  h(
1746
2104
  'span',
1747
2105
  { className: 'dsh-shelves-actions' },
1748
- h(
1749
- 'button',
1750
- {
1751
- type: 'button',
1752
- className: row.pinned ? 'dsh-shelves-action dsh-shelves-action-pinned' : 'dsh-shelves-action',
1753
- 'aria-label': row.pinned ? t('action.unpin') : t('action.pin'),
1754
- title: row.pinned ? t('action.unpin') : t('action.pin'),
1755
- onClick: (event) => {
1756
- event.stopPropagation();
1757
- togglePin(row);
1758
- },
1759
- },
1760
- glyph('pin', 15),
1761
- ),
2106
+ row.archived
2107
+ ? null
2108
+ : h(
2109
+ 'button',
2110
+ {
2111
+ type: 'button',
2112
+ className: row.pinned ? 'dsh-shelves-action dsh-shelves-action-pinned' : 'dsh-shelves-action',
2113
+ 'aria-label': row.pinned ? t('action.unpin') : t('action.pin'),
2114
+ title: row.pinned ? t('action.unpin') : t('action.pin'),
2115
+ onClick: (event) => {
2116
+ event.stopPropagation();
2117
+ togglePin(row);
2118
+ },
2119
+ },
2120
+ glyph('pin', 15),
2121
+ ),
1762
2122
  h(
1763
2123
  'button',
1764
2124
  {
@@ -1809,47 +2169,28 @@ window.__ModuleLoader__.load({
1809
2169
  'button',
1810
2170
  {
1811
2171
  type: 'button',
2172
+ ref: settingsGearRef,
1812
2173
  className: 'dsh-shelves-gear',
1813
2174
  'aria-label': t('settings.label'),
1814
- 'aria-expanded': settingsOpen ? 'true' : 'false',
2175
+ 'aria-expanded': settingsPopover !== null ? 'true' : 'false',
2176
+ 'aria-haspopup': 'dialog',
1815
2177
  title: t('settings.label'),
1816
- onClick: () => setSettingsOpen(!settingsOpen),
2178
+ onClick: (event) =>
2179
+ settingsPopover === null ? openSettings(event.currentTarget) : setSettingsPopover(null),
1817
2180
  },
1818
2181
  glyph('gear', 14),
1819
2182
  ),
1820
2183
  ),
1821
2184
  );
1822
- if (settingsOpen) {
2185
+ if (archivedOpen) {
1823
2186
  bottom.push(
1824
2187
  h(
1825
2188
  'div',
1826
- { key: 'settings', className: 'dsh-shelves-settings' },
1827
- h('div', { className: 'dsh-shelves-settings-title' }, t('settings.label')),
1828
- h(
1829
- 'div',
1830
- { className: 'dsh-shelves-setting' },
1831
- h('span', null, t('settings.autoArchive')),
1832
- h(
1833
- 'span',
1834
- { className: 'dsh-shelves-select' },
1835
- h(
1836
- 'select',
1837
- {
1838
- 'aria-label': t('settings.autoArchive'),
1839
- value: settings.autoArchiveDays === null ? '' : String(settings.autoArchiveDays),
1840
- onChange: (event) =>
1841
- updateSettings({ autoArchiveDays: event.target.value === '' ? null : Number(event.target.value) }),
1842
- },
1843
- h('option', { value: '' }, t('settings.off')),
1844
- AUTO_ARCHIVE_CHOICES.map((days) => h('option', { key: days, value: String(days) }, t('settings.days', { n: days }))),
1845
- ),
1846
- h('span', { className: 'dsh-shelves-select-chevron' }, glyph('chevron', 12)),
1847
- ),
1848
- ),
2189
+ { key: 'archived-list', className: 'dsh-shelves-archived-list' },
2190
+ archivedRows.map((row) => renderRow(row)),
1849
2191
  ),
1850
2192
  );
1851
2193
  }
1852
- if (archivedOpen) for (const row of archivedRows) bottom.push(renderRow(row));
1853
2194
 
1854
2195
  stack.push(h('div', { key: 'bottom', className: 'dsh-shelves-bottom' }, bottom));
1855
2196
  }
@@ -1923,6 +2264,43 @@ window.__ModuleLoader__.load({
1923
2264
  );
1924
2265
  };
1925
2266
 
2267
+ // Anchored above the gear, so opening it never reflows the column.
2268
+ const renderSettingsPopover = () => {
2269
+ if (settingsPopover === null) return null;
2270
+ return h(
2271
+ 'div',
2272
+ {
2273
+ className: 'dsh-shelves-settings',
2274
+ style: { left: settingsPopover.left, bottom: settingsPopover.bottom, width: SETTINGS_POPOVER_WIDTH },
2275
+ role: 'dialog',
2276
+ 'aria-label': t('settings.label'),
2277
+ },
2278
+ h('div', { className: 'dsh-shelves-settings-title' }, t('settings.label')),
2279
+ h(
2280
+ 'div',
2281
+ { className: 'dsh-shelves-setting' },
2282
+ h('span', null, t('settings.autoArchive')),
2283
+ h(
2284
+ 'span',
2285
+ { className: 'dsh-shelves-select' },
2286
+ h(
2287
+ 'select',
2288
+ {
2289
+ 'aria-label': t('settings.autoArchive'),
2290
+ autoFocus: true,
2291
+ value: settings.autoArchiveDays === null ? '' : String(settings.autoArchiveDays),
2292
+ onChange: (event) =>
2293
+ updateSettings({ autoArchiveDays: event.target.value === '' ? null : Number(event.target.value) }),
2294
+ },
2295
+ h('option', { value: '' }, t('settings.off')),
2296
+ AUTO_ARCHIVE_CHOICES.map((days) => h('option', { key: days, value: String(days) }, t('settings.days', { n: days }))),
2297
+ ),
2298
+ h('span', { className: 'dsh-shelves-select-chevron' }, glyph('chevron', 12)),
2299
+ ),
2300
+ ),
2301
+ );
2302
+ };
2303
+
1926
2304
  return h(
1927
2305
  React.Fragment,
1928
2306
  null,
@@ -1932,6 +2310,7 @@ window.__ModuleLoader__.load({
1932
2310
  { key: 'root', className: 'dsh-shelves-root' },
1933
2311
  h('div', { className: 'dsh-shelves-scroll' }, h('div', { className: 'dsh-shelves-stack' }, stack)),
1934
2312
  renderIconPicker(),
2313
+ renderSettingsPopover(),
1935
2314
  filePicker === null
1936
2315
  ? null
1937
2316
  : h(FileDialog, {
@@ -1945,6 +2324,108 @@ window.__ModuleLoader__.load({
1945
2324
  setFilePicker(null);
1946
2325
  },
1947
2326
  }),
2327
+ h(Menu, {
2328
+ open: cardMenu !== null,
2329
+ anchor: null,
2330
+ items:
2331
+ cardMenu === null
2332
+ ? []
2333
+ : cardMenu.kind === 'project'
2334
+ ? projectMenuItems()
2335
+ : cardMenuItems(cardMenu.row),
2336
+ onSelect: selectCardMenuItem,
2337
+ onClose: closeCardMenu,
2338
+ side: 'bottom',
2339
+ portal: true,
2340
+ autoFocus: cardMenu?.keyboard === true,
2341
+ getAnchorRect: cardMenuRect,
2342
+ }),
2343
+ toast === null
2344
+ ? null
2345
+ : h(Toast, {
2346
+ key: toast.key,
2347
+ text: toast.text,
2348
+ tone: toast.tone,
2349
+ onDone: () => setToast(null),
2350
+ }),
2351
+ h(
2352
+ Modal,
2353
+ {
2354
+ open: rename !== null,
2355
+ onClose: () => {
2356
+ if (rename === null || rename.busy) return;
2357
+ setRename(null);
2358
+ },
2359
+ closeLabel: t('rename.cancel'),
2360
+ title: t('rename.title'),
2361
+ footer: [
2362
+ h(Button, { key: 'cancel', onClick: () => (rename?.busy ? undefined : setRename(null)) }, t('rename.cancel')),
2363
+ h(
2364
+ Button,
2365
+ { key: 'confirm', variant: 'primary', disabled: rename?.busy === true, onClick: submitRename },
2366
+ t('rename.confirm'),
2367
+ ),
2368
+ ],
2369
+ },
2370
+ h(
2371
+ 'div',
2372
+ { className: 'dsh-shelves-rename' },
2373
+ h('input', {
2374
+ type: 'text',
2375
+ value: rename?.draft ?? '',
2376
+ placeholder: t('session.untitled'),
2377
+ autoFocus: true,
2378
+ 'aria-label': t('rename.title'),
2379
+ onChange: (event) => {
2380
+ const value = event.target.value;
2381
+ setRename((current) => (current === null ? current : { ...current, draft: value, error: null }));
2382
+ },
2383
+ onKeyDown: (event) => {
2384
+ if (event.key !== 'Enter') return;
2385
+ event.preventDefault();
2386
+ submitRename();
2387
+ },
2388
+ }),
2389
+ rename?.error ? h('div', { className: 'dsh-shelves-rename-error', role: 'alert' }, rename.error) : null,
2390
+ ),
2391
+ ),
2392
+ h(
2393
+ Modal,
2394
+ {
2395
+ open: removeProject !== null,
2396
+ onClose: () => {
2397
+ if (removeProject === null || removeProject.busy) return;
2398
+ setRemoveProject(null);
2399
+ },
2400
+ closeLabel: t('remove.cancel'),
2401
+ title: t('remove.title'),
2402
+ footer: [
2403
+ h(
2404
+ Button,
2405
+ { key: 'cancel', onClick: () => (removeProject?.busy ? undefined : setRemoveProject(null)) },
2406
+ t('remove.cancel'),
2407
+ ),
2408
+ h(
2409
+ Button,
2410
+ {
2411
+ key: 'confirm',
2412
+ variant: 'outline',
2413
+ className: 'dsh-shelves-danger',
2414
+ disabled: removeProject?.busy === true,
2415
+ onClick: confirmRemoveProject,
2416
+ },
2417
+ t('remove.confirm'),
2418
+ ),
2419
+ ],
2420
+ },
2421
+ h(
2422
+ 'div',
2423
+ { className: 'dsh-shelves-remove' },
2424
+ h('div', null, t('remove.desc', { name: removeProject?.name ?? '' })),
2425
+ removeProject?.busy ? h('div', { className: 'dsh-shelves-remove-pending', role: 'status' }, t('remove.pending')) : null,
2426
+ removeProject?.error ? h('div', { className: 'dsh-shelves-remove-error', role: 'alert' }, removeProject.error) : null,
2427
+ ),
2428
+ ),
1948
2429
  ),
1949
2430
  );
1950
2431
  }
@@ -2060,7 +2541,7 @@ window.__ModuleLoader__.load({
2060
2541
  }
2061
2542
 
2062
2543
  return {
2063
- inject: ['slots', 'locale', 'uiWorkspace', 'remote', 'remote.workspaceFiles', 'workspaces'],
2544
+ inject: ['slots', 'locale', 'uiWorkspace', 'remote', 'remote.workspaceFiles', 'workspaces', 'sessions'],
2064
2545
  apply(ctx) {
2065
2546
  ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'sidebar-shelves: dictionaries');
2066
2547
  const readFileBytes = (sessionId, path, length, signal) =>
@@ -2075,6 +2556,16 @@ window.__ModuleLoader__.load({
2075
2556
  openSession: (id) => ctx.uiWorkspace.openSession(id),
2076
2557
  archiveSession: (id) => ctx.uiWorkspace.archiveSession(id),
2077
2558
  unarchiveSession: (id) => ctx.uiWorkspace.unarchiveSession(id),
2559
+ // Workspace-level removal: unregisters the project, keeps its files and sessions.
2560
+ deleteWorkspace: (workspaceId) => ctx.workspaces.delete(workspaceId),
2561
+ // Same Host paths the native Session menu uses.
2562
+ forkSession: (id) => ctx.uiWorkspace.forkSession(id, undefined, { allowMigration: false }),
2563
+ renameSession: async (id, title) => {
2564
+ const result = await ctx.sessions.using(id, { source: 'workspaceOperation' }, (reference) =>
2565
+ reference.binding.session.rename(title),
2566
+ );
2567
+ if (!result.ok) throw new Error(result.error.message);
2568
+ },
2078
2569
  getOpenTabs: () => ctx.get('sidebarRight')?.openTabs,
2079
2570
  listFiles: (sessionId, path, signal) => ctx.remote.workspaceFiles.list(sessionId, path, signal),
2080
2571
  readFileBytes,
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Sidebar Session Cards",
4
- "description": "Replaces the sidebar session list with two-line cards: a project icon per workspace (a monogram, an emoji, a square image, or an Icon Composer .icon package), pinning, manual or after-N-days archiving, running and waiting status markers, running background-job and subagent counts, a terminal marker, and automatic sorting by the latest input."
4
+ "description": "Replaces the sidebar session list with two-line cards: a project icon per workspace (a monogram, an emoji, a square image, or an Icon Composer .icon package), pinning, manual or after-N-days archiving, running and waiting status markers, running background-job and subagent counts, a terminal marker, automatic sorting by the latest input, a right-click context menu on each card, and a project menu on the tile or name with project removal."
5
5
  }
6
6
  }
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "侧边栏会话卡片",
4
- "description": "把侧边栏的会话列表换成两行卡片:每个工作区一个项目图标(字母块、emoji、方形图片或 Icon Composer 的 .icon 图标包)、置顶、手动或按天数自动归档、运行与等待状态标记、运行中的后台任务与子代理计数、终端标记,并按最近一次输入自动排序。"
4
+ "description": "把侧边栏的会话列表换成两行卡片:每个工作区一个项目图标(字母块、emoji、方形图片或 Icon Composer 的 .icon 图标包)、置顶、手动或按天数自动归档、运行与等待状态标记、运行中的后台任务与子代理计数、终端标记,并按最近一次输入自动排序;会话卡片支持右键菜单,项目图标与项目名支持右键管理(含移除项目)。"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "dsh-sidebar-shelves",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
- "description": "Two-line session cards for the DSH sidebar: per-workspace project icons, pinning, archiving, status markers, job counts, and recency sorting",
5
+ "description": "Two-line session cards for the DSH sidebar: per-workspace project icons, pinning, archiving, project removal, status markers, job counts, and recency sorting",
6
6
  "license": "MIT",
7
7
  "author": "Han (https://github.com/YL404)",
8
8
  "repository": {