From 38e8d274162fd4cce3339ee9d386d4dc9a049ef4 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Thu, 6 Mar 2025 11:45:37 -0800 Subject: [PATCH] feat: Add desktop notification support with notify-py package --- aider/args.py | 6 ++++++ aider/io.py | 22 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/aider/args.py b/aider/args.py index 2a55b4d28..21c12b69c 100644 --- a/aider/args.py +++ b/aider/args.py @@ -795,6 +795,12 @@ def get_parser(default_config_files, git_root): default=default_env_file(git_root), help="Specify the .env file to load (default: .env in git root)", ) + group.add_argument( + "--notification", + choices=["bell", "desktop", "both", "none"], + default="bell", + help="Notification method when LLM completes (default: bell)", + ) group.add_argument( "--suggest-shell-commands", action=argparse.BooleanOptionalAction, diff --git a/aider/io.py b/aider/io.py index d4acc6bc4..b2951907d 100644 --- a/aider/io.py +++ b/aider/io.py @@ -8,6 +8,7 @@ from collections import defaultdict from dataclasses import dataclass from datetime import datetime from io import StringIO +from notifypy import Notify from pathlib import Path from prompt_toolkit.completion import Completer, Completion, ThreadedCompleter @@ -236,6 +237,7 @@ class InputOutput: file_watcher=None, multiline_mode=False, root=".", + notification="bell", ): self.placeholder = None self.interrupted = False @@ -243,6 +245,7 @@ class InputOutput: self.editingmode = editingmode self.multiline_mode = multiline_mode self.bell_on_next_input = False + self.notification_type = notification no_color = os.environ.get("NO_COLOR") if no_color is not None and no_color != "": pretty = False @@ -949,10 +952,25 @@ class InputOutput: """Clear the bell flag (optional, as we'll clear it after ringing)""" self.bell_on_next_input = False + def show_desktop_notification(self): + """Show a desktop notification that the LLM has completed""" + notification = Notify() + notification.title = "Aider" + notification.message = "LLM processing complete" + notification.send() + def ring_bell(self): - """Ring the terminal bell if needed and clear the flag""" + """Ring the terminal bell or show desktop notification if needed and clear the flag""" if self.bell_on_next_input: - print("\a", end="", flush=True) # Ring the bell + if self.notification_type in ("bell", "both"): + print("\a", end="", flush=True) # Ring the bell + + if self.notification_type in ("desktop", "both"): + try: + self.show_desktop_notification() + except Exception as e: + self.tool_warning(f"Desktop notification failed: {e}") + self.bell_on_next_input = False # Clear the flag def toggle_multiline_mode(self):