Queue Eve surface commands as typed state

This commit is contained in:
Meta Vens 2026-06-13 16:44:24 +01:00
commit b867e688e2
7 changed files with 250 additions and 14 deletions

Binary file not shown.

View file

@ -1,6 +1,7 @@
using Aetheria.State;
using Aetheria.State.Unity;
using GameCult.Aetheria.State.Unity;
using GameCult.Eve.Surface;
var root = args.Length > 0 ? Path.GetFullPath(args[0]) : Directory.GetCurrentDirectory();
var statePath = args.Length > 1
@ -234,6 +235,28 @@ try
{
throw new InvalidOperationException("Runtime state commit log did not apply queued settings/run snapshots through the typed state node.");
}
var eveCommand = AetheriaRuntimeEveCommandLog.QueueCommand(
commitSmokeStatePath,
new EveSurfaceCommandRequest(
"aetheria",
"aetheria.catalog.operator",
"aetheria.catalog.refresh",
new Dictionary<string, string> { ["source"] = "unity-smoke" },
DateTimeOffset.UtcNow,
"aetheria-state-unity-smoke"));
var evePending = AetheriaRuntimeEveCommandLog.ReadPending(commitSmokeStatePath);
if (evePending.Count != 1 ||
evePending[0].Schema != AetheriaRuntimeEveCommandLog.CommandSchema ||
evePending[0].CommandId != eveCommand.CommandId ||
evePending[0].ProviderId != "aetheria" ||
evePending[0].SurfaceId != "aetheria.catalog.operator" ||
evePending[0].Command != "aetheria.catalog.refresh" ||
evePending[0].Payload["source"] != "unity-smoke" ||
AetheriaRuntimeStateCommitLog.ReadPending(commitSmokeStatePath).Count != 0)
{
throw new InvalidOperationException("Runtime Eve command log did not preserve typed command envelopes separately from state commits.");
}
}
finally
{
@ -249,3 +272,4 @@ Console.WriteLine($"Behavior sample: {behaviorKind}");
Console.WriteLine($"Eve surface: {surface.Surface.Id}");
Console.WriteLine($"Package Eve surfaces: {packageSurfaces.Count}");
Console.WriteLine("Runtime state commit log smoke: settings and run zone/entity snapshots queued, applied, and cleared");
Console.WriteLine("Runtime Eve command log smoke: surface command queued separately from state commits");

View file

@ -11,6 +11,7 @@
<Compile Include="..\Packages\org.gamecult.eve.surface\Runtime\EveSurfaceDocument.cs" Link="EveSurfaceDocument.cs" />
<Compile Include="..\Packages\org.gamecult.aetheria.state\Runtime\AetheriaRuntimeCatalogSnapshot.cs" Link="AetheriaRuntimeCatalogSnapshot.cs" />
<Compile Include="..\Packages\org.gamecult.aetheria.state\Runtime\AetheriaRuntimeCatalogStore.cs" Link="AetheriaRuntimeCatalogStore.cs" />
<Compile Include="..\Packages\org.gamecult.aetheria.state\Runtime\AetheriaRuntimeEveCommandLog.cs" Link="AetheriaRuntimeEveCommandLog.cs" />
<Compile Include="..\Packages\org.gamecult.aetheria.state\Runtime\AetheriaRuntimeStateCommitLog.cs" Link="AetheriaRuntimeStateCommitLog.cs" />
<ProjectReference Include="..\Aetheria.State\Aetheria.State.csproj" />
</ItemGroup>

View file

@ -7,9 +7,10 @@ CultCache state into Unity UI Toolkit.
- it reads `gamecult.eve.surface.v1` from `GameData/aetheria-world.cc`;
- it lowers the retained tree through `org.gamecult.eve.unity-uitoolkit`;
- it does not accept, mutate, or persist Aetheria state.
- it queues renderer-emitted commands as typed `.cc.eve.pending` command
envelopes for the future CultMesh command bridge.
Commands are surfaced as `gamecult.eve.command.v1` requests and currently log a
capability gap until the CultMesh command bridge is wired. That gap is visible
on purpose; renderer-local command effects would be the wrong organ wearing a
clean shirt.
Commands are surfaced as `gamecult.eve.command.v1` requests. The presenter does
not accept or apply them locally; provider acceptance still belongs to the
CultMesh command bridge. Renderer-local command effects would be the wrong
organ wearing a clean shirt.

View file

@ -60,7 +60,7 @@ namespace GameCult.Aetheria.EveRuntime
}
var lowerer = new EveUiToolkitSurfaceLowerer();
root.Add(lowerer.Lower(surface, EmitCommand));
root.Add(lowerer.Lower(surface, request => EmitCommand(statePath, request)));
}
private void OnEnable()
@ -95,10 +95,11 @@ namespace GameCult.Aetheria.EveRuntime
return container;
}
private static void EmitCommand(EveSurfaceCommandRequest request)
private static void EmitCommand(string statePath, EveSurfaceCommandRequest request)
{
Debug.LogWarning(
$"Eve command emitted without a CultMesh command bridge: {request.ProviderId}/{request.SurfaceId}/{request.Command}");
var envelope = AetheriaRuntimeEveCommandLog.QueueCommand(statePath, request);
Debug.Log(
$"Queued Eve command for CultMesh bridge: {envelope.ProviderId}/{envelope.SurfaceId}/{envelope.Command} {envelope.CommandId}");
}
}
}

View file

@ -0,0 +1,199 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using GameCult.Eve.Surface;
using MessagePack;
#nullable enable
namespace GameCult.Aetheria.State.Unity
{
public sealed class AetheriaRuntimeEveCommandEnvelope
{
public AetheriaRuntimeEveCommandEnvelope(
string schema,
string commandId,
string providerId,
string surfaceId,
string command,
string issuedAtUtc,
string clientId,
IReadOnlyDictionary<string, string> payload,
string path)
{
Schema = schema;
CommandId = commandId;
ProviderId = providerId;
SurfaceId = surfaceId;
Command = command;
IssuedAtUtc = issuedAtUtc;
ClientId = clientId;
Payload = payload;
Path = path;
}
public string Schema { get; }
public string CommandId { get; }
public string ProviderId { get; }
public string SurfaceId { get; }
public string Command { get; }
public string IssuedAtUtc { get; }
public string ClientId { get; }
public IReadOnlyDictionary<string, string> Payload { get; }
public string Path { get; }
}
public static class AetheriaRuntimeEveCommandLog
{
public const string CommandSchema = "gamecult.eve.command.v1";
public static string GetPendingDirectory(string stateFilePath)
{
if (string.IsNullOrWhiteSpace(stateFilePath))
throw new ArgumentException("State file path must be non-empty.", nameof(stateFilePath));
return stateFilePath + ".eve.pending";
}
public static AetheriaRuntimeEveCommandEnvelope QueueCommand(
string stateFilePath,
EveSurfaceCommandRequest request)
{
if (request == null) throw new ArgumentNullException(nameof(request));
var commandId = Guid.NewGuid().ToString("N");
var issuedAtUtc = request.IssuedAt.UtcDateTime.ToString("O");
var pendingDirectory = GetPendingDirectory(stateFilePath);
Directory.CreateDirectory(pendingDirectory);
var finalPath = Path.Combine(
pendingDirectory,
$"{issuedAtUtc.Replace(':', '-')}.{StableToken(request.SurfaceId)}.{StableToken(request.Command)}.{commandId}.cc");
var tempPath = finalPath + ".tmp";
var buffer = new ArrayBufferWriter<byte>();
var writer = new MessagePackWriter(buffer);
writer.WriteArrayHeader(8);
writer.Write(CommandSchema);
writer.Write(commandId);
writer.Write(request.ProviderId ?? "");
writer.Write(request.SurfaceId ?? "");
writer.Write(request.Command ?? "");
writer.Write(issuedAtUtc);
writer.Write(request.ClientId ?? "");
WritePayload(ref writer, request.Payload);
writer.Flush();
File.WriteAllBytes(tempPath, buffer.WrittenSpan.ToArray());
if (File.Exists(finalPath))
File.Delete(finalPath);
File.Move(tempPath, finalPath);
return new AetheriaRuntimeEveCommandEnvelope(
CommandSchema,
commandId,
request.ProviderId,
request.SurfaceId,
request.Command,
issuedAtUtc,
request.ClientId,
new Dictionary<string, string>(request.Payload, StringComparer.Ordinal),
finalPath);
}
public static IReadOnlyList<AetheriaRuntimeEveCommandEnvelope> ReadPending(string stateFilePath)
{
var pendingDirectory = GetPendingDirectory(stateFilePath);
if (!Directory.Exists(pendingDirectory))
return Array.Empty<AetheriaRuntimeEveCommandEnvelope>();
return Directory
.EnumerateFiles(pendingDirectory, "*.cc")
.OrderBy(path => path, StringComparer.Ordinal)
.Select(ReadEnvelope)
.ToArray();
}
private static AetheriaRuntimeEveCommandEnvelope ReadEnvelope(string path)
{
var reader = new MessagePackReader(File.ReadAllBytes(path));
var fields = reader.ReadArrayHeader();
var schema = fields > 0 ? ReadString(ref reader) : "";
var commandId = fields > 1 ? ReadString(ref reader) : "";
var providerId = fields > 2 ? ReadString(ref reader) : "";
var surfaceId = fields > 3 ? ReadString(ref reader) : "";
var command = fields > 4 ? ReadString(ref reader) : "";
var issuedAtUtc = fields > 5 ? ReadString(ref reader) : "";
var clientId = fields > 6 ? ReadString(ref reader) : "";
var payload = fields > 7 ? ReadPayload(ref reader) : EmptyPayload();
for (var field = 8; field < fields; field++)
reader.Skip();
return new AetheriaRuntimeEveCommandEnvelope(
schema,
commandId,
providerId,
surfaceId,
command,
issuedAtUtc,
clientId,
payload,
path);
}
private static void WritePayload(ref MessagePackWriter writer, IReadOnlyDictionary<string, string>? payload)
{
payload ??= EmptyPayload();
writer.WriteMapHeader(payload.Count);
foreach (var entry in payload.OrderBy(entry => entry.Key, StringComparer.Ordinal))
{
writer.Write(entry.Key ?? "");
writer.Write(entry.Value ?? "");
}
}
private static IReadOnlyDictionary<string, string> ReadPayload(ref MessagePackReader reader)
{
var count = reader.ReadMapHeader();
if (count == 0)
return EmptyPayload();
var payload = new Dictionary<string, string>(count, StringComparer.Ordinal);
for (var index = 0; index < count; index++)
{
var key = ReadString(ref reader);
var value = ReadString(ref reader);
if (!string.IsNullOrWhiteSpace(key))
payload[key] = value;
}
return payload;
}
private static IReadOnlyDictionary<string, string> EmptyPayload()
{
return new Dictionary<string, string>(0, StringComparer.Ordinal);
}
private static string StableToken(string value)
{
if (string.IsNullOrWhiteSpace(value))
return "empty";
var chars = value
.Select(character => char.IsLetterOrDigit(character) ? character : '-')
.ToArray();
var token = new string(chars).Trim('-').ToLowerInvariant();
while (token.Contains("--", StringComparison.Ordinal))
token = token.Replace("--", "-", StringComparison.Ordinal);
return string.IsNullOrWhiteSpace(token) ? "empty" : token;
}
private static string ReadString(ref MessagePackReader reader)
{
return reader.ReadString() ?? "";
}
}
}

View file

@ -196,8 +196,9 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted.
summaries, or renderer-owned state.
- `AetheriaEveSurfacePresenter` is the first runtime UI Toolkit consumer of
those typed surface documents. It owns mounting only: state file resolution,
surface lookup, lowering, and visible capability gaps for commands. Provider
command acceptance still belongs to the future CultMesh command bridge.
surface lookup, lowering, and command emission into a typed pending queue.
Provider command acceptance still belongs to the future CultMesh command
bridge.
- `GameData/aetheria-world.cc` is now materialized from the importer as the
project-local typed state file for the checked-in catalog. The importer stores
relative provenance in the state document, not machine-local absolute paths.
@ -288,8 +289,9 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted.
`org.gamecult.aetheria.eve-runtime` now adds the Aetheria-specific
`UIDocument` presenter that reads provider-owned Eve surfaces from
`GameData/aetheria-world.cc` and mounts them through the lowerer. Its command
path currently reports the missing CultMesh command bridge instead of
accepting renderer-local command effects.
path queues `gamecult.eve.command.v1` envelopes under
`aetheria-world.cc.eve.pending` for the future CultMesh command bridge
instead of accepting renderer-local command effects.
## Invariants
@ -552,6 +554,13 @@ First Aetheria surfaces to publish:
- Done: add `org.gamecult.aetheria.eve-runtime` with a `UIDocument`
presenter that mounts typed Eve surfaces from `GameData/aetheria-world.cc`
through UI Toolkit without giving the renderer state authority.
- Done: queue renderer-emitted Eve commands as typed
`gamecult.eve.command.v1` envelopes under `.eve.pending`, separate from
runtime state commits so the existing state applicator cannot accidentally
accept commands it does not own.
- Add the CultMesh command bridge that drains `.eve.pending`, validates
command templates, invokes provider-owned command handlers, and republishes
accepted state.
- Wire the presenter into a Unity scene/prefab for the first runtime surface
and replace a concrete uGUI screen.
- Move the staged packages into the Eve repo once its worktree is clean, then
@ -627,7 +636,8 @@ First Aetheria surfaces to publish:
CultCache store. The smoke proves the Unity runtime state commit log can
queue player-settings and run snapshot commands, the `Aetheria.State` node
can apply them into canonical typed settings/run/zone/entity state, and
commands are cleared after application.
commands are cleared after application. It also proves renderer-emitted Eve
commands are queued as typed command envelopes separately from state commits.
- Unity play smoke proves runtime UI reads from Eve surfaces and sends commands
through the shared state service.
- UI Toolkit lowering parity compares Aetheria surfaces against the Eve browser