MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / parse_skill_file

Function parse_skill_file

crates/opencode-tool/src/skill.rs:121–154  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

119}
120
121fn parse_skill_file(path: &Path) -> Option<SkillInfo> {
122 let raw = fs::read_to_string(path).ok()?;
123 let normalized = raw.replace("\r\n", "\n");
124 let mut lines = normalized.lines();
125
126 if lines.next()?.trim() != "---" {
127 return None;
128 }
129
130 let mut frontmatter_lines = Vec::new();
131 let mut closed = false;
132 for line in lines.by_ref() {
133 if line.trim() == "---" {
134 closed = true;
135 break;
136 }
137 frontmatter_lines.push(line);
138 }
139 if !closed {
140 return None;
141 }
142
143 let frontmatter = frontmatter_lines.join("\n");
144 let content = lines.collect::<Vec<_>>().join("\n");
145 let name = parse_frontmatter_value(&frontmatter, "name")?;
146 let description = parse_frontmatter_value(&frontmatter, "description")?;
147
148 Some(SkillInfo {
149 name,
150 description,
151 content: content.trim().to_string(),
152 location: path.to_path_buf(),
153 })
154}
155
156fn scan_skill_root(root: &Path) -> Vec<SkillInfo> {
157 if !root.exists() || !root.is_dir() {

Callers 2

scan_skill_rootFunction · 0.85

Calls 3

newFunction · 0.85
parse_frontmatter_valueFunction · 0.85
replaceMethod · 0.80