Add CultMesh Eve dashboard and sensor lanes

This commit is contained in:
Meta Vens 2026-05-31 12:43:28 +01:00
commit 48ce102270
7 changed files with 239 additions and 4 deletions

View file

@ -49,6 +49,12 @@ EveCanvas connects to:
ws://192.168.1.66:8795/eve/deck
```
Periwinkle's Android Eve client uses the binary CultMesh lane:
```text
ws://192.168.1.66:8795/eve/deck/cultmesh
```
The compatibility endpoint remains:
```text
@ -116,6 +122,9 @@ The broker smoke on 2026-05-31 verified:
CultMesh dashboard document name.
- `/eve/deck/providers` returns the built-in provider manifests.
- WebSocket `/eve/deck` sends the switchboard snapshot.
- WebSocket `/eve/deck/cultmesh` sends the same provider state as
`mimir.eve_dashboard_state.v1` MessagePack and accepts
`mimir.eve_dashboard_command.v1` MessagePack command documents.
- `open-provider` switches to `mimir.stream.layout` and broadcasts that
provider state.
- `open-provider` switches to `voidbot.swarm`, which emits VoidBot's swarm

View file

@ -106,3 +106,13 @@ The Eve sensor receiver can be checked without launching the whole runtime:
```powershell
dotnet run --project .\src\Mimir.EveSensorReceiver\Mimir.EveSensorReceiver.csproj -- --port 8793 --path /eve/camera --source-id eve-camera --type video-frame
```
Periwinkle's Android Eve client publishes binary CultMesh sensor observations:
```powershell
dotnet run --project .\src\Mimir.EveSensorReceiver\Mimir.EveSensorReceiver.csproj -- --port 8796 --path /eve/periwinkle --source-id periwinkle-accelerometer --type cultmesh-observation
```
The receiver accepts `mimir.eve_sensor_observation.v1` MessagePack packets on
that lane. The device remains an observation source; Mimir owns synchronization
and interpretation.

View file

@ -9,4 +9,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\CultLib\src\GameCult.Caching.MessagePack\GameCult.Caching.MessagePack.csproj" />
<ProjectReference Include="..\Mimir.Runtime\Mimir.Runtime.csproj" />
</ItemGroup>
</Project>

View file

@ -5,6 +5,8 @@ using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using MessagePack;
using Mimir.Runtime.Synchronization;
var port = ParseInt(args, "--port", 8795);
var voidBotSwarmStatePath = ParseString(args, "--voidbot-swarm-state", @"E:\Projects\VoidBot\.voidbot\status\swarm-state.json");
@ -117,7 +119,7 @@ internal sealed class EveDashboardServer(int port, EveDashboardProviderCatalog p
return;
}
if (!IsDashboardPath(request.Path, out var requestedProviderId) ||
if (!IsDashboardPath(request.Path, out var requestedProviderId, out var cultMeshBinary) ||
!request.Headers.TryGetValue("Sec-WebSocket-Key", out var key))
{
await WriteHttpResponseAsync(stream, "404 Not Found", "text/plain", Encoding.UTF8.GetBytes("not found")).ConfigureAwait(false);
@ -131,7 +133,7 @@ internal sealed class EveDashboardServer(int port, EveDashboardProviderCatalog p
await WriteWebSocketHandshakeAsync(stream, key).ConfigureAwait(false);
var id = Guid.NewGuid();
var socket = new DashboardSocket(tcpClient, stream);
var socket = new DashboardSocket(tcpClient, stream, cultMeshBinary);
clients[id] = socket;
await SendStateAsync(socket).ConfigureAwait(false);
try
@ -145,6 +147,16 @@ internal sealed class EveDashboardServer(int port, EveDashboardProviderCatalog p
break;
}
if (frame.Opcode == 0x2 && cultMeshBinary)
{
if (ApplyCultMeshCommand(frame.Payload))
{
await BroadcastStateAsync().ConfigureAwait(false);
}
continue;
}
if (frame.Opcode != 0x1)
{
continue;
@ -163,9 +175,24 @@ internal sealed class EveDashboardServer(int port, EveDashboardProviderCatalog p
}
}
private static bool IsDashboardPath(string path, out string providerId)
private static bool IsDashboardPath(string path, out string providerId, out bool cultMeshBinary)
{
providerId = "";
cultMeshBinary = false;
if (path == "/eve/deck/cultmesh")
{
cultMeshBinary = true;
return true;
}
const string cultMeshProviderPrefix = "/eve/deck/cultmesh/";
if (path.StartsWith(cultMeshProviderPrefix, StringComparison.Ordinal))
{
providerId = Uri.UnescapeDataString(path[cultMeshProviderPrefix.Length..]);
cultMeshBinary = true;
return !string.IsNullOrWhiteSpace(providerId);
}
if (path == "/eve/dashboard" || path == "/eve/deck")
{
return true;
@ -181,6 +208,33 @@ internal sealed class EveDashboardServer(int port, EveDashboardProviderCatalog p
return false;
}
private bool ApplyCultMeshCommand(byte[] payload)
{
MimirEveDashboardCommandDocument? commandDocument;
try
{
commandDocument = MessagePackSerializer.Deserialize<MimirEveDashboardCommandDocument>(payload);
}
catch
{
return false;
}
var command = new DashboardCommand
{
Type = commandDocument.Type,
NodeId = commandDocument.NodeId,
ProviderId = commandDocument.ProviderId,
X = commandDocument.X,
Y = commandDocument.Y,
Rotation = commandDocument.Rotation,
Scale = commandDocument.Scale,
Visible = commandDocument.Visible,
};
return ApplyCommand(JsonSerializer.Serialize(command, JsonOptions));
}
private bool ApplyCommand(string text)
{
DashboardCommand? command;
@ -233,6 +287,35 @@ internal sealed class EveDashboardServer(int port, EveDashboardProviderCatalog p
private async Task SendStateAsync(DashboardSocket socket)
{
var state = providers.Get(activeProviderId).State;
if (socket.CultMeshBinary)
{
var document = new MimirEveDashboardStateDocument(
state.ProviderId,
state.Title,
state.Version,
state.UpdatedAt.ToString("O"),
state.SelectedNodeId,
state.LutPreset,
state.Nodes.Select(static node => new MimirEveDashboardNodeSnapshot(
node.Id,
node.Label,
node.Kind,
node.Visible,
node.X,
node.Y,
node.Z,
node.Rotation,
node.Scale,
node.Width,
node.Height,
node.Health,
node.ProviderId,
node.Command,
node.Endpoint)).ToArray());
await SendBinaryFrameAsync(socket.Stream, MessagePackSerializer.Serialize(document)).ConfigureAwait(false);
return;
}
await SendTextFrameAsync(socket.Stream, JsonSerializer.Serialize(state, JsonOptions)).ConfigureAwait(false);
}
@ -339,6 +422,36 @@ internal sealed class EveDashboardServer(int port, EveDashboardProviderCatalog p
await stream.WriteAsync(payload).ConfigureAwait(false);
}
private static async Task SendBinaryFrameAsync(NetworkStream stream, byte[] payload)
{
var header = BuildFrameHeader(0x82, payload.Length);
await stream.WriteAsync(header).ConfigureAwait(false);
await stream.WriteAsync(payload).ConfigureAwait(false);
}
private static byte[] BuildFrameHeader(byte opcode, int payloadLength)
{
var header = new List<byte> { opcode };
if (payloadLength < 126)
{
header.Add((byte)payloadLength);
}
else if (payloadLength <= ushort.MaxValue)
{
header.Add(126);
header.Add((byte)(payloadLength >> 8));
header.Add((byte)payloadLength);
}
else
{
header.Add(127);
var length = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((long)payloadLength));
header.AddRange(length);
}
return header.ToArray();
}
private static async Task<WebSocketFrame> ReceiveFrameAsync(NetworkStream stream)
{
var header = new byte[2];
@ -1258,7 +1371,7 @@ internal sealed record HttpRequest(string Path, IReadOnlyDictionary<string, stri
internal sealed record WebSocketFrame(int Opcode, byte[] Payload);
internal sealed record DashboardSocket(TcpClient Client, NetworkStream Stream);
internal sealed record DashboardSocket(TcpClient Client, NetworkStream Stream, bool CultMeshBinary);
internal sealed record DashboardProviderCatalogDocument(IReadOnlyList<DashboardProviderManifest> Providers);

View file

@ -9,4 +9,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\CultLib\src\GameCult.Caching.MessagePack\GameCult.Caching.MessagePack.csproj" />
<ProjectReference Include="..\Mimir.Runtime\Mimir.Runtime.csproj" />
</ItemGroup>
</Project>

View file

@ -3,6 +3,8 @@ using System.Net.Sockets;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using MessagePack;
using Mimir.Runtime.Synchronization;
var options = EveSensorReceiverOptions.Parse(args);
using var receiver = new EveSensorReceiver(options);
@ -92,6 +94,17 @@ internal sealed class EveSensorReceiver(EveSensorReceiverOptions options) : IDis
break;
}
if (frame.Opcode == 0x2)
{
if (TryValidateCultMeshObservation(frame.Payload, out var normalizedObservation))
{
Console.WriteLine(normalizedObservation);
Console.Out.Flush();
}
continue;
}
if (frame.Opcode != 0x1)
{
continue;
@ -134,6 +147,46 @@ internal sealed class EveSensorReceiver(EveSensorReceiverOptions options) : IDis
}
}
private bool TryValidateCultMeshObservation(byte[] payload, out string normalized)
{
normalized = "";
try
{
var observation = MessagePackSerializer.Deserialize<MimirEveSensorObservationDocument>(payload);
if (!string.Equals(observation.StreamId, options.SourceId, StringComparison.Ordinal) &&
!string.Equals(options.ExpectedType, "cultmesh-observation", StringComparison.OrdinalIgnoreCase))
{
return false;
}
normalized = JsonSerializer.Serialize(new
{
type = "cultmesh-observation",
document = "mimir.eve_sensor_observation.v1",
observation.ObservationId,
observation.DeviceId,
observation.StreamId,
observation.Kind,
observation.Sequence,
observation.SensorTimestampNs,
observation.ElapsedRealtimeNs,
observation.WallClockUtc,
observation.ClockDomainId,
observation.Values,
observation.Action,
observation.PointerCount,
observation.X,
observation.Y,
observation.Accuracy,
});
return true;
}
catch
{
return false;
}
}
private static async Task<HttpRequest> ReadHttpRequestAsync(NetworkStream stream)
{
var bytes = new List<byte>();

View file

@ -149,6 +149,46 @@ public sealed record MimirEveDashboardNodeSnapshot(
[property: Key(13)] string? Command,
[property: Key(14)] string? Endpoint);
[CultDocument("mimir.eve_dashboard_command", "mimir.eve_dashboard_command.v1")]
[MessagePackObject]
public sealed record MimirEveDashboardCommandDocument(
[property: Key(0)]
[property: CultName]
string CommandId,
[property: Key(1)] string DeviceId,
[property: Key(2)] string ClientId,
[property: Key(3)] string ProviderId,
[property: Key(4)] string Type,
[property: Key(5)] string NodeId,
[property: Key(6)] double? X,
[property: Key(7)] double? Y,
[property: Key(8)] double? Rotation,
[property: Key(9)] double? Scale,
[property: Key(10)] bool? Visible,
[property: Key(11)] long Sequence,
[property: Key(12)] long DeviceTimestampNs);
[CultDocument("mimir.eve_sensor_observation", "mimir.eve_sensor_observation.v1")]
[MessagePackObject]
public sealed record MimirEveSensorObservationDocument(
[property: Key(0)]
[property: CultName]
string ObservationId,
[property: Key(1)] string DeviceId,
[property: Key(2)] string StreamId,
[property: Key(3)] string Kind,
[property: Key(4)] long Sequence,
[property: Key(5)] long SensorTimestampNs,
[property: Key(6)] long ElapsedRealtimeNs,
[property: Key(7)] string WallClockUtc,
[property: Key(8)] string ClockDomainId,
[property: Key(9)] double[] Values,
[property: Key(10)] string? Action,
[property: Key(11)] int? PointerCount,
[property: Key(12)] double? X,
[property: Key(13)] double? Y,
[property: Key(14)] int? Accuracy);
public static class MimirCultMeshContractFactory
{
public static MimirBioacousticCodebookState CreateCodebookState(