merge: PR #57 - fix: make skill/template discovery dynamic

This commit is contained in:
Garry Tan
2026-03-22 22:47:01 -07:00
4 changed files with 50 additions and 40 deletions

View File

@@ -7,16 +7,17 @@
*/ */
import { validateSkill } from '../test/helpers/skill-parser'; import { validateSkill } from '../test/helpers/skill-parser';
import { discoverTemplates } from './discover-skills';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
const ROOT = path.resolve(import.meta.dir, '..'); const ROOT = path.resolve(import.meta.dir, '..');
const TEMPLATES = [ const TEMPLATES = discoverTemplates(ROOT).map(t => ({
{ tmpl: path.join(ROOT, 'SKILL.md.tmpl'), output: 'SKILL.md' }, tmpl: path.join(ROOT, t.tmpl),
{ tmpl: path.join(ROOT, 'browse', 'SKILL.md.tmpl'), output: 'browse/SKILL.md' }, output: t.output,
]; }));
function regenerateAndValidate() { function regenerateAndValidate() {
// Regenerate // Regenerate

View File

@@ -0,0 +1,39 @@
/**
* Shared discovery for SKILL.md and .tmpl files.
* Scans root + one level of subdirs, skipping node_modules/.git/dist.
*/
import * as fs from 'fs';
import * as path from 'path';
const SKIP = new Set(['node_modules', '.git', 'dist']);
function subdirs(root: string): string[] {
return fs.readdirSync(root, { withFileTypes: true })
.filter(d => d.isDirectory() && !SKIP.has(d.name))
.map(d => d.name);
}
export function discoverTemplates(root: string): Array<{ tmpl: string; output: string }> {
const dirs = ['', ...subdirs(root)];
const results: Array<{ tmpl: string; output: string }> = [];
for (const dir of dirs) {
const rel = dir ? `${dir}/SKILL.md.tmpl` : 'SKILL.md.tmpl';
if (fs.existsSync(path.join(root, rel))) {
results.push({ tmpl: rel, output: rel.replace(/\.tmpl$/, '') });
}
}
return results;
}
export function discoverSkillFiles(root: string): string[] {
const dirs = ['', ...subdirs(root)];
const results: string[] = [];
for (const dir of dirs) {
const rel = dir ? `${dir}/SKILL.md` : 'SKILL.md';
if (fs.existsSync(path.join(root, rel))) {
results.push(rel);
}
}
return results;
}

View File

@@ -11,6 +11,7 @@
import { COMMAND_DESCRIPTIONS } from '../browse/src/commands'; import { COMMAND_DESCRIPTIONS } from '../browse/src/commands';
import { SNAPSHOT_FLAGS } from '../browse/src/snapshot'; import { SNAPSHOT_FLAGS } from '../browse/src/snapshot';
import { discoverTemplates } from './discover-skills';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
@@ -3004,16 +3005,7 @@ function processTemplate(tmplPath: string, host: Host = 'claude'): { outputPath:
// ─── Main ─────────────────────────────────────────────────── // ─── Main ───────────────────────────────────────────────────
function findTemplates(): string[] { function findTemplates(): string[] {
const templates: string[] = []; return discoverTemplates(ROOT).map(t => path.join(ROOT, t.tmpl));
const rootTmpl = path.join(ROOT, 'SKILL.md.tmpl');
if (fs.existsSync(rootTmpl)) templates.push(rootTmpl);
for (const entry of fs.readdirSync(ROOT, { withFileTypes: true })) {
if (!entry.isDirectory() || entry.name.startsWith('.') || entry.name === 'node_modules') continue;
const tmpl = path.join(ROOT, entry.name, 'SKILL.md.tmpl');
if (fs.existsSync(tmpl)) templates.push(tmpl);
}
return templates;
} }
let hasChanges = false; let hasChanges = false;

View File

@@ -9,34 +9,15 @@
*/ */
import { validateSkill } from '../test/helpers/skill-parser'; import { validateSkill } from '../test/helpers/skill-parser';
import { discoverTemplates, discoverSkillFiles } from './discover-skills';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
const ROOT = path.resolve(import.meta.dir, '..'); const ROOT = path.resolve(import.meta.dir, '..');
// Find all SKILL.md files // Find all SKILL.md files (dynamic discovery — no hardcoded list)
const SKILL_FILES = [ const SKILL_FILES = discoverSkillFiles(ROOT);
'SKILL.md',
'browse/SKILL.md',
'qa/SKILL.md',
'qa-only/SKILL.md',
'ship/SKILL.md',
'review/SKILL.md',
'retro/SKILL.md',
'plan-ceo-review/SKILL.md',
'plan-eng-review/SKILL.md',
'setup-browser-cookies/SKILL.md',
'plan-design-review/SKILL.md',
'design-review/SKILL.md',
'gstack-upgrade/SKILL.md',
'document-release/SKILL.md',
'canary/SKILL.md',
'benchmark/SKILL.md',
'land-and-deploy/SKILL.md',
'setup-deploy/SKILL.md',
'cso/SKILL.md',
].filter(f => fs.existsSync(path.join(ROOT, f)));
let hasErrors = false; let hasErrors = false;
@@ -73,10 +54,7 @@ for (const file of SKILL_FILES) {
// ─── Templates ────────────────────────────────────────────── // ─── Templates ──────────────────────────────────────────────
console.log('\n Templates:'); console.log('\n Templates:');
const TEMPLATES = [ const TEMPLATES = discoverTemplates(ROOT);
{ tmpl: 'SKILL.md.tmpl', output: 'SKILL.md' },
{ tmpl: 'browse/SKILL.md.tmpl', output: 'browse/SKILL.md' },
];
for (const { tmpl, output } of TEMPLATES) { for (const { tmpl, output } of TEMPLATES) {
const tmplPath = path.join(ROOT, tmpl); const tmplPath = path.join(ROOT, tmpl);