@@ -95,9 +95,9 @@ const ToolCallMessage: React.FC<{
9595 ( ) => getToolCallView ( message , toolUpdates , toolResult ) ,
9696 [ message , toolResult , toolUpdates ] ,
9797 ) ;
98- const primaryDiff = toolCallView . diffs [ 0 ] ;
99- const toggleLabel = primaryDiff ? getFileNameFromPath ( primaryDiff . path ) : displayCommand ;
100- const toggleStats = primaryDiff ? countDiffLines ( primaryDiff . oldText , primaryDiff . newText ) : undefined ;
98+ const diffFileNames = getToolCallFileNames ( toolCallView . diffs ) ;
99+ const toggleLabel = formatToolCallLabel ( diffFileNames , displayCommand ) ;
100+ const toggleStats = getToolCallStats ( toolCallView . diffs ) ;
101101
102102 return (
103103 < div className = "acp-message acp-message-tool_call" >
@@ -364,6 +364,42 @@ const getFileNameFromPath = (path: string): string => {
364364 return path . split ( '/' ) . pop ( ) ?? path ;
365365} ;
366366
367+ const formatToolCallLabel = ( diffPaths : string [ ] , fallbackLabel : string ) : string => {
368+ if ( diffPaths . length === 0 ) {
369+ return fallbackLabel ;
370+ }
371+
372+ if ( diffPaths . length === 1 ) {
373+ return getFileNameFromPath ( diffPaths [ 0 ] ) ;
374+ }
375+
376+ const visibleNames = diffPaths . slice ( 0 , 2 ) . map ( getFileNameFromPath ) ;
377+ const hiddenCount = diffPaths . length - visibleNames . length ;
378+ return hiddenCount > 0
379+ ? `${ visibleNames . join ( ', ' ) } +${ hiddenCount } `
380+ : visibleNames . join ( ', ' ) ;
381+ } ;
382+
383+ const getToolCallStats = ( diffs : AcpDiffContent [ ] ) => {
384+ if ( diffs . length === 0 ) {
385+ return undefined ;
386+ }
387+
388+ return diffs . reduce (
389+ ( acc , diff ) => {
390+ const diffStats = countDiffLines ( diff . oldText , diff . newText ) ;
391+ acc . added += diffStats . added ;
392+ acc . deleted += diffStats . deleted ;
393+ return acc ;
394+ } ,
395+ { added : 0 , deleted : 0 } ,
396+ ) ;
397+ } ;
398+
399+ const getToolCallFileNames = ( diffs : AcpDiffContent [ ] ) : string [ ] => {
400+ return Array . from ( new Set ( diffs . map ( ( diff ) => getFileNameFromPath ( diff . path ) ) ) ) ;
401+ } ;
402+
367403const asRecord = ( value : unknown ) : Record < string , unknown > | undefined => {
368404 return typeof value === 'object' && value !== null ? value as Record < string , unknown > : undefined ;
369405} ;
0 commit comments