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

Function parse_intent_reference

atomic-core/src/pristine/vault.rs:442–478  ·  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

440/// - `PIMO::lee::3` -> `HumanKey("PIMO::lee::3")` (exact, project uppercased)
441/// - otherwise -> `Uid(<input uppercased>)` (a ULID or its prefix)
442pub fn parse_intent_reference(
443 input: &str,
444 default_project: &str,
445 default_author: &str,
446) -> IntentRef {
447 let t = input.trim();
448
449 if t.contains(HUMAN_KEY_SEP) {
450 let parts: Vec<&str> = t.split(HUMAN_KEY_SEP).collect();
451 return match parts.len() {
452 3 => IntentRef::HumanKey(VaultManifest::compose_human_key(
453 parts[0],
454 parts[1],
455 parts[2].parse().unwrap_or(0),
456 )),
457 2 => IntentRef::HumanKey(VaultManifest::compose_human_key(
458 default_project,
459 parts[0],
460 parts[1].parse().unwrap_or(0),
461 )),
462 _ => IntentRef::HumanKey(t.to_string()),
463 };
464 }
465
466 // A bare sequence number resolves to the current project + author.
467 if !t.is_empty() && t.chars().all(|c| c.is_ascii_digit()) {
468 return IntentRef::HumanKey(VaultManifest::compose_human_key(
469 default_project,
470 default_author,
471 t.parse().unwrap_or(0),
472 ));
473 }
474
475 // Anything else is treated as a ULID (or a ULID prefix). ULIDs are
476 // Crockford base32 and canonically uppercase.
477 IntentRef::Uid(t.to_uppercase())
478}
479
480// ── Knowledge Graph ─────────────────────────────────────────────
481

Callers 1

normalize_intent_idMethod · 0.85

Calls 6

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

Tested by

no test coverage detected