Commit Graph

13 Commits

Author SHA1 Message Date
Steven Gonsalvez
761b7b6849
fix(hooks): add security hardening for message handlers
- Add ReDoS protection using safe-regex validation for contentPattern
- Add token bucket rate limiting (10/min per handler) to prevent cost explosions
- Require at least one match condition in Zod schema (reject empty match)
- Change error logging from logVerbose to logWarn for visibility

Includes tests for rate limiter and ReDoS protection.
2026-01-28 21:59:34 +00:00
Steven Gonsalvez
42c647f2c9
feat(hooks): add config-driven message handlers for immediate agent triggering
Add `hooks.internal.messageHandlers` config array for triggering agent
execution when inbound messages match specified conditions. This solves
the problem of important messages (like bug reports) being queued and
potentially missed when cron jobs wake the agent.

Features:
- Match conditions: channelId, conversationId, from, contentPattern (regex),
  contentContains (keywords)
- Priority modes: "immediate" (bypass queue) or "queue" (normal flow)
- Execution modes: "exclusive" (handler only) or "parallel" (handler + normal)
- Message transformation: prefix, suffix, or full template with placeholders
- Configurable model and thinking level per handler

Implementation:
- src/config/types.hooks.ts: MessageHandlerConfig and MessageHandlerMatch types
- src/config/zod-schema.hooks.ts: Zod validation schemas
- src/hooks/message-handler-match.ts: Condition matching logic
- src/hooks/message-handler-run.ts: Handler executor using runCronIsolatedAgentTurn
- src/auto-reply/reply/dispatch-from-config.ts: Integration point
- docs/hooks.md: Full documentation with examples
- 28 unit tests for matcher logic
2026-01-28 20:51:06 +00:00
Steven Gonsalvez
bf9f78c14c
feat(hooks): add message:received internal hook
- Add MessageReceivedHookContext type with full message metadata
- Add isMessageReceivedEvent() type guard for type-safe handling
- Trigger hook in dispatchReplyFromConfig() after plugin hooks
- Fire-and-forget execution to avoid blocking message processing
- Works across all 12 channels (whatsapp, telegram, discord, etc.)
- Add comprehensive tests for type guard and hook triggering
- Document message events, context fields, and filtering examples
2026-01-28 20:51:05 +00:00
Peter Steinberger
aced5dde8d docs: switch skill metadata key to moltbot 2026-01-28 01:32:53 +01:00
Peter Steinberger
6d16a658e5 refactor: rename clawdbot to moltbot with legacy compat 2026-01-27 12:21:02 +00:00
Peter Steinberger
83460df96f chore: update molt.bot domains 2026-01-27 12:21:01 +00:00
Peter Steinberger
eb5145c5d1 docs: mention tool_result_persist hook 2026-01-20 09:36:10 +00:00
Nimrod Gutman
11b07f4a29 feat(hooks): run boot.md on gateway startup 2026-01-18 11:50:25 +02:00
Peter Steinberger
e39fd7dbb3 docs: update bundled hooks list 2026-01-18 06:23:09 +00:00
Peter Steinberger
b8a82923e9 docs: add soul-evil hook docs 2026-01-18 06:21:00 +00:00
Peter Steinberger
e2c10a2b7a feat: support plugin-managed hooks 2026-01-18 05:57:05 +00:00
Peter Steinberger
ad3c12a43a feat: add bootstrap hook and soul-evil hook 2026-01-18 05:24:47 +00:00
Peter Steinberger
34d59d7913 refactor: rename hooks docs and add tests 2026-01-17 07:32:54 +00:00