/** * Bounded parallel sub-agent executor with worktree isolation. * * Each task runs inside its own git worktree (via worktree.ts) so concurrent * writes never collide; after the task completes its diff is merged back onto * the main tree, and conflicting merges surface an explicit conflict report * (both diffs) in the structured result instead of overwriting silently. * * Spawn policy: depth = 1. Tasks run at depth 0; a sub-agent (depth >= 1) * cannot fan out again — runParallel throws if called at depth >= 1. * * Also hosts the live agent registry (registerAgent/finishAgent/killAgent/ * listAgents) consumed by the /agents command. */ import { type MergeConflictInfo } from "./worktree.ts"; export declare const DEFAULT_MAX_CONCURRENCY = 3; export declare const MAX_SPAWN_DEPTH = 1; export type Verdict = "success" | "failure" | "conflict" | "killed" | "error"; export interface TaskContext { /** Working directory for the task: its isolated worktree path (or repoRoot when useWorktrees=false). */ cwd: string; /** Spawn depth of this task. Tasks at depth >= MAX_SPAWN_DEPTH must not fan out. */ depth: number; signal: AbortSignal; } export interface ParallelTask { id: string; /** Injected task body (no LLM coupling): returns its output text. */ run: (ctx: TaskContext) => Promise | string; } export interface AgentResult { id: string; verdict: Verdict; output: string; conflicts?: MergeConflictInfo; } export interface RunParallelOptions { /** Repo root for worktree isolation. Required unless useWorktrees=false. */ repoRoot?: string; maxConcurrency?: number; /** Current spawn depth; >= MAX_SPAWN_DEPTH refuses to run. */ depth?: number; /** Set false for read-only tasks that need no isolation. */ useWorktrees?: boolean; } export interface AgentInfo { id: string; status: "running" | "finished" | "killed" | "error"; startedAt: number; finishedAt?: number; verdict?: Verdict; output?: string; } export declare function registerAgent(id: string): void; export declare function finishAgent(id: string, verdict: Verdict, output?: string): void; /** Abort a running agent. Returns false if unknown or already finished. */ export declare function killAgent(id: string): boolean; /** Live snapshot of all known agents (running first, then most recent). */ export declare function listAgents(): AgentInfo[]; /** Drop finished/killed entries from the registry. */ export declare function clearFinishedAgents(): void; /** * Build the explicit conflict report appended to an agent's output when its * merge fails: lists the conflicting files and BOTH diffs (incoming vs current * main tree) so the director can decide. Nothing is overwritten silently. */ export declare function formatConflictReport(conflict: MergeConflictInfo): string; /** * Run tasks with bounded concurrency, each in an isolated worktree. * Never throws for individual task failures; throws synchronously when the * spawn-depth policy is violated. */ export declare function runParallel(tasks: ParallelTask[], opts?: RunParallelOptions): Promise; //# sourceMappingURL=parallel-agents.d.ts.map