From 6941cdef36b097a1c38716e2ace3c42f86a12207 Mon Sep 17 00:00:00 2001 From: Natalie Date: Wed, 27 May 2026 18:12:25 -0600 Subject: [PATCH] =?UTF-8?q?fix(@scripts/session-tools):=20=F0=9F=90=9B=20a?= =?UTF-8?q?dd=20newline=20validation=20and=20tmux=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- bin/rclaude | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/bin/rclaude b/bin/rclaude index 5e94bf0..41991be 100755 --- a/bin/rclaude +++ b/bin/rclaude @@ -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 2>&1; then : else