| 235 | } |
| 236 | |
| 237 | async function stampSource(skillFile: string, source: string): Promise<void> { |
| 238 | const raw = await fs.readFile(skillFile, 'utf-8'); |
| 239 | if (/^source\s*:/m.test(raw)) return; |
| 240 | // Inject `source:` inside the existing frontmatter block, just before `---`. |
| 241 | const m = raw.match(/^---\s*\n([\s\S]*?)\n---\s*\r?\n?([\s\S]*)$/); |
| 242 | if (!m) return; |
| 243 | const newFm = (m[1] ?? '').trimEnd() + `\nsource: ${source}\n`; |
| 244 | const next = `---\n${newFm}---\n${m[2] ?? ''}`; |
| 245 | await fs.writeFile(skillFile, next); |
| 246 | } |
| 247 | |
| 248 | export async function removeSkill(name: string): Promise<void> { |
| 249 | if (!NAME_RE.test(name)) throw new Error(`Invalid skill name "${name}".`); |