/// A chat's default name, shown until the operator or the harness names it. library; /// The web's names for the chat harnesses; an unknown one shows as sent. String chatBackendLabel(String backend) => switch (backend) { 'codex' => 'Codex', 'claude' => 'Claude', 'pi' => 'Pi', 'opencode' => 'OpenCode', _ => backend, }; /// The default chat name: the directory's last folder and the harness, as in /// "Pipelines Codex". String defaultChatName(String directory, String harnessLabel) { final parts = directory .split('/') .where((part) => part.isNotEmpty && part != '~') .toList(); final leaf = parts.isEmpty ? 'Home' : parts.last; final folder = leaf.isEmpty ? 'Home' : '${leaf[0].toUpperCase()}${leaf.substring(1)}'; return '$folder $harnessLabel'; } /// OpenCode's placeholder for a session it has not named yet /// ("New session - 2026-12-02T09:00:00.000Z"). final RegExp _harnessPlaceholder = RegExp( r'^(New|Child) session - \d{4}-\d{2}-\d{2}T', ); /// The title a harness gave a chat, or null while it has none of its own /// (blank, or only its placeholder). String? chatHarnessTitle(String title) { final trimmed = title.trim(); if (trimmed.isEmpty || _harnessPlaceholder.hasMatch(trimmed)) return null; return title; }