The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bot-mode): the default profile is @hermes only when no real 'hermes' profile exists
Teknium446a38444e4c
diff --git a/gateway/session_bot.py b/gateway/session_bot.pyindex f069ccf7de1..a3488e007e7 100644--- a/gateway/session_bot.py+++ b/gateway/session_bot.py@@ -170,9 +170,11 @@ def _legacy_order(path, record):def _home(authority, actor, profile):from gateway.session_authorities import served_profile_name+ from tools.bot_mode_probe import _handle, _hermes_root, _rosterhome = Path(authority.db.db_path).parent.resolve()name = served_profile_name(home)- if actor.profile_id != authority.profile_id or profile not in (name, 'hermes' if name == 'default' else name):+ handle = _handle(name, [n for n, _d in _roster(_hermes_root(home))]) if name == 'default' else name+ if actor.profile_id != authority.profile_id or profile not in (name, handle):raise RuntimeStoreError('profile_mismatch')if 'session:submit' not in actor.capabilities:raise RuntimeStoreError('permission_denied')diff --git a/tests/tools/test_bot_mode_hermes_handle.py b/tests/tools/test_bot_mode_hermes_handle.pyindex 14e9aa35a6c..4dd43bdc67c 100644--- a/tests/tools/test_bot_mode_hermes_handle.py+++ b/tests/tools/test_bot_mode_hermes_handle.py@@ -33,3 +33,14 @@ def test_local_hermes_dm_lands_once_in_the_profile_that_owns_the_handle(tmp_pathassert ack["status"] == "queued" and ack["to"] == "@hermes"assert [home for home, _params in authority.calls] == [owner.resolve()]++[email protected]("real_hermes", [False, True])+def test_roster_shows_one_hermes_handle(tmp_path, real_hermes):+ root = _managed_home(tmp_path, teammates=("researcher", "hermes") if real_hermes else ("researcher",))++ teammates = bot_mode_probe.get_bot_mode_protocol_section(root / "profiles" / "researcher").split("Your teammates")[1]+ assert teammates.count("`@hermes`") == 1+ assert ("`@default`" in teammates) is real_hermes+ you = bot_mode_probe.get_bot_mode_protocol_section(root).split("Your teammates")[0]+ assert ("You are `@default`" if real_hermes else "You are `@hermes`") in youdiff --git a/tools/bot_mode_dm.py b/tools/bot_mode_dm.pyindex 55392000d60..93f76750e6d 100644--- a/tools/bot_mode_dm.py+++ b/tools/bot_mode_dm.py@@ -226,7 +226,7 @@ def message_agent_tool(target: str = "", message: str = "", task_id: Optional[stroster_homes = dict(_roster(root))roster = list(roster_homes)peers = _peers(root)- teammates = [_handle(n) for n in roster if n != me]+ teammates = [_handle(n, roster) for n in roster if n != me]def _roster_err(msg: str) -> str:return _err(msg, roster=teammates, peers=peers)@@ -242,10 +242,10 @@ def message_agent_tool(target: str = "", message: str = "", task_id: Optional[stif not raw_target:return _roster_err("target is required.")# Sender signature: the friendly name when the bot has one (#89720); the @handle stays the routing alias.- content = f"Message from π€ {_display_name(me, roster_homes.get(me, Path(home)))} (@{_handle(me)}): " + body+ content = f"Message from π€ {_display_name(me, roster_homes.get(me, Path(home)), roster)} (@{_handle(me, roster)}): " + bodydelivery = dict(task_id=task_id, agent=agent)# Attribution for the recipient's memory hooks; the text prefix above stays the human-facing signature.- author = {"id": f"bot:{me}", "name": _handle(me), "is_bot": True}+ author = {"id": f"bot:{me}", "name": _handle(me, roster), "is_bot": True}# Peer target: '<peer>/<agent>' or a bare registered peer name.peer_match = _PEER_TARGET_RE.match(raw_target)@@ -295,7 +295,7 @@ def message_agent_tool(target: str = "", message: str = "", task_id: Optional[st"(roles are listed in your system prompt).")# Local teammates are admitted through the profile authority; the argv only names the# profile for the runner's lock/home lookups and is never executed.- return _start_delivery([_hermes_cli(), "-p", resolved], content, f"@{_handle(resolved)}",+ return _start_delivery([_hermes_cli(), "-p", resolved], content, f"@{_handle(resolved, roster)}",stdin_file=False, profile_home=roster_homes[resolved], author=author, **delivery)@@ -306,7 +306,7 @@ def _try_relay_delivery(root: Path, raw_target: str, content: str, me: str, *,to drain; a background waiter is spawned immediately so the relayed reply wakesthe sender through the standard completion-notification path."""try:- from tools.bot_mode_probe import _handle, local_taken_forms+ from tools.bot_mode_probe import _handle, _hermes_root, _roster, local_taken_formsfrom tools.bot_relay import (EnvelopeRefusedError, _target_aliases, enqueue_envelope, read_remote_roster, remote_target_forms,resolve_remote_target, waiter_command,@@ -322,7 +322,8 @@ def _try_relay_delivery(root: Path, raw_target: str, content: str, me: str, *,if want in _target_aliases(r))return _err(f"'{raw_target}' exists on several connected machines β disambiguate with one of: {forms}.")try:- envelope = enqueue_envelope(root, target=match, message=content, sender_profile=me, sender_handle=_handle(me))+ envelope = enqueue_envelope(root, target=match, message=content, sender_profile=me,+ sender_handle=_handle(me, [n for n, _d in _roster(_hermes_root(root))]))except EnvelopeRefusedError as exc:# Fail fast: target definitively offline β nothing was queued.# Structured refusal so the agent can distinguish it from a resolution error ('runtime_offline'diff --git a/tools/bot_mode_probe.py b/tools/bot_mode_probe.pyindex b1bf9917f7f..b43064523bc 100644--- a/tools/bot_mode_probe.py+++ b/tools/bot_mode_probe.py@@ -65,9 +65,11 @@ def _profile_name(home: Path) -> str:return home.name if home.parent.name == "profiles" else "default"-def _handle(name: str) -> str:- # The mention middleware aliases the default profile as @hermes.- return "hermes" if name == "default" else name+def _handle(name: str, names: Collection[str]) -> str:+ """The @handle a local profile answers to; ``names`` are the roster's folder ids. The default+ profile is @hermes only while no real profile holds that name: a pre-reservation+ ``profiles/hermes`` keeps @hermes, and the default answers to @default."""+ return "hermes" if name == "default" and "hermes" not in names else namedef _profile_for_handle(handle: str, names: Collection[str]) -> str:@@ -174,11 +176,11 @@ def _friendly_names(profile_dir: Path) -> tuple[str, str]:return _swallow(_read, ("", ""))-def _display_name(name: str, profile_dir: Path) -> str:+def _display_name(name: str, profile_dir: Path, names: Collection[str]) -> str:"""Human-facing sender name, in the Desktop's ``botFriendlyNames`` order: Bot Mode title,then profile.yaml ``display_name`` (``hermes profile rename``), else the @handle β therenamed primary signs as ``Maia (@hermes)``, not ``hermes (@hermes)`` (#89720)."""- return next((n for n in _friendly_names(profile_dir) if n), None) or _handle(name)+ return next((n for n in _friendly_names(profile_dir) if n), None) or _handle(name, names)# Tokens the Desktop mention parser reserves; a bot titled "Hermes" never hijacks @hermes.@@ -237,7 +239,8 @@ def _remote_roster(root: Path) -> list[dict]:def local_taken_forms(root: Path) -> set[str]:"""Bare forms this gateway's own profiles answer to (handles + friendly-name slugs); a remoterow must not be offered under any of them, since local resolution wins (``_resolve_local_name``)."""- return {_handle(name) for name, _d in _roster(root)} | set(local_alias_map(root))+ names = [name for name, _d in _roster(root)]+ return {_handle(name, names) for name in names} | set(local_alias_map(root))def _remote_paragraph(root: Path) -> str:@@ -280,7 +283,9 @@ def _build_section(home: Path) -> str:if not _any_managed(root):return ""- roster_lines = [_bullet(f"@{_handle(name)}", _profile_role(d)) for name, d in _roster(root) if name != me]+ roster = _roster(root)+ names = [name for name, _d in roster]+ roster_lines = [_bullet(f"@{_handle(name, names)}", _profile_role(d)) for name, d in roster if name != me]roster_block = "\n".join(roster_lines) or "- (no teammates yet)"return (@@ -306,7 +311,7 @@ def _build_section(home: Path) -> str:"concisely via message_agent to their handle, and if it is a pure FYI ""with nothing to add, staying silent is fine β never ping-pong ""acknowledgements.\n"- f"You are `@{_handle(me)}`. Your teammates (live roster; roles from their "+ f"You are `@{_handle(me, names)}`. Your teammates (live roster; roles from their ""profiles):\n"f"{roster_block}"+ _remote_paragraph(home)