UNPKG

aiwg

Version:

Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo

130 lines 3.45 kB
/** * @file error-recovery.ts * @description Automated error recovery and resilience system * * Implements F-012/UC-012: Error Recovery * - Automatic error detection and classification * - Recovery strategy execution * - Retry logic with exponential backoff * - Circuit breaker pattern * - Graceful degradation * - Error reporting and logging * * @implements NFR-RECOV-001: Recovery time <30s for transient errors * @implements NFR-RECOV-002: 95% automatic recovery success rate * @implements NFR-RECOV-003: Zero data loss during recovery */ import { EventEmitter } from 'events'; export type ErrorSeverity = 'transient' | 'recoverable' | 'critical'; export type RecoveryStrategy = 'retry' | 'fallback' | 'circuit-breaker' | 'restart' | 'manual'; export interface RecoverableError { timestamp: Date; error: Error; severity: ErrorSeverity; context: Record<string, any>; stackTrace?: string; } export interface RecoveryAttempt { timestamp: Date; strategy: RecoveryStrategy; success: boolean; duration: number; error?: string; } export interface RecoveryResult { recovered: boolean; attempts: RecoveryAttempt[]; finalStrategy?: RecoveryStrategy; totalDuration: number; } export interface CircuitBreakerState { state: 'closed' | 'open' | 'half-open'; failures: number; lastFailureTime?: Date; nextAttemptTime?: Date; } export interface ErrorRecoveryConfig { maxRetries?: number; retryDelay?: number; exponentialBackoff?: boolean; circuitBreakerThreshold?: number; circuitBreakerTimeout?: number; fallbackEnabled?: boolean; } export declare class ErrorRecoverySystem extends EventEmitter { private config; private errorHistory; private circuitBreakers; constructor(config?: ErrorRecoveryConfig); /** * Attempt to recover from an error */ recover<T>(operation: () => Promise<T>, fallback?: () => Promise<T>, context?: Record<string, any>): Promise<T>; /** * Retry operation with exponential backoff */ private retryWithBackoff; /** * Calculate retry delay with exponential backoff */ private calculateDelay; /** * Sleep for specified duration */ private sleep; /** * Check if circuit breaker is open */ private isCircuitOpen; /** * Record successful operation */ private recordSuccess; /** * Record failed operation */ private recordFailure; /** * Open circuit breaker */ private openCircuit; /** * Set circuit breaker state */ private setCircuitState; /** * Get circuit breaker state */ getCircuitState(key: string): CircuitBreakerState | undefined; /** * Reset circuit breaker */ resetCircuit(key: string): void; /** * Classify error severity */ classifyError(error: Error): ErrorSeverity; /** * Log error with context */ private logError; /** * Get error history */ getErrorHistory(count?: number): RecoverableError[]; /** * Get error statistics */ getStatistics(): { totalErrors: number; transientErrors: number; recoverableErrors: number; criticalErrors: number; circuitBreakerTrips: number; }; /** * Clear error history */ clearHistory(): void; } //# sourceMappingURL=error-recovery.d.ts.map