Skip to content

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

Keep bracketed Bot names out of relayed message bodies

Chimneyb0f56c83985e
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 70a0f3d1..802fb59a 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -1756,7 +1756,7 @@ function elapsedLabel(ms) {
return `${hours > 0 ? `${hours}h ` : ""}${total >= 60 ? `${Math.floor(total / 60) % 60}m ` : ""}${total % 60}s`;
}
var contentText = (content) => (content ?? []).filter((block) => block?.type === "text").map((block) => block.text).join("\n");
-var HEADER = /^\[(Message from|Reply from|Group chat|Group post from|Bot team setup|Handoff · part|Secret card)[^\]]*\]\n?/;
+var HEADER = /^\[(Message from|Reply from|Group chat|Group post from|Bot team setup|Handoff · part|Secret card)(?:[^\r\n]*\]\r?\n|[^\]\r\n]*\])/;
var currentPart = (bot) => bot.sessionId ?? bot.id;
function reminderPrompts(text) {
const one = /^reminder_prompt_json: (.*)$/m.exec(text);
diff --git a/ds-bot/src/client/text.js b/ds-bot/src/client/text.js
index b4bc637a..3c725183 100644
--- a/ds-bot/src/client/text.js
+++ b/ds-bot/src/client/text.js
@@ -53,7 +53,9 @@ export function elapsedLabel(ms) {
}
export const contentText = content => (content ?? []).filter(block => block?.type === 'text').map(block => block.text).join('\n')
-export const HEADER = /^\[(Message from|Reply from|Group chat|Group post from|Bot team setup|Handoff · part|Secret card)[^\]]*\]\n?/
+// A name can contain brackets. Generated headers end at the newline; without a
+// newline, a legacy inline header still stops at its first closing bracket.
+export const HEADER = /^\[(Message from|Reply from|Group chat|Group post from|Bot team setup|Handoff · part|Secret card)(?:[^\r\n]*\]\r?\n|[^\]\r\n]*\])/
export const currentPart = bot => bot.sessionId ?? bot.id
// The prompts in a due scheduled task's message. DSH frames it for the model: one
// task as `reminder_prompt_json: "…"`, several as `reminders_json: [{reminder_prompt}]`.
diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.js
index 179c9cf3..f6a5c33b 100644
--- a/ds-bot/src/host/turns.js
+++ b/ds-bot/src/host/turns.js
@@ -430,7 +430,7 @@ export function install(rt) {
// A long post comes as a file (attachLong), which stays with its line.
const files = (Array.isArray(event.data.content) ? event.data.content : []).filter(block => block?.type === 'file' && block.attachment !== undefined).map(block => block.attachment)
queueRoomMessage(id, {
- text: textOf(event.data.content).replace(/^\[Group post from [^\]]*\]\n?/, ''),
+ text: textOf(event.data.content).replace(/^\[Group post from (?:[^\r\n]*\]\r?\n|[^\]\r\n]*\])/, ''),
...(files.length > 0 ? { files } : {}),
botId: source.senderSessionId,
name: source.senderName,
@@ -458,7 +458,7 @@ export function install(rt) {
else if (source.work !== undefined && source.work !== rt.workOf?.(entry.info) && !expectsReply(source)) {
// A result for other work than this turn's informs it, and comes back in a
// turn of its own once this one ends, which goes on with that work.
- entry.later = [...(entry.later ?? []), { info: source, text: textOf(event.data.content).replace(/^\[[^\]\n]*\]\n?/, '') }]
+ entry.later = [...(entry.later ?? []), { info: source, text: textOf(event.data.content).replace(/^\[(?:[^\r\n]*\]\r?\n|[^\]\r\n]*\])/, '') }]
} else if (expectsReply(source) && !answersUser(source)
&& source.exchangeId !== entry.info?.exchangeId
&& !(entry.joined ?? []).some(joined => joined.info.exchangeId === source.exchangeId)) {
@@ -466,7 +466,7 @@ export function install(rt) {
// answered in a hidden turn of its own once the work is done, so the
// sender never gets the turn's text. A failed-switch resume message
// re-sends the trigger's own source; the same exchangeId must not join twice.
- const text = textOf(event.data.content).replace(/^\[[^\]\n]*\]\n?/, '')
+ const text = textOf(event.data.content).replace(/^\[(?:[^\r\n]*\]\r?\n|[^\]\r\n]*\])/, '')
entry.joined = [...(entry.joined ?? []), { info: source, text }]
}
// A mid-turn relay that owes no reply only informs the turn: it neither
diff --git a/ds-bot/test/bot-messages.test.js b/ds-bot/test/bot-messages.test.js
index 154a3981..a302d0c3 100644
--- a/ds-bot/test/bot-messages.test.js
+++ b/ds-bot/test/bot-messages.test.js
@@ -197,6 +197,27 @@ test('a request steered into a running turn is recorded once and answered in a t
assert.deepEqual((await exchanges()).map(entry => entry.role), ['request', 'reply'])
})
+test('a request from a name with brackets keeps its body when replayed after the current work', async (t) => {
+ const seed = team()
+ seed.bots.a.name = 'R]2'
+ const { agents, emit, tool, stop } = await start(seed)
+ t.after(stop)
+ const body = 'Check [notes](https://example.test)\n[Keep this line]'
+ emit('b', 'turn/start', { turn: 1 })
+ emit('b', 'user/message', { content: textBlock('write the letter'), source: { kind: 'user' } })
+ await tool('message_bot', { to: 'Writer', message: body }, 'a')
+ const steered = agents.get('b').calls[0][1]
+ assert.equal(steered.source.senderName, 'R]2')
+ emit('b', 'user/message', { content: steered.content, source: steered.source })
+ emit('b', 'assistant/message', assistantText('the letter'))
+ emit('b', 'turn/end', { turn: 1, reason: { kind: 'completed' } })
+ await settled(() => agents.get('b').calls.length === 2)
+ const [kind, again] = agents.get('b').calls[1]
+ assert.equal(kind, 'followup')
+ assert.equal(again.source.exchangeId, steered.source.exchangeId)
+ assert.equal(textOf(again.content), `[Message from R]2 · you read it during your last task; answer it now]\n${body}`)
+})
+
test('a message its recipient has not read yet takes in the next one, however many come', async (t) => {
const { ctx, agentOf, emit, tool, exchanges, stop } = await start(team())
t.after(stop)
@@ -587,7 +608,9 @@ test('a stopped turn answers at once, and what it handed on comes back to it alo
})
test('a result read during other work comes back in a turn of its own and goes on with its work', async (t) => {
- const team = await start(threeBots())
+ const seed = threeBots()
+ seed.bots.a.name = 'Chief [ops]'
+ const team = await start(seed)
t.after(team.stop)
const { agents, emit } = team
const { take, end, userTurn } = await handedOn(team)
@@ -603,7 +626,7 @@ test('a result read during other work comes back in a turn of its own and goes o
await settled(() => callsOf(agents, 'b').length === 3)
const [kind, again] = callsOf(agents, 'b')[2]
assert.equal(kind, 'followup')
- assert.equal(textOf(again.content), '[Reply from Tester · you read it during your last task; go on with the work it is for now · for the work Chief asked you for; your answer goes to Chief once everything you handed on is back]\nreviewed')
+ assert.equal(textOf(again.content), '[Reply from Tester · you read it during your last task; go on with the work it is for now · for the work Chief [ops] asked you for; your answer goes to Chief [ops] once everything you handed on is back]\nreviewed')
assert.deepEqual(callsOf(agents, 'a'), [])
take('b')
end('b', 'done after the review')
diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.js
index ab539700..e6d19526 100644
--- a/ds-bot/test/group-work.test.js
+++ b/ds-bot/test/group-work.test.js
@@ -573,6 +573,24 @@ test('a member post calls only the members it names', async (t) => {
assert.deepEqual(host.agentOf('gb').calls.filter(call => call.source?.role !== 'post'), [])
})
+test('a post from a Bot with brackets in its name reaches the group and its member unchanged', async (t) => {
+ const host = await start(t)
+ assert.equal((await host.call('update-bot', { id: 'b', name: 'A[B]C' })).ok, true)
+ const body = '@Tester Check [notes](https://example.test)\n[Keep this line]'
+ await host.tool('post_to_group', { group: 'Ops', message: body }, 'b')
+ const post = host.takePost()
+ assert.equal(post.source.senderName, 'A[B]C')
+ assert.equal(text(post), `[Group post from A[B]C]\n${body}`)
+ const round = host.round('c1', post)
+ await settle(() => host.agentOf('gc').calls.length === 1)
+ assert.ok(text(host.begin('gc')).includes(`A[B]C: ${body}`))
+ host.finish('gc', 'Checked.')
+ await settle(() => round() !== undefined)
+ const [line] = logLines(host).filter(entry => entry.botId === 'b')
+ assert.equal(line.who, 'A[B]C')
+ assert.equal(line.text, body)
+})
+
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')
diff --git a/ds-bot/test/relay-header.test.js b/ds-bot/test/relay-header.test.js
new file mode 100644
index 00000000..21d4d548
--- /dev/null
+++ b/ds-bot/test/relay-header.test.js
@@ -0,0 +1,32 @@
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+import { stripHeader } from '../src/client/text.js'
+
+test('relay headers with brackets in a Bot or group name leave the body intact', () => {
+ const body = 'Hello [team]\n[notes](https://example.test)\n[Keep this line]'
+ for (const name of ['Writer', 'R]2', 'A]B]C', 'A[B]C', '[Ops]', '普通[助理]']) {
+ for (const header of [
+ `[Message from ${name}]`,
+ `[Reply from ${name}]`,
+ `[Group post from ${name}]`,
+ `[Group chat "${name}" · replies to your post]`,
+ `[Reply from Writer · for the work ${name} asked you for; your answer goes to ${name} once everything you handed on is back]`,
+ ]) {
+ assert.equal(stripHeader(`${header}\n${body}`), body, header)
+ assert.equal(stripHeader(`${header}\r\n${body}`), body, header)
+ }
+ }
+})
+
+test('a single-line relay keeps its inline body, including later brackets', () => {
+ for (const header of ['[Message from Writer]', '[Group post from Writer]', '[Bot team setup]']) {
+ assert.equal(stripHeader(`${header} Hello [team]`), ' Hello [team]')
+ assert.equal(stripHeader(header), '')
+ }
+})
+
+test('a header strip never reaches into a later body line or unrelated bracketed text', () => {
+ for (const text of ['[Message from Writer\n[Keep this line]', '[Someone else]\nHello', 'Hello\n[Message from Writer]']) {
+ assert.equal(stripHeader(text), text)
+ }
+})