The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): chat -q approvals keep the approvals.timeout deadline
unsupportedpastels82c63c505a9f
diff --git a/hermes_cli/cli_chat_turn_mixin.py b/hermes_cli/cli_chat_turn_mixin.pyindex c8b8dcb5e53..5961d86ecce 100644--- a/hermes_cli/cli_chat_turn_mixin.py+++ b/hermes_cli/cli_chat_turn_mixin.py@@ -346,8 +346,10 @@ class CLIChatTurnMixin:_one_turn_model_restore = getattr(self, "_pending_one_turn_model_restore", None)self._pending_one_turn_model_restore = None# The user is at this terminal: approval and clarify prompts wait until answered or Ctrl+C.+ # `chat -q` has nobody to answer (no prompt_toolkit app, often no stdin), so it keeps the+ # approvals.timeout deadline instead of waiting forever.from tools.approval_context import reset_prompts_wait_for_answer, set_prompts_wait_for_answer- _prompts_token = set_prompts_wait_for_answer()+ _prompts_token = None if getattr(self, "_single_query_mode", False) else set_prompts_wait_for_answer()try:from agent.notification_presentation import notification_turnmuted = getattr(turn, "mute_notification_reply", False)@@ -398,7 +400,8 @@ class CLIChatTurnMixin:reset_current_session_key(_approval_session_token)except Exception:pass- reset_prompts_wait_for_answer(_prompts_token)+ if _prompts_token is not None:+ reset_prompts_wait_for_answer(_prompts_token)def _chat_monitor_agent_thread(self, turn, agent_thread):"""Poll the interrupt queue while the agent thread runs; returns the interrupting message (or None)."""diff --git a/hermes_cli/cli_modal_mixin.py b/hermes_cli/cli_modal_mixin.pyindex f460db6c616..7be35cad9b1 100644--- a/hermes_cli/cli_modal_mixin.py+++ b/hermes_cli/cli_modal_mixin.py@@ -1050,9 +1050,10 @@ class CLIModalMixin:"""Dangerous-command approval through the prompt_toolkit UI (agent thread).Choices: once / session / always / deny (see ``_approval_choices``), plus 'view' for long- commands. The panel stays up until the user answers (Ctrl+C interrupts the turn).- ``_approval_lock`` serializes concurrent requests (parallel delegation subtasks) so the- shared ``_approval_state`` isn't clobbered.+ commands. The panel stays up until the user answers (Ctrl+C interrupts the turn), except in+ ``chat -q``: no prompt_toolkit app can answer there, so it keeps the ``approvals.timeout``+ deadline and returns ``"timeout"``. ``_approval_lock`` serializes concurrent requests+ (parallel delegation subtasks) so the shared ``_approval_state`` isn't clobbered."""with self._approval_lock:response_queue = queue.Queue()@@ -1067,6 +1068,9 @@ class CLIModalMixin:"selected": 0,"response_queue": response_queue}self._approval_deadline = None+ if getattr(self, "_single_query_mode", False):+ from tools.approval_context import approval_wait_seconds+ self._approval_deadline = _time.monotonic() + approval_wait_seconds()self._ring_bell(prompt=True, context=t("cli.approval.bell_context"), detail=command)self._paint_now()@@ -1074,6 +1078,12 @@ class CLIModalMixin:self._approval_state = Noneself._approval_deadline = 0self._paint_now()+ if result is _TIMED_OUT:+ from cli import _DIM, _RST, _cprint+ _cprint(f"\n{_DIM} {t('cli.approval.timeout_denying')}{_RST}")+ self._persist_prompt_summary(+ "⚠", t("cli.approval.label"), command, t("cli.approval.timed_out_no_response"))+ return "timeout"self._persist_prompt_summary("⚠", t("cli.approval.label"), command, _approval_outcome_label(result))return resultdiff --git a/locales/af.yaml b/locales/af.yamlindex a83df85b7d8..8e4e060ef73 100644--- a/locales/af.yaml+++ b/locales/af.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "goedkeuring"label: "Goedkeuring"+ timeout_denying: "⏱ Tyd verstreke — opdrag word geweier"+ timed_out_no_response: "tyd verstreke (geen antwoord)"outcome_once: "eenmalig toegelaat"outcome_session: "vir sessie toegelaat"outcome_always: "by toelaatlys gevoeg"diff --git a/locales/ar.yaml b/locales/ar.yamlindex 71467b9318a..10664ca2d37 100644--- a/locales/ar.yaml+++ b/locales/ar.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "الموافقة"label: "الموافقة"+ timeout_denying: "⏱ انتهت المهلة — رفض الأمر"+ timed_out_no_response: "انتهت المهلة (لا استجابة)"outcome_once: "مسموح مرة واحدة"outcome_session: "مسموح لهذه الجلسة"outcome_always: "أُضيف إلى قائمة السماح"diff --git a/locales/de.yaml b/locales/de.yamlindex 780734baaba..41c5c88e0c7 100644--- a/locales/de.yaml+++ b/locales/de.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "Genehmigung"label: "Genehmigung"+ timeout_denying: "⏱ Zeitüberschreitung — Befehl wird abgelehnt"+ timed_out_no_response: "Zeitüberschreitung (keine Antwort)"outcome_once: "einmalig erlaubt"outcome_session: "für diese Sitzung erlaubt"outcome_always: "zur Erlaubnisliste hinzugefügt"diff --git a/locales/en.yaml b/locales/en.yamlindex 3bf2504323f..e4f844ca2b3 100644--- a/locales/en.yaml+++ b/locales/en.yaml@@ -2352,6 +2352,8 @@ cli:approval:bell_context: "approval"label: "Approval"+ timeout_denying: "⏱ Timeout — denying command"+ timed_out_no_response: "timed out (no response)"outcome_once: "allowed once"outcome_session: "allowed for session"outcome_always: "added to allowlist"diff --git a/locales/es.yaml b/locales/es.yamlindex 48ca84fd5f1..71b3090d1fe 100644--- a/locales/es.yaml+++ b/locales/es.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "aprobación"label: "Aprobación"+ timeout_denying: "⏱ Tiempo agotado — denegando el comando"+ timed_out_no_response: "tiempo agotado (sin respuesta)"outcome_once: "permitido una vez"outcome_session: "permitido para la sesión"outcome_always: "añadido a la lista de permitidos"diff --git a/locales/fr.yaml b/locales/fr.yamlindex ad2d991d9a8..a2be5edae4a 100644--- a/locales/fr.yaml+++ b/locales/fr.yaml@@ -2525,6 +2525,8 @@ cli:approval:bell_context: "approbation"label: "Approbation"+ timeout_denying: "⏱ Délai dépassé — commande refusée"+ timed_out_no_response: "délai dépassé (aucune réponse)"outcome_once: "autorisé une fois"outcome_session: "autorisé pour la session"outcome_always: "ajouté à la liste d'autorisation"diff --git a/locales/ga.yaml b/locales/ga.yamlindex ff28d1a3190..acba431fe90 100644--- a/locales/ga.yaml+++ b/locales/ga.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "cead"label: "Cead"+ timeout_denying: "⏱ Teorainn ama — ag diúltú don ordú"+ timed_out_no_response: "imithe thar am (gan freagra)"outcome_once: "ceadaithe uair amháin"outcome_session: "ceadaithe don seisiún"outcome_always: "curtha leis an liosta ceadaithe"diff --git a/locales/hu.yaml b/locales/hu.yamlindex f00d816e946..0898dc80ad8 100644--- a/locales/hu.yaml+++ b/locales/hu.yaml@@ -2269,6 +2269,8 @@ cli:approval:bell_context: "jóváhagyás"label: "Jóváhagyás"+ timeout_denying: "⏱ Időtúllépés — a parancs elutasítva"+ timed_out_no_response: "időtúllépés (nem jött válasz)"outcome_once: "egyszer engedélyezve"outcome_session: "a munkamenetre engedélyezve"outcome_always: "engedélyezőlistára téve"diff --git a/locales/it.yaml b/locales/it.yamlindex 38a08ac7c92..cdf4a547daf 100644--- a/locales/it.yaml+++ b/locales/it.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "approvazione"label: "Approvazione"+ timeout_denying: "⏱ Timeout — comando negato"+ timed_out_no_response: "timeout (nessuna risposta)"outcome_once: "consentito una volta"outcome_session: "consentito per la sessione"outcome_always: "aggiunto alla allowlist"diff --git a/locales/ja.yaml b/locales/ja.yamlindex b07d8c67171..75ffd117497 100644--- a/locales/ja.yaml+++ b/locales/ja.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "承認"label: "承認"+ timeout_denying: "⏱ タイムアウト — コマンドを拒否します"+ timed_out_no_response: "タイムアウト(応答なし)"outcome_once: "今回のみ許可"outcome_session: "セッション中は許可"outcome_always: "許可リストに追加"diff --git a/locales/ko.yaml b/locales/ko.yamlindex 9a93e00abcf..b478312d397 100644--- a/locales/ko.yaml+++ b/locales/ko.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "승인"label: "승인"+ timeout_denying: "⏱ 시간 초과 — 명령을 거부해요"+ timed_out_no_response: "시간 초과 (응답 없음)"outcome_once: "한 번 허용됨"outcome_session: "세션 동안 허용됨"outcome_always: "허용 목록에 추가됨"diff --git a/locales/pt.yaml b/locales/pt.yamlindex 32b4f487a59..5c03205f047 100644--- a/locales/pt.yaml+++ b/locales/pt.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "aprovação"label: "Aprovação"+ timeout_denying: "⏱ Tempo limite — negando o comando"+ timed_out_no_response: "tempo limite esgotado (sem resposta)"outcome_once: "permitido uma vez"outcome_session: "permitido para a sessão"outcome_always: "adicionado à lista de permissões"diff --git a/locales/ru.yaml b/locales/ru.yamlindex 9ac26bc28b5..b8594c9cdb8 100644--- a/locales/ru.yaml+++ b/locales/ru.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "одобрение"label: "Одобрение"+ timeout_denying: "⏱ Тайм-аут — команда отклонена"+ timed_out_no_response: "тайм-аут (нет ответа)"outcome_once: "разрешено один раз"outcome_session: "разрешено на сеанс"outcome_always: "добавлено в список разрешённых"diff --git a/locales/tr.yaml b/locales/tr.yamlindex e9120093961..3fc72fc9f9e 100644--- a/locales/tr.yaml+++ b/locales/tr.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "onay"label: "Onay"+ timeout_denying: "⏱ Zaman aşımı — komut reddediliyor"+ timed_out_no_response: "zaman aşımı (yanıt yok)"outcome_once: "bir kez izin verildi"outcome_session: "oturum için izin verildi"outcome_always: "izin listesine eklendi"diff --git a/locales/uk.yaml b/locales/uk.yamlindex 2e400425006..9b6a1802784 100644--- a/locales/uk.yaml+++ b/locales/uk.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "схвалення"label: "Схвалення"+ timeout_denying: "⏱ Час вийшов — команду відхилено"+ timed_out_no_response: "час вийшов (без відповіді)"outcome_once: "дозволено один раз"outcome_session: "дозволено для сеансу"outcome_always: "додано до списку дозволених"diff --git a/locales/zh-hant.yaml b/locales/zh-hant.yamlindex a10f4a10ce4..03348021beb 100644--- a/locales/zh-hant.yaml+++ b/locales/zh-hant.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "批准"label: "批准"+ timeout_denying: "⏱ 逾時 — 拒絕指令"+ timed_out_no_response: "已逾時(無回應)"outcome_once: "允許一次"outcome_session: "本工作階段允許"outcome_always: "已加入允許清單"diff --git a/locales/zh.yaml b/locales/zh.yamlindex 2a020517c69..62ab2279c26 100644--- a/locales/zh.yaml+++ b/locales/zh.yaml@@ -2252,6 +2252,8 @@ cli:approval:bell_context: "审批"label: "审批"+ timeout_denying: "⏱ 超时——拒绝执行命令"+ timed_out_no_response: "已超时(无响应)"outcome_once: "已允许一次"outcome_session: "本会话内已允许"outcome_always: "已加入允许列表"diff --git a/tests/hermes_cli/test_cli_approval_ui.py b/tests/hermes_cli/test_cli_approval_ui.pyindex a7ee0071b33..4efc753b624 100644--- a/tests/hermes_cli/test_cli_approval_ui.py+++ b/tests/hermes_cli/test_cli_approval_ui.py@@ -91,6 +91,18 @@ class TestCliApprovalUi:thread.join(timeout=2)assert result["value"] == "once"+ def test_single_query_panel_times_out_at_approvals_timeout(self):+ """``chat -q`` has no prompt_toolkit app to answer the panel: it denies at+ ``approvals.timeout`` instead of parking the turn until the safe maximum."""+ cli = _make_cli_stub()+ cli._single_query_mode = True+ cli._persist_prompt_summary = MagicMock()+ with patch("tools.approval_context.approval_wait_seconds", return_value=1):+ started = time.monotonic()+ assert cli._approval_callback("rm -rf /tmp/x", "delete") == "timeout"+ assert time.monotonic() - started < 5+ assert cli._approval_state is None+def test_smart_denied_callback_offers_only_once_and_deny(self):cli = _make_cli_stub()result = {}diff --git a/tests/hermes_cli/test_cli_single_query_prompt_window.py b/tests/hermes_cli/test_cli_single_query_prompt_window.pynew file mode 100644index 00000000000..7c6ecbe99a2--- /dev/null+++ b/tests/hermes_cli/test_cli_single_query_prompt_window.py@@ -0,0 +1,39 @@+"""`chat -q` has nobody at a prompt: its turn must not bind the wait-until-answered policy.++The interactive CLI binds ``set_prompts_wait_for_answer()`` around each turn so approval panels stay+up until answered. A single-query turn has no prompt_toolkit app (and often no stdin), so binding it+there parks every approval for ``MAX_SAFE_TIMEOUT_S`` instead of ``approvals.timeout``.+"""++from __future__ import annotations++from types import SimpleNamespace+from unittest.mock import Mock++import pytest++from cli import HermesCLI, _ChatTurn+from tools.approval_context import prompts_wait_for_answer+++def _run_turn(single_query: bool) -> bool:+ cli = HermesCLI.__new__(HermesCLI)+ cli.session_id = "prompt-window"+ cli.conversation_history = [{"role": "user", "content": "go"}]+ if single_query:+ setattr(cli, "_single_query_mode", True)+ seen = {}++ def _run_conversation(**_kwargs):+ seen["wait_for_answer"] = prompts_wait_for_answer()+ return {}++ cli.agent = SimpleNamespace(run_conversation=Mock(side_effect=_run_conversation))+ cli._chat_run_agent(_ChatTurn(), "go")+ assert prompts_wait_for_answer() is False, "turn leaked the wait-for-answer binding"+ return seen["wait_for_answer"]++[email protected](("single_query", "expected"), [(False, True), (True, False)])+def test_only_an_attended_turn_waits_for_an_answer(single_query, expected):+ assert _run_turn(single_query) is expected