/** * Weavetab — sensors/operation_monitor.ts * Intelligent operation monitoring for detecting and resolving tool execution lag. * Detects when operations hang inside tool execution and provides adaptive bail-out. * Weavetab by fy2ne */ export interface OperationPhase { name: string; startTime: number; endTime?: number; duration?: number; completed: boolean; warning?: string; } export interface OperationDiagnostics { toolName: string; totalDuration: number; phases: OperationPhase[]; bottlenecks: string[]; health: "healthy" | "degraded" | "critical"; bailOutReason?: string; } declare class OperationMonitor { private activeOperations; private readonly PHASE_THRESHOLDS; private readonly BAIL_OUT_THRESHOLDS; private readonly TOTAL_OPERATION_TIMEOUT; /** * Start monitoring a new tool operation */ startOperation(operationId: string, toolName: string): void; /** * Record the start of a specific phase within an operation */ startPhase(operationId: string, phaseName: string): void; /** * Record the completion of a specific phase */ endPhase(operationId: string, phaseName: string, warning?: string): void; /** * End operation monitoring and return diagnostics */ endOperation(operationId: string): OperationDiagnostics | null; /** * Check if an operation should bail out with degraded results */ shouldBailOut(operationId: string): { shouldBail: boolean; reason?: string; }; /** * Get current operation status for diagnostics */ getOperationStatus(operationId: string): { toolName: string; duration: number; currentPhase: string; health: "healthy" | "degraded" | "critical"; } | null; /** * Periodic health check for active operations */ private checkOperationHealth; /** * Identify bottlenecks in operation phases */ private identifyBottlenecks; /** * Determine overall operation health */ private determineHealth; /** * Clear every active diagnostics timer. Registered on process exit events so * that a tool crashing before endOperation() can't leave an interval firing * every second and pinning the Node.js event loop. */ cleanupAll(): void; } export declare const operationMonitor: OperationMonitor; export {};