framework tools/tmux: B1 round 4 — whitespace-safe hit counting; rc 4 documented
ci/woodpecker/pr/ci Pipeline was canceled

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.
This commit is contained in:
2026-08-28 20:49:24 -05:00
parent 1177428704
commit 4d95c9cf82
@@ -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 <socket> 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