MCPcopy Create free account
hub / github.com/cursor/plugins / filterVictimsToSubtree

Function filterVictimsToSubtree

orchestrate/skills/orchestrate/scripts/cli/util.ts:185–210  ·  view source on GitHub ↗
(
  victims: TreeVictim[],
  rootAgentId: string | null
)

Source from the content-addressed store, hash-verified

183}
184
185export 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
212export function buildInlineTask(opts: SpawnOptions): PlanTask {
213 if (!opts.name) bail("--file or --name required");

Callers 1

Calls 1

visitFunction · 0.70

Tested by

no test coverage detected