"use strict";
/**
 * Benchmark tracking for wizard runs.
 *
 * Usage:
 *   const pipeline = createBenchmarkPipeline(spinner, options);
 *   pipeline.onMessage(message);
 *   pipeline.finalize(resultMessage, durationMs);
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createBenchmarkPipeline = createBenchmarkPipeline;
const chalk_1 = __importDefault(require("chalk"));
const ui_1 = require("../../ui");
const debug_1 = require("../../utils/debug");
const pipeline_1 = require("./pipeline");
const phase_detector_1 = require("./phase-detector");
const config_1 = require("./config");
const benchmarks_1 = require("./benchmarks");
const agent_interface_1 = require("../agent-interface");
const observability_1 = require("./observability");
// ── Factory ────────────────────────────────────────────────────────────
/**
 * Create a middleware pipeline configured for benchmarking.
 * Loads .benchmark-config.json from the install dir, falls back to defaults.
 */
function createBenchmarkPipeline(spinner, options, configOverride, extras) {
    const config = configOverride ?? (0, config_1.loadBenchmarkConfig)(options.installDir);
    (0, debug_1.configureLogFile)({
        path: config.output.logPath,
        enabled: config.output.logEnabled,
    });
    const plugins = (0, benchmarks_1.createPluginsFromConfig)(config, {
        spinner,
        phased: false,
        outputPath: config.output.benchmarkPath,
    });
    if (!config.output.suppressWizardLogs) {
        (0, ui_1.getUI)().log.info(`${chalk_1.default.cyan(agent_interface_1.AgentSignals.BENCHMARK)} Verbose logs: ${(0, debug_1.getLogFilePath)()}`);
        (0, ui_1.getUI)().log.info(`${chalk_1.default.cyan(agent_interface_1.AgentSignals.BENCHMARK)} Benchmark data will be written to: ${config.output.benchmarkPath}`);
    }
    (0, debug_1.logToFile)(`${agent_interface_1.AgentSignals.BENCHMARK} Tracking enabled, starting with setup phase`);
    // Prepend observability middleware so it runs on benchmark pipelines too.
    return new pipeline_1.MiddlewarePipeline([
        (0, observability_1.createObservabilityMiddleware)(),
        ...plugins,
        ...(extras?.extraMiddlewares ?? []),
    ], {
        phaseDetector: new phase_detector_1.PhaseDetector(),
        autoDetectPhases: true,
    });
}
