feat(admin): read-only admin portal and API (ADR-0182 step 1, schema 61)
evo-admin-api serves the portal at srs.aeternalisgames.com and read-only JSON for world 100 behind Keycloak (realm role aevolution-admin, audience aevolution-admin, client aevolution-admin-portal): accounts with session, status, lives, deaths, resets and mutation choices; one account's lives; the world's regions; and a live 2D region view of cells, wildlife, pools and bubbles. The portal is plain HTML/CSS/JS with PKCE sign-in, a strict CSP and no third-party code. - Schema 61: three bounded SECURITY DEFINER read functions, fenced in the privilege audit; no table or existing function changes. - Cellular regions answer GET /admin/view on the ops port (NetworkPolicy: Prometheus and the admin portal only); CellularLives::extent_of reads the existing phenotype budget. No simulation, checkpoint or wire change. - TokenVerifier takes an optional realm role and returns the email; the ops server's response bound is configurable (16 KiB default unchanged). - DEV component admin-portal-dev (Deployment, Service, NetworkPolicies); the Ingress and the aevolution-admin-pg Secret are created out of band. - CI scripts pinned to schema 60 now expect 61. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
#include "evo/server/lifecycle/cellular_admin_view.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace evo::server {
|
||||
namespace {
|
||||
void append(std::string& out, std::uint64_t value) {
|
||||
out += std::to_string(value);
|
||||
}
|
||||
void append_inventory(std::string& out, const accounting::Inventory& inventory) {
|
||||
append(out, inventory.energy.value);
|
||||
for (const auto& channel : inventory.matter) {
|
||||
out.push_back(',');
|
||||
append(out, channel.value);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string cellular_account_text(const LifeAccount& account) {
|
||||
constexpr std::string_view digits = "0123456789abcdef";
|
||||
std::string out;
|
||||
out.reserve(36);
|
||||
for (std::size_t i = 0; i < account.size(); ++i) {
|
||||
if (i == 4 || i == 6 || i == 8 || i == 10)
|
||||
out.push_back('-');
|
||||
out.push_back(digits[account[i] >> 4U]);
|
||||
out.push_back(digits[account[i] & 0x0FU]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string render_cellular_admin_view(const CellularLives& state,
|
||||
const CellularAdminOnline& online,
|
||||
CellularAdminViewLimits limits) {
|
||||
const auto lives = state.lives();
|
||||
const auto patches = state.habitat().patches();
|
||||
std::string out;
|
||||
out.reserve(256 + std::min(lives.size(), limits.cells) * 128 +
|
||||
std::min(patches.size(), limits.deposits) * 64);
|
||||
out += "{\"world\":";
|
||||
append(out, state.world());
|
||||
out += ",\"region\":";
|
||||
append(out, state.region());
|
||||
out += ",\"tick\":";
|
||||
append(out, state.tick());
|
||||
out += ",\"rules\":";
|
||||
append(out, state.rules_version());
|
||||
out += ",\"area\":[";
|
||||
append(out, state.area().width_um);
|
||||
out.push_back(',');
|
||||
append(out, state.area().height_um);
|
||||
out += "],\"spent\":[";
|
||||
append_inventory(out, state.spent());
|
||||
out += "],\"cells_total\":";
|
||||
append(out, lives.size());
|
||||
out += ",\"deposits_total\":";
|
||||
append(out, patches.size());
|
||||
|
||||
// Lives are kept in ascending life id; a prefix is the lowest ids.
|
||||
out += ",\"cells\":[";
|
||||
const auto cells = std::min(lives.size(), limits.cells);
|
||||
for (std::size_t i = 0; i < cells; ++i) {
|
||||
const auto& life = lives[i];
|
||||
const bool wildlife = life.account == LifeAccount{};
|
||||
std::uint64_t flags = wildlife ? 1U : 0U;
|
||||
if (!wildlife && online && online(life.account))
|
||||
flags |= 2U;
|
||||
if (life.presence == CellularPresence::lingering)
|
||||
flags |= 4U;
|
||||
if (life.presence == CellularPresence::suspended)
|
||||
flags |= 8U;
|
||||
std::uint64_t body_mass{};
|
||||
for (const auto& channel : life.body.matter)
|
||||
body_mass += channel.value;
|
||||
if (i != 0)
|
||||
out.push_back(',');
|
||||
out += "[\"";
|
||||
append(out, life.identity.life);
|
||||
out += "\",\"";
|
||||
append(out, life.identity.organism);
|
||||
out += "\",\"";
|
||||
if (!wildlife)
|
||||
out += cellular_account_text(life.account);
|
||||
out += "\",";
|
||||
append(out, life.position.x_um);
|
||||
out.push_back(',');
|
||||
append(out, life.position.y_um);
|
||||
out.push_back(',');
|
||||
append(out, state.extent_of(life).value_or(0));
|
||||
out.push_back(',');
|
||||
append(out, flags);
|
||||
out.push_back(',');
|
||||
append(out, life.revamp.members);
|
||||
out.push_back(',');
|
||||
append_inventory(out, life.reserve);
|
||||
out.push_back(',');
|
||||
append(out, body_mass);
|
||||
out.push_back(']');
|
||||
}
|
||||
|
||||
// Patches are kept by address; the view lists them by ascending id.
|
||||
std::vector<const biology::CellularPatch*> listed;
|
||||
listed.reserve(patches.size());
|
||||
for (const auto& patch : patches)
|
||||
listed.push_back(&patch);
|
||||
const auto deposits = std::min(listed.size(), limits.deposits);
|
||||
std::ranges::partial_sort(listed, listed.begin() + static_cast<std::ptrdiff_t>(deposits), {},
|
||||
[](const biology::CellularPatch* patch) { return patch->id; });
|
||||
out += "],\"deposits\":[";
|
||||
for (std::size_t i = 0; i < deposits; ++i) {
|
||||
const auto& patch = *listed[i];
|
||||
if (i != 0)
|
||||
out.push_back(',');
|
||||
out.push_back('[');
|
||||
append(out, patch.id);
|
||||
out.push_back(',');
|
||||
append(out, static_cast<std::uint64_t>(patch.kind));
|
||||
out.push_back(',');
|
||||
append(out, patch.address.x_um);
|
||||
out.push_back(',');
|
||||
append(out, patch.address.y_um);
|
||||
out.push_back(',');
|
||||
append(out, patch.radius_um);
|
||||
out.push_back(',');
|
||||
append_inventory(out, patch.stock);
|
||||
out.push_back(']');
|
||||
}
|
||||
out += "]}\n";
|
||||
return out;
|
||||
}
|
||||
} // namespace evo::server
|
||||
@@ -1127,6 +1127,13 @@ accounting::Inventory CellularLives::heat() const noexcept {
|
||||
accounting::Inventory CellularLives::spent() const noexcept {
|
||||
return state_->spent;
|
||||
}
|
||||
std::optional<std::uint32_t> CellularLives::extent_of(const CellularOwnedLife& life) const {
|
||||
const auto budget = budget_for(
|
||||
state_->archive, life, state_->config.ambient_temperature_millikelvin, state_->revamp.body);
|
||||
if (!budget)
|
||||
return std::nullopt;
|
||||
return budget->phenotype.extent;
|
||||
}
|
||||
accounting::Inventory CellularLives::opening_total() const noexcept {
|
||||
return state_->opening_total;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user