execute method
Execute the command.
Implementation
@override
Future<CommandResult> execute(String args, ToolUseContext context) async {
if (args.trim().isEmpty) {
return TextCommandResult('Current directory: ${getCurrentDir()}');
}
var target = args.trim();
if (target.startsWith('~/')) {
final home = Platform.environment['HOME'] ?? '/';
target = '$home/${target.substring(2)}';
} else if (!target.startsWith('/')) {
target = '${getCurrentDir()}/$target';
}
final dir = Directory(target);
if (!await dir.exists()) {
return TextCommandResult('Directory not found: $target');
}
final resolved = dir.resolveSymbolicLinksSync();
onDirectoryChange(resolved);
return TextCommandResult('Changed directory to: $resolved');
}