From dcba291d45d966ff67edf3aa16db163b1fe74f3a Mon Sep 17 00:00:00 2001 From: shitcoinsherpa <44278268+shitcoinsherpa@users.noreply.github.com> Date: Thu, 5 Mar 2026 17:02:51 -0500 Subject: [PATCH] Use pywinpty instead of ptyprocess on Windows for PTY support ptyprocess depends on Unix-only APIs (fork, openpty) and cannot work on Windows at all. pywinpty provides a compatible PtyProcess interface using the Windows ConPTY API. This conditionally imports winpty.PtyProcess on Windows and ptyprocess.PtyProcess on Unix. The pyproject.toml pty extra now uses platform markers so the correct package is installed automatically. --- pyproject.toml | 5 ++++- tools/process_registry.py | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 498d1112..fb37ee34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,10 @@ cron = ["croniter"] slack = ["slack-bolt>=1.18.0", "slack-sdk>=3.27.0"] cli = ["simple-term-menu"] tts-premium = ["elevenlabs"] -pty = ["ptyprocess>=0.7.0"] +pty = [ + "ptyprocess>=0.7.0; sys_platform != 'win32'", + "pywinpty>=2.0.0; sys_platform == 'win32'", +] honcho = ["honcho-ai>=2.0.1"] mcp = ["mcp>=1.2.0"] homeassistant = ["aiohttp>=3.9.0"] diff --git a/tools/process_registry.py b/tools/process_registry.py index 584f4b11..ed11a0e6 100644 --- a/tools/process_registry.py +++ b/tools/process_registry.py @@ -148,11 +148,14 @@ class ProcessRegistry: if use_pty: # Try PTY mode for interactive CLI tools try: - import ptyprocess + if _IS_WINDOWS: + from winpty import PtyProcess as _PtyProcessCls + else: + from ptyprocess import PtyProcess as _PtyProcessCls user_shell = _find_shell() pty_env = os.environ | (env_vars or {}) pty_env["PYTHONUNBUFFERED"] = "1" - pty_proc = ptyprocess.PtyProcess.spawn( + pty_proc = _PtyProcessCls.spawn( [user_shell, "-lic", command], cwd=session.cwd, env=pty_env,