xonecas.io
62159
Sy

symb / commit 3fa05c2

fix: lint and stuff

xonecas2026-02-17 3fa05c21e1991123f72beddae3802ec047bb231f parent cc2fdca

6 files changed

internal/llm/loop.go+53−34
@@ -113,25 +113,11 @@ type recentCall struct {
113113 }
114114
115115 func ProcessTurn(ctx context.Context, opts ProcessTurnOptions) error {
116- // Enforce max depth to prevent infinite recursion
117- if opts.Depth > MaxDepth {
118- return fmt.Errorf("max sub-agent depth exceeded: %d > %d", opts.Depth, MaxDepth)
119- }
120-
121- if opts.MaxToolRounds == 0 {
122- opts.MaxToolRounds = 60
123- }
124-
125- // Convert MCP tools to provider format once
126- providerTools := make([]provider.Tool, len(opts.Tools))
127- for i, t := range opts.Tools {
128- providerTools[i] = provider.Tool{
129- Name: t.Name,
130- Description: t.Description,
131- Parameters: t.InputSchema,
132- }
116+ if err := normalizeTurnOptions(&opts); err != nil {
117+ return err
133118 }
134119
120+ providerTools := toProviderTools(opts.Tools)
135121 var recent []recentCall
136122 for round := 0; round < opts.MaxToolRounds; round++ {
137123 // Inject a <system-reminder> into the last tool result to keep
@@ -160,30 +146,63 @@ func ProcessTurn(ctx context.Context, opts ProcessTurnOptions) error {
160146 // Execute each tool call and update history
161147 toolResults := executeToolCalls(ctx, opts.Proxy, resp.ToolCalls, opts.OnMessage)
162148 opts.History = append(opts.History, toolResults...)
163-
164- for _, tc := range resp.ToolCalls {
165- recent = append(recent, recentCall{Name: tc.Name, Args: string(tc.Arguments)})
166- }
167- if len(recent) >= 3 {
168- last3 := recent[len(recent)-3:]
169- if last3[0] == last3[1] && last3[1] == last3[2] {
170- if len(toolResults) > 0 {
171- last := &toolResults[len(toolResults)-1]
172- last.Content += "\n\n<system-reminder>WARNING: You are repeating the same tool call with the same arguments. This is wasteful. Stop and either try a different approach, summarize what you know, or ask the user for help.</system-reminder>"
173- opts.History[len(opts.History)-1] = *last
174- }
175- }
176- }
149+ appendRecentCalls(&opts, resp.ToolCalls, toolResults, &recent)
177150
178151 // Continue loop to let LLM process tool results
179152 }
180153
181154 // Tool call limit reached — do one final call with no tools so the LLM
182155 // must reply with text summarizing progress.
156+ return finalizeToolLimit(ctx, &opts)
157+}
158+
159+func normalizeTurnOptions(opts *ProcessTurnOptions) error {
160+ // Enforce max depth to prevent infinite recursion
161+ if opts.Depth > MaxDepth {
162+ return fmt.Errorf("max sub-agent depth exceeded: %d > %d", opts.Depth, MaxDepth)
163+ }
164+ if opts.MaxToolRounds == 0 {
165+ opts.MaxToolRounds = 60
166+ }
167+ return nil
168+}
169+
170+func toProviderTools(tools []mcp.Tool) []provider.Tool {
171+ if len(tools) == 0 {
172+ return nil
173+ }
174+ providerTools := make([]provider.Tool, len(tools))
175+ for i, t := range tools {
176+ providerTools[i] = provider.Tool{
177+ Name: t.Name,
178+ Description: t.Description,
179+ Parameters: t.InputSchema,
180+ }
181+ }
182+ return providerTools
183+}
184+
185+func appendRecentCalls(opts *ProcessTurnOptions, toolCalls []provider.ToolCall, toolResults []provider.Message, recent *[]recentCall) {
186+ for _, tc := range toolCalls {
187+ *recent = append(*recent, recentCall{Name: tc.Name, Args: string(tc.Arguments)})
188+ }
189+ if len(*recent) < 3 {
190+ return
191+ }
192+ last3 := (*recent)[len(*recent)-3:]
193+ if last3[0] == last3[1] && last3[1] == last3[2] {
194+ if len(toolResults) > 0 && len(opts.History) > 0 {
195+ last := &toolResults[len(toolResults)-1]
196+ last.Content += "\n\n<system-reminder>WARNING: You are repeating the same tool call with the same arguments. This is wasteful. Stop and either try a different approach, summarize what you know, or ask the user for help.</system-reminder>"
197+ opts.History[len(opts.History)-1] = *last
198+ }
199+ }
200+}
201+
202+func finalizeToolLimit(ctx context.Context, opts *ProcessTurnOptions) error {
183203 if err := ctx.Err(); err != nil {
184204 return err
185205 }
186-
187206 limitMsg := provider.Message{
188207 Role: "user",
189208 Content: "You have exhausted your tool call limit for this turn. Respond in text only. Summarize what you accomplished and what remains.",
@@ -194,12 +213,12 @@ func ProcessTurn(ctx context.Context, opts ProcessTurnOptions) error {
194213 }
195214 opts.History = append(opts.History, limitMsg)
196215
197- resp, err := streamAndCollect(ctx, &opts, nil)
216+ resp, err := streamAndCollect(ctx, opts, nil)
198217 if err != nil {
199218 return fmt.Errorf("final text-only LLM stream failed: %w", err)
200219 }
201220
202- emitAssistant(&opts, resp)
221+ emitAssistant(opts, resp)
203222 return nil
204223 }
205224
internal/tui/testdata/TestLayout/120x40/ANSI.golden+40−40
@@ -1,40 +1,40 @@
1- 1   │ 
2- │ 
3- │ 
4- │ 
5- │ 
6- │ 
7- │ 
8- │ 
9- │ 
10- │ 
11- │ 
12- │ 
13- │ 
14- │ 
15- │ 
16- │ 
17- │ 
18- │ 
19- │ 
20- │ 
21- │ 
22- │ 
23- │ 
24- │ 
25- │ 
26- │ 
27- │ 
28- │ 
29- │ 
30- │ 
31- │ 
32- │ 
33- │ 
34- │ 
35- │───────────────────────────────────────────────────────────
36- │What's our task?  
37- │  
38- │  
39-────────────────────────────────────────────────────────────┴───────────────────────────────────────────────────────────
40- test-provider ⠋ 
1+ 1   │ 
2+ │ 
3+ │ 
4+ │ 
5+ │ 
6+ │ 
7+ │ 
8+ │ 
9+ │ 
10+ │ 
11+ │ 
12+ │ 
13+ │ 
14+ │ 
15+ │ 
16+ │ 
17+ │ 
18+ │ 
19+ │ 
20+ │ 
21+ │ 
22+ │ 
23+ │ 
24+ │ 
25+ │ 
26+ │ 
27+ │ 
28+ │ 
29+ │ 
30+ │ 
31+ │ 
32+ │ 
33+ │ 
34+ │ 
35+ │───────────────────────────────────────────────────────────
36+ │Ask anything... (CTRL+h for keybinds)  
37+ │  
38+ │  
39+────────────────────────────────────────────────────────────┴───────────────────────────────────────────────────────────
40+ test-provider ⠋ 
internal/tui/testdata/TestLayout/120x40/Stripped.golden+1−1
@@ -33,7 +33,7 @@
3333 │
3434 │
3535 │───────────────────────────────────────────────────────────
36- │What's our task?
36+ │Ask anything... (CTRL+h for keybinds)
3737 │
3838 │
3939 ────────────────────────────────────────────────────────────┴───────────────────────────────────────────────────────────
internal/tui/testdata/TestLayout/80x24/ANSI.golden+24−24
@@ -1,24 +1,24 @@
1- 1   │ 
2- │ 
3- │ 
4- │ 
5- │ 
6- │ 
7- │ 
8- │ 
9- │ 
10- │ 
11- │ 
12- │ 
13- │ 
14- │ 
15- │ 
16- │ 
17- │ 
18- │ 
19- │───────────────────────────────────────
20- │What's our task?  
21- │  
22- │  
23-────────────────────────────────────────┴───────────────────────────────────────
24- test-provider ⠋ 
1+ 1   │ 
2+ │ 
3+ │ 
4+ │ 
5+ │ 
6+ │ 
7+ │ 
8+ │ 
9+ │ 
10+ │ 
11+ │ 
12+ │ 
13+ │ 
14+ │ 
15+ │ 
16+ │ 
17+ │ 
18+ │ 
19+ │───────────────────────────────────────
20+ │Ask anything... (CTRL+h for keybinds) 
21+ │  
22+ │  
23+────────────────────────────────────────┴───────────────────────────────────────
24+ test-provider ⠋ 
internal/tui/testdata/TestLayout/80x24/Stripped.golden+1−1
@@ -17,7 +17,7 @@
1717 │
1818 │
1919 │───────────────────────────────────────
20- │What's our task?
20+ │Ask anything... (CTRL+h for keybinds)
2121 │
2222 │
2323 ────────────────────────────────────────┴───────────────────────────────────────
internal/tui/tui.go+1−1
@@ -301,7 +301,7 @@ func New(prov provider.Provider, proxy *mcp.Proxy, tools []mcp.Tool, modelID str
301301 ed.DiagWarnStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#e5c07b"))
302302
303303 ai := editor.New()
304- ai.Placeholder = "What's our task?"
304+ ai.Placeholder = "Ask anything... (CTRL+h for keybinds)"
305305 ai.SubmitOnEnter = true
306306 ai.Language = "markdown"
307307 ai.SyntaxTheme = constants.SyntaxTheme