( filePath: string, pluginName: string, loadedPaths: Set<string>, )
| 34 | } |
| 35 | |
| 36 | async function loadOutputStyleFromFile( |
| 37 | filePath: string, |
| 38 | pluginName: string, |
| 39 | loadedPaths: Set<string>, |
| 40 | ): Promise<OutputStyleConfig | null> { |
| 41 | const fs = getFsImplementation() |
| 42 | if (isDuplicatePath(fs, filePath, loadedPaths)) { |
| 43 | return null |
| 44 | } |
| 45 | try { |
| 46 | const content = await fs.readFile(filePath, { encoding: 'utf-8' }) |
| 47 | const { frontmatter, content: markdownContent } = parseFrontmatter( |
| 48 | content, |
| 49 | filePath, |
| 50 | ) |
| 51 | |
| 52 | const fileName = basename(filePath, '.md') |
| 53 | const baseStyleName = (frontmatter.name as string) || fileName |
| 54 | // Namespace output styles with plugin name, consistent with commands and agents |
| 55 | const name = `${pluginName}:${baseStyleName}` |
| 56 | const description = |
| 57 | coerceDescriptionToString(frontmatter.description, name) ?? |
| 58 | extractDescriptionFromMarkdown( |
| 59 | markdownContent, |
| 60 | `Output style from ${pluginName} plugin`, |
| 61 | ) |
| 62 | |
| 63 | // Parse forceForPlugin flag (supports both boolean and string values) |
| 64 | const forceRaw = frontmatter['force-for-plugin'] |
| 65 | const forceForPlugin = |
| 66 | forceRaw === true || forceRaw === 'true' |
| 67 | ? true |
| 68 | : forceRaw === false || forceRaw === 'false' |
| 69 | ? false |
| 70 | : undefined |
| 71 | |
| 72 | return { |
| 73 | name, |
| 74 | description, |
| 75 | prompt: markdownContent.trim(), |
| 76 | source: 'plugin', |
| 77 | forceForPlugin, |
| 78 | } |
| 79 | } catch (error) { |
| 80 | logForDebugging(`Failed to load output style from ${filePath}: ${error}`, { |
| 81 | level: 'error', |
| 82 | }) |
| 83 | return null |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | export const loadPluginOutputStyles = memoize( |
| 88 | async (): Promise<OutputStyleConfig[]> => { |
no test coverage detected