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

Function saveAgentToFile

src/components/agents/agentFileUtils.ts:166–203  ·  view source on GitHub ↗
(
  source: SettingSource | 'built-in',
  agentType: string,
  whenToUse: string,
  tools: string[] | undefined,
  systemPrompt: string,
  checkExists = true,
  color?: string,
  model?: string,
  memory?: AgentMemoryScope,
  effort?: EffortValue,
)

Source from the content-addressed store, hash-verified

164 * @param checkExists - If true, throws error if file already exists
165 */
166export async function saveAgentToFile(
167 source: SettingSource | 'built-in',
168 agentType: string,
169 whenToUse: string,
170 tools: string[] | undefined,
171 systemPrompt: string,
172 checkExists = true,
173 color?: string,
174 model?: string,
175 memory?: AgentMemoryScope,
176 effort?: EffortValue,
177): Promise<void> {
178 if (source === 'built-in') {
179 throw new Error('Cannot save built-in agents')
180 }
181
182 await ensureAgentDirectoryExists(source)
183 const filePath = getNewAgentFilePath({ source, agentType })
184
185 const content = formatAgentAsMarkdown(
186 agentType,
187 whenToUse,
188 tools,
189 systemPrompt,
190 color,
191 model,
192 memory,
193 effort,
194 )
195 try {
196 await writeFileAndFlush(filePath, content, checkExists ? 'wx' : 'w')
197 } catch (e: unknown) {
198 if (getErrnoCode(e) === 'EEXIST') {
199 throw new Error(`Agent file already exists: ${filePath}`)
200 }
201 throw e
202 }
203}
204
205/**
206 * Updates an existing agent file

Callers 1

ConfirmStepWrapperFunction · 0.85

Calls 5

getNewAgentFilePathFunction · 0.85
formatAgentAsMarkdownFunction · 0.85
writeFileAndFlushFunction · 0.85
getErrnoCodeFunction · 0.85

Tested by

no test coverage detected