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 session inspector (`createSessionControl().inspect`, session-control-provider.ts): the read-only host
//! requests behind RPC `inspect`, `/agents`, `/memory why|list`, `/skills`, `/experiments`, `/goals`, `/progress`
//! and the Claude Code watch views. A request outside [`INSPECTION_REQUESTS`] is refused before it reaches the
//! runtime, so inspecting never runs a search, starts work or changes state. Allowed requests go to the session's
//! host stack as the root lane's requests (the worker's `host.handle(request, payload)`), outside any cell.

use kernel::{HostHandler, Signal};
use serde_json::{Map, Value};

/// Read-only host requests the inspector may issue (`INSPECTION_REQUESTS` of session-control.ts, without
/// `grants.list`: there is no grant system). None of them
/// runs a search or starts work.
pub const INSPECTION_REQUESTS: [&str; 25] = [
    "agents.status",
    "agents.list",
    "agents.inspect",
    "memory.why",
    "memory.list",
    "skills.list",
    "skills.why",
    "experiments.list",
    "refinements.list",
    "progress.history",
    "progress.assess",
    "schedules.list",
    // The session's scheduled prompts (`/schedules`; Rust-only).
    "schedule.list",
    "goals.list",
    "goals.get",
    "instances.list",
    "instances.get",
    "gates.list",
    "gates.history",
    "rlm.pool",
    "rlm.frames",
    "ctx.state",
    "async.pending",
    // The root lane's detached cells with their start times, for the TUI's running-work panel (Rust-only; the
    // worker answers it itself).
    "rlm.detached",
    "usage.report",
];

/// The inspections `ultron claude`'s watch viewer may make through its control socket (`READ_ONLY_INSPECTIONS` of
/// claude/mcp-server.ts): the [`INSPECTION_REQUESTS`] the rlm-views poller sends, plus `async.pending` and
/// `usage.report`.
pub const VIEWER_INSPECTIONS: [&str; 8] = [
    "agents.status",
    "instances.list",
    "rlm.pool",
    "ctx.state",
    "rlm.frames",
    "progress.assess",
    "async.pending",
    "usage.report",
];

/// `inspect(request, payload)`: refuse anything but an inspection request, then ask `runtime` (none: the session
/// has no Ultron runtime). A null payload is an empty one; any other non-object is refused.
pub fn inspect(
    runtime: Option<&dyn HostHandler>,
    request: &str,
    payload: Value,
    signal: &Signal,
) -> Result<Value, String> {
    if !INSPECTION_REQUESTS.contains(&request) {
        return Err(format!("Not an inspection request: {request}"));
    }
    let runtime = runtime.ok_or("This Session has no Ultron runtime to inspect")?;
    let body = match payload {
        Value::Null => Map::new(),
        Value::Object(body) => body,
        _ => return Err("Inspection payload must be an object".into()),
    };
    runtime.handle(request, body, signal)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn session_core_viewer_inspections_are_inspection_requests() {
        for request in VIEWER_INSPECTIONS {
            assert!(INSPECTION_REQUESTS.contains(&request), "{request}");
        }
    }
}