[Bug] GenerateSkillIndex.ts: PAI skill missing from index due to frontmatter regex, plus stale ALWAYS_LOADED_SKILLS entries
Summary
Two bugs in GenerateSkillIndex.ts cause the skill index to be silently incorrect:
- PAI skill is excluded from
skill-index.json— the frontmatter parser regex requires---at position 0, butPAI/SKILL.mdstarts with a generated HTML comment block, so PAI is always skipped. ALWAYS_LOADED_SKILLSreferences two nonexistent skills —DevelopmentandBloggingare listed but no corresponding skill directories exist. OnlyResearchandArtmatch anything, soalwaysLoadedCountreports2(not5as intended).
Root Cause Analysis
Bug 1 — Frontmatter regex anchored at position 0
// GenerateSkillIndex.ts:83
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
PAI/SKILL.md is a generated file (via RebuildPAI.ts) that begins with an HTML comment:
<!--
🔨 GENERATED FILE - Do not edit directly
Edit: ~/.claude/skills/PAI/Components/
...
-->
---
name: PAI
description: Personal AI Infrastructure core. The authoritative reference for how PAI works.
---
The regex /^---\n/ matches --- only at the very start of the string. Because the comment precedes the frontmatter delimiter, parseFrontmatter() returns null, and parseSkillFile() logs "Skipping: No valid frontmatter" and silently drops PAI from the index.
Bug 2 — Stale ALWAYS_LOADED_SKILLS array
// GenerateSkillIndex.ts:38-44
const ALWAYS_LOADED_SKILLS = [
'PAI', // ← excluded by Bug 1
'Development', // ← no skill directory exists
'Research', // ✓ exists
'Blogging', // ← no skill directory exists
'Art', // ✓ exists
];
Running GenerateSkillIndex.ts today produces:
Total: 45 skills (note: includes personal/custom skills not part of baseline PAI release)
Always loaded: 2 (research, art)
Deferred: 43
Expected (after fixes): alwaysLoadedCount: 3 (pai, research, art).
Proposed Fix
Bug 1 — Relax the frontmatter regex to allow content before the opening ---:
// Before
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
// After — match the first --- block anywhere near the top of the file
const frontmatterMatch = content.match(/(?:^|\n)---\n([\s\S]*?)\n---/);
Bug 2 — Remove the nonexistent entries:
const ALWAYS_LOADED_SKILLS = [
'PAI',
'Research',
'Art',
];
Question for Maintainer
@danielmiessler Is it intentional that PAI doesn't appear in skill-index.json? Since PAI loads via the LoadContext hook (always injected into context at session start), the Capability Audit's skill scan may not need PAI to be in the index. If that's the case, the ALWAYS_LOADED_SKILLS entry for 'PAI' is also misleading and should be removed rather than fixed.
Environment
- PAI v3.0
GenerateSkillIndex.ts@skills/PAI/Tools/GenerateSkillIndex.ts- Bun runtime
Closing — GenerateSkillIndex.ts and skill-index.json were removed in v4.0. The skill indexing system was replaced with the new architecture. This issue no longer applies. Thanks for the thorough analysis!