/**
 * api-client/format-error.ts — Human-readable error formatting for failed jobs.
 *
 * Produces structured console output that shows the failed step, error
 * message, and (when available) a remediation hint. The output is designed
 * to be useful both in interactive terminals and in CI log output.
 */
import { getRemediationHint } from "./remediation.js";
/**
 * Format a failed job response into a multi-line error string.
 *
 * Does NOT call `process.exit()` — the caller decides what to do.
 *
 * @example
 * ```
 * ❌ Pipeline failed at step 'fetch-docs'
 *    Postcondition failed: Canonical context for task "foo" is empty.
 *
 * 💡 One or more context.docs entries in your task definitions don't resolve ...
 * ```
 */
export function formatJobError(job) {
    const lines = [];
    if (job.error?.step && job.error?.message) {
        lines.push(`❌ Pipeline failed at step '${job.error.step}'`);
        lines.push(`   ${job.error.message}`);
    }
    else if (job.error?.message) {
        lines.push(`❌ Evaluation failed`);
        lines.push(`   ${job.error.message}`);
    }
    else if (job.status === "timed-out") {
        lines.push(`❌ Evaluation timed out`);
        lines.push("   The job did not complete within the server-side deadline.");
    }
    else {
        lines.push(`❌ Evaluation ${job.status}`);
    }
    // Remediation hint
    if (job.error) {
        const hint = getRemediationHint(job.error);
        if (hint) {
            lines.push("");
            lines.push(`💡 ${hint}`);
        }
    }
    return lines.join("\n");
}
