From 9a4f3c7d1a3c963aa7838bd29c18903aedfb7a43 Mon Sep 17 00:00:00 2001 From: Offending Commit Date: Fri, 30 Oct 2026 14:02:49 -0500 Subject: [PATCH] fix(tools): read the reserved agent-loop tool names from Hermes The kit copied Hermes' intercepted tool names by hand as todo, memory, session_search and delegate_task. Hermes renamed todo to todo_list and rewrites the legacy names todo, cronjob, process, tour and tip before registry dispatch, so the kit let a plugin register todo_list or cronjob and Hermes would silently swallow it. validate_tool_name now reads model_tools._AGENT_LOOP_TOOLS and _LEGACY_TOOL_ALIASES from the host, falling back to a literal that matches v0.22.5 outside a host. A contract test pins the fallback to the deployed host's sets so the copy cannot drift again unnoticed. Claude-Session: https://claude.ai/code/session_01B6XeAU5Gn7ZaLQJVSg4AKC --- hermes_plugin_kit/__init__.py | 20 +++++++++++++++++--- tests/test_hermes_contract.py | 8 ++++++++ tests/test_kit.py | 6 ++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/hermes_plugin_kit/__init__.py b/hermes_plugin_kit/__init__.py index 5a2b1cc..f3db40d 100644 --- a/hermes_plugin_kit/__init__.py +++ b/hermes_plugin_kit/__init__.py @@ -137,7 +137,11 @@ def register(ctx): _MAX_LOG_CHARS = 200 _TOOL_NAME_RE = re.compile(r"^[a-z][a-z0-9_]*$") _COMMAND_NAME_RE = re.compile(r"^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$") -_AGENT_LOOP_TOOL_NAMES = frozenset({"todo", "memory", "session_search", "delegate_task"}) +# Fallback for _agent_loop_tool_names() outside a Hermes host; matches v0.22.5. +_AGENT_LOOP_TOOL_NAMES = frozenset({ + "todo_list", "memory", "session_search", "delegate_task", + "todo", "cronjob", "process", "tour", "tip", +}) _RESERVED_NAMESPACE_PREFIXES = ("memory_",) _SKILL_NAME_RE = re.compile(r"^[a-zA-Z0-9_-]+$") _HOST_TOOL_IMPORTS = { @@ -704,6 +708,15 @@ def as_dict(self) -> dict[str, Any]: # Tool naming # --------------------------------------------------------------------------- +def _agent_loop_tool_names() -> frozenset[str]: + """Names Hermes intercepts or rewrites before registry dispatch, read from the host itself.""" + try: + from model_tools import _AGENT_LOOP_TOOLS, _LEGACY_TOOL_ALIASES + except ImportError: # not inside a Hermes host (unit tests, tooling) + return _AGENT_LOOP_TOOL_NAMES + return frozenset(_AGENT_LOOP_TOOLS) | frozenset(_LEGACY_TOOL_ALIASES) + + def validate_tool_name(name: str, *, namespace: str | None = None) -> str: """Validate a Hermes plugin tool name and return it unchanged. @@ -717,7 +730,8 @@ def validate_tool_name(name: str, *, namespace: str | None = None) -> str: raise ValueError( f"tool name {name!r} must match {_TOOL_NAME_RE.pattern!r}" ) - if name in _AGENT_LOOP_TOOL_NAMES: + reserved = _agent_loop_tool_names() + if name in reserved: raise ValueError( f"tool name {name!r} is reserved by the Hermes agent loop" ) @@ -731,7 +745,7 @@ def validate_tool_name(name: str, *, namespace: str | None = None) -> str: raise ValueError( f"tool namespace {namespace!r} must match {_TOOL_NAME_RE.pattern!r}" ) - if namespace in _AGENT_LOOP_TOOL_NAMES: + if namespace in reserved: raise ValueError( f"tool namespace {namespace!r} is reserved by the Hermes agent loop" ) diff --git a/tests/test_hermes_contract.py b/tests/test_hermes_contract.py index bd29a2e..415a678 100644 --- a/tests/test_hermes_contract.py +++ b/tests/test_hermes_contract.py @@ -689,6 +689,14 @@ def test_lifecycle_calls_bind_to_real_plugincontext_signatures(self) -> None: for method in ("launch", "status", "wait", "cancel", "result", "reconnect"): self.assertTrue(callable(getattr(service, method))) + def test_reserved_tool_names_match_the_host(self) -> None: + """The kit's offline fallback must equal what the deployed Hermes intercepts.""" + from model_tools import _AGENT_LOOP_TOOLS, _LEGACY_TOOL_ALIASES # type: ignore + + host = frozenset(_AGENT_LOOP_TOOLS) | frozenset(_LEGACY_TOOL_ALIASES) + self.assertEqual(hpk._agent_loop_tool_names(), host) + self.assertEqual(hpk._AGENT_LOOP_TOOL_NAMES, host) + def test_host_tool_invocation_reaches_real_telegram_media_contract(self) -> None: """Exercise Hermes media parsing and Telegram formatting without network I/O.""" import asyncio diff --git a/tests/test_kit.py b/tests/test_kit.py index 47f8aaa..400d9d9 100644 --- a/tests/test_kit.py +++ b/tests/test_kit.py @@ -414,6 +414,12 @@ def reserved(args, **kwargs): """Reserved.""" return {} + def test_renamed_and_legacy_agent_loop_names_rejected(self) -> None: + # Hermes v0.22 intercepts todo_list and rewrites legacy names such as cronjob. + for name in ("todo_list", "cronjob", "tip"): + with self.subTest(name=name), self.assertRaisesRegex(ValueError, "reserved"): + hpk.validate_tool_name(name) + def test_reserved_core_namespace_prefix_rejected(self) -> None: with self.assertRaisesRegex(ValueError, "reserved Hermes core namespace"): hpk.tool_name("memory", "write", "entry")