// tools/auto-promoter-handler.ts — Auto-Promotion Confidence Scoring handlers (SPEC-391)
import { calculateConfidence } from '../engine/auto-promoter.js';
import { getConfig, saveConfig } from '../storage/auto-promoter-config-store.js';
import { hashProjectPath } from '../storage/base-store.js';
import { getSpec } from '../storage/spec-store.js';
const SIMPLIFIED_READINESS_SCORE = 100;
/**
 * Configure auto-promotion settings for a project.
 * Merges provided fields into the existing config and persists.
 */
export async function handleConfigureAutoPromotion(input) {
    const { projectPath, enabled, threshold, maxRisk } = input;
    const current = await getConfig(projectPath);
    const updated = {
        ...current,
        ...(enabled !== undefined && { enabled }),
        ...(threshold !== undefined && { readinessThreshold: threshold }),
        ...(maxRisk !== undefined && { maxRisk }),
    };
    await saveConfig(projectPath, updated);
    const statusLine = updated.enabled ? 'enabled' : 'disabled';
    const text = `Auto-promotion ${statusLine}. ` +
        `Threshold: ${updated.readinessThreshold}, maxRisk: ${updated.maxRisk}.`;
    return { content: [{ type: 'text', text }] };
}
/**
 * Check whether a spec is eligible for auto-promotion.
 * Uses a simplified readiness score of 100 and evaluates against project config.
 */
export async function handleCheckAutoPromotion(input) {
    const { projectPath, specId } = input;
    const projectId = hashProjectPath(projectPath);
    const spec = await getSpec(projectId, specId);
    if (spec === null) {
        return {
            content: [{ type: 'text', text: `Spec ${specId} not found in project.` }],
        };
    }
    const config = await getConfig(projectPath);
    const score = calculateConfidence(spec, SIMPLIFIED_READINESS_SCORE, config);
    const lines = [
        `Spec: ${specId}`,
        `Overall score: ${score.overall}/100`,
        `Readiness: ${score.readiness} | Risk penalty: ${score.riskPenalty} | Dep bonus: ${score.dependencyBonus}`,
        `Eligible: ${score.eligible ? 'YES' : 'NO'}`,
        score.reason,
    ];
    return { content: [{ type: 'text', text: lines.join('\n') }] };
}
//# sourceMappingURL=auto-promoter-handler.js.map