Skip to content

centralize tool plugin hooks + add agent to hook input#13521

Closed
ArmirKS wants to merge 5 commits intoanomalyco:devfrom
ArmirKS:fix/tool-invoke-hooks
Closed

centralize tool plugin hooks + add agent to hook input#13521
ArmirKS wants to merge 5 commits intoanomalyco:devfrom
ArmirKS:fix/tool-invoke-hooks

Conversation

@ArmirKS
Copy link
Copy Markdown

@ArmirKS ArmirKS commented Feb 13, 2026

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 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 passthrough
    Typecheck clean, turbo typecheck passed all 12 packages on push.

@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@ArmirKS ArmirKS force-pushed the fix/tool-invoke-hooks branch 3 times, most recently from f573ba1 to 242ada3 Compare February 13, 2026 19:57
@ArmirKS ArmirKS force-pushed the fix/tool-invoke-hooks branch 2 times, most recently from d1440a3 to d74de90 Compare February 13, 2026 20:58
@ArmirKS ArmirKS changed the title fix: centralize tool plugin hooks via Tool.invoke() refactor: centralize tool plugin hooks + add agent to hook input Feb 14, 2026
@ArmirKS ArmirKS force-pushed the fix/tool-invoke-hooks branch from 4db8f42 to 76b0b87 Compare February 15, 2026 19:06
@ArmirKS ArmirKS changed the title refactor: centralize tool plugin hooks + add agent to hook input centralize tool plugin hooks + add agent to hook input Feb 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title centralize tool plugin hooks + add agent to hook input doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

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)
@ArmirKS ArmirKS force-pushed the fix/tool-invoke-hooks branch from 54d4993 to 312ade4 Compare February 16, 2026 21:25
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Feb 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

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.

@R44VC0RP R44VC0RP removed the needs:compliance This means the issue will auto-close after 2 hours. label Feb 18, 2026
@ArmirKS
Copy link
Copy Markdown
Author

ArmirKS commented Feb 27, 2026

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.

@ArmirKS ArmirKS closed this Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: centralize tool plugin hooks + add agent to hook input

2 participants