MCPcopy Create free account
hub / github.com/arctic-cli/interface / loadAgent

Function loadAgent

packages/arctic/src/config/config.ts:205–253  ·  view source on GitHub ↗
(dir: string)

Source from the content-addressed store, hash-verified

203
204 const AGENT_GLOB = new Bun.Glob("{agent,agents}/**/*.md")
205 async function loadAgent(dir: string) {
206 const result: Record<string, Agent> = {}
207
208 for await (const item of AGENT_GLOB.scan({
209 absolute: true,
210 followSymlinks: true,
211 dot: true,
212 cwd: dir,
213 })) {
214 const md = await ConfigMarkdown.parse(item)
215 if (!md.data) continue
216
217 // Extract relative path from agent folder for nested agents
218 let agentName = path.basename(item, ".md")
219 const agentFolderPath = item.includes("/.arctic/agent/")
220 ? item.split("/.arctic/agent/")[1]
221 : item.includes("/.arctic/agents/")
222 ? item.split("/.arctic/agents/")[1]
223 : item.includes("/.opencode/agent/")
224 ? item.split("/.opencode/agent/")[1]
225 : item.includes("/.opencode/agents/")
226 ? item.split("/.opencode/agents/")[1]
227 : item.includes("/agent/")
228 ? item.split("/agent/")[1]
229 : item.includes("/agents/")
230 ? item.split("/agents/")[1]
231 : agentName + ".md"
232
233 // If agent is in a subfolder, include folder path in name
234 if (agentFolderPath.includes("/")) {
235 const relativePath = agentFolderPath.replace(".md", "")
236 const pathParts = relativePath.split("/")
237 agentName = pathParts.slice(0, -1).join("/") + "/" + pathParts[pathParts.length - 1]
238 }
239
240 const config = normalizeClaudeAgentFrontmatter({
241 name: agentName,
242 ...md.data,
243 prompt: md.content.trim(),
244 })
245 const parsed = Agent.safeParse(config)
246 if (parsed.success) {
247 result[config.name] = parsed.data
248 continue
249 }
250 throw new InvalidError({ path: item }, { cause: parsed.error })
251 }
252 return result
253 }
254
255 const MODE_GLOB = new Bun.Glob("mode/*.md")
256 async function loadMode(dir: string) {

Callers 1

config.tsFile · 0.85

Calls 1

Tested by

no test coverage detected