"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidationProfilingEnabled = isValidationProfilingEnabled;
exports.emitValidationProfile = emitValidationProfile;
exports.profileValidationPhase = profileValidationPhase;
function isValidationProfilingEnabled() {
    return process.env.ARCHPILOT_PROFILE === '1';
}
function formatDetails(details) {
    if (!details || details.length === 0) {
        return '';
    }
    return ` ${details.map((detail) => `${detail.name}=${detail.value}`).join(' ')}`;
}
function emitValidationProfile(label, durationMs, details) {
    if (!isValidationProfilingEnabled()) {
        return;
    }
    process.stderr.write(`[ARCHPILOT_PROFILE] ${label} ${Math.round(durationMs)}ms${formatDetails(details)}\n`);
}
async function profileValidationPhase(label, run, details) {
    const started = Date.now();
    try {
        const result = await run();
        emitValidationProfile(label, Date.now() - started, details?.(result));
        return result;
    }
    catch (error) {
        emitValidationProfile(label, Date.now() - started, [{ name: 'failed', value: true }]);
        throw error;
    }
}
//# sourceMappingURL=validationProfiling.js.map