forked from kent/consciousness
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 <poc@bcachefs.org>
This commit is contained in:
parent
051198b3d1
commit
5a832b1d6c
3 changed files with 5 additions and 66 deletions
|
|
@ -573,4 +573,3 @@ async fn graph_health() -> Result<String> {
|
||||||
let graph = store.build_graph();
|
let graph = store.build_graph();
|
||||||
Ok(crate::subconscious::prompts::format_health_section(&store, &graph))
|
Ok(crate::subconscious::prompts::format_health_section(&store, &graph))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,68 +57,8 @@ pub fn cmd_query(expr: &[String]) -> Result<(), String> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_group_content(group: &crate::config::ContextGroup, store: &crate::store::Store, cfg: &crate::config::Config) -> Vec<(String, String)> {
|
/// Get group content via RPC (handles daemon or local fallback)
|
||||||
match group.source {
|
pub fn get_group_content(group: &crate::config::ContextGroup, cfg: &crate::config::Config) -> Vec<(String, String)> {
|
||||||
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)> {
|
|
||||||
match group.source {
|
match group.source {
|
||||||
crate::config::ContextSource::Journal => {
|
crate::config::ContextSource::Journal => {
|
||||||
// Query for recent journal entries
|
// Query for recent journal entries
|
||||||
|
|
@ -177,7 +117,7 @@ pub fn cmd_load_context(stats: bool) -> Result<(), String> {
|
||||||
println!("{}", "-".repeat(42));
|
println!("{}", "-".repeat(42));
|
||||||
|
|
||||||
for group in &cfg.context_groups {
|
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()
|
let words: usize = entries.iter()
|
||||||
.map(|(_, c)| c.split_whitespace().count())
|
.map(|(_, c)| c.split_whitespace().count())
|
||||||
.sum();
|
.sum();
|
||||||
|
|
@ -195,7 +135,7 @@ pub fn cmd_load_context(stats: bool) -> Result<(), String> {
|
||||||
println!("=== MEMORY SYSTEM ({}) ===", cfg.assistant_name);
|
println!("=== MEMORY SYSTEM ({}) ===", cfg.assistant_name);
|
||||||
|
|
||||||
for group in &cfg.context_groups {
|
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 {
|
if !entries.is_empty() && group.source == crate::config::ContextSource::Journal {
|
||||||
println!("--- recent journal entries ({}/{}) ---",
|
println!("--- recent journal entries ({}/{}) ---",
|
||||||
entries.len(), cfg.journal_max);
|
entries.len(), cfg.journal_max);
|
||||||
|
|
|
||||||
|
|
@ -474,7 +474,7 @@ fn resolve(
|
||||||
let mut keys = Vec::new();
|
let mut keys = Vec::new();
|
||||||
for group in &cfg.context_groups {
|
for group in &cfg.context_groups {
|
||||||
if !group.agent { continue; }
|
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 {
|
for (key, content) in entries {
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
writeln!(text, "--- {} ({}) ---", key, group.label).ok();
|
writeln!(text, "--- {} ({}) ---", key, group.label).ok();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue