F5 thalamus: cached channel status, refresh on entry

Channel status is cached on App and refreshed when switching
to F5, not polled every render frame. Shows connected/disconnected
status and unread count per channel daemon.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
ProofOfConcept 2026-04-03 19:05:48 -04:00
parent 48b8ba73d8
commit 36afa90cdb
3 changed files with 89 additions and 22 deletions

View file

@ -964,9 +964,13 @@ async fn run(cli: cli::CliArgs) -> Result<()> {
dirty = true;
}
// Render tick — only redraws if dirty
// Render tick
_ = render_interval.tick() => {
app.running_processes = session.process_tracker.list().await.len() as u32;
let new_count = session.process_tracker.list().await.len() as u32;
if new_count != app.running_processes {
app.running_processes = new_count;
dirty = true;
}
}
// DMN timer (only when no turn is running)

View file

@ -368,6 +368,16 @@ pub struct App {
pub(crate) agent_log_view: bool,
/// Agent state from last cycle update.
pub(crate) agent_state: Vec<crate::subconscious::subconscious::AgentSnapshot>,
/// Cached channel info for F5 screen (refreshed on status tick).
pub(crate) channel_status: Vec<ChannelStatus>,
}
/// Channel info for display on F5 screen.
#[derive(Clone)]
pub(crate) struct ChannelStatus {
pub name: String,
pub connected: bool,
pub unread: u32,
}
/// Screens toggled by F-keys.
@ -439,6 +449,7 @@ impl App {
agent_selected: 0,
agent_log_view: false,
agent_state: Vec::new(),
channel_status: Vec::new(),
}
}
@ -826,9 +837,62 @@ impl App {
self.draw_main(frame, size);
}
/// Refresh channel status by querying daemon sockets.
/// Called from the status tick, not every render frame.
pub fn refresh_channels(&mut self) {
let channels_dir = dirs::home_dir()
.unwrap_or_default()
.join(".consciousness/channels");
let mut status = Vec::new();
// Read supervisor config to know which daemons exist
let mut sup = crate::thalamus::supervisor::Supervisor::new();
sup.load_config();
for (daemon_name, enabled, alive) in sup.status() {
if !alive {
status.push(ChannelStatus {
name: daemon_name,
connected: false,
unread: 0,
});
continue;
}
// Try to connect and call list()
let sock = channels_dir.join(format!("{}.sock", daemon_name));
match std::os::unix::net::UnixStream::connect(&sock) {
Ok(_stream) => {
// For now, just show the daemon as connected
// TODO: actual capnp list() call
status.push(ChannelStatus {
name: daemon_name,
connected: true,
unread: 0,
});
}
Err(_) => {
status.push(ChannelStatus {
name: daemon_name,
connected: false,
unread: 0,
});
}
}
}
self.channel_status = status;
}
pub(crate) fn set_screen(&mut self, screen: Screen) {
self.screen = screen;
self.debug_scroll = 0;
// Refresh data for status screens on entry
match screen {
Screen::Thalamus => self.refresh_channels(),
_ => {}
}
}
}

View file

@ -1,6 +1,7 @@
// thalamus_screen.rs — F5: attention routing and channel status
//
// Shows presence/idle/activity status, then channel daemon status.
// Shows presence/idle/activity status, then channel status.
// Channel data is cached on App and refreshed on screen entry.
use ratatui::{
layout::Rect,
@ -11,7 +12,6 @@ use ratatui::{
};
use super::{App, SCREEN_LEGEND};
use crate::thalamus::supervisor::Supervisor;
fn fetch_daemon_status() -> Vec<String> {
std::process::Command::new("poc-daemon")
@ -35,7 +35,7 @@ impl App {
let dim = Style::default().fg(Color::DarkGray);
let mut lines: Vec<Line> = Vec::new();
// Presence status first
// Presence status
let daemon_status = fetch_daemon_status();
if !daemon_status.is_empty() {
lines.push(Line::styled("── Presence ──", section));
@ -46,36 +46,35 @@ impl App {
lines.push(Line::raw(""));
}
// Channel status
// Channel status from cached data
lines.push(Line::styled("── Channels ──", section));
lines.push(Line::raw(""));
let mut sup = Supervisor::new();
sup.load_config();
let status = sup.status();
if status.is_empty() {
if self.channel_status.is_empty() {
lines.push(Line::styled(" no channels configured", dim));
} else {
for (name, enabled, alive) in &status {
let (symbol, color) = if *alive {
for ch in &self.channel_status {
let (symbol, color) = if ch.connected {
("", Color::Green)
} else if *enabled {
} else {
("", Color::Red)
} else {
("", Color::DarkGray)
};
let state = if *alive {
"running"
} else if *enabled {
"stopped"
let unread_str = if ch.unread > 0 {
format!(" ({} unread)", ch.unread)
} else {
"disabled"
String::new()
};
lines.push(Line::from(vec![
Span::raw(" "),
Span::styled(symbol, Style::default().fg(color)),
Span::raw(format!(" {:<20} {}", name, state)),
Span::raw(format!(" {:<24}", ch.name)),
Span::styled(
if ch.connected { "connected" } else { "disconnected" },
Style::default().fg(color),
),
Span::styled(unread_str, Style::default().fg(Color::Yellow)),
]));
}
}