UNPKG

gepa-spo

Version:

Genetic-Pareto prompt optimizer to evolve system prompts from a few rollouts with modular support and intelligent crossover

73 lines (72 loc) 2.25 kB
/** * Simple colored logger with high-level step logging. * No external deps; ANSI colors via constants only. */ /** ANSI color constants (do not hardcode colors elsewhere). */ export const COLORS = { reset: '\u001b[0m', dim: '\u001b[2m', bold: '\u001b[1m', gray: '\u001b[90m', red: '\u001b[31m', green: '\u001b[32m', yellow: '\u001b[33m', blue: '\u001b[34m', magenta: '\u001b[35m', cyan: '\u001b[36m', white: '\u001b[37m' }; function shouldLog(level, desired) { const order = { error: 0, warn: 1, info: 2, debug: 3 }; if (desired === 'silent') return false; if (level === 'silent') return false; return order[level] <= order[desired]; } export function createLogger(enabled, level = 'info') { const fmt = (color, label, msg) => { return `${COLORS.dim}${new Date().toISOString()}${COLORS.reset} ${color}${label}${COLORS.reset} ${msg}`; }; const logImpl = (target, color, label, msg) => { if (!enabled) return; // eslint-disable-next-line no-console console[target](fmt(color, label, msg)); }; return { enabled, level, info(message) { if (shouldLog('info', level)) logImpl('log', COLORS.cyan, '[info]', message); }, warn(message) { if (shouldLog('warn', level)) logImpl('warn', COLORS.yellow, '[warn]', message); }, error(message) { if (shouldLog('error', level)) logImpl('error', COLORS.red, '[error]', message); }, debug(message) { if (shouldLog('debug', level)) logImpl('log', COLORS.gray, '[debug]', message); }, step(title, detail) { if (!enabled) return; const t = `${COLORS.magenta}${COLORS.bold}${title}${COLORS.reset}`; const d = detail ? `${COLORS.gray}${detail}${COLORS.reset}` : ''; // eslint-disable-next-line no-console console.log(`${t} ${d}`.trim()); } }; } /** A no-op logger you can use as default. */ export const silentLogger = createLogger(false, 'silent');