A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Let any group member post into its group
Fei24119c9a024aa6fb
diff --git a/docs/plans/2026-10-07-group-chat.md b/docs/plans/2026-10-07-group-chat.mdindex fb52e4d3..56c78f5a 100644--- a/docs/plans/2026-10-07-group-chat.md+++ b/docs/plans/2026-10-07-group-chat.md@@ -34,7 +34,8 @@### Bot 发起的轮次和上限-- Main Bot 能往任何群发言,管理员能往自己的群发言(`post_to_group`),发言人自己不参与回答。+- Main Bot 能往任何群发言,其他 Bot 能往自己所在的群发言(`post_to_group`),发言人自己不参与回答。+- Main Bot 和管理员的帖子按「谁来回答」叫人。其他成员的帖子只叫它用 `@名字` 点到的成员,`@all` 等不算;没点人就只写进群里,没人回答。同一次转发里还有别的消息时,由那条消息选人。- Bot 发起的轮次和全团队的 Bot 消息都不计数(见 [Bot 之间派活](2026-10-16-bot-handoffs.md))。Bot 被告知不要发感谢或确认,也不要回复一条回复。- Bot 为别的 Bot 交给它的活发帖并要回报(`report_back`)时,这一轮是那件活下面的活:回报交回之前,它给派活 Bot 的回复先不交。@@ -84,3 +85,4 @@- 2026-10-14:干活中的进度发到群里,结果由派活的 Bot 接话(PR #175);群的统一权限(PR #180)。- 2026-10-16:群里的活只留在群里:群里的 `message_bot` 只叫本群成员,等同 `@名字`(#165)。- 2026-10-16:去掉 Bot 在一个群里 3 轮和全团队 40 条的上限;要回报的发帖进派活树(#262)。+- 2026-10-18:其他成员也能往自己所在的群发帖,只叫 `@` 点到的成员(#198)。diff --git a/docs/plans/2026-10-07-roles-and-permissions.md b/docs/plans/2026-10-07-roles-and-permissions.mdindex c097de85..3ea61f6f 100644--- a/docs/plans/2026-10-07-roles-and-permissions.md+++ b/docs/plans/2026-10-07-roles-and-permissions.md@@ -21,7 +21,7 @@| 用户 | 全部 | 一切操作,包括设置、取消 Main Bot,设置 Bot 和群的沙盒权限 || Main Bot | 整个团队 | 建 Bot(`create_bot`)、改任何 Bot(`update_bot`)、停止别的 Bot 正在跑的回合(`stop_bot`);建群、改任何群、删群、往任何群发言;写团队记忆,按用户要求读写某个 Bot 的记忆;给任何 Bot 挂、摘能力 || 群管理员 | 自己管的群 | 改自己的群(改名、公告、成员、管理员、回答方式),往自己的群发言,写团队记忆。不能删群,不能改群的工作文件夹 |-| 普通 Bot | 自己 | 改自己的名字、角色、颜色、模型、工作文件夹、指令;给自己挂、摘能力;在群里发言、用 `@` 点名;在私聊里用 `message_bot` 给任何 Bot 发消息(在群里只能叫本群成员,见 [群聊](2026-10-07-group-chat.md)) |+| 普通 Bot | 自己 | 改自己的名字、角色、颜色、模型、工作文件夹、指令;给自己挂、摘能力;在群里发言、用 `@` 点名;往自己所在的群发帖(只叫 `@` 点到的成员);在私聊里用 `message_bot` 给任何 Bot 发消息(在群里只能叫本群成员,见 [群聊](2026-10-07-group-chat.md)) |- 可以有多个 Main Bot,至少保留一个。只有用户能设置或取消 Main Bot。- Main Bot 不能直接删除,要先取消它的 Main Bot 角色。diff --git a/ds-bot/README.md b/ds-bot/README.mdindex 13ac307b..928491d4 100644--- a/ds-bot/README.md+++ b/ds-bot/README.md@@ -20,7 +20,7 @@ Tested with dsh `0.2.0-rc.2` (Web and Desktop) on Linux.| You | Everything || Main Bot (there can be more than one) | Manage every group; change and delete Bots || Group admin | Manage its own group only (name, notice, members, reply mode) |- | Member | Speak in the group and `@` another member |+ | Member | Speak in the group, `@` another member, and post into its groups from outside them |- **Long chats stay inside the model's window**: dsh's own compaction never runs on a Bot's Session. When a turn ends past the check line (a share of the model's context window), a small separate model call, the context steward, reads the latest messages of the chat and decides once. If the work is still under way, the chat is condensed in place into a checkpoint: a handoff summary plus your recent messages word for word. If the work has reached a stopping point, the Bot writes a handoff note and continues in a new part. Either way you still see one chat, with no marker. Earlier parts and condensed messages stay searchable in a full-text index (`node:sqlite` FTS5) through `read_own_chat`.- **Memory**: each Bot keeps notes across all its conversations, and the team shares one more. See [Memory](#memory).diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.jsindex 6149573b..5dc679df 100644--- a/ds-bot/src/host/groups.js+++ b/ds-bot/src/host/groups.js@@ -519,8 +519,10 @@ export function install(rt) {}if (posts.some(post => !post.botId && !post.kickoff)) room.lateRounds = 0await rt.save()- // An event post never picks the speakers over a message queued with it.- const opener = posts.findLast(post => !event(post)) ?? posts.at(-1)+ // An event post, and a member post that calls nobody, never pick the speakers+ // over a message queued with them.+ const callsNobody = post => post.member === true && openingSpeakers(room, post).length === 0+ const opener = posts.findLast(post => !event(post) && !callsNobody(post)) ?? posts.findLast(post => !event(post)) ?? posts.at(-1)const references = posts.flatMap(post => post.references ?? [])// A member a Bot's post calls by name works for that Bot.const named = opener.botId === undefined ? [] : mentionsIn(opener.text ?? '', room.members.map(rt.botOf).filter(Boolean)).found@@ -679,6 +681,7 @@ export function install(rt) {const found = named.filter(bot => bot.id !== opener.botId)if (opener.progress) return foundif (opener.late) return found.length > 0 ? found : members.filter(bot => bot.id === opener.askedBy)+ if (opener.member) return foundif (found.length > 0 && !all) return foundif (!all && room.mode === 'admin' && admin) return [admin]return admin ? [admin, ...members.filter(bot => bot !== admin)] : membersdiff --git a/ds-bot/src/host/prompt.js b/ds-bot/src/host/prompt.jsindex 232cad39..aa24bb3c 100644--- a/ds-bot/src/host/prompt.js+++ b/ds-bot/src/host/prompt.js@@ -16,7 +16,7 @@ const TEAM_RULES = ['- In a group chat, the group sees what you write while you work, not only your final reply. For work that takes more than a quick look, start with one short sentence on what you will do, in the same response as your first tool call. After that, write only when you find something the group should know or finish a part of the work, in a sentence or two, not at every step. End with the result. Simple answers need no updates.','- Offer choices with ask_user (a tap-to-answer card) instead of long option lists in text. Calling it ends your turn at once, so write everything you want to say before the call, in the same reply. The answer arrives as the user\'s next message.','- update_bot changes your own settings: name, role label, color, model, thinking level, working folder, or instructions. Leave out bot to change yourself. Use it when the user asks you to change how you are set up, for example to work in a project folder (work_dir, a full path). Only a Main Bot can change other Bots; when another Bot needs changing, ask a Main Bot.',- '- You may be in group chats with the user and other Bots. You speak in each group from a separate conversation of yours, apart from your own chat with the user. There your turn arrives as a "[Group chat …]" message that shows the speaking order, and your reply is posted to the group. When someone there asks you to do something, do the work in that turn: the group goes on without waiting and sees what you write as you go. Any member can hand work to another with @Name, and the one that asked answers the result. Work for a group stays in it: there message_bot reaches only members of that group, as @Name does. In a group, read_own_chat shows your own chat (the group sees that you looked; share only what the group needs). In your own chat, read_group_chat shows what was said in a group. A group may have an admin, who steers it: the admin can call members with @Name, change the group with update_group, and start a new discussion there with post_to_group.',+ '- You may be in group chats with the user and other Bots. You speak in each group from a separate conversation of yours, apart from your own chat with the user. There your turn arrives as a "[Group chat …]" message that shows the speaking order, and your reply is posted to the group. When someone there asks you to do something, do the work in that turn: the group goes on without waiting and sees what you write as you go. Any member can hand work to another with @Name, and the one that asked answers the result. Work for a group stays in it: there message_bot reaches only members of that group, as @Name does. In a group, read_own_chat shows your own chat (the group sees that you looked; share only what the group needs). In your own chat, read_group_chat shows what was said in a group. A group may have an admin, who steers it: the admin can call members with @Name and change the group with update_group. From outside a group (your own chat or another group), post_to_group posts into a group you are in: the admin\'s post starts a new discussion there; another member\'s post calls only the members it names with @Name.','- When you need a key, token, or password, call request_secret: the user types it into a secure card and you never see it. Never ask the user to paste one into the chat. Use it through its environment variable ($DSH_SECRET_<NAME> in bash, $env:DSH_SECRET_<NAME> in PowerShell) and never print it. list_secrets shows which keys exist.','- web_search results say which search backend answered. If web_search fails, never guess URLs or present pages you remember as search results: use a browser tool if you have one, otherwise tell the user that search is unavailable and the reason it gave.','- Your conversations are long-lived. When one grows long, either its older messages are condensed in place into a summary you wrote (a "[Checkpoint N]" message), or it moves on to a fresh part that opens with a handoff note you wrote and your latest messages (a "[Handoff · part N]" message). What leaves your working context stays saved. When you need the exact earlier wording or a detail the summary or note does not show in full (a full path, a figure, every item of a complete list or a final summary), call read_own_chat with words to look for, or with part N to read the note that closed an earlier part; never fill such a detail in from memory. Each line it returns starts with an anchor such as [part 2 #1234 · 10-08 14:22]; pass the anchor as around to read what was said around it.',diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.jsindex 05990632..e5cfb73f 100644--- a/ds-bot/src/host/tools.js+++ b/ds-bot/src/host/tools.js@@ -460,7 +460,7 @@ export function install(rt) {ctx.tools.register(defineTool({name: 'post_to_group',- description: 'Post a message into a group chat as yourself. It starts a round: members reply in the group, where the user reads them. Main Bots may post into any group; an admin into its own group.',+ description: 'Post a message into a group chat as yourself. A Main Bot may post into any group, any other Bot into a group it is in. A Main Bot\'s or the group admin\'s post starts a round: members reply in the group, where the user reads them. Another member\'s post calls only the members it names with "@Name"; without one it is only written into the group.',parameters: {group: GROUP_REF,message: { type: 'string', required: true, description: 'What to say; write "@Name" to choose who answers, and a name without "@" to only mention a member' },@@ -474,26 +474,31 @@ export function install(rt) {if (sender === undefined) return 'Only Bots on the team can use post_to_group.'const { room, error } = pickRoom(args.group, self)if (error) return error- 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.`+ // An ordinary member's post calls only the members it names (openingSpeakers).+ const member = !rt.isMain(self) && !rt.isAdminOf(room, self)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.`const text = absoluteLinks(String(args.message ?? '').trim(), rt.sessionFolder?.(exec.agent?.session ?? exec.agent))if (text === '') return 'Write a message to post.'+ const named = mentionSpans(text, room.members.map(rt.botOf).filter(Boolean)).flatMap(span => (span.bot && span.bot.id !== self ? [span.bot.id] : []))+ const reportBack = args.report_back === true+ if (member && reportBack && named.length === 0) {+ return 'Nobody would answer: your post only calls the members you name. Write "@Name" for each member who should answer, or post without report_back.'+ }const long = await rt.attachLong(text, `Post from ${sender.name}.txt`)if (long === undefined) return tooLong(text)- const reportBack = args.report_back === true// Replies the poster waits for, while it works on what a Bot asked it for, are// work handed on for that request (handoffs.js).const work = reportBack ? worksOf(exec).find(id => rt.ownsWork(self, id)) : undefinedconst sub = work === undefined ? undefined : randomUUID()if (sub !== undefined) rt.openWork(sub, { from: self, room: room.id, parent: work })try {- await rt.postToRoom(room, sender, long.text, { ...(reportBack ? { reportBack: true } : {}), ...(sub ? { sub } : {}), ...(long.length ? { length: long.length } : {}) }, long.files)+ await rt.postToRoom(room, sender, long.text, { ...(reportBack ? { reportBack: true } : {}), ...(member ? { member: true } : {}), ...(sub ? { sub } : {}), ...(long.length ? { length: long.length } : {}) }, long.files)} catch (failure) {if (sub !== undefined) rt.dropWork(sub)return `Could not post in "${room.name}": ${failure.message}`}- const named = mentionSpans(text, room.members.map(rt.botOf).filter(Boolean)).flatMap(span => (span.bot ? [span.bot.id] : []))+ if (member && named.length === 0) return `Posted in "${room.name}", where the user and its members read it. Nobody answers it: your post only calls the members you name with @Name.`if (named.length > 0) {const turn = turnOf(exec)const earlier = calledInPosts.get(exec.agent?.id)diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.jsindex dbdb4c23..179c9cf3 100644--- a/ds-bot/src/host/turns.js+++ b/ds-bot/src/host/turns.js@@ -435,6 +435,7 @@ export function install(rt) {botId: source.senderSessionId,name: source.senderName,reportBack: source.reportBack === true,+ ...(source.member ? { member: true } : {}),...(source.sub ? { sub: source.sub } : {}),...(source.late ? { late: true } : {}),...(source.progress ? { progress: true } : {}),diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.jsindex afdad5b7..ab539700 100644--- a/ds-bot/test/group-work.test.js+++ b/ds-bot/test/group-work.test.js@@ -8,7 +8,7 @@ import { fakeAttachments, fakeContext } from './fake-ctx.js'import { MESSAGE_INLINE_MAX, ROOM_LATE_ROUNDS, ROOM_STEP_GAP_MS, ROOM_WORK_GRACE_MS } from '../src/host/constants.js'// Chief, the admin of group 'r1', speaks there from 'ga'; Writer from 'gb'; Tester from 'gc'.-const seed = (room = {}) => ({+const seed = (room = {}, extraRooms = {}) => ({version: 1,mainBotIds: ['a'],bots: {@@ -16,7 +16,7 @@ const seed = (room = {}) => ({b: { id: 'b', name: 'Writer', role: 'Write', sessionId: 'b', createdAt: 2 },c: { id: 'c', name: 'Tester', role: 'Test', sessionId: 'c', createdAt: 3 },},- rooms: { r1: { id: 'r1', name: 'Ops', members: ['a', 'b', 'c'], mode: 'admin', admin: 'a', named: true, sessions: { a: 'ga', b: 'gb', c: 'gc' }, log: [], seq: 0, seen: {}, ...room } },+ rooms: { r1: { id: 'r1', name: 'Ops', members: ['a', 'b', 'c'], mode: 'admin', admin: 'a', named: true, sessions: { a: 'ga', b: 'gb', c: 'gc' }, log: [], seq: 0, seen: {}, ...room }, ...extraRooms },agents: {},exchanges: [],exchangeTurns: {},@@ -25,9 +25,9 @@ const seed = (room = {}) => ({revision: 0,})-async function start(t, room, services) {+async function start(t, room, services, extraRooms) {const home = mkdtempSync(join(tmpdir(), 'ds-bot-work-'))- writeFileSync(join(home, 'state.json'), JSON.stringify(seed(room)))+ writeFileSync(join(home, 'state.json'), JSON.stringify(seed(room, extraRooms)))const ctx = fakeContext({ services })const agents = new Map()const agentOf = (sessionId) => {@@ -543,6 +543,113 @@ test('a post with no round running keeps the old way: queued, no logged mark', aassert.equal(logLines(host).filter(line => line.text === '@Writer 看一下文档').length, 1)})+// A member posts into a group it is in; nobody answers a post that names nobody.+test('an ordinary member posts into its group from its own chat; nobody answers', async (t) => {+ const host = await start(t)+ const posted = await host.tool('post_to_group', { group: 'Ops', message: '文档有了新进展' }, 'b')+ assert.match(posted, /Nobody answers it: your post only calls the members you name with @Name\.$/)+ assert.equal(host.agentOf('r1').calls.length, 1)++ const first = host.round('c1', host.takePost())+ await settle(() => first() !== undefined)+ const lines = logLines(host).filter(line => line.text === '文档有了新进展')+ assert.equal(lines.length, 1)+ assert.equal(lines[0].botId, 'b')+ assert.deepEqual(host.agentOf('ga').calls, [])+ assert.deepEqual(host.agentOf('gb').calls, [])+ assert.deepEqual(host.agentOf('gc').calls, [])+})++test('a member post calls only the members it names', async (t) => {+ const host = await start(t)+ await host.tool('post_to_group', { group: 'Ops', message: '@Tester 看一下文档' }, 'b')+ const first = host.round('c1', host.takePost())+ await settle(() => host.agentOf('gc').calls.length === 1)+ assert.equal(host.begin('gc').source.askedBy, 'b')+ assert.match(text(host.agentOf('gc').calls[0]), /Writer: @Tester 看一下文档/)+ host.finish('gc', '看过了。')+ await settle(() => first() !== undefined)+ assert.deepEqual(host.agentOf('ga').calls, [])+ assert.deepEqual(host.agentOf('gb').calls.filter(call => call.source?.role !== 'post'), [])+})++test('a member post that names only itself calls nobody', async (t) => {+ const host = await start(t)+ const rejected = await host.tool('post_to_group', { group: 'Ops', message: '@Writer 记一下', report_back: true }, 'b')+ assert.match(rejected, /Nobody would answer: your post only calls the members you name/)+ assert.equal(host.agentOf('r1').calls.length, 0)+ assert.equal(logLines(host).length, 0)++ const posted = await host.tool('post_to_group', { group: 'Ops', message: '@Writer 记一下' }, 'b')+ assert.match(posted, /Nobody answers it: your post only calls the members you name with @Name\.$/)+ const first = host.round('c1', host.takePost())+ await settle(() => first() !== undefined)+ assert.equal(logLines(host).filter(line => line.text === '@Writer 记一下').length, 1)+ assert.deepEqual(host.agentOf('ga').calls, [])+ assert.deepEqual(host.agentOf('gc').calls, [])+})++test('a member post with @all calls nobody', async (t) => {+ const host = await start(t)+ await host.tool('post_to_group', { group: 'Ops', message: '@all 看一下文档' }, 'b')+ const first = host.round('c1', host.takePost())+ await settle(() => first() !== undefined)+ assert.deepEqual(host.agentOf('ga').calls, [])+ assert.deepEqual(host.agentOf('gc').calls, [])+ assert.equal(logLines(host).filter(line => line.text === '@all 看一下文档').length, 1)+})++test('a member post that names nobody is rejected with report_back', async (t) => {+ const host = await start(t)+ const posted = await host.tool('post_to_group', { group: 'Ops', message: '快看文档', report_back: true }, 'b')+ assert.match(posted, /Nobody would answer: your post only calls the members you name/)+ assert.equal(host.agentOf('r1').calls.length, 0)+ assert.equal(logLines(host).length, 0)+ assert.deepEqual(JSON.parse(readFileSync(join(host.home, 'state.json'), 'utf8')).works ?? {}, {})+})++test('a member post during a running round is logged at once and calls nobody next', async (t) => {+ const { host, first } = await busyRound(t)+ await host.tool('post_to_group', { group: 'Ops', message: '群里的进展' }, 'b')+ const during = logLines(host)+ const logged = during.at(-1)+ assert.deepEqual([logged.who, logged.botId, logged.text], ['Writer', 'b', '群里的进展'])+ const post = host.takePost()+ assert.equal(post.source.logged, logged.seq)+ host.finish('gb', '整理好了。')+ await settle(() => first() !== undefined)++ const second = host.round('c2', post)+ await settle(() => second() !== undefined)+ assert.equal(logLines(host).filter(line => line.text === '群里的进展').length, 1)+ assert.deepEqual(host.agentOf('ga').calls, [])+ assert.deepEqual(host.agentOf('gc').calls, [])+})++test('a member post that calls nobody does not pick the speakers over a user message', async (t) => {+ const host = await start(t)+ await host.tool('post_to_group', { group: 'Ops', message: '让群里注意' }, 'b')+ // Both land in the same relay; the user's message picks the speakers.+ host.emit('r1', 'user/message', host.takePost())+ const first = host.round('c1', host.say('检查一下文档'))+ await settle(() => host.agentOf('ga').calls.length === 1)+ host.begin('ga')+ host.finish('ga', '看过了。')+ await settle(() => first() !== undefined)+ assert.deepEqual(host.agentOf('gb').calls.filter(call => call.source?.role !== 'post'), [])+ assert.deepEqual(host.agentOf('gc').calls, [])+})++test('a member cannot post into a group it is not in', async (t) => {+ const host = await start(t, {}, undefined, {+ r2: { id: 'r2', name: 'Lab', members: ['a', 'c'], mode: 'admin', admin: 'a', named: true, sessions: {}, log: [], seq: 0, seen: {} },+ })+ const posted = await host.tool('post_to_group', { group: 'Lab', message: '看一下' }, 'b')+ assert.match(posted, /No group chat called "Lab" that you can see/)+ assert.equal(host.agentOf('r2').calls.length, 0)+ assert.equal(logLines(host).length, 0)+})+// Such a message was sent before message_bot from a group stayed in that group.test('a reply to a message a group Session sent comes back there, and its turn posts in the group', async (t) => {const host = await start(t)