Skip to content

fix(metrics): simplify macOS memory to use Node.js os module#42

Closed
Claude wants to merge 6 commits intomainfrom
claude/remove-systeminformation-dependency
Closed

fix(metrics): simplify macOS memory to use Node.js os module#42
Claude wants to merge 6 commits intomainfrom
claude/remove-systeminformation-dependency

Conversation

@Claude
Copy link
Contributor

@Claude Claude AI commented Feb 16, 2026

The vm_stat-based macOS memory calculation was inaccurate. Simplified to use Node.js native os.freemem() and os.totalmem(), matching the Windows approach.

Changes:

  • Replaced ~40 lines of vm_stat parsing with 5-line implementation using Node.js os module
  • macOS and Windows now share identical memory collection logic
  • Linux continues using /proc/meminfo for MemAvailable/Active fields

Before (vm_stat parsing):

// Parse vm_stat output, extract page size, count pages by type
// Calculate: active = (pagesActive + pagesWiredDown) * pageSize
// Calculate: available = (pagesFree + pagesInactive + ...) * pageSize

After (Node.js native):

const available = freemem();
const total = totalmem();
const active = total - available;

Co-authored-by: Garbee <868301+Garbee@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Remove dependency on systeminformation package refactor(metrics): replace systeminformation with native OS commands Feb 16, 2026
@Claude Claude AI requested a review from Garbee February 16, 2026 13:16
…ction

Co-authored-by: Garbee <868301+Garbee@users.noreply.github.com>
@Claude Claude AI changed the title refactor(metrics): replace systeminformation with native OS commands fix(metrics): use PowerShell for Windows and fix macOS page size detection Feb 16, 2026
Co-authored-by: Garbee <868301+Garbee@users.noreply.github.com>
@Claude Claude AI changed the title fix(metrics): use PowerShell for Windows and fix macOS page size detection refactor(metrics): replace systeminformation with native OS commands Feb 16, 2026
…racy

Co-authored-by: Garbee <868301+Garbee@users.noreply.github.com>
@Claude Claude AI changed the title refactor(metrics): replace systeminformation with native OS commands fix(metrics): correct Windows disk collection and improve memory accuracy Feb 16, 2026

function getLinuxMemory(): MemoryInfo {
// Read /proc/meminfo for accurate memory statistics
const meminfo = execSync("cat /proc/meminfo", { encoding: "utf-8" });

Check warning

Code scanning / CodeQL

Unnecessary use of `cat` process Medium

Unnecessary use of cat process. Can be replaced with: fs.readFileSync("/proc/meminfo", ...)

Copilot Autofix

AI 23 days ago

To fix this, replace the use of execSync("cat /proc/meminfo", ...) with a direct file read via Node’s fs.readFileSync. This removes the need to spawn a shell and execute cat, while preserving the current behavior of returning the file contents as a UTF‑8 string.

Concretely, in src/system-info.ts, within getLinuxMemory(), change the line:

const meminfo = execSync("cat /proc/meminfo", { encoding: "utf-8" });

to:

const meminfo = readFileSync("/proc/meminfo", { encoding: "utf-8" });

You then need to import readFileSync from the Node fs module at the top of the file. No other logic needs to change; the parsing of meminfo as a string remains the same and the function signature and return type are unaffected.

Suggested changeset 1
src/system-info.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/system-info.ts b/src/system-info.ts
--- a/src/system-info.ts
+++ b/src/system-info.ts
@@ -1,5 +1,6 @@
 import { execSync } from "node:child_process";
 import { freemem, totalmem } from "node:os";
+import { readFileSync } from "node:fs";
 
 /**
  * Native system information collector that replaces systeminformation package.
@@ -86,7 +87,7 @@
 
 function getLinuxMemory(): MemoryInfo {
   // Read /proc/meminfo for accurate memory statistics
-  const meminfo = execSync("cat /proc/meminfo", { encoding: "utf-8" });
+  const meminfo = readFileSync("/proc/meminfo", { encoding: "utf-8" });
 
   let memTotal = 0;
   let memAvailable = 0;
EOF
@@ -1,5 +1,6 @@
import { execSync } from "node:child_process";
import { freemem, totalmem } from "node:os";
import { readFileSync } from "node:fs";

/**
* Native system information collector that replaces systeminformation package.
@@ -86,7 +87,7 @@

function getLinuxMemory(): MemoryInfo {
// Read /proc/meminfo for accurate memory statistics
const meminfo = execSync("cat /proc/meminfo", { encoding: "utf-8" });
const meminfo = readFileSync("/proc/meminfo", { encoding: "utf-8" });

let memTotal = 0;
let memAvailable = 0;
Copilot is powered by AI and may make mistakes. Always verify output.
Co-authored-by: Garbee <868301+Garbee@users.noreply.github.com>
@Claude Claude AI changed the title fix(metrics): correct Windows disk collection and improve memory accuracy fix(metrics): simplify macOS memory to use Node.js os module Feb 16, 2026
@Garbee Garbee closed this Feb 16, 2026
@Garbee Garbee deleted the claude/remove-systeminformation-dependency branch February 16, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants