Add M9.8c launcher, legend, labelled inspector and click selection

Toolkit-independent launcher, selection, label and outcome-log models with
bounded inputs and fixed error text; Dear ImGui overlay in the native adapter
with toolkit-first event routing and capture; engineering panels for fixture vs
dev region, legend, inspector, session outcomes, notices and dialog. Additive
SessionClient::unreachable_attempts() bounds unreachable connects. Docs, CI
targets and validation evidence updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-02 10:09:11 -04:00
co-authored by Claude Opus 5.5
parent a6e8094f57
commit 897055883a
36 changed files with 2106 additions and 200 deletions
+103 -72
View File
@@ -1,67 +1,46 @@
#pragma once
// M9.7 remote dev session for the engineering client (ADR-0083). Without
// EVO_CLIENT_NETWORK (a build without EVO_BUILD_NETWORK) remote options are refused.
// M9.7/M9.8c remote dev session for the engineering client (ADR-0083). Without
// EVO_CLIENT_NETWORK (a build without EVO_BUILD_NETWORK) remote mode is unavailable.
// The client only presents copies and sends bounded intentions; it never predicts.
// Grant bytes stay inside the session client: never printed, shown or persisted.
#include "evo/client/environment_view.hpp"
#include "evo/client/input.hpp"
#include "evo/client/launcher.hpp"
#include "evo/client/organism_view.hpp"
#include "evo/render/frame.hpp"
#include "evo/client/outcome_log.hpp"
#include "evo/client/ui_state.hpp"
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#ifdef EVO_CLIENT_NETWORK
#include "evo/network/session_client.hpp"
#include <charconv>
#include <cstdio>
#include <fstream>
#include <iterator>
#include <memory>
#include <type_traits>
#endif
namespace evo::client_app {
struct RemoteOptions {
std::string connect, server_name, authority, grants;
[[nodiscard]] bool any() const noexcept {
return !connect.empty() || !server_name.empty() || !authority.empty() || !grants.empty();
}
[[nodiscard]] bool complete() const noexcept {
return !connect.empty() && !server_name.empty() && !authority.empty() && !grants.empty();
}
struct RemoteStatus {
std::string phase; // connecting / connected / reconnecting / out of grants
std::uint64_t session{}, epoch{}, server_tick{}, commit_watermark{};
std::size_t grants_left{};
bool welcomed{};
};
#ifdef EVO_CLIENT_NETWORK
inline constexpr bool remote_available = true;
static_assert(std::is_same_v<client::GrantRecord, network::DevGrant>,
"the launcher's grant record is the session's grant");
class RemoteSession {
public:
static std::optional<RemoteSession> open(const RemoteOptions& o) {
const auto colon = o.connect.rfind(':');
unsigned port = 0;
if (colon == std::string::npos || colon == 0)
return std::nullopt;
const auto* digits = o.connect.data() + colon + 1;
const auto [end, error] =
std::from_chars(digits, o.connect.data() + o.connect.size(), port);
if (error != std::errc{} || end != o.connect.data() + o.connect.size() || port == 0 ||
port > 65535)
return std::nullopt;
const auto bundle = read(o.grants);
if (bundle.empty() || bundle.size() % network::dev_grant_bytes != 0 ||
bundle.size() / network::dev_grant_bytes > 64)
return std::nullopt;
static std::optional<RemoteSession> open(const client::ConnectMaterial& m) {
network::SessionClientConfig config;
config.host = o.connect.substr(0, colon);
config.port = static_cast<std::uint16_t>(port);
const auto pem = read(o.authority);
config.trust = {{pem.begin(), pem.end()}, o.server_name};
for (std::size_t at = 0; at < bundle.size(); at += network::dev_grant_bytes) {
network::DevGrant grant{};
std::copy_n(bundle.begin() + static_cast<std::ptrdiff_t>(at), grant.size(),
grant.begin());
config.grants.push_back(grant);
}
config.host = m.endpoint.host;
config.port = m.endpoint.port;
config.trust = {m.authority_pem, m.server_name};
config.grants = m.grants;
auto made = network::SessionClient::create(std::move(config));
if (!made)
return std::nullopt;
@@ -75,9 +54,34 @@ class RemoteSession {
[[nodiscard]] const client::OrganismLayer& organisms() const noexcept {
return client_->organisms();
}
// Services the connection and sends the intention when its vector changed, at
// most once per received server tick (the server also rate-limits).
void step(std::chrono::steady_clock::time_point now, const client::Intention& intention) {
[[nodiscard]] const client::OutcomeLog& outcomes() const noexcept {
return log_;
}
[[nodiscard]] RemoteStatus status() const {
using network::SessionPhase;
RemoteStatus s;
const auto phase = client_->phase();
s.phase = phase == SessionPhase::established ? "connected"
: phase == SessionPhase::exhausted ? "out of grants"
: welcomed_ ? "reconnecting"
: "connecting";
if (const auto w = client_->welcome()) {
s.session = w->session;
s.epoch = w->epoch;
}
if (const auto v = client_->latest_view()) {
s.server_tick = v->server_tick;
s.commit_watermark = v->commit_watermark;
}
s.grants_left = client_->grants_left();
s.welcomed = welcomed_;
return s;
}
// Services the connection; sends the intention when its vector changed, at most once
// per received server tick (the server also rate-limits). Session events update the
// outcome log (the durable record), short notifications and the launcher.
void step(std::chrono::steady_clock::time_point now, const client::Intention& intention,
client::UiState& ui, client::Launcher& launcher) {
client_->poll(now);
const auto view = client_->latest_view();
const bool changed = intention.move_x != sent_x_ || intention.move_y != sent_y_;
@@ -86,55 +90,70 @@ class RemoteSession {
sent_x_ = intention.move_x;
sent_y_ = intention.move_y;
sent_tick_ = view->server_tick;
log_.record({intention.sequence, client::OutcomeState::sent});
}
for (const auto& e : client_->take_events())
report(e);
}
// Connection chip and last-intention chip, below the capture bar.
void status(std::vector<render::Rectangle>& out) const {
using network::SessionPhase;
const auto phase = client_->phase();
const render::Color connection =
phase == SessionPhase::established ? render::Color{64, 180, 140, 255}
: phase == SessionPhase::exhausted ? render::Color{200, 40, 40, 255}
: render::Color{240, 170, 40, 255};
out.push_back({8, 72, 28, 6, connection});
out.push_back({40, 72, 6, 6, intent_});
report(e, ui, launcher);
// Refused TCP or failed TLS produce no event; each still counts toward the
// launcher's bounded "server unreachable" before a first Welcome.
for (; unreachable_ < client_->unreachable_attempts(); ++unreachable_)
launcher.observe(client::ConnectSignal::lost);
}
private:
static std::vector<std::uint8_t> read(const std::string& path) {
std::ifstream file{path, std::ios::binary};
return {std::istreambuf_iterator<char>{file}, std::istreambuf_iterator<char>{}};
static void notify(client::UiState& ui, const char* text, client::NoticeLevel level) {
static_cast<void>(ui.notify(text, level).has_value()); // Bounded; overflow evicts.
}
void report(const network::ClientEvent& e) {
void report(const network::ClientEvent& e, client::UiState& ui, client::Launcher& launcher) {
using Kind = network::ClientEvent::Kind;
constexpr render::Color pending{240, 240, 240, 255}, durable{64, 180, 140, 255},
refused{200, 40, 40, 255}, unknown{130, 130, 130, 255};
using network::CloseReason;
switch (e.kind) {
case Kind::welcome:
welcomed_ = true;
sent_tick_.reset(); // New session: resend the current intention.
sent_x_ = sent_y_ = 0;
launcher.observe(client::ConnectSignal::welcome);
notify(ui, "Connected to the dev region (fresh baseline).", client::NoticeLevel::info);
std::printf("session welcome session=%llu epoch=%llu tick=%llu commit=%llu\n",
static_cast<unsigned long long>(e.welcome.session),
static_cast<unsigned long long>(e.welcome.epoch),
static_cast<unsigned long long>(e.welcome.server_tick),
static_cast<unsigned long long>(e.welcome.commit_watermark));
break;
case Kind::closed:
case Kind::closed: {
const bool retry =
e.reason == CloseReason::server_shutdown || e.reason == CloseReason::capacity;
const bool lost = e.reason == CloseReason::timeout ||
e.reason == CloseReason::stale_epoch ||
e.reason == CloseReason::rate_limited;
launcher.observe(retry ? client::ConnectSignal::not_ready
: lost ? client::ConnectSignal::lost
: client::ConnectSignal::refused);
notify(ui, retry ? "Server not ready; retrying." : "Session closed by the server.",
retry ? client::NoticeLevel::info : client::NoticeLevel::warning);
std::printf("session closed reason=%u\n", static_cast<unsigned>(e.reason));
break;
}
case Kind::lost:
launcher.observe(client::ConnectSignal::lost);
notify(ui, "Connection lost; views are stale.", client::NoticeLevel::warning);
std::puts("session lost (reconnecting with a fresh grant)");
break;
case Kind::result:
intent_ = e.result.status == network::IntentStatus::admitted ? pending : refused;
log_.record({e.sequence,
e.result.status == network::IntentStatus::admitted
? client::OutcomeState::admitted
: client::OutcomeState::rejected,
static_cast<std::uint8_t>(e.result.status)});
std::printf("intent %llu status=%u\n", static_cast<unsigned long long>(e.sequence),
static_cast<unsigned>(e.result.status));
break;
case Kind::outcome:
intent_ = e.outcome.finality == network::IntentFinality::committed_no_effect ? durable
: refused;
log_.record({e.sequence,
e.outcome.finality == network::IntentFinality::committed_no_effect
? client::OutcomeState::durable
: client::OutcomeState::not_committed,
0, e.outcome.tick, e.outcome.commit_sequence});
std::printf("intent %llu final=%u tick=%llu commit=%llu\n",
static_cast<unsigned long long>(e.sequence),
static_cast<unsigned>(e.outcome.finality),
@@ -142,29 +161,34 @@ class RemoteSession {
static_cast<unsigned long long>(e.outcome.commit_sequence));
break;
case Kind::unknown:
intent_ = unknown;
log_.record({e.sequence, client::OutcomeState::unknown});
std::printf("intent %llu outcome unknown (connection lost)\n",
static_cast<unsigned long long>(e.sequence));
break;
case Kind::backpressure:
notify(ui, "Session event backlog; reconnecting after draining.",
client::NoticeLevel::warning);
std::puts("session event backlog: disconnected; draining before reconnect");
break;
case Kind::exhausted:
launcher.observe(client::ConnectSignal::exhausted);
std::puts("session grants exhausted; issue a new bundle to reconnect");
break;
}
std::fflush(stdout);
}
std::unique_ptr<network::SessionClient> client_;
client::OutcomeLog log_;
std::optional<std::uint64_t> sent_tick_;
std::uint64_t unreachable_{};
std::int16_t sent_x_{}, sent_y_{};
render::Color intent_{60, 60, 66, 255};
bool welcomed_{};
};
#else
inline constexpr bool remote_available = false;
class RemoteSession {
public:
static std::optional<RemoteSession> open(const RemoteOptions&) {
static std::optional<RemoteSession> open(const client::ConnectMaterial&) {
return std::nullopt;
}
[[nodiscard]] const client::EnvironmentLayer& environment() const noexcept {
@@ -173,12 +197,19 @@ class RemoteSession {
[[nodiscard]] const client::OrganismLayer& organisms() const noexcept {
return organisms_;
}
void step(std::chrono::steady_clock::time_point, const client::Intention&) {}
void status(std::vector<render::Rectangle>&) const {}
[[nodiscard]] const client::OutcomeLog& outcomes() const noexcept {
return log_;
}
[[nodiscard]] RemoteStatus status() const {
return {"unavailable in this build"};
}
void step(std::chrono::steady_clock::time_point, const client::Intention&, client::UiState&,
client::Launcher&) {}
private:
client::EnvironmentLayer environment_;
client::OrganismLayer organisms_;
client::OutcomeLog log_;
};
#endif
} // namespace evo::client_app