MCPcopy Create free account
hub / github.com/Noumena-Network/code / main

Function main

rust/py_repl_host/src/main.rs:73–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

71}
72
73fn 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
119fn next_nonempty_line<I>(input: &mut I) -> io::Result<Option<String>>
120where

Callers

nothing calls this directly

Calls 4

next_nonempty_lineFunction · 0.85
spawn_kernelFunction · 0.85
relay_execFunction · 0.85
write_exec_resultFunction · 0.85

Tested by

no test coverage detected