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

Function lift_intent

atomic-canonical/src/lift.rs:41–145  ·  view source on GitHub ↗

Lift an intent from its frontmatter spine and markdown body.

(frontmatter: &Map<String, Value>, body: &str)

Source from the content-addressed store, hash-verified

39
40/// Lift an intent from its frontmatter spine and markdown body.
41pub fn lift_intent(frontmatter: &Map<String, Value>, body: &str) -> Result<CanonicalNode> {
42 directive::check_embedded_directives(body)?;
43 let human_key = require_str(frontmatter, "id")?;
44 let uid = opt_str(frontmatter, "uid").unwrap_or_else(|| slug(&human_key));
45 let node_id = format!("urn:atomic:intent:{uid}");
46
47 let directives = directive::parse(body)?;
48
49 let mut why = None;
50 let mut acs = Vec::new();
51 let mut tasks = Vec::new();
52 let mut scope_in = Vec::new();
53 let mut scope_out = Vec::new();
54 let mut constraints = Vec::new();
55 let mut deps = Vec::new();
56 let mut ac_n = 0usize;
57 let mut task_n = 0usize;
58 let mut scope_in_n = 0usize;
59 let mut scope_out_n = 0usize;
60 let mut constraint_n = 0usize;
61
62 for d in &directives {
63 // Inline (and nested-leaf) `:ref` children of any container sit on the
64 // intent's dependency chain, same rules as a top-level `:::ref`. The
65 // container prose keeps the inline mention verbatim.
66 for child in &d.children {
67 if child.name == "ref" {
68 deps.push(lift_ref(child)?);
69 }
70 }
71 match d.name.as_str() {
72 "why" => {
73 // Single authoring site: first `:::why` wins; the reason is
74 // unconstrained prose, lifted verbatim, never inspected.
75 if why.is_none() {
76 why = Some(d.body.clone());
77 }
78 }
79 "acceptance-criterion" => {
80 ac_n += 1;
81 acs.push(lift_ac(d, &uid, ac_n)?);
82 }
83 "task" => {
84 task_n += 1;
85 tasks.push(lift_task(d, &uid, task_n));
86 }
87 "scope-in" => {
88 scope_in_n += 1;
89 scope_in.push(lift_scope(d, &uid, "scope-in", scope_in_n));
90 }
91 "scope-out" => {
92 scope_out_n += 1;
93 scope_out.push(lift_scope(d, &uid, "scope-out", scope_out_n));
94 }
95 "constraint" => {
96 constraint_n += 1;
97 constraints.push(lift_constraint(d, &uid, constraint_n));
98 }

Calls 15

slugFunction · 0.85
parseFunction · 0.85
lift_refFunction · 0.85
lift_acFunction · 0.85
lift_taskFunction · 0.85
lift_scopeFunction · 0.85
lift_constraintFunction · 0.85
is_noneMethod · 0.80
require_strFunction · 0.70
opt_strFunction · 0.70
str_arrayFunction · 0.70