feat(cellular): session v14, bundle 15 and rules-13 wildlife
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m29s
Foundation / postgres-tools (push) Successful in 24s
Foundation / server-image (push) Successful in 4m33s
Foundation / image (push) Successful in 4m59s

Session v14 carries the rules-13 revamp: a body block in the owner's view
(members, emergence threshold, exclusions, Emerge open, payable energy,
mass and the 20 traits), become, emerge and channel exclusions on actions,
become on mutation choices, catalog offers (id, chance, cost) and the
emerged ending. Older sessions never see a v14 field. The client shows
Stay / Become offspring offers named from the shared catalog, continuing
as a bud, the organism and its Emerge button, kept channels, the body and
the emerged end screen.

Bundle 15 (rules 13 on owner format 11) is durable: schema 60 admits it
raw-only, stores become as bit 15 of the choice's operator, widens the
action input and mutation results, and publishes the 14 -> 15 revamp
profile migration. evo-world-clone opens cellular-v10 (cellular-v9 plus the
revamp upgrade from --revamp-tuning), resumable and recoverable.

Wildlife counts reserve matter as energy, waits for the bud fee, grows
organisms one short of emerging, and hunts by the region step's rules-13
engulf test. The play summary adds organisms, offers and the spent pool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-26 07:31:32 -04:00
co-authored by Claude Opus 5.5
parent f454e038a1
commit 4bc5d5eee7
48 changed files with 1602 additions and 174 deletions
+6 -6
View File
@@ -238,9 +238,9 @@ ActionReceipt IntentAdmission::action(std::uint64_t session, const CellularActio
const AdmissionFacts& facts) {
const SessionAction base{m.session, m.epoch, m.action_id,
static_cast<std::uint16_t>(ActionKind::cellular), m.tick};
const auto bytes =
encode_cellular_action_input({m.tick, m.move_x, m.move_y, m.has_intake_target,
m.intake_x_um, m.intake_y_um, m.engulf, m.bud, m.brake});
const auto bytes = encode_cellular_action_input(
{m.tick, m.move_x, m.move_y, m.has_intake_target, m.intake_x_um, m.intake_y_um, m.engulf,
m.bud, m.brake, m.become, m.emerge, m.exclude});
auto* s = find(session);
if (!s)
return {m.action_id, AdmitStatus::unknown_session, facts.server_tick, m.tick};
@@ -280,9 +280,9 @@ std::optional<ActionReceipt> IntentAdmission::admit(std::uint64_t session, const
const AdmissionFacts& facts) {
const SessionAction base{m.session, m.epoch, m.action_id,
static_cast<std::uint16_t>(ActionKind::cellular), m.tick};
const auto bytes =
encode_cellular_action_input({m.tick, m.move_x, m.move_y, m.has_intake_target,
m.intake_x_um, m.intake_y_um, m.engulf, m.bud, m.brake});
const auto bytes = encode_cellular_action_input(
{m.tick, m.move_x, m.move_y, m.has_intake_target, m.intake_x_um, m.intake_y_um, m.engulf,
m.bud, m.brake, m.become, m.emerge, m.exclude});
auto* s = find(session);
if (!s)
return ActionReceipt{m.action_id, AdmitStatus::unknown_session, facts.server_tick, m.tick};
+121 -23
View File
@@ -37,6 +37,12 @@ constexpr std::size_t cellular_perceived_producer_bytes = 8 + 2 + 6;
constexpr std::size_t cellular_liquid_block_bytes = 4 + 4 + 2 + 1 + 1 + 8 + (9 * 4);
constexpr std::size_t cellular_perception_v13_prefix_bytes =
cellular_perception_v12_prefix_bytes + cellular_liquid_block_bytes;
// v14 (rules 13) appends the body block: members and threshold (2 x u16), exclusions, flags
// (bit 0 Emerge open), two reserved bytes, payable energy and total mass (2 x u64) and twenty
// u16 traits.
constexpr std::size_t cellular_revamp_block_bytes = 2 + 2 + 1 + 1 + 2 + 8 + 8 + (20 * 2);
constexpr std::size_t cellular_perception_v14_prefix_bytes =
cellular_perception_v13_prefix_bytes + cellular_revamp_block_bytes;
constexpr std::size_t cellular_perceived_patch_bytes = 8 + 8 + (4 * 8);
// v11: id, centre, radius, shape, drained flag and five 16-bit amount codes.
constexpr std::size_t cellular_perceived_deposit_bytes = 4 + 4 + 4 + 2 + 1 + 1 + (5 * 2);
@@ -70,8 +76,14 @@ bool valid_offer(const CellularMutationOffer& offer, std::uint16_t version) {
return offer.event_index == 0 && offer.offer_tick == 0;
std::uint16_t previous = 0;
for (const auto& candidate : offer.candidates) {
// v14: catalog ids with a chance in parts per million and nothing operator-shaped.
const bool named = version == session_protocol_v14;
if (candidate.operator_id <= previous ||
candidate.capability > cellular_offer_capability_limit(version) || candidate.effect > 3)
(named ? candidate.capability != 0 || candidate.effect != 0 ||
candidate.parameter > 1'000'000 || candidate.maintenance != 0 ||
candidate.total_mass != 0
: candidate.capability > cellular_offer_capability_limit(version) ||
candidate.effect > 3))
return false;
previous = candidate.operator_id;
}
@@ -214,7 +226,18 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
return {};
if (const auto* ended = std::get_if<CellularLifeEnded>(&message);
ended && (!cellular_v10_family(version) || ended->tick == 0 || ended->life_identity == 0 ||
ended->cause > CellularDeathReason::engulfed))
ended->cause > (version == session_protocol_v14 ? CellularDeathReason::emerged
: CellularDeathReason::engulfed)))
return {};
if (const auto* choice = std::get_if<CellularMutationAction>(&message);
choice && choice->become && version != session_protocol_v14)
return {};
// v14 alone carries become, emerge and exclusions; become needs a bud, emerge no target.
if (const auto* action = std::get_if<CellularAction>(&message);
action && (action->become || action->emerge || action->exclude != 0) &&
(version != session_protocol_v14 || action->exclude > 0x0F ||
(action->become && !action->bud) ||
(action->emerge && (action->bud || action->engulf || action->has_intake_target))))
return {};
// v9 has no room for engulf and bud effects or the bud cost; only v10 reports them
// (ADR-0129).
@@ -238,7 +261,15 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
// v12 and v13 carry captured light and producers (ADR-0176); v13 alone carries
// liquid motion.
const bool producers = cellular_light_version(version);
const bool liquid = version == session_protocol_v13;
const bool liquid = cellular_liquid_version(version);
const auto& body = perception->diagnostics;
if (version != session_protocol_v14 && body &&
(body->members || body->emerge_members || body->exclude || body->can_emerge ||
body->payable_energy_pj || body->total_mass_fg ||
std::ranges::any_of(body->traits, [](std::uint16_t value) { return value != 0; })))
return {};
if (version == session_protocol_v14 && body && (body->members == 0 || body->exclude > 0x0F))
return {};
if (!liquid && (perception->currents ||
(perception->diagnostics && (perception->diagnostics->velocity_x_q10 ||
perception->diagnostics->velocity_y_q10 ||
@@ -357,8 +388,11 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
put(out, static_cast<std::uint16_t>(m.move_x), 2);
put(out, static_cast<std::uint16_t>(m.move_y), 2);
out.push_back(m.has_intake_target ? 1 : m.engulf ? 2 : m.bud ? 3 : 0); // Target kind.
out.push_back(m.brake ? 1 : 0); // v13 flags: bit 0 brake.
put(out, 0, 2);
// v13 flags: bit 0 brake; v14 adds bit 1 become and bit 2 emerge.
out.push_back(static_cast<std::uint8_t>((m.brake ? 1U : 0U) | (m.become ? 2U : 0U) |
(m.emerge ? 4U : 0U)));
out.push_back(m.exclude); // v14: channels excluded from burning.
out.push_back(0);
put(out, m.intake_x_um, 4);
put(out, m.intake_y_um, 4);
return out;
@@ -370,7 +404,8 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
m.event_index, m.offer_tick})
put(out, value, 8);
put(out, m.operator_id, 2);
put(out, 0, 6);
out.push_back(m.become ? 1 : 0); // v14.
put(out, 0, 5);
return out;
}
std::vector<std::uint8_t> operator()(const CellularLifeEnded& m) const {
@@ -407,13 +442,14 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
std::vector<std::uint8_t> operator()(const CellularPerception& m) const {
auto out =
header(SessionMessageType::cellular_perception,
(version == session_protocol_v13 ? cellular_perception_v13_prefix_bytes
(version == session_protocol_v14 ? cellular_perception_v14_prefix_bytes
: version == session_protocol_v13 ? cellular_perception_v13_prefix_bytes
: version == session_protocol_v12 ? cellular_perception_v12_prefix_bytes
: cellular_v10_family(version) ? cellular_perception_v10_prefix_bytes
: version == session_protocol_v9 ? cellular_perception_v9_prefix_bytes
: cellular_perception_prefix_bytes) +
m.patches.size() * cellular_perceived_patch_bytes +
m.deposits.size() * (version == session_protocol_v13
m.deposits.size() * (cellular_liquid_version(version)
? cellular_perceived_liquid_deposit_bytes
: cellular_perceived_deposit_bytes) +
m.producers.size() * cellular_perceived_producer_bytes,
@@ -446,7 +482,7 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
put(out, m.producers.size(), 2);
put(out, 0, 6);
}
if (version == session_protocol_v13) {
if (cellular_liquid_version(version)) {
put(out, static_cast<std::uint32_t>(d ? d->velocity_x_q10 : 0), 4);
put(out, static_cast<std::uint32_t>(d ? d->velocity_y_q10 : 0), 4);
put(out, d ? d->heading : 0, 2);
@@ -460,6 +496,18 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
c.max_speed_um_per_s})
put(out, value, 4);
}
if (version == session_protocol_v14) {
const auto b = d.value_or(CellularLifeDiagnostics{});
put(out, b.members, 2);
put(out, b.emerge_members, 2);
out.push_back(b.exclude);
out.push_back(b.can_emerge ? 1 : 0);
put(out, 0, 2);
put(out, b.payable_energy_pj, 8);
put(out, b.total_mass_fg, 8);
for (const auto value : b.traits)
put(out, value, 2);
}
} else {
put(out, 0, 5);
}
@@ -480,7 +528,7 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
out.push_back(deposit.drained ? 1 : 0);
for (const auto code : deposit.amount_codes)
put(out, code, 2);
if (version == session_protocol_v13) {
if (cellular_liquid_version(version)) {
put(out, static_cast<std::uint16_t>(deposit.velocity_x_um_s), 2);
put(out, static_cast<std::uint16_t>(deposit.velocity_y_um_s), 2);
}
@@ -721,14 +769,22 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
m.move_x = static_cast<std::int16_t>(static_cast<std::uint16_t>(get(payload, 32, 2)));
m.move_y = static_cast<std::int16_t>(static_cast<std::uint16_t>(get(payload, 34, 2)));
// Target kind: 0 none, 1 patch intake, 2 engulf and 3 bud (v10 only, ADR-0124/0125).
const bool revamp = wire_version == session_protocol_v14;
if (payload[36] > (cellular_v10_family(wire_version) ? 3 : 1) ||
payload[37] > (wire_version == session_protocol_v13 ? 1 : 0) || payload[38] != 0 ||
payload[39] != 0)
payload[37] > (revamp ? 7
: wire_version == session_protocol_v13 ? 1
: 0) ||
payload[38] > (revamp ? 0x0F : 0) || payload[39] != 0)
return std::unexpected(SessionCodecError::invalid_value);
m.has_intake_target = payload[36] == 1;
m.engulf = payload[36] == 2;
m.bud = payload[36] == 3;
m.brake = payload[37] == 1;
m.brake = (payload[37] & 1U) != 0;
m.become = (payload[37] & 2U) != 0;
m.emerge = (payload[37] & 4U) != 0;
m.exclude = payload[38];
if ((m.become && !m.bud) || (m.emerge && payload[36] != 0))
return std::unexpected(SessionCodecError::invalid_value);
m.intake_x_um = static_cast<std::uint32_t>(get(payload, 40, 4));
m.intake_y_um = static_cast<std::uint32_t>(get(payload, 44, 4));
if (!m.session || !m.epoch || !m.action_id || !m.tick ||
@@ -750,9 +806,11 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
m.event_index = get(payload, 40, 8);
m.offer_tick = get(payload, 48, 8);
m.operator_id = static_cast<std::uint16_t>(get(payload, 56, 2));
m.become = payload[58] == 1;
if (!m.session || !m.epoch || !m.action_id || !m.tick || !m.life_identity ||
!m.event_index || !m.offer_tick || m.offer_tick >= m.tick || // operator 0 declines
std::ranges::any_of(payload.subspan(58, 6),
payload[58] > (wire_version == session_protocol_v14 ? 1 : 0) ||
std::ranges::any_of(payload.subspan(59, 5),
[](std::uint8_t value) { return value != 0; }))
return std::unexpected(SessionCodecError::invalid_value);
return m;
@@ -766,7 +824,9 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
m.tick = get(payload, 0, 8);
m.life_identity = get(payload, 8, 8);
if (m.tick == 0 || m.life_identity == 0 ||
payload[16] > static_cast<std::uint8_t>(CellularDeathReason::engulfed) ||
payload[16] > static_cast<std::uint8_t>(wire_version == session_protocol_v14
? CellularDeathReason::emerged
: CellularDeathReason::engulfed) ||
std::ranges::any_of(payload.subspan(17, 7),
[](std::uint8_t value) { return value != 0; }))
return std::unexpected(SessionCodecError::invalid_value);
@@ -823,9 +883,11 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
payload.size() == cellular_perception_v9_prefix_bytes +
count * cellular_perceived_patch_bytes;
const bool lit = cellular_light_version(wire_version);
const bool liquid = wire_version == session_protocol_v13;
const auto prefix = liquid ? cellular_perception_v13_prefix_bytes
: lit ? cellular_perception_v12_prefix_bytes
const bool liquid = cellular_liquid_version(wire_version);
const bool revamp = wire_version == session_protocol_v14;
const auto prefix = revamp ? cellular_perception_v14_prefix_bytes
: liquid ? cellular_perception_v13_prefix_bytes
: lit ? cellular_perception_v12_prefix_bytes
: cellular_v10_family(wire_version) && !without_bud_cost
? cellular_perception_v10_prefix_bytes
: wire_version == session_protocol_v9 || without_bud_cost
@@ -935,6 +997,35 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
if (flags == 1)
m.currents = c;
}
if (revamp) {
constexpr auto at = cellular_perception_v13_prefix_bytes;
CellularLifeDiagnostics b;
b.members = static_cast<std::uint16_t>(get(payload, at, 2));
b.emerge_members = static_cast<std::uint16_t>(get(payload, at + 2, 2));
b.exclude = payload[at + 4];
b.can_emerge = payload[at + 5] == 1;
b.payable_energy_pj = get(payload, at + 8, 8);
b.total_mass_fg = get(payload, at + 16, 8);
for (std::size_t i = 0; i < b.traits.size(); ++i)
b.traits.at(i) = static_cast<std::uint16_t>(get(payload, at + 24 + i * 2, 2));
const bool empty = b.members == 0 && b.emerge_members == 0 && b.exclude == 0 &&
payload[at + 5] == 0 && b.payable_energy_pj == 0 &&
b.total_mass_fg == 0 &&
std::ranges::all_of(b.traits, [](auto v) { return v == 0; });
if (b.exclude > 0x0F || payload[at + 5] > 1 || payload[at + 6] != 0 ||
payload[at + 7] != 0 || (m.diagnostics ? b.members == 0 : !empty))
return std::unexpected(SessionCodecError::invalid_value);
if (m.diagnostics) {
auto& d = *m.diagnostics;
d.members = b.members;
d.emerge_members = b.emerge_members;
d.exclude = b.exclude;
d.can_emerge = b.can_emerge;
d.payable_energy_pj = b.payable_energy_pj;
d.total_mass_fg = b.total_mass_fg;
d.traits = b.traits;
}
}
std::size_t offset = prefix;
if (deposits) {
m.deposits.reserve(count);
@@ -1167,8 +1258,11 @@ encode_cellular_action_input(const CellularActionInput& input) {
: input.engulf ? 2
: input.bud ? 3
: 0);
bytes.push_back(input.brake ? 1 : 0); // Flags (schema 58): bit 0 brake.
put(bytes, 0, 2);
// Flags: bit 0 brake (schema 58), bit 1 become and bit 2 emerge (schema 60).
bytes.push_back(static_cast<std::uint8_t>((input.brake ? 1U : 0U) | (input.become ? 2U : 0U) |
(input.emerge ? 4U : 0U)));
bytes.push_back(input.exclude); // Schema 60: channels excluded from burning.
bytes.push_back(0);
put(bytes, input.intake_x_um, 4);
put(bytes, input.intake_y_um, 4);
std::array<std::uint8_t, cellular_action_input_bytes> out{};
@@ -1180,7 +1274,7 @@ std::expected<CellularActionInput, SessionCodecError>
decode_cellular_action_input(std::span<const std::uint8_t> bytes) {
if (bytes.size() != cellular_action_input_bytes)
return std::unexpected(SessionCodecError::wrong_length);
if (bytes[12] > 3 || bytes[13] > 1 || bytes[14] != 0 || bytes[15] != 0)
if (bytes[12] > 3 || bytes[13] > 7 || bytes[14] > 0x0F || bytes[15] != 0)
return std::unexpected(SessionCodecError::invalid_value);
CellularActionInput input;
input.tick = get(bytes, 0, 8);
@@ -1189,11 +1283,15 @@ decode_cellular_action_input(std::span<const std::uint8_t> bytes) {
input.has_intake_target = bytes[12] == 1;
input.engulf = bytes[12] == 2;
input.bud = bytes[12] == 3;
input.brake = bytes[13] == 1;
input.brake = (bytes[13] & 1U) != 0;
input.become = (bytes[13] & 2U) != 0;
input.emerge = (bytes[13] & 4U) != 0;
input.exclude = bytes[14];
input.intake_x_um = static_cast<std::uint32_t>(get(bytes, 16, 4));
input.intake_y_um = static_cast<std::uint32_t>(get(bytes, 20, 4));
if (input.tick == 0 ||
(!input.has_intake_target && (input.intake_x_um != 0 || input.intake_y_um != 0)))
(!input.has_intake_target && (input.intake_x_um != 0 || input.intake_y_um != 0)) ||
(input.become && !input.bud) || (input.emerge && bytes[12] != 0))
return std::unexpected(SessionCodecError::invalid_value);
return input;
}