#!/bin/bash # AUTONOMOUS BUILDER - MB2 (No jq) LEARNED_FILE=~/.thataiguy/learned_items.json OUTPUT_DIR=~/Library/Mobile\ Documents/com~apple~CloudDocs/AGI_Data/generated LOG_FILE=~/.seferim/logs/builder.log mkdir -p "$OUTPUT_DIR/scripts" "$OUTPUT_DIR/insights" "$OUTPUT_DIR/tools" ~/.seferim/logs log() { echo "[$(date '+%H:%M:%S')] $1" >> "$LOG_FILE"; echo "[BUILDER-MB2] $1"; } get_topics() { grep -o '"content": "[^"]*"' "$LEARNED_FILE" | tail -100 | sed 's/"content": "//; s/"$//' | \ grep -oE '\b[A-Za-z][A-Za-z]{5,}\b' | tr '[:upper:]' '[:lower:]' | \ sort | uniq -c | sort -rn | head -15 | awk '$1 > 2 {print $2}' } log "=== MB2 Builder Starting ===" cycle=0 while true; do cycle=$((cycle + 1)) topics=$(get_topics) topic=$(echo "$topics" | head -1) if [ -n "$topic" ]; then log "Cycle $cycle: Building for $topic" strategy=$((cycle % 3)) case $strategy in 0) # Script f="$OUTPUT_DIR/scripts/${topic}_util_mb2.sh" echo "#!/bin/bash" > "$f" echo "# $topic utility (MB2)" >> "$f" echo "grep -i \"$topic\" ~/.thataiguy/learned_items.json | head -5" >> "$f" chmod +x "$f" log "Created script: $topic" ;; 1) # Insight f="$OUTPUT_DIR/insights/${topic}_mb2.md" echo "# $topic Insight (MB2)" > "$f" echo "Generated: $(date)" >> "$f" grep -i "$topic" "$LEARNED_FILE" | head -3 | sed 's/.*"content": "//; s/",.*//' >> "$f" log "Created insight: $topic" ;; 2) # Monitor f="$OUTPUT_DIR/tools/${topic}_mon_mb2.sh" echo "#!/bin/bash" > "$f" echo "while true; do grep -i \"$topic\" ~/.thataiguy/learned_items.json | tail -1; sleep 30; done" >> "$f" chmod +x "$f" log "Created monitor: $topic" ;; esac else log "Cycle $cycle: No topics" fi sleep 300 done