A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Read a group's relay replies from the real tool/result record
Fei2411e389474e5592
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 50ff7e98..5504bd91 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -7285,6 +7285,69 @@ var thinkingLive = (step) => step.status === "running" && texts(step).length ===var texts = (step) => step.blocks.filter((block) => block.kind === "text" && block.text.trim() !== "");var stepReasoning = (step) => step.blocks.filter((block) => block.kind === "reasoning").map((block) => block.text).join("\n").trim();+// src/shared/group-replies.js+var RELAY_LIST = /"replies"\s*:\s*\[/;+var PRUNE_MARKER = /\[\.\.\. tool result middle pruned \.\.\.\]/;+function parseReplies(text) {+ try {+ return { replies: JSON.parse(text).replies ?? [], broken: false };+ } catch {+ }+ const replies = [];+ const head = RELAY_LIST.exec(text);+ if (head) {+ for (const piece of text.slice(head.index + head[0].length).split(PRUNE_MARKER)) {+ const first = piece.indexOf('{"');+ if (first !== -1) scanReplies(piece, first, replies);+ }+ }+ return { replies, broken: true };+}+function scanReplies(text, start, replies) {+ let depth = 0;+ let from = -1;+ let inString = false;+ let escaped = false;+ for (let i = start; i < text.length; i += 1) {+ const ch = text[i];+ if (inString) {+ if (escaped) escaped = false;+ else if (ch === "\\") escaped = true;+ else if (ch === '"') inString = false;+ continue;+ }+ if (ch === '"') {+ inString = true;+ continue;+ }+ if (ch === "{") {+ if (depth === 0) from = i;+ depth += 1;+ } else if (ch === "}") {+ depth -= 1;+ if (depth === 0 && from >= 0) {+ try {+ replies.push(JSON.parse(text.slice(from, i + 1)));+ } catch {+ }+ from = -1;+ }+ } else if (ch === "]" && depth === 0) break;+ }+}+function stackReplies(replies) {+ const items = [];+ replies.forEach((reply, index) => {+ const last = items.at(-1);+ if (reply.kind === void 0 && last?.reply.kind === void 0 && last?.reply.botId === reply.botId) {+ last.texts.push(reply.text);+ last.time = reply.time;+ last.duration = reply.duration;+ } else items.push({ reply, index, texts: reply.kind === void 0 ? [reply.text] : [], time: reply.time, duration: reply.duration });+ });+ return items;+}+// src/client/fold.jsvar import_react14 = require("react");var FOLD_AT = { chars: 1500, lines: 25 };@@ -8026,18 +8089,6 @@ function GroupMessage({ bot, text, texts: texts2 = [text], room: room2, roster,(0, import_react16.createElement)(Bubbles, { texts: texts2, roster, selfId: bot.id, actions, sessionId: room2?.id, msgKey, useUi, lead: flat ? null : lead, whole }));}-function stackReplies(replies) {- const items = [];- replies.forEach((reply, index) => {- const last = items.at(-1);- if (reply.kind === void 0 && last?.reply.kind === void 0 && last?.reply.botId === reply.botId) {- last.texts.push(reply.text);- last.time = reply.time;- last.duration = reply.duration;- } else items.push({ reply, index, texts: reply.kind === void 0 ? [reply.text] : [], time: reply.time, duration: reply.duration });- });- return items;-}function GroupEvent({ prefix, room: room2, name, roster, actions }) {return (0, import_react16.createElement)("div",@@ -8243,14 +8294,21 @@ function chatRow(row, key, { sessionId, selfId, roster, actions, useUi, onBtwDelkey,bot: poster,text: row.file ? stripLongNote(row.text) : row.text,+ texts: row.texts,room: roster.roomsById[sessionId],roster,actions,msgKey: `${sessionId}:post:${row.seq ?? row.time}`,time: row.time,+ duration: row.duration,whole: row.file ? { length: row.length, load: () => actions.fileText(row.file) } : void 0});}+ case "relay": {+ const reply = row.reply;+ const speaker = roster.byId[reply.botId] ?? { id: reply.botId, name: reply.name ?? t("a Bot"), color: reply.color ?? "gray" };+ return (0, import_react16.createElement)(RelayEvent, { key, reply, bot: speaker, sessionId, actions });+ }case "event": {if (row.role === "report") return (0, import_react16.createElement)(GroupEvent, { key, prefix: t("Replies from"), room: roster.roomsById[row.roomId], name: t("a group chat"), roster, actions });const other = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t("a Bot"), color: "gray" };@@ -8508,54 +8566,63 @@ function useLiveNote(actions, sessionId, id, entry) {return () => actions.noteLive(sessionId, id, null);}, [sessionId, id, key]);}-var RELAY_LIST = /"replies"\s*:\s*\[/;-var PRUNE_MARKER = /\[\.\.\. tool result middle pruned \.\.\.\]/;-function parseReplies(text) {- try {- return { replies: JSON.parse(text).replies ?? [], broken: false };- } catch {+function RelayEvent({ reply, bot, sessionId, actions }) {+ if (reply.kind === "failed") {+ return (0, import_react16.createElement)(+ "div",+ { className: "bt-event bt-event-error", role: "status", title: [reply.code, reply.status, reply.text].filter(Boolean).join(" · ") },+ t("{name} could not answer: {reason}", { name: bot.name, reason: failureLabel(reply.code, reply.text) })+ );}- const replies = [];- const head = RELAY_LIST.exec(text);- if (head) {- for (const piece of text.slice(head.index + head[0].length).split(PRUNE_MARKER)) {- const first = piece.indexOf('{"');- if (first !== -1) scanReplies(piece, first, replies);- }+ if (reply.kind === "lookup") {+ return (0, import_react16.createElement)(+ "div",+ { className: "bt-event" },+ reply.text ? t("{name} looked up its own chat for “{text}”", { name: bot.name, text: reply.text }) : t("{name} looked up its own chat", { name: bot.name })+ );}- return { replies, broken: true };-}-function scanReplies(text, start, replies) {- let depth = 0;- let from = -1;- let inString = false;- let escaped = false;- for (let i = start; i < text.length; i += 1) {- const ch = text[i];- if (inString) {- if (escaped) escaped = false;- else if (ch === "\\") escaped = true;- else if (ch === '"') inString = false;- continue;- }- if (ch === '"') {- inString = true;- continue;- }- if (ch === "{") {- if (depth === 0) from = i;- depth += 1;- } else if (ch === "}") {- depth -= 1;- if (depth === 0 && from >= 0) {- try {- replies.push(JSON.parse(text.slice(from, i + 1)));- } catch {- }- from = -1;- }- } else if (ch === "]" && depth === 0) break;+ if (reply.kind === "missed") {+ return (0, import_react16.createElement)("div", { className: "bt-event" }, t("{name} didn't answer in time", { name: bot.name }));}+ if (reply.kind === "admin-passed") {+ return (0, import_react16.createElement)(+ "div",+ { className: "bt-event" },+ t("{name} did not answer or call anyone; call a member with @Name", { name: bot.name })+ );+ }+ if (reply.kind === "paused") {+ return (0, import_react16.createElement)(+ "div",+ { className: "bt-event" },+ t("Paused after {count} Bot relays. Waiting: {names}", { count: reply.count, names: (reply.names ?? []).join(t(" and ")) })+ );+ }+ if (reply.kind === "resumed") {+ return (0, import_react16.createElement)("div", { className: "bt-event" }, t("{name} was cut off by a restart and picked its work back up", { name: bot.name }));+ }+ if (reply.kind === "cut") {+ return (0, import_react16.createElement)("div", { className: "bt-event" }, t("{name} was cut off by a restart again and stopped", { name: bot.name }));+ }+ if (reply.kind === "approval" || reply.kind === "working") {+ return (0, import_react16.createElement)(+ "div",+ { className: "bt-event" },+ (0, import_react16.createElement)(+ "button",+ { type: "button", className: "bt-event-whole", onClick: () => actions.showDetails(sessionId) },+ (0, import_react16.createElement)(BotMark, { bot, size: 16 }),+ (0, import_react16.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_react16.createElement)("div", { className: "bt-event" }, t("You stopped {name}'s work", { name: bot.name }));+ }+ if (reply.kind === "done") {+ return (0, import_react16.createElement)("div", { className: "bt-event" }, t("{name} finished its work", { name: bot.name }));+ }+ return null;}function GroupReplies({ sessionId, callId, done, content, roster, actions, useUi, useWork }) {const [live, setLive] = (0, import_react16.useState)({ replies: [], speaking: [] });@@ -8610,60 +8677,8 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUiNumber.isFinite(time) ? (0, import_react16.createElement)("div", { className: "bt-utime", title: clockLabel(time) }, messageClock(time)) : null));}- if (reply.kind === "failed") {- return (0, import_react16.createElement)(- "div",- { key: `${reply.botId}-${index}`, className: "bt-event bt-event-error", role: "status", title: [reply.code, reply.status, reply.text].filter(Boolean).join(" · ") },- t("{name} could not answer: {reason}", { name: bot.name, reason: failureLabel(reply.code, reply.text) })- );- }- if (reply.kind === "lookup") {- return (0, import_react16.createElement)(- "div",- { key: `${reply.botId}-${index}`, className: "bt-event" },- reply.text ? t("{name} looked up its own chat for “{text}”", { name: bot.name, text: reply.text }) : t("{name} looked up its own chat", { name: bot.name })- );- }- if (reply.kind === "missed") {- return (0, import_react16.createElement)("div", { key: `${reply.botId}-${index}`, className: "bt-event" }, t("{name} didn't answer in time", { name: bot.name }));- }- if (reply.kind === "admin-passed") {- return (0, import_react16.createElement)(- "div",- { key: `${reply.botId}-${index}`, className: "bt-event" },- t("{name} did not answer or call anyone; call a member with @Name", { name: bot.name })- );- }- if (reply.kind === "paused") {- return (0, import_react16.createElement)(- "div",- { key: `paused-${index}`, className: "bt-event" },- t("Paused after {count} Bot relays. Waiting: {names}", { count: reply.count, names: (reply.names ?? []).join(t(" and ")) })- );- }- if (reply.kind === "resumed") {- return (0, import_react16.createElement)("div", { key: `${reply.botId}-${index}`, className: "bt-event" }, t("{name} was cut off by a restart and picked its work back up", { name: bot.name }));- }- if (reply.kind === "cut") {- return (0, import_react16.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" || reply.kind === "working") {- return (0, import_react16.createElement)(- "div",- { key: `${reply.botId}-${index}`, className: "bt-event" },- (0, import_react16.createElement)(- "button",- { type: "button", className: "bt-event-whole", onClick: () => actions.showDetails(sessionId) },- (0, import_react16.createElement)(BotMark, { bot, size: 16 }),- (0, import_react16.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_react16.createElement)("div", { key: `${reply.botId}-${index}`, className: "bt-event" }, t("You stopped {name}'s work", { name: bot.name }));- }- if (reply.kind === "done") {- return (0, import_react16.createElement)("div", { key: `${reply.botId}-${index}`, className: "bt-event" }, t("{name} finished its work", { name: bot.name }));+ if (reply.kind !== void 0) {+ return (0, import_react16.createElement)(RelayEvent, { key: `${reply.botId ?? reply.kind}-${index}`, reply, bot, sessionId, actions });}return (0, import_react16.createElement)(GroupMessage, { key: `${reply.botId}-${index}`, bot, texts: texts2, room: room2, roster, actions, msgKey: callId ? `${sessionId}:${callId}:${index}` : void 0, useUi, time, duration });}),diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.jsindex 770b2be9..75c5f993 100644--- a/ds-bot/src/client/cells.js+++ b/ds-bot/src/client/cells.js@@ -13,6 +13,7 @@ import { t } from './i18n.js'import { call } from './api.js'import { failureLabel } from './diagnostics.js'import { turnReasoning, thinkingStep, opensReply } from './turn-reasoning.js'+import { parseReplies, stackReplies } from '../shared/group-replies.js'import { FOLD_AT, FOLD_HUGE, stripLongNote, useFold } from './fold.js'import { noHover, useViewport, viewBottom } from './motion.js'import { heldCardKey } from './sources.js'@@ -308,21 +309,6 @@ function GroupMessage({ bot, text, texts = [text], room, roster, actions, msgKeyh(Bubbles, { texts, roster, selfId: bot.id, actions, sessionId: room?.id, msgKey, useUi, lead: flat ? null : lead, whole }))}-// A member's messages in a row, as one block under its name: what it says while it-// works comes one message at a time. A block carries the last message's time and run.-export function stackReplies(replies) {- const items = []- replies.forEach((reply, index) => {- const last = items.at(-1)- if (reply.kind === undefined && last?.reply.kind === undefined && last?.reply.botId === reply.botId) {- last.texts.push(reply.text)- last.time = reply.time- last.duration = reply.duration- } else items.push({ reply, index, texts: reply.kind === undefined ? [reply.text] : [], time: reply.time, duration: reply.duration })- })- return items-}-// A centered event line that names a group chat and opens it.function GroupEvent({ prefix, room, name, roster, actions }) {return h('div', { className: 'bt-event' },@@ -542,11 +528,18 @@ function chatRow(row, key, { sessionId, selfId, roster, actions, useUi, onBtwDel// A member's message in a group's earlier part, as the live row shows it.const poster = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t('a Bot'), color: 'gray' }return h(GroupMessage, {- key, bot: poster, text: row.file ? stripLongNote(row.text) : row.text, room: roster.roomsById[sessionId], roster, actions,- msgKey: `${sessionId}:post:${row.seq ?? row.time}`, time: row.time,+ key, bot: poster, text: row.file ? stripLongNote(row.text) : row.text, texts: row.texts, room: roster.roomsById[sessionId], roster, actions,+ msgKey: `${sessionId}:post:${row.seq ?? row.time}`, time: row.time, duration: row.duration,whole: row.file ? { length: row.length, load: () => actions.fileText(row.file) } : undefined,})}+ case 'relay': {+ // A round notice from a group_relay result on an earlier part, the row the+ // live chat draws for it.+ const reply = row.reply+ const speaker = roster.byId[reply.botId] ?? { id: reply.botId, name: reply.name ?? t('a Bot'), color: reply.color ?? 'gray' }+ return h(RelayEvent, { key, reply, bot: speaker, sessionId, actions })+ }case 'event': {if (row.role === 'report') return h(GroupEvent, { key, prefix: t('Replies from'), room: roster.roomsById[row.roomId], name: t('a group chat'), roster, actions })const other = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t('a Bot'), color: 'gray' }@@ -831,54 +824,48 @@ function useLiveNote(actions, sessionId, id, entry) {}, [sessionId, id, key])}-// Reads the replies of a settled group_relay result. Compaction can prune the-// middle of a long tool result, which leaves invalid JSON: then every complete-// reply object that survived is recovered so the turn still draws what it can.-const RELAY_LIST = /"replies"\s*:\s*\[/-// Compaction marks a pruned span with a literal bracketed note like-// "[... tool result middle pruned ...]". Its "]" looks like the end of the-// replies array to a naive scan, so the text is split on the marker first.-const PRUNE_MARKER = /\[\.\.\. tool result middle pruned \.\.\.\]/-function parseReplies(text) {- try { return { replies: JSON.parse(text).replies ?? [], broken: false } } catch { /* fall through */ }- const replies = []- const head = RELAY_LIST.exec(text)- if (head) {- for (const piece of text.slice(head.index + head[0].length).split(PRUNE_MARKER)) {- // The cut can start inside a string, leaving a fragment that keeps the- // scanner inside quotes: restart at the first complete reply instead.- const first = piece.indexOf('{"')- if (first !== -1) scanReplies(piece, first, replies)- }+// One non-message row of a group round: the same event line the live view draws+// for a reply that is not a member's message or the user's own line. `bot` is the+// resolved member the reply names.+function RelayEvent({ reply, bot, sessionId, actions }) {+ if (reply.kind === 'failed') {+ return h('div', { className: 'bt-event bt-event-error', role: 'status', title: [reply.code, reply.status, reply.text].filter(Boolean).join(' · ') },+ t('{name} could not answer: {reason}', { name: bot.name, reason: failureLabel(reply.code, reply.text) }))}- return { replies, broken: true }-}--function scanReplies(text, start, replies) {- let depth = 0- let from = -1- let inString = false- let escaped = false- for (let i = start; i < text.length; i += 1) {- const ch = text[i]- if (inString) {- if (escaped) escaped = false- else if (ch === '\\') escaped = true- else if (ch === '"') inString = false- continue- }- if (ch === '"') { inString = true; continue }- if (ch === '{') {- if (depth === 0) from = i- depth += 1- } else if (ch === '}') {- depth -= 1- if (depth === 0 && from >= 0) {- try { replies.push(JSON.parse(text.slice(from, i + 1))) } catch { /* partial object */ }- from = -1- }- } else if (ch === ']' && depth === 0) break+ if (reply.kind === 'lookup') {+ return h('div', { className: 'bt-event' },+ reply.text ? t('{name} looked up its own chat for “{text}”', { name: bot.name, text: reply.text }) : t('{name} looked up its own chat', { name: bot.name }))+ }+ if (reply.kind === 'missed') {+ return h('div', { className: 'bt-event' }, t("{name} didn't answer in time", { name: bot.name }))+ }+ if (reply.kind === 'admin-passed') {+ return h('div', { className: 'bt-event' },+ t('{name} did not answer or call anyone; call a member with @Name', { name: bot.name }))+ }+ // LEGACY: rounds from when groups paused at a relay limit.+ if (reply.kind === 'paused') {+ return h('div', { className: 'bt-event' },+ t('Paused after {count} Bot relays. Waiting: {names}', { count: reply.count, names: (reply.names ?? []).join(t(' and ')) }))}+ if (reply.kind === 'resumed') {+ return h('div', { className: 'bt-event' }, t('{name} was cut off by a restart and picked its work back up', { name: bot.name }))+ }+ if (reply.kind === 'cut') {+ return h('div', { className: 'bt-event' }, t('{name} was cut off by a restart again and stopped', { name: bot.name }))+ }+ if (reply.kind === 'approval' || reply.kind === 'working') {+ return h('div', { 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(reply.kind === 'working' ? '{name} started on it' : '{name} paused for your approval', { name: bot.name }))))+ }+ if (reply.kind === 'stopped') {+ return h('div', { className: 'bt-event' }, t("You stopped {name}'s work", { name: bot.name }))+ }+ if (reply.kind === 'done') {+ return h('div', { className: 'bt-event' }, t('{name} finished its work', { name: bot.name }))+ }+ return null}function GroupReplies({ sessionId, callId, done, content, roster, actions, useUi, useWork }) {@@ -927,42 +914,8 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUih(MarkdownText, { text: reply.text, labels: mdLabels(), variant: 'compact' }),Number.isFinite(time) ? h('div', { className: 'bt-utime', title: clockLabel(time) }, messageClock(time)) : null))}- if (reply.kind === 'failed') {- return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event bt-event-error', role: 'status', title: [reply.code, reply.status, reply.text].filter(Boolean).join(' · ') },- t('{name} could not answer: {reason}', { name: bot.name, reason: failureLabel(reply.code, reply.text) }))- }- if (reply.kind === 'lookup') {- return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' },- reply.text ? t('{name} looked up its own chat for “{text}”', { name: bot.name, text: reply.text }) : t('{name} looked up its own chat', { name: bot.name }))- }- if (reply.kind === 'missed') {- return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' }, t("{name} didn't answer in time", { name: bot.name }))- }- if (reply.kind === 'admin-passed') {- return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' },- t('{name} did not answer or call anyone; call a member with @Name', { name: bot.name }))- }- // LEGACY: rounds from when groups paused at a relay limit.- if (reply.kind === 'paused') {- return h('div', { key: `paused-${index}`, className: 'bt-event' },- t('Paused after {count} Bot relays. Waiting: {names}', { count: reply.count, names: (reply.names ?? []).join(t(' and ')) }))- }- if (reply.kind === 'resumed') {- return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' }, t('{name} was cut off by a restart and picked its work back up', { name: bot.name }))- }- 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' || 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(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 }))- }- if (reply.kind === 'done') {- return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' }, t('{name} finished its work', { name: bot.name }))+ if (reply.kind !== undefined) {+ return h(RelayEvent, { key: `${reply.botId ?? reply.kind}-${index}`, reply, bot, sessionId, actions })}return h(GroupMessage, { key: `${reply.botId}-${index}`, bot, texts, room, roster, actions, msgKey: callId ? `${sessionId}:${callId}:${index}` : undefined, useUi, time, duration })}),diff --git a/ds-bot/src/host/parts.js b/ds-bot/src/host/parts.jsindex 6f771022..293cb84c 100644--- a/ds-bot/src/host/parts.js+++ b/ds-bot/src/host/parts.js@@ -18,6 +18,7 @@ import { randomUUID } from 'node:crypto'import { BlockAssembler, createUserMessage } from '@deepseek-ai/dsh-llm'import { openTurnAt } from './btw.js'import { HANDOFF_ACK, HISTORY_TIMEOUT_MS, REPLY_KIND, SOURCE_KIND } from './constants.js'+import { parseReplies, stackReplies } from '../shared/group-replies.js'import { CHECKPOINT_PROMPT, STEWARD_SYSTEM, checkpointCount, checkpointTail, checkpointTailNote, checkpointText, linesFor, parseDecision, stewardRequest } from './steward.js'import { RESUME_DELAY_MS } from './resume.js'import { clip, createClock, escapeRegExp, estimateTokens, splitRef, textOf } from './text.js'@@ -1276,6 +1277,10 @@ export function install(rt) {const EARLIER_PAGE = 60function displayItems(partId, events, session, seedTurn) {const hidden = new Set(state.exchangeTurns[partId] ?? [])+ // Call ids of the page's group_relay calls; their tool/result events carry the+ // round's replies. A result without its call on the page (the page cut between+ // them) draws nothing rather than guessing.+ const relayCalls = new Set()const items = []// The turn/start still in effect. A steered or queued user message stays in// it; only another turn/start moves on. A later page does not repeat the@@ -1302,6 +1307,9 @@ export function install(rt) {continue}if (event.type === 'tool/call') {+ // A group_relay call's result is paired back to it by call id — the tool+ // name is on the call, never on the result.+ if (event.data?.name === 'group_relay') relayCalls.add(event.data?.callId)// Hidden turns and refused calls never showed a display card. Interactive// cards live in the pending dock or on their answer message instead.if (event.data?.name === 'show_view' && !hidden.has(event.data?.turn)) {@@ -1317,16 +1325,19 @@ export function install(rt) {}if (event.type === 'tool/result') {// A group's own Session runs no model; its turns are synthesized group_relay- // calls whose results hold the members' replies — the group's conversation,- // the same rows the live chat draws from the settled call.- if (event.data?.name !== 'group_relay' && event.data?.toolName !== 'group_relay') continue- const raw = event.data?.result ?? event.data?.content- const text = typeof raw === 'string' ? raw : textOf(raw)- let replies = []- try { replies = JSON.parse(text)?.replies ?? [] } catch { /* a pruned result draws nothing */ }- for (const reply of replies) {- if (reply.kind === 'user') stamp(event, { kind: 'user', text: reply.text, time: event.time })- else stamp(event, { kind: 'post', botId: reply.botId ?? null, name: reply.name ?? null, text: reply.text, time: event.time })+ // calls whose results hold the round's replies — the group's conversation,+ // read the way the live chat reads a settled call (shared/group-replies.js).+ const message = event.data?.message+ if (!relayCalls.has(message?.toolCallId)) continue+ const { replies } = parseReplies(textOf(message?.content))+ for (const { reply, texts, time, duration } of stackReplies(replies)) {+ // Reply rows take the reply's own time, and no seq: several rows share+ // the result event's seq, which the chat keys a post's anchor by.+ const item = { time: time ?? reply.time ?? event.time }+ if (turn !== undefined) item.turn = turn+ if (reply.kind === 'user') items.push({ kind: 'user', text: reply.text, ...item })+ else if (reply.kind === undefined) items.push({ kind: 'post', botId: reply.botId ?? null, name: reply.name ?? null, texts, ...item, ...(duration === undefined ? {} : { duration }) })+ else items.push({ kind: 'relay', reply, ...item })}continue}diff --git a/ds-bot/src/shared/group-replies.js b/ds-bot/src/shared/group-replies.jsnew file mode 100644index 00000000..ffce7d36--- /dev/null+++ b/ds-bot/src/shared/group-replies.js@@ -0,0 +1,69 @@+// Reading a settled group_relay result back into the group's conversation rows,+// shared by the live chat (client/cells.js) and the earlier-parts page+// (host/parts.js): the result's JSON holds the round's `replies`, in the order+// the live view draws them.++// Compaction can prune the middle of a long tool result, which leaves invalid+// JSON: then every complete reply object that survived is recovered so the turn+// still draws what it can.+const RELAY_LIST = /"replies"\s*:\s*\[/+// Compaction marks a pruned span with a literal bracketed note like+// "[... tool result middle pruned ...]". Its "]" looks like the end of the+// replies array to a naive scan, so the text is split on the marker first.+const PRUNE_MARKER = /\[\.\.\. tool result middle pruned \.\.\.\]/+export function parseReplies(text) {+ try { return { replies: JSON.parse(text).replies ?? [], broken: false } } catch { /* fall through */ }+ const replies = []+ const head = RELAY_LIST.exec(text)+ if (head) {+ for (const piece of text.slice(head.index + head[0].length).split(PRUNE_MARKER)) {+ // The cut can start inside a string, leaving a fragment that keeps the+ // scanner inside quotes: restart at the first complete reply instead.+ const first = piece.indexOf('{"')+ if (first !== -1) scanReplies(piece, first, replies)+ }+ }+ return { replies, broken: true }+}++function scanReplies(text, start, replies) {+ let depth = 0+ let from = -1+ let inString = false+ let escaped = false+ for (let i = start; i < text.length; i += 1) {+ const ch = text[i]+ if (inString) {+ if (escaped) escaped = false+ else if (ch === '\\') escaped = true+ else if (ch === '"') inString = false+ continue+ }+ if (ch === '"') { inString = true; continue }+ if (ch === '{') {+ if (depth === 0) from = i+ depth += 1+ } else if (ch === '}') {+ depth -= 1+ if (depth === 0 && from >= 0) {+ try { replies.push(JSON.parse(text.slice(from, i + 1))) } catch { /* partial object */ }+ from = -1+ }+ } else if (ch === ']' && depth === 0) break+ }+}++// A member's messages in a row, as one block under its name: what it says while it+// works comes one message at a time. A block carries the last message's time and run.+export function stackReplies(replies) {+ const items = []+ replies.forEach((reply, index) => {+ const last = items.at(-1)+ if (reply.kind === undefined && last?.reply.kind === undefined && last?.reply.botId === reply.botId) {+ last.texts.push(reply.text)+ last.time = reply.time+ last.duration = reply.duration+ } else items.push({ reply, index, texts: reply.kind === undefined ? [reply.text] : [], time: reply.time, duration: reply.duration })+ })+ return items+}diff --git a/ds-bot/test/tool-cells.test.js b/ds-bot/test/tool-cells.test.jsindex 64bc984e..d1d445d9 100644--- a/ds-bot/test/tool-cells.test.js+++ b/ds-bot/test/tool-cells.test.js@@ -9,7 +9,8 @@ import { build } from 'esbuild'const { outputFiles } = await build({stdin: {contents: [- "export { ToolCell, TriggerCell, callTree, stackReplies } from './src/client/cells.js'",+ "export { ToolCell, TriggerCell, callTree } from './src/client/cells.js'",+ "export { stackReplies } from './src/shared/group-replies.js'","export { QuestionDock } from './src/client/questions.js'","export { SecretDock } from './src/client/secret-card.js'","export { countCards } from './src/client/sources.js'",diff --git a/ds-bot/test/work-dir.test.js b/ds-bot/test/work-dir.test.jsindex 1759ff2c..d9f83dc3 100644--- a/ds-bot/test/work-dir.test.js+++ b/ds-bot/test/work-dir.test.js@@ -3,7 +3,10 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync,import { homedir, hostname, tmpdir } from 'node:os'import { join, resolve } from 'node:path'import { test } from 'node:test'+import { createToolResultMessage, createUserMessage } from '@deepseek-ai/dsh-llm'+import { Session } from '@deepseek-ai/dsh-session'import { apply } from '../index.js'+import { SOURCE_KIND } from '../src/host/constants.js'import { dshHomeOf } from '../src/host/folders.js'import { escapeRegExp } from '../src/host/text.js'import { fakeApproval, fakeContext } from './fake-ctx.js'@@ -1042,24 +1045,54 @@ test('a group folder change moves the group\'s own Session to a part in the foldtest('a group\'s earlier parts page like a Bot\'s own chat', async (t) => {const { ctx, call, project, state, stop } = await start()t.after(stop)- // The earlier part's record carries the group's posts as user/message events.- // A real group round's events: the user's question, a member's posted line, and- // the synthesized group_relay result holding its replies.+ // The earlier part's record is a real group round the way DSH logs it on the+ // group's own Session (rc.4): the user's question and a member's posted line as+ // user/message events, then the synthesized group_relay tool/call paired by call+ // id with a tool/result whose message holds the round's replies — the tool name+ // is on the call, never on the result.+ const session = Session.create('r1')+ const events = []+ const record = (type, data, opts) => {+ const event = session.append(type, data, opts)+ events.push(event)+ return event+ }+ record('user/message', createUserMessage({+ source: { kind: 'user' },+ content: [{ type: 'text', text: '@Writer 文档在哪' }],+ }), { surfaceOp: 'append' })+ record('user/message', createUserMessage({+ source: { kind: SOURCE_KIND, form: 'relay', role: 'post', senderName: 'Writer', senderSessionId: 'b', roomId: 'r1' },+ content: [{ type: 'text', text: '[Group post from Writer]\nDone.' }],+ }), { surfaceOp: 'append' })+ const relay = record('tool/call', { turn: 1, step: 1, callId: 'toolu_relay_1', name: 'group_relay', arguments: '{}' })+ record('tool/result', {+ turn: 1, step: 1,+ message: createToolResultMessage({+ callId: 'toolu_relay_1',+ isError: false,+ content: [{ type: 'text', text: JSON.stringify({ replies: [{ botId: 'b', name: 'Writer', color: 'blue', text: '在 docs/ 下面', time: 1000 }, { kind: 'missed', botId: 'a', name: 'Chief', color: 'gray', time: 2000 }] }) }],+ }),+ }, { surfaceOp: 'append', sourceEventSeqs: [relay.seq] })+ // A result whose call named another tool is not the group's conversation.+ const other = record('tool/call', { turn: 1, step: 2, callId: 'toolu_2', name: 'remember', arguments: '{}' })+ record('tool/result', {+ turn: 1, step: 2,+ message: createToolResultMessage({ callId: 'toolu_2', isError: false, content: [{ type: 'text', text: 'Saved to memory' }] }),+ }, { surfaceOp: 'append', sourceEventSeqs: [other.seq] })ctx.sessionController.page = async ({ address }) => (address?.sessionId === 'r1'- ? {- records: [- { event: { type: 'user/message', seq: 1, time: 1, data: { content: [{ type: 'text', text: '@Writer 文档在哪' }], source: { kind: 'user' } } } },- { event: { type: 'user/message', seq: 2, time: 2, data: { content: [{ type: 'text', text: '[Group post from Writer]\nDone.' }], source: { kind: 'bot', role: 'post', senderSessionId: 'gb', senderName: 'Writer' } } } },- { event: { type: 'tool/result', seq: 3, time: 3, data: { callId: 'c1', name: 'group_relay', result: '{"replies":[{"botId":"gb","name":"Writer","text":"在 docs/ 下面"}]}' } } },- ],- hasMore: false,- }+ ? { records: events.map(event => ({ event })), hasMore: false }: { records: [], hasMore: false })assert.equal((await call('update-room', { id: 'r1', workDir: project })).ok, true)await until(() => state().rooms.r1.sessionId === 's1')// The current part's earlier page reads the part it moved on from.const page = (await call('earlier', { sessionId: 's1' })).value- assert.deepEqual(page.items.map(item => [item.kind, item.name ?? null, item.text]), [['user', null, '@Writer 文档在哪'], ['post', 'Writer', 'Done.'], ['post', 'Writer', '在 docs/ 下面']])+ assert.deepEqual(page.items.map(item => [item.kind, item.name ?? item.reply?.kind ?? null, item.text ?? item.texts?.[0] ?? null]), [+ ['user', null, '@Writer 文档在哪'],+ ['post', 'Writer', 'Done.'],+ ['post', 'Writer', '在 docs/ 下面'],+ ['relay', 'missed', null],+ ])assert.equal(page.cursor, null)assert.equal(typeof page.startedAt, 'number')// The first part itself has nothing before it.