@@ -282,12 +282,20 @@ func (u *TerminalUI) handleMessage(msg *api.Message) {
282282 klog .Errorf ("Failed to get TTY reader: %v" , err )
283283 return
284284 }
285- fmt .Print ("\n >>> " ) // Print prompt manually
286- query , err = tReader .ReadString ('\n' )
287- if err != nil {
288- klog .Errorf ("Error reading from TTY: %v" , err )
289- u .agent .Input <- fmt .Errorf ("error reading from TTY: %w" , err )
290- return
285+ // keep reading input until we get a non-empty query
286+ for {
287+ var err error
288+ fmt .Print ("\n >>> " ) // Print prompt manually
289+ query , err = tReader .ReadString ('\n' )
290+ if err != nil {
291+ klog .Errorf ("Error reading from TTY: %v" , err )
292+ u .agent .Input <- fmt .Errorf ("error reading from TTY: %w" , err )
293+ return
294+ }
295+ if strings .TrimSpace (query ) == "" {
296+ continue
297+ }
298+ break
291299 }
292300 klog .Infof ("Sending TTY input to agent: %q" , query )
293301 u .agent .Input <- & api.UserInputResponse {Query : query }
@@ -298,21 +306,28 @@ func (u *TerminalUI) handleMessage(msg *api.Message) {
298306 u .agent .Input <- fmt .Errorf ("error creating readline instance: %w" , err )
299307 return
300308 }
301- rlInstance .SetPrompt (">>> " ) // Ensure correct prompt
302- query , err = rlInstance .Readline ()
303- if err != nil {
304- klog .Infof ("Readline error: %v" , err )
305- switch err {
306- case readline .ErrInterrupt : // Handle Ctrl+C
307- u .agent .Input <- io .EOF
308- case io .EOF : // Handle Ctrl+D
309- u .agent .Input <- io .EOF
310- default :
311- u .agent .Input <- err
309+ // keep reading input until we get a non-empty query
310+ for {
311+ rlInstance .SetPrompt (">>> " ) // Ensure correct prompt
312+ query , err = rlInstance .Readline ()
313+ if err != nil {
314+ klog .Infof ("Readline error: %v" , err )
315+ switch err {
316+ case readline .ErrInterrupt : // Handle Ctrl+C
317+ u .agent .Input <- io .EOF
318+ case io .EOF : // Handle Ctrl+D
319+ u .agent .Input <- io .EOF
320+ default :
321+ u .agent .Input <- err
322+ }
323+ break
324+ }
325+ if strings .TrimSpace (query ) == "" {
326+ continue
312327 }
313- } else {
314328 klog .Infof ("Sending readline input to agent: %q" , query )
315329 u .agent .Input <- & api.UserInputResponse {Query : query }
330+ break
316331 }
317332 }
318333 if query == "clear" || query == "reset" {
0 commit comments