using Spectre.Console; namespace AnchorCli.Commands; internal class SaveCommand(ChatSession session) : ICommand { public string Name => "save"; public string Description => "Save the current chat session to a file"; public async Task ExecuteAsync(string[] args, CancellationToken ct) { string filePath = args.Length > 0 ? args[0] : ".anchor/session.json"; try { var directory = Path.GetDirectoryName(filePath); if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory)) { Directory.CreateDirectory(directory); } await session.SaveAsync(filePath, ct); AnsiConsole.MarkupLine($"[green]Session saved to {Markup.Escape(filePath)}[/]"); } catch (Exception ex) { AnsiConsole.MarkupLine($"[red]Failed to save session: {Markup.Escape(ex.Message)}[/]"); } } }