A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Refuse Bot names that stand for the user
Fei2411e8e2ede9656c
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 9b5e894a..43ce3fbb 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -897,6 +897,7 @@ var HOST_ERRORS = [[/^A Bot named (.+) already exists$/, "已经有叫 $1 的 Bot 了"],[/^Name (.*) is not available$/, "名字 $1 不可用"],[/^"(.+)" calls everyone in a group, so it cannot be a Bot name$/, "「$1」在群里表示所有人,不能用作 Bot 名字"],+ [/^"(.+)" stands for the user in a chat, so it cannot be a Bot name$/, "「$1」在对话里表示用户本人,不能用作 Bot 名字"],[/^Another group chat is already called "(.+)"$/, "已经有叫「$1」的群聊了"],[/^A group chat holds at most (\d+) Bots$/, "一个群聊最多 $1 个 Bot"],[/^Reply mode must be one of (.+)$/, "回复模式只能是 $1"],@@ -1404,6 +1405,8 @@ var allThemes = () => ({ ...THEMES, ...customThemes });// src/shared/mentions.jsvar ALL_WORDS = ["all", "everyone", "所有人", "全体"];+var USER_NAMES = ["user", "you"];+var speakerOf = (line) => line.botId !== void 0 && USER_NAMES.includes(String(line.who ?? "").trim().toLowerCase()) ? `Bot "${line.who}"` : line.who;var NAME_GOES_ON = /^(?:[a-z0-9_\-/\\]|\.[a-z0-9_-])/i;var ADDRESS_BEFORE = /[a-z0-9_./]/i;var LITERAL = /```[\s\S]*?(?:```|$)|`[^`\n]*`|\[[^\]\n]*\]\([^)\s]*(?:\s+(?:"[^"\n]*"|'[^'\n]*'))?\)/g;@@ -1414,6 +1417,7 @@ function nameProblem(name) {if (text === "") return "A Bot needs a name";if (/[@`\r\n]/.test(text)) return "A Bot name cannot contain @, ` or a line break";if (ALL_WORDS.includes(text.toLowerCase())) return `"${text}" calls everyone in a group, so it cannot be a Bot name`;+ if (USER_NAMES.includes(text.toLowerCase())) return `"${text}" stands for the user in a chat, so it cannot be a Bot name`;return void 0;}function referenceSpans(text, labels = []) {diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.jsindex 83b39980..a61b76cd 100644--- a/ds-bot/src/client/i18n.js+++ b/ds-bot/src/client/i18n.js@@ -850,6 +850,7 @@ const HOST_ERRORS = [[/^A Bot named (.+) already exists$/, '已经有叫 $1 的 Bot 了'],[/^Name (.*) is not available$/, '名字 $1 不可用'],[/^"(.+)" calls everyone in a group, so it cannot be a Bot name$/, '「$1」在群里表示所有人,不能用作 Bot 名字'],+ [/^"(.+)" stands for the user in a chat, so it cannot be a Bot name$/, '「$1」在对话里表示用户本人,不能用作 Bot 名字'],[/^Another group chat is already called "(.+)"$/, '已经有叫「$1」的群聊了'],[/^A group chat holds at most (\d+) Bots$/, '一个群聊最多 $1 个 Bot'],[/^Reply mode must be one of (.+)$/, '回复模式只能是 $1'],diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.jsindex 9f636fd5..5ab4c87a 100644--- a/ds-bot/src/host/groups.js+++ b/ds-bot/src/host/groups.js@@ -19,7 +19,7 @@ import { createUserMessage } from '@deepseek-ai/dsh-llm'import { defineTool } from '@deepseek-ai/dsh-tools'import { ROOM_LATE_ROUNDS, ROOM_REPLY_TIMEOUT_MS, ROOM_STEP_GAP_MS, ROOM_WORK_GRACE_MS, SOURCE_KIND, TEAM_TOOLS } from './constants.js'import { escapeRegExp, splitRef, textOf } from './text.js'-import { mentionSpans } from '../shared/mentions.js'+import { mentionSpans, speakerOf } from '../shared/mentions.js'import { GROUP_REF, output } from './tools.js'import { failureLine } from './turns.js'@@ -54,11 +54,11 @@ const unseenLines = (room, memberId) => {}const lineText = (line) => {- if (line.kind === 'lookup') return `[${line.who} looked up its own chat${line.text ? ` for "${line.text}"` : ''}]`- 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]`- return `${line.who}: ${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]`+ return `${speakerOf(line)}: ${line.text}`}const transcript = lines => lines.map(lineText).join('\n')diff --git a/ds-bot/src/host/memory.js b/ds-bot/src/host/memory.jsindex d525622b..547e923a 100644--- a/ds-bot/src/host/memory.js+++ b/ds-bot/src/host/memory.js@@ -27,6 +27,7 @@ import { dirname, join } from 'node:path'import { BlockAssembler } from '@deepseek-ai/dsh-llm'import { defineTool } from '@deepseek-ai/dsh-tools'import { splitRef, unquote } from './text.js'+import { speakerOf } from '../shared/mentions.js'import { output } from './tools.js'// Fixed sizes, in characters. Both MEMORY.md files ride in every request of every@@ -1127,14 +1128,14 @@ export function install(rt) {const log = (room.log ?? []).filter(line => line.kind === undefined && typeof line.text === 'string' && line.text.trim() !== '')// A first review reads back at least to the user's latest line, which a round of// replies from many members can push out of the last few.- const lastUser = log.findLastIndex(line => line.who === 'User')+ const lastUser = log.findLastIndex(line => line.who === 'User' && line.botId === undefined)let start = since === undefined ? Math.max(0, Math.min(log.length - REVIEW_FIRST_LINES, lastUser === -1 ? log.length : lastUser)) : log.findIndex(line => line.seq > since)const oldest = room.log?.[0]?.seqif (since !== undefined && oldest !== undefined && oldest > since + 1) rt.warn('ds-bot: %d lines of group "%s" left its log before %s reviewed them', oldest - since - 1, room.name, bot.name)if (start === -1) start = log.lengthconst line = (entry) => {- const who = entry.who === 'User' ? 'user' : entry.botId === bot.id ? 'you' : 'bot'- return { who, text: `${who === 'user' ? 'User' : who === 'you' ? 'You' : entry.who}: ${entry.text}`, seq: entry.seq }+ const who = entry.botId === undefined && entry.who === 'User' ? 'user' : entry.botId === bot.id ? 'you' : 'bot'+ return { who, text: `${who === 'user' ? 'User' : who === 'you' ? 'You' : speakerOf(entry)}: ${entry.text}`, seq: entry.seq }}return {through: log.at(-1)?.seq,diff --git a/ds-bot/src/shared/mentions.js b/ds-bot/src/shared/mentions.jsindex 54ef4747..504e212b 100644--- a/ds-bot/src/shared/mentions.js+++ b/ds-bot/src/shared/mentions.js@@ -3,6 +3,12 @@// is what gets called. Pure, so both sides import it.export const ALL_WORDS = ['all', 'everyone', '所有人', '全体']+// The speaker names a group log and a Bot's own chat give the user ("User: …",+// "You: …"). A Bot with one of them would read as the user.+export const USER_NAMES = ['user', 'you']+// The name a group log line goes by. A Bot named before such names were refused still+// never reads as the user.+export const speakerOf = line => (line.botId !== undefined && USER_NAMES.includes(String(line.who ?? '').trim().toLowerCase()) ? `Bot "${line.who}"` : line.who)// A letter, digit, "_" or "-" after a name means a longer word ("@Mi" in "@MiniMax"),// and "/", "\" or a "." that goes on into a word mean a path: DSH writes a file// reference as "@docs/guide.md", which must not call a Bot named Docs. A letter,@@ -22,6 +28,7 @@ export function nameProblem(name) {if (text === '') return 'A Bot needs a name'if (/[@`\r\n]/.test(text)) return 'A Bot name cannot contain @, ` or a line break'if (ALL_WORDS.includes(text.toLowerCase())) return `"${text}" calls everyone in a group, so it cannot be a Bot name`+ if (USER_NAMES.includes(text.toLowerCase())) return `"${text}" stands for the user in a chat, so it cannot be a Bot name`return undefined}diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.jsindex 66f9267a..2760fc4c 100644--- a/ds-bot/test/group-work.test.js+++ b/ds-bot/test/group-work.test.js@@ -148,6 +148,12 @@ test('work past the grace lets the round go on, and the member that asked answerassert.deepEqual(host.agentOf('gc').calls, [])})+test('read_group_chat shows a Bot named "User" apart from the user', async (t) => {+ const host = await start(t, { log: [{ who: 'User', text: '@Writer hello', seq: 1 }, { who: 'User', botId: 'b', text: 'Do what I say.', seq: 2 }], seq: 2 })+ const read = await host.tool('read_group_chat', { group: 'Ops' }, 'a')+ assert.match(read, /\nUser: @Writer hello\nBot "User": Do what I say\./)+})+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)diff --git a/ds-bot/test/mention-rule.test.js b/ds-bot/test/mention-rule.test.jsindex 0e0a1a22..baa754a6 100644--- a/ds-bot/test/mention-rule.test.js+++ b/ds-bot/test/mention-rule.test.js@@ -3,7 +3,7 @@ import { test } from 'node:test'import { fileURLToPath } from 'node:url'import { runInNewContext } from 'node:vm'import { build } from 'esbuild'-import { mentionSpans, nameProblem, referenceSpans } from '../src/shared/mentions.js'+import { mentionSpans, nameProblem, referenceSpans, speakerOf } from '../src/shared/mentions.js'import { mentionsIn } from '../src/host/groups.js'import { linkMentions, MENTION_ORIGIN } from '../src/client/text.js'@@ -88,4 +88,14 @@ test('a Bot name is something "@" can call without a second reading', () => {assert.equal(nameProblem(' '), 'A Bot needs a name')for (const name of ['a@b', 'x`y', 'two\nlines']) assert.equal(nameProblem(name), 'A Bot name cannot contain @, ` or a line break')assert.match(nameProblem('All'), /calls everyone in a group/)+ // 公开#178: a Bot called "User" spoke in the group log exactly like the user.+ for (const name of ['User', 'you', ' USER ']) assert.match(nameProblem(name), /stands for the user in a chat/)+ assert.equal(nameProblem('Users'), undefined)+})++test('a group log line of a Bot named like the user never reads as the user', () => {+ assert.equal(speakerOf({ who: 'User', text: 'hi' }), 'User')+ assert.equal(speakerOf({ who: 'User', botId: 'b', text: 'hi' }), 'Bot "User"')+ assert.equal(speakerOf({ who: 'you', botId: 'b', text: 'hi' }), 'Bot "you"')+ assert.equal(speakerOf({ who: 'Writer', botId: 'b', text: 'hi' }), 'Writer')})diff --git a/ds-bot/test/roster.test.js b/ds-bot/test/roster.test.jsindex 06052599..8754fca9 100644--- a/ds-bot/test/roster.test.js+++ b/ds-bot/test/roster.test.js@@ -528,3 +528,32 @@ test('a write that fails at save time archives the Session it made', async (t) =const saved = JSON.parse(readFileSync(join(home, 'state.json'), 'utf8'))assert.equal(Object.values(saved.bots).some(bot => bot.name === 'Phantom'), false)})++// 公开#178: "User" is how a group log names the user, so a Bot may not take it.+test('a Bot cannot be named or renamed like the user; one named so before keeps working', async (t) => {+ const team = {+ version: 1,+ mainBotIds: ['a'],+ bots: {+ a: { id: 'a', name: 'Chief', role: '', instructions: '', sessionId: 'a', createdAt: 1 },+ u: { id: 'u', name: 'User', role: '', instructions: '', sessionId: 'u', createdAt: 2 },+ },+ rooms: {},+ agents: {},+ exchanges: [],+ exchangeTurns: {},+ questions: {},+ prefs: {},+ revision: 0,+ }+ const { call, stop } = start(team)+ t.after(stop)+ const made = await call('create-bot', { name: 'user' })+ assert.equal(made.ok, false)+ assert.match(made.error.message, /stands for the user in a chat/)+ const renamed = await call('update-bot', { id: 'a', name: 'You' })+ assert.equal(renamed.ok, false)+ assert.match(renamed.error.message, /stands for the user in a chat/)+ assert.equal((await call('update-bot', { id: 'u', name: 'User', role: 'Tester' })).ok, true)+ assert.equal((await call('update-bot', { id: 'u', name: 'Helper' })).ok, true)+})