import * as sessionStore from '../../storage/session-store.js';
const MAX_MEMORY_DECISIONS = 100;
/**
 * Update cross-conversation memory with decisions from the current session.
 * Only persists decisions with non-empty rationale.
 * Deduplicates by decision content. Keeps max 100 (most recent win).
 */
export async function updateCrossConversationMemory(session) {
    const newDecisions = session.decisions.filter((d) => d.rationale.length > 0);
    if (newDecisions.length === 0) {
        return;
    }
    const memory = await sessionStore.loadMemory(session.projectId);
    // Deduplicate by decision content
    const existingKeys = new Set(memory.decisions.map((d) => d.decision));
    const toAdd = newDecisions.filter((d) => !existingKeys.has(d.decision));
    if (toAdd.length === 0) {
        return;
    }
    memory.decisions.push(...toAdd);
    // Keep only the most recent MAX_MEMORY_DECISIONS
    if (memory.decisions.length > MAX_MEMORY_DECISIONS) {
        memory.decisions = memory.decisions.slice(-MAX_MEMORY_DECISIONS);
    }
    memory.updatedAt = new Date().toISOString();
    await sessionStore.saveMemory(memory);
}
/**
 * Load historical decisions from memory to inject into a new session.
 */
export async function loadHistoricalDecisions(projectId) {
    return sessionStore.loadMemory(projectId);
}
//# sourceMappingURL=memory-sync.js.map