feat(plugins): wire up before_tool_call hook for pre-execution validation#2363
Closed
fuushyn wants to merge 3 commits intoopenclaw:mainfrom
Closed
feat(plugins): wire up before_tool_call hook for pre-execution validation#2363fuushyn wants to merge 3 commits intoopenclaw:mainfrom
fuushyn wants to merge 3 commits intoopenclaw:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0b0318ad63
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…tion Adds the missing wiring for the `before_tool_call` plugin hook, enabling plugins to intercept, validate, modify, or block tool calls before execution. The hook infrastructure (types, runner, handler merging) already existed but was never invoked in the tool execution path. This change: - Adds `pi-tools.before-call-hook.ts` with tool wrapper functions - Wraps tools in `attempt.ts` after sanitization if hooks are registered - Supports three hook actions: allow (default), modify params, or block Closes openclaw#1733 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove toolCallId from hook context/event (not in type definitions) - Return proper AgentToolResult structure when blocking - Import AgentToolResult from pi-agent-core Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
ac6f05c to
50ba466
Compare
- Add status='error' to blocked tool results for proper error detection - Use sessionAgentId instead of agentAccountId for hook context - Move hook wrapping after resolveSessionAgentIds for correct agent id Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
06f9c76 to
f3fed22
Compare
Member
|
Closing due to merge conflicts. Please rebase on |
3 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
Adds the missing wiring for the
before_tool_callplugin hook, enabling plugins to intercept, validate, modify, or block tool calls before execution.The hook infrastructure (types, runner, handler merging) already existed in
src/plugins/hooks.tsbut was never actually invoked in the tool execution path. This PR adds the missing piece.Changes
New file:
src/agents/pi-tools.before-call-hook.tswrapToolWithBeforeCallHook()- wraps a single toolwrapToolsWithBeforeCallHook()- wraps all tools in arrayModified:
src/agents/pi-embedded-runner/run/attempt.tsbefore_tool_callhooks are registeredHook Behavior
Plugins can register a
before_tool_callhandler viaapi.on("before_tool_call", ...)to:{ params: modifiedParams }to change tool arguments{ block: true, blockReason: "..." }to prevent executionExample Plugin Usage
Test Plan
tool_result_persisthook still worksbefore_tool_callhandler can log tool callsCloses #1733
Generated with Claude Code