monothink 0.4.0

A totally non-agentic coding assistant
/*
 * This file is part of monothink.
 *
 * monothink is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * monothink is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with Wavething.
 * If not, see <https://www.gnu.org/licenses/>.
 */
mod config;
mod core;
mod llm;
mod session;
mod ui;

use crate::{llm::Llm, session::Session, ui::Ui};
use anyhow::Result;
use crossterm::{
    event::{KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags},
    execute,
};
use std::io::stdout;

#[tokio::main]
async fn main() -> Result<()> {
    let config = config::load_config()?;

    let terminal = ratatui::init();
    let mut stdout = stdout();
    execute!(
        stdout,
        PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES)
    )?;

    // NOTE: We wire everything together at top level to make it transparent
    // For such a simple actor model this is fine and easier to get an overview.
    let (session_tx, session_rx) = tokio::sync::mpsc::channel(128);
    let (ui_tx, ui_rx) = tokio::sync::mpsc::channel(128);
    let (llm_tx, llm_rx) = tokio::sync::mpsc::channel(32);

    let mut ui = Ui::new(session_tx.clone(), ui_rx, config.symbols.clone());
    let mut session = Session::new(ui_tx, llm_tx, session_rx, config.clone());
    let mut llm = Llm::new(session_tx, llm_rx, config.general);

    tokio::spawn(async move {
        session.run().await;
    });
    tokio::spawn(async move {
        llm.run().await;
    });
    let app_result = ui.run(terminal).await;

    execute!(stdout, PopKeyboardEnhancementFlags)?;
    ratatui::restore();

    app_result
}