Skip to content

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

Show group work in the group, the sidebar and the Bot's own chat

Fei2411dcee158bd931
diff --git a/ds-bot/client.js b/ds-bot/client.js
index faf68fbc..7998be19 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -469,6 +469,8 @@ var ZH = {
"{name} is typing…": "{name} 正在输入…",
"{name} didn't answer in time": "{name} 没有及时回应",
"{name} paused for your approval": "{name} 停下来等你批准",
+ "{name} started on it": "{name} 开始做了",
+ "You stopped {name}'s work": "你停下了 {name} 的工作",
"{name} was cut off by a restart and picked its work back up": "{name} 的工作被重启打断,已经接着做",
"{name} was cut off by a restart again and stopped": "{name} 的工作又被重启打断,已停下",
"Picked up its work after a restart": "重启后接着做之前的工作",
@@ -4059,7 +4061,7 @@ function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnClock, us
if (source.role === "resume") return (0, import_react6.createElement)("div", { className: "bt-event" }, t("Picked up its work after a restart"));
if (source.role === "retry") return (0, import_react6.createElement)("div", { className: "bt-event" }, t("Asked to make the tool call it wrote as text"));
if (source.role === "post") {
- if (source.failed !== void 0 || source.resumed === true) return null;
+ if (source.failed !== void 0 || source.resumed === true || source.stopped === true) return null;
const room2 = roster.roomsById[sessionId];
const poster = roster.byId[source.senderSessionId] ?? { id: source.senderSessionId, name: source.senderName ?? t("a Bot"), color: "gray" };
return (0, import_react6.createElement)(GroupMessage, { bot: poster, text: stripHeader(contentText(data.content)), room: room2, roster, actions, msgKey: `${sessionId}:${data.turn}:post`, useUi });
@@ -4181,7 +4183,7 @@ var PHRASES = {
var TOOL_PHRASES = [
[/web_?search|search_?web/i, "Searching online"],
[/fetch|browse|browser|web/i, "Reading a page"],
- [/shell|bash|exec|command|terminal/i, "Running shell commands"],
+ [/shell|bash|pwsh|powershell|exec|command|terminal/i, "Running shell commands"],
[/^(read|view|cat)\b|read_/i, "Opening a file"],
[/grep|glob|list_dir|^ls$|find|search/i, "Looking through files"],
[/write|edit|patch|apply|replace/i, "Writing changes"],
@@ -4315,7 +4317,7 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUi
if (reply.kind === "cut") {
return (0, import_react6.createElement)("div", { key: `${reply.botId}-${index}`, className: "bt-event" }, t("{name} was cut off by a restart again and stopped", { name: bot.name }));
}
- if (reply.kind === "approval") {
+ if (reply.kind === "approval" || reply.kind === "working") {
return (0, import_react6.createElement)(
"div",
{ key: `${reply.botId}-${index}`, className: "bt-event" },
@@ -4323,10 +4325,13 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUi
"button",
{ type: "button", className: "bt-event-whole", onClick: () => actions.showDetails(sessionId) },
(0, import_react6.createElement)(BotMark, { bot, size: 16 }),
- (0, import_react6.createElement)("span", { className: "bt-event-name" }, t("{name} paused for your approval", { name: bot.name }))
+ (0, import_react6.createElement)("span", { className: "bt-event-name" }, t(reply.kind === "working" ? "{name} started on it" : "{name} paused for your approval", { name: bot.name }))
)
);
}
+ if (reply.kind === "stopped") {
+ return (0, import_react6.createElement)("div", { key: `${reply.botId}-${index}`, className: "bt-event" }, t("You stopped {name}'s work", { name: bot.name }));
+ }
return (0, import_react6.createElement)(GroupMessage, { key: `${reply.botId}-${index}`, bot, text: reply.text, room: room2, roster, actions, msgKey: callId ? `${sessionId}:${callId}:${index}` : void 0, useUi });
}),
pending.map((id) => {
@@ -4619,6 +4624,12 @@ function useMarkedUnread(id, active, marked, actions) {
}
var PinMark = () => (0, import_react8.createElement)("span", { className: "bt-pin", "aria-hidden": true }, (0, import_react8.createElement)(PinMarkIcon));
var useApproval = (useWork, match) => useWork ? useWork((work) => (work.approvals ?? []).some(match)) : false;
+var useGroupWork = (useWork, pick2) => useWork ? useWork((work) => pick2(work.rooms ?? {}).join(",")) : "";
+var workKeys = (text) => text === "" ? [] : text.split(",").map((key) => {
+ const [id, tool] = key.split("|");
+ return { id, tool: tool || void 0 };
+});
+var workLine = (lead, tool, more) => (0, import_react8.createElement)(Shimmer, null, `${lead} · ${workPhrase(tool)}…${more > 0 ? ` +${more}` : ""}`);
function BotRow({ bot, roster, actions, useSessions, useSessionStatus, useSessionRetainInfo, useActivity, useWork, wide, marked }) {
const id = bot.id;
const part = currentPart(bot);
@@ -4632,14 +4643,17 @@ function BotRow({ bot, roster, actions, useSessions, useSessionStatus, useSessio
const approval = useApproval(useWork, (entry) => entry.botId === id);
const alert = roster.questions?.[part] !== void 0 || approval;
const doing = useActivity((map) => map[id]);
- const state = botState(running, doing, alert);
+ const groups = workKeys(useGroupWork(useWork, (rooms) => Object.entries(rooms).flatMap(([roomId, entries2]) => entries2.filter((entry) => entry.botId === id).map((entry) => `${roomId}|${entry.tool ?? ""}`))));
+ 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].tool, groups.length - 1) : null;
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 ? 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") : "", 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_react8.createElement)("div", { className: "bt-tile-wrap" }, (0, import_react8.createElement)(
"button",
@@ -4676,7 +4690,7 @@ function BotRow({ bot, roster, actions, useSessions, useSessionStatus, useSessio
"span",
{ className: "bt-row-body" },
(0, import_react8.createElement)("span", { className: "bt-row-name" }, (0, import_react8.createElement)("span", { className: "bt-row-title" }, bot.name), pinned ? (0, import_react8.createElement)(PinMark) : null),
- preview ? (0, import_react8.createElement)("span", { className: "bt-row-preview" }, preview) : null
+ awayLine ? (0, import_react8.createElement)("span", { className: "bt-row-preview" }, awayLine) : preview ? (0, import_react8.createElement)("span", { className: "bt-row-preview" }, preview) : null
) : null,
wide && unread && !active ? (0, import_react8.createElement)("span", { className: "bt-unread", "aria-hidden": true }) : null
);
@@ -4689,9 +4703,12 @@ function RoomRow({ room: room2, roster, actions, useSessions, useSessionStatus,
const unread = useSessionStatus((map) => map.get(id)?.completionUnread === true) || marked && !active;
useMarkedUnread(id, active, marked, actions);
const approval = useApproval(useWork, (entry) => entry.roomId === id);
+ const members = workKeys(useGroupWork(useWork, (rooms) => (rooms[id] ?? []).map((entry) => `${entry.botId}|${entry.tool ?? ""}`)));
+ const first = roster.byId[members[0]?.id];
+ const workingLine = first ? workLine(first.name, members[0].tool, members.length - 1) : null;
if (room2.hidden && !active) return null;
const pinned = room2.pinned === true;
- const label = [room2.name, pinned ? t("Pinned") : "", approval ? t("Waiting for your approval") : ""].filter(Boolean).join(", ");
+ const label = [room2.name, pinned ? t("Pinned") : "", members.length > 0 ? t("Working") : "", approval ? t("Waiting for your approval") : ""].filter(Boolean).join(", ");
return (0, import_react8.createElement)(
"button",
{
@@ -4712,7 +4729,7 @@ function RoomRow({ room: room2, roster, actions, useSessions, useSessionStatus,
"span",
{ className: "bt-row-body" },
(0, import_react8.createElement)("span", { className: "bt-row-name" }, (0, import_react8.createElement)("span", { className: "bt-row-title" }, room2.name), pinned ? (0, import_react8.createElement)(PinMark) : null),
- preview ? (0, import_react8.createElement)("span", { className: "bt-row-preview" }, preview) : null
+ workingLine ? (0, import_react8.createElement)("span", { className: "bt-row-preview" }, workingLine) : preview ? (0, import_react8.createElement)("span", { className: "bt-row-preview" }, preview) : null
) : null,
wide && approval && !active ? (0, import_react8.createElement)("span", { className: "bt-unread bt-unread-wait", "aria-hidden": true }) : wide && unread && !active ? (0, import_react8.createElement)("span", { className: "bt-unread", "aria-hidden": true }) : null
);
@@ -10506,18 +10523,33 @@ function migrateStorage(storage = globalThis.localStorage) {
// src/client/member-status.js
var import_react28 = require("react");
-var NO_WORK = { bots: {}, approvals: [] };
+var NO_WORK = { bots: {}, rooms: {}, approvals: [] };
+var ROWS_MAX = 4;
function memberWork(room2, work = NO_WORK) {
+ const here = work.rooms?.[room2.id] ?? [];
return room2.members.map((id) => {
const approvals = (work.approvals ?? []).filter((entry) => entry.botId === id);
- const doing = work.bots?.[id];
- return { id, approvals, doing, state: approvals.length > 0 ? "ask" : doing ? "work" : "idle" };
+ const local = here.find((entry) => entry.botId === id);
+ const doing = local ? { ...local, roomId: room2.id } : work.bots?.[id];
+ return { id, approvals, doing, here: local !== void 0, state: approvals.length > 0 ? "ask" : doing ? "work" : "idle" };
});
}
function busyMembers(room2, work, roster) {
const busy = memberWork(room2, work).filter((entry) => entry.state !== "idle" && roster.byId[entry.id]);
return [...busy.filter((entry) => entry.state === "ask"), ...busy.filter((entry) => entry.state === "work")].map((entry) => ({ ...entry, bot: roster.byId[entry.id] }));
}
+function splitBusy(busy) {
+ const speaking = (entry) => entry.state === "work" && entry.here && entry.doing.speaking === true;
+ const rows = busy.filter((entry) => entry.state === "work" && entry.here && !speaking(entry)).slice(0, ROWS_MAX);
+ return { rows, rest: busy.filter((entry) => !rows.includes(entry) && !speaking(entry)) };
+}
+function botGroupWork(botId, work, roster) {
+ return Object.entries(work.rooms ?? {}).flatMap(([roomId, entries2]) => {
+ const entry = entries2.find((item) => item.botId === botId);
+ const room2 = roster.roomsById[roomId];
+ return entry && room2 ? [{ room: room2, tool: entry.tool, since: entry.since }] : [];
+ });
+}
function summaryText(busy) {
const asks = busy.filter((entry) => entry.state === "ask");
const workers = busy.filter((entry) => entry.state === "work");
@@ -10534,20 +10566,25 @@ function Face({ entry, size }) {
(0, import_react28.createElement)(BotMark, { bot: entry.bot, size, state: entry.state === "ask" ? "alert" : toolState(entry.doing?.tool ?? "") })
);
}
-function MemberDock({ sessionId, useRoster, useWork, actions }) {
- const roster = useRoster((value) => value);
- const work = useWork((value) => value);
- const room2 = roster.roomsById[sessionId];
- if (!room2) return null;
- const busy = busyMembers(room2, work, roster);
- if (busy.length === 0) return null;
+function WorkRow({ bot, tool, label, at, now, onOpen }) {
+ const text = `${label} · ${workPhrase(tool)}…`;
+ const elapsed = typeof at === "number" && now - at >= 6e4 ? elapsedLabel(now - at) : "";
+ return (0, import_react28.createElement)(
+ "button",
+ { type: "button", className: "bt-mw-row", "aria-label": [text, elapsed].filter(Boolean).join(" · "), onClick: onOpen },
+ (0, import_react28.createElement)(BotMark, { bot, size: 22, state: toolState(tool ?? ""), live: true }),
+ (0, import_react28.createElement)("span", { className: "bt-mw-row-text" }, (0, import_react28.createElement)(Shimmer, null, text)),
+ elapsed ? (0, import_react28.createElement)("span", { className: "bt-mw-row-time" }, `· ${elapsed}`) : null
+ );
+}
+function SummaryLine({ busy, onOpen }) {
const { waiting, doing } = summaryText(busy);
return (0, import_react28.createElement)(
"div",
{ className: "bt-event bt-mw-dock" },
(0, import_react28.createElement)(
"button",
- { type: "button", className: "bt-event-whole bt-mw-line", "aria-label": [waiting, doing].filter(Boolean).join(" · "), onClick: () => actions.showDetails(sessionId) },
+ { type: "button", className: "bt-event-whole bt-mw-line", "aria-label": [waiting, doing].filter(Boolean).join(" · "), onClick: onOpen },
(0, import_react28.createElement)("span", { className: "bt-mw-stack", "aria-hidden": true }, busy.slice(0, 4).map((entry) => (0, import_react28.createElement)(Face, { key: entry.id, entry, size: 16 }))),
waiting ? (0, import_react28.createElement)("span", { className: "bt-mw-ask" }, waiting) : null,
waiting && doing ? (0, import_react28.createElement)("span", { "aria-hidden": true }, "·") : null,
@@ -10555,6 +10592,37 @@ function MemberDock({ sessionId, useRoster, useWork, actions }) {
)
);
}
+function MemberDock({ sessionId, useRoster, useWork, actions }) {
+ const roster = useRoster((value) => value);
+ const work = useWork((value) => value);
+ const room2 = roster.roomsById[sessionId];
+ const bot = room2 ? void 0 : roster.byId[sessionId];
+ const ownChat = bot !== void 0 && work.bots?.[bot.id] !== void 0 && work.bots[bot.id].roomId === void 0;
+ const busy = room2 ? busyMembers(room2, work, roster) : [];
+ const groups = bot !== void 0 && !ownChat ? botGroupWork(bot.id, work, roster) : [];
+ const now = useNow2(busy.length > 0 || groups.length > 0);
+ if (room2) {
+ if (busy.length === 0) return null;
+ const { rows, rest } = splitBusy(busy);
+ const open = () => actions.showDetails(sessionId);
+ return (0, import_react28.createElement)(
+ "div",
+ { className: "bt-mw-dock-stack" },
+ rows.map((entry) => (0, import_react28.createElement)(WorkRow, { key: entry.id, bot: entry.bot, tool: entry.doing.tool, label: entry.bot.name, at: entry.doing.since, now, onOpen: open })),
+ rest.length > 0 ? (0, import_react28.createElement)(SummaryLine, { busy: rest, onOpen: open }) : null
+ );
+ }
+ if (groups.length === 0) return null;
+ return (0, import_react28.createElement)("div", { className: "bt-mw-dock-stack" }, groups.slice(0, ROWS_MAX).map((item) => (0, import_react28.createElement)(WorkRow, {
+ key: item.room.id,
+ bot,
+ tool: item.tool,
+ label: t("in {name}", { name: item.room.name }),
+ at: item.since,
+ now,
+ onOpen: () => actions.openSession(item.room.id)
+ })));
+}
function useNow2(active) {
const [now, setNow] = (0, import_react28.useState)(Date.now);
(0, import_react28.useEffect)(() => {
@@ -10591,6 +10659,7 @@ function ApprovalCard({ approval, bot, actions }) {
);
}
function MemberWork({ entry, bot, room: room2, roster, actions, now }) {
+ const [stopping, setStopping] = (0, import_react28.useState)(false);
if (entry.state === "ask") {
return (0, import_react28.createElement)(
"div",
@@ -10601,10 +10670,19 @@ function MemberWork({ entry, bot, room: room2, roster, actions, now }) {
}
if (entry.state !== "work") return null;
const where = entry.doing.roomId === room2.id ? "" : entry.doing.roomId ? t("in {name}", { name: roster.roomsById[entry.doing.roomId]?.name ?? t("a group chat") }) : t("in its own chat");
+ const stop = () => {
+ setStopping(true);
+ void Promise.resolve(actions.stopMemberWork(room2.id, bot.id)).catch((error) => actions.reportError(error, "stop")).finally(() => setStopping(false));
+ };
return (0, import_react28.createElement)(
"div",
{ className: "bt-mw-member" },
- (0, import_react28.createElement)("div", { className: "bt-mw-state" }, (0, import_react28.createElement)(Shimmer, null, `${workPhrase(entry.doing.tool)}…`), where ? ` ${where}` : "", since(now, entry.doing.since))
+ (0, import_react28.createElement)(
+ "div",
+ { className: "bt-mw-state bt-mw-work" },
+ (0, import_react28.createElement)("span", null, (0, import_react28.createElement)(Shimmer, null, `${workPhrase(entry.doing.tool)}…`), where ? ` ${where}` : "", since(now, entry.doing.since)),
+ entry.here ? (0, import_react28.createElement)("button", { type: "button", className: "bt-mw-stop", disabled: stopping, onClick: stop }, t("Stop")) : null
+ )
);
}
function useMemberWork(room2, useWork) {
@@ -10614,6 +10692,17 @@ function useMemberWork(room2, useWork) {
return { entries: entries2, now };
}
var MEMBER_CSS = `
+.bt-mw-dock-stack{box-sizing:border-box;display:flex;flex-direction:column;align-items:flex-start;gap:2px;width:var(--dsh-chat-content-width,min(960px,100%));margin:0 auto 6px;pointer-events:none}
+.bt-mw-dock-stack>.bt-event.bt-mw-dock{align-self:stretch;margin:0}
+.bt-mw-row{pointer-events:auto;display:flex;align-items:center;gap:10px;min-width:0;max-width:calc(100% + 6px);height:32px;margin-inline-start:-6px;padding:0 12px 0 6px;border:0;border-radius:16px;background:none;color:var(--bt-ink-2);font:inherit;font-size:14px;cursor:pointer;animation:bt-mw-in .32s cubic-bezier(.23,1,.32,1) backwards;transition:background-color .16s ease-out}
+.bt-mw-row:hover{background:var(--bt-hover)}
+.bt-mw-row>.bt-mark{flex:none}
+.bt-mw-row-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
+.bt-mw-row-time{flex:none;font-size:12px;color:var(--bt-ink-3);white-space:nowrap}
+.bt-mw-work{display:flex;align-items:center;justify-content:space-between;gap:8px}
+.bt-mw-stop{flex:none;height:22px;padding:0 10px;border:1px solid var(--bt-line,rgba(0,0,0,.12));border-radius:11px;background:none;color:var(--bt-ink-2);font:inherit;font-size:12px;cursor:pointer}
+.bt-mw-stop:hover{background:var(--bt-hover)}
+.bt-mw-stop:disabled{opacity:.5;cursor:default}
.bt-event.bt-mw-dock{margin:0 0 6px;pointer-events:none}
.bt-mw-dock>button{pointer-events:auto;animation:bt-mw-in .32s cubic-bezier(.23,1,.32,1) backwards}
.bt-mw-line{gap:6px!important}
@@ -10635,7 +10724,7 @@ body[data-ds-dark-theme] .bt-mw-ask{color:#f0b84a}
.bt-mw-actions>button{height:28px;padding:0 12px;font-size:12px}
.bt-mw-actions>button:disabled{opacity:.5;cursor:default}
@keyframes bt-mw-in{from{opacity:0;transform:translateY(4px)}}
-@media (prefers-reduced-motion:reduce){.bt-mw-dock>button{animation:none}}
+@media (prefers-reduced-motion:reduce){.bt-mw-dock>button,.bt-mw-row{animation:none}}
`;
// src/client/details-drawer.js
@@ -13180,6 +13269,7 @@ function apply(ctx) {
answerQuestion: (sessionId, questionId, answer) => after(call("answer-question", { sessionId: partFor(sessionId), questionId, answer })),
dismissQuestion: (sessionId) => after(call("dismiss-question", { sessionId })),
answerApproval: (id, choice) => after(call("approval-answer", { id, choice })),
+ stopMemberWork: (roomId, botId) => after(call("stop-member-work", { roomId, botId })),
// Values go out in these requests and never come back in a response.
secretSet: (payload) => after(call("secret-set", payload)),
secretAllow: (requestId) => after(call("secret-allow", { requestId })),
diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.js
index 5764be1a..85480f4d 100644
--- a/ds-bot/src/client/cells.js
+++ b/ds-bot/src/client/cells.js
@@ -327,9 +327,9 @@ export function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnCl
if (source.role === 'resume') return h('div', { className: 'bt-event' }, t('Picked up its work after a restart'))
if (source.role === 'retry') return h('div', { className: 'bt-event' }, t('Asked to make the tool call it wrote as text'))
if (source.role === 'post') {
- // A member's late failure, or its work picked up after a restart, shows as an
- // event of the round it opens.
- if (source.failed !== undefined || source.resumed === true) return null
+ // A member's late failure, its work picked up after a restart, or its work the user
+ // stopped shows as an event of the round it opens.
+ if (source.failed !== undefined || source.resumed === true || source.stopped === true) return null
const room = roster.roomsById[sessionId]
const poster = roster.byId[source.senderSessionId] ?? { id: source.senderSessionId, name: source.senderName ?? t('a Bot'), color: 'gray' }
return h(GroupMessage, { bot: poster, text: stripHeader(contentText(data.content)), room, roster, actions, msgKey: `${sessionId}:${data.turn}:post`, useUi })
@@ -466,7 +466,7 @@ export const PHRASES = {
const TOOL_PHRASES = [
[/web_?search|search_?web/i, 'Searching online'],
[/fetch|browse|browser|web/i, 'Reading a page'],
- [/shell|bash|exec|command|terminal/i, 'Running shell commands'],
+ [/shell|bash|pwsh|powershell|exec|command|terminal/i, 'Running shell commands'],
[/^(read|view|cat)\b|read_/i, 'Opening a file'],
[/grep|glob|list_dir|^ls$|find|search/i, 'Looking through files'],
[/write|edit|patch|apply|replace/i, 'Writing changes'],
@@ -573,10 +573,13 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUi
if (reply.kind === 'cut') {
return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' }, t('{name} was cut off by a restart again and stopped', { name: bot.name }))
}
- if (reply.kind === 'approval') {
+ if (reply.kind === 'approval' || reply.kind === 'working') {
return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' },
h('button', { type: 'button', className: 'bt-event-whole', onClick: () => actions.showDetails(sessionId) },
- h(BotMark, { bot, size: 16 }), h('span', { className: 'bt-event-name' }, t('{name} paused for your approval', { name: bot.name }))))
+ h(BotMark, { bot, size: 16 }), h('span', { className: 'bt-event-name' }, t(reply.kind === 'working' ? '{name} started on it' : '{name} paused for your approval', { name: bot.name }))))
+ }
+ if (reply.kind === 'stopped') {
+ return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' }, t("You stopped {name}'s work", { name: bot.name }))
}
return h(GroupMessage, { key: `${reply.botId}-${index}`, bot, text: reply.text, room, roster, actions, msgKey: callId ? `${sessionId}:${callId}:${index}` : undefined, useUi })
}),
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index abc871a0..e0d9baf3 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -413,6 +413,8 @@ const ZH = {
'{name} is typing…': '{name} 正在输入…',
"{name} didn't answer in time": '{name} 没有及时回应',
'{name} paused for your approval': '{name} 停下来等你批准',
+ '{name} started on it': '{name} 开始做了',
+ "You stopped {name}'s work": '你停下了 {name} 的工作',
'{name} was cut off by a restart and picked its work back up': '{name} 的工作被重启打断,已经接着做',
'{name} was cut off by a restart again and stopped': '{name} 的工作又被重启打断,已停下',
'Picked up its work after a restart': '重启后接着做之前的工作',
diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.js
index 015c9426..95b62a83 100644
--- a/ds-bot/src/client/index.js
+++ b/ds-bot/src/client/index.js
@@ -545,6 +545,7 @@ export function apply(ctx) {
answerQuestion: (sessionId, questionId, answer) => after(call('answer-question', { sessionId: partFor(sessionId), questionId, answer })),
dismissQuestion: sessionId => after(call('dismiss-question', { sessionId })),
answerApproval: (id, choice) => after(call('approval-answer', { id, choice })),
+ stopMemberWork: (roomId, botId) => after(call('stop-member-work', { roomId, botId })),
// Values go out in these requests and never come back in a response.
secretSet: payload => after(call('secret-set', payload)),
secretAllow: requestId => after(call('secret-allow', { requestId })),
diff --git a/ds-bot/src/client/member-status.js b/ds-bot/src/client/member-status.js
index 9a88a0f8..b2391aec 100644
--- a/ds-bot/src/client/member-status.js
+++ b/ds-bot/src/client/member-status.js
@@ -5,17 +5,22 @@ import { elapsedLabel } from './activity-row.js'
import { t } from './i18n.js'
// -------------------------------------------------------------------------
-// What a group's members are doing: a line above the composer while any of them is
-// busy, in any of their chats, and the same per member in the details panel, where
-// the approvals their group turns wait on are answered.
+// What a group's members are doing: above the group's composer, a row for each member
+// at work in this group and a line for those busy elsewhere or waiting for an approval;
+// above a Bot's own composer, the groups it is at work in; and per member in the
+// details panel, where the approvals their group turns wait on are answered.
-const NO_WORK = { bots: {}, approvals: [] }
+const NO_WORK = { bots: {}, rooms: {}, approvals: [] }
+const ROWS_MAX = 4
+// Work in this group wins over the Bot's own chat or another group.
export function memberWork(room, work = NO_WORK) {
+ const here = work.rooms?.[room.id] ?? []
return room.members.map((id) => {
const approvals = (work.approvals ?? []).filter(entry => entry.botId === id)
- const doing = work.bots?.[id]
- return { id, approvals, doing, state: approvals.length > 0 ? 'ask' : doing ? 'work' : 'idle' }
+ const local = here.find(entry => entry.botId === id)
+ const doing = local ? { ...local, roomId: room.id } : work.bots?.[id]
+ return { id, approvals, doing, here: local !== undefined, state: approvals.length > 0 ? 'ask' : doing ? 'work' : 'idle' }
})
}
@@ -26,6 +31,23 @@ export function busyMembers(room, work, roster) {
.map(entry => ({ ...entry, bot: roster.byId[entry.id] }))
}
+// Members at work in this group get a row of their own, apart from the round's current
+// speaker, which its round shows; the rest go on the summary line.
+export function splitBusy(busy) {
+ const speaking = entry => entry.state === 'work' && entry.here && entry.doing.speaking === true
+ const rows = busy.filter(entry => entry.state === 'work' && entry.here && !speaking(entry)).slice(0, ROWS_MAX)
+ return { rows, rest: busy.filter(entry => !rows.includes(entry) && !speaking(entry)) }
+}
+
+// The groups a Bot is at work in.
+export function botGroupWork(botId, work, roster) {
+ return Object.entries(work.rooms ?? {}).flatMap(([roomId, entries]) => {
+ const entry = entries.find(item => item.botId === botId)
+ const room = roster.roomsById[roomId]
+ return entry && room ? [{ room, tool: entry.tool, since: entry.since }] : []
+ })
+}
+
export function summaryText(busy) {
const asks = busy.filter(entry => entry.state === 'ask')
const workers = busy.filter(entry => entry.state === 'work')
@@ -44,23 +66,52 @@ function Face({ entry, size }) {
h(BotMark, { bot: entry.bot, size, state: entry.state === 'ask' ? 'alert' : toolState(entry.doing?.tool ?? '') }))
}
-// The line above a group's composer; it opens the details panel.
-export function MemberDock({ sessionId, useRoster, useWork, actions }) {
- const roster = useRoster(value => value)
- const work = useWork(value => value)
- const room = roster.roomsById[sessionId]
- if (!room) return null
- const busy = busyMembers(room, work, roster)
- if (busy.length === 0) return null
+// One piece of work: the Bot's mark and what it is doing, like the activity row.
+function WorkRow({ bot, tool, label, at, now, onOpen }) {
+ const text = `${label} · ${workPhrase(tool)}…`
+ const elapsed = typeof at === 'number' && now - at >= 60000 ? elapsedLabel(now - at) : ''
+ return h('button', { type: 'button', className: 'bt-mw-row', 'aria-label': [text, elapsed].filter(Boolean).join(' · '), onClick: onOpen },
+ h(BotMark, { bot, size: 22, state: toolState(tool ?? ''), live: true }),
+ h('span', { className: 'bt-mw-row-text' }, h(Shimmer, null, text)),
+ elapsed ? h('span', { className: 'bt-mw-row-time' }, `· ${elapsed}`) : null)
+}
+
+function SummaryLine({ busy, onOpen }) {
const { waiting, doing } = summaryText(busy)
return h('div', { className: 'bt-event bt-mw-dock' },
- h('button', { type: 'button', className: 'bt-event-whole bt-mw-line', 'aria-label': [waiting, doing].filter(Boolean).join(' · '), onClick: () => actions.showDetails(sessionId) },
+ h('button', { type: 'button', className: 'bt-event-whole bt-mw-line', 'aria-label': [waiting, doing].filter(Boolean).join(' · '), onClick: onOpen },
h('span', { className: 'bt-mw-stack', 'aria-hidden': true }, busy.slice(0, 4).map(entry => h(Face, { key: entry.id, entry, size: 16 }))),
waiting ? h('span', { className: 'bt-mw-ask' }, waiting) : null,
waiting && doing ? h('span', { 'aria-hidden': true }, '·') : null,
doing ? h('span', { className: 'bt-event-name' }, h(Shimmer, null, doing)) : null))
}
+// Above a group's composer: who is at work here, and a line for the rest; both open the
+// details panel. Above a Bot's own composer: the groups it is at work in, while its own
+// chat is idle (a running own chat has its activity row).
+export function MemberDock({ sessionId, useRoster, useWork, actions }) {
+ const roster = useRoster(value => value)
+ const work = useWork(value => value)
+ const room = roster.roomsById[sessionId]
+ const bot = room ? undefined : roster.byId[sessionId]
+ const ownChat = bot !== undefined && work.bots?.[bot.id] !== undefined && work.bots[bot.id].roomId === undefined
+ const busy = room ? busyMembers(room, work, roster) : []
+ const groups = bot !== undefined && !ownChat ? botGroupWork(bot.id, work, roster) : []
+ const now = useNow(busy.length > 0 || groups.length > 0)
+ if (room) {
+ if (busy.length === 0) return null
+ const { rows, rest } = splitBusy(busy)
+ const open = () => actions.showDetails(sessionId)
+ return h('div', { className: 'bt-mw-dock-stack' },
+ rows.map(entry => h(WorkRow, { key: entry.id, bot: entry.bot, tool: entry.doing.tool, label: entry.bot.name, at: entry.doing.since, now, onOpen: open })),
+ rest.length > 0 ? h(SummaryLine, { busy: rest, onOpen: open }) : null)
+ }
+ if (groups.length === 0) return null
+ return h('div', { className: 'bt-mw-dock-stack' }, groups.slice(0, ROWS_MAX).map(item => h(WorkRow, {
+ key: item.room.id, bot, tool: item.tool, label: t('in {name}', { name: item.room.name }), at: item.since, now, onOpen: () => actions.openSession(item.room.id),
+ })))
+}
+
function useNow(active) {
const [now, setNow] = useState(Date.now)
useEffect(() => {
@@ -94,8 +145,10 @@ function ApprovalCard({ approval, bot, actions }) {
h('button', { type: 'button', className: 'bt-q-btn', onClick: () => actions.openSession(bot.id) }, t("Open {name}'s chat", { name: bot.name }))))
}
-// Under a member's row in the group's details: what it is doing, and where.
+// Under a member's row in the group's details: what it is doing, and where. Work in
+// this group can be stopped here, since the user cannot reach its Session otherwise.
export function MemberWork({ entry, bot, room, roster, actions, now }) {
+ const [stopping, setStopping] = useState(false)
if (entry.state === 'ask') {
return h('div', { className: 'bt-mw-member' },
h('div', { className: 'bt-mw-state bt-mw-ask' }, `${t('Waiting for your approval')}${since(now, entry.approvals[0].at)}`),
@@ -105,8 +158,16 @@ export function MemberWork({ entry, bot, room, roster, actions, now }) {
const where = entry.doing.roomId === room.id ? ''
: entry.doing.roomId ? t('in {name}', { name: roster.roomsById[entry.doing.roomId]?.name ?? t('a group chat') })
: t('in its own chat')
+ const stop = () => {
+ setStopping(true)
+ void Promise.resolve(actions.stopMemberWork(room.id, bot.id))
+ .catch(error => actions.reportError(error, 'stop'))
+ .finally(() => setStopping(false))
+ }
return h('div', { className: 'bt-mw-member' },
- h('div', { className: 'bt-mw-state' }, h(Shimmer, null, `${workPhrase(entry.doing.tool)}…`), where ? ` ${where}` : '', since(now, entry.doing.since)))
+ h('div', { className: 'bt-mw-state bt-mw-work' },
+ h('span', null, h(Shimmer, null, `${workPhrase(entry.doing.tool)}…`), where ? ` ${where}` : '', since(now, entry.doing.since)),
+ entry.here ? h('button', { type: 'button', className: 'bt-mw-stop', disabled: stopping, onClick: stop }, t('Stop')) : null))
}
export function useMemberWork(room, useWork) {
@@ -117,6 +178,17 @@ export function useMemberWork(room, useWork) {
}
export const MEMBER_CSS = `
+.bt-mw-dock-stack{box-sizing:border-box;display:flex;flex-direction:column;align-items:flex-start;gap:2px;width:var(--dsh-chat-content-width,min(960px,100%));margin:0 auto 6px;pointer-events:none}
+.bt-mw-dock-stack>.bt-event.bt-mw-dock{align-self:stretch;margin:0}
+.bt-mw-row{pointer-events:auto;display:flex;align-items:center;gap:10px;min-width:0;max-width:calc(100% + 6px);height:32px;margin-inline-start:-6px;padding:0 12px 0 6px;border:0;border-radius:16px;background:none;color:var(--bt-ink-2);font:inherit;font-size:14px;cursor:pointer;animation:bt-mw-in .32s cubic-bezier(.23,1,.32,1) backwards;transition:background-color .16s ease-out}
+.bt-mw-row:hover{background:var(--bt-hover)}
+.bt-mw-row>.bt-mark{flex:none}
+.bt-mw-row-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
+.bt-mw-row-time{flex:none;font-size:12px;color:var(--bt-ink-3);white-space:nowrap}
+.bt-mw-work{display:flex;align-items:center;justify-content:space-between;gap:8px}
+.bt-mw-stop{flex:none;height:22px;padding:0 10px;border:1px solid var(--bt-line,rgba(0,0,0,.12));border-radius:11px;background:none;color:var(--bt-ink-2);font:inherit;font-size:12px;cursor:pointer}
+.bt-mw-stop:hover{background:var(--bt-hover)}
+.bt-mw-stop:disabled{opacity:.5;cursor:default}
.bt-event.bt-mw-dock{margin:0 0 6px;pointer-events:none}
.bt-mw-dock>button{pointer-events:auto;animation:bt-mw-in .32s cubic-bezier(.23,1,.32,1) backwards}
.bt-mw-line{gap:6px!important}
@@ -138,5 +210,5 @@ body[data-ds-dark-theme] .bt-mw-ask{color:#f0b84a}
.bt-mw-actions>button{height:28px;padding:0 12px;font-size:12px}
.bt-mw-actions>button:disabled{opacity:.5;cursor:default}
@keyframes bt-mw-in{from{opacity:0;transform:translateY(4px)}}
-@media (prefers-reduced-motion:reduce){.bt-mw-dock>button{animation:none}}
+@media (prefers-reduced-motion:reduce){.bt-mw-dock>button,.bt-mw-row{animation:none}}
`
diff --git a/ds-bot/src/client/sidebar.js b/ds-bot/src/client/sidebar.js
index d9283696..2b3ea08f 100644
--- a/ds-bot/src/client/sidebar.js
+++ b/ds-bot/src/client/sidebar.js
@@ -7,6 +7,7 @@ import { PlusIcon, SearchIcon, GaugeIcon, PlugIcon, ClockIcon, GearIcon, PinMark
import { MAIN_LOOK } from './characters.js'
import { botState, BotMark, BotAvatar, RoomAvatar } from './mark.js'
import { reducedMotion } from './activity-row.js'
+import { Shimmer, workPhrase } from './cells.js'
import { springEasing, SPRING_SHAPE } from './motion.js'
import { hostText, t } from './i18n.js'
import { showsDshRow } from './dsh-offer.js'
@@ -27,6 +28,15 @@ const PinMark = () => h('span', { className: 'bt-pin', 'aria-hidden': true }, h(
// from any of its members there.
const useApproval = (useWork, match) => (useWork ? useWork(work => (work.approvals ?? []).some(match)) : false)
+// Work running in group Sessions, as "botId|tool" keys so a row redraws only when it
+// changes: the groups one Bot works in, or the members at work in one group.
+const useGroupWork = (useWork, pick) => (useWork ? useWork(work => pick(work.rooms ?? {}).join(',')) : '')
+const workKeys = text => (text === '' ? [] : text.split(',').map((key) => {
+ const [id, tool] = key.split('|')
+ return { id, tool: tool || undefined }
+}))
+const workLine = (lead, tool, more) => h(Shimmer, null, `${lead} · ${workPhrase(tool)}…${more > 0 ? ` +${more}` : ''}`)
+
function BotRow({ bot, roster, actions, useSessions, useSessionStatus, useSessionRetainInfo, useActivity, useWork, wide, marked }) {
const id = bot.id
const part = currentPart(bot)
@@ -40,14 +50,18 @@ function BotRow({ bot, roster, actions, useSessions, useSessionStatus, useSessio
const approval = useApproval(useWork, entry => entry.botId === id)
const alert = roster.questions?.[part] !== undefined || approval
const doing = useActivity(map => map[id])
- const state = botState(running, doing, alert)
+ // Work in a group runs in a Session of its own, so the Bot's chat stays idle meanwhile.
+ const groups = workKeys(useGroupWork(useWork, rooms => Object.entries(rooms).flatMap(([roomId, entries]) => entries.filter(entry => entry.botId === id).map(entry => `${roomId}|${entry.tool ?? ''}`))))
+ 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].tool, groups.length - 1) : null
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 ? 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') : '', 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,
@@ -65,7 +79,7 @@ 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),
- preview ? h('span', { className: 'bt-row-preview' }, preview) : null) : null,
+ awayLine ? h('span', { className: 'bt-row-preview' }, awayLine) : preview ? h('span', { className: 'bt-row-preview' }, preview) : null) : null,
wide && unread && !active ? h('span', { className: 'bt-unread', 'aria-hidden': true }) : null)
}
@@ -77,9 +91,12 @@ function RoomRow({ room, roster, actions, useSessions, useSessionStatus, useSess
const unread = useSessionStatus(map => map.get(id)?.completionUnread === true) || (marked && !active)
useMarkedUnread(id, active, marked, actions)
const approval = useApproval(useWork, entry => entry.roomId === id)
+ const members = workKeys(useGroupWork(useWork, rooms => (rooms[id] ?? []).map(entry => `${entry.botId}|${entry.tool ?? ''}`)))
+ const first = roster.byId[members[0]?.id]
+ const workingLine = first ? workLine(first.name, members[0].tool, members.length - 1) : null
if (room.hidden && !active) return null
const pinned = room.pinned === true
- const label = [room.name, pinned ? t('Pinned') : '', approval ? t('Waiting for your approval') : ''].filter(Boolean).join(', ')
+ const label = [room.name, pinned ? t('Pinned') : '', members.length > 0 ? t('Working') : '', approval ? t('Waiting for your approval') : ''].filter(Boolean).join(', ')
return h('button', {
type: 'button', className: 'bt-row', 'aria-label': label, 'aria-current': active ? 'page' : undefined,
'data-room-id': id, onClick: () => actions.openSession(id),
@@ -89,7 +106,7 @@ function RoomRow({ room, roster, actions, useSessions, useSessionStatus, useSess
pinned && !wide ? h(PinMark) : null,
wide ? h('span', { className: 'bt-row-body' },
h('span', { className: 'bt-row-name' }, h('span', { className: 'bt-row-title' }, room.name), pinned ? h(PinMark) : null),
- preview ? h('span', { className: 'bt-row-preview' }, preview) : null) : null,
+ workingLine ? h('span', { className: 'bt-row-preview' }, workingLine) : preview ? h('span', { className: 'bt-row-preview' }, preview) : null) : null,
wide && approval && !active ? h('span', { className: 'bt-unread bt-unread-wait', 'aria-hidden': true })
: wide && unread && !active ? h('span', { className: 'bt-unread', 'aria-hidden': true }) : null)
}
diff --git a/ds-bot/test/member-status.test.js b/ds-bot/test/member-status.test.js
index 2c1f9572..e50afaac 100644
--- a/ds-bot/test/member-status.test.js
+++ b/ds-bot/test/member-status.test.js
@@ -22,9 +22,21 @@ runInNewContext(bundle.outputFiles[0].text, {
return platform[name]
},
})
-const { busyMembers, summaryText } = module.exports
+const { busyMembers, summaryText, splitBusy, MemberDock } = module.exports
// Values from the bundle's realm compare by content only.
const plain = value => JSON.parse(JSON.stringify(value))
+// Renders the dock's own parts of an element tree, and lists its rows' labels.
+const expand = (node) => {
+ if (Array.isArray(node)) return node.flatMap(expand)
+ if (node === null || typeof node !== 'object') return node
+ if (['WorkRow', 'SummaryLine'].includes(node.type?.name)) return expand(node.type({ ...node.props, children: node.children }))
+ return { ...node, children: node.children.map(expand) }
+}
+const rowLabels = (node) => {
+ if (Array.isArray(node)) return node.flatMap(rowLabels)
+ if (node === null || typeof node !== 'object') return []
+ return [...(node.props.className === 'bt-mw-row' ? [node.props['aria-label']] : []), ...rowLabels(node.children)]
+}
test('the members line names who waits for an approval first, then who is at work', () => {
const names = { a: 'Anvil', b: 'Flint', c: 'Prism', d: 'Quill', e: 'King', f: 'Comet' }
@@ -41,3 +53,32 @@ test('the members line names who waits for an approval first, then who is at wor
assert.deepEqual(plain(summaryText(busy.slice(4))), { waiting: '', doing: 'Comet · Thinking about it…' })
assert.equal(busyMembers(room, { bots: {}, approvals: [] }, roster).length, 0)
})
+
+const names = { a: 'Anvil', b: 'Flint', c: 'Prism', d: 'Quill' }
+const team = {
+ byId: Object.fromEntries(Object.entries(names).map(([id, name]) => [id, { id, name }])),
+ roomsById: { r1: { id: 'r1', name: 'Ops', members: ['a', 'b', 'c', 'd'] }, r2: { id: 'r2', name: 'Docs', members: ['a', 'b'] } },
+}
+const dock = (sessionId, work) => expand(MemberDock({ sessionId, useRoster: pick => pick(team), useWork: pick => pick(work), actions: {} }))
+
+test('a member at work in the group gets a row; the speaker, work elsewhere and approvals do not', () => {
+ const work = {
+ // Anvil runs in its own chat too; its work here wins.
+ bots: { a: { since: 1, tool: 'pwsh' }, b: { since: 1, roomId: 'r2', tool: 'edit' } },
+ rooms: { r1: [{ botId: 'a', since: 1, tool: 'write' }, { botId: 'd', since: 1, speaking: true }], r2: [{ botId: 'b', since: 1, tool: 'edit' }] },
+ approvals: [{ botId: 'c', roomId: 'r1' }],
+ }
+ const busy = busyMembers(team.roomsById.r1, work, team)
+ const { rows, rest } = splitBusy(busy)
+ assert.deepEqual(plain(rows.map(entry => [entry.bot.name, entry.doing.tool, entry.doing.roomId])), [['Anvil', 'write', 'r1']])
+ assert.deepEqual(plain(rest.map(entry => [entry.bot.name, entry.state])), [['Prism', 'ask'], ['Flint', 'work']])
+ assert.deepEqual(rowLabels(dock('r1', work)), ['Anvil · Writing changes…'])
+ assert.equal(busyMembers(team.roomsById.r2, work, team).length, 2)
+})
+
+test('a Bot\'s own chat shows the groups it is at work in, unless its own chat runs', () => {
+ const away = { bots: { a: { since: 1, roomId: 'r1', tool: 'pwsh' } }, rooms: { r1: [{ botId: 'a', since: 1, tool: 'pwsh' }], r2: [{ botId: 'a', since: 1 }] }, approvals: [] }
+ assert.deepEqual(rowLabels(dock('a', away)), ['in Ops · Running shell commands…', 'in Docs · Thinking about it…'])
+ assert.deepEqual(rowLabels(dock('a', { ...away, bots: { a: { since: 1 } } })), [])
+ assert.equal(dock('b', away), null)
+})