dsh-collab-pair 1.4.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # dsh-collab-pair
2
2
 
3
- > A DSH plugin for large projects: link one project-manager conversation to one or more worker conversations. Dispatch each round once from the manager instead of repeating prompts across conversations; results come back automatically, and unattended runs keep moving.
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,8 +38,17 @@ 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
- Right-click a conversation in the sidebar and choose **Set as project manager (new worker)**: the plugin creates and links a fresh worker, so that conversation becomes a manager.
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.
44
+
45
+ ### Manager mode
46
+
47
+ Once a conversation is a manager, its prompt tells it to:
48
+
49
+ - create workers itself with `collab_worker_create` instead of waiting for the human to do it;
50
+ - delegate execution and keep its own context for reviewing reports and dispatching again — it should not spend a long turn doing a worker's job;
51
+ - confirm the project goal before creating workers and dispatching the first stage.
43
52
 
44
53
  The manager card also shows the **project name** and lets you rename it.
45
54
 
@@ -111,6 +120,15 @@ A human can pre-write several large stages for one worker; finishing one dispatc
111
120
  - A stage is a normal round: the worker reports as usual, and `complete` waits until no round is pending.
112
121
  - The queue is stored on the worker link; `remove` deletes a pending stage, `clear` removes all pending stages.
113
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
+
114
132
  ## Projects
115
133
 
116
134
  A project is the set of workers managed by one project-manager conversation. Different managers are different projects, so nothing mixes:
@@ -185,6 +203,7 @@ The settings page uses it; it can also be typed manually:
185
203
  /collab create {"name":"前端","preset":"standard"}
186
204
  /collab remote {"action":"link","device":"laptop","worker":"frontend"}
187
205
  /collab stage {"action":"add","title":"阶段一","prompt":"…"}
206
+ /collab queue {"action":"add","title":"第一步","prompt":"…"}
188
207
  /collab relay {"action":"set","mode":"ntfy","hubRoom":"my-project","hubToken":"…"}
189
208
  /collab configure {"worker":"session-…","preset":"ptc"}
190
209
  /collab configure {"worker":"session-…","provider":"deepseek-account","model":"deepseek-flash"}
@@ -244,7 +263,7 @@ One record per worker lives in `$DSH_HOME/storages/collab_pair.json` (storage-do
244
263
 
245
264
  # 中文说明
246
265
 
247
- > DSH 插件:一个项目经理对话管理多个员工对话,任务自动流转,并提供全部任务看板。
266
+ > 用于大项目的 DSH 协作插件:把项目经理对话与本机/远端员工关联,自动派发、回传并推进阶段;也可以给任意对话预设一串提示词待办,完成一轮自动发下一条。
248
267
 
249
268
  [**GitHub**](https://github.com/awa1231/dsh-collab-pair) · [给个 Star ★](https://github.com/awa1231/dsh-collab-pair)
250
269
 
@@ -272,7 +291,7 @@ dsh plugin add dsh-collab-pair
272
291
 
273
292
  ## 可视化设置页
274
293
 
275
- **设置 → 双对话协作**,从上到下:
294
+ **设置 → 协作待办**,从上到下:
276
295
 
277
296
  1. **工作会话**:选择要操作的对话(默认当前打开的对话)。
278
297
  2. **当前会话 · <标题>**:先看**这个对话自己的**关联与状态。
@@ -281,9 +300,18 @@ dsh plugin add dsh-collab-pair
281
300
  - 无关联:直接显示关联表单。
282
301
  3. **全部任务**:所有协作的任务看板,不限当前会话。每行显示员工、所属项目经理、第几轮、**工作状态**(`工作中` / `等待回报` / `空闲` / `已结束`)、等待时长、本轮任务、最近回报。点「刷新」重新读取。
283
302
  4. **跨设备协作**:中继模式(关闭 / 自建 hub / 免费 ntfy.sh)、URL、房间、令牌、设备名;保存/测试、连接状态、员工别名注册、远端员工关联。
284
- 5. **阶段队列**(仅项目经理):选员工,填标题/提示词/验收标准;可开始、完成并自动派发下一阶段、删除待开始阶段。
303
+ 5. **阶段待办**(仅项目经理):选员工,填标题/提示词/验收标准;可开始、完成并自动派发下一阶段、删除待开始阶段。
304
+ 6. **对话待办**(其他任意对话):预先写一串提示词;点开始发第一条,当前回合结束后自动发下一条。可暂停、恢复、清空待发。
285
305
 
286
- 在侧栏右键一个对话,选「设为项目经理(新建员工)」:插件会新建并关联一个员工,使该对话成为项目经理。
306
+ 在侧栏右键一个对话,选「设为项目经理并启动」:插件会新建并关联一个起始员工,然后给该对话发一条「项目经理模式」指令,让它自己创建更多员工并把执行工作派出去。
307
+
308
+ ### 项目经理模式
309
+
310
+ 对话成为项目经理后,提示词会要求它:
311
+
312
+ - 需要人干活时自己用 `collab_worker_create` 创建员工,不等待用户手动新建;
313
+ - 把执行交给员工,自己的上下文留给验收和继续派发——不要花长时间亲自做员工的活;
314
+ - 创建员工和派发第一阶段之前,先确认项目目标。
287
315
 
288
316
  页面只做关联/解除和查看,不代填目标、任务、验收——这些交给项目经理对话。
289
317
 
@@ -351,6 +379,15 @@ collab_dispatch({ worker: "前端", task: "…" })
351
379
  - 阶段本质就是普通的一轮:员工照常回报;仍有轮次在等待回报时,`complete` 会拒绝。
352
380
  - 队列保存在员工关联上;`remove` 删除待开始阶段,`clear` 清空所有待开始阶段。
353
381
 
382
+ ## 对话待办队列
383
+
384
+ 任意对话(不只是项目经理)都可以有自己的提示词队列:
385
+
386
+ - 在「对话待办」卡片里添加,或 `/collab queue {"action":"add","title":"…","prompt":"…"}`。
387
+ - `start` 把第一条待发提示词作为普通用户消息发进去;该回合结束后,自动发送下一条。
388
+ - `pause` 在当前回合后停止自动连发,`resume` 恢复,`clear` 清空待发。
389
+ - 队列按对话保存,插件重载后仍在。
390
+
354
391
  ## 项目
355
392
 
356
393
  一个项目就是「一个项目经理对话所管理的员工集合」。不同项目经理就是不同项目,互不混淆:
@@ -421,6 +458,7 @@ collab_dispatch({ worker: "前端", task: "…" })
421
458
  /collab create {"name":"前端","preset":"standard"}
422
459
  /collab remote {"action":"link","device":"laptop","worker":"frontend"}
423
460
  /collab stage {"action":"add","title":"阶段一","prompt":"…"}
461
+ /collab queue {"action":"add","title":"第一步","prompt":"…"}
424
462
  /collab relay {"action":"set","mode":"ntfy","hubRoom":"my-project","hubToken":"…"}
425
463
  /collab configure {"worker":"session-…","preset":"ptc"}
426
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: '阶段已完成。',
@@ -138,14 +155,14 @@ window.__ModuleLoader__.load({
138
155
  stageStart: '开始',
139
156
  stageComplete: '完成并发下一阶段',
140
157
  stageRemove: '删除',
141
- menuSetManager: '设为项目经理(新建员工)',
158
+ menuSetManager: '设为项目经理并启动',
142
159
  menuWorkerName: '新员工名字',
143
160
  menuFailed: '创建员工失败',
144
161
  },
145
162
  en: {
146
- nav: 'Collaboration pair',
147
- title: 'Collaboration pair',
148
- intro: 'On large projects you no longer repeat the same prompts across conversations: link once, then the manager dispatches every round and worker results come back automatically, with unattended runs kept moving. The plugin only links and drives; the goal, tasks, and acceptance stay with the manager.',
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 (new worker)"; then you can pre-write multiple stages here.',
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.',
@@ -274,7 +308,7 @@ window.__ModuleLoader__.load({
274
308
  stageStart: 'Start',
275
309
  stageComplete: 'Complete and dispatch next',
276
310
  stageRemove: 'Remove',
277
- menuSetManager: 'Set as project manager (new worker)',
311
+ menuSetManager: 'Set as project manager (start)',
278
312
  menuWorkerName: 'New worker name',
279
313
  menuFailed: 'Could not create the worker',
280
314
  },
@@ -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
  }
@@ -1279,7 +1429,7 @@ window.__ModuleLoader__.load({
1279
1429
  const name = typeof answer === 'string' ? answer.trim() : ''
1280
1430
  setBusy(true)
1281
1431
  try {
1282
- await runCommand(commands, sessionId, `/collab create ${JSON.stringify(name === '' ? {} : { name })}`)
1432
+ await runCommand(commands, sessionId, `/collab manage ${JSON.stringify(name === '' ? {} : { name })}`)
1283
1433
  } catch (cause) {
1284
1434
  const detail = cause instanceof Error ? cause.message : String(cause)
1285
1435
  if (typeof window.alert === 'function') window.alert(`${boundT('menuFailed')}\n${detail}`)
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.4.2'
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 {}
@@ -270,17 +270,17 @@ const LANGUAGES = {
270
270
  return [
271
271
  '## 双对话协作 · 你是项目经理',
272
272
  ...(project ? [`项目:${project}`] : []),
273
- `你正在协调 ${count} 个员工对话;项目目标、任务拆解与验收标准由你在对话中掌握。`,
273
+ `你正在协调 ${count} 个员工对话。默认由你自主创建员工并把执行工作派出去;项目目标、拆解与验收标准由你掌握。`,
274
274
  '员工:',
275
275
  ...rows,
276
276
  '',
277
277
  '规则:',
278
+ '- 默认自主创建员工:需要人干活时,先用 `collab_worker_create` 建立合适的员工(可按角色建多个),再派发;不要等用户手动新建。',
279
+ '- 不要自己承担员工的具体执行工作。你负责拆解、派发、验收和决定下一步;自己动手只限于规划、审阅和必要协调,避免因长时间执行而错过员工回报。',
278
280
  '- 用 `collab_dispatch` 派发任务;有多个员工时用 `worker` 指定员工(sessionId 或标题),只有一个时可省略。',
279
- '- 需要新的员工对话时用 `collab_worker_create`(可命名、设预设/模型,并自动关联)。',
280
281
  '- 阶段队列:用 `collab_stage` 添加/查看;当前阶段验收通过后调用 `collab_stage({action:"complete"})`,会自动派发下一阶段。',
282
+ '- 收到【协作回报】后尽快验收并继续派发;保持自己的上下文轻量,细节让员工在回报里给出摘要。',
281
283
  '- 需要调整某个员工的 agent 预设或模型时,用 `collab_configure`(worker 指定员工)。',
282
- '- 收到以【协作回报】开头的消息后,继续派发,或对该员工调用 `collab_done`;`collab_status` 查看全部进度。',
283
- '- 除非用户明确要求,不要自己执行员工的交付任务;你负责拆解、验收和决定下一步。',
284
284
  maxRounds > 0 ? `- 每个员工最多 ${maxRounds} 轮。` : '- 不限制轮次,直到你调用 collab_done 收尾。',
285
285
  ].join('\n')
286
286
  },
@@ -410,17 +410,17 @@ const LANGUAGES = {
410
410
  return [
411
411
  '## Collaboration pair · You are the project manager',
412
412
  ...(project ? [`Project: ${project}`] : []),
413
- `You coordinate ${count} worker conversations. You own the project goal, the task breakdown, and the acceptance criteria.`,
413
+ `You coordinate ${count} worker conversations. By default you create workers yourself and delegate the execution; you own the project goal, breakdown and acceptance criteria.`,
414
414
  'Workers:',
415
415
  ...rows,
416
416
  '',
417
417
  'Rules:',
418
+ '- Create workers by default: when work needs doing, use `collab_worker_create` to make the right worker(s) (multiple roles if needed), then dispatch. Do not wait for the user to create them manually.',
419
+ '- Do not do the workers\' execution work yourself. You break down, dispatch, review and decide; your own hands-on work should be limited to planning, review and necessary coordination, so a long execution does not make you miss worker reports.',
418
420
  '- Dispatch a round with `collab_dispatch`; when several workers exist, select one with `worker` (session id or title). With a single worker you may omit it.',
419
- '- To start a new worker conversation use `collab_worker_create` (name, preset/model, linked automatically).',
420
421
  '- Stage queue: manage it with `collab_stage`; when the current stage passes acceptance, call `collab_stage({action:"complete"})` to dispatch the next stage automatically.',
422
+ '- When a [Collaboration report] arrives, review it quickly and dispatch again; keep your own context light and let workers summarise details in their reports.',
421
423
  '- To change a worker\'s agent preset or model, use `collab_configure` (select the worker with `worker`).',
422
- '- When a message starting with [Collaboration report] arrives, dispatch the next round or call `collab_done` for that worker; `collab_status` shows every worker.',
423
- '- Unless the user explicitly asks, do not do the workers\' delivery work yourself; you break down, review, and decide.',
424
424
  maxRounds > 0 ? `- At most ${maxRounds} rounds per worker.` : '- Rounds are unlimited; continue until you call collab_done.',
425
425
  ].join('\n')
426
426
  },
@@ -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 <名字> | 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,95 @@ 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
+ }
3129
+ if (action === 'manage') {
3130
+ const agent = invocation.agent
3131
+ if (agent === undefined) return { kind: 'error', text: '无法确定当前对话。' }
3132
+ if (workerAssociation(agent.id) !== undefined) return { kind: 'error', text: '当前对话是员工,不能设为项目经理。' }
3133
+ let worker = null
3134
+ if (usableManagerLinks(agent.id).length === 0) {
3135
+ try {
3136
+ const created = await toolExecutors.create.execute(
3137
+ { name: typeof args?.name === 'string' ? args.name : '', mode: 'temporary' },
3138
+ { agent, signal: invocation.signal },
3139
+ )
3140
+ worker = created.sessionId
3141
+ } catch (error) {
3142
+ return { kind: 'error', text: error instanceof Error ? error.message : String(error) }
3143
+ }
3144
+ }
3145
+ const text = cfg.language === 'en'
3146
+ ? [
3147
+ '[Project manager mode]',
3148
+ 'You have been set as the project manager. By default you create workers yourself and delegate the execution.',
3149
+ '',
3150
+ '- When work needs doing, use `collab_worker_create` to make the right worker(s) (multiple roles if needed), then `collab_dispatch`.',
3151
+ '- Do not do the workers\' execution work yourself; keep your context for reviewing reports and dispatching again, so a long execution does not make you miss worker reports.',
3152
+ '- Confirm the project goal first; if the user has not given one, ask before creating workers and dispatching the first stage.',
3153
+ ].join('\n')
3154
+ : [
3155
+ '【项目经理模式】',
3156
+ '你已被设为项目经理。默认由你自主创建员工,并把执行工作派给员工。',
3157
+ '',
3158
+ '- 需要执行时,先用 `collab_worker_create` 创建合适的员工(可以按角色建多个),再用 `collab_dispatch` 派发。',
3159
+ '- 不要自己承担员工的具体执行工作;把上下文留给验收和继续派发,避免因长时间自己干活而错过员工回报。',
3160
+ '- 先确认项目目标;如果用户还没给目标,先问清楚,再创建员工并派发第一阶段。',
3161
+ ].join('\n')
3162
+ try {
3163
+ await deliver(agent.id, text, `cp-manage-${randomUUID().slice(0, 8)}`, 'queue', AbortSignal.timeout(PROMPT_TIMEOUT_MS))
3164
+ } catch (error) {
3165
+ return { kind: 'error', text: `项目经理已设置,但启动提示投递失败:${deliveryFailure(error)}` }
3166
+ }
3167
+ return { kind: 'success', text: JSON.stringify({ ok: true, worker, prompted: true }) }
3168
+ }
2919
3169
  if (action === 'relay') {
2920
3170
  const sub = typeof args?.action === 'string' ? args.action : 'get'
2921
3171
  if (sub === 'get') return { kind: 'success', text: JSON.stringify(relayStatus()) }
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
- "title": "Collaboration pair",
4
- "description": "For large projects: link several worker conversations to one manager, dispatch each round once instead of repeating prompts, relay results automatically, and keep unattended runs moving."
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
- "title": "双对话协作",
4
- "description": "做大项目时把多个员工对话关联到一个项目经理:每轮提示词只由经理发一次,产出自动回传,支持长时间挂机推进。"
3
+ "title": "协作待办",
4
+ "description": "把对话组织成协作网络:项目经理自主创建员工、派发任务并验收回报;也可给任意对话预设提示词待办,完成一轮自动发下一条。核心是协作,待办队列用来串起长流程。"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-collab-pair",
3
- "version": "1.4.2",
4
- "description": "For large projects: link a project-manager conversation with local or remote workers across devices (temporary or permanent), dispatch each round from the manager, relay results automatically, pre-write a stage queue that advances when a stage completes, and manage it all from a visual Settings page and a conversation context menu. Includes a relay hub and a free ntfy.sh transport for cross-device runs.",
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",