forked from kent/consciousness
cmd_load_context: use RPC instead of Store::load()
Add get_group_content_rpc() which uses memory_query and memory_render instead of direct store access. The original get_group_content() stays for the subconscious path which already has a store open. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
a6b93c2255
commit
8b59becbab
1 changed files with 52 additions and 4 deletions
|
|
@ -271,9 +271,58 @@ pub fn get_group_content(group: &crate::config::ContextGroup, store: &crate::sto
|
||||||
/// Tools with cli=null are agent-internal (not exposed via MCP CLI bridge).
|
/// 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)
|
// 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 {
|
||||||
|
crate::config::ContextSource::Journal => {
|
||||||
|
// Query for recent journal entries
|
||||||
|
let window: i64 = cfg.journal_days as i64 * 24 * 3600;
|
||||||
|
let query = format!("all | type:episodic | age:<{} | sort:timestamp | limit:{}",
|
||||||
|
window, cfg.journal_max);
|
||||||
|
|
||||||
|
let keys_str = match crate::mcp_server::memory_rpc(
|
||||||
|
"memory_query",
|
||||||
|
serde_json::json!({"query": query}),
|
||||||
|
) {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(_) => return vec![],
|
||||||
|
};
|
||||||
|
|
||||||
|
// Parse keys (one per line) and render each
|
||||||
|
keys_str.lines()
|
||||||
|
.filter(|k| !k.is_empty() && *k != "no results")
|
||||||
|
.filter_map(|key| {
|
||||||
|
let content = crate::mcp_server::memory_rpc(
|
||||||
|
"memory_render",
|
||||||
|
serde_json::json!({"key": key, "raw": true}),
|
||||||
|
).ok()?;
|
||||||
|
if content.trim().is_empty() { return None; }
|
||||||
|
Some((key.to_string(), content))
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
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 = crate::mcp_server::memory_rpc(
|
||||||
|
"memory_render",
|
||||||
|
serde_json::json!({"key": key, "raw": true}),
|
||||||
|
).ok()?;
|
||||||
|
if content.trim().is_empty() { return None; }
|
||||||
|
Some((key.clone(), content.trim().to_string()))
|
||||||
|
}).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn cmd_load_context(stats: bool) -> Result<(), String> {
|
pub fn cmd_load_context(stats: bool) -> Result<(), String> {
|
||||||
let cfg = crate::config::get();
|
let cfg = crate::config::get();
|
||||||
let store = crate::store::Store::load()?;
|
|
||||||
|
|
||||||
if stats {
|
if stats {
|
||||||
let mut total_words = 0;
|
let mut total_words = 0;
|
||||||
|
|
@ -282,7 +331,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(group, &store, &cfg);
|
let entries = get_group_content_rpc(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();
|
||||||
|
|
@ -298,10 +347,9 @@ pub fn cmd_load_context(stats: bool) -> Result<(), String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("=== MEMORY SYSTEM ({}) ===", cfg.assistant_name);
|
println!("=== MEMORY SYSTEM ({}) ===", cfg.assistant_name);
|
||||||
println!();
|
|
||||||
|
|
||||||
for group in &cfg.context_groups {
|
for group in &cfg.context_groups {
|
||||||
let entries = get_group_content(group, &store, &cfg);
|
let entries = get_group_content_rpc(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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue