Skip to content

The agent that grows with you

fix(plugins): keep a context keyword whose name only a positional-only first parameter shares

Teknium5f274827ffcd
diff --git a/hermes_cli/plugin_command_dispatch.py b/hermes_cli/plugin_command_dispatch.py
index c550908337f..3356df21894 100644
--- a/hermes_cli/plugin_command_dispatch.py
+++ b/hermes_cli/plugin_command_dispatch.py
@@ -23,7 +23,8 @@ def invoke_plugin_command(handler: Callable, raw_args: str, **context: Any) -> A
# The first positional parameter receives raw_args whatever its name (``def h(source, **kw)``
# must not get ``source`` twice).
if parameters and parameters[0].kind is not inspect.Parameter.KEYWORD_ONLY:
- context = {k: v for k, v in context.items() if k != parameters[0].name}
+ if parameters[0].kind is inspect.Parameter.POSITIONAL_OR_KEYWORD:
+ context = {k: v for k, v in context.items() if k != parameters[0].name}
parameters = parameters[1:]
if any(p.kind is inspect.Parameter.VAR_KEYWORD for p in parameters):
return handler(raw_args, **context)
diff --git a/tests/hermes_cli/test_plugin_command_source.py b/tests/hermes_cli/test_plugin_command_source.py
index 2b5ff062ce5..a7b2b6467e3 100644
--- a/tests/hermes_cli/test_plugin_command_source.py
+++ b/tests/hermes_cli/test_plugin_command_source.py
@@ -21,8 +21,12 @@ def test_handlers_get_only_the_context_they_declare():
def first_named_source(source, **kwargs): # raw_args fills `source`; it is never passed twice
return source, sorted(kwargs)
+ def first_positional_only(source, /, **kwargs): # its name is not a keyword: kwargs keep source
+ return source, kwargs["source"]
+
assert invoke_plugin_command(legacy, "a", **CONTEXT) == ("a",)
assert invoke_plugin_command(named, "a", **CONTEXT) == ("a", "sid", "telegram")
assert invoke_plugin_command(catch_all, "a", **CONTEXT) == ("a", CONTEXT)
assert invoke_plugin_command(positional_only, "a", **CONTEXT) == ("a", None)
assert invoke_plugin_command(first_named_source, "a", **CONTEXT) == ("a", ["platform", "session_id", "session_key"])
+ assert invoke_plugin_command(first_positional_only, "a", **CONTEXT) == ("a", "src")