import { appendFileSync } from "node:fs"; type Debug = (event: string, details?: Record) => void; const path = process.env.KLAUS_DEBUG_LOG; /** Temporary Klaus tracing. Delete this file, its imports, and all dbg?.(...) calls together. */ export const dbg: Debug | undefined = path ? (event, details = {}) => { try { appendFileSync( path, `${JSON.stringify({ timestamp: new Date().toISOString(), pid: process.pid, event, ...details, })}\n`, { encoding: "utf8", mode: 0o600 }, ); } catch (error) { process.stderr.write( `Klaus dbg failed: ${error instanceof Error ? error.message : String(error)}\n`, ); } } : undefined;