diff --git a/.voidbot/state/aetheria.cc b/.voidbot/state/aetheria.cc index c9ef6df34..cf7833bbe 100644 Binary files a/.voidbot/state/aetheria.cc and b/.voidbot/state/aetheria.cc differ 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