( agentType: string, whenToUse: string, tools: string[] | undefined, systemPrompt: string, color?: string, model?: string, memory?: AgentMemoryScope, effort?: EffortValue, )
| 18 | * Formats agent data as markdown file content |
| 19 | */ |
| 20 | export function formatAgentAsMarkdown( |
| 21 | agentType: string, |
| 22 | whenToUse: string, |
| 23 | tools: string[] | undefined, |
| 24 | systemPrompt: string, |
| 25 | color?: string, |
| 26 | model?: string, |
| 27 | memory?: AgentMemoryScope, |
| 28 | effort?: EffortValue, |
| 29 | ): string { |
| 30 | // For YAML double-quoted strings, we need to escape: |
| 31 | // - Backslashes: \ -> \\ |
| 32 | // - Double quotes: " -> \" |
| 33 | // - Newlines: \n -> \\n (so yaml reads it as literal backslash-n, not newline) |
| 34 | const escapedWhenToUse = whenToUse |
| 35 | .replace(/\\/g, '\\\\') // Escape backslashes first |
| 36 | .replace(/"/g, '\\"') // Escape double quotes |
| 37 | .replace(/\n/g, '\\\\n') // Escape newlines as \\n so yaml preserves them as \n |
| 38 | |
| 39 | // Omit tools field entirely when tools is undefined or ['*'] (all tools allowed) |
| 40 | const isAllTools = |
| 41 | tools === undefined || (tools.length === 1 && tools[0] === '*') |
| 42 | const toolsLine = isAllTools ? '' : `\ntools: ${tools.join(', ')}` |
| 43 | const modelLine = model ? `\nmodel: ${model}` : '' |
| 44 | const effortLine = effort !== undefined ? `\neffort: ${effort}` : '' |
| 45 | const colorLine = color ? `\ncolor: ${color}` : '' |
| 46 | const memoryLine = memory ? `\nmemory: ${memory}` : '' |
| 47 | |
| 48 | return `--- |
| 49 | name: ${agentType} |
| 50 | description: "${escapedWhenToUse}"${toolsLine}${modelLine}${effortLine}${colorLine}${memoryLine} |
| 51 | --- |
| 52 | |
| 53 | ${systemPrompt} |
| 54 | ` |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Gets the directory path for an agent location |
no outgoing calls
no test coverage detected