dsh-collab-pair 1.0.0 → 1.1.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 +175 -2
- package/client.js +53 -5
- package/cordis.patch.yml +4 -0
- package/index.js +431 -129
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,5 +1,158 @@
|
|
|
1
1
|
# dsh-collab-pair
|
|
2
2
|
|
|
3
|
+
> A DSH plugin for large projects: link one project-manager conversation to one or more worker conversations. Dispatch each round once from the manager instead of repeating prompts across conversations; results come back automatically, and unattended runs keep moving.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
dsh plugin add dsh-collab-pair
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or install `dsh-collab-pair` from the DSH plugin manager, refresh the page, and open **Settings → Collaboration pair**. The settings UI ships English and Chinese and follows the app language.
|
|
12
|
+
|
|
13
|
+
**The plugin only links conversations.** Goals, task breakdown, and acceptance criteria stay with the project manager; the plugin never asks for them again.
|
|
14
|
+
|
|
15
|
+
One manager can run several workers, each with its own round counter:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
Project manager (owns the goal, breakdown, acceptance)
|
|
19
|
+
│ collab_dispatch(worker="A") — round N
|
|
20
|
+
▼
|
|
21
|
+
Worker A / Worker B / … (execute the task, then collab_report)
|
|
22
|
+
│ the worker turn ends → the plugin captures report + final output
|
|
23
|
+
▼
|
|
24
|
+
Manager receives a collaboration report → next round for that worker, or collab_done
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Visual settings page
|
|
28
|
+
|
|
29
|
+
**Settings → Collaboration pair**, top to bottom:
|
|
30
|
+
|
|
31
|
+
1. **Working conversation** — the conversation to act on (defaults to the open one).
|
|
32
|
+
2. **Current conversation · <title>** — this conversation's own links and status first:
|
|
33
|
+
- Project manager: the workers it manages (state, round, current task, latest report, unlink) plus a form to link another worker.
|
|
34
|
+
- Worker: its manager, current task, state, latest report, and a "Leave" action.
|
|
35
|
+
- Not linked: the link form.
|
|
36
|
+
3. **All tasks** — a board across every collaboration. Each row shows the worker, its manager, round, **working state** (`Working` / `Waiting for report` / `Idle` / `Finished`), waiting time, current task, and latest report. Refresh re-reads it.
|
|
37
|
+
|
|
38
|
+
The header also has a **Message language** selector (中文 / English). It switches the generated collaboration messages; the page labels follow the app language.
|
|
39
|
+
|
|
40
|
+
The page only links, unlinks, and reports status. Goals, tasks, and acceptance stay in the manager conversation.
|
|
41
|
+
|
|
42
|
+
## Language
|
|
43
|
+
|
|
44
|
+
- The settings page follows the app language; English and Chinese ship in the package.
|
|
45
|
+
- Generated collaboration messages follow the `language` config (`zh` or `en`, default `zh`). Switch it in the page header (**Message language**) or with `/collab language en`. The command persists the config and reloads the plugin.
|
|
46
|
+
|
|
47
|
+
## Unattended runs
|
|
48
|
+
|
|
49
|
+
Once a round is dispatched, the worker finishing wakes the manager automatically; the settings page does not need to stay open. For long projects:
|
|
50
|
+
|
|
51
|
+
- `autoNudge` (default on) wakes an idle manager when a worker makes no progress for `nudgeAfterMinutes` (default 20), up to `maxNudges` times (default 3), then leaves it to a human.
|
|
52
|
+
- A failed relay to the manager is retried once after a minute.
|
|
53
|
+
- Links survive plugin reloads and DSH restarts; a cold session is resumed when it needs the next message.
|
|
54
|
+
|
|
55
|
+
Set `autoNudge: false` to disable reminders.
|
|
56
|
+
|
|
57
|
+
## Title prefixes
|
|
58
|
+
|
|
59
|
+
Linking adds a prefix to both conversations and removes it when the link ends (or the last worker finishes):
|
|
60
|
+
|
|
61
|
+
- Manager: `【项目经理】<title>`
|
|
62
|
+
- Worker: `【员工】<title>`
|
|
63
|
+
|
|
64
|
+
The prefix text is configurable and can be turned off.
|
|
65
|
+
|
|
66
|
+
## Quick start
|
|
67
|
+
|
|
68
|
+
1. Open the conversation that should manage the project and say:
|
|
69
|
+
|
|
70
|
+
> Link a worker. The goal is to finish XXX. Dispatch round one: …
|
|
71
|
+
|
|
72
|
+
The model calls `collab_link({ peer: "new" })` and `collab_dispatch({ task: "…" })`.
|
|
73
|
+
|
|
74
|
+
2. Link a second worker the same way. With several workers, dispatch with `worker`:
|
|
75
|
+
|
|
76
|
+
> Dispatch to worker B: … (worker="session-…")
|
|
77
|
+
|
|
78
|
+
3. Worker results come back automatically. Continue with `collab_dispatch`, or close that worker with `collab_done({ worker, summary })`.
|
|
79
|
+
|
|
80
|
+
For an existing conversation, call `collab_sessions` to get its id, then `collab_link({ peer: "<sessionId>" })`.
|
|
81
|
+
|
|
82
|
+
## Tools
|
|
83
|
+
|
|
84
|
+
| Tool | Role | Purpose |
|
|
85
|
+
| --- | --- | --- |
|
|
86
|
+
| `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 |
|
|
88
|
+
| `collab_dispatch` | manager | Dispatch one round; `worker` selects the worker (optional with a single worker), `acceptance` optional |
|
|
89
|
+
| `collab_report` | worker | Report `summary` / `status`(done\|partial\|blocked) / `details` / `next` |
|
|
90
|
+
| `collab_status` | anyone | A manager sees every worker's progress; a worker sees its manager and pending task |
|
|
91
|
+
| `collab_configure` | manager | Set a worker's agent preset or model; without arguments it lists available presets |
|
|
92
|
+
| `collab_done` | manager | Finish one worker (or `all=true`) |
|
|
93
|
+
| `collab_unlink` | both | Remove a link; a manager uses `worker` or `all`, a worker leaves its own |
|
|
94
|
+
|
|
95
|
+
## `/collab` command
|
|
96
|
+
|
|
97
|
+
The settings page uses it; it can also be typed manually:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
/collab tasks
|
|
101
|
+
/collab language en
|
|
102
|
+
/collab status
|
|
103
|
+
/collab link {"peer":"new"}
|
|
104
|
+
/collab link {"peer":"session-…"}
|
|
105
|
+
/collab configure {"worker":"session-…","preset":"ptc"}
|
|
106
|
+
/collab configure {"worker":"session-…","provider":"deepseek-account","model":"deepseek-flash"}
|
|
107
|
+
/collab dispatch {"worker":"session-…","task":"…","acceptance":"…"}
|
|
108
|
+
/collab done {"worker":"session-…","summary":"…"}
|
|
109
|
+
/collab done {"all":true,"summary":"…"}
|
|
110
|
+
/collab unlink {"worker":"session-…"}
|
|
111
|
+
/collab unlink {"all":true}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`--key value` flags are accepted too: `/collab link --peer new`. `/collab tasks` returns the board data (all links plus live state).
|
|
115
|
+
|
|
116
|
+
## Configuration
|
|
117
|
+
|
|
118
|
+
The `collab-pair` row in `cordis.patch.yml`:
|
|
119
|
+
|
|
120
|
+
```yaml
|
|
121
|
+
- id: collab-pair
|
|
122
|
+
name: 'dsh-collab-pair'
|
|
123
|
+
config:
|
|
124
|
+
maxRounds: 20 # rounds per worker
|
|
125
|
+
maxRelayChars: 12000 # max characters of the worker's final output in a relay
|
|
126
|
+
maxHistory: 20 # recent rounds kept per worker
|
|
127
|
+
notifyWorkerOnDone: true # tell the worker to stop when the link is finished
|
|
128
|
+
autoRelay: true # false records the report without delivering it
|
|
129
|
+
language: zh # generated message language: zh | en
|
|
130
|
+
autoNudge: true # wake an idle manager when a worker stalls
|
|
131
|
+
nudgeAfterMinutes: 20 # minutes of no progress before a reminder
|
|
132
|
+
maxNudges: 3 # reminders per link before leaving it to a human
|
|
133
|
+
addPrefix: true # add the title prefix to linked conversations
|
|
134
|
+
prefixManager: '【项目经理】'
|
|
135
|
+
prefixWorker: '【员工】'
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Persistence
|
|
139
|
+
|
|
140
|
+
One record per worker lives in `$DSH_HOME/storages/collab_pair.json` (storage-domain `collab_pair`, table `links`). Links survive plugin reloads and DSH restarts; without the storage service the plugin falls back to memory and `collab_status.storage` reports `memory`.
|
|
141
|
+
|
|
142
|
+
## Limits
|
|
143
|
+
|
|
144
|
+
- A worker conversation belongs to one collaboration at a time; a manager can own several workers.
|
|
145
|
+
- A conversation cannot be both manager and worker.
|
|
146
|
+
- Worker conversations need a configured model (new conversations inherit the deployment default).
|
|
147
|
+
- Relayed results arrive as user messages in the manager conversation, with a report header and round marker. The generated text follows `language`; tool descriptions and internal error messages are Chinese in this release.
|
|
148
|
+
- With a PTC preset the worker calls `collab_report` inside `run_code`; the plugin still reads the structured report.
|
|
149
|
+
- A new worker has no title until its first message; the prefix is applied once the title exists.
|
|
150
|
+
- The board is a snapshot on Refresh (working state comes from the agent status at that moment). It does not poll, which keeps command records out of the session log.
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
# 中文说明
|
|
155
|
+
|
|
3
156
|
> DSH 插件:一个项目经理对话管理多个员工对话,任务自动流转,并提供全部任务看板。
|
|
4
157
|
|
|
5
158
|
## 安装
|
|
@@ -8,7 +161,7 @@
|
|
|
8
161
|
dsh plugin add dsh-collab-pair
|
|
9
162
|
```
|
|
10
163
|
|
|
11
|
-
或在 DSH 的插件管理里用包名 `dsh-collab-pair` 安装。安装后刷新页面,在 **设置 → 双对话协作**
|
|
164
|
+
或在 DSH 的插件管理里用包名 `dsh-collab-pair` 安装。安装后刷新页面,在 **设置 → 双对话协作** 打开。界面中英文跟随应用语言。
|
|
12
165
|
|
|
13
166
|
**插件只做一件事:把员工对话关联到项目经理对话。** 目标、任务拆解、验收标准都由项目经理在对话里掌握,插件不重复收集。
|
|
14
167
|
|
|
@@ -37,6 +190,21 @@ dsh plugin add dsh-collab-pair
|
|
|
37
190
|
|
|
38
191
|
页面只做关联/解除和查看,不代填目标、任务、验收——这些交给项目经理对话。
|
|
39
192
|
|
|
193
|
+
## 中英文
|
|
194
|
+
|
|
195
|
+
- 设置页跟随应用语言,包内自带中文和英文。
|
|
196
|
+
- 对话里生成的消息由配置 `language` 决定(`zh` / `en`,默认 `zh`)。可在页面顶部「对话消息语言」切换,或用 `/collab language en`;命令会保存配置并重载插件。
|
|
197
|
+
|
|
198
|
+
## 挂机运行
|
|
199
|
+
|
|
200
|
+
派发一轮后,员工完成会自动唤醒项目经理,设置页不需要一直开着。长时间项目还有:
|
|
201
|
+
|
|
202
|
+
- `autoNudge`(默认开启):员工长时间无推进时唤醒空闲的项目经理,间隔 `nudgeAfterMinutes`(默认 20 分钟),最多 `maxNudges` 次(默认 3),之后留给人工处理。
|
|
203
|
+
- 回传项目经理失败会在 1 分钟后自动重试一次。
|
|
204
|
+
- 关联在插件重载、DSH 重启后自动恢复;需要下一条消息时会恢复冷会话。
|
|
205
|
+
|
|
206
|
+
不需要提醒时设 `autoNudge: false`。
|
|
207
|
+
|
|
40
208
|
## 标题前缀
|
|
41
209
|
|
|
42
210
|
关联时自动给两个对话加前缀,解除(或最后一个员工结束时)自动去掉:
|
|
@@ -77,6 +245,7 @@ dsh plugin add dsh-collab-pair
|
|
|
77
245
|
|
|
78
246
|
```
|
|
79
247
|
/collab tasks
|
|
248
|
+
/collab language en
|
|
80
249
|
/collab status
|
|
81
250
|
/collab link {"peer":"new"}
|
|
82
251
|
/collab link {"peer":"session-…"}
|
|
@@ -104,6 +273,10 @@ dsh plugin add dsh-collab-pair
|
|
|
104
273
|
maxHistory: 20 # 每个员工保留的最近轮次
|
|
105
274
|
notifyWorkerOnDone: true # done 时通知员工停止
|
|
106
275
|
autoRelay: true # false 时只记录、不自动投递
|
|
276
|
+
language: zh # 生成消息的语言:zh / en
|
|
277
|
+
autoNudge: true # 员工停滞时唤醒空闲的项目经理
|
|
278
|
+
nudgeAfterMinutes: 20 # 多久无推进后提醒(分钟)
|
|
279
|
+
maxNudges: 3 # 每条关联最多提醒几次
|
|
107
280
|
addPrefix: true # 是否给关联对话加标题前缀
|
|
108
281
|
prefixManager: '【项目经理】'
|
|
109
282
|
prefixWorker: '【员工】'
|
|
@@ -118,7 +291,7 @@ dsh plugin add dsh-collab-pair
|
|
|
118
291
|
- 员工对话同时只能属于一个协作;项目经理可以关联多个员工。
|
|
119
292
|
- 一个对话不能同时是项目经理和员工。
|
|
120
293
|
- 员工对话需要已配置模型(新建对话继承部署默认模型)。
|
|
121
|
-
-
|
|
294
|
+
- 回传以用户消息形式进入项目经理对话(带【协作回报】标题与轮次标记)。生成文本跟随 `language`;工具描述与内部错误信息本版本仍为中文。
|
|
122
295
|
- 员工用 PTC 预设时 `collab_report` 会在 `run_code` 里调用,插件仍能读到结构化汇报。
|
|
123
296
|
- 新建员工在产生第一条消息前没有标题,前缀会在它第一轮结束拿到标题后补上。
|
|
124
297
|
- 看板是点「刷新」时的快照(`工作中`/`等待回报` 来自当时的 agent 状态),不做轮询,避免往会话日志里反复写命令记录。
|
package/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
window.__ModuleLoader__.load({
|
|
2
|
-
id: '
|
|
2
|
+
id: '@local/collab-pair',
|
|
3
3
|
factory(require) {
|
|
4
4
|
const React = require('react')
|
|
5
5
|
const h = React.createElement
|
|
@@ -9,9 +9,13 @@ window.__ModuleLoader__.load({
|
|
|
9
9
|
zh: {
|
|
10
10
|
nav: '双对话协作',
|
|
11
11
|
title: '双对话协作',
|
|
12
|
-
intro: '
|
|
12
|
+
intro: '做大项目时,不必再反复把同一套提示词分别发给多个对话:关联一次,之后每轮都由项目经理派发,员工产出自动回传;长时间挂机也能自动推进。插件只负责关联与推进,目标、任务和验收仍由项目经理掌握。',
|
|
13
13
|
workSession: '工作会话',
|
|
14
14
|
workSessionHint: '选择要操作的对话。建立关联时,它就是项目经理对话。',
|
|
15
|
+
messageLanguage: '对话消息语言',
|
|
16
|
+
langZh: '中文',
|
|
17
|
+
langEn: 'English',
|
|
18
|
+
languageChanged: '消息语言已切换,正在重新加载…',
|
|
15
19
|
noSessions: '还没有可用的对话,请先在左侧新建一个对话。',
|
|
16
20
|
loading: '读取中…',
|
|
17
21
|
refresh: '刷新',
|
|
@@ -42,6 +46,7 @@ window.__ModuleLoader__.load({
|
|
|
42
46
|
finished: '已结束',
|
|
43
47
|
noWorkers: '还没有关联员工。',
|
|
44
48
|
lastReport: '最近回报',
|
|
49
|
+
reminder: '已提醒 {count}/{max}',
|
|
45
50
|
unlink: '解除',
|
|
46
51
|
confirmUnlink: '解除与该员工的协作关联?',
|
|
47
52
|
removeDone: '已解除关联。',
|
|
@@ -57,9 +62,13 @@ window.__ModuleLoader__.load({
|
|
|
57
62
|
en: {
|
|
58
63
|
nav: 'Collaboration pair',
|
|
59
64
|
title: 'Collaboration pair',
|
|
60
|
-
intro: '
|
|
65
|
+
intro: 'On large projects you no longer repeat the same prompts across conversations: link once, then the manager dispatches every round and worker results come back automatically, with unattended runs kept moving. The plugin only links and drives; the goal, tasks, and acceptance stay with the manager.',
|
|
61
66
|
workSession: 'Working conversation',
|
|
62
67
|
workSessionHint: 'The conversation to act on. When you create a link, it becomes the project manager.',
|
|
68
|
+
messageLanguage: 'Message language',
|
|
69
|
+
langZh: '中文',
|
|
70
|
+
langEn: 'English',
|
|
71
|
+
languageChanged: 'Message language changed; reloading…',
|
|
63
72
|
noSessions: 'No conversation is available yet. Create one in the sidebar first.',
|
|
64
73
|
loading: 'Loading…',
|
|
65
74
|
refresh: 'Refresh',
|
|
@@ -90,6 +99,7 @@ window.__ModuleLoader__.load({
|
|
|
90
99
|
finished: 'Finished',
|
|
91
100
|
noWorkers: 'No worker linked yet.',
|
|
92
101
|
lastReport: 'Latest report',
|
|
102
|
+
reminder: 'reminder {count}/{max}',
|
|
93
103
|
unlink: 'Unlink',
|
|
94
104
|
confirmUnlink: 'Remove the link to this worker?',
|
|
95
105
|
removeDone: 'Link removed.',
|
|
@@ -257,6 +267,29 @@ window.__ModuleLoader__.load({
|
|
|
257
267
|
}
|
|
258
268
|
}
|
|
259
269
|
|
|
270
|
+
const changeLanguage = async (code) => {
|
|
271
|
+
if (workId === undefined) return
|
|
272
|
+
setBusy(true)
|
|
273
|
+
setError(null)
|
|
274
|
+
setNotice(t('languageChanged'))
|
|
275
|
+
try {
|
|
276
|
+
await runCommand(commandsRef.current, workId, `/collab language ${JSON.stringify({ language: code })}`)
|
|
277
|
+
} catch {
|
|
278
|
+
// A config write restarts the Host plugin; the pending call may reject.
|
|
279
|
+
}
|
|
280
|
+
await new Promise((resolve) => setTimeout(resolve, 1200))
|
|
281
|
+
try {
|
|
282
|
+
const next = await loadBoard(workId)
|
|
283
|
+
if (next === null || next === undefined || next.language !== code) {
|
|
284
|
+
setError('语言未保存:请手动修改 cordis.patch.yml 里的 language。')
|
|
285
|
+
}
|
|
286
|
+
} catch (cause) {
|
|
287
|
+
setError(cause instanceof Error ? cause.message : String(cause))
|
|
288
|
+
} finally {
|
|
289
|
+
setBusy(false)
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
260
293
|
const linkWorker = () => {
|
|
261
294
|
void act(`/collab link ${JSON.stringify({ peer })}`, t('linkDone'))
|
|
262
295
|
}
|
|
@@ -272,6 +305,7 @@ window.__ModuleLoader__.load({
|
|
|
272
305
|
}
|
|
273
306
|
|
|
274
307
|
const links = board !== null && Array.isArray(board.links) ? board.links : []
|
|
308
|
+
const messageLang = board !== null && board.language === 'en' ? 'en' : 'zh'
|
|
275
309
|
const activeLinks = links.filter((link) => link.status === 'active')
|
|
276
310
|
const managed = workId === undefined ? [] : activeLinks.filter((link) => link.manager === workId)
|
|
277
311
|
const mine = workId === undefined ? undefined : activeLinks.find((link) => link.worker === workId)
|
|
@@ -320,6 +354,16 @@ window.__ModuleLoader__.load({
|
|
|
320
354
|
),
|
|
321
355
|
h('div', { style: S.hint }, t('workSessionHint')),
|
|
322
356
|
h('div', { style: S.mono }, workId ?? ''),
|
|
357
|
+
h('label', { style: S.label }, t('messageLanguage'),
|
|
358
|
+
h('select', {
|
|
359
|
+
style: S.input,
|
|
360
|
+
value: board !== null && board.language === 'en' ? 'en' : 'zh',
|
|
361
|
+
disabled: busy || workId === undefined,
|
|
362
|
+
onChange: (event) => void changeLanguage(event.target.value),
|
|
363
|
+
},
|
|
364
|
+
h('option', { value: 'zh' }, t('langZh')),
|
|
365
|
+
h('option', { value: 'en' }, t('langEn'))),
|
|
366
|
+
),
|
|
323
367
|
h('div', { style: S.row },
|
|
324
368
|
h('button', { type: 'button', style: S.secondary, disabled: busy || workId === undefined, onClick: () => void refresh() }, t('refresh')),
|
|
325
369
|
busy ? h('span', { style: S.muted }, t('busy')) : null,
|
|
@@ -336,6 +380,10 @@ window.__ModuleLoader__.load({
|
|
|
336
380
|
|
|
337
381
|
const stateBadge = (state) => h('span', { style: { ...S.badge, color: state.color } }, state.label)
|
|
338
382
|
|
|
383
|
+
const reminderText = (link) => (link.nudges > 0
|
|
384
|
+
? ` · ${t('reminder', { count: link.nudges, max: board !== null && typeof board.maxNudges === 'number' ? board.maxNudges : 3 })}`
|
|
385
|
+
: '')
|
|
386
|
+
|
|
339
387
|
const taskRow = (link) => {
|
|
340
388
|
const state = stateOf(link)
|
|
341
389
|
return h('div', { key: link.linkId, style: S.taskRow },
|
|
@@ -343,7 +391,7 @@ window.__ModuleLoader__.load({
|
|
|
343
391
|
h('div', { style: S.taskTitle }, link.workerTitle || link.worker),
|
|
344
392
|
h('div', { style: S.mono }, link.worker),
|
|
345
393
|
h('div', { style: S.muted },
|
|
346
|
-
`${link.managerTitle || link.manager} · ${roundText(link)}`,
|
|
394
|
+
`${link.managerTitle || link.manager} · ${roundText(link)}${reminderText(link)}`,
|
|
347
395
|
),
|
|
348
396
|
link.pending === null || link.pending === undefined
|
|
349
397
|
? null
|
|
@@ -377,7 +425,7 @@ window.__ModuleLoader__.load({
|
|
|
377
425
|
h('div', { style: S.workerMain },
|
|
378
426
|
h('div', { style: S.workerName }, link.workerTitle || link.worker),
|
|
379
427
|
h('div', { style: S.mono }, link.worker),
|
|
380
|
-
h('div', { style: S.muted }, roundText(link)),
|
|
428
|
+
h('div', { style: S.muted }, `${roundText(link)}${reminderText(link)}`),
|
|
381
429
|
link.pending === null || link.pending === undefined
|
|
382
430
|
? null
|
|
383
431
|
: h('p', { style: S.taskText }, link.pending.task),
|
package/cordis.patch.yml
CHANGED
package/index.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* opened through the optional `storageDomain` service, with an in-memory
|
|
15
15
|
* fallback when it is unavailable.
|
|
16
16
|
*
|
|
17
|
-
* @module
|
|
17
|
+
* @module @local/collab-pair
|
|
18
18
|
*/
|
|
19
19
|
import { randomUUID } from 'node:crypto'
|
|
20
20
|
|
|
@@ -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.0
|
|
35
|
+
const ENGINE = 'collab-pair/1.1.0'
|
|
36
36
|
|
|
37
37
|
/** A recoverable failure whose message is meant for the model. */
|
|
38
38
|
class CollabError extends Error {}
|
|
@@ -54,6 +54,10 @@ function resolveConfig(raw) {
|
|
|
54
54
|
addPrefix: value.addPrefix !== false,
|
|
55
55
|
prefixManager: prefixText(value.prefixManager, '【项目经理】'),
|
|
56
56
|
prefixWorker: prefixText(value.prefixWorker, '【员工】'),
|
|
57
|
+
language: value.language === 'en' ? 'en' : 'zh',
|
|
58
|
+
autoNudge: value.autoNudge !== false,
|
|
59
|
+
nudgeAfterMinutes: clampInt(value.nudgeAfterMinutes, 5, 1440, 20),
|
|
60
|
+
maxNudges: clampInt(value.maxNudges, 1, 20, 3),
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
|
|
@@ -92,26 +96,6 @@ function messageText(message) {
|
|
|
92
96
|
return parts.join('\n').trim()
|
|
93
97
|
}
|
|
94
98
|
|
|
95
|
-
/** Human description of a turn end reason. */
|
|
96
|
-
function reasonText(reason) {
|
|
97
|
-
const kind = reason?.kind
|
|
98
|
-
if (kind === 'completed') return '正常结束'
|
|
99
|
-
if (kind === 'blocked') return '等待输入(blocked)'
|
|
100
|
-
if (kind === 'max-tokens') return '达到输出上限'
|
|
101
|
-
if (kind === 'interrupted') return '被中断'
|
|
102
|
-
if (kind === 'forked') return '会话已分叉'
|
|
103
|
-
if (kind === 'aborted') {
|
|
104
|
-
const cause = reason?.reason?.kind
|
|
105
|
-
if (cause === 'user') return '被用户中止'
|
|
106
|
-
if (cause === 'parent') return '被父级中止'
|
|
107
|
-
if (cause === 'disposed') return '会话被关闭'
|
|
108
|
-
if (cause === 'hook') return '被钩子中止'
|
|
109
|
-
return '被中止'
|
|
110
|
-
}
|
|
111
|
-
if (kind === 'error') return `出错:${reason?.error?.message ?? '未知错误'}`
|
|
112
|
-
return typeof kind === 'string' ? kind : '未知'
|
|
113
|
-
}
|
|
114
|
-
|
|
115
99
|
/** Best-effort readable delivery failure. */
|
|
116
100
|
function deliveryFailure(error) {
|
|
117
101
|
const code = error?.code ?? error?.details?.code
|
|
@@ -152,6 +136,7 @@ function parseCommandBody(rawInput) {
|
|
|
152
136
|
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) throw new CollabError('参数必须是 JSON 对象。')
|
|
153
137
|
return { action, args: parsed }
|
|
154
138
|
}
|
|
139
|
+
if (!rest.startsWith('--')) return { action, args: { value: rest } }
|
|
155
140
|
return { action, args: parseFlags(rest) }
|
|
156
141
|
}
|
|
157
142
|
|
|
@@ -190,8 +175,283 @@ function parseFlags(text) {
|
|
|
190
175
|
return args
|
|
191
176
|
}
|
|
192
177
|
|
|
178
|
+
/** Localized collaboration messages. `language` in the plugin config selects one. */
|
|
179
|
+
const LANGUAGES = {
|
|
180
|
+
zh: {
|
|
181
|
+
idle: '空闲',
|
|
182
|
+
waiting: '等待回报',
|
|
183
|
+
statusLabel(status) {
|
|
184
|
+
if (status === 'done') return '完成'
|
|
185
|
+
if (status === 'partial') return '部分完成'
|
|
186
|
+
if (status === 'blocked') return '受阻,需要决策'
|
|
187
|
+
if (status === 'unreported') return '未显式汇报'
|
|
188
|
+
return '未知'
|
|
189
|
+
},
|
|
190
|
+
reasonText(reason) {
|
|
191
|
+
const kind = reason?.kind
|
|
192
|
+
if (kind === 'completed') return '正常结束'
|
|
193
|
+
if (kind === 'blocked') return '等待输入(blocked)'
|
|
194
|
+
if (kind === 'max-tokens') return '达到输出上限'
|
|
195
|
+
if (kind === 'interrupted') return '被中断'
|
|
196
|
+
if (kind === 'forked') return '会话已分叉'
|
|
197
|
+
if (kind === 'aborted') {
|
|
198
|
+
const cause = reason?.reason?.kind
|
|
199
|
+
if (cause === 'user') return '被用户中止'
|
|
200
|
+
if (cause === 'parent') return '被父级中止'
|
|
201
|
+
if (cause === 'disposed') return '会话被关闭'
|
|
202
|
+
if (cause === 'hook') return '被钩子中止'
|
|
203
|
+
return '被中止'
|
|
204
|
+
}
|
|
205
|
+
if (kind === 'error') return `出错:${reason?.error?.message ?? '未知错误'}`
|
|
206
|
+
return typeof kind === 'string' ? kind : '未知'
|
|
207
|
+
},
|
|
208
|
+
managerRow({ label, worker, round, state, last }) {
|
|
209
|
+
return `- ${label}(${worker}):第 ${round} 轮 · ${state}${last === '' ? '' : ` · 最近:${last}`}`
|
|
210
|
+
},
|
|
211
|
+
moreWorkers(count) {
|
|
212
|
+
return `- …另有 ${count} 个员工,用 collab_status 查看`
|
|
213
|
+
},
|
|
214
|
+
managerSection({ count, rows, maxRounds }) {
|
|
215
|
+
return [
|
|
216
|
+
'## 双对话协作 · 你是项目经理',
|
|
217
|
+
`你正在协调 ${count} 个员工对话;项目目标、任务拆解与验收标准由你在对话中掌握。`,
|
|
218
|
+
'员工:',
|
|
219
|
+
...rows,
|
|
220
|
+
'',
|
|
221
|
+
'规则:',
|
|
222
|
+
'- 用 `collab_dispatch` 派发任务;有多个员工时用 `worker` 指定员工(sessionId 或标题),只有一个时可省略。',
|
|
223
|
+
'- 需要调整某个员工的 agent 预设或模型时,用 `collab_configure`(worker 指定员工)。',
|
|
224
|
+
'- 收到以【协作回报】开头的消息后,继续派发,或对该员工调用 `collab_done`;`collab_status` 查看全部进度。',
|
|
225
|
+
'- 除非用户明确要求,不要自己执行员工的交付任务;你负责拆解、验收和决定下一步。',
|
|
226
|
+
`- 每个员工最多 ${maxRounds} 轮。`,
|
|
227
|
+
].join('\n')
|
|
228
|
+
},
|
|
229
|
+
workerSection({ manager, round, pending }) {
|
|
230
|
+
return [
|
|
231
|
+
'## 双对话协作 · 你是员工',
|
|
232
|
+
`项目经理对话:${manager}`,
|
|
233
|
+
`进度:第 ${round} 轮${pending ? ',待你完成本轮任务' : ''}`,
|
|
234
|
+
'你负责执行项目经理派发的任务,并如实回报结果;项目目标与验收标准以派发消息为准,不要改变大方向或扩大范围。',
|
|
235
|
+
'',
|
|
236
|
+
'规则:',
|
|
237
|
+
'- 严格按本对话里最近一条【协作任务】执行。',
|
|
238
|
+
'- 完成后调用 `collab_report` 汇报:summary(交付物/结论)、status(done/partial/blocked)、details、next,然后结束本轮回复。',
|
|
239
|
+
'- 你的最终回复会连同汇报一起自动回传给项目经理;遇到阻塞用 blocked 写清需要什么决策。',
|
|
240
|
+
'- 项目经理可能连续派发多轮任务,每轮都按上述流程执行。',
|
|
241
|
+
].join('\n')
|
|
242
|
+
},
|
|
243
|
+
dispatch({ round, goal, task, acceptance, marker }) {
|
|
244
|
+
const lines = [`【协作任务 · 第 ${round} 轮】`, '']
|
|
245
|
+
if (goal) lines.push(`项目目标:${goal}`, '')
|
|
246
|
+
lines.push(
|
|
247
|
+
'—— 本轮任务 ——',
|
|
248
|
+
task,
|
|
249
|
+
'',
|
|
250
|
+
'—— 验收标准 ——',
|
|
251
|
+
acceptance || '(未指定;按任务目标自行检查交付完整性)',
|
|
252
|
+
'',
|
|
253
|
+
'—— 交付要求 ——',
|
|
254
|
+
'1. 直接执行本轮任务,不要改变项目大方向,也不要扩大到任务之外。',
|
|
255
|
+
'2. 完成后调用 collab_report 汇报:summary / status(done 完成、partial 部分完成、blocked 受阻需决策)/ details / next。',
|
|
256
|
+
'3. 汇报后结束本轮回复;你的最终回复会作为「产出与反馈」自动回传给项目经理。',
|
|
257
|
+
marker,
|
|
258
|
+
)
|
|
259
|
+
return lines.join('\n')
|
|
260
|
+
},
|
|
261
|
+
report({ round, workerTitle, worker, report, reason, finalText, maxRounds, nextRound, marker }) {
|
|
262
|
+
const status = report === undefined ? this.statusLabel('unreported') : this.statusLabel(report.status)
|
|
263
|
+
const lines = [
|
|
264
|
+
`【协作回报 · 第 ${round} 轮】`,
|
|
265
|
+
`来自员工对话:${workerTitle || '(未命名对话)'}(${worker})`,
|
|
266
|
+
`本轮状态:${status}`,
|
|
267
|
+
`结束原因:${this.reasonText(reason)}`,
|
|
268
|
+
'',
|
|
269
|
+
]
|
|
270
|
+
if (report !== undefined) {
|
|
271
|
+
lines.push('—— 员工汇报 ——', report.summary)
|
|
272
|
+
if (report.details) lines.push('', '细节:', report.details)
|
|
273
|
+
if (report.next) lines.push('', `员工建议:${report.next}`)
|
|
274
|
+
lines.push('')
|
|
275
|
+
}
|
|
276
|
+
lines.push(
|
|
277
|
+
'—— 员工最终产出 ——',
|
|
278
|
+
finalText || (report === undefined
|
|
279
|
+
? '(本轮没有可读取的文本产出,可打开员工对话查看完整过程)'
|
|
280
|
+
: '(员工本轮没有额外文字总结,以上汇报即为其产出。)'),
|
|
281
|
+
'',
|
|
282
|
+
)
|
|
283
|
+
if (round >= maxRounds) lines.push(`⚠ 该员工已达到配置的最大轮次 ${maxRounds},无法再派发新一轮;请验收成果后调用 collab_done 收尾。`, '')
|
|
284
|
+
lines.push(
|
|
285
|
+
'—— 下一步 ——',
|
|
286
|
+
'请以项目经理身份审阅本轮结果:',
|
|
287
|
+
`- 需要继续:调用 collab_dispatch 下发第 ${nextRound} 轮任务,worker="${worker}"(可附验收标准)。`,
|
|
288
|
+
`- 该员工已完成:调用 collab_done,worker="${worker}",形成总结并收尾。`,
|
|
289
|
+
`- 需要了解过程细节:可打开员工对话 ${worker} 查看。`,
|
|
290
|
+
marker,
|
|
291
|
+
)
|
|
292
|
+
return lines.join('\n')
|
|
293
|
+
},
|
|
294
|
+
done({ summary, marker }) {
|
|
295
|
+
return [
|
|
296
|
+
'【协作结束】',
|
|
297
|
+
'项目经理已确认本项目完成,本轮协作到此结束。',
|
|
298
|
+
'',
|
|
299
|
+
`项目总结:${summary || '(无)'}`,
|
|
300
|
+
'',
|
|
301
|
+
'不需要再执行新的任务,也不要再调用协作工具;如果手上还有未完成的工作,请停止并简要说明当前状态。',
|
|
302
|
+
marker,
|
|
303
|
+
].join('\n')
|
|
304
|
+
},
|
|
305
|
+
nudge({ worker, minutes, attempt, max }) {
|
|
306
|
+
return [
|
|
307
|
+
'【协作推进提醒】',
|
|
308
|
+
`员工 ${worker} 目前空闲,已经 ${minutes} 分钟没有推进(第 ${attempt}/${max} 次提醒)。`,
|
|
309
|
+
'',
|
|
310
|
+
'请继续推进:调用 `collab_dispatch` 派发下一轮,或调用 `collab_done` 对该员工收尾。',
|
|
311
|
+
'如果项目需要暂停,请告知用户并说明原因。',
|
|
312
|
+
].join('\n')
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
en: {
|
|
316
|
+
idle: 'idle',
|
|
317
|
+
waiting: 'waiting for report',
|
|
318
|
+
statusLabel(status) {
|
|
319
|
+
if (status === 'done') return 'done'
|
|
320
|
+
if (status === 'partial') return 'partially done'
|
|
321
|
+
if (status === 'blocked') return 'blocked, needs a decision'
|
|
322
|
+
if (status === 'unreported') return 'no explicit report'
|
|
323
|
+
return 'unknown'
|
|
324
|
+
},
|
|
325
|
+
reasonText(reason) {
|
|
326
|
+
const kind = reason?.kind
|
|
327
|
+
if (kind === 'completed') return 'completed'
|
|
328
|
+
if (kind === 'blocked') return 'blocked, waiting for input'
|
|
329
|
+
if (kind === 'max-tokens') return 'output limit reached'
|
|
330
|
+
if (kind === 'interrupted') return 'interrupted'
|
|
331
|
+
if (kind === 'forked') return 'conversation forked'
|
|
332
|
+
if (kind === 'aborted') {
|
|
333
|
+
const cause = reason?.reason?.kind
|
|
334
|
+
if (cause === 'user') return 'stopped by the user'
|
|
335
|
+
if (cause === 'parent') return 'stopped by the parent'
|
|
336
|
+
if (cause === 'disposed') return 'conversation closed'
|
|
337
|
+
if (cause === 'hook') return 'stopped by a hook'
|
|
338
|
+
return 'aborted'
|
|
339
|
+
}
|
|
340
|
+
if (kind === 'error') return `error: ${reason?.error?.message ?? 'unknown'}`
|
|
341
|
+
return typeof kind === 'string' ? kind : 'unknown'
|
|
342
|
+
},
|
|
343
|
+
managerRow({ label, worker, round, state, last }) {
|
|
344
|
+
return `- ${label} (${worker}): round ${round} · ${state}${last === '' ? '' : ` · latest: ${last}`}`
|
|
345
|
+
},
|
|
346
|
+
moreWorkers(count) {
|
|
347
|
+
return `- …and ${count} more workers; use collab_status to see all`
|
|
348
|
+
},
|
|
349
|
+
managerSection({ count, rows, maxRounds }) {
|
|
350
|
+
return [
|
|
351
|
+
'## Collaboration pair · You are the project manager',
|
|
352
|
+
`You coordinate ${count} worker conversations. You own the project goal, the task breakdown, and the acceptance criteria.`,
|
|
353
|
+
'Workers:',
|
|
354
|
+
...rows,
|
|
355
|
+
'',
|
|
356
|
+
'Rules:',
|
|
357
|
+
'- Dispatch a round with `collab_dispatch`; when several workers exist, select one with `worker` (session id or title). With a single worker you may omit it.',
|
|
358
|
+
'- To change a worker\'s agent preset or model, use `collab_configure` (select the worker with `worker`).',
|
|
359
|
+
'- When a message starting with [Collaboration report] arrives, dispatch the next round or call `collab_done` for that worker; `collab_status` shows every worker.',
|
|
360
|
+
'- Unless the user explicitly asks, do not do the workers\' delivery work yourself; you break down, review, and decide.',
|
|
361
|
+
`- At most ${maxRounds} rounds per worker.`,
|
|
362
|
+
].join('\n')
|
|
363
|
+
},
|
|
364
|
+
workerSection({ manager, round, pending }) {
|
|
365
|
+
return [
|
|
366
|
+
'## Collaboration pair · You are a worker',
|
|
367
|
+
`Manager conversation: ${manager}`,
|
|
368
|
+
`Progress: round ${round}${pending ? ', with a task waiting for you' : ''}`,
|
|
369
|
+
'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.',
|
|
370
|
+
'',
|
|
371
|
+
'Rules:',
|
|
372
|
+
'- Follow the latest [Collaboration task] message in this conversation.',
|
|
373
|
+
'- When done, call `collab_report` with summary / status (done/partial/blocked) / details / next, then end your turn.',
|
|
374
|
+
'- Your final reply is relayed to the manager together with the report; use blocked and state the decision you need.',
|
|
375
|
+
'- The manager may dispatch further rounds; follow the same flow each time.',
|
|
376
|
+
].join('\n')
|
|
377
|
+
},
|
|
378
|
+
dispatch({ round, goal, task, acceptance, marker }) {
|
|
379
|
+
const lines = [`[Collaboration task · Round ${round}]`, '']
|
|
380
|
+
if (goal) lines.push(`Project goal: ${goal}`, '')
|
|
381
|
+
lines.push(
|
|
382
|
+
'— Task —',
|
|
383
|
+
task,
|
|
384
|
+
'',
|
|
385
|
+
'— Acceptance criteria —',
|
|
386
|
+
acceptance || '(not specified; check the deliverable for completeness against the task)',
|
|
387
|
+
'',
|
|
388
|
+
'— Delivery —',
|
|
389
|
+
'1. Execute this round directly; do not change the project direction or expand beyond the task.',
|
|
390
|
+
'2. When done, call collab_report with summary / status (done, partial, blocked) / details / next.',
|
|
391
|
+
'3. End your turn after reporting; your final reply is relayed back to the manager as the output and feedback.',
|
|
392
|
+
marker,
|
|
393
|
+
)
|
|
394
|
+
return lines.join('\n')
|
|
395
|
+
},
|
|
396
|
+
report({ round, workerTitle, worker, report, reason, finalText, maxRounds, nextRound, marker }) {
|
|
397
|
+
const status = report === undefined ? this.statusLabel('unreported') : this.statusLabel(report.status)
|
|
398
|
+
const lines = [
|
|
399
|
+
`[Collaboration report · Round ${round}]`,
|
|
400
|
+
`Worker conversation: ${workerTitle || 'Unnamed'} (${worker})`,
|
|
401
|
+
`Status: ${status}`,
|
|
402
|
+
`Turn ended: ${this.reasonText(reason)}`,
|
|
403
|
+
'',
|
|
404
|
+
]
|
|
405
|
+
if (report !== undefined) {
|
|
406
|
+
lines.push('— Worker report —', report.summary)
|
|
407
|
+
if (report.details) lines.push('', 'Details:', report.details)
|
|
408
|
+
if (report.next) lines.push('', `Worker suggestion: ${report.next}`)
|
|
409
|
+
lines.push('')
|
|
410
|
+
}
|
|
411
|
+
lines.push(
|
|
412
|
+
'— Final output —',
|
|
413
|
+
finalText || (report === undefined
|
|
414
|
+
? '(no readable text output this round; open the worker conversation for the full process)'
|
|
415
|
+
: '(the worker added no text summary; the report above is its output.)'),
|
|
416
|
+
'',
|
|
417
|
+
)
|
|
418
|
+
if (round >= maxRounds) lines.push(`⚠ This worker reached the configured maximum of ${maxRounds} rounds and cannot receive another round; review the result and call collab_done.`, '')
|
|
419
|
+
lines.push(
|
|
420
|
+
'— Next —',
|
|
421
|
+
'Review this result as the project manager:',
|
|
422
|
+
`- Continue: call collab_dispatch for round ${nextRound}, worker="${worker}" (acceptance optional).`,
|
|
423
|
+
`- This worker is done: call collab_done, worker="${worker}", with a summary.`,
|
|
424
|
+
`- Inspect the full process: open worker conversation ${worker}.`,
|
|
425
|
+
marker,
|
|
426
|
+
)
|
|
427
|
+
return lines.join('\n')
|
|
428
|
+
},
|
|
429
|
+
done({ summary, marker }) {
|
|
430
|
+
return [
|
|
431
|
+
'[Collaboration finished]',
|
|
432
|
+
'The project manager confirmed this project is complete; this collaboration ends here.',
|
|
433
|
+
'',
|
|
434
|
+
`Project summary: ${summary || '(none)'}`,
|
|
435
|
+
'',
|
|
436
|
+
'Do not start new tasks or call collaboration tools. If work is still unfinished, stop and briefly state the current status.',
|
|
437
|
+
marker,
|
|
438
|
+
].join('\n')
|
|
439
|
+
},
|
|
440
|
+
nudge({ worker, minutes, attempt, max }) {
|
|
441
|
+
return [
|
|
442
|
+
'[Collaboration reminder]',
|
|
443
|
+
`Worker ${worker} is idle and nothing has progressed for ${minutes} minutes (reminder ${attempt}/${max}).`,
|
|
444
|
+
'',
|
|
445
|
+
'Continue by calling `collab_dispatch` for the next round, or close that worker with `collab_done`.',
|
|
446
|
+
'If the project should pause, tell the user and explain why.',
|
|
447
|
+
].join('\n')
|
|
448
|
+
},
|
|
449
|
+
},
|
|
450
|
+
}
|
|
451
|
+
|
|
193
452
|
export function apply(ctx, rawConfig) {
|
|
194
453
|
const cfg = resolveConfig(rawConfig)
|
|
454
|
+
const L = LANGUAGES[cfg.language]
|
|
195
455
|
const links = new Map()
|
|
196
456
|
/** managerId -> Set<linkId>, every link the session manages (any status). */
|
|
197
457
|
const byManager = new Map()
|
|
@@ -222,6 +482,16 @@ export function apply(ctx, rawConfig) {
|
|
|
222
482
|
|
|
223
483
|
ctx.on('session/event', onSessionEvent)
|
|
224
484
|
|
|
485
|
+
// ------------------------------------------------------------- watchdog
|
|
486
|
+
let alive = true
|
|
487
|
+
let watchdogTimer
|
|
488
|
+
ctx.effect(() => () => {
|
|
489
|
+
alive = false
|
|
490
|
+
if (watchdogTimer !== undefined) clearInterval(watchdogTimer)
|
|
491
|
+
})
|
|
492
|
+
if (cfg.autoNudge) watchdogTimer = setInterval(() => { void runWatchdog() }, 60000)
|
|
493
|
+
setTimeout(() => { void recoverPendingLinks() }, 5000)
|
|
494
|
+
|
|
225
495
|
registerTools()
|
|
226
496
|
registerCommand()
|
|
227
497
|
|
|
@@ -284,6 +554,8 @@ export function apply(ctx, rawConfig) {
|
|
|
284
554
|
pending: normalizePending(value.pending),
|
|
285
555
|
lastReport: value.lastReport !== null && typeof value.lastReport === 'object' ? value.lastReport : null,
|
|
286
556
|
history: Array.isArray(value.history) ? value.history.slice(-cfg.maxHistory) : [],
|
|
557
|
+
nudges: Number.isSafeInteger(value.nudges) && value.nudges >= 0 ? value.nudges : 0,
|
|
558
|
+
...(typeof value.lastNudgeAt === 'number' ? { lastNudgeAt: value.lastNudgeAt } : {}),
|
|
287
559
|
createdAt: Number.isFinite(value.createdAt) ? value.createdAt : Date.now(),
|
|
288
560
|
updatedAt: Number.isFinite(value.updatedAt) ? value.updatedAt : Date.now(),
|
|
289
561
|
...(typeof value.closedAt === 'number' ? { closedAt: value.closedAt } : {}),
|
|
@@ -341,119 +613,49 @@ export function apply(ctx, rawConfig) {
|
|
|
341
613
|
if (typeof agentId !== 'string') return ''
|
|
342
614
|
const managed = managerLinks(agentId, true)
|
|
343
615
|
if (managed.length > 0) {
|
|
344
|
-
const rows = managed.slice(0, 8).map((link) => {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
'员工:',
|
|
354
|
-
...rows,
|
|
355
|
-
'',
|
|
356
|
-
'规则:',
|
|
357
|
-
'- 用 `collab_dispatch` 派发任务;有多个员工时用 `worker` 指定员工(sessionId 或标题),只有一个时可省略。',
|
|
358
|
-
'- 需要调整某个员工的 agent 预设或模型时,用 `collab_configure`(worker 指定员工)。',
|
|
359
|
-
'- 收到以【协作回报】开头的消息后,继续派发,或对该员工调用 `collab_done`;`collab_status` 查看全部进度。',
|
|
360
|
-
'- 除非用户明确要求,不要自己执行员工的交付任务;你负责拆解、验收和决定下一步。',
|
|
361
|
-
`- 每个员工最多 ${cfg.maxRounds} 轮。`,
|
|
362
|
-
].join('\n')
|
|
616
|
+
const rows = managed.slice(0, 8).map((link) => L.managerRow({
|
|
617
|
+
label: link.label || (cfg.language === 'en' ? '(unnamed worker)' : '(未命名员工)'),
|
|
618
|
+
worker: link.worker,
|
|
619
|
+
round: link.round,
|
|
620
|
+
state: link.pending === null ? L.idle : L.waiting,
|
|
621
|
+
last: link.lastReport === null ? '' : L.statusLabel(link.lastReport.status),
|
|
622
|
+
}))
|
|
623
|
+
if (managed.length > 8) rows.push(L.moreWorkers(managed.length - 8))
|
|
624
|
+
return L.managerSection({ count: managed.length, rows, maxRounds: cfg.maxRounds })
|
|
363
625
|
}
|
|
364
626
|
const link = workerLink(agentId)
|
|
365
627
|
if (link === undefined) return ''
|
|
366
|
-
return
|
|
367
|
-
'## 双对话协作 · 你是员工',
|
|
368
|
-
`项目经理对话:${link.manager}`,
|
|
369
|
-
`进度:第 ${link.round} 轮${link.pending === null ? '' : ',待你完成本轮任务'}`,
|
|
370
|
-
'你负责执行项目经理派发的任务,并如实回报结果;项目目标与验收标准以派发消息为准,不要改变大方向或扩大范围。',
|
|
371
|
-
'',
|
|
372
|
-
'规则:',
|
|
373
|
-
'- 严格按本对话里最近一条【协作任务】执行。',
|
|
374
|
-
'- 完成后调用 `collab_report` 汇报:summary(交付物/结论)、status(done/partial/blocked)、details、next,然后结束本轮回复。',
|
|
375
|
-
'- 你的最终回复会连同汇报一起自动回传给项目经理;遇到阻塞用 blocked 写清需要什么决策。',
|
|
376
|
-
'- 项目经理可能连续派发多轮任务,每轮都按上述流程执行。',
|
|
377
|
-
].join('\n')
|
|
628
|
+
return L.workerSection({ manager: link.manager, round: link.round, pending: link.pending !== null })
|
|
378
629
|
}
|
|
379
630
|
|
|
380
631
|
/** Render one dispatch message for a worker. */
|
|
381
632
|
function dispatchText(link, round, task, acceptance) {
|
|
382
|
-
|
|
383
|
-
if (link.goal) lines.push(`项目目标:${link.goal}`, '')
|
|
384
|
-
lines.push(
|
|
385
|
-
'—— 本轮任务 ——',
|
|
386
|
-
task,
|
|
387
|
-
'',
|
|
388
|
-
'—— 验收标准 ——',
|
|
389
|
-
acceptance || '(未指定;按任务目标自行检查交付完整性)',
|
|
390
|
-
'',
|
|
391
|
-
'—— 交付要求 ——',
|
|
392
|
-
'1. 直接执行本轮任务,不要改变项目大方向,也不要扩大到任务之外。',
|
|
393
|
-
'2. 完成后调用 collab_report 汇报:summary / status(done 完成、partial 部分完成、blocked 受阻需决策)/ details / next。',
|
|
394
|
-
'3. 汇报后结束本轮回复;你的最终回复会作为「产出与反馈」自动回传给项目经理。',
|
|
395
|
-
`[[collab:${link.id}:r${round}]]`,
|
|
396
|
-
)
|
|
397
|
-
return lines.join('\n')
|
|
633
|
+
return L.dispatch({ round, goal: link.goal, task, acceptance, marker: `[[collab:${link.id}:r${round}]]` })
|
|
398
634
|
}
|
|
399
635
|
|
|
400
636
|
/** Render the report the manager receives. */
|
|
401
637
|
function reportText({ link, pending, report, finalText, reason, workerTitle }) {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
if (report.next) lines.push('', `员工建议:${report.next}`)
|
|
414
|
-
lines.push('')
|
|
415
|
-
}
|
|
416
|
-
lines.push(
|
|
417
|
-
'—— 员工最终产出 ——',
|
|
418
|
-
finalText || (report === undefined
|
|
419
|
-
? '(本轮没有可读取的文本产出,可打开员工对话查看完整过程)'
|
|
420
|
-
: '(员工本轮没有额外文字总结,以上汇报即为其产出。)'),
|
|
421
|
-
'',
|
|
422
|
-
)
|
|
423
|
-
if (link.round >= cfg.maxRounds) {
|
|
424
|
-
lines.push(`⚠ 该员工已达到配置的最大轮次 ${cfg.maxRounds},无法再派发新一轮;请验收成果后调用 collab_done 收尾。`, '')
|
|
425
|
-
}
|
|
426
|
-
lines.push(
|
|
427
|
-
'—— 下一步 ——',
|
|
428
|
-
'请以项目经理身份审阅本轮结果:',
|
|
429
|
-
`- 需要继续:调用 collab_dispatch 下发第 ${link.round + 1} 轮任务,worker="${link.worker}"(可附验收标准)。`,
|
|
430
|
-
`- 该员工已完成:调用 collab_done,worker="${link.worker}",形成总结并收尾。`,
|
|
431
|
-
`- 需要了解过程细节:可打开员工对话 ${link.worker} 查看。`,
|
|
432
|
-
`[[collab:${link.id}:r${pending.round}:report]]`,
|
|
433
|
-
)
|
|
434
|
-
return lines.join('\n')
|
|
638
|
+
return L.report({
|
|
639
|
+
round: pending.round,
|
|
640
|
+
workerTitle,
|
|
641
|
+
worker: link.worker,
|
|
642
|
+
report,
|
|
643
|
+
reason,
|
|
644
|
+
finalText,
|
|
645
|
+
maxRounds: cfg.maxRounds,
|
|
646
|
+
nextRound: link.round + 1,
|
|
647
|
+
marker: `[[collab:${link.id}:r${pending.round}:report]]`,
|
|
648
|
+
})
|
|
435
649
|
}
|
|
436
650
|
|
|
437
651
|
/** Render the closing message for the worker. */
|
|
438
652
|
function doneText(link, summary) {
|
|
439
|
-
return [
|
|
440
|
-
'【协作结束】',
|
|
441
|
-
'项目经理已确认本项目完成,本轮协作到此结束。',
|
|
442
|
-
'',
|
|
443
|
-
`项目总结:${summary || '(无)'}`,
|
|
444
|
-
'',
|
|
445
|
-
'不需要再执行新的任务,也不要再调用协作工具;如果手上还有未完成的工作,请停止并简要说明当前状态。',
|
|
446
|
-
`[[collab:${link.id}:done]]`,
|
|
447
|
-
].join('\n')
|
|
653
|
+
return L.done({ summary, marker: `[[collab:${link.id}:done]]` })
|
|
448
654
|
}
|
|
449
655
|
|
|
450
|
-
/**
|
|
656
|
+
/** Localized label for a report status. */
|
|
451
657
|
function statusLabel(status) {
|
|
452
|
-
|
|
453
|
-
if (status === 'partial') return '部分完成'
|
|
454
|
-
if (status === 'blocked') return '受阻,需要决策'
|
|
455
|
-
if (status === 'unreported') return '未显式汇报'
|
|
456
|
-
return '未知'
|
|
658
|
+
return L.statusLabel(status)
|
|
457
659
|
}
|
|
458
660
|
|
|
459
661
|
// -------------------------------------------------------------- delivery
|
|
@@ -770,6 +972,8 @@ export function apply(ctx, rawConfig) {
|
|
|
770
972
|
workerRunning: workerAgent !== undefined && workerAgent.status === 'running',
|
|
771
973
|
managerRunning: managerAgent !== undefined && managerAgent.status === 'running',
|
|
772
974
|
round: link.round,
|
|
975
|
+
nudges: link.nudges,
|
|
976
|
+
...(link.lastNudgeAt === undefined ? {} : { lastNudgeAt: isoTime(link.lastNudgeAt) }),
|
|
773
977
|
waitedSeconds: link.pending === null ? null : Math.max(0, Math.round((Date.now() - link.pending.dispatchedAt) / 1000)),
|
|
774
978
|
pending: link.pending === null ? null : {
|
|
775
979
|
round: link.pending.round,
|
|
@@ -794,6 +998,8 @@ export function apply(ctx, rawConfig) {
|
|
|
794
998
|
ok: true,
|
|
795
999
|
generatedAt: isoTime(Date.now()),
|
|
796
1000
|
maxRounds: cfg.maxRounds,
|
|
1001
|
+
maxNudges: cfg.maxNudges,
|
|
1002
|
+
language: cfg.language,
|
|
797
1003
|
activeCount: rows.filter((row) => row.status === ACTIVE).length,
|
|
798
1004
|
totalCount: rows.length,
|
|
799
1005
|
links: rows,
|
|
@@ -821,6 +1027,8 @@ export function apply(ctx, rawConfig) {
|
|
|
821
1027
|
dispatchedAt: Date.now(),
|
|
822
1028
|
report: null,
|
|
823
1029
|
}
|
|
1030
|
+
link.nudges = 0
|
|
1031
|
+
delete link.lastNudgeAt
|
|
824
1032
|
link.updatedAt = Date.now()
|
|
825
1033
|
await persist(link)
|
|
826
1034
|
try {
|
|
@@ -849,6 +1057,8 @@ export function apply(ctx, rawConfig) {
|
|
|
849
1057
|
if (workerTitle !== undefined && workerTitle !== current.label) current.label = workerTitle
|
|
850
1058
|
const status = report?.status ?? 'unreported'
|
|
851
1059
|
current.pending = null
|
|
1060
|
+
current.nudges = 0
|
|
1061
|
+
delete current.lastNudgeAt
|
|
852
1062
|
current.lastReport = {
|
|
853
1063
|
round: pending.round,
|
|
854
1064
|
status,
|
|
@@ -856,7 +1066,7 @@ export function apply(ctx, rawConfig) {
|
|
|
856
1066
|
details: report?.details ?? '',
|
|
857
1067
|
next: report?.next ?? '',
|
|
858
1068
|
text: finalText,
|
|
859
|
-
turnReason: reasonText(reason),
|
|
1069
|
+
turnReason: L.reasonText(reason),
|
|
860
1070
|
relayedAt: Date.now(),
|
|
861
1071
|
relayRequestId: `cp-${current.id}-r${pending.round}-to-manager`,
|
|
862
1072
|
}
|
|
@@ -873,24 +1083,102 @@ export function apply(ctx, rawConfig) {
|
|
|
873
1083
|
current.updatedAt = Date.now()
|
|
874
1084
|
await persist(current)
|
|
875
1085
|
if (!cfg.autoRelay) return
|
|
1086
|
+
const text = reportText({ link: current, pending, report, finalText, reason, workerTitle })
|
|
1087
|
+
const relayRequestId = current.lastReport.relayRequestId
|
|
876
1088
|
try {
|
|
877
|
-
await deliver(
|
|
878
|
-
current.manager,
|
|
879
|
-
reportText({ link: current, pending, report, finalText, reason, workerTitle }),
|
|
880
|
-
current.lastReport.relayRequestId,
|
|
881
|
-
'queue',
|
|
882
|
-
AbortSignal.timeout(PROMPT_TIMEOUT_MS),
|
|
883
|
-
)
|
|
1089
|
+
await deliver(current.manager, text, relayRequestId, 'queue', AbortSignal.timeout(PROMPT_TIMEOUT_MS))
|
|
884
1090
|
} catch (error) {
|
|
885
1091
|
current.lastReport.deliveryError = String(error instanceof Error ? error.message : error)
|
|
886
1092
|
await persist(current)
|
|
887
1093
|
ctx.logger.warn(`collab-pair: delivering round ${pending.round} for ${current.worker} to the manager failed: ${String(error)}`)
|
|
1094
|
+
// One bounded retry keeps an unattended run alive across a transient failure.
|
|
1095
|
+
setTimeout(() => {
|
|
1096
|
+
if (!alive) return
|
|
1097
|
+
void deliver(current.manager, text, relayRequestId, 'queue', AbortSignal.timeout(PROMPT_TIMEOUT_MS))
|
|
1098
|
+
.then(async () => {
|
|
1099
|
+
if (current.lastReport !== null && current.lastReport.deliveryError !== undefined) {
|
|
1100
|
+
delete current.lastReport.deliveryError
|
|
1101
|
+
await persist(current)
|
|
1102
|
+
}
|
|
1103
|
+
})
|
|
1104
|
+
.catch((retryError) => {
|
|
1105
|
+
ctx.logger.warn(`collab-pair: relay retry for ${current.id} failed: ${String(retryError)}`)
|
|
1106
|
+
})
|
|
1107
|
+
}, 60000)
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/**
|
|
1112
|
+
* Wake an idle manager when a worker link makes no progress for a long time,
|
|
1113
|
+
* so an unattended project does not stall silently. Bounded per link.
|
|
1114
|
+
*/
|
|
1115
|
+
async function runWatchdog() {
|
|
1116
|
+
if (!alive || !cfg.autoNudge) return
|
|
1117
|
+
const now = Date.now()
|
|
1118
|
+
for (const link of [...links.values()]) {
|
|
1119
|
+
if (!alive) return
|
|
1120
|
+
if (link.status !== ACTIVE) continue
|
|
1121
|
+
if (link.pending !== null) continue
|
|
1122
|
+
if (link.nudges >= cfg.maxNudges) continue
|
|
1123
|
+
const since = link.lastNudgeAt ?? link.updatedAt
|
|
1124
|
+
if (now - since < cfg.nudgeAfterMinutes * 60000) continue
|
|
1125
|
+
const managerAgent = ctx.agents.get(link.manager)
|
|
1126
|
+
if (managerAgent !== undefined && managerAgent.status === 'running') continue
|
|
1127
|
+
const workerAgent = ctx.agents.get(link.worker)
|
|
1128
|
+
if (workerAgent !== undefined && workerAgent.status === 'running') continue
|
|
1129
|
+
const minutes = Math.max(1, Math.round((now - since) / 60000))
|
|
1130
|
+
const attempt = link.nudges + 1
|
|
1131
|
+
link.nudges = attempt
|
|
1132
|
+
link.lastNudgeAt = now
|
|
1133
|
+
link.updatedAt = now
|
|
1134
|
+
await persist(link)
|
|
1135
|
+
try {
|
|
1136
|
+
await deliver(
|
|
1137
|
+
link.manager,
|
|
1138
|
+
L.nudge({ worker: link.label || link.worker, minutes, attempt, max: cfg.maxNudges }),
|
|
1139
|
+
`cp-${link.id}-nudge-${attempt}`,
|
|
1140
|
+
'queue',
|
|
1141
|
+
AbortSignal.timeout(PROMPT_TIMEOUT_MS),
|
|
1142
|
+
)
|
|
1143
|
+
} catch (error) {
|
|
1144
|
+
ctx.logger.warn(`collab-pair: nudge for ${link.id} failed: ${String(error)}`)
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
/**
|
|
1150
|
+
* Recover a relay that was missed while the plugin was reloading: a live
|
|
1151
|
+
* worker may have finished a dispatched round before the listener returned.
|
|
1152
|
+
* Runs once shortly after activation.
|
|
1153
|
+
*/
|
|
1154
|
+
async function recoverPendingLinks() {
|
|
1155
|
+
if (!alive) return
|
|
1156
|
+
for (const link of [...links.values()]) {
|
|
1157
|
+
if (!alive) return
|
|
1158
|
+
if (link.status !== ACTIVE || link.pending === null) continue
|
|
1159
|
+
const session = ctx.sessions.get(link.worker)
|
|
1160
|
+
if (session === undefined) continue
|
|
1161
|
+
const all = session.ownEvents()
|
|
1162
|
+
for (let index = all.length - 1; index >= 0; index--) {
|
|
1163
|
+
const event = all[index]
|
|
1164
|
+
if (event.type !== 'turn/end') continue
|
|
1165
|
+
let scoped
|
|
1166
|
+
try {
|
|
1167
|
+
scoped = turnEvents(session, event.data?.turn, event.seq)
|
|
1168
|
+
} catch {
|
|
1169
|
+
scoped = undefined
|
|
1170
|
+
}
|
|
1171
|
+
if (scoped === undefined) continue
|
|
1172
|
+
if (!claimedBy(scoped, { ...link.pending, linkId: link.id })) continue
|
|
1173
|
+
const snapshot = { ...link.pending }
|
|
1174
|
+
enqueueRelay(link.id, () => relayReport(link, snapshot, scoped, event.data?.reason))
|
|
1175
|
+
break
|
|
1176
|
+
}
|
|
888
1177
|
}
|
|
889
1178
|
}
|
|
890
1179
|
|
|
891
1180
|
/** Serialize relays per link so one turn cannot relay twice. */
|
|
892
|
-
function enqueueRelay(linkId, run) {
|
|
893
|
-
const previous = relays.get(linkId) ?? Promise.resolve()
|
|
1181
|
+
function enqueueRelay(linkId, run) { const previous = relays.get(linkId) ?? Promise.resolve()
|
|
894
1182
|
const next = previous.then(run, run).catch((error) => {
|
|
895
1183
|
ctx.logger.warn(`collab-pair: relay for ${linkId} failed: ${String(error)}`)
|
|
896
1184
|
})
|
|
@@ -1259,6 +1547,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1259
1547
|
storage: storageState,
|
|
1260
1548
|
...(storageError === null ? {} : { storageError }),
|
|
1261
1549
|
engine: ENGINE,
|
|
1550
|
+
language: cfg.language,
|
|
1262
1551
|
role: 'manager',
|
|
1263
1552
|
manager: { sessionId: agent.id, title: (await titleOf(agent.id)) ?? null },
|
|
1264
1553
|
maxRounds: cfg.maxRounds,
|
|
@@ -1274,6 +1563,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1274
1563
|
storage: storageState,
|
|
1275
1564
|
...(storageError === null ? {} : { storageError }),
|
|
1276
1565
|
engine: ENGINE,
|
|
1566
|
+
language: cfg.language,
|
|
1277
1567
|
hint: '当前对话没有协作关联。用 collab_sessions 查看可关联的对话,再用 collab_link 建立关联(peer="new" 可新建员工对话)。',
|
|
1278
1568
|
}
|
|
1279
1569
|
}
|
|
@@ -1283,6 +1573,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1283
1573
|
storage: storageState,
|
|
1284
1574
|
...(storageError === null ? {} : { storageError }),
|
|
1285
1575
|
engine: ENGINE,
|
|
1576
|
+
language: cfg.language,
|
|
1286
1577
|
linkId: link.id,
|
|
1287
1578
|
role: 'worker',
|
|
1288
1579
|
manager: { sessionId: link.manager, title: managerTitle ?? null },
|
|
@@ -1549,9 +1840,9 @@ export function apply(ctx, rawConfig) {
|
|
|
1549
1840
|
}
|
|
1550
1841
|
ctx.commands.register({
|
|
1551
1842
|
name: 'collab',
|
|
1552
|
-
description: '
|
|
1843
|
+
description: '双对话协作:查看全部任务、关联员工、配置预设与语言、派发任务、收尾或解除。',
|
|
1553
1844
|
input: {
|
|
1554
|
-
hint: 'tasks | status | link --peer <id|new> | configure --preset <id> | dispatch --worker <id> --task ... | done --worker <id> --summary ... | unlink --worker <id>',
|
|
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>',
|
|
1555
1846
|
},
|
|
1556
1847
|
handler: async (invocation) => {
|
|
1557
1848
|
try {
|
|
@@ -1559,6 +1850,17 @@ export function apply(ctx, rawConfig) {
|
|
|
1559
1850
|
if (action === 'tasks' || action === 'board') {
|
|
1560
1851
|
return { kind: 'success', text: JSON.stringify(await tasksBoard()) }
|
|
1561
1852
|
}
|
|
1853
|
+
if (action === 'language') {
|
|
1854
|
+
const next = typeof args?.language === 'string' ? args.language : typeof args?.value === 'string' ? args.value : ''
|
|
1855
|
+
if (next !== 'zh' && next !== 'en') return { kind: 'error', text: 'language must be zh or en' }
|
|
1856
|
+
const entry = ctx.fiber?.entry
|
|
1857
|
+
const editor = ctx.get('configEditor')
|
|
1858
|
+
if (entry === undefined || editor === undefined) {
|
|
1859
|
+
return { kind: 'error', text: '当前环境无法保存语言设置;请手动修改 cordis.patch.yml 里的 language。' }
|
|
1860
|
+
}
|
|
1861
|
+
await editor.edit(entry, (current) => ({ ...current, language: next }))
|
|
1862
|
+
return { kind: 'success', text: JSON.stringify({ ok: true, language: next }) }
|
|
1863
|
+
}
|
|
1562
1864
|
const key = actions[action]
|
|
1563
1865
|
const executor = key === undefined ? undefined : toolExecutors[key]
|
|
1564
1866
|
if (executor === undefined) {
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Collaboration pair",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "For large projects: link several worker conversations to one manager, dispatch each round once instead of repeating prompts, relay results automatically, and keep unattended runs moving."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-collab-pair",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "For large projects: link one project-manager conversation with one or more worker conversations, dispatch each round from the manager instead of repeating prompts across conversations, relay results automatically, and keep unattended runs moving with a visual task board.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|