The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(memory): label a hosted forest by what each node says
Shanu16edc8c830b6
diff --git a/crates/openhuman-core/src/memory/read_rpc/graph.rs b/crates/openhuman-core/src/memory/read_rpc/graph.rsindex a04b4cb071..2b4037c146 100644--- a/crates/openhuman-core/src/memory/read_rpc/graph.rs+++ b/crates/openhuman-core/src/memory/read_rpc/graph.rs@@ -76,6 +76,15 @@ pub struct GraphExportResponse {/// still the cut the UI sees.const CHUNK_LABEL_CHARS: usize = 72;+/// Label cap for a summary node whose driver serves its text inline — hosted+/// memory's concepts, beliefs and facts. The same cut as a chunk's, so the two+/// read alike on the canvas.+const SUMMARY_LABEL_CHARS: usize = CHUNK_LABEL_CHARS;++/// The tree kind a hosted driver reports for the forest it draws from the+/// server's own understanding.+const HOSTED_TREE_KIND: &str = "understanding";+// ── graph_export ────────────────────────────────────────────────────────pub async fn graph_export_rpc(@@ -172,6 +181,9 @@ async fn collect_tree_graph(cfg: &Config) -> Result<(Vec<GraphNode>, Vec<GraphEd"[memory_tree::read::graph_tree] leaves={} budget={chunk_budget}",leaves.len());+ let leaf_ids: std::collections::HashSet<String> =+ leaves.iter().map(|leaf| leaf.chunk_id.clone()).collect();+ nodes = drop_stand_ins(nodes, &leaf_ids);for leaf in leaves {let TreeLeaf {chunk_id,@@ -247,10 +259,18 @@ fn shape_summary_nodes(summaries: Vec<TreeSummary>, max_nodes: usize) -> Vec<Grachild_ids,time_range_start,time_range_end,+ preview,} = summary;let child_count = child_ids.len() as u32;- let file_basename = sanitize_basename(&id);- let label = format!("L{level} · {tree_scope}");+ // A driver that serves a summary's text inline keeps no file for+ // it: the text is the label, and the UI is given no path to open.+ let (label, file_basename) = match preview.filter(|text| !text.trim().is_empty()) {+ Some(text) => (text.chars().take(SUMMARY_LABEL_CHARS).collect(), None),+ None => (+ format!("L{level} · {tree_scope}"),+ Some(sanitize_basename(&id)),+ ),+ };SummaryRow {node: GraphNode {kind: "summary".into(),@@ -266,7 +286,7 @@ fn shape_summary_nodes(summaries: Vec<TreeSummary>, max_nodes: usize) -> Vec<Grachild_count: Some(child_count),time_range_start_ms: Some(time_range_start.timestamp_millis()),time_range_end_ms: Some(time_range_end.timestamp_millis()),- file_basename: Some(file_basename),+ file_basename,entity_kind: None,},tree_scope,@@ -275,18 +295,23 @@ fn shape_summary_nodes(summaries: Vec<TreeSummary>, max_nodes: usize) -> Vec<Gra}).collect();- let mut scopes: std::collections::BTreeSet<String> = std::collections::BTreeSet::new();+ // Scope to the kind of tree that occupies it. A hosted driver's trees are+ // its namespaces and read as what they hold; every other driver's scope is+ // shown as it names itself.+ let mut scopes: std::collections::BTreeMap<String, String> = std::collections::BTreeMap::new();for sr in &summary_rows {- scopes.insert(sr.tree_scope.clone());+ scopes+ .entry(sr.tree_scope.clone())+ .or_insert_with(|| sr.node.tree_kind.clone().unwrap_or_default());}let mut nodes: Vec<GraphNode> = Vec::new();let mut source_root_ids: std::collections::HashMap<String, String> =std::collections::HashMap::new();- for scope in &scopes {+ for (scope, tree_kind) in &scopes {let root_id = format!("source:{scope}");- let label = scope_display_label(scope);+ let label = scope_display_label(scope, tree_kind);source_root_ids.insert(scope.clone(), root_id.clone());nodes.push(GraphNode {kind: "source".into(),@@ -367,7 +392,46 @@ fn shape_summary_nodes(summaries: Vec<TreeSummary>, max_nodes: usize) -> Vec<Granodes}-fn scope_display_label(scope: &str) -> String {+/// Drops the document leaves that stand in for children the leaf listing+/// then returned as leaves of their own.+///+/// A document leaf is drawn for each child of an L1 summary so a child the+/// listing never returns still shows. One the listing does return would be+/// drawn twice — once as the stand-in, once as itself — so its stand-in goes.+pub(super) fn drop_stand_ins(+ nodes: Vec<GraphNode>,+ leaf_ids: &std::collections::HashSet<String>,+) -> Vec<GraphNode> {+ nodes+ .into_iter()+ .filter(|node| {+ let stands_in_for = node.tree_scope.as_deref().and_then(|scope| {+ node.id+ .strip_prefix("doc:")+ .and_then(|rest| rest.strip_prefix(scope))+ .and_then(|rest| rest.strip_prefix(':'))+ });+ !(node.kind == "chunk" && stands_in_for.is_some_and(|child| leaf_ids.contains(child)))+ })+ .collect()+}++/// The name a source root carries: a hosted driver's namespaces read as what+/// they hold, and every other scope reads as it names itself.+///+/// `tree_kind` is what keeps the two apart. The embedded engine has a `global`+/// tree of its own, whose scope is the literal `global`, so matching on the+/// scope alone would rename a node that has nothing to do with hosted memory.+pub(super) fn scope_display_label(scope: &str, tree_kind: &str) -> String {+ if tree_kind == HOSTED_TREE_KIND {+ match scope {+ "global" => return "Memory".to_string(),+ "sources/chat" => return "Chat".to_string(),+ "sources/email" => return "Email".to_string(),+ "sources/documents" => return "Documents".to_string(),+ _ => {}+ }+ }if scope.starts_with("github:") {let repo = scope.strip_prefix("github:").unwrap_or(scope);format!("GitHub · {repo}")diff --git a/crates/openhuman-core/src/memory/read_rpc/graph_tests.rs b/crates/openhuman-core/src/memory/read_rpc/graph_tests.rsindex 5a32916469..2d2f3b2714 100644--- a/crates/openhuman-core/src/memory/read_rpc/graph_tests.rs+++ b/crates/openhuman-core/src/memory/read_rpc/graph_tests.rs@@ -24,10 +24,15 @@//! 4. **The node budget cuts the document tail, never the summaries.** The//! summaries are the skeleton — a budget that dropped them would leave//! document leaves parented to nodes that are not in the response.+//! 5. **A summary served with its text is labelled by it, and has no file.**+//! Hosted memory's concepts, beliefs and facts live on the server; a path+//! into the local content vault would open nothing.+//! 6. **A child is drawn once.** A document leaf stands in for a child the leaf+//! listing does not return, and goes when the listing returns it.use chrono::{TimeZone, Utc};-use super::shape_summary_nodes;+use super::{drop_stand_ins, scope_display_label, shape_summary_nodes};use crate::memory::api::tree::TreeSummary;const BUDGET: usize = 10_000;@@ -49,6 +54,7 @@ fn summary(child_ids: children.iter().map(|c| (*c).to_string()).collect(),time_range_start: Utc.timestamp_opt(1_700_000_000, 0).unwrap(),time_range_end: Utc.timestamp_opt(1_700_000_900, 0).unwrap(),+ preview: None,}}@@ -243,3 +249,74 @@ fn an_empty_forest_shapes_to_no_nodes_at_all() {// root per scope it has never seen.assert!(shape_summary_nodes(Vec::new(), BUDGET).is_empty());}++#[test]+fn a_summary_served_with_its_text_is_labelled_by_it_and_has_no_file() {+ let mut concept = summary("concept_job", "sources/email", 3, None, &["belief_1"]);+ concept.preview = Some(format!("Alice's new job — {}", "detail ".repeat(20)));+ let nodes = shape_summary_nodes(+ vec![concept, summary("s1", "sources/email", 1, None, &[])],+ BUDGET,+ );+ let node = |id: &str| nodes.iter().find(|n| n.id == id).expect("node");+ let concept = node("concept_job");+ assert!(concept.label.starts_with("Alice's new job — "));+ assert_eq!(concept.label.chars().count(), super::SUMMARY_LABEL_CHARS);+ assert_eq!(concept.file_basename, None, "no vault file to open");+ let sealed = node("s1");+ assert_eq!(sealed.label, "L1 · sources/email");+ assert!(sealed.file_basename.is_some());+}++#[test]+fn a_child_the_leaf_listing_returns_is_drawn_once() {+ let nodes = shape_summary_nodes(+ vec![summary(+ "fact_1",+ "sources/email",+ 1,+ None,+ &["evt_1", "evt_2"],+ )],+ BUDGET,+ );+ let leaves: std::collections::HashSet<String> = ["evt_1".to_string()].into();+ let kept = drop_stand_ins(nodes, &leaves);+ let ids: Vec<&str> = kept.iter().map(|n| n.id.as_str()).collect();+ assert!(+ ids.contains(&"doc:sources/email:evt_2"),+ "an unlisted child keeps its stand-in"+ );+ assert!(+ !ids.contains(&"doc:sources/email:evt_1"),+ "a listed child is drawn as itself"+ );+ assert!(ids.contains(&"fact_1") && ids.contains(&"source:sources/email"));+}++#[test]+fn hosted_namespaces_read_as_what_they_hold() {+ let hosted = "understanding";+ assert_eq!(scope_display_label("global", hosted), "Memory");+ assert_eq!(scope_display_label("sources/chat", hosted), "Chat");+ assert_eq!(scope_display_label("sources/email", hosted), "Email");+ assert_eq!(+ scope_display_label("sources/documents", hosted),+ "Documents"+ );+ assert_eq!(scope_display_label("slack:#eng", hosted), "Slack · #eng");+}++/// The embedded engine has a `global` tree of its own; renaming it would be a+/// change to a mode this work does not touch.+#[test]+fn another_drivers_scopes_are_left_alone() {+ for kind in ["global", "source", "topic"] {+ assert_eq!(scope_display_label("global", kind), "global");+ assert_eq!(scope_display_label("sources/email", kind), "sources/email");+ }+ assert_eq!(+ scope_display_label("gmail:a-at-b-dot-com", "source"),+ "Gmail · [email protected]"+ );+}