diff --git a/packages/mosaic/framework/tools/tmux/agent-send.sh b/packages/mosaic/framework/tools/tmux/agent-send.sh index fcbcc92c..adf9fb23 100755 --- a/packages/mosaic/framework/tools/tmux/agent-send.sh +++ b/packages/mosaic/framework/tools/tmux/agent-send.sh @@ -35,6 +35,9 @@ # # OPTIONS # -L NAME tmux socket name passed to `tmux -L NAME` on the target host +# +# Exit 4: local target session exists on multiple socket servers and no +# -L / MOSAIC_TMUX_SOCKET disambiguated it (B1 stale-twin guard). # -s DST_SESSION target tmux session (or session:window.pane) [required] # -H SSH_TARGET ssh target (user@host) for a remote pane; omit for local # -n DST_HOST hostname to show in the preamble for the target. @@ -175,15 +178,16 @@ if [ -z "$SOCKET_NAME" ] && [ -z "$SSH_TARGET" ]; then for sf in "$socket_dir"/*; do [ -S "$sf" ] || continue sname="${sf##*/}" - tmux -L "$sname" has-session -t "$DST_SESSION" 2>/dev/null && hits="$hits $sname" + tmux -L "$sname" has-session -t "$DST_SESSION" 2>/dev/null && hits="$hits$sname"$'\n' done - hit_count=$(printf '%s' "$hits" | wc -w) + hit_count=$(printf '%s' "$hits" | grep -c . || true) if [ "$hit_count" -gt 1 ]; then - echo "agent-send.sh: REFUSING - session '$DST_SESSION' exists on multiple sockets:$hits" >&2 + echo "agent-send.sh: REFUSING - session '$DST_SESSION' exists on multiple sockets:" >&2 + printf ' %s\n' $hits >&2 echo " Pass -L explicitly (or export MOSAIC_TMUX_SOCKET to disambiguate)." >&2 exit 4 elif [ "$hit_count" -eq 1 ]; then - SOCKET_NAME="${hits# }" + SOCKET_NAME="$(printf '%s' "$hits")" fi fi