Skip to content

Add smart thread naming (question detection, word boundaries) #6

@alexknowshtml

Description

@alexknowshtml

Summary

Improve thread name generation to detect questions and truncate at word boundaries.

How Andy Does It

In bot.ts generateThreadName():

const MAX_THREAD_NAME_LENGTH = 80;

function generateThreadName(text: string): string {
    const cleaned = text.replace(/\s+/g, ' ').trim();

    // If empty, fall back to timestamp
    if (!cleaned) {
        const now = new Date();
        return `💬 ${now.toLocaleString('en-US', {
            month: 'short', day: 'numeric',
            hour: 'numeric', minute: '2-digit',
            hour12: true, timeZone: 'America/New_York',
        })}`;
    }

    // If short enough, use as-is
    if (cleaned.length <= MAX_THREAD_NAME_LENGTH) {
        return cleaned;
    }

    // For questions, keep the question word and truncate
    const questionMatch = cleaned.match(/^(What|How|Why|Can|Is|Are|Do|Does|Should|Would|Could|Will|Where|When|Who)\s/i);
    if (questionMatch) {
        // Truncate at word boundary
        const truncated = cleaned.slice(0, MAX_THREAD_NAME_LENGTH);
        const lastSpace = truncated.lastIndexOf(' ');
        return (lastSpace > 20 ? truncated.slice(0, lastSpace) : truncated) + '...';
    }

    // Default: truncate at word boundary
    const truncated = cleaned.slice(0, MAX_THREAD_NAME_LENGTH);
    const lastSpace = truncated.lastIndexOf(' ');
    return (lastSpace > 20 ? truncated.slice(0, lastSpace) : truncated) + '...';
}

Current Cord Behavior

Basic truncation at 50 chars with no word boundary awareness:

const threadName = rawText.length > 50
    ? rawText.slice(0, 47) + '...'
    : rawText || 'New conversation';

Implementation

  1. Increase limit to 80 chars
  2. Add timestamp fallback for empty messages
  3. Truncate at word boundaries (find lastIndexOf(' '))
  4. Keep question words intact when possible

Priority

Low - cosmetic improvement

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions