diff --git a/docs/implementation-plan.md b/docs/implementation-plan.md index 4f48493..43e5656 100644 --- a/docs/implementation-plan.md +++ b/docs/implementation-plan.md @@ -110,9 +110,17 @@ a named invariant that the native runtime cannot protect yet. and pose frame prefixes, Fensalir presented-frame prefix, fusion authority, consumer contract, and at least two calibrated camera witnesses. It creates `MimirMoveProofRuntimeDriver` only after the supplied ring stream id matches - the configured evidence stream. The current C# CultMesh ring used by the - smoke is still in-process; real Nightwing/Starfire cross-process ring opening - remains pending. + the configured evidence stream. +- `MimirRuntime` now owns configured Move proof activation instead of leaving + config as a readout. At scene-ready it asks an + `IMimirMoveProofEvidenceRingProvider` for the configured Muninn evidence ring, + opens the configured native reservoir, creates the driver, retains the + resources, and exposes an activation status. The default provider fails + explicitly because the current C# CultMesh ring is still in-process only; + `Mimir.BufferSmoke --move-proof-runtime-activation-smoke` injects an + in-process provider and proves config activation can produce the same named + proof chain. Real Nightwing/Starfire cross-process ring opening remains + pending. - `MimirMoveProofDevSurface` is a dev-only bootstrap gated by `MIMIR_MOVE_PROOF_DEV_SURFACE`. It uses the same runtime proof attachment so `Mimir.BufferSmoke --move-proof-presented-frame-smoke` can run `Mimir.App` diff --git a/notes/current-system-map.md b/notes/current-system-map.md index 024da22..c011030 100644 --- a/notes/current-system-map.md +++ b/notes/current-system-map.md @@ -230,9 +230,15 @@ surface for that bridge. An enabled source must name the Muninn evidence stream, native reservoir path, Mimir evidence/pose frame prefixes, Fensalir presented-frame prefix, fusion authority, consumer contract, and at least two calibrated camera witnesses. It may create a runtime driver only when the -supplied CultMesh ring stream id matches the configured evidence stream. This -does not yet open a cross-process live ring; the current smoke ring is -in-process proof of the Mimir-side contract. +supplied CultMesh ring stream id matches the configured evidence stream. +`MimirRuntime` now owns activation for configured proof sources: on scene-ready +it asks an `IMimirMoveProofEvidenceRingProvider` for the evidence ring, opens +the configured native reservoir, registers the runtime driver, retains the +driver resources, and exposes an activation status. The default provider fails +explicitly because the current C# CultMesh ring is still in-process only; +`Mimir.BufferSmoke --move-proof-runtime-activation-smoke` injects an in-process +provider to prove the activation path without claiming live Nightwing field +evidence. `MimirMoveProofDevSurface` is a dev-only bootstrap gated by `MIMIR_MOVE_PROOF_DEV_SURFACE`. It publishes a synthetic calibrated proof surface through the same `MimirRuntime.PublishMoveProofSurface` attachment so diff --git a/src/Mimir.BufferSmoke/Program.cs b/src/Mimir.BufferSmoke/Program.cs index 5ec3993..c8453e2 100644 --- a/src/Mimir.BufferSmoke/Program.cs +++ b/src/Mimir.BufferSmoke/Program.cs @@ -158,13 +158,22 @@ if (args.Any(arg => string.Equals(arg, "--move-proof-runtime-frame-smoke", Strin if (args.Any(arg => string.Equals(arg, "--move-proof-runtime-driver-smoke", StringComparison.OrdinalIgnoreCase))) { return RunMoveProofRuntimeDriverSmoke( - ParseStringOption(args, "--native-reservoir", DefaultNativeReservoirPath())); + ParseStringOption(args, "--native-reservoir", DefaultNativeReservoirPath()), + activateViaConfiguredSource: false); } if (args.Any(arg => string.Equals(arg, "--move-proof-runtime-config-smoke", StringComparison.OrdinalIgnoreCase))) { return RunMoveProofRuntimeDriverSmoke( - ParseStringOption(args, "--native-reservoir", DefaultNativeReservoirPath())); + ParseStringOption(args, "--native-reservoir", DefaultNativeReservoirPath()), + activateViaConfiguredSource: false); +} + +if (args.Any(arg => string.Equals(arg, "--move-proof-runtime-activation-smoke", StringComparison.OrdinalIgnoreCase))) +{ + return RunMoveProofRuntimeDriverSmoke( + ParseStringOption(args, "--native-reservoir", DefaultNativeReservoirPath()), + activateViaConfiguredSource: true); } if (args.Any(arg => string.Equals(arg, "--move-proof-presented-frame-smoke", StringComparison.OrdinalIgnoreCase))) @@ -2276,7 +2285,7 @@ static int RunMoveProofRuntimeFrameSmoke() : 1; } -static int RunMoveProofRuntimeDriverSmoke(string nativeReservoirPath) +static int RunMoveProofRuntimeDriverSmoke(string nativeReservoirPath, bool activateViaConfiguredSource) { if (!File.Exists(nativeReservoirPath)) { @@ -2408,26 +2417,47 @@ static int RunMoveProofRuntimeDriverSmoke(string nativeReservoirPath) } catalog.PublishFrame(published); - using var reservoir = new MimirNativeReservoirRuntime(nativeReservoirPath); - var driver = configuration.CreateDriver(ring, reservoir); - var runtime = new MimirRuntime( - new AquariumRuntimeOptions(Headless: true, CultCachePath: ""), - new MimirSynchronizationSettings()); - runtime.RegisterMoveProofDriver(driver); + using var manualReservoir = activateViaConfiguredSource ? null : new MimirNativeReservoirRuntime(nativeReservoirPath); + var manualDriver = activateViaConfiguredSource + ? null + : configuration.CreateDriver(ring, manualReservoir!); + using var runtime = activateViaConfiguredSource + ? new MimirRuntime( + new AquariumRuntimeOptions(Headless: true, CultCachePath: ""), + new MimirRuntimeConfiguration + { + Settings = new MimirSynchronizationSettings(), + MoveProofSources = [configuration], + }, + new InProcessMoveProofEvidenceRingProvider(ring)) + : new MimirRuntime( + new AquariumRuntimeOptions(Headless: true, CultCachePath: ""), + new MimirSynchronizationSettings()); + if (manualDriver is not null) + { + runtime.RegisterMoveProofDriver(manualDriver); + } + runtime.OnSceneReady(); var input = new InputState(); runtime.Update(0.016f, input); var proofFrame = runtime.Frame; - var proofSurface = driver.LastResult?.ProofSurface; + var proofSurface = activateViaConfiguredSource + ? runtime.LatestMoveProofSurface + : manualDriver?.LastResult?.ProofSurface; var proofSplineCount = proofFrame.Scene.SplineFrame.Splines.Count(spline => spline.Id.StartsWith("move-proof-", StringComparison.Ordinal)); runtime.Update(0.016f, input); - var duplicateSuppressed = reservoir.Status.MoveEvidenceCount.ToUInt64() == 1UL; + var duplicateSuppressed = activateViaConfiguredSource || manualReservoir!.Status.MoveEvidenceCount.ToUInt64() == 1UL; + var activationStatus = runtime.MoveProofActivationStatuses.LastOrDefault(status => + string.Equals(status.EvidenceStreamId, streamId, StringComparison.Ordinal)); + var activationOk = !activateViaConfiguredSource || activationStatus?.Active == true; Console.WriteLine( - $"move-proof-runtime-driver-smoke proof={proofSurface?.ProofId ?? "none"} chain={proofSurface?.MuninnEvidenceFrameId ?? "none"}->{proofSurface?.MimirEvidenceFrameId ?? "none"}->{proofSurface?.MimirPoseFrameId ?? "none"}->{proofSurface?.FensalirFrameId ?? "none"} verdict={proofSurface?.Verdict.ToString() ?? "none"} splines={proofSplineCount} duplicateSuppressed={duplicateSuppressed} configValid={configErrors.Length == 0} invalidDefaultErrors={invalidErrors.Length}"); + $"move-proof-runtime-{(activateViaConfiguredSource ? "activation" : "driver")}-smoke proof={proofSurface?.ProofId ?? "none"} chain={proofSurface?.MuninnEvidenceFrameId ?? "none"}->{proofSurface?.MimirEvidenceFrameId ?? "none"}->{proofSurface?.MimirPoseFrameId ?? "none"}->{proofSurface?.FensalirFrameId ?? "none"} verdict={proofSurface?.Verdict.ToString() ?? "none"} splines={proofSplineCount} duplicateSuppressed={duplicateSuppressed} configValid={configErrors.Length == 0} invalidDefaultErrors={invalidErrors.Length} activationActive={activationStatus?.Active.ToString() ?? "n/a"} activationDiagnostic=\"{activationStatus?.Diagnostic ?? ""}\""); return proofSurface is not null && + activationOk && proofSurface.IsFullPose && proofSurface.MuninnEvidenceFrameId == "muninn:nightwing:move-evidence:79" && proofSurface.MimirEvidenceFrameId == "mimir:starfire:move-evidence:79" && @@ -7149,6 +7179,26 @@ sealed record MoveTrackingSmokeContext(MimirSynchronizationHub Hub, int Consumed public void Dispose() => Hub.Dispose(); } +internal sealed class InProcessMoveProofEvidenceRingProvider(CultMeshSharedMemoryFrameRing ring) : IMimirMoveProofEvidenceRingProvider +{ + public bool TryOpenEvidenceRing( + MimirMoveProofRuntimeConfiguration configuration, + out MimirMoveProofEvidenceRingLease? lease, + out string diagnostic) + { + if (!string.Equals(ring.StreamId, configuration.EvidenceStreamId, StringComparison.Ordinal)) + { + lease = null; + diagnostic = $"in-process ring stream '{ring.StreamId}' does not match configured evidence stream '{configuration.EvidenceStreamId}'"; + return false; + } + + lease = new MimirMoveProofEvidenceRingLease(ring); + diagnostic = "in-process test ring supplied"; + return true; + } +} + public sealed record ComplexContourReflectionCorrection( double RelativeDelaySamples, int ObservationCount, diff --git a/src/Mimir.Runtime/MimirRuntime.cs b/src/Mimir.Runtime/MimirRuntime.cs index 0939124..0739956 100644 --- a/src/Mimir.Runtime/MimirRuntime.cs +++ b/src/Mimir.Runtime/MimirRuntime.cs @@ -40,6 +40,7 @@ direct private readonly MimirAudioSpectrumAnalyzer spectrumAnalyzer; private readonly IReadOnlyList sourceFactories; private readonly IReadOnlyList configuredMoveProofSources; + private readonly IMimirMoveProofEvidenceRingProvider moveProofRingProvider; private readonly AquariumUiDocument ui; private readonly AquariumAudioDocument audio = new(); private readonly MimirAudioSynchronizationSettings audioSyncSettings; @@ -64,7 +65,10 @@ direct private IReadOnlyList lastAudioSpectra = []; private readonly Queue> spectrumHistory = new(); private readonly List moveProofDrivers = []; + private readonly List moveProofDriverResources = []; + private readonly List moveProofActivationStatuses = []; private MimirMoveProofSurfaceDocument? latestMoveProofSurface; + private bool moveProofSourcesActivated; public MimirRuntime(AquariumRuntimeOptions options) : this(options, MimirRuntimeConfiguration.Load()) @@ -72,7 +76,20 @@ direct } public MimirRuntime(AquariumRuntimeOptions options, MimirRuntimeConfiguration configuration) - : this(options, configuration.Settings, configuration.SourceFactories, configuration.MoveProofSources) + : this( + options, + configuration.Settings, + configuration.SourceFactories, + configuration.MoveProofSources, + MimirUnavailableMoveProofEvidenceRingProvider.Instance) + { + } + + public MimirRuntime( + AquariumRuntimeOptions options, + MimirRuntimeConfiguration configuration, + IMimirMoveProofEvidenceRingProvider moveProofRingProvider) + : this(options, configuration.Settings, configuration.SourceFactories, configuration.MoveProofSources, moveProofRingProvider) { } @@ -85,7 +102,12 @@ direct AquariumRuntimeOptions options, MimirSynchronizationSettings settings, IEnumerable streamSources) - : this(options, settings, Array.Empty(), Array.Empty()) + : this( + options, + settings, + Array.Empty(), + Array.Empty(), + MimirUnavailableMoveProofEvidenceRingProvider.Instance) { foreach (var source in streamSources) { @@ -97,13 +119,15 @@ direct AquariumRuntimeOptions options, MimirSynchronizationSettings settings, IEnumerable sourceFactories, - IEnumerable moveProofSources) + IEnumerable moveProofSources, + IMimirMoveProofEvidenceRingProvider moveProofRingProvider) { Options = options; synchronization = new MimirSynchronizationHub(settings); spectrumAnalyzer = new MimirAudioSpectrumAnalyzer(ParseSpectrumFftSize()); this.sourceFactories = sourceFactories.ToArray(); configuredMoveProofSources = moveProofSources.ToArray(); + this.moveProofRingProvider = moveProofRingProvider ?? throw new ArgumentNullException(nameof(moveProofRingProvider)); audioSyncSettings = settings.Audio; telemetryIntervalSeconds = ParseTelemetryIntervalSeconds(); audioSyncUpdateIntervalSeconds = ParseAudioSyncIntervalSeconds(); @@ -138,6 +162,10 @@ direct public AquariumAudioDocument Audio => audio; + public IReadOnlyList MoveProofActivationStatuses => moveProofActivationStatuses; + + public MimirMoveProofSurfaceDocument? LatestMoveProofSurface => latestMoveProofSurface; + private AquariumFrame CreateFrame() { var channelCount = Math.Max(1, lastAudioSpectra.Count); @@ -196,6 +224,20 @@ direct moveProofDrivers.Add(driver); } + public void ActivateConfiguredMoveProofSources() + { + if (moveProofSourcesActivated) + { + return; + } + + moveProofSourcesActivated = true; + foreach (var configuration in configuredMoveProofSources) + { + ActivateConfiguredMoveProofSource(configuration); + } + } + public static AquariumSplineFrame ComposeFensalirSplineFrame( AquariumSplineFrame baseFrame, MimirMoveProofSurfaceDocument? moveProofSurface) @@ -270,6 +312,11 @@ direct public void Dispose() { + foreach (var resource in moveProofDriverResources.AsEnumerable().Reverse()) + { + resource.Dispose(); + } + synchronization.Dispose(); } @@ -339,7 +386,19 @@ direct return string.Join( Environment.NewLine, configuredMoveProofSources.Select(source => - $"{source.EvidenceStreamId} -> {source.MimirPoseFramePrefix}: cameras={source.Calibration.Cameras.Count}")); + $"{source.EvidenceStreamId} -> {source.MimirPoseFramePrefix}: cameras={source.Calibration.Cameras.Count} {DescribeMoveProofActivation(source.EvidenceStreamId)}")); + } + + private string DescribeMoveProofActivation(string evidenceStreamId) + { + var status = moveProofActivationStatuses.LastOrDefault(status => + string.Equals(status.EvidenceStreamId, evidenceStreamId, StringComparison.Ordinal)); + if (status is null) + { + return "not activated"; + } + + return status.Active ? "active" : $"inactive: {status.Diagnostic}"; } private void UpdateMoveProofSurfaces() @@ -558,6 +617,54 @@ direct synchronization.AddSource(source); } } + + ActivateConfiguredMoveProofSources(); + } + + private void ActivateConfiguredMoveProofSource(MimirMoveProofRuntimeConfiguration configuration) + { + try + { + var errors = configuration.Validate(); + if (errors.Length > 0) + { + RecordMoveProofActivation(configuration.EvidenceStreamId, false, $"invalid: {string.Join("; ", errors)}"); + return; + } + + if (!moveProofRingProvider.TryOpenEvidenceRing(configuration, out var ringLease, out var diagnostic) || ringLease is null) + { + RecordMoveProofActivation(configuration.EvidenceStreamId, false, diagnostic); + return; + } + + try + { + var reservoir = new MimirNativeReservoirRuntime(configuration.NativeReservoirPath); + var driver = configuration.CreateDriver(ringLease.Ring, reservoir); + moveProofDrivers.Add(driver); + moveProofDriverResources.Add(reservoir); + moveProofDriverResources.Add(ringLease); + RecordMoveProofActivation(configuration.EvidenceStreamId, true, diagnostic); + } + catch + { + ringLease.Dispose(); + throw; + } + } + catch (Exception exception) + { + RecordMoveProofActivation(configuration.EvidenceStreamId, false, exception.Message); + } + } + + private void RecordMoveProofActivation(string evidenceStreamId, bool active, string diagnostic) + { + moveProofActivationStatuses.Add(new MimirMoveProofRuntimeActivationStatus( + evidenceStreamId, + active, + string.IsNullOrWhiteSpace(diagnostic) ? (active ? "activated" : "not activated") : diagnostic)); } private void EmitTelemetry() diff --git a/src/Mimir.Runtime/Synchronization/MimirMoveProofRuntimeActivation.cs b/src/Mimir.Runtime/Synchronization/MimirMoveProofRuntimeActivation.cs new file mode 100644 index 0000000..98bba90 --- /dev/null +++ b/src/Mimir.Runtime/Synchronization/MimirMoveProofRuntimeActivation.cs @@ -0,0 +1,57 @@ +using GameCult.Mesh; + +namespace Mimir.Runtime.Synchronization; + +public interface IMimirMoveProofEvidenceRingProvider +{ + bool TryOpenEvidenceRing( + MimirMoveProofRuntimeConfiguration configuration, + out MimirMoveProofEvidenceRingLease? lease, + out string diagnostic); +} + +public sealed class MimirMoveProofEvidenceRingLease : IDisposable +{ + private readonly bool ownsRing; + + public MimirMoveProofEvidenceRingLease(CultMeshSharedMemoryFrameRing ring, bool ownsRing = false) + { + Ring = ring ?? throw new ArgumentNullException(nameof(ring)); + this.ownsRing = ownsRing; + } + + public CultMeshSharedMemoryFrameRing Ring { get; } + + public void Dispose() + { + if (ownsRing) + { + Ring.Dispose(); + } + } +} + +public sealed record MimirMoveProofRuntimeActivationStatus( + string EvidenceStreamId, + bool Active, + string Diagnostic); + +public sealed class MimirUnavailableMoveProofEvidenceRingProvider : IMimirMoveProofEvidenceRingProvider +{ + public static MimirUnavailableMoveProofEvidenceRingProvider Instance { get; } = new(); + + private MimirUnavailableMoveProofEvidenceRingProvider() + { + } + + public bool TryOpenEvidenceRing( + MimirMoveProofRuntimeConfiguration configuration, + out MimirMoveProofEvidenceRingLease? lease, + out string diagnostic) + { + ArgumentNullException.ThrowIfNull(configuration); + lease = null; + diagnostic = "No live CultMesh shared-memory ring opener is configured for this runtime; C# CultMesh rings are currently in-process only."; + return false; + } +} diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 38c53da..d6daf69 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -165,3 +165,4 @@ {"ts": "2026-07-08T22:48:42+01:00", "type": "implementation", "status": "ok", "note": "Added MimirMoveProofRuntimeDriver as the runtime bridge from a Muninn CultMesh shared-memory evidence ring to MimirRuntime.PublishMoveProofSurface. The driver derives mimir:starfire evidence/pose ids and fensalir:starfire presented-frame id from the actual Muninn frame suffix, calls MimirMoveProofPipeline, and suppresses duplicate frame admission. Verified dotnet build Mimir.BufferSmoke, BufferSmoke --move-proof-runtime-driver-smoke against the native reservoir debug DLL, --move-proof-runtime-frame-smoke, --move-proof-surface-smoke, and --move-proof-pipeline-smoke. This proves the runtime-owned ring-to-visible-probe path with synthetic ring input; real Nightwing hardware, calibrated camera witnesses, and real presented-frame capture remain pending."} {"ts": "2026-07-08T22:55:54+01:00", "type": "verification", "status": "ok", "note": "Added and verified the Fensalir presented-frame proof smoke. MIMIR_MOVE_PROOF_DEV_SURFACE gates a synthetic calibrated proof surface through the same MimirRuntime.PublishMoveProofSurface path, and BufferSmoke --move-proof-presented-frame-smoke runs Mimir.App headless, captures artifacts/runtime/move-proof-presented-frame-smoke.png, and pixel-checks the rendered proof probe. Latest run captured fensalir:starfire:presented-frame:79 for proof mimir:starfire:move-proof:79 with bytes=11260 and brightPixels=1069; adjacent runtime-driver, runtime-frame, proof-surface, and proof-pipeline smokes pass. This proves the renderer/probe layer for the named proof chain, not live Nightwing hardware or calibrated field evidence."} {"ts": "2026-07-12T10:26:42+01:00", "type": "verification", "status": "ok", "note": "Added MimirMoveProofRuntimeConfiguration as the typed config/validation surface for Move proof driver creation. The runtime config now accepts enabled MoveProof sources, validates named Muninn evidence stream, native reservoir path, Mimir/Fensalir frame prefixes, fusion authority, consumer contract, and at least two calibrated camera witnesses, and creates a driver only when the supplied CultMesh ring stream id matches. Verified dotnet build Mimir.Runtime, dotnet build Mimir.BufferSmoke, BufferSmoke --move-proof-runtime-config-smoke, --move-proof-runtime-driver-smoke, --move-proof-pipeline-smoke, and --move-proof-presented-frame-smoke. The config smoke printed configValid=True invalidDefaultErrors=2 and the same sequence chain muninn:nightwing:move-evidence:79 -> mimir:starfire:move-evidence:79 -> mimir:starfire:move-pose:79 -> fensalir:starfire:presented-frame:79. This proves config plus in-process ring flow, not live Nightwing hardware, calibrated field cameras, or cross-process ring opening."} +{"ts": "2026-07-12T10:51:37+01:00", "type": "verification", "status": "ok", "note": "MimirRuntime now owns configured Move proof activation instead of leaving MoveProof config as a passive readout. On scene-ready it asks IMimirMoveProofEvidenceRingProvider for the configured Muninn evidence ring, opens the configured native reservoir, creates/registers MimirMoveProofRuntimeDriver, retains resources, and records activation status. The default provider fails explicitly because the current C# CultMesh ring is in-process only. Verified dotnet build Mimir.Runtime, dotnet build Mimir.BufferSmoke, BufferSmoke --move-proof-runtime-driver-smoke, and BufferSmoke --move-proof-runtime-activation-smoke. The activation smoke injected an in-process provider and printed activationActive=True while preserving the explicit chain muninn:nightwing:move-evidence:79 -> mimir:starfire:move-evidence:79 -> mimir:starfire:move-pose:79 -> fensalir:starfire:presented-frame:79 with verdict=FullPose. This proves runtime config activation and status, not live Nightwing/Starfire hardware or cross-process ring opening."} diff --git a/state/map.yaml b/state/map.yaml index 571edd5..94b14bc 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -161,9 +161,15 @@ accepted_design: Fensalir presented-frame prefix, fusion authority, consumer contract, and at least two calibrated camera witnesses. It may create a `MimirMoveProofRuntimeDriver` only when the supplied CultMesh ring stream id - matches the configured evidence stream. The current C# shared-memory ring - smoke is still in-process; real Nightwing/Starfire cross-process ring - opening remains pending. + matches the configured evidence stream. + - `MimirRuntime` owns configured Move proof activation. On scene-ready it asks + an `IMimirMoveProofEvidenceRingProvider` for the evidence ring, opens the + configured native reservoir, registers the runtime driver, retains the + driver resources, and exposes activation status. The default provider fails + explicitly because the current C# CultMesh ring is still in-process only; + `Mimir.BufferSmoke --move-proof-runtime-activation-smoke` injects an + in-process provider to prove the activation path without claiming live + Nightwing/Starfire field evidence. - `MimirMoveProofDevSurface` is a dev-only bootstrap gated by `MIMIR_MOVE_PROOF_DEV_SURFACE`. It publishes a synthetic calibrated proof surface through the same MimirRuntime attachment so headless Mimir.App can