frontmatter in skills files
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user