// engine/autopilot/cascade-deduplicator.ts — SPEC-660: Prevent duplicate cascade actions
// Module-level singleton: tracks in-flight cascade actions by specId+action key.
// Within the TTL window, duplicate triggers for the same key are silently dropped.
const pending = new Map();
const DEFAULT_TTL_MS = 5000;
function key(specId, action) {
    return `${specId}:${action}`;
}
/** Returns true if a cascade action is already pending for this spec+action pair. */
export function hasPending(specId, action) {
    return pending.has(key(specId, action));
}
/**
 * Mark a cascade action as in-flight for the given TTL window.
 * Subsequent calls to hasPending within the window return true.
 * After ttlMs, the entry is cleared automatically.
 */
export function markPending(specId, action, ttlMs = DEFAULT_TTL_MS) {
    const k = key(specId, action);
    const existing = pending.get(k);
    if (existing !== undefined) {
        clearTimeout(existing);
    }
    const handle = setTimeout(() => {
        pending.delete(k);
    }, ttlMs);
    pending.set(k, handle);
}
/** Clear a pending entry immediately (e.g. on action completion or failure). */
export function clearPending(specId, action) {
    const k = key(specId, action);
    const handle = pending.get(k);
    if (handle !== undefined) {
        clearTimeout(handle);
        pending.delete(k);
    }
}
/** Returns current count of pending entries (useful for testing). */
export function pendingCount() {
    return pending.size;
}
//# sourceMappingURL=cascade-deduplicator.js.map