Download codex-rs/app-server/src/main.rs from SaylorTwift/codex: direct link, hf CLI and curl.
- Browser
- Download file 5.57 kB
-
https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/app-server/src/main.rs
- Command line
-
hf download hf://SaylorTwift/codex/codex-rs/app-server/src/main.rs
-
curl -L -o main.rs https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/app-server/src/main.rs
5.57 kB
| use clap::Parser; | |
| use codex_app_server::AppServerCodeModeHostArgs; | |
| use codex_app_server::AppServerRuntimeOptions; | |
| use codex_app_server::AppServerTransport; | |
| use codex_app_server::AppServerWebsocketAuthArgs; | |
| use codex_app_server::PluginStartupTasks; | |
| use codex_app_server::run_main_with_transport_options; | |
| use codex_arg0::Arg0DispatchPaths; | |
| use codex_arg0::arg0_dispatch_or_else; | |
| use codex_config::LoaderOverrides; | |
| use codex_protocol::protocol::SessionSource; | |
| use codex_utils_cli::CliConfigOverrides; | |
| use std::path::PathBuf; | |
| static ALLOCATOR: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; | |
| // Debug-only test hook: lets integration tests point the server at a temporary | |
| // managed config file without writing to /etc. | |
| const MANAGED_CONFIG_PATH_ENV_VAR: &str = "CODEX_APP_SERVER_MANAGED_CONFIG_PATH"; | |
| const DISABLE_MANAGED_CONFIG_ENV_VAR: &str = "CODEX_APP_SERVER_DISABLE_MANAGED_CONFIG"; | |
| struct AppServerArgs { | |
| config_overrides: CliConfigOverrides, | |
| code_mode_host: AppServerCodeModeHostArgs, | |
| /// Transport endpoint URL. Supported values: `stdio://` (default), | |
| /// `unix://`, `unix://PATH`, `ws://IP:PORT`, `off`. | |
| listen: AppServerTransport, | |
| /// Session source used to derive product restrictions and metadata. | |
| session_source: SessionSource, | |
| auth: AppServerWebsocketAuthArgs, | |
| /// Fail if config.toml contains unknown configuration fields. | |
| strict_config: bool, | |
| /// Hidden debug-only test hook used by integration tests that spawn the | |
| /// production app-server binary. | |
| disable_plugin_startup_tasks_for_tests: bool, | |
| /// Enable remote control for this app-server process without changing persistence. | |
| remote_control: bool, | |
| /// Save loaded threads during managed daemon shutdown. | |
| managed_daemon: bool, | |
| } | |
| fn main() -> anyhow::Result<()> { | |
| let remote_control_disabled = codex_app_server::take_remote_control_disabled_env(); | |
| arg0_dispatch_or_else(move |arg0_paths: Arg0DispatchPaths| async move { | |
| let AppServerArgs { | |
| config_overrides, | |
| code_mode_host, | |
| listen, | |
| session_source, | |
| auth, | |
| strict_config, | |
| disable_plugin_startup_tasks_for_tests, | |
| remote_control, | |
| managed_daemon, | |
| } = AppServerArgs::parse(); | |
| let loader_overrides = if disable_managed_config_from_debug_env() { | |
| LoaderOverrides::without_managed_config_for_tests() | |
| } else { | |
| managed_config_path_from_debug_env() | |
| .map(LoaderOverrides::with_managed_config_path_for_tests) | |
| .unwrap_or_default() | |
| }; | |
| let transport = listen; | |
| let auth = auth.try_into_settings()?; | |
| let mut runtime_options = AppServerRuntimeOptions { | |
| code_mode_host_transport: code_mode_host.into(), | |
| managed_daemon, | |
| ..Default::default() | |
| }; | |
| if disable_plugin_startup_tasks_for_tests { | |
| runtime_options.plugin_startup_tasks = PluginStartupTasks::Skip; | |
| } | |
| runtime_options.remote_control_startup_mode = | |
| match (remote_control, remote_control_disabled) { | |
| (true, _) => codex_app_server::RemoteControlStartupMode::EnabledEphemeral, | |
| (false, true) => codex_app_server::RemoteControlStartupMode::DisabledEphemeral, | |
| (false, false) => codex_app_server::RemoteControlStartupMode::ResolvePersisted, | |
| }; | |
| let exit = run_main_with_transport_options( | |
| arg0_paths, | |
| config_overrides, | |
| loader_overrides, | |
| strict_config, | |
| /*default_analytics_enabled*/ false, | |
| transport, | |
| session_source, | |
| auth, | |
| runtime_options, | |
| ) | |
| .await?; | |
| if exit == codex_app_server::AppServerExit::Forced { | |
| // Runtime teardown can wait forever for blocked rollout I/O. | |
| std::process::exit(0); | |
| } | |
| Ok(()) | |
| }) | |
| } | |
| fn disable_managed_config_from_debug_env() -> bool { | |
| { | |
| if let Ok(value) = std::env::var(DISABLE_MANAGED_CONFIG_ENV_VAR) { | |
| return matches!(value.as_str(), "1" | "true" | "TRUE" | "yes" | "YES"); | |
| } | |
| } | |
| false | |
| } | |
| fn managed_config_path_from_debug_env() -> Option<PathBuf> { | |
| { | |
| if let Ok(value) = std::env::var(MANAGED_CONFIG_PATH_ENV_VAR) { | |
| return if value.is_empty() { | |
| None | |
| } else { | |
| Some(PathBuf::from(value)) | |
| }; | |
| } | |
| } | |
| None | |
| } | |
| mod tests; | |