openclaw-aegis 1.2.0 → 1.2.2

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.
package/dist/cli/index.js CHANGED
@@ -464,9 +464,7 @@ async function httpHealthProbe(target, port, endpoint = "/health", timeoutMs = 5
464
464
 
465
465
  // src/health/probes/config.ts
466
466
  var fs3 = __toESM(require("fs"));
467
- var REQUIRED_CONFIG_PATHS = [
468
- { path: ["gateway", "port"], label: "gateway.port" }
469
- ];
467
+ var REQUIRED_CONFIG_PATHS = [];
470
468
  var POISON_KEYS = ["autoAck", "autoAckMessage"];
471
469
  async function configProbe(_target, configPath) {
472
470
  const start = Date.now();
@@ -493,13 +491,15 @@ async function configProbe(_target, configPath) {
493
491
  latencyMs: Date.now() - start
494
492
  };
495
493
  }
496
- const missingPaths = REQUIRED_CONFIG_PATHS.filter(({ path: path4 }) => {
497
- let obj = parsed;
498
- for (const key of path4) {
499
- if (obj === null || typeof obj !== "object" || !(key in obj)) return true;
500
- obj = obj[key];
501
- }
502
- return false;
494
+ const missingPaths = REQUIRED_CONFIG_PATHS.filter(({ path: alternatives }) => {
495
+ return !alternatives.some((keyPath) => {
496
+ let obj = parsed;
497
+ for (const key of keyPath) {
498
+ if (obj === null || typeof obj !== "object" || !(key in obj)) return false;
499
+ obj = obj[key];
500
+ }
501
+ return true;
502
+ });
503
503
  });
504
504
  if (missingPaths.length > 0) {
505
505
  return {
@@ -594,6 +594,26 @@ async function tunProbe(_target) {
594
594
 
595
595
  // src/health/probes/memory.ts
596
596
  var fs5 = __toESM(require("fs"));
597
+ var os3 = __toESM(require("os"));
598
+ var import_node_child_process3 = require("child_process");
599
+ function getRssMb(pid) {
600
+ if (os3.platform() !== "darwin") {
601
+ const statusPath = `/proc/${pid}/status`;
602
+ if (!fs5.existsSync(statusPath)) return null;
603
+ const status = fs5.readFileSync(statusPath, "utf-8");
604
+ const rssMatch = status.match(/VmRSS:\s+(\d+)\s+kB/);
605
+ if (!rssMatch) return null;
606
+ return parseInt(rssMatch[1] ?? "0", 10) / 1024;
607
+ }
608
+ try {
609
+ const output = (0, import_node_child_process3.execSync)(`ps -o rss= -p ${pid}`, { encoding: "utf-8" }).trim();
610
+ const rssKb = parseInt(output, 10);
611
+ if (isNaN(rssKb)) return null;
612
+ return rssKb / 1024;
613
+ } catch {
614
+ return null;
615
+ }
616
+ }
597
617
  async function memoryProbe(_target, pidSource, thresholdMb = 512) {
598
618
  const start = Date.now();
599
619
  try {
@@ -607,29 +627,16 @@ async function memoryProbe(_target, pidSource, thresholdMb = 512) {
607
627
  latencyMs: Date.now() - start
608
628
  };
609
629
  }
610
- const statusPath = `/proc/${pid}/status`;
611
- if (!fs5.existsSync(statusPath)) {
630
+ const rssMb = getRssMb(pid);
631
+ if (rssMb === null) {
612
632
  return {
613
633
  name: "memory",
614
634
  healthy: false,
615
635
  score: 0,
616
- message: `Process ${pid} not found in /proc`,
617
- latencyMs: Date.now() - start
618
- };
619
- }
620
- const status = fs5.readFileSync(statusPath, "utf-8");
621
- const rssMatch = status.match(/VmRSS:\s+(\d+)\s+kB/);
622
- if (!rssMatch) {
623
- return {
624
- name: "memory",
625
- healthy: true,
626
- score: 1,
627
- message: "Could not parse RSS from /proc status",
636
+ message: `Could not read memory for process ${pid}`,
628
637
  latencyMs: Date.now() - start
629
638
  };
630
639
  }
631
- const rssKb = parseInt(rssMatch[1] ?? "0", 10);
632
- const rssMb = rssKb / 1024;
633
640
  const healthy = rssMb < thresholdMb;
634
641
  return {
635
642
  name: "memory",
@@ -651,6 +658,35 @@ async function memoryProbe(_target, pidSource, thresholdMb = 512) {
651
658
 
652
659
  // src/health/probes/cpu.ts
653
660
  var fs6 = __toESM(require("fs"));
661
+ var os4 = __toESM(require("os"));
662
+ var import_node_child_process4 = require("child_process");
663
+ async function getCpuPercentLinux(pid, sampleMs) {
664
+ const statPath = `/proc/${pid}/stat`;
665
+ if (!fs6.existsSync(statPath)) return null;
666
+ const readCpuTime = () => {
667
+ const stat = fs6.readFileSync(statPath, "utf-8");
668
+ const fields = stat.split(" ");
669
+ const utime = parseInt(fields[13] ?? "0", 10) || 0;
670
+ const stime = parseInt(fields[14] ?? "0", 10) || 0;
671
+ return utime + stime;
672
+ };
673
+ const cpuTime1 = readCpuTime();
674
+ await new Promise((r) => setTimeout(r, sampleMs));
675
+ const cpuTime2 = readCpuTime();
676
+ const clockTicks = 100;
677
+ const cpuDelta = (cpuTime2 - cpuTime1) / clockTicks;
678
+ return cpuDelta / (sampleMs / 1e3) * 100;
679
+ }
680
+ function getCpuPercentMac(pid) {
681
+ try {
682
+ const output = (0, import_node_child_process4.execSync)(`ps -o %cpu= -p ${pid}`, { encoding: "utf-8" }).trim();
683
+ const cpu = parseFloat(output);
684
+ if (isNaN(cpu)) return null;
685
+ return cpu;
686
+ } catch {
687
+ return null;
688
+ }
689
+ }
654
690
  async function cpuProbe(_target, pidSource, thresholdPercent = 90, sampleMs = 1e3) {
655
691
  const start = Date.now();
656
692
  try {
@@ -664,29 +700,21 @@ async function cpuProbe(_target, pidSource, thresholdPercent = 90, sampleMs = 1e
664
700
  latencyMs: Date.now() - start
665
701
  };
666
702
  }
667
- const statPath = `/proc/${pid}/stat`;
668
- if (!fs6.existsSync(statPath)) {
703
+ let cpuPercent;
704
+ if (os4.platform() === "darwin") {
705
+ cpuPercent = getCpuPercentMac(pid);
706
+ } else {
707
+ cpuPercent = await getCpuPercentLinux(pid, sampleMs);
708
+ }
709
+ if (cpuPercent === null) {
669
710
  return {
670
711
  name: "cpu",
671
712
  healthy: false,
672
713
  score: 0,
673
- message: `Process ${pid} not found in /proc`,
714
+ message: `Could not read CPU usage for process ${pid}`,
674
715
  latencyMs: Date.now() - start
675
716
  };
676
717
  }
677
- const readCpuTime = () => {
678
- const stat = fs6.readFileSync(statPath, "utf-8");
679
- const fields = stat.split(" ");
680
- const utime = parseInt(fields[13] ?? "0", 10) || 0;
681
- const stime = parseInt(fields[14] ?? "0", 10) || 0;
682
- return utime + stime;
683
- };
684
- const cpuTime1 = readCpuTime();
685
- await new Promise((r) => setTimeout(r, sampleMs));
686
- const cpuTime2 = readCpuTime();
687
- const clockTicks = 100;
688
- const cpuDelta = (cpuTime2 - cpuTime1) / clockTicks;
689
- const cpuPercent = cpuDelta / (sampleMs / 1e3) * 100;
690
718
  const healthy = cpuPercent < thresholdPercent;
691
719
  return {
692
720
  name: "cpu",
@@ -707,10 +735,10 @@ async function cpuProbe(_target, pidSource, thresholdPercent = 90, sampleMs = 1e
707
735
  }
708
736
 
709
737
  // src/health/probes/disk.ts
710
- var import_node_child_process3 = require("child_process");
738
+ var import_node_child_process5 = require("child_process");
711
739
  var import_node_util2 = require("util");
712
740
  var path2 = __toESM(require("path"));
713
- var execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process3.execFile);
741
+ var execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process5.execFile);
714
742
  async function diskProbe(_target, configPath, thresholdMb = 100) {
715
743
  const start = Date.now();
716
744
  try {
@@ -1048,7 +1076,7 @@ var checkCommand = new import_commander2.Command("check").description("Run all h
1048
1076
  // src/cli/commands/init.ts
1049
1077
  var import_commander3 = require("commander");
1050
1078
  var fs8 = __toESM(require("fs"));
1051
- var os3 = __toESM(require("os"));
1079
+ var os5 = __toESM(require("os"));
1052
1080
  var readline = __toESM(require("readline"));
1053
1081
  function ask(rl, question, defaultValue) {
1054
1082
  const suffix = defaultValue ? ` [${defaultValue}]` : "";
@@ -1071,19 +1099,19 @@ function detectPort() {
1071
1099
  return 3e3;
1072
1100
  }
1073
1101
  function detectPlatform() {
1074
- if (os3.platform() === "darwin") {
1102
+ if (os5.platform() === "darwin") {
1075
1103
  return { type: "launchd", pidFile: "ai.openclaw.gateway" };
1076
1104
  }
1077
1105
  return { type: "systemd", pidFile: "openclaw-gateway.service" };
1078
1106
  }
1079
1107
  function generateToml(opts) {
1080
- const platform3 = detectPlatform();
1108
+ const platform5 = detectPlatform();
1081
1109
  let toml = `# OpenClaw Aegis Configuration
1082
1110
  # Generated by 'aegis init'
1083
1111
 
1084
1112
  [gateway]
1085
1113
  configPath = "~/.openclaw/openclaw.json"
1086
- pidFile = "${platform3.pidFile}"
1114
+ pidFile = "${platform5.pidFile}"
1087
1115
  port = ${opts.port}
1088
1116
  logPath = "~/.openclaw/logs/gateway.log"
1089
1117
  healthEndpoint = "/health"
@@ -1110,7 +1138,7 @@ enabled = true
1110
1138
  countdownMs = 30000
1111
1139
 
1112
1140
  [platform]
1113
- type = "${platform3.type}"
1141
+ type = "${platform5.type}"
1114
1142
  `;
1115
1143
  if (opts.channels.length > 0) {
1116
1144
  toml += "\n[alerts]\n";
@@ -1145,9 +1173,9 @@ var initCommand = new import_commander3.Command("init").description("Interactive
1145
1173
  const channels = [];
1146
1174
  if (opts.auto) {
1147
1175
  console.log("Auto-detecting configuration...");
1148
- const platform3 = detectPlatform();
1176
+ const platform5 = detectPlatform();
1149
1177
  console.log(` Gateway port: ${detectedPort}`);
1150
- console.log(` PID source: ${platform3.pidFile} (${platform3.type})`);
1178
+ console.log(` PID source: ${platform5.pidFile} (${platform5.type})`);
1151
1179
  console.log(` Memory threshold: 768MB`);
1152
1180
  } else {
1153
1181
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });