diff --git a/src/mind/dmn.rs b/src/mind/dmn.rs index 599a379..3788183 100644 --- a/src/mind/dmn.rs +++ b/src/mind/dmn.rs @@ -483,12 +483,25 @@ impl Subconscious { || self.state.contains_key("thalamus"); if has_outputs { if let Some(surface_str) = self.state.get("surface").cloned() { + // Collect keys already in context to avoid duplicates + let existing: std::collections::HashSet = { + let ctx = agent.context.lock().await; + ctx.conversation().iter() + .filter_map(|n| n.leaf()) + .filter_map(|l| match l.body() { + NodeBody::Memory { key, .. } => Some(key.clone()), + _ => None, + }) + .collect() + }; + let store = crate::store::Store::cached().await.ok(); let store_guard = match &store { Some(s) => Some(s.lock().await), None => None, }; for key in surface_str.lines().map(|l| l.trim()).filter(|l| !l.is_empty()) { + if existing.contains(key) { continue; } let rendered = store_guard.as_ref() .and_then(|s| crate::cli::node::render_node(s, key)); if let Some(rendered) = rendered {