evo-anything 0.1.0

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_EN.md ADDED
@@ -0,0 +1,321 @@
1
+ # Evo-anything Plugin — Git-Based Evolutionary Code Optimizer
2
+
3
+ Evo-anything is the engineering implementation of **"From Understanding to Excelling: Template-Free Algorithm Design through Structural-Functional Co-Evolution"** (arXiv:2503.10721). It applies LLM-driven **structural-functional co-evolution** to automatically optimize code in any git repository toward better benchmark performance.
4
+
5
+ > **Paper:** Zhe Zhao, Haibin Wen, Pengkun Wang, Ye Wei, Zaixi Zhang, Xi Lin, Fei Liu, Bo An, Hui Xiong, Yang Wang, Qingfu Zhang. *From Understanding to Excelling: Template-Free Algorithm Design through Structural-Functional Co-Evolution.* arXiv:2503.10721 [cs.SE], 2025.
6
+
7
+ ## Installation
8
+
9
+ ### Prerequisites
10
+
11
+ - Python >= 3.11
12
+ - Git
13
+ - GitHub CLI (`gh`) — required for `/hunt` to search repositories
14
+
15
+ ### Option 1: npm (recommended)
16
+
17
+ ```bash
18
+ npm install -g evo-anything
19
+ ```
20
+
21
+ This automatically installs the Python MCP server via `pip` during the npm postinstall step.
22
+
23
+ After installation, configure your AI IDE:
24
+
25
+ ```bash
26
+ # Configure all supported platforms (Claude Code, Cursor, Windsurf, OpenClaw)
27
+ npx evo-anything setup
28
+
29
+ # Or configure a specific platform
30
+ npx evo-anything setup --platform claude
31
+ npx evo-anything setup --platform cursor
32
+ npx evo-anything setup --platform windsurf
33
+ npx evo-anything setup --platform openclaw
34
+ ```
35
+
36
+ ---
37
+
38
+ ### Option 2: Manual
39
+
40
+ #### Step 1: Install evo-engine (required for all platforms)
41
+
42
+ ```bash
43
+ git clone https://github.com/DataLab-atom/Evo-anything.git
44
+ cd Evo-anything/plugin/evo-engine
45
+ pip install .
46
+ ```
47
+
48
+ ---
49
+
50
+ ### OpenClaw
51
+
52
+ <details>
53
+ <summary>CLI one-liner (recommended)</summary>
54
+
55
+ ```bash
56
+ openclaw plugins install openclaw-evo
57
+ openclaw gateway restart
58
+ openclaw plugins doctor # verify
59
+ ```
60
+
61
+ </details>
62
+
63
+ <details>
64
+ <summary>Local development mode</summary>
65
+
66
+ ```bash
67
+ openclaw plugins install -l ./plugin
68
+ openclaw gateway restart
69
+ ```
70
+
71
+ </details>
72
+
73
+ <details>
74
+ <summary>Manual install</summary>
75
+
76
+ Copy the plugin to the extensions directory and register it in `~/.openclaw/openclaw.json`:
77
+
78
+ ```bash
79
+ cp -r plugin/ ~/.openclaw/extensions/openclaw-evo/
80
+ ```
81
+
82
+ ```json
83
+ {
84
+ "plugins": {
85
+ "entries": {
86
+ "openclaw-evo": {
87
+ "enabled": true,
88
+ "config": {}
89
+ }
90
+ }
91
+ },
92
+ "mcpServers": {
93
+ "evo-engine": {
94
+ "command": "evo-engine",
95
+ "args": [],
96
+ "env": {}
97
+ }
98
+ }
99
+ }
100
+ ```
101
+
102
+ ```bash
103
+ openclaw gateway restart
104
+ ```
105
+
106
+ </details>
107
+
108
+ **Verify:** Type `/status` in a conversation. Seeing "Evolution not initialized" means the install succeeded.
109
+
110
+ ---
111
+
112
+ ### Claude Code
113
+
114
+ Add the MCP server to your project root or global `.claude/settings.json`:
115
+
116
+ ```json
117
+ {
118
+ "mcpServers": {
119
+ "evo-engine": {
120
+ "command": "evo-engine",
121
+ "type": "stdio"
122
+ }
123
+ }
124
+ }
125
+ ```
126
+
127
+ Link skills to Claude Code:
128
+
129
+ ```bash
130
+ ln -s $(pwd)/plugin/skills/* ~/.claude/skills/
131
+ ```
132
+
133
+ Restart Claude Code and you're ready.
134
+
135
+ ---
136
+
137
+ ### Cursor
138
+
139
+ Add to `.cursor/mcp.json` in your project root:
140
+
141
+ ```json
142
+ {
143
+ "mcpServers": {
144
+ "evo-engine": {
145
+ "command": "evo-engine",
146
+ "type": "stdio"
147
+ }
148
+ }
149
+ }
150
+ ```
151
+
152
+ Cursor will auto-discover MCP tools (`evo_init`, `evo_next_batch`, etc.). Import skills as Cursor Rules manually:
153
+
154
+ ```bash
155
+ cp plugin/AGENTS.md .cursor/rules/evo-agents.md
156
+ ```
157
+
158
+ ---
159
+
160
+ ### Windsurf
161
+
162
+ Add to `~/.codeium/windsurf/mcp_config.json`:
163
+
164
+ ```json
165
+ {
166
+ "mcpServers": {
167
+ "evo-engine": {
168
+ "command": "evo-engine",
169
+ "type": "stdio"
170
+ }
171
+ }
172
+ }
173
+ ```
174
+
175
+ ---
176
+
177
+ ### Any Other MCP-Compatible Client
178
+
179
+ Evo-anything's core is a standard [MCP](https://modelcontextprotocol.io) server. Any client that supports MCP stdio transport can connect:
180
+
181
+ ```bash
182
+ # Start the server directly (stdio mode)
183
+ evo-engine
184
+
185
+ # Or run as a Python module
186
+ python -m plugin.evo-engine.server
187
+ ```
188
+
189
+ Available MCP tools: `evo_init`, `evo_register_targets`, `evo_next_batch`, `evo_report_fitness`, `evo_select_survivors`, `evo_get_status`, `evo_get_lineage`, `evo_freeze_target`, `evo_boost_target`, `evo_record_synergy`, `evo_check_cache`.
190
+
191
+ ---
192
+
193
+ ### Optional Configuration
194
+
195
+ Evolution state is stored in `~/.openclaw/evo-state/` by default. Override with an environment variable (`U2E` stands for *Understanding to Excelling*, the paper's acronym):
196
+
197
+ ```bash
198
+ export U2E_STATE_DIR=/path/to/your/state
199
+ ```
200
+
201
+ Or configure via `openclaw.json`:
202
+
203
+ ```json
204
+ {
205
+ "plugins": {
206
+ "entries": {
207
+ "openclaw-evo": {
208
+ "enabled": true,
209
+ "config": {
210
+ "statePath": "/path/to/your/state"
211
+ }
212
+ }
213
+ }
214
+ }
215
+ }
216
+ ```
217
+
218
+ ## Quick Start
219
+
220
+ ```
221
+ You send: I want SOTA on CIFAR-100-LT
222
+
223
+ /hunt triggers automatically
224
+
225
+ Searches GitHub → finds 3 candidates → asks which one
226
+
227
+ You say: use #1
228
+
229
+ clone → pip install → download data → run baseline to confirm it works
230
+
231
+ Automatically calls /evolve → evolution loop begins
232
+
233
+ Progress report after each generation
234
+
235
+ Pushes best branch + sends final report when done
236
+ ```
237
+
238
+ ## How It Works
239
+
240
+ Evo-anything implements the **U2E (Understanding to Excelling) protocol** proposed in the paper — a template-free, two-dimensional co-evolution framework. Unlike EoH and FunSearch, which rely on predefined templates and optimize only local key functions, U2E performs global joint optimization across both the **functional dimension** (algorithm logic) and the **structural dimension** (code architecture).
241
+
242
+ Every experiment is tracked as a git branch. The evolution loop has six stages:
243
+
244
+ 1. **Analysis** — automatically identify key algorithm modules worth optimizing
245
+ 2. **Planning** — decide mutation/crossover strategy and variant counts; adaptively allocate budget by temperature per target
246
+ 3. **Generation** — LLM generates code variants (mutation: single-parent refinement; crossover: two-parent combination)
247
+ 4. **Evaluation** — run benchmarks in isolated git worktrees
248
+ 5. **Selection** — keep the best, discard the rest; run cross-target Synergy checks every N generations
249
+ 6. **Reflection** — extract lessons into structured memory to guide future evolution
250
+
251
+ The best result of each generation is tagged (`best-gen-{N}`), and the final `best-overall` branch is pushed.
252
+
253
+ ### Comparison with Prior Work
254
+
255
+ | Method | Template Required | Optimization Scope | Structural Evolution |
256
+ |--------|------------------|--------------------|----------------------|
257
+ | EoH / FunSearch | Yes (predefined) | Local functions | No |
258
+ | **Evo-anything (U2E)** | **No** | **Global multi-target** | **Functional + Structural co-evolution** |
259
+
260
+ ## Skills
261
+
262
+ | Command | Description |
263
+ |---------|-------------|
264
+ | `/hunt <task description>` | Search GitHub for a suitable repo, auto clone/install/baseline, then start evolution |
265
+ | `/evolve <repo> <benchmark_cmd>` | Start an evolutionary optimization loop on a given repo |
266
+ | `/status` | Check current evolution progress |
267
+ | `/report` | Generate a full evolution report |
268
+ | `/boost <target_id>` | Increase the priority of an optimization target |
269
+ | `/freeze <target_id>` | Freeze a target, stopping evolution on it |
270
+
271
+ ## Repository Structure
272
+
273
+ ```
274
+ Evo-anythin/
275
+ ├── LICENSE
276
+ ├── README.md
277
+ ├── README_EN.md
278
+ └── plugin/
279
+ ├── openclaw.plugin.json # plugin definition
280
+ ├── AGENTS.md # evolution protocol (core loop)
281
+ ├── SOUL.md # agent persona
282
+ ├── TOOLS.md # tool usage conventions
283
+ ├── evo-engine/ # evolution engine (MCP server)
284
+ │ ├── server.py # MCP tool interface
285
+ │ ├── models.py # data models
286
+ │ └── selection.py # selection algorithms
287
+ └── skills/ # user-invocable skills
288
+ ├── hunt/ # search and deploy a codebase
289
+ ├── evolve/ # start evolution loop
290
+ ├── status/ # check progress
291
+ ├── report/ # generate report
292
+ ├── boost/ # boost target priority
293
+ └── freeze/ # freeze a target
294
+ ```
295
+
296
+ ## Evolution Memory
297
+
298
+ Evo-anything maintains structured memory in the target repository to avoid repeating failed attempts:
299
+
300
+ ```
301
+ memory/
302
+ ├── global/long_term.md — cross-target lessons
303
+ ├── targets/{id}/
304
+ │ ├── short_term/gen_{N}.md — per-generation reflection
305
+ │ ├── long_term.md — accumulated wisdom for this target
306
+ │ └── failures.md — what NOT to try again
307
+ └── synergy/records.md — cross-function combination results
308
+ ```
309
+
310
+ ## Branch Naming
311
+
312
+ ```
313
+ gen-{N}/{target_id}/{op}-{V} # single-target variant
314
+ gen-{N}/synergy/{targetA}+{targetB}-{V} # cross-target combination
315
+ ```
316
+
317
+ Tags: `seed-baseline`, `best-gen-{N}`, `best-overall`
318
+
319
+ ## License
320
+
321
+ MIT
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "evo-anything",
3
+ "version": "0.1.0",
4
+ "description": "Git-based evolutionary algorithm design engine. Evolves code via LLM-driven mutation, crossover, and reflection on any git repository.",
5
+ "keywords": [
6
+ "ai",
7
+ "evolutionary-algorithm",
8
+ "mcp",
9
+ "llm",
10
+ "code-optimization",
11
+ "openclaw",
12
+ "claude"
13
+ ],
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/DataLab-atom/Evo-anything.git"
18
+ },
19
+ "engines": {
20
+ "node": ">=16"
21
+ },
22
+ "bin": {
23
+ "evo-anything": "scripts/cli.js"
24
+ },
25
+ "scripts": {
26
+ "postinstall": "node scripts/postinstall.js"
27
+ },
28
+ "files": [
29
+ "plugin/",
30
+ "scripts/",
31
+ "README.md",
32
+ "README_EN.md"
33
+ ]
34
+ }
@@ -0,0 +1,89 @@
1
+ # U2E Evolution Protocol
2
+
3
+ You are the orchestrator of a git-based evolutionary algorithm design engine.
4
+
5
+ ## Overview
6
+
7
+ You evolve code in a target git repository by running generations of:
8
+ 1. **Analysis** — identify which functions to optimize (MapAgent role)
9
+ 2. **Planning** — decide operation types and variant counts per target (PlanAgent role)
10
+ 3. **Generation** — create code variants via mutation or crossover (CodeGenAgent role)
11
+ 4. **Evaluation** — run benchmarks in isolated git worktrees (DevAgent role)
12
+ 5. **Selection** — keep the best, eliminate the rest
13
+ 6. **Reflection** — extract lessons, update memory (ReflectAgent role)
14
+
15
+ ## Core Loop
16
+
17
+ ```
18
+ Call evo_init → set up evolution state
19
+ Call evo_register_targets → define what to optimize
20
+
21
+ WHILE evo_get_status shows budget remaining:
22
+ 1. Call evo_next_batch → get [{branch, op, target, parents}]
23
+ 2. For each operation:
24
+ a. git checkout -b <branch> from parent
25
+ b. Read target function code
26
+ c. Read memory/ for this target (long_term + failures)
27
+ d. Generate variant (mutate or crossover via LLM)
28
+ e. Write code change, git commit
29
+ 3. For each branch to evaluate:
30
+ a. git worktree add <path> <branch>
31
+ b. Run benchmark command in worktree
32
+ c. Parse fitness from output
33
+ d. Call evo_report_fitness with result
34
+ e. git worktree remove <path>
35
+ 4. Call evo_select_survivors → get keep/eliminate lists
36
+ 5. Delete eliminated branches
37
+ 6. Tag best: git tag best-gen-{N}
38
+ 7. Reflect:
39
+ a. git diff best..second_best → short-term reflection
40
+ b. Write to memory/targets/{id}/short_term/gen_{N}.md
41
+ c. Synthesize long_term.md from accumulated short_term
42
+ d. Record failures to memory/targets/{id}/failures.md
43
+ 8. Every 3 generations: synergy check
44
+ a. Cherry-pick best of each target into one branch
45
+ b. Evaluate combined fitness
46
+ c. Record synergy results
47
+ ```
48
+
49
+ ## Memory Layout
50
+
51
+ ```
52
+ memory/
53
+ ├── global/long_term.md — cross-target lessons
54
+ ├── targets/{id}/
55
+ │ ├── short_term/gen_{N}.md — per-generation reflection
56
+ │ ├── long_term.md — accumulated wisdom for this target
57
+ │ └── failures.md — what NOT to try again
58
+ └── synergy/records.md — cross-function combination results
59
+ ```
60
+
61
+ Write memory as Markdown. Be specific: include generation numbers, fitness values, and what changed.
62
+
63
+ ## Branch Naming
64
+
65
+ ```
66
+ gen-{N}/{target_id}/{op}-{V}
67
+ gen-{N}/synergy/{targetA}+{targetB}-{V}
68
+ ```
69
+
70
+ Tags: `seed-baseline`, `best-gen-{N}`, `best-overall`
71
+
72
+ ## Evaluation Protocol
73
+
74
+ 1. **Static check** — read generated code, fix obvious issues (missing imports, syntax errors). Do NOT fix algorithm logic.
75
+ 2. **Quick eval** — if quick_cmd is configured, run it first to filter obvious failures.
76
+ 3. **Full eval** — run full benchmark only on candidates that pass quick eval.
77
+
78
+ If a variant crashes:
79
+ - Read the traceback
80
+ - If it's a trivial fix (missing import, typo, type mismatch): fix it, re-commit, re-evaluate
81
+ - If it's an algorithm logic error: mark as failed, record in failures.md
82
+
83
+ ## Constraints
84
+
85
+ - NEVER modify the benchmark command or evaluation script
86
+ - NEVER change function signatures — only change function bodies
87
+ - NEVER edit files outside the declared optimization targets
88
+ - Always commit before evaluating (so the branch captures the exact code)
89
+ - Always clean up worktrees after evaluation
package/plugin/SOUL.md ADDED
@@ -0,0 +1,7 @@
1
+ You are an expert algorithm engineer running an evolutionary code optimization engine.
2
+
3
+ You operate on git repositories. You evolve code by iterating through generations of mutation, crossover, and reflection — all tracked as git branches.
4
+
5
+ You are methodical, data-driven, and never guess. You read code before changing it. You check fitness before claiming improvement. You record every experiment.
6
+
7
+ When speaking to the user, be concise and direct. Report numbers, not feelings.
@@ -0,0 +1,32 @@
1
+ # Tool Usage Conventions
2
+
3
+ ## evo-engine MCP tools
4
+
5
+ All deterministic evolution bookkeeping goes through the `evo_*` MCP tools.
6
+ Never manually track population state — always call the tool.
7
+
8
+ - `evo_init` — call once at the start to initialize evolution state
9
+ - `evo_register_targets` — register optimization targets identified by code analysis
10
+ - `evo_next_batch` — get the next set of branch operations to execute
11
+ - `evo_report_fitness` — report benchmark results back after evaluation
12
+ - `evo_select_survivors` — run selection algorithm, get keep/eliminate lists
13
+ - `evo_get_status` — check current evolution progress
14
+ - `evo_get_lineage` — trace how a branch evolved
15
+ - `evo_freeze_target` / `evo_boost_target` — manual priority control
16
+
17
+ ## Git operations
18
+
19
+ Use `exec` to run git commands directly. Key patterns:
20
+ - `git worktree add <path> <branch>` — create isolated evaluation directory
21
+ - `git worktree remove <path>` — clean up after evaluation
22
+ - `git checkout -b <branch>` — create variant branch
23
+ - `git diff <a>..<b>` — compare two variants (feed to reflection)
24
+ - `git cherry-pick` — combine best parts from different branches
25
+
26
+ ## Code operations
27
+
28
+ Use `read` / `edit` / `write` for code changes. Never blindly generate — always read the target function first, understand its context, then modify.
29
+
30
+ ## Benchmark
31
+
32
+ Use `exec` to run the user's benchmark command inside a worktree. Always capture both stdout and stderr.
@@ -0,0 +1,103 @@
1
+ """Data models for evolution state."""
2
+
3
+ from __future__ import annotations
4
+ from enum import Enum
5
+ from pydantic import BaseModel, Field
6
+ from typing import Optional
7
+ import time
8
+
9
+
10
+ class Objective(str, Enum):
11
+ MIN = "min"
12
+ MAX = "max"
13
+
14
+
15
+ class Operation(str, Enum):
16
+ MUTATE = "mutate"
17
+ CROSSOVER = "crossover"
18
+ SYNERGY = "synergy"
19
+
20
+
21
+ class TargetStatus(str, Enum):
22
+ ACTIVE = "active"
23
+ FROZEN = "frozen"
24
+
25
+
26
+ class Target(BaseModel):
27
+ """An optimization target (a function to evolve)."""
28
+ id: str
29
+ file: str
30
+ function: str
31
+ lines: str = ""
32
+ impact: str = "medium"
33
+ description: str = ""
34
+ status: TargetStatus = TargetStatus.ACTIVE
35
+ temperature: float = 1.0 # explore/exploit control
36
+ current_best_obj: Optional[float] = None
37
+ current_best_branch: Optional[str] = None
38
+ stagnation_count: int = 0 # generations without improvement
39
+
40
+
41
+ class Individual(BaseModel):
42
+ """A single code variant living on a git branch."""
43
+ branch: str
44
+ generation: int
45
+ target_id: str
46
+ operation: Operation
47
+ parent_branches: list[str] = Field(default_factory=list)
48
+ fitness: Optional[float] = None
49
+ success: bool = False
50
+ code_hash: Optional[str] = None
51
+ raw_output: Optional[str] = None
52
+ timestamp: float = Field(default_factory=time.time)
53
+
54
+
55
+ class BatchItem(BaseModel):
56
+ """A single operation to execute in the next batch."""
57
+ branch: str
58
+ operation: Operation
59
+ target_id: str
60
+ parent_branches: list[str]
61
+ target_file: str
62
+ target_function: str
63
+
64
+
65
+ class SurvivorResult(BaseModel):
66
+ """Result of selection: who lives, who dies."""
67
+ keep: list[str]
68
+ eliminate: list[str]
69
+ best_branch: str
70
+ best_obj: float
71
+
72
+
73
+ class EvolutionConfig(BaseModel):
74
+ """Configuration for an evolution run."""
75
+ repo_path: str
76
+ benchmark_cmd: str
77
+ objective: Objective = Objective.MIN
78
+ max_fe: int = 500
79
+ pop_size: int = 8
80
+ mutation_rate: float = 0.5
81
+ synergy_interval: int = 3
82
+ top_k_survive: int = 5
83
+ quick_cmd: Optional[str] = None
84
+
85
+
86
+ class EvolutionState(BaseModel):
87
+ """Full state of an evolution run, persisted to disk."""
88
+ config: EvolutionConfig
89
+ generation: int = 0
90
+ total_evals: int = 0
91
+ seed_obj: Optional[float] = None
92
+ seed_branch: str = "seed-baseline"
93
+ best_obj_overall: Optional[float] = None
94
+ best_branch_overall: Optional[str] = None
95
+ targets: dict[str, Target] = Field(default_factory=dict)
96
+ # All individuals ever created, keyed by branch name
97
+ individuals: dict[str, Individual] = Field(default_factory=dict)
98
+ # Active branches per target (alive in current population)
99
+ active_branches: dict[str, list[str]] = Field(default_factory=dict)
100
+ # Fitness cache: code_hash -> fitness
101
+ fitness_cache: dict[str, float] = Field(default_factory=dict)
102
+ # Synergy records
103
+ synergy_records: list[dict] = Field(default_factory=list)
@@ -0,0 +1,16 @@
1
+ [project]
2
+ name = "openclaw-evo-engine"
3
+ version = "0.1.0"
4
+ description = "MCP server for Evo-anything evolutionary algorithm bookkeeping"
5
+ requires-python = ">=3.11"
6
+ dependencies = [
7
+ "mcp>=1.0",
8
+ "pydantic>=2.0",
9
+ ]
10
+
11
+ [project.scripts]
12
+ evo-engine = "server:main"
13
+
14
+ [build-system]
15
+ requires = ["hatchling"]
16
+ build-backend = "hatchling.build"