mirror of
https://github.com/openai/codex.git
synced 2026-11-30 00:10:49 +00:00
Reload TUI preferences from configuration layers (#64645)
## What changed Reload `LocalSettings` from the effective configuration layers while preserving the active transcript and alternate-screen modes. Reuse the prepared settings after folder trust changes and when starting a session from the agents overview. Pass `LocalSettings` directly to working-directory prompts, hook review, and history loading. Initial history loading uses a bounded item budget when local settings are unavailable. ## Testing Update the reload test to verify that layered preferences are applied while the active screen modes are preserved. Check the initial history budget when local settings are absent. GitOrigin-RevId: e02736b7bb29e00ddfd791afa778fc0d958d358a
This commit is contained in:
@@ -29,6 +29,7 @@ use crate::backend_id::BackendId;
|
||||
use crate::bottom_pane::BottomPaneView;
|
||||
use crate::chatwidget::ReadOnlyThread;
|
||||
use crate::chatwidget::ThreadInputStateRestoreMode;
|
||||
use crate::local_settings::LocalSettings;
|
||||
use crate::session_start::is_archived_session_error;
|
||||
use crate::startup_draft::StartupDraftPump;
|
||||
use codex_app_server_protocol::SessionSource;
|
||||
@@ -780,7 +781,7 @@ impl App {
|
||||
tui: &mut tui::Tui,
|
||||
app_server: &mut AppServerSession,
|
||||
root_thread_id: ThreadId,
|
||||
started: Option<(Config, crate::app_server_session::AppServerStartedThread)>,
|
||||
started: Option<((Config, LocalSettings), AppServerStartedThread)>,
|
||||
mut startup_draft: Option<&mut StartupDraftPump>,
|
||||
) -> color_eyre::Result<AppRunControl> {
|
||||
if self.windows_sandbox_blocks_thread_switch() {
|
||||
@@ -893,9 +894,10 @@ impl App {
|
||||
target_thread.status,
|
||||
codex_app_server_protocol::ThreadStatus::NotLoaded
|
||||
);
|
||||
let (prepared, started) = started.unzip();
|
||||
let preserve_explicit_permissions = unloaded || started.is_some();
|
||||
let (mut resume_config, mut local_settings) = if let Some((config, _)) = &started {
|
||||
(config.clone(), self.local_settings.reloaded(config))
|
||||
let (mut resume_config, mut local_settings) = if let Some(settings) = prepared {
|
||||
settings
|
||||
} else if unloaded {
|
||||
let target_session = SessionTarget {
|
||||
backend_id: app_server.backend_id(),
|
||||
@@ -1013,7 +1015,7 @@ impl App {
|
||||
} else {
|
||||
ThreadAttachPresentation::SessionLineage
|
||||
};
|
||||
let (resumed, read_only) = if let Some((_, started)) = started {
|
||||
let (resumed, read_only) = if let Some(started) = started {
|
||||
(started, None)
|
||||
} else if let Some(blank) = self
|
||||
.live_blank_session(tui, app_server, root_thread_id, &target_thread)
|
||||
@@ -1344,7 +1346,7 @@ impl App {
|
||||
app_server: &mut AppServerSession,
|
||||
cwd: Option<PathBuf>,
|
||||
mut startup_draft: Option<&mut StartupDraftPump>,
|
||||
) -> Option<(Config, Option<PathBuf>)> {
|
||||
) -> Option<(Config, LocalSettings, Option<PathBuf>)> {
|
||||
if self
|
||||
.chat_widget
|
||||
.thread_id()
|
||||
@@ -1377,7 +1379,7 @@ impl App {
|
||||
}
|
||||
};
|
||||
let trust_cwd = config.cwd.to_path_buf();
|
||||
if self
|
||||
let refreshed = self
|
||||
.confirm_directory_trust(
|
||||
tui,
|
||||
app_server,
|
||||
@@ -1387,10 +1389,7 @@ impl App {
|
||||
startup_draft.as_deref_mut(),
|
||||
)
|
||||
.await
|
||||
.is_err()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
.ok()?;
|
||||
if let Some(profile) = self.runtime_permission_profile_override.as_ref()
|
||||
&& profile.turn_override == RuntimePermissionProfileTurnOverride::LegacySandbox
|
||||
&& profile
|
||||
@@ -1424,11 +1423,20 @@ impl App {
|
||||
.unwrap_or(Path::new(".")),
|
||||
}
|
||||
.to_path_buf();
|
||||
let local_settings = match refreshed {
|
||||
Some(settings) => settings,
|
||||
None => match self.local_settings.reloaded(&config.config_layer_stack) {
|
||||
Ok(settings) => settings,
|
||||
Err(error) => {
|
||||
self.add_agents_overview_error(format!(
|
||||
"Failed to load project settings: {error}"
|
||||
));
|
||||
return None;
|
||||
}
|
||||
},
|
||||
};
|
||||
if let Some(draft) = startup_draft.as_deref_mut() {
|
||||
draft.apply_settings(
|
||||
&crate::local_settings::LocalSettings::from(&config),
|
||||
config.cwd.as_path(),
|
||||
);
|
||||
draft.apply_settings(&local_settings, config.cwd.as_path());
|
||||
}
|
||||
let mut server_model_cleared = false;
|
||||
match StartupDraftPump::run_with_optional_draft(
|
||||
@@ -1514,7 +1522,7 @@ impl App {
|
||||
.or_else(|| defaults.first())
|
||||
.map(|model| model.model.clone());
|
||||
}
|
||||
Some((config, remote_cwd))
|
||||
Some((config, local_settings, remote_cwd))
|
||||
}
|
||||
|
||||
pub(super) async fn stop_agents_overview_thread(
|
||||
|
||||
@@ -60,7 +60,7 @@ impl App {
|
||||
))
|
||||
});
|
||||
draft.apply_settings(
|
||||
&crate::local_settings::LocalSettings::from(self.chat_widget.config_ref()),
|
||||
&self.local_settings,
|
||||
cwd.as_deref()
|
||||
.unwrap_or(&self.chat_widget.session_cwd().to_path_buf()),
|
||||
);
|
||||
@@ -113,12 +113,9 @@ impl App {
|
||||
}
|
||||
self.cancel_cloud_inventory_refresh(app_server).await;
|
||||
// Keep folder consent and config loading off the session-start stack frame.
|
||||
let Some((config, remote_cwd)) = Box::pin(self.agents_overview_session_config(
|
||||
tui,
|
||||
app_server,
|
||||
cwd,
|
||||
startup_draft.as_deref_mut(),
|
||||
))
|
||||
let Some((config, local_settings, remote_cwd)) = Box::pin(
|
||||
self.agents_overview_session_config(tui, app_server, cwd, startup_draft.as_deref_mut()),
|
||||
)
|
||||
.await
|
||||
else {
|
||||
if let Some((_, checkout)) = &managed_worktree {
|
||||
@@ -152,10 +149,6 @@ impl App {
|
||||
display_label: active.id,
|
||||
})
|
||||
});
|
||||
let local_settings = self.local_settings.reloaded(&config);
|
||||
if let Some(draft) = startup_draft.as_deref_mut() {
|
||||
draft.apply_settings(&local_settings, config.cwd.as_path());
|
||||
}
|
||||
let result = StartupDraftPump::run_with_optional_draft(
|
||||
startup_draft.as_deref_mut(),
|
||||
tui,
|
||||
@@ -231,7 +224,7 @@ impl App {
|
||||
tui,
|
||||
app_server,
|
||||
thread_id,
|
||||
Some((config, started)),
|
||||
Some(((config, local_settings), started)),
|
||||
startup_draft,
|
||||
))
|
||||
.await?;
|
||||
@@ -273,7 +266,7 @@ impl App {
|
||||
);
|
||||
return;
|
||||
}
|
||||
let Some((config, _)) = self
|
||||
let Some((config, _, _)) = self
|
||||
.agents_overview_session_config(
|
||||
tui,
|
||||
app_server,
|
||||
|
||||
@@ -507,7 +507,7 @@ impl App {
|
||||
.rebuild_config_for_cwd(self.chat_widget.config_ref().cwd.to_path_buf())
|
||||
.await?;
|
||||
self.apply_runtime_policy_overrides(&mut config, RuntimePolicyOverrideScope::All)?;
|
||||
self.local_settings = self.local_settings.reloaded(&config);
|
||||
self.local_settings = self.local_settings.reloaded(&config.config_layer_stack)?;
|
||||
self.refresh_server_version_overview_notice(CODEX_CLI_VERSION);
|
||||
// Copy preferences read directly by the live widget. Other preferences have runtime
|
||||
// caches and are adopted when the widget is replaced.
|
||||
@@ -572,7 +572,7 @@ impl App {
|
||||
.await
|
||||
{
|
||||
Ok(config) => {
|
||||
let local_settings = fallback.1.reloaded(&config);
|
||||
let local_settings = fallback.1.reloaded(&config.config_layer_stack)?;
|
||||
Ok((config, local_settings))
|
||||
}
|
||||
Err(err) => {
|
||||
|
||||
@@ -153,7 +153,9 @@ impl App {
|
||||
// Stage local preferences and permission carryover without changing the active task.
|
||||
let (mut config, local_settings) = match refreshed_config {
|
||||
Ok(config) => {
|
||||
let local_settings = settings.local_settings.reloaded(&config);
|
||||
let local_settings = settings
|
||||
.local_settings
|
||||
.reloaded(&config.config_layer_stack)?;
|
||||
(config, local_settings)
|
||||
}
|
||||
Err(err) => {
|
||||
|
||||
@@ -64,14 +64,14 @@ impl App {
|
||||
RuntimePolicyOverrideScope::All,
|
||||
settings.config.approvals_reviewer,
|
||||
)?;
|
||||
Ok::<_, color_eyre::Report>(config)
|
||||
let local_settings = settings
|
||||
.local_settings
|
||||
.reloaded(&config.config_layer_stack)?;
|
||||
Ok::<_, color_eyre::Report>((config, local_settings))
|
||||
}
|
||||
.await;
|
||||
let (config, local_settings) = match refreshed {
|
||||
Ok(config) => {
|
||||
let local_settings = settings.local_settings.reloaded(&config);
|
||||
(config, local_settings)
|
||||
}
|
||||
Ok(refreshed) => refreshed,
|
||||
Err(error) => {
|
||||
tracing::warn!(%error, "failed to refresh resume settings; using stored backend configuration");
|
||||
(settings.config.clone(), settings.local_settings.clone())
|
||||
@@ -123,7 +123,7 @@ impl App {
|
||||
};
|
||||
let outcome = crate::session_resume::resolve_cwd_for_resume_or_fork(
|
||||
tui,
|
||||
¤t_config,
|
||||
&local_settings,
|
||||
history_cwd,
|
||||
CwdPromptAction::Resume,
|
||||
crate::session_resume::ResumeCwdContext {
|
||||
@@ -314,6 +314,14 @@ impl App {
|
||||
if result.directory_trust_persisted && self.current_displayed_thread_id().is_none() {
|
||||
self.windows_sandbox.prompt_after_trust = true;
|
||||
}
|
||||
let local_settings = local_settings
|
||||
.reloaded(&config.config_layer_stack)
|
||||
.map_err(|error| {
|
||||
self.add_session_picker_error(format!(
|
||||
"Failed to reload trusted folder settings: {error}"
|
||||
));
|
||||
AppRunControl::Continue
|
||||
})?;
|
||||
// Directory changes review hooks once, after attaching the destination.
|
||||
if result.directory_trust_persisted
|
||||
&& options.resumed_thread.is_none()
|
||||
@@ -324,10 +332,7 @@ impl App {
|
||||
config.cwd.to_path_buf(),
|
||||
);
|
||||
let hooks = if let Some(draft) = startup_draft {
|
||||
draft.apply_settings(
|
||||
&crate::local_settings::LocalSettings::from(&*config),
|
||||
config.cwd.as_path(),
|
||||
);
|
||||
draft.apply_settings(&local_settings, config.cwd.as_path());
|
||||
async {
|
||||
let hooks = draft.run_until(tui, load_hooks).await?;
|
||||
draft.flush_pending_events(tui).await?;
|
||||
@@ -346,7 +351,7 @@ impl App {
|
||||
match maybe_run_startup_hooks_review(
|
||||
app_server,
|
||||
tui,
|
||||
config,
|
||||
&local_settings,
|
||||
config.bypass_hook_trust,
|
||||
hooks,
|
||||
)
|
||||
@@ -364,7 +369,7 @@ impl App {
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(Some(local_settings.reloaded(config)));
|
||||
return Ok(Some(local_settings));
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
@@ -2195,7 +2195,7 @@ async fn microphone_channel_is_machine_local_across_project_and_remote_transitio
|
||||
);
|
||||
for cwd in [project.path(), remote.path()] {
|
||||
let config = app.rebuild_config_for_cwd(cwd.to_path_buf()).await?;
|
||||
let reloaded = app.local_settings.reloaded(&config);
|
||||
let reloaded = app.local_settings.reloaded(&config.config_layer_stack)?;
|
||||
assert_eq!(reloaded.audio, app.chat_widget.local_settings.audio);
|
||||
assert_eq!(
|
||||
reloaded.audio.as_ref().unwrap().microphone_channel,
|
||||
@@ -2212,7 +2212,7 @@ async fn microphone_channel_is_machine_local_across_project_and_remote_transitio
|
||||
let config = app
|
||||
.rebuild_config_for_cwd(project.path().to_path_buf())
|
||||
.await?;
|
||||
app.chat_widget.local_settings = app.local_settings.reloaded(&config);
|
||||
app.chat_widget.local_settings = app.local_settings.reloaded(&config.config_layer_stack)?;
|
||||
assert!(app.chat_widget.local_settings.audio.is_err());
|
||||
app.chat_widget.open_realtime_sound_devices();
|
||||
assert!(!app.chat_widget.has_active_view());
|
||||
|
||||
@@ -259,7 +259,7 @@ impl App {
|
||||
}
|
||||
},
|
||||
};
|
||||
if config.active_project.trust_level.is_none() {
|
||||
let refreshed = if config.active_project.trust_level.is_none() {
|
||||
if let Some(message) = check_background_terminals(
|
||||
app_server,
|
||||
&self.app_server_target,
|
||||
@@ -270,7 +270,7 @@ impl App {
|
||||
{
|
||||
return self.working_directory_error(message);
|
||||
}
|
||||
if self
|
||||
match self
|
||||
.confirm_directory_trust(
|
||||
tui,
|
||||
app_server,
|
||||
@@ -283,11 +283,13 @@ impl App {
|
||||
/*startup_draft*/ None,
|
||||
)
|
||||
.await
|
||||
.is_err()
|
||||
{
|
||||
return;
|
||||
Ok(settings) => settings,
|
||||
Err(_) => return,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some((_, checkout, crate::app_event::ManagedWorktreeMode::Fork, _)) =
|
||||
managed_worktree.as_ref()
|
||||
&& with_terminal_visualization_instructions(
|
||||
@@ -395,7 +397,13 @@ impl App {
|
||||
{
|
||||
return;
|
||||
}
|
||||
let local_settings = self.local_settings.reloaded(&config);
|
||||
let local_settings = match refreshed {
|
||||
Some(settings) => settings,
|
||||
None => match self.local_settings.reloaded(&config.config_layer_stack) {
|
||||
Ok(settings) => settings,
|
||||
Err(error) => return self.chat_widget.add_error_message(error.to_string()),
|
||||
},
|
||||
};
|
||||
let keymap = match RuntimeKeymap::for_session(
|
||||
&local_settings.tui.keymap,
|
||||
local_settings.workspace_enabled(&config),
|
||||
|
||||
@@ -1742,11 +1742,10 @@ impl AppServerSession {
|
||||
let Some(model) = config.model.as_deref().or(self.default_model.as_deref()) else {
|
||||
return config.clone();
|
||||
};
|
||||
let local_settings = LocalSettings::from(config);
|
||||
let mut session_config = config.clone();
|
||||
match service_tier_resolution::service_tier_update_for_core(
|
||||
config,
|
||||
&local_settings.notices,
|
||||
&config.notices,
|
||||
model,
|
||||
&self.available_models,
|
||||
) {
|
||||
@@ -2737,9 +2736,8 @@ fn remove_permission_config_overrides(config: &mut Option<HashMap<String, serde_
|
||||
}
|
||||
|
||||
fn service_tier_override_from_config(config: &Config) -> Option<Option<String>> {
|
||||
let local_settings = LocalSettings::from(config);
|
||||
config.service_tier.clone().map(Some).or_else(|| {
|
||||
(local_settings.notices.fast_default_opt_out == Some(true))
|
||||
(config.notices.fast_default_opt_out == Some(true))
|
||||
.then(|| Some(SERVICE_TIER_DEFAULT_REQUEST_VALUE.to_string()))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ use std::collections::HashSet;
|
||||
use super::AppServerSession;
|
||||
use crate::history_cell::HistoryRenderMode;
|
||||
use crate::legacy_core::config::Config;
|
||||
use crate::local_settings::LocalSettings;
|
||||
use crate::terminal_capabilities::resize_reflow_max_rows;
|
||||
use crate::thread_transcript::RawReasoningVisibility;
|
||||
use crate::thread_transcript::thread_items_to_transcript_cells;
|
||||
@@ -54,15 +53,12 @@ struct HistoryLoadBudget {
|
||||
impl HistoryLoadBudget {
|
||||
fn new(
|
||||
scope: HistoryHydrationScope<'_>,
|
||||
config: Option<&Config>,
|
||||
local_settings: Option<&crate::local_settings::LocalSettings>,
|
||||
terminal_height: u16,
|
||||
) -> Self {
|
||||
use HistoryHydrationScope::CloudRecovery;
|
||||
|
||||
let transcript_mode = local_settings
|
||||
.map(|settings| settings.transcript_mode)
|
||||
.or_else(|| config.map(|config| LocalSettings::from(config).transcript_mode));
|
||||
let transcript_mode = local_settings.map(|settings| settings.transcript_mode);
|
||||
if scope == CloudRecovery
|
||||
|| (scope == HistoryHydrationScope::Initial
|
||||
&& transcript_mode.is_some_and(crate::transcript_mode::TranscriptMode::is_owned))
|
||||
@@ -76,7 +72,7 @@ impl HistoryLoadBudget {
|
||||
}
|
||||
let rows = local_settings
|
||||
.and_then(|settings| resize_reflow_max_rows(settings.terminal_resize_reflow()));
|
||||
let items = match (scope, config, rows) {
|
||||
let items = match (scope, local_settings, rows) {
|
||||
(HistoryHydrationScope::Complete | HistoryHydrationScope::FullTranscript, _, _)
|
||||
| (HistoryHydrationScope::ThroughTurn(_) | CloudRecovery, _, _)
|
||||
| (HistoryHydrationScope::Initial, Some(_), None) => None,
|
||||
@@ -478,7 +474,7 @@ impl AppServerSession {
|
||||
};
|
||||
let (width, height) = crossterm::terminal::size().unwrap_or(/*default*/ (80, 24));
|
||||
let width = width.max(/*other*/ 1);
|
||||
let budget = HistoryLoadBudget::new(scope, config, local_settings, height);
|
||||
let budget = HistoryLoadBudget::new(scope, local_settings, height);
|
||||
let mut scanned_items = 0;
|
||||
let mut rendered_rows = 0;
|
||||
while let Some(limit) = budget.next_page_size(rendered_rows, scanned_items) {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
use super::HistoryHydrationScope;
|
||||
use super::HistoryLoadBudget;
|
||||
use super::advancing_cursor;
|
||||
use crate::legacy_core::config::ConfigBuilder;
|
||||
use crate::legacy_core::config::TerminalResizeReflowMaxRows;
|
||||
use crate::local_settings::LocalSettings;
|
||||
use codex_config::types::AltScreenMode;
|
||||
use crate::transcript_mode::TranscriptMode;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::HashSet;
|
||||
|
||||
@@ -33,21 +31,14 @@ fn advancing_cursor_rejects_repeated_cursors() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn owned_initial_history_stops_after_viewport_or_scan_budget() {
|
||||
let codex_home = tempfile::tempdir().expect("temporary codex home");
|
||||
let mut config = ConfigBuilder::default()
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.build()
|
||||
.await
|
||||
.expect("config");
|
||||
config.tui_fullscreen_transcript = true;
|
||||
config.tui_alternate_screen = AltScreenMode::Always;
|
||||
config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Disabled;
|
||||
let local_settings = LocalSettings::from(&config);
|
||||
#[test]
|
||||
fn owned_initial_history_stops_after_viewport_or_scan_budget() {
|
||||
let home = codex_utils_absolute_path::AbsolutePathBuf::current_dir().unwrap();
|
||||
let mut local_settings = LocalSettings::from_layers(&home, &Default::default()).unwrap();
|
||||
local_settings.transcript_mode = TranscriptMode::Owned;
|
||||
local_settings.tui.terminal_resize_reflow_max_rows = Some(0);
|
||||
let budget = HistoryLoadBudget::new(
|
||||
HistoryHydrationScope::Initial,
|
||||
Some(&config),
|
||||
Some(&local_settings),
|
||||
/*terminal_height*/ 10,
|
||||
);
|
||||
@@ -64,18 +55,16 @@ async fn owned_initial_history_stops_after_viewport_or_scan_budget() {
|
||||
);
|
||||
|
||||
// Recovery remains bounded even when terminal scrollback is unlimited.
|
||||
config.tui_fullscreen_transcript = false;
|
||||
local_settings.transcript_mode = TranscriptMode::Terminal;
|
||||
let recovery = HistoryLoadBudget::new(
|
||||
HistoryHydrationScope::CloudRecovery,
|
||||
Some(&config),
|
||||
Some(&LocalSettings::from(&config)),
|
||||
Some(&local_settings),
|
||||
/*terminal_height*/ 10,
|
||||
);
|
||||
assert_eq!((recovery.rows, recovery.items), (budget.rows, budget.items));
|
||||
|
||||
let complete = HistoryLoadBudget::new(
|
||||
HistoryHydrationScope::Complete,
|
||||
Some(&config),
|
||||
/*local_settings*/ None,
|
||||
/*terminal_height*/ 10,
|
||||
);
|
||||
@@ -84,21 +73,13 @@ async fn owned_initial_history_stops_after_viewport_or_scan_budget() {
|
||||
Some(100),
|
||||
);
|
||||
|
||||
config.tui_fullscreen_transcript = false;
|
||||
// The mode selected at launch wins even if thread config changes or is unavailable.
|
||||
for config in [Some(&config), None] {
|
||||
let budget = HistoryLoadBudget::new(
|
||||
HistoryHydrationScope::Initial,
|
||||
config,
|
||||
Some(&local_settings),
|
||||
/*terminal_height*/ 10,
|
||||
);
|
||||
assert_eq!(
|
||||
[
|
||||
budget.next_page_size(/*rendered_rows*/ 0, /*scanned_items*/ 0),
|
||||
budget.next_page_size(/*rendered_rows*/ 30, /*scanned_items*/ 11),
|
||||
],
|
||||
[Some(30), None],
|
||||
);
|
||||
}
|
||||
let without_settings = HistoryLoadBudget::new(
|
||||
HistoryHydrationScope::Initial,
|
||||
/*local_settings*/ None,
|
||||
/*terminal_height*/ 10,
|
||||
);
|
||||
assert_eq!(
|
||||
without_settings.items,
|
||||
Some(super::HISTORY_ITEM_PAGE_LIMIT as usize)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ use std::path::Path;
|
||||
use crate::bottom_pane::picker_option_list;
|
||||
use crate::bottom_pane::render_menu_surface;
|
||||
use crate::key_hint;
|
||||
use crate::legacy_core::config::Config;
|
||||
use crate::legacy_core::config::edit::ConfigEditsBuilder;
|
||||
use crate::local_settings::LocalSettings;
|
||||
use crate::render::Insets;
|
||||
@@ -112,7 +111,7 @@ impl CwdSelection {
|
||||
|
||||
pub(crate) async fn run_cwd_selection_prompt(
|
||||
tui: &mut Tui,
|
||||
config: &Config,
|
||||
local_settings: &LocalSettings,
|
||||
action: CwdPromptAction,
|
||||
current_cwd: &Path,
|
||||
session_cwd: &Path,
|
||||
@@ -156,8 +155,7 @@ pub(crate) async fn run_cwd_selection_prompt(
|
||||
Ok(CwdPromptOutcome::Exit)
|
||||
} else {
|
||||
let selection = screen.selection().unwrap_or(CwdSelection::Session);
|
||||
if let Some(error_line) =
|
||||
persist_remembered_cwd_selection(&LocalSettings::from(config), selection).await
|
||||
if let Some(error_line) = persist_remembered_cwd_selection(local_settings, selection).await
|
||||
{
|
||||
tui.insert_history_lines(vec![error_line]);
|
||||
}
|
||||
|
||||
@@ -941,7 +941,8 @@ fn backend_preference_local_cwd(
|
||||
async fn resolve_startup_resume_or_fork_cwd(
|
||||
backend_id: crate::backend_id::BackendId,
|
||||
tui: &mut Tui,
|
||||
config: &Config,
|
||||
current_cwd: &Path,
|
||||
local_settings: &LocalSettings,
|
||||
app_server: Option<&mut AppServerSession>,
|
||||
session_selection: &resume_picker::SessionSelection,
|
||||
cwd_override: Option<&Path>,
|
||||
@@ -960,7 +961,6 @@ async fn resolve_startup_resume_or_fork_cwd(
|
||||
return Ok(ResolveCwdOutcome::Continue(None));
|
||||
};
|
||||
target_session.ensure_backend(backend_id)?;
|
||||
let local_settings = crate::local_settings::LocalSettings::from(config);
|
||||
let resume_cwd_mode = effective_resume_cwd_mode(local_settings.tui.resume_cwd, cwd_override);
|
||||
if uses_remote_workspace_or_environment
|
||||
&& cwd_override.is_none()
|
||||
@@ -971,7 +971,7 @@ async fn resolve_startup_resume_or_fork_cwd(
|
||||
);
|
||||
}
|
||||
if uses_remote_workspace {
|
||||
return Ok(ResolveCwdOutcome::Continue(Some(config.cwd.to_path_buf())));
|
||||
return Ok(ResolveCwdOutcome::Continue(Some(current_cwd.to_path_buf())));
|
||||
}
|
||||
|
||||
let history_cwd = if matches!(resume_cwd_mode, Some(ResumeCwdMode::Current)) {
|
||||
@@ -985,12 +985,12 @@ async fn resolve_startup_resume_or_fork_cwd(
|
||||
};
|
||||
resolve_cwd_for_resume_or_fork(
|
||||
tui,
|
||||
config,
|
||||
local_settings,
|
||||
history_cwd,
|
||||
action,
|
||||
ResumeCwdContext {
|
||||
current_cwd: config.cwd.as_path(),
|
||||
remembered_current_cwd: config.cwd.as_path(),
|
||||
current_cwd,
|
||||
remembered_current_cwd: current_cwd,
|
||||
allow_remember_current: !uses_remote_workspace_or_environment || cwd_override.is_some(),
|
||||
mode: resume_cwd_mode,
|
||||
},
|
||||
@@ -1832,7 +1832,8 @@ async fn run_ratatui_app(
|
||||
let fallback_cwd = match resolve_startup_resume_or_fork_cwd(
|
||||
backend_id,
|
||||
&mut tui,
|
||||
&config,
|
||||
config.cwd.as_path(),
|
||||
&local_settings,
|
||||
app_server.as_mut(),
|
||||
&session_selection,
|
||||
cli.cwd.as_deref(),
|
||||
@@ -2360,7 +2361,7 @@ async fn run_ratatui_app(
|
||||
let startup_hooks_review = maybe_run_startup_hooks_review(
|
||||
&mut app_server,
|
||||
&mut tui,
|
||||
&config,
|
||||
&local_settings,
|
||||
bypass_hook_trust_for_startup_review,
|
||||
startup_hooks_entry,
|
||||
)
|
||||
|
||||
@@ -535,7 +535,8 @@ async fn startup_resume_and_fork_use_configured_or_explicit_cwd() -> color_eyre:
|
||||
let fallback_cwd = match resolve_startup_resume_or_fork_cwd(
|
||||
backend_id,
|
||||
&mut tui,
|
||||
&config,
|
||||
config.cwd.as_path(),
|
||||
&LocalSettings::from_layers(&config.codex_home, &config.config_layer_stack)?,
|
||||
/*app_server*/ None,
|
||||
&session_selection,
|
||||
cwd_override,
|
||||
@@ -625,7 +626,8 @@ async fn startup_remote_current_cwd_without_override_is_rejected() -> color_eyre
|
||||
let error = resolve_startup_resume_or_fork_cwd(
|
||||
backend_id,
|
||||
&mut tui,
|
||||
&config,
|
||||
config.cwd.as_path(),
|
||||
&LocalSettings::from_layers(&config.codex_home, &config.config_layer_stack)?,
|
||||
/*app_server*/ None,
|
||||
&resume_picker::SessionSelection::Resume(resume_picker::SessionTarget {
|
||||
backend_id,
|
||||
@@ -648,7 +650,8 @@ async fn startup_remote_current_cwd_without_override_is_rejected() -> color_eyre
|
||||
let explicit = resolve_startup_resume_or_fork_cwd(
|
||||
backend_id,
|
||||
&mut tui,
|
||||
&config,
|
||||
config.cwd.as_path(),
|
||||
&LocalSettings::from_layers(&config.codex_home, &config.config_layer_stack)?,
|
||||
/*app_server*/ None,
|
||||
&resume_picker::SessionSelection::Resume(resume_picker::SessionTarget {
|
||||
backend_id,
|
||||
@@ -686,7 +689,8 @@ async fn startup_session_cwd_without_metadata_is_rejected() -> color_eyre::Resul
|
||||
let error = resolve_startup_resume_or_fork_cwd(
|
||||
backend_id,
|
||||
&mut tui,
|
||||
&config,
|
||||
config.cwd.as_path(),
|
||||
&LocalSettings::from_layers(&config.codex_home, &config.config_layer_stack)?,
|
||||
/*app_server*/ None,
|
||||
&resume_picker::SessionSelection::Resume(resume_picker::SessionTarget {
|
||||
backend_id,
|
||||
|
||||
@@ -236,8 +236,8 @@ impl LocalSettings {
|
||||
}
|
||||
|
||||
/// Refresh editable preferences without changing this launch's terminal ownership.
|
||||
pub(crate) fn reloaded(&self, config: &Config) -> Self {
|
||||
let mut settings = Self::from(config);
|
||||
pub(crate) fn reloaded(&self, layers: &ConfigLayerStack) -> std::io::Result<Self> {
|
||||
let mut settings = Self::from_layers(&self.codex_home, layers)?;
|
||||
settings.transcript_mode = self.transcript_mode;
|
||||
settings.tui.alternate_screen = self.tui.alternate_screen;
|
||||
// Generic reloads do not update these values in the live UI. The config panel updates
|
||||
@@ -247,7 +247,7 @@ impl LocalSettings {
|
||||
settings.tui.effects.starfield = self.tui.effects.starfield;
|
||||
settings.tui.disable_paste_burst = self.tui.disable_paste_burst;
|
||||
settings.tui.show_tooltips = self.tui.show_tooltips;
|
||||
settings
|
||||
Ok(settings)
|
||||
}
|
||||
|
||||
/// Copy on release unless the default copy shortcut reaches the application.
|
||||
|
||||
@@ -33,6 +33,26 @@ async fn launch_screen_mode_survives_configuration_reload() -> anyhow::Result<()
|
||||
config.disable_paste_burst = false;
|
||||
config.show_tooltips = true;
|
||||
|
||||
let layers = config
|
||||
.config_layer_stack
|
||||
.clone()
|
||||
.with_session_config(toml::from_str(
|
||||
r#"[tui]
|
||||
fullscreen_transcript = false
|
||||
copy_on_select = "never"
|
||||
copy_on_select_clear_selection = false
|
||||
right_click_paste = "off"
|
||||
alternate_screen = "never"
|
||||
theme = "nord"
|
||||
animations = false
|
||||
auto_recap = false
|
||||
effects.starfield = false
|
||||
disable_paste_burst = true
|
||||
show_tooltips = false
|
||||
"#,
|
||||
)?)?;
|
||||
let refreshed = LocalSettings::from_layers(&config.codex_home, &layers)?;
|
||||
|
||||
for (alternate_screen, owned, expected_mode, expected_alt) in [
|
||||
(true, true, TranscriptMode::Owned, AltScreenMode::Auto),
|
||||
(true, false, TranscriptMode::Terminal, AltScreenMode::Auto),
|
||||
@@ -47,19 +67,7 @@ async fn launch_screen_mode_survives_configuration_reload() -> anyhow::Result<()
|
||||
(expected_mode, expected_alt),
|
||||
);
|
||||
|
||||
let mut reloaded_config = config.clone();
|
||||
reloaded_config.tui_fullscreen_transcript = false;
|
||||
reloaded_config.tui_copy_on_select = CopyOnSelect::Never;
|
||||
reloaded_config.tui_copy_on_select_clear_selection = false;
|
||||
reloaded_config.tui_right_click_paste = RightClickPaste::Off;
|
||||
reloaded_config.tui_alternate_screen = AltScreenMode::Never;
|
||||
reloaded_config.tui_theme = Some("nord".into());
|
||||
reloaded_config.animations = false;
|
||||
reloaded_config.tui_auto_recap = false;
|
||||
reloaded_config.tui_effects.starfield = false;
|
||||
reloaded_config.disable_paste_burst = true;
|
||||
reloaded_config.show_tooltips = false;
|
||||
let mut expected_reload = LocalSettings::from(&reloaded_config);
|
||||
let mut expected_reload = refreshed.clone();
|
||||
expected_reload.transcript_mode = expected_mode;
|
||||
expected_reload.tui.alternate_screen = expected_alt;
|
||||
expected_reload.tui.animations = local.tui.animations;
|
||||
@@ -67,15 +75,12 @@ async fn launch_screen_mode_survives_configuration_reload() -> anyhow::Result<()
|
||||
expected_reload.tui.effects.starfield = local.tui.effects.starfield;
|
||||
expected_reload.tui.disable_paste_burst = local.tui.disable_paste_burst;
|
||||
expected_reload.tui.show_tooltips = local.tui.show_tooltips;
|
||||
assert_eq!(local.reloaded(&reloaded_config), expected_reload);
|
||||
assert_eq!(local.reloaded(&layers)?, expected_reload);
|
||||
|
||||
let mut expected_launch = LocalSettings::from(&reloaded_config);
|
||||
let mut expected_launch = refreshed.clone();
|
||||
expected_launch.transcript_mode = expected_mode;
|
||||
expected_launch.tui.alternate_screen = expected_alt;
|
||||
assert_eq!(
|
||||
LocalSettings::from(&reloaded_config).for_tui(&tui),
|
||||
expected_launch
|
||||
);
|
||||
assert_eq!(refreshed.clone().for_tui(&tui), expected_launch);
|
||||
tui.set_owned_screen(/*owned*/ false)?;
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::app_server_session::AppServerSession;
|
||||
use crate::cwd_prompt;
|
||||
use crate::cwd_prompt::CwdPromptAction;
|
||||
use crate::cwd_prompt::CwdPromptOutcome;
|
||||
use crate::legacy_core::config::Config;
|
||||
use crate::local_settings::LocalSettings;
|
||||
use crate::tui::Tui;
|
||||
use codex_config::types::ResumeCwdMode;
|
||||
use codex_protocol::ThreadId;
|
||||
@@ -83,7 +83,7 @@ pub(crate) async fn read_session_cwd(
|
||||
|
||||
pub(crate) async fn resolve_cwd_for_resume_or_fork(
|
||||
tui: &mut Tui,
|
||||
config: &Config,
|
||||
local_settings: &LocalSettings,
|
||||
history_cwd: Option<PathBuf>,
|
||||
action: CwdPromptAction,
|
||||
cwd_context: ResumeCwdContext<'_>,
|
||||
@@ -110,7 +110,7 @@ pub(crate) async fn resolve_cwd_for_resume_or_fork(
|
||||
if cwds_differ(cwd_context.current_cwd, &history_cwd) {
|
||||
let selection_outcome = cwd_prompt::run_cwd_selection_prompt(
|
||||
tui,
|
||||
config,
|
||||
local_settings,
|
||||
action,
|
||||
cwd_context.current_cwd,
|
||||
&history_cwd,
|
||||
@@ -161,7 +161,7 @@ mod tests {
|
||||
] {
|
||||
let outcome = resolve_cwd_for_resume_or_fork(
|
||||
&mut tui,
|
||||
&config,
|
||||
&LocalSettings::from_layers(&config.codex_home, &config.config_layer_stack)?,
|
||||
Some(session_cwd.clone()),
|
||||
CwdPromptAction::Fork,
|
||||
ResumeCwdContext {
|
||||
@@ -190,7 +190,7 @@ mod tests {
|
||||
|
||||
let outcome = resolve_cwd_for_resume_or_fork(
|
||||
&mut tui,
|
||||
&config,
|
||||
&LocalSettings::from_layers(&config.codex_home, &config.config_layer_stack)?,
|
||||
Some(current_cwd.clone()),
|
||||
CwdPromptAction::Resume,
|
||||
ResumeCwdContext {
|
||||
@@ -218,7 +218,7 @@ mod tests {
|
||||
|
||||
let error = resolve_cwd_for_resume_or_fork(
|
||||
&mut tui,
|
||||
&config,
|
||||
&LocalSettings::from_layers(&config.codex_home, &config.config_layer_stack)?,
|
||||
/*history_cwd*/ None,
|
||||
CwdPromptAction::Resume,
|
||||
ResumeCwdContext {
|
||||
|
||||
@@ -28,7 +28,7 @@ use crate::hooks_rpc::hook_needs_review;
|
||||
use crate::hooks_rpc::write_hook_trusts;
|
||||
use crate::keymap::ListAction;
|
||||
use crate::keymap::RuntimeKeymap;
|
||||
use crate::legacy_core::config::Config;
|
||||
use crate::local_settings::LocalSettings;
|
||||
use crate::render::renderable::ColumnRenderable;
|
||||
use crate::render::renderable::Renderable;
|
||||
use crate::terminal_program_status::StartupDialog;
|
||||
@@ -71,7 +71,7 @@ pub(crate) async fn load_startup_hooks_review_entry(
|
||||
pub(crate) async fn maybe_run_startup_hooks_review(
|
||||
app_server: &mut AppServerSession,
|
||||
tui: &mut Tui,
|
||||
config: &Config,
|
||||
local_settings: &LocalSettings,
|
||||
bypass_hook_trust: bool,
|
||||
entry: HooksListEntry,
|
||||
) -> Result<StartupHooksReviewOutcome> {
|
||||
@@ -79,16 +79,15 @@ pub(crate) async fn maybe_run_startup_hooks_review(
|
||||
return Ok(StartupHooksReviewOutcome::Continue);
|
||||
}
|
||||
|
||||
run_startup_hooks_review_app(app_server, tui, config, entry).await
|
||||
run_startup_hooks_review_app(app_server, tui, local_settings, entry).await
|
||||
}
|
||||
|
||||
async fn run_startup_hooks_review_app(
|
||||
app_server: &mut AppServerSession,
|
||||
tui: &mut Tui,
|
||||
config: &Config,
|
||||
local_settings: &LocalSettings,
|
||||
entry: HooksListEntry,
|
||||
) -> Result<StartupHooksReviewOutcome> {
|
||||
let local_settings = crate::local_settings::LocalSettings::from(config);
|
||||
let keymap = RuntimeKeymap::from_config(&local_settings.tui.keymap)
|
||||
.map_err(|err| color_eyre::eyre::eyre!(err))?;
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
|
||||
Reference in New Issue
Block a user