diff --git a/openhands-tools/openhands/tools/terminal/terminal/__init__.py b/openhands-tools/openhands/tools/terminal/terminal/__init__.py index 81d269b729..ff81e7dfb2 100644 --- a/openhands-tools/openhands/tools/terminal/terminal/__init__.py +++ b/openhands-tools/openhands/tools/terminal/terminal/__init__.py @@ -1,16 +1,29 @@ +import platform +from typing import TYPE_CHECKING + from openhands.tools.terminal.terminal.factory import create_terminal_session from openhands.tools.terminal.terminal.interface import ( TerminalInterface, TerminalSessionBase, ) -from openhands.tools.terminal.terminal.subprocess_terminal import ( - SubprocessTerminal, -) from openhands.tools.terminal.terminal.terminal_session import ( TerminalCommandStatus, TerminalSession, ) -from openhands.tools.terminal.terminal.tmux_terminal import TmuxTerminal + + +# These backends depend on Unix-only modules (fcntl, pty, libtmux) +if platform.system() != "Windows": + from openhands.tools.terminal.terminal.subprocess_terminal import ( + SubprocessTerminal, + ) + from openhands.tools.terminal.terminal.tmux_terminal import TmuxTerminal + +if TYPE_CHECKING: + from openhands.tools.terminal.terminal.subprocess_terminal import ( + SubprocessTerminal, + ) + from openhands.tools.terminal.terminal.tmux_terminal import TmuxTerminal __all__ = [ diff --git a/openhands-tools/openhands/tools/terminal/terminal/subprocess_terminal.py b/openhands-tools/openhands/tools/terminal/terminal/subprocess_terminal.py index 0d9a3c3e4e..a450b75e78 100644 --- a/openhands-tools/openhands/tools/terminal/terminal/subprocess_terminal.py +++ b/openhands-tools/openhands/tools/terminal/terminal/subprocess_terminal.py @@ -1,10 +1,8 @@ """PTY-based terminal backend implementation (replaces pipe-based subprocess).""" -import fcntl import os -import pty +import platform import re -import select import shutil import signal import subprocess @@ -12,6 +10,17 @@ import time from collections import deque + +if platform.system() == "Windows": + raise ImportError( + "SubprocessTerminal is not supported on Windows " + "(requires Unix-only modules: fcntl, pty, select)" + ) + +import fcntl +import pty +import select + from openhands.sdk.logger import get_logger from openhands.sdk.utils import sanitized_env from openhands.tools.terminal.constants import (