The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(send): name the default-root gateway and external secret sources in the 'not configured' error
teknium121642218445e
diff --git a/hermes_cli/send_cmd.py b/hermes_cli/send_cmd.pyindex 87b5fa0e249..f977119bf5d 100644--- a/hermes_cli/send_cmd.py+++ b/hermes_cli/send_cmd.py@@ -111,8 +111,13 @@ def _list_targets(platform_filter: Optional[str], *, json_mode: bool) -> int:if not platforms:print("No messaging platforms configured or no channels discovered yet.")print("Set one up with `hermes gateway setup`, or run the gateway once so")- from hermes_constants import get_hermes_home- print(f"channel discovery can populate {get_hermes_home() / 'channel_directory.json'}.")+ from hermes_constants import get_default_hermes_root, get_hermes_home, hermes_home_key+ home, root = get_hermes_home(), get_default_hermes_root()+ print(f"channel discovery can populate {home / 'channel_directory.json'}.")+ # A gateway started from the default root writes that root's directory, never this profile's.+ if hermes_home_key(root) != hermes_home_key(home) and (root / "channel_directory.json").exists():+ print(f"A gateway running from {root} already has {root / 'channel_directory.json'}; "+ f"this shell is scoped to profile home {home}, which has none.")return _SUCCESS_EXIT# Unfiltered: the shared formatter over the merged view. Filtered: a minimal view of our own.diff --git a/tests/hermes_cli/test_send_cmd.py b/tests/hermes_cli/test_send_cmd.pyindex e5c255a673c..c88e634d2ae 100644--- a/tests/hermes_cli/test_send_cmd.py+++ b/tests/hermes_cli/test_send_cmd.py@@ -407,3 +407,31 @@ def test_help_and_empty_list_hint_name_the_resolved_home(tmp_path, monkeypatch,out = capsys.readouterr().outassert str(home / "channel_directory.json") in outassert "~/.hermes" not in out+++def test_empty_list_hint_names_default_root_directory_under_profile_home(tmp_path, monkeypatch, capsys):+ """Under ``HERMES_HOME=<root>/profiles/<p>`` the ``--list`` empty state says the default root already holds+ a ``channel_directory.json`` (written by a gateway running from that root), so the user knows which home+ the gateway is serving (#114272 step 5)."""+ import sys+ import types++ root = tmp_path / "hermes"+ profile = root / "profiles" / "coder"+ profile.mkdir(parents=True)+ (root / "channel_directory.json").write_text("{}", encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(profile))++ fake_gw_config = types.ModuleType("gateway.config")+ fake_gw_config.load_gateway_config = lambda: types.SimpleNamespace(get_connected_platforms=lambda: [])+ monkeypatch.setitem(sys.modules, "gateway.config", fake_gw_config)+ fake_dir = types.ModuleType("gateway.channel_directory")+ fake_dir.load_directory = lambda: {"updated_at": None, "platforms": {}}+ fake_dir.format_directory_for_display = lambda platforms=None: ""+ monkeypatch.setitem(sys.modules, "gateway.channel_directory", fake_dir)++ assert send_cmd._list_targets(None, json_mode=False) == 0+ out = capsys.readouterr().out+ assert f"channel discovery can populate {profile / 'channel_directory.json'}." in out+ assert f"A gateway running from {root} already has {root / 'channel_directory.json'}" in out+ assert f"scoped to profile home {profile}" in outdiff --git a/tests/tools/test_send_message_tool.py b/tests/tools/test_send_message_tool.pyindex 0c67840db9e..0f53d78b9b8 100644--- a/tests/tools/test_send_message_tool.py+++ b/tests/tools/test_send_message_tool.py@@ -1842,3 +1842,32 @@ def test_not_configured_error_names_resolved_home_and_consulted_sources(tmp_pathassert f"{home / '.env'} (no DISCORD_BOT_TOKEN)" in errassert f"{home / 'config.yaml'} (platforms.discord.enabled: false)" in errassert "environment (DISCORD_BOT_TOKEN unset)" in err+++def test_not_configured_error_names_default_root_gateway_and_secret_sources(tmp_path, monkeypatch):+ """Under ``HERMES_HOME=<root>/profiles/<p>`` the error says a live gateway from the default root has the+ platform connected (its credentials never came from this profile's ``.env``) and lists external secret+ sources by name only (#114272 step 5)."""+ import json+ import os++ from gateway.config import GatewayConfig+ from tools.send_message_tool import _resolve_platform_config++ root = tmp_path / "hermes"+ profile = root / "profiles" / "coder"+ profile.mkdir(parents=True)+ (root / "gateway_state.json").write_text(+ json.dumps({"pid": os.getpid(), "platforms": {"discord": {"state": "connected"}}}), encoding="utf-8")+ (profile / ".env").write_text("FIRECRAWL_API_KEY=x\n", encoding="utf-8")+ (profile / "config.yaml").write_text(+ "secrets:\n bitwarden:\n enabled: false\n session_token: SECRET-VALUE\n", encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(profile))+ monkeypatch.delenv("DISCORD_BOT_TOKEN", raising=False)++ _, _, _, err = _resolve_platform_config("discord", GatewayConfig())++ assert (f"A gateway (pid {os.getpid()}) running from {root} has discord connected; "+ f"this shell is scoped to profile home {profile} whose .env has no DISCORD_BOT_TOKEN.") in err+ assert "external secret sources (bitwarden: disabled)" in err+ assert "SECRET-VALUE" not in errdiff --git a/tools/send_message_tool.py b/tools/send_message_tool.pyindex 2d038e831de..4d554de62ae 100644--- a/tools/send_message_tool.py+++ b/tools/send_message_tool.py@@ -324,9 +324,10 @@ def _not_configured_error(platform_name, platform, entry):if env_path.exists() else "missing"try:from hermes_cli.config_effective import load_user_config_effective- block = (load_user_config_effective(config_path) or {}).get("platforms", {}).get(platform_name)+ user_config = load_user_config_effective(config_path) or {}+ block = user_config.get("platforms", {}).get(platform_name)except Exception:- block = None+ user_config, block = {}, Noneif not config_path.exists():config_state = "missing"elif not isinstance(block, dict):@@ -337,20 +338,44 @@ def _not_configured_error(platform_name, platform, entry):config_state = f"platforms.{platform_name} has no token"env_state = f"{names} set" if any(_getenv(n) for n in env_names) else f"{names} unset"msg = (f"Platform '{platform_name}' is not configured. Looked in: {env_path} ({dotenv_state}), "- f"{config_path} ({config_state}), environment ({env_state}).")- # The gateway can hold a token only in its own process environment; a fresh CLI cannot see it.+ f"{config_path} ({config_state}), environment ({env_state}), "+ f"external secret sources ({_secret_sources_state(user_config)}).")+ # The gateway can hold a token only in its own process environment; a fresh CLI cannot see it. A+ # gateway started from the default root (the reporter's shell had HERMES_HOME=<root>/profiles/<p>)+ # never reads this profile's .env at all.try:from gateway.status import read_runtime_status, runtime_status_pid_is_live- record = read_runtime_status()- state = ((record or {}).get("platforms") or {}).get(platform_name, {}).get("state")- if state == "connected" and "present" not in dotenv_state and runtime_status_pid_is_live(record):- msg += (f" A gateway (pid {record.get('pid')}) running from {home} has {platform_name} connected, "- f"so its credentials live only in that process's environment; add {names} to {env_path}.")+ from hermes_constants import get_default_hermes_root, hermes_home_key+ root = get_default_hermes_root()+ gateways = [(home, read_runtime_status())]+ if hermes_home_key(root) != hermes_home_key(home):+ gateways.append((root, read_runtime_status(root / "gateway_state.json")))+ for gw_home, record in gateways:+ state = ((record or {}).get("platforms") or {}).get(platform_name, {}).get("state")+ if state != "connected" or "present" in dotenv_state or not runtime_status_pid_is_live(record):+ continue+ msg += f" A gateway (pid {record.get('pid')}) running from {gw_home} has {platform_name} connected"+ msg += (f", so its credentials live only in that process's environment; add {names} to {env_path}."+ if gw_home is home else+ f"; this shell is scoped to profile home {home} whose .env has no {names}.")except Exception:passreturn msg+def _secret_sources_state(user_config):+ """``name: enabled|disabled`` for every registered secret source with a ``secrets.<name>`` section,+ or ``none configured``; names only, never values."""+ try:+ from agent.secret_sources.registry import list_sources+ secrets_cfg = user_config.get("secrets") if isinstance(user_config.get("secrets"), dict) else {}+ states = [f"{s.name}: {'enabled' if s.is_enabled(secrets_cfg[s.name]) else 'disabled'}"+ for s in list_sources() if isinstance(secrets_cfg.get(s.name), dict)]+ except Exception:+ states = []+ return ", ".join(states) or "none configured"++def _home_chat_id(config, platform, platform_name):"""``(home chat_id, None)`` or ``(None, actionable error)``; Weixin also honours WEIXIN_HOME_CHANNEL."""home = config.get_home_channel(platform)diff --git a/website/docs/guides/pipe-script-output.md b/website/docs/guides/pipe-script-output.mdindex b87bf014400..1e750a7dac0 100644--- a/website/docs/guides/pipe-script-output.md+++ b/website/docs/guides/pipe-script-output.md@@ -195,9 +195,13 @@ If a platform reports `not configured`, the error lists the exact files itread and what each one held, e.g.`Looked in: C:\Users\me\AppData\Local\hermes\.env (no DISCORD_BOT_TOKEN),C:\Users\me\AppData\Local\hermes\config.yaml (no platforms.discord block),-environment (DISCORD_BOT_TOKEN unset)`. When a gateway started from the same-home has that platform connected, the token only exists in the gateway's-process environment — add it to that home's `.env` so `hermes send` can use it.+environment (DISCORD_BOT_TOKEN unset), external secret sources (none configured)`.+When a gateway started from the same home has that platform connected, the+token only exists in the gateway's process environment — add it to that home's+`.env` so `hermes send` can use it. When your shell is scoped to a profile home+(`HERMES_HOME=<root>/profiles/<name>`) but the connected gateway runs from the+default root, the error says so — the gateway never read the profile's `.env`,+and `hermes send --list` points at the root's `channel_directory.json`.A live gateway is only required for **plugin platforms** that rely on apersistent adapter connection (for example, a custom plugin that keeps