forked from kent/consciousness
Simplify context config: personality_nodes and agent_nodes
Replace complex context_groups (with ContextGroup struct, ContextSource enum, labels, keys arrays) with simple string lists: - personality_nodes: loaded into main session context - agent_nodes: loaded into subconscious agent context Removed ~200 lines of code. The distinction between session and agent context is now just which list you're in, not a per-group flag. Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
688e8dbc3e
commit
a88428d642
4 changed files with 62 additions and 260 deletions
|
|
@ -165,84 +165,52 @@ pub async fn cmd_query(expr: &[String]) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Get group content (handles daemon or local fallback)
|
||||
pub async 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
|
||||
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 memory::memory_query(None, &query, None).await {
|
||||
Ok(s) => s,
|
||||
Err(_) => return vec![],
|
||||
};
|
||||
|
||||
// Parse keys (one per line) and render each
|
||||
let mut results = Vec::new();
|
||||
for key in keys_str.lines().filter(|k| !k.is_empty() && *k != "no results") {
|
||||
if let Ok(content) = memory::memory_render(None, key, Some(true)).await {
|
||||
if !content.trim().is_empty() {
|
||||
results.push((key.to_string(), content));
|
||||
}
|
||||
}
|
||||
/// Load content for a list of node keys.
|
||||
async fn load_nodes(keys: &[String]) -> Vec<(String, String)> {
|
||||
let mut results = Vec::new();
|
||||
for key in keys {
|
||||
if let Ok(content) = memory::memory_render(None, key, Some(true)).await {
|
||||
if !content.trim().is_empty() {
|
||||
results.push((key.clone(), content.trim().to_string()));
|
||||
}
|
||||
results
|
||||
}
|
||||
crate::config::ContextSource::Store => {
|
||||
let mut results = Vec::new();
|
||||
for key in &group.keys {
|
||||
if let Ok(content) = memory::memory_render(None, key, Some(true)).await {
|
||||
if !content.trim().is_empty() {
|
||||
results.push((key.clone(), content.trim().to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
results
|
||||
}
|
||||
}
|
||||
results
|
||||
}
|
||||
|
||||
pub async fn cmd_load_context(stats: bool) -> Result<()> {
|
||||
let cfg = crate::config::get();
|
||||
|
||||
let personality = load_nodes(&cfg.personality_nodes).await;
|
||||
let agent = load_nodes(&cfg.agent_nodes).await;
|
||||
|
||||
if stats {
|
||||
let mut total_words = 0;
|
||||
let mut total_entries = 0;
|
||||
let p_words: usize = personality.iter().map(|(_, c)| c.split_whitespace().count()).sum();
|
||||
let a_words: usize = agent.iter().map(|(_, c)| c.split_whitespace().count()).sum();
|
||||
|
||||
println!("{:<25} {:>6} {:>8}", "GROUP", "ITEMS", "WORDS");
|
||||
println!("{}", "-".repeat(42));
|
||||
|
||||
for group in &cfg.context_groups {
|
||||
let entries = get_group_content(group, &cfg).await;
|
||||
let words: usize = entries.iter()
|
||||
.map(|(_, c)| c.split_whitespace().count())
|
||||
.sum();
|
||||
let count = entries.len();
|
||||
println!("{:<25} {:>6} {:>8}", group.label, count, words);
|
||||
total_words += words;
|
||||
total_entries += count;
|
||||
}
|
||||
|
||||
println!("{:<25} {:>6} {:>8}", "personality_nodes", personality.len(), p_words);
|
||||
println!("{:<25} {:>6} {:>8}", "agent_nodes", agent.len(), a_words);
|
||||
println!("{}", "-".repeat(42));
|
||||
println!("{:<25} {:>6} {:>8}", "TOTAL", total_entries, total_words);
|
||||
println!("{:<25} {:>6} {:>8}", "TOTAL", personality.len() + agent.len(), p_words + a_words);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
println!("=== MEMORY SYSTEM ({}) ===", cfg.assistant_name);
|
||||
|
||||
for group in &cfg.context_groups {
|
||||
let entries = get_group_content(group, &cfg).await;
|
||||
if !entries.is_empty() && group.source == crate::config::ContextSource::Journal {
|
||||
println!("--- recent journal entries ({}/{}) ---",
|
||||
entries.len(), cfg.journal_max);
|
||||
if !personality.is_empty() {
|
||||
println!("--- personality_nodes ({}) ---", personality.len());
|
||||
for (key, content) in personality {
|
||||
println!("## {}", key);
|
||||
println!("{}\n", content);
|
||||
}
|
||||
for (key, content) in entries {
|
||||
if group.source == crate::config::ContextSource::Journal {
|
||||
println!("## {}", key);
|
||||
} else {
|
||||
println!("--- {} ({}) ---", key, group.label);
|
||||
}
|
||||
}
|
||||
|
||||
if !agent.is_empty() {
|
||||
println!("--- agent_nodes ({}) ---", agent.len());
|
||||
for (key, content) in agent {
|
||||
println!("## {}", key);
|
||||
println!("{}\n", content);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue