Parse an agent markdown file.
(agent_path: Path)
| 119 | |
| 120 | |
| 121 | def parse_agent(agent_path: Path) -> ParsedAgent: |
| 122 | """Parse an agent markdown file.""" |
| 123 | content = agent_path.read_text(encoding="utf-8") |
| 124 | frontmatter, body = _split_frontmatter(content) |
| 125 | |
| 126 | tools_raw = frontmatter.get("tools", "") |
| 127 | if isinstance(tools_raw, list): |
| 128 | tools = [str(t).strip() for t in tools_raw] |
| 129 | elif isinstance(tools_raw, str) and tools_raw: |
| 130 | tools = [t.strip() for t in tools_raw.split(",")] |
| 131 | else: |
| 132 | tools = [] |
| 133 | |
| 134 | description = frontmatter.get("description", "") |
| 135 | has_proactive = bool(re.search(r"use proactively", description, re.IGNORECASE)) |
| 136 | |
| 137 | skill_refs = re.findall(r"(?:skill|skills)/([a-z0-9-]+)", body) |
| 138 | |
| 139 | return ParsedAgent( |
| 140 | path=agent_path, |
| 141 | name=frontmatter.get("name", agent_path.stem), |
| 142 | description=description, |
| 143 | model=frontmatter.get("model"), |
| 144 | has_tools_restriction=bool(tools), |
| 145 | tools=tools, |
| 146 | has_proactive_trigger=has_proactive, |
| 147 | skill_references=skill_refs, |
| 148 | raw_content=content, |
| 149 | frontmatter=frontmatter, |
| 150 | ) |
| 151 | |
| 152 | |
| 153 | def parse_plugin(plugin_dir: Path) -> ParsedPlugin: |