utils/hooks/hook_manager library

Hook Manager

Ported from neomage/src/utils/hooks/:

  • sessionHooks.ts — session-scoped hook lifecycle
  • hooksConfigManager.ts — hook event metadata and grouping
  • hooksSettings.ts — hook settings, sources, equality, display
  • hookEvents.ts — hook event emission system
  • AsyncHookRegistry.ts — async hook tracking
  • ssrfGuard.ts — SSRF address blocking for HTTP hooks

Provides the full hook lifecycle for the Sint-based Flutter port: session hooks, function hooks, event metadata, config grouping, hook emission, async hook registry, and SSRF protection.

Classes

AgentHook
Agent hook (multi-turn LLM agent).
AggregatedHookResult
Aggregated result from hook execution.
AsyncHookRegistry
Registry for tracking async hooks awaiting completion.
CommandHook
Shell command hook.
FunctionHook
Function hook (in-memory callback, session-scoped only).
FunctionHookMatcher
Function hook matcher (for getSessionFunctionHooks).
HookCommand
Base type for all hook commands.
HookEventEmitter
Hook event emission manager.
HookEventMetadata
Metadata for a hook event.
HookExecutionEvent
Base class for hook execution events.
HookProgressEvent
Emitted periodically during hook execution.
HookResponseEvent
Emitted when a hook finishes executing.
HookStartedEvent
Emitted when a hook starts executing.
HttpHook
HTTP hook (sends request to URL).
IndividualHookConfig
A single hook configuration with its source and event info.
MatcherMetadata
Metadata for matching hook events.
PendingAsyncHook
A pending async hook awaiting completion.
PromptHook
Prompt hook (LLM evaluates a prompt).
SessionDerivedHookMatcher
Derived hook matcher (without function hooks).
SessionHookEntry
An entry pairing a hook with its optional success callback.
SessionHookMatcher
A single matcher entry in the session hook store.
SessionHooksManager
Session hooks state manager. Uses a Map for O(1) mutations (same pattern as TS: Map not Record, to avoid O(N^2) copies).
SessionStore
Session hook store per session.

Enums

HookExecutionEventType
Hook execution event types.
HookSource
Source of a hook configuration.

Constants

alwaysEmittedHookEvents → const List<String>
Hook events always emitted regardless of includeHookEvents option.
defaultHookShell → const String
Default shell for command hooks.
hookEvents → const List<String>
All supported hook event names.

Functions

getHookDisplayText(HookCommand hook) String
Get the display text for a hook.
getHookEventMetadata(List<String> toolNames) Map<HookEvent, HookEventMetadata>
Get metadata for all hook events.
hookSourceDescription(HookSource source) String
Display strings for hook sources.
hookSourceHeader(HookSource source) String
hookSourceInline(HookSource source) String
isBlockedAddress(String address) bool
Returns true if the address is in a range that HTTP hooks should not reach. Loopback (127.0.0.0/8, ::1) is intentionally ALLOWED for local dev hooks.
isHookEqual(HookCommand a, HookCommand b) bool
Check if two hooks are equal (comparing command/prompt content, not timeout).

Typedefs

HookEvent = String
HookEventHandler = void Function(HookExecutionEvent event)