UNPKG

@nanocollective/nanocoder

Version:

A local-first CLI coding agent that brings the power of agentic coding tools like Claude Code and Gemini CLI to local models or controlled APIs like OpenRouter

61 lines 2.12 kB
/** * Memory health check */ /** * Check memory usage */ export function checkMemory(config) { const startTime = performance.now(); const memory = process.memoryUsage(); const heapUsagePercent = memory.heapUsed / memory.heapTotal; const externalMB = memory.external / 1024 / 1024; const thresholds = config.thresholds.memory; let status = 'pass'; let message = 'Memory usage is healthy'; const details = { heapUsedMB: Math.round(memory.heapUsed / 1024 / 1024), heapTotalMB: Math.round(memory.heapTotal / 1024 / 1024), heapUsagePercent: Math.round(heapUsagePercent * 100), externalMB: Math.round(externalMB), rssMB: Math.round(memory.rss / 1024 / 1024), }; if (heapUsagePercent > thresholds.heapUsageCritical || externalMB > thresholds.externalCritical) { status = 'fail'; message = 'Memory usage is critically high'; } else if (heapUsagePercent > thresholds.heapUsageWarning || externalMB > thresholds.externalWarning) { status = 'warn'; message = 'Memory usage is elevated'; } return { name: 'memory-usage', status, score: calculateScore(status, heapUsagePercent, thresholds.heapUsageWarning, thresholds.heapUsageCritical), duration: performance.now() - startTime, message, details, threshold: { warning: thresholds.heapUsageWarning, critical: thresholds.heapUsageCritical, }, }; } /** * Calculate score based on status and value */ function calculateScore(status, value, warningThreshold, criticalThreshold) { if (status === 'fail') return 0; if (status === 'pass') return 100; if (status === 'warn') { // Calculate score based on how far from critical threshold const range = criticalThreshold - warningThreshold; const distance = criticalThreshold - value; return Math.max(50, Math.min(80, 50 + (distance / range) * 30)); } return 50; // default for unknown status } //# sourceMappingURL=memory-check.js.map