export function detectTokenWasteLoops(events, policy, action = 'default') {
    if (policy.loops.safetyOverrideActions.includes(action)) {
        return { warnings: [] };
    }
    const counts = new Map();
    for (const event of events) {
        if (event.changedSincePrevious === true) {
            continue;
        }
        const key = `${event.type}:${event.key}`;
        counts.set(key, (counts.get(key) ?? 0) + 1);
    }
    const warnings = [];
    for (const [key, count] of counts) {
        const [type = 'unknown', target = key] = key.split(':');
        const threshold = policy.loops.thresholds[type] ?? Number.POSITIVE_INFINITY;
        if (count >= threshold) {
            warnings.push({
                decision: 'warn',
                target,
                reason: `Repeated ${type} operation detected ${String(count)} times without an intervening change.`,
                evidence: [
                    { source: 'policy', key: `loops.thresholds.${type}`, value: threshold },
                    { source: 'runtime', key: 'event.count', value: count },
                ],
                confidence: 'high',
            });
        }
    }
    return { warnings };
}
//# sourceMappingURL=loop-detector.js.map