From 6f14242c4778c50098a4c565bd58260fecaf1181 Mon Sep 17 00:00:00 2001 From: "Dr. Mohammed Lubbad" Date: Fri, 27 Nov 2026 21:11:12 +0300 Subject: [PATCH] fix(hermes): use --format stream-json and always pass -q in build_exec_args hermes chat has no --json option (exits 2 with unrecognized arguments) and uses --format stream-json for JSONL output. Also always pass -q when dispatching a bare slash command so hermes chat runs in single-query mode instead of exiting 2 or entering the interactive REPL. Assisted-by: Hermes Agent (model: Gemini 4 Carbon, autonomous) --- docs/integrations/hermes.md | 10 ++-- .../integrations/hermes/__init__.py | 17 ++++--- tests/integrations/test_integration_hermes.py | 49 +++++++++++++++++-- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/docs/integrations/hermes.md b/docs/integrations/hermes.md index a6a21d1cf9..6fb2cd1b56 100644 --- a/docs/integrations/hermes.md +++ b/docs/integrations/hermes.md @@ -58,7 +58,9 @@ Ownership records are project-local, not tied to the global directory: ## Workflow Dispatch -Workflow steps use `hermes chat -Q`. Slash-prefixed prompts select a skill with -`-s`; remaining text is passed with `-q`. Other prompts use `-q` directly. -The adapter forwards a configured model with `-m` and requests `--json` for -structured output. +Workflow steps use `hermes chat -Q`. Slash-prefixed prompts preload the skill +with `-s` and pass the remaining text (or the slash command itself when no +extra arguments are given) with `-q` so `hermes chat` stays in non-interactive +single-query mode. Other prompts use `-q` directly. The adapter forwards a +configured model with `-m` and requests `--format stream-json` for structured +JSONL output. diff --git a/src/specify_cli/integrations/hermes/__init__.py b/src/specify_cli/integrations/hermes/__init__.py index 0297b0c40d..ee28f70d62 100644 --- a/src/specify_cli/integrations/hermes/__init__.py +++ b/src/specify_cli/integrations/hermes/__init__.py @@ -306,16 +306,21 @@ def build_exec_args( if model: args.extend(["-m", model]) if output_json: - args.append("--json") - - # If prompt starts with a slash command, pass it directly - # so Hermes can dispatch to the appropriate skill. + # ``hermes chat`` has no ``--json`` flag (exits 2 with + # ``unrecognized arguments: --json``); its ``--format`` option + # accepts ``text`` and ``stream-json`` (JSONL events). + args.extend(["--format", "stream-json"]) + + # If prompt starts with a slash command, preload the skill via ``-s`` + # and always pass a non-empty ``-q`` query. ``-s/--skills`` only + # preloads skills into the session; omitting ``-q`` makes + # ``--format stream-json`` exit 2 (``requires -q/--query``) and makes + # text mode enter the interactive REPL instead of single-query mode. if prompt.startswith("/"): command, _, remainder = prompt[1:].partition(" ") if command: args.extend(["-s", command]) - if remainder: - args.extend(["-q", remainder]) + args.extend(["-q", remainder if remainder.strip() else f"/{command}"]) else: args.extend(["-q", prompt]) else: diff --git a/tests/integrations/test_integration_hermes.py b/tests/integrations/test_integration_hermes.py index 421188a01e..da9dcc24c8 100644 --- a/tests/integrations/test_integration_hermes.py +++ b/tests/integrations/test_integration_hermes.py @@ -364,26 +364,62 @@ class TestHermesBuildExecArgs: def test_build_exec_args_default_shape(self): i = get_integration("hermes") + assert i is not None assert i.build_exec_args("/speckit-plan hi", output_json=True) == [ - "hermes", "chat", "-Q", "--json", "-s", "speckit-plan", "-q", "hi", + "hermes", "chat", "-Q", "--format", "stream-json", + "-s", "speckit-plan", "-q", "hi", + ] + + def test_build_exec_args_text_mode_omits_stream_json(self): + """Streaming dispatch (output_json=False) omits --format stream-json.""" + i = get_integration("hermes") + assert i is not None + assert i.build_exec_args("/speckit-plan hi", output_json=False) == [ + "hermes", "chat", "-Q", "-s", "speckit-plan", "-q", "hi", + ] + + def test_build_exec_args_bare_slash_command_keeps_query_flag(self): + """A bare slash command (e.g. /speckit-analyze) or whitespace-only + remainder must still pass -q so hermes chat runs in single-query mode + instead of exiting 2 under --format stream-json or hanging in REPL.""" + i = get_integration("hermes") + assert i is not None + assert i.build_exec_args("/speckit-analyze", output_json=True) == [ + "hermes", "chat", "-Q", "--format", "stream-json", + "-s", "speckit-analyze", "-q", "/speckit-analyze", + ] + assert i.build_exec_args("/speckit-analyze ", output_json=False) == [ + "hermes", "chat", "-Q", + "-s", "speckit-analyze", "-q", "/speckit-analyze", + ] + + def test_build_exec_args_plain_and_bare_slash_prompts(self): + i = get_integration("hermes") + assert i is not None + assert i.build_exec_args("plain prompt", output_json=False, model="m1") == [ + "hermes", "chat", "-Q", "-m", "m1", "-q", "plain prompt", + ] + assert i.build_exec_args("/", output_json=False) == [ + "hermes", "chat", "-Q", "-q", "/", ] def test_build_exec_args_honors_extra_args(self, monkeypatch): """SPECKIT_INTEGRATION_HERMES_EXTRA_ARGS is injected before the - canonical -m/--json/-s/-q flags (same env hook as codex/opencode/ + canonical -m/--format/-s/-q flags (same env hook as codex/opencode/ devin; hermes previously skipped _apply_extra_args_env_var entirely). """ monkeypatch.setenv( "SPECKIT_INTEGRATION_HERMES_EXTRA_ARGS", "--temperature 0.2" ) i = get_integration("hermes") + assert i is not None args = i.build_exec_args("/speckit-plan hi", output_json=True) assert args == [ "hermes", "chat", "-Q", "--temperature", "0.2", - "--json", "-s", "speckit-plan", "-q", "hi", + "--format", "stream-json", "-s", "speckit-plan", "-q", "hi", ] # Injected before the canonical flags so it can't displace them. - assert args.index("--temperature") < args.index("--json") + assert args.index("--temperature") < args.index("--format") assert args.index("--temperature") < args.index("-s") def test_build_exec_args_honors_executable_override(self, monkeypatch): @@ -391,4 +427,7 @@ def test_build_exec_args_honors_executable_override(self, monkeypatch): "SPECKIT_INTEGRATION_HERMES_EXECUTABLE", "/custom/hermes" ) i = get_integration("hermes") - assert i.build_exec_args("/speckit-plan hi")[0] == "/custom/hermes" + assert i is not None + exec_args = i.build_exec_args("/speckit-plan hi") + assert exec_args is not None + assert exec_args[0] == "/custom/hermes"