Use app-server state for TUI Windows sandbox decisions (#45821)

## Why

Windows sandbox setup and permission choices need to reflect the connected app server's requirements and the active thread's executors.

## What changed

- Refresh sandbox configuration and requirements for the current working directory when threads or directories change, before setup, and after setup completes.
- Use the thread's observed environments to determine whether sandbox setup is local, remote, mixed, or unknown.
- Defer initial prompt submission while requirements load and preserve the draft if loading fails or required setup is unavailable.
- Hide sandbox setup choices and elevation commands that requirements or executor selection disallow.

## Testing

Add coverage for observed thread hosts, app-server configuration reads, draft preservation and recovery after read failures, deferred initial prompts, and non-admin-only setup choices.

GitOrigin-RevId: d85ac66d18951b752e71d1a6bf25404eeedcad02
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-16 01:01:26 +00:00
1 parent f2b5b81f39
commit 73db60e71f
27 files changed
+476 -341

No files matched your search

+15 -34
View File
@@ -682,39 +682,17 @@ impl App {
AppServerTarget::LocalDaemon { .. }
));
let thread_and_widget_ms = thread_and_widget_started_at.elapsed().as_millis();
let windows_sandbox_host =
windows_sandbox_host(&app_server_target, environment_manager.as_ref());
chat_widget.windows_sandbox_host = windows_sandbox_host;
let windows_sandbox_host_is_local = windows_sandbox_host == WindowsSandboxHost::Local;
#[cfg(target_os = "windows")]
let sandbox_ready =
if windows_sandbox_host_is_local && chat_widget.required_elevated_windows_sandbox() {
windows_sandbox_ready(&mut app_server).await
} else {
false
};
#[cfg(not(target_os = "windows"))]
let sandbox_ready = false;
#[cfg(target_os = "windows")]
if sandbox_ready {
chat_widget.windows_sandbox_elevated_setup_complete = true;
}
chat_widget.maybe_prompt_windows_sandbox_enable(
should_prompt_windows_sandbox_nux_at_startup
&& windows_sandbox_host_is_local
&& !sandbox_ready,
);
#[cfg(target_os = "windows")]
if windows_sandbox_host == WindowsSandboxHost::Mixed
&& should_prompt_windows_sandbox_nux_at_startup
{
app_event_tx.send(AppEvent::InsertHistoryCell(Box::new(
history_cell::StartupWarningsCell::new(vec![
"Windows sandbox setup is unavailable when local and remote executors are configured together."
.to_string(),
]),
)));
}
chat_widget.windows_sandbox_local_server = !app_server_target.uses_remote_workspace()
&& app_server.app_server_platform_os() == Some("windows");
chat_widget.windows_sandbox_host = if app_server_target.uses_remote_workspace() {
WindowsSandboxHost::Remote
} else {
initial_started_thread
.as_ref()
.map_or(WindowsSandboxHost::Unknown, |started| {
started.session.windows_sandbox_host
})
};
let file_search = FileSearchManager::new(config.cwd.to_path_buf(), app_event_tx.clone());
let runtime_keymap =
RuntimeKeymap::from_config(&local_settings.tui.keymap).map_err(|err| {
@@ -780,7 +758,10 @@ See the Codex keymap documentation for supported actions and examples."
},
pending_update_action: None,
pending_shutdown_exit_thread_id: None,
windows_sandbox: WindowsSandboxState::default(),
windows_sandbox: WindowsSandboxState {
prompt_after_trust: should_prompt_windows_sandbox_nux_at_startup,
..Default::default()
},
thread_event_channels: HashMap::new(),
pending_realtime_speech_replay: HashMap::new(),
pending_realtime_transcript_replay: HashMap::new(),