using System;using System.IO;using System.Text;using System.Threading.Tasks;using Agent.Core;using Agent.Core.Logging;using Agent.Core.TextToSpeech;using LilithAgent = Lilith.Agent;namespace LilithConsole{ partial class Program { static async Task Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; string model = Environment.GetEnvironmentVariable("LILITH_MODEL") ?? "gemma4"; Console.Title = Environment.GetEnvironmentVariable("GENESIS_TEST_WINDOW_TITLE") ?? $"Lilith — {model} Chat"; var credentials = new LilithAgent.LilithCredentials(Model: model); Action<LogEntry> onLog = entry => { entry.Type.Handle( onWrite: () => Console.Write(entry.Description), onWriteLine: () => Console.WriteLine(entry.Description), onProgress: () => { int width = Math.Max(Console.WindowWidth - 1, 40); string text = entry.Description.Length >= width ? entry.Description[..width] : entry.Description.PadRight(width); Console.Write($"\r{text}"); }); }; var lilith = new LilithAgent.Lilith(onLog, credentials); string configDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "workspace", "config"); string outputDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "workspace", "output"); Directory.CreateDirectory(configDir); Directory.CreateDirectory(outputDir); lilith.Workspace = new Workspace(configDir, outputDir); if (Environment.GetEnvironmentVariable("GENESIS_SELF_IMPROVE_SMOKE") == "1") { string? specJson = Environment.GetEnvironmentVariable("GENESIS_SELF_IMPROVE_TOOL_SPEC_JSON"); if (!string.IsNullOrWhiteSpace(specJson)) Console.WriteLine(lilith.SaveSelfImproveToolSpec(specJson)); Console.WriteLine(lilith.RunSelfImprovementSmokePipeline()); Console.Out.Flush(); return; } KokoroTts? tts = null; try { bool waitForTts = Environment.GetEnvironmentVariable("LILITH_WAIT_FOR_TTS") == "1"; tts = await KokoroTts.CreateAsync(lilith.Logger, new KokoroTtsOptions { WaitForTts = waitForTts }); lilith.OnVoiceChanged = voice => tts.SetVoice(voice); } catch (Exception ex) { lilith.Logger.WriteLine("TTS", $"Speech disabled: {ex.Message}", LogColors.Orange); } bool afterPromote = Environment.GetEnvironmentVariable("GENESIS_AFTER_PROMOTE") == "1"; string? greetReply = await lilith.BootAsync(startServerIfNotRunning: true); if (afterPromote) { lilith.Logger.WriteLine( "System", "Upgraded build loaded (post-promote). New tools from sandbox are now active.", LogColors.Cyan); } await ConsoleTts.SpeakReplyAsync(tts, lilith.Logger, greetReply); bool running = true; while (running) { lilith.Logger.Write("Input", "You: ", LogColors.Green); string? input = Console.ReadLine()?.Trim(); if (string.IsNullOrEmpty(input)) { continue; } if (input.Equals("/selfimprove smoke", StringComparison.OrdinalIgnoreCase) || input.Equals("/selfimprove run", StringComparison.OrdinalIgnoreCase)) { lilith.Logger.WriteLine("System", lilith.RunSelfImprovementSmokePipeline(), LogColors.Cyan); continue; } if (input.StartsWith("/selfimprove spec ", StringComparison.OrdinalIgnoreCase)) { string json = input["/selfimprove spec ".Length..].Trim(); if (!json.StartsWith('{')) { lilith.Logger.WriteLine("System", "Usage: /selfimprove spec {\"tool_name\":\"ping_self\",\"description\":\"...\",\"category\":\"self\",\"invoke_body\":\"return \\\"pong\\\";\"}", LogColors.Orange); continue; } lilith.Logger.WriteLine("System", lilith.SaveSelfImproveToolSpec(json), LogColors.Cyan); continue; } if (input.StartsWith("/voice ", StringComparison.OrdinalIgnoreCase)) { string newVoice = input.Substring(7).Trim(); if (tts is not null) { try { tts.SetVoice(newVoice); lilith.Logger.WriteLine("System", $"Voice changed to: {newVoice}", LogColors.Cyan); } catch (Exception ex) { lilith.Logger.WriteLine("System", $"Failed to change voice: {ex.Message}", LogColors.Orange); } } else { lilith.Logger.WriteLine("System", "TTS is not enabled.", LogColors.Orange); } continue; } var (continueRunning, assistantReply) = await lilith.HandleInputAsync(input); await ConsoleTts.SpeakReplyAsync(tts, lilith.Logger, assistantReply); running = continueRunning; } lilith.SaveConversation(); lilith.Logger.WriteLine("System", "Goodbye.", LogColors.Cyan); } }}
Documentation
Program
Console host for the Version 3 Lilith chat session.
Program.cs
- Sets UTF-8 console output and window title.
- Attempts
KokoroTtssetup (speech after replies); continues without TTS on failure. BootAsyncthen loops on user input untilexitor slash commands.