Files
dingoandClaude Opus 5.5 c183021fd5
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
feat(biology): genome schema 7 traits, founder 6 and development 7
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>
2026-10-22 18:09:06 -04:00

108 lines
6.1 KiB
C++

#pragma once
#include "evo/accounting/ledger.hpp"
#include "evo/biology/genome.hpp"
namespace evo::biology {
// What an organism has actually built and lost. Runtime state, never written
// back into the genome: heredity must not carry acquired condition.
struct GrowthState {
std::uint32_t realized_per_thousand{};
std::uint32_t damage_per_thousand{};
auto operator<=>(const GrowthState&) const = default;
};
struct EnvironmentState {
std::uint32_t temperature_millikelvin{};
// What is there to build from, per ledger channel. A single pool could not
// say that carbon is plentiful while nitrogen is not, which is the whole
// question once a body has a composition. Nothing here is spent or reserved.
accounting::Inventory available{};
auto operator<=>(const EnvironmentState&) const = default;
};
// Development version 1 is defined in ticks of this quantum: its per-tick constants and
// outputs, and the genome rates it reads (converted from per second, ADR-0099).
inline constexpr std::uint64_t development_v1_tick_microseconds = 50'000;
// Development version 2 (ADR-0099, M11.1) is defined per second: its rate constants and
// its rate outputs (maintenance, movement, ingestion) are per second.
inline constexpr std::uint64_t development_v2_rate_microseconds = 1'000'000;
// The period a development version's rates are per (phenotype maintenance, movement and
// ingestion; budget rates): 50 ms for version 1, one second for version 2; 0 when the
// version is unknown. Phenotypes are replicated unchanged, so the period is not a field
// of them: it follows from the genome's development version.
[[nodiscard]] constexpr std::uint64_t
development_rate_microseconds(std::uint32_t development_version) noexcept {
return development_version == 1 ? development_v1_tick_microseconds
: development_version >= 2 && development_version <= 7
? development_v2_rate_microseconds // Versions 3-7 keep version 2's rates.
: 0;
}
// Development version 7 (ADR-0179): region-declared body tuning. Upkeep is an essential
// share of the mass-based upkeep that no trait reduces, plus the rest divided by the
// genome's upkeep efficiency. Earlier versions ignore it.
struct BodyTuning {
std::uint32_t essential_upkeep_per_thousand{250}; // Trial (ADR-0179).
auto operator<=>(const BodyTuning&) const = default;
};
inline constexpr BodyTuning default_body_tuning{};
// Chosen constants, reviewable as a unit and selected by the genome's
// development version. Declared model parameters, not balance.
struct DevelopmentRules {
std::uint64_t structure_density; // femtograms per cubic micrometre
std::uint64_t membrane_density; // femtograms per cubic micrometre
std::uint64_t maintenance_per_kilogram; // picojoules per rate period per 1000 fg
std::uint64_t membrane_upkeep_per_kilo; // picojoules per rate period per 1000 fg
std::uint64_t construction_per_kilogram; // picojoules per 1000 fg built
std::uint64_t reference_surface; // square micrometres
std::uint32_t reference_temperature; // millikelvin
std::uint32_t growth_step_per_thousand; // most one plan may advance
};
// Dimensioned parameters derived from a genome and its runtime state. A derived
// phenotype is not a viability claim and holds no fitness score.
struct Phenotype {
std::uint64_t structural_mass{}; // femtograms
std::uint64_t membrane_mass{}; // femtograms
std::uint64_t total_mass{}; // femtograms
std::uint32_t extent{}; // micrometres, the cube-model side length
std::uint64_t surface{}; // square micrometres
std::uint64_t maintenance{}; // picojoules per rate period
std::uint32_t movement_speed{}; // micrometres per rate period; zero without the capability
std::uint64_t ingestion_rate{}; // femtograms per rate period; zero without the capability
std::uint32_t conversion_per_thousand{};
// Millikelvin beyond the genome's tolerance. A reported quantity, not a rule.
std::uint32_t thermal_shortfall{};
auto operator<=>(const Phenotype&) const = default;
};
// Development version 5 (ADR-0175; trial values): photosynthetic organelles are membrane
// built inside the cell. At efficiency p per thousand they add p/4 of the structural mass
// as membrane mass (so they are upkept twice, like membrane) and slow movement by p/2 per
// thousand. Light itself is captured by the region's environment owner, never here.
// Version 7 keeps the organelle mass but drops the speed penalty: mass slows the cell.
inline constexpr std::uint32_t photosynthesis_organelle_quarter = 4;
inline constexpr std::uint32_t photosynthesis_speed_halving = 2;
// A proposal. It reserves nothing, pays for nothing and commits nothing; the
// matching transfer does not exist until M3.3.
struct DevelopmentPlan {
GrowthState after{};
std::uint64_t material_required{};
std::uint64_t energy_required{};
auto operator<=>(const DevelopmentPlan&) const = default;
};
enum class DevelopmentError : std::uint8_t { unsupported_rules, invalid_growth, overflow };
[[nodiscard]] std::expected<DevelopmentRules, DevelopmentError>
rules_for(std::uint32_t development_version);
// Pure: a phenotype is recomputed from retained inputs rather than cached, so a
// cached copy can always be checked against a recomputation.
[[nodiscard]] std::expected<Phenotype, DevelopmentError>
derive_phenotype(const Genome& genome, GrowthState growth, EnvironmentState environment,
const BodyTuning& tuning = default_body_tuning);
// Advances realized growth toward the target by at most the rule step, reduced to
// the largest step the available mass and energy admit. This bounds by total mass
// only: it cannot see which elements a step consumes, so it is a proposal and not
// an affordability authority. `metabolic_budget` decides that, per channel, and
// can only narrow this further. Never repairs damage.
[[nodiscard]] std::expected<DevelopmentPlan, DevelopmentError>
plan_development(const Genome& genome, GrowthState growth, EnvironmentState environment,
const BodyTuning& tuning = default_body_tuning);
} // namespace evo::biology