centralize tool plugin hooks + add agent to hook input#13521
centralize tool plugin hooks + add agent to hook input#13521ArmirKS wants to merge 5 commits intoanomalyco:devfrom
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
f573ba1 to
242ada3
Compare
d1440a3 to
d74de90
Compare
4db8f42 to
76b0b87
Compare
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
prompt.ts had duplicated inline Plugin.trigger calls for tool.execute.before/after at two call sites. Sub-tools inside batch never fired hooks, allowing plugin security policies to be silently bypassed. - Add Tool.invoke() to wrap execution with before/after hooks - Replace duplicated inline Plugin.trigger calls in prompt.ts - Add agent to hook input, status to after output - Fire after hook on error path (previously silent) - MCP tools kept inline (different result shape)
54d4993 to
312ade4
Compare
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
Closing in favor of a smaller, focused PR that adds agent + parentAgent to hook input without mixing in the Tool.invoke() refactor. Will link to #15403. |
What does this PR do?
prompt.tshad the same before/after hook logic inline in 3 places (there's a TODO at line 353 saying "centralize invoke tool logic"). None of them passedagentto the hooks, so plugins couldn't tell which agent made the call.This adds
Tool.invoke()that wraps tool execution with before/after hooks:Tool.invoke(). MCP wrapper kept inline to preserve backward compat (existing plugins accessoutput.content)agentto hook input,statusto after outputtry/catchinTool.invoke()(deviation from style guide — needed to fire the after hook on errors then re-throw,.catch()can't do that cleanly)batch.ts changes removed — batch tool is experimental and being deprecated, so the bypass there is moot.Fixes refactor: centralize tool plugin hooks + add agent to hook input #13524
How did you verify your code works?
1 test file, 4 tests:
test/tool/invoke.test.ts— before/after hooks fire, error status on throw, callID defaults, result passthroughTypecheck clean, turbo typecheck passed all 12 packages on push.