// engine/ai-integration/agent-frameworks/langgraph-exporter.ts — LangGraph config exporter (SPEC-274)
import { writeFileSync, mkdirSync, existsSync } from 'node:fs';
import { join } from 'node:path';
/**
 * Converts a Planu spec into a LangGraph state machine configuration.
 * The SDD workflow is represented as nodes + edges.
 */
export function exportSpecToLangGraph(spec) {
    return {
        nodes: [
            {
                id: 'spec-reader',
                description: `Read spec ${spec.id} — ${spec.title} and extract acceptance criteria.`,
            },
            {
                id: 'implementer',
                description: `Implement all ${spec.acceptanceCriteria.length} acceptance criteria for spec ${spec.id}.`,
            },
            {
                id: 'validator',
                description: `Validate implementation against spec ${spec.id} criteria using mcp__planu__validate.`,
            },
            {
                id: 'done',
                description: `Mark spec ${spec.id} as done and update status in Planu.`,
            },
        ],
        edges: [
            {
                from: 'spec-reader',
                to: 'implementer',
            },
            {
                from: 'implementer',
                to: 'validator',
            },
            {
                from: 'validator',
                to: 'done',
                condition: 'validation_passed',
            },
            {
                from: 'validator',
                to: 'implementer',
                condition: 'validation_failed',
            },
        ],
        entryPoint: 'spec-reader',
        stateSchema: {
            specId: 'string',
            specTitle: 'string',
            acceptanceCriteria: 'string[]',
            implementationStatus: 'pending | in-progress | implemented | validated | done',
            validationResult: 'passed | failed | pending',
        },
    };
}
/**
 * Serializes the LangGraph config to JSON and writes `planu-graph.json` to the project path.
 */
export function writeLangGraphConfig(projectPath, spec) {
    const config = exportSpecToLangGraph(spec);
    /* v8 ignore start */
    if (!existsSync(projectPath)) {
        mkdirSync(projectPath, { recursive: true });
    }
    /* v8 ignore stop */
    const json = JSON.stringify(config, null, 2);
    writeFileSync(join(projectPath, 'planu-graph.json'), json, 'utf8');
}
//# sourceMappingURL=langgraph-exporter.js.map