The salvaged #139642 normaliser grew adapter.py past its code-health
cap. It is a pure id helper, so it lives beside normalize_telegram_chat_id
as parse_telegram_message_id; behaviour is unchanged.
Refs #139611
Refs #134889 (MSG-17)
Refs #140138
Route wakes (kanban-wake, loop-tick) are admitted with a synthetic JSON
identity (session_automation.admit_route_wake), and
_reply_anchor_for_event passes it to the send as the reply anchor. The
Telegram adapter ran raw int() on that anchor in
_metadata_reply_to_message_id, _reply_to_message_id_for_send and
_chunk_reply_routing, so every reply into the session failed with
"invalid literal for int() with base 10: '["kanban-wake",...]'" and
the poisoned anchor was retried.
All three sites now go through _telegram_message_id(): a non-numeric
anchor is not a Telegram message id, so the reply is sent unanchored,
or on the DM topic's own metadata anchor when there is one. The
normaliser follows luyifan's approach in #72937, which no longer applies
after the adapter refactor.
Co-authored-by: luyifan <al3060388206@gmail.com>
(cherry picked from commit 5b9f0d6cea2896c82e882297a0cd5e92571fdbb8)
The env bridge, allowlist names and prompt hint now live on the PlatformEntry (gateway_env.py,
AUTHZ, platform_hint), not in _ENV_STEPS, _PLATFORM_ALLOWLIST_ENV or PLATFORM_HINTS.
Independent review found the allowlist, the open-policy startup refusal, the pairing-noise
rule and `hermes pairing revoke` reading only the live PlatformEntry: a user plugin overriding a
bundled platform without the fields, safe mode or a disabled plugin then gated on nothing
(looser than main, whose core tables always applied).
Each bundled plugin now declares them once as `gateway_env.AUTHZ` (passed to register() with
**), and `gateway.platform_env.authz_field` answers from the entry, else from that file (read
without the plugin package). Probed main vs head: 208/208 authz decisions identical in normal,
safe-mode, plugin-disabled and user-override modes; revoke drops the user in all four.
The terminal secret blocklist and config_env_table_keys() read the same files, which removes the
three hand-listed plugin secrets in local_env_policy.
CI found three paths that read the registry where core used to read its own table:
- the system prompt's platform hint was built before any discovery (direct builders):
discover on a miss, like the send and config lookups already do;
- the dashboard's auth-posture check resolved the allowlist env inside the profile scope,
whose registry overlay may not hold the entry: resolve it in the request scope, the way
_env_value_rules already does;
- a parked profile's config read suppresses plugin discovery by design (#123386), so its
bundled-platform env rows vanished and the duplicate-credential guard stopped seeing a
shared bot token. Bundled rows are now read straight from plugins/platforms/<p>/gateway_env.py
(core-only imports, never the plugin package or register()) whenever the registry has no
entry: suppressed discovery, safe mode, a disabled plugin. That is main's behaviour.
Buzz's test loader imports adapter.py as a bare module, so its sibling imports go through the
existing loader-agnostic helper (generalized from nostr_auth).
The plugin loader runs a bundled platform package as hermes_plugins.platforms__<name>.
An absolute `from plugins.platforms.<name>.<sibling> import ...` inside register() imports
the canonical package too, whose __init__ loads a second copy of the adapter. The prompt-hint
and send-target siblings added on this branch did that for buzz, feishu and slack (three new
double-loaded adapters vs main). Relative imports, as the dashboard_card / gateway_env siblings
already use; after every plugin registers, the double-loaded set is back to main's five.
Move the per-platform `_Cred` rows of `_ENV_STEPS`, their helper steps and the
`_ENV_ENABLE_CREDENTIALS` rows for every plugin-backed platform (telegram, discord,
slack, whatsapp, whatsapp_cloud, signal, mattermost, matrix, email, sms, dingtalk,
feishu, wecom, wecom_callback, weixin, bluebubbles, qqbot, yuanbao) out of
gateway/config_env.py into each plugin's `gateway_env.py`, attached via two new
PlatformEntry fields: `env_overrides` (ordered steps) and `env_enable_credentials`.
`gateway/platform_env.py` holds the declarative `EnvCred` row and shared parsers.
`_apply_env_overrides` runs the rows of entries with activation evidence (same gate
as the plugin enable pass, computed once). Core-only rows (api_server, webhook,
msgraph_webhook, relay) stay in config_env. profile_channels reads the rows from
registry entries; the import-time terminal secret blocklist lists the three secrets
only those rows read, pinned by a new invariant test.
Resulting GatewayConfig and explicit-disable warnings are identical (differential
oracle, 100 fixtures); only env-created insertion order of api_server/webhook/
msgraph_webhook relative to plugin platforms changes.
The Channels page catalog (_PLATFORM_OVERRIDES) and the PUT env-value validators
(_ENV_VALUE_RULES) duplicated per-platform data the bundled platform plugins can
declare. Each plugin now declares its card on its PlatformEntry (new dashboard
block: dashboard_label, dashboard_description, docs_url, dashboard_env_vars,
dashboard_required_env, env_value_rules); core keeps static rows only for the
core-only platforms (api_server, webhook, msgraph_webhook, relay).
Telegram/Slack validators move into their plugins. The PUT route resolves the
rules right after _require_platform (catalog build already materialized every
entry, so nothing extra is imported) and before entering _profile_scope, where
the registry's profile overlay may not hold the entry.
Adapters over their size cap (discord, feishu, matrix, slack, telegram) keep the
card in a sibling dashboard_card.py, imported relatively so no second canonical
copy of the adapter module loads; surplus blank lines offset the two added lines.
Behaviour identity: differential oracle over the real route handlers (GET
/api/messaging/platforms root + profile, PUT valid/invalid per rule root +
profile) is byte-identical to base.
Delete the per-platform tables in tools/send_message_targets.py (_PLATFORM_PARSERS, 14 rows) and
tools/send_message_tool.py (_PLUGIN_STANDALONE_MEDIA, _TEXT_SENDERS, plus the discord-always and
whatsapp-mentions ladders). Each bundled plugin now declares them on its PlatformEntry:
- target_ref_syntax_fn: the old parser, body unchanged. A new field rather than parse_target_ref_fn
because that field is an authority (strict under pass_unresolved_references, no "not explicit"
sentinel, not re-applied to channel-directory hits) and reusing it would change react/cron
behaviour for ntfy/buzz/photon.
- standalone_send: StandaloneSendPolicy (label, media, all_sends, captionable,
empty_list_between_chunks, forward_force_document, mentions, text_direct).
Shared builders and the NOT_EXPLICIT sentinel live in gateway/platforms/send_targets.py so plugins
import no core-private helpers. Lookups discover plugins first when the name is not registered yet
(fresh CLI/cron process). Differential oracle (33 platforms x 48 refs, 10 send cases each): base and
head output identical.
PLATFORM_HINTS (agent/prompt_builder.py) and _PLATFORM_DEFAULTS (gateway/display_config.py)
duplicated per-platform data for every bundled messaging plugin. Both consumers already fell
back to the registry (PlatformEntry.platform_hint / display_tier), so the plugin rows move onto
each plugin's register() call and the core tables keep only core surfaces (cron, cli, tui,
desktop, api_server hints; webhook, api_server display rows).
New PlatformEntry field display_overrides: per-key defaults layered over display_tier (telegram,
discord, slack, wecom had tier + tweaks). Hint text is copied byte-for-byte (the shared
_MEDIA_NATIVE fragment is inlined); a base-vs-head oracle of platform_hint() and
resolve_display_setting()/resolve_tool_progress() for every platform, with and without user
display overrides, is byte-identical. Oversize adapters keep the hint in adapter_hint.py.
_ALLOW_BOTS_ENV (authz_mixin) and _OWN_POLICY_OPEN_ENV (run) duplicated data the
platform plugins own. PlatformEntry gains allow_bots_env and own_policy_env; the
discord/feishu/telegram/slack and wecom/weixin/yuanbao/qqbot/whatsapp plugins
declare them and both tables are deleted.
Both consumers run an idempotent discover_plugins() first so a hand-built config
or bare runner still sees the entries. The bot bypass fails closed with no entry.
The open-policy startup check fails closed for a bundled platform whose plugin is
disabled or failed to load (conventional <NAME>_* names, manifest-declared
allow-all): config can still enable such a platform, and a later plugin enable
re-wires its adapter without re-running the startup check.
_own_policy_envs lives in run_startup.py to keep run.py under its line cap;
small offsets in the discord/slack/feishu/telegram plugin files for the same reason.
Delete the hand-written per-platform rows that duplicated data every bundled
platform plugin already declares on its PlatformEntry:
- gateway/config.py `_PLATFORM_CONNECTED_CHECKERS`: the weixin, whatsapp_cloud,
signal, bluebubbles, qqbot and yuanbao rows move to a new narrow
`PlatformEntry.config_connected_fn` (verdict from the merged PlatformConfig
alone, no env fallback, owns the token shortcut so Weixin can refuse a bare
token). Core-only rows (api_server, webhook, msgraph_webhook, relay) stay.
- gateway/pairing.py `_PLATFORM_ALLOWLIST_ENV` and the derived authz maps
`_ALLOWED_USERS_ENV` / `_ALLOW_ALL_ENV`: read `allowed_users_env` /
`allow_all_env` (discovering plugins first). The unauthorized-DM
"allowlist set -> ignore" default keeps its historical platform set as a
names-only frozenset so irc/teams/... DM behaviour does not change.
- cron `_HOME_TARGET_ENV_VARS`: env var from `cron_deliver_env_var`; the
origin-fallback / deliver=all order is kept as a names-only priority tuple.
`_KNOWN_DELIVERY_PLATFORMS` keeps only webhook and wecom_callback (no cron var).
- hermes status `_PLATFORM_LABELS`: plugin labels already overrode every row;
discover first and use them alone.
- dashboard `_platform_authz_env_names` drops its read of the pairing table.
Differential oracle (connected matrix, pairing/dashboard env lookup,
_is_user_authorized + unauthorized-DM matrix, cron known/home/resolve/all,
hermes status platform section, hermes dump) is identical on base and head.
handle_drive_comment_event bound the launch profile scope to ANY unscoped
callback. Every secondary path arrives scoped today, but a secondary that lost
its context would quietly run its comment turn on the launch profile's
credentials, where main raised UnscopedSecretError. The adapter now passes
secondary (it has a multiplex owner profile), and only the launch adapter may
borrow the launch scope; a secondary's unscoped event is dropped with a warning.
Tests: test_an_unscoped_comment_from_a_secondary_adapter_fails_closed and
test_the_adapter_tells_the_comment_handler_whether_it_is_a_secondary (red
before, green after).
Review finding by @unsupportedpastels on #140186
Refs #134889 (MSG-13)
With SO_REUSEADDR a TIME-WAIT-only port reads as free on Linux. That matches the
Node bridge, which sets the same option, and the bridge allocator and ownership
check in this module are the only callers (git grep). The docstring now says so
and warns against gating a non-REUSEADDR binder on it.
Review finding on #140186 (independent review)
Refs #134889 (MSG-16)
On top of the salvaged SO_REUSEADDR probe: set the option only on POSIX
(libuv does the same; on Windows it lets a bind share a live listener's
port, which would read another profile's bridge as free), and pin the
restart case with a real kernel TIME-WAIT entry instead of a socket mock,
plus a live listener on the same port still failing closed.
Pre-existing before #106742 (bridge_ownership.py is unchanged since
d385b01469, an ancestor of d04056d609); only multiplexed secondaries
reach this check. Needs a live retest with a paired WhatsApp secondary
and `systemctl --user restart hermes-gateway`.
Refs #139425
Refs #134889 (MSG-16)
Refs #140138
_early_reject_unauthorized dropped the decoded thread_id, so a thread-scoped
profile_routes entry checked the default profile's pairing store: a caller
approved only in the routed profile had slash commands (even /stop) and
messages in that thread dropped. Pass thread_id from both the slash and the
message path to _is_sender_authorized and the build_source fallback.
Names resolved for a slash turn are awaited before the handoff and Bolt runs
callbacks concurrently, so a /queue whose cold users.info answered late
reached the gateway FIFO after a later one. A slash now reserves its
session's slot before any lookup and hands over only after the slash ahead
returned from handle_message; a slash cancelled while waiting still chains
the one behind it. /stop, /approve, /deny, /pause take no slot.
Ported from #128722 (9b719083, eb546b6a) into adapter_slash_lane.py.
Co-authored-by: John Paul Soliva <soliva.johnpaul@icloud.com>
Move the two pure slash-payload helpers (gateway text, thread anchor) out of
the adapter facade so the slash-turn parity fix keeps adapter.py under its
health cap. No behaviour change.
/pause engages the emergency stop and starts no turn, like /stop and /approve,
so a cold users.info must not hold it back. Ported from 9b719083 in #128722
(its arrival-order handoff lane is left out).
Co-authored-by: John Paul Soliva <soliva.johnpaul@icloud.com>
The names the slash path resolves (users.info, conversations.info) were awaited
before the event reached the active-session dispatcher. With a shared channel
session, a second operator's /stop sat behind their uncached users.info while
the first operator's worker kept running.
/stop, /new, /reset (the interrupt-then-dispatch commands) and /approve, /deny
start no turn of their own, so they are handed over before any lookup. Commands
that do start a turn (/queue, /retry, /goal, ...) and free-form questions keep
the names and the channel prompt.
The message path rejects an unauthorized sender before any lookup (5bb933eedf); the slash path now resolves the channel and user name, so a sender the gateway was going to reject cost a conversations.info and a users.info first. Ask the same early gate before resolving. In a channel the runner only drops such a sender, so stop there. In a DM it answers per unauthorized_dm_behavior (pairing code or decline), so the event still reaches it, without names, exactly as before this branch.
Docs: N/A, slack.md already says an unauthorized DM gets the pairing prompt.
`/hermes <question>` can open a new session, and bound skills load only
when a session starts. The slash event carried no auto_skill, so a session
opened that way never loaded the channel's slack.channel_skill_bindings,
unlike one opened by an ordinary message. Resolve it the same way the
message path does.
_handle_slash_command built its MessageEvent without channel_prompt and its
source without chat_name/user_name, unlike the message path. A /hermes turn
ran without the configured channel_prompts and the bot identity line, and as
a human turn it re-pinned channel_pin to None and re-keyed the pinned
session-context prompt; the next ordinary message flipped both back, so every
slash turn cost two agent rebuilds and two prompt-cache misses. Synthetic
events copied from it (/retry, /queue, /steer fallback, /goal kickoff)
inherited the gap.
Resolve the names and the channel prompt with the same helpers the message
path uses.
The registration hooks had grown the moved adapter past 1,000 lines and put
two forward-only wrappers next to the message code. register.py now holds
the configured/validate checks and register(), and registers the setup and
standalone-sender functions directly. adapter.py is back to 983 lines; no
behaviour change (composite live probe matches main).
Addresses the Greptile finding on this PR.
The loader executes the package as hermes_plugins.platforms__signal, and
`from .adapter import register` gave the registry that synthetic copy of the
adapter, while the adapter's own absolute sibling imports loaded a second
plugins.platforms.signal.adapter. The rate-limit scheduler stayed one object,
but SignalAdapter existed twice, so isinstance checks and monkeypatches on the
canonical path missed the live adapter, and every start imported it twice.
Register by the absolute name, as Yuanbao already does; a test pins both.
Also fix the namespace named in Yuanbao's __init__ comment.
Found by the independent review of this branch.
The six adapters now live at new paths, so the ratchet reads their moved
functions as new code held to today's targets:
- Standalone senders (bluebubbles, qqbot, weixin, yuanbao) are real
catch-all boundaries that turn any failure into an error result; they now
log the traceback at debug (behaviour unchanged).
- The Signal and Weixin setup wizards' catch-alls get reviewed waivers: any
probe/QR failure is shown to the user, who decides.
- QQ Bot's media existence check runs off the event loop (ASYNC240).
- Yuanbao's registration block moves to plugins/platforms/yuanbao/register.py
so adapter.py stays at main's size cap; it imports the adapter by its
canonical name, keeping one YuanbaoAdapter class object.
The composite live pass showed `hermes gateway setup` listing Signal and Weixin as
"not configured" for a profile whose credentials live only in .env, while main shows
"configured". The old static wizard rows read get_env_value (.env-backed); the plugin
is_connected checks read only config + the scoped environment, which a plain CLI
process never fills from .env. QQ Bot already had this fallback.
Both now fall back to env_is_connected over the same credential pair. A test pins the
.env-only status for all six moved platforms (red for signal and weixin before this).
With signal, weixin, bluebubbles, qqbot, yuanbao and whatsapp_cloud now
bundled platform plugins, gateway/platforms/ keeps only the base class and
the HTTP ingress adapters (api_server, webhook, msgraph_webhook). (The
now-unused _gateway_platform_module helper and the setup wizard's
second-credential map were dropped while integrating the weixin and
yuanbao "drop core wiring" commits.)
- ffmpeg calls in the Signal and QQ adapters get stdin=DEVNULL: they now
sit under plugins/, which check_subprocess_stdin scans (gateway/ is not
scanned), and ffmpeg reads stdin for its interactive keys.
- Setup wizard: collapse the blank lines left by the removed static rows.
- Developer docs (EN + zh-Hans) describe gateway/platforms/ as core base +
HTTP ingress adapters and list the six platforms under plugins/platforms/.
is_connected now falls back to env_is_connected(QQ_APP_ID, QQ_CLIENT_SECRET)
(.env-backed, scope-aware), so 'hermes gateway setup' shows QQ Bot as
configured for a .env-only profile, matching base.
(cherry picked from commit 19968fb98a96a99e59212fea7cf3129c81c5b7df)
- plugin.yaml name qqbot-platform (bundled-plugin convention)
- drop env_enablement/apply_yaml_config hooks and platform_hint: core
config_env _ENV_STEPS and PLATFORM_HINTS still own them, the hooks were
new behaviour (markdown/env seeding) the move must not add
- drop validate_config/max_message_length: base never config-gated or
chunked QQ in send_message (REST sender truncates at 4000)
- install_hint carries the old _BUILTIN_ADAPTERS warning text
- drop the _send_qqbot compat alias
- replace env-seeding tests with a registration-shape test
(cherry picked from commit b34a6d21e42d934555a2e6243c9a126dc0d5de42)
QQ Bot is a messaging platform, so its adapter, setup, and standalone sender belong in plugins/platforms/qqbot behind one register() entry. The core keeps the shipped-platform name lists, so webhook, cron, and prompt hints still treat qqbot as built-in.
(cherry picked from commit a7eb428aad0cc69ea098747b435e1e0e1d7e3b67)
gateway/platforms/signal{,_format,_rate_limit}.py -> plugins/platforms/signal/
(adapter.py + satellites, history-preserving renames). register(ctx) declares
the PlatformEntry hooks core used to hard-wire: requirements probe, config
gate (with the old 'SIGNAL_HTTP_URL or SIGNAL_ACCOUNT not configured' warning),
is_connected, allowlist/home env vars, max_message_length=8000, emoji, pii_safe,
allow_update_command. The out-of-process JSON-RPC sender (attachments still
ride the 'attachments' param, shared rate-limit scheduler) moves to
standalone.py as standalone_sender_fn; the setup wizard moves to setup.py as
setup_fn, unchanged flow. Tests repointed at the plugin path.
Co-authored-by: Karl Johannisson <karl.johannisson@gmail.com>
(cherry picked from commit eb9f7e730a39d702aea2505855631e3137ab509b)
gateway/platforms/bluebubbles.py -> plugins/platforms/bluebubbles/adapter.py (git mv) plus
plugin.yaml/__init__.py and register(ctx): adapter_factory, check_fn (+ the old
_BUILTIN_ADAPTERS warning as install_hint), is_connected, required_env, setup_fn (the
former hermes_cli/setup_platforms._setup_bluebubbles), standalone_sender_fn (the former
tools/send_message_senders._send_bluebubbles), allowed_users/allow_all/cron env vars,
pii_safe, allow_update_command, emoji. Tests follow the new module path.
(cherry picked from commit 870d4a169e4f89cbb2689ccd1db555ad15cea216)
gateway/platforms/whatsapp_cloud.py -> plugins/platforms/whatsapp_cloud/adapter.py and
hermes_cli/setup_whatsapp_cloud.py -> plugins/platforms/whatsapp_cloud/setup_wizard.py (git mv).
register(ctx) wires adapter_factory, check_fn, is_connected, required_env, install_hint,
setup_fn (the same wizard `hermes whatsapp-cloud` runs), allowed_users/allow_all env,
cron_deliver_env_var, label/emoji. gateway/platforms/whatsapp_common.py stays in core
(shared with the Baileys plugin and CLI helpers). Tests and docs point at the plugin path.
Co-authored-by: sprmn24 <oncuevtv@gmail.com>
(cherry picked from commit a3b08efc0249c2dcd3472e4a25addc3f3a2b0d5c)
Re-authorization re-reads config through load_gateway_config(), whose
Discord hook copies YAML allowed_roles into DISCORD_ALLOWED_ROLES (first
writer wins) outside multiplex, and env keeps precedence in _gate_raw.
So a role removed from YAML is revoked at once only for a multiplexed
profile (the copy is skipped); on a single-profile install it stays
granted until restart, as for ingress and as on main.
The revocation test passed only because its fixture deleted that env
var. Replace it with a parametrized test through the real loader: two
re-authorizations around a YAML edit, multiplexed (revoked) and single
profile (still granted, env holds the copy). Correct the comments that
implied immediate revocation. No behaviour change.
Refs #134889 (MSG-7)
Refs #139162
Refs #139148
The durable re-authorization read DISCORD_ALLOWED_ROLES from the scoped
env or the raw top-level `discord:` block only, so a profile that sets
its role allowlist under `platforms.discord` (flat or `extra`) admitted a
role-authorized member at ingress and then dropped the message with
permission_denied.
Recovery now resolves the gate with the same `_gate_raw` ingress uses,
applied to the Discord PlatformConfig that `load_gateway_config()` builds
for the transport profile at check time: scoped env first, then `extra`
with the loader's precedence (`platforms.discord.extra` over the flat
key and the top-level block). Reading current config instead of the
connect-time `self.config` keeps a config revocation effective.
Refs #134889 (MSG-7)
Refs #139162Fixes#139148
Co-authored-by: 686f6c61 <6115107+686f6c61@users.noreply.github.com>
gemini-4-argon is served on the per-user-quota endpoint (a bogus slug 404s; argon answers 429 quota on an account without headroom). Listed after 3.1 Pro so the default model and wire are unchanged.
The Mattermost adapter built inbound events with `media_urls or None` /
`media_types or None`, so every post without an attachment carried None.
Native admission (`_validate_native` in gateway/session_envelope.py)
requires both fields to be lists, as MessageEvent declares them, and
refused every plain text post with `invalid_params`. Commands bypass
admission, so /reset still worked while normal messages failed.
Pass the lists `_download_attachments` already returns. Mattermost was the
only adapter with this pattern.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit c0f32ce5a5c0d633bf4e73a0581ad18b07ee4171)
The bot's speaker re-reads say_queue.jsonl after speaking and rewrites it
without the spoken head; a meet_say append from the agent process landing
between the re-read and the rewrite was truncated away, so a request
reported as enqueued was never spoken. Appenders and the speaker's
re-read+rewrite now share a cross-process lock beside the queue file.