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

Method normalize_intent_id

atomic-repository/src/repository/vault_intent.rs:1200–1294  ·  view source on GitHub ↗

Normalize a user-supplied intent reference to its manifest key (the human key `PROJECT::author::seq`). Accepts, filling in the current project and author so the common case is just a number: - `3` -> `PROJECT:: ::3` - `alice::3` -> `PROJECT::alice::3` - `PIMO::alice::3` -> exact (project uppercased) - a ULID or prefix -> resolved to the matching intent's huma

(&self, id: &str)

Source from the content-addressed store, hash-verified

1198 /// produces a `HumanKey` for `::`-separated or all-digit input, so anything
1199 /// else — including `PIMO-1` — arrives here classified as a ULID.
1200 fn normalize_intent_id(&self, id: &str) -> Result<String, RepositoryError> {
1201 use atomic_core::pristine::vault::{parse_intent_reference, IntentRef};
1202
1203 let manifest = self.vault_manifest()?;
1204 let project = manifest.project_code().to_string();
1205 let author = slug_author(&self.resolve_vault_identity().name);
1206
1207 match parse_intent_reference(id, &project, &author) {
1208 IntentRef::HumanKey(key) => {
1209 // Exact manifest key, or a case-insensitive / legacy match.
1210 if manifest.intents.contains_key(&key) {
1211 return Ok(key);
1212 }
1213 if let Some(k) = manifest
1214 .intents
1215 .keys()
1216 .find(|k| k.eq_ignore_ascii_case(&key) || k.eq_ignore_ascii_case(id))
1217 {
1218 return Ok(k.clone());
1219 }
1220 // No entry yet (e.g. freshly composed key): return the composed
1221 // form so callers can still address it.
1222 Ok(key)
1223 }
1224 IntentRef::Uid(uid) => {
1225 // Prefer an exact UID. A prefix is accepted only when it
1226 // identifies exactly one intent.
1227 let mut matches: Vec<_> = manifest
1228 .intents
1229 .values()
1230 .filter(|summary| summary.uid.eq_ignore_ascii_case(&uid))
1231 .collect();
1232 if matches.is_empty() {
1233 let prefix = uid.to_ascii_uppercase();
1234 matches = manifest
1235 .intents
1236 .values()
1237 .filter(|summary| summary.uid.to_ascii_uppercase().starts_with(&prefix))
1238 .collect();
1239 }
1240 matches.sort_by(|a, b| a.uid.cmp(&b.uid));
1241
1242 if matches.len() == 1 {
1243 let summary = matches[0];
1244 return Ok(if summary.human_key.is_empty() {
1245 summary.uid.clone()
1246 } else {
1247 summary.human_key.clone()
1248 });
1249 }
1250 if matches.len() > 1 {
1251 return Err(RepositoryError::AmbiguousIntent {
1252 prefix: id.to_string(),
1253 matches: matches
1254 .into_iter()
1255 .map(|summary| summary.uid.clone())
1256 .collect(),
1257 });

Callers 8

vault_intent_showMethod · 0.80
vault_intent_pathMethod · 0.80
vault_intent_deleteMethod · 0.80
vault_intent_updateMethod · 0.80
vault_intent_linkMethod · 0.80
resolve_intent_keyMethod · 0.80

Calls 12

slug_authorFunction · 0.85
parse_intent_referenceFunction · 0.85
vault_manifestMethod · 0.80
project_codeMethod · 0.80
contains_keyMethod · 0.80
cloneMethod · 0.45
collectMethod · 0.45
is_emptyMethod · 0.45
cmpMethod · 0.45
lenMethod · 0.45
into_iterMethod · 0.45