// engine/token-savings-estimator.ts — SPEC-520: Estimate token savings from Planu behavioral rules
// Pure function, no I/O — takes usage stats snapshot and returns savings estimate.
const AVG_TOKENS_PER_CALL = 1200;
const SDD_TOKENS_PER_DONE_SPEC = 8000;
// Sonnet pricing ~$3/1M input + $15/1M output, average ~$9/1M tokens
const AVG_COST_USD_PER_MILLION_TOKENS = 9;
const BEHAVIORAL_COMPRESSION_RATE = 0.55;
export function estimateTokenSavings(usageStats, hasResponseStyleRules) {
    const compressionRate = hasResponseStyleRules ? BEHAVIORAL_COMPRESSION_RATE : 0;
    const behavioralTokensSaved = Math.round(usageStats.totalCalls * AVG_TOKENS_PER_CALL * compressionRate);
    const sddTokensSaved = usageStats.doneSpecs * SDD_TOKENS_PER_DONE_SPEC;
    const totalSaved = behavioralTokensSaved + sddTokensSaved;
    const costSavedUsd = Math.round((totalSaved / 1_000_000) * AVG_COST_USD_PER_MILLION_TOKENS * 1000) / 1000;
    return {
        estimatedTokensSaved: totalSaved,
        estimatedCostSavedUsd: costSavedUsd,
        breakdown: {
            behavioralPromptingTokens: behavioralTokensSaved,
            sddDisciplineTokens: sddTokensSaved,
        },
        assumption: {
            responseCompressionPct: Math.round(compressionRate * 100),
            avgTokensPerSession: AVG_TOKENS_PER_CALL,
            specsCompletedWithoutRework: usageStats.doneSpecs,
        },
        generatedAt: new Date().toISOString(),
    };
}
//# sourceMappingURL=token-savings-estimator.js.map