The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(sessions): Ctrl-C at a sessions confirmation exits 130, not 0
Tekniumb9e5df60fd98
diff --git a/hermes_cli/sessions_cmd.py b/hermes_cli/sessions_cmd.pyindex b269d679255..23a78065470 100644--- a/hermes_cli/sessions_cmd.py+++ b/hermes_cli/sessions_cmd.py@@ -40,21 +40,24 @@ def _size_delta_label(saved_mb: float) -> str:def _confirm_prompt(prompt: str) -> bool | None:"""Prompt for y/N confirmation. ``None`` when no answer can be read (stdin is /dev/null or closed:- cron, a wrapper, a backgrounded shell), which is not the same as the user saying no."""+ cron, a wrapper, a backgrounded shell), which is not the same as the user saying no. Ctrl-C+ propagates: an interrupt is neither a no nor a success."""try:return input(prompt).strip().lower() in {"y", "yes"}except EOFError:print()return None- except KeyboardInterrupt:- return Falsedef _confirm_or_exit_code(prompt: str, *, declined: str = "Cancelled.", unattended: str | None = "--yes") -> int | None:"""``None`` to proceed, else the exit code after saying why not. A decline exits 0; a run nobody couldanswer exits 1, so a cron job or wrapper that forgot *unattended* does not read "nothing happened" assuccess."""- answer = _confirm_prompt(prompt)+ try:+ answer = _confirm_prompt(prompt)+ except KeyboardInterrupt:+ print("\nInterrupted; nothing was changed.")+ return 130if answer:return Noneif answer is None:diff --git a/tests/hermes_cli/test_sessions_failure_exit_codes.py b/tests/hermes_cli/test_sessions_failure_exit_codes.pyindex faa8a4c38cf..b9edb2b43c0 100644--- a/tests/hermes_cli/test_sessions_failure_exit_codes.py+++ b/tests/hermes_cli/test_sessions_failure_exit_codes.py@@ -118,3 +118,9 @@ def test_confirmation_nobody_can_answer_exits_1_and_changes_nothing(monkeypatch,assert _run_cli(monkeypatch, argv) == 1assert "Pass --yes" in capsys.readouterr().outassert snapshot() == before++ def ctrl_c(_prompt=""):+ raise KeyboardInterrupt+ 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