Skip to content

Commit 51ac5a5

Browse files
committed
Better rendering for search_files args
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent 5639401 commit 51ac5a5

2 files changed

Lines changed: 46 additions & 14 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package tool
2+
3+
import (
4+
"encoding/json"
5+
"strings"
6+
7+
"github.com/docker/cagent/pkg/tools"
8+
"github.com/docker/cagent/pkg/tools/builtin"
9+
)
10+
11+
func render_search_files(toolCall tools.ToolCall) string {
12+
var args builtin.SearchFilesArgs
13+
if err := json.Unmarshal([]byte(toolCall.Function.Arguments), &args); err != nil {
14+
return ""
15+
}
16+
17+
// Search pattern
18+
output := args.Pattern
19+
20+
// Optional search path
21+
if path := args.Path; path != "" && path != "." {
22+
output += " in " + path
23+
}
24+
25+
// Optional exclude patterns
26+
if exclude := args.ExcludePatterns; len(exclude) > 0 {
27+
output += " excluding [" + strings.Join(exclude, ", ") + "]"
28+
}
29+
30+
return output
31+
}

internal/tui/components/tool/tool.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,31 @@ func (mv *toolModel) View() string {
8585
return mv.Render(mv.width)
8686
}
8787

88-
// MessageView specific methods
89-
9088
// Render renders the message view content
9189
func (mv *toolModel) Render(width int) string {
9290
msg := mv.message
9391

94-
// Add spinner for pending and running tools
95-
var spinnerText string
96-
if msg.ToolStatus == types.ToolStatusPending || msg.ToolStatus == types.ToolStatusRunning {
97-
spinnerText = " " + mv.spinner.View()
98-
}
99-
10092
// Ask the tool what's its display name
10193
team := mv.app.Team()
10294
agent := team.Agent(msg.Sender)
10395
displayName := agent.ToolDisplayName(context.TODO(), msg.ToolCall.Function.Name)
104-
content := fmt.Sprintf("%s %s%s", icon(msg.ToolStatus), styles.HighlightStyle.Render(displayName), spinnerText)
96+
content := fmt.Sprintf("%s %s", icon(msg.ToolStatus), styles.HighlightStyle.Render(displayName))
10597

10698
if msg.ToolCall.Function.Arguments != "" {
107-
lines := wrapLines(msg.ToolCall.Function.Arguments, mv.width-2)
108-
argsViewport := viewport.New(viewport.WithWidth(mv.width), viewport.WithHeight(len(lines)))
109-
argsViewport.SetContent(styles.MutedStyle.Render(strings.Join(lines, "\n")))
110-
argsViewport.GotoBottom()
111-
content += "\n" + argsViewport.View()
99+
if msg.ToolCall.Function.Name == "search_files" {
100+
content += " " + render_search_files(msg.ToolCall)
101+
} else {
102+
lines := wrapLines(msg.ToolCall.Function.Arguments, mv.width-2)
103+
argsViewport := viewport.New(viewport.WithWidth(mv.width), viewport.WithHeight(len(lines)))
104+
argsViewport.SetContent(styles.MutedStyle.Render(strings.Join(lines, "\n")))
105+
argsViewport.GotoBottom()
106+
content += "\n" + argsViewport.View()
107+
}
108+
}
109+
110+
// Add spinner for pending and running tools
111+
if msg.ToolStatus == types.ToolStatusPending || msg.ToolStatus == types.ToolStatusRunning {
112+
content += " " + mv.spinner.View()
112113
}
113114

114115
// Add tool result content if available (for completed tools with content)

0 commit comments

Comments
 (0)