external-skill-names.ts
42 lines · scripts/external-skill-names.ts at 3f79d81
1export function externalSkillName(skillDir: string, frontmatterName?: string): string {
2 if (skillDir === '.' || skillDir === '') return 'gstack';
3 const baseName = frontmatterName && frontmatterName !== skillDir ? frontmatterName : skillDir;
4 if (baseName.startsWith('gstack-')) return baseName;
5 return `gstack-${baseName}`;
6}
8export function extractNameAndDescription(content: string): { name: string; description: string } {
9 const fmStart = content.indexOf('---\n');
10 if (fmStart !== 0) return { name: '', description: '' };
11 const fmEnd = content.indexOf('\n---', fmStart + 4);
12 if (fmEnd === -1) return { name: '', description: '' };
14 const frontmatter = content.slice(fmStart + 4, fmEnd);
15 const nameMatch = frontmatter.match(/^name:\s*(.+)$/m);
16 const name = nameMatch ? nameMatch[1].trim() : '';
18 let description = '';
19 const lines = frontmatter.split('\n');
20 let inDescription = false;
21 const descLines: string[] = [];
22 for (const line of lines) {
23 if (line.match(/^description:\s*\|?\s*$/)) {
24 inDescription = true;
25 continue;
26 }
27 if (line.match(/^description:\s*\S/)) {
28 description = line.replace(/^description:\s*/, '').trim();
29 break;
30 }
31 if (inDescription) {
32 if (line === '' || line.match(/^\s/)) {
33 descLines.push(line.replace(/^ /, ''));
34 } else {
35 break;
36 }
37 }
38 }
39 if (descLines.length > 0) description = descLines.join('\n').trim();
41 return { name, description };
42}