From dcb2ab39688d1d4405e749268d941e59277667a0 Mon Sep 17 00:00:00 2001 From: TomiEckert Date: Sat, 28 Feb 2026 14:35:30 +0100 Subject: [PATCH] feat: Implement compact JSON serialization for history entries, improve history loading robustness, and add a new LLM model option. --- Commands/OnboardCommand.cs | 4 ++-- Commands/StatsCommand.cs | 2 +- Core/HistoryManager.cs | 18 ++++++++++++++---- Serialization/AppJsonSerializerContext.cs | 6 ++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Commands/OnboardCommand.cs b/Commands/OnboardCommand.cs index a6f9c81..b0713cb 100644 --- a/Commands/OnboardCommand.cs +++ b/Commands/OnboardCommand.cs @@ -26,8 +26,8 @@ public static class OnboardCommand config.LlmModel = AnsiConsole.Prompt( new SelectionPrompt() .Title("Select [green]LLM Model[/]:") - .AddChoices(new[] { "openai/gpt-oss-20b", "llama-3.1-8b-instant" }) - .UseConverter(c => c == "openai/gpt-oss-20b" ? "openai/gpt-oss-20b (Fastest)" : "llama-3.1-8b-instant (Cheapest)")); + .AddChoices(new[] { "openai/gpt-oss-20b", "llama-3.1-8b-instant", "llama-3.3-70b-versatile" }) + .UseConverter(c => c == "openai/gpt-oss-20b" ? "openai/gpt-oss-20b (Fastest)" : c == "llama-3.1-8b-instant" ? "llama-3.1-8b-instant (Cheapest)" : "llama-3.3-70b-versatile (More Accurate)")); if (config.LlmModel.Contains(" ")) config.LlmModel = config.LlmModel.Split(' ')[0]; diff --git a/Commands/StatsCommand.cs b/Commands/StatsCommand.cs index 9915980..49d4887 100644 --- a/Commands/StatsCommand.cs +++ b/Commands/StatsCommand.cs @@ -38,7 +38,7 @@ public static class StatsCommand .Select(g => g.Key) .ToList(); - AnsiConsole.MarkupLine("[bold blue]Toak Usage Statistics[/]"); + AnsiConsole.MarkupLine("\n[bold blue]Toak Usage Statistics[/]"); AnsiConsole.MarkupLine($"[dim]Total recordings:[/] {totalCount}"); AnsiConsole.MarkupLine($"[dim]Total duration:[/] {totalDuration.TotalMinutes:F1}m"); AnsiConsole.MarkupLine($"[dim]Average processing latency:[/] {avgDuration.TotalSeconds:F2}s"); diff --git a/Core/HistoryManager.cs b/Core/HistoryManager.cs index 87dc341..c273ed1 100644 --- a/Core/HistoryManager.cs +++ b/Core/HistoryManager.cs @@ -30,7 +30,7 @@ public static class HistoryManager DurationMs = durationMs }; - var json = JsonSerializer.Serialize(entry, AppJsonSerializerContext.Default.HistoryEntry); + var json = JsonSerializer.Serialize(entry, CompactJsonSerializerContext.Default.HistoryEntry); // Thread-safe append lock (HistoryFile) @@ -60,15 +60,25 @@ public static class HistoryManager foreach (var line in lines) { if (string.IsNullOrWhiteSpace(line)) continue; - var entry = JsonSerializer.Deserialize(line, AppJsonSerializerContext.Default.HistoryEntry); - if (entry != null) + if (!line.Trim().StartsWith("{") || !line.Trim().EndsWith("}")) continue; // Skip malformed old multiline json entries + + try { - entries.Add(entry); + var entry = JsonSerializer.Deserialize(line, CompactJsonSerializerContext.Default.HistoryEntry); + if (entry != null) + { + entries.Add(entry); + } + } + catch + { + // Skip entry if deserialization fails } } } catch (Exception ex) { + Console.WriteLine($"CRASH IN LOAD ENTRIES: {ex}"); Logger.LogDebug($"Failed to load history: {ex.Message}"); } diff --git a/Serialization/AppJsonSerializerContext.cs b/Serialization/AppJsonSerializerContext.cs index b828972..5ffbe0e 100644 --- a/Serialization/AppJsonSerializerContext.cs +++ b/Serialization/AppJsonSerializerContext.cs @@ -23,3 +23,9 @@ namespace Toak.Serialization; internal partial class AppJsonSerializerContext : JsonSerializerContext { } + +[JsonSourceGenerationOptions(WriteIndented = false, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] +[JsonSerializable(typeof(Toak.Core.HistoryEntry))] +internal partial class CompactJsonSerializerContext : JsonSerializerContext +{ +}