File size: 2,019 Bytes
64bc9a3 5309613 64bc9a3 5309613 64bc9a3 5309613 64bc9a3 5309613 64bc9a3 5309613 64bc9a3 5309613 64bc9a3 5309613 64bc9a3 5309613 64bc9a3 5309613 64bc9a3 5309613 64bc9a3 5309613 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | // System information tool — multi-OS device telemetry.
// Works on macOS, Linux, and Windows. Read-only, always safe.
import os from 'node:os';
const PLATFORM = os.platform();
const PLATFORM_LABEL = { darwin: 'macOS', linux: 'Linux', win32: 'Windows' };
export const sysinfo = {
name: 'sysinfo',
description: `Get device system information (hostname, OS, CPU, memory, load, uptime) — running on ${PLATFORM_LABEL[PLATFORM] || PLATFORM}`,
args: {},
platform: PLATFORM,
async run() {
const cpus = os.cpus();
const totalMem = os.totalmem();
const freeMem = os.freemem();
const loadavg = os.loadavg();
// Platform-specific info
const platformInfo = {};
if (PLATFORM === 'darwin') {
platformInfo.machine = os.machine?.() || os.arch();
platformInfo.endianness = os.endianness?.() || 'LE';
} else if (PLATFORM === 'linux') {
const releaseInfo = os.release();
platformInfo.kernel = releaseInfo;
} else if (PLATFORM === 'win32') {
platformInfo.version = os.version?.() || os.release();
}
return {
host: os.hostname(),
platform: PLATFORM,
platformName: PLATFORM_LABEL[PLATFORM] || PLATFORM,
arch: os.arch(),
release: os.release(),
cpus: cpus.length,
cpuModel: cpus[0]?.model || 'unknown',
cpuSpeed: cpus[0]?.speed || 0,
mem: {
total: totalMem,
free: freeMem,
used: totalMem - freeMem,
percent: Math.round((1 - freeMem / totalMem) * 100),
},
loadavg: loadavg.map(v => Math.round(v * 100) / 100),
uptime: Math.round(os.uptime()),
network: Object.entries(os.networkInterfaces())
.filter(([k]) => !k.startsWith('lo') && !k.startsWith('Loopback'))
.flatMap(([iface, addrs]) =>
(addrs || []).filter(a => a.family === 'IPv4' && !a.internal)
.map(a => ({ iface, address: a.address }))
)
.slice(0, 8),
...platformInfo,
};
},
};
|