From cf1c1c9fd21525fe630e00416e1cc9056db2be59 Mon Sep 17 00:00:00 2001 From: bbsngg Date: Fri, 27 Mar 2026 11:23:47 -0400 Subject: [PATCH] fix: use ps instead of pgrep for macOS process detection macOS pgrep -af only outputs PIDs without command lines, causing session discovery to fail. Replace with ps -eo pid,args which works on both macOS and Linux, with pgrep as fallback. Fixes #1 Co-Authored-By: Claude Opus 4.6 (1M context) --- clawchain/host_monitor.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/clawchain/host_monitor.py b/clawchain/host_monitor.py index 5e95de2..a5cba64 100644 --- a/clawchain/host_monitor.py +++ b/clawchain/host_monitor.py @@ -1068,15 +1068,25 @@ def _scan_processes_via_tasklist() -> list[str] | None: def _scan_processes_via_pgrep() -> list[str]: if os.name == "nt": return [] + # On macOS, pgrep -af does not print the full command line (only PIDs). + # Use "ps -eo pid,args" instead, which works on both macOS and Linux. try: probe = subprocess.run( - ["pgrep", "-af", "."], + ["ps", "-eo", "pid,args"], capture_output=True, text=True, check=False, ) except OSError: - return [] + try: + probe = subprocess.run( + ["pgrep", "-af", "."], + capture_output=True, + text=True, + check=False, + ) + except OSError: + return [] if probe.returncode not in (0, 1): return [] return [line.strip() for line in probe.stdout.splitlines() if line.strip()]