feat(hooks): add blocking capability to message_received hookFeat/message received blocking#10539
feat(hooks): add blocking capability to message_received hookFeat/message received blocking#10539khalidovicGPT wants to merge 4 commits intoopenclaw:mainfrom
Conversation
| async function runMessageReceived( | ||
| event: PluginHookMessageReceivedEvent, | ||
| ctx: PluginHookMessageContext, | ||
| ): Promise<PluginHookMessageReceivedResult | undefined> { |
There was a problem hiding this comment.
Incorrect generic arguments
runModifyingHook is declared as runModifyingHook<K extends PluginHookName, TResult>(hookName: K, ...), but runMessageReceived calls it as runModifyingHook<PluginHookMessageReceivedResult>(...), which supplies the hook name type parameter with the result type. This should be runModifyingHook<"message_received", PluginHookMessageReceivedResult>(...) (as is done in runBeforeAgentStart / runMessageSending), otherwise TS will either fail to compile or infer the wrong types for hookName/event/ctx.
Also appears in: src/plugins/hooks.ts:246.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/plugins/hooks.ts
Line: 242:245
Comment:
**Incorrect generic arguments**
`runModifyingHook` is declared as `runModifyingHook<K extends PluginHookName, TResult>(hookName: K, ...)`, but `runMessageReceived` calls it as `runModifyingHook<PluginHookMessageReceivedResult>(...)`, which supplies the *hook name* type parameter with the result type. This should be `runModifyingHook<"message_received", PluginHookMessageReceivedResult>(...)` (as is done in `runBeforeAgentStart` / `runMessageSending`), otherwise TS will either fail to compile or infer the wrong types for `hookName`/`event`/`ctx`.
Also appears in: `src/plugins/hooks.ts:246`.
How can I resolve this? If you propose a fix, please make it concise.| async function runMessageReceived( | ||
| event: PluginHookMessageReceivedEvent, | ||
| ctx: PluginHookMessageContext, |
There was a problem hiding this comment.
Type exports missing
PluginHookMessageReceivedResult is imported at src/plugins/hooks.ts:24 but it is not included in the export type { ... } block near the top. Consumers importing types from src/plugins/hooks.ts will not be able to reference the new result type even though it exists in src/plugins/types.ts, which breaks the intended public API for this hook result.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/plugins/hooks.ts
Line: 242:244
Comment:
**Type exports missing**
`PluginHookMessageReceivedResult` is imported at `src/plugins/hooks.ts:24` but it is not included in the `export type { ... }` block near the top. Consumers importing types from `src/plugins/hooks.ts` will not be able to reference the new result type even though it exists in `src/plugins/types.ts`, which breaks the intended public API for this hook result.
How can I resolve this? If you propose a fix, please make it concise.bfc1ccb to
f92900f
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
|
This pull request has been automatically marked as stale due to inactivity. |
Summary
This PR enhances the
message_receivedhook to support blocking incoming messages before they reach the agent. This enables security plugins to intercept and reject malicious messages (e.g., prompt injection attempts).Author: ClawForge Team
Changes
1. New Result Type (
src/plugins/types.ts)PluginHookMessageReceivedResultwithblock,blockReason,notifyUser,notifyAgent,threatLevel, andauditMetadatafields2. Hook Implementation (
src/plugins/hooks.ts)runMessageReceivedfromrunVoidHooktorunModifyingHook3. Dispatch Logic (
src/auto-reply/reply/dispatch-from-config.ts)block: trueand returns earlynotifyUsermessage when blockingBackward Compatibility
✅ Fully backward compatible
undefined→ message allowed{ block: true }cause blockingUse Case
Enables security plugins like prompt injection detection: