/**
 * Phase 1 — CliEventBus
 * Normalizes core onProgress/onTrace events into a unified stream.
 * Deterministic; no LLM calls here.
 */
export function createCliEventBus() {
    const events = [];
    const listeners = new Set();
    return {
        emit(event) {
            events.push(event);
            for (const listener of listeners) {
                try {
                    listener(event);
                }
                catch {
                    // isolated delivery; one failing listener must not break others
                }
            }
        },
        subscribe(listener) {
            listeners.add(listener);
            return () => {
                listeners.delete(listener);
            };
        },
        snapshot() {
            return events.slice();
        },
    };
}
