/**
 * Product Planner — Interactive multi-turn planning + persistent leader management.
 *
 * Architecture (aligned with CrewAI hierarchical + LangGraph durable execution):
 *
 * Phase 1 — PLANNING (multi-turn dialogue):
 *   1. product.plan → spawn leader agent → leader engages user in multi-turn dialogue
 *   2. Leader asks clarifying questions, proposes module decomposition
 *   3. User responds via product.message → leader refines plan
 *   4. Leader outputs structured plan → client presents to user
 *
 * Phase 2 — CONFIRMATION:
 *   5. product.confirm → user confirms/modifies plan → transition to execution
 *
 * Phase 3 — EXECUTION (leader as persistent manager):
 *   6. Leader manages DAG: dispatches tasks, monitors, handles failures
 *   7. Leader can dynamically mutate DAG: add/retry/reassign tasks
 *   8. User can intervene via product.message at any time
 *   9. Each state transition is checkpointed for crash recovery
 *
 * Key mechanisms from reference projects:
 *   - CrewAI: hierarchical process (manager auto-delegates/verifies)
 *   - CrewAI: checkpoint serialization (mid-task state)
 *   - LangGraph: durable execution (persist after each node)
 */
import type { AgentProcessManager } from "../runtime/infra/agent-process.js";
import type { AcpDetector } from "../runtime/infra/acp-detector.js";
import type { AgentConfigStore } from "../runtime/infra/agent-config-store.js";
import type { ProductPlanParams, ProductPlan, ProductConfirmParams } from "../protocol/wire/acp-agent-management.js";
export type PlanningPhase = "planning" | "awaiting_confirmation" | "confirmed" | "executing" | "paused" | "completed" | "cancelled";
export interface PlanningMessage {
    role: "leader" | "user";
    content: string;
    timestamp: string;
}
export interface PlanningSession {
    productId: string;
    goal: string;
    cwd: string;
    leaderAgentId: string;
    leaderMemberId?: string;
    phase: PlanningPhase;
    plan?: ProductPlan;
    /** Multi-turn conversation history during planning. */
    dialogue: PlanningMessage[];
    budget?: {
        maxTotalTokens?: number;
        maxDuration?: number;
    };
    createdAt: string;
    /** Last checkpoint timestamp for durable execution. */
    lastCheckpoint?: string;
}
export interface PlannerCallbacks {
    log?: {
        info(msg: string): void;
        warn(msg: string): void;
    };
    /** Leader produced a structured plan — client presents to user. */
    onPlanReady?: (productId: string, plan: ProductPlan) => void;
    /** Planning failed. */
    onPlanFailed?: (productId: string, error: string) => void;
    /** Streaming text from leader during planning dialogue. */
    onPlanningDelta?: (productId: string, text: string) => void;
    /** Leader sent a message to user (multi-turn). */
    onLeaderMessage?: (productId: string, message: string) => void;
    /** Leader dynamically mutated the DAG during execution. */
    onDagMutated?: (productId: string, mutation: DagMutation) => void;
}
/** Describes a DAG mutation performed by the leader. */
export interface DagMutation {
    type: "add_task" | "remove_task" | "retry_task" | "reassign_task" | "update_prompt";
    taskId: string;
    details?: Record<string, unknown>;
}
export declare class ProductPlanner {
    private processManager;
    private acpDetector;
    private configStore;
    private callbacks;
    private sessions;
    constructor(processManager: AgentProcessManager, acpDetector: AcpDetector, configStore: AgentConfigStore | null, callbacks?: PlannerCallbacks);
    /**
     * Start an interactive planning session (Phase 1).
     * Spawns the leader agent and begins multi-turn dialogue.
     */
    plan(params: ProductPlanParams): Promise<{
        productId: string;
        plan: ProductPlan;
    }>;
    /**
     * Send a user message to the leader (works in planning and execution phases).
     * Returns the leader's response and optionally a finalized plan.
     */
    message(productId: string, content: string): Promise<{
        response: string;
        plan?: ProductPlan;
        mutations?: DagMutation[];
    }>;
    /**
     * Confirm the plan → transition to execution (Phase 2 → Phase 3).
     */
    confirm(params: ProductConfirmParams): Promise<{
        productId: string;
        ok: true;
    }>;
    /** Transition session to executing phase. Called after ProductOrchestrator.create(). */
    markExecuting(productId: string): void;
    /** Mark as completed. */
    markCompleted(productId: string): void;
    /** Get planning session by ID. */
    getSession(productId: string): PlanningSession | undefined;
    /** Cancel and kill leader process. */
    cancel(productId: string): Promise<void>;
    /** List active sessions. */
    listSessions(): PlanningSession[];
    /**
     * Ask leader to evaluate execution state and propose DAG mutations.
     * Called by ProductOrchestrator when tasks fail or progress stalls.
     */
    consultLeader(productId: string, context: {
        progress: {
            total: number;
            completed: number;
            running: number;
            failed: number;
        };
        failedTasks?: Array<{
            taskId: string;
            error: string;
        }>;
    }): Promise<DagMutation[]>;
    /**
     * Serialize session for checkpoint persistence (durable execution).
     */
    serializeSession(productId: string): PlanningSession | null;
    /**
     * Restore session from checkpoint (crash recovery).
     */
    restoreSession(data: PlanningSession): void;
    private handlePlanningMessage;
    private handleExecutionMessage;
    private sendToLeader;
    private tryParsePlan;
    private parseDagMutations;
}
