// tools/checkpoint/require-checkpoint-handler.ts — require_checkpoint handler (SPEC-411)
import { loadCheckpointConfig } from '../../engine/checkpoint/policy-engine.js';
import { requestCheckpoint } from '../../engine/checkpoint/checkpoint-manager.js';
export async function handleRequireCheckpoint(args) {
    const { projectPath, specId, transition, requestedBy = 'system' } = args;
    const config = await loadCheckpointConfig(projectPath);
    const policy = config.policies.find((p) => p.transition === transition);
    if (policy === undefined) {
        return {
            content: [
                {
                    type: 'text',
                    text: [
                        `No policy found for transition "${transition}".`,
                        'Configure one first with configure_checkpoint_policy.',
                    ].join('\n'),
                },
            ],
        };
    }
    const checkpoint = await requestCheckpoint(projectPath, specId, policy, requestedBy);
    const autoApproveNote = checkpoint.autoApproveAt !== undefined
        ? `\nAuto-approve scheduled at: ${checkpoint.autoApproveAt}`
        : '';
    return {
        content: [
            {
                type: 'text',
                text: [
                    `Checkpoint created for ${specId} (${transition}).`,
                    `Checkpoint ID: ${checkpoint.id}`,
                    `Required approver role: ${policy.requiredRole}`,
                    `Reason: ${policy.description}`,
                    autoApproveNote,
                    '',
                    `To approve: approve_checkpoint { projectPath, checkpointId: "${checkpoint.id}", approvedBy: "<your-id>" }`,
                    `To reject:  reject_checkpoint  { projectPath, checkpointId: "${checkpoint.id}", rejectedBy: "<your-id>", reason: "<reason>" }`,
                ].join('\n'),
            },
        ],
        structuredContent: { checkpoint },
    };
}
//# sourceMappingURL=require-checkpoint-handler.js.map