import { execFile } from "node:child_process"; import { promisify } from "node:util"; const execFileAsync = promisify(execFile); export async function publishNoctaliaState( state, { execute = async (command, args) => execFileAsync(command, args) } = {}, ) { if (!state || typeof state !== "object") throw new TypeError("state is required"); const { state: bridgeState, projectLabel, attentionCount, detail, openCount = 0, workingCount = 0, recoveringCount = 0, errorCount = 0 } = state; if ( typeof bridgeState !== "string" || typeof projectLabel !== "string" || ![attentionCount, openCount, workingCount, recoveringCount, errorCount].every(Number.isSafeInteger) || typeof detail !== "string" ) throw new TypeError("state must contain presentation strings and integer counts"); await execute("qs", [ "-c", "noctalia-shell", "ipc", "call", "plugin:pi-status-bridge", "setBridgeState", bridgeState, projectLabel, String(attentionCount), detail, String(openCount), String(workingCount), String(recoveringCount), String(errorCount), ]); }