mirror of
https://github.com/openai/codex.git
synced 2026-04-30 11:21:34 +03:00
Prompt to turn on windows sandbox when auto mode selected. (#6618)
- stop prompting users to install WSL - prompt users to turn on Windows sandbox when auto mode requested. <img width="1660" height="195" alt="Screenshot 2025-11-17 110612" src="https://github.com/user-attachments/assets/c67fc239-a227-417e-94bb-599a8ed8f11e" /> <img width="1684" height="168" alt="Screenshot 2025-11-17 110637" src="https://github.com/user-attachments/assets/d18c3370-830d-4971-8746-04757ae2f709" /> <img width="1655" height="293" alt="Screenshot 2025-11-17 110719" src="https://github.com/user-attachments/assets/d21f6ce9-c23e-4842-baf6-8938b77c16db" />
This commit is contained in:
@@ -3,6 +3,3 @@ pub mod onboarding_screen;
|
||||
mod trust_directory;
|
||||
pub use trust_directory::TrustDirectorySelection;
|
||||
mod welcome;
|
||||
mod windows;
|
||||
|
||||
pub(crate) use windows::WSL_INSTRUCTIONS;
|
||||
|
||||
@@ -20,7 +20,6 @@ use crate::onboarding::auth::SignInState;
|
||||
use crate::onboarding::trust_directory::TrustDirectorySelection;
|
||||
use crate::onboarding::trust_directory::TrustDirectoryWidget;
|
||||
use crate::onboarding::welcome::WelcomeWidget;
|
||||
use crate::onboarding::windows::WindowsSetupWidget;
|
||||
use crate::tui::FrameRequester;
|
||||
use crate::tui::Tui;
|
||||
use crate::tui::TuiEvent;
|
||||
@@ -30,7 +29,6 @@ use std::sync::RwLock;
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum Step {
|
||||
Windows(WindowsSetupWidget),
|
||||
Welcome(WelcomeWidget),
|
||||
Auth(AuthModeWidget),
|
||||
TrustDirectory(TrustDirectoryWidget),
|
||||
@@ -56,12 +54,10 @@ pub(crate) struct OnboardingScreen {
|
||||
request_frame: FrameRequester,
|
||||
steps: Vec<Step>,
|
||||
is_done: bool,
|
||||
windows_install_selected: bool,
|
||||
should_exit: bool,
|
||||
}
|
||||
|
||||
pub(crate) struct OnboardingScreenArgs {
|
||||
pub show_windows_wsl_screen: bool,
|
||||
pub show_trust_screen: bool,
|
||||
pub show_login_screen: bool,
|
||||
pub login_status: LoginStatus,
|
||||
@@ -71,14 +67,12 @@ pub(crate) struct OnboardingScreenArgs {
|
||||
|
||||
pub(crate) struct OnboardingResult {
|
||||
pub directory_trust_decision: Option<TrustDirectorySelection>,
|
||||
pub windows_install_selected: bool,
|
||||
pub should_exit: bool,
|
||||
}
|
||||
|
||||
impl OnboardingScreen {
|
||||
pub(crate) fn new(tui: &mut Tui, args: OnboardingScreenArgs) -> Self {
|
||||
let OnboardingScreenArgs {
|
||||
show_windows_wsl_screen,
|
||||
show_trust_screen,
|
||||
show_login_screen,
|
||||
login_status,
|
||||
@@ -91,9 +85,6 @@ impl OnboardingScreen {
|
||||
let codex_home = config.codex_home;
|
||||
let cli_auth_credentials_store_mode = config.cli_auth_credentials_store_mode;
|
||||
let mut steps: Vec<Step> = Vec::new();
|
||||
if show_windows_wsl_screen {
|
||||
steps.push(Step::Windows(WindowsSetupWidget::new(codex_home.clone())));
|
||||
}
|
||||
steps.push(Step::Welcome(WelcomeWidget::new(
|
||||
!matches!(login_status, LoginStatus::NotAuthenticated),
|
||||
tui.frame_requester(),
|
||||
@@ -138,7 +129,6 @@ impl OnboardingScreen {
|
||||
request_frame: tui.frame_requester(),
|
||||
steps,
|
||||
is_done: false,
|
||||
windows_install_selected: false,
|
||||
should_exit: false,
|
||||
}
|
||||
}
|
||||
@@ -200,10 +190,6 @@ impl OnboardingScreen {
|
||||
.flatten()
|
||||
}
|
||||
|
||||
pub fn windows_install_selected(&self) -> bool {
|
||||
self.windows_install_selected
|
||||
}
|
||||
|
||||
pub fn should_exit(&self) -> bool {
|
||||
self.should_exit
|
||||
}
|
||||
@@ -249,14 +235,6 @@ impl KeyboardHandler for OnboardingScreen {
|
||||
}
|
||||
}
|
||||
};
|
||||
if self
|
||||
.steps
|
||||
.iter()
|
||||
.any(|step| matches!(step, Step::Windows(widget) if widget.exit_requested()))
|
||||
{
|
||||
self.windows_install_selected = true;
|
||||
self.is_done = true;
|
||||
}
|
||||
self.request_frame.schedule_frame();
|
||||
}
|
||||
|
||||
@@ -338,7 +316,6 @@ impl WidgetRef for &OnboardingScreen {
|
||||
impl KeyboardHandler for Step {
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
||||
match self {
|
||||
Step::Windows(widget) => widget.handle_key_event(key_event),
|
||||
Step::Welcome(widget) => widget.handle_key_event(key_event),
|
||||
Step::Auth(widget) => widget.handle_key_event(key_event),
|
||||
Step::TrustDirectory(widget) => widget.handle_key_event(key_event),
|
||||
@@ -347,7 +324,6 @@ impl KeyboardHandler for Step {
|
||||
|
||||
fn handle_paste(&mut self, pasted: String) {
|
||||
match self {
|
||||
Step::Windows(_) => {}
|
||||
Step::Welcome(_) => {}
|
||||
Step::Auth(widget) => widget.handle_paste(pasted),
|
||||
Step::TrustDirectory(widget) => widget.handle_paste(pasted),
|
||||
@@ -358,7 +334,6 @@ impl KeyboardHandler for Step {
|
||||
impl StepStateProvider for Step {
|
||||
fn get_step_state(&self) -> StepState {
|
||||
match self {
|
||||
Step::Windows(w) => w.get_step_state(),
|
||||
Step::Welcome(w) => w.get_step_state(),
|
||||
Step::Auth(w) => w.get_step_state(),
|
||||
Step::TrustDirectory(w) => w.get_step_state(),
|
||||
@@ -369,9 +344,6 @@ impl StepStateProvider for Step {
|
||||
impl WidgetRef for Step {
|
||||
fn render_ref(&self, area: Rect, buf: &mut Buffer) {
|
||||
match self {
|
||||
Step::Windows(widget) => {
|
||||
widget.render_ref(area, buf);
|
||||
}
|
||||
Step::Welcome(widget) => {
|
||||
widget.render_ref(area, buf);
|
||||
}
|
||||
@@ -451,7 +423,6 @@ pub(crate) async fn run_onboarding_app(
|
||||
}
|
||||
Ok(OnboardingResult {
|
||||
directory_trust_decision: onboarding_screen.directory_trust_decision(),
|
||||
windows_install_selected: onboarding_screen.windows_install_selected(),
|
||||
should_exit: onboarding_screen.should_exit(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use codex_core::config::edit::ConfigEditsBuilder;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyEventKind;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::prelude::Widget;
|
||||
use ratatui::style::Color;
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::Line;
|
||||
use ratatui::widgets::Paragraph;
|
||||
use ratatui::widgets::WidgetRef;
|
||||
use ratatui::widgets::Wrap;
|
||||
|
||||
use crate::onboarding::onboarding_screen::KeyboardHandler;
|
||||
use crate::onboarding::onboarding_screen::StepStateProvider;
|
||||
|
||||
use super::onboarding_screen::StepState;
|
||||
|
||||
pub(crate) const WSL_INSTRUCTIONS: &str = r#"Install WSL2 by opening PowerShell as Administrator and running:
|
||||
# Install WSL using the default Linux distribution (Ubuntu).
|
||||
# See https://learn.microsoft.com/en-us/windows/wsl/install for more info
|
||||
wsl --install
|
||||
|
||||
# Restart your computer, then start a shell inside of Windows Subsystem for Linux
|
||||
wsl
|
||||
|
||||
# Install Node.js in WSL via nvm
|
||||
# Documentation: https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash && export NVM_DIR="$HOME/.nvm" && \. "$NVM_DIR/nvm.sh"
|
||||
nvm install 22
|
||||
|
||||
# Install and run Codex in WSL
|
||||
npm install --global @openai/codex
|
||||
codex
|
||||
|
||||
# Additional details and instructions for how to install and run Codex in WSL:
|
||||
https://developers.openai.com/codex/windows"#;
|
||||
|
||||
pub(crate) struct WindowsSetupWidget {
|
||||
pub codex_home: PathBuf,
|
||||
pub selection: Option<WindowsSetupSelection>,
|
||||
pub highlighted: WindowsSetupSelection,
|
||||
pub error: Option<String>,
|
||||
exit_requested: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum WindowsSetupSelection {
|
||||
Continue,
|
||||
Install,
|
||||
}
|
||||
|
||||
impl WindowsSetupWidget {
|
||||
pub fn new(codex_home: PathBuf) -> Self {
|
||||
Self {
|
||||
codex_home,
|
||||
selection: None,
|
||||
highlighted: WindowsSetupSelection::Install,
|
||||
error: None,
|
||||
exit_requested: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_continue(&mut self) {
|
||||
self.highlighted = WindowsSetupSelection::Continue;
|
||||
match ConfigEditsBuilder::new(&self.codex_home)
|
||||
.set_windows_wsl_setup_acknowledged(true)
|
||||
.apply_blocking()
|
||||
{
|
||||
Ok(()) => {
|
||||
self.selection = Some(WindowsSetupSelection::Continue);
|
||||
self.exit_requested = false;
|
||||
self.error = None;
|
||||
}
|
||||
Err(err) => {
|
||||
tracing::error!("Failed to persist Windows onboarding acknowledgement: {err:?}");
|
||||
self.error = Some(format!("Failed to update config: {err}"));
|
||||
self.selection = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_install(&mut self) {
|
||||
self.highlighted = WindowsSetupSelection::Install;
|
||||
self.selection = Some(WindowsSetupSelection::Install);
|
||||
self.exit_requested = true;
|
||||
}
|
||||
|
||||
pub fn exit_requested(&self) -> bool {
|
||||
self.exit_requested
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetRef for &WindowsSetupWidget {
|
||||
fn render_ref(&self, area: Rect, buf: &mut Buffer) {
|
||||
let mut lines: Vec<Line> = vec![
|
||||
Line::from(vec![
|
||||
"> ".into(),
|
||||
"To use all Codex features, we recommend running Codex in Windows Subsystem for Linux (WSL2)".bold(),
|
||||
]),
|
||||
Line::from(vec![" ".into(), "WSL allows Codex to run Agent mode in a sandboxed environment with better data protections in place.".into()]),
|
||||
Line::from(vec![" ".into(), "Learn more: https://developers.openai.com/codex/windows".into()]),
|
||||
Line::from(""),
|
||||
];
|
||||
|
||||
let create_option =
|
||||
|idx: usize, option: WindowsSetupSelection, text: &str| -> Line<'static> {
|
||||
if self.highlighted == option {
|
||||
Line::from(format!("> {}. {text}", idx + 1)).cyan()
|
||||
} else {
|
||||
Line::from(format!(" {}. {}", idx + 1, text))
|
||||
}
|
||||
};
|
||||
|
||||
lines.push(create_option(
|
||||
0,
|
||||
WindowsSetupSelection::Install,
|
||||
"Exit and install WSL2",
|
||||
));
|
||||
lines.push(create_option(
|
||||
1,
|
||||
WindowsSetupSelection::Continue,
|
||||
"Continue anyway",
|
||||
));
|
||||
lines.push("".into());
|
||||
|
||||
if let Some(error) = &self.error {
|
||||
lines.push(Line::from(format!(" {error}")).fg(Color::Red));
|
||||
lines.push("".into());
|
||||
}
|
||||
|
||||
lines.push(Line::from(vec![" Press Enter to continue".dim()]));
|
||||
|
||||
Paragraph::new(lines)
|
||||
.wrap(Wrap { trim: false })
|
||||
.render(area, buf);
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyboardHandler for WindowsSetupWidget {
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
||||
if key_event.kind == KeyEventKind::Release {
|
||||
return;
|
||||
}
|
||||
|
||||
match key_event.code {
|
||||
KeyCode::Up | KeyCode::Char('k') => {
|
||||
self.highlighted = WindowsSetupSelection::Install;
|
||||
}
|
||||
KeyCode::Down | KeyCode::Char('j') => {
|
||||
self.highlighted = WindowsSetupSelection::Continue;
|
||||
}
|
||||
KeyCode::Char('1') => self.handle_install(),
|
||||
KeyCode::Char('2') => self.handle_continue(),
|
||||
KeyCode::Enter => match self.highlighted {
|
||||
WindowsSetupSelection::Install => self.handle_install(),
|
||||
WindowsSetupSelection::Continue => self.handle_continue(),
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StepStateProvider for WindowsSetupWidget {
|
||||
fn get_step_state(&self) -> StepState {
|
||||
match self.selection {
|
||||
Some(WindowsSetupSelection::Continue) => StepState::Hidden,
|
||||
Some(WindowsSetupSelection::Install) => StepState::Complete,
|
||||
None => StepState::InProgress,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use tempfile::TempDir;
|
||||
|
||||
#[test]
|
||||
fn windows_step_hidden_after_continue() {
|
||||
let temp_dir = TempDir::new().expect("temp dir");
|
||||
let mut widget = WindowsSetupWidget::new(temp_dir.path().to_path_buf());
|
||||
|
||||
assert_eq!(widget.get_step_state(), StepState::InProgress);
|
||||
|
||||
widget.handle_continue();
|
||||
|
||||
assert_eq!(widget.get_step_state(), StepState::Hidden);
|
||||
assert!(!widget.exit_requested());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_step_complete_after_install_selection() {
|
||||
let temp_dir = TempDir::new().expect("temp dir");
|
||||
let mut widget = WindowsSetupWidget::new(temp_dir.path().to_path_buf());
|
||||
|
||||
widget.handle_install();
|
||||
|
||||
assert_eq!(widget.get_step_state(), StepState::Complete);
|
||||
assert!(widget.exit_requested());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user