/genetic-evolve

Evolution L3 Production medium usage

/genetic-evolve

Overview

/genetic-evolve is a production command in the Evolution category of the Prismatic Platform that applies genetic algorithm principles to systematically improve platform quality across three critical dimensions: type specification coverage (@spec), test coverage, and documentation completeness (@doc/@moduledoc). Rather than relying on manual identification of improvement targets, this command treats quality improvement as an optimization problem and applies evolutionary strategies to converge on maximum coverage across the entire codebase.

The command operates under the L3 authority level and is executed by the evolution-orchestrator agent. It is part of the platform's 216-command slash command registry, built on the AIAD (Autonomous Intelligence Agent Design) standard. The L3 authority level grants the evolution-orchestrator the ability to create and modify files across the platform, subject to quality gate validation before any changes are committed.

The genetic evolution metaphor is implemented literally: quality improvements are treated as a population of candidate changes, each evaluated for fitness against the platform's quality metrics. The fittest candidates -- those that improve coverage metrics without introducing regressions -- survive and are applied, while ineffective candidates are discarded. Over successive generations, this process converges on optimal coverage across all three dimensions.

The platform's current quality score of 100/100 with zero violations across 13 quality domains is the direct result of sustained genetic evolution across 18 generations. The /genetic-evolve command is the operational tool that drove this improvement, starting from Gen 1's initial quality baseline and progressively eliminating quality debt through targeted, measured evolution cycles.

Architecture

The genetic evolution engine implements a classic evolutionary algorithm adapted for software quality optimization.

Population Init --> Fitness Evaluation --> Selection --> Mutation --> Quality Gate --> Integration
       |                  |                   |            |              |               |
  Candidate           Metric              Tournament    Generate      Compile +       Apply to
  Improvements        Collection          Selection     Variants      Test + Credo     Codebase
       |                  |                                               |
  Seed from          @spec coverage                                 Pass/Fail
  Quality Scans      Test coverage                                  Filter
                     Doc coverage

Evolutionary Components

ComponentRoleImplementation
PopulationCandidate improvementsList of {file, improvement_type, proposed_change} tuples
Fitness FunctionQuality measurementComposite score: spec_coverage * 0.4 + test_coverage * 0.35 + doc_coverage * 0.25
SelectionChoose best candidatesTournament selection (k=3) with elitism (top 10% always survive)
MutationGenerate variantsRandom parameter variation within type-safe bounds
CrossoverCombine strategiesMerge successful patterns from different quality dimensions
Quality GateValidationFull compilation + Credo + Dialyzer must pass

Fitness Dimensions

DimensionWeightMetricCurrent Platform Score
Spec Coverage40%Percentage of public functions with @spec100% (709 @impl)
Test Coverage35%Line coverage from mix test --cover100% across quality domains
Doc Coverage25%Percentage of public functions with @doc/@moduledoc100% (11,308 docs)

Usage

Basic Usage

# Run a single generation of genetic evolution
/genetic-evolve

# Target a specific quality dimension
/genetic-evolve --target spec-coverage

# Target a specific umbrella application
/genetic-evolve --app prismatic_perimeter

# Run multiple generations
/genetic-evolve --generations 5

Targeted Evolution

# Focus on test coverage for a specific app
/genetic-evolve --target test-coverage --app prismatic_web

# Focus on documentation completeness
/genetic-evolve --target documentation --min-fitness 0.95

# Evolve only modules below a coverage threshold
/genetic-evolve --target spec-coverage --below-threshold 80

# Evolve with specific population size
/genetic-evolve --population 50 --generations 3

Advanced Evolution

# Multi-objective evolution across all dimensions
/genetic-evolve --target all --generations 10 --report

# Evolution with custom fitness weights
/genetic-evolve --weight-spec 0.5 --weight-test 0.3 --weight-doc 0.2

# Dry-run evolution showing proposed changes
/genetic-evolve --dry-run --target spec-coverage --app prismatic_api

# Export evolution history as JSON
/genetic-evolve --history --format json --output evolution-report.json

Options & Parameters

OptionTypeDefaultDescription
--targetstringallEvolution target: spec-coverage, test-coverage, documentation, all
--appstringallTarget specific umbrella application
--generationsinteger1Number of evolution generations to run
--populationinteger30Population size per generation
--min-fitnessfloat0.80Minimum fitness threshold for candidate survival
--below-thresholdinteger100Only evolve modules below this coverage percentage
--weight-specfloat0.40Fitness weight for spec coverage
--weight-testfloat0.35Fitness weight for test coverage
--weight-docfloat0.25Fitness weight for documentation coverage
--dry-runbooleanfalseShow proposed changes without applying them
--reportbooleanfalseGenerate evolution report after completion
--historybooleanfalseShow evolution history across past sessions
--formatstringtableOutput format: table, json, markdown
--outputstringstdoutWrite results to file
--verbosebooleanfalseShow detailed evolution steps

Execution Flow

  1. Baseline Measurement: Measure current fitness across all three dimensions for the target scope. This establishes the starting point for evolution.

  2. Population Seeding: Generate the initial population of candidate improvements. Candidates are seeded from quality scan results, missing spec/doc analysis, and untested module detection.

  3. Fitness Evaluation: Evaluate each candidate's fitness by simulating the improvement and measuring the resulting coverage delta.

  4. Selection: Apply tournament selection to choose the fittest candidates for reproduction. The top 10% (elites) are always preserved.

  5. Mutation & Crossover: Generate new candidate variants through parameter mutation and strategy crossover. This introduces diversity into the population.

  6. Quality Gate Validation: Apply each selected candidate and validate through the full quality gate pipeline: mix compile --warnings-as-errors, mix credo --strict, and mix test.

  7. Integration: Candidates that pass all quality gates are integrated into the codebase. Failed candidates are discarded with their failure reasons logged.

  8. Generation Report: Summarize the generation's results: fitness improvement, candidates applied, candidates rejected, and current coverage levels.

  9. Iteration: If --generations > 1, repeat from step 2 with the improved codebase as the new baseline.

Integration Points

ComponentIntegration TypeDescription
Prismatic AgentsExecutionInvoked by evolution-orchestrator agent
Quality GatesValidationEvery evolved change must pass quality gates
CredoStatic AnalysisEvolved code must pass Credo strict mode
TelemetryMetricsEvolution metrics tracked as telemetry events
Quality DNAHistoryEvolution history persisted in quality DNA
SEADFFrameworkGenetic evolution is a component of the SEADF pipeline
/evolveParentPart of the broader evolution command family
/quality-gatesEnforcementQuality gates validate evolution outputs

Best Practices

Target one dimension at a time for focused improvement. While --target all provides multi-objective optimization, targeting a single dimension (spec-coverage, test-coverage, or documentation) produces more predictable and verifiable results per generation.

Use small populations for initial exploration. Start with --population 10 --generations 1 to understand what the evolution engine proposes before running larger campaigns. This is especially important when evolving unfamiliar applications.

Run evolution as part of session discipline. The platform's Universal Autonomous Evolution Protocol mandates evolution activity in every session. Use /genetic-evolve --generations 1 --target all as a lightweight evolution step that satisfies this requirement.

Monitor fitness convergence. Over successive generations, fitness should increase monotonically. If fitness plateaus, the remaining improvements may require manual intervention (complex architectural changes that the evolution engine cannot generate automatically).

Preserve evolution history for analysis. Use --report --format json to persist evolution results. Historical fitness trajectories reveal the platform's quality improvement velocity and identify areas where evolution has been most effective.

Error Handling

ErrorCauseResolution
{:error, :no_candidates}No improvement candidates found for the target scopeThe target scope may already be at 100% coverage; verify with quality gates
{:error, :quality_gate_failed}All candidates failed quality validationReview candidate proposals with --dry-run; some improvements may need manual refinement
{:error, :fitness_regression}Evolution produced a fitness decreaseThis should not happen with proper quality gating; investigate the fitness function
{:error, :compilation_failed}Generated code does not compileCheck for dependency issues; the evolution engine may need updated module context
{:error, :test_failure}Generated tests or existing tests failReview the failing test; the evolution may have exposed a pre-existing bug

Advanced Usage

Custom Fitness Functions

Define project-specific fitness criteria:

# Custom fitness function for security-critical code
fitness = fn module ->
  spec_score = PrismaticQuality.spec_coverage(module) * 0.50
  test_score = PrismaticQuality.test_coverage(module) * 0.30
  guard_score = PrismaticQuality.guard_clause_coverage(module) * 0.20
  spec_score + test_score + guard_score
end

Evolution Pipeline Integration

Chain evolution with other platform commands:

# Evolve, verify, and commit in a single workflow
/genetic-evolve --target spec-coverage --app prismatic_api && \
  mix compile --warnings-as-errors && \
  mix test apps/prismatic_api/ && \
  /commit "evolution: improve spec coverage for prismatic_api"

Cross-Generation Analysis

# Compare fitness across multiple sessions
/genetic-evolve --history --format json | \
  jq '[.generations[] | {gen: .number, fitness: .final_fitness}]'

Doctrine Compliance

All commands operate under the NO MERCY, NO DOUBTS doctrine:

  • NO MERCY: Zero tolerance for incomplete execution or quality violations. Every evolved change must pass the full quality gate pipeline. No partial improvements, no TODO placeholders, no quality regressions.
  • NO DOUBTS: Full investigation before action, evidence-based results. Fitness measurements provide quantitative evidence for every evolution decision. No changes are applied based on heuristic guesses.

The genetic evolution process is a direct implementation of the platform's Generation 1 through 18 evolution trajectory, which achieved 0.999 apex fitness through sustained, measured, evidence-based improvement -- the epitome of NO MERCY, NO DOUBTS in practice.


Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL