( teamName: string, )
| 761 | * @returns Array of agent statuses, or null if team not found |
| 762 | */ |
| 763 | export async function getAgentStatuses( |
| 764 | teamName: string, |
| 765 | ): Promise<AgentStatus[] | null> { |
| 766 | const teamData = await readTeamMembers(teamName) |
| 767 | if (!teamData) { |
| 768 | return null |
| 769 | } |
| 770 | |
| 771 | const taskListId = sanitizeName(teamName) |
| 772 | const allTasks = await listTasks(taskListId) |
| 773 | |
| 774 | // Get unresolved tasks grouped by owner (open or in_progress) |
| 775 | const unresolvedTasksByOwner = new Map<string, string[]>() |
| 776 | for (const task of allTasks) { |
| 777 | if (task.status !== 'completed' && task.owner) { |
| 778 | const existing = unresolvedTasksByOwner.get(task.owner) || [] |
| 779 | existing.push(task.id) |
| 780 | unresolvedTasksByOwner.set(task.owner, existing) |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | // Build status for each agent (leader is already in members) |
| 785 | return teamData.members.map(member => { |
| 786 | // Check both name (new) and agentId (legacy) for backwards compatibility |
| 787 | const tasksByName = unresolvedTasksByOwner.get(member.name) || [] |
| 788 | const tasksById = unresolvedTasksByOwner.get(member.agentId) || [] |
| 789 | const currentTasks = uniq([...tasksByName, ...tasksById]) |
| 790 | return { |
| 791 | agentId: member.agentId, |
| 792 | name: member.name, |
| 793 | agentType: member.agentType, |
| 794 | status: currentTasks.length === 0 ? 'idle' : 'busy', |
| 795 | currentTasks, |
| 796 | } |
| 797 | }) |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * Result of unassigning tasks from a teammate |
nothing calls this directly
no test coverage detected