From 70c2d06c4e792d0c5e4c896e70765ddf2a5affa7 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 17 Jan 2026 18:35:37 -0800 Subject: feat: add show-and-wait.sh helper, fix race condition - New show-and-wait.sh combines write + wait into one command - Uses polling instead of tail -f (which hangs on macOS) - Docs updated: start watcher BEFORE writing screen to avoid race - Reduces terminal noise by consolidating operations --- lib/brainstorm-server/show-and-wait.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 lib/brainstorm-server/show-and-wait.sh (limited to 'lib') diff --git a/lib/brainstorm-server/show-and-wait.sh b/lib/brainstorm-server/show-and-wait.sh new file mode 100755 index 0000000..02519f0 --- /dev/null +++ b/lib/brainstorm-server/show-and-wait.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# Write HTML to screen and wait for user feedback +# Usage: show-and-wait.sh < html_content +# +# Reads HTML from stdin, writes to screen_file, waits for feedback. +# Outputs the feedback JSON when user sends from browser. + +SCREEN_DIR="${1:?Usage: show-and-wait.sh }" +SCREEN_FILE="${SCREEN_DIR}/screen.html" +LOG_FILE="${SCREEN_DIR}/.server.log" + +if [[ ! -d "$SCREEN_DIR" ]]; then + echo '{"error": "Screen directory not found"}' >&2 + exit 1 +fi + +# Write HTML from stdin to screen file +cat > "$SCREEN_FILE" + +# Record current position in log file +LOG_POS=$(wc -l < "$LOG_FILE" 2>/dev/null || echo 0) + +# Poll for new lines containing the event +while true; do + # Check for new matching lines since our starting position + RESULT=$(tail -n +$((LOG_POS + 1)) "$LOG_FILE" 2>/dev/null | grep -m 1 "send-to-claude") + if [[ -n "$RESULT" ]]; then + echo "$RESULT" + exit 0 + fi + sleep 0.2 +done -- cgit