fix: subagent tool result parsing

This commit is contained in:
mingholy.lmh
2025-11-12 14:44:12 +08:00
parent 4324ba4686
commit 93999e45e7
3 changed files with 22 additions and 1 deletions

11
.vscode/launch.json vendored
View File

@@ -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": ["<node_internals>/**"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",

View File

@@ -74,6 +74,7 @@ export interface SubAgentToolResultEvent {
success: boolean;
error?: string;
responseParts?: Part[];
resultDisplay?: string;
durationMs?: number;
timestamp: number;
}

View File

@@ -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);