-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.sh
More file actions
513 lines (380 loc) · 10.9 KB
/
script.sh
File metadata and controls
513 lines (380 loc) · 10.9 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# Grounded Evolution Upgrade Script
This script:
* Clones the existing repo
* Removes old symbolic-only evaluator logic
* Creates a grounded execution-based evolution loop
* Adds runtime validation
* Adds pytest execution
* Adds auto git commits/pushes
* Adds README auto-beautification hooks
* Runs continuously in an infinite research loop
---
```bash
#!/usr/bin/env bash
# ============================================================
# Grounded Evolution System Bootstrap
# ============================================================
set -e
REPO_URL="https://github.com/NullLabTests/grounded_evolution.git"
REPO_NAME="grounded_evolution"
BRANCH_NAME="grounded-evolution"
# ============================================================
# Clone Repository
# ============================================================
if [ ! -d "$REPO_NAME" ]; then
git clone "$REPO_URL"
fi
cd "$REPO_NAME"
# ============================================================
# Branch Setup
# ============================================================
git checkout -b "$BRANCH_NAME" || git checkout "$BRANCH_NAME"
# ============================================================
# Remove Legacy Files
# ============================================================
rm -f evaluator.py || true
rm -f signal_hunt.py || true
rm -f reflective_mutation.py || true
rm -f lexical_scoring.py || true
rm -f buzzword_score.py || true
mkdir -p generated_projects
mkdir -p runtime_logs
mkdir -p benchmarks
mkdir -p population
mkdir -p evaluator
mkdir -p memory
mkdir -p reports
# ============================================================
# Python Requirements
# ============================================================
cat > requirements.txt << 'EOF'
openai
pytest
black
flake8
rich
gitpython
psutil
EOF
pip install -r requirements.txt
# ============================================================
# Benchmark Tasks
# ============================================================
cat > benchmarks/tasks.json << 'EOF'
[
{
"name": "flask_api",
"prompt": "Create a modular Flask REST API with health endpoint and clean structure"
},
{
"name": "cli_tool",
"prompt": "Create a Python CLI task manager using argparse"
},
{
"name": "websocket_server",
"prompt": "Create an async websocket echo server in Python"
}
]
EOF
# ============================================================
# Runtime Evaluator
# ============================================================
cat > evaluator/runtime_evaluator.py << 'EOF'
import os
import subprocess
import json
import time
from pathlib import Path
def run_command(cmd, cwd=None, timeout=60):
try:
start = time.time()
result = subprocess.run(
cmd,
cwd=cwd,
shell=True,
capture_output=True,
text=True,
timeout=timeout
)
duration = time.time() - start
return {
"success": result.returncode == 0,
"stdout": result.stdout,
"stderr": result.stderr,
"duration": duration
}
except Exception as e:
return {
"success": False,
"stdout": "",
"stderr": str(e),
"duration": 999
}
def evaluate_project(project_dir):
score = 0
metrics = {}
compile_result = run_command(
"python -m py_compile $(find . -name '*.py')",
cwd=project_dir
)
metrics["compile"] = compile_result
if compile_result["success"]:
score += 25
lint_result = run_command(
"flake8 .",
cwd=project_dir
)
metrics["lint"] = lint_result
if lint_result["success"]:
score += 20
format_result = run_command(
"black --check .",
cwd=project_dir
)
metrics["format"] = format_result
if format_result["success"]:
score += 15
pytest_result = run_command(
"pytest",
cwd=project_dir
)
metrics["pytest"] = pytest_result
if pytest_result["success"]:
score += 40
metrics["final_score"] = score
return metrics
EOF
# ============================================================
# Mutation Engine
# ============================================================
cat > mutation_engine.py << 'EOF'
import random
MUTATIONS = [
"Add stronger modularity requirements",
"Require async support",
"Require better logging",
"Require retry handling",
"Require tests",
"Require docstrings",
"Require cleaner architecture",
"Reduce token usage",
"Improve startup speed",
"Improve readability"
]
def mutate_prompt(prompt):
mutation = random.choice(MUTATIONS)
return f"{prompt}\n\nAdditional requirement: {mutation}"
EOF
# ============================================================
# Population Manager
# ============================================================
cat > population_manager.py << 'EOF'
import json
import random
from pathlib import Path
POP_FILE = "population/population.json"
def load_population():
path = Path(POP_FILE)
if not path.exists():
seed = [
{
"prompt": "Generate clean production-grade Python software",
"score": 0
}
]
path.parent.mkdir(exist_ok=True)
with open(path, "w") as f:
json.dump(seed, f, indent=2)
with open(path) as f:
return json.load(f)
def save_population(pop):
with open(POP_FILE, "w") as f:
json.dump(pop, f, indent=2)
def select_best(pop, k=3):
return sorted(pop, key=lambda x: x["score"], reverse=True)[:k]
EOF
# ============================================================
# OpenAI Generator
# ============================================================
cat > generator.py << 'EOF'
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
def generate_code(prompt):
response = client.chat.completions.create(
model="gpt-4.1",
messages=[
{
"role": "system",
"content": "You are an autonomous software architect. Generate clean executable Python projects."
},
{
"role": "user",
"content": prompt
}
],
temperature=0.8
)
return response.choices[0].message.content
EOF
# ============================================================
# README Beautifier
# ============================================================
cat > beautify_readme.py << 'EOF'
from pathlib import Path
from datetime import datetime
README = Path("README.md")
def beautify():
existing = README.read_text() if README.exists() else ""
banner = f"""
# Grounded Evolution System
Last Evolution Cycle: {datetime.utcnow().isoformat()} UTC
## Purpose
This system evolves prompts against REAL execution-based benchmarks.
It optimizes:
- Runtime success
- Test pass rates
- Modularity
- Maintainability
- Execution correctness
---
"""
README.write_text(banner + existing)
if __name__ == "__main__":
beautify()
EOF
# ============================================================
# Infinite Evolution Loop
# ============================================================
cat > infinite_research_loop.py << 'EOF'
import json
import os
import shutil
import subprocess
import time
from pathlib import Path
from generator import generate_code
from mutation_engine import mutate_prompt
from population_manager import (
load_population,
save_population,
select_best,
)
from evaluator.runtime_evaluator import evaluate_project
OUTPUT_DIR = Path("generated_projects")
def write_project_files(project_path, content):
project_path.mkdir(parents=True, exist_ok=True)
main_file = project_path / "main.py"
main_file.write_text(content)
test_file = project_path / "test_basic.py"
test_file.write_text(
"""
def test_placeholder():
assert True
"""
)
def git_commit_and_push(score):
subprocess.run("git add .", shell=True)
subprocess.run(
f'git commit -m "evolution-cycle score={score}"',
shell=True
)
subprocess.run("git push origin grounded-evolution", shell=True)
def evolve_cycle(cycle_num):
population = load_population()
best = select_best(population, k=1)[0]
mutated = mutate_prompt(best["prompt"])
generated = generate_code(mutated)
project_path = OUTPUT_DIR / f"cycle_{cycle_num}"
write_project_files(project_path, generated)
metrics = evaluate_project(project_path)
population.append(
{
"prompt": mutated,
"score": metrics["final_score"]
}
)
population = sorted(
population,
key=lambda x: x["score"],
reverse=True
)[:20]
save_population(population)
with open(f"runtime_logs/cycle_{cycle_num}.json", "w") as f:
json.dump(metrics, f, indent=2)
subprocess.run("python beautify_readme.py", shell=True)
git_commit_and_push(metrics["final_score"])
print(f"Cycle {cycle_num} complete")
print(metrics)
if __name__ == "__main__":
cycle = 0
while True:
try:
evolve_cycle(cycle)
cycle += 1
time.sleep(30)
except KeyboardInterrupt:
break
except Exception as e:
print(f"Loop error: {e}")
time.sleep(15)
EOF
# ============================================================
# Git Ignore
# ============================================================
cat > .gitignore << 'EOF'
__pycache__/
*.pyc
.env
.venv/
generated_projects/
runtime_logs/
EOF
# ============================================================
# Final Commit
# ============================================================
git add .
git commit -m "Grounded execution evolution system upgrade"
# ============================================================
# Startup Instructions
# ============================================================
echo ""
echo "======================================================="
echo "SETUP COMPLETE"
echo "======================================================="
echo ""
echo "Export your OpenAI key first:"
echo ""
echo "export OPENAI_API_KEY='your_key_here'"
echo ""
echo "Then run:"
echo ""
echo "python infinite_research_loop.py"
echo ""
echo "The system will now evolve continuously using:"
echo "- Runtime execution"
echo "- pytest"
echo "- flake8"
echo "- black"
echo "- Git auto commits"
echo "- README beautification"
echo "- Infinite evolutionary cycles"
echo ""
```
---
## Recommended Next Step
Open the repo in:
* OpenCode
* Cursor
* Windsurf
* VSCode + Copilot
Then allow the coding agent to:
* monitor runtime logs
* improve evaluator robustness
* add benchmark diversity
* evolve multi-file project generation
* optimize mutation operators
* introduce hidden benchmark tasks
* add execution sandboxes
* add regression tracking
That is where this starts becoming a genuinely interesting autonomous experimentation system.