Something went wrong. Try again.
fork of prime agent with changes i want but are not upstreamable probqbly (and some fixes)
Something went wrong. Try again.
935 B · 23 lines
TypeScript
123456789101112131415161718192021222324import { type LogEntry, setLogSink, stringifyLogEntry } from "@earendil-works/pi-ai";import { appendRotatingLog, getAgentLogPath } from "../config.js";
const AGENT_LOG_MAX_BYTES = 20 * 1024 * 1024;
let context: Record<string, unknown> = {};
/** Merge late-bound fields (e.g. mode, sessionId) into every subsequent log entry. */export function setLogContext(fields: Record<string, unknown>): void { Object.assign(context, fields);}
/** * Route all structured logging (coding-agent and pi-ai) to the shared JSONL * log at ~/.prime/agent/logs/agent.jsonl. One master file, filterable by the * pid/context fields; writes are best-effort and size-bounded. */export function installFileLogSink(fields?: Record<string, unknown>): void { context = { pid: process.pid, ...fields }; setLogSink((entry: LogEntry) => { appendRotatingLog(getAgentLogPath(), stringifyLogEntry({ ...entry, ...context }), AGENT_LOG_MAX_BYTES); });}