diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.py index 73f3cba435df..de5fe909153b 100644 --- a/agent/agent_runtime_helpers.py +++ b/agent/agent_runtime_helpers.py @@ -1619,6 +1619,7 @@ def invoke_tool(agent, function_name: str, function_args: dict, effective_task_i from hermes_cli.plugins import get_pre_tool_call_block_message block_message = get_pre_tool_call_block_message( function_name, function_args, task_id=effective_task_id or "", + session_id=agent.session_id or "", ) except Exception: pass diff --git a/agent/tool_executor.py b/agent/tool_executor.py index 358c1a0a8f70..d26d943d9916 100644 --- a/agent/tool_executor.py +++ b/agent/tool_executor.py @@ -212,6 +212,7 @@ def execute_tool_calls_concurrent(agent, assistant_message, messages: list, effe from hermes_cli.plugins import get_pre_tool_call_block_message block_message = get_pre_tool_call_block_message( function_name, function_args, task_id=effective_task_id or "", + session_id=agent.session_id or "", ) except Exception: block_message = None @@ -589,6 +590,7 @@ def execute_tool_calls_sequential(agent, assistant_message, messages: list, effe from hermes_cli.plugins import get_pre_tool_call_block_message _block_msg = get_pre_tool_call_block_message( function_name, function_args, task_id=effective_task_id or "", + session_id=agent.session_id or "", ) except Exception: pass diff --git a/tests/hermes_cli/test_plugins.py b/tests/hermes_cli/test_plugins.py index b78e8b2921d0..248267fac424 100644 --- a/tests/hermes_cli/test_plugins.py +++ b/tests/hermes_cli/test_plugins.py @@ -532,6 +532,38 @@ def test_first_valid_block_wins(self, monkeypatch): ) assert get_pre_tool_call_block_message("terminal", {}) == "first blocker" + def test_session_id_forwarded_to_hook(self, monkeypatch): + """Verify session_id kwarg reaches the plugin hook (regression test).""" + captured_kwargs = {} + + def _capture_hook(hook_name, **kwargs): + captured_kwargs.update(kwargs) + return [] + + monkeypatch.setattr( + "hermes_cli.plugins.invoke_hook", + _capture_hook, + ) + get_pre_tool_call_block_message( + "terminal", {}, task_id="t1", session_id="sess-42", + ) + assert captured_kwargs.get("session_id") == "sess-42" + + def test_session_id_defaults_to_empty_string(self, monkeypatch): + """When session_id is omitted, hook receives empty string default.""" + captured_kwargs = {} + + def _capture_hook(hook_name, **kwargs): + captured_kwargs.update(kwargs) + return [] + + monkeypatch.setattr( + "hermes_cli.plugins.invoke_hook", + _capture_hook, + ) + get_pre_tool_call_block_message("todo", {}, task_id="t1") + assert captured_kwargs.get("session_id") == "" + class TestThreadToolWhitelist: """Tests for the thread-local tool whitelist used by background review forks."""