import type { AgentTool, AgentToolContext, AgentToolResult, AgentToolUpdateCallback, ToolApprovalDecision } from "@oh-my-pi/pi-agent-core";
import type { BunFile } from "bun";
import { type Theme } from "../modes/theme/theme.js";
import type { ToolSession } from "../tools/index.js";
import { type LspServerStatus } from "./client.js";
import { type LspParams, type LspToolDetails, lspSchema } from "./types.js";
export type { LspServerStatus } from "./client.js";
export type { LspToolDetails } from "./types.js";
/**
 * LSP actions that do not mutate the workspace or language-server state.
 * Anything not in this set (rename, code_actions with apply, rename_file,
 * reload, raw request, etc.) is classified as write-tier.
 */
export declare const LSP_READONLY_ACTIONS: ReadonlySet<string>;
export interface LspStartupServerInfo {
    name: string;
    status: "connecting" | "ready" | "error" | "available";
    fileTypes: string[];
    error?: string;
}
/** Result from warming up LSP servers */
export interface LspWarmupResult {
    servers: Array<LspStartupServerInfo & {
        status: "ready" | "error";
    }>;
}
/** Options for warming up LSP servers */
export interface LspWarmupOptions {
    /** Called when starting to connect to servers */
    onConnecting?: (serverNames: string[]) => void;
}
export declare function discoverStartupLspServers(cwd: string, status?: LspStartupServerInfo["status"]): LspStartupServerInfo[];
/**
 * Warm up LSP servers for a directory by connecting to all detected servers.
 * This should be called at startup to avoid cold-start delays.
 *
 * @param cwd - Working directory to detect and start servers for
 * @param options - Optional callbacks for progress reporting
 * @returns Status of each server that was started
 */
export declare function warmupLspServers(cwd: string, options?: LspWarmupOptions): Promise<LspWarmupResult>;
/**
 * Get status of currently active LSP servers.
 */
export declare function getLspStatus(): LspServerStatus[];
/** Result from getDiagnosticsForFile */
export interface FileDiagnosticsResult {
    /** Name of the LSP server used (if available) */
    server?: string;
    /** Formatted diagnostic messages */
    messages: string[];
    /** Summary string (e.g., "2 error(s), 1 warning(s)") */
    summary: string;
    /** Whether there are any errors (severity 1) */
    errored: boolean;
    /** Whether the file was formatted */
    formatter?: FileFormatResult;
}
export declare enum FileFormatResult {
    UNCHANGED = "unchanged",
    FORMATTED = "formatted"
}
/** Options for creating the LSP writethrough callback */
export interface WritethroughOptions {
    /** Whether to format the file using LSP after writing */
    enableFormat?: boolean;
    /** Whether to get LSP diagnostics after writing */
    enableDiagnostics?: boolean;
    /** Called when diagnostics arrive after the main timeout. */
    onDeferredDiagnostics?: (diagnostics: FileDiagnosticsResult) => void;
    /** Signal to cancel a pending deferred diagnostics fetch. */
    deferredSignal?: AbortSignal;
    /** Transform diagnostics before surfacing them after a successful fetch. */
    transformDiagnostics?: (absPath: string, result: FileDiagnosticsResult) => FileDiagnosticsResult;
}
/** Per-file deferred LSP diagnostics wiring for {@link WritethroughCallback}. */
export type WritethroughDeferredHandle = {
    onDeferredDiagnostics: (diagnostics: FileDiagnosticsResult) => void;
    signal: AbortSignal;
    finalize: (diagnostics: FileDiagnosticsResult | undefined) => void;
};
/** Callback type for the LSP writethrough */
export type WritethroughCallback = (dst: string, content: string, signal?: AbortSignal, file?: BunFile, batch?: LspWritethroughBatchRequest, getDeferred?: (dst: string) => WritethroughDeferredHandle | undefined) => Promise<FileDiagnosticsResult | undefined>;
/** No-op writethrough callback */
export declare function writethroughNoop(dst: string, content: string, _signal?: AbortSignal, file?: BunFile, _batch?: LspWritethroughBatchRequest, _getDeferred?: (dst: string) => WritethroughDeferredHandle | undefined): Promise<FileDiagnosticsResult | undefined>;
interface LspWritethroughBatchRequest {
    id: string;
    flush: boolean;
}
export declare function flushLspWritethroughBatch(id: string, cwd: string, signal?: AbortSignal): Promise<FileDiagnosticsResult | undefined>;
/** Create a writethrough callback for LSP aware write operations */
export declare function createLspWritethrough(cwd: string, options?: WritethroughOptions): WritethroughCallback;
/**
 * LSP tool for language server protocol operations.
 */
export declare class LspTool implements AgentTool<typeof lspSchema, LspToolDetails, Theme> {
    private readonly session;
    readonly name = "lsp";
    readonly approval: (args: unknown) => ToolApprovalDecision;
    readonly formatApprovalDetails: (args: unknown) => string[];
    readonly label = "LSP";
    readonly loadMode = "discoverable";
    readonly summary = "Query LSP (language server) for diagnostics, hover info, and references";
    readonly description: string;
    readonly parameters: import("arktype/internal/variants/object.ts").ObjectType<{
        action: "capabilities" | "code_actions" | "definition" | "diagnostics" | "hover" | "implementation" | "references" | "reload" | "rename" | "rename_file" | "request" | "status" | "symbols" | "type_definition";
        file?: string | undefined;
        line?: number | undefined;
        symbol?: string | undefined;
        query?: string | undefined;
        new_name?: string | undefined;
        apply?: boolean | undefined;
        timeout?: number | undefined;
        payload?: string | undefined;
    }, {}>;
    readonly strict = true;
    constructor(session: ToolSession);
    static createIf(session: ToolSession): LspTool | null;
    execute(_toolCallId: string, params: LspParams, signal?: AbortSignal, _onUpdate?: AgentToolUpdateCallback<LspToolDetails>, _context?: AgentToolContext): Promise<AgentToolResult<LspToolDetails>>;
}
