(
selectedAgentIds: Set<string>,
dependencyIds: Set<string>,
agentDefinitions: Map<string, { spawnableAgents?: string[] }>,
localAgentIds: Set<string>,
)
| 53 | // Compute all dependents (agents that spawn the selected agents - reverse dependencies) |
| 54 | // This finds agents that directly or transitively spawn the selected agents |
| 55 | function computeDependents( |
| 56 | selectedAgentIds: Set<string>, |
| 57 | dependencyIds: Set<string>, |
| 58 | agentDefinitions: Map<string, { spawnableAgents?: string[] }>, |
| 59 | localAgentIds: Set<string>, |
| 60 | ): Set<string> { |
| 61 | const dependents = new Set<string>() |
| 62 | // Combined set of agents we're already including (selected + their children) |
| 63 | const alreadyIncluded = new Set([...selectedAgentIds, ...dependencyIds]) |
| 64 | |
| 65 | // Build a reverse map: for each agent, which agents spawn it? |
| 66 | const spawnedBy = new Map<string, Set<string>>() |
| 67 | for (const [agentId, definition] of agentDefinitions) { |
| 68 | const spawnableAgents = definition.spawnableAgents ?? [] |
| 69 | for (const spawnableId of spawnableAgents) { |
| 70 | const simpleId = getSimpleAgentId(spawnableId) |
| 71 | if (!spawnedBy.has(simpleId)) { |
| 72 | spawnedBy.set(simpleId, new Set()) |
| 73 | } |
| 74 | spawnedBy.get(simpleId)!.add(agentId) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // Find all agents that transitively spawn any of the selected agents |
| 79 | const visited = new Set<string>() |
| 80 | function findParents(agentId: string) { |
| 81 | const parents = spawnedBy.get(agentId) |
| 82 | if (!parents) return |
| 83 | |
| 84 | for (const parentId of parents) { |
| 85 | if (visited.has(parentId)) continue |
| 86 | visited.add(parentId) |
| 87 | |
| 88 | // Skip if already included or not a local agent |
| 89 | if (alreadyIncluded.has(parentId)) continue |
| 90 | if (!localAgentIds.has(parentId)) continue |
| 91 | |
| 92 | dependents.add(parentId) |
| 93 | // Recursively find parents of this parent |
| 94 | findParents(parentId) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // Start from each selected agent and find all its parents |
| 99 | for (const agentId of selectedAgentIds) { |
| 100 | findParents(agentId) |
| 101 | } |
| 102 | |
| 103 | return dependents |
| 104 | } |
| 105 | |
| 106 | interface AgentSectionProps { |
| 107 | title?: string |
no test coverage detected