Fix agent provenance and add store activity for unconscious agents

- Remove bogus "agent:" prefix from provenance - just use agent name
- Add history field to UnconsciousSnapshot
- Update snapshots() to fetch store activity via recent_by_provenance
- Fix TUI to display store activity for both agent types

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-11 21:57:24 -04:00
parent d2dbdedc8f
commit e9e7458013
5 changed files with 66 additions and 32 deletions

View file

@ -404,7 +404,12 @@ async fn run(
unc.toggle(name).await;
}
}
app.unconscious_state = unc.snapshots();
let store = crate::store::Store::cached().await.ok();
let store_guard = match &store {
Some(s) => Some(s.lock().await),
None => None,
};
app.unconscious_state = unc.snapshots(store_guard.as_deref());
app.graph_health = unc.graph_health.clone();
app.mind_state = Some(mind.shared.lock().unwrap().clone());
}

View file

@ -160,6 +160,21 @@ impl SubconsciousScreen {
app.unconscious_state.get(unc_idx)?.agent.clone()
}
/// Get store activity history for the selected agent.
fn selected_history<'a>(&self, app: &'a App) -> &'a [(String, i64)] {
let idx = self.selected();
let sub_count = app.agent_state.len();
if idx < sub_count {
return app.agent_state.get(idx)
.map(|s| s.history.as_slice())
.unwrap_or(&[]);
}
idx.checked_sub(sub_count + 1)
.and_then(|i| app.unconscious_state.get(i))
.map(|s| s.history.as_slice())
.unwrap_or(&[])
}
fn output_sections(&self, app: &App) -> Vec<SectionView> {
let snap = match app.agent_state.get(self.selected()) {
Some(s) => s,
@ -306,23 +321,27 @@ impl SubconsciousScreen {
let key_style = Style::default().fg(Color::Yellow);
let mut lines: Vec<Line> = Vec::new();
let mut title = "memory store activity".to_string();
if let Some(snap) = app.agent_state.get(self.selected()) {
let short_name = snap.name.strip_prefix("subconscious-").unwrap_or(&snap.name);
title = format!("{} store activity", short_name);
let name = self.selected_agent_name(app);
let short_name = name.as_ref()
.map(|n| n.strip_prefix("subconscious-").unwrap_or(n))
.unwrap_or("");
let title = format!("{} store activity", short_name);
if snap.history.is_empty() {
lines.push(Line::styled(" (no store activity)", dim));
} else {
for (key, ts) in &snap.history {
lines.push(Line::from(vec![
Span::styled(format!(" {:>6} ", format_ts_age(*ts)), dim),
Span::styled(key.as_str(), key_style),
]));
}
let history = self.selected_history(app);
if history.is_empty() {
lines.push(Line::styled(" (no store activity)", dim));
} else {
for (key, ts) in history {
lines.push(Line::from(vec![
Span::styled(format!(" {:>6} ", format_ts_age(*ts)), dim),
Span::styled(key.as_str(), key_style),
]));
}
}
// Walked state (subconscious only)
if let Some(snap) = app.agent_state.get(self.selected()) {
if let Some(walked_str) = snap.state.get("walked") {
let walked: Vec<&str> = walked_str.lines()
.map(|l| l.trim()).filter(|l| !l.is_empty()).collect();