wait-for-feedback.sh 739 B

123456789101112131415161718192021222324252627
  1. #!/bin/bash
  2. # Wait for user feedback from the brainstorm browser
  3. # Usage: wait-for-feedback.sh <screen_dir>
  4. #
  5. # Blocks until user sends feedback, then outputs the JSON.
  6. # Write HTML to screen_file BEFORE calling this.
  7. SCREEN_DIR="${1:?Usage: wait-for-feedback.sh <screen_dir>}"
  8. LOG_FILE="${SCREEN_DIR}/.server.log"
  9. if [[ ! -d "$SCREEN_DIR" ]]; then
  10. echo '{"error": "Screen directory not found"}' >&2
  11. exit 1
  12. fi
  13. # Record current position in log file
  14. LOG_POS=$(wc -l < "$LOG_FILE" 2>/dev/null || echo 0)
  15. # Poll for new lines containing the event
  16. while true; do
  17. RESULT=$(tail -n +$((LOG_POS + 1)) "$LOG_FILE" 2>/dev/null | grep -m 1 "send-to-claude")
  18. if [[ -n "$RESULT" ]]; then
  19. echo "$RESULT"
  20. exit 0
  21. fi
  22. sleep 0.2
  23. done