// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
const MAX_NAME_LENGTH = 64;
const CONTEXT_ARGUMENT = {
    name: 'context',
    description: 'Additional context for this spec execution',
    required: false,
};
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
/**
 * Sanitizes a string into a valid MCP prompt name segment.
 * Lowercases, replaces non-alphanumeric chars with hyphens,
 * collapses repeated hyphens, and strips leading/trailing hyphens.
 */
function sanitizeSegment(value) {
    return value
        .toLowerCase()
        .replace(/[^a-z0-9-]/g, '-')
        .replace(/-{2,}/g, '-')
        .replace(/^-+|-+$/g, '');
}
/**
 * Builds the prompt name from spec id and slug, truncated to MAX_NAME_LENGTH.
 * Format: `planu:{id}-{slug}` (e.g. `planu:SPEC-342-export-pdf`)
 */
export function buildPromptName(id, slug) {
    const idPart = sanitizeSegment(id);
    const slugPart = sanitizeSegment(slug);
    const full = `planu:${idPart}-${slugPart}`;
    return full.slice(0, MAX_NAME_LENGTH);
}
// ---------------------------------------------------------------------------
// Public API
// ---------------------------------------------------------------------------
/**
 * Generates a SpecPromptDefinition from a Planu spec.
 * The resulting definition can be registered as an MCP prompt via server.prompt().
 */
export function generatePromptFromSpec(spec) {
    const name = buildPromptName(spec.id, spec.slug);
    const firstCriterion = spec.criteria?.[0];
    const descriptionHint = firstCriterion !== undefined ? ` | ${firstCriterion}` : '';
    const description = `${spec.title}${descriptionHint}`;
    const criteriaLines = spec.criteria !== undefined && spec.criteria.length > 0
        ? spec.criteria.map((c, i) => `${i + 1}. ${c}`).join('\n')
        : 'No acceptance criteria defined.';
    const summarySection = spec.summary !== undefined ? `\n\nSummary: ${spec.summary}` : '';
    const template = [
        `You are implementing spec ${spec.id}: ${spec.title}.`,
        summarySection,
        '',
        'Acceptance criteria:',
        criteriaLines,
        '',
        'Follow each criterion exactly. When done, run validate to confirm compliance.',
    ]
        .join('\n')
        .trim();
    return {
        name,
        description,
        arguments: [{ ...CONTEXT_ARGUMENT }],
        template,
    };
}
//# sourceMappingURL=spec-prompt-generator.js.map