"use strict";
/**
 * Pack Diff (W3.3-support of F-NEW-PRODUCT-AGENT-VISIBILITY-CLUSTER-2026-05-12).
 *
 * Computes a structured diff between two pack versions. Two consumers:
 *
 *   1. Live pack editor (W3.3) — "preview your changes" view before publish.
 *   2. Shadow-mode comparison — "what would v2 have done differently than
 *      v1 on the last N events?"
 *
 * Pure function, no IO. Output is a stable, auditor-reproducible PackDiff
 * shape.
 *
 * @connexum/ai-governance  F-NEW-PRODUCT-LIVE-PACK-EDITOR + F-NEW-PRODUCT-PACK-VERSIONING-ROLLBACK
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.diffPacks = diffPacks;
exports.summarizeDiff = summarizeDiff;
/**
 * Diff two packs. Categories present only in `from` are 'removed'.
 * Categories present only in `to` are 'added'. Categories in both with
 * different actions are 'changed'. Categories in both with the same action
 * are NOT in the change list.
 */
function diffPacks(from, to) {
    const fromActions = from.dataPolicy?.categoryActions ?? {};
    const toActions = to.dataPolicy?.categoryActions ?? {};
    const allCategories = new Set([...Object.keys(fromActions), ...Object.keys(toActions)]);
    const changes = [];
    const added = [];
    const removed = [];
    const changed = [];
    for (const cat of [...allCategories].sort()) {
        const a = fromActions[cat];
        const b = toActions[cat];
        if (a === undefined && b !== undefined) {
            changes.push({ kind: 'added', category: cat, action: b });
            added.push(cat);
        }
        else if (b === undefined && a !== undefined) {
            changes.push({ kind: 'removed', category: cat, previousAction: a });
            removed.push(cat);
        }
        else if (a !== b && a !== undefined && b !== undefined) {
            changes.push({ kind: 'changed', category: cat, previousAction: a, newAction: b });
            changed.push(cat);
        }
    }
    const fromIso = String(from.requiresActionIsolation ?? 'none');
    const toIso = String(to.requiresActionIsolation ?? 'none');
    const isolationChange = fromIso !== toIso ? { from: fromIso, to: toIso } : undefined;
    return {
        fromVersion: from.version,
        toVersion: to.version,
        packId: from.id,
        changes,
        added,
        removed,
        changed,
        isolationChange,
        isNoop: changes.length === 0 && isolationChange === undefined,
    };
}
/**
 * Produce a short human-readable summary of the diff for dashboard cards
 * and email-notification subjects.
 */
function summarizeDiff(diff) {
    if (diff.isNoop)
        return `${diff.packId}: ${diff.fromVersion} -> ${diff.toVersion} (no functional changes)`;
    const parts = [];
    if (diff.added.length > 0)
        parts.push(`${diff.added.length} added`);
    if (diff.removed.length > 0)
        parts.push(`${diff.removed.length} removed`);
    if (diff.changed.length > 0)
        parts.push(`${diff.changed.length} changed`);
    if (diff.isolationChange)
        parts.push(`isolation ${diff.isolationChange.from} -> ${diff.isolationChange.to}`);
    return `${diff.packId}: ${diff.fromVersion} -> ${diff.toVersion} (${parts.join(', ')})`;
}
//# sourceMappingURL=pack-diff.js.map