@codeasier/dsh-plugin-orca-projects 0.0.0-stage → 0.1.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/client.js ADDED
@@ -0,0 +1,4772 @@
1
+ window.__ModuleLoader__.load({
2
+ id: '@codeasier/dsh-plugin-orca-projects',
3
+ factory(require) {
4
+ const React = require('react')
5
+ const h = React.createElement
6
+
7
+ const NS = 'orcaSidebar'
8
+ const STORAGE_KEY = 'dsh.orca-projects.v1'
9
+ const UNGROUPED = '__ungrouped__'
10
+ const MODES = ['orca', 'workspace', 'workspace-tree', 'flat']
11
+ const FILTERS = ['hide', 'all', 'only']
12
+ const EMPTY_STATUS = new Map()
13
+ const SessionStatusContext = React.createContext(null)
14
+ const WorkspacePathContext = React.createContext(null)
15
+
16
+ const en = {
17
+ 'title.projects': 'Projects',
18
+ 'title.workspaces': 'Workspaces',
19
+ 'title.sessions': 'Sessions',
20
+ 'action.search': 'Search',
21
+ 'action.viewOptions': 'View options',
22
+ 'action.add': 'Add',
23
+ 'action.addProject': 'Add project…',
24
+ 'action.addWorkspace': 'Add workspace…',
25
+ 'action.newGroup': 'New group…',
26
+ 'action.clear': 'Clear',
27
+ 'action.refresh': 'Refresh',
28
+ 'placeholder.search': 'Search projects or sessions',
29
+ 'section.groupBy': 'Group by',
30
+ 'group.workspace': 'Workspace',
31
+ 'group.workspaceTree': 'Workspace tree',
32
+ 'group.flat': 'Single list',
33
+ 'group.orca': 'Orca-like',
34
+ 'order.label': 'Sort by',
35
+ 'order.manual': 'Manual',
36
+ 'order.updated': 'Last updated',
37
+ 'filter.label': 'Filter sessions',
38
+ 'filter.hide': 'Hide archived',
39
+ 'filter.all': 'All conversations (show archived)',
40
+ 'filter.only': 'Archived only',
41
+ 'filter.activeOnly': 'Active sessions only',
42
+ 'active.empty': 'No active sessions',
43
+ 'active.hint': 'Turn off Active sessions only to see every session.',
44
+ 'active.showAll': 'Show all sessions',
45
+ 'pinned.title': 'Pinned',
46
+ 'pinned.empty': 'Pinned sessions collect here, above every project.',
47
+ 'pinned.hint': 'Pinned',
48
+ 'pinned.short': 'Pinned',
49
+ 'pinned.pin': 'Pin session',
50
+ 'pinned.unpin': 'Unpin session',
51
+ 'group.ungrouped': 'Ungrouped',
52
+ 'group.empty': 'Drop a project here, or use a project menu.',
53
+ 'group.drop': 'Move to group',
54
+ 'group.rename': 'Rename group',
55
+ 'group.delete': 'Delete group',
56
+ 'group.deleteConfirm': 'Delete “{name}”? Its projects return to Ungrouped.',
57
+ 'group.name': 'Group name',
58
+ 'group.namePlaceholder': 'e.g. Client work',
59
+ 'group.created': 'Group “{name}” created',
60
+ 'group.deleted': 'Group deleted',
61
+ 'group.moved': 'Moved “{name}” to {group}',
62
+ 'project.newSession': 'New session',
63
+ 'project.newSessionIn': 'New session in {name}',
64
+ 'project.open': 'Open workspace',
65
+ 'project.move': 'Move to group',
66
+ 'project.rename': 'Rename project',
67
+ 'project.delete': 'Delete project',
68
+ 'project.deleteConfirm':
69
+ 'Remove “{name}” from the workspace list? Files and sessions are kept.',
70
+ 'project.deleteConfirmMany':
71
+ 'Remove “{name}” and its {n} worktree workspaces from DSH? Files and sessions are kept.',
72
+ 'project.renamePlaceholder': 'Project name',
73
+ 'project.ungrouped': 'Ungrouped',
74
+ 'project.sessions': '{n} sessions',
75
+ 'loose.title': 'Unassigned sessions',
76
+ 'loose.hint': 'Sessions outside every registered workspace.',
77
+ 'migration.action': 'Migrate unassigned sessions…',
78
+ 'migration.short': 'Migrate',
79
+ 'migration.revert': 'Undo session migration',
80
+ 'migration.title': 'Migrate unassigned sessions',
81
+ 'migration.description':
82
+ 'Detected {n} sessions for {projects} projects; {unmatched} could not be matched. This writes only an external project mapping; DSH workspaces and session ownership stay unchanged.',
83
+ 'migration.confirm': 'Migrate {n}',
84
+ 'migration.done': 'Migrated {n} sessions into projects',
85
+ 'migration.changed': 'The session matches changed. Review a fresh migration preview.',
86
+ 'migration.reverted': 'Session migration cleared',
87
+ 'migration.none': 'No unassigned session could be matched to a project.',
88
+ 'project.worktrees': '{n} worktrees',
89
+ 'project.worktreesTitle': 'Worktrees: {list}',
90
+ 'project.worktreesSection': 'Worktrees',
91
+ 'project.worktreeMain': 'main',
92
+ 'project.added': 'Workspace “{name}” added',
93
+ 'project.autoExpand': 'Show sessions',
94
+ 'session.open': 'Open',
95
+ 'session.reveal': 'Show in project',
96
+ 'session.pin': 'Pin session',
97
+ 'session.unpin': 'Unpin session',
98
+ 'session.archive': 'Archive session',
99
+ 'session.unarchive': 'Restore session',
100
+ 'session.copyId': 'Copy session ID',
101
+ 'session.copied': 'Session ID copied',
102
+ 'session.copyFailed': 'Copy failed',
103
+ 'session.archivedHint': 'Archived',
104
+ 'session.archivedNotOpenable': 'Restore this session before opening it.',
105
+ 'session.new': 'New session',
106
+ 'session.untitled': 'Untitled',
107
+ 'session.stopArchive': 'Stop and archive',
108
+ 'session.stopArchiveTitle': 'Stop this session and archive it?',
109
+ 'session.stopArchiveDesc':
110
+ '“{name}” still has work running. Archiving stops that work first.',
111
+ 'session.pinned': 'Pinned “{name}”',
112
+ 'session.unpinned': 'Unpinned “{name}”',
113
+ 'session.archived': 'Archived “{name}”',
114
+ 'session.unarchived': 'Restored “{name}”',
115
+ 'session.actionFailed': 'Could not update the session.',
116
+ 'dialog.cancel': 'Cancel',
117
+ 'dialog.create': 'Create',
118
+ 'dialog.save': 'Save',
119
+ 'dialog.delete': 'Delete',
120
+ 'dialog.close': 'Close',
121
+ 'toast.noPicker': 'No directory picker is available.',
122
+ 'toast.workspaceFailed': 'Could not add the workspace.',
123
+ 'toast.projectFailed': 'Could not update the workspace.',
124
+ 'toast.pinFailed': 'Could not update the pin.',
125
+ 'toast.archiveFailed': 'Could not archive the session.',
126
+ 'empty.projects': 'No projects yet',
127
+ 'empty.projectsHint': 'Add a folder to start a project.',
128
+ 'empty.sessions': 'No sessions',
129
+ 'sessions.expand': 'Show {n} more sessions',
130
+ 'sessions.collapsed': 'Show fewer',
131
+ 'empty.noMatches': 'No matching sessions',
132
+ 'empty.archivedOnly': 'No archived sessions',
133
+ 'empty.viewOthers': 'View other sessions',
134
+ loading: 'Loading workspaces…',
135
+ 'new': 'New',
136
+ }
137
+
138
+ const zh = {
139
+ 'title.projects': '项目',
140
+ 'title.workspaces': '工作区',
141
+ 'title.sessions': '会话',
142
+ 'action.search': '搜索',
143
+ 'action.viewOptions': '视图选项',
144
+ 'action.add': '添加',
145
+ 'action.addProject': '添加项目…',
146
+ 'action.addWorkspace': '添加工作区…',
147
+ 'action.newGroup': '新建分组…',
148
+ 'action.clear': '清除',
149
+ 'action.refresh': '刷新',
150
+ 'placeholder.search': '搜索项目或会话',
151
+ 'section.groupBy': '分组方式',
152
+ 'group.workspace': '按工作区',
153
+ 'group.workspaceTree': '按工作区树',
154
+ 'group.flat': '单列表',
155
+ 'group.orca': 'Orca-like',
156
+ 'order.label': '排序方式',
157
+ 'order.manual': '手动排序',
158
+ 'order.updated': '最近更新',
159
+ 'filter.label': '筛选会话',
160
+ 'filter.hide': '隐藏已归档',
161
+ 'filter.all': '全部对话(显示已归档)',
162
+ 'filter.only': '仅显示已归档',
163
+ 'filter.activeOnly': '仅活跃会话',
164
+ 'active.empty': '暂无活跃会话',
165
+ 'active.hint': '关闭“仅活跃会话”可查看全部会话。',
166
+ 'active.showAll': '查看全部会话',
167
+ 'pinned.title': '已置顶',
168
+ 'pinned.empty': '置顶的会话会集中显示在这里。',
169
+ 'pinned.hint': '已置顶',
170
+ 'pinned.short': '置顶',
171
+ 'pinned.pin': '置顶会话',
172
+ 'pinned.unpin': '取消置顶',
173
+ 'group.ungrouped': '未分组',
174
+ 'group.empty': '将项目拖到这里,或使用项目菜单。',
175
+ 'group.drop': '移动到分组',
176
+ 'group.rename': '重命名分组',
177
+ 'group.delete': '删除分组',
178
+ 'group.deleteConfirm': '删除“{name}”?其中的项目会回到未分组。',
179
+ 'group.name': '分组名称',
180
+ 'group.namePlaceholder': '例如:客户项目',
181
+ 'group.created': '已创建分组“{name}”',
182
+ 'group.deleted': '分组已删除',
183
+ 'group.moved': '已将“{name}”移动到{group}',
184
+ 'project.newSession': '新建会话',
185
+ 'project.newSessionIn': '在 {name} 中新建会话',
186
+ 'project.open': '打开工作区',
187
+ 'project.move': '移动到分组',
188
+ 'project.rename': '重命名项目',
189
+ 'project.delete': '删除项目',
190
+ 'project.deleteConfirm': '将“{name}”从工作区列表移除?文件夹与会话会保留。',
191
+ 'project.deleteConfirmMany':
192
+ '将“{name}”及其 {n} 个 worktree 工作区从 DSH 移除?文件夹与会话会保留。',
193
+ 'project.renamePlaceholder': '项目名称',
194
+ 'project.ungrouped': '未分组',
195
+ 'project.sessions': '{n} 个会话',
196
+ 'loose.title': '未归属会话',
197
+ 'loose.hint': '这些会话不属于任何已注册工作区。',
198
+ 'migration.action': '迁移未归属会话…',
199
+ 'migration.short': '迁移',
200
+ 'migration.revert': '撤销会话迁移',
201
+ 'migration.title': '迁移未归属会话',
202
+ 'migration.description':
203
+ '识别到 {n} 个会话可归入 {projects} 个项目,另有 {unmatched} 个无法匹配。此操作只写入外挂 projectId 映射,不会修改 DSH workspace 或会话归属。',
204
+ 'migration.confirm': '迁移 {n} 条',
205
+ 'migration.done': '已将 {n} 个会话归入项目',
206
+ 'migration.changed': '会话匹配已变化,请重新查看迁移预览。',
207
+ 'migration.reverted': '已清除会话迁移',
208
+ 'migration.none': '没有可匹配到项目的未归属会话。',
209
+ 'project.worktrees': '{n} 个工作树',
210
+ 'project.worktreesTitle': '工作树:{list}',
211
+ 'project.worktreesSection': '工作树',
212
+ 'project.worktreeMain': 'main',
213
+ 'project.added': '已添加工作区“{name}”',
214
+ 'project.autoExpand': '展开会话',
215
+ 'session.open': '打开',
216
+ 'session.reveal': '在项目中显示',
217
+ 'session.pin': '置顶会话',
218
+ 'session.unpin': '取消置顶',
219
+ 'session.archive': '归档会话',
220
+ 'session.unarchive': '取消归档',
221
+ 'session.copyId': '复制 Session ID',
222
+ 'session.copied': 'Session ID 已复制',
223
+ 'session.copyFailed': '复制失败',
224
+ 'session.archivedHint': '已归档',
225
+ 'session.archivedNotOpenable': '请先取消归档再打开。',
226
+ 'session.new': '新会话',
227
+ 'session.untitled': '未命名',
228
+ 'session.stopArchive': '停止并归档',
229
+ 'session.stopArchiveTitle': '停止并归档此会话?',
230
+ 'session.stopArchiveDesc': '“{name}”仍有正在进行的工作。归档会先停止这些工作。',
231
+ 'session.pinned': '已置顶“{name}”',
232
+ 'session.unpinned': '已取消置顶“{name}”',
233
+ 'session.archived': '已归档“{name}”',
234
+ 'session.unarchived': '已取消归档“{name}”',
235
+ 'session.actionFailed': '无法更新该会话。',
236
+ 'dialog.cancel': '取消',
237
+ 'dialog.create': '创建',
238
+ 'dialog.save': '保存',
239
+ 'dialog.delete': '删除',
240
+ 'dialog.close': '关闭',
241
+ 'toast.noPicker': '目录选择器不可用。',
242
+ 'toast.workspaceFailed': '无法添加工作区。',
243
+ 'toast.projectFailed': '无法更新工作区。',
244
+ 'toast.pinFailed': '无法更新置顶状态。',
245
+ 'toast.archiveFailed': '无法归档该会话。',
246
+ 'empty.projects': '暂无项目',
247
+ 'empty.projectsHint': '添加一个文件夹来开始项目。',
248
+ 'empty.sessions': '暂无会话',
249
+ 'sessions.expand': '显示其余 {n} 个会话',
250
+ 'sessions.collapsed': '收起',
251
+ 'empty.noMatches': '无匹配会话',
252
+ 'empty.archivedOnly': '暂无已归档会话',
253
+ 'empty.viewOthers': '查看其他会话',
254
+ loading: '正在加载工作区…',
255
+ 'new': '新',
256
+ }
257
+
258
+ function cx(...parts) {
259
+ let value = ''
260
+ for (const part of parts) {
261
+ if (part) value += (value ? ' ' : '') + part
262
+ }
263
+ return value
264
+ }
265
+
266
+ const ICONS = {
267
+ search: [
268
+ ['circle', { cx: 7, cy: 7, r: 4.4 }],
269
+ ['path', { d: 'M10.3 10.3 14 14' }],
270
+ ],
271
+ sliders: [
272
+ ['path', { d: 'M2.5 4.5h3.2M9.3 4.5h4.2M2.5 8h6.1M12.4 8h1.1M2.5 11.5h1.7M7.9 11.5h5.6' }],
273
+ ['circle', { cx: 7.3, cy: 4.5, r: 1.4 }],
274
+ ['circle', { cx: 10.3, cy: 8, r: 1.4 }],
275
+ ['circle', { cx: 6.2, cy: 11.5, r: 1.4 }],
276
+ ],
277
+ plus: [['path', { d: 'M8 3v10M3 8h10' }]],
278
+ minus: [['path', { d: 'M3 8h10' }]],
279
+ chevron: [['path', { d: 'm6 3.5 4.5 4.5L6 12.5' }]],
280
+ folder: [
281
+ [
282
+ 'path',
283
+ {
284
+ d: 'M2.2 4.6a1.1 1.1 0 0 1 1.1-1.1h3.1l1.3 1.5h5a1.1 1.1 0 0 1 1.1 1.1v5.8a1.1 1.1 0 0 1-1.1 1.1H3.3a1.1 1.1 0 0 1-1.1-1.1Z',
285
+ },
286
+ ],
287
+ ],
288
+ folderOpen: [
289
+ ['path', { d: 'M2.2 4.6a1.1 1.1 0 0 1 1.1-1.1h3.1l1.3 1.5h4.5' }],
290
+ ['path', { d: 'M2.2 6.2h11.3l-1.2 6.3H3.4Z' }],
291
+ ],
292
+ pin: [
293
+ ['path', { d: 'M9.9 2.2 13.8 6.1 12.2 7.7l-.1 2.2-2.5 2.5-4.9-4.9 2.5-2.5 2.2-.1Z' }],
294
+ ['path', { d: 'M6.3 9.7 2.4 13.6' }],
295
+ ],
296
+ pinFilled: [
297
+ [
298
+ 'path',
299
+ {
300
+ d: 'M9.9 2.2 13.8 6.1 12.2 7.7l-.1 2.2-2.5 2.5-4.9-4.9 2.5-2.5 2.2-.1Z',
301
+ fill: 'currentColor',
302
+ stroke: 'none',
303
+ },
304
+ ],
305
+ ['path', { d: 'M6.3 9.7 2.4 13.6' }],
306
+ ],
307
+ more: [
308
+ ['circle', { cx: 3.2, cy: 8, r: 1.05, fill: 'currentColor', stroke: 'none' }],
309
+ ['circle', { cx: 8, cy: 8, r: 1.05, fill: 'currentColor', stroke: 'none' }],
310
+ ['circle', { cx: 12.8, cy: 8, r: 1.05, fill: 'currentColor', stroke: 'none' }],
311
+ ],
312
+ close: [['path', { d: 'm4 4 8 8M12 4l-8 8' }]],
313
+ check: [['path', { d: 'm3 8.2 3.2 3.2L13 4.6' }]],
314
+ trash: [
315
+ [
316
+ 'path',
317
+ {
318
+ d: 'M3.2 4.5h9.6M6.2 4.5V3.2h3.6v1.3M4.4 4.5l.6 8.2a1 1 0 0 0 1 .9h4a1 1 0 0 0 1-.9l.6-8.2',
319
+ },
320
+ ],
321
+ ['path', { d: 'M6.6 7v4M9.4 7v4' }],
322
+ ],
323
+ edit: [
324
+ ['path', { d: 'm10.6 2.9 2.5 2.5-7.4 7.4-3.2.7.7-3.2Z' }],
325
+ ['path', { d: 'm9.4 4.1 2.5 2.5' }],
326
+ ],
327
+ layers: [
328
+ ['path', { d: 'm8 2.2 6 3.3-6 3.3-6-3.3Z' }],
329
+ ['path', { d: 'm2.6 8.2 5.4 3 5.4-3M2.6 11.2l5.4 3 5.4-3' }],
330
+ ],
331
+ groupAdd: [
332
+ ['path', { d: 'M2.2 4.6a1.1 1.1 0 0 1 1.1-1.1h3.1l1.3 1.5h5a1.1 1.1 0 0 1 1.1 1.1v3' }],
333
+ ['path', { d: 'M2.2 5.8v6.1h7.2M11 10.4v4.1M8.95 12.45h4.1' }],
334
+ ],
335
+ archive: [
336
+ ['path', { d: 'M2.4 5.6h11.2v7.9H2.4Z' }],
337
+ ['path', { d: 'M1.9 3.2h12.2v2.4H1.9ZM6.2 8.5h3.6' }],
338
+ ],
339
+ restore: [
340
+ ['path', { d: 'M3.4 6.2A5 5 0 1 1 3 9.6' }],
341
+ ['path', { d: 'M3.4 2.8v3.4h3.4' }],
342
+ ],
343
+ copy: [
344
+ ['rect', { x: 5.3, y: 5.3, width: 8.2, height: 8.2, rx: 1.2 }],
345
+ [
346
+ 'path',
347
+ {
348
+ d: 'M10.7 5.3V3.7a1.2 1.2 0 0 0-1.2-1.2H3.7a1.2 1.2 0 0 0-1.2 1.2v5.8a1.2 1.2 0 0 0 1.2 1.2h1.6',
349
+ },
350
+ ],
351
+ ],
352
+ open: [
353
+ ['path', { d: 'M9.2 2.8h4v4M13.2 2.8 7.6 8.4' }],
354
+ ['path', { d: 'M12.4 9.4v3.4H3.2V3.6h3.4' }],
355
+ ],
356
+ chat: [
357
+ [
358
+ 'path',
359
+ {
360
+ d: 'M2.4 3.5a1 1 0 0 1 1-1h9.2a1 1 0 0 1 1 1v6.2a1 1 0 0 1-1 1H7.1l-3.3 2.7v-2.7H3.4a1 1 0 0 1-1-1Z',
361
+ },
362
+ ],
363
+ ],
364
+ inbox: [
365
+ ['path', { d: 'M2.2 8.6 4.1 3.3h7.8l1.9 5.3v3.4a1 1 0 0 1-1 1H3.2a1 1 0 0 1-1-1Z' }],
366
+ ['path', { d: 'M2.2 8.6h3.3l.8 1.5h3.4l.8-1.5h3.3' }],
367
+ ],
368
+ warning: [
369
+ ['path', { d: 'M8 2.5 14 13H2Z' }],
370
+ ['path', { d: 'M8 6.2v3.1M8 11.2v.1' }],
371
+ ],
372
+ dot: [['circle', { cx: 8, cy: 8, r: 3.1, fill: 'currentColor', stroke: 'none' }]],
373
+ }
374
+
375
+ function Icon({ name, size = 14, className }) {
376
+ const parts = ICONS[name] || []
377
+ return h(
378
+ 'svg',
379
+ {
380
+ className,
381
+ width: size,
382
+ height: size,
383
+ viewBox: '0 0 16 16',
384
+ fill: 'none',
385
+ stroke: 'currentColor',
386
+ strokeWidth: 1.5,
387
+ strokeLinecap: 'round',
388
+ strokeLinejoin: 'round',
389
+ 'aria-hidden': 'true',
390
+ focusable: 'false',
391
+ },
392
+ parts.map(([tag, attributes], index) => h(tag, { key: index, ...attributes })),
393
+ )
394
+ }
395
+
396
+ function normalizePath(value) {
397
+ const text = String(value || '')
398
+ const normalized = text.replace(/\\/g, '/').replace(/\/+$/u, '')
399
+ return normalized === '' ? '/' : normalized
400
+ }
401
+
402
+ function baseName(value) {
403
+ const path = normalizePath(value)
404
+ const index = path.lastIndexOf('/')
405
+ return index >= 0 ? path.slice(index + 1) || path : path
406
+ }
407
+
408
+ function isAncestor(parent, child) {
409
+ const left = normalizePath(parent)
410
+ const right = normalizePath(child)
411
+ if (left === right) return false
412
+ if (left === '/') return right.startsWith('/')
413
+ return right.startsWith(`${left}/`)
414
+ }
415
+
416
+ function worktreeFromPath(value) {
417
+ const path = normalizePath(value)
418
+ const marker = path.match(/\/(?:\.worktrees?|worktrees?)\/([^/]+)/i)
419
+ if (marker?.[1]) return { label: marker[1], main: false }
420
+ const orca = path.match(/\/orca\/workspaces\/[^/]+\/([^/]+)(?:\/|$)/i)
421
+ if (orca?.[1]) return { label: orca[1], main: false }
422
+ return { label: 'main', main: true }
423
+ }
424
+
425
+ function repositoryWorktree(repo, path) {
426
+ if (!repo || repo.main === true) return 'main'
427
+ if (repo.worktree) return repo.worktree
428
+ const derived = worktreeFromPath(path)
429
+ if (!derived.main) return derived.label
430
+ return baseName(path) || 'main'
431
+ }
432
+
433
+ function sessionWorktree(session, project) {
434
+ if (!session || !project?.path) return null
435
+ const root = normalizePath(project.path)
436
+ const cwd = session.cwd ? normalizePath(session.cwd) : null
437
+ const worktrees = Array.isArray(project.worktrees) ? project.worktrees : []
438
+ const checkout =
439
+ worktrees
440
+ .filter(
441
+ (entry) => cwd && (normalizePath(entry.path) === cwd || isAncestor(entry.path, cwd)),
442
+ )
443
+ .sort(
444
+ (left, right) => normalizePath(right.path).length - normalizePath(left.path).length,
445
+ )[0] || worktrees.find((entry) => normalizePath(entry.path) === root)
446
+ if (checkout) return { label: checkout.label, main: checkout.main === true }
447
+ const rootWorktree = worktreeFromPath(root)
448
+ if (!cwd || cwd === root) return rootWorktree
449
+ if (isAncestor(root, cwd)) {
450
+ const relative = cwd.slice(root.length + 1)
451
+ const segments = relative.split('/').filter(Boolean)
452
+ const index = segments.findIndex((segment) =>
453
+ /^(?:\.worktrees?|worktrees?)$/i.test(segment),
454
+ )
455
+ if (index >= 0 && segments[index + 1]) return { label: segments[index + 1], main: false }
456
+ return rootWorktree
457
+ }
458
+ const cwdWorktree = worktreeFromPath(cwd)
459
+ if (!cwdWorktree.main) return cwdWorktree
460
+ return { label: baseName(cwd), main: false }
461
+ }
462
+
463
+ function repoFromPathFallback(value) {
464
+ const path = normalizePath(value)
465
+ const nested = path.match(/^(.*?)\/(?:\.worktrees?|worktrees)\/([^/]+)(?:\/|$)/i)
466
+ if (nested?.[1] && nested[2]) {
467
+ const root = normalizePath(nested[1])
468
+ return {
469
+ key: root,
470
+ root,
471
+ title: baseName(root),
472
+ main: false,
473
+ worktree: nested[2],
474
+ }
475
+ }
476
+ const orca = path.match(/^(.*\/orca\/workspaces\/([^/]+))\/[^/]+(?:\/|$)/i)
477
+ if (orca?.[1] && orca[2]) {
478
+ const root = normalizePath(orca[1])
479
+ return {
480
+ key: `orca:${root}`,
481
+ root,
482
+ title: orca[2],
483
+ main: false,
484
+ worktree: baseName(path),
485
+ }
486
+ }
487
+ return null
488
+ }
489
+
490
+ function workspaceRepo(workspace, repoMap) {
491
+ const path = normalizePath(workspace?.path)
492
+ const entry = repoMap && typeof repoMap.get === 'function' ? repoMap.get(path) : undefined
493
+ if (
494
+ entry &&
495
+ entry.status !== 'missing' &&
496
+ entry.status !== 'error' &&
497
+ typeof entry.key === 'string' &&
498
+ entry.key
499
+ ) {
500
+ const key = normalizePath(entry.key)
501
+ const root = normalizePath(entry.root || entry.key)
502
+ return {
503
+ key,
504
+ root,
505
+ title: entry.title || baseName(root) || path,
506
+ main: entry.main === true,
507
+ worktree: repositoryWorktree(entry, path),
508
+ worktrees: Array.isArray(entry.worktrees) ? entry.worktrees : [],
509
+ }
510
+ }
511
+ return (
512
+ repoFromPathFallback(path) || {
513
+ key: path,
514
+ root: path,
515
+ title: workspace?.title || baseName(path),
516
+ main: true,
517
+ worktree: worktreeFromPath(path).label,
518
+ }
519
+ )
520
+ }
521
+
522
+ function projectWorktrees(group) {
523
+ const found = new Map()
524
+ for (const member of group.members) {
525
+ for (const entry of member.repo.worktrees || []) {
526
+ if (!entry || typeof entry.path !== 'string') continue
527
+ const path = normalizePath(entry.path)
528
+ if (!path || found.has(path)) continue
529
+ found.set(path, {
530
+ workspaceId: null,
531
+ path,
532
+ label: entry.label || worktreeFromPath(path).label || baseName(path),
533
+ main: entry.main === true,
534
+ branch: entry.branch,
535
+ title: baseName(path),
536
+ sessionCount: 0,
537
+ registered: false,
538
+ })
539
+ }
540
+ const discovered = (member.repo.worktrees || []).find(
541
+ (entry) => normalizePath(entry.path) === member.path,
542
+ )
543
+ found.set(member.path, {
544
+ workspaceId: member.workspace.workspaceId,
545
+ path: member.path,
546
+ label: repositoryWorktree(member.repo, member.path),
547
+ main: member.repo.main === true || member.path === normalizePath(member.repo.root),
548
+ branch: discovered?.branch,
549
+ title: member.workspace.title || baseName(member.path),
550
+ sessionCount: member.sessions.length,
551
+ registered: true,
552
+ })
553
+ }
554
+ return [...found.values()].sort((left, right) => {
555
+ if (left.main !== right.main) return left.main ? -1 : 1
556
+ return String(left.label).localeCompare(String(right.label))
557
+ })
558
+ }
559
+
560
+ function projectForLooseSession(session, projects) {
561
+ if (!session?.cwd) return null
562
+ const cwd = normalizePath(session.cwd)
563
+ let best = null
564
+ let bestLength = -1
565
+ for (const project of projects) {
566
+ if (project.isUngrouped) continue
567
+ const paths = [
568
+ project.path,
569
+ ...(project.memberPaths || []),
570
+ ...(project.worktrees || []).map((worktree) => worktree.path),
571
+ ]
572
+ for (const value of paths) {
573
+ if (!value) continue
574
+ const path = normalizePath(value)
575
+ if (cwd !== path && !isAncestor(path, cwd)) continue
576
+ if (path.length <= bestLength) continue
577
+ best = project
578
+ bestLength = path.length
579
+ }
580
+ }
581
+ return best
582
+ }
583
+
584
+ function groupLooseSessions(sessions, workspaces) {
585
+ const groups = new Map()
586
+ for (const session of sessions) {
587
+ const cwd = session.cwd ? normalizePath(session.cwd) : null
588
+ let workspace = null
589
+ let bestLength = -1
590
+ for (const candidate of workspaces) {
591
+ const path = normalizePath(candidate.path)
592
+ if (!path) continue
593
+ if (cwd !== path && !isAncestor(path, cwd)) continue
594
+ if (path.length <= bestLength) continue
595
+ workspace = candidate
596
+ bestLength = path.length
597
+ }
598
+ const key = workspace ? normalizePath(workspace.path) : cwd || UNGROUPED
599
+ let group = groups.get(key)
600
+ if (!group) {
601
+ group = {
602
+ key,
603
+ title: workspace?.title || (cwd ? baseName(cwd) : UNGROUPED),
604
+ path: workspace?.path || cwd,
605
+ workspaceId: workspace?.workspaceId || null,
606
+ sessions: [],
607
+ }
608
+ groups.set(key, group)
609
+ }
610
+ group.sessions.push(session)
611
+ }
612
+ return [...groups.values()].sort((left, right) => {
613
+ const delta = right.sessions.length - left.sessions.length
614
+ if (delta !== 0) return delta
615
+ return String(left.title || '').localeCompare(String(right.title || ''))
616
+ })
617
+ }
618
+
619
+ function worktreeForSession(session, project, workspaceBySession) {
620
+ const workspacePath =
621
+ workspaceBySession && typeof workspaceBySession.get === 'function'
622
+ ? workspaceBySession.get(session.id)
623
+ : undefined
624
+ if (workspacePath) {
625
+ const checkout = project?.worktrees?.find(
626
+ (entry) => normalizePath(entry.path) === normalizePath(workspacePath),
627
+ )
628
+ if (checkout) return { label: checkout.label, main: checkout.main === true }
629
+ return sessionWorktree(session, { path: workspacePath, worktrees: project?.worktrees })
630
+ }
631
+ if (project?.path) return sessionWorktree(session, project)
632
+ return session?.cwd ? worktreeFromPath(session.cwd) : null
633
+ }
634
+
635
+ async function fetchRepositories(paths, signal) {
636
+ const response = await fetch('api/orca-projects/resolve', {
637
+ method: 'POST',
638
+ headers: { 'content-type': 'application/json' },
639
+ body: JSON.stringify({ paths }),
640
+ ...(signal === undefined ? {} : { signal }),
641
+ })
642
+ if (!response.ok) return null
643
+ const value = await response.json()
644
+ const repositories = value?.repositories
645
+ return Array.isArray(repositories) ? repositories : null
646
+ }
647
+
648
+ function defaultState() {
649
+ return {
650
+ version: 1,
651
+ mode: 'orca',
652
+ orderBy: 'updated',
653
+ archivedFilter: 'hide',
654
+ activeOnly: false,
655
+ groups: [],
656
+ assignments: {},
657
+ projectNames: {},
658
+ sessionProjects: {},
659
+ projectOrder: {},
660
+ sessionOrder: {},
661
+ collapsed: {},
662
+ }
663
+ }
664
+
665
+ function asStringArray(value) {
666
+ if (!Array.isArray(value)) return []
667
+ return value.filter((entry) => typeof entry === 'string')
668
+ }
669
+
670
+ function sanitizeState(raw) {
671
+ const next = defaultState()
672
+ if (!raw || typeof raw !== 'object' || raw.version !== 1) return next
673
+ if (MODES.includes(raw.mode)) next.mode = raw.mode
674
+ if (raw.orderBy === 'manual' || raw.orderBy === 'updated') next.orderBy = raw.orderBy
675
+ if (FILTERS.includes(raw.archivedFilter)) next.archivedFilter = raw.archivedFilter
676
+ if (typeof raw.activeOnly === 'boolean') next.activeOnly = raw.activeOnly
677
+
678
+ if (Array.isArray(raw.groups)) {
679
+ const seen = new Set()
680
+ for (const entry of raw.groups) {
681
+ if (!entry || typeof entry !== 'object') continue
682
+ const id = typeof entry.id === 'string' ? entry.id : ''
683
+ const name = typeof entry.name === 'string' ? entry.name.trim() : ''
684
+ if (!id || !name || seen.has(id) || next.groups.length >= 50) continue
685
+ seen.add(id)
686
+ next.groups.push({ id, name })
687
+ }
688
+ }
689
+
690
+ if (raw.assignments && typeof raw.assignments === 'object') {
691
+ for (const [key, value] of Object.entries(raw.assignments)) {
692
+ if (typeof key === 'string' && typeof value === 'string' && value)
693
+ next.assignments[key] = value
694
+ }
695
+ }
696
+
697
+ if (raw.sessionProjects && typeof raw.sessionProjects === 'object') {
698
+ let count = 0
699
+ for (const [sessionId, projectId] of Object.entries(raw.sessionProjects)) {
700
+ if (count >= 5000) break
701
+ if (typeof sessionId !== 'string' || typeof projectId !== 'string') continue
702
+ if (!sessionId || !projectId) continue
703
+ next.sessionProjects[sessionId] = projectId
704
+ count += 1
705
+ }
706
+ }
707
+
708
+ if (raw.projectNames && typeof raw.projectNames === 'object') {
709
+ let count = 0
710
+ for (const [key, value] of Object.entries(raw.projectNames)) {
711
+ if (count >= 200) break
712
+ if (typeof key !== 'string' || typeof value !== 'string') continue
713
+ const name = value.trim()
714
+ if (!name || name.length > 80) continue
715
+ next.projectNames[key] = name
716
+ count += 1
717
+ }
718
+ }
719
+
720
+ if (raw.projectOrder && typeof raw.projectOrder === 'object') {
721
+ for (const [key, value] of Object.entries(raw.projectOrder)) {
722
+ if (typeof key === 'string') next.projectOrder[key] = asStringArray(value)
723
+ }
724
+ }
725
+
726
+ if (raw.sessionOrder && typeof raw.sessionOrder === 'object') {
727
+ for (const [key, value] of Object.entries(raw.sessionOrder)) {
728
+ if (typeof key === 'string') next.sessionOrder[key] = asStringArray(value)
729
+ }
730
+ }
731
+
732
+ if (raw.collapsed && typeof raw.collapsed === 'object') {
733
+ for (const [key, value] of Object.entries(raw.collapsed)) {
734
+ if (typeof key === 'string' && typeof value === 'boolean') next.collapsed[key] = value
735
+ }
736
+ }
737
+
738
+ return next
739
+ }
740
+
741
+ function loadState() {
742
+ try {
743
+ const raw = window.localStorage.getItem(STORAGE_KEY)
744
+ if (!raw) return defaultState()
745
+ return sanitizeState(JSON.parse(raw))
746
+ } catch {
747
+ return defaultState()
748
+ }
749
+ }
750
+
751
+ function saveState(state) {
752
+ try {
753
+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify(state))
754
+ } catch {
755
+ // The browser may deny storage; the in-memory state still works.
756
+ }
757
+ }
758
+
759
+ function nextGroupId() {
760
+ return `g_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 7)}`
761
+ }
762
+
763
+ function withAssignments(state, path, groupId, memberPaths) {
764
+ const assignments = { ...(state.assignments || {}) }
765
+ if (Array.isArray(memberPaths)) {
766
+ for (const member of memberPaths) {
767
+ if (typeof member === 'string' && member !== path) delete assignments[member]
768
+ }
769
+ }
770
+ if (groupId) assignments[path] = groupId
771
+ else delete assignments[path]
772
+ return assignments
773
+ }
774
+
775
+ function assignProject(state, path, groupId) {
776
+ return { ...state, assignments: withAssignments(state, path, groupId) }
777
+ }
778
+
779
+ function renameProject(state, key, name) {
780
+ const projectNames = { ...(state.projectNames || {}) }
781
+ const trimmed = typeof name === 'string' ? name.trim() : ''
782
+ if (trimmed) projectNames[key] = trimmed
783
+ else delete projectNames[key]
784
+ return { ...state, projectNames }
785
+ }
786
+
787
+ function createGroup(state, id, name) {
788
+ const groups = Array.isArray(state.groups) ? state.groups.slice() : []
789
+ groups.push({ id, name })
790
+ return { ...state, groups }
791
+ }
792
+
793
+ function deleteGroup(state, id) {
794
+ const groups = (Array.isArray(state.groups) ? state.groups : []).filter(
795
+ (group) => group.id !== id,
796
+ )
797
+ const assignments = { ...(state.assignments || {}) }
798
+ for (const [path, groupId] of Object.entries(assignments)) {
799
+ if (groupId === id) delete assignments[path]
800
+ }
801
+ const projectOrder = { ...(state.projectOrder || {}) }
802
+ delete projectOrder[id]
803
+ const collapsed = { ...(state.collapsed || {}) }
804
+ delete collapsed[`g:${id}`]
805
+ return { ...state, groups, assignments, projectOrder, collapsed }
806
+ }
807
+
808
+ function renameGroup(state, id, name) {
809
+ return {
810
+ ...state,
811
+ groups: (state.groups || []).map((group) => (group.id === id ? { ...group, name } : group)),
812
+ }
813
+ }
814
+
815
+ // Refill the visible slots without moving a filtered-out entry from its slot.
816
+ function mergeVisibleOrder(previous, next, aliases) {
817
+ const visible = new Set(next)
818
+ let index = 0
819
+ const prior = new Set(previous || [])
820
+ const aliasSlots = new Map()
821
+ // Like orderIndexForProject, prefer the exact key and then the first
822
+ // present member path in project membership order, not saved-slot order.
823
+ for (const [key, canonical] of aliases || []) {
824
+ if (!prior.has(canonical) && prior.has(key) && !aliasSlots.has(canonical)) {
825
+ aliasSlots.set(canonical, key)
826
+ }
827
+ }
828
+ const order = new Set()
829
+ for (const key of prior) {
830
+ const canonical = aliases?.get(key)
831
+ if (canonical === undefined) order.add(key)
832
+ else if (aliasSlots.get(canonical) === key) order.add(canonical)
833
+ }
834
+ return [
835
+ ...Array.from(order, (key) => (visible.has(key) ? next[index++] : key)),
836
+ ...next.slice(index),
837
+ ]
838
+ }
839
+
840
+ function moveProjectInOrder(
841
+ state,
842
+ path,
843
+ groupId,
844
+ orderedKeys,
845
+ anchorKey,
846
+ position,
847
+ memberPaths,
848
+ aliases,
849
+ ) {
850
+ const order = (Array.isArray(orderedKeys) ? orderedKeys : []).filter((key) => key !== path)
851
+ let index = anchorKey ? order.indexOf(anchorKey) : -1
852
+ if (index < 0) index = order.length
853
+ else if (position === 'after') index += 1
854
+ order.splice(index, 0, path)
855
+ const orderKey = groupId || UNGROUPED
856
+ return {
857
+ ...state,
858
+ assignments: withAssignments(state, path, groupId, memberPaths),
859
+ projectOrder: {
860
+ ...(state.projectOrder || {}),
861
+ [orderKey]: mergeVisibleOrder(state.projectOrder?.[orderKey], order, aliases),
862
+ },
863
+ }
864
+ }
865
+
866
+ function moveSessionInOrder(
867
+ state,
868
+ projectKey,
869
+ sessionId,
870
+ orderedIds,
871
+ anchorId,
872
+ position,
873
+ memberPaths,
874
+ ) {
875
+ const order = (Array.isArray(orderedIds) ? orderedIds : []).filter((id) => id !== sessionId)
876
+ let index = anchorId ? order.indexOf(anchorId) : -1
877
+ if (index < 0) index = order.length
878
+ else if (position === 'after') index += 1
879
+ order.splice(index, 0, sessionId)
880
+ return {
881
+ ...state,
882
+ orderBy: 'manual',
883
+ sessionOrder: {
884
+ ...(state.sessionOrder || {}),
885
+ [projectKey]: mergeVisibleOrder(
886
+ orderForProject(state.sessionOrder, projectKey, memberPaths),
887
+ order,
888
+ ),
889
+ },
890
+ }
891
+ }
892
+
893
+ function isCollapsed(state, key, defaultExpanded) {
894
+ const stored = state.collapsed ? state.collapsed[key] : undefined
895
+ return stored === undefined ? !defaultExpanded : stored === true
896
+ }
897
+
898
+ function toggleCollapsed(state, key, defaultExpanded) {
899
+ const collapsed = { ...(state.collapsed || {}) }
900
+ collapsed[key] = !isCollapsed(state, key, defaultExpanded)
901
+ return { ...state, collapsed }
902
+ }
903
+
904
+ function archivedSetOf(snapshot) {
905
+ return new Set(
906
+ snapshot && Array.isArray(snapshot.archivedSessionIds) ? snapshot.archivedSessionIds : [],
907
+ )
908
+ }
909
+
910
+ function sessionVisible(summary, archived, filter, currentId) {
911
+ if (!summary) return false
912
+ if (summary.origin === 'subagent') return false
913
+ if (summary.blank && summary.id !== currentId) return false
914
+ const isArchived = archived.has(summary.id)
915
+ if (filter === 'hide' && isArchived) return false
916
+ if (filter === 'only' && !isArchived) return false
917
+ return true
918
+ }
919
+
920
+ function isActiveSession(summary, statusMap) {
921
+ if (!summary) return false
922
+ const status =
923
+ statusMap && typeof statusMap.get === 'function' ? statusMap.get(summary.id) : undefined
924
+ if (status) {
925
+ if (status.running === true || status.pendingInteraction != null) return true
926
+ if (status.running === false) return false
927
+ }
928
+ return summary.running === true
929
+ }
930
+
931
+ function _sessionHasPendingInteraction(summary, statusMap) {
932
+ const status =
933
+ statusMap && typeof statusMap.get === 'function' ? statusMap.get(summary.id) : undefined
934
+ return Boolean(status?.pendingInteraction)
935
+ }
936
+
937
+ function compareSessions(left, right) {
938
+ const delta = (Number(right.updatedAt) || 0) - (Number(left.updatedAt) || 0)
939
+ if (delta !== 0) return delta
940
+ return String(left.displayTitle || '').localeCompare(String(right.displayTitle || ''))
941
+ }
942
+
943
+ function orderForProject(orderMap, projectKey, memberPaths) {
944
+ if (orderMap && Array.isArray(orderMap[projectKey])) return orderMap[projectKey]
945
+ for (const path of memberPaths || []) {
946
+ if (orderMap && Array.isArray(orderMap[path])) return orderMap[path]
947
+ }
948
+ return null
949
+ }
950
+
951
+ function orderIndexForProject(order, project) {
952
+ let index = order.indexOf(project.key)
953
+ if (index !== -1) return index
954
+ for (const path of project.memberPaths || []) {
955
+ index = order.indexOf(path)
956
+ if (index !== -1) return index
957
+ }
958
+ return -1
959
+ }
960
+
961
+ function sortSessions(list, state, projectKey, memberPaths) {
962
+ const order =
963
+ state.orderBy === 'manual'
964
+ ? orderForProject(state.sessionOrder, projectKey, memberPaths)
965
+ : null
966
+ return list.slice().sort((left, right) => {
967
+ if (order) {
968
+ const li = order.indexOf(left.id)
969
+ const ri = order.indexOf(right.id)
970
+ if (li !== -1 || ri !== -1) {
971
+ return (
972
+ (li === -1 ? Number.MAX_SAFE_INTEGER : li) -
973
+ (ri === -1 ? Number.MAX_SAFE_INTEGER : ri)
974
+ )
975
+ }
976
+ }
977
+ return compareSessions(left, right)
978
+ })
979
+ }
980
+
981
+ function pinFirst(list, pinned) {
982
+ return list.slice().sort((left, right) => {
983
+ const lp = pinned.has(left.id) ? 0 : 1
984
+ const rp = pinned.has(right.id) ? 0 : 1
985
+ return lp - rp
986
+ })
987
+ }
988
+
989
+ function sortProjects(list, state, orderKey) {
990
+ const order =
991
+ state.orderBy === 'manual' ? state.projectOrder[orderKey || UNGROUPED] || [] : null
992
+ list.sort((left, right) => {
993
+ if (order) {
994
+ const li = orderIndexForProject(order, left)
995
+ const ri = orderIndexForProject(order, right)
996
+ if (li !== -1 || ri !== -1) {
997
+ return (
998
+ (li === -1 ? Number.MAX_SAFE_INTEGER : li) -
999
+ (ri === -1 ? Number.MAX_SAFE_INTEGER : ri)
1000
+ )
1001
+ }
1002
+ }
1003
+ const delta = (Number(right.updatedAt) || 0) - (Number(left.updatedAt) || 0)
1004
+ if (delta !== 0) return delta
1005
+ return String(left.title || '').localeCompare(String(right.title || ''))
1006
+ })
1007
+ return list
1008
+ }
1009
+
1010
+ function assignmentForProject(state, project) {
1011
+ const assignments =
1012
+ state.assignments && typeof state.assignments === 'object' ? state.assignments : {}
1013
+ const groupIds = new Set((Array.isArray(state.groups) ? state.groups : []).map((g) => g.id))
1014
+ for (const candidate of [project.key, ...(project.memberPaths || [])]) {
1015
+ const groupId = assignments[candidate]
1016
+ if (typeof groupId === 'string' && groupIds.has(groupId)) return groupId
1017
+ }
1018
+ return null
1019
+ }
1020
+
1021
+ function buildTree(projects) {
1022
+ const nodes = new Map()
1023
+ for (const project of projects) nodes.set(project.key, { project, children: [] })
1024
+ const roots = []
1025
+ for (const project of projects) {
1026
+ let parent = null
1027
+ for (const candidate of projects) {
1028
+ if (candidate === project) continue
1029
+ if (!candidate.path || !project.path) continue
1030
+ if (!isAncestor(candidate.path, project.path)) continue
1031
+ if (!parent || normalizePath(candidate.path).length > normalizePath(parent.path).length)
1032
+ parent = candidate
1033
+ }
1034
+ if (parent) nodes.get(parent.key).children.push(nodes.get(project.key))
1035
+ else roots.push(nodes.get(project.key))
1036
+ }
1037
+ const sortNodes = (list) => {
1038
+ list.sort((left, right) => {
1039
+ const delta =
1040
+ (Number(right.project.updatedAt) || 0) - (Number(left.project.updatedAt) || 0)
1041
+ if (delta !== 0) return delta
1042
+ return String(left.project.title || '').localeCompare(String(right.project.title || ''))
1043
+ })
1044
+ for (const node of list) sortNodes(node.children)
1045
+ }
1046
+ sortNodes(roots)
1047
+ return roots
1048
+ }
1049
+
1050
+ function searchSessions(query, projects, pinned) {
1051
+ const results = []
1052
+ for (const project of projects) {
1053
+ const projectText = String(`${project.title || ''} ${project.path || ''}`).toLowerCase()
1054
+ for (const session of project.sessions) {
1055
+ const text = [session.displayTitle, session.title, session.cwd]
1056
+ .filter(Boolean)
1057
+ .join(' ')
1058
+ .toLowerCase()
1059
+ if (!text.includes(query) && !projectText.includes(query)) continue
1060
+ results.push({ session, project })
1061
+ }
1062
+ }
1063
+ results.sort((left, right) => {
1064
+ const lp = pinned.has(left.session.id) ? 0 : 1
1065
+ const rp = pinned.has(right.session.id) ? 0 : 1
1066
+ if (lp !== rp) return lp - rp
1067
+ return compareSessions(left.session, right.session)
1068
+ })
1069
+ return results.slice(0, 80)
1070
+ }
1071
+
1072
+ function buildView(input) {
1073
+ const snapshot = input.workspaceSnapshot || {
1074
+ items: [],
1075
+ archivedSessionIds: [],
1076
+ pinnedSessionIds: [],
1077
+ phase: 'pending',
1078
+ }
1079
+ const sessionSnapshot = input.sessionSnapshot || { ids: [], byId: {} }
1080
+ const state = input.state || defaultState()
1081
+ const statusMap = input.statusMap
1082
+ const currentId = input.currentId
1083
+ const query = typeof input.query === 'string' ? input.query : ''
1084
+ const activeOnly = state.activeOnly === true && state.mode === 'orca'
1085
+ const filter = FILTERS.includes(state.archivedFilter) ? state.archivedFilter : 'hide'
1086
+ const archived = archivedSetOf(snapshot)
1087
+ const pinnedIds = Array.isArray(snapshot.pinnedSessionIds) ? snapshot.pinnedSessionIds : []
1088
+ const pinned = new Set(pinnedIds)
1089
+ const summaries = sessionSnapshot.byId || {}
1090
+ const sessionIds = Array.isArray(sessionSnapshot.ids) ? sessionSnapshot.ids : []
1091
+ const items = Array.isArray(snapshot.items) ? snapshot.items : []
1092
+ let projects = []
1093
+ const accounted = new Set()
1094
+ const workspaceBySession = new Map()
1095
+ const consolidate = state.mode === 'orca'
1096
+ const repoMap = input.repoMap
1097
+ const groupsByKey = new Map()
1098
+
1099
+ for (const workspace of items) {
1100
+ const sessions = []
1101
+ for (const id of workspace.sessionIds || []) {
1102
+ accounted.add(id)
1103
+ const summary = summaries[id]
1104
+ if (!summary || !sessionVisible(summary, archived, filter, currentId)) continue
1105
+ if (activeOnly && !isActiveSession(summary, statusMap)) continue
1106
+ sessions.push(summary)
1107
+ }
1108
+ const path = normalizePath(workspace.path)
1109
+ const repo = workspaceRepo(workspace, repoMap)
1110
+ const key = consolidate ? repo.key : path
1111
+ let group = groupsByKey.get(key)
1112
+ if (!group) {
1113
+ group = {
1114
+ key,
1115
+ root: consolidate ? repo.root : path,
1116
+ title: consolidate ? repo.title : workspace.title || baseName(path),
1117
+ mainWorkspace: null,
1118
+ members: [],
1119
+ }
1120
+ groupsByKey.set(key, group)
1121
+ }
1122
+ group.members.push({ workspace, path, repo, sessions })
1123
+ if (!group.mainWorkspace && (repo.main === true || path === normalizePath(repo.root))) {
1124
+ group.mainWorkspace = workspace
1125
+ }
1126
+ for (const session of sessions) {
1127
+ if (!workspaceBySession.has(session.id)) workspaceBySession.set(session.id, path)
1128
+ }
1129
+ }
1130
+
1131
+ for (const group of groupsByKey.values()) {
1132
+ const all = []
1133
+ const seen = new Set()
1134
+ for (const member of group.members) {
1135
+ for (const session of member.sessions) {
1136
+ if (seen.has(session.id)) continue
1137
+ seen.add(session.id)
1138
+ all.push(session)
1139
+ }
1140
+ }
1141
+ const projectKey = normalizePath(group.key)
1142
+ const memberPaths = group.members.map((member) => member.path)
1143
+ const ordered = sortSessions(all, state, projectKey, memberPaths)
1144
+ const mainWorkspace = group.mainWorkspace
1145
+ const primary = mainWorkspace || group.members[0]?.workspace || null
1146
+ const customTitle =
1147
+ state.projectNames && typeof state.projectNames === 'object'
1148
+ ? state.projectNames[projectKey]
1149
+ : undefined
1150
+ const title =
1151
+ (typeof customTitle === 'string' && customTitle) ||
1152
+ mainWorkspace?.title ||
1153
+ group.title ||
1154
+ group.members[0]?.workspace?.title ||
1155
+ baseName(projectKey)
1156
+ const worktrees = projectWorktrees(group)
1157
+ const updatedAt =
1158
+ ordered.reduce((value, session) => Math.max(value, Number(session.updatedAt) || 0), 0) ||
1159
+ group.members.reduce(
1160
+ (value, member) => Math.max(value, Date.parse(member.workspace.updatedAt || '') || 0),
1161
+ 0,
1162
+ )
1163
+ projects.push({
1164
+ key: projectKey,
1165
+ projectId: projectKey,
1166
+ workspaceId: primary ? primary.workspaceId : null,
1167
+ workspaceIds: group.members.map((member) => member.workspace.workspaceId),
1168
+ memberPaths,
1169
+ worktrees,
1170
+ groupId: null,
1171
+ title,
1172
+ path: group.root || primary?.path || null,
1173
+ sessions: ordered,
1174
+ pinnedFirst: pinFirst(ordered, pinned),
1175
+ updatedAt,
1176
+ isUngrouped: false,
1177
+ })
1178
+ }
1179
+
1180
+ const loose = []
1181
+ for (const id of sessionIds) {
1182
+ if (accounted.has(id)) continue
1183
+ const summary = summaries[id]
1184
+ if (!summary) continue
1185
+ if (summary.origin === 'subagent') continue
1186
+ if (!sessionVisible(summary, archived, filter, currentId)) continue
1187
+ if (activeOnly && !isActiveSession(summary, statusMap)) continue
1188
+ loose.push(summary)
1189
+ }
1190
+ const sessionProjects =
1191
+ consolidate && state.sessionProjects && typeof state.sessionProjects === 'object'
1192
+ ? state.sessionProjects
1193
+ : {}
1194
+ const adoptedByProject = new Map()
1195
+ const migrationCandidates = []
1196
+ const unmatchedLoose = []
1197
+ const remainingLoose = []
1198
+ for (const session of loose) {
1199
+ if (!consolidate) {
1200
+ remainingLoose.push(session)
1201
+ unmatchedLoose.push(session)
1202
+ continue
1203
+ }
1204
+ const manualId =
1205
+ typeof sessionProjects[session.id] === 'string'
1206
+ ? normalizePath(sessionProjects[session.id])
1207
+ : null
1208
+ if (manualId) {
1209
+ const target = projects.find(
1210
+ (project) => !project.isUngrouped && normalizePath(project.projectId) === manualId,
1211
+ )
1212
+ if (!target) {
1213
+ remainingLoose.push(session)
1214
+ unmatchedLoose.push(session)
1215
+ continue
1216
+ }
1217
+ if (!adoptedByProject.has(target.key)) adoptedByProject.set(target.key, [])
1218
+ adoptedByProject.get(target.key).push(session)
1219
+ continue
1220
+ }
1221
+ const target = projectForLooseSession(session, projects)
1222
+ if (target) {
1223
+ migrationCandidates.push({
1224
+ sessionId: session.id,
1225
+ title: session.displayTitle || session.title || '',
1226
+ projectId: target.projectId,
1227
+ projectTitle: target.title || target.path || '',
1228
+ })
1229
+ remainingLoose.push(session)
1230
+ } else {
1231
+ remainingLoose.push(session)
1232
+ unmatchedLoose.push(session)
1233
+ }
1234
+ }
1235
+ for (const [key, sessions] of adoptedByProject) {
1236
+ const target = projects.find((project) => project.key === key)
1237
+ if (!target) continue
1238
+ target.sessions = sortSessions(
1239
+ [...target.sessions, ...sessions],
1240
+ state,
1241
+ target.key,
1242
+ target.memberPaths,
1243
+ )
1244
+ target.pinnedFirst = pinFirst(target.sessions, pinned)
1245
+ target.updatedAt = target.sessions.reduce(
1246
+ (value, session) => Math.max(value, Number(session.updatedAt) || 0),
1247
+ target.updatedAt,
1248
+ )
1249
+ }
1250
+ // Adoption and migration matching must see registered projects even when
1251
+ // their only active sessions are loose sessions with an external mapping.
1252
+ if (activeOnly) projects = projects.filter((project) => project.sessions.length > 0)
1253
+ if (remainingLoose.length > 0) {
1254
+ const ordered = sortSessions(remainingLoose, state, UNGROUPED)
1255
+ projects.push({
1256
+ key: UNGROUPED,
1257
+ projectId: UNGROUPED,
1258
+ workspaceId: null,
1259
+ workspaceIds: [],
1260
+ memberPaths: [],
1261
+ worktrees: [],
1262
+ looseGroups: groupLooseSessions(ordered, items),
1263
+ groupId: null,
1264
+ title: null,
1265
+ path: null,
1266
+ sessions: ordered,
1267
+ pinnedFirst: pinFirst(ordered, pinned),
1268
+ updatedAt: ordered.reduce(
1269
+ (value, session) => Math.max(value, Number(session.updatedAt) || 0),
1270
+ 0,
1271
+ ),
1272
+ isUngrouped: true,
1273
+ })
1274
+ }
1275
+
1276
+ const projectBySession = new Map()
1277
+ for (const project of projects) {
1278
+ for (const session of project.sessions) {
1279
+ if (!projectBySession.has(session.id)) projectBySession.set(session.id, project)
1280
+ }
1281
+ }
1282
+
1283
+ const pinnedSessions = []
1284
+ for (const id of pinnedIds) {
1285
+ const summary = summaries[id]
1286
+ if (!summary) continue
1287
+ if (summary.origin === 'subagent') continue
1288
+ if (!sessionVisible(summary, archived, filter, currentId)) continue
1289
+ if (activeOnly && !isActiveSession(summary, statusMap)) continue
1290
+ pinnedSessions.push({ session: summary, project: projectBySession.get(id) || null })
1291
+ }
1292
+
1293
+ const groups = []
1294
+ const configured = Array.isArray(state.groups) ? state.groups : []
1295
+ const groupIds = new Set(configured.map((group) => group.id))
1296
+ const assigned = new Map()
1297
+ for (const project of projects) {
1298
+ if (project.isUngrouped) continue
1299
+ const groupId = assignmentForProject(state, project)
1300
+ project.groupId = groupId
1301
+ if (typeof groupId === 'string' && groupIds.has(groupId)) {
1302
+ if (!assigned.has(groupId)) assigned.set(groupId, [])
1303
+ assigned.get(groupId).push(project)
1304
+ }
1305
+ }
1306
+ for (const group of configured) {
1307
+ const list = assigned.get(group.id) || []
1308
+ sortProjects(list, state, group.id)
1309
+ groups.push({ id: group.id, name: group.name, projects: list })
1310
+ }
1311
+
1312
+ const ungroupedProjects = projects.filter((project) => {
1313
+ if (project.isUngrouped) return false
1314
+ return !project.groupId
1315
+ })
1316
+ sortProjects(ungroupedProjects, state, UNGROUPED)
1317
+
1318
+ const flat = []
1319
+ for (const project of projects) {
1320
+ for (const session of project.sessions) flat.push({ session, project })
1321
+ }
1322
+ flat.sort((left, right) => {
1323
+ const lp = pinned.has(left.session.id) ? 0 : 1
1324
+ const rp = pinned.has(right.session.id) ? 0 : 1
1325
+ if (lp !== rp) return lp - rp
1326
+ return compareSessions(left.session, right.session)
1327
+ })
1328
+
1329
+ const trimmed = query.trim().toLowerCase()
1330
+ return {
1331
+ projects,
1332
+ groups,
1333
+ ungroupedProjects,
1334
+ pinned: pinnedSessions,
1335
+ tree: buildTree(projects.filter((project) => !project.isUngrouped)),
1336
+ flat,
1337
+ searchResults: trimmed ? searchSessions(trimmed, projects, pinned) : [],
1338
+ projectBySession,
1339
+ workspaceBySession,
1340
+ migration: {
1341
+ candidates: migrationCandidates,
1342
+ unmatched: unmatchedLoose.length,
1343
+ adopted: Object.keys(sessionProjects).length,
1344
+ },
1345
+ counts: {
1346
+ projects: projects.filter((project) => !project.isUngrouped).length,
1347
+ sessions: projects.reduce((value, project) => value + project.sessions.length, 0),
1348
+ pinned: pinnedSessions.length,
1349
+ },
1350
+ hasProjects: projects.length > 0,
1351
+ phase: snapshot.phase || 'pending',
1352
+ }
1353
+ }
1354
+
1355
+ function useSource(source) {
1356
+ const subscribe = React.useCallback(
1357
+ (listener) => (source ? source.subscribe(listener) : () => {}),
1358
+ [source],
1359
+ )
1360
+ const read = React.useCallback(() => (source ? source.getSnapshot() : undefined), [source])
1361
+ return React.useSyncExternalStore(subscribe, read, read)
1362
+ }
1363
+
1364
+ function findCurrentId(sessionSnapshot) {
1365
+ if (!sessionSnapshot) return undefined
1366
+ const ids = Array.isArray(sessionSnapshot.ids)
1367
+ ? sessionSnapshot.ids
1368
+ : Object.keys(sessionSnapshot.byId || {})
1369
+ for (const id of ids) {
1370
+ const summary = sessionSnapshot.byId ? sessionSnapshot.byId[id] : undefined
1371
+ if (summary?.retainedBy && summary.retainedBy.mainView > 0) return id
1372
+ }
1373
+ return undefined
1374
+ }
1375
+
1376
+ function sessionLabel(session, currentId, t) {
1377
+ if (!session) return t('session.untitled')
1378
+ if (session.blank && session.id === currentId) return t('session.new')
1379
+ return session.displayTitle || session.title || t('session.untitled')
1380
+ }
1381
+
1382
+ function errorMessage(error) {
1383
+ if (!error) return ''
1384
+ if (typeof error === 'string') return error
1385
+ if (typeof error.message === 'string' && error.message) return error.message
1386
+ if (error.rpcError && typeof error.rpcError.message === 'string')
1387
+ return error.rpcError.message
1388
+ return ''
1389
+ }
1390
+
1391
+ function isActiveWorkRefusal(error) {
1392
+ return Boolean(
1393
+ error &&
1394
+ error.name === 'WorkspaceArchiveError' &&
1395
+ error.rpcError &&
1396
+ error.rpcError.code === 'workspace/session-active',
1397
+ )
1398
+ }
1399
+
1400
+ function stopEvent(event) {
1401
+ if (!event) return
1402
+ event.preventDefault()
1403
+ event.stopPropagation()
1404
+ }
1405
+
1406
+ function clearDropIndicators() {
1407
+ for (const element of document.querySelectorAll('[data-orca-drop]')) {
1408
+ delete element.dataset.orcaDrop
1409
+ }
1410
+ }
1411
+
1412
+ function setDropIndicator(element, position) {
1413
+ if (!element) return
1414
+ clearDropIndicators()
1415
+ element.dataset.orcaDrop = position
1416
+ }
1417
+
1418
+ let dragPayload = null
1419
+
1420
+ function IconButton({ icon, label, onClick, active, danger, disabled, size = 22 }) {
1421
+ return h(
1422
+ 'button',
1423
+ {
1424
+ type: 'button',
1425
+ className: cx('orca-icon-button', active && 'is-active', danger && 'is-danger'),
1426
+ 'aria-label': label,
1427
+ title: label,
1428
+ disabled,
1429
+ onClick: (event) => {
1430
+ stopEvent(event)
1431
+ if (!disabled && onClick) onClick(event)
1432
+ },
1433
+ },
1434
+ h(Icon, { name: icon, size: size === 22 ? 14 : size }),
1435
+ )
1436
+ }
1437
+
1438
+ function SessionStatusIndicator({ running, completed, pending, archived }) {
1439
+ if (archived) {
1440
+ return h('span', { className: 'orca-status-dot is-archived', 'aria-hidden': 'true' })
1441
+ }
1442
+ if (pending) {
1443
+ return h('span', { className: 'orca-status-dot is-pending', 'aria-hidden': 'true' })
1444
+ }
1445
+ if (running) {
1446
+ return h('span', { className: 'orca-spinner', 'aria-hidden': 'true' })
1447
+ }
1448
+ if (completed) {
1449
+ return h('span', { className: 'orca-status-dot is-completed', 'aria-hidden': 'true' })
1450
+ }
1451
+ return h('span', { className: 'orca-status-dot', 'aria-hidden': 'true' })
1452
+ }
1453
+
1454
+ function CountBadge({ children }) {
1455
+ return h('span', { className: 'orca-count' }, children)
1456
+ }
1457
+
1458
+ function Chevron({ open }) {
1459
+ return h(
1460
+ 'span',
1461
+ { className: cx('orca-chevron', open && 'is-open') },
1462
+ h(Icon, { name: 'chevron', size: 11 }),
1463
+ )
1464
+ }
1465
+
1466
+ function SessionRow(props) {
1467
+ const {
1468
+ session,
1469
+ project,
1470
+ t,
1471
+ actions,
1472
+ variant,
1473
+ depth = 0,
1474
+ drag,
1475
+ pinned,
1476
+ archived,
1477
+ current,
1478
+ hideProject = false,
1479
+ } = props
1480
+ const statusMap = React.useContext(SessionStatusContext)
1481
+ const workspaceBySession = React.useContext(WorkspacePathContext)
1482
+ const worktree = worktreeForSession(session, project, workspaceBySession)
1483
+ const liveStatus =
1484
+ statusMap && typeof statusMap.get === 'function' ? statusMap.get(session.id) : undefined
1485
+ const running =
1486
+ !archived &&
1487
+ (liveStatus && liveStatus.running !== undefined
1488
+ ? liveStatus.running === true
1489
+ : session.running === true)
1490
+ const completed = !archived && Boolean(liveStatus?.completionUnread)
1491
+ const pending = !archived && Boolean(liveStatus?.pendingInteraction)
1492
+ const pinHint = Boolean(props.pinHint)
1493
+ const title = sessionLabel(session, props.currentId, t)
1494
+ const showMeta = variant === 'pinned' || variant === 'flat' || variant === 'search'
1495
+ const meta = showMeta
1496
+ ? project
1497
+ ? project.isUngrouped
1498
+ ? session.cwd
1499
+ ? baseName(session.cwd)
1500
+ : t('project.ungrouped')
1501
+ : project.title
1502
+ : session.cwd
1503
+ ? baseName(session.cwd)
1504
+ : null
1505
+ : null
1506
+ const showPinnedHint = pinHint && pinned
1507
+ const showPinGlyph = pinned && !pinHint
1508
+ const worktreeBadge = worktree
1509
+ ? h(
1510
+ 'span',
1511
+ {
1512
+ className: cx('orca-worktree', worktree.main && 'is-main'),
1513
+ title: session.cwd ? `${worktree.label} — ${session.cwd}` : worktree.label,
1514
+ },
1515
+ worktree.label,
1516
+ )
1517
+ : null
1518
+ const pinnedHint = showPinnedHint
1519
+ ? h(
1520
+ 'span',
1521
+ { className: 'orca-session-hint' },
1522
+ h(Icon, { name: 'pinFilled', size: 9 }),
1523
+ t('pinned.hint'),
1524
+ )
1525
+ : null
1526
+ const archivedBadge = archived
1527
+ ? h('span', { className: 'orca-session-hint is-archived' }, t('session.archivedHint'))
1528
+ : null
1529
+ const projectBadge =
1530
+ !hideProject && meta && !(worktree && worktree.label === meta)
1531
+ ? h(
1532
+ 'span',
1533
+ { className: 'orca-session-project' },
1534
+ h(Icon, { name: 'folder', size: 10, className: 'orca-session-project-icon' }),
1535
+ h('span', { className: 'orca-session-meta', title: meta }, meta),
1536
+ )
1537
+ : null
1538
+ const pinGlyph = showPinGlyph
1539
+ ? h(Icon, { name: 'pinFilled', size: 10, className: 'orca-session-pin' })
1540
+ : null
1541
+ const titleBadge = h('span', { className: 'orca-session-title', title }, title)
1542
+
1543
+ const main = h(
1544
+ 'div',
1545
+ {
1546
+ className: cx('orca-session-main', current && 'is-current'),
1547
+ role: 'button',
1548
+ tabIndex: 0,
1549
+ draggable: drag ? true : undefined,
1550
+ style: { marginLeft: variant === 'tree' ? depth * 13 : 0 },
1551
+ onClick: () => actions.open(session, variant),
1552
+ onKeyDown: (event) => {
1553
+ if (event.key === 'Enter' || event.key === ' ') {
1554
+ stopEvent(event)
1555
+ actions.open(session, variant)
1556
+ }
1557
+ },
1558
+ onDragStart: drag ? (event) => drag.start(event, session) : undefined,
1559
+ onDragOver: drag ? (event) => drag.over(event, session) : undefined,
1560
+ onDrop: drag ? (event) => drag.drop(event, session) : undefined,
1561
+ onDragEnd: drag ? drag.end : undefined,
1562
+ },
1563
+ h(
1564
+ 'div',
1565
+ { className: 'orca-session-line' },
1566
+ h(SessionStatusIndicator, { running, completed, pending, archived }),
1567
+ pinGlyph,
1568
+ titleBadge,
1569
+ ),
1570
+ h(
1571
+ 'div',
1572
+ { className: 'orca-session-subline' },
1573
+ worktreeBadge,
1574
+ projectBadge,
1575
+ pinnedHint,
1576
+ archivedBadge,
1577
+ ),
1578
+ )
1579
+
1580
+ const hover = h(
1581
+ 'div',
1582
+ { className: 'orca-session-actions' },
1583
+ !archived
1584
+ ? h(IconButton, {
1585
+ icon: pinned ? 'pinFilled' : 'pin',
1586
+ label: pinned ? t('pinned.unpin') : t('pinned.pin'),
1587
+ active: pinned,
1588
+ onClick: () => (pinned ? actions.unpin(session) : actions.pin(session)),
1589
+ })
1590
+ : h(IconButton, {
1591
+ icon: 'restore',
1592
+ label: t('session.unarchive'),
1593
+ onClick: () => actions.unarchive(session),
1594
+ }),
1595
+ h(IconButton, {
1596
+ icon: 'more',
1597
+ label: t('action.viewOptions'),
1598
+ onClick: (event) => actions.menu(event, session, pinned, archived, variant),
1599
+ }),
1600
+ )
1601
+
1602
+ return h(
1603
+ 'div',
1604
+ {
1605
+ className: cx(
1606
+ 'orca-session',
1607
+ `orca-session--${variant}`,
1608
+ pinned && pinHint && 'is-pinned-ref',
1609
+ archived && 'is-archived',
1610
+ current && 'is-current',
1611
+ ),
1612
+ 'data-session-id': session.id,
1613
+ },
1614
+ main,
1615
+ hover,
1616
+ )
1617
+ }
1618
+
1619
+ function ProjectRow(props) {
1620
+ const {
1621
+ project,
1622
+ t,
1623
+ actions,
1624
+ variant,
1625
+ depth = 0,
1626
+ groupId,
1627
+ siblings,
1628
+ collapsed,
1629
+ onToggle,
1630
+ allowDrag,
1631
+ beforeSessions,
1632
+ currentId,
1633
+ pinnedSet,
1634
+ archivedSet,
1635
+ drag,
1636
+ } = props
1637
+ const expanded = !collapsed
1638
+ const guided = variant === 'orca'
1639
+ const [sessionLimit, setSessionLimit] = React.useState(8)
1640
+ const sessions = variant === 'orca' ? project.sessions : project.pinnedFirst
1641
+ const visibleSessions = sessions.filter(
1642
+ (session, index) =>
1643
+ index < sessionLimit || session.id === currentId || pinnedSet.has(session.id),
1644
+ )
1645
+ const hiddenSessions = sessions.length - visibleSessions.length
1646
+ const title = project.title || t('project.ungrouped')
1647
+ const canManage = project.workspaceId !== null && project.workspaceId !== undefined
1648
+ const worktrees = Array.isArray(project.worktrees) ? project.worktrees : []
1649
+ const worktreeBadge =
1650
+ worktrees.length > 1
1651
+ ? h(
1652
+ 'span',
1653
+ {
1654
+ className: 'orca-project-worktrees',
1655
+ title: t('project.worktreesTitle', {
1656
+ list: worktrees.map((entry) => entry.label).join(', '),
1657
+ }),
1658
+ 'aria-label': t('project.worktrees', { n: worktrees.length }),
1659
+ },
1660
+ h(Icon, { name: 'layers', size: 9 }),
1661
+ String(worktrees.length),
1662
+ )
1663
+ : null
1664
+
1665
+ const head = h(
1666
+ 'div',
1667
+ {
1668
+ className: 'orca-project-head',
1669
+ role: 'button',
1670
+ tabIndex: 0,
1671
+ draggable: allowDrag ? true : undefined,
1672
+ style: { paddingLeft: 5 + depth * 13 },
1673
+ onClick: onToggle,
1674
+ onKeyDown: (event) => {
1675
+ if (event.key === 'Enter' || event.key === ' ') {
1676
+ stopEvent(event)
1677
+ onToggle()
1678
+ }
1679
+ },
1680
+ onDragStart: allowDrag && drag ? (event) => drag.start(event, project) : undefined,
1681
+ onDragOver: allowDrag && drag ? (event) => drag.over(event, project) : undefined,
1682
+ onDragLeave: allowDrag && drag ? drag.leave : undefined,
1683
+ onDrop:
1684
+ allowDrag && drag ? (event) => drag.drop(event, project, groupId, siblings) : undefined,
1685
+ onDragEnd: allowDrag && drag ? drag.end : undefined,
1686
+ },
1687
+ h(Chevron, { open: expanded }),
1688
+ h(Icon, {
1689
+ name: expanded ? 'folderOpen' : 'folder',
1690
+ size: 14,
1691
+ className: 'orca-project-folder',
1692
+ }),
1693
+ h('span', { className: 'orca-project-title', title: project.path || title }, title),
1694
+ worktreeBadge,
1695
+ h(CountBadge, null, String(project.sessions.length)),
1696
+ )
1697
+
1698
+ const hover = canManage
1699
+ ? h(
1700
+ 'div',
1701
+ { className: 'orca-project-actions' },
1702
+ h(IconButton, {
1703
+ icon: 'chat',
1704
+ label: t('project.newSession'),
1705
+ onClick: () => actions.startSession(project),
1706
+ }),
1707
+ h(IconButton, {
1708
+ icon: 'more',
1709
+ label: t('action.viewOptions'),
1710
+ onClick: (event) => actions.projectMenu(event, project, groupId),
1711
+ }),
1712
+ )
1713
+ : null
1714
+
1715
+ return h(
1716
+ 'div',
1717
+ { className: 'orca-project', 'data-project-key': project.key },
1718
+ h('div', { className: 'orca-project-row' }, head, hover),
1719
+ expanded
1720
+ ? h(
1721
+ 'div',
1722
+ { className: cx('orca-project-body', guided && 'is-guided') },
1723
+ beforeSessions || null,
1724
+ sessions.length > 0
1725
+ ? visibleSessions.map((session) =>
1726
+ h(SessionRow, {
1727
+ key: session.id,
1728
+ session,
1729
+ project,
1730
+ t,
1731
+ actions,
1732
+ variant: variant === 'tree' ? 'tree' : 'project',
1733
+ depth: depth + 1,
1734
+ pinned: pinnedSet.has(session.id),
1735
+ pinHint: variant === 'orca',
1736
+ archived: archivedSet.has(session.id),
1737
+ current: currentId === session.id,
1738
+ currentId,
1739
+ guided,
1740
+ drag:
1741
+ variant === 'orca' && drag
1742
+ ? {
1743
+ start: (event) => drag.startSession(event, session, project),
1744
+ over: (event) => drag.overSession(event, session, project),
1745
+ drop: (event) =>
1746
+ drag.dropSession(
1747
+ event,
1748
+ session,
1749
+ project,
1750
+ sessions.map((entry) => entry.id),
1751
+ ),
1752
+ end: drag.end,
1753
+ }
1754
+ : undefined,
1755
+ }),
1756
+ )
1757
+ : h('div', { className: 'orca-empty-inline' }, t('empty.sessions')),
1758
+ hiddenSessions > 0
1759
+ ? h(
1760
+ 'button',
1761
+ {
1762
+ type: 'button',
1763
+ className: 'orca-show-more',
1764
+ style: {
1765
+ paddingLeft: (guided ? 10 : 25) + (depth + 1) * (guided ? 12 : 13),
1766
+ },
1767
+ onClick: () => setSessionLimit(sessionLimit + 8),
1768
+ },
1769
+ t('sessions.expand', { n: hiddenSessions }),
1770
+ )
1771
+ : null,
1772
+ )
1773
+ : null,
1774
+ )
1775
+ }
1776
+
1777
+ function PinnedGroup(props) {
1778
+ const { entries, t, actions, collapsed, onToggle, currentId, archivedSet, emptyHint } = props
1779
+ return h(
1780
+ 'section',
1781
+ { className: cx('orca-pinned-group', collapsed && 'is-collapsed') },
1782
+ h(
1783
+ 'div',
1784
+ {
1785
+ className: 'orca-group-head orca-pinned-head',
1786
+ role: 'button',
1787
+ tabIndex: 0,
1788
+ onClick: onToggle,
1789
+ onKeyDown: (event) => {
1790
+ if (event.key === 'Enter' || event.key === ' ') {
1791
+ stopEvent(event)
1792
+ onToggle()
1793
+ }
1794
+ },
1795
+ },
1796
+ h(Chevron, { open: !collapsed }),
1797
+ h(Icon, { name: 'pinFilled', size: 12, className: 'orca-pinned-icon' }),
1798
+ h('span', { className: 'orca-group-title' }, t('pinned.title')),
1799
+ h(CountBadge, null, String(entries.length)),
1800
+ ),
1801
+ collapsed
1802
+ ? null
1803
+ : h(
1804
+ 'div',
1805
+ { className: 'orca-pinned-body' },
1806
+ entries.length > 0
1807
+ ? entries.map((entry) =>
1808
+ h(SessionRow, {
1809
+ key: entry.session.id,
1810
+ session: entry.session,
1811
+ project: entry.project,
1812
+ t,
1813
+ actions,
1814
+ variant: 'pinned',
1815
+ pinned: true,
1816
+ archived: archivedSet.has(entry.session.id),
1817
+ current: currentId === entry.session.id,
1818
+ currentId,
1819
+ }),
1820
+ )
1821
+ : h('div', { className: 'orca-empty-inline' }, emptyHint || t('pinned.empty')),
1822
+ ),
1823
+ )
1824
+ }
1825
+
1826
+ function LooseSessions(props) {
1827
+ const {
1828
+ project,
1829
+ t,
1830
+ actions,
1831
+ collapsed,
1832
+ onToggle,
1833
+ currentId,
1834
+ pinnedSet,
1835
+ pinHint = false,
1836
+ archivedSet,
1837
+ state,
1838
+ migration,
1839
+ onMigrate,
1840
+ } = props
1841
+ if (!project || project.sessions.length === 0) return null
1842
+ const groups =
1843
+ Array.isArray(project.looseGroups) && project.looseGroups.length > 0
1844
+ ? project.looseGroups
1845
+ : [{ key: UNGROUPED, title: t('loose.title'), path: null, sessions: project.sessions }]
1846
+ const hover =
1847
+ migration && migration.candidates.length > 0
1848
+ ? h(
1849
+ 'div',
1850
+ { className: 'orca-group-actions' },
1851
+ h(IconButton, {
1852
+ icon: 'layers',
1853
+ label: t('migration.action'),
1854
+ onClick: onMigrate,
1855
+ }),
1856
+ )
1857
+ : null
1858
+ return h(
1859
+ 'section',
1860
+ { className: 'orca-group orca-group--loose' },
1861
+ h(
1862
+ 'div',
1863
+ { className: 'orca-group-row' },
1864
+ h(
1865
+ 'div',
1866
+ {
1867
+ className: 'orca-group-head',
1868
+ role: 'button',
1869
+ tabIndex: 0,
1870
+ title: t('loose.hint'),
1871
+ onClick: onToggle,
1872
+ onKeyDown: (event) => {
1873
+ if (event.key === 'Enter' || event.key === ' ') {
1874
+ stopEvent(event)
1875
+ onToggle()
1876
+ }
1877
+ },
1878
+ },
1879
+ h(Chevron, { open: !collapsed }),
1880
+ h(Icon, { name: 'chat', size: 12, className: 'orca-group-icon' }),
1881
+ h('span', { className: 'orca-group-title' }, t('loose.title')),
1882
+ h(CountBadge, null, String(project.sessions.length)),
1883
+ ),
1884
+ hover,
1885
+ ),
1886
+ collapsed
1887
+ ? null
1888
+ : h(
1889
+ 'div',
1890
+ { className: 'orca-group-body' },
1891
+ groups.map((group) => {
1892
+ const groupCollapsed = isCollapsed(state, `lg:${group.key}`, false)
1893
+ return h(
1894
+ 'div',
1895
+ { className: 'orca-loose-workspace', key: group.key },
1896
+ h(
1897
+ 'div',
1898
+ {
1899
+ className: 'orca-loose-workspace-head',
1900
+ role: 'button',
1901
+ tabIndex: 0,
1902
+ title: group.path || group.title,
1903
+ onClick: () => actions.toggleGroup(`lg:${group.key}`, false),
1904
+ onKeyDown: (event) => {
1905
+ if (event.key === 'Enter' || event.key === ' ') {
1906
+ stopEvent(event)
1907
+ actions.toggleGroup(`lg:${group.key}`, false)
1908
+ }
1909
+ },
1910
+ },
1911
+ h(Chevron, { open: !groupCollapsed }),
1912
+ h(Icon, { name: 'folder', size: 12, className: 'orca-loose-workspace-icon' }),
1913
+ h('span', { className: 'orca-loose-workspace-title' }, group.title),
1914
+ h(CountBadge, null, String(group.sessions.length)),
1915
+ ),
1916
+ groupCollapsed
1917
+ ? null
1918
+ : h(
1919
+ 'div',
1920
+ { className: 'orca-loose-workspace-body' },
1921
+ group.sessions.map((session) => {
1922
+ const isPinned = pinnedSet.has(session.id)
1923
+ return h(SessionRow, {
1924
+ key: session.id,
1925
+ session,
1926
+ project,
1927
+ t,
1928
+ actions,
1929
+ variant: 'flat',
1930
+ hideProject: !isPinned,
1931
+ pinned: isPinned,
1932
+ pinHint,
1933
+ archived: archivedSet.has(session.id),
1934
+ current: currentId === session.id,
1935
+ currentId,
1936
+ })
1937
+ }),
1938
+ ),
1939
+ )
1940
+ }),
1941
+ ),
1942
+ )
1943
+ }
1944
+
1945
+ function GroupSection(props) {
1946
+ const {
1947
+ group,
1948
+ projects,
1949
+ t,
1950
+ actions,
1951
+ state,
1952
+ toggleGroup,
1953
+ onToggle,
1954
+ drag,
1955
+ currentId,
1956
+ pinnedSet,
1957
+ archivedSet,
1958
+ emptyHint,
1959
+ } = props
1960
+ const groupId = group ? group.id : null
1961
+ const name = group ? group.name : t('group.ungrouped')
1962
+ const collapsed = onToggle.collapsed
1963
+ const canManage = Boolean(group)
1964
+ const projectKeys = projects.map((project) => project.key)
1965
+
1966
+ const head = h(
1967
+ 'div',
1968
+ {
1969
+ className: 'orca-group-head',
1970
+ role: 'button',
1971
+ tabIndex: 0,
1972
+ onClick: () => toggleGroup(),
1973
+ onKeyDown: (event) => {
1974
+ if (event.key === 'Enter' || event.key === ' ') {
1975
+ stopEvent(event)
1976
+ toggleGroup()
1977
+ }
1978
+ },
1979
+ },
1980
+ h(Chevron, { open: !collapsed }),
1981
+ h(Icon, { name: canManage ? 'layers' : 'inbox', size: 12, className: 'orca-group-icon' }),
1982
+ h('span', { className: 'orca-group-title' }, name),
1983
+ h(CountBadge, null, String(projects.length)),
1984
+ )
1985
+
1986
+ const hover = canManage
1987
+ ? h(
1988
+ 'div',
1989
+ { className: 'orca-group-actions' },
1990
+ h(IconButton, {
1991
+ icon: 'more',
1992
+ label: t('action.viewOptions'),
1993
+ onClick: (event) => actions.groupMenu(event, group),
1994
+ }),
1995
+ )
1996
+ : null
1997
+
1998
+ const sectionDrop = drag
1999
+ ? {
2000
+ onDragOver: (event) => {
2001
+ if (dragPayload?.kind !== 'project') return
2002
+ event.preventDefault()
2003
+ event.stopPropagation()
2004
+ setDropIndicator(event.currentTarget, 'group')
2005
+ },
2006
+ onDragLeave: (event) => {
2007
+ if (event.currentTarget.contains(event.relatedTarget)) return
2008
+ if (event.currentTarget.dataset.orcaDrop) delete event.currentTarget.dataset.orcaDrop
2009
+ },
2010
+ onDrop: (event) => {
2011
+ if (dragPayload?.kind !== 'project') return
2012
+ stopEvent(event)
2013
+ drag.dropOnGroup(event, groupId, projectKeys)
2014
+ },
2015
+ }
2016
+ : null
2017
+
2018
+ return h(
2019
+ 'section',
2020
+ { className: cx('orca-group', !group && 'orca-group--ungrouped'), ...sectionDrop },
2021
+ h('div', { className: 'orca-group-row' }, head, hover),
2022
+ collapsed
2023
+ ? null
2024
+ : h(
2025
+ 'div',
2026
+ { className: 'orca-group-body' },
2027
+ projects.length > 0
2028
+ ? projects.map((project) =>
2029
+ h(ProjectRow, {
2030
+ key: project.key,
2031
+ project,
2032
+ t,
2033
+ actions,
2034
+ variant: 'orca',
2035
+ depth: 0,
2036
+ groupId,
2037
+ siblings: projectKeys,
2038
+ collapsed: isCollapsed(
2039
+ state,
2040
+ `p:${project.key}`,
2041
+ project.key === props.currentProjectKey,
2042
+ ),
2043
+ onToggle: () =>
2044
+ actions.toggleProject(project.key, project.key === props.currentProjectKey),
2045
+ allowDrag: Boolean(drag) && !project.isUngrouped,
2046
+ currentId,
2047
+ pinnedSet,
2048
+ archivedSet,
2049
+ drag,
2050
+ }),
2051
+ )
2052
+ : h('div', { className: 'orca-empty-inline' }, emptyHint || t('group.empty')),
2053
+ ),
2054
+ )
2055
+ }
2056
+
2057
+ function TreeNode(props) {
2058
+ const { node, depth, t, actions, state, currentId, pinnedSet, archivedSet } = props
2059
+ const project = node.project
2060
+ const key = `p:${project.key}`
2061
+ const defaultExpanded = true
2062
+ const collapsed = isCollapsed(state, key, defaultExpanded)
2063
+ const children = collapsed
2064
+ ? null
2065
+ : node.children.length > 0
2066
+ ? h(
2067
+ 'div',
2068
+ null,
2069
+ node.children.map((child) =>
2070
+ h(TreeNode, {
2071
+ key: child.project.key,
2072
+ node: child,
2073
+ depth: depth + 1,
2074
+ t,
2075
+ actions,
2076
+ state,
2077
+ currentId,
2078
+ pinnedSet,
2079
+ archivedSet,
2080
+ }),
2081
+ ),
2082
+ )
2083
+ : null
2084
+ return h(ProjectRow, {
2085
+ project,
2086
+ t,
2087
+ actions,
2088
+ variant: 'tree',
2089
+ depth,
2090
+ collapsed,
2091
+ onToggle: () => actions.toggleProject(project.key, defaultExpanded),
2092
+ beforeSessions: children,
2093
+ currentId,
2094
+ pinnedSet,
2095
+ archivedSet,
2096
+ })
2097
+ }
2098
+
2099
+ function EmptyState({ icon, title, hint, actionLabel, onAction }) {
2100
+ return h(
2101
+ 'div',
2102
+ { className: 'orca-empty' },
2103
+ h('div', { className: 'orca-empty-glyph' }, h(Icon, { name: icon, size: 20 })),
2104
+ h('div', { className: 'orca-empty-title' }, title),
2105
+ hint ? h('div', { className: 'orca-empty-hint' }, hint) : null,
2106
+ actionLabel
2107
+ ? h(
2108
+ 'button',
2109
+ {
2110
+ type: 'button',
2111
+ className: 'orca-text-button',
2112
+ onClick: onAction,
2113
+ },
2114
+ actionLabel,
2115
+ )
2116
+ : null,
2117
+ )
2118
+ }
2119
+
2120
+ function OrcaView(props) {
2121
+ const {
2122
+ view,
2123
+ state,
2124
+ t,
2125
+ actions,
2126
+ currentProjectKey,
2127
+ currentId,
2128
+ pinnedSet,
2129
+ archivedSet,
2130
+ drag,
2131
+ } = props
2132
+ const pinnedCollapsed = isCollapsed(state, 'pinned', true)
2133
+ const hasGroups = view.groups.length > 0
2134
+ const activeOnly = state.activeOnly === true
2135
+ const emptyHint = activeOnly ? t('active.empty') : t('group.empty')
2136
+ if (activeOnly && view.pinned.length === 0 && !view.hasProjects) {
2137
+ return h(
2138
+ 'div',
2139
+ { className: 'orca-view' },
2140
+ h(EmptyState, {
2141
+ icon: 'chat',
2142
+ title: t('active.empty'),
2143
+ hint: t('active.hint'),
2144
+ actionLabel: t('active.showAll'),
2145
+ onAction: () => actions.setActiveOnly(false),
2146
+ }),
2147
+ )
2148
+ }
2149
+ return h(
2150
+ 'div',
2151
+ { className: 'orca-view' },
2152
+ h(PinnedGroup, {
2153
+ entries: view.pinned,
2154
+ t,
2155
+ actions,
2156
+ collapsed: pinnedCollapsed,
2157
+ onToggle: () => actions.toggleGroup('pinned', true),
2158
+ currentId,
2159
+ archivedSet,
2160
+ emptyHint: activeOnly ? t('active.empty') : t('pinned.empty'),
2161
+ }),
2162
+ hasGroups
2163
+ ? [
2164
+ ...view.groups.map((group) =>
2165
+ h(GroupSection, {
2166
+ key: group.id,
2167
+ group,
2168
+ projects: group.projects,
2169
+ t,
2170
+ actions,
2171
+ state,
2172
+ toggleGroup: () => actions.toggleGroup(`g:${group.id}`, true),
2173
+ onToggle: { collapsed: isCollapsed(state, `g:${group.id}`, true) },
2174
+ currentProjectKey,
2175
+ currentId,
2176
+ pinnedSet,
2177
+ archivedSet,
2178
+ emptyHint,
2179
+ drag,
2180
+ }),
2181
+ ),
2182
+ h(GroupSection, {
2183
+ key: 'ungrouped',
2184
+ group: null,
2185
+ projects: view.ungroupedProjects,
2186
+ t,
2187
+ actions,
2188
+ state,
2189
+ toggleGroup: () => actions.toggleGroup(`g:${UNGROUPED}`, true),
2190
+ onToggle: { collapsed: isCollapsed(state, `g:${UNGROUPED}`, true) },
2191
+ currentProjectKey,
2192
+ currentId,
2193
+ pinnedSet,
2194
+ archivedSet,
2195
+ emptyHint,
2196
+ drag,
2197
+ }),
2198
+ ]
2199
+ : view.ungroupedProjects.map((project) =>
2200
+ h(ProjectRow, {
2201
+ key: project.key,
2202
+ project,
2203
+ t,
2204
+ actions,
2205
+ variant: 'orca',
2206
+ depth: 0,
2207
+ groupId: null,
2208
+ siblings: view.ungroupedProjects.map((entry) => entry.key),
2209
+ collapsed: isCollapsed(
2210
+ state,
2211
+ `p:${project.key}`,
2212
+ project.key === currentProjectKey,
2213
+ ),
2214
+ onToggle: () =>
2215
+ actions.toggleProject(project.key, project.key === currentProjectKey),
2216
+ allowDrag: Boolean(drag),
2217
+ currentId,
2218
+ pinnedSet,
2219
+ archivedSet,
2220
+ drag,
2221
+ }),
2222
+ ),
2223
+ view.projects
2224
+ .filter((project) => project.isUngrouped)
2225
+ .map((project) =>
2226
+ h(LooseSessions, {
2227
+ key: project.key,
2228
+ project,
2229
+ t,
2230
+ actions,
2231
+ collapsed: isCollapsed(state, 'loose', false),
2232
+ onToggle: () => actions.toggleGroup('loose', false),
2233
+ currentId,
2234
+ pinnedSet,
2235
+ pinHint: true,
2236
+ archivedSet,
2237
+ state,
2238
+ migration: view.migration,
2239
+ onMigrate: actions.migrateLoose,
2240
+ }),
2241
+ ),
2242
+ !view.hasProjects
2243
+ ? h(EmptyState, {
2244
+ icon: activeOnly ? 'chat' : 'folder',
2245
+ title: activeOnly ? t('active.empty') : t('empty.projects'),
2246
+ hint: activeOnly ? t('active.hint') : t('empty.projectsHint'),
2247
+ actionLabel: activeOnly ? t('active.showAll') : t('action.addProject'),
2248
+ onAction: activeOnly
2249
+ ? () => actions.setActiveOnly(false)
2250
+ : (event) => actions.addMenu(event, null),
2251
+ })
2252
+ : null,
2253
+ )
2254
+ }
2255
+
2256
+ function WorkspaceView(props) {
2257
+ const { view, state, t, actions, currentId, pinnedSet, archivedSet } = props
2258
+ const list = React.useMemo(() => {
2259
+ const copy = view.projects.filter((project) => !project.isUngrouped)
2260
+ sortProjects(copy, state, '__workspace__')
2261
+ return copy
2262
+ }, [view.projects, state.orderBy, state.projectOrder])
2263
+ const loose = view.projects.find((project) => project.isUngrouped)
2264
+ return h(
2265
+ 'div',
2266
+ { className: 'orca-view' },
2267
+ list.map((project) =>
2268
+ h(ProjectRow, {
2269
+ key: project.key,
2270
+ project,
2271
+ t,
2272
+ actions,
2273
+ variant: 'workspace',
2274
+ depth: 0,
2275
+ collapsed: isCollapsed(state, `p:${project.key}`, true),
2276
+ onToggle: () => actions.toggleProject(project.key, true),
2277
+ allowDrag: false,
2278
+ currentId,
2279
+ pinnedSet,
2280
+ archivedSet,
2281
+ }),
2282
+ ),
2283
+ loose
2284
+ ? h(LooseSessions, {
2285
+ key: loose.key,
2286
+ project: loose,
2287
+ t,
2288
+ actions,
2289
+ collapsed: isCollapsed(state, 'loose', false),
2290
+ onToggle: () => actions.toggleGroup('loose', false),
2291
+ currentId,
2292
+ pinnedSet,
2293
+ archivedSet,
2294
+ state,
2295
+ migration: view.migration,
2296
+ onMigrate: actions.migrateLoose,
2297
+ })
2298
+ : null,
2299
+ list.length === 0 && !loose
2300
+ ? h(EmptyState, {
2301
+ icon: 'folder',
2302
+ title: t('empty.projects'),
2303
+ hint: t('empty.projectsHint'),
2304
+ actionLabel: t('action.addWorkspace'),
2305
+ onAction: (event) => actions.addMenu(event, null),
2306
+ })
2307
+ : null,
2308
+ )
2309
+ }
2310
+
2311
+ function TreeView(props) {
2312
+ const { view, state, t, actions, currentId, pinnedSet, archivedSet } = props
2313
+ const loose = view.projects.find((project) => project.isUngrouped)
2314
+ return h(
2315
+ 'div',
2316
+ { className: 'orca-view' },
2317
+ view.tree.map((node) =>
2318
+ h(TreeNode, {
2319
+ key: node.project.key,
2320
+ node,
2321
+ depth: 0,
2322
+ t,
2323
+ actions,
2324
+ state,
2325
+ currentId,
2326
+ pinnedSet,
2327
+ archivedSet,
2328
+ }),
2329
+ ),
2330
+ loose
2331
+ ? h(LooseSessions, {
2332
+ key: loose.key,
2333
+ project: loose,
2334
+ t,
2335
+ actions,
2336
+ collapsed: isCollapsed(state, 'loose', false),
2337
+ onToggle: () => actions.toggleGroup('loose', false),
2338
+ currentId,
2339
+ pinnedSet,
2340
+ archivedSet,
2341
+ state,
2342
+ migration: view.migration,
2343
+ onMigrate: actions.migrateLoose,
2344
+ })
2345
+ : null,
2346
+ view.tree.length === 0 && !loose
2347
+ ? h(EmptyState, {
2348
+ icon: 'folder',
2349
+ title: t('empty.projects'),
2350
+ hint: t('empty.projectsHint'),
2351
+ actionLabel: t('action.addWorkspace'),
2352
+ onAction: (event) => actions.addMenu(event, null),
2353
+ })
2354
+ : null,
2355
+ )
2356
+ }
2357
+
2358
+ function FlatView(props) {
2359
+ const { view, t, actions, currentId, archivedSet } = props
2360
+ return h(
2361
+ 'div',
2362
+ { className: 'orca-view orca-flat' },
2363
+ view.flat.map((entry) =>
2364
+ h(SessionRow, {
2365
+ key: entry.session.id,
2366
+ session: entry.session,
2367
+ project: entry.project,
2368
+ t,
2369
+ actions,
2370
+ variant: 'flat',
2371
+ pinned: view.pinned.some((pinned) => pinned.session.id === entry.session.id),
2372
+ archived: archivedSet.has(entry.session.id),
2373
+ current: currentId === entry.session.id,
2374
+ currentId,
2375
+ }),
2376
+ ),
2377
+ view.flat.length === 0
2378
+ ? h(EmptyState, {
2379
+ icon: 'chat',
2380
+ title: t('empty.sessions'),
2381
+ hint: t('empty.projectsHint'),
2382
+ actionLabel: t('action.addWorkspace'),
2383
+ onAction: (event) => actions.addMenu(event, null),
2384
+ })
2385
+ : null,
2386
+ )
2387
+ }
2388
+
2389
+ function SearchView(props) {
2390
+ const { view, t, actions, currentId, archivedSet, query, onClear } = props
2391
+ return h(
2392
+ 'div',
2393
+ { className: 'orca-view orca-search' },
2394
+ view.searchResults.map((entry) =>
2395
+ h(SessionRow, {
2396
+ key: entry.session.id,
2397
+ session: entry.session,
2398
+ project: entry.project,
2399
+ t,
2400
+ actions,
2401
+ variant: 'search',
2402
+ pinned: view.pinned.some((pinned) => pinned.session.id === entry.session.id),
2403
+ archived: archivedSet.has(entry.session.id),
2404
+ current: currentId === entry.session.id,
2405
+ currentId,
2406
+ }),
2407
+ ),
2408
+ view.searchResults.length === 0
2409
+ ? h(EmptyState, {
2410
+ icon: 'search',
2411
+ title: t('empty.noMatches'),
2412
+ hint: query,
2413
+ actionLabel: t('action.clear'),
2414
+ onAction: onClear,
2415
+ })
2416
+ : null,
2417
+ )
2418
+ }
2419
+
2420
+ function Header(props) {
2421
+ const { t, mode, query, searchOpen, count, onSearchToggle, onQuery, onViewMenu, onAddMenu } =
2422
+ props
2423
+ const inputRef = React.useRef(null)
2424
+ React.useEffect(() => {
2425
+ if (searchOpen && inputRef.current) inputRef.current.focus()
2426
+ }, [searchOpen])
2427
+ return h(
2428
+ 'div',
2429
+ { className: 'orca-header' },
2430
+ h(
2431
+ 'div',
2432
+ { className: 'orca-title-row' },
2433
+ h(
2434
+ 'span',
2435
+ { className: 'orca-title' },
2436
+ mode === 'orca'
2437
+ ? t('title.projects')
2438
+ : mode === 'flat'
2439
+ ? t('title.sessions')
2440
+ : t('title.workspaces'),
2441
+ ),
2442
+ count > 0 ? h(CountBadge, null, String(count)) : null,
2443
+ h(
2444
+ 'div',
2445
+ { className: 'orca-head-actions' },
2446
+ h(IconButton, {
2447
+ icon: 'search',
2448
+ label: t('action.search'),
2449
+ active: searchOpen,
2450
+ onClick: onSearchToggle,
2451
+ }),
2452
+ h(IconButton, {
2453
+ icon: 'sliders',
2454
+ label: t('action.viewOptions'),
2455
+ onClick: onViewMenu,
2456
+ }),
2457
+ h(IconButton, {
2458
+ icon: 'plus',
2459
+ label: t('action.add'),
2460
+ onClick: onAddMenu,
2461
+ }),
2462
+ ),
2463
+ ),
2464
+ searchOpen
2465
+ ? h(
2466
+ 'div',
2467
+ { className: 'orca-search-field' },
2468
+ h(Icon, { name: 'search', size: 13, className: 'orca-search-icon' }),
2469
+ h('input', {
2470
+ ref: inputRef,
2471
+ type: 'text',
2472
+ value: query,
2473
+ placeholder: t('placeholder.search'),
2474
+ 'aria-label': t('action.search'),
2475
+ onChange: (event) => onQuery(event.target.value),
2476
+ onKeyDown: (event) => {
2477
+ if (event.key === 'Escape') {
2478
+ stopEvent(event)
2479
+ onSearchToggle(true)
2480
+ }
2481
+ },
2482
+ }),
2483
+ query
2484
+ ? h(IconButton, {
2485
+ icon: 'close',
2486
+ label: t('action.clear'),
2487
+ onClick: () => onQuery(''),
2488
+ size: 20,
2489
+ })
2490
+ : null,
2491
+ )
2492
+ : null,
2493
+ )
2494
+ }
2495
+
2496
+ function MenuLayer(props) {
2497
+ const { menu, onClose } = props
2498
+ const ref = React.useRef(null)
2499
+ React.useEffect(() => {
2500
+ const onPointerDown = (event) => {
2501
+ if (!ref.current || ref.current.contains(event.target)) return
2502
+ onClose()
2503
+ }
2504
+ const onKeyDown = (event) => {
2505
+ if (event.key === 'Escape') onClose()
2506
+ }
2507
+ const onScroll = (event) => {
2508
+ if (ref.current && event.target instanceof Node && ref.current.contains(event.target))
2509
+ return
2510
+ onClose()
2511
+ }
2512
+ document.addEventListener('pointerdown', onPointerDown, true)
2513
+ document.addEventListener('keydown', onKeyDown, true)
2514
+ window.addEventListener('resize', onScroll)
2515
+ window.addEventListener('scroll', onScroll, true)
2516
+ return () => {
2517
+ document.removeEventListener('pointerdown', onPointerDown, true)
2518
+ document.removeEventListener('keydown', onKeyDown, true)
2519
+ window.removeEventListener('resize', onScroll)
2520
+ window.removeEventListener('scroll', onScroll, true)
2521
+ }
2522
+ }, [onClose])
2523
+
2524
+ return h(
2525
+ 'div',
2526
+ {
2527
+ ref,
2528
+ className: 'orca-menu',
2529
+ role: 'menu',
2530
+ style: { left: menu.x, top: menu.y, width: menu.width },
2531
+ },
2532
+ menu.items.map((item, index) => {
2533
+ if (item.divider)
2534
+ return h('div', {
2535
+ key: `divider-${index}`,
2536
+ className: 'orca-menu-divider',
2537
+ role: 'separator',
2538
+ })
2539
+ if (item.section)
2540
+ return h(
2541
+ 'div',
2542
+ { key: `section-${index}`, className: 'orca-menu-section' },
2543
+ item.section,
2544
+ )
2545
+ return h(
2546
+ 'button',
2547
+ {
2548
+ key: `item-${index}`,
2549
+ type: 'button',
2550
+ role: 'menuitem',
2551
+ className: cx(
2552
+ 'orca-menu-item',
2553
+ item.danger && 'is-danger',
2554
+ item.disabled && 'is-disabled',
2555
+ ),
2556
+ disabled: item.disabled,
2557
+ onClick: () => {
2558
+ if (item.disabled) return
2559
+ onClose()
2560
+ if (item.onSelect) item.onSelect()
2561
+ },
2562
+ },
2563
+ h(
2564
+ 'span',
2565
+ { className: 'orca-menu-icon' },
2566
+ item.icon ? h(Icon, { name: item.icon, size: 13 }) : null,
2567
+ ),
2568
+ h('span', { className: 'orca-menu-label' }, item.label),
2569
+ item.badge ? h('span', { className: 'orca-menu-badge' }, item.badge) : null,
2570
+ item.checked
2571
+ ? h(Icon, { name: 'check', size: 13, className: 'orca-menu-check' })
2572
+ : null,
2573
+ )
2574
+ }),
2575
+ )
2576
+ }
2577
+
2578
+ function DialogLayer(props) {
2579
+ const { dialog, t, onCancel, onConfirm } = props
2580
+ const [value, setValue] = React.useState(dialog.value || '')
2581
+ const inputRef = React.useRef(null)
2582
+ const primaryRef = React.useRef(null)
2583
+ React.useEffect(() => {
2584
+ if (dialog.input && inputRef.current) {
2585
+ inputRef.current.focus()
2586
+ inputRef.current.select()
2587
+ } else if (primaryRef.current) {
2588
+ primaryRef.current.focus()
2589
+ }
2590
+ }, [dialog.input])
2591
+ const canConfirm = !dialog.input || value.trim().length > 0
2592
+ const submit = () => {
2593
+ if (!canConfirm) return
2594
+ onConfirm(dialog.input ? value.trim() : null)
2595
+ }
2596
+ return h(
2597
+ 'div',
2598
+ {
2599
+ className: 'orca-dialog-overlay',
2600
+ role: 'presentation',
2601
+ onPointerDown: (event) => {
2602
+ if (event.target === event.currentTarget) onCancel()
2603
+ },
2604
+ },
2605
+ h(
2606
+ 'div',
2607
+ {
2608
+ className: 'orca-dialog',
2609
+ role: 'dialog',
2610
+ 'aria-modal': 'true',
2611
+ 'aria-label': dialog.title,
2612
+ },
2613
+ h('div', { className: 'orca-dialog-title' }, dialog.title),
2614
+ dialog.description
2615
+ ? h('div', { className: 'orca-dialog-description' }, dialog.description)
2616
+ : null,
2617
+ dialog.input
2618
+ ? h('input', {
2619
+ ref: inputRef,
2620
+ className: 'orca-dialog-input',
2621
+ type: 'text',
2622
+ value,
2623
+ placeholder: dialog.placeholder || '',
2624
+ 'aria-label': dialog.title,
2625
+ onChange: (event) => setValue(event.target.value),
2626
+ onKeyDown: (event) => {
2627
+ if (event.key === 'Enter') {
2628
+ stopEvent(event)
2629
+ submit()
2630
+ } else if (event.key === 'Escape') {
2631
+ stopEvent(event)
2632
+ onCancel()
2633
+ }
2634
+ },
2635
+ })
2636
+ : null,
2637
+ h(
2638
+ 'div',
2639
+ { className: 'orca-dialog-actions' },
2640
+ h(
2641
+ 'button',
2642
+ { type: 'button', className: 'orca-button', onClick: onCancel },
2643
+ t('dialog.cancel'),
2644
+ ),
2645
+ h(
2646
+ 'button',
2647
+ {
2648
+ ref: primaryRef,
2649
+ type: 'button',
2650
+ className: cx(
2651
+ 'orca-button',
2652
+ dialog.danger ? 'orca-button--danger' : 'orca-button--primary',
2653
+ ),
2654
+ disabled: !canConfirm,
2655
+ onClick: submit,
2656
+ },
2657
+ dialog.confirm,
2658
+ ),
2659
+ ),
2660
+ ),
2661
+ )
2662
+ }
2663
+
2664
+ function ToastLayer({ toast }) {
2665
+ return h(
2666
+ 'div',
2667
+ { className: cx('orca-toast', toast.tone === 'error' && 'is-error'), role: 'status' },
2668
+ h(Icon, { name: toast.tone === 'error' ? 'warning' : 'check', size: 13 }),
2669
+ h('span', null, toast.message),
2670
+ )
2671
+ }
2672
+
2673
+ const EMPTY_WORKSPACES = {
2674
+ items: [],
2675
+ archivedSessionIds: [],
2676
+ pinnedSessionIds: [],
2677
+ phase: 'pending',
2678
+ }
2679
+ const EMPTY_SESSIONS = { ids: [], byId: {} }
2680
+
2681
+ function OrcaBrowser(props) {
2682
+ const {
2683
+ t,
2684
+ wide,
2685
+ expandSidebar,
2686
+ workspaceSource,
2687
+ sessionSource,
2688
+ sessionStatusSource,
2689
+ layoutSource,
2690
+ searchRequestSource,
2691
+ resolveRepositories,
2692
+ openSession: openSessionService,
2693
+ startSession: startSessionService,
2694
+ openWorkspace: openWorkspaceService,
2695
+ pickDirectory,
2696
+ createWorkspace,
2697
+ deleteWorkspace,
2698
+ pinSession: pinSessionService,
2699
+ unpinSession: unpinSessionService,
2700
+ archiveSession: archiveSessionService,
2701
+ unarchiveSession: unarchiveSessionService,
2702
+ } = props
2703
+
2704
+ const [state, setState] = React.useState(loadState)
2705
+ const [query, setQuery] = React.useState('')
2706
+ const [searchOpen, setSearchOpen] = React.useState(false)
2707
+ const [menu, setMenu] = React.useState(null)
2708
+ const [dialog, setDialog] = React.useState(null)
2709
+ const [toast, setToast] = React.useState(null)
2710
+ const [repoMap, setRepoMap] = React.useState(null)
2711
+ const toastTimer = React.useRef(undefined)
2712
+ const searchRoot = React.useRef(null)
2713
+ const lastSearchRequest = React.useRef(0)
2714
+ const searchFocusPending = React.useRef(false)
2715
+ const searchRequest = useSource(searchRequestSource) || 0
2716
+
2717
+ React.useEffect(() => {
2718
+ if (searchRequest === 0 || searchRequest === lastSearchRequest.current) return
2719
+ lastSearchRequest.current = searchRequest
2720
+ searchFocusPending.current = true
2721
+ setSearchOpen(true)
2722
+ if (wide === false || searchRoot.current?.closest('[inert]')) expandSidebar?.()
2723
+ }, [searchRequest, wide, expandSidebar])
2724
+
2725
+ // Drawer visibility can change while wide stays true; retry only pending focus.
2726
+ React.useEffect(() => {
2727
+ if (!searchFocusPending.current || !searchOpen || wide === false) return
2728
+ const input = searchRoot.current?.querySelector('.orca-search-field input')
2729
+ if (!input || input.closest('[inert]')) return
2730
+ input.focus({ preventScroll: true })
2731
+ searchFocusPending.current = false
2732
+ })
2733
+
2734
+ const workspaceSnapshot = useSource(workspaceSource)
2735
+ const sessionSnapshot = useSource(sessionSource)
2736
+ const sessionStatusSnapshot = useSource(sessionStatusSource)
2737
+ const layoutSnapshot = useSource(layoutSource)
2738
+ const workspaceState = workspaceSnapshot || EMPTY_WORKSPACES
2739
+ const sessionState = sessionSnapshot || EMPTY_SESSIONS
2740
+ const statusMap = sessionStatusSnapshot || EMPTY_STATUS
2741
+ const workspacePathsKey = React.useMemo(
2742
+ () =>
2743
+ (workspaceState.items || [])
2744
+ .map((workspace) => normalizePath(workspace.path))
2745
+ .filter(Boolean)
2746
+ .sort()
2747
+ .join('\n'),
2748
+ [workspaceState],
2749
+ )
2750
+
2751
+ React.useEffect(() => {
2752
+ if (typeof resolveRepositories !== 'function') {
2753
+ setRepoMap(null)
2754
+ return undefined
2755
+ }
2756
+ const paths = workspacePathsKey ? workspacePathsKey.split('\n').filter(Boolean) : []
2757
+ if (paths.length === 0) {
2758
+ setRepoMap(null)
2759
+ return undefined
2760
+ }
2761
+ const controller = new AbortController()
2762
+ let cancelled = false
2763
+ resolveRepositories(paths, controller.signal)
2764
+ .then((repositories) => {
2765
+ if (cancelled) return
2766
+ if (!Array.isArray(repositories)) {
2767
+ setRepoMap(null)
2768
+ return
2769
+ }
2770
+ const next = new Map()
2771
+ for (const repository of repositories) {
2772
+ if (!repository || typeof repository.key !== 'string') continue
2773
+ next.set(normalizePath(repository.path), repository)
2774
+ }
2775
+ setRepoMap(next)
2776
+ })
2777
+ .catch((error) => {
2778
+ if (cancelled || error?.name === 'AbortError') return
2779
+ setRepoMap(null)
2780
+ })
2781
+ return () => {
2782
+ cancelled = true
2783
+ controller.abort()
2784
+ }
2785
+ }, [workspacePathsKey, resolveRepositories])
2786
+
2787
+ React.useEffect(() => {
2788
+ saveState(state)
2789
+ }, [state])
2790
+
2791
+ React.useEffect(
2792
+ () => () => {
2793
+ if (toastTimer.current) window.clearTimeout(toastTimer.current)
2794
+ },
2795
+ [],
2796
+ )
2797
+
2798
+ const showToast = React.useCallback((message, tone) => {
2799
+ if (!message) return
2800
+ setToast({ message, tone: tone || 'info', key: Date.now() })
2801
+ if (toastTimer.current) window.clearTimeout(toastTimer.current)
2802
+ toastTimer.current = window.setTimeout(() => setToast(null), 3000)
2803
+ }, [])
2804
+
2805
+ const fail = React.useCallback(
2806
+ (error, fallbackKey) => {
2807
+ showToast(errorMessage(error) || t(fallbackKey), 'error')
2808
+ },
2809
+ [showToast, t],
2810
+ )
2811
+
2812
+ const currentId = findCurrentId(sessionState)
2813
+ const activePanel =
2814
+ layoutSnapshot &&
2815
+ layoutSnapshot.activePanelId !== null &&
2816
+ layoutSnapshot.activePanelId !== undefined
2817
+ const currentForView = activePanel ? undefined : currentId
2818
+ const view = React.useMemo(
2819
+ () =>
2820
+ buildView({
2821
+ workspaceSnapshot: workspaceState,
2822
+ sessionSnapshot: sessionState,
2823
+ statusMap,
2824
+ state,
2825
+ currentId,
2826
+ query,
2827
+ repoMap,
2828
+ }),
2829
+ [workspaceState, sessionState, statusMap, state, currentId, query, repoMap],
2830
+ )
2831
+ const archivedSet = React.useMemo(() => archivedSetOf(workspaceState), [workspaceState])
2832
+ const pinnedSet = React.useMemo(
2833
+ () =>
2834
+ new Set(
2835
+ Array.isArray(workspaceState.pinnedSessionIds) ? workspaceState.pinnedSessionIds : [],
2836
+ ),
2837
+ [workspaceState],
2838
+ )
2839
+ const currentProject = currentId ? view.projectBySession.get(currentId) : undefined
2840
+ const currentProjectKey = currentProject ? currentProject.key : undefined
2841
+
2842
+ const closeMenu = React.useCallback(() => setMenu(null), [])
2843
+ const closeDialog = React.useCallback(() => setDialog(null), [])
2844
+
2845
+ const openMenuAtRect = React.useCallback((rect, items, width) => {
2846
+ const menuWidth = Math.min(width || 248, Math.max(180, window.innerWidth - 16))
2847
+ const estimated = items.reduce(
2848
+ (sum, item) => sum + (item.section ? 26 : item.divider ? 9 : 31),
2849
+ 8,
2850
+ )
2851
+ const x = Math.min(Math.max(8, rect.right - menuWidth), window.innerWidth - menuWidth - 8)
2852
+ let y = rect.bottom + 4
2853
+ if (y + estimated > window.innerHeight - 8) y = Math.max(8, rect.top - estimated - 4)
2854
+ setMenu({ x, y, width: menuWidth, items, key: Date.now() })
2855
+ }, [])
2856
+
2857
+ const toggleSearch = (force) => {
2858
+ if (force === true || searchOpen) {
2859
+ setSearchOpen(false)
2860
+ setQuery('')
2861
+ return
2862
+ }
2863
+ setSearchOpen(true)
2864
+ }
2865
+
2866
+ const setMode = (mode) => {
2867
+ if (!MODES.includes(mode)) return
2868
+ setState((prev) => ({ ...prev, mode }))
2869
+ }
2870
+ const setOrderBy = (orderBy) => {
2871
+ setState((prev) => ({ ...prev, orderBy }))
2872
+ }
2873
+ const setFilter = (archivedFilter) => {
2874
+ setState((prev) => ({ ...prev, archivedFilter }))
2875
+ }
2876
+ const setActiveOnly = (activeOnly) => {
2877
+ setState((prev) => ({ ...prev, activeOnly: Boolean(activeOnly) }))
2878
+ }
2879
+
2880
+ const toggleGroup = (key, defaultExpanded) => {
2881
+ setState((prev) => toggleCollapsed(prev, key, defaultExpanded))
2882
+ }
2883
+ const toggleProject = (key, isCurrent) => {
2884
+ setState((prev) => toggleCollapsed(prev, `p:${key}`, isCurrent))
2885
+ }
2886
+
2887
+ const openSession = (session, fromVariant) => {
2888
+ if (archivedSet.has(session.id)) {
2889
+ showToast(t('session.archivedNotOpenable'), 'error')
2890
+ return
2891
+ }
2892
+ const project = view.projectBySession.get(session.id)
2893
+ if (project) {
2894
+ const key = `p:${project.key}`
2895
+ setState((prev) => {
2896
+ const collapsed = isCollapsed(prev, key, project.key === currentProjectKey)
2897
+ let groupCollapsed = false
2898
+ if (prev.mode === 'orca' && prev.groups.length > 0) {
2899
+ const assigned = assignmentForProject(prev, project)
2900
+ const valid = assigned && prev.groups.some((group) => group.id === assigned)
2901
+ groupCollapsed = isCollapsed(prev, `g:${valid ? assigned : UNGROUPED}`, true)
2902
+ }
2903
+ if (fromVariant === 'pinned') {
2904
+ if (!collapsed && !groupCollapsed) return prev
2905
+ return { ...prev, collapsed: { ...prev.collapsed, [key]: true } }
2906
+ }
2907
+ if (!collapsed) return prev
2908
+ return { ...prev, collapsed: { ...prev.collapsed, [key]: false } }
2909
+ })
2910
+ }
2911
+ openSessionService(session.id)
2912
+ }
2913
+
2914
+ const revealSession = (session) => {
2915
+ const project = view.projectBySession.get(session.id)
2916
+ if (!project) return
2917
+ const looseGroup = project.isUngrouped
2918
+ ? project.looseGroups?.find((group) =>
2919
+ group.sessions.some((entry) => entry.id === session.id),
2920
+ )
2921
+ : undefined
2922
+ if (project.isUngrouped && !looseGroup) return
2923
+ setState((prev) => {
2924
+ const collapsed = { ...(prev.collapsed || {}) }
2925
+ if (looseGroup) {
2926
+ collapsed.loose = false
2927
+ collapsed[`lg:${looseGroup.key}`] = false
2928
+ return { ...prev, collapsed }
2929
+ }
2930
+ if (prev.mode === 'orca' && Array.isArray(prev.groups) && prev.groups.length > 0) {
2931
+ const assigned = assignmentForProject(prev, project)
2932
+ const valid = assigned && prev.groups.some((group) => group.id === assigned)
2933
+ collapsed[`g:${valid ? assigned : UNGROUPED}`] = false
2934
+ }
2935
+ collapsed[`p:${project.key}`] = false
2936
+ return { ...prev, collapsed }
2937
+ })
2938
+ const selector = looseGroup
2939
+ ? '.orca-group--loose .orca-session--flat[data-session-id]'
2940
+ : '.orca-session--project[data-session-id], .orca-session--tree[data-session-id]'
2941
+ let attempts = 0
2942
+ const scrollToRow = () => {
2943
+ const root = searchRoot.current
2944
+ if (!root) return
2945
+ const row = Array.from(root.querySelectorAll(selector)).find(
2946
+ (element) => element.dataset.sessionId === session.id,
2947
+ )
2948
+ if (row) {
2949
+ row.scrollIntoView({ block: 'nearest' })
2950
+ return
2951
+ }
2952
+ attempts += 1
2953
+ if (attempts < 30) window.setTimeout(scrollToRow, 100)
2954
+ }
2955
+ window.setTimeout(scrollToRow, 50)
2956
+ }
2957
+
2958
+ const pin = async (session) => {
2959
+ try {
2960
+ await pinSessionService(session.id)
2961
+ showToast(t('session.pinned', { name: sessionLabel(session, currentId, t) }))
2962
+ } catch (error) {
2963
+ fail(error, 'toast.pinFailed')
2964
+ }
2965
+ }
2966
+ const unpin = async (session) => {
2967
+ try {
2968
+ await unpinSessionService(session.id)
2969
+ showToast(t('session.unpinned', { name: sessionLabel(session, currentId, t) }))
2970
+ } catch (error) {
2971
+ fail(error, 'toast.pinFailed')
2972
+ }
2973
+ }
2974
+ const archiveById = async (sessionId, sessionTitle, stopActivity) => {
2975
+ try {
2976
+ await archiveSessionService(sessionId, { stopActivity: Boolean(stopActivity) })
2977
+ showToast(t('session.archived', { name: sessionTitle }))
2978
+ } catch (error) {
2979
+ if (!stopActivity && isActiveWorkRefusal(error)) {
2980
+ setDialog({
2981
+ key: `d${Date.now()}`,
2982
+ kind: 'archive-confirm',
2983
+ sessionId,
2984
+ sessionTitle,
2985
+ title: t('session.stopArchiveTitle'),
2986
+ description: t('session.stopArchiveDesc', { name: sessionTitle }),
2987
+ confirm: t('session.stopArchive'),
2988
+ danger: true,
2989
+ })
2990
+ return
2991
+ }
2992
+ fail(error, 'toast.archiveFailed')
2993
+ }
2994
+ }
2995
+ const archive = (session) => {
2996
+ archiveById(session.id, sessionLabel(session, currentId, t), false)
2997
+ }
2998
+ const unarchive = async (session) => {
2999
+ try {
3000
+ await unarchiveSessionService(session.id)
3001
+ showToast(t('session.unarchived', { name: sessionLabel(session, currentId, t) }))
3002
+ } catch (error) {
3003
+ fail(error, 'toast.archiveFailed')
3004
+ }
3005
+ }
3006
+ const copy = async (session) => {
3007
+ try {
3008
+ await navigator.clipboard.writeText(session.id)
3009
+ showToast(t('session.copied'))
3010
+ } catch {
3011
+ showToast(t('session.copyFailed'), 'error')
3012
+ }
3013
+ }
3014
+
3015
+ const startSession = (project) => {
3016
+ if (!project.workspaceId) return
3017
+ startSessionService(project.workspaceId)
3018
+ }
3019
+ const startSessionIn = async (worktree) => {
3020
+ if (!worktree) return
3021
+ try {
3022
+ if (worktree.workspaceId) {
3023
+ startSessionService(worktree.workspaceId)
3024
+ return
3025
+ }
3026
+ const path = normalizePath(worktree.path)
3027
+ const existing = (workspaceState.items || []).find(
3028
+ (workspace) => normalizePath(workspace.path) === path,
3029
+ )
3030
+ if (existing?.workspaceId) {
3031
+ startSessionService(existing.workspaceId)
3032
+ return
3033
+ }
3034
+ const created = await createWorkspace(worktree.path)
3035
+ if (!created?.workspaceId) {
3036
+ showToast(t('toast.workspaceFailed'), 'error')
3037
+ return
3038
+ }
3039
+ startSessionService(created.workspaceId)
3040
+ } catch (error) {
3041
+ fail(error, 'toast.workspaceFailed')
3042
+ }
3043
+ }
3044
+ const openWorkspace = (project) => {
3045
+ if (!project.workspaceId) return
3046
+ openWorkspaceService(project.workspaceId)
3047
+ }
3048
+
3049
+ const addWorkspace = async (groupId) => {
3050
+ try {
3051
+ const path = await pickDirectory()
3052
+ if (!path) return
3053
+ const workspace = await createWorkspace(path)
3054
+ if (!workspace?.path) return
3055
+ const key = normalizePath(workspace.path)
3056
+ if (groupId) {
3057
+ setState((prev) => {
3058
+ const target = view.groups.find((group) => group.id === groupId)
3059
+ const keys = target ? target.projects.map((project) => project.key) : []
3060
+ return moveProjectInOrder(prev, key, groupId, keys, null, 'after')
3061
+ })
3062
+ }
3063
+ showToast(t('project.added', { name: workspace.title || baseName(workspace.path) }))
3064
+ } catch (error) {
3065
+ fail(error, 'toast.workspaceFailed')
3066
+ }
3067
+ }
3068
+
3069
+ const createGroupNow = (name, assignPath) => {
3070
+ const id = nextGroupId()
3071
+ setState((prev) => {
3072
+ let next = createGroup(prev, id, name)
3073
+ if (assignPath) {
3074
+ const project = view.projects.find((entry) => entry.key === assignPath)
3075
+ next = moveProjectInOrder(next, assignPath, id, [], null, 'after', project?.memberPaths)
3076
+ }
3077
+ return next
3078
+ })
3079
+ showToast(t('group.created', { name }))
3080
+ }
3081
+ const renameGroupNow = (id, name) => {
3082
+ setState((prev) => renameGroup(prev, id, name))
3083
+ }
3084
+ const deleteGroupNow = (id) => {
3085
+ setState((prev) => deleteGroup(prev, id))
3086
+ showToast(t('group.deleted'))
3087
+ }
3088
+ const moveProject = (path, groupId, orderedKeys, anchorKey, position) => {
3089
+ if (anchorKey && path === anchorKey) return
3090
+ const project = view.projects.find((entry) => entry.key === path)
3091
+ const previousGroup = project ? project.groupId : null
3092
+ const nextGroup = groupId || null
3093
+ const visible = new Set([...(orderedKeys || []), path])
3094
+ const aliases = new Map()
3095
+ for (const sibling of view.projects) {
3096
+ if (!visible.has(sibling.key)) continue
3097
+ // Keep member order so a legacy alias uses the same slot as sorting.
3098
+ for (const member of sibling.memberPaths) {
3099
+ if (!visible.has(member)) aliases.set(member, sibling.key)
3100
+ }
3101
+ }
3102
+ setState((prev) =>
3103
+ moveProjectInOrder(
3104
+ prev,
3105
+ path,
3106
+ groupId,
3107
+ orderedKeys,
3108
+ anchorKey,
3109
+ position,
3110
+ project?.memberPaths,
3111
+ aliases,
3112
+ ),
3113
+ )
3114
+ if (project && previousGroup !== nextGroup) {
3115
+ const groupName = groupId
3116
+ ? state.groups.find((group) => group.id === groupId)?.name || t('group.ungrouped')
3117
+ : t('group.ungrouped')
3118
+ showToast(t('group.moved', { name: project.title, group: groupName }))
3119
+ }
3120
+ }
3121
+ const moveProjectToGroup = (path, groupId) => {
3122
+ const target = groupId
3123
+ ? view.groups.find((group) => group.id === groupId)?.projects || []
3124
+ : view.ungroupedProjects
3125
+ const keys = target.map((project) => project.key).filter((key) => key !== path)
3126
+ moveProject(path, groupId, keys, null, 'after')
3127
+ }
3128
+ const moveSession = (projectKey, sessionId, orderedIds, anchorId, position) => {
3129
+ if (sessionId === anchorId) return
3130
+ const project = view.projects.find((entry) => entry.key === projectKey)
3131
+ setState((prev) =>
3132
+ moveSessionInOrder(
3133
+ prev,
3134
+ projectKey,
3135
+ sessionId,
3136
+ orderedIds,
3137
+ anchorId,
3138
+ position,
3139
+ project?.memberPaths,
3140
+ ),
3141
+ )
3142
+ }
3143
+
3144
+ const drag = {
3145
+ start(event, project) {
3146
+ if (!event) return
3147
+ dragPayload = { kind: 'project', path: project.key }
3148
+ try {
3149
+ event.dataTransfer.effectAllowed = 'move'
3150
+ event.dataTransfer.setData('text/orca-project', project.key)
3151
+ } catch {
3152
+ // Some browsers refuse custom drag data; the in-memory payload still works.
3153
+ }
3154
+ },
3155
+ startSession(event, session, project) {
3156
+ if (!event) return
3157
+ dragPayload = { kind: 'session', id: session.id, projectKey: project.key }
3158
+ try {
3159
+ event.dataTransfer.effectAllowed = 'move'
3160
+ event.dataTransfer.setData('text/orca-session', session.id)
3161
+ } catch {
3162
+ // The in-memory payload remains the source of truth.
3163
+ }
3164
+ },
3165
+ over(event, project) {
3166
+ if (dragPayload?.kind !== 'project') return
3167
+ if (dragPayload.path === project.key) return
3168
+ event.preventDefault()
3169
+ event.stopPropagation()
3170
+ const row = event.currentTarget.parentElement || event.currentTarget
3171
+ const rect = row.getBoundingClientRect()
3172
+ const position = event.clientY < rect.top + rect.height / 2 ? 'before' : 'after'
3173
+ setDropIndicator(row, position)
3174
+ },
3175
+ drop(event, project, groupId, siblings) {
3176
+ if (dragPayload?.kind !== 'project') return
3177
+ stopEvent(event)
3178
+ const rect = event.currentTarget.getBoundingClientRect()
3179
+ const position = event.clientY < rect.top + rect.height / 2 ? 'before' : 'after'
3180
+ const path = dragPayload.path
3181
+ dragPayload = null
3182
+ clearDropIndicators()
3183
+ if (path && path !== project.key)
3184
+ moveProject(path, groupId, siblings || [], project.key, position)
3185
+ },
3186
+ dropOnGroup(event, groupId, projectKeys) {
3187
+ if (dragPayload?.kind !== 'project') return
3188
+ stopEvent(event)
3189
+ const path = dragPayload.path
3190
+ dragPayload = null
3191
+ clearDropIndicators()
3192
+ if (path) moveProject(path, groupId, projectKeys || [], null, 'after')
3193
+ },
3194
+ overSession(event, session, project) {
3195
+ if (dragPayload?.kind !== 'session') return
3196
+ if (dragPayload.projectKey !== project.key) return
3197
+ if (dragPayload.id === session.id) return
3198
+ event.preventDefault()
3199
+ event.stopPropagation()
3200
+ const row = event.currentTarget.parentElement
3201
+ if (!row) return
3202
+ const rect = row.getBoundingClientRect()
3203
+ const position = event.clientY < rect.top + rect.height / 2 ? 'before' : 'after'
3204
+ setDropIndicator(row, position)
3205
+ },
3206
+ dropSession(event, session, project, orderedIds) {
3207
+ if (dragPayload?.kind !== 'session') return
3208
+ if (dragPayload.projectKey !== project.key) return
3209
+ stopEvent(event)
3210
+ const row = event.currentTarget.parentElement
3211
+ const rect = row ? row.getBoundingClientRect() : { top: 0, height: 0 }
3212
+ const position = event.clientY < rect.top + rect.height / 2 ? 'before' : 'after'
3213
+ const id = dragPayload.id
3214
+ dragPayload = null
3215
+ clearDropIndicators()
3216
+ if (id && id !== session.id)
3217
+ moveSession(project.key, id, orderedIds || [], session.id, position)
3218
+ },
3219
+ leave(event) {
3220
+ if (!event?.currentTarget) return
3221
+ if (event.currentTarget.contains(event.relatedTarget)) return
3222
+ if (event.currentTarget.dataset.orcaDrop) delete event.currentTarget.dataset.orcaDrop
3223
+ },
3224
+ end() {
3225
+ dragPayload = null
3226
+ clearDropIndicators()
3227
+ },
3228
+ }
3229
+
3230
+ const openSessionMenu = (event, session, pinned, archived, variant) => {
3231
+ const rect = event.currentTarget.getBoundingClientRect()
3232
+ const items = []
3233
+ if (!archived) {
3234
+ items.push({
3235
+ label: pinned ? t('pinned.unpin') : t('pinned.pin'),
3236
+ icon: pinned ? 'pinFilled' : 'pin',
3237
+ onSelect: () => (pinned ? unpin(session) : pin(session)),
3238
+ })
3239
+ }
3240
+ if (variant === 'pinned') {
3241
+ items.push({
3242
+ label: t('session.reveal'),
3243
+ icon: 'folderOpen',
3244
+ onSelect: () => revealSession(session),
3245
+ })
3246
+ }
3247
+ items.push({
3248
+ label: t('session.open'),
3249
+ icon: 'open',
3250
+ onSelect: () => openSession(session, variant),
3251
+ })
3252
+ items.push({ divider: true })
3253
+ items.push({ label: t('session.copyId'), icon: 'copy', onSelect: () => copy(session) })
3254
+ items.push(
3255
+ archived
3256
+ ? { label: t('session.unarchive'), icon: 'restore', onSelect: () => unarchive(session) }
3257
+ : {
3258
+ label: t('session.archive'),
3259
+ icon: 'archive',
3260
+ danger: true,
3261
+ onSelect: () => archive(session),
3262
+ },
3263
+ )
3264
+ openMenuAtRect(rect, items)
3265
+ }
3266
+
3267
+ const openMoveMenu = (rect, project) => {
3268
+ const current = project.groupId
3269
+ const items = [
3270
+ { section: t('group.drop') },
3271
+ {
3272
+ label: t('group.ungrouped'),
3273
+ checked: !current,
3274
+ onSelect: () => moveProjectToGroup(project.key, null),
3275
+ },
3276
+ ...state.groups.map((group) => ({
3277
+ label: group.name,
3278
+ checked: current === group.id,
3279
+ onSelect: () => moveProjectToGroup(project.key, group.id),
3280
+ })),
3281
+ { divider: true },
3282
+ {
3283
+ label: t('action.newGroup'),
3284
+ icon: 'groupAdd',
3285
+ onSelect: () => openNewGroupDialog(project.key),
3286
+ },
3287
+ ]
3288
+ openMenuAtRect(rect, items)
3289
+ }
3290
+
3291
+ const openProjectMenu = (event, project) => {
3292
+ const rect = event.currentTarget.getBoundingClientRect()
3293
+ const worktrees = Array.isArray(project.worktrees) ? project.worktrees : []
3294
+ const items = []
3295
+ if (worktrees.length > 1) {
3296
+ items.push({ section: t('project.worktreesSection') })
3297
+ for (const worktree of worktrees) {
3298
+ items.push({
3299
+ label: t('project.newSessionIn', {
3300
+ name: worktree.label === 'main' ? t('project.worktreeMain') : worktree.label,
3301
+ }),
3302
+ icon: 'chat',
3303
+ onSelect: () => startSessionIn(worktree),
3304
+ })
3305
+ }
3306
+ } else {
3307
+ items.push({
3308
+ label: t('project.newSession'),
3309
+ icon: 'chat',
3310
+ onSelect: () => startSession(project),
3311
+ })
3312
+ }
3313
+ items.push(
3314
+ { label: t('project.open'), icon: 'open', onSelect: () => openWorkspace(project) },
3315
+ { divider: true },
3316
+ {
3317
+ label: t('project.move'),
3318
+ icon: 'groupAdd',
3319
+ onSelect: () => openMoveMenu(rect, project),
3320
+ },
3321
+ {
3322
+ label: t('project.rename'),
3323
+ icon: 'edit',
3324
+ onSelect: () => openRenameProjectDialog(project),
3325
+ },
3326
+ {
3327
+ label: t('project.delete'),
3328
+ icon: 'trash',
3329
+ danger: true,
3330
+ onSelect: () => openDeleteProjectDialog(project),
3331
+ },
3332
+ )
3333
+ openMenuAtRect(rect, items)
3334
+ }
3335
+
3336
+ const openGroupMenu = (event, group) => {
3337
+ const rect = event.currentTarget.getBoundingClientRect()
3338
+ openMenuAtRect(rect, [
3339
+ { label: t('group.rename'), icon: 'edit', onSelect: () => openRenameGroupDialog(group) },
3340
+ { label: t('action.addProject'), icon: 'plus', onSelect: () => addWorkspace(group.id) },
3341
+ { divider: true },
3342
+ {
3343
+ label: t('group.delete'),
3344
+ icon: 'trash',
3345
+ danger: true,
3346
+ onSelect: () => openDeleteGroupDialog(group),
3347
+ },
3348
+ ])
3349
+ }
3350
+
3351
+ const openAddMenu = (event, groupId) => {
3352
+ const rect = event.currentTarget.getBoundingClientRect()
3353
+ const items = [
3354
+ {
3355
+ label: state.mode === 'orca' ? t('action.addProject') : t('action.addWorkspace'),
3356
+ icon: 'plus',
3357
+ onSelect: () => addWorkspace(groupId),
3358
+ },
3359
+ ]
3360
+ if (state.mode === 'orca') {
3361
+ items.push({
3362
+ label: t('action.newGroup'),
3363
+ icon: 'groupAdd',
3364
+ onSelect: () => openNewGroupDialog(),
3365
+ })
3366
+ }
3367
+ openMenuAtRect(rect, items)
3368
+ }
3369
+
3370
+ const openViewMenu = (event) => {
3371
+ const rect = event.currentTarget.getBoundingClientRect()
3372
+ const items = [
3373
+ { section: t('section.groupBy') },
3374
+ {
3375
+ label: t('group.workspace'),
3376
+ checked: state.mode === 'workspace',
3377
+ onSelect: () => setMode('workspace'),
3378
+ },
3379
+ {
3380
+ label: t('group.workspaceTree'),
3381
+ checked: state.mode === 'workspace-tree',
3382
+ onSelect: () => setMode('workspace-tree'),
3383
+ },
3384
+ {
3385
+ label: t('group.flat'),
3386
+ checked: state.mode === 'flat',
3387
+ onSelect: () => setMode('flat'),
3388
+ },
3389
+ {
3390
+ label: t('group.orca'),
3391
+ checked: state.mode === 'orca',
3392
+ badge: t('new'),
3393
+ onSelect: () => setMode('orca'),
3394
+ },
3395
+ { divider: true },
3396
+ { section: t('order.label') },
3397
+ {
3398
+ label: t('order.manual'),
3399
+ checked: state.orderBy === 'manual',
3400
+ onSelect: () => setOrderBy('manual'),
3401
+ },
3402
+ {
3403
+ label: t('order.updated'),
3404
+ checked: state.orderBy === 'updated',
3405
+ onSelect: () => setOrderBy('updated'),
3406
+ },
3407
+ { divider: true },
3408
+ { section: t('filter.label') },
3409
+ {
3410
+ label: t('filter.hide'),
3411
+ checked: state.archivedFilter === 'hide',
3412
+ onSelect: () => setFilter('hide'),
3413
+ },
3414
+ {
3415
+ label: t('filter.all'),
3416
+ checked: state.archivedFilter === 'all',
3417
+ onSelect: () => setFilter('all'),
3418
+ },
3419
+ {
3420
+ label: t('filter.only'),
3421
+ checked: state.archivedFilter === 'only',
3422
+ onSelect: () => setFilter('only'),
3423
+ },
3424
+ ]
3425
+ if (state.mode === 'orca') {
3426
+ items.push({ divider: true })
3427
+ items.push({
3428
+ label: t('filter.activeOnly'),
3429
+ icon: 'dot',
3430
+ checked: state.activeOnly === true,
3431
+ onSelect: () => setActiveOnly(!state.activeOnly),
3432
+ })
3433
+ items.push({ divider: true })
3434
+ items.push({
3435
+ label: t('migration.action'),
3436
+ icon: 'layers',
3437
+ disabled: (view.migration?.candidates.length || 0) === 0,
3438
+ onSelect: openMigrationDialog,
3439
+ })
3440
+ if (Object.keys(state.sessionProjects || {}).length > 0) {
3441
+ items.push({
3442
+ label: t('migration.revert'),
3443
+ icon: 'restore',
3444
+ onSelect: revertMigration,
3445
+ })
3446
+ }
3447
+ items.push({ divider: true })
3448
+ items.push({
3449
+ label: t('action.newGroup'),
3450
+ icon: 'groupAdd',
3451
+ onSelect: () => openNewGroupDialog(),
3452
+ })
3453
+ }
3454
+ openMenuAtRect(rect, items, 228)
3455
+ }
3456
+
3457
+ const openMigrationDialog = () => {
3458
+ const migration = view.migration || { candidates: [], unmatched: 0 }
3459
+ if (migration.candidates.length === 0) {
3460
+ showToast(t('migration.none'))
3461
+ return
3462
+ }
3463
+ const projects = new Set(migration.candidates.map((candidate) => candidate.projectId)).size
3464
+ const preview = migration.candidates.map(({ sessionId, projectId }) => ({
3465
+ sessionId,
3466
+ projectId,
3467
+ }))
3468
+ setDialog({
3469
+ key: `d${Date.now()}`,
3470
+ kind: 'migration-confirm',
3471
+ preview,
3472
+ unmatched: migration.unmatched,
3473
+ title: t('migration.title'),
3474
+ description: t('migration.description', {
3475
+ n: migration.candidates.length,
3476
+ projects,
3477
+ unmatched: migration.unmatched,
3478
+ }),
3479
+ confirm: t('migration.confirm', { n: migration.candidates.length }),
3480
+ })
3481
+ }
3482
+ const applyMigration = ({ preview, unmatched }) => {
3483
+ const migration = view.migration
3484
+ const current = new Map(
3485
+ migration?.candidates.map(({ sessionId, projectId }) => [sessionId, projectId]),
3486
+ )
3487
+ if (
3488
+ migration?.unmatched !== unmatched ||
3489
+ current.size !== preview.length ||
3490
+ !preview.every(({ sessionId, projectId }) => current.get(sessionId) === projectId)
3491
+ ) {
3492
+ showToast(t('migration.changed'))
3493
+ return
3494
+ }
3495
+ setState((prev) => {
3496
+ const sessionProjects = { ...(prev.sessionProjects || {}) }
3497
+ for (const { sessionId, projectId } of preview) {
3498
+ sessionProjects[sessionId] = projectId
3499
+ }
3500
+ return { ...prev, sessionProjects }
3501
+ })
3502
+ showToast(t('migration.done', { n: preview.length }))
3503
+ }
3504
+ const revertMigration = () => {
3505
+ setState((prev) => ({ ...prev, sessionProjects: {} }))
3506
+ showToast(t('migration.reverted'))
3507
+ }
3508
+
3509
+ const openNewGroupDialog = (assignPath) => {
3510
+ setDialog({
3511
+ key: `d${Date.now()}`,
3512
+ kind: 'group-new',
3513
+ assignPath,
3514
+ title: t('action.newGroup'),
3515
+ input: true,
3516
+ value: '',
3517
+ placeholder: t('group.namePlaceholder'),
3518
+ confirm: t('dialog.create'),
3519
+ })
3520
+ }
3521
+ const openRenameGroupDialog = (group) => {
3522
+ setDialog({
3523
+ key: `d${Date.now()}`,
3524
+ kind: 'group-rename',
3525
+ id: group.id,
3526
+ title: t('group.rename'),
3527
+ input: true,
3528
+ value: group.name,
3529
+ placeholder: t('group.name'),
3530
+ confirm: t('dialog.save'),
3531
+ })
3532
+ }
3533
+ const openDeleteGroupDialog = (group) => {
3534
+ setDialog({
3535
+ key: `d${Date.now()}`,
3536
+ kind: 'group-delete',
3537
+ id: group.id,
3538
+ title: t('group.delete'),
3539
+ description: t('group.deleteConfirm', { name: group.name }),
3540
+ confirm: t('dialog.delete'),
3541
+ danger: true,
3542
+ })
3543
+ }
3544
+ const openRenameProjectDialog = (project) => {
3545
+ setDialog({
3546
+ key: `d${Date.now()}`,
3547
+ kind: 'project-rename',
3548
+ projectKey: project.key,
3549
+ title: t('project.rename'),
3550
+ input: true,
3551
+ value: project.title || '',
3552
+ placeholder: t('project.renamePlaceholder'),
3553
+ confirm: t('dialog.save'),
3554
+ })
3555
+ }
3556
+ const openDeleteProjectDialog = (project) => {
3557
+ const workspaceIds = Array.isArray(project.workspaceIds)
3558
+ ? project.workspaceIds.filter(Boolean)
3559
+ : project.workspaceId
3560
+ ? [project.workspaceId]
3561
+ : []
3562
+ const many = workspaceIds.length > 1
3563
+ setDialog({
3564
+ key: `d${Date.now()}`,
3565
+ kind: 'project-delete',
3566
+ workspaceIds,
3567
+ title: t('project.delete'),
3568
+ description: many
3569
+ ? t('project.deleteConfirmMany', {
3570
+ name: project.title || t('project.ungrouped'),
3571
+ n: workspaceIds.length,
3572
+ })
3573
+ : t('project.deleteConfirm', {
3574
+ name: project.title || t('project.ungrouped'),
3575
+ }),
3576
+ confirm: t('dialog.delete'),
3577
+ danger: true,
3578
+ })
3579
+ }
3580
+
3581
+ const confirmDialog = (value) => {
3582
+ const current = dialog
3583
+ if (!current) return
3584
+ setDialog(null)
3585
+ if (current.kind === 'group-new') {
3586
+ createGroupNow(value, current.assignPath)
3587
+ } else if (current.kind === 'group-rename') {
3588
+ renameGroupNow(current.id, value)
3589
+ } else if (current.kind === 'group-delete') {
3590
+ deleteGroupNow(current.id)
3591
+ } else if (current.kind === 'project-rename') {
3592
+ setState((prev) => renameProject(prev, current.projectKey, value))
3593
+ } else if (current.kind === 'project-delete') {
3594
+ const workspaceIds = Array.isArray(current.workspaceIds)
3595
+ ? current.workspaceIds
3596
+ : current.workspaceId
3597
+ ? [current.workspaceId]
3598
+ : []
3599
+ Promise.all(workspaceIds.map((workspaceId) => deleteWorkspace(workspaceId))).catch(
3600
+ (error) => fail(error, 'toast.projectFailed'),
3601
+ )
3602
+ } else if (current.kind === 'migration-confirm') {
3603
+ applyMigration(current)
3604
+ } else if (current.kind === 'archive-confirm') {
3605
+ archiveById(current.sessionId, current.sessionTitle, true)
3606
+ }
3607
+ }
3608
+
3609
+ const actions = {
3610
+ open: openSession,
3611
+ pin,
3612
+ unpin,
3613
+ archive,
3614
+ unarchive,
3615
+ copy,
3616
+ menu: openSessionMenu,
3617
+ startSession,
3618
+ openWorkspace,
3619
+ projectMenu: openProjectMenu,
3620
+ groupMenu: openGroupMenu,
3621
+ addMenu: openAddMenu,
3622
+ toggleGroup,
3623
+ toggleProject,
3624
+ setActiveOnly,
3625
+ moveProject,
3626
+ moveSession,
3627
+ migrateLoose: openMigrationDialog,
3628
+ revertLoose: revertMigration,
3629
+ }
3630
+
3631
+ if (wide === false) return null
3632
+
3633
+ const count = state.mode === 'orca' ? view.counts.projects : view.counts.sessions
3634
+
3635
+ const content = h(
3636
+ 'div',
3637
+ { ref: searchRoot, className: 'orca-root', 'data-mode': state.mode },
3638
+ h(Header, {
3639
+ t,
3640
+ mode: state.mode,
3641
+ query,
3642
+ searchOpen,
3643
+ count,
3644
+ onSearchToggle: toggleSearch,
3645
+ onQuery: setQuery,
3646
+ onViewMenu: openViewMenu,
3647
+ onAddMenu: (event) => openAddMenu(event, null),
3648
+ }),
3649
+ h(
3650
+ 'div',
3651
+ { className: 'orca-scroll' },
3652
+ query.trim()
3653
+ ? h(SearchView, {
3654
+ view,
3655
+ t,
3656
+ actions,
3657
+ currentId: currentForView,
3658
+ archivedSet,
3659
+ query,
3660
+ onClear: () => {
3661
+ setQuery('')
3662
+ },
3663
+ })
3664
+ : state.mode === 'orca'
3665
+ ? h(OrcaView, {
3666
+ view,
3667
+ state,
3668
+ t,
3669
+ actions,
3670
+ currentProjectKey,
3671
+ currentId: currentForView,
3672
+ pinnedSet,
3673
+ archivedSet,
3674
+ drag,
3675
+ })
3676
+ : state.mode === 'workspace'
3677
+ ? h(WorkspaceView, {
3678
+ view,
3679
+ state,
3680
+ t,
3681
+ actions,
3682
+ currentProjectKey,
3683
+ currentId: currentForView,
3684
+ pinnedSet,
3685
+ archivedSet,
3686
+ })
3687
+ : state.mode === 'workspace-tree'
3688
+ ? h(TreeView, {
3689
+ view,
3690
+ state,
3691
+ t,
3692
+ actions,
3693
+ currentId: currentForView,
3694
+ pinnedSet,
3695
+ archivedSet,
3696
+ })
3697
+ : h(FlatView, {
3698
+ view,
3699
+ t,
3700
+ actions,
3701
+ currentId: currentForView,
3702
+ archivedSet,
3703
+ }),
3704
+ ),
3705
+ menu ? h(MenuLayer, { key: menu.key, menu, onClose: closeMenu }) : null,
3706
+ dialog
3707
+ ? h(DialogLayer, {
3708
+ key: dialog.key,
3709
+ dialog,
3710
+ t,
3711
+ onCancel: closeDialog,
3712
+ onConfirm: confirmDialog,
3713
+ })
3714
+ : null,
3715
+ toast ? h(ToastLayer, { toast }) : null,
3716
+ )
3717
+
3718
+ return h(
3719
+ SessionStatusContext.Provider,
3720
+ { value: statusMap },
3721
+ h(WorkspacePathContext.Provider, { value: view.workspaceBySession }, content),
3722
+ )
3723
+ }
3724
+
3725
+ const ORCA_CSS = `
3726
+ .orca-root,
3727
+ .orca-root *,
3728
+ .orca-root *::before,
3729
+ .orca-root *::after {
3730
+ box-sizing: border-box;
3731
+ }
3732
+ .orca-root {
3733
+ display: flex;
3734
+ flex-direction: column;
3735
+ min-width: 0;
3736
+ min-height: 0;
3737
+ height: 100%;
3738
+ color: var(--dsw-alias-label-primary);
3739
+ font-size: 14px;
3740
+ line-height: 1.4;
3741
+ }
3742
+ .orca-header {
3743
+ flex: none;
3744
+ padding: 2px 2px 0;
3745
+ }
3746
+ .orca-title-row {
3747
+ display: flex;
3748
+ align-items: center;
3749
+ gap: 6px;
3750
+ height: 32px;
3751
+ min-width: 0;
3752
+ }
3753
+ .orca-title {
3754
+ margin-left: 5px;
3755
+ color: var(--dsw-alias-label-secondary);
3756
+ font-size: 12px;
3757
+ font-weight: 600;
3758
+ letter-spacing: 0.04em;
3759
+ text-transform: uppercase;
3760
+ white-space: nowrap;
3761
+ }
3762
+ .orca-head-actions {
3763
+ display: flex;
3764
+ align-items: center;
3765
+ gap: 1px;
3766
+ margin-left: auto;
3767
+ }
3768
+ .orca-icon-button {
3769
+ display: inline-flex;
3770
+ align-items: center;
3771
+ justify-content: center;
3772
+ width: 26px;
3773
+ height: 26px;
3774
+ padding: 0;
3775
+ border: 0;
3776
+ border-radius: var(--dsw-radius-sm, 6px);
3777
+ background: transparent;
3778
+ color: var(--dsw-alias-label-secondary);
3779
+ cursor: pointer;
3780
+ flex: none;
3781
+ }
3782
+ .orca-icon-button:hover {
3783
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 8%, transparent);
3784
+ color: var(--dsw-alias-label-primary);
3785
+ }
3786
+ .orca-icon-button.is-active {
3787
+ color: var(--dsw-alias-brand-primary);
3788
+ background: color-mix(in srgb, var(--dsw-alias-brand-primary) 11%, transparent);
3789
+ }
3790
+ .orca-icon-button.is-danger {
3791
+ color: var(--dsw-alias-state-error-primary);
3792
+ }
3793
+ .orca-icon-button:disabled {
3794
+ opacity: 0.35;
3795
+ cursor: default;
3796
+ }
3797
+ .orca-icon-button:focus-visible,
3798
+ .orca-project-head:focus-visible,
3799
+ .orca-group-head:focus-visible,
3800
+ .orca-session-main:focus-visible,
3801
+ .orca-text-button:focus-visible,
3802
+ .orca-menu-item:focus-visible,
3803
+ .orca-button:focus-visible {
3804
+ outline: 1px solid var(--dsw-alias-brand-primary);
3805
+ outline-offset: -1px;
3806
+ }
3807
+ .orca-search-field {
3808
+ display: flex;
3809
+ align-items: center;
3810
+ gap: 6px;
3811
+ height: 32px;
3812
+ margin: 3px 0 6px;
3813
+ padding: 0 4px 0 9px;
3814
+ border: 1px solid var(--dsw-alias-border-l1);
3815
+ border-radius: var(--dsw-radius-sm, 6px);
3816
+ background: color-mix(in srgb, var(--dsw-alias-bg-base) 45%, transparent);
3817
+ }
3818
+ .orca-search-field:focus-within {
3819
+ border-color: var(--dsw-alias-brand-primary);
3820
+ }
3821
+ .orca-search-icon {
3822
+ flex: none;
3823
+ color: var(--dsw-alias-label-secondary);
3824
+ }
3825
+ .orca-search-field input {
3826
+ flex: 1;
3827
+ min-width: 0;
3828
+ height: 100%;
3829
+ padding: 0;
3830
+ border: 0;
3831
+ outline: 0;
3832
+ background: transparent;
3833
+ color: var(--dsw-alias-label-primary);
3834
+ font: inherit;
3835
+ font-size: 13px;
3836
+ }
3837
+ .orca-search-field input::placeholder {
3838
+ color: var(--dsw-alias-label-secondary);
3839
+ }
3840
+ .orca-scroll {
3841
+ flex: 1;
3842
+ min-height: 0;
3843
+ overflow-x: hidden;
3844
+ overflow-y: auto;
3845
+ padding: 4px 6px 16px;
3846
+ scrollbar-width: thin;
3847
+ scrollbar-color: var(--dsw-alias-scrollbar-bg-l2, transparent) transparent;
3848
+ }
3849
+ .orca-view {
3850
+ display: flex;
3851
+ flex-direction: column;
3852
+ gap: 1px;
3853
+ }
3854
+ .orca-count {
3855
+ display: inline-flex;
3856
+ align-items: center;
3857
+ justify-content: center;
3858
+ min-width: 17px;
3859
+ height: 17px;
3860
+ padding: 0 5px;
3861
+ border-radius: 999px;
3862
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 7%, transparent);
3863
+ color: var(--dsw-alias-label-secondary);
3864
+ font-size: 10px;
3865
+ font-weight: 500;
3866
+ line-height: 1;
3867
+ flex: none;
3868
+ }
3869
+ .orca-project-worktrees {
3870
+ display: inline-flex;
3871
+ align-items: center;
3872
+ gap: 2px;
3873
+ flex: none;
3874
+ height: 16px;
3875
+ padding: 0 4px;
3876
+ border: 1px solid color-mix(in srgb, var(--dsw-alias-brand-primary) 24%, transparent);
3877
+ border-radius: 999px;
3878
+ background: color-mix(in srgb, var(--dsw-alias-brand-primary) 7%, transparent);
3879
+ color: var(--dsw-alias-brand-primary);
3880
+ font-size: 10px;
3881
+ font-weight: 500;
3882
+ line-height: 1;
3883
+ }
3884
+ .orca-chevron {
3885
+ display: inline-flex;
3886
+ align-items: center;
3887
+ justify-content: center;
3888
+ width: 13px;
3889
+ height: 13px;
3890
+ color: var(--dsw-alias-label-secondary);
3891
+ transform: rotate(0deg);
3892
+ transition: transform 120ms ease;
3893
+ flex: none;
3894
+ }
3895
+ .orca-chevron.is-open {
3896
+ transform: rotate(90deg);
3897
+ }
3898
+ .orca-pinned-group {
3899
+ margin: 2px 0 10px;
3900
+ padding: 4px;
3901
+ border: 1px solid color-mix(in srgb, var(--dsw-alias-brand-primary) 24%, var(--dsw-alias-border-l1));
3902
+ border-radius: 11px;
3903
+ background: color-mix(in srgb, var(--dsw-alias-brand-primary) 6%, transparent);
3904
+ }
3905
+ .orca-pinned-head {
3906
+ height: 30px;
3907
+ padding: 0 6px;
3908
+ border-bottom: 1px solid color-mix(in srgb, var(--dsw-alias-brand-primary) 14%, transparent);
3909
+ border-radius: 7px 7px 0 0;
3910
+ background: color-mix(in srgb, var(--dsw-alias-brand-primary) 5%, transparent);
3911
+ }
3912
+ .orca-pinned-group.is-collapsed .orca-pinned-head {
3913
+ border-bottom-color: transparent;
3914
+ }
3915
+ .orca-pinned-icon {
3916
+ color: var(--dsw-alias-brand-primary);
3917
+ }
3918
+ .orca-pinned-body {
3919
+ display: flex;
3920
+ flex-direction: column;
3921
+ gap: 1px;
3922
+ padding: 4px 1px 1px;
3923
+ }
3924
+ .orca-group {
3925
+ border-radius: 8px;
3926
+ }
3927
+ .orca-group + .orca-group {
3928
+ margin-top: 8px;
3929
+ }
3930
+ .orca-group--loose {
3931
+ margin-top: 8px;
3932
+ }
3933
+ .orca-loose-workspace {
3934
+ display: flex;
3935
+ flex-direction: column;
3936
+ gap: 1px;
3937
+ }
3938
+ .orca-loose-workspace + .orca-loose-workspace {
3939
+ margin-top: 2px;
3940
+ }
3941
+ .orca-loose-workspace-head {
3942
+ display: flex;
3943
+ align-items: center;
3944
+ gap: 5px;
3945
+ height: 28px;
3946
+ padding: 0 8px 0 12px;
3947
+ border-radius: 6px;
3948
+ color: var(--dsw-alias-label-secondary);
3949
+ font-size: 12px;
3950
+ font-weight: 500;
3951
+ cursor: pointer;
3952
+ user-select: none;
3953
+ }
3954
+ .orca-loose-workspace-head:hover {
3955
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 5%, transparent);
3956
+ color: var(--dsw-alias-label-primary);
3957
+ }
3958
+ .orca-loose-workspace-icon {
3959
+ flex: none;
3960
+ opacity: 0.85;
3961
+ }
3962
+ .orca-loose-workspace-title {
3963
+ flex: 1;
3964
+ min-width: 0;
3965
+ overflow: hidden;
3966
+ text-overflow: ellipsis;
3967
+ white-space: nowrap;
3968
+ }
3969
+ .orca-loose-workspace-body {
3970
+ display: flex;
3971
+ flex-direction: column;
3972
+ gap: 1px;
3973
+ margin-left: 8px;
3974
+ }
3975
+ .orca-group-row {
3976
+ position: relative;
3977
+ }
3978
+ .orca-group-head {
3979
+ display: flex;
3980
+ align-items: center;
3981
+ gap: 6px;
3982
+ height: 30px;
3983
+ min-width: 0;
3984
+ padding: 0 8px;
3985
+ border: 1px solid transparent;
3986
+ border-radius: 7px;
3987
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 5%, transparent);
3988
+ color: var(--dsw-alias-label-secondary);
3989
+ font-size: 12px;
3990
+ font-weight: 600;
3991
+ letter-spacing: 0.02em;
3992
+ cursor: pointer;
3993
+ user-select: none;
3994
+ }
3995
+ .orca-group-head:hover {
3996
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 8%, transparent);
3997
+ color: var(--dsw-alias-label-primary);
3998
+ }
3999
+ .orca-group-icon {
4000
+ flex: none;
4001
+ opacity: 0.85;
4002
+ }
4003
+ .orca-group-title {
4004
+ flex: 1;
4005
+ min-width: 0;
4006
+ overflow: hidden;
4007
+ text-overflow: ellipsis;
4008
+ white-space: nowrap;
4009
+ }
4010
+ .orca-group-actions {
4011
+ position: absolute;
4012
+ top: 3px;
4013
+ right: 4px;
4014
+ display: none;
4015
+ align-items: center;
4016
+ background: var(--dsw-specific-sidebar-fill);
4017
+ border-radius: var(--dsw-radius-sm, 6px);
4018
+ }
4019
+ .orca-group-row:hover .orca-group-actions,
4020
+ .orca-group-row:focus-within .orca-group-actions {
4021
+ display: flex;
4022
+ }
4023
+ .orca-group-body {
4024
+ display: flex;
4025
+ flex-direction: column;
4026
+ gap: 1px;
4027
+ margin: 2px 0 0 10px;
4028
+ padding: 2px 0 4px 8px;
4029
+ border-left: 1px solid color-mix(in srgb, var(--dsw-alias-label-primary) 10%, transparent);
4030
+ }
4031
+ .orca-group--ungrouped {
4032
+ margin-top: 10px;
4033
+ }
4034
+ .orca-group--ungrouped .orca-group-head {
4035
+ height: 32px;
4036
+ padding-top: 3px;
4037
+ border-top: 1px solid var(--dsw-alias-border-l1);
4038
+ border-radius: 0;
4039
+ background: transparent;
4040
+ }
4041
+ .orca-group--ungrouped .orca-group-head:hover {
4042
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 5%, transparent);
4043
+ }
4044
+ .orca-project {
4045
+ display: flex;
4046
+ flex-direction: column;
4047
+ gap: 1px;
4048
+ }
4049
+ .orca-project + .orca-project {
4050
+ margin-top: 1px;
4051
+ }
4052
+ .orca-project-row {
4053
+ position: relative;
4054
+ }
4055
+ .orca-project-head {
4056
+ display: flex;
4057
+ align-items: center;
4058
+ gap: 6px;
4059
+ height: 32px;
4060
+ padding: 0 56px 0 4px;
4061
+ border-radius: var(--dsw-radius-sm, 6px);
4062
+ color: var(--dsw-alias-label-primary);
4063
+ font-size: 14px;
4064
+ font-weight: 500;
4065
+ line-height: 20px;
4066
+ cursor: pointer;
4067
+ user-select: none;
4068
+ }
4069
+ .orca-project-head:hover {
4070
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 7%, transparent);
4071
+ }
4072
+ .orca-project-folder {
4073
+ flex: none;
4074
+ color: var(--dsw-alias-label-secondary);
4075
+ }
4076
+ .orca-project-title {
4077
+ flex: 1;
4078
+ min-width: 0;
4079
+ overflow: hidden;
4080
+ text-overflow: ellipsis;
4081
+ white-space: nowrap;
4082
+ }
4083
+ .orca-project-actions {
4084
+ position: absolute;
4085
+ top: 3px;
4086
+ right: 4px;
4087
+ display: none;
4088
+ align-items: center;
4089
+ gap: 1px;
4090
+ background: var(--dsw-specific-sidebar-fill);
4091
+ border-radius: var(--dsw-radius-sm, 6px);
4092
+ }
4093
+ .orca-project-row:hover .orca-project-actions,
4094
+ .orca-project-row:focus-within .orca-project-actions {
4095
+ display: flex;
4096
+ }
4097
+ .orca-project-body {
4098
+ display: flex;
4099
+ flex-direction: column;
4100
+ gap: 1px;
4101
+ padding: 1px 0 2px;
4102
+ }
4103
+ .orca-project-body.is-guided {
4104
+ margin-left: 14px;
4105
+ padding: 2px 0 4px 6px;
4106
+ border-left: 1px solid color-mix(in srgb, var(--dsw-alias-label-primary) 8%, transparent);
4107
+ }
4108
+ .orca-session {
4109
+ position: relative;
4110
+ display: flex;
4111
+ align-items: stretch;
4112
+ min-width: 0;
4113
+ min-height: 50px;
4114
+ margin: 2px 0;
4115
+ border: 1px solid color-mix(in srgb, var(--dsw-alias-label-primary) 8%, transparent);
4116
+ border-radius: 8px;
4117
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 2.5%, transparent);
4118
+ }
4119
+ .orca-session:hover {
4120
+ border-color: color-mix(in srgb, var(--dsw-alias-label-primary) 14%, transparent);
4121
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 4.5%, transparent);
4122
+ }
4123
+ .orca-session.is-current {
4124
+ border-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 35%, transparent);
4125
+ background: color-mix(in srgb, var(--dsw-alias-brand-primary) 11%, transparent);
4126
+ box-shadow: inset 2px 0 0 var(--dsw-alias-brand-primary);
4127
+ }
4128
+ .orca-session-main {
4129
+ display: flex;
4130
+ flex-direction: column;
4131
+ justify-content: center;
4132
+ gap: 3px;
4133
+ min-width: 0;
4134
+ width: 100%;
4135
+ padding: 5px 8px;
4136
+ border-radius: 7px;
4137
+ color: var(--dsw-alias-label-primary);
4138
+ font-size: 14px;
4139
+ line-height: 20px;
4140
+ cursor: pointer;
4141
+ user-select: none;
4142
+ }
4143
+ .orca-session-line {
4144
+ display: flex;
4145
+ align-items: center;
4146
+ gap: 6px;
4147
+ min-width: 0;
4148
+ padding-right: 52px;
4149
+ }
4150
+ .orca-session-subline {
4151
+ display: flex;
4152
+ align-items: center;
4153
+ gap: 5px;
4154
+ min-width: 0;
4155
+ padding-left: 15px;
4156
+ overflow: hidden;
4157
+ }
4158
+ .orca-session-title {
4159
+ flex: 1;
4160
+ min-width: 0;
4161
+ overflow: hidden;
4162
+ text-overflow: ellipsis;
4163
+ white-space: nowrap;
4164
+ }
4165
+ .orca-session-pin {
4166
+ flex: none;
4167
+ color: var(--dsw-alias-brand-primary);
4168
+ }
4169
+ .orca-session-project {
4170
+ display: inline-flex;
4171
+ align-items: center;
4172
+ gap: 3px;
4173
+ flex: none;
4174
+ max-width: 46%;
4175
+ height: 16px;
4176
+ padding: 0 5px;
4177
+ border: 1px solid color-mix(in srgb, var(--dsw-alias-label-primary) 11%, transparent);
4178
+ border-radius: 999px;
4179
+ overflow: hidden;
4180
+ color: var(--dsw-alias-label-secondary);
4181
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 4%, transparent);
4182
+ font-size: 10px;
4183
+ line-height: 14px;
4184
+ }
4185
+ .orca-session-project-icon {
4186
+ flex: none;
4187
+ }
4188
+ .orca-session-meta {
4189
+ min-width: 0;
4190
+ overflow: hidden;
4191
+ text-overflow: ellipsis;
4192
+ white-space: nowrap;
4193
+ color: inherit;
4194
+ font-size: 10px;
4195
+ }
4196
+ .orca-worktree {
4197
+ display: inline-flex;
4198
+ align-items: center;
4199
+ flex: none;
4200
+ max-width: 92px;
4201
+ height: 16px;
4202
+ padding: 0 5px;
4203
+ border: 1px solid color-mix(in srgb, var(--dsw-alias-label-primary) 12%, transparent);
4204
+ border-radius: 999px;
4205
+ overflow: hidden;
4206
+ text-overflow: ellipsis;
4207
+ white-space: nowrap;
4208
+ color: var(--dsw-alias-label-secondary);
4209
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 4%, transparent);
4210
+ font-size: 10px;
4211
+ line-height: 14px;
4212
+ }
4213
+ .orca-worktree.is-main {
4214
+ color: var(--dsw-alias-label-secondary);
4215
+ }
4216
+ .orca-worktree:not(.is-main) {
4217
+ color: var(--dsw-alias-brand-primary);
4218
+ border-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 26%, transparent);
4219
+ background: color-mix(in srgb, var(--dsw-alias-brand-primary) 8%, transparent);
4220
+ }
4221
+ .orca-session-hint {
4222
+ display: inline-flex;
4223
+ align-items: center;
4224
+ gap: 2px;
4225
+ flex: none;
4226
+ height: 16px;
4227
+ padding: 0 4px;
4228
+ border: 1px solid var(--dsw-alias-border-l1);
4229
+ border-radius: 999px;
4230
+ color: var(--dsw-alias-label-secondary);
4231
+ font-size: 10px;
4232
+ line-height: 1;
4233
+ }
4234
+ .orca-session-hint.is-archived {
4235
+ color: var(--dsw-alias-state-warn-primary);
4236
+ border-color: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 35%, transparent);
4237
+ }
4238
+ .orca-session.is-pinned-ref {
4239
+ opacity: 0.55;
4240
+ }
4241
+ .orca-session.is-archived {
4242
+ opacity: 0.45;
4243
+ }
4244
+ .orca-session-actions {
4245
+ position: absolute;
4246
+ top: 5px;
4247
+ right: 4px;
4248
+ display: none;
4249
+ align-items: center;
4250
+ gap: 1px;
4251
+ background: var(--dsw-specific-sidebar-fill);
4252
+ border-radius: var(--dsw-radius-sm, 6px);
4253
+ }
4254
+ .orca-project-actions .orca-icon-button,
4255
+ .orca-session-actions .orca-icon-button,
4256
+ .orca-group-actions .orca-icon-button {
4257
+ width: 24px;
4258
+ height: 24px;
4259
+ }
4260
+ .orca-session:hover .orca-session-actions,
4261
+ .orca-session:focus-within .orca-session-actions {
4262
+ display: flex;
4263
+ }
4264
+ .orca-session:hover .orca-session-hint,
4265
+ .orca-session:focus-within .orca-session-hint {
4266
+ visibility: hidden;
4267
+ }
4268
+ .orca-status-dot {
4269
+ width: 9px;
4270
+ height: 9px;
4271
+ border-radius: 50%;
4272
+ background: var(--dsw-alias-state-idle-primary);
4273
+ opacity: 0.5;
4274
+ flex: none;
4275
+ }
4276
+ .orca-status-dot.is-completed {
4277
+ background: var(--dsw-alias-state-success-primary);
4278
+ box-shadow: 0 0 0 2px color-mix(in srgb, var(--dsw-alias-state-success-primary) 16%, transparent);
4279
+ opacity: 1;
4280
+ }
4281
+ .orca-status-dot.is-pending {
4282
+ background: var(--dsw-alias-state-warn-primary);
4283
+ opacity: 1;
4284
+ }
4285
+ .orca-status-dot.is-archived {
4286
+ background: var(--dsw-alias-state-idle-primary);
4287
+ opacity: 0.35;
4288
+ }
4289
+ .orca-spinner {
4290
+ width: 12px;
4291
+ height: 12px;
4292
+ border: 2px solid color-mix(in srgb, var(--dsw-alias-state-warn-primary) 22%, transparent);
4293
+ border-top-color: var(--dsw-alias-state-warn-primary);
4294
+ border-radius: 50%;
4295
+ animation: orca-spin 0.85s linear infinite;
4296
+ flex: none;
4297
+ }
4298
+ @keyframes orca-spin {
4299
+ to { transform: rotate(360deg); }
4300
+ }
4301
+ .orca-empty-inline {
4302
+ padding: 8px 12px;
4303
+ color: var(--dsw-alias-label-secondary);
4304
+ font-size: 12px;
4305
+ line-height: 1.5;
4306
+ }
4307
+ .orca-show-more {
4308
+ align-self: flex-start;
4309
+ margin: 1px 0 3px;
4310
+ padding-top: 3px;
4311
+ padding-right: 8px;
4312
+ padding-bottom: 3px;
4313
+ border: 0;
4314
+ border-radius: var(--dsw-radius-sm, 6px);
4315
+ background: transparent;
4316
+ color: var(--dsw-alias-label-secondary);
4317
+ font: inherit;
4318
+ font-size: 12px;
4319
+ text-align: left;
4320
+ cursor: pointer;
4321
+ }
4322
+ .orca-show-more:hover {
4323
+ color: var(--dsw-alias-label-primary);
4324
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent);
4325
+ }
4326
+ .orca-empty {
4327
+ display: flex;
4328
+ flex-direction: column;
4329
+ align-items: center;
4330
+ gap: 6px;
4331
+ padding: 28px 12px;
4332
+ text-align: center;
4333
+ color: var(--dsw-alias-label-secondary);
4334
+ }
4335
+ .orca-empty-glyph {
4336
+ display: flex;
4337
+ align-items: center;
4338
+ justify-content: center;
4339
+ width: 40px;
4340
+ height: 40px;
4341
+ margin-bottom: 2px;
4342
+ border: 1px solid var(--dsw-alias-border-l1);
4343
+ border-radius: 50%;
4344
+ color: var(--dsw-alias-label-secondary);
4345
+ }
4346
+ .orca-empty-title {
4347
+ color: var(--dsw-alias-label-primary);
4348
+ font-size: 14px;
4349
+ font-weight: 500;
4350
+ }
4351
+ .orca-empty-hint {
4352
+ max-width: 190px;
4353
+ font-size: 12px;
4354
+ line-height: 1.5;
4355
+ }
4356
+ .orca-text-button {
4357
+ margin-top: 2px;
4358
+ padding: 5px 9px;
4359
+ border: 0;
4360
+ border-radius: var(--dsw-radius-sm, 6px);
4361
+ background: transparent;
4362
+ color: var(--dsw-alias-brand-primary);
4363
+ font: inherit;
4364
+ font-size: 13px;
4365
+ cursor: pointer;
4366
+ }
4367
+ .orca-text-button:hover {
4368
+ background: color-mix(in srgb, var(--dsw-alias-brand-primary) 9%, transparent);
4369
+ }
4370
+ .orca-menu {
4371
+ position: fixed;
4372
+ z-index: 95;
4373
+ max-height: 72vh;
4374
+ overflow-y: auto;
4375
+ padding: 4px;
4376
+ border: 1px solid var(--dsw-alias-border-l1);
4377
+ border-radius: 10px;
4378
+ background: var(--dsw-alias-bg-layer-1);
4379
+ box-shadow: 0 10px 30px color-mix(in srgb, var(--dsw-alias-label-primary) 18%, transparent);
4380
+ font-size: 13px;
4381
+ scrollbar-width: thin;
4382
+ }
4383
+ .orca-menu-section {
4384
+ padding: 8px 8px 4px;
4385
+ color: var(--dsw-alias-label-secondary);
4386
+ font-size: 11px;
4387
+ font-weight: 600;
4388
+ letter-spacing: 0.04em;
4389
+ text-transform: uppercase;
4390
+ }
4391
+ .orca-menu-item {
4392
+ display: flex;
4393
+ align-items: center;
4394
+ gap: 8px;
4395
+ width: 100%;
4396
+ height: 32px;
4397
+ padding: 0 8px;
4398
+ border: 0;
4399
+ border-radius: var(--dsw-radius-sm, 6px);
4400
+ background: transparent;
4401
+ color: var(--dsw-alias-label-primary);
4402
+ font: inherit;
4403
+ font-size: 13px;
4404
+ text-align: left;
4405
+ cursor: pointer;
4406
+ }
4407
+ .orca-menu-item:hover {
4408
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 7%, transparent);
4409
+ }
4410
+ .orca-menu-item.is-danger {
4411
+ color: var(--dsw-alias-state-error-primary);
4412
+ }
4413
+ .orca-menu-item.is-disabled {
4414
+ opacity: 0.4;
4415
+ cursor: default;
4416
+ }
4417
+ .orca-menu-icon {
4418
+ display: inline-flex;
4419
+ align-items: center;
4420
+ justify-content: center;
4421
+ width: 15px;
4422
+ flex: none;
4423
+ color: var(--dsw-alias-label-secondary);
4424
+ }
4425
+ .orca-menu-item.is-danger .orca-menu-icon {
4426
+ color: inherit;
4427
+ }
4428
+ .orca-menu-label {
4429
+ flex: 1;
4430
+ min-width: 0;
4431
+ overflow: hidden;
4432
+ text-overflow: ellipsis;
4433
+ white-space: nowrap;
4434
+ }
4435
+ .orca-menu-badge {
4436
+ flex: none;
4437
+ padding: 0 4px;
4438
+ border: 1px solid var(--dsw-alias-border-l1);
4439
+ border-radius: 999px;
4440
+ color: var(--dsw-alias-label-secondary);
4441
+ font-size: 9px;
4442
+ line-height: 14px;
4443
+ text-transform: none;
4444
+ letter-spacing: 0;
4445
+ }
4446
+ .orca-menu-check {
4447
+ flex: none;
4448
+ color: var(--dsw-alias-brand-primary);
4449
+ }
4450
+ .orca-menu-divider {
4451
+ height: 1px;
4452
+ margin: 4px 2px;
4453
+ background: var(--dsw-alias-border-l1);
4454
+ }
4455
+ .orca-dialog-overlay {
4456
+ position: fixed;
4457
+ inset: 0;
4458
+ z-index: 100;
4459
+ display: flex;
4460
+ align-items: center;
4461
+ justify-content: center;
4462
+ padding: 20px;
4463
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 24%, transparent);
4464
+ }
4465
+ .orca-dialog {
4466
+ width: min(340px, calc(100vw - 32px));
4467
+ padding: 16px;
4468
+ border: 1px solid var(--dsw-alias-border-l1);
4469
+ border-radius: 12px;
4470
+ background: var(--dsw-alias-bg-layer-1);
4471
+ box-shadow: 0 14px 40px color-mix(in srgb, var(--dsw-alias-label-primary) 22%, transparent);
4472
+ }
4473
+ .orca-dialog-title {
4474
+ color: var(--dsw-alias-label-primary);
4475
+ font-size: 14px;
4476
+ font-weight: 600;
4477
+ line-height: 1.4;
4478
+ }
4479
+ .orca-dialog-description {
4480
+ margin-top: 8px;
4481
+ color: var(--dsw-alias-label-secondary);
4482
+ font-size: 13px;
4483
+ line-height: 1.55;
4484
+ }
4485
+ .orca-dialog-input {
4486
+ width: 100%;
4487
+ height: 34px;
4488
+ margin-top: 13px;
4489
+ padding: 0 9px;
4490
+ border: 1px solid var(--dsw-alias-border-l1);
4491
+ border-radius: var(--dsw-radius-sm, 6px);
4492
+ outline: 0;
4493
+ background: var(--dsw-alias-bg-base);
4494
+ color: var(--dsw-alias-label-primary);
4495
+ font: inherit;
4496
+ font-size: 14px;
4497
+ }
4498
+ .orca-dialog-input:focus {
4499
+ border-color: var(--dsw-alias-brand-primary);
4500
+ }
4501
+ .orca-dialog-actions {
4502
+ display: flex;
4503
+ justify-content: flex-end;
4504
+ gap: 8px;
4505
+ margin-top: 16px;
4506
+ }
4507
+ .orca-button {
4508
+ height: 30px;
4509
+ padding: 0 13px;
4510
+ border: 1px solid var(--dsw-alias-border-l1);
4511
+ border-radius: var(--dsw-radius-sm, 6px);
4512
+ background: transparent;
4513
+ color: var(--dsw-alias-label-primary);
4514
+ font: inherit;
4515
+ font-size: 13px;
4516
+ cursor: pointer;
4517
+ }
4518
+ .orca-button:hover {
4519
+ background: color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent);
4520
+ }
4521
+ .orca-button--primary {
4522
+ border-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 35%, transparent);
4523
+ background: color-mix(in srgb, var(--dsw-alias-brand-primary) 12%, transparent);
4524
+ color: var(--dsw-alias-brand-primary);
4525
+ }
4526
+ .orca-button--danger {
4527
+ border-color: color-mix(in srgb, var(--dsw-alias-state-error-primary) 35%, transparent);
4528
+ background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 10%, transparent);
4529
+ color: var(--dsw-alias-state-error-primary);
4530
+ }
4531
+ .orca-button:disabled {
4532
+ opacity: 0.45;
4533
+ cursor: default;
4534
+ }
4535
+ .orca-toast {
4536
+ position: fixed;
4537
+ left: 12px;
4538
+ bottom: 14px;
4539
+ z-index: 110;
4540
+ display: flex;
4541
+ align-items: flex-start;
4542
+ gap: 7px;
4543
+ width: 244px;
4544
+ max-width: calc(100vw - 24px);
4545
+ padding: 9px 10px;
4546
+ border: 1px solid var(--dsw-alias-border-l1);
4547
+ border-radius: 8px;
4548
+ background: var(--dsw-alias-bg-layer-1);
4549
+ box-shadow: 0 8px 24px color-mix(in srgb, var(--dsw-alias-label-primary) 18%, transparent);
4550
+ color: var(--dsw-alias-label-primary);
4551
+ font-size: 12px;
4552
+ line-height: 1.45;
4553
+ }
4554
+ .orca-toast.is-error {
4555
+ color: var(--dsw-alias-state-error-primary);
4556
+ }
4557
+ .orca-project-row[data-orca-drop="before"]::before,
4558
+ .orca-project-row[data-orca-drop="after"]::after,
4559
+ .orca-session[data-orca-drop="before"]::before,
4560
+ .orca-session[data-orca-drop="after"]::after {
4561
+ content: "";
4562
+ position: absolute;
4563
+ left: 6px;
4564
+ right: 6px;
4565
+ z-index: 2;
4566
+ height: 2px;
4567
+ border-radius: 2px;
4568
+ background: var(--dsw-alias-brand-primary);
4569
+ pointer-events: none;
4570
+ }
4571
+ .orca-project-row[data-orca-drop="before"]::before,
4572
+ .orca-session[data-orca-drop="before"]::before {
4573
+ top: -1px;
4574
+ }
4575
+ .orca-project-row[data-orca-drop="after"]::after,
4576
+ .orca-session[data-orca-drop="after"]::after {
4577
+ bottom: -1px;
4578
+ }
4579
+ [data-orca-drop="group"] {
4580
+ background: color-mix(in srgb, var(--dsw-alias-brand-primary) 9%, transparent);
4581
+ box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--dsw-alias-brand-primary) 45%, transparent);
4582
+ }
4583
+ @media (hover: none) {
4584
+ .orca-project-actions,
4585
+ .orca-session-actions,
4586
+ .orca-group-actions {
4587
+ display: flex;
4588
+ }
4589
+ .orca-session-hint {
4590
+ display: none;
4591
+ }
4592
+ }
4593
+ @media (prefers-reduced-motion: reduce) {
4594
+ .orca-chevron,
4595
+ .orca-spinner {
4596
+ transition: none;
4597
+ animation: none;
4598
+ }
4599
+ }
4600
+ `
4601
+
4602
+ function installStyles() {
4603
+ const existing = document.querySelector('style[data-orca-projects="styles"]')
4604
+ if (existing?.parentNode) existing.parentNode.removeChild(existing)
4605
+ const tag = document.createElement('style')
4606
+ tag.dataset.orcaProjects = 'styles'
4607
+ tag.textContent = ORCA_CSS
4608
+ document.head.appendChild(tag)
4609
+ return () => {
4610
+ if (tag.parentNode) tag.parentNode.removeChild(tag)
4611
+ }
4612
+ }
4613
+
4614
+ const inject = [
4615
+ 'slots',
4616
+ 'locale',
4617
+ 'workspaces',
4618
+ 'sessions',
4619
+ 'uiSession',
4620
+ 'uiWorkspace',
4621
+ 'layout',
4622
+ 'connection',
4623
+ ]
4624
+
4625
+ function apply(ctx) {
4626
+ const workspaces = ctx.get('workspaces')
4627
+ const sessions = ctx.get('sessions')
4628
+ const uiSession = ctx.get('uiSession')
4629
+ const uiWorkspace = ctx.get('uiWorkspace')
4630
+ const layout = ctx.get('layout')
4631
+
4632
+ const workspaceSource = {
4633
+ getSnapshot: () => workspaces.list.getSnapshot(),
4634
+ subscribe: (listener) => workspaces.list.subscribe(listener),
4635
+ }
4636
+ const sessionSource = {
4637
+ getSnapshot: () => sessions.list.getSnapshot(),
4638
+ subscribe: (listener) => sessions.list.subscribe(listener),
4639
+ }
4640
+ const sessionStatusSource = uiSession?.sessionStatus
4641
+ ? {
4642
+ getSnapshot: () => uiSession.sessionStatus.getSnapshot(),
4643
+ subscribe: (listener) => uiSession.sessionStatus.subscribe(listener),
4644
+ }
4645
+ : undefined
4646
+ const layoutSource = layout
4647
+ ? {
4648
+ getSnapshot: () => layout.panelInfo.getSnapshot(),
4649
+ subscribe: (listener) => layout.panelInfo.subscribe(listener),
4650
+ }
4651
+ : undefined
4652
+ ctx.effect(() => ctx.locale.register(NS, { en, zh }), 'orca-projects: dictionaries')
4653
+ ctx.effect(() => installStyles(), 'orca-projects: styles')
4654
+
4655
+ let searchRequest = 0
4656
+ const searchListeners = new Set()
4657
+ const searchRequestSource = {
4658
+ getSnapshot: () => searchRequest,
4659
+ subscribe: (listener) => {
4660
+ searchListeners.add(listener)
4661
+ return () => searchListeners.delete(listener)
4662
+ },
4663
+ }
4664
+ ctx.effect(() => {
4665
+ let entry
4666
+ let unsubscribe = () => {}
4667
+ const reconcile = () => {
4668
+ // Raw entries retain the shadowed DSH browser's injected shortcut source.
4669
+ const next = ctx.slots
4670
+ .entries?.('sidebar.workspaces')
4671
+ .find(
4672
+ (candidate) =>
4673
+ candidate.locale === 'workspace' && typeof candidate.inject === 'function',
4674
+ )
4675
+ if (next === entry) return
4676
+ unsubscribe()
4677
+ unsubscribe = () => {}
4678
+ entry = next
4679
+ if (!entry) return
4680
+ try {
4681
+ const source = entry.inject().hooks?.workspaceShortcuts
4682
+ if (
4683
+ typeof source?.getSnapshot !== 'function' ||
4684
+ typeof source?.subscribe !== 'function'
4685
+ )
4686
+ return
4687
+ let lastRequest = source.getSnapshot().searchRequest
4688
+ unsubscribe = source.subscribe(() => {
4689
+ const request = source.getSnapshot().searchRequest
4690
+ if (request === lastRequest) return
4691
+ lastRequest = request
4692
+ if (!Number.isSafeInteger(request) || request <= 0) return
4693
+ searchRequest += 1
4694
+ for (const listener of searchListeners) listener()
4695
+ })
4696
+ } catch {
4697
+ // An unavailable/incompatible shipped entry must not break the replacement.
4698
+ }
4699
+ }
4700
+ const unsubscribeSlots = ctx.slots.subscribe?.('sidebar.workspaces', reconcile)
4701
+ reconcile()
4702
+ return () => {
4703
+ unsubscribeSlots?.()
4704
+ unsubscribe()
4705
+ searchListeners.clear()
4706
+ }
4707
+ }, 'orca-projects: search shortcuts')
4708
+
4709
+ ctx.slots.inject('sidebar.workspaces', () =>
4710
+ ctx.slots.register(
4711
+ {
4712
+ name: 'sidebar.workspaces',
4713
+ priority: -1,
4714
+ locale: NS,
4715
+ inject: () => ({
4716
+ workspaceSource,
4717
+ sessionSource,
4718
+ sessionStatusSource,
4719
+ layoutSource,
4720
+ searchRequestSource,
4721
+ resolveRepositories: fetchRepositories,
4722
+ openSession: (sessionId) => uiWorkspace.openSession(sessionId),
4723
+ startSession: (workspaceId) => uiWorkspace.startSession(workspaceId),
4724
+ openWorkspace: (workspaceId) => uiWorkspace.openWorkspace(workspaceId),
4725
+ pickDirectory: () => uiWorkspace.pickDirectory(),
4726
+ createWorkspace: (path) => workspaces.create({ path }),
4727
+ deleteWorkspace: (workspaceId) => workspaces.delete(workspaceId),
4728
+ pinSession: (sessionId) => workspaces.pinSession(sessionId),
4729
+ unpinSession: (sessionId) => workspaces.unpinSession(sessionId),
4730
+ archiveSession: (sessionId, options) => workspaces.archiveSession(sessionId, options),
4731
+ unarchiveSession: (sessionId) => workspaces.unarchiveSession(sessionId),
4732
+ }),
4733
+ },
4734
+ OrcaBrowser,
4735
+ ),
4736
+ )
4737
+ }
4738
+
4739
+ const internals = {
4740
+ defaultState,
4741
+ sanitizeState,
4742
+ buildView,
4743
+ assignProject,
4744
+ renameProject,
4745
+ createGroup,
4746
+ deleteGroup,
4747
+ renameGroup,
4748
+ moveProjectInOrder,
4749
+ moveSessionInOrder,
4750
+ isCollapsed,
4751
+ normalizePath,
4752
+ isAncestor,
4753
+ worktreeFromPath,
4754
+ sessionWorktree,
4755
+ workspaceRepo,
4756
+ repoFromPathFallback,
4757
+ worktreeForSession,
4758
+ repositoryWorktree,
4759
+ isActiveSession,
4760
+ findCurrentId,
4761
+ sessionLabel,
4762
+ sortProjects,
4763
+ sortSessions,
4764
+ }
4765
+
4766
+ return {
4767
+ inject,
4768
+ apply,
4769
+ ...(globalThis.__ORCA_PROJECTS_TEST__ ? { __internals: internals } : {}),
4770
+ }
4771
+ },
4772
+ })