/**
 * Tiny unified-diff helpers for human-readable doctor output.
 *
 * Wraps the `diff` package's createPatch into one call that returns a
 * pre-coloured unified diff (red = removed, green = added, dim = context).
 * Used by `agents doctor --diff`.
 */
import chalk from 'chalk';
import { createPatch } from 'diff';
/**
 * Build a unified-diff text comparing two strings. Returns an empty string
 * when contents are identical.
 */
export function unifiedDiff(expected, actual, options = {}) {
    if (expected === actual)
        return '';
    const fromLabel = options.fromLabel ?? 'expected';
    const toLabel = options.toLabel ?? 'actual';
    const context = options.context ?? 3;
    return createPatch(fromLabel, expected, actual, '', '', { context });
}
/**
 * Colour a unified-diff string for terminal output. Indents each line with
 * a constant prefix so it nests cleanly under a header.
 */
export function colorizeUnifiedDiff(patch, indent = '    ') {
    const lines = patch.split('\n');
    const out = [];
    for (const line of lines) {
        if (line.startsWith('---') || line.startsWith('+++') || line.startsWith('Index:') || line.startsWith('===')) {
            out.push(indent + chalk.gray(line));
        }
        else if (line.startsWith('@@')) {
            out.push(indent + chalk.cyan(line));
        }
        else if (line.startsWith('+')) {
            out.push(indent + chalk.green(line));
        }
        else if (line.startsWith('-')) {
            out.push(indent + chalk.red(line));
        }
        else {
            out.push(indent + chalk.gray(line));
        }
    }
    return out.join('\n');
}
