@@ -63,7 +63,15 @@ func (m *Manager) ProcessUserMessage(ctx context.Context, message string) bool {
6363 return false
6464 }
6565
66- fmt .Println ("Failed to get response from AI: " + err .Error ())
66+ // Log both to console and debug file to capture error context
67+ errMsg := "Failed to get response from AI: " + err .Error ()
68+ fmt .Println (errMsg )
69+
70+ // Debug the failed request even when there's an error
71+ if m .Config .Debug {
72+ debugChatMessages (append (history , currentMessage ), "ERROR: " + err .Error ())
73+ }
74+
6775 return false
6876 }
6977
@@ -77,7 +85,16 @@ func (m *Manager) ProcessUserMessage(ctx context.Context, message string) bool {
7785 if err != nil {
7886 s .Stop ()
7987 m .Status = ""
80- fmt .Println ("Failed to parse AI response: " + err .Error ())
88+
89+ // Log both to console and debug file
90+ errMsg := "Failed to parse AI response: " + err .Error ()
91+ fmt .Println (errMsg )
92+
93+ // Debug the failed parsing even when there's an error
94+ if m .Config .Debug {
95+ debugChatMessages (append (history , currentMessage ), "PARSE ERROR: " + response )
96+ }
97+
8198 return false
8299 }
83100
@@ -141,24 +158,42 @@ func (m *Manager) ProcessUserMessage(ctx context.Context, message string) bool {
141158 }
142159 }
143160
144- for _ , sendKey := range r .SendKeys {
145- code , _ := system .HighlightCode ("txt" , sendKey )
146- m .Println (code )
161+ // Process SendKeys
162+ if len (r .SendKeys ) > 0 {
163+ // Show preview of all keys
164+ keysPreview := "Keys to send:\n "
165+ for i , sendKey := range r .SendKeys {
166+ code , _ := system .HighlightCode ("txt" , sendKey )
167+ if i == len (r .SendKeys )- 1 {
168+ keysPreview += code
169+ } else {
170+ keysPreview += code + "\n "
171+ }
172+ }
147173
148- isSafe := false
149- command := sendKey
174+ m .Println (keysPreview )
175+
176+ // Determine confirmation message based on number of keys
177+ confirmMessage := "Send this key?"
178+ if len (r .SendKeys ) > 1 {
179+ confirmMessage = "Send all these keys?"
180+ }
181+
182+ // Get confirmation if required
183+ allConfirmed := true
150184 if m .GetSendKeysConfirm () {
151- isSafe , command = m .confirmedToExec (sendKey , "Send this key(s)?" , true )
152- } else {
153- isSafe = true
185+ allConfirmed , _ = m .confirmedToExec ("keys shown above" , confirmMessage , true )
186+ if ! allConfirmed {
187+ m .Status = ""
188+ return false
189+ }
154190 }
155- if isSafe {
156- m .Println ("Sending keys: " + command )
157- system .TmuxSendCommandToPane (m .ExecPane .Id , command , false )
191+
192+ // Send each key with delay
193+ for _ , sendKey := range r .SendKeys {
194+ m .Println ("Sending keys: " + sendKey )
195+ system .TmuxSendCommandToPane (m .ExecPane .Id , sendKey , false )
158196 time .Sleep (1 * time .Second )
159- } else {
160- m .Status = ""
161- return false
162197 }
163198 }
164199
0 commit comments