diff --git a/integrations/hermes-t3-gateway/__init__.py b/integrations/hermes-t3-gateway/__init__.py index dfb9cfcc28..a7bee8dd63 100644 --- a/integrations/hermes-t3-gateway/__init__.py +++ b/integrations/hermes-t3-gateway/__init__.py @@ -11,7 +11,6 @@ from .adapter import ( ) from .cli import register_cli, t3_command from .home import HOME_CHANNEL_ENV, standalone_send -from .home import HOME_CHANNEL_ENV, standalone_send def _pre_tool_call( diff --git a/integrations/hermes-t3-gateway/connection.py b/integrations/hermes-t3-gateway/connection.py index d2300f70b5..4eec7fc98f 100644 --- a/integrations/hermes-t3-gateway/connection.py +++ b/integrations/hermes-t3-gateway/connection.py @@ -22,7 +22,6 @@ except ImportError: # pragma: no cover - Hermes currently installs websockets MessageHandler = Callable[[dict[str, Any]], Awaitable[None]] StateHandler = Callable[[bool, str | None], Awaitable[None] | None] AcceptedHandler = Callable[[dict[str, Any]], Awaitable[None]] -AcceptedHandler = Callable[[dict[str, Any]], Awaitable[None]] class ConnectionRejected(RuntimeError): @@ -346,20 +345,6 @@ class T3GatewayConnection: except Exception: # noqa: BLE001 - reconciliation must not fail a good handshake logger.warning("T3 connection accepted callback failed", exc_info=True) - async def _notify_accepted(self, accepted: dict[str, Any]) -> None: - """Hand the `connection.accepted` frame to the adapter, best-effort. - - A failure here — a read-only `.env`, an unwritable queue file — must - not tear down a connection that authenticated successfully, so it is - logged and swallowed exactly like the state callback. - """ - if self._on_accepted is None: - return - try: - await self._on_accepted(accepted) - except Exception: # noqa: BLE001 - reconciliation must not fail a good handshake - logger.warning("T3 connection accepted callback failed", exc_info=True) - async def _notify_state(self, connected: bool, reason: str | None) -> None: if self._on_state is None: return diff --git a/integrations/hermes-t3-gateway/home.py b/integrations/hermes-t3-gateway/home.py index e63ea6d8fd..16ec05c5e5 100644 --- a/integrations/hermes-t3-gateway/home.py +++ b/integrations/hermes-t3-gateway/home.py @@ -130,12 +130,14 @@ def save_home_thread_id(thread_id: str) -> bool: save_env_value(HOME_CHANNEL_ENV, value) saved = True - except Exception: # noqa: BLE001 - a read-only .env must not break the handshake + except Exception as exc: # noqa: BLE001 - a read-only .env must not break the handshake + # No stack trace: outside a Hermes install this is simply + # ModuleNotFoundError for hermes_cli, which is expected and noisy. logger.warning( - "Could not persist %s; T3 home delivery will use the in-process " - "value until the next reconnect", + "Could not persist %s (%s); T3 home delivery will use the " + "in-process value until the next reconnect", HOME_CHANNEL_ENV, - exc_info=True, + exc, ) # Mirror into this process exactly as enrollment does (`cli.py`): the # running gateway resolves the home channel from the environment and must diff --git a/integrations/hermes-t3-gateway/protocol.py b/integrations/hermes-t3-gateway/protocol.py index 85803fe951..8d661b5518 100644 --- a/integrations/hermes-t3-gateway/protocol.py +++ b/integrations/hermes-t3-gateway/protocol.py @@ -80,16 +80,6 @@ def delivery_id() -> str: return str(uuid.uuid4()) -def delivery_id() -> str: - """Mint the idempotency key for one home delivery. - - Stable across retries by construction: the id is minted once, when the - delivery is created, and the queued copy carries it verbatim through every - flush. T3 dedupes on it, which is what makes double-flushing safe. - """ - return str(uuid.uuid4()) - - def iso_now() -> str: return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z") @@ -372,52 +362,6 @@ def home_deliver( text=normalized_text, createdAt=created_at or iso_now(), ) - - -def home_deliver( - *, - delivery_id_value: str, - thread_id: str, - kind: str, - label: str, - text: str, - created_at: str | None = None, -) -> dict[str, Any]: - """Build a `home.deliver` frame with every wire bound already applied. - - Like `protocol_error`, this wraps the generic `frame()` helper rather than - assembling the envelope itself — but unlike the plain outbound frames the - adapter builds inline, a delivery has server-side validation the plugin - must not trip: `label` is trimmed non-empty <=200 chars and `text` is - 1..120000 chars in the T3 contract. Normalizing here rather than at the - call sites means a queued delivery is already wire-valid on disk, so a - flush after a plugin upgrade cannot resurrect a payload the server will - reject — the plugin would purge it only on an ack that never comes. - - An unknown `kind` degrades to `"other"` and an empty label to `"Hermes"`: - a misclassified badge is the documented worst case, a dropped delivery is - not. - """ - normalized_kind = str(kind or "").strip().lower() - if normalized_kind not in HOME_DELIVERY_KINDS: - normalized_kind = "other" - normalized_label = str(label or "").strip()[:MAX_HOME_DELIVERY_LABEL_CHARS].strip() - if not normalized_label: - normalized_label = "Hermes" - normalized_text = str(text or "")[:MAX_HOME_DELIVERY_TEXT_CHARS] - if not normalized_text: - normalized_text = " " - return frame( - "home.deliver", - deliveryId=delivery_id_value, - threadId=str(thread_id), - kind=normalized_kind, - label=normalized_label, - text=normalized_text, - createdAt=created_at or iso_now(), - ) - - def protocol_error( code: str, message: str, diff --git a/integrations/hermes-t3-gateway/pyproject.toml b/integrations/hermes-t3-gateway/pyproject.toml new file mode 100644 index 0000000000..c384077cb3 --- /dev/null +++ b/integrations/hermes-t3-gateway/pyproject.toml @@ -0,0 +1,15 @@ +# Tool configuration only — the plugin is installed by copying the directory +# (see install.sh), not packaged, so there is deliberately no [project] table. + +[tool.ruff] +# The plugin's floor: the code uses `X | None` unions and dict/list generics +# that require Python 3.10+. +target-version = "py310" + +[tool.ruff.lint] +# F catches real bugs — F811 (redefinition) is the rule that would have +# flagged the duplicated definitions this config was added alongside. +select = ["E", "W", "F"] +# The plugin favors long explanatory docstrings and comments; do not enforce a +# line length rather than reflowing existing prose. +ignore = ["E501"] diff --git a/integrations/hermes-t3-gateway/tests/test_connection.py b/integrations/hermes-t3-gateway/tests/test_connection.py index 67ffcd9ebd..a4095a8f5b 100644 --- a/integrations/hermes-t3-gateway/tests/test_connection.py +++ b/integrations/hermes-t3-gateway/tests/test_connection.py @@ -1,7 +1,6 @@ from __future__ import annotations import importlib.util -import contextlib import json import pathlib import sys