MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / parseFrontmatter

Function parseFrontmatter

internal/metadata/discover.go:221–247  ·  view source on GitHub ↗

parseFrontmatter extracts name and description from a leading YAML frontmatter block delimited by "---" lines. It is intentionally minimal: only flat "key: value" pairs are supported, which covers SKILL.md/AGENT.md.

(content string)

Source from the content-addressed store, hash-verified

219// frontmatter block delimited by "---" lines. It is intentionally minimal:
220// only flat "key: value" pairs are supported, which covers SKILL.md/AGENT.md.
221func parseFrontmatter(content string) (name, description string, ok bool) {
222 content = strings.ReplaceAll(content, "\r\n", "\n")
223 if !strings.HasPrefix(content, "---\n") {
224 return "", "", false
225 }
226 end := strings.Index(content[4:], "\n---")
227 if end < 0 {
228 return "", "", false
229 }
230 block := content[4 : 4+end]
231 for _, line := range strings.Split(block, "\n") {
232 key, value, found := strings.Cut(line, ":")
233 if !found {
234 continue
235 }
236 key = strings.TrimSpace(strings.ToLower(key))
237 value = strings.TrimSpace(value)
238 value = strings.Trim(value, "\"'")
239 switch key {
240 case "name":
241 name = value
242 case "description":
243 description = value
244 }
245 }
246 return name, description, true
247}
248
249// parsePluginJSON extracts name/description from a plugin.json manifest.
250func parsePluginJSON(path, fallbackName string) (name, description string) {

Callers 3

parseManifestFunction · 0.85
TestParseFrontmatterFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseFrontmatterFunction · 0.68