@@ -21,6 +21,7 @@ type screenSnapshot struct {
2121type AgentIO interface {
2222 Write (data []byte ) (int , error )
2323 ReadScreen () string
24+ Cursor () (int , int )
2425}
2526
2627type ConversationConfig struct {
@@ -289,16 +290,28 @@ func (c *Conversation) writeMessageWithConfirmation(ctx context.Context, message
289290
290291 // wait for the screen to change after the carriage return is written
291292 screenBeforeCarriageReturn := c .cfg .AgentIO .ReadScreen ()
293+ cursorBeforeCarriageReturnX , cursorBeforeCarriageReturnY := c .cfg .AgentIO .Cursor ()
294+ lastCarriageReturnTime := time.Time {}
292295 if err := util .WaitFor (ctx , util.WaitTimeout {
293296 Timeout : 15 * time .Second ,
294297 MinInterval : 25 * time .Millisecond ,
295298 }, func () (bool , error ) {
296- if _ , err := c .cfg .AgentIO .Write ([]byte ("\r " )); err != nil {
297- return false , xerrors .Errorf ("failed to write carriage return: %w" , err )
299+ // we don't want to spam additional carriage returns because the agent may process them
300+ // (aider does this), but we do want to retry sending one if nothing's
301+ // happening for a while
302+ if time .Since (lastCarriageReturnTime ) >= 3 * time .Second {
303+ lastCarriageReturnTime = time .Now ()
304+ if _ , err := c .cfg .AgentIO .Write ([]byte ("\r " )); err != nil {
305+ return false , xerrors .Errorf ("failed to write carriage return: %w" , err )
306+ }
298307 }
299- time .Sleep (25 * time .Millisecond )
308+ time .Sleep (1 * time .Millisecond )
300309 screen := c .cfg .AgentIO .ReadScreen ()
301- return screen != screenBeforeCarriageReturn , nil
310+ cursorX , cursorY := c .cfg .AgentIO .Cursor ()
311+
312+ return screen != screenBeforeCarriageReturn ||
313+ cursorX != cursorBeforeCarriageReturnX ||
314+ cursorY != cursorBeforeCarriageReturnY , nil
302315 }); err != nil {
303316 return xerrors .Errorf ("failed to wait for processing to start: %w" , err )
304317 }
0 commit comments