frontmatter in skills files

This commit is contained in:
2026-02-18 01:23:22 +00:00
parent 030cf9fbd3
commit c2660cd125
16 changed files with 959 additions and 506 deletions
+5 -4
View File
@@ -8,9 +8,9 @@ type Frontmatter = {
description: string;
};
export function parseFrontmatter(raw: string): { frontmatter: Frontmatter; body: string } {
export function parseFrontmatter(raw: string): { frontmatter: Frontmatter; body: string; rawYaml: string } {
const match = raw.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
if (!match) return { frontmatter: { name: '', description: '' }, body: raw };
if (!match) return { frontmatter: { name: '', description: '' }, body: raw, rawYaml: '' };
const yaml = match[1]!;
const body = match[2]!;
@@ -18,7 +18,7 @@ export function parseFrontmatter(raw: string): { frontmatter: Frontmatter; body:
const name = yaml.match(/^name:\s*(.+)$/m)?.[1]?.trim() ?? '';
const description = yaml.match(/^description:\s*(.+)$/m)?.[1]?.trim() ?? '';
return { frontmatter: { name, description }, body };
return { frontmatter: { name, description }, body, rawYaml: yaml };
}
export async function readProcessDirs(dir: string): Promise<Map<string, string>> {
@@ -89,7 +89,7 @@ processesRouter.get('/:name', async (ctx) => {
if (!resolved) return ctx.text('Not found', 404);
const raw = await Bun.file(resolved.filePath).text();
const { frontmatter, body } = parseFrontmatter(raw);
const { frontmatter, body, rawYaml } = parseFrontmatter(raw);
const chatMeta = join(dirname(resolved.filePath), 'chat', 'meta.json');
const chatSessionId = await Bun.file(chatMeta).json().then((m: { id: string }) => m.id).catch(() => null);
@@ -99,6 +99,7 @@ processesRouter.get('/:name', async (ctx) => {
description: frontmatter.description,
scope: resolved.scope,
body,
rawFrontmatter: rawYaml,
filePath: resolved.filePath,
chatSessionId,
});