The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(notifications): one notice classification, one config read, one diagnostic-metadata helper
kshitijk4poor94a029091df3
diff --git a/agent/notification_presentation.py b/agent/notification_presentation.pyindex f4ac9558b14..e99fd28e7e5 100644--- a/agent/notification_presentation.py+++ b/agent/notification_presentation.py@@ -29,25 +29,19 @@ def diagnostic_process_event(event: dict) -> bool:def notification_config_snapshot():- """Read the canonical owning effective config once; presentation fails open."""- from copy import deepcopy- from hermes_cli.config_effective import load_user_config_effective- try:- config = load_user_config_effective()- return deepcopy(config) if isinstance(config, dict) else {}- except Exception:- return {}+ """Read the owning effective config once per turn (the loader already returns a fresh copy)."""+ from gateway.warning_notifications import effective_user_config+ return effective_user_config()@contextmanagerdef notification_policy_snapshot(agent, platform, config):- """Bind one foreground policy for callbacks, including worker threads."""- from copy import deepcopy+ """Bind one foreground policy for callbacks, including worker threads. ``config`` is read-only."""missing = object()saved = {key: getattr(agent, key, missing)for key in ("_notification_config", "_notification_platform")}try:- agent._notification_config = deepcopy(config)+ agent._notification_config = configagent._notification_platform = platformyieldfinally:diff --git a/cli-config.yaml.example b/cli-config.yaml.exampleindex 8f44bd3af0a..46e1712b89b 100644--- a/cli-config.yaml.example+++ b/cli-config.yaml.example@@ -1798,6 +1798,14 @@ display:# false: Only keep/send the final responseinterim_assistant_messages: true+ # Opt-in: hide automatic warning/diagnostic notifications (compression, retry+ # and fallback notices, credit/subagent failure lines, inactivity and watchdog+ # stalls, media-delivery fallbacks, cron failure alerts) on this surface.+ # Requested results, approvals, clarifications and command outcomes are never+ # hidden, and nothing is removed from the logs. Per-platform override under+ # display.platforms.<platform>.suppress_warning_notifications.+ suppress_warning_notifications: false+# Gateway-only long-running status heartbeats.# When false, the platform does not receive periodic "⏳ Working — N min"# notifications even if agent.gateway_notify_interval is non-zero. Thediff --git a/gateway/run_turn.py b/gateway/run_turn.pyindex 84a7279b962..bc3cc7619c0 100644--- a/gateway/run_turn.py+++ b/gateway/run_turn.py@@ -24,6 +24,7 @@ from gateway.media_repair import repair_explicit_computer_use_media_pathsfrom gateway.platforms.base import BasePlatformAdapter, ProcessingOutcomefrom gateway.platforms.event import MessageEventfrom gateway.response_filters import display_kind_for_event, is_machinery_display_kind+from gateway.warning_notifications import diagnostic_metadata, diagnostic_turn_muted, diagnostic_wake_mutedfrom gateway.session import (SessionSource, _session_key_namespace, build_channel_continuity_note,build_session_context,@@ -1843,7 +1844,6 @@ class GatewayTurnMixin:):"""Final delivery decisions: intentional silence, voice reply, streamed-turn media/footer.Returns the text for the adapter to send, or ``None`` when already delivered."""- from gateway.warning_notifications import diagnostic_wake_mutedif diagnostic_wake_muted(event):return None# Intentional silence is a delivery decision: the [SILENT] turn stays persisted (alternation).@@ -2109,10 +2109,7 @@ class GatewayTurnMixin:persist_user_timestamp=prepared.persist_user_timestamp,persist_user_display_kind=prepared.persist_user_display_kind,persist_user_display_metadata={- "gateway_input_owner": prepared.persistence_owner,- **({"notification_category": "diagnostic"}- if event.internal and (event.metadata or {}).get("notification_category") == "diagnostic" else {}),- },+ "gateway_input_owner": prepared.persistence_owner, **diagnostic_metadata(event)},message_type=event.message_type,scheduled_heartbeat=bool(getattr(event, "_heartbeat_session_id", None)),)@@ -2990,7 +2987,6 @@ class GatewayTurnMixin:**{name: getattr(disp, name) for name in self._DISPLAY_TO_TURN_CTX}, **turn_params,)turn_runner = TurnRunner(self, turn_ctx)- from gateway.warning_notifications import diagnostic_turn_mutedturn_ctx.mute_notification_reply = diagnostic_turn_muted(turn_ctx.persist_user_display_metadata, source.platform, turn_ctx.user_config)# Agent tool-lifecycle callbacks live on the runner (bound methods, same signatures).@@ -3783,10 +3779,7 @@ class GatewayTurnMixin:event_message_id=next_message_id, inbound_message_id=next_inbound_id,channel_prompt=next_channel_prompt, message_type=next_message_type,persist_user_display_kind=next_display_kind,- persist_user_display_metadata=(- {"notification_category": "diagnostic"}- if pending_event is not None and pending_event.internal- and (pending_event.metadata or {}).get("notification_category") == "diagnostic" else None),+ persist_user_display_metadata=diagnostic_metadata(pending_event) or None,)except asyncio.CancelledError:await _run_followup_processing_hook(diff --git a/gateway/run_turn_runner.py b/gateway/run_turn_runner.pyindex c38e4e1a029..8e14df26ec6 100644--- a/gateway/run_turn_runner.py+++ b/gateway/run_turn_runner.py@@ -1156,11 +1156,10 @@ class TurnRunner:"""Credits / out-of-band notices (usage bands, depletion, restored) fire from the agent'ssync worker thread; hop onto the gateway loop. Fired-once latch lives on the cached agent."""from gateway.run import render_notice_line- from gateway.warning_notifications import render_notification+ from gateway.warning_notifications import is_diagnostic_notice, render_notificationif self._ctx.mute_notification_reply or not self._status_live():return- diagnostic = (getattr(notice, "level", None) in {"warn", "error"}- or str(getattr(notice, "key", "") or "").startswith("credits."))+ diagnostic = is_diagnostic_notice(notice)def present():try:line = render_notice_line(notice)diff --git a/gateway/warning_notifications.py b/gateway/warning_notifications.pyindex 1c32dca88b6..03e8e604f00 100644--- a/gateway/warning_notifications.py+++ b/gateway/warning_notifications.py@@ -15,6 +15,37 @@ def is_warning_status(event_type: str, message: str) -> bool:return event_type == "warn" or isinstance(message, DiagnosticText)+def is_diagnostic_notice(notice) -> bool:+ """Out-of-band ``AgentNotice`` classification shared by the gateway, TUI and CLI sinks.++ Credit-service notices are automatic diagnostics at every level (usage bands are ``info``,+ ``credits.restored`` is ``success``); everything else is diagnostic only when it warns.+ """+ return (getattr(notice, "level", None) in {"warn", "error"}+ or str(getattr(notice, "key", "") or "").startswith("credits."))+++def diagnostic_metadata(event) -> dict:+ """``{"notification_category": "diagnostic"}`` for a trusted diagnostic-only wake, else ``{}``.++ Only internal wakes may classify a turn; human content never does.+ """+ if getattr(event, "internal", False) and (getattr(event, "metadata", None) or {}).get(+ "notification_category") == "diagnostic":+ return {"notification_category": "diagnostic"}+ return {}+++def effective_user_config() -> dict:+ """The active profile's effective config, or ``{}`` when it cannot be read (presentation fails open)."""+ from hermes_cli.config_effective import load_user_config_effective+ try:+ config = load_user_config_effective()+ except Exception:+ return {}+ return config if isinstance(config, dict) else {}++def diagnostic_turn_muted(display_metadata, platform, user_config=None) -> bool:"""One admission rule for every surface: a diagnostic-category wake mutes its turn'spresentation only when the owning policy hides diagnostics. Human content never mutes."""@@ -63,12 +94,8 @@ def warning_notifications_enabled(platform, user_config=None) -> bool:Unknown values never opt in; null inherits via the canonical display resolver."""if user_config is None:- from hermes_cli.config_effective import load_user_config_effective- try:- user_config = load_user_config_effective()- except Exception:- user_config = {}- if not isinstance(user_config, dict):+ user_config = effective_user_config()+ elif not isinstance(user_config, dict):user_config = {}platform_key = getattr(platform, "value", platform)return not resolve_display_setting(user_config, platform_key, "suppress_warning_notifications", False)diff --git a/hermes_cli/cli_stream_mixin.py b/hermes_cli/cli_stream_mixin.pyindex 9bad5695e95..611fb309605 100644--- a/hermes_cli/cli_stream_mixin.py+++ b/hermes_cli/cli_stream_mixin.py@@ -74,12 +74,12 @@ class CLIStreamMixin:if not text:returnlevel = getattr(notice, "level", "info") or "info"- from gateway.warning_notifications import render_notification+ from gateway.warning_notifications import is_diagnostic_notice, render_notificationdef queue_notice():if not hasattr(self, "_pending_credit_notices"):self._pending_credit_notices = []self._pending_credit_notices.append((level, text))- render_notification(queue_notice, platform="cli", diagnostic=level in {"warn", "error"},+ render_notification(queue_notice, platform="cli", diagnostic=is_diagnostic_notice(notice),user_config=getattr(getattr(self, "agent", None), "_notification_config", None))except Exception:passdiff --git a/tests/tui_gateway/test_credit_producer_suppression.py b/tests/tui_gateway/test_credit_producer_suppression.pyindex 9aa25a5d789..457a987532f 100644--- a/tests/tui_gateway/test_credit_producer_suppression.py+++ b/tests/tui_gateway/test_credit_producer_suppression.py@@ -53,5 +53,7 @@ def test_actual_credit_capture_depletion_and_recovery(tmp_path, monkeypatch, setlevels = [row[0] for row in projected] if surface == "cli" else [frame["params"]["payload"]["level"] for frame in projected]assert ("error" in levels) is not (setting is True)- assert "success" in levels # recovery is informational, not a warning+ # Every credit-service notice is an automatic diagnostic, recovery included: a "restored"+ # line after a hidden depletion notice would be orphan noise (same rule as the gateway).+ assert ("success" in levels) is not (setting is True)assert sum(n.key == "credits.restored" for n in observed) == 1diff --git a/tui_gateway/agent_callbacks.py b/tui_gateway/agent_callbacks.pyindex 96468334eb6..adc2085c2be 100644--- a/tui_gateway/agent_callbacks.py+++ b/tui_gateway/agent_callbacks.py@@ -108,7 +108,8 @@ def _agent_thinking_update(sid: str, text: str) -> None:def _agent_notice_update(sid: str, notice) -> None:- if not _agent_presentation_enabled(sid, diagnostic=notice.level in {"warn", "error"}):+ from gateway.warning_notifications import is_diagnostic_notice+ if not _agent_presentation_enabled(sid, diagnostic=is_diagnostic_notice(notice)):return_emit("notification.show", sid,{"text": notice.text, "level": notice.level, "kind": notice.kind,diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.mdindex 5eeabdfc332..1469ee645de 100644--- a/website/docs/user-guide/configuration.md+++ b/website/docs/user-guide/configuration.md@@ -2024,6 +2024,7 @@ display:focus_view: false # CLI focus view (/focus) — reduced output, display-onlyplatforms: {} # Per-platform display overrides (see below)interim_assistant_messages: true # Gateway: send natural mid-turn assistant updates as separate messages+ suppress_warning_notifications: false # Opt-in: hide automatic warning/diagnostic notices (see messaging guide)show_commentary: true # Codex models: deliver commentary-channel progress narration as visible mid-turn updatesskin: default # Built-in or custom CLI skin (see user-guide/features/skins)personality: "" # Legacy cosmetic field still surfaced in some summariesdiff --git a/website/docs/user-guide/messaging/index.md b/website/docs/user-guide/messaging/index.mdindex b32be955656..a9b3594c3ba 100644--- a/website/docs/user-guide/messaging/index.md+++ b/website/docs/user-guide/messaging/index.md@@ -839,8 +839,10 @@ text in a user request or an ordinary result is not filtered by its wording.Suppression changes presentation, not execution. Existing logs, stored diagnosticcontent, retry decisions, failure state, scheduler bookkeeping and notification-cursors remain available. A diagnostic-only internal wake can still execute, but-its unsolicited text, media and streaming presentation are muted. Structured+cursors remain available. A diagnostic-only internal wake (a subagent or credit+failure, a Kanban crash notice) still runs its agent turn — so the agent can act on+the failure and the session history stays consistent — and that turn is billed as+usual; only its unsolicited text, media and streaming presentation are muted. Structuredapproval and clarification controls, direct command/API outcomes and requestedresults are not converted into success or discarded. API failure flags, statuscodes and usage remain truthful even when diagnostic text is hidden.