projectDirName function
The normalized terminal folder name for path.
Returns my_agent when path has no usable last segment.
Implementation
String projectDirName(String path) {
final String normalized = path.replaceAll('\\', '/');
final String trimmed = normalized.endsWith('/')
? normalized.substring(0, normalized.length - 1)
: normalized;
final List<String> segments = trimmed.split('/');
final String last = segments.isEmpty ? '' : segments.last.trim();
if (last.isEmpty || last == '.') {
return 'my_agent';
}
return last;
}