From 66d9cb43f9ad56792c158da05354acc26f2c8d9f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 14 Jun 2026 08:47:06 +0100 Subject: [PATCH] Use typed documents for Eve pending commands --- .voidbot/state/aetheria.cc | Bin 78708 -> 78984 bytes Aetheria.State/Aetheria.State.csproj | 1 + Aetheria.State/AetheriaEveCommandBridge.cs | 59 +------- Aetheria.State/README.md | 2 +- .../AetheriaRuntimeEveCommandDocument.cs | 73 +++++++++ .../Runtime/AetheriaRuntimeEveCommandLog.cs | 143 +++++------------- docs/aetheria-perfect-machine-map.md | 20 ++- 7 files changed, 131 insertions(+), 167 deletions(-) create mode 100644 Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveCommandDocument.cs diff --git a/.voidbot/state/aetheria.cc b/.voidbot/state/aetheria.cc index c9ef6df34c69a5e120fd293053811fff88dff8c3..cf7833bbe6645de91dc1e27379bcf0bb5410e67d 100644 GIT binary patch delta 1639 zcmZuy-)kI29B0yN^wI~ZG^GiR{WfWm26KC9dWp7?`e0gwR;?wiAVqF&cP=+(cV?ZL zy?7NlOB4isuq-(5idMk~Er`#3_CZtVgZTqQeNymEANqlk*27Dzvdm@wKN9wj%QymBoOhDQvvp@sqOu-i|O zBMT5x!8Ej_=|H0Kafd1vfa%3}Eo*pR_#x%d4tZ!RCkPyJFS+d+nl_vwlLwnCU^@2w zlVox@Urzto9_z0TdT4r3z{k|zpz91a6*o+2(60HA-(vVaL;Od8=Ut}|E7|1%Q#FlO zpm7{>pBkxjy`^}tj%@_^?w&%RDUSNuo?&oA)|M&8#7OZE4M$970#Rc6yE#)VNbNPGs0Zdz}WyjTU)wCS-fv(Y3u z_E<&+#P&XrlYI{^<*g3L-`6DL860~X^}sCrpE1#KA#X8-iibT16d`W~rAVAGa#!Wt zMSF>_xQu=}K}PN36uFoF`NrAwC;CJ>@?fOmLX*CH^Z0OM&4n3A8%EDsEs31!S+ zb?p`V(J69eL?BNDb|N(9Uk?Jc$H8SO)E1}1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&VpmhQ|^_T2t*Z#LbVb@p_*G*2!0rRlyo%6=$Ar<=tdopc}9nHq;rWtr2**!$zq Si#~MY<}vo;{xY_F^1^?nSN*^M diff --git a/Aetheria.State/Aetheria.State.csproj b/Aetheria.State/Aetheria.State.csproj index 1f5cca75b..b6b8a8178 100644 --- a/Aetheria.State/Aetheria.State.csproj +++ b/Aetheria.State/Aetheria.State.csproj @@ -9,6 +9,7 @@ + diff --git a/Aetheria.State/AetheriaEveCommandBridge.cs b/Aetheria.State/AetheriaEveCommandBridge.cs index bf3d81610..958a91852 100644 --- a/Aetheria.State/AetheriaEveCommandBridge.cs +++ b/Aetheria.State/AetheriaEveCommandBridge.cs @@ -1,4 +1,5 @@ using Aetheria.State.Documents; +using GameCult.Aetheria.State.Unity; using MessagePack; namespace Aetheria.State; @@ -79,29 +80,12 @@ public static class AetheriaEveCommandBridge return report; } - private static AetheriaPendingEveCommand ReadCommand(string path) + private static AetheriaRuntimeEveCommandDocument ReadCommand(string path) { - var reader = new MessagePackReader(File.ReadAllBytes(path)); - var fields = reader.ReadArrayHeader(); - var command = new AetheriaPendingEveCommand - { - Schema = fields > 0 ? ReadString(ref reader) : "", - CommandId = fields > 1 ? ReadString(ref reader) : "", - ProviderId = fields > 2 ? ReadString(ref reader) : "", - SurfaceId = fields > 3 ? ReadString(ref reader) : "", - Command = fields > 4 ? ReadString(ref reader) : "", - IssuedAtUtc = fields > 5 ? ReadString(ref reader) : "", - ClientId = fields > 6 ? ReadString(ref reader) : "", - Payload = fields > 7 ? ReadPayload(ref reader) : new Dictionary(0, StringComparer.Ordinal), - Path = path - }; - for (var field = 8; field < fields; field++) - reader.Skip(); - - return command; + return MessagePackSerializer.Deserialize(File.ReadAllBytes(path)); } - private static string Validate(AetheriaPendingEveCommand command) + private static string Validate(AetheriaRuntimeEveCommandDocument command) { if (!string.Equals(command.Schema, CommandSchema, StringComparison.Ordinal)) return $"Unexpected Eve command schema '{command.Schema}'."; @@ -123,7 +107,7 @@ public static class AetheriaEveCommandBridge private static void RecordRejection( AetheriaEveCommandApplyReport report, - AetheriaPendingEveCommand command, + AetheriaRuntimeEveCommandDocument command, string reason, string path, List rejected, @@ -161,37 +145,4 @@ public static class AetheriaEveCommandBridge }; } - private static IReadOnlyDictionary ReadPayload(ref MessagePackReader reader) - { - var count = reader.ReadMapHeader(); - 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 string ReadString(ref MessagePackReader reader) - { - return reader.ReadString() ?? ""; - } - - private sealed class AetheriaPendingEveCommand - { - public string Schema { get; set; } = ""; - public string CommandId { get; set; } = ""; - public string ProviderId { get; set; } = ""; - public string SurfaceId { get; set; } = ""; - public string Command { get; set; } = ""; - public string IssuedAtUtc { get; set; } = ""; - public string ClientId { get; set; } = ""; - public IReadOnlyDictionary Payload { get; set; } = - new Dictionary(0, StringComparer.Ordinal); - public string Path { get; set; } = ""; - } } diff --git a/Aetheria.State/README.md b/Aetheria.State/README.md index 7869b24a3..78b9d9e3b 100644 --- a/Aetheria.State/README.md +++ b/Aetheria.State/README.md @@ -34,7 +34,7 @@ Unity settings, loadout templates, and run checkpoints now queue typed into canonical typed state through `AetheriaRuntimeCommitLogApplier`; the Unity-side command log is command-only and cannot become durable truth by itself. -Unity Eve surfaces also emit `gamecult.eve.command.v1` envelopes under +Unity Eve surfaces also emit typed `gamecult.eve.command.v1` documents under `GameData/aetheria-world.cc.eve.pending`. `AetheriaEveCommandBridge` is the provider-owned acceptance organ for those commands: it validates the provider, surface, and command template before running the narrow refresh handlers for diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveCommandDocument.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveCommandDocument.cs new file mode 100644 index 000000000..752487968 --- /dev/null +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveCommandDocument.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +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; } + } + + [MessagePackObject] + public sealed class AetheriaRuntimeEveCommandDocument + { + public const string SchemaId = "gamecult.eve.command.v1"; + + [Key(0)] + public string Schema { get; set; } = SchemaId; + + [Key(1)] + public string CommandId { get; set; } = ""; + + [Key(2)] + public string ProviderId { get; set; } = ""; + + [Key(3)] + public string SurfaceId { get; set; } = ""; + + [Key(4)] + public string Command { get; set; } = ""; + + [Key(5)] + public string IssuedAtUtc { get; set; } = ""; + + [Key(6)] + public string ClientId { get; set; } = ""; + + [Key(7)] + public Dictionary Payload { get; set; } = new Dictionary(StringComparer.Ordinal); + } +} diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveCommandLog.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveCommandLog.cs index 372578ddc..c9c61dff6 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveCommandLog.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveCommandLog.cs @@ -1,5 +1,4 @@ using System; -using System.Buffers; using System.Collections.Generic; using System.IO; using System.Linq; @@ -10,44 +9,9 @@ using MessagePack; 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 const string CommandSchema = AetheriaRuntimeEveCommandDocument.SchemaId; public static string GetPendingDirectory(string stateFilePath) { @@ -73,33 +37,32 @@ namespace GameCult.Aetheria.State.Unity $"{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(); + var document = new AetheriaRuntimeEveCommandDocument + { + Schema = CommandSchema, + CommandId = commandId, + ProviderId = request.ProviderId ?? "", + SurfaceId = request.SurfaceId ?? "", + Command = request.Command ?? "", + IssuedAtUtc = issuedAtUtc, + ClientId = request.ClientId ?? "", + Payload = CopyPayload(request.Payload) + }; - File.WriteAllBytes(tempPath, buffer.WrittenSpan.ToArray()); + File.WriteAllBytes(tempPath, MessagePackSerializer.Serialize(document)); 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), + document.Schema, + document.CommandId, + document.ProviderId, + document.SurfaceId, + document.Command, + document.IssuedAtUtc, + document.ClientId, + document.Payload, finalPath); } @@ -118,61 +81,33 @@ namespace GameCult.Aetheria.State.Unity 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(); + var document = MessagePackSerializer.Deserialize(File.ReadAllBytes(path)); return new AetheriaRuntimeEveCommandEnvelope( - schema, - commandId, - providerId, - surfaceId, - command, - issuedAtUtc, - clientId, - payload, + document.Schema ?? "", + document.CommandId ?? "", + document.ProviderId ?? "", + document.SurfaceId ?? "", + document.Command ?? "", + document.IssuedAtUtc ?? "", + document.ClientId ?? "", + document.Payload ?? EmptyPayload(), path); } - private static void WritePayload(ref MessagePackWriter writer, IReadOnlyDictionary? payload) + private static Dictionary CopyPayload(IReadOnlyDictionary? payload) { - payload ??= EmptyPayload(); - writer.WriteMapHeader(payload.Count); - foreach (var entry in payload.OrderBy(entry => entry.Key, StringComparer.Ordinal)) + var copy = new Dictionary(StringComparer.Ordinal); + foreach (var entry in (payload ?? EmptyPayload()).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; + if (!string.IsNullOrWhiteSpace(entry.Key)) + copy[entry.Key] = entry.Value ?? ""; } - return payload; + return copy; } - private static IReadOnlyDictionary EmptyPayload() + private static Dictionary EmptyPayload() { return new Dictionary(0, StringComparer.Ordinal); } @@ -191,9 +126,5 @@ namespace GameCult.Aetheria.State.Unity 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 764db8b5a..b45295e23 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -32,9 +32,9 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. from the `.cc` directory store before constructing the temporary legacy `ItemManager`. Player settings saves, loadout saves, shutdown checkpoints, and wormhole transition checkpoints now queue typed `.cc.pending` Verse - commit commands through the embedded runtime state package. Run checkpoint - commands include the current zone plus its runtime entity snapshots. - `Aetheria.State` owns applying those command envelopes into canonical + commit documents through the embedded runtime state package. Run checkpoint + documents include the current zone plus its runtime entity snapshots. + `Aetheria.State` owns applying those command documents into canonical `AetheriaPlayerSettings`, `AetheriaLoadoutTemplate`, `AetheriaRunState`, `AetheriaZoneState`, and `AetheriaEntitySnapshot` documents through `AetheriaStateNode`. Local run saves, loadouts, player settings files, zone @@ -42,8 +42,8 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. legacy `RuntimePlayerSettings` runtime object is no longer named or decorated as a MessagePack persistence shape. `Economy.Server` now drains `aetheria-world.cc.pending` - into canonical typed state and drains `aetheria-world.cc.eve.pending` through - the provider-owned Eve command bridge on startup and on a daemon polling loop + into canonical typed state and drains typed `aetheria-world.cc.eve.pending` + command documents through the provider-owned Eve command bridge on startup and on a daemon polling loop while hosting the CultMesh state node. `Aetheria.State.ApplyPending` remains a bounded local operator applicator for both pending lanes. - Shared item domain state is still partly built around `RuntimeItemReference`, @@ -325,6 +325,12 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. successfully applied command files by default. It is an operational bridge, not a second state owner; the applicator delegates all writes to `AetheriaStateNode`. +- `AetheriaRuntimeEveCommandLog` emits typed + `AetheriaRuntimeEveCommandDocument` files under + `aetheria-world.cc.eve.pending`; `AetheriaEveCommandBridge` consumes the + same shared document type, validates provider/surface/command authority, and + deletes accounted command files. The Eve pending lane is command transport, + not renderer-owned state. - `Economy.Server` hosts the CultMesh state node and now owns the long-running pending runtime commit drain loop. `--apply-pending-once` runs the same drain path once for smoke/operator use without keeping the process alive. @@ -893,7 +899,7 @@ First Aetheria surfaces to publish: 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 + `gamecult.eve.command.v1` documents under `.eve.pending`, separate from runtime state commits so the existing state applicator cannot accidentally accept commands it does not own. - Done: add the provider-owned Eve command bridge that drains `.eve.pending`, @@ -904,6 +910,8 @@ First Aetheria surfaces to publish: `AetheriaEveCommandBridge`; renderer/runtime command files are queued through `AetheriaRuntimeEveCommandLog`, while the provider bridge only validates, applies, reports, and deletes accounted commands. + - Done: replace the `.eve.pending` command lane's private raw MessagePack + array protocol with shared `AetheriaRuntimeEveCommandDocument` files. - Extend the command bridge beyond refresh commands as gameplay/editor Eve surfaces acquire provider-owned handlers. - Wire the presenter into a Unity scene/prefab for the first runtime surface