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