import { EventEmitter } from 'events';
import { InProgressTask, InProgressTaskStatus, TaskTrackingData, TaskFileInfo } from '../../types/task-tracking.types.js';
import type { OrgRole } from '../ai/prompt-modules/prompt-module.interface.js';
export declare class TaskTrackingService extends EventEmitter {
    private readonly taskTrackingPath;
    private readonly logger;
    private autoSyncInterval?;
    constructor();
    /**
     * Start periodic file system sync for all projects (#137).
     * Cleans up stale task tracking entries whose files have been moved or deleted.
     *
     * @param intervalMs - Sync interval in milliseconds (default: 30 minutes)
     */
    startAutoSync(intervalMs?: number): void;
    /**
     * Stop periodic file system sync.
     */
    stopAutoSync(): void;
    /**
     * Run auto-sync: iterate all tracked tasks and sync with file system.
     * Groups tasks by projectId and calls syncTasksWithFileSystem for each.
     */
    private runAutoSync;
    loadTaskData(): Promise<TaskTrackingData>;
    saveTaskData(data: TaskTrackingData): Promise<void>;
    assignTask(projectId: string, teamId: string, taskFilePath: string, taskName: string, targetRole: string, teamMemberId: string, sessionName: string): Promise<InProgressTask>;
    updateTaskStatus(taskId: string, status: InProgressTask['status'], blockReason?: string, requestorOrgRole?: OrgRole): Promise<void>;
    /**
     * Emit task workflow events that drive the action trigger chain.
     * Only emits for transitions that require a different actor to wake up.
     *
     * @param task - The updated task
     * @param fromStatus - Previous status
     * @param toStatus - New status
     * @param data - Current task tracking data (for team:all_tasks_done check)
     */
    private emitTaskWorkflowEvent;
    /**
     * Accept a task — transitions from 'assigned' to 'accepted'.
     * Records the agent's structured understanding of the task.
     *
     * @param taskId - Task ID to accept
     * @param sessionName - Session name of the accepting agent (must match assignee)
     * @param understanding - Agent's structured understanding of the task scope
     * @returns The updated task
     * @throws If task not found, not in 'assigned' status, or session doesn't match
     */
    acceptTask(taskId: string, sessionName: string, understanding: string): Promise<InProgressTask>;
    /**
     * Request clarification on a task — transitions to 'needs_clarification'.
     * Signals that the agent needs more info before starting work.
     *
     * @param taskId - Task ID to request clarification for
     * @param sessionName - Session name of the requesting agent (must match assignee)
     * @param question - What the agent needs clarified
     * @returns The updated task
     * @throws If task not found, not in valid status, or session doesn't match
     */
    requestClarification(taskId: string, sessionName: string, question: string): Promise<InProgressTask>;
    /**
     * Save working notes for a task — persists agent's current working state
     * across session restarts. Not long-term memory; cleared on task completion.
     *
     * @param taskId - Task ID
     * @param sessionName - Session name (must match assignee)
     * @param notes - Working notes content
     * @throws If task not found or session doesn't match assignee
     */
    updateWorkingNotes(taskId: string, sessionName: string, notes: string): Promise<void>;
    /**
     * Validate that a status transition is allowed based on the Task State Ownership Matrix.
     * Enforces who can write which status and which transitions are legal.
     *
     * @param currentStatus - Current task status
     * @param newStatus - Requested new status
     * @param requestorOrgRole - Organizational role of the requestor
     * @returns Validation result with optional reason for rejection
     */
    validateStatusTransition(currentStatus: InProgressTaskStatus, newStatus: InProgressTaskStatus, requestorOrgRole: OrgRole): {
        valid: boolean;
        reason?: string;
    };
    removeTask(taskId: string): Promise<void>;
    addTaskToQueue(taskInfo: {
        projectId: string;
        teamId: string;
        taskFilePath: string;
        taskName: string;
        targetRole: string;
        priority: 'low' | 'medium' | 'high';
        createdAt: string;
    }): Promise<InProgressTask>;
    getTasksForProject(projectId: string): Promise<InProgressTask[]>;
    getTasksForTeamMember(teamMemberId: string): Promise<InProgressTask[]>;
    getAllInProgressTasks(): Promise<InProgressTask[]>;
    syncTasksWithFileSystem(projectPath: string, projectId: string): Promise<void>;
    getOpenTasks(projectPath: string): Promise<TaskFileInfo[]>;
    /**
     * Store monitoring IDs (schedules and subscriptions) for a task so they can be
     * automatically cleaned up when the task completes.
     *
     * @param taskId - The task ID to associate monitoring with
     * @param scheduleIds - Array of schedule check IDs to link
     * @param subscriptionIds - Array of event subscription IDs to link
     */
    addMonitoringIds(taskId: string, scheduleIds: string[], subscriptionIds: string[]): Promise<void>;
    /**
     * Find all tasks assigned to a specific agent session.
     *
     * @param sessionName - The agent session name
     * @returns Array of tasks assigned to the session
     */
    getTasksBySessionName(sessionName: string): Promise<InProgressTask[]>;
    /**
     * Collect all monitoring IDs (schedules and subscriptions) for tasks assigned
     * to a specific agent session. Used for auto-cleanup when tasks complete.
     *
     * @param sessionName - The agent session name
     * @returns Object with arrays of scheduleIds and subscriptionIds
     */
    getMonitoringIdsForSession(sessionName: string): Promise<{
        scheduleIds: string[];
        subscriptionIds: string[];
    }>;
    /**
     * Detect orphan tasks: tasks stuck in in_progress/assigned/active with no
     * corresponding active agent. Returns the list without modifying state.
     *
     * @param getTeamStatus - Function returning current team configurations
     * @param staleThresholdMs - Age threshold in ms to consider a task stale (default: 24 hours)
     * @returns Array of orphan tasks with staleness info
     */
    detectOrphanTasks(getTeamStatus: () => Promise<any[]>, staleThresholdMs?: number): Promise<Array<InProgressTask & {
        staleSinceMs: number;
    }>>;
    /**
     * Bulk cleanup orphan tasks by marking them as cancelled and optionally
     * moving their files back to the open folder.
     *
     * @param taskIds - Array of task IDs to clean up
     * @param action - 'cancel' marks tasks as cancelled, 'reopen' moves them back to open
     * @returns Cleanup report with counts
     */
    cleanupOrphanTasks(taskIds: string[], action?: 'cancel' | 'reopen'): Promise<{
        cleaned: number;
        errors: string[];
    }>;
    private extractTaskNameFromFile;
    /**
     * Recovers abandoned in-progress tasks by checking agent status and moving inactive tasks back to open
     * @param getTeamStatus Function to get current team status from API
     * @returns Recovery report with actions taken
     */
    recoverAbandonedTasks(getTeamStatus: () => Promise<any[]>): Promise<{
        totalInProgress: number;
        recovered: number;
        skipped: number;
        errors: string[];
        recoveredTasks: string[];
    }>;
    /**
     * Moves a task back to the open folder and cleans assignment metadata
     */
    private moveTaskBackToOpen;
    /**
     * Removes assignment metadata sections from task content
     */
    private cleanAssignmentMetadata;
}
//# sourceMappingURL=task-tracking.service.d.ts.map