MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / parse_markdown_command

Function parse_markdown_command

crates/opencode-config/src/loader.rs:709–726  ·  view source on GitHub ↗

Parse a markdown file as a command definition. Extracts YAML frontmatter and body content.

(path: &Path, base_dir: &Path)

Source from the content-addressed store, hash-verified

707/// Parse a markdown file as a command definition.
708/// Extracts YAML frontmatter and body content.
709fn parse_markdown_command(path: &Path, base_dir: &Path) -> Option<(String, CommandConfig)> {
710 let content = fs::read_to_string(path).ok()?;
711 let (frontmatter, body) = split_frontmatter(&content);
712
713 // Derive name from relative path
714 let name = derive_name_from_path(path, base_dir, &["command", "commands"]);
715
716 let mut config = if let Some(fm) = frontmatter {
717 serde_json::from_value::<CommandConfig>(serde_yaml_frontmatter_to_json(&fm))
718 .unwrap_or_default()
719 } else {
720 CommandConfig::default()
721 };
722
723 config.template = Some(body.trim().to_string());
724
725 Some((name, config))
726}
727
728/// Parse a markdown file as an agent definition.
729fn parse_markdown_agent(path: &Path, base_dir: &Path) -> Option<(String, AgentConfig)> {

Calls 3

split_frontmatterFunction · 0.85
derive_name_from_pathFunction · 0.85