Skip to content

The agent that grows with you

fix: ACP sends ordinary text that starts with '/' to the model

Teknium31d12d6b31dd
diff --git a/acp_adapter/gateway_server.py b/acp_adapter/gateway_server.py
index a6a1d416369..56d3604523c 100644
--- a/acp_adapter/gateway_server.py
+++ b/acp_adapter/gateway_server.py
@@ -69,6 +69,24 @@ def _text(payload):
return text if isinstance(text, str) else ""
+def _slash_command(text):
+ """Canonical Hermes command name ``text`` invokes, or None for ordinary text.
+
+ Only a registered command (or alias) is a command: ``/etc/hosts is wrong`` or ``/tmp/x``
+ (a path, the same rule ``MessageEvent.get_command`` applies) and unknown ``/words`` are
+ prompt text for the model. A registered command this surface does not carry still raises
+ ``unsupported_command`` in ``slash_mutation`` rather than reaching the owner as text."""
+ stripped = text.lstrip()
+ if not stripped.startswith('/'):
+ return None
+ name = stripped.split(None, 1)[0][1:]
+ if not name or '/' in name:
+ return None
+ from hermes_cli.commands import resolve_command
+ command = resolve_command(name)
+ return command.name if command is not None else None
+
+
class GatewayACPAgent(acp.Agent):
def __init__(self):
self._conn = None
@@ -282,10 +300,11 @@ class GatewayACPAgent(acp.Agent):
raise GatewayClientError("unknown_execution")
from acp_adapter.content import _content_blocks_to_openai_user_content
text, attachments = _stage_user_content(_content_blocks_to_openai_user_content(prompt))
- if text.lstrip().startswith('/') and not attachments:
+ command = _slash_command(text) if not attachments else None
+ if command is not None:
from hermes_cli.gateway_mutations import slash_mutation
parts = text.strip().split(None, 1)
- operation, payload = slash_mutation(parts[0], parts[1] if len(parts) > 1 else '')
+ operation, payload = slash_mutation('/' + command, parts[1] if len(parts) > 1 else '')
if operation == 'branch':
raise GatewayClientError('use_acp_fork_session')
client = await self._client()
diff --git a/tests/acp_adapter/test_gateway_slash_text.py b/tests/acp_adapter/test_gateway_slash_text.py
new file mode 100644
index 00000000000..d73017311d7
--- /dev/null
+++ b/tests/acp_adapter/test_gateway_slash_text.py
@@ -0,0 +1,39 @@
+"""Only registered Hermes commands are slash commands; other text starting with '/' is a prompt."""
+import asyncio
+from unittest.mock import AsyncMock
+
+import acp
+import pytest
+
+from acp_adapter.gateway_server import GatewayACPAgent
+from hermes_cli.gateway_client import GatewayClientError
+
+
[email protected]("text", ["/etc/hosts is wrong", "/tmp/build.log shows the failure", "/notacommand please"])
+async def test_path_and_unknown_slash_text_is_submitted_as_the_prompt(text):
+ agent = GatewayACPAgent()
+ agent._gateway = AsyncMock()
+ agent._snapshots["s"] = {}
+
+ async def rpc(method, **params):
+ assert method == "prompt.submit"
+ await agent._project({"session_id": "s", "type": "message.complete", "admission_id": "a",
+ "payload": {"outcome": "completed", "text": "ok"}})
+ return {"admission_id": "a"}
+
+ agent._gateway.rpc.side_effect = rpc
+ response = await asyncio.wait_for(agent.prompt([acp.text_block(text)], "s"), 5)
+ assert response.stop_reason == "end_turn"
+ assert agent._gateway.rpc.await_args.kwargs["text"] == text
+
+
+async def test_registered_command_this_surface_does_not_carry_is_still_refused_locally():
+ # A Hermes command is never forwarded as text the owner might execute as a control.
+ agent = GatewayACPAgent()
+ agent._gateway = AsyncMock()
+ agent._snapshots["s"] = {}
+ with pytest.raises(GatewayClientError, match="unsupported_command"):
+ await agent.prompt([acp.text_block("/reset")], "s")
+ agent._gateway.rpc.assert_not_awaited()