oats.hook
Hook engine for extensible event handling.
oats.hook.engine
Hook engine — executes user-defined commands at lifecycle events.
Hooks are configured in coder.json:
{
"hooks": [
{
"event": "pre_tool_use",
"matcher": "bash",
"command": "/path/to/script.sh",
"timeout": 30
}
]
}
Hook commands receive a JSON context on stdin and must return JSON on stdout:
{
"action": "continue",
"modified_args": {},
"message": "..."
}
- class oats.hook.engine.HookEvent(*values)[source]
-
Lifecycle events that can trigger hooks.
- PRE_TOOL_USE = 'pre_tool_use'
- POST_TOOL_USE = 'post_tool_use'
- USER_PROMPT_SUBMIT = 'user_prompt_submit'
- SESSION_START = 'session_start'
- FILE_CHANGED = 'file_changed'
- ASSISTANT_RESPONSE = 'assistant_response'
- class oats.hook.engine.HookContext(session_id, event, tool_name=None, tool_args=None, tool_result_output=None, tool_result_error=None, user_prompt=None, assistant_response=None, root_session_id=None, file_path=None, working_dir=None)[source]
Bases:
objectContext passed to hook commands.
- session_id: str
- event: HookEvent
- to_dict()[source]
Serialize the hook context to a plain dict for JSON encoding.
- __init__(session_id, event, tool_name=None, tool_args=None, tool_result_output=None, tool_result_error=None, user_prompt=None, assistant_response=None, root_session_id=None, file_path=None, working_dir=None)
- class oats.hook.engine.HookResult(action='continue', modified_args=None, message=None)[source]
Bases:
objectResult returned by a hook command.
- action: str = 'continue'
- classmethod from_dict(data)[source]
Deserialize a HookResult from a JSON dict.
- Return type:
HookResult
- classmethod continue_result()[source]
Return a HookResult that signals the agent to continue.
- Return type:
HookResult
- classmethod block_result(message='')[source]
Return a HookResult that signals the agent to stop.
- Return type:
HookResult
- __init__(action='continue', modified_args=None, message=None)
- class oats.hook.engine.HookEngine(hooks=None)[source]
Bases:
objectExecutes hook commands at lifecycle events.
Hooks are loaded from configuration and matched against events and optional tool name patterns.
- __init__(hooks=None)[source]
- async fire(event, context)[source]
Fire all hooks matching this event.
Returns the first blocking result, or continue if all pass. For pre_tool_use with “modify” action, returns modified args.
- Return type:
HookResult