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

Method append_reasoning

atomic-agent/src/provenance/accumulator/append.rs:104–170  ·  view source on GitHub ↗

Append a reasoning/thinking node (chain-of-thought from the model). These are created from the reasoning blocks captured by the OpenCode plugin. Each block represents a distinct thinking step where the agent planned its approach, evaluated alternatives, or reasoned about the codebase. The node is classified as `Decision` (the existing kind for strategic choices). Edges link from the current goal

(
        &mut self,
        text: &str,
        duration_ms: Option<u64>,
        signature: Option<&str>,
        timestamp: i64,
    )

Source from the content-addressed store, hash-verified

102 ///
103 /// Returns the new node's ID.
104 pub fn append_reasoning(
105 &mut self,
106 text: &str,
107 duration_ms: Option<u64>,
108 signature: Option<&str>,
109 timestamp: i64,
110 ) -> String {
111 // Truncate for summary: first line or first 100 chars
112 let first_line = text.lines().next().unwrap_or(text);
113 let summary = if first_line.len() > 100 {
114 let truncated: String = first_line.chars().take(97).collect();
115 format!("{}...", truncated)
116 } else {
117 first_line.to_string()
118 };
119
120 let mut node = GraphNode::new(self.next_id(), NodeKind::Decision, timestamp, &summary);
121
122 if let Some(ms) = duration_ms {
123 node = node.with_duration_ms(ms);
124 }
125
126 // Build detail with the full reasoning text and signature
127 let mut detail = serde_json::json!({
128 "reasoning_text": text,
129 });
130 if let Some(ms) = duration_ms {
131 detail["reasoning_duration_ms"] = serde_json::Value::Number(ms.into());
132 }
133 if let Some(sig) = signature {
134 detail["anthropic_signature"] = serde_json::Value::String(sig.to_string());
135 }
136 detail["text_length"] = serde_json::Value::Number(text.len().into());
137 node.detail = Some(detail);
138
139 // Mark as classified so the Phase 3 consolidator doesn't touch it
140 node.classified = true;
141 node.confidence = Some(1.0);
142
143 let node_id = node.id.clone();
144
145 // Edge: goal --led_to-→ reasoning (if we have a current goal)
146 if let Some(ref goal) = self.current_goal {
147 self.edges.push(GraphEdge::new(
148 goal.clone(),
149 node_id.clone(),
150 EdgeKind::LedTo,
151 ));
152 self.stats.edge_count += 1;
153 }
154
155 // Also chain from previous node for temporal ordering
156 if let Some(ref prev) = self.last_node {
157 // Only add led_to if previous wasn't already the goal
158 if self.current_goal.as_ref() != Some(prev) {
159 self.edges.push(GraphEdge::new(
160 prev.clone(),
161 node_id.clone(),

Callers 2

Calls 10

next_idMethod · 0.80
with_duration_msMethod · 0.80
as_refMethod · 0.80
push_nodeMethod · 0.80
nextMethod · 0.45
linesMethod · 0.45
lenMethod · 0.45
collectMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected