Skip to content

Commit 49ad949

Browse files
author
cc521137
committed
fix: add readline UTF-8 backspace fix to all agent scripts
macOS libedit has a known issue where backspace/delete does not work correctly with UTF-8 input in Python's input() prompt.
1 parent 5dfe67f commit 49ad949

19 files changed

Lines changed: 209 additions & 0 deletions

agents/s02_tool_use.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
import subprocess
1515
from pathlib import Path
1616

17+
try:
18+
import readline
19+
# #143 UTF-8 backspace fix for macOS libedit
20+
readline.parse_and_bind('set bind-tty-special-chars off')
21+
readline.parse_and_bind('set input-meta on')
22+
readline.parse_and_bind('set output-meta on')
23+
readline.parse_and_bind('set convert-meta off')
24+
readline.parse_and_bind('set enable-meta-keybindings on')
25+
except ImportError:
26+
pass
27+
1728
from anthropic import Anthropic
1829
from dotenv import load_dotenv
1930

agents/s03_todo_write.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
from dataclasses import dataclass, field
1414
from pathlib import Path
1515

16+
try:
17+
import readline
18+
# #143 UTF-8 backspace fix for macOS libedit
19+
readline.parse_and_bind('set bind-tty-special-chars off')
20+
readline.parse_and_bind('set input-meta on')
21+
readline.parse_and_bind('set output-meta on')
22+
readline.parse_and_bind('set convert-meta off')
23+
readline.parse_and_bind('set enable-meta-keybindings on')
24+
except ImportError:
25+
pass
26+
1627
from anthropic import Anthropic
1728
from dotenv import load_dotenv
1829

agents/s04_subagent.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@
4848
import subprocess
4949
from pathlib import Path
5050

51+
try:
52+
import readline
53+
# #143 UTF-8 backspace fix for macOS libedit
54+
readline.parse_and_bind('set bind-tty-special-chars off')
55+
readline.parse_and_bind('set input-meta on')
56+
readline.parse_and_bind('set output-meta on')
57+
readline.parse_and_bind('set convert-meta off')
58+
readline.parse_and_bind('set enable-meta-keybindings on')
59+
except ImportError:
60+
pass
61+
5162
from anthropic import Anthropic
5263
from dotenv import load_dotenv
5364

agents/s05_skill_loading.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
from dataclasses import dataclass
1919
from pathlib import Path
2020

21+
try:
22+
import readline
23+
# #143 UTF-8 backspace fix for macOS libedit
24+
readline.parse_and_bind('set bind-tty-special-chars off')
25+
readline.parse_and_bind('set input-meta on')
26+
readline.parse_and_bind('set output-meta on')
27+
readline.parse_and_bind('set convert-meta off')
28+
readline.parse_and_bind('set enable-meta-keybindings on')
29+
except ImportError:
30+
pass
31+
2132
from anthropic import Anthropic
2233
from dotenv import load_dotenv
2334

agents/s06_context_compact.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121
from dataclasses import dataclass, field
2222
from pathlib import Path
2323

24+
try:
25+
import readline
26+
# #143 UTF-8 backspace fix for macOS libedit
27+
readline.parse_and_bind('set bind-tty-special-chars off')
28+
readline.parse_and_bind('set input-meta on')
29+
readline.parse_and_bind('set output-meta on')
30+
readline.parse_and_bind('set convert-meta off')
31+
readline.parse_and_bind('set enable-meta-keybindings on')
32+
except ImportError:
33+
pass
34+
2435
from anthropic import Anthropic
2536
from dotenv import load_dotenv
2637

agents/s07_permission_system.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
from fnmatch import fnmatch
3030
from pathlib import Path
3131

32+
try:
33+
import readline
34+
# #143 UTF-8 backspace fix for macOS libedit
35+
readline.parse_and_bind('set bind-tty-special-chars off')
36+
readline.parse_and_bind('set input-meta on')
37+
readline.parse_and_bind('set output-meta on')
38+
readline.parse_and_bind('set convert-meta off')
39+
readline.parse_and_bind('set enable-meta-keybindings on')
40+
except ImportError:
41+
pass
42+
3243
from anthropic import Anthropic
3344
from dotenv import load_dotenv
3445

agents/s08_hook_system.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@
2828
import subprocess
2929
from pathlib import Path
3030

31+
try:
32+
import readline
33+
# #143 UTF-8 backspace fix for macOS libedit
34+
readline.parse_and_bind('set bind-tty-special-chars off')
35+
readline.parse_and_bind('set input-meta on')
36+
readline.parse_and_bind('set output-meta on')
37+
readline.parse_and_bind('set convert-meta off')
38+
readline.parse_and_bind('set enable-meta-keybindings on')
39+
except ImportError:
40+
pass
41+
3142
from anthropic import Anthropic
3243
from dotenv import load_dotenv
3344

agents/s09_memory_system.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@
4343
import subprocess
4444
from pathlib import Path
4545

46+
try:
47+
import readline
48+
# #143 UTF-8 backspace fix for macOS libedit
49+
readline.parse_and_bind('set bind-tty-special-chars off')
50+
readline.parse_and_bind('set input-meta on')
51+
readline.parse_and_bind('set output-meta on')
52+
readline.parse_and_bind('set convert-meta off')
53+
readline.parse_and_bind('set enable-meta-keybindings on')
54+
except ImportError:
55+
pass
56+
4657
from anthropic import Anthropic
4758
from dotenv import load_dotenv
4859

agents/s10_system_prompt.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@
3232
import subprocess
3333
from pathlib import Path
3434

35+
try:
36+
import readline
37+
# #143 UTF-8 backspace fix for macOS libedit
38+
readline.parse_and_bind('set bind-tty-special-chars off')
39+
readline.parse_and_bind('set input-meta on')
40+
readline.parse_and_bind('set output-meta on')
41+
readline.parse_and_bind('set convert-meta off')
42+
readline.parse_and_bind('set enable-meta-keybindings on')
43+
except ImportError:
44+
pass
45+
3546
from anthropic import Anthropic
3647
from dotenv import load_dotenv
3748

agents/s11_error_recovery.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@
4747
import time
4848
from pathlib import Path
4949

50+
try:
51+
import readline
52+
# #143 UTF-8 backspace fix for macOS libedit
53+
readline.parse_and_bind('set bind-tty-special-chars off')
54+
readline.parse_and_bind('set input-meta on')
55+
readline.parse_and_bind('set output-meta on')
56+
readline.parse_and_bind('set convert-meta off')
57+
readline.parse_and_bind('set enable-meta-keybindings on')
58+
except ImportError:
59+
pass
60+
5061
from anthropic import Anthropic, APIError
5162
from dotenv import load_dotenv
5263

0 commit comments

Comments
 (0)