import { isClarkVerboseLogsEnabled } from "./socket-manager.js";
import { registerLogListener, } from "./util/logger.js";
/**
 * Forwards Clark logs to connected browser clients via WebSocket.
 * Logs appear in Chrome DevTools with a [Clark:state] prefix.
 *
 * Enabled by default for internal dev (SUPERBLOCKS_CLI_ENV=local), or via `?clark_logs=true` query param.
 */
export function createClarkLogForwarder({ getEditorClients, getClarkState, }) {
    const forwardableLevels = new Set(["info", "warn", "error"]);
    const unregister = registerLogListener((entry) => {
        if (!isClarkVerboseLogsEnabled()) {
            return;
        }
        if (!forwardableLevels.has(entry.level)) {
            return;
        }
        const state = getClarkState();
        const payload = {
            level: entry.level,
            state,
            messages: entry.messages,
            timestamp: entry.timestamp,
            meta: entry.meta,
        };
        for (const client of getEditorClients()) {
            client.call.clarkLog(payload).catch(() => { });
        }
    });
    return unregister;
}
//# sourceMappingURL=clark-log-forwarder.js.map