diff --git a/Aetheria.State.ApplyPending/Aetheria.State.ApplyPending.csproj b/Aetheria.State.ApplyPending/Aetheria.State.ApplyPending.csproj
deleted file mode 100644
index ca788873d..000000000
--- a/Aetheria.State.ApplyPending/Aetheria.State.ApplyPending.csproj
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
- Exe
- net10.0
- enable
- latest
- enable
-
-
-
-
-
-
diff --git a/Aetheria.State.ApplyPending/Program.cs b/Aetheria.State.ApplyPending/Program.cs
deleted file mode 100644
index ae8a28177..000000000
--- a/Aetheria.State.ApplyPending/Program.cs
+++ /dev/null
@@ -1,134 +0,0 @@
-using Aetheria.State;
-using Aetheria.State.Documents;
-
-var root = args.Length > 0 && !args[0].StartsWith("--", StringComparison.Ordinal)
- ? Path.GetFullPath(args[0])
- : Directory.GetCurrentDirectory();
-var explicitStatePath = args.Length > 1 && !args[1].StartsWith("--", StringComparison.Ordinal)
- ? args[1]
- : "";
-var statePath = string.IsNullOrWhiteSpace(explicitStatePath)
- ? AetheriaStatePaths.ResolveDefaultStatePath(root)
- : Path.GetFullPath(explicitStatePath);
-var deleteApplied = !args.Any(arg => string.Equals(arg, "--keep", StringComparison.OrdinalIgnoreCase));
-var runtimeId = "aetheria-state-apply-pending";
-var runtimePendingBefore = CountPendingRuntimeCommits(statePath);
-var evePendingBefore = CountPendingEveCommands(statePath);
-var now = DateTimeOffset.UtcNow.ToString("O");
-
-await using var node = await AetheriaStateNode.OpenAsync(statePath, runtimeId);
-var verseHostSettings = await EnsureVerseHostSettingsAsync(node, now);
-await node.PutRuntimeSessionAsync(new AetheriaRuntimeSession
-{
- RuntimeId = runtimeId,
- Role = "pending-drain",
- StartedAtUtc = now,
- LastSeenAtUtc = now,
- Status = "running"
-});
-var report = await AetheriaRuntimeCommitLogApplier.ApplyPendingAsync(node, deleteApplied);
-var eveReport = await AetheriaEveCommandBridge.ApplyPendingAsync(node, deleteApplied);
-var commitStatus = new AetheriaRuntimeCommitDrainStatus
-{
- RuntimeId = runtimeId,
- StatePath = statePath,
- LastPollAtUtc = now,
- LastAppliedAtUtc = report.AppliedPaths.Length > 0 ? now : "",
- PendingBeforeApply = runtimePendingBefore,
- CommandsApplied = report.AppliedPaths.Length,
- AppliedPlayerSettings = report.AppliedPlayerSettings,
- AppliedLoadoutTemplates = report.AppliedLoadoutTemplates,
- AppliedRunCheckpoints = report.AppliedRunCheckpoints,
- Status = "ok"
-};
-var eveStatus = new AetheriaEveCommandDrainStatus
-{
- RuntimeId = runtimeId,
- StatePath = statePath,
- LastPollAtUtc = now,
- LastAcceptedAtUtc = eveReport.AcceptedPaths.Length > 0 ? now : "",
- PendingBeforeApply = evePendingBefore,
- CommandsAccepted = eveReport.AcceptedPaths.Length,
- CommandsRejected = eveReport.RejectedCommands,
- AppliedCatalogRefreshes = eveReport.AppliedCatalogRefreshes,
- AppliedOperationsRefreshes = eveReport.AppliedOperationsRefreshes,
- AppliedPlayerSettingsCommands = eveReport.AppliedPlayerSettingsCommands,
- AppliedVerseHostCommands = eveReport.AppliedVerseHostCommands,
- LastRejectedCommand = eveReport.LastRejectedCommand,
- LastRejectedReason = eveReport.LastRejectedReason,
- Status = eveReport.RejectedCommands > 0 ? "rejected" : "ok"
-};
-await node.PutRuntimeCommitDrainStatusAsync(commitStatus);
-await node.PutEveCommandDrainStatusAsync(eveStatus);
-var completedSession = new AetheriaRuntimeSession
-{
- RuntimeId = runtimeId,
- Role = "pending-drain",
- StartedAtUtc = now,
- LastSeenAtUtc = DateTimeOffset.UtcNow.ToString("O"),
- Status = "completed"
-};
-await node.PutRuntimeSessionAsync(completedSession);
-await node.PutOperationsSurfaceAsync(
- AetheriaOperationsSurfaceProjector.Build(
- commitStatus,
- eveStatus,
- verseHostSettings,
- completedSession));
-await PublishPlayerSettingsSurfaceAsync(node, now);
-await node.PutProviderAdvertisementAsync(
- AetheriaProviderAdvertisementProjector.Build(verseHostSettings, statePath, now));
-await node.FlushAsync();
-
-Console.WriteLine($"Applied pending Aetheria runtime commits: {statePath}");
-Console.WriteLine($"Player settings: {report.AppliedPlayerSettings}");
-Console.WriteLine($"Loadout templates: {report.AppliedLoadoutTemplates}");
-Console.WriteLine($"Run checkpoints: {report.AppliedRunCheckpoints}");
-Console.WriteLine($"Commands applied: {report.AppliedPaths.Length}");
-Console.WriteLine($"Eve commands accepted: {eveReport.AcceptedPaths.Length}");
-Console.WriteLine($"Eve commands rejected: {eveReport.RejectedCommands}");
-Console.WriteLine($"Eve catalog refreshes: {eveReport.AppliedCatalogRefreshes}");
-Console.WriteLine($"Eve operations refreshes: {eveReport.AppliedOperationsRefreshes}");
-Console.WriteLine($"Eve player settings commands: {eveReport.AppliedPlayerSettingsCommands}");
-Console.WriteLine($"Eve verse host commands: {eveReport.AppliedVerseHostCommands}");
-if (!deleteApplied)
- Console.WriteLine("Applied command files were kept because --keep was supplied.");
-
-static int CountPendingRuntimeCommits(string statePath)
-{
- var pendingDirectory = statePath + ".pending";
- return Directory.Exists(pendingDirectory)
- ? Directory.EnumerateFiles(pendingDirectory, "*.cc").Count()
- : 0;
-}
-
-static int CountPendingEveCommands(string statePath)
-{
- var pendingDirectory = AetheriaEveCommandBridge.GetPendingDirectory(statePath);
- return Directory.Exists(pendingDirectory)
- ? Directory.EnumerateFiles(pendingDirectory, "*.cc").Count()
- : 0;
-}
-
-static async Task PublishPlayerSettingsSurfaceAsync(AetheriaStateNode node, string updatedAtUtc)
-{
- var settings = await node.GetPlayerSettingsAsync().ConfigureAwait(false) ?? new AetheriaPlayerSettings();
- var publishedAtUtc = string.IsNullOrWhiteSpace(settings.LastUpdatedAtUtc)
- ? updatedAtUtc
- : settings.LastUpdatedAtUtc;
- await node.PutPlayerSettingsSurfaceAsync(
- AetheriaPlayerSettingsSurfaceProjector.Build(settings, publishedAtUtc)).ConfigureAwait(false);
-}
-
-static async Task EnsureVerseHostSettingsAsync(AetheriaStateNode node, string now)
-{
- var existing = await node.GetVerseHostSettingsAsync().ConfigureAwait(false);
- var normalized = AetheriaVerseHostSettingsNormalizer.Normalize(existing);
- if (existing == null || string.IsNullOrWhiteSpace(existing.LastUpdatedAtUtc))
- {
- normalized.LastUpdatedAtUtc = now;
- await node.PutVerseHostSettingsAsync(normalized).ConfigureAwait(false);
- }
-
- return normalized;
-}
diff --git a/Economy.Server/Economy.Server.csproj b/Economy.Server/Economy.Server.csproj
deleted file mode 100644
index b9fc3350e..000000000
--- a/Economy.Server/Economy.Server.csproj
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
- Exe
- net10.0
- enable
- latest
- enable
-
-
-
-
-
-
-
diff --git a/Economy.Server/Program.cs b/Economy.Server/Program.cs
deleted file mode 100644
index beb1d609a..000000000
--- a/Economy.Server/Program.cs
+++ /dev/null
@@ -1,449 +0,0 @@
-using System.Text.Json;
-using Aetheria.State;
-using Aetheria.State.Documents;
-
-namespace Aetheria.Server;
-
-internal static class Program
-{
- private const string RuntimeId = "aetheria-economy-server";
-
- private static async Task Main(string[] args)
- {
- var statePath = ResolveStatePath(args);
- Console.WriteLine($"Aetheria CultMesh state host starting: {statePath}");
-
- await using var node = await AetheriaStateNode.OpenAsync(
- statePath,
- runtimeId: RuntimeId,
- startServer: true).ConfigureAwait(false);
- using var verseDiscovery = new AetheriaVerseDiscoveryHost(node);
-
- await EnsureVerseHostSettingsAsync(node).ConfigureAwait(false);
- await RefreshVerseDiscoveryAsync(node, verseDiscovery).ConfigureAwait(false);
- var startedAtUtc = DateTimeOffset.UtcNow.ToString("O");
- await PublishRuntimeSessionAsync(node, startedAtUtc, "starting").ConfigureAwait(false);
- await EnsureWorldDocumentAsync(node).ConfigureAwait(false);
- await ApplyPendingRuntimeCommitsAsync(node).ConfigureAwait(false);
- await ApplyPendingEveCommandsAsync(node).ConfigureAwait(false);
- await RefreshVerseDiscoveryAsync(node, verseDiscovery).ConfigureAwait(false);
- await PublishRuntimeSessionAsync(node, startedAtUtc, "running").ConfigureAwait(false);
- await node.FlushAsync().ConfigureAwait(false);
-
- if (HasFlag(args, "--apply-pending-once"))
- {
- Console.WriteLine("Aetheria pending runtime and Eve command drains completed.");
- return;
- }
-
- Console.WriteLine("Aetheria CultMesh state host is running. Press Ctrl+C to stop.");
- await RunUntilShutdownAsync(node, verseDiscovery, startedAtUtc, PendingInterval(args)).ConfigureAwait(false);
-
- await PublishRuntimeSessionAsync(node, startedAtUtc, "stopping").ConfigureAwait(false);
- Console.WriteLine("Aetheria CultMesh state host stopping.");
- }
-
- private static string ResolveStatePath(IReadOnlyList args)
- {
- for (var i = 0; i < args.Count - 1; i++)
- {
- if (string.Equals(args[i], "--state", StringComparison.OrdinalIgnoreCase))
- {
- return Path.GetFullPath(args[i + 1]);
- }
- }
-
- var repoRoot = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", ".."));
- return AetheriaStatePaths.ResolveDefaultStatePath(repoRoot);
- }
-
- private static async Task EnsureWorldDocumentAsync(AetheriaStateNode node)
- {
- var existing = await node.GetWorldAsync().ConfigureAwait(false);
- if (existing != null)
- {
- existing.UpdatedAtUtc = DateTimeOffset.UtcNow.ToString("O");
- await node.PutWorldAsync(existing).ConfigureAwait(false);
- return;
- }
-
- var now = DateTimeOffset.UtcNow.ToString("O");
- await node.PutWorldAsync(new AetheriaWorldState
- {
- Name = "Aetheria",
- WorldId = "aetheria",
- SchemaEpoch = 1,
- CreatedAtUtc = now,
- UpdatedAtUtc = now
- }).ConfigureAwait(false);
- }
-
- private static async Task ApplyPendingRuntimeCommitsAsync(AetheriaStateNode node)
- {
- var pendingBefore = CountPendingRuntimeCommits(node.StatePath);
- var now = DateTimeOffset.UtcNow.ToString("O");
-
- try
- {
- var report = await AetheriaRuntimeCommitLogApplier.ApplyPendingAsync(node).ConfigureAwait(false);
- var status = new AetheriaRuntimeCommitDrainStatus
- {
- RuntimeId = RuntimeId,
- StatePath = node.StatePath,
- LastPollAtUtc = now,
- LastAppliedAtUtc = report.AppliedPaths.Length > 0 ? now : "",
- PendingBeforeApply = pendingBefore,
- CommandsApplied = report.AppliedPaths.Length,
- AppliedPlayerSettings = report.AppliedPlayerSettings,
- AppliedLoadoutTemplates = report.AppliedLoadoutTemplates,
- AppliedRunCheckpoints = report.AppliedRunCheckpoints,
- ConsecutiveFailures = 0,
- Status = "ok"
- };
- await PublishDrainStatusAsync(node, status).ConfigureAwait(false);
-
- if (report.AppliedPaths.Length == 0)
- {
- Console.WriteLine("No pending Aetheria runtime commits.");
- return;
- }
-
- Console.WriteLine(
- "Applied pending Aetheria runtime commits: " +
- $"settings={report.AppliedPlayerSettings}, " +
- $"loadouts={report.AppliedLoadoutTemplates}, " +
- $"runs={report.AppliedRunCheckpoints}, " +
- $"files={report.AppliedPaths.Length}");
- }
- catch (Exception ex)
- {
- var existing = await node.GetRuntimeCommitDrainStatusAsync().ConfigureAwait(false);
- var status = new AetheriaRuntimeCommitDrainStatus
- {
- RuntimeId = RuntimeId,
- StatePath = node.StatePath,
- LastPollAtUtc = now,
- LastAppliedAtUtc = existing?.LastAppliedAtUtc ?? "",
- PendingBeforeApply = pendingBefore,
- ConsecutiveFailures = (existing?.ConsecutiveFailures ?? 0) + 1,
- LastError = ex.ToString(),
- Status = "error"
- };
- await PublishDrainStatusAsync(node, status).ConfigureAwait(false);
- throw;
- }
- }
-
- private static async Task PublishDrainStatusAsync(
- AetheriaStateNode node,
- AetheriaRuntimeCommitDrainStatus status)
- {
- await node.PutRuntimeCommitDrainStatusAsync(status).ConfigureAwait(false);
- await PublishOperationsStateAsync(node, status.LastPollAtUtc).ConfigureAwait(false);
- }
-
- private static async Task ApplyPendingEveCommandsAsync(AetheriaStateNode node)
- {
- var pendingBefore = CountPendingEveCommands(node.StatePath);
- var now = DateTimeOffset.UtcNow.ToString("O");
-
- try
- {
- var report = await AetheriaEveCommandBridge.ApplyPendingAsync(node).ConfigureAwait(false);
- var status = new AetheriaEveCommandDrainStatus
- {
- RuntimeId = RuntimeId,
- StatePath = node.StatePath,
- LastPollAtUtc = now,
- LastAcceptedAtUtc = report.AcceptedPaths.Length > 0 ? now : "",
- PendingBeforeApply = pendingBefore,
- CommandsAccepted = report.AcceptedPaths.Length,
- CommandsRejected = report.RejectedCommands,
- AppliedCatalogRefreshes = report.AppliedCatalogRefreshes,
- AppliedOperationsRefreshes = report.AppliedOperationsRefreshes,
- AppliedPlayerSettingsCommands = report.AppliedPlayerSettingsCommands,
- AppliedVerseHostCommands = report.AppliedVerseHostCommands,
- LastRejectedCommand = report.LastRejectedCommand,
- LastRejectedReason = report.LastRejectedReason,
- ConsecutiveFailures = 0,
- Status = report.RejectedCommands > 0 ? "rejected" : "ok"
- };
- await PublishEveCommandStatusAsync(node, status).ConfigureAwait(false);
-
- if (report.AcceptedPaths.Length == 0 && report.RejectedCommands == 0)
- {
- Console.WriteLine("No pending Aetheria Eve commands.");
- return;
- }
-
- Console.WriteLine(
- "Drained pending Aetheria Eve commands: " +
- $"accepted={report.AcceptedPaths.Length}, " +
- $"rejected={report.RejectedCommands}, " +
- $"catalogRefreshes={report.AppliedCatalogRefreshes}, " +
- $"operationsRefreshes={report.AppliedOperationsRefreshes}, " +
- $"playerSettings={report.AppliedPlayerSettingsCommands}, " +
- $"verseHost={report.AppliedVerseHostCommands}");
- }
- catch (Exception ex)
- {
- var existing = await node.GetEveCommandDrainStatusAsync().ConfigureAwait(false);
- var status = new AetheriaEveCommandDrainStatus
- {
- RuntimeId = RuntimeId,
- StatePath = node.StatePath,
- LastPollAtUtc = now,
- LastAcceptedAtUtc = existing?.LastAcceptedAtUtc ?? "",
- PendingBeforeApply = pendingBefore,
- ConsecutiveFailures = (existing?.ConsecutiveFailures ?? 0) + 1,
- LastError = ex.ToString(),
- Status = "error"
- };
- await PublishEveCommandStatusAsync(node, status).ConfigureAwait(false);
- throw;
- }
- }
-
- private static async Task PublishEveCommandStatusAsync(
- AetheriaStateNode node,
- AetheriaEveCommandDrainStatus status)
- {
- await node.PutEveCommandDrainStatusAsync(status).ConfigureAwait(false);
- await PublishOperationsStateAsync(node, status.LastPollAtUtc).ConfigureAwait(false);
- }
-
- private static async Task PublishOperationsStateAsync(
- AetheriaStateNode node,
- string updatedAtUtc)
- {
- var commitStatus = await node.GetRuntimeCommitDrainStatusAsync().ConfigureAwait(false) ??
- new AetheriaRuntimeCommitDrainStatus
- {
- RuntimeId = RuntimeId,
- StatePath = node.StatePath,
- LastPollAtUtc = updatedAtUtc,
- Status = "idle"
- };
- var eveStatus = await node.GetEveCommandDrainStatusAsync().ConfigureAwait(false);
- var verseHostSettings = await node.GetVerseHostSettingsAsync().ConfigureAwait(false) ??
- new AetheriaVerseHostSettings();
- var runtimeSession = await node.GetRuntimeSessionAsync(RuntimeId).ConfigureAwait(false);
- await node.PutOperationsSurfaceAsync(
- AetheriaOperationsSurfaceProjector.Build(
- commitStatus,
- eveStatus,
- verseHostSettings,
- runtimeSession))
- .ConfigureAwait(false);
- await PublishPlayerSettingsSurfaceAsync(node, updatedAtUtc).ConfigureAwait(false);
- await node.PutProviderAdvertisementAsync(
- AetheriaProviderAdvertisementProjector.Build(verseHostSettings, node.StatePath, updatedAtUtc))
- .ConfigureAwait(false);
- await node.FlushAsync().ConfigureAwait(false);
- }
-
- private static async Task PublishPlayerSettingsSurfaceAsync(
- AetheriaStateNode node,
- string updatedAtUtc)
- {
- var settings = await node.GetPlayerSettingsAsync().ConfigureAwait(false) ?? new AetheriaPlayerSettings();
- var publishedAtUtc = string.IsNullOrWhiteSpace(settings.LastUpdatedAtUtc)
- ? updatedAtUtc
- : settings.LastUpdatedAtUtc;
- await node.PutPlayerSettingsSurfaceAsync(
- AetheriaPlayerSettingsSurfaceProjector.Build(settings, publishedAtUtc)).ConfigureAwait(false);
- }
-
- private static async Task PublishRuntimeSessionAsync(
- AetheriaStateNode node,
- string startedAtUtc,
- string status)
- {
- var now = DateTimeOffset.UtcNow.ToString("O");
- await node.PutRuntimeSessionAsync(new AetheriaRuntimeSession
- {
- RuntimeId = RuntimeId,
- Role = "cultmesh-state-host",
- StartedAtUtc = startedAtUtc,
- LastSeenAtUtc = now,
- Status = status
- }).ConfigureAwait(false);
- await PublishOperationsStateAsync(node, now).ConfigureAwait(false);
- }
-
- private static int CountPendingRuntimeCommits(string statePath)
- {
- var pendingDirectory = statePath + ".pending";
- return Directory.Exists(pendingDirectory)
- ? Directory.EnumerateFiles(pendingDirectory, "*.cc").Count()
- : 0;
- }
-
- private static int CountPendingEveCommands(string statePath)
- {
- var pendingDirectory = AetheriaEveCommandBridge.GetPendingDirectory(statePath);
- return Directory.Exists(pendingDirectory)
- ? Directory.EnumerateFiles(pendingDirectory, "*.cc").Count()
- : 0;
- }
-
- private static async Task RunUntilShutdownAsync(
- AetheriaStateNode node,
- AetheriaVerseDiscoveryHost verseDiscovery,
- string startedAtUtc,
- TimeSpan pendingInterval)
- {
- var stopped = new TaskCompletionSource