From 1429aa076d9902f8d2c2db16ee3978d525454f42 Mon Sep 17 00:00:00 2001 From: "Martin Magala (aider)" Date: Fri, 6 Sep 2024 15:16:56 +0100 Subject: [PATCH 1/2] feat: Add sudo support for apt package installation in terminal --- .../core/computer/terminal/terminal.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/interpreter/core/computer/terminal/terminal.py b/interpreter/core/computer/terminal/terminal.py index cb9841958e..b9f92582f6 100644 --- a/interpreter/core/computer/terminal/terminal.py +++ b/interpreter/core/computer/terminal/terminal.py @@ -1,6 +1,8 @@ import json import os import time +import subprocess +import getpass from ..utils.recipient_utils import parse_for_recipient from .languages.applescript import AppleScript @@ -45,6 +47,29 @@ def __init__(self, computer): ] self._active_languages = {} + def sudo_install(self, package): + try: + # First, try to install without sudo + subprocess.run(['apt', 'install', '-y', package], check=True) + except subprocess.CalledProcessError: + # If it fails, try with sudo + print(f"Installation of {package} requires sudo privileges.") + sudo_password = getpass.getpass("Enter sudo password: ") + + try: + # Use sudo with password + subprocess.run( + ['sudo', '-S', 'apt', 'install', '-y', package], + input=sudo_password.encode(), + check=True + ) + print(f"Successfully installed {package}") + except subprocess.CalledProcessError as e: + print(f"Failed to install {package}. Error: {e}") + return False + + return True + def get_language(self, language): for lang in self.languages: if language.lower() == lang.name.lower() or ( @@ -55,6 +80,14 @@ def get_language(self, language): return None def run(self, language, code, stream=False, display=False): + # Check if this is an apt install command + if language == "shell" and code.strip().startswith("apt install"): + package = code.split()[-1] + if self.sudo_install(package): + return [{"type": "console", "format": "output", "content": f"Package {package} installed successfully."}] + else: + return [{"type": "console", "format": "output", "content": f"Failed to install package {package}."}] + if language == "python": if ( self.computer.import_computer_api From 217b1eb2ecc41bcdb88afa48796428eff67ac8ed Mon Sep 17 00:00:00 2001 From: Martin Magala Date: Fri, 6 Sep 2024 15:20:26 +0100 Subject: [PATCH 2/2] added .aider* --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 54f4524825..4fbe078d98 100644 --- a/.gitignore +++ b/.gitignore @@ -235,3 +235,4 @@ misc/ # Ignore litellm_uuid.txt litellm_uuid.txt +.aider*