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
//! The footer's kernel strip reads `rlm.pool`: a session composed as the worker composes it (`Runtime::stack`, its
//! root lane opened) reports no live kernel before its first cell, as the TypeScript session does
//! (crates/lanes/fixtures/idle-pool.json, recorded from `createUltronRlmTool(...).poolStats()`).

use lanes::CellOutcome;
use serde_json::{Value, json};
use session_core::RunEnv;
use session_core::compose::{Runtime, Services, Stack};
use std::path::Path;
use std::sync::Arc;
use std::time::Duration;

const HANG_GUARD: Duration = Duration::from_secs(120);

fn stack(root: &Path, max_live: u64) -> Arc<Stack> {
    let home = root.join("home");
    std::fs::create_dir_all(home.join(".ultron/agent")).unwrap();
    std::fs::write(
        home.join(".ultron/agent/settings.json"),
        json!({"sandbox": {"mode": "off"}, "rlm": {"maxLiveKernels": max_live}}).to_string(),
    )
    .unwrap();
    let cwd = root.join("project");
    std::fs::create_dir_all(&cwd).unwrap();
    let vars: Vec<(String, String)> = vec![
        ("HOME".into(), home.display().to_string()),
        (
            config::paths::ENV_AGENT_DIR.into(),
            home.join(".ultron/agent").display().to_string(),
        ),
        (
            config::paths::ENV_SERVER_DIR.into(),
            root.join("server").display().to_string(),
        ),
        (hindsight::resolve::HINDSIGHT_URL_ENV.into(), "off".into()),
        ("ULTRON_LSP".into(), "off".into()),
        ("ULTRON_MEMORANTADO_URL".into(), "off".into()),
    ];
    let env = RunEnv {
        cwd,
        home,
        var: Arc::new(move |key| vars.iter().find(|(k, _)| k == key).map(|(_, v)| v.clone())),
        package: config::paths::normalize(&Path::new(env!("CARGO_MANIFEST_DIR")).join("../../packages/coding-agent")),
    };
    let runtime = Runtime::new(&env, "print", root.join("sessions"), Services::default()).unwrap();
    let model = ai::models::builtin_models("anthropic").next().unwrap().clone();
    runtime.stack(&model, None, "a43").unwrap()
}

#[test]
fn session_core_idle_session_reports_no_live_kernel_before_its_first_cell_like_ts() {
    let dir = tempfile::tempdir().unwrap();
    let stack = stack(dir.path(), 16);
    let expected: Value = serde_json::from_str(include_str!("../../lanes/fixtures/idle-pool.json")).unwrap();
    // The pool's own fields; the session adds its guard statistics (Loki), which the fixture's bare tool has not.
    let mut stats = stack.pool_stats();
    assert!(stats.as_object_mut().unwrap().remove("guards").is_some(), "{stats}");
    assert_eq!(stats, expected["idle"]["stats"]);
    assert!(matches!(
        stack.lanes.run("main", "1", HANG_GUARD).unwrap(),
        CellOutcome::Done(Ok(_))
    ));
    assert_eq!(stack.pool_stats()["live"], json!(1));
    stack.close();
}