The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): pass a CLI plugin command's argument through as typed
unsupportedpastelsc3563265e3c3
diff --git a/gateway/run_inbound_hooks.py b/gateway/run_inbound_hooks.pyindex 40bb54cdee0..f362929fd9a 100644--- a/gateway/run_inbound_hooks.py+++ b/gateway/run_inbound_hooks.py@@ -249,10 +249,12 @@ class GatewayInboundHooksMixin:return False, None, commandasync def _hm_run_plugin_handler(- self, plugin_handler, event: MessageEvent, source: SessionSource, session_entry=None+ self, plugin_handler, event: MessageEvent, source: SessionSource, session_entry=None, args=None) -> Optional[str]:"""Run a resolved plugin command handler for *source* → its reply text or None; raises what- the handler raises (``gateway/session_commands.py`` resolves the exact registered name)."""+ the handler raises (``gateway/session_commands.py`` resolves the exact registered name).+ *args* is the argument as typed (a local session's command); otherwise the message's+ command arguments, with the messaging dash repair of ``get_command_args``."""# The agent-turn path binds HERMES_SESSION_* via _set_session_env; this dispatch# sits before it, so a handler reading get_session_env() would see an empty or a# foreign (cron agent's os.environ) session (#108698). A local session's command@@ -263,7 +265,7 @@ class GatewayInboundHooksMixin:_plugin_context = build_session_context(source, self.config, session_entry)if session_entry is None:_plugin_context.session_key = self._session_key_for_source(source)- user_args = event.get_command_args().strip()+ user_args = event.get_command_args().strip() if args is None else argswith self._session_env_scope(_plugin_context):if asyncio.iscoroutinefunction(plugin_handler):result = await plugin_handler(user_args)diff --git a/gateway/session_commands.py b/gateway/session_commands.pyindex d95d36ca644..aba16d7b27b 100644--- a/gateway/session_commands.py+++ b/gateway/session_commands.py@@ -169,7 +169,8 @@ async def _run_runner_command(runner, live, name, arg, kind, shell):# the handler starts records this session as its parent.entry = await asyncio.to_thread(runner.session_store.lookup_by_session_key, live.route)try:- return await runner._hm_run_plugin_handler(handler, event, live.source, entry)+ # The argument as typed, like main's CLI: no messaging dash repair.+ return await runner._hm_run_plugin_handler(handler, event, live.source, entry, args=arg)except Exception as e: # main's CLI printed it; messaging (run_inbound_hooks) still only logs itlogger.warning("Plugin command dispatch failed: %s", e, exc_info=True)return t('cli.plugin.command_error', error=str(e) or type(e).__name__)diff --git a/tests/gateway/test_cli_plugin_command_in_gateway.py b/tests/gateway/test_cli_plugin_command_in_gateway.pyindex 3a0de1fcf15..84a11a12534 100644--- a/tests/gateway/test_cli_plugin_command_in_gateway.py+++ b/tests/gateway/test_cli_plugin_command_in_gateway.py@@ -55,6 +55,7 @@ def register(ctx):"key": get_session_env("HERMES_SESSION_KEY"),"parent": getattr(job, "parent_session_id", None), "started": started})ctx.register_command("probe-sid", sid, description="The calling session")+ ctx.register_command("probe-args", lambda arg: "ARGS=" + json.dumps(arg), description="Echo the argument")'''# One command per gateway life: A serves /alpha, the restarted B only /beta._LIFE = '''import os@@ -169,7 +170,8 @@ def test_cli_plugin_command_runs_in_the_gateway_and_reaches_its_mcp_registry(tmpout = capsys.readouterr().outcalls = list(wire.calls)typed_outs = {}- for typed in ('/probe_under', '/probe_only', '/probe-boom', '/probe-cwd', '/probe-sid'):+ for typed in ('/probe_under', '/probe_only', '/probe-boom', '/probe-cwd', '/probe-sid',+ '/probe-args 2026–2027 — x'):assert c._process_unregistered_slash(typed, typed) is Truetyped_outs[typed] = capsys.readouterr().outfinally:@@ -189,6 +191,9 @@ def test_cli_plugin_command_runs_in_the_gateway_and_reaches_its_mcp_registry(tmpident = json.loads(typed_outs['/probe-sid'].split('SID=', 1)[1].strip())assert ident['id'] == sid and ident['key'] == where['key'], identassert ident['parent'] == sid, ident+ # as typed: the messaging path's dash repair (MessageEvent.get_command_args) is not applied+ args = json.loads(typed_outs['/probe-args 2026–2027 — x'].split('ARGS=', 1)[1].strip())+ assert args == '2026–2027 — x', argsassert proc.pid != os.getpid()assert f'PLUGIN_PID={proc.pid} ' in out, out # the handler ran in the gateway processmcp = json.loads(json.loads(out.split('MCP=', 1)[1].strip())['result'])