/**
 * Matches `@handle` in body text. Handle is lowercase kebab-case, must follow
 * a word boundary (not part of an email or other identifier). Mirrors the
 * pattern used by the pre-Phase-0 messaging surface so handles already in
 * use stay valid.
 */
export const USER_MENTION_RE = /(?<![A-Za-z0-9._-])@([a-z0-9][a-z0-9-]*)/gi;
/** Separate @agent detection so it doesn't get rolled into user notifications. */
export const AGENT_MENTION_RE = /@agent\b/i;
/** Bounded mention fan-out per comment. Above this, extra @-handles in the
 *  body are ignored — prevents one comment from spamming every workspace
 *  member with notifications and broadcasts. */
export const MAX_MENTIONS_PER_COMMENT = 20;
/**
 * Extract user mentions from a body. Returns AuthUser records, excluding the
 * sender so authors don't notify themselves. Order matches first-occurrence
 * in the body; duplicates removed. Capped at MAX_MENTIONS_PER_COMMENT so a
 * single comment can't fan out unbounded notifications.
 */
export function detectUserMentions(body, senderUserId, authService) {
    if (!body)
        return [];
    const handles = new Set();
    for (const match of body.matchAll(USER_MENTION_RE)) {
        const handle = match[1]?.toLowerCase();
        if (!handle || handle === 'agent')
            continue;
        handles.add(handle);
        if (handles.size >= MAX_MENTIONS_PER_COMMENT)
            break;
    }
    if (handles.size === 0)
        return [];
    const byHandle = new Map(authService.listUsers().map(u => [u.handle, u]));
    const out = [];
    for (const handle of handles) {
        const user = byHandle.get(handle);
        if (user && user.id !== senderUserId)
            out.push(user);
    }
    return out;
}
/** True iff the body contains an `@agent` mention. */
export function hasAgentMention(body) {
    return AGENT_MENTION_RE.test(body);
}
//# sourceMappingURL=mention-detector.js.map