MCPcopy
hub / github.com/codeaashu/claude-code / formatAgentAsMarkdown

Function formatAgentAsMarkdown

src/components/agents/agentFileUtils.ts:20–55  ·  view source on GitHub ↗
(
  agentType: string,
  whenToUse: string,
  tools: string[] | undefined,
  systemPrompt: string,
  color?: string,
  model?: string,
  memory?: AgentMemoryScope,
  effort?: EffortValue,
)

Source from the content-addressed store, hash-verified

18 * Formats agent data as markdown file content
19 */
20export 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 `---
49name: ${agentType}
50description: "${escapedWhenToUse}"${toolsLine}${modelLine}${effortLine}${colorLine}${memoryLine}
51---
52
53${systemPrompt}
54`
55}
56
57/**
58 * Gets the directory path for an agent location

Callers 2

saveAgentToFileFunction · 0.85
updateAgentFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected