/**
 * EscalationService — Periodic evaluation of MissionPolicy escalation rules.
 *
 * Periodically scans all active Missions, builds an EscalationContext from
 * current runtime data (cost, time elapsed, failure count), and evaluates
 * each Mission's escalationRules via PolicyEnforcementService. When a rule
 * triggers, the specified action is executed:
 *
 * - **notify**: Sends a notification to the escalation target (user/orchestrator/team_lead)
 * - **pause**: Pauses the Mission and its associated WorkItems
 * - **block**: Blocks further Mission execution until manual review
 *
 * Integration with TriggerEngine:
 * On startup, registers a cron-based Trigger that periodically invokes
 * the escalation evaluation loop. This leverages TriggerEngine's lifecycle
 * management (fire counting, idle tracking, persistence).
 *
 * @module services/v3/escalation.service
 */
import { PolicyEnforcementService, type EscalationResult } from '../policy/policy-enforcement.service.js';
import type { WorkItem } from '../../types/v2/work-item.types.js';
import type { Mission, EscalationContext, EscalationRule } from '../../types/v2/index.js';
/**
 * Result of a single Mission's escalation evaluation.
 */
export interface MissionEscalationResult {
    /** Mission ID */
    missionId: string;
    /** Mission objective (for logging) */
    objective: string;
    /** The evaluation result from PolicyEnforcementService */
    escalation: EscalationResult;
    /** Actions executed (if any) */
    actionsExecuted: string[];
}
/**
 * Summary of a full escalation evaluation cycle.
 */
export interface EscalationCycleSummary {
    /** Number of active missions evaluated */
    missionsEvaluated: number;
    /** Number of missions where escalation was triggered */
    escalationsTriggered: number;
    /** Detailed results per mission (only for triggered ones) */
    results: MissionEscalationResult[];
    /** ISO timestamp of the evaluation */
    evaluatedAt: string;
}
/**
 * Handler for escalation actions (notify, pause, block).
 * Consumers register handlers to integrate with their notification/control systems.
 */
export type EscalationActionHandler = (mission: Mission, rule: EscalationRule, action: 'notify' | 'pause' | 'block') => Promise<void>;
/**
 * EscalationService periodically evaluates MissionPolicy escalation rules
 * and executes the required actions when thresholds are exceeded.
 *
 * @example
 * ```typescript
 * const service = new EscalationService('/path/to/project');
 * service.setActionHandler(async (mission, rule, action) => {
 *   if (action === 'notify') await sendSlackNotification(mission, rule);
 *   if (action === 'pause') await pauseMission(mission.id);
 * });
 * await service.start();
 * ```
 */
export declare class EscalationService {
    private readonly logger;
    private readonly projectPath;
    private readonly missionsDir;
    private readonly policyService;
    private actionHandler;
    private triggerId;
    private started;
    /**
     * The wrapper function this service installed on the TriggerEngine via
     * `setActionHandler`. Kept so we can detect "was I already installed?"
     * on re-entry and avoid building a growing delegation chain. Each
     * restart that skipped `stop()` (crash, test teardown gaps) would
     * otherwise wrap the previous wrapper as its "originalHandler",
     * stacking closures forever.
     */
    private installedHandler;
    /**
     * Creates a new EscalationService.
     *
     * @param projectPath - Absolute path to the project root
     * @param policyService - Optional PolicyEnforcementService instance (for DI/testing)
     */
    constructor(projectPath: string, policyService?: PolicyEnforcementService);
    /**
     * Registers a handler for escalation actions.
     * The handler is called whenever an escalation rule triggers.
     *
     * @param handler - Callback for executing escalation actions
     */
    setActionHandler(handler: EscalationActionHandler): void;
    /**
     * Starts the escalation service by registering a periodic trigger
     * with the TriggerEngine.
     *
     * @param cronExpression - Cron expression for evaluation frequency (default: every 5 min)
     */
    start(cronExpression?: string): Promise<void>;
    /**
     * Stops the escalation service by cancelling its trigger.
     */
    stop(): Promise<void>;
    /**
     * Returns whether the service is currently running.
     */
    isStarted(): boolean;
    /**
     * Evaluates all active Missions' escalation rules against current context.
     * This is the main loop called periodically by the TriggerEngine.
     *
     * @returns Summary of the evaluation cycle
     */
    evaluate(): Promise<EscalationCycleSummary>;
    /**
     * Loads the task pool once per evaluation cycle. Extracted so `evaluate`
     * can bucket items by missionId before calling
     * {@link buildEscalationContext} for each mission.
     */
    private loadMissionWorkItems;
    /**
     * Builds an EscalationContext for a Mission by aggregating runtime data.
     *
     * Sources:
     * - Cost: sum of WorkItem costs linked to this mission
     * - Time: hours elapsed since mission creation
     * - Failures: count of failed WorkItems linked to this mission
     *
     * @param mission - The Mission to build context for
     * @param missionItems - Pre-filtered WorkItems belonging to the mission.
     *        Pass an empty array when the mission has no items or the pool
     *        could not be loaded — the function does not re-fetch.
     * @returns Populated EscalationContext
     */
    buildEscalationContext(mission: Mission, missionItems: WorkItem[]): EscalationContext;
    /**
     * Executes the required actions from an escalation result.
     *
     * Action severity order: block > pause > notify.
     * Each triggered rule's action is executed via the registered handler.
     *
     * @param mission - The Mission being escalated
     * @param escalation - The evaluation result with triggered rules
     * @returns List of action descriptions that were executed
     */
    private executeEscalationActions;
    /**
     * Pauses all active WorkItems belonging to a Mission.
     * Sets queued/running items to 'blocked' status.
     *
     * @param missionId - The Mission ID whose WorkItems should be paused
     */
    private pauseMissionWorkItems;
    /**
     * Loads all active Missions from disk.
     *
     * @returns Array of active Mission objects
     */
    loadActiveMissions(): Promise<Mission[]>;
}
//# sourceMappingURL=escalation.service.d.ts.map