/**
 * `olam flywheel k5-score` — compute K5 composite + boost from sub-scores.
 *
 * Per `references/k5-rubric-schema.md` from the /10x: planning chain:
 *   k5_boost = min(2.0, cited_ratio * 4.0)
 *   k5_composite = min(100, min(k5_scores.values()) * k5_boost)
 *
 * Output: JSON object on stdout.
 *
 * Plan reference: docs/plans/olam-flywheel-cli-namespace/phase-a-tasks.md § A4
 */
function parseScore(raw, name) {
    const n = Number.parseInt(raw, 10);
    if (!Number.isFinite(n) || n < 0 || n > 100) {
        process.stderr.write(`[k5-score-reject] --${name} must be integer 0-100, got: ${JSON.stringify(raw)}\n`);
        process.exit(2);
    }
    return n;
}
function parseCitedRatio(raw) {
    if (raw === undefined)
        return 0.0;
    const n = Number.parseFloat(raw);
    if (!Number.isFinite(n) || n < 0.0 || n > 1.0) {
        process.stderr.write(`[k5-score-reject] --cited-ratio must be 0.0-1.0, got: ${JSON.stringify(raw)}\n`);
        process.exit(2);
    }
    return n;
}
function computeK5(scores, citedRatio) {
    const boost = Math.min(2.0, citedRatio * 4.0);
    const minScore = Math.min(scores.direction, scores.approach, scores.open_questions, scores.constraints, scores.reuse);
    const composite = Math.min(100, Math.round(minScore * boost));
    return { k5_scores: scores, k5_boost: boost, k5_composite: composite };
}
export function registerFlywheelK5Score(parent) {
    parent
        .command('k5-score')
        .description('Compute K5 composite + boost from sub-scores (min-of-5 × boost, capped at 100)')
        .requiredOption('--direction <0-100>', 'Direction sub-score')
        .requiredOption('--approach <0-100>', 'Approach sub-score')
        .requiredOption('--open-questions <0-100>', 'Open questions sub-score')
        .requiredOption('--constraints <0-100>', 'Constraints sub-score')
        .requiredOption('--reuse <0-100>', 'Reuse sub-score')
        .option('--cited-ratio <0.0-1.0>', 'Cited fact ratio (default 0.0 → boost = 0)')
        .action((opts) => {
        const scores = {
            direction: parseScore(opts.direction, 'direction'),
            approach: parseScore(opts.approach, 'approach'),
            open_questions: parseScore(opts.openQuestions, 'open-questions'),
            constraints: parseScore(opts.constraints, 'constraints'),
            reuse: parseScore(opts.reuse, 'reuse'),
        };
        const citedRatio = parseCitedRatio(opts.citedRatio);
        const result = computeK5(scores, citedRatio);
        process.stdout.write(JSON.stringify(result) + '\n');
    });
}
//# sourceMappingURL=k5-score.js.map