From 162204f28fea53118322a71655c1932608cc7ddd Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Sun, 26 Jan 2025 18:45:51 -0800 Subject: [PATCH] feat: improve keyboard interrupt message handling --- aider/coders/base_coder.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 3982c5d8e..193b90d76 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -1367,10 +1367,11 @@ class Coder: interrupted = True if interrupted: - # check if the last messages was role==user, append the ^C Key.. to it if so. ai! - self.cur_messages += [ - dict(role="user", content="^C KeyboardInterrupt"), - dict(role="assistant", content="I see that you interrupted my previous reply."), + if self.cur_messages and self.cur_messages[-1]["role"] == "user": + self.cur_messages[-1]["content"] += "\n^C KeyboardInterrupt" + else: + self.cur_messages += [dict(role="user", content="^C KeyboardInterrupt")] + self.cur_messages += [dict(role="assistant", content="I see that you interrupted my previous reply.")] ] return