A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Say when a group's calls and answers go unheard
Fei24118b3f1715e141
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 662dd1c1..db0dde94 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -559,6 +559,8 @@ var ZH = {"{name} looked up its own chat for “{text}”": "{name} 在自己的对话里查找「{text}」","{name} is typing…": "{name} 正在输入…","{name} didn't answer in time": "{name} 没有及时回应",+ "{names} not called: the per-member limit for this round is reached": "没叫到 {names}:这一轮每人的次数用完了",+ "The group went quiet: @ mentions in late replies call nobody until you write here": "群进入安静模式:之后迟到回复里的 @ 不再叫人,你在群里说句话就恢复","{name} paused for your approval": "{name} 停下来等你批准","{name} started on it": "{name} 开始做了","You stopped {name}'s work": "你停下了 {name} 的工作",@@ -5690,6 +5692,12 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUiif (reply.kind === "missed") {return (0, import_react9.createElement)("div", { key: `${reply.botId}-${index}`, className: "bt-event" }, t("{name} didn't answer in time", { name: bot.name }));}+ if (reply.kind === "dropped") {+ return (0, import_react9.createElement)("div", { key: `dropped-${index}`, className: "bt-event" }, t("{names} not called: the per-member limit for this round is reached", { names: (reply.names ?? []).join(t(" and ")) }));+ }+ if (reply.kind === "quiet") {+ return (0, import_react9.createElement)("div", { key: `quiet-${index}`, className: "bt-event" }, t("The group went quiet: @ mentions in late replies call nobody until you write here"));+ }if (reply.kind === "resumed") {return (0, import_react9.createElement)("div", { key: `${reply.botId}-${index}`, className: "bt-event" }, t("{name} was cut off by a restart and picked its work back up", { name: bot.name }));}diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.jsindex 88522089..87d1bc5c 100644--- a/ds-bot/src/client/cells.js+++ b/ds-bot/src/client/cells.js@@ -745,6 +745,12 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUiif (reply.kind === 'missed') {return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' }, t("{name} didn't answer in time", { name: bot.name }))}+ if (reply.kind === 'dropped') {+ return h('div', { key: `dropped-${index}`, className: 'bt-event' }, t('{names} not called: the per-member limit for this round is reached', { names: (reply.names ?? []).join(t(' and ')) }))+ }+ if (reply.kind === 'quiet') {+ return h('div', { key: `quiet-${index}`, className: 'bt-event' }, t('The group went quiet: @ mentions in late replies call nobody until you write here'))+ }if (reply.kind === 'resumed') {return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' }, t('{name} was cut off by a restart and picked its work back up', { name: bot.name }))}diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.jsindex b0ec1473..da2ad63f 100644--- a/ds-bot/src/client/i18n.js+++ b/ds-bot/src/client/i18n.js@@ -503,6 +503,8 @@ const ZH = {'{name} looked up its own chat for “{text}”': '{name} 在自己的对话里查找「{text}」','{name} is typing…': '{name} 正在输入…',"{name} didn't answer in time": '{name} 没有及时回应',+ '{names} not called: the per-member limit for this round is reached': '没叫到 {names}:这一轮每人的次数用完了',+ 'The group went quiet: @ mentions in late replies call nobody until you write here': '群进入安静模式:之后迟到回复里的 @ 不再叫人,你在群里说句话就恢复','{name} paused for your approval': '{name} 停下来等你批准','{name} started on it': '{name} 开始做了',"You stopped {name}'s work": '你停下了 {name} 的工作',diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.jsindex 4cb60fad..d9ab9242 100644--- a/ds-bot/src/host/groups.js+++ b/ds-bot/src/host/groups.js@@ -51,13 +51,26 @@ const unseenLines = (room, memberId) => {return room.log.filter(line => line.seq > since && line.botId !== memberId).slice(-ROOM_DELTA_MAX)}+// A notice keeps its fields, not a finished sentence: the line members read is written+// when it is read, so old entries still say what happened when the wording or the+// constants move on.+const noticeText = (line) => {+ if (line.reason === 'cap') {+ const via = line.admin !== undefined ? ` @${line.admin} can pass it on, or` : ''+ return `@${(line.names ?? []).join(' and @')} was not called: this round's per-member turn limit (${line.cap}) is reached, so the message is in the log but reaches nobody.${via} end this turn and call again in the next round.`+ }+ if (line.reason === 'missed') return `${(line.names ?? []).join(' and ')} did not answer within ${line.minutes} minutes, so this round moved on without it. If it is still working, it posts its result later as a late reply; if it is urgent, the user can write here or the admin can follow up.`+ if (line.reason === 'quiet') return `The group is in quiet mode: late replies after work have reached the ${ROOM_LATE_ROUNDS}-round limit, so @ names in later posts call nobody, though the messages still reach the log. The user can reset it by writing here, or the current work can finish.`+ return line.text ?? ''+}// `text` is what to show of a message line, by default what the log keeps of it.-const lineText = (line, text = line.text) => {+export const lineText = (line, text = line.text) => {if (line.kind === 'lookup') return `[${speakerOf(line)} looked up its own chat${line.text ? ` for "${line.text}"` : ''}]`if (line.kind === 'resumed') return `[${speakerOf(line)}'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 `[${speakerOf(line)}'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 ${speakerOf(line)}'s work here]`if (line.kind === 'done') return `[${speakerOf(line)} finished the work it was asked for]`+ if (line.kind === 'notice') return `[${noticeText(line)}]`return `${speakerOf(line)}: ${text}`}const transcript = (lines, textOfLine = line => line.text) => lines.map(line => lineText(line, textOfLine(line))).join('\n')@@ -231,6 +244,7 @@ export function install(rt) {const notice = room.notice ? `Group notice (shared instructions for every member):\n${room.notice}` : ''if (round.kickoff) return { text: [members, notice, leads ? adminNote(room) : '', roomKickoff(rt.uiLanguage?.())].filter(Boolean).join('\n\n'), files: [] }const working = workingIn(room).filter(item => item.bot.id !== member.id)+ .map(item => ({ ...item, unread: unreadCount(room, item.bot.id) }))const text = [members,notice,@@ -240,7 +254,7 @@ export function install(rt) {? `This round so far${spokeThisRound ? ', since your last message' : ', starting with the new message'} (oldest first):\n${transcript(current, memberText(room))}`: 'Nothing new in this round since your last message.',round.shown?.includes(member.id) ? '' : referenceNote(round.references),- working.length > 0 ? `Still at work on what they were asked; each posts here when done: ${working.map(item => `${item.bot.name} (${minutesSince(item.since)} min)`).join(', ')}.` : '',+ working.length > 0 ? `Still at work on what they were asked; each posts here when done: ${working.map(item => `${item.bot.name} (${minutesSince(item.since)} min${item.unread > 0 ? `, with ${item.unread} group message(s) it has not read yet` : ''})`).join(', ')}.` : '',`Speaking order for this round: ${round.slots.map(slotLabel).join(' → ')}.`,`You are number ${index + 1} of ${round.slots.length}. ${before === 0 ? 'Nobody spoke before you' : `${before} went before you`}${after === 0 ? ', and you are the last.' : `; ${after} after you will see your message.`}`,ROOM_REPLY,@@ -254,6 +268,12 @@ export function install(rt) {const bot = rt.botOf(id)return entry?.turn !== undefined && bot !== undefined ? [{ bot, since: entry.since ?? Date.now() }] : []})+ // How many group lines a member has not been shown yet, counted the same way a+ // round counts the lines it carries over (unseenLines), so the number a speaker+ // reads is the number the member would get. A turn the reply timeout cut short+ // may leave them unread, and the member is never called again: the next speaker+ // is told, so it knows the hand-off it waits on sits behind unread lines.+ const unreadCount = (room, botId) => unseenLines(room, botId).lengthconst minutesSince = at => Math.max(1, Math.round((Date.now() - at) / 60000))// A member's message in the round: in the log, for the members after it, and in the@@ -356,7 +376,14 @@ export function install(rt) {function callMembers(round, turns, index, callees, note, cap, by) {let next = index + 1for (const peer of callees) {- if ((turns.get(peer.id) ?? 0) >= cap) continue+ if ((turns.get(peer.id) ?? 0) >= cap) {+ // The bound drops the call in silence: the caller's "@Name" sits in the log+ // and reads as a hand-off, while the member never hears of it. Keep the drop+ // in the round, so the group is told once (noteDropped).+ round.dropped ??= []+ round.dropped.push({ name: peer.name, cap })+ continue+ }const waiting = round.slots.findIndex((other, at) => at > index && other.id === peer.id && other.status === 'waiting')const called = waiting === -1 ? { id: peer.id, name: peer.name, status: 'waiting' } : round.slots.splice(waiting, 1)[0]called.note = note@@ -367,6 +394,27 @@ export function install(rt) {}}+ // Calls the per-member turn bound dropped, told to the group once per batch of+ // calls: the drop is found while the caller's own reply is handled, so the group+ // hears of it with that reply and not at the end of the round — a round may see+ // several batches, one for the user's message and one for each member's reply.+ // The log already shows the "@Name" that went out, so without this the hand-off+ // looks done while nobody was called: the round moved on and the caller waits for+ // an answer that never starts. The admin can carry the message on, or the round+ // ends and the next one calls again.+ const noteDropped = (room, round) => {+ const dropped = round.dropped ?? []+ if (dropped.length === 0) return+ round.dropped = []+ const names = [...new Set(dropped.map(item => item.name))]+ const admin = rt.botOf(room.admin)+ appendRoom(room, { who: 'DS Bot', kind: 'notice', reason: 'cap', names, cap: dropped[0].cap, ...(admin === undefined ? {} : { admin: admin.name }) })+ // The user's half of the same event: the round's replies carry one line, so the+ // silence after the "@Name" it just saw is not read as a finished hand-off.+ round.replies.push({ kind: 'dropped', names, cap: dropped[0].cap, time: Date.now() })+ void rt.save().catch(() => {})+ }+// The user's messages waiting in the group Session's inbox while a round runs, from// the composer whether it queued or steered them. Images and chat references are// only read when the Session takes the message itself, so a message with either@@ -401,9 +449,12 @@ export function install(rt) {const { all, found } = mentionsIn(line.text, members)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)+ noteDropped(room, round)}// The user spoke in this room, so late results may call members again.room.lateRounds = 0+ room.quietNoticed = false+ room.quietShown = falsevoid rt.save().catch(() => {})return round.slots.length - before}@@ -472,7 +523,13 @@ export function install(rt) {} else {slot.status = typeof reply === 'string' ? 'passed' : 'missed'round.passed.push(member.name)- if (reply?.missed) round.replies.push({ kind: 'missed', botId: member.id, name: member.name, color: member.color, time: Date.now() })+ if (reply?.missed) {+ round.replies.push({ kind: 'missed', botId: member.id, name: member.name, color: member.color, time: Date.now() })+ // The round moved on without this member: the log shows the call and then+ // silence, which reads as a lost message. The group is told the baton was+ // dropped, and what brings the member back.+ appendRoom(room, { who: 'DS Bot', kind: 'notice', reason: 'missed', names: [member.name], minutes: Math.round(ROOM_REPLY_TIMEOUT_MS / 60000) })+ }}const spoken = final === undefined ? said : [...said, final]if (spoken.length === 0) continue@@ -484,6 +541,7 @@ export function install(rt) {const found = named.filter(other => other.id !== member.id)const callees = leads && all ? [...found, ...others.filter(other => !found.includes(other))] : foundcallMembers(round, turns, index, callees, `${member.name} mentioned you`, leads ? ROOM_ADMIN_TURNS_EACH : ROOM_TURNS_EACH, member.id)+ noteDropped(room, round)}}@@ -519,7 +577,14 @@ export function install(rt) {...(post.files === undefined ? {} : { files: post.files }),})}- if (posts.some(post => !post.botId && !post.kickoff)) room.lateRounds = 0+ // The user wrote here, so late results may call members again and the quiet+ // notice may be told again: the count and the notice reset together, as they+ // do for a message that waited in the inbox (drainRoomInbox).+ if (posts.some(post => !post.botId && !post.kickoff)) {+ room.lateRounds = 0+ room.quietNoticed = false+ room.quietShown = false+ }await rt.save()// An event post, and a member post that calls nobody, never pick the speakers// over a message queued with them.@@ -562,6 +627,7 @@ export function install(rt) {round.replies.push({ kind, botId: post.botId, name, color: bot?.color, time: Date.now() })}if (posts.some(post => post.resumed || post.stopped || post.done)) await rt.save()+ if (posts.some(post => post.quiet === true)) showQuiet(room, round)rt.roomProgress.set(exec.callId, round)try {await runRound(room, round, exec.signal, exec.agent)@@ -713,6 +779,7 @@ export function install(rt) {const line = [text, ...files.map(fileLine)].filter(Boolean).join('\n')appendRoom(room, { who: sender.name, botId: sender.id, text: line, ...(files.length > 0 ? { files } : {}) })running.replies.push({ botId: sender.id, name: sender.name, color: sender.color, text: line, time: Date.now() })+ if (extra.quiet === true) showQuiet(room, running)logged = room.seq}await rt.save()@@ -726,6 +793,26 @@ export function install(rt) {}rt.postToRoom = postToRoom+ // Past the late-round limit every later post is quiet: its "@" names call nobody,+ // while the log still shows them. Members would keep handing work to a room that+ // no longer answers, so the group is told once when the limit is reached; the+ // user's next message resets the count (drainRoomInbox) and it may be told again.+ const noteQuiet = (room) => {+ if (room.quietNoticed === true) return+ room.quietNoticed = true+ appendRoom(room, { who: 'DS Bot', kind: 'notice', reason: 'quiet' })+ void rt.save().catch(() => {})+ }++ // The user's half of the same event: one line in the replies of the round the+ // quiet post reaches, shown once per quiet stretch the way the notice is.+ const showQuiet = (room, round) => {+ if (room.quietNoticed !== true || room.quietShown === true || round === undefined) return+ room.quietShown = true+ round.replies.push({ kind: 'quiet', time: Date.now() })+ void rt.save().catch(() => {})+ }+// 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@@ -741,7 +828,8 @@ export function install(rt) {const done = isPass(text) && shown && info.askedBy !== undefinedif (isPass(text) && !done) returnconst quiet = (room.lateRounds ?? 0) >= ROOM_LATE_ROUNDS- if (!quiet) room.lateRounds = (room.lateRounds ?? 0) + 1+ if (quiet) noteQuiet(room)+ else room.lateRounds = (room.lateRounds ?? 0) + 1await rt.save()await postToRoom(room, member, done ? '' : text, { late: true, ...(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))@@ -768,8 +856,14 @@ export function install(rt) {ensureRoomLog(room)const calls = callsIn(room, member, text)const running = [...rt.roomProgress.values()].find(round => round.roomId === room.id)- if (!calls && running !== undefined) return postInRound(room, running, member, text)- const quiet = !calls || (room.lateRounds ?? 0) >= ROOM_LATE_ROUNDS+ const limited = (room.lateRounds ?? 0) >= ROOM_LATE_ROUNDS+ if (limited) noteQuiet(room)+ if (!calls && running !== undefined) {+ postInRound(room, running, member, text)+ if (limited) showQuiet(room, running)+ return+ }+ const quiet = !calls || limitedif (!quiet) room.lateRounds = (room.lateRounds ?? 0) + 1await rt.save()await postToRoom(room, member, text, { progress: true, ...(quiet ? { quiet: true } : {}) })diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.jsindex 09d71c8e..bc5fadf3 100644--- a/ds-bot/src/host/tools.js+++ b/ds-bot/src/host/tools.js@@ -168,10 +168,12 @@ export function install(rt) {const postedIn = posted !== undefined && posted.turn === turnOf(exec) ? posted.calls.get(target.id) : undefinedif (postedIn !== undefined) refuse(`Not sent: you called ${target.name} in "${postedIn}" in this turn, and it works on that there. Send each task one way only; to add to it, post in that group.`)// Whoever waits for this work gets the answer by itself; a message there only- // sends the work round in a circle.+ // sends the work round in a circle. Not a failed call: the turn goes on with+ // the work, and the result says where its answer goes instead of showing a+ // bare error the Bot cannot act on.const works = worksOf(exec)if (rt.upstreamOf(works).has(target.id)) {- refuse(`Not sent: ${target.name} is waiting for the result of the work you are doing, and your answer reaches it by itself. Finish the work and end your turn; to ask ${target.name} something, end your turn with the question.`)+ return `Not sent: ${target.name} is waiting for the result of the work you are doing, and your answer reaches it by itself once everything you handed on is back. Finish the work and end your turn; to ask ${target.name} something, end your turn with the question.`}const toUser = args.reply_to === 'user'const work = toUser ? undefined : works[0]diff --git a/ds-bot/test/bot-messages.test.js b/ds-bot/test/bot-messages.test.jsindex a302d0c3..de186c7e 100644--- a/ds-bot/test/bot-messages.test.js+++ b/ds-bot/test/bot-messages.test.js@@ -569,9 +569,11 @@ test('a Bot may take part in the same work again, but not message one that waitsconst { take, end } = await handedOn(team)end('b')take('c')- const refused = { message: /^Not sent: (Chief|Writer) is waiting for the result of the work you are doing, and your answer reaches it by itself\./ }- await assert.rejects(tool('message_bot', { to: 'Chief', message: 'please accept it' }, 'c'), refused)- await assert.rejects(tool('message_bot', { to: 'Writer', message: 'it passes' }, 'c'), refused)+ // The guard answers with a result, not a failed call: the turn goes on with the+ // work, and the result says where its answer goes.+ const refused = /^Not sent: (Chief|Writer) is waiting for the result of the work you are doing, and your answer reaches it by itself once everything you handed on is back\./+ assert.match(await tool('message_bot', { to: 'Chief', message: 'please accept it' }, 'c'), refused)+ assert.match(await tool('message_bot', { to: 'Writer', message: 'it passes' }, 'c'), refused)assert.deepEqual(callsOf(agents, 'a'), [])assert.equal(callsOf(agents, 'b').length, 1)end('c', 'it passes')@@ -585,7 +587,7 @@ test('a Bot may take part in the same work again, but not message one that waitsend('a')take('c')assert.match(await tool('message_bot', { to: 'Writer', message: 'what did you change last?' }, 'c'), /^Delivered to Writer/)- await assert.rejects(tool('message_bot', { to: 'Chief', message: 'done' }, 'c'), refused)+ assert.match(await tool('message_bot', { to: 'Chief', message: 'done' }, 'c'), refused)})test('a stopped turn answers at once, and what it handed on comes back to it alone', async (t) => {diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.jsindex 1600e306..ec391b44 100644--- a/ds-bot/test/group-work.test.js+++ b/ds-bot/test/group-work.test.js@@ -708,7 +708,9 @@ test('members still at work show in the team view and in the prompts of the othehost.emit('gb', 'tool/call', { callId: 'k1', name: 'pwsh', arguments: '{}' })const result = host.round('c1', host.say('@Tester 你怎么看'))await settle(() => host.agentOf('gc').calls.length === 1)- assert.match(text(host.agentOf('gc').calls[0]), /Still at work on what they were asked; each posts here when done: Writer \(1 min\)\./)+ // Writer has not read the one line in the group (the user's message that opened this+ // round), so the prompt names the wait and the unread count together.+ assert.match(text(host.agentOf('gc').calls[0]), /Still at work on what they were asked; each posts here when done: Writer \(1 min, with 1 group message\(s\) it has not read yet\)\./)host.begin('gc')const { value } = await host.call('state', {})assert.deepEqual(value.work.rooms.r1.map(entry => [entry.botId, entry.tool, entry.speaking]), [['b', 'pwsh', undefined], ['c', undefined, true]])diff --git a/ds-bot/test/rounds.test.js b/ds-bot/test/rounds.test.jsindex 61dc01aa..aabe076d 100644--- a/ds-bot/test/rounds.test.js+++ b/ds-bot/test/rounds.test.js@@ -5,6 +5,7 @@ import { tmpdir } from 'node:os'import { join } from 'node:path'import { test } from 'node:test'import { createRuntime } from '../index.js'+import { lineText } from '../src/host/groups.js'import { fakeAttachments, fakeContext } from './fake-ctx.js'// A fake team of two Bots in one group; member answers are played back through the@@ -626,3 +627,223 @@ test('a long post goes to the group as a file, and reaches the member with its passert.deepEqual(line.files, [file])assert.equal(line.length, undefined, 'the line is short; no file of its own')})++// The per-member turn bound, the late-round quiet limit and the reply timeout drop+// group hand-offs in silence: the log shows the "@Name" that went out, the called+// member never hears of it, and the round moves on. Each drop is told to the group+// instead, so a caller learns its hand-off did not land.+test('a call past the per-member turn limit is dropped, and the group is told once', async (t) => {+ const { call, emit, userMessage, relay, answer, stop, sent, rt } = start()+ t.after(stop)+ const chief = (await call('state', {})).value.mainBotId+ const writer = (await call('create-bot', { name: 'Writer' })).value+ const editor = (await call('create-bot', { name: 'Editor' })).value+ const room = (await call('create-room', { name: 'R1', members: [chief, writer.id, editor.id] })).value+ await call('update-room', { id: room.id, mode: 'everyone' })+ sent.length = 0++ await emit(room.id, userMessage('Start'))+ const running = relay(room.id, 'relay')++ // Everyone mode, admin first: the three opening turns weave @ calls between them.+ const first = await turnFor(sent)+ await answer(first.sessionId, first.message.source.exchangeId, '@Writer one', 1)+ const second = await turnFor(sent, first)+ await answer(second.sessionId, second.message.source.exchangeId, '@Editor one', 2)+ const third = await turnFor(sent, first, second)+ await answer(third.sessionId, third.message.source.exchangeId, '@Writer back', 3)+ const fourth = await turnFor(sent, first, second, third)+ await answer(fourth.sessionId, fourth.message.source.exchangeId, '@Editor two', 4)+ // Editor's second turn calls Writer a third time: Writer already spoke twice, so+ // the call is dropped. The log must say so, not show a hand-off that never starts.+ const fifth = await turnFor(sent, first, second, third, fourth)+ await answer(fifth.sessionId, fifth.message.source.exchangeId, '@Writer again', 5)+ await running++ const notices = rt.state.rooms[room.id].log.filter(line => line.kind === 'notice')+ assert.equal(notices.length, 1, 'one notice for the dropped call, not one per message')+ assert.deepEqual({ reason: notices[0].reason, names: notices[0].names, cap: notices[0].cap, admin: notices[0].admin },+ { reason: 'cap', names: ['Writer'], cap: 2, admin: rt.state.bots[rt.state.rooms[room.id].admin]?.name })+ assert.match(lineText(notices[0]), /@Writer was not called: this round's per-member turn limit \(2\) is reached/)+ // The round the user watched shows the same drop as one line of its replies.+ const result = JSON.parse(await running)+ assert.deepEqual(result.replies.filter(reply => reply.kind === 'dropped').map(reply => [reply.names, reply.cap]), [[['Writer'], 2]])+ const writerSession = rt.state.rooms[room.id].sessions[writer.id]+ const writerTurns = sent.filter(entry => entry.sessionId === writerSession && entry.message.source.role === 'room')+ assert.equal(writerTurns.length, 2, 'Writer was called twice, and the third call never reached it')+})++test('the quiet mode past the late-round limit is told to the group once, and the user resets it', async (t) => {+ const { call, emit, userMessage, compose, relay, answer, stop, sent, rt } = start()+ t.after(stop)+ const room = await team(call, sent)+ await call('update-room', { id: room.id, mode: 'admin' })+ const chief = rt.state.mainBotIds[0]++ // One round, so the admin has a group Session to post from.+ await emit(room.id, userMessage('Start'))+ const running = relay(room.id, 'relay')+ const turn = await turnFor(sent)+ await answer(turn.sessionId, turn.message.source.exchangeId, 'Ready.', 1)+ await running+ const groupSession = rt.state.rooms[room.id].sessions[chief]+ const state = rt.state.rooms[room.id]++ // Late replies after work have reached the limit: the next post is quiet, and the+ // group hears why its @ names stop calling anybody.+ state.lateRounds = 10+ sent.length = 0+ await rt.roomStepText(groupSession, {}, '@Writer still with me?', false)+ await waitFor(() => state.log.some(line => line.kind === 'notice'))+ const notices = state.log.filter(line => line.kind === 'notice')+ assert.equal(notices.length, 1, 'one notice when the limit is reached')+ assert.equal(notices[0].reason, 'quiet')+ assert.match(lineText(notices[0]), /quiet mode/)+ assert.match(lineText(notices[0]), /10-round limit/)+ assert.equal(state.lateRounds, 10, 'a quiet post does not push the count further')+ assert.equal(state.quietNoticed, true)++ // A second quiet post says nothing new.+ await rt.roomStepText(groupSession, {}, '@Writer again?', false)+ await waitFor(() => sent.length > 0)+ assert.equal(state.log.filter(line => line.kind === 'notice').length, 1, 'the notice is not repeated')++ // The user writes in the group: the count resets, so later posts call members again.+ await compose(room.id, 'carry on')+ const reset = relay(room.id, 'relay-2')+ const after = await turnFor(sent)+ await answer(after.sessionId, after.message.source.exchangeId, 'On it.', 2)+ await reset+ assert.equal(state.lateRounds, 0)+ assert.equal(state.quietNoticed, false)++ await rt.roomStepText(groupSession, {}, '@Writer one more', false)+ await waitFor(() => state.lateRounds === 1)+ assert.equal(state.log.filter(line => line.kind === 'notice').length, 1, 'no notice once the group talks again')+})++test('the quiet mode names itself once in the replies the user sees', async (t) => {+ const { call, emit, userMessage, relay, answer, stop, sent, rt } = start()+ t.after(stop)+ const room = await team(call, sent)+ await call('update-room', { id: room.id, mode: 'admin' })+ const chief = rt.state.mainBotIds[0]++ await emit(room.id, userMessage('Start'))+ const running = relay(room.id, 'relay')+ const turn = await turnFor(sent)+ await answer(turn.sessionId, turn.message.source.exchangeId, 'Ready.', 1)+ await running+ const state = rt.state.rooms[room.id]++ // In quiet mode — the notice already went to the log — a quiet post opens a round,+ // and the round's replies name the mode once.+ state.lateRounds = 10+ state.quietNoticed = true+ rt.roomInbox.set(room.id, [{ text: '@Writer still there?', botId: chief, late: true, quiet: true }])+ const first = JSON.parse(await relay(room.id, 'relay-2'))+ assert.equal(first.replies.filter(reply => reply.kind === 'quiet').length, 1)+ assert.equal(state.quietShown, true)++ // The next quiet post opens a round too, but the line is not drawn again.+ rt.roomInbox.set(room.id, [{ text: '@Writer?', botId: chief, late: true, quiet: true }])+ const second = JSON.parse(await relay(room.id, 'relay-3'))+ assert.equal(second.replies.filter(reply => reply.kind === 'quiet').length, 0)++ // The user writing in the group resets it: the next quiet stretch says it again.+ await emit(room.id, userMessage('carry on'))+ const third = relay(room.id, 'relay-4')+ const again = await turnFor(sent, turn)+ await answer(again.sessionId, again.message.source.exchangeId, 'On it.', 2)+ await third+ assert.equal(state.quietShown, false)+})++test('a member the reply timeout cut short is told to the group, not left as silence', async (t) => {+ const { call, emit, userMessage, relay, stop, sent, rt } = start()+ t.after(stop)+ const room = await team(call, sent)+ await call('update-room', { id: room.id, mode: 'admin' })++ await emit(room.id, userMessage('Start'))+ const running = relay(room.id, 'relay')+ const turn = await turnFor(sent)+ // The 4-minute reply timeout, fired now instead of in four minutes: the round+ // moves on without the member, and the group is told the baton was dropped.+ rt.roomWaiters.get(turn.message.source.exchangeId).resolve({ missed: true })+ await running++ const notices = rt.state.rooms[room.id].log.filter(line => line.kind === 'notice')+ assert.equal(notices.length, 1)+ assert.deepEqual({ reason: notices[0].reason, names: notices[0].names, minutes: notices[0].minutes },+ { reason: 'missed', names: ['Chief'], minutes: 4 })+ assert.match(lineText(notices[0]), /did not answer within 4 minutes/)+ assert.match(lineText(notices[0]), /late reply/)+})++test('a member still at work is shown with the group messages it has not read yet', async (t) => {+ const { call, emit, userMessage, relay, answer, stop, sent, rt } = start()+ t.after(stop)+ const chief = (await call('state', {})).value.mainBotId+ const writer = (await call('create-bot', { name: 'Writer' })).value+ const editor = (await call('create-bot', { name: 'Editor' })).value+ const room = (await call('create-room', { name: 'R1', members: [chief, writer.id, editor.id] })).value+ await call('update-room', { id: room.id, mode: 'everyone' })+ sent.length = 0++ // First round: every member speaks once, so each has a group Session and a `seen`.+ await emit(room.id, userMessage('hello'))+ const first0 = relay(room.id, 'relay-1')+ const spoken = []+ for (const text of ['Chief here.', 'Writer here.', 'Editor here.']) {+ const turn = await turnFor(sent, ...spoken)+ await answer(turn.sessionId, turn.message.source.exchangeId, text, 1)+ spoken.push(turn)+ }+ await first0++ // Second round. Editor starts a turn of its own and does not finish it, so when+ // the round calls it, it is at earlier work and the round moves on.+ await emit(room.id, userMessage('again'))+ const second0 = relay(room.id, 'relay-2')+ const chiefTurn = await turnFor(sent, ...spoken)+ await emit(rt.state.rooms[room.id].sessions[editor.id], { type: 'turn/start', data: { turn: 9 } })+ await answer(chiefTurn.sessionId, chiefTurn.message.source.exchangeId, 'Chief again.', 2)+ spoken.push(chiefTurn)++ // The Writer's prompt names Editor as still at work, with the group lines Editor+ // has not read: the user's message and the Chief's answer since Editor last spoke.+ const writerTurn = await turnFor(sent, ...spoken)+ assert.match(writerTurn.message.content[0].text, /Editor \(1 min, with [1-9]\d* group message\(s\) it has not read yet\)/)+ await answer(writerTurn.sessionId, writerTurn.message.source.exchangeId, 'Writer again.', 2)+ await second0+})++test('a user message that opens a round resets the quiet notice, as a queued one does', async (t) => {+ const { call, emit, userMessage, relay, answer, stop, sent, rt } = start()+ t.after(stop)+ const room = await team(call, sent)+ await call('update-room', { id: room.id, mode: 'admin' })++ await emit(room.id, userMessage('Start'))+ const first = relay(room.id, 'relay-1')+ const turn = await turnFor(sent)+ await answer(turn.sessionId, turn.message.source.exchangeId, 'Ready.', 1)+ await first++ const state = rt.state.rooms[room.id]+ // The group has gone quiet, and it has been told so.+ state.lateRounds = 10+ state.quietNoticed = true++ // The user writes in the group. This message opens a round of its own, rather than+ // waiting in the inbox for one that is running, and the quiet notice has to reset+ // with the count: otherwise the group is told about quiet mode only once, ever.+ await emit(room.id, userMessage('carry on'))+ const second = relay(room.id, 'relay-2')+ const again = await turnFor(sent, turn)+ await answer(again.sessionId, again.message.source.exchangeId, 'On it.', 2)+ await second+ assert.equal(state.lateRounds, 0)+ assert.equal(state.quietNoticed, false, 'the quiet notice can be told again later')+})diff --git a/ds-bot/test/tool-cells.test.js b/ds-bot/test/tool-cells.test.jsindex 32a43dc7..fc0e761f 100644--- a/ds-bot/test/tool-cells.test.js+++ b/ds-bot/test/tool-cells.test.js@@ -149,6 +149,21 @@ test('a user message inside a group relay shows its time', () => {assert.deepEqual(times.map(node => node.props.title), [`Today ${clockOf(today)}`])})+// Drops the round kept silent about get a line the user sees: calls past the+// per-member limit, and the group slipping into quiet mode.+test('a dropped call and quiet mode show as event lines in the round', () => {+ const replies = [+ { kind: 'dropped', names: ['Writer', 'Coder'], cap: 2, time: at(0, 14, 5) },+ { kind: 'quiet', time: at(0, 14, 6) },+ ]+ const out = show(call('group_relay', 'direct', { content: { replies } }), { sessionId: 'room' })+ const events = findAll(out, node => node.props?.className === 'bt-event').map(text)+ assert.deepEqual(events, [+ 'Writer and Coder not called: the per-member limit for this round is reached',+ 'The group went quiet: @ mentions in late replies call nobody until you write here',+ ])+})+// The trigger of a post in a group chat carries the event's time, not the post's.test('a group post drawn from its trigger shows the time it came in', () => {const time = at(0, 16, 42)