Add a dedicated codex agents dashboard command (#39114)

## What changed

- Add `codex agents` to open the shared agents overview without creating a new session.
- Start the local background app server automatically on Unix, or connect to a server supplied with `--remote`.
- Reject invocation-specific session overrides that cannot apply to shared sessions.
- When the overview is opened from an embedded session, offer to start the background server without moving or interrupting the current session.

## Testing

- Cover command-line parsing and rejection of incompatible overrides.
- Snapshot the embedded-session background-server prompt.

GitOrigin-RevId: 60845dfebc48d820dc4ff090626d30452127f062
This commit is contained in:
Eric Traut authored and copyberry committed 2026-08-18 00:31:51 +00:00
1 parent 13dfaab446
commit fd5018e044
14 files changed
+343 -30

No files matched your search

+86 -4
View File
@@ -4,6 +4,10 @@ use super::agents_overview_view::AgentsOverviewGroup;
use super::agents_overview_view::AgentsOverviewRow;
use super::agents_overview_view::AgentsOverviewView;
use super::*;
use crate::bottom_pane::SelectionDescriptionLayout;
use crate::bottom_pane::SelectionItem;
use crate::bottom_pane::SelectionViewParams;
use crate::bottom_pane::popup_consts::standard_popup_hint_line_for_keymap;
use crate::chatwidget::ThreadInputStateRestoreMode;
use codex_app_server_protocol::RequestId;
use codex_app_server_protocol::SessionSource;
@@ -38,10 +42,51 @@ pub(super) struct AgentsOverviewState {
impl App {
pub(super) fn open_agents_overview(&mut self, app_server: &AppServerSession) {
if matches!(self.app_server_target, AppServerTarget::Embedded) {
self.chat_widget.add_info_message(
"The shared agents dashboard requires a background app server.".to_string(),
/*hint*/ None,
);
let workload_identity_selected = codex_login::is_workload_identity_selected();
self.chat_widget.show_selection_view(SelectionViewParams {
title: Some("Shared agents unavailable".to_string()),
subtitle: Some(
if workload_identity_selected {
"The agents dashboard is unavailable while workload identity is active."
} else if cfg!(unix) {
"This session isn’t connected to a shared background server."
} else {
"Connect to a remote background server to use the agents dashboard."
}
.to_string(),
),
footer_note: (cfg!(unix) && !workload_identity_selected).then(|| {
Line::from(
"Starting a background server will not interrupt or move this session."
.dim(),
)
}),
footer_hint: Some(standard_popup_hint_line_for_keymap(&self.keymap.list)),
items: [
#[cfg(unix)]
(!workload_identity_selected).then(|| SelectionItem {
name: "Start background server".to_string(),
description: Some(
"Open `codex agents` in another terminal afterward.".to_string(),
),
actions: vec![Box::new(|tx| tx.send(AppEvent::StartAgentsDaemon))],
dismiss_on_select: true,
..Default::default()
}),
Some(SelectionItem {
name: "Return to this session".to_string(),
dismiss_on_select: true,
..Default::default()
}),
]
.into_iter()
.flatten()
.collect(),
description_layout: SelectionDescriptionLayout::StackBelowWhenNarrow {
min_description_width: 28,
},
..Default::default()
});
return;
}
@@ -647,6 +692,43 @@ impl App {
self.refresh_agents_overview_threads(app_server);
}
}
#[cfg(unix)]
pub(super) fn start_agents_daemon(&self) {
let app_event_tx = self.app_event_tx.clone();
tokio::spawn(async move {
let result = async {
let current_executable =
std::env::current_exe().map_err(|error| error.to_string())?;
let executable = if current_executable
.file_stem()
.is_some_and(|name| name == "codex-tui")
{
current_executable.with_file_name("codex")
} else {
current_executable
};
let output = tokio::process::Command::new(executable)
.args(["app-server", "daemon", "start"])
.output()
.await
.map_err(|error| error.to_string())?;
if output.status.success() {
Ok(())
} else {
let message = String::from_utf8_lossy(&output.stderr).trim().to_string();
Err(if message.is_empty() {
format!("daemon process exited with {}", output.status)
} else {
message
})
}
}
.await;
app_event_tx.send(AppEvent::AgentsDaemonStarted { result });
});
}
}
#[cfg(test)]
@@ -254,6 +254,25 @@ async fn shared_overview_shows_only_root_sessions() {
assert!(app.last_rendered_history_tail.is_some());
}
#[cfg(unix)]
#[tokio::test]
async fn embedded_sessions_offer_to_start_a_background_server_without_migrating() {
let mut app = make_test_app().await;
let app_server = crate::start_embedded_app_server_for_picker(app.chat_widget.config_ref())
.await
.expect("embedded app server");
app.open_agents_overview(&app_server);
insta::with_settings!({snapshot_path => "../snapshots"}, {
insta::assert_snapshot!(
"agents_overview_embedded",
render_bottom_popup(&app.chat_widget, /*width*/ 96)
);
});
app_server.shutdown().await.expect("shutdown app server");
}
#[tokio::test]
async fn failed_root_switch_keeps_background_requests_on_the_active_session() -> Result<()> {
let mut app = make_test_app().await;
+21 -1
View File
@@ -191,7 +191,9 @@ impl App {
}
}
}
SessionSelection::Exit | SessionSelection::StartFresh => {
SessionSelection::Exit
| SessionSelection::StartFresh
| SessionSelection::AgentsOverview => {
self.refresh_in_memory_config_from_disk_best_effort(
"closing the session picker",
)
@@ -2326,6 +2328,9 @@ impl App {
.select_agents_overview_thread(tui, app_server, thread_id)
.await?
{
AppRunControl::Continue if self.primary_thread_id.is_none() => {
self.open_agents_overview(app_server);
}
AppRunControl::Continue => {}
AppRunControl::Exit(reason) => return Ok(AppRunControl::Exit(reason)),
}
@@ -2348,6 +2353,21 @@ impl App {
self.stop_agents_overview_thread(app_server, thread_id)
.await;
}
#[cfg(unix)]
AppEvent::StartAgentsDaemon => {
self.start_agents_daemon();
}
#[cfg(unix)]
AppEvent::AgentsDaemonStarted { result } => match result {
Ok(()) => self.chat_widget.add_info_message(
"Background server started. Run `codex agents` in another terminal; this session remains unchanged."
.to_string(),
/*hint*/ None,
),
Err(error) => self
.chat_widget
.add_error_message(format!("Failed to start the background server: {error}")),
},
AppEvent::OpenAgentPicker => {
self.open_agent_picker(app_server).await;
}
+34 -17
View File
@@ -122,7 +122,9 @@ impl App {
let bootstrap_ms = bootstrap.duration.as_millis();
if matches!(
&session_selection,
SessionSelection::StartFresh | SessionSelection::Exit
SessionSelection::StartFresh
| SessionSelection::Exit
| SessionSelection::AgentsOverview
) {
apply_managed_new_thread_defaults(
&mut config,
@@ -222,23 +224,33 @@ impl App {
&session_selection,
SessionSelection::StartFresh | SessionSelection::Exit
);
let start_in_agents_overview =
matches!(&session_selection, SessionSelection::AgentsOverview);
let (mut chat_widget, initial_started_thread) = match session_selection {
SessionSelection::StartFresh | SessionSelection::Exit => {
spawn_startup_thread_start(&app_server, config.clone(), app_event_tx.clone());
SessionSelection::StartFresh
| SessionSelection::Exit
| SessionSelection::AgentsOverview => {
if !start_in_agents_overview {
spawn_startup_thread_start(&app_server, config.clone(), app_event_tx.clone());
}
// Count a startup tooltip once the initial chat widget can render it.
let startup_tooltip_override = match startup_draft
.run_until(
tui,
prepare_startup_tooltip_override(
&mut config,
&available_models,
is_first_run,
),
)
.await
{
Ok(tooltip_override) => tooltip_override,
Err(err) => return shutdown_on_startup_error(app_server, err).await,
let startup_tooltip_override = if start_in_agents_overview {
None
} else {
match startup_draft
.run_until(
tui,
prepare_startup_tooltip_override(
&mut config,
&available_models,
is_first_run,
),
)
.await
{
Ok(tooltip_override) => tooltip_override,
Err(err) => return shutdown_on_startup_error(app_server, err).await,
}
};
let init = crate::chatwidget::ChatWidgetInit {
config: config.clone(),
@@ -268,7 +280,9 @@ impl App {
session_telemetry: session_telemetry.clone(),
};
let mut chat_widget = ChatWidget::new_with_app_event(init);
chat_widget.set_queue_submissions_until_session_configured(/*queue*/ true);
chat_widget.set_queue_submissions_until_session_configured(
/*queue*/ !start_in_agents_overview,
);
(chat_widget, None)
}
SessionSelection::Resume(target_session) => {
@@ -451,6 +465,9 @@ See the Codex keymap documentation for supported actions and examples."
pending_plugin_enabled_writes: HashMap::new(),
pending_hook_enabled_writes: HashMap::new(),
};
if start_in_agents_overview {
app.open_agents_overview(&app_server);
}
if let Some(entry) = startup_hooks_browser {
app.chat_widget.open_hooks_browser(entry);
}
+3
View File
@@ -40,6 +40,9 @@ fn startup_waiting_gate_is_only_for_fresh_or_exit_session_selection() {
App::should_wait_for_initial_session(&SessionSelection::Exit),
true
);
assert!(!App::should_wait_for_initial_session(
&SessionSelection::AgentsOverview
));
assert_eq!(
App::should_wait_for_initial_session(&SessionSelection::Resume(
crate::resume_picker::SessionTarget {