Skip to content

feat: Mutator — LLM-driven mutation with failure cases + learning log (#153)#418

Open
yxlyx wants to merge 1 commit intomainfrom
feat/153-mutator
Open

feat: Mutator — LLM-driven mutation with failure cases + learning log (#153)#418
yxlyx wants to merge 1 commit intomainfrom
feat/153-mutator

Conversation

@yxlyx
Copy link
Copy Markdown
Collaborator

@yxlyx yxlyx commented Apr 10, 2026

Summary

  • Organism struct: code-patch candidate with id, parent_id, generation, explanation, diff, fitness, problem_hash
  • FailureCase struct: test_name + snippet from evaluation
  • buildMutationPrompt(): Constructs a bounded prompt with:
    • Problem statement (truncated to 1000 chars)
    • Parent solution explanation (500 chars) and diff (3000 chars)
    • Test failures (max 5 entries, 200 chars each)
    • Learning history (max 2000 chars)
    • Instruction template requesting EXPLANATION + DIFF format
  • parseMutationResponse(): Extracts EXPLANATION and DIFF sections, strips ```diff fences, returns null on malformed
  • Mutator.mutate(): Wires prompt building + parsing; placeholder for LLM call pending API integration

Test plan

  • zig test src/evolver.zig — 26/26 tests pass
  • buildMutationPrompt: contains all sections (problem, explanation, failures, history, instructions)
  • buildMutationPrompt: truncates long inputs within bounds
  • buildMutationPrompt: omits sections when failures/history empty
  • parseMutationResponse: valid response with code fence
  • parseMutationResponse: valid response without code fence
  • parseMutationResponse: returns null when markers missing
  • parseMutationResponse: returns null when diff is empty
  • Mutator.mutate: child has incremented generation, correct parent_id

Closes #153

Made with Cursor

…#153)

Adds Organism struct, FailureCase struct, and Mutator to evolver.zig:
- Organism: code-patch candidate with id, parent lineage, explanation, diff, fitness
- FailureCase: test name + snippet from evaluation
- buildMutationPrompt(): constructs bounded prompt with problem, parent
  solution, test failures (max 5), and learning history (max 2000 chars)
- parseMutationResponse(): extracts EXPLANATION and DIFF sections from LLM
  output, strips ```diff fences, returns null on malformed responses
- Mutator.mutate(): wires prompt building + response parsing; placeholder
  for actual LLM call pending API integration

8 new tests covering prompt construction (all sections, truncation, empty),
response parsing (valid, no markers, empty diff, no fence), and Mutator
offspring generation tracking.
All 26 evolver tests pass.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

evolver.zig: Mutator — LLM-driven mutation with failure cases + learning log

1 participant