@@ -337,124 +337,132 @@ func renderToolDetails(
337337 borderColor = t .BorderActive ()
338338 }
339339
340- metadata := toolCall .State .Metadata .(map [string ]any )
341- switch toolCall .Tool {
342- case "read" :
343- preview := metadata ["preview" ]
344- if preview != nil && toolInputMap ["filePath" ] != nil {
345- filename := toolInputMap ["filePath" ].(string )
346- body = preview .(string )
347- body = util .RenderFile (filename , body , width , util .WithTruncate (6 ))
348- }
349- case "edit" :
350- if filename , ok := toolInputMap ["filePath" ].(string ); ok {
351- diffField := metadata ["diff" ]
352- if diffField != nil {
353- patch := diffField .(string )
354- var formattedDiff string
355- formattedDiff , _ = diff .FormatUnifiedDiff (
356- filename ,
357- patch ,
358- diff .WithWidth (width - 2 ),
359- )
360- body = strings .TrimSpace (formattedDiff )
361- style := styles .NewStyle ().
362- Background (backgroundColor ).
363- Foreground (t .TextMuted ()).
364- Padding (1 , 2 ).
365- Width (width - 4 )
366- if highlight {
367- style = style .Foreground (t .Text ()).Bold (true )
340+ if toolCall .State .Metadata != nil {
341+ metadata := toolCall .State .Metadata .(map [string ]any )
342+ switch toolCall .Tool {
343+ case "read" :
344+ var preview any
345+ if metadata != nil {
346+ preview = metadata ["preview" ]
347+ }
348+ if preview != nil && toolInputMap ["filePath" ] != nil {
349+ filename := toolInputMap ["filePath" ].(string )
350+ body = preview .(string )
351+ body = util .RenderFile (filename , body , width , util .WithTruncate (6 ))
352+ }
353+ case "edit" :
354+ if filename , ok := toolInputMap ["filePath" ].(string ); ok {
355+ var diffField any
356+ if metadata != nil {
357+ diffField = metadata ["diff" ]
368358 }
369-
370- if diagnostics := renderDiagnostics (metadata , filename ); diagnostics != "" {
371- diagnostics = style .Render (diagnostics )
372- body += "\n " + diagnostics
359+ if diffField != nil {
360+ patch := diffField .(string )
361+ var formattedDiff string
362+ formattedDiff , _ = diff .FormatUnifiedDiff (
363+ filename ,
364+ patch ,
365+ diff .WithWidth (width - 2 ),
366+ )
367+ body = strings .TrimSpace (formattedDiff )
368+ style := styles .NewStyle ().
369+ Background (backgroundColor ).
370+ Foreground (t .TextMuted ()).
371+ Padding (1 , 2 ).
372+ Width (width - 4 )
373+ if highlight {
374+ style = style .Foreground (t .Text ()).Bold (true )
375+ }
376+
377+ if diagnostics := renderDiagnostics (metadata , filename ); diagnostics != "" {
378+ diagnostics = style .Render (diagnostics )
379+ body += "\n " + diagnostics
380+ }
381+
382+ title := renderToolTitle (toolCall , width )
383+ title = style .Render (title )
384+ content := title + "\n " + body
385+ content = renderContentBlock (
386+ app ,
387+ content ,
388+ highlight ,
389+ width ,
390+ WithPadding (0 ),
391+ WithBorderColor (borderColor ),
392+ )
393+ return content
373394 }
374-
375- title := renderToolTitle (toolCall , width )
376- title = style .Render (title )
377- content := title + "\n " + body
378- content = renderContentBlock (
379- app ,
380- content ,
381- highlight ,
382- width ,
383- WithPadding (0 ),
384- WithBorderColor (borderColor ),
385- )
386- return content
387395 }
388- }
389- case "write" :
390- if filename , ok := toolInputMap ["filePath " ].(string ); ok {
391- if content , ok := toolInputMap [ "content" ].( string ); ok {
392- body = util . RenderFile ( filename , content , width )
393- if diagnostics := renderDiagnostics ( metadata , filename ); diagnostics != "" {
394- body += " \n \n " + diagnostics
396+ case "write" :
397+ if filename , ok := toolInputMap [ "filePath" ].( string ); ok {
398+ if content , ok := toolInputMap ["content " ].(string ); ok {
399+ body = util . RenderFile ( filename , content , width )
400+ if diagnostics := renderDiagnostics ( metadata , filename ); diagnostics != "" {
401+ body += " \n \n " + diagnostics
402+ }
395403 }
396404 }
397- }
398- case "bash" :
399- stdout := metadata ["stdout" ]
400- if stdout != nil {
401- command := toolInputMap ["command" ].(string )
402- body = fmt .Sprintf ("```console\n > %s\n %s```" , command , stdout )
403- body = util .ToMarkdown (body , width , backgroundColor )
404- }
405- case "webfetch" :
406- if format , ok := toolInputMap ["format" ].(string ); ok && result != nil {
407- body = * result
408- body = util .TruncateHeight (body , 10 )
409- if format == "html" || format == "markdown" {
405+ case "bash" :
406+ stdout := metadata ["stdout" ]
407+ if stdout != nil {
408+ command := toolInputMap ["command" ].(string )
409+ body = fmt .Sprintf ("```console\n > %s\n %s```" , command , stdout )
410410 body = util .ToMarkdown (body , width , backgroundColor )
411411 }
412- }
413- case "todowrite" :
414- todos := metadata ["todos" ]
415- if todos != nil {
416- for _ , item := range todos .([]any ) {
417- todo := item .(map [string ]any )
418- content := todo ["content" ].(string )
419- switch todo ["status" ] {
420- case "completed" :
421- body += fmt .Sprintf ("- [x] %s\n " , content )
422- case "cancelled" :
423- // strike through cancelled todo
424- body += fmt .Sprintf ("- [~] ~~%s~~\n " , content )
425- case "in_progress" :
426- // highlight in progress todo
427- body += fmt .Sprintf ("- [ ] `%s`\n " , content )
428- default :
429- body += fmt .Sprintf ("- [ ] %s\n " , content )
412+ case "webfetch" :
413+ if format , ok := toolInputMap ["format" ].(string ); ok && result != nil {
414+ body = * result
415+ body = util .TruncateHeight (body , 10 )
416+ if format == "html" || format == "markdown" {
417+ body = util .ToMarkdown (body , width , backgroundColor )
430418 }
431419 }
432- body = util .ToMarkdown (body , width , backgroundColor )
433- }
434- case "task" :
435- summary := metadata ["summary" ]
436- if summary != nil {
437- toolcalls := summary .([]any )
438- steps := []string {}
439- for _ , item := range toolcalls {
440- data , _ := json .Marshal (item )
441- var toolCall opencode.ToolPart
442- _ = json .Unmarshal (data , & toolCall )
443- step := renderToolTitle (toolCall , width )
444- step = "∟ " + step
445- steps = append (steps , step )
420+ case "todowrite" :
421+ todos := metadata ["todos" ]
422+ if todos != nil {
423+ for _ , item := range todos .([]any ) {
424+ todo := item .(map [string ]any )
425+ content := todo ["content" ].(string )
426+ switch todo ["status" ] {
427+ case "completed" :
428+ body += fmt .Sprintf ("- [x] %s\n " , content )
429+ case "cancelled" :
430+ // strike through cancelled todo
431+ body += fmt .Sprintf ("- [~] ~~%s~~\n " , content )
432+ case "in_progress" :
433+ // highlight in progress todo
434+ body += fmt .Sprintf ("- [ ] `%s`\n " , content )
435+ default :
436+ body += fmt .Sprintf ("- [ ] %s\n " , content )
437+ }
438+ }
439+ body = util .ToMarkdown (body , width , backgroundColor )
446440 }
447- body = strings .Join (steps , "\n " )
448- }
449- body = styles .NewStyle ().Width (width - 6 ).Render (body )
450- default :
451- if result == nil {
452- empty := ""
453- result = & empty
441+ case "task" :
442+ summary := metadata ["summary" ]
443+ if summary != nil {
444+ toolcalls := summary .([]any )
445+ steps := []string {}
446+ for _ , item := range toolcalls {
447+ data , _ := json .Marshal (item )
448+ var toolCall opencode.ToolPart
449+ _ = json .Unmarshal (data , & toolCall )
450+ step := renderToolTitle (toolCall , width )
451+ step = "∟ " + step
452+ steps = append (steps , step )
453+ }
454+ body = strings .Join (steps , "\n " )
455+ }
456+ body = styles .NewStyle ().Width (width - 6 ).Render (body )
457+ default :
458+ if result == nil {
459+ empty := ""
460+ result = & empty
461+ }
462+ body = * result
463+ body = util .TruncateHeight (body , 10 )
464+ body = styles .NewStyle ().Width (width - 6 ).Render (body )
454465 }
455- body = * result
456- body = util .TruncateHeight (body , 10 )
457- body = styles .NewStyle ().Width (width - 6 ).Render (body )
458466 }
459467
460468 error := ""
0 commit comments