/** * Problem: * Upstream `agy_acp_server` does not detect repetitive tool calling loops or autoregressive attractor cycles. * When a model degenerates into repeating the same tool call or cycling through the same set of file slices, * raw agy blindly executes tool calls indefinitely, burning thousands of tokens and freezing editor sessions. * Furthermore, blindly halting every repeated tool breaks legitimate user polling (e.g. polling a port or waiting for builds). * * Solution: * Tracks canonicalized tool call signatures per prompt turn using suffix cycle matching. * Recognizes user polling intent (e.g. "until", "poll", "retry", "wait for", "N times") to allow legitimate polling. * When an unintentional runaway loop is detected, interrupts the repetitive execution and sends automated steering * ("You have repeatedly executed X, is that expected?") directly to the upstream model so it self-corrects without * ending the turn or polluting the user's chat. */ import { type AcpFix, type AcpStreamMessage } from "../../core/types.js"; export declare const IGNORED_METADATA_KEYS: Set; export declare const READ_ONLY_TOOLS: Set; export declare const POLLING_INTENT_PATTERN: RegExp; export declare function extractPromptText(msg: AcpStreamMessage): string; export declare function hasPollingIntent(promptText: string): boolean; export declare function extractRequestedIterations(promptText: string): number | undefined; export interface RepetitiveToolLoopOptions { maxPeriod?: number; readOnlySingleThreshold?: number; mutatingSingleThreshold?: number; pollingSingleThreshold?: number; cycleThreshold?: number; maxSteersPerTurn?: number; } export declare function normalizeKey(key: string): string; export declare function normalizeCommandLine(cmd: string): string; export declare function canonicalizeValue(val: unknown): unknown; export declare function inferToolNameFromUpdate(title?: string | null, kind?: string | null, rawInput?: unknown): string; export declare function computeToolCallSignature(toolName: string, rawInput: unknown): string; export declare function extractTargetResource(rawInput: unknown): string | undefined; export interface CycleDetectionResult { isLoop: boolean; cycleLength: number; repetitions: number; pattern: string[]; } export declare function detectCycle(signatures: readonly string[], options?: { maxPeriod?: number; singleToolThreshold?: number; cycleThreshold?: number; }): CycleDetectionResult; export declare const DEFAULT_READ_ONLY_SINGLE_THRESHOLD = 15; export declare const DEFAULT_MUTATING_SINGLE_THRESHOLD = 10; export declare const DEFAULT_CYCLE_THRESHOLD = 4; export declare const DEFAULT_RESOURCE_LOOP_THRESHOLD = 25; export declare class RepetitiveToolLoopTracker { private readonly sessions; private readonly promptIdToSessionId; private getOrCreate; startTurn(sessionId: string, promptId?: string | number, promptText?: string): void; isClientCancelled(sessionId: string): boolean; setClientCancelled(sessionId: string, cancelled: boolean): void; getSessionIdForPrompt(promptId: string | number): string | undefined; recordToolCall(sessionId: string, toolName: string, rawInput: unknown, options?: RepetitiveToolLoopOptions): CycleDetectionResult; isLoopInterrupted(sessionId: string): boolean; isSteerPending(sessionId: string): boolean; setSteerPending(sessionId: string, pending: boolean): void; getSteerPromptId(sessionId: string): string | number | undefined; setSteerPromptId(sessionId: string, promptId: string | number): void; clearSteerPrompt(sessionId: string): void; getSteerCount(sessionId: string): number; incrementSteerCount(sessionId: string): void; getLastToolName(sessionId: string): string | undefined; getLastLoopResult(sessionId: string): CycleDetectionResult | undefined; getLastTargetResource(sessionId: string): string | undefined; resetSignaturesForSteering(sessionId: string): void; getActivePromptId(sessionId: string): string | number | null | undefined; hasPollingIntent(sessionId: string): boolean; clearSession(sessionId: string): void; clear(): void; } export declare function buildSteeringText(toolName: string, targetResource: string | undefined, repetitions: number, steerCount: number): string; export declare function createRepetitiveToolLoopFix(options?: RepetitiveToolLoopOptions): AcpFix; export declare const repetitiveToolLoopFix: AcpFix; //# sourceMappingURL=index.d.ts.map