File size: 2,785 Bytes
a7ae6b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# Elizabeth Training Keep-Alive Script
# Provides periodic input to keep training sessions active

echo "=== Elizabeth Training Keep-Alive ==="
echo "Started: $(date)"

# Training prompts to keep session active
TRAINING_PROMPTS=(
    "Please continue your training and analysis"
    "Share your latest insights and learning progress"
    "What have you discovered in your recent training?"
    "Continue with your autonomous learning cycle"
    "Provide a status update on your training progress"
    "What patterns are you identifying in your learning?"
    "Continue your analysis and share key findings"
)

# Find active Elizabeth training process
find_elizabeth_pid() {
    ps aux | grep "python3.*elizabeth_main.py.*interactive" | grep -v grep | awk '{print $2}' | head -1
}

# Send input to process
send_training_prompt() {
    local pid=$1
    local prompt=$2
    
    # Check if process exists and is interactive
    if [ -n "$pid" ] && [ -e "/proc/$pid/fd/0" ]; then
        echo "Sending training prompt to PID $pid: $prompt"
        echo "$prompt" > /proc/$pid/fd/0
        return 0
    else
        echo "No active interactive training process found"
        return 1
    fi
}

# Main keep-alive loop
COUNTER=0
MAX_ITERATIONS=100
SLEEP_DURATION=300  # 5 minutes

while [ $COUNTER -lt $MAX_ITERATIONS ]; do
    echo ""
    echo "[$(date)] Keep-alive iteration $((COUNTER + 1))/$MAX_ITERATIONS"
    
    # Find active training process
    TRAINING_PID=$(find_elizabeth_pid)
    
    if [ -n "$TRAINING_PID" ]; then
        echo "Found training process: PID $TRAINING_PID"
        
        # Select random prompt
        PROMPT_INDEX=$((RANDOM % ${#TRAINING_PROMPTS[@]}))
        SELECTED_PROMPT="${TRAINING_PROMPTS[$PROMPT_INDEX]}"
        
        # Send keep-alive prompt
        if send_training_prompt "$TRAINING_PID" "$SELECTED_PROMPT"; then
            echo "Keep-alive prompt sent successfully"
        else
            echo "Failed to send keep-alive prompt"
        fi
    else
        echo "No active training process found - checking for restart..."
        
        # Check if training manager is running
        if ! ps aux | grep -q "training_manager.py" | grep -v grep; then
            echo "Training manager not running, attempting to restart..."
            cd /workspace/elizabeth-repo
            nohup python3 scripts/training_manager.py --start --mode interactive > /workspace/elizabeth_logs/training_manager.log 2>&1 &
            echo "Training manager restarted"
        fi
    fi
    
    # Wait before next iteration
    echo "Sleeping for $SLEEP_DURATION seconds..."
    sleep $SLEEP_DURATION
    
    COUNTER=$((COUNTER + 1))
done

echo ""
echo "=== Keep-Alive Completed ==="
echo "Finished: $(date)"
echo "Total iterations: $COUNTER"