@kabxx/dsh-session-move 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
@@ -1,14 +1,15 @@
1
1
  # @kabxx/dsh-session-move
2
2
 
3
- 面向 DeepSeek Harness(`0.2.2-rc.5`)的会话跨工作区拖拽移动插件,支持 Linux(含 WSL)、macOS 与原生 Windows 的默认 Zstandard JSONL 存储。
3
+ 面向 DeepSeek Harness(`0.2.2-rc.5`)的会话跨工作区拖拽移动插件,支持 Linux(含 WSL)、macOS 和原生 Windows 的默认 Zstandard JSONL 存储。
4
4
 
5
- - 在侧栏将普通会话直接拖到目标工作区的文件夹标题行(折叠或空工作区同样支持),原工作区内的上下排序不受影响。
6
- - 连同关联的子智能体会话、日志目录与工作目录整组迁移:仅重写首帧会话头 `cwd` 并追加工作目录变更事件,同步更新工作区账本、侧栏列表与全文搜索索引;若日志已位于目标目录则仅补全工作区登记。
5
+ - 在侧栏将普通会话直接拖到目标工作区的文件夹标题行(折叠或空工作区同样支持),原工作区内的上下排序及单列表视图的原生拖拽排序不受影响;移动过程提供即时进度提示,迁移或回滚后自动恢复当前已打开的会话视图与草稿附件。
6
+ - 连同关联的子智能体会话、日志目录与工作目录整组迁移:仅重写首帧会话头 `cwd` 并追加工作目录变更事件,同步更新工作区账本和侧栏列表,搜索索引由 DSH 在搜索时更新;若日志已位于目标目录则仅补全工作区登记。
7
7
  - 移动前自动释放空闲的 Web 会话句柄并通过原生会话锁(Linux / macOS `flock`、Windows 命名信号量)校验独占状态;运行中、存在未消费消息、归档或单独拖动的子智能体会话会被提前拦截,中途异常中断时由 `/recovery` 子插件在启动或下次操作时自动回滚或补完清理。
8
+ - 历史校验与文件暂存全程采用流式有界处理:在独立内存受限进程(Linux 结合操作系统级内存限额,macOS / Windows 采用独立进程与 V8 堆上限)中按 128 KiB 分块流式校验,单次最多迁移含子智能体会话在内的 128 个会话、准备限时 180 秒,并在暂存前核对整批日志与附件的可用磁盘空间。
8
9
 
9
10
  ## 安装
10
11
 
11
- 需要 Node.js `>= 24.9.0`(Linux 环境需包含 `/usr/bin/flock`):
12
+ 需要 Node.js `>= 24.9.0`(Linux 环境需包含 `/usr/bin/flock` 和 `prlimit`,支持时优先用 systemd 用户 scope 限制内存):
12
13
 
13
14
  ```bash
14
15
  dsh plugin --profile web add @kabxx/dsh-session-move
@@ -38,14 +39,17 @@ npm pack --dry-run
38
39
  | [`src/plan.js`](src/plan.js) | 移动前置校验、父子智能体会话组展开与目标路径检查 |
39
40
  | [`src/transaction.js`](src/transaction.js) | 事务意图日志、整组备份暂存、原子目录切换与回滚 |
40
41
  | [`src/zstd-frame.js`](src/zstd-frame.js) | Zstandard 会话容器帧扫描与首帧 `cwd` 原地重写 |
41
- | [`src/ledger.js`](src/ledger.js) | 工作区 KV 账本原子切换、回滚与搜索索引刷新 |
42
+ | [`src/ledger.js`](src/ledger.js) | 工作区 KV 账本原子切换与回滚 |
42
43
  | [`src/sidebar.js`](src/sidebar.js) | 迁移后刷新投影缓存与侧栏会话摘要事件 |
43
44
  | [`src/lease.js`](src/lease.js) | 识别并安全释放空闲的 Web 会话写入句柄 |
44
- | [`src/inbox.js`](src/inbox.js) | 重放校验会话持久收件箱是否存在未消费消息 |
45
+ | [`src/history.js`](src/history.js) | 调用独立进程执行会话历史校验,验证返回协议并转换超时与资源限额异常 |
46
+ | [`src/history-stream.js`](src/history-stream.js) | 流式分块解码和校验 Zstandard 会话历史 |
47
+ | [`src/history-worker.js`](src/history-worker.js) | 独立校验进程入口,逐条折叠未消费消息状态、侧栏摘要与恢复校验 |
48
+ | [`src/history-process.js`](src/history-process.js) | 启动并管理带内存限制的历史校验进程,处理超时、取消与数据传输 |
45
49
  | [`src/platform-fs.js`](src/platform-fs.js) | 跨平台会话锁(`flock` / Windows 信号量)、符号链接检查与原子替换 |
46
50
  | [`src/paths.js`](src/paths.js) | 与原生 JSONL 存储一致的工作区目录编码计算 |
47
51
  | [`src/config.js`](src/config.js) | 插件事务与历史版本恢复目录路径配置 |
48
- | [`src/client.js`](src/client.js) | Web 侧栏文件夹行拖拽捕获、高亮反馈与 Toast 提示 |
52
+ | [`src/client.js`](src/client.js) | Web 侧栏拖拽捕获、高亮与进度反馈、Toast 提示及已打开会话/草稿恢复 |
49
53
  | [`locale/`](locale/) | 主插件与 `/recovery` 子插件管理页中英文标题与描述 |
50
54
  | [`test/`](test/) | 拖拽交互、Zstd 帧重写、账本切换与多阶段崩溃恢复测试 |
51
55
 
package/icon.svg CHANGED
@@ -1,9 +1,25 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Move session to another workspace">
2
- <rect width="64" height="64" rx="14" fill="#101820"/>
3
- <path d="M12 22a4 4 0 0 1 4-4h9.2l3.4 4.2H48a4 4 0 0 1 4 4v17.6a4 4 0 0 1-4 4H16a4 4 0 0 1-4-4Z"
4
- fill="none" stroke="#4cc2ff" stroke-width="3" stroke-linejoin="round"/>
5
- <path d="M12 30.4h40" stroke="#4cc2ff" stroke-width="3" stroke-linecap="round" opacity="0.55"/>
6
- <path d="M25 39.5h13" stroke="#7ee787" stroke-width="3" stroke-linecap="round"/>
7
- <path d="M33.5 34.8 38.6 39.5l-5.1 4.7" fill="none" stroke="#7ee787" stroke-width="3"
8
- stroke-linecap="round" stroke-linejoin="round"/>
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36">
2
+ <!--
3
+ Lucide folder-input (v1.77.0): https://lucide.dev/icons/folder-input
4
+ ISC License
5
+
6
+ Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted, provided that the above
10
+ copyright notice and this permission notice appear in all copies.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
+ -->
20
+ <g transform="translate(6 6)" fill="none" stroke="#808080" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
21
+ <path d="M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1"/>
22
+ <path d="M2 13h10"/>
23
+ <path d="m9 16 3-3-3-3"/>
24
+ </g>
9
25
  </svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kabxx/dsh-session-move",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Move sessions across workspaces by dragging them in the DeepSeek Harness sidebar.",
5
5
  "type": "module",
6
6
  "publishConfig": {
package/src/client.js CHANGED
@@ -1,11 +1,12 @@
1
1
  window.__ModuleLoader__.load({
2
2
  id: '@kabxx/dsh-session-move',
3
3
  factory(require) {
4
- const { useSyncExternalStore } = require('react')
4
+ const { createElement, Fragment, useSyncExternalStore } = require('react')
5
5
  const { createSnapshotStore } = require('@deepseek-ai/dsh-client-store')
6
6
  const namespace = 'sessionMove'
7
7
  const strings = {
8
8
  zh: {
9
+ moving: '正在移动会话…',
9
10
  moved: '会话已移动到“{title}”',
10
11
  pending: '会话已移动,后续清理待完成。',
11
12
  'sidebar-pending': '会话已移动,侧栏暂未同步,请刷新页面。',
@@ -25,11 +26,20 @@ window.__ModuleLoader__.load({
25
26
  collision: '目标工作区中已存在同名会话记录。',
26
27
  changed: '会话状态已变更,请重试。',
27
28
  unsupported: '当前存储方式不支持移动会话。',
29
+ 'disk-space': '磁盘空间不足,无法暂存本次移动的日志、附件和备份。',
30
+ 'family-limit': '一次最多移动 128 个会话(含子智能体会话)。',
31
+ 'history-timeout': '移动准备超时(超过 180 秒),会话保留在原工作区。',
32
+ 'history-cancelled': '已取消移动准备。',
33
+ 'history-resource': '会话历史检查超出资源上限,无法安全移动。',
34
+ 'history-invalid': '会话或子智能体会话的历史记录未通过校验,无法移动。',
35
+ 'history-isolation-unavailable': '当前环境无法启动带内存限制的会话检查进程。',
36
+ 'history-busy': '已有其他会话移动正在检查中,请稍后重试。',
28
37
  'restore-pending': '移动中断,会话待自动恢复,请稍后重试。',
29
38
  'cleanup-pending': '上一次移动仍在清理中,请稍后重试。',
30
39
  failed: '移动失败,请重试。',
31
40
  },
32
41
  en: {
42
+ moving: 'Moving session…',
33
43
  moved: 'Session moved to “{title}”',
34
44
  pending: 'Session moved; follow-up cleanup is still pending.',
35
45
  'sidebar-pending': 'Session moved, but the sidebar did not update. Refresh the page.',
@@ -49,6 +59,14 @@ window.__ModuleLoader__.load({
49
59
  collision: 'The target workspace already holds a record for this session.',
50
60
  changed: 'Session state changed. Try again.',
51
61
  unsupported: 'Moving sessions is not supported for this storage.',
62
+ 'disk-space': 'There is not enough disk space to stage the logs, attachments, and backups.',
63
+ 'family-limit': 'You can move up to 128 sessions at once, including subagent sessions.',
64
+ 'history-timeout': 'Move preparation timed out after 180 seconds. The session remains in its original workspace.',
65
+ 'history-cancelled': 'Move preparation was cancelled.',
66
+ 'history-resource': 'The session history check exceeded its resource limit.',
67
+ 'history-invalid': 'The session or a subagent session failed history validation and cannot be moved.',
68
+ 'history-isolation-unavailable': 'This environment could not start a memory-limited session history worker.',
69
+ 'history-busy': 'Another session move is being checked. Try again shortly.',
52
70
  'restore-pending': 'The move was interrupted. Automatic restoration is pending; try again shortly.',
53
71
  'cleanup-pending': 'A previous move is still finishing cleanup. Try again shortly.',
54
72
  failed: 'Failed to move the session. Try again.',
@@ -57,11 +75,237 @@ window.__ModuleLoader__.load({
57
75
  const known = new Set([
58
76
  'busy', 'locked', 'missing', 'target-missing', 'target-not-canonical', 'same-workspace', 'stale-source',
59
77
  'collision', 'changed', 'unsupported', 'restore-pending', 'cleanup-pending',
60
- 'archived', 'subagent', 'unsafe-path', 'cross-device', 'restored', 'forbidden',
78
+ 'archived', 'subagent', 'unsafe-path', 'cross-device', 'restored', 'forbidden', 'disk-space', 'family-limit',
79
+ 'history-timeout', 'history-cancelled', 'history-resource', 'history-invalid',
80
+ 'history-isolation-unavailable', 'history-busy',
61
81
  ])
62
82
  const ROW_KEY = 'data-row-key'
63
83
  const WORKSPACE_PREFIX = 'workspace:'
64
84
  const SESSION_PREFIX = 'session:'
85
+ const LIST_AREA = '[data-sidebar-list-area]'
86
+ const TREE_ROLE = '[role="tree"]'
87
+ const WORKSPACE_ROW = `[${ROW_KEY}^="${WORKSPACE_PREFIX}"]`
88
+ const original = Symbol.for('cordis.original')
89
+
90
+ function replaceMethod(object, key, next) {
91
+ const previous = Object.getOwnPropertyDescriptor(object, key)
92
+ Object.defineProperty(object, key, { configurable: true, writable: true, value: next })
93
+ return () => {
94
+ if (object[key] !== next) return
95
+ if (previous) Object.defineProperty(object, key, previous)
96
+ else delete object[key]
97
+ }
98
+ }
99
+
100
+ function sessionRuntime(ctx) {
101
+ const service = ctx.get('sessions')
102
+ return service?.[original] ?? service
103
+ }
104
+
105
+ function sessionView(sessions, sessionId) {
106
+ const binding = sessions?.binding?.(sessionId)
107
+ const session = binding?.session
108
+ if (typeof session?.resync !== 'function' || typeof session.getSnapshot !== 'function'
109
+ || typeof session.projections?.clear !== 'function') return undefined
110
+ return binding
111
+ }
112
+
113
+ function rebindComposerAttachments(binding) {
114
+ const conversation = binding.ctx?.get?.('conversation')
115
+ if (typeof conversation?.rebindDraftFiles !== 'function') return
116
+ const input = conversation.input?.for?.(binding.ctx)
117
+ const attachmentIds = input?.state?.getSnapshot?.()?.attachmentIds
118
+ if (Array.isArray(attachmentIds) && attachmentIds.length > 0) {
119
+ // Reuse the browser File objects and draft IDs so upload receipts scoped
120
+ // to the disposed Agent are replaced for the reopened Session.
121
+ conversation.rebindDraftFiles(binding.sessionId, attachmentIds, binding.session.getSnapshot().subagent === null)
122
+ }
123
+ }
124
+
125
+ function clearSessionProjections(manager, sessionId, projections) {
126
+ manager.projectionInflight?.get(sessionId)?.controller?.abort?.()
127
+ manager.projectionInflight?.delete(sessionId)
128
+ manager.projectionLoads?.delete(sessionId)
129
+ projections?.clear?.()
130
+ }
131
+
132
+ function watchSessionViews(sessions) {
133
+ const manager = sessions?.manager
134
+ const remove = manager?.handleSessionRemoved
135
+ const add = manager?.handleSessionAdded
136
+ if (typeof remove !== 'function' || typeof add !== 'function') return undefined
137
+ const transitions = new WeakMap()
138
+ let disposed = false
139
+
140
+ const transitionFor = (binding) => {
141
+ let transition = transitions.get(binding)
142
+ if (!transition) {
143
+ transition = { removal: 0, scheduled: -1, work: Promise.resolve() }
144
+ transitions.set(binding, transition)
145
+ }
146
+ return transition
147
+ }
148
+
149
+ const undoRemove = replaceMethod(manager, 'handleSessionRemoved', function (id) {
150
+ const binding = sessionView(sessions, id)
151
+ const transition = binding && transitions.get(binding)
152
+ if (transition) transition.removal++
153
+ return remove.call(this, id)
154
+ })
155
+
156
+ let undoAdd
157
+ try {
158
+ undoAdd = replaceMethod(manager, 'handleSessionAdded', function (summary) {
159
+ const id = summary.sessionId
160
+ const binding = sessionView(sessions, id)
161
+ const session = binding?.session
162
+ const snapshotBefore = session?.getSnapshot()
163
+ const wasRemoved = Boolean(snapshotBefore?.removed)
164
+ const previousCwd = Array.isArray(manager.summaries)
165
+ ? manager.summaries.find((item) => item.sessionId === id)?.cwd
166
+ : undefined
167
+ const activeTransition = binding && transitions.get(binding)
168
+ const resyncInFlight = activeTransition !== undefined && activeTransition.scheduled === activeTransition.removal
169
+ if (!disposed && wasRemoved) {
170
+ // Native removal deletes the Manager's projection map entry while the
171
+ // retained Session keeps its store. Rejoin and drop stale sequenced
172
+ // entries before the replacement summary lands.
173
+ if (manager.projectionStores?.get(id) !== session.projections) {
174
+ manager.projectionStores?.set(id, session.projections)
175
+ }
176
+ if (!resyncInFlight) clearSessionProjections(manager, id, session.projections)
177
+ }
178
+ const result = add.call(this, summary)
179
+ if (disposed || !binding) return result
180
+
181
+ if (wasRemoved && session.removed === true && typeof session.notifier?.markDirty === 'function') {
182
+ if (session.getSnapshot().openState === 'cold' && !resyncInFlight) {
183
+ session.removed = false
184
+ session.notifier.markDirty()
185
+ return result
186
+ }
187
+ const transition = transitionFor(binding)
188
+ const removal = transition.removal
189
+ if (transition.scheduled === removal) return result
190
+ transition.scheduled = removal
191
+ const current = () => !disposed && sessions.binding(id) === binding && transition.removal === removal
192
+ transition.work = transition.work.then(async () => {
193
+ if (!current()) return
194
+ rebindComposerAttachments(binding)
195
+ manager.projectionInflight?.get(id)?.controller?.abort?.()
196
+ manager.projectionInflight?.delete(id)
197
+ manager.projectionLoads?.delete(id)
198
+ await binding.session.resync()
199
+ if (!current() || session.getSnapshot().openState !== 'open') return
200
+ // rc.5's native removal flag is one-way on a retained Session.
201
+ session.removed = false
202
+ session.notifier.markDirty()
203
+ }).catch(() => {
204
+ // Keep the session unavailable on sync failure so a later addition can retry.
205
+ }).finally(() => {
206
+ if (transition.scheduled === removal) transition.scheduled = -1
207
+ })
208
+ return result
209
+ }
210
+
211
+ if (!wasRemoved && snapshotBefore?.openState === 'open' && previousCwd && summary.cwd && previousCwd !== summary.cwd) {
212
+ const transition = transitionFor(binding)
213
+ const removal = transition.removal
214
+ const current = () => !disposed && sessions.binding(id) === binding && transition.removal === removal
215
+ transition.work = transition.work.then(async () => {
216
+ if (!current() || session.getSnapshot().removed || session.getSnapshot().openState !== 'open') return
217
+ clearSessionProjections(manager, id, session.projections)
218
+ await binding.session.resync()
219
+ }).catch(() => {})
220
+ }
221
+ return result
222
+ })
223
+ } catch (error) {
224
+ undoRemove()
225
+ throw error
226
+ }
227
+
228
+ return {
229
+ dispose() {
230
+ disposed = true
231
+ undoAdd()
232
+ undoRemove()
233
+ },
234
+ }
235
+ }
236
+ const progressStyles = `
237
+ .kabxx-session-move-progress {
238
+ position: fixed;
239
+ top: 40px;
240
+ left: 50%;
241
+ transform: translateX(-50%);
242
+ z-index: 1100;
243
+ display: flex;
244
+ align-items: center;
245
+ gap: 10px;
246
+ box-sizing: border-box;
247
+ width: max-content;
248
+ max-width: min(640px, calc(100vw - 48px));
249
+ padding: 12px 16px;
250
+ border-radius: var(--dsw-radius-lg);
251
+ background: var(--dsw-alias-toast-bg);
252
+ color: var(--dsw-alias-toast-label);
253
+ box-shadow: var(--dsw-shadow-lv3);
254
+ font-size: 14px;
255
+ line-height: 22px;
256
+ }
257
+ /* DSH StateDot (ongoing), scoped to this slot. */
258
+ .kabxx-session-move-spinner {
259
+ flex: none;
260
+ color: var(--dsw-alias-toast-action);
261
+ }
262
+ .kabxx-session-move-spinner-motion {
263
+ transform-origin: center;
264
+ animation: kabxx-session-move-spin 1.5s linear infinite;
265
+ }
266
+ .kabxx-session-move-spinner-track,
267
+ .kabxx-session-move-spinner-arc {
268
+ fill: none;
269
+ stroke: currentColor;
270
+ stroke-width: 2;
271
+ stroke-linecap: round;
272
+ }
273
+ .kabxx-session-move-spinner-track { opacity: 0.25; }
274
+ .kabxx-session-move-spinner-arc {
275
+ stroke-dasharray: 12 150;
276
+ animation: kabxx-session-move-dash 1.5s ease-in-out infinite;
277
+ }
278
+ @keyframes kabxx-session-move-spin { to { transform: rotate(360deg); } }
279
+ @keyframes kabxx-session-move-dash {
280
+ 0%, 100% { stroke-dasharray: 12 150; stroke-dashoffset: 0; }
281
+ 50% { stroke-dasharray: 24 150; stroke-dashoffset: -6; }
282
+ }
283
+ @media (prefers-reduced-motion: reduce) {
284
+ .kabxx-session-move-spinner-motion,
285
+ .kabxx-session-move-spinner-arc { animation: none; }
286
+ .kabxx-session-move-spinner-arc { stroke-dasharray: 18 150; stroke-dashoffset: -3; }
287
+ }
288
+ `
289
+
290
+ function syncSpinner(node) {
291
+ for (const animation of node?.getAnimations?.({ subtree: true }) ?? []) animation.startTime = 0
292
+ }
293
+
294
+ function MoveSpinner() {
295
+ return createElement('svg', {
296
+ ref: syncSpinner,
297
+ onAnimationStart: (event) => syncSpinner(event.currentTarget),
298
+ className: 'kabxx-session-move-spinner',
299
+ 'data-state': 'ongoing',
300
+ width: 18,
301
+ height: 18,
302
+ viewBox: '0 0 24 24',
303
+ 'aria-hidden': true,
304
+ }, createElement('g', { className: 'kabxx-session-move-spinner-motion' },
305
+ createElement('circle', { className: 'kabxx-session-move-spinner-track', cx: 12, cy: 12, r: 9.5 }),
306
+ createElement('circle', { className: 'kabxx-session-move-spinner-arc', cx: 12, cy: 12, r: 9.5 }),
307
+ ))
308
+ }
65
309
 
66
310
  return {
67
311
  inject: ['locale', 'slots', 'workspaces'],
@@ -69,13 +313,33 @@ window.__ModuleLoader__.load({
69
313
  const t = ctx.locale.bind(namespace)
70
314
  const toast = createSnapshotStore(null)
71
315
  const lifetime = new AbortController()
316
+ const inFlight = new Set()
317
+ const notices = []
72
318
  let sequence = 0
73
319
  let dragging = null
74
320
  let highlighted = null
75
321
  let savedStyle = null
76
322
 
323
+ function setToast(value) {
324
+ try {
325
+ toast.set(value)
326
+ } catch (error) {
327
+ console.warn('[dsh-session-move] Failed to update move feedback', error)
328
+ }
329
+ }
330
+
331
+ function showNextToast(advance = false) {
332
+ const current = toast.getSnapshot()
333
+ if (!advance && current !== null && current.key !== 'moving') return
334
+ if (notices.length) setToast({ ...notices.shift(), seq: ++sequence })
335
+ else if (inFlight.size > 0 && (advance || current === null)) {
336
+ setToast({ key: 'moving' })
337
+ } else if (advance) setToast(null)
338
+ }
339
+
77
340
  function notify(key, tone = 'warning', values) {
78
- toast.set({ key, tone, values, seq: ++sequence })
341
+ notices.push({ key, tone, values })
342
+ showNextToast()
79
343
  }
80
344
 
81
345
  function clearHighlight() {
@@ -112,7 +376,7 @@ window.__ModuleLoader__.load({
112
376
  if (!key?.startsWith(WORKSPACE_PREFIX)) return null
113
377
  const id = key.slice(WORKSPACE_PREFIX.length)
114
378
  // The ungrouped bucket is represented by `workspace:` with no id.
115
- if (!id || id === active.sourceWorkspaceId) return null
379
+ if (!id || id === active.sourceWorkspaceId || inFlight.has(active.id)) return null
116
380
  const snapshot = ctx.workspaces.list.getSnapshot()
117
381
  if (snapshot.archivedSessionIds.includes(active.id)) return null
118
382
  const workspace = snapshot.items.find((item) => item.workspaceId === id)
@@ -120,6 +384,10 @@ window.__ModuleLoader__.load({
120
384
  }
121
385
 
122
386
  async function perform(sessionId, targetWorkspaceId, sourceWorkspaceId, title) {
387
+ if (lifetime.signal.aborted || inFlight.has(sessionId)) return
388
+ inFlight.add(sessionId)
389
+ showNextToast()
390
+ let outcome
123
391
  try {
124
392
  const response = await fetch('/api/session-move/session', {
125
393
  method: 'POST',
@@ -129,20 +397,31 @@ window.__ModuleLoader__.load({
129
397
  body: JSON.stringify({ sessionId, targetWorkspaceId, sourceWorkspaceId }),
130
398
  })
131
399
  const result = await response.json().catch(() => null)
132
- if (lifetime.signal.aborted) return
133
400
  if (!response.ok || result?.error || result?.moved !== true) {
134
401
  const code = result?.error
135
402
  if (known.has(code)) throw new Error(code)
136
403
  if (response.status === 401 || response.status === 403) throw new Error('forbidden')
137
404
  throw new Error('failed')
138
405
  }
139
- if (result.sidebarPending) notify('sidebar-pending')
140
- else if (result.cleanupPending) notify('pending')
141
- else notify('moved', 'success', { title: title ?? '' })
406
+ outcome = result.sidebarPending ? 'sidebar-pending' : result.cleanupPending ? 'pending' : 'moved'
142
407
  } catch (error) {
143
- if (lifetime.signal.aborted) return
144
- notify(known.has(error.message) ? error.message : 'failed')
408
+ outcome = known.has(error?.message) ? error.message : 'failed'
409
+ } finally {
410
+ inFlight.delete(sessionId)
145
411
  }
412
+ if (lifetime.signal.aborted) return
413
+ if (outcome === 'moved') notify(outcome, 'success', { title: title ?? '' })
414
+ else notify(outcome)
415
+ }
416
+
417
+ function dragContainer(row) {
418
+ return row.closest?.(LIST_AREA) ?? row.closest?.(TREE_ROLE) ?? null
419
+ }
420
+
421
+ function inFlatList(row) {
422
+ const container = dragContainer(row)
423
+ return container !== null && typeof container.querySelector === 'function'
424
+ && container.querySelector(WORKSPACE_ROW) === null
146
425
  }
147
426
 
148
427
  function onDragStart(event) {
@@ -150,6 +429,9 @@ window.__ModuleLoader__.load({
150
429
  const row = closestRow(event.target)
151
430
  const key = row?.getAttribute(ROW_KEY)
152
431
  if (!key?.startsWith(SESSION_PREFIX) || row.draggable !== true) return
432
+ // DSH's flat "In one list" view renders no workspace folder rows and
433
+ // natively reorders sessions across workspaces.
434
+ if (inFlatList(row)) return
153
435
  const id = key.slice(SESSION_PREFIX.length)
154
436
  const snapshot = ctx.workspaces.list.getSnapshot()
155
437
  if (!id || snapshot.archivedSessionIds.includes(id)) return
@@ -231,18 +513,31 @@ window.__ModuleLoader__.load({
231
513
 
232
514
  function MoveToast({ t, renderFactorySlot }) {
233
515
  const current = useSyncExternalStore(toast.subscribe, toast.getSnapshot)
234
- if (!current) return null
235
- return renderFactorySlot('workspace.toast.content', {
516
+ const moving = current?.key === 'moving'
517
+ const progress = createElement('div', { role: 'status', style: { pointerEvents: 'none' } },
518
+ moving ? createElement('div', { className: 'kabxx-session-move-progress' },
519
+ createElement('style', null, progressStyles),
520
+ createElement(MoveSpinner),
521
+ t(current.key, current.values),
522
+ ) : null,
523
+ )
524
+ const outcome = current && !moving ? renderFactorySlot('workspace.toast.content', {
236
525
  seq: current.seq,
237
526
  text: t(current.key, current.values),
238
527
  tone: current.tone,
239
528
  onDone: () => {
240
- if (toast.getSnapshot() === current) toast.set(null)
529
+ if (toast.getSnapshot() === current) showNextToast(true)
241
530
  },
242
- })
531
+ }) : null
532
+ return createElement(Fragment, null, progress, outcome)
243
533
  }
244
534
 
245
- ctx.effect(() => () => lifetime.abort())
535
+ ctx.effect(() => () => {
536
+ lifetime.abort()
537
+ inFlight.clear()
538
+ notices.length = 0
539
+ setToast(null)
540
+ })
246
541
  ctx.effect(() => ctx.locale.register(namespace, strings))
247
542
 
248
543
  ctx.effect(() => {
@@ -266,6 +561,13 @@ window.__ModuleLoader__.load({
266
561
  }
267
562
  })
268
563
 
564
+ if (typeof ctx.inject === 'function') {
565
+ ctx.inject(['sessions'], (scoped) => scoped.effect(() => {
566
+ const views = watchSessionViews(sessionRuntime(scoped))
567
+ return () => { views?.dispose() }
568
+ }))
569
+ }
570
+
269
571
  ctx.effect(() => ctx.slots.inject('shell.overlay', () => ctx.slots.register({
270
572
  name: 'shell.overlay', id: 'session-move.toast', locale: namespace,
271
573
  }, MoveToast)))