sessionIdFromSessionPath function

String? sessionIdFromSessionPath(
  1. String path
)

The session id encoded in a session file basename (<timestamp>_<sessionId>.jsonl); null when the name has no id part (foreign files are never sweep candidates).

Implementation

String? sessionIdFromSessionPath(String path) {
  final base = path.split(RegExp(r'[/\\]')).last;
  if (!base.endsWith('.jsonl')) return null;
  final parts = base.substring(0, base.length - '.jsonl'.length).split('_');
  return parts.length < 2 || parts.last.isEmpty ? null : parts.last;
}