Session files (JSONLs, debug logs, todos, telemetry, group logs) accumulate unboundedly — especially from daily cron tasks. This adds a cleanup script that prunes old artifacts while protecting active sessions (read from DB), and wires it into the main process on a 24h interval. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
26 lines
762 B
TypeScript
26 lines
762 B
TypeScript
import { execFile } from 'child_process';
|
|
import path from 'path';
|
|
|
|
import { logger } from './logger.js';
|
|
|
|
const CLEANUP_INTERVAL = 24 * 60 * 60 * 1000; // 24 hours
|
|
const SCRIPT_PATH = path.resolve(process.cwd(), 'scripts/cleanup-sessions.sh');
|
|
|
|
function runCleanup(): void {
|
|
execFile('/bin/bash', [SCRIPT_PATH], { timeout: 60_000 }, (err, stdout) => {
|
|
if (err) {
|
|
logger.error({ err }, 'Session cleanup failed');
|
|
return;
|
|
}
|
|
const summary = stdout.trim().split('\n').pop();
|
|
if (summary) logger.info(summary);
|
|
});
|
|
}
|
|
|
|
export function startSessionCleanup(): void {
|
|
// Run once at startup (delayed 30s to not compete with init)
|
|
setTimeout(runCleanup, 30_000);
|
|
// Then every 24 hours
|
|
setInterval(runCleanup, CLEANUP_INTERVAL);
|
|
}
|