feat(biology): genome schema 7 traits, founder 6 and development 7
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m27s
Foundation / postgres-tools (push) Successful in 33s
Foundation / server-image (push) Successful in 4m14s
Foundation / image (push) Successful in 4m41s

Phase 1 of the cellular revamp build plan (ADR-0179). Genome schema 7 carries
twenty 16-bit cellular traits after the movement arrangement: density, upkeep
efficiency, growth speed, collection per channel (E/C/N/P/O), burn efficiency
per matter channel, engulf capacity, kill absorption, litter, the body recipe
(C/N/P/O per thousand, summing to 1000) and adhesion. Its membrane is held in
nanometres so it can change in 5% steps of the founder's 1 um. The largest
record still fits the 256-byte bound.

Development 7 and founder 6 serve rules 13: density sets how large a body is
for its mass, the recipe sets the body's composition (intake keeps the founder
shares), upkeep is an essential share no trait reduces plus the rest over upkeep
efficiency (region-declared BodyTuning, trial 25%), the producer speed penalty
is dropped, and the reproduction value is the bud's share of the body with the
construction discount fixed at the founder's level. Founder 6 builds exactly
founder 5's cell. Earlier schemas and development versions are unchanged.

The development and metabolism test mains now print the failing line. Refreshes
the DEV session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-22 18:09:06 -04:00
co-authored by Claude Opus 5.5
parent 0a5cf3e6bd
commit c183021fd5
13 changed files with 389 additions and 42 deletions
+41 -11
View File
@@ -72,14 +72,18 @@ std::expected<DevelopmentRules, DevelopmentError> rules_for(std::uint32_t develo
// Version 5 (ADR-0175) keeps them too; it adds photosynthetic organelles below.
// Version 6 (rules 12) keeps version 5's body; handling comes from the genome's movement
// arrangement (derive_cellular_handling).
if (development_version >= 3 && development_version <= 6) {
// Version 7 (rules 13, ADR-0179) keeps the constants; the genome's cellular traits set
// density, recipe and upkeep efficiency, and the membrane is in nanometres.
if (development_version >= 3 && development_version <= 7) {
return DevelopmentRules{1000, 1200, 10, 15, 13, 60'000, 293'150, 50};
}
return std::unexpected{DevelopmentError::unsupported_rules};
}
std::expected<Phenotype, DevelopmentError>
derive_phenotype(const Genome& genome, GrowthState growth, EnvironmentState environment) {
std::expected<Phenotype, DevelopmentError> derive_phenotype(const Genome& genome,
GrowthState growth,
EnvironmentState environment,
const BodyTuning& tuning) {
if (growth.realized_per_thousand > thousand || growth.damage_per_thousand > thousand) {
return std::unexpected{DevelopmentError::invalid_growth};
}
@@ -87,13 +91,23 @@ derive_phenotype(const Genome& genome, GrowthState growth, EnvironmentState envi
if (!rules) {
return std::unexpected{rules.error()};
}
// Version 7 reads the schema-7 traits; a version-7 genome without them is unsupported.
const bool v7 = genome.development_version() >= 7;
const auto& traits = genome.cellular_traits();
if (v7 != traits.has_value() || tuning.essential_upkeep_per_thousand > thousand) {
return std::unexpected{DevelopmentError::unsupported_rules};
}
Phenotype phenotype;
// target_size, membrane and energy_conversion are required by schema 1.
const auto target = *genome.parameter(Capability::target_size);
const auto built = scaled(target, growth.realized_per_thousand);
phenotype.structural_mass = scaled(built, thousand - growth.damage_per_thousand);
phenotype.extent = static_cast<std::uint32_t>(
integer_cube_root(phenotype.structural_mass / rules->structure_density));
// Version 7: density scales how tightly that mass packs, so a denser body is smaller.
const auto density =
v7 ? std::max<std::uint64_t>(1, rules->structure_density * traits->density / 100)
: rules->structure_density;
phenotype.extent =
static_cast<std::uint32_t>(integer_cube_root(phenotype.structural_mass / density));
std::uint64_t face{};
if (!multiply(face, phenotype.extent, phenotype.extent) ||
!multiply(phenotype.surface, face, 6)) {
@@ -104,6 +118,10 @@ derive_phenotype(const Genome& genome, GrowthState growth, EnvironmentState envi
!multiply(phenotype.membrane_mass, shell, rules->membrane_density)) {
return std::unexpected{DevelopmentError::overflow};
}
// Version 7 holds the membrane in nanometres: the same mass at 1,000 nm as at 1 um.
if (v7) {
phenotype.membrane_mass /= thousand;
}
const auto photosynthesis =
genome.development_version() >= 5 && genome.carries(Capability::photosynthesis)
? *genome.parameter(Capability::photosynthesis)
@@ -122,6 +140,15 @@ derive_phenotype(const Genome& genome, GrowthState growth, EnvironmentState envi
scaled(phenotype.membrane_mass, rules->membrane_upkeep_per_kilo))) {
return std::unexpected{DevelopmentError::overflow};
}
// Version 7: an essential share no trait reduces, plus the rest over upkeep efficiency.
if (v7) {
const auto essential = scaled(phenotype.maintenance, tuning.essential_upkeep_per_thousand);
std::uint64_t adjustable{};
if (!multiply(adjustable, phenotype.maintenance - essential, 100)) {
return std::unexpected{DevelopmentError::overflow};
}
phenotype.maintenance = essential + adjustable / traits->upkeep_efficiency;
}
phenotype.conversion_per_thousand =
static_cast<std::uint32_t>(*genome.parameter(Capability::energy_conversion));
// A capability the genome does not carry yields nothing, whatever the size.
@@ -137,8 +164,9 @@ derive_phenotype(const Genome& genome, GrowthState growth, EnvironmentState envi
if (!speed || *speed > std::numeric_limits<std::uint32_t>::max()) {
return std::unexpected{DevelopmentError::overflow};
}
// Organelles slow the cell: p/2 per thousand off its speed (version 5).
const auto kept = thousand - photosynthesis / photosynthesis_speed_halving;
// Organelles slow the cell: p/2 per thousand off its speed (versions 5 and 6). Version 7
// drops this: organelle mass slows the cell through its handling instead.
const auto kept = v7 ? thousand : thousand - photosynthesis / photosynthesis_speed_halving;
phenotype.movement_speed = static_cast<std::uint32_t>(scaled(*speed, kept));
}
if (genome.carries(Capability::ingestion)) {
@@ -159,9 +187,11 @@ derive_phenotype(const Genome& genome, GrowthState growth, EnvironmentState envi
return phenotype;
}
std::expected<DevelopmentPlan, DevelopmentError>
plan_development(const Genome& genome, GrowthState growth, EnvironmentState environment) {
const auto current = derive_phenotype(genome, growth, environment);
std::expected<DevelopmentPlan, DevelopmentError> plan_development(const Genome& genome,
GrowthState growth,
EnvironmentState environment,
const BodyTuning& tuning) {
const auto current = derive_phenotype(genome, growth, environment, tuning);
if (!current) {
return std::unexpected{current.error()};
}
@@ -179,7 +209,7 @@ plan_development(const Genome& genome, GrowthState growth, EnvironmentState envi
for (std::uint32_t attempt = step; attempt > 0; --attempt) {
auto proposed = growth;
proposed.realized_per_thousand += attempt;
const auto grown = derive_phenotype(genome, proposed, environment);
const auto grown = derive_phenotype(genome, proposed, environment, tuning);
if (!grown) {
return std::unexpected{grown.error()};
}
+5 -1
View File
@@ -11,14 +11,18 @@ std::expected<Genome, GenomeError> primitive_founder(std::uint64_t id, std::uint
draft.id = id;
draft.origin_event = origin_event;
draft.development_version = version.development_version;
const auto membrane =
version.genome_schema >= genome_schema_v7 ? founder_membrane_nanometres : p.membrane;
draft.capabilities = {{Capability::energy_conversion, p.energy_conversion, 0},
{Capability::membrane, p.membrane, 0},
{Capability::membrane, membrane, 0},
{Capability::movement, p.movement, 0},
{Capability::ingestion, p.ingestion, 0},
{Capability::reproduction, p.reproduction, 0},
{Capability::target_size, p.target_size, 0}};
if (version.genome_schema >= genome_schema_v6)
draft.movement_arrangement = founder_movement_arrangement;
if (version.genome_schema >= genome_schema_v7)
draft.cellular_traits = founder_cellular_traits;
return Genome::create(draft);
}
+64 -3
View File
@@ -17,9 +17,56 @@ constexpr std::size_t checksum_size = 8;
constexpr std::size_t arrangement_count = 9;
constexpr std::size_t arrangement_size = arrangement_count * 2;
// Schema 7: twenty 16-bit cellular traits after the arrangement.
constexpr std::size_t trait_count = 20;
constexpr std::size_t traits_size = trait_count * 2;
bool has_arrangement(std::uint32_t schema) noexcept {
return schema >= genome_schema_v6;
}
bool has_traits(std::uint32_t schema) noexcept {
return schema >= genome_schema_v7;
}
std::array<std::uint16_t, trait_count> trait_values(const CellularTraits& t) noexcept {
return {t.density, t.upkeep_efficiency, t.growth_speed, t.collection[0],
t.collection[1], t.collection[2], t.collection[3], t.collection[4],
t.burn[0], t.burn[1], t.burn[2], t.burn[3],
t.engulf_capacity, t.kill_absorption, t.litter, t.recipe[0],
t.recipe[1], t.recipe[2], t.recipe[3], t.adhesion};
}
CellularTraits traits_from(const std::array<std::uint16_t, trait_count>& v) noexcept {
return {v[0], v[1], v[2], {v[3], v[4], v[5], v[6], v[7]}, {v[8], v[9], v[10], v[11]},
v[12], v[13], v[14], {v[15], v[16], v[17], v[18]}, v[19]};
}
// Required from schema 7 and refused before it. Every index is 1 to 1,000 points; litter
// is bounded; each recipe share is at least 1 and they sum to 1000; adhesion is a flag.
bool valid_traits(std::uint32_t schema, const std::optional<CellularTraits>& traits) noexcept {
if (!has_traits(schema))
return !traits.has_value();
if (!traits)
return false;
const auto& t = *traits;
const auto index = [](std::uint16_t value) { return value >= 1 && value <= max_trait_points; };
if (!index(t.density) || !index(t.upkeep_efficiency) || !index(t.growth_speed) ||
!index(t.engulf_capacity) || !index(t.kill_absorption))
return false;
for (const auto value : t.collection)
if (!index(value))
return false;
for (const auto value : t.burn)
if (!index(value))
return false;
if (t.litter > max_litter || t.adhesion > 1)
return false;
std::uint32_t recipe{};
for (const auto share : t.recipe) {
if (share == 0)
return false;
recipe += share;
}
return recipe == 1000;
}
std::array<std::uint16_t, arrangement_count> indices(const MovementArrangement& a) noexcept {
return {a.output, a.efficiency, a.burst, a.steering, a.streamlining,
@@ -204,6 +251,9 @@ std::vector<std::uint8_t> Genome::body() const {
if (movement_arrangement_)
for (const auto value : indices(*movement_arrangement_))
append(bytes, value, 2);
if (cellular_traits_)
for (const auto value : trait_values(*cellular_traits_))
append(bytes, value, 2);
return bytes;
}
@@ -226,7 +276,8 @@ std::expected<Genome, GenomeError> Genome::create(const GenomeDraft& draft) {
!valid) {
return std::unexpected{valid.error()};
}
if (!valid_arrangement(draft.schema_version, draft.movement_arrangement)) {
if (!valid_arrangement(draft.schema_version, draft.movement_arrangement) ||
!valid_traits(draft.schema_version, draft.cellular_traits)) {
return std::unexpected{GenomeError::parameter_out_of_range};
}
Genome genome;
@@ -237,6 +288,7 @@ std::expected<Genome, GenomeError> Genome::create(const GenomeDraft& draft) {
genome.parents_ = draft.parents;
genome.capabilities_ = std::move(ordered);
genome.movement_arrangement_ = draft.movement_arrangement;
genome.cellular_traits_ = draft.cellular_traits;
genome.digest_ = digest_of(genome.body());
return genome;
}
@@ -278,8 +330,9 @@ std::expected<Genome, GenomeError> Genome::decode(std::span<const std::uint8_t>
}
// An exact length match rejects trailing bytes rather than ignoring them.
const auto arrangement_bytes = has_arrangement(schema) ? arrangement_size : 0;
const auto trait_bytes = has_traits(schema) ? traits_size : 0;
const auto expected = counted + static_cast<std::size_t>(record_count) * record_size +
arrangement_bytes + digest_size + checksum_size;
arrangement_bytes + trait_bytes + digest_size + checksum_size;
if (bytes.size() != expected) {
return std::unexpected{GenomeError::invalid_encoding};
}
@@ -306,11 +359,18 @@ std::expected<Genome, GenomeError> Genome::decode(std::span<const std::uint8_t>
arrangement = MovementArrangement{read[0], read[1], read[2], read[3], read[4],
read[5], read[6], read[7], read[8]};
}
std::optional<CellularTraits> traits;
if (has_traits(schema)) {
std::array<std::uint16_t, trait_count> read{};
for (auto& value : read)
value = static_cast<std::uint16_t>(reader.read(2));
traits = traits_from(read);
}
if (const auto valid = validate(schema, id, origin, development, parents, capabilities);
!valid) {
return std::unexpected{valid.error()};
}
if (!valid_arrangement(schema, arrangement)) {
if (!valid_arrangement(schema, arrangement) || !valid_traits(schema, traits)) {
return std::unexpected{GenomeError::parameter_out_of_range};
}
Genome genome;
@@ -321,6 +381,7 @@ std::expected<Genome, GenomeError> Genome::decode(std::span<const std::uint8_t>
genome.parents_ = std::move(parents);
genome.capabilities_ = std::move(capabilities);
genome.movement_arrangement_ = arrangement;
genome.cellular_traits_ = traits;
// The body must reproduce exactly, so a rewritten record is rejected.
const auto digest = digest_of(genome.body());
if (digest != reader.read(digest_size)) {
+22 -11
View File
@@ -109,8 +109,9 @@ metabolic_rules_for(std::uint32_t development_version) {
return MetabolicRules{structure_shares, membrane_shares, 20, 50'000};
}
// Version 2: per second; movement at 1000 um/s costs 50 pJ/s per 1000 fg (tunable).
// Versions 3 to 6: the same metabolism.
if (development_version >= 2 && development_version <= 6) {
// Versions 3 to 7: the same metabolism. Version 7 reads the body's structure recipe from
// the genome's cellular traits instead (ADR-0179); intake keeps these founder shares.
if (development_version >= 2 && development_version <= 7) {
return MetabolicRules{structure_shares, membrane_shares, 50, 50'000};
}
return std::unexpected{DevelopmentError::unsupported_rules};
@@ -118,8 +119,8 @@ metabolic_rules_for(std::uint32_t development_version) {
std::expected<MetabolicBudget, DevelopmentError>
metabolic_budget(const Genome& genome, GrowthState growth, EnvironmentState environment,
std::uint32_t max_growth_per_thousand) {
const auto phenotype = derive_phenotype(genome, growth, environment);
std::uint32_t max_growth_per_thousand, const BodyTuning& tuning) {
const auto phenotype = derive_phenotype(genome, growth, environment, tuning);
if (!phenotype) {
return std::unexpected{phenotype.error()};
}
@@ -131,12 +132,17 @@ metabolic_budget(const Genome& genome, GrowthState growth, EnvironmentState envi
if (!shape) {
return std::unexpected{shape.error()};
}
// The heritable recipe (version 7) or the version's fixed structure shares.
const auto& traits = genome.cellular_traits();
const Composition structure = traits ? Composition{traits->recipe[0], traits->recipe[1],
traits->recipe[2], traits->recipe[3]}
: rules->structure;
MetabolicBudget budget;
budget.phenotype = *phenotype;
budget.rate_microseconds = development_rate_microseconds(genome.development_version());
budget.assimilation_per_thousand =
static_cast<std::uint16_t>(phenotype->conversion_per_thousand);
budget.body = compose(phenotype->structural_mass, rules->structure);
budget.body = compose(phenotype->structural_mass, structure);
if (!combine(budget.body, compose(phenotype->membrane_mass, rules->membrane))) {
return std::unexpected{DevelopmentError::overflow};
}
@@ -155,7 +161,7 @@ metabolic_budget(const Genome& genome, GrowthState growth, EnvironmentState envi
budget.intake_limit = compose(phenotype->ingestion_rate, rules->structure);
budget.intake_limit.energy.value =
scaled(phenotype->ingestion_rate, rules->intake_energy_per_kilogram);
const auto plan = plan_development(genome, growth, environment);
const auto plan = plan_development(genome, growth, environment, tuning);
if (!plan) {
return std::unexpected{plan.error()};
}
@@ -169,7 +175,7 @@ metabolic_budget(const Genome& genome, GrowthState growth, EnvironmentState envi
--attempt) {
const GrowthState candidate{growth.realized_per_thousand + attempt,
growth.damage_per_thousand};
const auto grown = derive_phenotype(genome, candidate, environment);
const auto grown = derive_phenotype(genome, candidate, environment, tuning);
if (!grown) {
return std::unexpected{grown.error()};
}
@@ -178,7 +184,7 @@ metabolic_budget(const Genome& genome, GrowthState growth, EnvironmentState envi
// body already carries, and the budget could not then reproduce the
// derived body channel by channel. Each compartment is still composed
// separately: the two differ in what they cost.
auto reached = compose(grown->structural_mass, rules->structure);
auto reached = compose(grown->structural_mass, structure);
if (!combine(reached, compose(grown->membrane_mass, rules->membrane))) {
return std::unexpected{DevelopmentError::overflow};
}
@@ -209,15 +215,20 @@ metabolic_budget(const Genome& genome, GrowthState growth, EnvironmentState envi
// Version 4 (ADR-0137): a bud is always half the body, and reproduction is skill:
// it takes up to half off the bud's construction energy (value / 2000). Matter is
// never discounted (ADR-0118). Earlier versions invest `value` per thousand.
const bool skill = genome.development_version() >= 4; // Versions 4 to 6.
const auto fraction = skill ? bud_body_per_thousand_v4 : value;
// Version 7 (ADR-0179): `value` is again the bud's share of the body, and keeps the
// skill discount at the founder's 500.
const bool skill = genome.development_version() >= 4;
const bool share = genome.development_version() >= 7;
const auto fraction = share || !skill ? value : bud_body_per_thousand_v4;
// A parent divides the body it has, so the investment keeps its composition.
budget.reproduction_investment = fraction_of(budget.body, fraction);
// Offspring tissue is priced at what the parent's own tissue costs.
const auto construction =
scaled(matter_total(budget.reproduction_investment), shape->construction_per_kilogram);
// Discount = construction * skill / 2000, split to stay within 64 bits.
const std::uint64_t level = std::min<std::uint32_t>(value, 1000);
// Version 7 fixes the discount at the founder's level, so bigger buds are not cheaper.
const std::uint64_t level =
share ? primitive_bud_skill_v7 : std::min<std::uint32_t>(value, 1000);
const auto discount = construction / 2000 * level + construction % 2000 * level / 2000;
budget.reproduction_investment.energy.value =
skill ? construction - discount : construction;
+2 -1
View File
@@ -39,7 +39,7 @@ constexpr std::array<MutationOperator, 4 * capability_count> catalog = [] {
constexpr std::uint32_t adjustment_step(const std::array<CapabilitySpec, capability_count>& table,
Capability kind, std::uint32_t schema,
std::uint32_t current) noexcept {
if (schema == genome_schema_v4 || schema == genome_schema_v5 || schema == genome_schema_v6)
if (schema >= genome_schema_v4)
return current / 10 == 0 ? 1 : current / 10;
const auto& limits = table[static_cast<std::size_t>(kind)];
const auto span = limits.maximum - limits.minimum;
@@ -104,6 +104,7 @@ std::optional<GenomeDraft> apply(const Genome& genome, const MutationOperator& e
draft.parents = {genome.id()};
draft.capabilities.assign(genome.capabilities().begin(), genome.capabilities().end());
draft.movement_arrangement = genome.movement_arrangement();
draft.cellular_traits = genome.cellular_traits();
const auto& table = *capability_schema_for(genome.schema_version());
const auto& limits = table[static_cast<std::size_t>(entry.target)];
const auto carried =