fix(hooks): deliver internal hook replies on replyable surfaces

This commit is contained in:
Vincent Koc
2026-03-09 12:12:02 -07:00
parent 3d15111d64
commit 9c970561da
7 changed files with 237 additions and 35 deletions

View File

@@ -199,7 +199,7 @@ const myHandler = async (event) => {
// Your custom logic here
// Optionally send message to user
// Optionally send a reply on supported reply-capable surfaces
event.messages.push("✨ My hook executed!");
};
@@ -216,7 +216,7 @@ Each event includes:
action: string, // e.g., 'new', 'reset', 'stop', 'received', 'sent'
sessionKey: string, // Session identifier
timestamp: Date, // When the event occurred
messages: string[], // Push messages here to send to user
messages: string[], // Push reply messages here for supported reply-capable surfaces
context: {
// Command events:
sessionEntry?: SessionEntry,
@@ -339,6 +339,18 @@ Message events include rich context about the message:
}
```
#### Hook Reply Messages
`event.messages` is not a global "reply anywhere" mechanism.
OpenClaw only drains `event.messages` on reply-capable surfaces where it has a safe routing target:
- `command:new`
- `command:reset`
- `message:received`
For lifecycle-only surfaces such as `agent:bootstrap`, `message:preprocessed`, `message:transcribed`, `message:sent`, and gateway/session events, pushed `event.messages` are not automatically delivered to the user.
#### Example: Message Logger Hook
```typescript