-
Notifications
You must be signed in to change notification settings - Fork 61
t2897: Remove blanket stderr suppression and fix macOS pgrep incompatibility #2945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,7 +81,7 @@ count_interactive_sessions() { | |
| # the first argument after the binary name. | ||
| # Headless: .opencode run ... | ||
| local opencode_pids="" | ||
| opencode_pids=$(pgrep -f '\.opencode' 2>/dev/null || true) | ||
| opencode_pids=$(pgrep -f '\.opencode' || true) | ||
|
|
||
| if [[ -n "$opencode_pids" ]]; then | ||
| local pid | ||
|
|
@@ -92,7 +92,7 @@ count_interactive_sessions() { | |
| # Linux: /proc/PID/cmdline has null-separated args | ||
| cmdline=$(tr '\0' ' ' <"/proc/${pid}/cmdline" 2>/dev/null || true) | ||
| else | ||
| # macOS fallback: ps -o args= | ||
| # macOS fallback: ps -o args= (2>/dev/null: PID may have exited) | ||
| cmdline=$(ps -o args= -p "$pid" 2>/dev/null || true) | ||
| fi | ||
|
|
||
|
|
@@ -117,7 +117,7 @@ count_interactive_sessions() { | |
| # --- Claude Code sessions --- | ||
| # Interactive claude: the claude binary WITHOUT "-p", "--print", or "run" | ||
| local claude_pids="" | ||
| claude_pids=$(pgrep -x claude 2>/dev/null || true) | ||
| claude_pids=$(pgrep -x claude || true) | ||
|
|
||
| if [[ -n "$claude_pids" ]]; then | ||
| local pid | ||
|
|
@@ -127,6 +127,7 @@ count_interactive_sessions() { | |
| if [[ -r "/proc/${pid}/cmdline" ]]; then | ||
| cmdline=$(tr '\0' ' ' <"/proc/${pid}/cmdline" 2>/dev/null || true) | ||
| else | ||
| # macOS fallback (2>/dev/null: PID may have exited) | ||
| cmdline=$(ps -o args= -p "$pid" 2>/dev/null || true) | ||
| fi | ||
|
|
||
|
|
@@ -139,32 +140,51 @@ count_interactive_sessions() { | |
| fi | ||
|
|
||
| # --- Cursor sessions --- | ||
| # Note: pgrep -c is not available on macOS; use pgrep | wc -l instead | ||
| local cursor_count=0 | ||
| cursor_count=$(pgrep -c -f 'Cursor\.app' 2>/dev/null || true) | ||
| cursor_count=$(pgrep -f 'Cursor\.app' | wc -l || true) | ||
| cursor_count=$((cursor_count + 0)) # normalize whitespace from wc | ||
| count=$((count + cursor_count)) | ||
|
|
||
| # --- Windsurf sessions --- | ||
| local windsurf_count=0 | ||
| windsurf_count=$(pgrep -c -f 'Windsurf' 2>/dev/null || true) | ||
| windsurf_count=$(pgrep -f 'Windsurf' | wc -l || true) | ||
| windsurf_count=$((windsurf_count + 0)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| count=$((count + windsurf_count)) | ||
|
|
||
| # --- Aider sessions --- | ||
| local aider_count=0 | ||
| aider_count=$(pgrep -c -f 'aider' 2>/dev/null || true) | ||
| aider_count=$(pgrep -f 'aider' | wc -l || true) | ||
| aider_count=$((aider_count + 0)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| count=$((count + aider_count)) | ||
|
|
||
| echo "$count" | ||
| return 0 | ||
| } | ||
|
|
||
| # List detected interactive sessions with details. | ||
| # Output format: PID | APP | RSS_MB | UPTIME | DIR | ||
| # Output format: PID | APP | RSS_MB | UPTIME | ||
| list_sessions() { | ||
| local found=0 | ||
|
|
||
| # Helper: print session details for a given PID and app name. | ||
| # Uses 2>/dev/null on ps calls because the PID may have exited | ||
| # between detection and inspection (race condition). | ||
| _print_session_detail() { | ||
| local pid="$1" | ||
| local app_name="$2" | ||
| local rss_mb etime | ||
| rss_mb=$(ps -o rss= -p "$pid" 2>/dev/null || echo "0") | ||
| rss_mb=$((${rss_mb:-0} / 1024)) | ||
| etime=$(ps -o etime= -p "$pid" 2>/dev/null || echo "unknown") | ||
| etime=$(echo "$etime" | tr -d ' ') | ||
| echo " PID ${pid} | ${app_name} | ${rss_mb} MB | uptime: ${etime}" | ||
| return 0 | ||
| } | ||
|
|
||
| # --- OpenCode sessions --- | ||
| local opencode_pids="" | ||
| opencode_pids=$(pgrep -f '\.opencode' 2>/dev/null || true) | ||
| opencode_pids=$(pgrep -f '\.opencode' || true) | ||
|
|
||
| if [[ -n "$opencode_pids" ]]; then | ||
| local pid | ||
|
|
@@ -174,6 +194,7 @@ list_sessions() { | |
| if [[ -r "/proc/${pid}/cmdline" ]]; then | ||
| cmdline=$(tr '\0' ' ' <"/proc/${pid}/cmdline" 2>/dev/null || true) | ||
| else | ||
| # macOS fallback (2>/dev/null: PID may have exited) | ||
| cmdline=$(ps -o args= -p "$pid" 2>/dev/null || true) | ||
| fi | ||
|
|
||
|
|
@@ -188,20 +209,14 @@ list_sessions() { | |
| continue | ||
| fi | ||
|
|
||
| local rss_mb etime | ||
| rss_mb=$(ps -o rss= -p "$pid" 2>/dev/null || echo "0") | ||
| rss_mb=$((${rss_mb:-0} / 1024)) | ||
| etime=$(ps -o etime= -p "$pid" 2>/dev/null || echo "unknown") | ||
| etime=$(echo "$etime" | tr -d ' ') | ||
|
|
||
| echo " PID ${pid} | OpenCode | ${rss_mb} MB | uptime: ${etime}" | ||
| _print_session_detail "$pid" "OpenCode" | ||
| found=$((found + 1)) | ||
| done <<<"$opencode_pids" | ||
| fi | ||
|
|
||
| # --- Claude Code sessions --- | ||
| local claude_pids="" | ||
| claude_pids=$(pgrep -x claude 2>/dev/null || true) | ||
| claude_pids=$(pgrep -x claude || true) | ||
|
|
||
| if [[ -n "$claude_pids" ]]; then | ||
| local pid | ||
|
|
@@ -211,24 +226,58 @@ list_sessions() { | |
| if [[ -r "/proc/${pid}/cmdline" ]]; then | ||
| cmdline=$(tr '\0' ' ' <"/proc/${pid}/cmdline" 2>/dev/null || true) | ||
| else | ||
| # macOS fallback (2>/dev/null: PID may have exited) | ||
| cmdline=$(ps -o args= -p "$pid" 2>/dev/null || true) | ||
| fi | ||
|
|
||
| if echo "$cmdline" | grep -qE 'claude (-p|--print|run) '; then | ||
| continue | ||
| fi | ||
|
|
||
| local rss_mb etime | ||
| rss_mb=$(ps -o rss= -p "$pid" 2>/dev/null || echo "0") | ||
| rss_mb=$((${rss_mb:-0} / 1024)) | ||
| etime=$(ps -o etime= -p "$pid" 2>/dev/null || echo "unknown") | ||
| etime=$(echo "$etime" | tr -d ' ') | ||
|
|
||
| echo " PID ${pid} | Claude Code | ${rss_mb} MB | uptime: ${etime}" | ||
| _print_session_detail "$pid" "Claude Code" | ||
| found=$((found + 1)) | ||
| done <<<"$claude_pids" | ||
| fi | ||
|
|
||
| # --- Cursor sessions --- | ||
| local cursor_pids="" | ||
| cursor_pids=$(pgrep -f 'Cursor\.app' || true) | ||
|
|
||
| if [[ -n "$cursor_pids" ]]; then | ||
| local pid | ||
| while IFS= read -r pid; do | ||
| [[ -z "$pid" ]] && continue | ||
| _print_session_detail "$pid" "Cursor" | ||
| found=$((found + 1)) | ||
| done <<<"$cursor_pids" | ||
| fi | ||
|
|
||
| # --- Windsurf sessions --- | ||
| local windsurf_pids="" | ||
| windsurf_pids=$(pgrep -f 'Windsurf' || true) | ||
|
|
||
| if [[ -n "$windsurf_pids" ]]; then | ||
| local pid | ||
| while IFS= read -r pid; do | ||
| [[ -z "$pid" ]] && continue | ||
| _print_session_detail "$pid" "Windsurf" | ||
| found=$((found + 1)) | ||
| done <<<"$windsurf_pids" | ||
| fi | ||
|
|
||
| # --- Aider sessions --- | ||
| local aider_pids="" | ||
| aider_pids=$(pgrep -f 'aider' || true) | ||
|
|
||
| if [[ -n "$aider_pids" ]]; then | ||
| local pid | ||
| while IFS= read -r pid; do | ||
| [[ -z "$pid" ]] && continue | ||
| _print_session_detail "$pid" "Aider" | ||
| found=$((found + 1)) | ||
| done <<<"$aider_pids" | ||
| fi | ||
|
|
||
| if [[ "$found" -eq 0 ]]; then | ||
| echo " No interactive AI sessions detected" | ||
| fi | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This normalization step is redundant. The subsequent arithmetic expansion
count=$((count + cursor_count))on the next line automatically handles any leading whitespace from thewc -loutput. Removing this line would make the code more concise.