/** * Cycle detection for loop monitors. * * Tracks step execution history and detects when a specific cycle * of steps has been repeated a configured number of times (threshold). * * Example: * cycle: [ai_review, ai_fix], threshold: 3 * History: ai_review → ai_fix → ai_review → ai_fix → ai_review → ai_fix * ↑ * 3 cycles → trigger */ import type { LoopMonitorConfig } from '../../models/types.js'; /** Result of checking a single loop monitor */ export interface CycleCheckResult { /** Whether the threshold has been reached */ triggered: boolean; /** Current number of completed cycles */ cycleCount: number; /** The loop monitor config that was triggered (if triggered) */ monitor?: LoopMonitorConfig; } /** * Tracks step execution history and detects cyclic patterns * as defined by loop_monitors configuration. */ export declare class CycleDetector { /** Step execution history (names in order) */ private history; private monitors; constructor(monitors?: LoopMonitorConfig[]); /** * Record a step completion and check if any cycle threshold is reached. * * The detection logic works as follows: * 1. The step name is appended to the history * 2. For each monitor whose first step is the proposed next step, we check * if the cycle pattern has been completed by looking at the tail of the * history * 3. A cycle is "completed" when the last N entries in history match * the cycle pattern repeated `threshold` times * * @param stepName The name of the step that just completed * @param nextStep The natural transition proposed after the completed step * @returns CycleCheckResult indicating if any monitor was triggered */ recordAndCheck(stepName: string, nextStep: string): CycleCheckResult; /** * Check a single monitor against the current history. * * A cycle is detected when the last element of the history matches the * last element of the cycle, and looking backwards we can find exactly * `threshold` complete cycles. */ private checkMonitor; /** * Reset the history after a judge intervention. * This prevents the same cycle from immediately triggering again. */ reset(): void; /** * Get the current step history (for debugging/testing). */ getHistory(): readonly string[]; } //# sourceMappingURL=cycle-detector.d.ts.map