From 93999e45e7e13760e6b753f5187aa7cc7b56eb53 Mon Sep 17 00:00:00 2001 From: "mingholy.lmh" Date: Wed, 12 Nov 2025 14:44:12 +0800 Subject: [PATCH] fix: subagent tool result parsing --- .vscode/launch.json | 11 ++++++++++- packages/core/src/subagents/subagent-events.ts | 1 + packages/core/src/subagents/subagent.ts | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1966371c..d98757fb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -73,7 +73,16 @@ "request": "launch", "name": "Launch CLI Non-Interactive", "runtimeExecutable": "npm", - "runtimeArgs": ["run", "start", "--", "-p", "${input:prompt}", "-y"], + "runtimeArgs": [ + "run", + "start", + "--", + "-p", + "${input:prompt}", + "-y", + "--output-format", + "stream-json" + ], "skipFiles": ["/**"], "cwd": "${workspaceFolder}", "console": "integratedTerminal", diff --git a/packages/core/src/subagents/subagent-events.ts b/packages/core/src/subagents/subagent-events.ts index cd24998a..eb318f54 100644 --- a/packages/core/src/subagents/subagent-events.ts +++ b/packages/core/src/subagents/subagent-events.ts @@ -74,6 +74,7 @@ export interface SubAgentToolResultEvent { success: boolean; error?: string; responseParts?: Part[]; + resultDisplay?: string; durationMs?: number; timestamp: number; } diff --git a/packages/core/src/subagents/subagent.ts b/packages/core/src/subagents/subagent.ts index e68f77a5..7d161b10 100644 --- a/packages/core/src/subagents/subagent.ts +++ b/packages/core/src/subagents/subagent.ts @@ -620,6 +620,17 @@ export class SubAgentScope { success, error: errorMessage, responseParts: call.response.responseParts, + /** + * Tools like todoWrite will add some extra contents to the result, + * making it unable to deserialize the `responseParts` to a JSON object. + * While `resultDisplay` is normally a string, if not we stringify it, + * so that we can deserialize it to a JSON object when needed. + */ + resultDisplay: call.response.resultDisplay + ? typeof call.response.resultDisplay === 'string' + ? call.response.resultDisplay + : JSON.stringify(call.response.resultDisplay) + : undefined, durationMs: duration, timestamp: Date.now(), } as SubAgentToolResultEvent);