Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Merge remote-tracking branch 'origin/fix/185-delegated-result-reaches-caller' into feat/262-bot-handoffs

Fei24113cb8d703f593
diff --cc ds-bot/client.js
index bc3e27bb,b616f78b..0447abcb
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@@ -4198,12 -4172,10 +4199,12 @@@ function TriggerCell({ node, sessionId
if (source.role === "kickoff" || source.role === "room") return null;
if (source.role === "secret" || deferred) return null;
if (source.role === "post") {
- if (source.failed !== void 0 || source.resumed === true || source.stopped === true) return null;
+ if (source.failed !== void 0 || source.resumed === true || source.stopped === true || source.done === true) return null;
const room2 = roster.roomsById[sessionId];
const poster = roster.byId[source.senderSessionId] ?? { id: source.senderSessionId, name: source.senderName ?? t("a Bot"), color: "gray" };
- return (0, import_react6.createElement)(GroupMessage, { bot: poster, text: stripHeader(contentText(data.content)), room: room2, roster, actions, msgKey: `${sessionId}:${data.turn}:post`, useUi });
+ const post = { bot: poster, text: stripHeader(contentText(data.content)), room: room2, roster, actions, msgKey: `${sessionId}:${data.turn}:post`, useUi };
+ const file = source.length === void 0 ? void 0 : (data.content ?? []).find((block) => block?.type === "file")?.attachment;
+ return file ? (0, import_react6.createElement)(LongPost, { ...post, file, length: source.length }) : (0, import_react6.createElement)(GroupMessage, post);
}
if (source.role === "report") {
return (0, import_react6.createElement)(GroupEvent, { prefix: t("Replies from"), room: roster.roomsById[source.roomId], name: t("a group chat"), roster, actions });
diff --cc ds-bot/src/client/cells.js
index bb7d62f5,6e09df9f..df251a0e
--- a/ds-bot/src/client/cells.js
+++ b/ds-bot/src/client/cells.js
@@@ -376,14 -351,12 +376,14 @@@ export function TriggerCell({ node, ses
// The secret card itself shows what the user did; the note to the Bot stays out.
if (source.role === 'secret' || deferred) return null
if (source.role === 'post') {
- // A member's late failure, its work picked up after a restart, or its work the user
- // stopped shows as an event of the round it opens.
- if (source.failed !== undefined || source.resumed === true || source.stopped === true) return null
+ // A member's late failure, its work picked up after a restart, its work the user
+ // stopped, or the end of its work shows as an event of the round it opens.
+ if (source.failed !== undefined || source.resumed === true || source.stopped === true || source.done === true) return null
const room = roster.roomsById[sessionId]
const poster = roster.byId[source.senderSessionId] ?? { id: source.senderSessionId, name: source.senderName ?? t('a Bot'), color: 'gray' }
- return h(GroupMessage, { bot: poster, text: stripHeader(contentText(data.content)), room, roster, actions, msgKey: `${sessionId}:${data.turn}:post`, useUi })
+ const post = { bot: poster, text: stripHeader(contentText(data.content)), room, roster, actions, msgKey: `${sessionId}:${data.turn}:post`, useUi }
+ const file = source.length === undefined ? undefined : (data.content ?? []).find(block => block?.type === 'file')?.attachment
+ return file ? h(LongPost, { ...post, file, length: source.length }) : h(GroupMessage, post)
}
if (source.role === 'report') {
return h(GroupEvent, { prefix: t('Replies from'), room: roster.roomsById[source.roomId], name: t('a group chat'), roster, actions })
diff --cc ds-bot/src/host/groups.js
index 3750a7ce,f53069d6..7d07933f
--- a/ds-bot/src/host/groups.js
+++ b/ds-bot/src/host/groups.js
@@@ -57,9 -58,10 +57,10 @@@ const lineText = (line, text = line.tex
if (line.kind === 'resumed') return `[${line.who}'s work here was cut off when DeepSeek Harness restarted; it is picking it back up and posts when done]`
if (line.kind === 'cut') return `[${line.who}'s work here was cut off by a restart again, so it stopped; ask it to go on if it still matters]`
if (line.kind === 'stopped') return `[The user stopped ${line.who}'s work here]`
+ if (line.kind === 'done') return `[${line.who} finished the work it was asked for]`
- return `${line.who}: ${line.text}`
+ return `${line.who}: ${text}`
}
-const transcript = lines => lines.map(lineText).join('\n')
+const transcript = (lines, textOfLine = line => line.text) => lines.map(line => lineText(line, textOfLine(line))).join('\n')
// Models often echo the transcript format ("Name: …") despite the instruction.
export const stripOwnName = (name, text) => text.replace(new RegExp(`^\\s*\\**${escapeRegExp(name)}\\**\\s*[::]\\s*`), '').trim()
@@@ -475,19 -413,15 +476,19 @@@ export function install(rt)
const posts = queued.length > 0 ? queued : [{ text: '' }]
const startSeq = room.seq + 1
// The opening greeting is a cue for the admin, not a line of the group; a member's
- // late failure, its work picked up after a restart, or its work the user stopped is
- // an event of the round.
- const event = item => item.failed || item.resumed || item.stopped
+ // late failure, its work picked up after a restart, its work the user stopped, or
+ // the end of work whose result it already posted is an event of the round.
+ const event = item => item.failed || item.resumed || item.stopped || item.done
for (const post of posts.filter(item => !item.kickoff && !event(item))) {
// Image readings go into the log only; `@` names are picked from what the user typed.
- const text = post.images === undefined ? post.text : [post.text, ...await rt.imagesForGroup(post.images, room.id)].filter(Boolean).join('\n')
- appendRoom(room, post.botId
- ? { who: rt.botOf(post.botId)?.name ?? post.name ?? 'Bot', botId: post.botId, text }
- : { who: 'User', text })
+ // A file stays with its line and reaches each member the line is shown to.
+ const readings = post.images === undefined ? [] : await rt.imagesForGroup(post.images, room.id)
+ const text = [post.text, ...readings, ...(post.files ?? []).map(fileLine)].filter(Boolean).join('\n')
+ appendRoom(room, {
+ ...(post.botId ? { who: rt.botOf(post.botId)?.name ?? post.name ?? 'Bot', botId: post.botId } : { who: 'User' }),
+ text,
+ ...(post.files === undefined ? {} : { files: post.files }),
+ })
}
if (posts.some(post => !post.botId && !post.kickoff)) {
room.botRounds = 0
diff --cc ds-bot/test/group-work.test.js
index 6ba4fe26,8927060c..199bd5bd
--- a/ds-bot/test/group-work.test.js
+++ b/ds-bot/test/group-work.test.js
@@@ -148,70 -148,62 +148,125 @@@ test('work past the grace lets the roun
assert.deepEqual(host.agentOf('gc').calls, [])
})
+// 公开#165: asked in a group to hand out work, Chief sent it with message_bot. Members
+// did it in their own chats, apart from the group (Bots outside the group too), and
+// again when called in the group.
+test('message_bot from a group to one of its members calls it there, as "@Name" would', async (t) => {
+ const host = await start(t)
+ const first = host.round('c1', host.say('@Chief 安排一下文档'))
+ await settle(() => host.agentOf('ga').calls.length === 1)
+ host.begin('ga')
+ const sent = await host.tool('message_bot', { to: 'Writer', message: '把文档整理好' }, 'ga')
+ assert.match(sent, /^Called Writer in "Ops"/)
+ host.finish('ga', '安排好了。')
+ await settle(() => host.agentOf('gb').calls.length === 1)
+ const called = host.begin('gb')
+ assert.equal(called.source.askedBy, 'a')
+ assert.match(text(called), /Chief: @Writer 把文档整理好/)
+ host.finish('gb', '整理好了。')
+ await settle(() => first() !== undefined)
+ assert.deepEqual(kinds(first()), [['message', 'Chief'], ['message', 'Chief'], ['message', 'Writer']])
+ assert.deepEqual([host.agentOf('b').calls, host.agentOf('gc').calls], [[], []])
+})
+
+test('message_bot from a member the round moved on from calls the other member in a round of its own', async (t) => {
+ t.mock.timers.enable({ apis: ['setTimeout'] })
+ const host = await start(t)
+ const first = host.round('c1', host.say('@Writer 整理文档'))
+ await settle(() => host.agentOf('gb').calls.length === 1)
+ host.begin('gb')
+ host.emit('gb', 'tool/call', { callId: 'k1', name: 'write', arguments: '{}' })
+ t.mock.timers.tick(ROOM_WORK_GRACE_MS)
+ await settle(() => first() !== undefined)
+ await host.tool('message_bot', { to: 'Tester', message: '帮我测一下' }, 'gb')
+ await settle(() => host.agentOf('r1').calls.length === 1)
+ const post = host.takePost()
+ assert.deepEqual([post.source.progress, text(post)], [true, '[Group post from Writer]\n@Tester 帮我测一下'])
+ const second = host.round('c2', post)
+ await settle(() => host.agentOf('gc').calls.length === 1)
+ assert.equal(host.begin('gc').source.askedBy, 'b')
+ host.finish('gc', '测过了。')
+ await settle(() => second() !== undefined)
+ assert.deepEqual(host.agentOf('c').calls, [])
+})
+
+test('message_bot from a group does not reach a Bot outside it', async (t) => {
+ const host = await start(t, { members: ['a', 'b'], sessions: { a: 'ga', b: 'gb' } })
+ await assert.rejects(host.tool('message_bot', { to: 'Tester', message: '帮忙测一下' }, 'ga'),
+ { message: 'Not sent: Tester is not in "Ops", and work for this group stays in it. Ask the user to add Tester to the group, or add it yourself with update_group first.' })
+ await assert.rejects(host.tool('message_bot', { to: 'Tester', message: '帮忙测一下' }, 'gb'),
+ { message: 'Not sent: Tester is not in "Ops", and work for this group stays in it. Ask the user to add Tester to the group.' })
+ assert.deepEqual([host.agentOf('c').calls, host.agentOf('r1').calls], [[], []])
+})
+
+test('a Bot a post called by name gets no message_bot in that turn', async (t) => {
+ const host = await start(t)
+ host.emit('a', 'turn/start', { turn: 1 })
+ await host.tool('post_to_group', { group: 'Ops', message: '@Writer 整理文档' }, 'a')
+ await assert.rejects(host.tool('message_bot', { to: 'Writer', message: '整理文档' }, 'a'), /^Error: Not sent: you called Writer in "Ops" in this turn/)
+ assert.deepEqual(host.agentOf('b').calls, [])
+ assert.match(await host.tool('message_bot', { to: 'Tester', message: '准备测试' }, 'a'), /^Delivered to Tester/)
+ host.emit('a', 'turn/end', { turn: 1, reason: { kind: 'completed' } })
+ host.emit('a', 'turn/start', { turn: 2 })
+ assert.match(await host.tool('message_bot', { to: 'Writer', message: '进度如何?' }, 'a'), /^Delivered to Writer/)
+})
+
+ // 公开#185: the result went out as the work's first step line, next to one last tool
+ // call, and the turn then ended with an empty reply. Chief, which asked for the work,
+ // was never called to answer it.
+ const resultAsStep = async (t, ask) => {
+ t.mock.timers.enable({ apis: ['setTimeout'] })
+ const host = await start(t)
+ const first = host.round('c1', host.say(ask))
+ if (ask.startsWith('@Chief')) {
+ await settle(() => host.agentOf('ga').calls.length === 1)
+ host.begin('ga')
+ host.finish('ga', '@Writer 把文档整理好')
+ }
+ await settle(() => host.agentOf('gb').calls.length === 1)
+ host.begin('gb')
+ host.emit('gb', 'tool/call', { callId: 'k1', name: 'pwsh', arguments: '{}' })
+ t.mock.timers.tick(ROOM_WORK_GRACE_MS)
+ await settle(() => first() !== undefined)
+ host.emit('gb', 'tool/result', { callId: 'k1' })
+ host.emit('gb', 'assistant/message', { message: { content: [{ type: 'text', text: '整理好了,在 docs/ 下。' }, { type: 'tool-call', id: 'k2', name: 'pwsh', arguments: '{}' }] } })
+ host.emit('gb', 'tool/call', { callId: 'k2', name: 'pwsh', arguments: '{}' })
+ await settle(() => host.agentOf('r1').calls.length === 1)
+ const step = host.takePost()
+ assert.deepEqual([step.source.progress, step.source.quiet, text(step)], [true, true, '[Group post from Writer]\n整理好了,在 docs/ 下。'])
+ const stepRound = host.round('c2', step)
+ await settle(() => stepRound() !== undefined)
+ host.emit('gb', 'tool/result', { callId: 'k2' })
+ host.finish('gb', '')
+ return host
+ }
+
+ test('late work whose result went out as a step line still tells the member that asked, which answers it', async (t) => {
+ const host = await resultAsStep(t, '@Chief 安排一下文档')
+ await settle(() => host.agentOf('r1').calls.length === 1)
+ const done = host.takePost()
+ assert.deepEqual([done.source.done, done.source.late, done.source.askedBy], [true, true, 'a'])
+ const third = host.round('c3', done)
+ await settle(() => host.agentOf('ga').calls.length === 2)
+ const prompt = text(host.agentOf('ga').calls[1])
+ assert.match(prompt, /Writer finished the work you asked for/)
+ assert.match(prompt, /Writer: 整理好了,在 docs\/ 下。/)
+ host.begin('ga')
+ host.finish('ga', '收到,辛苦了。')
+ await settle(() => third() !== undefined)
+ assert.deepEqual(kinds(third()), [['done', 'Writer'], ['message', 'Chief']])
+ assert.deepEqual(host.agentOf('gc').calls, [])
+ const log = JSON.parse(readFileSync(join(host.home, 'state.json'), 'utf8')).rooms.r1.log.map(line => [line.who, line.kind ?? 'message'])
+ assert.deepEqual(log.slice(-3), [['Writer', 'message'], ['Writer', 'done'], ['Chief', 'message']])
+ })
+
+ test('late work the user asked for directly ends without a post once its result is out', async (t) => {
+ const host = await resultAsStep(t, '@Writer 把文档整理好')
+ for (let i = 0; i < 20; i += 1) await new Promise(resolve => setImmediate(resolve))
+ assert.deepEqual(host.agentOf('r1').calls, [])
+ })
+
-test('a Bot\'s post keeps its hop through the round, the member\'s late reply and its own messages', async (t) => {
+test('a Bot\'s post keeps its hop through the round, the members it calls and the member\'s late reply', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout'] })
const host = await start(t)
host.emit('a', 'turn/start', { turn: 1 })