/** * Global hook registry for the ecosystem. Packages add their typed hooks * via module augmentation: * * declare module '@basaltkit/core' { * interface BasaltHooks { * 'tenancy:switched': { tenantId: string } * } * } */ export interface BasaltHooks { [hook: string]: unknown; } export type HookHandler

= (payload: P) => void | Promise; /** Receives every hook emission — the audit trail and devtools hang here. */ export type AnyHookHandler = (hook: string, payload: unknown) => void | Promise; export declare class HookBus { private readonly handlers; private readonly anyHandlers; /** Registers a handler. Higher `priority` runs first. Returns an unsubscribe function. */ on(hook: K, handler: HookHandler, options?: { priority?: number; }): () => void; /** Subscribes to every hook. Runs after the specific handlers. */ onAny(handler: AnyHookHandler): () => void; /** * Runs the handlers in series, in priority order, then the onAny handlers. * * Handlers are ISOLATED (same contract as EventBus.emit): one failure never * starves the remaining handlers or the onAny observers (audit/devtools) — * every registered handler always runs. Failures still surface to the * emitter afterwards: a single failure rethrows the original error, several * become an AggregateError. Nothing is ever swallowed silently. */ emit(hook: K, payload: BasaltHooks[K]): Promise; }