A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Recover group replies after the prune marker too
Fei24112ce7572f1488
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex b94b1bdc..d27e27cf 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -7810,6 +7810,7 @@ function useLiveNote(actions, sessionId, id, entry) {}, [sessionId, id, key]);}var RELAY_LIST = /"replies"\s*:\s*\[/;+var PRUNE_MARKER = /\[\s*\.\.\.[^\]]*\]/;function parseReplies(text) {try {return { replies: JSON.parse(text).replies ?? [], broken: false };@@ -7818,39 +7819,45 @@ function parseReplies(text) {const replies = [];const head = RELAY_LIST.exec(text);if (head) {- let depth = 0;- let from = -1;- let inString = false;- let escaped = false;- for (let i = head.index + head[0].length; 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;+ 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 GroupReplies({ sessionId, callId, done, content, roster, actions, useUi, useWork }) {const [live, setLive] = (0, import_react12.useState)({ replies: [], speaking: null });(0, import_react12.useEffect)(() => {diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.jsindex 1722151c..f7c6d49d 100644--- a/ds-bot/src/client/cells.js+++ b/ds-bot/src/client/cells.js@@ -815,39 +815,52 @@ function useLiveNote(actions, sessionId, id, entry) {// 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 = /\[\s*\.\.\.[^\]]*\]/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) {- let depth = 0- let from = -1- let inString = false- let escaped = false- for (let i = head.index + head[0].length; 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+ 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+ }+}+function GroupReplies({ sessionId, callId, done, content, roster, actions, useUi, useWork }) {const [live, setLive] = useState({ replies: [], speaking: null })useEffect(() => {diff --git a/ds-bot/test/tool-cells.test.js b/ds-bot/test/tool-cells.test.jsindex 62443ca7..768d1ad3 100644--- a/ds-bot/test/tool-cells.test.js+++ b/ds-bot/test/tool-cells.test.js@@ -601,6 +601,17 @@ test('a pruned group relay still draws the replies that survived', () => {assert.match(text(gone), /The group replies could not be shown/)})+// The prune marker's "]" must not end the scan, and a cut inside a string must+// not hide the replies after it either.+test('a group relay recovers replies after the prune marker', () => {+ const between = '{"replies":[{"botId":"writer","text":"First."}[... tool result middle pruned ...],{"botId":"chief","text":"Last."}]}'+ const out = show(call('group_relay', 'direct', { content: between }), { sessionId: 'room' })+ assert.match(text(out), /Writer.*First\..*Chief.*Last\./)+ const inside = '{"replies":[{"botId":"writer","text":"First."},{"botId":"chief","text":"cut[... tool result middle pruned ...]{"botId":"writer","text":"Last."}]}'+ const out2 = show(call('group_relay', 'direct', { content: inside }), { sessionId: 'room' })+ assert.match(text(out2), /Writer.*First\..*Last\./)+})+// #38: a PTC group round's replies vanished once the round ended.test('a PTC group relay shows its replies from the sub-call, live and after reload', async () => {const replies = [{ botId: 'writer', text: 'Hello from Writer.' }, { botId: 'chief', text: 'Hello from Chief.' }]