dsh-collab-pair 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +123 -2
- package/client.js +481 -0
- package/cordis.patch.yml +11 -0
- package/icon.svg +24 -0
- package/index.js +1612 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +46 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-collab-pair contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,124 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-collab-pair
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> DSH 插件:一个项目经理对话管理多个员工对话,任务自动流转,并提供全部任务看板。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
dsh plugin add dsh-collab-pair
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
或在 DSH 的插件管理里用包名 `dsh-collab-pair` 安装。安装后刷新页面,在 **设置 → 双对话协作** 打开。
|
|
12
|
+
|
|
13
|
+
**插件只做一件事:把员工对话关联到项目经理对话。** 目标、任务拆解、验收标准都由项目经理在对话里掌握,插件不重复收集。
|
|
14
|
+
|
|
15
|
+
一个项目经理可以同时管理**多个员工**,每个员工各自跑自己的轮次:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
项目经理(掌握目标、拆解、验收)
|
|
19
|
+
│ collab_dispatch(worker="员工A") 派发第 N 轮
|
|
20
|
+
▼
|
|
21
|
+
员工A / 员工B / …(各自执行、collab_report 汇报)
|
|
22
|
+
│ 该员工本轮 turn 结束 → 插件抓取「汇报 + 最终产出」
|
|
23
|
+
▼
|
|
24
|
+
项目经理收到【协作回报】→ 决定该员工的下一轮,或 collab_done 收尾
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 可视化设置页
|
|
28
|
+
|
|
29
|
+
**设置 → 双对话协作**,从上到下:
|
|
30
|
+
|
|
31
|
+
1. **工作会话**:选择要操作的对话(默认当前打开的对话)。
|
|
32
|
+
2. **当前会话 · <标题>**:先看**这个对话自己的**关联与状态。
|
|
33
|
+
- 是项目经理:列出它管理的员工(状态、轮次、本轮任务、最近回报、解除),并可继续**关联员工**。
|
|
34
|
+
- 是员工:显示项目经理、当前任务、状态与最近回报,可**退出协作**。
|
|
35
|
+
- 无关联:直接显示关联表单。
|
|
36
|
+
3. **全部任务**:所有协作的任务看板,不限当前会话。每行显示员工、所属项目经理、第几轮、**工作状态**(`工作中` / `等待回报` / `空闲` / `已结束`)、等待时长、本轮任务、最近回报。点「刷新」重新读取。
|
|
37
|
+
|
|
38
|
+
页面只做关联/解除和查看,不代填目标、任务、验收——这些交给项目经理对话。
|
|
39
|
+
|
|
40
|
+
## 标题前缀
|
|
41
|
+
|
|
42
|
+
关联时自动给两个对话加前缀,解除(或最后一个员工结束时)自动去掉:
|
|
43
|
+
|
|
44
|
+
- 项目经理:`【项目经理】对话标题`
|
|
45
|
+
- 员工:`【员工】对话标题`
|
|
46
|
+
|
|
47
|
+
可在配置里改文字或关掉(见下)。
|
|
48
|
+
|
|
49
|
+
## 快速开始
|
|
50
|
+
|
|
51
|
+
1. 打开一个对话作为项目经理,对它说:
|
|
52
|
+
> 关联一个员工,目标是把 XXX 做完,先派发第一轮:……
|
|
53
|
+
模型会 `collab_link({ peer: "new" })` + `collab_dispatch({ task: "…" })`。
|
|
54
|
+
2. 再关联第二个员工时,同一句即可;派发时用 `worker` 指定是谁:
|
|
55
|
+
|
|
56
|
+
> 给员工 B 派发:……(worker="session-…")
|
|
57
|
+
3. 员工完成后产出自动回传,项目经理继续或 `collab_done({ worker, summary })` 收尾。
|
|
58
|
+
|
|
59
|
+
已有对话:先 `collab_sessions` 拿到 sessionId,再 `collab_link({ peer: "<sessionId>" })`。
|
|
60
|
+
|
|
61
|
+
## 工具
|
|
62
|
+
|
|
63
|
+
| 工具 | 角色 | 作用 |
|
|
64
|
+
| --- | --- | --- |
|
|
65
|
+
| `collab_sessions` | 任何人 | 列出最近对话(id / 标题 / 活跃 / 是否已关联) |
|
|
66
|
+
| `collab_link` | 任何人 | 关联员工;`role=worker` 表示当前对话成为对方的员工;`peer="new"` 新建员工 |
|
|
67
|
+
| `collab_dispatch` | 项目经理 | 派发一轮;`worker` 指定员工(只有一个时可省略),`acceptance` 可选 |
|
|
68
|
+
| `collab_report` | 员工 | 汇报 `summary` / `status`(done\|partial\|blocked) / `details` / `next` |
|
|
69
|
+
| `collab_status` | 任何人 | 经理看所有员工进度;员工看自己的经理与待办 |
|
|
70
|
+
| `collab_configure` | 项目经理 | 设置某个员工的 agent 预设或模型;不传参数时列出可用预设 |
|
|
71
|
+
| `collab_done` | 项目经理 | 结束某个员工的协作;`all=true` 结束全部 |
|
|
72
|
+
| `collab_unlink` | 双方 | 删除关联;经理用 `worker` 或 `all`,员工解除自己 |
|
|
73
|
+
|
|
74
|
+
## `/collab` 命令
|
|
75
|
+
|
|
76
|
+
设置页通过它操作,也可以手动输入:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
/collab tasks
|
|
80
|
+
/collab status
|
|
81
|
+
/collab link {"peer":"new"}
|
|
82
|
+
/collab link {"peer":"session-…"}
|
|
83
|
+
/collab configure {"worker":"session-…","preset":"ptc"}
|
|
84
|
+
/collab configure {"worker":"session-…","provider":"deepseek-account","model":"deepseek-flash"}
|
|
85
|
+
/collab dispatch {"worker":"session-…","task":"…","acceptance":"…"}
|
|
86
|
+
/collab done {"worker":"session-…","summary":"…"}
|
|
87
|
+
/collab done {"all":true,"summary":"…"}
|
|
88
|
+
/collab unlink {"worker":"session-…"}
|
|
89
|
+
/collab unlink {"all":true}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
也支持 `--key value`:`/collab link --peer new`。`/collab tasks` 返回看板数据(所有关联 + 运行状态)。
|
|
93
|
+
|
|
94
|
+
## 配置
|
|
95
|
+
|
|
96
|
+
`cordis.patch.yml` 的 `collab-pair` 行:
|
|
97
|
+
|
|
98
|
+
```yaml
|
|
99
|
+
- id: collab-pair
|
|
100
|
+
name: 'dsh-collab-pair'
|
|
101
|
+
config:
|
|
102
|
+
maxRounds: 20 # 每个员工最多派发多少轮
|
|
103
|
+
maxRelayChars: 12000 # 回传时最终产出的最大字符数
|
|
104
|
+
maxHistory: 20 # 每个员工保留的最近轮次
|
|
105
|
+
notifyWorkerOnDone: true # done 时通知员工停止
|
|
106
|
+
autoRelay: true # false 时只记录、不自动投递
|
|
107
|
+
addPrefix: true # 是否给关联对话加标题前缀
|
|
108
|
+
prefixManager: '【项目经理】'
|
|
109
|
+
prefixWorker: '【员工】'
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 持久化
|
|
113
|
+
|
|
114
|
+
每个员工一条记录,存在 `$DSH_HOME/storages/collab_pair.json`(storage-domain 的 `collab_pair` 域,表 `links`)。插件重载、DSH 重启后自动恢复;存储不可用时退回内存模式,`collab_status` 的 `storage` 字段会显示 `memory`。
|
|
115
|
+
|
|
116
|
+
## 限制
|
|
117
|
+
|
|
118
|
+
- 员工对话同时只能属于一个协作;项目经理可以关联多个员工。
|
|
119
|
+
- 一个对话不能同时是项目经理和员工。
|
|
120
|
+
- 员工对话需要已配置模型(新建对话继承部署默认模型)。
|
|
121
|
+
- 回传以用户消息形式进入项目经理对话(带【协作回报】标题与轮次标记)。
|
|
122
|
+
- 员工用 PTC 预设时 `collab_report` 会在 `run_code` 里调用,插件仍能读到结构化汇报。
|
|
123
|
+
- 新建员工在产生第一条消息前没有标题,前缀会在它第一轮结束拿到标题后补上。
|
|
124
|
+
- 看板是点「刷新」时的快照(`工作中`/`等待回报` 来自当时的 agent 状态),不做轮询,避免往会话日志里反复写命令记录。
|
package/client.js
ADDED
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-collab-pair',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react')
|
|
5
|
+
const h = React.createElement
|
|
6
|
+
const NS = 'collab-pair'
|
|
7
|
+
|
|
8
|
+
const MESSAGES = {
|
|
9
|
+
zh: {
|
|
10
|
+
nav: '双对话协作',
|
|
11
|
+
title: '双对话协作',
|
|
12
|
+
intro: '一个项目经理可以管理多个员工。插件只负责关联;目标、任务和验收都由项目经理在对话里掌握。',
|
|
13
|
+
workSession: '工作会话',
|
|
14
|
+
workSessionHint: '选择要操作的对话。建立关联时,它就是项目经理对话。',
|
|
15
|
+
noSessions: '还没有可用的对话,请先在左侧新建一个对话。',
|
|
16
|
+
loading: '读取中…',
|
|
17
|
+
refresh: '刷新',
|
|
18
|
+
busy: '处理中…',
|
|
19
|
+
boardTitle: '全部任务',
|
|
20
|
+
boardSummary: '{active} 进行中 / 共 {total}',
|
|
21
|
+
noTasks: '还没有任何协作任务。',
|
|
22
|
+
currentTitle: '当前会话',
|
|
23
|
+
linkTitle: '关联员工',
|
|
24
|
+
peer: '员工对话',
|
|
25
|
+
peerNew: '新建一个员工对话',
|
|
26
|
+
link: '关联',
|
|
27
|
+
linkDone: '已关联员工。接下来在项目经理对话里派发任务。',
|
|
28
|
+
workerPrefixHint: '关联后两个对话的标题会自动加上【项目经理】/【员工】前缀,解除时自动去掉。',
|
|
29
|
+
managerTitle: '项目经理',
|
|
30
|
+
managing: '正在管理',
|
|
31
|
+
workerCount: '个员工',
|
|
32
|
+
workerTitle: '员工',
|
|
33
|
+
workerHint: '这个对话是员工角色;项目目标与验收由项目经理掌握。',
|
|
34
|
+
leave: '退出协作',
|
|
35
|
+
confirmLeave: '退出这个协作?',
|
|
36
|
+
round: '第',
|
|
37
|
+
roundUnit: '轮',
|
|
38
|
+
waited: '已等待 {time}',
|
|
39
|
+
runningNow: '工作中',
|
|
40
|
+
waiting: '等待回报',
|
|
41
|
+
idle: '空闲',
|
|
42
|
+
finished: '已结束',
|
|
43
|
+
noWorkers: '还没有关联员工。',
|
|
44
|
+
lastReport: '最近回报',
|
|
45
|
+
unlink: '解除',
|
|
46
|
+
confirmUnlink: '解除与该员工的协作关联?',
|
|
47
|
+
removeDone: '已解除关联。',
|
|
48
|
+
statusDone: '完成',
|
|
49
|
+
statusPartial: '部分完成',
|
|
50
|
+
statusBlocked: '受阻',
|
|
51
|
+
statusUnreported: '未显式汇报',
|
|
52
|
+
seconds: '{count} 秒',
|
|
53
|
+
minutes: '{count} 分钟',
|
|
54
|
+
hours: '{count} 小时',
|
|
55
|
+
unknownError: '操作失败',
|
|
56
|
+
},
|
|
57
|
+
en: {
|
|
58
|
+
nav: 'Collaboration pair',
|
|
59
|
+
title: 'Collaboration pair',
|
|
60
|
+
intro: 'One project manager can run several workers. The plugin only manages links; goals, tasks, and acceptance stay with the manager in the conversation.',
|
|
61
|
+
workSession: 'Working conversation',
|
|
62
|
+
workSessionHint: 'The conversation to act on. When you create a link, it becomes the project manager.',
|
|
63
|
+
noSessions: 'No conversation is available yet. Create one in the sidebar first.',
|
|
64
|
+
loading: 'Loading…',
|
|
65
|
+
refresh: 'Refresh',
|
|
66
|
+
busy: 'Working…',
|
|
67
|
+
boardTitle: 'All tasks',
|
|
68
|
+
boardSummary: '{active} active / {total} total',
|
|
69
|
+
noTasks: 'No collaboration task yet.',
|
|
70
|
+
currentTitle: 'Current conversation',
|
|
71
|
+
linkTitle: 'Link a worker',
|
|
72
|
+
peer: 'Worker conversation',
|
|
73
|
+
peerNew: 'Create a new worker conversation',
|
|
74
|
+
link: 'Link',
|
|
75
|
+
linkDone: 'Worker linked. Dispatch tasks from the manager conversation.',
|
|
76
|
+
workerPrefixHint: 'Linking adds a 【项目经理】/【员工】 prefix to both titles; unlinking removes it.',
|
|
77
|
+
managerTitle: 'Project manager',
|
|
78
|
+
managing: 'Managing',
|
|
79
|
+
workerCount: 'workers',
|
|
80
|
+
workerTitle: 'Worker',
|
|
81
|
+
workerHint: 'This conversation is a worker; the project goal and acceptance stay with the project manager.',
|
|
82
|
+
leave: 'Leave',
|
|
83
|
+
confirmLeave: 'Leave this collaboration?',
|
|
84
|
+
round: 'Round',
|
|
85
|
+
roundUnit: '',
|
|
86
|
+
waited: 'waiting {time}',
|
|
87
|
+
runningNow: 'Working',
|
|
88
|
+
waiting: 'Waiting for report',
|
|
89
|
+
idle: 'Idle',
|
|
90
|
+
finished: 'Finished',
|
|
91
|
+
noWorkers: 'No worker linked yet.',
|
|
92
|
+
lastReport: 'Latest report',
|
|
93
|
+
unlink: 'Unlink',
|
|
94
|
+
confirmUnlink: 'Remove the link to this worker?',
|
|
95
|
+
removeDone: 'Link removed.',
|
|
96
|
+
statusDone: 'Done',
|
|
97
|
+
statusPartial: 'Partially done',
|
|
98
|
+
statusBlocked: 'Blocked',
|
|
99
|
+
statusUnreported: 'No explicit report',
|
|
100
|
+
seconds: '{count}s',
|
|
101
|
+
minutes: '{count}m',
|
|
102
|
+
hours: '{count}h',
|
|
103
|
+
unknownError: 'The operation failed',
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const S = {
|
|
108
|
+
page: { maxWidth: 820, display: 'flex', flexDirection: 'column', gap: 18, color: 'var(--dsw-alias-label-primary)', fontSize: 13, lineHeight: 1.55 },
|
|
109
|
+
title: { margin: 0, fontSize: 18, fontWeight: 600 },
|
|
110
|
+
intro: { margin: 0, color: 'var(--dsw-alias-label-secondary)' },
|
|
111
|
+
hint: { color: 'var(--dsw-alias-label-secondary)', fontSize: 12, margin: 0 },
|
|
112
|
+
card: { display: 'flex', flexDirection: 'column', gap: 12, padding: 16, border: '1px solid var(--dsw-alias-border-l1)', borderRadius: 12, background: 'var(--dsw-alias-bg-layer-1)' },
|
|
113
|
+
cardHead: { display: 'flex', gap: 8, alignItems: 'baseline', justifyContent: 'space-between', flexWrap: 'wrap' },
|
|
114
|
+
cardTitle: { margin: 0, fontSize: 14, fontWeight: 600 },
|
|
115
|
+
row: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' },
|
|
116
|
+
label: { display: 'flex', flexDirection: 'column', gap: 6, fontSize: 12, color: 'var(--dsw-alias-label-secondary)' },
|
|
117
|
+
input: { width: '100%', boxSizing: 'border-box', padding: '8px 10px', borderRadius: 8, border: '1px solid var(--dsw-alias-border-l1)', background: 'var(--dsw-alias-bg-base)', color: 'var(--dsw-alias-label-primary)', fontSize: 13, fontFamily: 'inherit' },
|
|
118
|
+
primary: { padding: '8px 14px', borderRadius: 8, border: '1px solid transparent', background: 'var(--dsw-alias-brand-primary)', color: '#fff', fontSize: 13, cursor: 'pointer' },
|
|
119
|
+
secondary: { padding: '6px 12px', borderRadius: 8, border: '1px solid var(--dsw-alias-border-l2)', background: 'transparent', color: 'var(--dsw-alias-label-primary)', fontSize: 12, cursor: 'pointer' },
|
|
120
|
+
danger: { padding: '6px 12px', borderRadius: 8, border: '1px solid var(--dsw-alias-state-error-primary)', background: 'transparent', color: 'var(--dsw-alias-state-error-primary)', fontSize: 12, cursor: 'pointer' },
|
|
121
|
+
badge: { display: 'inline-flex', alignItems: 'center', padding: '2px 8px', borderRadius: 999, fontSize: 11, fontWeight: 600, background: 'var(--dsw-alias-bg-layer-2)', whiteSpace: 'nowrap' },
|
|
122
|
+
mono: { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: 11, color: 'var(--dsw-alias-label-secondary)', wordBreak: 'break-all' },
|
|
123
|
+
muted: { color: 'var(--dsw-alias-label-secondary)', fontSize: 12 },
|
|
124
|
+
notice: { fontSize: 12, whiteSpace: 'pre-wrap', margin: 0 },
|
|
125
|
+
worker: { display: 'flex', gap: 12, alignItems: 'center', justifyContent: 'space-between', padding: '10px 12px', border: '1px solid var(--dsw-alias-border-l1)', borderRadius: 10, background: 'var(--dsw-alias-bg-base)' },
|
|
126
|
+
workerMain: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 },
|
|
127
|
+
workerName: { fontSize: 13, fontWeight: 600, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
128
|
+
taskRow: { display: 'flex', gap: 12, alignItems: 'flex-start', justifyContent: 'space-between', padding: '10px 12px', border: '1px solid var(--dsw-alias-border-l1)', borderRadius: 10, background: 'var(--dsw-alias-bg-base)' },
|
|
129
|
+
taskMain: { display: 'flex', flexDirection: 'column', gap: 3, minWidth: 0, flex: 1 },
|
|
130
|
+
taskTitle: { fontSize: 13, fontWeight: 600, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
131
|
+
taskText: { margin: 0, color: 'var(--dsw-alias-label-secondary)', fontSize: 12, maxHeight: 34, overflow: 'hidden', wordBreak: 'break-word' },
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Read every renderable conversation from the client session store. */
|
|
135
|
+
function sessionRows(snapshot) {
|
|
136
|
+
const byId = snapshot && typeof snapshot === 'object' && snapshot.byId !== null && typeof snapshot.byId === 'object' ? snapshot.byId : {}
|
|
137
|
+
const rows = []
|
|
138
|
+
for (const key of Object.keys(byId)) {
|
|
139
|
+
const item = byId[key]
|
|
140
|
+
if (item === null || typeof item !== 'object') continue
|
|
141
|
+
const id = typeof item.id === 'string' ? item.id : key
|
|
142
|
+
if (typeof id !== 'string' || id === '') continue
|
|
143
|
+
if (item.origin === 'subagent') continue
|
|
144
|
+
const retained = item.retainedBy !== undefined && (item.retainedBy.mainView ?? 0) > 0
|
|
145
|
+
rows.push({
|
|
146
|
+
id,
|
|
147
|
+
title: typeof item.title === 'string' && item.title !== '' ? item.title : id,
|
|
148
|
+
updatedAt: typeof item.updatedAt === 'number' ? item.updatedAt : (typeof item.createdAt === 'number' ? item.createdAt : 0),
|
|
149
|
+
retained,
|
|
150
|
+
running: item.running === true,
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
rows.sort((left, right) => (Number(right.retained) - Number(left.retained)) || (right.updatedAt - left.updatedAt))
|
|
154
|
+
return rows
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Run one `/collab` line on a session and return its JSON payload. */
|
|
158
|
+
async function runCommand(commands, sessionId, line) {
|
|
159
|
+
if (commands === undefined || commands === null || typeof commands.execute !== 'function') throw new Error('command channel unavailable')
|
|
160
|
+
const response = await commands.execute(sessionId, line, [])
|
|
161
|
+
if (response === undefined || response === null || response.ok !== true) {
|
|
162
|
+
const failure = response && response.error
|
|
163
|
+
throw new Error(failure === undefined ? 'command failed' : `${failure.code}: ${failure.message}`)
|
|
164
|
+
}
|
|
165
|
+
const execution = response.value
|
|
166
|
+
if (execution === undefined) throw new Error(`unknown command: ${line}`)
|
|
167
|
+
const result = execution.result
|
|
168
|
+
if (result === undefined || result === null) throw new Error('command returned no result')
|
|
169
|
+
if (result.kind === 'error') throw new Error(result.text)
|
|
170
|
+
const text = result.text ?? ''
|
|
171
|
+
if (text === '') return null
|
|
172
|
+
try {
|
|
173
|
+
return JSON.parse(text)
|
|
174
|
+
} catch {
|
|
175
|
+
return { message: text }
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function CollabSettings(props) {
|
|
180
|
+
const t = typeof props.t === 'function' ? props.t : (key) => key
|
|
181
|
+
const commands = props.commands
|
|
182
|
+
const useSessions = typeof props.useSessions === 'function' ? props.useSessions : (selector) => selector(undefined)
|
|
183
|
+
const snapshot = useSessions((state) => state)
|
|
184
|
+
const sessions = React.useMemo(() => sessionRows(snapshot), [snapshot])
|
|
185
|
+
const [workId, setWorkId] = React.useState(props.initialWorkId)
|
|
186
|
+
const [board, setBoard] = React.useState(props.initialBoard === undefined ? null : props.initialBoard)
|
|
187
|
+
const [error, setError] = React.useState(null)
|
|
188
|
+
const [notice, setNotice] = React.useState(null)
|
|
189
|
+
const [busy, setBusy] = React.useState(false)
|
|
190
|
+
const [peer, setPeer] = React.useState('new')
|
|
191
|
+
const commandsRef = React.useRef(commands)
|
|
192
|
+
commandsRef.current = commands
|
|
193
|
+
|
|
194
|
+
React.useEffect(() => {
|
|
195
|
+
if (workId !== undefined) return
|
|
196
|
+
if (sessions.length === 0) return
|
|
197
|
+
const preferred = sessions.find((row) => row.retained) ?? sessions[0]
|
|
198
|
+
setWorkId(preferred.id)
|
|
199
|
+
}, [sessions, workId])
|
|
200
|
+
|
|
201
|
+
const loadBoard = React.useCallback(async (sessionId) => {
|
|
202
|
+
const value = await runCommand(commandsRef.current, sessionId, '/collab tasks')
|
|
203
|
+
setBoard(value)
|
|
204
|
+
return value
|
|
205
|
+
}, [])
|
|
206
|
+
|
|
207
|
+
React.useEffect(() => {
|
|
208
|
+
if (workId === undefined) return undefined
|
|
209
|
+
let cancelled = false
|
|
210
|
+
setBusy(true)
|
|
211
|
+
setError(null)
|
|
212
|
+
setNotice(null)
|
|
213
|
+
setBoard(null)
|
|
214
|
+
loadBoard(workId)
|
|
215
|
+
.then((value) => {
|
|
216
|
+
if (!cancelled) setBoard(value)
|
|
217
|
+
})
|
|
218
|
+
.catch((cause) => {
|
|
219
|
+
if (cancelled) return
|
|
220
|
+
setBoard(null)
|
|
221
|
+
setError(cause instanceof Error ? cause.message : String(cause))
|
|
222
|
+
})
|
|
223
|
+
.finally(() => {
|
|
224
|
+
if (!cancelled) setBusy(false)
|
|
225
|
+
})
|
|
226
|
+
return () => {
|
|
227
|
+
cancelled = true
|
|
228
|
+
}
|
|
229
|
+
}, [workId, loadBoard])
|
|
230
|
+
|
|
231
|
+
const act = async (line, successText) => {
|
|
232
|
+
if (workId === undefined) return
|
|
233
|
+
setBusy(true)
|
|
234
|
+
setError(null)
|
|
235
|
+
setNotice(null)
|
|
236
|
+
try {
|
|
237
|
+
const value = await runCommand(commandsRef.current, workId, line)
|
|
238
|
+
setNotice(value !== null && typeof value === 'object' && typeof value.message === 'string' ? value.message : successText)
|
|
239
|
+
await loadBoard(workId)
|
|
240
|
+
} catch (cause) {
|
|
241
|
+
setError(cause instanceof Error ? cause.message : String(cause))
|
|
242
|
+
} finally {
|
|
243
|
+
setBusy(false)
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const refresh = async () => {
|
|
248
|
+
if (workId === undefined) return
|
|
249
|
+
setBusy(true)
|
|
250
|
+
setError(null)
|
|
251
|
+
try {
|
|
252
|
+
await loadBoard(workId)
|
|
253
|
+
} catch (cause) {
|
|
254
|
+
setError(cause instanceof Error ? cause.message : String(cause))
|
|
255
|
+
} finally {
|
|
256
|
+
setBusy(false)
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const linkWorker = () => {
|
|
261
|
+
void act(`/collab link ${JSON.stringify({ peer })}`, t('linkDone'))
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const removeWorker = (worker) => {
|
|
265
|
+
if (typeof window.confirm === 'function' && !window.confirm(t('confirmUnlink'))) return
|
|
266
|
+
void act(`/collab unlink ${JSON.stringify({ worker })}`, t('removeDone'))
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const leaveCollaboration = () => {
|
|
270
|
+
if (typeof window.confirm === 'function' && !window.confirm(t('confirmLeave'))) return
|
|
271
|
+
void act(`/collab unlink ${JSON.stringify({})}`, t('removeDone'))
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const links = board !== null && Array.isArray(board.links) ? board.links : []
|
|
275
|
+
const activeLinks = links.filter((link) => link.status === 'active')
|
|
276
|
+
const managed = workId === undefined ? [] : activeLinks.filter((link) => link.manager === workId)
|
|
277
|
+
const mine = workId === undefined ? undefined : activeLinks.find((link) => link.worker === workId)
|
|
278
|
+
const role = managed.length > 0 ? 'manager' : mine === undefined ? null : 'worker'
|
|
279
|
+
const peerChoices = sessions.filter((row) => row.id !== workId)
|
|
280
|
+
|
|
281
|
+
const statusText = (value) => {
|
|
282
|
+
if (value === 'done') return t('statusDone')
|
|
283
|
+
if (value === 'partial') return t('statusPartial')
|
|
284
|
+
if (value === 'blocked') return t('statusBlocked')
|
|
285
|
+
return t('statusUnreported')
|
|
286
|
+
}
|
|
287
|
+
const formatWait = (seconds) => {
|
|
288
|
+
if (typeof seconds !== 'number' || seconds < 0) return ''
|
|
289
|
+
if (seconds < 60) return t('seconds', { count: seconds })
|
|
290
|
+
if (seconds < 3600) return t('minutes', { count: Math.round(seconds / 60) })
|
|
291
|
+
return t('hours', { count: Math.round(seconds / 360) / 10 })
|
|
292
|
+
}
|
|
293
|
+
const stateOf = (link) => {
|
|
294
|
+
if (link.status !== 'active') return { label: t('finished'), color: 'var(--dsw-alias-label-secondary)' }
|
|
295
|
+
if (link.workerRunning === true) return { label: t('runningNow'), color: 'var(--dsw-alias-state-success-primary)' }
|
|
296
|
+
if (link.pending !== null && link.pending !== undefined) return { label: t('waiting'), color: 'var(--dsw-alias-state-warn-primary)' }
|
|
297
|
+
return { label: t('idle'), color: 'var(--dsw-alias-state-idle-primary)' }
|
|
298
|
+
}
|
|
299
|
+
const roundText = (link) => {
|
|
300
|
+
const base = `${t('round')} ${link.round} ${t('roundUnit')}`.trim()
|
|
301
|
+
if (link.pending === null || link.pending === undefined) return base
|
|
302
|
+
const wait = formatWait(link.waitedSeconds)
|
|
303
|
+
return wait === '' ? base : `${base} · ${t('waited', { time: wait })}`
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const header = h('div', { style: S.page },
|
|
307
|
+
h('h2', { style: S.title }, t('title')),
|
|
308
|
+
h('p', { style: S.intro }, t('intro')),
|
|
309
|
+
h('div', { style: S.card },
|
|
310
|
+
h('label', { style: S.label }, t('workSession'),
|
|
311
|
+
h('select', {
|
|
312
|
+
style: S.input,
|
|
313
|
+
value: workId ?? '',
|
|
314
|
+
disabled: busy || sessions.length === 0,
|
|
315
|
+
onChange: (event) => setWorkId(event.target.value),
|
|
316
|
+
},
|
|
317
|
+
sessions.length === 0
|
|
318
|
+
? h('option', { value: '' }, t('noSessions'))
|
|
319
|
+
: sessions.map((row) => h('option', { key: row.id, value: row.id }, `${row.title}${row.running ? ' · ●' : ''}`))),
|
|
320
|
+
),
|
|
321
|
+
h('div', { style: S.hint }, t('workSessionHint')),
|
|
322
|
+
h('div', { style: S.mono }, workId ?? ''),
|
|
323
|
+
h('div', { style: S.row },
|
|
324
|
+
h('button', { type: 'button', style: S.secondary, disabled: busy || workId === undefined, onClick: () => void refresh() }, t('refresh')),
|
|
325
|
+
busy ? h('span', { style: S.muted }, t('busy')) : null,
|
|
326
|
+
),
|
|
327
|
+
),
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
const feedback = (error !== null || notice !== null)
|
|
331
|
+
? h('div', { style: S.card },
|
|
332
|
+
error !== null ? h('p', { style: { ...S.notice, color: 'var(--dsw-alias-state-error-primary)' } }, error) : null,
|
|
333
|
+
notice !== null ? h('p', { style: { ...S.notice, color: 'var(--dsw-alias-state-success-primary)' } }, notice) : null,
|
|
334
|
+
)
|
|
335
|
+
: null
|
|
336
|
+
|
|
337
|
+
const stateBadge = (state) => h('span', { style: { ...S.badge, color: state.color } }, state.label)
|
|
338
|
+
|
|
339
|
+
const taskRow = (link) => {
|
|
340
|
+
const state = stateOf(link)
|
|
341
|
+
return h('div', { key: link.linkId, style: S.taskRow },
|
|
342
|
+
h('div', { style: S.taskMain },
|
|
343
|
+
h('div', { style: S.taskTitle }, link.workerTitle || link.worker),
|
|
344
|
+
h('div', { style: S.mono }, link.worker),
|
|
345
|
+
h('div', { style: S.muted },
|
|
346
|
+
`${link.managerTitle || link.manager} · ${roundText(link)}`,
|
|
347
|
+
),
|
|
348
|
+
link.pending === null || link.pending === undefined
|
|
349
|
+
? null
|
|
350
|
+
: h('p', { style: S.taskText }, link.pending.task),
|
|
351
|
+
link.lastReport === null || link.lastReport === undefined
|
|
352
|
+
? null
|
|
353
|
+
: h('div', { style: S.muted }, `${t('lastReport')}:${statusText(link.lastReport.status)}${link.lastReport.summary ? ` · ${link.lastReport.summary}` : ''}`),
|
|
354
|
+
),
|
|
355
|
+
stateBadge(state),
|
|
356
|
+
)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const boardCard = h('div', { style: S.card },
|
|
360
|
+
h('div', { style: S.cardHead },
|
|
361
|
+
h('h3', { style: S.cardTitle }, t('boardTitle')),
|
|
362
|
+
h('span', { style: S.muted }, t('boardSummary', {
|
|
363
|
+
active: board === null ? 0 : board.activeCount ?? activeLinks.length,
|
|
364
|
+
total: board === null ? 0 : board.totalCount ?? links.length,
|
|
365
|
+
})),
|
|
366
|
+
),
|
|
367
|
+
board === null
|
|
368
|
+
? h('p', { style: S.intro }, busy ? t('loading') : t('noTasks'))
|
|
369
|
+
: links.length === 0
|
|
370
|
+
? h('p', { style: S.intro }, t('noTasks'))
|
|
371
|
+
: links.map(taskRow),
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
const workerRow = (link) => {
|
|
375
|
+
const state = stateOf(link)
|
|
376
|
+
return h('div', { key: link.linkId, style: S.worker },
|
|
377
|
+
h('div', { style: S.workerMain },
|
|
378
|
+
h('div', { style: S.workerName }, link.workerTitle || link.worker),
|
|
379
|
+
h('div', { style: S.mono }, link.worker),
|
|
380
|
+
h('div', { style: S.muted }, roundText(link)),
|
|
381
|
+
link.pending === null || link.pending === undefined
|
|
382
|
+
? null
|
|
383
|
+
: h('p', { style: S.taskText }, link.pending.task),
|
|
384
|
+
link.lastReport === null || link.lastReport === undefined
|
|
385
|
+
? null
|
|
386
|
+
: h('div', { style: S.muted }, `${t('lastReport')}:${statusText(link.lastReport.status)}${link.lastReport.summary ? ` · ${link.lastReport.summary}` : ''}`),
|
|
387
|
+
),
|
|
388
|
+
h('div', { style: S.row },
|
|
389
|
+
stateBadge(state),
|
|
390
|
+
h('button', { type: 'button', style: S.danger, disabled: busy, onClick: () => removeWorker(link.worker) }, t('unlink')),
|
|
391
|
+
),
|
|
392
|
+
)
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const linkForm = h('div', { style: S.card },
|
|
396
|
+
h('h3', { style: S.cardTitle }, t('linkTitle')),
|
|
397
|
+
h('label', { style: S.label }, t('peer'),
|
|
398
|
+
h('select', {
|
|
399
|
+
style: S.input,
|
|
400
|
+
value: peer,
|
|
401
|
+
disabled: busy,
|
|
402
|
+
onChange: (event) => setPeer(event.target.value),
|
|
403
|
+
},
|
|
404
|
+
h('option', { value: 'new' }, t('peerNew')),
|
|
405
|
+
peerChoices.map((row) => h('option', { key: row.id, value: row.id }, row.title))),
|
|
406
|
+
),
|
|
407
|
+
h('div', { style: S.row },
|
|
408
|
+
h('button', { type: 'button', style: S.primary, disabled: busy, onClick: linkWorker }, t('link')),
|
|
409
|
+
),
|
|
410
|
+
h('p', { style: S.hint }, t('workerPrefixHint')),
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
let currentCard
|
|
414
|
+
if (sessions.length === 0) {
|
|
415
|
+
currentCard = h('div', { style: S.card }, h('p', { style: S.intro }, t('noSessions')))
|
|
416
|
+
} else if (role === 'manager') {
|
|
417
|
+
currentCard = h('div', { style: { display: 'flex', flexDirection: 'column', gap: 18 } },
|
|
418
|
+
h('div', { style: S.card },
|
|
419
|
+
h('div', { style: S.row },
|
|
420
|
+
h('span', { style: S.badge }, t('managerTitle')),
|
|
421
|
+
h('span', { style: S.muted }, `${t('managing')} ${managed.length} ${t('workerCount')}`),
|
|
422
|
+
),
|
|
423
|
+
managed.length === 0 ? h('p', { style: S.intro }, t('noWorkers')) : managed.map(workerRow),
|
|
424
|
+
),
|
|
425
|
+
linkForm,
|
|
426
|
+
)
|
|
427
|
+
} else if (role === 'worker' && mine !== undefined) {
|
|
428
|
+
const pending = mine.pending
|
|
429
|
+
currentCard = h('div', { style: S.card },
|
|
430
|
+
h('div', { style: S.row },
|
|
431
|
+
h('span', { style: S.badge }, t('workerTitle')),
|
|
432
|
+
stateBadge(stateOf(mine)),
|
|
433
|
+
),
|
|
434
|
+
h('div', { style: S.label }, t('managerTitle'),
|
|
435
|
+
h('div', null, mine.managerTitle || mine.manager),
|
|
436
|
+
h('div', { style: S.mono }, mine.manager),
|
|
437
|
+
),
|
|
438
|
+
h('div', { style: S.muted }, roundText(mine)),
|
|
439
|
+
pending === null || pending === undefined ? null : h('p', { style: S.taskText }, pending.task),
|
|
440
|
+
mine.lastReport === null || mine.lastReport === undefined
|
|
441
|
+
? null
|
|
442
|
+
: h('div', { style: S.muted }, `${t('lastReport')}:${statusText(mine.lastReport.status)}${mine.lastReport.summary ? ` · ${mine.lastReport.summary}` : ''}`),
|
|
443
|
+
h('p', { style: S.hint }, t('workerHint')),
|
|
444
|
+
h('div', { style: S.row },
|
|
445
|
+
h('button', { type: 'button', style: S.danger, disabled: busy, onClick: leaveCollaboration }, t('leave')),
|
|
446
|
+
),
|
|
447
|
+
)
|
|
448
|
+
} else {
|
|
449
|
+
currentCard = linkForm
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const workTitle = sessions.find((row) => row.id === workId)?.title
|
|
453
|
+
return h('div', { style: S.page },
|
|
454
|
+
header,
|
|
455
|
+
feedback,
|
|
456
|
+
h('h3', { style: S.cardTitle }, workTitle === undefined ? t('currentTitle') : `${t('currentTitle')} · ${workTitle}`),
|
|
457
|
+
currentCard,
|
|
458
|
+
boardCard,
|
|
459
|
+
)
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const inject = ['slots', 'locale', 'remote', 'remote.commands']
|
|
463
|
+
|
|
464
|
+
function apply(ctx) {
|
|
465
|
+
const locale = ctx.locale
|
|
466
|
+
if (locale !== undefined && typeof locale.register === 'function') {
|
|
467
|
+
ctx.effect(() => locale.register(NS, MESSAGES), 'collab-pair: locale dictionaries')
|
|
468
|
+
}
|
|
469
|
+
const t = locale !== undefined && typeof locale.bind === 'function' ? locale.bind(NS) : (key) => key
|
|
470
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
471
|
+
name: 'settings.section',
|
|
472
|
+
id: 'collab-pair',
|
|
473
|
+
order: 16,
|
|
474
|
+
label: () => t('nav'),
|
|
475
|
+
inject: () => ({ t, commands: ctx.remote.commands }),
|
|
476
|
+
}, CollabSettings))
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
return { inject, apply }
|
|
480
|
+
},
|
|
481
|
+
})
|
package/cordis.patch.yml
ADDED
package/icon.svg
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Two linked conversations">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="cpA" x1="0" y1="0" x2="1" y2="1">
|
|
4
|
+
<stop offset="0" stop-color="#3b82f6"/>
|
|
5
|
+
<stop offset="1" stop-color="#2563eb"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<linearGradient id="cpB" x1="0" y1="0" x2="1" y2="1">
|
|
8
|
+
<stop offset="0" stop-color="#2dd4bf"/>
|
|
9
|
+
<stop offset="1" stop-color="#0d9488"/>
|
|
10
|
+
</linearGradient>
|
|
11
|
+
</defs>
|
|
12
|
+
<path d="M11 9h24a7 7 0 0 1 7 7v9a7 7 0 0 1-7 7H22l-8 6v-6h-3a7 7 0 0 1-7-7v-9a7 7 0 0 1 7-7z" fill="url(#cpA)"/>
|
|
13
|
+
<circle cx="15" cy="20.5" r="2.1" fill="#eaf1ff"/>
|
|
14
|
+
<circle cx="23" cy="20.5" r="2.1" fill="#eaf1ff"/>
|
|
15
|
+
<circle cx="31" cy="20.5" r="2.1" fill="#eaf1ff"/>
|
|
16
|
+
<path d="M29 33h24a7 7 0 0 1 7 7v9a7 7 0 0 1-7 7H46v6l-8-6H29a7 7 0 0 1-7-7v-9a7 7 0 0 1 7-7z" fill="url(#cpB)"/>
|
|
17
|
+
<circle cx="33" cy="44.5" r="2.1" fill="#e7fffb"/>
|
|
18
|
+
<circle cx="41" cy="44.5" r="2.1" fill="#e7fffb"/>
|
|
19
|
+
<circle cx="49" cy="44.5" r="2.1" fill="#e7fffb"/>
|
|
20
|
+
<path d="M40 28.5c5.4 0 8.5 2.6 8.5 6.6" fill="none" stroke="#94a3b8" stroke-width="2.6" stroke-linecap="round"/>
|
|
21
|
+
<path d="M48.5 35.1l-2.6-1.9 4.9-1.4" fill="none" stroke="#94a3b8" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"/>
|
|
22
|
+
<path d="M24 34.5c-5.4 0-8.5-2.6-8.5-6.6" fill="none" stroke="#94a3b8" stroke-width="2.6" stroke-linecap="round"/>
|
|
23
|
+
<path d="M15.5 27.9l2.6 1.9-4.9 1.4" fill="none" stroke="#94a3b8" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"/>
|
|
24
|
+
</svg>
|