// engine/ai-integration/kiro/spec-exporter.ts — Kiro spec exporter (SPEC-270)
import { writeFileSync, mkdirSync, existsSync } from 'node:fs';
import { join } from 'node:path';
function buildUserStories(spec) {
    if (spec.acceptanceCriteria.length === 0) {
        return [
            {
                id: 'US-001',
                description: spec.description,
                acceptanceCriteria: [],
            },
        ];
    }
    return spec.acceptanceCriteria.map((criterion, index) => ({
        id: `US-${String(index + 1).padStart(3, '0')}`,
        description: criterion,
        acceptanceCriteria: [criterion],
    }));
}
function buildTasks(spec) {
    if (spec.acceptanceCriteria.length === 0) {
        return [
            {
                id: 'T-001',
                description: `Implement: ${spec.title}`,
                status: 'pending',
            },
        ];
    }
    return spec.acceptanceCriteria.map((criterion, index) => ({
        id: `T-${String(index + 1).padStart(3, '0')}`,
        description: `Implement: ${criterion}`,
        status: 'pending',
    }));
}
/** Converts a Planu spec to Kiro format */
export function exportSpecToKiro(spec) {
    return {
        id: spec.id,
        title: spec.title,
        status: 'approved',
        userStories: buildUserStories(spec),
        tasks: buildTasks(spec),
    };
}
/** Writes a Kiro spec JSON to .kiro/specs/<id>.json */
export function writeKiroSpec(projectPath, kiroSpec) {
    const specsDir = join(projectPath, '.kiro', 'specs');
    /* v8 ignore start */
    if (!existsSync(specsDir)) {
        mkdirSync(specsDir, { recursive: true });
    }
    /* v8 ignore stop */
    const content = JSON.stringify(kiroSpec, null, 2);
    writeFileSync(join(specsDir, `${kiroSpec.id}.json`), content + '\n', 'utf8');
}
//# sourceMappingURL=spec-exporter.js.map