Skip to content

Commit 1c1d515

Browse files
author
Aman Rusia
committed
Render terminal output everywhere -- including exit code, was failing for google colab env
1 parent ac95a4d commit 1c1d515

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
authors = [{ name = "Aman Rusia", email = "[email protected]" }]
33
name = "wcgw"
4-
version = "0.1.1"
4+
version = "0.1.2"
55
description = "What could go wrong giving full shell access to chatgpt?"
66
readme = "README.md"
77
requires-python = ">=3.10, <3.13"

src/wcgw/tools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def _get_exit_code() -> int:
114114
while not _is_int(before): # Consume all previous output
115115
SHELL.expect("#@@")
116116
assert isinstance(SHELL.before, str)
117-
before = SHELL.before
117+
# Render because there could be some anscii escape sequences still set like in google colab env
118+
before = render_terminal_output(SHELL.before).strip()
118119

119120
try:
120121
return int((before))
@@ -285,7 +286,7 @@ def read_image_from_shell(file_path: str) -> ImageData:
285286
SHELL.sendline("pwd")
286287
SHELL.expect("#@@")
287288
assert isinstance(SHELL.before, str)
288-
current_dir = SHELL.before.strip()
289+
current_dir = render_terminal_output(SHELL.before).strip()
289290
file_path = os.path.join(current_dir, file_path)
290291

291292
if not os.path.exists(file_path):
@@ -304,7 +305,7 @@ def write_file(writefile: Writefile) -> str:
304305
SHELL.sendline("pwd")
305306
SHELL.expect("#@@")
306307
assert isinstance(SHELL.before, str)
307-
current_dir = SHELL.before.strip()
308+
current_dir = render_terminal_output(SHELL.before).strip()
308309
return f"Failure: Use absolute path only. FYI current working directory is '{current_dir}'"
309310
os.makedirs(os.path.dirname(writefile.file_path), exist_ok=True)
310311
try:

0 commit comments

Comments
 (0)