dsh-collab-pair 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -5
- package/client.js +77 -6
- package/index.js +160 -52
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,7 +33,9 @@ Manager receives a collaboration report → next round for that worker, or colla
|
|
|
33
33
|
- Project manager: the workers it manages (state, round, current task, latest report, unlink) plus a form to link another worker.
|
|
34
34
|
- Worker: its manager, current task, state, latest report, and a "Leave" action.
|
|
35
35
|
- Not linked: the link form.
|
|
36
|
-
3. **All tasks** — a board across every collaboration
|
|
36
|
+
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.
|
|
37
|
+
|
|
38
|
+
The manager card also shows the **project name** and lets you rename it.
|
|
37
39
|
|
|
38
40
|
The header also has a **Message language** selector (中文 / English). It switches the generated collaboration messages; the page labels follow the app language.
|
|
39
41
|
|
|
@@ -54,6 +56,24 @@ Once a round is dispatched, the worker finishing wakes the manager automatically
|
|
|
54
56
|
|
|
55
57
|
Set `autoNudge: false` to disable reminders.
|
|
56
58
|
|
|
59
|
+
## Projects
|
|
60
|
+
|
|
61
|
+
A project is the set of workers managed by one project-manager conversation. Different managers are different projects, so nothing mixes:
|
|
62
|
+
|
|
63
|
+
- On the first link the project name defaults to the manager conversation title (role prefix removed).
|
|
64
|
+
- Rename it in the manager card or with `collab_project({ name })` / `/collab project {"name":"…"}`; every worker of that manager follows the project.
|
|
65
|
+
- The board groups tasks by project (project name + manager).
|
|
66
|
+
- A worker belongs to exactly one project at a time; unlink it before linking it to another manager.
|
|
67
|
+
|
|
68
|
+
## Link modes
|
|
69
|
+
|
|
70
|
+
Each worker is linked in one of two modes:
|
|
71
|
+
|
|
72
|
+
- **Temporary** (default): `collab_done` unbinds the pair automatically — the link record is removed, the title prefix is cleared, and the worker can join another manager.
|
|
73
|
+
- **Permanent**: `collab_done` ends the current project but keeps the association — the prefix and record stay, the board shows the worker as finished, and you can dispatch again later or remove it with `collab_unlink`.
|
|
74
|
+
|
|
75
|
+
Choose the mode in the link form, or pass `mode` to `collab_link`.
|
|
76
|
+
|
|
57
77
|
## Title prefixes
|
|
58
78
|
|
|
59
79
|
Linking adds a prefix to both conversations and removes it when the link ends (or the last worker finishes):
|
|
@@ -84,12 +104,13 @@ For an existing conversation, call `collab_sessions` to get its id, then `collab
|
|
|
84
104
|
| Tool | Role | Purpose |
|
|
85
105
|
| --- | --- | --- |
|
|
86
106
|
| `collab_sessions` | anyone | List recent conversations (id / title / activity / link state) |
|
|
87
|
-
| `collab_link` | anyone | Link a worker; `role=worker` makes the current conversation the worker; `peer="new"` creates one |
|
|
107
|
+
| `collab_link` | anyone | Link a worker; `role=worker` makes the current conversation the worker; `peer="new"` creates one; `mode` picks temporary/permanent; `project` names the project |
|
|
88
108
|
| `collab_dispatch` | manager | Dispatch one round; `worker` selects the worker (optional with a single worker), `acceptance` optional |
|
|
89
109
|
| `collab_report` | worker | Report `summary` / `status`(done\|partial\|blocked) / `details` / `next` |
|
|
90
110
|
| `collab_status` | anyone | A manager sees every worker's progress; a worker sees its manager and pending task |
|
|
91
111
|
| `collab_configure` | manager | Set a worker's agent preset or model; without arguments it lists available presets |
|
|
92
|
-
| `
|
|
112
|
+
| `collab_project` | manager | Set the project name shared by this manager's workers |
|
|
113
|
+
| `collab_done` | manager | Finish one worker (or `all=true`); temporary links unbind automatically |
|
|
93
114
|
| `collab_unlink` | both | Remove a link; a manager uses `worker` or `all`, a worker leaves its own |
|
|
94
115
|
|
|
95
116
|
## `/collab` command
|
|
@@ -102,6 +123,7 @@ The settings page uses it; it can also be typed manually:
|
|
|
102
123
|
/collab status
|
|
103
124
|
/collab link {"peer":"new"}
|
|
104
125
|
/collab link {"peer":"session-…"}
|
|
126
|
+
/collab project {"name":"…"}
|
|
105
127
|
/collab configure {"worker":"session-…","preset":"ptc"}
|
|
106
128
|
/collab configure {"worker":"session-…","provider":"deepseek-account","model":"deepseek-flash"}
|
|
107
129
|
/collab dispatch {"worker":"session-…","task":"…","acceptance":"…"}
|
|
@@ -205,6 +227,24 @@ dsh plugin add dsh-collab-pair
|
|
|
205
227
|
|
|
206
228
|
不需要提醒时设 `autoNudge: false`。
|
|
207
229
|
|
|
230
|
+
## 项目
|
|
231
|
+
|
|
232
|
+
一个项目就是「一个项目经理对话所管理的员工集合」。不同项目经理就是不同项目,互不混淆:
|
|
233
|
+
|
|
234
|
+
- 第一次关联时,项目名默认取项目经理对话的标题(去掉角色前缀)。
|
|
235
|
+
- 可在项目经理卡片里改名,或用 `collab_project({ name })` / `/collab project {"name":"…"}`;该经理的所有员工会一起归到新项目名。
|
|
236
|
+
- 看板按项目分组(项目名 + 项目经理)。
|
|
237
|
+
- 一个员工同一时间只属于一个项目;要换项目经理,先解除原关联。
|
|
238
|
+
|
|
239
|
+
## 关联模式
|
|
240
|
+
|
|
241
|
+
每个员工关联时选择一种模式:
|
|
242
|
+
|
|
243
|
+
- **临时**(默认):`collab_done` 后自动解绑——关联记录删除、标题前缀去掉,员工可以再加入其他项目经理。
|
|
244
|
+
- **永久**:`collab_done` 只结束当前项目,关联保留——前缀和记录都在,看板显示已结束,之后可以继续派发,直到手动 `collab_unlink`。
|
|
245
|
+
|
|
246
|
+
在关联表单里选择,或给 `collab_link` 传 `mode`。
|
|
247
|
+
|
|
208
248
|
## 标题前缀
|
|
209
249
|
|
|
210
250
|
关联时自动给两个对话加前缀,解除(或最后一个员工结束时)自动去掉:
|
|
@@ -231,12 +271,13 @@ dsh plugin add dsh-collab-pair
|
|
|
231
271
|
| 工具 | 角色 | 作用 |
|
|
232
272
|
| --- | --- | --- |
|
|
233
273
|
| `collab_sessions` | 任何人 | 列出最近对话(id / 标题 / 活跃 / 是否已关联) |
|
|
234
|
-
| `collab_link` | 任何人 | 关联员工;`role=worker` 表示当前对话成为对方的员工;`peer="new"`
|
|
274
|
+
| `collab_link` | 任何人 | 关联员工;`role=worker` 表示当前对话成为对方的员工;`peer="new"` 新建;`mode` 选临时/永久;`project` 指定项目名 |
|
|
235
275
|
| `collab_dispatch` | 项目经理 | 派发一轮;`worker` 指定员工(只有一个时可省略),`acceptance` 可选 |
|
|
236
276
|
| `collab_report` | 员工 | 汇报 `summary` / `status`(done\|partial\|blocked) / `details` / `next` |
|
|
237
277
|
| `collab_status` | 任何人 | 经理看所有员工进度;员工看自己的经理与待办 |
|
|
238
278
|
| `collab_configure` | 项目经理 | 设置某个员工的 agent 预设或模型;不传参数时列出可用预设 |
|
|
239
|
-
| `
|
|
279
|
+
| `collab_project` | 项目经理 | 设置该经理的员工所属的项目名 |
|
|
280
|
+
| `collab_done` | 项目经理 | 结束某个员工;临时关联会自动解绑;`all=true` 结束全部 |
|
|
240
281
|
| `collab_unlink` | 双方 | 删除关联;经理用 `worker` 或 `all`,员工解除自己 |
|
|
241
282
|
|
|
242
283
|
## `/collab` 命令
|
|
@@ -249,6 +290,7 @@ dsh plugin add dsh-collab-pair
|
|
|
249
290
|
/collab status
|
|
250
291
|
/collab link {"peer":"new"}
|
|
251
292
|
/collab link {"peer":"session-…"}
|
|
293
|
+
/collab project {"name":"…"}
|
|
252
294
|
/collab configure {"worker":"session-…","preset":"ptc"}
|
|
253
295
|
/collab configure {"worker":"session-…","provider":"deepseek-account","model":"deepseek-flash"}
|
|
254
296
|
/collab dispatch {"worker":"session-…","task":"…","acceptance":"…"}
|
package/client.js
CHANGED
|
@@ -28,6 +28,15 @@ window.__ModuleLoader__.load({
|
|
|
28
28
|
peer: '员工对话',
|
|
29
29
|
peerNew: '新建一个员工对话',
|
|
30
30
|
link: '关联',
|
|
31
|
+
linkMode: '关联模式',
|
|
32
|
+
modeTemporary: '临时关联(完成即解绑)',
|
|
33
|
+
modePermanent: '永久关联(直到手动解除)',
|
|
34
|
+
modeTempShort: '临时',
|
|
35
|
+
modePermShort: '永久',
|
|
36
|
+
projectLabel: '项目',
|
|
37
|
+
projectUnnamed: '未命名项目',
|
|
38
|
+
projectSave: '保存项目名',
|
|
39
|
+
projectSaved: '项目名已更新',
|
|
31
40
|
linkDone: '已关联员工。接下来在项目经理对话里派发任务。',
|
|
32
41
|
workerPrefixHint: '关联后两个对话的标题会自动加上【项目经理】/【员工】前缀,解除时自动去掉。',
|
|
33
42
|
managerTitle: '项目经理',
|
|
@@ -81,6 +90,15 @@ window.__ModuleLoader__.load({
|
|
|
81
90
|
peer: 'Worker conversation',
|
|
82
91
|
peerNew: 'Create a new worker conversation',
|
|
83
92
|
link: 'Link',
|
|
93
|
+
linkMode: 'Link mode',
|
|
94
|
+
modeTemporary: 'Temporary (unbind when done)',
|
|
95
|
+
modePermanent: 'Permanent (until unlinked)',
|
|
96
|
+
modeTempShort: 'Temporary',
|
|
97
|
+
modePermShort: 'Permanent',
|
|
98
|
+
projectLabel: 'Project',
|
|
99
|
+
projectUnnamed: 'Unnamed project',
|
|
100
|
+
projectSave: 'Save project name',
|
|
101
|
+
projectSaved: 'Project name updated',
|
|
84
102
|
linkDone: 'Worker linked. Dispatch tasks from the manager conversation.',
|
|
85
103
|
workerPrefixHint: 'Linking adds a 【项目经理】/【员工】 prefix to both titles; unlinking removes it.',
|
|
86
104
|
managerTitle: 'Project manager',
|
|
@@ -198,6 +216,8 @@ window.__ModuleLoader__.load({
|
|
|
198
216
|
const [notice, setNotice] = React.useState(null)
|
|
199
217
|
const [busy, setBusy] = React.useState(false)
|
|
200
218
|
const [peer, setPeer] = React.useState('new')
|
|
219
|
+
const [mode, setMode] = React.useState('temporary')
|
|
220
|
+
const [projectDraft, setProjectDraft] = React.useState('')
|
|
201
221
|
const commandsRef = React.useRef(commands)
|
|
202
222
|
commandsRef.current = commands
|
|
203
223
|
|
|
@@ -291,7 +311,7 @@ window.__ModuleLoader__.load({
|
|
|
291
311
|
}
|
|
292
312
|
|
|
293
313
|
const linkWorker = () => {
|
|
294
|
-
void act(`/collab link ${JSON.stringify({ peer })}`, t('linkDone'))
|
|
314
|
+
void act(`/collab link ${JSON.stringify({ peer, mode })}`, t('linkDone'))
|
|
295
315
|
}
|
|
296
316
|
|
|
297
317
|
const removeWorker = (worker) => {
|
|
@@ -304,12 +324,20 @@ window.__ModuleLoader__.load({
|
|
|
304
324
|
void act(`/collab unlink ${JSON.stringify({})}`, t('removeDone'))
|
|
305
325
|
}
|
|
306
326
|
|
|
327
|
+
const saveProject = () => {
|
|
328
|
+
const name = projectDraft.trim()
|
|
329
|
+
if (name === '') return
|
|
330
|
+
void act(`/collab project ${JSON.stringify({ name })}`, t('projectSaved')).then(() => setProjectDraft(''))
|
|
331
|
+
}
|
|
332
|
+
|
|
307
333
|
const links = board !== null && Array.isArray(board.links) ? board.links : []
|
|
308
334
|
const messageLang = board !== null && board.language === 'en' ? 'en' : 'zh'
|
|
335
|
+
const associated = links.filter((link) => link.status === 'active' || link.mode === 'permanent')
|
|
309
336
|
const activeLinks = links.filter((link) => link.status === 'active')
|
|
310
|
-
const managed = workId === undefined ? [] :
|
|
311
|
-
const mine = workId === undefined ? undefined :
|
|
337
|
+
const managed = workId === undefined ? [] : associated.filter((link) => link.manager === workId)
|
|
338
|
+
const mine = workId === undefined ? undefined : associated.find((link) => link.worker === workId)
|
|
312
339
|
const role = managed.length > 0 ? 'manager' : mine === undefined ? null : 'worker'
|
|
340
|
+
const managerProject = managed.find((link) => typeof link.project === 'string' && link.project !== '')?.project ?? ''
|
|
313
341
|
const peerChoices = sessions.filter((row) => row.id !== workId)
|
|
314
342
|
|
|
315
343
|
const statusText = (value) => {
|
|
@@ -383,6 +411,7 @@ window.__ModuleLoader__.load({
|
|
|
383
411
|
const reminderText = (link) => (link.nudges > 0
|
|
384
412
|
? ` · ${t('reminder', { count: link.nudges, max: board !== null && typeof board.maxNudges === 'number' ? board.maxNudges : 3 })}`
|
|
385
413
|
: '')
|
|
414
|
+
const modeText = (link) => (link.mode === 'permanent' ? t('modePermShort') : t('modeTempShort'))
|
|
386
415
|
|
|
387
416
|
const taskRow = (link) => {
|
|
388
417
|
const state = stateOf(link)
|
|
@@ -391,7 +420,7 @@ window.__ModuleLoader__.load({
|
|
|
391
420
|
h('div', { style: S.taskTitle }, link.workerTitle || link.worker),
|
|
392
421
|
h('div', { style: S.mono }, link.worker),
|
|
393
422
|
h('div', { style: S.muted },
|
|
394
|
-
`${link.managerTitle || link.manager} · ${roundText(link)}${reminderText(link)}`,
|
|
423
|
+
`${link.managerTitle || link.manager} · ${roundText(link)}${reminderText(link)} · ${modeText(link)}`,
|
|
395
424
|
),
|
|
396
425
|
link.pending === null || link.pending === undefined
|
|
397
426
|
? null
|
|
@@ -404,6 +433,19 @@ window.__ModuleLoader__.load({
|
|
|
404
433
|
)
|
|
405
434
|
}
|
|
406
435
|
|
|
436
|
+
const groups = []
|
|
437
|
+
const groupMap = new Map()
|
|
438
|
+
for (const link of links) {
|
|
439
|
+
const key = `${link.manager}\u0000${link.project || ''}`
|
|
440
|
+
let group = groupMap.get(key)
|
|
441
|
+
if (group === undefined) {
|
|
442
|
+
group = { key, manager: link.manager, managerTitle: link.managerTitle || link.manager, project: link.project || '', links: [] }
|
|
443
|
+
groupMap.set(key, group)
|
|
444
|
+
groups.push(group)
|
|
445
|
+
}
|
|
446
|
+
group.links.push(link)
|
|
447
|
+
}
|
|
448
|
+
|
|
407
449
|
const boardCard = h('div', { style: S.card },
|
|
408
450
|
h('div', { style: S.cardHead },
|
|
409
451
|
h('h3', { style: S.cardTitle }, t('boardTitle')),
|
|
@@ -416,7 +458,13 @@ window.__ModuleLoader__.load({
|
|
|
416
458
|
? h('p', { style: S.intro }, busy ? t('loading') : t('noTasks'))
|
|
417
459
|
: links.length === 0
|
|
418
460
|
? h('p', { style: S.intro }, t('noTasks'))
|
|
419
|
-
:
|
|
461
|
+
: groups.map((group) => h('div', { key: group.key, style: { display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
462
|
+
h('div', { style: { display: 'flex', gap: 8, alignItems: 'baseline', flexWrap: 'wrap' } },
|
|
463
|
+
h('span', { style: { fontSize: 13, fontWeight: 600 } }, group.project || t('projectUnnamed')),
|
|
464
|
+
h('span', { style: S.muted }, `${t('managerTitle')}:${group.managerTitle}`),
|
|
465
|
+
),
|
|
466
|
+
group.links.map(taskRow),
|
|
467
|
+
)),
|
|
420
468
|
)
|
|
421
469
|
|
|
422
470
|
const workerRow = (link) => {
|
|
@@ -425,7 +473,7 @@ window.__ModuleLoader__.load({
|
|
|
425
473
|
h('div', { style: S.workerMain },
|
|
426
474
|
h('div', { style: S.workerName }, link.workerTitle || link.worker),
|
|
427
475
|
h('div', { style: S.mono }, link.worker),
|
|
428
|
-
h('div', { style: S.muted }, `${roundText(link)}${reminderText(link)}`),
|
|
476
|
+
h('div', { style: S.muted }, `${roundText(link)}${reminderText(link)} · ${modeText(link)}`),
|
|
429
477
|
link.pending === null || link.pending === undefined
|
|
430
478
|
? null
|
|
431
479
|
: h('p', { style: S.taskText }, link.pending.task),
|
|
@@ -452,6 +500,16 @@ window.__ModuleLoader__.load({
|
|
|
452
500
|
h('option', { value: 'new' }, t('peerNew')),
|
|
453
501
|
peerChoices.map((row) => h('option', { key: row.id, value: row.id }, row.title))),
|
|
454
502
|
),
|
|
503
|
+
h('label', { style: S.label }, t('linkMode'),
|
|
504
|
+
h('select', {
|
|
505
|
+
style: S.input,
|
|
506
|
+
value: mode,
|
|
507
|
+
disabled: busy,
|
|
508
|
+
onChange: (event) => setMode(event.target.value),
|
|
509
|
+
},
|
|
510
|
+
h('option', { value: 'temporary' }, t('modeTemporary')),
|
|
511
|
+
h('option', { value: 'permanent' }, t('modePermanent'))),
|
|
512
|
+
),
|
|
455
513
|
h('div', { style: S.row },
|
|
456
514
|
h('button', { type: 'button', style: S.primary, disabled: busy, onClick: linkWorker }, t('link')),
|
|
457
515
|
),
|
|
@@ -468,6 +526,19 @@ window.__ModuleLoader__.load({
|
|
|
468
526
|
h('span', { style: S.badge }, t('managerTitle')),
|
|
469
527
|
h('span', { style: S.muted }, `${t('managing')} ${managed.length} ${t('workerCount')}`),
|
|
470
528
|
),
|
|
529
|
+
h('div', { style: S.row },
|
|
530
|
+
h('span', { style: S.muted }, `${t('projectLabel')}:${managerProject || t('projectUnnamed')}`),
|
|
531
|
+
),
|
|
532
|
+
h('div', { style: S.row },
|
|
533
|
+
h('input', {
|
|
534
|
+
style: { ...S.input, flex: 1 },
|
|
535
|
+
value: projectDraft,
|
|
536
|
+
placeholder: managerProject || t('projectUnnamed'),
|
|
537
|
+
disabled: busy,
|
|
538
|
+
onChange: (event) => setProjectDraft(event.target.value),
|
|
539
|
+
}),
|
|
540
|
+
h('button', { type: 'button', style: S.secondary, disabled: busy || projectDraft.trim() === '', onClick: saveProject }, t('projectSave')),
|
|
541
|
+
),
|
|
471
542
|
managed.length === 0 ? h('p', { style: S.intro }, t('noWorkers')) : managed.map(workerRow),
|
|
472
543
|
),
|
|
473
544
|
linkForm,
|
package/index.js
CHANGED
|
@@ -32,7 +32,7 @@ const DONE = 'done'
|
|
|
32
32
|
const STOPPED = 'stopped'
|
|
33
33
|
const REPORTS = new Set(['done', 'partial', 'blocked'])
|
|
34
34
|
const PROMPT_TIMEOUT_MS = 180000
|
|
35
|
-
const ENGINE = 'collab-pair/1.
|
|
35
|
+
const ENGINE = 'collab-pair/1.2.0'
|
|
36
36
|
|
|
37
37
|
/** A recoverable failure whose message is meant for the model. */
|
|
38
38
|
class CollabError extends Error {}
|
|
@@ -180,6 +180,7 @@ const LANGUAGES = {
|
|
|
180
180
|
zh: {
|
|
181
181
|
idle: '空闲',
|
|
182
182
|
waiting: '等待回报',
|
|
183
|
+
finished: '已结束',
|
|
183
184
|
statusLabel(status) {
|
|
184
185
|
if (status === 'done') return '完成'
|
|
185
186
|
if (status === 'partial') return '部分完成'
|
|
@@ -211,9 +212,10 @@ const LANGUAGES = {
|
|
|
211
212
|
moreWorkers(count) {
|
|
212
213
|
return `- …另有 ${count} 个员工,用 collab_status 查看`
|
|
213
214
|
},
|
|
214
|
-
managerSection({ count, rows, maxRounds }) {
|
|
215
|
+
managerSection({ count, rows, maxRounds, project }) {
|
|
215
216
|
return [
|
|
216
217
|
'## 双对话协作 · 你是项目经理',
|
|
218
|
+
...(project ? [`项目:${project}`] : []),
|
|
217
219
|
`你正在协调 ${count} 个员工对话;项目目标、任务拆解与验收标准由你在对话中掌握。`,
|
|
218
220
|
'员工:',
|
|
219
221
|
...rows,
|
|
@@ -226,9 +228,10 @@ const LANGUAGES = {
|
|
|
226
228
|
`- 每个员工最多 ${maxRounds} 轮。`,
|
|
227
229
|
].join('\n')
|
|
228
230
|
},
|
|
229
|
-
workerSection({ manager, round, pending }) {
|
|
231
|
+
workerSection({ manager, round, pending, project }) {
|
|
230
232
|
return [
|
|
231
233
|
'## 双对话协作 · 你是员工',
|
|
234
|
+
...(project ? [`项目:${project}`] : []),
|
|
232
235
|
`项目经理对话:${manager}`,
|
|
233
236
|
`进度:第 ${round} 轮${pending ? ',待你完成本轮任务' : ''}`,
|
|
234
237
|
'你负责执行项目经理派发的任务,并如实回报结果;项目目标与验收标准以派发消息为准,不要改变大方向或扩大范围。',
|
|
@@ -315,6 +318,7 @@ const LANGUAGES = {
|
|
|
315
318
|
en: {
|
|
316
319
|
idle: 'idle',
|
|
317
320
|
waiting: 'waiting for report',
|
|
321
|
+
finished: 'finished',
|
|
318
322
|
statusLabel(status) {
|
|
319
323
|
if (status === 'done') return 'done'
|
|
320
324
|
if (status === 'partial') return 'partially done'
|
|
@@ -346,9 +350,10 @@ const LANGUAGES = {
|
|
|
346
350
|
moreWorkers(count) {
|
|
347
351
|
return `- …and ${count} more workers; use collab_status to see all`
|
|
348
352
|
},
|
|
349
|
-
managerSection({ count, rows, maxRounds }) {
|
|
353
|
+
managerSection({ count, rows, maxRounds, project }) {
|
|
350
354
|
return [
|
|
351
355
|
'## Collaboration pair · You are the project manager',
|
|
356
|
+
...(project ? [`Project: ${project}`] : []),
|
|
352
357
|
`You coordinate ${count} worker conversations. You own the project goal, the task breakdown, and the acceptance criteria.`,
|
|
353
358
|
'Workers:',
|
|
354
359
|
...rows,
|
|
@@ -361,9 +366,10 @@ const LANGUAGES = {
|
|
|
361
366
|
`- At most ${maxRounds} rounds per worker.`,
|
|
362
367
|
].join('\n')
|
|
363
368
|
},
|
|
364
|
-
workerSection({ manager, round, pending }) {
|
|
369
|
+
workerSection({ manager, round, pending, project }) {
|
|
365
370
|
return [
|
|
366
371
|
'## Collaboration pair · You are a worker',
|
|
372
|
+
...(project ? [`Project: ${project}`] : []),
|
|
367
373
|
`Manager conversation: ${manager}`,
|
|
368
374
|
`Progress: round ${round}${pending ? ', with a task waiting for you' : ''}`,
|
|
369
375
|
'Execute the tasks the manager dispatches and report back honestly. The goal and acceptance criteria come from the dispatch message; do not change direction or expand the scope.',
|
|
@@ -548,6 +554,8 @@ export function apply(ctx, rawConfig) {
|
|
|
548
554
|
manager: value.manager,
|
|
549
555
|
worker: value.worker,
|
|
550
556
|
label: typeof value.label === 'string' ? value.label : '',
|
|
557
|
+
mode: value.mode === 'permanent' ? 'permanent' : 'temporary',
|
|
558
|
+
project: typeof value.project === 'string' ? value.project : '',
|
|
551
559
|
goal: typeof value.goal === 'string' ? value.goal : '',
|
|
552
560
|
status,
|
|
553
561
|
round: Number.isSafeInteger(value.round) && value.round >= 0 ? value.round : 0,
|
|
@@ -611,21 +619,21 @@ export function apply(ctx, rawConfig) {
|
|
|
611
619
|
function sectionText(context) {
|
|
612
620
|
const agentId = context?.agent?.id ?? context?.scope?.id
|
|
613
621
|
if (typeof agentId !== 'string') return ''
|
|
614
|
-
const managed =
|
|
622
|
+
const managed = usableManagerLinks(agentId)
|
|
615
623
|
if (managed.length > 0) {
|
|
616
624
|
const rows = managed.slice(0, 8).map((link) => L.managerRow({
|
|
617
625
|
label: link.label || (cfg.language === 'en' ? '(unnamed worker)' : '(未命名员工)'),
|
|
618
626
|
worker: link.worker,
|
|
619
627
|
round: link.round,
|
|
620
|
-
state: link.pending === null ? L.idle : L.waiting,
|
|
628
|
+
state: link.status !== ACTIVE ? L.finished : link.pending === null ? L.idle : L.waiting,
|
|
621
629
|
last: link.lastReport === null ? '' : L.statusLabel(link.lastReport.status),
|
|
622
630
|
}))
|
|
623
631
|
if (managed.length > 8) rows.push(L.moreWorkers(managed.length - 8))
|
|
624
|
-
return L.managerSection({ count: managed.length, rows, maxRounds: cfg.maxRounds })
|
|
632
|
+
return L.managerSection({ count: managed.length, rows, maxRounds: cfg.maxRounds, project: managerProjectName(agentId) })
|
|
625
633
|
}
|
|
626
|
-
const link =
|
|
634
|
+
const link = workerAssociation(agentId)
|
|
627
635
|
if (link === undefined) return ''
|
|
628
|
-
return L.workerSection({ manager: link.manager, round: link.round, pending: link.pending !== null })
|
|
636
|
+
return L.workerSection({ manager: link.manager, round: link.round, pending: link.pending !== null, project: link.project })
|
|
629
637
|
}
|
|
630
638
|
|
|
631
639
|
/** Render one dispatch message for a worker. */
|
|
@@ -836,6 +844,44 @@ export function apply(ctx, rawConfig) {
|
|
|
836
844
|
return linkId === undefined ? undefined : links.get(linkId)
|
|
837
845
|
}
|
|
838
846
|
|
|
847
|
+
/** The worker link a session still belongs to, including a finished permanent one. */
|
|
848
|
+
function workerAssociation(sessionId) {
|
|
849
|
+
const active = workerLink(sessionId)
|
|
850
|
+
if (active !== undefined) return active
|
|
851
|
+
for (const link of links.values()) {
|
|
852
|
+
if (link.worker === sessionId && link.mode === 'permanent') return link
|
|
853
|
+
}
|
|
854
|
+
return undefined
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/** Links a manager can still act on: active ones plus permanent associations. */
|
|
858
|
+
function usableManagerLinks(managerId) {
|
|
859
|
+
return managerLinks(managerId).filter((link) => link.status === ACTIVE || link.mode === 'permanent')
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
/** Whether a manager still has a usable worker association. */
|
|
863
|
+
function managerHasWork(managerId) {
|
|
864
|
+
return usableManagerLinks(managerId).length > 0
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/** The project name shared by one manager's links, or ''. */
|
|
868
|
+
function managerProjectName(managerId) {
|
|
869
|
+
for (const link of managerLinks(managerId)) {
|
|
870
|
+
if (typeof link.project === 'string' && link.project !== '') return link.project
|
|
871
|
+
}
|
|
872
|
+
return ''
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/** Rename the project shared by every link of one manager. */
|
|
876
|
+
async function renameProject(managerId, name) {
|
|
877
|
+
for (const link of managerLinks(managerId)) {
|
|
878
|
+
if (link.project === name) continue
|
|
879
|
+
link.project = name
|
|
880
|
+
link.updatedAt = Date.now()
|
|
881
|
+
await persist(link)
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
839
885
|
/** Index one link by its manager and (while active) its worker. */
|
|
840
886
|
function index(link) {
|
|
841
887
|
links.set(link.id, link)
|
|
@@ -928,20 +974,20 @@ export function apply(ctx, rawConfig) {
|
|
|
928
974
|
|
|
929
975
|
/** Resolve one of a manager's active workers by id, link id, or label. */
|
|
930
976
|
function resolveManagedLink(managerId, selector) {
|
|
931
|
-
const
|
|
932
|
-
if (
|
|
977
|
+
const candidates = usableManagerLinks(managerId)
|
|
978
|
+
if (candidates.length === 0) throw new CollabError('当前对话没有可用的员工协作;先用 collab_link 关联一个员工。')
|
|
933
979
|
const text = typeof selector === 'string' ? selector.trim() : ''
|
|
934
980
|
if (text === '') {
|
|
935
|
-
if (
|
|
936
|
-
throw new CollabError(`当前对话有 ${
|
|
981
|
+
if (candidates.length === 1) return candidates[0]
|
|
982
|
+
throw new CollabError(`当前对话有 ${candidates.length} 个员工,请用 worker 参数指定:\n${workerList(candidates)}`)
|
|
937
983
|
}
|
|
938
|
-
const exact =
|
|
984
|
+
const exact = candidates.find((link) => link.worker === text || link.id === text)
|
|
939
985
|
if (exact !== undefined) return exact
|
|
940
986
|
const needle = text.toLowerCase()
|
|
941
|
-
const matches =
|
|
987
|
+
const matches = candidates.filter((link) => typeof link.label === 'string' && link.label !== '' && link.label.toLowerCase().includes(needle))
|
|
942
988
|
if (matches.length === 1) return matches[0]
|
|
943
989
|
if (matches.length > 1) throw new CollabError(`"${text}" 匹配到多个员工,请用 sessionId 指定:\n${workerList(matches)}`)
|
|
944
|
-
throw new CollabError(`没有找到员工 "${text}"。当前员工:\n${workerList(
|
|
990
|
+
throw new CollabError(`没有找到员工 "${text}"。当前员工:\n${workerList(candidates)}`)
|
|
945
991
|
}
|
|
946
992
|
|
|
947
993
|
/** Global board: every link, active first, with the labels a human needs. */
|
|
@@ -968,6 +1014,8 @@ export function apply(ctx, rawConfig) {
|
|
|
968
1014
|
worker: link.worker,
|
|
969
1015
|
workerTitle: workerTitle ?? null,
|
|
970
1016
|
status: link.status,
|
|
1017
|
+
mode: link.mode,
|
|
1018
|
+
project: link.project || '',
|
|
971
1019
|
workerLive: workerAgent !== undefined,
|
|
972
1020
|
workerRunning: workerAgent !== undefined && workerAgent.status === 'running',
|
|
973
1021
|
managerRunning: managerAgent !== undefined && managerAgent.status === 'running',
|
|
@@ -1007,7 +1055,16 @@ export function apply(ctx, rawConfig) {
|
|
|
1007
1055
|
}
|
|
1008
1056
|
|
|
1009
1057
|
/** Send one round to the worker and record it as pending. */
|
|
1010
|
-
async function dispatchRound(link, task, acceptance, signal, force) {
|
|
1058
|
+
async function dispatchRound(link, task, acceptance, signal, force) {
|
|
1059
|
+
if (link.status !== ACTIVE) {
|
|
1060
|
+
if (link.mode === 'permanent' && link.status === DONE) {
|
|
1061
|
+
link.status = ACTIVE
|
|
1062
|
+
delete link.closedAt
|
|
1063
|
+
index(link)
|
|
1064
|
+
} else {
|
|
1065
|
+
throw new CollabError(`与该员工的协作已结束(${link.status}),不能继续派发。`)
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1011
1068
|
if (link.pending !== null && !force) {
|
|
1012
1069
|
throw new CollabError(`第 ${link.pending.round} 轮仍在等待该员工回报,不要重复派发;需要覆盖请传 force=true。`)
|
|
1013
1070
|
}
|
|
@@ -1298,7 +1355,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1298
1355
|
.filter((row) => query === '' || (row.title ?? '').toLowerCase().includes(query) || row.sessionId.toLowerCase().includes(query))
|
|
1299
1356
|
.slice(0, limit)
|
|
1300
1357
|
.map((row) => {
|
|
1301
|
-
const worker =
|
|
1358
|
+
const worker = workerAssociation(row.sessionId)
|
|
1302
1359
|
const managed = managerLinks(row.sessionId, true)
|
|
1303
1360
|
return {
|
|
1304
1361
|
sessionId: row.sessionId,
|
|
@@ -1316,7 +1373,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1316
1373
|
ok: true,
|
|
1317
1374
|
current: {
|
|
1318
1375
|
sessionId: agent.id,
|
|
1319
|
-
role:
|
|
1376
|
+
role: managerHasWork(agent.id) ? 'manager' : workerAssociation(agent.id) === undefined ? null : 'worker',
|
|
1320
1377
|
},
|
|
1321
1378
|
sessions,
|
|
1322
1379
|
note: sessions.length === 0
|
|
@@ -1329,12 +1386,14 @@ export function apply(ctx, rawConfig) {
|
|
|
1329
1386
|
toolExecutors.link = register({
|
|
1330
1387
|
name: 'collab_link',
|
|
1331
1388
|
description:
|
|
1332
|
-
'把当前对话与另一个对话关联:role=manager(默认)表示当前对话是项目经理、对方成为新的员工;一个项目经理可以关联多个员工。role=worker 表示当前对话成为对方的员工。peer 传 sessionId、标题关键词,或 "new"(新建一个员工对话)。',
|
|
1389
|
+
'把当前对话与另一个对话关联:role=manager(默认)表示当前对话是项目经理、对方成为新的员工;一个项目经理可以关联多个员工。role=worker 表示当前对话成为对方的员工。mode=temporary(默认,完成即解绑)或 permanent(一直关联直到人工解除)。peer 传 sessionId、标题关键词,或 "new"(新建一个员工对话)。',
|
|
1333
1390
|
parameters: {
|
|
1334
1391
|
type: 'object',
|
|
1335
1392
|
properties: {
|
|
1336
1393
|
peer: { type: 'string', description: 'sessionId、标题关键词,或 "new"。' },
|
|
1337
1394
|
role: { type: 'string', enum: ['manager', 'worker'], description: '当前对话的角色,默认 manager。' },
|
|
1395
|
+
mode: { type: 'string', enum: ['temporary', 'permanent'], description: '关联模式:temporary 完成后自动解绑(默认),permanent 保留到人工解除。' },
|
|
1396
|
+
project: { type: 'string', description: '可选:项目名。同一个项目经理的员工会归到同一个项目,不同项目经理的项目彼此独立。' },
|
|
1338
1397
|
goal: { type: 'string', description: '可选:项目总目标;不填时由项目经理在对话中掌握。' },
|
|
1339
1398
|
task: { type: 'string', description: '可选:关联成功后立即派发给该员工的第一轮任务。' },
|
|
1340
1399
|
acceptance: { type: 'string', description: '可选:第一轮任务的验收标准。' },
|
|
@@ -1346,14 +1405,18 @@ export function apply(ctx, rawConfig) {
|
|
|
1346
1405
|
const agent = requireAgent(exec)
|
|
1347
1406
|
const role = args?.role === 'worker' ? 'worker' : 'manager'
|
|
1348
1407
|
const managed = managerLinks(agent.id, true)
|
|
1349
|
-
const ownWorker =
|
|
1408
|
+
const ownWorker = workerAssociation(agent.id)
|
|
1409
|
+
if (workerLink(agent.id) !== undefined) {
|
|
1410
|
+
throw new CollabError(`当前对话已经是协作 ${ownWorker?.id ?? ''} 的员工,不能再加入其他协作;请先 collab_unlink。`)
|
|
1411
|
+
}
|
|
1350
1412
|
if (ownWorker !== undefined) {
|
|
1351
|
-
throw new CollabError(
|
|
1413
|
+
throw new CollabError(`当前对话已永久关联到协作 ${ownWorker.id}(已结束);请先 collab_unlink。`)
|
|
1352
1414
|
}
|
|
1353
1415
|
if (role === 'worker' && managed.length > 0) {
|
|
1354
1416
|
throw new CollabError(`当前对话正在管理 ${managed.length} 个员工,不能同时作为别人的员工。`)
|
|
1355
1417
|
}
|
|
1356
1418
|
const goal = typeof args?.goal === 'string' ? args.goal.trim() : ''
|
|
1419
|
+
const requestedProject = typeof args?.project === 'string' ? args.project.trim() : ''
|
|
1357
1420
|
let peerId
|
|
1358
1421
|
let peerTitle
|
|
1359
1422
|
const resolved = await resolvePeer(args?.peer, exec.signal)
|
|
@@ -1364,7 +1427,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1364
1427
|
peerTitle = resolved.title
|
|
1365
1428
|
}
|
|
1366
1429
|
if (peerId === agent.id) throw new CollabError('不能把对话与它自己关联。')
|
|
1367
|
-
if (
|
|
1430
|
+
if (workerAssociation(peerId) !== undefined) {
|
|
1368
1431
|
throw new CollabError(`目标对话 ${peerId} 已经是另一个协作的员工,请先解除那边的关联。`)
|
|
1369
1432
|
}
|
|
1370
1433
|
if (managerLinks(peerId, true).length > 0) {
|
|
@@ -1372,12 +1435,19 @@ export function apply(ctx, rawConfig) {
|
|
|
1372
1435
|
}
|
|
1373
1436
|
const manager = role === 'manager' ? agent.id : peerId
|
|
1374
1437
|
const worker = role === 'manager' ? peerId : agent.id
|
|
1438
|
+
let project = requestedProject || managerProjectName(manager)
|
|
1439
|
+
if (project === '') {
|
|
1440
|
+
const managerTitle = await titleOf(manager)
|
|
1441
|
+
if (typeof managerTitle === 'string') project = stripKnownPrefix(managerTitle)
|
|
1442
|
+
}
|
|
1375
1443
|
const link = {
|
|
1376
1444
|
v: 1,
|
|
1377
1445
|
id: `cp-${randomUUID().slice(0, 8)}`,
|
|
1378
1446
|
manager,
|
|
1379
1447
|
worker,
|
|
1380
1448
|
label: role === 'manager' ? (typeof peerTitle === 'string' ? peerTitle : '') : '',
|
|
1449
|
+
mode: args?.mode === 'permanent' ? 'permanent' : 'temporary',
|
|
1450
|
+
project,
|
|
1381
1451
|
goal,
|
|
1382
1452
|
status: ACTIVE,
|
|
1383
1453
|
round: 0,
|
|
@@ -1389,6 +1459,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1389
1459
|
}
|
|
1390
1460
|
index(link)
|
|
1391
1461
|
await persist(link)
|
|
1462
|
+
if (project !== '') await renameProject(manager, project)
|
|
1392
1463
|
await applyPrefix(manager, cfg.prefixManager)
|
|
1393
1464
|
await applyPrefix(worker, cfg.prefixWorker)
|
|
1394
1465
|
let receipt = null
|
|
@@ -1410,6 +1481,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1410
1481
|
ok: true,
|
|
1411
1482
|
linkId: link.id,
|
|
1412
1483
|
role,
|
|
1484
|
+
mode: link.mode,
|
|
1413
1485
|
manager,
|
|
1414
1486
|
worker: { sessionId: worker, title: workerTitle ?? null },
|
|
1415
1487
|
goal,
|
|
@@ -1417,8 +1489,8 @@ export function apply(ctx, rawConfig) {
|
|
|
1417
1489
|
receipt,
|
|
1418
1490
|
message: role === 'manager'
|
|
1419
1491
|
? (receipt === null
|
|
1420
|
-
? `已关联员工 ${worker}${managedNow > 1 ?
|
|
1421
|
-
: `已关联员工 ${worker}${managedNow > 1 ?
|
|
1492
|
+
? `已关联员工 ${worker}${link.mode === 'permanent' ? '(永久关联)' : '(临时关联,完成即解绑)'}${managedNow > 1 ? `,当前共 ${managedNow} 个员工` : ''}。用 collab_dispatch 派发任务。`
|
|
1493
|
+
: `已关联员工 ${worker}${link.mode === 'permanent' ? '(永久关联)' : '(临时关联,完成即解绑)'}${managedNow > 1 ? `,当前共 ${managedNow} 个员工` : ''},第一轮任务已派发。`)
|
|
1422
1494
|
: '协作已建立,你被设为员工角色;项目经理派发任务后会收到【协作任务】消息。',
|
|
1423
1495
|
}
|
|
1424
1496
|
},
|
|
@@ -1453,7 +1525,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1453
1525
|
message: `第 ${sent.round} 轮任务已派发给员工 ${link.worker}。该员工完成后,产出与反馈会自动作为用户消息回到本对话。`,
|
|
1454
1526
|
}
|
|
1455
1527
|
},
|
|
1456
|
-
when: ({ agent }) =>
|
|
1528
|
+
when: ({ agent }) => managerHasWork(agent.id),
|
|
1457
1529
|
})
|
|
1458
1530
|
|
|
1459
1531
|
toolExecutors.report = register({
|
|
@@ -1505,10 +1577,10 @@ export function apply(ctx, rawConfig) {
|
|
|
1505
1577
|
async execute(_args, exec) {
|
|
1506
1578
|
const agent = requireAgent(exec)
|
|
1507
1579
|
const managed = managerLinks(agent.id)
|
|
1508
|
-
const
|
|
1509
|
-
if (
|
|
1580
|
+
const visible = managed.filter((link) => link.status === ACTIVE || link.mode === 'permanent')
|
|
1581
|
+
if (visible.length > 0) {
|
|
1510
1582
|
const workers = []
|
|
1511
|
-
for (const link of
|
|
1583
|
+
for (const link of visible) {
|
|
1512
1584
|
const title = await titleOf(link.worker)
|
|
1513
1585
|
if (title !== undefined && title !== link.label) link.label = title
|
|
1514
1586
|
workers.push({
|
|
@@ -1516,6 +1588,8 @@ export function apply(ctx, rawConfig) {
|
|
|
1516
1588
|
worker: link.worker,
|
|
1517
1589
|
title: title ?? (link.label || null),
|
|
1518
1590
|
status: link.status,
|
|
1591
|
+
mode: link.mode,
|
|
1592
|
+
project: link.project || null,
|
|
1519
1593
|
round: link.round,
|
|
1520
1594
|
pending: link.pending === null
|
|
1521
1595
|
? null
|
|
@@ -1549,14 +1623,15 @@ export function apply(ctx, rawConfig) {
|
|
|
1549
1623
|
engine: ENGINE,
|
|
1550
1624
|
language: cfg.language,
|
|
1551
1625
|
role: 'manager',
|
|
1626
|
+
project: managerProjectName(agent.id) || null,
|
|
1552
1627
|
manager: { sessionId: agent.id, title: (await titleOf(agent.id)) ?? null },
|
|
1553
1628
|
maxRounds: cfg.maxRounds,
|
|
1554
|
-
activeCount:
|
|
1629
|
+
activeCount: visible.filter((link) => link.status === ACTIVE).length,
|
|
1555
1630
|
totalCount: managed.length,
|
|
1556
1631
|
workers,
|
|
1557
1632
|
}
|
|
1558
1633
|
}
|
|
1559
|
-
const link =
|
|
1634
|
+
const link = workerAssociation(agent.id)
|
|
1560
1635
|
if (link === undefined) {
|
|
1561
1636
|
return {
|
|
1562
1637
|
linked: false,
|
|
@@ -1576,6 +1651,8 @@ export function apply(ctx, rawConfig) {
|
|
|
1576
1651
|
language: cfg.language,
|
|
1577
1652
|
linkId: link.id,
|
|
1578
1653
|
role: 'worker',
|
|
1654
|
+
mode: link.mode,
|
|
1655
|
+
project: link.project || null,
|
|
1579
1656
|
manager: { sessionId: link.manager, title: managerTitle ?? null },
|
|
1580
1657
|
goal: link.goal || null,
|
|
1581
1658
|
status: link.status,
|
|
@@ -1660,13 +1737,34 @@ export function apply(ctx, rawConfig) {
|
|
|
1660
1737
|
message: '配置已应用;该员工下一轮会按新配置运行。',
|
|
1661
1738
|
}
|
|
1662
1739
|
},
|
|
1663
|
-
when: ({ agent }) =>
|
|
1740
|
+
when: ({ agent }) => managerHasWork(agent.id),
|
|
1741
|
+
})
|
|
1742
|
+
|
|
1743
|
+
toolExecutors.project = register({
|
|
1744
|
+
name: 'collab_project',
|
|
1745
|
+
description:
|
|
1746
|
+
'(仅项目经理)设置或修改当前项目名。项目名用于把该项目经理的员工归到同一个项目;不同项目经理的项目彼此独立。',
|
|
1747
|
+
parameters: {
|
|
1748
|
+
type: 'object',
|
|
1749
|
+
properties: { name: { type: 'string', description: '新的项目名,不能为空。' } },
|
|
1750
|
+
required: ['name'],
|
|
1751
|
+
},
|
|
1752
|
+
async execute(args, exec) {
|
|
1753
|
+
const agent = requireAgent(exec)
|
|
1754
|
+
const name = typeof args?.name === 'string' ? args.name.trim() : ''
|
|
1755
|
+
if (name === '') throw new CollabError('项目名不能为空。')
|
|
1756
|
+
const existing = managerLinks(agent.id)
|
|
1757
|
+
if (existing.length === 0) throw new CollabError('当前对话还没有关联员工;先 collab_link 再设置项目名。')
|
|
1758
|
+
await renameProject(agent.id, name)
|
|
1759
|
+
return { ok: true, project: name, workers: existing.length }
|
|
1760
|
+
},
|
|
1761
|
+
when: ({ agent }) => managerLinks(agent.id).length > 0,
|
|
1664
1762
|
})
|
|
1665
1763
|
|
|
1666
1764
|
toolExecutors.done = register({
|
|
1667
1765
|
name: 'collab_done',
|
|
1668
1766
|
description:
|
|
1669
|
-
'
|
|
1767
|
+
'(仅项目经理)宣布某个员工的项目完成:记录总结并结束本轮协作。临时关联会同时自动解绑;永久关联保留到 collab_unlink。有多个员工时用 worker 指定;all=true 结束全部进行中的员工。请在验收通过后调用。',
|
|
1670
1768
|
parameters: {
|
|
1671
1769
|
type: 'object',
|
|
1672
1770
|
properties: {
|
|
@@ -1693,8 +1791,10 @@ export function apply(ctx, rawConfig) {
|
|
|
1693
1791
|
throw new CollabError(`当前对话有 ${active.length} 个员工,请用 worker 指定或传 all=true:\n${workerList(active)}`)
|
|
1694
1792
|
}
|
|
1695
1793
|
const closed = []
|
|
1794
|
+
const removed = []
|
|
1696
1795
|
const notified = []
|
|
1697
1796
|
for (const link of targets) {
|
|
1797
|
+
const temporary = link.mode !== 'permanent'
|
|
1698
1798
|
link.status = DONE
|
|
1699
1799
|
link.pending = null
|
|
1700
1800
|
link.finalSummary = clip(summary, 4000)
|
|
@@ -1702,8 +1802,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1702
1802
|
link.updatedAt = Date.now()
|
|
1703
1803
|
index(link)
|
|
1704
1804
|
await persist(link)
|
|
1705
|
-
|
|
1706
|
-
closed.push({ linkId: link.id, worker: link.worker })
|
|
1805
|
+
closed.push({ linkId: link.id, worker: link.worker, mode: link.mode })
|
|
1707
1806
|
if (cfg.notifyWorkerOnDone) {
|
|
1708
1807
|
try {
|
|
1709
1808
|
await deliver(link.worker, doneText(link, link.finalSummary), `cp-${link.id}-done-to-worker`, 'queue', AbortSignal.timeout(PROMPT_TIMEOUT_MS))
|
|
@@ -1712,16 +1811,24 @@ export function apply(ctx, rawConfig) {
|
|
|
1712
1811
|
ctx.logger.warn(`collab-pair: notifying ${link.worker} of completion failed: ${String(error)}`)
|
|
1713
1812
|
}
|
|
1714
1813
|
}
|
|
1814
|
+
if (temporary) {
|
|
1815
|
+
await forget(link)
|
|
1816
|
+
await clearPrefix(link.worker)
|
|
1817
|
+
removed.push({ linkId: link.id, worker: link.worker })
|
|
1818
|
+
}
|
|
1715
1819
|
}
|
|
1716
|
-
if (managerLinks(agent.id
|
|
1820
|
+
if (managerLinks(agent.id).length === 0) await clearPrefix(agent.id)
|
|
1717
1821
|
return {
|
|
1718
1822
|
ok: true,
|
|
1719
1823
|
closed,
|
|
1824
|
+
removed,
|
|
1720
1825
|
workerNotified: notified,
|
|
1721
|
-
message:
|
|
1826
|
+
message: removed.length === 0
|
|
1827
|
+
? `已结束 ${closed.length} 个员工协作(永久关联保留,可继续派发或手动解除)。`
|
|
1828
|
+
: `已结束 ${closed.length} 个员工协作,其中 ${removed.length} 个临时关联已自动解绑。`,
|
|
1722
1829
|
}
|
|
1723
1830
|
},
|
|
1724
|
-
when: ({ agent }) =>
|
|
1831
|
+
when: ({ agent }) => managerHasWork(agent.id),
|
|
1725
1832
|
})
|
|
1726
1833
|
|
|
1727
1834
|
toolExecutors.unlink = register({
|
|
@@ -1739,7 +1846,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1739
1846
|
},
|
|
1740
1847
|
async execute(args, exec) {
|
|
1741
1848
|
const agent = requireAgent(exec)
|
|
1742
|
-
const ownWorker =
|
|
1849
|
+
const ownWorker = workerAssociation(agent.id)
|
|
1743
1850
|
if (ownWorker !== undefined) {
|
|
1744
1851
|
let notified = false
|
|
1745
1852
|
if (args?.notify === true) {
|
|
@@ -1755,20 +1862,20 @@ export function apply(ctx, rawConfig) {
|
|
|
1755
1862
|
const managerId = ownWorker.manager
|
|
1756
1863
|
await forget(ownWorker)
|
|
1757
1864
|
await clearPrefix(agent.id)
|
|
1758
|
-
if (managerLinks(managerId
|
|
1865
|
+
if (managerLinks(managerId).length === 0) await clearPrefix(managerId)
|
|
1759
1866
|
return { ok: true, removed: [{ linkId, worker: agent.id }], peerNotified: notified }
|
|
1760
1867
|
}
|
|
1761
|
-
const
|
|
1762
|
-
if (
|
|
1868
|
+
const candidates = usableManagerLinks(agent.id)
|
|
1869
|
+
if (candidates.length === 0) throw new CollabError('当前对话没有可解除的员工协作。')
|
|
1763
1870
|
let targets
|
|
1764
1871
|
if (args?.all === true) {
|
|
1765
|
-
targets =
|
|
1872
|
+
targets = candidates
|
|
1766
1873
|
} else if (typeof args?.worker === 'string' && args.worker.trim() !== '') {
|
|
1767
1874
|
targets = [resolveManagedLink(agent.id, args.worker)]
|
|
1768
|
-
} else if (
|
|
1769
|
-
targets = [
|
|
1875
|
+
} else if (candidates.length === 1) {
|
|
1876
|
+
targets = [candidates[0]]
|
|
1770
1877
|
} else {
|
|
1771
|
-
throw new CollabError(`当前对话有 ${
|
|
1878
|
+
throw new CollabError(`当前对话有 ${candidates.length} 个员工,请用 worker 指定或传 all=true:\n${workerList(candidates)}`)
|
|
1772
1879
|
}
|
|
1773
1880
|
const removed = []
|
|
1774
1881
|
let notified = 0
|
|
@@ -1786,10 +1893,10 @@ export function apply(ctx, rawConfig) {
|
|
|
1786
1893
|
await forget(link)
|
|
1787
1894
|
await clearPrefix(link.worker)
|
|
1788
1895
|
}
|
|
1789
|
-
if (managerLinks(agent.id
|
|
1896
|
+
if (managerLinks(agent.id).length === 0) await clearPrefix(agent.id)
|
|
1790
1897
|
return { ok: true, removed, peerNotified: notified > 0 }
|
|
1791
1898
|
},
|
|
1792
|
-
when: ({ agent }) =>
|
|
1899
|
+
when: ({ agent }) => managerHasWork(agent.id) || workerAssociation(agent.id) !== undefined,
|
|
1793
1900
|
})
|
|
1794
1901
|
}
|
|
1795
1902
|
|
|
@@ -1800,7 +1907,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1800
1907
|
|
|
1801
1908
|
/** Whether one session is an active worker. */
|
|
1802
1909
|
function isWorker(sessionId) {
|
|
1803
|
-
return
|
|
1910
|
+
return workerAssociation(sessionId) !== undefined
|
|
1804
1911
|
}
|
|
1805
1912
|
|
|
1806
1913
|
/** Require the calling agent. */
|
|
@@ -1834,15 +1941,16 @@ export function apply(ctx, rawConfig) {
|
|
|
1834
1941
|
link: 'link',
|
|
1835
1942
|
dispatch: 'dispatch',
|
|
1836
1943
|
configure: 'configure',
|
|
1944
|
+
project: 'project',
|
|
1837
1945
|
done: 'done',
|
|
1838
1946
|
unlink: 'unlink',
|
|
1839
1947
|
sessions: 'sessions',
|
|
1840
1948
|
}
|
|
1841
1949
|
ctx.commands.register({
|
|
1842
1950
|
name: 'collab',
|
|
1843
|
-
description: '
|
|
1951
|
+
description: '双对话协作:查看全部任务、关联员工、设置项目名、配置预设与语言、派发任务、收尾或解除。',
|
|
1844
1952
|
input: {
|
|
1845
|
-
hint: 'tasks | status | link --peer <id|new> | configure --preset <id> | language <zh|en> | dispatch --worker <id> --task ... | done --worker <id> --summary ... | unlink --worker <id>',
|
|
1953
|
+
hint: 'tasks | status | link --peer <id|new> | project --name <项目名> | configure --preset <id> | language <zh|en> | dispatch --worker <id> --task ... | done --worker <id> --summary ... | unlink --worker <id>',
|
|
1846
1954
|
},
|
|
1847
1955
|
handler: async (invocation) => {
|
|
1848
1956
|
try {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-collab-pair",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "For large projects: link
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "For large projects: link a project-manager conversation with one or more worker conversations (temporary links unbind when done, permanent links stay until unlinked), group managers and workers by project, dispatch each round from the manager instead of repeating prompts, relay results automatically, and keep unattended runs moving with a visual task board.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|