@phren/cli
Version:
Knowledge layer for AI agents - CLI, MCP server, and data layer
31 lines (30 loc) • 1.09 kB
JavaScript
import * as fs from "fs";
import * as path from "path";
import { debugLog } from "../shared.js";
import { errorMessage } from "../utils.js";
const MAX_LOG_LINES = 1000;
export function recordRetrieval(phrenPath, file, section) {
const dir = path.join(phrenPath, ".runtime");
let logPath;
try {
fs.mkdirSync(dir, { recursive: true });
logPath = path.join(dir, "retrieval-log.jsonl");
const entry = { file, section, retrievedAt: new Date().toISOString() };
fs.appendFileSync(logPath, JSON.stringify(entry) + "\n");
}
catch (err) {
debugLog(`recordRetrieval write failed: ${errorMessage(err)}`);
return;
}
try {
const stat = fs.statSync(logPath);
if (stat.size > 500_000) {
const content = fs.readFileSync(logPath, "utf8");
const lines = content.split("\n").filter(Boolean);
fs.writeFileSync(logPath, lines.slice(-MAX_LOG_LINES).join("\n") + "\n");
}
}
catch (err) {
debugLog(`recordRetrieval rotation failed: ${errorMessage(err)}`);
}
}