/**
 * Effective History Filter
 *
 * Filters message arrays to return only "visible" messages,
 * excluding those tagged by condensation or truncation.
 * Supports non-destructive context management where messages
 * are tagged instead of deleted.
 */
/**
 * Get the effective (visible) history from a message array.
 *
 * Filters out:
 * - Messages with a condenseParent (replaced by a summary)
 * - Messages with a truncationParent (hidden by truncation)
 *
 * Keeps:
 * - Summary messages (isSummary = true)
 * - Truncation markers (isTruncationMarker = true)
 * - All other untagged messages
 */
export function getEffectiveHistory(messages) {
    return messages.filter((msg) => {
        // Exclude messages that have been condensed (replaced by summary)
        if (msg.condenseParent) {
            return false;
        }
        // Exclude messages that have been truncated (hidden by marker)
        if (msg.truncationParent) {
            return false;
        }
        return true;
    });
}
/**
 * Tag messages for condensation (non-destructive summary).
 *
 * @param messages - Full message array
 * @param fromIndex - Start index of messages to condense
 * @param toIndex - End index (exclusive) of messages to condense
 * @param condenseId - UUID for this condensation group
 * @returns Updated message array with tags applied
 */
export function tagForCondensation(messages, fromIndex, toIndex, condenseId) {
    return messages.map((msg, i) => {
        if (i >= fromIndex && i < toIndex) {
            return { ...msg, condenseParent: condenseId };
        }
        return msg;
    });
}
/**
 * Tag messages for truncation (non-destructive hiding).
 *
 * @param messages - Full message array
 * @param fromIndex - Start index of messages to truncate
 * @param toIndex - End index (exclusive) of messages to truncate
 * @param truncationId - UUID for this truncation group
 * @returns Updated message array with tags applied
 */
export function tagForTruncation(messages, fromIndex, toIndex, truncationId) {
    return messages.map((msg, i) => {
        if (i >= fromIndex && i < toIndex) {
            return { ...msg, truncationParent: truncationId };
        }
        return msg;
    });
}
/**
 * Remove condensation tags (rewind).
 * Makes previously condensed messages visible again.
 */
export function removeCondensationTags(messages, condenseId) {
    return messages
        .map((msg) => {
        if (msg.condenseParent === condenseId) {
            const { condenseParent, ...rest } = msg;
            return rest;
        }
        // Also remove the summary message itself
        if (msg.condenseId === condenseId && msg.metadata?.isSummary) {
            return null;
        }
        return msg;
    })
        .filter((msg) => msg !== null);
}
/**
 * Remove truncation tags (rewind).
 * Makes previously truncated messages visible again.
 */
export function removeTruncationTags(messages, truncationId) {
    return messages
        .map((msg) => {
        if (msg.truncationParent === truncationId) {
            const { truncationParent, ...rest } = msg;
            return rest;
        }
        // Also remove the truncation marker itself
        if (msg.truncationId === truncationId && msg.isTruncationMarker) {
            return null;
        }
        return msg;
    })
        .filter((msg) => msg !== null);
}
//# sourceMappingURL=effectiveHistory.js.map