import type { HookEventPayload, SubAgentEndContext, SubAgentStartContext } from "@clinebot/agents";
import type { LlmsProviders } from "@clinebot/llms";
import type { SessionStatus } from "../types/common";
import { SessionArtifacts } from "./session-artifacts";
import { type SessionManifest } from "./session-manifest";
import type { CreateRootSessionWithArtifactsInput, RootSessionArtifacts, SessionRow, UpsertSubagentInput } from "./session-service";
export interface PersistedSessionUpdateInput {
    sessionId: string;
    expectedStatusLock?: number;
    status?: SessionStatus;
    endedAt?: string | null;
    exitCode?: number | null;
    prompt?: string | null;
    metadata?: Record<string, unknown> | null;
    title?: string | null;
    parentSessionId?: string | null;
    parentAgentId?: string | null;
    agentId?: string | null;
    conversationId?: string | null;
    setRunning?: boolean;
}
export interface SessionPersistenceAdapter {
    ensureSessionsDir(): string;
    upsertSession(row: SessionRow): Promise<void>;
    getSession(sessionId: string): Promise<SessionRow | undefined>;
    listSessions(options: {
        limit: number;
        parentSessionId?: string;
        status?: string;
    }): Promise<SessionRow[]>;
    updateSession(input: PersistedSessionUpdateInput): Promise<{
        updated: boolean;
        statusLock: number;
    }>;
    deleteSession(sessionId: string, cascade: boolean): Promise<boolean>;
    enqueueSpawnRequest(input: {
        rootSessionId: string;
        parentAgentId: string;
        task?: string;
        systemPrompt?: string;
    }): Promise<void>;
    claimSpawnRequest(rootSessionId: string, parentAgentId: string): Promise<string | undefined>;
}
export declare class UnifiedSessionPersistenceService {
    private readonly adapter;
    private readonly teamTaskSessionsByAgent;
    private readonly teamTaskLastHeartbeatBySession;
    private readonly teamTaskLastProgressLineBySession;
    protected readonly artifacts: SessionArtifacts;
    private static readonly STALE_REASON;
    private static readonly STALE_SOURCE;
    private static readonly TEAM_HEARTBEAT_LOG_INTERVAL_MS;
    constructor(adapter: SessionPersistenceAdapter);
    ensureSessionsDir(): string;
    private writeManifestFile;
    writeSessionManifest(manifestPath: string, manifest: SessionManifest): void;
    private readManifestFile;
    private buildManifestFromRow;
    private resolveArtifactPath;
    private teamTaskQueueKey;
    private activeTeamTaskSessionId;
    createRootSessionWithArtifacts(input: CreateRootSessionWithArtifactsInput): Promise<RootSessionArtifacts>;
    updateSessionStatus(sessionId: string, status: SessionStatus, exitCode?: number | null): Promise<{
        updated: boolean;
        endedAt?: string;
    }>;
    updateSession(input: {
        sessionId: string;
        prompt?: string | null;
        metadata?: Record<string, unknown> | null;
        title?: string | null;
    }): Promise<{
        updated: boolean;
    }>;
    queueSpawnRequest(event: HookEventPayload): Promise<void>;
    private buildSubsessionRow;
    upsertSubagentSession(input: UpsertSubagentInput): Promise<string | undefined>;
    upsertSubagentSessionFromHook(event: HookEventPayload): Promise<string | undefined>;
    appendSubagentHookAudit(subSessionId: string, event: HookEventPayload): Promise<void>;
    appendSubagentTranscriptLine(subSessionId: string, line: string): Promise<void>;
    persistSessionMessages(sessionId: string, messages: LlmsProviders.Message[], systemPrompt?: string): Promise<void>;
    applySubagentStatus(subSessionId: string, event: HookEventPayload): Promise<void>;
    applySubagentStatusBySessionId(subSessionId: string, status: SessionStatus): Promise<void>;
    applyStatusToRunningChildSessions(parentSessionId: string, status: Exclude<SessionStatus, "running">): Promise<void>;
    onTeamTaskStart(rootSessionId: string, agentId: string, message: string): Promise<void>;
    onTeamTaskEnd(rootSessionId: string, agentId: string, status: SessionStatus, summary?: string, messages?: LlmsProviders.Message[]): Promise<void>;
    onTeamTaskProgress(rootSessionId: string, agentId: string, progress: string, options?: {
        kind?: "heartbeat" | "progress" | "text";
    }): Promise<void>;
    handleSubAgentStart(rootSessionId: string, context: SubAgentStartContext): Promise<void>;
    handleSubAgentEnd(rootSessionId: string, context: SubAgentEndContext): Promise<void>;
    private isPidAlive;
    private reconcileDeadRunningSession;
    listSessions(limit?: number): Promise<SessionRow[]>;
    reconcileDeadSessions(limit?: number): Promise<number>;
    deleteSession(sessionId: string): Promise<{
        deleted: boolean;
    }>;
}
