[PR #13521] centralize tool plugin hooks + add agent to hook input #14702

Open
opened 2026-02-16 18:19:28 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13521

State: open
Merged: No


What does this PR do?

prompt.ts had 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 passed agent to the hooks, so plugins couldn't tell which agent made the call.
This adds Tool.invoke() that wraps tool execution with before/after hooks:

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 passthrough
    Typecheck clean, turbo typecheck passed all 12 packages on push.
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13521 **State:** open **Merged:** No --- ### What does this PR do? `prompt.ts` had 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 passed `agent` to the hooks, so plugins couldn't tell which agent made the call. This adds `Tool.invoke()` that wraps tool execution with before/after hooks: - **prompt.ts**: replaces 2 of the 3 inline hook pairs with `Tool.invoke()`. MCP wrapper kept inline to preserve backward compat (existing plugins access `output.content`) - **plugin types**: adds `agent` to hook input, `status` to after output - uses `try/catch` in `Tool.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 #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 passthrough Typecheck clean, turbo typecheck passed all 12 packages on push.
yindo added the pull-request label 2026-02-16 18:19:28 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14702