[WIP] feat: Add tool hooks bridge for external UI visibility#2908
Closed
JustMaier wants to merge 3 commits intoopenclaw:mainfrom
Closed
[WIP] feat: Add tool hooks bridge for external UI visibility#2908JustMaier wants to merge 3 commits intoopenclaw:mainfrom
JustMaier wants to merge 3 commits intoopenclaw:mainfrom
Conversation
Adds a bridge that connects agent runtime tool events to the internal hooks system, enabling workspace hooks to react to tool execution lifecycle events (start, update, result). This enables use cases like: - Ephemeral status messages in Discord showing tool progress - Typing indicators during tool execution - Real-time dashboards via WebSocket - Audit logging of tool usage Key changes: - New src/infra/agent-hook-bridge.ts with startAgentHookBridge() - Adds 'tool' to InternalHookEventType - Integrates bridge into gateway startup when hooks are enabled - Comprehensive test coverage for edge cases Design decisions: - Update events are NOT throttled at bridge level - hooks handle their own rate limiting (allows both throttled Discord and real-time WebSocket) - Fire-and-forget pattern so tool execution isn't blocked - Session key parsed into sessionMeta for hook convenience Closes openclaw#2904
- Remove unused imports (vi, ToolHookEvent) from test file - Apply oxfmt formatting
The test expects startAgentHookBridge() to return the same function instance when called multiple times. Fixed by storing the cleanup function separately from the event unsubscribe function.
Member
|
Closing: This PR is marked as WIP/Draft and has been open without completion. Please reopen when the work is ready for review. |
Author
|
The implementation is complete - I had forgotten to change the status from Draft to Ready for Review. Apologies for the confusion! This PR implements the tool hooks feature requested in #2538 (and duplicate #2904), adding:
All CI checks passed. Ready for review when reopened. |
Author
|
@sebslight this should be ready for review and solves a real issue. I'm unable to change the status of the PR from draft. |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a bridge that connects agent runtime tool events to the internal hooks system, enabling workspace hooks to react to tool execution lifecycle events.
Closes #2904
Problem
When an agent session is churning through tool calls (long-running exec, polling background processes, etc.), external UIs like Discord go silent even though the agent is actively working. There was no visibility into what the agent was doing.
Solution
Introduces a Tool Hook Bridge (
src/infra/agent-hook-bridge.ts) that:onAgentEvent()stream: "tool"eventstype: "tool")tool:start,tool:update,tool:resultactionsHook Event Structure
Key Design Decisions
Update events NOT throttled at bridge level — Hook scripts handle their own rate limiting. This allows both throttled Discord updates AND real-time WebSocket streaming.
Fire-and-forget —
void triggerInternalHook()so tool execution isn't blocked by slow hooks.Reuses existing utilities — Uses
parseAgentSessionKeyfrom session-key-utils.jsDedicated module — Keeps gateway startup clean, follows existing patterns.
Changes
src/infra/agent-hook-bridge.ts- The bridge implementationsrc/infra/agent-hook-bridge.test.ts- Comprehensive testssrc/hooks/internal-hooks.ts- Adds"tool"toInternalHookEventTypesrc/gateway/server-startup.ts- Starts bridge when hooks are enabledTesting
Added tests for:
Example Hook Script
Review Notes