class RunEventBus {
    listeners = new Set();
    publish(event) {
        for (const entry of this.listeners) {
            if (entry.filter.runId && entry.filter.runId !== event.runId)
                continue;
            if (entry.filter.projectPath && event.projectPath && normalize(entry.filter.projectPath) !== normalize(event.projectPath))
                continue;
            try {
                entry.listener(event);
            }
            catch {
                // Event subscribers must never disrupt the persisted run log.
            }
        }
    }
    subscribe(filter, listener) {
        const entry = { filter, listener };
        this.listeners.add(entry);
        return {
            unsubscribe: () => {
                this.listeners.delete(entry);
            },
        };
    }
}
const singleton = new RunEventBus();
export function getRunEventBus() {
    return singleton;
}
function normalize(value) {
    return value.replace(/\\/g, "/").toLowerCase();
}
