ultron-session-core 1.0.0

One session's runtime, shared by every mode through the session worker: the rlm lane (model, provider, system prompt, the single rlm tool), the composition root of its host stack, the format-4 run journal, session naming, Pi read views, and the session actor
Documentation
//! `diagram.mermaid` for a session ([`diagram`]): node from the session environment's `PATH`, Pele
//! unpacked under `<agent dir>/cache`, diagrams saved to `<agent dir>/rlm-output/<session id>/diagrams`, the theme
//! from the `theme` setting (read at each call), the terminal appearance the attached TUI reported (OSC 11) and
//! the session's `COLORFGBG`, and shown diagrams handed to the
//! lane's cell images ([`crate::view_images::ViewImages`]): attached for the model with `to_model`, else kept for
//! the tool result's display only.

use crate::compose::Config;
use crate::view_images::ViewImages;
use diagram::{DiagramConfig, DiagramModule, NODE_TIMEOUT, ShownDiagram, ThemeInputs};
use serde_json::{Map, Value, json};
use std::sync::Arc;

/// The diagram module of session `session_id`, showing diagrams through `images`.
pub fn module(config: &Config, session_id: &str, images: Arc<ViewImages>) -> DiagramModule {
    let (cwd, agent_dir, trusted, var, terminal) = (
        config.cwd.clone(),
        config.agent_dir.clone(),
        config.project_trusted,
        config.var.clone(),
        config.terminal_theme.clone(),
    );
    DiagramModule::new(DiagramConfig {
        path_var: (config.var)("PATH"),
        home: config.home.clone(),
        cache_dir: config.agent_dir.join("cache"),
        out_dir: config.agent_dir.join("rlm-output").join(session_id).join("diagrams"),
        cwd: config.cwd.clone(),
        theme: Arc::new(move || {
            let settings = config::settings::SettingsManager::create(&cwd, &agent_dir, trusted);
            ThemeInputs {
                setting: settings
                    .settings()
                    .get("theme")
                    .and_then(Value::as_str)
                    .map(str::to_string),
                colorfgbg: var("COLORFGBG"),
                terminal: terminal.lock().unwrap_or_else(|e| e.into_inner()).clone(),
                custom_dir: config::paths::AgentPaths::new(&agent_dir).custom_themes_dir(),
            }
        }),
        show: Arc::new(move |shown: &ShownDiagram<'_>| {
            if shown.to_model {
                let mut payload = Map::new();
                payload.insert("path".into(), json!(shown.png_path.display().to_string()));
                images.attach(shown.lane, &payload).map(|_| ())
            } else {
                images.display(shown.lane, shown.png.to_vec(), shown.line.clone());
                Ok(())
            }
        }),
        fonts: None,
        timeout: NODE_TIMEOUT,
    })
}