import type { CortexEvent, CortexEventInput } from './event-types.js'; export interface Subscription { unsubscribe(): void; } export declare class EventBus { private _entries; private _closeHooks; /** Guard against re-entrant event-bus.handler-failed loops. */ private _inHandlerFailed; /** * Subscribe to a specific event type or '*' for all events. * Handlers are called in subscription-registration order on publish. * * Overloads narrow `e` to the matching variant when a specific K is given; * the '*' form receives the full CortexEvent union. */ subscribe(type: K, handler: (e: Extract) => void | Promise): Subscription; subscribe(type: '*', handler: (e: CortexEvent) => void | Promise): Subscription; /** * Publish an event. `ts` is injected here; callers omit it. * * Fan-out is synchronous: all matching handlers are called in subscription order * before publish() returns. If a handler returns a Promise it is fire-and-forget * (errors are caught and logged). If a handler throws synchronously the error is * logged and an `event-bus.handler-failed` meta-event is published; the remaining * handlers continue to run. */ publish(e: CortexEventInput): void; private _emitHandlerFailed; /** * Register a hook called by close(). EventLogger uses this to flush its buffer * before the process exits on SIGTERM. */ registerCloseHook(fn: () => Promise): void; /** * Flush all registered close hooks (e.g., EventLogger buffer drain). * Called from the app.ts SIGTERM handler alongside repo flushes. */ close(): Promise; }