( victims: TreeVictim[], rootAgentId: string | null )
| 183 | } |
| 184 | |
| 185 | export function filterVictimsToSubtree( |
| 186 | victims: TreeVictim[], |
| 187 | rootAgentId: string | null |
| 188 | ): TreeVictim[] { |
| 189 | if (!rootAgentId) return victims; |
| 190 | const childrenByParent = new Map<string, TreeVictim[]>(); |
| 191 | for (const v of victims) { |
| 192 | if (!v.parentAgentId) continue; |
| 193 | const list = childrenByParent.get(v.parentAgentId) ?? []; |
| 194 | list.push(v); |
| 195 | childrenByParent.set(v.parentAgentId, list); |
| 196 | } |
| 197 | const out: TreeVictim[] = []; |
| 198 | const seen = new Set<string>(); |
| 199 | const visit = (agentId: string): void => { |
| 200 | if (seen.has(agentId)) return; |
| 201 | seen.add(agentId); |
| 202 | const directHit = victims.find(v => v.agentId === agentId); |
| 203 | if (directHit) out.push(directHit); |
| 204 | for (const child of childrenByParent.get(agentId) ?? []) { |
| 205 | visit(child.agentId); |
| 206 | } |
| 207 | }; |
| 208 | visit(rootAgentId); |
| 209 | return out; |
| 210 | } |
| 211 | |
| 212 | export function buildInlineTask(opts: SpawnOptions): PlanTask { |
| 213 | if (!opts.name) bail("--file or --name required"); |
no test coverage detected