The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(telemetry): add shared_metrics.slash_command RPC; gateway stops counting slash.exec
teknium1b73225cc1c00
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.tsindex f960cb28828..04c7bdec145 100644--- a/apps/shared/src/gateway-contract.generated.ts+++ b/apps/shared/src/gateway-contract.generated.ts@@ -656,6 +656,15 @@ export interface SharedMetricsSetParams {send?: booleanfirst_run?: boolean}+/** ``command`` is the raw typed name (no leading ``/``, no args); the backend canonicalizes it against the published registry. ``session_id`` scopes the count to that session's profile. */+export interface SharedMetricsSlashCommandParams {+ profile?: string | null+ command: string+ session_id?: string | null+}+export interface SharedMetricsSlashCommandResult {+ ok: boolean+}export interface ModelOptionsParams {profile?: string | nullsession_id?: string | null@@ -5150,6 +5159,8 @@ export interface RpcMethods {'setup.status': { params: ProfileParams; result: SetupStatusResult }/** Write both shared-metrics opt-ins at once (send requires collection) and reconcile consent windows. */'shared_metrics.set': { params: SharedMetricsSetParams; result: SharedMetricsConsentResult }+ /** Count one user-typed slash command (fire-and-forget; a no-op unless shared metrics are on). */+ 'shared_metrics.slash_command': { params: SharedMetricsSlashCommandParams; result: SharedMetricsSlashCommandResult }/** Pure read of the focused profile's shared-metrics opt-ins (collection, upload, answered). */'shared_metrics.status': { params: ProfileParams; result: SharedMetricsConsentResult }/** Run a safe (non-dangerous) shell command captured for ``!cmd`` / inline substitution. */@@ -5435,6 +5446,7 @@ export const RPC_METHODS = ['setup.runtime_check','setup.status','shared_metrics.set',+ 'shared_metrics.slash_command','shared_metrics.status','shell.exec','skills.manage',diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.jsonindex 388f9639e70..716dacae7e8 100644--- a/apps/shared/src/gateway-contract.openrpc.json+++ b/apps/shared/src/gateway-contract.openrpc.json@@ -3606,6 +3606,24 @@}}},+ {+ "name": "shared_metrics.slash_command",+ "summary": "Count one user-typed slash command (fire-and-forget; a no-op unless shared metrics are on).",+ "params": [+ {+ "name": "params",+ "schema": {+ "$ref": "#/components/schemas/SharedMetricsSlashCommandParams"+ }+ }+ ],+ "result": {+ "name": "result",+ "schema": {+ "$ref": "#/components/schemas/SharedMetricsSlashCommandResult"+ }+ }+ },{"name": "shared_metrics.status","summary": "Pure read of the focused profile's shared-metrics opt-ins (collection, upload, answered).",@@ -31952,6 +31970,59 @@"title": "SharedMetricsSetParams","type": "object"},+ "SharedMetricsSlashCommandParams": {+ "additionalProperties": false,+ "description": "``command`` is the raw typed name (no leading ``/``, no args); the backend canonicalizes it\nagainst the published registry. ``session_id`` scopes the count to that session's profile.",+ "properties": {+ "profile": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Profile"+ },+ "command": {+ "title": "Command",+ "type": "string"+ },+ "session_id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Session Id"+ }+ },+ "required": [+ "command"+ ],+ "title": "SharedMetricsSlashCommandParams",+ "type": "object"+ },+ "SharedMetricsSlashCommandResult": {+ "additionalProperties": false,+ "properties": {+ "ok": {+ "title": "Ok",+ "type": "boolean"+ }+ },+ "required": [+ "ok"+ ],+ "title": "SharedMetricsSlashCommandResult",+ "type": "object"+ },"ShellExecParams": {"additionalProperties": false,"properties": {diff --git a/tui_gateway/contracts/config_free_tier_control.py b/tui_gateway/contracts/config_free_tier_control.pyindex 759298557cf..7a702a817fe 100644--- a/tui_gateway/contracts/config_free_tier_control.py+++ b/tui_gateway/contracts/config_free_tier_control.py@@ -240,6 +240,23 @@ method("shared_metrics.set", params=SharedMetricsSetParams, result=SharedMetricsdoc="Write both shared-metrics opt-ins at once (send requires collection) and reconcile consent windows.")+class SharedMetricsSlashCommandParams(ProfileParams):+ """``command`` is the raw typed name (no leading ``/``, no args); the backend canonicalizes it+ against the published registry. ``session_id`` scopes the count to that session's profile."""++ command: str+ session_id: str | None = None+++class SharedMetricsSlashCommandResult(Result):+ ok: bool+++method("shared_metrics.slash_command", params=SharedMetricsSlashCommandParams,+ result=SharedMetricsSlashCommandResult,+ doc="Count one user-typed slash command (fire-and-forget; a no-op unless shared metrics are on).")++# ── model.options ─────────────────────────────────────────────────────────────────────────────diff --git a/tui_gateway/methods_shared_metrics.py b/tui_gateway/methods_shared_metrics.pyindex 6729a47d6e6..270417c7440 100644--- a/tui_gateway/methods_shared_metrics.py+++ b/tui_gateway/methods_shared_metrics.py@@ -85,5 +85,17 @@ def _(rid, params: dict) -> dict:return _ok(rid, _shared_metrics_consent(cfg))+@method("shared_metrics.slash_command")+@_profile_scoped+def _(rid, params: dict) -> dict:+ """The Desktop and Ink TUI dispatchers call this once per user-typed slash command, locally+ handled ones included; the gateway never counts slash.exec / command.dispatch itself, so+ each command lands exactly once. Always ``{ok: true}`` (the events API never raises)."""+ from hermes_cli.observability.shared_metrics_events import record_slash_command++ record_slash_command(command=str(params.get("command") or ""), surface=_resolve_session_platform())+ return _ok(rid, {"ok": True})++def register(server) -> None:bind_module(globals(), server, skip=("_",))diff --git a/tui_gateway/rpc_dispatch.py b/tui_gateway/rpc_dispatch.pyindex 78fc9dbcadb..17bb684f137 100644--- a/tui_gateway/rpc_dispatch.py+++ b/tui_gateway/rpc_dispatch.py@@ -39,26 +39,9 @@ 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 ownresponse via the bound transport), everything else inline (returns the response dict).diff --git a/tui_gateway/slash_worker.py b/tui_gateway/slash_worker.pyindex 14e03bf191e..9383b351284 100644--- a/tui_gateway/slash_worker.py+++ b/tui_gateway/slash_worker.py@@ -148,7 +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+ cli._slash_metrics_surface = None # the TUI/Desktop client already counted the typed commandcli.is_slash_worker = True# 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).