claude-evolve 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +202 -0
- package/bin/claude-evolve-analyze +8 -2
- package/bin/claude-evolve-run +38 -23
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# claude-evolve
|
|
2
|
+
|
|
3
|
+
Automated algorithm evolution - let AI evolve your algorithms while you sleep.
|
|
4
|
+
|
|
5
|
+
## What is this?
|
|
6
|
+
|
|
7
|
+
claude-evolve is an automated algorithm evolution system that runs continuous evolution cycles without constant supervision. Start with a base algorithm and let it evolve optimized variants autonomously.
|
|
8
|
+
|
|
9
|
+
Think of it like **genetic algorithms for code** - it handles the mutations and testing, but you should keep an eye on the results and occasionally guide the evolution when needed.
|
|
10
|
+
|
|
11
|
+
### How the Evolution System Works
|
|
12
|
+
|
|
13
|
+
The system operates with specialized phases working together:
|
|
14
|
+
|
|
15
|
+
- 🧠 **Ideation Phase**: Generates creative algorithm variations using Claude Opus
|
|
16
|
+
- 🔬 **Development Phase**: Implements mutations using Claude Sonnet (with periodic Opus "megathinking")
|
|
17
|
+
- 📊 **Evaluation Phase**: Tests performance against your custom evaluator
|
|
18
|
+
- 📈 **Analysis Phase**: Tracks evolution progress and identifies top performers
|
|
19
|
+
|
|
20
|
+
The evolution cycle:
|
|
21
|
+
```
|
|
22
|
+
Ideate → Mutate → Evaluate → Analyze → Repeat
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
You can leave it running while you grab lunch or sleep - it just keeps evolving better algorithms until you stop it.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install -g claude-evolve
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
claude-evolve
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The system will walk you through the setup process:
|
|
40
|
+
|
|
41
|
+
1. **Create evolution workspace** - Initialize the directory structure
|
|
42
|
+
2. **Write evolution/BRIEF.md** - Describe your optimization problem
|
|
43
|
+
3. **Customize evolution/evaluator.py** - Define how to measure algorithm performance
|
|
44
|
+
4. **Generate ideas** - Create initial algorithm candidates
|
|
45
|
+
5. **Start evolution** - Begin the automated evolution process
|
|
46
|
+
|
|
47
|
+
## Commands
|
|
48
|
+
|
|
49
|
+
### Main wrapper command
|
|
50
|
+
```bash
|
|
51
|
+
claude-evolve # Interactive mode (recommended for beginners)
|
|
52
|
+
claude-evolve setup # Initialize evolution workspace
|
|
53
|
+
claude-evolve ideate # Generate new algorithm ideas
|
|
54
|
+
claude-evolve run # Execute evolution candidates
|
|
55
|
+
claude-evolve analyze # Analyze evolution results
|
|
56
|
+
claude-evolve config # Manage configuration settings
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Individual commands (if you know what you're doing)
|
|
60
|
+
|
|
61
|
+
#### claude-evolve-setup
|
|
62
|
+
Initializes your evolution workspace with:
|
|
63
|
+
- Directory structure
|
|
64
|
+
- Template files (BRIEF.md, algorithm.py, evaluator.py, config.yaml)
|
|
65
|
+
- CSV file for tracking evolution progress
|
|
66
|
+
|
|
67
|
+
#### claude-evolve-ideate
|
|
68
|
+
Generates new algorithm variation ideas using Claude Opus in megathinking mode:
|
|
69
|
+
- Reads your project brief
|
|
70
|
+
- Analyzes top-performing algorithms so far
|
|
71
|
+
- Creates creative mutations and variations
|
|
72
|
+
- Defaults to 20 ideas per run (configurable)
|
|
73
|
+
|
|
74
|
+
#### claude-evolve-run
|
|
75
|
+
Executes the next evolution candidate:
|
|
76
|
+
- Picks the next untested idea from your CSV
|
|
77
|
+
- Uses Claude to implement the mutation
|
|
78
|
+
- Runs your evaluator to measure performance
|
|
79
|
+
- Records results and updates the evolution log
|
|
80
|
+
- Every 4th iteration uses Opus for architectural thinking
|
|
81
|
+
|
|
82
|
+
#### claude-evolve-analyze
|
|
83
|
+
Analyzes evolution progress and generates insights:
|
|
84
|
+
- Performance trends over time
|
|
85
|
+
- Best-performing algorithm variants
|
|
86
|
+
- Suggestions for future evolution directions
|
|
87
|
+
|
|
88
|
+
#### claude-evolve-config
|
|
89
|
+
Manages configuration settings:
|
|
90
|
+
- View current configuration
|
|
91
|
+
- Edit paths and behavior settings
|
|
92
|
+
- Reset to defaults
|
|
93
|
+
|
|
94
|
+
## How it Works
|
|
95
|
+
|
|
96
|
+
1. **Set up evolution workspace** - Define your optimization problem
|
|
97
|
+
2. **Create base algorithm** - Start with `evolution/algorithm.py`
|
|
98
|
+
3. **Define evaluation criteria** - Customize `evolution/evaluator.py`
|
|
99
|
+
4. **Generate initial ideas** - Run `claude-evolve ideate` to create variations
|
|
100
|
+
5. **Start evolution loop** - The system automatically:
|
|
101
|
+
- Picks the next candidate from your CSV
|
|
102
|
+
- Implements the mutation
|
|
103
|
+
- Evaluates performance
|
|
104
|
+
- Records results
|
|
105
|
+
- Repeats until you stop it
|
|
106
|
+
|
|
107
|
+
## Monitoring Progress (Like Genetic Algorithms)
|
|
108
|
+
|
|
109
|
+
This isn't sci-fi level "sleep through the entire evolution" automation - it's more like controlled genetic algorithms. The system handles most mutations, but you should monitor it and guide the evolution when needed.
|
|
110
|
+
|
|
111
|
+
**Recommended monitoring approach:**
|
|
112
|
+
- **Check evolution.csv** - Track performance of all variants
|
|
113
|
+
- **Review top performers** - Look at the best algorithms generated so far
|
|
114
|
+
- **Monitor for convergence** - Watch for diminishing returns or local optima
|
|
115
|
+
- **Inject new ideas** - Add manual variations when evolution stagnates
|
|
116
|
+
|
|
117
|
+
**When you need to guide evolution:**
|
|
118
|
+
- **Add targeted ideas** - Use `claude-evolve ideate` with specific directions
|
|
119
|
+
- **Modify the evaluator** - Update `evolution/evaluator.py` to change selection pressure
|
|
120
|
+
- **Restart from best** - Copy top performer to `algorithm.py` and continue evolving
|
|
121
|
+
- **The system adapts** - New ideas will build on your guidance
|
|
122
|
+
|
|
123
|
+
**Interruptible design:**
|
|
124
|
+
- Hit Ctrl+C anytime to pause
|
|
125
|
+
- Restart later with `claude-evolve run`
|
|
126
|
+
- Perfect for running overnight, during meetings, or while getting lunch
|
|
127
|
+
|
|
128
|
+
## Requirements
|
|
129
|
+
|
|
130
|
+
### Required
|
|
131
|
+
- Node.js >= 14.0.0
|
|
132
|
+
- Python 3.x (for algorithm execution)
|
|
133
|
+
- Unix-like environment (macOS, Linux)
|
|
134
|
+
- [Claude CLI](https://docs.anthropic.com/en/docs/claude-code) (`claude` command)
|
|
135
|
+
|
|
136
|
+
### Optional (but recommended)
|
|
137
|
+
- Scientific Python libraries (numpy, scipy, etc.) depending on your algorithms
|
|
138
|
+
- Plotting libraries (matplotlib, plotly) for analyzing results
|
|
139
|
+
|
|
140
|
+
## Project Structure
|
|
141
|
+
|
|
142
|
+
Your evolution workspace will have:
|
|
143
|
+
```
|
|
144
|
+
your-project/
|
|
145
|
+
├── evolution/
|
|
146
|
+
│ ├── BRIEF.md # Problem description and goals
|
|
147
|
+
│ ├── algorithm.py # Base algorithm to evolve
|
|
148
|
+
│ ├── evaluator.py # Performance evaluation logic
|
|
149
|
+
│ ├── config.yaml # Configuration settings
|
|
150
|
+
│ ├── evolution.csv # Evolution progress tracking
|
|
151
|
+
│ ├── evolution_id1.py # Generated algorithm variants
|
|
152
|
+
│ ├── evolution_id2.py
|
|
153
|
+
│ └── ...
|
|
154
|
+
└── (your main project files)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Configuration
|
|
158
|
+
|
|
159
|
+
Edit `evolution/config.yaml` to customize:
|
|
160
|
+
|
|
161
|
+
```yaml
|
|
162
|
+
# Working directory for evolution files
|
|
163
|
+
evolution_dir: "evolution"
|
|
164
|
+
|
|
165
|
+
# Algorithm and evaluator file paths
|
|
166
|
+
algorithm_file: "algorithm.py"
|
|
167
|
+
evaluator_file: "evaluator.py"
|
|
168
|
+
brief_file: "BRIEF.md"
|
|
169
|
+
|
|
170
|
+
# CSV file for tracking evolution
|
|
171
|
+
evolution_csv: "evolution.csv"
|
|
172
|
+
|
|
173
|
+
# Parent algorithm selection strategy
|
|
174
|
+
parent_selection: "best" # or "random", "latest"
|
|
175
|
+
|
|
176
|
+
# Maximum number of ideas to generate at once
|
|
177
|
+
max_ideas: 50
|
|
178
|
+
|
|
179
|
+
# Python command to use for evaluation
|
|
180
|
+
python_cmd: "python3"
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Tips for Success
|
|
184
|
+
|
|
185
|
+
1. **Write a clear BRIEF.md** - Describe your optimization problem, constraints, and goals
|
|
186
|
+
2. **Create a robust evaluator** - Your evaluator.py determines evolution direction
|
|
187
|
+
3. **Start simple** - Begin with a basic algorithm and let evolution add complexity
|
|
188
|
+
4. **Monitor early cycles** - Watch the first few evolutions to ensure proper setup
|
|
189
|
+
5. **Guide when stuck** - Add manual ideas when evolution hits local optima
|
|
190
|
+
6. **Embrace failures** - Not every mutation will be better, that's how evolution works
|
|
191
|
+
|
|
192
|
+
## Example Use Cases
|
|
193
|
+
|
|
194
|
+
- **Algorithm optimization** - Improve sorting, searching, or mathematical algorithms
|
|
195
|
+
- **Machine learning** - Evolve model architectures or training procedures
|
|
196
|
+
- **Game AI** - Develop and optimize game-playing strategies
|
|
197
|
+
- **Numerical methods** - Improve solvers, optimizers, or approximation algorithms
|
|
198
|
+
- **Data structures** - Evolve efficient data organization strategies
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT
|
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
set -e
|
|
4
4
|
|
|
5
|
+
# Load configuration
|
|
6
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
7
|
+
# shellcheck source=../lib/config.sh
|
|
8
|
+
source "$SCRIPT_DIR/../lib/config.sh"
|
|
9
|
+
load_config
|
|
10
|
+
|
|
5
11
|
# Parse arguments
|
|
6
12
|
open_chart=false
|
|
7
|
-
csv_file="
|
|
8
|
-
output_file="
|
|
13
|
+
csv_file="$FULL_CSV_PATH"
|
|
14
|
+
output_file="$FULL_OUTPUT_DIR/performance.png"
|
|
9
15
|
|
|
10
16
|
while [[ $# -gt 0 ]]; do
|
|
11
17
|
case $1 in
|
package/bin/claude-evolve-run
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
set -e
|
|
4
4
|
|
|
5
|
+
# Load configuration
|
|
6
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
7
|
+
# shellcheck source=../lib/config.sh
|
|
8
|
+
source "$SCRIPT_DIR/../lib/config.sh"
|
|
9
|
+
load_config
|
|
10
|
+
|
|
5
11
|
# Parse arguments
|
|
6
12
|
timeout_seconds=""
|
|
7
13
|
|
|
@@ -46,18 +52,27 @@ done
|
|
|
46
52
|
echo "[INFO] Starting evolution run..."
|
|
47
53
|
[[ -n $timeout_seconds ]] && echo "[INFO] Using timeout: ${timeout_seconds} seconds"
|
|
48
54
|
|
|
49
|
-
# Validate workspace
|
|
50
|
-
if [[ ! -d
|
|
51
|
-
echo "[ERROR] Evolution directory not found. Run 'claude-evolve setup' first." >&2
|
|
55
|
+
# Validate workspace using config
|
|
56
|
+
if [[ ! -d "$FULL_EVOLUTION_DIR" ]]; then
|
|
57
|
+
echo "[ERROR] Evolution directory not found: $FULL_EVOLUTION_DIR. Run 'claude-evolve setup' first." >&2
|
|
52
58
|
exit 1
|
|
53
59
|
fi
|
|
54
60
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
# Check required files
|
|
62
|
+
if [[ ! -f "$FULL_CSV_PATH" ]]; then
|
|
63
|
+
echo "[ERROR] CSV file not found: $FULL_CSV_PATH" >&2
|
|
64
|
+
exit 1
|
|
65
|
+
fi
|
|
66
|
+
|
|
67
|
+
if [[ ! -f "$FULL_EVALUATOR_PATH" ]]; then
|
|
68
|
+
echo "[ERROR] Evaluator not found: $FULL_EVALUATOR_PATH" >&2
|
|
69
|
+
exit 1
|
|
70
|
+
fi
|
|
71
|
+
|
|
72
|
+
if [[ ! -f "$FULL_ALGORITHM_PATH" ]]; then
|
|
73
|
+
echo "[ERROR] Algorithm not found: $FULL_ALGORITHM_PATH" >&2
|
|
74
|
+
exit 1
|
|
75
|
+
fi
|
|
61
76
|
|
|
62
77
|
# Find oldest empty row (pure shell)
|
|
63
78
|
find_empty_row() {
|
|
@@ -68,13 +83,13 @@ find_empty_row() {
|
|
|
68
83
|
return 0
|
|
69
84
|
fi
|
|
70
85
|
((row_num++))
|
|
71
|
-
done < <(tail -n +2
|
|
86
|
+
done < <(tail -n +2 "$FULL_CSV_PATH")
|
|
72
87
|
return 1
|
|
73
88
|
}
|
|
74
89
|
|
|
75
90
|
# Get CSV row (pure shell)
|
|
76
91
|
get_csv_row() {
|
|
77
|
-
sed -n "${1}p"
|
|
92
|
+
sed -n "${1}p" "$FULL_CSV_PATH"
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
# Update CSV row (pure shell with temp file)
|
|
@@ -84,7 +99,7 @@ update_csv_row() {
|
|
|
84
99
|
local status="$3"
|
|
85
100
|
|
|
86
101
|
# Read CSV and update specific row
|
|
87
|
-
local temp_file="
|
|
102
|
+
local temp_file="${FULL_CSV_PATH}.tmp"
|
|
88
103
|
local current_row=1
|
|
89
104
|
|
|
90
105
|
while IFS=, read -r id based_on desc perf stat; do
|
|
@@ -96,9 +111,9 @@ update_csv_row() {
|
|
|
96
111
|
echo "$id,$based_on,$desc,$perf,$stat"
|
|
97
112
|
fi
|
|
98
113
|
((current_row++))
|
|
99
|
-
done <
|
|
114
|
+
done <"$FULL_CSV_PATH" >"$temp_file"
|
|
100
115
|
|
|
101
|
-
mv "$temp_file"
|
|
116
|
+
mv "$temp_file" "$FULL_CSV_PATH"
|
|
102
117
|
}
|
|
103
118
|
|
|
104
119
|
# Find next candidate
|
|
@@ -126,9 +141,9 @@ trap 'update_csv_row "$row_num" "" "interrupted"; echo "[INFO] Evolution interru
|
|
|
126
141
|
update_csv_row "$row_num" "" "running"
|
|
127
142
|
|
|
128
143
|
# Determine parent algorithm
|
|
129
|
-
parent_file="
|
|
144
|
+
parent_file="$FULL_ALGORITHM_PATH"
|
|
130
145
|
if [[ -n $based_on_id && $based_on_id != "0" ]]; then
|
|
131
|
-
parent_file="
|
|
146
|
+
parent_file="$FULL_OUTPUT_DIR/evolution_id${based_on_id}.py"
|
|
132
147
|
if [[ ! -f $parent_file ]]; then
|
|
133
148
|
echo "[ERROR] Parent algorithm file not found: $parent_file" >&2
|
|
134
149
|
update_csv_row "$row_num" "" "failed"
|
|
@@ -139,7 +154,7 @@ fi
|
|
|
139
154
|
echo "[INFO] Using parent algorithm: $parent_file"
|
|
140
155
|
|
|
141
156
|
# Generate mutation
|
|
142
|
-
output_file="
|
|
157
|
+
output_file="$FULL_OUTPUT_DIR/evolution_id${id}.py"
|
|
143
158
|
echo "[INFO] Generating algorithm mutation..."
|
|
144
159
|
|
|
145
160
|
# Copy parent algorithm to output file first
|
|
@@ -156,8 +171,8 @@ fi
|
|
|
156
171
|
|
|
157
172
|
# Implement claude-fsd style model selection
|
|
158
173
|
# Read/create loop counter for megathinking mode
|
|
159
|
-
if [[ -f
|
|
160
|
-
LOOP_COUNTER=$(cat
|
|
174
|
+
if [[ -f "$FULL_EVOLUTION_DIR/.loop_counter" ]]; then
|
|
175
|
+
LOOP_COUNTER=$(cat "$FULL_EVOLUTION_DIR/.loop_counter")
|
|
161
176
|
else
|
|
162
177
|
LOOP_COUNTER=1
|
|
163
178
|
fi
|
|
@@ -175,13 +190,13 @@ else
|
|
|
175
190
|
fi
|
|
176
191
|
|
|
177
192
|
# Increment and save counter
|
|
178
|
-
echo $((LOOP_COUNTER + 1)) >
|
|
193
|
+
echo $((LOOP_COUNTER + 1)) > "$FULL_EVOLUTION_DIR/.loop_counter"
|
|
179
194
|
|
|
180
195
|
# Create mutation prompt
|
|
181
196
|
prompt="${MEGATHINK_PREFIX}You are an AI assistant helping to evolve algorithms through mutations. Please modify the Python algorithm file at $output_file based on the requested modification.
|
|
182
197
|
|
|
183
198
|
CONTEXT:
|
|
184
|
-
$(cat
|
|
199
|
+
$(cat "$FULL_BRIEF_PATH" 2>/dev/null || echo "No brief available")
|
|
185
200
|
|
|
186
201
|
ALGORITHM FILE TO MODIFY: $output_file
|
|
187
202
|
|
|
@@ -216,7 +231,7 @@ eval_exit_code=0
|
|
|
216
231
|
|
|
217
232
|
if [[ -n $timeout_seconds ]]; then
|
|
218
233
|
echo "[INFO] Starting evaluation with ${timeout_seconds}s timeout..."
|
|
219
|
-
if eval_output=$(timeout "$timeout_seconds"
|
|
234
|
+
if eval_output=$(timeout "$timeout_seconds" "$PYTHON_CMD" "$FULL_EVALUATOR_PATH" "$output_file" 2>&1); then
|
|
220
235
|
eval_exit_code=0
|
|
221
236
|
else
|
|
222
237
|
eval_exit_code=$?
|
|
@@ -227,7 +242,7 @@ if [[ -n $timeout_seconds ]]; then
|
|
|
227
242
|
fi
|
|
228
243
|
fi
|
|
229
244
|
else
|
|
230
|
-
if eval_output=$(
|
|
245
|
+
if eval_output=$("$PYTHON_CMD" "$FULL_EVALUATOR_PATH" "$output_file" 2>&1); then
|
|
231
246
|
eval_exit_code=0
|
|
232
247
|
else
|
|
233
248
|
eval_exit_code=$?
|