MCPcopy Create free account
hub / github.com/Noumena-Network/code / deriveTitle

Function deriveTitle

src/bridge/initReplBridge.ts:515–529  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

513 * generateSessionTitle once Haiku resolves (~1-15s).
514 */
515function 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}

Callers 2

initReplBridgeFunction · 0.85
onUserMessageFunction · 0.85

Calls 1

Tested by

no test coverage detected