/**
 * Skill document schema — defines the structure of learned skills.
 * Compatible with agentskills.io format and upstream SKILL.md convention.
 */
/**
 * Extract metadata from a full skill document.
 */
export function toMetadata(skill) {
    return {
        id: skill.id,
        name: skill.name,
        description: skill.description,
        tags: skill.tags ?? [],
        whenToUse: skill.whenToUse,
        useCount: skill.useCount,
        createdAt: skill.createdAt,
        updatedAt: skill.updatedAt,
    };
}
/**
 * Render a skill document as SKILL.md content (upstream-compatible).
 */
export function renderSkillMd(skill) {
    if (skill.sourceMarkdown?.trim()) {
        return skill.sourceMarkdown;
    }
    const lines = [];
    lines.push(`# ${skill.name}`);
    lines.push('');
    lines.push(`> ${skill.description}`);
    lines.push('');
    if (skill.whenToUse) {
        lines.push(`## When to Use`);
        lines.push('');
        lines.push(skill.whenToUse);
        lines.push('');
    }
    if (skill.procedure && skill.procedure.length > 0) {
        lines.push(`## Procedure`);
        lines.push('');
        for (const step of skill.procedure) {
            lines.push(`${step.order}. **${step.action}**`);
            if (step.detail)
                lines.push(`   ${step.detail}`);
        }
        lines.push('');
    }
    if (skill.pitfalls && skill.pitfalls.length > 0) {
        lines.push(`## Pitfalls`);
        lines.push('');
        for (const p of skill.pitfalls) {
            lines.push(`- ⚠️ **${p.description}**`);
            lines.push(`  → ${p.mitigation}`);
        }
        lines.push('');
    }
    if (skill.verification && skill.verification.length > 0) {
        lines.push(`## Verification`);
        lines.push('');
        for (const v of skill.verification) {
            lines.push(`- [ ] ${v.check} → ${v.expected}`);
        }
        lines.push('');
    }
    if (skill.tags && skill.tags.length > 0) {
        lines.push(`## Tags`);
        lines.push('');
        lines.push(skill.tags.map(t => `\`${t}\``).join(', '));
        lines.push('');
    }
    return lines.join('\n');
}
/**
 * Validate a skill ID (kebab-case, 3-80 chars).
 */
export function isValidSkillId(id) {
    return /^[a-z0-9][a-z0-9-]{1,78}[a-z0-9]$/.test(id);
}
/**
 * Generate a skill ID from a name.
 */
export function nameToId(name) {
    return name
        .toLowerCase()
        .replace(/[^a-z0-9]+/g, '-')
        .replace(/^-+|-+$/g, '')
        .slice(0, 80);
}
//# sourceMappingURL=schema.js.map