xonecas.io
64875
Mc

mini-coder / commit f462acf

feat(skills): support nested YAML frontmatter and surface compatibility field

- Frontmatter parser now handles one level of nesting (e.g. metadata:
  with indented sub-keys) instead of flattening them as top-level keys
- Added type-safe extraction in parseSkillFrontmatter to handle mixed
  string/object values from the updated parser
- Added compatibility field to SkillMeta, surfaced in system prompt
  catalog and listSkills tool output
- Added tests for nested metadata parsing, compatibility field
  presence/absence

xonecas2026-03-21 f462acf01b3d8fae4bf72931d1bac8cfe05d1bf8 parent bf34c34

6 files changed

src/agent/system-prompt.ts+2−1
@@ -111,7 +111,8 @@ Apply one safe exact-text edit to an existing file.
111111 prompt +=
112112 '\nFor complex skills that would clutter your context, consider delegating to a subagent via `mc "prompt"` in the shell tool.\n';
113113 for (const skill of skills) {
114- prompt += `\n- ${skill.name}: ${skill.description} (${skill.source}, ${skill.filePath})`;
114+ const compat = skill.compatibility ? ` [${skill.compatibility}]` : "";
115+ prompt += `\n- ${skill.name}: ${skill.description}${compat} (${skill.source}, ${skill.filePath})`;
115116 }
116117 }
117118
src/cli/frontmatter.test.ts+25−0
@@ -45,4 +45,29 @@ describe("parseFrontmatter", () => {
4545 body: raw,
4646 });
4747 });
48+
49+ test("parses nested metadata as a sub-object", () => {
50+ const raw =
51+ '---\nname: pdf-tool\ndescription: Handles PDFs\nmetadata:\n author: example-org\n version: "1.0"\n---\n\nBody';
52+ expect(parseFrontmatter(raw)).toEqual({
53+ meta: {
54+ name: "pdf-tool",
55+ description: "Handles PDFs",
56+ metadata: { author: "example-org", version: "1.0" },
57+ },
58+ body: "Body",
59+ });
60+ });
61+
62+ test("handles empty nested block followed by a top-level key", () => {
63+ const raw =
64+ "---\nmetadata:\n key: val\ncompatibility: Requires git\n---\n\nEnd";
65+ expect(parseFrontmatter(raw)).toEqual({
66+ meta: {
67+ metadata: { key: "val" },
68+ compatibility: "Requires git",
69+ },
70+ body: "End",
71+ });
72+ });
4873 });
src/cli/frontmatter.ts+40−9
@@ -2,28 +2,59 @@
22
33 const FM_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
44
5+type FrontmatterValue = string | Record<string, string>;
6+
57 /**
68 * Parse simple YAML-like frontmatter from a text string.
7- * Returns key-value pairs (string values only) and the body after the closing `---`.
9+ * Supports one level of nesting (e.g. `metadata:` with indented sub-keys).
10+ * Returns key-value pairs and the body after the closing `---`.
811 */
912 export function parseFrontmatter(raw: string): {
10- meta: Record<string, string>;
13+ meta: Record<string, FrontmatterValue>;
1114 body: string;
1215 } {
1316 const m = raw.match(FM_RE);
1417 if (!m) return { meta: {}, body: raw };
1518
16- const meta: Record<string, string> = {};
17- const yamlBlock = m[1] ?? "";
18- for (const line of yamlBlock.split("\n")) {
19- const colon = line.indexOf(":");
19+ const meta: Record<string, FrontmatterValue> = {};
20+ const lines = (m[1] ?? "").split("\n");
21+ let parentKey = "";
22+
23+ for (const line of lines) {
24+ const stripped = line.replace(/\r$/, "");
25+ const indent = stripped.length - stripped.trimStart().length;
26+
27+ if (indent > 0 && parentKey) {
28+ const colon = stripped.indexOf(":");
29+ if (colon === -1) continue;
30+ const key = stripped.slice(0, colon).trim();
31+ const val = stripped
32+ .slice(colon + 1)
33+ .trim()
34+ .replace(/^["']|["']$/g, "");
35+ if (!key) continue;
36+ const parent = meta[parentKey];
37+ if (typeof parent === "object") parent[key] = val;
38+ else meta[parentKey] = { [key]: val };
39+ continue;
40+ }
41+
42+ const colon = stripped.indexOf(":");
2043 if (colon === -1) continue;
21- const key = line.slice(0, colon).trim();
22- const val = line
44+ const key = stripped.slice(0, colon).trim();
45+ const val = stripped
2346 .slice(colon + 1)
2447 .trim()
2548 .replace(/^["']|["']$/g, "");
26- if (key) meta[key] = val;
49+ if (!key) continue;
50+
51+ if (val === "") {
52+ parentKey = key;
53+ meta[key] = {};
54+ } else {
55+ parentKey = "";
56+ meta[key] = val;
57+ }
2758 }
2859
2960 return { meta, body: (m[2] ?? "").trim() };
src/cli/skills.test.ts+23−0
@@ -287,4 +287,27 @@ describe("skills loader", () => {
287287 expect(skill).toBeDefined();
288288 expect(skill?.context).toBeUndefined();
289289 });
290+
291+ test("parses compatibility field from frontmatter", () => {
292+ writeSkill(
293+ dir,
294+ ".agents",
295+ "deploy-skill",
296+ "---\nname: deploy-skill\ndescription: Deploy things\ncompatibility: Requires docker and git\n---\ncontent",
297+ );
298+ const index = loadSkillsIndex(dir, fakeHome);
299+ const skill = index.get("deploy-skill");
300+ expect(skill?.compatibility).toBe("Requires docker and git");
301+ });
302+
303+ test("compatibility is undefined when not specified", () => {
304+ writeSkill(
305+ dir,
306+ ".agents",
307+ "plain-skill",
308+ "---\nname: plain-skill\ndescription: No compat\n---\ncontent",
309+ );
310+ const index = loadSkillsIndex(dir, fakeHome);
311+ expect(index.get("plain-skill")?.compatibility).toBeUndefined();
312+ });
290313 });
src/cli/skills.ts+10−3
@@ -20,6 +20,7 @@ export interface SkillMeta {
2020 rootPath: string;
2121 filePath: string;
2222 context?: "fork";
23+ compatibility?: string;
2324 }
2425
2526 export interface LoadedSkillContent {
@@ -48,6 +49,7 @@ type SkillFrontmatter = {
4849 name?: string;
4950 description?: string;
5051 context?: string;
52+ compatibility?: string;
5153 };
5254
5355 function parseSkillFrontmatter(filePath: string): SkillFrontmatter {
@@ -59,9 +61,13 @@ function parseSkillFrontmatter(filePath: string): SkillFrontmatter {
5961 const text = chunk.toString("utf8", 0, bytesRead);
6062 const { meta } = parseFrontmatter(text);
6163 const result: SkillFrontmatter = {};
62- if (meta.name) result.name = meta.name;
63- if (meta.description) result.description = meta.description;
64- if (meta.context) result.context = meta.context;
64+ if (typeof meta.name === "string" && meta.name) result.name = meta.name;
65+ if (typeof meta.description === "string" && meta.description)
66+ result.description = meta.description;
67+ if (typeof meta.context === "string" && meta.context)
68+ result.context = meta.context;
69+ if (typeof meta.compatibility === "string" && meta.compatibility)
70+ result.compatibility = meta.compatibility;
6571 return result;
6672 } catch {
6773 return {};
@@ -233,6 +239,7 @@ function validateSkill(candidate: SkillCandidate): SkillMeta | null {
233239 rootPath: candidate.rootPath,
234240 filePath: candidate.filePath,
235241 ...(meta.context === "fork" && { context: "fork" as const }),
242+ ...(meta.compatibility && { compatibility: meta.compatibility }),
236243 };
237244 }
238245
src/tools/skills.ts+7−1
@@ -11,7 +11,12 @@ const ListSkillsSchema = z.object({});
1111 type ListSkillsInput = { cwd?: string };
1212
1313 interface ListSkillsOutput {
14- skills: Array<Pick<SkillMeta, "name" | "description" | "source" | "context">>;
14+ skills: Array<
15+ Pick<
16+ SkillMeta,
17+ "name" | "description" | "source" | "context" | "compatibility"
18+ >
19+ >;
1520 }
1621
1722 export const listSkillsTool: ToolDef<ListSkillsInput, ListSkillsOutput> = {
@@ -26,6 +31,7 @@ export const listSkillsTool: ToolDef<ListSkillsInput, ListSkillsOutput> = {
2631 description: skill.description,
2732 source: skill.source,
2833 ...(skill.context && { context: skill.context }),
34+ ...(skill.compatibility && { compatibility: skill.compatibility }),
2935 }));
3036 return { skills };
3137 },