Reliable loop messaging: msg-loop.sh + hardened ping_session (retry submit)
tmux `send-keys -l <long msg>` often leaves the text UNSENT in the input box (the immediate Enter is swallowed while the TUI ingests the paste). Both now type the message then retry Enter/C-m until the leading text is no longer in the input box (= submitted) or a bounded loop gives up. - msg-loop.sh: standalone reliable messenger for orchestrator use. - launch.sh ping_session: same retry-submit (loads on next watchdog restart). Live-tested: delivered first try. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
33
cc-ci-plan/msg-loop.sh
Executable file
33
cc-ci-plan/msg-loop.sh
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
# msg-loop.sh — reliably send a message to a loop's tmux session AND submit it.
|
||||
# -------------------------------------------------------------------------
|
||||
# `tmux send-keys -l <long message>` frequently leaves the text sitting UNSENT in
|
||||
# the input box (the immediate Enter is swallowed while the TUI is still ingesting
|
||||
# the paste). This types the message, then retries Enter/C-m until the text is no
|
||||
# longer in the input box (= it was submitted), or gives up after a bounded loop.
|
||||
#
|
||||
# msg-loop.sh <tmux-session> <message...>
|
||||
# exit 0 = delivered; 2 = could not confirm submit; 1 = bad args / no session.
|
||||
set -uo pipefail
|
||||
|
||||
S="${1:?usage: msg-loop.sh <session> <message...>}"; shift
|
||||
MSG="$*"
|
||||
[ -n "$MSG" ] || { echo "msg-loop: empty message"; exit 1; }
|
||||
tmux has-session -t "$S" 2>/dev/null || { echo "msg-loop: no tmux session '$S'"; exit 1; }
|
||||
|
||||
PREFIX="$(printf '%s' "$MSG" | head -c 28)"
|
||||
# Submitted ⇔ the message's leading text is no longer in the input box (bottom of the pane).
|
||||
in_input_box() { tmux capture-pane -pt "$S" 2>/dev/null | tail -4 | grep -qF -- "$PREFIX"; }
|
||||
|
||||
tmux send-keys -t "$S" -l -- "$MSG" 2>/dev/null || { echo "msg-loop: send-keys failed"; exit 1; }
|
||||
sleep 0.8
|
||||
for _ in 1 2 3 4 5 6 7 8 9 10; do
|
||||
tmux send-keys -t "$S" Enter 2>/dev/null || true
|
||||
sleep 1.2
|
||||
in_input_box || { echo "$S: delivered ✔"; exit 0; }
|
||||
tmux send-keys -t "$S" C-m 2>/dev/null || true # some TUI states take C-m not Enter
|
||||
sleep 0.8
|
||||
in_input_box || { echo "$S: delivered ✔"; exit 0; }
|
||||
done
|
||||
echo "$S: WARNING — could not confirm submit; message may remain in the input box"
|
||||
exit 2
|
||||
Reference in New Issue
Block a user