execute method

  1. @override
Future<CommandResult> execute(
  1. String args,
  2. ToolUseContext context
)
override

Execute the command.

Implementation

@override
Future<CommandResult> execute(String args, ToolUseContext context) async {
  final messages = getMessages();
  final estimated = compactionService.estimateTokenCount(messages);
  final percent = (estimated / contextWindow * 100).toStringAsFixed(1);

  final buffer = StringBuffer();
  buffer.writeln('Context Window Usage:');
  buffer.writeln('  Messages: ${messages.length}');
  buffer.writeln(
    '  Estimated tokens: ~$estimated / $contextWindow ($percent%)',
  );
  buffer.writeln('  Auto-compact threshold: ${contextWindow - 13000}');

  if (estimated > contextWindow * 0.8) {
    buffer.writeln(
      '  Warning: Approaching context limit. Consider /compact.',
    );
  }

  return TextCommandResult(buffer.toString());
}