mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
## What changed - Register an additional Cloud connection on supported macOS and Linux launches when `TuiMultiBackend` is enabled, using the selected ChatGPT account and local network policy. - Preserve backend settings and identify Cloud in connection controls and status. - Let Cloud supply the model when a thread opens, skip local skills requests and stale results, and allow resume without a local working-directory override. - Preserve Git metadata in Cloud thread snapshots and continue history hydration past empty filtered pages within the scan budget. - Report Cloud connection failures and require reopening Codex to reconnect. ## Testing Add regression coverage for Cloud model bootstrap, skipped skills requests, resume directory handling, history pagination through filtered pages, and Git metadata preservation. GitOrigin-RevId: 6717f0f5ad7708c5e9b5796d94711dd1eecc49bb
149 lines
6.1 KiB
Rust
149 lines
6.1 KiB
Rust
//! Exit output distinguishes a disconnected client from a stopped embedded server.
|
|
//! Persisted sessions offer a direct UUID command and an optional named picker hint.
|
|
|
|
use super::*;
|
|
use crate::RemoteAppServerEndpoint;
|
|
use crate::exec_command::escape_command;
|
|
use crate::status::remote_connection::sanitized_websocket_url;
|
|
|
|
/// A persisted thread that can be resumed after the TUI exits.
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct ResumableThread {
|
|
pub thread_id: ThreadId,
|
|
pub thread_name: Option<String>,
|
|
}
|
|
|
|
/// Reconnection and stop guidance for a task owned by a persistent app server.
|
|
#[derive(Debug, Clone)]
|
|
pub struct DisconnectInfo {
|
|
/// CLI arguments identifying the server, without credential values.
|
|
pub command: Vec<String>,
|
|
pub stop_hint: String,
|
|
}
|
|
|
|
impl App {
|
|
pub(super) fn exit_info(&self, exit_reason: ExitReason) -> AppExitInfo {
|
|
let thread_id = self.chat_widget.thread_id().or(self.primary_thread_id);
|
|
let disconnect_info = thread_id.and_then(|_| {
|
|
let command = match &self.app_server_target {
|
|
AppServerTarget::Embedded | AppServerTarget::Cloud => return None,
|
|
AppServerTarget::LocalDaemon { .. } => vec!["codex".to_string()],
|
|
AppServerTarget::Remote { endpoint } => {
|
|
let address = match endpoint {
|
|
RemoteAppServerEndpoint::WebSocket { websocket_url, .. } => {
|
|
sanitized_websocket_url(websocket_url)
|
|
.and_then(|url| {
|
|
let host = url.host()?;
|
|
let port = url.port_or_known_default()?;
|
|
// The CLI requires an explicit port, including 80/443.
|
|
Some(format!("{}://{host}:{port}{}", url.scheme(), url.path()))
|
|
})
|
|
.unwrap_or_else(|| "<server-address>".to_string())
|
|
}
|
|
RemoteAppServerEndpoint::UnixSocket { socket_path } => {
|
|
format!("unix://{}", socket_path.display())
|
|
}
|
|
};
|
|
vec!["codex".to_string(), "--remote".to_string(), address]
|
|
}
|
|
};
|
|
let stop_hint = self
|
|
.keymap
|
|
.agents
|
|
.primary_hint("stop", &self.keymap.agents.stop)
|
|
.map_or_else(
|
|
|| "use the configured stop shortcut".to_string(),
|
|
|key| format!("press {}", key.display_label()),
|
|
);
|
|
Some(DisconnectInfo { command, stop_hint })
|
|
});
|
|
AppExitInfo {
|
|
token_usage: self.token_usage(),
|
|
thread_id,
|
|
resume_hint: resumable_thread(
|
|
thread_id,
|
|
self.chat_widget.thread_name(),
|
|
self.chat_widget.rollout_path().as_deref(),
|
|
),
|
|
disconnect_info,
|
|
update_action: self.pending_update_action,
|
|
exit_reason,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl AppExitInfo {
|
|
/// Format the terminal summary for both the CLI and standalone TUI binaries.
|
|
pub fn format_exit_messages(self, color_enabled: bool) -> Vec<String> {
|
|
let color_command = |command: String| {
|
|
if color_enabled {
|
|
format!("\u{1b}[36m{command}\u{1b}[39m")
|
|
} else {
|
|
command
|
|
}
|
|
};
|
|
let mut lines = Vec::new();
|
|
if let Some(disconnect) = self.disconnect_info
|
|
&& let Some(thread_id) = self.thread_id
|
|
{
|
|
let turn_interrupted = matches!(self.exit_reason, ExitReason::TurnInterrupted);
|
|
let message = match self.exit_reason {
|
|
ExitReason::UserRequested => {
|
|
"Disconnected from this task. Any running work continues."
|
|
}
|
|
ExitReason::Fatal(_) => "Disconnected from this task. Work may still be running.",
|
|
ExitReason::TurnInterrupted => {
|
|
"Disconnected from this task. The current turn was stopped."
|
|
}
|
|
};
|
|
lines.push(message.to_string());
|
|
let mut resume_command = disconnect.command.clone();
|
|
resume_command.extend(["resume".to_string(), thread_id.to_string()]);
|
|
lines.push("To reconnect, run:".to_string());
|
|
lines.push(format!(
|
|
" {}",
|
|
color_command(escape_command(&resume_command)),
|
|
));
|
|
if !turn_interrupted {
|
|
let mut agents_command = disconnect.command;
|
|
agents_command.push("agents".to_string());
|
|
lines.push(format!(
|
|
"Stop the current turn: run {}, select this task, and {}.",
|
|
color_command(escape_command(&agents_command)),
|
|
disconnect.stop_hint,
|
|
));
|
|
}
|
|
if !self.token_usage.is_zero() {
|
|
let usage = self.token_usage.to_string();
|
|
lines.push(if turn_interrupted {
|
|
usage
|
|
} else {
|
|
usage.replacen("Token usage:", "Token usage so far:", /*count*/ 1)
|
|
});
|
|
}
|
|
return lines;
|
|
}
|
|
|
|
if !self.token_usage.is_zero() {
|
|
lines.push(self.token_usage.to_string());
|
|
}
|
|
if let Some(thread) = self.resume_hint {
|
|
lines.push("To continue this session, run:".to_string());
|
|
lines.push(format!(
|
|
" {}",
|
|
color_command(format!("codex resume {}", thread.thread_id)),
|
|
));
|
|
if let Some(thread_name) = thread.thread_name.filter(|name| !name.is_empty()) {
|
|
lines.push(format!(
|
|
"Or run {} and select {}.",
|
|
color_command("codex resume".to_string()),
|
|
color_command(thread_name),
|
|
));
|
|
}
|
|
} else if let Some(thread_id) = self.thread_id {
|
|
lines.push(format!("Session ID: {thread_id}"));
|
|
}
|
|
lines
|
|
}
|
|
}
|