Skip to content

The agent that grows with you

fix(sessions): Windows NUL stdin is unattended, not a terminal decline

Teknium46adcf7d4083
diff --git a/hermes_cli/sessions_cmd.py b/hermes_cli/sessions_cmd.py
index 37681e9267e..e1de2cfc6d1 100644
--- a/hermes_cli/sessions_cmd.py
+++ b/hermes_cli/sessions_cmd.py
@@ -46,7 +46,9 @@ def _confirm_prompt(prompt: str) -> bool | None:
return input(prompt).strip().lower() in {"y", "yes"}
except EOFError:
print()
- return False if sys.stdin.isatty() else None
+ # isatty() alone is True for Windows NUL; the console check keeps `< NUL` unattended (#113977).
+ from hermes_cli.gateway_windows import _stdin_console_mode_ok, _stdin_is_interactive
+ return False if _stdin_is_interactive(isatty=sys.stdin.isatty(), console_mode_ok=_stdin_console_mode_ok()) else None
def _confirm_or_exit_code(prompt: str, *, declined: str = "Cancelled.", unattended: str | None = "--yes") -> int | None:
diff --git a/tests/hermes_cli/test_sessions_failure_exit_codes.py b/tests/hermes_cli/test_sessions_failure_exit_codes.py
index b9edb2b43c0..8e5bfc86807 100644
--- a/tests/hermes_cli/test_sessions_failure_exit_codes.py
+++ b/tests/hermes_cli/test_sessions_failure_exit_codes.py
@@ -124,3 +124,23 @@ def test_confirmation_nobody_can_answer_exits_1_and_changes_nothing(monkeypatch,
monkeypatch.setattr("builtins.input", ctrl_c) # an interrupt is not a decline either: `&& next` must not run
assert _run_cli(monkeypatch, argv) == 130
assert snapshot() == before
+
+
+def test_redirected_null_stdin_is_unattended_on_every_os(tmp_path):
+ """A real ``stdin=DEVNULL`` child: Windows reports isatty() True for NUL, which must still read as
+ nobody-could-answer (exit 1), never as a decline that lets ``&& next`` run."""
+ import os
+ import subprocess
+ from pathlib import Path
+
+ home = tmp_path / ".hermes"
+ home.mkdir()
+ _old_ended_session(home / "state.db")
+ root = str(Path(__file__).resolve().parents[2])
+ env = {**os.environ, "HERMES_HOME": str(home), "PYTHONPATH": root}
+ proc = subprocess.run([sys.executable, "-m", "hermes_cli.main", "sessions", "delete", "s-old"], cwd=root,
+ env=env, stdin=subprocess.DEVNULL, capture_output=True, text=True, encoding="utf-8",
+ errors="replace", timeout=120, check=False)
+ assert proc.returncode == 1, proc.stdout + proc.stderr
+ assert "Pass --yes" in proc.stdout