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 lastChange = await getLastChange();
  if (lastChange == null) {
    return const TextCommandResult(
      'Nothing to undo. No file changes recorded in this session.',
    );
  }

  final changeId = lastChange['id'] as String? ?? '';
  final filePath = lastChange['file'] as String? ?? 'unknown';
  final toolName = lastChange['tool'] as String? ?? 'unknown';

  final success = await revertChange(changeId);
  if (success) {
    return TextCommandResult('Reverted $toolName on $filePath.');
  }
  return TextCommandResult(
    'Failed to undo change on $filePath. '
    'The file may have been modified since.',
  );
}