* Quick placeholder title: strip display tags, take the first sentence, * collapse whitespace, truncate to 50 chars. Returns undefined if the result * is empty (e.g. message was only ). Replaced by * generateSessionTitle once Haiku resolves (~1-15s).
(raw: string)
| 513 | * generateSessionTitle once Haiku resolves (~1-15s). |
| 514 | */ |
| 515 | function deriveTitle(raw: string): string | undefined { |
| 516 | // Strip <ide_opened_file>, <session-start-hook>, etc. — these appear in |
| 517 | // user messages when IDE/hooks inject context. stripDisplayTagsAllowEmpty |
| 518 | // returns '' (not the original) so pure-tag messages are skipped. |
| 519 | const clean = stripDisplayTagsAllowEmpty(raw) |
| 520 | // First sentence is usually the intent; rest is often context/detail. |
| 521 | // Capture group instead of lookbehind — keeps YARR JIT happy. |
| 522 | const firstSentence = /^(.*?[.!?])\s/.exec(clean)?.[1] ?? clean |
| 523 | // Collapse newlines/tabs — titles are single-line in the remote session list. |
| 524 | const flat = firstSentence.replace(/\s+/g, ' ').trim() |
| 525 | if (!flat) return undefined |
| 526 | return flat.length > TITLE_MAX_LEN |
| 527 | ? flat.slice(0, TITLE_MAX_LEN - 1) + '\u2026' |
| 528 | : flat |
| 529 | } |
no test coverage detected