-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_forge.sh
More file actions
executable file
·165 lines (142 loc) · 6.36 KB
/
run_forge.sh
File metadata and controls
executable file
·165 lines (142 loc) · 6.36 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env bash
# =============================================================================
# Self-Referential Forge — Evolution Loop Automation
# =============================================================================
# Starts the self-referential evolution loop with environment validation,
# proper signal handling, auto-install, and optional dashboard launch.
#
# Usage:
# bash run_forge.sh # Infinite evolution
# bash run_forge.sh --cycles 50 # 50 evolution cycles
# bash run_forge.sh --dashboard # Launch dashboard alongside
# bash run_forge.sh --human-approval # Manual approval per mutation
# bash run_forge.sh --help # Show help
# =============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
# ────────────────────────────────────────────────── Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
FORGE_PID=""
DASHBOARD_PID=""
EXTRA_ARGS=()
# ────────────────────────────────────────────────── Signal handling
cleanup() {
echo -e "\n${YELLOW}Shutting down forge...${NC}"
if [ -n "$FORGE_PID" ]; then
kill "$FORGE_PID" 2>/dev/null || true
wait "$FORGE_PID" 2>/dev/null || true
fi
if [ -n "$DASHBOARD_PID" ]; then
kill "$DASHBOARD_PID" 2>/dev/null || true
fi
echo -e "${GREEN}Forge stopped.${NC}"
exit 0
}
trap cleanup SIGINT SIGTERM
# ────────────────────────────────────────────────── Banner
print_banner() {
echo -e "${CYAN}"
echo " ╔══════════════════════════════════════════════════════════╗"
echo " ║ Self-Referential Forge ║"
echo " ║ Darwin-style evolution of the forge's own components ║"
echo " ╚══════════════════════════════════════════════════════════╝"
echo -e "${NC}"
}
# ────────────────────────────────────────────────── Help
show_help() {
cat <<EOF
Usage: bash run_forge.sh [OPTIONS]
Options:
--cycles N Run N evolution cycles (default: infinite)
--human-approval Require manual approval per mutation
--auto-commit Auto-commit improvements to git
--dashboard Launch the real-time dashboard alongside the forge
--apply Apply mutations to forge's own .py files (self-referential)
--safety-off Disable safety validation (NOT RECOMMENDED)
--verbose Enable debug logging
--help Show this help message and exit
Examples:
bash run_forge.sh # Infinite self-referential evolution
bash run_forge.sh --cycles 50 # 50 evolution cycles
bash run_forge.sh --dashboard # Evolution + live dashboard
bash run_forge.sh --human-approval # Manual approval per mutation
EOF
exit 0
}
# ────────────────────────────────────────────────── Parse arguments
parse_args() {
while [ $# -gt 0 ]; do
case "$1" in
--help) show_help ;;
--cycles) EXTRA_ARGS+=("--cycles" "$2"); shift 2 ;;
--human-approval) EXTRA_ARGS+=("--human-approval"); shift ;;
--auto-commit) EXTRA_ARGS+=("--auto-commit"); shift ;;
--dashboard) LAUNCH_DASHBOARD=1; shift ;;
--safety-off) EXTRA_ARGS+=("--safety-off"); shift ;;
--apply) EXTRA_ARGS+=("--apply"); shift ;;
--verbose) EXTRA_ARGS+=("--verbose"); shift ;;
*) echo -e "${RED}Unknown option: $1${NC}"; exit 1 ;;
esac
done
}
# ────────────────────────────────────────────────── Environment validation
check_env() {
local missing=0
# Load .env if present
if [ -f .env ]; then
set -a
source .env
set +a
fi
# Check Python
if ! command -v python3 &>/dev/null; then
echo -e "${RED}ERROR: python3 not found${NC}"
missing=1
fi
# Check / validate package install
if ! python3 -c "import forge" 2>/dev/null; then
echo -e "${YELLOW}forge module not found — installing...${NC}"
pip install -e . 2>/dev/null || {
echo -e "${RED}ERROR: Failed to install dependencies${NC}"
echo -e " Try: ${BLUE}pip install -e .${NC}"
missing=1
}
fi
# Warn about LLM_API_KEY (optional for this forge, but useful)
if [ -z "${LLM_API_KEY:-}" ]; then
echo -e "${YELLOW}WARNING: LLM_API_KEY not set — LLM-dependent features disabled${NC}"
fi
return "$missing"
}
# ────────────────────────────────────────────────── Main
parse_args "$@"
print_banner
echo -e "${BLUE}Validating environment...${NC}"
if ! check_env; then
echo -e "${RED}Environment validation failed. Exiting.${NC}"
exit 1
fi
echo -e "${GREEN}Environment OK${NC}"
# Launch dashboard if requested
if [ "${LAUNCH_DASHBOARD:-0}" = "1" ]; then
echo -e "${BLUE}Launching dashboard...${NC}"
python3 -m uvicorn dashboard.main:app --host 0.0.0.0 --port "${DASHBOARD_PORT:-8000}" &
DASHBOARD_PID=$!
echo -e "${GREEN}Dashboard running on http://localhost:${DASHBOARD_PORT:-8000} (PID: $DASHBOARD_PID)${NC}"
fi
echo -e "${BLUE}Starting self-referential evolution loop...${NC}"
python3 -m forge "${EXTRA_ARGS[@]}" &
FORGE_PID=$!
echo -e "${GREEN}"
echo " Forge is running (PID: $FORGE_PID)"
if [ "${LAUNCH_DASHBOARD:-0}" = "1" ]; then
echo " Dashboard: ${BLUE}http://localhost:${DASHBOARD_PORT:-8000}${GREEN}"
fi
echo -e " Press Ctrl+C to stop.${NC}"
wait "$FORGE_PID"