The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): a stop the owner took as a voice stop mid-turn is consumed, not re-queued
Teknium52c9d4728635
diff --git a/hermes_cli/cli_loops_mixin.py b/hermes_cli/cli_loops_mixin.pyindex b3050c24b38..413b45cd42d 100644--- a/hermes_cli/cli_loops_mixin.py+++ b/hermes_cli/cli_loops_mixin.py@@ -477,7 +477,9 @@ class CLILoopsMixin:except Exception as exc:_cprint(f" {t('cli.steer.failed', error=exc)}")else:- if accepted:+ if accepted == "voice_stopped": # TUI-26: the owner ended the voice chat; consumed+ pass+ elif accepted:_cprint(f" {t('cli.steer.queued', preview=_preview(payload))}")else:_cprint(f" {t('cli.steer.rejected_empty')}")diff --git a/hermes_cli/cli_tui_mixin.py b/hermes_cli/cli_tui_mixin.pyindex a456e92ac6b..39fd414b4a8 100644--- a/hermes_cli/cli_tui_mixin.py+++ b/hermes_cli/cli_tui_mixin.py@@ -1519,10 +1519,12 @@ class CLITuiMixin:accepted = Falsetry:if self.agent is not None and hasattr(self.agent, "steer"):- accepted = bool(self.agent.steer(text))+ accepted = self.agent.steer(text)except Exception as exc:_cprint(f" {_DIM}{t('cli.tui.steer_failed_queued', error=exc)}{_RST}")accepted = False+ if accepted == "voice_stopped": # TUI-26: consumed as a voice stop; nothing to queue+ returnif accepted:preview = text[:80] + ("..." if len(text) > 80 else "")_cprint(f" {_ACCENT}{t('cli.tui.steered', preview=preview)}{_RST}")@@ -1540,9 +1542,11 @@ class CLITuiMixin:self.agent is not Noneand getattr(self.agent, "_supports_active_turn_redirect", False) is Trueand hasattr(self.agent, "redirect")):- redirected = bool(self.agent.redirect(text))+ redirected = self.agent.redirect(text)except Exception:redirected = False+ if redirected == "voice_stopped": # TUI-26: consumed as a voice stop; nothing to queue+ returnif redirected:preview = text[:80] + ("..." if len(text) > 80 else "")_cprint(f" {_ACCENT}{t('cli.tui.redirected_turn', preview=preview)}{_RST}")diff --git a/hermes_cli/gateway_agent.py b/hermes_cli/gateway_agent.pyindex fd1e535917f..0635617fda6 100644--- a/hermes_cli/gateway_agent.py+++ b/hermes_cli/gateway_agent.py@@ -25,6 +25,9 @@ logger = logging.getLogger(__name__)# How long a turn waits for its settlement after an interrupt (main: cli_chat_turn_mixin 10 s).INTERRUPT_SETTLE_SECONDS = 10.0_POLL = 0.1+# ``steer()`` / ``redirect()``'s reply when the owner consumed the text as a typed voice stop (TUI-26):+# truthy, so a caller that only asks "taken?" never re-queues it.+VOICE_STOPPED = "voice_stopped"_RESULT_DEFAULTS = {"final_response": "", "failed": False, "partial": False, "error": None, "failure_reason": None,@@ -559,6 +562,9 @@ class GatewayAgent:self.interrupt(message)def _correct(self, verb, text):+ """-> ``True`` (accepted), ``False`` (not taken: the caller queues the text), or+ ``"voice_stopped"`` (TUI-26: the owner took a bare stop phrase as the end of this LOCAL+ session's voice chat; the text is consumed and reaches no turn, so it is never re-queued)."""generation = self._generationif generation is None:return False@@ -567,6 +573,10 @@ class GatewayAgent:execution_generation=generation)except GatewayClientError:return False+ if (result or {}).get("voice_stopped") is True:+ from agent.i18n import t+ self._emit_print(t("cli.voice.stop_phrase_typed"))+ return VOICE_STOPPEDreturn (result or {}).get("status") in {"queued", "redirected"}def _compress_context(self, messages, system_message=None, *, approx_tokens=None, focus_topic=None,@@ -605,7 +615,7 @@ class GatewayAgent:def redirect(self, text):accepted = self._correct("redirect", text)- if accepted:+ if accepted is True:# Main's turn then answers the redirect row first (the interrupted call has no usage), so# its anchor is priced through that row: it, not the original ask, is the turn's ask.self._turn_ask_index = Nonediff --git a/tests/hermes_cli/test_gateway_agent.py b/tests/hermes_cli/test_gateway_agent.pyindex d033331a7c8..b11599aec61 100644--- a/tests/hermes_cli/test_gateway_agent.py+++ b/tests/hermes_cli/test_gateway_agent.py@@ -958,3 +958,38 @@ def test_a_voice_stopped_reply_returns_without_waiting_for_a_turn():assert any(t("cli.voice.stop_phrase_typed") in line for line in printed), printedfinally:conn.close()++[email protected]("mode", ["steer", "interrupt"])+def test_a_voice_stopped_correction_is_consumed_not_requeued(make_agent, mode):+ """TUI-26 (Greptile): a bare stop typed while a turn runs reaches ``session.steer`` /+ ``session.redirect``; the owner ends the LOCAL voice chat and answers ``{voice_stopped: true}``.+ The classic CLI must take the text as consumed: re-queuing it would submit ``stop`` again once+ voice is already off, and that becomes an agent turn."""+ import queue++ from cli import HermesCLI++ agent, client = make_agent([])+ agent._generation = 7+ agent._supports_active_turn_redirect = True+ original = client.rpc++ async def rpc(method, *, _timeout=None, **params):+ if method in {"session.steer", "session.redirect"}:+ client.calls.append((method, params))+ return {"voice_stopped": True}+ return await original(method, _timeout=_timeout, **params)+ client.rpc = rpc+ printed = []+ agent._print_fn = printed.append+ shell = object.__new__(HermesCLI)+ shell.busy_input_mode = mode+ shell.agent = agent+ shell._pending_input, shell._interrupt_queue = queue.Queue(), queue.Queue()+ agent._turn_ask_index = 3 # the running turn's ask; a consumed stop must leave it alone+ shell._tui_enter_while_busy("stop", [], "stop")+ assert shell._pending_input.empty() and shell._interrupt_queue.empty(), "consumed stop was re-queued"+ sent = [m for m, _ in client.calls if m.startswith("session.")]+ assert sent == [{"steer": "session.steer", "interrupt": "session.redirect"}[mode]]+ assert agent._turn_ask_index == 3, "the running turn's history changed for a consumed stop"