()
| 71 | } |
| 72 | |
| 73 | fn main() -> io::Result<()> { |
| 74 | let stdin = io::stdin(); |
| 75 | let stdout = io::stdout(); |
| 76 | let mut input = stdin.lock().lines(); |
| 77 | let mut output = BufWriter::new(stdout.lock()); |
| 78 | let mut kernel: Option<KernelProcess> = None; |
| 79 | |
| 80 | while let Some(line) = next_nonempty_line(&mut input)? { |
| 81 | let message = match serde_json::from_str::<ParentMessage>(&line) { |
| 82 | Ok(message) => message, |
| 83 | Err(_) => continue, |
| 84 | }; |
| 85 | |
| 86 | match message { |
| 87 | ParentMessage::Exec { |
| 88 | id, |
| 89 | code, |
| 90 | timeout_ms, |
| 91 | } => { |
| 92 | if kernel.is_none() { |
| 93 | kernel = Some(spawn_kernel()?); |
| 94 | } |
| 95 | |
| 96 | let result = relay_exec( |
| 97 | &id, |
| 98 | &code, |
| 99 | timeout_ms, |
| 100 | kernel.as_mut().expect("kernel initialized"), |
| 101 | &mut input, |
| 102 | &mut output, |
| 103 | ); |
| 104 | |
| 105 | if let Err(error) = result { |
| 106 | write_exec_result(&mut output, &id, false, "", Some(&error))?; |
| 107 | kernel = None; |
| 108 | } |
| 109 | } |
| 110 | ParentMessage::RunToolResult { .. } => { |
| 111 | // Ignored outside an active exec loop. |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | Ok(()) |
| 117 | } |
| 118 | |
| 119 | fn next_nonempty_line<I>(input: &mut I) -> io::Result<Option<String>> |
| 120 | where |
nothing calls this directly
no test coverage detected