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

Function parse_intent_reference

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

392/// - `PIMO::lee::3` -> `HumanKey("PIMO::lee::3")` (exact, project uppercased)
393/// - otherwise -> `Uid(<input uppercased>)` (a ULID or its prefix)
394pub fn parse_intent_reference(
395 input: &str,
396 default_project: &str,
397 default_author: &str,
398) -> IntentRef {
399 let t = input.trim();
400
401 if t.contains(HUMAN_KEY_SEP) {
402 let parts: Vec<&str> = t.split(HUMAN_KEY_SEP).collect();
403 return match parts.len() {
404 3 => IntentRef::HumanKey(VaultManifest::compose_human_key(
405 parts[0],
406 parts[1],
407 parts[2].parse().unwrap_or(0),
408 )),
409 2 => IntentRef::HumanKey(VaultManifest::compose_human_key(
410 default_project,
411 parts[0],
412 parts[1].parse().unwrap_or(0),
413 )),
414 _ => IntentRef::HumanKey(t.to_string()),
415 };
416 }
417
418 // A bare sequence number resolves to the current project + author.
419 if !t.is_empty() && t.chars().all(|c| c.is_ascii_digit()) {
420 return IntentRef::HumanKey(VaultManifest::compose_human_key(
421 default_project,
422 default_author,
423 t.parse().unwrap_or(0),
424 ));
425 }
426
427 // Anything else is treated as a ULID (or a ULID prefix). ULIDs are
428 // Crockford base32 and canonically uppercase.
429 IntentRef::Uid(t.to_uppercase())
430}
431
432// ── Knowledge Graph ─────────────────────────────────────────────
433

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