on main help sign in
chore: implement agent tool
b6c792bKujtim Hoxha
internal/tui/components/chat/messages/messages.go+1−1
@@ -164,7 +164,7 @@ func (m *messageCmp) renderUserMessage() string {
164 parts = append(parts, "", strings.Join(attachments, ""))
164 parts = append(parts, "", strings.Join(attachments, ""))
165 }
165 }
166 joined := lipgloss.JoinVertical(lipgloss.Left, parts...)
166 joined := lipgloss.JoinVertical(lipgloss.Left, parts...)
167− return m.style().MarginBottom(1).Render(joined)
167+ return m.style().Render(joined)
168}
168}
169
169
170// toMarkdown converts text content to rendered markdown using the configured renderer
170// toMarkdown converts text content to rendered markdown using the configured renderer
internal/tui/components/chat/messages/renderer.go+52−14
@@ -111,8 +111,18 @@ func (br baseRenderer) unmarshalParams(input string, target any) error {
111 return json.Unmarshal([]byte(input), target)
111 return json.Unmarshal([]byte(input), target)
112}
112}
113
113
114+// makeHeader builds the tool call header with status icon and parameters for a nested tool call.
115+func (br baseRenderer) makeNestedHeader(v *toolCallCmp, tool string, width int, params ...string) string {
116+ t := styles.CurrentTheme()
117+ tool = t.S().Base.Foreground(t.FgHalfMuted).Render(tool) + " "
118+ return tool + renderParamList(true, width-lipgloss.Width(tool), params...)
119+}
120+
114// makeHeader builds "<Tool>: param (key=value)" and truncates as needed.
121// makeHeader builds "<Tool>: param (key=value)" and truncates as needed.
115func (br baseRenderer) makeHeader(v *toolCallCmp, tool string, width int, params ...string) string {
122func (br baseRenderer) makeHeader(v *toolCallCmp, tool string, width int, params ...string) string {
123+ if v.isNested {
124+ return br.makeNestedHeader(v, tool, width, params...)
125+ }
116 t := styles.CurrentTheme()
126 t := styles.CurrentTheme()
117 icon := t.S().Base.Foreground(t.GreenDark).Render(styles.ToolPending)
127 icon := t.S().Base.Foreground(t.GreenDark).Render(styles.ToolPending)
118 if v.result.ToolCallID != "" {
128 if v.result.ToolCallID != "" {
@@ -126,7 +136,7 @@ func (br baseRenderer) makeHeader(v *toolCallCmp, tool string, width int, params
126 }
136 }
127 tool = t.S().Base.Foreground(t.Blue).Render(tool)
137 tool = t.S().Base.Foreground(t.Blue).Render(tool)
128 prefix := fmt.Sprintf("%s %s ", icon, tool)
138 prefix := fmt.Sprintf("%s %s ", icon, tool)
129− return prefix + renderParamList(width-lipgloss.Width(prefix), params...)
139+ return prefix + renderParamList(false, width-lipgloss.Width(prefix), params...)
130}
140}
131
141
132// renderError provides consistent error rendering
142// renderError provides consistent error rendering
@@ -477,25 +487,45 @@ type agentRenderer struct {
477 baseRenderer
487 baseRenderer
478}
488}
479
489
490+func RoundedEnumerator(children tree.Children, index int) string {
491+ if children.Length()-1 == index {
492+ return " ╰──"
493+ }
494+ return " ├──"
495+}
496+
480// Render displays agent task parameters and result content
497// Render displays agent task parameters and result content
481func (tr agentRenderer) Render(v *toolCallCmp) string {
498func (tr agentRenderer) Render(v *toolCallCmp) string {
499+ t := styles.CurrentTheme()
482 var params agent.AgentParams
500 var params agent.AgentParams
483 if err := tr.unmarshalParams(v.call.Input, &params); err != nil {
501 if err := tr.unmarshalParams(v.call.Input, &params); err != nil {
484 return tr.renderError(v, "Invalid task parameters")
502 return tr.renderError(v, "Invalid task parameters")
485 }
503 }
486 prompt := params.Prompt
504 prompt := params.Prompt
487 prompt = strings.ReplaceAll(prompt, "\n", " ")
505 prompt = strings.ReplaceAll(prompt, "\n", " ")
488− args := newParamBuilder().addMain(prompt).build()
489
506
490− header := tr.makeHeader(v, "Task", v.textWidth(), args...)
507+ header := tr.makeHeader(v, "Agent", v.textWidth())
508+ taskTag := t.S().Base.Padding(0, 1).MarginLeft(1).Background(t.BlueLight).Foreground(t.White).Render("Task")
509+ remainingWidth := v.textWidth() - lipgloss.Width(header) - lipgloss.Width(taskTag) - 2 // -2 for padding
510+ prompt = t.S().Muted.Width(remainingWidth).Render(prompt)
511+ header = lipgloss.JoinVertical(
512+ lipgloss.Left,
513+ header,
514+ "",
515+ lipgloss.JoinHorizontal(
516+ lipgloss.Left,
517+ taskTag,
518+ " ",
519+ prompt,
520+ ),
521+ )
491− t := tree.Root(header)
522+ childTools := tree.Root(header)
492
523
493 for _, call := range v.nestedToolCalls {
524 for _, call := range v.nestedToolCalls {
494− t.Child(call.View())
525+ childTools.Child(call.View())
495 }
526 }
496−
497 parts := []string{
527 parts := []string{
498− t.Enumerator(tree.RoundedEnumerator).String(),
528+ childTools.Enumerator(RoundedEnumerator).String(),
499 }
529 }
500 if v.result.ToolCallID == "" {
530 if v.result.ToolCallID == "" {
501 v.spinning = true
531 v.spinning = true
@@ -518,7 +548,7 @@ func (tr agentRenderer) Render(v *toolCallCmp) string {
518}
548}
519
549
520// renderParamList renders params, params[0] (params[1]=params[2] ....)
550// renderParamList renders params, params[0] (params[1]=params[2] ....)
521−func renderParamList(paramsWidth int, params ...string) string {
551+func renderParamList(nested bool, paramsWidth int, params ...string) string {
522 t := styles.CurrentTheme()
552 t := styles.CurrentTheme()
523 if len(params) == 0 {
553 if len(params) == 0 {
524 return ""
554 return ""
@@ -529,6 +559,9 @@ func renderParamList(paramsWidth int, params ...string) string {
529 }
559 }
530
560
531 if len(params) == 1 {
561 if len(params) == 1 {
562+ if nested {
563+ return t.S().Muted.Render(mainParam)
564+ }
532 return t.S().Subtle.Render(mainParam)
565 return t.S().Subtle.Render(mainParam)
533 }
566 }
534 otherParams := params[1:]
567 otherParams := params[1:]
@@ -550,6 +583,9 @@ func renderParamList(paramsWidth int, params ...string) string {
550 partsRendered := strings.Join(parts, ", ")
583 partsRendered := strings.Join(parts, ", ")
551 remainingWidth := paramsWidth - lipgloss.Width(partsRendered) - 3 // count for " ()"
584 remainingWidth := paramsWidth - lipgloss.Width(partsRendered) - 3 // count for " ()"
552 if remainingWidth < 30 {
585 if remainingWidth < 30 {
586+ if nested {
587+ return t.S().Muted.Render(mainParam)
588+ }
553 // No space for the params, just show the main
589 // No space for the params, just show the main
554 return t.S().Subtle.Render(mainParam)
590 return t.S().Subtle.Render(mainParam)
555 }
591 }
@@ -558,6 +594,9 @@ func renderParamList(paramsWidth int, params ...string) string {
558 mainParam = fmt.Sprintf("%s (%s)", mainParam, strings.Join(parts, ", "))
594 mainParam = fmt.Sprintf("%s (%s)", mainParam, strings.Join(parts, ", "))
559 }
595 }
560
596
597+ if nested {
598+ return t.S().Muted.Render(ansi.Truncate(mainParam, paramsWidth, "..."))
599+ }
561 return t.S().Subtle.Render(ansi.Truncate(mainParam, paramsWidth, "..."))
600 return t.S().Subtle.Render(ansi.Truncate(mainParam, paramsWidth, "..."))
562}
601}
563
602
@@ -635,7 +674,7 @@ func renderCodeContent(v *toolCallCmp, path, content string, offset int) string
635 if len(strings.Split(content, "\n")) > responseContextHeight {
674 if len(strings.Split(content, "\n")) > responseContextHeight {
636 lines = append(lines, t.S().Muted.
675 lines = append(lines, t.S().Muted.
637 Background(t.BgBase).
676 Background(t.BgBase).
638− Render(fmt.Sprintf(" ... (%d lines)", len(strings.Split(content, "\n"))-responseContextHeight)))
677+ Render(fmt.Sprintf(" …(%d lines)", len(strings.Split(content, "\n"))-responseContextHeight)))
639 }
678 }
640
679
641 maxLineNumber := len(lines) + offset
680 maxLineNumber := len(lines) + offset
@@ -647,13 +686,12 @@ func renderCodeContent(v *toolCallCmp, path, content string, offset int) string
647 PaddingRight(1).
686 PaddingRight(1).
648 PaddingLeft(1).
687 PaddingLeft(1).
649 Render(pad(i+1+offset, padding))
688 Render(pad(i+1+offset, padding))
650− w := v.textWidth() - 2 - lipgloss.Width(num) // -2 for left padding
689+ w := v.textWidth() - 10 - lipgloss.Width(num) // -4 for left padding
651 lines[i] = lipgloss.JoinHorizontal(lipgloss.Left,
690 lines[i] = lipgloss.JoinHorizontal(lipgloss.Left,
652 num,
691 num,
653 t.S().Base.
692 t.S().Base.
654 PaddingLeft(1).
693 PaddingLeft(1).
655− Width(w).
656− Render(v.fit(ln, w)))
694+ Render(v.fit(ln, w-1)))
657 }
695 }
658 return lipgloss.JoinVertical(lipgloss.Left, lines...)
696 return lipgloss.JoinVertical(lipgloss.Left, lines...)
659}
697}
@@ -662,7 +700,7 @@ func (v *toolCallCmp) renderToolError() string {
662 t := styles.CurrentTheme()
700 t := styles.CurrentTheme()
663 err := strings.ReplaceAll(v.result.Content, "\n", " ")
701 err := strings.ReplaceAll(v.result.Content, "\n", " ")
664 err = fmt.Sprintf("Error: %s", err)
702 err = fmt.Sprintf("Error: %s", err)
665− return t.S().Base.Foreground(t.Error).Render(v.fit(err, v.textWidth()))
703+ return t.S().Base.Foreground(t.Error).Render(v.fit(err, v.textWidth()-2))
666}
704}
667
705
668func truncateHeight(s string, h int) string {
706func truncateHeight(s string, h int) string {
@@ -676,7 +714,7 @@ func truncateHeight(s string, h int) string {
676func prettifyToolName(name string) string {
714func prettifyToolName(name string) string {
677 switch name {
715 switch name {
678 case agent.AgentToolName:
716 case agent.AgentToolName:
679− return "Task"
717+ return "Agent"
680 case tools.BashToolName:
718 case tools.BashToolName:
681 return "Bash"
719 return "Bash"
682 case tools.EditToolName:
720 case tools.EditToolName:
internal/tui/components/chat/messages/tool.go+9−2
@@ -207,6 +207,10 @@ func (m *toolCallCmp) SetIsNested(isNested bool) {
207// renderPending displays the tool name with a loading animation for pending tool calls
207// renderPending displays the tool name with a loading animation for pending tool calls
208func (m *toolCallCmp) renderPending() string {
208func (m *toolCallCmp) renderPending() string {
209 t := styles.CurrentTheme()
209 t := styles.CurrentTheme()
210+ if m.isNested {
211+ tool := t.S().Base.Foreground(t.FgHalfMuted).Render(prettifyToolName(m.call.Name))
212+ return fmt.Sprintf("%s %s", tool, m.anim.View())
213+ }
210 icon := t.S().Base.Foreground(t.GreenDark).Render(styles.ToolPending)
214 icon := t.S().Base.Foreground(t.GreenDark).Render(styles.ToolPending)
211 tool := t.S().Base.Foreground(t.Blue).Render(prettifyToolName(m.call.Name))
215 tool := t.S().Base.Foreground(t.Blue).Render(prettifyToolName(m.call.Name))
212 return fmt.Sprintf("%s %s %s", icon, tool, m.anim.View())
216 return fmt.Sprintf("%s %s %s", icon, tool, m.anim.View())
@@ -226,14 +230,17 @@ func (m *toolCallCmp) style() lipgloss.Style {
226// textWidth calculates the available width for text content,
230// textWidth calculates the available width for text content,
227// accounting for borders and padding
231// accounting for borders and padding
228func (m *toolCallCmp) textWidth() int {
232func (m *toolCallCmp) textWidth() int {
233+ if m.isNested {
234+ return m.width - 6
235+ }
229 return m.width - 5 // take into account the border and PaddingLeft
236 return m.width - 5 // take into account the border and PaddingLeft
230}
237}
231
238
232// fit truncates content to fit within the specified width with ellipsis
239// fit truncates content to fit within the specified width with ellipsis
233func (m *toolCallCmp) fit(content string, width int) string {
240func (m *toolCallCmp) fit(content string, width int) string {
234 t := styles.CurrentTheme()
241 t := styles.CurrentTheme()
235− lineStyle := t.S().Muted.Background(t.BgSubtle)
242+ lineStyle := t.S().Muted
236− dots := lineStyle.Render("...")
243+ dots := lineStyle.Render("…")
237 return ansi.Truncate(content, width, dots)
244 return ansi.Truncate(content, width, dots)
238}
245}
239
246
internal/tui/components/core/list/keys.go+3−3
@@ -32,10 +32,10 @@ func DefaultKeyMap() KeyMap {
32 key.WithKeys("k"),
32 key.WithKeys("k"),
33 ),
33 ),
34 UpOneItem: key.NewBinding(
34 UpOneItem: key.NewBinding(
35− key.WithKeys("shift+up", "shift+k"),
35+ key.WithKeys("shift+up", "K"),
36 ),
36 ),
37 DownOneItem: key.NewBinding(
37 DownOneItem: key.NewBinding(
38− key.WithKeys("shift+down", "shift+j"),
38+ key.WithKeys("shift+down", "J"),
39 ),
39 ),
40 HalfPageDown: key.NewBinding(
40 HalfPageDown: key.NewBinding(
41 key.WithKeys("d"),
41 key.WithKeys("d"),
@@ -47,7 +47,7 @@ func DefaultKeyMap() KeyMap {
47 key.WithKeys("g", "home"),
47 key.WithKeys("g", "home"),
48 ),
48 ),
49 End: key.NewBinding(
49 End: key.NewBinding(
50− key.WithKeys("shift+g", "end"),
50+ key.WithKeys("G", "end"),
51 ),
51 ),
52 }
52 }
53}
53}
internal/tui/styles/crush.go+2−1
@@ -39,7 +39,8 @@ func NewCrushTheme() *Theme {
39 // Colors
39 // Colors
40 White: charmtone.Butter,
40 White: charmtone.Butter,
41
41
42− Blue: charmtone.Malibu,
42+ BlueLight: charmtone.Sardine,
43+ Blue: charmtone.Malibu,
43
44
44 Yellow: charmtone.Mustard,
45 Yellow: charmtone.Mustard,
45
46
internal/tui/styles/theme.go+2−1
@@ -56,7 +56,8 @@ type Theme struct {
56 White color.Color
56 White color.Color
57
57
58 // Blues
58 // Blues
59− Blue color.Color
59+ BlueLight color.Color
60+ Blue color.Color
60
61
61 // Yellows
62 // Yellows
62 Yellow color.Color
63 Yellow color.Color