Skip to content

The agent that grows with you

refactor(signal): plugin wiring lives in register.py, like QQ Bot and Yuanbao

Teknium42762d6a6436
diff --git a/plugins/platforms/signal/__init__.py b/plugins/platforms/signal/__init__.py
index 15b98c45fb2..81795be6b66 100644
--- a/plugins/platforms/signal/__init__.py
+++ b/plugins/platforms/signal/__init__.py
@@ -1,6 +1,6 @@
# Absolute import (not ``from .adapter``): the plugin loader executes this package under a synthetic
# ``hermes_plugins.platforms__signal`` name, and the adapter's own absolute sibling imports would then
# load a second ``plugins.platforms.signal.adapter``. One canonical name = one SignalAdapter class.
-from plugins.platforms.signal.adapter import register
+from plugins.platforms.signal.register import register
__all__ = ["register"]
diff --git a/plugins/platforms/signal/adapter.py b/plugins/platforms/signal/adapter.py
index ac1fa5f88af..93477c3378b 100644
--- a/plugins/platforms/signal/adapter.py
+++ b/plugins/platforms/signal/adapter.py
@@ -39,7 +39,7 @@ from plugins.platforms.signal.signal_rate_limit import (
SIGNAL_BATCH_PACING_NOTICE_THRESHOLD, SIGNAL_MAX_ATTACHMENTS_PER_MSG, SIGNAL_RATE_LIMIT_MAX_ATTEMPTS,
SignalRateLimitError, _extract_retry_after_seconds, _format_wait, _is_signal_rate_limit_error,
_signal_send_timeout, get_scheduler)
-from gateway.platforms._shared import env_is_connected, get_scoped_secret as _sig_secret
+from gateway.platforms._shared import get_scoped_secret as _sig_secret
from utils import TRUTHY_STRINGS
logger = logging.getLogger(__name__)
@@ -173,15 +173,6 @@ def validate_signal_config(config: PlatformConfig) -> bool:
return bool(http_url and account)
-_env_configured = env_is_connected("SIGNAL_HTTP_URL", "SIGNAL_ACCOUNT")
-
-
-def _is_connected(config: PlatformConfig) -> bool:
- """URL + account from config/scoped env, else ``.env``: a plain CLI process never loads ``.env``
- into the environment, and the old static setup row read it, so a ``.env``-only profile stays
- "configured" in ``hermes gateway setup``."""
- return validate_signal_config(config) or _env_configured(config)
-
class SignalAdapter(BasePlatformAdapter):
"""Signal messenger adapter using signal-cli HTTP daemon."""
@@ -990,37 +981,3 @@ class SignalAdapter(BasePlatformAdapter):
result = await self._rpc("getContact", {"account": self.account, "contactAddress": chat_id})
name = (result.get("name") or result.get("profileName")) if isinstance(result, dict) else None
return {"name": name or chat_id, "type": "dm", "chat_id": chat_id}
-
-
-def _validate_config(config: PlatformConfig) -> bool:
- """``validate_config``: same warning the core instantiation path logged before the move."""
- if validate_signal_config(config):
- return True
- logger.warning("Signal: SIGNAL_HTTP_URL or SIGNAL_ACCOUNT not configured")
- return False
-
-
-async def _standalone_send(pconfig, chat_id, message, *, thread_id=None, media_files=None, force_document=False):
- from plugins.platforms.signal.standalone import standalone_send
- return await standalone_send(pconfig, chat_id, message, thread_id=thread_id, media_files=media_files,
- force_document=force_document)
-
-
-def _interactive_setup() -> None:
- from plugins.platforms.signal.setup import interactive_setup
- interactive_setup()
-
-
-def register(ctx) -> None:
- """Plugin entry point β€” called by the Hermes plugin system."""
- ctx.register_platform(
- name="signal", label="Signal", adapter_factory=SignalAdapter,
- check_fn=check_signal_requirements, validate_config=_validate_config,
- is_connected=_is_connected, required_env=["SIGNAL_HTTP_URL", "SIGNAL_ACCOUNT"],
- install_hint="Signal: runtime requirements not met", setup_fn=_interactive_setup,
- allowed_users_env="SIGNAL_ALLOWED_USERS", allow_all_env="SIGNAL_ALLOW_ALL_USERS",
- cron_deliver_env_var="SIGNAL_HOME_CHANNEL",
- # Out-of-process sends speak raw JSON-RPC and bypass SignalAdapter.send()'s chunking, so
- # send_message splits at the adapter's limit through this field.
- standalone_sender_fn=_standalone_send, max_message_length=MAX_MESSAGE_LENGTH,
- emoji="πŸ“‘", pii_safe=True, allow_update_command=True)
diff --git a/plugins/platforms/signal/register.py b/plugins/platforms/signal/register.py
new file mode 100644
index 00000000000..37f27b3a481
--- /dev/null
+++ b/plugins/platforms/signal/register.py
@@ -0,0 +1,46 @@
+"""Signal plugin registration: configured/validate checks and ``register``."""
+
+import logging
+
+from gateway.config import PlatformConfig
+from gateway.platforms._shared import env_is_connected
+
+# Absolute imports (see __init__.py): one canonical module per file.
+from plugins.platforms.signal.adapter import (
+ MAX_MESSAGE_LENGTH, SignalAdapter, check_signal_requirements, validate_signal_config)
+from plugins.platforms.signal.setup import interactive_setup
+from plugins.platforms.signal.standalone import standalone_send
+
+logger = logging.getLogger(__name__)
+
+_env_configured = env_is_connected("SIGNAL_HTTP_URL", "SIGNAL_ACCOUNT")
+
+
+def _is_connected(config: PlatformConfig) -> bool:
+ """URL + account from config/scoped env, else ``.env``: a plain CLI process never loads ``.env``
+ into the environment, and the old static setup row read it, so a ``.env``-only profile stays
+ "configured" in ``hermes gateway setup``."""
+ return validate_signal_config(config) or _env_configured(config)
+
+
+def _validate_config(config: PlatformConfig) -> bool:
+ """``validate_config``: same warning the core instantiation path logged before the move."""
+ if validate_signal_config(config):
+ return True
+ logger.warning("Signal: SIGNAL_HTTP_URL or SIGNAL_ACCOUNT not configured")
+ return False
+
+
+def register(ctx) -> None:
+ """Plugin entry point β€” called by the Hermes plugin system."""
+ ctx.register_platform(
+ name="signal", label="Signal", adapter_factory=SignalAdapter,
+ check_fn=check_signal_requirements, validate_config=_validate_config,
+ is_connected=_is_connected, required_env=["SIGNAL_HTTP_URL", "SIGNAL_ACCOUNT"],
+ install_hint="Signal: runtime requirements not met", setup_fn=interactive_setup,
+ allowed_users_env="SIGNAL_ALLOWED_USERS", allow_all_env="SIGNAL_ALLOW_ALL_USERS",
+ cron_deliver_env_var="SIGNAL_HOME_CHANNEL",
+ # Out-of-process sends speak raw JSON-RPC and bypass SignalAdapter.send()'s chunking, so
+ # send_message splits at the adapter's limit through this field.
+ standalone_sender_fn=standalone_send, max_message_length=MAX_MESSAGE_LENGTH,
+ emoji="πŸ“‘", pii_safe=True, allow_update_command=True)
diff --git a/tests/gateway/test_signal_plugin.py b/tests/gateway/test_signal_plugin.py
index d0e9a63c606..65a27829239 100644
--- a/tests/gateway/test_signal_plugin.py
+++ b/tests/gateway/test_signal_plugin.py
@@ -8,9 +8,10 @@ from gateway.config import PlatformConfig
def test_register_declares_the_former_core_wiring(monkeypatch):
from plugins.platforms.signal import adapter
+ from plugins.platforms.signal.register import register
captured = {}
- adapter.register(SimpleNamespace(register_platform=lambda **kw: captured.update(kw)))
+ register(SimpleNamespace(register_platform=lambda **kw: captured.update(kw)))
assert captured["name"] == "signal" and captured["label"] == "Signal" and captured["emoji"] == "πŸ“‘"
assert captured["adapter_factory"] is adapter.SignalAdapter