From b867e688e2720a143161f44f12780e74128afa18 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 13 Jun 2026 16:44:24 +0100 Subject: [PATCH] Queue Eve surface commands as typed state --- .voidbot/state/aetheria.cc | Bin 38193 -> 40589 bytes Aetheria.State.Unity.Smoke/Program.cs | 24 +++ .../Aetheria.State.Unity.csproj | 1 + .../README.md | 11 +- .../Runtime/AetheriaEveSurfacePresenter.cs | 9 +- .../Runtime/AetheriaRuntimeEveCommandLog.cs | 199 ++++++++++++++++++ docs/aetheria-perfect-machine-map.md | 20 +- 7 files changed, 250 insertions(+), 14 deletions(-) create mode 100644 Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveCommandLog.cs diff --git a/.voidbot/state/aetheria.cc b/.voidbot/state/aetheria.cc index fe3ace4cee27ff5df6841f787eeca1523b502171..91ad1ea4775905390c95d98451515d410755c171 100644 GIT binary patch delta 2097 zcmZ`)&2Jk;6j#zvkx1={2<4FSlpcDhz1T^cCQ+plLO~G)rLIe>h|75Q*`8*1W|^6_ zYbw>15C>WnfmVn=pnN0+q(%V=At5gG#HBYBF8mo>c{BTAH;CKr%)GDP`~BYAe?0l{ z*U2Z}OwOEJTB~31Rxd1Xe?BprKAn6}oUGK{i9GgUd9vhAUYwer|FrS(58Cfy#NI=t zxfBz7x+|4wqKeXk*Qb8Jv+{5^!bqyYW^h=^zSbC;E-KE}u!mJ&MiCQ1^@9WxTwAOy zE>~;I)%sF;ck0Z{{#z`F7Tsos1gzO*9qlytXhJ5}vpAMDiQzVbj@bYV~R|kr$SqHb6zmw-Y zERs%aaX=t~Hq0Qjd5DyY^AJQDCk*PqJN~X>yVQ>`0ydvmQlS3j2^jOFP zn>8H(^L>nsEk$F7S>V7dtVWIMb2Fp>20}D0Wt&Xd<`$9#xy%c({Zp5|H7G18|C*Q| z<4P#|L_R7A09L*Sw~Ia8UhS?i-H=YE@+II{e-rX5fsd7B*O3rui5r)kV3e*A}PL>E-c>W z)Sj|!ET(Wiqh^E8gpe*};;}Hcn+3)ML0%uFZy=Dwe*2cN^7btNQfx+&r3wR*-8erhB@c9w78s=XR4|!#tOu*> zaY3ekoIWwE5cWN}LywBfl3Eo(d+>&Ig|{UYV+Y9y7GWf) z4Emf&_Kq7jK8RdhIj4-D81FF?KJ~VNZJmDfNMZZ%N_z3Ni!U4WwEYOtXI;R8<%-^jM$?AWQR=&tE0F)%B)eM zM6B@<@joLWJ$tj3{<%VX9otP1eNrb*sq@+>|1t%yCCnGz1i?Ni6z)C-# zxh0cw2GQG0aD*^ga-#CSM?043zkxF);Fr>S{Zr|)+6(DtNqzRGEg~v4S_&B3Aw$1+ zYcapEF^LX;`(v5oxQr~c6RfV-^!Eo k`CdPsuH2V})#^(6IYj7{+xCu_V?WOzoXm&NB{r; delta 178 zcmeC(%d~M7(}rbCll!XKnN5tMCNhdn-Y|)6@@b}4h>$s0D4)3s!nFi*Iap+6TfVif zEl$oz%}oqTEh^5;&tqI!oRMEt5|Ub!J882M%aQ8MNu9i$Ky6%;FEUGjwVOh;ZNg*nau8$=JF~fQ6ae2QK 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 { ["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"); diff --git a/Aetheria.State.Unity/Aetheria.State.Unity.csproj b/Aetheria.State.Unity/Aetheria.State.Unity.csproj index 8f8348024..f3c8bcf79 100644 --- a/Aetheria.State.Unity/Aetheria.State.Unity.csproj +++ b/Aetheria.State.Unity/Aetheria.State.Unity.csproj @@ -11,6 +11,7 @@ + diff --git a/Packages/org.gamecult.aetheria.eve-runtime/README.md b/Packages/org.gamecult.aetheria.eve-runtime/README.md index 2448ec1df..fd5d70f51 100644 --- a/Packages/org.gamecult.aetheria.eve-runtime/README.md +++ b/Packages/org.gamecult.aetheria.eve-runtime/README.md @@ -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. diff --git a/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs b/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs index 85dbed9f0..20789c9d4 100644 --- a/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs +++ b/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs @@ -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}"); } } } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveCommandLog.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveCommandLog.cs new file mode 100644 index 000000000..27d116405 --- /dev/null +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveCommandLog.cs @@ -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 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 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(); + 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(request.Payload, StringComparer.Ordinal), + finalPath); + } + + public static IReadOnlyList ReadPending(string stateFilePath) + { + var pendingDirectory = GetPendingDirectory(stateFilePath); + if (!Directory.Exists(pendingDirectory)) + return Array.Empty(); + + 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? 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 ReadPayload(ref MessagePackReader reader) + { + var count = reader.ReadMapHeader(); + if (count == 0) + return EmptyPayload(); + + var payload = new Dictionary(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 EmptyPayload() + { + return new Dictionary(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() ?? ""; + } + } +} diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index 3df9c5ce3..d2538cc88 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -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