/** * OrchestratorLifecycleHooks — Orchestrator-level agent lifecycle hooks. * * Unlike AdapterHookManager (which wraps individual adapter calls), these * hooks wrap the full delegation pipeline: auth → injection scan → adapter * execution → quality gate → result. * * Three phases: `beforeSpawn`, `afterComplete`, `onFailure`. * * @module OrchestratorLifecycleHooks */ /** Lifecycle phase */ export type LifecyclePhase = 'beforeSpawn' | 'afterComplete' | 'onFailure'; /** Context available at beforeSpawn — agent selected, not yet executed */ export interface BeforeSpawnContext { agentId: string; instruction: string; priority: string; requiresAuth: boolean; metadata: Record; /** Set to true to abort the delegation before execution */ aborted: boolean; /** If aborted, reason shown to caller */ abortReason?: string; } /** Context available at afterComplete — result approved by quality gate */ export interface AfterCompleteContext { agentId: string; instruction: string; result: unknown; durationMs: number; tokensUsed: number; metadata: Record; } /** Context available at onFailure — error captured */ export interface OnFailureContext { agentId: string; instruction: string; error: Error | string; durationMs: number; metadata: Record; /** Set to true to suppress the error (delegation returns a default instead) */ suppress: boolean; } /** Hook handler — can be sync or async */ export type LifecycleHandler = (ctx: T) => void | Promise; /** Registered hook entry */ export interface LifecycleHookEntry { name: string; phase: LifecyclePhase; priority: number; handler: LifecycleHandler; } /** * Registry and runner for orchestrator-level lifecycle hooks. * * @example * ```ts * const hooks = new OrchestratorLifecycleHooks(); * * hooks.beforeSpawn('log-spawn', (ctx) => { * console.log(`Spawning ${ctx.agentId}: ${ctx.instruction}`); * }); * * hooks.afterComplete('track-cost', (ctx) => { * costTracker.record(ctx.agentId, ctx.tokensUsed, ctx.durationMs); * }); * * hooks.onFailure('alert', (ctx) => { * alerting.send(`${ctx.agentId} failed: ${ctx.error}`); * }); * ``` */ export declare class OrchestratorLifecycleHooks { private hooks; /** * Register a beforeSpawn hook. * Can modify context or set `aborted = true` to block execution. */ beforeSpawn(name: string, handler: LifecycleHandler, priority?: number): void; /** * Register an afterComplete hook. * Receives the approved result after quality gate. */ afterComplete(name: string, handler: LifecycleHandler, priority?: number): void; /** * Register an onFailure hook. * Can set `suppress = true` to silently absorb the error. */ onFailure(name: string, handler: LifecycleHandler, priority?: number): void; /** Remove a hook by name */ unregister(name: string): boolean; /** List all registered hooks */ list(): LifecycleHookEntry[]; /** Number of registered hooks */ size(): number; /** Clear all hooks */ clear(): void; /** * Run all beforeSpawn hooks in priority order. * Returns the (potentially mutated) context. */ runBeforeSpawn(ctx: BeforeSpawnContext): Promise; /** * Run all afterComplete hooks in priority order. */ runAfterComplete(ctx: AfterCompleteContext): Promise; /** * Run all onFailure hooks in priority order. * Returns the (potentially mutated) context. */ runOnFailure(ctx: OnFailureContext): Promise; private register; private runPhase; } //# sourceMappingURL=lifecycle-hooks.d.ts.map