import { AgentType } from '../types/index.js';
import type { EventBus } from '../core/event-bus.js';
import { TeamReconcilerService } from './team-reconciler.service.js';
interface StopSessionOptions {
    skipTeamRunReconcile?: boolean;
}
export declare class SessionManager {
    private readonly eventBus;
    private pipelines;
    private pendingSpawns;
    private cancelTokens;
    private snapshotFlushTimers;
    private snapshotFlushChains;
    private pendingSnapshotStatus;
    private readonly teamReconciler;
    private static readonly SNAPSHOT_DEBOUNCE_MS;
    constructor(eventBus: EventBus, teamReconciler?: TeamReconcilerService);
    findById(id: string): Promise<({
        workspace: {
            id: string;
            createdAt: Date;
            status: string;
            taskId: string;
            updatedAt: Date;
            branchName: string;
            worktreePath: string;
            workingDir: string;
            parentWorkspaceId: string | null;
            ownerMemberId: string | null;
            baseBranch: string | null;
            workspaceKind: string;
            commitMessage: string | null;
            previewTarget: string | null;
            hibernatedAt: Date | null;
        };
        processes: {
            exitCode: number | null;
            pid: number | null;
            id: string;
            createdAt: Date;
            sessionId: string;
            updatedAt: Date;
        }[];
    } & {
        agentType: string;
        id: string;
        createdAt: Date;
        status: string;
        updatedAt: Date;
        workspaceId: string;
        variant: string;
        providerId: string | null;
        prompt: string;
        purpose: string;
        logSnapshot: string | null;
        tokenUsage: string | null;
    }) | null>;
    create(workspaceId: string, agentType: AgentType, prompt: string, variant?: string, providerId?: string): Promise<{
        agentType: string;
        id: string;
        createdAt: Date;
        status: string;
        updatedAt: Date;
        workspaceId: string;
        variant: string;
        providerId: string | null;
        prompt: string;
        purpose: string;
        logSnapshot: string | null;
        tokenUsage: string | null;
    }>;
    start(id: string): Promise<({
        workspace: {
            task: {
                id: string;
                createdAt: Date;
                status: string;
                description: string | null;
                priority: number;
                updatedAt: Date;
                title: string;
                position: number;
                projectId: string;
                deletedAt: Date | null;
            };
        } & {
            id: string;
            createdAt: Date;
            status: string;
            taskId: string;
            updatedAt: Date;
            branchName: string;
            worktreePath: string;
            workingDir: string;
            parentWorkspaceId: string | null;
            ownerMemberId: string | null;
            baseBranch: string | null;
            workspaceKind: string;
            commitMessage: string | null;
            previewTarget: string | null;
            hibernatedAt: Date | null;
        };
    } & {
        agentType: string;
        id: string;
        createdAt: Date;
        status: string;
        updatedAt: Date;
        workspaceId: string;
        variant: string;
        providerId: string | null;
        prompt: string;
        purpose: string;
        logSnapshot: string | null;
        tokenUsage: string | null;
    }) | null>;
    startFollowUp(id: string, resumeFromSessionId: string): Promise<({
        workspace: {
            task: {
                id: string;
                createdAt: Date;
                status: string;
                description: string | null;
                priority: number;
                updatedAt: Date;
                title: string;
                position: number;
                projectId: string;
                deletedAt: Date | null;
            };
        } & {
            id: string;
            createdAt: Date;
            status: string;
            taskId: string;
            updatedAt: Date;
            branchName: string;
            worktreePath: string;
            workingDir: string;
            parentWorkspaceId: string | null;
            ownerMemberId: string | null;
            baseBranch: string | null;
            workspaceKind: string;
            commitMessage: string | null;
            previewTarget: string | null;
            hibernatedAt: Date | null;
        };
    } & {
        agentType: string;
        id: string;
        createdAt: Date;
        status: string;
        updatedAt: Date;
        workspaceId: string;
        variant: string;
        providerId: string | null;
        prompt: string;
        purpose: string;
        logSnapshot: string | null;
        tokenUsage: string | null;
    }) | null>;
    sendMessage(id: string, message: string, providerId?: string): Promise<({
        workspace: {
            task: {
                id: string;
                createdAt: Date;
                status: string;
                description: string | null;
                priority: number;
                updatedAt: Date;
                title: string;
                position: number;
                projectId: string;
                deletedAt: Date | null;
            };
        } & {
            id: string;
            createdAt: Date;
            status: string;
            taskId: string;
            updatedAt: Date;
            branchName: string;
            worktreePath: string;
            workingDir: string;
            parentWorkspaceId: string | null;
            ownerMemberId: string | null;
            baseBranch: string | null;
            workspaceKind: string;
            commitMessage: string | null;
            previewTarget: string | null;
            hibernatedAt: Date | null;
        };
    } & {
        agentType: string;
        id: string;
        createdAt: Date;
        status: string;
        updatedAt: Date;
        workspaceId: string;
        variant: string;
        providerId: string | null;
        prompt: string;
        purpose: string;
        logSnapshot: string | null;
        tokenUsage: string | null;
    }) | null>;
    stop(id: string, options?: StopSessionOptions): Promise<{
        agentType: string;
        id: string;
        createdAt: Date;
        status: string;
        updatedAt: Date;
        workspaceId: string;
        variant: string;
        providerId: string | null;
        prompt: string;
        purpose: string;
        logSnapshot: string | null;
        tokenUsage: string | null;
    } | null>;
    writeInput(sessionId: string, data: string): void;
    resize(sessionId: string, cols: number, rows: number): void;
    /**
     * Destroy all active pipelines. Called on graceful server shutdown.
     */
    destroyAll(): void;
    private resolveAgentSessionId;
    private attachPipeline;
    private registerSpawnedSessionIfTaskLive;
    private cancelSpawnedSession;
    private createParser;
    private injectAgentTowerMcpServiceEnv;
    private injectTeamRunInvocationEnv;
    /**
     * Agent 进程退出后自动提交未保存的变更。
     * 保证 worktree 始终干净的兜底机制，最终会被 squash merge 合并。
     * 参考: vibe-kanban crates/local-deployment/src/container.rs:496-505
     */
    private autoCommitChanges;
    private persistCompletedSnapshot;
    private scheduleSnapshotPersist;
    private flushSnapshotPersist;
    private extractTokenUsageFromSnapshot;
    /**
     * Session 完成后检查 Task 是否可以自动推进状态。
     *
     * 规则：当一个 Task 下所有 Workspace 的所有 CHAT Session 都处于终态
     * （COMPLETED / CANCELLED / FAILED）时，自动将 IN_PROGRESS 的 Task
     * 推进到 IN_REVIEW，提示用户进行代码审查。
     * 同时触发 commit message 的后台生成。
     */
    private checkTaskAutoAdvance;
    /**
     * 异步触发 commit message 生成（fire-and-forget）
     */
    private triggerCommitMessageGeneration;
    /**
     * Session 启动时自动更新 Task 状态。
     *
     * 规则：
     * 1. TODO → IN_PROGRESS：首次启动 session 时，任务开始进行
     * 2. IN_REVIEW/DONE → IN_PROGRESS：重新启动 session 时，任务回退到进行中
     * 注意：COMMIT_MSG session 启动不应触发状态变更。
     */
    private checkTaskAutoRevert;
    /**
     * Session 退出后的统一处理入口。
     * 根据 session purpose 走不同的后处理路径。
     * exitCode 非 0 时标记为 FAILED。
     */
    private handleSessionExit;
}
export {};
//# sourceMappingURL=session-manager.d.ts.map