import { appendArtifact } from '../handoff-artifacts/io.js';
export async function writeSpecReviewFeedback(input) {
    const blockers = buildSpecReviewBlockers(input.spec);
    const verdict = blockers.length === 0 ? 'approved' : 'changes-requested';
    const payload = {
        schema_version: '1.0.0',
        specId: input.specId,
        verdict,
        reviewer: {
            kind: 'spec-review-agent',
            agent: 'planu-spec-reviewer',
            verdict,
        },
        blockers,
        suggestions: blockers.length === 0
            ? ['Proceed to approval gates; keep implementation reviewer separate after coding.']
            : [
                'Resolve blockers, rerun challenge/readiness checks, then move the spec back to review.',
            ],
        body: blockers.length === 0
            ? `Spec ${input.specId} reviewed by planu-spec-reviewer and approved for approval gates.`
            : `Spec ${input.specId} reviewed by planu-spec-reviewer with requested changes.`,
        reviewedAt: new Date().toISOString(),
    };
    try {
        const artifact = await appendArtifact({
            projectId: input.projectId,
            specId: input.specId,
            kind: 'review_feedback',
            payload,
        });
        return { written: true, path: artifact.path, sha: artifact.sha, payload };
    }
    catch (err) {
        return {
            written: false,
            payload,
            error: err instanceof Error ? err.message : String(err),
        };
    }
}
function buildSpecReviewBlockers(spec) {
    const blockers = [];
    if (!spec.title || spec.title.trim().length === 0) {
        blockers.push('Spec title is missing.');
    }
    return blockers;
}
//# sourceMappingURL=spec-review-writer.js.map