pyre-cli 8.2.0 → 9.1.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.
@@ -13,7 +13,7 @@ function runAnomaliesDigest(opts = {}) {
13
13
  console.log(chalk.dim(" Enable background logging with `pyre --log` to record history.\n"));
14
14
  return;
15
15
  }
16
- const files = fs.readdirSync(dir).filter((f) => f.startsWith("pyre-log-") && f.endsWith(".csv"));
16
+ const files = fs.readdirSync(dir).filter((f) => f.startsWith("pyre-") && f.endsWith(".csv"));
17
17
  if (files.length === 0) {
18
18
  console.log(chalk.yellow(` No CSV logs found for range '${sinceStr}' in ${dir}.`));
19
19
  console.log(chalk.dim(" Enable background logging with `pyre --log` to record history.\n"));
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  run
3
- } from "./chunk-GLH7EKAX.js";
3
+ } from "./chunk-FH5WDJBF.js";
4
4
 
5
5
  // src/brewHealth.ts
6
6
  import chalk from "chalk";
@@ -2,7 +2,7 @@
2
2
  import { exec } from "child_process";
3
3
  import { promisify } from "util";
4
4
  var execAsync = promisify(exec);
5
- async function run(cmd, fallback = "", timeout = 5e3) {
5
+ async function run(cmd, fallback = "", timeout = 3e3) {
6
6
  try {
7
7
  return (await execAsync(cmd, { encoding: "utf8", timeout })).stdout.trim();
8
8
  } catch {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  run
3
- } from "./chunk-GLH7EKAX.js";
3
+ } from "./chunk-FH5WDJBF.js";
4
4
 
5
5
  // src/monitors/collectors.ts
6
6
  import chalk from "chalk";
@@ -15,7 +15,8 @@ async function getSmcMetrics() {
15
15
  try {
16
16
  const pm = (await run(
17
17
  "sudo -n powermetrics --samplers smc,cpu_power -n 1 --format text 2>/dev/null",
18
- ""
18
+ "",
19
+ 2e3
19
20
  )).trim();
20
21
  if (pm) {
21
22
  const cpuTemp = pm.match(/CPU die temperature:\s*([\d.]+)/i);
@@ -71,13 +72,9 @@ async function getSmcMetrics() {
71
72
  }
72
73
  }
73
74
  if (result.temps["cpu_die"] === void 0) {
74
- let loadUsage = 0;
75
- try {
76
- const top = await run("top -l 1 -n 0 2>/dev/null", "");
77
- const m = top.match(/CPU usage:\s*[\d.]+\%\s*user,\s*[\d.]+\%\s*sys,\s*([\d.]+)\%\s*idle/);
78
- if (m) loadUsage = Math.max(0, 100 - parseFloat(m[1]));
79
- } catch {
80
- }
75
+ const loadAvg = (await import("os")).loadavg();
76
+ const ncpus = (await import("os")).cpus().length || 1;
77
+ const loadUsage = Math.min(100, loadAvg[0] / ncpus * 100);
81
78
  const estCpu = Math.round((38 + loadUsage * 0.42) * 10) / 10;
82
79
  result.temps["cpu_die"] = estCpu;
83
80
  if (result.temps["gpu_die"] === void 0) {
@@ -98,6 +95,7 @@ function parseSuffix(s) {
98
95
  var SP_TTL_MS = 1e4;
99
96
  var NETSTAT_TTL_MS = 1e3;
100
97
  var prevCpuTimes = null;
98
+ var prevCpuTotal = { total: 0, idle: 0, ts: 0 };
101
99
  var ROUTE_TTL_MS = 5e3;
102
100
  var SYSCTL_TTL_MS = 6e4;
103
101
  var spGpuCache = null;
@@ -239,7 +237,7 @@ async function collectGpu(detailed) {
239
237
  if (spGpuCache && now - spGpuCache.ts < SP_TTL_MS) {
240
238
  spRaw = spGpuCache.raw;
241
239
  } else {
242
- spRaw = (await run("system_profiler SPDisplaysDataType 2>/dev/null")).trim();
240
+ spRaw = (await run("system_profiler SPDisplaysDataType 2>/dev/null", "", 3e3)).trim();
243
241
  spGpuCache = { raw: spRaw, ts: now };
244
242
  }
245
243
  let model = "Unknown";
@@ -374,14 +372,32 @@ async function collectCpu() {
374
372
  } catch {
375
373
  }
376
374
  }
375
+ if (frequency === 0) {
376
+ try {
377
+ const cpus = os.cpus();
378
+ if (cpus && cpus.length > 0 && cpus[0].speed) {
379
+ frequency = cpus[0].speed;
380
+ }
381
+ } catch {
382
+ }
383
+ }
377
384
  let usage = 0;
378
385
  try {
379
- const top = (await run("top -l 1 -n 0")).trim();
380
- const cpuLine = top.match(/CPU usage:\s*[\d.]+%\s*user,\s*[\d.]+%\s*sys,\s*([\d.]+)%\s*idle/);
381
- if (cpuLine) {
382
- const idle = parseFloat(cpuLine[1]);
383
- usage = Math.round(100 - idle);
386
+ const cpus = os.cpus();
387
+ let totalNow = 0;
388
+ let idleNow = 0;
389
+ for (const cpu of cpus) {
390
+ totalNow += cpu.times.user + cpu.times.nice + cpu.times.sys + cpu.times.idle + cpu.times.irq;
391
+ idleNow += cpu.times.idle;
392
+ }
393
+ if (prevCpuTotal.ts > 0) {
394
+ const totalDelta = totalNow - prevCpuTotal.total;
395
+ const idleDelta = idleNow - prevCpuTotal.idle;
396
+ if (totalDelta > 0) {
397
+ usage = Math.round((totalDelta - idleDelta) / totalDelta * 100);
398
+ }
384
399
  }
400
+ prevCpuTotal = { total: totalNow, idle: idleNow, ts: Date.now() };
385
401
  } catch {
386
402
  }
387
403
  const loadAvgStr = (await run("sysctl -n vm.loadavg", "0.00 0.00 0.00")).trim();
@@ -485,7 +501,7 @@ async function getDiskIoRates() {
485
501
  return { readBytesSec: cachedDiskIo.readBytesSec, writeBytesSec: cachedDiskIo.writeBytesSec };
486
502
  }
487
503
  try {
488
- const raw = (await run("iostat -d -c 2 1 2", "")).trim();
504
+ const raw = (await run("iostat -d -c 2 1 2", "", 3e3)).trim();
489
505
  const blocks = raw.split(/\n\s*\n/).filter(Boolean);
490
506
  const targetBlock = blocks.length > 1 ? blocks[1] : blocks[0];
491
507
  if (targetBlock) {
@@ -547,7 +563,7 @@ async function collectBattery() {
547
563
  if (spBatteryCache && now - spBatteryCache.ts < SP_TTL_MS) {
548
564
  battInfo = spBatteryCache.raw;
549
565
  } else {
550
- battInfo = (await run("system_profiler SPPowerDataType 2>/dev/null")).trim();
566
+ battInfo = (await run("system_profiler SPPowerDataType 2>/dev/null", "", 3e3)).trim();
551
567
  spBatteryCache = { raw: battInfo, ts: now };
552
568
  }
553
569
  const cycleMatch = battInfo.match(/Cycle Count:\s+(\d+)/);
@@ -723,7 +739,7 @@ async function collectPackets() {
723
739
  }
724
740
  let connections = 0;
725
741
  try {
726
- const tcpConns = (await run("netstat -an | grep ESTABLISHED | wc -l", "0")).trim();
742
+ const tcpConns = (await run("netstat -an | grep ESTABLISHED | wc -l", "0", 2e3)).trim();
727
743
  connections = parseInt(tcpConns) || 0;
728
744
  } catch {
729
745
  connections = 0;
@@ -731,7 +747,7 @@ async function collectPackets() {
731
747
  let topProcesses = [];
732
748
  let allProcesses = [];
733
749
  try {
734
- const lsof = (await run("lsof -i -n -P 2>/dev/null | tail -n +2 | awk '{print $1, $2}' | sort | uniq -c | sort -rn", "")).trim();
750
+ const lsof = (await run("lsof -i -n -P 2>/dev/null | tail -n +2 | awk '{print $1, $2}' | sort | uniq -c | sort -rn", "", 2e3)).trim();
735
751
  const lsofLines = lsof.split("\n");
736
752
  topProcesses = lsofLines.map((line) => {
737
753
  const parts = line.trim().split(/\s+/);
@@ -13,8 +13,8 @@ import {
13
13
  collectThermal,
14
14
  getDisplayInfo,
15
15
  getTimeMachineStatus
16
- } from "./chunk-KBKXU2ZV.js";
17
- import "./chunk-GLH7EKAX.js";
16
+ } from "./chunk-QOLZ7T32.js";
17
+ import "./chunk-FH5WDJBF.js";
18
18
  export {
19
19
  collectAll,
20
20
  collectBattery,
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-RVGKEJXT.js";
5
5
  import {
6
6
  run
7
- } from "./chunk-GLH7EKAX.js";
7
+ } from "./chunk-FH5WDJBF.js";
8
8
 
9
9
  // src/doctor.ts
10
10
  import chalk from "chalk";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  run
3
- } from "./chunk-GLH7EKAX.js";
3
+ } from "./chunk-FH5WDJBF.js";
4
4
 
5
5
  // src/extensions.ts
6
6
  import chalk from "chalk";