The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(cli): quiet -Q session binding as a context manager
kshitijk4poor30b02bba126d
diff --git a/cli.py b/cli.pyindex 50f1fc0a90a..53cb5aff0aa 100644--- a/cli.py+++ b/cli.py@@ -4091,12 +4091,7 @@ def _run_quiet_single_query(cli, effective_query):author = take_turn_author_from_env()author_kwargs = {"turn_author": author} if author is not None and _accepts_keyword(cli.agent.run_conversation, "turn_author") else {}- key_token, reset_session_key = None, None- try:- key_token, reset_session_key = bind_quiet_session_key(getattr(cli, "session_id", "") or "default")- except Exception:- key_token, reset_session_key = None, None- try:+ with bind_quiet_session_key(getattr(cli, "session_id", "") or "default"):try:result = cli.agent.run_conversation(user_message=effective_query, conversation_history=cli.conversation_history, **author_kwargs,@@ -4133,12 +4128,6 @@ def _run_quiet_single_query(cli, effective_query):if isinstance(continued, dict):result = continuedresponse = result.get("final_response", "") if isinstance(result, dict) else str(result)- finally:- if key_token is not None and reset_session_key is not None:- try:- reset_session_key(key_token)- except Exception:- pass# Surface backend errors that produced no visible output (e.g. invalid model slug# -> provider 4xx) on stderr so piped stdout stays clean.if (diff --git a/hermes_cli/quiet_single_query.py b/hermes_cli/quiet_single_query.pyindex a31bfa9ee10..b2e2179b591 100644--- a/hermes_cli/quiet_single_query.py+++ b/hermes_cli/quiet_single_query.py@@ -10,6 +10,7 @@ was never injected as a follow-up.from __future__ import annotations+import contextlibimport timefrom typing import Any, Callable@@ -17,12 +18,16 @@ from typing import Any, Callable_MAX_QUIET_NOTIFY_ROUNDS = 8def bind_quiet_session_key(session_id: str):- """Bind the approval/session key to *this* quiet session, not an inherited parent env."""+ """Bind the approval/session key to *this* quiet session for the enclosing ``with`` block."""from tools.approval_context import reset_current_session_key, set_current_session_keytoken = set_current_session_key(session_id or "default")- return token, reset_current_session_key+ try:+ yield+ finally:+ reset_current_session_key(token)def quiet_notify_linger_seconds() -> float: