Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/core/frontmatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

export function extractFrontmatter(content) {
const match = content.match(/^---\n([\s\S]*?)\n---/m)
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/m)
if (!match) {
return null
}
Expand All @@ -14,13 +14,15 @@ export function extractFrontmatter(content) {
let currentValue = ''

for (const line of lines) {
const keyMatch = line.match(/^(\w+):\s*(.*)$/)
if (keyMatch && !line.startsWith(' ')) {
const separatorIndex = line.indexOf(':')
const key = separatorIndex > 0 ? line.slice(0, separatorIndex) : null

if (key !== null && /^\w+$/.test(key) && !line.startsWith(' ')) {
if (currentKey) {
frontmatter[currentKey] = currentValue.trim().replace(/^["']|["']$/g, '')
}
currentKey = keyMatch[1]
currentValue = keyMatch[2]
currentKey = key
currentValue = line.slice(separatorIndex + 1)
} else if (currentKey) {
currentValue += ' ' + line.trim()
}
Expand Down
6 changes: 3 additions & 3 deletions src/validate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function validateSkill(skillDir) {
}

// Check SKILL.md length (words, excluding frontmatter)
const frontmatterMatch = content.match(/^---\n[\s\S]*?\n---/m)
const frontmatterMatch = content.match(/^---\r?\n[\s\S]*?\r?\n---/m)
const skillContent = frontmatterMatch ? content.slice(frontmatterMatch[0].length) : content
const wordCount = skillContent
.trim()
Expand Down Expand Up @@ -504,7 +504,7 @@ async function checkHeadingHierarchy(skillDir, warnings) {

if (inCodeBlock) continue

const headingMatch = lines[i].match(/^(#{1,6})\s+\S/)
const headingMatch = lines[i].match(/^(#{1,6})[ \t]+\S/)
if (headingMatch) {
const currentLevel = headingMatch[1].length
if (previousLevel > 0 && currentLevel > previousLevel + 1) {
Expand Down Expand Up @@ -540,7 +540,7 @@ async function checkDuplicateHeadings(skillDir, warnings) {
const lines = data.text.split('\n')

for (const line of lines) {
const headingMatch = line.match(/^#{1,6}\s+(.+)$/)
const headingMatch = line.match(/^#{1,6}[ \t]+(.+)$/)
if (headingMatch) {
const headingText = headingMatch[1].trim()
if (headings.includes(headingText)) {
Expand Down
11 changes: 6 additions & 5 deletions src/validate/micro-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

function normalizeText(text) {
return (text || '').replace(/[\t\r\n]+/g, ' ').trim()
return (typeof text === 'string' ? text : '').replace(/[\t\r\n]+/g, ' ').trim()
}

function hasTriggerContext(text) {
Expand Down Expand Up @@ -39,10 +39,11 @@ function checkIOTokens(text) {
}

function hasNoLinks(text) {
return !/(https?:\/\/|\[[^\]]+\]\([^\)]+\))/i.test(text)
return !/(https?:\/\/|\[[^\][]+\]\([^()]+\))/i.test(text)
}

export function validateMicroTemplate(description) {
const raw = typeof description === 'string' ? description : ''
const desc = normalizeText(description)
const issues = []

Expand Down Expand Up @@ -92,7 +93,7 @@ export function validateMicroTemplate(description) {
})
}

if (/<[a-zA-Z][^>]*>/.test(desc)) {
if (/<[a-zA-Z][^<>]*>/.test(desc)) {
issues.push({
severity: 'error',
code: 'desc.xml',
Expand All @@ -110,7 +111,7 @@ export function validateMicroTemplate(description) {
}

// NBSP
if (/\u00A0/.test(description)) {
if (/\u00A0/.test(raw)) {
issues.push({
severity: 'warn',
code: 'desc.nbsp',
Expand All @@ -128,7 +129,7 @@ export function validateMicroTemplate(description) {
}

// Trailing whitespace
if (/[ \t]+$/.test(description)) {
if (raw.endsWith(' ') || raw.endsWith('\t')) {
issues.push({
severity: 'warn',
code: 'desc.trailing',
Expand Down