From f5065abf41f47c0a1facfb134fc401620088f5bc Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 24 Aug 2025 13:24:57 -0700 Subject: [PATCH] fix: address feedback --- .../src/services/ResourceMonitoringService.ts | 16 +++++----------- extensions/cli/src/ui/TUIChat.tsx | 3 ++- .../cli/src/ui/components/ResourceDebugBar.tsx | 6 +++++- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/extensions/cli/src/services/ResourceMonitoringService.ts b/extensions/cli/src/services/ResourceMonitoringService.ts index bceaa4478..a114d3027 100644 --- a/extensions/cli/src/services/ResourceMonitoringService.ts +++ b/extensions/cli/src/services/ResourceMonitoringService.ts @@ -1,4 +1,5 @@ import { exec } from "child_process"; +import * as os from "os"; import { promisify } from "util"; import { logger } from "../util/logger.js"; @@ -265,10 +266,7 @@ class ResourceMonitoringService { private getLoadAverage(): number[] { try { - return process.platform !== "win32" && - typeof (process as any).loadavg === "function" - ? (process as any).loadavg() - : [0, 0, 0]; + return process.platform === "win32" ? [0, 0, 0] : os.loadavg(); } catch { return [0, 0, 0]; } @@ -284,9 +282,7 @@ class ResourceMonitoringService { private getFreeMemory(): number { try { - return typeof (process as any).freemem === "function" - ? (process as any).freemem() - : 0; + return os.freemem(); } catch { return 0; } @@ -294,11 +290,9 @@ class ResourceMonitoringService { private getTotalMemory(): number { try { - return typeof (process as any).totalmem === "function" - ? (process as any).totalmem() - : 1024 * 1024 * 1024; // 1GB default + return os.totalmem(); } catch { - return 1024 * 1024 * 1024; // 1GB default + return 1024 * 1024 * 1024; // 1GB default fallback } } diff --git a/extensions/cli/src/ui/TUIChat.tsx b/extensions/cli/src/ui/TUIChat.tsx index 9cc9cfdc0..5e39f6e12 100644 --- a/extensions/cli/src/ui/TUIChat.tsx +++ b/extensions/cli/src/ui/TUIChat.tsx @@ -15,6 +15,7 @@ import { MCPServiceState, ModelServiceState, } from "../services/types.js"; +import { logger } from "../util/logger.js"; import { BottomStatusBar } from "./components/BottomStatusBar.js"; import { ResourceDebugBar } from "./components/ResourceDebugBar.js"; @@ -64,7 +65,7 @@ async function loadAndSetSession( // Load the session history const sessionHistory = loadSessionById(sessionId); if (!sessionHistory) { - console.error(`Session ${sessionId} could not be loaded.`); + logger.error(`Session ${sessionId} could not be loaded.`); return; } diff --git a/extensions/cli/src/ui/components/ResourceDebugBar.tsx b/extensions/cli/src/ui/components/ResourceDebugBar.tsx index 344ceed96..340edc757 100644 --- a/extensions/cli/src/ui/components/ResourceDebugBar.tsx +++ b/extensions/cli/src/ui/components/ResourceDebugBar.tsx @@ -50,7 +50,7 @@ export function ResourceDebugBar({ visible }: ResourceDebugBarProps) { }; }, [visible]); - if (!visible || !resourceData) { + if (!visible) { return null; } @@ -62,6 +62,10 @@ export function ResourceDebugBar({ visible }: ResourceDebugBarProps) { ); } + if (!resourceData) { + return null; + } + const memoryPercent = (resourceData.memory.rss / resourceData.system.totalMemory) * 100; const cpuPercent = resourceData.cpu.percent || 0;