HookExecutor class

Central hook execution engine.

Manages hook registration, chain execution, history tracking, and statistics. All hook execution flows through this class.

Usage:

final executor = HookExecutor();

// Register a hook
executor.register(HookRegistration(
  id: 'my-hook',
  type: HookType.preToolExecution,
  name: 'My Hook',
  handler: (ctx) => const HookContinue(),
));

// Execute hooks for a type
final result = await executor.executeAsync(
  HookType.preToolExecution,
  ToolHookContext(
    hookType: HookType.preToolExecution,
    timestamp: DateTime.now(),
    toolName: 'bash',
    toolInput: {'command': 'ls'},
  ),
);

Constructors

HookExecutor({int maxHistorySize = 1000, Duration defaultTimeout = const Duration(seconds: 5)})

Properties

defaultTimeout → Duration
Default timeout for individual hook execution.
final
hashCode → int
The hash code for this object.
no setterinherited
maxHistorySize → int
Maximum number of history entries to keep.
final
onHookExecuted → Stream<HookExecutionEvent>
Stream of hook execution events. Subscribe to monitor all hook activity.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

clearAll() → void
Remove all registered hooks.
clearHistory() → void
Clear all execution history and reset statistics.
disable(String hookId) → void
Disable a hook without unregistering it.
dispose() → void
Dispose of the executor, closing the event stream.
enable(String hookId) → void
Enable a previously disabled hook.
execute(HookType type, HookContext context) → HookResult
Execute all matching hooks for the given type synchronously.
executeAsync(HookType type, HookContext context) → Future<HookResult>
Execute all matching hooks for the given type asynchronously.
executeBatch(HookType type, List<HookContext> contexts) → Future<List<HookResult>>
Execute hooks for a batch of contexts, returning one result per context.
executeWithTimeout(HookType type, HookContext context, Duration timeout) → Future<HookResult>
Execute hooks with an overall timeout for the entire chain.
getExecutionHistory({HookType? type, int? limit}) → List<HookExecutionEvent>
Get execution history, optionally filtered by type and/or limited.
getRegistered({HookType? type, HookPriority? priority}) → List<HookRegistration>
Get all registered hooks, optionally filtered by type and/or priority.
hasHooks(HookType type) → bool
Check if any hooks are registered for a given type.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
register(HookRegistration registration) → String
Register a hook and return its ID.
stats() → HookStats
Get aggregate execution statistics.
toString() → String
A string representation of this object.
inherited
unregister(String hookId) → bool
Unregister a hook by ID. Returns true if found and removed.
unregisterSource(String source) → int
Unregister all hooks from a given source.

Operators

operator ==(Object other) → bool
The equality operator.
inherited