import type { Credential } from "@earendil-works/pi-ai";
import type { ExtensionAPI, ExtensionContext } from "../../types.ts";
import { type CursorCliSessionRouter } from "./session-router.ts";
import type { CursorCliOauthProviderSettings } from "./settings.ts";
import { type CursorCliTransportHandle, type CursorCliTransportInput } from "./transport.ts";
/** Minimum known-good cursor-agent version; below it senpi warns once per session but never blocks. */
export declare const CURSOR_CLI_MINIMUM_KNOWN_GOOD_VERSION = "2026.08.11";
/** This lane always authenticates through per-account sandboxed HOME file stores. */
export declare const CURSOR_CLI_STATUS_LANE = "file-store";
/** senpi never delegates compaction on this lane, so it is always the context owner. */
export declare const CURSOR_CLI_STATUS_CONTEXT_OWNER = "senpi";
/** The native Cursor provider id; the recommended default when both providers are configured. */
export declare const NATIVE_CURSOR_PROVIDER_ID = "cursor";
export type CursorCliBlockWindow = {
    readonly account: string;
    readonly reason: "rate_limit" | "auth_error";
    /** Expiry timestamp; undefined means blocked until the account logs in again. */
    readonly blockedUntil: number | undefined;
};
export type CursorCliStatusReport = {
    readonly lane: typeof CURSOR_CLI_STATUS_LANE;
    readonly selectedAccount: string | undefined;
    readonly pinnedAccount: string | undefined;
    readonly chatId: string | undefined;
    readonly lastModel: string | undefined;
    readonly contextOwner: typeof CURSOR_CLI_STATUS_CONTEXT_OWNER;
    readonly executablePath: string | undefined;
    readonly executableVersion: string | undefined;
    readonly minimumKnownGoodVersion: string;
    readonly belowMinimumKnownGood: boolean;
    readonly executableProblem: string | undefined;
    readonly blockWindows: readonly CursorCliBlockWindow[];
    readonly accountNames: readonly string[];
    readonly nativeCursorConfigured: boolean;
};
export type CursorCliStatusDeps = {
    readonly sessionId: string;
    readonly settings: CursorCliOauthProviderSettings;
    readonly readCredential: () => Credential | undefined | Promise<Credential | undefined>;
    readonly readNativeCredential?: () => Credential | undefined | Promise<Credential | undefined>;
    readonly router?: CursorCliSessionRouter;
    readonly resolveExecutable?: (settings: CursorCliOauthProviderSettings) => string;
    readonly probeVersion?: (executable: string) => Promise<string>;
    readonly now?: () => number;
};
export declare function parseCursorCliVersion(version: string): {
    year: number;
    month: number;
    day: number;
} | undefined;
/** Compares two `YYYY.MM.DD[-suffix]` version strings; undefined when either cannot be parsed. */
export declare function compareCursorCliVersions(version: string, floor: string): number | undefined;
/**
 * Collects the status snapshot. Account data is read fresh from the credential
 * store on every call - never memoized - so the rendered state always matches
 * the store even after concurrent logins, removals, or failover blocks. Only
 * account names and metadata are extracted; tokens never enter the report.
 */
export declare function collectCursorCliStatus(deps: CursorCliStatusDeps): Promise<CursorCliStatusReport>;
/** Pure renderer: names and metadata only, never token material. */
export declare function renderCursorCliStatus(report: CursorCliStatusReport): string;
export type CursorCliFencedOutcome<T> = {
    readonly status: "completed";
    readonly value: T;
} | {
    readonly status: "dropped";
    readonly reason: string;
};
export type CursorCliDeferredContinuation<T> = {
    /** Runs the continuation through the fence, even if its timer was cancelled or already fired. */
    fire(): Promise<CursorCliFencedOutcome<T>>;
    cancel(): void;
};
export type CursorCliDroppedReporter = (description: string, reason: string) => void;
/**
 * A reload retires this extension generation (`AgentSession.reload()` then
 * invalidates the old runner) while timers and promise continuations captured
 * by it are still armed; every `ExtensionContext` getter then throws
 * "stale extension generation after reload". The context carries no liveness
 * flag, so a retired generation is only observable by probing a getter.
 */
export declare function isCursorCliContextRetired(ctx: ExtensionContext): boolean;
/** Per-registration generation fence; one per extension registration (a reload builds a new one). */
export declare class CursorCliGenerationGuard {
    private retired;
    private retirementReason;
    private readonly timers;
    private droppedReporter;
    isRetired(): boolean;
    retire(reason: string): void;
    onDropped(reporter: CursorCliDroppedReporter): void;
    /** Arms a timer the shutdown path cancels; arming after retirement is a no-op by construction. */
    setTrackedTimeout(callback: () => void, delayMs: number): () => void;
    /** Cancels every armed timer; returns how many were pending. */
    clearTrackedTimers(): number;
    /**
     * Runs a deferred continuation behind the generation fence. A dropped
     * continuation is reported, never silently presented as completed.
     */
    runFenced<T>(ctx: ExtensionContext, work: (ctx: ExtensionContext) => Promise<T> | T): Promise<CursorCliFencedOutcome<T>>;
    /** Synchronous variant for continuations that only touch the context once, after an outer await. */
    runFencedSync(ctx: ExtensionContext, work: () => void): {
        ran: boolean;
    };
    defer<T>(ctx: ExtensionContext, work: (ctx: ExtensionContext) => Promise<T> | T, delayMs?: number): CursorCliDeferredContinuation<T>;
    private armTracked;
    private cancelTimer;
    private retirementReasonFor;
    private reportDropped;
}
/**
 * Registry of live children this extension spawned. Entries leave the registry
 * when their transport run settles, so `killAll` only ever signals live
 * process groups and is idempotent across repeated interruptions.
 */
export declare class CursorCliChildRegistry {
    private readonly children;
    track(handle: CursorCliTransportHandle): CursorCliTransportHandle;
    livePids(): number[];
    /** SIGTERMs every tracked process group with a SIGKILL escalation; returns the pids it signalled. */
    killAll(graceMs?: number): number[];
}
/** Shared registry; child pids are process-wide resources, so one registry serves every generation. */
export declare const cursorCliChildRegistry: CursorCliChildRegistry;
/** Spawns one cursor-agent run through the transport and registers it for shutdown teardown. */
export declare function spawnCursorCliTracked(input: CursorCliTransportInput, registry?: CursorCliChildRegistry): CursorCliTransportHandle;
export type CursorCliShutdownSafetyDeps = {
    readonly generation?: CursorCliGenerationGuard;
    readonly registry?: CursorCliChildRegistry;
};
/**
 * Installs the `session_shutdown`/`session_extensions_removed` teardown: kill
 * every tracked child's process group, cancel the generation's pending timers,
 * and retire the generation so every deferred continuation is fenced. Safe to
 * fire repeatedly; a retired generation is never resurrected (a reload builds a
 * new registration with a fresh guard).
 */
export declare function registerCursorCliShutdownSafety(pi: Pick<ExtensionAPI, "on">, deps?: CursorCliShutdownSafetyDeps): CursorCliGenerationGuard;
//# sourceMappingURL=diagnostics.d.ts.map