import { ChannelMessenger } from './channel-messenger.js';
import type { ProcessSpawner } from './process-spawner.js';
import { TemplateResolver } from './template-resolver.js';
import type { StepOutcome } from './trajectory.js';
import type { AgentDefinition, ErrorHandlingConfig, StepCompletionMode, VerificationCheck, WorkflowStep, WorkflowStepCompletionReason, WorkflowStepRow, WorkflowStepStatus } from './types.js';
import { type VerificationOptions, type VerificationResult, type VerificationSideEffects } from './verification.js';
type StateLike = {
    row: WorkflowStepRow;
};
export interface StepResult {
    status: WorkflowStepStatus;
    output: string;
    exitCode?: number;
    exitSignal?: string;
    duration: number;
    retries: number;
    completionReason?: WorkflowStepCompletionReason;
    error?: string;
}
export interface StepSchedule {
    step: WorkflowStep;
    readyAt: number;
    staggerDelay: number;
}
export interface StepExecutorDeps<TState extends StateLike = StateLike> {
    cwd: string;
    runId?: string;
    postToChannel?: (text: string) => void;
    persistStepRow?: (stepId: string, patch: Partial<WorkflowStepRow>) => Promise<void>;
    persistStepOutput?: (runId: string, stepName: string, output: string) => Promise<void>;
    resolveTemplate?: (template: string, context: Record<string, unknown>) => string;
    getStepOutput?: (stepName: string) => string | undefined;
    loadStepOutput?: (runId: string, stepName: string) => string | undefined;
    checkAborted?: () => void;
    waitIfPaused?: () => Promise<void>;
    log?: (message: string) => void;
    processSpawner?: ProcessSpawner;
    templateResolver?: TemplateResolver;
    channelMessenger?: ChannelMessenger;
    verificationRunner?: (check: VerificationCheck, output: string, stepName: string, injectedTaskText?: string, options?: VerificationOptions, sideEffects?: VerificationSideEffects) => VerificationResult;
    executeStep?: (step: WorkflowStep, state: TState, agentMap: Map<string, AgentDefinition>, errorHandling?: ErrorHandlingConfig) => Promise<Partial<StepResult> | void>;
    onStepStarted?: (step: WorkflowStep, state: TState) => Promise<void> | void;
    onStepRetried?: (step: WorkflowStep, state: TState, attempt: number, maxRetries: number) => Promise<void> | void;
    onStepCompleted?: (step: WorkflowStep, state: TState, result: StepResult) => Promise<void> | void;
    onStepFailed?: (step: WorkflowStep, state: TState, result: StepResult) => Promise<void> | void;
    onBeginTrack?: (steps: WorkflowStep[]) => Promise<void> | void;
    onConverge?: (steps: WorkflowStep[], outcomes: StepOutcome[]) => Promise<void> | void;
    markDownstreamSkipped?: (failedStepName: string) => Promise<void>;
    buildCompletionMode?: (stepName: string, completionReason?: WorkflowStepCompletionReason) => StepCompletionMode | undefined;
}
export interface MonitorStepOptions<TState extends StateLike, TResult> {
    maxRetries?: number;
    retryDelayMs?: number;
    startMessage?: string;
    onStart?: (attempt: number, state: TState) => Promise<void> | void;
    onRetry?: (attempt: number, maxRetries: number, state: TState) => Promise<void> | void;
    execute: (attempt: number, state: TState) => Promise<TResult>;
    toCompletionResult: (result: TResult, attempt: number, state: TState) => Partial<StepResult>;
    onAttemptFailed?: (error: unknown, attempt: number, state: TState) => Promise<void> | void;
    getFailureResult?: (error: unknown, attempt: number, state: TState) => Partial<StepResult>;
}
export declare class StepExecutor<TState extends StateLike = StateLike> {
    private readonly deps;
    private readonly templateResolver;
    private readonly channelMessenger;
    private readonly verificationRunner;
    constructor(deps: StepExecutorDeps<TState>);
    findReady(steps: WorkflowStep[], statuses: Map<string, WorkflowStepStatus> | Map<string, TState>): WorkflowStep[];
    /** @deprecated Use {@link findReady} instead. This is an alias kept for backward compatibility. */
    findReadySteps(steps: WorkflowStep[], statuses: Map<string, WorkflowStepStatus> | Map<string, TState>): WorkflowStep[];
    scheduleStep(step: WorkflowStep, options?: {
        readyAt?: number;
        staggerDelay?: number;
    }): StepSchedule;
    startStep(step: WorkflowStep, state: TState, startMessage?: string): Promise<void>;
    retryStep(step: WorkflowStep, state: TState, attempt: number, maxRetries: number): Promise<void>;
    completeStep(step: WorkflowStep, state: TState, result: Partial<StepResult>): Promise<StepResult>;
    monitorStep<TResult>(step: WorkflowStep, state: TState, options: MonitorStepOptions<TState, TResult>): Promise<StepResult>;
    executeAll(steps: WorkflowStep[], agentMap: Map<string, AgentDefinition>, errorHandling?: ErrorHandlingConfig, providedStates?: Map<string, TState>): Promise<Map<string, StepResult>>;
    executeOne(step: WorkflowStep, agentMap: Map<string, AgentDefinition>, errorHandling?: ErrorHandlingConfig, providedState?: TState): Promise<StepResult>;
    markFailed(stepName: string, error: string): Promise<void>;
    buildStepOutputContext(stepStates: Map<string, TState>): Record<string, {
        output: string;
    }>;
    resolveStepTemplate(template: string, context: Record<string, unknown>): string;
    getChannelMessenger(): ChannelMessenger;
    runVerification(check: VerificationCheck, output: string, stepName: string, injectedTaskText?: string, options?: VerificationOptions): VerificationResult;
    private executeScheduledStep;
    private executeWithProcessSpawner;
    private createEphemeralStates;
    private createEphemeralState;
    private getStatus;
}
export {};
//# sourceMappingURL=step-executor.d.ts.map