diff --git a/packages/web-shell/client/components/messages/ToolGroup.test.tsx b/packages/web-shell/client/components/messages/ToolGroup.test.tsx index 3bfd630583..1b96635806 100644 --- a/packages/web-shell/client/components/messages/ToolGroup.test.tsx +++ b/packages/web-shell/client/components/messages/ToolGroup.test.tsx @@ -13,6 +13,7 @@ vi.mock('../../App', async () => { const { buildUnifiedDiff, + extractDiff, formatToolGroupSummary, getActiveTool, getRawFileDiff, @@ -184,6 +185,32 @@ describe('tool output logic', () => { ).toBe(''); }); + it('prefers raw fileDiff over content old/new text', () => { + const fileDiff = + 'Index: file.ts\n@@ -10,1 +10,2 @@\n old context\n+precise line'; + + expect( + extractDiff( + makeTool({ + toolName: 'edit', + content: [ + { + type: 'diff', + oldText: 'full old text', + newText: 'full new text', + }, + ], + rawOutput: { + fileDiff, + fileName: 'file.ts', + originalContent: 'full old text', + newContent: 'full new text', + }, + }), + ), + ).toBe(fileDiff); + }); + it('builds a unified diff for changed content blocks', () => { expect(buildUnifiedDiff('same\nold', 'same\nnew')).toBe( ' same\n-old\n+new', diff --git a/packages/web-shell/client/components/messages/ToolGroup.tsx b/packages/web-shell/client/components/messages/ToolGroup.tsx index 7d5efc64e9..802a5b0c28 100644 --- a/packages/web-shell/client/components/messages/ToolGroup.tsx +++ b/packages/web-shell/client/components/messages/ToolGroup.tsx @@ -110,14 +110,18 @@ function hasEditContent(tool: ACPToolCall): boolean { return hasDiffContent(tool) || !!extractText(tool); } -function extractDiff(tool: ACPToolCall): string { +export function extractDiff(tool: ACPToolCall): string { + const rawFileDiff = getRawFileDiff(tool); + if (rawFileDiff) return rawFileDiff; + if (tool.content) { const diffBlock = tool.content.find((b) => b.type === 'diff'); if (diffBlock && diffBlock.type === 'diff') { return buildUnifiedDiff(diffBlock.oldText || '', diffBlock.newText || ''); } } - return getRawFileDiff(tool); + + return ''; } export function getRawFileDiff(tool: ACPToolCall): string {