(content: ToolResultContent)
| 28 | } |
| 29 | |
| 30 | export function formatToolResultContent(content: ToolResultContent): string { |
| 31 | switch (content.kind) { |
| 32 | case 'text': |
| 33 | return content.text; |
| 34 | case 'json': |
| 35 | return formatUnknown(content.value); |
| 36 | case 'terminal': |
| 37 | return [ |
| 38 | `$ ${content.cmd}`, |
| 39 | `cwd: ${content.cwd}`, |
| 40 | `status: ${content.status}`, |
| 41 | content.exitCode !== undefined ? `exit: ${content.exitCode}` : '', |
| 42 | formatShellOutput(content.output), |
| 43 | ] |
| 44 | .filter(Boolean) |
| 45 | .join('\n\n'); |
| 46 | case 'shell_run': |
| 47 | return [ |
| 48 | `$ ${content.cmd}`, |
| 49 | `cwd: ${content.cwd}`, |
| 50 | `ref: ${content.ref}`, |
| 51 | `status: ${content.status}`, |
| 52 | content.exitCode !== undefined ? `exit: ${content.exitCode}` : '', |
| 53 | content.output ? formatShellOutput(content.output) : '', |
| 54 | ] |
| 55 | .filter(Boolean) |
| 56 | .join('\n\n'); |
| 57 | case 'file_diff': |
| 58 | return content.diff; |
| 59 | case 'file_write': |
| 60 | return `Wrote ${content.bytes} bytes to ${content.path}`; |
| 61 | case 'summary': |
| 62 | return content.summarized; |
| 63 | case 'image': |
| 64 | return `${content.mimeType} image result`; |
| 65 | case 'web_search': |
| 66 | return [ |
| 67 | `Search ${content.provider}: ${content.query}`, |
| 68 | ...content.rows.map((row) => `${row.title}\n${row.url}\n${row.snippet}`), |
| 69 | ].join('\n\n'); |
| 70 | case 'web_search_error': |
| 71 | return content.message; |
| 72 | case 'explore_agent': |
| 73 | return ( |
| 74 | content.report ?? |
| 75 | content.summary ?? |
| 76 | content.message ?? |
| 77 | `Inspected ${content.filesInspected} files` |
| 78 | ); |
| 79 | case 'subagent': |
| 80 | return content.summary; |
| 81 | case 'agent_swarm': { |
| 82 | const projection = projectAgentSwarmResult(content); |
| 83 | return limitText( |
| 84 | [ |
| 85 | [ |
| 86 | `Agent swarm: ${projection.status}`, |
| 87 | `${projection.itemCount} items`, |
no test coverage detected