initial commit
This commit is contained in:
38
Commands/CompactCommand.cs
Normal file
38
Commands/CompactCommand.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
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)[/]");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user