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

+23 -11
View File
@@ -75,7 +75,6 @@ use crate::diff_model::FileChange;
use crate::legacy_core::config::ConfigBuilder;
use crate::legacy_core::config::ConfigOverrides;
use crate::legacy_core::config::PermissionProfileSnapshot;
use crate::legacy_core::config::TerminalResizeReflowMaxRows;
use codex_app_server_client::AppServerPath;
use codex_app_server_protocol::AdditionalFileSystemPermissions;
use codex_app_server_protocol::AdditionalNetworkPermissions;
@@ -563,6 +562,8 @@ async fn enqueue_primary_thread_session_replays_turns_before_initial_prompt_subm
let config = app.config.clone();
let model = get_model_offline_for_tests(config.model.as_deref());
app.chat_widget = ChatWidget::new_with_app_event(ChatWidgetInit {
requires_openai_auth: true,
local_settings: crate::local_settings::LocalSettings::from(&config),
config,
frame_requester: crate::tui::FrameRequester::test_dummy(),
app_event_tx: app.app_event_tx.clone(),
@@ -2280,6 +2281,7 @@ fn selected_and_resumed_threads_use_server_capability_for_v1_and_v2_children() -
crate::start_embedded_app_server_for_picker(app.chat_widget.config_ref()).await?;
let root = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
root_thread_id,
crate::app_server_session::ResumeModelSettings::PreserveExistingThread,
@@ -2358,6 +2360,7 @@ fn selected_and_resumed_threads_use_server_capability_for_v1_and_v2_children() -
let resumed = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
child_thread_ids[1],
app.resume_model_settings(),
@@ -2539,6 +2542,7 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<()
let mut app_server = Box::pin(crate::start_embedded_app_server_for_picker(&config)).await?;
let started = app_server
.resume_thread(
&crate::local_settings::LocalSettings::from(&config),
config,
parent_thread_id,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
@@ -5317,6 +5321,7 @@ async fn render_clear_ui_header_after_long_transcript_for_snapshot() -> String {
};
Arc::new(new_session_info(
app.chat_widget.config_ref(),
&app.local_settings,
app.chat_widget.current_model(),
&session,
is_first,
@@ -5434,6 +5439,7 @@ async fn make_test_app() -> App {
workspace_command_runner: None,
launch_cwd: config.cwd.to_path_buf(),
runtime_working_directory_override: None,
local_settings: crate::local_settings::LocalSettings::from(&config),
config,
state_db: None,
cli_kv_overrides: Vec::new(),
@@ -5517,6 +5523,7 @@ async fn make_test_app_with_channels() -> (
workspace_command_runner: None,
launch_cwd: config.cwd.to_path_buf(),
runtime_working_directory_override: None,
local_settings: crate::local_settings::LocalSettings::from(&config),
config,
state_db: None,
cli_kv_overrides: Vec::new(),
@@ -5843,7 +5850,7 @@ fn rendered_line_text(line: &crate::terminal_hyperlinks::HyperlinkLine) -> Strin
#[tokio::test]
async fn capped_resize_reflow_renders_recent_suffix_only() {
let (mut app, _rx, _op_rx) = make_test_app_with_channels().await;
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Limit(5);
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(5);
app.transcript_cells = (0..20)
.map(|i| plain_line_cell(format!("cell {i}")))
.collect();
@@ -5871,7 +5878,7 @@ async fn capped_resize_reflow_renders_recent_suffix_only() {
#[tokio::test]
async fn uncapped_resize_reflow_renders_all_cells_when_row_cap_absent() {
let (mut app, _rx, _op_rx) = make_test_app_with_channels().await;
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Disabled;
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(0);
app.transcript_cells = (0..20)
.map(|i| plain_line_cell(format!("cell {i}")))
.collect();
@@ -5886,7 +5893,7 @@ async fn uncapped_resize_reflow_renders_all_cells_when_row_cap_absent() {
#[tokio::test]
async fn resize_reflow_wraps_transcript_early_when_pet_is_enabled() {
let (mut app, _rx, _op_rx) = make_test_app_with_channels().await;
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Disabled;
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(0);
app.transcript_cells = vec![Arc::new(AgentMarkdownCell::new(
"alpha beta gamma delta epsilon zeta eta theta iota kappa lambda".to_string(),
Path::new("/tmp"),
@@ -5983,7 +5990,7 @@ async fn copy_picker_opening_preserves_terminal_scrollback_without_reflow() {
#[tokio::test]
async fn uncapped_resize_reflow_renders_all_cells_under_row_limit() {
let (mut app, _rx, _op_rx) = make_test_app_with_channels().await;
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Limit(100);
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(100);
app.transcript_cells = (0..3)
.map(|i| plain_line_cell(format!("cell {i}")))
.collect();
@@ -6009,7 +6016,7 @@ async fn uncapped_resize_reflow_renders_all_cells_under_row_limit() {
#[tokio::test]
async fn initial_replay_buffer_keeps_recent_rows_when_row_cap_present() {
let (mut app, _rx, _op_rx) = make_test_app_with_channels().await;
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Limit(3);
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(3);
app.begin_initial_history_replay_buffer();
for index in 0..5 {
@@ -6043,7 +6050,7 @@ async fn initial_replay_buffer_keeps_recent_rows_when_row_cap_present() {
#[tokio::test]
async fn required_stream_reflow_during_capped_initial_replay_uses_transcript_tail() -> Result<()> {
let (mut app, _rx, _op_rx) = make_test_app_with_channels().await;
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Limit(20);
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(20);
app.transcript_cells = vec![
plain_line_cell("latest user question"),
Arc::new(AgentMarkdownCell::new(
@@ -6097,7 +6104,7 @@ async fn required_stream_reflow_during_capped_initial_replay_uses_transcript_tai
#[tokio::test]
async fn directive_only_completion_removes_streamed_directive() -> Result<()> {
let (mut app, _rx, _op_rx) = make_test_app_with_channels().await;
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Limit(20);
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(20);
app.begin_initial_history_replay_buffer();
app.transcript_cells = vec![
plain_line_cell("before directive"),
@@ -6134,7 +6141,7 @@ async fn directive_only_completion_removes_streamed_directive() -> Result<()> {
async fn required_stream_reflow_during_capped_initial_replay_survives_transcript_overlay()
-> Result<()> {
let (mut app, _rx, _op_rx) = make_test_app_with_channels().await;
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Limit(7);
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(7);
app.transcript_cells = vec![
plain_line_cell("latest user question"),
Arc::new(AgentMessageCell::new(
@@ -6194,7 +6201,7 @@ async fn required_stream_reflow_during_capped_initial_replay_survives_transcript
#[tokio::test]
async fn thread_switch_replay_buffer_uses_transcript_tail_mode_when_row_cap_present() {
let (mut app, _rx, _op_rx) = make_test_app_with_channels().await;
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Limit(3);
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(3);
app.begin_thread_switch_history_replay_buffer();
@@ -6209,7 +6216,7 @@ async fn thread_switch_replay_buffer_uses_transcript_tail_mode_when_row_cap_pres
#[tokio::test]
async fn thread_switch_replay_buffer_is_disabled_without_row_cap() {
let (mut app, _rx, _op_rx) = make_test_app_with_channels().await;
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Disabled;
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(0);
app.begin_thread_switch_history_replay_buffer();
@@ -6665,6 +6672,7 @@ async fn backtrack_selection_preserves_selected_prompt_and_requests_branch() {
};
Arc::new(new_session_info(
app.chat_widget.config_ref(),
&app.local_settings,
app.chat_widget.current_model(),
&session,
is_first,
@@ -7319,6 +7327,7 @@ async fn prompt_edit_forks_before_selected_prompt_and_preserves_source() -> Resu
let mut app_server = Box::pin(crate::start_embedded_app_server_for_picker(&config)).await?;
let started = app_server
.resume_thread(
&crate::local_settings::LocalSettings::from(&config),
config.clone(),
source_thread_id,
crate::app_server_session::ResumeModelSettings::OverrideFromCurrentConfig,
@@ -7458,6 +7467,7 @@ async fn prompt_edit_before_first_prompt_starts_fresh_thread() -> Result<()> {
let mut app_server = Box::pin(crate::start_embedded_app_server_for_picker(&config)).await?;
let started = app_server
.resume_thread(
&crate::local_settings::LocalSettings::from(&config),
config.clone(),
source_thread_id,
crate::app_server_session::ResumeModelSettings::OverrideFromCurrentConfig,
@@ -7606,6 +7616,8 @@ async fn replace_chat_widget_reseeds_collab_agent_metadata_for_replay() {
);
let replacement = ChatWidget::new_with_app_event(ChatWidgetInit {
requires_openai_auth: true,
local_settings: crate::local_settings::LocalSettings::from(&app.config),
config: app.config.clone(),
frame_requester: crate::tui::FrameRequester::test_dummy(),
app_event_tx: app.app_event_tx.clone(),