Skip to content

@studnicky/system

Portable runtime facts with Node host inspection and browser capability reporting.

Install

bash
pnpm add @studnicky/system

Requires @studnicky:registry=https://npm.pkg.github.com in .npmrc.

Usage

CPU, memory, and platform

Read CPU topology, memory usage, and platform info synchronously, plus the computed worker-pool recommendation:

ts
import { System } from '../src/node/index.js';

const cpu = System.cpu;
console.log('CPU:');
console.log(`  cpu.arch          = ${cpu.arch}`);
console.log(`  cpu.model         = ${cpu.model}`);
console.log(`  cpu.logicalCount  = ${cpu.logicalCount}`);
console.log(`  cpu.physicalCount = ${cpu.physicalCount}`);

console.log(`Optimal worker count = ${System.optimalWorkerCount}`);

const mem = System.memory;
console.log('Memory:');
console.log(`  memory.totalMb = ${mem.totalMb}`);
console.log(`  memory.freeMb  = ${mem.freeMb}`);

const plat = System.platform;
const nodeVersion = plat.nodeVersion;
if (nodeVersion === undefined) {
  throw new Error('Node System adapter must report nodeVersion');
}
console.log('Platform:');
console.log(`  platform.os             = ${plat.os}`);
console.log(`  platform.nodeVersion    = ${nodeVersion}`);
console.log(`  platform.isAppleSilicon = ${plat.isAppleSilicon}`);

GPU detection

System.gpu() synchronously detects and caches GPU information, then returns a defensive copy. The Node adapter invokes system_profiler on macOS, nvidia-smi for Linux NVIDIA systems, or rocm-smi for Linux AMD systems, returning null when detection is unavailable. Import the Node adapter from @studnicky/system/node and use the canonical System.cpu, System.gpu(), System.memory, and System.platform APIs.

Try it

Loading example…

The output shows live CPU architecture, model, logical and physical counts, optimalWorkerCount, total and free memory in megabytes, OS name, runtime version string, and the Apple Silicon flag — all read from navigator in-browser.

API

ExportTypeDescription
SystemclassStatic-only system introspection API
CpuInfoEntity.Typeentity type{ arch, logicalCount, physicalCount, model }
MemoryInfoEntity.Typeentity type{ totalMb, freeMb }
PlatformInfoEntity.Typeentity type{ os, isAppleSilicon, nodeVersion }
GpuInfoEntity.Typeentity type{ name, computeApi, vramMb }
SystemInfoEntity.Typeentity typeCanonical composition of CPU, GPU, memory, and platform data
SystemProviderInterfaceinterfaceRuntime provider contract used by platform implementations

System

MemberSignatureDescription
cpustatic get cpu(): CpuInfoEntity.TypeCPU model, architecture, logical count, and physical count
memorystatic get memory(): MemoryInfoEntity.TypeTotal and free memory in megabytes
platformstatic get platform(): PlatformInfoEntity.TypeOS, Node.js version, and Apple Silicon flag
gpustatic gpu(): GpuInfoEntity.Type | nullDetects and caches GPU information; returns a defensive copy or null when unavailable
optimalWorkerCountstatic get optimalWorkerCount(): numbermax(1, System.cpu.logicalCount - 1)

GpuInfoEntity.Type.computeApi values

ValuePlatformDetector
'metal'macOSsystem_profiler SPDisplaysDataType
'cuda'Linux (NVIDIA)nvidia-smi
'opencl'Linux (AMD)rocm-smi
'software'software rendererreported by providers that identify a software-backed renderer

Source on GitHub

Entities

@studnicky/system/entities exports every schema namespace in src/entities.

typescript
import { SystemInfoEntity } from '@studnicky/system/entities';

Interfaces

@studnicky/system/interfaces exports every TypeScript interface in src/interfaces, including configuration and state contracts.

typescript
import type { SystemProviderInterface } from '@studnicky/system/interfaces';

Exports

SymbolPurposeImport path
SystemProvides Node runtime facts.@studnicky/system/node
SystemInterfaceDefines shared Node and browser runtime facts.@studnicky/system
SystemProvides browser runtime facts.@studnicky/system/browser