Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix output code error in docker image (#2862)

Yufan Song9198ea3fb107
diff --git a/opendevin/runtime/client/client.py b/opendevin/runtime/client/client.py
index 3311033f7c..2a9f80b5a3 100644
--- a/opendevin/runtime/client/client.py
+++ b/opendevin/runtime/client/client.py
@@ -4,6 +4,7 @@ import websockets
import pexpect
import json
import shutil
+import re
from typing import Any
from websockets.exceptions import ConnectionClosed
from opendevin.events.serialization import event_to_dict, event_from_dict
@@ -77,13 +78,23 @@ class RuntimeClient():
)
except UnicodeDecodeError:
return ErrorObservation('Command output could not be decoded as utf-8')
-
+
+ def clean_up(self,input_text):
+ # Remove escape sequences
+ cleaned_text = re.sub(r'\x1b\[[0-9;?]*[a-zA-Z]', '', input_text)
+ # Remove carriage returns and other control characters
+ cleaned_text = re.sub(r'[\r\n\t]', '', cleaned_text)
+ return cleaned_text
+
def execute(self, command):
print(f"Received command: {command}")
self.shell.sendline(command)
self.shell.expect(r'[$#] ')
output = self.shell.before.strip().split('\r\n', 1)[1].strip()
- exit_code = output[-1].strip()
+ # Get the exit code
+ self.shell.sendline('echo $?')
+ self.shell.expect(r'[$#] ')
+ exit_code = self.clean_up(self.shell.before.strip().split('\r\n')[1].strip())
return output, exit_code
def run_ipython(self, action: IPythonRunCellAction) -> Observation:
@@ -193,6 +204,9 @@ def test_run_commond():
command = CmdRunAction(command="ls -l")
obs = client.run_action(command)
print(obs)
+ command = CmdRunAction(command="pwd")
+ obs = client.run_action(command)
+ print(obs)
def test_shell(message):
@@ -207,8 +221,8 @@ def test_shell(message):
if __name__ == "__main__":
# print(test_shell("ls -l"))
- client = RuntimeClient()
- # test_run_commond()
+ # client = RuntimeClient()
+ test_run_commond()
# client.init_sandbox_plugins([AgentSkillsRequirement,JupyterRequirement])
# print(test_shell("whoami"))