From 4d95c9cf82770e44fe53fed606b7816692369ae3 Mon Sep 17 00:00:00 2001 From: marcie Date: Fri, 28 Aug 2026 20:49:24 -0500 Subject: [PATCH] =?UTF-8?q?framework=20tools/tmux:=20B1=20round=204=20?= =?UTF-8?q?=E2=80=94=20whitespace-safe=20hit=20counting;=20rc=204=20docume?= =?UTF-8?q?nted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hits newline-delimited and counted by lines (socket names with spaces no longer break the count; codex should-fix); ambiguity listing prints one socket per line; exit 4 added to the public contract in the header. --- packages/mosaic/framework/tools/tmux/agent-send.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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