dsh-collab-pair 1.5.2 → 1.5.4

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.
Files changed (4) hide show
  1. package/README.md +8 -2
  2. package/client.js +236 -60
  3. package/index.js +124 -11
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -52,6 +52,8 @@ Once a conversation is a manager, its prompt tells it to:
52
52
 
53
53
  The manager card also shows the **project name** and lets you rename it.
54
54
 
55
+ The page now opens with a compact **three-step guide** and an expandable **Show details** section; the cross-device and all-tasks cards start collapsed and expand on demand, so the common path (pick a conversation → link / to-do → review) stays one glance away.
56
+
55
57
  The header also has a **Message language** selector (中文 / English). It switches the generated collaboration messages; the page labels follow the app language.
56
58
 
57
59
  The page only links, unlinks, and reports status. Goals, tasks, and acceptance stay in the manager conversation.
@@ -136,7 +138,8 @@ Any conversation, not only a manager, can have its own prompt queue:
136
138
 
137
139
  - Add items in the **Conversation to-do** card, or `/collab queue {"action":"add","title":"…","prompt":"…"}`.
138
140
  - `start` sends the first pending prompt as a normal user message; when that turn ends, the next pending prompt is sent automatically.
139
- - `pause` stops auto-advance after the current turn, `resume` re-enables it, and `clear` removes pending items.
141
+ - `pause` stops auto-advance after the current turn, `resume` re-enables it and sends the next pending prompt when the queue is idle, and `clear` removes pending items.
142
+ - If a turn ends with an error/abort, that item is marked **failed** and auto-advance pauses; press **Reset queue** to return a stuck `sent` item to pending and retry.
140
143
  - The queue is stored per conversation and survives plugin reloads.
141
144
 
142
145
  ## Projects
@@ -325,6 +328,8 @@ dsh plugin add dsh-collab-pair
325
328
 
326
329
  页面只做关联/解除和查看,不代填目标、任务、验收——这些交给项目经理对话。
327
330
 
331
+ 页面顶部新增**三步上手**和可展开的**详细说明**;「跨设备协作」与「全部任务」默认收起,点「展开」再看,日常路径(选对话 → 关联/待办 → 验收)一眼可见。
332
+
328
333
  ## 中英文
329
334
 
330
335
  - 设置页跟随应用语言,包内自带中文和英文。
@@ -405,7 +410,8 @@ collab_dispatch({ worker: "前端", task: "…" })
405
410
 
406
411
  - 在「对话待办」卡片里添加,或 `/collab queue {"action":"add","title":"…","prompt":"…"}`。
407
412
  - `start` 把第一条待发提示词作为普通用户消息发进去;该回合结束后,自动发送下一条。
408
- - `pause` 在当前回合后停止自动连发,`resume` 恢复,`clear` 清空待发。
413
+ - `pause` 在当前回合后停止自动连发,`resume` 恢复并在队列空闲时发送下一条,`clear` 清空待发。
414
+ - 如果某轮以错误/中止结束,该条会标记为 **失败** 并暂停自动连发;点「重置队列」可把卡在 `sent` 的条目退回待发并重试。
409
415
  - 队列按对话保存,插件重载后仍在。
410
416
 
411
417
  ## 项目
package/client.js CHANGED
@@ -10,6 +10,44 @@ window.__ModuleLoader__.load({
10
10
  nav: '协作待办',
11
11
  title: '协作待办',
12
12
  intro: '把对话组织成协作网络:项目经理自主创建员工、派发任务并验收回报;也可以给任意对话预设一串提示词,完成一轮自动发下一条。核心是协作,待办队列用来把长流程串起来。',
13
+ guideTitle: '三步上手',
14
+ guideStep1: '选择要操作的对话(默认当前打开的对话)。',
15
+ guideStep2: '要协作:在「当前会话」关联员工,或右键对话选「设为项目经理并启动」,让经理自己建员工、派任务、验收。',
16
+ guideStep3: '要串任务:在下方「对话待办」写好提示词,点「发送下一条」,每轮结束自动发下一条。',
17
+ guideMore: '查看详细说明',
18
+ guideLess: '收起详细说明',
19
+ guideDetail: [
20
+ '① 关联员工',
21
+ '• 在「当前会话」选择员工对话后点「关联」;只有一个员工时 worker 可省略。',
22
+ '• 想新建:填名字后点「新建员工」。',
23
+ '• 右键侧栏对话 →「设为项目经理并启动」:自动建一个起始员工,并让该对话自己继续建员工。',
24
+ '',
25
+ '② 项目经理怎么用',
26
+ '• 在经理对话里说清目标;经理会用 collab_worker_create 建人、collab_dispatch 派任务。',
27
+ '• 员工每轮结束会自动回传【协作回报】;验收后继续派发,或 collab_done 收尾。',
28
+ '• 不要让经理自己埋头干活,上下文留给验收和继续派发。',
29
+ '',
30
+ '③ 对话待办(自动连发)',
31
+ '• 普通对话可用:写多条提示词,点「发送下一条」。',
32
+ '• 当前回合结束后自动发下一条;可暂停/恢复/清空。',
33
+ '• 失败/中止会标红并暂停;点「重置队列」把卡住的条目退回待发。',
34
+ '',
35
+ '④ 阶段待办(项目经理)',
36
+ '• 给某个员工预写多个大阶段;点「开始」,验收后「完成并发下一阶段」。',
37
+ '• 阶段是派给员工的;对话待办是发给当前对话自己的。',
38
+ '',
39
+ '⑤ 跨设备',
40
+ '• 自建 hub:hub 机器运行 node hub.js --port 8787 --token <密钥>;用局域网 IP 或 HTTPS 隧道;127.0.0.1 只在本机有效。',
41
+ '• 免费 ntfy:两台设备填同一个 room + 长 token,免部署;消息经公共服务器。',
42
+ '• 员工设备注册别名;经理设备填设备名+别名关联;点「测试连接」。',
43
+ '• 远程员工文件不共享:用共同 git remote/网络盘,或让员工回报 patch。',
44
+ '',
45
+ '⑥ 语言与前缀',
46
+ '• 页面顶部切换消息语言;中文前缀【项目经理】/【员工】,英文 [Manager]/[Worker]。',
47
+ ].join('\n'),
48
+ summaryExpand: '展开',
49
+ summaryCollapse: '收起',
50
+ summaryRelayHint: '自建 hub 或免费 ntfy.sh;两台设备同 room/token。',
13
51
  workSession: '工作会话',
14
52
  workSessionHint: '选择要操作的对话。建立关联时,它就是项目经理对话。',
15
53
  messageLanguage: '对话消息语言',
@@ -144,6 +182,10 @@ window.__ModuleLoader__.load({
144
182
  queueUntitled: '未命名任务',
145
183
  queueAuto: '自动连发',
146
184
  queuePaused: '已暂停',
185
+ queueFailed: '失败',
186
+ queueReset: '重置队列',
187
+ queueLoadFailed: '读取队列失败',
188
+ queueLastError: '最近错误',
147
189
  stageAdded: '阶段已添加。',
148
190
  stageStarted: '阶段已开始。',
149
191
  stageFinished: '阶段已完成。',
@@ -164,6 +206,44 @@ window.__ModuleLoader__.load({
164
206
  nav: 'Collab To-do',
165
207
  title: 'Collab To-do',
166
208
  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.',
209
+ guideTitle: 'Three steps',
210
+ guideStep1: 'Pick the conversation to work on (the open one is selected by default).',
211
+ guideStep2: 'To collaborate: link a worker in **Current conversation**, or right-click a conversation and choose **Set as project manager (start)** so the manager creates workers, dispatches and reviews.',
212
+ guideStep3: 'To string tasks: add prompts to **Conversation to-do** below and click **Send next**; the next one is sent when a turn ends.',
213
+ guideMore: 'Show details',
214
+ guideLess: 'Hide details',
215
+ guideDetail: [
216
+ '① Link a worker',
217
+ '• In Current conversation, pick a worker conversation and click Link; with one worker you can omit worker.',
218
+ '• To create one: type a name and click New worker.',
219
+ '• Right-click a sidebar conversation → Set as project manager (start): creates a starter worker and lets that conversation create more itself.',
220
+ '',
221
+ '② How the manager works',
222
+ '• State the goal in the manager conversation; it uses collab_worker_create and collab_dispatch.',
223
+ '• A finished worker turn comes back as a [Collaboration report]; review it, dispatch again, or call collab_done.',
224
+ '• The manager should not do the workers’ execution; keep its context for review and dispatching.',
225
+ '',
226
+ '③ Conversation to-do',
227
+ '• For any ordinary conversation: add several prompts, then click Send next.',
228
+ '• The next prompt is sent when the current turn ends; pause, resume or clear pending items.',
229
+ '• Failed/aborted items turn red and pause auto-advance; Reset queue returns stuck items to pending.',
230
+ '',
231
+ '④ Stage queue (manager)',
232
+ '• Pre-write stages for one worker; Start, then Complete to dispatch the next stage.',
233
+ '• Stages go to workers; the conversation to-do goes to this conversation itself.',
234
+ '',
235
+ '⑤ Cross-device',
236
+ '• Self-hosted hub: run node hub.js --port 8787 --token <secret>; use a LAN IP or HTTPS tunnel; 127.0.0.1 is local only.',
237
+ '• Free ntfy: same room + long token on both devices; no deployment, public server.',
238
+ '• Worker device registers an alias; manager links device + alias; press Test connection.',
239
+ '• Remote workers do not share files: use a common git remote/network drive, or return patches.',
240
+ '',
241
+ '⑥ Language and prefixes',
242
+ '• Switch message language at the top; zh prefixes 【项目经理】/【员工】, en [Manager]/[Worker].',
243
+ ].join('\n'),
244
+ summaryExpand: 'Expand',
245
+ summaryCollapse: 'Collapse',
246
+ summaryRelayHint: 'Self-hosted hub or free ntfy.sh; both devices share room/token.',
167
247
  workSession: 'Working conversation',
168
248
  workSessionHint: 'The conversation to act on. When you create a link, it becomes the project manager.',
169
249
  messageLanguage: 'Message language',
@@ -298,6 +378,10 @@ window.__ModuleLoader__.load({
298
378
  queueUntitled: 'Untitled task',
299
379
  queueAuto: 'Auto-advance',
300
380
  queuePaused: 'Paused',
381
+ queueFailed: 'Failed',
382
+ queueReset: 'Reset queue',
383
+ queueLoadFailed: 'Failed to load the queue',
384
+ queueLastError: 'Last error',
301
385
  stageAdded: 'Stage added.',
302
386
  stageStarted: 'Stage started.',
303
387
  stageFinished: 'Stage finished.',
@@ -425,8 +509,15 @@ window.__ModuleLoader__.load({
425
509
  const [queueTitle, setQueueTitle] = React.useState('')
426
510
  const [queuePrompt, setQueuePrompt] = React.useState('')
427
511
  const [queueBusy, setQueueBusy] = React.useState(false)
512
+ const [showGuide, setShowGuide] = React.useState(false)
513
+ const [showRelay, setShowRelay] = React.useState(false)
514
+ const [showBoard, setShowBoard] = React.useState(false)
515
+ const [queueError, setQueueError] = React.useState(null)
428
516
  const commandsRef = React.useRef(commands)
429
517
  commandsRef.current = commands
518
+ const workIdRef = React.useRef(workId)
519
+ workIdRef.current = workId
520
+ const queueReadSeq = React.useRef(0)
430
521
 
431
522
  React.useEffect(() => {
432
523
  if (workId !== undefined) return
@@ -511,6 +602,7 @@ window.__ModuleLoader__.load({
511
602
  setError(null)
512
603
  try {
513
604
  await loadBoard(workId)
605
+ if (!queueBusy) await readQueue(workId)
514
606
  const relay = await readRelay(workId).catch(() => null)
515
607
  if (relay !== null && relay.mode !== 'off') await loadAliases(workId).catch(() => undefined)
516
608
  } catch (cause) {
@@ -584,32 +676,51 @@ window.__ModuleLoader__.load({
584
676
  return value
585
677
  }
586
678
 
587
- /** Run one command, show the dictionary text, then refresh the board. */
588
- const readQueue = async (sessionId) => {
679
+ /** Read one session's queue; stale session responses are discarded. */
680
+ const readQueue = async (sessionId, isCancelled) => {
681
+ const seq = ++queueReadSeq.current
682
+ const stale = () => (typeof isCancelled === 'function' && isCancelled())
683
+ || workIdRef.current !== sessionId || seq !== queueReadSeq.current
589
684
  try {
590
685
  const value = await runCommand(commandsRef.current, sessionId, '/collab queue {"action":"list"}')
591
- if (value !== null && typeof value === 'object' && Array.isArray(value.items)) setQueue(value)
686
+ if (value !== null && typeof value === 'object' && Array.isArray(value.items)
687
+ && value.sessionId === sessionId && !stale()) {
688
+ setQueue(value)
689
+ setQueueError(null)
690
+ }
592
691
  return value
593
- } catch {
594
- setQueue(null)
692
+ } catch (cause) {
693
+ if (!stale()) {
694
+ setQueue(null)
695
+ setQueueError(cause instanceof Error ? cause.message : String(cause))
696
+ }
595
697
  return null
596
698
  }
597
699
  }
598
700
 
599
701
  const queueAction = async (action, extra = {}) => {
600
702
  if (workId === undefined) return
703
+ const sessionId = workId
704
+ const seq = ++queueReadSeq.current
601
705
  setQueueBusy(true)
602
706
  setError(null)
603
707
  setNotice(null)
708
+ setQueueError(null)
604
709
  try {
605
- const value = await runCommand(commandsRef.current, workId, `/collab queue ${JSON.stringify({ action, ...extra })}`)
606
- if (value !== null && typeof value === 'object' && Array.isArray(value.items)) setQueue(value)
607
- if (action === 'add') {
710
+ const value = await runCommand(commandsRef.current, sessionId, `/collab queue ${JSON.stringify({ action, ...extra })}`)
711
+ const current = workIdRef.current === sessionId && seq === queueReadSeq.current
712
+ if (current && value !== null && typeof value === 'object' && Array.isArray(value.items) && value.sessionId === sessionId) {
713
+ setQueue(value)
714
+ setQueueError(null)
715
+ }
716
+ if (action === 'add' && current) {
608
717
  setQueueTitle('')
609
718
  setQueuePrompt('')
610
719
  }
611
720
  } catch (cause) {
612
- setError(cause instanceof Error ? cause.message : String(cause))
721
+ if (workIdRef.current === sessionId && seq === queueReadSeq.current) {
722
+ setError(cause instanceof Error ? cause.message : String(cause))
723
+ }
613
724
  } finally {
614
725
  setQueueBusy(false)
615
726
  }
@@ -618,9 +729,16 @@ window.__ModuleLoader__.load({
618
729
  React.useEffect(() => {
619
730
  if (workId === undefined) {
620
731
  setQueue(null)
621
- return
732
+ setQueueError(null)
733
+ return undefined
734
+ }
735
+ let cancelled = false
736
+ setQueue(null)
737
+ setQueueError(null)
738
+ void readQueue(workId, () => cancelled)
739
+ return () => {
740
+ cancelled = true
622
741
  }
623
- void readQueue(workId)
624
742
  }, [workId])
625
743
 
626
744
  const runAction = async (line, successText) => {
@@ -840,35 +958,46 @@ window.__ModuleLoader__.load({
840
958
  return wait === '' ? base : `${base} · ${t('waited', { time: wait })}`
841
959
  }
842
960
 
961
+ const starLink = h('a', {
962
+ href: 'https://github.com/awa1231/dsh-collab-pair',
963
+ target: '_blank',
964
+ rel: 'noreferrer noopener',
965
+ style: S.starLink,
966
+ }, t('starLabel'))
843
967
  const header = h('div', { style: S.page },
844
- h('h2', { style: S.title }, t('title')),
845
- h('p', { style: S.intro }, t('intro')),
846
- h('div', { style: S.card },
847
- h('label', { style: S.label }, t('workSession'),
848
- h('select', {
849
- style: S.input,
850
- value: workId ?? '',
851
- disabled: busy || sessions.length === 0,
852
- onChange: (event) => setWorkId(event.target.value),
853
- },
854
- sessions.length === 0
855
- ? h('option', { value: '' }, t('noSessions'))
856
- : sessions.map((row) => h('option', { key: row.id, value: row.id }, `${row.title}${row.running ? ' · ●' : ''}`))),
968
+ h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', gap: 12, flexWrap: 'wrap' } },
969
+ h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, minWidth: 0 } },
970
+ h('h2', { style: S.title }, t('title')),
971
+ h('p', { style: S.intro }, t('intro')),
857
972
  ),
858
- h('div', { style: S.hint }, t('workSessionHint')),
859
- h('div', { style: S.mono }, workId ?? ''),
860
- h('label', { style: S.label }, t('messageLanguage'),
861
- h('select', {
862
- style: S.input,
863
- value: board !== null && board.language === 'en' ? 'en' : 'zh',
864
- disabled: busy || workId === undefined,
865
- onChange: (event) => void changeLanguage(event.target.value),
866
- },
867
- h('option', { value: 'zh' }, t('langZh')),
868
- h('option', { value: 'en' }, t('langEn'))),
973
+ starLink,
974
+ ),
975
+ h('div', { style: S.card },
976
+ h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: 10 } },
977
+ h('label', { style: S.label }, t('workSession'),
978
+ h('select', {
979
+ style: S.input,
980
+ value: workId ?? '',
981
+ disabled: busy || sessions.length === 0,
982
+ onChange: (event) => setWorkId(event.target.value),
983
+ },
984
+ sessions.length === 0
985
+ ? h('option', { value: '' }, t('noSessions'))
986
+ : sessions.map((row) => h('option', { key: row.id, value: row.id }, `${row.title}${row.running ? ' · ●' : ''}`))),
987
+ ),
988
+ h('label', { style: S.label }, t('messageLanguage'),
989
+ h('select', {
990
+ style: S.input,
991
+ value: board !== null && board.language === 'en' ? 'en' : 'zh',
992
+ disabled: busy || workId === undefined,
993
+ onChange: (event) => void changeLanguage(event.target.value),
994
+ },
995
+ h('option', { value: 'zh' }, t('langZh')),
996
+ h('option', { value: 'en' }, t('langEn'))),
997
+ ),
869
998
  ),
870
999
  h('div', { style: S.row },
871
- h('button', { type: 'button', style: S.secondary, disabled: busy || workId === undefined, onClick: () => void refresh() }, t('refresh')),
1000
+ h('button', { type: 'button', style: S.secondary, disabled: busy || queueBusy || workId === undefined, onClick: () => void refresh() }, t('refresh')),
872
1001
  busy ? h('span', { style: S.muted }, t('busy')) : null,
873
1002
  ),
874
1003
  ),
@@ -881,6 +1010,19 @@ window.__ModuleLoader__.load({
881
1010
  )
882
1011
  : null
883
1012
 
1013
+ const quickGuide = h('div', { style: S.card },
1014
+ h('div', { style: S.cardHead },
1015
+ h('h3', { style: S.cardTitle }, t('guideTitle')),
1016
+ h('button', { type: 'button', style: S.secondary, onClick: () => setShowGuide(!showGuide) }, showGuide ? t('guideLess') : t('guideMore')),
1017
+ ),
1018
+ h('ol', { style: { margin: 0, paddingLeft: 18, display: 'flex', flexDirection: 'column', gap: 4, fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } },
1019
+ h('li', null, t('guideStep1')),
1020
+ h('li', null, t('guideStep2')),
1021
+ h('li', null, t('guideStep3')),
1022
+ ),
1023
+ showGuide ? h('p', { style: { ...S.hint, whiteSpace: 'pre-wrap', lineHeight: 1.75 } }, t('guideDetail')) : null,
1024
+ )
1025
+
884
1026
  const stateBadge = (state) => h('span', { style: { ...S.badge, color: state.color } }, state.label)
885
1027
 
886
1028
  const reminderText = (link) => (link.nudges > 0
@@ -938,8 +1080,10 @@ window.__ModuleLoader__.load({
938
1080
  )
939
1081
 
940
1082
  const relayCard = h('div', { style: S.card },
941
- h('h3', { style: S.cardTitle }, t('relayTitle')),
942
- h('p', { style: S.hint }, t('relayIntro')),
1083
+ h('div', { style: S.cardHead },
1084
+ h('h3', { style: S.cardTitle }, t('relayTitle')),
1085
+ h('button', { type: 'button', style: S.secondary, onClick: () => setShowRelay(false) }, t('summaryCollapse')),
1086
+ ),
943
1087
  h('label', { style: S.label }, t('relayModeLabel'),
944
1088
  h('select', {
945
1089
  style: S.input,
@@ -1171,6 +1315,9 @@ window.__ModuleLoader__.load({
1171
1315
  h('span', { style: S.badge }, queue !== null && queue.auto === false ? t('queuePaused') : t('queueAuto')),
1172
1316
  ),
1173
1317
  h('p', { style: S.intro }, t('queueIntro')),
1318
+ queue !== null && typeof queue.lastError === 'string' && queue.lastError !== ''
1319
+ ? h('p', { style: { ...S.notice, color: 'var(--dsw-alias-state-error-primary)' } }, t('queueLastError') + ':' + queue.lastError)
1320
+ : null,
1174
1321
  h('label', { style: S.label }, t('queueAddTitle'),
1175
1322
  h('input', {
1176
1323
  style: S.input,
@@ -1212,16 +1359,29 @@ window.__ModuleLoader__.load({
1212
1359
  disabled: queueBusy || queue === null || !queueItems.some((item) => item.status === 'pending'),
1213
1360
  onClick: () => void queueAction('clear'),
1214
1361
  }, t('queueClear')),
1362
+ queue !== null && ((queue.active !== null && queue.active !== undefined) || (typeof queue.lastError === 'string' && queue.lastError !== ''))
1363
+ ? h('button', {
1364
+ type: 'button',
1365
+ style: S.secondary,
1366
+ disabled: queueBusy,
1367
+ onClick: () => void queueAction('reset'),
1368
+ }, t('queueReset'))
1369
+ : null,
1215
1370
  ),
1216
- queue === null
1217
- ? h('p', { style: S.intro }, t('loading'))
1218
- : queueItems.length === 0
1219
- ? h('p', { style: S.intro }, t('queueEmpty'))
1220
- : h('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
1221
- queueItems.map((item, index) => h('div', { key: item.id, style: S.worker },
1371
+ queueError !== null
1372
+ ? h('p', { style: { ...S.notice, color: 'var(--dsw-alias-state-error-primary)' } }, t('queueLoadFailed') + ':' + queueError)
1373
+ : queue === null
1374
+ ? h('p', { style: S.intro }, t('loading'))
1375
+ : queueItems.length === 0
1376
+ ? h('p', { style: S.intro }, t('queueEmpty'))
1377
+ : h('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
1378
+ queueItems.map((item, index) => h('div', { key: item.id, style: S.worker },
1222
1379
  h('div', { style: S.workerMain },
1223
1380
  h('div', { style: S.workerName }, `${index + 1}. ${item.title || t('queueUntitled')}`),
1224
- h('div', { style: S.muted }, `${item.status === 'pending' ? t('queuePending') : item.status === 'sent' ? t('queueSent') : t('queueDone')} · ${item.prompt}`),
1381
+ item.status === 'failed'
1382
+ ? h('span', { style: { ...S.badge, alignSelf: 'flex-start', color: 'var(--dsw-alias-state-error-primary)' } }, t('queueFailed'))
1383
+ : null,
1384
+ h('div', { style: S.muted }, `${item.status === 'pending' ? t('queuePending') : item.status === 'sent' ? t('queueSent') : item.status === 'failed' ? t('queueFailed') : t('queueDone')} · ${item.prompt}`),
1225
1385
  ),
1226
1386
  item.status === 'pending'
1227
1387
  ? h('button', {
@@ -1250,11 +1410,14 @@ window.__ModuleLoader__.load({
1250
1410
 
1251
1411
  const boardCard = h('div', { style: S.card },
1252
1412
  h('div', { style: S.cardHead },
1253
- h('h3', { style: S.cardTitle }, t('boardTitle')),
1254
- h('span', { style: S.muted }, t('boardSummary', {
1255
- active: board === null ? 0 : board.activeCount ?? activeLinks.length,
1256
- total: board === null ? 0 : board.totalCount ?? links.length,
1257
- })),
1413
+ h('div', { style: S.row },
1414
+ h('h3', { style: S.cardTitle }, t('boardTitle')),
1415
+ h('span', { style: S.muted }, t('boardSummary', {
1416
+ active: board === null ? 0 : board.activeCount ?? activeLinks.length,
1417
+ total: board === null ? 0 : board.totalCount ?? links.length,
1418
+ })),
1419
+ ),
1420
+ h('button', { type: 'button', style: S.secondary, onClick: () => setShowBoard(false) }, t('summaryCollapse')),
1258
1421
  ),
1259
1422
  board === null
1260
1423
  ? h('p', { style: S.intro }, busy ? t('loading') : t('noTasks'))
@@ -1371,24 +1534,37 @@ window.__ModuleLoader__.load({
1371
1534
  }
1372
1535
 
1373
1536
  const workTitle = sessions.find((row) => row.id === workId)?.title
1374
- const starRow = h('div', { style: { display: 'flex', justifyContent: 'center', padding: '2px 0 6px' } },
1375
- h('a', {
1376
- href: 'https://github.com/awa1231/dsh-collab-pair',
1377
- target: '_blank',
1378
- rel: 'noreferrer noopener',
1379
- style: S.starLink,
1380
- }, t('starLabel')),
1537
+ const relaySummary = h('div', { style: S.card },
1538
+ h('div', { style: S.cardHead },
1539
+ h('h3', { style: S.cardTitle }, t('relayTitle')),
1540
+ h('span', { style: S.badge }, relayState === null ? t('loading') : relayModeText(relayState.mode)),
1541
+ ),
1542
+ h('div', { style: S.row },
1543
+ h('span', { style: S.muted }, t('summaryRelayHint')),
1544
+ h('button', { type: 'button', style: S.secondary, onClick: () => setShowRelay(true) }, t('summaryExpand')),
1545
+ ),
1546
+ )
1547
+ const totalCount = board !== null && typeof board.totalCount === 'number' ? board.totalCount : 0
1548
+ const activeCount = board !== null && typeof board.activeCount === 'number' ? board.activeCount : 0
1549
+ const boardSummary = h('div', { style: S.card },
1550
+ h('div', { style: S.cardHead },
1551
+ h('h3', { style: S.cardTitle }, t('boardTitle')),
1552
+ h('span', { style: S.muted }, t('boardSummary', { active: activeCount, total: totalCount })),
1553
+ ),
1554
+ h('div', { style: S.row },
1555
+ h('button', { type: 'button', style: S.secondary, onClick: () => setShowBoard(true) }, t('summaryExpand')),
1556
+ ),
1381
1557
  )
1382
1558
  return h('div', { style: S.page },
1383
- starRow,
1384
1559
  header,
1385
1560
  feedback,
1561
+ quickGuide,
1386
1562
  h('h3', { style: S.cardTitle }, workTitle === undefined ? t('currentTitle') : `${t('currentTitle')} · ${workTitle}`),
1387
1563
  currentCard,
1388
- relayCard,
1564
+ showRelay ? relayCard : relaySummary,
1389
1565
  stageCard,
1390
1566
  queueCard,
1391
- boardCard,
1567
+ showBoard ? boardCard : boardSummary,
1392
1568
  )
1393
1569
  }
1394
1570
 
package/index.js CHANGED
@@ -41,7 +41,9 @@ 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.5.2'
44
+ const QUEUE_LIMIT = 100
45
+ const QUEUE_DONE_LIMIT = 20
46
+ const ENGINE = 'collab-pair/1.5.4'
45
47
  const PREFIX_DEFAULTS = {
46
48
  zh: { manager: '【项目经理】', worker: '【员工】' },
47
49
  en: { manager: '[Manager]', worker: '[Worker]' },
@@ -592,6 +594,7 @@ export function apply(ctx, rawConfig) {
592
594
  setTimeout(() => { void recoverPendingLinks() }, 5000)
593
595
  setTimeout(() => { void backfillProjects() }, 3000)
594
596
  setTimeout(() => { void relocalizePrefixes() }, 4000)
597
+ setTimeout(() => { if (alive) void recoverQueues() }, 6000)
595
598
  setTimeout(() => { if (alive) void remoteLoop() }, 2000)
596
599
 
597
600
  registerTools()
@@ -810,11 +813,11 @@ export function apply(ctx, rawConfig) {
810
813
 
811
814
  function normalizeQueue(value, sessionId) {
812
815
  const items = []
813
- for (const item of Array.isArray(value?.items) ? value.items.slice(0, 100) : []) {
816
+ for (const item of Array.isArray(value?.items) ? value.items : []) {
814
817
  if (item === null || typeof item !== 'object') continue
815
818
  const prompt = typeof item.prompt === 'string' ? item.prompt.trim() : ''
816
819
  if (prompt === '') continue
817
- const status = item.status === 'sent' || item.status === 'done' ? item.status : 'pending'
820
+ const status = item.status === 'sent' || item.status === 'done' || item.status === 'failed' ? item.status : 'pending'
818
821
  items.push({
819
822
  id: typeof item.id === 'string' ? item.id : `q-${randomUUID().slice(0, 8)}`,
820
823
  title: typeof item.title === 'string' ? item.title : '',
@@ -826,17 +829,26 @@ export function apply(ctx, rawConfig) {
826
829
  ...(typeof item.marker === 'string' ? { marker: item.marker } : {}),
827
830
  })
828
831
  }
832
+ // Keep every pending/sent/failed item; only trim the oldest done history.
833
+ const doneIndexes = []
834
+ for (let index = 0; index < items.length; index++) {
835
+ if (items[index].status === 'done') doneIndexes.push(index)
836
+ }
837
+ const keepDone = new Set(doneIndexes.slice(-QUEUE_DONE_LIMIT))
838
+ const kept = items.filter((item, index) => item.status !== 'done' || keepDone.has(index))
829
839
  let activeId = typeof value?.activeId === 'string' ? value.activeId : null
830
- if (activeId !== null && !items.some((item) => item.id === activeId && item.status === 'sent')) activeId = null
840
+ if (activeId !== null && !kept.some((item) => item.id === activeId && item.status === 'sent')) activeId = null
831
841
  if (activeId === null) {
832
- const sent = items.find((item) => item.status === 'sent')
842
+ const sent = kept.find((item) => item.status === 'sent')
833
843
  if (sent !== undefined) activeId = sent.id
834
844
  }
835
845
  return {
836
846
  sessionId,
837
- items,
847
+ items: kept,
838
848
  activeId,
839
849
  auto: value?.auto !== false,
850
+ started: value?.started === true || kept.some((item) => item.status === 'sent' || item.status === 'done' || item.status === 'failed'),
851
+ lastError: typeof value?.lastError === 'string' && value.lastError !== '' ? value.lastError : null,
840
852
  updatedAt: Number.isFinite(value?.updatedAt) ? value.updatedAt : Date.now(),
841
853
  }
842
854
  }
@@ -874,6 +886,7 @@ export function apply(ctx, rawConfig) {
874
886
  sessionId: queue.sessionId,
875
887
  auto: queue.auto,
876
888
  active: queue.activeId,
889
+ lastError: queue.lastError ?? null,
877
890
  items: queue.items.map((item) => ({
878
891
  id: item.id,
879
892
  title: item.title,
@@ -899,6 +912,8 @@ export function apply(ctx, rawConfig) {
899
912
  next.requestId = requestId
900
913
  next.marker = marker
901
914
  queue.activeId = next.id
915
+ queue.started = true
916
+ queue.lastError = null
902
917
  queue.updatedAt = Date.now()
903
918
  await persistQueue(queue)
904
919
  const text = [
@@ -918,6 +933,7 @@ export function apply(ctx, rawConfig) {
918
933
  delete next.requestId
919
934
  delete next.marker
920
935
  queue.activeId = null
936
+ queue.lastError = clip(error instanceof Error ? error.message : String(error), 500)
921
937
  queue.updatedAt = Date.now()
922
938
  await persistQueue(queue)
923
939
  throw error
@@ -941,30 +957,113 @@ export function apply(ctx, rawConfig) {
941
957
  return
942
958
  }
943
959
  if (events === undefined || !claimedQueue(events, active)) return
960
+ const reason = event.data?.reason
961
+ const kind = typeof reason?.kind === 'string' ? reason.kind : (typeof reason === 'string' && reason !== '' ? reason : 'unknown')
962
+ if (kind !== 'completed' && kind !== 'max-tokens') {
963
+ active.status = 'failed'
964
+ queue.activeId = null
965
+ queue.auto = false
966
+ queue.lastError = '本轮结束原因:' + kind + ';未自动续发。'
967
+ queue.updatedAt = Date.now()
968
+ await persistQueue(queue)
969
+ return
970
+ }
944
971
  active.status = 'done'
945
972
  active.completedAt = Date.now()
946
973
  queue.activeId = null
974
+ queue.lastError = null
947
975
  queue.updatedAt = Date.now()
976
+ trimQueue(queue)
948
977
  await persistQueue(queue)
949
978
  if (!queue.auto) return
950
979
  if (queue.items.some((item) => item.status === 'pending')) {
951
980
  try {
952
981
  await startQueueItem(session.id, AbortSignal.timeout(PROMPT_TIMEOUT_MS))
953
982
  } catch (error) {
983
+ queue.lastError = clip(error instanceof Error ? error.message : String(error), 500)
984
+ queue.updatedAt = Date.now()
985
+ await persistQueue(queue)
954
986
  ctx.logger.warn(`collab-pair: sending the next queue item for ${session.id} failed: ${String(error)}`)
955
987
  }
956
988
  }
957
989
  }
958
990
 
959
991
  function claimedQueue(events, item) {
992
+ if (typeof item.requestId !== 'string' || item.requestId === '') return false
960
993
  for (const event of events) {
961
994
  if (event.type !== 'user/message') continue
962
- if (typeof item.requestId === 'string' && event.data?.source?.rpcId === item.requestId) return true
963
- if (typeof item.marker === 'string' && messageText(event.data).includes(item.marker)) return true
995
+ if (event.data?.source?.rpcId === item.requestId) return true
964
996
  }
965
997
  return false
966
998
  }
967
999
 
1000
+ /** Keep all live items but only the newest done history. */
1001
+ function trimQueue(queue) {
1002
+ const done = queue.items.filter((item) => item.status === 'done')
1003
+ if (done.length <= QUEUE_DONE_LIMIT) return
1004
+ const keep = new Set(done.slice(-QUEUE_DONE_LIMIT).map((item) => item.id))
1005
+ queue.items = queue.items.filter((item) => item.status !== 'done' || keep.has(item.id))
1006
+ }
1007
+
1008
+ /** Return every sent item to pending and clear the active/failure state. */
1009
+ async function resetQueue(sessionId) {
1010
+ const queue = await readQueue(sessionId)
1011
+ for (const item of queue.items) {
1012
+ if (item.status !== 'sent') continue
1013
+ item.status = 'pending'
1014
+ delete item.sentAt
1015
+ delete item.requestId
1016
+ delete item.marker
1017
+ }
1018
+ queue.activeId = null
1019
+ queue.lastError = null
1020
+ queue.updatedAt = Date.now()
1021
+ await persistQueue(queue)
1022
+ return queue
1023
+ }
1024
+
1025
+ /** Resume idle auto-advance queues after activation. */
1026
+ async function recoverQueues() {
1027
+ try {
1028
+ const candidates = new Map(queues)
1029
+ const domain = await remoteReady.catch(() => undefined)
1030
+ if (domain !== undefined) {
1031
+ try {
1032
+ for (const [key, value] of domain.table('state').entries()) {
1033
+ if (typeof key !== 'string' || !key.startsWith('queue:')) continue
1034
+ const sessionId = key.slice('queue:'.length)
1035
+ if (sessionId === '') continue
1036
+ if (!queues.has(sessionId)) queues.set(sessionId, normalizeQueue(value, sessionId))
1037
+ candidates.set(sessionId, queues.get(sessionId))
1038
+ }
1039
+ } catch (error) {
1040
+ ctx.logger.warn('collab-pair: scanning queues for recovery failed: ' + String(error))
1041
+ }
1042
+ }
1043
+ for (const [sessionId, queue] of candidates) {
1044
+ if (!alive) return
1045
+ if (queue === undefined || queue.auto !== true || queue.started !== true || queue.activeId !== null) continue
1046
+ if (!queue.items.some((item) => item.status === 'pending')) continue
1047
+ try {
1048
+ const current = await readQueue(sessionId)
1049
+ if (current.auto !== true || current.started !== true || current.activeId !== null) continue
1050
+ if (!current.items.some((item) => item.status === 'pending')) continue
1051
+ await startQueueItem(sessionId, AbortSignal.timeout(PROMPT_TIMEOUT_MS))
1052
+ } catch (error) {
1053
+ const current = await readQueue(sessionId).catch(() => undefined)
1054
+ if (current !== undefined && current.activeId === null) {
1055
+ current.lastError = clip(error instanceof Error ? error.message : String(error), 500)
1056
+ current.updatedAt = Date.now()
1057
+ await persistQueue(current)
1058
+ }
1059
+ ctx.logger.warn('collab-pair: recovering the queue for ' + sessionId + ' failed: ' + String(error))
1060
+ }
1061
+ }
1062
+ } catch (error) {
1063
+ ctx.logger.warn('collab-pair: queue recovery failed: ' + String(error))
1064
+ }
1065
+ }
1066
+
968
1067
  function hubConfigured() {
969
1068
  return cfg.relayMode === 'hub' && cfg.hubUrl !== '' && cfg.hubToken !== ''
970
1069
  }
@@ -3123,6 +3222,9 @@ export function apply(ctx, rawConfig) {
3123
3222
  if (sub === 'add') {
3124
3223
  const prompt = typeof args?.prompt === 'string' ? args.prompt.trim() : ''
3125
3224
  if (prompt === '') return { kind: 'error', text: 'prompt 不能为空。' }
3225
+ if (queue.items.length >= QUEUE_LIMIT) {
3226
+ return { kind: 'error', text: '队列最多 ' + QUEUE_LIMIT + ' 条;请先清理待发或已完成条目。' }
3227
+ }
3126
3228
  queue.items.push({
3127
3229
  id: `q-${randomUUID().slice(0, 8)}`,
3128
3230
  title: typeof args?.title === 'string' ? args.title.trim() : '',
@@ -3141,11 +3243,22 @@ export function apply(ctx, rawConfig) {
3141
3243
  queue.auto = sub === 'resume'
3142
3244
  queue.updatedAt = Date.now()
3143
3245
  await persistQueue(queue)
3246
+ if (sub === 'resume' && queue.activeId === null && queue.items.some((item) => item.status === 'pending')) {
3247
+ const { queue: started, item } = await startQueueItem(agent.id, invocation.signal)
3248
+ return { kind: 'success', text: JSON.stringify({ ...queueView(started), started: item.id }) }
3249
+ }
3144
3250
  return { kind: 'success', text: JSON.stringify(queueView(queue)) }
3145
3251
  }
3252
+ if (sub === 'reset') {
3253
+ const reset = await resetQueue(agent.id)
3254
+ return { kind: 'success', text: JSON.stringify(queueView(reset)) }
3255
+ }
3146
3256
  if (sub === 'remove') {
3147
- const index = clampInt(args?.index, 1, 100, 0)
3148
- const item = index > 0 ? queue.items[index - 1] : undefined
3257
+ const index = Number(args?.index)
3258
+ if (!Number.isInteger(index) || index < 1 || index > queue.items.length) {
3259
+ return { kind: 'error', text: 'index 必须是 1 到当前条目数之间的整数。' }
3260
+ }
3261
+ const item = queue.items[index - 1]
3149
3262
  if (item === undefined) return { kind: 'error', text: 'index 超出范围。' }
3150
3263
  if (item.status !== 'pending') return { kind: 'error', text: '只能删除尚未发送的条目。' }
3151
3264
  queue.items.splice(index - 1, 1)
@@ -3159,7 +3272,7 @@ export function apply(ctx, rawConfig) {
3159
3272
  await persistQueue(queue)
3160
3273
  return { kind: 'success', text: JSON.stringify(queueView(queue)) }
3161
3274
  }
3162
- return { kind: 'error', text: 'action 必须是 list | add | start | pause | resume | remove | clear。' }
3275
+ return { kind: 'error', text: 'action 必须是 list | add | start | pause | resume | reset | remove | clear。' }
3163
3276
  }
3164
3277
  if (action === 'manage') {
3165
3278
  const agent = invocation.agent
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-collab-pair",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
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",