A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Count every Bot message toward the hop limit and cap unattended chatter
Fei2411d3b66d01d5f8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c8b2fec5..612d5e94 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,6 +4,10 @@ All notable changes to DS Bot are listed here. The format follows [Keep a Change## [Unreleased]+### Fixed++- Bots could keep messaging each other for a long time without you, for example by forwarding a request from Bot to Bot or through group posts. Every forwarded message and group post now counts toward the limit on how long a chain of Bot messages can get, and after 40 Bot messages since you last wrote, answered a question card or a scheduled task ran, `message_bot` and `post_to_group` fail and tell the Bot to report to you. Bots are also told not to send thanks or acknowledgements, and not to answer a reply. ([#129](https://github.com/Fei2411/DeepSeek-Bot/issues/129))+## [0.1.5] - 2026-10-13### Addeddiff --git a/ds-bot/src/host/constants.js b/ds-bot/src/host/constants.jsindex 42cff582..dae8be0e 100644--- a/ds-bot/src/host/constants.js+++ b/ds-bot/src/host/constants.js@@ -21,6 +21,9 @@ export const OCR_CACHE_MAX = 500export const MAX_AVATAR_IMAGE = 160_000export const ROUTE = '/api/bot'export const MAX_HOPS = 6+// Messages the whole team may send each other (message_bot, post_to_group) while+// nobody outside it speaks: the user, a question card's answer or a scheduled task.+export const MAX_UNATTENDED_MESSAGES = 40// Bot requests a Bot's own chat may hold unread; past this the Bot is most likely// stuck, and more messages only pile up behind it.export const MAX_UNREAD_REQUESTS = 10diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.jsindex 7dbcc2ca..dad1f488 100644--- a/ds-bot/src/host/groups.js+++ b/ds-bot/src/host/groups.js@@ -187,10 +187,11 @@ export function install(rt) {// round, or null when the round was stopped. The wait restarts on each event of the// member's Session, so a member at work is never cut off. `by` is the member that// called it, which answers what the turn posts after the round moved on.- async function roomTurn(room, member, sessionId, text, note, signal, started, by) {+ async function roomTurn(room, member, sessionId, text, note, signal, round, by) {if (signal.aborted) return nullconst exchangeId = randomUUID()const turn = { botId: member.id, sessionId, exchangeId }+ const { started } = roundstarted.push(turn)room.seen[member.id] = room.seq// Checked before the delivery, which may start the turn at once.@@ -214,7 +215,7 @@ export function install(rt) {signal.addEventListener('abort', () => finish(null), { once: true })})try {- await rt.deliver({ fromId: undefined, toId: member.id, sessionId, role: 'room', roomId: room.id, exchangeId, note, text, ...(by ? { askedBy: by } : {}) })+ await rt.deliver({ fromId: undefined, toId: member.id, sessionId, role: 'room', roomId: room.id, exchangeId, note, text, hop: round.hop, ...(by ? { askedBy: by } : {}) })// Still held by an earlier request: this turn cannot start until the user answers.if (rt.waitsForApproval?.(sessionId)) rt.roomWaiters.get(exchangeId)?.approval()// Still at earlier work: the call waits in its inbox and is answered after that.@@ -298,9 +299,11 @@ export function install(rt) {const note = all || found.length > 0 ? 'the user mentioned you' : 'new message from the user'callMembers(round, turns, index - 1, openingSpeakers(room, { text: line.text }), note, ROOM_ADMIN_TURNS_EACH)}- // The user spoke in this room, so Bots may start their own rounds again.+ // The user spoke in this room, so Bots may start their own rounds again. These+ // messages never reach the Session as events, so the team's count resets here too.room.botRounds = 0room.lateRounds = 0+ rt.userSpoke()void rt.save().catch(() => {})return round.slots.length - before}@@ -339,7 +342,7 @@ export function install(rt) {const prompt = roomPrompt(room, member, round)round.shown?.push(member.id)const text = session.brief === undefined ? prompt : `${session.brief}\n\n${prompt}`- const reply = await roomTurn(room, member, session.id, text, slot.note ?? 'your turn', signal, round.started, slot.by)+ const reply = await roomTurn(room, member, session.id, text, slot.note ?? 'your turn', signal, round, slot.by)round.speaking = nullif (reply?.failure !== undefined) {// Not a pass: the user sees why the member is silent, and the round goes on.@@ -422,6 +425,8 @@ export function install(rt) {roomId: room.id,members: room.members,startSeq,+ // Member turns answer the opener, so they keep its hop; a round the user opens starts at 0.+ hop: opener.hop ?? 0,...(opener.kickoff ? { kickoff: true } : {}),...(references.length > 0 ? { references, shown: [] } : {}),slots: openingSpeakers(room, opener).map(member => ({@@ -587,7 +592,7 @@ export function install(rt) {const quiet = (room.lateRounds ?? 0) >= ROOM_LATE_ROUNDSif (!quiet) room.lateRounds = (room.lateRounds ?? 0) + 1await rt.save()- await postToRoom(room, member, text, { late: true, ...(info.askedBy ? { askedBy: info.askedBy } : {}), ...(quiet ? { quiet: true } : {}) })+ await postToRoom(room, member, text, { late: true, hop: info.hop ?? 0, ...(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 = lateRoomReply@@ -645,7 +650,7 @@ export function install(rt) {round.passed.length > 0 ? `Stayed silent: ${round.passed.join(', ')}.` : '',round.failed.length > 0 ? `Could not answer because their model call failed: ${round.replies.filter(reply => reply.kind === 'failed').map(reply => `${reply.name} (${failureLine({ code: reply.code, status: reply.status, message: reply.text })})`).join(', ')}.` : '',].filter(Boolean).join('\n\n')- await rt.deliver({ toId: post.botId, role: 'report', roomId: room.id, text, hop: (post.hop ?? 0) + 1 })+ await rt.deliver({ toId: post.botId, role: 'report', roomId: room.id, text, hop: post.hop ?? 0 }).catch(error => rt.warn('ds-bot: group report to %s failed: %s', post.name, error))}diff --git a/ds-bot/src/host/prompt.js b/ds-bot/src/host/prompt.jsindex 9309a3b3..abb33773 100644--- a/ds-bot/src/host/prompt.js+++ b/ds-bot/src/host/prompt.js@@ -5,11 +5,11 @@ const TEAM_RULES = ['## How your Bot team works','- Every Bot is its own long-lived conversation with the user, with its own memory and computer.','- The team changes over time. Call list_bots whenever you need to know who exists; do not rely on memory.',- '- message_bot sends a message to another Bot. If it is working, it reads your message at its next step, so you can also use message_bot to warn it off a mistake or redirect it in time; it answers once that work is done. Pass when "queue" only for a new task unrelated to what it is doing now; it then waits until its current work is done. Its reply arrives later as a new "[Reply from …]" message. Never wait, poll, or resend.',+ '- message_bot sends a message to another Bot. Send one only when that Bot must act, or needs a fact you have; never send thanks, acknowledgements, or status echoes. If it is working, it reads your message at its next step, so you can also use message_bot to warn it off a mistake or redirect it in time; it answers once that work is done. Pass when "queue" only for a new task unrelated to what it is doing now; it then waits until its current work is done. Its reply arrives later as a new "[Reply from …]" message. Never wait, poll, or resend.','- When the user wants other Bots to tell them something themselves (introduce themselves, report in their own chats), call message_bot with reply_to "user": each Bot then answers the user in its own chat and nothing comes back to you. Do not relay those answers yourself.','- When a "[Message from …]" opens a turn, your final text in that turn is delivered back to that Bot automatically and the user does not see it. If one arrives while you are working on something else, take it into account in that work but do not answer it there: once the work is done, it comes back to you in a turn of its own to answer. Answer it directly and briefly, as a list of facts. Never invent facts: say "not discussed yet" when you do not know. If the message brings a request or a decision meant for the user, handle it in the same turn too — do the work, or ask the user with ask_user.','- When a "[Message from … · the user sees your reply here]" arrives, your reply is shown to the user in your own chat and is not sent back. Talk to the user directly, as yourself.',- '- When a "[Reply from …]" arrives, tell the user the outcome if it matters to them.',+ '- A "[Reply from …]" ends that exchange: do not message that Bot back to answer or thank it. Tell the user the outcome if it matters to them. If you need more from that Bot, send it a new request.','- Chat like a teammate texting: short sentences, often two or three short messages instead of one long one, no headings. When the user asks for a deliverable (a plan, schedule, draft, or list), write it out in full in the chat; never claim you gave something you did not write. Mention other Bots by their exact name.','- Only for a direct user request in your own chat that needs several steps: write one short sentence of normal reply text before your first tool call, and make that tool call in the same response. Never start such a task with tools alone or end it with a promise. On long tasks, give brief factual updates only at meaningful milestones, then keep working.','- For "[Group chat …]", "[Message from …]", or "[Reply from …]" messages, do not write plans or progress updates: use tools silently, then reply with the answer. Simple answers do not need progress messages.',@@ -32,7 +32,7 @@ const MAIN_RULES = ['- Every Bot runs on one model of its own (list_bots shows it). Pass model to create_bot or update_bot only when the user names one; list_models gives the provider/model refs.','- Use update_bot to rename a Bot, change its role, color, model, working folder, or instructions when the user asks.','- You run the group chats too. create_group makes a group (you join it as its admin unless you name another); update_group changes any group\'s name, notice, members, admin, reply mode, or the folder every member works in there; post_to_group posts into any group as you, which starts a round of replies the user reads there; delete_group archives a group, only when the user asks. list_bots shows every group.',- '- The team can have more than one Main Bot; list_bots marks them. They share these powers, so coordinate with them through message_bot.',+ '- The team can have more than one Main Bot; list_bots marks them. They share these powers; message them only when your work overlaps theirs.',].join('\n')export function install(rt) {diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.jsindex ffaf7827..42e5f780 100644--- a/ds-bot/src/host/tools.js+++ b/ds-bot/src/host/tools.js@@ -2,7 +2,7 @@// question card. Group rounds and reading chats are in groups.js.import { randomUUID } from 'node:crypto'import { defineTool } from '@deepseek-ai/dsh-tools'-import { COLORS, EXTRA_COLORS, MAX_HOPS, MAX_UNREAD_REQUESTS, ROOM_BOT_ROUNDS, ROOM_MODES, SOURCE_KIND } from './constants.js'+import { COLORS, EXTRA_COLORS, MAX_HOPS, MAX_UNATTENDED_MESSAGES, MAX_UNREAD_REQUESTS, ROOM_BOT_ROUNDS, ROOM_MODES, SOURCE_KIND } from './constants.js'import { unquote } from './text.js'export const output = { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: String(value) }] }@@ -82,6 +82,19 @@ export function install(rt) {// A tool that throws shows as failed in the chat, instead of as sent or stopped.const refuse = (message) => { throw new Error(message) }+ // A message a Bot sends is one hop past the turn that sends it, while a reply keeps+ // the hop of the request it answers (turns.js): any chain, forwarded or back and+ // forth, reaches MAX_HOPS.+ const nextHop = (exec) => {+ const turn = rt.live.get(exec.agent?.id)+ return 1 + Math.max(turn?.info?.hop ?? 0, ...(turn?.joined ?? []).map(joined => joined.info?.hop ?? 0))+ }+ const CHAIN_TOO_LONG = 'This chain of Bot messages is already long. Stop here and report to the user instead.'+ const checkUnattended = () => {+ if (rt.unattended.sent < MAX_UNATTENDED_MESSAGES) return+ refuse(`Not sent: the team has sent ${MAX_UNATTENDED_MESSAGES} Bot messages since the user last wrote. Stop messaging other Bots and tell the user what is still open.`)+ }+ctx.tools.register(defineTool({name: 'message_bot',description: 'Send a message to another Bot on the team. If that Bot is working, it reads your message at its next step and can change course, then answers once that work is done; if it is idle, it starts on it right away. Its reply arrives later as a new message to you; with reply_to "user" it answers the user in its own chat instead.',@@ -107,9 +120,9 @@ export function install(rt) {const target = rt.findBot(args.to)if (target === undefined) return `No Bot named ${args.to}. Team: ${Object.values(state.bots).map(bot => bot.name).join(', ')}`if (target.id === sender.id) return 'You cannot message yourself.'- const turn = rt.live.get(exec.agent?.id)- const hop = Math.max(turn?.info?.hop ?? 0, ...(turn?.joined ?? []).map(joined => joined.info?.hop ?? 0))- if (hop >= MAX_HOPS) return 'This chain of Bot messages is already long. Stop here and report to the user instead.'+ const hop = nextHop(exec)+ if (hop > MAX_HOPS) return CHAIN_TOO_LONG+ checkUnattended()const chat = rt.chatOf(target.id)const unread = unreadRequests(await rt.resolveAgent(chat))if (unread >= MAX_UNREAD_REQUESTS) {@@ -119,6 +132,7 @@ export function install(rt) {const working = rt.live.get(chat)?.turn !== undefinedconst steer = args.when !== 'queue' && !toUserawait rt.deliver({ fromId: sender.id, toId: target.id, text: args.message, role: 'request', hop, steer, ...(toUser ? { audience: 'user' } : callerRoom(exec)) })+ rt.unattended.sent += 1const sent = toUser? `Delivered to ${target.name}. It will answer the user in its own chat; nothing comes back to you, so point the user to ${target.name}'s chat instead of relaying.`: working && steer@@ -392,18 +406,21 @@ export function install(rt) {if (!rt.isMain(self) && !rt.isAdminOf(room, self)) return `Only a Main Bot or the admin of "${room.name}" can post there. Use message_bot to reach its members.`const info = rt.live.get(exec.agent?.id)?.infoif (info?.role === 'room' && info.roomId === room.id) return `You are speaking in "${room.name}" right now. Write your message as your reply instead.`- if ((info?.hop ?? 0) >= MAX_HOPS) return 'This chain of Bot messages is already long. Stop here and report to the user instead.'+ const hop = nextHop(exec)+ if (hop > MAX_HOPS) return CHAIN_TOO_LONGconst text = String(args.message ?? '').trim()if (text === '') return 'Write a message to post.'if ((room.botRounds ?? 0) >= ROOM_BOT_ROUNDS) return `Bots already started ${ROOM_BOT_ROUNDS} rounds in "${room.name}" since the user last spoke there. Wait for the user.`+ checkUnattended()room.botRounds = (room.botRounds ?? 0) + 1await rt.save()const reportBack = args.report_back === truetry {- await rt.postToRoom(room, sender, text, { hop: info?.hop ?? 0, ...(reportBack ? { reportBack: true } : {}) })+ await rt.postToRoom(room, sender, text, { hop, ...(reportBack ? { reportBack: true } : {}) })} catch (failure) {return `Could not post in "${room.name}": ${failure.message}`}+ rt.unattended.sent += 1return `Posted in "${room.name}". Members reply there, where the user reads them${reportBack ? '; their replies also come back to you as a new message when the round ends' : ', and nothing comes back to you'}.`},}))diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.jsindex 450191e9..39547082 100644--- a/ds-bot/src/host/turns.js+++ b/ds-bot/src/host/turns.js@@ -81,6 +81,10 @@ export function install(rt) {const queueRoomMessage = (roomId, item) => roomInbox.set(roomId, [...(roomInbox.get(roomId) ?? []), item])// Member turns of a group round the user stopped: what they end with stays out of the group.const stoppedRoomTurns = new Set()+ // Bot messages sent since someone outside the team last spoke. Process-local: a+ // restart is itself a pause, so the count starts afresh.+ const unattended = { sent: 0 }+ const userSpoke = () => { unattended.sent = 0 }// A stopped round stops the member work it started: the turn that answers it, or the// delivery still waiting for the member's Session. An earlier turn there keeps going.@@ -300,6 +304,7 @@ export function install(rt) {breakcase 'user/message': {const source = event.data?.source+ if (source?.kind === 'user' || source?.kind === REPLY_KIND || source?.kind === 'schedule') userSpoke()// A message that shares a step with a bare handoff package is what the turn// answers, so the turn is not a hidden acknowledgement.const bare = info => info?.handoff === true && info.resume !== true@@ -432,7 +437,7 @@ export function install(rt) {...(back ? { sessionId: back } : {}),text: `${name} could not answer your message: its model call failed (${failureLine(failure)}). Tell the user if it matters; do not retry right away.`,role: 'reply',- hop: (source.hop ?? 0) + 1,+ hop: source.hop ?? 0,replyTo: source.exchangeId,}).catch(error => rt.warn('ds-bot: failure notice delivery failed: %s', error))} else if (reply !== '' || reason?.kind === 'aborted') {@@ -444,7 +449,7 @@ export function install(rt) {...(back ? { sessionId: back } : {}),text: reply !== '' ? reply : `${name} was stopped before it could answer your message.`,role: 'reply',- hop: (source.hop ?? 0) + 1,+ hop: source.hop ?? 0,replyTo: source.exchangeId,}).catch(error => rt.warn('ds-bot: reply delivery failed: %s', error))}@@ -496,5 +501,5 @@ export function install(rt) {}})- Object.assign(rt, { live, liveOf, roomWaiters, roomProgress, roomInbox, activityView, workView, roomWorkView, callDetail, stopRoomTurn })+ Object.assign(rt, { live, liveOf, roomWaiters, roomProgress, roomInbox, activityView, workView, roomWorkView, callDetail, stopRoomTurn, unattended, userSpoke })}diff --git a/ds-bot/test/bot-messages.test.js b/ds-bot/test/bot-messages.test.jsindex 961b718b..be8b4f5d 100644--- a/ds-bot/test/bot-messages.test.js+++ b/ds-bot/test/bot-messages.test.js@@ -8,7 +8,7 @@ import { apply } from '../index.js'import { fakeContext } from './fake-ctx.js'import { install as installTurns } from '../src/host/turns.js'import { install as installParts } from '../src/host/parts.js'-import { SOURCE_KIND } from '../src/host/constants.js'+import { MAX_HOPS, MAX_UNATTENDED_MESSAGES, REPLY_KIND, SOURCE_KIND } from '../src/host/constants.js'// A two-Bot team, optionally with b in a group Session 'gb' of room 'Ops'.function team({ group = false } = {}) {@@ -314,7 +314,7 @@ test('a request that joins a user-started turn is handed back, not answered withemit('b', 'user/message', { content: textBlock('[Message from Chief · you read it during your last task; answer it now]\nmake it shorter'), source: replySource('request', { exchangeId: 'e1', hop: 2, deferred: true }) })emit('b', 'assistant/message', assistantText('done, it is shorter'))emit('b', 'turn/end', { turn: 2, reason: { kind: 'completed' } })- assert.deepEqual(delivered.slice(1).map(job => [job.toId, job.role, job.replyTo, job.hop, job.text]), [['a', 'reply', 'e1', 3, 'done, it is shorter']])+ assert.deepEqual(delivered.slice(1).map(job => [job.toId, job.role, job.replyTo, job.hop, job.text]), [['a', 'reply', 'e1', 2, 'done, it is shorter']])assert.deepEqual(rt.state.exchangeTurns, { b: [2] })})@@ -427,7 +427,7 @@ test('a joined request crosses a part switch and is handed back in the new part'assert.equal(textOf(handedBack()[1].content), '[Message from Chief · you read it during your last task; answer it now]\nmore')})-test('the caller hop is the highest of the turn\'s trigger and joined requests', async (t) => {+test('a message goes one hop past the highest of the turn\'s trigger and joined requests', async (t) => {const { agents, emit, tool, stop } = await start(team())t.after(stop)@@ -435,7 +435,118 @@ test('the caller hop is the highest of the turn\'s trigger and joined requests',emit('b', 'user/message', { content: textBlock('[Message from Chief]\ntask'), source: replySource('request', { exchangeId: 'e0', hop: 1 }) })emit('b', 'user/message', { content: textBlock('[Message from Chief]\nmore'), source: replySource('request', { exchangeId: 'e1', hop: 4 }) })await tool('message_bot', { to: 'Chief', message: 'onward' }, 'b')- assert.equal(agents.get('a').calls[0][1].source.hop, 4)+ assert.equal(agents.get('a').calls[0][1].source.hop, 5)+})++// Each Session takes up the newest message it was sent as its next turn.+function turnTaker(agents, emit) {+ const turns = new Map()+ const take = (id) => {+ const [, message] = agents.get(id).calls.at(-1)+ turns.set(id, (turns.get(id) ?? 0) + 1)+ emit(id, 'turn/start', { turn: turns.get(id) })+ emit(id, 'user/message', { content: message.content, source: message.source })+ return message+ }+ const end = (id, text) => {+ if (text !== undefined) emit(id, 'assistant/message', assistantText(text))+ emit(id, 'turn/end', { turn: turns.get(id), reason: { kind: 'completed' } })+ }+ const userTurn = (id, text) => {+ turns.set(id, (turns.get(id) ?? 0) + 1)+ emit(id, 'turn/start', { turn: turns.get(id) })+ emit(id, 'user/message', { content: textBlock(text), source: { kind: 'user' } })+ }+ return { take, end, userTurn }+}+const allCalls = agents => [...agents.values()].reduce((sum, agent) => sum + agent.calls.length, 0)++test('every forwarded message counts a hop, and the one past MAX_HOPS is not sent', async (t) => {+ const seed = team()+ seed.bots.c = { id: 'c', name: 'Tester', role: 'Test', sessionId: 'c', createdAt: 3 }+ const { agents, emit, tool, stop } = await start(seed)+ t.after(stop)+ const { take, end, userTurn } = turnTaker(agents, emit)+ const ring = [['a', 'Writer', 'b'], ['b', 'Tester', 'c'], ['c', 'Chief', 'a']]++ userTurn('a', 'ask Writer to pass it on')+ const hops = []+ let refused+ for (let step = 0; step < MAX_HOPS + 3 && refused === undefined; step += 1) {+ const [from, to, toId] = ring[step % ring.length]+ if (step > 0) take(from)+ const before = allCalls(agents)+ const out = await tool('message_bot', { to, message: 'pass it on' }, from)+ end(from)+ if (out.startsWith('Delivered')) hops.push(agents.get(toId).calls.at(-1)[1].source.hop)+ else {+ refused = out+ assert.equal(allCalls(agents), before)+ }+ }+ assert.deepEqual(hops, Array.from({ length: MAX_HOPS }, (_, index) => index + 1))+ assert.equal(refused, 'This chain of Bot messages is already long. Stop here and report to the user instead.')+})++test('a back-and-forth between two Bots ends at MAX_HOPS', async (t) => {+ const { agents, emit, tool, stop } = await start(team())+ t.after(stop)+ const { take, end, userTurn } = turnTaker(agents, emit)+ const replies = () => (agents.get('a')?.calls ?? []).length++ userTurn('a', 'work it out with Writer')+ const asked = []+ for (let round = 0; round < MAX_HOPS + 3; round += 1) {+ const out = await tool('message_bot', { to: 'Writer', message: 'and now?' }, 'a')+ end('a')+ if (!out.startsWith('Delivered')) break+ asked.push(take('b').source.hop)+ const before = replies()+ end('b', 'here is my part')+ for (let count = 0; count < 200 && replies() === before; count += 1) await delay(5)+ const reply = take('a')+ assert.equal(reply.source.role, 'reply')+ }+ assert.deepEqual(asked, Array.from({ length: MAX_HOPS }, (_, index) => index + 1))+})++const spentBudget = { message: new RegExp(`^Not sent: the team has sent ${MAX_UNATTENDED_MESSAGES} Bot messages since the user last wrote`) }++test('the team sends no more Bot messages past the unattended limit, counting group posts', async (t) => {+ const { agents, tool, stop } = await start(team({ group: true }))+ t.after(stop)+ const send = () => tool('message_bot', { to: 'Writer', message: 'ping' }, 'a')++ for (let count = 1; count < MAX_UNATTENDED_MESSAGES; count += 1) await send()+ assert.match(await tool('post_to_group', { group: 'Ops', message: 'note' }, 'a'), /^Posted in "Ops"/)+ await assert.rejects(send(), spentBudget)+ await assert.rejects(tool('post_to_group', { group: 'Ops', message: 'again' }, 'a'), spentBudget)+ assert.equal(agents.get('b').calls.length, MAX_UNATTENDED_MESSAGES - 1)+ assert.equal(agents.get('r1').calls.length, 1)+})++test('the user, a question card\'s answer and a scheduled task each reset the unattended count; a goal does not', async (t) => {+ const { emit, tool, stop } = await start(team({ group: true }))+ t.after(stop)+ const send = () => tool('message_bot', { to: 'Writer', message: 'ping' }, 'a')+ const spend = async (count) => {+ for (let sent = 0; sent < count; sent += 1) await send()+ await assert.rejects(send(), spentBudget)+ }+ const arrive = (id, source) => emit(id, 'user/message', { content: textBlock('next'), source })++ await spend(MAX_UNATTENDED_MESSAGES)+ arrive('b', { kind: 'goal' })+ await assert.rejects(send(), spentBudget)++ arrive('r1', { kind: 'user' })+ await spend(MAX_UNATTENDED_MESSAGES)+ arrive('a', { kind: REPLY_KIND })+ await spend(MAX_UNATTENDED_MESSAGES)+ arrive('b', { kind: 'schedule' })+ await spend(MAX_UNATTENDED_MESSAGES)+ arrive('a', { kind: 'user' })+ assert.match(await send(), /^Delivered to Writer/)})test('an earlier part keeps the request its Bot answered', async () => {diff --git a/ds-bot/test/diagnostics.test.js b/ds-bot/test/diagnostics.test.jsindex 28dcf7bb..4b3e33c8 100644--- a/ds-bot/test/diagnostics.test.js+++ b/ds-bot/test/diagnostics.test.js@@ -193,7 +193,7 @@ test('a failed reply to message_bot tells the sender instead of leaving it waitiassert.equal(delivered[0].toId, 'a')assert.equal(delivered[0].role, 'reply')assert.equal(delivered[0].replyTo, 'x1')- assert.equal(delivered[0].hop, 2)+ assert.equal(delivered[0].hop, 1)assert.match(delivered[0].text, /^Writer could not answer your message: its model call failed \(SERVER 503: upstream busy\)/)assert.deepEqual(noted.map(entry => [entry.source, entry.code, entry.bot, entry.where]), [['turn', 'SERVER', 'Writer', 'own chat']])})diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.jsindex 20c93bc9..ffab47e8 100644--- a/ds-bot/test/group-work.test.js+++ b/ds-bot/test/group-work.test.js@@ -148,6 +148,36 @@ test('work past the grace lets the round go on, and the member that asked answerassert.deepEqual(host.agentOf('gc').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)+ host.emit('a', 'turn/start', { turn: 1 })+ host.emit('a', 'user/message', { content: [{ type: 'text', text: '[Message from Tester]\npost it' }], source: { kind: 'bot', role: 'request', senderSessionId: 'c', senderName: 'Tester', exchangeId: 'x1', hop: 2 } })+ await host.tool('post_to_group', { group: 'Ops', message: '@Writer 看一下文档' }, 'a')+ const post = host.takePost()+ assert.equal(post.source.hop, 3)++ const first = host.round('c1', post)+ await settle(() => host.agentOf('gb').calls.length === 1)+ assert.equal(host.begin('gb').source.hop, 3)+ await host.tool('message_bot', { to: 'Tester', message: '帮我确认一下' }, 'gb')+ assert.equal(host.agentOf('c').calls.at(-1).source.hop, 4)+ 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.finish('gb', '看完了。')+ await settle(() => host.agentOf('r1').calls.length === 1)+ const late = host.takePost()+ assert.deepEqual([late.source.late, late.source.hop], [true, 3])+ const second = host.round('c2', late)+ await settle(() => host.agentOf('ga').calls.length === 1)+ assert.equal(host.begin('ga').source.hop, 3)+ host.finish('ga', '[PASS]')+ await settle(() => second() !== undefined)+})+test('a member called while still at earlier work lets the round go on at once', async (t) => {const host = await start(t)host.emit('gb', 'turn/start', { turn: 1 })