Skip to content

The agent that grows with you

feat(plugins): document and allowlist the platform-plugin public surface

Teknium14508f97f701
diff --git a/hermes_cli/plugin_validate_private_imports.py b/hermes_cli/plugin_validate_private_imports.py
index d5d75544626..d1380e6a6a3 100644
--- a/hermes_cli/plugin_validate_private_imports.py
+++ b/hermes_cli/plugin_validate_private_imports.py
@@ -46,6 +46,16 @@ _PUBLIC = frozenset({
"agent.runtime_cwd:resolve_agent_cwd", "agent.usage_pricing:CostResult", "hermes_cli.auth_constants:AuthError",
"tools.environments.base:BaseEnvironment", "tools.environments:BaseEnvironment", # package ``__all__``
"utils:atomic_json_write", "utils:read_json_or_empty",
+ # adding-platform-adapters.md § Public helpers for platform plugins
+ "gateway.platforms.access_policy_mixin:OwnAccessPolicyMixin", "tools.approval:resolve_gateway_approval",
+ "tools.clarify_gateway:get_pending", "tools.clarify_gateway:resolve_gateway_clarify",
+ "tools.clarify_gateway:mark_awaiting_text", "tools.clarify_gateway:SKIPPED",
+ "tools.url_safety:is_safe_url", "tools.url_safety:create_ssrf_safe_async_client",
+ "gateway.platforms._http_client_limits:platform_httpx_limits",
+ "hermes_cli.gateway_setup_wizard:print_setup_header", "hermes_cli.gateway_setup_wizard:confirm_reconfigure",
+ "hermes_cli.gateway_setup_wizard:offer_home_channel", "hermes_cli.gateway_setup_wizard:save_env_values",
+ "hermes_cli.gateway_setup_wizard:prompt_csv", "hermes_cli.setup:prompt", "hermes_cli.setup:prompt_choice",
+ "hermes_cli.setup:prompt_yes_no", "hermes_cli.cli_output",
})
_SHOWN = 10
diff --git a/tests/hermes_cli/test_plugin_validate_private_imports.py b/tests/hermes_cli/test_plugin_validate_private_imports.py
index 5ef360d0639..8019e8832aa 100644
--- a/tests/hermes_cli/test_plugin_validate_private_imports.py
+++ b/tests/hermes_cli/test_plugin_validate_private_imports.py
@@ -68,3 +68,34 @@ def test_documented_public_stdlib_and_own_package_imports_are_not_flagged(tmp_pa
sites = warning.split("release): ", 1)[1].split(". Use ctx.*")[0].split("; ")
assert sites == ["__init__.py:12 hermes_cli.plugins.get_plugin_manager"], sites
+
+
+_PLATFORM_PLUGIN_SEAMS = (
+ ("gateway.platforms.access_policy_mixin", "OwnAccessPolicyMixin"),
+ ("tools.approval", "resolve_gateway_approval"),
+ ("tools.clarify_gateway", "get_pending"),
+ ("tools.clarify_gateway", "resolve_gateway_clarify"),
+ ("tools.clarify_gateway", "mark_awaiting_text"),
+ ("gateway.platforms.helpers", "platform_http_client"),
+ ("gateway.platforms.base", "ssrf_redirect_guard"),
+ ("tools.url_safety", "create_ssrf_safe_async_client"),
+ ("tools.url_safety", "is_safe_url"),
+ ("gateway.platforms._http_client_limits", "platform_httpx_limits"),
+ ("hermes_cli.gateway_setup_wizard", "print_setup_header"),
+ ("hermes_cli.gateway_setup_wizard", "confirm_reconfigure"),
+ ("hermes_cli.gateway_setup_wizard", "offer_home_channel"),
+ ("hermes_cli.gateway_setup_wizard", "save_env_values"),
+ ("hermes_cli.gateway_setup_wizard", "prompt_csv"),
+)
+
+
+def test_platform_plugin_seams_are_public_and_exist(tmp_path):
+ """The documented platform-plugin helpers import cleanly AND raise no private-import finding."""
+ import importlib
+
+ for module, name in _PLATFORM_PLUGIN_SEAMS:
+ assert hasattr(importlib.import_module(module), name), f"{module}.{name}"
+ imports = "".join(f"from {module} import {name}\n" for module, name in _PLATFORM_PLUGIN_SEAMS)
+ plugin = _plugin(tmp_path / "chatplat", {"adapter.py": imports})
+
+ assert _private_warnings(validate_plugin_dir(plugin)) == []
diff --git a/website/docs/developer-guide/adding-platform-adapters.md b/website/docs/developer-guide/adding-platform-adapters.md
index a16cbbaecef..4631713eb36 100644
--- a/website/docs/developer-guide/adding-platform-adapters.md
+++ b/website/docs/developer-guide/adding-platform-adapters.md
@@ -212,7 +212,7 @@ When you call `ctx.register_platform()`, the following integration points are ha
| Gateway adapter creation | Registry checked before the built-in `_BUILTIN_ADAPTERS` table |
| Config parsing | `Platform._missing_()` accepts any platform name |
| Connected platform validation | Registry `validate_config()` called |
-| User authorization | `allowed_users_env` / `allow_all_env` checked |
+| User authorization | `allowed_users_env` / `allow_all_env` checked; `group_allowed_chats_env` / `allowlist_suppresses_pairing` (see below) |
| Env-only auto-enable | `env_enablement_fn` seeds `PlatformConfig.extra` + `home_channel` |
| YAML config bridge | `apply_yaml_config_fn` translates `config.yaml` keys into env vars / extras |
| Cron delivery | `cron_deliver_env_var` makes `deliver=<name>` work |
@@ -271,6 +271,56 @@ def register(ctx):
Feature-detect these fields with `dataclasses.fields(PlatformEntry)` as above so the plugin stays loadable on
older Hermes cores that predate them.
+## Authorization fields for chat platforms
+
+Two more optional `PlatformEntry` fields carry gateway authorization behaviour that core used to
+hard-code for its bundled platforms. Declare them and a plugin platform behaves the same way:
+
+| Field | Type / default | Effect |
+|---|---|---|
+| `group_allowed_chats_env` | `str = ''` | Env var holding comma-separated group/forum **chat** IDs. Any message from a listed chat is authorized, even without a `user_id` (anonymous admins, channel posts). Telegram declares `TELEGRAM_GROUP_ALLOWED_CHATS` and QQ Bot declares `QQ_GROUP_ALLOWED_USERS`. |
+| `allowlist_suppresses_pairing` | `bool = False` | When the platform's `allowed_users_env` (or `group_allowed_chats_env`) is set, unknown DM senders are ignored rather than sent a pairing code: the owner already restricted access. Most bundled chat platforms set it. |
+
+```python
+kwargs = dict(name="my_chat", label="My Chat", adapter_factory=MyChatAdapter, check_fn=check_requirements,
+ allowed_users_env="MY_CHAT_ALLOWED_USERS", allow_all_env="MY_CHAT_ALLOW_ALL_USERS")
+known = {f.name for f in dataclasses.fields(PlatformEntry)}
+for key, value in (("group_allowed_chats_env", "MY_CHAT_GROUP_ALLOWED_CHATS"),
+ ("allowlist_suppresses_pairing", True)):
+ if key in known: # older cores reject unknown kwargs
+ kwargs[key] = value
+ctx.register_platform(**kwargs)
+```
+
+## Public helpers for platform plugins
+
+A platform adapter needs more of core than a tool plugin does. These names are public: `hermes plugins
+validate` raises no private-import warning for them, and they keep their names and signatures across
+releases. Anything else under `gateway.*`, `tools.*` or `hermes_cli.*` is internal, and the validator
+lists each import of it.
+
+| Need | Import |
+|---|---|
+| Adapter base class, send results, media cache helpers | `gateway.platforms.base` (public names) |
+| SSRF-safe HTTP client: connect-time IP validation, per-redirect re-check, shared keepalive limits | `from gateway.platforms.helpers import platform_http_client` |
+| The pieces of that client, to build your own | `gateway.platforms.base.ssrf_redirect_guard` (httpx `response` hook), `tools.url_safety.create_ssrf_safe_async_client`, `tools.url_safety.is_safe_url`, `gateway.platforms._http_client_limits.platform_httpx_limits` |
+| Own DM/group policy (`dm_policy` / `group_policy` / allowlists) | `from gateway.platforms.access_policy_mixin import OwnAccessPolicyMixin` |
+| Resolve an approval from a native button | `from tools.approval import resolve_gateway_approval` |
+| Native clarify buttons | `tools.clarify_gateway`: `get_pending(clarify_id)` (the pending entry or `None`; read `session_key`, `choices`, `multi_select`), `resolve_gateway_clarify(clarify_id, text)`, `mark_awaiting_text(clarify_id)`, `SKIPPED` |
+| `setup_fn` wizard steps | `hermes_cli.gateway_setup_wizard`: `print_setup_header(title)`, `confirm_reconfigure(label, *env_vars)`, `offer_home_channel(home_var, user_id, what)`, `save_env_values(**values)`, `prompt_csv(text, default)`; prompts from `hermes_cli.setup` (`prompt`, `prompt_choice`, `prompt_yes_no`); output from `hermes_cli.cli_output` (`print_info`, `print_success`, `print_warning`, `print_error`); `.env` access through `hermes_cli.config` (`save_env_value`, `get_env_value`) |
+
+```python
+from gateway.platforms.helpers import platform_http_client
+
+async def connect(self) -> bool:
+ # timeout=30.0 and follow_redirects=True by default; any other httpx.AsyncClient kwarg passes through.
+ self._http = platform_http_client(headers={"User-Agent": "my-chat-bot/1.0"})
+ ...
+```
+
+`get_pending()` returns `None` once the clarify was answered, timed out or cleared, so compare the
+result by identity with the entry your card was rendered for before acting on a click.
+
## Standalone send-path extensions
A standalone platform can participate in host-driven outbound delivery through
diff --git a/website/docs/developer-guide/plugins/catalog-submission.md b/website/docs/developer-guide/plugins/catalog-submission.md
index 61864aa0d79..a3b2b655eb6 100644
--- a/website/docs/developer-guide/plugins/catalog-submission.md
+++ b/website/docs/developer-guide/plugins/catalog-submission.md
@@ -124,7 +124,8 @@ the gallery. There is no separate listing to maintain.
patching the same seam silently break each other, and every core release
can break both. `hermes plugins validate` refuses these at admission (`no
core override` check), and warns (without failing) on each import of an
- undocumented core module, by file and line. If the hook you need does not
+ undocumented core module, by file and line (platform adapters: see
+ [Public helpers for platform plugins](../adding-platform-adapters.md#public-helpers-for-platform-plugins)). If the hook you need does not
exist, open an issue describing it: we would rather add the seam than list
a patch.
10. **Dependency security policy is the plugin's.** Hermes's 3-day