MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / frontmatter_metadata

Function frontmatter_metadata

atomic-cli/src/commands/diagnostics/collect.rs:1111–1190  ·  view source on GitHub ↗
(text: &str)

Source from the content-addressed store, hash-verified

1109}
1110
1111fn frontmatter_metadata(text: &str) -> SkillMetadata {
1112 use serde_yaml_ng::Value;
1113
1114 fn key(name: &str) -> Value {
1115 Value::String(name.to_string())
1116 }
1117 fn string(value: Option<&Value>) -> Result<Option<String>, ()> {
1118 match value {
1119 None | Some(Value::Null) => Ok(None),
1120 Some(Value::String(value)) if value.trim().is_empty() => Ok(None),
1121 Some(Value::String(value)) if !value.chars().any(char::is_control) => {
1122 Ok(Some(value.trim().to_string()))
1123 }
1124 _ => Err(()),
1125 }
1126 }
1127 let incomplete = || SkillMetadata {
1128 version: None,
1129 updated_at: None,
1130 status: SkillMetadataStatus::Incomplete,
1131 missing: vec!["metadata.version", "metadata.updatedAt"],
1132 };
1133 let mut lines = text.lines();
1134 if lines.next().map(str::trim_end) != Some("---") {
1135 return incomplete();
1136 }
1137 let mut yaml = String::new();
1138 let mut closed = false;
1139 for line in lines {
1140 if line.trim_end() == "---" {
1141 closed = true;
1142 break;
1143 }
1144 yaml.push_str(line);
1145 yaml.push('\n');
1146 }
1147 if !closed {
1148 return SkillMetadata::invalid();
1149 }
1150 let root = match serde_yaml_ng::from_str(&yaml) {
1151 Ok(Value::Null) => return incomplete(),
1152 Ok(Value::Mapping(root)) => root,
1153 _ => return SkillMetadata::invalid(),
1154 };
1155 let legacy_version = string(root.get(key("version"))).unwrap_or(None);
1156 let metadata = match root.get(key("metadata")) {
1157 None | Some(Value::Null) => {
1158 return SkillMetadata {
1159 version: legacy_version,
1160 ..incomplete()
1161 };
1162 }
1163 Some(Value::Mapping(metadata)) => metadata,
1164 _ => return SkillMetadata::invalid(),
1165 };
1166 let (version, updated_at) = match (
1167 string(metadata.get(key("version"))),
1168 string(metadata.get(key("updatedAt"))),

Calls 9

stringFunction · 0.85
keyFunction · 0.85
is_noneMethod · 0.80
getMethod · 0.65
invalidFunction · 0.50
linesMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45
is_emptyMethod · 0.45