From 5a832b1d6c1ae2c18adc203c7d71e1610d2a8513 Mon Sep 17 00:00:00 2001 From: ProofOfConcept Date: Sun, 12 Apr 2026 23:00:10 -0400 Subject: [PATCH] get_group_content: use RPC, delete store-based version One function that uses memory_rpc (which handles daemon vs local). Removes 65 lines of duplicate logic. Co-Authored-By: Proof of Concept --- src/agent/tools/memory.rs | 1 - src/cli/misc.rs | 68 +++------------------------------------ src/subconscious/defs.rs | 2 +- 3 files changed, 5 insertions(+), 66 deletions(-) diff --git a/src/agent/tools/memory.rs b/src/agent/tools/memory.rs index 1bf69bc..690718c 100644 --- a/src/agent/tools/memory.rs +++ b/src/agent/tools/memory.rs @@ -573,4 +573,3 @@ async fn graph_health() -> Result { let graph = store.build_graph(); Ok(crate::subconscious::prompts::format_health_section(&store, &graph)) } - diff --git a/src/cli/misc.rs b/src/cli/misc.rs index 345b1e2..fddf9b5 100644 --- a/src/cli/misc.rs +++ b/src/cli/misc.rs @@ -57,68 +57,8 @@ pub fn cmd_query(expr: &[String]) -> Result<(), String> { Ok(()) } -pub fn get_group_content(group: &crate::config::ContextGroup, store: &crate::store::Store, cfg: &crate::config::Config) -> Vec<(String, String)> { - match group.source { - crate::config::ContextSource::Journal => { - let mut entries = Vec::new(); - let now = crate::store::now_epoch(); - let window: i64 = cfg.journal_days as i64 * 24 * 3600; - let cutoff = now - window; - let key_date_re = regex::Regex::new(r"j-(\d{4}-\d{2}-\d{2})").unwrap(); - - let journal_ts = |n: &crate::store::Node| -> i64 { - if n.created_at > 0 { return n.created_at; } - if let Some(caps) = key_date_re.captures(&n.key) { - use chrono::{NaiveDate, TimeZone, Local}; - if let Ok(d) = NaiveDate::parse_from_str(&caps[1], "%Y-%m-%d") - && let Some(dt) = Local.from_local_datetime(&d.and_hms_opt(0, 0, 0).unwrap()).earliest() { - return dt.timestamp(); - } - } - n.timestamp - }; - - let mut journal_nodes: Vec<_> = store.nodes.values() - .filter(|n| n.node_type == crate::store::NodeType::EpisodicSession && journal_ts(n) >= cutoff) - .collect(); - journal_nodes.sort_by_key(|n| journal_ts(n)); - - let max = cfg.journal_max; - let skip = journal_nodes.len().saturating_sub(max); - for node in journal_nodes.iter().skip(skip) { - entries.push((node.key.clone(), node.content.clone())); - } - entries - } - crate::config::ContextSource::File => { - group.keys.iter().filter_map(|key| { - let content = std::fs::read_to_string(cfg.identity_dir.join(key)).ok()?; - if content.trim().is_empty() { return None; } - Some((key.clone(), content.trim().to_string())) - }).collect() - } - crate::config::ContextSource::Store => { - group.keys.iter().filter_map(|key| { - let content = store.render_file(key)?; - if content.trim().is_empty() { return None; } - Some((key.clone(), content.trim().to_string())) - }).collect() - } - } -} - -/// MCP tool schema with CLI routing info. -/// -/// Each tool definition includes: -/// - name, description, inputSchema (standard MCP) -/// - cli: the CLI args prefix to invoke this tool -/// - stdin_param: which parameter (if any) should be sent via stdin -/// -/// Tools with cli=null are agent-internal (not exposed via MCP CLI bridge). -// mcp-schema moved to consciousness-mcp binary (src/claude/mcp-server.rs) - -/// Get group content via RPC (no Store::load needed) -fn get_group_content_rpc(group: &crate::config::ContextGroup, cfg: &crate::config::Config) -> Vec<(String, String)> { +/// Get group content via RPC (handles daemon or local fallback) +pub fn get_group_content(group: &crate::config::ContextGroup, cfg: &crate::config::Config) -> Vec<(String, String)> { match group.source { crate::config::ContextSource::Journal => { // Query for recent journal entries @@ -177,7 +117,7 @@ pub fn cmd_load_context(stats: bool) -> Result<(), String> { println!("{}", "-".repeat(42)); for group in &cfg.context_groups { - let entries = get_group_content_rpc(group, &cfg); + let entries = get_group_content(group, &cfg); let words: usize = entries.iter() .map(|(_, c)| c.split_whitespace().count()) .sum(); @@ -195,7 +135,7 @@ pub fn cmd_load_context(stats: bool) -> Result<(), String> { println!("=== MEMORY SYSTEM ({}) ===", cfg.assistant_name); for group in &cfg.context_groups { - let entries = get_group_content_rpc(group, &cfg); + let entries = get_group_content(group, &cfg); if !entries.is_empty() && group.source == crate::config::ContextSource::Journal { println!("--- recent journal entries ({}/{}) ---", entries.len(), cfg.journal_max); diff --git a/src/subconscious/defs.rs b/src/subconscious/defs.rs index 6e344b0..fce6bff 100644 --- a/src/subconscious/defs.rs +++ b/src/subconscious/defs.rs @@ -474,7 +474,7 @@ fn resolve( let mut keys = Vec::new(); for group in &cfg.context_groups { if !group.agent { continue; } - let entries = crate::cli::misc::get_group_content(group, store, &cfg); + let entries = crate::cli::misc::get_group_content(group, &cfg); for (key, content) in entries { use std::fmt::Write; writeln!(text, "--- {} ({}) ---", key, group.label).ok();