/**
 * Escalation Router Service
 *
 * Routes escalations to the appropriate target:
 * - target === 'team_lead' → Send message to TL agent via MessageQueue
 * - target === 'human' → Send Slack notification to user + pause task + create pending record
 *
 * Also handles MissionPolicy escalation rules (cost_exceeded, failure_count, etc.)
 * by routing `escalateTo: 'user'` to human and `escalateTo: 'orchestrator'` to agent.
 *
 * Pending human escalations are stored in `.crewly/escalations/` and resolved
 * via POST /api/escalations/:id/resolve.
 *
 * @module services/v3/escalation-router.service
 */
import type { AlignmentRequest } from '../../types/v2/work-item.types.js';
import type { EscalationRule, Mission } from '../../types/v2/mission.types.js';
/** Status of a pending human escalation. */
export type EscalationStatus = 'pending' | 'resolved' | 'expired';
/**
 * Minimal WorkItem shape `escalateFailedWorkItem` needs. Defined locally
 * (rather than importing the full WorkItem type) to keep this service's
 * dependency surface narrow — escalation only reads, never writes,
 * fields it doesn't recognise.
 */
export interface WorkItemForEscalation {
    id: string;
    title: string;
    type: string;
    target?: string | null;
    retryCount: number;
    maxRetries: number;
    error?: string | null;
    requestId?: string | null;
    missionId?: string | null;
    parentWorkItemId?: string | null;
    priority?: string | null;
}
/** A persisted escalation record awaiting human resolution. */
export interface PendingEscalation {
    id: string;
    status: EscalationStatus;
    /** What triggered this escalation */
    source: 'alignment_request' | 'policy_rule' | 'tl_verification' | 'manual' | 'workitem_failed';
    /** Who needs to resolve it */
    target: 'human' | 'team_lead' | 'orchestrator';
    /** The escalation content */
    summary: string;
    details: Record<string, unknown>;
    /** Related IDs */
    workItemId?: string;
    missionId?: string;
    taskId?: string;
    /** Who raised it */
    raisedBy: string;
    raisedAt: string;
    /** Resolution (filled when resolved) */
    resolvedAt?: string;
    resolvedBy?: string;
    resolution?: string;
}
export declare class EscalationRouterService {
    private static instance;
    private readonly logger;
    private readonly escalationsDir;
    private constructor();
    static getInstance(projectPath?: string): EscalationRouterService;
    static resetInstance(): void;
    /**
     * Route a worker's AlignmentRequest to the correct target.
     *
     * @param request - The structured alignment request from the worker
     * @param workItemId - The WorkItem being escalated
     * @param workerSession - Worker's session name
     * @returns The escalation ID if routed to human, null if handled by agent
     */
    routeAlignmentRequest(request: AlignmentRequest, workItemId: string, workerSession: string): Promise<string | null>;
    /**
     * Route a MissionPolicy escalation rule trigger.
     *
     * @param mission - The Mission that triggered the rule
     * @param rule - The escalation rule that fired
     * @param context - Current context values (cost, time, failures)
     */
    routePolicyEscalation(mission: Mission, rule: EscalationRule, context: Record<string, number>): Promise<string | null>;
    /**
     * Resolve a pending human escalation.
     *
     * @param escalationId - The escalation to resolve
     * @param resolution - What the human decided
     * @param resolvedBy - Who resolved it (user ID or name)
     * @returns The updated escalation, or null if not found
     */
    resolve(escalationId: string, resolution: string, resolvedBy: string): Promise<PendingEscalation | null>;
    /**
     * Escalate a WorkItem that exhausted its retry budget to the
     * orchestrator. The orchestrator receives a structured message via
     * the same MessageQueue used by `target='team_lead'` escalations,
     * decides whether to (a) surface to the user, (b) replan, (c) hand
     * off to a different agent. Also persists a `PendingEscalation`
     * record for the dashboard / API.
     *
     * Called from `V3DataService.onTaskFailed` once `retryCount >=
     * maxRetries`. Best-effort — exceptions are caught and logged so a
     * messaging blip doesn't strand the upstream failure handler.
     *
     * @param wi      - The failed WorkItem (post-`failItem`, with retryCount
     *                  and maxRetries reflecting the exhausted budget)
     * @param reason  - Final failure reason (same string written to wi.error)
     * @returns The persisted escalation id, or null on persistence failure
     */
    escalateFailedWorkItem(wi: WorkItemForEscalation, reason: string): Promise<string | null>;
    /**
     * List all pending escalations.
     */
    listPending(): Promise<PendingEscalation[]>;
    private createPendingEscalation;
    private saveEscalation;
    private loadEscalation;
    /**
     * Notify human via the same channel the original request came from.
     * Falls back to Slack → Chat UI if source channel can't be determined.
     */
    private notifyHuman;
    /**
     * Resolve the source channel for an escalation by tracing back to the
     * original Request/ChatMessage that started the work.
     */
    private resolveSourceChannel;
    /**
     * Notify TL agent via message queue (for team_lead-targeted escalations).
     */
    private notifyAgent;
    private pauseWorkItem;
    private resumeWorkItem;
}
//# sourceMappingURL=escalation-router.service.d.ts.map