import type { DevToolsSys } from "../types";
import { type Credentials } from "./credentials";
import type { CodegenFeedback, CodegenTurn, CustomInstruction, GenerateCompletionState, GenerateCompletionStep, GenerateUserMessage, UserContext } from "$/ai-utils";
import prettier from "prettier";
import { type CommitMode, type FusionContext } from "./code-tools";
export interface RunCommandCtx {
    command: string;
    state: "running" | "stopped";
    ensureRunning: () => Promise<boolean>;
    addCheckpoint: () => void;
    getCheckpoints: (n: number, mode: "all" | "out" | "err") => string;
    getAllStdout: () => string;
    getAllStderr: () => string;
    getOutput: () => string;
    waitUntilIdle: (initialWaitMs?: number, idleTimeMs?: number) => Promise<void>;
    pid: number | undefined;
    onClose: (callback: (code: number | null) => void) => void;
    onStdout: (callback: (data: string) => void) => void;
    onStderr: (callback: (data: string) => void) => void;
    restart: () => Promise<void>;
}
export interface SessionContext {
    sessionId: string;
    turns: CodegenTurn[];
    customInstructions: CustomInstruction[];
    userContext: UserContext;
    prettierConfig: prettier.Config | null;
    state: GenerateCompletionState;
    title: string | undefined;
    beforeCommit: string | undefined;
    createdUnixTime: number;
    updatedUnixTime: number;
}
export interface CodeGenSessionOptionsBase {
    sys: DevToolsSys;
    credentials: Credentials;
    position: string;
    maxTokens?: number;
    mode?: "quality" | "quality-v3" | "fast";
    builtInCustomInstructions?: CustomInstruction[];
    fusionContext?: FusionContext;
    workingDirectory?: string;
}
export interface CodeGenSessionOptionsSession extends CodeGenSessionOptionsBase {
    sessionOrCompletionId?: string;
}
export interface CodeGenSessionOptionsInitialUrl extends CodeGenSessionOptionsBase {
    initialUrl: string;
}
export type CodeGenSessionOptions = CodeGenSessionOptionsSession | CodeGenSessionOptionsInitialUrl;
export declare class CodeGenSession {
    #private;
    constructor(options: CodeGenSessionOptions);
    get workingDirectory(): string;
    initializeSession(): Promise<void>;
    setRepoUrl(repoUrl: string): void;
    setPrUrl(prUrl: string): void;
    pushRepo(repoFullName: string, githubToken: string): Promise<{
        success: boolean;
        error: string;
        details?: undefined;
    } | {
        success: boolean;
        error: string;
        details: string;
    } | {
        success: boolean;
        error?: undefined;
        details?: undefined;
    }>;
    createPR(repoFullName: string, githubToken: string, branchName: string, projectId: string): Promise<{
        success: boolean;
        prUrl: any;
        prNumber: any;
        error?: undefined;
        details?: undefined;
    } | {
        success: boolean;
        error: string;
        details: unknown;
        prUrl?: undefined;
        prNumber?: undefined;
    }>;
    getCommitMode(): CommitMode | undefined;
    setCommitMode(commitMode: CommitMode): void;
    pushChanges(pullFirst?: boolean): Promise<void>;
    hasChangesRelativeToRemote(): Promise<boolean>;
    pullLatestFromRemote(): Promise<void>;
    /**
     * Get the current commit hash
     */
    getCurrentCommitHash(): Promise<string | undefined>;
    /**
     * Get the feature branch name
     */
    getFeatureBranch(): string | undefined;
    /**
     * Get the AI branch name
     */
    getAiBranch(): string | undefined;
    /**
     * Helper to run git commands
     */
    runGitCommand(command: string): Promise<string>;
    /**
     * Helper to run git commands
     */
    runCheckCommand(): Promise<{
        code: number;
        logs: string;
    } | null>;
    setDebug(debug: boolean): void;
    getAllFiles(): Promise<string[]>;
    isNextPage(): boolean;
    getSessionId(): string;
    getSpaceId(): string | undefined;
    /**
     * Core function to restore the codebase to a state that matches a predicate.
     * This is the main function that handles both git-based and file-based restoration.
     *
     * @param predicate Function that takes a turn and its index and returns true if we should restore up to that turn
     * @param dryRun If true, only simulate the restoration without making changes
     * @returns Array of file paths that were changed
     */
    restore(location: "before" | "after", predicate: (turn: CodegenTurn | null, index: number) => boolean, dryRun?: boolean): Promise<string[] | null>;
    restoreHEAD(): Promise<string[] | null>;
    restoreAll(): Promise<string[] | null>;
    restoreBeforeCompletionId(completionId: string): Promise<string[] | null>;
    /**
     * Undo all changes back to the last user message
     */
    undoLastUserMessage(dryRun?: boolean): Promise<string[] | null>;
    getLastCompletionId(): string | undefined;
    getCurrentState(): GenerateCompletionState;
    getLastTurn(): CodegenTurn | undefined;
    getNextUrl(): string | undefined;
    getNextMessage(): Promise<GenerateUserMessage>;
    sendFeedback(feedback: Partial<CodegenFeedback>): Promise<void>;
    lastTurnHasChanges(): Promise<boolean>;
    sendMessage(message: GenerateUserMessage, immediate?: boolean): Promise<void>;
    getTurns(): CodegenTurn[];
    getSessionContext(): SessionContext;
    abort(): Promise<boolean>;
    stopEventLoop(): Promise<void>;
    close(): Promise<void>;
    connectToEventLoop(shouldReplay: boolean, onStep: (step: GenerateCompletionStep) => void): Promise<() => void>;
    waitForEventLoop(): Promise<void>;
    agentCompletion(userMessage: GenerateUserMessage, signal: AbortSignal | undefined, onStep: (step: GenerateCompletionStep) => void): Promise<void>;
    commitWorkInProgress(lastTurn: CodegenTurn): Promise<string | undefined>;
    /**
     * Returns true if the last turn's afterCommit (or beforeCommit) is different from the session's beforeCommit.
     */
    hasChanges(): boolean;
    isCleanWorkTree(): Promise<boolean>;
}
export declare function transformStream(body: ReadableStream<Uint8Array> | null): AsyncGenerator<string, void, unknown>;
export declare function getUserContext(sys: DevToolsSys): Promise<UserContext>;
export declare function makeAsyncIterator<T>(): readonly [AsyncGenerator<T, void, void>, (event: T) => void, () => void];
export declare function isServerResponding(url: string, maxRetries?: number, retryDelay?: number): Promise<boolean>;
