From 7d96c42a3c98e4e5ed659f3982c7bdd7a31e94ee Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 8 Jul 2026 22:35:32 +0100 Subject: [PATCH] Add Mimir Move proof pipeline --- docs/implementation-plan.md | 8 + notes/current-system-map.md | 5 + src/Mimir.BufferSmoke/Program.cs | 145 ++++++++++++++++++ .../Synchronization/MimirMoveProofPipeline.cs | 130 ++++++++++++++++ .../Synchronization/MimirMoveProofSurface.cs | 7 +- state/evidence.jsonl | 1 + state/map.yaml | 6 + 7 files changed, 300 insertions(+), 2 deletions(-) create mode 100644 src/Mimir.Runtime/Synchronization/MimirMoveProofPipeline.cs diff --git a/docs/implementation-plan.md b/docs/implementation-plan.md index 9779636..4fec194 100644 --- a/docs/implementation-plan.md +++ b/docs/implementation-plan.md @@ -82,6 +82,14 @@ a named invariant that the native runtime cannot protect yet. `muninn:nightwing:move-evidence:79 -> mimir:starfire:move-evidence:79 -> mimir:starfire:move-pose:79 -> fensalir:starfire:presented-frame:79` chain, and rejects single-ray fallback as not full pose. +- `MimirMoveProofPipeline` is the shared commit primitive for the live Move + proof path. It starts from a Muninn CultMesh shared-memory evidence frame, + admits samples to the native `move_evidence` reservoir, runs Mimir-owned + fusion, creates the Mimir pose stream frame, creates the proof surface, and + returns the Fensalir spline probe in one pass. `Mimir.BufferSmoke + --move-proof-pipeline-smoke` proves that shape against the native reservoir + debug DLL; live hardware and presented-frame capture still need to call this + primitive instead of hand-assembling a parallel path. - `MimirMoveCalibrationProtocol` publishes the typed calibration preflight for Starfire/Nightwing Moves: required Muninn evidence streams, optional Quest headset/controller pose witnesses, stillness/sweep/validation phases, and diff --git a/notes/current-system-map.md b/notes/current-system-map.md index b3a3b6d..1970e21 100644 --- a/notes/current-system-map.md +++ b/notes/current-system-map.md @@ -207,6 +207,11 @@ frame, emits `mimir.move_proof_surface.v1`, and lowers an observer-only chain. It does not decide pose. Single-ray fallback remains a visible non-final verdict until calibrated multi-camera optical evidence earns full pose. +`MimirMoveProofPipeline` is now the reusable commit primitive for that chain: +from one Muninn CultMesh shared-memory frame it performs native admission, +Mimir fusion, pose-frame creation, proof-surface creation, and Fensalir probe +lowering. Live Nightwing/Starfire wiring should call this owner path rather +than preserving separate manual actions and programmatic proof paths. ## Program Composition diff --git a/src/Mimir.BufferSmoke/Program.cs b/src/Mimir.BufferSmoke/Program.cs index e22e014..d7cf594 100644 --- a/src/Mimir.BufferSmoke/Program.cs +++ b/src/Mimir.BufferSmoke/Program.cs @@ -140,6 +140,12 @@ if (args.Any(arg => string.Equals(arg, "--move-proof-surface-smoke", StringCompa return RunMoveProofSurfaceSmoke(); } +if (args.Any(arg => string.Equals(arg, "--move-proof-pipeline-smoke", StringComparison.OrdinalIgnoreCase))) +{ + return RunMoveProofPipelineSmoke( + ParseStringOption(args, "--native-reservoir", DefaultNativeReservoirPath())); +} + if (args.Any(arg => string.Equals(arg, "--move-calibration-protocol-smoke", StringComparison.OrdinalIgnoreCase))) { return await RunMoveCalibrationProtocolSmokeAsync( @@ -2217,6 +2223,145 @@ static int RunMoveProofSurfaceSmoke() : 1; } +static int RunMoveProofPipelineSmoke(string nativeReservoirPath) +{ + const ulong leftWitnessHash = 0x00000000000A11CE; + const ulong rightWitnessHash = 0x0000000000000B0B; + const string observedAt = "2026-06-11T18:30:00.0040000Z"; + var streamId = "muninn:nightwing:move-evidence"; + var frame = new MimirMuninnMoveEvidenceStreamFrame( + FrameId: "muninn:nightwing:move-evidence:79", + ProducerPeerId: "muninn:nightwing", + PublishedAtNs: 1_781_202_600_005_000_000, + MarkerCandidates: + [ + new MuninnMoveMarkerCandidateDocument( + StreamId: "nightwing:ps3-eye-0:move-marker-candidates", + HostId: "nightwing", + CameraId: "ps3-eye-0", + FrameSequence: 9101, + SourceIdHash: leftWitnessHash, + TileX: 10, + TileY: 10, + CenterXPx: 170.0f, + CenterYPx: 120.0f, + RadiusPx: 12.0f, + AreaPx: 452, + MeanLuma: 0.64f, + PeakLuma: 252, + Score: 0.90f, + ObservedAt: observedAt), + new MuninnMoveMarkerCandidateDocument( + StreamId: "starfire:ps3-eye-1:move-marker-candidates", + HostId: "starfire", + CameraId: "ps3-eye-1", + FrameSequence: 9102, + SourceIdHash: rightWitnessHash, + TileX: 11, + TileY: 10, + CenterXPx: 150.0f, + CenterYPx: 120.0f, + RadiusPx: 12.0f, + AreaPx: 449, + MeanLuma: 0.62f, + PeakLuma: 250, + Score: 0.86f, + ObservedAt: observedAt) + ], + ControllerStates: + [ + new MuninnMoveControllerStateDocument( + StreamId: "nightwing:move-usb:move-controller-state", + HostId: "nightwing", + MoveId: "move-usb", + Sequence: 79, + SourceTimestampNs: 1_781_202_600_004_000_000, + AccelerometerXyz: [-0.01f, 0.10f, 0.99f], + GyroscopeXyz: [0.02f, -0.01f, 0.04f], + MagnetometerXyz: [0.0f, 0.0f, 0.0f], + TriggerValue: 0.5f, + Buttons: ["move", "trigger"], + Battery01: 0.72f, + ObservedAt: observedAt) + ]); + var calibration = new MimirMoveFusionRigCalibration( + CalibrationId: "mimir-move-stage-calibration-v1", + TrackingSpaceId: "mimir-stage-space", + Cameras: + [ + new MimirMoveFusionCameraCalibration( + CameraId: "nightwing:ps3-eye-0", + WitnessIdHash: leftWitnessHash, + PositionMeters: new MimirVector3Snapshot(-0.1, 0.0, 0.0), + Orientation: new MimirQuaternionSnapshot(0.0, 0.0, 0.0, 1.0), + FocalLengthXPx: 100.0, + FocalLengthYPx: 100.0, + PrincipalPointXPx: 160.0, + PrincipalPointYPx: 120.0), + new MimirMoveFusionCameraCalibration( + CameraId: "starfire:ps3-eye-1", + WitnessIdHash: rightWitnessHash, + PositionMeters: new MimirVector3Snapshot(0.1, 0.0, 0.0), + Orientation: new MimirQuaternionSnapshot(0.0, 0.0, 0.0, 1.0), + FocalLengthXPx: 100.0, + FocalLengthYPx: 100.0, + PrincipalPointXPx: 160.0, + PrincipalPointYPx: 120.0) + ], + MaximumAssociationSkewMilliseconds: 20.0); + var catalog = CultMesh.CreateStreamCatalog(); + catalog.Declare(MimirMuninnMoveEvidenceAdapter.CreateStreamDescriptor( + streamId, + "mimir-live", + "muninn:nightwing", + "nightwing:clock")); + using var ring = catalog.CreateSharedMemoryRing(streamId, slotCount: 4, slotByteLength: 8192); + var payload = MimirMuninnMoveEvidenceAdapter.SerializeStreamFrame(frame); + if (!ring.TryPublishCopy(payload, frame.PublishedAtNs, durationNs: 0, out var published)) + { + Console.Error.WriteLine("move-proof-pipeline-smoke publish-failed"); + return 1; + } + + catalog.PublishFrame(published); + using var runtime = new MimirNativeReservoirRuntime(nativeReservoirPath); + var options = new MimirMoveProofPipelineOptions( + MimirEvidenceSourceId: "mimir:starfire:move-evidence", + MimirEvidenceFrameId: "mimir:starfire:move-evidence:79", + MimirPoseFrameId: "mimir:starfire:move-pose:79", + MimirPoseProducerPeerId: "mimir:starfire", + FensalirFrameId: "fensalir:starfire:presented-frame:79", + FensalirPresentedAtNs: 1_781_202_600_007_100_000); + var built = MimirMoveProofPipeline.TryBuildLatestFromRing( + ring, + runtime, + calibration, + options, + out var result); + + Console.WriteLine( + $"move-proof-pipeline-smoke built={built} proof={result?.ProofSurface.ProofId ?? "none"} chain={result?.ProofSurface.MuninnEvidenceFrameId ?? "none"}->{result?.ProofSurface.MimirEvidenceFrameId ?? "none"}->{result?.ProofSurface.MimirPoseFrameId ?? "none"}->{result?.ProofSurface.FensalirFrameId ?? "none"} verdict={result?.ProofSurface.Verdict.ToString() ?? "none"} samples={result?.Admission.SampleCount ?? 0} poses={result?.PoseFrame.Poses.Length ?? 0} splines={result?.FensalirProbeFrame.Splines.Count ?? 0} reservoirEdgeNs={result?.Admission.ReservoirEdgeNs ?? 0}"); + + return built && + result is not null && + result.Admission.FrameId == frame.FrameId && + result.Admission.OpticalMarkerCount == 2 && + result.Admission.ControllerStateCount == 1 && + result.Fusion.Poses.Count == 1 && + result.PoseFrame.FrameId == options.MimirPoseFrameId && + result.PoseFrame.ProducerPeerId == options.MimirPoseProducerPeerId && + result.PoseFrame.Poses.Length == 1 && + result.ProofSurface.IsFullPose && + result.ProofSurface.MimirEvidenceFrameId == options.MimirEvidenceFrameId && + result.ProofSurface.MimirPoseFrameId == options.MimirPoseFrameId && + result.ProofSurface.FensalirFrameId == options.FensalirFrameId && + result.FensalirProbeFrame.HasInput && + result.Admission.Handle.PayloadHandle != 0 && + runtime.Status.MoveEvidenceCount.ToUInt64() == 1 + ? 0 + : 1; +} + static async Task RunMoveCalibrationProtocolSmokeAsync(string outputPath) { var protocol = MimirMoveCalibrationProtocol.CreateStarfireNightwingProtocol( diff --git a/src/Mimir.Runtime/Synchronization/MimirMoveProofPipeline.cs b/src/Mimir.Runtime/Synchronization/MimirMoveProofPipeline.cs new file mode 100644 index 0000000..97bc983 --- /dev/null +++ b/src/Mimir.Runtime/Synchronization/MimirMoveProofPipeline.cs @@ -0,0 +1,130 @@ +using Aquarium.Engine.Render; +using GameCult.Mesh; + +namespace Mimir.Runtime.Synchronization; + +public sealed record MimirMoveProofPipelineResult( + MimirMuninnMoveEvidenceAdmission Admission, + MimirMoveFusionResult Fusion, + MimirMoveControllerPoseStreamFrame PoseFrame, + MimirMoveProofSurfaceDocument ProofSurface, + AquariumSplineFrame FensalirProbeFrame); + +public sealed record MimirMoveProofPipelineOptions( + string MimirEvidenceSourceId, + string MimirEvidenceFrameId, + string MimirPoseFrameId, + string MimirPoseProducerPeerId, + string FensalirFrameId, + ulong FensalirPresentedAtNs, + string FusionAuthorityId = "mimir.runtime.move-fusion", + string ConsumerContract = "fensalir.move-controller-input"); + +public static class MimirMoveProofPipeline +{ + public static bool TryBuildLatestFromRing( + CultMeshSharedMemoryFrameRing ring, + MimirNativeReservoirRuntime runtime, + MimirMoveFusionRigCalibration calibration, + MimirMoveProofPipelineOptions options, + out MimirMoveProofPipelineResult? result) + { + ArgumentNullException.ThrowIfNull(ring); + result = null; + if (!ring.TryAcquireLatestRead(out var lease)) + { + return false; + } + + using (lease) + { + var frame = MimirMuninnMoveEvidenceAdapter.DeserializeStreamFrame(lease.Memory[..lease.Handle.ByteLength]); + return TryBuild( + frame, + runtime, + calibration, + options, + out result); + } + } + + public static bool TryBuild( + MimirMuninnMoveEvidenceStreamFrame frame, + MimirNativeReservoirRuntime runtime, + MimirMoveFusionRigCalibration calibration, + MimirMoveProofPipelineOptions options, + out MimirMoveProofPipelineResult? result) + { + ArgumentNullException.ThrowIfNull(frame); + ArgumentNullException.ThrowIfNull(runtime); + ArgumentNullException.ThrowIfNull(calibration); + ArgumentNullException.ThrowIfNull(options); + result = null; + + var mimirReadAtNs = NowUnixNs(); + var samples = MimirMuninnMoveEvidenceAdapter.BuildNativeSamples(frame.MarkerCandidates, frame.ControllerStates); + if (samples.Count == 0) + { + return false; + } + + var handle = runtime.AdmitMoveEvidence( + options.MimirEvidenceSourceId, + samples, + calibration.CalibrationId, + calibration.TrackingSpaceId); + var status = runtime.Status; + var admission = new MimirMuninnMoveEvidenceAdmission( + FrameId: frame.FrameId, + ProducerPeerId: frame.ProducerPeerId, + PublishedAtNs: frame.PublishedAtNs, + MimirReadAtNs: mimirReadAtNs, + SampleCount: samples.Count, + OpticalMarkerCount: samples.Count(sample => sample.EvidenceKind == (uint)MimirNativeMoveEvidenceKind.OpticalMarker), + ControllerStateCount: samples.Count(sample => sample.EvidenceKind == (uint)MimirNativeMoveEvidenceKind.ControllerState), + SourceTimeMinNs: samples.Min(sample => sample.SourceTimestampNs), + SourceTimeMaxNs: samples.Max(sample => sample.SourceTimestampNs), + ArrivalMinNs: samples.Min(sample => sample.ArrivalNs), + ArrivalMaxNs: samples.Max(sample => sample.ArrivalNs), + Handle: handle, + ReservoirEdgeNs: status.EdgeNs, + ReservoirWindowStartNs: status.WindowStartNs, + ReservoirMoveEvidenceCount: status.MoveEvidenceCount.ToUInt64()); + var fusion = MimirMoveFusion.Fuse( + samples, + calibration, + options.FusionAuthorityId, + options.ConsumerContract); + var poseFrame = MimirMovePoseStream.CreateFrame( + options.MimirPoseFrameId, + options.MimirPoseProducerPeerId, + publishedAtNs: fusion.Poses.Count == 0 + ? checked((long)Math.Min(admission.ArrivalMaxNs, (ulong)long.MaxValue)) + : fusion.Poses.Max(pose => pose.EstimatedAtNs), + calibration.TrackingSpaceId, + calibration.CalibrationId, + fusion.Poses); + var proofSurface = MimirMoveProofSurface.Create( + admission, + poseFrame, + options.FensalirFrameId, + options.FensalirPresentedAtNs, + options.MimirEvidenceFrameId); + var probeFrame = MimirMoveProofSurface.BuildFensalirProbeFrame(proofSurface); + result = new MimirMoveProofPipelineResult( + admission, + fusion, + poseFrame, + proofSurface, + probeFrame); + return true; + } + + private static ulong NowUnixNs() + { + var now = DateTimeOffset.UtcNow; + var secondsNs = checked((ulong)now.ToUnixTimeSeconds() * 1_000_000_000UL); + var tickRemainderNs = checked((ulong)(now.Ticks % TimeSpan.TicksPerSecond) * 100UL); + return checked(secondsNs + tickRemainderNs); + } +} diff --git a/src/Mimir.Runtime/Synchronization/MimirMoveProofSurface.cs b/src/Mimir.Runtime/Synchronization/MimirMoveProofSurface.cs index 60545a8..0b2c953 100644 --- a/src/Mimir.Runtime/Synchronization/MimirMoveProofSurface.cs +++ b/src/Mimir.Runtime/Synchronization/MimirMoveProofSurface.cs @@ -56,7 +56,8 @@ public static class MimirMoveProofSurface MimirMuninnMoveEvidenceAdmission admission, MimirMoveControllerPoseStreamFrame poseFrame, string fensalirFrameId, - ulong fensalirPresentedAtNs) + ulong fensalirPresentedAtNs, + string? mimirEvidenceFrameId = null) { ArgumentNullException.ThrowIfNull(admission); ArgumentNullException.ThrowIfNull(poseFrame); @@ -80,7 +81,9 @@ public static class MimirMoveProofSurface return new MimirMoveProofSurfaceDocument( ProofId: $"{poseFrame.ProducerPeerId}:move-proof:{SequenceSuffix(poseFrame.FrameId)}", MuninnEvidenceFrameId: admission.FrameId, - MimirEvidenceFrameId: $"mimir:starfire:move-evidence:{SequenceSuffix(admission.FrameId)}", + MimirEvidenceFrameId: string.IsNullOrWhiteSpace(mimirEvidenceFrameId) + ? $"mimir:starfire:move-evidence:{SequenceSuffix(admission.FrameId)}" + : mimirEvidenceFrameId, MimirPoseFrameId: poseFrame.FrameId, FensalirFrameId: fensalirFrameId, ProducerPeerId: poseFrame.ProducerPeerId, diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 2a19e5f..5c1abf7 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -160,3 +160,4 @@ {"ts": "2026-07-08T22:18:44+01:00", "type": "decision", "status": "ok", "note": "Muninn serve now has a first daemon-owned Move marker camera producer path: --move-marker-camera = configures a source-local camera, the serve loop polls a platform frame reader, Unix builds use a V4L2 YUYV single-frame reader that converts to compact Y8, and the shared extraction/publish seam emits canonical muninn.move_marker_candidate.v1 records into the Mimir-compatible move-evidence stream. Verified on Windows with cargo test -p muninn-daemon (148 passed) and marker-camera unit tests; Linux cross-target check could not run because x86_64-unknown-linux-gnu target is not installed, and Nightwing hardware live proof remains pending."} {"ts": "2026-07-08T22:21:57+01:00", "type": "verification", "status": "ok", "note": "Correction to the earlier Move marker camera evidence: after installing/using the x86_64-unknown-linux-gnu Rust target, Muninn's V4L2 YUYV Move marker camera producer compiled with cargo check -p muninn-daemon --target x86_64-unknown-linux-gnu. cargo test -p muninn-daemon passes 148 tests. Nightwing hardware live proof remains pending, so this proves owned producer code and target compatibility, not calibrated live pose."} {"ts": "2026-07-08T22:28:32+01:00", "type": "implementation", "status": "ok", "note": "Added MimirMoveProofSurface as the first observer-only Fensalir-visible Move proof surface: it combines a Muninn evidence admission receipt, Mimir pose stream frame, and Fensalir presentation/probe timestamp into mimir.move_proof_surface.v1, lowers a dev AquariumSplineFrame probe, preserves source/publish/read/admit/fusion/present timing, and refuses to treat single-ray fallback as full pose. Verified dotnet build Mimir.Runtime, dotnet build Mimir.BufferSmoke, BufferSmoke --move-proof-surface-smoke, and BufferSmoke --move-fusion-smoke. Live Nightwing hardware, calibrated camera witnesses, and actual Fensalir presented-frame capture remain pending."} +{"ts": "2026-07-08T22:34:00+01:00", "type": "implementation", "status": "ok", "note": "Added MimirMoveProofPipeline as the shared commit primitive for one Move proof frame: it reads a Muninn CultMesh shared-memory evidence frame, admits samples to native move_evidence, runs MimirMoveFusion, emits the mimir:starfire move-pose frame, creates mimir.move_proof_surface.v1, and lowers the Fensalir spline probe in one pass. Verified dotnet build Mimir.Runtime, dotnet build Mimir.BufferSmoke, and BufferSmoke --move-proof-pipeline-smoke against the native reservoir debug DLL. This proves the reusable Mimir owner path; live Nightwing hardware, calibrated camera witnesses, and actual presented-frame capture remain pending."} diff --git a/state/map.yaml b/state/map.yaml index 98be669..a449a0a 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -137,6 +137,12 @@ accepted_design: becoming a pose owner. Single-ray fallback is surfaced as non-final; only triangulated calibrated optical marker evidence can earn a full-pose verdict. + - `MimirMoveProofPipeline` is the single shared commit primitive for one + Move proof frame. It reads a Muninn CultMesh evidence frame, admits native + `move_evidence`, runs Mimir fusion, emits the Mimir pose frame, creates the + proof surface, and returns the Fensalir spline probe. Direct user actions, + programmatic smokes, and future live subscribers should use this same path + so the proof chain does not split into separately repaired truths. - `MimirMoveCalibrationProtocol` defines the runnable Starfire/Nightwing Move calibration preflight as typed state: required Muninn Move evidence streams, optional Quest headset/controller pose witnesses over USB,