// engine/agent-ready-exporter.ts — Agent-Ready spec export central module — SPEC-318
import { formatGeneric } from './agent-ready-exporter/formatters/generic.js';
import { formatDevin } from './agent-ready-exporter/formatters/devin.js';
import { formatKiro } from './agent-ready-exporter/formatters/kiro.js';
import { formatSweAgent } from './agent-ready-exporter/formatters/swe-agent.js';
// ---------------------------------------------------------------------------
// Context extraction helpers
// ---------------------------------------------------------------------------
function extractObjective(spec) {
    return `Implement "${spec.title}" (${spec.id}) — a ${spec.type} spec with ${spec.scope} scope.`;
}
function extractSuccessCriteria(spec) {
    // Build criteria from spec metadata — technical path is the source of truth at runtime,
    // but at export time we derive criteria from available structured fields.
    const criteria = [
        `Spec ${spec.id} passes validation (pnpm validate or equivalent)`,
        `All tests pass for modified/created files`,
        `TypeScript strict mode: zero type errors`,
        `ESLint: zero warnings or errors`,
    ];
    if (spec.estimation.devHours > 0) {
        criteria.push(`Implementation completed within estimated ${String(spec.estimation.devHours)}h`);
    }
    return criteria;
}
function extractConstraints(spec) {
    const constraints = [
        'TypeScript strict mode enforced — no any types',
        'ES modules with .js extensions on all imports',
        `Risk level is ${spec.risk} — review carefully before merging`,
    ];
    if (spec.tags.length > 0) {
        constraints.push(`Tagged: ${spec.tags.join(', ')} — respect domain conventions`);
    }
    return constraints;
}
function extractDependencies(spec) {
    return spec.dependencies.length > 0
        ? spec.dependencies
        : ['No blocking dependencies — can start immediately'];
}
function buildAgentContext(spec) {
    return {
        objective: extractObjective(spec),
        success_criteria: extractSuccessCriteria(spec),
        constraints: extractConstraints(spec),
        files_to_create: [],
        files_to_modify: [spec.specPath, spec.technicalPath].filter(Boolean),
        forbidden_files: ['src/index.ts', 'src/types/index.ts'],
        test_command: 'pnpm test',
        validation_command: 'pnpm typecheck && pnpm lint',
        effort_estimate: `${String(spec.estimation.devHours)}h (${spec.difficulty} difficulty)`,
        dependencies: extractDependencies(spec),
        rollback: `git revert HEAD or delete branch feat/${spec.id.toLowerCase()}-*`,
    };
}
// ---------------------------------------------------------------------------
// Public API
// ---------------------------------------------------------------------------
/**
 * Convert a Spec into an AgentReadySpec structure optimized for autonomous coding agents.
 */
export function specToAgentReady(spec, agentTarget) {
    return {
        spec_id: spec.id,
        title: spec.title,
        agent_context: buildAgentContext(spec),
        _format: agentTarget,
    };
}
/**
 * Serialize an AgentReadySpec to a string using the appropriate formatter.
 */
export function serializeAgentReady(agentSpec, target) {
    switch (target) {
        case 'devin':
            return formatDevin(agentSpec);
        case 'kiro':
            return formatKiro(agentSpec);
        case 'swe-agent':
            return formatSweAgent(agentSpec);
        case 'generic':
            return formatGeneric(agentSpec);
    }
}
//# sourceMappingURL=agent-ready-exporter.js.map