← Back to PRs

#12986: feat(hooks): wire message_sending and message_sent plugin hooks

by Ramsbaby open 2026-02-10 01:15 View on GitHub →
stale
## Summary Wire the `message_sending` and `message_sent` plugin hooks that were defined in the type system but never called in the execution flow. Related: #6535 ## Changes **`src/auto-reply/reply/dispatch-from-config.ts`** - Call `runMessageSending()` before final reply delivery - Supports content modification (`result.content`) - Supports reply cancellation (`result.cancel`) - Call `runMessageSent()` after successful delivery (fire-and-forget) ## Scope & Design Decisions - **Final replies only** — block/streaming and tool results are not hooked to avoid latency impact - **Fast-abort replies excluded** — system-generated abort messages bypass hooks intentionally - `message_sending` runs sequentially (modifying hook) — consistent with `runMessageSending()` in hooks.ts - `message_sent` runs as fire-and-forget with error catching — no impact on delivery flow - `hasHooks()` guard ensures zero overhead when no plugins register these hooks - `sendSuccess` reflects queue acceptance (dispatcher) or route result (cross-provider), not final delivery confirmation ## Use Cases - **Persona enforcement**: Validate/correct responses against SOUL.md after context compaction - **Content filtering**: Block or modify responses before they reach users - **Audit logging**: Track all outbound messages with delivery status - **Analytics**: Measure delivery success rates per channel ## Testing (20/20 passing) | Test | Coverage | |------|----------| | Content modification | Hook modifies `ttsReply.text` before dispatch | | Reply cancellation | Hook returns `cancel: true`, reply skipped | | No-op (unregistered) | Zero overhead, hooks not called | | Multiple replies | Hook fires per reply in array | | Cross-provider routing | Modified content reaches `routeReply()` | | Fast-abort exclusion | System abort messages bypass hooks | | message_sent fires | After successful delivery | | message_sent no-op | Not called when unregistered | ``` pnpm lint → 0 warnings, 0 errors (2796 files) pnpm format → All files formatted correctly vitest → 20/20 tests passing ``` Partially addresses #6535 (2 of 8 remaining hooks)

Most Similar PRs