fix(web-shell): prefer raw file diffs in tool output (#5992)

Co-authored-by: ytahdn <ytahdn@gmail.com>
This commit is contained in:
ytahdn 2026-06-29 16:00:16 +08:00 committed by GitHub
parent 23830a180b
commit b737364892
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 2 deletions

View file

@ -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',

View file

@ -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 {