about-system 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,457 @@
1
+ /**
2
+ * System Information Types
3
+ *
4
+ * TypeScript type definitions for the system information API response.
5
+ * All values are returned as clean strings without ANSI color codes or emojis.
6
+ */
7
+
8
+ /**
9
+ * Platform types supported by the system info service
10
+ */
11
+ export type Platform = 'linux' | 'windows' | 'macos' | 'unknown';
12
+
13
+ /**
14
+ * Complete system information object returned by the API
15
+ */
16
+ export interface SystemInfo {
17
+ /**
18
+ * ISO 8601 timestamp indicating when the system information was collected
19
+ * Format: "2025-01-15T10:30:00.000Z"
20
+ * Always present regardless of platform
21
+ *
22
+ * @example "2025-01-15T10:30:00.000Z"
23
+ */
24
+ timestamp: string;
25
+
26
+ // =============================================================================
27
+ // SYSTEM IDENTITY
28
+ // =============================================================================
29
+
30
+ /**
31
+ * System hostname or computer name
32
+ * The network name assigned to this machine
33
+ * Empty string if unable to determine
34
+ *
35
+ * @example "workstation-linux", "DESKTOP-ABC123", "MacBook-Pro"
36
+ */
37
+ hostname: string;
38
+
39
+ /**
40
+ * Username of the currently logged-in user
41
+ * The user account running the system info service
42
+ * Empty string if unable to determine
43
+ *
44
+ * @example "admin", "john.doe", "deck"
45
+ */
46
+ user: string;
47
+
48
+ /**
49
+ * Operating system platform classification
50
+ * Categorizes the underlying OS family
51
+ * Always present, defaults to 'unknown' if detection fails
52
+ */
53
+ platform: Platform;
54
+
55
+ // =============================================================================
56
+ // OPERATING SYSTEM INFORMATION
57
+ // =============================================================================
58
+
59
+ /**
60
+ * Operating system name and version string
61
+ * Human-readable OS identification including version numbers
62
+ * Empty string on detection failure
63
+ *
64
+ * @example
65
+ * - Linux: "Ubuntu 22.04.3 LTS", "CachyOS Linux", "SteamOS 3.5.7"
66
+ * - Windows: "Windows 11 Pro", "Windows 10 Enterprise"
67
+ * - macOS: "macOS Ventura 13.2.1"
68
+ */
69
+ os: string;
70
+
71
+ /**
72
+ * Kernel version string
73
+ * The core OS kernel version currently running
74
+ * Format varies by platform
75
+ * Empty string if unavailable
76
+ *
77
+ * @example
78
+ * - Linux: "6.2.0-37-generic", "6.1.52-valve16-1-neptune-61"
79
+ * - Windows: "10.0.22621.2428"
80
+ * - macOS: "22.3.0"
81
+ */
82
+ kernel: string;
83
+
84
+ /**
85
+ * Current shell program being used
86
+ * The command-line interface shell (Linux/Unix systems only)
87
+ * Empty string on Windows or if unable to detect
88
+ *
89
+ * @example "bash", "zsh", "fish", "powershell"
90
+ */
91
+ shell: string;
92
+
93
+ // =============================================================================
94
+ // HARDWARE SPECIFICATIONS
95
+ // =============================================================================
96
+
97
+ /**
98
+ * CPU model name and specifications
99
+ * Processor identification string, cleaned of unnecessary suffixes
100
+ * "with Radeon Graphics" and similar text is automatically stripped
101
+ * Empty string if detection fails
102
+ *
103
+ * @example
104
+ * - "Intel Core i7-12700K"
105
+ * - "AMD Ryzen 9 5900HX"
106
+ * - "Apple M2 Pro"
107
+ * - "AMD Custom APU 0405" (Steam Deck)
108
+ */
109
+ cpu: string;
110
+
111
+ /**
112
+ * Graphics card model name
113
+ * Primary GPU identification (Linux systems primarily)
114
+ * Extracted from lspci output when available
115
+ * Empty string if no discrete GPU or detection fails
116
+ *
117
+ * @example
118
+ * - "NVIDIA GeForce RTX 4070"
119
+ * - "AMD Radeon RX 6800 XT"
120
+ * - "Intel UHD Graphics 770"
121
+ */
122
+ gpu: string;
123
+
124
+ /**
125
+ * Device or computer model name
126
+ * Hardware model identification when available
127
+ * Useful for laptops, prebuilt systems, and specialized devices
128
+ * Empty string if not available or generic hardware
129
+ *
130
+ * @example
131
+ * - "Dell OptiPlex 7090"
132
+ * - "ASUS TUF Gaming A15"
133
+ * - "Valve Steam Deck"
134
+ * - "MacBook Pro 16-inch"
135
+ */
136
+ device: string;
137
+
138
+ // =============================================================================
139
+ // REAL-TIME RESOURCE USAGE
140
+ // =============================================================================
141
+
142
+ /**
143
+ * Root filesystem disk usage percentage
144
+ * Shows how full the primary disk partition is
145
+ * Format: number followed by percent sign
146
+ * Empty string if unable to determine
147
+ *
148
+ * @example "45%", "78%", "12%"
149
+ */
150
+ disk_used: string;
151
+
152
+ /**
153
+ * Memory usage in gigabytes
154
+ * Format: "used/total GB" showing current RAM consumption
155
+ * Calculated from system memory statistics
156
+ * Empty string if detection fails
157
+ *
158
+ * @example "12/32GB", "6/16GB", "8/64GB"
159
+ */
160
+ ram_used: string;
161
+
162
+ /**
163
+ * Highest CPU consuming process
164
+ * Format: "percentage processname" of the most resource-intensive process
165
+ * Percentage is rounded to whole number
166
+ * Empty string if unable to determine (non-Linux systems)
167
+ *
168
+ * @example "8% firefox", "15% chrome", "3% systemd", "25% game.exe"
169
+ */
170
+ top_process: string;
171
+
172
+ /**
173
+ * System uptime since last boot
174
+ * Format: "Xd Yh Zm" where X=days, Y=hours, Z=minutes
175
+ * Always present as calculated from system boot time
176
+ *
177
+ * @example "2d 14h 23m", "0d 3h 45m", "15d 2h 1m"
178
+ */
179
+ uptime: string;
180
+
181
+ // =============================================================================
182
+ // HARDWARE STATUS (Linux-specific)
183
+ // =============================================================================
184
+
185
+ /**
186
+ * System temperature reading
187
+ * CPU or system temperature from thermal sensors (Linux only)
188
+ * Format: number followed by "°C"
189
+ * Empty string if no temperature sensors available or non-Linux
190
+ *
191
+ * @example "42°C", "65°C", "38°C"
192
+ */
193
+ temperature: string;
194
+
195
+ /**
196
+ * Battery charge level and charging status
197
+ * Format: "percentage" optionally followed by "+" if charging
198
+ * Only available on battery-powered devices (laptops, handhelds)
199
+ * Empty string if no battery present or detection fails
200
+ *
201
+ * @example
202
+ * - "85%" (discharging)
203
+ * - "73%+" (charging)
204
+ * - "100%" (full)
205
+ */
206
+ battery: string;
207
+
208
+ /**
209
+ * System load averages (Linux only)
210
+ * Format: "1min 5min 15min" showing system load over time periods
211
+ * Values represent average system load, where 1.0 = full utilization
212
+ * Empty string on non-Linux systems
213
+ *
214
+ * @example "0.8 1.2 1.5", "2.1 1.8 1.6", "0.1 0.3 0.4"
215
+ */
216
+ load_average: string;
217
+
218
+ // =============================================================================
219
+ // NETWORK INFORMATION
220
+ // =============================================================================
221
+
222
+ /**
223
+ * Public IP address
224
+ * External internet-facing IPv4 address
225
+ * Obtained from ipinfo.io service
226
+ * Empty string if no internet connection or service unavailable
227
+ *
228
+ * @example "203.0.113.42", "198.51.100.15", "192.0.2.1"
229
+ */
230
+ ip: string;
231
+
232
+ /**
233
+ * Local/private IP address(es)
234
+ * Internal network IP addresses (RFC 1918 ranges)
235
+ * Multiple addresses separated by spaces if available
236
+ * Empty string if no network interfaces active
237
+ *
238
+ * @example
239
+ * - "192.168.1.100"
240
+ * - "10.0.0.50 192.168.1.100" (multiple interfaces)
241
+ * - "172.16.0.10"
242
+ */
243
+ iplocal: string;
244
+
245
+ /**
246
+ * Geographic city location
247
+ * City name based on public IP geolocation
248
+ * Obtained from ipinfo.io service
249
+ * Empty string if no internet connection or location unavailable
250
+ *
251
+ * @example "San Francisco", "New York", "London", "Tokyo"
252
+ */
253
+ city: string;
254
+
255
+ /**
256
+ * Reverse DNS hostname with HTTP prefix
257
+ * Format: "http://hostname" from reverse DNS lookup of public IP
258
+ * Empty string if reverse DNS unavailable or no internet connection
259
+ *
260
+ * @example "http://example.com", "http://host-203-0-113-42.example.net"
261
+ */
262
+ domain: string;
263
+
264
+ /**
265
+ * Internet Service Provider name
266
+ * ISP identification from public IP ownership data
267
+ * AS (Autonomous System) number prefix is automatically removed
268
+ * Empty string if no internet connection or data unavailable
269
+ *
270
+ * @example "Comcast Cable", "Verizon Business", "T-Mobile USA", "Cloudflare Inc"
271
+ */
272
+ isp: string;
273
+
274
+ // =============================================================================
275
+ // SOFTWARE AND DEVELOPMENT TOOLS
276
+ // =============================================================================
277
+
278
+ /**
279
+ * Available package managers and development tools
280
+ * Space-separated list of detected command-line tools
281
+ * Includes package managers, editors, and development utilities
282
+ * Empty string if no recognized tools found
283
+ *
284
+ * @example
285
+ * - "apt npm pip docker nvim yay" (Linux development setup)
286
+ * - "pacman yay flatpak" (Arch-based system)
287
+ * - "npm pip docker hx bun" (Node.js developer setup)
288
+ */
289
+ pacman: string;
290
+
291
+ /**
292
+ * Open network ports with associated services
293
+ * Space-separated list of "port+service" combinations
294
+ * Shows ports that are actively listening for connections
295
+ * Empty string if no open ports detected or non-Linux system
296
+ *
297
+ * @example
298
+ * - "22ssh 80http 443https" (web server with SSH)
299
+ * - "3000node 5432postgres" (development services)
300
+ * - "8080java 9000python" (application servers)
301
+ */
302
+ ports: string;
303
+
304
+ /**
305
+ * Running Docker containers with exposed ports
306
+ * Space-separated list of container names followed by port numbers
307
+ * Only shows currently running containers
308
+ * Empty string if Docker not installed, no containers running, or access denied
309
+ *
310
+ * @example
311
+ * - "web-server 80 db-postgres 5432"
312
+ * - "redis-cache 6379 nginx-proxy 443"
313
+ * - "app-backend 8080"
314
+ */
315
+ containers: string;
316
+
317
+ /**
318
+ * Number of active system services
319
+ * Count of running systemd services (Linux only)
320
+ * Format: "number services"
321
+ * Empty string on non-Linux systems or if systemctl unavailable
322
+ *
323
+ * @example "145 services", "89 services", "203 services"
324
+ */
325
+ services_running: string;
326
+
327
+ // =============================================================================
328
+ // EXTENDED SYSTEM INFORMATION (Linux-specific)
329
+ // =============================================================================
330
+
331
+ /**
332
+ * Available system memory (Linux only)
333
+ * Amount of memory available for new processes
334
+ * Format: "number GB available"
335
+ * Based on MemAvailable from /proc/meminfo
336
+ * Empty string on non-Linux systems
337
+ *
338
+ * @example "18GB available", "4GB available", "32GB available"
339
+ */
340
+ memory_available: string;
341
+
342
+ /**
343
+ * Swap usage statistics (Linux only)
344
+ * Virtual memory usage percentage and size
345
+ * Format: "percentage (size) swap"
346
+ * Empty string on non-Linux systems or if no swap configured
347
+ *
348
+ * @example "2% (512MB) swap", "0% (0MB) swap", "15% (2048MB) swap"
349
+ */
350
+ swap_used: string;
351
+
352
+ /**
353
+ * Number of logged-in users (Linux only)
354
+ * Count of active user sessions
355
+ * Format: "number users"
356
+ * Empty string on non-Linux systems
357
+ *
358
+ * @example "2 users", "1 users", "5 users"
359
+ */
360
+ users_logged_in: string;
361
+
362
+ /**
363
+ * Active network interface names (Linux only)
364
+ * Space-separated list of network interface names with active IPv4 addresses
365
+ * Excludes loopback interface (lo)
366
+ * Empty string on non-Linux systems or no active interfaces
367
+ *
368
+ * @example
369
+ * - "eth0 wlan0" (wired and wireless)
370
+ * - "enp3s0" (single ethernet interface)
371
+ * - "wlp2s0 docker0" (wireless and Docker bridge)
372
+ */
373
+ network_interfaces: string;
374
+
375
+ /**
376
+ * Non-root filesystem mount points with usage (Linux only)
377
+ * Space-separated list of "mountpoint(usage%)"
378
+ * Excludes system mounts (/dev, /proc, /sys) and root (/)
379
+ * Shows up to 3 mount points to prevent excessive output
380
+ * Empty string on non-Linux systems or only root filesystem mounted
381
+ *
382
+ * @example
383
+ * - "/home(85%) /var(23%)"
384
+ * - "/opt(12%) /tmp(5%) /boot(45%)"
385
+ * - "/mnt/data(67%)"
386
+ */
387
+ mount_points: string;
388
+
389
+ /**
390
+ * Display screen resolution (Linux with X11 only)
391
+ * Current display resolution from xrandr
392
+ * Format: "widthxheight"
393
+ * Empty string if no X11 display, non-Linux, or detection fails
394
+ *
395
+ * @example "1920x1080", "2560x1440", "3840x2160", "1280x800"
396
+ */
397
+ screen_resolution: string;
398
+ }
399
+
400
+ /**
401
+ * Options for configuring system info collection and output
402
+ */
403
+ export interface SystemInfoOptions {
404
+ /** Return JSON object instead of formatted output */
405
+ json_output?: boolean;
406
+
407
+ /** Force single-line vs multi-line display mode */
408
+ single_line?: boolean;
409
+
410
+ /** Return data object instead of printing to console (module usage) */
411
+ returnData?: boolean;
412
+ }
413
+
414
+ /**
415
+ * Error object returned when system information collection fails
416
+ */
417
+ export interface SystemInfoError {
418
+ /** Error type identifier */
419
+ error: string;
420
+
421
+ /** Human-readable error message */
422
+ message: string;
423
+
424
+ /** Additional error details if available */
425
+ details?: string;
426
+
427
+ /** Timestamp when error occurred */
428
+ timestamp: string;
429
+ }
430
+
431
+ /**
432
+ * Function type for getting system information as JSON
433
+ * @returns Promise resolving to complete system information object
434
+ */
435
+ export type GetSystemInfoFunction = () => Promise<SystemInfo>;
436
+
437
+ /**
438
+ * Function type for displaying system information with options
439
+ * @param options Configuration options for output format and behavior
440
+ * @returns Promise resolving to SystemInfo object if JSON output requested
441
+ */
442
+ export type DisplaySystemInfoFunction = (options?: SystemInfoOptions) => Promise<SystemInfo | void>;
443
+
444
+ /**
445
+ * Platform-specific field availability matrix
446
+ * Indicates which fields are typically available on each platform
447
+ */
448
+ export interface PlatformAvailability {
449
+ /** Fields available on all platforms */
450
+ universal: Array<keyof SystemInfo>;
451
+
452
+ /** Fields primarily available on Linux */
453
+ linux_specific: Array<keyof SystemInfo>;
454
+
455
+ /** Fields that may be empty on certain platforms */
456
+ conditional: Array<keyof SystemInfo>;
457
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Internal type definitions
3
+ * @module internal-types
4
+ */
5
+
6
+ import type { Cache, CacheEntry } from "../cache/cache";
7
+ import type { IPInfo } from "../utils/network";
8
+
9
+ /**
10
+ * Context object passed to info collection functions
11
+ * @interface InfoContext
12
+ */
13
+ export interface InfoContext {
14
+ /** Cache storage */
15
+ cache: Cache;
16
+ /** IP information from external API */
17
+ ipInfo?: IPInfo;
18
+ }
19
+
20
+ // Re-export cache types for convenience
21
+ export type { Cache, CacheEntry };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Command execution utilities
3
+ * @module command
4
+ */
5
+
6
+ import { execSync } from "child_process";
7
+ import { IS_WINDOWS } from "./platform";
8
+
9
+ /**
10
+ * Executes a shell command safely with timeout
11
+ * @param {string} command - Command to execute
12
+ * @param {object} options - Additional options for execSync
13
+ * @returns {string} Command output or empty string on error
14
+ */
15
+ export function execCommand(command: string, options = {}): string {
16
+ try {
17
+ const cmd = IS_WINDOWS ? `cmd /c ${command}` : command;
18
+ return execSync(cmd, {
19
+ encoding: "utf8",
20
+ timeout: 10000,
21
+ stdio: ["pipe", "pipe", "ignore"],
22
+ ...options,
23
+ })
24
+ .toString()
25
+ .trim();
26
+ } catch (error) {
27
+ return "";
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Checks if a command exists in the system PATH
33
+ * @param {string} command - Command name to check
34
+ * @returns {boolean} True if command exists
35
+ */
36
+ export function commandExists(command: string): boolean {
37
+ try {
38
+ if (IS_WINDOWS) {
39
+ execSync(`where ${command}`, { stdio: "ignore" });
40
+ } else {
41
+ execSync(`which ${command}`, { stdio: "ignore" });
42
+ }
43
+ return true;
44
+ } catch {
45
+ return false;
46
+ }
47
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Network utilities for IP information fetching
3
+ * @module network
4
+ */
5
+
6
+ import https from "https";
7
+ import {
8
+ DEFAULT_IPINFO_TOKEN,
9
+ DEFAULT_NETWORK_TIMEOUT,
10
+ } from "../cache/cache-config";
11
+
12
+ /**
13
+ * IP information from ipinfo.io API
14
+ * @interface IPInfo
15
+ */
16
+ export interface IPInfo {
17
+ /** Public IP address */
18
+ ip?: string;
19
+ /** City location */
20
+ city?: string;
21
+ /** Reverse DNS hostname */
22
+ hostname?: string;
23
+ /** ISP organization string (includes AS number) */
24
+ org?: string;
25
+ }
26
+
27
+ /**
28
+ * Fetches IP geolocation information from ipinfo.io API
29
+ * @param {string} token - IPInfo.io API token
30
+ * @param {number} timeout - Request timeout in milliseconds
31
+ * @returns {Promise<IPInfo>} IP information object or empty object on error
32
+ */
33
+ export async function fetchIPInfo(
34
+ token: string = DEFAULT_IPINFO_TOKEN,
35
+ timeout: number = DEFAULT_NETWORK_TIMEOUT
36
+ ): Promise<IPInfo> {
37
+ return new Promise((resolve) => {
38
+ const url = `https://ipinfo.io/json${token ? `?token=${token}` : ""}`;
39
+
40
+ const req = https.get(url, (res) => {
41
+ let data = "";
42
+ res.on("data", (chunk) => (data += chunk));
43
+ res.on("end", () => {
44
+ try {
45
+ resolve(JSON.parse(data));
46
+ } catch {
47
+ resolve({});
48
+ }
49
+ });
50
+ });
51
+
52
+ req.on("error", () => resolve({}));
53
+ req.setTimeout(timeout, () => {
54
+ req.destroy();
55
+ resolve({});
56
+ });
57
+ });
58
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Platform detection utilities
3
+ * @module platform
4
+ */
5
+
6
+ import os from "os";
7
+
8
+ /**
9
+ * Platform detection constants
10
+ */
11
+ export const IS_WINDOWS = os.platform() === "win32";
12
+ export const IS_MAC = os.platform() === "darwin";
13
+ export const IS_LINUX = os.platform() === "linux";