Add stateful call leaf runtime

This commit is contained in:
Michael Mikovsky
2026-04-25 15:35:08 -06:00
parent 56bc7ee4f8
commit 7e266e2a38
18 changed files with 1349 additions and 388 deletions
+29 -22
View File
@@ -17,25 +17,46 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut endpoint = common::build_controller_endpoint();
let hook_id = endpoint.allocate_hook_id();
let shell_leaf_name = common::shell_leaf_name();
let start_procedure = common::shell_start_procedure();
let open_procedure = common::shell_open_procedure();
let outcome = endpoint.send_call(
common::agent_path(),
Some(shell_leaf_name),
start_procedure.clone(),
open_procedure.clone(),
Some(hook_id),
Vec::new(),
common::shell_open_payload(),
)?;
common::write_frames(
&mut stream,
&outcome
.forward
.into_iter()
.map(|(_, frame)| frame)
.collect::<Vec<_>>(),
)?;
let _ = common::pump_outcome(&mut stream, outcome)?;
let mut commands_sent = false;
for (index, command) in ["pwd\n", "whoami\n", "exit\n"].iter().enumerate() {
let outcome = endpoint.send_data(
common::agent_path(),
hook_id,
open_procedure.clone(),
command.as_bytes().to_vec(),
index == 2,
)?;
common::write_frames(
&mut stream,
&outcome
.forward
.into_iter()
.map(|(_, frame)| frame)
.collect::<Vec<_>>(),
)?;
}
for result in frame_rx {
let frame = result?;
let outcome = endpoint.receive(&Ingress::Child(common::agent_path()), frame)?;
let event = common::pump_outcome(&mut stream, outcome)?;
let Some(event) = event else {
let Some(event) = outcome.event else {
continue;
};
@@ -43,20 +64,6 @@ fn main() -> Result<(), Box<dyn Error>> {
LocalEvent::Data { message, .. } => {
print!("{}", String::from_utf8_lossy(&message.data));
if !commands_sent {
commands_sent = true;
for (index, command) in ["pwd\n", "whoami\n", "exit\n"].iter().enumerate() {
let outcome = endpoint.send_data(
common::agent_path(),
hook_id,
start_procedure.clone(),
command.as_bytes().to_vec(),
index == 2,
)?;
let _ = common::pump_outcome(&mut stream, outcome)?;
}
}
if message.end_hook {
break;
}