agent-ecosystem/src/shared/utils/leadDetection.ts
iliya 194bd1bf1e feat: enhance task messaging and member role detection
- Introduced a new function `quoteMarkdown` to format task comments with markdown quotes for better readability.
- Updated the `buildCommentNotificationMessage` to utilize `quoteMarkdown`, ensuring comments are displayed correctly.
- Refactored member role detection across multiple services to use `isLeadMember` for consistency and clarity in identifying team leads.
- Enhanced various components to improve handling of team member roles, ensuring accurate representation in UI and logic.
- Adjusted tests to reflect changes in comment formatting and member role checks, improving overall reliability.
2026-03-15 17:45:10 +02:00

34 lines
1.4 KiB
TypeScript

/**
* Lead agent type detection.
*
* CLI Claude Code assigns inconsistent agentType values to the lead member
* across different versions/runs: "team-lead", "lead", "orchestrator",
* or even "general-purpose". This module centralizes lead detection
* so the rest of the codebase does not need to hard-code any single value.
*/
const LEAD_AGENT_TYPES = new Set(['team-lead', 'lead', 'orchestrator']);
/**
* Returns true if the given agentType string identifies a team lead.
* Handles all known CLI variants: "team-lead", "lead", "orchestrator".
*
* Does NOT match "general-purpose" — that value is ambiguous and used
* for regular teammates too. Lead detection for "general-purpose" agents
* must rely on name-based checks (see {@link isLeadMember}).
*/
export function isLeadAgentType(agentType: string | undefined | null): boolean {
if (!agentType) return false;
return LEAD_AGENT_TYPES.has(agentType);
}
/**
* Returns true if the member is a team lead, checking both agentType
* and the conventional "team-lead" name as a fallback.
*/
export function isLeadMember(member: { agentType?: unknown; name?: unknown }): boolean {
const agentType = typeof member.agentType === 'string' ? member.agentType : null;
if (isLeadAgentType(agentType)) return true;
const name = typeof member.name === 'string' ? member.name.trim().toLowerCase() : '';
return name === 'team-lead';
}