feat: add HooksManager lifecycle hook system to callModel#7
Open
mattapperson wants to merge 3 commits intomainfrom
Open
feat: add HooksManager lifecycle hook system to callModel#7mattapperson wants to merge 3 commits intomainfrom
mattapperson wants to merge 3 commits intomainfrom
Conversation
Implements an extensible hook system for callModel inspired by the Claude Agent SDK hooks pattern. Supports inline config for quick declarative usage and a HooksManager class for custom hooks, dynamic registration, and programmatic emit. Built-in hooks: PreToolUse, PostToolUse, PostToolUseFailure, UserPromptSubmit, Stop, PermissionRequest, SessionStart, SessionEnd. Features: tool matchers (string/RegExp/function), filter predicates, mutation piping, short-circuit on block/reject, async fire-and-forget handlers, configurable error handling, and custom hook definitions via Zod schema pairs.
81 edge-case tests covering handler chain execution, manager lifecycle, tool matchers, resolver normalization, and async output detection. Surfaces real issues: filter throws bypass error handling, global RegExp stateful .test(), and function matcher lacking boolean coercion.
3 tasks
test: add adversarial unit tests for hooks system
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
callModelinspired by the Claude Agent SDK hooks patternPreToolUse,PostToolUse,PostToolUseFailure,UserPromptSubmit,Stop,PermissionRequest,SessionStart,SessionEndonTurnStart,onTurnEnd,requireApprovalremain unchangedRe-creation of OpenRouterTeam/openrouter-web#16735 on the standalone agent SDK repo.
Test plan
pnpm build) passes cleanlypnpm lint) passes cleanly