2026-04-09 00:45:26 -04:00
|
|
|
|
// unconscious_screen.rs — F4: graph health
|
2026-04-03 17:25:59 -04:00
|
|
|
|
|
|
|
|
|
|
use ratatui::{
|
|
|
|
|
|
layout::{Constraint, Layout, Rect},
|
2026-04-09 00:45:26 -04:00
|
|
|
|
style::{Color, Style},
|
2026-04-03 17:25:59 -04:00
|
|
|
|
text::{Line, Span},
|
2026-04-09 00:45:26 -04:00
|
|
|
|
widgets::{Block, Borders, Gauge, Paragraph},
|
2026-04-03 17:25:59 -04:00
|
|
|
|
Frame,
|
2026-04-06 19:33:18 -04:00
|
|
|
|
crossterm::event::KeyCode,
|
2026-04-03 17:25:59 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
2026-04-06 19:33:18 -04:00
|
|
|
|
use super::{App, ScreenView, screen_legend};
|
2026-04-03 17:25:59 -04:00
|
|
|
|
use crate::subconscious::daemon::GraphHealth;
|
|
|
|
|
|
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
|
pub(crate) struct UnconsciousScreen {
|
|
|
|
|
|
scroll: u16,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl UnconsciousScreen {
|
|
|
|
|
|
pub fn new() -> Self { Self { scroll: 0 } }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl ScreenView for UnconsciousScreen {
|
2026-04-09 00:45:26 -04:00
|
|
|
|
fn label(&self) -> &'static str { "hippocampus" }
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
|
|
|
|
|
|
|
fn tick(&mut self, frame: &mut Frame, area: Rect,
|
2026-04-09 00:45:26 -04:00
|
|
|
|
events: &[ratatui::crossterm::event::Event], app: &mut App) {
|
2026-04-05 23:04:10 -04:00
|
|
|
|
for event in events {
|
|
|
|
|
|
if let ratatui::crossterm::event::Event::Key(key) = event {
|
|
|
|
|
|
if key.kind != ratatui::crossterm::event::KeyEventKind::Press { continue; }
|
|
|
|
|
|
match key.code {
|
|
|
|
|
|
KeyCode::PageUp => { self.scroll = self.scroll.saturating_sub(20); }
|
|
|
|
|
|
KeyCode::PageDown => { self.scroll += 20; }
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
}
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-03 17:25:59 -04:00
|
|
|
|
let block = Block::default()
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
|
.title_top(Line::from(screen_legend()).left_aligned())
|
2026-04-09 00:45:26 -04:00
|
|
|
|
.title_top(Line::from(" hippocampus ").right_aligned())
|
2026-04-03 17:25:59 -04:00
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
|
|
.border_style(Style::default().fg(Color::Cyan));
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
|
let inner = block.inner(area);
|
|
|
|
|
|
frame.render_widget(block, area);
|
2026-04-03 17:25:59 -04:00
|
|
|
|
|
2026-04-09 00:45:26 -04:00
|
|
|
|
match &app.graph_health {
|
2026-04-03 17:25:59 -04:00
|
|
|
|
None => {
|
|
|
|
|
|
frame.render_widget(
|
2026-04-09 00:45:26 -04:00
|
|
|
|
Paragraph::new(Line::styled(" computing graph health...",
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
|
Style::default().fg(Color::DarkGray))),
|
2026-04-03 17:25:59 -04:00
|
|
|
|
inner,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2026-04-09 00:45:26 -04:00
|
|
|
|
Some(gh) => {
|
|
|
|
|
|
render_health(frame, gh, inner);
|
2026-04-03 17:25:59 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
|
}
|
2026-04-03 17:25:59 -04:00
|
|
|
|
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
|
fn render_health(frame: &mut Frame, gh: &GraphHealth, area: Rect) {
|
|
|
|
|
|
let [metrics_area, gauges_area, plan_area] = Layout::vertical([
|
|
|
|
|
|
Constraint::Length(2), Constraint::Length(4), Constraint::Min(1),
|
|
|
|
|
|
]).areas(area);
|
|
|
|
|
|
|
|
|
|
|
|
let summary = Line::from(format!(
|
|
|
|
|
|
" {} nodes {} edges {} communities", gh.nodes, gh.edges, gh.communities
|
|
|
|
|
|
));
|
|
|
|
|
|
let ep_line = Line::from(vec![
|
|
|
|
|
|
Span::raw(" episodic: "),
|
|
|
|
|
|
Span::styled(format!("{:.0}%", gh.episodic_ratio * 100.0),
|
|
|
|
|
|
if gh.episodic_ratio < 0.4 { Style::default().fg(Color::Green) }
|
|
|
|
|
|
else { Style::default().fg(Color::Red) }),
|
|
|
|
|
|
Span::raw(format!(" σ={:.1} interference={}", gh.sigma, gh.interference)),
|
|
|
|
|
|
]);
|
|
|
|
|
|
frame.render_widget(Paragraph::new(vec![summary, ep_line]), metrics_area);
|
|
|
|
|
|
|
|
|
|
|
|
let [g1, g2, g3] = Layout::horizontal([
|
|
|
|
|
|
Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3),
|
|
|
|
|
|
]).areas(gauges_area);
|
|
|
|
|
|
|
|
|
|
|
|
let alpha_color = if gh.alpha >= 2.5 { Color::Green } else { Color::Red };
|
|
|
|
|
|
frame.render_widget(Gauge::default()
|
|
|
|
|
|
.block(Block::default().borders(Borders::ALL).title(" α (≥2.5) "))
|
|
|
|
|
|
.gauge_style(Style::default().fg(alpha_color))
|
|
|
|
|
|
.ratio((gh.alpha / 5.0).clamp(0.0, 1.0) as f64)
|
|
|
|
|
|
.label(format!("{:.2}", gh.alpha)), g1);
|
|
|
|
|
|
|
|
|
|
|
|
let gini_color = if gh.gini <= 0.4 { Color::Green } else { Color::Red };
|
|
|
|
|
|
frame.render_widget(Gauge::default()
|
|
|
|
|
|
.block(Block::default().borders(Borders::ALL).title(" gini (≤0.4) "))
|
|
|
|
|
|
.gauge_style(Style::default().fg(gini_color))
|
|
|
|
|
|
.ratio(gh.gini.clamp(0.0, 1.0) as f64)
|
|
|
|
|
|
.label(format!("{:.3}", gh.gini)), g2);
|
|
|
|
|
|
|
|
|
|
|
|
let cc_color = if gh.avg_cc >= 0.2 { Color::Green } else { Color::Red };
|
|
|
|
|
|
frame.render_widget(Gauge::default()
|
|
|
|
|
|
.block(Block::default().borders(Borders::ALL).title(" cc (≥0.2) "))
|
|
|
|
|
|
.gauge_style(Style::default().fg(cc_color))
|
|
|
|
|
|
.ratio(gh.avg_cc.clamp(0.0, 1.0) as f64)
|
|
|
|
|
|
.label(format!("{:.3}", gh.avg_cc)), g3);
|
|
|
|
|
|
|
|
|
|
|
|
let plan_total: usize = gh.plan_counts.values().sum::<usize>() + 1;
|
|
|
|
|
|
let mut plan_items: Vec<_> = gh.plan_counts.iter().filter(|(_, c)| **c > 0).collect();
|
|
|
|
|
|
plan_items.sort_by(|a, b| a.0.cmp(b.0));
|
|
|
|
|
|
let plan_summary: Vec<String> = plan_items.iter().map(|(a, c)| format!("{}{}", &a[..1], c)).collect();
|
|
|
|
|
|
frame.render_widget(Paragraph::new(Line::from(vec![
|
|
|
|
|
|
Span::raw(" plan: "),
|
2026-04-09 00:45:26 -04:00
|
|
|
|
Span::styled(format!("{}", plan_total), Style::default().fg(Color::White)),
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
|
Span::raw(format!(" agents ({} +health)", plan_summary.join(" "))),
|
|
|
|
|
|
])), plan_area);
|
|
|
|
|
|
}
|