import { type LoopState } from "../state/machine.js"; import { type McpSpawnConfig } from "./agent-runner.js"; import { runBuilder, type BuilderResult } from "./run-builder.js"; import { runInspector, type InspectorResult } from "./run-inspector.js"; import { runOwnerReview, type OwnerResult } from "./run-owner-review.js"; import { runSuperintendent, type SuperintendentResult } from "./run-superintendent.js"; export type SuperintendentStopReason = "completed" | "dry_run" | "max_rounds" | "paused" | "stopped" | "aborted"; export type SuperintendentRunResult = LoopState & { stopReason: SuperintendentStopReason; }; export interface SuperintendentFileStat { isFile(): boolean; isDirectory(): boolean; mtimeMs: number; } export interface SuperintendentFileSystem { readFile(path: string, encoding: BufferEncoding): Promise; writeFile(path: string, data: string, options?: { encoding?: BufferEncoding; flag?: string; }): Promise; readdir(path: string): Promise; stat(path: string): Promise; lstat(path: string): Promise<{ isSymbolicLink(): boolean; }>; mkdir(path: string, options?: { recursive?: boolean; }): Promise; rmdir(path: string): Promise; rename(oldPath: string, newPath: string): Promise; unlink?(path: string): Promise; } export interface AgentRunInput { agent: string; prompt: string; cwd: string; mode?: string; mcpServers?: McpSpawnConfig; runtime?: "host" | "docker"; runtimeImage?: string; detach?: boolean; mountPoeCode?: boolean; runnerSync?: "both" | "upload" | "none"; signal?: AbortSignal; logPath?: string; onStdout?: (chunk: string) => void; onStderr?: (chunk: string) => void; } export interface AgentRunResult { stdout: string; stderr: string; exitCode: number; summary?: string; log?: string; logFile?: string; output?: string; text?: string; transition?: unknown; toolCalls?: unknown; sessionResult?: unknown; } export type LoopCallbacks = { runRole?: (role: "builder" | "inspector" | "superintendent" | "owner", name: string | undefined, run: () => Promise) => Promise; onBuilderStart?: () => void; onBuilderComplete?: (result: BuilderResult) => void; onBuilderFailed?: (error: Error) => void; onInspectorStart?: (name: string) => void; onInspectorComplete?: (result: InspectorResult) => void; onInspectorFailed?: (name: string, error: Error) => void; onSuperintendentStart?: () => void; onSuperintendentComplete?: (result: SuperintendentResult) => void; onOwnerStart?: () => void; onOwnerComplete?: (result: OwnerResult) => void; onRoundComplete?: (round: number) => void; onLoopComplete?: (state: SuperintendentRunResult) => void; onStateChange?: (state: LoopState) => void; shouldPause?: () => boolean; shouldStop?: () => boolean; }; export type LoopRunners = { builder?: typeof runBuilder; inspector?: typeof runInspector; superintendent?: typeof runSuperintendent; ownerReview?: typeof runOwnerReview; }; export type RunLoopOptions = { docPath: string; cwd: string; homeDir: string; fs?: SuperintendentFileSystem; callbacks?: LoopCallbacks; runAgent?: (input: AgentRunInput) => Promise; builderAgent?: string; runners?: LoopRunners; signal?: AbortSignal; logDir?: string; }; export declare function runLoop(docPath: string, callbacks?: LoopCallbacks): Promise; export declare function runLoop(options: RunLoopOptions): Promise;