From 6eb9545a72be62987ce86e7a25c41ca407ddb00a Mon Sep 17 00:00:00 2001 From: Richard Anaya Date: Wed, 18 Mar 2026 21:02:53 -0700 Subject: [PATCH] fix: extract text content from Pi's tool result content arrays Pi returns tool results in format: {"content": [{"type": "text", "text": "..."}]} Previously we were JSON.stringify-ing the whole object, showing as: {"content":[{"type":"text","text":"..."}]} Now we extract the actual text content for cleaner display. --- .../adapters/pi-local/src/ui/parse-stdout.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/adapters/pi-local/src/ui/parse-stdout.ts b/packages/adapters/pi-local/src/ui/parse-stdout.ts index f7b5b7f9..57a78725 100644 --- a/packages/adapters/pi-local/src/ui/parse-stdout.ts +++ b/packages/adapters/pi-local/src/ui/parse-stdout.ts @@ -72,7 +72,17 @@ export function parsePiStdoutLine(line: string, ts: string): TranscriptEntry[] { for (const tr of toolResults) { const content = tr.content; const isError = tr.isError === true; - const contentStr = typeof content === "string" ? content : JSON.stringify(content); + + // Extract text from Pi's content array format + let contentStr: string; + if (typeof content === "string") { + contentStr = content; + } else if (Array.isArray(content)) { + contentStr = extractTextContent(content as Array<{ type: string; text?: string }>); + } else { + contentStr = JSON.stringify(content); + } + entries.push({ kind: "tool_result", ts, @@ -134,7 +144,21 @@ export function parsePiStdoutLine(line: string, ts: string): TranscriptEntry[] { const toolName = asString(parsed.toolName); const result = parsed.result; const isError = parsed.isError === true; - const contentStr = typeof result === "string" ? result : JSON.stringify(result); + + // Extract text from Pi's content array format: {"content": [{"type": "text", "text": "..."}]} + let contentStr: string; + if (typeof result === "string") { + contentStr = result; + } else if (result && typeof result === "object") { + const resultObj = result as Record; + if (Array.isArray(resultObj.content)) { + contentStr = extractTextContent(resultObj.content as Array<{ type: string; text?: string }>); + } else { + contentStr = JSON.stringify(result); + } + } else { + contentStr = JSON.stringify(result); + } return [{ kind: "tool_result",