@xmodelin/dsh-collab-sessions 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js ADDED
@@ -0,0 +1,2176 @@
1
+ /**
2
+ * Browser half of the collaboration-session plugin.
3
+ *
4
+ * The left sidebar's `sidebar.session.action` layer wraps the New-session row.
5
+ * We keep the owner's New Session control and add one sibling entry that asks
6
+ * the Workspace navigation service for a New Session under the `collab` Agent
7
+ * preset in the currently selected Workspace. The Host half prepares the
8
+ * per-session comm/private layout inside that Workspace.
9
+ *
10
+ * A small watcher activates a collab Session when its Agent starts running
11
+ * because a peer message woke it, so the user sees the incoming request and
12
+ * the result instead of having to find the session manually.
13
+ */
14
+ window.__ModuleLoader__.load({
15
+ id: '@xmodelin/dsh-collab-sessions',
16
+ factory(require) {
17
+ const React = require('react')
18
+ const h = React.createElement
19
+ const NS = 'dsh-collab-sessions'
20
+ const BOARD_TAB_ID = '@xmodelin/dsh-collab-sessions/supervisor-tasks'
21
+ const BOARD_TAB_KIND = 'collabSupervisorTasks'
22
+ const WORKERS_TAB_ID = '@xmodelin/dsh-collab-sessions/supervisor-workers'
23
+ const WORKERS_TAB_KIND = 'collabSupervisorWorkers'
24
+ let MenuItemButton
25
+ let Button
26
+ let IconCopyOutlineRegular
27
+ try {
28
+ const primitives = require('@deepseek-ai/dsh-client-ui-primitives')
29
+ MenuItemButton = primitives.MenuItemButton
30
+ Button = primitives.Button
31
+ IconCopyOutlineRegular = primitives.IconCopyOutlineRegular
32
+ } catch {
33
+ MenuItemButton = undefined
34
+ Button = undefined
35
+ IconCopyOutlineRegular = undefined
36
+ }
37
+
38
+ const ZH = {
39
+ 'entry.short': '协同',
40
+ 'entry.label': '新建协同会话',
41
+ 'entry.hint': '新建协同会话或超级会话;超级会话只做协调调度',
42
+ 'entry.noWorkspace': '请先打开一个工作区。',
43
+ 'entry.notReady': '工作区仍在加载,请稍后重试。',
44
+ 'entry.createFailed': '无法新建协同会话,请稍后重试。',
45
+ 'entry.menuCollab': '协同会话',
46
+ 'entry.menuSupervisor': '超级会话',
47
+ 'panel.label': '协同授权',
48
+ 'panel.title': '协同授权',
49
+ 'panel.description': '只有协同会话支持相互通信;授权是双向的,必须双方都授权后才能通信。在“已授权会话对”查看现有关系,在“协同会话”勾选两个会话完成授权。',
50
+ 'panel.pairs': '已授权的会话对(双方)',
51
+ 'panel.pairsTab': '已授权会话对',
52
+ 'panel.sessionsTab': '协同会话',
53
+ 'panel.sessions': '协同会话',
54
+ 'panel.emptyPairs': '还没有双方都授权的会话对。',
55
+ 'panel.emptySessions': '还没有协同会话。先点“协同”创建一个。',
56
+ 'panel.pending': '单方已授权(通信仍被拒绝)',
57
+ 'panel.oneSided': '单方已授权',
58
+ 'panel.complete': '补齐双方',
59
+ 'panel.authorize': '为双方授权',
60
+ 'panel.revoke': '撤销',
61
+ 'panel.confirmRevoke': '确认撤销',
62
+ 'panel.refresh': '刷新',
63
+ 'panel.loading': '加载中…',
64
+ 'panel.selectTwo': '请选择两个协同会话。',
65
+ 'panel.authorizedNotice': '双方已授权。',
66
+ 'panel.revokedNotice': '已撤销双方授权。',
67
+ 'panel.error': '操作失败',
68
+ 'panel.running': '运行中',
69
+ 'auth.open': '打开协同授权',
70
+ 'base.menu': '设置会话提示词',
71
+ 'copy.title': '复制会话名',
72
+ 'copy.done': '会话名已复制',
73
+ 'copy.failed': '复制失败,请重试',
74
+ 'base.title': '会话提示词',
75
+ 'base.session': '会话',
76
+ 'base.description': '这条会话提示词会注入当前协同会话后续的每一轮,可用于设定角色和约束。',
77
+ 'base.placeholder': '例如:你是代码审查员;只审查,不修改文件;回答使用中文。',
78
+ 'base.save': '保存',
79
+ 'base.cancel': '取消',
80
+ 'base.saving': '保存中…',
81
+ 'base.loading': '加载中…',
82
+ 'base.error': '操作失败',
83
+ 'base.heroButton': '设置提示词',
84
+ 'board.title': '任务看板',
85
+ 'board.tasksTitle': '任务列表',
86
+ 'board.workersTitle': '注册中心',
87
+ 'board.allProjects': '全部任务',
88
+ 'board.capabilityBoard': '能力登记',
89
+ 'board.open': '任务',
90
+ 'board.workers': '已 offer 的协同会话',
91
+ 'board.available': '未 offer 的协同会话',
92
+ 'board.offer': 'Offer',
93
+ 'board.emptyAvailable': '没有可 offer 的协同会话。',
94
+ 'board.tasks': '子任务',
95
+ 'board.projects': '任务',
96
+ 'board.parentTask': '任务',
97
+ 'board.subtask': '子任务',
98
+ 'board.add': '登记功能会话',
99
+ 'board.capability': '能力名称',
100
+ 'board.description': '能力描述',
101
+ 'board.selectWorker': '选择功能会话',
102
+ 'board.register': '登记',
103
+ 'board.unlink': '注销',
104
+ 'board.refresh': '刷新',
105
+ 'board.locate': '定位到对话',
106
+ 'board.sourceLive': '实时能力',
107
+ 'board.sourceOverride': '固定能力',
108
+ 'board.changed': '能力已更新',
109
+ 'board.pin': '固定当前',
110
+ 'board.viewDetails': '查看会话详情',
111
+ 'board.detailsTitle': '会话能力详情',
112
+ 'board.description': '能力描述',
113
+ 'board.workerId': '会话 ID',
114
+ 'board.source': '能力来源',
115
+ 'board.version': '能力版本',
116
+ 'board.noDescription': '未填写能力描述。',
117
+ 'board.close': '关闭',
118
+ 'board.pinnedNotice': '已固定当前能力。',
119
+ 'board.liveNotice': '已切换为实时能力。',
120
+ 'board.requests': '已接收请求',
121
+ 'board.emptyRequests': '还没有已接收请求。',
122
+ 'board.requester': '请求方',
123
+ 'board.worker': '处理方',
124
+ 'board.noLinkedTask': '该请求尚未创建任务。',
125
+ 'board.prevPage': '上一页',
126
+ 'board.nextPage': '下一页',
127
+ 'preset.collabName': '协同会话',
128
+ 'preset.collabDescription': '拥有独立的 .dsh-collab 工作目录、共享的 comm/ 目录和仅本会话可访问的 private/ 目录,并提供经过身份验证的会话间通信工具。',
129
+ 'preset.supervisorName': '超级会话',
130
+ 'preset.supervisorDescription': '负责拆解需求、把子任务分派给已登记的功能会话、核验结果并完成交付;不提供任何实现类工具。',
131
+ 'board.taskDetail': '子任务详情',
132
+ 'board.close': '关闭',
133
+ 'board.noResult': '暂无结果。',
134
+ 'status.pending': '待处理',
135
+ 'status.accepted': '已受理',
136
+ 'status.rejected': '已拒绝',
137
+ 'status.expired': '已过期',
138
+ 'status.cancelled': '已取消',
139
+ 'status.delivered': '已交付',
140
+ 'status.created': '待分配',
141
+ 'status.assigned': '已分配',
142
+ 'status.running': '执行中',
143
+ 'status.done': '已完成',
144
+ 'status.failed': '失败',
145
+ 'status.open': '进行中',
146
+ 'status.closed': '已关闭',
147
+ 'board.search': '搜索能力描述',
148
+ 'board.searchEmpty': '无匹配内容。',
149
+ 'board.expand': '展开',
150
+ 'board.collapse': '收起',
151
+ 'board.useLive': '使用实时',
152
+ 'board.noLocation': '该任务没有可定位的对话记录。',
153
+ 'board.notFound': '未找到对应的对话位置,可能尚未加载。',
154
+ 'board.emptyWorkers': '还没有登记功能会话。',
155
+ 'board.emptyTasks': '还没有子任务。',
156
+ 'board.loading': '加载中…',
157
+ 'board.open': '任务',
158
+ 'board.openTitle': '打开 supervisor 任务面板',
159
+ 'board.overdue': '已超期',
160
+ 'board.error': '操作失败',
161
+ 'board.registerHint': '登记会同时完成双向通信授权;Phase 1 只开放被指派(offer)。',
162
+ 'board.confirmUnlink': '注销该功能会话并撤销通信授权?',
163
+ }
164
+ const EN = {
165
+ 'entry.short': 'Collab',
166
+ 'entry.label': 'New collab session',
167
+ 'entry.hint': 'Start a collab or supervisor session in the current Workspace',
168
+ 'entry.noWorkspace': 'Open a workspace first.',
169
+ 'entry.notReady': 'Workspaces are still loading; try again in a moment.',
170
+ 'entry.createFailed': 'Could not start the collab session; try again.',
171
+ 'entry.menuCollab': 'Collab session',
172
+ 'entry.menuSupervisor': 'Supervisor session',
173
+ 'panel.label': 'Collab access',
174
+ 'panel.title': 'Collab access',
175
+ 'panel.description': 'Only collab sessions can message each other, and authorization is bilateral: both sides must authorize before communication works. The upper section lists fully authorized pairs (and one-sided grants still waiting for the other side); the lower section lists collab sessions. Select two collab sessions to authorize both sides.',
176
+ 'panel.pairs': 'Authorized pairs (both sides)',
177
+ 'panel.pairsTab': 'Authorized pairs',
178
+ 'panel.sessionsTab': 'Collab sessions',
179
+ 'panel.sessions': 'Collab sessions',
180
+ 'panel.emptyPairs': 'No pair has both sides authorized yet.',
181
+ 'panel.emptySessions': 'No collab sessions yet. Create one with Collab.',
182
+ 'panel.pending': 'One-sided grants (communication still refused)',
183
+ 'panel.oneSided': 'One-sided',
184
+ 'panel.complete': 'Authorize both',
185
+ 'panel.authorize': 'Authorize both sides',
186
+ 'panel.revoke': 'Revoke',
187
+ 'panel.confirmRevoke': 'Confirm revoke',
188
+ 'panel.refresh': 'Refresh',
189
+ 'panel.loading': 'Loading…',
190
+ 'panel.selectTwo': 'Select exactly two collab sessions.',
191
+ 'panel.noControl': 'Open a collab session first.',
192
+ 'panel.authorizedNotice': 'Both sides authorized.',
193
+ 'panel.revokedNotice': 'Both sides revoked.',
194
+ 'panel.error': 'Operation failed',
195
+ 'panel.running': 'Running',
196
+ 'auth.open': 'Open Collab access',
197
+ 'base.menu': 'Set session prompt',
198
+ 'copy.title': 'Copy session name',
199
+ 'copy.done': 'Session name copied',
200
+ 'copy.failed': 'Copy failed; try again',
201
+ 'base.title': 'Session prompt',
202
+ 'base.session': 'Session',
203
+ 'base.description': 'This session prompt is injected into every subsequent turn of the current collaboration session; use it for a role and constraints.',
204
+ 'base.placeholder': 'For example: You are a code reviewer. Only review; never edit files. Answer in Chinese.',
205
+ 'base.save': 'Save',
206
+ 'base.cancel': 'Cancel',
207
+ 'base.saving': 'Saving…',
208
+ 'base.loading': 'Loading…',
209
+ 'base.error': 'Operation failed',
210
+ 'base.heroButton': 'Set prompt',
211
+ 'board.title': 'Task board',
212
+ 'board.tasksTitle': 'Task list',
213
+ 'board.workersTitle': 'Registration center',
214
+ 'board.allProjects': 'All tasks',
215
+ 'board.capabilityBoard': 'Capabilities',
216
+ 'board.open': 'Tasks',
217
+ 'board.workers': 'Offered collaboration sessions',
218
+ 'board.available': 'Collaboration sessions not offered',
219
+ 'board.offer': 'Offer',
220
+ 'board.emptyAvailable': 'No collaboration sessions available to offer.',
221
+ 'board.tasks': 'Subtasks',
222
+ 'board.projects': 'Tasks',
223
+ 'board.parentTask': 'Task',
224
+ 'board.subtask': 'Subtask',
225
+ 'board.add': 'Register worker',
226
+ 'board.capability': 'Capability name',
227
+ 'board.description': 'Capability description',
228
+ 'board.selectWorker': 'Select a functional session',
229
+ 'board.register': 'Register',
230
+ 'board.unlink': 'Unregister',
231
+ 'board.refresh': 'Refresh',
232
+ 'board.locate': 'Locate in conversation',
233
+ 'board.sourceLive': 'Live capability',
234
+ 'board.sourceOverride': 'Pinned capability',
235
+ 'board.changed': 'Capability updated',
236
+ 'board.pin': 'Pin current',
237
+ 'board.viewDetails': 'View session details',
238
+ 'board.detailsTitle': 'Session capability details',
239
+ 'board.description': 'Capability description',
240
+ 'board.workerId': 'Session ID',
241
+ 'board.source': 'Capability source',
242
+ 'board.version': 'Capability version',
243
+ 'board.noDescription': 'No capability description provided.',
244
+ 'board.close': 'Close',
245
+ 'board.pinnedNotice': 'Capability pinned.',
246
+ 'board.liveNotice': 'Switched to live capability.',
247
+ 'board.requests': 'Received requests',
248
+ 'board.emptyRequests': 'No received requests yet.',
249
+ 'board.requester': 'Requester',
250
+ 'board.worker': 'Worker',
251
+ 'board.noLinkedTask': 'No task has been created for this request yet.',
252
+ 'board.prevPage': 'Previous',
253
+ 'board.nextPage': 'Next',
254
+ 'preset.collabName': 'Collab session',
255
+ 'preset.collabDescription': 'A session with its own .dsh-collab working directory, a shared comm/ directory, a session-only private/ directory, and authenticated session-to-session messaging.',
256
+ 'preset.supervisorName': 'Supervisor session',
257
+ 'preset.supervisorDescription': 'Coordinates requirements, assigns subtasks to registered functional sessions, verifies results, and delivers. It has no implementation tools.',
258
+ 'board.taskDetail': 'Subtask details',
259
+ 'board.close': 'Close',
260
+ 'board.noResult': 'No result yet.',
261
+ 'status.pending': 'Pending',
262
+ 'status.accepted': 'Accepted',
263
+ 'status.rejected': 'Rejected',
264
+ 'status.expired': 'Expired',
265
+ 'status.cancelled': 'Cancelled',
266
+ 'status.delivered': 'Delivered',
267
+ 'status.created': 'Unassigned',
268
+ 'status.assigned': 'Assigned',
269
+ 'status.running': 'Running',
270
+ 'status.done': 'Done',
271
+ 'status.failed': 'Failed',
272
+ 'status.open': 'Open',
273
+ 'status.closed': 'Closed',
274
+ 'board.search': 'Search capability description',
275
+ 'board.searchEmpty': 'No matching content.',
276
+ 'board.expand': 'Expand',
277
+ 'board.collapse': 'Collapse',
278
+ 'board.useLive': 'Use live',
279
+ 'board.noLocation': 'This task has no recorded conversation position.',
280
+ 'board.notFound': 'The conversation position is not loaded yet.',
281
+ 'board.emptyWorkers': 'No functional sessions registered yet.',
282
+ 'board.emptyTasks': 'No subtasks yet.',
283
+ 'board.loading': 'Loading…',
284
+ 'board.open': 'Tasks',
285
+ 'board.openTitle': 'Open the supervisor task panel',
286
+ 'board.overdue': 'overdue',
287
+ 'board.error': 'Operation failed',
288
+ 'board.registerHint': 'Registration also authorizes the communication pair; Phase 1 exposes offer only.',
289
+ 'board.confirmUnlink': 'Unregister this worker and revoke its communication authorization?',
290
+ }
291
+
292
+ const FALLBACK = EN
293
+ function fallbackT(key) {
294
+ return FALLBACK[key] ?? key
295
+ }
296
+ const selectSnapshot = snapshot => snapshot
297
+
298
+ function isCollabSummary(summary, state) {
299
+ if (summary === undefined) return false
300
+ const values = summary.projectionValues ?? state?.projectionsBySession?.[summary.id]?.values
301
+ const preset = values?.agentPreset
302
+ const workdir = typeof values?.workingDirectory === 'string'
303
+ ? values.workingDirectory.replace(/\\/gu, '/')
304
+ : ''
305
+ return preset === 'collab'
306
+ || preset === 'supervisor'
307
+ || workdir.includes('.dsh-collab/sessions/')
308
+ }
309
+
310
+ const CSS = [
311
+ '.dsh-collab-new-stack{display:flex;flex-direction:column;align-items:stretch;gap:6px;width:100%;min-width:0}',
312
+ '.dsh-collab-new-stack[data-wide="false"]{width:36px;align-items:flex-start;gap:4px}',
313
+ '.dsh-collab-new-owner{display:flex;align-items:center;width:100%;min-width:0}',
314
+ '.dsh-collab-new-owner>*{flex:1 1 auto;min-width:0}',
315
+ '.dsh-collab-new-cell{position:relative;flex:0 0 auto;display:flex;flex-direction:column;gap:4px;min-width:0;width:100%}',
316
+ '.dsh-collab-new-button{position:relative;display:flex;align-items:center;justify-content:center;gap:8px;width:100%;height:38px;padding:8px 12px;margin:0;box-sizing:border-box;border:0.5px solid var(--dsw-alias-border-l3);border-radius:var(--dsw-radius-md,10px);background:var(--dsw-alias-button-elevated-fill,var(--dsw-alias-bg-layer-1));color:var(--dsw-alias-label-primary);font-family:inherit;font-size:14px;font-weight:500;line-height:22px;cursor:pointer;overflow:hidden}',
317
+ '.dsh-collab-new-button[data-wide="false"]{width:36px;height:36px;padding:0;gap:0;border-color:transparent;background:transparent}',
318
+ 'html[data-platform="darwin"] .dsh-collab-new-button[data-wide="true"]{background:var(--dsw-specific-sidebar-glass-fill,var(--dsw-alias-button-elevated-fill))}',
319
+ '.dsh-collab-new-button[data-error="true"]{border-color:var(--dsw-alias-state-error-primary)}',
320
+ '.dsh-collab-new-label{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
321
+ '.dsh-collab-new-alert{max-width:180px;font-size:11px;line-height:15px;color:var(--dsw-alias-state-error-primary)}',
322
+ '.dsh-collab-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}',
323
+ '@media (hover:hover){.dsh-collab-new-button:hover{background:var(--dsw-alias-button-floating-hover,var(--dsw-alias-bg-layer-2))}}',
324
+ '@media (hover:hover){.dsh-collab-new-button[data-wide="false"]:hover{background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2))}}',
325
+ '@media (hover:hover){html[data-platform="darwin"] .dsh-collab-new-button[data-wide="true"]:hover{background:var(--dsw-specific-sidebar-glass-hover,var(--dsw-alias-button-floating-hover))}}',
326
+ '.dsh-collab-new-menu-backdrop{position:fixed;inset:0;z-index:1000;background:transparent}',
327
+ '.dsh-collab-new-menu{position:fixed;z-index:1001;min-width:180px;padding:4px;border:0.5px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-layer-1);box-shadow:0 12px 32px rgba(0,0,0,.18)}',
328
+ '.dsh-collab-new-menu-item{display:flex;align-items:center;justify-content:center;width:100%;padding:7px 10px;border:0;border-radius:7px;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:18px;font-weight:600;text-align:center;cursor:pointer}',
329
+ '.dsh-collab-new-menu-item:hover{background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2))}',
330
+ '.dsh-collab-new-button:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-brand-primary));outline-offset:-2px}',
331
+ ].join('')
332
+
333
+ /** Two linked speech bubbles; inherits the button's text color. */
334
+ function CollabIcon({ size }) {
335
+ return h('svg', {
336
+ viewBox: '0 0 36 36',
337
+ width: size,
338
+ height: size,
339
+ 'aria-hidden': true,
340
+ style: { display: 'block', flex: 'none' },
341
+ },
342
+ h('path', {
343
+ d: 'M5.5 10.2A3.2 3.2 0 0 1 8.7 7h8.6a3.2 3.2 0 0 1 3.2 3.2v5.6a3.2 3.2 0 0 1-3.2 3.2h-4.9l-4 3.1a1 1 0 0 1-1.6-.8v-2.4a3.2 3.2 0 0 1-1.9-2.9z',
344
+ fill: 'currentColor',
345
+ }),
346
+ h('path', {
347
+ d: 'M14.5 21.6a3.2 3.2 0 0 1 3.2-3.2h7.6a3.2 3.2 0 0 1 3.2 3.2v4.6a3.2 3.2 0 0 1-3.2 3.2h-1v2.6a1 1 0 0 1-1.6.8l-3.3-3.4h-1.7a3.2 3.2 0 0 1-3.2-3.2z',
348
+ fill: 'currentColor',
349
+ opacity: 0.55,
350
+ }))
351
+ }
352
+
353
+ function CollabNewSessionControls(props) {
354
+ const wide = props.wide === true
355
+ const t = typeof props.t === 'function'
356
+ ? props.t
357
+ : (typeof props.translate === 'function' ? props.translate : fallbackT)
358
+ const workspace = props.useWorkspaces(selectSnapshot)
359
+ const sessions = props.useSessions(selectSnapshot)
360
+ const workspaceCount = workspace?.items?.length ?? 0
361
+ const workspaceReady = workspace?.phase === 'ready'
362
+ const sessionsReady = sessions?.phase === 'ready'
363
+ const [error, setError] = React.useState(null)
364
+ const [menuOpen, setMenuOpen] = React.useState(false)
365
+ const [menuPos, setMenuPos] = React.useState(null)
366
+ const buttonRef = React.useRef(null)
367
+ const menuRef = React.useRef(null)
368
+ const menuId = React.useId()
369
+ const alertId = React.useId()
370
+ const label = t('entry.label')
371
+ const hint = t('entry.hint')
372
+
373
+ React.useEffect(() => {
374
+ if (workspaceReady && sessionsReady && workspaceCount > 0) setError(null)
375
+ }, [workspaceReady, sessionsReady, workspaceCount])
376
+
377
+ React.useEffect(() => {
378
+ if (!menuOpen) return undefined
379
+ const first = menuRef.current?.querySelector('[role="menuitem"]')
380
+ if (first !== undefined) first.focus()
381
+ const close = () => { setMenuOpen(false); buttonRef.current?.focus() }
382
+ window.addEventListener('resize', close)
383
+ return () => window.removeEventListener('resize', close)
384
+ }, [menuOpen])
385
+
386
+ const moveMenuFocus = (event) => {
387
+ const items = [...(menuRef.current?.querySelectorAll('[role="menuitem"]') ?? [])]
388
+ if (items.length === 0) return
389
+ const index = items.indexOf(document.activeElement)
390
+ let next = index
391
+ if (event.key === 'ArrowDown') next = (index + 1) % items.length
392
+ else if (event.key === 'ArrowUp') next = index <= 0 ? items.length - 1 : index - 1
393
+ else if (event.key === 'Home') next = 0
394
+ else if (event.key === 'End') next = items.length - 1
395
+ else return
396
+ event.preventDefault()
397
+ items[next].focus()
398
+ }
399
+
400
+ const openMenu = () => {
401
+ if (!workspaceReady || !sessionsReady) {
402
+ setError({ key: 'notReady' })
403
+ return
404
+ }
405
+ if (workspaceCount < 1) {
406
+ setError({ key: 'noWorkspace' })
407
+ return
408
+ }
409
+ setError(null)
410
+ const rect = buttonRef.current?.getBoundingClientRect()
411
+ const width = Math.max(rect?.width ?? 180, 180)
412
+ const maxLeft = typeof window === 'undefined' ? 0 : Math.max(8, window.innerWidth - width - 8)
413
+ const left = Math.min(rect?.left ?? 8, maxLeft)
414
+ setMenuPos({ left, top: (rect?.bottom ?? 0) + 4, width })
415
+ setMenuOpen(true)
416
+ }
417
+
418
+ const launch = (preset) => {
419
+ setMenuOpen(false)
420
+ try {
421
+ props.start(preset)
422
+ } catch (failure) {
423
+ console.error('[collab-sessions] could not start a session:', failure)
424
+ const detail = failure instanceof Error ? failure.message : String(failure)
425
+ setError({
426
+ key: 'createFailed',
427
+ detail: detail.length > 200 ? `${detail.slice(0, 200)}…` : detail,
428
+ })
429
+ }
430
+ }
431
+
432
+ const errorText = error === null
433
+ ? undefined
434
+ : t(`entry.${error.key}`) + (error.detail === undefined ? '' : ` (${error.detail})`)
435
+ const button = h('button', {
436
+ ref: buttonRef,
437
+ type: 'button',
438
+ 'aria-haspopup': 'menu',
439
+ 'aria-expanded': menuOpen ? 'true' : 'false',
440
+ 'aria-controls': menuOpen ? menuId : undefined,
441
+ title: errorText ?? hint,
442
+ 'aria-label': label,
443
+ 'aria-invalid': error === null ? undefined : 'true',
444
+ 'aria-describedby': error === null ? undefined : alertId,
445
+ 'data-wide': wide ? 'true' : 'false',
446
+ 'data-error': error === null ? 'false' : 'true',
447
+ 'data-collab-entry': 'true',
448
+ className: 'dsh-collab-new-button',
449
+ onClick: openMenu,
450
+ onKeyDown: (event) => {
451
+ if (event.key !== 'ArrowDown') return
452
+ event.preventDefault()
453
+ if (menuOpen) menuRef.current?.querySelector('[role="menuitem"]')?.focus()
454
+ else openMenu()
455
+ },
456
+ },
457
+ h(CollabIcon, { size: wide ? 16 : 18 }),
458
+ wide ? h('span', { className: 'dsh-collab-new-label' }, t('entry.label')) : null)
459
+
460
+ const alert = errorText === undefined
461
+ ? null
462
+ : h('span', {
463
+ id: alertId,
464
+ role: 'alert',
465
+ className: wide ? 'dsh-collab-new-alert' : 'dsh-collab-sr',
466
+ }, errorText)
467
+
468
+ const menu = menuOpen && menuPos !== null
469
+ ? h(React.Fragment, null,
470
+ h('div', { className: 'dsh-collab-new-menu-backdrop', onClick: () => setMenuOpen(false) }),
471
+ h('div', {
472
+ ref: menuRef,
473
+ id: menuId,
474
+ className: 'dsh-collab-new-menu',
475
+ role: 'menu',
476
+ style: { left: menuPos.left, top: menuPos.top, width: menuPos.width },
477
+ onKeyDown: (event) => {
478
+ if (event.key === 'Escape') {
479
+ event.preventDefault()
480
+ setMenuOpen(false)
481
+ buttonRef.current?.focus()
482
+ return
483
+ }
484
+ moveMenuFocus(event)
485
+ },
486
+ },
487
+ h('button', {
488
+ type: 'button',
489
+ role: 'menuitem',
490
+ tabIndex: -1,
491
+ className: 'dsh-collab-new-menu-item',
492
+ onClick: () => launch('collab'),
493
+ }, t('entry.menuCollab')),
494
+ h('button', {
495
+ type: 'button',
496
+ role: 'menuitem',
497
+ tabIndex: -1,
498
+ className: 'dsh-collab-new-menu-item',
499
+ onClick: () => launch('supervisor'),
500
+ }, t('entry.menuSupervisor'))))
501
+ : null
502
+ return h(React.Fragment, null,
503
+ h('style', null, CSS),
504
+ h('div', {
505
+ className: 'dsh-collab-new-stack',
506
+ 'data-wide': wide ? 'true' : 'false',
507
+ },
508
+ h('div', { className: 'dsh-collab-new-owner' }, props.children),
509
+ h('div', { className: 'dsh-collab-new-cell' }, button, alert)),
510
+ menu)
511
+ }
512
+
513
+ const AUTH_CSS = [
514
+ '.dsh-collab-auth{display:flex;flex-direction:column;gap:16px;padding:22px 24px;max-width:860px;margin:0 auto;box-sizing:border-box;height:100%;min-height:0;overflow:hidden;color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px}',
515
+ '.dsh-collab-auth-head{flex:none;display:flex;flex-direction:column;gap:4px}',
516
+ '.dsh-collab-auth-title{margin:0;font-size:18px;line-height:24px;font-weight:600}',
517
+ '.dsh-collab-auth-desc{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px}',
518
+ '.dsh-collab-auth-card{border:0.5px solid var(--dsw-alias-border-l1);border-radius:12px;background:var(--dsw-alias-bg-layer-1);padding:14px;display:flex;flex-direction:column;gap:8px;min-height:0;flex:none}',
519
+ '.dsh-collab-auth-card[data-grow="true"]{flex:1 1 auto;min-height:0}',
520
+ '.dsh-collab-auth-tabs-row{flex:none;display:flex;align-items:center;gap:4px;border-bottom:0.5px solid var(--dsw-alias-border-l1);padding-bottom:8px}',
521
+ '.dsh-collab-auth-tabs{display:flex;align-items:center;gap:4px;min-width:0}',
522
+ '.dsh-collab-auth-tabs-actions{margin-left:auto;display:flex;align-items:center;gap:6px}',
523
+ '.dsh-collab-auth-body{flex:1;min-height:0;display:flex;flex-direction:column;gap:8px}',
524
+ '.dsh-collab-auth-tab{height:30px;padding:0 10px;border:0;border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;cursor:pointer}',
525
+ '.dsh-collab-auth-tab:hover{background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2))}',
526
+ '.dsh-collab-auth-tab[data-active="true"]{background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2));color:var(--dsw-alias-label-primary);font-weight:600}',
527
+ '.dsh-collab-auth-content{flex:1;min-height:0;display:flex;flex-direction:column}',
528
+ '.dsh-collab-auth-content>.dsh-collab-auth-card{flex:1 1 auto;min-height:0;max-height:none}',
529
+ '.dsh-collab-auth-list{display:flex;flex-direction:column;gap:2px;min-height:0;flex:1 1 auto;overflow-y:auto;overscroll-behavior:contain;padding-right:2px}',
530
+ '.dsh-collab-auth-footer{flex:none;display:flex;align-items:center;justify-content:flex-end;gap:8px;flex-wrap:wrap;padding-top:8px;margin-top:2px;border-top:0.5px solid var(--dsw-alias-border-l1)}',
531
+ '.dsh-collab-auth-hint{flex:1 1 180px;min-width:0;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px}',
532
+ '.dsh-collab-auth-muted{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;margin:0}',
533
+ '.dsh-collab-auth-row{display:flex;align-items:center;gap:8px;padding:8px;border-radius:8px;min-width:0}',
534
+ '.dsh-collab-auth-row:hover{background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2))}',
535
+ '.dsh-collab-auth-row input{flex:none;margin:0;accent-color:var(--dsw-alias-brand-primary)}',
536
+ '.dsh-collab-auth-title-cell{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
537
+ '.dsh-collab-auth-id{flex:none;color:var(--dsw-alias-label-tertiary);font-family:var(--dsh-font-mono,monospace);font-size:11px}',
538
+ '.dsh-collab-auth-badge{flex:none;padding:1px 7px;border-radius:999px;border:0.5px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);font-size:11px;line-height:16px}',
539
+ '.dsh-collab-auth-dot{flex:none;width:7px;height:7px;border-radius:50%;background:var(--dsw-alias-state-success-primary)}',
540
+ '.dsh-collab-auth-pair{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
541
+ '.dsh-collab-auth-button{flex:none;height:28px;padding:0 10px;border:0.5px solid var(--dsw-alias-border-l2);border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;cursor:pointer}',
542
+ '.dsh-collab-auth-button:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2));color:var(--dsw-alias-label-primary)}',
543
+ '.dsh-collab-auth-button:disabled{opacity:.45;cursor:default}',
544
+ '.dsh-collab-auth-button[data-danger="true"]{border-color:var(--dsw-alias-state-error-primary);color:var(--dsw-alias-state-error-primary)}',
545
+ '.dsh-collab-auth-button[data-primary="true"]{background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-bg-base)}',
546
+ '.dsh-collab-auth-button[data-primary="true"]:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover,var(--dsw-alias-brand-primary));border-color:var(--dsw-alias-button-primary-hover,var(--dsw-alias-brand-primary));color:var(--dsw-alias-bg-base)}',
547
+ '.dsh-collab-auth-error{margin:0;color:var(--dsw-alias-state-error-primary);font-size:12px;line-height:18px}',
548
+ '.dsh-collab-auth-notice{margin:0;color:var(--dsw-alias-state-success-primary);font-size:12px;line-height:18px}',
549
+ '.dsh-collab-auth-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px;flex-wrap:wrap}',
550
+ ].join('')
551
+
552
+ function shortId(id) {
553
+ return typeof id === 'string' && id.length > 20 ? `${id.slice(0, 12)}…${id.slice(-4)}` : String(id)
554
+ }
555
+
556
+ /** Shield with two linked nodes: authorization management. */
557
+ function CollabAuthIcon({ size }) {
558
+ return h('svg', {
559
+ viewBox: '0 0 36 36', width: size, height: size, 'aria-hidden': true,
560
+ style: { display: 'block', flex: 'none' },
561
+ },
562
+ h('path', {
563
+ d: 'M18 5.5 7.5 9.6v7.2c0 5.9 4.3 11.2 10.5 13.7 6.2-2.5 10.5-7.8 10.5-13.7V9.6z',
564
+ fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinejoin: 'round',
565
+ }),
566
+ h('circle', { cx: 14, cy: 18, r: 2.2, fill: 'currentColor' }),
567
+ h('circle', { cx: 22, cy: 18, r: 2.2, fill: 'currentColor' }),
568
+ h('path', { d: 'M16.2 18h3.6', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round' }))
569
+ }
570
+
571
+ function CollabAuthPanel(props) {
572
+ const t = typeof props.t === 'function' ? props.t : fallbackT
573
+ const sessions = props.useSessions(selectSnapshot)
574
+ const roots = (sessions?.ids ?? [])
575
+ .map(id => sessions.byId[id])
576
+ .filter(summary => summary !== undefined && summary.origin !== 'subagent' && isCollabSummary(summary, sessions))
577
+ const sorted = [...roots].sort((left, right) => (right.updatedAt ?? 0) - (left.updatedAt ?? 0))
578
+ const [pairs, setPairs] = React.useState([])
579
+ const [pendingGrants, setPendingGrants] = React.useState([])
580
+ const [activeTab, setActiveTab] = React.useState('pairs')
581
+ const [selected, setSelected] = React.useState([])
582
+ const [loading, setLoading] = React.useState(false)
583
+ const [busy, setBusy] = React.useState(false)
584
+ const [error, setError] = React.useState(null)
585
+ const [notice, setNotice] = React.useState(null)
586
+ const [confirmRevoke, setConfirmRevoke] = React.useState(null)
587
+
588
+ const titleOf = id => sessions?.byId?.[id]?.displayTitle ?? shortId(id)
589
+ const presetOf = id => (sessions?.byId?.[id]?.projectionValues ?? sessions?.projectionsBySession?.[id]?.values)?.agentPreset
590
+
591
+ const run = async (operation) => {
592
+ const result = await operation()
593
+ if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`)
594
+ return result.value
595
+ }
596
+ const mountedRef = React.useRef(true)
597
+ const requestSeqRef = React.useRef(0)
598
+ React.useEffect(() => () => { mountedRef.current = false }, [])
599
+
600
+ const loadSnapshot = async (showLoading) => {
601
+ const seq = requestSeqRef.current + 1
602
+ requestSeqRef.current = seq
603
+ if (showLoading) setLoading(true)
604
+ setError(null)
605
+ try {
606
+ const next = await run(() => props.auth.list())
607
+ if (!mountedRef.current || seq !== requestSeqRef.current) return
608
+ setPairs(next.pairs)
609
+ setPendingGrants(next.pending)
610
+ } catch (failure) {
611
+ if (!mountedRef.current || seq !== requestSeqRef.current) return
612
+ setError(`${t('panel.error')}: ${failure instanceof Error ? failure.message : String(failure)}`)
613
+ } finally {
614
+ if (mountedRef.current && seq === requestSeqRef.current) setLoading(false)
615
+ }
616
+ }
617
+
618
+ React.useEffect(() => {
619
+ void loadSnapshot(true)
620
+ const onChanged = () => { void loadSnapshot(false) }
621
+ window.addEventListener('dsh-collab-auth-changed', onChanged)
622
+ return () => { window.removeEventListener('dsh-collab-auth-changed', onChanged) }
623
+ }, [])
624
+
625
+ const rootIds = sorted.map(summary => summary.id).join('|')
626
+ React.useEffect(() => {
627
+ setSelected(current => current.filter(id => sorted.some(summary => summary.id === id)))
628
+ }, [rootIds])
629
+
630
+ const toggle = (id) => {
631
+ setNotice(null)
632
+ setError(null)
633
+ setConfirmRevoke(null)
634
+ setSelected(current => current.includes(id)
635
+ ? current.filter(item => item !== id)
636
+ : (current.length >= 2 ? [current[1], id] : [...current, id]))
637
+ }
638
+
639
+ const authorize = async () => {
640
+ setConfirmRevoke(null)
641
+ if (selected.length !== 2) {
642
+ setError(t('panel.selectTwo'))
643
+ return
644
+ }
645
+ if (!selected.every(id => sorted.some(summary => summary.id === id))) {
646
+ setSelected([])
647
+ setError(t('panel.selectTwo'))
648
+ return
649
+ }
650
+ setBusy(true)
651
+ setError(null)
652
+ setNotice(null)
653
+ try {
654
+ const next = await run(() => props.auth.authorize(selected[0], selected[1]))
655
+ setPairs(next.pairs)
656
+ setPendingGrants(next.pending)
657
+ setSelected([])
658
+ setActiveTab('pairs')
659
+ setNotice(t('panel.authorizedNotice'))
660
+ if (typeof window !== 'undefined') window.dispatchEvent(new Event('dsh-collab-auth-changed'))
661
+ } catch (failure) {
662
+ setError(`${t('panel.error')}: ${failure instanceof Error ? failure.message : String(failure)}`)
663
+ } finally {
664
+ setBusy(false)
665
+ }
666
+ }
667
+
668
+ const revoke = async (pair) => {
669
+ setConfirmRevoke(null)
670
+ setBusy(true)
671
+ setError(null)
672
+ setNotice(null)
673
+ try {
674
+ const next = await run(() => props.auth.revoke(pair.a, pair.b))
675
+ setPairs(next.pairs)
676
+ setPendingGrants(next.pending)
677
+ setNotice(t('panel.revokedNotice'))
678
+ if (typeof window !== 'undefined') window.dispatchEvent(new Event('dsh-collab-auth-changed'))
679
+ } catch (failure) {
680
+ setError(`${t('panel.error')}: ${failure instanceof Error ? failure.message : String(failure)}`)
681
+ } finally {
682
+ setBusy(false)
683
+ }
684
+ }
685
+
686
+ const authorizePair = async (a, b) => {
687
+ setConfirmRevoke(null)
688
+ setBusy(true)
689
+ setError(null)
690
+ setNotice(null)
691
+ try {
692
+ const next = await run(() => props.auth.authorize(a, b))
693
+ setPairs(next.pairs)
694
+ setPendingGrants(next.pending)
695
+ setActiveTab('pairs')
696
+ setNotice(t('panel.authorizedNotice'))
697
+ if (typeof window !== 'undefined') window.dispatchEvent(new Event('dsh-collab-auth-changed'))
698
+ } catch (failure) {
699
+ setError(`${t('panel.error')}: ${failure instanceof Error ? failure.message : String(failure)}`)
700
+ } finally {
701
+ setBusy(false)
702
+ }
703
+ }
704
+
705
+ const refresh = async () => {
706
+ setConfirmRevoke(null)
707
+ await loadSnapshot(true)
708
+ }
709
+
710
+ const hint = loading
711
+ ? t('panel.loading')
712
+ : (selected.length === 2 ? null : t('panel.selectTwo'))
713
+
714
+ const pairRows = pairs.map(pair => h('div', {
715
+ key: `${pair.a}|${pair.b}`,
716
+ className: 'dsh-collab-auth-row',
717
+ },
718
+ h('span', { className: 'dsh-collab-auth-pair' },
719
+ h('span', null, titleOf(pair.a)),
720
+ h('span', { className: 'dsh-collab-auth-muted' }, ' ↔ '),
721
+ h('span', null, titleOf(pair.b))),
722
+ h('code', { className: 'dsh-collab-auth-id' }, `${shortId(pair.a)} ↔ ${shortId(pair.b)}`),
723
+ h('button', {
724
+ type: 'button',
725
+ className: 'dsh-collab-auth-button',
726
+ 'data-danger': confirmRevoke === `pair:${pair.a}|${pair.b}` ? 'true' : 'false',
727
+ disabled: busy,
728
+ onClick: () => {
729
+ const key = `pair:${pair.a}|${pair.b}`
730
+ if (confirmRevoke !== key) { setConfirmRevoke(key); return }
731
+ void revoke(pair)
732
+ },
733
+ }, confirmRevoke === `pair:${pair.a}|${pair.b}` ? t('panel.confirmRevoke') : t('panel.revoke'))))
734
+
735
+ const pendingRows = pendingGrants.map(grant => h('div', {
736
+ key: `pending:${grant.from}|${grant.to}`,
737
+ className: 'dsh-collab-auth-row',
738
+ },
739
+ h('span', { className: 'dsh-collab-auth-pair' }, `${titleOf(grant.from)} → ${titleOf(grant.to)}`),
740
+ h('code', { className: 'dsh-collab-auth-id' }, `${shortId(grant.from)} → ${shortId(grant.to)}`),
741
+ h('span', { className: 'dsh-collab-auth-badge' }, t('panel.oneSided')),
742
+ h('button', {
743
+ type: 'button',
744
+ className: 'dsh-collab-auth-button',
745
+ disabled: busy,
746
+ onClick: () => { void authorizePair(grant.from, grant.to) },
747
+ }, t('panel.complete')),
748
+ h('button', {
749
+ type: 'button',
750
+ className: 'dsh-collab-auth-button',
751
+ 'data-danger': confirmRevoke === `pending:${grant.from}|${grant.to}` ? 'true' : 'false',
752
+ disabled: busy,
753
+ onClick: () => {
754
+ const key = `pending:${grant.from}|${grant.to}`
755
+ if (confirmRevoke !== key) { setConfirmRevoke(key); return }
756
+ void revoke({ a: grant.from, b: grant.to })
757
+ },
758
+ }, confirmRevoke === `pending:${grant.from}|${grant.to}` ? t('panel.confirmRevoke') : t('panel.revoke'))))
759
+
760
+ const sessionRows = sorted.length === 0
761
+ ? [h('p', { key: 'empty', className: 'dsh-collab-auth-muted' }, t('panel.emptySessions'))]
762
+ : sorted.map(summary => h('label', {
763
+ key: summary.id,
764
+ className: 'dsh-collab-auth-row',
765
+ },
766
+ h('input', {
767
+ type: 'checkbox',
768
+ checked: selected.includes(summary.id),
769
+ onChange: () => toggle(summary.id),
770
+ }),
771
+ h('span', { className: 'dsh-collab-auth-title-cell' }, summary.displayTitle),
772
+ h('code', { className: 'dsh-collab-auth-id' }, shortId(summary.id)),
773
+ typeof presetOf(summary.id) === 'string' && presetOf(summary.id).length > 0
774
+ ? h('span', { className: 'dsh-collab-auth-badge' }, presetOf(summary.id))
775
+ : null,
776
+ summary.running ? h('span', { className: 'dsh-collab-auth-dot', title: t('panel.running') }) : null))
777
+
778
+ const pairCard = h('section', {
779
+ className: 'dsh-collab-auth-card',
780
+ 'data-pairs': 'true',
781
+ role: 'tabpanel',
782
+ id: 'dsh-collab-auth-panel-pairs',
783
+ 'aria-labelledby': 'dsh-collab-auth-tab-pairs',
784
+ },
785
+ h('div', { className: 'dsh-collab-auth-list' },
786
+ loading ? h('p', { className: 'dsh-collab-auth-muted' }, t('panel.loading')) : null,
787
+ !loading && pairs.length === 0 && pendingGrants.length === 0
788
+ ? h('p', { className: 'dsh-collab-auth-muted' }, t('panel.emptyPairs'))
789
+ : null,
790
+ ...pairRows,
791
+ pendingRows.length === 0
792
+ ? null
793
+ : h('p', { className: 'dsh-collab-auth-muted', style: { marginTop: 6 } }, t('panel.pending')),
794
+ ...pendingRows))
795
+
796
+ const sessionCard = h('section', {
797
+ className: 'dsh-collab-auth-card',
798
+ 'data-grow': 'true',
799
+ role: 'tabpanel',
800
+ id: 'dsh-collab-auth-panel-sessions',
801
+ 'aria-labelledby': 'dsh-collab-auth-tab-sessions',
802
+ },
803
+ h('div', { className: 'dsh-collab-auth-list' }, ...sessionRows),
804
+ h('div', { className: 'dsh-collab-auth-footer' },
805
+ hint === null ? null : h('span', { className: 'dsh-collab-auth-hint' }, hint),
806
+ h('span', { className: 'dsh-collab-auth-id' }, `${selected.length}/2`),
807
+ h('button', {
808
+ type: 'button',
809
+ className: 'dsh-collab-auth-button',
810
+ 'data-primary': 'true',
811
+ disabled: busy || selected.length !== 2,
812
+ onClick: () => { void authorize() },
813
+ }, t('panel.authorize'))))
814
+
815
+ const tabButton = (id, label, count) => h('button', {
816
+ type: 'button',
817
+ role: 'tab',
818
+ id: `dsh-collab-auth-tab-${id}`,
819
+ 'aria-controls': `dsh-collab-auth-panel-${id}`,
820
+ className: 'dsh-collab-auth-tab',
821
+ 'data-active': activeTab === id ? 'true' : 'false',
822
+ 'aria-selected': activeTab === id ? 'true' : 'false',
823
+ onClick: () => setActiveTab(id),
824
+ onKeyDown: (event) => {
825
+ if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return
826
+ event.preventDefault()
827
+ const next = activeTab === 'pairs' ? 'sessions' : 'pairs'
828
+ setActiveTab(next)
829
+ window.requestAnimationFrame(() => {
830
+ document.getElementById(`dsh-collab-auth-tab-${next}`)?.focus()
831
+ })
832
+ },
833
+ }, `${label} (${String(count)})`)
834
+
835
+ return h('div', { className: 'dsh-collab-auth' },
836
+ h('style', null, AUTH_CSS),
837
+ h('div', { className: 'dsh-collab-auth-head' },
838
+ h('h2', { className: 'dsh-collab-auth-title' }, t('panel.title')),
839
+ h('p', { className: 'dsh-collab-auth-desc' }, t('panel.description'))),
840
+ h('div', { className: 'dsh-collab-auth-tabs-row' },
841
+ h('div', { className: 'dsh-collab-auth-tabs', role: 'tablist' },
842
+ tabButton('pairs', t('panel.pairsTab'), pairs.length),
843
+ tabButton('sessions', t('panel.sessionsTab'), sorted.length)),
844
+ h('div', { className: 'dsh-collab-auth-tabs-actions' },
845
+ h('button', {
846
+ type: 'button',
847
+ className: 'dsh-collab-auth-button',
848
+ disabled: loading || busy,
849
+ onClick: () => { void refresh() },
850
+ }, t('panel.refresh')))),
851
+ h('div', { className: 'dsh-collab-auth-body' },
852
+ h('div', { className: 'dsh-collab-auth-content' },
853
+ activeTab === 'pairs' ? pairCard : sessionCard)),
854
+ error === null ? null : h('p', { className: 'dsh-collab-auth-error', role: 'alert' }, error),
855
+ notice === null ? null : h('p', { className: 'dsh-collab-auth-notice', role: 'status' }, notice))
856
+ }
857
+
858
+ const REFUSED_CSS = [
859
+ '.dsh-collab-refused{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin:10px 0 2px;padding:10px 12px;border:0.5px solid var(--dsw-alias-state-error-primary);border-radius:10px;background:var(--dsw-alias-bg-layer-1);background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 10%,var(--dsw-alias-bg-layer-1));color:var(--dsw-alias-state-error-primary);font-size:13px;font-weight:600;line-height:20px}',
860
+ '.dsh-collab-refused-text{flex:1 1 240px;min-width:0}',
861
+ '.dsh-collab-refused-button{flex:none;height:28px;padding:0 10px;border:0.5px solid var(--dsw-alias-state-error-primary);border-radius:8px;background:var(--dsw-alias-state-error-primary);color:var(--dsw-alias-bg-base);font:inherit;font-size:12px;cursor:pointer}',
862
+ '.dsh-collab-refused-button:hover{opacity:.9}',
863
+ ].join('')
864
+
865
+ function resultText(message) {
866
+ const blocks = Array.isArray(message?.content) ? message.content : []
867
+ return blocks
868
+ .filter(block => block?.type === 'text' && typeof block.text === 'string')
869
+ .map(block => block.text)
870
+ .join('\n')
871
+ }
872
+
873
+ /** Accumulate one collab_send authorization refusal against its Turn. */
874
+ const collabAuthRefusedDefinition = {
875
+ kind: 'collab-auth-refused',
876
+ match(event) {
877
+ if (event.type === 'turn/start') return { id: String(event.data.turn), role: 'start' }
878
+ if (event.type === 'tool/call') return { id: String(event.data.turn), role: 'update' }
879
+ if (event.type === 'tool/result') return { id: String(event.data.turn), role: 'update' }
880
+ return null
881
+ },
882
+ start(_context, match) {
883
+ if (match.event.type !== 'turn/start') throw new Error('collab-auth-refused start requires turn/start')
884
+ return { turn: match.event.data.turn, calls: new Map(), message: null }
885
+ },
886
+ update(context, match) {
887
+ if (context.state === undefined) return context.state
888
+ if (match.event.type === 'tool/call') {
889
+ const calls = new Map(context.state.calls)
890
+ calls.set(String(match.event.data.callId), match.event.data.name)
891
+ return { ...context.state, calls }
892
+ }
893
+ if (match.event.type !== 'tool/result') return context.state
894
+ const callId = String(match.event.data.message.source.callId)
895
+ if (context.state.calls.get(callId) !== 'collab_send') return context.state
896
+ const text = resultText(match.event.data.message)
897
+ if (!text.includes('未授权') && !text.includes('授权双方')) return context.state
898
+ return { ...context.state, message: text }
899
+ },
900
+ buildLocationData(context, scope, previous) {
901
+ if (scope !== 'turn' || context.state?.message == null) return null
902
+ if (previous?.kind === 'turn'
903
+ && previous.turn === context.state.turn
904
+ && previous.key === 'collab-auth-refused'
905
+ && previous.value.message === context.state.message) return previous
906
+ return {
907
+ kind: 'turn',
908
+ turn: context.state.turn,
909
+ key: 'collab-auth-refused',
910
+ value: { message: context.state.message },
911
+ }
912
+ },
913
+ }
914
+
915
+ function CollabAuthRefusedTail(props) {
916
+ const data = props.turn?.data?.get('collab-auth-refused')
917
+ if (data === undefined) return null
918
+ return h(React.Fragment, null,
919
+ h('style', null, REFUSED_CSS),
920
+ h('div', { className: 'dsh-collab-refused', role: 'status' },
921
+ h('span', { className: 'dsh-collab-refused-text' }, `⚠️ ${data.message}`),
922
+ h('button', {
923
+ type: 'button',
924
+ className: 'dsh-collab-refused-button',
925
+ onClick: () => { props.openAuth() },
926
+ }, props.t('auth.open'))))
927
+ }
928
+
929
+ const COPY_SESSION_CSS = [
930
+ '.dsh-collab-copy-session{appearance:none;display:flex;flex:none;align-items:center;justify-content:center;width:20px;height:20px;padding:0;border:0;border-radius:5px;background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer;font:inherit;font-size:12px;line-height:1}',
931
+ '.dsh-collab-copy-session:hover{background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2));color:var(--dsw-alias-label-primary)}',
932
+ '.dsh-collab-copy-session[data-copied="true"]{color:var(--dsw-alias-state-success-primary,var(--dsw-alias-brand-primary))}',
933
+ ].join('')
934
+
935
+ async function copySessionName(text) {
936
+ const value = typeof text === 'string' ? text : ''
937
+ try {
938
+ await navigator.clipboard.writeText(value)
939
+ return true
940
+ } catch { /* fall through to the legacy copy path */ }
941
+ try {
942
+ const area = document.createElement('textarea')
943
+ area.value = value
944
+ area.setAttribute('readonly', '')
945
+ area.style.position = 'fixed'
946
+ area.style.opacity = '0'
947
+ document.body.appendChild(area)
948
+ area.select()
949
+ const copied = document.execCommand('copy')
950
+ area.remove()
951
+ return copied
952
+ } catch {
953
+ return false
954
+ }
955
+ }
956
+
957
+ function CollabCopySessionAction(props) {
958
+ const t = typeof props.t === 'function' ? props.t : fallbackT
959
+ const [state, setState] = React.useState('idle')
960
+ const title = typeof props.displayTitle === 'string' ? props.displayTitle : ''
961
+ const onClick = async (event) => {
962
+ event.stopPropagation()
963
+ const copied = await copySessionName(title)
964
+ setState(copied ? 'done' : 'failed')
965
+ window.setTimeout(() => setState('idle'), 1400)
966
+ }
967
+ return h('button', {
968
+ type: 'button',
969
+ className: 'dsh-collab-copy-session',
970
+ 'data-copied': state === 'done' ? 'true' : 'false',
971
+ title: state === 'done' ? t('copy.done') : (state === 'failed' ? t('copy.failed') : t('copy.title')),
972
+ 'aria-label': t('copy.title'),
973
+ onClick,
974
+ onPointerDown: (event) => event.stopPropagation(),
975
+ },
976
+ IconCopyOutlineRegular === undefined ? '⧉' : h(IconCopyOutlineRegular, { size: 14 }))
977
+ }
978
+
979
+ function CollabCopySessionMenuItem(props) {
980
+ const t = typeof props.t === 'function' ? props.t : fallbackT
981
+ const [, setMenuOpen] = props.useMenuOpenState()
982
+ const copy = () => {
983
+ setMenuOpen(false)
984
+ void copySessionName(typeof props.displayTitle === 'string' ? props.displayTitle : '')
985
+ }
986
+ return typeof MenuItemButton === 'function'
987
+ ? h(MenuItemButton, { onSelect: copy }, h('span', null, t('copy.title')))
988
+ : h('button', {
989
+ type: 'button',
990
+ role: 'menuitem',
991
+ className: 'dsh-collab-menu-item',
992
+ onClick: copy,
993
+ }, t('copy.title'))
994
+ }
995
+
996
+ function CollabCopySessionStyles() {
997
+ return h('style', null, COPY_SESSION_CSS)
998
+ }
999
+
1000
+ const BASE_MAX = 16 * 1024
1001
+ const basePromptStore = {
1002
+ open: false,
1003
+ sessionId: null,
1004
+ sessionTitle: '',
1005
+ value: '',
1006
+ loading: false,
1007
+ saving: false,
1008
+ error: null,
1009
+ listeners: new Set(),
1010
+ }
1011
+ let executeBasePromptCommand = null
1012
+
1013
+ const BASE_CSS = [
1014
+ '.dsh-collab-menu-item{display:flex;align-items:center;gap:8px;width:100%;padding:6px 10px;border:0;border-radius:7px;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:18px;text-align:left;cursor:pointer}',
1015
+ '.dsh-collab-menu-item:hover{background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2))}',
1016
+ '.dsh-collab-base-overlay{position:fixed;inset:0;z-index:10000;display:flex;align-items:center;justify-content:center;padding:16px;box-sizing:border-box;background:rgba(0,0,0,.38);pointer-events:auto}',
1017
+ '.dsh-collab-base-dialog{display:flex;flex-direction:column;gap:12px;width:min(620px,100%);max-height:calc(100vh - 32px);overflow:auto;padding:20px;box-sizing:border-box;border:0.5px solid var(--dsw-alias-border-l2);border-radius:14px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);box-shadow:0 18px 60px rgba(0,0,0,.28)}',
1018
+ '.dsh-collab-base-title{margin:0;font-size:16px;line-height:22px;font-weight:600}',
1019
+ '.dsh-collab-base-desc{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px}',
1020
+ '.dsh-collab-base-session{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px}',
1021
+ '.dsh-collab-base-textarea{width:100%;min-height:180px;max-height:45vh;box-sizing:border-box;padding:10px 12px;border:0.5px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:20px;resize:vertical;outline:none}',
1022
+ '.dsh-collab-base-textarea:focus{border-color:var(--dsw-alias-brand-primary)}',
1023
+ '.dsh-collab-base-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px}',
1024
+ '.dsh-collab-base-button{height:30px;padding:0 12px;border:0.5px solid var(--dsw-alias-border-l2);border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;cursor:pointer}',
1025
+ '.dsh-collab-base-button:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2))}',
1026
+ '.dsh-collab-base-button:disabled{opacity:.45;cursor:default}',
1027
+ '.dsh-collab-base-button[data-primary="true"]{background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-bg-base)}',
1028
+ '.dsh-collab-base-button[data-primary="true"]:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover,var(--dsw-alias-brand-primary));border-color:var(--dsw-alias-button-primary-hover,var(--dsw-alias-brand-primary));color:var(--dsw-alias-bg-base)}',
1029
+ '.dsh-collab-base-error{margin:0;color:var(--dsw-alias-state-error-primary);font-size:12px;line-height:18px}',
1030
+ '.dsh-collab-base-loading{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px}',
1031
+ ].join('')
1032
+
1033
+ function setBasePromptExecutor(executor) {
1034
+ executeBasePromptCommand = executor
1035
+ }
1036
+
1037
+ function emitBasePrompt() {
1038
+ for (const listener of basePromptStore.listeners) listener()
1039
+ }
1040
+
1041
+ function updateBasePromptState(patch) {
1042
+ Object.assign(basePromptStore, patch)
1043
+ emitBasePrompt()
1044
+ }
1045
+
1046
+ function useBasePromptState() {
1047
+ const [state, setState] = React.useState(() => ({ ...basePromptStore }))
1048
+ React.useEffect(() => {
1049
+ const update = () => setState({ ...basePromptStore })
1050
+ basePromptStore.listeners.add(update)
1051
+ update()
1052
+ return () => { basePromptStore.listeners.delete(update) }
1053
+ }, [])
1054
+ return state
1055
+ }
1056
+
1057
+ function encodeBasePrompt(text) {
1058
+ const bytes = new TextEncoder().encode(text)
1059
+ let binary = ''
1060
+ for (const byte of bytes) binary += String.fromCharCode(byte)
1061
+ return btoa(binary)
1062
+ }
1063
+
1064
+ function parseBasePromptResult(result) {
1065
+ if (result === undefined || result.ok !== true) {
1066
+ const message = result?.error?.message ?? 'command failed'
1067
+ throw new Error(message)
1068
+ }
1069
+ const execution = result.value
1070
+ if (execution === undefined) throw new Error('command unavailable')
1071
+ if (execution.result?.kind === 'error') throw new Error(execution.result.text)
1072
+ const text = execution.result?.text
1073
+ if (typeof text !== 'string' || text.length === 0) throw new Error('empty command result')
1074
+ const data = JSON.parse(text)
1075
+ return typeof data.basePrompt === 'string' ? data.basePrompt : ''
1076
+ }
1077
+
1078
+ function parseBasePromptCommand(line) {
1079
+ if (line === '/collab-base get') return { operation: 'baseGet' }
1080
+ const match = /^\/collab-base set(?: (.*))?$/u.exec(line)
1081
+ if (match === null) return null
1082
+ const encoded = match[1] ?? ''
1083
+ try {
1084
+ const binary = atob(encoded)
1085
+ const value = new TextDecoder().decode(Uint8Array.from(binary, character => character.charCodeAt(0)))
1086
+ return { operation: 'baseSet', value }
1087
+ } catch {
1088
+ return null
1089
+ }
1090
+ }
1091
+
1092
+ const capabilityDetailStore = {
1093
+ open: false,
1094
+ sessionId: null,
1095
+ relationship: null,
1096
+ busy: false,
1097
+ error: null,
1098
+ listeners: new Set(),
1099
+ }
1100
+ let executeLinkCommand = null
1101
+
1102
+ const CAP_DETAIL_CSS = [
1103
+ '.dsh-collab-cap-field{display:flex;flex-direction:column;gap:3px;min-width:0}',
1104
+ '.dsh-collab-cap-label{color:var(--dsw-alias-label-tertiary);font-size:10px;line-height:14px;text-transform:uppercase;letter-spacing:.04em}',
1105
+ '.dsh-collab-cap-value{font-size:12px;line-height:18px;word-break:break-word}',
1106
+ '.dsh-collab-cap-desc{margin:0;padding:10px 12px;max-height:40vh;overflow:auto;white-space:pre-wrap;word-break:break-word;background:var(--dsw-alias-bg-layer-2);border:0.5px solid var(--dsw-alias-border-l2);border-radius:8px;font:inherit;font-size:12px;line-height:18px}',
1107
+ '.dsh-collab-cap-head{display:flex;align-items:flex-start;gap:8px}',
1108
+ '.dsh-collab-cap-head .dsh-collab-base-title{flex:1;min-width:0}',
1109
+ '.dsh-collab-cap-tools{display:flex;align-items:center;gap:8px}',
1110
+ '.dsh-collab-cap-search{flex:1;min-width:0;height:30px;padding:0 10px;box-sizing:border-box;border:0.5px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;outline:none}',
1111
+ '.dsh-collab-cap-search:focus{border-color:var(--dsw-alias-brand-primary)}',
1112
+ '.dsh-collab-cap-count{flex:none;color:var(--dsw-alias-label-tertiary);font-size:10px;line-height:14px}',
1113
+ '.dsh-collab-cap-desc{max-height:40vh;overflow:auto}',
1114
+ '.dsh-collab-cap-desc[data-collapsed="true"]{max-height:112px;overflow:hidden;mask-image:linear-gradient(to bottom,black 68%,transparent)}',
1115
+ '.dsh-collab-cap-desc mark{background:var(--dsw-alias-brand-primary);color:var(--dsw-alias-bg-base);border-radius:2px}',
1116
+ ].join('')
1117
+
1118
+ function setLinkExecutor(executor) {
1119
+ executeLinkCommand = executor
1120
+ }
1121
+
1122
+ function emitCapabilityDetail() {
1123
+ for (const listener of capabilityDetailStore.listeners) listener()
1124
+ }
1125
+
1126
+ function updateCapabilityDetail(patch) {
1127
+ Object.assign(capabilityDetailStore, patch)
1128
+ emitCapabilityDetail()
1129
+ }
1130
+
1131
+ function useCapabilityDetailState() {
1132
+ const [state, setState] = React.useState(() => ({ ...capabilityDetailStore }))
1133
+ React.useEffect(() => {
1134
+ const update = () => setState({ ...capabilityDetailStore })
1135
+ capabilityDetailStore.listeners.add(update)
1136
+ update()
1137
+ return () => { capabilityDetailStore.listeners.delete(update) }
1138
+ }, [])
1139
+ return state
1140
+ }
1141
+
1142
+ function openCapabilityDetail(sessionId, relationship) {
1143
+ updateCapabilityDetail({
1144
+ open: true,
1145
+ sessionId,
1146
+ relationship,
1147
+ busy: false,
1148
+ error: null,
1149
+ })
1150
+ }
1151
+
1152
+ function closeCapabilityDetail() {
1153
+ updateCapabilityDetail({
1154
+ open: false,
1155
+ sessionId: null,
1156
+ relationship: null,
1157
+ busy: false,
1158
+ error: null,
1159
+ })
1160
+ }
1161
+
1162
+ function useDialogFocus(dialogRef, open, close, blocked) {
1163
+ React.useEffect(() => {
1164
+ if (!open) return undefined
1165
+ const previous = document.activeElement
1166
+ const dialog = dialogRef.current
1167
+ const focusable = () => dialog === null ? []
1168
+ : [...dialog.querySelectorAll('button, textarea, input, select, a[href], [tabindex]:not([tabindex="-1"])')]
1169
+ const first = focusable()[0]
1170
+ if (first !== undefined) first.focus()
1171
+ else dialog?.focus?.()
1172
+ const onKey = (event) => {
1173
+ if (event.key === 'Escape') {
1174
+ if (blocked) return
1175
+ event.preventDefault()
1176
+ close()
1177
+ return
1178
+ }
1179
+ if (event.key !== 'Tab') return
1180
+ const items = focusable()
1181
+ if (items.length === 0) {
1182
+ event.preventDefault()
1183
+ dialog?.focus?.()
1184
+ return
1185
+ }
1186
+ const current = document.activeElement
1187
+ const index = items.indexOf(current)
1188
+ const next = event.shiftKey
1189
+ ? (index <= 0 ? items[items.length - 1] : items[index - 1])
1190
+ : (index < 0 || index === items.length - 1 ? items[0] : items[index + 1])
1191
+ event.preventDefault()
1192
+ next.focus()
1193
+ }
1194
+ document.addEventListener('keydown', onKey)
1195
+ return () => {
1196
+ document.removeEventListener('keydown', onKey)
1197
+ if (previous !== null && typeof previous.focus === 'function') previous.focus()
1198
+ }
1199
+ }, [open, blocked, close])
1200
+ }
1201
+
1202
+ function CollabCapabilityDetailOverlay(props) {
1203
+ const state = useCapabilityDetailState()
1204
+ React.useEffect(() => {
1205
+ if (!state.open) return undefined
1206
+ const onKey = (event) => {
1207
+ if (event.key === 'Escape' && !state.busy) closeCapabilityDetail()
1208
+ }
1209
+ document.addEventListener('keydown', onKey)
1210
+ return () => { document.removeEventListener('keydown', onKey) }
1211
+ }, [state.open, state.busy])
1212
+ const [query, setQuery] = React.useState('')
1213
+ const [expanded, setExpanded] = React.useState(false)
1214
+ React.useEffect(() => {
1215
+ if (!state.open) return
1216
+ const description = state.relationship?.capability?.description ?? ''
1217
+ setQuery('')
1218
+ setExpanded(description.length <= 320)
1219
+ }, [state.open, state.relationship?.worker])
1220
+ if (!state.open || state.relationship === null) return null
1221
+ const relationship = state.relationship
1222
+ const capability = relationship.capability
1223
+ const pinned = capability?.source === 'override'
1224
+ const rawDescription = capability?.description ?? ''
1225
+ const queryText = query.trim()
1226
+ const lowerDescription = rawDescription.toLocaleLowerCase()
1227
+ const lowerQuery = queryText.toLocaleLowerCase()
1228
+ const segments = []
1229
+ let matchCount = 0
1230
+ if (lowerQuery.length > 0 && rawDescription.length > 0) {
1231
+ let cursor = 0
1232
+ while (matchCount < 500) {
1233
+ const index = lowerDescription.indexOf(lowerQuery, cursor)
1234
+ if (index < 0) break
1235
+ if (index > cursor) segments.push(rawDescription.slice(cursor, index))
1236
+ segments.push(h('mark', { key: `m-${String(matchCount)}` }, rawDescription.slice(index, index + queryText.length)))
1237
+ matchCount += 1
1238
+ cursor = index + queryText.length
1239
+ }
1240
+ if (cursor < rawDescription.length) segments.push(rawDescription.slice(cursor))
1241
+ }
1242
+ const canCollapse = rawDescription.length > 320 || rawDescription.split('\n').length > 6
1243
+ const collapsed = canCollapse && !expanded && queryText.length === 0
1244
+ const descriptionBody = queryText.length === 0
1245
+ ? rawDescription
1246
+ : (matchCount === 0 ? props.t('board.searchEmpty') : h(React.Fragment, null, ...segments))
1247
+ const detailField = (label, value) => h('div', { className: 'dsh-collab-cap-field' },
1248
+ h('span', { className: 'dsh-collab-cap-label' }, label),
1249
+ value)
1250
+ const applyMode = async (action) => {
1251
+ updateCapabilityDetail({ busy: true, error: null })
1252
+ try {
1253
+ if (executeLinkCommand === null) throw new Error('command executor is not ready')
1254
+ const result = await executeLinkCommand(state.sessionId, `/collab-link ${action} ${relationship.worker}`)
1255
+ if (result === undefined || result.ok !== true) throw new Error(result?.error?.message ?? 'command failed')
1256
+ if (result.value?.result?.kind === 'error') throw new Error(result.value.result.text)
1257
+ closeCapabilityDetail()
1258
+ if (typeof window !== 'undefined') {
1259
+ window.dispatchEvent(new CustomEvent('dsh-collab-board-refresh', { detail: { action, worker: relationship.worker } }))
1260
+ }
1261
+ } catch (error) {
1262
+ updateCapabilityDetail({ busy: false, error: error instanceof Error ? error.message : String(error) })
1263
+ }
1264
+ }
1265
+ return h(React.Fragment, null,
1266
+ h('style', null, BASE_CSS + CAP_DETAIL_CSS),
1267
+ h('div', {
1268
+ className: 'dsh-collab-base-overlay',
1269
+ onMouseDown: (event) => {
1270
+ if (event.target === event.currentTarget && !state.busy) closeCapabilityDetail()
1271
+ },
1272
+ },
1273
+ h('div', {
1274
+ ref: dialogRef,
1275
+ tabIndex: -1,
1276
+ className: 'dsh-collab-base-dialog',
1277
+ role: 'dialog',
1278
+ 'aria-modal': 'true',
1279
+ 'aria-labelledby': 'dsh-collab-cap-title',
1280
+ },
1281
+ h('div', { className: 'dsh-collab-cap-head' },
1282
+ h('h2', { id: 'dsh-collab-cap-title', className: 'dsh-collab-base-title' },
1283
+ capability?.name ?? shortId(relationship.worker))),
1284
+ detailField(props.t('board.workerId'), h('code', { className: 'dsh-collab-cap-value' }, relationship.worker)),
1285
+ detailField(props.t('board.source'), h('span', { className: 'dsh-collab-cap-value' },
1286
+ pinned ? props.t('board.sourceOverride') : props.t('board.sourceLive'),
1287
+ capability?.changed === true
1288
+ ? h('span', { className: 'dsh-collab-board-status', 'data-warn': 'true', style: { marginLeft: 6 } }, props.t('board.changed'))
1289
+ : null)),
1290
+ detailField(props.t('board.version'), h('code', { className: 'dsh-collab-cap-value' }, capability?.version ?? '-')),
1291
+
1292
+ detailField(props.t('board.description'),
1293
+ h(React.Fragment, null,
1294
+ rawDescription.length === 0
1295
+ ? h('p', { className: 'dsh-collab-cap-desc' }, props.t('board.noDescription'))
1296
+ : h(React.Fragment, null,
1297
+ h('div', { className: 'dsh-collab-cap-tools' },
1298
+ h('input', {
1299
+ className: 'dsh-collab-cap-search',
1300
+ type: 'search',
1301
+ value: query,
1302
+ placeholder: props.t('board.search'),
1303
+ onChange: (event) => setQuery(event.target.value),
1304
+ }),
1305
+ queryText.length === 0
1306
+ ? null
1307
+ : h('span', { className: 'dsh-collab-cap-count' }, `${String(matchCount)}`),
1308
+ canCollapse && queryText.length === 0
1309
+ ? h('button', {
1310
+ type: 'button',
1311
+ className: 'dsh-collab-base-button',
1312
+ onClick: () => setExpanded(value => !value),
1313
+ }, expanded ? props.t('board.collapse') : props.t('board.expand'))
1314
+ : null),
1315
+ h('pre', { className: 'dsh-collab-cap-desc', 'data-collapsed': collapsed ? 'true' : 'false' }, descriptionBody)))),
1316
+ state.error === null
1317
+ ? null
1318
+ : h('p', { className: 'dsh-collab-base-error', role: 'alert' }, state.error),
1319
+ h('div', { className: 'dsh-collab-base-actions' },
1320
+ h('button', {
1321
+ type: 'button',
1322
+ className: 'dsh-collab-base-button',
1323
+ disabled: state.busy || pinned,
1324
+ onClick: () => { void applyMode('pin') },
1325
+ }, props.t('board.pin')),
1326
+ h('button', {
1327
+ type: 'button',
1328
+ className: 'dsh-collab-base-button',
1329
+ 'data-primary': 'true',
1330
+ disabled: state.busy || !pinned,
1331
+ onClick: () => { void applyMode('live') },
1332
+ }, props.t('board.useLive')),
1333
+ h('button', {
1334
+ type: 'button',
1335
+ className: 'dsh-collab-base-button',
1336
+ disabled: state.busy,
1337
+ onClick: closeCapabilityDetail,
1338
+ }, props.t('board.close'))))))
1339
+ }
1340
+
1341
+ async function loadBasePrompt(sessionId) {
1342
+ if (executeBasePromptCommand === null) throw new Error('command executor is not ready')
1343
+ const result = await executeBasePromptCommand(sessionId, '/collab-base get')
1344
+ return parseBasePromptResult(result)
1345
+ }
1346
+
1347
+ async function openBasePromptEditor(sessionId, sessionTitle) {
1348
+ updateBasePromptState({
1349
+ open: true,
1350
+ sessionId,
1351
+ sessionTitle: typeof sessionTitle === 'string' ? sessionTitle : '',
1352
+ value: '',
1353
+ loading: true,
1354
+ saving: false,
1355
+ error: null,
1356
+ })
1357
+ try {
1358
+ const value = await loadBasePrompt(sessionId)
1359
+ if (basePromptStore.open && basePromptStore.sessionId === sessionId) {
1360
+ updateBasePromptState({ value, loading: false })
1361
+ }
1362
+ } catch (error) {
1363
+ if (basePromptStore.open && basePromptStore.sessionId === sessionId) {
1364
+ updateBasePromptState({ loading: false, error: error instanceof Error ? error.message : String(error) })
1365
+ }
1366
+ }
1367
+ }
1368
+
1369
+ function closeBasePromptEditor() {
1370
+ updateBasePromptState({ open: false, sessionId: null, sessionTitle: '', value: '', loading: false, saving: false, error: null })
1371
+ }
1372
+
1373
+ async function writeBasePrompt(sessionId, value) {
1374
+ if (executeBasePromptCommand === null) throw new Error('command executor is not ready')
1375
+ const encoded = encodeBasePrompt(value)
1376
+ const result = await executeBasePromptCommand(sessionId, `/collab-base set ${encoded}`)
1377
+ return parseBasePromptResult(result)
1378
+ }
1379
+
1380
+ async function saveBasePromptEditor() {
1381
+ const sessionId = basePromptStore.sessionId
1382
+ if (sessionId === null) return
1383
+ updateBasePromptState({ saving: true, error: null })
1384
+ try {
1385
+ await writeBasePrompt(sessionId, basePromptStore.value)
1386
+ if (basePromptStore.open && basePromptStore.sessionId === sessionId) {
1387
+ updateBasePromptState({ open: false, saving: false, sessionId: null, sessionTitle: '', value: '' })
1388
+ }
1389
+ } catch (error) {
1390
+ updateBasePromptState({
1391
+ saving: false,
1392
+ error: error instanceof Error ? error.message : String(error),
1393
+ })
1394
+ }
1395
+ }
1396
+
1397
+ function CollabBasePromptEditor(props) {
1398
+ const state = useBasePromptState()
1399
+ const dialogRef = React.useRef(null)
1400
+ useDialogFocus(dialogRef, state.open, closeBasePromptEditor, state.saving)
1401
+ if (!state.open) return null
1402
+ return h(React.Fragment, null,
1403
+ h('style', null, BASE_CSS),
1404
+ h('div', {
1405
+ className: 'dsh-collab-base-overlay',
1406
+ onMouseDown: (event) => {
1407
+ if (event.target === event.currentTarget && !state.saving) closeBasePromptEditor()
1408
+ },
1409
+ },
1410
+ h('div', {
1411
+ ref: dialogRef,
1412
+ tabIndex: -1,
1413
+ className: 'dsh-collab-base-dialog',
1414
+ role: 'dialog',
1415
+ 'aria-modal': 'true',
1416
+ 'aria-labelledby': 'dsh-collab-base-title',
1417
+ 'aria-describedby': 'dsh-collab-base-desc',
1418
+ },
1419
+ h('h2', { id: 'dsh-collab-base-title', className: 'dsh-collab-base-title' }, props.t('base.title')),
1420
+ state.sessionTitle.length === 0
1421
+ ? null
1422
+ : h('p', { className: 'dsh-collab-base-session' }, `${props.t('base.session')}: ${state.sessionTitle}`),
1423
+ h('p', { id: 'dsh-collab-base-desc', className: 'dsh-collab-base-desc' }, props.t('base.description')),
1424
+ state.loading
1425
+ ? h('p', { className: 'dsh-collab-base-loading' }, props.t('base.loading'))
1426
+ : h('textarea', {
1427
+ className: 'dsh-collab-base-textarea',
1428
+ value: state.value,
1429
+ maxLength: BASE_MAX,
1430
+ rows: 9,
1431
+ autoFocus: true,
1432
+ placeholder: props.t('base.placeholder'),
1433
+ onChange: (event) => { updateBasePromptState({ value: event.target.value }) },
1434
+ }),
1435
+ state.error === null
1436
+ ? null
1437
+ : h('p', { className: 'dsh-collab-base-error', role: 'alert' },
1438
+ `${props.t('base.error')}: ${state.error}`),
1439
+ h('div', { className: 'dsh-collab-base-actions' },
1440
+ h('button', {
1441
+ type: 'button',
1442
+ className: 'dsh-collab-base-button',
1443
+ onClick: closeBasePromptEditor,
1444
+ }, props.t('base.cancel')),
1445
+ h('button', {
1446
+ type: 'button',
1447
+ className: 'dsh-collab-base-button',
1448
+ 'data-primary': 'true',
1449
+ disabled: state.loading || state.saving,
1450
+ onClick: () => { void saveBasePromptEditor() },
1451
+ }, state.saving ? props.t('base.saving') : props.t('base.save'))))))
1452
+ }
1453
+
1454
+ function CollabBasePromptMenuItem(props) {
1455
+ const sessions = props.useSessions(selectSnapshot)
1456
+ const summary = sessions.byId[props.sessionId]
1457
+ const [, setMenuOpen] = props.useMenuOpenState()
1458
+ if (!isCollabSummary(summary, sessions)) return null
1459
+ const select = () => {
1460
+ setMenuOpen(false)
1461
+ void openBasePromptEditor(props.sessionId, props.displayTitle || summary?.displayTitle || props.sessionId)
1462
+ }
1463
+ return typeof MenuItemButton === 'function'
1464
+ ? h(MenuItemButton, { onSelect: select }, h('span', null, props.t('base.menu')))
1465
+ : h('button', {
1466
+ type: 'button',
1467
+ role: 'menuitem',
1468
+ className: 'dsh-collab-menu-item',
1469
+ onClick: select,
1470
+ }, props.t('base.menu'))
1471
+ }
1472
+
1473
+ const BOARD_CSS = [
1474
+ '.dsh-collab-board{display:flex;flex-direction:column;gap:12px;height:100%;min-height:0;overflow-y:auto;padding:12px;box-sizing:border-box;color:var(--dsw-alias-label-primary);font-size:12px;line-height:18px}',
1475
+ '.dsh-collab-board-head{display:flex;align-items:center;justify-content:flex-start;gap:10px}',
1476
+ '.dsh-collab-board-title{margin:0;font-size:14px;line-height:20px;font-weight:600}',
1477
+ '.dsh-collab-board-section{display:flex;flex-direction:column;gap:6px;border:0.5px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1);padding:10px}',
1478
+ '.dsh-collab-board-section-title{margin:0;font-size:12px;font-weight:600}',
1479
+ '.dsh-collab-board-muted{color:var(--dsw-alias-label-secondary);font-size:11px;line-height:16px;margin:0}',
1480
+ '.dsh-collab-board-row{display:flex;align-items:center;gap:6px;padding:5px 6px;border-radius:6px;min-width:0}',
1481
+ '.dsh-collab-board-row:hover{background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2))}',
1482
+ '.dsh-collab-board-row[data-selected="true"]{background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2));outline:0.5px solid var(--dsw-alias-border-l2);outline-offset:-0.5px}',
1483
+ '.dsh-collab-board-row[data-clickable="true"]{cursor:pointer}',
1484
+ '.dsh-collab-board-locate{flex:none;color:var(--dsw-alias-label-tertiary);font-size:11px}',
1485
+ '[data-collab-focus="true"]{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:3px;border-radius:8px;transition:outline-color .2s ease}',
1486
+ '.dsh-collab-board-row-main{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
1487
+ '.dsh-collab-board-id{flex:none;color:var(--dsw-alias-label-tertiary);font-family:var(--dsh-font-mono,monospace);font-size:10px}',
1488
+ '.dsh-collab-board-status{flex:none;padding:0 6px;border-radius:999px;border:0.5px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);font-size:10px;line-height:16px}',
1489
+ '.dsh-collab-board-status[data-warn="true"]{color:var(--dsw-alias-state-warning-primary,var(--dsw-alias-brand-primary));border-color:currentColor}',
1490
+ '.dsh-collab-board-button{flex:none;height:24px;padding:0 8px;border:0.5px solid var(--dsw-alias-border-l2);border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:11px;cursor:pointer}',
1491
+ '.dsh-collab-board-button:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2))}',
1492
+ '.dsh-collab-board-button:disabled{opacity:.45;cursor:default}',
1493
+ '.dsh-collab-board-button[data-primary="true"]{background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-bg-base)}',
1494
+ '.dsh-collab-board-button[data-primary="true"]:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover,var(--dsw-alias-brand-primary));border-color:var(--dsw-alias-button-primary-hover,var(--dsw-alias-brand-primary));color:var(--dsw-alias-bg-base)}',
1495
+ '.dsh-collab-board-input,.dsh-collab-board-select,.dsh-collab-board-textarea{width:100%;box-sizing:border-box;padding:6px 8px;border:0.5px solid var(--dsw-alias-border-l2);border-radius:6px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;line-height:18px;outline:none}',
1496
+ '.dsh-collab-board-textarea{min-height:48px;resize:vertical}',
1497
+ '.dsh-collab-board-form{display:flex;flex-direction:column;gap:6px}',
1498
+ '.dsh-collab-board-actions{display:flex;align-items:center;justify-content:flex-end;gap:6px;flex-wrap:wrap}',
1499
+ '.dsh-collab-board-actions[data-align="start"]{justify-content:flex-start}',
1500
+ '.dsh-collab-board-open{appearance:none;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;line-height:20px;padding:2px 6px;cursor:pointer}',
1501
+ '.dsh-collab-board-open:hover{background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2));color:var(--dsw-alias-label-primary)}',
1502
+ '.dsh-collab-board-error{margin:0;color:var(--dsw-alias-state-error-primary);font-size:11px;line-height:16px}',
1503
+ '.dsh-collab-board-notice{margin:0;padding:6px 8px;border:0.5px solid var(--dsw-alias-state-success-primary,var(--dsw-alias-border-l2));border-radius:6px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-state-success-primary,var(--dsw-alias-label-primary));font-size:11px;line-height:16px}',
1504
+ ].join('')
1505
+
1506
+ function isSupervisorSessionSummary(summary, state) {
1507
+ const values = summary?.projectionValues ?? state?.projectionsBySession?.[summary?.id]?.values
1508
+ return values?.agentPreset === 'supervisor'
1509
+ }
1510
+
1511
+ /** Best-effort turn lookup for tasks created before turn recording. */
1512
+ function taskTurnFromChat(chat, task) {
1513
+ if (chat === undefined || chat === null) return null
1514
+ const nodes = typeof chat.nodes?.values === 'function' ? chat.nodes.values() : []
1515
+ let found = null
1516
+ for (const node of nodes) {
1517
+ if (node?.kind !== 'tool-call') continue
1518
+ const root = node.data?.root
1519
+ const raw = typeof root?.call?.argsRaw === 'string'
1520
+ ? root.call.argsRaw
1521
+ : (typeof root?.argsRaw === 'string' ? root.argsRaw : '')
1522
+ if (raw.length === 0 || typeof root?.turn !== 'number') continue
1523
+ const idMatch = raw.match(/"taskId"\s*:\s*"([^"]+)"/u)
1524
+ if (idMatch?.[1] !== task.id && !raw.includes(JSON.stringify(task.title))) continue
1525
+ found = root.turn
1526
+ }
1527
+ return found
1528
+ }
1529
+
1530
+ function SupervisorBoardTab(props) {
1531
+ const t = typeof props.t === 'function' ? props.t : fallbackT
1532
+ const mode = props.mode === 'workers' ? 'workers' : 'tasks'
1533
+ const [data, setData] = React.useState(null)
1534
+ const [loading, setLoading] = React.useState(true)
1535
+ const [error, setError] = React.useState(null)
1536
+ const [notice, setNotice] = React.useState(null)
1537
+ const [busy, setBusy] = React.useState(false)
1538
+ const noticeTimerRef = React.useRef(null)
1539
+ const [requestPage, setRequestPage] = React.useState(0)
1540
+ const [selectedRequestId, setSelectedRequestId] = React.useState(null)
1541
+ const chat = typeof props.useChat === 'function' ? props.useChat(snapshot => snapshot) : undefined
1542
+
1543
+ const load = async () => {
1544
+ setLoading(true)
1545
+ setError(null)
1546
+ try {
1547
+ const result = await props.panel(props.sessionId, 'board', {})
1548
+ if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`)
1549
+ setData(JSON.parse(result.value))
1550
+ } catch (failure) {
1551
+ setError(`${t('board.error')}: ${failure instanceof Error ? failure.message : String(failure)}`)
1552
+ } finally {
1553
+ setLoading(false)
1554
+ }
1555
+ }
1556
+
1557
+ React.useEffect(() => { void load() }, [props.sessionId])
1558
+
1559
+ React.useEffect(() => {
1560
+ const reload = (event) => {
1561
+ const action = event?.detail?.action
1562
+ if (action === 'pin') setNotice(t('board.pinnedNotice'))
1563
+ else if (action === 'live') setNotice(t('board.liveNotice'))
1564
+ if (action !== undefined) {
1565
+ if (noticeTimerRef.current !== null) window.clearTimeout(noticeTimerRef.current)
1566
+ noticeTimerRef.current = window.setTimeout(() => setNotice(null), 2600)
1567
+ }
1568
+ void load()
1569
+ }
1570
+ window.addEventListener('dsh-collab-board-refresh', reload)
1571
+ return () => { window.removeEventListener('dsh-collab-board-refresh', reload) }
1572
+ }, [props.sessionId])
1573
+
1574
+ const offer = async (entry) => {
1575
+ setBusy(true)
1576
+ setError(null)
1577
+ try {
1578
+ const result = await props.panel(props.sessionId, 'link', { worker: entry.sessionId, payload: { offer: true } })
1579
+ if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`)
1580
+ if (typeof window !== 'undefined') window.dispatchEvent(new Event('dsh-collab-auth-changed'))
1581
+ await load()
1582
+ } catch (failure) {
1583
+ setError(`${t('board.error')}: ${failure instanceof Error ? failure.message : String(failure)}`)
1584
+ } finally {
1585
+ setBusy(false)
1586
+ }
1587
+ }
1588
+
1589
+ const unlink = async (workerId) => {
1590
+ if (typeof window !== 'undefined' && typeof window.confirm === 'function' && !window.confirm(t('board.confirmUnlink'))) return
1591
+ setBusy(true)
1592
+ setError(null)
1593
+ try {
1594
+ const result = await props.panel(props.sessionId, 'unlink', { worker: workerId })
1595
+ if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`)
1596
+ if (typeof window !== 'undefined') window.dispatchEvent(new Event('dsh-collab-auth-changed'))
1597
+ await load()
1598
+ } catch (failure) {
1599
+ setError(`${t('board.error')}: ${failure instanceof Error ? failure.message : String(failure)}`)
1600
+ } finally {
1601
+ setBusy(false)
1602
+ }
1603
+ }
1604
+
1605
+ const workers = data?.workers ?? []
1606
+ const linked = (data?.relationships ?? []).filter(rel => rel.offer === true)
1607
+ const available = workers.filter(entry => !linked.some(rel => rel.worker === entry.sessionId))
1608
+ const subtasks = data?.tasks ?? []
1609
+ const parentTasks = data?.tasks ?? []
1610
+ const requests = data?.requests ?? []
1611
+ const statusText = (status) => {
1612
+ const key = `status.${String(status)}`
1613
+ const localized = t(key)
1614
+ return localized === key ? String(status) : localized
1615
+ }
1616
+ const requestPageCount = Math.max(1, Math.ceil(requests.length / 5))
1617
+ const safeRequestPage = Math.min(requestPage, requestPageCount - 1)
1618
+ const pageRequests = requests.slice(
1619
+ safeRequestPage * 5,
1620
+ safeRequestPage * 5 + 5,
1621
+ )
1622
+ const pageRequestIds = pageRequests.map(request => request.id).join('\u0000')
1623
+ const selectedRequest = requests.find(request => request.id === selectedRequestId)
1624
+ ?? pageRequests[0]
1625
+ ?? null
1626
+ const selectedParentTask = selectedRequest === null
1627
+ ? null
1628
+ : (parentTasks.find(task => task.id === (selectedRequest.taskId ?? selectedRequest.projectId))
1629
+ ?? parentTasks.find(task => task.requestId === selectedRequest.id)
1630
+ ?? null)
1631
+ const selectedSubtasks = selectedParentTask === null
1632
+ ? []
1633
+ : subtasks.filter(task => (task.taskId ?? task.projectId) === selectedParentTask.id)
1634
+ React.useEffect(() => {
1635
+ if (requestPage !== safeRequestPage) setRequestPage(safeRequestPage)
1636
+ }, [requestPage, safeRequestPage])
1637
+ React.useEffect(() => {
1638
+ if (pageRequests.length === 0) {
1639
+ if (selectedRequestId !== null) setSelectedRequestId(null)
1640
+ return
1641
+ }
1642
+ if (!pageRequests.some(request => request.id === selectedRequestId)) {
1643
+ setSelectedRequestId(pageRequests[0].id)
1644
+ }
1645
+ }, [safeRequestPage, pageRequestIds, selectedRequestId])
1646
+
1647
+ const focusTask = (task) => {
1648
+ let turn = Number.isInteger(task.assignedTurn)
1649
+ ? task.assignedTurn
1650
+ : (Number.isInteger(task.createdTurn) ? task.createdTurn : null)
1651
+ if (turn === null) turn = taskTurnFromChat(chat, task)
1652
+ if (turn === null) {
1653
+ setError(t('board.noLocation'))
1654
+ return
1655
+ }
1656
+ setError(null)
1657
+ try { props.openSession?.(props.sessionId) } catch { /* the current session may already be shown */ }
1658
+ let settled = false
1659
+ const chatScroller = () => {
1660
+ const anchor = document.querySelector('[data-turn-process], [data-turn-tail]')
1661
+ let node = anchor?.parentElement ?? null
1662
+ while (node !== null) {
1663
+ const style = window.getComputedStyle(node)
1664
+ if (/(auto|scroll)/u.test(style.overflowY) && node.scrollHeight > node.clientHeight) return node
1665
+ node = node.parentElement
1666
+ }
1667
+ return document.scrollingElement
1668
+ }
1669
+ const nudgeOlderTurns = () => {
1670
+ const scroller = chatScroller()
1671
+ if (scroller === null) return
1672
+ scroller.scrollTop = 0
1673
+ scroller.dispatchEvent(new Event('scroll', { bubbles: true }))
1674
+ }
1675
+ const reveal = () => {
1676
+ if (settled) return
1677
+ const processElement = document.querySelector(`[data-turn-process="${turn}"]`)
1678
+ const tailElement = document.querySelector(`[data-turn-tail="${turn}"]`)
1679
+ const element = processElement !== null && processElement.getClientRects().length > 0
1680
+ ? processElement
1681
+ : (tailElement ?? processElement)
1682
+ if (element === null) {
1683
+ // DSH virtualizes long conversations; scrolling to the oldest loaded
1684
+ // turn asks the chat pager to render the page that owns this turn.
1685
+ nudgeOlderTurns()
1686
+ return
1687
+ }
1688
+ settled = true
1689
+ element.scrollIntoView({ behavior: 'smooth', block: 'center' })
1690
+ element.setAttribute('data-collab-focus', 'true')
1691
+ window.setTimeout(() => element.removeAttribute('data-collab-focus'), 1500)
1692
+ }
1693
+ reveal()
1694
+ for (const delay of [80, 180, 360, 700, 1200, 1800, 2500]) window.setTimeout(reveal, delay)
1695
+ window.setTimeout(() => { if (!settled) setError(t('board.notFound')) }, 3000)
1696
+ }
1697
+
1698
+ const headerActions = []
1699
+ headerActions.push(h('button', {
1700
+ type: 'button',
1701
+ className: 'dsh-collab-board-button',
1702
+ disabled: loading || busy,
1703
+ onClick: () => { void load() },
1704
+ }, t('board.refresh')))
1705
+
1706
+ return h('div', { className: 'dsh-collab-board' },
1707
+ h('style', null, BOARD_CSS),
1708
+ h('div', { className: 'dsh-collab-board-head' },
1709
+ h('h2', { className: 'dsh-collab-board-title' }, mode === 'tasks' ? t('board.tasksTitle') : t('board.workersTitle')),
1710
+ h('div', { className: 'dsh-collab-board-actions' }, ...headerActions)),
1711
+ error === null ? null : h('p', { className: 'dsh-collab-board-error', role: 'alert' }, error),
1712
+ notice === null ? null : h('p', { className: 'dsh-collab-board-notice', role: 'status' }, notice),
1713
+ loading ? h('p', { className: 'dsh-collab-board-muted' }, t('board.loading')) : null,
1714
+ mode === 'workers'
1715
+ ? h(React.Fragment, null,
1716
+ h('section', { className: 'dsh-collab-board-section' },
1717
+ h('h3', { className: 'dsh-collab-board-section-title' }, t('board.workers')),
1718
+ linked.length === 0
1719
+ ? h('p', { className: 'dsh-collab-board-muted' }, t('board.emptyWorkers'))
1720
+ : linked.map(rel => h('div', {
1721
+ key: rel.worker,
1722
+ className: 'dsh-collab-board-row',
1723
+ 'data-clickable': 'true',
1724
+ role: 'button',
1725
+ tabIndex: 0,
1726
+ title: t('board.viewDetails'),
1727
+ onClick: () => openCapabilityDetail(props.sessionId, rel),
1728
+ onKeyDown: (event) => {
1729
+ if (event.key !== 'Enter' && event.key !== ' ') return
1730
+ event.preventDefault()
1731
+ openCapabilityDetail(props.sessionId, rel)
1732
+ },
1733
+ },
1734
+ h('span', { className: 'dsh-collab-board-row-main' }, rel.capability?.name ?? shortId(rel.worker)),
1735
+ h('code', { className: 'dsh-collab-board-id' }, shortId(rel.worker)),
1736
+ h('span', { className: 'dsh-collab-board-status' }, 'offer'),
1737
+ h('button', {
1738
+ type: 'button',
1739
+ className: 'dsh-collab-board-button',
1740
+ disabled: busy,
1741
+ onClick: (event) => {
1742
+ event.stopPropagation()
1743
+ void unlink(rel.worker)
1744
+ },
1745
+ onKeyDown: (event) => { event.stopPropagation() },
1746
+ }, t('board.unlink'))))),
1747
+ h('section', { className: 'dsh-collab-board-section' },
1748
+ h('h3', { className: 'dsh-collab-board-section-title' }, t('board.available')),
1749
+ available.length === 0
1750
+ ? h('p', { className: 'dsh-collab-board-muted' }, t('board.emptyAvailable'))
1751
+ : available.map(entry => h('div', { key: entry.sessionId, className: 'dsh-collab-board-row' },
1752
+ h('span', { className: 'dsh-collab-board-row-main' },
1753
+ entry.capability?.name ?? entry.title ?? shortId(entry.sessionId),
1754
+ typeof entry.capability?.description === 'string' && entry.capability.description.trim().length > 0
1755
+ ? h('span', { className: 'dsh-collab-board-muted' }, ` · ${entry.capability.description.trim().slice(0, 120)}`)
1756
+ : null),
1757
+ h('code', { className: 'dsh-collab-board-id' }, shortId(entry.sessionId)),
1758
+ h('button', {
1759
+ type: 'button',
1760
+ className: 'dsh-collab-board-button',
1761
+ 'data-primary': 'true',
1762
+ disabled: busy,
1763
+ onClick: () => { void offer(entry) },
1764
+ }, t('board.offer'))))))
1765
+ : h(React.Fragment, null,
1766
+ h('section', { className: 'dsh-collab-board-section' },
1767
+ h('div', { className: 'dsh-collab-board-head' },
1768
+ h('h3', { className: 'dsh-collab-board-section-title' }, t('board.requests')),
1769
+ h('span', { className: 'dsh-collab-board-status' }, String(requests.length))),
1770
+ requests.length === 0
1771
+ ? h('p', { className: 'dsh-collab-board-muted' }, t('board.emptyRequests'))
1772
+ : h(React.Fragment, null,
1773
+ h('div', { className: 'dsh-collab-auth-list' },
1774
+ pageRequests.map(request => h('div', {
1775
+ key: request.id,
1776
+ className: 'dsh-collab-board-row',
1777
+ 'data-selected': selectedRequest?.id === request.id ? 'true' : undefined,
1778
+ 'data-clickable': 'true',
1779
+ role: 'button',
1780
+ tabIndex: 0,
1781
+ onClick: () => setSelectedRequestId(request.id),
1782
+ onKeyDown: (event) => {
1783
+ if (event.key !== 'Enter' && event.key !== ' ') return
1784
+ event.preventDefault()
1785
+ setSelectedRequestId(request.id)
1786
+ },
1787
+ },
1788
+ h('span', { className: 'dsh-collab-board-row-main' },
1789
+ request.title,
1790
+ request.reason === undefined ? null : h('span', { className: 'dsh-collab-board-muted' }, ` · ${request.reason}`)),
1791
+ h('code', { className: 'dsh-collab-board-id' }, request.requesterTitle ?? shortId(request.requester)),
1792
+ h('span', { className: 'dsh-collab-board-status' }, statusText(request.status))))),
1793
+ requestPageCount > 1
1794
+ ? h('div', { className: 'dsh-collab-board-actions', 'data-align': 'start' },
1795
+ h('button', {
1796
+ type: 'button',
1797
+ className: 'dsh-collab-board-button',
1798
+ disabled: safeRequestPage === 0,
1799
+ onClick: () => setRequestPage(page => Math.max(0, page - 1)),
1800
+ }, t('board.prevPage')),
1801
+ h('span', { className: 'dsh-collab-board-muted' }, `${safeRequestPage + 1} / ${requestPageCount}`),
1802
+ h('button', {
1803
+ type: 'button',
1804
+ className: 'dsh-collab-board-button',
1805
+ disabled: safeRequestPage >= requestPageCount - 1,
1806
+ onClick: () => setRequestPage(page => Math.min(requestPageCount - 1, page + 1)),
1807
+ }, t('board.nextPage')))
1808
+ : null)),
1809
+ selectedRequest === null
1810
+ ? null
1811
+ : h('section', { className: 'dsh-collab-board-section' },
1812
+ h('div', { className: 'dsh-collab-board-head' },
1813
+ h('h3', { className: 'dsh-collab-board-section-title' }, selectedRequest.title),
1814
+ h('span', { className: 'dsh-collab-board-status' }, statusText(selectedRequest.status))),
1815
+ h('p', { className: 'dsh-collab-board-muted' },
1816
+ `${t('board.requester')}: ${selectedRequest.requesterTitle ?? shortId(selectedRequest.requester)}`),
1817
+ selectedParentTask === null
1818
+ ? h('p', { className: 'dsh-collab-board-muted' }, t('board.noLinkedTask'))
1819
+ : h(React.Fragment, null,
1820
+ h('div', { className: 'dsh-collab-board-head' },
1821
+ h('h4', { className: 'dsh-collab-board-section-title' }, selectedParentTask.title),
1822
+ h('span', { className: 'dsh-collab-board-status' }, t('board.parentTask')),
1823
+ h('span', { className: 'dsh-collab-board-status' }, statusText(selectedParentTask.status))),
1824
+ selectedSubtasks.length === 0
1825
+ ? h('p', { className: 'dsh-collab-board-muted' }, t('board.emptyTasks'))
1826
+ : selectedSubtasks.map(task => h('div', {
1827
+ key: task.id,
1828
+ className: 'dsh-collab-board-row',
1829
+ 'data-clickable': 'true',
1830
+ role: 'button',
1831
+ tabIndex: 0,
1832
+ title: t('board.locate'),
1833
+ onClick: () => focusTask(task),
1834
+ onKeyDown: (event) => {
1835
+ if (event.key !== 'Enter' && event.key !== ' ') return
1836
+ event.preventDefault()
1837
+ focusTask(task)
1838
+ },
1839
+ },
1840
+ h('span', { className: 'dsh-collab-board-row-main' }, task.title),
1841
+ h('span', { className: 'dsh-collab-board-status' }, t('board.subtask')),
1842
+ h('code', { className: 'dsh-collab-board-id' }, ` ${t('board.worker')}: ${task.workerTitle ?? shortId(task.worker ?? '-')}`),
1843
+ h('span', { className: 'dsh-collab-board-locate', 'aria-hidden': 'true' }, '↗'),
1844
+ h('span', { className: 'dsh-collab-board-status' }, statusText(task.status))))),
1845
+ )))
1846
+ }
1847
+
1848
+ function CollabBoardTabTitle(props) {
1849
+ const t = typeof props.t === 'function' ? props.t : fallbackT
1850
+ const { tab } = props.useTabInfo()
1851
+ return h('span', { className: 'dsh-collab-board-tab-title' },
1852
+ tab?.kind === WORKERS_TAB_KIND ? t('board.workersTitle') : t('board.tasksTitle'))
1853
+ }
1854
+
1855
+ function CollabPresetMenuFilter(props) {
1856
+ const t = typeof props.t === 'function' ? props.t : fallbackT
1857
+ React.useEffect(() => {
1858
+ const translatePresetCopy = () => {
1859
+ const pairs = [
1860
+ ['协同会话', t('preset.collabName')],
1861
+ ['超级会话', t('preset.supervisorName')],
1862
+ ['拥有独立的 .dsh-collab 工作目录、共享的 comm/ 目录和仅本会话可访问的 private/ 目录,并提供经过身份验证的会话间通信工具。', t('preset.collabDescription')],
1863
+ ['负责拆解需求、把子任务分派给已登记的功能会话、核验结果并完成交付;不提供任何实现类工具。', t('preset.supervisorDescription')],
1864
+ ]
1865
+ for (const node of document.querySelectorAll('span, div, p, button')) {
1866
+ if (node.children.length !== 0) continue
1867
+ const text = node.textContent ?? ''
1868
+ const pair = pairs.find(([source]) => text === source)
1869
+ if (pair !== undefined && pair[1] !== pair[0]) node.textContent = pair[1]
1870
+ }
1871
+ }
1872
+ const hideLockedPresets = () => {
1873
+ translatePresetCopy()
1874
+ for (const node of document.querySelectorAll('[role="menuitem"]')) {
1875
+ // The collab entry's own dropdown also uses role=menuitem.
1876
+ if (node.closest('.dsh-collab-new-menu') !== null) continue
1877
+ const text = node.textContent ?? ''
1878
+ if (!/(协同会话|超级会话|Collab session|Supervisor session)/u.test(text)) continue
1879
+ node.hidden = true
1880
+ node.setAttribute('aria-hidden', 'true')
1881
+ node.style.setProperty('display', 'none', 'important')
1882
+ }
1883
+ }
1884
+ hideLockedPresets()
1885
+ const observer = new MutationObserver(hideLockedPresets)
1886
+ observer.observe(document.body, { childList: true, subtree: true })
1887
+ return () => observer.disconnect()
1888
+ }, [t])
1889
+ return null
1890
+ }
1891
+
1892
+ function CollabPresetLockProbe(props) {
1893
+ const useSessions = typeof props.useSessions === 'function' ? props.useSessions : () => undefined
1894
+ const sessions = useSessions(selectSnapshot)
1895
+ const values = sessions?.byId?.[props.sessionId]?.projectionValues
1896
+ ?? sessions?.projectionsBySession?.[props.sessionId]?.values
1897
+ const locked = values?.agentPreset === 'collab' || values?.agentPreset === 'supervisor'
1898
+ React.useEffect(() => {
1899
+ if (!locked) return undefined
1900
+ const root = document.documentElement
1901
+ root.setAttribute('data-collab-preset-lock', 'true')
1902
+ return () => root.removeAttribute('data-collab-preset-lock')
1903
+ }, [locked])
1904
+ return h('style', null,
1905
+ 'html[data-collab-preset-lock="true"] button[aria-haspopup="menu"][title*="Agent 预设"],'
1906
+ + 'html[data-collab-preset-lock="true"] button[aria-haspopup="menu"][title*="Agent preset"]{display:none!important}')
1907
+ }
1908
+
1909
+ function CollabSupervisorTabsOnOpen(props) {
1910
+ const sessions = props.useSessions(selectSnapshot)
1911
+ const summary = sessions.byId[props.sessionId]
1912
+ const supervisor = isSupervisorSessionSummary(summary, sessions)
1913
+ React.useEffect(() => {
1914
+ if (!supervisor) return undefined
1915
+ let wasExpanded = false
1916
+ const seed = () => {
1917
+ const expanded = props.isExpanded()
1918
+ if (!expanded) {
1919
+ wasExpanded = false
1920
+ return
1921
+ }
1922
+ if (wasExpanded) return
1923
+ wasExpanded = true
1924
+ props.openGuide(props.sessionId)
1925
+ props.openTasks(props.sessionId)
1926
+ props.openWorkers(props.sessionId)
1927
+ }
1928
+ seed()
1929
+ const timer = setInterval(seed, 200)
1930
+ return () => clearInterval(timer)
1931
+ }, [supervisor, props.sessionId])
1932
+ return null
1933
+ }
1934
+
1935
+ return {
1936
+ __test: { isCollabSummary, isSupervisorSessionSummary, parseBasePromptCommand },
1937
+ inject: ['slots', 'locale', 'uiWorkspace', 'sessions', 'remote', 'remote.commands', 'remote.collabAuth', 'uiConversation', 'layout', 'sidebarRight', 'sidebarRightTabs'],
1938
+ apply(ctx) {
1939
+ ctx.effect(() => ctx.locale.register(NS, { zh: ZH, en: EN }), 'collab-sessions: dictionaries')
1940
+ const authUnavailable = { ok: false, error: { code: 'collab-auth-unavailable', message: 'Collaboration authorization Remote is not loaded' } }
1941
+ const authPanel = {
1942
+ list: async () => ctx.remote.collabAuth === undefined ? authUnavailable : ctx.remote.collabAuth.list(),
1943
+ authorize: async (a, b) => ctx.remote.collabAuth === undefined ? authUnavailable : ctx.remote.collabAuth.authorize(a, b),
1944
+ revoke: async (a, b) => ctx.remote.collabAuth === undefined ? authUnavailable : ctx.remote.collabAuth.revoke(a, b),
1945
+ }
1946
+ const callPanel = (sessionId, operation, args) => {
1947
+ if (ctx.remote.collabAuth === undefined) return Promise.resolve(authUnavailable)
1948
+ return ctx.remote.collabAuth.panel(sessionId, operation, JSON.stringify(args ?? {}))
1949
+ }
1950
+
1951
+ const panelCommand = async (sessionId, operation, args) => {
1952
+ try {
1953
+ const result = await callPanel(sessionId, operation, args)
1954
+ if (result === undefined || result.ok !== true) return result
1955
+ return {
1956
+ ok: true,
1957
+ value: { result: { kind: 'success', text: result.value } },
1958
+ }
1959
+ } catch (error) {
1960
+ return {
1961
+ ok: false,
1962
+ error: { code: 'collab-panel', message: error instanceof Error ? error.message : String(error) },
1963
+ }
1964
+ }
1965
+ }
1966
+
1967
+ const mainSessionPreset = () => {
1968
+ const snapshot = ctx.sessions?.list?.getSnapshot?.()
1969
+ if (snapshot === undefined) return undefined
1970
+ const main = Object.values(snapshot.byId ?? {})
1971
+ .find(session => (session.retainedBy?.mainView ?? 0) > 0)
1972
+ return main?.projectionValues?.agentPreset
1973
+ }
1974
+ const originalOpenWorkspace = typeof ctx.uiWorkspace.openWorkspace === 'function'
1975
+ ? ctx.uiWorkspace.openWorkspace.bind(ctx.uiWorkspace)
1976
+ : undefined
1977
+ if (originalOpenWorkspace !== undefined) {
1978
+ const openWorkspacePreservingPreset = (workspaceId, beforeOpen, options) => {
1979
+ if (options === undefined) {
1980
+ const preset = mainSessionPreset()
1981
+ if (preset === 'collab' || preset === 'supervisor') {
1982
+ return originalOpenWorkspace(workspaceId, beforeOpen, { agentPreset: preset })
1983
+ }
1984
+ }
1985
+ return originalOpenWorkspace(workspaceId, beforeOpen, options)
1986
+ }
1987
+ ctx.uiWorkspace.openWorkspace = openWorkspacePreservingPreset
1988
+ ctx.effect(() => () => {
1989
+ if (ctx.uiWorkspace.openWorkspace === openWorkspacePreservingPreset) {
1990
+ ctx.uiWorkspace.openWorkspace = originalOpenWorkspace
1991
+ }
1992
+ }, 'collab:workspace-switch-preset')
1993
+ }
1994
+
1995
+ const start = (preset = 'collab') => {
1996
+ try {
1997
+ // The navigation service targets the current Session's Workspace,
1998
+ // then the recent Workspace, exactly like the New Session button.
1999
+ const agentPreset = preset === 'supervisor' ? 'supervisor' : 'collab'
2000
+ ctx.uiWorkspace.startSession(undefined, { agentPreset })
2001
+ } catch (error) {
2002
+ console.error('[collab-sessions] could not start a collab session:', error)
2003
+ throw error
2004
+ }
2005
+ }
2006
+
2007
+ ctx.slots.inject('sidebar.session.action', () => ctx.slots.register({
2008
+ name: 'sidebar.session.action',
2009
+ id: 'collab-sessions',
2010
+ order: 5,
2011
+ locale: NS,
2012
+ inject: () => ({
2013
+ translate: ctx.locale.bind(NS),
2014
+ start,
2015
+ }),
2016
+ }, CollabNewSessionControls))
2017
+
2018
+ ctx.slots.inject('sidebar.workspaces.session.row.action', () => ctx.slots.register({
2019
+ name: 'sidebar.workspaces.session.row.action',
2020
+ id: 'collab-copy-title',
2021
+ order: 50,
2022
+ locale: NS,
2023
+ }, CollabCopySessionAction))
2024
+
2025
+ ctx.slots.inject('sidebar.workspaces.session.menu.item', () => ctx.slots.register({
2026
+ name: 'sidebar.workspaces.session.menu.item',
2027
+ id: 'collab-copy-title',
2028
+ order: 500,
2029
+ locale: NS,
2030
+ }, CollabCopySessionMenuItem))
2031
+
2032
+ ctx.slots.inject('shell.overlay', () => ctx.slots.register({
2033
+ name: 'shell.overlay',
2034
+ id: 'collab-copy-session-styles',
2035
+ }, CollabCopySessionStyles))
2036
+
2037
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
2038
+ name: 'sidebar.panellist',
2039
+ id: 'collab-auth',
2040
+ order: 20,
2041
+ label: () => ctx.locale.bind(NS)('panel.label'),
2042
+ }, CollabAuthIcon))
2043
+
2044
+ ctx.slots.inject('main', () => ctx.slots.register({
2045
+ name: 'main',
2046
+ key: 'collab-auth',
2047
+ locale: NS,
2048
+ inject: () => ({ auth: authPanel }),
2049
+ }, CollabAuthPanel))
2050
+
2051
+ ctx.effect(() => ctx.sidebarRightTabs.register({
2052
+ id: BOARD_TAB_ID,
2053
+ kind: BOARD_TAB_KIND,
2054
+ priority: 'builtin',
2055
+ title: () => ctx.locale.bind(NS)('board.tasksTitle'),
2056
+ }), 'collab-sessions: supervisor task board tab type')
2057
+
2058
+ ctx.effect(() => ctx.sidebarRightTabs.register({
2059
+ id: WORKERS_TAB_ID,
2060
+ kind: WORKERS_TAB_KIND,
2061
+ priority: 'builtin',
2062
+ title: () => ctx.locale.bind(NS)('board.workersTitle'),
2063
+ }), 'collab-sessions: supervisor capability board tab type')
2064
+
2065
+ ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({
2066
+ name: 'sidebar.right.pane.tab',
2067
+ key: BOARD_TAB_ID,
2068
+ locale: NS,
2069
+ inject: () => ({
2070
+ mode: 'tasks',
2071
+ panel: (sessionId, operation, args) => callPanel(sessionId, operation, args),
2072
+ openSession: (sessionId) => ctx.uiWorkspace.openSession(sessionId),
2073
+ openWorkers: (sessionId) => ctx.sidebarRight.openTab(WORKERS_TAB_KIND, { params: { sessionId } }),
2074
+ }),
2075
+ }, SupervisorBoardTab))
2076
+
2077
+ ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({
2078
+ name: 'sidebar.right.pane.tab',
2079
+ key: WORKERS_TAB_ID,
2080
+ locale: NS,
2081
+ inject: () => ({
2082
+ mode: 'workers',
2083
+ panel: (sessionId, operation, args) => callPanel(sessionId, operation, args),
2084
+ openSession: (sessionId) => ctx.uiWorkspace.openSession(sessionId),
2085
+ }),
2086
+ }, SupervisorBoardTab))
2087
+
2088
+ for (const key of [BOARD_TAB_ID, WORKERS_TAB_ID]) {
2089
+ ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register({
2090
+ name: 'sidebar.right.pane.tab.title',
2091
+ key,
2092
+ locale: NS,
2093
+ }, CollabBoardTabTitle))
2094
+ }
2095
+
2096
+ ctx.slots.inject('conversation.hero.options', () => ctx.slots.register({
2097
+ name: 'conversation.hero.options',
2098
+ id: 'collab-preset-lock',
2099
+ order: 100,
2100
+ }, CollabPresetLockProbe))
2101
+
2102
+ ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({
2103
+ name: 'conversation.session.header.utilities',
2104
+ id: 'collab-supervisor-tabs-on-open',
2105
+ order: 11,
2106
+ inject: () => ({
2107
+ isExpanded: () => ctx.sidebarRight.isExpanded(),
2108
+ openGuide: () => ctx.sidebarRight.openTab('guide', { revealIfOpened: true }),
2109
+ openTasks: (sessionId) => ctx.sidebarRight.openTab(BOARD_TAB_KIND, {
2110
+ params: { sessionId },
2111
+ revealIfOpened: false,
2112
+ }),
2113
+ openWorkers: (sessionId) => ctx.sidebarRight.openTab(WORKERS_TAB_KIND, {
2114
+ params: { sessionId },
2115
+ revealIfOpened: false,
2116
+ }),
2117
+ }),
2118
+ }, CollabSupervisorTabsOnOpen))
2119
+
2120
+ ctx.effect(
2121
+ () => ctx.uiConversation.events.register(collabAuthRefusedDefinition),
2122
+ 'collab-sessions: authorization-refusal turn data',
2123
+ )
2124
+
2125
+ ctx.slots.inject('conversation.chat.turnTail', () => ctx.slots.register({
2126
+ name: 'conversation.chat.turnTail',
2127
+ id: 'collab-auth-refused',
2128
+ order: 25,
2129
+ locale: NS,
2130
+ inject: () => ({
2131
+ openAuth: () => ctx.layout.selectPanel('collab-auth'),
2132
+ }),
2133
+ }, CollabAuthRefusedTail))
2134
+
2135
+ setBasePromptExecutor((sessionId, line) => {
2136
+ const command = parseBasePromptCommand(line)
2137
+ if (command === null) return Promise.resolve({ ok: false, error: { code: 'invalid-base', message: 'invalid base prompt command' } })
2138
+ if (command.operation === 'baseGet') return panelCommand(sessionId, 'baseGet')
2139
+ return panelCommand(sessionId, 'baseSet', { value: command.value })
2140
+ })
2141
+
2142
+ ctx.slots.inject('shell.overlay', () => ctx.slots.register({
2143
+ name: 'shell.overlay',
2144
+ id: 'collab-base-prompt',
2145
+ locale: NS,
2146
+ }, CollabBasePromptEditor))
2147
+
2148
+ ctx.slots.inject('shell.overlay', () => ctx.slots.register({
2149
+ name: 'shell.overlay',
2150
+ id: 'collab-preset-menu-filter',
2151
+ locale: NS,
2152
+ }, CollabPresetMenuFilter))
2153
+
2154
+ setLinkExecutor((sessionId, line) => {
2155
+ const match = /^\/collab-link (pin|live|unlink) ([^\s]+)$/u.exec(line)
2156
+ if (match === null) return Promise.resolve({ ok: false, error: { code: 'invalid-link', message: 'invalid worker action' } })
2157
+ return panelCommand(sessionId, match[1], { worker: match[2] })
2158
+ })
2159
+
2160
+ ctx.slots.inject('shell.overlay', () => ctx.slots.register({
2161
+ name: 'shell.overlay',
2162
+ id: 'collab-capability-detail',
2163
+ locale: NS,
2164
+ }, CollabCapabilityDetailOverlay))
2165
+
2166
+ ctx.slots.inject('sidebar.workspaces.session.menu.item', () => ctx.slots.register({
2167
+ name: 'sidebar.workspaces.session.menu.item',
2168
+ id: 'collab-base-prompt',
2169
+ order: 40,
2170
+ locale: NS,
2171
+ }, CollabBasePromptMenuItem))
2172
+
2173
+ },
2174
+ }
2175
+ },
2176
+ })