dsh-collab-pair 1.5.0 → 1.5.2
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 +20 -0
- package/client.js +5 -0
- package/hub.js +6 -0
- package/index.js +45 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,6 +60,7 @@ The page only links, unlinks, and reports status. Goals, tasks, and acceptance s
|
|
|
60
60
|
|
|
61
61
|
- The settings page follows the app language; English and Chinese ship in the package.
|
|
62
62
|
- Generated collaboration messages follow the `language` config (`zh` or `en`, default `zh`). Switch it in the page header (**Message language**) or with `/collab language en`. The command persists the config and reloads the plugin.
|
|
63
|
+
- Built-in title prefixes follow `language`: `【项目经理】`/`【员工】` for zh, `[Manager]`/`[Worker]` for en. Custom `prefixManager`/`prefixWorker` values override the defaults; switching language re-prefixes linked titles on reload.
|
|
63
64
|
|
|
64
65
|
## Unattended runs
|
|
65
66
|
|
|
@@ -111,6 +112,15 @@ Security: the token is a shared secret for the room; anyone holding it can deliv
|
|
|
111
112
|
|
|
112
113
|
If a tunnel is inconvenient, choose **Free public relay (ntfy.sh)** in the Settings card: no account and no deployment. The topic is derived from room + token; messages go through ntfy.sh in 4 KB chunks (the free tier allows about 250 publishes per day per IP). Use a long random token; this is not end-to-end encrypted.
|
|
113
114
|
|
|
115
|
+
**`127.0.0.1` / `localhost` only works on the machine running the hub.** On every other device use the hub's LAN IP (same network, with the firewall port open) or the HTTPS tunnel URL. `hub.js` prints its LAN addresses at startup. Before relying on a relay, open `<hub-url>/v1/health` from the other device and press **Test connection** in the Settings card.
|
|
116
|
+
|
|
117
|
+
Cross-device checklist:
|
|
118
|
+
|
|
119
|
+
- the other device can open `<hub-url>/v1/health`;
|
|
120
|
+
- both devices use the same `hubRoom` and `hubToken`, with **distinct** `deviceName`s;
|
|
121
|
+
- the worker device registered its alias, and the manager linked that device + alias;
|
|
122
|
+
- remote workers run on their own machine, so files are **not** shared: use a common git remote or network drive, or ask the worker to return patches/text in its report.
|
|
123
|
+
|
|
114
124
|
## Stage queue
|
|
115
125
|
|
|
116
126
|
A human can pre-write several large stages for one worker; finishing one dispatches the next automatically.
|
|
@@ -319,6 +329,7 @@ dsh plugin add dsh-collab-pair
|
|
|
319
329
|
|
|
320
330
|
- 设置页跟随应用语言,包内自带中文和英文。
|
|
321
331
|
- 对话里生成的消息由配置 `language` 决定(`zh` / `en`,默认 `zh`)。可在页面顶部「对话消息语言」切换,或用 `/collab language en`;命令会保存配置并重载插件。
|
|
332
|
+
- 内置标题前缀跟随 `language`:中文 `【项目经理】`/`【员工】`,英文 `[Manager]`/`[Worker]`。自定义 `prefixManager`/`prefixWorker` 会覆盖默认;切换语言后重载会自动把已关联对话改成对应前缀。
|
|
322
333
|
|
|
323
334
|
## 挂机运行
|
|
324
335
|
|
|
@@ -370,6 +381,15 @@ collab_dispatch({ worker: "前端", task: "…" })
|
|
|
370
381
|
|
|
371
382
|
如果内网穿透不方便,可在设置卡片里选 **免费公共中继(ntfy.sh)**:不用账号、不用部署。topic 由 room + token 派生;消息以 4 KB 分片经过 ntfy.sh(免费额度约每 IP 每天 250 次发布)。请用足够长的随机 token;这不是端到端加密。
|
|
372
383
|
|
|
384
|
+
**`127.0.0.1` / `localhost` 只对运行 hub 的那台机器有效。** 其他设备要填 hub 所在机器的局域网 IP(同一网络、防火墙放行端口)或 HTTPS 隧道地址;`hub.js` 启动时会打印局域网地址。正式使用前,从另一台设备打开 `<hub 地址>/v1/health`,并在设置卡片里点「测试连接」。
|
|
385
|
+
|
|
386
|
+
跨设备检查清单:
|
|
387
|
+
|
|
388
|
+
- 另一台设备能打开 `<hub 地址>/v1/health`;
|
|
389
|
+
- 两台设备的 `hubRoom`、`hubToken` 相同,`deviceName` **不同**;
|
|
390
|
+
- 员工设备已注册别名,经理设备关联了该设备 + 别名;
|
|
391
|
+
- 远程员工在各自机器上执行,**文件不共享**:用共同的 git remote 或网络盘,或让员工在回报里给出 patch/文本。
|
|
392
|
+
|
|
373
393
|
## 阶段队列
|
|
374
394
|
|
|
375
395
|
人可以给同一个员工预先写好多个大阶段;完成一个阶段后自动派发下一个。
|
package/client.js
CHANGED
|
@@ -77,6 +77,7 @@ window.__ModuleLoader__.load({
|
|
|
77
77
|
relayNtfy: '免费公共中继 ntfy.sh',
|
|
78
78
|
relayOffHint: '关闭后不再轮询中继,令牌会保留,切回时无需重填。',
|
|
79
79
|
relayHubUrl: 'Hub 地址',
|
|
80
|
+
relayLocalhostHint: '127.0.0.1 / localhost 只在本机可访问;另一台设备请填这台机器的局域网 IP 或 HTTPS 隧道地址。',
|
|
80
81
|
relayRoom: '房间',
|
|
81
82
|
relayToken: '令牌',
|
|
82
83
|
relayTokenKeep: '留空保留已保存的令牌',
|
|
@@ -230,6 +231,7 @@ window.__ModuleLoader__.load({
|
|
|
230
231
|
relayNtfy: 'Free public relay ntfy.sh',
|
|
231
232
|
relayOffHint: 'Turning it off stops polling and keeps the token for next time.',
|
|
232
233
|
relayHubUrl: 'Hub URL',
|
|
234
|
+
relayLocalhostHint: '127.0.0.1 / localhost only works on this machine; on another device use this machine’s LAN address or an HTTPS tunnel URL.',
|
|
233
235
|
relayRoom: 'Room',
|
|
234
236
|
relayToken: 'Token',
|
|
235
237
|
relayTokenKeep: 'Leave blank to keep the saved token',
|
|
@@ -960,6 +962,9 @@ window.__ModuleLoader__.load({
|
|
|
960
962
|
onChange: (event) => setRelayHubUrl(event.target.value),
|
|
961
963
|
}))
|
|
962
964
|
: null,
|
|
965
|
+
relayMode === 'hub' && /^https?:\/\/(localhost|127\.0\.0\.1)(:|\/|$)/i.test(relayHubUrl.trim())
|
|
966
|
+
? h('p', { style: S.hint }, t('relayLocalhostHint'))
|
|
967
|
+
: null,
|
|
963
968
|
relayMode === 'off'
|
|
964
969
|
? null
|
|
965
970
|
: h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
package/hub.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
// for dispatch/report round trips; it is deliberately not a durable queue.
|
|
18
18
|
|
|
19
19
|
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto'
|
|
20
|
+
import { networkInterfaces } from 'node:os'
|
|
20
21
|
import { createServer } from 'node:http'
|
|
21
22
|
|
|
22
23
|
const args = new Map()
|
|
@@ -192,6 +193,11 @@ const server = createServer(async (request, response) => {
|
|
|
192
193
|
|
|
193
194
|
server.listen(port, host, () => {
|
|
194
195
|
console.log(`collab-pair hub listening on http://${host}:${port}`)
|
|
196
|
+
const lan = Object.values(networkInterfaces()).flat()
|
|
197
|
+
.filter((entry) => entry !== undefined && entry.family === 'IPv4' && entry.internal !== true)
|
|
198
|
+
.map((entry) => `http://${entry.address}:${port}`)
|
|
199
|
+
if (lan.length > 0) console.log(`LAN addresses: ${lan.join(' ')}`)
|
|
195
200
|
console.log(`token: ${token}`)
|
|
201
|
+
console.log('127.0.0.1/localhost only works on this machine; other devices must use a LAN address or an HTTPS tunnel')
|
|
196
202
|
console.log('put the hub behind HTTPS before using it across untrusted networks')
|
|
197
203
|
})
|
package/index.js
CHANGED
|
@@ -41,7 +41,11 @@ const DONE = 'done'
|
|
|
41
41
|
const STOPPED = 'stopped'
|
|
42
42
|
const REPORTS = new Set(['done', 'partial', 'blocked'])
|
|
43
43
|
const PROMPT_TIMEOUT_MS = 180000
|
|
44
|
-
const ENGINE = 'collab-pair/1.5.
|
|
44
|
+
const ENGINE = 'collab-pair/1.5.2'
|
|
45
|
+
const PREFIX_DEFAULTS = {
|
|
46
|
+
zh: { manager: '【项目经理】', worker: '【员工】' },
|
|
47
|
+
en: { manager: '[Manager]', worker: '[Worker]' },
|
|
48
|
+
}
|
|
45
49
|
|
|
46
50
|
/** A recoverable failure whose message is meant for the model. */
|
|
47
51
|
class CollabError extends Error {}
|
|
@@ -61,9 +65,9 @@ function resolveConfig(raw) {
|
|
|
61
65
|
notifyWorkerOnDone: value.notifyWorkerOnDone !== false,
|
|
62
66
|
autoRelay: value.autoRelay !== false,
|
|
63
67
|
addPrefix: value.addPrefix !== false,
|
|
64
|
-
prefixManager: prefixText(value.prefixManager, '【项目经理】'),
|
|
65
|
-
prefixWorker: prefixText(value.prefixWorker, '【员工】'),
|
|
66
68
|
language: value.language === 'en' ? 'en' : 'zh',
|
|
69
|
+
prefixManager: prefixFor(value.prefixManager, 'manager', value.language === 'en' ? 'en' : 'zh'),
|
|
70
|
+
prefixWorker: prefixFor(value.prefixWorker, 'worker', value.language === 'en' ? 'en' : 'zh'),
|
|
67
71
|
autoNudge: value.autoNudge !== false,
|
|
68
72
|
nudgeAfterMinutes: clampInt(value.nudgeAfterMinutes, 5, 1440, 20),
|
|
69
73
|
maxNudges: clampInt(value.maxNudges, 1, 20, 3),
|
|
@@ -114,6 +118,15 @@ function prefixText(candidate, fallback) {
|
|
|
114
118
|
return value.length > 24 ? value.slice(0, 24) : value
|
|
115
119
|
}
|
|
116
120
|
|
|
121
|
+
/** Built-in prefixes follow the message language; custom values stay custom. */
|
|
122
|
+
function prefixFor(candidate, role, language) {
|
|
123
|
+
const value = typeof candidate === 'string' ? candidate.trim() : ''
|
|
124
|
+
const fallback = PREFIX_DEFAULTS[language][role]
|
|
125
|
+
if (value === '') return fallback
|
|
126
|
+
const builtIn = Object.values(PREFIX_DEFAULTS).some((set) => set[role] === value)
|
|
127
|
+
return builtIn ? fallback : prefixText(value, fallback)
|
|
128
|
+
}
|
|
129
|
+
|
|
117
130
|
/** Rounds per worker: 0 (the default) means unlimited. */
|
|
118
131
|
function normalizeRounds(candidate) {
|
|
119
132
|
const number = typeof candidate === 'number' ? candidate : Number(candidate)
|
|
@@ -276,6 +289,7 @@ const LANGUAGES = {
|
|
|
276
289
|
'',
|
|
277
290
|
'规则:',
|
|
278
291
|
'- 默认自主创建员工:需要人干活时,先用 `collab_worker_create` 建立合适的员工(可按角色建多个),再派发;不要等用户手动新建。',
|
|
292
|
+
'- 远端设备上的员工用 `collab_remote` 关联(先在设置页的「跨设备协作」里配置中继);本机员工才用 `collab_worker_create`,不要重复创建。',
|
|
279
293
|
'- 不要自己承担员工的具体执行工作。你负责拆解、派发、验收和决定下一步;自己动手只限于规划、审阅和必要协调,避免因长时间执行而错过员工回报。',
|
|
280
294
|
'- 用 `collab_dispatch` 派发任务;有多个员工时用 `worker` 指定员工(sessionId 或标题),只有一个时可省略。',
|
|
281
295
|
'- 阶段队列:用 `collab_stage` 添加/查看;当前阶段验收通过后调用 `collab_stage({action:"complete"})`,会自动派发下一阶段。',
|
|
@@ -416,6 +430,7 @@ const LANGUAGES = {
|
|
|
416
430
|
'',
|
|
417
431
|
'Rules:',
|
|
418
432
|
'- Create workers by default: when work needs doing, use `collab_worker_create` to make the right worker(s) (multiple roles if needed), then dispatch. Do not wait for the user to create them manually.',
|
|
433
|
+
'- For a worker on another device use `collab_remote` (configure the relay in the Settings cross-device card first); only create a local worker with `collab_worker_create`. Do not duplicate it.',
|
|
419
434
|
'- Do not do the workers\' execution work yourself. You break down, dispatch, review and decide; your own hands-on work should be limited to planning, review and necessary coordination, so a long execution does not make you miss worker reports.',
|
|
420
435
|
'- 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.',
|
|
421
436
|
'- Stage queue: manage it with `collab_stage`; when the current stage passes acceptance, call `collab_stage({action:"complete"})` to dispatch the next stage automatically.',
|
|
@@ -576,6 +591,7 @@ export function apply(ctx, rawConfig) {
|
|
|
576
591
|
if (cfg.autoNudge) watchdogTimer = setInterval(() => { void runWatchdog() }, 60000)
|
|
577
592
|
setTimeout(() => { void recoverPendingLinks() }, 5000)
|
|
578
593
|
setTimeout(() => { void backfillProjects() }, 3000)
|
|
594
|
+
setTimeout(() => { void relocalizePrefixes() }, 4000)
|
|
579
595
|
setTimeout(() => { if (alive) void remoteLoop() }, 2000)
|
|
580
596
|
|
|
581
597
|
registerTools()
|
|
@@ -1635,7 +1651,12 @@ export function apply(ctx, rawConfig) {
|
|
|
1635
1651
|
|
|
1636
1652
|
/** Remove one of our role prefixes from a title. */
|
|
1637
1653
|
function stripKnownPrefix(title) {
|
|
1638
|
-
|
|
1654
|
+
const known = new Set([
|
|
1655
|
+
cfg.prefixManager,
|
|
1656
|
+
cfg.prefixWorker,
|
|
1657
|
+
...Object.values(PREFIX_DEFAULTS).flatMap((set) => [set.manager, set.worker]),
|
|
1658
|
+
])
|
|
1659
|
+
for (const prefix of known) {
|
|
1639
1660
|
if (prefix !== '' && title.startsWith(prefix)) return title.slice(prefix.length).trimStart()
|
|
1640
1661
|
}
|
|
1641
1662
|
return title
|
|
@@ -1977,6 +1998,20 @@ export function apply(ctx, rawConfig) {
|
|
|
1977
1998
|
}
|
|
1978
1999
|
}
|
|
1979
2000
|
|
|
2001
|
+
/** Re-apply role prefixes in the current language after a language switch. */
|
|
2002
|
+
async function relocalizePrefixes() {
|
|
2003
|
+
if (!alive || !cfg.addPrefix) return
|
|
2004
|
+
for (const link of [...links.values()]) {
|
|
2005
|
+
if (!alive) return
|
|
2006
|
+
try {
|
|
2007
|
+
await applyPrefix(link.manager, cfg.prefixManager)
|
|
2008
|
+
if (link.remote === undefined) await applyPrefix(link.worker, cfg.prefixWorker)
|
|
2009
|
+
} catch (error) {
|
|
2010
|
+
ctx.logger.warn(`collab-pair: re-prefixing ${link.id} failed: ${String(error)}`)
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
|
|
1980
2015
|
/** Serialize relays per link so one turn cannot relay twice. */
|
|
1981
2016
|
function enqueueRelay(linkId, run) { const previous = relays.get(linkId) ?? Promise.resolve()
|
|
1982
2017
|
const next = previous.then(run, run).catch((error) => {
|
|
@@ -2333,7 +2368,7 @@ export function apply(ctx, rawConfig) {
|
|
|
2333
2368
|
toolExecutors.remote = register({
|
|
2334
2369
|
name: 'collab_remote',
|
|
2335
2370
|
description:
|
|
2336
|
-
'
|
|
2371
|
+
'跨设备协作:在设置页的「跨设备协作」里选择中继并保存(自建 hub 或免费 ntfy.sh)。action=alias 在员工设备上把当前对话注册成别名;action=link 在项目经理设备上关联远端设备上的别名;action=aliases / remove-alias / status 查看或维护。',
|
|
2337
2372
|
parameters: {
|
|
2338
2373
|
type: 'object',
|
|
2339
2374
|
properties: {
|
|
@@ -3172,14 +3207,18 @@ export function apply(ctx, rawConfig) {
|
|
|
3172
3207
|
if (sub === 'test') {
|
|
3173
3208
|
if (!relayConfigured()) return { kind: 'error', text: '中继未启用:先选择模式并保存。' }
|
|
3174
3209
|
try {
|
|
3210
|
+
let message = ''
|
|
3175
3211
|
if (cfg.relayMode === 'hub') {
|
|
3176
3212
|
await hubFetch(`/v1/head?room=${encodeURIComponent(cfg.hubRoom)}`)
|
|
3213
|
+
if (/^https?:\/\/(localhost|127\.0\.0\.1)(:|\/|$)/i.test(cfg.hubUrl)) {
|
|
3214
|
+
message = '连接成功,但这个地址只在本机可访问;跨设备请改用局域网 IP 或 HTTPS 隧道地址。'
|
|
3215
|
+
}
|
|
3177
3216
|
} else {
|
|
3178
3217
|
const response = await fetch(`https://ntfy.sh/${encodeURIComponent(ntfyTopic())}/json?poll=1&since=10m`, { signal: AbortSignal.timeout(15000) })
|
|
3179
3218
|
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
3180
3219
|
await response.text()
|
|
3181
3220
|
}
|
|
3182
|
-
return { kind: 'success', text: JSON.stringify({ ok: true, mode: cfg.relayMode, device: cfg.deviceName, room: cfg.hubRoom }) }
|
|
3221
|
+
return { kind: 'success', text: JSON.stringify({ ok: true, mode: cfg.relayMode, device: cfg.deviceName, room: cfg.hubRoom, ...(message === '' ? {} : { message }) }) }
|
|
3183
3222
|
} catch (error) {
|
|
3184
3223
|
return { kind: 'error', text: `连接测试失败:${error instanceof Error ? error.message : String(error)}` }
|
|
3185
3224
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-collab-pair",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "DSH collaboration plugin: link a project-manager conversation with local or remote workers across devices, dispatch rounds, relay results and manage projects/stages automatically. Also ships a prompt to-do queue for any conversation: pre-write a series of prompts and the next one is sent when a turn ends. Includes a relay hub and a free ntfy.sh transport.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|