1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! 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}");
}
}
}