fix: parse serialized JSON content in subagent Task results

Subagent (Task/Explore) results were rendered as raw JSON
`[{"type":"text","text":"..."}]` with literal `\n` instead of
formatted markdown. The root cause was that the API sometimes
returns content blocks as a serialized JSON string rather than
a parsed array. The existing `Array.isArray()` check missed this
case and fell through to `String()`, displaying raw JSON.

Now the Task tool result handler tries to JSON.parse string content
before checking for array structure, matching the pattern already
used by exit_plan_mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
vadymtrunov
2026-02-15 11:43:43 +01:00
committed by Haileyesus
parent c55e996f3a
commit 29b80b1905

View File

@@ -436,16 +436,28 @@ export const TOOL_CONFIGS: Record<string, ToolDisplayConfig> = {
getContentProps: (result) => {
// Handle agent results which may have complex structure
if (result && result.content) {
let content = result.content;
// If content is a JSON string, try to parse it (agent results may arrive serialized)
if (typeof content === 'string') {
try {
const parsed = JSON.parse(content);
if (Array.isArray(parsed)) {
content = parsed;
}
} catch {
// Not JSON — use as-is
return { content };
}
}
// If content is an array (typical for agent responses with multiple text blocks)
if (Array.isArray(result.content)) {
const textContent = result.content
if (Array.isArray(content)) {
const textContent = content
.filter((item: any) => item.type === 'text')
.map((item: any) => item.text)
.join('\n\n');
return { content: textContent || 'No response text' };
}
// If content is already a string
return { content: String(result.content) };
return { content: String(content) };
}
// Fallback to string representation
return { content: String(result || 'No response') };