A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Tell the member that asked for work when it ends after its result is out
Fei24111fdbb57469c4
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 9b5e894a..b616f78b 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -503,6 +503,7 @@ var ZH = {"{name} paused for your approval": "{name} 停下来等你批准","{name} started on it": "{name} 开始做了","You stopped {name}'s work": "你停下了 {name} 的工作",+ "{name} finished its work": "{name} 做完了","{name} was cut off by a restart and picked its work back up": "{name} 的工作被重启打断,已经接着做","{name} was cut off by a restart again and stopped": "{name} 的工作又被重启打断,已停下","Picked up its work after a restart": "重启后接着做之前的工作",@@ -4171,7 +4172,7 @@ function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnClock, usif (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 });@@ -4451,6 +4452,9 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUiif (reply.kind === "stopped") {return (0, import_react6.createElement)("div", { key: `${reply.botId}-${index}`, className: "bt-event" }, t("You stopped {name}'s work", { name: bot.name }));}+ if (reply.kind === "done") {+ return (0, import_react6.createElement)("div", { key: `${reply.botId}-${index}`, className: "bt-event" }, t("{name} finished its work", { name: bot.name }));+ }return (0, import_react6.createElement)(GroupMessage, { key: `${reply.botId}-${index}`, bot, texts: texts2, room: room2, roster, actions, msgKey: callId ? `${sessionId}:${callId}:${index}` : void 0, useUi });}),pending.map((id) => {diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.jsindex 2695e45d..6e09df9f 100644--- a/ds-bot/src/client/cells.js+++ b/ds-bot/src/client/cells.js@@ -351,9 +351,9 @@ export function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnCl// The secret card itself shows what the user did; the note to the Bot stays out.if (source.role === 'secret' || deferred) return nullif (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 nullconst 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 })@@ -619,6 +619,9 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUiif (reply.kind === 'stopped') {return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' }, t("You stopped {name}'s work", { name: bot.name }))}+ if (reply.kind === 'done') {+ return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' }, t('{name} finished its work', { name: bot.name }))+ }return h(GroupMessage, { key: `${reply.botId}-${index}`, bot, texts, room, roster, actions, msgKey: callId ? `${sessionId}:${callId}:${index}` : undefined, useUi })}),pending.map((id) => {diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.jsindex 83b39980..d6aac1bf 100644--- a/ds-bot/src/client/i18n.js+++ b/ds-bot/src/client/i18n.js@@ -447,6 +447,7 @@ const ZH = {'{name} paused for your approval': '{name} 停下来等你批准','{name} started on it': '{name} 开始做了',"You stopped {name}'s work": '你停下了 {name} 的工作',+ '{name} finished its work': '{name} 做完了','{name} was cut off by a restart and picked its work back up': '{name} 的工作被重启打断,已经接着做','{name} was cut off by a restart again and stopped': '{name} 的工作又被重启打断,已停下','Picked up its work after a restart': '重启后接着做之前的工作',diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.jsindex 9f636fd5..f53069d6 100644--- a/ds-bot/src/host/groups.js+++ b/ds-bot/src/host/groups.js@@ -58,6 +58,7 @@ const lineText = (line) => {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}`}const transcript = lines => lines.map(lineText).join('\n')@@ -412,9 +413,9 @@ 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.donefor (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')@@ -444,6 +445,7 @@ export function install(rt) {id: member.id, name: member.name, status: 'waiting',...(opener.kickoff ? { note: 'the group was just created' } : {}),...(named.includes(member) ? { by: opener.botId } : {}),+ ...(opener.done ? { note: `${opener.name ?? 'a member'} finished the work you asked for` } : {}),})),speaking: null,turns: 0,@@ -459,14 +461,14 @@ export function install(rt) {round.replies.push({ kind: 'failed', botId: post.botId, name: bot?.name ?? post.name, color: bot?.color, code, ...(status ? { status } : {}), text: message, time: Date.now() })}// The log line tells the admin and the other members on their next turn.- for (const post of posts.filter(item => item.resumed || item.stopped)) {+ for (const post of posts.filter(item => item.resumed || item.stopped || item.done)) {const bot = rt.botOf(post.botId)const name = bot?.name ?? post.name- const kind = post.stopped ? 'stopped' : post.again ? 'cut' : 'resumed'+ const kind = post.done ? 'done' : post.stopped ? 'stopped' : post.again ? 'cut' : 'resumed'appendRoom(room, { who: name, botId: post.botId, kind, text: '' })round.replies.push({ kind, botId: post.botId, name, color: bot?.color, time: Date.now() })}- if (posts.some(post => post.resumed || post.stopped)) await rt.save()+ if (posts.some(post => post.resumed || post.stopped || post.done)) await rt.save()rt.roomProgress.set(exec.callId, round)try {await runRound(room, round, exec.signal, exec.agent)@@ -570,6 +572,7 @@ export function install(rt) {const admin = members.find(bot => rt.isAdminOf(room, bot.id))if (opener.kickoff) return admin ? [admin] : []if (opener.quiet) return []+ if (opener.done) return members.filter(bot => bot.id === opener.askedBy)const { all, found: named } = mentionsIn(opener.text, everyone, opener.references)const found = named.filter(bot => bot.id !== opener.botId)if (opener.progress) return found@@ -593,18 +596,21 @@ export function install(rt) {// A member the round moved on from (it went on working, went quiet or waited for an// approval) posts what its turn ended with. The member that asked for it and anyone// it names answer; past the late round limit nobody does, so late posts cannot keep a- // group talking.- async function lateRoomReply(sessionId, info, reply) {+ // group talking. Work whose result already went out as a step line (`shown`) and+ // that ends with nothing more to say still tells the member that asked for it, which+ // answers the result: where the result sits in the turn decides nothing.+ async function lateRoomReply(sessionId, info, reply, { shown = false } = {}) {const owner = rt.groupOwners.get(sessionId)const room = rt.roomOf(owner?.roomId ?? info.roomId)const member = rt.botOf(owner?.botId)if (room === undefined || member === undefined || !room.members.includes(member.id)) returnconst text = stripOwnName(member.name, reply)- if (isPass(text)) return+ const done = isPass(text) && shown && info.askedBy !== undefined+ if (isPass(text) && !done) returnconst quiet = (room.lateRounds ?? 0) >= ROOM_LATE_ROUNDSif (!quiet) room.lateRounds = (room.lateRounds ?? 0) + 1await rt.save()- await postToRoom(room, member, text, { late: true, hop: info.hop ?? 0, ...(info.askedBy ? { askedBy: info.askedBy } : {}), ...(quiet ? { quiet: true } : {}) })+ await postToRoom(room, member, done ? '' : text, { late: true, hop: info.hop ?? 0, ...(done ? { done: true } : {}), ...(info.askedBy ? { askedBy: info.askedBy } : {}), ...(quiet ? { quiet: true } : {}) }).catch(error => rt.warn('ds-bot: late group reply from %s failed: %s', member.name, error))}rt.lateRoomReply = lateRoomReplydiff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.jsindex ba4bd434..2cb89539 100644--- a/ds-bot/src/host/turns.js+++ b/ds-bot/src/host/turns.js@@ -384,6 +384,7 @@ export function install(rt) {...(source.resumed ? { resumed: true } : {}),...(source.again ? { again: true } : {}),...(source.stopped ? { stopped: true } : {}),+ ...(source.done ? { done: true } : {}),...(source.askedBy ? { askedBy: source.askedBy } : {}),})} else if (source?.kind === SOURCE_KIND && source.role === 'kickoff' && rt.roomOf(id)) {@@ -443,6 +444,7 @@ export function install(rt) {const joined = entry.joined ?? []// What the group already saw of the turn is not posted again.const texts = entry.texts.slice(entry.shown)+ const shown = entry.shown > 0const { lastText, lastCalled } = entry// A turn stopped for a switch goes on in the next part, which answers instead.const switched = entry.switched === true@@ -519,11 +521,11 @@ export function install(rt) {} else if (!stopped && reason?.kind !== 'aborted') {// The round moved on without this member; how its turn ends still reaches the group.if (failure !== undefined) void rt.lateRoomFailure?.(id, info, failure)- else void rt.lateRoomReply?.(id, info, groupReply())+ else void rt.lateRoomReply?.(id, info, groupReply(), { shown })}} else if (!retry && speaksInGroup(id, info)) {if (failure !== undefined) void rt.lateRoomFailure?.(id, info ?? {}, failure)- else if (reason?.kind !== 'aborted') void rt.lateRoomReply?.(id, info ?? {}, groupReply())+ else if (reason?.kind !== 'aborted') void rt.lateRoomReply?.(id, info ?? {}, groupReply(), { shown })} else if (!retry && info !== undefined) {answer(info, replyText())}diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.jsindex 66f9267a..8927060c 100644--- a/ds-bot/test/group-work.test.js+++ b/ds-bot/test/group-work.test.js@@ -148,6 +148,61 @@ test('work past the grace lets the round go on, and the member that asked answerassert.deepEqual(host.agentOf('gc').calls, [])})+// 公开#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) => {t.mock.timers.enable({ apis: ['setTimeout'] })const host = await start(t)