dsh-collab-pair 1.4.3 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -4
- package/client.js +159 -9
- package/index.js +212 -2
- package/locale/en.json +2 -2
- package/locale/zh.json +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dsh-collab-pair
|
|
2
2
|
|
|
3
|
-
> A DSH plugin for large projects: link
|
|
3
|
+
> A DSH collaboration plugin for large projects: link a project-manager conversation to local or remote workers, dispatch rounds, relay results and manage stages. It also provides a prompt to-do queue for any conversation: pre-write several prompts and the next one is sent when a turn ends.
|
|
4
4
|
|
|
5
5
|
[**GitHub**](https://github.com/awa1231/dsh-collab-pair) · [Give it a star ★](https://github.com/awa1231/dsh-collab-pair)
|
|
6
6
|
|
|
@@ -38,6 +38,7 @@ Manager receives a collaboration report → next round for that worker, or colla
|
|
|
38
38
|
3. **All tasks** — a board across every collaboration, grouped by **project**. Each row shows the worker, round, **working state** (`Working` / `Waiting for report` / `Idle` / `Finished`), waiting time, current task, and latest report. Refresh re-reads it.
|
|
39
39
|
4. **Cross-device** — relay mode (off / self-hosted hub / free ntfy.sh), URL, room, token and device name; save/test, connection status, worker alias registration, and remote-worker linking.
|
|
40
40
|
5. **Stage queue** (manager only) — pick a worker, add a stage title/prompt/acceptance, then start it, complete it (auto-dispatches the next), or remove a pending one.
|
|
41
|
+
6. **Conversation to-do** (any other conversation) — pre-write a series of prompts; the first is sent when you press start, and the next is sent when the current turn ends. Pause, resume, or clear pending items.
|
|
41
42
|
|
|
42
43
|
Right-click a conversation in the sidebar and choose **Set as project manager (start)**: the plugin creates and links a starter worker, then sends that conversation a manager-mode instruction to create more workers itself and delegate the execution.
|
|
43
44
|
|
|
@@ -119,6 +120,15 @@ A human can pre-write several large stages for one worker; finishing one dispatc
|
|
|
119
120
|
- A stage is a normal round: the worker reports as usual, and `complete` waits until no round is pending.
|
|
120
121
|
- The queue is stored on the worker link; `remove` deletes a pending stage, `clear` removes all pending stages.
|
|
121
122
|
|
|
123
|
+
## Conversation to-do queue
|
|
124
|
+
|
|
125
|
+
Any conversation, not only a manager, can have its own prompt queue:
|
|
126
|
+
|
|
127
|
+
- Add items in the **Conversation to-do** card, or `/collab queue {"action":"add","title":"…","prompt":"…"}`.
|
|
128
|
+
- `start` sends the first pending prompt as a normal user message; when that turn ends, the next pending prompt is sent automatically.
|
|
129
|
+
- `pause` stops auto-advance after the current turn, `resume` re-enables it, and `clear` removes pending items.
|
|
130
|
+
- The queue is stored per conversation and survives plugin reloads.
|
|
131
|
+
|
|
122
132
|
## Projects
|
|
123
133
|
|
|
124
134
|
A project is the set of workers managed by one project-manager conversation. Different managers are different projects, so nothing mixes:
|
|
@@ -193,6 +203,7 @@ The settings page uses it; it can also be typed manually:
|
|
|
193
203
|
/collab create {"name":"前端","preset":"standard"}
|
|
194
204
|
/collab remote {"action":"link","device":"laptop","worker":"frontend"}
|
|
195
205
|
/collab stage {"action":"add","title":"阶段一","prompt":"…"}
|
|
206
|
+
/collab queue {"action":"add","title":"第一步","prompt":"…"}
|
|
196
207
|
/collab relay {"action":"set","mode":"ntfy","hubRoom":"my-project","hubToken":"…"}
|
|
197
208
|
/collab configure {"worker":"session-…","preset":"ptc"}
|
|
198
209
|
/collab configure {"worker":"session-…","provider":"deepseek-account","model":"deepseek-flash"}
|
|
@@ -252,7 +263,7 @@ One record per worker lives in `$DSH_HOME/storages/collab_pair.json` (storage-do
|
|
|
252
263
|
|
|
253
264
|
# 中文说明
|
|
254
265
|
|
|
255
|
-
> DSH
|
|
266
|
+
> 用于大项目的 DSH 协作插件:把项目经理对话与本机/远端员工关联,自动派发、回传并推进阶段;也可以给任意对话预设一串提示词待办,完成一轮自动发下一条。
|
|
256
267
|
|
|
257
268
|
[**GitHub**](https://github.com/awa1231/dsh-collab-pair) · [给个 Star ★](https://github.com/awa1231/dsh-collab-pair)
|
|
258
269
|
|
|
@@ -280,7 +291,7 @@ dsh plugin add dsh-collab-pair
|
|
|
280
291
|
|
|
281
292
|
## 可视化设置页
|
|
282
293
|
|
|
283
|
-
**设置 →
|
|
294
|
+
**设置 → 协作待办**,从上到下:
|
|
284
295
|
|
|
285
296
|
1. **工作会话**:选择要操作的对话(默认当前打开的对话)。
|
|
286
297
|
2. **当前会话 · <标题>**:先看**这个对话自己的**关联与状态。
|
|
@@ -289,7 +300,8 @@ dsh plugin add dsh-collab-pair
|
|
|
289
300
|
- 无关联:直接显示关联表单。
|
|
290
301
|
3. **全部任务**:所有协作的任务看板,不限当前会话。每行显示员工、所属项目经理、第几轮、**工作状态**(`工作中` / `等待回报` / `空闲` / `已结束`)、等待时长、本轮任务、最近回报。点「刷新」重新读取。
|
|
291
302
|
4. **跨设备协作**:中继模式(关闭 / 自建 hub / 免费 ntfy.sh)、URL、房间、令牌、设备名;保存/测试、连接状态、员工别名注册、远端员工关联。
|
|
292
|
-
5.
|
|
303
|
+
5. **阶段待办**(仅项目经理):选员工,填标题/提示词/验收标准;可开始、完成并自动派发下一阶段、删除待开始阶段。
|
|
304
|
+
6. **对话待办**(其他任意对话):预先写一串提示词;点开始发第一条,当前回合结束后自动发下一条。可暂停、恢复、清空待发。
|
|
293
305
|
|
|
294
306
|
在侧栏右键一个对话,选「设为项目经理并启动」:插件会新建并关联一个起始员工,然后给该对话发一条「项目经理模式」指令,让它自己创建更多员工并把执行工作派出去。
|
|
295
307
|
|
|
@@ -367,6 +379,15 @@ collab_dispatch({ worker: "前端", task: "…" })
|
|
|
367
379
|
- 阶段本质就是普通的一轮:员工照常回报;仍有轮次在等待回报时,`complete` 会拒绝。
|
|
368
380
|
- 队列保存在员工关联上;`remove` 删除待开始阶段,`clear` 清空所有待开始阶段。
|
|
369
381
|
|
|
382
|
+
## 对话待办队列
|
|
383
|
+
|
|
384
|
+
任意对话(不只是项目经理)都可以有自己的提示词队列:
|
|
385
|
+
|
|
386
|
+
- 在「对话待办」卡片里添加,或 `/collab queue {"action":"add","title":"…","prompt":"…"}`。
|
|
387
|
+
- `start` 把第一条待发提示词作为普通用户消息发进去;该回合结束后,自动发送下一条。
|
|
388
|
+
- `pause` 在当前回合后停止自动连发,`resume` 恢复,`clear` 清空待发。
|
|
389
|
+
- 队列按对话保存,插件重载后仍在。
|
|
390
|
+
|
|
370
391
|
## 项目
|
|
371
392
|
|
|
372
393
|
一个项目就是「一个项目经理对话所管理的员工集合」。不同项目经理就是不同项目,互不混淆:
|
|
@@ -437,6 +458,7 @@ collab_dispatch({ worker: "前端", task: "…" })
|
|
|
437
458
|
/collab create {"name":"前端","preset":"standard"}
|
|
438
459
|
/collab remote {"action":"link","device":"laptop","worker":"frontend"}
|
|
439
460
|
/collab stage {"action":"add","title":"阶段一","prompt":"…"}
|
|
461
|
+
/collab queue {"action":"add","title":"第一步","prompt":"…"}
|
|
440
462
|
/collab relay {"action":"set","mode":"ntfy","hubRoom":"my-project","hubToken":"…"}
|
|
441
463
|
/collab configure {"worker":"session-…","preset":"ptc"}
|
|
442
464
|
/collab configure {"worker":"session-…","provider":"deepseek-account","model":"deepseek-flash"}
|
package/client.js
CHANGED
|
@@ -7,9 +7,9 @@ window.__ModuleLoader__.load({
|
|
|
7
7
|
|
|
8
8
|
const MESSAGES = {
|
|
9
9
|
zh: {
|
|
10
|
-
nav: '
|
|
11
|
-
title: '
|
|
12
|
-
intro: '
|
|
10
|
+
nav: '协作待办',
|
|
11
|
+
title: '协作待办',
|
|
12
|
+
intro: '把对话组织成协作网络:项目经理自主创建员工、派发任务并验收回报;也可以给任意对话预设一串提示词,完成一轮自动发下一条。核心是协作,待办队列用来把长流程串起来。',
|
|
13
13
|
workSession: '工作会话',
|
|
14
14
|
workSessionHint: '选择要操作的对话。建立关联时,它就是项目经理对话。',
|
|
15
15
|
messageLanguage: '对话消息语言',
|
|
@@ -117,7 +117,7 @@ window.__ModuleLoader__.load({
|
|
|
117
117
|
remoteMissing: '请填写远端设备和别名。',
|
|
118
118
|
remoteLinkDone: '已关联远端员工,接着给它派发任务。',
|
|
119
119
|
stageTitle: '阶段待办(To-do)',
|
|
120
|
-
stageNoManager: '
|
|
120
|
+
stageNoManager: '这个对话还不是项目经理。先在下方关联一个员工,或在侧栏右键该对话选择「设为项目经理并启动」,之后就能在这里预先写多个大阶段。',
|
|
121
121
|
stageIntro: '先写好几个大阶段,完成一个会自动派发下一个。',
|
|
122
122
|
stageEmpty: '还没有阶段。先添加几个大阶段,完成一个会自动派发下一个。',
|
|
123
123
|
stageWorker: '员工',
|
|
@@ -126,6 +126,23 @@ window.__ModuleLoader__.load({
|
|
|
126
126
|
stagePrompt: '提示词',
|
|
127
127
|
stageAcceptance: '验收标准',
|
|
128
128
|
stageAdd: '添加到阶段队列',
|
|
129
|
+
queueTitle: '对话待办(自动连发)',
|
|
130
|
+
queueIntro: '给这个对话预先写好一系列提示词;每轮结束后自动发下一条。',
|
|
131
|
+
queueAddTitle: '标题(可选)',
|
|
132
|
+
queuePrompt: '提示词 / 任务',
|
|
133
|
+
queueAdd: '加到队尾',
|
|
134
|
+
queueStart: '发送下一条',
|
|
135
|
+
queuePause: '暂停自动连发',
|
|
136
|
+
queueResume: '恢复自动连发',
|
|
137
|
+
queueClear: '清空待发',
|
|
138
|
+
queueEmpty: '还没有待办。',
|
|
139
|
+
queuePending: '待发',
|
|
140
|
+
queueSent: '进行中',
|
|
141
|
+
queueDone: '完成',
|
|
142
|
+
queueRemove: '删除',
|
|
143
|
+
queueUntitled: '未命名任务',
|
|
144
|
+
queueAuto: '自动连发',
|
|
145
|
+
queuePaused: '已暂停',
|
|
129
146
|
stageAdded: '阶段已添加。',
|
|
130
147
|
stageStarted: '阶段已开始。',
|
|
131
148
|
stageFinished: '阶段已完成。',
|
|
@@ -143,9 +160,9 @@ window.__ModuleLoader__.load({
|
|
|
143
160
|
menuFailed: '创建员工失败',
|
|
144
161
|
},
|
|
145
162
|
en: {
|
|
146
|
-
nav: '
|
|
147
|
-
title: '
|
|
148
|
-
intro: '
|
|
163
|
+
nav: 'Collab To-do',
|
|
164
|
+
title: 'Collab To-do',
|
|
165
|
+
intro: 'Organise conversations into a collaboration network: a manager creates workers, dispatches tasks and reviews reports; pre-write a prompt queue for any conversation to advance after each turn. Collaboration is the core; the to-do queue strings long workflows together.',
|
|
149
166
|
workSession: 'Working conversation',
|
|
150
167
|
workSessionHint: 'The conversation to act on. When you create a link, it becomes the project manager.',
|
|
151
168
|
messageLanguage: 'Message language',
|
|
@@ -253,7 +270,7 @@ window.__ModuleLoader__.load({
|
|
|
253
270
|
remoteMissing: 'Enter the remote device and alias.',
|
|
254
271
|
remoteLinkDone: 'Remote worker linked; dispatch a task next.',
|
|
255
272
|
stageTitle: 'To-do list',
|
|
256
|
-
stageNoManager: 'This conversation is not a project manager yet. Link a worker below, or right-click the conversation in the sidebar and choose "Set as project manager (
|
|
273
|
+
stageNoManager: 'This conversation is not a project manager yet. Link a worker below, or right-click the conversation in the sidebar and choose "Set as project manager (start)"; then you can pre-write multiple stages here.',
|
|
257
274
|
stageIntro: 'Write a few large stages up front; completing one dispatches the next automatically.',
|
|
258
275
|
stageEmpty: 'No stage yet. Add a few large stages; completing one dispatches the next automatically.',
|
|
259
276
|
stageWorker: 'Worker',
|
|
@@ -262,6 +279,23 @@ window.__ModuleLoader__.load({
|
|
|
262
279
|
stagePrompt: 'Prompt',
|
|
263
280
|
stageAcceptance: 'Acceptance',
|
|
264
281
|
stageAdd: 'Add to stage queue',
|
|
282
|
+
queueTitle: 'Conversation to-do (auto-advance)',
|
|
283
|
+
queueIntro: 'Pre-write a series of prompts for this conversation; the next one is sent when a turn ends.',
|
|
284
|
+
queueAddTitle: 'Title (optional)',
|
|
285
|
+
queuePrompt: 'Prompt / task',
|
|
286
|
+
queueAdd: 'Append',
|
|
287
|
+
queueStart: 'Send next',
|
|
288
|
+
queuePause: 'Pause auto-advance',
|
|
289
|
+
queueResume: 'Resume auto-advance',
|
|
290
|
+
queueClear: 'Clear pending',
|
|
291
|
+
queueEmpty: 'No items yet.',
|
|
292
|
+
queuePending: 'Pending',
|
|
293
|
+
queueSent: 'Running',
|
|
294
|
+
queueDone: 'Done',
|
|
295
|
+
queueRemove: 'Remove',
|
|
296
|
+
queueUntitled: 'Untitled task',
|
|
297
|
+
queueAuto: 'Auto-advance',
|
|
298
|
+
queuePaused: 'Paused',
|
|
265
299
|
stageAdded: 'Stage added.',
|
|
266
300
|
stageStarted: 'Stage started.',
|
|
267
301
|
stageFinished: 'Stage finished.',
|
|
@@ -385,6 +419,10 @@ window.__ModuleLoader__.load({
|
|
|
385
419
|
const [stageTitle, setStageTitle] = React.useState('')
|
|
386
420
|
const [stagePrompt, setStagePrompt] = React.useState('')
|
|
387
421
|
const [stageAcceptance, setStageAcceptance] = React.useState('')
|
|
422
|
+
const [queue, setQueue] = React.useState(null)
|
|
423
|
+
const [queueTitle, setQueueTitle] = React.useState('')
|
|
424
|
+
const [queuePrompt, setQueuePrompt] = React.useState('')
|
|
425
|
+
const [queueBusy, setQueueBusy] = React.useState(false)
|
|
388
426
|
const commandsRef = React.useRef(commands)
|
|
389
427
|
commandsRef.current = commands
|
|
390
428
|
|
|
@@ -545,6 +583,44 @@ window.__ModuleLoader__.load({
|
|
|
545
583
|
}
|
|
546
584
|
|
|
547
585
|
/** Run one command, show the dictionary text, then refresh the board. */
|
|
586
|
+
const readQueue = async (sessionId) => {
|
|
587
|
+
try {
|
|
588
|
+
const value = await runCommand(commandsRef.current, sessionId, '/collab queue {"action":"list"}')
|
|
589
|
+
if (value !== null && typeof value === 'object' && Array.isArray(value.items)) setQueue(value)
|
|
590
|
+
return value
|
|
591
|
+
} catch {
|
|
592
|
+
setQueue(null)
|
|
593
|
+
return null
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
const queueAction = async (action, extra = {}) => {
|
|
598
|
+
if (workId === undefined) return
|
|
599
|
+
setQueueBusy(true)
|
|
600
|
+
setError(null)
|
|
601
|
+
setNotice(null)
|
|
602
|
+
try {
|
|
603
|
+
const value = await runCommand(commandsRef.current, workId, `/collab queue ${JSON.stringify({ action, ...extra })}`)
|
|
604
|
+
if (value !== null && typeof value === 'object' && Array.isArray(value.items)) setQueue(value)
|
|
605
|
+
if (action === 'add') {
|
|
606
|
+
setQueueTitle('')
|
|
607
|
+
setQueuePrompt('')
|
|
608
|
+
}
|
|
609
|
+
} catch (cause) {
|
|
610
|
+
setError(cause instanceof Error ? cause.message : String(cause))
|
|
611
|
+
} finally {
|
|
612
|
+
setQueueBusy(false)
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
React.useEffect(() => {
|
|
617
|
+
if (workId === undefined) {
|
|
618
|
+
setQueue(null)
|
|
619
|
+
return
|
|
620
|
+
}
|
|
621
|
+
void readQueue(workId)
|
|
622
|
+
}, [workId])
|
|
623
|
+
|
|
548
624
|
const runAction = async (line, successText) => {
|
|
549
625
|
if (workId === undefined) return
|
|
550
626
|
setBusy(true)
|
|
@@ -1019,7 +1095,7 @@ window.__ModuleLoader__.load({
|
|
|
1019
1095
|
)
|
|
1020
1096
|
}
|
|
1021
1097
|
|
|
1022
|
-
const stageCard = h('div', { style: S.card },
|
|
1098
|
+
const stageCard = role !== 'manager' ? null : h('div', { style: S.card },
|
|
1023
1099
|
h('div', { style: S.cardHead },
|
|
1024
1100
|
h('h3', { style: S.cardTitle }, t('stageTitle')),
|
|
1025
1101
|
h('span', { style: S.muted }, t('stageIntro')),
|
|
@@ -1081,6 +1157,79 @@ window.__ModuleLoader__.load({
|
|
|
1081
1157
|
),
|
|
1082
1158
|
)
|
|
1083
1159
|
|
|
1160
|
+
const queueItems = queue !== null && typeof queue === 'object' && Array.isArray(queue.items) ? queue.items : []
|
|
1161
|
+
const queueCard = role === 'manager'
|
|
1162
|
+
? null
|
|
1163
|
+
: h('div', { style: S.card },
|
|
1164
|
+
h('div', { style: S.cardHead },
|
|
1165
|
+
h('h3', { style: S.cardTitle }, t('queueTitle')),
|
|
1166
|
+
h('span', { style: S.badge }, queue !== null && queue.auto === false ? t('queuePaused') : t('queueAuto')),
|
|
1167
|
+
),
|
|
1168
|
+
h('p', { style: S.intro }, t('queueIntro')),
|
|
1169
|
+
h('label', { style: S.label }, t('queueAddTitle'),
|
|
1170
|
+
h('input', {
|
|
1171
|
+
style: S.input,
|
|
1172
|
+
value: queueTitle,
|
|
1173
|
+
disabled: queueBusy,
|
|
1174
|
+
onChange: (event) => setQueueTitle(event.target.value),
|
|
1175
|
+
})),
|
|
1176
|
+
h('label', { style: S.label }, t('queuePrompt'),
|
|
1177
|
+
h('textarea', {
|
|
1178
|
+
style: { ...S.input, minHeight: 88, resize: 'vertical' },
|
|
1179
|
+
value: queuePrompt,
|
|
1180
|
+
disabled: queueBusy,
|
|
1181
|
+
onChange: (event) => setQueuePrompt(event.target.value),
|
|
1182
|
+
})),
|
|
1183
|
+
h('div', { style: S.row },
|
|
1184
|
+
h('button', {
|
|
1185
|
+
type: 'button',
|
|
1186
|
+
style: S.primary,
|
|
1187
|
+
disabled: queueBusy || queuePrompt.trim() === '',
|
|
1188
|
+
onClick: () => void queueAction('add', { title: queueTitle.trim(), prompt: queuePrompt.trim() }),
|
|
1189
|
+
}, t('queueAdd')),
|
|
1190
|
+
),
|
|
1191
|
+
h('div', { style: S.row },
|
|
1192
|
+
h('button', {
|
|
1193
|
+
type: 'button',
|
|
1194
|
+
style: S.secondary,
|
|
1195
|
+
disabled: queueBusy || queue === null || queue.active !== null || !queueItems.some((item) => item.status === 'pending'),
|
|
1196
|
+
onClick: () => void queueAction('start'),
|
|
1197
|
+
}, t('queueStart')),
|
|
1198
|
+
h('button', {
|
|
1199
|
+
type: 'button',
|
|
1200
|
+
style: S.secondary,
|
|
1201
|
+
disabled: queueBusy || queue === null,
|
|
1202
|
+
onClick: () => void queueAction(queue !== null && queue.auto === false ? 'resume' : 'pause'),
|
|
1203
|
+
}, queue !== null && queue.auto === false ? t('queueResume') : t('queuePause')),
|
|
1204
|
+
h('button', {
|
|
1205
|
+
type: 'button',
|
|
1206
|
+
style: S.danger,
|
|
1207
|
+
disabled: queueBusy || queue === null || !queueItems.some((item) => item.status === 'pending'),
|
|
1208
|
+
onClick: () => void queueAction('clear'),
|
|
1209
|
+
}, t('queueClear')),
|
|
1210
|
+
),
|
|
1211
|
+
queue === null
|
|
1212
|
+
? h('p', { style: S.intro }, t('loading'))
|
|
1213
|
+
: queueItems.length === 0
|
|
1214
|
+
? h('p', { style: S.intro }, t('queueEmpty'))
|
|
1215
|
+
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
1216
|
+
queueItems.map((item, index) => h('div', { key: item.id, style: S.worker },
|
|
1217
|
+
h('div', { style: S.workerMain },
|
|
1218
|
+
h('div', { style: S.workerName }, `${index + 1}. ${item.title || t('queueUntitled')}`),
|
|
1219
|
+
h('div', { style: S.muted }, `${item.status === 'pending' ? t('queuePending') : item.status === 'sent' ? t('queueSent') : t('queueDone')} · ${item.prompt}`),
|
|
1220
|
+
),
|
|
1221
|
+
item.status === 'pending'
|
|
1222
|
+
? h('button', {
|
|
1223
|
+
type: 'button',
|
|
1224
|
+
style: S.danger,
|
|
1225
|
+
disabled: queueBusy,
|
|
1226
|
+
onClick: () => void queueAction('remove', { index: index + 1 }),
|
|
1227
|
+
}, t('queueRemove'))
|
|
1228
|
+
: null,
|
|
1229
|
+
)),
|
|
1230
|
+
),
|
|
1231
|
+
)
|
|
1232
|
+
|
|
1084
1233
|
const groups = []
|
|
1085
1234
|
const groupMap = new Map()
|
|
1086
1235
|
for (const link of links) {
|
|
@@ -1233,6 +1382,7 @@ window.__ModuleLoader__.load({
|
|
|
1233
1382
|
currentCard,
|
|
1234
1383
|
relayCard,
|
|
1235
1384
|
stageCard,
|
|
1385
|
+
queueCard,
|
|
1236
1386
|
boardCard,
|
|
1237
1387
|
)
|
|
1238
1388
|
}
|
package/index.js
CHANGED
|
@@ -41,7 +41,7 @@ const DONE = 'done'
|
|
|
41
41
|
const STOPPED = 'stopped'
|
|
42
42
|
const REPORTS = new Set(['done', 'partial', 'blocked'])
|
|
43
43
|
const PROMPT_TIMEOUT_MS = 180000
|
|
44
|
-
const ENGINE = 'collab-pair/1.
|
|
44
|
+
const ENGINE = 'collab-pair/1.5.0'
|
|
45
45
|
|
|
46
46
|
/** A recoverable failure whose message is meant for the model. */
|
|
47
47
|
class CollabError extends Error {}
|
|
@@ -527,6 +527,7 @@ export function apply(ctx, rawConfig) {
|
|
|
527
527
|
let storageError = null
|
|
528
528
|
const remoteAliases = new Map()
|
|
529
529
|
const remoteInbound = new Map()
|
|
530
|
+
const queues = new Map()
|
|
530
531
|
let remoteState = 'pending'
|
|
531
532
|
let remoteCursor = 0
|
|
532
533
|
let remoteLastError = null
|
|
@@ -789,6 +790,165 @@ export function apply(ctx, rawConfig) {
|
|
|
789
790
|
}
|
|
790
791
|
}
|
|
791
792
|
|
|
793
|
+
// ------------------------------------------------------------ session to-do
|
|
794
|
+
|
|
795
|
+
function normalizeQueue(value, sessionId) {
|
|
796
|
+
const items = []
|
|
797
|
+
for (const item of Array.isArray(value?.items) ? value.items.slice(0, 100) : []) {
|
|
798
|
+
if (item === null || typeof item !== 'object') continue
|
|
799
|
+
const prompt = typeof item.prompt === 'string' ? item.prompt.trim() : ''
|
|
800
|
+
if (prompt === '') continue
|
|
801
|
+
const status = item.status === 'sent' || item.status === 'done' ? item.status : 'pending'
|
|
802
|
+
items.push({
|
|
803
|
+
id: typeof item.id === 'string' ? item.id : `q-${randomUUID().slice(0, 8)}`,
|
|
804
|
+
title: typeof item.title === 'string' ? item.title : '',
|
|
805
|
+
prompt,
|
|
806
|
+
status,
|
|
807
|
+
...(typeof item.sentAt === 'number' ? { sentAt: item.sentAt } : {}),
|
|
808
|
+
...(typeof item.completedAt === 'number' ? { completedAt: item.completedAt } : {}),
|
|
809
|
+
...(typeof item.requestId === 'string' ? { requestId: item.requestId } : {}),
|
|
810
|
+
...(typeof item.marker === 'string' ? { marker: item.marker } : {}),
|
|
811
|
+
})
|
|
812
|
+
}
|
|
813
|
+
let activeId = typeof value?.activeId === 'string' ? value.activeId : null
|
|
814
|
+
if (activeId !== null && !items.some((item) => item.id === activeId && item.status === 'sent')) activeId = null
|
|
815
|
+
if (activeId === null) {
|
|
816
|
+
const sent = items.find((item) => item.status === 'sent')
|
|
817
|
+
if (sent !== undefined) activeId = sent.id
|
|
818
|
+
}
|
|
819
|
+
return {
|
|
820
|
+
sessionId,
|
|
821
|
+
items,
|
|
822
|
+
activeId,
|
|
823
|
+
auto: value?.auto !== false,
|
|
824
|
+
updatedAt: Number.isFinite(value?.updatedAt) ? value.updatedAt : Date.now(),
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
async function readQueue(sessionId) {
|
|
829
|
+
const cached = queues.get(sessionId)
|
|
830
|
+
if (cached !== undefined) return cached
|
|
831
|
+
let stored
|
|
832
|
+
const domain = await remoteReady.catch(() => undefined)
|
|
833
|
+
if (domain !== undefined) {
|
|
834
|
+
try {
|
|
835
|
+
stored = [...domain.table('state').entries()].find(([key]) => key === `queue:${sessionId}`)?.[1]
|
|
836
|
+
} catch (error) {
|
|
837
|
+
ctx.logger.warn(`collab-pair: reading the queue for ${sessionId} failed: ${String(error)}`)
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
const queue = normalizeQueue(stored, sessionId)
|
|
841
|
+
queues.set(sessionId, queue)
|
|
842
|
+
return queue
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
async function persistQueue(queue) {
|
|
846
|
+
queues.set(queue.sessionId, queue)
|
|
847
|
+
const domain = await remoteReady.catch(() => undefined)
|
|
848
|
+
if (domain === undefined) return
|
|
849
|
+
try {
|
|
850
|
+
await domain.table('state').put(`queue:${queue.sessionId}`, JSON.parse(JSON.stringify(queue)))
|
|
851
|
+
} catch (error) {
|
|
852
|
+
ctx.logger.warn(`collab-pair: persisting the queue for ${queue.sessionId} failed: ${String(error)}`)
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
function queueView(queue) {
|
|
857
|
+
return {
|
|
858
|
+
sessionId: queue.sessionId,
|
|
859
|
+
auto: queue.auto,
|
|
860
|
+
active: queue.activeId,
|
|
861
|
+
items: queue.items.map((item) => ({
|
|
862
|
+
id: item.id,
|
|
863
|
+
title: item.title,
|
|
864
|
+
prompt: clip(item.prompt, 400),
|
|
865
|
+
status: item.status,
|
|
866
|
+
...(item.sentAt === undefined ? {} : { sentAt: isoTime(item.sentAt) }),
|
|
867
|
+
...(item.completedAt === undefined ? {} : { completedAt: isoTime(item.completedAt) }),
|
|
868
|
+
})),
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/** Send the first pending prompt as a normal user turn. */
|
|
873
|
+
async function startQueueItem(sessionId, signal) {
|
|
874
|
+
const queue = await readQueue(sessionId)
|
|
875
|
+
if (queue.activeId !== null) throw new CollabError('当前待办仍在等待完成;先等这一轮结束,或暂停队列。')
|
|
876
|
+
const next = queue.items.find((item) => item.status === 'pending')
|
|
877
|
+
if (next === undefined) throw new CollabError('队列里没有待发送的提示词。')
|
|
878
|
+
const index = queue.items.indexOf(next) + 1
|
|
879
|
+
const requestId = `cp-queue-${sessionId}-${next.id}`
|
|
880
|
+
const marker = `[[collab-queue:${next.id}]]`
|
|
881
|
+
next.status = 'sent'
|
|
882
|
+
next.sentAt = Date.now()
|
|
883
|
+
next.requestId = requestId
|
|
884
|
+
next.marker = marker
|
|
885
|
+
queue.activeId = next.id
|
|
886
|
+
queue.updatedAt = Date.now()
|
|
887
|
+
await persistQueue(queue)
|
|
888
|
+
const text = [
|
|
889
|
+
`【对话待办 ${index}/${queue.items.length}】`,
|
|
890
|
+
...(next.title === '' ? [] : [next.title]),
|
|
891
|
+
'',
|
|
892
|
+
next.prompt,
|
|
893
|
+
'',
|
|
894
|
+
'完成本轮后直接给出结果;若队列还有下一条,会在本轮结束后自动发送。',
|
|
895
|
+
marker,
|
|
896
|
+
].join('\n')
|
|
897
|
+
try {
|
|
898
|
+
await deliver(sessionId, text, requestId, 'queue', signal ?? AbortSignal.timeout(PROMPT_TIMEOUT_MS))
|
|
899
|
+
} catch (error) {
|
|
900
|
+
next.status = 'pending'
|
|
901
|
+
delete next.sentAt
|
|
902
|
+
delete next.requestId
|
|
903
|
+
delete next.marker
|
|
904
|
+
queue.activeId = null
|
|
905
|
+
queue.updatedAt = Date.now()
|
|
906
|
+
await persistQueue(queue)
|
|
907
|
+
throw error
|
|
908
|
+
}
|
|
909
|
+
return { queue, item: next }
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/** Finish the active queue turn and send the next prompt when auto is on. */
|
|
913
|
+
async function advanceQueue(session, event) {
|
|
914
|
+
const queue = await readQueue(session.id)
|
|
915
|
+
if (queue.activeId === null) return
|
|
916
|
+
const active = queue.items.find((item) => item.id === queue.activeId && item.status === 'sent')
|
|
917
|
+
if (active === undefined) return
|
|
918
|
+
const turn = event.data?.turn
|
|
919
|
+
if (!Number.isSafeInteger(turn)) return
|
|
920
|
+
let events
|
|
921
|
+
try {
|
|
922
|
+
events = turnEvents(session, turn, event.seq)
|
|
923
|
+
} catch (error) {
|
|
924
|
+
ctx.logger.warn(`collab-pair: reading a queue turn failed: ${String(error)}`)
|
|
925
|
+
return
|
|
926
|
+
}
|
|
927
|
+
if (events === undefined || !claimedQueue(events, active)) return
|
|
928
|
+
active.status = 'done'
|
|
929
|
+
active.completedAt = Date.now()
|
|
930
|
+
queue.activeId = null
|
|
931
|
+
queue.updatedAt = Date.now()
|
|
932
|
+
await persistQueue(queue)
|
|
933
|
+
if (!queue.auto) return
|
|
934
|
+
if (queue.items.some((item) => item.status === 'pending')) {
|
|
935
|
+
try {
|
|
936
|
+
await startQueueItem(session.id, AbortSignal.timeout(PROMPT_TIMEOUT_MS))
|
|
937
|
+
} catch (error) {
|
|
938
|
+
ctx.logger.warn(`collab-pair: sending the next queue item for ${session.id} failed: ${String(error)}`)
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function claimedQueue(events, item) {
|
|
944
|
+
for (const event of events) {
|
|
945
|
+
if (event.type !== 'user/message') continue
|
|
946
|
+
if (typeof item.requestId === 'string' && event.data?.source?.rpcId === item.requestId) return true
|
|
947
|
+
if (typeof item.marker === 'string' && messageText(event.data).includes(item.marker)) return true
|
|
948
|
+
}
|
|
949
|
+
return false
|
|
950
|
+
}
|
|
951
|
+
|
|
792
952
|
function hubConfigured() {
|
|
793
953
|
return cfg.relayMode === 'hub' && cfg.hubUrl !== '' && cfg.hubToken !== ''
|
|
794
954
|
}
|
|
@@ -1887,6 +2047,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1887
2047
|
/** Global post-commit listener: relay a worker turn that answered a dispatch. */
|
|
1888
2048
|
function onSessionEvent(session, event) {
|
|
1889
2049
|
if (event?.type !== 'turn/end') return
|
|
2050
|
+
void advanceQueue(session, event).catch((error) => ctx.logger.warn(`collab-pair: advancing a queue failed: ${String(error)}`))
|
|
1890
2051
|
const inbound = remoteInbound.get(session.id)
|
|
1891
2052
|
if (inbound !== undefined) {
|
|
1892
2053
|
void handleRemoteTurnEnd(session, event, inbound)
|
|
@@ -2908,7 +3069,7 @@ export function apply(ctx, rawConfig) {
|
|
|
2908
3069
|
name: 'collab',
|
|
2909
3070
|
description: '双对话协作:查看全部任务、关联员工、阶段队列、跨设备中继、设置项目名、配置预设与语言、派发任务、收尾或解除。',
|
|
2910
3071
|
input: {
|
|
2911
|
-
hint: 'tasks | status | link --peer <id|new> | create --name <名字> | manage --name <名字> | stage --action add --prompt ... | relay --action set --mode hub|ntfy | remote --action link --device <名> --worker <别名> | project --name <项目名> | dispatch --worker <id> --task ... | done --worker <id> --summary ...',
|
|
3072
|
+
hint: 'tasks | status | queue --action add --prompt ... | link --peer <id|new> | create --name <名字> | manage --name <名字> | stage --action add --prompt ... | relay --action set --mode hub|ntfy | remote --action link --device <名> --worker <别名> | project --name <项目名> | dispatch --worker <id> --task ... | done --worker <id> --summary ...',
|
|
2912
3073
|
},
|
|
2913
3074
|
handler: async (invocation) => {
|
|
2914
3075
|
try {
|
|
@@ -2916,6 +3077,55 @@ export function apply(ctx, rawConfig) {
|
|
|
2916
3077
|
if (action === 'tasks' || action === 'board') {
|
|
2917
3078
|
return { kind: 'success', text: JSON.stringify(await tasksBoard()) }
|
|
2918
3079
|
}
|
|
3080
|
+
if (action === 'queue') {
|
|
3081
|
+
const agent = invocation.agent
|
|
3082
|
+
if (agent === undefined) return { kind: 'error', text: '无法确定当前对话。' }
|
|
3083
|
+
const sub = typeof args?.action === 'string' ? args.action : 'list'
|
|
3084
|
+
const queue = await readQueue(agent.id)
|
|
3085
|
+
if (sub === 'list' || sub === 'status') {
|
|
3086
|
+
return { kind: 'success', text: JSON.stringify(queueView(queue)) }
|
|
3087
|
+
}
|
|
3088
|
+
if (sub === 'add') {
|
|
3089
|
+
const prompt = typeof args?.prompt === 'string' ? args.prompt.trim() : ''
|
|
3090
|
+
if (prompt === '') return { kind: 'error', text: 'prompt 不能为空。' }
|
|
3091
|
+
queue.items.push({
|
|
3092
|
+
id: `q-${randomUUID().slice(0, 8)}`,
|
|
3093
|
+
title: typeof args?.title === 'string' ? args.title.trim() : '',
|
|
3094
|
+
prompt,
|
|
3095
|
+
status: 'pending',
|
|
3096
|
+
})
|
|
3097
|
+
queue.updatedAt = Date.now()
|
|
3098
|
+
await persistQueue(queue)
|
|
3099
|
+
return { kind: 'success', text: JSON.stringify(queueView(queue)) }
|
|
3100
|
+
}
|
|
3101
|
+
if (sub === 'start') {
|
|
3102
|
+
const { queue: started, item } = await startQueueItem(agent.id, invocation.signal)
|
|
3103
|
+
return { kind: 'success', text: JSON.stringify({ ...queueView(started), started: item.id }) }
|
|
3104
|
+
}
|
|
3105
|
+
if (sub === 'pause' || sub === 'resume') {
|
|
3106
|
+
queue.auto = sub === 'resume'
|
|
3107
|
+
queue.updatedAt = Date.now()
|
|
3108
|
+
await persistQueue(queue)
|
|
3109
|
+
return { kind: 'success', text: JSON.stringify(queueView(queue)) }
|
|
3110
|
+
}
|
|
3111
|
+
if (sub === 'remove') {
|
|
3112
|
+
const index = clampInt(args?.index, 1, 100, 0)
|
|
3113
|
+
const item = index > 0 ? queue.items[index - 1] : undefined
|
|
3114
|
+
if (item === undefined) return { kind: 'error', text: 'index 超出范围。' }
|
|
3115
|
+
if (item.status !== 'pending') return { kind: 'error', text: '只能删除尚未发送的条目。' }
|
|
3116
|
+
queue.items.splice(index - 1, 1)
|
|
3117
|
+
queue.updatedAt = Date.now()
|
|
3118
|
+
await persistQueue(queue)
|
|
3119
|
+
return { kind: 'success', text: JSON.stringify(queueView(queue)) }
|
|
3120
|
+
}
|
|
3121
|
+
if (sub === 'clear') {
|
|
3122
|
+
queue.items = queue.items.filter((item) => item.status !== 'pending')
|
|
3123
|
+
queue.updatedAt = Date.now()
|
|
3124
|
+
await persistQueue(queue)
|
|
3125
|
+
return { kind: 'success', text: JSON.stringify(queueView(queue)) }
|
|
3126
|
+
}
|
|
3127
|
+
return { kind: 'error', text: 'action 必须是 list | add | start | pause | resume | remove | clear。' }
|
|
3128
|
+
}
|
|
2919
3129
|
if (action === 'manage') {
|
|
2920
3130
|
const agent = invocation.agent
|
|
2921
3131
|
if (agent === undefined) return { kind: 'error', text: '无法确定当前对话。' }
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
|
-
"title": "
|
|
4
|
-
"description": "
|
|
3
|
+
"title": "Collab To-do",
|
|
4
|
+
"description": "Organise conversations into a collaboration network: a manager creates workers, dispatches tasks and reviews reports; pre-write a prompt queue for any conversation to advance after each turn. Collaboration first, with a to-do queue for long workflows."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-collab-pair",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "DSH collaboration plugin: link a project-manager conversation with local or remote workers across devices, dispatch rounds, relay results and manage projects/stages automatically. Also ships a prompt to-do queue for any conversation: pre-write a series of prompts and the next one is sent when a turn ends. Includes a relay hub and a free ntfy.sh transport.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "awa1231",
|