fix(@scripts/session-tools): 🐛 add newline validation and tmux cleanup

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Natalie 2026-05-27 18:12:25 -06:00
parent a74af5e613
commit 6941cdef36

View file

@ -881,10 +881,13 @@ EOF
/*) ;;
*) echo "rclaude send --slash: text must start with '/' (got: $_text)" >&2; exit 2 ;;
esac
case $_text in
*"$(printf '\n')"*)
echo "rclaude send --slash: text must not contain newlines" >&2; exit 2 ;;
esac
# POSIX-portable newline check: command substitution strips trailing
# newlines, so a glob with $(printf '\n') won't work. Strip with tr
# and compare lengths instead.
_text_no_nl=$(printf '%s' "$_text" | tr -d '\n')
if [ "$_text_no_nl" != "$_text" ]; then
echo "rclaude send --slash: text must not contain newlines" >&2; exit 2
fi
fi
# Gather candidate rows across all hosts, then filter.
@ -911,11 +914,18 @@ EOF
# `while` runs in a subshell under POSIX sh and would lose mutations).
_rowfile=$(mktemp /tmp/rclaude-send.XXXXXX 2>/dev/null || echo /tmp/rclaude-send.$$)
printf '%s\n' "$_rows" > "$_rowfile"
# Every send pre-clears the target's input line. tmux send-keys -l types
# into whatever buffer is focused — if Claude is mid-turn or has queued
# input, the payload would otherwise concatenate with stray text. C-a
# moves to start of line, C-k kills to end. This is mandatory for
# --slash (slash commands fire only when they're the entire message)
# and harmless for prose (the buffer is normally empty between turns).
while IFS=$(printf '\t') read -r _host _kind _sess _detail; do
[ -z "$_sess" ] && continue
_total=$((_total + 1))
if is_local "$_host"; then
if tmux send-keys -t "$_sess" -l -- "$_text" 2>/dev/null \
if tmux send-keys -t "$_sess" C-a C-k 2>/dev/null \
&& tmux send-keys -t "$_sess" -l -- "$_text" 2>/dev/null \
&& tmux send-keys -t "$_sess" Enter 2>/dev/null; then
:
else
@ -925,7 +935,7 @@ EOF
else
_q_sess=$(sh_quote "$_sess")
if ssh -o BatchMode=yes -o ConnectTimeout=3 "$_host" \
"tmux send-keys -t $_q_sess -l -- $_quoted_text && tmux send-keys -t $_q_sess Enter" \
"tmux send-keys -t $_q_sess C-a C-k && tmux send-keys -t $_q_sess -l -- $_quoted_text && tmux send-keys -t $_q_sess Enter" \
</dev/null >/dev/null 2>&1; then
:
else