39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using Microsoft.Extensions.AI;
|
|
using Spectre.Console;
|
|
|
|
namespace AnchorCli.Commands;
|
|
|
|
internal class CompactCommand(ContextCompactor compactor, List<ChatMessage> history) : ICommand
|
|
{
|
|
public string Name => "compact";
|
|
public string Description => "Manually compact conversation history via LLM summarization";
|
|
|
|
public async Task ExecuteAsync(string[] args, CancellationToken ct)
|
|
{
|
|
if (history.Count < 5)
|
|
{
|
|
AnsiConsole.MarkupLine("[dim grey]Nothing to compact (too few messages).[/]");
|
|
return;
|
|
}
|
|
|
|
AnsiConsole.MarkupLine("[yellow]⚠ Manually compacting conversation history...[/]");
|
|
|
|
bool compacted = await AnsiConsole.Status()
|
|
.Spinner(Spinner.Known.BouncingBar)
|
|
.SpinnerStyle(Style.Parse("yellow"))
|
|
.StartAsync("Compacting context...", async ctx =>
|
|
await compactor.TryCompactAsync(history, ct));
|
|
|
|
if (compacted)
|
|
{
|
|
AnsiConsole.MarkupLine(
|
|
$"[green]✓ Context compacted ({history.Count} messages remaining)[/]");
|
|
}
|
|
else
|
|
{
|
|
AnsiConsole.MarkupLine(
|
|
"[dim grey] (compaction skipped — not enough history to compress)[/]");
|
|
}
|
|
}
|
|
}
|