/**
 * Unified Scheduler Service
 *
 * Consolidates cron, interval, and idle-based scheduling into a single
 * persistent service with agent auto-start capabilities.
 *
 * Features:
 * - Cron schedules: standard 5-field expressions
 * - Interval schedules: fixed-interval triggers
 * - Idle schedules: trigger when agent has been idle for N minutes
 * - Persistent storage in ~/.crewly/unified-schedules.json
 * - Auto-start agents that are offline when triggered
 * - Auto-pause after maxConsecutiveTriggers without agent response
 * - Manual trigger, pause, and resume
 *
 * Runs a 60-second evaluation loop that checks all active schedules
 * and triggers those that are due.
 *
 * @module services/workflow/unified-scheduler.service
 */
import { EventEmitter } from 'events';
import type { UnifiedSchedule, CreateScheduleRequest, UpdateScheduleRequest, SchedulerHealth } from './unified-scheduler.types.js';
/**
 * UnifiedSchedulerService manages all schedule types (cron, interval, idle)
 * in a single persistent store with a 60-second evaluation loop.
 *
 * Uses sendMessageToAgent (via callback) for message delivery and
 * supports auto-starting offline agents.
 */
export declare class UnifiedSchedulerService extends EventEmitter {
    private static instance;
    private readonly logger;
    private readonly storagePath;
    /** All schedules indexed by ID */
    private schedules;
    /** Evaluation loop timer */
    private evalTimer;
    /** Whether the eval loop is running */
    private running;
    /** Timestamp of last evaluation cycle */
    private lastEvaluatedAt;
    /** Total triggers since service start */
    private totalTriggersSinceStart;
    /**
     * Callback for sending messages to agents.
     * Set via setMessageCallback() — decouples from AgentRegistrationService.
     */
    private messageCallback;
    /**
     * Callback for checking if an agent is online.
     * Set via setAgentStatusCallback().
     */
    private agentStatusCallback;
    /**
     * Callback for starting an offline agent.
     * Set via setAgentStartCallback().
     */
    private agentStartCallback;
    /**
     * Callback for checking agent idle status.
     * Set via setIdleCheckCallback().
     */
    private idleCheckCallback;
    private constructor();
    /**
     * Get the singleton instance.
     *
     * @param crewlyHome - Override ~/.crewly path (for testing)
     * @returns Service instance
     */
    static getInstance(crewlyHome?: string): UnifiedSchedulerService;
    /**
     * Reset the singleton (for testing).
     */
    static resetInstance(): void;
    /**
     * Set the callback for sending messages to agents.
     *
     * @param callback - Function that sends a message to an agent by session name
     */
    setMessageCallback(callback: (sessionName: string, message: string) => Promise<{
        success: boolean;
    }>): void;
    /**
     * Set the callback for checking if an agent is online.
     *
     * @param callback - Returns true if the agent is currently active
     */
    setAgentStatusCallback(callback: (sessionName: string) => Promise<boolean>): void;
    /**
     * Set the callback for starting an offline agent.
     *
     * @param callback - Starts the agent and returns true if successful
     */
    setAgentStartCallback(callback: (sessionName: string) => Promise<boolean>): void;
    /**
     * Set the callback for checking agent idle status.
     *
     * @param callback - Returns idle status and idle duration
     */
    setIdleCheckCallback(callback: (sessionName: string) => Promise<{
        idle: boolean;
        idleMinutes: number;
    }>): void;
    /**
     * Start the scheduler evaluation loop.
     *
     * Loads persisted schedules from disk and begins the 60-second
     * evaluation cycle.
     */
    start(): void;
    /**
     * Stop the scheduler evaluation loop.
     */
    stop(): void;
    /**
     * Create a new schedule.
     *
     * @param request - Schedule creation request
     * @returns Created schedule
     * @throws Error if validation fails
     */
    create(request: CreateScheduleRequest): UnifiedSchedule;
    /**
     * Get a schedule by ID.
     *
     * @param id - Schedule ID
     * @returns Schedule or null
     */
    get(id: string): UnifiedSchedule | null;
    /**
     * List all schedules, optionally filtered by target session.
     *
     * @param target - Optional session name filter
     * @returns Array of schedules
     */
    list(target?: string): UnifiedSchedule[];
    /**
     * Update an existing schedule.
     *
     * @param id - Schedule ID
     * @param updates - Partial update fields
     * @returns Updated schedule or null if not found
     */
    update(id: string, updates: UpdateScheduleRequest): UnifiedSchedule | null;
    /**
     * Delete a schedule.
     *
     * @param id - Schedule ID
     * @returns True if deleted
     */
    delete(id: string): boolean;
    /**
     * Pause a schedule.
     *
     * @param id - Schedule ID
     * @returns Updated schedule or null
     */
    pause(id: string): UnifiedSchedule | null;
    /**
     * Resume a paused schedule.
     *
     * @param id - Schedule ID
     * @returns Updated schedule or null
     */
    resume(id: string): UnifiedSchedule | null;
    /**
     * Manually trigger a schedule now, regardless of timing.
     *
     * @param id - Schedule ID
     * @returns True if triggered successfully
     */
    triggerNow(id: string): Promise<boolean>;
    /**
     * Get scheduler health and statistics.
     *
     * @returns Health stats
     */
    getHealth(): SchedulerHealth;
    /**
     * Evaluate all active schedules and trigger those that are due.
     *
     * Called every 60 seconds by the eval timer. Checks each schedule
     * type against its timing criteria and executes if due.
     */
    evaluate(): Promise<void>;
    /**
     * Check if a schedule is due for triggering.
     *
     * @param schedule - Schedule to check
     * @returns True if the schedule should trigger now
     */
    private isScheduleDue;
    /**
     * Check if a cron schedule is due (within the current evaluation window).
     *
     * Compares the cron expression against the current time.
     * Uses minute-level granularity (matches eval loop frequency).
     *
     * @param schedule - Cron schedule to check
     * @returns True if the current minute matches the cron expression
     */
    private isCronDue;
    /**
     * Execute a schedule: send message to agent, handle auto-start,
     * track consecutive triggers, and auto-pause if limit reached.
     *
     * @param schedule - Schedule to execute
     * @returns True if message was delivered successfully
     */
    private executeSchedule;
    /**
     * Reset the consecutive trigger counter for a target agent.
     *
     * Called when an agent shows activity (e.g., sends a message, completes a task).
     * This prevents auto-pausing schedules for responsive agents.
     *
     * @param target - Agent session name
     */
    resetConsecutiveTriggers(target: string): void;
    /**
     * Save all schedules to disk.
     */
    private persist;
    /**
     * Load schedules from disk.
     */
    private loadFromDisk;
    /**
     * Get count of active schedules.
     */
    private getActiveCount;
}
//# sourceMappingURL=unified-scheduler.service.d.ts.map