dsh-collab-pair 1.4.3 → 1.5.1

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,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
 
@@ -59,6 +60,7 @@ The page only links, unlinks, and reports status. Goals, tasks, and acceptance s
59
60
 
60
61
  - The settings page follows the app language; English and Chinese ship in the package.
61
62
  - Generated collaboration messages follow the `language` config (`zh` or `en`, default `zh`). Switch it in the page header (**Message language**) or with `/collab language en`. The command persists the config and reloads the plugin.
63
+ - Built-in title prefixes follow `language`: `【项目经理】`/`【员工】` for zh, `[Manager]`/`[Worker]` for en. Custom `prefixManager`/`prefixWorker` values override the defaults; switching language re-prefixes linked titles on reload.
62
64
 
63
65
  ## Unattended runs
64
66
 
@@ -119,6 +121,15 @@ A human can pre-write several large stages for one worker; finishing one dispatc
119
121
  - A stage is a normal round: the worker reports as usual, and `complete` waits until no round is pending.
120
122
  - The queue is stored on the worker link; `remove` deletes a pending stage, `clear` removes all pending stages.
121
123
 
124
+ ## Conversation to-do queue
125
+
126
+ Any conversation, not only a manager, can have its own prompt queue:
127
+
128
+ - Add items in the **Conversation to-do** card, or `/collab queue {"action":"add","title":"…","prompt":"…"}`.
129
+ - `start` sends the first pending prompt as a normal user message; when that turn ends, the next pending prompt is sent automatically.
130
+ - `pause` stops auto-advance after the current turn, `resume` re-enables it, and `clear` removes pending items.
131
+ - The queue is stored per conversation and survives plugin reloads.
132
+
122
133
  ## Projects
123
134
 
124
135
  A project is the set of workers managed by one project-manager conversation. Different managers are different projects, so nothing mixes:
@@ -193,6 +204,7 @@ The settings page uses it; it can also be typed manually:
193
204
  /collab create {"name":"前端","preset":"standard"}
194
205
  /collab remote {"action":"link","device":"laptop","worker":"frontend"}
195
206
  /collab stage {"action":"add","title":"阶段一","prompt":"…"}
207
+ /collab queue {"action":"add","title":"第一步","prompt":"…"}
196
208
  /collab relay {"action":"set","mode":"ntfy","hubRoom":"my-project","hubToken":"…"}
197
209
  /collab configure {"worker":"session-…","preset":"ptc"}
198
210
  /collab configure {"worker":"session-…","provider":"deepseek-account","model":"deepseek-flash"}
@@ -252,7 +264,7 @@ One record per worker lives in `$DSH_HOME/storages/collab_pair.json` (storage-do
252
264
 
253
265
  # 中文说明
254
266
 
255
- > DSH 插件:一个项目经理对话管理多个员工对话,任务自动流转,并提供全部任务看板。
267
+ > 用于大项目的 DSH 协作插件:把项目经理对话与本机/远端员工关联,自动派发、回传并推进阶段;也可以给任意对话预设一串提示词待办,完成一轮自动发下一条。
256
268
 
257
269
  [**GitHub**](https://github.com/awa1231/dsh-collab-pair) · [给个 Star ★](https://github.com/awa1231/dsh-collab-pair)
258
270
 
@@ -280,7 +292,7 @@ dsh plugin add dsh-collab-pair
280
292
 
281
293
  ## 可视化设置页
282
294
 
283
- **设置 → 双对话协作**,从上到下:
295
+ **设置 → 协作待办**,从上到下:
284
296
 
285
297
  1. **工作会话**:选择要操作的对话(默认当前打开的对话)。
286
298
  2. **当前会话 · <标题>**:先看**这个对话自己的**关联与状态。
@@ -289,7 +301,8 @@ dsh plugin add dsh-collab-pair
289
301
  - 无关联:直接显示关联表单。
290
302
  3. **全部任务**:所有协作的任务看板,不限当前会话。每行显示员工、所属项目经理、第几轮、**工作状态**(`工作中` / `等待回报` / `空闲` / `已结束`)、等待时长、本轮任务、最近回报。点「刷新」重新读取。
291
303
  4. **跨设备协作**:中继模式(关闭 / 自建 hub / 免费 ntfy.sh)、URL、房间、令牌、设备名;保存/测试、连接状态、员工别名注册、远端员工关联。
292
- 5. **阶段队列**(仅项目经理):选员工,填标题/提示词/验收标准;可开始、完成并自动派发下一阶段、删除待开始阶段。
304
+ 5. **阶段待办**(仅项目经理):选员工,填标题/提示词/验收标准;可开始、完成并自动派发下一阶段、删除待开始阶段。
305
+ 6. **对话待办**(其他任意对话):预先写一串提示词;点开始发第一条,当前回合结束后自动发下一条。可暂停、恢复、清空待发。
293
306
 
294
307
  在侧栏右键一个对话,选「设为项目经理并启动」:插件会新建并关联一个起始员工,然后给该对话发一条「项目经理模式」指令,让它自己创建更多员工并把执行工作派出去。
295
308
 
@@ -307,6 +320,7 @@ dsh plugin add dsh-collab-pair
307
320
 
308
321
  - 设置页跟随应用语言,包内自带中文和英文。
309
322
  - 对话里生成的消息由配置 `language` 决定(`zh` / `en`,默认 `zh`)。可在页面顶部「对话消息语言」切换,或用 `/collab language en`;命令会保存配置并重载插件。
323
+ - 内置标题前缀跟随 `language`:中文 `【项目经理】`/`【员工】`,英文 `[Manager]`/`[Worker]`。自定义 `prefixManager`/`prefixWorker` 会覆盖默认;切换语言后重载会自动把已关联对话改成对应前缀。
310
324
 
311
325
  ## 挂机运行
312
326
 
@@ -367,6 +381,15 @@ collab_dispatch({ worker: "前端", task: "…" })
367
381
  - 阶段本质就是普通的一轮:员工照常回报;仍有轮次在等待回报时,`complete` 会拒绝。
368
382
  - 队列保存在员工关联上;`remove` 删除待开始阶段,`clear` 清空所有待开始阶段。
369
383
 
384
+ ## 对话待办队列
385
+
386
+ 任意对话(不只是项目经理)都可以有自己的提示词队列:
387
+
388
+ - 在「对话待办」卡片里添加,或 `/collab queue {"action":"add","title":"…","prompt":"…"}`。
389
+ - `start` 把第一条待发提示词作为普通用户消息发进去;该回合结束后,自动发送下一条。
390
+ - `pause` 在当前回合后停止自动连发,`resume` 恢复,`clear` 清空待发。
391
+ - 队列按对话保存,插件重载后仍在。
392
+
370
393
  ## 项目
371
394
 
372
395
  一个项目就是「一个项目经理对话所管理的员工集合」。不同项目经理就是不同项目,互不混淆:
@@ -437,6 +460,7 @@ collab_dispatch({ worker: "前端", task: "…" })
437
460
  /collab create {"name":"前端","preset":"standard"}
438
461
  /collab remote {"action":"link","device":"laptop","worker":"frontend"}
439
462
  /collab stage {"action":"add","title":"阶段一","prompt":"…"}
463
+ /collab queue {"action":"add","title":"第一步","prompt":"…"}
440
464
  /collab relay {"action":"set","mode":"ntfy","hubRoom":"my-project","hubToken":"…"}
441
465
  /collab configure {"worker":"session-…","preset":"ptc"}
442
466
  /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: '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.',
@@ -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,11 @@ 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.3'
44
+ const ENGINE = 'collab-pair/1.5.1'
45
+ const PREFIX_DEFAULTS = {
46
+ zh: { manager: '【项目经理】', worker: '【员工】' },
47
+ en: { manager: '[Manager]', worker: '[Worker]' },
48
+ }
45
49
 
46
50
  /** A recoverable failure whose message is meant for the model. */
47
51
  class CollabError extends Error {}
@@ -61,9 +65,9 @@ function resolveConfig(raw) {
61
65
  notifyWorkerOnDone: value.notifyWorkerOnDone !== false,
62
66
  autoRelay: value.autoRelay !== false,
63
67
  addPrefix: value.addPrefix !== false,
64
- prefixManager: prefixText(value.prefixManager, '【项目经理】'),
65
- prefixWorker: prefixText(value.prefixWorker, '【员工】'),
66
68
  language: value.language === 'en' ? 'en' : 'zh',
69
+ prefixManager: prefixFor(value.prefixManager, 'manager', value.language === 'en' ? 'en' : 'zh'),
70
+ prefixWorker: prefixFor(value.prefixWorker, 'worker', value.language === 'en' ? 'en' : 'zh'),
67
71
  autoNudge: value.autoNudge !== false,
68
72
  nudgeAfterMinutes: clampInt(value.nudgeAfterMinutes, 5, 1440, 20),
69
73
  maxNudges: clampInt(value.maxNudges, 1, 20, 3),
@@ -114,6 +118,15 @@ function prefixText(candidate, fallback) {
114
118
  return value.length > 24 ? value.slice(0, 24) : value
115
119
  }
116
120
 
121
+ /** Built-in prefixes follow the message language; custom values stay custom. */
122
+ function prefixFor(candidate, role, language) {
123
+ const value = typeof candidate === 'string' ? candidate.trim() : ''
124
+ const fallback = PREFIX_DEFAULTS[language][role]
125
+ if (value === '') return fallback
126
+ const builtIn = Object.values(PREFIX_DEFAULTS).some((set) => set[role] === value)
127
+ return builtIn ? fallback : prefixText(value, fallback)
128
+ }
129
+
117
130
  /** Rounds per worker: 0 (the default) means unlimited. */
118
131
  function normalizeRounds(candidate) {
119
132
  const number = typeof candidate === 'number' ? candidate : Number(candidate)
@@ -527,6 +540,7 @@ export function apply(ctx, rawConfig) {
527
540
  let storageError = null
528
541
  const remoteAliases = new Map()
529
542
  const remoteInbound = new Map()
543
+ const queues = new Map()
530
544
  let remoteState = 'pending'
531
545
  let remoteCursor = 0
532
546
  let remoteLastError = null
@@ -575,6 +589,7 @@ export function apply(ctx, rawConfig) {
575
589
  if (cfg.autoNudge) watchdogTimer = setInterval(() => { void runWatchdog() }, 60000)
576
590
  setTimeout(() => { void recoverPendingLinks() }, 5000)
577
591
  setTimeout(() => { void backfillProjects() }, 3000)
592
+ setTimeout(() => { void relocalizePrefixes() }, 4000)
578
593
  setTimeout(() => { if (alive) void remoteLoop() }, 2000)
579
594
 
580
595
  registerTools()
@@ -789,6 +804,165 @@ export function apply(ctx, rawConfig) {
789
804
  }
790
805
  }
791
806
 
807
+ // ------------------------------------------------------------ session to-do
808
+
809
+ function normalizeQueue(value, sessionId) {
810
+ const items = []
811
+ for (const item of Array.isArray(value?.items) ? value.items.slice(0, 100) : []) {
812
+ if (item === null || typeof item !== 'object') continue
813
+ const prompt = typeof item.prompt === 'string' ? item.prompt.trim() : ''
814
+ if (prompt === '') continue
815
+ const status = item.status === 'sent' || item.status === 'done' ? item.status : 'pending'
816
+ items.push({
817
+ id: typeof item.id === 'string' ? item.id : `q-${randomUUID().slice(0, 8)}`,
818
+ title: typeof item.title === 'string' ? item.title : '',
819
+ prompt,
820
+ status,
821
+ ...(typeof item.sentAt === 'number' ? { sentAt: item.sentAt } : {}),
822
+ ...(typeof item.completedAt === 'number' ? { completedAt: item.completedAt } : {}),
823
+ ...(typeof item.requestId === 'string' ? { requestId: item.requestId } : {}),
824
+ ...(typeof item.marker === 'string' ? { marker: item.marker } : {}),
825
+ })
826
+ }
827
+ let activeId = typeof value?.activeId === 'string' ? value.activeId : null
828
+ if (activeId !== null && !items.some((item) => item.id === activeId && item.status === 'sent')) activeId = null
829
+ if (activeId === null) {
830
+ const sent = items.find((item) => item.status === 'sent')
831
+ if (sent !== undefined) activeId = sent.id
832
+ }
833
+ return {
834
+ sessionId,
835
+ items,
836
+ activeId,
837
+ auto: value?.auto !== false,
838
+ updatedAt: Number.isFinite(value?.updatedAt) ? value.updatedAt : Date.now(),
839
+ }
840
+ }
841
+
842
+ async function readQueue(sessionId) {
843
+ const cached = queues.get(sessionId)
844
+ if (cached !== undefined) return cached
845
+ let stored
846
+ const domain = await remoteReady.catch(() => undefined)
847
+ if (domain !== undefined) {
848
+ try {
849
+ stored = [...domain.table('state').entries()].find(([key]) => key === `queue:${sessionId}`)?.[1]
850
+ } catch (error) {
851
+ ctx.logger.warn(`collab-pair: reading the queue for ${sessionId} failed: ${String(error)}`)
852
+ }
853
+ }
854
+ const queue = normalizeQueue(stored, sessionId)
855
+ queues.set(sessionId, queue)
856
+ return queue
857
+ }
858
+
859
+ async function persistQueue(queue) {
860
+ queues.set(queue.sessionId, queue)
861
+ const domain = await remoteReady.catch(() => undefined)
862
+ if (domain === undefined) return
863
+ try {
864
+ await domain.table('state').put(`queue:${queue.sessionId}`, JSON.parse(JSON.stringify(queue)))
865
+ } catch (error) {
866
+ ctx.logger.warn(`collab-pair: persisting the queue for ${queue.sessionId} failed: ${String(error)}`)
867
+ }
868
+ }
869
+
870
+ function queueView(queue) {
871
+ return {
872
+ sessionId: queue.sessionId,
873
+ auto: queue.auto,
874
+ active: queue.activeId,
875
+ items: queue.items.map((item) => ({
876
+ id: item.id,
877
+ title: item.title,
878
+ prompt: clip(item.prompt, 400),
879
+ status: item.status,
880
+ ...(item.sentAt === undefined ? {} : { sentAt: isoTime(item.sentAt) }),
881
+ ...(item.completedAt === undefined ? {} : { completedAt: isoTime(item.completedAt) }),
882
+ })),
883
+ }
884
+ }
885
+
886
+ /** Send the first pending prompt as a normal user turn. */
887
+ async function startQueueItem(sessionId, signal) {
888
+ const queue = await readQueue(sessionId)
889
+ if (queue.activeId !== null) throw new CollabError('当前待办仍在等待完成;先等这一轮结束,或暂停队列。')
890
+ const next = queue.items.find((item) => item.status === 'pending')
891
+ if (next === undefined) throw new CollabError('队列里没有待发送的提示词。')
892
+ const index = queue.items.indexOf(next) + 1
893
+ const requestId = `cp-queue-${sessionId}-${next.id}`
894
+ const marker = `[[collab-queue:${next.id}]]`
895
+ next.status = 'sent'
896
+ next.sentAt = Date.now()
897
+ next.requestId = requestId
898
+ next.marker = marker
899
+ queue.activeId = next.id
900
+ queue.updatedAt = Date.now()
901
+ await persistQueue(queue)
902
+ const text = [
903
+ `【对话待办 ${index}/${queue.items.length}】`,
904
+ ...(next.title === '' ? [] : [next.title]),
905
+ '',
906
+ next.prompt,
907
+ '',
908
+ '完成本轮后直接给出结果;若队列还有下一条,会在本轮结束后自动发送。',
909
+ marker,
910
+ ].join('\n')
911
+ try {
912
+ await deliver(sessionId, text, requestId, 'queue', signal ?? AbortSignal.timeout(PROMPT_TIMEOUT_MS))
913
+ } catch (error) {
914
+ next.status = 'pending'
915
+ delete next.sentAt
916
+ delete next.requestId
917
+ delete next.marker
918
+ queue.activeId = null
919
+ queue.updatedAt = Date.now()
920
+ await persistQueue(queue)
921
+ throw error
922
+ }
923
+ return { queue, item: next }
924
+ }
925
+
926
+ /** Finish the active queue turn and send the next prompt when auto is on. */
927
+ async function advanceQueue(session, event) {
928
+ const queue = await readQueue(session.id)
929
+ if (queue.activeId === null) return
930
+ const active = queue.items.find((item) => item.id === queue.activeId && item.status === 'sent')
931
+ if (active === undefined) return
932
+ const turn = event.data?.turn
933
+ if (!Number.isSafeInteger(turn)) return
934
+ let events
935
+ try {
936
+ events = turnEvents(session, turn, event.seq)
937
+ } catch (error) {
938
+ ctx.logger.warn(`collab-pair: reading a queue turn failed: ${String(error)}`)
939
+ return
940
+ }
941
+ if (events === undefined || !claimedQueue(events, active)) return
942
+ active.status = 'done'
943
+ active.completedAt = Date.now()
944
+ queue.activeId = null
945
+ queue.updatedAt = Date.now()
946
+ await persistQueue(queue)
947
+ if (!queue.auto) return
948
+ if (queue.items.some((item) => item.status === 'pending')) {
949
+ try {
950
+ await startQueueItem(session.id, AbortSignal.timeout(PROMPT_TIMEOUT_MS))
951
+ } catch (error) {
952
+ ctx.logger.warn(`collab-pair: sending the next queue item for ${session.id} failed: ${String(error)}`)
953
+ }
954
+ }
955
+ }
956
+
957
+ function claimedQueue(events, item) {
958
+ for (const event of events) {
959
+ if (event.type !== 'user/message') continue
960
+ if (typeof item.requestId === 'string' && event.data?.source?.rpcId === item.requestId) return true
961
+ if (typeof item.marker === 'string' && messageText(event.data).includes(item.marker)) return true
962
+ }
963
+ return false
964
+ }
965
+
792
966
  function hubConfigured() {
793
967
  return cfg.relayMode === 'hub' && cfg.hubUrl !== '' && cfg.hubToken !== ''
794
968
  }
@@ -1475,7 +1649,12 @@ export function apply(ctx, rawConfig) {
1475
1649
 
1476
1650
  /** Remove one of our role prefixes from a title. */
1477
1651
  function stripKnownPrefix(title) {
1478
- for (const prefix of new Set([cfg.prefixManager, cfg.prefixWorker])) {
1652
+ const known = new Set([
1653
+ cfg.prefixManager,
1654
+ cfg.prefixWorker,
1655
+ ...Object.values(PREFIX_DEFAULTS).flatMap((set) => [set.manager, set.worker]),
1656
+ ])
1657
+ for (const prefix of known) {
1479
1658
  if (prefix !== '' && title.startsWith(prefix)) return title.slice(prefix.length).trimStart()
1480
1659
  }
1481
1660
  return title
@@ -1817,6 +1996,20 @@ export function apply(ctx, rawConfig) {
1817
1996
  }
1818
1997
  }
1819
1998
 
1999
+ /** Re-apply role prefixes in the current language after a language switch. */
2000
+ async function relocalizePrefixes() {
2001
+ if (!alive || !cfg.addPrefix) return
2002
+ for (const link of [...links.values()]) {
2003
+ if (!alive) return
2004
+ try {
2005
+ await applyPrefix(link.manager, cfg.prefixManager)
2006
+ if (link.remote === undefined) await applyPrefix(link.worker, cfg.prefixWorker)
2007
+ } catch (error) {
2008
+ ctx.logger.warn(`collab-pair: re-prefixing ${link.id} failed: ${String(error)}`)
2009
+ }
2010
+ }
2011
+ }
2012
+
1820
2013
  /** Serialize relays per link so one turn cannot relay twice. */
1821
2014
  function enqueueRelay(linkId, run) { const previous = relays.get(linkId) ?? Promise.resolve()
1822
2015
  const next = previous.then(run, run).catch((error) => {
@@ -1887,6 +2080,7 @@ export function apply(ctx, rawConfig) {
1887
2080
  /** Global post-commit listener: relay a worker turn that answered a dispatch. */
1888
2081
  function onSessionEvent(session, event) {
1889
2082
  if (event?.type !== 'turn/end') return
2083
+ void advanceQueue(session, event).catch((error) => ctx.logger.warn(`collab-pair: advancing a queue failed: ${String(error)}`))
1890
2084
  const inbound = remoteInbound.get(session.id)
1891
2085
  if (inbound !== undefined) {
1892
2086
  void handleRemoteTurnEnd(session, event, inbound)
@@ -2908,7 +3102,7 @@ export function apply(ctx, rawConfig) {
2908
3102
  name: 'collab',
2909
3103
  description: '双对话协作:查看全部任务、关联员工、阶段队列、跨设备中继、设置项目名、配置预设与语言、派发任务、收尾或解除。',
2910
3104
  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 ...',
3105
+ 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
3106
  },
2913
3107
  handler: async (invocation) => {
2914
3108
  try {
@@ -2916,6 +3110,55 @@ export function apply(ctx, rawConfig) {
2916
3110
  if (action === 'tasks' || action === 'board') {
2917
3111
  return { kind: 'success', text: JSON.stringify(await tasksBoard()) }
2918
3112
  }
3113
+ if (action === 'queue') {
3114
+ const agent = invocation.agent
3115
+ if (agent === undefined) return { kind: 'error', text: '无法确定当前对话。' }
3116
+ const sub = typeof args?.action === 'string' ? args.action : 'list'
3117
+ const queue = await readQueue(agent.id)
3118
+ if (sub === 'list' || sub === 'status') {
3119
+ return { kind: 'success', text: JSON.stringify(queueView(queue)) }
3120
+ }
3121
+ if (sub === 'add') {
3122
+ const prompt = typeof args?.prompt === 'string' ? args.prompt.trim() : ''
3123
+ if (prompt === '') return { kind: 'error', text: 'prompt 不能为空。' }
3124
+ queue.items.push({
3125
+ id: `q-${randomUUID().slice(0, 8)}`,
3126
+ title: typeof args?.title === 'string' ? args.title.trim() : '',
3127
+ prompt,
3128
+ status: 'pending',
3129
+ })
3130
+ queue.updatedAt = Date.now()
3131
+ await persistQueue(queue)
3132
+ return { kind: 'success', text: JSON.stringify(queueView(queue)) }
3133
+ }
3134
+ if (sub === 'start') {
3135
+ const { queue: started, item } = await startQueueItem(agent.id, invocation.signal)
3136
+ return { kind: 'success', text: JSON.stringify({ ...queueView(started), started: item.id }) }
3137
+ }
3138
+ if (sub === 'pause' || sub === 'resume') {
3139
+ queue.auto = sub === 'resume'
3140
+ queue.updatedAt = Date.now()
3141
+ await persistQueue(queue)
3142
+ return { kind: 'success', text: JSON.stringify(queueView(queue)) }
3143
+ }
3144
+ if (sub === 'remove') {
3145
+ const index = clampInt(args?.index, 1, 100, 0)
3146
+ const item = index > 0 ? queue.items[index - 1] : undefined
3147
+ if (item === undefined) return { kind: 'error', text: 'index 超出范围。' }
3148
+ if (item.status !== 'pending') return { kind: 'error', text: '只能删除尚未发送的条目。' }
3149
+ queue.items.splice(index - 1, 1)
3150
+ queue.updatedAt = Date.now()
3151
+ await persistQueue(queue)
3152
+ return { kind: 'success', text: JSON.stringify(queueView(queue)) }
3153
+ }
3154
+ if (sub === 'clear') {
3155
+ queue.items = queue.items.filter((item) => item.status !== 'pending')
3156
+ queue.updatedAt = Date.now()
3157
+ await persistQueue(queue)
3158
+ return { kind: 'success', text: JSON.stringify(queueView(queue)) }
3159
+ }
3160
+ return { kind: 'error', text: 'action 必须是 list | add | start | pause | resume | remove | clear。' }
3161
+ }
2919
3162
  if (action === 'manage') {
2920
3163
  const agent = invocation.agent
2921
3164
  if (agent === undefined) return { kind: 'error', text: '无法确定当前对话。' }
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.3",
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.1",
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",