Skip to content

The agent that grows with you

fix(cli): fall back to input() when prompt_toolkit can't attach stdin

wo-oe8ab3b075dc6
diff --git a/hermes_cli/cli_output.py b/hermes_cli/cli_output.py
index 165de84b8f8..3aab6ff2e36 100644
--- a/hermes_cli/cli_output.py
+++ b/hermes_cli/cli_output.py
@@ -59,7 +59,15 @@ def line_input(prompt_text: str) -> str:
except ImportError:
return input(prompt_text)
- return prompt_toolkit_prompt(ANSI(prompt_text))
+ try:
+ return prompt_toolkit_prompt(ANSI(prompt_text))
+ except OSError:
+ # Some terminals report isatty() == True yet reject registering stdin
+ # with the asyncio event-loop selector (observed on macOS, where kqueue
+ # raises EINVAL / "Invalid argument" for fd 0). prompt_toolkit cannot
+ # attach its input there, so fall back to the built-in line reader,
+ # which needs no selector and works in cooked mode.
+ return input(prompt_text)
def prompt(