/** * Task File Sync - Centralized file sync operations * @requirement REQ-V2-003 - Task file synchronization * * This class is the ONLY way to write to current-task.json * All file writes must go through this class to ensure consistency. */ import type { WorkflowState } from '@shadel/workflow-core'; import type { Task as QueueTask, ReviewChecklist } from './task-queue.js'; /** * Task data in current-task.json file */ import type { StateChecklist } from './state-checklist-service.js'; export interface TaskFileData { taskId: string; originalGoal: string; status: 'in_progress' | 'completed'; startedAt: string; completedAt?: string; workflow: { currentState: WorkflowState; stateEnteredAt: string; stateHistory: Array<{ state: WorkflowState; enteredAt: string; }>; }; requirements?: string[]; reviewChecklist?: ReviewChecklist; stateChecklists?: { [state in WorkflowState]?: StateChecklist; }; } /** * Options for sync operations */ export interface SyncOptions { preserveFields?: string[]; skipValidation?: boolean; backup?: boolean; } /** * Task File Sync - Centralized file sync operations * * Responsibilities: * - Sync queue data to file (one-way: queue → file) * - Atomic writes to prevent corruption * - Manual edit detection (content-based) * - Backup and rollback support */ export declare class TaskFileSync { private taskFile; private contextDir; private fileLock; constructor(contextDir?: string); /** * Sync file from queue (one-way: queue → file) * This is the ONLY way to write to current-task.json * * @param queueTask - Task from queue system * @param options - Sync options */ syncFromQueue(queueTask: QueueTask, options?: SyncOptions): Promise; /** * Build file data from queue task * * @param queueTask - Task from queue system * @param options - Sync options */ private buildFileData; /** * Preserve existing value or sync from queue */ private preserveOrSync; /** * Load existing file data * Handles old format files (with `goal` field) by converting to new format (`originalGoal`) */ private loadExistingFile; /** * Atomic write using temp file + rename * * This ensures file writes are atomic and prevent corruption */ private atomicWrite; /** * Verify sync consistency */ private verifySync; /** * Detect manual edit using content hash * * Uses content-based hash comparison instead of timestamp * to avoid false positives/negatives from file system timing. */ /** * Detect if file was manually edited * @param queueTask - Task from queue to compare * @param fileData - Optional file data to avoid re-reading (performance optimization) */ detectManualEdit(queueTask: QueueTask, fileData?: TaskFileData): Promise; /** * Calculate content hash for comparison * * Uses stable hash (excludes timestamps, etc.) to compare * only meaningful content differences. */ private calculateHash; /** * Create backup of current file */ backupFile(): Promise; /** * Check if backup exists */ private hasBackup; /** * Rollback from backup */ rollbackFromBackup(): Promise; /** * Cleanup old backups (keep only last 5) */ private cleanupOldBackups; }