Open History to see the last commit
1/**
2 * `validateSkill` — author-time linting against native-delivery constraints, so
3 * a skill authored today can be promoted to a hosted (Anthropic/OpenAI) skill
4 * later without surprises. Phase 1 never uploads; this only warns.
5 */
6import type { SkillMetadata } from './types'
7
8export type SkillTarget = 'portable' | 'anthropic' | 'openai'
9
10export interface SkillValidationIssue {
11 target: SkillTarget
12 message: string
13}
14
15export interface SkillValidationResult {
16 ok: boolean
17 issues: Array<SkillValidationIssue>
18}
19
20const XML_TAG = /<[^>]+>/
21const RESERVED_ANTHROPIC = ['anthropic', 'claude']
22
23/** Lint a skill against the given delivery targets (default `['portable']`). */
24export function validateSkill(
25 skill: SkillMetadata,
26 options: { targets?: Array<SkillTarget> } = {},
27): SkillValidationResult {
28 const targets = options.targets ?? ['portable']
29 const issues: Array<SkillValidationIssue> = []
30
31 const add = (target: SkillTarget, message: string) =>
32 issues.push({ target, message })
33
34 // Portable: the spec's own name/description bounds.
35 if (targets.includes('portable')) {
36 if (!/^[a-z0-9-]+$/.test(skill.name)) {
37 add('portable', 'name must match [a-z0-9-]')
38 }
39 if (skill.name.length > 64) add('portable', 'name exceeds 64 characters')
40 if (skill.description.length > 1024) {
41 add('portable', 'description exceeds 1024 characters')
42 }
43 }
44
45 if (targets.includes('anthropic')) {
46 const lower = skill.name.toLowerCase()
47 if (RESERVED_ANTHROPIC.some((r) => lower.includes(r))) {
48 add('anthropic', 'name may not contain "anthropic" or "claude"')
49 }
50 if (XML_TAG.test(skill.name) || XML_TAG.test(skill.description)) {
51 add('anthropic', 'name/description may not contain XML tags')
52 }
53 }
54
55 if (targets.includes('openai')) {
56 // OpenAI requires exactly one case-insensitive SKILL.md per bundle — a
57 // bundle-shape constraint not visible from metadata alone. Only the
58 // metadata-checkable rule is enforced here.
59 if (skill.name.trim() === '') add('openai', 'name must not be empty')
60 }
61
62 return { ok: issues.length === 0, issues }
63}