Skip to content

The agent that grows with you

fix(bot-mode): a local @hermes DM reaches a real 'hermes' profile, not the default

Tekniume64697029747
diff --git a/tests/tools/test_bot_mode_hermes_handle.py b/tests/tools/test_bot_mode_hermes_handle.py
new file mode 100644
index 00000000000..14e9aa35a6c
--- /dev/null
+++ b/tests/tools/test_bot_mode_hermes_handle.py
@@ -0,0 +1,35 @@
+"""@hermes is the default profile's handle only while no real profile is named 'hermes'.
+
+A pre-reservation ``profiles/hermes`` keeps the handle: a local ``message_agent`` to @hermes
+reaches it, and the roster shows exactly one @hermes (the default answers to @default).
+"""
+
+import json
+
+import pytest
+
+from tests.tools.test_bot_mode_dm import _canonical_target, _capture_spawn, _FakeAgent, _managed_home
+from tools import bot_mode_dm, bot_mode_probe, bot_relay
+
+
[email protected](autouse=True)
+def _fresh_probe_cache():
+ bot_mode_probe._reset_cache_for_tests()
+ yield
+ bot_mode_probe._reset_cache_for_tests()
+
+
[email protected]("real_hermes", [False, True])
+def test_local_hermes_dm_lands_once_in_the_profile_that_owns_the_handle(tmp_path, monkeypatch, real_hermes):
+ _capture_spawn(monkeypatch)
+ monkeypatch.setattr(bot_relay, "_hermes_cli", lambda: "hermes")
+ monkeypatch.setattr(bot_mode_dm, "_dm_dir", lambda: tmp_path)
+ root = _managed_home(tmp_path, teammates=("researcher", "hermes") if real_hermes else ("researcher",))
+ owner = root / "profiles" / "hermes" if real_hermes else root
+ authority = _canonical_target(monkeypatch, root, root / "profiles" / "hermes")
+
+ ack = json.loads(bot_mode_dm.message_agent_tool(
+ target="@hermes", message="ping", agent=_FakeAgent(root / "profiles" / "researcher")))
+
+ assert ack["status"] == "queued" and ack["to"] == "@hermes"
+ assert [home for home, _params in authority.calls] == [owner.resolve()]
diff --git a/tools/bot_mode_dm.py b/tools/bot_mode_dm.py
index fa65742d6e6..55392000d60 100644
--- a/tools/bot_mode_dm.py
+++ b/tools/bot_mode_dm.py
@@ -168,15 +168,17 @@ def ensure_message_agent_tool(agent: Any) -> bool:
def _resolve_local_name(target: str, roster: list[str], root: Path | None = None) -> Optional[str]:
- """Map a target to a local profile FOLDER id: 'hermes' → 'default'; an exact folder id
+ """Map a target to a local profile FOLDER id: 'hermes' → 'default' unless a real 'hermes'
+ profile holds that handle (``_profile_for_handle``); an exact folder id
(case-insensitive); else — when ``root`` is given — a friendly name or its Desktop @-slug
(profile.yaml ``display_name`` / Bot Mode title: 'Scribe', '@scribe', 'Dr. Foo' → 'foo').
Ambiguous friendly names resolve to None so a DM never lands on the wrong bot (#100671)."""
want = target.strip().lower()
if not want:
return None
- if want == "hermes":
- return "default" if "default" in roster else None
+ from tools.bot_mode_probe import _profile_for_handle
+
+ want = _profile_for_handle(want, roster)
exact = next((name for name in roster if name.lower() == want), None)
if exact is not None or root is None:
return exact
diff --git a/tools/bot_mode_probe.py b/tools/bot_mode_probe.py
index 6392ce3b896..b1bf9917f7f 100644
--- a/tools/bot_mode_probe.py
+++ b/tools/bot_mode_probe.py
@@ -15,6 +15,7 @@ from __future__ import annotations
import os
import re
import threading
+from collections.abc import Collection
from pathlib import Path
_PROTOCOL_HEADING = "## Messaging other agents"
@@ -69,6 +70,12 @@ def _handle(name: str) -> str:
return "hermes" if name == "default" else name
+def _profile_for_handle(handle: str, names: Collection[str]) -> str:
+ """The folder id a bare @handle names on this install: @hermes is the default profile's alias
+ only while no real profile holds that name (a pre-reservation ``profiles/hermes`` keeps it)."""
+ return "default" if handle == "hermes" and "hermes" not in names else handle
+
+
def _roster(root: Path) -> list[tuple[str, Path]]:
"""(name, dir) for the default profile + every live named profile, sorted. Same identity
predicate as ``profile list``: infra dirs (``sessions/``, ``logs/``) and tombstones are not
diff --git a/tui_gateway/methods_bot_relay.py b/tui_gateway/methods_bot_relay.py
index a036b95e1b6..727e0833b02 100644
--- a/tui_gateway/methods_bot_relay.py
+++ b/tui_gateway/methods_bot_relay.py
@@ -96,12 +96,13 @@ def _(rid, params: dict, _root=_relay_root) -> dict:
forwarded = {key: value for key, value in params.items() if key not in sender_fields}
if author:
forwarded["author"] = author
- resolved = 'default' if profile.lower() == 'hermes' else profile
root = _root()
# Same identity predicate as `profile list`: infra dirs and tombstones under profiles/ are
# not teammates (#99392), so a DM never targets one.
- from tools.bot_mode_probe import _roster
- home = dict(_roster(root)).get(resolved)
+ from tools.bot_mode_probe import _profile_for_handle, _roster
+ roster = dict(_roster(root))
+ resolved = _profile_for_handle('hermes', roster) if profile.lower() == 'hermes' else profile
+ home = roster.get(resolved)
if home is None:
return _err(rid, 4092, f"no profile '{profile}' on this gateway", data={'reason': 'unknown_profile'})
if isinstance(forwarded.get("message"), str):