Skip to content

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

Show a Bot that waits for work it handed on in its mark (#262)

Fei2411a704500074b7
diff --git a/docs/plans/2026-10-16-bot-handoffs.md b/docs/plans/2026-10-16-bot-handoffs.md
index 6688c06c..89bd2419 100644
--- a/docs/plans/2026-10-16-bot-handoffs.md
+++ b/docs/plans/2026-10-16-bot-handoffs.md
@@ -43,6 +43,10 @@ Bot 之间派活原来按数量拦,不看对方的状态:
- `list_bots` 每个 Bot 一行,带上状态和这两项。
- `message_bot` 的结果带上对方发出时的状态。
- 状态不写进系统提示:系统提示要逐字节稳定,才能复用缓存。Bot 要看状态就调 `list_bots`。
+- 界面上,Bot 的形象动画表示状态(侧栏、聊天标题、详情面板):
+ - 在干活、等批准、换新会话,和原来一样(按工具分思考、搜索、干活、发消息;等批准跳起来并带「?」)。
+ - 在等别的 Bot:没有回合在跑,但派出去的活还没交回。形象左右摇、眼睛转圈,和协调队友时一样(对齐 Grok Bot:等待和等子任务都用这个动作);不带「工作中」的绿点,因为没有回合在跑。侧栏这一行写「等 X 交回」。
+ - 有回合在跑时显示回合的状态;等批准或问题卡片优先于在等别的 Bot。
### 没读的消息合成一条
@@ -106,3 +110,4 @@ Bot 之间派活原来按数量拦,不看对方的状态:
## 变更
- 2026-10-16:定下(#262)。
+- 2026-10-16:Bot 的形象动画表示「在等别的 Bot」(#262)。
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 56c50e35..95e7569f 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -46,6 +46,7 @@ var ZH = {
"Main Bot": "主 Bot",
Working: "工作中",
"Waiting for your answer": "等你回答",
+ "Waiting for {names}": "等 {names} 交回",
"Unread activity": "有未读",
Search: "搜索",
"New chat": "新对话",
@@ -1896,8 +1897,9 @@ body[data-bt-motion=quiet] .bt-mark[data-gaze] .bt-gaze{transform:none}
.bt-mark[data-state=working]:is([data-shape=gumdrop],[data-shape=peanut],[data-shape=cushion],[data-shape=squircle],[data-shape=moon],[data-shape=wave]) .bt-b{animation:bt-squash 1.2s ease-in-out infinite}
.bt-mark[data-state=working] .bt-eye{animation:bt-blink 2.4s ease-in-out infinite}
.bt-mark[data-state=sending] .bt-b{animation:bt-dash 1.1s cubic-bezier(.4,0,.2,1) infinite}
-.bt-mark[data-state=orbit] .bt-b{animation:bt-sway 2.6s ease-in-out infinite;transform-origin:50% 50%}
-.bt-mark[data-state=orbit] .bt-eyes{animation:bt-roll 2.6s linear infinite}
+/* Waiting for teammates to hand back work circles like coordinating them. */
+.bt-mark:is([data-state=orbit],[data-state=waiting]) .bt-b{animation:bt-sway 2.6s ease-in-out infinite;transform-origin:50% 50%}
+.bt-mark:is([data-state=orbit],[data-state=waiting]) .bt-eyes{animation:bt-roll 2.6s linear infinite}
/* A question for you hops twice when it arrives and the badge keeps it in view after;
a lively mark keeps hopping. */
.bt-mark[data-state=alert] .bt-b{animation:bt-hop 1.3s cubic-bezier(.3,.7,.4,1) 2}
@@ -2892,8 +2894,8 @@ function installCompiledStyles(text, tag) {
// src/client/mark.js
var import_react2 = require("react");
-var STATES = ["idle", "thinking", "searching", "working", "sending", "orbit", "alert", "done"];
-var botState = (running, activity, alert) => running ? STATES.includes(activity) ? activity : "working" : alert ? "alert" : "idle";
+var STATES = ["idle", "thinking", "searching", "working", "sending", "orbit", "waiting", "alert", "done"];
+var botState = (running, activity, alert) => running ? STATES.includes(activity) && activity !== "waiting" ? activity : "working" : alert ? "alert" : activity === "waiting" ? "waiting" : "idle";
var toolState = (name) => /^(message_bot|stop_bot|create_bot|update_bot|create_group|update_group|delete_group|post_to_group)$/.test(name) ? "sending" : /search|fetch|browse|read|grep|glob|list|recall/i.test(name) ? "searching" : "working";
function useGaze(ref, enabled) {
(0, import_react2.useEffect)(() => {
@@ -2994,7 +2996,7 @@ function useSettled(state) {
function BotAvatar({ bot, size, state = "idle", main, admin, badge = true, live = true, gaze = false, pokeable = false }) {
const settled = useSettled(state);
if (bot === void 0) return (0, import_react2.createElement)(BotMark, { size });
- const badgeKind = !badge ? null : state === "alert" ? "alert" : state !== "idle" ? "working" : admin ? "admin" : main ? "main" : null;
+ const badgeKind = !badge ? null : state === "alert" ? "alert" : state !== "idle" && state !== "waiting" ? "working" : admin ? "admin" : main ? "main" : null;
return (0, import_react2.createElement)(
"span",
{ className: "bt-mark", style: { width: size, height: size, "--bt-size": `${size}px` } },
@@ -4908,6 +4910,10 @@ var useGroupWork = (useWork, pick2) => useWork ? useWork((work) => JSON.stringif
var workKeys = (text) => JSON.parse(text);
var doingOf = ({ tool, said, note, target, switching }) => ({ tool, said, note, target, switching });
var workLine = (lead, doing, more) => (0, import_react9.createElement)(Shimmer, null, `${lead} · ${workPhrase(doing)}…${more > 0 ? ` +${more}` : ""}`);
+var waitingFor = (roster, waits) => {
+ const names = [...(waits?.bots ?? []).map((id) => roster.byId[id]?.name), ...(waits?.rooms ?? []).map((id) => roster.roomsById[id]?.name)].filter(Boolean);
+ return names.length === 0 ? "" : t("Waiting for {names}", { names: names.join(t(" and ")) });
+};
function BotRow({ bot, roster, actions, useSessions, useSessionStatus, useSessionRetainInfo, useActivity, useWork, wide, marked }) {
const id = bot.id;
const part = currentPart(bot);
@@ -4925,13 +4931,15 @@ function BotRow({ bot, roster, actions, useSessions, useSessionStatus, useSessio
const away = !running && groups.length > 0;
const state = botState(running || away, doing, alert);
const awayLine = away ? workLine(roster.roomsById[groups[0].id]?.name ?? t("a group chat"), groups[0], groups.length - 1) : null;
+ const waits = workKeys(useWork ? useWork((work) => JSON.stringify(work.waiting?.[id] ?? null)) : "null");
+ const waitsFor = state === "waiting" ? waitingFor(roster, waits) : "";
if (bot.hidden && !active && !main) return null;
const onContextMenu = (event) => {
event.preventDefault();
actions.openMenu({ kind: "bot", id, x: event.clientX, y: event.clientY });
};
const pinned = bot.pinned === true && !tile;
- const label = [bot.name, main ? t("Main Bot") : "", pinned ? t("Pinned") : "", running || away ? t("Working") : "", approval ? t("Waiting for your approval") : alert ? t("Waiting for your answer") : "", unread ? t("Unread activity") : ""].filter(Boolean).join(", ");
+ const label = [bot.name, main ? t("Main Bot") : "", pinned ? t("Pinned") : "", running || away ? t("Working") : "", waitsFor, approval ? t("Waiting for your approval") : alert ? t("Waiting for your answer") : "", unread ? t("Unread activity") : ""].filter(Boolean).join(", ");
if (tile && wide) {
return (0, import_react9.createElement)("div", { className: "bt-tile-wrap" }, (0, import_react9.createElement)(
"button",
@@ -4968,7 +4976,7 @@ function BotRow({ bot, roster, actions, useSessions, useSessionStatus, useSessio
"span",
{ className: "bt-row-body" },
(0, import_react9.createElement)("span", { className: "bt-row-name" }, (0, import_react9.createElement)("span", { className: "bt-row-title" }, bot.name), pinned ? (0, import_react9.createElement)(PinMark) : null),
- awayLine ? (0, import_react9.createElement)("span", { className: "bt-row-preview" }, awayLine) : preview ? (0, import_react9.createElement)("span", { className: "bt-row-preview" }, preview) : null
+ awayLine ? (0, import_react9.createElement)("span", { className: "bt-row-preview" }, awayLine) : waitsFor ? (0, import_react9.createElement)("span", { className: "bt-row-preview" }, waitsFor) : preview ? (0, import_react9.createElement)("span", { className: "bt-row-preview" }, preview) : null
) : null,
wide && unread && !active ? (0, import_react9.createElement)("span", { className: "bt-unread", "aria-hidden": true }) : null
);
diff --git a/ds-bot/dev/mock-llm.mjs b/ds-bot/dev/mock-llm.mjs
index 0b1412dd..ddaf2614 100644
--- a/ds-bot/dev/mock-llm.mjs
+++ b/ds-bot/dev/mock-llm.mjs
@@ -19,6 +19,7 @@
// 建群 名: A, B · 群发[回报] 名: 消息 · 改群 名 公告|管理员|模式|加|踢: 值 · 删群 名
// 看群 名 (read_group_chat) · 转告 名: 消息, also over several lines (message_bot) · 搜索:查询1 | 查询2 (web_search)
// 插话 名: 消息 (message_bot when "now") · 排队 名: 消息 (message_bot when "queue") · 叫停 名: 原因 (stop_bot)
+// In a message from a Bot: 转告 名: 消息 (hands it on with message_bot) · 慢慢做 N (answers after N seconds)
// 长文 N / long N (N×1000 characters) · 长任务 N [K] (N steps of K×1000, default 4)
// 查记录 词 [词…] · 查锚点 part N #序号 · 查第 N 段 (read_own_chat)
// 上下文里有 词 (searches the context except the last message) · 撑爆 (fake overflow, 400)
@@ -431,12 +432,19 @@ function decide(body) {
const asked = userText.split('\n').slice(1).join(' ').trim().replace(/[。.!!??]+$/u, '')
return [text(`${match[1]} 转来一句话:「${asked}」。我先说打算:把手头已有的材料理一遍,列出还缺什么,再和你确认先后顺序;你确认之前我不会动手。`)]
}
+ if ((match = /^\[Message from ([^\]·]+?)(?: · [^\]]*)?\]\n(?:转告\s*(\S+?)\s*[::]\s*([\s\S]+)|慢慢做\s*(\d+))/.exec(userText))) {
+ if (match[2] && tools.has('message_bot')) return [tool('message_bot', { to: match[2], message: match[3].trim() })]
+ if (match[4]) return Object.assign([text(`给 ${match[1]} 的回复:做完了,用了 ${match[4]} 秒。`)], { delay: Number(match[4]) * 1000 })
+ }
if ((match = /^\[Message from ([^\]·]+?)(?: · [^\]]*)?\]/.exec(userText))) {
return [text(`给 ${match[1]} 的回复:\n- 先做:把现有材料理一遍\n- 需要用户提供:目标和截止时间(尚未聊过)\n- 节奏:确认后每天同步一次`)]
}
if ((match = /^\[Reply from ([^\]]+)\]\n.* could not answer your message: its model call failed \(([^)]+)\)/.exec(userText))) {
return [text(`${match[1]} 这次没能回答:它的模型调用出错了(${match[2]})。可能是 API 密钥失效,请检查它用的模型设置。`)]
}
+ if ((match = /^\[Reply from ([^\]·]+?) · for the work ([^\]]+?) asked you for/.exec(userText))) {
+ return [text(`${match[1]} 交回了,我把结果交给 ${match[2]}。`)]
+ }
if ((match = /^\[Reply from ([^\]]+)\]/.exec(userText))) {
return [text(`${match[1]} 回话了:目标和截止时间都还没和你聊过,它没法凭空开工。`), tool('ask_user', { question: '下一步怎么走?', detail: '没有目标之前它只能空转。', options: ['现在告诉我目标', '先去跟它聊', '先搁着'] })]
}
diff --git a/ds-bot/dev/smoke.mjs b/ds-bot/dev/smoke.mjs
index afc2592b..7d25eb7e 100644
--- a/ds-bot/dev/smoke.mjs
+++ b/ds-bot/dev/smoke.mjs
@@ -274,6 +274,20 @@ for (const round of [1, 2, 3, 4]) {
await step('exchange log between Chief and Writer', () => api('exchange', { a: chief().id, b: botNamed('Writer').id }), entries => expect(entries.length >= 2, `got ${entries.length}`))
+// Writer hands Chief's work on to Coder and waits, and the team view shows it; Coder's
+// result goes up to Chief with Writer's answer.
+await step('Writer waits for the work it handed on, then answers with it', async () => {
+ await send(chief().id, '转告 Writer: 转告 Coder: 慢慢做 3')
+ const writer = botNamed('Writer').id
+ for (const deadline = Date.now() + STEP_TIMEOUT_MS; Date.now() < deadline; await sleep(200)) {
+ const { activity = {}, work = {} } = await api('state')
+ if (activity[writer] === 'waiting') return work.waiting?.[writer]
+ }
+ return undefined
+}, (waiting, calls) => expect(waiting?.bots?.includes(botNamed('Coder').id) && waiting.for.includes(chief().id), `Writer did not show that it waits for Coder (${JSON.stringify(waiting)})`)
+ ?? expect(saidText(calls, /^Coder 交回了,我把结果交给 Chief/), 'Writer did not go on when Coder answered')
+ ?? expect(state().exchanges.some(entry => entry.role === 'reply' && entry.from === botNamed('Writer').id && entry.text.includes('[Handed back to Writer for this work]')), 'Chief did not get Coder\'s result with Writer\'s answer'))
+
await step('update Writer', () => api('update-bot', { id: botNamed('Writer').id, role: 'Copywriter', instructions: 'Write the copy.' }), () => {
const writer = botNamed('Writer')
return expect(writer.role === 'Copywriter' && writer.instructions === 'Write the copy.', 'update not saved')
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index 2199afd6..e6ba7e13 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -9,6 +9,7 @@ const ZH = {
'Main Bot': '主 Bot',
Working: '工作中',
'Waiting for your answer': '等你回答',
+ 'Waiting for {names}': '等 {names} 交回',
'Unread activity': '有未读',
Search: '搜索',
'New chat': '新对话',
diff --git a/ds-bot/src/client/mark.js b/ds-bot/src/client/mark.js
index d357ca2f..a0058fee 100644
--- a/ds-bot/src/client/mark.js
+++ b/ds-bot/src/client/mark.js
@@ -8,9 +8,11 @@ export { colorOf, lookOf } from './characters.js'
// Bot mark: the Bot's character (or its uploaded photo), looked up by lookOf.
// Mascot states: what the Bot is doing picks the
-// motion. Uploaded images only bob or hop, since they have no parts to move.
-const STATES = ['idle', 'thinking', 'searching', 'working', 'sending', 'orbit', 'alert', 'done']
-export const botState = (running, activity, alert) => (running ? (STATES.includes(activity) ? activity : 'working') : alert ? 'alert' : 'idle')
+// motion. Uploaded images only bob or hop, since they have no parts to move. `waiting`:
+// no turn runs, but work it handed on has not come back yet.
+const STATES = ['idle', 'thinking', 'searching', 'working', 'sending', 'orbit', 'waiting', 'alert', 'done']
+export const botState = (running, activity, alert) => (running ? (STATES.includes(activity) && activity !== 'waiting' ? activity : 'working')
+ : alert ? 'alert' : activity === 'waiting' ? 'waiting' : 'idle')
export const toolState = name => (/^(message_bot|stop_bot|create_bot|update_bot|create_group|update_group|delete_group|post_to_group)$/.test(name) ? 'sending'
: /search|fetch|browse|read|grep|glob|list|recall/i.test(name) ? 'searching' : 'working')
@@ -107,7 +109,7 @@ function useSettled(state) {
export function BotAvatar({ bot, size, state = 'idle', main, admin, badge = true, live = true, gaze = false, pokeable = false }) {
const settled = useSettled(state)
if (bot === undefined) return h(BotMark, { size })
- const badgeKind = !badge ? null : state === 'alert' ? 'alert' : state !== 'idle' ? 'working' : admin ? 'admin' : main ? 'main' : null
+ const badgeKind = !badge ? null : state === 'alert' ? 'alert' : state !== 'idle' && state !== 'waiting' ? 'working' : admin ? 'admin' : main ? 'main' : null
return h('span', { className: 'bt-mark', style: { width: size, height: size, '--bt-size': `${size}px` } },
h(BotMark, { bot, size, state: settled ? 'done' : state, live, gaze, pokeable }),
badgeKind === 'working' ? h('span', { className: 'bt-badge bt-badge-working', 'aria-label': t('Working'), role: 'img' }) : null,
diff --git a/ds-bot/src/client/sidebar.js b/ds-bot/src/client/sidebar.js
index 1d673001..e41a46ae 100644
--- a/ds-bot/src/client/sidebar.js
+++ b/ds-bot/src/client/sidebar.js
@@ -35,6 +35,11 @@ const useGroupWork = (useWork, pick) => (useWork ? useWork(work => JSON.stringif
const workKeys = text => JSON.parse(text)
const doingOf = ({ tool, said, note, target, switching }) => ({ tool, said, note, target, switching })
const workLine = (lead, doing, more) => h(Shimmer, null, `${lead} · ${workPhrase(doing)}…${more > 0 ? ` +${more}` : ''}`)
+// The Bots and groups a Bot waits for (handoffs.js), by the names they have now.
+const waitingFor = (roster, waits) => {
+ const names = [...(waits?.bots ?? []).map(id => roster.byId[id]?.name), ...(waits?.rooms ?? []).map(id => roster.roomsById[id]?.name)].filter(Boolean)
+ return names.length === 0 ? '' : t('Waiting for {names}', { names: names.join(t(' and ')) })
+}
function BotRow({ bot, roster, actions, useSessions, useSessionStatus, useSessionRetainInfo, useActivity, useWork, wide, marked }) {
const id = bot.id
@@ -54,13 +59,15 @@ function BotRow({ bot, roster, actions, useSessions, useSessionStatus, useSessio
const away = !running && groups.length > 0
const state = botState(running || away, doing, alert)
const awayLine = away ? workLine(roster.roomsById[groups[0].id]?.name ?? t('a group chat'), groups[0], groups.length - 1) : null
+ const waits = workKeys(useWork ? useWork(work => JSON.stringify(work.waiting?.[id] ?? null)) : 'null')
+ const waitsFor = state === 'waiting' ? waitingFor(roster, waits) : ''
if (bot.hidden && !active && !main) return null
const onContextMenu = (event) => {
event.preventDefault()
actions.openMenu({ kind: 'bot', id, x: event.clientX, y: event.clientY })
}
const pinned = bot.pinned === true && !tile
- const label = [bot.name, main ? t('Main Bot') : '', pinned ? t('Pinned') : '', running || away ? t('Working') : '', approval ? t('Waiting for your approval') : alert ? t('Waiting for your answer') : '', unread ? t('Unread activity') : ''].filter(Boolean).join(', ')
+ const label = [bot.name, main ? t('Main Bot') : '', pinned ? t('Pinned') : '', running || away ? t('Working') : '', waitsFor, approval ? t('Waiting for your approval') : alert ? t('Waiting for your answer') : '', unread ? t('Unread activity') : ''].filter(Boolean).join(', ')
if (tile && wide) {
return h('div', { className: 'bt-tile-wrap' }, h('button', {
type: 'button', className: 'bt-tile', 'aria-label': label, 'aria-current': active ? 'page' : undefined,
@@ -78,7 +85,9 @@ function BotRow({ bot, roster, actions, useSessions, useSessionStatus, useSessio
pinned && !wide ? h(PinMark) : null,
wide ? h('span', { className: 'bt-row-body' },
h('span', { className: 'bt-row-name' }, h('span', { className: 'bt-row-title' }, bot.name), pinned ? h(PinMark) : null),
- awayLine ? h('span', { className: 'bt-row-preview' }, awayLine) : preview ? h('span', { className: 'bt-row-preview' }, preview) : null) : null,
+ awayLine ? h('span', { className: 'bt-row-preview' }, awayLine)
+ : waitsFor ? h('span', { className: 'bt-row-preview' }, waitsFor)
+ : preview ? h('span', { className: 'bt-row-preview' }, preview) : null) : null,
wide && unread && !active ? h('span', { className: 'bt-unread', 'aria-hidden': true }) : null)
}
diff --git a/ds-bot/src/client/styles.js b/ds-bot/src/client/styles.js
index 2ab4915d..238360a2 100644
--- a/ds-bot/src/client/styles.js
+++ b/ds-bot/src/client/styles.js
@@ -68,8 +68,9 @@ body[data-bt-motion=quiet] .bt-mark[data-gaze] .bt-gaze{transform:none}
.bt-mark[data-state=working]:is([data-shape=gumdrop],[data-shape=peanut],[data-shape=cushion],[data-shape=squircle],[data-shape=moon],[data-shape=wave]) .bt-b{animation:bt-squash 1.2s ease-in-out infinite}
.bt-mark[data-state=working] .bt-eye{animation:bt-blink 2.4s ease-in-out infinite}
.bt-mark[data-state=sending] .bt-b{animation:bt-dash 1.1s cubic-bezier(.4,0,.2,1) infinite}
-.bt-mark[data-state=orbit] .bt-b{animation:bt-sway 2.6s ease-in-out infinite;transform-origin:50% 50%}
-.bt-mark[data-state=orbit] .bt-eyes{animation:bt-roll 2.6s linear infinite}
+/* Waiting for teammates to hand back work circles like coordinating them. */
+.bt-mark:is([data-state=orbit],[data-state=waiting]) .bt-b{animation:bt-sway 2.6s ease-in-out infinite;transform-origin:50% 50%}
+.bt-mark:is([data-state=orbit],[data-state=waiting]) .bt-eyes{animation:bt-roll 2.6s linear infinite}
/* A question for you hops twice when it arrives and the badge keeps it in view after;
a lively mark keeps hopping. */
.bt-mark[data-state=alert] .bt-b{animation:bt-hop 1.3s cubic-bezier(.3,.7,.4,1) 2}
diff --git a/ds-bot/src/host/channel.js b/ds-bot/src/host/channel.js
index 2e738c13..9df58a62 100644
--- a/ds-bot/src/host/channel.js
+++ b/ds-bot/src/host/channel.js
@@ -69,10 +69,10 @@ export function install(rt) {
// What changes without a new revision, sent with every state answer. `memoryNews`:
// per Bot, its latest memory change; `memoryReviews`: memory reviews waiting or
// running; `work`: per Bot, the turn it runs and its tool; per group, the members whose
- // turn there runs; and the approvals waiting.
+ // turn there runs; the approvals waiting; and per Bot, who it waits for to hand back work.
const live = () => ({
activity: rt.activityView(),
- work: { bots: rt.workView(), rooms: rt.roomWorkView(), approvals: rt.approvalsView() },
+ work: { bots: rt.workView(), rooms: rt.roomWorkView(), approvals: rt.approvalsView(), waiting: rt.waitingView?.() ?? {} },
memoryNews: rt.memoryNews(),
memoryReviews: rt.memoryReviews(),
connectors: rt.connectorsView(),
diff --git a/ds-bot/src/host/handoffs.js b/ds-bot/src/host/handoffs.js
index 73585fb8..9f0f970d 100644
--- a/ds-bot/src/host/handoffs.js
+++ b/ds-bot/src/host/handoffs.js
@@ -109,6 +109,26 @@ export function install(rt) {
// Two requests from one sender belong to the same work when they were sent for it.
const sameWork = (id, parent) => (works()[id]?.parent ?? undefined) === (works()[parent] === undefined ? undefined : parent)
+ // The works their Bots wait on, outside a turn that does them (`busy`): each with what
+ // it handed on that has not come back yet. One that came back waits only to be read.
+ const held = busy => Object.entries(works())
+ .filter(([id, work]) => work.to !== undefined && work.open.length > 0 && !busy.has(id))
+ .map(([id, work]) => ({ id, work, out: work.open.map(childId => works()[childId]).filter(Boolean) }))
+ const busyWith = sessionIds => new Set(sessionIds.map(sessionId => rt.live.get(sessionId)).filter(entry => entry?.turn !== undefined).map(entry => workOf(entry.info)).filter(Boolean))
+
+ // Per Bot, the Bots and groups it waits for, and the Bots it does that work for.
+ function waitingView() {
+ const view = {}
+ const add = (list, id) => { if (id !== undefined && !list.includes(id)) list.push(id) }
+ for (const { work, out } of held(busyWith([...rt.live.keys()]))) {
+ if (out.length === 0) continue
+ const entry = view[work.to] ??= { bots: [], rooms: [], for: [] }
+ for (const child of out) add(child.room ? entry.rooms : entry.bots, child.room ?? child.to)
+ add(entry.for, work.from)
+ }
+ return view
+ }
+
// A deleted Bot answers no more work and waits for none.
function forgetBot(botId) {
const waiting = Object.entries(works()).filter(([, work]) => work.to === botId).map(([id]) => askedBy(id))
@@ -145,16 +165,10 @@ export function install(rt) {
const entry = rt.live.get(sessionId)
lines.push(`working ${place(sessionId)} ${minutes(entry.since ?? Date.now())}${forWhom(sessionId, entry.info)}${doing(entry)}`)
}
- const busyWith = new Set(running.map(sessionId => workOf(rt.live.get(sessionId)?.info)).filter(Boolean))
- for (const [id, work] of Object.entries(works())) {
- if (work.to !== botId || work.open.length === 0 || busyWith.has(id)) continue
+ for (const { work, out } of held(busyWith(running))) {
+ if (work.to !== botId) continue
const forName = nameOf(work.from) ? `, for ${nameOf(work.from)}` : ''
- // A child that answered already waits only to be read.
- const on = [...new Set(work.open.flatMap((childId) => {
- const child = works()[childId]
- if (child === undefined) return []
- return [child.room ? `group "${rt.roomOf(child.room)?.name ?? 'a group'}"` : nameOf(child.to) ?? 'a teammate']
- }))]
+ const on = [...new Set(out.map(child => (child.room ? `group "${rt.roomOf(child.room)?.name ?? 'a group'}"` : nameOf(child.to) ?? 'a teammate')))]
lines.push(on.length > 0 ? `waiting for ${on.join(' and ')} to hand back work${forName}` : `about to go on with work${forName}, whose results came back`)
}
if (lines.length === 0) lines.push('idle')
@@ -168,5 +182,5 @@ export function install(rt) {
return lines.join('; ')
}
- Object.assign(rt, { workOf, openWork, closeWork, dropWork, takenWork: taken, ownsWork: owns, waitsWork: waits, holdWork: hold, workAsker: askedBy, answerText, upstreamOf, sameWork, forgetBotWork: forgetBot, statusOf })
+ Object.assign(rt, { workOf, openWork, closeWork, dropWork, takenWork: taken, ownsWork: owns, waitsWork: waits, holdWork: hold, workAsker: askedBy, answerText, upstreamOf, sameWork, forgetBotWork: forgetBot, statusOf, waitingView })
}
diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.js
index c19e32b3..0576e8e7 100644
--- a/ds-bot/src/host/turns.js
+++ b/ds-bot/src/host/turns.js
@@ -256,6 +256,8 @@ export function install(rt) {
else merged[job.botId] ??= 'thinking'
}
for (const approval of rt.approvalsView?.() ?? []) merged[approval.botId] = 'alert'
+ // Waiting for work it handed on shows only while no turn of the Bot runs.
+ for (const botId of Object.keys(rt.waitingView?.() ?? {})) merged[botId] ??= 'waiting'
return merged
}
diff --git a/ds-bot/test/bot-mark.test.js b/ds-bot/test/bot-mark.test.js
new file mode 100644
index 00000000..72d9b573
--- /dev/null
+++ b/ds-bot/test/bot-mark.test.js
@@ -0,0 +1,36 @@
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+import { runInNewContext } from 'node:vm'
+import { dirname } from 'node:path'
+import { fileURLToPath } from 'node:url'
+import { build } from 'esbuild'
+
+const bundle = await build({
+ stdin: { contents: "export { botState, BotAvatar } from './src/client/mark.js'\nexport { SHELL_CSS } from './src/client/styles.js'", resolveDir: dirname(dirname(fileURLToPath(import.meta.url))) },
+ bundle: true, format: 'cjs', platform: 'node', write: false, logLevel: 'silent',
+ external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],
+})
+const module = { exports: {} }
+const react = {
+ createElement: (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat(Infinity) }),
+ useState: initial => [initial, () => {}], useEffect: () => {}, useRef: current => ({ current }), useLayoutEffect: () => {}, Fragment: 'fragment',
+}
+runInNewContext(bundle.outputFiles[0].text, { module, exports: module.exports, require: name => (name === 'react' ? react : {}) })
+const { botState, BotAvatar, SHELL_CSS } = module.exports
+
+test('a Bot that waits for work it handed on has a mark of its own, behind a running turn and a question', () => {
+ assert.equal(botState(false, 'waiting', false), 'waiting')
+ // A turn of its own runs: the turn shows, not the wait.
+ assert.equal(botState(true, 'waiting', false), 'working')
+ assert.equal(botState(true, 'searching', false), 'searching')
+ assert.equal(botState(false, 'waiting', true), 'alert')
+ assert.equal(botState(false, undefined, false), 'idle')
+ // It moves like a Bot coordinating its teammates.
+ assert.match(SHELL_CSS, /\.bt-mark:is\(\[data-state=orbit\],\[data-state=waiting\]\) \.bt-b\{animation:bt-sway/)
+})
+
+test('a waiting Bot does not wear the working badge, since no turn of it runs', () => {
+ const badges = state => BotAvatar({ bot: { id: 'b', name: 'Writer' }, size: 36, state }).children.slice(1).filter(Boolean).map(child => child.props.className)
+ assert.deepEqual(badges('waiting'), [])
+ assert.deepEqual(badges('working'), ['bt-badge bt-badge-working'])
+})
diff --git a/ds-bot/test/bot-messages.test.js b/ds-bot/test/bot-messages.test.js
index cfb21203..e8036c34 100644
--- a/ds-bot/test/bot-messages.test.js
+++ b/ds-bot/test/bot-messages.test.js
@@ -513,24 +513,30 @@ async function handedOn({ agents, emit, tool }) {
test('a Bot\'s answer waits for the work it handed on, and carries what came back', async (t) => {
const team = await start(threeBots())
t.after(team.stop)
- const { agents, tool } = team
+ const { agents, tool, call } = team
+ const shown = async () => { const { value } = await call('state', {}); return [value.activity.b === 'waiting', value.work.waiting] }
const { take, end, handed } = await handedOn(team)
+ assert.deepEqual(await shown(), [false, {}])
assert.match(handed, /When you have handed on everything, end your turn: each reply brings you back to this work, and your answer goes to Chief once all of it is back\.$/)
end('b', 'handed it to Tester')
// Nothing goes up yet; Writer waits, and the team can see it.
assert.match(await tool('list_bots', {}, 'a'), /- Writer \(Write\)\n {2}now: waiting for Tester to hand back work, for Chief\n/)
assert.deepEqual(Object.values(await worksIn(team)).map(work => [work.from, work.to, work.open.length, work.held]), [['a', 'b', 1, 'handed it to Tester'], ['b', 'c', 0, undefined]])
assert.deepEqual(callsOf(agents, 'a'), [])
+ // Its mark shows it waits, and its row whom for.
+ assert.deepEqual(await shown(), [true, { b: { bots: ['c'], rooms: [], for: ['a'] } }])
take('c')
end('c', 'two things to fix')
await settled(() => callsOf(agents, 'b').length === 2)
const back = take('b')
+ assert.deepEqual(await shown(), [false, {}])
assert.equal(textOf(back.content), '[Reply from Tester · for the work Chief asked you for; your answer goes to Chief once everything you handed on is back]\ntwo things to fix')
end('b', 'fixed both')
await settled(() => callsOf(agents, 'a').length === 1)
assert.equal(textOf(callsOf(agents, 'a')[0][1].content), '[Reply from Writer]\nfixed both\n\n[Handed back to Writer for this work]\n\nTester:\ntwo things to fix')
assert.match(await tool('list_bots', {}, 'a'), /- Writer \(Write\)\n {2}now: idle\n/)
+ assert.deepEqual(await shown(), [false, {}])
assert.deepEqual(await worksIn(team), {})
})
diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.js
index f89d0091..c0db1307 100644
--- a/ds-bot/test/group-work.test.js
+++ b/ds-bot/test/group-work.test.js
@@ -273,6 +273,8 @@ test('replies a post waits for are work handed on: the answer to the Bot that as
const posted = await host.tool('post_to_group', { group: 'Ops', message: '@Writer 看一下文档', report_back: true }, 'a')
assert.match(posted, /your answer goes to Tester once all of it is back\.$/)
host.finish('a', '已经让 Writer 去看了。')
+ const waiting = (await host.call('state', {})).value
+ assert.deepEqual([waiting.activity.a, waiting.work.waiting], ['waiting', { a: { bots: [], rooms: ['r1'], for: ['c'] } }])
const done = host.round('c1', host.takePost())
await settle(() => host.agentOf('gb').calls.length === 1)
host.begin('gb')
diff --git a/ds-bot/test/mock-llm.test.js b/ds-bot/test/mock-llm.test.js
index fc516f75..7bc51e00 100644
--- a/ds-bot/test/mock-llm.test.js
+++ b/ds-bot/test/mock-llm.test.js
@@ -9,11 +9,11 @@ import { fileURLToPath } from 'node:url'
const MOCK = fileURLToPath(new URL('../dev/mock-llm.mjs', import.meta.url))
// One Anthropic-shaped request, its SSE reply folded into { text, tools }.
-async function call(url, messages) {
+async function call(url, messages, names = ['list_bots']) {
const res = await fetch(url, {
method: 'POST',
headers: { 'content-type': 'application/json' },
- body: JSON.stringify({ model: 'mock', stream: true, tools: [{ name: 'list_bots' }], messages }),
+ body: JSON.stringify({ model: 'mock', stream: true, tools: names.map(name => ({ name })), messages }),
})
assert.equal(res.status, 200)
const events = (await res.text()).split('\n\n')
@@ -35,22 +35,26 @@ function fold(messages, out) {
)
}
-// "长任务 N [K]" adds about K×1000 characters per step, defaulting to 4. A missing K once
-// parsed as NaN, so every step after the opener silently sent no text block.
-test('长任务 writes text on every step when the step size is left out', async (t) => {
+async function startMock(t) {
const home = mkdtempSync(join(tmpdir(), 'dsb-mock-'))
const mock = spawn(process.execPath, [MOCK], {
env: { ...process.env, MOCK_PORT: '0', MOCK_LOG: join(home, 'mock.jsonl'), MOCK_DELAY_MS: '5', MOCK_JITTER_MS: '0' },
})
t.after(() => { mock.kill(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })
// MOCK_PORT=0 lets the kernel pick a free port; the mock prints the real one.
- const url = await new Promise((resolve, reject) => {
+ return new Promise((resolve, reject) => {
mock.stdout.on('data', chunk => {
const found = /127\.0\.0\.1:(\d+)\/v1/.exec(String(chunk))
if (found !== null) resolve(`http://127.0.0.1:${found[1]}/v1/messages`)
})
mock.once('exit', code => reject(new Error(`mock-llm exited ${code}`)))
})
+}
+
+// "长任务 N [K]" adds about K×1000 characters per step, defaulting to 4. A missing K once
+// parsed as NaN, so every step after the opener silently sent no text block.
+test('长任务 writes text on every step when the step size is left out', async (t) => {
+ const url = await startMock(t)
const messages = [{ role: 'user', content: '长任务 3' }]
let out = await call(url, messages)
@@ -73,3 +77,18 @@ test('长任务 writes text on every step when the step size is left out', async
out = await call(url, messages)
assert.match(out.text, /长任务做完了,一共 3 步。/)
})
+
+// A Bot hands work on when a Bot message says 转告, and answers 慢慢做 N after N seconds,
+// so the bench can watch a Bot wait for work it handed on.
+test('a Bot message hands work on with 转告 and takes its time with 慢慢做', async (t) => {
+ const url = await startMock(t)
+ const tools = ['list_bots', 'message_bot']
+ const handed = await call(url, [{ role: 'user', content: '[Message from Chief]\n转告 Coder: 慢慢做 1' }], tools)
+ assert.deepEqual(handed.tools.map(used => used.name), ['message_bot'])
+ const started = Date.now()
+ const slow = await call(url, [{ role: 'user', content: '[Message from Writer]\n慢慢做 1' }], tools)
+ assert.ok(Date.now() - started >= 1000)
+ assert.equal(slow.text, '给 Writer 的回复:做完了,用了 1 秒。')
+ const back = await call(url, [{ role: 'user', content: '[Reply from Coder · for the work Chief asked you for; your answer goes to Chief once everything you handed on is back]\n做完了' }], tools)
+ assert.deepEqual([back.text, back.tools], ['Coder 交回了,我把结果交给 Chief。', []])
+})