From a2cb6601837eff5fce0dfccb6ab04942a912b02c Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 21 Aug 2024 15:12:43 -0700 Subject: [PATCH] pty.spawn is not good --- aider/coders/editblock_coder.py | 44 ++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index 882cd5635..aa1a0fcb3 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -29,15 +29,34 @@ class EditBlockCoder(Coder): return edits def run_interactive_subprocess(self, command): + dump(repr(command)) if os.name == "posix": # Unix-like systems (Linux, macOS) - import pty - - return pty.spawn(command) + return subprocess.run(command, shell=True) + # return pty.spawn(command) elif os.name == "nt": # Windows return subprocess.run(command, shell=True) else: raise OSError("Unsupported operating system") + def handle_shell_commands(self, commands_str): + commands = commands_str.strip().splitlines() + if not self.io.confirm_ask("Run shell command(s)?", subject="\n".join(commands)): + return + + for command in commands: + command = command.strip() + if not command or command.startswith("#"): + continue + + self.io.tool_output() + self.io.tool_output(f"Running {command}") + try: + # Add the command to input history + self.io.add_to_input_history(f"/run {command.strip()}") + self.run_interactive_subprocess(command) + except Exception as e: + self.io.tool_error(f"Error running command '{command}': {str(e)}") + def apply_edits(self, edits): failed = [] passed = [] @@ -67,6 +86,8 @@ class EditBlockCoder(Coder): else: failed.append(edit) + dump(failed) + dump(passed) if not failed: return @@ -568,20 +589,3 @@ def main(): if __name__ == "__main__": main() - - def handle_shell_commands(self, commands_str): - commands = commands_str.strip().splitlines() - if self.io.confirm_ask("Run shell command(s)?", subject="\n".join(commands)): - for command in commands: - command = command.strip() - if not command or command.startswith("#"): - continue - - self.io.tool_output() - self.io.tool_output(f"Running {command}") - try: - # Add the command to input history - self.io.add_to_input_history(f"/run {command.strip()}") - self.run_interactive_subprocess(command.split()) - except Exception as e: - self.io.tool_error(f"Error running command '{command}': {str(e)}")