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

Function lift_intent

atomic-canonical/src/lift.rs:43–169  ·  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

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

Calls 15

slugFunction · 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
attrMethod · 0.80
require_strFunction · 0.70
opt_strFunction · 0.70
parseFunction · 0.70