/** * Enhanced Execution Journal for tracking workflow executions * Implements ring buffer with size limits and JSON export */ import { type ExecutionStateZod } from '@orchestr8/schema'; import type { BoundedEventBus, OrchestrationEvent } from './event-bus.js'; /** * Journal entry with execution context */ export interface EnhancedJournalEntry { timestamp: number; executionId?: string; workflowId?: string; stepId?: string; type: string; data: OrchestrationEvent; metadata?: Record; } /** * Journal export format */ export interface JournalExport { executionId: string; workflowId?: string; startTime?: number; endTime?: number; duration?: number; entries: EnhancedJournalEntry[]; summary: { totalEvents: number; stepCount: number; retryCount: number; errorCount: number; status?: 'running' | 'completed' | 'failed' | 'cancelled'; }; } /** * Enhanced Execution Journal with multi-execution support and size limits */ export declare class EnhancedExecutionJournal { private readonly journalsByExecution; private readonly maxEntriesPerExecution; private readonly maxTotalSizeBytes; private readonly maxFieldSizeBytes; private readonly eventBus?; private currentSizeBytes; private isDisposed; private pendingEntries; private isProcessingQueue; private processingPromise; private readonly boundRecordEvent; private readonly subscribedEventTypes; /** * Validate event and determine how to proceed */ private validateEvent; /** * Validate journal entry and determine how to proceed */ private validateJournalEntry; /** * Handle validation results consistently */ private handleValidationResult; /** * Determine if we should continue processing despite validation errors */ private shouldContinueOnValidationError; constructor(options?: { eventBus?: BoundedEventBus; maxEntriesPerExecution?: number; maxTotalSizeBytes?: number; maxFieldSizeBytes?: number; }); /** * Subscribe to all relevant event types */ private subscribeToEvents; /** * Record an event to the journal (automatic recording from event bus) * Uses unified error handling for consistent behavior */ private recordEvent; /** * Process pending entries in queue with ordered processing */ private processPendingEntries; /** * Manually record an event (for testing or direct usage) * Uses unified error handling for consistent behavior */ recordManualEvent(event: OrchestrationEvent): void; /** * Add an entry to the journal for a specific execution * Uses unified error handling for consistent validation behavior */ addEntry(executionId: string, entry: EnhancedJournalEntry): void; /** * Evict oldest executions to make space */ private evictOldestExecutions; /** * Calculate size of an entry in bytes */ private calculateSize; /** * Truncate event data to respect field size limits */ private truncateEventData; /** * Extract execution ID from event */ private extractExecutionId; /** * Extract workflow ID from event */ private extractWorkflowId; /** * Extract step ID from event */ private extractStepId; /** * Get journal entries for a specific execution */ getEntriesByExecution(executionId: string): ReadonlyArray; /** * Export journal for a specific execution as JSON */ exportExecution(executionId: string): string; /** * Export all journals as JSON */ exportAll(): string; /** * Create export data for an execution */ private createExportData; /** * Create execution state data aligned with JSON execution model patterns */ createExecutionState(executionId: string): { executionId: string; workflowId?: string; status: 'pending' | 'validating' | 'running' | 'completed' | 'failed' | 'cancelled'; startTime?: string; endTime?: string; duration?: number; completedSteps: string[]; failedSteps: string[]; skippedSteps: string[]; cancelledSteps: string[]; stepResults: Record; variables: Record; errors?: unknown[]; metadata?: Record; } | null; /** * Calculate total size of journal entries */ private calculateJournalSize; /** * Validate consistency between journal data and execution state * Uses the ExecutionConsistencyValidator for comprehensive validation */ validateConsistency(executionState: Partial & { executionId: string; completedSteps: string[]; failedSteps: string[]; skippedSteps: string[]; cancelledSteps: string[]; stepResults: Record; variables: Record; }): Promise<{ isConsistent: boolean; errors: string[]; warnings: string[]; details: { journalEntryCount: number; executionStateValid: boolean; timestampConsistency: boolean; stepProgressConsistency: boolean; }; }>; /** * Get all execution IDs */ getExecutionIds(): string[]; /** * Clear journal for a specific execution */ clearExecution(executionId: string): void; /** * Clear all journals */ clearAll(): void; /** * Get current size in bytes */ getCurrentSize(): number; /** * Get number of executions being tracked */ getExecutionCount(): number; /** * Unsubscribe from all events and clear journals */ dispose(): Promise; /** * Unsubscribe from all event types */ private unsubscribeFromEvents; } /** * Global journal instance management */ export declare class JournalManager { private static instance?; /** * Get or create the global journal instance */ static getGlobalJournal(eventBus?: BoundedEventBus): EnhancedExecutionJournal; /** * Reset the global journal instance */ static resetGlobalJournal(): void; } //# sourceMappingURL=enhanced-execution-journal.d.ts.map