Plan device actions exclusively as approved scripts and provide reboot library revisions

This commit is contained in:
2026-11-18 12:04:58 +01:00
parent adc04f0148
commit cd80bfc704
31 changed files with 1014 additions and 779 deletions
+37 -6
View File
@@ -58,6 +58,7 @@ struct Device {
#[serde(deny_unknown_fields)]
struct Plan {
tenant_id: Uuid,
#[schemars(with = "crate::jobs::WebPlanInput")]
input: crate::jobs::PlanRequest,
}
#[derive(Deserialize, schemars::JsonSchema)]
@@ -138,11 +139,11 @@ fn tools() -> Vec<Tool> {
),
tool::<crate::monitoring::LogQuery>(
"logs.query",
"Read stored bounded log evidence, or request a live query as a pending approval operation.",
"Read stored bounded log evidence. Use a script job for a fresh collection.",
),
tool::<Plan>(
"operations.plan",
"Persist immutable exact job plan. No executable jobs are created.",
"Plan a run_script operation for selected devices. The stored script and target list require interactive approval.",
),
tool::<Submit>(
"operations.submit",
@@ -156,10 +157,6 @@ fn tools() -> Vec<Tool> {
"jobs.cancel",
"Request cancellation, not rollback or proof of termination.",
),
tool::<Tenant>(
"sessions.request",
"Unsupported until after MVP; never opens a shell.",
),
]
}
fn parse<T: serde::de::DeserializeOwned>(v: Value) -> Result<T, crate::jobs::Error> {
@@ -400,3 +397,37 @@ pub fn routes(r: Router<crate::State>, state: crate::State) -> Router<crate::Sta
r.nest_service("/mcp", service)
.route_layer(middleware::from_fn_with_state(state, guard))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn plan_tool_advertises_the_script_wire_contract() {
let tools = tools();
let plan = tools
.iter()
.find(|tool| tool.name == "operations.plan")
.unwrap();
let schema = serde_json::to_string(&plan.input_schema).unwrap();
for field in [
"run_script",
"script_utf8",
"variants",
"execution_identity",
] {
assert!(schema.contains(field), "{field}");
}
for retired in [
"update_agent",
"reboot",
"query_logs",
"apt_manifest",
"windows_msi_manifest",
"dependency_group",
] {
assert!(!schema.contains(retired), "{retired}");
}
assert!(tools.iter().all(|tool| tool.name != "sessions.request"));
}
}