kill off pub in src/usr/mod.rs
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
d7c93ffdf1
commit
7de816022a
1 changed files with 55 additions and 75 deletions
130
src/user/mod.rs
130
src/user/mod.rs
|
|
@ -30,32 +30,29 @@ use std::io;
|
||||||
|
|
||||||
/// Status info for the bottom status bar.
|
/// Status info for the bottom status bar.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct StatusInfo {
|
struct StatusInfo {
|
||||||
pub dmn_state: String,
|
dmn_state: String,
|
||||||
pub dmn_turns: u32,
|
dmn_turns: u32,
|
||||||
pub dmn_max_turns: u32,
|
dmn_max_turns: u32,
|
||||||
pub prompt_tokens: u32,
|
prompt_tokens: u32,
|
||||||
pub completion_tokens: u32,
|
model: String,
|
||||||
pub model: String,
|
turn_tools: u32,
|
||||||
pub turn_tools: u32,
|
context_budget: String,
|
||||||
pub context_budget: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Context loading details for the debug screen.
|
/// Context loading details for the debug screen.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ContextInfo {
|
struct ContextInfo {
|
||||||
pub model: String,
|
model: String,
|
||||||
pub available_models: Vec<String>,
|
available_models: Vec<String>,
|
||||||
pub prompt_file: String,
|
prompt_file: String,
|
||||||
pub backend: String,
|
backend: String,
|
||||||
pub instruction_files: Vec<(String, usize)>,
|
system_prompt_chars: usize,
|
||||||
pub memory_files: Vec<(String, usize)>,
|
context_message_chars: usize,
|
||||||
pub system_prompt_chars: usize,
|
|
||||||
pub context_message_chars: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build the screen legend from screen labels.
|
/// Build the screen legend from screen labels.
|
||||||
pub(crate) fn screen_legend_from(screens: &[Box<dyn ScreenView>]) -> String {
|
fn screen_legend_from(screens: &[Box<dyn ScreenView>]) -> String {
|
||||||
let parts: Vec<String> = screens.iter().enumerate()
|
let parts: Vec<String> = screens.iter().enumerate()
|
||||||
.map(|(i, s)| format!("F{}={}", i + 1, s.label()))
|
.map(|(i, s)| format!("F{}={}", i + 1, s.label()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
@ -65,78 +62,61 @@ pub(crate) fn screen_legend_from(screens: &[Box<dyn ScreenView>]) -> String {
|
||||||
// Cached legend — set once at startup by event_loop
|
// Cached legend — set once at startup by event_loop
|
||||||
static SCREEN_LEGEND: std::sync::OnceLock<String> = std::sync::OnceLock::new();
|
static SCREEN_LEGEND: std::sync::OnceLock<String> = std::sync::OnceLock::new();
|
||||||
|
|
||||||
pub(crate) fn set_screen_legend(legend: String) {
|
fn set_screen_legend(legend: String) {
|
||||||
let _ = SCREEN_LEGEND.set(legend);
|
let _ = SCREEN_LEGEND.set(legend);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn screen_legend() -> String {
|
fn screen_legend() -> String {
|
||||||
SCREEN_LEGEND.get().cloned().unwrap_or_default()
|
SCREEN_LEGEND.get().cloned().unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Action returned from a screen's tick method.
|
|
||||||
pub enum ScreenAction {
|
|
||||||
/// Switch to screen at this index
|
|
||||||
Switch(usize),
|
|
||||||
/// Send a hotkey action to the Mind
|
|
||||||
Hotkey(HotkeyAction),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A screen that can draw itself and handle input.
|
/// A screen that can draw itself and handle input.
|
||||||
pub(crate) trait ScreenView: Send {
|
trait ScreenView: Send {
|
||||||
fn tick(&mut self, frame: &mut ratatui::Frame, area: ratatui::layout::Rect,
|
fn tick(&mut self, frame: &mut ratatui::Frame, area: ratatui::layout::Rect,
|
||||||
events: &[ratatui::crossterm::event::Event], app: &mut App);
|
events: &[ratatui::crossterm::event::Event], app: &mut App);
|
||||||
fn label(&self) -> &'static str;
|
fn label(&self) -> &'static str;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Clone)]
|
||||||
pub enum HotkeyAction {
|
struct IdleInfo {
|
||||||
CycleReasoning, KillProcess, Interrupt, CycleAutonomy,
|
user_present: bool,
|
||||||
/// Adjust a sampling parameter: (param_index, delta)
|
since_activity: f64,
|
||||||
/// 0=temperature, 1=top_p, 2=top_k
|
activity_ewma: f64,
|
||||||
AdjustSampling(usize, f32),
|
block_reason: String,
|
||||||
|
dreaming: bool,
|
||||||
|
sleeping: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct IdleInfo {
|
struct ChannelStatus {
|
||||||
pub user_present: bool,
|
name: String,
|
||||||
pub since_activity: f64,
|
connected: bool,
|
||||||
pub activity_ewma: f64,
|
unread: u32,
|
||||||
pub block_reason: String,
|
|
||||||
pub dreaming: bool,
|
|
||||||
pub sleeping: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
struct App {
|
||||||
pub(crate) struct ChannelStatus {
|
status: StatusInfo,
|
||||||
pub name: String,
|
activity: String,
|
||||||
pub connected: bool,
|
running_processes: u32,
|
||||||
pub unread: u32,
|
reasoning_effort: String,
|
||||||
}
|
temperature: f32,
|
||||||
|
top_p: f32,
|
||||||
pub struct App {
|
top_k: u32,
|
||||||
pub(crate) status: StatusInfo,
|
active_tools: crate::agent::tools::SharedActiveTools,
|
||||||
pub(crate) activity: String,
|
should_quit: bool,
|
||||||
pub running_processes: u32,
|
context_info: Option<ContextInfo>,
|
||||||
pub reasoning_effort: String,
|
agent_state: Vec<crate::mind::SubconsciousSnapshot>,
|
||||||
pub temperature: f32,
|
walked_count: usize,
|
||||||
pub top_p: f32,
|
channel_status: Vec<ChannelStatus>,
|
||||||
pub top_k: u32,
|
idle_info: Option<IdleInfo>,
|
||||||
pub(crate) active_tools: crate::agent::tools::SharedActiveTools,
|
|
||||||
pub should_quit: bool,
|
|
||||||
pub submitted: Vec<String>,
|
|
||||||
pub(crate) context_info: Option<ContextInfo>,
|
|
||||||
pub(crate) agent_state: Vec<crate::mind::SubconsciousSnapshot>,
|
|
||||||
pub(crate) walked_count: usize,
|
|
||||||
pub(crate) channel_status: Vec<ChannelStatus>,
|
|
||||||
pub(crate) idle_info: Option<IdleInfo>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub fn new(model: String, active_tools: crate::agent::tools::SharedActiveTools) -> Self {
|
fn new(model: String, active_tools: crate::agent::tools::SharedActiveTools) -> Self {
|
||||||
Self {
|
Self {
|
||||||
status: StatusInfo {
|
status: StatusInfo {
|
||||||
dmn_state: "resting".into(), dmn_turns: 0, dmn_max_turns: 20,
|
dmn_state: "resting".into(), dmn_turns: 0, dmn_max_turns: 20,
|
||||||
prompt_tokens: 0, completion_tokens: 0, model,
|
prompt_tokens: 0, model,
|
||||||
turn_tools: 0, context_budget: String::new(),
|
turn_tools: 0, context_budget: String::new(),
|
||||||
},
|
},
|
||||||
activity: String::new(),
|
activity: String::new(),
|
||||||
|
|
@ -146,7 +126,7 @@ impl App {
|
||||||
top_p: 0.95,
|
top_p: 0.95,
|
||||||
top_k: 20,
|
top_k: 20,
|
||||||
active_tools,
|
active_tools,
|
||||||
should_quit: false, submitted: Vec::new(),
|
should_quit: false,
|
||||||
context_info: None,
|
context_info: None,
|
||||||
agent_state: Vec::new(),
|
agent_state: Vec::new(),
|
||||||
walked_count: 0,
|
walked_count: 0,
|
||||||
|
|
@ -155,13 +135,13 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn set_channel_status(&mut self, channels: Vec<(String, bool, u32)>) {
|
fn set_channel_status(&mut self, channels: Vec<(String, bool, u32)>) {
|
||||||
self.channel_status = channels.into_iter()
|
self.channel_status = channels.into_iter()
|
||||||
.map(|(name, connected, unread)| ChannelStatus { name, connected, unread })
|
.map(|(name, connected, unread)| ChannelStatus { name, connected, unread })
|
||||||
.collect();
|
.collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_idle(&mut self, state: &crate::thalamus::idle::State) {
|
fn update_idle(&mut self, state: &crate::thalamus::idle::State) {
|
||||||
self.idle_info = Some(IdleInfo {
|
self.idle_info = Some(IdleInfo {
|
||||||
user_present: state.user_present(), since_activity: state.since_activity(),
|
user_present: state.user_present(), since_activity: state.since_activity(),
|
||||||
activity_ewma: state.activity_ewma, block_reason: state.block_reason().to_string(),
|
activity_ewma: state.activity_ewma, block_reason: state.block_reason().to_string(),
|
||||||
|
|
@ -171,7 +151,7 @@ impl App {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_terminal() -> io::Result<ratatui::Terminal<CrosstermBackend<io::Stdout>>> {
|
fn init_terminal() -> io::Result<ratatui::Terminal<CrosstermBackend<io::Stdout>>> {
|
||||||
terminal::enable_raw_mode()?;
|
terminal::enable_raw_mode()?;
|
||||||
let mut stdout = io::stdout();
|
let mut stdout = io::stdout();
|
||||||
stdout.execute(EnterAlternateScreen)?;
|
stdout.execute(EnterAlternateScreen)?;
|
||||||
|
|
@ -180,7 +160,7 @@ pub fn init_terminal() -> io::Result<ratatui::Terminal<CrosstermBackend<io::Stdo
|
||||||
ratatui::Terminal::new(backend)
|
ratatui::Terminal::new(backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn restore_terminal(terminal: &mut ratatui::Terminal<CrosstermBackend<io::Stdout>>) -> io::Result<()> {
|
fn restore_terminal(terminal: &mut ratatui::Terminal<CrosstermBackend<io::Stdout>>) -> io::Result<()> {
|
||||||
terminal::disable_raw_mode()?;
|
terminal::disable_raw_mode()?;
|
||||||
terminal.backend_mut().execute(DisableMouseCapture)?;
|
terminal.backend_mut().execute(DisableMouseCapture)?;
|
||||||
terminal.backend_mut().execute(LeaveAlternateScreen)?;
|
terminal.backend_mut().execute(LeaveAlternateScreen)?;
|
||||||
|
|
@ -188,7 +168,7 @@ pub fn restore_terminal(terminal: &mut ratatui::Terminal<CrosstermBackend<io::St
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Top-level entry point — creates Mind and UI, wires them together.
|
/// Top-level entry point — creates Mind and UI, wires them together.
|
||||||
pub async fn start(cli: crate::user::CliArgs) -> Result<()> {
|
async fn start(cli: crate::user::CliArgs) -> Result<()> {
|
||||||
let (config, _figment) = crate::config::load_session(&cli)?;
|
let (config, _figment) = crate::config::load_session(&cli)?;
|
||||||
|
|
||||||
if config.app.debug {
|
if config.app.debug {
|
||||||
|
|
@ -309,7 +289,7 @@ fn is_global_event(event: &ratatui::crossterm::event::Event) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(
|
async fn run(
|
||||||
mut app: tui::App,
|
mut app: tui::App,
|
||||||
mind: &crate::mind::Mind,
|
mind: &crate::mind::Mind,
|
||||||
mind_tx: tokio::sync::mpsc::UnboundedSender<MindCommand>,
|
mind_tx: tokio::sync::mpsc::UnboundedSender<MindCommand>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue