mirror of
https://github.com/openai/codex.git
synced 2026-05-20 19:23:21 +00:00
## Why reapplies https://github.com/openai/codex/pull/22386 which was previously reverted Also, introduce `remoteControl/enable` and `remoteControl/disable` app-server APIs to toggle on/off remote control at runtime for a given running app-server instance. ## What Changed - Adds experimental v2 RPCs: - `remoteControl/enable` - `remoteControl/disable` - Adds `RemoteControlRequestProcessor` and routes the new RPCs through it instead of `ConfigRequestProcessor`. - Adds named `RemoteControlHandle::enable`, `disable`, and `status` methods. - Makes `remoteControl/enable` return an error when sqlite state DB is unavailable, while keeping enrollment/websocket failures as async status updates. - Adds `AppServerRuntimeOptions.remote_control_enabled` and hidden `--remote-control` flags for `codex app-server` and `codex-app-server`. - Updates managed daemon startup to use `codex app-server --remote-control --listen unix://`. - Marks `Feature::RemoteControl` as removed and ignores `[features].remote_control`. - Updates app-server README entries for the new remote-control methods.
125 lines
4.0 KiB
Rust
125 lines
4.0 KiB
Rust
use clap::Parser;
|
|
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;
|
|
|
|
// 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";
|
|
|
|
#[derive(Debug, Parser)]
|
|
struct AppServerArgs {
|
|
/// Transport endpoint URL. Supported values: `stdio://` (default),
|
|
/// `unix://`, `unix://PATH`, `ws://IP:PORT`, `off`.
|
|
#[arg(
|
|
long = "listen",
|
|
value_name = "URL",
|
|
default_value = AppServerTransport::DEFAULT_LISTEN_URL
|
|
)]
|
|
listen: AppServerTransport,
|
|
|
|
/// Session source used to derive product restrictions and metadata.
|
|
#[arg(
|
|
long = "session-source",
|
|
value_name = "SOURCE",
|
|
default_value = "vscode",
|
|
value_parser = SessionSource::from_startup_arg
|
|
)]
|
|
session_source: SessionSource,
|
|
|
|
#[command(flatten)]
|
|
auth: AppServerWebsocketAuthArgs,
|
|
|
|
/// Fail if config.toml contains unknown configuration fields.
|
|
#[arg(long = "strict-config", default_value_t = false)]
|
|
strict_config: bool,
|
|
|
|
/// Hidden debug-only test hook used by integration tests that spawn the
|
|
/// production app-server binary.
|
|
#[cfg(debug_assertions)]
|
|
#[arg(long = "disable-plugin-startup-tasks-for-tests", hide = true)]
|
|
disable_plugin_startup_tasks_for_tests: bool,
|
|
|
|
/// Enable remote control for this app-server process.
|
|
#[arg(long = "remote-control", hide = true)]
|
|
remote_control: bool,
|
|
}
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
arg0_dispatch_or_else(|arg0_paths: Arg0DispatchPaths| async move {
|
|
let AppServerArgs {
|
|
listen,
|
|
session_source,
|
|
auth,
|
|
strict_config,
|
|
#[cfg(debug_assertions)]
|
|
disable_plugin_startup_tasks_for_tests,
|
|
remote_control,
|
|
} = 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::default();
|
|
#[cfg(debug_assertions)]
|
|
if disable_plugin_startup_tasks_for_tests {
|
|
runtime_options.plugin_startup_tasks = PluginStartupTasks::Skip;
|
|
}
|
|
runtime_options.remote_control_enabled = remote_control;
|
|
|
|
run_main_with_transport_options(
|
|
arg0_paths,
|
|
CliConfigOverrides::default(),
|
|
loader_overrides,
|
|
strict_config,
|
|
/*default_analytics_enabled*/ false,
|
|
transport,
|
|
session_source,
|
|
auth,
|
|
runtime_options,
|
|
)
|
|
.await?;
|
|
Ok(())
|
|
})
|
|
}
|
|
|
|
fn disable_managed_config_from_debug_env() -> bool {
|
|
#[cfg(debug_assertions)]
|
|
{
|
|
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> {
|
|
#[cfg(debug_assertions)]
|
|
{
|
|
if let Ok(value) = std::env::var(MANAGED_CONFIG_PATH_ENV_VAR) {
|
|
return if value.is_empty() {
|
|
None
|
|
} else {
|
|
Some(PathBuf::from(value))
|
|
};
|
|
}
|
|
}
|
|
|
|
None
|
|
}
|