split out src/mind

This commit is contained in:
Kent Overstreet 2026-04-04 02:46:32 -04:00
parent ce04568454
commit 79e384f005
21 changed files with 1865 additions and 2175 deletions

View file

@ -15,6 +15,7 @@
pub mod api;
pub mod context;
pub mod parsing;
pub mod tools;
pub mod training;
@ -79,13 +80,10 @@ pub struct Agent {
app_config: crate::config::AppConfig,
pub prompt_file: String,
/// Stable session ID for memory-search dedup across turns.
session_id: String,
pub session_id: String,
/// Agent orchestration state (surface-observe, journal, reflect).
/// TODO: move to Session — it's session-level, not agent-level.
pub agent_cycles: crate::subconscious::subconscious::AgentCycleState,
/// Latest memory importance scores from training scorer.
pub memory_scores: Option<crate::agent::training::MemoryScore>,
/// Whether a /score task is currently running.
pub scoring_in_flight: bool,
/// Shared active tools — Agent writes, TUI reads.
pub active_tools: crate::user::ui_channel::SharedActiveTools,
}
@ -137,8 +135,6 @@ impl Agent {
prompt_file,
session_id,
agent_cycles,
memory_scores: None,
scoring_in_flight: false,
active_tools,
};
@ -323,7 +319,7 @@ impl Agent {
// Check for closing tag — parse and fire immediately
if let Some(end) = tool_call_buf.find("</tool_call>") {
let body = &tool_call_buf[..end];
if let Some(call) = crate::user::parsing::parse_tool_call_body(body) {
if let Some(call) = crate::agent::parsing::parse_tool_call_body(body) {
let args: serde_json::Value =
serde_json::from_str(&call.function.arguments).unwrap_or_default();
let args_summary = summarize_args(&call.function.name, &args);
@ -666,7 +662,7 @@ impl Agent {
}
/// Build context state summary for the debug screen.
pub fn context_state_summary(&self) -> Vec<ContextSection> {
pub fn context_state_summary(&self, memory_scores: Option<&crate::agent::training::MemoryScore>) -> Vec<ContextSection> {
let count = |s: &str| self.tokenizer.encode_with_special_tokens(s).len();
let mut sections = Vec::new();
@ -758,7 +754,7 @@ impl Agent {
_ => unreachable!(),
};
let text = entry.message().content_text();
let score = self.memory_scores.as_ref()
let score = memory_scores
.and_then(|s| s.memory_weights.iter()
.find(|(k, _)| k == key)
.map(|(_, v)| *v));
@ -823,7 +819,7 @@ impl Agent {
};
// Show which memories were important for this response
let children = if m.role == Role::Assistant {
self.memory_scores.as_ref()
memory_scores
.map(|s| s.important_memories_for_entry(i))
.unwrap_or_default()
.into_iter()
@ -965,7 +961,11 @@ impl Agent {
/// Push the current context summary to the shared state for the TUI to read.
pub fn publish_context_state(&self) {
let summary = self.context_state_summary();
self.publish_context_state_with_scores(None);
}
pub fn publish_context_state_with_scores(&self, memory_scores: Option<&crate::agent::training::MemoryScore>) {
let summary = self.context_state_summary(memory_scores);
if let Ok(mut dbg) = std::fs::OpenOptions::new().create(true).append(true)
.open("/tmp/poc-journal-debug.log") {
use std::io::Write;