import type { DevToolsSys } from "../types";
import type { CLIArgs } from "./index";
import { type Credentials } from "./credentials";
import type { CodegenTurn, CustomInstruction, GenerateCompletionState, GenerateCompletionStep, GenerateUserMessage, UserContext } from "$/ai-utils";
import prettier from "prettier";
import { type ProvidedToolContext } from "./code-tools";
export interface RunCommandCtx {
    command: string;
    state: "running" | "crashed";
    ensureRunning: () => Promise<boolean>;
    addCheckpoint: () => void;
    getCheckpoints: (n: number) => string;
    getAllStdout: () => string;
    getAllStderr: () => string;
    getOutput: () => string;
    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[];
    selectedFilePaths: Map<string, number>;
    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;
    args: CLIArgs;
    position: string;
    maxTokens?: number;
    mode?: "quality" | "quality-v3" | "fast";
    fusion?: boolean;
    fusionRemote?: string;
    fusionAutoInitGit?: boolean;
    builtInCustomInstructions?: CustomInstruction[];
    featureBranch?: string;
    providedToolContext?: ProvidedToolContext;
}
export interface CodeGenSessionOptionsSession extends CodeGenSessionOptionsBase {
    sessionOrCompletionId?: string;
}
export interface CodeGenSessionOptionsInitialUrl extends CodeGenSessionOptionsBase {
    initialUrl: string;
}
export type CodeGenSessionOptions = CodeGenSessionOptionsSession | CodeGenSessionOptionsInitialUrl;
export declare function createCodeSession(options: CodeGenSessionOptions): Promise<CodeGenSession>;
export declare class CodeGenSession {
    #private;
    constructor(options: CodeGenSessionOptions);
    initializeSession(): 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>;
    /**
     * Check if Fusion is enabled for this session
     */
    isFusionEnabled(): boolean;
    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(sentiment: "positive" | "negative" | "undo", message?: string, lastCompletionId?: string | undefined): Promise<void>;
    lastTurnHasChanges(): Promise<boolean>;
    sendMessage(message: GenerateUserMessage): void;
    getTurns(): CodegenTurn[];
    getSessionContext(): SessionContext;
    abort(): void;
    stopEventLoop(): Promise<void>;
    close(): Promise<void>;
    connectToEventLoop(shouldReplay: boolean, onStep: (step: GenerateCompletionStep) => void): () => 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];
