export interface ScheduledTask {
    id: string;
    name: string;
    cron: string;
    timezone?: string;
    prompt: string;
    model?: string;
    template?: string;
    enabled: boolean;
    lastRun?: number;
    nextRun?: number;
    runCount: number;
    missedRuns: number;
    createdAt: number;
}
export interface TaskRunRecord {
    taskId: string;
    startedAt: number;
    agentId: string;
    status: 'running' | 'completed' | 'failed';
    error?: string | undefined;
}
interface TaskSchedulerConfig {
    readonly storePath?: string | undefined;
    readonly spawnTask?: (input: {
        readonly prompt: string;
        readonly model?: string | undefined;
        readonly template?: string | undefined;
    }) => string;
}
/**
 * TaskScheduler — cron-like task scheduler that runs inside the daemon.
 *
 * Tasks persist to disk through the configured scheduler store path and survive restarts.
 * Task execution requires an explicit spawnTask callback so runs stay owned by the caller.
 */
export declare class TaskScheduler {
    private tasks;
    private timers;
    /**
     * Per-task run history indexed by taskId — O(1) push + trim per task run.
     * The flat `history` array is derived from this on persist.
     */
    private historyByTask;
    private store;
    private readonly spawnTask;
    private running;
    /** Debounce handle for coalescing rapid successive save() calls. */
    private _saveDebounceTimer;
    constructor(config: string | TaskSchedulerConfig);
    /** Load tasks from disk and start timers. */
    start(): Promise<void>;
    /** Stop all timers. */
    stop(): void;
    /** Add a new scheduled task. Returns the created task with generated ID. */
    add(input: Omit<ScheduledTask, 'id' | 'runCount' | 'createdAt' | 'missedRuns'>): ScheduledTask;
    /** Remove a task by ID. Returns true if found and removed. */
    remove(taskId: string): boolean;
    /** Enable or disable a task. */
    setEnabled(taskId: string, enabled: boolean): boolean;
    /** Return all tasks as an array. */
    list(): ScheduledTask[];
    /** Return the run history for a given task (up to MAX_HISTORY_PER_TASK). O(1) via Map index. */
    getHistory(taskId: string): TaskRunRecord[];
    /** Return all run history records. */
    getAllHistory(): TaskRunRecord[];
    /**
     * Compute the next run time for a cron expression, starting from `from`
     * (defaults to now). Throws if the expression is invalid.
     */
    getNextRun(cron: string, from?: Date, timezone?: string): Date;
    /** Return the missed-run count for a given task. */
    getMissedRuns(taskId: string): number;
    /** Validate an IANA timezone string. Throws if invalid. */
    static validateTimezone(tz: string): void;
    /** Run a task immediately (ignoring its schedule). */
    runNow(taskId: string): Promise<string>;
    private scheduleNext;
    private cancelTimer;
    /**
     * Execute a task by spawning an agent with the task's prompt.
     * Records the run in history and updates the task's lastRun/runCount.
     * Returns the spawned agent ID.
     */
    private executeTask;
    /**
     * O(1) per-task history push + trim.
     * The Map index makes both the push and the cap check O(1) instead of O(n) global filter.
     */
    private pushHistory;
    /** Flatten historyByTask Map into a single array for serialisation. */
    private flatHistory;
    private save;
    /**
     * Debounced save: coalesces multiple rapid calls into a single disk write
     * that fires SAVE_DEBOUNCE_MS after the last call.
     */
    private scheduleSave;
    private load;
}
export {};
//# sourceMappingURL=scheduler.d.ts.map