Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

[Bug] GenerateSkillIndex.ts: PAI skill missing from index due to frontmatter regex, plus stale ALWAYS_LOADED_SKILLS entries

Open brycemagera opened this issue 9 months ago • 1 comments

Summary

Two bugs in GenerateSkillIndex.ts cause the skill index to be silently incorrect:

  1. PAI skill is excluded from skill-index.json — the frontmatter parser regex requires --- at position 0, but PAI/SKILL.md starts with a generated HTML comment block, so PAI is always skipped.
  2. ALWAYS_LOADED_SKILLS references two nonexistent skills — Development and Blogging are listed but no corresponding skill directories exist. Only Research and Art match anything, so alwaysLoadedCount reports 2 (not 5 as 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

brycemagera avatar Feb 27 '26 17:02 brycemagera

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!

kaimagnus avatar Mar 01 '26 02:03 kaimagnus