import type { CronJob, CronJobCreate, CronJobPatch, CronTaskSourceListFilters, CronTaskSourceListResult, CronTaskSourceRemoveResult, CronTaskSourceUpdateResult, CronTaskRepairRecoveryAction, CronTaskRepairRecoveryResult } from "../types.js";
import type { CronServiceState } from "./state.js";
type CronJobsEnabledFilter = "all" | "enabled" | "disabled";
type CronJobsSortBy = "nextRunAtMs" | "updatedAtMs" | "name";
type CronSortDir = "asc" | "desc";
export type CronListPageOptions = {
    includeDisabled?: boolean;
    limit?: number;
    offset?: number;
    query?: string;
    enabled?: CronJobsEnabledFilter;
    sortBy?: CronJobsSortBy;
    sortDir?: CronSortDir;
};
export type CronListPageResult = {
    jobs: ReturnType<typeof sortJobs>;
    total: number;
    offset: number;
    limit: number;
    hasMore: boolean;
    nextOffset: number | null;
};
export type CronQueueControlAction = "cancel" | "retry" | "clear-stale";
export type CronQueueControlResult = {
    ok: true;
    action: CronQueueControlAction;
    runId: string;
    jobId: string;
    message: string;
    aborted?: boolean;
    processed?: number;
} | {
    ok: false;
    action: CronQueueControlAction;
    runId: string;
    reason: string;
};
export declare function start(state: CronServiceState): Promise<void>;
export declare function stop(state: CronServiceState): void;
export declare function status(state: CronServiceState): Promise<{
    enabled: boolean;
    storePath: string;
    jobs: number;
    nextWakeAtMs: number | null;
    queue: import("../task-run-queue.js").CronTaskRunQueueSummary;
}>;
export declare function list(state: CronServiceState, opts?: {
    includeDisabled?: boolean;
}): Promise<CronJob[]>;
declare function sortJobs(jobs: CronJob[], sortBy: CronJobsSortBy, sortDir: CronSortDir): CronJob[];
export declare function listPage(state: CronServiceState, opts?: CronListPageOptions): Promise<{
    jobs: CronJob[];
    total: number;
    offset: number;
    limit: number;
    hasMore: boolean;
    nextOffset: number | null;
}>;
export declare function sourcesList(state: CronServiceState, opts?: CronTaskSourceListFilters): Promise<CronTaskSourceListResult>;
export declare function sourcesUpdate(state: CronServiceState, id: string, patch: {
    active?: boolean;
}): Promise<CronTaskSourceUpdateResult>;
export declare function sourcesRemove(state: CronServiceState, id: string): Promise<CronTaskSourceRemoveResult>;
export declare function add(state: CronServiceState, input: CronJobCreate): Promise<CronJob>;
export declare function update(state: CronServiceState, id: string, patch: CronJobPatch): Promise<CronJob>;
export declare function repair(state: CronServiceState, id: string, params: {
    action: CronTaskRepairRecoveryAction;
    source?: string;
    sourceNodeId?: string;
}): Promise<CronTaskRepairRecoveryResult>;
export declare function remove(state: CronServiceState, id: string): Promise<{
    readonly ok: false;
    readonly removed: false;
} | {
    readonly ok: true;
    readonly removed: boolean;
}>;
export declare function run(state: CronServiceState, id: string, mode?: "due" | "force"): Promise<{
    ok: boolean;
    ran: boolean;
    reason: "already-running";
    readonly jobId?: undefined;
    readonly runId?: undefined;
} | {
    ok: boolean;
    ran: boolean;
    reason: "not-due";
    readonly jobId?: undefined;
    readonly runId?: undefined;
} | {
    ok: boolean;
    ran: boolean;
    reason: "needs-access";
    readonly jobId?: undefined;
    readonly runId?: undefined;
} | {
    readonly ok: false;
    readonly ran?: undefined;
    reason?: undefined;
    readonly runId?: undefined;
    readonly detail?: undefined;
} | {
    readonly ok: true;
    readonly ran: false;
    readonly reason: "running" | "queued";
    readonly runId: string;
    readonly detail: string | undefined;
} | {
    readonly ok: true;
    readonly ran: false;
    readonly reason: "error" | "blocked";
    readonly runId: string;
    readonly detail: string | undefined;
} | {
    readonly ok: true;
    readonly ran: true;
    reason?: undefined;
    readonly runId?: undefined;
    readonly detail?: undefined;
}>;
export declare function queueCancel(state: CronServiceState, runId: string, reason?: string): Promise<CronQueueControlResult>;
export declare function queueRetry(state: CronServiceState, runId: string, reason?: string): Promise<CronQueueControlResult>;
export declare function queueClearStale(state: CronServiceState, runId: string, reason?: string): Promise<CronQueueControlResult>;
export declare function wakeNow(state: CronServiceState, opts: {
    mode: "now" | "next-heartbeat";
    text: string;
}): {
    readonly ok: false;
} | {
    readonly ok: true;
};
export declare function work(state: CronServiceState, opts?: {
    maxRuns?: number;
    leaseOwner?: string;
}): Promise<{
    ok: true;
    processed: number;
    outcomes: {
        jobId: string;
        status: import("../types.js").CronRunStatus;
        error: string | undefined;
        sessionId: string | undefined;
        sessionKey: string | undefined;
        delivered: boolean | undefined;
        startedAt: number;
        endedAt: number;
        model: string | undefined;
        provider: string | undefined;
        policy: import("../types.js").CronRunPolicyTelemetry | undefined;
    }[];
}>;
export {};
