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

Function parse_intent_reference

atomic-core/src/pristine/vault.rs:417–453  ·  view source on GitHub ↗

Resolve a user-supplied intent reference into a [`IntentRef`], filling in the current project and author so the common case is just a number. Rules (the project is never required from the user): - `3` -> `HumanKey(" :: ::3")` - `alice::3` -> `HumanKey(" ::alice::3")` (other teammate) - `PIMO::lee::3` -> `HumanKey("PIMO::lee::3")` (exact, project uppercased) -

(
    input: &str,
    default_project: &str,
    default_author: &str,
)

Source from the content-addressed store, hash-verified

415/// - `PIMO::lee::3` -> `HumanKey("PIMO::lee::3")` (exact, project uppercased)
416/// - otherwise -> `Uid(<input uppercased>)` (a ULID or its prefix)
417pub fn parse_intent_reference(
418 input: &str,
419 default_project: &str,
420 default_author: &str,
421) -> IntentRef {
422 let t = input.trim();
423
424 if t.contains(HUMAN_KEY_SEP) {
425 let parts: Vec<&str> = t.split(HUMAN_KEY_SEP).collect();
426 return match parts.len() {
427 3 => IntentRef::HumanKey(VaultManifest::compose_human_key(
428 parts[0],
429 parts[1],
430 parts[2].parse().unwrap_or(0),
431 )),
432 2 => IntentRef::HumanKey(VaultManifest::compose_human_key(
433 default_project,
434 parts[0],
435 parts[1].parse().unwrap_or(0),
436 )),
437 _ => IntentRef::HumanKey(t.to_string()),
438 };
439 }
440
441 // A bare sequence number resolves to the current project + author.
442 if !t.is_empty() && t.chars().all(|c| c.is_ascii_digit()) {
443 return IntentRef::HumanKey(VaultManifest::compose_human_key(
444 default_project,
445 default_author,
446 t.parse().unwrap_or(0),
447 ));
448 }
449
450 // Anything else is treated as a ULID (or a ULID prefix). ULIDs are
451 // Crockford base32 and canonically uppercase.
452 IntentRef::Uid(t.to_uppercase())
453}
454
455// ── Knowledge Graph ─────────────────────────────────────────────
456

Callers 1

normalize_intent_idMethod · 0.85

Calls 5

containsMethod · 0.45
lenMethod · 0.45
parseMethod · 0.45
is_emptyMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected