Skip to content

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

Merge a member's close lines instead of holding them for minutes

Fei24115f41883246d0
diff --git a/ds-bot/src/host/constants.js b/ds-bot/src/host/constants.js
index ca764f1e..a694671a 100644
--- a/ds-bot/src/host/constants.js
+++ b/ds-bot/src/host/constants.js
@@ -29,8 +29,8 @@ export const MAX_UNATTENDED_MESSAGES = 40
export const MAX_UNREAD_REQUESTS = 10
export const MAX_EXCHANGES = 600
export const ROOM_REPLY_TIMEOUT_MS = 240_000
-// How often at most what a member says while it works reaches its group.
-export const ROOM_STEP_GAP_MS = 120_000
+// Lines a member writes less than this apart while it works reach its group together.
+export const ROOM_STEP_GAP_MS = 30_000
export const SOURCE_KIND = 'bot'
// The fixed reply that opens a fresh conversation part; it is never shown or sent on.
export const HANDOFF_ACK = 'Noted. I have my handoff note and carry on from here.'
diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.js
index 2873da83..8a6c611e 100644
--- a/ds-bot/src/host/groups.js
+++ b/ds-bot/src/host/groups.js
@@ -636,10 +636,10 @@ export function install(rt) {
await postToRoom(room, member, text, { progress: true, hop: info?.hop ?? 0, ...(quiet ? { quiet: true } : {}) })
}
- // A member that writes at every step would fill the group, so what it says goes out at
- // most once per gap, the lines since the last one together. The first line of work it
- // was asked for and a line that calls a member go at once; lines still held when the
- // turn ends give way to its result. Per group Session.
+ // Lines a member writes close together reach the group as one message, so a burst of
+ // steps does not come out as a string of messages. Its first line on work it was asked
+ // for and a line that calls a member go at once; lines still held when the turn ends
+ // open its result. Per group Session.
const held = new Map()
ctx.effect(() => () => { for (const entry of held.values()) clearTimeout(entry.timer) }, 'ds-bot: group step lines')
const flushSteps = (sessionId) => {
@@ -662,14 +662,15 @@ export function install(rt) {
if ((first && info?.role === 'room') || callsIn(room, member, text) || Date.now() - entry.last >= ROOM_STEP_GAP_MS) return flushSteps(sessionId)
entry.timer ??= setTimeout(() => void flushSteps(sessionId)?.catch(error => rt.warn('ds-bot: step lines from %s not posted: %s', member.name, error)), entry.last + ROOM_STEP_GAP_MS - Date.now())
}
- rt.endRoomSteps = (sessionId) => {
+ rt.takeRoomSteps = (sessionId) => {
const entry = held.get(sessionId)
- if (entry === undefined) return
+ if (entry === undefined) return ''
clearTimeout(entry.timer)
entry.timer = undefined
- entry.lines = []
entry.last = Date.now()
+ return entry.lines.splice(0).join('\n\n')
}
+ rt.withRoomSteps = (lines, reply) => (lines === '' ? reply : isPass(reply) ? lines : `${lines}\n\n${reply}`)
// The user stops a member's work in this group from the group's details. Messages
// still waiting for that member here go with it.
diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.js
index 6e883a9c..ba4bd434 100644
--- a/ds-bot/src/host/turns.js
+++ b/ds-bot/src/host/turns.js
@@ -461,7 +461,7 @@ export function install(rt) {
const reason = event.data?.reason
const failure = reason?.kind === 'error' && !switched ? turnFailure(reason.error) : undefined
if (failure !== undefined) noteTurnFailure(id, failure)
- if (rt.groupOwners.has(id)) rt.endRoomSteps?.(id)
+ const held = rt.groupOwners.has(id) ? rt.takeRoomSteps?.(id) ?? '' : ''
if (switched) break
// A model that writes its tool call as text ends the turn as if it were done,
// though nothing ran. It gets one more turn on the same trigger, so a waiting
@@ -474,6 +474,7 @@ export function install(rt) {
const reply = (wroteCall ? texts.map(stripWrittenCalls) : texts).join('\n\n').trim()
return wroteCall && reply === '' ? 'Tried to run a tool but wrote the call as text, so it did not run.' : reply
}
+ const groupReply = () => rt.withRoomSteps?.(held, replyText()) ?? replyText()
// Whoever the turn answers gets the same three-way rule: a failure notice,
// the turn's text (or a stopped-before-answer line), or nothing.
const answer = (source, reply) => {
@@ -514,15 +515,15 @@ export function install(rt) {
const stopped = stoppedRoomTurns.delete(info.exchangeId)
if (waiter !== undefined) {
if (failure !== undefined) waiter.fail(failure)
- else waiter.resolve(reason?.kind === 'aborted' ? null : replyText())
+ else waiter.resolve(reason?.kind === 'aborted' ? null : groupReply())
} 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, replyText())
+ else void rt.lateRoomReply?.(id, info, groupReply())
}
} 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 ?? {}, replyText())
+ else if (reason?.kind !== 'aborted') void rt.lateRoomReply?.(id, info ?? {}, groupReply())
} 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.js
index 5c4e2969..66f9267a 100644
--- a/ds-bot/test/group-work.test.js
+++ b/ds-bot/test/group-work.test.js
@@ -358,7 +358,7 @@ test('a member whose every message went out while it worked counts as posted, no
assert.deepEqual([result().passed, result().replies.map(reply => reply.text)], [[], ['我看一下。']])
})
-test('after the round went on, what a member says reaches the group at most once per gap; only the result is answered', async (t) => {
+test('after the round went on, lines a member writes close together reach the group as one message; only the result is answered', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout'] })
const host = await start(t)
const first = host.round('c1', host.say('@Chief 安排一下文档'))
@@ -386,14 +386,14 @@ test('after the round went on, what a member says reaches the group at most once
await settle(() => quiet() !== undefined)
assert.deepEqual(quiet().replies, [])
- // A line still held when the work ends gives way to the result.
+ // A line still held when the work ends opens the result.
host.emit('gb', 'tool/result', { callId: 'k3' })
step(host, 'gb', '索引也改完了。', 'k4')
host.emit('gb', 'tool/result', { callId: 'k4' })
host.finish('gb', '整理好了,在 docs/ 下。')
await settle(() => host.agentOf('r1').calls.length === 1)
const done = host.takePost()
- assert.deepEqual([done.source.late, done.source.askedBy, text(done)], [true, 'a', '[Group post from Writer]\n整理好了,在 docs/ 下。'])
+ assert.deepEqual([done.source.late, done.source.askedBy, text(done)], [true, 'a', '[Group post from Writer]\n索引也改完了。\n\n整理好了,在 docs/ 下。'])
t.mock.timers.tick(ROOM_STEP_GAP_MS)
await settle(() => true)
assert.deepEqual(host.agentOf('r1').calls, [])