Skip to content

The agent that grows with you

feat(telemetry): count TUI and Desktop slash commands in shared metrics

teknium188bce5cf90de
diff --git a/tui_gateway/rpc_dispatch.py b/tui_gateway/rpc_dispatch.py
index 17bb684f137..78fc9dbcadb 100644
--- a/tui_gateway/rpc_dispatch.py
+++ b/tui_gateway/rpc_dispatch.py
@@ -39,9 +39,26 @@ def _handle_admitted_request(req: dict) -> dict | None:
if contract is not None and isinstance(response, dict) and isinstance(response.get("result"), dict):
_contracts.check_params_accepted(contract, params)
_contracts.check_result(contract, response["result"])
+ _count_slash_command(method, params, response)
return response
+# Client RPCs carrying a user-typed slash command -> the param naming it. Counted here, at the
+# client boundary, so slash.exec's internal command.dispatch hops and session.control intents
+# never count; a refused slash.exec (4018) counts on the client's command.dispatch fallback.
+_SLASH_COMMAND_RPC_PARAM = {"slash.exec": "command", "command.dispatch": "name"}
+
+
+def _count_slash_command(method: str, params: dict, response) -> None:
+ key = _SLASH_COMMAND_RPC_PARAM.get(method)
+ result = response.get("result") if key and isinstance(response, dict) else None
+ # An alias directive is re-dispatched by the client as its target, which counts then.
+ if not isinstance(result, dict) or result.get("type") == "alias":
+ return
+ from hermes_cli.observability.shared_metrics_events import record_slash_command
+ record_slash_command(command=str(params.get(key) or ""), surface=_resolve_session_platform())
+
+
def dispatch(req: dict, transport: Optional[Transport] = None) -> dict | None:
"""Route inbound RPCs — long handlers to the pool (returns None; the worker writes its own
response via the bound transport), everything else inline (returns the response dict).
diff --git a/tui_gateway/slash_worker.py b/tui_gateway/slash_worker.py
index f768701ff72..0c1a0c11c87 100644
--- a/tui_gateway/slash_worker.py
+++ b/tui_gateway/slash_worker.py
@@ -148,6 +148,7 @@ def main():
# MoA preset NAME to the configured real provider (#57283).
cli = HermesCLI(model=args.model or None, provider=args.provider or None,
compact=True, resume=args.session_key, verbose=False)
+ cli._slash_metrics_surface = None # tui_gateway's slash.exec already counted the command
# Spurious stdin-EOF recovery (same shared-file-description O_NONBLOCK issue as the gateway entry
# point — any child inheriting fd 0 can flip the flag).
_sw_recovery_times: list[float] = []