@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
37 lines • 1.16 kB
JavaScript
/**
* Safe process metrics utilities
* Provides defensive wrappers around process.memoryUsage() and process.cpuUsage()
* to handle environments where process is polyfilled to null
*/
import nodeProcess from 'node:process';
/**
* Safe memory usage getter with runtime checks
* Returns fallback values if process.memoryUsage() is unavailable or throws
*/
export function getSafeMemory() {
try {
if (nodeProcess && typeof nodeProcess.memoryUsage === 'function') {
return nodeProcess.memoryUsage();
}
}
catch {
// Ignore any errors during process.memoryUsage()
}
return { rss: 0, heapTotal: 0, heapUsed: 0, external: 0, arrayBuffers: 0 };
}
/**
* Safe CPU usage getter with runtime checks
* Returns fallback values if process.cpuUsage() is unavailable or throws
*/
export function getSafeCpuUsage() {
try {
if (nodeProcess && typeof nodeProcess.cpuUsage === 'function') {
return nodeProcess.cpuUsage();
}
}
catch {
// Ignore any errors during process.cpuUsage()
}
return { user: 0, system: 0 };
}
//# sourceMappingURL=safe-process.js.map