Package com.tnsai.server.hooks
Class DeclarativeHookRegistry
java.lang.Object
com.tnsai.server.hooks.DeclarativeHookRegistry
Parses declarative hook definitions from YAML and registers them as runtime
listeners on agents.
YAML schema
hooks:
- event: preToolUse
matcher: "file_*"
action:
type: log
message: "Tool ${tool} is about to execute"
- event: postToolUse
matcher: "shell"
action:
type: command
command: "echo 'shell tool finished'"
- event: onStart
action:
type: log
message: "Agent started"
-
Method Summary
Modifier and TypeMethodDescriptionvoidapplyTo(com.tnsai.agents.Agent agent) Register this registry's hooks as aToolCallListeneron the agent.voidFire hooks for the given event with context variables.voidFire hooks for a tool-specific event.static DeclarativeHookRegistryfromYaml(InputStream yamlInput) Parse hooks from a YAML input stream.static DeclarativeHookRegistryfromYaml(InputStream yamlInput, HookExecutor executor) Parse hooks from a YAML input stream with a custom executor.getHooks()Returns an unmodifiable view of all registered hooks.getHooksForEvent(HookEvent event) Returns hooks registered for a specific event.static DeclarativeHookRegistryof(List<HookConfig> hooks) Create a registry from pre-built hook configs (for programmatic/test use).static DeclarativeHookRegistryof(List<HookConfig> hooks, HookExecutor executor) Create a registry from pre-built hook configs with a custom executor.
-
Method Details
-
fromYaml
Parse hooks from a YAML input stream.- Parameters:
yamlInput- YAML content containing ahooksarray- Returns:
- a registry with the parsed hooks
-
fromYaml
Parse hooks from a YAML input stream with a custom executor. -
of
Create a registry from pre-built hook configs (for programmatic/test use). -
of
Create a registry from pre-built hook configs with a custom executor. -
applyTo
public void applyTo(com.tnsai.agents.Agent agent) Register this registry's hooks as aToolCallListeneron the agent. Also fires anyonStarthooks immediately. -
fireEvent
Fire hooks for the given event with context variables. -
fireToolEvent
Fire hooks for a tool-specific event. -
getHooks
Returns an unmodifiable view of all registered hooks. -
getHooksForEvent
Returns hooks registered for a specific event.
-