11import fs from "fs/promises"
22import * as path from "path"
33import { Dirent } from "fs"
4- import matter from "gray-matter "
4+ import { parseFrontmatter } from "../../utils/safeFrontmatter "
55import { getGlobalRooDirectory , getProjectRooDirectoryForCwd } from "../roo-config"
66import { getBuiltInCommands , getBuiltInCommand } from "./built-in-commands"
77
@@ -10,19 +10,6 @@ import { getBuiltInCommands, getBuiltInCommand } from "./built-in-commands"
1010 */
1111const MAX_DEPTH = 5
1212
13- /** Parse command metadata only after rejecting document-selected executable engines. */
14- function parseCommandFrontmatter ( content : string ) {
15- // gray-matter strips a leading BOM before detecting the opening delimiter.
16- const input = content . replace ( / ^ \uFEFF / , "" )
17- if ( matter . test ( input ) ) {
18- const { name : language } = matter . language ( input )
19- if ( language && ! [ "yaml" , "yml" , "json" ] . includes ( language . toLowerCase ( ) ) ) {
20- throw new Error ( `Unsupported command frontmatter language: ${ language } ` )
21- }
22- }
23- return matter ( content )
24- }
25-
2613export interface Command {
2714 name : string
2815 content : string
@@ -234,7 +221,7 @@ async function tryLoadCommand(
234221
235222 try {
236223 // Try to parse frontmatter with gray-matter
237- parsed = parseCommandFrontmatter ( content )
224+ parsed = parseFrontmatter ( content )
238225 description =
239226 typeof parsed . data . description === "string" && parsed . data . description . trim ( )
240227 ? parsed . data . description . trim ( )
@@ -319,7 +306,7 @@ async function scanCommandDirectory(
319306
320307 try {
321308 // Try to parse frontmatter with gray-matter
322- parsed = parseCommandFrontmatter ( content )
309+ parsed = parseFrontmatter ( content )
323310 description =
324311 typeof parsed . data . description === "string" && parsed . data . description . trim ( )
325312 ? parsed . data . description . trim ( )
0 commit comments