feat: Add /copy command to copy last assistant message to clipboard

This commit is contained in:
Paul Gauthier (aider) 2024-09-27 14:21:37 -07:00
parent 7c1318274e
commit 0c470662bb

View file

@ -1158,6 +1158,21 @@ class Commands:
settings = format_settings(self.parser, self.args)
self.io.tool_output(settings)
def cmd_copy(self, args):
"Copy the last assistant message to the clipboard"
all_messages = self.coder.done_messages + self.coder.cur_messages
assistant_messages = [msg for msg in reversed(all_messages) if msg['role'] == 'assistant']
if not assistant_messages:
self.io.tool_error("No assistant messages found to copy.")
return
last_assistant_message = assistant_messages[0]['content']
pyperclip.copy(last_assistant_message)
preview = last_assistant_message[:50] + "..." if len(last_assistant_message) > 50 else last_assistant_message
self.io.tool_output(f"Copied last assistant message to clipboard. Preview: {preview}")
def cmd_report(self, args):
"Report a problem by opening a GitHub Issue"
from aider.report import report_github_issue