import fs from "node:fs";
import { discoverAgents } from "./discovery.js";
import { parseAgentDocument } from "./manifest.js";
export function loadAgent(projectPath, dataDir, name) {
    const agent = discoverAgents(projectPath, dataDir).find((candidate) => candidate.name === name);
    if (!agent)
        return null;
    const parsed = parseAgentDocument(fs.readFileSync(agent.path, "utf8"));
    return {
        ...agent,
        frontmatter: parsed.frontmatter,
        prompt: parsed.body,
        model: parsed.frontmatter.model ?? "inherit",
        tools: parsed.frontmatter.tools,
        skills: parsed.frontmatter.skills,
    };
}
