function pctSaved(baseline, candidate) {
    if (baseline <= 0) {
        return 0;
    }
    return Math.max(0, Math.round(((baseline - candidate) / baseline) * 1000) / 10);
}
export function evaluateContextModes(cases) {
    return cases.map((item) => {
        const modes = {
            baseline: item.baselineTokens,
            'spec-guided': item.specGuidedTokens,
            'graph-guided': item.graphGuidedTokens,
            lean: item.leanTokens,
            'graph+lean': item.graphLeanTokens,
        };
        const bestMode = Object.entries(modes).sort((a, b) => a[1] - b[1])[0]?.[0] ??
            'baseline';
        return {
            id: item.id,
            bestMode,
            savingsVsBaselinePct: pctSaved(item.baselineTokens, modes[bestMode]),
            modes,
        };
    });
}
export function summarizeContextEval(results) {
    const bestModeCounts = {
        baseline: 0,
        'spec-guided': 0,
        'graph-guided': 0,
        lean: 0,
        'graph+lean': 0,
    };
    let totalSavings = 0;
    for (const result of results) {
        bestModeCounts[result.bestMode] += 1;
        totalSavings += result.savingsVsBaselinePct;
    }
    return {
        cases: results.length,
        averageSavingsVsBaselinePct: results.length === 0 ? 0 : Math.round((totalSavings / results.length) * 10) / 10,
        bestModeCounts,
    };
}
//# sourceMappingURL=eval-harness.js.map