dsh-nested-workspaces 1.0.0 → 1.3.0
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 +34 -4
- package/client.js +518 -29
- package/index.js +136 -4
- package/locale/en.json +1 -1
- package/locale/ja.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,6 +25,25 @@ name.
|
|
|
25
25
|
- **Every row keeps its affordances.** Each workspace row, child or not, has the
|
|
26
26
|
same `…` menu (add child, new session, rename, delete) and the same
|
|
27
27
|
new-session button.
|
|
28
|
+
- **Reorder workspaces.** Drag a workspace row above or below another row that
|
|
29
|
+
shares its parent: a child moves among its siblings, a root moves among the
|
|
30
|
+
roots, and a drag that would cross the parent boundary is refused so a child
|
|
31
|
+
can never be hoisted out of the workspace it belongs to. A newly created child
|
|
32
|
+
is anchored above its existing siblings instead of below them.
|
|
33
|
+
- **Last-used time.** Every session row shows how long ago it was last used
|
|
34
|
+
(`刚刚 / 12分钟 / 3小时 / 2天`, `now / 12min / 3h / 2d`), hover-swapped for the
|
|
35
|
+
row buttons exactly like the shipped browser. The full sentence (`12分钟前`)
|
|
36
|
+
is the tooltip.
|
|
37
|
+
- **Pin.** The row's pin button pins the session; pinned rows show a filled pin
|
|
38
|
+
glyph beside the time and sort to the top of their workspace. The session `…`
|
|
39
|
+
menu offers the same toggle as **置顶 / 取消置顶**.
|
|
40
|
+
- **Row status, like the shipped browser.** An idle session row draws nothing in
|
|
41
|
+
front of its title. While the session is working it shows the same rotating
|
|
42
|
+
ring the built-in sidebar uses; a pending approval, plan review or question
|
|
43
|
+
shows the amber warning dot, and an unread completion shows the green dot.
|
|
44
|
+
- **Nested indent.** A session row sitting inside a child workspace is indented
|
|
45
|
+
by the same 12px step as that child, so sessions line up under their own
|
|
46
|
+
workspace instead of under the root.
|
|
28
47
|
- **Workspace rename and delete.** Double-click a workspace title to rename it in
|
|
29
48
|
place; the `…` menu offers the same plus a delete confirmation. Deleting a
|
|
30
49
|
workspace only removes it from the sidebar — the folder and its sessions stay on
|
|
@@ -52,15 +71,22 @@ row list). A few things come with that trade:
|
|
|
52
71
|
- Workspace rows carry this plugin's own menu instead of the shipped one: rename,
|
|
53
72
|
delete, new session and add child workspace all live there. Entries that other
|
|
54
73
|
plugins contribute to the *shipped* workspace context menu are not shown here.
|
|
55
|
-
-
|
|
56
|
-
|
|
57
|
-
menu, which is still the shipped menu.
|
|
58
|
-
- The
|
|
74
|
+
- Session rows carry this plugin's own pin button and resting cell (time + pin
|
|
75
|
+
glyph) instead of the shipped ones, and per-session archiving stays in the
|
|
76
|
+
session's own `…` menu, which is still the shipped menu.
|
|
77
|
+
- The shipped browser's child seats
|
|
59
78
|
(`sidebar.workspaces.directoryFlow`, `sidebar.workspaces.session.row.action`,
|
|
60
79
|
`sidebar.session.row.leading`, `sidebar.session.row.trailing`,
|
|
61
80
|
`sidebar.session.row.hover`) are not rendered on these rows, so additions other
|
|
62
81
|
plugins place in them will not appear inside this section. The session `…` menu
|
|
63
82
|
is unaffected and remains the supported extension point.
|
|
83
|
+
- **Add child workspace does not need the browse picker.** A Host whose composed
|
|
84
|
+
directory picker is the OS chooser (the `native` capability) cannot serve
|
|
85
|
+
`directoryPicker.createDirectory`. This bundle's Host half therefore creates the
|
|
86
|
+
folder itself over the Connection route `/api/nested-workspaces`. The plugin
|
|
87
|
+
falls back to the shipped `createDirectory` endpoint if that route cannot be
|
|
88
|
+
called (for example an older Host half), which on a `native`-only Host is the
|
|
89
|
+
error you would otherwise see.
|
|
64
90
|
|
|
65
91
|
## Using it
|
|
66
92
|
|
|
@@ -70,9 +96,13 @@ Right-click any workspace in the sidebar.
|
|
|
70
96
|
| --- | --- |
|
|
71
97
|
| Rename the section title | double-click the 「工作区」 label |
|
|
72
98
|
| Add a child workspace | workspace `…` menu → 添加子工作区 |
|
|
99
|
+
| Reorder workspaces | drag a workspace row above or below a sibling that shares its parent |
|
|
73
100
|
| New session in a child | the `+` on the child's row |
|
|
74
101
|
| File a session under another workspace | drag the session row, or session `…` menu → 移动到工作区 |
|
|
75
102
|
| Rename / delete a workspace | double-click its title, or its `…` menu |
|
|
103
|
+
| Pin / unpin a session | the pin button on its row, or session `…` menu → 置顶 |
|
|
104
|
+
| See the last-used time | the resting label on its row; hover for the sentence |
|
|
105
|
+
| See whether a session is working | the rotating ring in front of its title |
|
|
76
106
|
| Show archived sessions | the archive button in the section header |
|
|
77
107
|
|
|
78
108
|
## Languages
|
package/client.js
CHANGED
|
@@ -70,6 +70,26 @@ window.__ModuleLoader__.load({
|
|
|
70
70
|
'ungrouped': '未分组',
|
|
71
71
|
'empty': '暂无会话',
|
|
72
72
|
'search.empty': '没有匹配结果',
|
|
73
|
+
'time.now': '刚刚',
|
|
74
|
+
'time.minutes': '{n}分钟',
|
|
75
|
+
'time.hours': '{n}小时',
|
|
76
|
+
'time.days': '{n}天',
|
|
77
|
+
'time.months': '{n}个月',
|
|
78
|
+
'time.years': '{n}年',
|
|
79
|
+
'time.ago': '{t}前',
|
|
80
|
+
'actions.pin': '置顶',
|
|
81
|
+
'actions.unpin': '取消置顶',
|
|
82
|
+
'row.pinned': '已置顶',
|
|
83
|
+
'errors.pinFailed': '置顶状态更新失败',
|
|
84
|
+
'status.running': '正在工作',
|
|
85
|
+
'status.subagentsRunning': '{n}个子代理正在运行',
|
|
86
|
+
'status.completed': '已完成',
|
|
87
|
+
'status.waitingApproval': '等待批准',
|
|
88
|
+
'status.planReview': '等待确认计划',
|
|
89
|
+
'status.waitingAnswer': '等待回答',
|
|
90
|
+
'errors.reorderFailed': '工作区排序更新失败',
|
|
91
|
+
'errors.invalidParent': 'The parent workspace directory is not usable.',
|
|
92
|
+
'errors.unreadable': 'The new directory could not be read.',
|
|
73
93
|
},
|
|
74
94
|
en: {
|
|
75
95
|
'heading.default': 'Workspaces',
|
|
@@ -116,6 +136,26 @@ window.__ModuleLoader__.load({
|
|
|
116
136
|
'ungrouped': 'Ungrouped',
|
|
117
137
|
'empty': 'No sessions',
|
|
118
138
|
'search.empty': 'No matches',
|
|
139
|
+
'time.now': 'now',
|
|
140
|
+
'time.minutes': '{n}min',
|
|
141
|
+
'time.hours': '{n}h',
|
|
142
|
+
'time.days': '{n}d',
|
|
143
|
+
'time.months': '{n}mo',
|
|
144
|
+
'time.years': '{n}y',
|
|
145
|
+
'time.ago': '{t} ago',
|
|
146
|
+
'actions.pin': 'Pin',
|
|
147
|
+
'actions.unpin': 'Unpin',
|
|
148
|
+
'row.pinned': 'Pinned',
|
|
149
|
+
'errors.pinFailed': 'Could not update the pin',
|
|
150
|
+
'status.running': 'Working',
|
|
151
|
+
'status.subagentsRunning': '{n} subagents running',
|
|
152
|
+
'status.completed': 'Completed',
|
|
153
|
+
'status.waitingApproval': 'Waiting for approval',
|
|
154
|
+
'status.planReview': 'Waiting for plan review',
|
|
155
|
+
'status.waitingAnswer': 'Waiting for an answer',
|
|
156
|
+
'errors.reorderFailed': 'Could not reorder the workspace',
|
|
157
|
+
'errors.invalidParent': 'The parent workspace directory is not usable.',
|
|
158
|
+
'errors.unreadable': 'The new directory could not be read.',
|
|
119
159
|
},
|
|
120
160
|
ja: {
|
|
121
161
|
'heading.default': 'ワークスペース',
|
|
@@ -162,6 +202,26 @@ window.__ModuleLoader__.load({
|
|
|
162
202
|
'ungrouped': '未分類',
|
|
163
203
|
'empty': 'セッションはありません',
|
|
164
204
|
'search.empty': '一致する項目はありません',
|
|
205
|
+
'time.now': '今',
|
|
206
|
+
'time.minutes': '{n}分',
|
|
207
|
+
'time.hours': '{n}時間',
|
|
208
|
+
'time.days': '{n}日',
|
|
209
|
+
'time.months': '{n}か月',
|
|
210
|
+
'time.years': '{n}年',
|
|
211
|
+
'time.ago': '{t}前',
|
|
212
|
+
'actions.pin': 'ピン留め',
|
|
213
|
+
'actions.unpin': 'ピン留めを解除',
|
|
214
|
+
'row.pinned': 'ピン留め済み',
|
|
215
|
+
'errors.pinFailed': 'ピン留めを更新できませんでした',
|
|
216
|
+
'status.running': '実行中',
|
|
217
|
+
'status.subagentsRunning': '{n}件のサブエージェントが実行中',
|
|
218
|
+
'status.completed': '完了',
|
|
219
|
+
'status.waitingApproval': '承認待ち',
|
|
220
|
+
'status.planReview': 'プラン確認待ち',
|
|
221
|
+
'status.waitingAnswer': '回答待ち',
|
|
222
|
+
'errors.reorderFailed': 'ワークスペースの並び順を更新できませんでした',
|
|
223
|
+
'errors.invalidParent': '親ワークスペースのディレクトリを使用できません。',
|
|
224
|
+
'errors.unreadable': '作成したディレクトリを読み取れませんでした。',
|
|
165
225
|
},
|
|
166
226
|
}
|
|
167
227
|
|
|
@@ -204,9 +264,26 @@ window.__ModuleLoader__.load({
|
|
|
204
264
|
.dnw-rowArchived .dnw-title{color:var(--dsw-alias-label-caption)}
|
|
205
265
|
.dnw-actions{flex:none;display:none;align-items:center;gap:13px}
|
|
206
266
|
.dnw-row:hover .dnw-actions,.dnw-actionsOpen{display:flex}
|
|
207
|
-
|
|
208
|
-
.dnw-
|
|
209
|
-
.dnw-
|
|
267
|
+
.dnw-resting{flex:none;display:inline-flex;align-items:center;gap:6px}
|
|
268
|
+
.dnw-time{flex:none;font-size:10px;line-height:16px;color:var(--dsw-alias-label-tertiary);margin-inline-end:-1px}
|
|
269
|
+
.dnw-pinIndicator{display:inline-flex;flex:none;width:16px;height:20px;align-items:center;justify-content:center;color:var(--dsw-alias-label-caption)}
|
|
270
|
+
@media (hover:hover){.dnw-row:hover .dnw-resting,html[data-input-modality='keyboard'] .dnw-row:focus-within .dnw-resting{display:none}}
|
|
271
|
+
.dnw-row:has(.dnw-actionsOpen) .dnw-resting{display:none}
|
|
272
|
+
@media (hover:none){.dnw-actions{display:flex}.dnw-resting{display:none}}
|
|
273
|
+
.dnw-stateDot{position:relative;display:inline-block;flex:none;border-radius:50%}
|
|
274
|
+
.dnw-stateDot::after{content:"";position:absolute;inset:20%;border-radius:50%;background:currentColor}
|
|
275
|
+
.dnw-stateDot[data-state=done]{color:var(--dsw-alias-state-success-primary)}
|
|
276
|
+
.dnw-stateDot[data-state=warning]{color:var(--dsw-alias-state-warn-primary)}
|
|
277
|
+
.dnw-stateDot[data-state=error]{color:var(--dsw-alias-state-error-primary)}
|
|
278
|
+
.dnw-spinner{flex:none;color:var(--dsw-alias-label-tertiary)}
|
|
279
|
+
.dnw-spinnerMotion{transform-origin:center;animation:dnw-state-dot-spin 1.5s linear infinite}
|
|
280
|
+
.dnw-spinnerTrack,.dnw-spinnerArc{fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round}
|
|
281
|
+
.dnw-spinnerTrack{opacity:.25}
|
|
282
|
+
.dnw-spinnerArc{stroke-dasharray:12 150;animation:dnw-state-dot-dash 1.5s ease-in-out infinite}
|
|
283
|
+
@keyframes dnw-state-dot-spin{to{transform:rotate(360deg)}}
|
|
284
|
+
@keyframes dnw-state-dot-dash{0%{stroke-dasharray:12 150;stroke-dashoffset:0}50%{stroke-dasharray:24 150;stroke-dashoffset:-6}to{stroke-dasharray:12 150;stroke-dashoffset:0}}
|
|
285
|
+
@media (prefers-reduced-motion:reduce){.dnw-spinnerMotion,.dnw-spinnerArc{animation:none}.dnw-spinnerArc{stroke-dasharray:18 150;stroke-dashoffset:-3}}
|
|
286
|
+
.dnw-visuallyHidden{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
|
|
210
287
|
.dnw-empty{padding:2px 8px 4px;padding-inline-start:calc(var(--dsh-sidebar-row-padding,12px) + 22px + var(--dnw-indent,0px));font-size:13px;line-height:20px;color:var(--dsw-alias-label-caption)}
|
|
211
288
|
.dnw-dropBefore::before,.dnw-dropAfter::after{content:"";position:absolute;left:calc(-1 * var(--dsh-sidebar-paint-inset,3px));right:calc(4px - var(--dsh-sidebar-paint-inset,3px));height:2px;border-radius:1px;background:var(--dsw-alias-state-business-primary)}
|
|
212
289
|
.dnw-dropBefore::before{top:-8px}
|
|
@@ -296,11 +373,100 @@ window.__ModuleLoader__.load({
|
|
|
296
373
|
h('path', { key: 'b', d: 'M4.8 8.5v6.2h10.4V8.5' }),
|
|
297
374
|
h('path', { key: 'c', d: 'M10 13.4V9.9M8.4 11.5L10 9.9l1.6 1.6' }),
|
|
298
375
|
])
|
|
376
|
+
/* A pushed-in pin, drawn solid so it reads at 14px in a 16px cell. */
|
|
377
|
+
const IconPin = () =>
|
|
378
|
+
svg(
|
|
379
|
+
[
|
|
380
|
+
h('path', { key: 'a', d: 'M7.2 3h5.6l-.7 4.1 2.4 2.1-.5 1.3H5.9l-.5-1.3 2.4-2.1z', fill: 'currentColor', stroke: 'none' }),
|
|
381
|
+
h('path', { key: 'b', d: 'M10 10.5V17' }),
|
|
382
|
+
],
|
|
383
|
+
{ strokeWidth: 1.4 },
|
|
384
|
+
)
|
|
385
|
+
const IconPinOutline = () =>
|
|
386
|
+
svg([
|
|
387
|
+
h('path', { key: 'a', d: 'M7.2 3h5.6l-.7 4.1 2.4 2.1-.5 1.3H5.9l-.5-1.3 2.4-2.1z' }),
|
|
388
|
+
h('path', { key: 'b', d: 'M10 10.5V17' }),
|
|
389
|
+
])
|
|
299
390
|
|
|
300
391
|
/* ---------------------------------------------------------------- utilities */
|
|
301
392
|
|
|
302
393
|
const cls = (...parts) => parts.filter(Boolean).join(' ')
|
|
303
394
|
|
|
395
|
+
const MINUTE_MS = 60 * 1000
|
|
396
|
+
const HOUR_MS = 60 * MINUTE_MS
|
|
397
|
+
const DAY_MS = 24 * HOUR_MS
|
|
398
|
+
const MONTH_MS = 30 * DAY_MS
|
|
399
|
+
const YEAR_MS = 365 * DAY_MS
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Coarse age bucket of one timestamp, mirroring the shipped row labels.
|
|
403
|
+
* @returns {{unit: 'now'|'minutes'|'hours'|'days'|'months'|'years', n: number}}
|
|
404
|
+
*/
|
|
405
|
+
function relativeTime(updatedAt, now) {
|
|
406
|
+
/* `updatedAt` is epoch milliseconds on a live SessionSummary; a fixture or
|
|
407
|
+
* a future shape may hand us something else, and a "NaN分钟" label is
|
|
408
|
+
* worse than no label at all. */
|
|
409
|
+
const stamp = typeof updatedAt === 'number' ? updatedAt : typeof updatedAt === 'string' ? Date.parse(updatedAt) : Number(updatedAt)
|
|
410
|
+
if (!Number.isFinite(stamp) || !Number.isFinite(now)) return { unit: 'now', n: 0 }
|
|
411
|
+
const age = Math.max(0, now - stamp)
|
|
412
|
+
if (age < MINUTE_MS) return { unit: 'now', n: 0 }
|
|
413
|
+
if (age < HOUR_MS) return { unit: 'minutes', n: Math.floor(age / MINUTE_MS) }
|
|
414
|
+
if (age < DAY_MS) return { unit: 'hours', n: Math.floor(age / HOUR_MS) }
|
|
415
|
+
if (age < MONTH_MS) return { unit: 'days', n: Math.floor(age / DAY_MS) }
|
|
416
|
+
if (age < YEAR_MS) return { unit: 'months', n: Math.floor(age / MONTH_MS) }
|
|
417
|
+
return { unit: 'years', n: Math.floor(age / YEAR_MS) }
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** Compact resting label: 刚刚 / 12分钟 / 3小时 / 2天 … */
|
|
421
|
+
function timeLabel(updatedAt, now, t) {
|
|
422
|
+
const { unit, n } = relativeTime(updatedAt, now)
|
|
423
|
+
return unit === 'now' ? t('time.now') : t('time.' + unit, { n })
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** Full sentence for the tooltip: 刚才 / 12分钟前 … */
|
|
427
|
+
function hoverTimeLabel(updatedAt, now, t) {
|
|
428
|
+
const { unit, n } = relativeTime(updatedAt, now)
|
|
429
|
+
return unit === 'now' ? t('time.now') : t('time.ago', { t: t('time.' + unit, { n }) })
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/** Shipped runningChildCount: sessions in this one's subagent catalog still running. */
|
|
433
|
+
function runningSubagentCount(list, parentId, statuses) {
|
|
434
|
+
const entry = list !== null && list !== undefined && list.projectionsBySession !== undefined ? list.projectionsBySession[parentId] : undefined
|
|
435
|
+
const catalog = entry !== undefined && entry !== null && entry.values !== undefined ? entry.values.subagentCatalog : undefined
|
|
436
|
+
if (!Array.isArray(catalog)) return 0
|
|
437
|
+
let count = 0
|
|
438
|
+
for (const child of catalog) {
|
|
439
|
+
const childStatus = statuses.get(child.id)
|
|
440
|
+
const running = childStatus === undefined ? list.byId[child.id] !== undefined && list.byId[child.id].running === true : childStatus.running === true
|
|
441
|
+
if (running) count += 1
|
|
442
|
+
}
|
|
443
|
+
return count
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/* The shipped browser's working indicator: a 14px stroked arc that spins
|
|
447
|
+
* while the stroke length breathes. Both keyframes and the reduced-motion
|
|
448
|
+
* fallback live in the stylesheet below. */
|
|
449
|
+
function StatusSpinner() {
|
|
450
|
+
return h(
|
|
451
|
+
'svg',
|
|
452
|
+
{
|
|
453
|
+
className: 'dnw-spinner',
|
|
454
|
+
'data-state': 'ongoing',
|
|
455
|
+
width: '14',
|
|
456
|
+
height: '14',
|
|
457
|
+
viewBox: '0 0 24 24',
|
|
458
|
+
'aria-hidden': 'true',
|
|
459
|
+
focusable: 'false',
|
|
460
|
+
},
|
|
461
|
+
h(
|
|
462
|
+
'g',
|
|
463
|
+
{ className: 'dnw-spinnerMotion' },
|
|
464
|
+
h('circle', { className: 'dnw-spinnerTrack', cx: '12', cy: '12', r: '9.5' }),
|
|
465
|
+
h('circle', { className: 'dnw-spinnerArc', cx: '12', cy: '12', r: '9.5' }),
|
|
466
|
+
),
|
|
467
|
+
)
|
|
468
|
+
}
|
|
469
|
+
|
|
304
470
|
function isRecord(value) {
|
|
305
471
|
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
306
472
|
}
|
|
@@ -434,7 +600,7 @@ window.__ModuleLoader__.load({
|
|
|
434
600
|
}
|
|
435
601
|
|
|
436
602
|
return {
|
|
437
|
-
inject: ['slots', 'locale', 'contextMenus', 'workspaces', 'uiWorkspace', 'sessions'],
|
|
603
|
+
inject: ['slots', 'locale', 'contextMenus', 'workspaces', 'uiWorkspace', 'sessions', 'connection'],
|
|
438
604
|
apply(ctx) {
|
|
439
605
|
const store = createStore()
|
|
440
606
|
const addChildRequest = createSignal(null)
|
|
@@ -461,6 +627,47 @@ window.__ModuleLoader__.load({
|
|
|
461
627
|
}
|
|
462
628
|
}
|
|
463
629
|
|
|
630
|
+
/* --------------------------------------------------- child directories */
|
|
631
|
+
|
|
632
|
+
/* The composed directory picker is a capability union: a Host whose
|
|
633
|
+
* backend is the OS chooser serves only `native`, and `createDirectory`
|
|
634
|
+
* belongs to `browse`, so it answers "needs the browse capability".
|
|
635
|
+
* Making a folder is not really browsing, so this bundle's Host half
|
|
636
|
+
* does the mkdir and answers over Connection; `createDirectory` stays
|
|
637
|
+
* as the fallback for compositions that do serve the browse backend. */
|
|
638
|
+
const CREATE_CHILD_ENDPOINT = 'nested-workspaces'
|
|
639
|
+
|
|
640
|
+
const createChildDirectory = async (parent, name) => {
|
|
641
|
+
const connection = ctx.get('connection')
|
|
642
|
+
const rpc = connection !== null && typeof connection === 'object' ? connection.rpc : null
|
|
643
|
+
if (rpc !== null && typeof rpc === 'object' && typeof rpc.call === 'function') {
|
|
644
|
+
let result = null
|
|
645
|
+
try {
|
|
646
|
+
const controller = typeof AbortController === 'function' ? new AbortController() : null
|
|
647
|
+
result = await rpc.call(
|
|
648
|
+
'/api',
|
|
649
|
+
CREATE_CHILD_ENDPOINT,
|
|
650
|
+
{ action: 'createChild', parent, name },
|
|
651
|
+
controller === null ? undefined : controller.signal,
|
|
652
|
+
)
|
|
653
|
+
} catch {
|
|
654
|
+
/* Transport missing or route unregistered: fall through to the
|
|
655
|
+
* shipped picker endpoint below. */
|
|
656
|
+
result = null
|
|
657
|
+
}
|
|
658
|
+
if (result !== null && typeof result === 'object') {
|
|
659
|
+
if (result.ok === true) {
|
|
660
|
+
const value = result.value !== null && typeof result.value === 'object' ? result.value.path : undefined
|
|
661
|
+
if (typeof value === 'string' && value !== '') return value
|
|
662
|
+
throw new Error('createChild answered without a directory path')
|
|
663
|
+
} else if (result.error !== null && typeof result.error === 'object' && typeof result.error.code === 'string') {
|
|
664
|
+
throw Object.assign(new Error(String(result.error.message || result.error.code)), { code: result.error.code })
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return uiWorkspace.createDirectory(parent, name)
|
|
669
|
+
}
|
|
670
|
+
|
|
464
671
|
/* ------------------------------------------------------- context menus */
|
|
465
672
|
|
|
466
673
|
ctx.effect(
|
|
@@ -541,6 +748,11 @@ window.__ModuleLoader__.load({
|
|
|
541
748
|
'dsh-nested-workspaces: move-to menu',
|
|
542
749
|
)
|
|
543
750
|
|
|
751
|
+
/* Pin/unpin is NOT registered here. ui-workspace already contributes
|
|
752
|
+
* `session.pin` at order 100 (guarding archived rows and the pin/unpin
|
|
753
|
+
* capability), and a second contribution would show the toggle twice in
|
|
754
|
+
* the same menu. The plugin's value-add is the row button below. */
|
|
755
|
+
|
|
544
756
|
/* --------------------------------------------------------------- dialog */
|
|
545
757
|
|
|
546
758
|
function NewWorkspaceDialog(props) {
|
|
@@ -568,6 +780,10 @@ window.__ModuleLoader__.load({
|
|
|
568
780
|
if (code === 'directory-picker/exists' || message.includes('directory-exists') || message.includes('already exists')) {
|
|
569
781
|
return t('errors.exists')
|
|
570
782
|
}
|
|
783
|
+
/* The Host answers these two with a stable code and an English OS
|
|
784
|
+
* string; show the localized wording instead of the raw message. */
|
|
785
|
+
if (code === 'nested-workspaces/invalid-parent') return t('errors.invalidParent')
|
|
786
|
+
if (code === 'directory-picker/unreadable') return t('errors.unreadable')
|
|
571
787
|
return t('errors.createFailed', { message })
|
|
572
788
|
}
|
|
573
789
|
|
|
@@ -587,7 +803,7 @@ window.__ModuleLoader__.load({
|
|
|
587
803
|
try {
|
|
588
804
|
let path = trimmed
|
|
589
805
|
if (isChild) {
|
|
590
|
-
path = await
|
|
806
|
+
path = await createChildDirectory(request.parentPath, trimmed)
|
|
591
807
|
} else if (path === '') {
|
|
592
808
|
/* No typed path: ask the host's directory picker, which is the
|
|
593
809
|
* same flow the shipped picker uses. */
|
|
@@ -598,12 +814,24 @@ window.__ModuleLoader__.load({
|
|
|
598
814
|
setValue(picked)
|
|
599
815
|
setBusy(true)
|
|
600
816
|
}
|
|
601
|
-
await workspaces.create({ path })
|
|
817
|
+
const created = await workspaces.create({ path })
|
|
602
818
|
if (isChild) {
|
|
603
819
|
store.update(state => ({
|
|
604
820
|
...state,
|
|
605
821
|
collapsed: { ...state.collapsed, [request.parentId]: false },
|
|
606
822
|
}))
|
|
823
|
+
/* Land the new child at the TOP of its siblings instead of below
|
|
824
|
+
* them. The Host appends new registrations after the existing
|
|
825
|
+
* ones, so anchor the new workspace to the first sibling that is
|
|
826
|
+
* already registered under the same parent. */
|
|
827
|
+
const createdId = created && created.workspaceId ? created.workspaceId : null
|
|
828
|
+
if (createdId !== null) {
|
|
829
|
+
const snapshot = workspaces.list.getSnapshot()
|
|
830
|
+
const siblings = snapshot.items
|
|
831
|
+
.filter(item => item.workspaceId !== createdId)
|
|
832
|
+
.filter(item => owningParentPath(item.path, snapshot.items.map(entry => entry.path)) === request.parentPath)
|
|
833
|
+
if (siblings.length > 0) await workspaces.insertBefore(createdId, siblings[0].workspaceId).catch(() => {})
|
|
834
|
+
}
|
|
607
835
|
notify(t('createdChild'), true)
|
|
608
836
|
} else {
|
|
609
837
|
notify(t('created'), true)
|
|
@@ -1012,18 +1240,71 @@ window.__ModuleLoader__.load({
|
|
|
1012
1240
|
*/
|
|
1013
1241
|
function SessionRow(props) {
|
|
1014
1242
|
const { session, groupKey, index, bucket, env } = props
|
|
1015
|
-
const { view, statuses, t, uiWorkspace, useSessionAccess, openMenu, assignSession, dragIdRef, draggingId, dropTarget, setDropTarget, setDraggingId } = env
|
|
1243
|
+
const { view, statuses, t, uiWorkspace, list, useSessionAccess, openMenu, assignSession, dragIdRef, draggingId, dropTarget, setDropTarget, setDraggingId, now } = env
|
|
1016
1244
|
const isArchived = view.archived.has(session.id)
|
|
1245
|
+
const isPinned = view.pinned.has(session.id) && !isArchived
|
|
1017
1246
|
const label = session.blank ? (session.id === view.currentId ? t('session.new') : t('session.untitled')) : sessionTitle(session)
|
|
1018
1247
|
const title = label === '' ? t('session.untitled') : label
|
|
1019
1248
|
const status = statuses.get(session.id)
|
|
1020
1249
|
const running = status !== undefined && status.running === true
|
|
1250
|
+
/* Shipped precedence (ui-workspace Rows.tsx sessionStatuses): a pending
|
|
1251
|
+
* interaction wins, then running, then running subagents, then an unread
|
|
1252
|
+
* completion, and otherwise the row is idle and draws no glyph. */
|
|
1253
|
+
const pendingKind = status === undefined ? undefined : status.pendingInteraction === undefined ? undefined : status.pendingInteraction.kind
|
|
1254
|
+
const runningChildren = runningSubagentCount(list, session.id, statuses)
|
|
1255
|
+
const statusState =
|
|
1256
|
+
session.blank || isArchived
|
|
1257
|
+
? 'idle'
|
|
1258
|
+
: pendingKind !== undefined && pendingKind !== null
|
|
1259
|
+
? 'warning'
|
|
1260
|
+
: running
|
|
1261
|
+
? 'ongoing'
|
|
1262
|
+
: runningChildren > 0
|
|
1263
|
+
? 'ongoing'
|
|
1264
|
+
: status !== undefined && status.completionUnread === true
|
|
1265
|
+
? 'done'
|
|
1266
|
+
: 'idle'
|
|
1267
|
+
const statusLabel =
|
|
1268
|
+
statusState === 'idle'
|
|
1269
|
+
? null
|
|
1270
|
+
: statusState === 'warning'
|
|
1271
|
+
? t(pendingKind === 'approval' ? 'status.waitingApproval' : pendingKind === 'plan-review' ? 'status.planReview' : 'status.waitingAnswer')
|
|
1272
|
+
: statusState === 'ongoing'
|
|
1273
|
+
? running
|
|
1274
|
+
? t('status.running')
|
|
1275
|
+
: t('status.subagentsRunning', { n: runningChildren })
|
|
1276
|
+
: t('status.completed')
|
|
1021
1277
|
const selected = session.id === view.currentId
|
|
1022
1278
|
const canUnarchive = useSessionAccess(session.id, 'workspace/unarchiveSession')
|
|
1023
1279
|
const canMove = useSessionAccess(session.id, 'workspace/insertSessionBefore')
|
|
1280
|
+
const canPin = useSessionAccess(session.id, isPinned ? 'workspace/unpinSession' : 'workspace/pinSession')
|
|
1024
1281
|
const canDrag = !session.blank && !isArchived && canMove
|
|
1025
1282
|
const rowDropPosition = dropTarget !== null && dropTarget.sessionId === session.id ? dropTarget.position : null
|
|
1026
1283
|
const actions = []
|
|
1284
|
+
const menuOpen = env.menuOpenSessionId === session.id
|
|
1285
|
+
if (!session.blank && !isArchived && canPin) {
|
|
1286
|
+
actions.push(
|
|
1287
|
+
h(
|
|
1288
|
+
'button',
|
|
1289
|
+
{
|
|
1290
|
+
type: 'button',
|
|
1291
|
+
key: 'pin',
|
|
1292
|
+
className: cls('dnw-iconButton', isPinned && 'dnw-iconButtonOn'),
|
|
1293
|
+
title: t(isPinned ? 'actions.unpin' : 'actions.pin'),
|
|
1294
|
+
'aria-label': t(isPinned ? 'actions.unpin' : 'actions.pin') + ' ' + title,
|
|
1295
|
+
'aria-pressed': isPinned,
|
|
1296
|
+
onClick: event => {
|
|
1297
|
+
event.stopPropagation()
|
|
1298
|
+
const task = isPinned ? uiWorkspace.unpinSession(session.id) : uiWorkspace.pinSession(session.id)
|
|
1299
|
+
if (task !== null && typeof task === 'object' && typeof task.catch === 'function') {
|
|
1300
|
+
task.catch(() => notify(t('errors.pinFailed'), false))
|
|
1301
|
+
}
|
|
1302
|
+
},
|
|
1303
|
+
},
|
|
1304
|
+
h(isPinned ? IconPin : IconPinOutline, null),
|
|
1305
|
+
),
|
|
1306
|
+
)
|
|
1307
|
+
}
|
|
1027
1308
|
if (!session.blank && !isArchived) {
|
|
1028
1309
|
actions.push(
|
|
1029
1310
|
openMenu(
|
|
@@ -1135,19 +1416,54 @@ window.__ModuleLoader__.load({
|
|
|
1135
1416
|
},
|
|
1136
1417
|
onClick: activate,
|
|
1137
1418
|
},
|
|
1419
|
+
/* Leading cell, matching the shipped browser: an idle session shows
|
|
1420
|
+
* nothing at all, a running one shows the rotating spinner, and a
|
|
1421
|
+
* pending interaction or unread completion shows a state dot. */
|
|
1138
1422
|
h(
|
|
1139
1423
|
'span',
|
|
1140
1424
|
{ className: 'dnw-slot' },
|
|
1141
|
-
|
|
1425
|
+
statusState === 'ongoing' ? h(StatusSpinner, null) : null,
|
|
1426
|
+
statusState !== 'ongoing' && statusState !== 'idle'
|
|
1427
|
+
? h('span', { className: 'dnw-stateDot', 'data-state': statusState, style: { width: '10px', height: '10px' }, 'aria-hidden': 'true' })
|
|
1428
|
+
: null,
|
|
1429
|
+
statusLabel === null ? null : h('span', { className: 'dnw-visuallyHidden' }, statusLabel),
|
|
1142
1430
|
),
|
|
1143
1431
|
h('span', { className: cls('dnw-title', (session.blank || isArchived) && 'dnw-titleMuted') }, title),
|
|
1144
|
-
|
|
1432
|
+
/* Resting cell: the last-used time and, when pinned, the pin glyph —
|
|
1433
|
+
* the shipped browser swaps this cell for the action buttons on
|
|
1434
|
+
* hover, and so does this one. */
|
|
1435
|
+
session.blank
|
|
1436
|
+
? null
|
|
1437
|
+
: h(
|
|
1438
|
+
'span',
|
|
1439
|
+
{ className: 'dnw-resting' },
|
|
1440
|
+
h(
|
|
1441
|
+
'span',
|
|
1442
|
+
{ className: 'dnw-time', title: hoverTimeLabel(session.updatedAt, now, t) },
|
|
1443
|
+
timeLabel(session.updatedAt, now, t),
|
|
1444
|
+
),
|
|
1445
|
+
isPinned
|
|
1446
|
+
? h(
|
|
1447
|
+
'span',
|
|
1448
|
+
{
|
|
1449
|
+
className: 'dnw-pinIndicator',
|
|
1450
|
+
role: 'img',
|
|
1451
|
+
'aria-label': t('row.pinned'),
|
|
1452
|
+
title: t('row.pinned'),
|
|
1453
|
+
},
|
|
1454
|
+
h(IconPin, null),
|
|
1455
|
+
)
|
|
1456
|
+
: null,
|
|
1457
|
+
),
|
|
1458
|
+
actions.length === 0
|
|
1459
|
+
? null
|
|
1460
|
+
: h('span', { className: cls('dnw-actions', menuOpen && 'dnw-actionsOpen') }, ...actions),
|
|
1145
1461
|
)
|
|
1146
1462
|
}
|
|
1147
1463
|
|
|
1148
1464
|
function WorkspaceGroup(props) {
|
|
1149
1465
|
const { workspace, depth, env } = props
|
|
1150
|
-
const { view, state, t, uiWorkspace, useWorkspaceAccess, openMenu, openWorkspaceMenu, assignSession, setExpanded, setRenaming, menu, dragIdRef, draggingId, dropTarget, setDropTarget, setDraggingId } = env
|
|
1466
|
+
const { view, state, t, uiWorkspace, useWorkspaceAccess, openMenu, openWorkspaceMenu, assignSession, setExpanded, setRenaming, menu, dragIdRef, draggingId, dropTarget, setDropTarget, setDraggingId, workspaceDrag, draggingWorkspaceId, beginWorkspaceDrag, endWorkspaceDrag, hoverWorkspaceDrag, workspaceClickBlockRef } = env
|
|
1151
1467
|
const workspaceId = workspace.workspaceId
|
|
1152
1468
|
const collapsed = state.collapsed[workspaceId] === true
|
|
1153
1469
|
const members = view.members.get(workspaceId) || []
|
|
@@ -1161,17 +1477,44 @@ window.__ModuleLoader__.load({
|
|
|
1161
1477
|
const indent = { '--dnw-indent': depth * INDENT_PX + 'px' }
|
|
1162
1478
|
const canCreateSession = useWorkspaceAccess(workspaceId, 'session/create')
|
|
1163
1479
|
const collapsible = children.length > 0 || hasSessions
|
|
1480
|
+
/* A workspace drag is legal only between rows that share a parent, so a
|
|
1481
|
+
* child can be reordered among its siblings but never leave its root. */
|
|
1482
|
+
const parentId = view.parentOf.get(workspaceId)
|
|
1483
|
+
const workspaceSibling =
|
|
1484
|
+
workspaceDrag !== null &&
|
|
1485
|
+
workspaceDrag.workspaceId !== workspaceId &&
|
|
1486
|
+
view.parentOf.get(workspaceDrag.workspaceId) === parentId
|
|
1487
|
+
const workspaceDropHalf =
|
|
1488
|
+
workspaceSibling && workspaceDrag.over !== null && workspaceDrag.over.id === workspaceId
|
|
1489
|
+
? workspaceDrag.over.half
|
|
1490
|
+
: null
|
|
1164
1491
|
const row = h(
|
|
1165
1492
|
'div',
|
|
1166
1493
|
{
|
|
1167
1494
|
key: 'w:' + workspaceId,
|
|
1168
|
-
className: cls(
|
|
1495
|
+
className: cls(
|
|
1496
|
+
'dnw-row',
|
|
1497
|
+
'dnw-workspaceRow',
|
|
1498
|
+
isDropTarget && 'dnw-dropOn',
|
|
1499
|
+
workspaceDropHalf === 'before' && 'dnw-dropBefore',
|
|
1500
|
+
workspaceDropHalf === 'after' && 'dnw-dropAfter',
|
|
1501
|
+
draggingWorkspaceId === workspaceId && 'dnw-rowDragging',
|
|
1502
|
+
),
|
|
1169
1503
|
role: 'treeitem',
|
|
1170
1504
|
tabIndex: 0,
|
|
1505
|
+
draggable: true,
|
|
1171
1506
|
'aria-expanded': !collapsed,
|
|
1172
1507
|
'aria-label': workspace.title + ' — ' + workspace.path,
|
|
1173
1508
|
style: indent,
|
|
1174
|
-
onClick: () =>
|
|
1509
|
+
onClick: () => {
|
|
1510
|
+
/* A drag ends with a click; expanding on it would undo the drop. */
|
|
1511
|
+
if (draggingWorkspaceId !== null) return
|
|
1512
|
+
if (workspaceClickBlockRef.current) {
|
|
1513
|
+
workspaceClickBlockRef.current = false
|
|
1514
|
+
return
|
|
1515
|
+
}
|
|
1516
|
+
setExpanded(workspaceId, collapsed)
|
|
1517
|
+
},
|
|
1175
1518
|
onKeyDown: event => {
|
|
1176
1519
|
if (event.target !== event.currentTarget) return
|
|
1177
1520
|
if (event.key !== 'Enter' && event.key !== ' ') return
|
|
@@ -1179,7 +1522,50 @@ window.__ModuleLoader__.load({
|
|
|
1179
1522
|
setExpanded(workspaceId, collapsed)
|
|
1180
1523
|
},
|
|
1181
1524
|
onContextMenu: event => openWorkspaceMenu(event, workspace),
|
|
1525
|
+
onDragStart: event => {
|
|
1526
|
+
/* `draggable` lives on the row, so the target is normally the row
|
|
1527
|
+
* itself; a drag started on the action buttons must not reorder. */
|
|
1528
|
+
const fromActions =
|
|
1529
|
+
event.target !== event.currentTarget &&
|
|
1530
|
+
typeof Element !== 'undefined' &&
|
|
1531
|
+
event.target instanceof Element &&
|
|
1532
|
+
event.target.closest('.dnw-actions') !== null
|
|
1533
|
+
if (fromActions) {
|
|
1534
|
+
event.preventDefault()
|
|
1535
|
+
return
|
|
1536
|
+
}
|
|
1537
|
+
event.stopPropagation()
|
|
1538
|
+
try {
|
|
1539
|
+
event.dataTransfer.effectAllowed = 'move'
|
|
1540
|
+
event.dataTransfer.setData('text/plain', workspaceId)
|
|
1541
|
+
} catch {
|
|
1542
|
+
/* ignore */
|
|
1543
|
+
}
|
|
1544
|
+
beginWorkspaceDrag(workspaceId)
|
|
1545
|
+
},
|
|
1546
|
+
onDragEnd: () => {
|
|
1547
|
+
endWorkspaceDrag()
|
|
1548
|
+
},
|
|
1182
1549
|
onDragOver: event => {
|
|
1550
|
+
if (workspaceDrag !== null) {
|
|
1551
|
+
/* Workspace reorder: sibling rows only, chosen by row midpoint. */
|
|
1552
|
+
if (!workspaceSibling) {
|
|
1553
|
+
/* Keep swallowing the event so the session path below cannot
|
|
1554
|
+
* mistake a workspace drag for a session drop. */
|
|
1555
|
+
return
|
|
1556
|
+
}
|
|
1557
|
+
event.preventDefault()
|
|
1558
|
+
event.stopPropagation()
|
|
1559
|
+
try {
|
|
1560
|
+
event.dataTransfer.dropEffect = 'move'
|
|
1561
|
+
} catch {
|
|
1562
|
+
/* ignore */
|
|
1563
|
+
}
|
|
1564
|
+
const rect = event.currentTarget.getBoundingClientRect()
|
|
1565
|
+
const half = event.clientY < rect.top + rect.height / 2 ? 'before' : 'after'
|
|
1566
|
+
if (workspaceDropHalf !== half) hoverWorkspaceDrag(workspaceId, half)
|
|
1567
|
+
return
|
|
1568
|
+
}
|
|
1183
1569
|
if (dragIdRef.current === null) return
|
|
1184
1570
|
event.preventDefault()
|
|
1185
1571
|
event.stopPropagation()
|
|
@@ -1197,9 +1583,10 @@ window.__ModuleLoader__.load({
|
|
|
1197
1583
|
if (isDropTarget) setDropTarget(null)
|
|
1198
1584
|
},
|
|
1199
1585
|
onDrop: event => {
|
|
1200
|
-
const id = dragIdRef.current || event.dataTransfer.getData('text/plain')
|
|
1201
1586
|
event.preventDefault()
|
|
1202
1587
|
event.stopPropagation()
|
|
1588
|
+
if (workspaceDrag !== null) return
|
|
1589
|
+
const id = dragIdRef.current || event.dataTransfer.getData('text/plain')
|
|
1203
1590
|
setDropTarget(null)
|
|
1204
1591
|
setDraggingId(null)
|
|
1205
1592
|
dragIdRef.current = null
|
|
@@ -1275,10 +1662,14 @@ window.__ModuleLoader__.load({
|
|
|
1275
1662
|
)
|
|
1276
1663
|
|
|
1277
1664
|
const body = []
|
|
1278
|
-
|
|
1665
|
+
/* Shipped section order: the workspace header, then its child
|
|
1666
|
+
* workspaces, then the workspace's own session rows. A newly created
|
|
1667
|
+
* child therefore sits directly under its parent instead of at the
|
|
1668
|
+
* bottom of the section. */
|
|
1279
1669
|
if (visible) {
|
|
1280
1670
|
for (const child of children) body.push(h(WorkspaceGroup, { key: 'grp:' + child.workspaceId, workspace: child, depth: depth + 1, env }))
|
|
1281
1671
|
}
|
|
1672
|
+
if (visible && hasSessions) body.push(h('div', { key: 'g:' + workspaceId, role: 'group', style: indent }, members.map((session, index) => h(SessionRow, { key: 's:' + session.id, session, groupKey: workspaceId, index, bucket: members, env }))))
|
|
1282
1673
|
return h(Fragment, { key: 'grp:' + workspaceId }, row, ...body)
|
|
1283
1674
|
}
|
|
1284
1675
|
|
|
@@ -1290,6 +1681,18 @@ window.__ModuleLoader__.load({
|
|
|
1290
1681
|
const useSessionAccess = typeof props.useSessionAccess === 'function' ? props.useSessionAccess : () => true
|
|
1291
1682
|
const state = useSyncExternalStore(store.subscribe, store.get, store.get)
|
|
1292
1683
|
const request = useSyncExternalStore(addChildRequest.subscribe, addChildRequest.get, addChildRequest.get)
|
|
1684
|
+
/* The shared context menu portals out of the row, so neither :hover nor
|
|
1685
|
+
* :focus-within holds while a row's menu is open. Track the menu's
|
|
1686
|
+
* active target instead, exactly like the shipped `.sessionRow.menuOpen`. */
|
|
1687
|
+
const menuTarget = useSyncExternalStore(
|
|
1688
|
+
contextMenus.active.subscribe,
|
|
1689
|
+
contextMenus.active.getSnapshot,
|
|
1690
|
+
contextMenus.active.getSnapshot,
|
|
1691
|
+
)
|
|
1692
|
+
const menuOpenSessionId =
|
|
1693
|
+
menuTarget !== null && menuTarget !== undefined && menuTarget.kind === 'session'
|
|
1694
|
+
? menuTarget.value.sessionId
|
|
1695
|
+
: null
|
|
1293
1696
|
const list = useSessions(snapshot => snapshot)
|
|
1294
1697
|
const workspaceSnapshot = useWorkspaces(snapshot => snapshot)
|
|
1295
1698
|
const statuses = useSessionStatus(snapshot => snapshot)
|
|
@@ -1303,6 +1706,11 @@ window.__ModuleLoader__.load({
|
|
|
1303
1706
|
const [query, setQuery] = useState('')
|
|
1304
1707
|
const [draggingId, setDraggingId] = useState(null)
|
|
1305
1708
|
const [dropTarget, setDropTarget] = useState(null)
|
|
1709
|
+
const [workspaceDrag, setWorkspaceDrag] = useState(null)
|
|
1710
|
+
const workspaceDragRef = useRef(null)
|
|
1711
|
+
/* Some browsers still deliver a click after a drag ends; that click must
|
|
1712
|
+
* not also toggle the group open/closed. */
|
|
1713
|
+
const workspaceClickBlockRef = useRef(false)
|
|
1306
1714
|
const [menu, setMenu] = useState(null)
|
|
1307
1715
|
const [renaming, setRenaming] = useState(null)
|
|
1308
1716
|
const [deleting, setDeleting] = useState(null)
|
|
@@ -1345,6 +1753,7 @@ window.__ModuleLoader__.load({
|
|
|
1345
1753
|
}
|
|
1346
1754
|
|
|
1347
1755
|
const archived = new Set(workspaceSnapshot.archivedSessionIds)
|
|
1756
|
+
const pinned = new Set(workspaceSnapshot.pinnedSessionIds)
|
|
1348
1757
|
const realOwner = new Map()
|
|
1349
1758
|
for (const item of items) for (const id of item.sessionIds) realOwner.set(id, item.workspaceId)
|
|
1350
1759
|
const currentId = list.ids.find(id => ((list.byId[id] && list.byId[id].retainedBy.mainView) || 0) > 0) || null
|
|
@@ -1384,27 +1793,38 @@ window.__ModuleLoader__.load({
|
|
|
1384
1793
|
const saved = state.order[key]
|
|
1385
1794
|
if (!Array.isArray(saved) || saved.length === 0) {
|
|
1386
1795
|
bucket.sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : a.updatedAt > b.updatedAt ? -1 : 0))
|
|
1387
|
-
|
|
1796
|
+
} else {
|
|
1797
|
+
const rank = new Map()
|
|
1798
|
+
for (let index = 0; index < saved.length; index += 1) rank.set(saved[index], index)
|
|
1799
|
+
const known = []
|
|
1800
|
+
const rest = []
|
|
1801
|
+
for (const session of bucket) {
|
|
1802
|
+
if (rank.has(session.id)) known.push(session)
|
|
1803
|
+
else rest.push(session)
|
|
1804
|
+
}
|
|
1805
|
+
known.sort((a, b) => rank.get(a.id) - rank.get(b.id))
|
|
1806
|
+
rest.sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : a.updatedAt > b.updatedAt ? -1 : 0))
|
|
1807
|
+
bucket.splice(0, bucket.length, ...known, ...rest)
|
|
1388
1808
|
}
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
const
|
|
1392
|
-
const
|
|
1809
|
+
/* Shipped section order: the blank row, then pinned rows, then the
|
|
1810
|
+
* rest. Sorting after the manual order keeps both intact. */
|
|
1811
|
+
const leading = []
|
|
1812
|
+
const pinnedRows = []
|
|
1813
|
+
const trailing = []
|
|
1393
1814
|
for (const session of bucket) {
|
|
1394
|
-
if (
|
|
1395
|
-
else
|
|
1815
|
+
if (session.blank) leading.push(session)
|
|
1816
|
+
else if (pinned.has(session.id) && !archived.has(session.id)) pinnedRows.push(session)
|
|
1817
|
+
else trailing.push(session)
|
|
1396
1818
|
}
|
|
1397
|
-
|
|
1398
|
-
rest.sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : a.updatedAt > b.updatedAt ? -1 : 0))
|
|
1399
|
-
members.set(key, known.concat(rest))
|
|
1819
|
+
bucket.splice(0, bucket.length, ...leading, ...pinnedRows, ...trailing)
|
|
1400
1820
|
}
|
|
1401
1821
|
|
|
1402
1822
|
const filtering = needle !== ''
|
|
1403
1823
|
let visibleCount = 0
|
|
1404
1824
|
for (const bucket of members.values()) visibleCount += bucket.length
|
|
1405
1825
|
|
|
1406
|
-
return { byId, parentOf, childrenOf, roots, members, currentId, ownerOf, realOwner, archived, filtering, visibleCount }
|
|
1407
|
-
}, [items, list, state.order, state.assign, workspaceSnapshot.archivedSessionIds, query, showArchived])
|
|
1826
|
+
return { byId, parentOf, childrenOf, roots, members, currentId, ownerOf, realOwner, archived, pinned, filtering, visibleCount }
|
|
1827
|
+
}, [items, list, state.order, state.assign, workspaceSnapshot.archivedSessionIds, workspaceSnapshot.pinnedSessionIds, query, showArchived])
|
|
1408
1828
|
|
|
1409
1829
|
const setExpanded = useCallback((workspaceId, expanded) => {
|
|
1410
1830
|
store.update(current => ({
|
|
@@ -1413,9 +1833,71 @@ window.__ModuleLoader__.load({
|
|
|
1413
1833
|
}))
|
|
1414
1834
|
}, [])
|
|
1415
1835
|
|
|
1836
|
+
/* Workspace reorder. Mirrors the shipped `commitWorkspaceDrag`: the drop
|
|
1837
|
+
* anchor is the next row after the target, and a move that would leave
|
|
1838
|
+
* the order unchanged is dropped instead of being sent to the Host. */
|
|
1839
|
+
const commitWorkspaceDrag = useCallback(
|
|
1840
|
+
(drag, over) => {
|
|
1841
|
+
if (drag === null || over === null) return
|
|
1842
|
+
const owner = view.parentOf.get(drag.workspaceId)
|
|
1843
|
+
if (over !== null && view.parentOf.get(over.id) !== owner) return
|
|
1844
|
+
const siblings = items.filter(item => view.parentOf.get(item.workspaceId) === owner)
|
|
1845
|
+
const rowIndex = siblings.findIndex(item => item.workspaceId === over.id)
|
|
1846
|
+
if (rowIndex === -1) return
|
|
1847
|
+
const anchor = over.half === 'before' ? over.id : (siblings[rowIndex + 1] || {}).workspaceId
|
|
1848
|
+
if (anchor === drag.workspaceId) return
|
|
1849
|
+
const sourceIndex = siblings.findIndex(item => item.workspaceId === drag.workspaceId)
|
|
1850
|
+
const anchorIndex =
|
|
1851
|
+
anchor === undefined ? siblings.length : siblings.findIndex(item => item.workspaceId === anchor)
|
|
1852
|
+
if (sourceIndex !== -1 && (anchorIndex === sourceIndex || anchorIndex === sourceIndex + 1)) return
|
|
1853
|
+
workspaces.insertBefore(drag.workspaceId, anchor).catch(() => {
|
|
1854
|
+
notify(t('errors.reorderFailed'), false)
|
|
1855
|
+
})
|
|
1856
|
+
},
|
|
1857
|
+
[items, view, workspaces, notify, t],
|
|
1858
|
+
)
|
|
1859
|
+
|
|
1860
|
+
const beginWorkspaceDrag = useCallback(workspaceId => {
|
|
1861
|
+
const next = { workspaceId, over: null }
|
|
1862
|
+
workspaceDragRef.current = next
|
|
1863
|
+
workspaceClickBlockRef.current = true
|
|
1864
|
+
setWorkspaceDrag(next)
|
|
1865
|
+
}, [])
|
|
1866
|
+
|
|
1867
|
+
const hoverWorkspaceDrag = useCallback((id, half) => {
|
|
1868
|
+
const current = workspaceDragRef.current
|
|
1869
|
+
if (current === null) return
|
|
1870
|
+
if (current.over !== null && current.over.id === id && current.over.half === half) return
|
|
1871
|
+
const next = { ...current, over: { id, half } }
|
|
1872
|
+
workspaceDragRef.current = next
|
|
1873
|
+
setWorkspaceDrag(next)
|
|
1874
|
+
}, [])
|
|
1875
|
+
|
|
1876
|
+
const endWorkspaceDrag = useCallback(() => {
|
|
1877
|
+
const current = workspaceDragRef.current
|
|
1878
|
+
workspaceDragRef.current = null
|
|
1879
|
+
setWorkspaceDrag(null)
|
|
1880
|
+
if (current !== null && current.over !== null) commitWorkspaceDrag(current, current.over)
|
|
1881
|
+
/* The click that follows a drop arrives after `dragend`; keep the
|
|
1882
|
+
* block for one task so it is swallowed, then re-arm the row. */
|
|
1883
|
+
window.setTimeout(() => {
|
|
1884
|
+
workspaceClickBlockRef.current = false
|
|
1885
|
+
}, 0)
|
|
1886
|
+
}, [commitWorkspaceDrag])
|
|
1887
|
+
|
|
1416
1888
|
const assignSession = useCallback(
|
|
1417
1889
|
(sessionId, groupKey, beforeSessionId) => {
|
|
1418
1890
|
if (typeof sessionId !== 'string' || sessionId === '') return
|
|
1891
|
+
/* The display bucket is re-partitioned blank → pinned → rest after a
|
|
1892
|
+
* drop index is derived, so a drop that crosses the pinned boundary
|
|
1893
|
+
* would land somewhere other than the marker promised. Refuse it. */
|
|
1894
|
+
if (
|
|
1895
|
+
beforeSessionId !== undefined &&
|
|
1896
|
+
beforeSessionId !== null &&
|
|
1897
|
+
view.pinned.has(sessionId) !== view.pinned.has(beforeSessionId)
|
|
1898
|
+
) {
|
|
1899
|
+
return
|
|
1900
|
+
}
|
|
1419
1901
|
store.update(current => {
|
|
1420
1902
|
const realOwner = view.realOwner.get(sessionId)
|
|
1421
1903
|
const previousKey = view.ownerOf(sessionId)
|
|
@@ -1547,10 +2029,13 @@ window.__ModuleLoader__.load({
|
|
|
1547
2029
|
|
|
1548
2030
|
/* One bag of closures for the row components; rebuilt each render. */
|
|
1549
2031
|
const env = {
|
|
1550
|
-
view, state, statuses, t, uiWorkspace,
|
|
2032
|
+
view, state, statuses, t, uiWorkspace, list,
|
|
1551
2033
|
useSessionAccess, useWorkspaceAccess,
|
|
1552
2034
|
openMenu, openWorkspaceMenu, assignSession, setExpanded, setRenaming,
|
|
1553
|
-
menu, draggingId, dropTarget, dragIdRef, setDraggingId, setDropTarget,
|
|
2035
|
+
menu, menuOpenSessionId, draggingId, dropTarget, dragIdRef, setDraggingId, setDropTarget,
|
|
2036
|
+
workspaceDrag, draggingWorkspaceId: workspaceDrag === null ? null : workspaceDrag.workspaceId,
|
|
2037
|
+
beginWorkspaceDrag, hoverWorkspaceDrag, endWorkspaceDrag, workspaceClickBlockRef,
|
|
2038
|
+
now: Date.now(),
|
|
1554
2039
|
}
|
|
1555
2040
|
|
|
1556
2041
|
const tree = []
|
|
@@ -1579,6 +2064,7 @@ window.__ModuleLoader__.load({
|
|
|
1579
2064
|
setExpanded(UNGROUPED, ungroupedCollapsed)
|
|
1580
2065
|
},
|
|
1581
2066
|
onDragOver: event => {
|
|
2067
|
+
if (workspaceDrag !== null) return
|
|
1582
2068
|
if (dragIdRef.current === null) return
|
|
1583
2069
|
event.preventDefault()
|
|
1584
2070
|
event.stopPropagation()
|
|
@@ -1589,9 +2075,12 @@ window.__ModuleLoader__.load({
|
|
|
1589
2075
|
if (isUngroupedDrop) setDropTarget(null)
|
|
1590
2076
|
},
|
|
1591
2077
|
onDrop: event => {
|
|
1592
|
-
const id = dragIdRef.current || event.dataTransfer.getData('text/plain')
|
|
1593
2078
|
event.preventDefault()
|
|
1594
2079
|
event.stopPropagation()
|
|
2080
|
+
/* The ungrouped bucket is not a real workspace: it accepts
|
|
2081
|
+
* sessions but must never take part in a workspace reorder. */
|
|
2082
|
+
if (workspaceDrag !== null) return
|
|
2083
|
+
const id = dragIdRef.current || event.dataTransfer.getData('text/plain')
|
|
1595
2084
|
setDropTarget(null)
|
|
1596
2085
|
setDraggingId(null)
|
|
1597
2086
|
dragIdRef.current = null
|
package/index.js
CHANGED
|
@@ -1,8 +1,140 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Host half of the nested-workspaces bundle.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* workspace
|
|
4
|
+
* Child workspaces are ordinary workspaces whose directory sits inside the parent
|
|
5
|
+
* workspace, so the workspace controller already persists them — nothing here
|
|
6
|
+
* touches workspace records.
|
|
7
|
+
*
|
|
8
|
+
* The one thing the Host must do is make the child directory. The Client's
|
|
9
|
+
* `uiWorkspace.createDirectory()` goes through the composed directory picker,
|
|
10
|
+
* and a Host whose picker backend is the OS chooser serves only the `native`
|
|
11
|
+
* capability: `directoryPicker.createDirectory` then answers
|
|
12
|
+
* `directory-picker/unavailable: ... needs the browse capability`. Creating a
|
|
13
|
+
* folder is not really a "browse" feature, so this bundle answers it over the
|
|
14
|
+
* public Connection transport instead (the same `/api` carrier other bundles
|
|
15
|
+
* use), and the Client falls back to `createDirectory` when this route is
|
|
16
|
+
* missing.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { mkdir, stat } from 'node:fs/promises'
|
|
20
|
+
import path from 'node:path'
|
|
21
|
+
|
|
22
|
+
/** Connection is the only Host service this half needs. */
|
|
23
|
+
export const inject = ['connection']
|
|
24
|
+
|
|
25
|
+
/** Exact route below `/api`; Connection rejects anything that is not an exact `/api/...` path. */
|
|
26
|
+
const ROUTE_PATH = '/api/nested-workspaces'
|
|
27
|
+
/** Envelope method name, mirrored by the Client call. */
|
|
28
|
+
const ENDPOINT = 'nested-workspaces'
|
|
29
|
+
|
|
30
|
+
/** A child name becomes one directory segment, so it may not carry a separator. */
|
|
31
|
+
const INVALID_NAME = /[\\/]/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Validate the requested child name.
|
|
35
|
+
* @param value - raw name from the Client.
|
|
36
|
+
* @returns the trimmed name, or null when it cannot be a directory segment.
|
|
37
|
+
*/
|
|
38
|
+
function normalizeName(value) {
|
|
39
|
+
if (typeof value !== 'string') return null
|
|
40
|
+
const name = value.trim()
|
|
41
|
+
if (name === '' || name === '.' || name === '..') return null
|
|
42
|
+
if (INVALID_NAME.test(name)) return null
|
|
43
|
+
return name
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** One failure result in the Connection envelope. */
|
|
47
|
+
function failure(code, message) {
|
|
48
|
+
return { ok: false, error: { code, message, details: {} } }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Create `<parent>/<name>` without creating any other segment.
|
|
53
|
+
* @param payload - decoded request payload.
|
|
54
|
+
* @returns a Connection handler result.
|
|
55
|
+
*/
|
|
56
|
+
async function createChild(payload) {
|
|
57
|
+
const parent = payload !== null && typeof payload === 'object' ? payload.parent : undefined
|
|
58
|
+
const name = normalizeName(payload !== null && typeof payload === 'object' ? payload.name : undefined)
|
|
59
|
+
if (typeof parent !== 'string' || parent.trim() === '') {
|
|
60
|
+
return failure('nested-workspaces/invalid-parent', 'A parent directory is required.')
|
|
61
|
+
}
|
|
62
|
+
if (name === null) {
|
|
63
|
+
return failure('nested-workspaces/invalid-name', 'A child name may not be empty, "." , ".." or contain a separator.')
|
|
64
|
+
}
|
|
65
|
+
const target = path.join(parent, name)
|
|
66
|
+
try {
|
|
67
|
+
await mkdir(target)
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error !== null && typeof error === 'object' && error.code === 'EEXIST') {
|
|
70
|
+
return failure('directory-picker/exists', `"${target}" already exists.`)
|
|
71
|
+
}
|
|
72
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
73
|
+
return failure('directory-picker/create-failed', message)
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const info = await stat(target)
|
|
77
|
+
if (!info.isDirectory()) {
|
|
78
|
+
return failure('directory-picker/create-failed', `"${target}" is not a directory.`)
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
82
|
+
return failure('directory-picker/unreadable', message)
|
|
83
|
+
}
|
|
84
|
+
return { ok: true, value: { path: target } }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Reply in the envelope `createWebConnectionRpc` parses. */
|
|
88
|
+
function reply(rpcId, result) {
|
|
89
|
+
return Response.json({ type: 'server-response', rpcId, result })
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Register the child-directory route.
|
|
94
|
+
* @param ctx - the Host plugin context.
|
|
7
95
|
*/
|
|
8
|
-
export function apply() {
|
|
96
|
+
export function apply(ctx) {
|
|
97
|
+
let dispose
|
|
98
|
+
try {
|
|
99
|
+
dispose = ctx.connection.fetch.register({
|
|
100
|
+
path: ROUTE_PATH,
|
|
101
|
+
methods: ['POST'],
|
|
102
|
+
requestBody: 'buffered',
|
|
103
|
+
async fetch(request) {
|
|
104
|
+
if (request.method !== 'POST') return new Response('method not allowed', { status: 405 })
|
|
105
|
+
let message
|
|
106
|
+
try {
|
|
107
|
+
message = await request.json()
|
|
108
|
+
} catch {
|
|
109
|
+
return new Response('body is not JSON', { status: 400 })
|
|
110
|
+
}
|
|
111
|
+
const rpcId = message !== null && typeof message === 'object' && typeof message.rpcId === 'string'
|
|
112
|
+
? message.rpcId
|
|
113
|
+
: 'invalid-request'
|
|
114
|
+
if (
|
|
115
|
+
message === null
|
|
116
|
+
|| typeof message !== 'object'
|
|
117
|
+
|| message.type !== 'client-request'
|
|
118
|
+
|| typeof message.method !== 'string'
|
|
119
|
+
|| message.method !== ENDPOINT
|
|
120
|
+
) {
|
|
121
|
+
return reply(rpcId, failure('gateway/bad-request', 'Invalid nested-workspaces request.'))
|
|
122
|
+
}
|
|
123
|
+
const payload = message.payload
|
|
124
|
+
if (payload === null || typeof payload !== 'object' || payload.action !== 'createChild') {
|
|
125
|
+
return reply(rpcId, failure('gateway/bad-request', 'Unknown nested-workspaces action.'))
|
|
126
|
+
}
|
|
127
|
+
return reply(rpcId, await createChild(payload))
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
} catch (error) {
|
|
131
|
+
/* The route registry is a Host-wide singleton: a live reload can reach this
|
|
132
|
+
* line with the previous instance still holding the path. Yielding keeps the
|
|
133
|
+
* serving instance authoritative instead of failing the whole composition. */
|
|
134
|
+
if (/already registered/.test(String(error && error.message ? error.message : error))) return
|
|
135
|
+
throw error
|
|
136
|
+
}
|
|
137
|
+
/* `fetch.register` already returns the disposer that drops the route; hand it
|
|
138
|
+
* straight to the effect instead of wrapping it a second time. */
|
|
139
|
+
ctx.effect(() => dispose, 'dsh-nested-workspaces: child directory route')
|
|
140
|
+
}
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Nested workspaces",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "Nested child workspaces in the DeepSeek Harness sidebar. Create a child workspace inside its parent folder without the OS picker, drag workspaces to reorder siblings, drag sessions between workspaces, rename the section title by double-clicking, and see each session last-used time and pin marker."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/ja.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "子ワークスペース",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "DeepSeek Harness のサイドバーで子ワークスペースを扱います。OS のフォルダ選択なしで親フォルダ内に作成し、ワークスペースをドラッグして同階層の順序を変更し、セッションを別のワークスペースへ移動でき、見出しはダブルクリックで変更、各セッションの最終使用時刻とピン留めも表示します。"
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "子工作区",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "在 DeepSeek Harness 侧边栏中创建子工作区:在父目录内直接新建(无需系统目录选择器)、拖动工作区调整同级顺序、把会话拖到其它工作区、双击改写分区标题,并显示每个会话的最近使用时间与置顶标记。"
|
|
5
5
|
}
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-nested-workspaces",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Nested child workspaces in the DeepSeek Harness sidebar: editable section title, an Add child workspace menu, and sessions you can drag between workspaces.",
|