/** * Task Queue Manager - Multi-task queue system for Free Tier * @requirement FREE-TIER-001 - Task Queue Management * * Cursor Integration: This file defines data structures that Cursor will read * from tasks.json to understand the task queue state when reading STATUS.txt */ import type { WorkflowState } from '@shadel/workflow-core'; /** * Workflow progress structure (matches existing system) * Cursor reads this to understand task workflow state */ export interface WorkflowProgress { currentState: WorkflowState; stateEnteredAt: string; stateHistory: Array<{ state: WorkflowState; enteredAt: string; }>; } /** * Task status in queue system * QUEUED: Waiting to be activated * ACTIVE: Currently being worked on (only 1 can be ACTIVE) * DONE: Completed * ARCHIVED: Auto-archived after 30 days */ export type TaskStatus = 'QUEUED' | 'ACTIVE' | 'DONE' | 'ARCHIVED'; /** * Task priority levels * CRITICAL: Production bugs, security issues * HIGH: Important features, deadlines * MEDIUM: Standard work (default) * LOW: Refactoring, cleanup */ export type Priority = 'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW'; /** * Review checklist (for REVIEWING state) */ export interface ReviewChecklist { items: Array<{ id: string; description: string; category: 'automated' | 'manual'; completed: boolean; completedAt?: string; notes?: string; }>; completedAt?: string; } /** * Task in queue system * Cursor reads this from tasks.json to understand task context */ export interface Task { id: string; goal: string; status: TaskStatus; priority?: Priority; tags?: string[]; createdAt: string; activatedAt?: string; completedAt?: string; archivedAt?: string; estimatedTime?: string; actualTime?: number; workflow?: WorkflowProgress; reviewChecklist?: ReviewChecklist; } /** * Task queue structure * Stored in .ai-context/tasks.json * Cursor reads this file to understand full project context */ export interface TaskQueue { tasks: Task[]; activeTaskId: string | null; metadata: { totalTasks: number; queuedCount: number; activeCount: number; completedCount: number; archivedCount: number; lastUpdated: string; }; } /** * Type guard to check if value is valid TaskStatus */ export declare function isTaskStatus(value: string): value is TaskStatus; /** * Type guard to check if value is valid Priority */ export declare function isPriority(value: string): value is Priority; /** * Validate Task structure * Used to ensure data integrity for Cursor reading */ export declare function validateTask(task: any): task is Task; /** * Validate TaskQueue structure * Used to ensure data integrity for Cursor reading */ export declare function validateTaskQueue(queue: any): queue is TaskQueue; /** * TaskQueueManager - Manages multi-task queue system * Cursor Integration: Updates tasks.json which Cursor reads for project context */ export declare class TaskQueueManager { private queueFile; private contextDir; private lockOptions; constructor(contextDir?: string); /** * File locking wrapper for concurrent access safety * Cursor Integration: Ensures data integrity when multiple processes access tasks.json */ private withLock; /** * Load queue from file * Cursor Integration: Reads tasks.json that Cursor uses for context */ private loadQueue; /** * Save queue to file * Cursor Integration: Writes tasks.json that Cursor reads for project context */ private saveQueue; /** * Create empty queue structure */ private createEmptyQueue; /** * Validate queue structure * Cursor Integration: Ensures tasks.json structure is valid for Cursor reading */ private validateQueue; /** * Update metadata * Cursor Integration: Updates metadata that Cursor reads for statistics */ private updateMetadata; /** * Create new task * - If no active task → Mark as ACTIVE * - If active task exists → Mark as QUEUED * Cursor Integration: Creates task that Cursor reads from tasks.json */ createTask(goal: string, options?: { priority?: Priority; tags?: string[]; estimatedTime?: string; }): Promise; /** * Activate a queued task * - Only 1 task can be ACTIVE at a time * - Previous active task → QUEUED (preserve state) * Cursor Integration: Updates active task that Cursor reads from tasks.json */ activateTask(taskId: string): Promise; /** * Complete active task * - Mark as DONE * - Calculate actual time * - Auto-activate next QUEUED task (by priority) * Cursor Integration: Updates task status that Cursor reads from tasks.json */ completeTask(taskId: string, options?: { autoActivateNext?: boolean; }): Promise<{ completed: Task; nextActive?: Task; }>; /** * Get next queued task by priority * Cursor Integration: Used to determine which task Cursor should work on next */ private getNextQueuedTask; /** * Auto-archive DONE tasks older than 30 days * Cursor Integration: Keeps tasks.json manageable for Cursor reading */ archiveOldTasks(): Promise; /** * Get active task * Cursor Integration: Returns task that Cursor should focus on */ getActiveTask(): Promise; /** * List tasks (with filtering) * Cursor Integration: Returns tasks that Cursor can see in queue overview */ listTasks(options?: { status?: TaskStatus[]; priority?: Priority[]; includeArchived?: boolean; limit?: number; }): Promise; }