pyre-cli 9.4.0 → 9.5.0

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,74 @@
1
+ import {
2
+ formatBytes
3
+ } from "./chunk-MOAEGMFP.js";
4
+ import "./chunk-SG26Y3WF.js";
5
+ import {
6
+ collectAll
7
+ } from "./chunk-PV4MXTAJ.js";
8
+ import "./chunk-FH5WDJBF.js";
9
+
10
+ // src/checkCmd.ts
11
+ import chalk from "chalk";
12
+ async function runCheckCommand(opts = {}) {
13
+ const data = await collectAll({ detailed: opts.detailed });
14
+ const cpuUsage = data.cpu.usage;
15
+ const tempC = data.cpu.temperature ?? data.thermal.temperatures?.cpu_die;
16
+ const memUsage = data.memory.usagePercent;
17
+ const disk = data.disk.mainVolume;
18
+ const sentences = [];
19
+ let isWarning = false;
20
+ const tempStr = tempC !== void 0 ? `${Math.round(tempC)}\xB0C` : null;
21
+ const cpuAlertThreshold = opts.cpuAlertPct ?? 90;
22
+ const tempAlertThreshold = opts.tempAlertC ?? 95;
23
+ if (cpuUsage >= cpuAlertThreshold || tempC !== void 0 && tempC >= tempAlertThreshold) {
24
+ isWarning = true;
25
+ if (tempStr) {
26
+ sentences.push(`CPU running hot at ${tempStr}, ${Math.round(cpuUsage)}% used.`);
27
+ } else {
28
+ sentences.push(`CPU load is high at ${Math.round(cpuUsage)}% used.`);
29
+ }
30
+ } else {
31
+ if (tempStr) {
32
+ sentences.push(`CPU running cool at ${tempStr}, ${Math.round(cpuUsage)}% used.`);
33
+ } else {
34
+ sentences.push(`CPU running normally at ${Math.round(cpuUsage)}% used.`);
35
+ }
36
+ }
37
+ if (data.battery) {
38
+ if (data.battery.friendlySummary) {
39
+ if (data.battery.friendlySummary.toLowerCase().includes("service") || data.battery.friendlySummary.toLowerCase().includes("reduced")) {
40
+ isWarning = true;
41
+ }
42
+ sentences.push(data.battery.friendlySummary);
43
+ } else {
44
+ let healthStr = "health good";
45
+ if (data.battery.health.toLowerCase().includes("service") || data.battery.health.toLowerCase().includes("check")) {
46
+ healthStr = "service recommended";
47
+ isWarning = true;
48
+ }
49
+ sentences.push(`Battery at ${data.battery.level}%, ${healthStr}.`);
50
+ }
51
+ } else {
52
+ sentences.push(`Memory at ${Math.round(memUsage)}% used.`);
53
+ }
54
+ if (disk) {
55
+ const freeBytes = disk.free;
56
+ const freeStr = formatBytes(freeBytes);
57
+ sentences.push(`${freeStr} free on ${disk.mount}.`);
58
+ if (disk.usePercent >= 90) {
59
+ isWarning = true;
60
+ }
61
+ }
62
+ const summaryText = sentences.join(" ");
63
+ if (isWarning) {
64
+ console.log(chalk.yellow(`\u26A0 ${summaryText}`));
65
+ } else {
66
+ console.log(chalk.green(`\u2714 ${summaryText}`));
67
+ }
68
+ if (opts.exitCode && isWarning) {
69
+ process.exit(1);
70
+ }
71
+ }
72
+ export {
73
+ runCheckCommand
74
+ };