import type { RunnerScope, RuntimeConfig } from "../../poe-code-config/dist/index.js";
import type { RunHandle, Runner, RunSpec } from "../../process-runner/dist/index.js";
import type { StateManager } from "../../poe-code-config/dist/index.js";
export type { RuntimeConfig } from "../../poe-code-config/dist/index.js";
export type { RunHandle, RunSpec } from "../../process-runner/dist/index.js";
export type ExecutionEnvType = "host" | "docker" | "e2b";
export type JobStatus = "running" | "exited" | "killed" | "lost";
export interface ExecutionEnvFactory {
    readonly type: ExecutionEnvType;
    readonly supportsDetach?: boolean;
    open(spec: OpenSpec): Promise<OpenedEnv>;
    attach(envId: string, context?: AttachedJobContext): Promise<OpenedEnv>;
}
export interface OpenSpec {
    cwd: string;
    runtimeCwd?: string;
    runtime: RuntimeConfig;
    runner?: RunnerScope;
    state?: StateManager;
    hostRunner?: Runner;
    env: Record<string, string>;
    uploadIgnoreFiles: string[];
    jobLabel: {
        tool: string;
        argv: string[];
        displayArgv?: string[];
    };
    execution?: {
        wrapForLogTee?: boolean;
        stdin?: RunSpec["stdin"];
        stdout?: RunSpec["stdout"];
        stderr?: RunSpec["stderr"];
        env?: RunSpec["env"];
        tty?: boolean;
        input?: string | Buffer;
        captureOutput?: boolean;
        activityTimeoutMs?: number;
        activityTimeoutSource?: "all" | "stdout";
        onStdout?(chunk: string): void;
        onStderr?(chunk: string): void;
    };
    shellSpec?: RunSpec;
}
export interface UploadResult {
    files: number;
    bytes: number;
    skipped: {
        path: string;
        bytes: number;
        reason: "max_size";
    }[];
}
export interface DownloadResult {
    files: number;
    bytes: number;
    conflicts: {
        path: string;
        reason: "local_modified";
    }[];
}
export interface LogChunk {
    byteOffset: number;
    data: string;
}
export interface AttachedJobContext {
    jobId: string;
    tool: string;
    argv: string[];
    cwd: string;
    reattachContext?: Record<string, unknown>;
}
export interface OpenedEnv {
    readonly id: string;
    readonly job: JobHandle | null;
    readonly reattachContext?: Record<string, unknown>;
    uploadWorkspace(): Promise<UploadResult>;
    downloadWorkspace(opts: {
        conflictPolicy: "refuse" | "overwrite";
    }): Promise<DownloadResult>;
    exec(spec: RunSpec): RunHandle;
    detach(): Promise<JobHandle>;
    shell(): RunHandle;
    close(): Promise<void>;
}
export interface JobHandle {
    readonly id: string;
    readonly envId: string;
    readonly tool: string;
    readonly argv: string[];
    status(): Promise<JobStatus>;
    stream(opts?: {
        sinceByte?: number;
        since?: Date;
        follow?: boolean;
    }): AsyncIterable<LogChunk>;
    wait(): Promise<{
        exitCode: number;
    }>;
    kill(signal?: NodeJS.Signals): Promise<void>;
}
export declare function registerExecutionEnvFactory(factory: ExecutionEnvFactory): void;
export declare function selectExecutionEnv(runtime: RuntimeConfig): ExecutionEnvFactory;
export declare function selectExecutionEnvFactory(type: ExecutionEnvType): ExecutionEnvFactory;
