The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): a NUL-stdin Windows `gateway start` is non-interactive too
teknium1be0a21445236
diff --git a/hermes_cli/gateway_windows.py b/hermes_cli/gateway_windows.pyindex 9bafd6f4621..7a34788147b 100644--- a/hermes_cli/gateway_windows.py+++ b/hermes_cli/gateway_windows.py@@ -683,6 +683,22 @@ def _spawn_detached(script_path: Path | None = None, home: Path | None = None) -return proc.pid+def _stdin_is_interactive(*, isatty: bool, console_mode_ok: bool | None) -> bool:+ """A human can answer a prompt only on a real console. The Windows CRT reports isatty()==True for+ every character device — the NUL device included (`hermes gateway start < NUL`, stdin=DEVNULL) — so+ isatty must be confirmed by GetConsoleMode accepting the handle (#113977). ``console_mode_ok`` is+ None where that fact does not exist (not Windows) and isatty alone decides."""+ return isatty and console_mode_ok is not False+++def _stdin_console_mode_ok() -> bool | None:+ if sys.platform != "win32":+ return None+ kernel32 = ctypes.windll.kernel32+ handle = kernel32.GetStdHandle(-10) # STD_INPUT_HANDLE+ return bool(kernel32.GetConsoleMode(handle, ctypes.byref(ctypes.c_ulong())))++def _install_choice_from_env(name: str) -> bool | None:raw = os.environ.get(name)if raw is None:@@ -1501,7 +1517,9 @@ def start() -> None:from hermes_cli.setup import is_interactive_stdin, is_noninteractive, prompt_yes_noprint("✗ Gateway service is not installed")- if is_noninteractive() or not is_interactive_stdin():+ if is_noninteractive() or not _stdin_is_interactive(+ isatty=is_interactive_stdin(), console_mode_ok=_stdin_console_mode_ok()+ ):start_on_login = Falseelse:start_on_login = prompt_yes_no(" Install it now so the gateway starts on login?", True)diff --git a/tests/hermes_cli/test_gateway_windows.py b/tests/hermes_cli/test_gateway_windows.pyindex a997492149c..d4a62e19317 100644--- a/tests/hermes_cli/test_gateway_windows.py+++ b/tests/hermes_cli/test_gateway_windows.py@@ -494,9 +494,32 @@ def _arrange_uninstalled_start(monkeypatch):monkeypatch.setattr(gateway_windows, "install", lambda **kwargs: installs.append(kwargs))monkeypatch.setattr(gateway_windows, "_spawn_detached", lambda: spawns.append(1) or 4242)monkeypatch.setattr(gateway_windows, "_report_gateway_start", lambda via: None)+ monkeypatch.setattr(gateway_windows, "_stdin_console_mode_ok", lambda: True)return installs, spawns+def test_stdin_interactive_only_when_isatty_and_a_console_answers_get_console_mode():+ """Windows CRT isatty() is True for the NUL device (`hermes gateway start < NUL`, stdin=DEVNULL), so+ isatty alone must not open the prompt; off Windows (no console-mode fact) isatty decides (#113977)."""+ assert gateway_windows._stdin_is_interactive(isatty=True, console_mode_ok=False) is False # NUL+ assert gateway_windows._stdin_is_interactive(isatty=True, console_mode_ok=True) is True # console+ assert gateway_windows._stdin_is_interactive(isatty=False, console_mode_ok=True) is False # pipe+ assert gateway_windows._stdin_is_interactive(isatty=True, console_mode_ok=None) is True # POSIX tty+++def test_start_with_nul_stdin_starts_the_gateway_but_never_installs_login_persistence(monkeypatch, capsys):+ """isatty says TTY, GetConsoleMode says no console: `< NUL` gets the same treatment as a pipe."""+ installs, spawns = _arrange_uninstalled_start(monkeypatch)+ monkeypatch.setattr(setup, "is_interactive_stdin", lambda: True)+ monkeypatch.setattr(gateway_windows, "_stdin_console_mode_ok", lambda: False)+ monkeypatch.setattr(setup, "prompt_yes_no", lambda *a, **k: pytest.fail("no prompt on a NUL stdin"))++ gateway_windows.start()++ assert installs == [] and spawns == [1]+ assert "hermes gateway install" in capsys.readouterr().out++def test_start_without_tty_starts_the_gateway_but_never_installs_login_persistence(monkeypatch, capsys):"""`hermes gateway start < /dev/null` must not answer the persistence question with a default Yes(#113977); it starts the gateway once and points at the explicit install command."""