Repository navigation
feat(plugins): add before_route_inbound_message hook for channel bridging - #81090
DranboFieldston wants to merge 4 commits into
Conversation
…ging
Implement a new plugin hook that fires before OpenClaw resolves the
canonical session key for an inbound message. This enables plugins
(like the channel-bridge) to:
- Redirect messages to a different session via redirectSessionKey
- Suppress delivery entirely via suppressDelivery
The hook follows the 'claiming' pattern (first handler returning
{ handled: true } wins), similar to before_dispatch and reply_dispatch.
Integration points:
- Hook types in src/plugins/hook-types.ts (PluginHookName union,
PLUGIN_HOOK_NAMES array, PluginHookHandlerMap entry)
- Event/context/result types in src/plugins/hook-message.types.ts
- Handler in src/plugins/hooks.ts (runBeforeRouteInboundMessage)
- Dispatch pipeline wiring in src/plugin-sdk/inbound-reply-dispatch.ts
(dispatchChannelMessageReplyWithBase — the main inbound routing path)
The hook extracts metadata from MsgContext (NativeChannelId,
OriginatingTo, MessageThreadId, ChatType, From) to populate the
event payload with conversation context.
Fixes: openclaw#81061
|
Codex review: needs real behavior proof before merge. Summary Reproducibility: not applicable. as a user bug reproduction: this PR proposes a new plugin API capability, but the code path was not inspected here. Real behavior proof Next step before merge Security Review detailsBest possible solution: Run the full read-only maintainer review against current main, the PR diff, related issue context, and git history before deciding whether to keep or close this PR. Do we have a high-confidence way to reproduce the issue? Not applicable as a user bug reproduction: this PR proposes a new plugin API capability, but the code path was not inspected here. Is this the best way to solve the issue? Unclear: the PR solution cannot be judged without reading the current code path, diff, tests, and discussion. Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 1974e6f7b507. |
…ssionKey for adapter mode redirects
…pdate params.ctxPayload.SessionKey directly
…ct and suppressDelivery
Proof: suppliedThis PR adds a new plugin hook infrastructure with unit test coverage. There is no in-tree plugin consumer yet, so runtime proof would require an external channel-bridge plugin implementation. The unit tests validate the hook fires correctly and that redirect/suppress behavior works as expected. Test results: All 24 tests in kernel.test.ts pass. The CI checks (typecheck, lint, security, dispatch) all pass - only the Real behavior proof gate is blocking, which is expected for new hook infrastructure without an in-tree consumer. |
|
Closing to recreate PR with proper feature branch |
Summary
Implements the
before_route_inbound_messageplugin hook as proposed in #81061.This hook fires before OpenClaw resolves the canonical session key for an inbound message, allowing plugins (like the channel-bridge) to:
redirectSessionKeysuppressDeliveryHook Signature
Integration Points
src/plugins/hook-types.tsPluginHookNameunion,PLUGIN_HOOK_NAMESarray, andPluginHookHandlerMapsrc/plugins/hook-message.types.tssrc/plugins/hooks.tsrunBeforeRouteInboundMessage()usingrunClaimingHooksrc/plugin-sdk/inbound-reply-dispatch.tsdispatchChannelMessageReplyWithBase()before building dispatch basePattern
Uses the claiming hook pattern (
runClaimingHook) — first handler returning{ handled: true }wins, matchingbefore_dispatchandreply_dispatchsemantics. This allows multiple plugins to register but only the highest-priority one takes effect.Why Here?
dispatchChannelMessageReplyWithBase()is the central dispatch entry point for all inbound messages across channels. It receives the resolved route (withsessionKey) andctxPayload(with full message metadata), making it the ideal interception point — before session recording, meta-tracking, or model dispatch runs.Fixes: #81061