Procházet zdrojové kódy

feat: add sendToClaude helper and wait-for-event tool

- Add sendToClaude() function to browser helper that shows confirmation
- Add wait-for-event.sh script for watching server output (tail -f | grep -m 1)
- Enables clean event-driven loop: background bash waits for event, completion triggers Claude's turn
Jesse Vincent před 7 měsíci
rodič
revize
fd51e8a6b7

+ 19 - 1
lib/brainstorm-server/helper.js

@@ -87,10 +87,28 @@
     }, 500); // 500ms debounce
     }, 500); // 500ms debounce
   });
   });
 
 
+  // Send to Claude - triggers server to exit and return all events
+  function sendToClaude(feedback) {
+    send({
+      type: 'send-to-claude',
+      feedback: feedback || null
+    });
+    // Show confirmation to user
+    document.body.innerHTML = `
+      <div style="display: flex; align-items: center; justify-content: center; height: 100vh; font-family: system-ui, sans-serif;">
+        <div style="text-align: center; color: #666;">
+          <h2 style="color: #333;">✓ Sent to Claude</h2>
+          <p>Return to the terminal to see Claude's response.</p>
+        </div>
+      </div>
+    `;
+  }
+
   // Expose for explicit use if needed
   // Expose for explicit use if needed
   window.brainstorm = {
   window.brainstorm = {
     send: send,
     send: send,
-    choice: (value, metadata = {}) => send({ type: 'choice', value, ...metadata })
+    choice: (value, metadata = {}) => send({ type: 'choice', value, ...metadata }),
+    sendToClaude: sendToClaude
   };
   };
 
 
   connect();
   connect();

+ 20 - 0
lib/brainstorm-server/wait-for-event.sh

@@ -0,0 +1,20 @@
+#!/bin/bash
+# Wait for a browser event from the brainstorm server
+# Usage: wait-for-event.sh <output-file> [event-type]
+#
+# Blocks until a matching event arrives, then prints it and exits.
+# Default event type: "send-to-claude"
+
+OUTPUT_FILE="${1:?Usage: wait-for-event.sh <output-file> [event-type]}"
+EVENT_TYPE="${2:-send-to-claude}"
+
+if [[ ! -f "$OUTPUT_FILE" ]]; then
+  echo "Error: Output file not found: $OUTPUT_FILE" >&2
+  exit 1
+fi
+
+# Wait for new lines matching the event type
+# -n 0: start at end (only new content)
+# -f: follow
+# grep -m 1: exit after first match
+tail -n 0 -f "$OUTPUT_FILE" | grep -m 1 "$EVENT_TYPE"