Skip to main content

nemo_relay_cli/
lib.rs

1// SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Internal application library for the `nemo-relay` executable.
5
6mod agents;
7mod banner;
8mod bootstrap;
9mod commands;
10mod configuration;
11mod diagnostics;
12mod error;
13mod events;
14mod filesystem;
15mod gateway;
16mod hooks;
17mod installation;
18mod mcp;
19mod mcp_environment;
20mod plugins;
21mod process;
22mod provider_auth;
23mod server;
24mod sessions;
25
26#[cfg(test)]
27#[path = "../tests/coverage/shared/hook_assertions.rs"]
28mod hook_assertions;
29
30#[cfg(test)]
31#[path = "../tests/coverage/shared/test_support.rs"]
32pub(crate) mod test_support;
33
34use std::process::ExitCode;
35
36/// Runs the `nemo-relay` process.
37///
38/// This is an executable entrypoint, not a supported library API.
39#[doc(hidden)]
40pub fn run_cli() -> ExitCode {
41    mcp_environment::remove_unresolved_mcp_placeholders();
42    let bootstrap_shutdown_token = take_bootstrap_shutdown_token();
43    let runtime = match tokio::runtime::Builder::new_multi_thread()
44        .enable_all()
45        .build()
46    {
47        Ok(runtime) => runtime,
48        Err(error) => {
49            eprintln!("failed to initialize async runtime: {error}");
50            return ExitCode::FAILURE;
51        }
52    };
53    runtime.block_on(commands::run(bootstrap_shutdown_token))
54}
55
56fn take_bootstrap_shutdown_token() -> Option<String> {
57    let token = std::env::var(bootstrap::state::BOOTSTRAP_SHUTDOWN_TOKEN_ENV)
58        .ok()
59        .filter(|token| !token.is_empty());
60    // SAFETY: this runs before the Tokio runtime and application threads are created.
61    unsafe {
62        std::env::remove_var(bootstrap::state::BOOTSTRAP_SHUTDOWN_TOKEN_ENV);
63    }
64    token
65}