(
{
repoPath,
branch,
slug,
}: { repoPath: string; branch: string; slug: string },
depth: number,
out: string[],
visited: Set<string>
)
| 49 | } |
| 50 | |
| 51 | export function crawlBranch( |
| 52 | { |
| 53 | repoPath, |
| 54 | branch, |
| 55 | slug, |
| 56 | }: { repoPath: string; branch: string; slug: string }, |
| 57 | depth: number, |
| 58 | out: string[], |
| 59 | visited: Set<string> |
| 60 | ): void { |
| 61 | const key = `${branch}:${slug}`; |
| 62 | if (visited.has(key)) { |
| 63 | out.push(`${indent(depth)}(cycle detected: ${key})`); |
| 64 | return; |
| 65 | } |
| 66 | visited.add(key); |
| 67 | const path = `.orchestrate/${slug}/state.json`; |
| 68 | let raw: string; |
| 69 | try { |
| 70 | raw = execFileSync( |
| 71 | "git", |
| 72 | ["-C", repoPath, "show", `origin/${branch}:${path}`], |
| 73 | { |
| 74 | stdio: ["ignore", "pipe", "pipe"], |
| 75 | } |
| 76 | ).toString(); |
| 77 | } catch { |
| 78 | out.push( |
| 79 | `${indent(depth)}${branch}:${path} (not found — planner hasn't committed state yet)` |
| 80 | ); |
| 81 | return; |
| 82 | } |
| 83 | let state: TreeTask[] | null = null; |
| 84 | let ownSlug = slug; |
| 85 | try { |
| 86 | const parsed = parseTreeStateJson(raw, `${branch}:${path}`); |
| 87 | state = parsed.tasks; |
| 88 | ownSlug = parsed.rootSlug ?? slug; |
| 89 | } catch (err) { |
| 90 | out.push( |
| 91 | `${indent(depth)}${branch}:${path} (parse failed: ${errorMessage(err)})` |
| 92 | ); |
| 93 | return; |
| 94 | } |
| 95 | out.push( |
| 96 | `${indent(depth)}${ownSlug}/ (${state?.length ?? 0} tasks, on ${branch})` |
| 97 | ); |
| 98 | for (const t of state ?? []) { |
| 99 | const lineage = t.parentAgentId ? ` parent=${t.parentAgentId}` : ""; |
| 100 | out.push( |
| 101 | `${indent(depth + 1)}${t.name.padEnd(28)} ${t.type.padEnd(11)} ${t.status.padEnd(11)} ${t.agentId ?? ""}${lineage}` |
| 102 | ); |
| 103 | if ( |
| 104 | t.type === "subplanner" && |
| 105 | (t.status === "running" || t.status === "handed-off") |
| 106 | ) { |
| 107 | // `ownSlug` (from loaded state.json) is authoritative over the param. |
| 108 | crawlBranch( |
no test coverage detected