frontmatter in skills files
This commit is contained in:
@@ -11,9 +11,9 @@ type Frontmatter = {
|
||||
triggers: TriggerConfig[];
|
||||
};
|
||||
|
||||
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: '', triggers: [] }, body: raw };
|
||||
if (!match) return { frontmatter: { name: '', description: '', triggers: [] }, body: raw, rawYaml: '' };
|
||||
|
||||
const yaml = match[1]!;
|
||||
const body = match[2]!;
|
||||
@@ -38,7 +38,7 @@ export function parseFrontmatter(raw: string): { frontmatter: Frontmatter; body:
|
||||
}
|
||||
}
|
||||
|
||||
return { frontmatter: { name, description, triggers }, body };
|
||||
return { frontmatter: { name, description, triggers }, body, rawYaml: yaml };
|
||||
}
|
||||
|
||||
export async function readTaskDirs(dir: string): Promise<Map<string, string>> {
|
||||
@@ -116,7 +116,7 @@ tasksRouter.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);
|
||||
@@ -126,6 +126,7 @@ tasksRouter.get('/:name', async (ctx) => {
|
||||
description: frontmatter.description,
|
||||
scope: resolved.scope,
|
||||
body,
|
||||
rawFrontmatter: rawYaml,
|
||||
filePath: resolved.filePath,
|
||||
chatSessionId,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user