The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(platforms): plugin-declared rows reach callers that run before or outside discovery
Tekniumb035c13e77ad
diff --git a/agent/system_prompt.py b/agent/system_prompt.pyindex 29b2a4e65da..dc09facac3e 100644--- a/agent/system_prompt.py+++ b/agent/system_prompt.py@@ -417,6 +417,12 @@ def _default_platform_hint(platform_key: str) -> str:try:from gateway.platform_registry import platform_registry_entry = platform_registry.get(platform_key)+ if _entry is None:+ # A prompt can be built before anything ran plugin discovery (direct builders,+ # one-shot callers); the hint lives on the plugin's entry, so discover (idempotent).+ from hermes_cli.plugins import discover_plugins+ discover_plugins()+ _entry = platform_registry.get(platform_key)hint = (_entry and _entry.platform_hint) or ""except Exception:passdiff --git a/gateway/config_env.py b/gateway/config_env.pyindex bf270762989..faf3b19673b 100644--- a/gateway/config_env.py+++ b/gateway/config_env.py@@ -46,7 +46,11 @@ def _enable_credential_names(platform: Platform) -> tuple:return _ENV_ENABLE_CREDENTIALS[platform]from gateway.platform_registry import platform_registryentry = platform_registry.get(platform.value)- return tuple(getattr(entry, "env_enable_credentials", ()) or ())+ names = tuple(getattr(entry, "env_enable_credentials", ()) or ())+ if not names:+ from gateway.platform_env import bundled_env_rows+ names = (bundled_env_rows(platform.value) or ((), ()))[1]+ return namesdef _warn_explicit_disable_beats_env(platform: Platform) -> None:@@ -237,6 +241,26 @@ def _configured_plugin_entries(config: GatewayConfig) -> list:return []+def _bundled_env_fallbacks(config: GatewayConfig, entries: list) -> list:+ """Env rows of bundled platforms with activation evidence but no registry entry (discovery+ suppressed or the plugin disabled), read from their ``gateway_env`` files; see+ ``gateway.platform_env.bundled_env_rows``. They only run the env steps, never the enable pass."""+ from types import SimpleNamespace+ from gateway.platform_activation import activation_predicate+ from gateway.platform_env import _BUNDLED_ENV_SIBLINGS, bundled_env_rows+ have = {getattr(e, "name", "") for e in entries}+ names = (set(Platform._scan_bundled_plugin_platforms()[0]) | set(_BUNDLED_ENV_SIBLINGS)) - have+ if not names:+ return []+ wanted = activation_predicate(yaml_cfg={}, platform_names=config.platforms)+ out = []+ for name in sorted(names):+ rows = bundled_env_rows(name) if wanted(name) else None+ if rows and rows[0]:+ out.append(SimpleNamespace(name=name, env_overrides=rows[0], env_enable_credentials=rows[1]))+ return out++def _platform_rank(entry) -> int:# Static ``Platform`` members first, in enum order (the order the env rows always ran in), so# ``config.platforms`` insertion order stays deterministic and independent of registry load order.@@ -333,7 +357,7 @@ def _apply_env_overrides(config: GatewayConfig) -> None:disabling (needs every platform's final ``enabled``), and the marker scrub, which must be last."""entries = _configured_plugin_entries(config)- _apply_plugin_env_overrides(config, entries)+ _apply_plugin_env_overrides(config, entries + _bundled_env_fallbacks(config, entries))_api_server(config)_webhook(config)_msgraph_webhook(config)diff --git a/gateway/platform_env.py b/gateway/platform_env.pyindex ce0b810daa0..e9626a7fe28 100644--- a/gateway/platform_env.py+++ b/gateway/platform_env.py@@ -9,10 +9,13 @@ Import-light on purpose (only ``gateway.config``): adapters import it at module"""import contextlib+import functools+import importlib.utilimport jsonimport loggingfrom dataclasses import dataclassfrom functools import partial+from pathlib import Pathfrom typing import Any, Callable, Optionalfrom gateway.config import GatewayConfig, HomeChannel, Platform, PlatformConfig, _getenv_str@@ -173,3 +176,38 @@ class EnvCred:self.then(config, platform_config)if self.home:env_home_channel(config, self.platform, self.home, strip=self.home_strip)+++# --- bundled rows without the plugin -------------------------------------------++# Entries a bundled plugin registers under a name other than its directory, with the export prefix.+_BUNDLED_ENV_SIBLINGS = {"wecom_callback": ("wecom", "CALLBACK_")}+++def _bundled_gateway_env_module(directory: str) -> Any:+ """``plugins/platforms/<directory>/gateway_env.py`` executed from its file under a private name:+ the plugin package (``__init__``, adapter, ``register()``) is never imported. None when absent."""+ path = Path(__file__).resolve().parent.parent / "plugins" / "platforms" / directory / "gateway_env.py"+ if not path.is_file():+ return None+ spec = importlib.util.spec_from_file_location(f"_hermes_bundled_gateway_env_{directory}", path)+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+++def bundled_env_rows(name: str) -> Optional[tuple]:+ """``(env_overrides, env_enable_credentials)`` a BUNDLED platform plugin declares, read without+ the plugin. For when its registry entry is absent: discovery suppressed (a parked profile's+ config read, ``HERMES_SAFE_MODE``) or the plugin disabled. These rows were core's own table, and+ the duplicate-credential guard and the explicit-disable warning still need them then."""+ from gateway.config import Platform+ directory, prefix = _BUNDLED_ENV_SIBLINGS.get(name, (name, ""))+ if directory not in Platform._scan_bundled_plugin_platforms()[0]:+ return None+ module = _bundled_gateway_env_module(directory)+ if module is None:+ return None+ return (tuple(getattr(module, f"{prefix}ENV_OVERRIDES", ()) or ()),+ tuple(getattr(module, f"{prefix}ENV_ENABLE_CREDENTIALS", ()) or ()))diff --git a/hermes_cli/web_routers/messaging.py b/hermes_cli/web_routers/messaging.pyindex 0801f4a65ad..8a03ceedc3c 100644--- a/hermes_cli/web_routers/messaging.py+++ b/hermes_cli/web_routers/messaging.py@@ -971,7 +971,9 @@ def _count_csv(value: str) -> int:return len([part for part in (value or "").split(",") if part.strip()])-def _messaging_platform_posture(platform_id: str, entry: dict[str, Any], scoped: bool) -> dict[str, Any] | None:+def _messaging_platform_posture(+ platform_id: str, entry: dict[str, Any], scoped: bool, authz_env: tuple[str, str]+) -> dict[str, Any] | None:"""Auth-posture verdict for a CONNECTED platform (must be called inside the profilescope, after the connectivity chain has already reported ``connected``).@@ -991,8 +993,10 @@ def _messaging_platform_posture(platform_id: str, entry: dict[str, Any], scoped:Everything failing → deny-all: the connection is up but no sender can get through,which the Channels "Test" button must not render as a plain green "connected".Returns ``None`` when the platform has no per-user authorization surface at all.+ *authz_env* is :func:`_platform_authz_env_names`, resolved OUTSIDE the profile scope (see+ :func:`_env_value_rules`: the scope's registry overlay may not hold the entry)."""- allowed_env, allow_all_env = _platform_authz_env_names(platform_id)+ allowed_env, allow_all_env = authz_envif not allowed_env:return None@@ -1053,6 +1057,7 @@ def _messaging_platform_posture(platform_id: str, entry: dict[str, Any], scoped:@router.post("/api/messaging/platforms/{platform_id}/test")async def test_messaging_platform(platform_id: str, profile: Optional[str] = None):entry = _require_platform(platform_id)+ authz_env = _platform_authz_env_names(platform_id)def _run():with _profile_scope(profile) as scoped_dir:@@ -1062,7 +1067,7 @@ async def test_messaging_platform(platform_id: str, profile: Optional[str] = Non# Still inside the profile scope: load_env()/load_config()/PairingStore# must resolve the ACTIVE profile's env/config/pairing store, not the# dashboard process's root home.- posture = _messaging_platform_posture(platform_id, entry, scoped_dir is not None)+ posture = _messaging_platform_posture(platform_id, entry, scoped_dir is not None, authz_env)return payload, posturepayload, posture = await asyncio.to_thread(_run)diff --git a/plugins/platforms/buzz/adapter.py b/plugins/platforms/buzz/adapter.pyindex 454151d672d..34f97fbd8f4 100644--- a/plugins/platforms/buzz/adapter.py+++ b/plugins/platforms/buzz/adapter.py@@ -219,22 +219,26 @@ def _replace_media_refs(text: str, replacements: list[tuple[int, int, str]]) ->return re.sub(r"\n{3,}", "\n\n", re.sub(r"[ \t]+\n", "\n", text)).strip()-def _load_nostr_auth():- """Import sibling nostr_auth loader-agnostically (the test loader imports this file as a bare module)."""+def _load_sibling(name: str):+ """Import a sibling module loader-agnostically (the test loader imports this file as a bare module)."""+ import importlibtry:- from . import nostr_auth # type: ignore[no-redef]- return nostr_auth+ return importlib.import_module(f".{name}", __package__) if __package__ else _load_sibling_file(name)except ImportError:- import importlib.util- path = Path(__file__).with_name("nostr_auth.py")- spec = importlib.util.spec_from_file_location("plugin_adapter_buzz_nostr_auth", path)- assert spec is not None and spec.loader is not None- module = importlib.util.module_from_spec(spec)- spec.loader.exec_module(module)- return module+ return _load_sibling_file(name)-_nostr_auth = _load_nostr_auth()+def _load_sibling_file(name: str):+ import importlib.util+ path = Path(__file__).with_name(f"{name}.py")+ spec = importlib.util.spec_from_file_location(f"plugin_adapter_buzz_{name}", path)+ assert spec is not None and spec.loader is not None+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+++_nostr_auth = _load_sibling("nostr_auth")# bech32 (BIP-173) npub <-> hex so mention detection and allow-lists accept either form.from gateway.authz_mixin import (@@ -2003,9 +2007,8 @@ def interactive_setup() -> None:def register(ctx):"""Plugin entry point: called by the Hermes plugin system."""- from .send_targets import SEND_ENTRY_KWARGSctx.register_platform(- **SEND_ENTRY_KWARGS, # send_message target syntax + routing+ **_load_sibling("send_targets").SEND_ENTRY_KWARGS, # send_message target syntax + routingname="buzz", label="Buzz", adapter_factory=lambda cfg: BuzzAdapter(cfg), check_fn=check_requirements,validate_config=validate_config, is_connected=is_connected, required_env=["BUZZ_RELAY_URL", "BUZZ_PRIVATE_KEY"],install_hint="Requires the buzz CLI binary (https://github.com/block/buzz) on PATH or at BUZZ_CLI_PATH",