import type { CronJob, CronRunStatus, CronTaskGraphRepairReplay, CronTaskRunCheckpointTrigger, CronTaskWorkflowGraphNodeKind, CronUsageSummary } from "./types.js";
export type CronTaskRunQueueStatus = "queued" | "running" | "ok" | "error" | "skipped" | "blocked" | "canceled" | "recovered";
export type CronTaskRunQueueStepStatus = "queued" | "running" | "ok" | "error" | "skipped" | "blocked" | "canceled" | "recovered";
export type CronTaskRunQueueStepRetryPolicy = {
    maxAttempts: number;
    retryDelayMs: number;
    backoffMultiplier: number;
    retryOn: "error" | "lease-expired" | "error-or-lease-expired";
};
export type CronTaskRunQueueStepResumeState = {
    resumable: boolean;
    reason: string;
    checkpointKeys: string[];
    updatedAtMs: number;
};
export type CronTaskRunQueueStep = {
    id: string;
    kind?: "phase" | "graph-node";
    graphNodeId?: string;
    graphNodeKind?: CronTaskWorkflowGraphNodeKind;
    graphNodeLabel?: string;
    graphNodeDependsOn?: string[];
    graphNodeOptional?: boolean;
    graphNodeSourceRole?: string;
    graphNodeSourcePriority?: number;
    graphNodeSourceFreshness?: string;
    graphNodeSourceExpectedOutputType?: string;
    graphNodeTrustedSourceId?: string;
    status: CronTaskRunQueueStepStatus;
    attempt: number;
    maxAttempts: number;
    retryPolicy?: CronTaskRunQueueStepRetryPolicy;
    nextRetryAtMs?: number;
    resume?: CronTaskRunQueueStepResumeState;
    createdAtMs: number;
    startedAtMs?: number;
    completedAtMs?: number;
    leaseOwner?: string;
    leaseExpiresAtMs?: number;
    checkpoint?: Record<string, unknown>;
    error?: string;
};
export type CronTaskRunQueueItem = {
    runId: string;
    jobId: string;
    jobName: string;
    agentId?: string;
    sessionKey?: string;
    trigger: CronTaskRunCheckpointTrigger;
    status: CronTaskRunQueueStatus;
    createdAtMs: number;
    updatedAtMs: number;
    queuedAtMs: number;
    startedAtMs?: number;
    completedAtMs?: number;
    cancelRequestedAtMs?: number;
    recoveredAtMs?: number;
    error?: string;
    skipReason?: string;
    graphRevision?: number;
    parentRevision?: number;
    repairRevision?: number;
    repairReplay?: CronTaskGraphRepairReplay;
    result?: {
        status: CronRunStatus;
        summary?: string;
        error?: string;
        delivered?: boolean;
        sessionId?: string;
        sessionKey?: string;
        model?: string;
        provider?: string;
        usage?: CronUsageSummary;
    };
    steps: CronTaskRunQueueStep[];
};
export type CronTaskRunQueueStore = {
    version: 1;
    runs: CronTaskRunQueueItem[];
};
export type CronTaskRunQueueWorkerSummary = {
    workerId: string;
    running: number;
    expired: number;
    runIds: string[];
    nextLeaseExpiresAtMs?: number;
    lastLeaseAtMs?: number;
};
export type CronTaskRunQueueActiveRunSummary = {
    runId: string;
    jobId: string;
    jobName: string;
    agentId?: string;
    sessionKey?: string;
    status: CronTaskRunQueueStatus;
    stepId: string;
    attempt: number;
    maxAttempts: number;
    retryPolicy?: CronTaskRunQueueStepRetryPolicy;
    nextRetryAtMs?: number;
    resume?: CronTaskRunQueueStepResumeState;
    leaseOwner?: string;
    leaseExpiresAtMs?: number;
    leaseExpired: boolean;
    queuedAtMs: number;
    startedAtMs?: number;
    updatedAtMs: number;
};
export type CronTaskRunQueueRecentRunSummary = {
    runId: string;
    jobId: string;
    jobName: string;
    agentId?: string;
    sessionKey?: string;
    status: CronTaskRunQueueStatus;
    error?: string;
    resultStatus?: CronRunStatus;
    queuedAtMs: number;
    startedAtMs?: number;
    completedAtMs?: number;
    updatedAtMs: number;
};
export type CronTaskRunQueueSummary = {
    path: string;
    total: number;
    queued: number;
    running: number;
    terminal: number;
    cancelRequested: number;
    expiredLeases: number;
    byStatus: Record<CronTaskRunQueueStatus, number>;
    workers: CronTaskRunQueueWorkerSummary[];
    activeRuns: CronTaskRunQueueActiveRunSummary[];
    recentRuns: CronTaskRunQueueRecentRunSummary[];
};
export type CronTaskRunQueueControlResult = {
    ok: true;
    run: CronTaskRunQueueItem;
    message: string;
} | {
    ok: false;
    reason: string;
    run?: CronTaskRunQueueItem;
};
export declare const CRON_TASK_RUN_QUEUE_WORKER_STEP_ID = "run-tool-or-model";
export declare const CRON_TASK_RUN_QUEUE_COLLECT_STEP_ID = "collect";
export declare const CRON_TASK_RUN_QUEUE_PLAN_ANALYSIS_STEP_ID = "plan-analysis";
export declare const CRON_TASK_RUN_QUEUE_SYNTHESIZE_STEP_ID = "synthesize";
export declare const CRON_TASK_RUN_QUEUE_GRAPH_STEP_PREFIX = "graph:";
export declare function resolveCronTaskRunQueuePath(params: {
    storePath: string;
}): string;
export declare function cronTaskRunQueueGraphStepId(nodeId: string): string;
export declare function cronTaskRunQueueGraphNodeIdFromStepId(stepId: string): string | undefined;
export declare function enqueueCronTaskRunQueueItem(params: {
    storePath: string;
    job: CronJob;
    runId: string;
    trigger: CronTaskRunCheckpointTrigger;
    nowMs: number;
    skipReason?: string;
}): Promise<void>;
export declare function startCronTaskRunQueueStep(params: {
    storePath: string;
    runId: string;
    stepId: string;
    nowMs: number;
    leaseMs: number;
    leaseOwner?: string;
    checkpoint?: Record<string, unknown>;
}): Promise<void>;
export type CronTaskRunQueueLease = {
    runId: string;
    jobId: string;
    stepId: string;
    trigger: CronTaskRunCheckpointTrigger;
    attempt: number;
    skipReason?: string;
    checkpoint?: Record<string, unknown>;
};
export declare function leaseCronTaskRunQueueExecuteSteps(params: {
    storePath: string;
    nowMs: number;
    leaseMs: number;
    leaseOwner?: string;
    runIds?: ReadonlySet<string>;
    maxRuns: number;
}): Promise<CronTaskRunQueueLease[]>;
export declare function retryCronTaskRunQueueExecuteStep(params: {
    storePath: string;
    runId: string;
    nowMs: number;
    error: string;
    checkpoint?: Record<string, unknown>;
}): Promise<"retry" | "terminal">;
export declare function retryCronTaskRunQueueStep(params: {
    storePath: string;
    runId: string;
    stepId: string;
    nowMs: number;
    error: string;
    checkpoint?: Record<string, unknown>;
}): Promise<"retry" | "terminal">;
export declare function checkpointCronTaskRunQueueStep(params: {
    storePath: string;
    runId: string;
    stepId: string;
    nowMs: number;
    leaseMs?: number;
    checkpoint: Record<string, unknown>;
}): Promise<void>;
export declare function completeCronTaskRunQueueStep(params: {
    storePath: string;
    runId: string;
    stepId: string;
    nowMs: number;
    status: CronTaskRunQueueStepStatus;
    error?: string;
    checkpoint?: Record<string, unknown>;
}): Promise<void>;
export declare function finishCronTaskRunQueueItem(params: {
    storePath: string;
    runId: string;
    nowMs: number;
    status: CronTaskRunQueueStatus;
    error?: string;
    result?: CronTaskRunQueueItem["result"];
}): Promise<void>;
export declare function cancelCronTaskRunQueueItem(params: {
    storePath: string;
    runId: string;
    nowMs: number;
    reason?: string;
}): Promise<CronTaskRunQueueControlResult>;
export declare function retryCronTaskRunQueueItem(params: {
    storePath: string;
    runId: string;
    nowMs: number;
    reason?: string;
}): Promise<CronTaskRunQueueControlResult>;
export declare function clearExpiredCronTaskRunQueueLease(params: {
    storePath: string;
    runId: string;
    nowMs: number;
    reason?: string;
}): Promise<CronTaskRunQueueControlResult>;
export declare function recoverCronTaskRunQueueItem(params: {
    storePath: string;
    runId: string;
    nowMs: number;
    reason: string;
}): Promise<void>;
export declare function recoverExpiredCronTaskRunQueueLeases(params: {
    storePath: string;
    nowMs: number;
    reason: string;
}): Promise<void>;
export declare function readCronTaskRunQueue(params: {
    storePath: string;
}): Promise<CronTaskRunQueueStore>;
export declare function removeCronTaskRunQueueItems(params: {
    storePath: string;
    runIds: string[];
}): Promise<{
    removed: number;
}>;
export declare function summarizeCronTaskRunQueue(params: {
    storePath: string;
    nowMs: number;
}): Promise<CronTaskRunQueueSummary>;
