Separate TUI preferences from server configuration (#42202)

## Why

TUI preferences and persistence paths belong to the local client, while thread
configuration and account requirements may come from the active app server.
Keeping both in the same resolved `Config` can replace live local preferences
when a thread is resumed, forked, reconnected, or switched.

## What changed

- Add `LocalSettings` as the TUI-owned source for UI, history, notice, and local
  persistence settings, and preserve it across session lifecycle transitions.
- Write preference changes to the selected user config file and reload local
  settings from disk when changing roots.
- Use the app server's account response for authentication-dependent onboarding
  and status UI instead of the local model-provider configuration.
- Retain platform family and OS metadata reported by remote app servers.

## Testing

- Cover local setting defaults, overrides, persistence destinations, reloads,
  and preservation across widget replacement and root switching.
- Cover remote platform metadata and server-controlled authentication UI.

GitOrigin-RevId: dbc2965fb1d6cbecb3f973f6133f3dcd4467b753
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-02 04:20:38 +00:00
1 parent 0b509e930e
commit 9d57be71ba
87 files changed
+1188 -459

No files matched your search

@@ -202,6 +202,7 @@ async fn shared_overview_seeds_once_and_retains_locally_resumed_history() -> Res
for thread_id in [ids[0], ids[21]] {
app_server
.resume_thread(
&app.local_settings,
config.clone(),
thread_id,
crate::app_server_session::ResumeModelSettings::PreserveExistingThread,
@@ -257,6 +258,7 @@ async fn shared_overview_seeds_once_and_retains_locally_resumed_history() -> Res
// Opening older history is a local addition, even without starting a turn.
let resumed = app_server
.resume_thread(
&app.local_settings,
config.clone(),
ids[1],
crate::app_server_session::ResumeModelSettings::PreserveExistingThread,
@@ -699,6 +701,45 @@ async fn failed_root_switch_keeps_background_requests_on_the_active_session() ->
Ok(())
}
#[tokio::test]
async fn root_switch_loads_local_preferences_from_disk() -> Result<()> {
let mut app = make_test_app().await;
let mut app_server =
crate::start_embedded_app_server_for_picker(app.chat_widget.config_ref()).await?;
let previous = app_server.start_thread(&app.config).await?;
app.enqueue_primary_thread_session(previous.session, previous.turns)
.await?;
let target_thread_id = ThreadId::from_string(
&app_test_support::create_fake_rollout(
app.config.codex_home.as_path(),
"2025-01-05T12-00-00",
"2025-01-05T12:00:00Z",
"Target task",
Some(&app.config.model_provider_id),
/*git_info*/ None,
)
.expect("materialize target rollout"),
)?;
std::fs::write(
app.local_settings.user_config_path.as_path(),
"[tui]\ntheme = \"dracula\"\nresume_cwd = \"session\"\n[history]\npersistence = \"none\"\n",
)?;
let config = app
.rebuild_config_for_cwd(app.config.cwd.to_path_buf())
.await?;
let expected = crate::local_settings::LocalSettings::from(&config);
let mut tui = crate::tui::test_support::make_test_tui()?;
app.select_agents_overview_thread(&mut tui, &mut app_server, target_thread_id)
.await?;
assert_eq!(app.current_displayed_thread_id(), Some(target_thread_id));
assert_eq!(app.local_settings, expected);
assert_eq!(app.chat_widget.local_settings, expected);
app_server.shutdown().await?;
Ok(())
}
#[tokio::test]
async fn root_switch_preserves_idle_root_with_running_subagent() -> Result<()> {
let mut app = make_test_app().await;
@@ -721,6 +762,7 @@ async fn root_switch_preserves_idle_root_with_running_subagent() -> Result<()> {
)?;
let target = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
target_thread_id,
crate::app_server_session::ResumeModelSettings::PreserveExistingThread,
@@ -801,6 +843,7 @@ async fn overview_selection_applies_user_permissions_only_to_unloaded_threads()
let mut app_server = crate::start_embedded_app_server_for_picker(&server_config).await?;
let loaded = app_server
.resume_thread(
&crate::local_settings::LocalSettings::from(&server_config),
server_config.clone(),
thread_ids[0],
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
@@ -861,6 +904,7 @@ async fn overview_selection_applies_user_permissions_only_to_unloaded_threads()
.await?;
let observed = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
thread_id,
crate::app_server_session::ResumeModelSettings::PreserveExistingThread,
@@ -961,6 +1005,7 @@ async fn overview_cold_resume_honors_working_directory_selection() -> Result<()>
.await?;
let observed = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
thread_id,
crate::app_server_session::ResumeModelSettings::PreserveExistingThread,