diff options
| author | Jesse Vincent <jesse@fsck.com> | 2026-01-17 18:35:37 -0800 |
|---|---|---|
| committer | Jesse Vincent <jesse@fsck.com> | 2026-01-17 18:35:37 -0800 |
| commit | 70c2d06c4e792d0c5e4c896e70765ddf2a5affa7 (patch) | |
| tree | 1f39257de34d3a1622feef265aa986cd7a5c7ae4 /lib | |
| parent | b98afbd74fc346b3fa293d9e638716d3823dc1c1 (diff) | |
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
Diffstat (limited to 'lib')
| -rwxr-xr-x | lib/brainstorm-server/show-and-wait.sh | 32 |
1 files changed, 32 insertions, 0 deletions
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 <screen_dir> < 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_dir>}" +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 |
