Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536"""Model-facing callbacks and opt-in inner-tool gates."""
import albedo_hooksfrom albedo_api import PythonApi
class Hooks: def register(self, event: str, callback, matcher: str | None = None): """Register callback(input) for PreToolUse, PostToolUse, UserPromptSubmit or Stop. matcher is a regex on tool names (None, '' or '*' matches all). input has hook_event_name/session_id/cwd and tool_name/tool_input/ tool_response for tool events, prompt for UserPromptSubmit, or last_assistant_message/stop_hook_active for Stop. Return None or Claude hook JSON: decision:'block'/reason, continue:False/stopReason, systemMessage, or hookSpecificOutput with permissionDecision:'deny', permissionDecisionReason, updatedInput or additionalContext. A tool veto raises PermissionError; a Stop veto continues the turn (max 8). Callbacks run first, sync or async, and fail open on exceptions. Answers an idempotent remove function. Registrations die with the kernel.""" return albedo_hooks.register(event, callback, matcher)
def registered(self) -> list[tuple[str, str | None]]: """List (event, matcher) for callbacks in registration order.""" return [(event, matcher) for event, matcher, _ in albedo_hooks.registered()]
def clear(self) -> None: """Remove all registered callbacks.""" albedo_hooks.clear()
def setup(api: PythonApi) -> dict[str, object]: albedo_hooks.enabled = True api.on_shutdown(albedo_hooks.clear) api.on_shutdown(albedo_hooks.end) # runs first: callbacks still registered return {"hooks": Hooks()}