dsh-rhine-lab-team 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +73 -4
- package/docs/RELEASE.md +5 -3
- package/host/tools.js +180 -37
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -645,9 +645,16 @@ window.__ModuleLoader__.load({
|
|
|
645
645
|
/**
|
|
646
646
|
* 这个会话是不是 Bot 的私聊 / 工作聊天。是的话「团队协作」整块不显示:
|
|
647
647
|
* 团队协作只在主会话里有意义,Bot 会话里开着就是自己派活给自己。
|
|
648
|
-
*
|
|
648
|
+
* 非空答案按会话缓存;空结果不缓存,等任务行落盘后再问。
|
|
649
649
|
*/
|
|
650
650
|
const botChatKinds = new Map()
|
|
651
|
+
// 刚从私聊入口打开、但 session-kind 还没回填的会话:新会话守卫先用它兜底。
|
|
652
|
+
const privateSessionIds = new Set()
|
|
653
|
+
// apply() 里的新会话守卫读不到闭包,给它一个只读判断。
|
|
654
|
+
internals.isPrivateSession = (sessionId) => {
|
|
655
|
+
const sid = String(sessionId ?? '')
|
|
656
|
+
return botChatKinds.get(sid) === 'private' || privateSessionIds.has(sid)
|
|
657
|
+
}
|
|
651
658
|
|
|
652
659
|
function useBotChatKind(props) {
|
|
653
660
|
const sessionId = resolveSessionId(props)
|
|
@@ -664,7 +671,9 @@ window.__ModuleLoader__.load({
|
|
|
664
671
|
if (!res.ok) return
|
|
665
672
|
const data = await res.json()
|
|
666
673
|
const next = typeof data?.kind === 'string' ? data.kind : ''
|
|
667
|
-
|
|
674
|
+
// 空结果不缓存:任务行可能还没落盘,过一会儿再问就有了。
|
|
675
|
+
// 缓存空值会让这个会话永远被当成普通会话,开关再也藏不掉。
|
|
676
|
+
if (next !== '') botChatKinds.set(sessionId, next)
|
|
668
677
|
if (alive) setKind(next)
|
|
669
678
|
} catch {
|
|
670
679
|
// 问不到就当普通会话:藏开关是小,报错是大。
|
|
@@ -5727,6 +5736,7 @@ function createMembersPanel(React, host) {
|
|
|
5727
5736
|
// 私聊是根会话:它就是一条普通会话,交给主视图打开,
|
|
5728
5737
|
// 这样左侧会话列表里也有它(子会话地址只会开成一栏聊天,不进列表)。
|
|
5729
5738
|
if (standalone) {
|
|
5739
|
+
if (asPrivate) privateSessionIds.add(sessionId)
|
|
5730
5740
|
stampTeamIdentity(sessionId, openedIdentity)
|
|
5731
5741
|
const workspace = service('uiWorkspace')
|
|
5732
5742
|
if (!workspace || typeof workspace.openSession !== 'function') {
|
|
@@ -6922,8 +6932,8 @@ function createMembersPanel(React, host) {
|
|
|
6922
6932
|
|
|
6923
6933
|
return {
|
|
6924
6934
|
// ctx 只代理声明过的服务:没在这里写的服务,读到的永远是 undefined。
|
|
6925
|
-
//
|
|
6926
|
-
inject: ['slots', 'sidebarRightTabs', 'sidebarRight'],
|
|
6935
|
+
// 前三样是团队 UI;后两样只给“私聊新会话回默认工作区”的守卫用。
|
|
6936
|
+
inject: ['slots', 'sidebarRightTabs', 'sidebarRight', 'uiWorkspace', 'workspaces'],
|
|
6927
6937
|
internals,
|
|
6928
6938
|
apply(ctx) {
|
|
6929
6939
|
/**
|
|
@@ -6938,6 +6948,65 @@ function createMembersPanel(React, host) {
|
|
|
6938
6948
|
reportDiag({ event: 'slot-register-failed', where: label, build: BUILD_STAMP, error: String(error?.message ?? error) })
|
|
6939
6949
|
}
|
|
6940
6950
|
}
|
|
6951
|
+
/**
|
|
6952
|
+
* 私聊 Bot 里点「新会话」时,DSH 默认沿用当前工作区。当前是
|
|
6953
|
+
* 「私聊会话」工作区的话,新会话会继续落进私聊目录,把私聊会话的
|
|
6954
|
+
* 工作区越攒越乱。这里只在“当前会话确实是私聊”时,把目标改回
|
|
6955
|
+
* 私聊工作区之前的那一个工作区;其余情况原样放行。
|
|
6956
|
+
* 只包插件自己的客户端,不改 DSH 的 app.asar。
|
|
6957
|
+
*/
|
|
6958
|
+
const installPrivateNewChatGuard = () => {
|
|
6959
|
+
let uiWorkspace
|
|
6960
|
+
let workspaces
|
|
6961
|
+
try {
|
|
6962
|
+
uiWorkspace = typeof ctx.get === 'function' ? ctx.get('uiWorkspace') : ctx.uiWorkspace
|
|
6963
|
+
workspaces = typeof ctx.get === 'function' ? ctx.get('workspaces') : ctx.workspaces
|
|
6964
|
+
} catch {
|
|
6965
|
+
return () => {}
|
|
6966
|
+
}
|
|
6967
|
+
if (!uiWorkspace || typeof uiWorkspace.startSession !== 'function') return () => {}
|
|
6968
|
+
if (!workspaces?.list || typeof workspaces.list.getSnapshot !== 'function') return () => {}
|
|
6969
|
+
const original = uiWorkspace.startSession
|
|
6970
|
+
const isPrivateWorkspace = (workspace) => {
|
|
6971
|
+
const title = String(workspace?.title ?? '')
|
|
6972
|
+
const path = String(workspace?.path ?? '')
|
|
6973
|
+
return title === '私聊会话' || /[\\/]rhine-lab-team[\\/]chats[\\/]?$/i.test(path)
|
|
6974
|
+
}
|
|
6975
|
+
const pickDefaultWorkspace = () => {
|
|
6976
|
+
let items = []
|
|
6977
|
+
try {
|
|
6978
|
+
items = workspaces.list.getSnapshot()?.items ?? []
|
|
6979
|
+
} catch {
|
|
6980
|
+
return undefined
|
|
6981
|
+
}
|
|
6982
|
+
const privateIndex = items.findIndex(isPrivateWorkspace)
|
|
6983
|
+
const before = privateIndex >= 0 ? items.slice(0, privateIndex) : items
|
|
6984
|
+
const candidates = before.filter((workspace) => (
|
|
6985
|
+
workspace?.workspaceId && !isPrivateWorkspace(workspace)
|
|
6986
|
+
))
|
|
6987
|
+
return candidates.length > 0 ? candidates[candidates.length - 1].workspaceId : undefined
|
|
6988
|
+
}
|
|
6989
|
+
const wrapped = function (workspaceId, options) {
|
|
6990
|
+
try {
|
|
6991
|
+
if (workspaceId === undefined) {
|
|
6992
|
+
const current = uiWorkspace.selection?.getSnapshot?.().sessionId
|
|
6993
|
+
if (current && internals.isPrivateSession?.(current)) {
|
|
6994
|
+
const target = pickDefaultWorkspace()
|
|
6995
|
+
if (target !== undefined) return original.call(uiWorkspace, target, options)
|
|
6996
|
+
}
|
|
6997
|
+
}
|
|
6998
|
+
} catch {
|
|
6999
|
+
// 守卫失败不能挡住新会话本身,回落到 DSH 原逻辑。
|
|
7000
|
+
}
|
|
7001
|
+
return original.call(uiWorkspace, workspaceId, options)
|
|
7002
|
+
}
|
|
7003
|
+
uiWorkspace.startSession = wrapped
|
|
7004
|
+
return () => {
|
|
7005
|
+
if (uiWorkspace.startSession === wrapped) uiWorkspace.startSession = original
|
|
7006
|
+
}
|
|
7007
|
+
}
|
|
7008
|
+
safeEffect(() => installPrivateNewChatGuard(), 'dsh-team: 私聊新会话回默认工作区')
|
|
7009
|
+
|
|
6941
7010
|
// 离线测试要能直接渲染编辑器,正常路径不碰它。
|
|
6942
7011
|
internals.createMembersPanel = createMembersPanel
|
|
6943
7012
|
reportDiag({ event: 'apply', build: BUILD_STAMP })
|
package/docs/RELEASE.md
CHANGED
|
@@ -41,10 +41,12 @@ dsh plugin add <包名或本地路径>
|
|
|
41
41
|
|
|
42
42
|
## 版本
|
|
43
43
|
|
|
44
|
-
- `0.7.
|
|
44
|
+
- `0.7.3`(当前):修两处会话工作区与开关问题。① 审计等已完成任务的会话不再被当成普通会话——`botChatOf` 对任何绑定了 Bot 的任务行都返回工作聊天,客户端不再缓存空结果,Bot 会话里的「团队协作」开关稳定隐藏。② 私聊 Bot 里点「新会话」时,若当前工作区是「私聊会话」,自动改回私聊工作区之前的工作区,避免新会话落进私聊目录;只包插件客户端,不改 DSH 本体。
|
|
45
|
+
- `0.7.2`:`team_dispatch` / `continueFrom` 新增 `detach` 异步派活——调用立刻返回 `status: running` 和任务号,不把主会话占在等待里;Bot 完成或超时会通过团队消息唤醒主会话,并照常自动建审计。只支持单件,`team_dispatch_many` 批量仍同步汇总。另把后台接力的超时也改成会给主会话补一条消息,不再只广播;无文字产出的回合按 `turn/end` 收尾,不再空等最后一句。
|
|
46
|
+
- `0.7.1`:删掉 Bot 时把它那条私聊会话一并归档(记录保留、从左侧列表收起),并清掉 `private.json` 条目;插件启动时也扫一遍,清理「Bot 早删了、会话还挂着」的遗留。删掉的 Bot 再点头像返回「这个 Bot 已经不在了」;万一从归档里翻出它的旧会话,也不再被当成秘书会话,只回一句实话。
|
|
45
47
|
- `0.7.0`:私聊从子代理改成**独立根会话**——不再挂 ANY 主会话下面,所以主会话里不会再飘进「子代理完成」的通知;私聊会话出现在左侧列表(独立「私聊会话」工作区,排在最后),点开时归档过的会另开一条(旧的标成「名字(存档 月-日)」);Bot 会话里隐藏「团队协作」开关、协调类工具一律收起来;私聊里只剩一个 `remember`,其余工具在执行口拦掉(guard)。
|
|
46
48
|
- `0.6.0`:改人设不用新开会话(人设段的 text 用取值函数,每次组装现取);工作聊天按主会话隔离,一个主会话一条;私聊独立记录、跨主会话复用(0.6.0 时还是子代理,0.7.0 改成根会话);点头像进私聊、未读红点。
|
|
47
|
-
- `0.5.6
|
|
49
|
+
- `0.5.6`:修单聊在根会话失效后发不出去。DSH 要求子会话的根会话在线,旧实现把单聊挂在当时的会话下,重启后根已停止,`sendMessage` 返回 `subagent/delivery-unavailable`。现在客户端一律走 `/dsh-team/open`:服务端先判断原单聊的根是否活着,活着复用,死了在当前会话新开一条;账本同时记 `parentSession` 与 `rootSession`。另补进程级路由撤单,避免热重载时 `identity-map` / `session-bot` 重复注册。
|
|
48
50
|
- `0.5.5`:修两处状态错位。①「待命」误判:成员卡原先只认账本里的 `running` 行,派活那次工具调用一旦被打断(用户在派活途中插话),账本被记成 `ready`,子会话却还在后台跑——面板显示「待命」、看门狗关机、干完也没有任何回报。现在成员繁忙状态同时看会话实际运行态(新增 `host/live-watch.js` 订阅子会话 `agent/status`);派活被打断时不再收 `ready`,任务保留 `running` 并标 `detached`,由后台接力每 3 秒查子会话是否真说完,拿到答复再收尾并广播 `task-done`。②热重载后新子会话头像回落主会话:`team-mode.js` 的 `dispose()` 漏撤 `identity-map` 与 `session-bot` 两条 exact 路由,重载时新实例撞 `duplicate exact route` 注册失败,`/dsh-team/identity-map` 一直由已卸载的旧实例供数、数据冻结在重载那一刻。现已补进撤单清单;客户端身份映射改为并行拉 `tasks`/`roster` 现拼,不再单依赖 `identity-map`。另:`host/runtime.js` 的 `tools.js`/`team-mode.js` 改成带版本参数的动态 import,翻开关即可热加载。
|
|
49
51
|
- `0.5.4`:任务依赖图(验收门、整链超时/取消、重启恢复)、强制审查链、成员信箱、窄版工作区、P1 三项、第 7 步文档;修复监考提醒被当成任务结果、晋升感言串段、窄面板名字截断。
|
|
50
52
|
- `0.5.3`:团队设置面板三处 —— 称谓框不再被限定成数字;「超时」改名「单任务最长运行(秒)」,卡住提醒的三个参数收进设置不再摆在面板上;新建组面板里还没建组时,导出/导入先提示「请先创建组」。交付目录说明更正为文档目录。
|
|
@@ -56,4 +58,4 @@ dsh plugin add <包名或本地路径>
|
|
|
56
58
|
- `0.2.0`:任务详情与重试、成本统计、能力卡与团队记忆编辑、Bot 交接、系统通知、模板、近实时刷新。
|
|
57
59
|
- `0.1.0`:派活、验收、产物收集、记忆快照、名册与面板。
|
|
58
60
|
|
|
59
|
-
`package.json` 现在是 `0.7.
|
|
61
|
+
`package.json` 现在是 `0.7.3`。发的时候跑一遍上面的检查。
|
package/host/tools.js
CHANGED
|
@@ -392,6 +392,57 @@ export async function readSessionTurnReply(sessionId, afterTime, root = join(hom
|
|
|
392
392
|
return final
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
+
/**
|
|
396
|
+
* 只看「这一轮有没有结束」,不要求有 assistant 文本。
|
|
397
|
+
*
|
|
398
|
+
* 有的回合收尾只有工具调用、没有最后一句;`readSessionTurnReply` 会一直返回空,
|
|
399
|
+
* 父会话就会误以为它还在跑。detach 的后台 watcher 和 continueTask 用它兜底:
|
|
400
|
+
* 看到 `turn/end` 就算这一轮结束,文本可以为空。
|
|
401
|
+
*
|
|
402
|
+
* @param sessionId - 子会话 id。
|
|
403
|
+
* @param afterTime - 只要这个时间之后开始的轮次(epoch ms)。
|
|
404
|
+
* @param root - sessions 根目录。
|
|
405
|
+
* @returns 该轮是否已经结束。
|
|
406
|
+
*/
|
|
407
|
+
export async function readSessionTurnEnded(sessionId, afterTime, root = join(homedir(), '.dsh', 'sessions')) {
|
|
408
|
+
const file = await findSessionFile(sessionId, root)
|
|
409
|
+
if (!file) return false
|
|
410
|
+
let buffer
|
|
411
|
+
try {
|
|
412
|
+
buffer = await readFile(file)
|
|
413
|
+
} catch {
|
|
414
|
+
return false
|
|
415
|
+
}
|
|
416
|
+
const from = Math.max(0, buffer.length - SESSION_TAIL_BYTES)
|
|
417
|
+
let offset = buffer.indexOf(ZSTD_MAGIC, from)
|
|
418
|
+
let turnStarted = 0
|
|
419
|
+
let ended = false
|
|
420
|
+
while (offset !== -1) {
|
|
421
|
+
let text = ''
|
|
422
|
+
try {
|
|
423
|
+
text = zstdDecompressSync(buffer.subarray(offset)).toString('utf8')
|
|
424
|
+
} catch {
|
|
425
|
+
text = ''
|
|
426
|
+
}
|
|
427
|
+
for (const line of text.split('\n')) {
|
|
428
|
+
if (line.trim() === '') continue
|
|
429
|
+
let event
|
|
430
|
+
try {
|
|
431
|
+
event = JSON.parse(line)
|
|
432
|
+
} catch {
|
|
433
|
+
continue
|
|
434
|
+
}
|
|
435
|
+
if (event?.type === 'turn/start') {
|
|
436
|
+
turnStarted = Number(event?.time ?? 0)
|
|
437
|
+
} else if (event?.type === 'turn/end' && turnStarted >= afterTime) {
|
|
438
|
+
ended = true
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
offset = buffer.indexOf(ZSTD_MAGIC, offset + 4)
|
|
442
|
+
}
|
|
443
|
+
return ended
|
|
444
|
+
}
|
|
445
|
+
|
|
395
446
|
/**
|
|
396
447
|
* 读「某时刻之后收到的最新一句 assistant 文本」,不等 turn/end。
|
|
397
448
|
*
|
|
@@ -574,6 +625,7 @@ export async function waitForSessionTurnReply(sessionId, afterTime, timeoutMs, o
|
|
|
574
625
|
let loopWarned = false
|
|
575
626
|
let lastDigestAt = 0
|
|
576
627
|
let ignoreGrowthUntil = 0
|
|
628
|
+
let lastTurnEndCheck = 0
|
|
577
629
|
const nudge = typeof options.nudge === 'function' ? options.nudge : null
|
|
578
630
|
const cancel = typeof options.cancel === 'function' ? options.cancel : null
|
|
579
631
|
// 提醒本身会写进子会话,不能让它把自己的写入当成「BOT 还在动」。
|
|
@@ -608,6 +660,11 @@ export async function waitForSessionTurnReply(sessionId, afterTime, timeoutMs, o
|
|
|
608
660
|
const text = readFallback()
|
|
609
661
|
if (fresh(text)) return { text, why: 'ok' }
|
|
610
662
|
}
|
|
663
|
+
// 有的回合只有工具调用、没有最后一句;看到 turn/end 也算结束。
|
|
664
|
+
if (options.acceptEmptyTurnEnd && Date.now() - lastTurnEndCheck >= 3000) {
|
|
665
|
+
lastTurnEndCheck = Date.now()
|
|
666
|
+
if (await readSessionTurnEnded(sessionId, afterTime, root)) return { text: '', why: 'ok' }
|
|
667
|
+
}
|
|
611
668
|
if (!file) {
|
|
612
669
|
file = await findSessionFile(sessionId, root)
|
|
613
670
|
attach()
|
|
@@ -1413,7 +1470,30 @@ export function registerTeamTools(ctx, options) {
|
|
|
1413
1470
|
* 只读不打断——它在干活,别去碰它。
|
|
1414
1471
|
*/
|
|
1415
1472
|
function watchDetachedTask({ taskId, bot, sessionId, startedAt, exec }) {
|
|
1416
|
-
const
|
|
1473
|
+
const fallbackDeadline = Date.now() + 4 * 60 * 60 * 1000
|
|
1474
|
+
const notifyParent = async (row, text) => {
|
|
1475
|
+
try {
|
|
1476
|
+
const child = liveChildren.get(sessionId) ?? agents?.get?.(sessionId) ?? null
|
|
1477
|
+
if (child && row.parentSession && subagents?.sendMessage) {
|
|
1478
|
+
await subagents.sendMessage(
|
|
1479
|
+
child,
|
|
1480
|
+
row.parentSession,
|
|
1481
|
+
[{ type: 'text', text }],
|
|
1482
|
+
{ signal: new AbortController().signal },
|
|
1483
|
+
)
|
|
1484
|
+
void debug?.({ event: 'detached-notify', taskId, ok: true })
|
|
1485
|
+
} else {
|
|
1486
|
+
void debug?.({
|
|
1487
|
+
event: 'detached-notify',
|
|
1488
|
+
taskId,
|
|
1489
|
+
ok: false,
|
|
1490
|
+
reason: child ? 'no-parent' : 'no-child',
|
|
1491
|
+
})
|
|
1492
|
+
}
|
|
1493
|
+
} catch (error) {
|
|
1494
|
+
void debug?.({ event: 'detached-notify', taskId, ok: false, error: String(error?.message ?? error) })
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1417
1497
|
let ticking = false
|
|
1418
1498
|
const timer = setInterval(async () => {
|
|
1419
1499
|
if (ticking) return
|
|
@@ -1424,27 +1504,38 @@ export function registerTeamTools(ctx, options) {
|
|
|
1424
1504
|
clearInterval(timer)
|
|
1425
1505
|
return
|
|
1426
1506
|
}
|
|
1507
|
+
const deadline = Number(row.detachedDeadlineMs) || fallbackDeadline
|
|
1427
1508
|
if (Date.now() > deadline) {
|
|
1428
1509
|
row.status = 'timeout'
|
|
1429
1510
|
row.doneAt = Date.now()
|
|
1430
|
-
row.note = '
|
|
1511
|
+
row.note = '后台接力超时:派活已返回,一直没等到这一轮说完'
|
|
1431
1512
|
delete row.detached
|
|
1513
|
+
delete row.detachedDeadlineMs
|
|
1514
|
+
running.delete(taskId)
|
|
1515
|
+
pending.delete(sessionId)
|
|
1432
1516
|
forgetChild(sessionId)
|
|
1433
1517
|
void persistTasks?.()
|
|
1434
1518
|
options.api?.broadcast?.({ type: 'tasks' })
|
|
1519
|
+
await notifyParent(row, `【团队】${bot.name ?? bot.id} 的 ${taskId} 超时了(后台补报):派活已返回,但一直没等到这一轮说完。`)
|
|
1435
1520
|
void debug?.({ event: 'detached-timeout', taskId, bot: bot.id })
|
|
1436
1521
|
clearInterval(timer)
|
|
1437
1522
|
return
|
|
1438
1523
|
}
|
|
1439
1524
|
const text = await readSessionTurnReply(sessionId, startedAt)
|
|
1440
|
-
|
|
1525
|
+
// 有的回合没有最后一句;turn/end 到了也算干完,别让父会话一直等。
|
|
1526
|
+
if (!text && !(await readSessionTurnEnded(sessionId, startedAt))) return
|
|
1441
1527
|
const usage = usageBook?.take?.(sessionId)
|
|
1442
1528
|
if (usage) row.tokens = usage
|
|
1443
1529
|
row.status = 'ready'
|
|
1444
1530
|
row.doneAt = Date.now()
|
|
1445
1531
|
row.output = text.slice(0, 4000)
|
|
1446
|
-
row.note =
|
|
1532
|
+
row.note = text
|
|
1533
|
+
? '后台接力补记:派活已返回,这一轮结果是后台补记的'
|
|
1534
|
+
: '后台接力补记:这一轮没有文字产出,去看交付物'
|
|
1447
1535
|
delete row.detached
|
|
1536
|
+
delete row.detachedDeadlineMs
|
|
1537
|
+
running.delete(taskId)
|
|
1538
|
+
pending.delete(sessionId)
|
|
1448
1539
|
forgetChild(sessionId)
|
|
1449
1540
|
void persistTasks?.()
|
|
1450
1541
|
options.api?.broadcast?.({ type: 'tasks' })
|
|
@@ -1458,33 +1549,12 @@ export function registerTeamTools(ctx, options) {
|
|
|
1458
1549
|
void maybeQueueReview(row, exec)
|
|
1459
1550
|
void debug?.({ event: 'detached-finish', taskId, bot: bot.id, bytes: text.length })
|
|
1460
1551
|
// 账本变了不会自己开一轮,所以让子会话给秘书发一条消息,把秘书叫醒。
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
row.parentSession,
|
|
1468
|
-
[
|
|
1469
|
-
{
|
|
1470
|
-
type: 'text',
|
|
1471
|
-
text: `【团队】${bot.name ?? bot.id} 的 ${taskId} 已经干完(派活调用被中断,这条是后台补报的):\n${String(text).slice(0, 800)}`,
|
|
1472
|
-
},
|
|
1473
|
-
],
|
|
1474
|
-
{ signal: new AbortController().signal },
|
|
1475
|
-
)
|
|
1476
|
-
void debug?.({ event: 'detached-notify', taskId, ok: true })
|
|
1477
|
-
} else {
|
|
1478
|
-
void debug?.({
|
|
1479
|
-
event: 'detached-notify',
|
|
1480
|
-
taskId,
|
|
1481
|
-
ok: false,
|
|
1482
|
-
reason: child ? 'no-parent' : 'no-child',
|
|
1483
|
-
})
|
|
1484
|
-
}
|
|
1485
|
-
} catch (error) {
|
|
1486
|
-
void debug?.({ event: 'detached-notify', taskId, ok: false, error: String(error?.message ?? error) })
|
|
1487
|
-
}
|
|
1552
|
+
await notifyParent(
|
|
1553
|
+
row,
|
|
1554
|
+
text
|
|
1555
|
+
? `【团队】${bot.name ?? bot.id} 的 ${taskId} 已经干完(后台补报):\n${String(text).slice(0, 800)}`
|
|
1556
|
+
: `【团队】${bot.name ?? bot.id} 的 ${taskId} 已经干完(后台补报):这一轮没有文字产出,去看交付物。`,
|
|
1557
|
+
)
|
|
1488
1558
|
clearInterval(timer)
|
|
1489
1559
|
} finally {
|
|
1490
1560
|
ticking = false
|
|
@@ -1799,6 +1869,10 @@ export function registerTeamTools(ctx, options) {
|
|
|
1799
1869
|
|
|
1800
1870
|
const botId = String(args?.bot ?? '').trim()
|
|
1801
1871
|
const task = String(args?.task ?? '').trim()
|
|
1872
|
+
const detach = args?.detach === true
|
|
1873
|
+
if (detach && args?.__batch === true) {
|
|
1874
|
+
return JSON.stringify({ status: 'failed', error: 'detach 只能单件用;批量派活请用 team_dispatch_many 的默认同步模式' })
|
|
1875
|
+
}
|
|
1802
1876
|
if (!botId || !task) {
|
|
1803
1877
|
return JSON.stringify({ status: 'failed', error: 'bot and task are required' })
|
|
1804
1878
|
}
|
|
@@ -1859,6 +1933,7 @@ export function registerTeamTools(ctx, options) {
|
|
|
1859
1933
|
].join('\n')
|
|
1860
1934
|
const continued = await continueTask(previous, {
|
|
1861
1935
|
prompt,
|
|
1936
|
+
detach,
|
|
1862
1937
|
brief: {
|
|
1863
1938
|
task,
|
|
1864
1939
|
goal: args?.goal,
|
|
@@ -2151,6 +2226,40 @@ export function registerTeamTools(ctx, options) {
|
|
|
2151
2226
|
// 入组失败不影响派活
|
|
2152
2227
|
}
|
|
2153
2228
|
|
|
2229
|
+
let detached = false
|
|
2230
|
+
if (detach) {
|
|
2231
|
+
const entry = tasks?.get(taskId)
|
|
2232
|
+
if (entry) {
|
|
2233
|
+
entry.detached = true
|
|
2234
|
+
entry.status = 'running'
|
|
2235
|
+
entry.note = '后台接力:派活已返回,完成时自动补记'
|
|
2236
|
+
entry.detachedDeadlineMs = Date.now() + Math.max(60_000, taskTimeoutMs() * 2)
|
|
2237
|
+
delete entry.doneAt
|
|
2238
|
+
void persistTasks?.()
|
|
2239
|
+
options.api?.broadcast?.({ type: 'tasks' })
|
|
2240
|
+
watchDetachedTask({
|
|
2241
|
+
taskId,
|
|
2242
|
+
bot,
|
|
2243
|
+
sessionId: started.childId ?? childId,
|
|
2244
|
+
startedAt: entry.startedAt ?? Date.now(),
|
|
2245
|
+
exec,
|
|
2246
|
+
})
|
|
2247
|
+
}
|
|
2248
|
+
detached = true
|
|
2249
|
+
stallWatch.stop()
|
|
2250
|
+
started.result?.catch?.(() => {})
|
|
2251
|
+
await debug?.({ event: 'dispatch-detached', taskId, bot: bot.id, sessionId: started.childId ?? childId })
|
|
2252
|
+
return JSON.stringify({
|
|
2253
|
+
status: 'running',
|
|
2254
|
+
bot: bot.id,
|
|
2255
|
+
taskId,
|
|
2256
|
+
sessionId: started.childId ?? childId,
|
|
2257
|
+
cwd: taskDir,
|
|
2258
|
+
detached: true,
|
|
2259
|
+
message: '已派出,不等这一轮。干完会自动补账并给你发消息;审计也会在完成时自动建。',
|
|
2260
|
+
})
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2154
2263
|
try {
|
|
2155
2264
|
// `result` settles after the child's teardown; `output` is its final
|
|
2156
2265
|
// assistant text, so the tool can return the answer synchronously.
|
|
@@ -2348,9 +2457,11 @@ export function registerTeamTools(ctx, options) {
|
|
|
2348
2457
|
error: String(error?.message ?? error),
|
|
2349
2458
|
})
|
|
2350
2459
|
} finally {
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2460
|
+
if (!detached) {
|
|
2461
|
+
pending.delete(childId)
|
|
2462
|
+
running.delete(taskId)
|
|
2463
|
+
}
|
|
2464
|
+
const entry = detached ? null : tasks?.get(taskId)
|
|
2354
2465
|
if (entry) {
|
|
2355
2466
|
// 真实 token:子会话这一趟跑掉的全部 usage,结算时一次性领走。
|
|
2356
2467
|
const usage = usageBook?.take?.(started?.childId ?? childId)
|
|
@@ -2380,7 +2491,7 @@ export function registerTeamTools(ctx, options) {
|
|
|
2380
2491
|
startedAt: entry.startedAt ?? Date.now(),
|
|
2381
2492
|
exec,
|
|
2382
2493
|
})
|
|
2383
|
-
} else {
|
|
2494
|
+
} else if (!detached) {
|
|
2384
2495
|
// 只把「还在跑」的行收成 ready:失败 / 超时 / 取消已经写过自己的状态,别覆盖。
|
|
2385
2496
|
if (entry && (!entry.status || entry.status === 'running')) {
|
|
2386
2497
|
entry.doneAt = Date.now()
|
|
@@ -2422,6 +2533,7 @@ export function registerTeamTools(ctx, options) {
|
|
|
2422
2533
|
*/
|
|
2423
2534
|
async function continueTask(entry, request, exec) {
|
|
2424
2535
|
const prompt = String(request?.prompt ?? '').trim()
|
|
2536
|
+
const detach = request?.detach === true
|
|
2425
2537
|
const brief = request?.brief ?? entry?.brief ?? null
|
|
2426
2538
|
const sessionId = String(entry?.sessionId ?? '').trim()
|
|
2427
2539
|
const baseline = String(entry?.output ?? '')
|
|
@@ -2461,6 +2573,27 @@ export function registerTeamTools(ctx, options) {
|
|
|
2461
2573
|
void persistTasks?.()
|
|
2462
2574
|
options.api?.broadcast?.({ type: 'tasks' })
|
|
2463
2575
|
await debug?.({ event: 'continue', from: entry.taskId, taskId, sessionId, retried: request?.retried === true })
|
|
2576
|
+
if (detach) {
|
|
2577
|
+
const row = tasks?.get(taskId)
|
|
2578
|
+
if (row) {
|
|
2579
|
+
row.detached = true
|
|
2580
|
+
row.note = '后台接力:派活已返回,完成时自动补记'
|
|
2581
|
+
row.detachedDeadlineMs = Date.now() + Math.max(60_000, taskTimeoutMs() * 2)
|
|
2582
|
+
void persistTasks?.()
|
|
2583
|
+
options.api?.broadcast?.({ type: 'tasks' })
|
|
2584
|
+
watchDetachedTask({ taskId, bot, sessionId, startedAt: continuedAt, exec })
|
|
2585
|
+
}
|
|
2586
|
+
await debug?.({ event: 'continue-detached', from: entry.taskId, taskId, sessionId })
|
|
2587
|
+
return {
|
|
2588
|
+
status: 'running',
|
|
2589
|
+
bot: bot.id,
|
|
2590
|
+
taskId,
|
|
2591
|
+
sessionId,
|
|
2592
|
+
cwd: taskDir,
|
|
2593
|
+
detached: true,
|
|
2594
|
+
message: '已接回原会话,不等这一轮。干完会自动补账并给你发消息;审计也会在完成时自动建。',
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2464
2597
|
let probedAt = 0
|
|
2465
2598
|
const readContinuedAgent = () => {
|
|
2466
2599
|
const live = liveChildren.get(sessionId) ?? null
|
|
@@ -2484,6 +2617,8 @@ export function registerTeamTools(ctx, options) {
|
|
|
2484
2617
|
stallAskMs: Number(getSettings()?.stallHardSec ?? 300) * 1000,
|
|
2485
2618
|
stallGraceMs: Number(getSettings()?.stallGraceSec ?? 120) * 1000,
|
|
2486
2619
|
stallMaxNormal: 10,
|
|
2620
|
+
// 续聊的回合可能没有最后一句,看到 turn/end 就收尾,别空等。
|
|
2621
|
+
acceptEmptyTurnEnd: true,
|
|
2487
2622
|
// agent 侧只作兜底:恢复出来的会话有时 status=idle 但 session 里没有任何事件。
|
|
2488
2623
|
readFallback: () => {
|
|
2489
2624
|
const agent = readContinuedAgent()
|
|
@@ -2521,6 +2656,7 @@ export function registerTeamTools(ctx, options) {
|
|
|
2521
2656
|
else if (why === 'loop') row.note = '子会话在原地打转(同一工具、同一组参数调用 8 次),已提前结束'
|
|
2522
2657
|
else if (why === 'timeout') row.note = `续聊超过 ${Math.round(taskTimeoutMs() / 1000)} 秒没回来`
|
|
2523
2658
|
else if (text !== '') row.output = text.slice(0, 4000)
|
|
2659
|
+
else row.note = '这一轮没有文字产出,去看交付物'
|
|
2524
2660
|
if (usage) row.tokens = usage
|
|
2525
2661
|
}
|
|
2526
2662
|
void persistTasks?.()
|
|
@@ -3171,7 +3307,7 @@ export function registerTeamTools(ctx, options) {
|
|
|
3171
3307
|
{
|
|
3172
3308
|
name: 'team_dispatch',
|
|
3173
3309
|
description:
|
|
3174
|
-
'把一件活派给团队里的某个 Bot。Bot 在自己的任务会话里干活(只能写工作区,写不出去),干完返回结论。同一件成果的修改 / 补充 / 优化,用 continueFrom
|
|
3310
|
+
'把一件活派给团队里的某个 Bot。Bot 在自己的任务会话里干活(只能写工作区,写不出去),干完返回结论。同一件成果的修改 / 补充 / 优化,用 continueFrom 接回原会话;和上一件无关的新活不要填,直接新开。默认同步等结果;detach=true 时立刻返回任务号,不占主会话,Bot 完成/超时会发消息唤醒你,并自动建审计。',
|
|
3175
3311
|
parameters: {
|
|
3176
3312
|
bot: { type: 'string', required: true, description: 'Bot 的 id,例如 nova' },
|
|
3177
3313
|
task: { type: 'string', required: true, description: '任务单正文(一句话说清要干什么)' },
|
|
@@ -3186,6 +3322,7 @@ export function registerTeamTools(ctx, options) {
|
|
|
3186
3322
|
dependsOnMode: { type: 'string', description: 'done(默认,上游跑完就放行)或 accepted(上游验收通过才放行)。' },
|
|
3187
3323
|
dependsOnTimeoutSec: { type: 'number', description: '等依赖的最长秒数,默认 1800;超时则 blocked。' },
|
|
3188
3324
|
review: { type: 'boolean', description: '是否强制审计:默认有 deliverable 就 true;显式 false 可跳过。审计员的活不审。' },
|
|
3325
|
+
detach: { type: 'boolean', description: '异步派活:调用立刻返回任务号,不阻塞主会话;Bot 完成/超时会发消息唤醒你,并自动建审计。单件可用,批量不支持;continueFrom 也支持。' },
|
|
3189
3326
|
},
|
|
3190
3327
|
output: {
|
|
3191
3328
|
schema: { type: 'string' },
|
|
@@ -3209,7 +3346,7 @@ export function registerTeamTools(ctx, options) {
|
|
|
3209
3346
|
{
|
|
3210
3347
|
name: 'team_dispatch_many',
|
|
3211
3348
|
description:
|
|
3212
|
-
'一次派多件活,可声明依赖。带 dependsOn 的项等上游跑完再开;同一批里可以用 key 给任务起别名,dependsOn 直接写 key。互不依赖的项并行,最多按并发上限;某件失败/打回,它下游会标 blocked,不会 spawn。',
|
|
3349
|
+
'一次派多件活,可声明依赖。带 dependsOn 的项等上游跑完再开;同一批里可以用 key 给任务起别名,dependsOn 直接写 key。互不依赖的项并行,最多按并发上限;某件失败/打回,它下游会标 blocked,不会 spawn。批量默认同步汇总;单件异步用 team_dispatch 的 detach=true,批量不支持 detach。',
|
|
3213
3350
|
parameters: {
|
|
3214
3351
|
tasks: {
|
|
3215
3352
|
type: 'string',
|
|
@@ -4395,6 +4532,12 @@ export function registerTeamTools(ctx, options) {
|
|
|
4395
4532
|
if (row?.sessionId !== sid || row.status !== 'chat') continue
|
|
4396
4533
|
return row.chatKind === 'private' ? 'private' : 'work'
|
|
4397
4534
|
}
|
|
4535
|
+
// 派活/审计任务完成后 status 不是 'chat',但会话仍是 Bot 的工作聊天。
|
|
4536
|
+
// 只按 status === 'chat' 会把这些会话当普通会话,界面于是又露出「团队协作」开关。
|
|
4537
|
+
for (const row of tasks.values()) {
|
|
4538
|
+
if (row?.sessionId !== sid || !row?.bot) continue
|
|
4539
|
+
return row.chatKind === 'private' ? 'private' : 'work'
|
|
4540
|
+
}
|
|
4398
4541
|
try {
|
|
4399
4542
|
const state = await readPrivateState(root)
|
|
4400
4543
|
for (const entry of Object.values(state.bots ?? {})) {
|
package/package.json
CHANGED