Add Idunn keepalive organ

This commit is contained in:
Meta Vens 2026-06-04 18:32:26 +01:00
commit 27ec51ec9a
6 changed files with 246 additions and 0 deletions

12
src/Idunn/Idunn.csproj Normal file
View file

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\CultLib\src\GameCult.Mesh\GameCult.Mesh.csproj" />
</ItemGroup>
</Project>

102
src/Idunn/Program.cs Normal file
View file

@ -0,0 +1,102 @@
using GameCult.Caching.MessagePack;
using GameCult.Mesh;
var options = IdunnOptions.Parse(args);
var cachePath = Path.GetFullPath(options.CachePath);
var cacheDirectory = Path.GetDirectoryName(cachePath);
if (!string.IsNullOrWhiteSpace(cacheDirectory))
{
Directory.CreateDirectory(cacheDirectory);
}
using var node = await CultMesh.CreateNodeAsync(
cachePath,
new CultMeshNodeOptions
{
StartServer = options.Serve,
CacheOptions = new CultCacheOpenOptions
{
PullOnOpen = false
}
}).ConfigureAwait(false);
Console.WriteLine("Idunn CultMesh organ initialized.");
Console.WriteLine($"Keepalive store: {cachePath}");
Console.WriteLine("Provider id: idunn.keepalive");
Console.WriteLine("Authority: daemon lifecycle, health watching, restart intent, and operator escalation for Odin-known daemons");
Console.WriteLine("Owner escalation: CultMesh command voidbot.operator-dm owner.dm.send");
Console.WriteLine($"CultMesh server: {(options.Serve ? "started" : "disabled")}");
Console.WriteLine("Typed keepalive records and restart adapters are the next cut.");
if (!options.Serve)
{
return 0;
}
var stopping = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
Console.CancelKeyPress += (_, eventArgs) =>
{
eventArgs.Cancel = true;
stopping.TrySetResult();
};
Console.WriteLine("Press Ctrl+C to stop Idunn.");
await stopping.Task.ConfigureAwait(false);
return 0;
internal sealed record IdunnOptions(string CachePath, bool Serve)
{
public static IdunnOptions Parse(string[] args)
{
var repoRoot = FindRepoRoot(Directory.GetCurrentDirectory());
var cachePath = Path.Combine(repoRoot, "scratch", "idunn", "idunn.keepalive.cc");
var serve = false;
for (var index = 0; index < args.Length; index++)
{
switch (args[index])
{
case "--serve":
serve = true;
break;
case "--cache" when index + 1 < args.Length:
cachePath = args[++index];
break;
case "--help":
case "-h":
PrintUsage();
Environment.Exit(0);
break;
default:
throw new ArgumentException($"Unknown Idunn argument: {args[index]}");
}
}
return new IdunnOptions(cachePath, serve);
}
private static string FindRepoRoot(string start)
{
var current = new DirectoryInfo(start);
while (current != null)
{
if (File.Exists(Path.Combine(current.FullName, "package.json")) &&
Directory.Exists(Path.Combine(current.FullName, "src", "Gjallar")))
{
return current.FullName;
}
current = current.Parent;
}
return start;
}
private static void PrintUsage()
{
Console.WriteLine("Idunn");
Console.WriteLine(" --cache <path> Keepalive CultCache store path.");
Console.WriteLine(" --serve Start the CultMesh server instead of only opening the node.");
}
}