dsh-collab-pair 1.5.2 → 1.5.3
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 +4 -2
- package/client.js +74 -19
- package/index.js +124 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -136,7 +136,8 @@ Any conversation, not only a manager, can have its own prompt queue:
|
|
|
136
136
|
|
|
137
137
|
- Add items in the **Conversation to-do** card, or `/collab queue {"action":"add","title":"…","prompt":"…"}`.
|
|
138
138
|
- `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.
|
|
139
|
+
- `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.
|
|
140
|
+
- 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
141
|
- The queue is stored per conversation and survives plugin reloads.
|
|
141
142
|
|
|
142
143
|
## Projects
|
|
@@ -405,7 +406,8 @@ collab_dispatch({ worker: "前端", task: "…" })
|
|
|
405
406
|
|
|
406
407
|
- 在「对话待办」卡片里添加,或 `/collab queue {"action":"add","title":"…","prompt":"…"}`。
|
|
407
408
|
- `start` 把第一条待发提示词作为普通用户消息发进去;该回合结束后,自动发送下一条。
|
|
408
|
-
- `pause` 在当前回合后停止自动连发,`resume`
|
|
409
|
+
- `pause` 在当前回合后停止自动连发,`resume` 恢复并在队列空闲时发送下一条,`clear` 清空待发。
|
|
410
|
+
- 如果某轮以错误/中止结束,该条会标记为 **失败** 并暂停自动连发;点「重置队列」可把卡在 `sent` 的条目退回待发并重试。
|
|
409
411
|
- 队列按对话保存,插件重载后仍在。
|
|
410
412
|
|
|
411
413
|
## 项目
|
package/client.js
CHANGED
|
@@ -144,6 +144,10 @@ window.__ModuleLoader__.load({
|
|
|
144
144
|
queueUntitled: '未命名任务',
|
|
145
145
|
queueAuto: '自动连发',
|
|
146
146
|
queuePaused: '已暂停',
|
|
147
|
+
queueFailed: '失败',
|
|
148
|
+
queueReset: '重置队列',
|
|
149
|
+
queueLoadFailed: '读取队列失败',
|
|
150
|
+
queueLastError: '最近错误',
|
|
147
151
|
stageAdded: '阶段已添加。',
|
|
148
152
|
stageStarted: '阶段已开始。',
|
|
149
153
|
stageFinished: '阶段已完成。',
|
|
@@ -298,6 +302,10 @@ window.__ModuleLoader__.load({
|
|
|
298
302
|
queueUntitled: 'Untitled task',
|
|
299
303
|
queueAuto: 'Auto-advance',
|
|
300
304
|
queuePaused: 'Paused',
|
|
305
|
+
queueFailed: 'Failed',
|
|
306
|
+
queueReset: 'Reset queue',
|
|
307
|
+
queueLoadFailed: 'Failed to load the queue',
|
|
308
|
+
queueLastError: 'Last error',
|
|
301
309
|
stageAdded: 'Stage added.',
|
|
302
310
|
stageStarted: 'Stage started.',
|
|
303
311
|
stageFinished: 'Stage finished.',
|
|
@@ -425,8 +433,12 @@ window.__ModuleLoader__.load({
|
|
|
425
433
|
const [queueTitle, setQueueTitle] = React.useState('')
|
|
426
434
|
const [queuePrompt, setQueuePrompt] = React.useState('')
|
|
427
435
|
const [queueBusy, setQueueBusy] = React.useState(false)
|
|
436
|
+
const [queueError, setQueueError] = React.useState(null)
|
|
428
437
|
const commandsRef = React.useRef(commands)
|
|
429
438
|
commandsRef.current = commands
|
|
439
|
+
const workIdRef = React.useRef(workId)
|
|
440
|
+
workIdRef.current = workId
|
|
441
|
+
const queueReadSeq = React.useRef(0)
|
|
430
442
|
|
|
431
443
|
React.useEffect(() => {
|
|
432
444
|
if (workId !== undefined) return
|
|
@@ -511,6 +523,7 @@ window.__ModuleLoader__.load({
|
|
|
511
523
|
setError(null)
|
|
512
524
|
try {
|
|
513
525
|
await loadBoard(workId)
|
|
526
|
+
if (!queueBusy) await readQueue(workId)
|
|
514
527
|
const relay = await readRelay(workId).catch(() => null)
|
|
515
528
|
if (relay !== null && relay.mode !== 'off') await loadAliases(workId).catch(() => undefined)
|
|
516
529
|
} catch (cause) {
|
|
@@ -584,32 +597,51 @@ window.__ModuleLoader__.load({
|
|
|
584
597
|
return value
|
|
585
598
|
}
|
|
586
599
|
|
|
587
|
-
/**
|
|
588
|
-
const readQueue = async (sessionId) => {
|
|
600
|
+
/** Read one session's queue; stale session responses are discarded. */
|
|
601
|
+
const readQueue = async (sessionId, isCancelled) => {
|
|
602
|
+
const seq = ++queueReadSeq.current
|
|
603
|
+
const stale = () => (typeof isCancelled === 'function' && isCancelled())
|
|
604
|
+
|| workIdRef.current !== sessionId || seq !== queueReadSeq.current
|
|
589
605
|
try {
|
|
590
606
|
const value = await runCommand(commandsRef.current, sessionId, '/collab queue {"action":"list"}')
|
|
591
|
-
if (value !== null && typeof value === 'object' && Array.isArray(value.items)
|
|
607
|
+
if (value !== null && typeof value === 'object' && Array.isArray(value.items)
|
|
608
|
+
&& value.sessionId === sessionId && !stale()) {
|
|
609
|
+
setQueue(value)
|
|
610
|
+
setQueueError(null)
|
|
611
|
+
}
|
|
592
612
|
return value
|
|
593
|
-
} catch {
|
|
594
|
-
|
|
613
|
+
} catch (cause) {
|
|
614
|
+
if (!stale()) {
|
|
615
|
+
setQueue(null)
|
|
616
|
+
setQueueError(cause instanceof Error ? cause.message : String(cause))
|
|
617
|
+
}
|
|
595
618
|
return null
|
|
596
619
|
}
|
|
597
620
|
}
|
|
598
621
|
|
|
599
622
|
const queueAction = async (action, extra = {}) => {
|
|
600
623
|
if (workId === undefined) return
|
|
624
|
+
const sessionId = workId
|
|
625
|
+
const seq = ++queueReadSeq.current
|
|
601
626
|
setQueueBusy(true)
|
|
602
627
|
setError(null)
|
|
603
628
|
setNotice(null)
|
|
629
|
+
setQueueError(null)
|
|
604
630
|
try {
|
|
605
|
-
const value = await runCommand(commandsRef.current,
|
|
606
|
-
|
|
607
|
-
if (
|
|
631
|
+
const value = await runCommand(commandsRef.current, sessionId, `/collab queue ${JSON.stringify({ action, ...extra })}`)
|
|
632
|
+
const current = workIdRef.current === sessionId && seq === queueReadSeq.current
|
|
633
|
+
if (current && value !== null && typeof value === 'object' && Array.isArray(value.items) && value.sessionId === sessionId) {
|
|
634
|
+
setQueue(value)
|
|
635
|
+
setQueueError(null)
|
|
636
|
+
}
|
|
637
|
+
if (action === 'add' && current) {
|
|
608
638
|
setQueueTitle('')
|
|
609
639
|
setQueuePrompt('')
|
|
610
640
|
}
|
|
611
641
|
} catch (cause) {
|
|
612
|
-
|
|
642
|
+
if (workIdRef.current === sessionId && seq === queueReadSeq.current) {
|
|
643
|
+
setError(cause instanceof Error ? cause.message : String(cause))
|
|
644
|
+
}
|
|
613
645
|
} finally {
|
|
614
646
|
setQueueBusy(false)
|
|
615
647
|
}
|
|
@@ -618,9 +650,16 @@ window.__ModuleLoader__.load({
|
|
|
618
650
|
React.useEffect(() => {
|
|
619
651
|
if (workId === undefined) {
|
|
620
652
|
setQueue(null)
|
|
621
|
-
|
|
653
|
+
setQueueError(null)
|
|
654
|
+
return undefined
|
|
655
|
+
}
|
|
656
|
+
let cancelled = false
|
|
657
|
+
setQueue(null)
|
|
658
|
+
setQueueError(null)
|
|
659
|
+
void readQueue(workId, () => cancelled)
|
|
660
|
+
return () => {
|
|
661
|
+
cancelled = true
|
|
622
662
|
}
|
|
623
|
-
void readQueue(workId)
|
|
624
663
|
}, [workId])
|
|
625
664
|
|
|
626
665
|
const runAction = async (line, successText) => {
|
|
@@ -868,7 +907,7 @@ window.__ModuleLoader__.load({
|
|
|
868
907
|
h('option', { value: 'en' }, t('langEn'))),
|
|
869
908
|
),
|
|
870
909
|
h('div', { style: S.row },
|
|
871
|
-
h('button', { type: 'button', style: S.secondary, disabled: busy || workId === undefined, onClick: () => void refresh() }, t('refresh')),
|
|
910
|
+
h('button', { type: 'button', style: S.secondary, disabled: busy || queueBusy || workId === undefined, onClick: () => void refresh() }, t('refresh')),
|
|
872
911
|
busy ? h('span', { style: S.muted }, t('busy')) : null,
|
|
873
912
|
),
|
|
874
913
|
),
|
|
@@ -1171,6 +1210,9 @@ window.__ModuleLoader__.load({
|
|
|
1171
1210
|
h('span', { style: S.badge }, queue !== null && queue.auto === false ? t('queuePaused') : t('queueAuto')),
|
|
1172
1211
|
),
|
|
1173
1212
|
h('p', { style: S.intro }, t('queueIntro')),
|
|
1213
|
+
queue !== null && typeof queue.lastError === 'string' && queue.lastError !== ''
|
|
1214
|
+
? h('p', { style: { ...S.notice, color: 'var(--dsw-alias-state-error-primary)' } }, t('queueLastError') + ':' + queue.lastError)
|
|
1215
|
+
: null,
|
|
1174
1216
|
h('label', { style: S.label }, t('queueAddTitle'),
|
|
1175
1217
|
h('input', {
|
|
1176
1218
|
style: S.input,
|
|
@@ -1212,16 +1254,29 @@ window.__ModuleLoader__.load({
|
|
|
1212
1254
|
disabled: queueBusy || queue === null || !queueItems.some((item) => item.status === 'pending'),
|
|
1213
1255
|
onClick: () => void queueAction('clear'),
|
|
1214
1256
|
}, t('queueClear')),
|
|
1257
|
+
queue !== null && ((queue.active !== null && queue.active !== undefined) || (typeof queue.lastError === 'string' && queue.lastError !== ''))
|
|
1258
|
+
? h('button', {
|
|
1259
|
+
type: 'button',
|
|
1260
|
+
style: S.secondary,
|
|
1261
|
+
disabled: queueBusy,
|
|
1262
|
+
onClick: () => void queueAction('reset'),
|
|
1263
|
+
}, t('queueReset'))
|
|
1264
|
+
: null,
|
|
1215
1265
|
),
|
|
1216
|
-
|
|
1217
|
-
? h('p', { style: S.
|
|
1218
|
-
:
|
|
1219
|
-
? h('p', { style: S.intro }, t('
|
|
1220
|
-
:
|
|
1221
|
-
|
|
1266
|
+
queueError !== null
|
|
1267
|
+
? h('p', { style: { ...S.notice, color: 'var(--dsw-alias-state-error-primary)' } }, t('queueLoadFailed') + ':' + queueError)
|
|
1268
|
+
: queue === null
|
|
1269
|
+
? h('p', { style: S.intro }, t('loading'))
|
|
1270
|
+
: queueItems.length === 0
|
|
1271
|
+
? h('p', { style: S.intro }, t('queueEmpty'))
|
|
1272
|
+
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
1273
|
+
queueItems.map((item, index) => h('div', { key: item.id, style: S.worker },
|
|
1222
1274
|
h('div', { style: S.workerMain },
|
|
1223
1275
|
h('div', { style: S.workerName }, `${index + 1}. ${item.title || t('queueUntitled')}`),
|
|
1224
|
-
|
|
1276
|
+
item.status === 'failed'
|
|
1277
|
+
? h('span', { style: { ...S.badge, alignSelf: 'flex-start', color: 'var(--dsw-alias-state-error-primary)' } }, t('queueFailed'))
|
|
1278
|
+
: null,
|
|
1279
|
+
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
1280
|
),
|
|
1226
1281
|
item.status === 'pending'
|
|
1227
1282
|
? h('button', {
|
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
|
|
44
|
+
const QUEUE_LIMIT = 100
|
|
45
|
+
const QUEUE_DONE_LIMIT = 20
|
|
46
|
+
const ENGINE = 'collab-pair/1.5.3'
|
|
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
|
|
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 && !
|
|
840
|
+
if (activeId !== null && !kept.some((item) => item.id === activeId && item.status === 'sent')) activeId = null
|
|
831
841
|
if (activeId === null) {
|
|
832
|
-
const 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 (
|
|
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 =
|
|
3148
|
-
|
|
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.
|
|
3
|
+
"version": "1.5.3",
|
|
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",
|