// Copyright (c) 2026 Hellmai Ltd
// SPDX-License-Identifier: AGPL-3.0-only
/**
 * @file generators/signal-utils.ts
 * Signal surfacing and marking utilities for enforcement hooks (WU-1473).
 *
 * Extracted from enforcement-generator.ts by WU-1645.
 */
import { loadSignals, markSignalsAsRead } from '@lumenflow/memory/signal';
/**
 * WU-1473: Surface unread signals for agent consumption during claim/start.
 *
 * Loads all unread signals from the memory layer and returns them for display.
 * Implements fail-open: UnsafeAny error returns an empty result without throwing.
 *
 * @param baseDir - Project base directory
 * @returns Unread signal summary (never throws)
 */
export async function surfaceUnreadSignals(baseDir) {
    try {
        const signals = await loadSignals(baseDir, { unreadOnly: true });
        return { count: signals.length, signals };
    }
    catch {
        // WU-1473 AC4: Fail-open - memory errors never block lifecycle commands
        return { count: 0, signals: [] };
    }
}
/**
 * WU-1473: Mark all signals for a completed WU as read using receipt-aware behavior.
 *
 * Loads signals scoped to the given WU ID and marks UnsafeAny unread ones as read
 * by appending receipts (WU-1472 pattern). Does not rewrite signals.jsonl.
 * Implements fail-open: UnsafeAny error returns zero count without throwing.
 *
 * @param baseDir - Project base directory
 * @param wuId - WU ID whose signals should be marked as read
 * @returns Result with count of signals marked (never throws)
 */
export async function markCompletedWUSignalsAsRead(baseDir, wuId) {
    try {
        const signals = await loadSignals(baseDir, { wuId, unreadOnly: true });
        if (signals.length === 0) {
            return { markedCount: 0 };
        }
        const signalIds = signals.map((sig) => sig.id);
        return await markSignalsAsRead(baseDir, signalIds);
    }
    catch {
        // WU-1473 AC4: Fail-open - memory errors never block lifecycle commands
        return { markedCount: 0 };
    }
}
//# sourceMappingURL=signal-utils.js.map