Skip to content

Add tool:before/tool:after internal hook events#22068

Closed
yhindy wants to merge 1 commit into
openclaw:mainfrom
yhindy:feat/issue-7597-tool-hooks
Closed

Add tool:before/tool:after internal hook events#22068
yhindy wants to merge 1 commit into
openclaw:mainfrom
yhindy:feat/issue-7597-tool-hooks

Conversation

@yhindy

@yhindy yhindy commented Feb 20, 2026

Copy link
Copy Markdown

Summary

  • add new internal hook event type tool with typed contexts for tool:before and tool:after
  • emit tool:before and tool:after from the central tool execution wrapper (wrapToolWithBeforeToolCallHook)
  • support pre-execution abort via event.context.abort() in tool:before
  • include success/failure metadata (durationMs, result, error) in tool:after
  • add tests for new type guards and end-to-end tool hook emission/abort behavior
  • document tool hook events in automation hooks docs

Issue Intent Check (#7597)

  • real-time interception before execution: ✅ (tool:before)
  • real-time execution outcome hooks: ✅ (tool:after)
  • guardrail blocking path: ✅ (abort() + hook message propagated as error)
  • audit payload for monitoring/compliance: ✅ (tool, toolCallId, arguments, success, durationMs, result/error)

Validation

  • corepack pnpm exec vitest run src/hooks/internal-hooks.test.ts
  • corepack pnpm exec vitest run --config vitest.e2e.config.ts src/agents/pi-tools.before-tool-call.e2e.test.ts
  • corepack pnpm lint
  • corepack pnpm test:fast

Notes

  • Per-tool aliases like tool:exec:before were not added. Existing hook filtering can key off event.context.tool === "exec".

Closes #7597

Greptile Summary

This PR adds comprehensive tool:before and tool:after internal hook events to enable real-time tool execution monitoring and guardrails. The implementation correctly emits hooks from the central tool wrapper (wrapToolWithBeforeToolCallHook), supports pre-execution abort via the abort() callback, and includes success/failure metadata in the tool:after event. The changes are well-tested with both unit tests for type guards and e2e tests for the full hook emission flow.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is well-structured with comprehensive test coverage (unit tests for type guards + e2e tests for hook emission and abort behavior). The changes follow existing patterns in the codebase, maintain backward compatibility, and include clear documentation. All hook events are properly typed with TypeScript type guards, and the abort mechanism correctly prevents execution while still emitting tool:after events for audit trails.
  • No files require special attention

Last reviewed commit: 456e637

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Feb 20, 2026
@yhindy yhindy marked this pull request as ready for review February 20, 2026 20:29
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Feb 28, 2026
@vincentkoc vincentkoc self-assigned this Mar 3, 2026
@rapturt9

rapturt9 commented Mar 5, 2026

Copy link
Copy Markdown

Any updates on this, would be helpful for my workflow?

@vincentkoc

Copy link
Copy Markdown
Member

I will be landing via #18889

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation size: M stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Tool execution hook events (tool:before, tool:after)

3 participants