Skip to content

Add server running status to vite-port-demo info hook#33

Merged
agarcher merged 1 commit intomainfrom
vite-demo-server-status
Jan 16, 2026
Merged

Add server running status to vite-port-demo info hook#33
agarcher merged 1 commit intomainfrom
vite-demo-server-status

Conversation

@agarcher
Copy link
Owner

@agarcher agarcher commented Jan 16, 2026

Summary

  • Show whether the dev server is running or stopped next to the URL in the info hook
  • Uses lsof to check if the port is listening
  • Displays status as "(running)" in bold or "(stopped)"

Test plan

  • Run wt info on a worktree with the vite server running - should show "(running)" in bold
  • Run wt info on a worktree with the vite server stopped - should show "(stopped)"

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Port status indicator now displays alongside URLs, showing whether each port is running or stopped.
    • Enhanced text formatting with bold styling for improved readability of status information.

✏️ Tip: You can customize this high-level summary in your review settings.

Show whether the dev server is running or stopped next to the URL
using lsof to check if the port is listening.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 16, 2026

📝 Walkthrough

Walkthrough

This change enhances the show-info.sh script by adding port status checking functionality. It introduces ANSI styling variables, a helper function to verify if a port is listening via lsof, and a formatter to display the port status alongside the localhost URL.

Changes

Cohort / File(s) Summary
Shell script port status enhancement
examples/vite-port-demo/scripts/show-info.sh
Added ANSI styling (BOLD, RESET) variables. Introduced is_port_running(port) function to check port availability using lsof. Added format_status(port) helper function returning formatted status string ("(running)" in bold or "(stopped)"). Updated URL output to display port status.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A port now shows its beating heart,
With bold "running" when it plays its part,
Or "stopped" when quiet, at its rest,
This script's enhancement—simply the best! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding server running status display to the vite-port-demo info hook script.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@examples/vite-port-demo/scripts/show-info.sh`:
- Around line 16-25: The is_port_running check currently uses lsof -i ":$1"
which matches non-listening endpoints and hides lsof absence; update
is_port_running to first verify lsof exists (command -v lsof) and if missing
either error out or fall back to ss, and when using lsof restrict to listening
TCP sockets with flags like -iTCP -sTCP:LISTEN -P -n to avoid name-resolution
and false positives; update format_status to rely on the corrected
is_port_running behavior.
🧹 Nitpick comments (1)
examples/vite-port-demo/scripts/show-info.sh (1)

12-15: Emit ANSI only on TTY and prefer printf over echo -e.

echo -e isn’t portable, and raw ANSI escapes are noisy when output is piped or logged. Consider TTY-gating the ANSI codes and using printf.

♻️ Suggested update
-# ANSI codes for bold
-BOLD='\033[1m'
-RESET='\033[0m'
+# ANSI codes for bold (only when stdout is a TTY)
+if [ -t 1 ]; then
+  BOLD=$'\033[1m'
+  RESET=$'\033[0m'
+else
+  BOLD=''
+  RESET=''
+fi
@@
-        echo -e "(${BOLD}running${RESET})"
+        printf '(%srunning%s)' "$BOLD" "$RESET"
@@
-        echo "(stopped)"
+        printf '(stopped)'
@@
-echo -e "URL: http://localhost:$PORT $(format_status "$PORT")"
+printf 'URL: http://localhost:%s %s\n' "$PORT" "$(format_status "$PORT")"

Also applies to: 21-32

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5267688 and de27330.

📒 Files selected for processing (1)
  • examples/vite-port-demo/scripts/show-info.sh
🧰 Additional context used
🧬 Code graph analysis (1)
examples/vite-port-demo/scripts/show-info.sh (1)
examples/vite-port-demo/vite.config.js (1)
  • env (3-10)

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +16 to +25
# Check if a port is listening
is_port_running() {
lsof -i ":$1" >/dev/null 2>&1
}

# Format status with optional bold
format_status() {
local port=$1
if is_port_running "$port"; then
echo -e "(${BOLD}running${RESET})"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n examples/vite-port-demo/scripts/show-info.sh | head -40

Repository: agarcher/wt

Length of output: 1008


🏁 Script executed:

# Verify lsof behavior with different flags
# Test what flags work for filtering LISTEN sockets
man lsof 2>/dev/null | grep -A 5 "LISTEN" || echo "Man pages not available, will use online documentation"

Repository: agarcher/wt

Length of output: 109


🌐 Web query:

lsof -i flag behavior matching outbound connections vs listening ports

💡 Result:

Short answer

  • lsof -i selects Internet (network) sockets; -i :port or -i @host:port matches sockets whose local OR remote address uses that port/address. [1][2]
  • That means lsof -i :34002 will show both a process LISTENing on 34002 and any established/outbound socket whose local (ephemeral) or remote endpoint is 34002. [1][3]
  • To restrict to listening sockets use protocol/state filters: lsof -iTCP -sTCP:LISTEN (or lsof -i -sTCP:LISTEN). To restrict to TCP-only use -iTCP; to see only established use -sTCP:ESTABLISHED. [3][4]

Why outbound connections appear

  • An outbound TCP connection has a local ephemeral port. lsof reports that socket with its local:remote pair, so the ephemeral local port can appear as “:34002” and will prevent another process from binding that same port while the socket is in use. This is normal OS behavior. [5]

Useful examples

  • Show all Internet sockets: sudo lsof -i. [1]
  • Show sockets using port 80 (local or remote): sudo lsof -i :80. [1][6]
  • Show only TCP listeners: sudo lsof -iTCP -sTCP:LISTEN -n -P. [3][7]
  • Show only established TCP connections: sudo lsof -iTCP -sTCP:ESTABLISHED -n -P. [3]

Sources
[1] lsof manual/FAQ and LinuxCommandLibrary.
[2] lsof options doc (readthedocs).
[3] lsof manpage (man7).
[4] lsof manpage examples for -sTCP:LISTEN.
[5] ServerFault Q&A explaining outbound ephemeral ports blocking binds.
[6] lsof tutorial / examples.
[7] Practical examples from lsof docs.


🌐 Web query:

lsof -sTCP:LISTEN filter documentation

💡 Result:

Summary: -s selects socket state filters. Syntax: -sPROTO:state-list (protocol name, colon, comma/space-separated states). Use with -i to restrict to network files. You can negate states with ^. Example: lsof -iTCP -sTCP:LISTEN lists only TCP sockets in LISTEN state; lsof -iUDP -sUDP:^Idle lists UDP sockets excluding Idle. State names vary by OS. [1][2]

Sources:

  • lsof manpage (state filter syntax, need for -i, negation, examples). [1]
  • lsof usage examples (common examples including -sTCP:LISTEN). [2]

Tighten lsof check and handle missing dependency.

lsof -i ":$1" matches both listening sockets and outbound connections using that port as a local or remote endpoint, producing false "running" statuses. Also, if lsof is not installed, the check silently fails (stderr suppressed) and the script incorrectly reports "stopped." Restrict to listening sockets and verify lsof availability.

🔧 Suggested update
 is_port_running() {
-    lsof -i ":$1" >/dev/null 2>&1
+    command -v lsof >/dev/null 2>&1 || return 1
+    lsof -iTCP:"$1" -sTCP:LISTEN -P -n >/dev/null 2>&1
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Check if a port is listening
is_port_running() {
lsof -i ":$1" >/dev/null 2>&1
}
# Format status with optional bold
format_status() {
local port=$1
if is_port_running "$port"; then
echo -e "(${BOLD}running${RESET})"
# Check if a port is listening
is_port_running() {
command -v lsof >/dev/null 2>&1 || return 1
lsof -iTCP:"$1" -sTCP:LISTEN -P -n >/dev/null 2>&1
}
🤖 Prompt for AI Agents
In `@examples/vite-port-demo/scripts/show-info.sh` around lines 16 - 25, The
is_port_running check currently uses lsof -i ":$1" which matches non-listening
endpoints and hides lsof absence; update is_port_running to first verify lsof
exists (command -v lsof) and if missing either error out or fall back to ss, and
when using lsof restrict to listening TCP sockets with flags like -iTCP
-sTCP:LISTEN -P -n to avoid name-resolution and false positives; update
format_status to rely on the corrected is_port_running behavior.

@agarcher agarcher merged commit fb9ac4b into main Jan 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant