mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
1752f374a8
## Description
This PR makes `codex remote-control` behave like a foreground CLI
command by default. Running it now starts remote control, waits for
readiness, prints a clear status message with the machine name, and
stays alive until Ctrl-C.
Users who want daemon behavior can use `codex remote-control start`, and
`codex remote-control stop` now prints concise human-readable output.
`--json` remains available for scripts.
Implementation-wise, this now verifies the real app-server state instead
of just assuming startup worked. The CLI starts or connects to
app-server, probes its control socket, calls the `remoteControl/enable`
API, and waits for the remote-control status response/notification
before printing success.
For daemon mode, `codex remote-control start` also reports which managed
app-server binary was used, including its path and best-effort `codex
--version`, so failures are easier to diagnose.
## Examples
Example output:
```
> codex remote-control
Starting app-server with remote control enabled...
This machine is available for remote control as com-97826.
Press Ctrl-C to stop.
```
Error case using daemon (currently expected based on our publicly
released CLI version):
```
> ./target/debug/codex remote-control start
Starting app-server daemon with remote control enabled...
Error: app server did not become ready on /Users/owen/.codex/app-server-control/app-server-control.sock
Daemon used app-server:
path: /Users/owen/.codex/packages/standalone/current/codex
version: 0.130.0
Managed app-server stderr (/Users/owen/.codex/app-server-daemon/app-server.stderr.log):
error: unexpected argument '--remote-control' found
Usage: codex app-server [OPTIONS] [COMMAND]
For more information, try '--help'.
Caused by:
0: failed to connect to /Users/owen/.codex/app-server-control/app-server-control.sock
1: No such file or directory (os error 2)
```
## What changed
- `codex remote-control` now runs remote control in the foreground and
prints a Ctrl-C stop hint.
- `codex remote-control start` starts the daemon and waits for remote
control readiness before reporting success.
- `codex remote-control stop` reports stopped/not-running status in
plain language.
- Startup failures now include recent managed app-server stderr to make
daemon issues easier to diagnose.
- Added coverage for CLI output, readiness waiting, foreground shutdown,
and stderr log tailing.
47 lines
1.2 KiB
Rust
47 lines
1.2 KiB
Rust
mod pid;
|
|
|
|
use std::path::Path;
|
|
use std::path::PathBuf;
|
|
|
|
use serde::Serialize;
|
|
|
|
pub(crate) use pid::PidBackend;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub enum BackendKind {
|
|
Pid,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub(crate) struct BackendPaths {
|
|
pub(crate) codex_bin: PathBuf,
|
|
pub(crate) pid_file: PathBuf,
|
|
pub(crate) update_pid_file: PathBuf,
|
|
pub(crate) remote_control_enabled: bool,
|
|
}
|
|
|
|
pub(crate) fn pid_backend(paths: BackendPaths) -> PidBackend {
|
|
PidBackend::new(
|
|
paths.codex_bin,
|
|
paths.pid_file,
|
|
paths.remote_control_enabled,
|
|
)
|
|
}
|
|
|
|
pub(crate) fn pid_update_loop_backend(paths: BackendPaths) -> PidBackend {
|
|
PidBackend::new_update_loop(paths.codex_bin, paths.update_pid_file)
|
|
}
|
|
|
|
pub(crate) async fn append_stderr_log_tail_context(pid_file: &Path, context: &mut String) {
|
|
match pid::read_stderr_log_tail(pid_file).await {
|
|
Ok(Some(tail)) => tail.append_to_context(context),
|
|
Ok(None) => {}
|
|
Err(err) => {
|
|
context.push_str(&format!(
|
|
"\n\nFailed to read managed app-server stderr log: {err:#}"
|
|
));
|
|
}
|
|
}
|
|
}
|